#! /bin/bash
# Last edited on 2011-06-01 23:08:33 by stolfilocal

# Plots pressure data for one Fukushima reactor.

rix="$1"; shift;     # Index of reactor (1,2,3).
source="$1"; shift;  # Data source suffix ('t', 'n', etc.).
tag="$1"; shift;     # Tag for plot file name ("I" for first month, "T" for full history).
width="$1"; shift;   # Width in pixels before downscaling.
xmin="$1"; shift;    # Initial time coordinate (better if midnight).
xmax="$1"; shift;    # Final time coordinate (better if just before midnight).
xtics="$1"; shift;   # X tics option ("daily" for now).

tmp="/tmp/$$"

unk="un${rix}"
unks="un${rix}-${source}"

height=702

pngfile="out/plot-pres-${unks}-${tag}-full.png"
  
export GDFONTPATH=..

gnuplot <<EOF

set term png font arial 14 size ${width},${height}
set xrange [${xmin}:${xmax}]
set output "${tmp}.png" 

# Special pressures:
norcorp =  6690 # Norml core operating pressure (kPa).
maxcorp =  8700 # Max core operating pressure (kPa).
maxdryp =   485 # Max drywell design pressure (kPa).
atmosph =   100 # Atmospheric pressure (kPa).

ymin = 3.16     # Min plot pressure (kPa).
ymax = 75000.0  # Max plot pressure (kPa).

yelo = ymin*1.1  # Min ordinate of event bar (kPa).
yehi = ymax/4.0  # Max ordinate of event bar (kPa).

ytopscale = 100000.0   # Assumed top of instrument's scale (kPa).
ybotscale =      1.0   # Assumed bottom of instrument's scale (kPa).

# Ordinate of explosion and smoke mark:
boomord = atmosph 

load "plot-common.gnuplot"
load "xtics-${xtics}.gnuplot"

set logscale y; set logscale y2
set ytics ( \
  0.5, \
  1, \
  2, \
  5, \
  10, \
  20, \
  50, \
  100, \
  200, \
  500, \
  1000, \
  2000, \
  5000, \
  10000, \
  20000, \
  50000, \
  100000, \
  200000 \
)
set y2tics ( \
  0.5, \
  1, \
  2, \
  5, \
  10, \
  20, \
  50, \
  100, \
  200, \
  500, \
  1000, \
  2000, \
  5000, \
  10000, \
  20000, \
  50000, \
  100000, \
  200000 \
)
set mytics 1; set my2tics 1
set format y "%7.0f"
set format y2 "%-7.0f"
set grid nomytics; set grid ytics
set xzeroaxis linetype -1 linewidth 1.5
plot \
  "boom-${unk}.txt"  using 5:(eum(column(7))):(yelo):(yehi) title "Earthquake"   with yerrorbars pt 13 ps 2.0 lw  6.0 lc rgb '#ffaaaa', \
  "boom-${unk}.txt"  using 5:(tum(column(7))):(yelo):(yehi) title "Tsunami"      with yerrorbars pt 13 ps 2.0 lw  6.0 lc rgb '#aaaaff', \
  "boom-${unk}.txt"  using 5:(bum(column(7))):(yelo):(yehi) title "Explosion"    with yerrorbars pt 13 ps 2.0  lw 6.0 lc rgb '#ff8844', \
  "boom-${unk}.txt"  using 5:(fum(column(7))):(yelo):(yehi) title "Dark smoke"   with yerrorbars pt  7 ps 0.0  lw 8.0 lc rgb '#ccbbaa', \
  (atmosph)                                    title "Atmospheric pressure"      with lines                    lw 3.0 lc rgb '#aaccff', \
  (maxdryp)                                    title "Max drywell pressure"      with lines                    lw 3.0 lc rgb '#99cc99', \
  (norcorp)                                    title "Operating core pressure"   with lines                    lw 3.0 lc rgb '#ddaaaa', \
  (maxcorp)                                    title "Max core pressure"         with lines                    lw 3.0 lc rgb '#ffaaaa', \
  "pres-${unks}.txt" using 5:(qty(column(13))) title "Torus pressure (kPa)"      with linespoints pt  6 ps 1.5 lw 1.8 lc rgb '#0088ff', \
  "pres-${unks}.txt" using 5:(qty(column(11))) title "Drywell pressure (kPa)"    with linespoints pt  7 ps 0.9 lw 1.8 lc rgb '#008800', \
  "pres-${unks}.txt" using 5:(qty(column(7)))  title "Core pressure A (kPa)"     with linespoints pt  6 ps 1.5 lw 1.8 lc rgb '#aa3300', \
  "pres-${unks}.txt" using 5:(qty(column(9)))  title "Core pressure B (kPa)"     with linespoints pt  7 ps 0.9 lw 1.8 lc rgb '#ff2200'
quit
EOF

convert ${tmp}.png -resize '50%' ${pngfile}

display ${pngfile}

rm -f ${tmp}.png
