#!/bin/bash

# It seems stupid, but in Fedora 16, if you don't explicitly
# make $HOME your current working directory, birch starts in root (/)
# and for whatever reason, bioLegato jobs launched from birch won't 
# be able to find important files.
cd

# Get BioLegato environment variables.
if [ -f $BIRCH/admin/setblenv.profile.$BIRCH_PLATFORM.source ]
   then
      . $BIRCH/admin/setblenv.profile.$BIRCH_PLATFORM.source
fi

BIOLEGATO_HOME=$BIRCH/java/bioLegato
export BIOLEGATO_HOME


# The location of anciliary data files used by bioLegato.
BL_DATA_DIR=$BIRCH/dat/birch
export BL_DATA_DIR
BL_PROPERTIES=$BL_DATA_DIR/birch.properties
export BL_PROPERTIES

# The USERONLY variable is used in Edit --> BLHelper. The menu file for this item is
# a symbolic link to $BIRCH/dat/birchadmin/PCD/HelperApps.blmenu. The latter runs BLHelper.py
# WITHOUT the USERONLY variable. That causes BLHelper.py to change settings for all BIRCH users.
# In contrast, when running the birch application from this script, USERONLY runs BLHelper.py to
# with the --useronly option, which causes settings to be saved to each user's $HOME/.config/BIRCH/BLHelper.source file
USERONLY="--useronly"
export USERONLY

# The -dir switch is mainly for launching bioLegato from the birch launcher. By 
# prompting the user for a working folder, we help enforce good file organization
# habits.
if [ $# -gt 0 ]
then
   if [ ${1} = "-dir" ]
   then

      # Get rid of the -dir switch, and send the remaining command line arguments to bioLegato
      shift

      #Prompt the user to choose a working directory
      CHANGEDIR=`java -cp "$BIRCH/script" DirChooser "Where do you want to work? Choose a folder."`

      if [ -d "$CHANGEDIR" ]; then
	  cd "$CHANGEDIR"
      fi
   fi
fi

################################################################
#             User Preferences that override defaults          #
################################################################

BIRCHSettingsFile=$HOME/.config/BIRCH/BIRCHsettings.source
if [ -f $BIRCHSettingsFile ]
   then
      . $BIRCHSettingsFile
fi

BLHelperFile=$HOME/.config/BIRCH/BLHelper.source
if [ -f $BLHelperFile ]
   then
      . $BLHelperFile
fi

#java -Xms6M -Xmx64M -jar $BIOLEGATO_HOME/image.jar $*
#java -Xms6M -Xmx96M -jar $BIOLEGATO_HOME/biolegato.jar $*
#java -Xms6M -Xmx128M -jar $BIOLEGATO_HOME/biolegato.jar $*
#java -Xms6M -Xmx256M -jar $BIOLEGATO_HOME/biolegato.jar $*
#java -Xms6M -Xmx384M -jar $BIOLEGATO_HOME/image.jar $* "$BIRCH/dat/birch/splash.blimg"
java -Xms6M -Xmx32M -jar $BIOLEGATO_HOME/image.jar $* "$BIRCH/dat/birch/splash.blimg"
#java -jar $BIOLEGATO_HOME/biolegato.jar $*

# ------------------------ LOGGING ------------------------------
# For future use when we have a secure logging method.

#if [ "$BIRCH_LOGGING" -eq "1" ] 
#    then
#    echo `whoami` `date` >> $BIRCH/local/admin/biolegato.log
#fi