#!/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
#     08-Aug-2012, aandrews
#          Added the macros EVGLOCA=SYS6 and OLDTIME=1 for the backup
#          shell script button. Also added EDMTIMINGBACKUP and EDMDATAFILES
#          to make the script look at the older Aug 8 edm displays. 
#--------------------------------------------------------------
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 EDMTIMINGBACKUP=/afs/slac/g/lcls/tools/edm/TimingUsabilityDisplay/AUG8_xta_Timing_usability
export EDMDATAFILES=.:..:${EDMTIMINGBACKUP}/AUG8_xta:${EDMTIMINGBACKUP}/AUG8_install:${EDMTIMINGBACKUP}/AUG8_event:$EDMUSERS:$EDM/xta:$EDM/mgnt:$EDM/install:$EDM/event:$EDM/vac:${EDM}/pps:${EDM}/bcs:${EDM}/mps:${EDM}/prof:${EDM}/mc:${EDM}/watr:${EDM}/temp:${EDM}/alh:${EDM}/toroid:${EDM}/misc:${EDM}/fbck:${EDM}/cud:${EDM}/cf:${EDM}/knob:${EDM}/autosave:${EDM}/laser:${EDM}/bpms:${EDM}/ws:${EDM}/exp
export ALHCONFIGFILES=/afs/slac/g/acctest/tools/alh/config-xta
export ACCELERATOR=XTA

#echo EDMDATAFILES=$EDMDATAFILES

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

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

exit 0
