#!/usr/bin/perl
#
#

##########################################
#  plot speed of sound waves in air vs. frequency
#  data taken from 
# L. B. Evans and H. E. Bass, 
#    “Tables of absorption and velocity of sound in still air at 68F (20°C),” 
#     Technical Report No. AD0738576,
#     WYLE LABS HUNTSVILLE AL HUNTSVILLE United States
#     Report Date: 1972-01-01 

  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "sound_air_speed.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 '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 bot right \n";
  printf CMDFILE "set ylabel 'Speed of sound (m/s)'  \n";
  printf CMDFILE "set xlabel 'Frequency (Hz)' \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set title 'Speed of Sound in air, from Evans and Bass (1972)' \n";

  $cmd = "plot [][343.40:343.60] './sound_air.txt' index 0 using 1:(\$2*304.8) ";
  $cmd .= "        with points ls 1 ps 3 pt 6 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`;
  }











exit 0;
