#!/bin/sh

# Check for FSLDIR being set \
if [ -z "$FSLDIR" ]; then echo "You need to set the FSLDIR environment variable to point to the FSL installation directory before you can run anything." ; exit 1; fi
# Check for FSLDIR being valid \
if [ ! -f $FSLDIR/etc/fslconf/fsl.sh ]; then echo "You need to set the FSLDIR environment variable to point to the FSL installation directory before you can run anything." ; exit 1; fi

# the next line restarts using wish \
if [ _$FSLWISH = _ ] ; then echo "You need to source an FSL setup file - either fsl.sh or fsl.csh in \$FSLDIR/etc/fslconf !" ; exit 1 ; else exec $FSLWISH "$0" -- "$@" ; fi

set FSLDIR $env(FSLDIR)
set FSLDEVDIR $env(FSLDEVDIR)

set origname [ string tolower [ file tail [ info script ] ] ]

# The entry point might be named "<Tool>" or "<Tool>_gui"
regsub "_gui" $origname "" origname

# Call dev version in $FSLDEVDIR if installed
if { [file exists ${FSLDEVDIR}/tcl/${origname}.tcl] == 1 } {
  source ${FSLDEVDIR}/tcl/${origname}.tcl
}
# Otherwise call normal version in $FSLDIR
else {
  source ${FSLDIR}/tcl/${origname}.tcl
}

exit
