#!/usr/bin/perl
#

  
  my($output_file, $term_options);

  # light curves for RXJ 1131
  $output_file = "rxj1131_curves_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 'relative R-band magnitude '  \n";
  printf CMDFILE "set xlabel 'Julian Day - 2452900 '  \n";
  printf CMDFILE "set title 'RXJ 1131-1231 light curves '\n";
  
  $cmd = "plot [][4.8:0.8]  ";
  $cmd .= "   './rxj1131_mags.dat' using (\$1-2452900):2 ";
  $cmd .= "        with points ps 0.5 lc rgbcolor \"red\"  ";
  $cmd .= " , ";
  $cmd .= "   './rxj1131_mags.dat' using (\$1-2452900):4 ";
  $cmd .= "        with points ps 0.5 lc rgbcolor \"blue\"  ";
  $cmd .= " , ";
  $cmd .= "   './rxj1131_mags.dat' using (\$1-2452900):6 ";
  $cmd .= "        with points ps 0.5 lc rgbcolor \"black\"  ";
  $cmd .= " , ";
  $cmd .= "   './rxj1131_mags.dat' using (\$1-2452900):8 ";
  $cmd .= "        with points ps 0.5 lc rgbcolor \"dark-green\"  ";

  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;
