#! /bin/bash
# Last edited on 2011-03-28 13:32:42 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:406]
set yrange [-4000:10000]
set ytics 1000
set grid ytics
set title "Fukushima Daiichi - Reactor #${rix}"
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 \
)
set grid xtics
set xzeroaxis linetype -1 linewidth 1.5
# 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 =  200 # Ordinate of explosion mark.
qty(z) = (z == 88888 ? 0/0 : (z == 99999 ? 0/0 : z))
bum(z) = ((z == 0) ? 0/0 : boomord)
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:(qty(column(9)))    title "Core pressure (kPa)"      with linespoints pt 7 ps 1.0 lw 2.0 lc rgb '#008800', \
  "data-${tag}.txt" using 5:(qty(column(11)))   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', \
  "data-${tag}.txt" using 5:(qty(column(13)))   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', \
  "heat-${tag}.txt" using 5:(10*qty(column(7))) title "Core noz. temp. x10 (C)"  with linespoints pt 7 ps 1.0 lw 2.0 lc rgb '#aa1100', \
  "heat-${tag}.txt" using 5:(10*qty(column(9))) title "Core bot. temp. x10 (C)"  with linespoints pt 7 ps 1.0 lw 2.0 lc rgb '#ff1100', \
  (10*maxtemp)                                  title "Topscale temp. x10 (C)"   with lines                   lw 1.5 lc rgb '#ff4422', \
  "data-${tag}.txt" using 5:(bum(column(15)))   title "Explosion"                with      points pt 5 ps 3.0 lw 0.0 lc rgb '#ff3300'
quit
EOF

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

display plot-${tag}-full.png

rm -f ${tmp}.png
