#! /bin/bash
# Last edited on 2011-03-30 18:32:21 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,1800
set output "${tmp}.png" 
set xrange [24:478]
set format y "%5.0f"
set format y2 "%5.0f"
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 \
)
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 LEVEL
set origin 0.00, 0.01
set size 1.00,0.25
set yrange [-4000:4000]; set y2range [-4000:4000]
set ytics 1000; set y2tics 1000
set mytics 2; set my2tics 2
set grid mytics
set xzeroaxis linetype -1 linewidth 1.5
plot \
  "data-${tag}.txt" using 5:(qty(column(7)))    title "Water level (mm)"         with linespoints pt  7 ps 1.0 lw 2.0 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'
# ----------------------------------------------------------------------
# TEMPERATURE
set origin 0.00, 0.26
set size 1.00,0.25
set yrange [-50.1:600.1]; set y2range [-50.1:600.1]
set format x ""
set ytics 100; set y2tics 100
set mytics 2; set my2tics 2
set grid mytics
set xzeroaxis linetype -1 linewidth 1.5
# set key left Left reverse
plot \
  "heat-${tag}.txt" using 5:(qty(column(7)))    title "Core noz. temp. (C)"  with linespoints pt  7 ps 1.0 lw 2.0 lc rgb '#aa1100', \
  "heat-${tag}.txt" using 5:(qty(column(9)))    title "Core bot. temp. (C)"  with linespoints pt  7 ps 1.0 lw 2.0 lc rgb '#ff1100', \
  (maxtemp)                                     title "Topscale temp. (C)"   with lines                    lw 1.5 lc rgb '#bb4422', \
  "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.51
set size 1.00,0.25
set yrange [-100.1:800.1]; set y2range [-100.1:800.1]
set ytics 100; set y2tics 100
set grid ytics
set xzeroaxis linetype -1 linewidth 1.5
plot \
  "data-${tag}.txt" using 5:(qty(column(9)))    notitle  with linespoints pt  7 ps 1.0 lw 2.0 lc rgb '#008800', \
  "data-${tag}.txt" using 5:(qty(column(11)))   notitle  with linespoints pt  6 ps 2.0 lw 2.0 lc rgb '#995500', \
  (maxpres)                                     notitle  with lines                    lw 1.5 lc rgb '#995500', \
  "data-${tag}.txt" using 5:(qty(column(13)))   notitle  with linespoints pt  7 ps 1.0 lw 2.0 lc rgb '#550088', \
  (atmosph)                                     notitle  with lines                    lw 1.5 lc rgb '#779988', \
  "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.74
set size 1.00,0.25
set xtics 24
set format x " "
set yrange [-100.1:9000.1]; set y2range [-100.1:9000.1]
set ytics 1000; set y2tics 1000
set grid ytics
set xzeroaxis linetype -1 linewidth 1.5
plot \
  "data-${tag}.txt" using 5:(qty(column(9)))    title "Core pressure (kPa)"      with linespoints pt  7 ps 1.0 lw 2.0 lc rgb '#008800', \
  (0/0)                                         title "Drywell pressure (kPa)"   with linespoints pt  6 ps 2.0 lw 2.0 lc rgb '#995500', \
  (maxpres)                                     title "Max drywell press. (kPa)" with lines                    lw 1.5 lc rgb '#995500', \
  (0/0)                                         title "Torus pressure (kPa)"     with linespoints pt  7 ps 1.0 lw 2.0 lc rgb '#550088', \
  (atmosph)                                     title "Atmospheric pressure"     with lines                    lw 1.5 lc rgb '#779988', \
  "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
