#!/usr/bin/perl
#


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

  
#############################################################################
#    Make a graph showing motion of star over all observations
#        Dec vs. RA 
#        with line showing model for parallax = 0
#
  my($output_file, $term_options);

  $output_file = "fit_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 'Motion in Dec (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Motion in RA (milliarcsec) ' \n";
  printf CMDFILE "set title 'GX And A, 2020 - 2021 '\n";
  
  $cmd = "plot [-500:3800][-200:600] 'gxand_pos.dat' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  t '' ";
  $cmd .=  " , ";
  $cmd .=  "  'fit_gxand_para_0.dat' using 2:3 ";
  $cmd .=  "     with points ls 3 ps 1.5 pt 6  t  '{/Symbol v} = 0' ";

  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 motion of star over all observations
#        Dec vs. RA 
#        with line showing model for parallax = 0
#        and  line showing model for parallax = 100
#
  my($output_file, $term_options);

  $output_file = "fit_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 'Motion in Dec (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Motion in RA (milliarcsec) ' \n";
  printf CMDFILE "set title 'GX And A, 2020 - 2021 '\n";
  
  $cmd = "plot [-500:3800][-200:600] 'gxand_pos.dat' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  t '' ";
  $cmd .=  " , ";
  $cmd .=  "  'fit_gxand_para_0.dat' using 2:3 ";
  $cmd .=  "     with lines ls 3  t  '{/Symbol v} = 0' ";
  $cmd .=  " , ";
  $cmd .=  "  'fit_gxand_para_100.dat' using 2:3 ";
  $cmd .=  "     with points ls 2 ps 1.2 pt 3  t  '{/Symbol v} = 100' ";


  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 motion of star over all observations
#        Dec vs. RA 
#        with line showing model for parallax = 0
#        and  line showing model for parallax = 500
#
  my($output_file, $term_options);

  $output_file = "fit_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 'Motion in Dec (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Motion in RA (milliarcsec) ' \n";
  printf CMDFILE "set title 'GX And A, 2020 - 2021 '\n";
  
  $cmd = "plot [-500:3800][-200:600] 'gxand_pos.dat' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  t '' ";
  $cmd .=  " , ";
  $cmd .=  "  'fit_gxand_para_0.dat' using 2:3 ";
  $cmd .=  "     with lines ls 3  t  '{/Symbol v} = 0' ";
  $cmd .=  " , ";
  $cmd .=  "  'fit_gxand_para_500.dat' using 2:3 ";
  $cmd .=  "     with points ls 2 ps 1.2 pt 3  t  '{/Symbol v} = 500' ";


  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 motion of star over all observations
#        Dec vs. RA 
#        with line showing model for parallax = 0
#        and  line showing model for parallax = 300
#
  my($output_file, $term_options);

  $output_file = "fit_para_d.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 'Motion in Dec (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Motion in RA (milliarcsec) ' \n";
  printf CMDFILE "set title 'GX And A, 2020 - 2021 '\n";
  
  $cmd = "plot [-500:3800][-200:600] 'gxand_pos.dat' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  t '' ";
  $cmd .=  " , ";
  $cmd .=  "  'fit_gxand_para_0.dat' using 2:3 ";
  $cmd .=  "     with lines ls 3 t  '{/Symbol v} = 0' ";
  $cmd .=  " , ";
  $cmd .=  "  'fit_gxand_para_300.dat' using 2:3 ";
  $cmd .=  "     with points ls 2 ps 1.2 pt 3  t  '{/Symbol v} = 300' ";


  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 motion of star over all observations
#        Dec vs. RA 
#        with line showing model for parallax = 320
#
  my($output_file, $term_options);

  $output_file = "fit_para_e.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 'Motion in Dec (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Motion in RA (milliarcsec) ' \n";
  printf CMDFILE "set title 'GX And A, 2020 - 2021 '\n";
  
  $cmd = "plot [-500:3800][-200:600] 'gxand_pos.dat' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  t '' ";
  $cmd .=  " , ";
  $cmd .=  "  'fit_gxand_para_0.dat' using 2:3 ";
  $cmd .=  "     with lines ls 3 t  '{/Symbol v} = 0' ";
  $cmd .=  " , ";
  $cmd .=  "  'fit_gxand_para_306.dat' using 2:3 ";
  $cmd .=  "     with points ls 2 ps 1.2 pt 3  t  '{/Symbol v} = 306' ";


  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;
