#!/bin/sh
set -x

. $HOME/PlotsOfTheDay/LONLAT.def

nowdtg=`date -u +"%Y%m%d%H"`
nowdate=`$HOME/bin/mandtg -date $nowdtg`
nowhour=`$HOME/bin/mandtg -hour $nowdtg`
if [ $nowhour -lt 2 ]
then
   basedtg=`$HOME/bin/mandtg $nowdtg + -48`
else
   basedtg=`$HOME/bin/mandtg $nowdtg + -24`
fi
basedtg=`$HOME/bin/mandtg -date $basedtg`18
baseyyyy=`$HOME/bin/mandtg -year $basedtg`
basemm=`$HOME/bin/mandtg -month $basedtg`
basedd=`$HOME/bin/mandtg -day $basedtg`
basehh=`$HOME/bin/mandtg -hour $basedtg`
[ -r /data/hirlam/hl_arc/OPR/$baseyyyy/$basemm/$basedd/$basehh/fc$baseyyyy$basemm${basedd}_${basehh}+0${FL}ve ] || exit # Run not finished yet.
ls -1t $HOME/public_html/$basedtg/* $HOME/public_html/${nowdate}??/* | head -1 | grep index                     && exit # Nothing new to process.
echo $0 - DTG of last full run: $basedtg

wd=/data/hirlam/WD$$
mkdir $wd || exit
cd $wd || exit

html=$HOME/public_html
todir=$html/$basedtg
mkdir $todir

# Get the list of regions for which to produce graphs.

grep -v '^#' > region.list <<EOF
# Name                    LAT    LON  SIZE TZ
MeetmastCabauw            51.970 4.926 3    1
AaEnMaas                  51.7   5.6   5    1
AmstelGooiEnVecht         52.3   5.2   5    1
BrabantseDelta            51.6   4.7   5    1
DeDommel                  51.5   5.1   5    1
Delfland                  51.9   4.5   5    1
DeStichtseRijnlanden      52.1   5.2   5    1
DrentsOverijselseDelta    52.2   6.1   5    1
HollandseDelta            51.8   4.4   5    1
HollandsNoorderkwartier   52.7   4.8   5    1
HunzeEnAas                53.1   6.9   5    1
NoorderZijlvest           53.3   6.5   5    1
RijnEnIJssel              52.1   6.5   5    1
Rijnland                  52.3   4.6   5    1
Rivierenland              51.8   5.2   5    1
ScheldeStromen            51.5   3.8   5    1
SchielandEnKrimpenerwaard 51.9   4.5   5    1
ValleiEnVeluwe            52.2   5.7   5    1
VechtStromen              52.6   6.7   5    1
WaterschapLimburg         51.4   6.0   5    1
WetterskipFryslan         53.2   5.8   5    1
Zuiderzeeland             52.6   5.5   5    1
Leverkusen                51.0   7.0   3    1
# Prague                  50.1  14.4   3    1
# Vilnius                 54.68 25.28  3
# Norrkoping              58.6  16.2   3    1
# Copenhagen              55.67 12.56  3    1
Reading                   51.45 -0.97  3    0
Exeter                    50.75 -3.51  3    0
# Cambridge               52.2   0.1   3    0
Madrid                    40.40 -3.75  3    1
# Toulouse                43.6   1.4   3
# Oslo                    59.9  10.75  3    1
# Marrakech               31.6  -8.0   3
Dublin                  53.376 -6.270  3    0
# Reykjavik               64.1 -22.0   3    0
# London                  51.52 -0.12  3    0
# Manchester              53.5  -2.25  3    0
# Bratislava              48.14 17.11  3
# Delft                   52.1   4.8   3
# Garching                48.3  11.6   3
# Cork			  51.9  -8.5   5    0
# Philippi                41.0  24.3   3    2
Moscow                    55.75 37.6   3    3
EastJerusalem             31.75 35.21  3    2
# GooseBay                53.4 -60.2   3   -4
EOF

regionlist=`awk '{print $1}' region.list`

# Set up the links to the observation files.

ln -sf $todir/SYNOP18.txt fort.10
ln -sf $todir/SYNOP19.txt fort.11
ln -sf $todir/SYNOP20.txt fort.12
nextdtg=`$HOME/bin/mandtg $basedtg + 6`            # 00 UTC
nextdir=$html/$nextdtg
ln -sf $nextdir/SYNOP21.txt fort.13
ln -sf $nextdir/SYNOP22.txt fort.14
ln -sf $nextdir/SYNOP23.txt fort.15
ln -sf $nextdir/SYNOP00.txt fort.16
ln -sf $nextdir/SYNOP01.txt fort.17
ln -sf $nextdir/SYNOP02.txt fort.18
nextdtg=`$HOME/bin/mandtg $nextdtg + 6`            # 06 UTC
nextdir=$html/$nextdtg
if [ -r $nextdir ]
then
   ln -sf $nextdir/SYNOP03.txt fort.19
   ln -sf $nextdir/SYNOP04.txt fort.20
   ln -sf $nextdir/SYNOP05.txt fort.21
   ln -sf $nextdir/SYNOP06.txt fort.22
   ln -sf $nextdir/SYNOP07.txt fort.23
   ln -sf $nextdir/SYNOP08.txt fort.24
fi
nextdtg=`$HOME/bin/mandtg $nextdtg + 6`            # 12 UTC
nextdir=$html/$nextdtg
if [ -r $nextdir ]
then
   ln -sf $nextdir/SYNOP09.txt fort.25
   ln -sf $nextdir/SYNOP10.txt fort.26
   ln -sf $nextdir/SYNOP11.txt fort.27
   ln -sf $nextdir/SYNOP12.txt fort.28
   ln -sf $nextdir/SYNOP13.txt fort.29
   ln -sf $nextdir/SYNOP14.txt fort.30
fi
nextdtg=`$HOME/bin/mandtg $nextdtg + 6`            # 18 UTC
nextdir=$html/$nextdtg
if [ -r $nextdir ]
then
   ln -sf $nextdir/SYNOP15.txt fort.31
   ln -sf $nextdir/SYNOP16.txt fort.32
   ln -sf $nextdir/SYNOP17.txt fort.33
   ln -sf $nextdir/SYNOP18.txt fort.34
   ln -sf $nextdir/SYNOP19.txt fort.35
   ln -sf $nextdir/SYNOP20.txt fort.36
fi
nextdtg=`$HOME/bin/mandtg $nextdtg + 6`            # 00 UTC
nextdir=$html/$nextdtg
if [ -r $nextdir ]
then
   ln -sf $nextdir/SYNOP21.txt fort.37
   ln -sf $nextdir/SYNOP22.txt fort.38
   ln -sf $nextdir/SYNOP23.txt fort.39
   ln -sf $nextdir/SYNOP00.txt fort.40
   ln -sf $nextdir/SYNOP01.txt fort.41
   ln -sf $nextdir/SYNOP02.txt fort.42
fi

# Feed the region list (list of areas) to the Fortran program that constructs the time series.

(\
   echo ' &REGIONLIST'; \
   awk '{print " regname(" FNR ")=\"" $1 "\",reglat(" FNR ")=" $2 ",reglon(" FNR ")=" $3 ",nregside(" FNR ")=" $4}' region.list; \
   echo ' /'          \
)\
   | $HOME/PlotsOfTheDay/timeseries $basedtg || exit

# rm EastJerusalem.*-obs # Weird observations - have to investigate.

# Construct the map of land use at the beginning of the forecast shown here.

[ -s $todir/landuse.png ] || $HOME/PlotsOfTheDay/LandUse $basedtg

cp $HOME/PlotsOfTheDay/index.html tmp.html
echo "<H1 ALIGN=CENTER>Verwachting vanaf $basedtg UTC</H1>" >> tmp.html

echo "<TABLE ALIGN=CENTER CELLSPACING=5 BORDER=5>" >> tmp.html

echo "<TR><TH COLSPAN=4>Landgebruikgegevens aan het begin van de verwachting</TH></TR>" \
         "<TR><TD><A HREF=/~hirlam/$basedtg/landuse.png>PNG</A></TD>" \
         "    <TD><A HREF=/~hirlam/$basedtg/landuse.ps>PS</A></TD>" \
         "    <TD><A HREF=/~hirlam/LandUse>Hoe wordt deze kaart gemaakt</A></TD>" \
         "    <TD><A HREF=/~hirlam/landuse>Hoe wordt landgebruik bepaald</A></TD></TR>" >> tmp.html

echo "</TABLE>" >> tmp.html

# Construct the table of animations of the forecast.

echo "<H2 ALIGN=CENTER> <A NAME=Animaties>Animaties</A></H2>" >> tmp.html

echo "<TABLE ALIGN=CENTER CELLSPACING=5 BORDER=5>" >> tmp.html

echo "<TR><TH ALIGN=CENTER COLSPAN=4>Lokaal</TH></TR>" \
         "<TR ALIGN=CENTER><TD><A HREF=/~hirlam/$basedtg/rad1-$FL.png>'Neerslagradar'</A></TD>" \
             "<TD><A HREF=/~hirlam/$basedtg/bew0-$FL.png>Bewolking</A></TD>"       \
             "<TD><A HREF=/~hirlam/$basedtg/zicht0-$FL.png>Zicht</A></TD>"         \
             "<TD><A HREF=/~hirlam/$basedtg/w10m0-$FL.png>Wind</A></TD></TR>"      >> tmp.html
echo     "<TR ALIGN=CENTER><TD><A HREF=/~hirlam/$basedtg/t2m0-$FL.png>Temperatuur</A></TD>"     \
             "<TD><A HREF=/~hirlam/$basedtg/latw0-$FL.png>Latente Warmte</A></TD>"     \
             "<TD><A HREF=/~hirlam/$basedtg/voelw0-$FL.png>Voelbare Warmte</A></TD>" \
             "<TD></TD></TR>" >> tmp.html
echo "<TR><TH ALIGN=CENTER COLSPAN=4>Klassiek</TH></TR>" \
         "<TR ALIGN=CENTER><TD><A HREF=/~hirlam/$basedtg/pmsl-w10m0-$FL.png>Luchtdruk en wind</A></TD>"                 \
             "<TD><A HREF=/~hirlam/$basedtg/z500-jet0-$FL.png>Straalstroom en hoogte 500hPa vlak</A></TD>" \
             "<TD></TD><TD></TD></TR>"                                                           >> tmp.html
echo "<TR><TH ALIGN=CENTER COLSPAN=4>Bewegings- en potenti&euml;le energie</TH></TR>" \
         "<TR ALIGN=CENTER><TD><A HREF=/~hirlam/$basedtg/wspd0-$FL.png>Windsnelheid</A></TD>"                            \
             "<TD><A HREF=/~hirlam/$basedtg/gusts0-$FL.png>Windstoten</A></TD>"                           \
             "<TD><A HREF=/~hirlam/$basedtg/cape0-$FL.png>Convective Available Potential Energy</A></TD>" \
             "<TD></TD></TR>"                                                                   >> tmp.html
echo "<TR><TH ALIGN=CENTER COLSPAN=4>Waterhuishouding</TH></TR>" \
         "<TR ALIGN=CENTER><TD><A HREF=/~hirlam/$basedtg/cl0-$FL.png>Wolken</A></TD>"             \
             "<TD><A HREF=/~hirlam/$basedtg/rr1-$FL.png>Neerslag/Soort</A></TD>"     \
             "<TD><A HREF=/~hirlam/$basedtg/vis0-$FL.png>Zicht</A></TD>"             \
             "<TD><A HREF=/~hirlam/$basedtg/snh0-$FL.png>Sneeuwhoogte</A></TD></TR>" >> tmp.html
echo "<TR><TH ALIGN=CENTER COLSPAN=4>Opwarming en afkoeling</TH></TR>" \
         "<TR ALIGN=CENTER><TD><A HREF=/~hirlam/$basedtg/temp0-$FL.png>Temperatuur</A></TD>"           \
             "<TD><A HREF=/~hirlam/$basedtg/lat0-$FL.png>Latente warmtestroom</A></TD>"   \
             "<TD><A HREF=/~hirlam/$basedtg/sens0-$FL.png>Voelbare warmtestroom</A></TD>" \
             "<TD></TD></TR>"                                                   >> tmp.html
echo "<TR><TH ALIGN=CENTER COLSPAN=4>'Satelliet' beelden</TH></TR>" \
         "<TR ALIGN=CENTER><TD><A HREF=/~hirlam/$basedtg/ctt0-$FL.png>Wolkentoptemperatuur</A></TD>"               \
             "<TD><A HREF=/~hirlam/$basedtg/wv0-$FL.png>Waterdamp</A></TD>"                           \
             "<TD><A HREF=/~hirlam/$basedtg/wvclcorr0-$FL.png>Waterdamp met wolkencorrectie</A></TD>" \
             "<TD><A HREF=/~hirlam/$basedtg/cw0-$FL.png>Wolkenwater fractie</A></TD></TR>"            >> tmp.html

echo "</TABLE>" >> tmp.html

# Construct the table of "weercijfers" for the areas predicted by this forecast.

echo "<H2 ALIGN=CENTER> <A NAME=Weercijfers>Weercijfers</A></H2>" >> tmp.html

echo "<TABLE ALIGN=CENTER CELLSPACING=5 BORDER=5>" >> tmp.html
echo "<TR><TH>Locatie/Waterschap</TH>" \
     "<TH>Breedtegraad</TH>" \
     "<TH>Lengtegraad</TH>" \
     "<TH>Tijdzone</TH>" \
     "<TH>Roostercellen</TH>" \
     "<TH>Vandaag</TH>" \
     "<TH>Morgen</TH>" \
        >> tmp.html
if [ $FL -eq 78 ]
then
   echo "<TH>Overmorgen</TH>" >> tmp.html
fi
echo "</TR>" >> tmp.html

for area in $regionlist
do
   lat=`grep ^$area region.list | awk '{print $2}'`
   lon=`grep ^$area region.list | awk '{print $3}'`
   size=`grep ^$area region.list | awk '{print $4}'`
   tz=`grep ^$area region.list | awk '{print $5}'`
   echo "<TR><TD>$area</TD>" \
        "<TD ALIGN=CENTER>$lat</TD>" \
        "<TD ALIGN=CENTER>$lon</TD>" \
        "<TD ALIGN=CENTER>$tz</TD>" \
        "<TD ALIGN=CENTER>$size x $size</TD>" \
        "<TD ALIGN=CENTER>`cat $area.WEERCIJFER | awk -F, '{print $1}'`</TD>" \
        "<TD ALIGN=CENTER>`cat $area.WEERCIJFER | awk -F, '{print $2}'`</TD>" \
        >> tmp.html
if [ $FL -eq 78 ]
then
   echo "<TD ALIGN=CENTER>`cat $area.WEERCIJFER | awk -F, '{print $3}'`</TD>" >> tmp.html
fi
echo "</TR>" >> tmp.html
done
echo "</TABLE>" >> tmp.html

# Construct the table of recent logs of computations and maps of observations used.

echo "<H2 ALIGN=CENTER> <A NAME=LogsEnWaarnemingen>Logs van de berekeningen en overzicht van de waarnemingen</A></H2>" >> tmp.html

echo "<TABLE ALIGN=CENTER CELLSPACING=5 BORDER=5>" >> tmp.html
now=`date -u +"%Y%m%d"`
for HH in `seq -w 0 6 18`
do
   dtgobs=$now$HH
   [ -r $html/$dtgobs/observations$HH.png ] || dtgobs=`$HOME/bin/mandtg $dtgobs + -24`
   DATEobs=`$HOME/bin/mandtg -date $dtgobs`
   dtglog=$now$HH
   [ -r $html/$dtglog/HL_Cycle_$dtglog.html ] || dtglog=`$HOME/bin/mandtg $dtglog + -24`
   DATElog=`$HOME/bin/mandtg -date $dtglog`
   logfile=${DATElog}${HH}/HL_Cycle_${DATElog}${HH}.html
   echo "<TR><TH ROWSPAN=7>$HH UTC</TH></TR>"                                              >> tmp.html
   echo "<TR><TD>`export TZ=UTC; ls -l --time-style=+"%Y%m%d%H%M%S" /data/hirlam/hl_arc/OPR/ob$dtgobs | awk '{print $6}'` UTC</TD>" >> tmp.html
   echo "<TD><A HREF=/~hirlam/Observations>Ingekomen</A> <A HREF=/~hirlam/decode-eccodes>waarnemingen</A></TD>" >> tmp.html
   for h in -3 -2 -1 +0 +1 +2
   do
      dtgoff=`$HOME/bin/mandtg $dtgobs + $h`
      houroff=`$HOME/bin/mandtg -hour $dtgoff`
      echo "<TD>${h}H <A HREF=/~hirlam/${DATEobs}${HH}/observations$houroff.png>PNG</A> " >> tmp.html
      echo "<A HREF=/~hirlam/${DATEobs}${HH}/observations$houroff.ps>PS</A></TD>"         >> tmp.html
   done
   if [ $HH -eq 0 ]
   then
      echo "<TD>Gebruikt</TD><TD>Redundant</TD><TD>Verworpen</TD>" >> tmp.html
   else
      echo "<TD></TD><TD></TD><TD></TD>"                             >> tmp.html
   fi
   echo "</TR>" >> tmp.html
   echo "<TR><TD><A HREF=/~hirlam/$logfile>`export TZ=UTC; ls -l --time-style=+"%Y%m%d%H%M%S" $html/$logfile | awk '{print $6}'` LOG</A></TD>" >> tmp.html
   echo "<TD><A HREF=/~hirlam/UseOfASCAT>Verwerking</A> <A HREF=/~hirlam/use-ascat>ASCAT</A></TD>" >> tmp.html
   for h in -3 -2 -1 +0 +1 +2
   do
      dtgoff=`$HOME/bin/mandtg $dtglog + $h`
      houroff=`$HOME/bin/mandtg -hour $dtgoff`
      if [ -s $html/$dtglog/use_ascat$houroff.png ]
      then
         echo "<TD>${h}H <A HREF=/~hirlam/${DATElog}${HH}/use_ascat$houroff.png>PNG</A> " >> tmp.html
         echo "<A HREF=/~hirlam/${DATElog}${HH}/use_ascat$houroff.ps>PS</A></TD>"         >> tmp.html
      else
         echo "<TD></TD>"                                                        >> tmp.html
      fi
   done
   used=`awk '{print $1}' $html/$dtglog/ASCAT_COUNT.txt`; rejected=`awk '{print $2}' $html/$dtglog/ASCAT_COUNT.txt`
   echo "<TD align=right style='color:green;'>$used</TD><TD></TD><TD align=right style='color:red;'>$rejected</TD>" >> tmp.html
   echo "</TR>" >> tmp.html
   echo "<TR><TD><A HREF=/~hirlam/${DATElog}${HH}/minimization$HH.png>Effect waarnemingen</A></TD>" >> tmp.html
   echo "<TD><A HREF=/~hirlam/UseOfAIREP>Verwerking</A> <A HREF=/~hirlam/use-airep>AIREP/AMDAR</A></TD>" >> tmp.html
   for h in -3 -2 -1 +0 +1 +2
   do
      dtgoff=`$HOME/bin/mandtg $dtglog + $h`
      houroff=`$HOME/bin/mandtg -hour $dtgoff`
      if [ -s $html/$dtglog/use_airep$houroff.png ]
      then
         echo "<TD>${h}H <A HREF=/~hirlam/${DATElog}${HH}/use_airep$houroff.png>PNG</A> " >> tmp.html
         echo "<A HREF=/~hirlam/${DATElog}${HH}/use_airep$houroff.ps>PS</A></TD>"         >> tmp.html
      else
         echo "<TD></TD>"                                                        >> tmp.html
      fi
   done
   used=`awk '{print $1}' $html/$dtglog/AIREP_COUNT.txt`; redundant=`awk '{print $2}' $html/$dtglog/AIREP_COUNT.txt`; rejected=`awk '{print $3}' $html/$dtglog/AIREP_COUNT.txt`
   echo "<TD align=right style='color:green;'>$used</TD><TD align=right style='color:orange;'>$redundant</TD><TD align=right style='color:red;'>$rejected</TD>" >> tmp.html
   echo "</TR>" >> tmp.html
   echo "<TR><TD><A HREF=/~hirlam/${DATElog}${HH}/dpsdt$HH.png>Druktendens</A></TD>" >> tmp.html
   echo "<TD><A HREF=/~hirlam/UseOfSOUNDING>Verwerking</A> <A HREF=/~hirlam/use-temp>TEMP</A>/<A HREF=/~hirlam/use-pilot>PILOT</A></TD>"  >> tmp.html
   for h in -3 -2 -1 +0 +1 +2
   do
      dtgoff=`$HOME/bin/mandtg $dtglog + $h`
      houroff=`$HOME/bin/mandtg -hour $dtgoff`
      if [ -s $html/$dtglog/use_temp$houroff.png ]
      then
         echo "<TD>${h}H <A HREF=/~hirlam/${DATElog}${HH}/use_temp$houroff.png>PNG</A> "  >> tmp.html
         echo "<A HREF=/~hirlam/${DATElog}${HH}/use_temp$houroff.ps>PS</A></TD>"          >> tmp.html
      else
         echo "<TD></TD>"                                                        >> tmp.html
      fi
   done
   usedt=`awk '{print $1}' $html/$dtglog/TEMP_COUNT.txt`; rejectedt=`awk '{print $2}' $html/$dtglog/TEMP_COUNT.txt`
   usedp=`awk '{print $1}' $html/$dtglog/PILOT_COUNT.txt`; rejectedp=`awk '{print $2}' $html/$dtglog/PILOT_COUNT.txt`
   used=`expr $usedt \+ $usedp`; rejected=`expr $rejectedt \+ $rejectedp`
   echo "<TD align=right style='color:green;'>$used</TD><TD></TD><TD align=right style='color:red;'>$rejected</TD>" >> tmp.html
   echo "</TR>" >> tmp.html
   echo "<TR><TD><A HREF=/~hirlam/${DATElog}${HH}/wind$HH.png>Maximum wind</A></TD>" >> tmp.html
   echo "<TD><A HREF=/~hirlam/UseOfOTHERS>Verwerking</A> <A HREF=/~hirlam/use-synop>SYNOP</A>/<A HREF=/~hirlam/use-ship>SHIP</A>/<A HREF=/~hirlam/use-dribu>DRIBU</A></TD>" >> tmp.html
   for h in -3 -2 -1 +0 +1 +2
   do
      dtgoff=`$HOME/bin/mandtg $dtglog + $h`
      houroff=`$HOME/bin/mandtg -hour $dtgoff`
      if [ -s $html/$dtglog/use_other$houroff.png ]
      then
         echo "<TD>${h}H <A HREF=/~hirlam/${DATElog}${HH}/use_other$houroff.png>PNG</A> " >> tmp.html
         echo "<A HREF=/~hirlam/${DATElog}${HH}/use_other$houroff.ps>PS</A></TD>"         >> tmp.html
      else
         echo "<TD></TD>"                                                        >> tmp.html
      fi
   done
   used1=`awk '{print $1}' $html/$dtglog/SYNOP_COUNT.txt`; redundant1=`awk '{print $2}' $html/$dtglog/SYNOP_COUNT.txt`; rejected1=`awk '{print $3}' $html/$dtglog/SYNOP_COUNT.txt`
   used2=`awk '{print $1}' $html/$dtglog/SHIP_COUNT.txt`;  redundant2=`awk '{print $2}' $html/$dtglog/SHIP_COUNT.txt`;  rejected2=`awk '{print $3}' $html/$dtglog/SHIP_COUNT.txt`
   used3=`awk '{print $1}' $html/$dtglog/DRIBU_COUNT.txt`; redundant3=`awk '{print $2}' $html/$dtglog/DRIBU_COUNT.txt`; rejected3=`awk '{print $3}' $html/$dtglog/DRIBU_COUNT.txt`
   used=`expr $used1 \+ $used2 \+ $used3`; redundant=`expr $redundant1 \+ $redundant2 \+ $redundant3`; rejected=`expr $rejected1 \+ $rejected2 \+ $rejected3`
   echo "<TD align=right style='color:green;'>$used</TD><TD align=right style='color:orange;'>$redundant</TD><TD align=right style='color:red;'>$rejected</TD>" >> tmp.html
   echo "</TR>" >> tmp.html
   echo "<TR><TD>Oppervlakte <A HREF=/~hirlam/${DATEobs}${HH}/use_span00.png>PNG</A> <A HREF=/~hirlam/${DATEobs}${HH}/use_span00.ps>PS</A></TD>" >> tmp.html
   echo "<TD><A HREF=/~hirlam/UseOfSPAN>Verwerking</A> <A HREF=/~hirlam/use-span>waarnemingen</A></TD>" >> tmp.html
   for h in -3 -2 -1 +0 +1 +2
   do
      dtgoff=`$HOME/bin/mandtg $dtgobs + $h`
      houroff=`$HOME/bin/mandtg -hour $dtgoff`
      if [ -s $html/$dtglog/use_span$houroff.png ]
      then
         echo "<TD>${h}H <A HREF=/~hirlam/${DATEobs}${HH}/use_span$houroff.png>PNG</A> " >> tmp.html
         echo "<A HREF=/~hirlam/${DATEobs}${HH}/use_span$houroff.ps>PS</A></TD>"         >> tmp.html
      else
         echo "<TD></TD>"                                                        >> tmp.html
      fi
   done
   used=`awk '{print $1}' $html/$dtglog/SPAN_COUNT.txt`; rejected=`awk '{print $2}' $html/$dtglog/SPAN_COUNT.txt`
   echo "<TD align=right style='color:green;'>$used</TD><TD></TD><TD align=right style='color:red;'>$rejected</TD>" >> tmp.html
   echo "</TR>" >> tmp.html
done
echo "</TABLE>" >> tmp.html

echo "<P ALIGN=CENTER>" \
     "De ingekomen waarnemingen zijn gekleurd naar hoogte volgens het <A HREF=http://www.mrao.cam.ac.uk/~dag/CUBEHELIX/>cubehelix algoritme</A>. " \
     "De verwerkte waarnemingen zijn gekleurd volgens de behandeling (<b style='color:green;'>gebruikt</b>, <b style='color:orange;'>redundant</b> of <b style='color:red;'>verworpen</b>)." \
     "</P>"     >> tmp.html

# Show the evolution of the distance of the model to the observations at the start of data assimilation

echo "<H2 ALIGN=CENTER> <A NAME=J0>Ontwikkeling afstand tot de waarnemingen over de afgelopen 30 dagen.</A></H2>"                               >> tmp.html

echo "<TABLE ALIGN=CENTER CELLSPACING=5 BORDER=5>"                                                                                              >> tmp.html
echo "<TR><TH COLSPAN=2>Afstand tot de waarnemingen aan het begin van de minimalisatie</TH></TR>"                                               >> tmp.html
echo "<TR>"                                                                                                                                     >> tmp.html
echo "<TD><A HREF=/~hirlam/`cd $HOME/public_html/ && ls -1t 20????????/J0.png | head -1`>Beginwaarde afstand</A></TD>"                          >> tmp.html
echo "<TD><A HREF=/~hirlam/InitialCostFunction>Hoe dit te bepalen</A></TD>"                                                                     >> tmp.html
echo "</TR>"                                                                                                                                    >> tmp.html
echo "</TABLE>"                                                                                                                                 >> tmp.html

echo "<P ALIGN=CENTER>" \
     "Deze afstand geeft aan in hoeverre het model in 6 uur tijd verwijderd is geraakt van de werkelijkheid," \
     "en is dus een maat voor de (on)voorspelbaarheid van de atmosfeer in die tijdspanne." \
     "</P>"     >> tmp.html

# Construct the table of verification data over the past 30 days.

echo "<H2 ALIGN=CENTER> <A NAME=Verificatie>Verificatie over de afgelopen 30 dagen</A></H2>" >> tmp.html

. $HOME/hl_home/OPR/progressPP.log
verifdtg=`$HOME/bin/mandtg $DTGPP + -6`

echo "<TABLE ALIGN=CENTER CELLSPACING=5 BORDER=5>" >> tmp.html

echo "<TR><TH COLSPAN=14>Oppervlak (tijdreeks) - Nederland</TH></TR>" >> tmp.html
for par in pmsl w10m t2m td2m rh2m cc rr06 rr12 rr24
do
   echo "<TR><TD>${par^^}</TD>"                                       >> tmp.html
   for fp in `seq -w 6 6 $FL`
   do
      file=$verifdtg/verif_time-${par}-${fp}.png
      if [ -s $html/$file ]
      then
         echo "<TD><A HREF=/~hirlam/$file>+$fp</A></TD>"              >> tmp.html
      else
         echo "<TD></TD>"                                             >> tmp.html
      fi
   done
   echo "</TR>"                                                       >> tmp.html
done

echo "<TR><TH COLSPAN=9>Oppervlak (geaggregeerd) - Nederland</TH></TR>"        >> tmp.html
echo "<TR>"                                                                    >> tmp.html
for par in pmsl w10m t2m td2m rh2m cc rr06 rr12 rr24
do
   echo "<TD><A HREF=/~hirlam/$verifdtg/verif_aggr-$par.png>${par^^}</A></TD>" >> tmp.html
done
echo "</TR>"                                                                   >> tmp.html

echo "<TR><TH COLSPAN=6>Bovenlucht (geaggregeerd) - Europa</TH></TR>"                           >> tmp.html
for level in 250 500 700 850 925 1000
do
   echo "<TR>"                                                                                  >> tmp.html
   echo "<TD>$level hPa</TD>"                                                                   >> tmp.html
   for par in wind temp dewp geop relh
   do
      echo "<TD><A HREF=/~hirlam/$verifdtg/verif_aggr-${par:0:1}${level}.png>${par^^}</A></TD>" >> tmp.html
   done
   echo "</TR>"                                                                                 >> tmp.html
done

echo "</TABLE>" >> tmp.html

# Loop over the region list, plotting time series of the near surface atmospheric quantities.

echo "<H2 ALIGN=CENTER> <A NAME=Tijdreeksen>Tijdreeksen</A></H2>" >> tmp.html

echo "<TABLE ALIGN=CENTER CELLSPACING=5 BORDER=5>" >> tmp.html
echo "<TR>" >> tmp.html
echo "<TH><A HREF=/~hirlam/Weerbericht>Locatie/Waterschap</A></TH>" >> tmp.html
echo "<TH><A HREF=/~hirlam/OverAll>Grootheden</A></TH>" >> tmp.html
echo "<TH COLSPAN=3><A HREF=/~hirlam/timeseries>Tabellen (verwachtingstijd gemiddelde stddev min max ...)</A></TH>" >> tmp.html
echo "</TR>" >> tmp.html

XTIX="('d0h18' 0"
for h in `seq 6 6 $FL`
do
   d=`expr \( $h + 18 \) / 24`
   hh=`expr \( $h - 6 \) % 24`
   XTIX=$XTIX",'d${d}h${hh}' $h"
done
XTIX=$XTIX")"

for area in $regionlist
do

   tz=`grep ^$area region.list | awk '{print $5}'`
   [ -s $todir/$area.WEERBERICHT ] || $HOME/PlotsOfTheDay/Weerbericht $area $basedtg $tz && mv $area.WEERBERICHT $todir

   echo "<TR><TH ROWSPAN=11><A HREF=/~hirlam/$basedtg/$area.WEERBERICHT>$area</A></TH></TR>" >> tmp.html

   # Temperature and dew point temperature.

   plottempobs=""; [ -r $area.TEMPERATUUR-obs ] && plottempobs=",'$area.TEMPERATUUR-obs' using 1:(\$2-273.16):3 title 'T obs'  pointtype 5"
   plotdauwobs=""; [ -r $area.DAUWPUNT-obs ]    && plotdauwobs=",'$area.DAUWPUNT-obs'    using 1:(\$2-273.16):3 title 'TD obs' pointtype 7"
   gnuplot << EOF
      set terminal pngcairo mono size 1440,720
      set output '$area-t2m.png'
      set style data errorbars
      set key outside
      set grid linestyle 2
      set xtics $XTIX
      set xrange [-2:`expr $FL + 2`]
      set xlabel 'Verwachtingstijd (UTC)'
      set ylabel 'Temperatuur en Dauwpunt (graden C)'
      set title 'Verwachting $basedtg: $area - 2 meter temperatuur en dauwpunt'
      plot '$area.TEMPERATUUR' using 1:(\$2-273.16):3 title 'T gem +/- stdev' linetype -1 pointtype 6, \
           '$area.TEMPERATUUR' using 1:(\$4-273.16) title 'T min' with lines linetype 0, \
           '$area.TEMPERATUUR' using 1:(\$5-273.16) title 'T max' with lines linetype 0, \
           '$area.DAUWPUNT' using 1:(\$2-273.16):3 title 'TD gem +/- stdev' linetype -1 pointtype 3, \
           '$area.DAUWPUNT' using 1:(\$4-273.16) title 'TD min' with lines linetype 0, \
           '$area.DAUWPUNT' using 1:(\$5-273.16) title 'TD max' with lines linetype 0 \
           $plottempobs \
           $plotdauwobs
EOF
   mv -f $area-t2m.png $todir
   mv -f $area.TEMPERATUUR $todir
   mv -f $area.DAUWPUNT $todir
   echo "<TR><TD><A HREF=/~hirlam/$basedtg/$area-t2m.png>Temperatuur en dauwpunt</A></TD>" >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.TEMPERATUUR>Temperatuur</A></TD>" >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.DAUWPUNT>Dauwpunt</A></TD></TR>"  >> tmp.html

   # Relative humidity.

   plotrhobs=""; [ -r $area.RELVOCHT-obs ] && plotrhobs=",'$area.RELVOCHT-obs' using 1:2:3 title 'RH obs' pointtype 5"
   gnuplot << EOF
      set terminal pngcairo mono size 1440,720
      set output '$area-rh.png'
      set style data errorbars
      set key outside
      set grid linestyle 2
      set xtics $XTIX
      set xrange [-2:`expr $FL + 2`]
      set xlabel 'Verwachtingstijd (UTC)'
      set ylabel 'Relatieve vochtigheid (%)'
      set title 'Verwachting $basedtg: $area - relatieve vochtigheid op 2 meter'
      plot '$area.RELVOCHT' using 1:(\$2*100):(\$3*100) title 'RH gem +/- stdev' linetype -1 pointtype 6, \
           '$area.RELVOCHT' using 1:(\$4*100) title 'RH min' with lines linetype 0, \
           '$area.RELVOCHT' using 1:(\$5*100) title 'RH max' with lines linetype 0 \
           $plotrhobs
EOF
   mv -f $area-rh.png $todir
   mv -f $area.RELVOCHT $todir
   echo "<TR><TD><A HREF=/~hirlam/$basedtg/$area-rh.png>Relatieve vochtigheid</A></TD>"        >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.RELVOCHT>Relatieve vochtigheid</A></TD></TR>" >> tmp.html

   # Wind direction.

   plotwdirobs=""; [ -r $area.WINDRICHTING-obs ] && plotwdirobs=",'$area.WINDRICHTING-obs' using 1:2:3 title 'DD obs' pointtype 5"
   gnuplot << EOF
      set terminal pngcairo mono size 1440,720
      set output '$area-dd10m.png'
      set style data errorbars
      set key outside
      set grid linestyle 2
      set xtics $XTIX
      set xrange [-2:`expr $FL + 2`]
      set xlabel 'Verwachtingstijd (UTC)'
      set ytics ('Noord' 0, 'Noordoost' 45, 'Oost' 90, 'Zuidoost' 135, 'Zuid' 180, 'Zuidwest' 225, 'West' 270, 'Noordwest' 315, 'Noord' 360)
      set ylabel 'Windrichting'
      set title 'Verwachting $basedtg: $area - 10 meter wind richting'
      plot '$area.WINDRICHTING' using 1:2:3 title 'DD gem +/- stdev' linetype -1 pointtype 6, \
           '$area.WINDRICHTING' using 1:4 title 'DD min' with lines linetype 0, \
           '$area.WINDRICHTING' using 1:5 title 'DD max' with lines linetype 0 \
           $plotwdirobs
EOF
   mv -f $area-dd10m.png $todir
   mv -f $area.WINDRICHTING $todir
   echo "<TR><TD><A HREF=/~hirlam/$basedtg/$area-dd10m.png>Windrichting</A></TD>"         >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.WINDRICHTING>Windrichting</A></TD></TR>" >> tmp.html

   # Wind speed.

   plotwspdobs=""; [ -r $area.WINDSNELHEID-obs ] && plotwspdobs=",'$area.WINDSNELHEID-obs' using 1:2:3 title 'FF obs' pointtype 5"
   plotgustobs=""; [ -r $area.GUST-obs ]         && plotgustobs=",'$area.GUST-obs'         using 1:2:3 title 'GUST obs' pointtype 7"
   gnuplot << EOF
      set terminal pngcairo mono size 1440,720
      set output '$area-ff10m.png'
      set style data errorbars
      set key outside
      set grid linestyle 2
      set xtics $XTIX
      set xrange [-2:`expr $FL + 2`]
      set xlabel 'Verwachtingstijd (UTC)'
      set yrange [0:]
      set ylabel 'Wind(stoten) (m/s)'
      set title 'Verwachting $basedtg: $area - 10 meter wind snelheid en windstoten'
      plot '$area.WINDSNELHEID' using 1:2:3 title 'FF gem +/- stdev' linetype -1 pointtype 6, \
           '$area.WINDSNELHEID' using 1:4 title 'FF min' with lines linetype 0, \
           '$area.WINDSNELHEID' using 1:5 title 'FF max' with lines linetype 0, \
           '$area.WINDSTOTEN' using 1:2:3 title 'GUST gem +/- stdev' linetype -1 pointtype 3, \
           '$area.WINDSTOTEN' using 1:4 title 'GUST min' with lines linetype 0, \
           '$area.WINDSTOTEN' using 1:5 title 'GUST max' with lines linetype 0 \
           $plotwspdobs \
           $plotgustobs
EOF
   mv -f $area-ff10m.png $todir
   mv -f $area.WINDSNELHEID $todir
   mv -f $area.WINDSTOTEN $todir
   echo "<TR><TD><A HREF=/~hirlam/$basedtg/$area-ff10m.png>Windsnelheid en windstoten</A></TD>" >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.WINDSNELHEID>Windsnelheid</A></TD>"  >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.WINDSTOTEN>Windstoten</A></TD></TR>" >> tmp.html

   # Neerslag.

#          '$area.CONVNEERSLAG' using 1:2:3 axes x1y1 title 'RRc gem +/- stdev' linetype -1 pointtype 3,
#          '$area.CONVNEERSLAG' using 1:4 axes x1y1 title 'RRc min' with lines linetype 0,
#          '$area.CONVNEERSLAG' using 1:5 axes x1y1 title 'RRc max' with lines linetype 0,
   awk -f $HOME/PlotsOfTheDay/neso.awk $area.NEERSLAGSRT > $area.neso
   awk 'BEGIN {prevmin=0; prevmax=0}; {if ($1 > 0) {min=$4-prevmin; max=$5-prevmax; if (min > max) max=min; prevmin=$4; prevmax=$5; print $1, min, max, 0}}' $area.FRNTNEERSLAG > $area.RR1
   plotprecobs=""; [ -r $area.NEERSLAG-obs ] && plotprecobs=",'$area.NEERSLAG-obs' using 1:2:3 axes x1y1 title 'RR1 obs' pointtype 5 pointsize 1"
   gnuplot << EOF
      set terminal pngcairo mono size 1440,720
      set output '$area-rr.png'
      set style data errorbars
      set key outside
      set grid linestyle 2
      set xtics $XTIX
      set xrange [-2:`expr $FL + 2`]
      set xlabel 'Verwachtingstijd (UTC)'
      set ytics nomirror autofreq
      set y2range [0:1.05]
      set y2tics 0,0.1,1
      set ylabel 'Neerslag (kg/m^2)'
      set y2label ' Neerslagsoort (%)'
      set title 'Verwachting $basedtg: $area - neerslag en neerslagsoort'
      plot '$area.FRNTNEERSLAG' using 1:2:3 axes x1y1 title 'RRf gem +/- stdev' linetype -1 pointtype 6, \
           '$area.FRNTNEERSLAG' using 1:4 axes x1y1 title 'RRf min' with lines linetype 0, \
           '$area.FRNTNEERSLAG' using 1:5 axes x1y1 title 'RRf max' with lines linetype 0, \
           '$area.RR1' using 1:2:4 axes x1y1 title 'RR1 min' with points pointtype  8 pointsize 2, \
           '$area.RR1' using 1:3:4 axes x1y1 title 'RR1 max' with points pointtype 12 pointsize 2, \
           '$area.neso' using 1 axes x1y2 title 'Regen' with points pointtype 7 pointsize 2, \
           '$area.neso' using 2 axes x1y2 title 'Sneeuw' with points pointtype 9 pointsize 2, \
           '$area.neso' using 3 axes x1y2 title 'Sneeuw' with points pointtype 9 pointsize 2, \
           '$area.neso' using 4 axes x1y2 title 'Ijzel' with points pointtype 4 pointsize 2, \
           '$area.neso' using 5 axes x1y2 title 'Ijsregen' with points pointtype 11 pointsize 2, \
           '$area.neso' using 6 axes x1y2 title 'Ijsregen/natte sneeuw' with points pointtype 13 pointsize 2, \
           '$area.neso' using 7 axes x1y2 title 'Natte sneeuw' with points pointtype 15 pointsize 2 \
           $plotprecobs
EOF
   mv -f $area-rr.png $todir
   #  mv -f $area.FRNTNEERSLAG $todir # Later ...
   mv -f $area.CONVNEERSLAG $todir
   echo "<TR><TD><A HREF=/~hirlam/$basedtg/$area-rr.png>Neerslag; neerslagsoort</A></TD>"         >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.FRNTNEERSLAG>Neerslag</A></TD></TR>"             >> tmp.html
#  echo "    <TD><A HREF=/~hirlam/$basedtg/$area.CONVNEERSLAG>Convectieve neerslag</A></TD></TR>" >> tmp.html

   # Cloud cover.

   plotccobs=""; [ -r $area.BEWOLKING-obs ] && plotccobs=",'$area.BEWOLKING-obs' using 1:(\$2*0.01):3 title 'CC obs' pointtype 5"
   gnuplot << EOF
      set terminal pngcairo mono size 1440,720
      set output '$area-cc.png'
      set style data errorbars
      set key outside
      set grid linestyle 2
      set xtics $XTIX
      set xrange [-2:`expr $FL + 2`]
      set xlabel 'Verwachtingstijd (UTC)'
      set ytics ('0' 0, '1' 0.125, '2' 0.25, '3' 0.375, '4' 0.5, '5' 0.625, '6' 0.75, '7' 0.875, '8' 1.0)
      set yrange [-0.8:1.1]
      set y2tics autofreq
      set y2range [:600]
      set ylabel 'Bewolkingsgraad (octa)'
      set y2label 'Latente en Voelbare warmtestroom (W/m^2)'
      set title 'Verwachting $basedtg: $area - bewolking; latente en voelbare warmtestroom'
      plot '$area.BEWOLKING' using 1:2:3 axes x1y1 title 'CC gem +/- stdev' linetype -1 pointtype 6, \
           '$area.BEWOLKING' using 1:4 axes x1y1 title 'CC min' with lines linetype 0, \
           '$area.BEWOLKING' using 1:5 axes x1y1 title 'CC max' with lines linetype 0, \
           '$area.LATHFLUX' using 1:2:3 axes x1y2 title 'LATHFLX gem +/- stdev' linetype -1 pointtype 3, \
           '$area.LATHFLUX' using 1:4 axes x1y2 title 'LATHFLX min' with lines linetype 0, \
           '$area.LATHFLUX' using 1:5 axes x1y2 title 'LATHFLX max' with lines linetype 0, \
           '$area.SENSHFLUX' using 1:2:3 axes x1y2 title 'SNSHFLX gem +/- stdev' linetype -1 pointtype 4, \
           '$area.SENSHFLUX' using 1:4 axes x1y2 title 'SNSHFLX min' with lines linetype 0, \
           '$area.SENSHFLUX' using 1:5 axes x1y2 title 'SNSHFLX max' with lines linetype 0 \
           $plotccobs
EOF
   mv -f $area-cc.png $todir
   mv -f $area.BEWOLKING $todir
   mv -f $area.LATHFLUX $todir
   mv -f $area.SENSHFLUX $todir
   echo "<TR><TD><A HREF=/~hirlam/$basedtg/$area-cc.png>Bewolking; latente en voelbare warmtestroom</A></TD>" >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.BEWOLKING>Bewolking</A></TD>"                  >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.LATHFLUX>Latente warmtestroom</A></TD>"        >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.SENSHFLUX>Voelbare warmtestroom</A></TD></TR>" >> tmp.html

#  Visibility.

   plotvisobs=""; [ -r $area.ZICHT-obs ] && plotvisobs=",'$area.ZICHT-obs' using 1:2:3 title 'VIS obs' pointtype 5"
   gnuplot << EOF
      set terminal pngcairo mono size 1440,720
      set output '$area-vis.png'
      set style data errorbars
      set key outside
      set grid linestyle 2
      set xtics $XTIX
      set xrange [-2:`expr $FL + 2`]
      set xlabel 'Verwachtingstijd (UTC)'
      set logscale y
      set yrange [10:50000]
      set ylabel 'Zicht (m)'
      set title 'Verwachting $basedtg: $area - zicht'
      plot '$area.ZICHT' using 1:2:3 title 'VIS gem +/- stdev' linetype -1 pointtype 6, \
           '$area.ZICHT' using 1:4 title 'VIS min' with lines linetype 0, \
           '$area.ZICHT' using 1:5 title 'VIS max' with lines linetype 0 \
           $plotvisobs
EOF
   mv -f $area-vis.png $todir
   mv -f $area.ZICHT $todir
   echo "<TR><TD><A HREF=/~hirlam/$basedtg/$area-vis.png>Zicht</A></TD>"    >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.ZICHT>Zicht</A></TD></TR>" >> tmp.html

#  Snow heigth.

   plotsnhobs=""; [ -r $area.SNOWDEPTH-obs ] && plotsnhobs=",'$area.SNOWDEPTH-obs' using 1:2:3 title 'SNH obs' pointtype 5"
   gnuplot << EOF
      set terminal pngcairo mono size 1440,720
      set output '$area-sn.png'
      set style data errorbars
      set key outside
      set grid linestyle 2
      set xtics $XTIX
      set xrange [-2:`expr $FL + 2`]
      set xlabel 'Verwachtingstijd (UTC)'
      set ylabel 'Sneeuwhoogte (m)'
      set title 'Verwachting $basedtg: $area - sneeuwhoogte'
      plot '$area.SNEEUWHOOGTE' using 1:2:3 title 'SNH gem +/- stdev' linetype -1 pointtype 6, \
           '$area.SNEEUWHOOGTE' using 1:4 title 'SNH min' with lines linetype 0, \
           '$area.SNEEUWHOOGTE' using 1:5 title 'SNH max' with lines linetype 0 \
           $plotsnhobs
EOF
   mv -f $area-sn.png $todir
   mv -f $area.SNEEUWHOOGTE $todir
   echo "<TR><TD><A HREF=/~hirlam/$basedtg/$area-sn.png>Sneeuwhoogte</A></TD>"            >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.SNEEUWHOOGTE>Sneeuwhoogte</A></TD></TR>" >> tmp.html

#  Convective Available Potential Energy.

   gnuplot << EOF
      set terminal pngcairo mono size 1440,720
      set output '$area-cape.png'
      set style data errorbars
      set key outside
      set grid linestyle 2
      set xtics $XTIX
      set xrange [-2:`expr $FL + 2`]
      set xlabel 'Verwachtingstijd (UTC)'
      set ytics nomirror autofreq
      set ylabel 'CAPE en CIN (J/kg)'
      set y2tics autofreq
      set y2label 'Convectieve neerslag (kg/m^2)'
      set title 'Verwachting $basedtg: $area - Convective Available Potential Energy'
      plot '$area.CAPE' using 1:2:3 axes x1y1 title 'CAPE gem +/- stdev' linetype -1 pointtype 6, \
           '$area.CAPE' using 1:4 axes x1y1 title 'CAPE min' with lines linetype 0, \
           '$area.CAPE' using 1:5 axes x1y1 title 'CAPE max' with lines linetype 0, \
           '$area.CIN' using 1:2:3 axes x1y1 title 'CIN gem +/- stdev' linetype -1 pointtype 4, \
           '$area.CIN' using 1:4 axes x1y1 title 'CIN min' with lines linetype 0, \
           '$area.CIN' using 1:5 axes x1y1 title 'CIN max' with lines linetype 0, \
           '$area.FRNTNEERSLAG' using 1:2:3 axes x1y2 title 'RR gem +/- stdev' linetype -1 pointtype 3, \
           '$area.FRNTNEERSLAG' using 1:4 axes x1y2 title 'RR min' with lines linetype 0, \
           '$area.FRNTNEERSLAG' using 1:5 axes x1y2 title 'RR max' with lines linetype 0
EOF
   mv -f $area-cape.png $todir
   mv -f $area.CAPE $todir
   mv -f $area.CIN $todir
   mv -f $area.FRNTNEERSLAG $todir
   echo "<TR><TD><A HREF=/~hirlam/$basedtg/$area-cape.png>Convective Available Potential Energy; Inhibition</A></TD>" >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.CAPE>Convective Available Potential Energy</A></TD>" >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.CIN>Convective Inhibition</A></TD></TR>"             >> tmp.html

#  Incoming and outgoing radiation.

   gnuplot << EOF
      set terminal pngcairo mono size 1440,720
      set output '$area-rad.png'
      set style data errorbars
      set key outside
      set grid linestyle 2
      set xtics $XTIX
      set xrange [-2:`expr $FL + 2`]
      set xlabel 'Verwachtingstijd (UTC)'
      set ylabel 'Zonlicht (J/m^2)'
      set y2tics autofreq
      set y2label 'Infrarood (J/m^2)'
      set title 'Verwachting $basedtg: $area - Zonne-instraling en infrarood-uitstraling'
      plot '$area.ZONLICHT' using 1:2:3 axes x1y1 title 'ZL gem +/- stdev' linetype -1 pointtype 6, \
           '$area.ZONLICHT' using 1:4 axes x1y1 title 'ZL min' with lines linetype 0, \
           '$area.ZONLICHT' using 1:5 axes x1y1 title 'ZL max' with lines linetype 0, \
           '$area.INFRAROOD' using 1:2:3 axes x1y2 title 'IR gem +/- stdev' linetype -1 pointtype 3, \
           '$area.INFRAROOD' using 1:4 axes x1y2 title 'IR min' with lines linetype 0, \
           '$area.INFRAROOD' using 1:5 axes x1y2 title 'IR max' with lines linetype 0
EOF
   mv -f $area-rad.png $todir
   mv -f $area.ZONLICHT $todir
   mv -f $area.INFRAROOD $todir
   echo "<TR><TD><A HREF=/~hirlam/$basedtg/$area-rad.png>Zonlicht en infrarood</A></TD>" >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.ZONLICHT>Zonlicht</A></TD>"  >> tmp.html
   echo "    <TD><A HREF=/~hirlam/$basedtg/$area.INFRAROOD>Infrarood</A></TD></TR>" >> tmp.html

done

echo "</TABLE>" >> tmp.html

echo "</BODY>" >> tmp.html
echo "</HTML>" >> tmp.html

mv -f tmp.html $todir/index.html
rm -f $html/index.html
ln -s $todir/index.html $html/index.html

cd

rm -rf $wd

exit 0
