Marine systems simulation
NetCDFParser.h
1#ifndef C_NETCDF_PARSER_H
2#define C_NETCDF_PARSER_H
3
4namespace NetCDFsinmod
5{
6 struct Date {int year; int month; int day; int hour; int minute; int second;};
7 struct Grid {
8 int numX;
9 int numY;
10 int numZ;
11 int numT;
12 double sizeX;
13 double sizeY;
14 };
15}
16
17#ifdef NETCDFCPP_AVAILABLE
18#include "netcdf-cxx4/netcdf"
19
20#include <string>
21#include <vector>
22
23using std::string;
24using std::vector;
25
26namespace NetCDFsinmod
27{
28 class Exception;
29 class Parser
30 {
31 public:
32
33 Parser();
34 ~Parser(void);
35 void LoadFile(string NetCDF_Filepath);
36 Grid GetGridInfo();
37 void GetStaticData(double* layer_depth, double* depth_map, Date* timeline);
38
39 void SetCurrentTime(int offset_from_start_time);
40 void GetDynamicData(double* x_velocity, double* y_velocity, double* z_velocity);
41
42 private:
43 enum DIMENSION_NUMBER {X_NUM = 0, Y_NUM = 1, Z_NUM = 2, T_NUM = 3, T2_NUM = 4};
44 enum DIMENSION_BITMASK {X_MASK = 1<<X_NUM, Y_MASK = 1<<Y_NUM, Z_MASK = 1<<Z_NUM, T_MASK = 1<<T_NUM, T2_MASK = 1<<T2_NUM, VOID_DIMENSION_MASK = 1<<5};
45 static const DIMENSION_BITMASK SURFACE = (DIMENSION_BITMASK)(X_MASK | Y_MASK);
46 static const DIMENSION_BITMASK DEPTH = Z_MASK;
47 static const DIMENSION_BITMASK SPACE = (DIMENSION_BITMASK)(SURFACE | DEPTH);
48 static const DIMENSION_BITMASK SPACE_TIME = (DIMENSION_BITMASK)(SPACE | T_MASK);
49 static const DIMENSION_BITMASK SURFACE_TIME = (DIMENSION_BITMASK)(SURFACE | T_MASK);
50 static const DIMENSION_BITMASK EXPANDED_TIME = (DIMENSION_BITMASK)(T_MASK | T2_MASK);
51 static const DIMENSION_BITMASK ALL_SPACE_AND_TIME = (DIMENSION_BITMASK)(SPACE | EXPANDED_TIME);
52
53 struct variable_info {string name; netCDF::NcVar ncvar; DIMENSION_BITMASK required_dimensions;};
54 struct system_variables {variable_info vx; variable_info vy; variable_info vz; variable_info depth; variable_info layer_depth; variable_info time;};
55
56 string m_x_dim_name;
57 string m_y_dim_name;
58 string m_z_dim_name;
59 string m_t_dim_name;
60 string m_t2_dim_name;
61
62 void set_to_NULL();
63
64 //bool nctype_has_dim(netCDF::NcVar* nc_dimension_type, string dimension_name); /// test if a nc_type is defined in a specified dimension
65 //bool nctype_has_dim(netCDF::NcFile* nc_dimension_type, string dimension_name); /// test if a nc_type is defined in a specified dimension
66
67 void read_dynamic_variable_data(double* value_array, variable_info variable);
68
69 void read_variable_info_from_file(variable_info& variable);
70 void report_exception(string error_message);
71 //void check_requirement(bool requires_dimension, bool needs_dimension, string variable_name, string dimension_name);
72
73
74 netCDF::NcFile* m_ncfile;
75 Grid m_grid;
76 int m_current_time_offset;
77
78 system_variables m_variables;
79
80 double m_fill_value;
81 string m_fill_value_attribute_name;
82 string m_offset_value_attribute_name;
83 string m_scaling_value_attribute_name;
84 string m_resolution_attribute_name;
85
86 Exception* m_exception_collector;
87 };
88
89 class Exception
90 {
91 public:
92 Exception(string errorMessage){
93 m_error_message = "Error in NetCDF parser: "+errorMessage;
94 }
95 void AppendErrorMessage(string errormessage){
96 m_error_message.append("\nError in NetCDF parser: "+errormessage);
97 }
98 string GetErrorMessage(){
99 return m_error_message;
100 }
101 private:
102 string m_error_message;
103 };
104}
105
106#endif
107
108#endif// NETCDFCPP_AVAILABLE
Definition: NetCDFParser.h:6
Definition: NetCDFParser.h:7
double sizeX
number of time steps
Definition: NetCDFParser.h:12
double sizeY
size of grid cells in X-direction
Definition: NetCDFParser.h:13
int numT
number of grid cells in Z-direction
Definition: NetCDFParser.h:11
int numY
number of grid cells in X-direction
Definition: NetCDFParser.h:9
int numZ
number of grid cells in Y-direction
Definition: NetCDFParser.h:10