#!/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

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

############################################################################
# RCS INFORMATION:
#
#       $RCSfile: vmd,v $
#       $Author: johns $        $Locker:  $                $State: Exp $
#       $Revision: 1.66 $      $Date: 2003/05/20 22:35:27 $
#
############################################################################
# DESCRIPTION:
#
# csh script to start up vmd, using an xterm-like window for the console
#
############################################################################

#
# User configurable/overridable default settings.
#

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

# set default display device to be windowed
if ($?VMDDISPLAYDEVICE == "0") then
  setenv VMDDISPLAYDEVICE win
endif

# set serial port device to which a Spaceball 6DOF input device
# is connected.  This allows VMD to use the Spaceball as an additional
# input device.  Remember to check permissions on the serial port device
# before you tell VMD to use it.
# Common names for serial ports on Unix are:
#   Solaris: /dev/ttya    /dev/ttyb    /dev/term/a  /dev/term/b
#     Linux: /dev/ttyS0   /dev/ttyS1
#      IRIX: /dev/ttyd1   /dev/ttyd2   /dev/ttyd3   /dev/ttyd4
#     HP-UX: /dev/tty0p0  /dev/tty1p0 
# setenv VMDSPACEBALLPORT /dev/ttyS1

# set a default window position, where x is 0 at the left side of the screen
# and y is 0 at the bottom of the screen.
if ($?VMDSCRPOS == "0") then
  setenv VMDSCRPOS "596 190"
endif

# set a default window size.
if ($?VMDSCRSIZE == "0") then
  setenv VMDSCRSIZE "669 834"
endif

# set a default screen height
if ($?VMDSCRHEIGHT == "0") then
  setenv VMDSCRHEIGHT 6.0
endif

# set a default screen distance
if ($?VMDSCRDIST == "0") then
  setenv VMDSCRDIST -2.0
endif

# set the default behavior for enable/disable of the VMD title screen
if ($?VMDTITLE == "0") then
  setenv VMDTITLE on
endif

# set the default geometry (size/position) used for the VMD command window
if ($?VMD_WINGEOM == "0") then
  setenv VMD_WINGEOM "-geometry 80x11-0-0"
endif

#
# Don't edit items below unless you know what you are doing.
#

# Define the various script library locations
setenv TCL_LIBRARY "$VMDDIR/scripts/tcl"

if ($?PYTHONPATH == "0") then
  setenv PYTHONPATH "$VMDDIR/scripts/python"
else
  setenv PYTHONPATH "$PYTHONPATH/:$VMDDIR/scripts/python"
endif

# if the location of the babel binary isn't already defined
#  1st see if it is on the path
if ($?VMDBABELBIN == "0") then
  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 == "0") then
  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, and disable
# Spaceball input and X-Windows DISPLAY if no graphics.
# check if VMD is being run as a web helper application, if so, then
# when we spawn the VMD binary, we don't run it as a background process.
set VMDWEBHELPER=0
@ parmcount = 0
foreach i ( $* )
  @ parmcount++
  if ( "$argv[$parmcount]" == "-webhelper") then
    set VMDWEBHELPER=1
  endif

  if ( "$argv[$parmcount]" == "-h" || "$argv[$parmcount]" == "--help" ) then
    if ($?DISPLAY) then
       unsetenv DISPLAY
    endif
  endif

  if ( "$argv[$parmcount]" == "-dispdev") then
    @ parm = $parmcount + 1
    if ( $parm <= $#argv ) then
      if ( "$argv[$parm]" == "none" || "$argv[$parm]" == "text" ) then
        if ($?VMDSPACEBALLPORT) then
          unsetenv VMDSPACEBALLPORT
        endif
        if ($?DISPLAY) then
          unsetenv DISPLAY
        endif
      endif
    endif
  endif
end


# 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=/usr/bin/X11/xterm
  set VMD_WINOPTS="-sb -sl 1000 -e"
  if ("$MACHVER" == "6") then
    set ARCH=IRIX6
  else
    echo "Error: Unknown or unsupported IRIX version $MACHVER"
    exit 1
  endif
breaksw

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

case *AIX*:
  set VERSION=`uname -v`
  set ARCH=AIX${VERSION}
  set VMD_WINTERM=/usr/lpp/X11/bin/aixterm
  set VMD_WINOPTS='-sb -sl 1000 -e'
breaksw

case *Linux*:
  # The standard options
  if (`uname --machine` == "ppc") then
    set ARCH=LINUXPPC
  else if (`uname --machine` == "alpha") then
    set ARCH=LINUXALPHA
  else
    set ARCH=LINUX
  endif
  set VMD_WINTERM=xterm
  set VMD_WINOPTS='-sb -sl 1000 -e'
breaksw

case *SunOS*:
  # The standard options
  if (`uname -p` == "sparc") then
    set ARCH=SOLARIS2
  else
    set ARCH=SOLARISX86
  endif

  set VMD_WINTERM=/usr/openwin/bin/xterm
  set VMD_WINOPTS='-sb -sl 1000 -e'
breaksw

case *OSF*:
  set ARCH=TRU64
  set VMD_WINTERM=xterm
  set VMD_WINOPTS='-sb -sl 1000 -e'
breaksw

case *Rhapsody*:
case *Darwin*:
  if ($?TMPDIR == "0" ) then
    setenv TMPDIR /tmp
  endif
  set ARCH=MACOSX
  set VMD_WINTERM=xterm
  set VMD_WINOPTS='-sb -sl 1000 -e'
  ## Override default window size and position 
  setenv VMDSCRPOS "400 200"
  setenv VMDSCRSIZE "512 512"
breaksw

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

endsw

# Test to see if a 64-bit version of VMD exists
# in the installation directory, and use the 64-bit
# version if it is there.
if ( -e "${VMDDIR}/${vmdbasename}_${ARCH}_64" ) then
  set ARCH=${ARCH}_64
endif

# set VMD executable name based on architecture
set execname="$vmdbasename"_$ARCH

# set the path to a few external programs
# Stride -- used to generate cartoon representations etc.
if ($?STRIDE_BIN == "0") then
  if (-x "$VMDDIR/stride_$ARCH") then
    setenv STRIDE_BIN "$VMDDIR/stride_$ARCH"
  endif
endif

# Surf -- used to generate molecular surfaces
if ($?SURF_BIN == "0") then
  if (-x "$VMDDIR/surf_$ARCH") then
    setenv SURF_BIN "$VMDDIR/surf_$ARCH"
  endif
endif

# Tachyon -- used to generate ray traced graphics
if ($?TACHYON_BIN == "0") then
  if (-x "$VMDDIR/tachyon_$ARCH") then
    setenv TACHYON_BIN "$VMDDIR/tachyon_$ARCH"
  endif
endif

# check for Mac bundled version, else assume X-Windows 
if ($?VMDMACBUNDLE == "0") then
  # if DISPLAY is set, spawn off a terminal, else use current terminal
  if ($?DISPLAY) then
    if ("$VMDWEBHELPER" == "1") then
      exec $VMD_WINTERM -T "vmd console" $VMD_WINGEOM $VMD_WINOPTS \
		"$VMDDIR/$execname" $*
    else
      exec $VMD_WINTERM -T "vmd console" $VMD_WINGEOM $VMD_WINOPTS \
		"$VMDDIR/$execname" $* &
    endif
  else
      "$VMDDIR/$execname" $*
  endif
else 
  # Special startup code for the MacOS X bundle version of VMD
  "$VMDMACEXEC" $*
endif


