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