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