#!/bin/bash
#
# @(#) Generate combined and extended charts for
# @(#) two HP Receivers
#
# Where the HTML output will go
HTMLDIR="/opt/http/htdocs/darkgps"
#
# Where the data files are
DATADIR="/opt/gpsdata"
#
# Where the programs are
PROGRAMDIR="/opt/ntp/timelord/shm"
#
# The semaphore that will prevent multiple copies of this
# file from running.
FSEM="/tmp/chartsemaphore"
#
# If we are trapped, then we remove the semaphore
trap "rm -f ${FSEM}" 1 2 3 15
#
if [[ -f $FSEM ]]
then
	echo "Previous chart already running"
	exit
fi
cd $PROGRAMDIR || exit
#
# Create the semaphore
touch $FSEM
	echo "+++++++++++++++++++++++++++++++++++++++++++"
	date
	echo "Chart0 Single"
	echo ""
	#
	EFILE="${HTMLDIR}/chartEFC0"
	UFILE="${HTMLDIR}/chartHU0"
	TITLE="HP Z3801A Receiver on ttyS0"
	LOG="${DATADIR}/timelogS0.log"
		./gpschart -i "${LOG}" -e "${EFILE}" -u "${UFILE}" -t "${TITLE}"
	echo "-----------------------------"
	echo "Chart1 Single"
	echo ""
	#
	EFILE="${HTMLDIR}/chartEFC1"
	UFILE="${HTMLDIR}/chartHU1"
	TITLE="HP Z3801A Receiver on ttyS1"
	LOG="${DATADIR}/timelogS1.log"
		./gpschart -i "${LOG}" -e "${EFILE}" -u "${UFILE}" -t "${TITLE}"
	echo "-----------------------------"
	echo "Chart double"
	echo ""
	#
	EFILE="${HTMLDIR}/chartEFC"
	UFILE="${HTMLDIR}/chartHU"
	TITLE="HP Z3801A Combined Receiver Data"
	LOG="${DATADIR}/timelogS0.log,${DATADIR}/timelogS1.log"
		./gpschart -i "${LOG}" -e "${EFILE}" -u "${UFILE}" -t "${TITLE}"
	echo ""
	date
rm -f $FSEM
