#!/bin/bash

tds=`date +%s` #today's date in sec. since 1 jan 1970
#mas=`expr $tds - 2592000` # date of 1 month ago in sec. since 1 jan 1970
mas=`expr $tds - 1000000`
da=` date --date='@'$mas'' +%Y%m%d ` # converts the date to a new format
db=`date +%Y%m%d` # today's date 

# the 3 arguments are the names of the ascii 
# databases of the meteo stations

f1=$1 
f2=$2
f3=$3


cat > plotta << EOF


set xdata time
set timefmt "%Y%m%d %H.%M"
#set format x "%m/%y"
set format x "%d/%m/%y"
set xrange ["$da 00.00" : "$db 23.30"]

set title "Solar radiation"
set ylabel 'W/m^2'
set xlabel 'Day'
set yrange [0:1000]
plot '$f1' u 1:19 w p, '$f2' u 1:19 w p, '$f3' u 1:19 w p
pause -1
set autoscale y

set title "UV radiation"
set ylabel 'UV index'
set xlabel 'Day'
set yrange [0:10]
plot '$f1' u 1:20 w p, '$f2' u 1:20 w p, '$f3' u 1:20 w p
pause -1
set autoscale y

set title "Outside Temperature (°C)"
set yrange [-10:40]
set ylabel 'T(degC)'
set xlabel 'Day'
plot '$f1' u 1:6 w p, '$f2' u 1:6 w p, '$f3' u 1:6 w p
pause -1
set autoscale y

set title "Wind speed (m/s)"
set ylabel 'Wind speed (m/s)'
set xlabel 'Day'
set yrange [0:10]
plot '$f1' u 1:9 w p, '$f2' u 1:9 w p, '$f3' u 1:9 w p
pause -1
set autoscale y

set title "Wind direction (deg/N)"
set ylabel 'Wind direction (deg/N)'
set xlabel 'Day'
plot '$f1' u 1:10 w p, '$f2' u 1:10 w p, '$f3' u 1:10 w p
pause -1

set title "Pressure (hPa)"
set yrange [800:1100]
set ylabel 'Pressure (hPa)'
set xlabel 'Day'
plot '$f1' u 1:4 w p, '$f2' u 1:4 w p, '$f3' u 1:4 w p
pause -1
set autoscale y

EOF

gnuplot plotta
rm plotta 

exit
