#! /bin/bash
# Last edited on 2019-08-08 10:03:10 by jstolfi

namper="$1"; shift;

tmp="/tmp/$$"
tfile="${tmp}_t.png"

export GDFONTPATH="."
gnuplot <<EOF
  set term png truecolor size 800,800 font "arial,18"
  set size ratio -1
  set output "${tfile}"
  set xrange [-0.0005:1.0005]
  set yrange [-0.0005:1.0005]
  set xtics 0.1
  set format x ""
  set ytics 0.1
  set format y ""
  set nokey
  val(z) = ((z < 0) || (z > 1) ? 0/0 : z)
  plot \
    "out/${namper}.txt" using (val(column(3))):4 with points pt 7 ps 1.2 lc rgb '#cc0000', \
    "out/${namper}.txt" using (val(column(5))):6 with points pt 7 ps 2.0 lc rgb '#0077ff', \
    (x) with lines lw 2 lt 1 lc rgb '#88aa99', \
    (1-x) with lines lw 2 lt 1 lc rgb '#aa9988', \
    "out/${namper}.txt" using (val(column(1))):2 with lines lw 3 lt 1 lc rgb '#cc0000'
  quit
EOF

if [[ -s ${tfile} ]]; then
  convert ${tfile} -resize '50%' out/${namper}.png 
  display -title '%f' out/${namper}.png 
fi
