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