#!/bin/sh


## simple script to execute java with the appropriate options to run beast
##
## edeveaud, inspired from mauve.sh  (c) 2003 Aaron Darling

BEAST_LIB="/opt/gensoft/exe/beast/v1.10.4/libexec"

JAVA_CMD="java"
JAVA_ARGS="-Djava.library.path=\"$BEAST_LIB:${BEAGLELIB_ROOT}/lib:$LD_LIBRARY_PATH\" -cp"
JAVA_OPTS=${BEAST_JAVA_OPTS:-${JAVA_OPTS:-"-Xms256M -Xmx4G"}}

## force -template file to be mandatory for beauty

TMPL_DIR="/opt/gensoft/exe/beast/v1.10.4/share/templates"
TMPL_OPT=""

PROG=$(basename $0)


#check if -template option is given, if not abort and display a message
CMDLINE="$*"

while [ "$*" != "" ]
 do
   case $1 in 
     '-template' ) TMPL_OPT='set'; break ;;
     *    ) shift ;;
   esac 
 done

# display message 
if [ $PROG = "beauti" ]; then
    if [ -z  "$TMPL_OPT" ] ; then
       echo "template file is mandatory."  1>&2
       echo "use one of the template file available here:" 1>&2
       echo "$TMPL_DIR"  1>&2
       echo "or one of your own template" 1>&2
       exit 1
    fi; 
fi

if [ $PROG = "beauti" ]; then
    $JAVA_CMD $JAVA_OPTS $JAVA_ARGS "$BEAST_LIB/beast.jar" beast.app.beauti.Beauti $CMDLINE
fi

if [ $PROG = "beast" ]; then
    $JAVA_CMD $JAVA_OPTS $JAVA_ARGS "$BEAST_LIB/beast.jar:$BEAST_LIB/beast-beagle.jar" dr.app.beast.BeastMain $CMDLINE
fi


#$JAVA_CMD $JAVA_OPTS $JAVA_ARGS -Duser.language=en "$BEAST_LIB/launcher.jar" beast.app.beauti.BeautiLauncher -capture $CMDLINE


