PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 77ms RepoModel.GetById 10ms app.codeStats 1ms

/contrib/exodusii/5.22b/exodus/cbind/test/testrd1.c

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