#!/usr/bin/perl
#


############################################################################
# create a graph comparing Wratten RGB filters to Bessell BVR
#
  

  # get the arguments
  $output_file = "compare_filters_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 bot right \n";
  printf CMDFILE "set ylabel 'Transmission ' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";

  printf CMDFILE "set multiplot layout 2, 1 title 'Comparison of Filters' \n";
  
  $cmd = "plot [3500:8000][0.0:1.1] '~/z1/snap/old_snap/spectra/spho/wratten_25.filter' ";
  $cmd .= "      using 1:(\$2/0.90) lc 1 lt 1 lw 3 with linespoints t 'Wratten 25' ";
  $cmd .= " , ";
  $cmd .= "   '~/z1/snap/old_snap/spectra/spho/wratten_58.filter' ";
  $cmd .= "      using 1:(\$2/0.57) lc 2 lt 1 lw 3 with linespoints t 'Wratten 58' ";
  $cmd .= " , ";
  $cmd .= "   '~/z1/snap/old_snap/spectra/spho/wratten_47.filter' ";
  $cmd .= "      using 1:(\$2/0.55) lc 3 lt 1 lw 3 with linespoints t 'Wratten 47' ";
  printf CMDFILE "$cmd \n";

  printf CMDFILE "set key top right \n";
  $cmd = "plot [3500:8000][0.0:1.1] '~/z1/snap/old_snap/spectra/spho/bess_r.pass' ";
  $cmd .= "      using 1:(\$2/1.00) lc 1 lt 1 lw 3 with lines t 'Bessell R' ";
  $cmd .= " , ";
  $cmd .= "   '~/z1/snap/old_snap/spectra/spho/bess_v.pass' ";
  $cmd .= "      using 1:(\$2/1.00) lc 2 lt 1 lw 3 with lines t 'Bessell V' ";
  $cmd .= " , ";
  $cmd .= "   '~/z1/snap/old_snap/spectra/spho/bess_b.pass' ";
  $cmd .= "      using 1:(\$2/1.00) lc 3 lt 1 lw 3 with lines t 'Bessell B' ";
  printf CMDFILE "$cmd \n";


  printf CMDFILE "unset multiplot \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;
