#!/bin/csh -f

set datadir = '../../../csv'

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

set ndat = 121		

set NDATA = 11
set SDATA = 19

set prname = P
set psname = .csv

set dTdtMIN = -5
set dTdtMAX =  5


$FC dTdt.f
mv a.out dTdt.out
$FC dTdtmean.f
mv a.out dTdtmean.out

rm datafile dTdtall.dat
foreach xx (01 02 03 04 05 06 07 08 09 10 11)
  ln -s ${datadir}/${prname}${xx}${psname} datafile
  $NKF -Lu --overwrite datafile
  ./dTdt.out >> dTdtall.dat
  rm datafile
end
rm dTdtmeanN.dat
./dTdtmean.out > dTdtmeanN.dat
rm dTdtall.dat

rm datafile dTdtall.dat
foreach xx (12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31)
  ln -s ${datadir}/${prname}${xx}${psname} datafile
  $NKF -Lu --overwrite datafile
  ./dTdt.out >> dTdtall.dat
  rm datafile
end
rm dTdtmeanS.dat
./dTdtmean.out > dTdtmeanS.dat
rm dTdtall.dat


gnuplot <<EOF
set term png
set out "dTdtmeanNS.png"
unset key
unset colorbox
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 change rate (degree C / min)"
set yrange [-0.6:0.6]
#plot 'dTdtmeanN.dat' u 1:3:(1.96*\$4/((${NDATA}-1)**0.5)) with errorbars pt 5 ps 0.4 lc rgb "blue", 'dTdtmeanS.dat' u 1:3:(1.96*\$4/((${NDATA}-1)**0.5)) with errorbars pt 5 ps 0.4 lc rgb "red"
plot 'dTdtmeanN.dat' u 1:3 with linespoints pt 5 ps 0.4 lc rgb "blue", 'dTdtmeanS.dat' u 1:3 with linespoints pt 5 ps 0.4 lc rgb "red"
EOF

gnuplot <<EOF
set term png
set out "dTdtmeanN.png"
unset key
unset colorbox
set xdata time
set timefmt "%H:%M:%S"
set title "North (blue)"
set xrange ["09:30:00":"11:30:00"]
set format x "%H:%M"
set xlabel "Time"
set ylabel "Temperature change rate (degree C / min)"
set yrange [-0.6:0.6]
plot 'dTdtmeanN.dat' u 1:3:(1.96*\$4/((${NDATA}-1)**0.5)) with errorbars pt 5 ps 0.4 lc rgb "blue"
EOF

gnuplot <<EOF
set term png
set out "dTdtmeanS.png"
unset key
unset colorbox
set xdata time
set timefmt "%H:%M:%S"
set title "South (red)"
set xrange ["09:30:00":"11:30:00"]
set format x "%H:%M"
set xlabel "Time"
set ylabel "Temperature change rate (degree C / min)"
set yrange [-0.6:0.6]
plot 'dTdtmeanS.dat' u 1:3:(1.96*\$4/((${NDATA}-1)**0.5)) with errorbars pt 5 ps 0.4 lc rgb "red"
EOF
