#!/usr/bin/perl
#

  $output_file = "co2_trend_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 'CO_2 concentration (parts per million) ' \n";
  printf CMDFILE "set xlabel 'Year ' \n";
  printf CMDFILE "set title 'Measurements from Mauna Kea, corrected for seasonal trends '\n";
  
  $cmd = "plot [][300:420] 'co2_mm_mlo.txt' using (\$3):(\$6)  ";
  $cmd .= "    with points lt 1 lc 1 pt 3 ps 0.8 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`;
  }


exit 0;
