| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020, 2024, 2024 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "exodusII.h" // for ex_err, etc |
| 10 |
#include "exodusII_int.h" // for EX_FATAL, EX_FILE_ID_MASK, etc |
| 11 |
|
| 12 |
/** |
| 13 |
* \ingroup Utilities |
| 14 |
* Given an exoid and group name (NULL gets root group), return id of that |
| 15 |
* group. |
| 16 |
* If the name is NULL, return the root group. |
| 17 |
* If the name contains "/", then the name is assumed to be a full path name |
| 18 |
* and all groups in the file are searched. |
| 19 |
* Otherwise, the name is assumed to be the name of a child group of exoid |
| 20 |
*/ |
| 21 |
int ex_get_group_id(int parent_id, const char *group_name, int *group_id) |
| 22 |
{ |
| 23 |
char errmsg[MAX_ERR_LENGTH]; |
| 24 |
#if NC_HAS_HDF5 |
| 25 |
EX_FUNC_ENTER(); |
| 26 |
/* If the `group_name` is NULL, or is the single character '/', then |
| 27 |
* return the root id. |
| 28 |
*/ |
| 29 |
if (group_name == NULL || (group_name[0] == '/' && group_name[1] == '\0')) { |
| 30 |
/* Return root */ |
| 31 |
*group_id = (unsigned)parent_id & EX_FILE_ID_MASK; |
| 32 |
} |
| 33 |
/* If the name does not start with "/" then it is a relative name from current location... */ |
| 34 |
else if (group_name[0] != '/') { |
| 35 |
/* Local child */ |
| 36 |
int status = nc_inq_grp_ncid(parent_id, group_name, group_id); |
| 37 |
if (status != NC_NOERR) { |
| 38 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 39 |
"ERROR: Failed to locate group with name %s as child " |
| 40 |
"group in file id %d", |
| 41 |
group_name, parent_id); |
| 42 |
ex_err_fn(parent_id, __func__, errmsg, status); |
| 43 |
*group_id = 0; |
| 44 |
EX_FUNC_LEAVE(EX_FATAL); |
| 45 |
} |
| 46 |
} |
| 47 |
else { |
| 48 |
/* Full path name */ |
| 49 |
int rootid = parent_id & EX_FILE_ID_MASK; |
| 50 |
int status = nc_inq_grp_full_ncid(rootid, group_name, group_id); |
| 51 |
if (status != NC_NOERR) { |
| 52 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 53 |
"ERROR: Failed to locate group with full path name %s in file id %d", group_name, |
| 54 |
parent_id); |
| 55 |
ex_err_fn(parent_id, __func__, errmsg, status); |
| 56 |
*group_id = 0; |
| 57 |
EX_FUNC_LEAVE(EX_FATAL); |
| 58 |
} |
| 59 |
} |
| 60 |
EX_FUNC_LEAVE(EX_NOERR); |
| 61 |
#else |
| 62 |
EX_UNUSED(parent_id); |
| 63 |
EX_UNUSED(group_name); |
| 64 |
EX_UNUSED(group_id); |
| 65 |
EX_FUNC_ENTER(); |
| 66 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 67 |
"ERROR: Group capabilities are not available in this netcdf " |
| 68 |
"version--not netcdf4"); |
| 69 |
ex_err_fn(parent_id, __func__, errmsg, NC_ENOTNC4); |
| 70 |
*group_id = 0; |
| 71 |
EX_FUNC_LEAVE(EX_FATAL); |
| 72 |
#endif |
| 73 |
} |