#!/usr/bin/perl
#

$JDBASE = 2455000;

  # make a graph showing airmass and JD for all calibration images
  $output_file = "jd_airmass_a.ps";
  $term_options = "postscript enhanced mono";
  $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 nokey \n";
  printf CMDFILE "set xlabel 'Julian Date - 2,455,000' \n";
  printf CMDFILE "set ylabel 'airmass'  \n";
  printf CMDFILE "set title 'Observations to calibrate MR Del field, Oct 25, 2009'\n", $aper;
  
  $cmd = "plot [][] './collate_BV/collate_BV.out' ";
  $cmd = $cmd . "  using (\$4-$JDBASE):(\$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;
