| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020 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 |
* |
| 10 |
* exgpa - ex_get_prop_array: read object property array |
| 11 |
* |
| 12 |
* entry conditions - |
| 13 |
* input parameters: |
| 14 |
* int exoid exodus file id |
| 15 |
* int obj_type type of object (element block, node |
| 16 |
* set or side set) |
| 17 |
* char* prop_name name of the property for which the |
| 18 |
* values will be read |
| 19 |
* |
| 20 |
* exit conditions - |
| 21 |
* int* values returned array of property values |
| 22 |
* |
| 23 |
* revision history - |
| 24 |
* |
| 25 |
* |
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
#include "exodusII.h" // for ex_err, etc |
| 29 |
#include "exodusII_int.h" // for EX_FATAL, ATT_PROP_NAME, etc |
| 30 |
#include <stdbool.h> |
| 31 |
|
| 32 |
/*! |
| 33 |
|
| 34 |
The function ex_get_prop_array() reads an array of integer property |
| 35 |
values for all element blocks, node sets, or side sets. The order of |
| 36 |
the values in the array correspond to the order in which the element |
| 37 |
blocks, node sets, or side sets were introduced into the file. Before |
| 38 |
this function is invoked, memory must be allocated for the returned |
| 39 |
array of(num_elem_blk, num_node_sets, or {num_side_sets}) |
| 40 |
integer values. |
| 41 |
|
| 42 |
This function can be used in place of |
| 43 |
- ex_get_elem_blk_ids(), |
| 44 |
- ex_get_node_set_ids(), and |
| 45 |
- ex_get_side_set_ids() |
| 46 |
to get element block, node set, and side set IDs, respectively, by |
| 47 |
requesting the property name \b ID. One should also note that this |
| 48 |
same function can be accomplished with multiple calls to |
| 49 |
ex_get_prop(). |
| 50 |
|
| 51 |
\return In case of an error, ex_get_prop_array() returns a negative |
| 52 |
number; a warning will return a positive number. Possible causes of |
| 53 |
errors include: |
| 54 |
- data file not properly opened with call to ex_create() or ex_open() |
| 55 |
- invalid object type specified. |
| 56 |
- a warning value is returned if a property with the specified name is not |
| 57 |
found. |
| 58 |
|
| 59 |
\param[in] exoid exodus file ID returned from a previous call to |
| 60 |
ex_create() or ex_open(). |
| 61 |
\param[in] obj_type Type of object; use one of the options in the table |
| 62 |
below. |
| 63 |
\param[in] prop_name The name of the property (maximum length of \p |
| 64 |
MAX_STR_LENGTH ) |
| 65 |
for which the values are desired. |
| 66 |
\param[out] values Returned array of property values. |
| 67 |
|
| 68 |
| #ex_entity_type | description | |
| 69 |
| -------------- | ------------------------- | |
| 70 |
| #EX_NODE_SET | Node Set entity type | |
| 71 |
| #EX_EDGE_BLOCK | Edge Block entity type | |
| 72 |
| #EX_EDGE_SET | Edge Set entity type | |
| 73 |
| #EX_FACE_BLOCK | Face Block entity type | |
| 74 |
| #EX_FACE_SET | Face Set entity type | |
| 75 |
| #EX_ELEM_BLOCK | Element Block entity type| |
| 76 |
| #EX_ELEM_SET | Element Set entity type | |
| 77 |
| #EX_SIDE_SET | Side Set entity type | |
| 78 |
| #EX_ELEM_MAP | Element Map entity type | |
| 79 |
| #EX_NODE_MAP | Node Map entity type | |
| 80 |
| #EX_EDGE_MAP | Edge Map entity type | |
| 81 |
| #EX_FACE_MAP | Face Map entity type | |
| 82 |
|
| 83 |
For an example of code to read an array of object properties, refer to |
| 84 |
the description for ex_get_prop_names(). |
| 85 |
*/ |
| 86 |
|
| 87 |
int ex_get_prop_array(int exoid, ex_entity_type obj_type, const char *prop_name, void_int *values) |
| 88 |
{ |
| 89 |
int num_props, i, propid, status; |
| 90 |
int found = false; |
| 91 |
char *name; |
| 92 |
char tmpstr[MAX_STR_LENGTH + 1]; |
| 93 |
|
| 94 |
char errmsg[MAX_ERR_LENGTH]; |
| 95 |
|
| 96 |
EX_FUNC_ENTER(); |
| 97 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 98 |
EX_FUNC_LEAVE(EX_FATAL); |
| 99 |
} |
| 100 |
|
| 101 |
/* open appropriate variable, depending on obj_type and prop_name */ |
| 102 |
|
| 103 |
num_props = ex_get_num_props(exoid, obj_type); |
| 104 |
|
| 105 |
for (i = 1; i <= num_props; i++) { |
| 106 |
switch (obj_type) { |
| 107 |
case EX_ELEM_BLOCK: name = VAR_EB_PROP(i); break; |
| 108 |
case EX_EDGE_BLOCK: name = VAR_ED_PROP(i); break; |
| 109 |
case EX_FACE_BLOCK: name = VAR_FA_PROP(i); break; |
| 110 |
case EX_NODE_SET: name = VAR_NS_PROP(i); break; |
| 111 |
case EX_EDGE_SET: name = VAR_ES_PROP(i); break; |
| 112 |
case EX_FACE_SET: name = VAR_FS_PROP(i); break; |
| 113 |
case EX_ELEM_SET: name = VAR_ELS_PROP(i); break; |
| 114 |
case EX_SIDE_SET: name = VAR_SS_PROP(i); break; |
| 115 |
case EX_ELEM_MAP: name = VAR_EM_PROP(i); break; |
| 116 |
case EX_FACE_MAP: name = VAR_FAM_PROP(i); break; |
| 117 |
case EX_EDGE_MAP: name = VAR_EDM_PROP(i); break; |
| 118 |
case EX_NODE_MAP: name = VAR_NM_PROP(i); break; |
| 119 |
default: |
| 120 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: object type %d not supported; file id %d", obj_type, |
| 121 |
exoid); |
| 122 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 123 |
EX_FUNC_LEAVE(EX_FATAL); |
| 124 |
} |
| 125 |
|
| 126 |
if ((status = nc_inq_varid(exoid, name, &propid)) != NC_NOERR) { |
| 127 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate property array %s in file id %d", |
| 128 |
name, exoid); |
| 129 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 130 |
EX_FUNC_LEAVE(EX_FATAL); |
| 131 |
} |
| 132 |
|
| 133 |
/* compare stored attribute name with passed property name */ |
| 134 |
memset(tmpstr, 0, MAX_STR_LENGTH + 1); |
| 135 |
if ((status = nc_get_att_text(exoid, propid, ATT_PROP_NAME, tmpstr)) != NC_NOERR) { |
| 136 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get property name in file id %d", exoid); |
| 137 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 138 |
EX_FUNC_LEAVE(EX_FATAL); |
| 139 |
} |
| 140 |
|
| 141 |
if (strcmp(tmpstr, prop_name) == 0) { |
| 142 |
found = true; |
| 143 |
break; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
/* if property is not found, return warning */ |
| 148 |
if (!found) { |
| 149 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 150 |
"Warning: object type %d, property %s not defined in file id %d", obj_type, prop_name, |
| 151 |
exoid); |
| 152 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 153 |
EX_FUNC_LEAVE(EX_WARN); |
| 154 |
} |
| 155 |
|
| 156 |
/* read num_obj values from property variable */ |
| 157 |
if (ex_int64_status(exoid) & EX_IDS_INT64_API) { |
| 158 |
status = nc_get_var_longlong(exoid, propid, values); |
| 159 |
} |
| 160 |
else { |
| 161 |
status = nc_get_var_int(exoid, propid, values); |
| 162 |
} |
| 163 |
|
| 164 |
if (status != NC_NOERR) { |
| 165 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 166 |
"ERROR: failed to read values in %s property array in file id %d", |
| 167 |
ex_name_of_object(obj_type), exoid); |
| 168 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 169 |
EX_FUNC_LEAVE(EX_FATAL); |
| 170 |
} |
| 171 |
|
| 172 |
EX_FUNC_LEAVE(EX_NOERR); |
| 173 |
} |