#!/usr/bin/perl
#
#
#
# Make graphs showing frequency spectra of various sounds.
#
# MWR 2/12/2019


##########################################
#  sine 220 Hz, by itself
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "sine_220.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 'Log (Sound Intensity)  '  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set title 'A3 = 220 Hz ' \n";

  $cmd = "plot [0:3000][] './sine_220.txt' using 1:(10**(\$2/100)) ";
  $cmd .= "        with lines ls 1 lw 2 t 'sine wave' ";
#  $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`;
  }


##########################################
#  sawtooth 220 Hz, by itself
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "sawtooth_220.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 'Log (Sound Intensity)  '  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set title 'A3 = 220 Hz ' \n";

  $cmd = "plot [0:3000][] './sawtooth_220.txt' using 1:(10**(\$2/100)) ";
  $cmd .= "        with lines ls 2 lw 3 t 'sawtooth wave' ";
#  $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`;
  }



##########################################
#  square 220 Hz, by itself
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "square_220.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 'Log (Sound Intensity)  '  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set title 'A3 = 220 Hz ' \n";

  $cmd = "plot [0:3000][] './square_220.txt' using 1:(10**(\$2/100)) ";
  $cmd .= "        with lines ls 3 lw 3 t 'square wave' ";
#  $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`;
  }




##########################################
#  piano, by itself
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "piano_spec.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 'Log (Sound Intensity)  '  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set title 'A3 = 220 Hz ' \n";

  $cmd = "plot [0:3000][] './piano_a3.txt' using 1:(10**(\$2/100)) ";
  $cmd .= "        with lines ls 2 lw 3 t 'piano' ";
#  $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`;
  }




##########################################
#  piano A3  and sine 220
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "piano_sine_spec.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 'Log (Sound Intensity)  '  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set title 'A3 = 220 Hz ' \n";

  $cmd = "plot [0:3000][] './sine_220.txt' using 1:(10**(\$2/100)) ";
  $cmd .= "        with lines ls 1 lw 2 t 'sine wave' ";
  $cmd .= " , ";
  $cmd .= "                './piano_a3.txt' using 1:(10**(\$2/100)) ";
  $cmd .= "        with lines ls 2 lw 3 t 'piano ' ";

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



##########################################
#  sine and square waves
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "sine_square_spec.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 'Log (Sound Intensity)  '  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set title 'A3 = 220 Hz ' \n";

  $cmd = "plot [0:3000][] './sine_220.txt' using 1:(0.10+10**(\$2/100)) ";
  $cmd .= "        with lines ls 1 lw 5 t 'sine wave' ";
  $cmd .= " , ";
  $cmd .= "                './square_220.txt' using 1:(10**(\$2/100)) ";
  $cmd .= "        with lines ls 2 lw 5 t 'square wave' ";

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


##########################################
#  sine and square and sawtooth waves
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "sine_square_saw_spec.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 'Log (Sound Intensity)  '  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set title 'A3 = 220 Hz ' \n";

  $cmd = "plot [0:3000][] './sine_220.txt' using 1:(0.05+10**(\$2/100)) ";
  $cmd .= "        with lines ls 1 lw 6 t 'sine wave' ";
  $cmd .= " , ";
  $cmd .= "                './square_220.txt' using 1:(-0.05+10**(\$2/100)) ";
  $cmd .= "        with lines ls 2 lw 4 t 'square wave' ";
  $cmd .= " , ";
  $cmd .= "                './sawtooth_220.txt' using 1:(-0.1+10**(\$2/100)) ";
  $cmd .= "        with lines ls 3 lw 2 t 'sawtooth wave' ";

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



##########################################
# piano and flute
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "piano_flute_spec.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 'Log (Sound Intensity)  '  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set title 'A3 = 220 Hz ' \n";

  $cmd = "plot [0:3000][0:0.6] './sine_220.txt' using 1:(8.05+10**(\$2/100)) ";
  $cmd .= "        with lines ls 1 lw 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                './piano_a3.txt' using 1:(-0.05+10**(\$2/100)) ";
  $cmd .= "        with lines ls 2 lw 4 t 'piano' ";
  $cmd .= " , ";
  $cmd .= "                './bass_flute_a3.txt' using 1:(-0.1+10**(\$2/100)) ";
  $cmd .= "        with lines ls 3 lw 2 t 'flute' ";

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



##########################################
#  viola and flute
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "viola_flute_spec.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 'Log (Sound Intensity)  '  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set title 'A3 = 220 Hz ' \n";

  $cmd = "plot [0:3000][0:0.6] './sine_220.txt' using 1:(8.05+10**(\$2/100)) ";
  $cmd .= "        with lines ls 1 lw 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                './viola_a3.txt' using 1:(-0.15+10**(\$2/100)) ";
  $cmd .= "        with lines ls 5 lw 4 t 'viola' ";
  $cmd .= " , ";
  $cmd .= "                './bass_flute_a3.txt' using 1:(-0.1+10**(\$2/100)) ";
  $cmd .= "        with lines ls 3 lw 2 t 'flute' ";

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


##########################################
#  horn and flute
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "horn_flute_spec.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 'Log (Sound Intensity)  '  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set title 'A3 = 220 Hz ' \n";

  $cmd = "plot [0:3000][0:0.7] './sine_220.txt' using 1:(8.05+10**(\$2/100)) ";
  $cmd .= "        with lines ls 1 lw 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                './horn_a3.txt' using 1:(-0.00+10**(\$2/100)) ";
  $cmd .= "        with lines ls -1 lw 3 t 'horn' ";
  $cmd .= " , ";
  $cmd .= "                './bass_flute_a3.txt' using 1:(-0.1+10**(\$2/100)) ";
  $cmd .= "        with lines ls 3 lw 3 t 'flute' ";

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


##########################################
#  horn and viola
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "horn_viola_spec.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 'Log (Sound Intensity)  '  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set title 'A3 = 220 Hz ' \n";

  $cmd = "plot [0:3000][0:0.7] './sine_220.txt' using 1:(8.05+10**(\$2/100)) ";
  $cmd .= "        with lines ls 1 lw 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                './horn_a3.txt' using 1:(-0.00+10**(\$2/100)) ";
  $cmd .= "        with lines ls -1 lw 3 t 'horn' ";
  $cmd .= " , ";
  $cmd .= "                './viola_a3.txt' using 1:(-0.1+10**(\$2/100)) ";
  $cmd .= "        with lines ls 5 lw 3 t 'viola' ";

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



##########################################
#  horn alone
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "horn_spec.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 'Log (Sound Intensity)  '  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set title 'A3 = 220 Hz ' \n";

  $cmd = "plot [0:3000][0:0.7] './sine_220.txt' using 1:(8.05+10**(\$2/100)) ";
  $cmd .= "        with lines ls 1 lw 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                './horn_a3.txt' using 1:(-0.00+10**(\$2/100)) ";
  $cmd .= "        with lines ls -1 lw 3 t 'horn' ";
#  $cmd .= " , ";
#  $cmd .= "                './viola_a3.txt' using 1:(-0.1+10**(\$2/100)) ";
#  $cmd .= "        with lines ls 5 lw 3 t 'viola' ";

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






##########################################
#  viola alone
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "viola_spec.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 'Log (Sound Intensity)  '  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set title 'A3 = 220 Hz ' \n";

  $cmd = "plot [0:3000][0:0.7] './sine_220.txt' using 1:(8.05+10**(\$2/100)) ";
  $cmd .= "        with lines ls 1 lw 6 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                './horn_a3.txt' using 1:(-0.00+10**(\$2/100)) ";
#  $cmd .= "        with lines ls -1 lw 3 t 'horn' ";
  $cmd .= " , ";
  $cmd .= "                './viola_a3.txt' using 1:(-0.1+10**(\$2/100)) ";
  $cmd .= "        with lines ls 5 lw 3 t 'viola' ";

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



##########################################
#  flute alone
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "flute_spec.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 'Log (Sound Intensity)  '  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set title 'A3 = 220 Hz ' \n";

  $cmd = "plot [0:3000][0:0.7] './sine_220.txt' using 1:(8.05+10**(\$2/100)) ";
  $cmd .= "        with lines ls 1 lw 6 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                './horn_a3.txt' using 1:(-0.00+10**(\$2/100)) ";
#  $cmd .= "        with lines ls -1 lw 3 t 'horn' ";
  $cmd .= " , ";
  $cmd .= "                './bass_flute_a3.txt' using 1:(-0.1+10**(\$2/100)) ";
  $cmd .= "        with lines ls 3 lw 3 t 'viola' ";

  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;
