#!/bin/csh -f

set nobs = 26
set ndat = 121		

set prname = P
set psname = .csv
    

@ n = 1
rm datafile
while ( $n <= $nobs )
  set num = `printf "%02d" $n`

  ln -s ${prname}${num}${psname} datafile

gnuplot <<EOF
set term png
set out "temp.png"
unset key
unset colorbox
set datafile separator ","
set xdata time
set timefmt "%H:%M:%S"
set title "n = ${n}"
set xrange ["09:30:00":"11:30:00"]
set format x "%H:%M"
set xlabel "Time"
set yrange [16.5:24.5]
set ylabel "Temperature (degree C)"
set y2range [0:8]
set y2label "Wind speed (cat)"
plot "datafile" every ::6 using 1:2 w p pt 5 ps 0.4 lc rgb "red", "datafile" every ::6 using 1:4 w p pt 5 ps 0.4 lc rgb "blue" axes x1y2
EOF

  mv temp.png t-ws${num}.png

  @ n = $n + 1
  rm datafile
end

convert -delay 50 t-ws*.png t-ws.gif
rm t-ws*.png



@ n = 1
rm datafile
while ( $n <= $nobs )
  set num = `printf "%02d" $n`

  ln -s ${prname}${num}${psname} datafile

gnuplot <<EOF
set term png
set out "temp.png"
unset key
unset colorbox
set datafile separator ","
set xdata time
set timefmt "%H:%M:%S"
set title "n = ${n}"
set xrange ["09:30:00":"11:30:00"]
set format x "%H:%M"
set xlabel "Time"
set yrange [16.5:24.5]
set ylabel "Temperature (degree C)"
set y2range [0.5:8.5]
set y2label "Wind direction"
plot "datafile" every ::6 using 1:2 w p pt 5 ps 0.4 lc rgb "red", "datafile" every ::6 using 1:3 w p pt 5 ps 0.4 lc rgb "blue" axes x1y2
EOF

  mv temp.png t-wd${num}.png

  @ n = $n + 1
  rm datafile
end

convert -delay 50 t-wd*.png t-wd.gif
rm t-wd*.png
