Skip to content

Commit

Permalink
#1815 Added find_var_by_dim_name
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Soh committed Jul 1, 2022
1 parent 8e9d91c commit f051bab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
41 changes: 33 additions & 8 deletions src/libcode/vx_data2d_nccf/nccf_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -451,20 +451,24 @@ bool NcCfFile::open(const char * filepath)
Var[j].t_slot = k;
}
else if (dim_count == max_dim_count) {
Var[j].z_slot = k;
if (0 == z_dim_name.length()) z_dim_name = dimNames[k];
NcVarInfo *info = find_var_by_dim_name(c.c_str());
if (info) {
if (is_nc_unit_time(info->units_att.c_str())) {
Var[j].t_slot = k;
}
else {
Var[j].z_slot = k;
if (0 == z_dim_name.length()) z_dim_name = dimNames[k];
}
}
}
}
} // for j

// Find the vertical level variable from dimension name if not found
if (IS_INVALID_NC_P(z_var) && (0 < z_dim_name.length())) {
for (int j=0; j<Nvars; ++j) {
if (Var[j].name == z_dim_name) {
z_var = Var[j].var;
break;
}
} // for j
NcVarInfo *info = find_var_by_dim_name(z_dim_name.c_str());
if (info) z_var = info->var;
}

// Pull out the vertical levels
Expand Down Expand Up @@ -1149,6 +1153,27 @@ NcVarInfo* NcCfFile::find_var_name(const char * var_name) const
////////////////////////////////////////////////////////////////////////


NcVarInfo* NcCfFile::find_var_by_dim_name(const char *dim_name) const
{
NcVarInfo *var = find_var_name(dim_name);
if (!var) {
for (int i = 0; i < Nvars; i++) {
if (1 == Var[i].Ndims) {
if (GET_NC_NAME_P(Var[i].Dims[0]) == dim_name) {
var = &Var[i];
break;
}
}
}
}

return var;
}


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


void NcCfFile::read_netcdf_grid()
{
// Loop through the variables looking for the first gridded variable. We
Expand Down
1 change: 1 addition & 0 deletions src/libcode/vx_data2d_nccf/nccf_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class NcCfFile {
bool getData(const char *, const LongArray &, DataPlane &, NcVarInfo *&) const;

NcVarInfo* find_var_name(const char * var_name) const;
NcVarInfo* find_var_by_dim_name(const char *dim_name) const;

private:

Expand Down

0 comments on commit f051bab

Please sign in to comment.