#! /bin/bash
# Last edited on 2011-06-01 23:10:18 by stolfilocal

# Plots water level for one #Fukushima reactor.

rix="$1"; shift # Index of reactor (1,2,3)
source="$1"; shift; # Data source suffix ('t', 'n', etc.).
tag="$1"; shift;    # Tag for plot file name ("I" for first month, "T" for full history).
width="$1"; shift;  # Width in pixels before downscaling.
xmin="$1"; shift;   # Initial time coordinate (better if midnight).
xmax="$1"; shift;   # Final time coordinate (better if just before midnight).
xtics="$1"; shift;  # X tics option ("daily" for now).

tmp="/tmp/$$"

unk="un${rix}"
unks="un${rix}-${source}"

height=442

pngfile="out/plot-wlev-${unks}-${tag}-full.png"
  
export GDFONTPATH=..

gnuplot <<EOF

set term png font arial 14 size ${width},${height}
set xrange [${xmin}:${xmax}]
set output "${tmp}.png" 

# Special readings:
minwlev = -4000 # Lowest measurable water level (mm).
maxwlev = +4000 # Max measurable water level (mm).

ymin =  -5500    # Min plot level (mm).
ymax =  +5500    # Max plot level (mm).

yelo = ymin+20   # Min ordinate of event bar (mm).
yehi = ymax-20   # Max ordinate of event bar (mm).

ytopscale = maxwlev  # Assumed top of instrument's scale (mm).
ybotscale = minwlev  # Assumed bottom of instrument's scale (mm).

# Ordinate of explosion and smoke mark (mm):
boomord = 0

load "plot-common.gnuplot"
load "xtics-${xtics}.gnuplot"

unset logscale y; unset logscale y2
set ytics 1000; set y2tics 1000
set mytics 2; set my2tics 2
set format y "%5.0f"
set format y2 "%-5.0f"
set grid mytics
set xzeroaxis linetype -1 linewidth 1.5
plot \
  "boom-${unk}.txt"  using 5:(eum(column(7))):(yelo):(yehi) notitle               with yerrorbars  pt 13 ps 2.0 lw 6.0 lc rgb '#ffaaaa', \
  "boom-${unk}.txt"  using 5:(tum(column(7))):(yelo):(yehi) notitle               with yerrorbars  pt 13 ps 2.0 lw 6.0 lc rgb '#aaaaff', \
  "boom-${unk}.txt"  using 5:(bum(column(7))):(yelo):(yehi) notitle               with yerrorbars  pt 13 ps 2.0 lw 6.0 lc rgb '#ff8844', \
  "boom-${unk}.txt"  using 5:(fum(column(7))):(yelo):(yehi) notitle               with yerrorbars  pt  7 ps 0.0 lw 8.0 lc rgb '#ccbbaa', \
  "boom-${unk}.txt"  using 5:(rum(column(7))):(yelo):(yehi) title "Recalibration" with yerrorbars  pt  7 ps 0.0 lw 8.0 lc rgb '#aaccee', \
  (maxwlev)                                      title "Top of scale (mm)"        with lines                    lw 3.0 lc rgb '#aabbff', \
  (minwlev)                                      title "Bottom of scale (mm)"     with lines                    lw 3.0 lc rgb '#ccaaff', \
  "wlev-${unks}.txt" using 5:(qty(column(7)))    title "Water level A (mm)"       with linespoints pt  6 ps 1.5 lw 1.8 lc rgb '#0044ff', \
  "wlev-${unks}.txt" using 5:(qty(column(9)))    title "Water level B (mm)"       with linespoints pt  7 ps 0.9 lw 1.8 lc rgb '#6600ff'
quit
EOF

convert ${tmp}.png -resize '50%' ${pngfile}

display ${pngfile}

rm -f ${tmp}.png
