#!/usr/bin/perl
#

  # show just the fundamental
  $output_file = "fund_only.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 ylabel 'Displacement  (cm)'  \n";
  printf CMDFILE "set xlabel 'Distance along string (m) ' \n";


  printf CMDFILE "set title 'A plucked cello string ' \n";
  
  $cmd = "plot [0.0:0.7][-0.10:0.10] 'calc_sin.out' using 2:4 ";
  $cmd .= "       with lines ls 1 t '' ";

  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`;
  }


  # show just the fundamental
  #    with pos and neg excursions
  $output_file = "fund_only_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 11 lt rgb 'red' lw 3 dt 2  \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 ylabel 'Displacement  (cm)'  \n";
  printf CMDFILE "set xlabel 'Distance along string (m) ' \n";


  printf CMDFILE "set title 'A plucked cello string ' \n";
  
  $cmd = "plot [0.0:0.7][-0.10:0.10] 'calc_sin.out' using 2:4 ";
  $cmd .= "       with lines ls 1 t '' ";
  $cmd .= " , ";
  $cmd .= "                          'calc_sin.out' using 2:(0.0-\$4) ";
  $cmd .= "       with lines ls 11  t '' ";

  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`;
  }



  # show the fundamental and first overtone
  #    with pos and neg excursions
  $output_file = "fund_first_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 11 lt rgb 'red' lw 3 dt 2  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 21 lt rgb 'sea-green' lw 3 dt 2  \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 multiplot layout 2,1 title 'A plucked cello string ' \n";


  # the fundamental panel
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Displacement  (cm)'  \n";
  printf CMDFILE "set xlabel 'Distance along string (m) ' \n";

  $cmd = "plot [0.0:0.7][-0.10:0.10] 'calc_sin.out' using 2:4 ";
  $cmd .= "       with lines ls 1 t 'fundamental' ";
  $cmd .= " , ";
  $cmd .= "                          'calc_sin.out' using 2:(0.0-\$4) ";
  $cmd .= "       with lines ls 11  t '' ";
  printf CMDFILE "$cmd \n";


  # the first overtone panel
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Displacement  (cm)'  \n";
  printf CMDFILE "set xlabel 'Distance along string (m) ' \n";

  $cmd = "plot [0.0:0.7][-0.10:0.10] 'calc_sin.out' using 2:6 ";
  $cmd .= "       with lines ls 2 t 'first overtone' ";
  $cmd .= " , ";
  $cmd .= "                          'calc_sin.out' using 2:(0.0-\$6) ";
  $cmd .= "       with lines ls 21  t '' ";
  printf CMDFILE "$cmd \n";

  printf CMDFILE "unset multiplot \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;
