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