BEGIN {FS=",";oldcat="0";oldType="O";oldsec="O";one=1;
misfile="missing_files_"strftime("%Y-%m-%d_%H_%M")".txt"
print "Missing files "strftime("%Y-%m-%d %H:%M:S") > misfile
# Generate Google Earth KML files for water quality data points.
# Generate text HTML files for accessing the same data.
# Normally data should be sorted by type, then tertiary|wma, then feature id.
# 2007-06-11 Michael Silberbauer major changes from previous versions (icons, dynamic variables in awk)
# 2007-08-31 Select better map icons
# 2007-09-01 Timespan (see http://nsidc.org/data/virtual_globes/timelines.html)
# 2007-09-03 Exclude all boreholes from surface report, not just those with < 10 samples
# 2007-09-07 Arrange folders more logically
# 2008-05-15 Check if files exist... adds an extra layer of complexity... only works for file-based system
# 2008-08-04 Cumulative minor modifications to text for missing data in balloons and HTML tables
#Usage
# for primary drainage region grouping (WMA_on=0):
# gawk -v WMA_on=0 -v bor=0 -v mau=0 -v disk=0 -f C:\data\Program\awk\kml_WMS_mnpts_html.awk C:\Data_Large\av\nms_wms_dat_pri.txt
# 84960,'A1H002','A1H002 DINOKANA AT DAM','',-25.448056,25.878889,'A10',0,0,'1899-12-30','1899-12-30','Dinokana at Dam','A10_0000084960',3,'A10A','A1','A'
#
# for WMA grouping (WMA_on=1):
# gawk -v WMA_on=1 -v bor=0 -v mau=0 -v disk=0 -f C:\data\Program\awk\kml_WMS_mnpts_html.awk C:\Data_Large\av\nms_wms_dat_wma.txt
# 90174,'A2H027Q01','A2H027Q01 PIENAARS RIVER AT BAVIAANSPOORT','Rivers',-25.662500,28.351389,'A23',1,4287,'1967-02-08','2008-02-25','Pienaars River at Baviaanspoort','A23_0000090174',3,'A23A','A2','A'
#
# borehole and WMA switches are set in C:\data\Program\awk\kml_WMS.bat using -v variable setting for gawk
# Choose boreholes or no boreholes (many of the sites are boreholes with one sample, which clutter the view):
#bor=0# use batch file with: gawk -v bor=0 -v WMA_on=0 ...
if(bor)borf="_boreh"
else borf="_nobor"
if(bor)bfold=" boreholes"
else bfold=" surface"
# switch WMA mode off (0) or on (1, only for data sorted by WMA, then tertiary, then type, then feature id):
#WMA_on=0# use batch file with: gawk -v bor=1 -v WMA_on=1 ...
# choose whether to use Maucha symbols as point markers (use -v mauc=1):
if(mau) msym=1
else msym=0
if(mau) bfold=bfold" Maucha"
# set the disk to the local disk (for testing) or "" for online (now set in calling routine):
#disk=""
#disk="c:"
# set the address root (hrfc="file:///" or "http://")
hrfc="file:///"
isdisk=1
# set the address path (dpath="/data_large/wms_graphs_2006/" or "www.dwaf.gov.za/iwqs/wms/data/")
dpath="/data_large/wms_graphs_2006/"
if (disk==""||disk==0) {
hrfc="http://"
disk=""
isdisk=0
dpath="www.dwaf.gov.za/iwqs/wms/data/"
}
#print "Disk="disk", isdisk="isdisk
dospath=dpath
gsub("/","\\",dospath)
if (isdisk) dpath="www.dwaf.gov.za/iwqs/wms/data/"
# set the search path to check if files exist, when creating the web version
srchpath="Q:\\wms\\data\\"
#srchpath="C:\\data_large\\wms_graphs_2008\\"
# set Water Management Area numbers and names:
WMA[00]="sites outside borders"
WMA[01]="Limpopo"
WMA[02]="Luvuvhu and Letaba"
WMA[03]="Crocodile West and Marico"
WMA[04]="Olifants"
WMA[05]="Inkomati"
WMA[06]="Usutu to Mhlatuze"
WMA[07]="Thukela"
WMA[08]="Upper Vaal"
WMA[09]="Middle Vaal"
WMA[10]="Lower Vaal"
WMA[11]="Mvoti to Umzimkulu"
WMA[12]="Mzimvubu to Keiskamma"
WMA[13]="Upper Orange"
WMA[14]="Lower Orange"
WMA[15]="Fish to Tsitsikamma"
WMA[16]="Gouritz"
WMA[17]="Olifants-Doorn"
WMA[18]="Breede"
WMA[19]="Berg"
#for(i=1;i<=19;i++) print i,WMA[i]
# set marker names and files:
ico[1]="normalPlacemark" ;nic[1]="http://maps.google.com/mapfiles/kml/paddle/wht-circle-lv.png"
ico[2]="unknownPlacemark" ;nic[2]="http://maps.google.com/mapfiles/kml/paddle/wht-blank-lv.png"
ico[3]="boreholePlacemark" ;nic[3]="http://maps.google.com/mapfiles/kml/paddle/B-lv.png"
ico[4]="borehole00Placemark" ;nic[4]="http://maps.google.com/mapfiles/kml/paddle/O-lv.png"
ico[5]="borehole01Placemark" ;nic[5]="http://maps.google.com/mapfiles/kml/paddle/1-lv.png"
ico[6]="borehole02Placemark" ;nic[6]="http://maps.google.com/mapfiles/kml/paddle/2-lv.png"
ico[7]="borehole03Placemark" ;nic[7]="http://maps.google.com/mapfiles/kml/paddle/3-lv.png"
ico[8]="borehole04Placemark" ;nic[8]="http://maps.google.com/mapfiles/kml/paddle/4-lv.png"
ico[9]="borehole05Placemark" ;nic[9]="http://maps.google.com/mapfiles/kml/paddle/5-lv.png"
ico[10]="borehole06Placemark" ;nic[10]="http://maps.google.com/mapfiles/kml/paddle/6-lv.png"
ico[11]="borehole07Placemark" ;nic[11]="http://maps.google.com/mapfiles/kml/paddle/7-lv.png"
ico[12]="borehole08Placemark" ;nic[12]="http://maps.google.com/mapfiles/kml/paddle/8-lv.png"
ico[13]="borehole09Placemark" ;nic[13]="http://maps.google.com/mapfiles/kml/paddle/9-lv.png"
ico[14]="borehole10Placemark" ;nic[14]="http://maps.google.com/mapfiles/kml/paddle/10-lv.png"
ico[15]="canalPlacemark" ;nic[15]="http://maps.google.com/mapfiles/kml/pal5/icon50l.png"
ico[16]="potablePlacemark" ;nic[16]="http://maps.google.com/mapfiles/kml/paddle/blu-blank-lv.png"
ico[17]="industryPlacemark" ;nic[17]="http://maps.google.com/mapfiles/kml/pal2/icon10.png"
#ico[18]="hydroPlacemark" ;nic[18]="http://maps.google.com/mapfiles/kml/shapes/water.png"
ico[18]="hydroPlacemark" ;nic[18]="http://maps.google.com/mapfiles/kml/paddle/blu-circle-lv.png"
#ico[19]="lakePlacemark" ;nic[19]="http://www.dwaf.gov.za/iwqs/wms/img/dam.png"
ico[19]="lakePlacemark" ;nic[19]="http://maps.google.com/mapfiles/kml/paddle/ltblu-blank-lv.png"
ico[20]="marinePlacemark" ;nic[20]="http://maps.google.com/mapfiles/kml/paddle/grn-stars-lv.png"
ico[21]="municipalPlacemark" ;nic[21]="http://maps.google.com/mapfiles/kml/pal3/icon21.png"
ico[22]="pipelinePlacemark" ;nic[22]="http://maps.google.com/mapfiles/kml/shapes/target.png"
ico[23]="sewagePlacemark" ;nic[23]="http://maps.google.com/mapfiles/kml/paddle/ylw-blank.png"
#ico[24]="tunnelPlacemark" ;nic[24]="http://maps.google.com/mapfiles/kml/pal4/icon25.png"
ico[24]="tunnelPlacemark" ;nic[24]="http://maps.google.com/mapfiles/kml/shapes/donut.png"
ico[25]="wetlandPlacemark" ;nic[25]="http://maps.google.com/mapfiles/kml/paddle/grn-blank-lv.png"
ico[26]="groundPlacemark" ;nic[26]="http://maps.google.com/mapfiles/kml/paddle/g-lv.png"
ico[27]="panPlacemark" ;nic[27]="http://maps.google.com/mapfiles/kml/paddle/ylw-blank-lv.png"
}
{
gsub( "&", " and ", $0 )
#gsub( "'", "", $0 ) # single quotes are an artefact of the ArcInfo Tables UNLOAD command in wms2nms.aml
#for( i=1;i<17;i++ ) print i,$i
for( i=1;i<17;i++ ) gsub( "'", "", $i) # single quotes are an artefact of the ArcInfo Tables UNLOAD command in wms2nms.aml
ptnwms=$1 # Monitoring_point_id
ptstn =$2 #station code
pttype=$3 # Located_on_type
pntlat=$4 # Latitude
pntlon=$5 # Longitude
catcht=$6 # Tertiary ... quat is $15
ptactv=$7 # Active point flag
nsmpls=$8 # Number_of_samples
dtsmp1=$9 # First_sample_date
dtsmpn=$10 # Last_sample_date
ptname=$11 # Monitoring_point_name
pntsrt=$12 # PRI_Sort (tertiary plus WMS code, stuffed with zeros e.g. D16_0000157611
wmanum=$13 # WMA number
qat =$14 # Quaternary drainage region
sec =$15 # Secondary drainage region
primry=$16 # Primary drainage region or WMA number ... now just primary
catcht=substr( qat,1,3 ) # Warning: the WMS and GIS tertiaries differ for some sites!
cat=substr( catcht,1,1 )
wma="WMA"wmanum
if(wmanum<10) wma="WMA0"wmanum #insert leading zero to tidy up file name
#if(wmanum>=10 && wmanum<100)
# here's a switch to group by WMAs
if(WMA_on) cat=wma
ter=tolower(substr(catcht,1,3))
sec=tolower(substr(catcht,1,2))
pri=tolower(substr(catcht,1,1))
#print "Catchment "cat
if( cat!=oldcat )
{
if (one)
{
one=0 # the first time here we skip the lines to close a file
}
else
{
# we've come to the end of a section
print " " >> catfile # for secondary catchment
print "" >> catfile # for Type
print "" >> catfile # for primary catchment or WMA
print "" >> catfile
close (catfile)
#print "Closing "oldcat " and opening "cat
print "" >> htmfile
print ""strftime("%Y-%m-%d %H:%M") >> htmfile
print "|WMS water quality sites home" >> htmfile
print "" >> htmfile
print "" >> htmfile
print "" >> htmfile
print "" >> htmfile
print "