#!/usr/bin/perl
#


  ########################################################################
  #  Simple graph showing star alone, moving
  #

  $output_file = "./astrom_alone_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 top right \n";
  printf CMDFILE "set ylabel 'Declination (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Right Ascension (milliarcsec) ' \n";
  printf CMDFILE "set title 'Motion of a star over 100 years '\n";
  
  $cmd = "plot [0:500][0:30]  15+(0.0*x) ";
  $cmd .= "   with linespoints lt 1 pt 1 lw 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`;
  }




  ########################################################################
  #  graph showing one star and its planet moving in a straight line
  #     adding in some transverse component due to orbit around CoM
  #

  $output_file = "./astrom_orbit_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 top right \n";
  printf CMDFILE "set ylabel 'Declination (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Right Ascension (milliarcsec) ' \n";
  printf CMDFILE "set title 'Motion of a star with planet over 100 years '\n";
  
  $cmd = "plot [0:500][-120:150]  'calc_astrom.out' using 4:6 ";
  $cmd .= "   with linespoints lt 1 pt 1 lw 4 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'calc_astrom.out' using 8:10 ";
  $cmd .= "   with linespoints lc 3 lt 1 pt 1 ps 0.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 showing one star ONLY moving in a straight line
  #     but add in some transverse component due to orbit around CoM
  #

  $output_file = "./astrom_orbit_b.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 top right \n";
  printf CMDFILE "set ylabel 'Declination (milliarcsec) ' \n";
  printf CMDFILE "set xlabel 'Right Ascension (milliarcsec) ' \n";
  printf CMDFILE "set title 'Motion of a star with planet over 100 years '\n";
  
  $cmd = "plot [0:500][-120:150]  'calc_astrom.out' using 4:6 ";
  $cmd .= "   with linespoints lt 1 pt 1 lw 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;

