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