Skip to content

Commit

Permalink
Per #2152, add logic to add the coordinates variable attributes to gr…
Browse files Browse the repository at this point in the history
…idded NetCDF variables that contain both the lat and lon dimensions but not for the lat and lon variables themselves.
  • Loading branch information
JohnHalleyGotway committed May 5, 2022
1 parent 82b0c86 commit d145d1b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions met/src/libcode/vx_nc_util/nc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ using namespace netCDF::exceptions;

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

void patch_nc_name(string *var_name) {
size_t offset;

Expand Down Expand Up @@ -3216,6 +3214,26 @@ NcVar add_var(NcFile *nc, const string &var_name, const NcType ncType,
mlog << Debug(3) << " nc_utils.add_var() deflate_level: " << deflate_level << "\n";
var.setCompression(false, true, deflate_level);
}

// Check for lat and lon dimensions
ConcatString cs;
bool has_lat_dim, has_lon_dim;
vector<NcDim>::const_iterator itDim;
for (itDim = ncDims.begin(), has_lat_dim = has_lon_dim = false;
itDim != ncDims.end(); ++itDim) {
if (itDim->getName() == "lat") has_lat_dim = true;
else if (itDim->getName() == "lon") has_lon_dim = true;
if (itDim != ncDims.begin()) cs << " ";
cs << itDim->getName();
}

// Add the coordinates variable attribute for variables
// with both lat and lon dimensions
if (has_lat_dim && var_name != "lat" &&
has_lon_dim && var_name != "lon") {
add_att(&var, "coordinates", cs.c_str());
}

return var;
}

Expand Down

0 comments on commit d145d1b

Please sign in to comment.