#                              sassetup
# SANS setup file at ILL for SGI-IRIX, Linux, Macintosh OS-X
#
# tcsh script (uses tcsh shell)
#
# invoked as 
#  % tcsh
#  % source /home/cs/sans/sassetup
#
# derived from sassetup_ILL
#
# this version November 2015 (R. Ghosh  reghosh @ gmail.com)
# 
# requires modifications to /etc/cshrc reflect location of host
# instrument specific parts are placed in
# .login for standard users, or 
# e.g. /home/vis/d22/.login.group for visitor_d22 zones etc.
# (this is invoked by getname procedure in F. Pinet's login routine)
# 
# started 29-Oct-1995  R.E. Ghosh
#------------------------------------------
#========================================================================
# Modified for Linux from Mac OSX 10.5 2/05/2012  Ron Ghosh  Version 2.0
#
# to start from Terminal ( Applications/Utilities/Terminal )
# > tcsh            (change to tcshell)
# > cd current_work_directory
# > source ~/sans2012L/Linux12/sassetup
#       (Assuming files are unzipped in the HOME directory                 )
#       (this should be an absolute path, not relative to the workdirectory)
#========================================================================
#
# The directory of programs is found from the source command line
# (eventually allowing simultaneous storage of versions for different systems)
#
# In this version of sassetup (Macintosh 1.4, 10.5, 10.6 specific) this is 
# set in the next line, and this may have to be edited if the distribution is not
# unzipped in the HOME directory 
#
# The following tries to ensure absolute path is given for SAS_DIR
#
setenv SAS_DIR {!!:1:h}
setenv WD $PWD
cd $SAS_DIR
setenv SAS_DIR $PWD
cd $WD
echo "  SAS_DIR has been set to $SAS_DIR "
echo "  Current work directory is $WD "

#
#
#
#
#  Other useful definitions should follow!
# PLOTTING
setenv PGPLOT_DIR $SAS_DIR
#
#
# wish is installed as standard on most systems  
#
#========================================================================
# This present file contains environment variables primarily, rather than
# executables which are all in SAS_DIR
#
#
echo
echo "in sassetup"
stty intr ^C
if ( $?NEW_SAS_SETUP == 0 ) then
# remaining steps 1,2,3,4,5 will be skipped
  setenv SAS_EXTRA_G g2x
  setenv SAS_DECOMPRESS zcat
    alias help "/usr/bin/firefox http://www.ill.eu/instruments-support/computing-for-science/cs-software/all-software/sans/"
echo " "
echo " "
echo " A program distribution may be found at ftp://ftp.ill.fr/pub/cs/sans"
echo " "
echo " "
  setenv MY_INST d22
    setenv SAS_INSTRUMENT $MY_INST
    setenv SAS_DATA_PATH $WD/
  endif
# to get non-US date formats on some systems
  unsetenv LANG
#echo "#1"
# library path
setenv LD_LIBRARY_PATH $SAS_DIR
# for shareable library
  if (! $?SAS_DEF_PRINTER ) then
    setenv SAS_DEF_PRINTER lp
    echo "Not standard SAS_DEF_PRINTER"
  endif
  if (! $?SAS_DEF_PLOTTER ) then
    setenv SAS_DEF_PLOTTER lp
    echo "Not standard SAS_DEF_PLOTTER"
  endif
#echo "#1b"
  echo $SAS_DIR" is being added to path"
  set path = ( . $SAS_DIR $path )
  rehash
#echo "#2"
  setenv SAS_CHECK limited
# for graphics:
  setenv PGPLOT_XW_WIDTH 0.3
  setenv PGPLOT_ILL_DEV_1 /xserv
  setenv PGPLOT_ILL_DEV_2 /vcps
  setenv PGPLOT_ILL_DEV_3 /null
  setenv PGPLOT_ILL_PPAGE 2
  setenv PGPLOT_ILL_PGRUNFIGDISP figdisp
  setenv PGPLOT_DIR $SAS_DIR
#
  alias newest "more $SAS_DIR/SANSLOG"
  alias xplots "wish $SAS_DIR/xplots.bat"
  alias xpolly "wish $SAS_DIR/xpolly.bat"
  alias xmill "wish $SAS_DIR/xmill.bat"
  alias xmplot "wish $SAS_DIR/xmplot.bat"
  alias xreg  "wish $SAS_DIR/xreg.bat"
  alias clickfit "wish $SAS_DIR/clickfit.bat"
  alias clickfit_m "wish $SAS_DIR/clickfit_m.bat"
  
#
# Local printers are set up initially using a pseudo- pri command
# which is normally used for printing here. myprinter can be used to modify
# choice manually
#
# first check if enviroment variable DISPLAY is set, and if yes, run a 
# GUI version, else run a text version.
#echo "#4"
  if ($?DISPLAY ) then
        echo "setting up X environment"
	alias myprinter "$SAS_DIR/expectk $SAS_DIR/sasprinter.tk " 
	alias pri "$SAS_DIR/expectk $SAS_DIR/sasprinter.tk ; source $HOME/.login.sasprinter;unalias pri;alias pri $SAS_DIR/prip;$SAS_DIR/prip "
  else
# rather unlikely nowadays...
	alias myprinter "$SAS_DIR/sasprinter.tcl;source $HOME/.login.sasprinter" 
	alias pri "$SAS_DIR/sasprinter.tcl;source $HOME/.login.sasprinter ; unalias pri; alias pri $SAS_DIR/prip; $SAS_DIR/prip"
  endif
#echo "#5"
# Similarly plotters - typically colour printers printing direct to PostScript
# Local plotters are set up initially using a pseudo- plo command
# which is normally used for printing here. myplotter can be used to modify
# choice manually
  alias myplotter-1 "$SAS_DIR/expectk $SAS_DIR/sasplotter.tk ; source $HOME/.login.sasplotter" 
  alias myplotter "wish $SAS_DIR/sasplotter.tk ; source $HOME/.login.sasplotter" 
  alias plo-1 "$SAS_DIR/expectk $SAS_DIR/sasplotter.tk ; source $HOME/.login.sasplotter ;unalias plo-1; alias plo-1 $SAS_DIR/plop;$SAS_DIR/plop"
  alias plo "wish $SAS_DIR/sasplotter.tk ; source $HOME/.login.sasplotter ;unalias plo; alias plo $SAS_DIR/plop;$SAS_DIR/plop"
  alias xmplot-1 "$SAS_DIR/expectk $SAS_DIR/sasplotter.tk ; source $HOME/.login.sasplotter ; unalias xmplot-1; alias xmplot-1 $SAS_DIR/xmplott; $SAS_DIR/xmplott" 
  alias xmplot "wish $SAS_DIR/sasplotter.tk ; source $HOME/.login.sasplotter ; unalias xmplot; alias xmplot wish $SAS_DIR/xmplot.bat;wish $SAS_DIR/xmplot.bat" 
  setenv NEW_SAS_SETUP completed
  echo "SANSANSANSANSANSANSANSANSANSANSANSANSANSANSANSANSANSANSANSANS"
  echo "                       ILL - SANS"
  echo "Currently SAS_INSTRUMENT is set to $SAS_INSTRUMENT"
  echo "Current SAS_DATA_PATH is $SAS_DATA_PATH "
  echo "For help give the command help"
  echo "For information on recent changes give the command newest"
  echo " WWW information  "
  echo " www.ill.eu/computing-for-science/cs-software/all-software/sans"
  echo " "
  echo "For most recent Mac/Linux/PC-Windows programs (containing Prop updates)"
  echo " see ftp://ftp.ill.fr/pub/cs/sans "
  echo " "
  echo "XML output of regrouped data is enabled; SAS_EXTRA_G is $SAS_EXTRA_G "
  echo " "
  echo "SANSANSANSANSANSANSANSANSANSANSANSANSANSANSANSANSANSANSANSANS"
else
  echo NEW_SAS_SETUP is $NEW_SAS_SETUP "(nothing has been done)"
endif
echo "end of $SAS_DIR/sassetup"
echo
