#!/usr/bin/perl
#


# time "zero" corresponds to this JD = May 26, 2020
$JDBASE = 2458995.5;

  
#############################################################################
#    Make a graph showing 
#        beta vs. parallax value
#
  my($output_file, $term_options);

  $output_file = "grid_para_a.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";

  #  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 bot right \n";
  printf CMDFILE "set ylabel 'Sum of squares of differences {/Symbol b} ' \n";
  printf CMDFILE "set xlabel 'Guessed value of parallax {/Symbol v} (milliarcsec)' \n";
#  printf CMDFILE "set title 'GX And A, 2020 - 2021 '\n";
  
  $cmd = "plot [80:520][0:2e6] 'fit_gxand_para_only_a.dat' using (\$7-0):(\$2-0)  ";
  $cmd .=  "     with points ls 1 pt 3.0  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`;
  }

  
#############################################################################
#    Make a graph showing 
#        beta vs. parallax value
#        This version shows all iterations on a single graph
#
  my($output_file, $term_options);

  $output_file = "grid_para_b.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";

  #  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 bot right \n";
  printf CMDFILE "set ylabel 'Sum of squares of differences {/Symbol b} ' \n";
  printf CMDFILE "set xlabel 'Guessed value of parallax {/Symbol v} (milliarcsec)' \n";
#  printf CMDFILE "set title 'GX And A, 2020 - 2021 '\n";
  
  $cmd = "plot [250:370][270:330] 'fit_gxand_para_b.dat' using (\$7-0):(\$2-0)  ";
  $cmd .=  "     with points ls 1 pt 3.0 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`;
  }

  
#############################################################################
#    Make a graph showing 
#        beta vs. parallax value
#        This version shows only final iterations on a single graph
#
  my($output_file, $term_options);

  $output_file = "grid_para_c.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";

  #  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 bot right \n";
  printf CMDFILE "set ylabel 'Sum of squares of differences {/Symbol b} ' \n";
  printf CMDFILE "set xlabel 'Guessed value of parallax {/Symbol v} (milliarcsec)' \n";
#  printf CMDFILE "set title 'GX And A, 2020 - 2021 '\n";
  
  $cmd = "plot [290:320][0.88e6:0.89e6] 'fit_gxand_para_c.dat' using (\$7-0):(\$2-0)  ";
  $cmd .=  "     with points ls 1 pt 3.0 ps 0.6 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;
