#!/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;

# home of the executable program "flyball"
$flyball_exe = "/home/richmond/richmond_www/baseball/traj/fly/flyball";
# home of the Perl script "print_last.pl"
$print_last = "/home/richmond/richmond_www/baseball/traj/fly/print_last.pl";
# the Perl script which prints lines for every 1.0 seconds of trajectory
$make_second = "./make_second_stanza_1sec.pl";
# default value of backspin for batted balls
$rpm = 1500;
# drag coefficient (Cd)
$cd = 0.33;

$ball_speed = 105;

if (1 == 0) {

		  # 100-mph flyball, no air drag, no Magnus
		  $cmd = "$flyball_exe 0 0 $ball_speed 0  45 0  $cd               > foo ";
		  exec_cmd($cmd);
		  $cmd = "grep QQ foo | perl $print_last > flyball.A.dat ";
		  exec_cmd($cmd);
		  $cmd = "perl $make_second flyball.A.dat ";
		  exec_cmd($cmd);


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


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


		  # 100-mph flyball, air drag, no Magnus, 20 degree angle
		  $cmd = "$flyball_exe 1 0 $ball_speed 0  20 0   $cd          > foo ";
		  exec_cmd($cmd);
		  $cmd = "grep QQ foo | perl $print_last > flyball.D.dat ";
		  exec_cmd($cmd);
		  $cmd = "perl $make_second flyball.D.dat ";
		  exec_cmd($cmd);

		  # 100-mph flyball, air drag, no Magnus, 25 degree angle
		  $cmd = "$flyball_exe 1 0 $ball_speed 0  25 0   $cd          > foo ";
		  exec_cmd($cmd);
		  $cmd = "grep QQ foo | perl $print_last > flyball.E.dat ";
		  exec_cmd($cmd);
		  $cmd = "perl $make_second flyball.E.dat ";
		  exec_cmd($cmd);

		  # 100-mph flyball, air drag, no Magnus, 30 degree angle
		  $cmd = "$flyball_exe 1 0 $ball_speed 0  30 0   $cd          > foo ";
		  exec_cmd($cmd);
		  $cmd = "grep QQ foo | perl $print_last > flyball.F.dat ";
		  exec_cmd($cmd);
		  $cmd = "perl $make_second flyball.F.dat ";
		  exec_cmd($cmd);

		  # 100-mph flyball, air drag, no Magnus, 35 degree angle
		  $cmd = "$flyball_exe 1 0 $ball_speed 0  35 0   $cd          > foo ";
		  exec_cmd($cmd);
		  $cmd = "grep QQ foo | perl $print_last > flyball.G.dat ";
		  exec_cmd($cmd);
		  $cmd = "perl $make_second flyball.G.dat ";
		  exec_cmd($cmd);

		  # 100-mph flyball, air drag, no Magnus, 40 degree angle
		  $cmd = "$flyball_exe 1 0 $ball_speed 0  40 0   $cd          > foo ";
		  exec_cmd($cmd);
		  $cmd = "grep QQ foo | perl $print_last > flyball.H.dat ";
		  exec_cmd($cmd);
		  $cmd = "perl $make_second flyball.H.dat ";
		  exec_cmd($cmd);





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

}

if (1 == 0) {

		  # 100-mph flyball, air drag, Magnus, hit at 20 degrees
		  $cmd = "$flyball_exe 1 1 $ball_speed $rpm  20 0   $cd             > foo ";
		  exec_cmd($cmd);
		  $cmd = "grep QQ foo | perl $print_last > flyball.I.dat ";
		  exec_cmd($cmd);
		  $cmd = "perl $make_second flyball.I.dat ";
		  exec_cmd($cmd);

		  # 100-mph flyball, air drag, Magnus, hit at 25 degrees
		  $cmd = "$flyball_exe 1 1 $ball_speed $rpm  25 0   $cd             > foo ";
		  exec_cmd($cmd);
		  $cmd = "grep QQ foo | perl $print_last > flyball.J.dat ";
		  exec_cmd($cmd);
		  $cmd = "perl $make_second flyball.J.dat ";
		  exec_cmd($cmd);


		  # 100-mph flyball, air drag, Magnus, hit at 30 degrees
		  $cmd = "$flyball_exe 1 1 $ball_speed $rpm  30 0   $cd             > foo ";
		  exec_cmd($cmd);
		  $cmd = "grep QQ foo | perl $print_last > flyball.K.dat ";
		  exec_cmd($cmd);
		  $cmd = "perl $make_second flyball.K.dat ";
		  exec_cmd($cmd);


		  # 100-mph flyball, air drag, Magnus, hit at 35 degrees
		  $cmd = "$flyball_exe 1 1 $ball_speed $rpm  35 0   $cd             > foo ";
		  exec_cmd($cmd);
		  $cmd = "grep QQ foo | perl $print_last > flyball.L.dat ";
		  exec_cmd($cmd);
		  $cmd = "perl $make_second flyball.L.dat ";
		  exec_cmd($cmd);


		  # 100-mph flyball, air drag, Magnus, hit at 40 degrees
		  $cmd = "$flyball_exe 1 1 $ball_speed $rpm  40 0   $cd             > foo ";
		  exec_cmd($cmd);
		  $cmd = "grep QQ foo | perl $print_last > flyball.M.dat ";
		  exec_cmd($cmd);
		  $cmd = "perl $make_second flyball.M.dat ";
		  exec_cmd($cmd);

		  # 100-mph flyball, air drag, Magnus, hit at 45 degrees
		  $cmd = "$flyball_exe 1 1 $ball_speed $rpm  45 0   $cd             > foo ";
		  exec_cmd($cmd);
		  $cmd = "grep QQ foo | perl $print_last > flyball.N.dat ";
		  exec_cmd($cmd);
		  $cmd = "perl $make_second flyball.N.dat ";
		  exec_cmd($cmd);



}


# $ball_speed-mph flyball, air drag, Magnus, hit at 28 degrees
$cmd = "$flyball_exe 1 0 $ball_speed $rpm  50 0  $cd              > foo ";
exec_cmd($cmd);
$cmd = "grep QQ foo | perl $print_last > flyball.B2.dat ";
exec_cmd($cmd);
$cmd = "perl $make_second flyball.B2.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);
}





