Go to the documentation of this file. 1
2
3
4
5
6
7
8
9 #ifndef READNC_HPP
10 #define READNC_HPP
11
12 #ifndef IS_BUILDING_MB
13 #error "ReadNC.hpp isn't supposed to be included into an application"
14 #endif
15
16 #include <vector>
17 #include <map>
18 #include <set>
19 #include <string>
20
21 #include "moab/ReaderIface.hpp"
22 #include "moab/ScdInterface.hpp"
23 #include "DebugOutput.hpp"
24
25 #ifdef MOAB_HAVE_MPI
26 #include "moab_mpi.h"
27 #include "moab/ParallelComm.hpp"
28 #endif
29
30 #ifdef MOAB_HAVE_PNETCDF
31 #include "pnetcdf.h"
32 #define NCFUNC( func ) ncmpi_##func
33
34
35 #define NCFUNCAG( func ) ncmpi_get##func##_all
36
37
38 #define NCFUNCG( func ) ncmpi_get##func
39
40
41 #define NCFUNCREQG( func ) ncmpi_iget##func
42
43 #define NCDF_SIZE MPI_Offset
44 #define NCDF_DIFF MPI_Offset
45 #else
46 #include "netcdf.h"
47 #define NCFUNC( func ) nc_##func
48 #define NCFUNCAG( func ) nc_get##func
49 #define NCFUNCG( func ) nc_get##func
50 #define NCDF_SIZE size_t
51 #define NCDF_DIFF ptrdiff_t
52 #endif
53
54 namespace moab
55 {
56
57 class ReadUtilIface;
58 class ScdInterface;
59 class NCHelper;
60
61
62 class ReadNC : public ReaderIface
63 {
64 friend class NCHelper;
65 friend class ScdNCHelper;
66 friend class UcdNCHelper;
67 friend class NCHelperEuler;
68 friend class NCHelperFV;
69 friend class NCHelperDomain;
70 friend class NCHelperScrip;
71 friend class NCHelperHOMME;
72 friend class NCHelperMPAS;
73 friend class NCHelperESMF;
74 friend class NCHelperGCRM;
75
76 public:
77 static ReaderIface* factory( Interface* );
78
79 enum NCFormatType
80 {
81 NC_FORMAT_UNKNOWN_TYPE = 0,
82 NC_FORMAT_MPAS = 1,
83 NC_FORMAT_SCRIP = 2,
84 NC_FORMAT_ESMF = 3,
85 NC_FORMAT_DOMAIN = 4,
86 NC_FORMAT_HOMME = 5,
87 NC_FORMAT_GCRM = 6,
88 NC_FORMAT_EULER = 7,
89 NC_FORMAT_FV = 8
90 };
91
92
93 ErrorCode load_file( const char* file_name,
94 const EntityHandle* file_set,
95 const FileOptions& opts,
96 const SubsetList* subset_list = nullptr,
97 const Tag* file_id_tag = nullptr );
98
99
100 explicit ReadNC( Interface* impl = nullptr );
101
102
103 virtual ~ReadNC();
104
105 virtual ErrorCode read_tag_values( const char* file_name,
106 const char* tag_name,
107 const FileOptions& opts,
108 std::vector< int >& tag_values_out,
109 const SubsetList* subset_list = nullptr );
110
111
112
113 enum EntityLocation
114 {
115 ENTLOCVERT = 0,
116 ENTLOCNSEDGE,
117 ENTLOCEWEDGE,
118 ENTLOCFACE,
119 ENTLOCSET,
120 ENTLOCEDGE,
121 ENTLOCREGION
122 };
123
124 private:
125 class AttData
126 {
127 public:
128 AttData() : attId( -1 ), attLen( 0 ), attVarId( -2 ) {}
129 int attId;
130 NCDF_SIZE attLen;
131 int attVarId;
132 nc_type attDataType;
133 std::string attName;
134 };
135
136 class VarData
137 {
138 public:
139 VarData() : varId( -1 ), numAtts( -1 ), entLoc( ENTLOCSET ), numLev( 0 ), sz( 0 ), has_tsteps( false ) {}
140 int varId;
141 int numAtts;
142 nc_type varDataType;
143 std::vector< int > varDims;
144 std::map< std::string, AttData > varAtts;
145 std::string varName;
146 std::vector< Tag > varTags;
147 std::vector< void* > varDatas;
148 std::vector< NCDF_SIZE > readStarts;
149 std::vector< NCDF_SIZE > readCounts;
150 int entLoc;
151 int numLev;
152 int sz;
153 bool has_tsteps;
154 };
155
156 ReadUtilIface* readMeshIface;
157
158
159 ErrorCode read_header();
160
161
162 ErrorCode get_attributes( int var_id,
163 int num_atts,
164 std::map< std::string, AttData >& atts,
165 const char* prefix = "" );
166
167
168 ErrorCode get_dimensions( int file_id, std::vector< std::string >& dim_names, std::vector< int >& dim_lens );
169
170
171 ErrorCode get_variables();
172
173 ErrorCode parse_options( const FileOptions& opts,
174 std::vector< std::string >& var_names,
175 std::vector< int >& tstep_nums,
176 std::vector< double >& tstep_vals );
177
178
179
180
181 Interface* mbImpl;
182
183
184 std::string fileName;
185
186
187 int fileId;
188
189
190 std::vector< std::string > dimNames;
191
192
193 std::vector< int > dimLens;
194
195
196 std::map< std::string, AttData > globalAtts;
197
198
199 std::map< std::string, VarData > varInfo;
200
201
202
203 Tag mGlobalIdTag;
204
205
206
207
208
209 const Tag* mpFileIdTag;
210
211
212 DebugOutput dbgOut;
213
214
215 bool isParallel;
216
217
218 int partMethod;
219
220
221 ScdInterface* scdi;
222
223
224 ScdParData parData;
225
226 #ifdef MOAB_HAVE_MPI
227 ParallelComm* myPcomm;
228 #endif
229
230
231 bool noMesh;
232 bool noVars;
233 bool spectralMesh;
234 bool noMixedElements;
235 bool noEdges;
236 bool culling;
237 bool repartition;
238 int gatherSetRank;
239 int tStepBase;
240 int trivialPartitionShift;
241
242
243 NCHelper* myHelper;
244 };
245
246 }
247
248 #endif