Go to the documentation of this file. 1
15
16 #ifndef WRITENC_HPP_
17 #define WRITENC_HPP_
18
19 #ifndef IS_BUILDING_MB
20 #error "WriteNC.hpp isn't supposed to be included into an application"
21 #endif
22
23 #include <vector>
24 #include <map>
25 #include <set>
26 #include <string>
27
28 #include "moab/WriterIface.hpp"
29 #include "moab/ScdInterface.hpp"
30 #include "DebugOutput.hpp"
31
32 #ifdef MOAB_HAVE_MPI
33 #include "moab_mpi.h"
34 #include "moab/ParallelComm.hpp"
35 #endif
36
37 #ifdef MOAB_HAVE_PNETCDF
38 #include "pnetcdf.h"
39 #define NCFUNC( func ) ncmpi_##func
40
41
42 #define NCFUNCAP( func ) ncmpi_put##func##_all
43
44
45 #define NCFUNCP( func ) ncmpi_put##func
46
47
48 #define NCFUNCREQP( func ) ncmpi_iput##func
49
50 #define NCDF_SIZE MPI_Offset
51 #define NCDF_DIFF MPI_Offset
52 #else
53 #include "netcdf.h"
54 #define NCFUNC( func ) nc_##func
55 #define NCFUNCAP( func ) nc_put##func
56 #define NCFUNCP( func ) nc_put##func
57 #define NCDF_SIZE size_t
58 #define NCDF_DIFF ptrdiff_t
59 #endif
60
61 namespace moab
62 {
63
64 class WriteUtilIface;
65 class NCWriteHelper;
66
67
70 class WriteNC : public WriterIface
71 {
72 friend class NCWriteHelper;
73 friend class ScdNCWriteHelper;
74 friend class UcdNCWriteHelper;
75 friend class NCWriteEuler;
76 friend class NCWriteFV;
77 friend class NCWriteHOMME;
78 friend class NCWriteMPAS;
79 friend class NCWriteGCRM;
80
81 public:
82
83 static WriterIface* factory( Interface* );
84
85
86 WriteNC( Interface* impl = NULL );
87
88
89 virtual ~WriteNC();
90
91
92 ErrorCode write_file( const char* file_name,
93 const bool overwrite,
94 const FileOptions& opts,
95 const EntityHandle* output_list,
96 const int num_sets,
97 const std::vector< std::string >& qa_list,
98 const Tag* tag_list = NULL,
99 int num_tags = 0,
100 int export_dimension = 3 );
101
102 private:
103
104
105 enum EntityLocation
106 {
107 ENTLOCVERT = 0,
108 ENTLOCNSEDGE,
109 ENTLOCEWEDGE,
110 ENTLOCFACE,
111 ENTLOCSET,
112 ENTLOCEDGE,
113 ENTLOCREGION
114 };
115
116 class AttData
117 {
118 public:
119 AttData() : attId( -1 ), attLen( 0 ), attVarId( -2 ), attDataType( NC_NAT ) {}
120 int attId;
121 NCDF_SIZE attLen;
122 int attVarId;
123 nc_type attDataType;
124 std::string attValue;
125 };
126
127 class VarData
128 {
129 public:
130 VarData() : varId( -1 ), numAtts( -1 ), entLoc( ENTLOCSET ), numLev( 0 ), sz( 0 ), has_tsteps( false ) {}
131 int varId;
132 int numAtts;
133 nc_type varDataType;
134 std::vector< int > varDims;
135 std::map< std::string, AttData > varAtts;
136 std::string varName;
137 std::vector< Tag > varTags;
138 std::vector< void* > memoryHogs;
139 std::vector< NCDF_SIZE > writeStarts;
140 std::vector< NCDF_SIZE > writeCounts;
141 int entLoc;
142 int numLev;
143 int sz;
144 bool has_tsteps;
145 };
146
147
148
149 std::vector< std::string > dimNames;
150
151
152 std::vector< int > dimLens;
153
154
155 std::set< std::string > usedCoordinates;
156
157
158 std::set< std::string > dummyVarNames;
159
160
161 std::map< std::string, AttData > globalAtts;
162
163
164 std::map< std::string, VarData > varInfo;
165
166 ErrorCode parse_options( const FileOptions& opts,
167 std::vector< std::string >& var_names,
168 std::vector< std::string >& desired_names,
169 std::vector< int >& tstep_nums,
170 std::vector< double >& tstep_vals );
171
175 ErrorCode process_conventional_tags( EntityHandle fileSet );
176
177 ErrorCode process_concatenated_attribute( const void* attPtr,
178 int attSz,
179 std::vector< int >& attLen,
180 std::map< std::string, AttData >& attributes );
181
182
183 Interface* mbImpl;
184 WriteUtilIface* mWriteIface;
185
186
187 const char* fileName;
188
189
190 int fileId;
191
192
193 DebugOutput dbgOut;
194
195 #ifdef MOAB_HAVE_MPI
196 ParallelComm* myPcomm;
197 #endif
198
199
200 bool noMesh;
201 bool noVars;
202 bool append;
203
204
205 Tag mGlobalIdTag;
206
207
208 bool isParallel;
209
210
211 std::string grid_type;
212
213
214 NCWriteHelper* myHelper;
215 };
216
217 }
218
219 #endif