#!/usr/bin/perl
#

my $KG2OZ = 35.274;

  my($output_file, $term_options);


  ##############################################################
  # plot showing ball speed as function of bat speed, 
  #   for several bat masses

  $output_file = "batted_ball_a.ps";
  $term_options = "postscript 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 left \n";
  printf CMDFILE "set ylabel 'Speed of outgoing ball (mph)' \n";
  printf CMDFILE "set xlabel 'Speed of incoming bat (mph) ' \n";
  printf CMDFILE "set title 'Perfect contact with a 90 mph fastball' \n";
  printf CMDFILE "set object 1 rect from 20,97 to 120,117 ";
  printf CMDFILE "    back fc lt 3 lw 0 fs solid 0.1   \n";
  printf CMDFILE "set label 2 'likely home run'  ";
  printf CMDFILE "    at 33,110  textcolor lt 3    \n";
  
  $oz_05 = sprintf "%.0f", 0.5*$KG2OZ;
  $oz_09 = sprintf "%.0f", 0.9*$KG2OZ;
  $oz_13 = sprintf "%.0f", 1.3*$KG2OZ;
  $cmd = "plot [30:100][40:140] 'bbs_0.5.out' using 4:8 ";
  $cmd .= "     with points pt 3 ps 1.5 lc 1 lw 3 t '$oz_05 ounce' ";
  $cmd .= " , ";
  $cmd .= "          'bbs_0.9.out' using 4:8 ";
  $cmd .= "     with points pt 6 ps 1.5 lc 2 lw 5 t '$oz_09 ounce' ";
  $cmd .= " , ";
  $cmd .= "          'bbs_1.3.out' using 4:8 ";
  $cmd .= "     with points pt 2 ps 1.0 lc -1 lw 2 t '$oz_13 ounce' ";
  $cmd .= " \n";

  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 showing pre-contact-BAT speed as function of bat mass,
  #   based on some physics, Miguel Cabrera as reference,
  #   and a maximum possible swing speed

  $output_file = "bat_speed_a.ps";
  $term_options = "postscript 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 left \n";
  printf CMDFILE "set ylabel 'Speed of bat before contact (mph)' \n";
  printf CMDFILE "set xlabel 'Mass of bat (ounces) ' \n";
  printf CMDFILE "set title 'How fast can one swing a bat?' \n";
#  printf CMDFILE "set object 1 rect from 10,97 to 120,117 ";
#  printf CMDFILE "    back fc lt 3 lw 0 fs solid 0.1   \n";
#  printf CMDFILE "set label 2 'likely home run'  ";
#  printf CMDFILE "    at 33,110  textcolor lt 3    \n";
  
  $cmd = "plot [20:50][20:85] 'swing_bat_speed.out' using 2:4 ";
  $cmd .= "     with points pt 6 ps 1.5 lc 3 lw 3 t '' ";
  $cmd .= " \n";

  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 showing batted ball speed as function of bat mass,
  #   based on some physics, Miguel Cabrera as reference,
  #   and a maximum possible swing speed

  $output_file = "batted_ball_b.ps";
  $term_options = "postscript 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 left \n";
  printf CMDFILE "set ylabel 'Speed of outgoing ball (mph)' \n";
  printf CMDFILE "set xlabel 'Mass of bat (ounces) ' \n";
  printf CMDFILE "set title 'Perfect contact with a 90 mph fastball' \n";
  printf CMDFILE "set object 1 rect from 10,97 to 120,117 ";
  printf CMDFILE "    back fc lt 3 lw 0 fs solid 0.1   \n";
  printf CMDFILE "set label 2 'likely home run'  ";
  printf CMDFILE "    at 43,110  textcolor lt 3    \n";
  
  $cmd = "plot [20:50][40:120] 'swing_bat_speed.out' using 2:8 ";
  $cmd .= "     with points pt 3 ps 1.5 lc 1 lw 3 t '' ";
  $cmd .= " \n";

  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 showing trajectory of batted ball
  #   ideal case: no air resistance, 45 degrees

  $output_file = "fly_traj_a.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $METER2FOOT = (1.0/0.3048);

  $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 left \n";
  printf CMDFILE "set ylabel 'Height (ft) ' \n";
  printf CMDFILE "set xlabel 'Distance (ft) ' \n";
  printf CMDFILE "set title 'Batted ball with initial speed 105 mph, angle 45 deg ' \n";
  
  $cmd = "plot [0:750][0:220] 'flyball.A.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 3 ps 0.5 lc 1 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.A.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lc 1 lw 3 t '' ";
  $cmd .= " \n";

  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 showing trajectory of batted ball
  #   ideal case: no air resistance, 45 degrees
  #   second case: air resistance, 45 degrees

  $output_file = "fly_traj_b.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $METER2FOOT = (1.0/0.3048);

  $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 ylabel 'Height (ft) ' \n";
  printf CMDFILE "set xlabel 'Distance (ft) ' \n";
  printf CMDFILE "set title 'Batted ball with initial speed 105 mph, angle 45 deg ' \n";
  
  $cmd = "plot [0:750][0:220] 'flyball.A.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 3 ps 0.5 lc 1 lw 2 t 'no air' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.A.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lc 1 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.B.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 0.5 lt 1 lc -1 lw 3 t 'air resist' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.B.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc -1 lw 3 t '' ";
  $cmd .= " \n";

  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 showing trajectory of batted ball
  #   ideal case: no air resistance, 45 degrees
  #   many cases: air resistance, 20-25-30-35-40-45-50 degrees

  $output_file = "fly_traj_c.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $METER2FOOT = (1.0/0.3048);

  $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 ylabel 'Height (ft) ' \n";
  printf CMDFILE "set xlabel 'Distance (ft) ' \n";
  printf CMDFILE "set title 'Batted ball with initial speed 105 mph plus air resistance ' \n";
  
  $cmd = "plot [0:750][0:220] 'flyball.A.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 3 ps 0.5 lc 1 lw 2 t 'no air' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.A.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lc 1 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.D.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines lt 1 lc 3 lw 3 t '20 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.D.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 3 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.E.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc 2 lw 3 t '25 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.E.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 2 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.F.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc 4 lw 3 t '30 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.F.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 4 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.G.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc 5 lw 3 t '35 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.G.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 5 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.H.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc 8 lw 3 t '40 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.H.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 8 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.B.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc -1 lw 3 t '45 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.B.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc -1 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.B2.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 2 lc 1 lw 3 t '50 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.B2.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 1 lw 3 t '' ";
  $cmd .= " \n";

  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 showing trajectory of batted ball
  #   ideal case: no air resistance, 45 degrees
  #   many cases: air resistance, Magnus, 20-25-30-35-40-45 degrees

  $output_file = "fly_traj_d.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $METER2FOOT = (1.0/0.3048);

  $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 ylabel 'Height (ft) ' \n";
  printf CMDFILE "set xlabel 'Distance (ft) ' \n";
  printf CMDFILE "set title 'Batted ball with initial speed 105 mph plus air resistance + Magnus  ' \n";
  
  $cmd = "plot [0:750][0:220] 'flyball.A.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 3 ps 0.5 lc 1 lw 2 t 'no air' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.A.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lc 1 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.I.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines lt 1 lc 3 lw 3 t '20 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.I.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 3 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.J.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc 2 lw 3 t '25 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.J.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 2 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.K.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc 4 lw 3 t '30 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.K.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 4 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.L.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc 5 lw 3 t '35 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.L.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 5 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.M.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc 8 lw 3 t '40 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.M.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 8 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.N.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc -1 lw 3 t '45 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.N.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc -1 lw 3 t '' ";
  $cmd .= " \n";

  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 showing trajectory of batted ball
  #   ideal case: no air resistance, 45 degrees
  #   many cases: air resistance, Magnus, 20-25-30-35-40-45 degrees
  #   zoomed in to show details

  $output_file = "fly_traj_e.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $METER2FOOT = (1.0/0.3048);

  $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 ylabel 'Height (ft) ' \n";
  printf CMDFILE "set xlabel 'Distance (ft) ' \n";
  printf CMDFILE "set title 'Batted ball with initial speed 105 mph plus air resistance + Magnus  ' \n";
  
  $cmd = "plot [0:450][0:180] 'flyball.A.dat' index 0 ";
  $cmd .= "      using (-1e6+\$5*$METER2FOOT):(-1e6+\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 3 ps 0.5 lc 1 lw 2 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.A.dat' index 1 ";
  $cmd .= "      using (-1e6+\$5*$METER2FOOT):(-1e6+\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lc 1 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.I.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines lt 1 lc 3 lw 3 t '20 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.I.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 3 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.J.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc 2 lw 3 t '25 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.J.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 2 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.K.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc 4 lw 3 t '30 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.K.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 4 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.L.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc 5 lw 3 t '35 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.L.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 5 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.M.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc 8 lw 3 t '40 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.M.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc 8 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.N.dat' index 0 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with lines  lt 1 lc -1 lw 3 t '45 deg' ";
  $cmd .= " , ";
  $cmd .= "                   'flyball.N.dat' index 1 ";
  $cmd .= "      using (\$5*$METER2FOOT):(\$6*$METER2FOOT) ";
  $cmd .= "     with points pt 6 ps 1.5 lt 1 lc -1 lw 3 t '' ";
  $cmd .= " \n";

  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;

