#! /bin/bash
# -*- sh -*-
cat <
RPiRENA Data
Live plots of µMustang on $(hostname)
EOT
exec 2>&1
cd /home/$(hostname)/stephan/rpirena || exit
lf=../../www/data/rpirena-cgi.log
lkf=../../www/data/rpirena-cgi.lock
declare -a QUERY=(${QUERY_STRING//&/ })
ACTION=${QUERY[0]}
[ -z "$ACTION" ] && TARGET="" || TARGET=${QUERY[-1]}
[ "$TARGET" = "$ACTION" ] && TARGET=""
[ -z "$ACTION" ] && ACTION=old
echo "$REMOTE_ADDR $HTTP_USER_AGENT $QUERY_STRING $ACTION $TARGET" >>$lf
[ -f "$lkf" ] && cat "$lkf" 2>/dev/null
[ -z "$TARGET" ] || cat <Actions for the selected old data file:
plot
old
trigger
replot
nomake
EOF
cat <Beware of the fake hwclock of the Raspberry Pi, the times in the filenames may be fake.
You may need to reload the page in your browser to see the latest plots.
EOF
if [ "$ACTION" = "trigger" ]
then
export QUERY_STRING="replot&$TARGET"
nohup ../../www/cgi/rpirena > ../../www/data/rpirena-trigger.log 2>&1 &
ACTION="old"
fi
if [ "$ACTION" = "restart" ]
then
echo restart > auto-run
export ACTION="old"
fi
if [ "$ACTION" = "stop" ]
then
echo stop > auto-run
export ACTION="old"
fi
fn=../../www/data/$TARGET
[ -f $fn ] || fn=$(ls -1 ../../www/data/20??-??-??T??:??:??Z.EI | tail -1)
bfn=$(basename $fn .EI)
pfn=../../www/data/$bfn
sfn=${pfn}-spectra.png
hfn=${pfn}-hk.png
cfn=${pfn}-counts.png
REPLOT=$ACTION
[ -f "$fn" -a "$fn" -nt "$sfn" -a "$ACTION" = "plot" ] && REPLOT=replot
if [ -f "$fn" -a "$REPLOT" = "replot" ] && dotlockfile -r 0 $lkf
then
trap "rm $lkf" EXIT
date +"Processing $bfn since %Y-%m-%d %H:%M:%S UTC" > $lkf
date +"Plot $bfn %Y-%m-%d %H:%M:%S" >>$lf
[ "$ACTION" = "nomake" ] || make UNIT=uM ${pfn}.EmV ${pfn}.uMhist ${pfn}.HK ${pfn}.CP >>$lf 2>&1
cat <>$lf 2>&1
print "plot spectra"
set title "$(hostname) RPiRENA $bfn" noenh
set xrange [-10:160]
set yrange [-10:160]
set y2range [0.9:*]
set log y2
set ytics nomirror
set y2tics
set xlab "pulse height [mV]"
set ylab "pulse height [mV]"
set y2lab "[counts/mV]"
set grid
set timestamp "%Y-%m-%d %H:%M:%S"
set term png size 1024,768
set out "${sfn}-new"
plot \
"$pfn.EmV" u "A1":"A2" tit "A1 vs A2" with d, \
"$pfn.EmV" u "B1":"B2" tit "B1 vs B2" with d, \
for [c in "A1 A2 B1 B2"] "$pfn.uMhist" u "mV":c axis x1y2 tit c w histeps
unset out
print "plot HK"
set xrange [*:*]
set xtics timedate
set format x "%d.%m.\n%Hh%M" time
set yrange [0:10]
set y2range [*:*]
unset log y2
set xlab "time [UTC]"
set ylab "[V] [10nA]"
set y2lab "[°C]"
set term png
set out "${hfn}-new"
array HN[8] = [ "V_{CORE}", "V_{CC}", "V_{IO}", "V_{PRIM}", "T_{FPGA}", "T_{CPU}", "T_{EBOX}", "I_{BIAS}" ]
plot \
for [c=8:8] ">$lf 2>&1
mv -v $hfn-new $hfn >>$lf 2>&1
mv -v $cfn-new $cfn >>$lf 2>&1
rm -f $lkf
trap EXIT
fi
cat <File: $bfn
Older Spectra:
EOT
cd ../../www/data
ls -r1 20??-??-??T??:??:??Z.EI | xargs -i echo '- {}'
cat <