#! /bin/bash
#
#   This function sends an alarm to the Epics system. The calling syntax
#   is as follows:
#
#       earthquake_alarm <significance>
#
#   Recognized significance levels are
#            x < -1  -- minor event A
#       -1 < x < 1   -- return to normal
#        1 < x < 2   -- minor event B
#        2 < x       -- major event
#

# Set the logfile for earthquake alarms
[ -n "$DMTHTMLOUT" ] || export DMTHTMLOUT=$DMTOUTPUT
eq_alarmlog=${DMTHTMLOUT}/eqkalarm_log

# Set the site-dependent variables
if [ "$LIGOSITE" = "LHO" ]; then
  eq_channel=H0:GDS-EARTHQUAKE
elif [ "$LIGOSITE" = "LLO" ]; then
  eq_channel=L0:GDS-EARTHQUAKE
fi

# Send the alarm
significance="$p1"
caput $eq_channel $significance

# Write to the logfile
echo "Earthquake Alarm triggered: $significance at `date`" >> $eq_alarmlog
