#!/bin/csh -X
#-----------------------------------------------------------------------------
#
# Name: OWL login AUTO TEMPLATE
#
# This file is a template of owl_login.csh, and is used by the automatic
# configuration generator.  You can add any additional definitions to the
# file created by the generator, but be aware that these will be lost if
# if you re-run the generator.
#
# Any names below prefixed by "_empty_" should get replaced by the
# configuration generator.
#
# Your own version of this file should be placed in the directory
# defined below as opus_definitions_dir.
#
# Some names remain OPUS-centric to avoid making too many changes in too
# many external places.
#
# 07/13/12 xxxxx    MSwam     first version
# 04/16/13 73930    MSwam     get OWL_LOGS setting from owlrc file
# 05/09/13 73930    MSwam     add DPQ_SERVER, DPQ_DB
# 06/05/13 74104    MSwam     add DADS dir to LD_LIBRARY_PATH to stop 
#                               instalj/insrspj complaints
#-----------------------------------------------------------------------------
# this TCSH variable gives us the desired error status return behavior in
# csh scripts under RHEL6 (see OPUS PR 70213 for details)
set anyerror

# the pipeline code BASE directory (combined with overrides to supply 
#   pipeline code for workflows).  This is the BUILD that is being run
#   (NOT the OWL code, but the pipelines, e.g. HST build).
#
setenv PIPELINE_BASE _empty_SCIENCE_PATH
#
# CONDOR/OWL add-ons (some here, some after SSB config, so OWL takes precedence)
setenv OWL_ROOT  _empty_OWL_ROOT
setenv DRMAA_LIBRARY_PATH /usr/lib64/condor/libdrmaa.so
#
# a handy short-cut to the value in the OWL config
setenv OWL_LOGS `/bin/grep work_root ${OWL_ROOT}/etc/owl/owlrc.local | awk '{print $3}'`
#
# keep this one around for a while, it's handy
setenv OPUS_HOME_DIR _empty_HOME_ROOT
#
# common external items needed by our pipelines are found here
#  (e.g. isql, cfitsio, stpydb, etc.)
set COMMON_EXTERNALS = _empty_COMMON_EXTERNALS
#
# pre-pend PATH so we avoid picking up system-level unwanted isql tool
#   (also used to pick up other local tools like bcp)
#
setenv PATH ${COMMON_EXTERNALS}:${PATH}
#
# root override area
#   (the following dir must contain subdir bin/linux/ so it 
#    will be added to $path in a foreach block below
set OVERRIDE_BASE = _empty_OVERRIDE_ROOT
setenv SOGS_DISK "${OVERRIDE_BASE} ${PIPELINE_BASE}"
#
# definitions override area (combined with pipeline code definitions area
#
set OVERRIDE_DEFS = "${OVERRIDE_BASE}/defs/"
set ODD = _empty_DEFS_ROOT
setenv OPUS_DEFINITIONS_DIR "${OVERRIDE_DEFS} ${ODD} SOGS_DISK:/definitions/unix/ SOGS_DISK:/definitions/"
#
# for some pipeline LOG files (NOT those written by Condor/OWL, but ones that
#   traditionally would go to OPUS_HOME_DIR)
setenv PIPELINE_LOG_DIR _empty_HOME_ROOT
#
# where OWL picks up pipeline workflow templates
#   (currently can NOT be overriden)
setenv DAG_ROOT_DIR ${PIPELINE_BASE}/owl_templates/
#
# root of science pipeline processing dirs
setenv DATA_ROOT_DIR _empty_DATA_ROOT_DIR #/hstdev/info/mswam/paths/opus/11/
#
# 3rd-party packages
#
setenv CFITSIO_BASE _empty_CFITSIO_BASEDIR
setenv CFITSIO_LIB ${CFITSIO_BASE}/lib/
#
# define platform setting for OWL code tree
setenv OUR_PLATFORM linux
#
# add SOGS_DISK entries to end of PATH if 
#  -not already there AND
#  -(a bin/OUR_PLATFORM directory exists OR 
#    a bin/java subdirectory exists)
#
foreach i ($SOGS_DISK)
  foreach j ( bin bin/$OUR_PLATFORM  bin/java dbms/tools )
    set testdir = ${i}/${j}
    if (-d ${testdir}) then
      # make sure its not already in the path
      set atest = `echo $PATH | grep ${testdir}`
      if ($status == 1) then
        setenv PATH ${PATH}:${testdir}
      endif
    endif
  end
end
#
# run-time library additions
setenv PIPELINE_LIB ${PIPELINE_BASE}/lib/${OUR_PLATFORM}
#
# add to existing LD_LIBRARY_PATH
setenv LD_LIBRARY_PATH ${PIPELINE_LIB}:${LD_LIBRARY_PATH}:${CFITSIO_LIB}:_empty_DADS_BASEDIR
#
# database definitions
#
setenv DB_TYPE     _empty_DB_TYPE
setenv DSQUERY     _empty_DSQUERY
setenv OPUS_SERVER _empty_OPUS_SERVER
setenv OPUS_DB     _empty_OPUS_DB
setenv SPSS_SERVER _empty_SPSS_SERVER
setenv SPSS_DB     _empty_SPSS_DB
setenv ASSIST_SERVER _empty_ASSIST_SERVER
setenv ASSIST_DB   _empty_ASSIST_DB
setenv PROP_SERVER _empty_PROP_SERVER
setenv PROP_DB     _empty_PROP_DB
setenv ARCH_SERVER _empty_ARCH_SERVER
setenv ARCH_DB     _empty_ARCH_DB
setenv CDBS_SERVER _empty_CDBS_SERVER
setenv CDBS_DB     _empty_CDBS_DB
setenv REFFILE_SERVER _empty_REFFILE_SERVER
setenv REFFILE_DB     _empty_REFFILE_DB
setenv KW_SERVER   _empty_KW_SERVER
setenv KW_DB       _empty_KW_DB
setenv REF_SERVER  _empty_REF_SERVER
setenv REF_DB      _empty_REF_DB
setenv DPQ_SERVER  _empty_DPQ_SERVER
setenv DPQ_DB      _empty_DPQ_DB

#
#---------------------------------
# BEGIN SSB-related set-up
#---------------------------------
# translate UNIX platform name into name needed for SSB set-up scripts
#
set platform = `/bin/uname -p`
setenv IRAFARCH $platform
if (${IRAFARCH} == "x86_64") then
 # adjustment for Linux
 setenv IRAFARCH redhat
endif
#
# set the location of the SSG (IRAF,STSDAS, PYRAF) software and run the
#   set-up script
#
setenv whichiraf     _empty_SSB_VERSION
setenv whichiraftree _empty_IRAF_BASEDIR
setenv ssb_stuff     ${whichiraftree}/${whichiraf}
#CURRENTLY LEAVE THIS OUT as it brings in a conflicting Jinga2 version
#Will try to activate this only in workflow tasks that need the SSB Python
#environment.
#source ${ssb_stuff}/config.csh
#
setenv SSGROOT    ${whichiraftree}/${whichiraf}
setenv STSDASDISK ${SSGROOT}/stsdas/
setenv TABLESDISK ${SSGROOT}/tables/
setenv STLOCAL    ${SSGROOT}/stlocal/
#---------------------------------
# END SSB-related set-up
#---------------------------------
#
# append to PYTHONPATH for finding override and OWL pipeline scripts
#
set OVERRIDE_PY = "${OVERRIDE_BASE}/bin/"
set PIPELINE_PY = "${PIPELINE_BASE}/bin/${OUR_PLATFORM}"
set STPYDB_LOCATION = _empty_STPYDB_BASEDIR
setenv PYTHONPATH ${OVERRIDE_PY}:${PIPELINE_PY}:${STPYDB_LOCATION}:${PYTHONPATH}
#
# TRIED to put OWL specifically in front of later SSB add-on, but the SSB 
# version of Jinja2 is still picked-up
setenv PYTHONPATH ${OVERRIDE_PY}:${PIPELINE_PY}:${STPYDB_LOCATION}:${OWL_ROOT}/lib/python2.7/site-packages/:${PYTHONPATH}
#
# ADD ON until SSB puts this in their set-up config
# (only needed for NICMOS pipeline, leave out for now)
setenv PYTHONPATH ${PYTHONPATH}:${SSGROOT}/stsci_python/nictools
#
#<<<<<<<<<<<<<<<<<<<<<<<
# WAS REQUIRED in order to pick-up SSB python add-ons, like numpy
# BUT HAD TO REMOVE FOR NOW, as it picks up a Jinja2 that is 
# incompatible with OWL
#setenv PYTHONPATH ${PYTHONPATH}:/usr/stsci/${python}/lib/python2.7/site-packages/
#<<<<<<<<<<<<<<<<<<<<<<<
#
# more OWL items (put FIRST so they take precedence)
setenv PATH ${OWL_ROOT}/bin/:${PATH}
setenv LD_LIBRARY_PATH ${OWL_ROOT}/lib/:${LD_LIBRARY_PATH}
#
# Build OPUS_CLASSPATH for Java tasks.  Now uses -classpath wildcarding
#   to workaround a variable length problem.
#
setenv OPUS_CLASSPATH ""
foreach sd ($SOGS_DISK)
  set junk = `/usr/bin/test -d ${sd}/bin/java && find ${sd}/bin/java -name '[A-GI-Za-z]*.jar'`
  set last_jf_dir = nuttin
  foreach jf ($junk)
     # trim off the filename, leaving just the dir name
     set jf_dir = $jf:h/
     if ($jf_dir != $last_jf_dir) then
        setenv OPUS_CLASSPATH "${OPUS_CLASSPATH}:${jf_dir}JAVAWILDCARD"
     endif
     set last_jf_dir = $jf_dir
  end
end
#
# Add DADS libraries to classpath for INGEST interface
setenv DADS_CLASSPATH _empty_DADS_BASEDIR  #/opt/dads/lib/JAVAWILDCARD
#
# set the reference file paths
setenv REFROOT _empty_REF_BASEDIR  #/grp/hst/cdbs/
#
setenv SAADARK_CACHE _empty_SAADARK_CACHE #/hstdev/store/ref/saadark
#
# ACS reference files
setenv jref        ${REFROOT}/acs/
setenv cracscomp   ${REFROOT}/thu/
# WF2 reference files
setenv mtab        ${REFROOT}/mul/
# TTAB needs its own area because central store synphot is organized differently
setenv ttab        ${REFROOT}/thu/  #/hstdev/store/ref/thu
setenv crwfpc2comp ${REFROOT}/thu/
setenv crotacomp   ${REFROOT}/thu/
setenv uref        ${REFROOT}/wf2/
# STIS reference files
setenv oref        ${REFROOT}/stis/
# NIC  reference files
setenv nref        ${REFROOT}/nic/
# WFC3 reference files
setenv iref        ${REFROOT}/wfc3/
setenv crwfc3comp  ${REFROOT}/thu/
# COS reference files
setenv lref        ${REFROOT}/cos/
setenv crcoscomp   ${REFROOT}/thu/
#
setenv crnonhstcomp ${REFROOT}/thu/
#
#
# some additional set-up values
set fxlogin = `osfile_stretch_file SOGS_DISK:/com/fxlogin.csh`
source $fxlogin
#
# Set unlimited process resources
unlimit
#---------------------------------------------------------------------
# UNCOMMENT FOR DEBUGGING:
#
## Possible report levels (uncomment as needed).  Default is MSG_INFO.
## Available levels: MSG_DIAG MSG_INFO MSG_WARN MSG_ERROR MSG_FATAL 
##                   MSG_ALL  MSG_NONE
##
# setenv MSG_REPORT_LEVEL MSG_ALL
# setenv MSG_TRL_REPORT_LEVEL MSG_ALL
#
## DEBUGGING for Python tasks using STPYDB database interface
# setenv STPYDB_DEBUG on
# setenv STPYDB_DEBUG_FILE file_for_debug_msgs
##
## Possible database report levels (uncomment as needed).  Default is STDB_ERR.
## (only see output when there is an error).  See OSTDB2.0 manual for info.
## If STDB_REPORT_FILE is not defined, messages go into process log file (good).
## Known available levels: STDB_INFO   STDB_STAT   STDB_WARN   STDB_ERR
##
# setenv STDB_REPORT_LEVEL STDB_INFO
# setenv STDB_REPORT_FILE "<eg. $OPUS_HOME_DIR/stdb_info.out>"
#
## Perl DBI database debugging messages:
## (can use levels 1-5, 1=least extreme, 5=most extreme, and an optional
##  filename can be provided as well, otherwise STDERR is used)
#setenv DBI_TRACE 1
#setenv DBI_TRACE 2=perlDBI.msgs
#
# setenv NETCOPY_DEBUG on       ## Be careful: writes passwords to a file
#====================== OWL login completed.  ===============================
