#!/usr/bin/perl
#


  
  my($output_file, $term_options);



###########################################################################
#  Plot the spectrum of an A0V star, closeup 4000 - 5000 Angstroms
#

  $output_file = "./a0_spec_narrow.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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Flux per unit wavelength ' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Spectrum of an A0 star '\n";


  
  $cmd = "plot [4000:5000][]  'uka0v_dat' using 1:2 ";
  $cmd .= "    with lines ls -1 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`;
  }



###########################################################################
#  Plot the spectrum of an A0V star, closeup 4000 - 5000 Angstroms
#    Also plot a copy redshifted to z=1.005 

  $output_file = "./a0_spec_narrow_comp.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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Flux per unit wavelength ' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Spectrum of an A0 star '\n";


  
  $cmd = "plot [4000:5000][]  'uka0v_dat' using 1:2 ";
  $cmd .= "    with lines ls -1 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'uka0v_dat.z_005' using 1:2 ";
  $cmd .= "    with lines ls 1 t 'redshifted ' ";

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


###########################################################################
#  Plot the spectrum of an A0V star, wide 0 - 8000 Angstroms
#

  $output_file = "./a0_spec_wide.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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Flux per unit wavelength ' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Spectrum of an A0 star '\n";


  
  $cmd = "plot [0:8000][]  'uka0v_dat' using 1:2 ";
  $cmd .= "    with lines ls -1 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`;
  }


###########################################################################
#  Plot the spectrum of an A0V star, wide 0 - 8000 Angstroms
#    Also plot ordinary B,V passbands used to measure it
#

  $output_file = "./a0_bv_bands.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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Flux per unit wavelength ' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Spectrum of an A0 star at rest '\n";

  printf CMDFILE "set label 1 'B' rotate by 90 at 4415,0.5 font \'Helvetica,18\' \n";
  printf CMDFILE "set label 2 'V' rotate by 90 at 5503,0.5 font \'Helvetica,18\' \n";

  
  $cmd = "plot [0:8000][0:2.8]  'uka0v_dat' using 1:2 ";
  $cmd .= "    with lines ls -1 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'bess_b.pass' using 1:(\$2*2.0) ";
  $cmd .= "    with lines ls -1 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'bess_v.pass' using 1:(\$2*2.0) ";
  $cmd .= "    with lines ls -1 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`;
  }



###########################################################################
#  Plot the spectrum of an A0V star, wide 0 - 8000 Angstroms
#    Also plot ordinary B,V passbands used to measure it
#    Also, plot a copy of the star's spectrum redshifted by to z=0.01
#

  $output_file = "./a0_bv_bands_smallz.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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Flux per unit wavelength ' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Spectrum of an A0 with small redshift '\n";

  printf CMDFILE "set label 1 'B' rotate by 90 at 4415,0.5 font \'Helvetica,18\' \n";
  printf CMDFILE "set label 2 'V' rotate by 90 at 5503,0.5 font \'Helvetica,18\' \n";

  
  $cmd = "plot [0:8000][0:2.8]  'uka0v_dat' using 1:2 ";
  $cmd .= "    with lines ls -1 t 'at rest' ";
  $cmd .= " , ";
  $cmd .= "                     'uka0v_dat.z=0.01' using 1:2 ";
  $cmd .= "    with lines ls 1 t 'z=0.01' ";
  $cmd .= " , ";
  $cmd .= "                   'bess_b.pass' using 1:(\$2*2.0) ";
  $cmd .= "    with lines ls -1 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'bess_v.pass' using 1:(\$2*2.0) ";
  $cmd .= "    with lines ls -1 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`;
  }





###########################################################################
#  Plot the spectrum of an A0V star, wide 0 - 8000 Angstroms
#

  $output_file = "./a0_spec_wide.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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Flux per unit wavelength ' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Spectrum of an A0 star '\n";


  
  $cmd = "plot [0:8000][]  'uka0v_dat' using 1:2 ";
  $cmd .= "    with lines ls -1 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`;
  }



###########################################################################
#  Plot the spectrum of an A0V star, very wide 0 - 50000 Angstroms
#

  $output_file = "./a0_spec_verywide.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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Flux per unit wavelength ' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Spectrum of an A0 star '\n";


  
  $cmd = "plot [0:50000][]  'uka0v_dat' using 1:2 ";
  $cmd .= "    with lines ls -1 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`;
  }



###########################################################################
#  Plot the spectrum of an A0V star, very wide 0 - 50000 Angstroms
#    Also plot a copy of the spectrum, redshifted to z=7
#

  $output_file = "./a0_spec_z7.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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Flux per unit wavelength ' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Spectrum of an A0 star and redshifted copy '\n";


  
  $cmd = "plot [0:50000][0:2.8]  'uka0v_dat' using 1:2 ";
  $cmd .= "    with lines ls -1 t 'at rest z=0' ";
  $cmd .= " , ";
  $cmd .= "                   'uka0v_dat.z_7' using 1:2 ";
  $cmd .= "    with lines ls 1 t 'redshifted z=7' ";


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



###########################################################################
#  Plot the z=7 spectrum of an A0V star, very wide 0 - 50000 Angstroms
#    Also plot HST/JWST passbands used to measure it
#

  $output_file = "./a0_z7_bands.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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Flux per unit wavelength ' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Spectrum of an A0 star at z=7 '\n";

  printf CMDFILE "set label 1 'B' rotate by 0 at 4050,0.1 font \'Helvetica,12\' \n";
  printf CMDFILE "set label 2 'V' rotate by 0 at 5414,0.1 font \'Helvetica,12\' \n";
#  printf CMDFILE "set label 1 'F606W' rotate by 90 at 6060,0.1 font \'Helvetica,12\' \n";
#  printf CMDFILE "set label 2 'F814W' rotate by 90 at 8140,0.02 font \'Helvetica,12\' \n";
  printf CMDFILE "set label 3 'F115W' rotate by 90 at 11500,0.1  font \'Helvetica,12\' \n";
  printf CMDFILE "set label 4 'F150W' rotate by 90 at 15000,0.1  font \'Helvetica,12\' \n";
  printf CMDFILE "set label 5 'F200W' rotate by 90 at 20000,0.1  font \'Helvetica,12\' \n";
  printf CMDFILE "set label 6 'F277W' rotate by 90 at 27700,0.1  font \'Helvetica,12\' \n";
  printf CMDFILE "set label 7 'F356W' rotate by 90 at 35600,0.1  font \'Helvetica,12\' \n";
  printf CMDFILE "set label 8 'F444W' rotate by 90 at 44400,0.1  font \'Helvetica,12\' \n";

  
  $cmd = "plot [0:50000][0:2.8]  'uka0v_dat.z_7' using 1:2 ";
  $cmd .= "    with lines ls 1 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'bess_b.pass' using 1:(\$2*1.1) ";
#  $cmd .= "                   'HST_ACS_HRC.F606W.dat' using 1:(\$2*2.0) ";
  $cmd .= "    with lines ls -1 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'bess_v.pass' using 1:(\$2*1.1) ";
#  $cmd .= "                   'HST_ACS_HRC.F814W.dat' using 1:(\$2*2.0) ";
  $cmd .= "    with lines ls -1 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'F115W_mean_system_throughput.txt' ";
  $cmd .= "                       using (\$1*10000):(\$2*2.0) ";
  $cmd .= "    with lines ls -1 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'F150W_mean_system_throughput.txt' ";
  $cmd .= "                       using (\$1*10000):(\$2*2.0) ";
  $cmd .= "    with lines ls -1 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'F200W_mean_system_throughput.txt' ";
  $cmd .= "                       using (\$1*10000):(\$2*2.0) ";
  $cmd .= "    with lines ls -1 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'F277W_mean_system_throughput.txt' ";
  $cmd .= "                       using (\$1*10000):(\$2*2.0) ";
  $cmd .= "    with lines ls -1 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'F356W_mean_system_throughput.txt' ";
  $cmd .= "                       using (\$1*10000):(\$2*2.0) ";
  $cmd .= "    with lines ls -1 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'F444W_mean_system_throughput.txt' ";
  $cmd .= "                       using (\$1*10000):(\$2*2.0) ";
  $cmd .= "    with lines ls -1 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;
