Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-2025 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 * expinix - ex_put_init_ext
11 *
12 * entry conditions -
13 * input parameters:
14 * int exoid exodus file id
15 * const ex_init_params* params finite element model parameters
16 *
17 * exit conditions -
18 *
19 * revision history -
20 * David Thompson - Added edge/face blocks/sets
21 *
22 *
23 *****************************************************************************/
24
25 #include "exodusII.h" // for ex_init_params, ex_err, etc
26 #include "exodusII_int.h" // for nc_flt_code, etc
27
28 static void write_dummy_names(int exoid, ex_entity_type obj_type, int num)
29 {
30 if (num > 0) {
31 int varid;
32 size_t num_entity;
33 exi_get_dimension(exoid, exi_dim_num_objects(obj_type), ex_name_of_object(obj_type),
34 &num_entity, &varid, __func__);
35
36 char *text = "";
37 for (size_t i = 0; i < num_entity; i++) {
38 size_t start[] = {i, 0, 0};
39 size_t count[] = {1, 1, 1};
40 nc_put_vara_text(exoid, varid, start, count, text);
41 }
42 }
43 }
44
45 static int ex_write_object_names(int exoid, const char *type, const char *dimension_name,
46 int dimension_var, int string_dimension, int count)
47 {
48
49 if (count > 0) {
50 int dim[] = {dimension_var, string_dimension};
51 int status;
52 int varid;
53 if ((status = nc_def_var(exoid, dimension_name, NC_CHAR, 2, dim, &varid)) != NC_NOERR) {
54 char errmsg[MAX_ERR_LENGTH];
55 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define %s name array in file id %d", type,
56 exoid);
57 ex_err_fn(exoid, __func__, errmsg, status);
58 return status; /* exit define mode and return */
59 }
60 exi_set_compact_storage(exoid, varid);
61 #if defined(EX_CAN_USE_NC_DEF_VAR_FILL)
62 int fill = NC_FILL_CHAR;
63 nc_def_var_fill(exoid, varid, 0, &fill);
64 #endif
65 }
66 return EX_NOERR;
67 }
68
69 static int ex_write_object_params(int exoid, const char *type, const char *dimension_name,
70 const char *status_dim_name, const char *id_array_dim_name,
71 size_t count, int *dimension)
72 {
73
74 /* Can have nonzero model->num_elem_blk even if model->num_elem == 0 */
75 if (count > 0) {
76 int status;
77 if ((status = nc_def_dim(exoid, dimension_name, count, dimension)) != NC_NOERR) {
78 char errmsg[MAX_ERR_LENGTH];
79 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of %ss in file id %d", type,
80 exoid);
81 ex_err_fn(exoid, __func__, errmsg, status);
82 return status; /* exit define mode and return */
83 }
84 /* ...and some variables */
85 /* element block id status array */
86 int dim[2];
87 int varid;
88 dim[0] = *dimension;
89 if ((status = nc_def_var(exoid, status_dim_name, NC_INT, 1, dim, &varid)) != NC_NOERR) {
90 char errmsg[MAX_ERR_LENGTH];
91 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define %s status array in file id %d",
92 type, exoid);
93 ex_err_fn(exoid, __func__, errmsg, status);
94 return status; /* exit define mode and return */
95 }
96
97 size_t sixty_four_kb = 64 * 1024; // Compact storage can only be used for < 64KiByte data sizes
98 if (4 * count < sixty_four_kb) {
99 exi_set_compact_storage(exoid, varid);
100 }
101
102 /* type id array */
103 int int_type = NC_INT;
104 int int_size = 4;
105 if (ex_int64_status(exoid) & EX_IDS_INT64_DB) {
106 int_type = NC_INT64;
107 int_size = 8;
108 }
109
110 if ((status = nc_def_var(exoid, id_array_dim_name, int_type, 1, dim, &varid)) != NC_NOERR) {
111 char errmsg[MAX_ERR_LENGTH];
112 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define %s id array in file id %d", type,
113 exoid);
114 ex_err_fn(exoid, __func__, errmsg, status);
115 return status; /* exit define mode and return */
116 }
117 if (int_size * count < sixty_four_kb) {
118 exi_set_compact_storage(exoid, varid);
119 }
120
121 /* store property name as attribute of property array variable */
122 if ((status = nc_put_att_text(exoid, varid, ATT_PROP_NAME, 3, "ID")) != NC_NOERR) {
123 char errmsg[MAX_ERR_LENGTH];
124 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store %s property name %s in file id %d",
125 type, "ID", exoid);
126 ex_err_fn(exoid, __func__, errmsg, status);
127 return status;
128 }
129 }
130 return EX_NOERR;
131 }
132
133 static int ex_write_map_params(int exoid, const char *map_name, const char *map_dim_name,
134 const char *map_id_name, size_t map_count, int *map_dimension)
135 {
136
137 int int_type = NC_INT;
138 if (ex_int64_status(exoid) & EX_IDS_INT64_DB) {
139 int_type = NC_INT64;
140 }
141
142 /* Can have nonzero model->num_XXXX_map even if model->num_XXXX == 0 */
143 if ((map_count) > 0) {
144 int status;
145 if ((status = nc_def_dim(exoid, map_dim_name, map_count, map_dimension)) != NC_NOERR) {
146 char errmsg[MAX_ERR_LENGTH];
147 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of %ss in file id %d",
148 map_name, exoid);
149 ex_err_fn(exoid, __func__, errmsg, status);
150 return status; /* exit define mode and return */
151 }
152
153 int dim[] = {*map_dimension};
154
155 /* map_name id array */
156 int varid;
157 if ((status = nc_def_var(exoid, map_id_name, int_type, 1, dim, &varid)) != NC_NOERR) {
158 char errmsg[MAX_ERR_LENGTH];
159 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define %s id array in file id %d",
160 map_name, exoid);
161 ex_err_fn(exoid, __func__, errmsg, status);
162 return status; /* exit define mode and return */
163 }
164
165 /* store property name as attribute of property array variable */
166 if ((status = nc_put_att_text(exoid, varid, ATT_PROP_NAME, 3, "ID")) != NC_NOERR) {
167 char errmsg[MAX_ERR_LENGTH];
168 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store %s property name %s in file id %d",
169 map_name, "ID", exoid);
170 ex_err_fn(exoid, __func__, errmsg, status);
171 return EX_FATAL;
172 }
173 }
174 return EX_NOERR;
175 }
176
177 static void invalidate_id_status(int exoid, const char *var_stat, const char *var_id, int count,
178 int *ids)
179 {
180 if (count > 0) {
181 if (var_id != NULL) {
182 for (int i = 0; i < count; i++) {
183 ids[i] = EX_INVALID_ID;
184 }
185 int id_var;
186 (void)nc_inq_varid(exoid, var_id, &id_var);
187 (void)nc_put_var_int(exoid, id_var, ids);
188 }
189
190 if (var_stat != NULL) {
191 for (int i = 0; i < count; i++) {
192 ids[i] = 0;
193 }
194
195 int stat_var;
196 (void)nc_inq_varid(exoid, var_stat, &stat_var);
197 (void)nc_put_var_int(exoid, stat_var, ids);
198 }
199 }
200 }
201
202 /*!
203 \ingroup ModelDescription
204
205 * writes the initialization parameters to the EXODUS file
206 * \param exoid exodus file id
207 * \param model finite element model parameters
208 */
209
210 int ex_put_init_ext(int exoid, const ex_init_params *model)
211 {
212 int numdimdim = 0;
213 int numnoddim = 0;
214 int elblkdim = 0;
215 int edblkdim = 0;
216 int fablkdim = 0;
217 int esetdim = 0;
218 int fsetdim = 0;
219 int elsetdim = 0;
220 int nsetdim = 0;
221 int ssetdim = 0;
222 int dim_str_name = 0;
223 int dim[2];
224 int temp = 0;
225 int nmapdim = 0;
226 int edmapdim = 0;
227 int famapdim = 0;
228 int emapdim = 0;
229 int timedim = 0;
230 int status = 0;
231 int title_len = 0;
232
233 EX_FUNC_ENTER();
234 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
235 EX_FUNC_LEAVE(EX_FATAL);
236 }
237 int rootid = exoid & EX_FILE_ID_MASK;
238
239 if (rootid == exoid && nc_inq_dimid(exoid, DIM_NUM_DIM, &temp) == NC_NOERR) {
240 char errmsg[MAX_ERR_LENGTH];
241 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: initialization already done for file id %d", exoid);
242 ex_err_fn(exoid, __func__, errmsg, EX_MSG);
243 EX_FUNC_LEAVE(EX_FATAL);
244 }
245
246 /* put file into define mode */
247 if ((status = exi_redef(exoid, __func__)) != NC_NOERR) {
248 char errmsg[MAX_ERR_LENGTH];
249 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file id %d into define mode", exoid);
250 ex_err_fn(exoid, __func__, errmsg, status);
251 EX_FUNC_LEAVE(EX_FATAL);
252 }
253
254 /* define some attributes... */
255 title_len = strlen(model->title) < MAX_LINE_LENGTH ? strlen(model->title) : MAX_LINE_LENGTH;
256 if ((status = nc_put_att_text(rootid, NC_GLOBAL, (const char *)ATT_TITLE, title_len + 1,
257 model->title)) != NC_NOERR) {
258 char errmsg[MAX_ERR_LENGTH];
259 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define model->title attribute to file id %d",
260 rootid);
261 ex_err_fn(exoid, __func__, errmsg, status);
262 goto error_ret; /* exit define mode and return */
263 }
264
265 /* ...and some dimensions... */
266
267 /* create name string length dimension */
268 if (nc_inq_dimid(rootid, DIM_STR_NAME, &dim_str_name) != NC_NOERR) {
269 if ((status = nc_def_dim(rootid, DIM_STR_NAME, NC_MAX_NAME, &dim_str_name)) != NC_NOERR) {
270 char errmsg[MAX_ERR_LENGTH];
271 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define name string length in file id %d",
272 rootid);
273 ex_err_fn(exoid, __func__, errmsg, status);
274 goto error_ret;
275 }
276 }
277
278 if ((status = nc_def_dim(exoid, DIM_TIME, NC_UNLIMITED, &timedim)) != NC_NOERR) {
279 char errmsg[MAX_ERR_LENGTH];
280 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define time dimension in file id %d", exoid);
281 ex_err_fn(exoid, __func__, errmsg, status);
282 goto error_ret;
283 }
284
285 dim[0] = timedim;
286 if ((status = nc_def_var(exoid, VAR_WHOLE_TIME, nc_flt_code(exoid), 1, dim, &temp)) != NC_NOERR) {
287 char errmsg[MAX_ERR_LENGTH];
288 snprintf(errmsg, MAX_ERR_LENGTH,
289 "ERROR: failed to define whole time step variable in file id %d", exoid);
290 ex_err_fn(exoid, __func__, errmsg, status);
291 goto error_ret;
292 }
293
294 {
295 struct exi_file_item *file = exi_find_file_item(exoid);
296 if (!file) {
297 char errmsg[MAX_ERR_LENGTH];
298 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unknown file id %d.", exoid);
299 ex_err_fn(exoid, __func__, errmsg, EX_BADFILEID);
300 goto error_ret;
301 }
302 file->time_varid = temp;
303 }
304
305 exi_compress_variable(exoid, temp, -2); /* Don't compress, but do set collective io */
306
307 if (model->num_dim > 0) {
308 if ((status = nc_def_dim(exoid, DIM_NUM_DIM, model->num_dim, &numdimdim)) != NC_NOERR) {
309 char errmsg[MAX_ERR_LENGTH];
310 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of dimensions in file id %d",
311 exoid);
312 ex_err_fn(exoid, __func__, errmsg, status);
313 goto error_ret; /* exit define mode and return */
314 }
315 }
316
317 /*
318 * Need to handle "empty file" that may be the result of a strange
319 * load balance or some other strange run. Note that if num_node
320 * == 0, then model->num_elem must be zero since you cannot have elements
321 * with no nodes. It *is* permissible to have zero elements with
322 * non-zero node count.
323 */
324
325 int int_size = ex_int64_status(exoid) & EX_IDS_INT64_DB ? 8 : 4;
326 size_t twoGiB = 1ul << 31;
327
328 if (model->num_nodes > 0) {
329 // If file is using 32-bit integers, check what node count is in range...
330 if (int_size == 4 && model->num_nodes >= twoGiB) {
331 char errmsg[MAX_ERR_LENGTH];
332 snprintf(errmsg, MAX_ERR_LENGTH,
333 "ERROR: File is using 32-bit integers, but the node count exceeds the integer "
334 "capacity (%" PRId64 ") in file id %d",
335 model->num_nodes, exoid);
336 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
337 goto error_ret;
338 }
339
340 if ((status = nc_def_dim(exoid, DIM_NUM_NODES, model->num_nodes, &numnoddim)) != NC_NOERR) {
341 char errmsg[MAX_ERR_LENGTH];
342 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of nodes in file id %d",
343 exoid);
344 ex_err_fn(exoid, __func__, errmsg, status);
345 goto error_ret; /* exit define mode and return */
346 }
347 }
348
349 if (model->num_elem > 0) {
350 if (model->num_nodes <= 0) {
351 char errmsg[MAX_ERR_LENGTH];
352 snprintf(errmsg, MAX_ERR_LENGTH,
353 "ERROR: Cannot have non-zero element count if node count "
354 "is zero.in file id %d",
355 exoid);
356 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
357 goto error_ret; /* exit define mode and return */
358 }
359
360 if (int_size == 4 && model->num_elem >= twoGiB) {
361 char errmsg[MAX_ERR_LENGTH];
362 snprintf(errmsg, MAX_ERR_LENGTH,
363 "ERROR: File is using 32-bit integers, but the element count exceeds the integer "
364 "capacity (%" PRId64 ") in file id %d",
365 model->num_elem, exoid);
366 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
367 goto error_ret;
368 }
369
370 if ((status = nc_def_dim(exoid, DIM_NUM_ELEM, model->num_elem, &temp)) != NC_NOERR) {
371 char errmsg[MAX_ERR_LENGTH];
372 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of elements in file id %d",
373 exoid);
374 ex_err_fn(exoid, __func__, errmsg, status);
375 goto error_ret; /* exit define mode and return */
376 }
377 }
378
379 if (model->num_edge > 0) {
380 if (model->num_nodes <= 0) {
381 char errmsg[MAX_ERR_LENGTH];
382 snprintf(errmsg, MAX_ERR_LENGTH,
383 "ERROR: Cannot have non-zero edge count if node count is "
384 "zero.in file id %d",
385 exoid);
386 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
387 goto error_ret; /* exit define mode and return */
388 }
389
390 if ((status = nc_def_dim(exoid, DIM_NUM_EDGE, model->num_edge, &temp)) != NC_NOERR) {
391 char errmsg[MAX_ERR_LENGTH];
392 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of edges in file id %d",
393 exoid);
394 ex_err_fn(exoid, __func__, errmsg, status);
395 goto error_ret; /* exit define mode and return */
396 }
397 }
398
399 if (model->num_face > 0) {
400 if (model->num_nodes <= 0) {
401 char errmsg[MAX_ERR_LENGTH];
402 snprintf(errmsg, MAX_ERR_LENGTH,
403 "ERROR: Cannot have non-zero face count if node count is "
404 "zero.in file id %d",
405 exoid);
406 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
407 goto error_ret; /* exit define mode and return */
408 }
409
410 if ((status = nc_def_dim(exoid, DIM_NUM_FACE, model->num_face, &temp)) != NC_NOERR) {
411 char errmsg[MAX_ERR_LENGTH];
412 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of faces in file id %d",
413 exoid);
414 ex_err_fn(exoid, __func__, errmsg, status);
415 goto error_ret; /* exit define mode and return */
416 }
417 }
418
419 if (ex_write_object_params(exoid, "element block", DIM_NUM_EL_BLK, VAR_STAT_EL_BLK, VAR_ID_EL_BLK,
420 model->num_elem_blk, &elblkdim)) {
421 goto error_ret;
422 }
423 if (ex_write_object_params(exoid, "edge block", DIM_NUM_ED_BLK, VAR_STAT_ED_BLK, VAR_ID_ED_BLK,
424 model->num_edge_blk, &edblkdim)) {
425 goto error_ret;
426 }
427 if (ex_write_object_params(exoid, "face block", DIM_NUM_FA_BLK, VAR_STAT_FA_BLK, VAR_ID_FA_BLK,
428 model->num_face_blk, &fablkdim)) {
429 goto error_ret;
430 }
431
432 if (ex_write_object_params(exoid, "node set", DIM_NUM_NS, VAR_NS_STAT, VAR_NS_IDS,
433 model->num_node_sets, &nsetdim)) {
434 goto error_ret;
435 }
436 if (ex_write_object_params(exoid, "edge set", DIM_NUM_ES, VAR_ES_STAT, VAR_ES_IDS,
437 model->num_edge_sets, &esetdim)) {
438 goto error_ret;
439 }
440 if (ex_write_object_params(exoid, "face set", DIM_NUM_FS, VAR_FS_STAT, VAR_FS_IDS,
441 model->num_face_sets, &fsetdim)) {
442 goto error_ret;
443 }
444 if (ex_write_object_params(exoid, "side set", DIM_NUM_SS, VAR_SS_STAT, VAR_SS_IDS,
445 model->num_side_sets, &ssetdim)) {
446 goto error_ret;
447 }
448 if (ex_write_object_params(exoid, "elem set", DIM_NUM_ELS, VAR_ELS_STAT, VAR_ELS_IDS,
449 model->num_elem_sets, &elsetdim)) {
450 goto error_ret;
451 }
452
453 if (ex_write_map_params(exoid, "node map", DIM_NUM_NM, VAR_NM_PROP(1), model->num_node_maps,
454 &nmapdim) != NC_NOERR) {
455 goto error_ret;
456 }
457 if (ex_write_map_params(exoid, "edge map", DIM_NUM_EDM, VAR_EDM_PROP(1), model->num_edge_maps,
458 &edmapdim) != NC_NOERR) {
459 goto error_ret;
460 }
461 if (ex_write_map_params(exoid, "face map", DIM_NUM_FAM, VAR_FAM_PROP(1), model->num_face_maps,
462 &famapdim) != NC_NOERR) {
463 goto error_ret;
464 }
465 if (ex_write_map_params(exoid, "element map", DIM_NUM_EM, VAR_EM_PROP(1), model->num_elem_maps,
466 &emapdim) != NC_NOERR) {
467 goto error_ret;
468 }
469
470 if (model->num_nodes > 0) {
471 dim[0] = numnoddim;
472 if (model->num_dim > 0) {
473 if ((status = nc_def_var(exoid, VAR_COORD_X, nc_flt_code(exoid), 1, dim, &temp)) !=
474 NC_NOERR) {
475 char errmsg[MAX_ERR_LENGTH];
476 snprintf(errmsg, MAX_ERR_LENGTH,
477 "ERROR: failed to define node x coordinate array in file id %d", exoid);
478 ex_err_fn(exoid, __func__, errmsg, status);
479 goto error_ret; /* exit define mode and return */
480 }
481 exi_compress_variable(exoid, temp, 2);
482 }
483
484 if (model->num_dim > 1) {
485 if ((status = nc_def_var(exoid, VAR_COORD_Y, nc_flt_code(exoid), 1, dim, &temp)) !=
486 NC_NOERR) {
487 char errmsg[MAX_ERR_LENGTH];
488 snprintf(errmsg, MAX_ERR_LENGTH,
489 "ERROR: failed to define node y coordinate array in file id %d", exoid);
490 ex_err_fn(exoid, __func__, errmsg, status);
491 goto error_ret; /* exit define mode and return */
492 }
493 exi_compress_variable(exoid, temp, 2);
494 }
495
496 if (model->num_dim > 2) {
497 if ((status = nc_def_var(exoid, VAR_COORD_Z, nc_flt_code(exoid), 1, dim, &temp)) !=
498 NC_NOERR) {
499 char errmsg[MAX_ERR_LENGTH];
500 snprintf(errmsg, MAX_ERR_LENGTH,
501 "ERROR: failed to define node z coordinate array in file id %d", exoid);
502 ex_err_fn(exoid, __func__, errmsg, status);
503 goto error_ret; /* exit define mode and return */
504 }
505 exi_compress_variable(exoid, temp, 2);
506 }
507 }
508
509 if (ex_write_object_names(exoid, "element block", VAR_NAME_EL_BLK, elblkdim, dim_str_name,
510 model->num_elem_blk) != NC_NOERR) {
511 goto error_ret;
512 }
513 if (ex_write_object_names(exoid, "edge block", VAR_NAME_ED_BLK, edblkdim, dim_str_name,
514 model->num_edge_blk) != NC_NOERR) {
515 goto error_ret;
516 }
517 if (ex_write_object_names(exoid, "face block", VAR_NAME_FA_BLK, fablkdim, dim_str_name,
518 model->num_face_blk) != NC_NOERR) {
519 goto error_ret;
520 }
521 if (ex_write_object_names(exoid, "node set", VAR_NAME_NS, nsetdim, dim_str_name,
522 model->num_node_sets) != NC_NOERR) {
523 goto error_ret;
524 }
525 if (ex_write_object_names(exoid, "edge set", VAR_NAME_ES, esetdim, dim_str_name,
526 model->num_edge_sets) != NC_NOERR) {
527 goto error_ret;
528 }
529 if (ex_write_object_names(exoid, "face set", VAR_NAME_FS, fsetdim, dim_str_name,
530 model->num_face_sets) != NC_NOERR) {
531 goto error_ret;
532 }
533 if (ex_write_object_names(exoid, "side set", VAR_NAME_SS, ssetdim, dim_str_name,
534 model->num_side_sets) != NC_NOERR) {
535 goto error_ret;
536 }
537 if (ex_write_object_names(exoid, "element set", VAR_NAME_ELS, elsetdim, dim_str_name,
538 model->num_elem_sets) != NC_NOERR) {
539 goto error_ret;
540 }
541 if (ex_write_object_names(exoid, "node map", VAR_NAME_NM, nmapdim, dim_str_name,
542 model->num_node_maps) != NC_NOERR) {
543 goto error_ret;
544 }
545 if (ex_write_object_names(exoid, "edge map", VAR_NAME_EDM, edmapdim, dim_str_name,
546 model->num_edge_maps) != NC_NOERR) {
547 goto error_ret;
548 }
549 if (ex_write_object_names(exoid, "face map", VAR_NAME_FAM, famapdim, dim_str_name,
550 model->num_face_maps) != NC_NOERR) {
551 goto error_ret;
552 }
553 if (ex_write_object_names(exoid, "element map", VAR_NAME_EM, emapdim, dim_str_name,
554 model->num_elem_maps) != NC_NOERR) {
555 goto error_ret;
556 }
557 if (model->num_dim > 0) {
558 if (ex_write_object_names(exoid, "coordinate", VAR_NAME_COOR, numdimdim, dim_str_name,
559 model->num_dim) != NC_NOERR) {
560 goto error_ret;
561 }
562 }
563
564 /* leave define mode */
565 if ((status = exi_leavedef(exoid, __func__)) != NC_NOERR) {
566 char errmsg[MAX_ERR_LENGTH];
567 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to exit define mode");
568 ex_err_fn(exoid, __func__, errmsg, status);
569 EX_FUNC_LEAVE(EX_FATAL);
570 }
571
572 /* Fill the id and status arrays with EX_INVALID_ID */
573 {
574 int *invalid_ids = NULL;
575 int64_t maxset = model->num_elem_blk;
576 if (maxset < model->num_edge_blk) {
577 maxset = model->num_edge_blk;
578 }
579 if (maxset < model->num_face_blk) {
580 maxset = model->num_face_blk;
581 }
582 if (maxset < model->num_node_sets) {
583 maxset = model->num_node_sets;
584 }
585 if (maxset < model->num_edge_sets) {
586 maxset = model->num_edge_sets;
587 }
588 if (maxset < model->num_face_sets) {
589 maxset = model->num_face_sets;
590 }
591 if (maxset < model->num_side_sets) {
592 maxset = model->num_side_sets;
593 }
594 if (maxset < model->num_elem_sets) {
595 maxset = model->num_elem_sets;
596 }
597 if (maxset < model->num_node_maps) {
598 maxset = model->num_node_maps;
599 }
600 if (maxset < model->num_edge_maps) {
601 maxset = model->num_edge_maps;
602 }
603 if (maxset < model->num_face_maps) {
604 maxset = model->num_face_maps;
605 }
606 if (maxset < model->num_elem_maps) {
607 maxset = model->num_elem_maps;
608 }
609
610 /* allocate space for id/status array */
611 if (!(invalid_ids = malloc(maxset * sizeof(int)))) {
612 char errmsg[MAX_ERR_LENGTH];
613 snprintf(errmsg, MAX_ERR_LENGTH,
614 "ERROR: failed to allocate memory for id/status array for file id %d", exoid);
615 ex_err_fn(exoid, __func__, errmsg, EX_MEMFAIL);
616 EX_FUNC_LEAVE(EX_FATAL);
617 }
618
619 invalidate_id_status(exoid, VAR_STAT_EL_BLK, VAR_ID_EL_BLK, model->num_elem_blk, invalid_ids);
620 invalidate_id_status(exoid, VAR_STAT_ED_BLK, VAR_ID_ED_BLK, model->num_edge_blk, invalid_ids);
621 invalidate_id_status(exoid, VAR_STAT_FA_BLK, VAR_ID_FA_BLK, model->num_face_blk, invalid_ids);
622 invalidate_id_status(exoid, VAR_NS_STAT, VAR_NS_IDS, model->num_node_sets, invalid_ids);
623 invalidate_id_status(exoid, VAR_ES_STAT, VAR_ES_IDS, model->num_edge_sets, invalid_ids);
624 invalidate_id_status(exoid, VAR_FS_STAT, VAR_FS_IDS, model->num_face_sets, invalid_ids);
625 invalidate_id_status(exoid, VAR_SS_STAT, VAR_SS_IDS, model->num_side_sets, invalid_ids);
626 invalidate_id_status(exoid, VAR_ELS_STAT, VAR_ELS_IDS, model->num_elem_sets, invalid_ids);
627
628 invalidate_id_status(exoid, 0, VAR_NM_PROP(1), model->num_node_maps, invalid_ids);
629 invalidate_id_status(exoid, 0, VAR_EDM_PROP(1), model->num_edge_maps, invalid_ids);
630 invalidate_id_status(exoid, 0, VAR_FAM_PROP(1), model->num_face_maps, invalid_ids);
631 invalidate_id_status(exoid, 0, VAR_EM_PROP(1), model->num_elem_maps, invalid_ids);
632
633 free(invalid_ids);
634 invalid_ids = NULL;
635 }
636
637 /* Write dummy values to the names arrays to avoid corruption issues on some
638 * platforms */
639 write_dummy_names(exoid, EX_ELEM_BLOCK, model->num_elem_blk);
640 write_dummy_names(exoid, EX_EDGE_BLOCK, model->num_edge_blk);
641 write_dummy_names(exoid, EX_FACE_BLOCK, model->num_face_blk);
642 write_dummy_names(exoid, EX_NODE_SET, model->num_node_sets);
643 write_dummy_names(exoid, EX_EDGE_SET, model->num_edge_sets);
644 write_dummy_names(exoid, EX_FACE_SET, model->num_face_sets);
645 write_dummy_names(exoid, EX_SIDE_SET, model->num_side_sets);
646 write_dummy_names(exoid, EX_ELEM_SET, model->num_elem_sets);
647 write_dummy_names(exoid, EX_NODE_MAP, model->num_node_maps);
648 write_dummy_names(exoid, EX_EDGE_MAP, model->num_edge_maps);
649 write_dummy_names(exoid, EX_FACE_MAP, model->num_face_maps);
650 write_dummy_names(exoid, EX_ELEM_MAP, model->num_elem_maps);
651
652 EX_FUNC_LEAVE(EX_NOERR);
653
654 /* Fatal error: exit definition mode and return */
655 error_ret:
656 exi_leavedef(exoid, __func__);
657 EX_FUNC_LEAVE(EX_FATAL);
658 }