#! /bin/bash -e
# Last edited on 2026-02-18 03:14:09 by stolfi

export GDFONTPATH="${HOME}/ttf"

pfile="out/plot.png"

gnuplot <<EOF
  set term png size 600,300 linewidth 2.0 font "Arial" 11 set term
  set output "${pfile}"
  set xrange [-1:+2]
  bgrd = 0.15
  rfunc(td) = sqrt(bgrd**2 + (td/2)**2)
  sfunc(td) = sqrt(bgrd**2 + ((1 - td)/2)**2)
  sgrd(td) = 0.5 + rfunc(td) - sfunc(td)
  
  bsim = 0.05
  ssim(td) = bsim/sqrt(bsim**2 + (td - 0.5)**2)
  set samples 1000
  plot \
    (sgrd(x)) title "sgrd" with lines lc rgb '#ff0000', \
    (ssim(x)) title "ssim" with lines lc rgb '#ff0000'
  quit
EOF


if [[ -s ${pfile} ]]; then
  display -title '%f' ${pfile}
else
  echo "** file ${pfile} not created" 1>&2; exit 1
fi

