MCPcopy Create free account
hub / github.com/boutproject/BOUT-dev / writeGroup

Function writeGroup

src/sys/options/options_netcdf.cxx:448–606  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446}
447
448void writeGroup(const Options& options, NcGroup group,
449 const std::string& time_dimension) {
450
451 for (const auto& childpair : options.getChildren()) {
452 const auto& name = childpair.first;
453 const auto& child = childpair.second;
454
455 if (child.isValue()) {
456 try {
457 auto nctype = bout::utils::visit(NcTypeVisitor(), child.value);
458
459 if (nctype.isNull()) {
460 continue; // Skip this value
461 }
462
463 // Get spatial dimensions
464 auto spatial_dims = bout::utils::visit(NcDimVisitor(group), child.value);
465
466 // Vector of all dimensions, including time
467 std::vector<NcDim> dims{spatial_dims};
468
469 // Get the time dimension
470 NcDim time_dim; ///< Time dimension (Null -> none)
471 auto time_it = child.attributes.find("time_dimension");
472 if (time_it != child.attributes.end()) {
473 // Has a time dimension
474
475 const auto& time_name = bout::utils::get<std::string>(time_it->second);
476
477 // Only write time-varying values that match current time
478 // dimension being written
479 if (time_name != time_dimension) {
480 continue;
481 }
482
483 time_dim = group.getDim(time_name, NcGroup::ParentsAndCurrent);
484 if (time_dim.isNull()) {
485 time_dim = group.addDim(time_name);
486 }
487
488 // prepend to vector of dimensions
489 dims.insert(dims.begin(), time_dim);
490 }
491
492 // Check if the variable exists
493 auto var = group.getVar(name);
494 if (var.isNull()) {
495 // Variable doesn't exist yet
496 // Create variable
497 // Temporary NcType as a workaround for bug in NetCDF 4.4.0 and
498 // NetCDF-CXX4 4.2.0
499 var = group.addVar(name, NcType{group, nctype.getId()}, dims);
500 if (!time_dim.isNull()) {
501 // Time evolving variable, so we'll need to keep track of its time index
502 var.putAtt(current_time_index_name, ncInt, 0);
503 }
504 } else {
505 // Variable does exist

Callers 1

writeMethod · 0.70

Calls 8

NcTypeVisitorClass · 0.85
NcDimVisitorClass · 0.85
NcPutVarVisitorClass · 0.85
getCurrentTimeIndexFunction · 0.85
NcPutAttVisitorClass · 0.85
isSectionMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected