#!/bin/bash
#==============================================================
#  Name:  xtahome
#
#  Rem:   This script launches XTA EPICS Home Screen.
# 
#  Usage: lclshome
#
#  Auth:  22-Nov-2011, Terri Lahey (lahey)
#  Rev:   
# ------------------------------------------------------------
#     16-Feb-2012, lahey
#         Change bash setup
#     12-Mar-2012, drogind
#          add $EDM/install to EDMDATAFILES for autogen'ed 
#          event trigger screens
#     02-May-2012, jingchen
#          removed EDMDATAFILES to use $EDMSETUP/setup_acctest.sh 
#--------------------------------------------------------------
CMD="edm"
ACCLIST="tfprod acctf"

if [ `uname -s` != "Linux" ] ; then
    echo "Please run $0 on a public Linux machine"
    exit 1
fi

if [ -z "${EDM}" ] ; then
    . /afs/slac/g/acctest/epics/setup/epicsReset_acctest.bash
fi

. /afs/slac/g/acctest/tools/matlab/setup/matlabSetup_acctest.bash

cmdpath=`which ${CMD}`
if [ ! -x "${cmdpath}" ] ; then
    echo "ERROR: cannot find ${CMD}"
    exit 1
fi

if [ ! -f ${EDM}/xta/xta_main.edl ] ; then
    echo "ERROR: cannot find xta_main.edl"
    exit 1
fi 

USER=`whoami` 
INLIST=`echo ${ACCLIST} | grep ${USER}`
mode="-x"
if [ -n "${INLIST}" ]; then  
    mode="-x -noedit"
fi

#export EDMFILTERS=$TOOLS/edm/config/homeFilter
export EDMFILTERS=/afs/slac/g/acctest/tools/edm/config/homeFilter_xta

export ALHCONFIGFILES=/afs/slac/g/acctest/tools/alh/config-xta
export ACCELERATOR=XTA

#echo EDMDATAFILES=$EDMDATAFILES

${cmdpath} -eolc ${mode} -m "EVGLOCA=SYS6" xta_main

if [ $? -ne 0 ]; then
    echo "ERROR: $0 failed" 
    exit 1
fi

exit 0
