41#ifndef OPENSWMM_ENGINE_OUTPUT_READER_HPP
42#define OPENSWMM_ENGINE_OUTPUT_READER_HPP
90 bool open(
const char* path);
130 bool is_live() const noexcept {
return live_; }
142 bool is_open() const noexcept {
return file_ !=
nullptr; }
149 int version() const noexcept {
return version_; }
192 const int i = subcatchColumn(code);
193 return i >= 0 && i < n_subcatch_vars_;
223 const char*
node_id(
int index)
const;
228 const char*
link_id(
int index)
const;
304 bool get_node_block(
int period, std::vector<float>& values)
const;
311 bool get_link_block(
int period, std::vector<float>& values)
const;
325 float* values)
const;
336 bool get_node_series(
int obj_idx,
int var,
int start_period,
int end_period,
337 float* values)
const;
348 bool get_link_series(
int obj_idx,
int var,
int start_period,
int end_period,
349 float* values)
const;
359 bool get_system_series(
int var,
int start_period,
int end_period,
float* values)
const;
445 static constexpr int32_t MAGIC_NUMBER = 516114522;
447 FILE* file_ =
nullptr;
458 int n_subcatch_vars_ = 0;
459 std::vector<int> subcatch_codes_;
463 int subcatchColumn(
int code)
const;
464 int n_node_vars_ = 0;
465 int n_link_vars_ = 0;
466 int n_system_vars_ = 0;
469 double start_date_ = 0.0;
470 int report_step_ = 0;
473 long id_start_pos_ = 0;
474 long input_start_pos_ = 0;
475 long output_start_pos_ = 0;
480 long bytes_per_period_ = 0;
486 std::vector<std::string> subcatch_ids_;
487 std::vector<std::string> node_ids_;
488 std::vector<std::string> link_ids_;
489 std::vector<std::string> pollut_ids_;
490 std::vector<int> pollut_units_;
503 bool readResultBlock(
int period,
int objectType,
int count,
int variables,
504 std::vector<float>& values)
const;
527 bool readVariableCodes();
533 bool readInt4(int32_t& value)
const;
538 bool readReal4(
float& value)
const;
543 bool readReal8(
double& value)
const;
549 long periodOffset(
int period)
const;
559 bool seekToVar(
int period,
int obj_type,
int obj_idx,
int var)
const;
bool get_subcatch_attribute(int obj_idx, int period, float *values, int *count) const
All variables for one subcatchment at one period.
Definition OutputReader.cpp:422
int node_var_count() const noexcept
Read retained parsed metadata without performing IO.
Definition OutputReader.hpp:202
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.
Definition OutputReader.cpp:339
OutputReader()=default
Construct an unopened reader with zero metadata and empty identifier arrays.
bool is_live() const noexcept
True while opened via openLive() and the footer has not yet been seen.
Definition OutputReader.hpp:130
bool get_node_stat_max_depth(int node_idx, double *value) const
Compute a node summary from its complete stored report-period series.
Definition OutputReader.cpp:810
OutputReader & operator=(const OutputReader &)=delete
Disable assignment of the owned FILE cursor and buffers.
int system_var_count() const noexcept
Read retained parsed metadata without performing IO.
Definition OutputReader.hpp:210
int subcatch_var_count() const noexcept
Read retained parsed metadata without performing IO.
Definition OutputReader.hpp:198
bool get_node_stat_max_overflow(int node_idx, double *value) const
Compute a node summary from its complete stored report-period series.
Definition OutputReader.cpp:833
bool get_node_stat_vol_flooded(int node_idx, double *value) const
Compute a node summary from its complete stored report-period series.
Definition OutputReader.cpp:856
const char * subcatch_id(int index) const
Borrow one subcatch identifier stored by the file.
Definition OutputReader.cpp:205
bool get_link_result(int period, int var, float *values) const
Read one link variable for all links at a period.
Definition OutputReader.cpp:282
double start_date() const noexcept
Read retained parsed metadata without performing IO.
Definition OutputReader.hpp:177
bool get_link_attribute(int obj_idx, int period, float *values, int *count) const
All variables for one link at one period.
Definition OutputReader.cpp:464
int node_count() const noexcept
Read retained parsed metadata without performing IO.
Definition OutputReader.hpp:161
const char * pollut_id(int index) const
Species (pollutant) ID at a column index, or nullptr.
Definition OutputReader.cpp:223
void close()
Close the file and release resources.
Definition OutputReader.cpp:187
const char * link_id(int index) const
Borrow one link identifier stored by the file.
Definition OutputReader.cpp:217
bool get_node_stat_time_flooded(int node_idx, double *value) const
Compute a node summary from its complete stored report-period series.
Definition OutputReader.cpp:885
const char * node_id(int index) const
Borrow one node identifier stored by the file.
Definition OutputReader.cpp:211
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.
Definition OutputReader.cpp:360
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.
Definition OutputReader.cpp:380
bool get_node_result(int period, int var, float *values) const
Read one node variable for all nodes at a period.
Definition OutputReader.cpp:265
int pollut_count() const noexcept
Read retained parsed metadata without performing IO.
Definition OutputReader.hpp:169
int flow_units() const noexcept
Read retained parsed metadata without performing IO.
Definition OutputReader.hpp:153
int link_count() const noexcept
Read retained parsed metadata without performing IO.
Definition OutputReader.hpp:165
bool open(const char *path)
Open and parse the header/footer of a binary output file.
Definition OutputReader.cpp:51
bool get_system_result(int period, int var, float *value) const
Read one system variable at a period.
Definition OutputReader.cpp:299
bool has_subcatch_variable(int code) const
Test presence of a stored subcatchment variable code.
Definition OutputReader.hpp:191
int report_step() const noexcept
Read retained parsed metadata without performing IO.
Definition OutputReader.hpp:181
int link_var_count() const noexcept
Read retained parsed metadata without performing IO.
Definition OutputReader.hpp:206
int refresh()
Re-count periods on a live file.
Definition OutputReader.cpp:145
bool get_period_time(int period, double *time) const
Get the simulation time for a given period.
Definition OutputReader.cpp:487
int version() const noexcept
Read retained parsed metadata without performing IO.
Definition OutputReader.hpp:149
int subcatch_count() const noexcept
Read retained parsed metadata without performing IO.
Definition OutputReader.hpp:157
bool is_open() const noexcept
Whether the reader has a file open and valid.
Definition OutputReader.hpp:142
bool get_node_attribute(int obj_idx, int period, float *values, int *count) const
All variables for one node at one period.
Definition OutputReader.cpp:445
bool openLive(const char *path)
Open a file that is still being written (no footer yet).
Definition OutputReader.cpp:100
OutputReader(const OutputReader &)=delete
Disable copying of the owned FILE cursor and buffers.
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[...
Definition OutputReader.cpp:327
int error_code() const noexcept
Read retained parsed metadata without performing IO.
Definition OutputReader.hpp:185
~OutputReader()
Close the file and destroy all reader-owned ID and code buffers.
Definition OutputReader.cpp:47
bool get_link_block(int period, std::vector< float > &values) const
Read the contiguous object-major link result block.
Definition OutputReader.cpp:331
bool get_subcatch_result(int period, int var, float *values) const
Read one subcatch variable at one report period.
Definition OutputReader.cpp:247
int pollut_units(int index) const
Read a stored pollutant concentration-unit code.
Definition OutputReader.cpp:229
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.
Definition OutputReader.cpp:400
int period_count() const noexcept
Read retained parsed metadata without performing IO.
Definition OutputReader.hpp:173
Definition ExchangeLaw.hpp:60