#!/bin/sh

# Set up default variable values if not supplied by the user.

# where the HDFView is installed, e.g. /home/user1/hdfview
HDFJAVA=/usr/local
export HDFJAVA

# where Java is installed (requires jdk1.4.x or above), e.g. /usr/jdk1.4.2/bin
JAVAHOME=/usr/local/openjdk6/bin
export JAVAHOME

###############################################################################
#            DO NOT MODIFY BELOW THIS LINE
###############################################################################

CPATH=/usr/local/share/java/classes"/jhdf.jar:"/usr/local/share/java/classes"/jhdf5.jar:"/usr/local/share/java/classes"/jhdfobj.jar"
CPATH=$CPATH":"/usr/local/share/java/classes"/netcdf.jar:"/usr/local/share/java/classes"/fits.jar:"/usr/local/share/java/classes"/h5srb.jar"
CPATH=$CPATH":"/usr/local/share/java/classes"/jhdf4obj.jar:"/usr/local/share/java/classes"/jhdf5obj.jar:"/usr/local/share/java/classes"/jhdfview.jar"
CPATH=$CPATH":"/usr/local/share/java/classes"/jgraph.jar:"/usr/local/share/java/classes"/ext/*"

TEST=/usr/bin/test
if [ ! -x /usr/bin/test ] 
then
TEST=`which test`
fi

if [ ! -d $JAVAHOME ]; then
    JAVALOC=`which java`
    LASTSLASH=`perl -e "print rindex(\"${JAVALOC}\", '/')"`
    JAVAHOME=`perl -e "print substr(\"${JAVALOC}\", 0, $LASTSLASH)"`
fi

if $TEST -z "$CLASSPATH"; then
	CLASSPATH=""
fi
CLASSPATH=$CPATH":"$CLASSPATH
export CLASSPATH

if $TEST -n "$JAVAHOME" ; then
	PATH=$JAVAHOME":"$PATH
	export PATH
fi


if $TEST -e /bin/uname; then
   os_name=`/bin/uname -s`
elif $TEST -e /usr/bin/uname; then
   os_name=`/usr/bin/uname -s`
else
   os_name=unknown
fi

if $TEST -z "$LD_LIBRARY_PATH" ; then
        LD_LIBRARY_PATH=""
fi

case  $os_name in
    SunOS)
	LD_LIBRARY_PATH=$HDFJAVA/lib/solaris:$HDFJAVA/lib/ext:$LD_LIBRARY_PATH
	;;
    Linux)
        LD_LIBRARY_PATH=/usr/local/share/java/classes"/linux:"/usr/local/share/java/classes"/ext:"$LD_LIBRARY_PATH
	;;
    IRIX*)
	OSREV=`/bin/uname -r`
	LD_LIBRARY_PATH=/usr/local/share/java/classes"/irix-6.5:"/usr/local/share/java/classes"/ext:"$LD_LIBRARY_PATH 
	LD_LIBRARYN32_PATH=/usr/local/share/java/classes"/irix-6.5:"/usr/local/share/java/classes"/ext":$LD_LIBRARY_PATH
	export LD_LIBRARYN32_PATH
	;;
    OSF1)
	LD_LIBRARY_PATH=/usr/local/share/java/classes"/alpha:"/usr/local/share/java/classes"/ext:"$LD_LIBRARY_PATH
	;;
    AIX)
	LD_LIBRARY_PATH=/usr/local/share/java/classes"/aix:"/usr/local/share/java/classes"/ext:"$LD_LIBRARY_PATH
	;;
    Darwin)
	DYLD_LIBRARY_PATH=/usr/local/share/java/classes"/macosx:"/usr/local/share/java/classes"/ext:"$DYLD_LIBRARY_PATH
	export DYLD_LIBRARY_PATH
	LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
	;;
    FreeBSD)
	LD_LIBRARY_PATH=/usr/local/lib":"$LD_LIBRARY_PATH
	;;
    *)
	echo "Unknown Operating System:  HDFView may not work correctly"
        ;;
esac

export LD_LIBRARY_PATH

$JAVAHOME/java  -Djava.library.path=$LD_LIBRARY_PATH ncsa.hdf.view.HDFView -root $HDFJAVA $*
