#!/usr/bin/perl
#
#

$mypi = 3.14159;

##########################################
#  plot the "baseline" frequency only
  
  my($output_file, $term_options);

  $output_file = "pulse_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 'sea-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 xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
#  printf CMDFILE "set title 'Motion of a mass hanging from a spring ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [0:20][-1.5:1.5] 'make_basefreq_data.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 1 lw 6 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 "baseline" frequency 
#     plus a high frequency, 1000x the baseline
  
  my($output_file, $term_options);

  $output_file = "pulse_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 'sea-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 xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
#  printf CMDFILE "set title 'Motion of a mass hanging from a spring ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [0:20][-1.5:1.5] 'make_nopulse_data.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
  $cmd .= " , ";
  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 1 lw 6 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 "baseline" frequency 
#     plus a high frequency, 1000x the baseline
#     zoom in on a very small range of times so we can see the
#        high-freq variations
  
  my($output_file, $term_options);

  $output_file = "pulse_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 'sea-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 xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
#  printf CMDFILE "set title 'Motion of a mass hanging from a spring ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [9.9:10.1][-1.5:1.5] 'make_nopulse_data.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
  $cmd .= " , ";
  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 1 lw 6 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 combination of a few frequencies 
#     around the 1000x baseline
#     "wide" view
  
  my($output_file, $term_options);

  $output_file = "pulse_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 'sea-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 xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [0:20][-1.5:1.5] 'make_pulse_data_a.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 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 combination of a few frequencies 
#     around the 1000x baseline
#     "narrow" view
  
  my($output_file, $term_options);

  $output_file = "pulse_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 'sea-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 xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [9:11][-1.5:1.5] 'make_pulse_data_a.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 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 combination of a few frequencies 
#     around the 1000x baseline
#     "very narrow" view
  
  my($output_file, $term_options);

  $output_file = "pulse_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 'sea-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 xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [9.9:10.1][-1.5:1.5] 'make_pulse_data_a.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 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 single high frequency
#     around the 1000x baseline
#     "wide" view
#  two panels, showing frequency spectrum and then sum of frequencies below
  
  my($output_file, $term_options);

  $output_file = "pulse_f2.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 'sea-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 multiplot layout 2, 1 \n";


  ###################################################
  # first, we plot a frequency spectrum

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
#  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Amplitude  '  \n";
  printf CMDFILE "set xlabel 'Frequency (rad/s) ' \n";
#  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [965:1035][-1.5:1.5] 'make_nopulse_data.out' index 0 using 4:8 ";
  $cmd .= "        with impulse ls 2 lw 10 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";


  ###################################################
  # in lower panel, we plot the sum of frequencies

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title '1 pure frequency ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [0:35][-1.5:1.5] 'make_nopulse_data.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";



  printf CMDFILE "unset multiplot \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 combination of a few frequencies 
#     around the 1000x baseline
#     "wide" view
#  two panels, showing frequency spectrum and then sum of frequencies below
  
  my($output_file, $term_options);

  $output_file = "pulse_g.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 'sea-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 multiplot layout 2, 1 \n";


  ###################################################
  # first, we plot a frequency spectrum

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
#  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Amplitude  '  \n";
  printf CMDFILE "set xlabel 'Frequency (rad/s) ' \n";
#  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [965:1035][-1.5:1.5] 'make_pulse_data_a.out' index 0 using 4:8 ";
  $cmd .= "        with impulse ls 2 lw 10 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";


  ###################################################
  # in lower panel, we plot the sum of frequencies

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [0:35][-1.5:1.5] 'make_pulse_data_a.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";



  printf CMDFILE "unset multiplot \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 combination of a few frequencies 
#     around the 1000x baseline
#     "narrow" view
#  two panels, showing frequency spectrum and then sum of frequencies below
  
  my($output_file, $term_options);

  $output_file = "pulse_h.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 'sea-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 multiplot layout 2, 1 \n";


  ###################################################
  # first, we plot a frequency spectrum

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
#  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Amplitude  '  \n";
  printf CMDFILE "set xlabel 'Frequency (rad/s) ' \n";
#  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [965:1035][-1.5:1.5] 'make_pulse_data_a.out' index 0 using 4:8 ";
  $cmd .= "        with impulse ls 2 lw 10 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";


  ###################################################
  # in lower panel, we plot the sum of frequencies

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [9:11][-1.5:1.5] 'make_pulse_data_a.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";



  printf CMDFILE "unset multiplot \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 combination of 9 frequencies 
#     around the 1000x baseline
#     "wide" view
#  two panels, showing frequency spectrum and then sum of frequencies below
  
  my($output_file, $term_options);

  $output_file = "pulse_i.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 'sea-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 multiplot layout 2, 1 \n";


  ###################################################
  # first, we plot a frequency spectrum

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
#  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Amplitude  '  \n";
  printf CMDFILE "set xlabel 'Frequency (rad/s) ' \n";
#  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [965:1035][-1.5:1.5] 'make_pulse_data_b.out' index 0 using 4:(\$8*3) ";
  $cmd .= "        with impulse ls 2 lw 10 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";


  ###################################################
  # in lower panel, we plot the sum of frequencies

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 9 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [0:35][-1.5:1.5] 'make_pulse_data_b.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";



  printf CMDFILE "unset multiplot \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 combination of 9 frequencies
#     around the 1000x baseline
#     "narrow" view
#  two panels, showing frequency spectrum and then sum of frequencies below
  
  my($output_file, $term_options);

  $output_file = "pulse_i2.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 'sea-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 multiplot layout 2, 1 \n";


  ###################################################
  # first, we plot a frequency spectrum

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
#  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Amplitude  '  \n";
  printf CMDFILE "set xlabel 'Frequency (rad/s) ' \n";
#  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [965:1035][-1.5:1.5] 'make_pulse_data_b.out' index 0 using 4:(\$8*3) ";
  $cmd .= "        with impulse ls 2 lw 10 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";


  ###################################################
  # in lower panel, we plot the sum of frequencies

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 9 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [9:11][-1.5:1.5] 'make_pulse_data_b.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";



  printf CMDFILE "unset multiplot \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 combination of 39 frequencies 
#     around the 1000x baseline
#     "wide" view
#  two panels, showing frequency spectrum and then sum of frequencies below
  
  my($output_file, $term_options);

  $output_file = "pulse_j.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 'sea-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 multiplot layout 2, 1 \n";


  ###################################################
  # first, we plot a frequency spectrum

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
#  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Amplitude  '  \n";
  printf CMDFILE "set xlabel 'Frequency (rad/s) ' \n";
#  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [965:1035][-1.5:1.5] 'make_pulse_data_c.out' index 0 using 4:(\$8*10) ";
  $cmd .= "        with impulse ls 2 lw 3 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";


  ###################################################
  # in lower panel, we plot the sum of frequencies

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 39 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [0:35][-1.5:1.5] 'make_pulse_data_c.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";



  printf CMDFILE "unset multiplot \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 combination of 39 frequencies
#     around the 1000x baseline
#     "narrow" view
#  two panels, showing frequency spectrum and then sum of frequencies below
  
  my($output_file, $term_options);

  $output_file = "pulse_j2.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 'sea-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 multiplot layout 2, 1 \n";


  ###################################################
  # first, we plot a frequency spectrum

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
#  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Amplitude  '  \n";
  printf CMDFILE "set xlabel 'Frequency (rad/s) ' \n";
#  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [965:1035][-1.5:1.5] 'make_pulse_data_c.out' index 0 using 4:(\$8*10) ";
  $cmd .= "        with impulse ls 2 lw 3 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";


  ###################################################
  # in lower panel, we plot the sum of frequencies

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 39 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [11:13][-1.5:1.5] 'make_pulse_data_c.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";



  printf CMDFILE "unset multiplot \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 combination of 99 frequencies 
#     around the 1000x baseline
#     "wide" view
#  two panels, showing frequency spectrum and then sum of frequencies below
  
  my($output_file, $term_options);

  $output_file = "pulse_k.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 'sea-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 multiplot layout 2, 1 \n";


  ###################################################
  # first, we plot a frequency spectrum

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
#  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Amplitude  '  \n";
  printf CMDFILE "set xlabel 'Frequency (rad/s) ' \n";
#  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [965:1035][-1.5:1.5] 'make_pulse_data_d.out' index 0 using 4:(\$8*40) ";
  $cmd .= "        with impulse ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";


  ###################################################
  # in lower panel, we plot the sum of frequencies

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 99 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [0:35][-1.5:1.5] 'make_pulse_data_d.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";



  printf CMDFILE "unset multiplot \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 combination of 99 frequencies
#     around the 1000x baseline
#     "narrow" view
#  two panels, showing frequency spectrum and then sum of frequencies below
  
  my($output_file, $term_options);

  $output_file = "pulse_k2.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 'sea-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 multiplot layout 2, 1 \n";


  ###################################################
  # first, we plot a frequency spectrum

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
#  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Amplitude  '  \n";
  printf CMDFILE "set xlabel 'Frequency (rad/s) ' \n";
#  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [965:1035][-1.5:1.5] 'make_pulse_data_d.out' index 0 using 4:(\$8*40) ";
  $cmd .= "        with impulse ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";


  ###################################################
  # in lower panel, we plot the sum of frequencies

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 99 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [30:32][-1.5:1.5] 'make_pulse_data_d.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";



  printf CMDFILE "unset multiplot \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`;
  }







##########################################
#  this is part of series to compare how freq-width affects pulse-width
#     using freq_width = 5 only
#     "centered" view
#  two panels, showing frequency spectrum and then sum of frequencies below
  
  my($output_file, $term_options);

  $output_file = "pulse_freq_width_a.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 'sea-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 multiplot layout 2, 1 \n";


  ###################################################
  # first, we plot a frequency spectrum

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
#  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Amplitude  '  \n";
  printf CMDFILE "set xlabel 'Frequency (rad/s) ' \n";
#  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [955:1045][-0.5:1.5] 'pulse_width_a.out' index 0 using 4:(\$8*5) ";
  $cmd .= "        with impulse ls 2 lw 3 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";


  ###################################################
  # in lower panel, we plot the sum of frequencies

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 19 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [-2:2][-1.5:1.5] 'pulse_width_a.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";



  printf CMDFILE "unset multiplot \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`;
  }






##########################################
#  this is part of series to compare how freq-width affects pulse-width
#     using freq_width = 10 only
#     "centered" view
#  two panels, showing frequency spectrum and then sum of frequencies below
  
  my($output_file, $term_options);

  $output_file = "pulse_freq_width_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 'sea-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 multiplot layout 2, 1 \n";


  ###################################################
  # first, we plot a frequency spectrum

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
#  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Amplitude  '  \n";
  printf CMDFILE "set xlabel 'Frequency (rad/s) ' \n";
#  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [955:1045][-0.5:1.5] 'pulse_width_b.out' index 0 using 4:(\$8*5) ";
  $cmd .= "        with impulse ls 2 lw 3 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";


  ###################################################
  # in lower panel, we plot the sum of frequencies

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 19 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [-2:2][-1.5:1.5] 'pulse_width_b.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";



  printf CMDFILE "unset multiplot \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`;
  }




##########################################
#  this is part of series to compare how freq-width affects pulse-width
#     using freq_width = 20 only
#     "centered" view
#  two panels, showing frequency spectrum and then sum of frequencies below
  
  my($output_file, $term_options);

  $output_file = "pulse_freq_width_c.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 'sea-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 multiplot layout 2, 1 \n";


  ###################################################
  # first, we plot a frequency spectrum

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
#  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Amplitude  '  \n";
  printf CMDFILE "set xlabel 'Frequency (rad/s) ' \n";
#  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [955:1045][-0.5:1.5] 'pulse_width_c.out' index 0 using 4:(\$8*5) ";
  $cmd .= "        with impulse ls 2 lw 5 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";


  ###################################################
  # in lower panel, we plot the sum of frequencies

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 19 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [-2:2][-1.5:1.5] 'pulse_width_c.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";



  printf CMDFILE "unset multiplot \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`;
  }




##########################################
#  this is part of series to compare how freq-width affects pulse-width
#     using freq_width = 40 only
#     "centered" view
#  two panels, showing frequency spectrum and then sum of frequencies below
  
  my($output_file, $term_options);

  $output_file = "pulse_freq_width_d.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 'sea-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 multiplot layout 2, 1 \n";


  ###################################################
  # first, we plot a frequency spectrum

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
#  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Amplitude  '  \n";
  printf CMDFILE "set xlabel 'Frequency (rad/s) ' \n";
#  printf CMDFILE "set title 'Sum of 3 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [955:1045][-0.5:1.5] 'pulse_width_d.out' index 0 using 4:(\$8*5) ";
  $cmd .= "        with impulse ls 2 lw 6 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";


  ###################################################
  # in lower panel, we plot the sum of frequencies

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xzeroaxis  lw 3.5 \n";
  printf CMDFILE "set yzeroaxis  lw 3.5 \n";
  printf CMDFILE "set ylabel 'Value  '  \n";
  printf CMDFILE "set xlabel 'Time (s) ' \n";
  printf CMDFILE "set title 'Sum of 19 frequencies ' \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [-2:2][-1.5:1.5] 'pulse_width_d.out' index 1 using 1:2 ";
  $cmd .= "        with lines ls 2 lw 2 t '' ";
#  $cmd .= " , ";
#  $cmd .= "                      'make_basefreq_data.out' index 1 using 1:2 ";
#  $cmd .= "        with lines ls 1 lw 6 t '' ";

  printf CMDFILE "$cmd \n";



  printf CMDFILE "unset multiplot \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;
