#!/bin/bash
#==============================================================
#  Name:  astahome
#
#  Rem:   This script launches ASTA EPICS Home Screen.
# 
#  Usage: astahome
#
#  Auth:  05-DED-2011, Terri Lahey (lahey)
#    
# ------------------------------------------------------------
#  Rev:   07-Dec-2011, Terri Lahey (lahey):
#                      added magnet and profile monitors to EDMDATAFILES
#                change directory for ALH configuration files to */config-asta
#     02-May-2012, jingchen
#          removed EDMDATAFILES to use $EDMSETUP/setup_acctest.sh
#          cleaned up ACCLIST 
#     09-Oct-2013, jingchen
#          added lcls-prod01:5068 to EPICS_CA_ADDR_LIST to display
#          lcls timing for ASTA. 
#--------------------------------------------------------------
CMD="edm"
# MODIFY THIS LIST!!
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
export EDMDATAFILES=/afs/slac/g/acctest/tools/edm/display/asta:$EDMDATAFILES

. /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}/asta/asta_main.edl ] ; then
    echo "ERROR: cannot find asta_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_asta

export ALHCONFIGFILES=/afs/slac/g/acctest/tools/alh/config-asta
export ACCELERATOR=ASTA

#echo EDMDATAFILES=$EDMDATAFILES 

#CATER 133529, ASTA has its own timing system. There is no longer need to have a tunnel to LCLS' PVs. 
#So, the following line is commented it out. (carolina) 
#export EPICS_CA_ADDR_LIST="$EPICS_CA_ADDR_LIST lcls-prod01:5068"

${cmdpath} -eolc ${mode} -m "EVGLOCA=SYS7,SYS=SYS7" asta_main

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

exit 0
