FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
NetCDFParser.h
1#pragma once
2
8namespace netcdf_sinmod
9{
11struct Date
12{
13 int year;
14 int month;
15 int day;
16 int hour;
17 int minute;
18 int second;
19};
20
22struct Grid
23{
24 int numX;
25 int numY;
26 int numZ;
27 int numT;
28 double sizeX;
29 double sizeY;
30};
31} // namespace netcdf_sinmod
32
33#include "netcdf-cxx4/netcdf"
34
35#include <string>
36#include <vector>
37
38using std::string;
39using std::vector;
40
41namespace netcdf_sinmod
42{
45{
46public:
51 Exception(string errorMessage)
52 {
53 m_error_message = "Error in NetCDF parser: " + errorMessage;
54 }
59 void AppendErrorMessage(string errormessage)
60 {
61 m_error_message.append("\nError in NetCDF parser: " + errormessage);
62 }
67 {
68 return m_error_message;
69 }
70
71private:
72 string m_error_message;
73};
74
80class Parser
81{
82public:
85
87 ~Parser(void);
88
89 Parser(const Parser&) = delete;
90 Parser& operator=(const Parser&) = delete;
91
96 void LoadFile(string NetCDF_Filepath);
97
102
109 void GetStaticData(double* layer_depth, double* depth_map, Date* timeline);
110
115 void SetCurrentTime(int offset_from_start_time);
116
123 void GetDynamicData(double* x_velocity, double* y_velocity, double* z_velocity);
124
125private:
127 enum DIMENSION_NUMBER
128 {
129 X_NUM = 0,
130 Y_NUM = 1,
131 Z_NUM = 2,
132 T_NUM = 3,
133 T2_NUM = 4
134 };
136 enum DIMENSION_BITMASK
137 {
138 X_MASK = 1 << X_NUM,
139 Y_MASK = 1 << Y_NUM,
140 Z_MASK = 1 << Z_NUM,
141 T_MASK = 1 << T_NUM,
142 T2_MASK = 1 << T2_NUM,
143 VOID_DIMENSION_MASK = 1 << 5
144 };
145 static const DIMENSION_BITMASK SURFACE = (DIMENSION_BITMASK)(X_MASK | Y_MASK);
146 static const DIMENSION_BITMASK DEPTH = Z_MASK;
147 static const DIMENSION_BITMASK SPACE = (DIMENSION_BITMASK)(SURFACE | DEPTH);
148 static const DIMENSION_BITMASK SPACE_TIME = (DIMENSION_BITMASK)(SPACE | T_MASK);
149 static const DIMENSION_BITMASK SURFACE_TIME = (DIMENSION_BITMASK)(SURFACE | T_MASK);
150 static const DIMENSION_BITMASK EXPANDED_TIME = (DIMENSION_BITMASK)(T_MASK | T2_MASK);
151 static const DIMENSION_BITMASK ALL_SPACE_AND_TIME = (DIMENSION_BITMASK)(SPACE | EXPANDED_TIME);
152
154 struct variable_info
155 {
156 string name;
157 netCDF::NcVar ncvar;
158 DIMENSION_BITMASK required_dimensions;
159 };
161 struct system_variables
162 {
163 variable_info vx;
164 variable_info vy;
165 variable_info vz;
166 variable_info depth;
167 variable_info layer_depth;
168 variable_info time;
169 };
170
171 string m_x_dim_name;
172 string m_y_dim_name;
173 string m_z_dim_name;
174 string m_t_dim_name;
175 string m_t2_dim_name;
176
178 void set_to_NULL();
179
185 void read_dynamic_variable_data(double* value_array, variable_info variable);
186
193 void read_variable_info_from_file(variable_info& variable);
194
200 int dimension_size(const string& dimension_name);
201
203 void read_resolution();
204
209 void report_exception(string error_message);
210
211 netCDF::NcFile* m_ncfile;
212 Grid m_grid;
213 int m_current_time_offset;
214
215 system_variables m_variables;
216
217 double m_fill_value;
218 string m_fill_value_attribute_name;
219 string m_offset_value_attribute_name;
220 string m_scaling_value_attribute_name;
221 string m_resolution_attribute_name;
222
223 Exception* m_exception_collector;
224};
225} // namespace netcdf_sinmod
226
NetCDF exception for error reporting.
Definition NetCDFParser.h:45
void AppendErrorMessage(string errormessage)
Definition NetCDFParser.h:59
Exception(string errorMessage)
Definition NetCDFParser.h:51
string GetErrorMessage()
Definition NetCDFParser.h:66
Definition NetCDFParser.h:81
void GetStaticData(double *layer_depth, double *depth_map, Date *timeline)
Parser(const Parser &)=delete
Owns the file handle: not copyable.
~Parser(void)
Destructor - closes file.
void LoadFile(string NetCDF_Filepath)
Parser & operator=(const Parser &)=delete
Owns the file handle: not copyable.
void GetDynamicData(double *x_velocity, double *y_velocity, double *z_velocity)
void SetCurrentTime(int offset_from_start_time)
Parser()
Construct parser with null values.
Definition NetCDFParser.h:9
@ Grid
An edge of a gridded wake's box.
Date structure for time coordinates.
Definition NetCDFParser.h:12
int hour
Hour.
Definition NetCDFParser.h:16
int minute
Minute.
Definition NetCDFParser.h:17
int day
Day.
Definition NetCDFParser.h:15
int year
Year.
Definition NetCDFParser.h:13
int second
Second.
Definition NetCDFParser.h:18
int month
Month.
Definition NetCDFParser.h:14
Grid dimensions structure.
Definition NetCDFParser.h:23
double sizeY
Size of grid cells in Y-direction [m].
Definition NetCDFParser.h:29
int numX
Number of grid cells in X-direction (xc, NED north)
Definition NetCDFParser.h:24
int numT
Number of time steps.
Definition NetCDFParser.h:27
int numY
Number of grid cells in Y-direction (yc, NED east)
Definition NetCDFParser.h:25
int numZ
Number of grid cells in Z-direction.
Definition NetCDFParser.h:26
double sizeX
Size of grid cells in X-direction [m].
Definition NetCDFParser.h:28