#! /bin/bash
# Last edited on 2011-04-06 01:29:43 by stolfi

# Plots water level and pressure for one #Fukushima reactor.

rix="$1"; shift # Index of reactor (1,2,...,6)

tmp="/tmp/$$"

tag="un${rix}"
  
export GDFONTPATH=..

gnuplot <<EOF

set term png font arialbd 18 size 1800,2600
set output "${tmp}.png" 
set xrange [0:646]
unset title
set xtics ( \
  "        3/11"   0 0, \
  "        3/12"  24 0, \
  "        3/13"  48 0, \
  "        3/14"  72 0, \
  "        3/15"  96 0, \
  "        3/16" 120 0, \
  "        3/17" 144 0, \
  "        3/18" 168 0, \
  "        3/19" 192 0, \
  "        3/20" 216 0, \
  "        3/21" 240 0, \
  "        3/22" 264 0, \
  "        3/23" 288 0, \
  "        3/24" 312 0, \
  "        3/25" 336 0, \
  "        3/26" 360 0, \
  "        3/27" 384 0, \
  "        3/28" 408 0, \
  "        3/29" 432 0, \
  "        3/30" 456 0, \
  "        3/31" 480 0, \
  "        4/01" 504 0, \
  "        4/02" 528 0, \
  "        4/03" 552 0, \
  "        4/04" 576 0, \
  "        4/05" 600 0, \
  "        4/06" 624 0, \
  "        4/07" 648 0 \
)
set grid xtics
set grid ytics
# set key left
maxpres =  400 # Max design pressure for vessel (core or drywell)?
maxtemp =  400 # Upper limit of temperature sensor scale (C).
atmosph =  100 # Atmospheric pressure (kPa).
boomord =    0 # Ordinate of explosion mark.
qty(z) = (z == 88888 ? 0/0 : (z == 99999 ? 0/0 : z))
bum(z) = ((z == 0) ? 0/0 : boomord)
set multiplot layout 3,1 title "Fukushima Dai-ichi Reactor #${rix}"
# ----------------------------------------------------------------------
# WATER INPUT
set origin 0.00, 0.00
set size 1.00,0.17
set yrange [-1:790]; set y2range [-1:790]
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 \
  "flow-${tag}.txt" using 5:(qty(column(7)))  title "Water injection rate (l/min)" with      points pt  7 ps 2.0 lw 1.5 lc rgb '#008888', \
  "data-${tag}.txt" using 5:(bum(column(15))) notitle                              with      points pt 13 ps 4.0 lw 0.0 lc rgb '#ff5500'
# ----------------------------------------------------------------------
# WATER LEVEL
set origin 0.00, 0.16
set size 1.00,0.17
set yrange [-3500:4500]; set y2range [-3500:4500]
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 \
  "data-${tag}.txt" using 5:(qty(column(7)))    title "Water level (mm)"         with      points pt  7 ps 2.0 lw 1.5 lc rgb '#0044ff', \
  "data-${tag}.txt" using 5:(bum(column(15)))   notitle                          with      points pt 13 ps 4.0 lw 0.0 lc rgb '#ff5500'
# ----------------------------------------------------------------------
# RADIATION
set origin 0.00, 0.32
set size 1.00,0.17
set yrange [0.27:600]; set y2range [0.27:600]
set logscale y; set logscale y2
set ytics ( \
  0.5, \
  1, \
  2.5, \
  5, \
  10, \
  25, \
  50, \
  100, \
  250 \
)
set y2tics ( \
  0.5, \
  1, \
  2.5, \
  5, \
  10, \
  25, \
  50, \
  100, \
  250 \
)
set mytics 2; set my2tics 2
set format y "%5.1f"
set format y2 "%-5.1f"
set grid mytics
# set xzeroaxis linetype -1 linewidth 1.5
plot \
  "cams-${tag}.txt" using 5:(qty(column(7))/100) title "Drywell radiation (Sv/h)" with linespoints pt  7 ps 1.3 lw 1.5 lc rgb '#ff8800', \
  "cams-${tag}.txt" using 5:(qty(column(9))/100) title "Torus radiation (Sv/h)"   with linespoints pt  7 ps 1.3 lw 1.5 lc rgb '#ff0088', \
  "data-${tag}.txt" using 5:(bum(column(15)))   notitle                           with      points pt 13 ps 4.0 lw 0.0 lc rgb '#ff5500'
# ----------------------------------------------------------------------
# TEMPERATURE
set origin 0.00, 0.49
set size 1.00,0.17
set yrange [-49.0:590.0]; set y2range [-49.0:590.0]
unset logscale y; unset logscale y2
set format x ""
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
# set key left Left reverse
plot \
  (maxtemp)                                     title "Topscale temp. (C)"   with lines                    lw 3.5 lc rgb '#ff6644', \
  "heat-${tag}.txt" using 5:(qty(column(7)))    title "Core noz. temp. (C)"  with linespoints pt  7 ps 1.3 lw 1.5 lc rgb '#aa1100', \
  "heat-${tag}.txt" using 5:(qty(column(9)))    title "Core bot. temp. (C)"  with linespoints pt  7 ps 1.3 lw 1.5 lc rgb '#ff1100', \
  "data-${tag}.txt" using 5:(bum(column(15)))   notitle                      with      points pt 13 ps 4.0 lw 0.0 lc rgb '#ff5500'
# ----------------------------------------------------------------------
# PRESSURE (MICRO)
set origin 0.00, 0.66
set size 1.00,0.17
set yrange [-49.0:790.0]; set y2range [-49.0:790.0]
unset logscale y; unset logscale y2
set ytics 100; set y2tics 100
set format y "%5.0f"
set format y2 "%-5.0f"
set grid ytics
set xzeroaxis linetype -1 linewidth 1.5
plot \
  (atmosph)                                     notitle  with lines                    lw 3.5 lc rgb '#77aaff', \
  (maxpres)                                     notitle  with lines                    lw 3.5 lc rgb '#cc9977', \
  "data-${tag}.txt" using 5:(qty(column(13)))   notitle  with linespoints pt  6 ps 2.5 lw 1.5 lc rgb '#6688ff', \
  "data-${tag}.txt" using 5:(qty(column(11)))   notitle  with linespoints pt  7 ps 1.5 lw 1.5 lc rgb '#993300', \
  "data-${tag}.txt" using 5:(qty(column(9)))    notitle  with linespoints pt  7 ps 1.3 lw 1.5 lc rgb '#008800', \
  "data-${tag}.txt" using 5:(bum(column(15)))   notitle  with      points pt 13 ps 4.0 lw 0.0 lc rgb '#ff5500'
# ----------------------------------------------------------------------
# PRESSURE (MACRO)
set origin 0.00, 0.80
set size 1.00,0.18
set xtics 24
set format x " "
set yrange [+750.0:8900.0]; set y2range [+750.0:8900.0]
unset logscale y; unset logscale y2
set ytics 1000; set y2tics 1000
set format y "%5.0f"
set format y2 "%-5.0f"
set grid ytics
set xzeroaxis linetype -1 linewidth 1.5
plot \
  (0/0)                                         title "Atmospheric pressure"     with lines                    lw 3.5 lc rgb '#77aaff', \
  (0/0)                                         title "Max drywell press. (kPa)" with lines                    lw 3.5 lc rgb '#cc9977', \
  (0/0)                                         title "Torus pressure (kPa)"     with linespoints pt  6 ps 2.5 lw 1.5 lc rgb '#6688ff', \
  (0/0)                                         title "Drywell pressure (kPa)"   with linespoints pt  7 ps 1.5 lw 1.5 lc rgb '#993300', \
  "data-${tag}.txt" using 5:(qty(column(9)))    title "Core pressure (kPa)"      with linespoints pt  7 ps 1.3 lw 1.5 lc rgb '#008800', \
  "data-${tag}.txt" using 5:(bum(column(15)))   title "Explosion"                with      points pt 13 ps 4.0 lw 0.0 lc rgb '#ff5500'
# ----------------------------------------------------------------------
quit
EOF

convert ${tmp}.png -resize '50%' plot-${tag}-full.png

display plot-${tag}-full.png

rm -f ${tmp}.png
