#!/usr/bin/perl
#
# Plots for (bulk) properties of discovered planets
# 
# MWR 9/28/2016

if (1 == 1) {
    
      ####################################################################
      #  planet mass vs. period, 
      #    with colors denoting discovery method
      #
      # get the arguments
      $output_file = "./planets_mass_period_m.ps";
      $term_options = "postscript monochrome 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 bot left Left reverse \n";
      printf CMDFILE "set xlabel 'Orbital Period (days) ' \n";
      printf CMDFILE "set ylabel 'Planet Mass (Jupiter units)' \n";
      printf CMDFILE "set title '' \n";
      printf CMDFILE "set logscale y  \n";
      printf CMDFILE "set logscale x  \n";
      printf CMDFILE "set datafile separator ',' \n";

      
      $cmd = "plot [0.1:1e6][1e-5:100] ";
      $cmd .= " './planet_table.transit.csv' using 7:23 ";
      $cmd .= "    with points pt 6 ps 0.2 lw 6 lt 1 lc -1 ";
      $cmd .= "    t '' ";
      $cmd .= " , ";
      $cmd .= " './planet_table.rv.csv' using 7:23 ";
      $cmd .= "    with points pt 6 ps 0.2 lw 6 lt 1 lc -1 ";
      $cmd .= "    t '' ";
      $cmd .= " , ";
      $cmd .= " './planet_table.imaging.csv' using 7:23 ";
      $cmd .= "    with points pt 6 ps 0.2 lw 5 lt 1 lc -1 ";
      $cmd .= "    t '' ";
      $cmd .= " , ";
      $cmd .= " './planet_table.microlensing.csv' using 7:23 ";
      $cmd .= "    with points pt 6 ps 0.2 lw 3 lt 1 lc -1 ";
      $cmd .= "    t '' ";
      $cmd .= " , ";
      $cmd .= " './planet_table.ttv.csv' using 7:23 ";
      $cmd .= "    with points pt 6 ps 0.2 lw 4 lt 1 lc -1 ";
      $cmd .= "    t '' ";
      $cmd .= " , ";
      $cmd .= " './planet_table.orbital.csv' using 7:23 ";
      $cmd .= "    with points pt 6 ps 0.2 lw 2 lt 1 lc -1 ";
      $cmd .= "    t '' ";
      $cmd .= " , ";
      $cmd .= " './planet_table.pulsar.csv' using 7:23 ";
      $cmd .= "    with points pt 6 ps 0.2 lw 4 lt 1 lc -1 ";
      $cmd .= "    t '' ";
      $cmd .= " , ";
      $cmd .= " './planet_table.eclipse.csv' using 7:23 ";
      $cmd .= "    with points pt 6 ps 0.2 lw 5 lt 1 lc -1 ";
      $cmd .= "    t '' ";
      $cmd .= " , ";
      $cmd .= " './planet_table.pulsation.csv' using 7:23 ";
      $cmd .= "    with points pt 6 ps 0.2 lw 5 lt 1 lc -1 ";
      $cmd .= "    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/.eps/.png/;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

}

exit 0;
