#!/bin/csh -f

set datadir = '../../qc-correction'
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 NDATA = 11
set SDATA = 19
    

rm datafile

foreach xx (01 02 03 04 05 06 07 08 09 10 11)
  cat ${datadir}/P${xx}.csv >> datafile
end
$NKF -Lu --overwrite datafile
$FC calcmean-c.f
./a.out > meanN.csv

foreach xx (12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31)
  cat ${datadir}/P${xx}.csv >> datafile
end
$NKF -Lu --overwrite datafile
$FC calcmean-c.f
./a.out > meanS.csv

gnuplot <<EOF
set term png
set out "TmeanNS-qc-c.png"
unset key
unset colorbox
set datafile separator ","
set xdata time
set timefmt "%H:%M:%S"
set title "North (blue) and South (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 'meanN.csv' u 1:(\$3+${dT}):(1.96*\$4/((${NDATA}-1)**0.5)) with errorbars pt 5 ps 0.4 lc rgb "blue", 'meanS.csv' u 1:(\$3+${dT}):(1.96*\$4/((${SDATA}-1)**0.5)) with errorbars pt 5 ps 0.4 lc rgb "red"
EOF



#rm a.out datafile
rm a.out
