#! /bin/sh

############################################################
# This shell script is a "front-end" to twobody which 
# expedites the analysis of the results from that code,
# including the plotting of particle position, d(energy), 
# d(angular momentum) as a function of time using the 
# xvs interactive graphics server.
############################################################
P=`basename $0`

############################################################
# Set defaults 
############################################################
tmax=5.0
dt=0.05
tol=1.0d-6

############################################################
# Usage
############################################################
Usage() {
cat<<END
usage: $P <y0> [<tol>}

       Default tol: $tol

       y0 = 1.0 will produce circular orbit.
END
exit 1
}

############################################################
# Argument handling
############################################################
case $# in
1|2) y0=$1; tol=${2-$tol};;
*) Usage;;
esac

############################################################
# Build application, run it, and process the results.
############################################################
make -f Makefile twobody

tag="$y0"_"$tol"
ofile=out_"$tag"

twobody 0.0 $y0 1.0 0.0 $tmax $dt $tol > $ofile

nth 2 3 < $ofile | xvs put xcyc_$tag 0.0
nth 1 2 < $ofile | xvs put xc_$tag 0.0
nth 1 3 < $ofile | xvs put yc_$tag 0.0
nth 1 4 < $ofile | xvs put dEtot_$tag 0.0
nth 1 5 < $ofile | xvs put dJtot_$tag 0.0

exit 0