#!/usr/bin/perl
#



############################################################################
# plot of K^2 and the data itself for noiseless data: coarse grid dt = 1.0
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "fit_k_a.ps";
  $term_options = "postscript enhanced 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 xlabel 'Time (sec)' \n";
  printf CMDFILE "set ylabel 'Voltage (volts) or scaled K^2' \n";
  printf CMDFILE "set title ''\n", $aper;
  
  $cmd = "plot [8:16][0:3] 'make_one_gauss.b.out' using 1:2 ";
  $cmd .= "     with linespoints ps 1.5 pt 3 lc 1 lw 3 t 'data' ";
  $cmd .= " , ";
  $cmd .= "   'fit_one_gauss.1.out' using 2:(\$4*0.15) ";
  $cmd .= "     with points ps 1.5 pt 3 lc 3 lw 3 t 'K^2' ";


  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 K^2 and the data itself for noiseless data: fine grid dt = 0.1
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "fit_k_b.ps";
  $term_options = "postscript enhanced 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 xlabel 'Time (sec)' \n";
  printf CMDFILE "set ylabel 'Voltage (volts) or scaled K^2' \n";
  printf CMDFILE "set title ''\n", $aper;
  
  $cmd = "plot [10:14][0:3] 'make_one_gauss.b.out' using 1:2 ";
  $cmd .= "     with linespoints ps 1.5 pt 3 lc 1 lw 3 t 'data' ";
  $cmd .= " , ";
  $cmd .= "   'fit_one_gauss.0.1.out' using 2:(\$4*0.15) ";
  $cmd .= "     with points ps 1.5 pt 3 lc 3 lw 3 t 'K^2' ";


  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 the data itself for noisy stdev = 0.1
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "noisy_data_a.ps";
  $term_options = "postscript enhanced 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 xlabel 'Time (sec)' \n";
  printf CMDFILE "set ylabel 'Voltage (volts) ' \n";
  printf CMDFILE "set title ''\n", $aper;
  
  $cmd = "plot [8:16][-0.5:1.5] 'make_noisy_gauss.0.1.out' using 1:2 ";
  $cmd .= "     with linespoints ps 1.5 pt 3 lc 1 lw 3 t 'data' ";
#  $cmd .= " , ";
#  $cmd .= "   'fit_one_gauss.1.out' using 2:(\$4*0.15) ";
#  $cmd .= "     with points ps 1.5 pt 3 lc 3 lw 3 t 'K^2' ";


  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 the data and fit for noisy stdev = 0.1
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "fit_noisy_data_a.ps";
  $term_options = "postscript enhanced 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 xlabel 'Time (sec)' \n";
  printf CMDFILE "set ylabel 'Voltage (volts) or scaled K^2 ' \n";
  printf CMDFILE "set title ''\n", $aper;
  
  $cmd = "plot [8:16][-0.5:3.5] 'make_noisy_gauss.0.1.out' using 1:2 ";
  $cmd .= "     with linespoints ps 1.5 pt 3 lc 1 lw 3 t 'data' ";
  $cmd .= " , ";
  $cmd .= "   'fit_noisy.a.out' using 2:(\$4*0.15) ";
  $cmd .= "     with points ps 1.5 pt 3 lc 3 lw 3 t 'K^2' ";


  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 the data itself for noisy stdev = 0.3
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "noisy_data_b.ps";
  $term_options = "postscript enhanced 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 xlabel 'Time (sec)' \n";
  printf CMDFILE "set ylabel 'Voltage (volts) ' \n";
  printf CMDFILE "set title ''\n", $aper;
  
  $cmd = "plot [8:16][-0.5:2.0] 'make_noisy_gauss.0.3.out' using 1:2 ";
  $cmd .= "     with linespoints ps 1.5 pt 3 lc 1 lw 3 t 'data' ";
#  $cmd .= " , ";
#  $cmd .= "   'fit_one_gauss.1.out' using 2:(\$4*0.15) ";
#  $cmd .= "     with points ps 1.5 pt 3 lc 3 lw 3 t 'K^2' ";


  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 the data and fit for noisy stdev = 0.3
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "fit_noisy_data_b.ps";
  $term_options = "postscript enhanced 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 xlabel 'Time (sec)' \n";
  printf CMDFILE "set ylabel 'Voltage (volts) or scaled K^2 ' \n";
  printf CMDFILE "set title ''\n", $aper;
  
  $cmd = "plot [8:16][-0.5:2.5] 'make_noisy_gauss.0.3.out' using 1:2 ";
  $cmd .= "     with linespoints ps 1.5 pt 3 lc 1 lw 3 t 'data' ";
  $cmd .= " , ";
  $cmd .= "   'fit_noisy.b.out' using 2:(\$4*0.05) ";
  $cmd .= "     with points ps 1.5 pt 3 lc 3 lw 3 t 'K^2' ";


  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`;
  }





