#!/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' ";


  $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 (meters) ' \n";
  printf CMDFILE "set title 'Blackbody flux per unit wavelength ' \n";
  
  $cmd = "plot [1e-8:10][1e-10:1e15] './bb_lam_10000.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 3 lw 3 t '10000 K' ";
  $cmd .= " , ";
  $cmd .= "  './bb_lam_1000.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 2 lw 3 t '1000 K' ";
  $cmd .= " , ";
  $cmd .= "  './bb_lam_100.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 1 lw 3 t '100 K' ";
  $cmd .= " , ";
  $cmd .= "  './bb_lam_10.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc -1 lw 3 t '10 K' ";

  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 of blackbody flux per unit frequency
  $output_file = "./bb_fnu_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 logscale x \n";
  printf CMDFILE "set logscale y \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Flux per unit frequency' \n";
  printf CMDFILE "set xlabel 'Frequency (Hz) ' \n";
  printf CMDFILE "set title 'Blackbody flux per unit frequency ' \n";
  printf CMDFILE "set label 1 at 3e6,2e-16 '{/Symbol n}^2' \n";
  
  $cmd = "plot [1e5:1e17][1e-30:1e-4] './bb_fnu_10000.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 3 lw 3 t '10000 K' ";
  $cmd .= " , ";
  $cmd .= "  './bb_fnu_1000.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 2 lw 3 t '1000 K' ";
  $cmd .= " , ";
  $cmd .= "  './bb_fnu_100.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 1 lw 3 t '100 K' ";
  $cmd .= " , ";
  $cmd .= "  './bb_fnu_10.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc -1 lw 3 t '10 K' ";
  $cmd .= " , " ;
  $cmd .= "    1e-30*x*x  with lines lt 2 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`;
  }



  # plot of blackbody flux per unit frequency
  #    closeup around radio region only
  $output_file = "./bb_fnu_b.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 logscale y \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Flux per unit frequency' \n";
  printf CMDFILE "set format y '10^{%L}' \n";
  printf CMDFILE "set xlabel 'Frequency (Hz) ' \n";
  printf CMDFILE "set title 'Blackbody flux per unit frequency ' \n";
#  printf CMDFILE "set label 1 at 3e6,2e-16 '{/Symbol n}^2' \n";
  
  $cmd = "plot [1e8:1e11][1e-23:1e-13] './bb_fnu_10000.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 3 lw 3 t '10000 K' ";
  $cmd .= " , ";
  $cmd .= "  './bb_fnu_1000.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 2 lw 3 t '1000 K' ";
  $cmd .= " , ";
  $cmd .= "  './bb_fnu_100.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 1 lw 3 t '100 K' ";
  $cmd .= " , ";
  $cmd .= "  './bb_fnu_10.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc -1 lw 3 t '10 K' ";
#  $cmd .= " , " ;
#  $cmd .= "    1e-30*x*x  with lines lt 2 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`;
  }




  # plot of blackbody flux per unit frequency
  #    with synchrotron spectrum P(nu) ~ vu^(-1/2) shown as well
  $output_file = "./bb_fnu_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 logscale y \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Flux per unit frequency' \n";
  printf CMDFILE "set xlabel 'Frequency (Hz) ' \n";
  printf CMDFILE "set title 'Blackbody flux per unit frequency ' \n";
  printf CMDFILE "set label 1 at 3e6,2e-16 '{/Symbol n}^2' \n";
  
  $cmd = "plot [1e5:1e17][1e-30:1e-4] './bb_fnu_10000.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 3 lw 3 t '10000 K' ";
  $cmd .= " , ";
  $cmd .= "  './bb_fnu_1000.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 2 lw 3 t '1000 K' ";
  $cmd .= " , ";
  $cmd .= "  './bb_fnu_100.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc 1 lw 3 t '100 K' ";
  $cmd .= " , ";
  $cmd .= "  './bb_fnu_10.dat' ";
  $cmd .= "   using 2:3  with lines lt 1 lc -1 lw 3 t '10 K' ";
  $cmd .= " , " ;
  $cmd .= "    1e-30*x*x  with lines lt 2 lc -1 lw 2 t '' ";
  $cmd .= " , ";
  $cmd .= "    1e-15*x**(-0.5) with lines lt 1 lc 4 lw 10 t 'synch' ";
  

  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;
