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