#!/usr/bin/perl
#

#
# Make a light curve of V445 Cas over several nights
#   based on RIT Obs data, but time values are shifted 
#   arbitrarily for cosmetic effect (so can't actually 
#   determine a period properly any more)
#
#   instrumental mag vs. time
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "v445_curve_a.ps";
  $term_options = "postscript enhanced 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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 




  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xlabel 'Time (days) ' \n";
  printf CMDFILE "set ylabel 'Instrumental magnitude ' \n";


  printf CMDFILE "set title 'RIT Obs measurements of V445 Cas '\n";
  
  $cmd = "plot [524.4:526.8][2.5:2.0] 'nov05_v445_b.dat' using (\$5-2459000):7 ";
  $cmd .= "      with points ls 1 ps 0.4 t '' , ";
  $cmd .= "   'nov16_v445_b.dat' using (\$5-2459000-10):7 ";
  $cmd .= "      with points ls 2 ps 0.4 t '' , ";
  $cmd .= "   'nov23_v445_b.dat' using (\$5-2459000-16):7 ";
  $cmd .= "      with points ls 3 ps 0.4 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;
