#!/usr/bin/perl
#
# Make plots illustrating the "Michelson Interferometer" experiment
#
# MWR 10/14/2009
  
  my($output_file, $term_options);



  # Calibration of energy as function of channel number
  $output_file = "./mwr_michelson_a.ps";
  $term_options = "postscript color enhanced ";

  $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 right \n";
  printf CMDFILE "set xlabel 'Temperature of rod (Celsius)'  \n";
  printf CMDFILE "set ylabel 'Number of fringes' \n";
  printf CMDFILE "set title 'Expansion of a copper rod, Oct 13, 2009' \n";
  
  $cmd = "plot [24:44][0:70] ";
  $cmd .= " './mwr_michelson.dat'  ";
  $cmd .= "    using (\$1):(\$2)  ";
  $cmd .= "    t '' with points ps 1.0 pt 3 lw 3 ";
  $cmd .= " , ";
  $cmd .= "  -8.522641e+01+3.571082e+00*x t '-85.23 + 3.57*T' lc 1 ";
 
 

  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/.eps/.png/;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



exit 0;
