#!/usr/bin/perl
#
#

##########################################
#  plot amplitude as a function of frequency
#      for several Q values
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "a_plot_a.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' size 7,10 ";

  $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 left \n";
  printf CMDFILE "set ylabel 'Amplitude (m)'  \n";
  printf CMDFILE "set xlabel 'Driving frequency (rad/s)' \n";
  printf CMDFILE "set title 'F = 10 N, m = 1.0 kg, k = 30.0 N/m' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [0:10][] './make_a_data.out' index 0 using 2:8 ";
  $cmd .= "        with lines ls 1 lw 3 t 'b = 0.2' ";
  $cmd .= " , ";
  $cmd .= "              './make_a_data.out' index 1 using 2:8 ";
  $cmd .= "        with lines ls 2 lw 5 t 'b = 0.8' ";
  $cmd .= " , ";
  $cmd .= "              './make_a_data.out' index 2 using 2:8 ";
  $cmd .= "        with lines ls 3 lw 3 t 'b = 2.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`;
  }



##########################################
#  plot amplitude-squared = "power" as a function of frequency
#      for several Q values
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "a_plot_b.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' size 10,10 ";

  $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 left \n";
  printf CMDFILE "set ylabel 'Power dissipated (W)'  \n";
  printf CMDFILE "set xlabel 'Driving frequency (rad/s)' \n";
  printf CMDFILE "set title '' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [5.0:6.0][] './make_a_data.out' index 0 using 2:(0.7*\$8*\$8) ";
  $cmd .= "        with lines ls 1 lw 3 t 'Q = 27' ";
#  $cmd .= " , ";
#  $cmd .= "              './make_a_data.out' index 1 using 2:8 ";
#  $cmd .= "        with lines ls 2 lw 5 t 'b = 0.8' ";
#  $cmd .= " , ";
#  $cmd .= "              './make_a_data.out' index 2 using 2:8 ";
#  $cmd .= "        with lines ls 3 lw 3 t 'b = 2.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;
