############################
# Display the temperature and the humidity values of a Oregon PCR800 rain gauge
#
# FileLog definition: 
# define <filelogname> FileLog /var/log/fhem/<devname>-%Y.log <devname>
# Filelog example:
# define FileLog_PCR800_7a FileLog /var/log/fhem/PCR800_7a-%Y.log PCR800_7a.*rain.*
#
# Logfile record example:
# 2010-08-16_19:44:34 PCR800_7a rain_rate: 0
# 2010-08-16_19:44:35 PCR800_7a rain_total: 2.08



set terminal png transparent size <SIZE> crop
set output '<OUT>.png'
set xdata time
set timefmt "%Y-%m-%d_%H:%M:%S"
set xlabel " "
set ytics nomirror
set y2tics
set title '<L1>'
set grid

set y2label "Rain rate mm/hr"
set format y "%0.1f"
set ylabel "Rain (l/m2)"
set yrange [0:]

# Computing Rain/h and Rain/d values by accumulating the changes.

#FileLog 4:rain_rate:0:
#FileLog 4:rain_total:0:delta-h
#FileLog 4:rain_total:0:delta-d

plot "< awk $3=="rain_rate:" {print $1, $4}' <IN>"\
     using 1:2 axes x1y2 title 'Rain Rate' with lines,\
     "<grep rain_total <IN> | perl -ane '\
        @a = split(\" \", $F[0]);\
        if(defined($lh) && $lh ne $a[1])\
          { printf(\"${ld}_$lh:30:00 %f\n\", $hv); $hv = 0; }\
        if($lv) { $hv += ($F[4]-$lv); }\
        $lh = $a[1]; $ld = $a[0]; $lv = $F[4];\
        END { printf(\"${ld}_$lh:30:00 %f\n\", $hv) }'"\
     using 1:2 axes x1y1 title 'Rain/h' with histeps,\
     "<grep rain_total <IN> | perl -ane '\
        @a = split(\" \", $F[0]);\
        if(defined($ld) && $ld ne $a[0]) {\
          printf(\"${ld}_12:00:00 %f\n\", $dv); $dv = 0; }\
          if($lv) { $dv += ($F[4]-$lv); }\
          $ld = $a[0]; $lv = $F[4];\
          END {printf(\"${ld}_12:00:00 %f\n\", $dv)}'"\
     using 1:2 axes x1y1 title 'Rain/day' with histeps
