#!/bin/bash
#==============================================================
#
#  Name:  ktl-pps
#
#  Rem:   This script launches the Klystron Test Lab PPS Display
# 
#  Usage: klt-pps
#
#  Auth:  06-Dec-2016, Kristi Luchini  (luchini) 
#  Rev:   dd-mmm-yyyy, Reviewer's Name (username)
# ------------------------------------------------------------
#  Mod:
#         dd-mmm-yyyy, First Lastname  (username):
#            comment
#--------------------------------------------------------------
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

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

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

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

#export EDMFILTERS=/afs/slac/g/acctest/tools/edm/config/homeFilter_ktl
export EPICS_CA_ADDR_LIST="$EPICS_CA_ADDR_LIST lcls-prod01:5068"

${cmdpath} -eolc ${mode} pps_b44_main

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

exit 0
