#!/usr/bin/perl
#

  
  my($output_file, $term_options);

  # Human eye, normalized so peak response is "1.0"
  $output_file = "./scotopic_norm.ps";
  $term_options = "postscript color enhanced font '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 nokey \n";
  printf CMDFILE "set xlabel 'Wavelength (nm)' \n";
  printf CMDFILE "set title 'Scotopic response of the human eye (normalized) '\n", $aper;
  
  $cmd = "plot [350:800][0:1.0] './scotopic.dat' using (\$1):(\$2)   ";
  $cmd .= "   with lines lc 1 lw 4";

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



  # Human eye, absolute scale 
  $output_file = "./scotopic_abs.ps";
  $term_options = "postscript color enhanced font '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 nokey \n";
  printf CMDFILE "set xlabel 'Wavelength (nm)' \n";
  printf CMDFILE "set ylabel 'Quantum efficiency (percent)' \n";
  printf CMDFILE "set title 'Scotopic response of the human eye (absolute) '\n", $aper;
  
  $cmd = "plot [350:800][0:100.0] './scotopic.dat' using (\$1):(\$2*100*0.06)   ";
  $cmd .= "   with lines lc 1 lw 4";

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


  
  my($output_file, $term_options);

  # Photo film, scaled so peak is "1.0"
  $output_file = "./film_norm.ps";
  $term_options = "postscript color enhanced font '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 nokey \n";
  printf CMDFILE "set xlabel 'Wavelength (nm)' \n";
  printf CMDFILE "set title 'Response of Kodak Tech Pan Film (normalized) '\n", $aper;
  
  $cmd = "plot [350:800][0:1.0] './techpan_qe.dat' using (\$1):(\$3/1.057)   ";
  $cmd .= "   with lines lc 2 lw 4";

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



  # Photographic emulsion, absolute scale 
  $output_file = "./film_abs.ps";
  $term_options = "postscript color enhanced font '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 (nm)' \n";
  printf CMDFILE "set ylabel 'Quantum efficiency (percent)' \n";
  printf CMDFILE "set title 'Response of Kodak Tech Pan Film (absolute) '\n", $aper;
  
  $cmd = "plot [350:800][0:100.0] './techpan_qe.dat' using (\$1):(\$3)   ";
  $cmd .= "   with lines lc 2 lw 4 t 'normal'";
  $cmd .= " , ";
  $cmd .= "                        './techpan_qe.dat' using (\$1):(\$4)   ";
  $cmd .= "   with lines lc 2 lw 4 t 'hypered' ";

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




  # Photographic emulsion vs. human eye, absolute scale
  $output_file = "./film_vs_eye.ps";
  $term_options = "postscript color enhanced font '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 (nm)' \n";
  printf CMDFILE "set ylabel 'Quantum efficiency (percent)' \n";
  printf CMDFILE "set title 'Film vs. the eye '\n", $aper;
  
  $cmd = "plot [350:800][0:100.0] './techpan_qe.dat' using (\$1):(\$4)   ";
  $cmd .= "   with lines lt 2 lc 2 lw 4 t 'hypered film'";
  $cmd .= " , ";
  $cmd .= "                        './scotopic.dat' using (\$1):(\$2*100*0.06)   ";
  $cmd .= "   with lines lt 1 lc 1 lw 4 t 'human eye'";

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




  # History of papers published in AJ and PASP:  "photographic"
  $output_file = "./papers_photo.ps";
  $term_options = "postscript color enhanced font '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 'Year' \n";
  printf CMDFILE "set ylabel 'Percentage of all papers in journal' \n";
  printf CMDFILE "set title 'Papers with \"photographic\" in Abstract ' \n", $aper;
  
  $cmd = "plot [1945:2020][-2:30] './aj_data.dat' using (\$1+2.5):(100*(\$3/\$2))   ";
  $cmd .= "   with boxes lt 1 lc 1 lw 4 t 'Astronomical Journal' ";
  $cmd .= " , ";
  $cmd .= "                        './pasp_data.dat' using (\$1+3.5):(100*(\$3/\$2))   ";
  $cmd .= "   with boxes lt 1 lc 3 lw 4 t 'Publ. of the ASP '";

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



  # Comparison of papers published in AJ and PASP:  
  #   "photographic" vs. "CCD" 
  $output_file = "./papers_photo_ccd.ps";
  $term_options = "postscript color enhanced font '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 'Year' \n";
  printf CMDFILE "set ylabel 'Percentage of all papers in journal' \n";
  printf CMDFILE "set title 'Comparison of papers with \"photographic\" vs. \"CCD\" ' \n", $aper;
  
  $cmd = "plot [1945:2020][-2:30] './aj_data.dat' using (\$1+2.5):(100*(\$3/\$2))   ";
  $cmd .= "   with boxes lt 1 lc 1 lw 2 t 'AJ: photographic' ";
  $cmd .= " , ";
  $cmd .= "                        './pasp_data.dat' using (\$1+3.5):(100*(\$3/\$2))   ";
  $cmd .= "   with boxes lt 1 lc 3 lw 2 t 'PASP: photographic '";
  $cmd .= " , ";
  $cmd .= "                        './aj_data.dat' index 1 using (\$1+0.0):(100*(\$4/\$2))   ";
  $cmd .= "   with points pt 4 ps 3 lt 1 lc 1 lw 4 t 'AJ: CCD' ";
  $cmd .= " , ";
  $cmd .= "                        './pasp_data.dat' index 1 using (\$1+1.0):(100*(\$4/\$2))   ";
  $cmd .= "   with points pt 6 ps 3 lt 1 lc 3 lw 4 t 'PASP: CCD' ";


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






  # CCD QE, absolute scale 
  $output_file = "./ccd_abs.ps";
  $term_options = "postscript color enhanced font '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 (nm)' \n";
  printf CMDFILE "set ylabel 'Quantum efficiency (percent)' \n";
  printf CMDFILE "set title 'Response of e2V CCD231 (absolute) '\n", $aper;
  
  $cmd = "plot [350:800][0:100.0] './ccd_qe.dat' using (\$1):(\$2)   ";
  $cmd .= "   with lines lc 3 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`;
  }




  # Photographic emulsion vs. human eye, absolute scale
  $output_file = "./film_vs_eye_vs_ccd.ps";
  $term_options = "postscript color enhanced font '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 (nm)' \n";
  printf CMDFILE "set ylabel 'Quantum efficiency (percent)' \n";
  printf CMDFILE "set title 'Film vs. the eye vs. CCD '\n", $aper;
  
  $cmd = "plot [350:800][0:100.0] './techpan_qe.dat' using (\$1):(\$4)   ";
  $cmd .= "   with lines lt 2 lc 2 lw 4 t 'hypered film'";
  $cmd .= " , ";
  $cmd .= "                        './scotopic.dat' using (\$1):(\$2*100*0.06)   ";
  $cmd .= "   with lines lt 1 lc 1 lw 4 t 'human eye'";
  $cmd .= " , ";
  $cmd .= "                        './ccd_qe.dat' using (\$1):(\$2)   ";
  $cmd .= "   with lines lt 1 lc 3 lw 3 t 'CCD'";

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





  # Linearity of photographic emulsion vs. CCD
  $output_file = "./film_vs_ccd_lin.ps";
  $term_options = "postscript color enhanced font '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 size square \n";
  printf CMDFILE "set key bot right \n";
  printf CMDFILE "set xlabel 'Exposure time (sec)' \n";
  printf CMDFILE "set ylabel 'Response (density or ADU) ' \n";
  printf CMDFILE "set title 'Linearity of film vs. CCD '\n", $aper;
  
  $cmd = "plot [-0.2:5][-0.2:5] './techpan_curve.dat' using (3*10**(\$1)):2   ";
  $cmd .= "   with points pt 4 ps 1 lc 2 lw 4 t 'film'";
  $cmd .= " , ";
  $cmd .= "    './e2v_linearity.dat' using (\$1*(0.016)):(\$2*(0.00007))  ";
  $cmd .= "   with points pt 5 ps 0.8 lc 3 lw 3 t 'CCD'";

  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;

