#!/bin/csh -f

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

set dT = 0.0
#set dT = -0.3

set Tmax = 27
set Tmin = 20

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


cat ${datadir}/P*.csv > datafile
$NKF -Lu --overwrite datafile

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

gnuplot <<EOF
set term png
set out "Tmean.png"
unset key
unset colorbox
set datafile separator ","
set xdata time
set timefmt "%H:%M:%S"
set title "Mean of all station"
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 'mean.csv' u 1:(\$3+${dT}):4 with errorbars pt 5 ps 0.4 lc rgb "red", 'amedas.csv' u 1:5 w p pt 5 ps 2 lc rgb "blue"
EOF

gnuplot <<EOF
set term png
set out "Tsd.png"
unset key
unset colorbox
set datafile separator ","
set xdata time
set timefmt "%H:%M:%S"
#set title "Mean of all station"
set xrange ["09:30:00":"11:30:00"]
set format x "%H:%M"
set xlabel "Time"
set ylabel "Standard deviation (degree C)"
set yrange [0:2]
plot 'mean.csv' u 1:4 with points pt 5 ps 0.4 lc rgb "red"
EOF

gnuplot <<EOF
set term png
set out "WSmean.png"
unset key
unset colorbox
set datafile separator ","
set xdata time
set timefmt "%H:%M:%S"
set title "Mean of all station"
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:8]
plot 'mean.csv' u 1:5:6 with errorbars pt 5 ps 0.4 lc rgb "red", 'amedas.csv' u 1:7 w p pt 5 ps 2 lc rgb "blue", 'amedas.csv' u 1:9 w p pt 5 ps 2 lc rgb "cyan"
EOF


#rm a.out datafile
rm a.out
