OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
OutputReader.hpp
Go to the documentation of this file.
1
25#ifndef OPENSWMM_ENGINE_OUTPUT_READER_HPP
26#define OPENSWMM_ENGINE_OUTPUT_READER_HPP
27
28#include <cstdio>
29#include <cstdint>
30#include <string>
31#include <vector>
32
33namespace openswmm {
34
40public:
41 OutputReader() = default;
43
44 OutputReader(const OutputReader&) = delete;
46
52 bool open(const char* path);
53
57 void close();
58
60 bool is_open() const noexcept { return file_ != nullptr; }
61
62 // -- Metadata ---------------------------------------------------------
63
64 int version() const noexcept { return version_; }
65 int flow_units() const noexcept { return flow_units_; }
66 int subcatch_count() const noexcept { return n_subcatch_; }
67 int node_count() const noexcept { return n_nodes_; }
68 int link_count() const noexcept { return n_links_; }
69 int pollut_count() const noexcept { return n_polluts_; }
70 int period_count() const noexcept { return n_periods_; }
71 double start_date() const noexcept { return start_date_; }
72 int report_step() const noexcept { return report_step_; }
73 int error_code() const noexcept { return error_code_; }
74
75 int subcatch_var_count() const noexcept { return n_subcatch_vars_; }
76 int node_var_count() const noexcept { return n_node_vars_; }
77 int link_var_count() const noexcept { return n_link_vars_; }
78 int system_var_count() const noexcept { return n_system_vars_; }
79
80 // -- Object IDs -------------------------------------------------------
81
82 const char* subcatch_id(int index) const;
83 const char* node_id(int index) const;
84 const char* link_id(int index) const;
85
86 // -- Per-period results (all objects, one variable) --------------------
87
93 bool get_subcatch_result(int period, int var, float* values) const;
94
96 bool get_node_result(int period, int var, float* values) const;
97
99 bool get_link_result(int period, int var, float* values) const;
100
102 bool get_system_result(int period, int var, float* value) const;
103
104 // -- Time series (one object, one variable, period range) --------------
105
106 bool get_subcatch_series(int obj_idx, int var,
107 int start_period, int end_period,
108 float* values) const;
109
110 bool get_node_series(int obj_idx, int var,
111 int start_period, int end_period,
112 float* values) const;
113
114 bool get_link_series(int obj_idx, int var,
115 int start_period, int end_period,
116 float* values) const;
117
118 bool get_system_series(int var,
119 int start_period, int end_period,
120 float* values) const;
121
122 // -- Per-object all-variables at one period ----------------------------
123
125 bool get_subcatch_attribute(int obj_idx, int period,
126 float* values, int* count) const;
127
129 bool get_node_attribute(int obj_idx, int period,
130 float* values, int* count) const;
131
133 bool get_link_attribute(int obj_idx, int period,
134 float* values, int* count) const;
135
136 // -- Period time -------------------------------------------------------
137
139 bool get_period_time(int period, double* time) const;
140
141private:
142 static constexpr int32_t MAGIC_NUMBER = 516114522;
143
144 FILE* file_ = nullptr;
145
146 // Header fields
147 int version_ = 0;
148 int flow_units_ = 0;
149 int n_subcatch_ = 0;
150 int n_nodes_ = 0;
151 int n_links_ = 0;
152 int n_polluts_ = 0;
153
154 // Variable counts (read from file)
155 int n_subcatch_vars_ = 0;
156 int n_node_vars_ = 0;
157 int n_link_vars_ = 0;
158 int n_system_vars_ = 0;
159
160 // Report metadata
161 double start_date_ = 0.0;
162 int report_step_ = 0;
163
164 // Footer fields
165 long id_start_pos_ = 0;
166 long input_start_pos_ = 0;
167 long output_start_pos_ = 0;
168 int n_periods_ = 0;
169 int error_code_ = 0;
170
171 // Computed: bytes per period record
172 long bytes_per_period_ = 0;
173
174 // Object IDs
175 std::vector<std::string> subcatch_ids_;
176 std::vector<std::string> node_ids_;
177 std::vector<std::string> link_ids_;
178
179 // -- Helpers ----------------------------------------------------------
180
181 bool readFooter();
182 bool readHeader();
183 bool readIDs();
184 bool readVariableCodes();
185
186 bool readInt4(int32_t& value) const;
187 bool readReal4(float& value) const;
188 bool readReal8(double& value) const;
189
191 long periodOffset(int period) const;
192
199 bool seekToVar(int period, int obj_type, int obj_idx, int var) const;
200};
201
202} /* namespace openswmm */
203
204#endif /* OPENSWMM_ENGINE_OUTPUT_READER_HPP */
Reads SWMM 5.x binary .out files produced by DefaultOutputPlugin.
Definition OutputReader.hpp:39
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:214
int node_var_count() const noexcept
Definition OutputReader.hpp:76
bool get_subcatch_series(int obj_idx, int var, int start_period, int end_period, float *values) const
Definition OutputReader.cpp:151
OutputReader & operator=(const OutputReader &)=delete
int system_var_count() const noexcept
Definition OutputReader.hpp:78
int subcatch_var_count() const noexcept
Definition OutputReader.hpp:75
const char * subcatch_id(int index) const
Definition OutputReader.cpp:83
bool get_link_result(int period, int var, float *values) const
Read one link variable for all links at a period.
Definition OutputReader.cpp:126
double start_date() const noexcept
Definition OutputReader.hpp:71
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:242
int node_count() const noexcept
Definition OutputReader.hpp:67
void close()
Close the file and release resources.
Definition OutputReader.cpp:68
const char * link_id(int index) const
Definition OutputReader.cpp:93
const char * node_id(int index) const
Definition OutputReader.cpp:88
bool get_node_series(int obj_idx, int var, int start_period, int end_period, float *values) const
Definition OutputReader.cpp:166
bool get_link_series(int obj_idx, int var, int start_period, int end_period, float *values) const
Definition OutputReader.cpp:181
bool get_node_result(int period, int var, float *values) const
Read one node variable for all nodes at a period.
Definition OutputReader.cpp:114
int pollut_count() const noexcept
Definition OutputReader.hpp:69
int flow_units() const noexcept
Definition OutputReader.hpp:65
int link_count() const noexcept
Definition OutputReader.hpp:68
bool open(const char *path)
Open and parse the header/footer of a binary output file.
Definition OutputReader.cpp:34
bool get_system_result(int period, int var, float *value) const
Read one system variable at a period.
Definition OutputReader.cpp:138
int report_step() const noexcept
Definition OutputReader.hpp:72
int link_var_count() const noexcept
Definition OutputReader.hpp:77
bool get_period_time(int period, double *time) const
Get the simulation time for a given period.
Definition OutputReader.cpp:260
int version() const noexcept
Definition OutputReader.hpp:64
int subcatch_count() const noexcept
Definition OutputReader.hpp:66
bool is_open() const noexcept
Whether the reader has a file open and valid.
Definition OutputReader.hpp:60
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:228
OutputReader(const OutputReader &)=delete
int error_code() const noexcept
Definition OutputReader.hpp:73
~OutputReader()
Definition OutputReader.cpp:30
bool get_subcatch_result(int period, int var, float *values) const
Read one subcatch variable for all subcatchments at a period.
Definition OutputReader.cpp:102
bool get_system_series(int var, int start_period, int end_period, float *values) const
Definition OutputReader.cpp:196
int period_count() const noexcept
Definition OutputReader.hpp:70
Definition Controls.cpp:24