Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_get_partial_set.c

raw
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_is_parallel, etc
11
12 /*!
13 * reads a portion of 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 offset index of first entry in set to access (1-based)
18 * \param num_to_get number of entries to output.
19 * \param set_entry_list array of entries in set. Set to NULL to not
20 * read.
21 * \param set_extra_list array of extras in set. Set to NULL to not
22 * read.
23 */
24
25 int ex_get_partial_set(int exoid, ex_entity_type set_type, ex_entity_id set_id, int64_t offset,
26 int64_t num_to_get, void_int *set_entry_list, void_int *set_extra_list)
27 {
28 int dimid, status;
29 int entry_list_id, extra_list_id, set_id_ndx;
30 size_t start[1], count[1];
31 char errmsg[MAX_ERR_LENGTH];
32 char *entryptr = NULL;
33 char *extraptr = NULL;
34
35 EX_FUNC_ENTER();
36 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
37 EX_FUNC_LEAVE(EX_FATAL);
38 }
39
40 /* first check if any sets are specified */
41 if ((status = nc_inq_dimid(exoid, exi_dim_num_objects(set_type), &dimid)) != NC_NOERR) {
42 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: no %ss defined in file id %d",
43 ex_name_of_object(set_type), exoid);
44 ex_err_fn(exoid, __func__, errmsg, status);
45 EX_FUNC_LEAVE(EX_FATAL);
46 }
47
48 /* Lookup index of set id in VAR_*S_IDS array */
49 set_id_ndx = exi_id_lkup(exoid, set_type, set_id);
50 if (set_id_ndx <= 0) {
51 ex_get_err(NULL, NULL, &status);
52
53 if (status != 0) {
54 if (status == EX_NULLENTITY) {
55 snprintf(errmsg, MAX_ERR_LENGTH,
56 "Warning: no data allowed for NULL %s %" PRId64 " in file id %d",
57 ex_name_of_object(set_type), set_id, exoid);
58 ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY);
59 EX_FUNC_LEAVE(EX_WARN);
60 }
61 snprintf(errmsg, MAX_ERR_LENGTH,
62 "ERROR: failed to locate %s id %" PRId64 " in VAR_*S_IDS array in file id %d",
63 ex_name_of_object(set_type), set_id, exoid);
64 ex_err_fn(exoid, __func__, errmsg, status);
65 EX_FUNC_LEAVE(EX_FATAL);
66 }
67 }
68
69 /* setup more pointers based on set_type */
70 if (set_type == EX_NODE_SET) {
71 entryptr = VAR_NODE_NS(set_id_ndx);
72 extraptr = NULL;
73 }
74 else if (set_type == EX_EDGE_SET) {
75 entryptr = VAR_EDGE_ES(set_id_ndx);
76 extraptr = VAR_ORNT_ES(set_id_ndx);
77 }
78 else if (set_type == EX_FACE_SET) {
79 entryptr = VAR_FACE_FS(set_id_ndx);
80 extraptr = VAR_ORNT_FS(set_id_ndx);
81 }
82 else if (set_type == EX_SIDE_SET) {
83 entryptr = VAR_ELEM_SS(set_id_ndx);
84 extraptr = VAR_SIDE_SS(set_id_ndx);
85 }
86 else if (set_type == EX_ELEM_SET) {
87 entryptr = VAR_ELEM_ELS(set_id_ndx);
88 extraptr = NULL;
89 }
90
91 /* inquire id's of previously defined variables */
92 if ((status = nc_inq_varid(exoid, entryptr, &entry_list_id)) != NC_NOERR) {
93 snprintf(errmsg, MAX_ERR_LENGTH,
94 "ERROR: failed to locate entry list for %s %" PRId64 " in file id %d",
95 ex_name_of_object(set_type), set_id, exoid);
96 ex_err_fn(exoid, __func__, errmsg, status);
97 EX_FUNC_LEAVE(EX_FATAL);
98 }
99
100 /* read the entry list and extra list arrays */
101 if (set_entry_list != NULL || exi_is_parallel(exoid)) {
102 start[0] = offset - 1;
103 count[0] = num_to_get;
104 if (count[0] == 0) {
105 start[0] = 0;
106 }
107
108 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
109 status = nc_get_vara_longlong(exoid, entry_list_id, start, count, set_entry_list);
110 }
111 else {
112 status = nc_get_vara_int(exoid, entry_list_id, start, count, set_entry_list);
113 }
114
115 if (status != NC_NOERR) {
116 snprintf(errmsg, MAX_ERR_LENGTH,
117 "ERROR: failed to get entry list for %s %" PRId64 " in file id %d",
118 ex_name_of_object(set_type), set_id, exoid);
119 ex_err_fn(exoid, __func__, errmsg, status);
120 EX_FUNC_LEAVE(EX_FATAL);
121 }
122 }
123
124 /* only do for edge, face and side sets */
125 if (extraptr && (set_extra_list != NULL || exi_is_parallel(exoid))) {
126 if ((status = nc_inq_varid(exoid, extraptr, &extra_list_id)) != NC_NOERR) {
127 snprintf(errmsg, MAX_ERR_LENGTH,
128 "ERROR: failed to locate extra list for %s %" PRId64 " in file id %d",
129 ex_name_of_object(set_type), set_id, exoid);
130 ex_err_fn(exoid, __func__, errmsg, status);
131 EX_FUNC_LEAVE(EX_FATAL);
132 }
133
134 start[0] = offset - 1;
135 count[0] = num_to_get;
136 if (count[0] == 0) {
137 start[0] = 0;
138 }
139 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
140 status = nc_get_vara_longlong(exoid, extra_list_id, start, count, set_extra_list);
141 }
142 else {
143 status = nc_get_vara_int(exoid, extra_list_id, start, count, set_extra_list);
144 }
145
146 if (status != NC_NOERR) {
147 snprintf(errmsg, MAX_ERR_LENGTH,
148 "ERROR: failed to get extra list for %s %" PRId64 " in file id %d",
149 ex_name_of_object(set_type), set_id, exoid);
150 ex_err_fn(exoid, __func__, errmsg, status);
151 EX_FUNC_LEAVE(EX_FATAL);
152 }
153 }
154
155 /* warn if extra data was sent in for node sets and elem sets */
156 if ((set_type == EX_NODE_SET || set_type == EX_ELEM_SET) && set_extra_list != NULL) {
157 snprintf(errmsg, MAX_ERR_LENGTH,
158 "Warning: extra list was ignored for %s %" PRId64 " in file id %d",
159 ex_name_of_object(set_type), set_id, exoid);
160 ex_err_fn(exoid, __func__, errmsg, EX_MSG);
161 EX_FUNC_LEAVE(EX_WARN);
162 }
163
164 EX_FUNC_LEAVE(EX_NOERR);
165 }