PageRenderTime 4ms CodeModel.GetById 4ms app.highlight 76ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/exodusii/5.22b/exodus/cbind/test/testrd-nsided.c

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