39#ifndef OPENSWMM_CLIMATE_FILE_HPP
40#define OPENSWMM_CLIMATE_FILE_HPP
120 bool open(
const std::string& path,
double start_oa_date,
int unit_system,
int temp_units = -1);
155 bool isOpen()
const {
return file_ !=
nullptr; }
158 static constexpr double MISSING = -1.0e10;
160 static constexpr int MAX_LINE = 512;
163 std::FILE* file_ =
nullptr;
165 int unit_system_ = 0;
168 double file_data_[4][32] = {};
171 double day_offset_ = 0.0;
174 int field_pos_[4] = {-1, -1, -1, -1};
175 int date_field_pos_ = 0;
176 int wind_type_ =
WDMV;
180 char saved_line_[MAX_LINE + 1] = {};
181 bool has_saved_line_ =
false;
196 bool isGhcndFormat(
const char* line);
207 bool bufferMonth(
int year,
int month);
220 void parseUserLine(
const char* line);
228 void parseGhcndLine(
const char* line);
236 void parseTD3200Line(
const char* line);
243 void parseDLY0204Line(
const char* line);
252 static void oaDateToYMD(
double oa_date,
int&
y,
int& m,
int& d);
257 double convertTemp(
double raw)
const;
262 double convertEvap(
double raw)
const;
268 double convertWind(
double raw,
int wind_type)
const;
ClimateFileReader()=default
Construct a closed reader with no cached month and zero day offset. Initial temperature encoding is t...
ClimateFileFormat format() const
Read the recognized first-line format without further IO.
Definition ClimateFile.hpp:150
~ClimateFileReader()
Close the owned stream, ignoring fclose status. Caller first ends all concurrent/borrowed use; no fin...
Definition ClimateFile.cpp:41
ClimateFileReader & operator=(const ClimateFileReader &)=delete
Disallow copy assignment of owned stream/cached cursor state.
void close()
Close the stream and invalidate cached month and saved read-ahead line. Ignores fclose status....
Definition ClimateFile.cpp:45
ClimateFileReader(const ClimateFileReader &)=delete
Disallow copying the uniquely owned file/cursor state. No callable copy operation is provided.
bool open(const std::string &path, double start_oa_date, int unit_system, int temp_units=-1)
Close any previous stream, open a file and detect its first-line format.
Definition ClimateFile.cpp:55
bool isOpen() const
Test ownership of a currently open stream.
Definition ClimateFile.hpp:155
void setDayOffset(double days)
Store the date shift used by subsequent lookups.
Definition ClimateFile.hpp:145
bool getRecord(double oa_date, DailyClimateRecord &rec)
Fetch the day at a shifted serial date from the current/next month buffer.
Definition ClimateFile.cpp:539
@ DEG_C10
Temperature in tenths of a degree Celsius.
Definition climate.c:119
@ WDMV
Wind speed.
Definition climate.c:108
#define MISSING
Missing value code.
Definition consts.h:142
Definition Rk2RuntimeSources.hpp:19
ClimateFileFormat
Definition ClimateFile.hpp:53
@ UNKNOWN
Definition ClimateFile.hpp:54
@ TD3200
NCDC TD3200 (NWS cooperative observer)
Definition ClimateFile.hpp:57
@ GHCND
NCDC Global Historical Climatology Network Daily.
Definition ClimateFile.hpp:56
@ DLY0204
Canadian DLY02/DLY04.
Definition ClimateFile.hpp:58
@ USER_PREPARED
StationID YYYY MM DD TMAX TMIN EVAP WIND.
Definition ClimateFile.hpp:55
TempUnits
Temperature unit encoding in GHCND.
Definition ClimateFile.hpp:68
@ DEG_C
Definition ClimateFile.hpp:68
@ DEG_F
Definition ClimateFile.hpp:68
@ DEG_C10
Definition ClimateFile.hpp:68
ClimateVar
Climate variable indices (matching legacy ClimateVarType)
Definition ClimateFile.hpp:62
@ TMAX
Definition ClimateFile.hpp:62
@ WIND
Definition ClimateFile.hpp:62
@ EVAP
Definition ClimateFile.hpp:62
@ TMIN
Definition ClimateFile.hpp:62
WindFieldType
Wind field type in GHCND.
Definition ClimateFile.hpp:65
@ AWND
Definition ClimateFile.hpp:65
@ WDMV
Definition ClimateFile.hpp:65
constexpr double MM_PER_INCH
Definition Climate.hpp:50
Definition ExchangeLaw.hpp:60
double * y
Definition odesolve.c:37
Definition ClimateFile.hpp:74
double evap
Pan evaporation (in/day US, mm/day SI; NAN if missing)
Definition ClimateFile.hpp:77
double tmin
Minimum temperature (deg F)
Definition ClimateFile.hpp:75
double wind
Wind speed (mph; NAN if missing)
Definition ClimateFile.hpp:78
double tmax
Maximum temperature (deg F)
Definition ClimateFile.hpp:76