#!/usr/bin/perl
#

# Initial conditions for static case
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "static_start.ps";
  $term_options = "postscript color font '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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set xlabel 'Position along rod (m)' \n";
  printf CMDFILE "set ylabel 'Temperature (K)' \n";
  printf CMDFILE "set title 'Initial conditions of a metal rod' \n", $aper;
  
  $cmd = "plot [0:9][0:55] './static_start.dat' using 4:6 ";
  $cmd .= "  with points pt 5 ps 2 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`;
  }


# Final conditions for static case
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "static_end.ps";
  $term_options = "postscript color font '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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set xlabel 'Position along rod (m)' \n";
  printf CMDFILE "set ylabel 'Temperature (K)' \n";
  printf CMDFILE "set title 'Final conditions of a metal rod' \n", $aper;
  
  $cmd = "plot [0:9][0:55] './static_end.dat' using (\$2-1):4 ";
  $cmd .= "  with linespoints pt 5 ps 2 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`;
  }


# gradual change for dynamic case
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "gradual_change.ps";
  $term_options = "postscript color font '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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set xlabel 'Position along rod (m)' \n";
  printf CMDFILE "set ylabel 'Temperature (K)' \n";
  printf CMDFILE "set title 'Dynamic behavior of a metal rod at 1 hour intervals' \n", $aper;
  
  $cmd = "plot [0:9][0:55] './changing_rod.dat' using 4:6 ";
  $cmd .= "  with lines  lw 3 t '' ";
  $cmd .= " , " ;
  $cmd .= " './changing_rod.dat' index 0 using 4:6 ";
  $cmd .= "  with points ps 2 pt 5 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`;
  }


# gradual change for unstable dynamic case
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "bogus_change.ps";
  $term_options = "postscript color font '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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set xlabel 'Position along rod (m)' \n";
  printf CMDFILE "set ylabel 'Temperature (K)' \n";
  printf CMDFILE "set title 'Dynamic behavior of a metal rod at 1 hour intervals' \n", $aper;
  
  $cmd = "plot [0:9][0:100] './bogus_rod.dat' using (\$4*10):6 ";
  $cmd .= "  with lines  lw 3 t '' ";
  $cmd .= " , " ;
  $cmd .= " './bogus_rod.dat' index 0 using (\$4*10):6 ";
  $cmd .= "  with points ps 2 pt 5 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`;
  }

