#!/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 
#
  my($output_file, $term_options);

  $output_file = "gxand_dec_vs_ra_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 top 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 [][] 'gxand_pos.dat' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  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 motion of star over all observations
#        Dec vs. RA 
#        This version has square axis ratio
#
  my($output_file, $term_options);

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

  printf CMDFILE "set size square \n";

  
  $cmd = "plot [0:3500][-1500:2000] 'gxand_pos.dat' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  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 motion of star over all observations
#        Dec vs. RA 
#    Include best-fit model from grid-based method
#
  my($output_file, $term_options);

  $output_file = "gxand_dec_vs_ra_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 [][] 'gxand_pos.dat' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  t '' ";
  $cmd .=  " , ";
  $cmd .=  "   'fit_gxand.out.10' using (\$2-0):(\$3-0)  ";
  $cmd .=  "     with points ls 2 ps 2 pt 6  t 'grid-based model' ";


  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 
#    Include best-fit model from least-squares method
#
  my($output_file, $term_options);

  $output_file = "gxand_dec_vs_ra_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 [][] 'gxand_pos.dat' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  t '' ";
  $cmd .=  " , ";
  $cmd .=  "   'matrix_gxand.out' using (\$2-0):(\$3-0)  ";
  $cmd .=  "     with points ls 3 ps 0.5 pt 4  t 'deriv-based model' ";


  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 
#    Include models from both grid and least-squares method
#
  my($output_file, $term_options);

  $output_file = "gxand_dec_vs_ra_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 [][] 'gxand_pos.dat' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  t '' ";
  $cmd .=  " , ";
  $cmd .=  "   'fit_gxand.out.10' using (\$2-0):(\$3-0)  ";
  $cmd .=  "     with points ls 2 ps 2 pt 6  t 'grid-based model' ";
  $cmd .=  " , ";
  $cmd .=  "   'matrix_gxand.out' using (\$2-0):(\$3-0)  ";
  $cmd .=  "     with points ls 3 ps 0.5 pt 4  t 'deriv-based model' ";


  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 
#    Include best-fit model from UNWEIGHTED grid-based method
#
  my($output_file, $term_options);

  $output_file = "gxand_dec_vs_ra_unweighted.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 [][] 'gxand_pos.dat' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  t '' ";
  $cmd .=  " , ";
  $cmd .=  "   'grid_unweighted.out' using (\$2-0):(\$3-0)  ";
  $cmd .=  "     with points ls 2 ps 1.0 pt 3 t 'grid-based model' ";


  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 
#    Include the actual data, plus one "alternate" set of measurements
#
  my($output_file, $term_options);

  $output_file = "gxand_dec_vs_ra_alt1.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 [][] 'gxand_pos.dat' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  t 'actual measurements' ";
  $cmd .=  " , ";
  $cmd .=  "   'gxand_pos_alt_1.dat' using (\$2-0):(\$4-0)  ";
  $cmd .=  "     with points ls 2 ps 1.0 pt 3 t 'alternate 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 
#    Include the actual data, plus one "alternate" set of measurements
#
  my($output_file, $term_options);

  $output_file = "gxand_dec_vs_ra_alt2.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 [][] 'gxand_pos.dat' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  t 'actual measurements' ";
  $cmd .=  " , ";
  $cmd .=  "   'gxand_pos_alt_2.dat' using (\$2-0):(\$4-0)  ";
  $cmd .=  "     with points ls 3 ps 1.0 pt 3 t 'alternate 1' ";


  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 
#    Include the actual data, plus one "alternate" set of measurements
#
  my($output_file, $term_options);

  $output_file = "gxand_dec_vs_ra_alt3.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 [][] 'gxand_pos.dat' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  t 'actual measurements' ";
  $cmd .=  " , ";
  $cmd .=  "   'gxand_pos_alt_3.dat' using (\$2-0):(\$4-0)  ";
  $cmd .=  "     with points ls -1 ps 0.8 pt 5 t 'alternate 2' ";


  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 theoretical motion due to parallax
#        for a star at North Ecliptic Pole,
#        with no proper motion.
#        This version has square axis ratio
#
  my($output_file, $term_options);

  $output_file = "theory_face_on_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 top right \n";
  printf CMDFILE "set ylabel 'Motion in Dec (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Motion in RA (milliarcsec) ' \n";
  printf CMDFILE "set title 'A star directly above Earth orbit' \n";

  printf CMDFILE "set size square \n";

  
  $cmd = "plot [-400:400][-400:400] 'generate_ra_dec_faceon_a.out' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with points ls 1 ps 0.8 pt 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`;
  }


#############################################################################
#    Make a graph showing theoretical motion due to parallax
#        for a star on Ecliptic Equator,
#        with no proper motion.
#        This version has square axis ratio
#
  my($output_file, $term_options);

  $output_file = "theory_edge_on_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 top right \n";
  printf CMDFILE "set ylabel 'Motion in Dec (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Motion in RA (milliarcsec) ' \n";
  printf CMDFILE "set title 'A star in plane of Earth orbit ' \n";

  printf CMDFILE "set size square \n";

  
  $cmd = "plot [-400:400][-400:400] 'generate_ra_dec_edgeon_b.out' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with points ls 1 ps 0.8 pt 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`;
  }

  
#############################################################################
#    Make a graph showing theoretical motion due to parallax
#        for a star at the position of GX And,
#        with no proper motion.
#        This version has square axis ratio
#
  my($output_file, $term_options);

  $output_file = "theory_gxand_nomu.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 top right \n";
  printf CMDFILE "set ylabel 'Motion in Dec (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Motion in RA (milliarcsec) ' \n";
  printf CMDFILE "set title 'A star at position of GX And ' \n";

  printf CMDFILE "set size square \n";

  
  $cmd = "plot [-400:400][-400:400] 'theory_gxand_nomu.out' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with points ls 1 ps 0.8 pt 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`;
  }

  
  
#############################################################################
#    Make a graph showing theoretical motion due to parallax
#        for a star at the position of GX And,
#        with no parallax, just proper motion.
#
  my($output_file, $term_options);

  $output_file = "theory_mu_only_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 top right \n";
  printf CMDFILE "set ylabel 'Motion in Dec (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Motion in RA (milliarcsec) ' \n";
  printf CMDFILE "set title 'A star with zero parallax, but proper motion ' \n";


  
  $cmd = "plot [][] 'theory_mu_only.out' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with points ls 1 ps 0.8 pt 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`;
  }

  
  
#############################################################################
#    Make a graph showing theoretical motion due to parallax
#        for a star at the position of GX And,
#        with small proper motion.
#
  my($output_file, $term_options);

  $output_file = "theory_small_mu_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 top right \n";
  printf CMDFILE "set ylabel 'Motion in Dec (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Motion in RA (milliarcsec) ' \n";
  printf CMDFILE "set title 'A star with parallax and small proper motion ' \n";

  
  $cmd = "plot [][] 'theory_small_mu.out' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with points ls 1 ps 0.8 pt 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`;
  }

  
  
#############################################################################
#    Make a graph showing theoretical motion due to parallax
#        for a star at the position of GX And,
#        with large proper motion.
#
  my($output_file, $term_options);

  $output_file = "theory_large_mu_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 top right \n";
  printf CMDFILE "set ylabel 'Motion in Dec (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Motion in RA (milliarcsec) ' \n";
  printf CMDFILE "set title 'A star with parallax and large proper motion ' \n";


  
  $cmd = "plot [][] 'theory_large_mu.out' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with points ls 1 ps 0.8 pt 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`;
  }

  
  
#############################################################################
#    Make a graph showing a small dataset which might be fit
#        by a parabola
#
  my($output_file, $term_options);

  $output_file = "example_data_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 'Potential energy of a spring (Joules) ' \n";
  printf CMDFILE "set xlabel 'Distance between left and right ends of the spring (cm) ' \n";
#  printf CMDFILE "set title 'GX And A, 2020 - 2021 '\n";
  
  $cmd = "plot [7:18][0:12] 'spring_data.dat' using (\$1-0):(\$2-0) ";
  $cmd .=  "     with points ls 1 ps 1.2 pt 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`;
  }

  
  
#############################################################################
#    Make a graph showing a small dataset which might be fit
#        by a parabola
#        together with a fitted parabolic model
#
  my($output_file, $term_options);

  $output_file = "example_data_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 'Potential energy of a spring (Joules) ' \n";
  printf CMDFILE "set xlabel 'Distance between left and right ends of the spring (cm) ' \n";
#  printf CMDFILE "set title 'GX And A, 2020 - 2021 '\n";
  
  $cmd = "plot [7:18][0:12] 'spring_data.dat' using (\$1-0):(\$2-0) ";
  $cmd .=  "     with points ls 1 ps 1.2 pt 3  t '' ";
  $cmd .=  " , ";
  $cmd .=  "  115.1-18.20*x+0.72857*x*x with lines ls 3 t 'quadratic model' ";

  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 
#        This is Procyon
#        This version has square axis ratio
#
  my($output_file, $term_options);

  $output_file = "procyon_dec_vs_ra_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 top right \n";
  printf CMDFILE "set ylabel 'Motion in Dec (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Motion in RA (milliarcsec) ' \n";
  printf CMDFILE "set title 'Procyon, 2020 - 2023 '\n";

  printf CMDFILE "set size square \n";

  
  $cmd = "plot [-3500:1000][-3500:1000] 'generate_ra_dec_procyon.out' using (\$2-0):(\$4-0):3:5  ";
  $cmd .=  "     with xyerrorbars ls 1  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;
