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

$debug = 1;

# default value of backspin for batted balls
$rpm = 1480;

# 100-mph flyball, no air drag, no Magnus
$cmd = "./flyball 0 0 100 0  45 0  0.4               > foo ";
exec_cmd($cmd);
$cmd = "grep QQ foo | perl print_last.pl > flyball.A.dat ";
exec_cmd($cmd);
$cmd = "perl make_second_stanza.pl flyball.A.dat ";
exec_cmd($cmd);


# 100-mph flyball, air drag, no Magnus, 45 degree angle
$cmd = "./flyball 1 0 100 0  45 0    0.4           > foo ";
exec_cmd($cmd);
$cmd = "grep QQ foo | perl print_last.pl > flyball.B.dat ";
exec_cmd($cmd);
$cmd = "perl make_second_stanza.pl flyball.B.dat ";
exec_cmd($cmd);


# 100-mph flyball, air drag, Magnus, hit at 45 degrees
$cmd = "./flyball 1 1 100 $rpm  45 0   0.4             > foo ";
exec_cmd($cmd);
$cmd = "grep QQ foo | perl print_last.pl > flyball.C.dat ";
exec_cmd($cmd);
$cmd = "perl make_second_stanza.pl flyball.C.dat ";
exec_cmd($cmd);


# 100-mph flyball, air drag, no Magnus, 25 degree angle
$cmd = "./flyball 1 0 100 0  25 0   0.4          > foo ";
exec_cmd($cmd);
$cmd = "grep QQ foo | perl print_last.pl > flyball.D.dat ";
exec_cmd($cmd);
$cmd = "perl make_second_stanza.pl flyball.D.dat ";
exec_cmd($cmd);


# 100-mph flyball, air drag, Magnus, hit at 25 degrees
$cmd = "./flyball 1 1 100 $rpm  25 0  0.4              > foo ";
exec_cmd($cmd);
$cmd = "grep QQ foo | perl print_last.pl > flyball.E.dat ";
exec_cmd($cmd);
$cmd = "perl make_second_stanza.pl flyball.E.dat ";
exec_cmd($cmd);

# 100-mph flyball, air drag, Magnus, hit at 25 degrees
#    change drag coeff from default 0.4 to 0.42 (low seam)
$cmd = "./flyball 1 1 100 $rpm  25 0  0.42             > foo ";
exec_cmd($cmd);
$cmd = "grep QQ foo | perl print_last.pl > flyball.F.dat ";
exec_cmd($cmd);
$cmd = "perl make_second_stanza.pl flyball.F.dat ";
exec_cmd($cmd);

# 100-mph flyball, air drag, Magnus, hit at 25 degrees
#    change drag coeff from default 0.4 to 0.50 (no seam)
$cmd = "./flyball 1 1 100 $rpm  25 0  0.50             > foo ";
exec_cmd($cmd);
$cmd = "grep QQ foo | perl print_last.pl > flyball.G.dat ";
exec_cmd($cmd);
$cmd = "perl make_second_stanza.pl flyball.G.dat ";
exec_cmd($cmd);

# 100-mph flyball, air drag, Magnus, hit at 25 degrees
#    change drag coeff from default 0.4 to 0.41 (slightly low seam)
$cmd = "./flyball 1 1 100 $rpm  25 0  0.41             > foo ";
exec_cmd($cmd);
$cmd = "grep QQ foo | perl print_last.pl > flyball.H.dat ";
exec_cmd($cmd);
$cmd = "perl make_second_stanza.pl flyball.H.dat ";
exec_cmd($cmd);








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);
   

}




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);
}





