' '---------------------------- '--- Creation information --- '---------------------------- ' 'Name: calcvol.ave 'Version: 1.0 'Date: 02/07/97 'Author: Ferdi Hellweger ' Center for Research in Water Resources ' The University of Texas at Austin ' ferdi@crwr.utexas.edu ' '--------------------------- '--- Purpose/Description --- '--------------------------- ' 'This program computes the volume. ' '--------------------------------------------- '--- Check if units configuration happened --- '--------------------------------------------- ' if (not _configu) then configure = msgbox.yesno("Units are not configured. Configure it now?","BALANCE",true) if (configure) then av.run("balconu", nil) else exit end end ' '---------------- '--- Get view --- '---------------- ' theview = av.getactivedoc ' '----------------- '--- Get theme --- '----------------- ' theactivethemes = theview.getactivethemes if (theactivethemes.count = 0) then msgbox.error("No active themes found", "BALANCE") exit end if (theactivethemes.count > 1) then msgbox.error("Too many active themes found", "BALANCE") exit end theptheme = theactivethemes.get(0) pftab = theptheme.getftab pshapef = pftab.findfield("shape") pshape = pftab.returnvalue(pshapef,0) if (not (pshape.getclass.getclassname = "polygon")) then msgbox.error("The theme needs to be a polygon theme", "BALANCE") exit end ' '-------------------- '--- Set up theme --- '-------------------- ' hf = pftab.findfield("h") if (hf = nil) then addfield = msgbox.yesno("Can't find 'h' field in polygon theme. Add it?","BALANCE", true) if (addfield) then pftab.seteditable(true) hf = field.make("h", #FIELD_DECIMAL, 16, 4) pftab.addfields({hf}) pftab.seteditable(false) else exit end end ' vf = pftab.findfield("v") if (vf = nil) then addfield = msgbox.yesno("Can't find 'v' field in polygon theme. Add it?","BALANCE", true) if (addfield) then pftab.seteditable(true) vf = field.make("v", #FIELD_DECIMAL, 16, 4) pftab.addfields({vf}) pftab.seteditable(false) else exit end end ' '----------------- '--- Calculate --- '----------------- ' '--- Initial set up --- ' 'make polygon attribute table editable ' pftab.seteditable(true) ' '--- Loop --- ' for each prec in pftab ' 'get depth ' h = pftab.returnvalue(hf, prec) ' 'calculate area ' pshape = pftab.returnvalue(pshapef, prec) lshape = pshape.aspolyline mpoint = lshape.asmultipoint plist = mpoint.aslist n = plist.count i = 1 a = 0 for each prec in plist yterm = plist.get(i - 1).gety if (i < n ) then xterma = plist.get(i).getx end if (i = n ) then xterma = plist.get(0).getx end if (i > 1) then xtermb = plist.get(i - 2).getx end if (i = 1) then xtermb = plist.get(n - 1).getx end a = a + (yterm * (xterma - xtermb)) i = i + 1 end a = 0.5 * a.abs ' 'calculate volume ' v = a * h ' 'write v to polygon attribute table ' pftab.setvalue(vf, prec, v) ' end ' 'make polygon attribute table non editable ' pftab.seteditable(false) ' 'final message to user ' message = "Volume, v calculated" msgbox.info(message,"BALANCE") ' '----------- '--- End --- '----------- '