#!/usr/bin/perl
#

  $output_file = "maxwell_dist_a.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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Relative number of molecules ' \n";
  printf CMDFILE "set xlabel 'Speed of molecule (m/s) ' \n";
  printf CMDFILE "set title 'Oxygen in Earth atmosphere at 300 K '\n";
  
  $cmd = "plot [0:2000][] 'maxwell.out' using (\$2):(\$4)  ";
  $cmd .= "    with lines lt 1 lc 1 lw 3 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`;
  }



  $output_file = "maxwell_dist_b.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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set logscale y\n";
  printf CMDFILE "set ylabel 'Relative number of molecules ' \n";
  printf CMDFILE "set xlabel 'Speed of molecule (m/s) ' \n";
  printf CMDFILE "set title 'Oxygen in Earth atmosphere at 300 K '\n";
  
  $cmd = "plot [0:5000][1e-35:2.0] 'maxwell.out' using (\$2):(\$4)  ";
  $cmd .= "    with lines lt 1 lc 1 lw 3 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`;
  }







  $output_file = "maxwell_dist_c.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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set size 2.5,1 \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set logscale y\n";
  printf CMDFILE "set ylabel 'Relative number of molecules ' \n";
  printf CMDFILE "set xlabel 'Speed of molecule (m/s) ' \n";
  printf CMDFILE "set title 'Oxygen in Earth atmosphere at 300 K '\n";
  
  $cmd = "plot [0:5000][1e-35:2.0] 'maxwell.out' using (\$2):(\$4)  ";
  $cmd .= "    with lines lt 1 lc 1 lw 3 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;
