1 /*
2  * Copyright (c) 2006 Sandia Corporation. Under the terms of Contract
3  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Governement
4  * retains certain rights in this software.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *
13  *     * Redistributions in binary form must reproduce the above
14  *       copyright notice, this list of conditions and the following
15  *       disclaimer in the documentation and/or other materials provided
16  *       with the distribution.
17  *
18  *     * Neither the name of Sandia Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  */
35 /*****************************************************************************
36 *
37 * expinix - ex_put_init_ext
38 *
39 * entry conditions -
40 *   input parameters:
41 *       int                   exoid     exodus file id
42 *       const ex_init_params* params    finite element model parameters
43 *
44 * exit conditions -
45 *
46 * revision history -
47 *          David Thompson  - Added edge/face blocks/sets
48 *
49 *
50 *****************************************************************************/
51 
52 #include "exodusII.h"
53 #include "exodusII_int.h"
54 #include <stdlib.h>
55 #include <string.h>
56 #include <assert.h>
57 
write_dummy_names(int exoid,ex_entity_type obj_type)58 static void write_dummy_names(int exoid, ex_entity_type obj_type)
59 {
60   const char *routine = "write_dummy_names";
61   size_t  start[2], count[2];
62   char *text = "";
63   int varid;
64   size_t num_entity;
65   size_t i;
66 
67   ex_get_dimension(exoid, ex_dim_num_objects(obj_type),
68 		   ex_name_of_object(obj_type),
69 		   &num_entity, &varid, routine);
70 
71   for (i = 0; i < num_entity; i++) {
72     start[0] = i;
73     count[0] = 1;
74 
75     start[1] = 0;
76     count[1] = strlen(text)+1;
77 
78     nc_put_vara_text(exoid, varid, start, count, text);
79   }
80 }
81 
ex_write_object_names(int exoid,const char * type,const char * dimension_name,int dimension_var,int string_dimension,int count)82 static int ex_write_object_names(int exoid, const char *type, const char *dimension_name,
83 				 int dimension_var, int string_dimension, int count)
84 {
85   int dim[2];
86   int status;
87   int varid;
88   char errmsg[MAX_ERR_LENGTH];
89 
90   if (count > 0) {
91     dim[0] = dimension_var;
92     dim[1] = string_dimension;
93 
94     if ((status = nc_def_var (exoid, dimension_name, NC_CHAR, 2, dim, &varid)) != NC_NOERR) {
95       exerrval = status;
96       sprintf(errmsg,
97 	      "Error: failed to define %s name array in file id %d",type,exoid);
98       ex_err("ex_put_init_ext",errmsg,exerrval);
99       return status;         /* exit define mode and return */
100     }
101   }
102   return NC_NOERR;
103 }
104 
ex_write_object_params(int exoid,const char * type,const char * dimension_name,const char * status_dim_name,const char * id_array_dim_name,int count,int * dimension)105 static int ex_write_object_params(int exoid, const char *type, const char *dimension_name,
106 				  const char *status_dim_name, const char *id_array_dim_name,
107 				  int count, int *dimension)
108 {
109   int dim[2];
110   int varid;
111   int status;
112   char errmsg[MAX_ERR_LENGTH];
113 
114   /* Can have nonzero model->num_elem_blk even if model->num_elem == 0 */
115   if (count > 0) {
116     if ((status = nc_def_dim(exoid, dimension_name, (size_t)count, dimension)) != NC_NOERR) {
117       exerrval = status;
118       sprintf(errmsg,
119 	      "Error: failed to define number of %ss in file id %d",
120 	      type, exoid);
121       ex_err("ex_put_init_ext",errmsg,exerrval);
122       return status;         /* exit define mode and return */
123     }
124     /* ...and some variables */
125     /* element block id status array */
126     dim[0] = *dimension;
127     if ((status = nc_def_var (exoid, status_dim_name, NC_INT, 1, dim, &varid)) != NC_NOERR) {
128       exerrval = status;
129       sprintf(errmsg,
130 	      "Error: failed to define %s status array in file id %d", type, exoid);
131       ex_err("ex_put_init_ext",errmsg,exerrval);
132       return status;         /* exit define mode and return */
133     }
134 
135     /* type id array */
136     if ((status = nc_def_var (exoid, id_array_dim_name, NC_INT, 1, dim, &varid)) != NC_NOERR) {
137       exerrval = status;
138       sprintf(errmsg,
139 	      "Error: failed to define %s id array in file id %d", type, exoid);
140       ex_err("ex_put_init_ext",errmsg,exerrval);
141       return status;         /* exit define mode and return */
142     }
143 
144     /*   store property name as attribute of property array variable */
145     if ((status=nc_put_att_text(exoid, varid, ATT_PROP_NAME, 3, "ID")) != NC_NOERR) {
146       exerrval = status;
147       sprintf(errmsg,
148 	      "Error: failed to store %s property name %s in file id %d",
149 	      type, "ID", exoid);
150       ex_err("ex_put_init_ext",errmsg,exerrval);
151       return status;
152     }
153   }
154   return NC_NOERR;
155 }
156 
ex_write_map_params(int exoid,const char * map_name,const char * map_dim_name,const char * map_id_name,int map_count,int * map_dimension)157 static int ex_write_map_params(int exoid, const char *map_name, const char *map_dim_name,
158 			       const char *map_id_name, int map_count, int *map_dimension)
159 {
160   int dim[2];
161   int varid;
162   int status;
163   char errmsg[MAX_ERR_LENGTH];
164 
165   /* Can have nonzero model->num_XXXX_map even if model->num_XXXX == 0 */
166   if ((map_count) > 0) {
167     if ((status = nc_def_dim(exoid, map_dim_name, (size_t)(map_count), map_dimension)) != NC_NOERR) {
168         exerrval = status;
169         sprintf(errmsg,
170                 "Error: failed to define number of %ss in file id %d",
171                 map_name, exoid);
172         ex_err("ex_put_init_ext",errmsg,exerrval);
173         return status;         /* exit define mode and return */
174       }
175 
176     dim[0] = *map_dimension;
177 
178     /* map_name id array */
179     if ((status = nc_def_var(exoid, map_id_name, NC_INT, 1, dim, &varid)) != NC_NOERR) {
180         exerrval = status;
181         sprintf(errmsg,
182                 "Error: failed to define %s id array in file id %d", map_name, exoid);
183         ex_err("ex_put_init_ext",errmsg,exerrval);
184         return status;         /* exit define mode and return */
185       }
186 
187     /*   store property name as attribute of property array variable */
188     if ((status=nc_put_att_text(exoid, varid, ATT_PROP_NAME, 3, "ID")) != NC_NOERR) {
189         exerrval = status;
190         sprintf(errmsg,
191                 "Error: failed to store %s property name %s in file id %d",
192                 map_name, "ID",exoid);
193         ex_err("ex_put_init_ext",errmsg,exerrval);
194         return (EX_FATAL);
195       }
196   }
197   return NC_NOERR;
198 }
199 
invalidate_id_status(int exoid,const char * var_stat,const char * var_id,int count,int * ids)200 static void invalidate_id_status(int exoid, const char *var_stat,
201 				 const char *var_id, int count, int *ids)
202 {
203   int status;
204   int i;
205   int id_var, stat_var;
206 
207   if (count > 0) {
208     if (var_id != 0) {
209       for (i=0; i < count; i++) {
210 	ids[i] = EX_INVALID_ID;
211       }
212 
213       status = nc_inq_varid(exoid, var_id,   &id_var);
214       assert(status == NC_NOERR);
215       status = nc_put_var_int(exoid, id_var,   ids);
216       assert(status == NC_NOERR);
217     }
218 
219     if (var_stat != 0) {
220       for (i=0; i < count; i++) {
221 	ids[i] = 0;
222       }
223 
224       status = nc_inq_varid(exoid, var_stat, &stat_var);
225       assert(status == NC_NOERR);
226       status = nc_put_var_int(exoid, stat_var, ids);
227       assert(status == NC_NOERR);
228     }
229   }
230 }
231 
232 /*!
233  * writes the initialization parameters to the EXODUS II file
234  * \param     exoid     exodus file id
235  * \param     model     finite element model parameters
236  */
237 
ex_put_init_ext(int exoid,const ex_init_params * model)238 int ex_put_init_ext (int   exoid,
239                      const ex_init_params *model)
240 {
241   int numdimdim, numnoddim, elblkdim, edblkdim, fablkdim, esetdim,
242     fsetdim, elsetdim, nsetdim, ssetdim, dim_str_name, dim[2], temp;
243   int status;
244   int nmapdim,edmapdim,famapdim,emapdim;
245   int title_len;
246 #if 0
247   /* used for header size calculations which are turned off for now */
248   int header_size, fixed_var_size, iows;
249 #endif
250   char errmsg[MAX_ERR_LENGTH];
251 
252   exerrval = 0; /* clear error code */
253 
254   if (nc_inq_dimid (exoid, DIM_NUM_DIM, &temp) == NC_NOERR)
255     {
256       exerrval = EX_MSG;
257       sprintf(errmsg,
258               "Error: initialization already done for file id %d",exoid);
259       ex_err("ex_put_init_ext",errmsg,exerrval);
260       return (EX_FATAL);
261     }
262 
263 
264   /* put file into define mode */
265 
266   if ((status = nc_redef (exoid)) != NC_NOERR)
267     {
268       exerrval = status;
269       sprintf(errmsg,
270               "Error: failed to put file id %d into define mode", exoid);
271       ex_err("ex_put_init_ext",errmsg,exerrval);
272       return (EX_FATAL);
273     }
274 
275   /* define some attributes... */
276   title_len = strlen(model->title) < MAX_LINE_LENGTH ?
277     strlen(model->title) : MAX_LINE_LENGTH;
278   if ((status = nc_put_att_text(exoid, NC_GLOBAL, (const char*)ATT_TITLE,
279 				title_len+1, model->title)) != NC_NOERR)
280     {
281       exerrval = status;
282       sprintf(errmsg,
283               "Error: failed to define model->title attribute to file id %d", exoid);
284       ex_err("ex_put_init_ext",errmsg,exerrval);
285       goto error_ret;         /* exit define mode and return */
286     }
287 
288   /* ...and some dimensions... */
289 
290   /* create name string length dimension */
291   {
292     int max_name = ex_max_name_length < 32 ? 32 : ex_max_name_length;
293     if ((status=nc_def_dim (exoid, DIM_STR_NAME, max_name+1, &dim_str_name)) != NC_NOERR) {
294       exerrval = status;
295       sprintf(errmsg,
296 	      "Error: failed to define name string length in file id %d",exoid);
297       ex_err("ex_put_init_ext",errmsg,exerrval);
298       goto error_ret;
299     }
300   }
301 
302   {
303     int max_so_far = 32;
304     if ((status=nc_put_att_int(exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, NC_INT, 1, &max_so_far)) != NC_NOERR) {
305       exerrval = status;
306       sprintf(errmsg,
307 	      "Error: failed to add maximum_name_length attribute in file id %d",exoid);
308       ex_err("ex_put_init_ext",errmsg,exerrval);
309       goto error_ret;
310     }
311   }
312 
313   if ((status = nc_def_dim(exoid, DIM_NUM_DIM, model->num_dim, &numdimdim)) != NC_NOERR)
314     {
315       exerrval = status;
316       sprintf(errmsg,
317               "Error: failed to define number of dimensions in file id %d",exoid);
318       ex_err("ex_put_init_ext",errmsg,exerrval);
319       goto error_ret;         /* exit define mode and return */
320     }
321 
322   /*
323    * Need to handle "empty file" that may be the result of a strange
324    * load balance or some other strange run.  Note that if num_node
325    * == 0, then model->num_elem must be zero since you cannot have elements
326    * with no nodes. It *is* permissible to have zero elements with
327    * non-zero node count.
328    */
329 
330   if (model->num_nodes > 0) {
331     if ((status = nc_def_dim(exoid, DIM_NUM_NODES, model->num_nodes, &numnoddim)) != NC_NOERR)
332       {
333         exerrval = status;
334         sprintf(errmsg,
335                 "Error: failed to define number of nodes in file id %d",exoid);
336         ex_err("ex_put_init_ext",errmsg,exerrval);
337         goto error_ret;         /* exit define mode and return */
338       }
339   }
340 
341   if (model->num_elem > 0) {
342     if (model->num_nodes <=  0) {
343       exerrval = EX_MSG;
344       sprintf(errmsg,
345               "Error: Cannot have non-zero element count if node count is zero.in file id %d",exoid);
346       ex_err("ex_put_init_ext",errmsg,exerrval);
347       goto error_ret;         /* exit define mode and return */
348     }
349 
350     if ((status = nc_def_dim(exoid, DIM_NUM_ELEM, model->num_elem, &temp)) != NC_NOERR)
351       {
352         exerrval = status;
353         sprintf(errmsg,
354                 "Error: failed to define number of elements in file id %d",exoid);
355         ex_err("ex_put_init_ext",errmsg,exerrval);
356         goto error_ret;         /* exit define mode and return */
357       }
358   }
359 
360   if (model->num_edge > 0) {
361     if (model->num_nodes <=  0) {
362       exerrval = EX_MSG;
363       sprintf(errmsg,
364               "Error: Cannot have non-zero edge count if node count is zero.in file id %d",exoid);
365       ex_err("ex_put_init_ext",errmsg,exerrval);
366       goto error_ret;         /* exit define mode and return */
367     }
368 
369     if ((status = nc_def_dim(exoid, DIM_NUM_EDGE, model->num_edge, &temp)) != NC_NOERR)
370       {
371         exerrval = status;
372         sprintf(errmsg,
373                 "Error: failed to define number of edges in file id %d",exoid);
374         ex_err("ex_put_init_ext",errmsg,exerrval);
375         goto error_ret;         /* exit define mode and return */
376       }
377   }
378 
379   if (model->num_face > 0) {
380     if (model->num_nodes <=  0) {
381       exerrval = EX_MSG;
382       sprintf(errmsg,
383               "Error: Cannot have non-zero face count if node count is zero.in file id %d",exoid);
384       ex_err("ex_put_init_ext",errmsg,exerrval);
385       goto error_ret;         /* exit define mode and return */
386     }
387 
388     if ((status = nc_def_dim(exoid, DIM_NUM_FACE, model->num_face, &temp)) != NC_NOERR)
389       {
390         exerrval = status;
391         sprintf(errmsg,
392                 "Error: failed to define number of faces in file id %d",exoid);
393         ex_err("ex_put_init_ext",errmsg,exerrval);
394         goto error_ret;         /* exit define mode and return */
395       }
396   }
397 
398   if (ex_write_object_params(exoid, "element block", DIM_NUM_EL_BLK, VAR_STAT_EL_BLK, VAR_ID_EL_BLK, model->num_elem_blk, &elblkdim)) goto error_ret;
399   if (ex_write_object_params(exoid, "edge block",    DIM_NUM_ED_BLK, VAR_STAT_ED_BLK, VAR_ID_ED_BLK, model->num_edge_blk, &edblkdim)) goto error_ret;
400   if (ex_write_object_params(exoid, "face block",    DIM_NUM_FA_BLK, VAR_STAT_FA_BLK, VAR_ID_FA_BLK, model->num_face_blk, &fablkdim)) goto error_ret;
401 
402   if (ex_write_object_params(exoid, "node set", DIM_NUM_NS,  VAR_NS_STAT,  VAR_NS_IDS, model->num_node_sets,  &nsetdim)) goto error_ret;
403   if (ex_write_object_params(exoid, "edge set", DIM_NUM_ES,  VAR_ES_STAT,  VAR_ES_IDS, model->num_edge_sets,  &esetdim)) goto error_ret;
404   if (ex_write_object_params(exoid, "face set", DIM_NUM_FS,  VAR_FS_STAT,  VAR_FS_IDS, model->num_face_sets,  &fsetdim)) goto error_ret;
405   if (ex_write_object_params(exoid, "side set", DIM_NUM_SS,  VAR_SS_STAT,  VAR_SS_IDS, model->num_side_sets,  &ssetdim)) goto error_ret;
406   if (ex_write_object_params(exoid, "elem set", DIM_NUM_ELS, VAR_ELS_STAT, VAR_ELS_IDS, model->num_elem_sets, &elsetdim)) goto error_ret;
407 
408   if (ex_write_map_params(exoid,   "node map",  DIM_NUM_NM,  VAR_NM_PROP(1),  model->num_node_maps, &nmapdim)  != NC_NOERR) goto error_ret;
409   if (ex_write_map_params(exoid,   "edge map",  DIM_NUM_EDM, VAR_EDM_PROP(1), model->num_edge_maps, &edmapdim) != NC_NOERR) goto error_ret;
410   if (ex_write_map_params(exoid,   "face map",  DIM_NUM_FAM, VAR_FAM_PROP(1), model->num_face_maps, &famapdim) != NC_NOERR) goto error_ret;
411   if (ex_write_map_params(exoid, "element map", DIM_NUM_EM,  VAR_EM_PROP(1),  model->num_elem_maps, &emapdim)  != NC_NOERR) goto error_ret;
412 
413   /*
414    * To reduce the maximum dataset sizes, the storage of the nodal
415    * coordinates and the nodal variables was changed from a single
416    * dataset to a dataset per component or variable.  However, we
417    * want to maintain some form of compatability with the old
418    * exodusII version.  It is easy to do this on read; however, we
419    * also want to be able to store in the old format using the new
420    * library.
421    *
422    * The mode is set in the ex_create call. The setting can be checked
423    * via the ATT_FILESIZE attribute in the file (1=large,
424    * 0=normal). Also handle old files that do not contain this
425    * attribute.
426    */
427 
428   if (model->num_nodes > 0) {
429     if (ex_large_model(exoid) == 1) {
430       /* node coordinate arrays -- separate storage... */
431 
432       dim[0] = numnoddim;
433       if (model->num_dim > 0) {
434         if ((status = nc_def_var (exoid, VAR_COORD_X, nc_flt_code(exoid), 1, dim, &temp)) != NC_NOERR)
435           {
436             exerrval = status;
437             sprintf(errmsg,
438                     "Error: failed to define node x coordinate array in file id %d",exoid);
439             ex_err("ex_put_init_ext",errmsg,exerrval);
440             goto error_ret;         /* exit define mode and return */
441           }
442       }
443 
444       if (model->num_dim > 1) {
445         if ((status = nc_def_var(exoid, VAR_COORD_Y, nc_flt_code(exoid), 1, dim, &temp)) != NC_NOERR)
446           {
447             exerrval = status;
448             sprintf(errmsg,
449                     "Error: failed to define node y coordinate array in file id %d",exoid);
450             ex_err("ex_put_init_ext",errmsg,exerrval);
451             goto error_ret;         /* exit define mode and return */
452           }
453       }
454 
455       if (model->num_dim > 2) {
456         if ((status = nc_def_var(exoid, VAR_COORD_Z, nc_flt_code(exoid), 1, dim, &temp)) != NC_NOERR)
457           {
458             exerrval = status;
459             sprintf(errmsg,
460                     "Error: failed to define node z coordinate array in file id %d",exoid);
461             ex_err("ex_put_init_ext",errmsg,exerrval);
462             goto error_ret;         /* exit define mode and return */
463           }
464       }
465     } else {
466       /* node coordinate arrays: -- all stored together (old method) */
467 
468       dim[0] = numdimdim;
469       dim[1] = numnoddim;
470       if ((status = nc_def_var(exoid, VAR_COORD, nc_flt_code(exoid), 2, dim, &temp)) != NC_NOERR)
471         {
472           exerrval = status;
473           sprintf(errmsg,
474                   "Error: failed to define node coordinate array in file id %d",exoid);
475           ex_err("ex_put_init_ext",errmsg,exerrval);
476           goto error_ret;         /* exit define mode and return */
477         }
478     }
479   }
480 
481   if (ex_write_object_names(exoid, "element block",VAR_NAME_EL_BLK,elblkdim, dim_str_name, model->num_elem_blk) != NC_NOERR) goto error_ret;
482   if (ex_write_object_names(exoid, "edge block",   VAR_NAME_ED_BLK,edblkdim, dim_str_name, model->num_edge_blk) != NC_NOERR) goto error_ret;
483   if (ex_write_object_names(exoid, "face block",   VAR_NAME_FA_BLK,fablkdim, dim_str_name, model->num_face_blk) != NC_NOERR) goto error_ret;
484   if (ex_write_object_names(exoid, "node set",     VAR_NAME_NS,    nsetdim,  dim_str_name, model->num_node_sets) != NC_NOERR) goto error_ret;
485   if (ex_write_object_names(exoid, "edge set",     VAR_NAME_ES,    esetdim,  dim_str_name, model->num_edge_sets) != NC_NOERR) goto error_ret;
486   if (ex_write_object_names(exoid, "face set",     VAR_NAME_FS,    fsetdim,  dim_str_name, model->num_face_sets) != NC_NOERR) goto error_ret;
487   if (ex_write_object_names(exoid, "side set",     VAR_NAME_SS,    ssetdim,  dim_str_name, model->num_side_sets) != NC_NOERR) goto error_ret;
488   if (ex_write_object_names(exoid, "element set",  VAR_NAME_ELS,   elsetdim, dim_str_name, model->num_elem_sets) != NC_NOERR) goto error_ret;
489   if (ex_write_object_names(exoid, "node map",     VAR_NAME_NM,    nmapdim,  dim_str_name, model->num_node_maps) != NC_NOERR) goto error_ret;
490   if (ex_write_object_names(exoid, "edge map",     VAR_NAME_EDM,   edmapdim, dim_str_name, model->num_edge_maps) != NC_NOERR) goto error_ret;
491   if (ex_write_object_names(exoid, "face map",     VAR_NAME_FAM,   famapdim, dim_str_name, model->num_face_maps) != NC_NOERR) goto error_ret;
492   if (ex_write_object_names(exoid, "element map",  VAR_NAME_EM,    emapdim,  dim_str_name, model->num_elem_maps) != NC_NOERR) goto error_ret;
493   if (ex_write_object_names(exoid, "coordinate",   VAR_NAME_COOR,  numdimdim,dim_str_name, model->num_dim) != NC_NOERR) goto error_ret;
494 
495   /* leave define mode */
496   if ((status = nc_enddef (exoid)) != NC_NOERR) {
497     exerrval = status;
498     sprintf(errmsg,
499 	    "Error: failed to complete variable definitions in file id %d",exoid);
500     ex_err("ex_put_init_ext",errmsg,exerrval);
501     return (EX_FATAL);
502   }
503 
504   /* Fill the id and status arrays with EX_INVALID_ID */
505   {
506     int *invalid_ids = NULL;
507     int maxset = model->num_elem_blk;
508     if (maxset < model->num_edge_blk)  maxset = model->num_edge_blk;
509     if (maxset < model->num_face_blk)  maxset = model->num_face_blk;
510     if (maxset < model->num_node_sets) maxset = model->num_node_sets;
511     if (maxset < model->num_edge_sets) maxset = model->num_edge_sets;
512     if (maxset < model->num_face_sets) maxset = model->num_face_sets;
513     if (maxset < model->num_side_sets) maxset = model->num_side_sets;
514     if (maxset < model->num_elem_sets) maxset = model->num_elem_sets;
515     if (maxset < model->num_node_maps) maxset = model->num_node_maps;
516     if (maxset < model->num_edge_maps) maxset = model->num_edge_maps;
517     if (maxset < model->num_face_maps) maxset = model->num_face_maps;
518     if (maxset < model->num_elem_maps) maxset = model->num_elem_maps;
519 
520     /* allocate space for id/status array */
521     if (!(invalid_ids = malloc(maxset*sizeof(int)))) {
522       exerrval = EX_MEMFAIL;
523       sprintf(errmsg,
524 	      "Error: failed to allocate memory for id/status array for file id %d", exoid);
525       ex_err("ex_put_init_ext",errmsg,exerrval);
526       return (EX_FATAL);
527     }
528 
529     invalidate_id_status(exoid, VAR_STAT_EL_BLK, VAR_ID_EL_BLK,
530 			 model->num_elem_blk, invalid_ids);
531     invalidate_id_status(exoid, VAR_STAT_ED_BLK, VAR_ID_ED_BLK,
532 			 model->num_edge_blk, invalid_ids);
533     invalidate_id_status(exoid, VAR_STAT_FA_BLK, VAR_ID_FA_BLK,
534 			 model->num_face_blk, invalid_ids);
535     invalidate_id_status(exoid, VAR_NS_STAT,  VAR_NS_IDS,
536 			 model->num_node_sets, invalid_ids);
537     invalidate_id_status(exoid, VAR_ES_STAT,  VAR_ES_IDS,
538 			 model->num_edge_sets, invalid_ids);
539     invalidate_id_status(exoid, VAR_FS_STAT,  VAR_FS_IDS,
540 			 model->num_face_sets, invalid_ids);
541     invalidate_id_status(exoid, VAR_SS_STAT,  VAR_SS_IDS,
542 			 model->num_side_sets, invalid_ids);
543     invalidate_id_status(exoid, VAR_ELS_STAT, VAR_ELS_IDS,
544 			 model->num_elem_sets, invalid_ids);
545 
546     invalidate_id_status(exoid, 0, VAR_NM_PROP(1),  model->num_node_maps, invalid_ids);
547     invalidate_id_status(exoid, 0, VAR_EDM_PROP(1), model->num_edge_maps, invalid_ids);
548     invalidate_id_status(exoid, 0, VAR_FAM_PROP(1), model->num_face_maps, invalid_ids);
549     invalidate_id_status(exoid, 0, VAR_EM_PROP(1),  model->num_elem_maps, invalid_ids);
550 
551     if (invalid_ids != NULL) {
552       free(invalid_ids);
553       invalid_ids = NULL;
554     }
555   }
556 
557   /* Write dummy values to the names arrays to avoid corruption issues on some platforms */
558   if (model->num_elem_blk > 0) write_dummy_names(exoid, EX_ELEM_BLOCK);
559   if (model->num_edge_blk > 0) write_dummy_names(exoid, EX_EDGE_BLOCK);
560   if (model->num_face_blk > 0) write_dummy_names(exoid, EX_FACE_BLOCK);
561   if (model->num_node_sets> 0) write_dummy_names(exoid, EX_NODE_SET);
562   if (model->num_edge_sets> 0) write_dummy_names(exoid, EX_EDGE_SET);
563   if (model->num_face_sets> 0) write_dummy_names(exoid, EX_FACE_SET);
564   if (model->num_side_sets> 0) write_dummy_names(exoid, EX_SIDE_SET);
565   if (model->num_elem_sets> 0) write_dummy_names(exoid, EX_ELEM_SET);
566   if (model->num_node_maps> 0) write_dummy_names(exoid, EX_NODE_MAP);
567   if (model->num_edge_maps> 0) write_dummy_names(exoid, EX_EDGE_MAP);
568   if (model->num_face_maps> 0) write_dummy_names(exoid, EX_FACE_MAP);
569   if (model->num_elem_maps> 0) write_dummy_names(exoid, EX_ELEM_MAP);
570 
571   return (EX_NOERR);
572 
573   /* Fatal error: exit definition mode and return */
574  error_ret:
575   if (nc_enddef (exoid) != NC_NOERR)     /* exit define mode */
576     {
577       sprintf(errmsg,
578               "Error: failed to complete definition for file id %d",
579               exoid);
580       ex_err("ex_put_init_ext",errmsg,exerrval);
581     }
582   return (EX_FATAL);
583 }
584 
585