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

# Plots radiation levels 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=572

pngfile="out/plot-cams-${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 readings:
ymin = 0.12     # Min plot radiation (Sv/h).
ymax = 750.0    # Max plot radiation (Sv/h).

yelo = ymin*1.05  # Min ordinate of event bar (Sv/h).
yehi = ymax/1.05  # Max ordinate of event bar (Sv/h).

ytopscale = 99999.0   # Assumed top of instrument's scale (Sv/h).
ybotscale = 0.000001  # Assumed bottom of instrument's scale (Sv/h).

# Ordinate of explosion and smoke mark (Sv/h):
boomord = 1.0

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

set logscale y; set logscale y2
set ytics ( \
  0.001, \
  0.002, \
  0.005, \
  0.01, \
  0.02, \
  0.05, \
  0.1, \
  0.2, \
  0.5, \
  1, \
  2, \
  5, \
  10, \
  20, \
  50, \
  100, \
  200, \
  500, \
  1000, \
  2000, \
  5000 \
)
set y2tics ( \
  0.001, \
  0.002, \
  0.005, \
  0.01, \
  0.02, \
  0.05, \
  0.1, \
  0.2, \
  0.5, \
  1, \
  2, \
  5, \
  10, \
  20, \
  50, \
  100, \
  200, \
  500, \
  1000, \
  2000, \
  5000 \
)
set mytics 2; set my2tics 2
set format y "%g"
set format y2 "%-g"
set grid mytics
# set xzeroaxis linetype -1 linewidth 1.5
plot \
  "boom-${unk}.txt"  using 5:(eum(column(7))):(yelo):(yehi) notitle                   with yerrorbars  pt 13 ps 2.0 lw 6.0 lc rgb '#ffaaaa', \
  "boom-${unk}.txt"  using 5:(tum(column(7))):(yelo):(yehi) notitle                   with yerrorbars  pt 13 ps 2.0 lw 6.0 lc rgb '#aaaaff', \
  "boom-${unk}.txt"  using 5:(bum(column(7))):(yelo):(yehi) notitle                   with yerrorbars  pt 13 ps 2.0 lw 6.0 lc rgb '#ff8844', \
  "boom-${unk}.txt"  using 5:(fum(column(7))):(yelo):(yehi) notitle                   with yerrorbars  pt  7 ps 0.0 lw 8.0 lc rgb '#ccbbaa', \
  "cams-${unks}.txt" using 5:(qty(column(7))/100)  title "Drywell radiation A (Sv/h)" with linespoints pt  6 ps 1.5 lw 1.8 lc rgb '#ee9900', \
  "cams-${unks}.txt" using 5:(qty(column(9))/100)  title "Drywell radiation B (Sv/h)" with linespoints pt  7 ps 0.9 lw 1.8 lc rgb '#cc8800', \
  "cams-${unks}.txt" using 5:(qty(column(11))/100) title "Torus radiation A (Sv/h)"   with linespoints pt  6 ps 1.5 lw 1.8 lc rgb '#ff0088', \
  "cams-${unks}.txt" using 5:(qty(column(13))/100) title "Torus radiation B (Sv/h)"   with linespoints pt  7 ps 0.9 lw 1.8 lc rgb '#aa0088'
quit
EOF

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

display ${pngfile}

rm -f ${tmp}.png
