#!/usr/bin/perl
#
# Practice making Hammer-Aitoff plots
#

$cmdfile = "./makeplot.gnu";



#####################################################################
# Create a graph showing planets in ecliptic long/lat
#    regular Mercator projection
#

  $infile = "planets_eclip.dat";
  $outfile = "planets_eclip_a.ps";

  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$outfile' \n";
  printf CMDFILE "set term postscript color 'Helvetica,18' \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set xlabel 'Ecliptic longitude (degrees)' \n";
  printf CMDFILE "set ylabel 'Ecliptic latitude (degrees) ' \n";
  
  $cmd = "plot [-10:370][-100:100] '$infile' using 2:1  ";
  $cmd .= "      with points pt 5 ps 0.4 lc 1 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;

  # create a PNG copy of any Postscript file
    $png_file = $outfile;
    $png_file =~ s/.ps/.png/;
    $cmd = "convert -flatten -background white -rotate 90 $outfile $png_file ";
    printf "cmd is ..$cmd.. \n";
    $retval = `$cmd`;



#####################################################################
# Create a graph showing planets in galactic long/lat
#    regular Mercator projection
#

  $infile = "planets_gal.dat";
  $outfile = "planets_gal_a.ps";

  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$outfile' \n";
  printf CMDFILE "set term postscript color 'Helvetica,18' \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set xlabel 'Galactic longitude (degrees)' \n";
  printf CMDFILE "set ylabel 'Galactic latitude (degrees) ' \n";
  
  $cmd = "plot [-10:370][-100:100] '$infile' using 2:1  ";
  $cmd .= "      with points pt 5 ps 0.4 lc 1 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;

  # create a PNG copy of any Postscript file
    $png_file = $outfile;
    $png_file =~ s/.ps/.png/;
    $cmd = "convert -flatten -background white -rotate 90 $outfile $png_file ";
    printf "cmd is ..$cmd.. \n";
    $retval = `$cmd`;






exit 0;



