![]() |
OpenSWMM Engine
6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
|
Reads SWMM 5.x binary .out files produced by DefaultOutputPlugin. Reads use a shared mutable FILE cursor even on const methods: serialize all operations per reader, including refresh/close. Returns raw stored units; no endian/float-representation conversion or general corrupt-file hardening is provided. File counts/offsets must fit native allocation/long arithmetic. More...
#include <OutputReader.hpp>
Public Member Functions | |
| OutputReader ()=default | |
| Construct an unopened reader with zero metadata and empty identifier arrays. | |
| ~OutputReader () | |
| Close the file and destroy all reader-owned ID and code buffers. | |
| OutputReader (const OutputReader &)=delete | |
| Disable copying of the owned FILE cursor and buffers. | |
| OutputReader & | operator= (const OutputReader &)=delete |
| Disable assignment of the owned FILE cursor and buffers. | |
| bool | open (const char *path) |
| Open and parse the header/footer of a binary output file. | |
| bool | openLive (const char *path) |
| Open a file that is still being written (no footer yet). | |
| int | refresh () |
| Re-count periods on a live file. | |
| bool | is_live () const noexcept |
| True while opened via openLive() and the footer has not yet been seen. | |
| void | close () |
| Close the file and release resources. | |
| bool | is_open () const noexcept |
| Whether the reader has a file open and valid. | |
| int | version () const noexcept |
| Read retained parsed metadata without performing IO. | |
| int | flow_units () const noexcept |
| Read retained parsed metadata without performing IO. | |
| int | subcatch_count () const noexcept |
| Read retained parsed metadata without performing IO. | |
| int | node_count () const noexcept |
| Read retained parsed metadata without performing IO. | |
| int | link_count () const noexcept |
| Read retained parsed metadata without performing IO. | |
| int | pollut_count () const noexcept |
| Read retained parsed metadata without performing IO. | |
| int | period_count () const noexcept |
| Read retained parsed metadata without performing IO. | |
| double | start_date () const noexcept |
| Read retained parsed metadata without performing IO. | |
| int | report_step () const noexcept |
| Read retained parsed metadata without performing IO. | |
| int | error_code () const noexcept |
| Read retained parsed metadata without performing IO. | |
| bool | has_subcatch_variable (int code) const |
| Test presence of a stored subcatchment variable code. | |
| int | subcatch_var_count () const noexcept |
| Read retained parsed metadata without performing IO. | |
| int | node_var_count () const noexcept |
| Read retained parsed metadata without performing IO. | |
| int | link_var_count () const noexcept |
| Read retained parsed metadata without performing IO. | |
| int | system_var_count () const noexcept |
| Read retained parsed metadata without performing IO. | |
| const char * | subcatch_id (int index) const |
| Borrow one subcatch identifier stored by the file. | |
| const char * | node_id (int index) const |
| Borrow one node identifier stored by the file. | |
| const char * | link_id (int index) const |
| Borrow one link identifier stored by the file. | |
| const char * | pollut_id (int index) const |
| Species (pollutant) ID at a column index, or nullptr. | |
| int | pollut_units (int index) const |
| Read a stored pollutant concentration-unit code. | |
| bool | get_subcatch_result (int period, int var, float *values) const |
| Read one subcatch variable at one report period. | |
| bool | get_node_result (int period, int var, float *values) const |
| Read one node variable for all nodes at a period. | |
| bool | get_link_result (int period, int var, float *values) const |
| Read one link variable for all links at a period. | |
| bool | get_system_result (int period, int var, float *value) const |
| Read one system variable at a period. | |
| bool | get_node_block (int period, std::vector< float > &values) const |
| Read all node/link variables at one period with one contiguous read. Values are object-major: values[object * var_count + variable]. Storage is reused across calls; no history or live-file data is cached. | |
| bool | get_link_block (int period, std::vector< float > &values) const |
| Read the contiguous object-major link result block. | |
| bool | get_subcatch_series (int obj_idx, int var, int start_period, int end_period, float *values) const |
| Read an inclusive report-period series for one subcatch variable. | |
| bool | get_node_series (int obj_idx, int var, int start_period, int end_period, float *values) const |
| Read an inclusive report-period series for one node variable. | |
| bool | get_link_series (int obj_idx, int var, int start_period, int end_period, float *values) const |
| Read an inclusive report-period series for one link variable. | |
| bool | get_system_series (int var, int start_period, int end_period, float *values) const |
| Read an inclusive report-period series for one system variable. | |
| bool | get_subcatch_attribute (int obj_idx, int period, float *values, int *count) const |
| All variables for one subcatchment at one period. | |
| bool | get_node_attribute (int obj_idx, int period, float *values, int *count) const |
| All variables for one node at one period. | |
| bool | get_link_attribute (int obj_idx, int period, float *values, int *count) const |
| All variables for one link at one period. | |
| bool | get_period_time (int period, double *time) const |
| Get the simulation time for a given period. | |
| bool | get_node_stat_max_depth (int node_idx, double *value) const |
| Compute a node summary from its complete stored report-period series. | |
| bool | get_node_stat_max_overflow (int node_idx, double *value) const |
| Compute a node summary from its complete stored report-period series. | |
| bool | get_node_stat_vol_flooded (int node_idx, double *value) const |
| Compute a node summary from its complete stored report-period series. | |
| bool | get_node_stat_time_flooded (int node_idx, double *value) const |
| Compute a node summary from its complete stored report-period series. | |
Reads SWMM 5.x binary .out files produced by DefaultOutputPlugin. Reads use a shared mutable FILE cursor even on const methods: serialize all operations per reader, including refresh/close. Returns raw stored units; no endian/float-representation conversion or general corrupt-file hardening is provided. File counts/offsets must fit native allocation/long arithmetic.
|
default |
Construct an unopened reader with zero metadata and empty identifier arrays.
| openswmm::OutputReader::~OutputReader | ( | ) |
Close the file and destroy all reader-owned ID and code buffers.
|
delete |
Disable copying of the owned FILE cursor and buffers.
| void openswmm::OutputReader::close | ( | ) |
Close the file and release resources.
Safe repeatedly. Clears file/ID buffers and resets period count/live flag; other scalar counts/metadata and subcatch code storage can remain stale. Borrowed ID pointers become invalid. Never call concurrently with a read.
|
inlinenoexcept |
Read retained parsed metadata without performing IO.
|
inlinenoexcept |
Read retained parsed metadata without performing IO.
| bool openswmm::OutputReader::get_link_attribute | ( | int | obj_idx, |
| int | period, | ||
| float * | values, | ||
| int * | count ) const |
All variables for one link at one period.
Read one link object's stored result columns for a report period.
| obj_idx | Zero-based in-range object index. | |
| period | Zero-based in-range period. | |
| [out] | values | Required array of at least link_var_count() floats. |
| [out] | count | Optional number-written destination, set to link_var_count() only on success. |
| bool openswmm::OutputReader::get_link_block | ( | int | period, |
| std::vector< float > & | values ) const |
Read the contiguous object-major link result block.
| period | Zero-based in-range report period. | |
| [out] | values | Resized to link_count()*link_var_count(); allocation errors propagate. A zero-object block succeeds with an empty destination. |
| bool openswmm::OutputReader::get_link_result | ( | int | period, |
| int | var, | ||
| float * | values ) const |
Read one link variable for all links at a period.
Read one link variable at one report period.
| period | Zero-based period index. | |
| var | Zero-based physical variable-column ordinal in the stored block. | |
| [out] | values | Required writable array of at least link_count() floats, in object order. |
| bool openswmm::OutputReader::get_link_series | ( | int | obj_idx, |
| int | var, | ||
| int | start_period, | ||
| int | end_period, | ||
| float * | values ) const |
Read an inclusive report-period series for one link variable.
| obj_idx | Zero-based in-range object index. | |
| var | Zero-based physical variable-column ordinal in the stored block. | |
| start_period | Inclusive first period, at least zero. | |
| end_period | Inclusive final period, >=start_period and <period_count(). | |
| [out] | values | Required array of at least end_period-start_period+1 floats; first output corresponds to start_period. |
| bool openswmm::OutputReader::get_node_attribute | ( | int | obj_idx, |
| int | period, | ||
| float * | values, | ||
| int * | count ) const |
All variables for one node at one period.
Read one node object's stored result columns for a report period.
| obj_idx | Zero-based in-range object index. | |
| period | Zero-based in-range period. | |
| [out] | values | Required array of at least node_var_count() floats. |
| [out] | count | Optional number-written destination, set to node_var_count() only on success. |
| bool openswmm::OutputReader::get_node_block | ( | int | period, |
| std::vector< float > & | values ) const |
Read all node/link variables at one period with one contiguous read. Values are object-major: values[object * var_count + variable]. Storage is reused across calls; no history or live-file data is cached.
Read the contiguous object-major node result block.
| period | Zero-based in-range report period. | |
| [out] | values | Resized to node_count()*node_var_count(); allocation errors propagate. A zero-object block succeeds with an empty destination. |
| bool openswmm::OutputReader::get_node_result | ( | int | period, |
| int | var, | ||
| float * | values ) const |
Read one node variable for all nodes at a period.
Read one node variable at one report period.
| period | Zero-based period index. | |
| var | Zero-based physical variable-column ordinal in the stored block. | |
| [out] | values | Required writable array of at least node_count() floats, in object order. |
| bool openswmm::OutputReader::get_node_series | ( | int | obj_idx, |
| int | var, | ||
| int | start_period, | ||
| int | end_period, | ||
| float * | values ) const |
Read an inclusive report-period series for one node variable.
| obj_idx | Zero-based in-range object index. | |
| var | Zero-based physical variable-column ordinal in the stored block. | |
| start_period | Inclusive first period, at least zero. | |
| end_period | Inclusive final period, >=start_period and <period_count(). | |
| [out] | values | Required array of at least end_period-start_period+1 floats; first output corresponds to start_period. |
| bool openswmm::OutputReader::get_node_stat_max_depth | ( | int | node_idx, |
| double * | value ) const |
Compute a node summary from its complete stored report-period series.
| node_idx | Zero-based in-range node. | |
| [out] | value | Required destination. Maximum stored report-period depth in the file's length unit. |
| bool openswmm::OutputReader::get_node_stat_max_overflow | ( | int | node_idx, |
| double * | value ) const |
Compute a node summary from its complete stored report-period series.
| node_idx | Zero-based in-range node. | |
| [out] | value | Required destination. Maximum stored report-period overflow in the file's flow unit. |
| bool openswmm::OutputReader::get_node_stat_time_flooded | ( | int | node_idx, |
| double * | value ) const |
Compute a node summary from its complete stored report-period series.
| node_idx | Zero-based in-range node. | |
| [out] | value | Required destination. Number of positive-overflow periods times report_step, in seconds. |
| bool openswmm::OutputReader::get_node_stat_vol_flooded | ( | int | node_idx, |
| double * | value ) const |
Compute a node summary from its complete stored report-period series.
| node_idx | Zero-based in-range node. | |
| [out] | value | Required destination. Sum of positive report-period overflow times report_step seconds, in raw file-flow-unit times seconds (for example L for LPS, ft3 for CFS; GPM remains gallons/minute times seconds, without minute conversion). |
| bool openswmm::OutputReader::get_period_time | ( | int | period, |
| double * | time ) const |
Get the simulation time for a given period.
| period | Zero-based index in [0,period_count()). | |
| [out] | time | Required writable double receiving the raw SWMM serial day value (day zero 1899-12-30). No timezone conversion is applied. |
| bool openswmm::OutputReader::get_subcatch_attribute | ( | int | obj_idx, |
| int | period, | ||
| float * | values, | ||
| int * | count ) const |
All variables for one subcatchment at one period.
Read one subcatch object's stored result columns for a report period.
| obj_idx | Zero-based in-range object index. | |
| period | Zero-based in-range period. | |
| [out] | values | Required array of at least min(subcatch_var_count(),8+pollut_count()) floats. |
| [out] | count | Optional number-written destination, set to min(subcatch_var_count(),8+pollut_count()) only on success. |
| bool openswmm::OutputReader::get_subcatch_result | ( | int | period, |
| int | var, | ||
| float * | values ) const |
Read one subcatch variable at one report period.
| period | Zero-based period index. | |
| var | Semantic subcatch code resolved through the file code list, not a column ordinal. | |
| [out] | values | Required writable array of at least subcatch_count() floats, in object order. |
| bool openswmm::OutputReader::get_subcatch_series | ( | int | obj_idx, |
| int | var, | ||
| int | start_period, | ||
| int | end_period, | ||
| float * | values ) const |
Read an inclusive report-period series for one subcatch variable.
| obj_idx | Zero-based in-range object index. | |
| var | Semantic subcatch code resolved through the file code list, not a column ordinal. | |
| start_period | Inclusive first period, at least zero. | |
| end_period | Inclusive final period, >=start_period and <period_count(). | |
| [out] | values | Required array of at least end_period-start_period+1 floats; first output corresponds to start_period. |
| bool openswmm::OutputReader::get_system_result | ( | int | period, |
| int | var, | ||
| float * | value ) const |
Read one system variable at a period.
Read one system variable at one report period.
| period | Zero-based period index. | |
| var | Zero-based physical variable-column ordinal in the stored block. | |
| [out] | value | Required writable float. |
| bool openswmm::OutputReader::get_system_series | ( | int | var, |
| int | start_period, | ||
| int | end_period, | ||
| float * | values ) const |
Read an inclusive report-period series for one system variable.
| var | Zero-based physical variable-column ordinal in the stored block. | |
| start_period | Inclusive first period, at least zero. | |
| end_period | Inclusive final period, >=start_period and <period_count(). | |
| [out] | values | Required array of at least end_period-start_period+1 floats; first output corresponds to start_period. |
|
inline |
Test presence of a stored subcatchment variable code.
| code | Nonnegative code, not a physical column ordinal. |
|
inlinenoexcept |
True while opened via openLive() and the footer has not yet been seen.
|
inlinenoexcept |
Whether the reader has a file open and valid.
|
inlinenoexcept |
Read retained parsed metadata without performing IO.
| const char * openswmm::OutputReader::link_id | ( | int | index | ) | const |
Borrow one link identifier stored by the file.
| index | Zero-based link index. Requires a successfully open reader; close() clears names while retaining object counts. |
|
inlinenoexcept |
Read retained parsed metadata without performing IO.
|
inlinenoexcept |
Read retained parsed metadata without performing IO.
| const char * openswmm::OutputReader::node_id | ( | int | index | ) | const |
Borrow one node identifier stored by the file.
| index | Zero-based node index. Requires a successfully open reader; close() clears names while retaining object counts. |
|
inlinenoexcept |
Read retained parsed metadata without performing IO.
| bool openswmm::OutputReader::open | ( | const char * | path | ) |
Open and parse the header/footer of a binary output file.
| path | NUL-terminated UTF-8 filename, read-only. Null returns false while preserving an existing open reader; a nonnull path closes it before attempting the new file. Requires the expected SWMM binary layout and complete footer. Failure closes any newly opened file but retains some parsed scalar metadata; allocation exceptions propagate. A footer simulation error code does not itself make open fail. Caller serializes file access and checks is_open() before ID reads. |
| bool openswmm::OutputReader::openLive | ( | const char * | path | ) |
Open a file that is still being written (no footer yet).
Every offset the footer would supply is derived by parsing the header forward, and the period count is derived from the file size: floor((size - output_start) / bytes_per_period), so a partially flushed last record is never counted. Call refresh() to pick up periods appended since. Works on any file with a complete header — including one from a run that died before writing its footer. Never writes to the file.
| path | NUL-terminated UTF-8 filename with a complete expected header/input/ variable section. Null preserves an existing reader; nonnull closes it first. Initial refresh errors can leave the count zero while openLive still succeeds. This method neither waits for a header nor writes/locks the growing source file. Caller coordinates writer visibility and serializes this reader's cursor access. |
|
delete |
Disable assignment of the owned FILE cursor and buffers.
|
inlinenoexcept |
Read retained parsed metadata without performing IO.
|
inlinenoexcept |
Read retained parsed metadata without performing IO.
| const char * openswmm::OutputReader::pollut_id | ( | int | index | ) | const |
Species (pollutant) ID at a column index, or nullptr.
The writer has always emitted a fourth ID list after the link IDs — the species names, one per pollutant column — but the reader stopped after three and no public entry point exposed them. Water age reports as a trailing __WATER_AGE__ column whose unit field necessarily reuses a concentration code (the .out unit enum has no HOURS slot), so the NAME is the only way a consumer can tell hours from mg/L. That made this reader a prerequisite for water age being usable at all, not a convenience.
Borrow one pollut identifier stored by the file.
| index | Zero-based pollut index. Bounds use the actual stored name array. |
| int openswmm::OutputReader::pollut_units | ( | int | index | ) | const |
Read a stored pollutant concentration-unit code.
| index | Zero-based pollutant column. |
| int openswmm::OutputReader::refresh | ( | ) |
Re-count periods on a live file.
Re-reads the file size and updates period_count(). When the footer has appeared (the run finished) it is adopted — period count and error code become the writer's own — and the reader leaves live mode; subsequent calls are no-ops. On a reader opened with open() this returns period_count() unchanged.
|
inlinenoexcept |
Read retained parsed metadata without performing IO.
|
inlinenoexcept |
Read retained parsed metadata without performing IO.
|
inlinenoexcept |
Read retained parsed metadata without performing IO.
| const char * openswmm::OutputReader::subcatch_id | ( | int | index | ) | const |
Borrow one subcatch identifier stored by the file.
| index | Zero-based subcatch index. Requires a successfully open reader; close() clears names while retaining object counts. |
|
inlinenoexcept |
Read retained parsed metadata without performing IO.
|
inlinenoexcept |
Read retained parsed metadata without performing IO.
|
inlinenoexcept |
Read retained parsed metadata without performing IO.