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

# Plots water injection 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-flow-${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:
ymin =  -4        # Min plot level (m^3/h).
ymax =  +48       # Max plot level (m^3/h).

yelo = ymin+0.05   # Min ordinate of event bar (m^3/h).
yehi = ymax-0.05   # Max ordinate of event bar (m^3/h).

ytopscale = 999999.0  # Assumed top of instrument's scale (m^3/h).
ybotscale = 0.0       # Assumed bottom of instrument's scale (m^3/h).

# Ordinate of explosion and smoke mark (m^3/h):
boomord = 0.0

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

unset logscale y; unset logscale y2
set ytics 10; set y2tics 10
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', \
  "flow-${unks}.txt" using 5:(qty(column(7))*0.06) title "Through fire ext. line (m^3/h)"  with linespoints pt  7 ps 1.5 lw 1.8 lc rgb '#008888', \
  "flow-${unks}.txt" using 5:(qty(column(9))*0.06) title "Through water feed line (m^3/h)" with linespoints pt  7 ps 1.5 lw 1.8 lc rgb '#6600ff'
quit
EOF

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

display ${pngfile}

rm -f ${tmp}.png
