| 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 |
#include "exodusII.h" // for ex_err, ex_name_of_object, etc |
| 10 |
#include "exodusII_int.h" // for exi_check_valid_file_id, etc |
| 11 |
|
| 12 |
/*! |
| 13 |
* reads the set entry list and set extra list for a single set |
| 14 |
* \param exoid exodus file id |
| 15 |
* \param set_type set type |
| 16 |
* \param set_id set id |
| 17 |
* \param *set_entry_list array of entries in set. Set to NULL to not |
| 18 |
* read. |
| 19 |
* \param *set_extra_list array of extras in set. Set to NULL to not |
| 20 |
* read. |
| 21 |
*/ |
| 22 |
|
| 23 |
int ex_get_set(int exoid, ex_entity_type set_type, ex_entity_id set_id, void_int *set_entry_list, |
| 24 |
void_int *set_extra_list) /* NULL if don't want to retrieve data */ |
| 25 |
{ |
| 26 |
|
| 27 |
int dimid, entry_list_id, extra_list_id, status; |
| 28 |
int set_id_ndx; |
| 29 |
char errmsg[MAX_ERR_LENGTH]; |
| 30 |
char *entryptr = NULL; |
| 31 |
char *extraptr = NULL; |
| 32 |
|
| 33 |
EX_FUNC_ENTER(); |
| 34 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 35 |
EX_FUNC_LEAVE(EX_FATAL); |
| 36 |
} |
| 37 |
|
| 38 |
/* first check if any sets are specified */ |
| 39 |
if ((status = nc_inq_dimid(exoid, exi_dim_num_objects(set_type), &dimid)) != NC_NOERR) { |
| 40 |
snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no %ss stored in file id %d", |
| 41 |
ex_name_of_object(set_type), exoid); |
| 42 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 43 |
EX_FUNC_LEAVE(EX_WARN); |
| 44 |
} |
| 45 |
|
| 46 |
/* Lookup index of set id in VAR_*S_IDS array */ |
| 47 |
set_id_ndx = exi_id_lkup(exoid, set_type, set_id); |
| 48 |
if (set_id_ndx <= 0) { |
| 49 |
ex_get_err(NULL, NULL, &status); |
| 50 |
|
| 51 |
if (status != 0) { |
| 52 |
if (status == EX_NULLENTITY) { |
| 53 |
snprintf(errmsg, MAX_ERR_LENGTH, "Warning: %s %" PRId64 " is NULL in file id %d", |
| 54 |
ex_name_of_object(set_type), set_id, exoid); |
| 55 |
ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY); |
| 56 |
EX_FUNC_LEAVE(EX_WARN); |
| 57 |
} |
| 58 |
|
| 59 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 60 |
"ERROR: failed to locate %s id %" PRId64 " in VAR_*S_IDS array in file id %d", |
| 61 |
ex_name_of_object(set_type), set_id, exoid); |
| 62 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 63 |
EX_FUNC_LEAVE(EX_FATAL); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
/* setup more pointers based on set_type */ |
| 68 |
if (set_type == EX_NODE_SET) { |
| 69 |
entryptr = VAR_NODE_NS(set_id_ndx); |
| 70 |
extraptr = NULL; |
| 71 |
} |
| 72 |
else if (set_type == EX_EDGE_SET) { |
| 73 |
entryptr = VAR_EDGE_ES(set_id_ndx); |
| 74 |
extraptr = VAR_ORNT_ES(set_id_ndx); |
| 75 |
} |
| 76 |
else if (set_type == EX_FACE_SET) { |
| 77 |
entryptr = VAR_FACE_FS(set_id_ndx); |
| 78 |
extraptr = VAR_ORNT_FS(set_id_ndx); |
| 79 |
} |
| 80 |
else if (set_type == EX_SIDE_SET) { |
| 81 |
entryptr = VAR_ELEM_SS(set_id_ndx); |
| 82 |
extraptr = VAR_SIDE_SS(set_id_ndx); |
| 83 |
} |
| 84 |
else if (set_type == EX_ELEM_SET) { |
| 85 |
entryptr = VAR_ELEM_ELS(set_id_ndx); |
| 86 |
extraptr = NULL; |
| 87 |
} |
| 88 |
|
| 89 |
/* inquire id's of previously defined dimensions and variables */ |
| 90 |
if ((status = nc_inq_varid(exoid, entryptr, &entry_list_id)) != NC_NOERR) { |
| 91 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 92 |
"ERROR: failed to locate entry list for %s %" PRId64 " in file id %d", |
| 93 |
ex_name_of_object(set_type), set_id, exoid); |
| 94 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 95 |
EX_FUNC_LEAVE(EX_FATAL); |
| 96 |
} |
| 97 |
|
| 98 |
/* If client doet not pass in an array to store the |
| 99 |
extra list, don't access it at all */ |
| 100 |
|
| 101 |
/* only do extra list for edge, face and side sets */ |
| 102 |
if (set_extra_list) { |
| 103 |
if ((status = nc_inq_varid(exoid, extraptr, &extra_list_id)) != NC_NOERR) { |
| 104 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 105 |
"ERROR: failed to locate extra list for %s %" PRId64 " in file id %d", |
| 106 |
ex_name_of_object(set_type), set_id, exoid); |
| 107 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 108 |
EX_FUNC_LEAVE(EX_FATAL); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
/* read in the entry list and extra list arrays unless they are NULL */ |
| 113 |
if (set_entry_list) { |
| 114 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 115 |
status = nc_get_var_longlong(exoid, entry_list_id, set_entry_list); |
| 116 |
} |
| 117 |
else { |
| 118 |
status = nc_get_var_int(exoid, entry_list_id, set_entry_list); |
| 119 |
} |
| 120 |
|
| 121 |
if (status != NC_NOERR) { |
| 122 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 123 |
"ERROR: failed to get entry list for %s %" PRId64 " in file id %d", |
| 124 |
ex_name_of_object(set_type), set_id, exoid); |
| 125 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 126 |
EX_FUNC_LEAVE(EX_FATAL); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
/* only do extra list for edge, face and side sets */ |
| 131 |
if (set_extra_list) { |
| 132 |
if (ex_int64_status(exoid) & EX_BULK_INT64_API) { |
| 133 |
status = nc_get_var_longlong(exoid, extra_list_id, set_extra_list); |
| 134 |
} |
| 135 |
else { |
| 136 |
status = nc_get_var_int(exoid, extra_list_id, set_extra_list); |
| 137 |
} |
| 138 |
|
| 139 |
if (status != NC_NOERR) { |
| 140 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 141 |
"ERROR: failed to get extra list for %s %" PRId64 " in file id %d", |
| 142 |
ex_name_of_object(set_type), set_id, exoid); |
| 143 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 144 |
EX_FUNC_LEAVE(EX_FATAL); |
| 145 |
} |
| 146 |
} |
| 147 |
EX_FUNC_LEAVE(EX_NOERR); |
| 148 |
} |