#!/usr/bin/perl
#

  
  my($output_file, $term_options);

  # plot of semi-major axis, 0 - 25 AU, linear
  $output_file = "planet_dist_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 'Number of minor bodies' \n";
  printf CMDFILE "set xlabel 'Semi-major axis (AU) ' \n";
  printf CMDFILE "set title 'Size of planetary orbits '\n";
  
  $cmd = "plot [0.2:25][0.1:1.5] 'planet_dist.dat' index 0 using (\$1):(\$2)   ";
  $cmd .= "     with points pt 6 ps 1.5 lw 5 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`;
  }



  # plot of semi-major axis, 0 - 25 AU, log x
  $output_file = "planet_dist_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 logscale x \n";
#  printf CMDFILE "set ylabel 'Number of minor bodies' \n";
  printf CMDFILE "set xlabel 'Semi-major axis (AU) ' \n";
  printf CMDFILE "set title 'Size of planetary orbits '\n";
  
  $cmd = "plot [0.2:25][0.1:1.5] 'planet_dist.dat' index 0 using (\$1):(\$2)   ";
  $cmd .= "     with points pt 6 ps 1.5 lw 5 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`;
  }


  # plot of semi-major axis, 0 - 25 AU, log x
  #   now add Ceres
  $output_file = "planet_dist_c.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 logscale x \n";
#  printf CMDFILE "set ylabel 'Number of minor bodies' \n";
  printf CMDFILE "set xlabel 'Semi-major axis (AU) ' \n";
  printf CMDFILE "set title 'Size of planetary orbits '\n";
  
  $cmd = "plot [0.2:25][0.1:1.5] 'planet_dist.dat' index 0 using (\$1):(\$2)   ";
  $cmd .= "     with points pt 6 ps 1.5 lw 5 t '' ";
  $cmd .= " , ";
  $cmd .= "         'planet_dist.dat' index 1 using 1:2 ";
  $cmd .= "     with points pt 4 ps 1.5 lc 3 lw 5 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`;
  }


  # plot of semi-major axis, 0 - 25 AU, log x
  #   now add Ceres, and next 3 asteroids
  $output_file = "planet_dist_d.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 logscale x \n";
#  printf CMDFILE "set ylabel 'Number of minor bodies' \n";
  printf CMDFILE "set xlabel 'Semi-major axis (AU) ' \n";
  printf CMDFILE "set title 'Size of planetary orbits '\n";
  
  $cmd = "plot [0.2:25][0.1:1.5] 'planet_dist.dat' index 0 using (\$1):(\$2)   ";
  $cmd .= "     with points pt 6 ps 1.5 lw 5 t '' ";
  $cmd .= " , ";
  $cmd .= "         'planet_dist.dat' index 1 using 1:2 ";
  $cmd .= "     with points pt 4 ps 1.5 lc 3 lw 5 t '' ";
  $cmd .= " , ";
  $cmd .= "         'planet_dist.dat' index 2 using 1:2 ";
  $cmd .= "     with points pt 4 ps 1.5 lc 3 lw 5 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;
