Monday, December 30, 2024

SWMM5 Delphi GUI Uresults.pas Summary

 Below is a high-level summary of the Uresults.pas unit, which handles reading the contents of the summary result tables from SWMM’s Status Report (i.e., .rpt) file, storing them in memory, and providing methods to retrieve or display these results in the main application.


1. Purpose and Overview

  1. Reads the summary sections (or “topics”) of the SWMM Status Report file (the temporary .rpt file) for:
    • Subcatchment Runoff
    • LID Performance
    • Groundwater
    • Subcatchment Washoff
    • Node and Link summary data (depth, flow, surcharging, etc.)
  2. Tracks the location (start line and number of lines) of each summary table in the report file.
  3. Extracts result values (e.g., maximum depth for each node, total flow for each link, etc.) and stores them in arrays, so they can be:
    • Displayed on a map, grid, or used for color theming in the main interface.
    • Used to create legends for subcatchment, node, or link map themes.
  4. Populates a string grid with the text lines from one of the summary topics in the .rpt file, allowing the user to see the numerical values displayed in a table.

This unit supplements SWMM’s main output (.out) results by adding summary-level data that SWMM writes to the .rpt file.


2. Key Data Structures and Variables

  • TTopic: An enumeration listing all the summary topics that appear in the .rpt file (e.g., rtRunoff, rtNodeDepth, rtLinkFlow, etc.).
  • Topics[]: Array of these topics.
  • TopicStart[], TopicSize[]: For each topic, stores the line number where it starts and how many lines it spans in the report.
  • TopicHeaderLines[][]: Holds up to 4 lines of column headers for each topic’s table section.
  • F: TextFile: Used to read lines from the .rpt file.
  • UpdateCount: A Boolean that tells whether to keep counting lines for the current topic.
  • Arrays like Z[]: These arrays store numeric values read from the .rpt file (e.g., link flow data, node depth data, etc.) for use in theming.

3. Principal Routines

  1. InitSummaryResults

    • Main entry point to initialize reading summary results.
    • Calls FindTopicsInReportFile to locate each summary section in the .rpt file.
  2. FindTopicsInReportFile

    • Scans the .rpt file line by line, searching for known topic headings (like Node Depth Summary, Link Flow Summary, etc.).
    • Saves each topic’s starting line (TopicStart) and dynamically determines how many lines each section (TopicSize) contains.
  3. PopulateGrid(Topic, aGrid)

    • Reads the lines of a particular Topic’s table from the .rpt file and fills them into a TStringGrid.
    • Used to display summary results in a table-like UI component.
  4. GetLinkRptValues(LinkVar, Z[]), GetNodeRptValues(NodeVar, Z[]), GetSubcatchRptValues(SubcatchVar, Z[])

    • For a given summary result variable (e.g., maximum flooding at nodes, or maximum flow in links), retrieves the numeric values for all nodes/links/subcatchments from the .rpt file and stores them in an array Z[].
    • May later be used by the map to color-code or by other UI components to display data.
  5. RetrieveValues(Topic, VarIndex, Z[])

    • Low-level routine that reads each line of a particular topic from the .rpt file, parses the needed column (VarIndex), and places the numeric value into the Z[] array at the correct position.
  6. SetLegend

    • If no legend intervals for a particular summary variable exist, it auto-scales intervals based on min/max of the retrieved summary values.
    • This drives how the map theming is automatically partitioned into color intervals.

4. How the Unit is Used

  1. After SWMM completes a run and generates the .rpt file, the main program calls InitSummaryResults to:

    • Locate each summary table in the .rpt file.
    • Identify the range of lines for each summary topic.
  2. When the user requests a display of, say, the Link Flow Summary table or wants to color the map by Max Node Depth from the .rpt file:

    • The code calls GetNodeRptValues or PopulateGrid with the right topic.
    • RetrieveValues reads each line in that topic’s region.
    • The values are stored in an array Z[] or directly assigned to the TStringGrid.
  3. Legends may be dynamically created if the user chooses a summary variable for the map. If none exist, SetLegend automatically picks interval breakpoints from min/max in the array of summary results.

  4. The retrieved data is distinct from that in the binary .out file; these routines handle only the textual summary tables in the .rpt file.


5. Interaction with Other Units

  • Uglobals: Provides global variables (TempReportFile, definitions for intervals, etc.).
  • Uproject: Used to find node or link indices (FindNode, FindLink) and store results in RptFileIndex.
  • Uutils: Tokenizing lines, numeric string conversions, etc.
  • Umap, Uoutput: May combine with these to color-code objects or show complementary numeric data.

6. Key Points and Constraints

  • Each summary topic can have multiple header lines; the code reads them to figure out columns.
  • TopicSize[] is computed by scanning the file; if a section is missing or zero lines, attempts to retrieve data from that topic fail silently.
  • The code assumes the .rpt file is from SWMM 5.2 or a consistent format. If the user modifies it or if a run fails, results might be incomplete or invalid.
  • The approach used is purely text parsing: reading line by line, searching for headings (Subcatchment Runoff Summary, etc.), collecting numerical data columns.

7. Conclusion

Uresults.pas focuses on parsing SWMM’s status report file for summary tables, retrieving relevant numeric values for subcatchments, nodes, or links, and optionally populating a data grid or setting map legend intervals. It complements SWMM’s main .out file reading (handled in other units) by providing additional summary results used for quick analysis and visualization in the SWMM GUI.

No comments:

A comprehensive explanation of how minimum travel distance relates to link length in InfoSewer

In hydraulic modeling of sewer networks, the minimum travel distance is a fundamental parameter that affects how accurately the model can si...