' '----------------- '----------------- '--- HECPREPRO --- '----------------- '----------------- ' '---------------------------- '--- creation information --- '---------------------------- ' 'Name: hecprepro.ave 'Version: 4.0.av 'Date: 04/20/97 'Author: Ferdi Hellweger ' Center for Research in Water Resources ' The University of Texas at Austin ' ferdi@crwr.utexas.edu ' www.ce.utexas.edu/stu/ferdi/ ' '--------------------------- '--- purpose/description --- '--------------------------- ' 'This program creates an HMS basin file. ' '-------------------------- '--- general set up (1) --- '-------------------------- ' '--- get view (1.1) --- ' theview = av.getactivedoc ' '--- get display --- ' thedisplay = theview.getdisplay ' '--- get themes (1.2) --- ' theactivethemes = theview.getactivethemes if (theactivethemes.count = 0) then msgbox.error("No active themes found", "HECPREPRO") exit end if (theactivethemes.count = 1) then msgbox.error("Only one active theme found", "HECPREPRO") exit end if (theactivethemes.count > 4) then msgbox.error("Too many active themes found", "HECPREPRO") exit end ilfound = false ipfound = false infound = false igfound = false for each activetheme in theactivethemes if (activetheme.getclass.getclassname = "ftheme") then theftab = activetheme.getftab theshapef = theftab.findfield("shape") theshape = theftab.returnvalue(theshapef,0) if (theshape.getclass.getclassname = "polyline") then iltheme = activetheme ilfound = true end if (theshape.getclass.getclassname = "polygon") then iptheme = activetheme ipfound = true end if (theshape.getclass.getclassname = "point") then intheme = activetheme infound = true end end if (activetheme.getclass.getclassname = "gtheme") then igtheme = activetheme igfound = true end end if (not ilfound) then msgbox.error("One theme needs to be a line theme.", "HECPREPRO") exit end if (not ipfound) then msgbox.error("One theme needs to be a polygon theme.", "HECPREPRO") exit end if ((not infound) and (not igfound) and (theactivethemes.count = 3)) then msgbox.error("Three themes are active." + nl + "One theme needs to be a grid or point/node theme.", "HECPREPRO") exit end if ((not infound) and (theactivethemes.count = 4)) then msgbox.error("Four themes are active." + nl + "One theme needs to be a point/node theme.", "HECPREPRO") exit end if ((not igfound) and (theactivethemes.count = 4)) then msgbox.error("Four themes are active." + nl + "One theme needs to be a grid theme.", "HECPREPRO") exit end ' '--- get run control parameters (1.3) --- ' labels = list.make labels = labels.add("Transfer Attributes (y/n)") labels = labels.add("HMS File Path (default, path)") labels = labels.add("Tolerance") labels = labels.add("User Observation Level (0-4)") ' defaults = list.make defaults = defaults.add("no") defaults = defaults.add("default") defaults = defaults.add("10") defaults = defaults.add("2") ' inputs = msgbox.multiinput("Enter run control parameters", "HECPREPRO", labels, defaults) if (inputs.count = 0) then exit end ' if (inputs.get(0).left(1).ucase = "N") then attrib = false else attrib = true end ' hmsmode = "d" if (not (inputs.get(1).left(3).ucase = "DEF")) then hmsmode = inputs.get(1) end ' tol = inputs.get(2).asnumber ' oblevel = inputs.get(3).asnumber ' '--- set up hydrologic element type dictionary (1.4) --- ' 'hedict: 'key = hectype id 'value = hectype name ' hedict = dictionary.make(7 * 2) ' hedict.add(5, "subbasin") hedict.add(4, "reach") hedict.add(3, "junction") hedict.add(8, "diversion") hedict.add(10, "reservoir") hedict.add(7, "source") hedict.add(6, "sink") ' '--- set up error handling --- ' if (oblevel >= 1) then mainmsg = "HECPREPRO: Setting up error handling. " av.showmsg(mainmsg) av.setstatus(1) av.showstopbutton end ' errors = 0 ' '--- set up input themes (1.5) --- ' if (oblevel >= 1) then mainmsg = "HECPREPRO: Setting up input themes. " av.showmsg(mainmsg) keepgoing = av.setstatus(2) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' 'input line theme ' if (oblevel >= 1) then av.showmsg(mainmsg + "Line theme.") keepgoing = av.setstatus(3) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' ilftab = iltheme.getftab if (ilftab = nil) then msgbox.error("Can't open input line theme","HECPREPRO") exit end ' ilfields = list.make for each ilfrec in ilftab.getfields if (ilfrec.getname = "shape") then ilshapef = ilfrec continue else ilfields = ilfields.add(ilfrec) end end if (ilshapef = nil) then msgbox.error("Can't find 'shape' field in input line theme","HECPREPRO") exit end ' 'input polygon theme ' if (oblevel >= 1) then av.showmsg(mainmsg + "Polygon theme.") keepgoing = av.setstatus(4) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' ipftab = iptheme.getftab if (ipftab = nil) then msgbox.error("Can't open input polygon theme","HECPREPRO") exit end ' ipfields = list.make for each ipfrec in ipftab.getfields if (ipfrec.getname = "shape") then ipshapef = ipfrec continue else ipfields = ipfields.add(ipfrec) end end if (ipshapef = nil) then msgbox.error("Can't find 'shape' field in input polygon theme","HECPREPRO") exit end ' 'input point/node theme ' if (infound) then if (oblevel >= 1) then av.showmsg(mainmsg + "Point/node theme.") keepgoing = av.setstatus(3) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' inftab = intheme.getftab if (inftab = nil) then msgbox.error("Can't open input point/node theme","HECPREPRO") exit end ' infields = list.make for each infrec in inftab.getfields if (infrec.getname = "shape") then inshapef = infrec continue else infields = infields.add(infrec) end end if (inshapef = nil) then msgbox.error("Can't find 'shape' field in input point/node theme","HECPREPRO") exit end end ' 'input grid theme ' 'doesn't need set up ' ' '--- get attribute map info (1.6) --- ' if (attrib) then if (oblevel >= 1) then av.showmsg(mainmsg + "Attribute transfer tables.") keepgoing = av.setstatus(4) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' attribpossible = false ' 'set up attribute maping dictionary ' 'mapdict: 'key = hydrologic element type '0 = map attributes? '1 = table name '2 = table vtab '3 = field name string list ' 'field name string list: '0 hmsfield '1 gisfield '2 transfer ' 'transfer: '0 = no transfer '1 = transfer, reach attribute total '2 = transfer, reach attribute simple average '3 = transfer, reach attribute length weighted average ' mapdict = dictionary.make(7 * 3) for each herec in hedict mapdict.add(herec.clone, {false, nil, nil, nil}) end ' 'define attribute map table names ' mapdict.get("subbasin").set(1, "hecsub.dbf") mapdict.get("reach").set(1, "hecreach.dbf") mapdict.get("junction").set(1, "hecjunct.dbf") mapdict.get("diversion").set(1, "hecdiv.dbf") mapdict.get("reservoir").set(1, "hecres.dbf") mapdict.get("source").set(1, "hecsourc.dbf") mapdict.get("sink").set(1, "hecsink.dbf") ' 'get tables ' theproject = av.getproject thedocs = theproject.getdocs thetables = list.make for each thedoc in thedocs if (thedoc.getclass.getclassname = "table") then thetables = thetables.add(thedoc.clone) end end ' 'get map attribute map tables ' for each thetable in thetables for each herec in hedict if (thetable.getname = mapdict.get(herec).get(1)) then mapdict.get(herec).set(0, true) mapdict.get(herec).set(2, thetable.getvtab.clone) end end end ' 'process attribute map tables ' for each herec in hedict if (mapdict.get(herec).get(0)) then mapdict.get(herec).set(0, false) mapvtb = mapdict.get(herec).get(2) hmsf = mapvtb.findfield("hmsfield") if (hmsf = nil) then msgbox.error("Error in " + herec + " attribute map table", "HECPREPRO") exit end gisf = mapvtb.findfield("gisfield") if (gisf = nil) then msgbox.error("Error in " + herec + " attribute map table", "HECPREPRO") exit end traf = mapvtb.findfield("transfer") if (traf = nil) then msgbox.error("Error in " + herec + " attribute map table", "HECPREPRO") exit end templist = list.make for each maprec in mapvtb tra = mapvtb.returnvalue(traf, maprec) if (tra > 0) then hms = mapvtb.returnvalue(hmsf, maprec) if (hms = "") then msgbox.error("Error in " + herec + " attribute map table", "HECPREPRO") exit end gis = mapvtb.returnvalue(gisf, maprec) if (gis = "") then msgbox.error("Error in " + herec + " attribute map table", "HECPREPRO") exit end if (herec = "subbasin") then testf = ipftab.findfield(gis) if (testf = nil) then msgbox.error("Error in " + herec + " attribute map table", "HECPREPRO") exit end end if (herec = "reach") then testf = ilftab.findfield(gis) if (testf = nil) then msgbox.error("Error in " + herec + " attribute map table", "HECPREPRO") exit end end if ((not (herec = "reach")) and (not (herec = "subbasin")) and infound) then testf = inftab.findfield(gis) if (testf = nil) then msgbox.error("Error in " + herec + " attribute map table", "HECPREPRO") exit end end templist.add({hms.clone, gis.clone, tra.clone}) mapdict.get(herec).set(0, true) attribpossible = true end end mapdict.get(herec).set(3, templist.clone) end end if (not attribpossible) then msgbox.info("Attribute transfer is not possible." + nl + "Using no attribute transfer option", "HECPREPRO") attrib = false end end ' '---------------------------------------- '--- create hydro line shape file (2) --- '---------------------------------------- ' 'this code is based on a script taken from esri's home page 'called view.intersectthemes. ' if (oblevel >= 1) then mainmsg = "HECPREPRO: Intersecting input themes. " av.showmsg(mainmsg) keepgoing = av.setstatus(5) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' '--- set up hydro line theme (2.1) --- ' if (oblevel >= 1) then av.showmsg(mainmsg + "Setting up hydro line theme.") keepgoing = av.setstatus(6) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' 'set up file ' hlfilename = av.getproject.makefilename("hydrol", "shp") hlftab = ftab.makenew(hlfilename, polyline) ' 'add fields to hydro line theme ' hlfields = list.make ' hlhectypef = field.make("hectype", #FIELD_DECIMAL, 16, 4) hlhecidf = field.make("hecid", #FIELD_DECIMAL, 16, 4) hllhpf = field.make("lhp", #FIELD_DECIMAL, 16, 4) hlfphpf = field.make("fphp", #FIELD_DECIMAL, 16, 4) hltphpf = field.make("tphp", #FIELD_DECIMAL, 16, 4) ' hlfields = hlfields.add(hlhectypef) hlfields = hlfields.add(hlhecidf) hlfields = hlfields.add(hllhpf) hlfields = hlfields.add(hlfphpf) hlfields = hlfields.add(hltphpf) ' hlfields = hlfields + ilfields.deepclone ' hlftab.addfields(hlfields) ' hlshapef = hlftab.findfield("shape") ' 'make theme editable ' hlftab.seteditable(true) ' '--- user observation --- ' if (oblevel >= 2) then hltheme = ftheme.make(hlftab) theview.addtheme(hltheme) iltheme.setvisible(false) hltheme.setvisible(true) theview.draw(thedisplay) end ' '--- intersect (2.2) --- ' 'user observation ' if (oblevel >= 1) then av.showmsg(mainmsg + "Processing each polygon.") keepgoing = av.setstatus(7) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' theme1 = iltheme ftab1 = theme1.getftab shpfld1 = ftab1.findfield("shape") therecs1 = ftab1.getselection theoldsel = ftab1.getselection.clone if (therecs1.count = 0) then therecs1 = ftab1 end ' theme2 = iptheme ftab2 = theme2.getftab shpfld2 = ftab2.findfield("shape") therecs2 = ftab2.getselection if (therecs2.count = 0) then therecs2 = ftab2 end ' 'loop on each polygon ' for each arec2 in therecs2 ' 'get the polygon shape and select all records within that shape ' thesrcshape = ftab2.returnvalue(shpfld2,arec2) if (theview.getprojection.isnull) then theme1.selectbyshapes({thesrcshape}, #VTAB_SELTYPE_NEW) else pshp = thesrcshape.returnprojected(theview.getprojection) theme1.selectbyshapes({pshp}, #VTAB_SELTYPE_NEW) end ' 'for each selected record ' for each selrec in ftab1.getselection ' 'get the shape of the record ' selectedshape = ftab1.returnvalue(shpfld1,selrec) ' 'if the line is wholely within the polygin (no intersection) then ' if (selectedshape.iscontainedin(thesrcshape)) then alineshp = selectedshape else ' 'split the line using the polygon ' alineshp = selectedshape.lineintersection(thesrcshape) end ' 'add the new record ' theoutrec = hlftab.addrecord ' 'set the shape value ' hlftab.setvalue(hlshapef,theoutrec,alineshp) ' 'set the line field values ' for each ilfrec in ilfields ilf = ftab1.findfield(ilfrec.getname) ilvalue = ftab1.returnvalue(ilf, selrec) hlf = hlftab.findfield(ilfrec.getname) hlftab.setvalue(hlf, theoutrec, ilvalue) end ' if (oblevel >= 3) then theview.draw(thedisplay) end end end ' 'revert to original selection set ' ftab1.setselection(theoldsel) ftab1.updateselection ' '--- user observation --- ' if (oblevel >= 2) then av.run("HECLEGEND", {hltheme}) theview.draw(thedisplay) end ' '----------------------------------------- '--- create hydro point shape file (3) --- '----------------------------------------- ' if (oblevel >= 1) then mainmsg = "HECPREPRO: Creating hydro point theme. " av.showmsg(mainmsg) keepgoing = av.setstatus(25) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' '--- set up hydro point theme (3.1) --- ' if (oblevel >= 1) then av.showmsg(mainmsg + "Setting up hydro point theme.") keepgoing = av.setstatus(26) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' 'set up file ' hpfilename = av.getproject.makefilename("hydrop", "shp") hpftab = ftab.makenew(hpfilename, point) ' 'get shape field ' hpshapef = hpftab.findfield("shape") ' 'add fields to hydro point theme ' hpfields = list.make ' hphecidf = field.make("hecid", #FIELD_DECIMAL, 16, 4) hphectypef = field.make("hectype", #FIELD_DECIMAL, 16, 4) hprntf = field.make("rnt", #FIELD_CHAR, 16, 4) hphntf = field.make("hnt", #FIELD_CHAR, 16, 4) hprlf = field.make("rl", #FIELD_DECIMAL, 16, 4) hpruplf = field.make("rupl", #FIELD_DECIMAL, 16, 4) hprdnlf = field.make("rdnl", #FIELD_DECIMAL, 16, 4) hprrlf = field.make("rrl", #FIELD_DECIMAL, 16, 4) hprruplf = field.make("rrupl", #FIELD_DECIMAL, 16, 4) hprrdnlf = field.make("rrdnl", #FIELD_DECIMAL, 16, 4) hphlf = field.make("hl", #FIELD_DECIMAL, 16, 4) hphuplf = field.make("hupl", #FIELD_DECIMAL, 16, 4) hphdnlf = field.make("hdnl", #FIELD_DECIMAL, 16, 4) hphrlf = field.make("hrl", #FIELD_DECIMAL, 16, 4) hphruplf = field.make("hrupl", #FIELD_DECIMAL, 16, 4) hphrdnlf = field.make("hrdnl", #FIELD_DECIMAL, 16, 4) ' hpfields = hpfields.add(hphecidf) hpfields = hpfields.add(hphectypef) hpfields = hpfields.add(hprntf) hpfields = hpfields.add(hphntf) hpfields = hpfields.add(hprlf) hpfields = hpfields.add(hpruplf) hpfields = hpfields.add(hprdnlf) hpfields = hpfields.add(hprrlf) hpfields = hpfields.add(hprruplf) hpfields = hpfields.add(hprrdnlf) hpfields = hpfields.add(hphlf) hpfields = hpfields.add(hphuplf) hpfields = hpfields.add(hphdnlf) hpfields = hpfields.add(hphrlf) hpfields = hpfields.add(hphruplf) hpfields = hpfields.add(hphrdnlf) ' if (infound) then hpfields = hpfields + infields.deepclone end ' hpftab.addfields(hpfields) ' 'make hydro point theme editable ' hpftab.seteditable(true) ' '--- user observation --- ' if (oblevel >= 2) then hptheme = ftheme.make(hpftab) theview.addtheme(hptheme) hptheme.setvisible(true) theview.draw(thedisplay) end ' '--- add points (3.2) --- ' if (oblevel >= 1) then av.showmsg(mainmsg + "Adding points.") keepgoing = av.setstatus(27) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' 'loop for each line ' for each hlrec in hlftab ' hlshape = hlftab.returnvalue(hlshapef, hlrec) hlpoints = hlshape.asmultipoint.aslist if (hlpoints.count > 1) then hlfp = hlpoints.get(0) hltp = hlpoints.get(hlpoints.count - 1) ' 'add fpoint ' exists = false for each hprec in hpftab hpshape = hpftab.returnvalue(hpshapef, hprec) if (hpshape.distance(hlfp) < tol) then exists = true hlfphp = hprec.clone break end end if (not exists) then theoutrec = hpftab.addrecord hpftab.setvalue(hpshapef, theoutrec, hlfp) hlftab.setvalue(hlfphpf, hlrec, theoutrec) if (oblevel >= 3) then theview.draw(thedisplay) end if (infound) then for each inrec in inftab inshape = inftab.returnvalue(inshapef, inrec) if (inshape.distance(hlfp) < tol) then for each infrec in inftab.getfields if (infrec.getname = "shape") then continue else inval = inftab.returnvalue(infrec, inrec) hpf = hpftab.findfield(infrec.getname) hpftab.setvalue(hpf, theoutrec, inval) end end break end end end end if (exists) then hlftab.setvalue(hlfphpf, hlrec, hlfphp) end ' 'add tpoint ' exists = false for each hprec in hpftab hpshape = hpftab.returnvalue(hpshapef, hprec) if (hpshape.distance(hltp) < tol) then exists = true hltphp = hprec.clone break end end if (not exists) then theoutrec = hpftab.addrecord hpftab.setvalue(hpshapef, theoutrec, hltp) hlftab.setvalue(hltphpf, hlrec, theoutrec) if (oblevel >= 3) then theview.draw(thedisplay) end if (infound) then for each inrec in inftab inshape = inftab.returnvalue(inshapef, inrec) if (inshape.distance(hltp) < tol) then for each infrec in inftab.getfields if (infrec.getname = "shape") then continue else inval = inftab.returnvalue(infrec, inrec) hpf = hpftab.findfield(infrec.getname) hpftab.setvalue(hpf, theoutrec, inval) end end break end end end end if (exists) then hlftab.setvalue(hltphpf, hlrec, hltphp) end end end ' '--- user observation --- ' if (oblevel >= 2) then av.run("HECLEGEND", {hptheme}) theview.draw(thedisplay) end ' '-------------------------------------------------------- '--- identify sources, subbasin outlets and sinks (4) --- '-------------------------------------------------------- ' '--- user observation --- ' if (oblevel >= 1) then mainmsg = "HECPREPRO: Identifying sources, subbasin outlets and sinks. " av.showmsg(mainmsg) keepgoing = av.setstatus(50) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' '--- identify and mark points --- ' for each hprec in hpftab hpshape = hpftab.returnvalue(hpshapef, hprec) for each polyrec in ipftab polyshape = ipftab.returnvalue(ipshapef, polyrec) polylshape = polyshape.aspolyline if (hpshape.distance(polylshape) < tol) then hpftab.setvalue(hphectypef, hprec, 1) if (oblevel >= 3) then av.run("HECLEGEND", {hptheme}) theview.draw(thedisplay) end end end end ' '--- user observation --- ' if (oblevel >= 2) then av.run("HECLEGEND", {hptheme}) theview.draw(thedisplay) end ' '----------------------------------- '--- identify channel system (5) --- '----------------------------------- ' '--- user observation --- ' if (oblevel >= 1) then mainmsg = "HECPREPRO: Identifying channel system. " av.showmsg(mainmsg) keepgoing = av.setstatus(60) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' '--- create stream dictionary (5.1) --- ' if (oblevel >= 1) then av.showmsg(mainmsg + "Creating stream dictionary.") keepgoing = av.setstatus(61) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' 'streamdict: 'key = hlrec '0 = hlrec ' streamdict = dictionary.make(hlftab.getnumrecords * 2) ' for each hlrec in hlftab if (oblevel >= 1) then av.showmsg(mainmsg + "Line number " + hlrec.asstring) end hlshape = hlftab.returnvalue(hlshapef, hlrec) hlpoints = hlshape.asmultipoint.aslist if (hlpoints.count < 2) then hllength = 0 else hlfp = hlpoints.get(0) hltp = hlpoints.get(hlpoints.count - 1) hllength = (((hltp.getx - hlfp.getx)^2) + ((hltp.gety - hlfp.gety)^2))^0.5 end if (hllength > (tol / 2)) then streamdict.add(hlrec.clone, hlrec.clone) end end ' '--- create channel dictionary (5.2) --- ' if (oblevel >= 1) then av.showmsg(mainmsg + "Creating channel dictionary.") keepgoing = av.setstatus(62) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' 'channeldict: 'key = hlrec '0 = hlrec ' channeldict = dictionary.make(hlftab.getnumrecords * 2) ' uplist = list.make for each hprec in hpftab if (hpftab.returnvalue(hphectypef, hprec) = 1) then hpshape = hpftab.returnvalue(hpshapef, hprec) for each hlrec in streamdict hlshape = hlftab.returnvalue(hlshapef, hlrec) hlpoints = hlshape.asmultipoint.aslist if (hlpoints.get(0).distance(hpshape) < tol) then channeldict.add(hlrec.clone, hlrec.clone) uplist = uplist.add(hlrec.clone) end end for each hlrec in channeldict streamdict.remove(hlrec) end end end ' done = false while (not done) dnlist = list.make for each uplrec in uplist uplineshape = hlftab.returnvalue(hlshapef, uplrec) uplinepoints = uplineshape.asmultipoint.aslist updnpoint = uplinepoints.get(uplinepoints.count - 1) for each hlrec in streamdict hlshape = hlftab.returnvalue(hlshapef, hlrec) if (hlshape.asmultipoint.aslist.get(0).distance(updnpoint) < tol) then dnlist = dnlist.add(hlrec.clone) channeldict.add(hlrec.clone, hlrec.clone) end end for each hlrec in channeldict streamdict.remove(hlrec) end end if (dnlist.count = 0) then done = true end uplist = dnlist end ' '--- mark lines (5.3) --- ' if (oblevel >= 1) then av.showmsg(mainmsg + "Marking lines.") keepgoing = av.setstatus(69) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' for each hlrec in channeldict hlftab.setvalue(hlhectypef, hlrec, 4) if (oblevel >= 3) then av.run("HECLEGEND", {hltheme}) theview.draw(thedisplay) end end ' '--- user observation --- ' if (oblevel >= 2) then av.run("HECLEGEND", {hltheme}) theview.draw(thedisplay) end ' '-------------------------- '--- identify lakes (6) --- '-------------------------- ' '--- user observation --- ' if (oblevel >= 1) then mainmsg = "HECPREPRO: Identifying lakes. " av.showmsg(mainmsg) keepgoing = av.setstatus(70) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' '--- identify lines --- ' for each hprec in hpftab uplines = 0 dnlines = 0 dnlinelist = list.make for each hlrec in hlftab hlshape = hlftab.returnvalue(hlshapef, hlrec) hlpointlist = hlshape.asmultipoint.aslist if (hlpointlist.count < 2) then hllength = 0 else fpoint = hlpointlist.get(0) tpoint = hlpointlist.get(hlpointlist.count - 1) hllength = (((tpoint.getx - fpoint.getx)^2) + ((tpoint.gety - fpoint.gety)^2))^0.5 end if (hllength > (tol / 2)) then hlfphp = hlftab.returnvalue(hlfphpf, hlrec) hltphp = hlftab.returnvalue(hltphpf, hlrec) if (hlfphp = hprec) then dnlines = dnlines + 1 dnlinelist = dnlinelist.add(hlrec.clone) end if (hltphp = hprec) then uplines = uplines + 1 end end end if ((uplines = 1) and (dnlines = 2)) then tracelist = list.make tracelist.add(dnlinelist.get(0).clone) tracelist.add(dnlinelist.get(1).clone) uplist = dnlinelist.clone done = false while (not done) dnlist = list.make for each uplrec in uplist upltphp = hlftab.returnvalue(hltphpf, uplrec) for each hlrec in hlftab hlfphp = hlftab.returnvalue(hlfphpf, hlrec) if (hlfphp = upltphp) then dnlist = dnlist.add(hlrec.clone) tracelist.add(hlrec.clone) end end end if (dnlist.count = 0) then done = true end uplist = dnlist end tracelistb = tracelist.clone tracelistb.removeduplicates lake = false i = 0 for each hlrec in tracelist if (not (tracelist.get(i) = tracelistb.get(i))) then lake = true dnline = tracelist.get(i) break end i = i + 1 end if (lake) then dnphp = hlftab.returnvalue(hlfphpf, dnline) tracelistc = list.make for each hlrec in tracelist hltphp = hlftab.returnvalue(hltphpf, hlrec) if (hltphp = dnphp) then dnline = hlrec.clone tracelistc.add(hlrec.clone) done = false while (not done) dnfphp = hlftab.returnvalue(hlfphpf, dnline) found = false for each hlrec2 in tracelist hl2tphp = hlftab.returnvalue(hltphpf, hlrec2) if (hl2tphp = dnfphp) then found = true upline = hlrec2.clone tracelistc.add(hlrec2.clone) end end if (found = false) then done = true end dnline = upline end end end for each hlrec in tracelistc hlhectype = hlftab.returnvalue(hlhectypef, hlrec) hlhectype = hlhectype * 10 hlftab.setvalue(hlhectypef, hlrec, hlhectype) hlftab.setvalue(hllhpf, hlrec, dnphp) if (oblevel >= 3) then av.run("HECLEGEND", {hltheme}) theview.draw(thedisplay) end end end end end ' '--- user observation --- ' if (oblevel >= 2) then av.run("HECLEGEND", {hltheme}) theview.draw(thedisplay) end ' '------------------------------------- '--- identify channel elements (7) --- '------------------------------------- ' '--- user observation --- ' if (oblevel >= 1) then mainmsg = "HECPREPRO: Identifying channel elements. " av.showmsg(mainmsg) keepgoing = av.setstatus(80) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' '--- set up sym dictionaries (7.1) --- ' 'sldict: 'key = hecid '0 = hecid '1 = hectype '2 = hecupid '3 = hecdnid '4 = hecupx '5 = hecupy '6 = hecdnx '7 = hecdny ' 'spdict: 'key = hecid '0 = hecid '1 = hectype '2 = hecupids '3 = hecdnids '4 = hecx '5 = hecy '6 = hprec ' 'upiddict: 'key = hecid '0 = hecid '1 = hecupid 1 '2 = hecupid 2 '3 = etc... ' 'dniddict: 'key = hecid '0 = hecid '1 = hecdnid 1 '2 = hecdnid 2 '3 = etc... ' sldict = dictionary.make(hlftab.getnumrecords * 8) spdict = dictionary.make(hpftab.getnumrecords * 7) upiddict = dictionary.make(hpftab.getnumrecords * 2) dniddict = dictionary.make(hpftab.getnumrecords * 2) ' '--- set up hecid variable (7.2) --- ' hecid = 1 ' '--- identify elements (7.3) --- ' for each hprec in hpftab if (oblevel >= 1) then av.showmsg(mainmsg + "Point number " + hprec.asstring) end hpshape = hpftab.returnvalue(hpshapef, hprec) hphecx = hpshape.getx hphecy = hpshape.gety hphectype = hpftab.returnvalue(hphectypef, hprec) rlines = 0 ruplines = 0 rdnlines = 0 rrlines = 0 rruplines = 0 rrdnlines = 0 hlines = 0 huplines = 0 hdnlines = 0 hrlines = 0 hruplines = 0 hrdnlines = 0 for each hlrec in hlftab hlhectype = hlftab.returnvalue(hlhectypef, hlrec) hlshape = hlftab.returnvalue(hlshapef, hlrec) hlpoints = hlshape.asmultipoint.aslist if (hlpoints.count < 2) then hllength = 0 else hlfp = hlpoints.get(0) hltp = hlpoints.get(hlpoints.count - 1) hllength = (((hltp.getx - hlfp.getx)^2) + ((hltp.gety - hlfp.gety)^2))^0.5 end if (hllength > (tol / 2)) then if (hlfp.distance(hpshape) < tol) then rlines = rlines + 1 rdnlines = rdnlines + 1 if (hlhectype > 10 ) then rrlines = rrlines + 1 rrdnlines = rrdnlines + 1 end if ((hlhectype = 4) or (hlhectype = 40)) then hlines = hlines + 1 hdnlines = hdnlines + 1 if (hlhectype = 40 ) then hrlines = hrlines + 1 hrdnlines = hrdnlines + 1 end end else if (hltp.distance(hpshape) < tol) then rlines = rlines + 1 ruplines = ruplines + 1 if (hlhectype > 10 ) then rrlines = rrlines + 1 rruplines = rruplines + 1 end if ((hlhectype = 4) or (hlhectype = 40)) then hlines = hlines + 1 huplines = huplines + 1 if (hlhectype = 40 ) then hrlines = hrlines + 1 hruplines = hruplines + 1 end end end end end end ' 'calculate node types ' rnodetype = "unknown" if ((rlines = 1) and (rdnlines = 1)) then rnodetype = "updangling" end if ((rlines = 1) and (ruplines = 1)) then rnodetype = "dndangling" end if ((ruplines = 1) and (rdnlines = 1)) then rnodetype = "interior" end if ((ruplines >= 2) and (rdnlines = 1)) then rnodetype = "junction" end if ((ruplines = 1) and (rdnlines >= 2)) then rnodetype = "diversion" end if ((rruplines = 1) and (rrdnlines = 1)) then rnodetype = "mreservoir" end if ((rrdnlines = 2) and (rruplines = 0)) then rnodetype = "upreservoir" end if ((rruplines = 2) and (rrdnlines = 0)) then rnodetype = "dnreservoir" end if ((rruplines = 1) and (rrdnlines = 1) and (rdnlines = 2)) then rnodetype = "dreservoir" end if ((rruplines = 1) and (rrdnlines = 1) and (ruplines = 2)) then rnodetype = "jreservoir" end ' hnodetype = "unknown" if ((hlines = 1) and (hdnlines = 1)) then hnodetype = "updangling" end if ((hlines = 1) and (huplines = 1)) then hnodetype = "dndangling" end if ((huplines = 1) and (hdnlines = 1)) then hnodetype = "interior" end if ((huplines >= 2) and (hdnlines = 1)) then hnodetype = "junction" end if ((huplines = 1) and (hdnlines >= 2)) then hnodetype = "diversion" end if ((hruplines = 1) and (hrdnlines = 1)) then hnodetype = "mreservoir" end if ((hrdnlines = 2) and (hruplines = 0)) then hnodetype = "upreservoir" end if ((hruplines = 2) and (hrdnlines = 0)) then hnodetype = "dnreservoir" end if ((hruplines = 1) and (hrdnlines = 1) and (hdnlines = 2)) then hnodetype = "dreservoir" end if ((hruplines = 1) and (hrdnlines = 1) and (huplines = 2)) then hnodetype = "jreservoir" end if (hlines = 0) then hnodetype = "none" end if (oblevel >= 4) then message = "rlines = " + rlines.asstring message = message + nl + "ruplines = " + ruplines.asstring message = message + nl + "rdnlines = " + rdnlines.asstring message = message + nl + "rnodetype = " + rnodetype message = message + nl + "hlines = " + hlines.asstring message = message + nl + "huplines = " + huplines.asstring message = message + nl + "hdnlines = " + hdnlines.asstring message = message + nl + "hnodetype = " + hnodetype msgbox.report(message, "HECPREPRO") end if (rnodetype = "unknown") then if (oblevel >= 2) then msgbox.error("Unidentifiable rnodetype", "HECPREPRO") end errors = errors + 1 end if (hnodetype = "unknown") then if (oblevel >= 2) then msgbox.error("Unidentifiable hnodetype", "HECPREPRO") end errors = errors + 1 end ' 'record node types ' hpftab.setvalue(hprntf, hprec, rnodetype) hpftab.setvalue(hphntf, hprec, hnodetype) hpftab.setvalue(hprlf, hprec, rlines) hpftab.setvalue(hpruplf, hprec, ruplines) hpftab.setvalue(hprdnlf, hprec, rdnlines) hpftab.setvalue(hprrlf, hprec, rrlines) hpftab.setvalue(hprruplf, hprec, rruplines) hpftab.setvalue(hprrdnlf, hprec, rrdnlines) hpftab.setvalue(hphlf, hprec, hlines) hpftab.setvalue(hphuplf, hprec, huplines) hpftab.setvalue(hphdnlf, hprec, hdnlines) hpftab.setvalue(hphrlf, hprec, hrlines) hpftab.setvalue(hphruplf, hprec, hruplines) hpftab.setvalue(hphrdnlf, hprec, hrdnlines) ' 'classify elements based on hectype system ' if ((hnodetype = "junction") and (not (hphectype = 1))) then hphectype = 3 ' hpftab.setvalue(hphectypef, hprec, hphectype) hpftab.setvalue(hphecidf, hprec, hecid) ' spdictrec = {hecid.clone, hphectype.clone, 0, 0, hpshape.getx.clone, hpshape.gety.clone, hprec.clone} spdict.add(hecid.clone, spdictrec.clone) upiddict.add(hecid.clone, {}) dniddict.add(hecid.clone, {}) ' if (oblevel >= 3) then av.run("HECLEGEND", {hptheme}) theview.draw(thedisplay) end ' if (oblevel >= 4) then message = "Recording HECID, HECTYPE, HECX and HECY" message = message + nl message = message + nl + "JUNCTION" message = message + nl + "HECID: " + hecid.asstring message = message + nl + "HECTYPE: " + hphectype.asstring message = message + nl + "HECX: " + hphecx.asstring message = message + nl + "HECY: " + hphecy.asstring msgbox.report(message, "HECPREPRO") end ' hecid = hecid + 1 end if (hnodetype = "diversion") then hphectype = 8 ' hpftab.setvalue(hphectypef, hprec, hphectype) hpftab.setvalue(hphecidf, hprec, hecid) ' spdictrec = {hecid.clone, hphectype.clone, 0, 0, hpshape.getx.clone, hpshape.gety.clone, hprec.clone} spdict.add(hecid.clone, spdictrec.clone) upiddict.add(hecid.clone, {}) dniddict.add(hecid.clone, {}) ' if (oblevel >= 3) then av.run("HECLEGEND", {hptheme}) theview.draw(thedisplay) end ' if (oblevel >= 4) then message = "Recording HECID, HECTYPE, HECX and HECY" message = message + nl message = message + nl + "DIVERSION" message = message + nl + "HECID: " + hecid.asstring message = message + nl + "HECTYPE: " + hphectype.asstring message = message + nl + "HECX: " + hphecx.asstring message = message + nl + "HECY: " + hphecy.asstring msgbox.report(message, "HECPREPRO") end ' hecid = hecid + 1 end if (rnodetype = "dndangling") then hphectype = 6 ' hpftab.setvalue(hphectypef, hprec, hphectype) hpftab.setvalue(hphecidf, hprec, hecid) ' spdictrec = {hecid.clone, hphectype.clone, 0, 0, hpshape.getx.clone, hpshape.gety.clone, hprec.clone} spdict.add(hecid.clone, spdictrec.clone) upiddict.add(hecid.clone, {}) dniddict.add(hecid.clone, {}) ' if (oblevel >= 3) then av.run("HECLEGEND", {hptheme}) theview.draw(thedisplay) end ' if (oblevel >= 4) then message = "Recording HECID, HECTYPE, HECX and HECY" message = message + nl message = message + nl + "SINK" message = message + nl + "HECID: " + hecid.asstring message = message + nl + "HECTYPE: " + hphectype.asstring message = message + nl + "HECX: " + hphecx.asstring message = message + nl + "HECY: " + hphecy.asstring msgbox.report(message, "HECPREPRO") end ' hecid = hecid + 1 end if ((rnodetype = "updangling") and (hnodetype = "updangling")) then hphectype = 7 ' hpftab.setvalue(hphectypef, hprec, hphectype) hpftab.setvalue(hphecidf, hprec, hecid) ' spdictrec = {hecid.clone, hphectype.clone, 0, 0, hpshape.getx.clone, hpshape.gety.clone, hprec.clone} spdict.add(hecid.clone, spdictrec.clone) upiddict.add(hecid.clone, {}) dniddict.add(hecid.clone, {}) ' if (oblevel >= 3) then av.run("HECLEGEND", {hptheme}) theview.draw(thedisplay) end ' if (oblevel >= 4) then message = "Recording HECID, HECTYPE, HECX and HECY" message = message + nl message = message + nl + "SOURCE" message = message + nl + "HECID: " +hecid.asstring message = message + nl + "HECTYPE: " + hphectype.asstring message = message + nl + "HECX: " + hphecx.asstring message = message + nl + "HECY: " + hphecy.asstring msgbox.report(message, "HECPREPRO") end ' hecid = hecid + 1 end if (hnodetype = "dnreservoir") then hphectype = 10 ' hpftab.setvalue(hphectypef, hprec, hphectype) hpftab.setvalue(hphecidf, hprec, hecid) ' spdictrec = {hecid.clone, hphectype.clone, 0, 0, hpshape.getx.clone, hpshape.gety.clone, hprec.clone} spdict.add(hecid.clone, spdictrec.clone) upiddict.add(hecid.clone, {}) dniddict.add(hecid.clone, {}) ' if (oblevel >= 3) then av.run("HECLEGEND", {hptheme}) theview.draw(thedisplay) end ' if (oblevel >= 4) then message = "Recording HECID, HECTYPE, HECX and HECY" message = message + nl message = message + nl + "RESERVOIR" message = message + nl + "HECID: " + hecid.asstring message = message + nl + "HECTYPE:" + hphectype.asstring message = message + nl + "HECX: " + hphecx.asstring message = message + nl + "HECY: " + hphecy.asstring msgbox.report(message, "HECPREPRO") end ' hecid = hecid + 1 end if (hphectype = 1) then hpftab.setvalue(hphecidf, hprec, hecid) ' spdictrec = {hecid.clone, hphectype.clone, 0, 0, hpshape.getx.clone, hpshape.gety.clone, hprec.clone} spdict.add(hecid.clone, spdictrec.clone) upiddict.add(hecid.clone, {}) dniddict.add(hecid.clone, {}) ' if (oblevel >= 3) then av.run("HECLEGEND", {hptheme}) theview.draw(thedisplay) end ' if (oblevel >= 4) then message = "Recording HECID, HECTYPE, HECX and HECY" message = message + nl message = message + nl + "SUBBASIN OUTLET" message = message + nl + "HECID: " + hecid.asstring message = message + nl + "HECTYPE: " + hphectype.asstring message = message + nl + "HECX: " + hphecx.asstring message = message + nl + "HECY: " + hphecy.asstring msgbox.report(message, "HECPREPRO") end ' hecid = hecid + 1 end end ' '--- user observation --- ' if (oblevel >= 2) then av.run("HECLEGEND", {hptheme}) theview.draw(thedisplay) end ' '---------------------------------- '--- establish connectivity (8) --- '---------------------------------- ' '--- user observation --- ' if (oblevel >= 1) then mainmsg = "HECPREPRO: Establishing connectivity. " av.showmsg(mainmsg) keepgoing = av.setstatus(90) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' '--- reaches and channel elements (8.1) --- ' if (oblevel >= 1) then av.showmsg(mainmsg + "Reaches and channel elements.") keepgoing = av.setstatus(91) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' processdict = channeldict.clone startdict = channeldict.clone for each hlrec in processdict hllhp = hlftab.returnvalue(hllhpf, hlrec) if (hllhp > 0) then startdict.remove(hlrec) end end ' eof = false while (not eof) reachlist = list.make reachlist.add(startdict.aslist.get(0).clone) ' 'go upstream ' if (oblevel >= 1) then av.showmsg(mainmsg + "Looking for upstream end of reach.") end ' dnline = reachlist.get(0).clone ' upfound = false uplake = false ' hlfphp = hlftab.returnvalue(hlfphpf, dnline) uphectype = hpftab.returnvalue(hphectypef, hlfphp) ' if (uphectype = 1) then upfound = true end if (uphectype = 3) then upfound = true end if (uphectype = 7) then upfound = true end if (uphectype = 8) then upfound = true end if (uphectype = 10) then upfound = true end if (oblevel >= 4) then message = "Looking for upstream end of reach." message = message + nl message = message + nl + "HLFPHP: " + hlfphp.asstring message = message + nl + "UPHECTYPE: " + uphectype.asstring message = message + nl + "UPFOUND: " + upfound.asstring message = message + nl + "UPLAKE: " + uplake.asstring message = message + nl + "REACHLIST: " + reachlist.count.asstring message = message + nl + "PROCESSDICT: " + processdict.count.asstring message = message + nl + "CHANNELDICT: " + channeldict.count.asstring msgbox.report(message, "HECPREPRO") end while ((not upfound) and (not uplake)) for each prec in processdict hltphp = hlftab.returnvalue(hltphpf, prec) if (hltphp = hlfphp) then hllhp = hlftab.returnvalue(hllhpf, prec) if (hllhp = 0) then reachlist.add(prec.clone) end if (hllhp > 0) then uplake = true end dnline = prec.clone break end end hlfphp = hlftab.returnvalue(hlfphpf, dnline) uphectype = hpftab.returnvalue(hphectypef, hlfphp) if (uphectype = 1) then upfound = true end if (uphectype = 3) then upfound = true end if (uphectype = 7) then upfound = true end if (uphectype = 8) then upfound = true end if (uphectype = 10) then upfound = true end if (oblevel >= 4) then message = "Looking for upstream end of reach." message = message + nl message = message + nl + "HLFPHP: " + hlfphp.asstring message = message + nl + "UPHECTYPE: " + uphectype.asstring message = message + nl + "UPFOUND: " + upfound.asstring message = message + nl + "UPLAKE: " + uplake.asstring message = message + nl + "REACHLIST: " + reachlist.count.asstring message = message + nl + "PROCESSDICT: " + processdict.count.asstring message = message + nl + "CHANNELDICT: " + channeldict.count.asstring msgbox.report(message, "HECPREPRO") end end if (not uplake) then hecupid = hpftab.returnvalue(hphecidf, hlfphp) hecupshape = hpftab.returnvalue(hpshapef, hlfphp) hecupx = hecupshape.getx hecupy = hecupshape.gety end if (uplake) then hecupid = hpftab.returnvalue(hphecidf, hllhp) hecupshape = hpftab.returnvalue(hpshapef, hllhp) hecupx = hecupshape.getx hecupy = hecupshape.gety end for each hlrec in reachlist processdict.remove(hlrec) startdict.remove(hlrec) end ' 'go dnstream ' upline = reachlist.get(0).clone ' dnfound = false dnlake = false ' hltphp = hlftab.returnvalue(hltphpf, upline) dnhectype = hpftab.returnvalue(hphectypef, hltphp) ' if (dnhectype = 1) then dnfound = true end if (dnhectype = 3) then dnfound = true end if (dnhectype = 6) then dnfound = true end if (dnhectype = 8) then dnfound = true end if (dnhectype = 10) then dnfound = true end if (oblevel >= 4) then message = "Looking for downstream end of reach." message = message + nl message = message + nl + "HLTPHP: " + hltphp.asstring message = message + nl + "DNHECTYPE: " + dnhectype.asstring message = message + nl + "DNFOUND: " + dnfound.asstring message = message + nl + "DNLAKE: " + dnlake.asstring message = message + nl + "REACHLIST: " + reachlist.count.asstring message = message + nl + "PROCESSDICT: " + processdict.count.asstring message = message + nl + "CHANNELDICT: " + channeldict.count.asstring msgbox.report(message, "HECPREPRO") end while ((not dnfound) and (not dnlake)) if (not dnfound) then for each prec in processdict hlfphp = hlftab.returnvalue(hlfphpf, prec) if (hlfphp = hltphp) then hllhp = hlftab.returnvalue(hllhpf, prec) if (hllhp = 0) then reachlist.add(prec.clone) end if (hllhp > 0) then dnlake = true end upline = prec.clone break end end end hltphp = hlftab.returnvalue(hltphpf, upline) dnhectype = hpftab.returnvalue(hphectypef, hltphp) ' if (dnhectype = 1) then dnfound = true end if (dnhectype = 3) then dnfound = true end if (dnhectype = 6) then dnfound = true end if (dnhectype = 8) then dnfound = true end if (dnhectype = 10) then dnfound = true end if (oblevel >= 4) then message = "Looking for downstream end of reach." message = message + nl message = message + nl + "HLTPHP: " + hltphp.asstring message = message + nl + "DNHECTYPE: " + dnhectype.asstring message = message + nl + "DNFOUND: " + dnfound.asstring message = message + nl + "DNLAKE: " + dnlake.asstring message = message + nl + "REACHLIST: " + reachlist.count.asstring message = message + nl + "PROCESSDICT: " + processdict.count.asstring message = message + nl + "CHANNELDICT: " + channeldict.count.asstring msgbox.report(message, "HECPREPRO") end end if (not dnlake) then hecdnid = hpftab.returnvalue(hphecidf, hltphp) hecdnshape = hpftab.returnvalue(hpshapef, hltphp) hecdnx = hecdnshape.getx hecdny = hecdnshape.gety end if (dnlake) then hecdnid = hpftab.returnvalue(hphecidf, hllhp) hecdnshape = hpftab.returnvalue(hpshapef, hllhp) hecdnx = hecdnshape.getx hecdny = hecdnshape.gety end for each hlrec in reachlist processdict.remove(hlrec) startdict.remove(hlrec) end if (oblevel >= 4) then message = "Recording reach data." message = message + nl message = message + nl + "HECID: " + hecid.asstring message = message + nl + "HECUPID: " + hecupid.asstring message = message + nl + "HECUPX: " + hecupx.asstring message = message + nl + "HECUPY: " + hecupy.asstring message = message + nl + "HECDNID: " + hecdnid.asstring message = message + nl + "HECDNX: " + hecdnx.asstring message = message + nl + "HECDNY: " + hecdny.asstring message = message + nl + "REACHLIST: " + reachlist.count.asstring msgbox.report(message, "HECPREPRO") end ' 'write hydro line theme ' for each hlrec in reachlist hlftab.setvalue(hlhecidf, hlrec, hecid.clone) end ' 'write data to sym line dictionary ' sldictrec = list.make sldictrec = sldictrec.add(hecid.clone) sldictrec = sldictrec.add(4) sldictrec = sldictrec.add(hecupid.clone) sldictrec = sldictrec.add(hecdnid.clone) sldictrec = sldictrec.add(hecupx.clone) sldictrec = sldictrec.add(hecupy.clone) sldictrec = sldictrec.add(hecdnx.clone) sldictrec = sldictrec.add(hecdny.clone) sldict.add(hecid.clone, sldictrec.clone) ' 'write data to sym point dictionary ' 'upstream element ' sphecdnids = spdict.get(hecupid).get(3) + 1 spdict.get(hecupid).set(3, sphecdnids) sphecdnid = hecid.clone dniddict.get(hecupid).add(sphecdnid.clone) ' 'downstream element ' sphecupids = spdict.get(hecupid).get(2) + 1 spdict.get(hecdnid).set(2, sphecupids) sphecupid = hecid.clone upiddict.get(hecdnid).add(sphecupid.clone) ' 'keep hecid counter going ' hecid = hecid + 1 ' 'close loop ' if (startdict.count = 0) then eof = true end end ' '--- subbasins (8.2) --- ' if (oblevel >= 1) then av.showmsg(mainmsg + "Subbasins.") keepgoing = av.setstatus(95) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus exit end end ' for each iprec in ipftab ipshape = ipftab.returnvalue(ipshapef, iprec) ipline = ipshape.aspolyline ipcenter = ipshape.returncenter ' outletlist = list.make for each hprec in hpftab hpshape = hpftab.returnvalue(hpshapef, hprec) if (ipline.distance(hpshape) < tol) then for each hlrec in hlftab hlshape = hlftab.returnvalue(hlshapef, hlrec) hlpoints = hlshape.asmultipoint.aslist if (hlpoints.count > 0) then hltp = hlpoints.get(hlpoints.count - 1) if (hltp.distance(hpshape) < tol) then if (hlshape.iscontainedin(ipshape)) then outletlist = outletlist.add(hprec.clone) break end end end end end end if(outletlist.count = 0) then if (oblevel >= 2) then msgbox.error("Subbasin outlet not found." + nl + "Polygon Number " + iprec.asstring , "HECPREPRO") end errors = errors + 1 continue end ' if ((outletlist.count = 1) or (not igfound)) then outlet = outletlist.get(0) end ' if ((outletlist.count > 1) and (igfound)) then zlow = 100000000 for each outrec in outletlist hpshape = hpftab.returnvalue(hpshapef, outrec) zval = igtheme.returncellvalue(hpshape) if (zval <= zlow) then zlow = zval.clone outlet = outrec.clone end end end ' outletshape = hpftab.returnvalue(hpshapef, outlet) hecdnid = hpftab.returnvalue(hphecidf, outlet) hecdnx = outletshape.getx hecdny = outletshape.gety ' spdictrec = {hecid.clone, 5, 0, 1, ipcenter.getx.clone, ipcenter.gety.clone, iprec.clone} spdict.add(hecid.clone, spdictrec.clone) dniddict.add(hecid.clone, {hecdnid.clone}) ' sldictrec = {0, 0, hecid.clone, hecdnid.clone, ipcenter.getx.clone, ipcenter.gety.clone, hecdnx.clone, hecdny.clone} sldict.add(hecid.clone, sldictrec.clone) ' hecid = hecid + 1 ' end ' '-------------------------------------- '--- create sym line shape file (9) --- '-------------------------------------- ' if (oblevel >= 1) then mainmsg = "HECPREPRO: Creating sym line. " av.showmsg(mainmsg) keepgoing = av.setstatus(97) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearstatus exit end end ' '--- set up sym line theme (9.1) --- ' 'create file ' slfilename = av.getproject.makefilename("syml", "shp") slftab = ftab.makenew(slfilename, polyline) ' 'get shape field ' slshapef = slftab.findfield("shape") ' 'add fields to sym line theme ' slfields1 = list.make ' slhecidf = field.make("hecid", #FIELD_DECIMAL, 16, 4) slhectypef = field.make("hectype", #FIELD_DECIMAL, 16, 4) slhecupidf = field.make("hecupid", #FIELD_DECIMAL, 16, 4) slhecdnidf = field.make("hecdnid", #FIELD_DECIMAL, 16, 4) slhecupxf = field.make("hecupx", #FIELD_DECIMAL, 16, 4) slhecupyf = field.make("hecupy", #FIELD_DECIMAL, 16, 4) slhecdnxf = field.make("hecdnx", #FIELD_DECIMAL, 16, 4) slhecdnyf = field.make("hecdny", #FIELD_DECIMAL, 16, 4) ' slfields1 = slfields1.add(slhecidf) slfields1 = slfields1.add(slhectypef) slfields1 = slfields1.add(slhecupidf) slfields1 = slfields1.add(slhecdnidf) slfields1 = slfields1.add(slhecupxf) slfields1 = slfields1.add(slhecupyf) slfields1 = slfields1.add(slhecdnxf) slfields1 = slfields1.add(slhecdnyf) ' if (attrib) then slfields2 = list.make for each atfnrec in mapdict.get("reach").get(3) atf = ilftab.findfield(atfnrec.get(1)) slfields2 = slfields2.add(atf) end slfields2.removeduplicates slfields1 = slfields1 + slfields2.deepclone end ' slftab.addfields(slfields1) ' 'make sym line theme editable ' slftab.seteditable(true) ' '--- user observation --- ' if (oblevel >= 2) then sltheme = ftheme.make(slftab) theview.addtheme(sltheme) sltheme.setvisible(true) theview.draw(thedisplay) end ' '--- add lines (9.2) --- ' for each slrec in sldict slfpointx = slrec.get(4) slfpointy = slrec.get(5) slfpoint = point.make(slfpointx, slfpointy) sltpointx = slrec.get(6) sltpointy = slrec.get(7) sltpoint = point.make(sltpointx, sltpointy) slline = polyline.make({{slfpoint, sltpoint}}) ' theoutrec = slftab.addrecord ' slftab.setvalue(slshapef, theoutrec, slline) slftab.setvalue(slhecidf, theoutrec, slrec.get(0)) slftab.setvalue(slhectypef, theoutrec, slrec.get(1)) slftab.setvalue(slhecupidf, theoutrec, slrec.get(2)) slftab.setvalue(slhecdnidf, theoutrec, slrec.get(3)) slftab.setvalue(slhecupxf, theoutrec, slrec.get(4)) slftab.setvalue(slhecupyf, theoutrec, slrec.get(5)) slftab.setvalue(slhecdnxf, theoutrec, slrec.get(6)) slftab.setvalue(slhecdnyf, theoutrec, slrec.get(7)) ' if (attrib) then reachlist = list.make for each hlrec in hlftab hlshape = hlftab.returnvalue(hlshapef, hlrec) hlpointlist = hlshape.asmultipoint.aslist if (hlpointlist.count < 2) then hllength = 0 else fpoint = hlpointlist.get(0) tpoint = hlpointlist.get(hlpointlist.count - 1) hllength = (((tpoint.getx - fpoint.getx)^2) + ((tpoint.gety - fpoint.gety)^2))^0.5 end if (hllength > (tol / 2)) then hlhecid = hlftab.returnvalue(hlhecidf, hlrec) if (hlhecid = slrec.get(0)) then reachlist = reachlist.add(hlrec.clone) end end end for each atfnrec in mapdict.get("reach").get(3) hlatf = hlftab.findfield(atfnrec.get(1)) total = 0 totnumb = 0 totweight = 0 for each hlrec in reachlist hlval = hlftab.returnvalue(hlatf, hlrec) if (atfnrec.get(2) = 1) then total = total + hlval end if (atfnrec.get(2) = 2) then total = total + hlval totnumb = totnumb + 1 end if (atfnrec.get(2) = 3) then hlshape = hlftab.returnvalue(hlshapef, hlrec) hlpointlist = hlshape.asmultipoint.aslist i = 0 hllength = 0 while (true) vxfp = hlpointlist.get(i) vxtp = hlpointlist.get(i + 1) vxl = (((vxtp.getx - vxfp.getx)^2) + ((vxtp.gety - vxfp.gety)^2))^0.5 hllength = hllength + vxl i = i + 1 if (i = (hlpointlist.count - 1)) then break end end total = total + (hlval * hllength) totweight = totweight + hllength end end if (atfnrec.get(2) = 1) then slval = total end if (atfnrec.get(2) = 2) then slval = total / totnumb end if (atfnrec.get(2) = 3) then slval = total / totweight end slatf = slftab.findfield(atfnrec.get(1)) slftab.setvalue(slatf, theoutrec, slval) end end ' if (oblevel >= 3) then av.run("HECLEGEND", {sltheme}) theview.draw(thedisplay) end end ' '--- user observation --- ' if (oblevel >= 2) then av.run("HECLEGEND", {sltheme}) theview.draw(thedisplay) end ' '---------------------------------------- '--- create sym point shape file (10) --- '---------------------------------------- ' if (oblevel >= 1) then mainmsg = "HECPREPRO: Creating sym point. " av.showmsg(mainmsg) keepgoing = av.setstatus(98) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearstatus exit end end ' '--- set up sym point theme (10.1) --- ' 'create file ' spfilename = av.getproject.makefilename("symp", "shp") spftab = ftab.makenew(spfilename, point) ' 'get shape field ' spshapef = spftab.findfield("shape") ' 'add fields to sym point theme ' spfields1 = list.make ' sphecidf = field.make("hecid", #FIELD_DECIMAL, 16, 4) sphectypef = field.make("hectype", #FIELD_DECIMAL, 16, 4) sphecupidsf = field.make("hecupids", #FIELD_DECIMAL, 16, 4) sphecdnidsf = field.make("hecdnids", #FIELD_DECIMAL, 16, 4) sphecxf = field.make("hecx", #FIELD_DECIMAL, 16, 4) sphecyf = field.make("hecy", #FIELD_DECIMAL, 16, 4) ' spfields1 = spfields1.add(sphecidf) spfields1 = spfields1.add(sphectypef) spfields1 = spfields1.add(sphecupidsf) spfields1 = spfields1.add(sphecdnidsf) spfields1 = spfields1.add(sphecxf) spfields1 = spfields1.add(sphecyf) ' if (attrib) then spfields2 = list.make for each maprec in mapdict.returnkeys if (maprec = "reach") then continue else for each atfnrec in mapdict.get(maprec).get(3) if (maprec = "subbasin") then atf = ipftab.findfield(atfnrec.get(1)) spfields2 = spfields2.add(atf) else if (infound) then atf = inftab.findfield(atfnrec.get(1)) spfields2 = spfields2.add(atf) end end end end end spfields2.removeduplicates spfields1 = spfields1 + spfields2.deepclone end ' spftab.addfields(spfields1) ' 'make sym point theme editable ' spftab.seteditable(true) ' '--- user observation --- ' if (oblevel >= 2) then sptheme = ftheme.make(spftab) theview.addtheme(sptheme) sptheme.setvisible(true) theview.draw(thedisplay) end ' '--- add points (10.2) --- ' for each sprec in spdict sppointx = sprec.get(4) sppointy = sprec.get(5) sppoint = point.make(sppointx, sppointy) theoutrec = spftab.addrecord spftab.setvalue(spshapef, theoutrec, sppoint) spftab.setvalue(sphecidf, theoutrec, sprec.get(0)) spftab.setvalue(sphectypef, theoutrec, sprec.get(1)) spftab.setvalue(sphecupidsf, theoutrec, sprec.get(2)) spftab.setvalue(sphecdnidsf, theoutrec, sprec.get(3)) spftab.setvalue(sphecxf, theoutrec, sprec.get(4)) spftab.setvalue(sphecyf, theoutrec, sprec.get(5)) if (attrib) then if (sprec.get(1) = 5) then for each atfnrec in mapdict.get("subbasin").get(3) ipatf = ipftab.findfield(atfnrec.get(1).clone) ipval = ipftab.returnvalue(ipatf, sprec.get(6)) spatf = spftab.findfield(atfnrec.get(1).clone) spftab.setvalue(spatf, theoutrec, ipval) end else if (infound) then for each herec in hedict.returnkeys if (sprec.get(1) = herec) then hename = hedict.get(herec) for each atfnrec in mapdict.get(hename).get(3) hpatf = hpftab.findfield(atfnrec.get(1)) hpval = hpftab.returnvalue(hpatf, sprec.get(6)) spatf = spftab.findfield(atfnrec.get(1)) spftab.setvalue(spatf, theoutrec, hpval) end end end end end end ' if (oblevel >= 2) then av.run("HECLEGEND", {sptheme}) theview.draw(thedisplay) end end ' '--- user observation --- ' if (oblevel >= 2) then av.run("HECLEGEND", {sptheme}) theview.draw(thedisplay) end ' '------------------------ '--- link tables (11) --- '------------------------ ' slftab.link(slhecidf, hlftab, hlhecidf) spftab.link(sphecidf, hpftab, hphecidf) ' '-------------------------------------- '--- create HEC-HMS basin file (12) --- '-------------------------------------- ' if (oblevel >= 1) then mainmsg = "HECPREPRO: Creating HMS basin file. " av.showmsg(mainmsg) keepgoing = av.setstatus(99) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearstatus exit end end ' '--- set up file (12.1) --- ' if (hmsmode = "d") then hmsfilename = av.getproject.makefilename("basin", "txt") else hmsfilename = hmsmode.asfilename end hmsfile = linefile.make(hmsfilename, #FILE_PERM_WRITE) ' '--- write header (12.2) --- ' outstring = "Basin: HECPREPRO generated HMS basin file" hmsfile.writeelt(outstring) outstring = " Description: HECPREPRO Version 4.0.av" hmsfile.writeelt(outstring) thisdate = date.now.setformat("dd MMMM yyyy") outstring = " Last Modified Date: " + thisdate.asstring hmsfile.writeelt(outstring) thistime = date.now.setformat("hhh:m") outstring = " Last Modified Time: " + thistime.asstring hmsfile.writeelt(outstring) outstring = " Unit System: Unknown" hmsfile.writeelt(outstring) outstring = "End:" hmsfile.writeelt(outstring) outstring = "" hmsfile.writeelt(outstring) ' '--- write element data (12.3) --- ' 'subbasin elements ' for each sprec in spftab sphectype = spftab.returnvalue(sphectypef, sprec) if (sphectype = 5) then sphecid = spftab.returnvalue(sphecidf, sprec) outstring = "Subbasin: " + sphecid.asstring hmsfile.writeelt(outstring) ' sphecx = spftab.returnvalue(sphecxf, sprec) outstring = " Canvas X: " + sphecx.asstring hmsfile.writeelt(outstring) ' sphecy = spftab.returnvalue(sphecyf, sprec) outstring = " Canvas Y: " + sphecy.asstring hmsfile.writeelt(outstring) ' sphecdnidlist = dniddict.get(sphecid) outstring = " Downstream: " for each dnid in sphecdnidlist outstring = outstring ++ dnid.asstring end hmsfile.writeelt(outstring) ' if (attrib) then for each atfrec in mapdict.get("subbasin").get(3) spf = spftab.findfield(atfrec.get(1)) spval = spftab.returnvalue(spf, sprec) outstring = " " + atfrec.get(0) + ": " + spval.asstring hmsfile.writeelt(outstring) end end ' outstring = "End:" hmsfile.writeelt(outstring) ' outstring = "" hmsfile.writeelt(outstring) end end ' 'source elements ' for each sprec in spftab sphectype = spftab.returnvalue(sphectypef, sprec) if (sphectype = 7) then sphecid = spftab.returnvalue(sphecidf, sprec) outstring = "Source: " + sphecid.asstring hmsfile.writeelt(outstring) ' sphecx = spftab.returnvalue(sphecxf, sprec) outstring = " Canvas X: " + sphecx.asstring hmsfile.writeelt(outstring) ' sphecy = spftab.returnvalue(sphecyf, sprec) outstring = " Canvas Y: " + sphecy.asstring hmsfile.writeelt(outstring) ' sphecdnidlist = dniddict.get(sphecid) outstring = " Downstream: " for each dnid in sphecdnidlist outstring = outstring ++ dnid.asstring end hmsfile.writeelt(outstring) ' if (attrib) then for each atfrec in mapdict.get("source").get(3) spf = spftab.findfield(atfrec.get(1)) spval = spftab.returnvalue(spf, sprec) outstring = " " + atfrec.get(0) + ": " + spval.asstring hmsfile.writeelt(outstring) end end ' outstring = "End:" hmsfile.writeelt(outstring) ' outstring = "" hmsfile.writeelt(outstring) end end ' 'reach elements ' for each slrec in slftab slhectype = slftab.returnvalue(slhectypef, slrec) if (slhectype = 4) then slhecid = slftab.returnvalue(slhecidf, slrec) outstring = "Reach: " + slhecid.asstring hmsfile.writeelt(outstring) ' slhecdnx = sldict.get(slhecid).get(6) outstring = " Canvas X: " + slhecdnx.asstring hmsfile.writeelt(outstring) ' slhecdny = sldict.get(slhecid).get(7) outstring = " Canvas Y: " + slhecdny.asstring hmsfile.writeelt(outstring) ' slhecupx = sldict.get(slhecid).get(4) outstring = " From Canvas X: " + slhecupx.asstring hmsfile.writeelt(outstring) ' slhecupy = sldict.get(slhecid).get(5) outstring = " From Canvas Y: " + slhecupy.asstring hmsfile.writeelt(outstring) ' slhecdnid = slftab.returnvalue(slhecdnidf, slrec) outstring = " Downstream: " + slhecdnid.asstring hmsfile.writeelt(outstring) ' if (attrib) then reachlist = list.make for each hlrec in hlftab hlshape = hlftab.returnvalue(hlshapef, hlrec) hlpointlist = hlshape.asmultipoint.aslist if (hlpointlist.count < 2) then hllength = 0 else fpoint = hlpointlist.get(0) tpoint = hlpointlist.get(hlpointlist.count - 1) hllength = (((tpoint.getx - fpoint.getx)^2) + ((tpoint.gety - fpoint.gety)^2))^0.5 end if (hllength > (tol / 2)) then hlhecid = hlftab.returnvalue(hlhecidf, hlrec) if (hlhecid = slhecid) then reachlist = reachlist.add(hlrec.clone) end end end for each atfnrec in mapdict.get("reach").get(3) hlf = hlftab.findfield(atfnrec.get(1)) total = 0 totnumb = 0 totweight = 0 for each hlrec in reachlist hlval = hlftab.returnvalue(hlf, hlrec) if (atfnrec.get(2) = 1) then total = total + hlval end if (atfnrec.get(2) = 2) then total = total + hlval totnumb = totnumb + 1 end if (atfnrec.get(2) = 3) then hlshape = hlftab.returnvalue(hlshapef, hlrec) hlpointlist = hlshape.asmultipoint.aslist i = 0 hllength = 0 while (true) vxfp = hlpointlist.get(i) vxtp = hlpointlist.get(i + 1) vxl = (((vxtp.getx - vxfp.getx)^2) + ((vxtp.gety - vxfp.gety)^2))^0.5 hllength = hllength + vxl i = i + 1 if (i = (hlpointlist.count - 1)) then break end end total = total + (hlval * hllength) totweight = totweight + hllength end end if (atfnrec.get(2) = 1) then slval = total end if (atfnrec.get(2) = 2) then slval = total / totnumb end if (atfnrec.get(2) = 3) then slval = total / totweight end outstring = " " + atfnrec.get(0) + ": " + slval.asstring hmsfile.writeelt(outstring) end end ' outstring = "End:" hmsfile.writeelt(outstring) ' outstring = "" hmsfile.writeelt(outstring) end end ' 'junction elements ' for each sprec in spftab sphectype = spftab.returnvalue(sphectypef, sprec) if ((sphectype = 3) or (sphectype = 1)) then sphecid = spftab.returnvalue(sphecidf, sprec) outstring = "Junction: " + sphecid.asstring hmsfile.writeelt(outstring) ' sphecx = spftab.returnvalue(sphecxf, sprec) outstring = " Canvas X: " + sphecx.asstring hmsfile.writeelt(outstring) ' sphecy = spftab.returnvalue(sphecyf, sprec) outstring = " Canvas Y: " + sphecy.asstring hmsfile.writeelt(outstring) ' sphecdnidlist = dniddict.get(sphecid) outstring = " Downstream: " for each dnid in sphecdnidlist outstring = outstring ++ dnid.asstring end hmsfile.writeelt(outstring) ' if (attrib) then for each atfrec in mapdict.get("junction").get(3) spf = spftab.findfield(atfrec.get(1)) spval = spftab.returnvalue(spf, sprec) outstring = " " + atfrec.get(0) + ": " + spval.asstring hmsfile.writeelt(outstring) end end ' outstring = "End:" hmsfile.writeelt(outstring) ' outstring = "" hmsfile.writeelt(outstring) end end ' 'reservoir elements ' for each sprec in spftab sphectype = spftab.returnvalue(sphectypef, sprec) if (sphectype = 10) then sphecid = spftab.returnvalue(sphecidf, sprec) outstring = "Reservoir: " + sphecid.asstring hmsfile.writeelt(outstring) ' sphecx = spftab.returnvalue(sphecxf, sprec) outstring = " Canvas X: " + sphecx.asstring hmsfile.writeelt(outstring) ' sphecy = spftab.returnvalue(sphecyf, sprec) outstring = " Canvas Y: " + sphecy.asstring hmsfile.writeelt(outstring) ' sphecdnidlist = dniddict.get(sphecid) outstring = " Downstream: " for each dnid in sphecdnidlist outstring = outstring ++ dnid.asstring end hmsfile.writeelt(outstring) ' if (attrib) then for each atfrec in mapdict.get("reservoir").get(3) spf = spftab.findfield(atfrec.get(1)) spval = spftab.returnvalue(spf, sprec) outstring = " " + atfrec.get(0) + ": " + spval.asstring hmsfile.writeelt(outstring) end end ' outstring = "End:" hmsfile.writeelt(outstring) ' outstring = "" hmsfile.writeelt(outstring) end end ' 'diversion elements ' for each sprec in spftab sphectype = spftab.returnvalue(sphectypef, sprec) if (sphectype = 8) then sphecid = spftab.returnvalue(sphecidf, sprec) outstring = "Diversion: " + sphecid.asstring hmsfile.writeelt(outstring) ' sphecx = spftab.returnvalue(sphecxf, sprec) outstring = " Canvas X: " + sphecx.asstring hmsfile.writeelt(outstring) ' sphecy = spftab.returnvalue(sphecyf, sprec) outstring = " Canvas Y: " + sphecy.asstring hmsfile.writeelt(outstring) ' sphecdnidlist = dniddict.get(sphecid) outstring = " Downstream: " for each dnid in sphecdnidlist outstring = outstring ++ dnid.asstring end hmsfile.writeelt(outstring) ' if (attrib) then for each atfrec in mapdict.get("diversion").get(3) spf = spftab.findfield(atfrec.get(1)) spval = spftab.returnvalue(spf, sprec) outstring = " " + atfrec.get(0) + ": " + spval.asstring hmsfile.writeelt(outstring) end end ' outstring = "End:" hmsfile.writeelt(outstring) ' outstring = "" hmsfile.writeelt(outstring) end end ' 'sink elements ' for each sprec in spftab sphectype = spftab.returnvalue(sphectypef, sprec) if (sphectype = 6) then sphecid = spftab.returnvalue(sphecidf, sprec) outstring = "Sink: " + sphecid.asstring hmsfile.writeelt(outstring) ' sphecx = spftab.returnvalue(sphecxf, sprec) outstring = " Canvas X: " + sphecx.asstring hmsfile.writeelt(outstring) ' sphecy = spftab.returnvalue(sphecyf, sprec) outstring = " Canvas Y: " + sphecy.asstring hmsfile.writeelt(outstring) ' if (attrib) then for each atfrec in mapdict.get("sink").get(3) spf = spftab.findfield(atfrec.get(1)) spval = spftab.returnvalue(spf, sprec) outstring = " " + atfrec.get(0) + ": " + spval.asstring hmsfile.writeelt(outstring) end end ' outstring = "End:" hmsfile.writeelt(outstring) ' outstring = "" hmsfile.writeelt(outstring) end end ' '--- close file (12.4) --- ' hmsfile.close ' '--------------------- '--- close up (13) --- '--------------------- ' '--- user observation --- ' if (oblevel >= 1) then mainmsg = "HECPREPRO: Closing up. " av.showmsg(mainmsg) keepgoing = av.setstatus(100) if (not keepgoing) then message = "Premature end." + nl + nl + "Errors detected = " + errors.asstring msgbox.info(message, "HECPREPRO") av.clearstatus exit end end ' '--- make themes non-editable --- ' hlftab.seteditable(false) hpftab.seteditable(false) slftab.seteditable(false) spftab.seteditable(false) ' '--- final message to user --- ' if (oblevel >= 1) then av.showmsg("HECPREPRO: Normal end.") av.setstatus(100) message = "Normal end." message = message + nl + "Errors detected = " + errors.asstring message = message + nl + "HMS basin file saved to " + hmsfilename.asstring msgbox.info(message, "HECPREPRO") av.clearmsg av.clearstatus end ' '----------- '--- end --- '----------- '