#!/bin/sh
#  N.B. the previous line should be blank. 
#  But not if you want to exec it from Java!
#+
#  Name:
#     runFROG

#  Purpose:
#     Start the main FROG application.

#  Description:
#     This script defines the environment necessary to start the FROG
#     program. FROG should be installed in a standard place, the 
#     main directory of which (i.e. the one containing this file) should
#     be identified by the environment variable FROG_DIR. Any arguments
#     to this script should be the names of any time series to add to the 
#     stack and then display.

#  Type of Module:
#     Shell script.

#  Copyright:
#     Copyright (C) 2001-2004 Central Laboratory of the Research Councils

#  Authors:
#     AA: Alasdair Allan (Starlink, University of Exeter)
#     PWD: P.W. Draper (Starlink, Durham University)
#     {enter_new_authors_here}

#  History:
#     15-DEC-2004 (PWD):
#        Switch to using the standard starjava script.
#     07-FEB-2004 (AA):
#        Added CLASSPATH to FROG Help JAR file
#     26-NOV-2002 (AA):
#        Modified for FROG
#     01-AUG-2002 (PWD):
#        Original version.
#     {enter_further_changes_here}

#  Bugs:
#     {note_any_bugs_here}

#-
echo "Starting frog"

#  Locate this script or FROG_DIR to find our jar files etc.
if test -z "$FROG_DIR"; then
   FROG_DIR=`dirname $0`
fi
echo "FROG_DIR = $FROG_DIR"

# Set the amount of memory that we use for the heap. Increase this
# if you start getting out of memory errors. Decrease it for smaller 
# footprint machines.
if test -z "$frog_MAXMEM"; then
   frog_MAXMEM=128m
fi

#  Locate the application jar file. This is relative to this script or
#  FROG_DIR.
appjar="$FROG_DIR/../../lib/frog/frog.jar"
if test ! -f "$appjar"; then
   echo "Failed to locate the frog application. Please define FROG_DIR"
   exit
fi

# Make sure that we get the frog_docs.jar file into the CLASSPATH
if test -z "$CLASSPATH"; then
   CLASSPATH=$FROG_DIR/../../lib/frog/frog_help.jar
else
   CLASSPATH=$FROG_DIR/../../lib/frog/frog_help.jar:${CLASSPATH}
fi
export CLASSPATH

#  Check if we are running Cygwin. If so then convert PATHs to Windows format.
case "`uname`" in
  CYGWIN*)
   appjar=`cygpath --windows "$appjar"`
   CLASSPATH=`cygpath --windows --path "$CLASSPATH"`
   ;;
esac

#  Locate the "starjava" command. This should be in ".." or on the PATH.
if test -f "$FROG_DIR/../starjava"; then
   starjava="$FROG_DIR/../starjava"
else
   starjava="starjava"
fi

# Run up the main application. Uses the JVM located by the starjava script.
$starjava -mx$frog_MAXMEM $defines \
          -jar $appjar \
          ${1+"$@"}
exit
