#!/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 = "compare_dist_2.ps";
  $term_options = "postscript 'Helvetica' 14 color";

  $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 key top left \n";
  printf CMDFILE "set xlabel 'Number of customers per hour (normalized)' \n";
  printf CMDFILE "set ylabel '' \n";
  printf CMDFILE "set title 'Comparison of customer statistics over a long period'\n", $aper;
  
  $cmd = "plot [0:20][0:160] 'mcking/hist_g.dat' using 1:2 ";
  $cmd .= "   with linespoints ps 1.5 pt 1 lw 2 t 'N=1 store' ";
  $cmd .= " , ";
  $cmd .= " 'mcking/hist_p2.dat' using (\$1*0.01):(\$2*6) ";
  $cmd .= "   with points ps 0.5 pt 2 lw 4 t 'N=100 stores' ";
  $cmd .= " , ";
  $cmd .= " 'mcking/hist_t.dat' using (\$1*0.0001):(\$2*20) ";
  $cmd .= "   with lines lw 2 t 'N=10,000 stores' ";


  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;
