#!/usr/bin/perl
#
#

$mypi = 3.14159;
$period = 8;
$halfp = $period/2.0;
$amp = 2.0;

##########################################
#  plot an example of an odd function
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "odd_a.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' ";

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";

  # revert to some oldish default colors
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n";
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n";
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n";
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n";
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n";


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set samples 500  \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) after frame 34' \n";
  printf CMDFILE "set title 'Motion of a mass hanging from a spring ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [-10:20][-3:3] $amp*sin(2*$mypi*x/$period) ";
  $cmd .= "        with lines ls 1 lw 6 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                        './test_four.out' index 0 using 2:10 ";
#  $cmd .= "        with lines ls -1 lw 3 t 'sin({/Symbol w_1})' ";

  printf CMDFILE "$cmd \n";


  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $giffile = $psfile;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


##########################################
#  plot an example of an odd function
#       add a rectangle to highlight time around zero
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "odd_b.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' ";

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";

  # revert to some oldish default colors
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n";
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n";
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n";
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n";
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n";


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set samples 500  \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) after frame 34' \n";
  printf CMDFILE "set title 'Motion of a mass hanging from a spring ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  printf CMDFILE "set object 1 rect from -$halfp,-10 to $halfp, 10 behind ";
  printf CMDFILE "      fs solid 0.1 fc lt 1 \n";

  $cmd = "plot [-10:20][-3:3] 2.0*sin(2*$mypi*x/$period) ";
  $cmd .= "        with lines ls 1 lw 6 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                        './test_four.out' index 0 using 2:10 ";
#  $cmd .= "        with lines ls -1 lw 3 t 'sin({/Symbol w_1})' ";

  printf CMDFILE "$cmd \n";


  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $giffile = $psfile;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


##########################################
#  plot an example of an even function
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "even_a.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' ";

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";

  # revert to some oldish default colors
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n";
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n";
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n";
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n";
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n";


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set samples 500  \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) after frame 49' \n";
  printf CMDFILE "set title 'Motion of a mass hanging from a spring ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [-10-10:20-10][-3:3] $amp*sin(2*$mypi*(x+2)/$period) ";
  $cmd .= "        with lines ls 1 lw 6 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                        './test_four.out' index 0 using 2:10 ";
#  $cmd .= "        with lines ls -1 lw 3 t 'sin({/Symbol w_1})' ";

  printf CMDFILE "$cmd \n";


  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $giffile = $psfile;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


##########################################
#  plot an example of an even function
#       add a rectangle to highlight time around zero
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "even_b.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' ";

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";

  # revert to some oldish default colors
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n";
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n";
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n";
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n";
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n";


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set samples 500  \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) after frame 49' \n";
  printf CMDFILE "set title 'Motion of a mass hanging from a spring ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  printf CMDFILE "set object 1 rect from -$halfp,-10 to $halfp, 10 behind ";
  printf CMDFILE "      fs solid 0.1 fc lt 1 \n";

  $cmd = "plot [-10-10:20-10][-3:3] 2.0*sin(2*$mypi*(x+2)/$period) ";
  $cmd .= "        with lines ls 1 lw 6 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                        './test_four.out' index 0 using 2:10 ";
#  $cmd .= "        with lines ls -1 lw 3 t 'sin({/Symbol w_1})' ";

  printf CMDFILE "$cmd \n";


  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $giffile = $psfile;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }





exit 0;
