#!/usr/bin/perl
#

$debug = 1;

$DEGTORAD = (3.14159 / 180.0);

$infile = "./nbody.med_eccen.proj.out";
$rot_theta_deg = 0.0;
$rot_theta = $rot_theta_deg*$DEGTORAD;
$proj_beta_deg = 35.0;
$proj_beta = $proj_beta_deg*$DEGTORAD;


if (1 == 1) {
  # pretty simple: just a projection around long axis
  $cmd = "./modify_ellipse infile=$infile deproject=$proj_beta_deg | grep -v '#' | awk '{ if (NF==5) { print  \$2, 0, 0,  \$3, \$4, \$5 } }' > foo ";
  $ret = exec_cmd($cmd);
  exit 0;
} else {
  # complex: projection around an off-major axis
  $cmd = "./modify_ellipse infile=$infile rotate=$rot_theta_deg project=$proj_beta_deg  | grep -v '#' | awk '{ if (NF==5) { print  \$2, 0, 0,  \$3, \$4, \$5 } }' > foo ";
#  $cmd = "./modify_ellipse infile=$infile rotate=69 project=27 | grep -v '#' | awk '{ if (NF==5) { print  \$2, 0, 0,  \$3, \$4, \$5 } }' > foo ";
}
$ret = exec_cmd($cmd);
#$cmd = "time ./find_proj infile=foo verbose > foo2 ";


$cmd = "time ./find_rot_proj infile=foo.F verbose > foo2 ";
$ret = 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);
}


