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