#! /bin/csh -f

# $Id$

# DO NOT EDIT THIS FILE DIRECTLY!  EDIT ONLY THE CORRESPONDING .tpl FILE.

# Shell script to start Mathematica and initialize Heisenberg; assumes
#   that the graphics daemon is already running on the graphics host.

# usage: HeisMath [-port <n>] [graphicshost]

# This script:
# 	(1) starts Mathematica on the current host
# 	(2) reads in Heisenberg.m
# 	(3) executes gConnect[]

if ($#argv > 0) then
  if ( "$1" == "-port" ) then
    shift
    if ($#argv <= 0) goto usage
    setenv ELBOWPORT $1
    shift
  endif
endif

if ($#argv > 0) then
  set graphicshost = $1
  shift
else
  if $?ELBOWSERVER then
    set graphicshost = $ELBOWSERVER
  else
    echo -n "Enter name of Heisenberg graphics host: "
    set graphicshost = $<
    if ( "$graphicshost" == "" ) then
      echo "Null host.  HeisMath aborted."
      exit -1
    endif
  endif
endif

if ($argv > 0) then
  goto usage
endif

set heisdir = /u/mbp/Heisenberg/Mathematica/Packages
set mathdir = /u/src/mathematica/version1.2/iris_4d120/
set machdir = Bin.Iris

if ( "$machdir" == "Bin.sun3" ) then
	set machdir = "$machdir.`$mathdir/Install/foption`"
endif
set path = ( $path $mathdir/$machdir/Display )

setenv ELBOWSERVER $graphicshost

exec $mathdir/$machdir/mathexe				\
	-pwpath '{"'$mathdir/Install'"}'		\
	-run '$Path = Join[				\
		$Path,					\
		{					\
			"~",				\
			"'$mathdir/Init'",		\
			"'$mathdir/Packages'",		\
			"'$heisdir'"			\
		}					\
	]' 						\
	-run '<<Heisenberg.m' 				\
	-run 'gConnect[]'				\
	"$*"

echo 'HeisMath: exec failed.'
exit -1

usage:
	echo 'usage: HeisMath [-port <n>] [graphicshost]'
	exit -1
