#!/usr/bin/perl
#

  $output_file = "drag_expt_2011.ps";
  $term_options = "postscript color '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 key bot left \n";
  printf CMDFILE "set xlabel 'Velocity (red) or Velocity^2 (blue) ' \n";
  printf CMDFILE "set ylabel 'Force of air resistance (mN) ' \n";
  printf CMDFILE "set title 'Coffee filters with paper clips falling through air' \n";
  
  $cmd = "plot [-0.2:7.0][-1:50] './drag_expt_2011.dat' ";
  $cmd .= "   using 3:(\$1*9.8) with points pt 5 ps 2 lw 5 t '' ";
  $cmd .= " , ";
  $cmd .= "                              './drag_expt_2011.dat' ";
  $cmd .= "   using 4:(\$1*9.8) with points lc 3 pt 6 ps 2 lw 5 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;
