#!/usr/bin/perl
#

############################################################################
# create a file with GNUPLOT commands, then execute GNUPLOT to read
#   from that file.
#
# usage:  make_graph   outfile_file_name  set_term_options
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "beat_picture_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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set samples 10000 \n";
  # printf CMDFILE "set key 1563.84,0.60 \n";
  #printf CMDFILE "set ylabel 'Differential V magnitude' \n";
  #printf CMDFILE "set xlabel 'Julian Date - 2,455,000' \n";
  #printf CMDFILE "set title 'Jup field, $filter $aper-pix diff mag, 12-inch, $date UT'\n", $aper;
 
  $omega = 1.0;
  
  $cmd = "plot [-20:20][-3:3] sin($omega*x)*2*cos($omega*0.01*x) ";
  $cmd .= "   with lines lw 3  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`;
  }


############################################################################
# create a file with GNUPLOT commands, then execute GNUPLOT to read
#   from that file.
#
# usage:  make_graph   outfile_file_name  set_term_options
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "beat_picture_c.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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set samples 10000 \n";
  # printf CMDFILE "set key 1563.84,0.60 \n";
  #printf CMDFILE "set ylabel 'Differential V magnitude' \n";
  #printf CMDFILE "set xlabel 'Julian Date - 2,455,000' \n";
  #printf CMDFILE "set title 'Jup field, $filter $aper-pix diff mag, 12-inch, $date UT'\n", $aper;
 
  $omega = 1.0;
  
  $cmd = "plot [-300:300][-3:3] sin($omega*x)*2*cos($omega*0.01*x) ";
  $cmd .= "   with lines lw 3  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`;
  }



############################################################################
# create a file with GNUPLOT commands, then execute GNUPLOT to read
#   from that file.
#
# usage:  make_graph   outfile_file_name  set_term_options
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "beat_picture_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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set samples 10000 \n";
  # printf CMDFILE "set key 1563.84,0.60 \n";
  #printf CMDFILE "set ylabel 'Differential V magnitude' \n";
  #printf CMDFILE "set xlabel 'Julian Date - 2,455,000' \n";
  #printf CMDFILE "set title 'Jup field, $filter $aper-pix diff mag, 12-inch, $date UT'\n", $aper;
 
  $omega = 1.0;
  
  $cmd = "plot [-100:100][-3:3] sin($omega*x)*2*cos($omega*0.01*x) ";
  $cmd .= "   with lines lw 3  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`;
  }



############################################################################
# create a file with GNUPLOT commands, then execute GNUPLOT to read
#   from that file.
#
# usage:  make_graph   outfile_file_name  set_term_options
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "beat_picture_d.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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set samples 100000 \n";
  # printf CMDFILE "set key 1563.84,0.60 \n";
  #printf CMDFILE "set ylabel 'Differential V magnitude' \n";
  #printf CMDFILE "set xlabel 'Julian Date - 2,455,000' \n";
  #printf CMDFILE "set title 'Jup field, $filter $aper-pix diff mag, 12-inch, $date UT'\n", $aper;
 
  $omega = 1.0;
  
  $cmd = "plot [-1000:1000][-3:3] sin($omega*x)*2*cos($omega*0.01*x) ";
  $cmd .= "   with lines lw 3  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;
