rpirena/www/cgi/rpirena-3Diodes
stephan 8c2462e42a cgi/rpirena-3diodes DATA
git-svn-id: svn+ssh://asterix.ieap.uni-kiel.de/home/subversion/stephan/solo/eda/cospi/host@9406 bc5caf13-1734-44f8-af43-603852e9ee25
2026-06-03 18:42:37 +00:00

174 lines
4.9 KiB
Bash
Executable file

#! /bin/bash
# -*- sh -*-
DATA="/3diodes/data/"
cat <<EOT
Content-type: text/html
<html>
<head>
<meta charset="UTF-8" />
<title>RPiRENA Data</title>
</head>
<body>
<h1>Live plots of the Three-Diodes sensor for Cosmic Ray measurements on Balloons</h1>
<ul>
<li/><a href="rpirena?old">Show</a> the plots already processed (default).
<li/><a href="rpirena?plot">Process</a> new data and show the plots. May time out for big files.
<li/><a href="rpirena?trigger">Start processing</a> data, without waiting.
<li/><a href="rpirena-control">RPiRENA control.</a>
<li/><a href="${DATA}">Data Files.</a>
</ul>
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 <<EOF
<p/>Actions for the selected old data file:
<a href="rpirena?plot&amp;$TARGET">plot</a>
<a href="rpirena?old&amp;$TARGET">old</a>
<a href="rpirena?trigger&amp;$TARGET">trigger</a>
<a href="rpirena?replot&amp;$TARGET">replot</a>
<a href="rpirena?nomake&amp;$TARGET">nomake</a>
EOF
cat <<EOF
<p/>Beware of the fake hwclock of the Raspberry Pi, the times in the filenames may be fake.
<p/>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=THREED ${pfn}.EmV ${pfn}.3Dhist ${pfn}.HK ${pfn}.CP >>$lf 2>&1
cat <<EOT | gnuplot >>$lf 2>&1
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 \
for [c in "B C"] "$pfn.EmV" u c:"A" tit "A vs ".c with p pt 6 ps 0.3, \
for [c in "A B C"] "$pfn.3Dhist" u "mV":c axis x1y2 tit c with histeps, \
for [c in "Bc Cc"] "$pfn.3Dhist" u "mV":c axis x1y2 tit c[:1]."(A>10)" with histeps lw 2
unset out
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] [nA]"
set y2lab "[°C]"
set term png
set out "${hfn}-new"
array HN[8] = [ "V_{CORE}", "V_{CC}", "V_{IO}", "V_{PRIM}", "T_{FPGA}", "T_{SENSOR}", "T_{AIR}", "I_{BIAS}" ]
plot \
for [c=8:8] "<tail -n +25 ${pfn}.HK" u 2:2+c axis x1y1 tit HN[c] with l lt c, \
for [c=1:4] "<tail -n +25 ${pfn}.HK" u 2:2+c axis x1y1 tit HN[c] with l lt c lw 2, \
for [c=5:7] "<tail -n +25 ${pfn}.HK" u 2:2+c axis x1y2 tit HN[c] with l lt c lw 2
unset out
set yrange [0.9:*]
set log y
set y2range [0.1<*:1100]
set log y2
set xlab "time [UTC]"
set ylab "[counts/min]"
set y2lab "p [mbar]"
set term png
set out "${cfn}-new"
array CN[17] = ["T0", "-", "T2", "T3", "H0", "-", "H2", "H3", "X0", "X2", "X3", "C23", "C03", "C02", "C023", "L2", "L3"]
plot \
"<tail -n +8 ${pfn}.CP" u 23:22 axis x1y2 tit "p" w l lt 1, \
for [c in "1 3 4 4 7 8"] "<tail -n +8 ${pfn}.CP" u 23:2+c tit "L_1[".(c-1)."]: ".CN[c+0] with l lt c+1, \
for [c=9:16] "<tail -n +8 ${pfn}.CP" u 23:2+c tit "L_2[".(c-9)."]: ".CN[c+0] with steps lt c-3 lw 2
unset out
EOT
mv -v $sfn-new $sfn >>$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 <<EOT
<h3>File: $bfn</h3>
<ul>
<li><a href="${DATA}$bfn.CP">Count Rates</a>, <a href="/data/README.txt">README</a>
<li><a href="${DATA}$bfn.HK">Housekeeping</a>
<li><a href="${DATA}$bfn.EI">Raw Data</a>
</ul>
<p/><img src="${DATA}$bfn-spectra.png"/>
<p/><img src="${DATA}$bfn-hk.png"/>
<p/><img src="${DATA}$bfn-counts.png"/>
<h2>Older Spectra:</h2>
<ul>
EOT
cd ../../www/data
ls -r1 20??-??-??T??:??:??Z.EI | xargs -i echo '<li> <a href="rpirena?old&amp;{}">{}</a>'
cat <<EOT
</ul>
</p><img src="${DATA}IMG_5703-25.jpg"/>
</body>
</html>
EOT