#!/bin/csh -f

set datadir = '../../../csv'
set amedas  = 'amedas.dat'

set dT = 0.0
#set dT = -0.3

set Tmax = 27
set Tmin = 18

set NKF = '/usr/bin/nkf'
set FC  = '/usr/bin/gfortran'

set ADATA = 8
set GDATA = 8
    

rm datafile

foreach xx (01 02 08 15 18 19 29 30)
  cat ${datadir}/P${xx}.csv >> datafile
end
$NKF -Lu --overwrite datafile

$FC calcmean.f
./a.out > meanA.csv

foreach xx (05 12 13 20 23 24 26 27)
  cat ${datadir}/P${xx}.csv >> datafile
end
$NKF -Lu --overwrite datafile

$FC calcmean.f
./a.out > meanG.csv

gnuplot <<EOF
set term png
set out "TmeanAG.png"
unset key
unset colorbox
set datafile separator ","
set xdata time
set timefmt "%H:%M:%S"
set title "Grass (blue) and Asphalt (red)"
set xrange ["09:30:00":"11:30:00"]
set format x "%H:%M"
set xlabel "Time"
set ylabel "Temperature (degree C)"
set yrange [${Tmin}:${Tmax}]
#plot 'meanN.csv' u 1:(\$3+${dT}):4 with errorbars pt 5 ps 0.4 lc rgb "blue", 'meanS.csv' u 1:(\$3+${dT}):4 with errorbars pt 5 ps 0.4 lc rgb "red"
plot 'meanG.csv' u 1:(\$3+${dT}):(1.96*\$4/((${GDATA}-1)**0.5)) with errorbars pt 5 ps 0.4 lc rgb "blue", 'meanA.csv' u 1:(\$3+${dT}):(1.96*\$4/((${ADATA}-1)**0.5)) with errorbars pt 5 ps 0.4 lc rgb "red"
EOF

gnuplot <<EOF
set term png
set out "WSmeanAG.png"
unset key
unset colorbox
set datafile separator ","
set xdata time
set timefmt "%H:%M:%S"
set title "Grass (blue) and Asphalt (red)"
set xrange ["09:30:00":"11:30:00"]
set format x "%H:%M"
set xlabel "Time"
set ylabel "Wind speed (m/s)"
set yrange [0:2]
plot 'meanG.csv' u 1:5:(1.96*\$6/((${GDATA}-1)**0.5)) with errorbars pt 5 ps 0.4 lc rgb "blue", 'meanA.csv' u 1:5:(1.96*\$6/((${ADATA}-1)**0.5)) with errorbars pt 5 ps 0.4 lc rgb "red"
EOF


#rm a.out datafile
rm a.out
