/contrib/exodusii/5.22b/exodus/cbind/test/testrdwt.c
C | 455 lines | 270 code | 107 blank | 78 comment | 28 complexity | 3a43af111aca7198ca463da61d665be6 MD5 | raw file
1/* 2 * Copyright (c) 2005 Sandia Corporation. Under the terms of Contract 3 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Governement 4 * retains certain rights in this software. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above 14 * copyright notice, this list of conditions and the following 15 * disclaimer in the documentation and/or other materials provided 16 * with the distribution. 17 * 18 * * Neither the name of Sandia Corporation nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 */ 35/***************************************************************************** 36* 37* testrdwt - test reading from one ExodusII file and writing to another 38* ExodusII file open concurrently 39* 40* author - Sandia National Laboratories 41* Larry A. Schoof - Original 42* 43* environment - UNIX 44* 45* entry conditions - 46* 47* exit conditions - 48* 49* revision history - 50* 51* This is a test program for the C binding of the EXODUS II 52* database read and write routines. It tests reading from an open EXODUSII 53* file and writing to another concurrently opened EXODUSII file. 54* 55* 56*****************************************************************************/ 57 58 59#include <stdlib.h> 60#include <stdio.h> 61#include "exodusII.h" 62#include "netcdf.h" 63int main (int argc, char **argv) 64{ 65 int exoid, exoid2, num_dim, num_nodes, num_elem, num_elem_blk; 66 int num_elem_in_block, num_node_sets, num_nodes_per_elem, num_attr; 67 int num_side_sets, error; 68 int i, j; 69 int *elem_map, *connect, *node_list, *node_ctr_list, *elem_list, *side_list; 70 int *ids; 71 int num_nodes_in_set, num_elem_in_set; 72 int num_sides_in_set, num_df_in_set; 73 int num_qa_rec, num_info; 74 int CPU_word_size,IO_word_size; 75 int num_props, prop_value, *prop_values; 76 77 float *x, *y, *z; 78 float *dist_fact; 79 float version, fdum; 80 81 char *coord_names[3], *qa_record[2][4], *info[3]; 82 char title[MAX_LINE_LENGTH+1], elem_type[MAX_STR_LENGTH+1]; 83 char *prop_names[3]; 84 char *cdum = 0; 85 86/* Specify compute and i/o word size */ 87 88 CPU_word_size = 0; /* sizeof(float) */ 89 IO_word_size = 4; /* float */ 90 91/* open EXODUS II file for reading */ 92 93 ex_opts (EX_VERBOSE | EX_ABORT); 94 95 exoid = ex_open ("test.exo", /* filename path */ 96 EX_READ, /* access mode */ 97 &CPU_word_size, /* CPU float word size in bytes */ 98 &IO_word_size, /* I/O float word size in bytes */ 99 &version); /* returned version number */ 100 printf ("after ex_open for test.exo\n"); 101 printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size); 102 103/* create EXODUS II file for writing */ 104 105 exoid2= ex_create ("test2.exo", /* filename path */ 106 EX_CLOBBER, /* create mode */ 107 &CPU_word_size, /* CPU float word size in bytes */ 108 &IO_word_size); /* I/O float word size in bytes */ 109 printf ("after ex_create for test2.exo, exoid = %d\n", exoid2); 110 111 /* ncopts = NC_VERBOSE; */ 112 113/* read initialization parameters */ 114 115 error = ex_get_init (exoid, title, &num_dim, &num_nodes, &num_elem, 116 &num_elem_blk, &num_node_sets, &num_side_sets); 117 118 printf ("after ex_get_init, error = %d\n", error); 119 120/* write initialization parameters */ 121 122 error = ex_put_init (exoid2, title, num_dim, num_nodes, num_elem, 123 num_elem_blk, num_node_sets, num_side_sets); 124 125 printf ("after ex_put_init, error = %d\n", error); 126 127/* read nodal coordinate values */ 128 129 x = (float *) calloc(num_nodes, sizeof(float)); 130 y = (float *) calloc(num_nodes, sizeof(float)); 131 if (num_dim >= 3) 132 z = (float *) calloc(num_nodes, sizeof(float)); 133 else 134 z = 0; 135 136 error = ex_get_coord (exoid, x, y, z); 137 printf ("\nafter ex_get_coord, error = %3d\n", error); 138 139/* write nodal coordinate values */ 140 141 error = ex_put_coord (exoid2, x, y, z); 142 printf ("after ex_put_coord, error = %d\n", error); 143 144 free (x); 145 free (y); 146 if (num_dim >= 3) 147 free (z); 148 149/* read nodal coordinate names */ 150 151 for (i=0; i<num_dim; i++) 152 { 153 coord_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char)); 154 } 155 156 error = ex_get_coord_names (exoid, coord_names); 157 printf ("\nafter ex_get_coord_names, error = %3d\n", error); 158 159/* write nodal coordinate names */ 160 161 error = ex_put_coord_names (exoid2, coord_names); 162 printf ("after ex_put_coord_names, error = %d\n", error); 163 164 for (i=0; i<num_dim; i++) { 165 free(coord_names[i]); 166 } 167 168/* read element order map */ 169 170 elem_map = (int *) calloc(num_elem, sizeof(int)); 171 172 error = ex_get_map (exoid, elem_map); 173 printf ("\nafter ex_get_map, error = %3d\n", error); 174 175/* write element order map */ 176 177 error = ex_put_map (exoid2, elem_map); 178 printf ("after ex_put_map, error = %d\n", error); 179 180 free (elem_map); 181 182/* read and write element block parameters and element connectivity */ 183 184 ids = (int *) calloc(num_elem_blk, sizeof(int)); 185 error = ex_get_elem_blk_ids (exoid, ids); 186 printf ("\nafter ex_get_elem_blk_ids, error = %3d\n", error); 187 188 for (i=0; i<num_elem_blk; i++) 189 { 190 error = ex_get_elem_block (exoid, ids[i], elem_type, 191 &num_elem_in_block, 192 &num_nodes_per_elem, &num_attr); 193 printf ("\nafter ex_get_elem_block, error = %d\n", error); 194 195 error = ex_put_elem_block (exoid2, ids[i], elem_type, num_elem_in_block, 196 num_nodes_per_elem, num_attr); 197 printf ("after ex_put_elem_block, error = %d\n", error); 198 199 connect = (int *) calloc((num_nodes_per_elem * num_elem_in_block), 200 sizeof(int)); 201 202 error = ex_get_elem_conn (exoid, ids[i], connect); 203 printf ("\nafter ex_get_elem_conn, error = %d\n", error); 204 205 error = ex_put_elem_conn (exoid2, ids[i], connect); 206 printf ("after ex_put_elem_conn, error = %d\n", error); 207 208 free (connect); 209 } 210 211/* read and write element block properties */ 212 213 error = ex_inquire (exoid, EX_INQ_EB_PROP, &num_props, &fdum, cdum); 214 printf ("\nafter ex_inquire, error = %d\n", error); 215 216 for (i=0; i<num_props; i++) 217 { 218 prop_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char)); 219 } 220 221 error = ex_get_prop_names(exoid,EX_ELEM_BLOCK,prop_names); 222 printf ("after ex_get_prop_names, error = %d\n", error); 223 224 error = ex_put_prop_names(exoid2,EX_ELEM_BLOCK,num_props,prop_names); 225 printf ("after ex_put_prop_names, error = %d\n", error); 226 227 for (i=0; i<num_props; i++) 228 { 229 for (j=0; j<num_elem_blk; j++) 230 { 231 error = ex_get_prop(exoid, EX_ELEM_BLOCK, ids[j], prop_names[i], 232 &prop_value); 233 printf ("after ex_get_prop, error = %d\n", error); 234 235 if (i>0) { /* first property is the ID which is already stored */ 236 error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ids[j], prop_names[i], 237 prop_value); 238 printf ("after ex_put_prop, error = %d\n", error); 239 } 240 } 241 } 242 243 for (i=0; i<num_props; i++) 244 free(prop_names[i]); 245 246 247 free (ids); 248 249/* read and write individual node sets */ 250 251 ids = (int *) calloc(num_node_sets, sizeof(int)); 252 253 error = ex_get_node_set_ids (exoid, ids); 254 printf ("\nafter ex_get_node_set_ids, error = %3d\n", error); 255 256 for (i=0; i<num_node_sets; i++) 257 { 258 error = ex_get_node_set_param (exoid, ids[i], 259 &num_nodes_in_set, &num_df_in_set); 260 printf ("\nafter ex_get_node_set_param, error = %3d\n", error); 261 262 error = ex_put_node_set_param (exoid2, ids[i], num_nodes_in_set, 263 num_df_in_set); 264 printf ("after ex_put_node_set_param, error = %d\n", error); 265 266 node_list = (int *) calloc(num_nodes_in_set, sizeof(int)); 267 dist_fact = (float *) calloc(num_nodes_in_set, sizeof(float)); 268 269 error = ex_get_node_set (exoid, ids[i], node_list); 270 printf ("\nafter ex_get_node_set, error = %3d\n", error); 271 272 error = ex_put_node_set (exoid2, ids[i], node_list); 273 printf ("after ex_put_node_set, error = %d\n", error); 274 275 if (num_df_in_set > 0) 276 { 277 error = ex_get_node_set_dist_fact (exoid, ids[i], dist_fact); 278 printf ("\nafter ex_get_node_set_dist_fact, error = %3d\n", error); 279 280 error = ex_put_node_set_dist_fact (exoid2, ids[i], dist_fact); 281 printf ("after ex_put_node_set, error = %d\n", error); 282 283 } 284 285 free (node_list); 286 free (dist_fact); 287 } 288 free(ids); 289 290 /* read node set properties */ 291 error = ex_inquire (exoid, EX_INQ_NS_PROP, &num_props, &fdum, cdum); 292 printf ("\nafter ex_inquire, error = %d\n", error); 293 294 for (i=0; i<num_props; i++) 295 { 296 prop_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char)); 297 } 298 prop_values = (int *) calloc (num_node_sets, sizeof(int)); 299 300 error = ex_get_prop_names(exoid,EX_NODE_SET,prop_names); 301 printf ("after ex_get_prop_names, error = %d\n", error); 302 303 error = ex_put_prop_names(exoid2,EX_NODE_SET,num_props,prop_names); 304 printf ("after ex_put_prop_names, error = %d\n", error); 305 306 for (i=0; i<num_props; i++) 307 { 308 error = ex_get_prop_array(exoid, EX_NODE_SET, prop_names[i], 309 prop_values); 310 printf ("after ex_get_prop_array, error = %d\n", error); 311 312 error = ex_put_prop_array(exoid2, EX_NODE_SET, prop_names[i], prop_values); 313 printf ("after ex_put_prop_array, error = %d\n", error); 314 315 } 316 for (i=0; i<num_props; i++) 317 free(prop_names[i]); 318 free(prop_values); 319 320/* read and write individual side sets */ 321 322 ids = (int *) calloc(num_side_sets, sizeof(int)); 323 324 error = ex_get_side_set_ids (exoid, ids); 325 printf ("\nafter ex_get_side_set_ids, error = %3d\n", error); 326 327 for (i=0; i<num_side_sets; i++) 328 { 329 error = ex_get_side_set_param (exoid, ids[i], &num_sides_in_set, 330 &num_df_in_set); 331 printf ("\nafter ex_get_side_set_param, error = %3d\n", error); 332 333 error = ex_put_side_set_param (exoid2, ids[i], num_sides_in_set, 334 num_df_in_set); 335 printf ("after ex_put_side_set_param, error = %d\n", error); 336 337 /* Note: The # of elements is same as # of sides! */ 338 num_elem_in_set = num_sides_in_set; 339 elem_list = (int *) calloc(num_elem_in_set, sizeof(int)); 340 side_list = (int *) calloc(num_sides_in_set, sizeof(int)); 341 node_ctr_list = (int *) calloc(num_elem_in_set, sizeof(int)); 342 node_list = (int *) calloc(num_elem_in_set*21, sizeof(int)); 343 dist_fact = (float *) calloc(num_df_in_set, sizeof(float)); 344 345 error = ex_get_side_set (exoid, ids[i], elem_list, side_list); 346 printf ("\nafter ex_get_side_set, error = %3d\n", error); 347 348 error = ex_put_side_set (exoid2, ids[i], elem_list, side_list); 349 printf ("after ex_put_side_set, error = %d\n", error); 350 351 error = ex_get_side_set_node_list (exoid, ids[i], node_ctr_list, 352 node_list); 353 printf ("\nafter ex_get_side_set_node_list, error = %3d\n", error); 354 355 if (num_df_in_set > 0) 356 { 357 error = ex_get_side_set_dist_fact (exoid, ids[i], dist_fact); 358 printf ("\nafter ex_get_side_set_dist_fact, error = %3d\n", error); 359 360 error = ex_put_side_set_dist_fact (exoid2, ids[i], dist_fact); 361 printf ("after ex_put_side_set_dist_fact, error = %d\n", error); 362 363 } 364 365 free (elem_list); 366 free (side_list); 367 free (node_ctr_list); 368 free (node_list); 369 free (dist_fact); 370 371 } 372 373 374 /* read side set properties */ 375 error = ex_inquire (exoid, EX_INQ_SS_PROP, &num_props, &fdum, cdum); 376 printf ("\nafter ex_inquire, error = %d\n", error); 377 378 for (i=0; i<num_props; i++) 379 { 380 prop_names[i] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char)); 381 } 382 383 error = ex_get_prop_names(exoid,EX_SIDE_SET,prop_names); 384 printf ("after ex_get_prop_names, error = %d\n", error); 385 386 387 for (i=0; i<num_props; i++) 388 { 389 for (j=0; j<num_side_sets; j++) 390 { 391 error = ex_get_prop(exoid, EX_SIDE_SET, ids[j], prop_names[i], 392 &prop_value); 393 printf ("after ex_get_prop, error = %d\n", error); 394 395 if (i>0) { /* first property is ID so it is already stored */ 396 error = ex_put_prop(exoid2, EX_SIDE_SET, ids[j], prop_names[i], 397 prop_value); 398 printf ("after ex_put_prop, error = %d\n", error); 399 } 400 } 401 } 402 for (i=0; i<num_props; i++) 403 free(prop_names[i]); 404 free (ids); 405 406/* read and write QA records */ 407 408 ex_inquire (exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum); 409 410 for (i=0; i<num_qa_rec; i++) { 411 for (j=0; j<4; j++) { 412 qa_record[i][j] = (char *) calloc ((MAX_STR_LENGTH+1), sizeof(char)); 413 } 414 } 415 416 error = ex_get_qa (exoid, qa_record); 417 printf ("\nafter ex_get_qa, error = %3d\n", error); 418 419 error = ex_put_qa (exoid2, num_qa_rec, qa_record); 420 printf ("after ex_put_qa, error = %d\n", error); 421 422 for (i=0; i<num_qa_rec; i++) { 423 for (j=0; j<4; j++) { 424 free(qa_record[i][j]); 425 } 426 } 427/* read and write information records */ 428 429 error = ex_inquire (exoid, EX_INQ_INFO, &num_info, &fdum, cdum); 430 printf ("\nafter ex_inquire, error = %3d\n", error); 431 432 for (i=0; i<num_info; i++) 433 { 434 info[i] = (char *) calloc ((MAX_LINE_LENGTH+1), sizeof(char)); 435 } 436 437 error = ex_get_info (exoid, info); 438 printf ("\nafter ex_get_info, error = %3d\n", error); 439 440 error = ex_put_info (exoid2, num_info, info); 441 printf ("after ex_put_info, error = %d\n", error); 442 443 for (i=0; i<num_info; i++) 444 { 445 free(info[i]); 446 } 447 448/* close the EXODUS files */ 449 450 error = ex_close (exoid); 451 printf ("after ex_close, error = %d\n", error); 452 error = ex_close (exoid2); 453 printf ("after ex_close (2), error = %d\n", error); 454 return 0; 455}