#!/usr/bin/perl
#
#

##########################################
#  plot amplitude as a function of frequency
#      to show effect of Q on radio stations
#
#  This version shows only first value of Q, and has mix_a
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "radio_plot_a.ps";
#  $term_options = "postscript color enhanced 'Helvetica,18' size 14,7 ";
  $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 at 92.7,0.8 \n";
  printf CMDFILE "set ylabel 'Output power'  \n";
  printf CMDFILE "set xlabel 'Frequency (MHz)' \n";
  printf CMDFILE "set title 'How well does a radio isolate stations?' \n";
#  printf CMDFILE "set logscale y  \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [89:93][-0.1:1.1] 1.0 ";
  $cmd .= "        with lines ls 1 t 'flat' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out1' index 0 using 2:4 ";
  $cmd .= "        with points ls 1 pt 3 ps 2.0 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
#      to show effect of Q on radio stations
#
#  This version shows first two values of Q, and has mix_b
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "radio_plot_b.ps";
#  $term_options = "postscript color enhanced 'Helvetica,18' size 14,7 ";
  $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 at 92.7,0.8 \n";
  printf CMDFILE "set ylabel 'Output power'  \n";
  printf CMDFILE "set xlabel 'Frequency (MHz)' \n";
  printf CMDFILE "set title 'How well does a radio isolate stations?' \n";
#  printf CMDFILE "set logscale y  \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [89:93][-0.1:1.1] 1.0 ";
  $cmd .= "        with lines ls 1 t 'flat' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out1' index 0 using 2:4 ";
  $cmd .= "        with points ls 1 pt 3 ps 2.0 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 2 using 2:10 ";
  $cmd .= "        with lines ls 2 t 'Q=90' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 3 using 2:10 ";
  $cmd .= "        with points ls 2 pt 7 ps 2.0 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
#      to show effect of Q on radio stations
#
#  This version shows first three values of Q, and has mix_c
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "radio_plot_c.ps";
#  $term_options = "postscript color enhanced 'Helvetica,18' size 14,7 ";
  $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 at 92.7,0.8 \n";
  printf CMDFILE "set ylabel 'Output power'  \n";
  printf CMDFILE "set xlabel 'Frequency (MHz)' \n";
  printf CMDFILE "set title 'How well does a radio isolate stations?' \n";
#  printf CMDFILE "set logscale y  \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [89:93][-0.1:1.1] 1.0 ";
  $cmd .= "        with lines ls 1 t 'flat' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out1' index 0 using 2:4 ";
  $cmd .= "        with points ls 1 pt 3 ps 2.0 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 2 using 2:10 ";
  $cmd .= "        with lines ls 2 t 'Q=90' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 3 using 2:10 ";
  $cmd .= "        with points ls 2 pt 7 ps 2.0 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 4 using 2:10 ";
  $cmd .= "        with lines ls 3 t 'Q=150' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 5 using 2:10 ";
  $cmd .= "        with points ls 3 pt 5 ps 2.0 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
#      to show effect of Q on radio stations
#
#  This version shows first four values of Q, and has mix_d
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "radio_plot_d.ps";
#  $term_options = "postscript color enhanced 'Helvetica,18' size 14,7 ";
  $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 at 92.7,0.8 \n";
  printf CMDFILE "set ylabel 'Output power'  \n";
  printf CMDFILE "set xlabel 'Frequency (MHz)' \n";
  printf CMDFILE "set title 'How well does a radio isolate stations?' \n";
#  printf CMDFILE "set logscale y  \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [89:93][-0.1:1.1] 1.0 ";
  $cmd .= "        with lines ls 1 t 'flat' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out1' index 0 using 2:4 ";
  $cmd .= "        with points ls 1 pt 3 ps 2.0 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 2 using 2:10 ";
  $cmd .= "        with lines ls 2 t 'Q=90' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 3 using 2:10 ";
  $cmd .= "        with points ls 2 pt 7 ps 2.0 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 4 using 2:10 ";
  $cmd .= "        with lines ls 3 t 'Q=150' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 5 using 2:10 ";
  $cmd .= "        with points ls 3 pt 5 ps 2.0 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 6 using 2:10 ";
  $cmd .= "        with lines ls 4 t 'Q=280' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 7 using 2:10 ";
  $cmd .= "        with points ls 4 pt 5 ps 2.0 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
#      to show effect of Q on radio stations
#
#  This version shows first five values of Q, and has mix_e
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "radio_plot_e.ps";
#  $term_options = "postscript color enhanced 'Helvetica,18' size 14,7 ";
  $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 at 92.7,0.8 \n";
  printf CMDFILE "set ylabel 'Output power'  \n";
  printf CMDFILE "set xlabel 'Frequency (MHz)' \n";
  printf CMDFILE "set title 'How well does a radio isolate stations?' \n";
#  printf CMDFILE "set logscale y  \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [89:93][-0.1:1.1] 1.0 ";
  $cmd .= "        with lines ls 1 t 'flat' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out1' index 0 using 2:4 ";
  $cmd .= "        with points ls 1 pt 3 ps 2.0 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 2 using 2:10 ";
  $cmd .= "        with lines ls 2 t 'Q=90' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 3 using 2:10 ";
  $cmd .= "        with points ls 2 pt 7 ps 2.0 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 4 using 2:10 ";
  $cmd .= "        with lines ls 3 t 'Q=150' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 5 using 2:10 ";
  $cmd .= "        with points ls 3 pt 5 ps 2.0 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 6 using 2:10 ";
  $cmd .= "        with lines ls 4 t 'Q=280' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 7 using 2:10 ";
  $cmd .= "        with points ls 4 pt 5 ps 2.0 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 8 using 2:10 ";
  $cmd .= "        with lines ls 5 t 'Q=800' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 9 using 2:10 ";
  $cmd .= "        with points ls 5 pt 5 ps 1.5 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
#      to show effect of Q on radio stations
#
#  This version shows all values of Q, and has mix_f
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "radio_plot_f.ps";
#  $term_options = "postscript color enhanced 'Helvetica,18' size 14,7 ";
  $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 at 92.7,0.8 \n";
  printf CMDFILE "set ylabel 'Output power'  \n";
  printf CMDFILE "set xlabel 'Frequency (MHz)' \n";
  printf CMDFILE "set title 'How well does a radio isolate stations?' \n";
#  printf CMDFILE "set logscale y  \n";
#  printf CMDFILE "set label  '{/Symbol w_0} ' at 8.8,-0.5 \n";

  $cmd = "plot [89:93][-0.1:1.1] 1.0 ";
  $cmd .= "        with lines ls 1 t 'flat' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out1' index 0 using 2:4 ";
  $cmd .= "        with points ls 1 pt 3 ps 2.0 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 2 using 2:10 ";
  $cmd .= "        with lines ls 2 t 'Q=90' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 3 using 2:10 ";
  $cmd .= "        with points ls 2 pt 7 ps 2.0 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 4 using 2:10 ";
  $cmd .= "        with lines ls 3 t 'Q=150' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 5 using 2:10 ";
  $cmd .= "        with points ls 3 pt 5 ps 2.0 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 6 using 2:10 ";
  $cmd .= "        with lines ls 4 t 'Q=280' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 7 using 2:10 ";
  $cmd .= "        with points ls 4 pt 5 ps 2.0 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 8 using 2:10 ";
  $cmd .= "        with lines ls 5 t 'Q=800' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 9 using 2:10 ";
  $cmd .= "        with points ls 5 pt 5 ps 1.5 t '' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 10 using 2:10 ";
  $cmd .= "        with lines lt -1 lw 2 t 'Q=3000' ";
  $cmd .= " , ";
  $cmd .= "              './make_radio_data.out' index 11 using 2:10 ";
  $cmd .= "        with points lt -1 lw 2 pt 5 ps 1.0 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;
