#! /bin/bash
# Last edited on 2011-03-23 03:03:54 by stolfi

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

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

tmp="/tmp/$$"

dcol=$(( 2*rix + 5 )) # Column of first quantity of that reactor in "data.txt"
bcol=$(( 2*rix + 5 )) # Column of first quantity of that reactor in "boom.txt"
hcol=$(( 4*rix + 3 )) # Column of first quantity of that reactor in "heat.txt"

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

gnuplot <<EOF

set term png font arialbd 18 size 1800,900
set output "${tmp}.png" 
set xrange [24:287]
set yrange [-4000:10000]
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 \
)
set grid xtics
set xzeroaxis linetype -1 linewidth 1.5
# set key left
qty(z) = ((z == 88888) || (z == 99999) ? 0/0 : z)
bum(z) = ((z == 0) ? 0/0 : 0)
plot \
  "data.txt" using 5:(qty(column(${dcol}+ 0)))   title "Water level (mm)"         with linespoints pt 7 ps 1.0 lw 3.0 lc rgb '#0044ff', \
  "data.txt" using 5:(qty(column(${dcol}+ 6)))   title "Core pressure (kPa)"      with linespoints pt 7 ps 1.0 lw 3.0 lc rgb '#008800', \
  "data.txt" using 5:(qty(column(${dcol}+12)))   title "Drywell pressure (kPa)"   with linespoints pt 7 ps 1.0 lw 3.0 lc rgb '#995500', \
  "data.txt" using 5:(qty(column(${dcol}+18)))   title "Torus pressure (kPa)"     with linespoints pt 7 ps 1.0 lw 3.0 lc rgb '#550088', \
  "heat.txt" using 5:(10*qty(column(${hcol}+2))) title "Core temperature x10 (C)" with linespoints pt 7 ps 1.0 lw 3.0 lc rgb '#ff1100', \
  "boom.txt" using 5:(bum(column(${bcol})))      title "Explosion"                with      points pt 5 ps 2.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
