#!/bin/csh -f
## In case the installation didn't add these (which means you didn't
# do the 'configure', here's the default settings:
#set defaultvmddir=/usr/local/lib/vmd
#set vmdbasename=vmd
#set consumer=namd_consumer

############################################################################
#cr                                                                       
#cr            (C) Copyright 1995 The Board of Trustees of the            
#cr                        University of Illinois                         
#cr                         All Rights Reserved                           
#cr                                                                       
############################################################################

############################################################################
# RCS INFORMATION:
#
#       $RCSfile: vmd,v $
#       $Author: dalke $        $Locker:  $                $State: Exp $
#       $Revision: 1.14 $      $Date: 1996/03/25 20:21:49 $
#
############################################################################
# DESCRIPTION:
#
# csh script to start up vmd, using an xterm-like window for the console
#
############################################################################

# find where the vmd executable is located
if ( $?VMDDIR) then
else
  setenv VMDDIR $defaultvmddir
endif

# Define the various script library locations
setenv TCL_LIBRARY $VMDDIR/scripts/tcl
setenv TCLX_LIBRARY $VMDDIR/scripts/tclX
setenv DP_LIBRARY $VMDDIR/scripts/dp


# find where .tracker file is located
if ( $?TRACKERDIR) then
else
  setenv TRACKERDIR $VMDDIR
endif

# if the location of the babel binary isn't already defined
#  1st see if it is on the path
if ($?VMDBABELBIN) then
else
  foreach i ($path)
    if (-x $i/babel) then
        setenv VMDBABELBIN $i/babel
        break
    endif
  end
endif

# if not, and if the BABEL_DIR is set, see if the binary is
# in that directory
if ($?VMDBABELBIN) then
else
  if ($?BABEL_DIR) then
    if (-x $BABEL_DIR/babel) then
      setenv VMDBABELBIN $BABEL_DIR/babel
    endif
  endif
endif

#  otherwise, outta luck

# check if we're requesting to run without any graphics
if ( "`echo $* | grep -i 'dispdev '`" != "" && \
     ( "`echo $* | grep -i ' text'`" != "" || \
       "`echo $* | grep -i ' none'`" != "" ) ) then
  if ($?DISPLAY) then
    unsetenv DISPLAY
  endif
endif


# determine type of machine, and run appropriate executable
set MACHARCH=`uname -s`
switch ($MACHARCH)
case *IRIX*:
  set MACHVER=`uname -r | cut -f1 -d.`
  set VMD_WINTERM=winterm
  set VMD_WINOPTS="-fn Screen11 -e"
  if ( "$MACHVER" == "4" ) then
    set ARCH=IRIX4
  else if ("$MACHVER" == "5" || "$MACHVER" == "6" ) then
    set ARCH=IRIX5
  else
    echo "Error: Unknown IRIX version $MACHVER"
    exit 1
  endif
breaksw

case *HP-UX*:
  set MACHVER=`uname -r | cut -f2 -d.`
  set VMD_WINTERM=xterm
  set VMD_WINOPTS='-e'
  if ( "$MACHVER" == "09" ) then
    set ARCH=HPUX9
  else 
    echo "Error:  Unknown HP-UX version $MACHVER"
    exit 1
  endif
breaksw

case *AIX*:
  # don't know enough about IBMs to specify the version
  set ARCH=AIX3
  set VMD_WINTERM=aixterm
  set VMD_WINOPTS='-e'
breaksw

case *:
  echo "Unsupported architechture.  Must be IRIX, HP-UX, or AIX."
breaksw

endsw

# set the path to a few external programs
set execname="$vmdbasename"_$ARCH
if ($?SURF_BIN) then
else
  if (-x $VMDDIR/surf_$ARCH) then
    setenv SURF_BIN $VMDDIR/surf_$ARCH
  endif
endif

# find where MDCOMM consumer program is located
if ($?MDC_CONSUMER) then
else
  setenv MDC_CONSUMER $VMDDIR/mdcomm/bin_$ARCH/$consumer
endif

# if DISPLAY is set, spawn off a terminal, else just use 
# the current terminal
if($?DISPLAY) then
  exec $VMD_WINTERM -T "vmd console" -geometry 90x11+596-0 $VMD_WINOPTS \
	$VMDDIR/$execname $*
else
  $VMDDIR/$execname $*
endif
