#!/usr/bin/perl
#

  my($output_file, $term_options);


  # First, we try linear relationship
  $output_file = "kepler3_a.ps";
  $term_options = "postscript enhanced 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";
#  printf CMDFILE "set size square \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set ylabel 'Period of orbit (years)' \n";
  printf CMDFILE "set xlabel 'Distance from Sun (AU) ' \n";
  printf CMDFILE "set title 'Period proportional to distance? '\n";

  $cmd = "plot [0.0:11.0][0.0:33] 'planet_data.dat' using 2:3 ";
  $cmd .= "  with points pt 6 ps 2.0 lt 1 lc 1 lw 3 ";

  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`;
  }



  # Next, we try quadratic relationship
  $output_file = "kepler3_b.ps";
  $term_options = "postscript enhanced 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";
#  printf CMDFILE "set size square \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set ylabel 'Period of orbit (years)' \n";
  printf CMDFILE "set xlabel 'Square of distance from Sun (AU) ' \n";
  printf CMDFILE "set title 'Period proportional to distance squared? '\n";

  $cmd = "plot [0.0:100.0][0.0:33] 'planet_data.dat' using (\$2*\$2):3 ";
  $cmd .= "  with points pt 6 ps 2.0 lt 1 lc 1 lw 3 ";

  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`;
  }



  # Finally, we try Kepler's version -- on linear graph
  $output_file = "kepler3_c.ps";
  $term_options = "postscript enhanced 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";
#  printf CMDFILE "set size square \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set ylabel 'Square of period of orbit (years)' \n";
  printf CMDFILE "set xlabel 'Cube of distance from Sun (AU) ' \n";
  printf CMDFILE "set title 'Period squared proportional to distance cubed? '\n";

  $cmd = "plot [0.0:1000.0][0.0:1000] 'planet_data.dat' using (\$2*\$2*\$2):(\$3*\$3) ";
  $cmd .= "  with points pt 6 ps 2.0 lt 1 lc 1 lw 3 ";

  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`;
  }



  # Finally, we try Kepler's version -- on log-log graph
  $output_file = "kepler3_d.ps";
  $term_options = "postscript enhanced 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";
#  printf CMDFILE "set size square \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set logscale x  \n";
  printf CMDFILE "set logscale y  \n";
  printf CMDFILE "set ylabel 'Square of period of orbit (years)' \n";
  printf CMDFILE "set xlabel 'Cube of distance from Sun (AU) ' \n";
  printf CMDFILE "set title 'Period squared proportional to distance cubed? '\n";

  $cmd = "plot [0.01:1100.0][0.01:1100] 'planet_data.dat' using (\$2*\$2*\$2):(\$3*\$3) ";
  $cmd .= "  with points pt 6 ps 2.0 lt 1 lc 1 lw 3 ";

  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;

