Skip to content

Commit

Permalink
EXODUS: Fixing group usage
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsjaar committed Oct 3, 2024
1 parent a980da1 commit b909160
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions packages/seacas/libraries/exodus/src/ex_copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ int ex_copy_transient(int in_exoid, int out_exoid)
static int cpy_variable_data(int in_exoid, int out_exoid, int in_large, int mesh_only)
{
int nvars; /* number of variables */
/* NOTE: This is incorrect for files containing groups */
EXCHECKI(nc_inq(in_exoid, NULL, &nvars, NULL, NULL));
for (int varid = 0; varid < nvars; varid++) {
bool is_filtered;
Expand Down Expand Up @@ -216,6 +217,7 @@ static int cpy_variables(int in_exoid, int out_exoid, int in_large, int mesh_onl
{
int recdimid; /* id of unlimited dimension */
int nvars; /* number of variables */
/* NOTE: This is incorrect for files containing groups */
EXCHECKI(nc_inq(in_exoid, NULL, &nvars, NULL, &recdimid));
for (int varid = 0; varid < nvars; varid++) {
struct ncvar var; /* variable */
Expand Down Expand Up @@ -259,6 +261,7 @@ static int cpy_dimension(int in_exoid, int out_exoid, int mesh_only)

int ndims; /* number of dimensions */
int recdimid; /* id of unlimited dimension */
/* NOTE: This is incorrect for files containing groups */
EXCHECKI(nc_inq(in_exoid, &ndims, NULL, NULL, &recdimid));
for (int dimid = 0; dimid < ndims; dimid++) {

Expand Down Expand Up @@ -344,6 +347,7 @@ static int cpy_global_att(int in_exoid, int out_exoid)
struct ncatt att; /* attribute */

int ngatts;
/* NOTE: This is incorrect for files containing groups */
EXCHECKI(nc_inq(in_exoid, NULL, NULL, &ngatts, NULL));

/* copy global attributes */
Expand Down
6 changes: 5 additions & 1 deletion packages/seacas/libraries/exodus/src/ex_get_group_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,20 @@ int ex_get_group_id(int parent_id, const char *group_name, int *group_id)
"group in file id %d",
group_name, parent_id);
ex_err_fn(parent_id, __func__, errmsg, status);
*group_id = 0;
EX_FUNC_LEAVE(EX_FATAL);
}
}
else {
/* Full path name */
int status = nc_inq_grp_full_ncid(parent_id, group_name, group_id);
int rootid = parent_id & EX_FILE_ID_MASK;
int status = nc_inq_grp_full_ncid(rootid, group_name, group_id);
if (status != NC_NOERR) {
snprintf(errmsg, MAX_ERR_LENGTH,
"ERROR: Failed to locate group with full path name %s in file id %d", group_name,
parent_id);
ex_err_fn(parent_id, __func__, errmsg, status);
*group_id = 0;
EX_FUNC_LEAVE(EX_FATAL);
}
}
Expand All @@ -64,6 +67,7 @@ int ex_get_group_id(int parent_id, const char *group_name, int *group_id)
"ERROR: Group capabilities are not available in this netcdf "
"version--not netcdf4");
ex_err_fn(parent_id, __func__, errmsg, NC_ENOTNC4);
*group_id = 0;
EX_FUNC_LEAVE(EX_FATAL);
#endif
}
10 changes: 7 additions & 3 deletions packages/seacas/libraries/exodus/src/ex_get_init_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@

static void exi_get_entity_count(int exoid, ex_init_params *info)
{
int ndims;
int include_parent_group = 1;
int include_parent_group = 0; // Only want dims in current group
int ndims = 0;
nc_inq_dimids(exoid, &ndims, NULL, include_parent_group);
int *dimids = calloc(ndims, sizeof(int));
nc_inq_dimids(exoid, &ndims, dimids, include_parent_group);

for (int dimid = 0; dimid < ndims; dimid++) {
char dim_nm[NC_MAX_NAME + 1] = {'\0'};
size_t dim_sz;
nc_inq_dim(exoid, dimid, dim_nm, &dim_sz);
nc_inq_dim(exoid, dimids[dimid], dim_nm, &dim_sz);
/* For assemblies, we check for a dim starting with "num_entity_assembly" */
if (strncmp(dim_nm, "num_entity_assembly", 19) == 0) {
info->num_assembly++;
Expand All @@ -41,6 +44,7 @@ static void exi_get_entity_count(int exoid, ex_init_params *info)
info->num_blob++;
}
}
free(dimids);
}

/* Used to reduce repeated code below */
Expand Down
5 changes: 3 additions & 2 deletions packages/seacas/libraries/ioss/src/main/io_shell.C
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,12 @@ namespace {
}

if (!interFace.groupName.empty()) {
bool success = dbi->open_group(interFace.groupName);
std::string group_path = "/" + interFace.groupName;
bool success = dbi->open_group(group_path);
if (!success) {
if (rank == 0) {
fmt::print(stderr, "ERROR: Unable to open group '{}' in file '{}'\n",
interFace.groupName, inpfile);
group_path, inpfile);
}
return;
}
Expand Down

0 comments on commit b909160

Please sign in to comment.