#!/usr/bin/perl
#
# Generate a Perl script which will run 
#   Gnuplot repeatedly to make a set of 
#   GIF images which can be animated to make
#   a movie illustrating reverberation.
#
# MWR 3/28/2013

$debug = 1;


# first, the ray going straight from source to observer
$cmdfile = "test.gnu";
$term_options = "postscript enhanced font 'Helvectica,18' size 10,15 ";
$base = "test";


$minx = -250;
$maxx = 250;
$miny = -50;
$maxy = 450;

  $output_file = "./test.ps";

  open(CMDFILE, ">$cmdfile") || die("can't open file $cmdfile");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";
  printf CMDFILE "set size 1.0,1.0 \n";
  printf CMDFILE "set origin 0.0,0.0 \n";
  printf CMDFILE "set multiplot  \n";
  printf CMDFILE "set size 1.0,0.6666 \n";
  printf CMDFILE "set origin 0.0,0.3333 \n";
  printf CMDFILE "set size square \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set xlabel '' \n";
  printf CMDFILE "set ylabel '' \n";
  printf CMDFILE "plot sin(x) \n";

  printf CMDFILE "set size 1.0,0.3333 \n";
  printf CMDFILE "set origin 0.0,0.0 \n";
  printf CMDFILE "set size nosquare \n";
  printf CMDFILE "plot cos(x) \n";

  

  printf CMDFILE "$cmd \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;
