| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020 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 |
* testwt - test write an ExodusII database file |
| 11 |
* |
| 12 |
* author - Sandia National Laboratories |
| 13 |
* Larry A. Schoof - Original |
| 14 |
* Vic Yarberry - Added headers and error logging |
| 15 |
* 7/7/93 Modified for use with Exodus 2.00 |
| 16 |
* |
| 17 |
* |
| 18 |
* environment - UNIX |
| 19 |
* |
| 20 |
* entry conditions - |
| 21 |
* |
| 22 |
* exit conditions - |
| 23 |
* |
| 24 |
* revision history - |
| 25 |
* |
| 26 |
* This is a test program for the C binding of the EXODUS II |
| 27 |
* database write routines. |
| 28 |
* |
| 29 |
* |
| 30 |
*****************************************************************************/ |
| 31 |
|
| 32 |
#include "exodusII.h" |
| 33 |
#include <stdio.h> |
| 34 |
#include <stdlib.h> |
| 35 |
|
| 36 |
int main(int argc, char **argv) |
| 37 |
{ |
| 38 |
int exoid, num_dim, num_nodes, num_elem, num_elem_blk; |
| 39 |
int num_elem_in_block[10], num_nodes_per_elem[10]; |
| 40 |
int num_face_in_sset[10], num_nodes_in_nset[10]; |
| 41 |
int num_node_sets, num_side_sets, error; |
| 42 |
int i, j, k, m, *elem_map, *connect; |
| 43 |
int node_list[100], elem_list[100], side_list[100]; |
| 44 |
int ebids[10], ssids[10], nsids[10]; |
| 45 |
int num_qa_rec, num_info; |
| 46 |
int num_glo_vars, num_nod_vars, num_ele_vars, num_sset_vars, num_nset_vars; |
| 47 |
int *truth_tab; |
| 48 |
int whole_time_step, num_time_steps; |
| 49 |
int CPU_word_size, IO_word_size; |
| 50 |
int prop_array[2]; |
| 51 |
|
| 52 |
float *glob_var_vals, *nodal_var_vals, *elem_var_vals; |
| 53 |
float *sset_var_vals, *nset_var_vals; |
| 54 |
float time_value; |
| 55 |
float x[100], y[100], z[100]; |
| 56 |
float attrib[1], dist_fact[100]; |
| 57 |
char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3]; |
| 58 |
char *block_names[10], *nset_names[10], *sset_names[10]; |
| 59 |
char *prop_names[2], *attrib_names[2]; |
| 60 |
|
| 61 |
ex_opts(EX_VERBOSE | EX_ABORT); |
| 62 |
|
| 63 |
/* Specify compute and i/o word size */ |
| 64 |
|
| 65 |
CPU_word_size = 0; /* sizeof(float) */ |
| 66 |
IO_word_size = 4; /* (4 bytes) */ |
| 67 |
|
| 68 |
/* create EXODUS II file */ |
| 69 |
|
| 70 |
exoid = ex_create("test.exo", /* filename path */ |
| 71 |
EX_CLOBBER, /* create mode */ |
| 72 |
&CPU_word_size, /* CPU float word size in bytes */ |
| 73 |
&IO_word_size); /* I/O float word size in bytes */ |
| 74 |
printf("after ex_create for test.exo, exoid = %d\n", exoid); |
| 75 |
printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size); |
| 76 |
|
| 77 |
/* initialize file with parameters */ |
| 78 |
|
| 79 |
num_dim = 3; |
| 80 |
num_nodes = 33; |
| 81 |
num_elem = 7; |
| 82 |
num_elem_blk = 7; |
| 83 |
num_node_sets = 2; |
| 84 |
num_side_sets = 5; |
| 85 |
|
| 86 |
error = ex_put_init(exoid, "This is a test", num_dim, num_nodes, num_elem, num_elem_blk, |
| 87 |
num_node_sets, num_side_sets); |
| 88 |
|
| 89 |
printf("after ex_put_init, error = %d\n", error); |
| 90 |
|
| 91 |
if (error) { |
| 92 |
ex_close(exoid); |
| 93 |
exit(-1); |
| 94 |
} |
| 95 |
|
| 96 |
/* write nodal coordinates values and names to database */ |
| 97 |
|
| 98 |
/* Quad #1 */ |
| 99 |
x[0] = 0.0; |
| 100 |
y[0] = 0.0; |
| 101 |
z[0] = 0.0; |
| 102 |
x[1] = 1.0; |
| 103 |
y[1] = 0.0; |
| 104 |
z[1] = 0.0; |
| 105 |
x[2] = 1.0; |
| 106 |
y[2] = 1.0; |
| 107 |
z[2] = 0.0; |
| 108 |
x[3] = 0.0; |
| 109 |
y[3] = 1.0; |
| 110 |
z[3] = 0.0; |
| 111 |
|
| 112 |
/* Quad #2 */ |
| 113 |
x[4] = 1.0; |
| 114 |
y[4] = 0.0; |
| 115 |
z[4] = 0.0; |
| 116 |
x[5] = 2.0; |
| 117 |
y[5] = 0.0; |
| 118 |
z[5] = 0.0; |
| 119 |
x[6] = 2.0; |
| 120 |
y[6] = 1.0; |
| 121 |
z[6] = 0.0; |
| 122 |
x[7] = 1.0; |
| 123 |
y[7] = 1.0; |
| 124 |
z[7] = 0.0; |
| 125 |
|
| 126 |
/* Hex #1 */ |
| 127 |
x[8] = 0.0; |
| 128 |
y[8] = 0.0; |
| 129 |
z[8] = 0.0; |
| 130 |
x[9] = 10.0; |
| 131 |
y[9] = 0.0; |
| 132 |
z[9] = 0.0; |
| 133 |
x[10] = 10.0; |
| 134 |
y[10] = 0.0; |
| 135 |
z[10] = -10.0; |
| 136 |
x[11] = 1.0; |
| 137 |
y[11] = 0.0; |
| 138 |
z[11] = -10.0; |
| 139 |
x[12] = 1.0; |
| 140 |
y[12] = 10.0; |
| 141 |
z[12] = 0.0; |
| 142 |
x[13] = 10.0; |
| 143 |
y[13] = 10.0; |
| 144 |
z[13] = 0.0; |
| 145 |
x[14] = 10.0; |
| 146 |
y[14] = 10.0; |
| 147 |
z[14] = -10.0; |
| 148 |
x[15] = 1.0; |
| 149 |
y[15] = 10.0; |
| 150 |
z[15] = -10.0; |
| 151 |
|
| 152 |
/* Tetra #1 */ |
| 153 |
x[16] = 0.0; |
| 154 |
y[16] = 0.0; |
| 155 |
z[16] = 0.0; |
| 156 |
x[17] = 1.0; |
| 157 |
y[17] = 0.0; |
| 158 |
z[17] = 5.0; |
| 159 |
x[18] = 10.0; |
| 160 |
y[18] = 0.0; |
| 161 |
z[18] = 2.0; |
| 162 |
x[19] = 7.0; |
| 163 |
y[19] = 5.0; |
| 164 |
z[19] = 3.0; |
| 165 |
|
| 166 |
/* Wedge #1 */ |
| 167 |
x[20] = 3.0; |
| 168 |
y[20] = 0.0; |
| 169 |
z[20] = 6.0; |
| 170 |
x[21] = 6.0; |
| 171 |
y[21] = 0.0; |
| 172 |
z[21] = 0.0; |
| 173 |
x[22] = 0.0; |
| 174 |
y[22] = 0.0; |
| 175 |
z[22] = 0.0; |
| 176 |
x[23] = 3.0; |
| 177 |
y[23] = 2.0; |
| 178 |
z[23] = 6.0; |
| 179 |
x[24] = 6.0; |
| 180 |
y[24] = 2.0; |
| 181 |
z[24] = 2.0; |
| 182 |
x[25] = 0.0; |
| 183 |
y[25] = 2.0; |
| 184 |
z[25] = 0.0; |
| 185 |
|
| 186 |
/* Tetra #2 */ |
| 187 |
x[26] = 2.7; |
| 188 |
y[26] = 1.7; |
| 189 |
z[26] = 2.7; |
| 190 |
x[27] = 6.0; |
| 191 |
y[27] = 1.7; |
| 192 |
z[27] = 3.3; |
| 193 |
x[28] = 5.7; |
| 194 |
y[28] = 1.7; |
| 195 |
z[28] = 1.7; |
| 196 |
x[29] = 3.7; |
| 197 |
y[29] = 0.0; |
| 198 |
z[29] = 2.3; |
| 199 |
|
| 200 |
/* 3d Tri */ |
| 201 |
x[30] = 0.0; |
| 202 |
y[30] = 0.0; |
| 203 |
z[30] = 0.0; |
| 204 |
x[31] = 10.0; |
| 205 |
y[31] = 0.0; |
| 206 |
z[31] = 0.0; |
| 207 |
x[32] = 10.0; |
| 208 |
y[32] = 10.0; |
| 209 |
z[32] = 10.0; |
| 210 |
|
| 211 |
error = ex_put_coord(exoid, NULL, NULL, z); |
| 212 |
printf("after ex_put_coord, error = %d\n", error); |
| 213 |
error = ex_put_coord(exoid, x, NULL, NULL); |
| 214 |
printf("after ex_put_coord, error = %d\n", error); |
| 215 |
error = ex_put_coord(exoid, NULL, y, NULL); |
| 216 |
printf("after ex_put_coord, error = %d\n", error); |
| 217 |
|
| 218 |
if (error) { |
| 219 |
ex_close(exoid); |
| 220 |
exit(-1); |
| 221 |
} |
| 222 |
|
| 223 |
coord_names[0] = "xcoor"; |
| 224 |
coord_names[1] = "ycoor"; |
| 225 |
coord_names[2] = "zcoor"; |
| 226 |
|
| 227 |
error = ex_put_coord_names(exoid, coord_names); |
| 228 |
printf("after ex_put_coord_names, error = %d\n", error); |
| 229 |
|
| 230 |
if (error) { |
| 231 |
ex_close(exoid); |
| 232 |
exit(-1); |
| 233 |
} |
| 234 |
|
| 235 |
/* Add nodal attributes */ |
| 236 |
error = ex_put_attr_param(exoid, EX_NODAL, 0, 2); |
| 237 |
printf("after ex_put_attr_param, error = %d\n", error); |
| 238 |
|
| 239 |
if (error) { |
| 240 |
ex_close(exoid); |
| 241 |
exit(-1); |
| 242 |
} |
| 243 |
|
| 244 |
error = ex_put_one_attr(exoid, EX_NODAL, 0, 1, x); |
| 245 |
if (error) { |
| 246 |
ex_close(exoid); |
| 247 |
exit(-1); |
| 248 |
} |
| 249 |
|
| 250 |
error = ex_put_one_attr(exoid, EX_NODAL, 0, 2, y); |
| 251 |
if (error) { |
| 252 |
ex_close(exoid); |
| 253 |
exit(-1); |
| 254 |
} |
| 255 |
|
| 256 |
{ |
| 257 |
attrib_names[0] = "Node_attr_1"; |
| 258 |
attrib_names[1] = "Node_attr_2"; |
| 259 |
error = ex_put_attr_names(exoid, EX_NODAL, 0, attrib_names); |
| 260 |
if (error) { |
| 261 |
ex_close(exoid); |
| 262 |
exit(-1); |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
elem_map = (int *)calloc(num_elem, sizeof(int)); |
| 267 |
|
| 268 |
for (i = 1; i <= num_elem; i++) { |
| 269 |
elem_map[i - 1] = 10 * i; |
| 270 |
} |
| 271 |
|
| 272 |
error = ex_put_id_map(exoid, EX_ELEM_MAP, elem_map); |
| 273 |
printf("after ex_put_id_map, error = %d\n", error); |
| 274 |
|
| 275 |
if (error) { |
| 276 |
ex_close(exoid); |
| 277 |
exit(-1); |
| 278 |
} |
| 279 |
|
| 280 |
free(elem_map); |
| 281 |
|
| 282 |
/* write element block parameters */ |
| 283 |
|
| 284 |
block_names[0] = "block_1"; |
| 285 |
block_names[1] = "block_2"; |
| 286 |
block_names[2] = "block_3"; |
| 287 |
block_names[3] = "block_4"; |
| 288 |
block_names[4] = "block_5"; |
| 289 |
block_names[5] = "block_6"; |
| 290 |
block_names[6] = "block_7"; |
| 291 |
|
| 292 |
num_elem_in_block[0] = 1; |
| 293 |
num_elem_in_block[1] = 1; |
| 294 |
num_elem_in_block[2] = 1; |
| 295 |
num_elem_in_block[3] = 1; |
| 296 |
num_elem_in_block[4] = 1; |
| 297 |
num_elem_in_block[5] = 1; |
| 298 |
num_elem_in_block[6] = 1; |
| 299 |
|
| 300 |
num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads */ |
| 301 |
num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads */ |
| 302 |
num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes */ |
| 303 |
num_nodes_per_elem[3] = 4; /* elements in block #4 are 4-node tetras */ |
| 304 |
num_nodes_per_elem[4] = 6; /* elements in block #5 are 6-node wedges */ |
| 305 |
num_nodes_per_elem[5] = 8; /* elements in block #6 are 8-node tetras */ |
| 306 |
num_nodes_per_elem[6] = 3; /* elements in block #7 are 3-node tris */ |
| 307 |
|
| 308 |
ebids[0] = 10; |
| 309 |
ebids[1] = 11; |
| 310 |
ebids[2] = 12; |
| 311 |
ebids[3] = 13; |
| 312 |
ebids[4] = 14; |
| 313 |
ebids[5] = 15; |
| 314 |
ebids[6] = 16; |
| 315 |
|
| 316 |
error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[0], "quad", num_elem_in_block[0], |
| 317 |
num_nodes_per_elem[0], 0, 0, 1); |
| 318 |
printf("after ex_put_elem_block, error = %d\n", error); |
| 319 |
|
| 320 |
if (error) { |
| 321 |
ex_close(exoid); |
| 322 |
exit(-1); |
| 323 |
} |
| 324 |
|
| 325 |
error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[1], "quad", num_elem_in_block[1], |
| 326 |
num_nodes_per_elem[1], 0, 0, 1); |
| 327 |
printf("after ex_put_elem_block, error = %d\n", error); |
| 328 |
|
| 329 |
if (error) { |
| 330 |
ex_close(exoid); |
| 331 |
exit(-1); |
| 332 |
} |
| 333 |
|
| 334 |
error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[2], "hex", num_elem_in_block[2], |
| 335 |
num_nodes_per_elem[2], 0, 0, 1); |
| 336 |
printf("after ex_put_elem_block, error = %d\n", error); |
| 337 |
|
| 338 |
if (error) { |
| 339 |
ex_close(exoid); |
| 340 |
exit(-1); |
| 341 |
} |
| 342 |
|
| 343 |
error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[3], "tetra", num_elem_in_block[3], |
| 344 |
num_nodes_per_elem[3], 0, 0, 1); |
| 345 |
printf("after ex_put_elem_block, error = %d\n", error); |
| 346 |
|
| 347 |
if (error) { |
| 348 |
ex_close(exoid); |
| 349 |
exit(-1); |
| 350 |
} |
| 351 |
|
| 352 |
error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[4], "wedge", num_elem_in_block[4], |
| 353 |
num_nodes_per_elem[4], 0, 0, 1); |
| 354 |
printf("after ex_put_elem_block, error = %d\n", error); |
| 355 |
|
| 356 |
if (error) { |
| 357 |
ex_close(exoid); |
| 358 |
exit(-1); |
| 359 |
} |
| 360 |
|
| 361 |
error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[5], "tetra", num_elem_in_block[5], |
| 362 |
num_nodes_per_elem[5], 0, 0, 1); |
| 363 |
printf("after ex_put_elem_block, error = %d\n", error); |
| 364 |
|
| 365 |
if (error) { |
| 366 |
ex_close(exoid); |
| 367 |
exit(-1); |
| 368 |
} |
| 369 |
|
| 370 |
error = ex_put_block(exoid, EX_ELEM_BLOCK, ebids[6], "tri", num_elem_in_block[6], |
| 371 |
num_nodes_per_elem[6], 0, 0, 1); |
| 372 |
printf("after ex_put_elem_block, error = %d\n", error); |
| 373 |
|
| 374 |
if (error) { |
| 375 |
ex_close(exoid); |
| 376 |
exit(-1); |
| 377 |
} |
| 378 |
|
| 379 |
/* Write element block names */ |
| 380 |
error = ex_put_names(exoid, EX_ELEM_BLOCK, block_names); |
| 381 |
printf("after ex_put_names, error = %d\n", error); |
| 382 |
|
| 383 |
if (error) { |
| 384 |
ex_close(exoid); |
| 385 |
exit(-1); |
| 386 |
} |
| 387 |
|
| 388 |
/* write element block properties */ |
| 389 |
|
| 390 |
/* 12345678901234567890123456789012 */ |
| 391 |
prop_names[0] = "MATERIAL_PROPERTY_LONG_NAME_32CH"; |
| 392 |
prop_names[1] = "DENSITY"; |
| 393 |
error = ex_put_prop_names(exoid, EX_ELEM_BLOCK, 2, prop_names); |
| 394 |
printf("after ex_put_prop_names, error = %d\n", error); |
| 395 |
|
| 396 |
if (error) { |
| 397 |
ex_close(exoid); |
| 398 |
exit(-1); |
| 399 |
} |
| 400 |
|
| 401 |
error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], prop_names[0], 10); |
| 402 |
printf("after ex_put_prop, error = %d\n", error); |
| 403 |
if (error) { |
| 404 |
ex_close(exoid); |
| 405 |
exit(-1); |
| 406 |
} |
| 407 |
|
| 408 |
error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], prop_names[0], 20); |
| 409 |
printf("after ex_put_prop, error = %d\n", error); |
| 410 |
if (error) { |
| 411 |
ex_close(exoid); |
| 412 |
exit(-1); |
| 413 |
} |
| 414 |
|
| 415 |
error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], prop_names[0], 30); |
| 416 |
printf("after ex_put_prop, error = %d\n", error); |
| 417 |
if (error) { |
| 418 |
ex_close(exoid); |
| 419 |
exit(-1); |
| 420 |
} |
| 421 |
|
| 422 |
error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], prop_names[0], 40); |
| 423 |
printf("after ex_put_prop, error = %d\n", error); |
| 424 |
if (error) { |
| 425 |
ex_close(exoid); |
| 426 |
exit(-1); |
| 427 |
} |
| 428 |
|
| 429 |
error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], prop_names[0], 50); |
| 430 |
printf("after ex_put_prop, error = %d\n", error); |
| 431 |
if (error) { |
| 432 |
ex_close(exoid); |
| 433 |
exit(-1); |
| 434 |
} |
| 435 |
|
| 436 |
error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[5], prop_names[0], 60); |
| 437 |
printf("after ex_put_prop, error = %d\n", error); |
| 438 |
if (error) { |
| 439 |
ex_close(exoid); |
| 440 |
exit(-1); |
| 441 |
} |
| 442 |
|
| 443 |
error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[6], prop_names[0], 70); |
| 444 |
printf("after ex_put_prop, error = %d\n", error); |
| 445 |
if (error) { |
| 446 |
ex_close(exoid); |
| 447 |
exit(-1); |
| 448 |
} |
| 449 |
|
| 450 |
/* write element connectivity */ |
| 451 |
|
| 452 |
connect = (int *)calloc(8, sizeof(int)); |
| 453 |
connect[0] = 1; |
| 454 |
connect[1] = 2; |
| 455 |
connect[2] = 3; |
| 456 |
connect[3] = 4; |
| 457 |
|
| 458 |
error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL); |
| 459 |
printf("after ex_put_elem_conn, error = %d\n", error); |
| 460 |
if (error) { |
| 461 |
ex_close(exoid); |
| 462 |
exit(-1); |
| 463 |
} |
| 464 |
|
| 465 |
connect[0] = 5; |
| 466 |
connect[1] = 6; |
| 467 |
connect[2] = 7; |
| 468 |
connect[3] = 8; |
| 469 |
|
| 470 |
error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[1], connect, NULL, NULL); |
| 471 |
printf("after ex_put_elem_conn, error = %d\n", error); |
| 472 |
|
| 473 |
if (error) { |
| 474 |
ex_close(exoid); |
| 475 |
exit(-1); |
| 476 |
} |
| 477 |
|
| 478 |
connect[0] = 9; |
| 479 |
connect[1] = 10; |
| 480 |
connect[2] = 11; |
| 481 |
connect[3] = 12; |
| 482 |
connect[4] = 13; |
| 483 |
connect[5] = 14; |
| 484 |
connect[6] = 15; |
| 485 |
connect[7] = 16; |
| 486 |
|
| 487 |
error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[2], connect, NULL, NULL); |
| 488 |
printf("after ex_put_elem_conn, error = %d\n", error); |
| 489 |
|
| 490 |
if (error) { |
| 491 |
ex_close(exoid); |
| 492 |
exit(-1); |
| 493 |
} |
| 494 |
|
| 495 |
connect[0] = 17; |
| 496 |
connect[1] = 18; |
| 497 |
connect[2] = 19; |
| 498 |
connect[3] = 20; |
| 499 |
|
| 500 |
error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[3], connect, NULL, NULL); |
| 501 |
printf("after ex_put_elem_conn, error = %d\n", error); |
| 502 |
|
| 503 |
if (error) { |
| 504 |
ex_close(exoid); |
| 505 |
exit(-1); |
| 506 |
} |
| 507 |
|
| 508 |
connect[0] = 21; |
| 509 |
connect[1] = 22; |
| 510 |
connect[2] = 23; |
| 511 |
connect[3] = 24; |
| 512 |
connect[4] = 25; |
| 513 |
connect[5] = 26; |
| 514 |
|
| 515 |
error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[4], connect, NULL, NULL); |
| 516 |
printf("after ex_put_elem_conn, error = %d\n", error); |
| 517 |
|
| 518 |
if (error) { |
| 519 |
ex_close(exoid); |
| 520 |
exit(-1); |
| 521 |
} |
| 522 |
|
| 523 |
connect[0] = 17; |
| 524 |
connect[1] = 18; |
| 525 |
connect[2] = 19; |
| 526 |
connect[3] = 20; |
| 527 |
connect[4] = 27; |
| 528 |
connect[5] = 28; |
| 529 |
connect[6] = 30; |
| 530 |
connect[7] = 29; |
| 531 |
|
| 532 |
error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[5], connect, NULL, NULL); |
| 533 |
printf("after ex_put_elem_conn, error = %d\n", error); |
| 534 |
|
| 535 |
if (error) { |
| 536 |
ex_close(exoid); |
| 537 |
exit(-1); |
| 538 |
} |
| 539 |
|
| 540 |
connect[0] = 31; |
| 541 |
connect[1] = 32; |
| 542 |
connect[2] = 33; |
| 543 |
|
| 544 |
error = ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[6], connect, NULL, NULL); |
| 545 |
printf("after ex_put_elem_conn, error = %d\n", error); |
| 546 |
|
| 547 |
if (error) { |
| 548 |
ex_close(exoid); |
| 549 |
exit(-1); |
| 550 |
} |
| 551 |
|
| 552 |
free(connect); |
| 553 |
|
| 554 |
/* write element block attributes */ |
| 555 |
|
| 556 |
attrib[0] = 3.14159; |
| 557 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[0], attrib); |
| 558 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 559 |
if (error) { |
| 560 |
ex_close(exoid); |
| 561 |
exit(-1); |
| 562 |
} |
| 563 |
|
| 564 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[0], attrib); |
| 565 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 566 |
if (error) { |
| 567 |
ex_close(exoid); |
| 568 |
exit(-1); |
| 569 |
} |
| 570 |
|
| 571 |
attrib[0] = 6.14159; |
| 572 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[1], attrib); |
| 573 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 574 |
|
| 575 |
if (error) { |
| 576 |
ex_close(exoid); |
| 577 |
exit(-1); |
| 578 |
} |
| 579 |
|
| 580 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[2], attrib); |
| 581 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 582 |
|
| 583 |
if (error) { |
| 584 |
ex_close(exoid); |
| 585 |
exit(-1); |
| 586 |
} |
| 587 |
|
| 588 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[3], attrib); |
| 589 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 590 |
|
| 591 |
if (error) { |
| 592 |
ex_close(exoid); |
| 593 |
exit(-1); |
| 594 |
} |
| 595 |
|
| 596 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[4], attrib); |
| 597 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 598 |
|
| 599 |
if (error) { |
| 600 |
ex_close(exoid); |
| 601 |
exit(-1); |
| 602 |
} |
| 603 |
|
| 604 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[5], attrib); |
| 605 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 606 |
|
| 607 |
if (error) { |
| 608 |
ex_close(exoid); |
| 609 |
exit(-1); |
| 610 |
} |
| 611 |
|
| 612 |
error = ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[6], attrib); |
| 613 |
printf("after ex_put_elem_attr, error = %d\n", error); |
| 614 |
|
| 615 |
if (error) { |
| 616 |
ex_close(exoid); |
| 617 |
exit(-1); |
| 618 |
} |
| 619 |
|
| 620 |
attrib_names[0] = "THICKNESS"; |
| 621 |
for (i = 0; i < 7; i++) { |
| 622 |
error = ex_put_attr_names(exoid, EX_ELEM_BLOCK, ebids[i], attrib_names); |
| 623 |
printf("after ex_put_elem_attr_names, error = %d\n", error); |
| 624 |
if (error) { |
| 625 |
ex_close(exoid); |
| 626 |
exit(-1); |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
/* write individual node sets */ |
| 631 |
|
| 632 |
num_nodes_in_nset[0] = 5; |
| 633 |
num_nodes_in_nset[1] = 3; |
| 634 |
|
| 635 |
nsids[0] = 20; |
| 636 |
nsids[1] = 21; |
| 637 |
|
| 638 |
error = ex_put_set_param(exoid, EX_NODE_SET, nsids[0], 5, 5); |
| 639 |
printf("after ex_put_node_set_param, error = %d\n", error); |
| 640 |
|
| 641 |
if (error) { |
| 642 |
ex_close(exoid); |
| 643 |
exit(-1); |
| 644 |
} |
| 645 |
|
| 646 |
node_list[0] = 10; |
| 647 |
node_list[1] = 11; |
| 648 |
node_list[2] = 12; |
| 649 |
node_list[3] = 13; |
| 650 |
node_list[4] = 14; |
| 651 |
|
| 652 |
dist_fact[0] = 1.0; |
| 653 |
dist_fact[1] = 2.0; |
| 654 |
dist_fact[2] = 3.0; |
| 655 |
dist_fact[3] = 4.0; |
| 656 |
dist_fact[4] = 5.0; |
| 657 |
|
| 658 |
error = ex_put_set(exoid, EX_NODE_SET, nsids[0], node_list, NULL); |
| 659 |
printf("after ex_put_node_set, error = %d\n", error); |
| 660 |
if (error) { |
| 661 |
ex_close(exoid); |
| 662 |
exit(-1); |
| 663 |
} |
| 664 |
|
| 665 |
error = ex_put_set_dist_fact(exoid, EX_NODE_SET, nsids[0], dist_fact); |
| 666 |
printf("after ex_put_node_set_dist_fact, error = %d\n", error); |
| 667 |
if (error) { |
| 668 |
ex_close(exoid); |
| 669 |
exit(-1); |
| 670 |
} |
| 671 |
|
| 672 |
error = ex_put_set_param(exoid, EX_NODE_SET, nsids[1], 3, 3); |
| 673 |
printf("after ex_put_node_set_param, error = %d\n", error); |
| 674 |
|
| 675 |
if (error) { |
| 676 |
ex_close(exoid); |
| 677 |
exit(-1); |
| 678 |
} |
| 679 |
|
| 680 |
node_list[0] = 20; |
| 681 |
node_list[1] = 21; |
| 682 |
node_list[2] = 22; |
| 683 |
|
| 684 |
dist_fact[0] = 1.1; |
| 685 |
dist_fact[1] = 2.1; |
| 686 |
dist_fact[2] = 3.1; |
| 687 |
|
| 688 |
error = ex_put_set(exoid, EX_NODE_SET, nsids[1], node_list, NULL); |
| 689 |
printf("after ex_put_node_set, error = %d\n", error); |
| 690 |
if (error) { |
| 691 |
ex_close(exoid); |
| 692 |
exit(-1); |
| 693 |
} |
| 694 |
|
| 695 |
error = ex_put_set_dist_fact(exoid, EX_NODE_SET, nsids[1], dist_fact); |
| 696 |
printf("after ex_put_node_set_dist_fact, error = %d\n", error); |
| 697 |
if (error) { |
| 698 |
ex_close(exoid); |
| 699 |
exit(-1); |
| 700 |
} |
| 701 |
|
| 702 |
/* Write node set names */ |
| 703 |
nset_names[0] = "nset_1"; |
| 704 |
nset_names[1] = "nset_2"; |
| 705 |
|
| 706 |
error = ex_put_names(exoid, EX_NODE_SET, nset_names); |
| 707 |
printf("after ex_put_names, error = %d\n", error); |
| 708 |
|
| 709 |
if (error) { |
| 710 |
ex_close(exoid); |
| 711 |
exit(-1); |
| 712 |
} |
| 713 |
|
| 714 |
error = ex_put_prop(exoid, EX_NODE_SET, nsids[0], "FACE", 4); |
| 715 |
printf("after ex_put_prop, error = %d\n", error); |
| 716 |
if (error) { |
| 717 |
ex_close(exoid); |
| 718 |
exit(-1); |
| 719 |
} |
| 720 |
|
| 721 |
error = ex_put_prop(exoid, EX_NODE_SET, nsids[1], "FACE", 5); |
| 722 |
printf("after ex_put_prop, error = %d\n", error); |
| 723 |
|
| 724 |
if (error) { |
| 725 |
ex_close(exoid); |
| 726 |
exit(-1); |
| 727 |
} |
| 728 |
|
| 729 |
prop_array[0] = 1000; |
| 730 |
prop_array[1] = 2000; |
| 731 |
|
| 732 |
error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array); |
| 733 |
printf("after ex_put_prop_array, error = %d\n", error); |
| 734 |
if (error) { |
| 735 |
ex_close(exoid); |
| 736 |
exit(-1); |
| 737 |
} |
| 738 |
|
| 739 |
/* Add nodeset attributes */ |
| 740 |
error = ex_put_attr_param(exoid, EX_NODE_SET, nsids[0], 1); |
| 741 |
printf("after ex_put_attr_param, error = %d\n", error); |
| 742 |
|
| 743 |
if (error) { |
| 744 |
ex_close(exoid); |
| 745 |
exit(-1); |
| 746 |
} |
| 747 |
|
| 748 |
error = ex_put_attr(exoid, EX_NODE_SET, nsids[0], x); |
| 749 |
if (error) { |
| 750 |
ex_close(exoid); |
| 751 |
exit(-1); |
| 752 |
} |
| 753 |
|
| 754 |
{ |
| 755 |
attrib_names[0] = "Nodeset_attribute"; |
| 756 |
error = ex_put_attr_names(exoid, EX_NODE_SET, nsids[0], attrib_names); |
| 757 |
if (error) { |
| 758 |
ex_close(exoid); |
| 759 |
exit(-1); |
| 760 |
} |
| 761 |
} |
| 762 |
|
| 763 |
/* write individual side sets */ |
| 764 |
num_face_in_sset[0] = 2; |
| 765 |
num_face_in_sset[1] = 2; |
| 766 |
num_face_in_sset[2] = 7; |
| 767 |
num_face_in_sset[3] = 8; |
| 768 |
num_face_in_sset[4] = 10; |
| 769 |
|
| 770 |
ssids[0] = 30; |
| 771 |
ssids[1] = 31; |
| 772 |
ssids[2] = 32; |
| 773 |
ssids[3] = 33; |
| 774 |
ssids[4] = 34; |
| 775 |
|
| 776 |
/* side set #1 - quad */ |
| 777 |
|
| 778 |
error = ex_put_set_param(exoid, EX_SIDE_SET, ssids[0], 2, 4); |
| 779 |
printf("after ex_put_side_set_param, error = %d\n", error); |
| 780 |
|
| 781 |
if (error) { |
| 782 |
ex_close(exoid); |
| 783 |
exit(-1); |
| 784 |
} |
| 785 |
|
| 786 |
elem_list[0] = 2; |
| 787 |
elem_list[1] = 2; |
| 788 |
|
| 789 |
side_list[0] = 4; |
| 790 |
side_list[1] = 2; |
| 791 |
|
| 792 |
dist_fact[0] = 30.0; |
| 793 |
dist_fact[1] = 30.1; |
| 794 |
dist_fact[2] = 30.2; |
| 795 |
dist_fact[3] = 30.3; |
| 796 |
|
| 797 |
error = ex_put_set(exoid, EX_SIDE_SET, 30, elem_list, side_list); |
| 798 |
printf("after ex_put_side_set, error = %d\n", error); |
| 799 |
|
| 800 |
if (error) { |
| 801 |
ex_close(exoid); |
| 802 |
exit(-1); |
| 803 |
} |
| 804 |
|
| 805 |
error = ex_put_set_dist_fact(exoid, EX_SIDE_SET, 30, dist_fact); |
| 806 |
printf("after ex_put_side_set_dist_fact, error = %d\n", error); |
| 807 |
|
| 808 |
if (error) { |
| 809 |
ex_close(exoid); |
| 810 |
exit(-1); |
| 811 |
} |
| 812 |
|
| 813 |
/* side set #2 - quad, spanning 2 elements */ |
| 814 |
|
| 815 |
error = ex_put_set_param(exoid, EX_SIDE_SET, 31, 2, 4); |
| 816 |
printf("after ex_put_side_set_param, error = %d\n", error); |
| 817 |
|
| 818 |
if (error) { |
| 819 |
ex_close(exoid); |
| 820 |
exit(-1); |
| 821 |
} |
| 822 |
|
| 823 |
elem_list[0] = 1; |
| 824 |
elem_list[1] = 2; |
| 825 |
|
| 826 |
side_list[0] = 2; |
| 827 |
side_list[1] = 3; |
| 828 |
|
| 829 |
dist_fact[0] = 31.0; |
| 830 |
dist_fact[1] = 31.1; |
| 831 |
dist_fact[2] = 31.2; |
| 832 |
dist_fact[3] = 31.3; |
| 833 |
|
| 834 |
error = ex_put_set(exoid, EX_SIDE_SET, 31, elem_list, side_list); |
| 835 |
printf("after ex_put_side_set, error = %d\n", error); |
| 836 |
|
| 837 |
if (error) { |
| 838 |
ex_close(exoid); |
| 839 |
exit(-1); |
| 840 |
} |
| 841 |
|
| 842 |
error = ex_put_set_dist_fact(exoid, EX_SIDE_SET, 31, dist_fact); |
| 843 |
printf("after ex_put_side_set_dist_fact, error = %d\n", error); |
| 844 |
|
| 845 |
if (error) { |
| 846 |
ex_close(exoid); |
| 847 |
exit(-1); |
| 848 |
} |
| 849 |
|
| 850 |
/* side set #3 - hex */ |
| 851 |
|
| 852 |
error = ex_put_set_param(exoid, EX_SIDE_SET, 32, 7, 0); |
| 853 |
printf("after ex_put_side_set_param, error = %d\n", error); |
| 854 |
|
| 855 |
if (error) { |
| 856 |
ex_close(exoid); |
| 857 |
exit(-1); |
| 858 |
} |
| 859 |
|
| 860 |
elem_list[0] = 3; |
| 861 |
elem_list[1] = 3; |
| 862 |
elem_list[2] = 3; |
| 863 |
elem_list[3] = 3; |
| 864 |
elem_list[4] = 3; |
| 865 |
elem_list[5] = 3; |
| 866 |
elem_list[6] = 3; |
| 867 |
|
| 868 |
side_list[0] = 5; |
| 869 |
side_list[1] = 3; |
| 870 |
side_list[2] = 3; |
| 871 |
side_list[3] = 2; |
| 872 |
side_list[4] = 4; |
| 873 |
side_list[5] = 1; |
| 874 |
side_list[6] = 6; |
| 875 |
|
| 876 |
error = ex_put_set(exoid, EX_SIDE_SET, 32, elem_list, side_list); |
| 877 |
printf("after ex_put_side_set, error = %d\n", error); |
| 878 |
|
| 879 |
if (error) { |
| 880 |
ex_close(exoid); |
| 881 |
exit(-1); |
| 882 |
} |
| 883 |
|
| 884 |
/* side set #4 - tetras */ |
| 885 |
|
| 886 |
error = ex_put_set_param(exoid, EX_SIDE_SET, 33, 8, 0); |
| 887 |
printf("after ex_put_side_set_param, error = %d\n", error); |
| 888 |
|
| 889 |
if (error) { |
| 890 |
ex_close(exoid); |
| 891 |
exit(-1); |
| 892 |
} |
| 893 |
|
| 894 |
elem_list[0] = 4; |
| 895 |
elem_list[1] = 4; |
| 896 |
elem_list[2] = 4; |
| 897 |
elem_list[3] = 4; |
| 898 |
elem_list[4] = 6; |
| 899 |
elem_list[5] = 6; |
| 900 |
elem_list[6] = 6; |
| 901 |
elem_list[7] = 6; |
| 902 |
|
| 903 |
side_list[0] = 1; |
| 904 |
side_list[1] = 2; |
| 905 |
side_list[2] = 3; |
| 906 |
side_list[3] = 4; |
| 907 |
side_list[4] = 1; |
| 908 |
side_list[5] = 2; |
| 909 |
side_list[6] = 3; |
| 910 |
side_list[7] = 4; |
| 911 |
|
| 912 |
error = ex_put_set(exoid, EX_SIDE_SET, 33, elem_list, side_list); |
| 913 |
printf("after ex_put_side_set, error = %d\n", error); |
| 914 |
|
| 915 |
if (error) { |
| 916 |
ex_close(exoid); |
| 917 |
exit(-1); |
| 918 |
} |
| 919 |
|
| 920 |
/* side set #5 - wedges and tris */ |
| 921 |
|
| 922 |
error = ex_put_set_param(exoid, EX_SIDE_SET, 34, 10, 0); |
| 923 |
printf("after ex_put_side_set_param, error = %d\n", error); |
| 924 |
|
| 925 |
if (error) { |
| 926 |
ex_close(exoid); |
| 927 |
exit(-1); |
| 928 |
} |
| 929 |
|
| 930 |
elem_list[0] = 5; |
| 931 |
elem_list[1] = 5; |
| 932 |
elem_list[2] = 5; |
| 933 |
elem_list[3] = 5; |
| 934 |
elem_list[4] = 5; |
| 935 |
elem_list[5] = 7; |
| 936 |
elem_list[6] = 7; |
| 937 |
elem_list[7] = 7; |
| 938 |
elem_list[8] = 7; |
| 939 |
elem_list[9] = 7; |
| 940 |
|
| 941 |
side_list[0] = 1; |
| 942 |
side_list[1] = 2; |
| 943 |
side_list[2] = 3; |
| 944 |
side_list[3] = 4; |
| 945 |
side_list[4] = 5; |
| 946 |
side_list[5] = 1; |
| 947 |
side_list[6] = 2; |
| 948 |
side_list[7] = 3; |
| 949 |
side_list[8] = 4; |
| 950 |
side_list[9] = 5; |
| 951 |
|
| 952 |
error = ex_put_set(exoid, EX_SIDE_SET, 34, elem_list, side_list); |
| 953 |
printf("after ex_put_side_set, error = %d\n", error); |
| 954 |
|
| 955 |
if (error) { |
| 956 |
ex_close(exoid); |
| 957 |
exit(-1); |
| 958 |
} |
| 959 |
|
| 960 |
/* Write side set names */ |
| 961 |
sset_names[0] = "sset_1"; |
| 962 |
sset_names[1] = "sset_2"; |
| 963 |
sset_names[2] = "sset_3"; |
| 964 |
sset_names[3] = "sset_4"; |
| 965 |
sset_names[4] = "sset_5"; |
| 966 |
|
| 967 |
error = ex_put_names(exoid, EX_SIDE_SET, sset_names); |
| 968 |
printf("after ex_put_names, error = %d\n", error); |
| 969 |
|
| 970 |
if (error) { |
| 971 |
ex_close(exoid); |
| 972 |
exit(-1); |
| 973 |
} |
| 974 |
|
| 975 |
error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100); |
| 976 |
printf("after ex_put_prop, error = %d\n", error); |
| 977 |
|
| 978 |
if (error) { |
| 979 |
ex_close(exoid); |
| 980 |
exit(-1); |
| 981 |
} |
| 982 |
|
| 983 |
error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101); |
| 984 |
printf("after ex_put_prop, error = %d\n", error); |
| 985 |
|
| 986 |
if (error) { |
| 987 |
ex_close(exoid); |
| 988 |
exit(-1); |
| 989 |
} |
| 990 |
|
| 991 |
/* write QA records; test empty and just blank-filled records */ |
| 992 |
|
| 993 |
num_qa_rec = 2; |
| 994 |
|
| 995 |
qa_record[0][0] = "TESTWT"; |
| 996 |
qa_record[0][1] = "testwt"; |
| 997 |
qa_record[0][2] = "07/07/93"; |
| 998 |
qa_record[0][3] = "15:41:33"; |
| 999 |
qa_record[1][0] = "Thirty-Two character QA Record|"; |
| 1000 |
qa_record[1][1] = " "; |
| 1001 |
qa_record[1][2] = ""; |
| 1002 |
qa_record[1][3] = " "; |
| 1003 |
|
| 1004 |
error = ex_put_qa(exoid, num_qa_rec, qa_record); |
| 1005 |
printf("after ex_put_qa, error = %d\n", error); |
| 1006 |
|
| 1007 |
if (error) { |
| 1008 |
ex_close(exoid); |
| 1009 |
exit(-1); |
| 1010 |
} |
| 1011 |
|
| 1012 |
/* write information records; test empty and just blank-filled records */ |
| 1013 |
|
| 1014 |
num_info = 3; |
| 1015 |
|
| 1016 |
info[0] = "This is the first information record."; |
| 1017 |
info[1] = ""; |
| 1018 |
info[2] = "This info record is exactly 80 characters long. last character should be pipe |"; |
| 1019 |
|
| 1020 |
error = ex_put_info(exoid, num_info, info); |
| 1021 |
printf("after ex_put_info, error = %d\n", error); |
| 1022 |
|
| 1023 |
if (error) { |
| 1024 |
ex_close(exoid); |
| 1025 |
exit(-1); |
| 1026 |
} |
| 1027 |
|
| 1028 |
/* write results variables parameters and names */ |
| 1029 |
|
| 1030 |
num_glo_vars = 1; |
| 1031 |
|
| 1032 |
var_names[0] = "glo_vars"; |
| 1033 |
|
| 1034 |
error = ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars); |
| 1035 |
printf("after ex_put_variable_param, error = %d\n", error); |
| 1036 |
if (error) { |
| 1037 |
ex_close(exoid); |
| 1038 |
exit(-1); |
| 1039 |
} |
| 1040 |
|
| 1041 |
error = ex_put_variable_names(exoid, EX_GLOBAL, num_glo_vars, var_names); |
| 1042 |
printf("after ex_put_variable_names, error = %d\n", error); |
| 1043 |
if (error) { |
| 1044 |
ex_close(exoid); |
| 1045 |
exit(-1); |
| 1046 |
} |
| 1047 |
|
| 1048 |
num_nod_vars = 2; |
| 1049 |
/* 12345678901234567890123456789012 */ |
| 1050 |
var_names[0] = "node_variable_a_very_long_name_0"; |
| 1051 |
var_names[1] = "nod_var1"; |
| 1052 |
|
| 1053 |
error = ex_put_variable_param(exoid, EX_NODAL, num_nod_vars); |
| 1054 |
printf("after ex_put_variable_param, error = %d\n", error); |
| 1055 |
if (error) { |
| 1056 |
ex_close(exoid); |
| 1057 |
exit(-1); |
| 1058 |
} |
| 1059 |
|
| 1060 |
error = ex_put_variable_names(exoid, EX_NODAL, num_nod_vars, var_names); |
| 1061 |
printf("after ex_put_variable_names, error = %d\n", error); |
| 1062 |
if (error) { |
| 1063 |
ex_close(exoid); |
| 1064 |
exit(-1); |
| 1065 |
} |
| 1066 |
|
| 1067 |
num_ele_vars = 3; |
| 1068 |
|
| 1069 |
/* 0 1 2 3 */ |
| 1070 |
/* 12345678901234567890123456789012 */ |
| 1071 |
var_names[0] = "this_variable_name_is_short"; |
| 1072 |
var_names[1] = "this_variable_name_is_just_right"; |
| 1073 |
var_names[2] = "this_variable_name_is_tooooo_long"; |
| 1074 |
|
| 1075 |
error = ex_put_variable_param(exoid, EX_ELEM_BLOCK, num_ele_vars); |
| 1076 |
printf("after ex_put_variable_param, error = %d\n", error); |
| 1077 |
if (error) { |
| 1078 |
ex_close(exoid); |
| 1079 |
exit(-1); |
| 1080 |
} |
| 1081 |
|
| 1082 |
error = ex_put_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, var_names); |
| 1083 |
printf("after ex_put_variable_names, error = %d\n", error); |
| 1084 |
if (error) { |
| 1085 |
ex_close(exoid); |
| 1086 |
exit(-1); |
| 1087 |
} |
| 1088 |
|
| 1089 |
{ |
| 1090 |
num_nset_vars = 3; |
| 1091 |
|
| 1092 |
var_names[0] = "ns_var0"; |
| 1093 |
var_names[1] = "ns_var1"; |
| 1094 |
var_names[2] = "ns_var2"; |
| 1095 |
|
| 1096 |
error = ex_put_variable_param(exoid, EX_NODE_SET, num_nset_vars); |
| 1097 |
printf("after ex_put_variable_param, error = %d\n", error); |
| 1098 |
if (error) { |
| 1099 |
ex_close(exoid); |
| 1100 |
exit(-1); |
| 1101 |
} |
| 1102 |
|
| 1103 |
error = ex_put_variable_names(exoid, EX_NODE_SET, num_nset_vars, var_names); |
| 1104 |
printf("after ex_put_variable_names, error = %d\n", error); |
| 1105 |
if (error) { |
| 1106 |
ex_close(exoid); |
| 1107 |
exit(-1); |
| 1108 |
} |
| 1109 |
} |
| 1110 |
|
| 1111 |
{ |
| 1112 |
num_sset_vars = 3; |
| 1113 |
|
| 1114 |
var_names[0] = "ss_var0"; |
| 1115 |
var_names[1] = "ss_var1"; |
| 1116 |
var_names[2] = "ss_var2"; |
| 1117 |
|
| 1118 |
error = ex_put_variable_param(exoid, EX_SIDE_SET, num_sset_vars); |
| 1119 |
printf("after ex_put_variable_param, error = %d\n", error); |
| 1120 |
if (error) { |
| 1121 |
ex_close(exoid); |
| 1122 |
exit(-1); |
| 1123 |
} |
| 1124 |
|
| 1125 |
error = ex_put_variable_names(exoid, EX_SIDE_SET, num_sset_vars, var_names); |
| 1126 |
printf("after ex_put_variable_names, error = %d\n", error); |
| 1127 |
if (error) { |
| 1128 |
ex_close(exoid); |
| 1129 |
exit(-1); |
| 1130 |
} |
| 1131 |
} |
| 1132 |
|
| 1133 |
/* write element variable truth table */ |
| 1134 |
|
| 1135 |
truth_tab = (int *)calloc((num_elem_blk * num_ele_vars), sizeof(int)); |
| 1136 |
|
| 1137 |
k = 0; |
| 1138 |
for (i = 0; i < num_elem_blk; i++) { |
| 1139 |
for (j = 0; j < num_ele_vars; j++) { |
| 1140 |
truth_tab[k++] = 1; |
| 1141 |
} |
| 1142 |
} |
| 1143 |
|
| 1144 |
error = ex_put_truth_table(exoid, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab); |
| 1145 |
printf("after ex_put_elem_var_tab, error = %d\n", error); |
| 1146 |
|
| 1147 |
if (error) { |
| 1148 |
ex_close(exoid); |
| 1149 |
exit(-1); |
| 1150 |
} |
| 1151 |
|
| 1152 |
free(truth_tab); |
| 1153 |
|
| 1154 |
/* for each time step, write the analysis results; |
| 1155 |
* the code below fills the arrays glob_var_vals, |
| 1156 |
* nodal_var_vals, and elem_var_vals with values for debugging purposes; |
| 1157 |
* obviously the analysis code will populate these arrays |
| 1158 |
*/ |
| 1159 |
|
| 1160 |
whole_time_step = 1; |
| 1161 |
num_time_steps = 10; |
| 1162 |
|
| 1163 |
glob_var_vals = (float *)calloc(num_glo_vars, CPU_word_size); |
| 1164 |
nodal_var_vals = (float *)calloc(num_nodes, CPU_word_size); |
| 1165 |
elem_var_vals = (float *)calloc(4, CPU_word_size); |
| 1166 |
sset_var_vals = (float *)calloc(10, CPU_word_size); |
| 1167 |
nset_var_vals = (float *)calloc(10, CPU_word_size); |
| 1168 |
|
| 1169 |
for (i = 0; i < num_time_steps; i++) { |
| 1170 |
time_value = (float)(i + 1) / 100.; |
| 1171 |
|
| 1172 |
/* write time value */ |
| 1173 |
|
| 1174 |
error = ex_put_time(exoid, whole_time_step, &time_value); |
| 1175 |
printf("after ex_put_time, error = %d\n", error); |
| 1176 |
|
| 1177 |
if (error) { |
| 1178 |
ex_close(exoid); |
| 1179 |
exit(-1); |
| 1180 |
} |
| 1181 |
|
| 1182 |
/* write global variables */ |
| 1183 |
|
| 1184 |
for (j = 0; j < num_glo_vars; j++) { |
| 1185 |
glob_var_vals[j] = (float)(j + 2) * time_value; |
| 1186 |
} |
| 1187 |
|
| 1188 |
error = ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals); |
| 1189 |
printf("after ex_put_glob_vars, error = %d\n", error); |
| 1190 |
|
| 1191 |
if (error) { |
| 1192 |
ex_close(exoid); |
| 1193 |
exit(-1); |
| 1194 |
} |
| 1195 |
|
| 1196 |
/* write nodal variables */ |
| 1197 |
|
| 1198 |
for (k = 1; k <= num_nod_vars; k++) { |
| 1199 |
for (j = 0; j < num_nodes; j++) { |
| 1200 |
nodal_var_vals[j] = (float)k + ((float)(j + 1) * time_value); |
| 1201 |
} |
| 1202 |
|
| 1203 |
error = ex_put_var(exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals); |
| 1204 |
printf("after ex_put_nodal_var, error = %d\n", error); |
| 1205 |
if (error) { |
| 1206 |
ex_close(exoid); |
| 1207 |
exit(-1); |
| 1208 |
} |
| 1209 |
} |
| 1210 |
|
| 1211 |
/* write element variables */ |
| 1212 |
|
| 1213 |
for (k = 1; k <= num_ele_vars; k++) { |
| 1214 |
for (j = 0; j < num_elem_blk; j++) { |
| 1215 |
for (m = 0; m < num_elem_in_block[j]; m++) { |
| 1216 |
elem_var_vals[m] = (float)(k + 1) + (float)(j + 2) + ((float)(m + 1) * time_value); |
| 1217 |
/* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */ |
| 1218 |
} |
| 1219 |
error = ex_put_var(exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j], num_elem_in_block[j], |
| 1220 |
elem_var_vals); |
| 1221 |
printf("after ex_put_elem_var, error = %d\n", error); |
| 1222 |
if (error) { |
| 1223 |
ex_close(exoid); |
| 1224 |
exit(-1); |
| 1225 |
} |
| 1226 |
} |
| 1227 |
} |
| 1228 |
|
| 1229 |
/* write sideset variables */ |
| 1230 |
|
| 1231 |
for (k = 1; k <= num_sset_vars; k++) { |
| 1232 |
for (j = 0; j < num_side_sets; j++) { |
| 1233 |
for (m = 0; m < num_face_in_sset[j]; m++) { |
| 1234 |
sset_var_vals[m] = (float)(k + 2) + (float)(j + 3) + ((float)(m + 1) * time_value); |
| 1235 |
/* printf("sset_var_vals[%d]: %f\n",m,sset_var_vals[m]); */ |
| 1236 |
} |
| 1237 |
error = ex_put_var(exoid, whole_time_step, EX_SIDE_SET, k, ssids[j], num_face_in_sset[j], |
| 1238 |
sset_var_vals); |
| 1239 |
printf("after ex_put_sset_var, error = %d\n", error); |
| 1240 |
if (error) { |
| 1241 |
ex_close(exoid); |
| 1242 |
exit(-1); |
| 1243 |
} |
| 1244 |
} |
| 1245 |
} |
| 1246 |
|
| 1247 |
/* write nodeset variables */ |
| 1248 |
|
| 1249 |
for (k = 1; k <= num_nset_vars; k++) { |
| 1250 |
for (j = 0; j < num_node_sets; j++) { |
| 1251 |
for (m = 0; m < num_nodes_in_nset[j]; m++) { |
| 1252 |
nset_var_vals[m] = (float)(k + 3) + (float)(j + 4) + ((float)(m + 1) * time_value); |
| 1253 |
/* printf("nset_var_vals[%d]: %f\n",m,nset_var_vals[m]); */ |
| 1254 |
} |
| 1255 |
error = ex_put_var(exoid, whole_time_step, EX_NODE_SET, k, nsids[j], num_nodes_in_nset[j], |
| 1256 |
nset_var_vals); |
| 1257 |
printf("after ex_put_nset_var, error = %d\n", error); |
| 1258 |
if (error) { |
| 1259 |
ex_close(exoid); |
| 1260 |
exit(-1); |
| 1261 |
} |
| 1262 |
} |
| 1263 |
} |
| 1264 |
|
| 1265 |
whole_time_step++; |
| 1266 |
|
| 1267 |
/* update the data file; this should be done at the end of every time step |
| 1268 |
* to ensure that no data is lost if the analysis dies |
| 1269 |
*/ |
| 1270 |
error = ex_update(exoid); |
| 1271 |
printf("after ex_update, error = %d\n", error); |
| 1272 |
if (error) { |
| 1273 |
ex_close(exoid); |
| 1274 |
exit(-1); |
| 1275 |
} |
| 1276 |
} |
| 1277 |
free(glob_var_vals); |
| 1278 |
free(nodal_var_vals); |
| 1279 |
free(elem_var_vals); |
| 1280 |
free(sset_var_vals); |
| 1281 |
free(nset_var_vals); |
| 1282 |
|
| 1283 |
/* close the EXODUS files |
| 1284 |
*/ |
| 1285 |
error = ex_close(exoid); |
| 1286 |
printf("after ex_close, error = %d\n", error); |
| 1287 |
if (error) { |
| 1288 |
ex_close(exoid); |
| 1289 |
exit(-1); |
| 1290 |
} |
| 1291 |
return 0; |
| 1292 |
} |