| 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 |
* exgsetp - ex_get_set_param |
| 11 |
* |
| 12 |
* entry conditions - |
| 13 |
* input parameters: |
| 14 |
* int exoid exodus file id |
| 15 |
* int set_type the type of set |
| 16 |
* int set_id set id |
| 17 |
* |
| 18 |
* exit conditions - |
| 19 |
* int* num_entries_in_set number of entries in the set |
| 20 |
* int* num_dist_fact_in_set number of distribution factors in the |
| 21 |
* set |
| 22 |
* |
| 23 |
* revision history - |
| 24 |
* |
| 25 |
* |
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
#include "exodusII.h" // for ex_err, etc |
| 29 |
#include "exodusII_int.h" // for EX_FATAL, EX_NOERR, etc |
| 30 |
|
| 31 |
/* |
| 32 |
* reads the number of entries and the number of distribution factors which |
| 33 |
* describe a single set |
| 34 |
*/ |
| 35 |
|
| 36 |
int ex_get_set_param(int exoid, ex_entity_type set_type, ex_entity_id set_id, |
| 37 |
void_int *num_entry_in_set, void_int *num_dist_fact_in_set) |
| 38 |
{ |
| 39 |
int status; |
| 40 |
int varid, dimid, set_id_ndx; |
| 41 |
size_t lnum_entry_in_set; |
| 42 |
size_t lnum_dist_fact_in_set; |
| 43 |
char errmsg[MAX_ERR_LENGTH]; |
| 44 |
char *numentryptr = NULL; |
| 45 |
char *numdfptr = NULL; |
| 46 |
|
| 47 |
EX_FUNC_ENTER(); |
| 48 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 49 |
EX_FUNC_LEAVE(EX_FATAL); |
| 50 |
} |
| 51 |
|
| 52 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 53 |
if (num_entry_in_set) { |
| 54 |
*(int64_t *)num_entry_in_set = 0; |
| 55 |
} |
| 56 |
if (num_dist_fact_in_set) { |
| 57 |
*(int64_t *)num_dist_fact_in_set = 0; |
| 58 |
} |
| 59 |
} |
| 60 |
else { |
| 61 |
if (num_entry_in_set) { |
| 62 |
*(int *)num_entry_in_set = 0; |
| 63 |
} |
| 64 |
if (num_dist_fact_in_set) { |
| 65 |
*(int *)num_dist_fact_in_set = 0; |
| 66 |
} |
| 67 |
} |
| 68 |
/* first check if any sets are specified */ |
| 69 |
if ((status = nc_inq_dimid(exoid, exi_dim_num_objects(set_type), &dimid)) != NC_NOERR) { |
| 70 |
snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no %ss stored in file id %d", |
| 71 |
ex_name_of_object(set_type), exoid); |
| 72 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 73 |
EX_FUNC_LEAVE(EX_WARN); |
| 74 |
} |
| 75 |
|
| 76 |
/* Lookup index of set id in VAR_*S_IDS array */ |
| 77 |
set_id_ndx = exi_id_lkup(exoid, set_type, set_id); |
| 78 |
if (set_id_ndx <= 0) { |
| 79 |
ex_get_err(NULL, NULL, &status); |
| 80 |
|
| 81 |
if (status != 0) { |
| 82 |
if (status == EX_NULLENTITY) { |
| 83 |
EX_FUNC_LEAVE(EX_NOERR); |
| 84 |
} |
| 85 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 86 |
"ERROR: failed to locate %s id %" PRId64 " in id array in file id %d", |
| 87 |
ex_name_of_object(set_type), set_id, exoid); |
| 88 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 89 |
EX_FUNC_LEAVE(EX_FATAL); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
/* setup more pointers based on set_type */ |
| 94 |
if (set_type == EX_NODE_SET) { |
| 95 |
numentryptr = DIM_NUM_NOD_NS(set_id_ndx); |
| 96 |
/* note we are using DIM_NUM_NODE_NS instead of DIM_NUM_DF_NS */ |
| 97 |
numdfptr = DIM_NUM_NOD_NS(set_id_ndx); |
| 98 |
} |
| 99 |
else if (set_type == EX_EDGE_SET) { |
| 100 |
numentryptr = DIM_NUM_EDGE_ES(set_id_ndx); |
| 101 |
numdfptr = DIM_NUM_DF_ES(set_id_ndx); |
| 102 |
} |
| 103 |
else if (set_type == EX_FACE_SET) { |
| 104 |
numentryptr = DIM_NUM_FACE_FS(set_id_ndx); |
| 105 |
numdfptr = DIM_NUM_DF_FS(set_id_ndx); |
| 106 |
} |
| 107 |
else if (set_type == EX_SIDE_SET) { |
| 108 |
numentryptr = DIM_NUM_SIDE_SS(set_id_ndx); |
| 109 |
numdfptr = DIM_NUM_DF_SS(set_id_ndx); |
| 110 |
} |
| 111 |
if (set_type == EX_ELEM_SET) { |
| 112 |
numentryptr = DIM_NUM_ELE_ELS(set_id_ndx); |
| 113 |
numdfptr = DIM_NUM_DF_ELS(set_id_ndx); |
| 114 |
} |
| 115 |
|
| 116 |
/* inquire values of dimension for number of entities in set */ |
| 117 |
if (exi_get_dimension(exoid, numentryptr, "entries", &lnum_entry_in_set, &dimid, __func__) != |
| 118 |
NC_NOERR) { |
| 119 |
EX_FUNC_LEAVE(EX_FATAL); |
| 120 |
} |
| 121 |
|
| 122 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 123 |
if (num_entry_in_set) { |
| 124 |
*(int64_t *)num_entry_in_set = lnum_entry_in_set; |
| 125 |
} |
| 126 |
} |
| 127 |
else { |
| 128 |
if (num_entry_in_set) { |
| 129 |
*(int *)num_entry_in_set = lnum_entry_in_set; |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
/* Inquire value of dimension of number of dist factors for this set. |
| 134 |
NOTE: For node sets, because DIM_NUM_DF_NS is not used, we check to see |
| 135 |
if the dist factor variable for a node set index exits. If it does not, |
| 136 |
the dist factor count is assumed to be zero, otherwise the dist factor |
| 137 |
count will be the same as the number of nodes in the set. */ |
| 138 |
|
| 139 |
if (set_type == EX_NODE_SET) { |
| 140 |
if ((status = nc_inq_varid(exoid, VAR_FACT_NS(set_id_ndx), &varid)) != NC_NOERR) { |
| 141 |
if (status == NC_ENOTVAR) { |
| 142 |
EX_FUNC_LEAVE(EX_NOERR); |
| 143 |
} |
| 144 |
|
| 145 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 146 |
"ERROR: failed to locate the dist factors for %s %" PRId64 " in file id %d", |
| 147 |
ex_name_of_object(set_type), set_id, exoid); |
| 148 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 149 |
EX_FUNC_LEAVE(EX_FATAL); |
| 150 |
} |
| 151 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 152 |
if (num_dist_fact_in_set) { |
| 153 |
*(int64_t *)num_dist_fact_in_set = lnum_entry_in_set; |
| 154 |
} |
| 155 |
} |
| 156 |
else { |
| 157 |
if (num_dist_fact_in_set) { |
| 158 |
*(int *)num_dist_fact_in_set = lnum_entry_in_set; |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
else { /* all other set types */ |
| 163 |
if ((status = nc_inq_dimid(exoid, numdfptr, &dimid)) != NC_NOERR) { |
| 164 |
if (status == NC_EBADDIM) { |
| 165 |
EX_FUNC_LEAVE(EX_NOERR); |
| 166 |
} |
| 167 |
|
| 168 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 169 |
"ERROR: failed to locate number of dist factors in %s %" PRId64 " in file id %d", |
| 170 |
ex_name_of_object(set_type), set_id, exoid); |
| 171 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 172 |
EX_FUNC_LEAVE(EX_FATAL); |
| 173 |
} |
| 174 |
|
| 175 |
if ((status = nc_inq_dimlen(exoid, dimid, &lnum_dist_fact_in_set)) != NC_NOERR) { |
| 176 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 177 |
"ERROR: failed to get number of dist factors in %s %" PRId64 " in file id %d", |
| 178 |
ex_name_of_object(set_type), set_id, exoid); |
| 179 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 180 |
EX_FUNC_LEAVE(EX_FATAL); |
| 181 |
} |
| 182 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 183 |
if (num_dist_fact_in_set) { |
| 184 |
*(int64_t *)num_dist_fact_in_set = lnum_dist_fact_in_set; |
| 185 |
} |
| 186 |
} |
| 187 |
else { |
| 188 |
if (num_dist_fact_in_set) { |
| 189 |
*(int *)num_dist_fact_in_set = lnum_dist_fact_in_set; |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
EX_FUNC_LEAVE(EX_NOERR); |
| 195 |
} |