Extended Summary of the Uimport.pas
Unit
This unit, Uimport.pas
, is responsible for importing SWMM project data from a formatted text file (usually the .inp
file). It handles lines and tokens read from the file and populates SWMM's internal data structures with subcatchments, nodes, links, pollutants, land uses, pump curves, raingages, etc. It also supports reading older and newer formats for various sections (like older or updated raingage format), and reading optional or legacy sections (like [EVENTS]
or [BACKDROP]
).
Below is a detailed overview of how the unit works and the responsibilities of its types, variables, and procedures.
1. Overall Purpose
Uimport.pas
manages:
- Opening a SWMM project file (
.inp
typically). - Reading each line, splitting into tokens, removing comments, and determining which input section it belongs to (via
[RAINGAGES]
,[JUNCTIONS]
,[CONDUITS]
, etc.). - Parsing tokens into SWMM data objects, such as nodes, links, subcatchments, etc. For each recognized section, there is a parser routine (e.g.,
ReadConduitData
,ReadSubcatchmentData
) that populates the relevant fields. - Error handling and message reporting if lines have invalid data or references to undefined items.
- Post-processing after the entire file is read, such as re-assigning pointers to ID strings, re-calculating subcatchment centroids, adjusting map dimensions, etc.
2. Key Variables and Data Structures
-
SectionWords
: array[0..57]- Contains all recognized section keywords in SWMM’s input file (e.g.
[RAINGAGES]
,[JUNCTIONS]
,[CONTROLS]
, etc.). - The integer index into this array (when a match is found) determines which parser function handles the subsequent lines.
- Contains all recognized section keywords in SWMM’s input file (e.g.
-
Section
: Integer- Holds the current input-section index. Initially
-1
(no section). Once a line with[
is found,Section
is updated.
- Holds the current input-section index. Initially
-
FileType: TFileType
- Either
ftInput
orftImport
. TypicallyftInput
is used for reading.inp
data.
- Either
-
Objects:
SubcatchList, NodeList, LinkList
: transient string lists used only during the import process ifFileType = ftInput
. They help quickly look up existing Subcatch/Node/Link objects by name before final pointers are set.
-
Error Handling:
ErrCount, ErrList
: counters and list for storing error messages. Up toMAX_ERRORS
(50) lines are recorded.
-
Various:
TokList
: the token list for the current line being processed.PrevID, PrevIndex
: used for lines that continue the same object across multiple lines (e.g., multiple lines describing a single[HYDROGRAPH]
or[TIMESERIES]
block).
3. Reading the File
3.1 ReadInpFile(const Fname: String): Boolean
- Attempts to open the file as text, then calls
ReadFile
(a local procedure) that line-by-line parses:- Removes comment portion.
- Checks if line defines a new
[SECTION]
. If yes, updatesSection
. - Otherwise, tokenizes the line (
TokList
,Ntoks
) and callsParseInpLine
to handle it, depending onSection
.
- If any references to undefined objects or numeric parse failures occur, an error is appended to
ErrList
. - After reading is done:
- Calls
SetIDPtrs
to link each object’s.ID
property to the ID string table. - Calls
SetSubcatchCentroids
,SetStorageCentroids
to compute polygons' centroids. - Calls
SetMapDimensions
to detect the bounding coordinates for the map.
- Calls
3.2 ParseInpLine(S: String): Integer
- Switch statement on
Section
. Example:- If
Section = 14
, callsReadConduitData
. - If
Section = 23
, callsReadPollutantData
. - etc.
- If
3.3 Routines for Each Section
-
For instance,
ReadConduitData
expects at least 7 tokens:- Conduit ID
From Node ID
To Node ID
Length
Roughness
Inlet Offset
Outlet Offset
- If references are invalid (can't find node by name), it reports an error.
-
ReadSubcatchmentData
similarly expects[SUBCATCHMENT]
lines, etc. -
Many of these are fairly self-contained, returning an error code if not enough tokens appear or if numeric parse fails.
4. Post-Processing
SetMapDimensions
: If user-supplied[MAP]
or[BACKDROP]
sections didn't provide bounding dimensions, the module scans all objects (nodes, subcatch polygons, etc.) to find min/max X & Y for the map.SetIDPtrs
: ensures each subcatch/node/link object’sID
pointer references the actual ID name in the TList object strings.SetSubcatchCentroids
andSetStorageCentroids
: compute polygon centroid X/Y if polygon has vertices.
5. Notable Edge Cases / Details
- Old vs. new format: Some sections (e.g.
[RAINGAGES]
,[HYDROGRAPHS]
) have older 4.4/4.5 era formats;ReadOldRaingageData
orReadNewRaingageData
handle this. [FILE]
section: references external interface files.- Deprecated
[Import]
logic**: not actually used, but placeholders remain. - Backdrop:
[BACKDROP]
lines can define a background image file and coordinate extents. If loaded,SetMapDimensions
merges it with the bounding extents of all other objects. - Many unrecognized keywords or not enough items produce an error line in
ErrList
.
6. Startup & Time Setup
SetDefaultDates
: ensuresStart/End/Report
date/time entries are valid. If not found in the file or invalid, it uses default or tries to fix them.
7. Summary of Use
When opening a SWMM .inp
project file:
- The main form calls
OpenProject(Fname)
. - This sets up default map dimension, calls
ReadInpFile(...)
. ReadInpFile
usesReadFile
to parse all lines. Each line leads to a specialized reader routine, storing data in the globalProject
object.- Errors encountered along the way are accumulated in
ErrList
. If any exist, a status form displays them. SetDefaultDates
,SetMapDimensions
,SetIDPtrs
finalize the newly imported data.
Hence, Uimport.pas
is central to making user’s textual project files into an in-memory model representation that the SWMM GUI can manipulate.
No comments:
Post a Comment