#!/usr/bin/perl
#

  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "bb_log_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 key top right \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  printf CMDFILE "set ylabel 'Flux per unit wavelength interval (arb scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (nm)' \n";
  printf CMDFILE "set title 'Spectra of blackbodies '\n";
  
  $cmd = "plot [0.1:1e6][10:1e45] './bb_lam_100.dat' using (\$2*1e9):(\$3) ";
  $cmd .= "       with points ps 0.8 pt 3 lc 1 lw 2 t 'T = 100 K' ";
  $cmd .= " , ";
  $cmd .= "              './bb_lam_1000.dat' using (\$2*1e9):(\$3) ";
  $cmd .= "       with lines lt 1 lw 5 lc 2 t 'T = 1,000 K' ";
  $cmd .= " , ";
  $cmd .= "              './bb_lam_10000.dat' using (\$2*1e9):(\$3) ";
  $cmd .= "       with points ps 0.8 pt 4 lc 3 lw 2 t 'T = 10,000 K' ";
  $cmd .= " , ";
  $cmd .= "              './bb_lam_100000.dat' using (\$2*1e9):(\$3) ";
  $cmd .= "       with lines lt 1 lw 4 lc 4 t 'T = 100,000 K' ";
  $cmd .= " , ";
  $cmd .= "              './bb_lam_1000000.dat' using (\$2*1e9):(\$3) ";
  $cmd .= "       with points ps 0.8 pt 6 lw 2 lc -1 t 'T = 1,000,000 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`;
  }



exit 0;

