#!/bin/sh
#
# This script is a part of FreeUSP - the UNIX Seismic Processing system.
#

# Get architecture information
#
. usp-osarch
#
# The IRIX64 architecture uses the IRIX32 module
#
# bypass this - we get the 32 bit anyway - forcing the issue causes
# execution of other 32 bit binaries - ie. usparg - 2/19/02 - joe
#
# if ( test "${OSARCH_OS}" = "IRIX64" ) then
#  OSARCH_OS=IRIX32
# fi
#
# Get USP division/group information
#
. usp-set-env
#
# override the name of the binary; our actual process is "ikp"
#
APP="ikp"

XUI_PATH=${APPDIR}/etc/${DIST_PRODUCT}/xui_pattern/

if ( test "{OSARCH_OS}" = "SunOS" -a "${OSARCH_MAJOR_OS_REV}" = "4" ) then
 XKEYSYMDB=${APPDIR}/etc/X11R5/XKeysymDB
 XNLSPATH=${APPDIR}/etc/X11R5/nls
else
 XKEYSYMDB=${APPDIR}/etc/X11R6/XKeysymDB
 XLOCALEDIR=${APPDIR}/etc/X11R6/locale
fi

XFILESEARCHPATH=${XFILESEARCHPATH:+"${APPDIR}/etc/${DIST_PRODUCT}/app-defaults/%N:$XFILESEARCHPATH"}
XFILESEARCHPATH=${XFILESEARCHPATH:="${APPDIR}/etc/${DIST_PRODUCT}/app-defaults/%N:$XFILESEARCHPATH"}

# if ( test "`type setplot.sh | 2>&1 awk '{print $2 $3}' | sed 's/[.]$//'`" \
#    != "not found" ) then
# 	( . setplot.sh ) || echo "setplot.sh does not exist"
# 	echo "pltr setup done"
# else
# 	echo "Warning: pltr setup file does not exist"
# fi

BATCH=`usparg -B "" $*`
LOCAL=`usparg -L "" $*`
BLOCKSIZE=`usparg -b "8192" $*`

IKP_SOCKETSIZE=${BLOCKSIZE}

export PATH XUI_PATH XFILESEARCHPATH XKEYSYMDB XNLSPATH IKP_SOCKETSIZE XLOCALEDIR

if ( test "$BATCH" = "" ) then
	NETFIL=`usparg -N "" $*`
	if ( test "$NETFIL" = "") then
	  NETFIL=${APPDIR}/etc/${DIST_PRODUCT}/xui_pattern/utilnet.net
	fi
	echo " "
	echo "ikp in interactive mode: reading start-up net "$NETFIL
else
	echo " "
	echo "ikp in batch mode: will try to read batch net "$BATCH
fi

if ( test "$BATCH" = "" ) then
	exec ${USP_MONITOR_CMD} ${APP} -N $NETFIL -l ${XUI_PATH}/table.sort ${1:+"$@"}

else
	echo " "
	echo "ikp in batch mode: reading batch net "$BATCH
	exec ${USP_MONITOR_CMD} ${APP} -B -N $BATCH -l ${XUI_PATH}/table.sort ${1:+"$@"}
fi
