Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-2021 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 * \undoc exgblk - read block parameters
11 *
12 * entry conditions -
13 * input parameters:
14 * int idexo exodus file id
15 * int blk_type block type (edge,face,element)
16 * int blk_id block id
17 *
18 * exit conditions -
19 * char* elem_type element type name
20 * int* num_entries_this_blk number of elements in this element block
21 * int* num_nodes_per_entry number of nodes per element block
22 * int* num_attr_per_entry number of attributes
23 *
24 * revision history -
25 *
26 *
27 */
28
29 #include "exodusII.h" // for ex_block, ex_err, etc
30 #include "exodusII_int.h" // for EX_FATAL, ATT_NAME_ELB, etc
31
32 /*
33 * reads the parameters used to describe an edge, face, or element block
34 */
35
36 int ex_get_block_param(int exoid, ex_block *block)
37 {
38 int dimid, connid, blk_id_ndx;
39 char errmsg[MAX_ERR_LENGTH];
40 int status;
41 const char *dnument = NULL;
42 const char *dnumnod = NULL;
43 const char *dnumedg = NULL;
44 const char *dnumfac = NULL;
45 const char *dnumatt = NULL;
46 const char *ablknam = NULL;
47 const char *vblkcon = NULL;
48
49 EX_FUNC_ENTER();
50
51 struct exi_file_item *file = exi_find_file_item(exoid);
52 if (!file) {
53 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unknown file id %d in ex_get_block_param().", exoid);
54 ex_err_fn(exoid, __func__, errmsg, EX_BADFILEID);
55 EX_FUNC_LEAVE(EX_FATAL);
56 }
57
58 /* First, locate index of element block id in VAR_ID_EL_BLK array */
59 blk_id_ndx = exi_id_lkup(exoid, block->type, block->id);
60 if (blk_id_ndx <= 0) {
61 ex_get_err(NULL, NULL, &status);
62 if (status != 0) {
63 ex_copy_string(block->topology, "NULL", MAX_STR_LENGTH + 1); /* NULL element type name */
64 block->num_entry = 0; /* no elements */
65 block->num_nodes_per_entry = 0; /* no nodes */
66 block->num_edges_per_entry = 0;
67 block->num_faces_per_entry = 0;
68 block->num_attribute = 0; /* no attributes */
69 if (status == EX_NULLENTITY) { /* NULL element block? */
70 EX_FUNC_LEAVE(EX_NOERR);
71 }
72 snprintf(errmsg, MAX_ERR_LENGTH,
73 "ERROR: failed to locate %s id %" PRId64 " in id array in file id %d",
74 ex_name_of_object(block->type), block->id, exoid);
75 ex_err_fn(exoid, __func__, errmsg, status);
76 EX_FUNC_LEAVE(EX_FATAL);
77 }
78 }
79
80 switch (block->type) {
81 case EX_EDGE_BLOCK:
82 dnument = DIM_NUM_ED_IN_EBLK(blk_id_ndx);
83 dnumnod = DIM_NUM_NOD_PER_ED(blk_id_ndx);
84 dnumedg = NULL;
85 dnumfac = NULL;
86 dnumatt = DIM_NUM_ATT_IN_EBLK(blk_id_ndx);
87 vblkcon = VAR_EBCONN(blk_id_ndx);
88 ablknam = ATT_NAME_ELB;
89 break;
90 case EX_FACE_BLOCK:
91 dnument = DIM_NUM_FA_IN_FBLK(blk_id_ndx);
92 dnumnod = DIM_NUM_NOD_PER_FA(blk_id_ndx);
93 dnumedg = NULL; /* it is possible this might be non-NULL some day */
94 dnumfac = NULL;
95 dnumatt = DIM_NUM_ATT_IN_FBLK(blk_id_ndx);
96 vblkcon = VAR_FBCONN(blk_id_ndx);
97 ablknam = ATT_NAME_ELB;
98 break;
99 case EX_ELEM_BLOCK:
100 dnument = DIM_NUM_EL_IN_BLK(blk_id_ndx);
101 dnumnod = DIM_NUM_NOD_PER_EL(blk_id_ndx);
102 dnumedg = DIM_NUM_EDG_PER_EL(blk_id_ndx);
103 dnumfac = DIM_NUM_FAC_PER_EL(blk_id_ndx);
104 dnumatt = DIM_NUM_ATT_IN_BLK(blk_id_ndx);
105 vblkcon = VAR_CONN(blk_id_ndx);
106 ablknam = ATT_NAME_ELB;
107 break;
108 default:
109 snprintf(errmsg, MAX_ERR_LENGTH, "Bad block type parameter (%d) specified for file id %d.",
110 block->type, exoid);
111 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
112 EX_FUNC_LEAVE(EX_FATAL);
113 }
114
115 /* inquire values of some dimensions */
116 if ((status = nc_inq_dimid(exoid, dnument, &dimid)) != NC_NOERR) {
117 snprintf(errmsg, MAX_ERR_LENGTH,
118 "ERROR: failed to locate number of entities in %s %" PRId64 " in file id %d",
119 ex_name_of_object(block->type), block->id, exoid);
120 ex_err_fn(exoid, __func__, errmsg, status);
121 EX_FUNC_LEAVE(EX_FATAL);
122 }
123
124 size_t len;
125 if ((status = nc_inq_dimlen(exoid, dimid, &len)) != NC_NOERR) {
126 snprintf(errmsg, MAX_ERR_LENGTH,
127 "ERROR: failed to get number of %ss in block %" PRId64 " in file id %d",
128 ex_name_of_object(block->type), block->id, exoid);
129 ex_err_fn(exoid, __func__, errmsg, status);
130 EX_FUNC_LEAVE(EX_FATAL);
131 }
132 block->num_entry = len;
133
134 if ((status = nc_inq_dimid(exoid, dnumnod, &dimid)) != NC_NOERR) {
135 /* undefined => no node entries per element */
136 len = 0;
137 }
138 else {
139 if ((status = nc_inq_dimlen(exoid, dimid, &len)) != NC_NOERR) {
140 snprintf(errmsg, MAX_ERR_LENGTH,
141 "ERROR: failed to get number of nodes/entity in %s %" PRId64 " in file id %d",
142 ex_name_of_object(block->type), block->id, exoid);
143 ex_err_fn(exoid, __func__, errmsg, status);
144 EX_FUNC_LEAVE(EX_FATAL);
145 }
146 }
147 block->num_nodes_per_entry = len;
148
149 if (!file->has_edges || block->type != EX_ELEM_BLOCK) {
150 block->num_edges_per_entry = 0;
151 }
152 else {
153 if ((status = nc_inq_dimid(exoid, dnumedg, &dimid)) != NC_NOERR) {
154 /* undefined => no edge entries per element */
155 len = 0;
156 }
157 else {
158 if ((status = nc_inq_dimlen(exoid, dimid, &len)) != NC_NOERR) {
159 snprintf(errmsg, MAX_ERR_LENGTH,
160 "ERROR: failed to get number of edges/entry in %s %" PRId64 " in file id %d",
161 ex_name_of_object(block->type), block->id, exoid);
162 ex_err_fn(exoid, __func__, errmsg, status);
163 EX_FUNC_LEAVE(EX_FATAL);
164 }
165 }
166 block->num_edges_per_entry = len;
167 }
168
169 if (!file->has_faces || block->type != EX_ELEM_BLOCK) {
170 block->num_faces_per_entry = 0;
171 }
172 else {
173 if ((status = nc_inq_dimid(exoid, dnumfac, &dimid)) != NC_NOERR) {
174 /* undefined => no face entries per element */
175 len = 0;
176 }
177 else {
178 if ((status = nc_inq_dimlen(exoid, dimid, &len)) != NC_NOERR) {
179 snprintf(errmsg, MAX_ERR_LENGTH,
180 "ERROR: failed to get number of faces/entity in %s %" PRId64 " in file id %d",
181 ex_name_of_object(block->type), block->id, exoid);
182 ex_err_fn(exoid, __func__, errmsg, status);
183 EX_FUNC_LEAVE(EX_FATAL);
184 }
185 }
186 block->num_faces_per_entry = len;
187 }
188
189 if ((status = nc_inq_dimid(exoid, dnumatt, &dimid)) != NC_NOERR) {
190 /* dimension is undefined */
191 block->num_attribute = 0;
192 }
193 else {
194 if ((status = nc_inq_dimlen(exoid, dimid, &len)) != NC_NOERR) {
195 snprintf(errmsg, MAX_ERR_LENGTH,
196 "ERROR: failed to get number of attributes in %s %" PRId64 " in file id %d",
197 ex_name_of_object(block->type), block->id, exoid);
198 ex_err_fn(exoid, __func__, errmsg, status);
199 EX_FUNC_LEAVE(EX_FATAL);
200 }
201 block->num_attribute = len;
202 }
203
204 if (block->num_nodes_per_entry == 0 && block->num_edges_per_entry == 0 &&
205 block->num_faces_per_entry == 0) {
206 vblkcon = NULL;
207 }
208
209 if (block->num_nodes_per_entry > 0) {
210 ; /* Do nothing, vblkcon should be correctly set already */
211 }
212 else if (block->num_edges_per_entry > 0) {
213 vblkcon = VAR_EBCONN(blk_id_ndx);
214 }
215 else if (block->num_faces_per_entry > 0) {
216 vblkcon = VAR_FCONN(blk_id_ndx);
217 }
218
219 if (vblkcon) {
220 /* look up connectivity array for this element block id */
221 if ((status = nc_inq_varid(exoid, vblkcon, &connid)) != NC_NOERR) {
222 snprintf(errmsg, MAX_ERR_LENGTH,
223 "ERROR: failed to locate connectivity array for %s %" PRId64 " in file id %d",
224 ex_name_of_object(block->type), block->id, exoid);
225 ex_err_fn(exoid, __func__, errmsg, status);
226 EX_FUNC_LEAVE(EX_FATAL);
227 }
228
229 if ((status = nc_inq_attlen(exoid, connid, ablknam, &len)) != NC_NOERR) {
230 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s %" PRId64 " type in file id %d",
231 ex_name_of_object(block->type), block->id, exoid);
232 ex_err_fn(exoid, __func__, errmsg, status);
233 EX_FUNC_LEAVE(EX_FATAL);
234 }
235
236 if (len > (MAX_STR_LENGTH + 1)) {
237 len = MAX_STR_LENGTH;
238 snprintf(errmsg, MAX_ERR_LENGTH,
239 "Warning: %s %" PRId64 " type will be truncated to %ld chars",
240 ex_name_of_object(block->type), block->id, (long)len);
241 ex_err_fn(exoid, __func__, errmsg, EX_MSG);
242 }
243
244 for (int i = 0; i < MAX_STR_LENGTH + 1; i++) {
245 block->topology[i] = '\0';
246
247 /* get the element type name */
248 }
249 if ((status = nc_get_att_text(exoid, connid, ablknam, block->topology)) != NC_NOERR) {
250 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s %" PRId64 " type in file id %d",
251 ex_name_of_object(block->type), block->id, exoid);
252 ex_err_fn(exoid, __func__, errmsg, status);
253 EX_FUNC_LEAVE(EX_FATAL);
254 }
255
256 /* get rid of trailing blanks */
257 exi_trim(block->topology);
258 }
259 EX_FUNC_LEAVE(EX_NOERR);
260 }