/* aml to draw multiple graphs on a single page
/* Version 1.0 Michael Silberbauer Jan 1994
/* Version 1.1 Michael Silberbauer modified October 1994 to allow automatic
/* printing of entire drainage regions for macro or trace variables.
/* Version 1.2 Michael Silberbauer modified November 1994 to print a record file and
/* to try to get duplex printing on the HP4Si laserjet (no such luck!)
/* Version 1.3 All duplex commands commented out using /*dup
/* Version 1.4 use point coverage of
/* stations to select which
/* stations to plot Feb 1995 Michael Silberbauer
/* Version 1.5 test version Mar 1995 Michael Silberbauer
/* (different inorg.dat, flow incorporated)
/* Version 1.6 modified for Arc/Info 7.0.3 Jul 1995 E Vermaak & M Silberbauer
/* and Solaris 2.4
/* Version 1.7 shading modified Feb 1996 M Silberbauer
/* and renamed barcode.aml
/* Version 1.8 Large fonts option added Sep 1996, M Silberbauer
/* Version 2.0 with new font and shading Nov 1996, M Silberbauer
/* Version 2.1 with quaternary mini-map, Feb 1997, Michael Silberbauer
/* Version 2.2 with bug removal:
/* a) values set to null before STATISTICS
/* b) rounding of results for y-axis improved
/* Jun 1997, Michael Silberbauer
/* c) rounding changed because of numeric overflow in 7.1.1
/* Aug 1997, Michael Silberbauer
/* d) ISO dates Nov 1998, Michael Silberbauer
/* e) HP8000 printer Jun 1999, Michael Silberbauer
/* Version 3.0 with median, number Jun 1999, Michael Silberbauer
/* Version 3.1 with percentiles Sep 2000, Michael Silberbauer
/* Version 3.2 with Arc/Info 8 fixes
/* menu improvements
/* log file Jan 2001, Michael Silberbauer
/* Version 3.3 percentile bug fix May 2001, Michael Silberbauer
/* Version 3.31 remove all temp files Jun 2001, Michael Silberbauer
/* Version 3.4 allow variable file name Jun 2001, Michael Silberbauer
/* Version 3.41 fix variable file name! Oct 2001, Michael Silberbauer
/* Version 3.5 adapt to Windows 2000 Apr 2002, Michael Silberbauer
/* Version 3.51 new logo Oct 2002, Michael Silberbauer
/* Version 3.6 new directorate and DMS Jul 2003, Michael Silberbauer
/* Version 3.61 replaced library by cov Aug 2003, Michael Silberbauer
/* Version 4.01 added the Maucha symbol Aug 2004, Michael Silberbauer
/* Version 4.02 changed pH graph to +/- Aug 2004, Michael Silberbauer
/* Version 4.03 edit of descriptive text Aug 2004, Michael Silberbauer
/* Version 4.10 OS detection for PC use Aug 2004, Michael Silberbauer
/* Version 4.20 accept non-STASKAT stns Aug 2004, Michael Silberbauer
/* Version 4.30 check for minNstn data Aug 2004, Michael Silberbauer
/* Version 4.40 Sep 2004, Michael Silberbauer
/* Version 4.50 PDF option Sep 2004, Michael Silberbauer
/* Version 4.60 suppress graphics option Sep 2004, Michael Silberbauer
/* Version 4.61 allow YYYY-MM-DD dates Sep 2004, Michael Silberbauer
/* Version 4.62 cosmetic changes Sep 2004, Michael Silberbauer
/* Version 4.63 correct page orient. PDF Sep 2004, Michael Silberbauer
/* Version 5.01 allow guideline shading Feb 2005, Michael Silberbauer
/* Version 5.02 fix use of YYYY-MM-DD Feb 2005, Michael Silberbauer
/* Version 5.10 use vector DWAF logo Aug 2005, Michael Silberbauer
/* Version 5.11 Fix Feat_ID not set Aug 2005, Michael Silberbauer
/* Version 6.00 Add trace metal option Oct 2005, Michael Silberbauer
/* Version 6.10 Change WMS abbr to hexadec Dec 2005, Michael Silberbauer
/* Version 6.11 Station code check routine Dec 2005, Michael Silberbauer
/* Version 6.12 Prefix tertiary to WMS code Dec 2005, Michael Silberbauer
/* Version 6.20 Generate minute Maucha sym Dec 2005, Michael Silberbauer
/* Version 6.21 Optimise size when on screen Dec 2005, Michael Silberbauer
/* Version 6.22 Allow selection of ALL stns May 2006, Michael Silberbauer
/* Version 6.23 INDEXITEM on temp files May 2006, Michael Silberbauer
/* Version 6.24 Check for NDATE = 0 May 2006, Michael Silberbauer
/* Version 6.30 Export text file of data Jun 2006, Michael Silberbauer
/* Version 6.40 Write HTML text Jun 2006, Michael Silberbauer
/* Version 6.41 Write No data message maucha Sep 2006, Michael Silberbauer
/* Version 6.50 Z is default, not noZ Nov 2006, Michael Silberbauer
/* Version 6.51 PlotName = Tertiary_Station Nov 2006, Michael Silberbauer
/* Version 6.52 Fix error in %ile for n=1 Nov 2006, Michael Silberbauer
/* Version 6.53 Improve grep example Dec 2006, Michael Silberbauer
/* Version 6.54 %Longitude%%ValList% (no ",") Dec 2006, Michael Silberbauer
/* Version 6.55 Fix No data text size maucha Dec 2006, Michael Silberbauer
/* Version 6.60 Plot dam levels if available Jun 2007, Michael Silberbauer
/* Version 6.61 [Slightly] improve date axis Jun 2007, Michael Silberbauer
/* Version 7.01 Majorly improve y axis Jul 2007, Michael Silberbauer
/* Version 7.02 Supress maucha with trace plot Jul 2007, Michael Silberbauer
/* Version 7.03 Use nawk (SunOS) or gawk (NT) Feb 2008, Michael Silberbauer
/* Version 8.01 Use feat_id for selection WMS data Apr 2008, Michael Silberbauer Q01 suffix no longer guaranteed
/* Version 8.02 Make all temp variables unique Apr 2008, Michael Silberbauer ESKOM problems so must multitask
/* Version 8.03 Add guideline to PlotName Feb 2009, Michael Silberbauer
/* Be sure to change the version number in the AML below!
&args CatPri CatSec CatTer Station VarType Flow Year1 Year2 Display Pcntl BigFont StnType noZ minNsmp PctMax GLV inFile Type DebugD
&sv Version = %AML$FULLFILE% v8.03
&call SetOS
&type ********************* Command-line interface! *********************
&type %opsys% operating system using directory %enterprise%
&call ISOdate
&sv StartBarcodeTime = %ISOdate%
&type Running %Version% on %StartBarcodeTime%
&if [null %CatPri%] or [quote %CatPri%] = # and ~
( [quote %CatSec%] <> # or [quote %CatTer%] <> # ) and ~
[quote %Station%] <> # &then
&do
&type Usage: barcode CatPri CatSec CatTer Station VarType Flow Year1 Year2 Display
&type Pcntl BigFont StnType noZ PctMax GLV inFile Type DebugD
&type CatPri limits the search to one primary catchment, (e.g. C, or # to skip)
&type CatSec narrows the search to a secondary catchment, if CatPri is set
&type CatTer further narrows the search if CatPri and CatSec are set
&type Station selects only one station, or CatQat
&type VarType analysis group (only macro or trace currently available)
&type Flow to plot flow or dam level (where available)
&type Year1 the first year to plot, e.g. 1983
&type Year2 the last year to plot, e.g. 1994
&type Display p=print, f=PDF, m=PDF + maucha.jpg file, n=no (or s=Sun screen)
&type Pcntl percentile (= 90 percent by default)
&type BigFont for setting large fonts for posters and presentations
&type StnType R or H (default is B for both)
&type noZ Z or noZ (to exclude Z stations)
&type minNsmp minimum number of samples to accept (default 1)
&type PctMax Y = use the selected percentile as the graph max (default No)
&type GLV guideline DHC,ALW,AGI,AAQ,ICn,RFC,RIC,AES (default none)
&type inFile input data file (ignore)
&type Type sun1 sun2 sun3 sun4 tek1040 tek4107 (ignore)
&type DebugD used by programmers to set debugging mode (ignore)
&type
&type Examples-
&type WindowsNT:
&type barcode # # # g2h015q01 macro flow 1990 2006 # # # # # # # DHC n:/db/wmrq/wmdata/wq/macro080207.dat
&type SunOS:
&type Select one station : barcode # # # c9r002q01 macro flow 1980 1996 print
&type Whole quat catchment : barcode A 2 1 H m f 1993 1994 p
&type Whole ter catcht - PDF : barcode A 2 1 # m f 1993 1994 f
&type Sel only >= 300 smpls : barcode # # # a2h027q01 m f 2004 2005 s # # b Z 300
&type Specialists only:
&type Show guideline : barcode # # # c9r002q01 macro flow 1980 1996 p # # # # # # DHC
&type Set Ymax = percentile: barcode # # # r2r002q01 m f 2000 2004 p # # # # # y
&type Pcntl=95 and big font: barcode # # # A2H027Q01 macro flow 1993 1994 p 95 B
&type Tabular output : barcode A # # # m # 2003 2003 n 95 # # # 10
&type Debugging : barcode E # # # m f 1991 2000 p 95 s b z # # # # # d
&type Select all stations : barcode # # # $ macro flow 1972 2005 f
&type WARNING: DO NOT RUN MANY JOBS AT THE SAME TIME IN THE SAME DIRECTORY!
&return
&end
&if [substr [locase %DebugD%] 1 1] = 'd' &then &sv Debug = .true.
&else &sv Debug = .false.
&if ^ [exists . -workspace] &then createworkspace .
&if [null %CatSec%] &then &sv CatSec = #
&if [null %CatTer%] &then &sv CatTer = #
&if [null %Station% ] &then &sv Station = #
&sv CatPri = [translate %CatPri% ]
&sv CatSec = [translate %CatSec% ]
&sv CatTer = [translate %CatTer% ]
&sv Station = [translate %Station%]
&call isWMS /* return Single, WMS, Station, Feat_ID
&if %unresolved% &then
&do
&type Please check the station code
&return
&end
&if [null %VarType% ] or [quote %VarType%] = '#' &then &sv VarType = Macro
&sv VarType = [substr [locase %VarType%] 1 1]
&sv Flow = [substr [locase %Flow%] 1 1]
&if [null %Year1%] &then &sv Year1 = 1972
&if [null %Year2%] &then &sv Year2 = 2005
&if [null %Display%] &then &sv Display = p
&else &sv Display = [substr %Display% 1 1]
&sv Display = [locase %Display%]
&if [null %Pcntl%] or [quote %Pcntl%] = '#' &then &sv Percentile = 90
&else &sv Percentile = %Pcntl%
/* The following is a relic from the Tektronix days - it remains for sentimental reasons:
&if [null %Type%] &then
&do
&sv MoniType = '9999 3'
&sv Type sun3
&end
&else
&do
&sv Type = [locase %Type%]
&sv MoniType = '9999 3'
&if %Type% = tek1040 &then &sv MoniType = 'tek1040'
&if %Type% = tek4107 &then &sv MoniType = 'tek4107'
&if %Type% = sun1 &then &sv MoniType = '9999'
&if %Type% = sun2 &then &sv MoniType = '9999 2'
&if %Type% = sun3 &then &sv MoniType = '9999 3'
&if %Type% = sun4 &then &sv MoniType = '9999 4'
&end
&if %Display% = p or %Display% = f or %Display% = m &then
&do
&sv MoniType = '0'
&sv Type = paper
&end
&if %Display% = n &then &sv MoniType = '1040'
&if [substr [locase %BigFont%] 1 1] = 'b' &then &sv BigFont = .true.
&else &sv BigFont = .false.
&if [null %StnType%] or %StnType% = # &then &sv StnType = B
&else &sv StnType = [translate %StnType%]
&if [null %noZ%] &then &sv noZ = Z
&else &sv noZ = [translate %noZ%]
&sv no_zstn = .false.
&if %noZ% = NOZ &then &sv no_zstn = .true.
&if [null %minNsmp%] or [quote %minNsmp%] = '#' &then &sv minNsmp = 1
&else &sv minNsmp = %minNsmp%
&sv PctMaxY = .FALSE.
&if [null %PctMax%] or %PctMax% = # &then &sv PctMaxY = .FALSE.
&else &if [locase %PctMax%] = y &then &sv PctMaxY = .TRUE.
&sv GL = .TRUE.
&if [null %GLV%] or %GLV% = # &then &sv GL = .FALSE.
&else &sv GLV = [translate %GLV%]
&if [null %inFile%] or %inFile% = # &then &sv inFile = Default
&call SetDefaults
/*&sv GLV = DHC;&sv GL = .true.
&if %GL% &then &call SetGuide
/*&sys echo User %User% running %Version% on %ISOdate% >> %LogFile%
&sv LogLine User %User% running %Version% on %ISOdate%
&call CheckDate
&sv rw = [write %ReportUnit% [quote %ISOdate1% to %ISOdate2% on RQS GIS file %ChemFile%]]
&sv rw = [write %RepHTML% [quote
> %LogFile%
&sv LogLine = %LogLine% \%UsingText%
&type ************************************************************
ARCPLOT
DISPLAY 0
&type Searching for valid stations...
clearselect %StnPnt% point
&if %Single% &then
/*&if %WMS% &then reselect %StnPnt% point feat_id = %Station%
&if %WMS% &then reselect %StnPnt% point feat_id = %Feat_ID%
&else
reselect %StnPnt% point station = [quote %Station%]
&else
&if %station% = $ &then reselect %StnPnt% point station <> ''
&else
&do
reselect %StnPnt% point primary = [quote %CatPri%]
&if [quote %CatSec%] <> # &then
reselect %StnPnt% point secondary = [quote %CatPri%%CatSec%]
&if [quote %CatTer%] <> # &then
reselect %StnPnt% point tertiary = [quote %CatPri%%CatSec%%CatTer%]
&if [quote %CatQat%] <> # &then
reselect %StnPnt% point quaternary = [quote %CatPri%%CatSec%%CatTer%%CatQat%]
&if %StnType% <> B &then
reselect %StnPnt% point stntype = [quote %StnType%]
/*Only works with the traditional Hydro numbers... or WMS hex numbers:
/*reselect %StnPnt% point monitype = 'Q' or station cn 'O'
&end
&sv nStations = [before [show select %StnPnt% point] ,]
infofile %StnPnt% point %BarTmpLst% primary secondary tertiary quaternary station feat_id init
&data ARC INFO
ARC
SELECT [translate [entryname %BarTmpLst%]]
SORT ON QUATERNARY, STATION
Q STOP
&end
&sys arc indexitem %BarTmpLst% feat_id
&sys arc indexitem %BarTmpLst% station
list %BarTmpLst% info 1 10
&type Number of stations selected = %nStations%
clearselect %BarTmpLst% info
reselect %BarTmpLst% info feat_id > 0
&sv nTmpLst = [before [show select %BarTmpLst% info] ,]
&if %nStations% = 0 OR %nTmpLst% = 0 &then
&do
&type N stations = %nStations% and nTmpLst = %nTmpLst%...
&sv delf [delete %BarTmpLst% -info]
QUIT
&return
&end
/*&message &off
&do nStation = 1 &to %nStations%
&if [exists %BarTmpXY% -file] &then &ty [delete %BarTmpXY% -file]
&if [exists %BarTmpGeo% -file] &then &ty [delete %BarTmpGeo% -file]
&if [exists %BarPrjXY% -file] &then &ty [delete %BarPrjXY% -file]
&if [exists %BarPrjGeo% -file] &then &ty [delete %BarPrjGeo% -file]
&if [exists %BarScratch% -file] &then &ty [delete %BarScratch% -file]
&if [exists %BarPrjScr% -file] &then &ty [delete %BarPrjScr% -file]
&if [show program] <> ARCPLOT &then ARCPLOT
/*&sv Station = [show select %BarTmpLst% info %nStation% item station]
/*&if %WMS% &then ~
&sv Station = [show select %BarTmpLst% info %nStation% item feat_id]
&sv Feat_ID = [show select %BarTmpLst% info %nStation% item feat_id]
/*&else
/*&sv Station = [show select %BarTmpLst% info %nStation% item station]
&sv StationName = [show select %BarTmpLst% info %nStation% item station]
&if ( ( [type [substr %StationName% 1 1]] NE -1 ) ~
AND ( [quote [unquote [substr [quote %StationName%] 1 1]]] = 'Z' ) ~
AND ( %no_zstn% ) ) &then
&do
&type (%nStation% of %nStations%) Skipping Z-station %Station% (%StationName%)
&sv rw = [write %ReportUnit% [quote Skipped Z-station %Station% (%StationName%)]]
&end
&else
&do
&if %minNsmp% > 0 &then &call CheckChem
&else &sv ExistSmp = .TRUE.
&if %ExistSmp% &then
&do
clearselect %StnPnt% point
/*&if %WMS% &then ~
reselect %StnPnt% point feat_id = %Station%
/*&else
/*reselect %StnPnt% point station = [quote %Station%]
&if [iteminfo %StnPnt% -point place -exists] &then
&sv Place = [show select %StnPnt% point 1 item place]
&else
&sv Place = [unquote '']
&sv Description = [show select %StnPnt% point 1 item description]
&sv mx = [show select %StnPnt% point 1 item x-coord]
&sv my = [show select %StnPnt% point 1 item y-coord]
&sv Primary = [show select %StnPnt% point 1 item primary]
&sv Secondary = [show select %StnPnt% point 1 item secondary]
&sv Tertiary = [show select %StnPnt% point 1 item tertiary]
&sv TertiaryL = [locase %Tertiary%]
&sv Quaternary = [show select %StnPnt% point 1 item quaternary]
&sv Stype = [show select %StnPnt% point 1 item stntype]
&sv PlotName = %TertiaryL%_%Station%
&if %GL% &then &sv PlotName = %PlotName%_%GLV%
&if [exists %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL% -directory] &then ~
&type Output will go to %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL%
&else &sys mkdir %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL%
/*&if [null %Stype%] &then &sv PlotName = %Tertiary%_%Station%
/*&else
/*&do
/*&if [type %Stype%] <> -1 &then
/*&if ( ( %Stype% = H ) OR ( %Stype% = R ) ) ~
/*&then &sv PlotName = %StationName%
/*&end
&if [locase %VarType%] = t &then &sv PlotName = %PlotName%_t
&call bartextfile
&sv PrjUnit = [open %BarTmpXY% openstatus -write]
&sv wp [write %PrjUnit% [quote %mx% %my%]]
&sv cl [close %PrjUnit%]
&call AlbGeo
&sv Place [unquote [trim [quote %Place%]]]
&sv Description [unquote [trim [quote %Description%]]]
&sv Description %Description% %Place%
/*&if %WMS% &then &sv Description %Tertiary%_%WMSstation% %Description%
&sv Description [unquote [trim [quote %Description%]]]
&type (%nStation% of %nStations%) %StationName% (%Station%) %GeoString% - %Description%
&sv nVars = %nVariables%
&if %Flow% = f &then &call FlowCalc
&call GraphLoop
&if [show program] = ARCPLOT &then QUIT /* ARCPLOT (so as to close .gra file)
&if %Display% = m AND %VarType% = m &then &call mauchapetit
&if %Display% = p or %Display% = f or %Display% = m &then &call Print1
&end
&end
&end
&message &on
&call ISOdate
&type Job started on %StartBarcodeTime%
&type Job finished on %ISOdate%
&sv rw = [write %ReportUnit% [quote End of data summary on %ISOdate%]]
&sv rw = [write %RepHTML% [quote
]]
&sv rw = [write %RepHdrHTML% [quote ]]
&sv CloseReport = [close -all]
&if %opsys% = SunOS &then &sys dos2unix %Report% %Report%
&sys echo %LogLine%\Results are summarised in file %Report% >> %LogFile%
&type Results are summarised in file %Report%
&type Combine files with a command of the form:
/*&type grep -v -h file *txt | grep -v Data | grep -v ":" > all.txt
&type grep -v -h StNam *txt | grep -v Data | grep -v "End" > all.txt
/* The report file is too wide to print, even with landscape, so we now
/* generate a comma-delimited file for use with spreadsheets (MJS 2000).
/*&if [exists [locase %Report%]r -file] &then %remove% [locase %Report%]r
/*cat %Landscape% [locase %Report%] %Portrait% > [locase %Report%]r
/*unix2dos %Report%r %Report%r
/*&if %Display% = p &then lp -dhp8000 %Report%r
/*&if %Display% = p &then &sys pr -f -w120 -l66 [locase %Report%r] | lp -dhp8000
&call ISOdate
&type End of station list at %ISOdate%
&if [show program] = ARCPLOT &then QUIT /* arcplot session
&if ^ %Debug% &then &call DeleteTempFiles
/*&sys %listfile% %Report%
&if %opsys% <> Windows_NT &then &sys head %Report%
&if %opsys% = SunOS &then &type A summary of results is available in file %Report%
&else &type A summary of results is available in file [subst %Report% '/' '\']
&type This job was run using the following parameters:
&type %UsingText%
&return
/* - - - - - - - - - - - - - - - - -
&routine GraphLoop
/* routine to draw graphs:
markerset water
&sv counter = %counter% + 1
/*&if %counter% > 2 &then &stop Finished - test mode.
/* A very unsatisfactory way of setting the display to cope with
/* the changes since the old Tektronix monitors.
/* Shows how old this AML is...
&if %Display% = p or %Display% = f or %Display% = m &then
&do
display 1040
%PlotName%
&type ...creating graphics file %PlotName%
&end
&else
&if %Display% = n &then
&do
display [unquote %MoniType%]
tb%unik%
&end
&else
display [unquote %MoniType%]
/*LIBRARY access
PAGEUNITS cm
&call PageSet
PAGESIZE %xPageSiz% %yPageSiz%
BOX 0 0 %xPageSiz% %yPageSiz%
&if %BigFont% &then &type Skipping interior box for clarity.
&else BOX %xMar% %yMar% %xPage% %yPage%
&sv yMin = 0
&sv yMax = %nVars%
&sv yMap = 0.26
GRAPHEXTENT %.startday% %yMin% %.endday% %yMax%
GRAPHLIMITS %Lxmin% %Lymin% %Lxmax% %Lymax%
linecolor %lcol_light%
BOX %Lxmin% %Lymin% %Lxmax% %Lymax%
linecolor 1
&sv xLencm = [calc %Lxmax% - %Lxmin%]
&sv yLencm = [calc %Lymax% - %Lymin%]
&sv xLenDay = [calc %.endday% - %.startday%]
&sv yLenVar = [calc %yMax% - %yMin%]
&sv cm_Day = [calc %xLencm% / %xLenDay%]
&sv cm_Var = [calc %yLencm% / %yLenVar%]
&sv tsb = 1 /* textsymbol ("big font")
&sv tsn = 10 /* textsymbol ("narrow font")
&sv tsl = 3 /* textsymbol ("bold font")
&sv tsm = 14 /* textsymbol (Only valid font for PostScript!)
&sv tss = 22 /* textsymbol (special characters)
&sv tsi = 23 /* textsymbol (italics)
&if %Display% = m or %Display% = f &then /* only postscript font
&do
&sv tsb = 14
&sv tsl = 14
&sv tsn = 14
&sv tss = 14
&sv tsi = 14
&end
UNITS page
TEXTSET font
&if %MoniType% = '0' &then TEXTSET font
&else
&do
&if [substr %MoniType% 1 1 ] = 9 &then TEXTSET font
&if [substr %MoniType% 1 1 ] = 1 &then TEXTSET plotter
&end
&if %BigFont% &then
&do
&sv tsm = %tsb%
&sv tss = %tsb%
&end
TEXTSYMBOL %tsm%
/*TEXTSTYLE TYPESET
TEXTSCALE 2.5
&if %BigFont% &then TEXTSCALE 3.7
MOVE [calc %xPage% * 0.5] [calc %yPage% * 0.975]
&if %BigFont% &then &sv Title_Text BARCODE GRAPHS
&else &sv Title_Text BARCODE GRAPHS OF WATER QUALITY VARIABLES
TEXT [quote %Tertiary%_[unquote %Feat_ID%] (%StationName%) WATER QUALITY] cc
TEXTSCALE 1.5
/*TEXTJUSTIFICATION cc
MOVE [calc %xPage% * 0.5] [calc %yPage% * 0.905]
&if [locase %VarType%] = t &then ~
&sv explaintext = Time series graphs of available flow and trace metal data. The y axes show summary statistics.
&else
&sv explaintext = Maucha median ion balance diagram (left) and time series graphs (below) of available flow and water quality data. The y axes show summary statistics.
&if %Flow% = f &then ~
TEXT [quote %explaintext%\Source data are from the WMS: INFO [subst %ChemFile% \ /], %StnPnt% and Hydsys: %FlowDir%] cc
&else
TEXT [quote %explaintext%\Source data are from the WMS: INFO [subst %ChemFile% \ /] and %StnPnt%] cc
TEXTSCALE 1.8
&if %BigFont% &then TEXTSCALE 2.0
MOVE [calc %xPage% * 0.5] [calc %yPage% * 0.950]
&if %GL% &then TEXT [quote %Description%: Guideline for [unquote [locase [value gd%GLV%]]]] cc
&else TEXT [quote BARCODE graphs: %Description%] cc
TEXTJUSTIFICATION ll
MOVE [calc %xPage% * 0.3] [calc %yPage% * 0.920]
TEXT [quote %ISOdate1% to %ISOdate2%]
MOVE [calc %xPage% * 0.6] [calc %yPage% * 0.920]
TEXTSTYLE TYPESET
TEXT [quote [unquote %GeoLabel1%]]
text '''
text [quote %GeoLabel2%]
text ' '
text [quote %GeoLabel3%]
text '''
text [quote %GeoLabel4%]
TEXTSTYLE SIMPLE
&sv closeall [close -all]
TEXTSYMBOL %tss%
TEXTJUSTIFICATION cr
&if %BigFont% &then
&do
TEXTSCALE 2.0
move [calc %xPage% * 0.995] [calc %yPage% * 0.980]
&sv ymaxmesg = yMax=\value shown
&if %PctMaxY% &then &sv ymaxmesg = yMax=%Percentile%%suffix% Pcntl.
TEXT [quote %ymaxmesg%] ur
&end
&else
&do
&sv ymaxmesg =
move %Lxmax% [calc %yPage% * 0.980]
&sv y2 = [calc %yPage% * 0.970]
&sv y1 = [calc %Lymax% + %yMar%]
linecolor %lcol_light%
line %Lxmax% %y1% %Lxmax% %y2%
linecolor 1
TEXTSCALE 1.5
TEXT [quote Each y-axis shows:\] lc
TEXTSYMBOL %tsb%
TEXTSIZE [calc ( %y2% - %y1% ) / 8]
MOVE [calc %Lxmax% + 0.1] %y2%
&if %PctMaxY% &then
&do
textcolor red
TEXT [quote ^maximum] ul
textcolor black
&end
&else TEXT maximum ul
MOVE [calc %Lxmax% + 0.1] %y1%
TEXT minimum ll
MOVE [calc %Lxmax% + [calc %xMar% * 1.5]] [calc %y1% + [calc ( %y2% - %y1% ) / 2]]
TEXT median ul
&if %GL% &then
&do
MOVE [calc %Lxmax% - [calc %xMar% * 0.2]] [calc %y1% + [calc ( %y2% - %y1% ) / 2]]
TEXT [quote guideline\value] cr
&end
TEXTSYMBOL %tsl%
TEXTSIZE [calc ( %y2% - %y1% ) / 6]
TEXTCOLOR blue
MOVE [calc %Lxmax% + [calc %xMar% * 2]] [calc %y1% + [calc ( %y2% - %y1% ) / 1.7]]
TEXT [quote %Percentile%%suffix% Percentile] ll
TEXTSYMBOL %tsb%
TEXTCOLOR black
&end
&sv ReportUnit = [open %Report% openstatus -append]
&sv RepHTML = [open %ReportHTML% openstatus -append]
&sv RepHdrHTML = [open %ReportHdrHTML% openstatus -append]
/*&sv rw = [write %ReportUnit% [quote %Station% %Quaternary%: %Description%]]
&sv x = %Lxmin%
TEXTJUSTIFICATION cl
SHADESET colornames
UNITS graph
TEXTSYMBOL %tsm%
TEXTOFFSET 0 0
TEXTJUSTIFICATION cr
&if %xLenDay% > 366 &then
&do
&sv DticP = M
&sv MticP = Y
&end
&else
&do
&sv DticP = D
&sv MticP = M
&end
&if %xLenDay% > [calc 40 * 365.24] &then &sv YletP = YY
&else &sv YletP = Year
linecolor %lcol_light%
&if %BigFont% &then
&do
&sv tsc [show textscale]
TEXTSCALE 0.1
AXISDATE %DticP% YY NoMonth NoDay [calc %cm_Var% / 3.5]
textscale %tsc%
&end
&else
AXISDATE %DticP% %YletP% NoMonth NoDay [calc %cm_Var% / 4]
linecolor 1
&if %Debug% &then &echo &on
TEXTJUSTIFICATION cl
TEXTSCALE 1.5
SHADESET colornames
/* Check for NDATE = 0 (NDATE is the day number since INFO's starting day)
CLEARSELECT %ChemFile% INFO
RESELECT %ChemFile% INFO NDATE <= 0
&if [before [show select %ChemFile% info] ,] > 0 &then &stop CALC NDATE = DATE
&sv NoData_AtAll = .TRUE.
&sv ValList =
&type Drawing bar graphs...
&sv VarList = StNam,Stn,Lat,Lon
&sv rw = [write %RepHdrHTML% [quote StNam | Stn | Lat | Lon | ]]
&sv rw = [write %RepHTML% [quote
---|
%StationName% | %Station% | %Latitude% | %Longitude% | ]]
&call ClearMauchaVar
&sv y2_prev = 0
&do n = 1 &to %nVars%
/* Label the left-hand y-axis with the constituents:
&sv y = [calc %Lymin% + [calc ( %n% - 0.5 ) * %cm_Var% ]]
MOVE [calc %x% - 0.1] %y%
/*textsymbol [calc %n% + 20] /*debug text fonts in PostScript!
&if %BigFont% &then
&do
&sv tsc [show textscale]
TEXTSCALE 2.5
TEXT [value VarAbbr%n%] ur
TEXTSCALE %tsc%
&end
&else
TEXT [value Var%n%] lr
/*TEXT [quote [calc %n% + 20] [value VarAbbr%n%]] lr /*debug text fonts in PostScript!
&sv VarList = %VarList%,[value VarAbbr%n%]min,[value VarAbbr%n%]med,[value VarAbbr%n%]p%Percentile%,[value VarAbbr%n%]max
&if %counter% = 1 &then
&sv rw = [write %RepHdrHTML% [quote [value VarAbbr%n%]min | [value VarAbbr%n%]med | [value VarAbbr%n%]p%Percentile% | [value VarAbbr%n%]max | ]]
&sv y1 = [calc %Lymin% + [calc %n% - 1] * %cm_Var%]
&sv y2 = [calc %Lymin% + [calc %n% - 0.1] * %cm_Var%]
&sv y2_prev = %y2%
GRAPHLIMITS %Lxmin% %y1% %Lxmax% %y2%
linecolor %lcol_light%
/*linecolor gray[calc %n% * 5]
line %Lxmin% %y2% %Lxmax% %y2%
/*&if %n% = %nVars% &then AXISDATE %MticP% NoYear NoMonth NoDay [calc %cm_Var% / 9]
&if %n% > 1 &then AXISDATE %MticP% NoYear NoMonth NoDay [calc %cm_Var% / 5]
/*&if %GL% &then line %Lxmin% %y1% %Lxmax% %y1%
linecolor 1
&if ( %flow% = f and %n% = %nVars% ) &then &call PlotFlow
&else
&call PlotChem
&end
&if %counter% = 1 &then
&sv rw = [write %ReportUnit% [quote %VarList%]]
&sv rw = [write %ReportUnit% [quote %StationName%,%Station%,%Latitude%,%Longitude%%ValList%]]
&sv rw = [write %RepHTML% [quote
]]
&type Drawing the location maps...
MAPPOSITION cen cen
LINESYMBOL 1
markerset mineral
&if %Display% <> n &then &call pri_location
&if %Display% <> n &then &call sec_location
&if %Display% <> n &then &call ter_location
&if %Display% <> n &then &call qat_location
&call datestamp
&call ISOdate
&type Job started on %StartBarcodeTime%
&type Plot finished on %ISOdate%
&if %Display% = s &then &pause
/*&if %Debug% &then &echo &off
&return
/* - - - - - - - - - - - - - - - - -
&routine datestamp
/* Print metadata
UNITS page
/*&sv x1 = [calc 0.75 * %xPage%]
&sv x1 = %Lxmax%
&sv y1 = %yMar% + 0.1
&sv x2 = [calc %xPage% - 0.1 ]
&sv y2 = [calc %yMap% * %yPageSiz%]
/*BOX %x1% %y1% %x2% %y2%
/*move [calc %xPage% - %xMar% ] %yMar%
move %x1% %y2%
textsymbol %tsn%
textscale 0.8
/*textangle 90
&call ISOdate
&sv Address = Resource Quality Services directorate\Department of Water Affairs & Forestry\Private Bag X313 PRETORIA.\tel 012 808 9605, fax 012 808 2702\E-mail: SilberbauerM@dwaf.gov.za
&sv Mauchatext = Maucha diagram explanation:\http://www.dwaf.gov.za/iwqs/gis_apps/maucha.pdf
&sv stntag %Station% nr %counter% of select > %minNsmp% samples
&if %BigFont% &then
&do
TEXT [quote [unquote %ISOdate%\[entryname [quote %Version%]]]] ul
&end
&else
&do
TEXT [quote Metadata:\%stntag%\%Address%\Run %ISOdate% (by %User%)\.] ul
textscale 0.7
TEXT [quote Text in\%Report%\%Mauchatext%\Software:\%Version%] ul
maplimits [calc 1.1 * %xMar%] [calc %yPage% * 0.919] ~
[calc 4.5 * %xMar%] [calc %yPage% * 0.991]
mapposition cen cen
clipmape off
mape %enterprise%/db/clip/dwaf_logo
polygonshades %enterprise%/db/clip/dwaf_logo code
&end
move [calc %x2% - 0.1] [calc %y1% + 0.1]
textangle 0
textscale 1
&return
/* - - - - - - - - - - - - - - - - -
&routine pri_location
&type Drawing primary map:
units page
&sv mapwidth = [calc 0.21 * %xPageSiz%]
&sv xpri1 = [calc %xMar% + 0.1]
&sv ypri1 = [calc %yMar% + 0.1]
&sv xpri2 = [calc %xpri1% + %mapwidth%]
&sv ypri2 = [calc %yMap% * %yPageSiz%]
maplimits %xpri1% %ypri1% %xpri2% %ypri2%
mapextent -759000,-3853000,942000,-2316000
clipmapextent off
clearselect %Province% poly
reselect %Province% poly class = 'Ocean'
polygonshade %Province% 57
clearselect %Province% poly
reselect %Province% poly class = 'Country' and name <> 'LESOTHO' and name <> 'SWAZILAND'
polygonshade %Province% 32
/*ARCS %Province%
CLEARSELECT %Catch_Pri% poly
RESELECT %Catch_Pri% poly primary = [quote %Primary%]
nselect %Catch_Pri% poly
RESELECT %Catch_Pri% poly primary <> 'O'
polygonsHADE %Catch_Pri% 32
polygons %Catch_Pri%
CLEARSELECT %Catch_Pri% poly
RESELECT %Catch_Pri% poly primary = [quote %Primary%]
clearselect %Catch_Sec% poly
reselect %Catch_Sec% poly primary = [quote %Primary%]
linesymbol 1
polygons %Catch_Sec%
UNITS map
markersymbol %MonPtMrk%
markerscale 1.1
markercolor 7
marker %mx% %my%
markerscale 0.9
markercolor 4
marker %mx% %my%
UNITS page
MOVE [extract 3 [show maplimits]] [extract 2 [show maplimits]]
textoffset -0.1 0.1
textmask rectangle 0.02
&if %BigFont% &then
&do
&sv tsc [show textscale]
TEXTSCALE 2.5
TEXT [quote Drainage\region %Primary%] lr
/*TEXT [quote Drainage\region [substr %Station% 1 1]] lr
TEXTSCALE %tsc%
&end
&else
TEXT [quote Drainage\region %Primary%] lr
/*TEXT [quote Drainage\region [substr %Station% 1 1]] lr
linecolor %lcol_light%
BOX [show maplimits]
linecolor 1
textoffset 0 0
textmask none
CLIPMAPEXTENT on
&return
/* - - - - - - - - - - - - - - - - -
&routine sec_location
&type Drawing secondary map:
units page
&sv xsec1 = [calc %xpri2% + 0.1]
&sv ysec1 = %ypri1%
&sv xsec2 = [calc %xsec1% + %mapwidth%]
&sv ysec2 = %ypri2%
maplimits %xsec1% %ysec1% %xsec2% %ysec2%
clearselect %Catch_Pri% poly
/*reselect %Catch_Pri% poly primary = [quote [substr %Station% 1 1]]
/*reselect %Catch_Pri% poly primary = [quote %Primary%]
clearselect %Catch_Sec% poly
reselect %Catch_Sec% poly secondary = [quote %Secondary%]
mapextent poly %Catch_Sec%
clipmapextent off
clearselect %Province% poly
reselect %Province% poly class = 'Ocean'
polygonshade %Province% 57
clearselect %Province% poly
reselect %Province% poly class = 'Country' and name <> 'LESOTHO' and name <> 'SWAZILAND'
polygonshade %Province% 32
/*arcs %Province%
nselect %Catch_Sec% poly
reselect %Catch_Sec% poly primary <> 'O'
polygonshade %Catch_Sec% 33
nselect %Catch_Pri% poly
reselect %Catch_Pri% poly primary <> 'O'
polygonshade %Catch_Pri% 32
clearselect %Catch_Ter% poly
reselect %Catch_Ter% poly secondary = [quote %Secondary%]
arcs %Catch_Ter%
markersymbol %MonPtMrk%
markercolor 7
markerscale 1.85
units map
marker %mx% %my%
markerscale 1.7
markercolor 4
marker %mx% %my%
UNITS page
MOVE [extract 3 [show maplimits]] [extract 2 [show maplimits]]
textoffset -0.1 0.1
textmask rectangle 0.02
&if %BigFont% &then
&do
&sv tsc [show textscale]
TEXTSCALE 2.8
/*TEXT [quote [substr %Station% 1 2]] lr
TEXT [quote %Secondary%] lr
TEXTSCALE %tsc%
&end
&else
/*TEXT [quote [substr %Station% 1 2]] lr
TEXT [quote %Secondary%] lr
linecolor %lcol_light%
BOX [show maplimits]
linecolor 1
textoffset 0 0
textmask none
CLIPMAPEXTENT on
&return
/* - - - - - - - - - - - - - - - - -
&routine ter_location
&type Drawing tertiary map:
units page
&sv xter1 = [calc %xsec2% + 0.1]
&sv yter1 = %ypri1%
&sv xter2 = [calc %xter1% + %mapwidth%]
&sv yter2 = %ypri2%
maplimits %xter1% %yter1% %xter2% %yter2%
clearselect %Catch_Ter% poly
reselect %Catch_Ter% poly tertiary = [quote %Tertiary%]
MAPEXTENT poly %Catch_Ter%
CLIPMAPEXTENT off
&call SearchBox
clearselect %Province% poly
reselect %Province% poly class = 'Ocean'
polygonshade %Province% 57
clearselect %Province% poly
reselect %Province% poly class = 'Country' and name <> 'LESOTHO' and name <> 'SWAZILAND'
polygonshade %Province% 32
nselect %Catch_Ter% poly
reselect %Catch_Ter% poly primary <> 'O'
polygonshade %Catch_Ter% 33
clearselect %Catch_Ter% poly
/*
/*ARCS %Catch_Ter%
clearselect %Towns% poly
polygonshade %Towns% 83
linesymbol 5
arcs %Catch_Qat%
RESELECT %Catch_Ter% poly tertiary = [quote %Tertiary%]
LINESYMBOL 14
polygons %Catch_Ter%
linesymbol 4
linecolor cyan_2
arcs %RiversOut%
&do nOrder = 1 &to 7
&sv width = %nOrder% / 140
&type Rivers of order %nOrder% being drawn with a width of ~
[calc [round [calc 100 * %width%]] / 100]cm:
clearselect %Rivers% arc
reselect %Rivers% arc order = %nOrder%
linesize %width%
arcs %Rivers%
&end
clearselect %Lakes% poly
reselect %Lakes% poly name <> 'Island'
polygonshade %Lakes% 56
overpost 0.1 1.0 0.1
overpost text moveable
overpost on
textalignment automatic
LINESYMBOL 7
/*ARCS %Province%
LINESYMBOL 1
markerSYMBOL %MonPtMrk%
markerSCALE 2.5
markerCOLOR 7
UNITS map
marker %mx% %my%
markerSCALE 2.3
markercolor 4
marker %mx% %my%
UNITS page
reselect %Towns% poly mapextent
reselect %Towns% poly overlap %Catch_Ter% poly
infofile %Towns% poly %BarTmpSrt% area name init
reselect %BarTmpSrt% info name <> ''
&sv nTowns = [extract 1 [show select %BarTmpSrt% info]]
&if %nTowns% > 0 &then
&do
&data ARC INFO
ARC
SELECT [translate [entryname %BarTmpSrt%]]
SORT ON AREA (D)
Q STOP
&end
list %BarTmpSrt% info 1 6
&sv BigTown = [show select %BarTmpSrt% info 1 item name]
&sv BigArea = [show select %BarTmpSrt% info 1 item area]
reselect %Towns% poly name = [quote %BigTown%]
&sv AreaMax = [calc %BigArea% + ( %BigArea% * 0.000001 )]
&sv AreaMin = [calc %BigArea% - ( %BigArea% * 0.000001 )]
reselect %Towns% poly area > %AreaMin% and area < %AreaMax%
labeltext %Towns% nametag cc
&end
overpost off
MOVE [extract 3 [show maplimits]] [extract 2 [show maplimits]]
textoffset -0.1 0.1
textmask rectangle 0.02
&if %BigFont% &then
&do
&sv tsc [show textscale]
TEXTSCALE 2.8
text %Tertiary% lr
TEXTSCALE %tsc%
&end
&else
text %Tertiary% lr
linecolor %lcol_light%
BOX [show maplimits]
linecolor 1
textoffset 0 0
textmask none
markerSCALE 1
CLIPMAPEXTENT on
&return
/* - - - - - - - - - - - - - - - - -
&routine qat_location
&type Drawing quaternary map:
units page
&sv xqat1 = [calc %xter2% + 0.1]
&sv yqat1 = %ypri1%
&sv xqat2 = [calc %xqat1% + %mapwidth%]
&sv yqat2 = %ypri2%
maplimits %xqat1% %yqat1% %xqat2% %yqat2%
clearselect %Catch_Qat% poly
reselect %Catch_Qat% poly quaternary = [quote %Quaternary%]
mapextent poly %Catch_Qat%
clipmapextent off
&call SearchBox
clearselect %Province% poly
reselect %Province% poly class = 'Ocean'
polygonshade %Province% 57
clearselect %Province% poly
reselect %Province% poly class = 'Country' and name <> 'LESOTHO' and name <> 'SWAZILAND'
polygonshade %Province% 32
nselect %Catch_Qat% poly
reselect %Catch_Qat% poly primary <> 'O'
polygonshade %Catch_Qat% 81
clearselect %Catch_Qat% poly
/*
clearselect %Towns% poly
polygonshade %Towns% 83
reselect %Catch_Qat% poly quaternary = [quote %Quaternary%]
linesymbol 14
polygons %Catch_Qat%
linesymbol 4
linecolor cyan_2
arcs %RiversOut%
&do nOrder = 1 &to 7
&sv width = %nOrder% / 70
&type Rivers of order %nOrder% being drawn with a width of ~
[calc [round [calc 100 * %width%]] / 100]cm:
clearselect %Rivers% arc
reselect %Rivers% arc order = %nOrder%
linesize %width%
arcs %Rivers%
&end
clearselect %Lakes% poly
reselect %Lakes% poly name <> 'Island'
polygonshade %Lakes% 56
overpost 0.1 1.0 0.1
overpost text moveable
overpost on
textalignment automatic
linesymbol 7
arcs %Province%
linesymbol 1
&sv mauchsize = 0.4
&if [locase %VarType%] = m &then
&do
&call VerifyMauchaVar
&sv tsc [show textscale]
&sv mauchax = [calc %xMar% * 7]
&sv mauchay = [calc %yPage% - ( 2.5 * %yMar% )]
&if %BigFont% &then
&do
&sv mauchax = [calc %xMar% * 4]
&sv otxs = [show textsize]
textsize [calc [extract 1 %otxs%] * 2]
&end
&if %RunMaucha% &then &run %enterprise%/db/michael/aml/maucha ~
%mauchax% %mauchay% %mauchsize% '' key ~
%mK% 112 %mNa% 83 %mCa% 110 %mMg% 33 %mSO4% 48 %mCl% 71 %mTAL% 56 -1 1 -1 8 /* Outline 1 /*colornames.shd
/*%mK% 6 %mNa% 7 %mCa% 2 %mMg% 14 %mSO4% 4 %mCl% 3 %mTAL% 5 -1 1 -1 8 Outline 1 /*color.shd
/*%mK% 27 %mNa% 27 %mCa% 27 %mMg% 27 %mSO4% 27 %mCl% 27 %mTAL% 27 -1 27 -1 27 Outline 1 /* black
&sv .maucha_variables = ~
%mK% 112 %mNa% 83 %mCa% 110 %mMg% 33 %mSO4% 48 %mCl% 71 %mTAL% 56 -1 1 -1 8
&if %BigFont% &then textsize [extract 1 %otxs%]
textscale %tsc%
&end
markersymbol %MonPtMrk%
markerscale 2.8
markercolor 7
units map
marker %mx% %my%
markerscale 2.5
markercolor 4
marker %mx% %my%
units page
&if ^ %Debug% &then &message &off
clearselect %Rivers% arc
reselect %Rivers% arc mapextent
reselect %Rivers% arc overlap %Catch_Qat% poly
infofile %Rivers% arc %BarTmpSrt% length name order init
textsymbol %tsi%
textcolor blue
reselect %BarTmpSrt% info name <> ''
&sv nRivers = [extract 1 [show select %BarTmpSrt% info]]
&if %nRivers% > 0 &then
&do
&data ARC INFO
ARC
SELECT [translate [entryname %BarTmpSrt%]]
SORT ON ORDER (D), LENGTH (D)
Q STOP
&end
list %BarTmpSrt% info 1 6
&sv BigRiver = [show select %BarTmpSrt% info 1 item name]
&sv BigLength = [show select %BarTmpSrt% info 1 item length]
reselect %Rivers% arc name = [quote %BigRiver%]
&sv LengthMax = [calc %BigLength% + ( %BigLength% * 0.000001 )]
&sv LengthMin = [calc %BigLength% - ( %BigLength% * 0.000001 )]
reselect %Rivers% arc length > %LengthMin% and length < %LengthMax%
arctext %Rivers% name # point2 [calc [extract 1 [show textsize]] / 2.5]
&end
textsymbol %tsm%
reselect %Towns% poly mapextent
reselect %Towns% poly overlap %Catch_Qat% poly
infofile %Towns% poly %BarTmpSrt% area name init
reselect %BarTmpSrt% info name <> ''
&sv nTowns = [extract 1 [show select %BarTmpSrt% info]]
&if %nTowns% > 0 &then
&do
&data ARC INFO
ARC
SELECT [translate [entryname %BarTmpSrt%]]
SORT ON AREA (D)
Q STOP
&end
list %BarTmpSrt% info 1 6
&sv BigTown = [show select %BarTmpSrt% info 1 item name]
&sv BigArea = [show select %BarTmpSrt% info 1 item area]
reselect %Towns% poly name = [quote %BigTown%]
&sv AreaMax = [calc %BigArea% + ( %BigArea% * 0.000001 )]
&sv AreaMin = [calc %BigArea% - ( %BigArea% * 0.000001 )]
reselect %Towns% poly area > %AreaMin% and area < %AreaMax%
labeltext %Towns% nametag cc
&end
reselect %Lakes% poly mapextent
reselect %Lakes% poly overlap %Catch_Qat% poly
reselect %Lakes% poly name <> 'Island'
reselect %Lakes% poly name <> '?'
infofile %Lakes% poly %BarTmpSrt% area name init
textsymbol %tsi%
textcolor blue
reselect %BarTmpSrt% info name <> ''
&sv nLakes = [extract 1 [show select %BarTmpSrt% info]]
&if %nLakes% > 0 &then
&do
&data ARC INFO
ARC
SELECT [translate [entryname %BarTmpSrt%]]
SORT ON AREA (D)
Q STOP
&end
list %BarTmpSrt% info 1 6
&sv BigLake = [show select %BarTmpSrt% info 1 item name]
&sv BigArea = [show select %BarTmpSrt% info 1 item area]
reselect %Lakes% poly name = [quote %BigLake%]
&sv AreaMax = [calc %BigArea% + ( %BigArea% * 0.000001 )]
&sv AreaMin = [calc %BigArea% - ( %BigArea% * 0.000001 )]
reselect %Lakes% poly area > %AreaMin% and area < %AreaMax%
labeltext %Lakes% name cc
&end
textsymbol %tsm%
overpost off
MOVE [extract 3 [show maplimits]] [extract 2 [show maplimits]]
textoffset -0.1 0.1
textmask rectangle 0.02
&if %BigFont% &then
&do
&sv tsc [show textscale]
TEXTSCALE 2.8
TEXT %Quaternary% lr
TEXTSCALE %tsc%
&end
&else
TEXT %Quaternary% lr
linecolor %lcol_light%
BOX [show maplimits]
linecolor 1
textoffset 0 0
textmask none
markerSCALE 1
CLIPMAPEXTENT on
&message &on
&return
/* - - - - - - - - - - - - - - - - -
&routine Print1
/* routine to delete old plot file and send graph to printer:
&sv plot = %PlotName%
&type rotating %plot% to make %plot%r (Landscape)
&if [exists %plot%r.gra -file] &then &sys %remove% [locase %plot%]r.gra
rotateplot %plot% %plot%r
&if [exists %plot%.ps -file] &then &sys %remove% [locase %plot%].ps
&if %Display% = f or %Display% = m &then
&do
&type converting %plot% to %plot%.ps (Postscript)
postscript %plot% %plot%.ps
&end
&else
&do
&type converting %plot%r to %plot%.ps (Postscript)
postscript %plot%r %plot%.ps
&end
&call ISOdate
&if %Debug% &then
&do
&type Debug mode: not printing %plot%.ps: print manually if required!
&type ****************************************************************************
&type %StartBarcodeTime%-%ISOdate% %plot%.ps %plot%r.gra %plot%.gra files kept...
&type ****************************************************************************
&return
&end
&else
&do
&if %Display% = p and %opsys% = SunOS &then
&do
&type Now printing %plot%.ps
&sys lp -c -d hp8000 [locase %plot%].ps
&sys lpstat
&if [exists %plot%.gra -file] &then &sys %remove% [locase %plot%].gra
&if [exists %plot%r.gra -file] &then &sys %remove% [locase %plot%]r.gra
&if [exists %plot%.ps -file] &then &sys %remove% [locase %plot%].ps
&type ****************************************************************************
&type %StartBarcodeTime%-%ISOdate% %plot%.ps %plot%r.gra %plot%.gra files removed
&type ****************************************************************************
&end
&if %Display% = f or %Display% = m or %opsys% = Windows_NT &then
&do
&if [exists %plot%.gra -file] &then &sys %remove% [locase %plot%].gra
&type %opsys% mode: not printing %plot%.ps: print manually if required!
&if [exists %plot%r.gra -file] &then &sys %remove% [locase %plot%]r.gra
&sv PDF_file = %enterprise%/db/iwqs3/tmp/barcode/michael/in/[entryname %plot%.ps]
&if [exists %PDF_file% -file] &then &sys %remove% [locase %PDF_file%]
&sys %move% [locase %plot%.ps] [locase %PDF_file%]
&type ******************************************************************
&type %StartBarcodeTime%-%ISOdate% %plot%.ps moved to %PDF_file%
&type ******************************************************************
&end
&end
&return
/* - - - - - - - - - - - - - - - - -
&routine PageSet
/* set page constants (A4 only in this version):
&if %Display% = s &then
&do
&sv xPageSiz = [extract 1 [show pagesize]]
&sv yPageSiz = [extract 2 [show pagesize]]
&end
&else
&do
&sv xPageSiz = 29.7
&sv yPageSiz = 20.9
&end
&sv xMar = [calc 0.5 * %xPageSiz% / 29.7]
&sv yMar = [calc 0.5 * %yPageSiz% / 20.9]
&sv xPage = [calc %xPageSiz% - %xMar%]
&sv yPage = [calc %yPageSiz% - %yMar%]
&sv Lxmin = 0.084 * %xPageSiz%
&sv Lymin = 0.311 * %yPageSiz%
&sv Lxmax = 0.875 * %xPageSiz%
&sv Lymax = 0.861 * %yPageSiz%
&return
/* - - - - - - - - - - - - - - - - -
&routine FlowCalc
&sv nVars = %nVars% + 1
&sv Var%nVars% = no
&sv Qdir = %FlowDir%
&sv FlowStn = [locase [substr %StationName% 1 6]]
&if [quote [substr %StationName% 3 1]] = [quote H] &then
&do
&sv Var%nVars% = Flow
&sv FlowStn = [locase [substr %StationName% 1 6]A01]
&sv Qdir = %FlowDir%
&end
&if [quote [substr %StationName% 3 1]] = [quote R] &then
&do
&sv Var%nVars% = Level
&sv FlowStn = [locase [substr %StationName% 1 6]]
&sv Qdir = %VolDir%
&end
&if [exists %TempFlowFile% -info] &then &sv deli [delete %TempFlowFile% -info]
&if [exists %QDir%%FlowStn% -file] &then
&do
&DATA arc info
ARC
DFMT YMD-/
DEFINE %TempFlowFile%
DATE , 8,11,D
[upcase [value Var%nVars%]] , 4, 9,F,3
CODE , 1, 1, C
NDATE , 4,10,F,0
ADD FROM %Qdir%%FlowStn%
CALC NDATE = DATE
Q STOP
&end
&sys arc indexitem %TempFlowFile% DATE
&end
&else
&type Sorry - no flow data for station %FlowStn%
&return
/* - - - - - - - - - - - - - - - - -
&routine CheckChem
/* If minNsmp is not zero, then check that at least
/* one variable is present for at least minNsmp samples:
&sv ExistSmp = .FALSE.
&if %minNsmp% <= 0 &then
&do
&sv ExistSmp = .TRUE.
&return
&end
/*&if ^ %Debug% &then &message &off
CLEARSELECT %ChemFile% INFO
/*&if %WMS% &then
/* RESELECT %ChemFile% INFO FEAT_ID = %Feat_ID%
/*&else ~
/* RESELECT %ChemFile% INFO STATION = [quote %StationName%]
reselect %ChemFile% INFO feat_id = %Station%
RESELECT %ChemFile% INFO %DateRange%
WRITESELECT %ChemSel% %ChemFile% INFO
&sv maxnSmp = 0
&sv ExistSmp = .FALSE.
&do nVs = 1 &to %nVariables%
&if [locase [value Var%nVs%]] <> flow &then
&do
/*check that each required value is present
&sv VarNsmp = 0
/*&call WMSstn /* get hex code
/*&if ^ %Debug% &then &message &off
READSELECT %ChemSel% CLEAR
RESELECT %ChemFile% INFO [value Var%nVs%] > 0
/*&if ^ %Debug% &then &message &on
&sv VarNsmp = [before [show select %ChemFile% info] ,]
&if %VarNsmp% > %maxnSmp% &then &sv maxnSmp = %VarNsmp%
&if %VarNsmp% >= %minNsmp% &then
&do
&sv ExistSmp = .TRUE.
&return
&end
&end
&end
&if ^ %ExistSmp% &then
&do
&type (%nStation% of %nStations%) Skipping station %StationName% %Station%: %maxnSmp% < %minNsmp% samples.
&sv rw = [write %ReportUnit% [quote %StationName%,%Station%, skipped: %maxnSmp% < %minNsmp% samples]]
&end
&return
/* - - - - - - - - - - - - - - - - -
&routine PlotChem
&if ^ %Debug% &then &message &off
markersymbol %MonPtMrk%
&if [locase [value Var%n%]] <> flow &then
&do
&sv yMax = null
&sv yMin = null
&if ^ %Debug% &then &message &off
READSELECT %ChemSel% CLEAR
/*CLEARSELECT %ChemFile% INFO
/*&if %WMS% &then
/*&if [type %StationName%] = -1 &then
/*RESELECT %ChemFile% INFO FEAT_ID = %Feat_ID%
/*&else
/*RESELECT %ChemFile% INFO STATION = [quote %StationName%]
/*RESELECT %ChemFile% INFO %DateRange%
RESELECT %ChemFile% INFO [value Var%n%] > 0
&if %PctMaxY% &then
&do
/* create an extra field to hold locations of markers to indicate exceedance.
/* use GP_READING as a placeholder, as we don't use it for anything else:
INFOFILE %ChemFile% INFO %TempChemFile% ndate date [value Var%n%] GP_READING init
&end
&else
&do
INFOFILE %ChemFile% INFO %TempChemFile% ndate date [value Var%n%] init
&end
&if [locase [value Var%n%]] = ph &then &call SetpHval
&sv ndata = [before [show select %ChemFile% info] ,]
&message &on
&if %ndata% > 0 &then
&do
&call Median
&if [locase %VarType%] = m &then &call SetMauchaVar
&call Percentile
&sv NoData_AtAll = .FALSE.
STATISTICS %ChemFile% INFO
max [value Var%n%]
min [value Var%n%]
end
&sv yMax = [calc [show statistic 1 1] ]
&sv yMin = [calc [show statistic 2 1] ]
&if %ndata% = 1 &then &sv yMin = 0
&if %GL% &then
&do
&sv gd0g = .false.
&sv gd0 = [value gd%GLV%_[value VarAbbr%n%]0]
&if %gd0% > 0 &then &sv gd0g = .true.
&sv gd1g = .false.
&sv gd1 = [value gd%GLV%_[value VarAbbr%n%]1]
&if %gd1% > -9 &then &sv gd1g = .true.
&end
&sv VpH = .false.
&if [locase [value Var%n%]] = ph &then
&do
&sv VpH = .true.
/* The graph allows for values from 3 to 11 (7-4 to 7+4)
GRAPHEXTENT %.startday% -4 %.endday% 4 /* allow for values from 3 to 11
UNITS graph
&if %GL% &then
&do
&sv gd0 = %gd0% - 7
&sv gd1 = %gd1% - 7
&call GuideShade
&end
linecolor %lcol_light%
AXIS horizontal %.startday% 0
linecolor black
&if %Display% <> n &then GRAPHBAR %TemppHFile% INFO NDATE pH 1000 # # # ZERO
linecolor 1
&end
&else
&do
&if %PctMaxY% &then
&do
GRAPHEXTENT %.startday% %yMin% %.endday% %PcntVar%
UNITS graph
&DATA arc info
ARC
SELECT [translate %TempChemFile%]
CALC GP_READING = 0
RESELECT [TRANSLATE [value Var%n%]] > %PcntVar%
CALC GP_READING = %PcntVar% * 0.95 /* "^" marker positions
Q STOP
&end
markerscale 0.25
&if %Display% <> n &then GRAPHPOINT %TempChemFile% INFO NDATE GP_READING 225 /* or 125
&if %GL% &then &call GuideShade
markerscale 1
&end
&else
&do
GRAPHEXTENT %.startday% %yMin% %.endday% %yMax%
/*GRAPHBAR %ChemFile% INFO NDATE [value Var%n%] 1
UNITS graph
&if %GL% &then &call GuideShade
&end
linecolor black
&if %Display% <> n &then GRAPHBAR %TempChemFile% INFO NDATE [value Var%n%] 1000
linecolor 1
&end
UNITS page
/* Write the minimum, median, %percentile%th percentile and maximum value
/* for variable n on the right-hand y axis.
/* Do some elementary rounding off...
&sv var_minva = [calc [round [calc 1000 * %yMin%] ] / 1000]
&sv var_medva = [calc [round [calc 100 * %Median%] ] / 100]
&if %Median% < 0.01 &then &sv var_medva = [calc [round [calc 1000 * %Median%]] / 1000]
&if %Median% > 99.9 &then &sv var_medva = [round %Median%]
&sv var_pctva = [calc [round [calc 100 * %PcntVar%]] / 100]
&if %PcntVar% < 0.01 &then &sv var_pctva = [calc [round [calc 1000 * %PcntVar%]] / 1000]
&if %PcntVar% > 99.9 &then &sv var_pctva = [round %PcntVar%]
&sv var_value = [calc [round [calc 100 * %yMax%] ] / 100]
&if %yMax% < 0.01 &then &sv var_value = [calc [round [calc 1000 * %yMax%]] / 1000]
&if %yMax% > 99.9 &then &sv var_value = [round %yMax%]
MOVE [calc %Lxmax% + 0.1] %y2%
&if %BigFont% &then
&do
&if %PctMaxY% &then &sv big_ymax = %var_pctva%
&else &sv big_ymax = %var_value%
&sv tsc [show textscale]
TEXTSCALE 2.5
&sv AbbrQ = mg/L
&if [locase [value Var%n%]] = conductivity &then &sv AbbrQ = mS/m
&if [locase [value Var%n%]] = ph &then &sv AbbrQ =
text [quote %big_ymax% %AbbrQ%] ul
TEXTSCALE %tsc%
&end
&else
&do
&sv AbbrQ = mg/L
&if [locase [value Var%n%]] = conductivity &then &sv AbbrQ = mS/m
&if [locase [value Var%n%]] = ph &then &sv AbbrQ =
TEXTSYMBOL %tsb%
TEXTSIZE [calc ( %y2% - %y1% ) / 4]
MOVE [calc %Lxmax% + 0.1] %y2%
TEXT %var_value% ul
MOVE [calc %Lxmax% + 0.1] %y1%
TEXT %var_minva% ll
MOVE [calc %Lxmax% + [calc %xMar% * 1.5]] [calc %y1% + [calc ( %y2% - %y1% ) / 2]]
TEXT %var_medva% ul
TEXTSYMBOL %tsl%
TEXTSIZE [calc ( %y2% - %y1% ) / 3]
TEXTCOLOR blue
MOVE [calc %Lxmax% + [calc %xMar% * 1.75]] %y2%
TEXT [quote %var_pctva% %AbbrQ% [value VarAbbr%n%]] ul
TEXTSYMBOL %tsb%
TEXTCOLOR black
/*TEXTSTYLE simple
TEXTSYMBOL %tsm%
MOVE [calc %Lxmin% - 0.1] %y1%
TEXT [quote n=%ndata%] lr
&end
&sv ValList = %ValList%,%var_minva%,%var_medva%,%var_pctva%,%var_value%
&sv rw = [write %RepHTML% [quote %var_minva% | %var_medva% | %var_pctva% | %var_value% | ]]
&end
&if %ndata% = 0 &then
&do
&type No data.
MOVE [calc %Lxmax% + 0.1] %y2%
&sv txtscl = [show textscale]
textscale 0.8
TEXT 'No data' ul
textscale %txtscl%
&sv ValList = %ValList%,-9,-9,-9,-9
&sv rw = [write %RepHTML% [quote -9 | -9 | -9 | -9 | ]]
&end
&end
&else
&type Program error - should not try to plot flow here...
&if ^ %Debug% &then &sv deltemp = [delete %TempChemFile% -info]
&message &on
&return
/* - - - - - - - - - - - - - - - - -
&routine PlotFlow
&if [exists %TempFlowFile% -info] &then
&do
CLEARSELECT %TempFlowFile% INFO
RESELECT %TempFlowFile% INFO [value Var%n%] >= 0
RESELECT %TempFlowFile% INFO %DateRange%
INFOFILE %TempFlowFile% INFO %TempChemFile% date [value Var%n%] init
/*INFOFILE FLOWBARC.TMP INFO %TempChemFile% date FLOW init
&sv ndata = [before [show select %TempFlowFile% info] ,]
&if %ndata% > 0 &then
&do
&call Median
&call Percentile
STATISTICS %TempFlowFile% INFO
max [upcase [value Var%nVars%]]
end
&sv Ymax = [calc [show statistic 1 1] ]
&sv ymin = 0
&if %Display% <> n &then
&do
&if %PctMaxY% &then GRAPHEXTENT %.startday% %yMin% %.endday% %PcntVar%
&else GRAPHEXTENT %.startday% %yMin% %.endday% %yMax%
linecolor black
&if %Ymax% > 0 &then GRAPHBAR %TempFlowFile% INFO NDATE [value Var%n%] 1000
linecolor 1
&end
MOVE [calc %Lxmax% + 0.1] %y2%
&sv var_minim = 0
&sv var_median = [calc [round [calc 10 * %Median%] ] / 10]
&sv var_Pcntl = [calc [round [calc 10 * %PcntVar%]] / 10]
&sv var_value = [calc [round [calc 10 * %yMax%] ] / 10]
&if %BigFont% &then
&do
&if %PctMaxY% &then &sv big_ymax %var_Pcntl%
&else &sv big_ymax = %var_value%
&sv tsc [show textscale]
TEXTSCALE 2.5
TEXTSYMBOL %tss%
TEXTSTYLE typeset
&if [value Var%n%] = Level &then
TEXT [quote %big_ymax% m] ul
&else
TEXT [quote %big_ymax% m[unquote '!pat1621;s!pat7318;!pat1619;']] ul
TEXTSTYLE simple
TEXTSYMBOL %tsm%
TEXTSCALE %tsc%
&end
&else
&do
TEXTSYMBOL %tsb%
/*TEXTSTYLE typeset
&if [value Var%n%] = Level &then &sv AbbrQ = m
&else &sv AbbrQ = m3/s
TEXTSIZE [calc ( %y2% - %y1% ) / 4]
MOVE [calc %Lxmax% + 0.1] %y2%
TEXT %var_value% ul
MOVE [calc %Lxmax% + 0.1] %y1%
TEXT %ymin% ll
MOVE [calc %Lxmax% + [calc %xMar% * 1.5]] [calc %y1% + [calc ( %y2% - %y1% ) / 2]]
TEXT %var_median% ul
TEXTSYMBOL %tsl%
TEXTSIZE [calc ( %y2% - %y1% ) / 3]
TEXTCOLOR blue
MOVE [calc %Lxmax% + [calc %xMar% * 1.75]] %y2%
TEXT [quote %var_Pcntl% %AbbrQ%] ul
TEXTSYMBOL %tsb%
TEXTCOLOR black
/*TEXT [quote (%var_Pcntl%) %var_value% m\(%ymin%)(%var_median%)] ul
/*TEXT [quote %var_value%\%var_Pcntl%\%var_median%\%ymin%]
/*TEXT [quote (%var_Pcntl%) %var_value% m[unquote '!pat1621;s!pat7318;!pat1619;']\(%ymin%)(%var_median%)] ul
/*TEXTSTYLE simple
TEXTSYMBOL %tsm%
MOVE [calc %Lxmin% - 0.1] %y1%
TEXT [quote n=%ndata%] lr
&end
&sv ValList = %ValList%,%var_minim%,%var_median%,%var_Pcntl%,%var_value%
&sv rw = [write %RepHTML% [quote %var_minim% | %var_median% | %var_Pcntl% | %var_value% | ]]
&end
&else
&do
&type No [value Var%nVars%] data available in %Qdir%[locase %FlowStn%] for %DateRange%
MOVE [calc %Lxmax% + 0.1] %y2%
TEXT 'No data' ul
&sv ValList = %ValList%,-9,-9,-9,-9
&sv rw = [write %RepHTML% [quote -9 | -9 | -9 | -9 | ]]
&end
&end
&else
&do
&type Sorry - no [value Var%nVars%] data file %Qdir%[locase %FlowStn%]
MOVE [calc %Lxmax% + 0.1] %y2%
TEXT 'No data' ul
&sv ValList = %ValList%,-9,-9,-9,-9
&sv rw = [write %RepHTML% [quote -9 | -9 | -9 | -9 | ]]
&end
&return
/* - - - - - - - - - - - - - - - - -
&routine AlbGeo
&sv GeoString =
&sv GeoLabel =
&sv GeoLabel1 =
&sv GeoLabel2 =
&sv GeoLabel3 =
&sv GeoLabel4 =
/*&if %Display% = n &then &return
&if [exists %BarScratch% -file] &then &ty [delete %BarScratch% -file]
&if [exists %BarPrjScr% -file] &then &ty [delete %BarPrjScr% -file]
&if [exists %BarPrjXY% -file] &then &ty [delete %BarPrjXY% -file]
&if [exists %BarPrjGeo% -file] &then &ty [delete %BarPrjGeo% -file]
&data arc
project file %BarTmpXY% %BarScratch%
input
projection albers
units meters
spheroid clarke1880
parameters
-18 0 0
-32 0 0
24 0 0
00 0 0
0.0
0.0
output
projection geographic
units dms
spheroid clarke1880
parameters
end
quit
&end
&if %opsys% = SunOS &then &sys nawk 'BEGIN {OFS=","}{print $1,$2,$3,$4,$5,$6}' %BarScratch% > %BarTmpGeo%
&else
&sys gawk "BEGIN {OFS=\",\"}{print $1,$2,$3,$4,$5,$6}" %BarScratch% > %BarTmpGeo%
&sv GeoUnit [open %BarTmpGeo% openstatus -read]
&sv GeoCoord [read %GeoUnit% readstatus]
&sv LonD = [extract 1 %GeoCoord%]
&sv LonM = [extract 2 %GeoCoord%]
&sv LonS = [extract 3 %GeoCoord%]
&sv LatD = [extract 4 %GeoCoord%]
&sv LatM = [extract 5 %GeoCoord%]
&sv LatS = [extract 6 %GeoCoord%]
&sv Latitude = [calc %LatD% - [calc %LatM% / 60 ] - [calc %LatS% / 3600 ] ]
&sv Longitude = [calc %LonD% + [calc %LonM% / 60 ] + [calc %LonS% / 3600 ] ]
&sv Latitude = [calc [round [calc 100000 * %Latitude% ]] / 100000]
&sv Longitude = [calc [round [calc 100000 * %Longitude%]] / 100000]
&type %LonD% %LonM% %LonS% = %Longitude%, %LatD% %LatM% %LatS% = %Latitude%
&sv LonS = [round %LonS%]
&sv LatS = [round %LatS%]
&if %LonS% = 60 &then
&do
&sv LonM = %LonM% + 1
&sv LonS = 0
&end
&if %LonM% = 60 &then
&do
&sv LonD = %LonD% + 1
&sv LonM = 0
&end
&if %LonD% > 180 &then &sv LonD = %LonD% - 360
&if %LatS% = 60 &then
&do
&sv LatM = %LatM% + 1
&sv LatS = 0
&end
&if %LatM% = 60 &then
&do
&sv LatD = %LatD% + 1
&sv LatM = 0
&end
&if %LatD% > 90 &then &sv LatD = %Latd% - 90
&sv LonA = [unquote '']
&sv LatA = [unquote '']
&if %LonD% > 0 &then &sv LonA = E
&if %LonD% < 0 &then &sv LonA = W
&if %LatD% > 0 &then &sv LatA = N
&if %LatD% < 0 &then &sv LatA = S
&if %LonM% = 0 &then &sv LonM = 00
&if %LonS% = 0 &then &sv LonS = 00
&if %LatM% = 0 &then &sv LatM = 00
&if %LatS% = 0 &then &sv LatS = 00
&if %LonM% > 0 and %LonM% < 10 &then &sv LonM = 0%LonM%
&if %LonS% > 0 and %LonS% < 10 &then &sv LonS = 0%LonS%
&if %LatM% > 0 and %LatM% < 10 &then &sv LatM = 0%LatM%
&if %LatS% > 0 and %LatS% < 10 &then &sv LatS = 0%LatS%
&sv GeoString = [abs %LatD%]°%LatM%/%LatS%"%LatA% [abs %LonD%]°%LonM%/%LonS%"%LonA%
/*&sv GeoString = [abs %LatD%]%DegSym%%LatM%/%LatS%"%LatA% [abs %LonD%]%DegSym%%LonM%/%LonS%"%LonA%
&sv GeoLabel = [abs %LatD%]°%LatM%/%LatS%"%LatA% [abs %LonD%]°%LonM%/%LonS%"%LonA%
/*&sv GeoLabel = [abs %LatD%]%DegSym%%LatM%/%LatS%"%LatA% [abs %LonD%]%DegSym%%LonM%/%LonS%"%LonA%
&sv GeoLabel1 = [abs %LatD%]%DegSym%%LatM%
&sv GeoLabel2 = %LatS%"%LatA%
&sv GeoLabel3 = [abs %LonD%]%DegSym%%LonM%
&sv GeoLabel4 = %LonS%"%LonA%
&return
&routine SearchBox
&sv SrchArea = [show mapextent]
&return
/*------------------------------------------------------------------------
&routine Median
/* calculate median:
&if %ndata% = 1 &then &sv Median = [show select %TempChemFile% info 1 item [value Var%n%]]
&else
&do
&data ARC INFO
ARC
SELECT [translate [entryname %TempChemFile%]]
SORT ON [translate [value Var%n%]]
Q STOP
q
&end
&sv MedRec = [round [max 1 [calc 0.5 * %ndata%] ] ]
&if %MedRec% > %ndata% &then &sv MedRec = %ndata%
&if [mod %ndata% 2] = 0 &then /* even
&do
&sv MedRec2 = %MedRec% + 1
&sv Median1 = [show select %TempChemFile% info %MedRec% item [value Var%n%]]
&sv Median2 = [show select %TempChemFile% info %MedRec2% item [value Var%n%]]
&sv Median = [calc ( %Median1% + %Median2% ) / 2 ]
&end
&else /* odd
&do
&sv Median = [show select %TempChemFile% info %MedRec% item [value Var%n%]]
&end
&end
&return
/* commented out:
&sv MapexCat = [show mapextent]
&sv Catx1 = [extract 1 %MapexCat%]
&sv Caty1 = [extract 2 %MapexCat%]
&sv Catx2 = [extract 3 %MapexCat%]
&sv Caty2 = [extract 4 %MapexCat%]
&sv Catxlen = [calc %Catx2% - %Catx1%]
&sv Catylen = [calc %Caty2% - %Caty1%]
/* reduce the search area to half the mapextent:
&sv Srchxlen = [calc %Catxlen% / [sqrt 2]]
&sv Srchylen = [calc %Catylen% / [sqrt 2]]
&sv Srchx = [calc %Srchxlen% / 2]
&sv Srchy = [calc %Srchylen% / 2]
&sv Srchx1 = [calc %Catx1% + %Srchx%]
&sv Srchy1 = [calc %Caty1% + %Srchy%]
&sv Srchx2 = [calc %Catx2% - %Srchx%]
&sv Srchy2 = [calc %Caty2% - %Srchy%]
&sv SrchArea = %Srchx1% %Srchy1% %Srchx2% %Srchy2%
&type Mapextent = %MapexCat%
&type SearchArea = %SrchArea%
&return
/*------------------------------------------------------------------------
&routine Percentile
/* Calculate nth percentile. Algorithm supplied by John Carter.
/* Calculate the record, then sort the data for each variable and select the nth percentile.
/* First calculate the (possibly) theoretical ExactRecord for the percentile,
/* then find the two integers surrounding this value:
&if %ndata% = 1 &then
&do
&sv PcntVar = [show select %TempChemFile% info 1 item [value Var%n%]]
&type Special case: single record for [value Var%n%]
&return
&end
&sv PcntRec = [round [max 1 [calc %Percentile% / 100 * %ndata%]]]
&if %PcntRec% > %ndata% &then &sv PcntRec = %ndata%
&sv ExactRec = [calc ( %Percentile% * %ndata% ) / 100 ]
&sv Recd1 [truncate %ExactRec%]
&if %Recd1% < 1 &then &sv Recd1 = 1
&sv Recd2 = [calc %Recd1% + 1]
&if %Recd2% > %ndata% &then &sv Recd2 = %ndata%
&data ARC INFO
ARC
SELECT [translate [entryname %TempChemFile%]]
SORT ON [translate [value Var%n%]]
Q STOP
q
&end
&sv FirstValue = [show select %TempChemFile% INFO %Recd1% item [value Var%n%]]
&sv SecondValue = [show select %TempChemFile% INFO %Recd2% item [value Var%n%]]
/* Interpolate between these two records, by the cunning method of finding out
/* the exact percentile of the two records surrounding the percentile we want:
&sv Val2-1 = [calc %SecondValue% - %FirstValue%]
&sv Pcntile1 = [calc ( %Recd1% / %ndata% ) * 100]
&sv Pcntile2 = [calc ( %Recd2% / %ndata% ) * 100]
&if %Pcntile1% <> %Pcntile2% &then
&do
&sv PcntRatio = [calc ( %Percentile% - %Pcntile1% ) / ( %Pcntile2% - %Pcntile1% ) ]
&sv PcntVar = [calc ( %PcntRatio% * %Val2-1% ) + %FirstValue%]
&end
&else &sv PcntVar = %FirstValue%
&return
/*------------------------------------------------------------------------
&routine SetSuffix
/* 1st 2nd 3rd 4th ... 20th 21st 22nd 23rd 24th ... 30th 31st 32nd 33rd .... 100th
&select %number%
&when 1,21,31,41,51,61,71,81,91
&do
&sv suffix = st
&end
&when 2,22,32,42,52,62,72,82,92
&do
&sv suffix = nd
&end
&when 3,23,33,43,53,63,73,83,93
&do
&sv suffix = rd
&end
&otherwise
&do
&sv suffix = th
&end
&end
&return
/*------------------------------------------------------------------------
&routine ISOdate
/* date in ISO format
&sv ISOdate [date -year]-[substr[date -usa] 1 2]-[substr[date -vmsdate] 1 2] - [before[date -vmstime] .]
&return
/*------------------------------------------------------------------------
&routine SetDefaults
&sv number = %Percentile%; &call SetSuffix
&sv plot dummy
&if [locase %VarType%] = m &then
&do
&sv VarAbbr18 = Q
&sv Var17 = Conductivity; &sv VarAbbr17 = EC
&sv Var16 = TDS ; &sv VarAbbr16 = TDS
&sv Var15 = pH ; &sv VarAbbr15 = pH
&sv Var14 = Calcium ; &sv VarAbbr14 = Ca
&sv Var13 = Magnesium ; &sv VarAbbr13 = Mg
&sv Var12 = Potassium ; &sv VarAbbr12 = K
&sv Var11 = Sodium ; &sv VarAbbr11 = Na
&sv Var10 = TAlkalinity ; &sv VarAbbr10 = TAL
&sv Var9 = Chloride ; &sv VarAbbr9 = Cl
&sv Var8 = Fluoride ; &sv VarAbbr8 = F
&sv Var7 = Silica ; &sv VarAbbr7 = Si
&sv Var6 = Sulphate ; &sv VarAbbr6 = SO4
&sv Var5 = NH4(N) ; &sv VarAbbr5 = NH4_N
&sv Var4 = NO3(N) ; &sv VarAbbr4 = NO3_N
&sv Var3 = KN ; &sv VarAbbr3 = KN
&sv Var2 = PO4(P) ; &sv VarAbbr2 = PO4_P
&sv Var1 = TP ; &sv VarAbbr1 = TP
&sv nVariables = 17
&if %inFile% = Default &then &sv ChemFile = %enterprise%/db/wmrq/wmdata/wq/inorganic.dat
&else &sv ChemFile = %inFile%
/*&sv ChemFile = %enterprise%/db/hri2/waterm/wmdata/wq/inorg_mg.dat
&end
&if [locase %VarType%] = t &then
&do
&sv VarAbbr22 = Q
&sv Var1 = Beryllium ; &sv VarAbbr1 = Be /* Atomic mass 9.01
&sv Var2 = Boron ; &sv VarAbbr2 = B /* Atomic mass 10.81
&sv Var3 = Aluminium ; &sv VarAbbr3 = Al /* Atomic mass 26.98
&sv Var4 = Titanium ; &sv VarAbbr4 = Ti /* Atomic mass 47.88
&sv Var5 = Vanadium ; &sv VarAbbr5 = V /* Atomic mass 50.94
&sv Var6 = Chromium ; &sv VarAbbr6 = Cr /* Atomic mass 52.00
&sv Var7 = Manganese ; &sv VarAbbr7 = Mn /* Atomic mass 54.94
&sv Var8 = Iron ; &sv VarAbbr8 = Fe /* Atomic mass 55.85
&sv Var9 = Nickel ; &sv VarAbbr9 = Ni /* Atomic mass 58.69
&sv Var10 = Cobalt ; &sv VarAbbr10 = Co /* Atomic mass 58.93
&sv Var11 = Copper ; &sv VarAbbr11 = Cu /* Atomic mass 63.55
&sv Var12 = Zinc ; &sv VarAbbr12 = Zn /* Atomic mass 65.39
&sv Var13 = Arsenic ; &sv VarAbbr13 = As /* Atomic mass 74.92
&sv Var14 = Strontium ; &sv VarAbbr14 = Sr /* Atomic mass 87.62
&sv Var15 = Zirconium ; &sv VarAbbr15 = Zr /* Atomic mass 91.22
&sv Var16 = Molybdenum ; &sv VarAbbr16 = Mo /* Atomic mass 95.94
&sv Var17 = Cadmium ; &sv VarAbbr17 = Cd /* Atomic mass 112.41
&sv Var18 = Antimony ; &sv VarAbbr18 = Sb /* Atomic mass 121.76
&sv Var19 = Barium ; &sv VarAbbr19 = Ba /* Atomic mass 137.33
&sv Var20 = Mercury ; &sv VarAbbr20 = Hg /* Atomic mass 200.59
&sv Var21 = Lead ; &sv VarAbbr21 = Pb /* Atomic mass 207.20
&sv nVariables = 21
&if %inFile% = Default &then &sv ChemFile = %enterprise%/db/wmrq/wmdata/wq/tracemetal.dat
&else &sv ChemFile = %inFile%
/*&sv ChemFile = %enterprise%/iwqs/prj/aqces/wq_data/trace.dat
&end
/* set file constants:
&if ^ [exists %ChemFile% -info] &then &stop %ChemFile% does not exist!
&sv StnPnt = %enterprise%/db/cover/s-africa/nms_wms
/*&sv StnPnt = %enterprise%/db/cover/s-africa/nms_his
/*&sv StnPnt = %enterprise%/tmp/staskat/hg_pnts
/*&sv StnPnt = %enterprise%/db/hri2/waterm/wmdata/general/hwq
&sv Province = %enterprise%/db/cover/s-africa/spr_500
&sv Catch_Pri = %enterprise%/db/cover/s-africa/hca_1
&sv Catch_Sec = %enterprise%/db/cover/s-africa/hca_2
&sv Catch_Ter = %enterprise%/db/cover/s-africa/hca_3
&sv Catch_Qat = %enterprise%/db/cover/s-africa/hca_4
&sv Rivers = %enterprise%/db/cover/s-africa/wri_500
&sv RiversOut = %enterprise%/db/cover/s-africa/wri_not_sa
&sv Lakes = %enterprise%/db/cover/s-africa/wla_500
&sv Towns = %enterprise%/db/cover/s-africa/smu_500
&sv FlowDir = %enterprise%/db/iwqs/db/flow/
&sv VolDir = %enterprise%/db/iwqs/db/vol/
&sv Portrait = %enterprise%/db/michael/aml/portrait.hp4
&sv Landscape = %enterprise%/db/michael/aml/landscape.hp4
&sv FormFeed = %enterprise%/db/michael/aml/formfeed.hp4
&sv User = [translate [substr [username] 1 1]][substr [username] 2 [calc [length [username]] - 1]]
&sv unik = [random 10 99][substr [unquote [after [date -ftag] .]] 3 6]
&sv FileName = bc_%unik%
&sv BarTmpLst = BTL%unik%.TMP
&sv BarTmpSrt = BTS%unik%.TMP
&sv BarTmpXY = btxy%unik%.tmp
&sv BarPrjXY = [before %BarTmpXY% .].prj
&sv BarTmpGeo = btgeo%unik%.tmp
&sv BarPrjGeo = [before %BarTmpGeo% .].prj
&sv BarScratch = bscr%unik%.tmp
&sv BarPrjScr = [before %BarScratch% .].prj
&sv TempFlowFile = BF%unik%.TMP
&sv TemppHFile = BP%unik%.TMP
&sv TempChemFile = BC%unik%.TMP
&sv TempTextFile = bc%unik%txt.tmp
&sv ChemSel = cs%unik%
&if %Type% = paper &then &sv lcol_light = gray45
&else &sv lcol_light = gray85
&call ISOdate
&sv ISOyear = [substr [quote %ISOdate%] 1 4]
&sv RepFileID = [subst [quote %ISOdate%] ' ' '']
&sv RepFileID = [subst [quote %RepFileID%] '-' '']
&sv RepFileID = [unquote [subst [quote %RepFileID%] ':' '']]
&if ^ [exists %enterprise%/db/barcode/%ISOyear% -directory] &then
&sys mkdir %enterprise%/db/barcode/%ISOyear%
&sv Report = %enterprise%/db/barcode/%ISOyear%/bc[username]%RepFileID%.txt
&if [exists %Report% -file] &then &sv delf [delete %Report% -file]
&sv ReportHdrHTML = %enterprise%/db/barcode/%ISOyear%/bc[username]%RepFileID%hdr.htm
&if [exists %ReportHdrHTML% -file] &then &sv delf [delete %ReportHdrHTML% -file]
&sv ReportHTML = %enterprise%/db/barcode/%ISOyear%/bc[username]%RepFileID%.htm
&if [exists %ReportHTML% -file] &then &sv delf [delete %ReportHTML% -file]
&sv LogFile = %enterprise%/db/barcode/barcode.log
&call DeleteTempFiles
&sv closeall [close -all]
&sv ReportUnit = [open %Report% openstatus -write]
&sv RepHTML = [open %ReportHTML% openstatus -write]
&sv RepHdrHTML = [open %ReportHdrHTML% openstatus -write]
&type Job run on %ISOdate%
&sv rw = [write %ReportUnit% [quote Data summary on %ISOdate%]]
&sv MonPtMrk = 405
&return
/*------------------------------------------------------------------------
&routine SetGuide
/* Set the guideline values where available or -9
/* 1996 guidelines
&sv GLlist = DHC ALW AGI AAQ IC1 IC2 IC3 IC4 RFC RIC AES
&sv GLisok = .FALSE.
&do GLis &list %GLlist%
&if %GLis% = %GLV% &then &sv GLisok = .TRUE.
&end
&if %GLisok% &then &type setting values for %GLV%
&else &stop %GLV% invalid
&sv gdDHC = 'Domestic human consumption'
&sv gdDHC_EC0 = 0
&sv gdDHC_EC1 = 70
&sv gdDHC_TDS0 = 0
&sv gdDHC_TDS1 = 450
&sv gdDHC_pH0 = 6
&sv gdDHC_pH1 = 9
&sv gdDHC_Ca0 = 0
&sv gdDHC_Ca1 = 32
&sv gdDHC_Mg0 = 0
&sv gdDHC_Mg1 = 30
&sv gdDHC_K0 = 0
&sv gdDHC_K1 = 50
&sv gdDHC_Na0 = 0
&sv gdDHC_Na1 = 100
&sv gdDHC_TAL0 = -9
&sv gdDHC_TAL1 = -9
&sv gdDHC_Cl0 = 0
&sv gdDHC_Cl1 = 100
&sv gdDHC_F0 = 0.0
&sv gdDHC_F1 = 0.7
&sv gdDHC_Si0 = -9
&sv gdDHC_Si1 = -9
&sv gdDHC_SO40 = 0
&sv gdDHC_SO41 = 200
&sv gdDHC_NH4_N0 = 0
&sv gdDHC_NH4_N1 = 1
&sv gdDHC_NO3_N0 = 0
&sv gdDHC_NO3_N1 = 6
&sv gdDHC_KN0 = -9
&sv gdDHC_KN1 = -9
&sv gdDHC_PO4_P0 = -9
&sv gdDHC_PO4_P1 = -9
&sv gdDHC_TP0 = -9
&sv gdDHC_TP1 = -9
&sv gdDHF = 'Domestic human consumption - F'
&sv gdDHF_EC0 = 0
&sv gdDHF_EC1 = 70
&sv gdDHF_TDS0 = 0
&sv gdDHF_TDS1 = 450
&sv gdDHF_pH0 = 6
&sv gdDHF_pH1 = 9
&sv gdDHF_Ca0 = 0
&sv gdDHF_Ca1 = 32
&sv gdDHF_Mg0 = 0
&sv gdDHF_Mg1 = 30
&sv gdDHF_K0 = 0
&sv gdDHF_K1 = 50
&sv gdDHF_Na0 = 0
&sv gdDHF_Na1 = 100
&sv gdDHF_TAL0 = -9
&sv gdDHF_TAL1 = -9
&sv gdDHF_Cl0 = 0
&sv gdDHF_Cl1 = 100
&sv gdDHF_F0 = 0.5
&sv gdDHF_F1 = 0.7
&sv gdDHF_Si0 = -9
&sv gdDHF_Si1 = -9
&sv gdDHF_SO40 = 0
&sv gdDHF_SO41 = 200
&sv gdDHF_NH4_N0 = 0
&sv gdDHF_NH4_N1 = 1
&sv gdDHF_NO3_N0 = 0
&sv gdDHF_NO3_N1 = 6
&sv gdDHF_KN0 = -9
&sv gdDHF_KN1 = -9
&sv gdDHF_PO4_P0 = -9
&sv gdDHF_PO4_P1 = -9
&sv gdDHF_TP0 = -9
&sv gdDHF_TP1 = -9
&sv gdALW = 'Agriculture livestock watering'
&sv gdALW_EC0 = -9
&sv gdALW_EC1 = -9
&sv gdALW_TDS0 = 0
&sv gdALW_TDS1 = 1000
&sv gdALW_pH0 = -9
&sv gdALW_pH1 = -9
&sv gdALW_Ca0 = 0
&sv gdALW_Ca1 = 1000
&sv gdALW_Mg0 = 0
&sv gdALW_Mg1 = 500
&sv gdALW_K0 = -9
&sv gdALW_K1 = -9
&sv gdALW_Na0 = 0
&sv gdALW_Na1 = 2000
&sv gdALW_TAL0 = -9
&sv gdALW_TAL1 = -9
&sv gdALW_Cl0 = 0
&sv gdALW_Cl1 = 2000
&sv gdALW_F0 = 0
&sv gdALW_F1 = 2
&sv gdALW_Si0 = -9
&sv gdALW_Si1 = -9
&sv gdALW_SO40 = 0
&sv gdALW_SO41 = 1000
&sv gdALW_NH4_N0 = -9
&sv gdALW_NH4_N1 = -9
&sv gdALW_NO3_N0 = 0
&sv gdALW_NO3_N1 = 100
&sv gdALW_KN0 = -9
&sv gdALW_KN1 = -9
&sv gdALW_PO4_P0 = -9
&sv gdALW_PO4_P1 = -9
&sv gdALW_TP0 = -9
&sv gdALW_TP1 = -9
&sv gdAGI = 'Agriculture irrigation'
&sv gdAGI_EC0 = 0
&sv gdAGI_EC1 = 40
&sv gdAGI_TDS0 = -9
&sv gdAGI_TDS1 = -9
&sv gdAGI_pH0 = 6.5
&sv gdAGI_pH1 = 8.4
&sv gdAGI_Ca0 = -9
&sv gdAGI_Ca1 = -9
&sv gdAGI_Mg0 = -9
&sv gdAGI_Mg1 = -9
&sv gdAGI_K0 = -9
&sv gdAGI_K1 = -9
&sv gdAGI_Na0 = 0
&sv gdAGI_Na1 = 70
&sv gdAGI_TAL0 = -9
&sv gdAGI_TAL1 = -9
&sv gdAGI_Cl0 = 0
&sv gdAGI_Cl1 = 100
&sv gdAGI_F0 = 0
&sv gdAGI_F1 = 2
&sv gdAGI_Si0 = -9
&sv gdAGI_Si1 = -9
&sv gdAGI_SO40 = -9
&sv gdAGI_SO41 = -9
&sv gdAGI_NH4_N0 = -9
&sv gdAGI_NH4_N1 = -9
&sv gdAGI_NO3_N0 = 0
&sv gdAGI_NO3_N1 = 5
&sv gdAGI_KN0 = -9
&sv gdAGI_KN1 = -9
&sv gdAGI_PO4_P0 = -9
&sv gdAGI_PO4_P1 = -9
&sv gdAGI_TP0 = -9
&sv gdAGI_TP1 = -9
&sv gdAAQ = 'Agriculture aquaculture'
&sv gdAAQ_EC0 = -9
&sv gdAAQ_EC1 = -9
&sv gdAAQ_TDS0 = -9
&sv gdAAQ_TDS1 = -9
&sv gdAAQ_pH0 = 6
&sv gdAAQ_pH1 = 9
&sv gdAAQ_Ca0 = -9
&sv gdAAQ_Ca1 = -9
&sv gdAAQ_Mg0 = -9
&sv gdAAQ_Mg1 = -9
&sv gdAAQ_K0 = -9
&sv gdAAQ_K1 = -9
&sv gdAAQ_Na0 = -9
&sv gdAAQ_Na1 = -9
&sv gdAAQ_TAL0 = 20
&sv gdAAQ_TAL1 = 100
&sv gdAAQ_Cl0 = 0
&sv gdAAQ_Cl1 = 600
&sv gdAAQ_F0 = -9
&sv gdAAQ_F1 = -9
&sv gdAAQ_Si0 = -9
&sv gdAAQ_Si1 = -9
&sv gdAAQ_SO40 = -9
&sv gdAAQ_SO41 = -9
&sv gdAAQ_NH4_N0 = -9
&sv gdAAQ_NH4_N1 = -9
&sv gdAAQ_NO3_N0 = 0
&sv gdAAQ_NO3_N1 = 300
&sv gdAAQ_KN0 = -9
&sv gdAAQ_KN1 = -9
&sv gdAAQ_PO4_P0 = 0
&sv gdAAQ_PO4_P1 = 0.1
&sv gdAAQ_TP0 = -9
&sv gdAAQ_TP1 = -9
&sv gdIC1 = 'Industry category 1'
&sv gdIC1_EC0 = 0
&sv gdIC1_EC1 = 15
&sv gdIC1_TDS0 = 0
&sv gdIC1_TDS1 = 100
&sv gdIC1_pH0 = 7
&sv gdIC1_pH1 = 8
&sv gdIC1_Ca0 = -9
&sv gdIC1_Ca1 = -9
&sv gdIC1_Mg0 = -9
&sv gdIC1_Mg1 = -9
&sv gdIC1_K0 = -9
&sv gdIC1_K1 = -9
&sv gdIC1_Na0 = -9
&sv gdIC1_Na1 = -9
&sv gdIC1_TAL0 = 0
&sv gdIC1_TAL1 = 50
&sv gdIC1_Cl0 = 0
&sv gdIC1_Cl1 = 20
&sv gdIC1_F0 = -9
&sv gdIC1_F1 = -9
&sv gdIC1_Si0 = 0
&sv gdIC1_Si1 = 5
&sv gdIC1_SO40 = 0
&sv gdIC1_SO41 = 30
&sv gdIC1_NH4_N0 = -9
&sv gdIC1_NH4_N1 = -9
&sv gdIC1_NO3_N0 = -9
&sv gdIC1_NO3_N1 = -9
&sv gdIC1_KN0 = -9
&sv gdIC1_KN1 = -9
&sv gdIC1_PO4_P0 = -9
&sv gdIC1_PO4_P1 = -9
&sv gdIC1_TP0 = -9
&sv gdIC1_TP1 = -9
&sv gdIC2 = 'Industry category 2'
&sv gdIC2_EC0 = 0
&sv gdIC2_EC1 = 30
&sv gdIC2_TDS0 = 0
&sv gdIC2_TDS1 = 200
&sv gdIC2_pH0 = 6.5
&sv gdIC2_pH1 = 8
&sv gdIC2_Ca0 = -9
&sv gdIC2_Ca1 = -9
&sv gdIC2_Mg0 = -9
&sv gdIC2_Mg1 = -9
&sv gdIC2_K0 = -9
&sv gdIC2_K1 = -9
&sv gdIC2_Na0 = -9
&sv gdIC2_Na1 = -9
&sv gdIC2_TAL0 = 0
&sv gdIC2_TAL1 = 120
&sv gdIC2_Cl0 = 0
&sv gdIC2_Cl1 = 40
&sv gdIC2_F0 = -9
&sv gdIC2_F1 = -9
&sv gdIC2_Si0 = 0
&sv gdIC2_Si1 = 10
&sv gdIC2_SO40 = 0
&sv gdIC2_SO41 = 80
&sv gdIC2_NH4_N0 = -9
&sv gdIC2_NH4_N1 = -9
&sv gdIC2_NO3_N0 = -9
&sv gdIC2_NO3_N1 = -9
&sv gdIC2_KN0 = -9
&sv gdIC2_KN1 = -9
&sv gdIC2_PO4_P0 = -9
&sv gdIC2_PO4_P1 = -9
&sv gdIC2_TP0 = -9
&sv gdIC2_TP1 = -9
&sv gdIC3 = 'Industry category 3'
&sv gdIC3_EC0 = 0
&sv gdIC3_EC1 = 70
&sv gdIC3_TDS0 = 0
&sv gdIC3_TDS1 = 450
&sv gdIC3_pH0 = 6.5
&sv gdIC3_pH1 = 8
&sv gdIC3_Ca0 = -9
&sv gdIC3_Ca1 = -9
&sv gdIC3_Mg0 = -9
&sv gdIC3_Mg1 = -9
&sv gdIC3_K0 = -9
&sv gdIC3_K1 = -9
&sv gdIC3_Na0 = -9
&sv gdIC3_Na1 = -9
&sv gdIC3_TAL0 = 0
&sv gdIC3_TAL1 = 300
&sv gdIC3_Cl0 = 0
&sv gdIC3_Cl1 = 100
&sv gdIC3_F0 = -9
&sv gdIC3_F1 = -9
&sv gdIC3_Si0 = 0
&sv gdIC3_Si1 = 20
&sv gdIC3_SO40 = 0
&sv gdIC3_SO41 = 200
&sv gdIC3_NH4_N0 = -9
&sv gdIC3_NH4_N1 = -9
&sv gdIC3_NO3_N0 = -9
&sv gdIC3_NO3_N1 = -9
&sv gdIC3_KN0 = -9
&sv gdIC3_KN1 = -9
&sv gdIC3_PO4_P0 = -9
&sv gdIC3_PO4_P1 = -9
&sv gdIC3_TP0 = -9
&sv gdIC3_TP1 = -9
&sv gdIC4 = 'Industry category 4'
&sv gdIC4_EC0 = 0
&sv gdIC4_EC1 = 250
&sv gdIC4_TDS0 = 0
&sv gdIC4_TDS1 = 1600
&sv gdIC4_pH0 = 5
&sv gdIC4_pH1 = 10
&sv gdIC4_Ca0 = -9
&sv gdIC4_Ca1 = -9
&sv gdIC4_Mg0 = -9
&sv gdIC4_Mg1 = -9
&sv gdIC4_K0 = -9
&sv gdIC4_K1 = -9
&sv gdIC4_Na0 = -9
&sv gdIC4_Na1 = -9
&sv gdIC4_TAL0 = 0
&sv gdIC4_TAL1 = 1200
&sv gdIC4_Cl0 = 0
&sv gdIC4_Cl1 = 500
&sv gdIC4_F0 = -9
&sv gdIC4_F1 = -9
&sv gdIC4_Si0 = 0
&sv gdIC4_Si1 = 150
&sv gdIC4_SO40 = 0
&sv gdIC4_SO41 = 500
&sv gdIC4_NH4_N0 = -9
&sv gdIC4_NH4_N1 = -9
&sv gdIC4_NO3_N0 = -9
&sv gdIC4_NO3_N1 = -9
&sv gdIC4_KN0 = -9
&sv gdIC4_KN1 = -9
&sv gdIC4_PO4_P0 = -9
&sv gdIC4_PO4_P1 = -9
&sv gdIC4_TP0 = -9
&sv gdIC4_TP1 = -9
&sv gdRFC = 'Recreation full contact'
&sv gdRFC_EC0 = -9
&sv gdRFC_EC1 = -9
&sv gdRFC_TDS0 = -9
&sv gdRFC_TDS1 = -9
&sv gdRFC_pH0 = 6.5
&sv gdRFC_pH1 = 8.5
&sv gdRFC_Ca0 = -9
&sv gdRFC_Ca1 = -9
&sv gdRFC_Mg0 = -9
&sv gdRFC_Mg1 = -9
&sv gdRFC_K0 = -9
&sv gdRFC_K1 = -9
&sv gdRFC_Na0 = -9
&sv gdRFC_Na1 = -9
&sv gdRFC_TAL0 = -9
&sv gdRFC_TAL1 = -9
&sv gdRFC_Cl0 = -9
&sv gdRFC_Cl1 = -9
&sv gdRFC_F0 = -9
&sv gdRFC_F1 = -9
&sv gdRFC_Si0 = -9
&sv gdRFC_Si1 = -9
&sv gdRFC_SO40 = -9
&sv gdRFC_SO41 = -9
&sv gdRFC_NH4_N0 = -9
&sv gdRFC_NH4_N1 = -9
&sv gdRFC_NO3_N0 = -9
&sv gdRFC_NO3_N1 = -9
&sv gdRFC_KN0 = -9
&sv gdRFC_KN1 = -9
&sv gdRFC_PO4_P0 = -9
&sv gdRFC_PO4_P1 = -9
&sv gdRFC_TP0 = -9
&sv gdRFC_TP1 = -9
&sv gdRIC = 'Recreation intermediate contact'
&sv gdRIC_EC0 = -9
&sv gdRIC_EC1 = -9
&sv gdRIC_TDS0 = -9
&sv gdRIC_TDS1 = -9
&sv gdRIC_pH0 = -9
&sv gdRIC_pH1 = -9
&sv gdRIC_Ca0 = -9
&sv gdRIC_Ca1 = -9
&sv gdRIC_Mg0 = -9
&sv gdRIC_Mg1 = -9
&sv gdRIC_K0 = -9
&sv gdRIC_K1 = -9
&sv gdRIC_Na0 = -9
&sv gdRIC_Na1 = -9
&sv gdRIC_TAL0 = -9
&sv gdRIC_TAL1 = -9
&sv gdRIC_Cl0 = -9
&sv gdRIC_Cl1 = -9
&sv gdRIC_F0 = -9
&sv gdRIC_F1 = -9
&sv gdRIC_Si0 = -9
&sv gdRIC_Si1 = -9
&sv gdRIC_SO40 = -9
&sv gdRIC_SO41 = -9
&sv gdRIC_NH4_N0 = -9
&sv gdRIC_NH4_N1 = -9
&sv gdRIC_NO3_N0 = -9
&sv gdRIC_NO3_N1 = -9
&sv gdRIC_KN0 = -9
&sv gdRIC_KN1 = -9
&sv gdRIC_PO4_P0 = -9
&sv gdRIC_PO4_P1 = -9
&sv gdRIC_TP0 = -9
&sv gdRIC_TP1 = -9
&sv gdAES = 'Aquatic ecosystems'
&sv gdAES_EC0 = -9
&sv gdAES_EC1 = -9
&sv gdAES_TDS0 = -9
&sv gdAES_TDS1 = -9
&sv gdAES_pH0 = -9
&sv gdAES_pH1 = -9
&sv gdAES_Ca0 = -9
&sv gdAES_Ca1 = -9
&sv gdAES_Mg0 = -9
&sv gdAES_Mg1 = -9
&sv gdAES_K0 = -9
&sv gdAES_K1 = -9
&sv gdAES_Na0 = -9
&sv gdAES_Na1 = -9
&sv gdAES_TAL0 = -9
&sv gdAES_TAL1 = -9
&sv gdAES_Cl0 = -9
&sv gdAES_Cl1 = -9
&sv gdAES_F0 = 0
&sv gdAES_F1 = 0.75
&sv gdAES_Si0 = -9
&sv gdAES_Si1 = -9
&sv gdAES_SO40 = -9
&sv gdAES_SO41 = -9
&sv gdAES_NH4_N0 = -9
&sv gdAES_NH4_N1 = -9
&sv gdAES_NO3_N0 = -9
&sv gdAES_NO3_N1 = -9
&sv gdAES_KN0 = -9
&sv gdAES_KN1 = -9
&sv gdAES_PO4_P0 = -9
&sv gdAES_PO4_P1 = -9
&sv gdAES_TP0 = -9
&sv gdAES_TP1 = -9
&return
/*------------------------------------------------------------------------
&routine CheckDate
/* check and set date limits:
&sv MonList = Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
&type Checking %Year1% and %Year2%
&if [type %Year1%] > 0 &then /* assume 1984-01-01 format
&do
&sv ISOdate1 = %Year1%
&sv Year1 = [substr %ISOdate1% 1 4]
&sv Mon1 = [substr %ISOdate1% 6 2]
&sv nMon = 0
&sv Month1 = Xxx
&do Mon &list %MonList%
&sv nMon = %nMon% + 1
&if %nMon% = %Mon1% &then &sv Month1 = %Mon%
&end
&sv Day1 = [substr %ISOdate1% 9 2]
&sv Date1 = %Day1%-%Month1%-%Year1%
&end
&else /* assume 1984 format
&do
&sv Date1 = 1-Jan-%Year1%
&sv ISOdate1 = %Year1%-01-01
&end
&if [type %Year2%] > 0 &then /* assume 1984-01-01 format
&do
&sv ISOdate2 = %Year2%
&sv Year2 = [substr %ISOdate2% 1 4]
&sv Mon2 = [substr %ISOdate2% 6 2]
&sv nMon = 0
&sv Month2 = Xxx
&do Mon &list %MonList%
&sv nMon = %nMon% + 1
&if %nMon% = %Mon2% &then &sv Month2 = %Mon%
&end
&sv Day2 = [substr %ISOdate2% 9 2]
&sv Date2 = %Day2%-%Month2%-%Year2%
&end
&else /* assume 1984 format
&do
&sv Date2 = 31-Dec-%Year2%
&sv ISOdate2 = %Year2%-12-31
&end
&if %Year1% < 1000 or %Year2% < 1000 &then &stop Please use 4-digit years!
/* Arc8 requires delimiters (/ or -) in dates:
&sv DateRange = DATE >= %ISOdate1% & DATE <= %ISOdate2%
date2day %Date1% .startday
date2day %Date2% .endday
&sv counter = 0
&sv ReadStatus = 0
&sv Page = 1
&return
/*------------------------------------------------------------------------
&routine DeleteTempFiles
&if [exists %Report%r -file] &then &sv delf [delete %Report%r -file]
&if [exists %BarTmpXY% -file] &then &sv delf [delete %BarTmpXY% -file]
&if [exists %BarTmpGeo% -file] &then &sv delf [delete %BarTmpGeo% -file]
&if [exists %BarTmpLst% -info] &then &sv delf [delete %BarTmpLst% -info]
&if [exists %BarTmpSrt% -file] &then &sv delf [delete %BarTmpSrt% -file]
&if [exists %BarTmpSrt% -info] &then &sv delf [delete %BarTmpSrt% -info]
&if [exists %BarPrjXY% -file] &then &sv delf [delete %BarPrjXY% -file]
&if [exists %BarPrjGeo% -file] &then &sv delf [delete %BarPrjGeo% -file]
&if [exists %BarScratch% -file] &then &sv delf [delete %BarScratch% -file]
/*&ty BarPrjScr %BarPrjScr%
&if [exists %BarPrjScr% -file] &then &sv delf [delete %BarPrjScr% -file]
&if [exists %TempChemFile% -info] &then &sv delf [delete %TempChemFile% -info]
&if [exists %TempFlowFile% -info] &then &sv delf [delete %TempFlowFile% -info]
&if [exists %TemppHFile% -info] &then &sv delf [delete %TemppHFile% -info]
&if [exists %TempTextFile% -file] &then &sv delf [delete %TempTextFile% -file]
&if [exists %TempTextFile% -info] &then &sv delf [delete %TempTextFile% -info]
/*&ty ChemSel %ChemSel% and ChemSelx %ChemSel%x
&if [exists %ChemSel% -file] &then &sv delf [delete %Chemsel% -file]
&if [exists %ChemSel%x -file] &then &sv delf [delete %Chemsel%x -file]
&return
/*------------------------------------------------------------------------
&routine SetMauchaVar
/* seems a bit too hard-coded... when Maucha goes wrong, look here!
&select %n%
&when 16
&sv mpH = %Median%
&when 15
&sv mTDS = %Median%
&when 14
&sv mCa = %Median%
&when 13
&sv mMg = %Median%
&when 12
&sv mK = %Median%
&when 11
&sv mNa = %Median%
&when 10
&sv mTAL = %Median%
&when 9
&sv mCl = %Median%
/*&when 7
/*&sv mSi = %Median%
&when 6
&sv mSO4 = %Median%
&end
&return
/*------------------------------------------------------------------------
&routine ClearMauchaVar
&sv mpH = -9
&sv mTDS = -9
&sv mCa = -9
&sv mMg = -9
&sv mK = -9
&sv mNa = -9
&sv mTAL = -9
&sv mCl = -9
/*&sv mSi = -9
&sv mSO4 = -9
&return
/*------------------------------------------------------------------------
&routine VerifyMauchaVar
&sv RunMaucha = .true.
/*&if %mpH% < 0 &then &sv RunMaucha = .false.
/*&if %mTDS% < 0 &then &sv RunMaucha = .false.
&if %mCa% < 0 &then &sv RunMaucha = .false.
&if %mMg% < 0 &then &sv RunMaucha = .false.
&if %mK% < 0 &then &sv RunMaucha = .false.
&if %mNa% < 0 &then &sv RunMaucha = .false.
&if %mTAL% < 0 &then &sv RunMaucha = .false.
&if %mCl% < 0 &then &sv RunMaucha = .false.
/*%&if %mSi% < 0 &then &sv RunMaucha = .false.
&if %mSO4% < 0 &then &sv RunMaucha = .false.
&if %RunMaucha% = .false. &then &type Sorry, not enough data for the Maucha diagram.
&return
/*------------------------------------------------------------------------
&routine SetpHval
INFOFILE %ChemFile% INFO %TemppHFile% date ndate [value Var%n%] init
&DATA arc info
ARC
SELECT %TemppHFile%
CALC PH = PH - 7
Q STOP
&end
&return
/*~~~~~~~~~~~~~~~~~~~~~~~~~~
&routine stnWMS
/* remove this and use FEAT_ID
WMSstation = %Feat_ID%
&return
/* convert an encoded WMS station back to its original form:
/* expects string %WMShexcode%, returns string %WMSstation%
/* delete the initial letter I (if present!):
&sv hexstr = [quote %WMShexcode%]
&sv hexstr = [subst %hexstr% 'O' '']
&sv hexval = 0
&sv hexpos = 0
&do i = [length %hexstr%] &to 1 &by -1
&sv c = [substr %hexstr% %i% 1]
&if [type %c%] = -1 &then &sv hexval = [calc %hexval% + [calc %c% * [calc 16 ** %hexpos% ] ] ]
&else
&do
&select %c%
&when A ; &sv hexval = [calc %hexval% + [calc 10 * [calc 16 ** %hexpos% ] ] ]
&when B ; &sv hexval = [calc %hexval% + [calc 11 * [calc 16 ** %hexpos% ] ] ]
&when C ; &sv hexval = [calc %hexval% + [calc 12 * [calc 16 ** %hexpos% ] ] ]
&when D ; &sv hexval = [calc %hexval% + [calc 13 * [calc 16 ** %hexpos% ] ] ]
&when E ; &sv hexval = [calc %hexval% + [calc 14 * [calc 16 ** %hexpos% ] ] ]
&when F ; &sv hexval = [calc %hexval% + [calc 15 * [calc 16 ** %hexpos% ] ] ]
&otherwise ; &stop Error in routine stnWMS
&end
&end
&sv hexpos = %hexpos% + 1
&end
&if %Debug% &then &type %Station% %WMSstation%
&return
/*~~~~~~~~~~~~~~~~~~~~~~~~~~
&routine WMSstn
/* By-pass this expensive step:
&sv WMShexcode = 'BAD0BAD0'
&return
/* Deal with the difference between WMS and STASKAT stations.
/* Shorten the codes by converting to hexadecimal:
/* expects string %Station%, returns string %WMShexcode%
/* Derived from the algorithm by Tim Sherwood, "Some Useful Gawk Scripts"
/* http://www.cs.ucsb.edu/~sherwood/awk/ (accessed 2005-11-29)
&sv WMS = .TRUE.
&sv intval = [unquote %Station%]
&sv Feat_ID = %Station%
&sv maxhex = 8
&sv hexstr =
&if %intval% >= [calc 16 ** [calc %maxhex% + 1]] &then &stop %intval% >= 16 ** [calc %maxhex% + 1]
&sv val = %intval%
&do i = %maxhex% &to 0 &by -1
&sv c = [calc 16 ** %i%]
&if %c% > %val% &then &sv hexstr = %hexstr%0
&else
&do
&sv n = [truncate [calc %val% / %c%]]
&select %n%
&when 10 ; &sv digit = A
&when 11 ; &sv digit = B
&when 12 ; &sv digit = C
&when 13 ; &sv digit = D
&when 14 ; &sv digit = E
&when 15 ; &sv digit = F
&otherwise ; &sv digit = %n%
&end
&sv hexstr = %hexstr%%digit%
&sv val = [calc %val% - [calc %n% * [calc 16 ** %i%]]]
&end
&end
&sv WMShexcode = %hexstr%
&return
/*------------------------------------------------------------------------
&routine WMSstn_old
/* Deal with the difference between WMS and STASKAT stations.
/* Shorten the codes by replacing consecutive zeroes:
&sv WMS = .TRUE.
&sv WMSstation = [quote %Station%]
&sv Feat_ID = %WMSstation%
/* replace strings of zeroes with letters:
&sv WMSstation = [subst %WMSstation% '0000000000' 'Z']
&sv WMSstation = [subst %WMSstation% '000000000' 'Y']
&sv WMSstation = [subst %WMSstation% '00000000' 'X']
&sv WMSstation = [subst %WMSstation% '0000000' 'W']
&sv WMSstation = [subst %WMSstation% '000000' 'V']
&sv WMSstation = [subst %WMSstation% '00000' 'U']
&sv WMSstation = [subst %WMSstation% '0000' 'T']
&sv WMSstation = [subst %WMSstation% '000' 'S']
&sv WMSstation = [subst %WMSstation% '00' 'R']
&sv WMSstation = [subst %WMSstation% '0' 'Q']
&sv WMSstation = O[unquote %WMSstation%]
&sv Station = %WMSstation%
/*&call stnWMS
/*&type %WMSstation%
/*&stop %AML$file% cannot handle this format yet.
&return
/*------------------------------------------------------------------------
&routine stnWMS_old
/* convert an encoded WMS station back to its original form:
/* delete the initial letter O (oh):
&sv WMSstation = [subst %Station% 'O' '']
/* replace letters with strings of zeroes:
&sv WMSstation = [subst %WMSstation% 'Z' '0000000000']
&sv WMSstation = [subst %WMSstation% 'Y' '000000000']
&sv WMSstation = [subst %WMSstation% 'X' '00000000']
&sv WMSstation = [subst %WMSstation% 'W' '0000000']
&sv WMSstation = [subst %WMSstation% 'V' '000000']
&sv WMSstation = [subst %WMSstation% 'U' '00000']
&sv WMSstation = [subst %WMSstation% 'T' '0000']
&sv WMSstation = [subst %WMSstation% 'S' '000']
&sv WMSstation = [subst %WMSstation% 'R' '00']
&sv WMSstation = [subst %WMSstation% 'Q' '0']
&return
/*------------------------------------------------------------------------
&routine SetOS
&sv opsys = [extract 1 [show &os] ]
&if %opsys% = SunOS &then
&do
&sv enterprise = /hri
&sv tempdir = %enterprise%/db/iwqs3/tmp/
&sv NL = \
&sv remove = \rm
&sv listdir = \ls -l
&sv listfile = \cat
&sv dirsep = /
&sv sorti = sort -f -o
&sv copy = cp
&sv move = mv
/*&sv DegSym = °
&sv DegSym = [unquote '!sup;o!bak;']
&sv awk = nawk
&end
&if %opsys% = Windows_NT &then
&do
&sv enterprise = N:
&sv tempdir = C:\Temp\catalog\
&sv NL = /& /* ?
&sv remove = del
&sv listdir = dir
&sv listfile = type
&sv dirsep = \
&sv sorti = [unquote 'sort /o ']
&sv copy = copy
&sv move = move
&sv Version = [unquote [subst [quote %Version%] '\' '/']]
/*&sv DegSym = °
&sv DegSym = [unquote '!sup;o!bak;']
&sv awk = gawk /* not entirely interchangeable...
&end
&return
/*------------------------------------------------------------------------
&routine GuideShade
&if %Debug% &then &echo &on
&sv ptx1 = [extract 1 [show graphextent]]
&sv pty1 = [extract 2 [show graphextent]]
&sv ptx2 = [extract 3 [show graphextent]]
&sv pty2 = [extract 4 [show graphextent]]
&sv ptwx = [calc %ptx2% - %ptx1%] /* graph width, graph units
&sv pthy = [calc %pty2% - %pty1%] /* graph height, graph units
&sv ptx1 = [calc %ptx1% + ( 0.002 * %ptwx% )]
/*&sv pty1 = [calc %pty1% + ( 0.020 * %ptwx% )]
&sv pty2 = [calc %pty1% + ( 0.990 * %pthy% )]
&sv ptx2 = [calc %ptx1% + ( 0.990 * %ptwx% )]
shadesymbol 81
&sv otxsym = [show textsymbol]
&sv otxsca = [show textscale]
textsymbol 1
&if %BigFont% &then textscale 1.5
&else textscale 0.9
textmask rectangle 0.02
&if %gd0g% &then
&do
&sv gtxtx = %ptx2%
&sv gtxty = %pty1%
&sv gtxt = >%gd0%;&if %VpH% &then &sv gtxt = [calc %gd0% + 7]
&if %pty1% < %gd0% &then
&do
patch %ptx1% %pty1% %ptx2% %gd0%
&sv gtxty = %gd0%
&sv gtxt = %gd0%;&if %VpH% &then &sv gtxt = [calc %gd0% + 7]
&sv gtxtp = ur
&end
move %gtxtx% %gtxty%
text %gtxt% %gtxtp%
&end
&if %gd1g% &then
&do
&sv gtxtx = %ptx2%
&sv gtxty = %pty2%
&sv gtxt = <%gd1%;&if %VpH% &then &sv gtxt = [calc %gd1% + 7]
&sv gtxtp = ur
&if %gd1% < %pty2% &then
&do
patch %ptx1% %gd1% %ptx2% %pty2%
&sv gtxty = %gd1%
&sv gtxt = %gd1%;&if %VpH% &then &sv gtxt = [calc %gd1% + 7]
&sv gtxtp = lr
&end
move %gtxtx% %gtxty%
text %gtxt% %gtxtp%
&end
/*&if %Debug% &then &echo &off
textsymbol %otxsym%
textscale %otxsca%
textmask none
&return
/*------------------------------------------------------------------------
&routine isWMS
/* Pattern recognition to determine what kind of input is in the Station field.
/* Example Type
/* ========== ===========================================================================
/* $ All stations in database (used in input line only)
/* B Quaternary drainage region (all stations within - used in input line only)
/* A2H027Q01 Hydro or STASKAT station code (single)
/* 1000000089 WMS feature ID (single)
/* I03B9ACA59 WMS feature ID compressed to hexadecimal (single)
/* 2230CC00222 Groundwater monitoring code (single)
&sv Single = .FALSE.
&sv WMS = .FALSE.
&sv isZstn = .FALSE.
&sv unresolved = .FALSE.
&if [type %Station%] = -1 &then /* number input
&do
&type Assuming %Station% integer value is WMS Feat_ID
&sv Single = .TRUE.
&sv WMS = .TRUE.
&sv Feat_ID = %Station% * 1
&sv WMSstation = %Feat_ID%
&call WMSstn /* to convert hexadecimal code to WMS numerical station
&type Hexadecimal code %WMShexcode% is WMS numerical %WMSstation%
&return
&end
&select [length %Station%]
&when 1
&if %Station% = $ &then
&do
&type Selecting ALL stations
&sv Single = .FALSE.
&sv WMS = .FALSE.
&end
&else
&do
&type Assuming %Station% single character is Quaternary letter
&sv Single = .FALSE.
&sv WMS = .FALSE.
&sv CatQat = %Station%
&end
&when 9
&do
&sv Single = .TRUE.
&sv WMS = .FALSE.
&sv is1char = .FALSE.
&if [type [translate [substr %Station% 1 1]]] = 1 &then
&do
&sv is1char = .TRUE.
&type First character of %Station% is non-numeric
&end
&else
&do
&type Could not resolve Station code %Station%
&sv unresolved = .TRUE.
&return
&end
&if [locase [substr [quote %Station%] 1 1]] = 'z' &then
&do
&type First character of %Station% is Z: ad hoc sample
&sv isZstn = .TRUE.
&end
&end
&when 10
&do
&sv Single = .TRUE.
&sv WMS = .TRUE.
&if [type [substr %Station% 1 1] = -1] &then
&do
&call WMSstn
&type assuming %Station% is WMS Feat_ID = hexadecimal code %WMShexcode%
&end
&else
&if [substr %Station% 1 1] = I &then
&do
&sv WMShexcode = %Station%
&call WMSstn /* to convert hexadecimal code to WMS numerical station
&type Hexadecimal code %Station% is WMS numerical %WMSstation%
&end
&end
&when 11
&do
&sv Single = .TRUE.
&sv WMS = .TRUE.
&type Sorry, cannot use borehole station %Station% yet, please use WMS code.
&sv unresolved = .TRUE.
&return
&end
&otherwise
&do
&if [locase [substr [quote %Station%] 1 1]] = 'z' &then
&do
&type First character of %Station% is Z: ad hoc sample
&sv isZstn = .TRUE.
&sv Single = .TRUE.
&sv WMS = .FALSE.
&sv is1char = .FALSE.
&end
&else
&do
&type Could not resolve Station code %Station%
&sv unresolved = .TRUE.
&return
&end
&end
&end
&return
/*------------------------------------------------------------------------
&routine mauchapetit
/* generate a tiny jpeg of the current maucha:
ArcPlot
display 9999
display size canvas 64 64
SHADESET colornames
&sv mauchax = [calc [extract 1 [show pagesize]] * 0.5 ]
&sv mauchay = [calc [extract 2 [show pagesize]] * 0.5 ]
&if %RunMaucha% &then &r /hri/db/michael/aml/maucha %mauchax% %mauchay% 0.2 '' nokey %.maucha_variables%
&else
&do
move %mauchax% %mauchay%
text 'X' cc /* No data
&end
/* allocate names for the JPEG files:
&sv maucjpg = [locase %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL%/%PlotName%.jpg]
&sv maucras = [locase %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL%/%PlotName%.ras]
&sv maucjgw = [locase %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL%/%PlotName%.jgw]
&if [exists temp%unik%.ras -file] &then &sv dt [delete temp%unik%.ras -file]
&if [exists temp%unik%.rasw -file] &then &sv dt [delete temp%unik%.rasw -file]
screensave temp%unik%.ras
Quit
&type Converting graphics file temp.ras into %maucjpg% with world file %maucjgw%...
&if [exists %maucjpg% -file] &then &sv deljpg [delete %maucjpg% -file]
&if [exists %maucras% -file] &then &sv delras [delete %maucras% -file]
&if [exists %maucjgw% -file] &then &sv deljgw [delete %maucjgw% -file]
convertimage temp%unik%.ras %maucjpg% jfif
/*&sys %copy% temp%unik%.ras %maucras%
&if [exists %maucjgw% -file] &then &sv deljgw [delete %maucjgw% -file]
&if [exists temp%unik%.ras -file] &then &sv delras [delete temp%unik%.ras -file]
&if [exists temp%unik%.rasw -file] &then &sv delrsw [delete temp%unik%.rasw -file]
&return
/*------------------------------------------------------------------------
&routine bartextfile_tables
/* export the data to a text file:
/* this is not working too well, so we need a different approach...
&if [exists %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL% -directory] &then ~
&type Output will go to %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL%
&else &sys mkdir %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL%
&sv btf = [locase %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL%/%PlotName%.txt]
&sv btf = [locase %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL%/hdrbtftmp%unik%.txt]
&if [exists %btf% -file] &then &sv dbtf [delete %btf% -file]
&if [exists %hdrbtf% -file] &then &sv dbtf [delete %hdrbtf% -file]
listoutput %hdrbtf%
items %ChemFile%
listoutput screen
&sv curwrkspc = [show workspace]
workspace [dir %ChemFile%]
&sv eChemFile = [entryname %ChemFile%]
&if %opsys% = SunOS &then &sys nawk 'BEGIN{l=""}{if(NR>1)l=l$2","}END{print l}' %hdrbtf% > %btf%
&else
&sys gawk "BEGIN {l=\"\"}{if(NR>1)l=l$2\",\"}END{print l}" %hdrbtf% > %btf%
/*nawk 'BEGIN{l=""}{if(NR>1)l=l$2","}END{print l}' %hdrbtf% > %btf%
&if %WMS% &then
/*&if [type %StationName%] = -1 &then
&do
&data ARC tables
select %eChemFile%
/*reselect STATION = [quote %WMShexcode%]
reselect FEAT_ID = Feat_ID
reselect %DateRange%
unload %btf%
q stop
q
&end
&end
&else
&do
&data ARC tables
select %eChemFile%
reselect STATION = [quote %StationName%]
reselect %DateRange%
unload %btf%
q stop
q
&end
&end
&if [exists %btf% -file] &then &sv dbtf [delete %btf% -file]
&if [exists %hdrbtf% -file] &then &sv dbtf [delete %hdrbtf% -file]
workspace %curwrkspc%
&return
/*------------------------------------------------------------------------
&routine bartextfile
/* Export the data to a text file.
/* Prepare a file for export:
READSELECT %ChemSel% CLEAR
/*CLEARSELECT %ChemFile% INFO
/*&if %WMS% &then
/*&if [type %StationName%] = -1 &then
/*RESELECT %ChemFile% INFO FEAT_ID = %Feat_ID%
/*&else ~
/*RESELECT %ChemFile% INFO STATION = [quote %StationName%]
/*RESELECT %ChemFile% INFO %DateRange%
INFOFILE %ChemFile% INFO %TempTextFile% INIT
&if [exists %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL% -directory] &then ~
&type Output will go to %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL%
&else &sys mkdir %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL%
&sv btf = [locase %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL%/%PlotName%.txt]
&sv hdrbtf = [locase %enterprise%/db/iwqs3/tmp/barcode/michael/out/%TertiaryL%/hdrbtftmp%unik%.txt]
&if [exists %btf% -file] &then &sv dbtf [delete %btf% -file]
&if [exists %hdrbtf% -file] &then &sv dbtf [delete %hdrbtf% -file]
listoutput %hdrbtf%
items %TempTextFile%
listoutput screen
&sv eTempTextFile = [entryname %TempTextFile%]
&setchar &separator '?'
&if %opsys% = SunOS &then &sys nawk 'BEGIN{l="";ok=1}{if($2=="REDEFINED")ok=0;if(NR>2&&ok)l=l$2","}END{print l}' %hdrbtf% > %btf%
&else
&sys gawk "BEGIN {l=\"\";ok=1}{if($2==\"REDEFINED\")ok=0;if(NR>2&&ok)l=l$2\",\"}END{print l}" %hdrbtf% > %btf%
&setchar &separator ';'
/*&sys %awk% 'BEGIN{l="";ok=1}{if($2=="REDEFINED")ok=0;if(NR>2&&ok)l=l$2","}END{print l}' %hdrbtf% > %btf%
&data ARC INFO
ARC
DFMT YMD-/
SELECT [translate [entryname %TempTextFile%]]
EXPORT %btf% SDF APPEND
Q STOP
&end
&if %opsys% = SunOS &then &sys gzip -f %btf%
&else &sys pkzipc -add %btf% %btf%
&if [exists %btf% -file] &then &sv dbtf [delete %btf% -file]
&if [exists %hdrbtf% -file] &then &sv dbtf [delete %hdrbtf% -file]
&return