#! /bin/bash
# Last edited on 2011-04-15 08:39:27 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}"
pre="uns/2011-04-12-130000-"
old="../2011-04-14-233000/"
  
export GDFONTPATH=.

gnuplot <<EOF

set term png font arial 18 size 2400,3600
set output "${tmp}.png" 
unset title
set lmargin 7; set rmargin 7 
unset ylabel; unset y2label 
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, \
  "        4/08" 672 0, \
  "        4/09" 696 0, \
  "        4/10" 720 0, \
  "        4/11" 744 0, \
  "        4/12" 768 0, \
  "        4/13" 792 0, \
  "        4/14" 816 0, \
  "        4/15" 840 0, \
  "        4/16" 864 0, \
  "        4/17" 888 0, \
  "        4/18" 912 0, \
  "        4/19" 936 0, \
  "        4/20" 960 0 \
)
set grid xtics
set grid ytics
# set key left
sizeden = 1.200 # Denominator for Y plot origins and sizes.
keytime =   648 # Time coordinate when plot key starts.
norcorp =  6690 # Norml core operating pressure (kPa)
maxdryp =   485 # Max drywell design pressure (kPa)
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.00/sizeden)
set size 1.00,(0.17/sizeden)
set xrange [0:814]
set yrange [-4500:4500]; set y2range [-4500: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 \
  "${old}data-${tag}.txt" using 5:(qty(column(7)))    notitle                          with linespoints pt  7 ps 3.0 lw 2.0 lc rgb '#88aacc', \
  \
  "${pre}watr-${tag}.txt" using 5:(qty(column(7)))    title "Water level A (mm)"       with linespoints pt  6 ps 2.0 lw 1.5 lc rgb '#0044ff', \
  "${pre}watr-${tag}.txt" using 5:(qty(column(9)))    title "Water level B (mm)"       with linespoints pt  7 ps 1.3 lw 1.5 lc rgb '#008877'
# ----------------------------------------------------------------------
# RADIATION
set origin 0.00,(0.16/sizeden)
set size 1.00,(0.17/sizeden)
set xrange [0:814]
set yrange [0.27:950]; set y2range [0.27:950]
set logscale y; set logscale y2
set ytics ( \
  0.5, \
  1, \
  2.5, \
  5, \
  10, \
  25, \
  50, \
  100, \
  250, \
  500 \
)
set y2tics ( \
  0.5, \
  1, \
  2.5, \
  5, \
  10, \
  25, \
  50, \
  100, \
  250, \
  500 \
)
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 \
  "${old}cams-${tag}.txt" using 5:(qty(column(7))/100) notitle                          with linespoints pt  6 ps 3.8 lw 2.5 lc rgb '#ffcc88', \
  "${old}cams-${tag}.txt" using 5:(qty(column(9))/100) notitle                          with linespoints pt  7 ps 3.0 lw 2.5 lc rgb '#ff88cc', \
  \
  "${pre}cams-${tag}.txt" using 5:(qty(column(7))/100) title "Drywell radiation (Sv/h)" with linespoints pt  6 ps 1.8 lw 1.5 lc rgb '#ff8800', \
  "${pre}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'
# ----------------------------------------------------------------------
# TEMPERATURE
set origin 0.00,(0.33/sizeden)
set size 1.00,(0.17/sizeden)
set xrange [0:814]
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 \
  (x < keytime ? maxtemp : 0/0)                       title "Topscale temp. (C)"   with lines                    lw 3.5 lc rgb '#ff7755', \
  \
  "${old}heat-${tag}.txt" using 5:(qty(column(7)))    notitle                      with linespoints pt  6 ps 3.8 lw 2.5 lc rgb '#cc9988', \
  "${old}heat-${tag}.txt" using 5:(qty(column(9)))    notitle                      with linespoints pt  7 ps 3.0 lw 2.5 lc rgb '#ff8877', \
  \
  "${pre}heat-${tag}.txt" using 5:(qty(column(7)))    title "Core noz. temp. (C)"  with linespoints pt  6 ps 1.8 lw 1.5 lc rgb '#aa1100', \
  "${pre}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'
# ----------------------------------------------------------------------
# CORE PRESSURE
set origin 0.00,(0.50/sizeden)
set size 1.00,(0.32/sizeden)
set xrange [0:814]
set yrange [0.9:19000]; set y2range [0.9:19000]
set logscale y; set logscale y2
set ytics ( \
  0.5, \
  1, \
  2.5, \
  5, \
  10, \
  25, \
  50, \
  100, \
  250, \
  500, \
  1000, \
  2500, \
  5000 \
)
set y2tics ( \
  0.5, \
  1, \
  2.5, \
  5, \
  10, \
  25, \
  50, \
  100, \
  250, \
  500, \
  1000, \
  2500, \
  5000 \
)
set mytics 2; set my2tics 2
set format y "%6.1f"
set format y2 "%-6.1f"
set grid ytics
set xzeroaxis linetype -1 linewidth 1.5
plot \
  (atmosph)                                           title "Atmospheric pressure"      with lines                    lw 3.5 lc rgb '#77aaff', \
  (x < keytime ? norcorp : 0/0)                       title "Operating core pressure"   with lines                    lw 3.5 lc rgb '#55aa55', \
  \
  "${old}data-${tag}.txt" using 5:(qty(column(9)))   title "Core pressure JS (kPa)"     with linespoints pt  7 ps 3.5 lw 2.5 lc rgb '#aaccff', \
  \
  "${pre}pres-${tag}.txt" using 5:(qty(column(7)))   title "Core pressure RA (kPa)"     with linespoints pt  6 ps 1.8 lw 1.5 lc rgb '#008822', \
  "${pre}pres-${tag}.txt" using 5:(qty(column(9)))   title "Core pressure RB (kPa)"     with linespoints pt  6 ps 1.8 lw 1.5 lc rgb '#446600', \
  \
  "${pre}corr-${tag}.txt" using 5:(qty(column(7)))   title "Core pressure CA (kPa)"     with linespoints pt  7 ps 1.3 lw 1.5 lc rgb '#008822', \
  "${pre}corr-${tag}.txt" using 5:(qty(column(9)))   title "Core pressure CB (kPa)"     with linespoints pt  7 ps 1.3 lw 1.5 lc rgb '#446600'
# ----------------------------------------------------------------------
# DRYWELL PRESSURE
set origin 0.00,(0.82/sizeden)
set size 1.000,(0.17/sizeden)
set xrange [0:814]
set yrange [-49:1149]; set y2range [-49:1149]
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 ytics
set xzeroaxis linetype -1 linewidth 1.5
plot \
  (atmosph)                                           title "Atmospheric pressure"       with lines                    lw 3.5 lc rgb '#77aaff', \
  (maxdryp)                                           title "Max drywell pressure"       with lines                    lw 3.5 lc rgb '#cc9977', \
  \
  "${old}data-${tag}.txt" using 5:(qty(column(11)))  title "Drywell pressure JS (kPa)"   with linespoints pt  7 ps 3.5 lw 2.5 lc rgb '#bb8866', \
  \
  "${pre}pres-${tag}.txt" using 5:(qty(column(11)))  title "Drywell pressure RA (kPa)"   with linespoints pt  6 ps 1.8 lw 1.5 lc rgb '#993300', \
  \
  "${pre}corr-${tag}.txt" using 5:(qty(column(11)))  title "Drywell pressure CA (kPa)"   with linespoints pt  7 ps 1.3 lw 1.5 lc rgb '#993300'
# ----------------------------------------------------------------------
# TORUS PRESSURE
set origin 0.00,(0.99/sizeden)
set size 1.000,(0.17/sizeden)
set xrange [0:814]
set yrange [-49:1149]; set y2range [-49:1149]
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 ytics
set xzeroaxis linetype -1 linewidth 1.5
plot \
  (atmosph)                                          title "Atmospheric pressure"       with lines                    lw 3.5 lc rgb '#77aaff', \
  (maxdryp)                                          title "Max drywell pressure"       with lines                    lw 3.5 lc rgb '#cc9977', \
  \
  "${old}data-${tag}.txt" using 5:(qty(column(13)))  title "Torus pressure JS (kPa)"    with linespoints pt  7 ps 3.5 lw 2.5 lc rgb '#aaccff', \
  \
  "${pre}pres-${tag}.txt" using 5:(qty(column(13)))  title "Torus pressure RA (kPa)"    with linespoints pt  6 ps 1.8 lw 1.5 lc rgb '#6688ff', \
  \
  "${pre}corr-${tag}.txt" using 5:(qty(column(13)))  title "Torus pressure CA (kPa)"    with linespoints pt  7 ps 1.3 lw 1.5 lc rgb '#6688ff'
# ----------------------------------------------------------------------
unset multiplot
quit
EOF

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

display plot-${tag}-full.png

rm -f ${tmp}.png
