/* * Copyright (c) 2005 Sandia Corporation. Under the terms of Contract * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Governement * retains certain rights in this software. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * * Neither the name of Sandia Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ /***************************************************************************** * * testrd - read exodus file test.exo created by testwt * * author - Sandia National Laboratories * Larry A. Schoof - Original * * * environment - UNIX * * entry conditions - * input parameters: * int exoid exodus file id * * exit conditions - * * revision history - * * *****************************************************************************/ #include #include #include #include "netcdf.h" #include "exodusII.h" /* #include "drmd.h" */ int main (int argc, char **argv) { int exoid, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets; int num_side_sets, error; int i, j, k, node_ctr; int *elem_map, *connect, *node_list, *node_ctr_list, *elem_list, *side_list; int *ids; int *num_nodes_per_set = NULL; int *num_elem_per_set = NULL; int *num_df_per_set = NULL; int *node_ind = NULL; int *elem_ind = NULL; int *df_ind = NULL; int num_qa_rec, num_info; int num_glo_vars, num_nod_vars, num_ele_vars; int num_nset_vars, num_sset_vars; int *truth_tab; int num_time_steps; int *num_elem_in_block = NULL; int *num_nodes_per_elem = NULL; int *num_attr = NULL; int num_nodes_in_set, num_elem_in_set; int num_sides_in_set, num_df_in_set; int list_len, elem_list_len, node_list_len, df_list_len; int node_num, time_step, var_index, beg_time, end_time, elem_num; int CPU_word_size,IO_word_size; int num_props, prop_value, *prop_values; int idum; int max_name_length; float time_value, *time_values, *var_values; float *x, *y, *z; float *attrib, *dist_fact; float version, fdum; char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3]; char *block_names[10], *nset_names[10], *sset_names[10]; char *attrib_names[10]; char title[MAX_LINE_LENGTH+1], elem_type[MAX_STR_LENGTH+1]; char title_chk[MAX_LINE_LENGTH+1]; char *cdum = 0; char *prop_names[3]; char *name = NULL; CPU_word_size = 0; /* sizeof(float) */ IO_word_size = 0; /* use what is stored in file */ ex_opts (EX_VERBOSE | EX_ABORT ); /* open EXODUS II files */ exoid = ex_open ("test.exo", /* filename path */ EX_READ, /* access mode = READ */ &CPU_word_size, /* CPU word size */ &IO_word_size, /* IO word size */ &version); /* ExodusII library version */ printf ("\nafter ex_open\n"); if (exoid < 0) exit(1); printf ("test.exo is an EXODUSII file; version %4.2f\n", version); /* printf (" CPU word size %1d\n",CPU_word_size); */ printf (" I/O word size %1d\n",IO_word_size); ex_inquire(exoid,EX_INQ_API_VERS, &idum, &version, cdum); printf ("EXODUSII API; version %4.2f\n", version); ex_inquire(exoid,EX_INQ_LIB_VERS, &idum, &version, cdum); printf ("EXODUSII Library API; version %4.2f (%d)\n", version, idum); /* Query size of names used in this file */ { int max_all_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH); int max_use_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH); printf ("This file can use at most %d-character names\n", max_all_name_length); printf ("The maximum name length used is %d-character names\n", max_use_name_length); max_name_length = max_use_name_length; ex_set_max_name_length(exoid, max_name_length); } name = (char *) calloc(max_name_length+1, sizeof(char)); /* read database parameters */ error = ex_get_init (exoid, title, &num_dim, &num_nodes, &num_elem, &num_elem_blk, &num_node_sets, &num_side_sets); printf ("after ex_get_init, error = %3d\n", error); printf ("database parameters:\n"); printf ("title = '%s'\n",title); printf ("num_dim = %3d\n",num_dim); printf ("num_nodes = %3d\n",num_nodes); printf ("num_elem = %3d\n",num_elem); printf ("num_elem_blk = %3d\n",num_elem_blk); printf ("num_node_sets = %3d\n",num_node_sets); printf ("num_side_sets = %3d\n",num_side_sets); /* Check that ex_inquire gives same title */ error = ex_inquire (exoid, EX_INQ_TITLE, &idum, &fdum, title_chk); printf ("after ex_inquire, error = %3d\n", error); if (strcmp(title, title_chk) != 0) { printf ("error in ex_inquire for EX_INQ_TITLE\n"); } /* read nodal coordinates values and names from database */ x = (float *) calloc(num_nodes, sizeof(float)); y = (float *) calloc(num_nodes, sizeof(float)); if (num_dim >= 3) z = (float *) calloc(num_nodes, sizeof(float)); else z = 0; error = ex_get_coord (exoid, x, y, z); printf ("\nafter ex_get_coord, error = %3d\n", error); printf ("x coords = \n"); for (i=0; i= 3) { printf ("z coords = \n"); for (i=0; i= 3) free (z); for (i=0; i2) printf ("z coord name = '%s'\n", coord_names[2]); for (i=0; i 0) { for (j=0; j 0) { ids = (int *) calloc(num_elem_blk, sizeof(int)); num_elem_in_block = (int *) calloc(num_elem_blk, sizeof(int)); num_nodes_per_elem = (int *) calloc(num_elem_blk, sizeof(int)); num_attr = (int *) calloc(num_elem_blk, sizeof(int)); error = ex_get_elem_blk_ids (exoid, ids); printf ("\nafter ex_get_elem_blk_ids, error = %3d\n", error); for (i=0; i 0) { connect = (int *) calloc((num_nodes_per_elem[i] * num_elem_in_block[i]), sizeof(int)); error = ex_get_elem_conn (exoid, ids[i], connect); printf ("\nafter ex_get_elem_conn, error = %d\n", error); printf ("connect array for elem block %2d\n", ids[i]); for (j=0; j 0) { for (j=0; j 0) { free (ids); free (num_nodes_per_elem); free (num_attr); } /* read individual node sets */ if (num_node_sets > 0) { ids = (int *) calloc(num_node_sets, sizeof(int)); error = ex_get_node_set_ids (exoid, ids); printf ("\nafter ex_get_node_set_ids, error = %3d\n", error); for (i=0; i 0) { error = ex_get_node_set_dist_fact (exoid, ids[i], dist_fact); printf ("\nafter ex_get_node_set_dist_fact, error = %3d\n", error); } printf ("\nnode list for node set %2d\n", ids[i]); for (j=0; j 0) { printf ("dist factors for node set %2d\n", ids[i]); for (j=0; j 0) { for (j=0; j 0) { ids = (int *) calloc(num_side_sets, sizeof(int)); error = ex_get_side_set_ids (exoid, ids); printf ("\nafter ex_get_side_set_ids, error = %3d\n", error); for (i=0; i 0) { error = ex_get_side_set_dist_fact (exoid, ids[i], dist_fact); printf ("\nafter ex_get_side_set_dist_fact, error = %3d\n", error); } printf ("element list for side set %2d\n", ids[i]); for (j=0; j 0) { printf ("dist factors for side set %2d\n", ids[i]); for (j=0; j 0) { error = ex_inquire(exoid, EX_INQ_SS_ELEM_LEN, &elem_list_len, &fdum, cdum); printf ("\nafter ex_inquire: EX_INQ_SS_ELEM_LEN = %d, error = %d\n", elem_list_len, error); error = ex_inquire(exoid, EX_INQ_SS_NODE_LEN, &node_list_len, &fdum, cdum); printf ("\nafter ex_inquire: EX_INQ_SS_NODE_LEN = %d, error = %d\n", node_list_len, error); error = ex_inquire(exoid, EX_INQ_SS_DF_LEN, &df_list_len, &fdum, cdum); printf ("\nafter ex_inquire: EX_INQ_SS_DF_LEN = %d, error = %d\n", df_list_len, error); } /* read concatenated side sets; this produces the same information as * the above code which reads individual side sets */ /* concatenated side set read */ if (num_side_sets > 0) { ids = (int *) calloc(num_side_sets, sizeof(int)); num_elem_per_set = (int *) calloc(num_side_sets, sizeof(int)); num_df_per_set = (int *) calloc(num_side_sets, sizeof(int)); elem_ind = (int *) calloc(num_side_sets, sizeof(int)); df_ind = (int *) calloc(num_side_sets, sizeof(int)); elem_list = (int *) calloc(elem_list_len, sizeof(int)); side_list = (int *) calloc(elem_list_len, sizeof(int)); dist_fact = (float *) calloc(df_list_len, sizeof(float)); error = ex_get_concat_side_sets (exoid, ids, num_elem_per_set, num_df_per_set, elem_ind, df_ind, elem_list, side_list, dist_fact); printf ("\nafter ex_get_concat_side_sets, error = %3d\n", error); printf ("concatenated side set info\n"); printf ("ids = \n"); for (i=0; i 0) { error = ex_get_var_param (exoid, "n", &num_nod_vars); printf ("\nafter ex_get_var_param, error = %3d\n", error); for (i=0; i 0) { error = ex_get_var_param (exoid, "e", &num_ele_vars); printf ("\nafter ex_get_var_param, error = %3d\n", error); for (i=0; i 0) { truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int)); error = ex_get_elem_var_tab (exoid, num_elem_blk, num_ele_vars, truth_tab); printf ("\nafter ex_get_elem_var_tab, error = %3d\n", error); printf ("This is the element variable truth table:\n"); k = 0; for (i=0; i 0) { error = ex_get_var_param (exoid, "m", &num_nset_vars); printf ("\nafter ex_get_var_param, error = %3d\n", error); if (num_nset_vars > 0) { for (i=0; i 0) { truth_tab = (int *) calloc ((num_node_sets*num_nset_vars), sizeof(int)); error = ex_get_nset_var_tab (exoid, num_node_sets, num_nset_vars, truth_tab); printf ("\nafter ex_get_nset_var_tab, error = %3d\n", error); printf ("This is the nodeset variable truth table:\n"); k = 0; for (i=0; i 0) { error = ex_get_var_param (exoid, "s", &num_sset_vars); printf ("\nafter ex_get_var_param, error = %3d\n", error); if (num_sset_vars > 0) { for (i=0; i 0) { truth_tab = (int *) calloc ((num_side_sets*num_sset_vars), sizeof(int)); error = ex_get_sset_var_tab (exoid, num_side_sets, num_sset_vars, truth_tab); printf ("\nafter ex_get_sset_var_tab, error = %3d\n", error); printf ("This is the sideset variable truth table:\n"); k = 0; for (i=0; i 0) { var_values = (float *) calloc (num_nodes, sizeof(float)); error = ex_get_nodal_var (exoid, time_step, var_index, num_nodes, var_values); printf ("\nafter ex_get_nodal_var, error = %3d\n", error); printf ("nodal variable %2d values at time step %2d\n", var_index, time_step); for (i=0; i 0) { ids = (int *) calloc(num_elem_blk, sizeof(int)); error = ex_get_elem_blk_ids (exoid, ids); printf ("\n after ex_get_elem_blk_ids, error = %3d\n", error); for (i=0; i 0) { var_values = (float *) calloc (num_elem_in_block[i], sizeof(float)); error = ex_get_elem_var (exoid, time_step, var_index, ids[i], num_elem_in_block[i], var_values); printf ("\nafter ex_get_elem_var, error = %3d\n", error); if (!error) { printf ("element variable %2d values of element block %2d at time step %2d\n", var_index, ids[i], time_step); for (j=0; j 0) { var_values = (float *) calloc (num_time_steps, sizeof(float)); var_index = 2; elem_num = 2; error = ex_get_elem_var_time (exoid, var_index, elem_num, beg_time, end_time, var_values); printf ("\nafter ex_get_elem_var_time, error = %3d\n", error); printf ("element variable %2d values for element %2d through time:\n", var_index, elem_num); for (i=0; i 0) { ids = (int *) calloc(num_side_sets, sizeof(int)); error = ex_get_side_set_ids (exoid, ids); printf ("\n after ex_get_side_set_ids, error = %3d\n", error); for (i=0; i 0) { ids = (int *) calloc(num_node_sets, sizeof(int)); error = ex_get_node_set_ids (exoid, ids); printf ("\n after ex_get_node_set_ids, error = %3d\n", error); for (i=0; i 0) free (num_nodes_per_set); free (name); error = ex_close (exoid); printf ("\nafter ex_close, error = %3d\n", error); return 0; }