#!/usr/bin/perl
#
  
  my($output_file, $term_options);

  # plot of blackbody flux per unit wavelength
  $output_file = "./bb_lam_a.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' ";

  $xmin = 5.0e-9;
  $xmax = 1.0e-5;
  $ymin = 1.0e-8;
  $ymax = 1.0e19;


  $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 logscale y \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Flux per unit wavelength' \n";
  printf CMDFILE "set xlabel 'Wavelength (m) ' \n";
#  printf CMDFILE "set format x '%4.1e' \n";
  printf CMDFILE "set xtics ('1.0E-8' 1.0E-8, '1.0E-7' 1.0E-7, '1.0E-6' 1.0E-6, '1.0E-5' 1.0E-5, '1.0E-4' 1.0E-4) \n";
#  printf CMDFILE "set xlabel 'Spectral Type ' \n";
#  printf CMDFILE "set xtics 'O5', 'O8', 'B0', 'B3', 'B5', 'A0', 'A5', 'G2' \n";
  printf CMDFILE "set title 'Blackbody flux per unit wavelength ' \n";

  printf CMDFILE "set arrow 1 from 91.2E-9,1.0E-5 to 91.2E-9,1.0E19 nohead dt 2 \n";
 
  
  
  $cmd = "plot [5.0e-9:1.0e-5][1.0e10:1.0e19] './bb_lam_nuv_45000.out' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 3 lw 3 t 'O5' ";
  $cmd .= " , ";
  $cmd .= "  './bb_lam_nuv_35800.out' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 2 lw 3 t 'O8' ";
  $cmd .= " , ";
  $cmd .= "  './bb_lam_nuv_30000.out' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 1 lw 3 t 'B0' ";
  $cmd .= " , ";
  $cmd .= "  './bb_lam_nuv_18700.out' ";
  $cmd .= "   using 2:3  with lines lt 1 lc -1 lw 3 t 'B3' ";



  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 -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  

  # plot of stellar properties vs. spectral type
  #    first, just the temperature and radius
  $output_file = "./stellar_prop_a.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' ";

  $xmin = 0;
  $xmax = 9;
  $ymin = 0.5;
  $ymax = 1e6;

  #  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"; 

  $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 y \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Solar units' \n";
  printf CMDFILE "set xlabel 'Spectral Type' \n";
#  printf CMDFILE "set format x '%4.1e' \n";
  printf CMDFILE "set xtics ('O5' 1, 'O8' 2, 'B0' 3, 'B3' 4, 'B5' 5, 'A0' 6, 'A5' 7, 'G2' 8) \n";
#  printf CMDFILE "set xlabel 'Spectral Type ' \n";
#  printf CMDFILE "set xtics 'O5', 'O8', 'B0', 'B3', 'B5', 'A0', 'A5', 'G2' \n";
  printf CMDFILE "set title 'Stellar properties ' \n";

#  printf CMDFILE "set arrow 1 from 91.2E-9,1.0E-5 to 91.2E-9,1.0E19 nohead dt 2 \n";
 
  
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] './compare_nuv.dat' ";
  $cmd .= "   using 1:(\$3/5780)  with linespoints ls 1 t 'Temp' ";
  $cmd .= " , ";
  $cmd .= "   './compare_nuv.dat' ";
  $cmd .= "   using 1:5  with linespoints ls 3 pt 3 ps 1.5 t 'Radius ' ";
#  $cmd .= " , ";
#  $cmd .= "   './compare_nuv.dat' ";
#  $cmd .= "   using 1:4  with linespoints ls 2 pt 6 ps 2 t 'Luminosity ' ";
#  $cmd .= " , ";
#  $cmd .= " , ";
#  $cmd .= "   './compare_nuv.dat' ";
#  $cmd .= "   using 1:(\$5*\$5)  with linespoints ls 4 pt 4 ps 1.5 t 'Surface area ' ";
#  $cmd .= " , ";
#  $cmd .= "   './compare_nuv.dat' ";
#  $cmd .= "   using 1:((\$3/5780)**(4.0))  with linespoints ls 5 pt 5 ps 1.5 t 'T^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 -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  

  # plot of stellar properties vs. spectral type
  #    now, surface area, T^4, and luminosity
  $output_file = "./stellar_prop_b.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' ";

  $xmin = 0;
  $xmax = 9;
  $ymin = 0.5;
  $ymax = 1e6;

  #  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"; 

  $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 y \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Solar units' \n";
  printf CMDFILE "set xlabel 'Spectral Type' \n";
#  printf CMDFILE "set format x '%4.1e' \n";
  printf CMDFILE "set xtics ('O5' 1, 'O8' 2, 'B0' 3, 'B3' 4, 'B5' 5, 'A0' 6, 'A5' 7, 'G2' 8) \n";
#  printf CMDFILE "set xlabel 'Spectral Type ' \n";
#  printf CMDFILE "set xtics 'O5', 'O8', 'B0', 'B3', 'B5', 'A0', 'A5', 'G2' \n";
  printf CMDFILE "set title 'Stellar properties ' \n";

#  printf CMDFILE "set arrow 1 from 91.2E-9,1.0E-5 to 91.2E-9,1.0E19 nohead dt 2 \n";
 
  
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] './compare_nuv.dat' ";
  $cmd .= "   using 1:((\$3/5780)**4.0)  with linespoints ls 1 t 'Temp^4' ";
  $cmd .= " , ";
  $cmd .= "   './compare_nuv.dat' ";
  $cmd .= "   using 1:(\$5*\$5)  with linespoints ls 3 pt 3 ps 1.5 t 'Surface area ' ";
  $cmd .= " , ";
  $cmd .= "   './compare_nuv.dat' ";
  $cmd .= "   using 1:4  with linespoints ls 2 pt 6 ps 2 t 'Luminosity ' ";
#  $cmd .= " , ";
#  $cmd .= " , ";
#  $cmd .= "   './compare_nuv.dat' ";
#  $cmd .= "   using 1:(\$5*\$5)  with linespoints ls 4 pt 4 ps 1.5 t 'Surface area ' ";
#  $cmd .= " , ";
#  $cmd .= "   './compare_nuv.dat' ";
#  $cmd .= "   using 1:((\$3/5780)**(4.0))  with linespoints ls 5 pt 5 ps 1.5 t 'T^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 -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  

  # plot of stellar properties vs. spectral type
  #    now, number of photons, frac UV, number of UV
  $output_file = "./stellar_prop_c.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' ";

  $xmin = 0;
  $xmax = 9;
  $ymin = 0.5;
  $ymax = 1e6;

  #  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"; 

  $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 y \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Solar units' \n";
  printf CMDFILE "set xlabel 'Spectral Type' \n";
#  printf CMDFILE "set format x '%4.1e' \n";
  printf CMDFILE "set xtics ('O5' 1, 'O8' 2, 'B0' 3, 'B3' 4, 'B5' 5, 'A0' 6, 'A5' 7, 'G2' 8) \n";
#  printf CMDFILE "set xlabel 'Spectral Type ' \n";
#  printf CMDFILE "set xtics 'O5', 'O8', 'B0', 'B3', 'B5', 'A0', 'A5', 'G2' \n";
  printf CMDFILE "set title 'Photons from stars of different spectral types ' \n";

  printf CMDFILE "set label 1 '100 percent ionizing' at 6,3.0e10 font 'Helvetica,14' tc rgb 'blue' \n";
 
  
  
  $cmd = "plot [$xmin:$xmax][0.1:1.0e16] './compare_nuv.dat' ";
  $cmd .= "   using 1:(\$11/4.44E44)  with linespoints ls 1 t 'Photon/s' ";
  $cmd .= " , ";
  $cmd .= "   './compare_nuv.dat' ";
  $cmd .= "   using 1:(1e10*(\$12/\$11))  with linespoints ls 3 pt 3 ps 1.5 t 'Fraction ionizing' ";
  $cmd .= " , ";
  $cmd .= "   './compare_nuv.dat' ";
  $cmd .= "   using 1:(\$12/1.96E35) with linespoints ls 2 pt 6 ps 2 t 'Ionizing photon/s' ";
  $cmd .= " , ";
  $cmd .= "   1e10 with lines ls 3 dt 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 -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }







exit 0;
