#!/usr/bin/perl
#
#

##########################################
#  plot amplitude as a function of frequency
#      for a low-damping system
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "amp_plot_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";

  # 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 '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 grid \n";
  printf CMDFILE "set key bot left \n";
  printf CMDFILE "set ylabel 'Amplitude (m)'  \n";
  printf CMDFILE "set xlabel 'Driving Frequency (rad/s)' \n";
  printf CMDFILE "set title 'F_{max} = 2.0 N, m = 0.1 kg, k = 7.5 N/m, b = 0.02 N/m/s' \n";
  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [0:20][-1:14] './make_data_smallb.out' index 0 using 2:4 ";
  $cmd .= "        with lines ls 1 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_data_smallb.out' index 1 using 2:4 ";
  $cmd .= "        with lines lc -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`;
  }


##########################################
#  plot amplitude as a function of frequency
#      for a high-damping system
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "amp_plot_b.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";

  # 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 '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 grid \n";
  printf CMDFILE "set key bot left \n";
  printf CMDFILE "set ylabel 'Amplitude (m)'  \n";
  printf CMDFILE "set xlabel 'Driving Frequency (rad/s)' \n";
  printf CMDFILE "set title 'F_{max} = 2.0 N, m = 0.1 kg, k = 7.5 N/m, b = 0.4 N/m/s' \n";
  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.05 \n";

  $cmd = "plot [0:20][-0.1:1] './make_data_bigb.out' index 0 using 2:4 ";
  $cmd .= "        with lines ls 3 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_data_smallb.out' index 1 using 2:4 ";
  $cmd .= "        with lines lc -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`;
  }



##########################################
#  plot amplitude as a function of frequency
#      for both a low-damping and high-damping system
#      on linear scale
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "amp_plot_c.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";

  # 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 '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 grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Amplitude (m)'  \n";
  printf CMDFILE "set xlabel 'Driving Frequency (rad/s)' \n";
  printf CMDFILE "set title 'F_{max} = 2.0 N, m = 0.1 kg, k = 7.5 N/m ' \n";
  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.2 \n";

  $cmd = "plot [0:20][-1:15] './make_data_smallb.out' index 0 using 2:4 ";
  $cmd .= "        with lines ls 1 t 'b = 0.02 N/m/s' ";
  $cmd .= " , ";
  $cmd .= "                   './make_data_bigb.out' index 0 using 2:(\$4) ";
  $cmd .= "        with lines ls 3 t 'b = 0.4 N/m/s ' ";
  $cmd .= " , ";
  $cmd .= "                   './make_data_vbigb.out' index 0 using 2:(\$4) ";
  $cmd .= "        with lines ls 2 t 'b = 1.0 N/m/s' ";
  $cmd .= " , ";
  $cmd .= "              './make_data_smallb.out' index 1 using 2:4 ";
  $cmd .= "        with lines lc -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`;
  }


##########################################
#  plot amplitude as a function of frequency
#      for both a low-damping and high-damping system
#      on log scale
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "amp_plot_d.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";

  # 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 '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 grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set logscale y   \n";
  printf CMDFILE "set ylabel 'Amplitude (m)'  \n";
  printf CMDFILE "set xlabel 'Driving Frequency (rad/s)' \n";
  printf CMDFILE "set title 'F_{max} = 2.0 N, m = 0.1 kg, k = 7.5 N/m ' \n";
  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,0.2 \n";

  $cmd = "plot [0:20][0.1:15] './make_data_smallb.out' index 0 using 2:4 ";
  $cmd .= "        with lines ls 1 t 'b = 0.02 N/m/s' ";
  $cmd .= " , ";
  $cmd .= "                   './make_data_bigb.out' index 0 using 2:(\$4) ";
  $cmd .= "        with lines ls 3 t 'b = 0.4 N/m/s ' ";
  $cmd .= " , ";
  $cmd .= "                   './make_data_vbigb.out' index 0 using 2:(\$4) ";
  $cmd .= "        with lines ls 2 t 'b = 1.0 N/m/s' ";
  $cmd .= " , ";
  $cmd .= "              './make_data_smallb.out' index 1 using 2:4 ";
  $cmd .= "        with lines lc -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`;
  }



exit 0;






##########################################
#  plot the position as a function of time over a long period
#      for a lightly damped system
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "damped_plot_b.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";

  # 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 '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 grid \n";
  printf CMDFILE "set key bot left \n";
  printf CMDFILE "set ylabel 'Position (m)'  \n";
  printf CMDFILE "set xlabel 'Time (s)' \n";
  $cmd = "plot [][-5:5] './make_damped.out' index 1 using 1:2 ";
  $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`;
  }




##########################################
#  plot the position as a function of time over a long period
#      for a lightly damped system
#      and plot the exponential envelope, too
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "damped_plot_c.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";

  # 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 '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 grid \n";
  printf CMDFILE "set key bot left \n";
  printf CMDFILE "set ylabel 'Position (m)'  \n";
  printf CMDFILE "set xlabel 'Time (s)' \n";
  $cmd = "plot [][-5:5] './make_damped.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 1 t '' ";
  $cmd .= " , ";
  $cmd .= "        4.0*exp(-x/15.8114) with lines ls 3 t '' ";
  $cmd .= " , ";
  $cmd .= "        0.0-4.0*exp(-x/15.8114) with lines ls 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`;
  }



##########################################
#  plot the position as a function of time over a long period
#      for a critically damped system
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "damped_plot_d.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";

  # 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 '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 grid \n";
  printf CMDFILE "set key bot left \n";
  printf CMDFILE "set ylabel 'Position (m)'  \n";
  printf CMDFILE "set xlabel 'Time (s)' \n";
  $cmd = "plot [][-5:5] './make_damped.out' index 2 using 1:2 ";
  $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`;
  }



##########################################
#  plot the position as a function of time over a long period
#      for a critically damped system
#      zoom in to first few seconds
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "damped_plot_e.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";

  # 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 '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 grid \n";
  printf CMDFILE "set key bot left \n";
  printf CMDFILE "set ylabel 'Position (m)'  \n";
  printf CMDFILE "set xlabel 'Time (s)' \n";
  $cmd = "plot [0:3][-5:5] './make_damped.out' index 2 using 1:2 ";
  $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`;
  }



##########################################
#  plot the position as a function of time over a long period
#      for a over- damped system
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "damped_plot_f.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";

  # 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 '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 grid \n";
  printf CMDFILE "set key bot left \n";
  printf CMDFILE "set ylabel 'Position (m)'  \n";
  printf CMDFILE "set xlabel 'Time (s)' \n";
  $cmd = "plot [0:3][-5:5] './make_damped.out' index 2 using 1:2 ";
  $cmd .= "        with lines ls 1 t 'critical' ";
  $cmd .= " , ";
  $cmd .= "                 './make_damped.out' index 3 using 1:2 ";
  $cmd .= "        with lines ls 3 t 'over' ";
  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;


