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

# Plots temperatures 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=638

pngfile="out/plot-heat-${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 temperatures:
maxtemp =   400 # Upper limit of temperature sensor scale (C).

ymin = -49.0    # Min plot temperature (C).
ymax = 549.0    # Max plot temperature (C).

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

ytopscale = maxtemp   # Assumed top of instrument's scale (C).
ybotscale =  -275     # Assumed bottom of instrument's scale (C).

# Ordinate of explosion and smoke mark (C):
boomord = 100

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

unset logscale y; unset logscale y2
set ytics 100; set y2tics 100
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', \
  (maxtemp)                                     title "Topscale temp. (C)"      with lines                    lw 3.0 lc rgb '#ff7755', \
  "heat-${unks}.txt" using 5:(qty(column(7)))    title "Core noz. temp. (C)"    with linespoints pt  6 ps 1.5 lw 1.8 lc rgb '#aa3300', \
  "heat-${unks}.txt" using 5:(qty(column(9)))    title "Core bot. temp. (C)"    with linespoints pt  7 ps 0.9 lw 1.8 lc rgb '#ff1100', \
  "heat-${unks}.txt" using 5:(qty(column(11)))   title "Drywell temp. RPV (C)"  with linespoints pt  6 ps 1.5 lw 1.8 lc rgb '#5500ff', \
  "heat-${unks}.txt" using 5:(qty(column(13)))   title "Drywell temp. HVH (C)"  with linespoints pt  7 ps 0.9 lw 1.8 lc rgb '#8800aa', \
  "heat-${unks}.txt" using 5:(qty(column(15)))   title "Torus temp. A (C)"      with linespoints pt  6 ps 1.5 lw 1.8 lc rgb '#0055aa', \
  "heat-${unks}.txt" using 5:(qty(column(17)))   title "Torus temp. B (C)"      with linespoints pt  7 ps 0.9 lw 1.8 lc rgb '#006655'
quit
EOF

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

display ${pngfile}

rm -f ${tmp}.png
