#!/bin/bash
OUT=tmpfile.txt
cat $1 > $OUT
VAL=$(head -n1 $1 | awk '{print $3}')
echo -e "30\t30\t$VAL\n-30\t-30\t$VAL" >> $OUT
cat << EOF > gnutplt
#!/usr/bin/gnuplot
set contour
unset surface
set cntrparam order 4
set cntrparam bspline
#set cntrparam levels auto 6
#set cntrparam levels incremental -30,0.1,30
set view map
set size square
set xrange [-40:40]
set yrange [-40:40]
set dgrid3d 100,100,4
set table "contour.txt"
splot '$OUT' u 1:2:3
unset table
unset contour
set surface
set table "dgrid.txt"
splot '$OUT' u 1:2:3
unset table
reset
set terminal canvas enhanced mousing size 1024,768 jsdir 'js'
set output "$1.html"
set size square
set xrange [-30:30]
set yrange [-30:30]
set xlabel "X, dm"
set ylabel "Y, dm"
set title "Mirror temperature  $2"
set pm3d map
unset key
circle(x,y,z) = x**2+y**2 > 900 ? NaN : z
splot 'dgrid.txt' u 1:2:(circle(\$1,\$2,\$3)) w pm3d, 'contour.txt' u 1:2:(circle(\$1,\$2,\$3)) w l lc rgb "black", '$OUT' u 1:2:(circle(\$1,\$2,\$3)):3 with labels font ",8"
EOF

chmod 755 gnutplt
./gnutplt
