#!/usr/bin/perl
#


$suffix = sprintf "dat";

############################################################################
# create a file with GNUPLOT commands, then execute GNUPLOT to read
#   from that file.
#
# usage:  make_graph   outfile_file_name  set_term_options
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "comp_v_pass_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 xlabel 'Wavelength (Angstroms)' \n";
  printf CMDFILE "set ylabel '' \n";
  printf CMDFILE "set title 'Transmission of 2 V-band filters '\n";
  
  $cmd = "plot [4500:7000][0:100] 'bess-v.pass' using 1:(\$2*100) ";
  $cmd .= "   with linespoints lc 1 pt 3 ps 1 lw 4 ";
  $cmd .= "   t 'Bessell V' ";
  $cmd .= " , ";
  $cmd .= "   'w003.dat' using 1:(\$2*1.15) with points pt 4 ps 0.5 lc 3 lw 3 ";
  $cmd .= "   t 'WIYN V' ";

  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`;
  }



$suffix = sprintf "dat";

############################################################################
# Compare two filters AND two stars as well.
#
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "hotcool_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 xlabel 'Wavelength (Angstroms)' \n";
  printf CMDFILE "set ylabel '' \n";
  printf CMDFILE "set title 'Transmission of 2 V-band filters '\n";
  
  $cmd = "plot [4200:7000][0:100] 'bess-v.pass' using 1:(\$2*100) ";
  $cmd .= "   with linespoints lc 1 pt 3 ps 1 lw 4 ";
  $cmd .= "   t 'Bessell V' ";
  $cmd .= " , ";
  $cmd .= "   'w003.dat' using 1:(\$2*1.15) with linespoints pt 4 ps 0.5 lc 3 lw 3 ";
  $cmd .= "   t 'WIYN V' ";
  $cmd .= " , ";
  $cmd .= "   'uka0v.dat' using 1:(\$2*5e1) with lines lt 1 lc -1 lw 3 ";
  $cmd .= "   t 'Hot star A0V' ";
  $cmd .= " , ";
  $cmd .= "   'ukk0iii.dat' using 1:(\$2*5e1) with lines lt 1 lc 4 lw 3 ";
  $cmd .= "   t 'Cool star K0III' ";

  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;
