#!/bin/tcsh -f
# UIRAF.CSH -- execute an IRAF task stand-alone
#
set noglob

# initialize SAORD variables
if ( $?SAORD_ROOT == 0 ) then
  setenv SAORD_ROOT /scisoft/saord
endif
if ( -e ${SAORD_ROOT}/xpa1 ) then
  setenv XPA_VERSION 1
else
  setenv XPA_VERSION 2
endif
if ( $?SAORD_BIN == 0 ) then
  setenv SAORD_BIN ${SAORD_ROOT}/bin.`${SAORD_ROOT}/getarch`
endif
if ( $?SAORD_TMPDIR == 0 ) then
  setenv SAORD_TMPDIR /tmp
endif
setenv SAORD_VERSION "`cat ${SAORD_ROOT}/VERSION`"
# end of SAORD initialization

set UIRAFVARS=./clvars.csh
if ( ! -e ${UIRAFVARS} ) then
  set UIRAFVARS=/tmp/clvars.csh
  if ( ! -e ${UIRAFVARS} ) then
    ${SAORD_BIN}/mkclvars > ${UIRAFVARS}
    chmod 666 ${UIRAFVARS}
  endif
endif
if ( -e ${UIRAFVARS} ) then
  source ${UIRAFVARS}
endif

set SW=""
set EXE=$1; shift
if ( "$1" == "-b" ) then
  set SW="-b"; shift
endif
set CMD=$1; shift

set EXEPATH=`${SAORD_BIN}/access $EXE`
if ( "${EXEPATH}" != "" ) then
  eval ${EXEPATH} ${SW} ${CMD} `${SAORD_BIN}/pline ${CMD} $*`
else
  set EXEPATH=`${SAORD_BIN}/access ${SAORD_BIN}/$EXE`
  if ( "${EXEPATH}" != "" ) then
    eval ${EXEPATH} ${SW} ${CMD} `${SAORD_BIN}/pline ${CMD} $*`
  else
    echo "ERROR: can't locate the IRAF ${EXE} analysis program."
  endif
endif
