1 /*
2  * Copyright (c) 2005 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 * testrd - read exodus file test.exo created by testwt
38 *
39 * author - Sandia National Laboratories
40 *          Larry A. Schoof - Original
41 *
42 *
43 * environment - UNIX
44 *
45 * entry conditions -
46 *   input parameters:
47 *       int     exoid                   exodus file id
48 *
49 * exit conditions -
50 *
51 * revision history -
52 *
53 *
54 *****************************************************************************/
55 
56 #include <stdlib.h>
57 #include <stdio.h>
58 #include <string.h>
59 #include "netcdf.h"
60 #include "exodusII.h"
61 /* #include "drmd.h" */
62 
63 
main(int argc,char ** argv)64 int main (int argc, char **argv)
65 {
66   int exoid, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets;
67   int num_side_sets, error;
68   int i, j, k, node_ctr;
69   int *elem_map, *connect, *node_list, *node_ctr_list, *elem_list, *side_list;
70   int *ids;
71   int *num_nodes_per_set = NULL;
72   int *num_elem_per_set = NULL;
73   int *num_df_per_set = NULL;
74   int *node_ind = NULL;
75   int *elem_ind = NULL;
76   int *df_ind = NULL;
77   int num_qa_rec, num_info;
78   int num_glo_vars, num_nod_vars, num_ele_vars;
79   int num_nset_vars, num_sset_vars;
80   int *truth_tab;
81   int num_time_steps;
82   int *num_elem_in_block = NULL;
83   int *num_nodes_per_elem = NULL;
84   int *num_attr = NULL;
85   int num_nodes_in_set, num_elem_in_set;
86   int num_sides_in_set, num_df_in_set;
87   int list_len, elem_list_len, node_list_len, df_list_len;
88   int node_num, time_step, var_index, beg_time, end_time, elem_num;
89   int CPU_word_size,IO_word_size;
90   int num_props, prop_value, *prop_values;
91   int idum;
92 
93   float time_value, *time_values, *var_values;
94   float *x, *y, *z;
95   float *attrib, *dist_fact;
96   float version, fdum;
97 
98   char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
99   char *block_names[10], *nset_names[10], *sset_names[10];
100   char *attrib_names[10];
101   char name[MAX_STR_LENGTH+1];
102   char title[MAX_LINE_LENGTH+1], elem_type[MAX_STR_LENGTH+1];
103   char title_chk[MAX_LINE_LENGTH+1];
104   char *cdum = 0;
105   char *prop_names[3];
106 
107   CPU_word_size = 0;                    /* sizeof(float) */
108   IO_word_size = 0;                     /* use what is stored in file */
109 
110   ex_opts (EX_VERBOSE | EX_ABORT );
111 
112   /* open EXODUS II files */
113   exoid = ex_open ("test.exo",  /* filename path */
114                    EX_READ,             /* access mode = READ */
115                    &CPU_word_size,      /* CPU word size */
116                    &IO_word_size,       /* IO word size */
117                    &version);           /* ExodusII library version */
118 
119   printf ("\nafter ex_open\n");
120   if (exoid < 0) exit(1);
121 
122   printf ("test.exo is an EXODUSII file; version %4.2f\n",
123           version);
124   /*   printf ("         CPU word size %1d\n",CPU_word_size);  */
125   printf ("         I/O word size %1d\n",IO_word_size);
126   ex_inquire(exoid,EX_INQ_API_VERS, &idum, &version, cdum);
127   printf ("EXODUSII API; version %4.2f\n", version);
128 
129   ex_inquire(exoid,EX_INQ_LIB_VERS, &idum, &version, cdum);
130   printf ("EXODUSII Library API; version %4.2f (%d)\n", version, idum);
131 
132   /* ncopts = NC_VERBOSE; */
133 
134   /* read database parameters */
135 
136   error = ex_get_init (exoid, title, &num_dim, &num_nodes, &num_elem,
137                        &num_elem_blk, &num_node_sets, &num_side_sets);
138 
139   printf ("after ex_get_init, error = %3d\n", error);
140 
141   printf ("database parameters:\n");
142   printf ("title =  '%s'\n",title);
143   printf ("num_dim = %3d\n",num_dim);
144   printf ("num_nodes = %3d\n",num_nodes);
145   printf ("num_elem = %3d\n",num_elem);
146   printf ("num_elem_blk = %3d\n",num_elem_blk);
147   printf ("num_node_sets = %3d\n",num_node_sets);
148   printf ("num_side_sets = %3d\n",num_side_sets);
149 
150   /* Check that ex_inquire gives same title */
151   error = ex_inquire (exoid, EX_INQ_TITLE, &idum, &fdum, title_chk);
152   printf (" after ex_inquire, error = %d\n", error);
153   if (strcmp(title, title_chk) != 0) {
154     printf ("error in ex_inquire for EX_INQ_TITLE\n");
155   }
156 
157   /* read nodal coordinates values and names from database */
158 
159   x = (float *) calloc(num_nodes, sizeof(float));
160   if (num_dim >= 2)
161     y = (float *) calloc(num_nodes, sizeof(float));
162   else
163     y = 0;
164 
165   if (num_dim >= 3)
166     z = (float *) calloc(num_nodes, sizeof(float));
167   else
168     z = 0;
169 
170   error = ex_get_coord (exoid, x, y, z);
171   printf ("\nafter ex_get_coord, error = %3d\n", error);
172 
173   printf ("x coords = \n");
174   for (i=0; i<num_nodes; i++)
175     {
176       printf ("%5.1f\n", x[i]);
177     }
178 
179   if (num_dim >= 2) {
180     printf ("y coords = \n");
181     for (i=0; i<num_nodes; i++)
182       {
183 	printf ("%5.1f\n", y[i]);
184       }
185   }
186   if (num_dim >= 3)
187     {
188       printf ("z coords = \n");
189       for (i=0; i<num_nodes; i++)
190         {
191           printf ("%5.1f\n", z[i]);
192         }
193     }
194 
195   /*
196     error = ex_get_1_coord (exoid, 2, x, y, z);
197     printf ("\nafter ex_get_1_coord, error = %3d\n", error);
198 
199     printf ("x coord of node 2 = \n");
200     printf ("%f \n", x[0]);
201 
202     printf ("y coord of node 2 = \n");
203     printf ("%f \n", y[0]);
204   */
205   free (x);
206   if (num_dim >= 2)
207     free (y);
208   if (num_dim >= 3)
209     free (z);
210 
211 
212   for (i=0; i<num_dim; i++)
213     {
214       coord_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
215     }
216 
217   error = ex_get_coord_names (exoid, coord_names);
218   printf ("\nafter ex_get_coord_names, error = %3d\n", error);
219   printf ("x coord name = '%s'\n", coord_names[0]);
220   if (num_dim >1)
221     printf ("y coord name = '%s'\n", coord_names[1]);
222   if (num_dim >2)
223     printf ("z coord name = '%s'\n", coord_names[2]);
224 
225   for (i=0; i<num_dim; i++)
226     free(coord_names[i]);
227 
228   {
229     int num_attrs = 0;
230     error = ex_get_attr_param(exoid, EX_NODAL, 0, &num_attrs);
231     printf (" after ex_get_attr_param, error = %d\n", error);
232     printf ("num nodal attributes = %d\n", num_attrs);
233     if (num_attrs > 0) {
234       for (j=0; j<num_attrs; j++) {
235 	attrib_names[j] = (char *)calloc ((MAX_STR_LENGTH+1), sizeof(char));
236       }
237       error = ex_get_attr_names (exoid, EX_NODAL, 0, attrib_names);
238       printf (" after ex_get_attr_names, error = %d\n", error);
239 
240       if (error == 0) {
241 	attrib = (float *) calloc(num_nodes,sizeof(float));
242 	for (j=0; j<num_attrs; j++) {
243 	  printf ("nodal attribute %d = '%s'\n", j, attrib_names[j]);
244 	  error = ex_get_one_attr(exoid, EX_NODAL, 0, j+1, attrib);
245 	  printf (" after ex_get_one_attr, error = %d\n", error);
246 	  for (i=0; i < num_nodes; i++) {
247 	    printf ("%5.1f\n", attrib[i]);
248 	  }
249 	  free(attrib_names[j]);
250 	}
251 	free(attrib);
252       }
253     }
254   }
255 
256   /* read element order map */
257 
258   elem_map = (int *) calloc(num_elem, sizeof(int));
259 
260   error = ex_get_map (exoid, elem_map);
261   printf ("\nafter ex_get_map, error = %3d\n", error);
262 
263   for (i=0; i<num_elem; i++)
264     {
265       printf ("elem_map(%d) = %d \n", i, elem_map[i]);
266     }
267 
268   free (elem_map);
269 
270   /* read element block parameters */
271 
272   if (num_elem_blk > 0) {
273     ids = (int *) calloc(num_elem_blk, sizeof(int));
274     num_elem_in_block = (int *) calloc(num_elem_blk, sizeof(int));
275     num_nodes_per_elem = (int *) calloc(num_elem_blk, sizeof(int));
276     num_attr = (int *) calloc(num_elem_blk, sizeof(int));
277 
278     error = ex_get_elem_blk_ids (exoid, ids);
279     printf ("\nafter ex_get_elem_blk_ids, error = %3d\n", error);
280 
281     for (i=0; i<num_elem_blk; i++) {
282       block_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
283     }
284 
285     error = ex_get_names(exoid, EX_ELEM_BLOCK, block_names);
286     printf ("\nafter ex_get_names, error = %3d\n", error);
287 
288     for (i=0; i<num_elem_blk; i++)
289       {
290 	ex_get_name(exoid, EX_ELEM_BLOCK, ids[i], name);
291 	if (strcmp(name, block_names[i]) != 0) {
292 	  printf ("error in ex_get_name for block id %d\n", ids[i]);
293 	}
294         error = ex_get_elem_block (exoid, ids[i], elem_type,
295                                    &(num_elem_in_block[i]),
296                                    &(num_nodes_per_elem[i]), &(num_attr[i]));
297         printf ("\nafter ex_get_elem_block, error = %d\n", error);
298 
299         printf ("element block id = %2d\n",ids[i]);
300         printf ("element type = '%s'\n", elem_type);
301         printf ("num_elem_in_block = %2d\n",num_elem_in_block[i]);
302         printf ("num_nodes_per_elem = %2d\n",num_nodes_per_elem[i]);
303         printf ("num_attr = %2d\n",num_attr[i]);
304         printf ("name = '%s'\n",block_names[i]);
305 	free(block_names[i]);
306       }
307 
308     /* read element block properties */
309     error = ex_inquire (exoid, EX_INQ_EB_PROP, &num_props, &fdum, cdum);
310     printf ("\nafter ex_inquire, error = %d\n", error);
311     printf ("\nThere are %2d properties for each element block\n", num_props);
312 
313     for (i=0; i<num_props; i++)
314       {
315         prop_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
316       }
317 
318     error = ex_get_prop_names(exoid,EX_ELEM_BLOCK,prop_names);
319     printf ("after ex_get_prop_names, error = %d\n", error);
320 
321 
322     for (i=1; i<num_props; i++) /* Prop 1 is id; skip that here */
323       {
324         for (j=0; j<num_elem_blk; j++)
325           {
326             error = ex_get_prop(exoid, EX_ELEM_BLOCK, ids[j], prop_names[i],
327                                 &prop_value);
328             if (error == 0)
329               printf ("element block %2d, property(%2d): '%s'= %5d\n",
330                       j+1, i+1, prop_names[i], prop_value);
331             else
332               printf ("after ex_get_prop, error = %d\n", error);
333           }
334       }
335 
336     for (i=0; i<num_props; i++)
337       free(prop_names[i]);
338   }
339 
340   /* read element connectivity */
341 
342   for (i=0; i<num_elem_blk; i++)
343     {
344       if (num_elem_in_block[i] > 0) {
345 	connect = (int *) calloc((num_nodes_per_elem[i] * num_elem_in_block[i]),
346 				 sizeof(int));
347 
348 	error = ex_get_elem_conn (exoid, ids[i], connect);
349 	printf ("\nafter ex_get_elem_conn, error = %d\n", error);
350 
351 
352 	printf ("connect array for elem block %2d\n", ids[i]);
353 
354 	for (j=0; j<num_nodes_per_elem[i]; j++)
355 	  {
356 	    printf ("%3d\n", connect[j]);
357 	  }
358 	/*
359 	  error = ex_get_1_elem_conn (exoid, 1, ids[i], connect);
360 	  printf ("\nafter ex_get_elem_conn, error = %d\n", error);
361 
362 	  printf ("node list for first element of element block %d \n ", ids[i]);
363 	  for (j=0; j<num_nodes_per_elem[i]; j++)
364 	  {
365 	  printf ("%d \n", connect[j]);
366 	  }
367 	*/
368 	free (connect);
369       }
370     }
371 
372   /* read element block attributes */
373 
374   for (i=0; i<num_elem_blk; i++)
375     {
376       if (num_elem_in_block[i] > 0) {
377 	for (j=0; j<num_attr[i]; j++)
378 	  attrib_names[j] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
379 
380 	attrib = (float *) calloc(num_attr[i]*num_elem_in_block[i],sizeof(float));
381 	error = ex_get_elem_attr (exoid, ids[i], attrib);
382 	printf ("\n after ex_get_elem_attr, error = %d\n", error);
383 
384 	if (error == 0) {
385 	  error = ex_get_elem_attr_names (exoid, ids[i], attrib_names);
386 	  printf (" after ex_get_elem_attr_names, error = %d\n", error);
387 
388 	  if (error == 0) {
389 	    printf ("element block %d attribute '%s' = %6.4f\n", ids[i], attrib_names[0], *attrib);
390 	  }
391 	}
392 	free (attrib);
393 	for (j=0; j<num_attr[i]; j++)
394 	  free (attrib_names[j]);
395       }
396     }
397 
398   if (num_elem_blk > 0) {
399     free (ids);
400     free (num_nodes_per_elem);
401     free (num_attr);
402   }
403 
404   /* read individual node sets */
405   if (num_node_sets > 0) {
406     ids = (int *) calloc(num_node_sets, sizeof(int));
407 
408     error = ex_get_node_set_ids (exoid, ids);
409     printf ("\nafter ex_get_node_set_ids, error = %3d\n", error);
410 
411     for (i=0; i<num_node_sets; i++) {
412       nset_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
413     }
414 
415     error = ex_get_names(exoid, EX_NODE_SET, nset_names);
416     printf ("\nafter ex_get_names, error = %3d\n", error);
417 
418     for (i=0; i<num_node_sets; i++)
419       {
420 	ex_get_name(exoid, EX_NODE_SET, ids[i], name);
421 	if (strcmp(name, nset_names[i]) != 0) {
422 	  printf ("error in ex_get_name for nodeset id %d\n", ids[i]);
423 	}
424 
425         error = ex_get_node_set_param (exoid, ids[i],
426                                        &num_nodes_in_set, &num_df_in_set);
427         printf ("\nafter ex_get_node_set_param, error = %3d\n", error);
428 
429         printf ("\nnode set %2d parameters: \n", ids[i]);
430         printf ("num_nodes = %2d\n", num_nodes_in_set);
431 	printf ("name = '%s'\n", nset_names[i]);
432 	free(nset_names[i]);
433         node_list = (int *) calloc(num_nodes_in_set, sizeof(int));
434         dist_fact = (float *) calloc(num_nodes_in_set, sizeof(float));
435 
436         error = ex_get_node_set (exoid, ids[i], node_list);
437         printf ("\nafter ex_get_node_set, error = %3d\n", error);
438 
439         if (num_df_in_set > 0)
440           {
441             error = ex_get_node_set_dist_fact (exoid, ids[i], dist_fact);
442             printf ("\nafter ex_get_node_set_dist_fact, error = %3d\n", error);
443           }
444 
445         printf ("\nnode list for node set %2d\n", ids[i]);
446 
447         for (j=0; j<num_nodes_in_set; j++)
448           {
449             printf ("%3d\n", node_list[j]);
450           }
451 
452         if (num_df_in_set > 0)
453           {
454             printf ("dist factors for node set %2d\n", ids[i]);
455 
456             for (j=0; j<num_nodes_in_set; j++)
457               {
458                 printf ("%5.2f\n", dist_fact[j]);
459               }
460           }
461         else
462           printf ("no dist factors for node set %2d\n", ids[i]);
463 
464         free (node_list);
465         free (dist_fact);
466 
467 	{
468 	  int num_attrs = 0;
469 	  error = ex_get_attr_param(exoid, EX_NODE_SET, ids[i], &num_attrs);
470 	  printf (" after ex_get_attr_param, error = %d\n", error);
471 	  printf ("num nodeset attributes for nodeset %d = %d\n", ids[i], num_attrs);
472 	  if (num_attrs > 0) {
473 	    for (j=0; j<num_attrs; j++) {
474 	      attrib_names[j] = (char *)calloc ((MAX_STR_LENGTH+1), sizeof(char));
475 	    }
476 	    error = ex_get_attr_names (exoid, EX_NODE_SET, ids[i], attrib_names);
477 	    printf (" after ex_get_attr_names, error = %d\n", error);
478 
479 	    if (error == 0) {
480 	      attrib = (float *) calloc(num_nodes_in_set,sizeof(float));
481 	      for (j=0; j<num_attrs; j++) {
482 		printf ("nodeset attribute %d = '%s'\n", j, attrib_names[j]);
483 		error = ex_get_one_attr(exoid, EX_NODE_SET, ids[i], j+1, attrib);
484 		printf (" after ex_get_one_attr, error = %d\n", error);
485 		for (k=0; k < num_nodes_in_set; k++) {
486 		  printf ("%5.1f\n", attrib[k]);
487 		}
488 		free(attrib_names[j]);
489 	      }
490 	      free(attrib);
491 	    }
492 	  }
493 	}
494       }
495     free(ids);
496 
497     /* read node set properties */
498     error = ex_inquire (exoid, EX_INQ_NS_PROP, &num_props, &fdum, cdum);
499     printf ("\nafter ex_inquire, error = %d\n", error);
500     printf ("\nThere are %2d properties for each node set\n", num_props);
501 
502     for (i=0; i<num_props; i++)
503       {
504         prop_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
505       }
506     prop_values = (int *) calloc (num_node_sets, sizeof(int));
507 
508     error = ex_get_prop_names(exoid,EX_NODE_SET,prop_names);
509     printf ("after ex_get_prop_names, error = %d\n", error);
510 
511 
512     for (i=0; i<num_props; i++)
513       {
514         error = ex_get_prop_array(exoid, EX_NODE_SET, prop_names[i],
515                                   prop_values);
516         if (error == 0)
517           for (j=0; j<num_node_sets; j++)
518             printf ("node set %2d, property(%2d): '%s'= %5d\n",
519                     j+1, i+1, prop_names[i], prop_values[j]);
520         else
521           printf ("after ex_get_prop_array, error = %d\n", error);
522       }
523     for (i=0; i<num_props; i++)
524       free(prop_names[i]);
525     free(prop_values);
526 
527     /* read concatenated node sets; this produces the same information as
528      * the above code which reads individual node sets
529      */
530 
531     error = ex_inquire (exoid, EX_INQ_NODE_SETS, &num_node_sets, &fdum, cdum);
532     printf ("\nafter ex_inquire, error = %3d\n",error);
533 
534     ids = (int *) calloc(num_node_sets, sizeof(int));
535     num_nodes_per_set = (int *) calloc(num_node_sets, sizeof(int));
536     num_df_per_set = (int *) calloc(num_node_sets, sizeof(int));
537     node_ind = (int *) calloc(num_node_sets, sizeof(int));
538     df_ind = (int *) calloc(num_node_sets, sizeof(int));
539 
540     error = ex_inquire (exoid, EX_INQ_NS_NODE_LEN, &list_len, &fdum, cdum);
541     printf ("\nafter ex_inquire: EX_INQ_NS_NODE_LEN = %d, error = %3d\n",
542             list_len, error);
543     node_list = (int *) calloc(list_len, sizeof(int));
544 
545     error = ex_inquire (exoid, EX_INQ_NS_DF_LEN, &list_len, &fdum, cdum);
546     printf ("\nafter ex_inquire: EX_INQ_NS_DF_LEN = %d, error = %3d\n",
547             list_len, error);
548     dist_fact = (float *) calloc(list_len, sizeof(float));
549 
550     error = ex_get_concat_node_sets (exoid,ids,num_nodes_per_set,num_df_per_set,
551                                      node_ind, df_ind, node_list, dist_fact);
552     printf ("\nafter ex_get_concat_node_sets, error = %3d\n", error);
553 
554     printf ("\nconcatenated node set info\n");
555 
556     printf ("ids = \n");
557     for (i=0; i<num_node_sets; i++) printf ("%3d\n", ids[i]);
558 
559     printf ("num_nodes_per_set = \n");
560     for (i=0; i<num_node_sets; i++) printf ("%3d\n", num_nodes_per_set[i]);
561 
562     printf ("node_ind = \n");
563     for (i=0; i<num_node_sets; i++) printf ("%3d\n", node_ind[i]);
564 
565     printf ("node_list = \n");
566     for (i=0; i<list_len; i++) printf ("%3d\n", node_list[i]);
567 
568     printf ("dist_fact = \n");
569     for (i=0; i<list_len; i++) printf ("%5.3f\n", dist_fact[i]);
570 
571     free (ids);
572     free (df_ind);
573     free (node_ind);
574     free (num_df_per_set);
575     free (node_list);
576     free (dist_fact);
577   }
578 
579   /* read individual side sets */
580 
581   if (num_side_sets > 0) {
582     ids = (int *) calloc(num_side_sets, sizeof(int));
583 
584     error = ex_get_side_set_ids (exoid, ids);
585     printf ("\nafter ex_get_side_set_ids, error = %3d\n", error);
586 
587     for (i=0; i<num_side_sets; i++) {
588       sset_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
589     }
590 
591     error = ex_get_names(exoid, EX_SIDE_SET, sset_names);
592     printf ("\nafter ex_get_names, error = %3d\n", error);
593 
594     for (i=0; i<num_side_sets; i++)
595       {
596 	ex_get_name(exoid, EX_SIDE_SET, ids[i], name);
597 	if (strcmp(name, sset_names[i]) != 0) {
598 	  printf ("error in ex_get_name for sideset id %d\n", ids[i]);
599 	}
600 
601         error = ex_get_side_set_param (exoid, ids[i], &num_sides_in_set,
602                                        &num_df_in_set);
603         printf ("\nafter ex_get_side_set_param, error = %3d\n", error);
604 
605         printf ("side set %2d parameters:\n",ids[i]);
606 	printf ("name = '%s'\n", sset_names[i]);
607         printf ("num_sides = %3d\n",num_sides_in_set);
608         printf ("num_dist_factors = %3d\n", num_df_in_set);
609 	free(sset_names[i]);
610 
611 
612         /* Note: The # of elements is same as # of sides!  */
613         num_elem_in_set = num_sides_in_set;
614         elem_list = (int *) calloc(num_elem_in_set, sizeof(int));
615         side_list = (int *) calloc(num_sides_in_set, sizeof(int));
616         node_ctr_list = (int *) calloc(num_elem_in_set, sizeof(int));
617         node_list = (int *) calloc(num_elem_in_set*21, sizeof(int));
618         dist_fact = (float *) calloc(num_df_in_set, sizeof(float));
619 
620         error = ex_get_side_set (exoid, ids[i], elem_list, side_list);
621         printf ("\nafter ex_get_side_set, error = %3d\n", error);
622 
623         error = ex_get_side_set_node_list (exoid, ids[i], node_ctr_list,
624                                            node_list);
625         printf ("\nafter ex_get_side_set_node_list, error = %3d\n", error);
626 
627         if (num_df_in_set > 0)
628           {
629             error = ex_get_side_set_dist_fact (exoid, ids[i], dist_fact);
630             printf ("\nafter ex_get_side_set_dist_fact, error = %3d\n", error);
631           }
632 
633         printf ("element list for side set %2d\n", ids[i]);
634         for (j=0; j<num_elem_in_set; j++)
635           {
636             printf ("%3d\n", elem_list[j]);
637           }
638 
639         printf ("side list for side set %2d\n", ids[i]);
640         for (j=0; j<num_sides_in_set; j++)
641           {
642             printf ("%3d\n", side_list[j]);
643           }
644 
645         node_ctr = 0;
646         printf ("node list for side set %2d\n", ids[i]);
647         for (k=0; k<num_elem_in_set; k++)
648           {
649             for (j=0; j<node_ctr_list[k]; j++)
650               {
651                 printf ("%3d\n", node_list[node_ctr+j]);
652               }
653             node_ctr += node_ctr_list[k];
654           }
655 
656         if (num_df_in_set > 0)
657           {
658             printf ("dist factors for side set %2d\n", ids[i]);
659 
660             for (j=0; j<num_df_in_set; j++)
661               {
662                 printf ("%5.3f\n", dist_fact[j]);
663               }
664           }
665         else
666           printf ("no dist factors for side set %2d\n", ids[i]);
667 
668         free (elem_list);
669         free (side_list);
670         free (node_ctr_list);
671         free (node_list);
672         free (dist_fact);
673 
674       }
675 
676     /* read side set properties */
677     error = ex_inquire (exoid, EX_INQ_SS_PROP, &num_props, &fdum, cdum);
678     printf ("\nafter ex_inquire, error = %d\n", error);
679     printf ("\nThere are %2d properties for each side set\n", num_props);
680 
681     for (i=0; i<num_props; i++)
682       {
683         prop_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
684       }
685 
686     error = ex_get_prop_names(exoid,EX_SIDE_SET,prop_names);
687     printf ("after ex_get_prop_names, error = %d\n", error);
688 
689 
690     for (i=0; i<num_props; i++)
691       {
692         for (j=0; j<num_side_sets; j++)
693           {
694             error = ex_get_prop(exoid, EX_SIDE_SET, ids[j], prop_names[i],
695                                 &prop_value);
696             if (error == 0)
697               printf ("side set %2d, property(%2d): '%s'= %5d\n",
698                       j+1, i+1, prop_names[i], prop_value);
699             else
700               printf ("after ex_get_prop, error = %d\n", error);
701           }
702       }
703     for (i=0; i<num_props; i++)
704       free(prop_names[i]);
705     free (ids);
706 
707     error = ex_inquire (exoid, EX_INQ_SIDE_SETS, &num_side_sets, &fdum, cdum);
708     printf ("\nafter ex_inquire: EX_INQ_SIDE_SETS = %d,  error = %d\n",
709             num_side_sets, error);
710 
711     if (num_side_sets > 0)
712       {
713         error = ex_inquire(exoid, EX_INQ_SS_ELEM_LEN, &elem_list_len, &fdum, cdum);
714         printf ("\nafter ex_inquire: EX_INQ_SS_ELEM_LEN = %d,  error = %d\n",
715                 elem_list_len, error);
716 
717         error = ex_inquire(exoid, EX_INQ_SS_NODE_LEN, &node_list_len, &fdum, cdum);
718         printf ("\nafter ex_inquire: EX_INQ_SS_NODE_LEN = %d,  error = %d\n",
719                 node_list_len, error);
720 
721         error = ex_inquire(exoid, EX_INQ_SS_DF_LEN, &df_list_len, &fdum, cdum);
722         printf ("\nafter ex_inquire: EX_INQ_SS_DF_LEN = %d,  error = %d\n",
723                 df_list_len, error);
724       }
725 
726     /* read concatenated side sets; this produces the same information as
727      * the above code which reads individual side sets
728      */
729 
730     /* concatenated side set read */
731 
732     if (num_side_sets > 0) {
733       ids = (int *) calloc(num_side_sets, sizeof(int));
734       num_elem_per_set = (int *) calloc(num_side_sets, sizeof(int));
735       num_df_per_set = (int *) calloc(num_side_sets, sizeof(int));
736       elem_ind = (int *) calloc(num_side_sets, sizeof(int));
737       df_ind = (int *) calloc(num_side_sets, sizeof(int));
738       elem_list = (int *) calloc(elem_list_len, sizeof(int));
739       side_list = (int *) calloc(elem_list_len, sizeof(int));
740       dist_fact = (float *) calloc(df_list_len, sizeof(float));
741 
742       error = ex_get_concat_side_sets (exoid, ids, num_elem_per_set,
743                                        num_df_per_set, elem_ind, df_ind,
744                                        elem_list, side_list, dist_fact);
745       printf ("\nafter ex_get_concat_side_sets, error = %3d\n", error);
746 
747       printf ("concatenated side set info\n");
748 
749       printf ("ids = \n");
750       for (i=0; i<num_side_sets; i++) printf ("%3d\n", ids[i]);
751 
752       printf ("num_elem_per_set = \n");
753       for (i=0; i<num_side_sets; i++) printf ("%3d\n", num_elem_per_set[i]);
754 
755       printf ("num_dist_per_set = \n");
756       for (i=0; i<num_side_sets; i++) printf ("%3d\n", num_df_per_set[i]);
757 
758       printf ("elem_ind = \n");
759       for (i=0; i<num_side_sets; i++) printf ("%3d\n", elem_ind[i]);
760 
761       printf ("dist_ind = \n");
762       for (i=0; i<num_side_sets; i++) printf ("%3d\n", df_ind[i]);
763 
764       printf ("elem_list = \n");
765       for (i=0; i<elem_list_len; i++) printf ("%3d\n", elem_list[i]);
766 
767       printf ("side_list = \n");
768       for (i=0; i<elem_list_len; i++) printf ("%3d\n", side_list[i]);
769 
770       printf ("dist_fact = \n");
771       for (i=0; i<df_list_len; i++) printf ("%5.3f\n", dist_fact[i]);
772 
773       free (ids);
774       free (num_df_per_set);
775       free (df_ind);
776       free (elem_ind);
777       free (elem_list);
778       free (side_list);
779       free (dist_fact);
780     }
781   }
782   /* end of concatenated side set read */
783 
784   /* read QA records */
785 
786   ex_inquire (exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum);
787 
788   for (i=0; i<num_qa_rec; i++)
789     {
790       for (j=0; j<4; j++)
791         {
792           qa_record[i][j] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
793         }
794     }
795 
796   error = ex_get_qa (exoid, qa_record);
797   printf ("\nafter ex_get_qa, error = %3d\n", error);
798 
799   printf ("QA records = \n");
800   for (i=0; i<num_qa_rec; i++)
801     {
802       for (j=0; j<4; j++)
803         {
804           printf (" '%s'\n", qa_record[i][j]);
805           free(qa_record[i][j]);
806         }
807     }
808 
809   /* read information records */
810 
811   error = ex_inquire (exoid, EX_INQ_INFO, &num_info, &fdum, cdum);
812   printf ("\nafter ex_inquire, error = %3d\n", error);
813 
814   for (i=0; i<num_info; i++)
815     {
816       info[i] = (char *) calloc ((MAX_LINE_LENGTH+1), sizeof(char));
817     }
818 
819   error = ex_get_info (exoid, info);
820   printf ("\nafter ex_get_info, error = %3d\n", error);
821 
822   printf ("info records = \n");
823   for (i=0; i<num_info; i++)
824     {
825       printf (" '%s'\n", info[i]);
826       free(info[i]);
827     }
828 
829   /* read global variables parameters and names */
830 
831   error = ex_get_var_param (exoid, "g", &num_glo_vars);
832   printf ("\nafter ex_get_var_param, error = %3d\n", error);
833 
834   for (i=0; i<num_glo_vars; i++)
835     {
836       var_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
837     }
838 
839   error = ex_get_var_names (exoid, "g", num_glo_vars, var_names);
840   printf ("\nafter ex_get_var_names, error = %3d\n", error);
841 
842   printf ("There are %2d global variables; their names are :\n",
843           num_glo_vars);
844   for (i=0; i<num_glo_vars; i++)
845     {
846       printf (" '%s'\n", var_names[i]);
847       free(var_names[i]);
848     }
849 
850   /* read nodal variables parameters and names */
851   num_nod_vars = 0;
852   if (num_nodes > 0) {
853     error = ex_get_var_param (exoid, "n", &num_nod_vars);
854     printf ("\nafter ex_get_var_param, error = %3d\n", error);
855 
856     for (i=0; i<num_nod_vars; i++)
857       {
858         var_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
859       }
860 
861     error = ex_get_var_names (exoid, "n", num_nod_vars, var_names);
862     printf ("\nafter ex_get_var_names, error = %3d\n", error);
863 
864     printf ("There are %2d nodal variables; their names are :\n", num_nod_vars);
865     for (i=0; i<num_nod_vars; i++)
866       {
867         printf (" '%s'\n", var_names[i]);
868         free(var_names[i]);
869       }
870   }
871 
872   /* read element variables parameters and names */
873 
874   num_ele_vars = 0;
875   if (num_elem > 0) {
876     error = ex_get_var_param (exoid, "e", &num_ele_vars);
877     printf ("\nafter ex_get_var_param, error = %3d\n", error);
878 
879     for (i=0; i<num_ele_vars; i++)
880       {
881         var_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
882       }
883 
884     error = ex_get_var_names (exoid, "e", num_ele_vars, var_names);
885     printf ("\nafter ex_get_var_names, error = %3d\n", error);
886 
887     printf ("There are %2d element variables; their names are :\n",
888             num_ele_vars);
889     for (i=0; i<num_ele_vars; i++)
890       {
891         printf (" '%s'\n", var_names[i]);
892         free(var_names[i]);
893       }
894 
895     /* read element variable truth table */
896 
897     if (num_ele_vars > 0) {
898       truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int));
899 
900       error = ex_get_elem_var_tab (exoid, num_elem_blk, num_ele_vars, truth_tab);
901       printf ("\nafter ex_get_elem_var_tab, error = %3d\n", error);
902 
903       printf ("This is the element variable truth table:\n");
904 
905       k = 0;
906       for (i=0; i<num_elem_blk*num_ele_vars; i++)
907         {
908           printf ("%2d\n", truth_tab[k++]);
909         }
910       free (truth_tab);
911     }
912   }
913 
914   /* read nodeset variables parameters and names */
915 
916   num_nset_vars = 0;
917   if (num_node_sets > 0) {
918     error = ex_get_var_param (exoid, "m", &num_nset_vars);
919     printf ("\nafter ex_get_var_param, error = %3d\n", error);
920 
921     if (num_nset_vars > 0) {
922       for (i=0; i<num_nset_vars; i++)
923 	{
924 	  var_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
925 	}
926 
927       error = ex_get_var_names (exoid, "m", num_nset_vars, var_names);
928       printf ("\nafter ex_get_var_names, error = %3d\n", error);
929 
930       printf ("There are %2d nodeset variables; their names are :\n",
931 	      num_nset_vars);
932       for (i=0; i<num_nset_vars; i++)
933 	{
934 	  printf (" '%s'\n", var_names[i]);
935 	  free(var_names[i]);
936 	}
937 
938       /* read nodeset variable truth table */
939 
940       if (num_nset_vars > 0) {
941 	truth_tab = (int *) calloc ((num_node_sets*num_nset_vars), sizeof(int));
942 
943 	error = ex_get_nset_var_tab (exoid, num_node_sets, num_nset_vars, truth_tab);
944 	printf ("\nafter ex_get_nset_var_tab, error = %3d\n", error);
945 
946 	printf ("This is the nodeset variable truth table:\n");
947 
948 	k = 0;
949 	for (i=0; i<num_node_sets*num_nset_vars; i++)
950 	  {
951 	    printf ("%2d\n", truth_tab[k++]);
952 	  }
953 	free (truth_tab);
954       }
955     }
956   }
957 
958   /* read sideset variables parameters and names */
959 
960   num_sset_vars = 0;
961   if (num_side_sets > 0) {
962     error = ex_get_var_param (exoid, "s", &num_sset_vars);
963     printf ("\nafter ex_get_var_param, error = %3d\n", error);
964 
965     if (num_sset_vars > 0) {
966       for (i=0; i<num_sset_vars; i++)
967 	{
968 	  var_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char));
969 	}
970 
971       error = ex_get_var_names (exoid, "s", num_sset_vars, var_names);
972       printf ("\nafter ex_get_var_names, error = %3d\n", error);
973 
974       printf ("There are %2d sideset variables; their names are :\n",
975 	      num_sset_vars);
976       for (i=0; i<num_sset_vars; i++)
977 	{
978 	  printf (" '%s'\n", var_names[i]);
979 	  free(var_names[i]);
980 	}
981 
982       /* read sideset variable truth table */
983 
984       if (num_sset_vars > 0) {
985 	truth_tab = (int *) calloc ((num_side_sets*num_sset_vars), sizeof(int));
986 
987 	error = ex_get_sset_var_tab (exoid, num_side_sets, num_sset_vars, truth_tab);
988 	printf ("\nafter ex_get_sset_var_tab, error = %3d\n", error);
989 
990 	printf ("This is the sideset variable truth table:\n");
991 
992 	k = 0;
993 	for (i=0; i<num_side_sets*num_sset_vars; i++)
994 	  {
995 	    printf ("%2d\n", truth_tab[k++]);
996 	  }
997 	free (truth_tab);
998       }
999     }
1000   }
1001 
1002   /* determine how many time steps are stored */
1003 
1004   error = ex_inquire (exoid, EX_INQ_TIME, &num_time_steps, &fdum, cdum);
1005   printf ("\nafter ex_inquire, error = %3d\n", error);
1006   printf ("There are %2d time steps in the database.\n", num_time_steps);
1007 
1008   /* read time value at one time step */
1009 
1010   time_step = 3;
1011   error = ex_get_time (exoid, time_step, &time_value);
1012   printf ("\nafter ex_get_time, error = %3d\n", error);
1013 
1014   printf ("time value at time step %2d = %5.3f\n", time_step, time_value);
1015 
1016   /* read time values at all time steps */
1017 
1018   time_values = (float *) calloc (num_time_steps, sizeof(float));
1019 
1020   error = ex_get_all_times (exoid, time_values);
1021   printf ("\nafter ex_get_all_times, error = %3d\n", error);
1022 
1023   printf ("time values at all time steps are:\n");
1024   for (i=0; i<num_time_steps; i++) printf ("%5.3f\n", time_values[i]);
1025 
1026   free (time_values);
1027 
1028   /* read all global variables at one time step */
1029 
1030   var_values = (float *) calloc (num_glo_vars, sizeof(float));
1031 
1032   error = ex_get_glob_vars (exoid, time_step, num_glo_vars, var_values);
1033   printf ("\nafter ex_get_glob_vars, error = %3d\n", error);
1034 
1035   printf ("global variable values at time step %2d\n", time_step);
1036   for (i=0; i<num_glo_vars; i++) printf ("%5.3f\n", var_values[i]);
1037 
1038   free (var_values);
1039 
1040   /* read a single global variable through time */
1041 
1042   var_index = 1;
1043   beg_time = 1;
1044   end_time = -1;
1045 
1046   var_values = (float *) calloc (num_time_steps, sizeof(float));
1047 
1048   error = ex_get_glob_var_time (exoid, var_index, beg_time, end_time,
1049                                 var_values);
1050   printf ("\nafter ex_get_glob_var_time, error = %3d\n", error);
1051 
1052   printf ("global variable %2d values through time:\n", var_index);
1053   for (i=0; i<num_time_steps; i++) printf ("%5.3f\n", var_values[i]);
1054 
1055   free (var_values);
1056 
1057   /* read a nodal variable at one time step */
1058 
1059   if (num_nodes > 0) {
1060     var_values = (float *) calloc (num_nodes, sizeof(float));
1061 
1062     error = ex_get_nodal_var (exoid, time_step, var_index, num_nodes,
1063                               var_values);
1064     printf ("\nafter ex_get_nodal_var, error = %3d\n", error);
1065 
1066     printf ("nodal variable %2d values at time step %2d\n", var_index,
1067             time_step);
1068     for (i=0; i<num_nodes; i++) printf ("%5.3f\n", var_values[i]);
1069 
1070     free (var_values);
1071 
1072     /* read a nodal variable through time */
1073 
1074     var_values = (float *) calloc (num_time_steps, sizeof(float));
1075 
1076     node_num = 1;
1077     error = ex_get_nodal_var_time (exoid, var_index, node_num, beg_time,
1078                                    end_time, var_values);
1079     printf ("\nafter ex_get_nodal_var_time, error = %3d\n", error);
1080 
1081     printf ("nodal variable %2d values for node %2d through time:\n", var_index,
1082             node_num);
1083     for (i=0; i<num_time_steps; i++) printf ("%5.3f\n", var_values[i]);
1084 
1085     free (var_values);
1086   }
1087   /* read an element variable at one time step */
1088 
1089   if (num_elem_blk > 0) {
1090     ids = (int *) calloc(num_elem_blk, sizeof(int));
1091 
1092     error = ex_get_elem_blk_ids (exoid, ids);
1093     printf ("\n after ex_get_elem_blk_ids, error = %3d\n", error);
1094 
1095     for (i=0; i<num_elem_blk; i++)
1096       {
1097 	if (num_elem_in_block[i] > 0) {
1098 	  var_values = (float *) calloc (num_elem_in_block[i], sizeof(float));
1099 
1100 	  error = ex_get_elem_var (exoid, time_step, var_index, ids[i],
1101 				   num_elem_in_block[i], var_values);
1102 	  printf ("\nafter ex_get_elem_var, error = %3d\n", error);
1103 
1104 	  if (!error)
1105 	    {
1106 	      printf
1107 		("element variable %2d values of element block %2d at time step %2d\n",
1108 		 var_index, ids[i], time_step);
1109 	      for (j=0; j<num_elem_in_block[i]; j++)
1110 		printf ("%5.3f\n", var_values[j]);
1111 	    }
1112 
1113 	  free (var_values);
1114 	}
1115       }
1116     free (num_elem_in_block);
1117     free(ids);
1118   }
1119   /* read an element variable through time */
1120 
1121   if (num_ele_vars > 0) {
1122     var_values = (float *) calloc (num_time_steps, sizeof(float));
1123 
1124     var_index = 2;
1125     elem_num = 2;
1126     error = ex_get_elem_var_time (exoid, var_index, elem_num, beg_time,
1127                                   end_time, var_values);
1128     printf ("\nafter ex_get_elem_var_time, error = %3d\n", error);
1129 
1130     printf ("element variable %2d values for element %2d through time:\n",
1131             var_index, elem_num);
1132     for (i=0; i<num_time_steps; i++) printf ("%5.3f\n", var_values[i]);
1133 
1134     free (var_values);
1135   }
1136 
1137   /* read a sideset variable at one time step */
1138 
1139   if (num_sset_vars > 0) {
1140     ids = (int *) calloc(num_side_sets, sizeof(int));
1141 
1142     error = ex_get_side_set_ids (exoid, ids);
1143     printf ("\n after ex_get_side_set_ids, error = %3d\n", error);
1144 
1145     for (i=0; i<num_side_sets; i++)
1146       {
1147         var_values = (float *) calloc (num_elem_per_set[i], sizeof(float));
1148 
1149         error = ex_get_sset_var (exoid, time_step, var_index, ids[i],
1150                                  num_elem_per_set[i], var_values);
1151         printf ("\nafter ex_get_sset_var, error = %3d\n", error);
1152 
1153         if (!error)
1154           {
1155             printf
1156               ("sideset variable %2d values of sideset %2d at time step %2d\n",
1157                var_index, ids[i], time_step);
1158             for (j=0; j<num_elem_per_set[i]; j++)
1159               printf ("%5.3f\n", var_values[j]);
1160           }
1161 
1162         free (var_values);
1163       }
1164     free (num_elem_per_set);
1165     free(ids);
1166   }
1167 
1168   /* read a nodeset variable at one time step */
1169 
1170   if (num_nset_vars > 0) {
1171     ids = (int *) calloc(num_node_sets, sizeof(int));
1172 
1173     error = ex_get_node_set_ids (exoid, ids);
1174     printf ("\n after ex_get_node_set_ids, error = %3d\n", error);
1175 
1176     for (i=0; i<num_node_sets; i++)
1177       {
1178         var_values = (float *) calloc (num_nodes_per_set[i], sizeof(float));
1179 
1180         error = ex_get_nset_var (exoid, time_step, var_index, ids[i],
1181                                  num_nodes_per_set[i], var_values);
1182         printf ("\nafter ex_get_nset_var, error = %3d\n", error);
1183 
1184         if (!error)
1185           {
1186             printf
1187               ("nodeset variable %2d values of nodeset %2d at time step %2d\n",
1188                var_index, ids[i], time_step);
1189             for (j=0; j<num_nodes_per_set[i]; j++)
1190               printf ("%5.3f\n", var_values[j]);
1191           }
1192 
1193         free (var_values);
1194       }
1195     free(ids);
1196   }
1197   if (num_node_sets > 0)
1198     free (num_nodes_per_set);
1199 
1200   error = ex_close (exoid);
1201   printf ("\nafter ex_close, error = %3d\n", error);
1202   return 0;
1203 }
1204