#!/usr/bin/perl


  my($output_file, $term_options);

  # graph showing magnitude as a function of airmass
  #    to derive extinction coefficient
  $output_file = "ext_graph_a.ps";
  $term_options = "postscript 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 grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Instrumental magnitude' \n";
  printf CMDFILE "set xlabel 'Airmass ' \n";
  printf CMDFILE "set title 'Measurements of a star on Jul 27, 2001'\n";
  
  $cmd = "plot [1.0:2.0][12.56:12.80] ";
  $cmd .=  "  './stara_jul27.dat' using (\$1):(\$9) ";
  $cmd .=  "      with points pt 3 ps 0.5 lc 1 lw 2 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`;
  }


  # graph showing magnitude as a function of airmass
  #    to derive extinction coefficient
  #    this includes a linear fit as well
  $output_file = "ext_graph_b.ps";
  $term_options = "postscript 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 grid \n";
  printf CMDFILE "set key bot right \n";
  printf CMDFILE "set ylabel 'Instrumental magnitude' \n";
  printf CMDFILE "set xlabel 'Airmass ' \n";
  printf CMDFILE "set title 'Measurements of a star on Jul 27, 2001'\n";
  
  $cmd = "plot [1.0:2.0][12.56:12.80] ";
  $cmd .=  "  './stara_jul27.dat' using (\$1):(\$9) ";
  $cmd .=  "      with points pt 3 ps 0.5 lc 1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  12.456 + 0.15366*x with lines lt 1 lc -1 lw 2  t 'slope 0.15' ";

  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;



