#!/usr/bin/perl
#

  
  my($output_file, $term_options);

  # histogram of semi-major axis, 0 - 60 AU, linear
  $output_file = "hist_a_1.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 'Minor planets with orbits, as of Oct 2018 '\n";
  
  $cmd = "plot [0:60][] 'hist_a.dat' using (\$1):(\$2)   ";
  $cmd .= "     with impulse 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`;
  }


  # histogram of semi-major axis, 0 - 60 AU, log on Y-axis
  $output_file = "hist_a_2.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 'Minor planets with orbits, as of Oct 2018 '\n";
  printf CMDFILE "set logscale y \n";
  printf CMDFILE "set label 1 'M' at 1.52,150000 \n"; 
  printf CMDFILE "set label 2 'J' at 5.20,150000 \n"; 
  printf CMDFILE "set label 3 'S' at 9.58,150000 \n"; 
  printf CMDFILE "set label 4 'U' at 19.20,150000 \n"; 
  printf CMDFILE "set label 5 'N' at 30.05,150000 \n"; 
  printf CMDFILE "set label 6 'P' at 39.48,150000 \n"; 
  
  $cmd = "plot [0:60][0.5:220000] 'hist_a_fine.dat' using (\$1):(\$2)   ";
  $cmd .= "     with impulse lw 2 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`;
  }



  # histogram of semi-major axis, 0 - 10 AU, log on Y-axis
  #    using "fine" histogram data
  $output_file = "hist_a_3.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 'Minor planets with orbits, as of Oct 2018 '\n";
  printf CMDFILE "set logscale y \n";
  printf CMDFILE "set label 1 'M' at 1.52,20000 \n"; 
  printf CMDFILE "set label 2 'J' at 5.20,20000 \n"; 
  printf CMDFILE "set label 3 'S' at 9.58,20000 \n"; 
  
  $cmd = "plot [0:10][] 'hist_a_fine.dat' using (\$1):(\$2)   ";
  $cmd .= "     with impulse 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`;
  }



  # histogram of semi-major axis, 0 - 5.5 AU, log on Y-axis
  #    using "fine" histogram data
  $output_file = "hist_a_4.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 'Minor planets with orbits, as of Oct 2018 '\n";
  printf CMDFILE "set logscale y \n";
  printf CMDFILE "set label 1 'E' at 1.00,20000 \n"; 
  printf CMDFILE "set label 2 'M' at 1.52,20000 \n"; 
  printf CMDFILE "set label 3 'J' at 5.20,20000 \n"; 
  
  $cmd = "plot [0:5.5][0.5:35000] 'hist_a_finer.dat' using (\$1):(\$2)   ";
  $cmd .= "     with impulse lw 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`;
  }



  # histogram of semi-major axis, 0 - 5.5 AU, linear on Y-axis
  #    using "fine" histogram data
  $output_file = "hist_a_5.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 y \n";
  printf CMDFILE "set ylabel 'Number of minor bodies' \n";
  printf CMDFILE "set xlabel 'Semi-major axis (AU) ' \n";
  printf CMDFILE "set title 'Minor planets with orbits, as of Oct 2018 '\n";
  printf CMDFILE "set label 1 'E' at 1.00,8500 \n"; 
  printf CMDFILE "set label 2 'M' at 1.52,8500 \n"; 
  printf CMDFILE "set label 3 'J' at 5.20,8500 \n"; 
  
  $cmd = "plot [0:5.5][] 'hist_a_finer.dat' using (\$1):(\$2)   ";
  $cmd .= "     with impulse lw 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`;
  }



  # histogram of semi-major axis, 30 - 60 AU, linear on Y-axis
  #    using "coarse" histogram data
  $output_file = "hist_a_6.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 'Minor planets with orbits, as of Oct 2018 '\n";
  printf CMDFILE "set label 1 'N' at 30.05,75 \n"; 
  printf CMDFILE "set label 2 'P' at 39.48,75 \n"; 
  
  $cmd = "plot [28:60][] 'hist_a.dat' using (\$1):(\$2)   ";
  $cmd .= "     with impulse 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`;
  }




  # histogram of semi-major axis, 0.3 - 1000 AU, logarithmic on Y-axis
  #    and on X-axis
  #    using "coarse" histogram data
  $output_file = "hist_a_7.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 'Minor planets with orbits, as of Oct 2018 '\n";
#  printf CMDFILE "set label 1 'J' at 5.20,750 \n"; 
  printf CMDFILE "set label 2 'S' at 9.58,50 \n"; 
  printf CMDFILE "set label 3 'U' at 19.20,50 \n"; 
  printf CMDFILE "set label 4 'N' at 30.05,50 \n"; 
  printf CMDFILE "set label 5 'P' at 39.48,50 \n"; 
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  
  
  $cmd = "plot [7:1000][0.1:1e3] 'hist_a_fine.dat' using (\$1):(\$2)   ";
  $cmd .= "     with impulse 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`;
  }




  # histogram of semi-major axis, 0 - 5.5 AU, linear on Y-axis
  #    using "fine" histogram data
  #    highlight the Kirkwood gaps
  $output_file = "hist_a_8.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 'Minor planets with orbits, as of Oct 2018 '\n";
  printf CMDFILE "set label 1 'M' at 1.52,11500 \n"; 
  printf CMDFILE "set label 2 'J' at 5.20,11500 \n"; 
  
  $cmd = "plot [0:5.5][] 'hist_a_fine.dat' using (\$1):(\$2)   ";
  $cmd .= "     with impulse t '' ";
  $cmd .= " , ";
  $cmd .= "     './kirkwood.dat' index 0  using 1:(5000+\$2*5000) ";
  $cmd .= "     with lines lc -1 lt 2 lw 3  t '' ";
  $cmd .= " , ";
  $cmd .= "     './kirkwood.dat' index 1  using 1:(5000+\$2*5000) ";
  $cmd .= "     with lines lc -1 lt 2 lw 3  t '' ";
  $cmd .= " , ";
  $cmd .= "     './kirkwood.dat' index 2  using 1:(5000+\$2*5000) ";
  $cmd .= "     with lines lc -1 lt 2 lw 3  t '' ";
  $cmd .= " , ";
  $cmd .= "     './kirkwood.dat' index 3  using 1:(5000+\$2*5000) ";
  $cmd .= "     with lines lc -1 lt 2 lw 3  t '' ";
  $cmd .= " , ";
  $cmd .= "     './kirkwood.dat' index 4  using 1:(5000+\$2*5000) ";
  $cmd .= "     with lines lc -1 lt 2 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`;
  }



  # histogram of semi-major axis, 0 - 5.5 AU, linear on Y-axis
  #    using "fine" histogram data
  #    highlight the Kirkwood gaps
  #    and add labels to the gaps
  $output_file = "hist_a_9.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 'Minor planets with orbits, as of Oct 2018 '\n";
  printf CMDFILE "set label 1 'M' at 1.52,11500 \n"; 
  printf CMDFILE "set label 2 'J' at 5.20,11500 \n"; 
  printf CMDFILE "set label 5 '2-1' at 3.284,9000 rotate by 90 \n"; 
  printf CMDFILE "set label 6 '3-1' at 2.506,9000 rotate by 90 \n"; 
  printf CMDFILE "set label 7 '4-1' at 2.069,9000 rotate by 90 \n"; 
  printf CMDFILE "set label 8 '5-2' at 2.830,9000 rotate by 90 \n"; 
  printf CMDFILE "set label 9 '7-3' at 2.963,9000 rotate by 90 \n"; 
  
  $cmd = "plot [0:5.5][0:10000] 'hist_a_finer.dat' using (\$1):(\$2)   ";
  $cmd .= "     with impulse lw 2 t '' ";
  $cmd .= " , ";
  $cmd .= "     './kirkwood.dat' index 0  using 1:(2000+\$2*6500) ";
  $cmd .= "     with lines lc -1 lt 2 lw 3  t '' ";
  $cmd .= " , ";
  $cmd .= "     './kirkwood.dat' index 1  using 1:(2000+\$2*6500) ";
  $cmd .= "     with lines lc -1 lt 2 lw 3  t '' ";
  $cmd .= " , ";
  $cmd .= "     './kirkwood.dat' index 2  using 1:(2000+\$2*6500) ";
  $cmd .= "     with lines lc -1 lt 2 lw 3  t '' ";
  $cmd .= " , ";
  $cmd .= "     './kirkwood.dat' index 3  using 1:(2000+\$2*6500) ";
  $cmd .= "     with lines lc -1 lt 2 lw 3  t '' ";
  $cmd .= " , ";
  $cmd .= "     './kirkwood.dat' index 4  using 1:(2000+\$2*6500) ";
  $cmd .= "     with lines lc -1 lt 2 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`;
  }



  # histogram of semi-major axis, 0.3 - 1000 AU, logarithmic on Y-axis
  #    and on X-axis
  #    using "coarse" histogram data
  $output_file = "hist_a_10.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 'Minor planets with orbits, as of Oct 2018 '\n";
#  printf CMDFILE "set label 1 'J' at 5.20,750 \n"; 
  printf CMDFILE "set label 2 'S' at 9.58,50 \n"; 
  printf CMDFILE "set label 3 'U' at 19.20,50 \n"; 
  printf CMDFILE "set label 4 'N' at 30.05,50 \n"; 
  printf CMDFILE "set label 5 'P' at 39.48,50 \n"; 
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  
  
  $cmd = "plot [0.8:1000][0.1:1e5] 'hist_a_fine.dat' using (\$1):(\$2)   ";
  $cmd .= "     with impulse 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`;
  }




  # histogram of semi-major axis, 30 - 60 AU, linear on Y-axis
  #    and on X-axis
  #    using "fine" histogram data
  #    focus on gaps in the Kuiper Belt
  $output_file = "hist_a_11.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 'Minor planets with orbits, as of Oct 2018 '\n";
#  printf CMDFILE "set label 1 'J' at 5.20,750 \n"; 
  printf CMDFILE "set label 2 'S' at 9.58,50 \n"; 
  printf CMDFILE "set label 3 'U' at 19.20,50 \n"; 
  printf CMDFILE "set label 4 'N' at 30.05,50 \n"; 
  printf CMDFILE "set label 5 'P' at 39.48,50 \n"; 
  
  
  $cmd = "plot [30:60][] 'hist_a_fine.dat' using (\$1):(\$2)   ";
  $cmd .= "     with impulse lw 2 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;
