#!/usr/bin/perl
#

  my($output_file, $term_options);

  ########################################################################3
  #  Plot a negative exponential -- light travelling through material
  #     with no source function
  #

  $output_file = "./transfer_a.ps";
  $term_options = "postscript color 'Helvectica,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 style line 6 lt rgb 'orange' lw 3  \n"; 
  printf CMDFILE "set style line 7 lt rgb 'black' lw 3  \n"; 


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Intensity / (Initial intensity)' \n";
  printf CMDFILE "set xlabel 'Optical depth travelled ' \n";
  
  $cmd = "plot [0:5][] 1.0*(exp(-x))  ";
  $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`;
  }


  ########################################################################3
  #  Plot the intensity as function of position for a beam of light
  #     moving through a region of constant density, opacity, source function.
  #
  #

  $output_file = "./transfer_b.ps";
  $term_options = "postscript color 'Helvectica,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 style line 6 lt rgb 'orange' lw 3  \n"; 
  printf CMDFILE "set style line 7 lt rgb 'black' lw 3  \n"; 


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key center right \n";
  printf CMDFILE "set ylabel 'Intensity / (Initial intensity)' \n";
  printf CMDFILE "set xlabel 'Optical depth travelled ' \n";

  # initial intensity 
  $I0 = 1.0;
  # source function, choice A:
  $Sa = 1.8;
  # source function, choice B:
  $Sb = 0.3;

  
  $cmd = "plot [0:5][0:2] $I0*(exp(-x)) + $Sa*(1 - exp(-x))  ";
  $cmd .= "   with lines  ls 2  t 'S = $Sa I_0' ";
  $cmd .= " , ";
  $cmd .= "             $I0*(exp(-x)) + $Sb*(1 - exp(-x))  ";
  $cmd .= "   with lines  ls 3  t 'S = $Sb I_0' ";

  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;
