#!/usr/bin/perl


  my($output_file, $term_options);

  # basic graph showing regions of transmission
  #    color codes for source of data
  $output_file = "window_trans_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 logscale x \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Transmission' \n";
  printf CMDFILE "set xlabel 'Wavelength (meters) ' \n";
  printf CMDFILE "set title 'Transmission of atmosphere of Earth '\n";
  
  $cmd = "plot [1.0e-7:1.0e2][-0.05:1.2] ";
#  $cmd = "plot [1.0e-7:1.0e-5][0.0:1.5] ";
  $cmd .=  "  './mm_trans.dat' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 lc 1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './mktrans_zm_10_10.dat' every 100 using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc 3 lw 1 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './mktrans_nq_10_10.dat' every 100 using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc 4 lw 1 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './modtran_maunakea.txt' using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc 2 lw 3 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './long_radio.dat' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 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`;
  }


  # basic graph showing regions of transmission
  #    all data a single color
  $output_file = "window_trans_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 logscale x \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Transmission' \n";
  printf CMDFILE "set xlabel 'Wavelength (meters) ' \n";
  printf CMDFILE "set title 'Transmission of atmosphere of Earth '\n";
  
  $cmd = "plot [1.0e-7:1.0e2][-0.05:1.2] ";
#  $cmd = "plot [1.0e-7:1.0e-5][0.0:1.5] ";
  $cmd .=  "  './mm_trans.dat' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './mktrans_zm_10_10.dat' every 100 using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 1 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './mktrans_nq_10_10.dat' every 100 using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 1 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './modtran_maunakea.txt' using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './long_radio.dat' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 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`;
  }

  # basic graph showing regions of transmission
  #    all data a single color
  #    very wide range, to include gamma rays
  #    does NOT include text labels
  $output_file = "window_trans_c.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 logscale x \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Transmission' \n";
  printf CMDFILE "set xlabel 'Wavelength (meters) ' \n";
  printf CMDFILE "set title 'Transmission of atmosphere of Earth '\n";

  $cmd = "plot [1.0e-19:1.0e2][-0.05:1.4] ";
#  $cmd = "plot [1.0e-7:1.0e-5][0.0:1.5] ";
  $cmd .=  "  './mm_trans.dat' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './mktrans_zm_10_10.dat' every 100 using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 1 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './mktrans_nq_10_10.dat' every 100 using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 1 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './modtran_maunakea.txt' using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './long_radio.dat' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './short_gamma.dat' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 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`;
  }


  # basic graph showing regions of transmission
  #    all data a single color
  #    very wide range, to include gamma rays
  #    does include text labels
  $output_file = "window_trans_d.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 logscale x \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Transmission' \n";
  printf CMDFILE "set xlabel 'Wavelength (meters) ' \n";
  printf CMDFILE "set title 'Transmission of atmosphere of Earth '\n";

  printf CMDFILE "set label 1 at 0.8E-18,1.1 'TeV' center tc rgbcolor 'violet' \n";
  printf CMDFILE "set label 2 at 0.8E-15,1.1 'GeV' center tc rgbcolor 'blue' \n";
  printf CMDFILE "set label 3 at 0.8E-12,1.1 'MeV' center tc rgbcolor 'dark-green' \n";
  printf CMDFILE "set label 4 at 0.8E-09,1.1 'keV' center tc rgbcolor 'dark-orange' \n";
  printf CMDFILE "set label 5 at 1.0E-06,1.1 '{/Symbol m}m' center tc rgbcolor 'black' \n";
  printf CMDFILE "set label 6 at 1.0E-03,1.1 'mm' center tc rgbcolor 'red' \n";

  printf CMDFILE "set label 7 at 0.33E2,1.3 'MHz' center tc rgbcolor 'red' \n";
  printf CMDFILE "set label 8 at 0.33E-1,1.3 'GHz' center tc rgbcolor 'steelblue' \n";
  printf CMDFILE "set label 9 at 0.33E-4,1.3 'THz' center tc rgbcolor 'dark-red' \n";
  
  $cmd = "plot [1.0e-19:1.0e2][-0.05:1.4] ";
#  $cmd = "plot [1.0e-7:1.0e-5][0.0:1.5] ";
  $cmd .=  "  './mm_trans.dat' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './mktrans_zm_10_10.dat' every 100 using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 1 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './mktrans_nq_10_10.dat' every 100 using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 1 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './modtran_maunakea.txt' using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './long_radio.dat' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './short_gamma.dat' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 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`;
  }


  # basic graph showing regions of transmission
  #    all data a single color
  #    only showing regions of transmission to ground
  #    does include text labels
  $output_file = "window_trans_e.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 logscale x \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Transmission' \n";
  printf CMDFILE "set xlabel 'Wavelength (meters) ' \n";
  printf CMDFILE "set title 'Transmission of atmosphere of Earth '\n";

  printf CMDFILE "set label 1 at 0.8E-18,1.1 'TeV' center tc rgbcolor 'violet' \n";
  printf CMDFILE "set label 2 at 0.8E-15,1.1 'GeV' center tc rgbcolor 'blue' \n";
  printf CMDFILE "set label 3 at 0.8E-12,1.1 'MeV' center tc rgbcolor 'dark-green' \n";
  printf CMDFILE "set label 4 at 0.8E-09,1.1 'keV' center tc rgbcolor 'dark-orange' \n";
  printf CMDFILE "set label 5 at 1.0E-06,1.1 '{/Symbol m}m' center tc rgbcolor 'black' \n";
  printf CMDFILE "set label 6 at 1.0E-03,1.1 'mm' center tc rgbcolor 'red' \n";

  printf CMDFILE "set label 7 at 0.33E2,1.3 'MHz' center tc rgbcolor 'red' \n";
  printf CMDFILE "set label 8 at 0.33E-1,1.3 'GHz' center tc rgbcolor 'steelblue' \n";
  printf CMDFILE "set label 9 at 0.33E-4,1.3 'THz' center tc rgbcolor 'dark-red' \n";
  
  $cmd = "plot [1.0e-7:1.0e2][-0.05:1.4] ";
#  $cmd = "plot [1.0e-7:1.0e-5][0.0:1.5] ";
  $cmd .=  "  './mm_trans.dat' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './mktrans_zm_10_10.dat' every 100 using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 1 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './mktrans_nq_10_10.dat' every 100 using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 1 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './modtran_maunakea.txt' using (\$1*1.0e-6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './long_radio.dat' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './short_gamma.dat' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 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`;
  }


  # basic graph showing regions of transmission
  #    all data a single color
  #    only showing optical plus near-IR
  #    does NOT include text labels
  $output_file = "window_trans_f.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 logscale x \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Transmission' \n";
  printf CMDFILE "set xlabel 'Wavelength (microns) ' \n";
  printf CMDFILE "set title 'Transmission of atmosphere of Earth (optical-IR)'\n";

  
  $cmd = "plot [2.0e-1:5.0e1][-0.05:1.4] ";
#  $cmd = "plot [1.0e-7:1.0e-5][0.0:1.5] ";
  $cmd .=  "  './mm_trans.dat' using (\$1*1e6):(\$2*1.0) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './mktrans_zm_10_10.dat' every 100 using (\$1):(\$2*0.96) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 1 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './mktrans_nq_10_10.dat' every 100 using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 1 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './modtran_maunakea.txt' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './long_radio.dat' using (\$1*1e6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './short_gamma.dat' using (\$1*1e6):(\$2) ";
  $cmd .=  "      with lines lt 1 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`;
  }



  # basic graph showing regions of transmission
  #    all data a single color
  #    only showing optical plus near-IR
  #    does include text labels
  $output_file = "window_trans_g.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 logscale x \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Transmission' \n";
  printf CMDFILE "set xlabel 'Wavelength (microns) ' \n";
  printf CMDFILE "set title 'Transmission of atmosphere of Earth (optical-IR)'\n";

  printf CMDFILE "set label 10 at 1.0,1.1 'Y' center tc rgbcolor 'dark-plum' \n";
  printf CMDFILE "set label 1 at 1.3,1.1 'J' center tc rgbcolor 'violet' \n";
  printf CMDFILE "set label 2 at 1.65,1.1 'H' center tc rgbcolor 'blue' \n";
  printf CMDFILE "set label 3 at 2.20,1.1 'K' center tc rgbcolor 'dark-green' \n";
  printf CMDFILE "set label 4 at 3.5,1.1 'L' center tc rgbcolor 'brown4' \n";
  printf CMDFILE "set label 5 at 4.8,1.1 'M' center tc rgbcolor 'orange' \n";
  printf CMDFILE "set label 6 at 10,1.1 'N' center tc rgbcolor 'dark-orange' \n";
  printf CMDFILE "set label 7 at 20,1.1 'O' center tc rgbcolor 'red' \n";
  
  $cmd = "plot [2.0e-1:5.0e1][-0.05:1.4] ";
#  $cmd = "plot [1.0e-7:1.0e-5][0.0:1.5] ";
  $cmd .=  "  './mm_trans.dat' using (\$1*1e6):(\$2*1.0) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './mktrans_zm_10_10.dat' every 100 using (\$1):(\$2*0.96) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 1 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './mktrans_nq_10_10.dat' every 100 using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 1 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './modtran_maunakea.txt' using (\$1):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './long_radio.dat' using (\$1*1e6):(\$2) ";
  $cmd .=  "      with lines lt 1 lc -1 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './short_gamma.dat' using (\$1*1e6):(\$2) ";
  $cmd .=  "      with lines lt 1 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`;
  }






exit 0;



