#!/usr/bin/perl
#
# run the "traj" program to compute a number of trajectories,
#   and place the output in a set of files with names like
#
#         traj.A.dat     traj.B.dat
#
# processed so that they are ready to be plotted by "make_plot.pl".
#
# MWR 8/18/2008

$debug = 1;

if (0 == 1) {

   # fastball, no drag, no magnus, to center of strike zone
   $cmd = "./traj 0 0 90 2200 > foo ";
   exec_cmd($cmd);
   $cmd = "grep QQ foo | perl print_last.pl > traj.A.dat ";
   exec_cmd($cmd);
   $cmd = "perl make_second_stanza.pl traj.A.dat ";
   exec_cmd($cmd);
   
   
   # fastball, air drag, no magnus, same angles as A
   $cmd = "./traj 1 0 67 2200 -1.156 -2.094 > foo ";
   exec_cmd($cmd);
   $cmd = "grep QQ foo | perl print_last.pl > traj.B.dat ";
   exec_cmd($cmd);
   $cmd = "perl make_second_stanza.pl traj.B.dat ";
   exec_cmd($cmd);
   
   
   
   # fastball, air drag, no magnus, to center of zone
   $cmd = "./traj 1 0 90 2200  > foo ";
   exec_cmd($cmd);
   $cmd = "grep QQ foo | perl print_last.pl > traj.C.dat ";
   exec_cmd($cmd);
   $cmd = "perl make_second_stanza.pl traj.C.dat ";
   exec_cmd($cmd);
   
   # fastball, air drag, Magnus, same as C
   $cmd = "./traj 1 1 90 2200 -0.9375 -2.0625 > foo ";
   exec_cmd($cmd);
   $cmd = "grep QQ foo | perl print_last.pl > traj.D.dat ";
   exec_cmd($cmd);
   $cmd = "perl make_second_stanza.pl traj.D.dat ";
   exec_cmd($cmd);
   
   
   # super fastball, super spin air drag, Magnus, horizontal release
   #     a really rising fastball
   $cmd = "./traj 1 1 110 3500 0.000   -2.0625 > foo ";
   exec_cmd($cmd);
   $cmd = "grep QQ foo | perl print_last.pl > traj.O.dat ";
   exec_cmd($cmd);
   $cmd = "perl make_second_stanza.pl traj.O.dat ";
   exec_cmd($cmd);
   
   
   
   # fastball, air drag, Magnus, centered
   $cmd = "./traj 1 1 90 2200  > foo ";
   exec_cmd($cmd);
   $cmd = "grep QQ foo | perl print_last.pl > traj.E.dat ";
   exec_cmd($cmd);
   $cmd = "perl make_second_stanza.pl traj.E.dat ";
   exec_cmd($cmd);
   
   
   # changeup, air drag, Magnus, same angles as E
   $cmd = "./traj 1 1 80 1300 -3.000 -2.0625 > foo ";
   exec_cmd($cmd);
   $cmd = "grep QQ foo | perl print_last.pl > traj.F.dat ";
   exec_cmd($cmd);
   $cmd = "perl make_second_stanza.pl traj.F.dat ";
   exec_cmd($cmd);
   
   
   # curve, air drag, Magnus, same angles as E
   $cmd = "./traj 1 1 80 -1300 -3.000 -2.0625 > foo ";
   exec_cmd($cmd);
   $cmd = "grep QQ foo | perl print_last.pl > traj.G.dat ";
   exec_cmd($cmd);
   $cmd = "perl make_second_stanza.pl traj.G.dat ";
   exec_cmd($cmd);
   
   # curve, air drag, Magnus, centered
   $cmd = "./traj 1 1 80 -1300 > foo ";
   exec_cmd($cmd);
   $cmd = "grep QQ foo | perl print_last.pl > traj.H.dat ";
   exec_cmd($cmd);
   $cmd = "perl make_second_stanza.pl traj.H.dat ";
   exec_cmd($cmd);
   
   # changeup, air drag, Magnus, centered
   $cmd = "./traj 1 1 80 1300 > foo ";
   exec_cmd($cmd);
   $cmd = "grep QQ foo | perl print_last.pl > traj.I.dat ";
   exec_cmd($cmd);
   $cmd = "perl make_second_stanza.pl traj.I.dat ";
   exec_cmd($cmd);
   
   
   # changeup, air drag, Magnus 
   #        designed to have same height as centered fastball at t=0.23 sec
   $cmd = "./traj 1 1 80 1300 -3.05 -2.078 > foo ";
   exec_cmd($cmd);
   $cmd = "grep QQ foo | perl print_last.pl > traj.J.dat ";
   exec_cmd($cmd);
   $cmd = "perl make_second_stanza.pl traj.J.dat ";
   exec_cmd($cmd);
   
   # curve, air drag, Magnus 
   #        designed to have same height as centered fastball at t=0.23 sec
   $cmd = "./traj 1 1 80 -1300 -1.20 -2.078 > foo ";
   exec_cmd($cmd);
   $cmd = "grep QQ foo | perl print_last.pl > traj.K.dat ";
   exec_cmd($cmd);
   $cmd = "perl make_second_stanza.pl traj.K.dat ";
   exec_cmd($cmd);
   
   # curve, air drag, Magnus 
   #        designed to have same spatial location 
   #             as centered fastball at t=0.23 sec
   $cmd = "./traj 1 1 80 -1300 -0.42 -2.078 > foo ";
   exec_cmd($cmd);
   $cmd = "grep QQ foo | perl print_last.pl > traj.M.dat ";
   exec_cmd($cmd);
   $cmd = "perl make_second_stanza.pl traj.M.dat ";
   exec_cmd($cmd);
   
   
   # changeup, air drag, Magnus 
   #        designed to have same spatial location 
   #             as centered fastball at t=0.23 sec
   $cmd = "./traj 1 1 80 1300 -2.48 -2.078 > foo ";
   exec_cmd($cmd);
   $cmd = "grep QQ foo | perl print_last.pl > traj.N.dat ";
   exec_cmd($cmd);
   $cmd = "perl make_second_stanza.pl traj.N.dat ";
   exec_cmd($cmd);
   

}


# 90-mph curveball, air drag, Magnus
#        designed to have same speed, spin rate, initial dir as basic fastball
#        (i.e. traj.D.dat)
$cmd = "./traj 1 1 90 -2200 -0.9375 -2.0625 > foo ";
exec_cmd($cmd);
$cmd = "grep QQ foo | perl print_last.pl > traj.Q.dat ";
exec_cmd($cmd);
$cmd = "perl make_second_stanza.pl traj.Q.dat ";
exec_cmd($cmd);


# 80-mph curveball, air drag, Magnus
#        designed to have typical curveball speed and spin, 
#        but same initial direction as basic fastball
#        (i.e. traj.D.dat)
$cmd = "./traj 1 1 80 -1300 -0.9375 -2.0625 > foo ";
exec_cmd($cmd);
$cmd = "grep QQ foo | perl print_last.pl > traj.R.dat ";
exec_cmd($cmd);
$cmd = "perl make_second_stanza.pl traj.R.dat ";
exec_cmd($cmd);


# 80-mph changeup, air drag, Magnus
#        designed to have typical changeup speed (80 mph),
#             but the same spin rate as a fastball (2200 RPM)
#        and same initial direction as centered fastball
#        (i.e. traj.E.dat)
$cmd = "./traj 1 1 80 2200 -3.0000 -2.0625 > foo ";
exec_cmd($cmd);
$cmd = "grep QQ foo | perl print_last.pl > traj.S.dat ";
exec_cmd($cmd);
$cmd = "perl make_second_stanza.pl traj.S.dat ";
exec_cmd($cmd);


# 80-mph changeup, air drag, Magnus
#        designed to have typical changeup speed and spin,
#        and same initial direction as basic fastball
#        (i.e. traj.D.dat)
$cmd = "./traj 1 1 80 1300 -3.0000 -2.0625 > foo ";
exec_cmd($cmd);
$cmd = "grep QQ foo | perl print_last.pl > traj.T.dat ";
exec_cmd($cmd);
$cmd = "perl make_second_stanza.pl traj.T.dat ";
exec_cmd($cmd);




exit 0;









##############################################################################
# PROCEDURE: exec_cmd
#
# DESCRIPTION: Execute the given shell command line.  If the $debug flag
#              is set, we print to stdout the command line, and
#              also print out the result string.
#
# RETURNS:
#              the result of the command
#
#
sub exec_cmd {

  my($cmd, $ret);

  $cmd = $_[0];

  if ($debug > 0) {
    printf "cmd is ..$cmd.. \n";
  }
  $ret = `$cmd`;
  if ($debug > 0) {
    printf "ret is ..$ret.. \n";
  }

  return($ret);
}





