#! /bin/sh
## This Bourne-shell script is used to initialize and run Ferret using 
## the pyferret Python module.  The intent of this script is to provide 
## a traditional Ferret interface through the pyferret module.

## set python_exe to the (optionally full-path) python executable to use
python_exe=PYTHON_EXECUTABLE

## Make sure the FER_* environment variables are assigned
if [ -z "${FER_LIBS}" ]; then
## Either source the ferret_paths script to assign the environment variables
#    . "/my/path/to/ferret_paths.sh"
## or just throw an error if they should have already been defined
    echo "**ERROR: Ferret environment variables are not defined"
    exit 1
##
fi


##
## ==== The following should not need any modifications ====
##

## The pyferret assignment to PYTHONPATH and LD_LIBRARY_PATH 
## is now done in the ferret_paths script.

## Finally, execute an in-line Python script to run Ferret using the pyferret 
## module.  The init method explicity processes the $PYTHONSTARTUP file, if it
## exists and if '-secure' was not given as a command-line argument.
if echo "$@" | grep -q -- "-linebuffer"; then
    GFORTRAN_UNBUFFERED_PRECONNECTED=1
    export GFORTRAN_UNBUFFERED_PRECONNECTED
    python_flags="-u -i"
else
    python_flags="-i"
fi
${python_exe} ${python_flags} -c "import sys; import pyferret; (errval, errmsg) = pyferret.init(sys.argv[1:], True)" "$@"

