#!/usr/bin/perl
#

$JDBASE = 2455000;

  my($output_file, $term_options);



###################################################################
#  Graph of student values

  # get the arguments
  $output_file = "./iyuma_student.ps";
  $term_options = "postscript color enhanced '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 1563.84,0.60 \n";
  printf CMDFILE "set ylabel 'Instrumental magnitude' \n";
  printf CMDFILE "set xlabel 'image number ' \n";
  printf CMDFILE "set title 'Field of IY UMa, student values '\n";
  
  $cmd = "plot [0:100][16.5:12] ";
  $cmd .=  "   './mathews.dat' using 1:2 lt 1 lc 1 lw 3 t 'A' ";
  $cmd .= " , ";
  $cmd .=  "   './emerson.dat' using 1:2 lt 1 lc 1 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './rustowicz.dat' using 1:2 lt 1 lc 1 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './jones.dat' using 1:2 lt 1 lc 1 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './bero.dat' using 1:2 lt 1 lc 1 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './sagan.dat' using 1:2 lt 1 lc 1 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './dooling.dat' using 1:2 lt 1 lc 1 lw 3 t '' ";
  
  # 
  # now for star "B"
  #
  $cmd .= " , ";
  $cmd .=  "   './mathews.dat' using 1:3 lt 1 lc 2 lw 3 t 'B' ";
  $cmd .= " , ";
  $cmd .=  "   './emerson.dat' using 1:3 lt 1 lc 2 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './rustowicz.dat' using 1:3 lt 1 lc 2 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './jones.dat' using 1:3 lt 1 lc 2 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './bero.dat' using 1:3 lt 1 lc 2 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './sagan.dat' using 1:3 lt 1 lc 2 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './dooling.dat' using 1:3 lt 1 lc 2 lw 3 t '' ";

  # 
  # now for star "IY"
  #
  $cmd .= " , ";
  $cmd .=  "   './mathews.dat' using 1:4 lt 1 lc 3 lw 3 t 'C' ";
  $cmd .= " , ";
  $cmd .=  "   './emerson.dat' using 1:4 lt 1 lc 3 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './rustowicz.dat' using 1:4 lt 1 lc 3 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './jones.dat' using 1:4 lt 1 lc 3 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './bero.dat' using 1:4 lt 1 lc 3 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './sagan.dat' using 1:4 lt 1 lc 3 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .=  "   './dooling.dat' using 1:4 lt 1 lc 3 lw 3 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`;
  }


###################################################################
#  Graph of Richmond's values

  # get the arguments
  $output_file = "./iyuma_mwr.ps";
  $term_options = "postscript color enhanced '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 1563.84,0.60 \n";
  printf CMDFILE "set ylabel 'Instrumental magnitude' \n";
  printf CMDFILE "set xlabel 'image number ' \n";
  printf CMDFILE "set title 'Field of IY UMa, MWR values '\n";
  
  $cmd = "plot [0:100][16.5:12] ";
  $cmd .=  "   './pff/starA_.dat4' using (\$4+10):(\$7+11) ";
  $cmd .=  "            lt 1 lc 1 lw 3 t 'A' ";
  $cmd .= " , ";
  $cmd .=  "   './pff/starB_.dat4' using (\$4+10):(\$7+11) ";
  $cmd .=  "            lt 1 lc 2 lw 3 t 'B' ";
  $cmd .= " , ";
  $cmd .=  "   './pff/starIY_.dat4' using (\$4+10):(\$7+11) ";
  $cmd .=  "            lt 1 lc 3 lw 3 t 'IY' ";
  

  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`;
  }



###################################################################
#  Second graph of Richmond's values, with JD

  # get the arguments
  $output_file = "./iyuma_mwr_a.ps";
  $term_options = "postscript color enhanced '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 1563.84,0.60 \n";
  printf CMDFILE "set ylabel 'Instrumental magnitude' \n";
  printf CMDFILE "set xlabel 'Julian Date - 2453800' \n";
  printf CMDFILE "set title 'Field of IY UMa, MWR values '\n";
  
  $cmd = "plot [37.554:37.596][15.5:12] ";
  $cmd .=  "   './pff/starA_.dat4' using (\$5-2453800.0):(\$7+11) ";
  $cmd .=  "            lt 1 lc 1 lw 3 t 'A' ";
  $cmd .= " , ";
  $cmd .=  "   './pff/starB_.dat4' using (\$5-2453800.0):(\$7+11) ";
  $cmd .=  "            lt 1 lc 2 lw 3 t 'B' ";
  $cmd .= " , ";
  $cmd .=  "   './pff/starIY_.dat4' using (\$5-2453800.0):(\$7+11) ";
  $cmd .=  "            lt 1 lc 3 lw 3 t 'IY' ";
  

  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;
