#!/usr/bin/perl
#

  
  my($output_file, $term_options);

  # Plot showing H0 values over time, long view 1920 - 2010 or so
  #
  $output_file = "hval_long_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 "unset key \n";
  printf CMDFILE "set ylabel 'H0 (km/s/Mpc) '  \n";
  printf CMDFILE "set xlabel 'Years ' \n";
  printf CMDFILE "set title 'Measurements of H0 (thanks to John Huchra) '\n";
  
  $cmd = "plot [1920:2020][]  ";
  $cmd .= "   './hubble_plot.dat' using (\$4+0):1 ";
  $cmd .= "      with points pt 3 ps 0.5 lc rgbcolor \"blue\" ";


  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 -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  # Plot showing H0 values over time, recent view 1960 - 2010 or so
  #
  $output_file = "hval_med_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 "unset key \n";
  printf CMDFILE "set ylabel 'H0 (km/s/Mpc) '  \n";
  printf CMDFILE "set xlabel 'Years ' \n";
  printf CMDFILE "set title 'Measurements of H0 (thanks to John Huchra) '\n";
  
  $cmd = "plot [1960:2020][0:150]  ";
  $cmd .= "   './hubble_plot.dat' using (\$4+0):1 ";
  $cmd .= "      with points pt 3 ps 0.5 lc -1 ";


  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 -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }




  # Plot showing H0 values over time, recent view 1960 - 2010 or so
  #    Highlight "Sandage" and "deVaucouleurs"
  #
  $output_file = "hval_med_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 ylabel 'H0 (km/s/Mpc) '  \n";
  printf CMDFILE "set xlabel 'Years ' \n";
  printf CMDFILE "set title 'Measurements of H0 (thanks to John Huchra) '\n";
  
  $cmd = "plot [1960:2020][0:150]  ";
  $cmd .= "   './hubble_plot.dat' using (\$4+0):1 ";
  $cmd .= "      with points pt 3 ps 0.5 lc rgbcolor \"black\" ";
  $cmd .= "      t '' ";
  $cmd .= " , ";
  $cmd .= "   './hubble_sandage.dat' using (\$4+0):1 ";
  $cmd .= "      with points pt 6 ps 1.5 lw 3 lc rgbcolor \"red\" ";
  $cmd .= "      t 'Sandage' ";
  $cmd .= " , ";
  $cmd .= "   './hubble_devauc.dat' using (\$4+0):1 ";
  $cmd .= "      with points pt 6 ps 1.5 lw 3 lc rgbcolor \"blue\" ";
  $cmd .= "      t 'deVaucouleurs' ";


  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 -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  # Plot showing H0 values over time, very recent view
  #    highlight classical ladded + inverse ladder
  #
  $output_file = "hval_recent_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 'H0 (km/s/Mpc) '  \n";
  printf CMDFILE "set xlabel 'Years ' \n";
  printf CMDFILE "set title 'Measurements of H0 (thanks to John Huchra) '\n";
  
  $cmd = "plot [2000:2020][50:90]  ";
  $cmd .= "   './hubble_plot.dat' using (\$4+0):1 ";
  $cmd .= "      with points pt 3 ps 0.5 lc rgbcolor \"black\"  ";
  $cmd .= "      t '' ";
  $cmd .= " , ";
  $cmd .= "   './hubble_current.dat' index 0 using (\$4+0):1:2 ";
  $cmd .= "      with yerrorbars pt 6 ps 1.5 lc rgbcolor \"red\" lw 3 ";
  $cmd .= "      t 'inverse ladder' ";
  $cmd .= " , ";
  $cmd .= "   './hubble_current.dat' index 1 using (\$4+0):1:2 ";
  $cmd .= "      with yerrorbars pt 4 ps 1.5 lc rgbcolor \"blue\" lw 3 ";
  $cmd .= "      t 'classic ladder' ";
#  $cmd .= " , ";
#  $cmd .= "   './hubble_current.dat' index 2 using (\$4+0):1:2 ";
#  $cmd .= "      with yerrorbars pt 4 ps 1.5 lc rgbcolor \"blue\" lw 3 ";
#  $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/.ps/.png/;
    $cmd = "convert -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  # Plot showing H0 values over time, very recent view
  #    highlight classical ladded + inverse ladder
  #    includes Jang and Lee 2017
  $output_file = "hval_recent_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 ylabel 'H0 (km/s/Mpc) '  \n";
  printf CMDFILE "set xlabel 'Years ' \n";
  printf CMDFILE "set title 'Measurements of H0 (thanks to John Huchra) '\n";
  
  $cmd = "plot [2000:2020][50:90]  ";
  $cmd .= "   './hubble_plot.dat' using (\$4+0):1 ";
  $cmd .= "      with points pt 3 ps 0.5 lc rgbcolor \"black\"  ";
  $cmd .= "      t '' ";
  $cmd .= " , ";
  $cmd .= "   './hubble_current.dat' index 0 using (\$4+0):1:2 ";
  $cmd .= "      with yerrorbars pt 6 ps 1.5 lc rgbcolor \"red\" lw 3 ";
  $cmd .= "      t 'inverse ladder' ";
  $cmd .= " , ";
  $cmd .= "   './hubble_current.dat' index 1 using (\$4+0):1:2 ";
  $cmd .= "      with yerrorbars pt 4 ps 1.5 lc rgbcolor \"blue\" lw 3 ";
  $cmd .= "      t 'classic ladder' ";
  $cmd .= " , ";
  $cmd .= "   './hubble_current.dat' index 2 using (\$4+0):1:2 ";
  $cmd .= "      with yerrorbars pt 4 ps 1.5 lc rgbcolor \"blue\" lw 3 ";
  $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/.ps/.png/;
    $cmd = "convert -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  # Plot showing H0 values over time, very recent view
  #    highlight classical ladded + inverse ladder
  #    includes references 2015-2020
  $output_file = "hval_recent_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 ylabel 'H0 (km/s/Mpc) '  \n";
  printf CMDFILE "set xlabel 'Years ' \n";
  printf CMDFILE "set title 'Measurements of H0 (thanks to John Huchra) '\n";
  
  $cmd = "plot [2000:2022][50:90]  ";
  $cmd .= "   './hubble_plot.dat' using (\$4+0):1 ";
  $cmd .= "      with points pt 3 ps 0.5 lc rgbcolor \"black\"  ";
  $cmd .= "      t '' ";
  $cmd .= " , ";
  $cmd .= "   './hubble_current.dat' index 0 using (\$4+0):1:2 ";
  $cmd .= "      with yerrorbars pt 6 ps 1.5 lc rgbcolor \"red\" lw 3 ";
  $cmd .= "      t 'CMB + BAO' ";
  $cmd .= " , ";
  $cmd .= "   './hubble_current.dat' index 1 using (\$4+0):1:2 ";
  $cmd .= "      with yerrorbars pt 4 ps 1.5 lc rgbcolor \"blue\" lw 3 ";
  $cmd .= "      t 'classic ladder' ";
  $cmd .= " , ";
  $cmd .= "   './hubble_current.dat' index 2 using (\$4+0):1:2 ";
  $cmd .= "      with yerrorbars pt 4 ps 1.5 lc rgbcolor \"blue\" lw 3 ";
  $cmd .= "      t '' ";
  $cmd .= " , ";
  $cmd .= "   './hubble_current.dat' index 3 using (\$4+0):1:2 ";
  $cmd .= "      with yerrorbars pt 3 ps 1.0 lc rgbcolor \"black\" lw 2 ";
  $cmd .= "      t 'lenses' ";
  $cmd .= " , ";
  $cmd .= "   './hubble_current.dat' index 4 using (\$4+0):1:2 ";
  $cmd .= "      with yerrorbars pt 5 ps 1.5 lc rgbcolor \"dark-plum\" lw 2 ";
  $cmd .= "      t 'megamasers' ";
#  $cmd .= " , ";
#  $cmd .= "   './hubble_current.dat' index 5 using (\$4+0):1:2 ";
#  $cmd .= "      with yerrorbars pt 4 ps 1.5 lc rgbcolor \"black\" lw 3 ";
#  $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/.ps/.png/;
    $cmd = "convert -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }





exit 0;
