Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-2020, 2022, 2023 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 * expclb - ex_put_concat_all_blocks: write elem, edge, & face block parameters
11 *
12 * entry conditions -
13 * input parameters:
14 * int exoid exodus file id
15 * const ex_block_params* bparam block parameters structure
16 *
17 *****************************************************************************/
18
19 #include "exodusII.h" // for ex_err, etc
20 #include "exodusII_int.h" // for EX_FATAL, etc
21
22 /*!
23 * writes the parameters used to describe all element, edge, and face blocks
24 * \param exoid exodus file id
25 * \param param block parameters structure
26 */
27 int ex_put_concat_all_blocks(int exoid, const ex_block_params *param)
28 {
29 int varid, dimid, dims[2], strdim, *eb_stat, *ed_stat, *fa_stat;
30 int temp;
31 size_t iblk;
32 size_t i;
33 int status;
34 size_t num_elem_blk = 0;
35 size_t num_edge_blk = 0;
36 size_t num_face_blk = 0;
37 int cur_num_elem_blk, nelnoddim, numelbdim, numattrdim, connid = -1;
38 int cur_num_edge_blk, numedbdim, nednoddim, cur_num_face_blk, numfabdim, nfanoddim;
39 int neledgdim = -1, nelfacdim = -1;
40 char errmsg[MAX_ERR_LENGTH];
41 int elem_work = 0; /* is DIM_NUM_EL_BLK defined? If so, there's work to do */
42 int edge_work = 0; /* is DIM_NUM_ED_BLK defined? If so, there's work to do */
43 int face_work = 0; /* is DIM_NUM_FA_BLK defined? If so, there's work to do */
44
45 int *edge_id_int = NULL;
46 int *face_id_int = NULL;
47 int *elem_id_int = NULL;
48
49 int64_t *edge_id_int64 = NULL;
50 int64_t *face_id_int64 = NULL;
51 int64_t *elem_id_int64 = NULL;
52
53 int ids_int64 = ex_int64_status(exoid) & EX_IDS_INT64_API;
54
55 static const char *dim_num_maps[] = {
56 DIM_NUM_NM,
57 DIM_NUM_EDM,
58 DIM_NUM_FAM,
59 DIM_NUM_EM,
60 };
61 static const char *dim_size_maps[] = {
62 DIM_NUM_NODES,
63 DIM_NUM_EDGE,
64 DIM_NUM_FACE,
65 DIM_NUM_ELEM,
66 };
67 static const ex_entity_type map_enums[] = {EX_NODE_MAP, EX_EDGE_MAP, EX_FACE_MAP, EX_ELEM_MAP};
68
69 /* If param->define_maps is true, we must fill these with values from
70 ex_put_init_ext
71 before entering define mode */
72 size_t num_maps[sizeof(dim_num_maps) / sizeof(dim_num_maps[0])];
73 size_t num_map_dims = sizeof(dim_num_maps) / sizeof(dim_num_maps[0]);
74
75 EX_FUNC_ENTER();
76
77 if (ids_int64) {
78 edge_id_int64 = param->edge_blk_id;
79 face_id_int64 = param->face_blk_id;
80 elem_id_int64 = param->elem_blk_id;
81 }
82 else {
83 edge_id_int = param->edge_blk_id;
84 face_id_int = param->face_blk_id;
85 elem_id_int = param->elem_blk_id;
86 }
87
88 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
89 EX_FUNC_LEAVE(EX_FATAL);
90 }
91
92 /* inquire previously defined dimensions */
93 if ((status = nc_inq_dimid(exoid, DIM_STR_NAME, &strdim)) != NC_NOERR) {
94 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get string length in file id %d", exoid);
95 ex_err_fn(exoid, __func__, errmsg, status);
96 EX_FUNC_LEAVE(EX_FATAL);
97 }
98
99 if (param->define_maps) {
100 for (i = 0; i < num_map_dims; ++i) {
101 if ((status = nc_inq_dimid(exoid, dim_num_maps[i], &dimid)) != NC_NOERR) {
102 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find node map size of file id %d",
103 exoid);
104 ex_err_fn(exoid, __func__, errmsg, status);
105 EX_FUNC_LEAVE(EX_FATAL);
106 }
107 if ((status = nc_inq_dimlen(exoid, dimid, num_maps + i)) != NC_NOERR) {
108 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to retrieve node map size of file id %d",
109 exoid);
110 ex_err_fn(exoid, __func__, errmsg, status);
111 EX_FUNC_LEAVE(EX_FATAL);
112 }
113 }
114 }
115
116 #define EX_PREPARE_BLOCK(TNAME, WNAME, DNUMNAME, VSTATNAME, VIDNAME, LNUMNAME, SNUMNAME, SIDNAME, \
117 GSTAT) \
118 /* first check if any TNAME blocks are specified \
119 * OK if zero... \
120 */ \
121 if ((status = (nc_inq_dimid(exoid, DNUMNAME, &dimid))) == NC_NOERR) { \
122 WNAME = 1; \
123 \
124 /* Get number of TNAME blocks defined for this file */ \
125 if ((status = nc_inq_dimlen(exoid, dimid, &LNUMNAME)) != NC_NOERR) { \
126 snprintf(errmsg, MAX_ERR_LENGTH, \
127 "ERROR: failed to get number of " TNAME " blocks in file id %d", exoid); \
128 ex_err_fn(exoid, __func__, errmsg, status); \
129 EX_FUNC_LEAVE(EX_FATAL); \
130 } \
131 \
132 /* Fill out the TNAME block status array */ \
133 if (!(GSTAT = malloc(LNUMNAME * sizeof(int)))) { \
134 snprintf(errmsg, MAX_ERR_LENGTH, \
135 "ERROR: failed to allocate space for " TNAME " block status array in file id %d", \
136 exoid); \
137 ex_err_fn(exoid, __func__, errmsg, EX_MEMFAIL); \
138 EX_FUNC_LEAVE(EX_FATAL); \
139 } \
140 \
141 for (i = 0; i < LNUMNAME; i++) { \
142 if (SNUMNAME[i] == 0) /* Is this a NULL TNAME block? */ \
143 GSTAT[i] = 0; /* change TNAME block status to NULL */ \
144 else \
145 GSTAT[i] = 1; /* change TNAME block status to TRUE */ \
146 } \
147 \
148 /* Next, get variable id of status array */ \
149 if ((status = nc_inq_varid(exoid, VSTATNAME, &varid)) != NC_NOERR) { \
150 snprintf(errmsg, MAX_ERR_LENGTH, \
151 "ERROR: failed to locate " TNAME " block status in file id %d", exoid); \
152 ex_err_fn(exoid, __func__, errmsg, status); \
153 free(GSTAT); \
154 EX_FUNC_LEAVE(EX_FATAL); \
155 } \
156 \
157 status = nc_put_var_int(exoid, varid, GSTAT); \
158 \
159 if (status != NC_NOERR) { \
160 snprintf(errmsg, MAX_ERR_LENGTH, \
161 "ERROR: failed to store " TNAME " block status array to file id %d", exoid); \
162 ex_err_fn(exoid, __func__, errmsg, status); \
163 free(GSTAT); \
164 EX_FUNC_LEAVE(EX_FATAL); \
165 } \
166 \
167 free(GSTAT); \
168 \
169 /* Next, fill out ids array */ \
170 /* first get id of ids array variable */ \
171 if ((status = nc_inq_varid(exoid, VIDNAME, &varid)) != NC_NOERR) { \
172 snprintf(errmsg, MAX_ERR_LENGTH, \
173 "ERROR: failed to locate " TNAME " block ids array in file id %d", exoid); \
174 ex_err_fn(exoid, __func__, errmsg, status); \
175 EX_FUNC_LEAVE(EX_FATAL); \
176 } \
177 \
178 /* then, write out id list */ \
179 if (ids_int64) { \
180 status = nc_put_var_longlong(exoid, varid, SIDNAME); \
181 } \
182 else { \
183 status = nc_put_var_int(exoid, varid, SIDNAME); \
184 } \
185 \
186 if (status != NC_NOERR) { \
187 snprintf(errmsg, MAX_ERR_LENGTH, \
188 "ERROR: failed to store " TNAME " block id array in file id %d", exoid); \
189 ex_err_fn(exoid, __func__, errmsg, status); \
190 EX_FUNC_LEAVE(EX_FATAL); \
191 } \
192 }
193
194 EX_PREPARE_BLOCK("element", elem_work, DIM_NUM_EL_BLK, VAR_STAT_EL_BLK, VAR_ID_EL_BLK,
195 num_elem_blk, param->num_elem_this_blk, param->elem_blk_id, eb_stat);
196 EX_PREPARE_BLOCK("edge", edge_work, DIM_NUM_ED_BLK, VAR_STAT_ED_BLK, VAR_ID_ED_BLK, num_edge_blk,
197 param->num_edge_this_blk, param->edge_blk_id, ed_stat);
198 EX_PREPARE_BLOCK("face", face_work, DIM_NUM_FA_BLK, VAR_STAT_FA_BLK, VAR_ID_FA_BLK, num_face_blk,
199 param->num_face_this_blk, param->face_blk_id, fa_stat);
200
201 if (elem_work == 0 && edge_work == 0 && face_work == 0 && param->define_maps == 0) {
202 /* Nothing to do. This is not an error, but we can save
203 * ourselves from entering define mode by returning here.
204 */
205 EX_FUNC_LEAVE(EX_NOERR);
206 }
207 /* put netcdf file into define mode */
208 if ((status = exi_redef(exoid, __func__)) != NC_NOERR) {
209 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to place file id %d into define mode", exoid);
210 ex_err_fn(exoid, __func__, errmsg, status);
211 EX_FUNC_LEAVE(EX_FATAL);
212 }
213
214 #if defined(EX_CAN_USE_NC_DEF_VAR_FILL)
215 #define EX_PREPARE_ATTRIB_ARRAY(TNAME, CURBLK, DNAME, DVAL, ID, VANAME, VADIM0, VADIM1, VANNAME) \
216 if (DVAL[iblk] > 0) { \
217 if ((status = nc_def_dim(exoid, DNAME(CURBLK + 1), DVAL[iblk], &VADIM1)) != NC_NOERR) { \
218 snprintf(errmsg, MAX_ERR_LENGTH, \
219 "ERROR: failed to define number of attributes in " TNAME " block %" PRId64 \
220 " in file id %d", \
221 ID, exoid); \
222 ex_err_fn(exoid, __func__, errmsg, status); \
223 goto error_ret; /* exit define mode and return */ \
224 } \
225 \
226 dims[0] = VADIM0; \
227 dims[1] = VADIM1; \
228 \
229 if ((status = nc_def_var(exoid, VANAME(CURBLK + 1), nc_flt_code(exoid), 2, dims, &temp)) != \
230 NC_NOERR) { \
231 snprintf(errmsg, MAX_ERR_LENGTH, \
232 "ERROR: failed to define attributes for " TNAME " block %" PRId64 \
233 " in file id %d", \
234 ID, exoid); \
235 ex_err_fn(exoid, __func__, errmsg, status); \
236 goto error_ret; /* exit define mode and return */ \
237 } \
238 exi_compress_variable(exoid, temp, 2); \
239 \
240 /* Attribute names... */ \
241 dims[0] = VADIM1; \
242 dims[1] = strdim; \
243 \
244 if ((status = nc_def_var(exoid, VANNAME(CURBLK + 1), NC_CHAR, 2, dims, &temp)) != NC_NOERR) { \
245 snprintf(errmsg, MAX_ERR_LENGTH, \
246 "ERROR: failed to define " TNAME " attribute name array in file id %d", exoid); \
247 ex_err_fn(exoid, __func__, errmsg, status); \
248 goto error_ret; /* exit define mode and return */ \
249 } \
250 int fill = NC_FILL_CHAR; \
251 nc_def_var_fill(exoid, temp, 0, &fill); \
252 }
253 #else
254 #define EX_PREPARE_ATTRIB_ARRAY(TNAME, CURBLK, DNAME, DVAL, ID, VANAME, VADIM0, VADIM1, VANNAME) \
255 if (DVAL[iblk] > 0) { \
256 if ((status = nc_def_dim(exoid, DNAME(CURBLK + 1), DVAL[iblk], &VADIM1)) != NC_NOERR) { \
257 snprintf(errmsg, MAX_ERR_LENGTH, \
258 "ERROR: failed to define number of attributes in " TNAME " block %" PRId64 \
259 " in file id %d", \
260 ID, exoid); \
261 ex_err_fn(exoid, __func__, errmsg, status); \
262 goto error_ret; /* exit define mode and return */ \
263 } \
264 \
265 dims[0] = VADIM0; \
266 dims[1] = VADIM1; \
267 \
268 if ((status = nc_def_var(exoid, VANAME(CURBLK + 1), nc_flt_code(exoid), 2, dims, &temp)) != \
269 NC_NOERR) { \
270 snprintf(errmsg, MAX_ERR_LENGTH, \
271 "ERROR: failed to define attributes for " TNAME " block %" PRId64 \
272 " in file id %d", \
273 ID, exoid); \
274 ex_err_fn(exoid, __func__, errmsg, status); \
275 goto error_ret; /* exit define mode and return */ \
276 } \
277 exi_compress_variable(exoid, temp, 2); \
278 \
279 /* Attribute names... */ \
280 dims[0] = VADIM1; \
281 dims[1] = strdim; \
282 \
283 if ((status = nc_def_var(exoid, VANNAME(CURBLK + 1), NC_CHAR, 2, dims, &temp)) != NC_NOERR) { \
284 snprintf(errmsg, MAX_ERR_LENGTH, \
285 "ERROR: failed to define " TNAME " attribute name array in file id %d", exoid); \
286 ex_err_fn(exoid, __func__, errmsg, status); \
287 goto error_ret; /* exit define mode and return */ \
288 } \
289 }
290 #endif
291
292 #define EX_PREPARE_CONN(TNAME, BLK, BLKID, BLKSZ, VNAME, DNAME) \
293 if (DNAME > 0) { \
294 int conn_int_type = NC_INT; \
295 if (ex_int64_status(exoid) & EX_BULK_INT64_DB) { \
296 conn_int_type = NC_INT64; \
297 } \
298 dims[0] = BLKSZ; \
299 dims[1] = DNAME; \
300 \
301 if ((status = nc_def_var(exoid, VNAME(BLK + 1), conn_int_type, 2, dims, &connid)) != \
302 NC_NOERR) { \
303 snprintf(errmsg, MAX_ERR_LENGTH, \
304 "ERROR: failed to create " TNAME " connectivity array for block %" PRId64 \
305 " in file id %d", \
306 BLKID, exoid); \
307 ex_err_fn(exoid, __func__, errmsg, status); \
308 goto error_ret; /* exit define mode and return */ \
309 } \
310 exi_compress_variable(exoid, connid, 1); \
311 }
312
313 /* Iterate over edge blocks ... */
314 for (iblk = 0; iblk < num_edge_blk; ++iblk) {
315 ex_entity_id eb_id;
316 if (ids_int64) {
317 eb_id = edge_id_int64[iblk];
318 }
319 else {
320 eb_id = edge_id_int[iblk];
321 }
322
323 cur_num_edge_blk = exi_get_file_item(exoid, exi_get_counter_list(EX_EDGE_BLOCK));
324 if (cur_num_edge_blk >= (int)num_edge_blk) {
325 snprintf(errmsg, MAX_ERR_LENGTH,
326 "ERROR: exceeded number of edge blocks (%ld) defined in file id %d",
327 (long)num_edge_blk, exoid);
328 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
329 goto error_ret;
330 }
331
332 /* NOTE: exi_inc_file_item is used to find the number of edge blocks
333 for a specific file and returns that value incremented. */
334 cur_num_edge_blk = exi_inc_file_item(exoid, exi_get_counter_list(EX_EDGE_BLOCK));
335
336 if (param->num_edge_this_blk[iblk] == 0) { /* Is this a NULL edge block? */
337 continue;
338 }
339
340 /* define some dimensions and variables*/
341 if ((status = nc_def_dim(exoid, DIM_NUM_ED_IN_EBLK(cur_num_edge_blk + 1),
342 param->num_edge_this_blk[iblk], &numedbdim)) != NC_NOERR) {
343 if (status == NC_ENAMEINUSE) { /* duplicate entry */
344 snprintf(errmsg, MAX_ERR_LENGTH,
345 "ERROR: edge block %" PRId64 " already defined in file id %d", eb_id, exoid);
346 }
347 else {
348 snprintf(errmsg, MAX_ERR_LENGTH,
349 "ERROR: failed to define number of edges/block for block %" PRId64 " file id %d",
350 eb_id, exoid);
351 }
352 ex_err_fn(exoid, __func__, errmsg, status);
353 goto error_ret; /* exit define mode and return */
354 }
355
356 if ((status = nc_def_dim(exoid, DIM_NUM_NOD_PER_ED(cur_num_edge_blk + 1),
357 param->num_nodes_per_edge[iblk], &nednoddim)) != NC_NOERR) {
358 snprintf(errmsg, MAX_ERR_LENGTH,
359 "ERROR: failed to define number of nodes/edge for block %" PRId64 " in file id %d",
360 eb_id, exoid);
361 ex_err_fn(exoid, __func__, errmsg, status);
362 goto error_ret; /* exit define mode and return */
363 }
364
365 /* edge attribute array */
366 EX_PREPARE_ATTRIB_ARRAY("edge", cur_num_edge_blk, DIM_NUM_ATT_IN_EBLK, param->num_attr_edge,
367 eb_id, VAR_EATTRIB, numedbdim, numattrdim, VAR_NAME_EATTRIB);
368
369 EX_PREPARE_CONN("edge block", cur_num_edge_blk, eb_id, numedbdim, VAR_EBCONN, nednoddim);
370
371 /* store edge type as attribute of connectivity variable */
372 if ((status = nc_put_att_text(exoid, connid, ATT_NAME_ELB, strlen(param->edge_type[iblk]) + 1,
373 (void *)param->edge_type[iblk])) != NC_NOERR) {
374 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store edge type name %s in file id %d",
375 param->edge_type[iblk], exoid);
376 ex_err_fn(exoid, __func__, errmsg, status);
377 goto error_ret; /* exit define mode and return */
378 }
379 }
380
381 /* Iterate over face blocks ... */
382 for (iblk = 0; iblk < num_face_blk; ++iblk) {
383 ex_entity_id fb_id;
384 if (ids_int64) {
385 fb_id = face_id_int64[iblk];
386 }
387 else {
388 fb_id = face_id_int[iblk];
389 }
390
391 cur_num_face_blk = exi_get_file_item(exoid, exi_get_counter_list(EX_FACE_BLOCK));
392 if (cur_num_face_blk >= (int)num_face_blk) {
393 snprintf(errmsg, MAX_ERR_LENGTH,
394 "ERROR: exceeded number of face blocks (%ld) defined in file id %d",
395 (long)num_face_blk, exoid);
396 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
397 goto error_ret;
398 }
399
400 /* NOTE: exi_inc_file_item is used to find the number of edge blocks
401 for a specific file and returns that value incremented. */
402 cur_num_face_blk = exi_inc_file_item(exoid, exi_get_counter_list(EX_FACE_BLOCK));
403
404 if (param->num_face_this_blk[iblk] == 0) { /* Is this a NULL face block? */
405 continue;
406 }
407
408 /* define some dimensions and variables*/
409 if ((status = nc_def_dim(exoid, DIM_NUM_FA_IN_FBLK(cur_num_face_blk + 1),
410 param->num_face_this_blk[iblk], &numfabdim)) != NC_NOERR) {
411 if (status == NC_ENAMEINUSE) { /* duplicate entry */
412 snprintf(errmsg, MAX_ERR_LENGTH,
413 "ERROR: face block %" PRId64 " already defined in file id %d", fb_id, exoid);
414 }
415 else {
416 snprintf(errmsg, MAX_ERR_LENGTH,
417 "ERROR: failed to define number of faces/block for block %" PRId64 " file id %d",
418 fb_id, exoid);
419 }
420 ex_err_fn(exoid, __func__, errmsg, status);
421 goto error_ret; /* exit define mode and return */
422 }
423
424 if ((status = nc_def_dim(exoid, DIM_NUM_NOD_PER_FA(cur_num_face_blk + 1),
425 param->num_nodes_per_face[iblk], &nfanoddim)) != NC_NOERR) {
426 snprintf(errmsg, MAX_ERR_LENGTH,
427 "ERROR: failed to define number of nodes/face for block %" PRId64 " in file id %d",
428 fb_id, exoid);
429 ex_err_fn(exoid, __func__, errmsg, status);
430 goto error_ret; /* exit define mode and return */
431 }
432
433 /* face attribute array */
434 EX_PREPARE_ATTRIB_ARRAY("face", cur_num_face_blk, DIM_NUM_ATT_IN_FBLK, param->num_attr_face,
435 fb_id, VAR_FATTRIB, numfabdim, numattrdim, VAR_NAME_FATTRIB);
436
437 EX_PREPARE_CONN("face block", cur_num_face_blk, fb_id, numfabdim, VAR_FBCONN, nfanoddim);
438
439 /* store face type as attribute of connectivity variable */
440 if ((status = nc_put_att_text(exoid, connid, ATT_NAME_ELB, strlen(param->face_type[iblk]) + 1,
441 (void *)param->face_type[iblk])) != NC_NOERR) {
442 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store face type name %s in file id %d",
443 param->face_type[iblk], exoid);
444 ex_err_fn(exoid, __func__, errmsg, status);
445 goto error_ret; /* exit define mode and return */
446 }
447 }
448
449 /* Iterate over element blocks ... */
450 for (iblk = 0; iblk < num_elem_blk; ++iblk) {
451 ex_entity_id eb_id;
452 if (ids_int64) {
453 eb_id = elem_id_int64[iblk];
454 }
455 else {
456 eb_id = elem_id_int[iblk];
457 }
458
459 cur_num_elem_blk = exi_get_file_item(exoid, exi_get_counter_list(EX_ELEM_BLOCK));
460 if (cur_num_elem_blk >= (int)num_elem_blk) {
461 snprintf(errmsg, MAX_ERR_LENGTH,
462 "ERROR: exceeded number of element blocks (%ld) defined "
463 "in file id %d",
464 (long)num_elem_blk, exoid);
465 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
466 goto error_ret;
467 }
468
469 /* NOTE: exi_inc_file_item is used to find the number of element blocks
470 for a specific file and returns that value incremented. */
471 cur_num_elem_blk = exi_inc_file_item(exoid, exi_get_counter_list(EX_ELEM_BLOCK));
472
473 if (param->num_elem_this_blk[iblk] == 0) { /* Is this a NULL element block? */
474 continue;
475 }
476
477 /* define some dimensions and variables*/
478 if ((status = nc_def_dim(exoid, DIM_NUM_EL_IN_BLK(cur_num_elem_blk + 1),
479 param->num_elem_this_blk[iblk], &numelbdim)) != NC_NOERR) {
480 if (status == NC_ENAMEINUSE) { /* duplicate entry */
481 snprintf(errmsg, MAX_ERR_LENGTH,
482 "ERROR: element block %" PRId64 " already defined in file id %d", eb_id, exoid);
483 }
484 else {
485 snprintf(errmsg, MAX_ERR_LENGTH,
486 "ERROR: failed to define number of elements/block for "
487 "block %" PRId64 " file id %d",
488 eb_id, exoid);
489 }
490 ex_err_fn(exoid, __func__, errmsg, status);
491 goto error_ret; /* exit define mode and return */
492 }
493
494 /* Always define DIM_NUM_NOD_PER_EL, even if zero.
495 * Do not define DIM_NUM_EDG_PER_EL or DIM_NUM_FAC_PER_EL unless > 0.
496 */
497 if ((status = nc_def_dim(exoid, DIM_NUM_NOD_PER_EL(cur_num_elem_blk + 1),
498 param->num_nodes_per_elem[iblk], &nelnoddim)) != NC_NOERR) {
499 snprintf(errmsg, MAX_ERR_LENGTH,
500 "ERROR: failed to define number of nodes/element for block %" PRId64
501 " in file id %d",
502 eb_id, exoid);
503 ex_err_fn(exoid, __func__, errmsg, status);
504 goto error_ret; /* exit define mode and return */
505 }
506
507 if (param->num_edges_per_elem[iblk] > 0) {
508 if ((status = nc_def_dim(exoid, DIM_NUM_EDG_PER_EL(cur_num_elem_blk + 1),
509 param->num_edges_per_elem[iblk], &neledgdim)) != NC_NOERR) {
510 snprintf(errmsg, MAX_ERR_LENGTH,
511 "ERROR: failed to define number of edges/element for block %" PRId64
512 " in file id %d",
513 eb_id, exoid);
514 ex_err_fn(exoid, __func__, errmsg, status);
515 goto error_ret; /* exit define mode and return */
516 }
517 }
518
519 if (param->num_faces_per_elem[iblk] > 0) {
520 if ((status = nc_def_dim(exoid, DIM_NUM_FAC_PER_EL(cur_num_elem_blk + 1),
521 param->num_faces_per_elem[iblk], &nelfacdim)) != NC_NOERR) {
522 snprintf(errmsg, MAX_ERR_LENGTH,
523 "ERROR: failed to define number of faces/element for block %" PRId64
524 " in file id %d",
525 eb_id, exoid);
526 ex_err_fn(exoid, __func__, errmsg, status);
527 goto error_ret; /* exit define mode and return */
528 }
529 }
530
531 EX_PREPARE_ATTRIB_ARRAY("element", cur_num_elem_blk, DIM_NUM_ATT_IN_BLK, param->num_attr_elem,
532 eb_id, VAR_ATTRIB, numelbdim, numattrdim, VAR_NAME_ATTRIB);
533
534 EX_PREPARE_CONN("nodal", cur_num_elem_blk, eb_id, numelbdim, VAR_CONN, nelnoddim);
535
536 /* store element type as attribute of connectivity variable */
537 if ((status = nc_put_att_text(exoid, connid, ATT_NAME_ELB, strlen(param->elem_type[iblk]) + 1,
538 (void *)param->elem_type[iblk])) != NC_NOERR) {
539 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store element type name %s in file id %d",
540 param->elem_type[iblk], exoid);
541 ex_err_fn(exoid, __func__, errmsg, status);
542 goto error_ret; /* exit define mode and return */
543 }
544
545 EX_PREPARE_CONN("edge", cur_num_elem_blk, eb_id, numelbdim, VAR_ECONN, neledgdim);
546 EX_PREPARE_CONN("face", cur_num_elem_blk, eb_id, numelbdim, VAR_FCONN, nelfacdim);
547 }
548
549 /* Define the element map here to avoid a later redefine call */
550 if (param->define_maps != 0) {
551 size_t map_type;
552 for (map_type = 0; map_type < num_map_dims; ++map_type) {
553 if ((status = nc_inq_dimid(exoid, dim_size_maps[map_type], &dims[0])) != NC_NOERR) {
554 snprintf(errmsg, MAX_ERR_LENGTH,
555 "ERROR: could not find map size dimension %s in file id %d",
556 dim_size_maps[map_type], exoid);
557 ex_err_fn(exoid, __func__, errmsg, status);
558 }
559 for (i = 1; i <= num_maps[map_type]; ++i) {
560 const char *mapname = exi_name_of_map(map_enums[map_type], i);
561 if (nc_inq_varid(exoid, mapname, &temp) != NC_NOERR) {
562 int map_int_type = NC_INT;
563 if (ex_int64_status(exoid) & EX_MAPS_INT64_DB) {
564 map_int_type = NC_INT64;
565 }
566
567 if ((status = nc_def_var(exoid, mapname, map_int_type, 1, dims, &temp)) != NC_NOERR) {
568 if (status == NC_ENAMEINUSE) {
569 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: number map %s already exists in file id %d",
570 mapname, exoid);
571 }
572 else {
573 snprintf(errmsg, MAX_ERR_LENGTH,
574 "ERROR: failed to create number map array %s in file id %d", mapname, exoid);
575 }
576 ex_err_fn(exoid, __func__, errmsg, status);
577 goto error_ret; /* exit define mode and return */
578 }
579 exi_compress_variable(exoid, temp, 1);
580 }
581 }
582 }
583 }
584
585 /* leave define mode */
586 if ((status = exi_leavedef(exoid, __func__)) != NC_NOERR) {
587 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to exit define mode");
588 ex_err_fn(exoid, __func__, errmsg, status);
589 EX_FUNC_LEAVE(EX_FATAL);
590 }
591
592 EX_FUNC_LEAVE(EX_NOERR);
593
594 /* Fatal error: exit definition mode and return */
595 error_ret:
596 exi_leavedef(exoid, __func__);
597 EX_FUNC_LEAVE(EX_FATAL);
598 }