1 | #include "nc4_data_output.hpp" |
---|
2 | |
---|
3 | #include <boost/lexical_cast.hpp> |
---|
4 | #include "attribute_template.hpp" |
---|
5 | #include "group_template.hpp" |
---|
6 | |
---|
7 | #include "file.hpp" |
---|
8 | #include "calendar.hpp" |
---|
9 | #include "context.hpp" |
---|
10 | #include "context_server.hpp" |
---|
11 | #include "netCdfException.hpp" |
---|
12 | #include "exception.hpp" |
---|
13 | |
---|
14 | namespace xios |
---|
15 | { |
---|
16 | /// ////////////////////// Dfinitions ////////////////////// /// |
---|
17 | CNc4DataOutput::CNc4DataOutput |
---|
18 | (const StdString & filename, bool exist) |
---|
19 | : SuperClass() |
---|
20 | , SuperClassWriter(filename, exist) |
---|
21 | , filename(filename) |
---|
22 | { |
---|
23 | SuperClass::type = MULTI_FILE; |
---|
24 | } |
---|
25 | |
---|
26 | CNc4DataOutput::CNc4DataOutput |
---|
27 | (const StdString & filename, bool exist, bool useClassicFormat, bool useCFConvention, |
---|
28 | MPI_Comm comm_file,bool multifile, bool isCollective, const StdString& timeCounterName) |
---|
29 | : SuperClass() |
---|
30 | , SuperClassWriter(filename, exist, useClassicFormat, useCFConvention, &comm_file, multifile, timeCounterName) |
---|
31 | , comm_file(comm_file) |
---|
32 | , filename(filename) |
---|
33 | , isCollective(isCollective) |
---|
34 | { |
---|
35 | SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE; |
---|
36 | } |
---|
37 | |
---|
38 | CNc4DataOutput::~CNc4DataOutput(void) |
---|
39 | { /* Ne rien faire de plus */ } |
---|
40 | |
---|
41 | ///-------------------------------------------------------------- |
---|
42 | |
---|
43 | const StdString & CNc4DataOutput::getFileName(void) const |
---|
44 | { |
---|
45 | return (this->filename); |
---|
46 | } |
---|
47 | |
---|
48 | //--------------------------------------------------------------- |
---|
49 | |
---|
50 | void CNc4DataOutput::writeDomain_(CDomain* domain) |
---|
51 | { |
---|
52 | if (domain->type == CDomain::type_attr::unstructured) |
---|
53 | { |
---|
54 | if (SuperClassWriter::useCFConvention) |
---|
55 | writeUnstructuredDomain(domain) ; |
---|
56 | else |
---|
57 | writeUnstructuredDomainUgrid(domain) ; |
---|
58 | return ; |
---|
59 | } |
---|
60 | |
---|
61 | CContext* context = CContext::getCurrent() ; |
---|
62 | CContextServer* server=context->server ; |
---|
63 | |
---|
64 | if (domain->IsWritten(this->filename)) return; |
---|
65 | domain->checkAttributes(); |
---|
66 | |
---|
67 | if (domain->isEmpty()) |
---|
68 | if (SuperClass::type==MULTI_FILE) return; |
---|
69 | |
---|
70 | std::vector<StdString> dim0, dim1; |
---|
71 | StdString domid = domain->getDomainOutputName(); |
---|
72 | StdString appendDomid = (singleDomain) ? "" : "_"+domid ; |
---|
73 | if (isWrittenDomain(domid)) return ; |
---|
74 | else setWrittenDomain(domid); |
---|
75 | |
---|
76 | |
---|
77 | StdString dimXid, dimYid ; |
---|
78 | |
---|
79 | bool isRegularDomain = (domain->type == CDomain::type_attr::rectilinear); |
---|
80 | switch (domain->type) |
---|
81 | { |
---|
82 | case CDomain::type_attr::curvilinear : |
---|
83 | dimXid = StdString("x").append(appendDomid); |
---|
84 | dimYid = StdString("y").append(appendDomid); |
---|
85 | break ; |
---|
86 | case CDomain::type_attr::rectilinear : |
---|
87 | dimXid = StdString("lon").append(appendDomid); |
---|
88 | dimYid = StdString("lat").append(appendDomid); |
---|
89 | break; |
---|
90 | } |
---|
91 | |
---|
92 | StdString dimVertId = StdString("nvertex").append(appendDomid); |
---|
93 | |
---|
94 | string lonid,latid,bounds_lonid,bounds_latid ; |
---|
95 | string areaId = "area" + appendDomid; |
---|
96 | /* |
---|
97 | StdString lonid_loc = (server->intraCommSize > 1) |
---|
98 | ? StdString("lon").append(appendDomid).append("_local") |
---|
99 | : lonid; |
---|
100 | StdString latid_loc = (server->intraCommSize > 1) |
---|
101 | ? StdString("lat").append(appendDomid).append("_local") |
---|
102 | : latid; |
---|
103 | */ |
---|
104 | |
---|
105 | try |
---|
106 | { |
---|
107 | switch (SuperClass::type) |
---|
108 | { |
---|
109 | case (MULTI_FILE) : |
---|
110 | { |
---|
111 | // if (domain->isEmpty()) return; |
---|
112 | |
---|
113 | if (server->intraCommSize > 1) |
---|
114 | { |
---|
115 | // SuperClassWriter::addDimension(lonid, domain->zoom_ni.getValue()); |
---|
116 | // SuperClassWriter::addDimension(latid, domain->zoom_nj.getValue()); |
---|
117 | } |
---|
118 | |
---|
119 | switch (domain->type) |
---|
120 | { |
---|
121 | case CDomain::type_attr::curvilinear : |
---|
122 | dim0.push_back(dimYid); dim0.push_back(dimXid); |
---|
123 | lonid = StdString("nav_lon").append(appendDomid); |
---|
124 | latid = StdString("nav_lat").append(appendDomid); |
---|
125 | break ; |
---|
126 | case CDomain::type_attr::rectilinear : |
---|
127 | lonid = StdString("lon").append(appendDomid); |
---|
128 | latid = StdString("lat").append(appendDomid); |
---|
129 | dim0.push_back(dimYid); |
---|
130 | dim1.push_back(dimXid); |
---|
131 | break; |
---|
132 | } |
---|
133 | |
---|
134 | bounds_lonid = StdString("bounds_lon").append(appendDomid); |
---|
135 | bounds_latid = StdString("bounds_lat").append(appendDomid); |
---|
136 | |
---|
137 | SuperClassWriter::addDimension(dimXid, domain->zoom_ni_srv); |
---|
138 | SuperClassWriter::addDimension(dimYid, domain->zoom_nj_srv); |
---|
139 | |
---|
140 | if (domain->hasBounds) |
---|
141 | SuperClassWriter::addDimension(dimVertId, domain->nvertex); |
---|
142 | |
---|
143 | if (server->intraCommSize > 1) |
---|
144 | { |
---|
145 | this->writeLocalAttributes(domain->zoom_ibegin_srv, |
---|
146 | domain->zoom_ni_srv, |
---|
147 | domain->zoom_jbegin_srv, |
---|
148 | domain->zoom_nj_srv, |
---|
149 | appendDomid); |
---|
150 | |
---|
151 | if (singleDomain) |
---|
152 | this->writeLocalAttributes_IOIPSL(dimXid, dimYid, |
---|
153 | domain->zoom_ibegin_srv, |
---|
154 | domain->zoom_ni_srv, |
---|
155 | domain->zoom_jbegin_srv, |
---|
156 | domain->zoom_nj_srv, |
---|
157 | domain->ni_glo,domain->nj_glo, |
---|
158 | server->intraCommRank,server->intraCommSize); |
---|
159 | } |
---|
160 | |
---|
161 | if (domain->hasLonLat) |
---|
162 | { |
---|
163 | switch (domain->type) |
---|
164 | { |
---|
165 | case CDomain::type_attr::curvilinear : |
---|
166 | SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); |
---|
167 | SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); |
---|
168 | break ; |
---|
169 | case CDomain::type_attr::rectilinear : |
---|
170 | SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); |
---|
171 | SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1); |
---|
172 | break ; |
---|
173 | } |
---|
174 | |
---|
175 | this->writeAxisAttributes(lonid, isRegularDomain ? "X" : "", "longitude", "Longitude", "degrees_east", domid); |
---|
176 | this->writeAxisAttributes(latid, isRegularDomain ? "Y" : "", "latitude", "Latitude", "degrees_north", domid); |
---|
177 | |
---|
178 | if (domain->hasBounds) |
---|
179 | { |
---|
180 | SuperClassWriter::addAttribute("bounds", bounds_lonid, &lonid); |
---|
181 | SuperClassWriter::addAttribute("bounds", bounds_latid, &latid); |
---|
182 | |
---|
183 | dim0.clear(); |
---|
184 | dim0.push_back(dimYid); |
---|
185 | dim0.push_back(dimXid); |
---|
186 | dim0.push_back(dimVertId); |
---|
187 | SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); |
---|
188 | SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | dim0.clear(); |
---|
193 | dim0.push_back(dimYid); |
---|
194 | dim0.push_back(dimXid); |
---|
195 | |
---|
196 | |
---|
197 | // supress mask if (server->intraCommSize > 1) |
---|
198 | // supress mask { |
---|
199 | // supress mask SuperClassWriter::addVariable(maskid, NC_INT, dim0); |
---|
200 | // supress mask |
---|
201 | // supress mask this->writeMaskAttributes(maskid, |
---|
202 | // supress mask domain->data_dim.getValue()/*, |
---|
203 | // supress mask domain->data_ni.getValue(), |
---|
204 | // supress mask domain->data_nj.getValue(), |
---|
205 | // supress mask domain->data_ibegin.getValue(), |
---|
206 | // supress mask domain->data_jbegin.getValue()*/); |
---|
207 | // supress mask } |
---|
208 | |
---|
209 | //SuperClassWriter::setDefaultValue(maskid, &dvm); |
---|
210 | |
---|
211 | if (domain->hasArea) |
---|
212 | { |
---|
213 | SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0); |
---|
214 | SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); |
---|
215 | SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); |
---|
216 | } |
---|
217 | |
---|
218 | SuperClassWriter::definition_end(); |
---|
219 | |
---|
220 | if (domain->hasLonLat) |
---|
221 | { |
---|
222 | switch (domain->type) |
---|
223 | { |
---|
224 | case CDomain::type_attr::curvilinear : |
---|
225 | SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0); |
---|
226 | SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0); |
---|
227 | break; |
---|
228 | case CDomain::type_attr::rectilinear : |
---|
229 | CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ; |
---|
230 | SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0); |
---|
231 | CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ; |
---|
232 | SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0); |
---|
233 | break; |
---|
234 | } |
---|
235 | |
---|
236 | if (domain->hasBounds) |
---|
237 | { |
---|
238 | SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0); |
---|
239 | SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0); |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | if (domain->hasArea) |
---|
244 | SuperClassWriter::writeData(domain->area_srv, areaId, isCollective, 0); |
---|
245 | |
---|
246 | SuperClassWriter::definition_start(); |
---|
247 | |
---|
248 | break; |
---|
249 | } |
---|
250 | case (ONE_FILE) : |
---|
251 | { |
---|
252 | SuperClassWriter::addDimension(dimXid, domain->global_zoom_ni); |
---|
253 | SuperClassWriter::addDimension(dimYid, domain->global_zoom_nj); |
---|
254 | |
---|
255 | if (domain->hasBounds) |
---|
256 | SuperClassWriter::addDimension(dimVertId, domain->nvertex); |
---|
257 | |
---|
258 | if (domain->hasLonLat) |
---|
259 | { |
---|
260 | switch (domain->type) |
---|
261 | { |
---|
262 | case CDomain::type_attr::curvilinear : |
---|
263 | dim0.push_back(dimYid); dim0.push_back(dimXid); |
---|
264 | lonid = StdString("nav_lon").append(appendDomid); |
---|
265 | latid = StdString("nav_lat").append(appendDomid); |
---|
266 | SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); |
---|
267 | SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); |
---|
268 | break; |
---|
269 | |
---|
270 | case CDomain::type_attr::rectilinear : |
---|
271 | dim0.push_back(dimYid); |
---|
272 | dim1.push_back(dimXid); |
---|
273 | lonid = StdString("lon").append(appendDomid); |
---|
274 | latid = StdString("lat").append(appendDomid); |
---|
275 | SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); |
---|
276 | SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1); |
---|
277 | break; |
---|
278 | } |
---|
279 | |
---|
280 | bounds_lonid = StdString("bounds_lon").append(appendDomid); |
---|
281 | bounds_latid = StdString("bounds_lat").append(appendDomid); |
---|
282 | |
---|
283 | this->writeAxisAttributes |
---|
284 | (lonid, isRegularDomain ? "X" : "", "longitude", "Longitude", "degrees_east", domid); |
---|
285 | this->writeAxisAttributes |
---|
286 | (latid, isRegularDomain ? "Y" : "", "latitude", "Latitude", "degrees_north", domid); |
---|
287 | |
---|
288 | if (domain->hasBounds) |
---|
289 | { |
---|
290 | SuperClassWriter::addAttribute("bounds", bounds_lonid, &lonid); |
---|
291 | SuperClassWriter::addAttribute("bounds", bounds_latid, &latid); |
---|
292 | |
---|
293 | dim0.clear(); |
---|
294 | dim0.push_back(dimYid); |
---|
295 | dim0.push_back(dimXid); |
---|
296 | dim0.push_back(dimVertId); |
---|
297 | SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); |
---|
298 | SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); |
---|
299 | } |
---|
300 | } |
---|
301 | |
---|
302 | if (domain->hasArea) |
---|
303 | { |
---|
304 | dim0.clear(); |
---|
305 | dim0.push_back(dimYid); dim0.push_back(dimXid); |
---|
306 | SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0); |
---|
307 | SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); |
---|
308 | SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); |
---|
309 | dim0.clear(); |
---|
310 | } |
---|
311 | |
---|
312 | SuperClassWriter::definition_end(); |
---|
313 | |
---|
314 | switch (domain->type) |
---|
315 | { |
---|
316 | case CDomain::type_attr::curvilinear : |
---|
317 | { |
---|
318 | std::vector<StdSize> start(2) ; |
---|
319 | std::vector<StdSize> count(2) ; |
---|
320 | if (domain->isEmpty()) |
---|
321 | { |
---|
322 | start[0]=0 ; start[1]=0 ; |
---|
323 | count[0]=0 ; count[1]=0 ; |
---|
324 | } |
---|
325 | else |
---|
326 | { |
---|
327 | start[1]=domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
328 | start[0]=domain->zoom_jbegin_srv-domain->global_zoom_jbegin; |
---|
329 | count[1]=domain->zoom_ni_srv ; count[0]=domain->zoom_nj_srv ; |
---|
330 | } |
---|
331 | |
---|
332 | if (domain->hasLonLat) |
---|
333 | { |
---|
334 | SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count); |
---|
335 | SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count); |
---|
336 | } |
---|
337 | break; |
---|
338 | } |
---|
339 | case CDomain::type_attr::rectilinear : |
---|
340 | { |
---|
341 | if (domain->hasLonLat) |
---|
342 | { |
---|
343 | std::vector<StdSize> start(1) ; |
---|
344 | std::vector<StdSize> count(1) ; |
---|
345 | if (domain->isEmpty()) |
---|
346 | { |
---|
347 | start[0]=0 ; |
---|
348 | count[0]=0 ; |
---|
349 | SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count); |
---|
350 | SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count); |
---|
351 | |
---|
352 | } |
---|
353 | else |
---|
354 | { |
---|
355 | start[0]=domain->zoom_jbegin_srv-domain->global_zoom_jbegin; |
---|
356 | count[0]=domain->zoom_nj_srv ; |
---|
357 | CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ; |
---|
358 | SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0,&start,&count); |
---|
359 | |
---|
360 | start[0]=domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
361 | count[0]=domain->zoom_ni_srv ; |
---|
362 | CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ; |
---|
363 | SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0,&start,&count); |
---|
364 | } |
---|
365 | } |
---|
366 | break; |
---|
367 | } |
---|
368 | } |
---|
369 | |
---|
370 | if (domain->hasBounds) |
---|
371 | { |
---|
372 | std::vector<StdSize> start(3); |
---|
373 | std::vector<StdSize> count(3); |
---|
374 | if (domain->isEmpty()) |
---|
375 | { |
---|
376 | start[2] = start[1] = start[0] = 0; |
---|
377 | count[2] = count[1] = count[0] = 0; |
---|
378 | } |
---|
379 | else |
---|
380 | { |
---|
381 | start[2] = 0; |
---|
382 | start[1] = domain->zoom_ibegin_srv - domain->global_zoom_ibegin; |
---|
383 | start[0] = domain->zoom_jbegin_srv - domain->global_zoom_jbegin; |
---|
384 | count[2] = domain->nvertex; |
---|
385 | count[1] = domain->zoom_ni_srv; |
---|
386 | count[0] = domain->zoom_nj_srv; |
---|
387 | } |
---|
388 | |
---|
389 | SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0, &start, &count); |
---|
390 | SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0, &start, &count); |
---|
391 | } |
---|
392 | |
---|
393 | if (domain->hasArea) |
---|
394 | { |
---|
395 | std::vector<StdSize> start(2); |
---|
396 | std::vector<StdSize> count(2); |
---|
397 | |
---|
398 | if (domain->isEmpty()) |
---|
399 | { |
---|
400 | start[0] = 0; start[1] = 0; |
---|
401 | count[0] = 0; count[1] = 0; |
---|
402 | } |
---|
403 | else |
---|
404 | { |
---|
405 | start[1] = domain->zoom_ibegin_srv - domain->global_zoom_ibegin; |
---|
406 | start[0] = domain->zoom_jbegin_srv - domain->global_zoom_jbegin; |
---|
407 | count[1] = domain->zoom_ni_srv; |
---|
408 | count[0] = domain->zoom_nj_srv; |
---|
409 | } |
---|
410 | |
---|
411 | SuperClassWriter::writeData(domain->area_srv, areaId, isCollective, 0, &start, &count); |
---|
412 | } |
---|
413 | |
---|
414 | SuperClassWriter::definition_start(); |
---|
415 | break; |
---|
416 | } |
---|
417 | default : |
---|
418 | ERROR("CNc4DataOutput::writeDomain(domain)", |
---|
419 | << "[ type = " << SuperClass::type << "]" |
---|
420 | << " not implemented yet !"); |
---|
421 | } |
---|
422 | } |
---|
423 | catch (CNetCdfException& e) |
---|
424 | { |
---|
425 | StdString msg("On writing the domain : "); |
---|
426 | msg.append(domid); msg.append("\n"); |
---|
427 | msg.append("In the context : "); |
---|
428 | msg.append(context->getId()); msg.append("\n"); |
---|
429 | msg.append(e.what()); |
---|
430 | ERROR("CNc4DataOutput::writeDomain_(CDomain* domain)", << msg); |
---|
431 | } |
---|
432 | |
---|
433 | domain->addRelFile(this->filename); |
---|
434 | } |
---|
435 | |
---|
436 | //-------------------------------------------------------------- |
---|
437 | |
---|
438 | void CNc4DataOutput::writeUnstructuredDomainUgrid(CDomain* domain) |
---|
439 | { |
---|
440 | CContext* context = CContext::getCurrent() ; |
---|
441 | CContextServer* server=context->server ; |
---|
442 | |
---|
443 | if (domain->IsWritten(this->filename)) return; |
---|
444 | domain->checkAttributes(); |
---|
445 | if (domain->isEmpty()) |
---|
446 | if (SuperClass::type==MULTI_FILE) return ; |
---|
447 | |
---|
448 | std::vector<StdString> dim0; |
---|
449 | StdString domid = domain->getDomainOutputName(); |
---|
450 | StdString domainName = domain->name; |
---|
451 | domain->assignMesh(domainName); |
---|
452 | //domain->mesh->createMesh(domain->lonvalue_srv, domain->latvalue_srv, domain->bounds_lon_srv, domain->bounds_lat_srv); |
---|
453 | domain->mesh->createMeshEpsilon(domain->lonvalue_srv, domain->latvalue_srv, domain->bounds_lon_srv, domain->bounds_lat_srv); |
---|
454 | |
---|
455 | StdString node_x = domainName + "_node_x"; |
---|
456 | StdString node_y = domainName + "_node_y"; |
---|
457 | |
---|
458 | StdString edge_x = domainName + "_edge_x"; |
---|
459 | StdString edge_y = domainName + "_edge_y"; |
---|
460 | StdString edge_nodes = domainName + "_edge_nodes"; |
---|
461 | |
---|
462 | StdString face_x = domainName + "_face_x"; |
---|
463 | StdString face_y = domainName + "_face_y"; |
---|
464 | StdString face_nodes = domainName + "_face_nodes"; |
---|
465 | |
---|
466 | StdString dimNode = "n" + domainName + "_node"; |
---|
467 | StdString dimEdge = "n" + domainName + "_edge"; |
---|
468 | StdString dimFace = "n" + domainName + "_face"; |
---|
469 | StdString dimVertex = "n" + domainName + "_vertex"; |
---|
470 | StdString dimTwo = "Two"; |
---|
471 | |
---|
472 | if (!SuperClassWriter::dimExist(dimTwo)) SuperClassWriter::addDimension(dimTwo, 2); |
---|
473 | if (!isWrittenDomain(domid)) |
---|
474 | { |
---|
475 | dim0.clear(); |
---|
476 | SuperClassWriter::addVariable(domainName, NC_INT, dim0); |
---|
477 | SuperClassWriter::addAttribute("cf_role", StdString("mesh_topology"), &domainName); |
---|
478 | SuperClassWriter::addAttribute("node_coordinates", node_x + " " + node_y, &domainName); |
---|
479 | } |
---|
480 | |
---|
481 | try |
---|
482 | { |
---|
483 | switch (SuperClass::type) |
---|
484 | { |
---|
485 | case (ONE_FILE) : |
---|
486 | { |
---|
487 | // Adding nodes |
---|
488 | if (domain->nvertex == 1) |
---|
489 | { |
---|
490 | if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y)) |
---|
491 | { |
---|
492 | SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodes); |
---|
493 | dim0.clear(); |
---|
494 | dim0.push_back(dimNode); |
---|
495 | SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0); |
---|
496 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); |
---|
497 | SuperClassWriter::addAttribute("longname_name", StdString("Longitude of mesh nodes."), &node_x); |
---|
498 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); |
---|
499 | SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0); |
---|
500 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); |
---|
501 | SuperClassWriter::addAttribute("longname_name", StdString("Latitude of mesh nodes."), &node_y); |
---|
502 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y); |
---|
503 | } |
---|
504 | } // domain->nvertex == 1 |
---|
505 | |
---|
506 | // Adding edges and nodes, if nodes have not been defined previously |
---|
507 | if (domain->nvertex == 2) |
---|
508 | { |
---|
509 | // Nodes |
---|
510 | if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y)) |
---|
511 | { |
---|
512 | SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodes); |
---|
513 | dim0.clear(); |
---|
514 | dim0.push_back(dimNode); |
---|
515 | SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0); |
---|
516 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); |
---|
517 | SuperClassWriter::addAttribute("longname_name", StdString("Longitude of mesh nodes."), &node_x); |
---|
518 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); |
---|
519 | SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0); |
---|
520 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); |
---|
521 | SuperClassWriter::addAttribute("longname_name", StdString("Latitude of mesh nodes."), &node_y); |
---|
522 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y); |
---|
523 | } |
---|
524 | // Edges |
---|
525 | if (!SuperClassWriter::varExist(edge_x) || !SuperClassWriter::varExist(edge_y)) |
---|
526 | { |
---|
527 | SuperClassWriter::addAttribute("edge_node_connectivity", edge_nodes, &domainName); |
---|
528 | SuperClassWriter::addAttribute("edge_coordinates", edge_x + " " + edge_y, &domainName); |
---|
529 | SuperClassWriter::addDimension(dimEdge, domain->mesh->nbEdges); |
---|
530 | dim0.clear(); |
---|
531 | dim0.push_back(dimEdge); |
---|
532 | SuperClassWriter::addVariable(edge_x, NC_FLOAT, dim0); |
---|
533 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x); |
---|
534 | SuperClassWriter::addAttribute("longname_name", StdString("Characteristic longitude of mesh edges."), &edge_x); |
---|
535 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x); |
---|
536 | SuperClassWriter::addVariable(edge_y, NC_FLOAT, dim0); |
---|
537 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y); |
---|
538 | SuperClassWriter::addAttribute("longname_name", StdString("Characteristic latitude of mesh edges."), &edge_y); |
---|
539 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &edge_y); |
---|
540 | dim0.clear(); |
---|
541 | dim0.push_back(dimEdge); |
---|
542 | dim0.push_back(dimTwo); |
---|
543 | SuperClassWriter::addVariable(edge_nodes, NC_INT, dim0); |
---|
544 | SuperClassWriter::addAttribute("cf_role", StdString("edge_node_connectivity"), &edge_nodes); |
---|
545 | SuperClassWriter::addAttribute("long_name", StdString("Maps every edge/link to two nodes that it connects."), &edge_nodes); |
---|
546 | SuperClassWriter::addAttribute("start_index", 0, &edge_nodes); |
---|
547 | } |
---|
548 | } // domain->nvertex == 2 |
---|
549 | |
---|
550 | // Adding faces, edges, and nodes, if edges and nodes have not been defined previously |
---|
551 | if (domain->nvertex > 2) |
---|
552 | { |
---|
553 | // Nodes |
---|
554 | if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y)) |
---|
555 | { |
---|
556 | SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodes); |
---|
557 | dim0.clear(); |
---|
558 | dim0.push_back(dimNode); |
---|
559 | SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0); |
---|
560 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x); |
---|
561 | SuperClassWriter::addAttribute("longname_name", StdString("Longitude of mesh nodes."), &node_x); |
---|
562 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x); |
---|
563 | SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0); |
---|
564 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y); |
---|
565 | SuperClassWriter::addAttribute("longname_name", StdString("Latitude of mesh nodes."), &node_y); |
---|
566 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y); |
---|
567 | } |
---|
568 | // Edges |
---|
569 | if (!SuperClassWriter::varExist(edge_x) || !SuperClassWriter::varExist(edge_y)) |
---|
570 | { |
---|
571 | SuperClassWriter::addAttribute("edge_coordinates", edge_x + " " + edge_y, &domainName); |
---|
572 | SuperClassWriter::addAttribute("edge_node_connectivity", edge_nodes, &domainName); |
---|
573 | SuperClassWriter::addDimension(dimEdge, domain->mesh->nbEdges); |
---|
574 | dim0.clear(); |
---|
575 | dim0.push_back(dimEdge); |
---|
576 | SuperClassWriter::addVariable(edge_x, NC_FLOAT, dim0); |
---|
577 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x); |
---|
578 | SuperClassWriter::addAttribute("longname_name", StdString("Characteristic longitude of mesh edges."), &edge_x); |
---|
579 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x); |
---|
580 | SuperClassWriter::addVariable(edge_y, NC_FLOAT, dim0); |
---|
581 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y); |
---|
582 | SuperClassWriter::addAttribute("longname_name", StdString("Characteristic latitude of mesh edges."), &edge_y); |
---|
583 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &edge_y); |
---|
584 | dim0.clear(); |
---|
585 | dim0.push_back(dimEdge); |
---|
586 | dim0.push_back(dimTwo); |
---|
587 | SuperClassWriter::addVariable(edge_nodes, NC_INT, dim0); |
---|
588 | SuperClassWriter::addAttribute("cf_role", StdString("edge_node_connectivity"), &edge_nodes); |
---|
589 | SuperClassWriter::addAttribute("long_name", StdString("Maps every edge/link to two nodes that it connects."), &edge_nodes); |
---|
590 | SuperClassWriter::addAttribute("start_index", 0, &edge_nodes); |
---|
591 | } |
---|
592 | // Faces |
---|
593 | SuperClassWriter::addAttribute("face_coordinates", face_x + " " + face_y, &domainName); |
---|
594 | SuperClassWriter::addAttribute("face_node_connectivity", face_nodes, &domainName); |
---|
595 | SuperClassWriter::addDimension(dimFace, domain->mesh->nbFaces); |
---|
596 | SuperClassWriter::addDimension(dimVertex, domain->mesh->nvertex); |
---|
597 | dim0.clear(); |
---|
598 | dim0.push_back(dimFace); |
---|
599 | SuperClassWriter::addVariable(face_x, NC_FLOAT, dim0); |
---|
600 | SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &face_x); |
---|
601 | SuperClassWriter::addAttribute("longname_name", StdString("Characteristic longitude of mesh faces."), &face_x); |
---|
602 | SuperClassWriter::addAttribute("units", StdString("degrees_east"), &face_x); |
---|
603 | SuperClassWriter::addVariable(face_y, NC_FLOAT, dim0); |
---|
604 | SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &face_y); |
---|
605 | SuperClassWriter::addAttribute("longname_name", StdString("Characteristic latitude of mesh faces."), &face_y); |
---|
606 | SuperClassWriter::addAttribute("units", StdString("degrees_north"), &face_y); |
---|
607 | dim0.clear(); |
---|
608 | dim0.push_back(dimFace); |
---|
609 | dim0.push_back(dimVertex); |
---|
610 | SuperClassWriter::addVariable(face_nodes, NC_INT, dim0); |
---|
611 | SuperClassWriter::addAttribute("cf_role", StdString("face_node_connectivity"), &face_nodes); |
---|
612 | SuperClassWriter::addAttribute("long_name", StdString("Maps every face to its corner nodes."), &face_nodes); |
---|
613 | SuperClassWriter::addAttribute("start_index", 0, &face_nodes); |
---|
614 | } // domain->nvertex > 2 |
---|
615 | |
---|
616 | SuperClassWriter::definition_end(); |
---|
617 | |
---|
618 | if (!isWrittenDomain(domid)) |
---|
619 | { |
---|
620 | if (domain->nvertex == 1) |
---|
621 | { |
---|
622 | SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0); |
---|
623 | SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0); |
---|
624 | } |
---|
625 | else if (domain->nvertex == 2) |
---|
626 | { |
---|
627 | SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0); |
---|
628 | SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0); |
---|
629 | SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0); |
---|
630 | SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0); |
---|
631 | SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes); |
---|
632 | } |
---|
633 | else |
---|
634 | { |
---|
635 | SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0); |
---|
636 | SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0); |
---|
637 | SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0); |
---|
638 | SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0); |
---|
639 | SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes); |
---|
640 | SuperClassWriter::writeData(domain->mesh->face_lat, face_y, isCollective, 0); |
---|
641 | SuperClassWriter::writeData(domain->mesh->face_lon, face_x, isCollective, 0); |
---|
642 | SuperClassWriter::writeData(domain->mesh->face_nodes, face_nodes); |
---|
643 | } |
---|
644 | setWrittenDomain(domid); |
---|
645 | } // !isWrittenDomain |
---|
646 | else |
---|
647 | { |
---|
648 | if (domain->nvertex == 1) |
---|
649 | { |
---|
650 | if ( (!domain->mesh->edgesAreWritten) && (!domain->mesh->facesAreWritten) ) |
---|
651 | { |
---|
652 | SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0); |
---|
653 | SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0); |
---|
654 | } |
---|
655 | } |
---|
656 | if (domain->nvertex == 2) |
---|
657 | { |
---|
658 | if (!domain->mesh->facesAreWritten) |
---|
659 | { |
---|
660 | if (!domain->mesh->nodesAreWritten) |
---|
661 | { |
---|
662 | SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0); |
---|
663 | SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0); |
---|
664 | } |
---|
665 | SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0); |
---|
666 | SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0); |
---|
667 | SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes); |
---|
668 | } |
---|
669 | } |
---|
670 | if (domain->nvertex > 2) |
---|
671 | { |
---|
672 | if (!domain->mesh->edgesAreWritten) |
---|
673 | { |
---|
674 | if (!domain->mesh->nodesAreWritten) |
---|
675 | { |
---|
676 | SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0); |
---|
677 | SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0); |
---|
678 | } |
---|
679 | SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0); |
---|
680 | SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0); |
---|
681 | SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes); |
---|
682 | } |
---|
683 | SuperClassWriter::writeData(domain->mesh->face_lat, face_y, isCollective, 0); |
---|
684 | SuperClassWriter::writeData(domain->mesh->face_lon, face_x, isCollective, 0); |
---|
685 | SuperClassWriter::writeData(domain->mesh->face_nodes, face_nodes); |
---|
686 | } |
---|
687 | }// isWrittenDomain |
---|
688 | |
---|
689 | SuperClassWriter::definition_start(); |
---|
690 | |
---|
691 | break; |
---|
692 | } // ONE_FILE |
---|
693 | |
---|
694 | case (MULTI_FILE) : |
---|
695 | { |
---|
696 | break; |
---|
697 | } |
---|
698 | |
---|
699 | default : |
---|
700 | ERROR("CNc4DataOutput::writeDomain(domain)", |
---|
701 | << "[ type = " << SuperClass::type << "]" |
---|
702 | << " not implemented yet !"); |
---|
703 | } // switch |
---|
704 | } // try |
---|
705 | |
---|
706 | catch (CNetCdfException& e) |
---|
707 | { |
---|
708 | StdString msg("On writing the domain : "); |
---|
709 | msg.append(domid); msg.append("\n"); |
---|
710 | msg.append("In the context : "); |
---|
711 | msg.append(context->getId()); msg.append("\n"); |
---|
712 | msg.append(e.what()); |
---|
713 | ERROR("CNc4DataOutput::writeUnstructuredDomain(CDomain* domain)", << msg); |
---|
714 | } |
---|
715 | |
---|
716 | domain->addRelFile(this->filename); |
---|
717 | } |
---|
718 | |
---|
719 | //-------------------------------------------------------------- |
---|
720 | |
---|
721 | void CNc4DataOutput::writeUnstructuredDomain(CDomain* domain) |
---|
722 | { |
---|
723 | CContext* context = CContext::getCurrent() ; |
---|
724 | CContextServer* server=context->server ; |
---|
725 | |
---|
726 | if (domain->IsWritten(this->filename)) return; |
---|
727 | domain->checkAttributes(); |
---|
728 | |
---|
729 | if (domain->isEmpty()) |
---|
730 | if (SuperClass::type==MULTI_FILE) return ; |
---|
731 | |
---|
732 | std::vector<StdString> dim0, dim1; |
---|
733 | StdString domid = domain->getDomainOutputName(); |
---|
734 | if (isWrittenDomain(domid)) return ; |
---|
735 | else setWrittenDomain(domid); |
---|
736 | |
---|
737 | StdString appendDomid = (singleDomain) ? "" : "_"+domid ; |
---|
738 | |
---|
739 | |
---|
740 | StdString dimXid = StdString("cell").append(appendDomid); |
---|
741 | StdString dimVertId = StdString("nvertex").append(appendDomid); |
---|
742 | |
---|
743 | string lonid,latid,bounds_lonid,bounds_latid ; |
---|
744 | string areaId = "area" + appendDomid; |
---|
745 | |
---|
746 | try |
---|
747 | { |
---|
748 | switch (SuperClass::type) |
---|
749 | { |
---|
750 | case (MULTI_FILE) : |
---|
751 | { |
---|
752 | dim0.push_back(dimXid); |
---|
753 | SuperClassWriter::addDimension(dimXid, domain->zoom_ni_srv); |
---|
754 | |
---|
755 | lonid = StdString("lon").append(appendDomid); |
---|
756 | latid = StdString("lat").append(appendDomid); |
---|
757 | bounds_lonid = StdString("bounds_lon").append(appendDomid); |
---|
758 | bounds_latid = StdString("bounds_lat").append(appendDomid); |
---|
759 | if (domain->hasLonLat) |
---|
760 | { |
---|
761 | SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); |
---|
762 | SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); |
---|
763 | this->writeAxisAttributes(lonid, "", "longitude", "Longitude", "degrees_east", domid); |
---|
764 | if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid); |
---|
765 | this->writeAxisAttributes(latid, "", "latitude", "Latitude", "degrees_north", domid); |
---|
766 | if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid); |
---|
767 | if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex); |
---|
768 | } |
---|
769 | dim0.clear(); |
---|
770 | if (domain->hasBounds) |
---|
771 | { |
---|
772 | dim0.push_back(dimXid); |
---|
773 | dim0.push_back(dimVertId); |
---|
774 | SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); |
---|
775 | SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); |
---|
776 | } |
---|
777 | |
---|
778 | dim0.clear(); |
---|
779 | dim0.push_back(dimXid); |
---|
780 | if (domain->hasArea) |
---|
781 | { |
---|
782 | SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0); |
---|
783 | SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); |
---|
784 | SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); |
---|
785 | } |
---|
786 | |
---|
787 | SuperClassWriter::definition_end(); |
---|
788 | |
---|
789 | if (domain->hasLonLat) |
---|
790 | { |
---|
791 | SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0); |
---|
792 | SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0); |
---|
793 | if (domain->hasBounds) |
---|
794 | { |
---|
795 | SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0); |
---|
796 | SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0); |
---|
797 | } |
---|
798 | } |
---|
799 | |
---|
800 | if (domain->hasArea) |
---|
801 | SuperClassWriter::writeData(domain->area_srv, areaId, isCollective, 0); |
---|
802 | |
---|
803 | SuperClassWriter::definition_start(); |
---|
804 | break ; |
---|
805 | } |
---|
806 | |
---|
807 | case (ONE_FILE) : |
---|
808 | { |
---|
809 | lonid = StdString("lon").append(appendDomid); |
---|
810 | latid = StdString("lat").append(appendDomid); |
---|
811 | bounds_lonid = StdString("bounds_lon").append(appendDomid); |
---|
812 | bounds_latid = StdString("bounds_lat").append(appendDomid); |
---|
813 | dim0.push_back(dimXid); |
---|
814 | SuperClassWriter::addDimension(dimXid, domain->ni_glo); |
---|
815 | if (domain->hasLonLat) |
---|
816 | { |
---|
817 | SuperClassWriter::addVariable(latid, NC_FLOAT, dim0); |
---|
818 | SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0); |
---|
819 | |
---|
820 | this->writeAxisAttributes(lonid, "", "longitude", "Longitude", "degrees_east", domid); |
---|
821 | if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid); |
---|
822 | this->writeAxisAttributes(latid, "", "latitude", "Latitude", "degrees_north", domid); |
---|
823 | if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid); |
---|
824 | if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex); |
---|
825 | } |
---|
826 | dim0.clear(); |
---|
827 | |
---|
828 | if (domain->hasBounds) |
---|
829 | { |
---|
830 | dim0.push_back(dimXid); |
---|
831 | dim0.push_back(dimVertId); |
---|
832 | SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0); |
---|
833 | SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0); |
---|
834 | } |
---|
835 | |
---|
836 | if (domain->hasArea) |
---|
837 | { |
---|
838 | dim0.clear(); |
---|
839 | dim0.push_back(dimXid); |
---|
840 | SuperClassWriter::addVariable(areaId, NC_FLOAT, dim0); |
---|
841 | SuperClassWriter::addAttribute("standard_name", StdString("cell_area"), &areaId); |
---|
842 | SuperClassWriter::addAttribute("units", StdString("m2"), &areaId); |
---|
843 | } |
---|
844 | |
---|
845 | SuperClassWriter::definition_end(); |
---|
846 | |
---|
847 | std::vector<StdSize> start(1), startBounds(2) ; |
---|
848 | std::vector<StdSize> count(1), countBounds(2) ; |
---|
849 | if (domain->isEmpty()) |
---|
850 | { |
---|
851 | start[0]=0 ; |
---|
852 | count[0]=0 ; |
---|
853 | startBounds[1]=0 ; |
---|
854 | countBounds[1]=domain->nvertex ; |
---|
855 | startBounds[0]=0 ; |
---|
856 | countBounds[0]=0 ; |
---|
857 | } |
---|
858 | else |
---|
859 | { |
---|
860 | start[0]=domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
861 | count[0]=domain->zoom_ni_srv ; |
---|
862 | startBounds[0]=domain->zoom_ibegin_srv-domain->global_zoom_ibegin; |
---|
863 | startBounds[1]=0 ; |
---|
864 | countBounds[0]=domain->zoom_ni_srv ; |
---|
865 | countBounds[1]=domain->nvertex ; |
---|
866 | } |
---|
867 | |
---|
868 | if (domain->hasLonLat) |
---|
869 | { |
---|
870 | SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count); |
---|
871 | SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count); |
---|
872 | if (domain->hasBounds) |
---|
873 | { |
---|
874 | SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0,&startBounds,&countBounds); |
---|
875 | SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0,&startBounds,&countBounds); |
---|
876 | } |
---|
877 | } |
---|
878 | |
---|
879 | if (domain->hasArea) |
---|
880 | SuperClassWriter::writeData(domain->area_srv, areaId, isCollective, 0, &start, &count); |
---|
881 | |
---|
882 | SuperClassWriter::definition_start(); |
---|
883 | |
---|
884 | break; |
---|
885 | } |
---|
886 | default : |
---|
887 | ERROR("CNc4DataOutput::writeDomain(domain)", |
---|
888 | << "[ type = " << SuperClass::type << "]" |
---|
889 | << " not implemented yet !"); |
---|
890 | } |
---|
891 | } |
---|
892 | catch (CNetCdfException& e) |
---|
893 | { |
---|
894 | StdString msg("On writing the domain : "); |
---|
895 | msg.append(domid); msg.append("\n"); |
---|
896 | msg.append("In the context : "); |
---|
897 | msg.append(context->getId()); msg.append("\n"); |
---|
898 | msg.append(e.what()); |
---|
899 | ERROR("CNc4DataOutput::writeUnstructuredDomain(CDomain* domain)", << msg); |
---|
900 | } |
---|
901 | domain->addRelFile(this->filename); |
---|
902 | } |
---|
903 | //-------------------------------------------------------------- |
---|
904 | |
---|
905 | void CNc4DataOutput::writeAxis_(CAxis* axis) |
---|
906 | { |
---|
907 | if (axis->IsWritten(this->filename)) return; |
---|
908 | axis->checkAttributes(); |
---|
909 | int zoom_size_srv = axis->zoom_size_srv; |
---|
910 | int zoom_begin_srv = axis->zoom_begin_srv; |
---|
911 | int zoom_size = (MULTI_FILE == SuperClass::type) ? zoom_size_srv |
---|
912 | : axis->global_zoom_n; |
---|
913 | int zoom_begin = (MULTI_FILE == SuperClass::type) ? zoom_begin_srv |
---|
914 | : axis->global_zoom_begin; |
---|
915 | |
---|
916 | if ((0 == zoom_size_srv) && (MULTI_FILE == SuperClass::type)) return; |
---|
917 | |
---|
918 | std::vector<StdString> dims; |
---|
919 | StdString axisid = axis->getAxisOutputName(); |
---|
920 | if (isWrittenAxis(axisid)) return ; |
---|
921 | else setWrittenAxis(axisid); |
---|
922 | |
---|
923 | try |
---|
924 | { |
---|
925 | SuperClassWriter::addDimension(axisid, zoom_size); |
---|
926 | if (axis->hasValue) |
---|
927 | { |
---|
928 | dims.push_back(axisid); |
---|
929 | SuperClassWriter::addVariable(axisid, NC_FLOAT, dims); |
---|
930 | |
---|
931 | if (!axis->name.isEmpty()) |
---|
932 | SuperClassWriter::addAttribute("name", axis->name.getValue(), &axisid); |
---|
933 | |
---|
934 | if (!axis->standard_name.isEmpty()) |
---|
935 | SuperClassWriter::addAttribute("standard_name", axis->standard_name.getValue(), &axisid); |
---|
936 | |
---|
937 | if (!axis->long_name.isEmpty()) |
---|
938 | SuperClassWriter::addAttribute("long_name", axis->long_name.getValue(), &axisid); |
---|
939 | |
---|
940 | if (!axis->unit.isEmpty()) |
---|
941 | SuperClassWriter::addAttribute("units", axis->unit.getValue(), &axisid); |
---|
942 | |
---|
943 | if (!axis->positive.isEmpty()) |
---|
944 | { |
---|
945 | SuperClassWriter::addAttribute("axis", string("Z"), &axisid); |
---|
946 | SuperClassWriter::addAttribute("positive", |
---|
947 | (axis->positive == CAxis::positive_attr::up) ? string("up") : string("down"), |
---|
948 | &axisid); |
---|
949 | } |
---|
950 | |
---|
951 | StdString axisBoundsId = axisid + "_bounds"; |
---|
952 | if (!axis->bounds.isEmpty()) |
---|
953 | { |
---|
954 | dims.push_back("axis_nbounds"); |
---|
955 | SuperClassWriter::addVariable(axisBoundsId, NC_FLOAT, dims); |
---|
956 | SuperClassWriter::addAttribute("bounds", axisBoundsId, &axisid); |
---|
957 | } |
---|
958 | |
---|
959 | SuperClassWriter::definition_end(); |
---|
960 | |
---|
961 | switch (SuperClass::type) |
---|
962 | { |
---|
963 | case MULTI_FILE: |
---|
964 | { |
---|
965 | CArray<double,1> axis_value(zoom_size_srv); |
---|
966 | for (int i = 0; i < zoom_size_srv; i++) axis_value(i) = axis->value_srv(i); |
---|
967 | SuperClassWriter::writeData(axis_value, axisid, isCollective, 0); |
---|
968 | |
---|
969 | if (!axis->bounds.isEmpty()) |
---|
970 | SuperClassWriter::writeData(axis->bound_srv, axisBoundsId, isCollective, 0); |
---|
971 | |
---|
972 | SuperClassWriter::definition_start(); |
---|
973 | |
---|
974 | break; |
---|
975 | } |
---|
976 | case ONE_FILE: |
---|
977 | { |
---|
978 | CArray<double,1> axis_value(zoom_size_srv); |
---|
979 | axis_value = axis->value_srv; |
---|
980 | |
---|
981 | std::vector<StdSize> start(1), startBounds(2) ; |
---|
982 | std::vector<StdSize> count(1), countBounds(2) ; |
---|
983 | start[0] = startBounds[0] = zoom_begin_srv-axis->global_zoom_begin; |
---|
984 | count[0] = countBounds[0] = zoom_size_srv; |
---|
985 | startBounds[1] = 0; |
---|
986 | countBounds[1] = 2; |
---|
987 | SuperClassWriter::writeData(axis_value, axisid, isCollective, 0, &start, &count); |
---|
988 | |
---|
989 | if (!axis->bounds.isEmpty()) |
---|
990 | SuperClassWriter::writeData(axis->bound_srv, axisBoundsId, isCollective, 0, &startBounds, &countBounds); |
---|
991 | |
---|
992 | SuperClassWriter::definition_start(); |
---|
993 | |
---|
994 | break; |
---|
995 | } |
---|
996 | default : |
---|
997 | ERROR("CNc4DataOutput::writeAxis_(CAxis* axis)", |
---|
998 | << "[ type = " << SuperClass::type << "]" |
---|
999 | << " not implemented yet !"); |
---|
1000 | } |
---|
1001 | } |
---|
1002 | } |
---|
1003 | catch (CNetCdfException& e) |
---|
1004 | { |
---|
1005 | StdString msg("On writing the axis : "); |
---|
1006 | msg.append(axisid); msg.append("\n"); |
---|
1007 | msg.append("In the context : "); |
---|
1008 | CContext* context = CContext::getCurrent() ; |
---|
1009 | msg.append(context->getId()); msg.append("\n"); |
---|
1010 | msg.append(e.what()); |
---|
1011 | ERROR("CNc4DataOutput::writeAxis_(CAxis* axis)", << msg); |
---|
1012 | } |
---|
1013 | axis->addRelFile(this->filename); |
---|
1014 | } |
---|
1015 | |
---|
1016 | //-------------------------------------------------------------- |
---|
1017 | |
---|
1018 | void CNc4DataOutput::writeGridCompressed_(CGrid* grid) |
---|
1019 | { |
---|
1020 | if (grid->isScalarGrid() || grid->isWrittenCompressed(this->filename)) return; |
---|
1021 | |
---|
1022 | try |
---|
1023 | { |
---|
1024 | CArray<bool,1> axisDomainOrder = grid->axis_domain_order; |
---|
1025 | std::vector<StdString> domainList = grid->getDomainList(); |
---|
1026 | std::vector<StdString> axisList = grid->getAxisList(); |
---|
1027 | int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0; |
---|
1028 | |
---|
1029 | std::vector<StdString> dims; |
---|
1030 | |
---|
1031 | if (grid->isCompressible()) |
---|
1032 | { |
---|
1033 | StdString varId = grid->getId() + "_points"; |
---|
1034 | |
---|
1035 | int nbIndexes = (SuperClass::type == MULTI_FILE) ? grid->getNumberWrittenIndexes() : grid->getTotalNumberWrittenIndexes(); |
---|
1036 | SuperClassWriter::addDimension(varId, nbIndexes); |
---|
1037 | |
---|
1038 | dims.push_back(varId); |
---|
1039 | SuperClassWriter::addVariable(varId, NC_INT, dims); |
---|
1040 | |
---|
1041 | StdOStringStream compress; |
---|
1042 | for (int i = numElement - 1; i >= 0; --i) |
---|
1043 | { |
---|
1044 | if (axisDomainOrder(i)) |
---|
1045 | { |
---|
1046 | CDomain* domain = CDomain::get(domainList[domainList.size() - idxDomain - 1]); |
---|
1047 | StdString domId = domain->getDomainOutputName(); |
---|
1048 | StdString appendDomId = singleDomain ? "" : "_" + domId; |
---|
1049 | |
---|
1050 | switch (domain->type) |
---|
1051 | { |
---|
1052 | case CDomain::type_attr::curvilinear: |
---|
1053 | compress << "y" << appendDomId << " x" << appendDomId; |
---|
1054 | break; |
---|
1055 | case CDomain::type_attr::rectilinear: |
---|
1056 | compress << "lat" << appendDomId << " lon" << appendDomId; |
---|
1057 | break; |
---|
1058 | case CDomain::type_attr::unstructured: |
---|
1059 | compress << "cell" << appendDomId; |
---|
1060 | break; |
---|
1061 | } |
---|
1062 | ++idxDomain; |
---|
1063 | } |
---|
1064 | else |
---|
1065 | { |
---|
1066 | CAxis* axis = CAxis::get(axisList[axisList.size() - idxAxis - 1]); |
---|
1067 | compress << axis->getAxisOutputName(); |
---|
1068 | ++idxAxis; |
---|
1069 | } |
---|
1070 | |
---|
1071 | if (i != 0) compress << ' '; |
---|
1072 | } |
---|
1073 | SuperClassWriter::addAttribute("compress", compress.str(), &varId); |
---|
1074 | |
---|
1075 | grid->computeCompressedIndex(); |
---|
1076 | |
---|
1077 | CArray<int, 1> indexes(grid->getNumberWrittenIndexes()); |
---|
1078 | std::map<int, CArray<size_t, 1> >::const_iterator it; |
---|
1079 | for (it = grid->outIndexFromClient.begin(); it != grid->outIndexFromClient.end(); ++it) |
---|
1080 | { |
---|
1081 | const CArray<size_t, 1> compressedIndexes = grid->compressedOutIndexFromClient[it->first]; |
---|
1082 | for (int i = 0; i < it->second.numElements(); i++) |
---|
1083 | indexes(compressedIndexes(i)) = it->second(i); |
---|
1084 | } |
---|
1085 | |
---|
1086 | switch (SuperClass::type) |
---|
1087 | { |
---|
1088 | case (MULTI_FILE): |
---|
1089 | { |
---|
1090 | SuperClassWriter::writeData(indexes, varId, isCollective, 0); |
---|
1091 | break; |
---|
1092 | } |
---|
1093 | case (ONE_FILE): |
---|
1094 | { |
---|
1095 | if (grid->doGridHaveDataDistributed()) |
---|
1096 | grid->getDistributionServer()->computeGlobalIndex(indexes); |
---|
1097 | |
---|
1098 | std::vector<StdSize> start, count; |
---|
1099 | start.push_back(grid->getOffsetWrittenIndexes()); |
---|
1100 | count.push_back(grid->getNumberWrittenIndexes()); |
---|
1101 | |
---|
1102 | SuperClassWriter::writeData(indexes, varId, isCollective, 0, &start, &count); |
---|
1103 | break; |
---|
1104 | } |
---|
1105 | } |
---|
1106 | } |
---|
1107 | else |
---|
1108 | { |
---|
1109 | for (int i = 0; i < numElement; ++i) |
---|
1110 | { |
---|
1111 | StdString varId, compress; |
---|
1112 | CArray<int, 1> indexes; |
---|
1113 | bool isDistributed; |
---|
1114 | StdSize nbIndexes, totalNbIndexes, offset; |
---|
1115 | int firstGlobalIndex; |
---|
1116 | |
---|
1117 | if (axisDomainOrder(i)) |
---|
1118 | { |
---|
1119 | CDomain* domain = CDomain::get(domainList[idxDomain]); |
---|
1120 | StdString domId = domain->getDomainOutputName(); |
---|
1121 | |
---|
1122 | if (!domain->isCompressible() |
---|
1123 | || domain->type == CDomain::type_attr::unstructured |
---|
1124 | || domain->isWrittenCompressed(this->filename) |
---|
1125 | || isWrittenCompressedDomain(domId)) |
---|
1126 | continue; |
---|
1127 | |
---|
1128 | StdString appendDomId = singleDomain ? "" : "_" + domId; |
---|
1129 | |
---|
1130 | varId = domId + "_points"; |
---|
1131 | switch (domain->type) |
---|
1132 | { |
---|
1133 | case CDomain::type_attr::curvilinear: |
---|
1134 | compress = "y" + appendDomId + " x" + appendDomId; |
---|
1135 | break; |
---|
1136 | case CDomain::type_attr::rectilinear: |
---|
1137 | compress = "lat" + appendDomId + " lon" + appendDomId; |
---|
1138 | break; |
---|
1139 | } |
---|
1140 | |
---|
1141 | const std::vector<int>& indexesToWrite = domain->getIndexesToWrite(); |
---|
1142 | indexes.resize(indexesToWrite.size()); |
---|
1143 | for (int n = 0; n < indexes.numElements(); ++n) |
---|
1144 | indexes(n) = indexesToWrite[n]; |
---|
1145 | |
---|
1146 | isDistributed = domain->isDistributed(); |
---|
1147 | nbIndexes = domain->getNumberWrittenIndexes(); |
---|
1148 | totalNbIndexes = domain->getTotalNumberWrittenIndexes(); |
---|
1149 | offset = domain->getOffsetWrittenIndexes(); |
---|
1150 | firstGlobalIndex = domain->ibegin + domain->jbegin * domain->ni_glo; |
---|
1151 | |
---|
1152 | domain->addRelFileCompressed(this->filename); |
---|
1153 | setWrittenCompressedDomain(domId); |
---|
1154 | ++idxDomain; |
---|
1155 | } |
---|
1156 | else |
---|
1157 | { |
---|
1158 | CAxis* axis = CAxis::get(axisList[idxAxis]); |
---|
1159 | StdString axisId = axis->getAxisOutputName(); |
---|
1160 | |
---|
1161 | if (!axis->isCompressible() |
---|
1162 | || axis->isWrittenCompressed(this->filename) |
---|
1163 | || isWrittenCompressedAxis(axisId)) |
---|
1164 | continue; |
---|
1165 | |
---|
1166 | varId = axisId + "_points"; |
---|
1167 | compress = axisId; |
---|
1168 | |
---|
1169 | const std::vector<int>& indexesToWrite = axis->getIndexesToWrite(); |
---|
1170 | indexes.resize(indexesToWrite.size()); |
---|
1171 | for (int n = 0; n < indexes.numElements(); ++n) |
---|
1172 | indexes(n) = indexesToWrite[n]; |
---|
1173 | |
---|
1174 | isDistributed = axis->isDistributed(); |
---|
1175 | nbIndexes = axis->getNumberWrittenIndexes(); |
---|
1176 | totalNbIndexes = axis->getTotalNumberWrittenIndexes(); |
---|
1177 | offset = axis->getOffsetWrittenIndexes(); |
---|
1178 | firstGlobalIndex = axis->begin; |
---|
1179 | |
---|
1180 | axis->addRelFileCompressed(this->filename); |
---|
1181 | setWrittenCompressedAxis(axisId); |
---|
1182 | ++idxAxis; |
---|
1183 | } |
---|
1184 | |
---|
1185 | if (!varId.empty()) |
---|
1186 | { |
---|
1187 | SuperClassWriter::addDimension(varId, (SuperClass::type == MULTI_FILE) ? nbIndexes : totalNbIndexes); |
---|
1188 | |
---|
1189 | dims.clear(); |
---|
1190 | dims.push_back(varId); |
---|
1191 | SuperClassWriter::addVariable(varId, NC_INT, dims); |
---|
1192 | |
---|
1193 | SuperClassWriter::addAttribute("compress", compress, &varId); |
---|
1194 | |
---|
1195 | switch (SuperClass::type) |
---|
1196 | { |
---|
1197 | case (MULTI_FILE): |
---|
1198 | { |
---|
1199 | indexes -= firstGlobalIndex; |
---|
1200 | SuperClassWriter::writeData(indexes, varId, isCollective, 0); |
---|
1201 | break; |
---|
1202 | } |
---|
1203 | case (ONE_FILE): |
---|
1204 | { |
---|
1205 | std::vector<StdSize> start, count; |
---|
1206 | start.push_back(offset); |
---|
1207 | count.push_back(nbIndexes); |
---|
1208 | |
---|
1209 | SuperClassWriter::writeData(indexes, varId, isCollective, 0, &start, &count); |
---|
1210 | break; |
---|
1211 | } |
---|
1212 | } |
---|
1213 | } |
---|
1214 | } |
---|
1215 | |
---|
1216 | if (!dims.empty()) |
---|
1217 | grid->computeCompressedIndex(); |
---|
1218 | } |
---|
1219 | |
---|
1220 | grid->addRelFileCompressed(this->filename); |
---|
1221 | } |
---|
1222 | catch (CNetCdfException& e) |
---|
1223 | { |
---|
1224 | StdString msg("On writing compressed grid : "); |
---|
1225 | msg.append(grid->getId()); msg.append("\n"); |
---|
1226 | msg.append("In the context : "); |
---|
1227 | CContext* context = CContext::getCurrent(); |
---|
1228 | msg.append(context->getId()); msg.append("\n"); |
---|
1229 | msg.append(e.what()); |
---|
1230 | ERROR("CNc4DataOutput::writeGridCompressed_(CGrid* grid)", << msg); |
---|
1231 | } |
---|
1232 | } |
---|
1233 | |
---|
1234 | //-------------------------------------------------------------- |
---|
1235 | |
---|
1236 | void CNc4DataOutput::writeTimeDimension_(void) |
---|
1237 | { |
---|
1238 | try |
---|
1239 | { |
---|
1240 | SuperClassWriter::addDimension(getTimeCounterName()); |
---|
1241 | } |
---|
1242 | catch (CNetCdfException& e) |
---|
1243 | { |
---|
1244 | StdString msg("On writing time dimension : time_couter\n"); |
---|
1245 | msg.append("In the context : "); |
---|
1246 | CContext* context = CContext::getCurrent() ; |
---|
1247 | msg.append(context->getId()); msg.append("\n"); |
---|
1248 | msg.append(e.what()); |
---|
1249 | ERROR("CNc4DataOutput::writeTimeDimension_(void)", << msg); |
---|
1250 | } |
---|
1251 | } |
---|
1252 | |
---|
1253 | //-------------------------------------------------------------- |
---|
1254 | |
---|
1255 | void CNc4DataOutput::writeField_(CField* field) |
---|
1256 | { |
---|
1257 | CContext* context = CContext::getCurrent() ; |
---|
1258 | CContextServer* server=context->server ; |
---|
1259 | |
---|
1260 | std::vector<StdString> dims, coodinates; |
---|
1261 | CGrid* grid = field->grid; |
---|
1262 | if (!grid->doGridHaveDataToWrite()) |
---|
1263 | if (SuperClass::type==MULTI_FILE) return ; |
---|
1264 | |
---|
1265 | CArray<bool,1> axisDomainOrder = grid->axis_domain_order; |
---|
1266 | int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0; |
---|
1267 | std::vector<StdString> domainList = grid->getDomainList(); |
---|
1268 | std::vector<StdString> axisList = grid->getAxisList(); |
---|
1269 | |
---|
1270 | StdString timeid = getTimeCounterName(); |
---|
1271 | StdString dimXid,dimYid; |
---|
1272 | std::deque<StdString> dimIdList, dimCoordList; |
---|
1273 | bool hasArea = false; |
---|
1274 | StdString cellMeasures = "area:"; |
---|
1275 | bool compressedOutput = !field->indexed_output.isEmpty() && field->indexed_output; |
---|
1276 | |
---|
1277 | for (int i = 0; i < numElement; ++i) |
---|
1278 | { |
---|
1279 | if (axisDomainOrder(i)) |
---|
1280 | { |
---|
1281 | CDomain* domain = CDomain::get(domainList[idxDomain]); |
---|
1282 | StdString domId = domain->getDomainOutputName(); |
---|
1283 | StdString appendDomId = singleDomain ? "" : "_" + domId ; |
---|
1284 | |
---|
1285 | if (compressedOutput && domain->isCompressible() && domain->type != CDomain::type_attr::unstructured) |
---|
1286 | { |
---|
1287 | dimIdList.push_back(domId + "_points"); |
---|
1288 | field->setUseCompressedOutput(); |
---|
1289 | } |
---|
1290 | |
---|
1291 | switch (domain->type) |
---|
1292 | { |
---|
1293 | case CDomain::type_attr::curvilinear: |
---|
1294 | if (!compressedOutput || !domain->isCompressible()) |
---|
1295 | { |
---|
1296 | dimXid = StdString("x").append(appendDomId); |
---|
1297 | dimIdList.push_back(dimXid); |
---|
1298 | dimYid = StdString("y").append(appendDomId); |
---|
1299 | dimIdList.push_back(dimYid); |
---|
1300 | } |
---|
1301 | dimCoordList.push_back(StdString("nav_lon").append(appendDomId)); |
---|
1302 | dimCoordList.push_back(StdString("nav_lat").append(appendDomId)); |
---|
1303 | break ; |
---|
1304 | case CDomain::type_attr::rectilinear: |
---|
1305 | if (!compressedOutput || !domain->isCompressible()) |
---|
1306 | { |
---|
1307 | dimXid = StdString("lon").append(appendDomId); |
---|
1308 | dimIdList.push_back(dimXid); |
---|
1309 | dimYid = StdString("lat").append(appendDomId); |
---|
1310 | dimIdList.push_back(dimYid); |
---|
1311 | } |
---|
1312 | break ; |
---|
1313 | case CDomain::type_attr::unstructured: |
---|
1314 | { |
---|
1315 | if (SuperClassWriter::useCFConvention) |
---|
1316 | { |
---|
1317 | dimXid = StdString("cell").append(appendDomId); |
---|
1318 | dimIdList.push_back(dimXid); |
---|
1319 | dimCoordList.push_back(StdString("lon").append(appendDomId)); |
---|
1320 | dimCoordList.push_back(StdString("lat").append(appendDomId)); |
---|
1321 | } |
---|
1322 | else |
---|
1323 | { |
---|
1324 | StdString domainName = domain->name; |
---|
1325 | if (domain->nvertex == 1) |
---|
1326 | { |
---|
1327 | dimXid = "n" + domainName + "_node"; |
---|
1328 | dimIdList.push_back(dimXid); |
---|
1329 | dimCoordList.push_back(StdString(domainName + "_node_x")); |
---|
1330 | dimCoordList.push_back(StdString(domainName + "_node_y")); |
---|
1331 | } |
---|
1332 | else if (domain->nvertex == 2) |
---|
1333 | { |
---|
1334 | dimXid = "n" + domainName + "_edge"; |
---|
1335 | dimIdList.push_back(dimXid); |
---|
1336 | dimCoordList.push_back(StdString(domainName + "_edge_x")); |
---|
1337 | dimCoordList.push_back(StdString(domainName + "_edge_y")); |
---|
1338 | } |
---|
1339 | else |
---|
1340 | { |
---|
1341 | dimXid = "n" + domainName + "_face"; |
---|
1342 | dimIdList.push_back(dimXid); |
---|
1343 | dimCoordList.push_back(StdString(domainName + "_face_x")); |
---|
1344 | dimCoordList.push_back(StdString(domainName + "_face_y")); |
---|
1345 | } |
---|
1346 | } // ugrid convention |
---|
1347 | } // case unstructured domain |
---|
1348 | } |
---|
1349 | |
---|
1350 | if (domain->hasArea) |
---|
1351 | { |
---|
1352 | hasArea = true; |
---|
1353 | cellMeasures += " area" + appendDomId; |
---|
1354 | } |
---|
1355 | ++idxDomain; |
---|
1356 | } |
---|
1357 | else |
---|
1358 | { |
---|
1359 | CAxis* axis = CAxis::get(axisList[idxAxis]); |
---|
1360 | StdString axisId = axis->getAxisOutputName(); |
---|
1361 | |
---|
1362 | if (compressedOutput && axis->isCompressible()) |
---|
1363 | { |
---|
1364 | dimIdList.push_back(axisId + "_points"); |
---|
1365 | field->setUseCompressedOutput(); |
---|
1366 | } |
---|
1367 | else |
---|
1368 | dimIdList.push_back(axisId); |
---|
1369 | |
---|
1370 | dimCoordList.push_back(axisId); |
---|
1371 | ++idxAxis; |
---|
1372 | } |
---|
1373 | } |
---|
1374 | |
---|
1375 | /* |
---|
1376 | StdString lonid_loc = (server->intraCommSize > 1) |
---|
1377 | ? StdString("lon").append(appendDomid).append("_local") |
---|
1378 | : lonid; |
---|
1379 | StdString latid_loc = (server->intraCommSize > 1) |
---|
1380 | ? StdString("lat").append(appendDomid).append("_local") |
---|
1381 | : latid; |
---|
1382 | */ |
---|
1383 | StdString fieldid = field->getFieldOutputName(); |
---|
1384 | |
---|
1385 | // unsigned int ssize = domain->zoom_ni_loc.getValue() * domain->zoom_nj_loc.getValue(); |
---|
1386 | // bool isCurvilinear = (domain->lonvalue.getValue()->size() == ssize); |
---|
1387 | // bool isCurvilinear = domain->isCurvilinear ; |
---|
1388 | |
---|
1389 | nc_type type ; |
---|
1390 | if (field->prec.isEmpty()) type = NC_FLOAT ; |
---|
1391 | else |
---|
1392 | { |
---|
1393 | if (field->prec==2) type = NC_SHORT ; |
---|
1394 | else if (field->prec==4) type = NC_FLOAT ; |
---|
1395 | else if (field->prec==8) type = NC_DOUBLE ; |
---|
1396 | } |
---|
1397 | |
---|
1398 | bool wtime = !(!field->operation.isEmpty() && field->getOperationTimeType() == func::CFunctor::once); |
---|
1399 | |
---|
1400 | if (wtime) |
---|
1401 | { |
---|
1402 | |
---|
1403 | //StdOStringStream oss; |
---|
1404 | // oss << "time_" << field->operation.getValue() |
---|
1405 | // << "_" << field->getRelFile()->output_freq.getValue(); |
---|
1406 | //oss |
---|
1407 | if (field->getOperationTimeType() == func::CFunctor::instant) coodinates.push_back(string("time_instant")); |
---|
1408 | else if (field->getOperationTimeType() == func::CFunctor::centered) coodinates.push_back(string("time_centered")); |
---|
1409 | dims.push_back(timeid); |
---|
1410 | } |
---|
1411 | |
---|
1412 | if (compressedOutput && grid->isCompressible()) |
---|
1413 | { |
---|
1414 | dims.push_back(grid->getId() + "_points"); |
---|
1415 | field->setUseCompressedOutput(); |
---|
1416 | } |
---|
1417 | else |
---|
1418 | { |
---|
1419 | while (!dimIdList.empty()) |
---|
1420 | { |
---|
1421 | dims.push_back(dimIdList.back()); |
---|
1422 | dimIdList.pop_back(); |
---|
1423 | } |
---|
1424 | } |
---|
1425 | |
---|
1426 | while (!dimCoordList.empty()) |
---|
1427 | { |
---|
1428 | coodinates.push_back(dimCoordList.back()); |
---|
1429 | dimCoordList.pop_back(); |
---|
1430 | } |
---|
1431 | |
---|
1432 | try |
---|
1433 | { |
---|
1434 | SuperClassWriter::addVariable(fieldid, type, dims); |
---|
1435 | |
---|
1436 | if (!field->standard_name.isEmpty()) |
---|
1437 | SuperClassWriter::addAttribute |
---|
1438 | ("standard_name", field->standard_name.getValue(), &fieldid); |
---|
1439 | |
---|
1440 | if (!field->long_name.isEmpty()) |
---|
1441 | SuperClassWriter::addAttribute |
---|
1442 | ("long_name", field->long_name.getValue(), &fieldid); |
---|
1443 | |
---|
1444 | if (!field->unit.isEmpty()) |
---|
1445 | SuperClassWriter::addAttribute |
---|
1446 | ("units", field->unit.getValue(), &fieldid); |
---|
1447 | |
---|
1448 | if (!field->valid_min.isEmpty()) |
---|
1449 | SuperClassWriter::addAttribute |
---|
1450 | ("valid_min", field->valid_min.getValue(), &fieldid); |
---|
1451 | |
---|
1452 | if (!field->valid_max.isEmpty()) |
---|
1453 | SuperClassWriter::addAttribute |
---|
1454 | ("valid_max", field->valid_max.getValue(), &fieldid); |
---|
1455 | |
---|
1456 | if (!field->scale_factor.isEmpty()) |
---|
1457 | SuperClassWriter::addAttribute |
---|
1458 | ("scale_factor", field->scale_factor.getValue(), &fieldid); |
---|
1459 | |
---|
1460 | if (!field->add_offset.isEmpty()) |
---|
1461 | SuperClassWriter::addAttribute |
---|
1462 | ("add_offset", field->add_offset.getValue(), &fieldid); |
---|
1463 | |
---|
1464 | SuperClassWriter::addAttribute |
---|
1465 | ("online_operation", field->operation.getValue(), &fieldid); |
---|
1466 | |
---|
1467 | // write child variables as attributes |
---|
1468 | |
---|
1469 | |
---|
1470 | vector<CVariable*> listVars = field->getAllVariables() ; |
---|
1471 | for (vector<CVariable*>::iterator it = listVars.begin() ;it != listVars.end(); it++) writeAttribute_(*it, fieldid) ; |
---|
1472 | |
---|
1473 | |
---|
1474 | if (wtime) |
---|
1475 | { |
---|
1476 | CDuration freqOp = field->freq_op.getValue(); |
---|
1477 | freqOp.solveTimeStep(*context->calendar); |
---|
1478 | StdString freqOpStr = freqOp.toStringUDUnits(); |
---|
1479 | SuperClassWriter::addAttribute("interval_operation", freqOpStr, &fieldid); |
---|
1480 | |
---|
1481 | CDuration freqOut = field->getRelFile()->output_freq.getValue(); |
---|
1482 | freqOut.solveTimeStep(*context->calendar); |
---|
1483 | SuperClassWriter::addAttribute("interval_write", freqOut.toStringUDUnits(), &fieldid); |
---|
1484 | |
---|
1485 | StdString cellMethods = "time: "; |
---|
1486 | if (field->operation.getValue() == "instant") cellMethods += "point"; |
---|
1487 | else if (field->operation.getValue() == "average") cellMethods += "mean"; |
---|
1488 | else if (field->operation.getValue() == "accumulate") cellMethods += "sum"; |
---|
1489 | else cellMethods += field->operation; |
---|
1490 | if (freqOp.resolve(*context->calendar) != freqOut.resolve(*context->calendar)) |
---|
1491 | cellMethods += " (interval: " + freqOpStr + ")"; |
---|
1492 | SuperClassWriter::addAttribute("cell_methods", cellMethods, &fieldid); |
---|
1493 | } |
---|
1494 | |
---|
1495 | if (hasArea) |
---|
1496 | SuperClassWriter::addAttribute("cell_measures", cellMeasures, &fieldid); |
---|
1497 | |
---|
1498 | if (!field->default_value.isEmpty()) |
---|
1499 | { |
---|
1500 | double default_value = field->default_value.getValue(); |
---|
1501 | float fdefault_value = (float)default_value; |
---|
1502 | if (type == NC_DOUBLE) |
---|
1503 | SuperClassWriter::setDefaultValue(fieldid, &default_value); |
---|
1504 | else |
---|
1505 | SuperClassWriter::setDefaultValue(fieldid, &fdefault_value); |
---|
1506 | } |
---|
1507 | else |
---|
1508 | SuperClassWriter::setDefaultValue(fieldid, (double*)NULL); |
---|
1509 | |
---|
1510 | if (field->compression_level.isEmpty()) |
---|
1511 | field->compression_level = field->file->compression_level.isEmpty() ? 0 : field->file->compression_level; |
---|
1512 | SuperClassWriter::setCompressionLevel(fieldid, field->compression_level); |
---|
1513 | |
---|
1514 | { // Ecriture des coordonnes |
---|
1515 | |
---|
1516 | StdString coordstr; //boost::algorithm::join(coodinates, " ") |
---|
1517 | std::vector<StdString>::iterator |
---|
1518 | itc = coodinates.begin(), endc = coodinates.end(); |
---|
1519 | |
---|
1520 | for (; itc!= endc; itc++) |
---|
1521 | { |
---|
1522 | StdString & coord = *itc; |
---|
1523 | if (itc+1 != endc) |
---|
1524 | coordstr.append(coord).append(" "); |
---|
1525 | else coordstr.append(coord); |
---|
1526 | } |
---|
1527 | |
---|
1528 | SuperClassWriter::addAttribute("coordinates", coordstr, &fieldid); |
---|
1529 | |
---|
1530 | } |
---|
1531 | } |
---|
1532 | catch (CNetCdfException& e) |
---|
1533 | { |
---|
1534 | StdString msg("On writing field : "); |
---|
1535 | msg.append(fieldid); msg.append("\n"); |
---|
1536 | msg.append("In the context : "); |
---|
1537 | msg.append(context->getId()); msg.append("\n"); |
---|
1538 | msg.append(e.what()); |
---|
1539 | ERROR("CNc4DataOutput::writeField_(CField* field)", << msg); |
---|
1540 | } |
---|
1541 | } // writeField_() |
---|
1542 | |
---|
1543 | //-------------------------------------------------------------- |
---|
1544 | |
---|
1545 | void CNc4DataOutput::writeFile_ (CFile* file) |
---|
1546 | { |
---|
1547 | StdString filename = file->getFileOutputName(); |
---|
1548 | StdString description = (!file->description.isEmpty()) |
---|
1549 | ? file->description.getValue() |
---|
1550 | : StdString("Created by xios"); |
---|
1551 | |
---|
1552 | singleDomain = (file->nbDomains == 1); |
---|
1553 | |
---|
1554 | try |
---|
1555 | { |
---|
1556 | if (SuperClassWriter::useCFConvention) |
---|
1557 | this->writeFileAttributes(filename, description, |
---|
1558 | StdString("CF-1.5"), |
---|
1559 | StdString("An IPSL model"), |
---|
1560 | this->getTimeStamp()); |
---|
1561 | else |
---|
1562 | this->writeFileAttributes(filename, description, |
---|
1563 | StdString("UGRID"), |
---|
1564 | StdString("An IPSL model"), |
---|
1565 | this->getTimeStamp()); |
---|
1566 | |
---|
1567 | |
---|
1568 | if (!appendMode) |
---|
1569 | SuperClassWriter::addDimension("axis_nbounds", 2); |
---|
1570 | } |
---|
1571 | catch (CNetCdfException& e) |
---|
1572 | { |
---|
1573 | StdString msg("On writing file : "); |
---|
1574 | msg.append(filename); msg.append("\n"); |
---|
1575 | msg.append("In the context : "); |
---|
1576 | CContext* context = CContext::getCurrent() ; |
---|
1577 | msg.append(context->getId()); msg.append("\n"); |
---|
1578 | msg.append(e.what()); |
---|
1579 | ERROR("CNc4DataOutput::writeFile_ (CFile* file)", << msg); |
---|
1580 | } |
---|
1581 | } |
---|
1582 | |
---|
1583 | void CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId) |
---|
1584 | { |
---|
1585 | StdString name = var->getVariableOutputName(); |
---|
1586 | |
---|
1587 | try |
---|
1588 | { |
---|
1589 | if (var->type.getValue() == CVariable::type_attr::t_int || var->type.getValue() == CVariable::type_attr::t_int32) |
---|
1590 | addAttribute(name, var->getData<int>(), &fieldId); |
---|
1591 | else if (var->type.getValue() == CVariable::type_attr::t_int16) |
---|
1592 | addAttribute(name, var->getData<short int>(), &fieldId); |
---|
1593 | else if (var->type.getValue() == CVariable::type_attr::t_float) |
---|
1594 | addAttribute(name, var->getData<float>(), &fieldId); |
---|
1595 | else if (var->type.getValue() == CVariable::type_attr::t_double) |
---|
1596 | addAttribute(name, var->getData<double>(), &fieldId); |
---|
1597 | else if (var->type.getValue() == CVariable::type_attr::t_string) |
---|
1598 | addAttribute(name, var->getData<string>(), &fieldId); |
---|
1599 | else |
---|
1600 | ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)", |
---|
1601 | << "Unsupported variable of type " << var->type.getStringValue()); |
---|
1602 | } |
---|
1603 | catch (CNetCdfException& e) |
---|
1604 | { |
---|
1605 | StdString msg("On writing attributes of variable with name : "); |
---|
1606 | msg.append(name); msg.append("in the field "); msg.append(fieldId); msg.append("\n"); |
---|
1607 | msg.append("In the context : "); |
---|
1608 | CContext* context = CContext::getCurrent() ; |
---|
1609 | msg.append(context->getId()); msg.append("\n"); |
---|
1610 | msg.append(e.what()); |
---|
1611 | ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)", << msg); |
---|
1612 | } |
---|
1613 | } |
---|
1614 | |
---|
1615 | void CNc4DataOutput::writeAttribute_ (CVariable* var) |
---|
1616 | { |
---|
1617 | StdString name = var->getVariableOutputName(); |
---|
1618 | |
---|
1619 | try |
---|
1620 | { |
---|
1621 | if (var->type.getValue() == CVariable::type_attr::t_int || var->type.getValue() == CVariable::type_attr::t_int32) |
---|
1622 | addAttribute(name, var->getData<int>()); |
---|
1623 | else if (var->type.getValue() == CVariable::type_attr::t_int16) |
---|
1624 | addAttribute(name, var->getData<short int>()); |
---|
1625 | else if (var->type.getValue() == CVariable::type_attr::t_float) |
---|
1626 | addAttribute(name, var->getData<float>()); |
---|
1627 | else if (var->type.getValue() == CVariable::type_attr::t_double) |
---|
1628 | addAttribute(name, var->getData<double>()); |
---|
1629 | else if (var->type.getValue() == CVariable::type_attr::t_string) |
---|
1630 | addAttribute(name, var->getData<string>()); |
---|
1631 | else |
---|
1632 | ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var)", |
---|
1633 | << "Unsupported variable of type " << var->type.getStringValue()); |
---|
1634 | } |
---|
1635 | catch (CNetCdfException& e) |
---|
1636 | { |
---|
1637 | StdString msg("On writing attributes of variable with name : "); |
---|
1638 | msg.append(name); msg.append("\n"); |
---|
1639 | msg.append("In the context : "); |
---|
1640 | CContext* context = CContext::getCurrent() ; |
---|
1641 | msg.append(context->getId()); msg.append("\n"); |
---|
1642 | msg.append(e.what()); |
---|
1643 | ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var)", << msg); |
---|
1644 | } |
---|
1645 | } |
---|
1646 | |
---|
1647 | void CNc4DataOutput::syncFile_ (void) |
---|
1648 | { |
---|
1649 | try |
---|
1650 | { |
---|
1651 | SuperClassWriter::sync() ; |
---|
1652 | } |
---|
1653 | catch (CNetCdfException& e) |
---|
1654 | { |
---|
1655 | StdString msg("On synchronizing the write among processes"); |
---|
1656 | msg.append("In the context : "); |
---|
1657 | CContext* context = CContext::getCurrent() ; |
---|
1658 | msg.append(context->getId()); msg.append("\n"); |
---|
1659 | msg.append(e.what()); |
---|
1660 | ERROR("CNc4DataOutput::syncFile_ (void)", << msg); |
---|
1661 | } |
---|
1662 | } |
---|
1663 | |
---|
1664 | void CNc4DataOutput::closeFile_ (void) |
---|
1665 | { |
---|
1666 | try |
---|
1667 | { |
---|
1668 | SuperClassWriter::close() ; |
---|
1669 | } |
---|
1670 | catch (CNetCdfException& e) |
---|
1671 | { |
---|
1672 | StdString msg("On closing file"); |
---|
1673 | msg.append("In the context : "); |
---|
1674 | CContext* context = CContext::getCurrent() ; |
---|
1675 | msg.append(context->getId()); msg.append("\n"); |
---|
1676 | msg.append(e.what()); |
---|
1677 | ERROR("CNc4DataOutput::syncFile_ (void)", << msg); |
---|
1678 | } |
---|
1679 | |
---|
1680 | } |
---|
1681 | |
---|
1682 | //--------------------------------------------------------------- |
---|
1683 | |
---|
1684 | StdString CNc4DataOutput::getTimeStamp(void) const |
---|
1685 | { |
---|
1686 | const int buffer_size = 100; |
---|
1687 | time_t rawtime; |
---|
1688 | struct tm * timeinfo = NULL; |
---|
1689 | char buffer [buffer_size]; |
---|
1690 | |
---|
1691 | time ( &rawtime ); |
---|
1692 | timeinfo = localtime ( &rawtime ); |
---|
1693 | strftime (buffer, buffer_size, "%Y-%b-%d %H:%M:%S %Z", timeinfo); |
---|
1694 | |
---|
1695 | return (StdString(buffer)); |
---|
1696 | } |
---|
1697 | |
---|
1698 | //--------------------------------------------------------------- |
---|
1699 | |
---|
1700 | void CNc4DataOutput::writeFieldData_ (CField* field) |
---|
1701 | { |
---|
1702 | CContext* context = CContext::getCurrent(); |
---|
1703 | CContextServer* server = context->server; |
---|
1704 | CGrid* grid = field->grid; |
---|
1705 | |
---|
1706 | if (!grid->doGridHaveDataToWrite()) |
---|
1707 | if (SuperClass::type == MULTI_FILE || !isCollective) return; |
---|
1708 | |
---|
1709 | StdString fieldid = field->getFieldOutputName(); |
---|
1710 | |
---|
1711 | StdOStringStream oss; |
---|
1712 | string timeAxisId; |
---|
1713 | if (field->getOperationTimeType() == func::CFunctor::instant) timeAxisId = "time_instant"; |
---|
1714 | else if (field->getOperationTimeType() == func::CFunctor::centered) timeAxisId = "time_centered"; |
---|
1715 | |
---|
1716 | StdString timeBoundId = getTimeCounterName() + "_bounds"; |
---|
1717 | |
---|
1718 | StdString timeAxisBoundId; |
---|
1719 | if (field->getOperationTimeType() == func::CFunctor::instant) timeAxisBoundId = "time_instant_bounds"; |
---|
1720 | else if (field->getOperationTimeType() == func::CFunctor::centered) timeAxisBoundId = "time_centered_bounds"; |
---|
1721 | |
---|
1722 | if (!field->wasWritten()) |
---|
1723 | { |
---|
1724 | if (appendMode && field->file->record_offset.isEmpty()) |
---|
1725 | { |
---|
1726 | field->resetNStep(getRecordFromTime(field->last_Write_srv) + 1); |
---|
1727 | } |
---|
1728 | |
---|
1729 | field->setWritten(); |
---|
1730 | } |
---|
1731 | |
---|
1732 | |
---|
1733 | CArray<double,1> time_data(1); |
---|
1734 | CArray<double,1> time_data_bound(2); |
---|
1735 | CArray<double,1> time_counter(1); |
---|
1736 | CArray<double,1> time_counter_bound(2); |
---|
1737 | |
---|
1738 | bool wtime = (field->getOperationTimeType() != func::CFunctor::once); |
---|
1739 | |
---|
1740 | if (wtime) |
---|
1741 | { |
---|
1742 | Time lastWrite = field->last_Write_srv; |
---|
1743 | Time lastLastWrite = field->lastlast_Write_srv; |
---|
1744 | |
---|
1745 | if (field->getOperationTimeType() == func::CFunctor::instant) |
---|
1746 | time_data(0) = lastWrite; |
---|
1747 | else if (field->getOperationTimeType() == func::CFunctor::centered) |
---|
1748 | time_data(0) = (lastWrite + lastLastWrite) / 2; |
---|
1749 | |
---|
1750 | if (field->getOperationTimeType() == func::CFunctor::instant) |
---|
1751 | time_data_bound(0) = time_data_bound(1) = lastWrite; |
---|
1752 | else if (field->getOperationTimeType() == func::CFunctor::centered) |
---|
1753 | { |
---|
1754 | time_data_bound(0) = lastLastWrite; |
---|
1755 | time_data_bound(1) = lastWrite; |
---|
1756 | } |
---|
1757 | |
---|
1758 | if (field->file->time_counter == CFile::time_counter_attr::instant) |
---|
1759 | time_counter(0) = lastWrite; |
---|
1760 | else if (field->file->time_counter == CFile::time_counter_attr::centered) |
---|
1761 | time_counter(0) = (lastWrite + lastLastWrite) / 2; |
---|
1762 | else if (field->file->time_counter == CFile::time_counter_attr::record) |
---|
1763 | time_counter(0) = field->getNStep() - 1; |
---|
1764 | |
---|
1765 | |
---|
1766 | if (field->file->time_counter == CFile::time_counter_attr::instant) |
---|
1767 | time_counter_bound(0) = time_counter_bound(1) = lastWrite; |
---|
1768 | else if (field->file->time_counter == CFile::time_counter_attr::centered) |
---|
1769 | { |
---|
1770 | time_counter_bound(0) = lastLastWrite; |
---|
1771 | time_counter_bound(1) = lastWrite; |
---|
1772 | } |
---|
1773 | else if (field->file->time_counter == CFile::time_counter_attr::record) |
---|
1774 | time_counter_bound(0) = time_counter_bound(1) = field->getNStep() - 1; |
---|
1775 | } |
---|
1776 | |
---|
1777 | bool isRoot = (server->intraCommRank == 0); |
---|
1778 | |
---|
1779 | if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty()) |
---|
1780 | { |
---|
1781 | double scaleFactor = 1.0; |
---|
1782 | double addOffset = 0.0; |
---|
1783 | if (!field->scale_factor.isEmpty()) scaleFactor = field->scale_factor; |
---|
1784 | if (!field->add_offset.isEmpty()) addOffset = field->add_offset; |
---|
1785 | field->scaleFactorAddOffset(scaleFactor, addOffset); |
---|
1786 | } |
---|
1787 | |
---|
1788 | try |
---|
1789 | { |
---|
1790 | size_t writtenSize; |
---|
1791 | if (field->getUseCompressedOutput()) |
---|
1792 | writtenSize = grid->getNumberWrittenIndexes(); |
---|
1793 | else |
---|
1794 | writtenSize = grid->getWrittenDataSize(); |
---|
1795 | |
---|
1796 | CArray<double,1> fieldData(writtenSize); |
---|
1797 | if (!field->default_value.isEmpty()) fieldData = field->default_value; |
---|
1798 | |
---|
1799 | if (field->getUseCompressedOutput()) |
---|
1800 | field->outputCompressedField(fieldData); |
---|
1801 | else |
---|
1802 | field->outputField(fieldData); |
---|
1803 | |
---|
1804 | if (!field->prec.isEmpty() && field->prec == 2) fieldData = round(fieldData); |
---|
1805 | |
---|
1806 | switch (SuperClass::type) |
---|
1807 | { |
---|
1808 | case (MULTI_FILE) : |
---|
1809 | { |
---|
1810 | SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1); |
---|
1811 | if (wtime) |
---|
1812 | { |
---|
1813 | SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep() - 1); |
---|
1814 | SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1); |
---|
1815 | if (field->file->time_counter != CFile::time_counter_attr::none) |
---|
1816 | { |
---|
1817 | SuperClassWriter::writeData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1); |
---|
1818 | if (field->file->time_counter != CFile::time_counter_attr::record) |
---|
1819 | SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1); |
---|
1820 | } |
---|
1821 | } |
---|
1822 | break; |
---|
1823 | } |
---|
1824 | case (ONE_FILE) : |
---|
1825 | { |
---|
1826 | const std::vector<int>& nZoomBeginGlobal = grid->getDistributionServer()->getZoomBeginGlobal(); |
---|
1827 | const std::vector<int>& nZoomBeginServer = grid->getDistributionServer()->getZoomBeginServer(); |
---|
1828 | const std::vector<int>& nZoomSizeServer = grid->getDistributionServer()->getZoomSizeServer(); |
---|
1829 | |
---|
1830 | std::vector<StdSize> start, count; |
---|
1831 | |
---|
1832 | if (field->getUseCompressedOutput()) |
---|
1833 | { |
---|
1834 | if (grid->isCompressible()) |
---|
1835 | { |
---|
1836 | start.push_back(grid->getOffsetWrittenIndexes()); |
---|
1837 | count.push_back(grid->getNumberWrittenIndexes()); |
---|
1838 | } |
---|
1839 | else |
---|
1840 | { |
---|
1841 | CArray<bool,1> axisDomainOrder = grid->axis_domain_order; |
---|
1842 | std::vector<StdString> domainList = grid->getDomainList(); |
---|
1843 | std::vector<StdString> axisList = grid->getAxisList(); |
---|
1844 | int numElement = axisDomainOrder.numElements(); |
---|
1845 | int idxDomain = domainList.size() - 1, idxAxis = axisList.size() - 1; |
---|
1846 | int idx = nZoomBeginGlobal.size() - 1; |
---|
1847 | |
---|
1848 | start.reserve(nZoomBeginGlobal.size()); |
---|
1849 | count.reserve(nZoomBeginGlobal.size()); |
---|
1850 | |
---|
1851 | |
---|
1852 | for (int i = numElement - 1; i >= 0; --i) |
---|
1853 | { |
---|
1854 | if (axisDomainOrder(i)) |
---|
1855 | { |
---|
1856 | CDomain* domain = CDomain::get(domainList[idxDomain]); |
---|
1857 | |
---|
1858 | if (domain->isCompressible()) |
---|
1859 | { |
---|
1860 | start.push_back(domain->getOffsetWrittenIndexes()); |
---|
1861 | count.push_back(domain->getNumberWrittenIndexes()); |
---|
1862 | idx -= 2; |
---|
1863 | } |
---|
1864 | else |
---|
1865 | { |
---|
1866 | if ((domain->type) != CDomain::type_attr::unstructured) |
---|
1867 | { |
---|
1868 | start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]); |
---|
1869 | count.push_back(nZoomSizeServer[idx]); |
---|
1870 | } |
---|
1871 | --idx; |
---|
1872 | start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]); |
---|
1873 | count.push_back(nZoomSizeServer[idx]); |
---|
1874 | --idx; |
---|
1875 | } |
---|
1876 | --idxDomain; |
---|
1877 | } |
---|
1878 | else |
---|
1879 | { |
---|
1880 | CAxis* axis = CAxis::get(axisList[idxAxis]); |
---|
1881 | |
---|
1882 | if (axis->isCompressible()) |
---|
1883 | { |
---|
1884 | start.push_back(axis->getOffsetWrittenIndexes()); |
---|
1885 | count.push_back(axis->getNumberWrittenIndexes()); |
---|
1886 | } |
---|
1887 | else |
---|
1888 | { |
---|
1889 | start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]); |
---|
1890 | count.push_back(nZoomSizeServer[idx]); |
---|
1891 | } |
---|
1892 | |
---|
1893 | --idxAxis; |
---|
1894 | --idx; |
---|
1895 | } |
---|
1896 | } |
---|
1897 | } |
---|
1898 | } |
---|
1899 | else |
---|
1900 | { |
---|
1901 | |
---|
1902 | CArray<bool,1> axisDomainOrder = grid->axis_domain_order; |
---|
1903 | std::vector<StdString> domainList = grid->getDomainList(); |
---|
1904 | std::vector<StdString> axisList = grid->getAxisList(); |
---|
1905 | int numElement = axisDomainOrder.numElements(); |
---|
1906 | int idxDomain = domainList.size() - 1, idxAxis = axisList.size() - 1; |
---|
1907 | int idx = nZoomBeginGlobal.size() - 1; |
---|
1908 | |
---|
1909 | start.reserve(nZoomBeginGlobal.size()); |
---|
1910 | count.reserve(nZoomBeginGlobal.size()); |
---|
1911 | |
---|
1912 | for (int i = numElement - 1; i >= 0; --i) |
---|
1913 | { |
---|
1914 | if (axisDomainOrder(i)) |
---|
1915 | { |
---|
1916 | CDomain* domain = CDomain::get(domainList[idxDomain]); |
---|
1917 | if ((domain->type) != CDomain::type_attr::unstructured) |
---|
1918 | { |
---|
1919 | start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]); |
---|
1920 | count.push_back(nZoomSizeServer[idx]); |
---|
1921 | } |
---|
1922 | --idx ; |
---|
1923 | start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]); |
---|
1924 | count.push_back(nZoomSizeServer[idx]); |
---|
1925 | --idx ; |
---|
1926 | --idxDomain; |
---|
1927 | } |
---|
1928 | else |
---|
1929 | { |
---|
1930 | start.push_back(nZoomBeginServer[idx] - nZoomBeginGlobal[idx]); |
---|
1931 | count.push_back(nZoomSizeServer[idx]); |
---|
1932 | --idx; |
---|
1933 | } |
---|
1934 | } |
---|
1935 | } |
---|
1936 | |
---|
1937 | SuperClassWriter::writeData(fieldData, fieldid, isCollective, field->getNStep() - 1, &start, &count); |
---|
1938 | if (wtime) |
---|
1939 | { |
---|
1940 | SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep() - 1, isRoot); |
---|
1941 | SuperClassWriter::writeTimeAxisData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1, isRoot); |
---|
1942 | if (field->file->time_counter != CFile::time_counter_attr::none) |
---|
1943 | { |
---|
1944 | SuperClassWriter::writeTimeAxisData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1, isRoot); |
---|
1945 | if (field->file->time_counter != CFile::time_counter_attr::record) |
---|
1946 | SuperClassWriter::writeTimeAxisData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1, isRoot); |
---|
1947 | } |
---|
1948 | } |
---|
1949 | |
---|
1950 | break; |
---|
1951 | } |
---|
1952 | } |
---|
1953 | } |
---|
1954 | catch (CNetCdfException& e) |
---|
1955 | { |
---|
1956 | StdString msg("On writing field data: "); |
---|
1957 | msg.append(fieldid); msg.append("\n"); |
---|
1958 | msg.append("In the context : "); |
---|
1959 | msg.append(context->getId()); msg.append("\n"); |
---|
1960 | msg.append(e.what()); |
---|
1961 | ERROR("CNc4DataOutput::writeFieldData_ (CField* field)", << msg); |
---|
1962 | } |
---|
1963 | } |
---|
1964 | |
---|
1965 | //--------------------------------------------------------------- |
---|
1966 | |
---|
1967 | void CNc4DataOutput::writeTimeAxis_ |
---|
1968 | (CField* field, |
---|
1969 | const boost::shared_ptr<CCalendar> cal) |
---|
1970 | { |
---|
1971 | StdOStringStream oss; |
---|
1972 | |
---|
1973 | if (field->getOperationTimeType() == func::CFunctor::once) return ; |
---|
1974 | |
---|
1975 | // oss << "time_" << field->operation.getValue() |
---|
1976 | // << "_" << field->getRelFile()->output_freq.getValue(); |
---|
1977 | |
---|
1978 | // StdString axisid = oss.str(); |
---|
1979 | // if (field->getOperationTimeType() == func::CFunctor::centered) axisid="time_centered" ; |
---|
1980 | // else if (field->getOperationTimeType() == func::CFunctor::instant) axisid="time_instant" ; |
---|
1981 | |
---|
1982 | StdString axisid("time_centered") ; |
---|
1983 | StdString axisBoundId("time_centered_bounds"); |
---|
1984 | StdString timeid(getTimeCounterName()); |
---|
1985 | StdString timeBoundId("axis_nbounds"); |
---|
1986 | |
---|
1987 | if (field->getOperationTimeType() == func::CFunctor::instant) |
---|
1988 | { |
---|
1989 | axisid = "time_instant"; |
---|
1990 | axisBoundId = "time_instant_bounds"; |
---|
1991 | } |
---|
1992 | |
---|
1993 | try |
---|
1994 | { |
---|
1995 | // Adding time_instant or time_centered |
---|
1996 | std::vector<StdString> dims; |
---|
1997 | dims.push_back(timeid); |
---|
1998 | if (!SuperClassWriter::varExist(axisid)) |
---|
1999 | { |
---|
2000 | SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims); |
---|
2001 | |
---|
2002 | CDate timeOrigin=cal->getTimeOrigin() ; |
---|
2003 | StdOStringStream oss2; |
---|
2004 | // oss2<<initDate.getYear()<<"-"<<initDate.getMonth()<<"-"<<initDate.getDay()<<" " |
---|
2005 | // <<initDate.getHour()<<"-"<<initDate.getMinute()<<"-"<<initDate.getSecond() ; |
---|
2006 | StdString strInitdate=oss2.str() ; |
---|
2007 | StdString strTimeOrigin=timeOrigin.toString() ; |
---|
2008 | this->writeTimeAxisAttributes |
---|
2009 | (axisid, cal->getType(), |
---|
2010 | StdString("seconds since ").append(strTimeOrigin), |
---|
2011 | strTimeOrigin, axisBoundId); |
---|
2012 | } |
---|
2013 | |
---|
2014 | // Adding time_instant_bounds or time_centered_bounds variables |
---|
2015 | if (!SuperClassWriter::varExist(axisBoundId)) |
---|
2016 | { |
---|
2017 | dims.clear() ; |
---|
2018 | dims.push_back(timeid); |
---|
2019 | dims.push_back(timeBoundId); |
---|
2020 | SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims); |
---|
2021 | } |
---|
2022 | |
---|
2023 | if (field->file->time_counter != CFile::time_counter_attr::none) |
---|
2024 | { |
---|
2025 | // Adding time_counter |
---|
2026 | axisid = getTimeCounterName(); |
---|
2027 | axisBoundId = getTimeCounterName() + "_bounds"; |
---|
2028 | dims.clear(); |
---|
2029 | dims.push_back(timeid); |
---|
2030 | if (!SuperClassWriter::varExist(axisid)) |
---|
2031 | { |
---|
2032 | SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims); |
---|
2033 | SuperClassWriter::addAttribute("axis", string("T"), &axisid); |
---|
2034 | |
---|
2035 | if (field->file->time_counter != CFile::time_counter_attr::record) |
---|
2036 | { |
---|
2037 | CDate timeOrigin = cal->getTimeOrigin(); |
---|
2038 | StdString strTimeOrigin = timeOrigin.toString(); |
---|
2039 | |
---|
2040 | this->writeTimeAxisAttributes(axisid, cal->getType(), |
---|
2041 | StdString("seconds since ").append(strTimeOrigin), |
---|
2042 | strTimeOrigin, axisBoundId); |
---|
2043 | } |
---|
2044 | } |
---|
2045 | |
---|
2046 | // Adding time_counter_bound dimension |
---|
2047 | if (field->file->time_counter != CFile::time_counter_attr::record) |
---|
2048 | { |
---|
2049 | if (!SuperClassWriter::varExist(axisBoundId)) |
---|
2050 | { |
---|
2051 | dims.clear(); |
---|
2052 | dims.push_back(timeid); |
---|
2053 | dims.push_back(timeBoundId); |
---|
2054 | SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims); |
---|
2055 | } |
---|
2056 | } |
---|
2057 | } |
---|
2058 | } |
---|
2059 | catch (CNetCdfException& e) |
---|
2060 | { |
---|
2061 | StdString msg("On writing time axis data: "); |
---|
2062 | msg.append("In the context : "); |
---|
2063 | CContext* context = CContext::getCurrent() ; |
---|
2064 | msg.append(context->getId()); msg.append("\n"); |
---|
2065 | msg.append(e.what()); |
---|
2066 | ERROR("CNc4DataOutput::writeTimeAxis_ (CField* field, \ |
---|
2067 | const boost::shared_ptr<CCalendar> cal)", << msg); |
---|
2068 | } |
---|
2069 | } |
---|
2070 | |
---|
2071 | //--------------------------------------------------------------- |
---|
2072 | |
---|
2073 | void CNc4DataOutput::writeTimeAxisAttributes(const StdString & axis_name, |
---|
2074 | const StdString & calendar, |
---|
2075 | const StdString & units, |
---|
2076 | const StdString & time_origin, |
---|
2077 | const StdString & time_bounds, |
---|
2078 | const StdString & standard_name, |
---|
2079 | const StdString & long_name) |
---|
2080 | { |
---|
2081 | try |
---|
2082 | { |
---|
2083 | SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name); |
---|
2084 | SuperClassWriter::addAttribute("long_name", long_name , &axis_name); |
---|
2085 | SuperClassWriter::addAttribute("calendar", calendar , &axis_name); |
---|
2086 | SuperClassWriter::addAttribute("units", units , &axis_name); |
---|
2087 | SuperClassWriter::addAttribute("time_origin", time_origin , &axis_name); |
---|
2088 | SuperClassWriter::addAttribute("bounds", time_bounds , &axis_name); |
---|
2089 | } |
---|
2090 | catch (CNetCdfException& e) |
---|
2091 | { |
---|
2092 | StdString msg("On writing time axis Attribute: "); |
---|
2093 | msg.append("In the context : "); |
---|
2094 | CContext* context = CContext::getCurrent() ; |
---|
2095 | msg.append(context->getId()); msg.append("\n"); |
---|
2096 | msg.append(e.what()); |
---|
2097 | ERROR("CNc4DataOutput::writeTimeAxisAttributes(const StdString & axis_name, \ |
---|
2098 | const StdString & calendar,\ |
---|
2099 | const StdString & units, \ |
---|
2100 | const StdString & time_origin, \ |
---|
2101 | const StdString & time_bounds, \ |
---|
2102 | const StdString & standard_name, \ |
---|
2103 | const StdString & long_name)", << msg); |
---|
2104 | } |
---|
2105 | } |
---|
2106 | |
---|
2107 | //--------------------------------------------------------------- |
---|
2108 | |
---|
2109 | void CNc4DataOutput::writeAxisAttributes(const StdString & axis_name, |
---|
2110 | const StdString & axis, |
---|
2111 | const StdString & standard_name, |
---|
2112 | const StdString & long_name, |
---|
2113 | const StdString & units, |
---|
2114 | const StdString & nav_model) |
---|
2115 | { |
---|
2116 | try |
---|
2117 | { |
---|
2118 | if (!axis.empty()) |
---|
2119 | SuperClassWriter::addAttribute("axis" , axis , &axis_name); |
---|
2120 | |
---|
2121 | SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name); |
---|
2122 | SuperClassWriter::addAttribute("long_name" , long_name , &axis_name); |
---|
2123 | SuperClassWriter::addAttribute("units" , units , &axis_name); |
---|
2124 | SuperClassWriter::addAttribute("nav_model" , nav_model , &axis_name); |
---|
2125 | } |
---|
2126 | catch (CNetCdfException& e) |
---|
2127 | { |
---|
2128 | StdString msg("On writing Axis Attribute: "); |
---|
2129 | msg.append("In the context : "); |
---|
2130 | CContext* context = CContext::getCurrent() ; |
---|
2131 | msg.append(context->getId()); msg.append("\n"); |
---|
2132 | msg.append(e.what()); |
---|
2133 | ERROR("CNc4DataOutput::writeAxisAttributes(const StdString & axis_name, \ |
---|
2134 | const StdString & axis, \ |
---|
2135 | const StdString & standard_name, \ |
---|
2136 | const StdString & long_name, \ |
---|
2137 | const StdString & units, \ |
---|
2138 | const StdString & nav_model)", << msg); |
---|
2139 | } |
---|
2140 | } |
---|
2141 | |
---|
2142 | //--------------------------------------------------------------- |
---|
2143 | |
---|
2144 | void CNc4DataOutput::writeLocalAttributes |
---|
2145 | (int ibegin, int ni, int jbegin, int nj, StdString domid) |
---|
2146 | { |
---|
2147 | try |
---|
2148 | { |
---|
2149 | SuperClassWriter::addAttribute(StdString("ibegin").append(domid), ibegin); |
---|
2150 | SuperClassWriter::addAttribute(StdString("ni" ).append(domid), ni); |
---|
2151 | SuperClassWriter::addAttribute(StdString("jbegin").append(domid), jbegin); |
---|
2152 | SuperClassWriter::addAttribute(StdString("nj" ).append(domid), nj); |
---|
2153 | } |
---|
2154 | catch (CNetCdfException& e) |
---|
2155 | { |
---|
2156 | StdString msg("On writing Local Attributes: "); |
---|
2157 | msg.append("In the context : "); |
---|
2158 | CContext* context = CContext::getCurrent() ; |
---|
2159 | msg.append(context->getId()); msg.append("\n"); |
---|
2160 | msg.append(e.what()); |
---|
2161 | ERROR("CNc4DataOutput::writeLocalAttributes \ |
---|
2162 | (int ibegin, int ni, int jbegin, int nj, StdString domid)", << msg); |
---|
2163 | } |
---|
2164 | |
---|
2165 | } |
---|
2166 | |
---|
2167 | void CNc4DataOutput::writeLocalAttributes_IOIPSL(const StdString& dimXid, const StdString& dimYid, |
---|
2168 | int ibegin, int ni, int jbegin, int nj, int ni_glo, int nj_glo, int rank, int size) |
---|
2169 | { |
---|
2170 | CArray<int,1> array(2) ; |
---|
2171 | |
---|
2172 | try |
---|
2173 | { |
---|
2174 | SuperClassWriter::addAttribute("DOMAIN_number_total",size ) ; |
---|
2175 | SuperClassWriter::addAttribute("DOMAIN_number", rank) ; |
---|
2176 | array = SuperClassWriter::getDimension(dimXid) + 1, SuperClassWriter::getDimension(dimYid) + 1; |
---|
2177 | SuperClassWriter::addAttribute("DOMAIN_dimensions_ids",array) ; |
---|
2178 | array=ni_glo,nj_glo ; |
---|
2179 | SuperClassWriter::addAttribute("DOMAIN_size_global", array) ; |
---|
2180 | array=ni,nj ; |
---|
2181 | SuperClassWriter::addAttribute("DOMAIN_size_local", array) ; |
---|
2182 | array=ibegin+1,jbegin+1 ; |
---|
2183 | SuperClassWriter::addAttribute("DOMAIN_position_first", array) ; |
---|
2184 | array=ibegin+ni-1+1,jbegin+nj-1+1 ; |
---|
2185 | SuperClassWriter::addAttribute("DOMAIN_position_last",array) ; |
---|
2186 | array=0,0 ; |
---|
2187 | SuperClassWriter::addAttribute("DOMAIN_halo_size_start", array) ; |
---|
2188 | SuperClassWriter::addAttribute("DOMAIN_halo_size_end", array); |
---|
2189 | SuperClassWriter::addAttribute("DOMAIN_type",string("box")) ; |
---|
2190 | /* |
---|
2191 | SuperClassWriter::addAttribute("DOMAIN_DIM_N001",string("x")) ; |
---|
2192 | SuperClassWriter::addAttribute("DOMAIN_DIM_N002",string("y")) ; |
---|
2193 | SuperClassWriter::addAttribute("DOMAIN_DIM_N003",string("axis_A")) ; |
---|
2194 | SuperClassWriter::addAttribute("DOMAIN_DIM_N004",string("time_counter")) ; |
---|
2195 | */ |
---|
2196 | } |
---|
2197 | catch (CNetCdfException& e) |
---|
2198 | { |
---|
2199 | StdString msg("On writing Local Attributes IOIPSL \n"); |
---|
2200 | msg.append("In the context : "); |
---|
2201 | CContext* context = CContext::getCurrent() ; |
---|
2202 | msg.append(context->getId()); msg.append("\n"); |
---|
2203 | msg.append(e.what()); |
---|
2204 | ERROR("CNc4DataOutput::writeLocalAttributes_IOIPSL \ |
---|
2205 | (int ibegin, int ni, int jbegin, int nj, int ni_glo, int nj_glo, int rank, int size)", << msg); |
---|
2206 | } |
---|
2207 | } |
---|
2208 | //--------------------------------------------------------------- |
---|
2209 | |
---|
2210 | void CNc4DataOutput:: writeFileAttributes(const StdString & name, |
---|
2211 | const StdString & description, |
---|
2212 | const StdString & conventions, |
---|
2213 | const StdString & production, |
---|
2214 | const StdString & timeStamp) |
---|
2215 | { |
---|
2216 | try |
---|
2217 | { |
---|
2218 | SuperClassWriter::addAttribute("name" , name); |
---|
2219 | SuperClassWriter::addAttribute("description", description); |
---|
2220 | SuperClassWriter::addAttribute("title" , description); |
---|
2221 | SuperClassWriter::addAttribute("Conventions", conventions); |
---|
2222 | SuperClassWriter::addAttribute("production" , production); |
---|
2223 | SuperClassWriter::addAttribute("timeStamp" , timeStamp); |
---|
2224 | } |
---|
2225 | catch (CNetCdfException& e) |
---|
2226 | { |
---|
2227 | StdString msg("On writing File Attributes \n "); |
---|
2228 | msg.append("In the context : "); |
---|
2229 | CContext* context = CContext::getCurrent() ; |
---|
2230 | msg.append(context->getId()); msg.append("\n"); |
---|
2231 | msg.append(e.what()); |
---|
2232 | ERROR("CNc4DataOutput:: writeFileAttributes(const StdString & name, \ |
---|
2233 | const StdString & description, \ |
---|
2234 | const StdString & conventions, \ |
---|
2235 | const StdString & production, \ |
---|
2236 | const StdString & timeStamp)", << msg); |
---|
2237 | } |
---|
2238 | } |
---|
2239 | |
---|
2240 | //--------------------------------------------------------------- |
---|
2241 | |
---|
2242 | void CNc4DataOutput::writeMaskAttributes(const StdString & mask_name, |
---|
2243 | int data_dim, |
---|
2244 | int data_ni, |
---|
2245 | int data_nj, |
---|
2246 | int data_ibegin, |
---|
2247 | int data_jbegin) |
---|
2248 | { |
---|
2249 | try |
---|
2250 | { |
---|
2251 | SuperClassWriter::addAttribute("data_dim" , data_dim , &mask_name); |
---|
2252 | SuperClassWriter::addAttribute("data_ni" , data_ni , &mask_name); |
---|
2253 | SuperClassWriter::addAttribute("data_nj" , data_nj , &mask_name); |
---|
2254 | SuperClassWriter::addAttribute("data_ibegin", data_ibegin, &mask_name); |
---|
2255 | SuperClassWriter::addAttribute("data_jbegin", data_jbegin, &mask_name); |
---|
2256 | } |
---|
2257 | catch (CNetCdfException& e) |
---|
2258 | { |
---|
2259 | StdString msg("On writing Mask Attributes \n "); |
---|
2260 | msg.append("In the context : "); |
---|
2261 | CContext* context = CContext::getCurrent() ; |
---|
2262 | msg.append(context->getId()); msg.append("\n"); |
---|
2263 | msg.append(e.what()); |
---|
2264 | ERROR("CNc4DataOutput::writeMaskAttributes(const StdString & mask_name, \ |
---|
2265 | int data_dim, \ |
---|
2266 | int data_ni, \ |
---|
2267 | int data_nj, \ |
---|
2268 | int data_ibegin, \ |
---|
2269 | int data_jbegin)", << msg); |
---|
2270 | } |
---|
2271 | } |
---|
2272 | |
---|
2273 | ///-------------------------------------------------------------- |
---|
2274 | |
---|
2275 | StdSize CNc4DataOutput::getRecordFromTime(Time time) |
---|
2276 | { |
---|
2277 | std::map<Time, StdSize>::const_iterator it = timeToRecordCache.find(time); |
---|
2278 | if (it == timeToRecordCache.end()) |
---|
2279 | { |
---|
2280 | StdString timeAxisBoundsId(getTimeCounterName() + "_bounds"); |
---|
2281 | if (!SuperClassWriter::varExist(timeAxisBoundsId)) |
---|
2282 | timeAxisBoundsId = "time_instant_bounds"; |
---|
2283 | |
---|
2284 | CArray<double,2> timeAxisBounds; |
---|
2285 | SuperClassWriter::getTimeAxisBounds(timeAxisBounds, timeAxisBoundsId, isCollective); |
---|
2286 | |
---|
2287 | StdSize record = 0; |
---|
2288 | double dtime(time); |
---|
2289 | for (int n = timeAxisBounds.extent(1) - 1; n >= 0; n--) |
---|
2290 | { |
---|
2291 | if (timeAxisBounds(1, n) < dtime) |
---|
2292 | { |
---|
2293 | record = n + 1; |
---|
2294 | break; |
---|
2295 | } |
---|
2296 | } |
---|
2297 | it = timeToRecordCache.insert(std::make_pair(time, record)).first; |
---|
2298 | } |
---|
2299 | return it->second; |
---|
2300 | } |
---|
2301 | |
---|
2302 | ///-------------------------------------------------------------- |
---|
2303 | |
---|
2304 | bool CNc4DataOutput::isWrittenDomain(const std::string& domainName) const |
---|
2305 | { |
---|
2306 | return (this->writtenDomains.find(domainName) != this->writtenDomains.end()); |
---|
2307 | } |
---|
2308 | |
---|
2309 | bool CNc4DataOutput::isWrittenCompressedDomain(const std::string& domainName) const |
---|
2310 | { |
---|
2311 | return (this->writtenCompressedDomains.find(domainName) != this->writtenCompressedDomains.end()); |
---|
2312 | } |
---|
2313 | |
---|
2314 | bool CNc4DataOutput::isWrittenAxis(const std::string& axisName) const |
---|
2315 | { |
---|
2316 | return (this->writtenAxis.find(axisName) != this->writtenAxis.end()); |
---|
2317 | } |
---|
2318 | |
---|
2319 | bool CNc4DataOutput::isWrittenCompressedAxis(const std::string& axisName) const |
---|
2320 | { |
---|
2321 | return (this->writtenCompressedAxis.find(axisName) != this->writtenCompressedAxis.end()); |
---|
2322 | } |
---|
2323 | |
---|
2324 | void CNc4DataOutput::setWrittenDomain(const std::string& domainName) |
---|
2325 | { |
---|
2326 | this->writtenDomains.insert(domainName); |
---|
2327 | } |
---|
2328 | |
---|
2329 | void CNc4DataOutput::setWrittenCompressedDomain(const std::string& domainName) |
---|
2330 | { |
---|
2331 | this->writtenCompressedDomains.insert(domainName); |
---|
2332 | } |
---|
2333 | |
---|
2334 | void CNc4DataOutput::setWrittenAxis(const std::string& axisName) |
---|
2335 | { |
---|
2336 | this->writtenAxis.insert(axisName); |
---|
2337 | } |
---|
2338 | |
---|
2339 | void CNc4DataOutput::setWrittenCompressedAxis(const std::string& axisName) |
---|
2340 | { |
---|
2341 | this->writtenCompressedAxis.insert(axisName); |
---|
2342 | } |
---|
2343 | } // namespace xios |
---|