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