int c_ex_get_side_set_ids(int *exoid, int *side_set_ids) { int error=0; #ifdef HAVE_LIBEXOIIV2C error = ex_get_side_set_ids (*exoid, side_set_ids); #else FLExit("Fluidity was not configured with exodusII, reconfigure with '--with-exodusii'!"); #endif return (error); }
int ex_inquire (int exoid, int req_info, int *ret_int, void *ret_float, char *ret_char) { int dimid, varid, i, tmp_num, *ids; long ldum, num_sets, start[2], count[2]; nclong *stat_vals; char errmsg[MAX_ERR_LENGTH]; exerrval = 0; /* clear error code */ switch (req_info) { case EX_INQ_FILE_TYPE: /* obsolete call */ /*returns "r" for regular EXODUS II file or "h" for history EXODUS file*/ *ret_char = '\0'; exerrval = EX_BADPARAM; sprintf(errmsg, "Warning: file type inquire is obsolete"); ex_err("ex_inquire",errmsg,exerrval); return (EX_WARN); case EX_INQ_API_VERS: /* returns the EXODUS II API version number */ if (ncattget (exoid, NC_GLOBAL, ATT_API_VERSION, ret_float) == -1) { /* try old (prior to db version 2.02) attribute name */ if (ncattget (exoid, NC_GLOBAL, ATT_API_VERSION_BLANK,ret_float) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to get EXODUS API version for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } } break; case EX_INQ_DB_VERS: /* returns the EXODUS II database version number */ if (ncattget (exoid, NC_GLOBAL, ATT_VERSION, ret_float) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to get EXODUS database version for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } break; case EX_INQ_LIB_VERS: /* returns the EXODUS II Library version number */ flt_cvt((float *)ret_float, EX_API_VERS); break; case EX_INQ_TITLE: /* returns the title of the database */ if (ncattget (exoid, NC_GLOBAL, ATT_TITLE, ret_char) == -1) { *ret_char = '\0'; exerrval = ncerr; sprintf(errmsg, "Error: failed to get database title for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } break; case EX_INQ_DIM: /* returns the dimensionality (2 or 3, for 2-d or 3-d) of the database */ if ((dimid = ncdimid (exoid, DIM_NUM_DIM)) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to locate database dimensionality in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to get database dimensionality for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } *ret_int = ldum; break; case EX_INQ_NODES: /* returns the number of nodes */ if ((dimid = ncdimid (exoid, DIM_NUM_NODES)) == -1) { *ret_int = 0; } else { if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of nodes for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } *ret_int = ldum; } break; case EX_INQ_ELEM: /* returns the number of elements */ if ((dimid = ncdimid (exoid, DIM_NUM_ELEM)) == -1) { *ret_int = 0; } else { if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of elements for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } *ret_int = ldum; } break; case EX_INQ_ELEM_BLK: /* returns the number of element blocks */ if ((dimid = ncdimid (exoid, DIM_NUM_EL_BLK)) == -1) { *ret_int = 0; } else { if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of element blocks for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } *ret_int = ldum; } break; case EX_INQ_NODE_SETS: /* returns the number of node sets */ if ((dimid = ncdimid (exoid, DIM_NUM_NS)) < 0) *ret_int = 0; /* no node sets defined */ else { if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of node sets in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } *ret_int = ldum; } break; case EX_INQ_NS_NODE_LEN: /* returns the length of the concatenated node sets node list */ *ret_int = 0; /* default value if no node sets are defined */ if ((dimid = ncdimid (exoid, DIM_NUM_NS)) != -1 ) { if (ncdiminq (exoid, dimid, (char *) 0, &num_sets) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of node sets in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (!(ids = malloc(num_sets*sizeof(int)))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate memory for node set ids for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (ex_get_node_set_ids (exoid, ids) == EX_FATAL) { sprintf(errmsg, "Error: failed to get node sets in file id %d", exoid); /* pass back error code from ex_get_node_set_ids (in exerrval) */ ex_err("ex_inquire",errmsg,exerrval); free (ids); return (EX_FATAL); } /* allocate space for stat array */ if (!(stat_vals = malloc((int)num_sets*sizeof(nclong)))) { exerrval = EX_MEMFAIL; free (ids); sprintf(errmsg, "Error: failed to allocate memory for node set status array for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } /* get variable id of status array */ if ((varid = ncvarid (exoid, VAR_NS_STAT)) != -1) { /* if status array exists, use it, otherwise assume, object exists to be backward compatible */ start[0] = 0; start[1] = 0; count[0] = num_sets; count[1] = 0; if (ncvarget (exoid, varid, start, count, (void *)stat_vals) == -1) { exerrval = ncerr; free (ids); free(stat_vals); sprintf(errmsg, "Error: failed to get node set status array from file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } } else /* default: status is true */ for(i=0;i<num_sets;i++) stat_vals[i]=1; for (i=0; i<num_sets; i++) { if (stat_vals[i] == 0) /* is this object null? */ continue; if ((dimid = ncdimid (exoid, DIM_NUM_NOD_NS(i+1))) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to locate number of nodes in node set %d in file id %d", ids[i],exoid); ex_err("ex_inquire",errmsg,exerrval); free (ids); free (stat_vals); return (EX_FATAL); } if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of nodes in node set %d in file id %d", ids[i],exoid); ex_err("ex_inquire",errmsg,exerrval); free (stat_vals); free (ids); return (EX_FATAL); } *ret_int += ldum; } free (stat_vals); free (ids); } break; case EX_INQ_NS_DF_LEN: /* returns the length of the concatenated node sets dist factor list */ /* Determine the concatenated node sets distribution factor length: 1. Get the node set ids list. 2. Check see if the dist factor variable for a node set id exists. 3. If it exists, goto step 4, else the length is zero. 4. Get the dimension of the number of nodes in the node set -0 use this value as the length as by definition they are the same. 5. Sum the individual lengths for the total list length. */ *ret_int = 0; /* default value if no node sets defined */ if ((dimid = ncdimid (exoid, DIM_NUM_NS)) != -1) { if (ncdiminq (exoid, dimid, (char *) 0, &num_sets) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of node sets in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (!(ids = malloc(num_sets*sizeof(int)))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate memory for node set ids for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (ex_get_node_set_ids (exoid, ids) == EX_FATAL) { sprintf(errmsg, "Error: failed to get node sets in file id %d", exoid); /* pass back error code from ex_get_node_set_ids (in exerrval) */ ex_err("ex_inquire",errmsg,exerrval); free (ids); return (EX_FATAL); } for (i=0; i<num_sets; i++) { if (ncvarid (exoid, VAR_FACT_NS(i+1)) == -1) { if (ncerr == NC_ENOTVAR) { ldum = 0; /* this dist factor doesn't exist */ } else { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to locate number of dist fact for node set %d in file id %d", ids[i], exoid); ex_err("ex_inquire",errmsg,exerrval); free (ids); return (EX_FATAL); } } else { if ((dimid = ncdimid (exoid, DIM_NUM_NOD_NS(i+1))) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to locate number of nodes in node set %d in file id %d", ids[i], exoid); ex_err("ex_inquire",errmsg,exerrval); free (ids); return (EX_FATAL); } if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of nodes in node set %d in file id %d", ids[i],exoid); ex_err("ex_inquire",errmsg,exerrval); free(ids); return (EX_FATAL); } } *ret_int += ldum; } free(ids); } break; case EX_INQ_SIDE_SETS: /* returns the number of side sets */ *ret_int = 0; /* default return value */ if ((dimid = ncdimid (exoid, DIM_NUM_SS)) != -1) { if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of side sets in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } *ret_int = ldum; } break; case EX_INQ_SS_NODE_LEN: /* returns the length of the concatenated side sets node list */ *ret_int = 0; /* default return value */ if ((dimid = ncdimid (exoid, DIM_NUM_SS)) != -1) { if (ncdiminq (exoid, dimid, (char *) 0, &num_sets) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of side sets in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (!(ids = malloc(num_sets*sizeof(int)))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate memory for side set ids for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (ex_get_side_set_ids (exoid, ids) == EX_FATAL) { sprintf(errmsg, "Error: failed to get side set ids in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); free(ids); return (EX_FATAL); } /* allocate space for stat array */ if (!(stat_vals = malloc((int)num_sets*sizeof(nclong)))) { exerrval = EX_MEMFAIL; free (ids); sprintf(errmsg, "Error: failed to allocate memory for side set status array for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } /* get variable id of status array */ if ((varid = ncvarid (exoid, VAR_SS_STAT)) != -1) { /* if status array exists, use it, otherwise assume, object exists to be backward compatible */ start[0] = 0; start[1] = 0; count[0] = num_sets; count[1] = 0; if (ncvarget (exoid, varid, start, count, (void *)stat_vals) == -1) { exerrval = ncerr; free (ids); free(stat_vals); sprintf(errmsg, "Error: failed to get element block status array from file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } } else /* default: status is true */ for(i=0;i<num_sets;i++) stat_vals[i]=1; /* walk id list, get each side set node length and sum for total */ for (i=0; i<num_sets; i++) { if (stat_vals[i] == 0) /* is this object null? */ continue; if (ex_get_side_set_node_list_len(exoid, ids[i], &tmp_num) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to side set %d node length in file id %d", ids[i],exoid); ex_err("ex_inquire",errmsg,exerrval); free(stat_vals); free(ids); return (EX_FATAL); } *ret_int += tmp_num; } free(stat_vals); free (ids); } break; case EX_INQ_SS_ELEM_LEN: /* returns the length of the concatenated side sets element list */ EX_GET_CONCAT_SET_LEN(ret_int,"side",EX_SIDE_SET,DIM_NUM_SS,VAR_SS_STAT,DIM_NUM_SIDE_SS,0); break; case EX_INQ_SS_DF_LEN: /* returns the length of the concatenated side sets dist factor list */ /* Determine the concatenated side sets distribution factor length: 1. Get the side set ids list. 2. Check see if the dist factor dimension for a side set id exists. 3. If it exists, goto step 4, else set the individual length to zero. 4. Sum the dimension value into the running total length. */ *ret_int = 0; /* first check see if any side sets exist */ if ((dimid = ncdimid (exoid, DIM_NUM_SS)) != -1) { if (ncdiminq (exoid, dimid, (char *) 0, &num_sets) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of side sets in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (!(ids = malloc(num_sets*sizeof(int)))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate memory for side set ids for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (ex_get_side_set_ids (exoid, ids) == EX_FATAL) { sprintf(errmsg, "Error: failed to get side sets in file id %d", exoid); /* pass back error code from ex_get_side_set_ids (in exerrval) */ ex_err("ex_inquire",errmsg,exerrval); free (ids); return (EX_FATAL); } for (i=0; i<num_sets; i++) { if ((dimid = ncdimid (exoid, DIM_NUM_DF_SS(i+1))) == -1) { if (ncerr == NC_EBADDIM) { ldum = 0; /* this dist factor doesn't exist */ } else { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to locate number of dist fact for side set %d in file id %d", ids[i], exoid); ex_err("ex_inquire",errmsg,exerrval); free (ids); return (EX_FATAL); } } else { if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of dist factors in side set %d in file id %d", ids[i], exoid); ex_err("ex_inquire",errmsg,exerrval); free (ids); return (EX_FATAL); } } *ret_int += ldum; } free (ids); } break; case EX_INQ_QA: /* returns the number of QA records */ if ((dimid = ncdimid (exoid, DIM_NUM_QA)) < 0) *ret_int = 0; /* no QA records stored */ else { if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of QA records in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } *ret_int = ldum; } break; case EX_INQ_INFO: /* returns the number of information records */ if ((dimid = ncdimid (exoid, DIM_NUM_INFO)) < 0) *ret_int = 0; /* no information records stored */ else { if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of info records in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } *ret_int = ldum; } break; case EX_INQ_TIME: /* returns the number of time steps stored in the database; we find * this out by inquiring the maximum record number of the "unlimited" * dimension */ if ((dimid = ncdimid (exoid, DIM_TIME)) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to locate time dimension in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to get time dimension in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } *ret_int = ldum; break; case EX_INQ_EB_PROP: /* returns the number of element block properties */ *ret_int = ex_get_num_props (exoid, EX_ELEM_BLOCK); break; case EX_INQ_NS_PROP: /* returns the number of node set properties */ *ret_int = ex_get_num_props (exoid, EX_NODE_SET); break; case EX_INQ_SS_PROP: /* returns the number of side set properties */ *ret_int = ex_get_num_props (exoid, EX_SIDE_SET); break; case EX_INQ_ELEM_MAP: /* returns the number of element maps */ if ((dimid = ncdimid (exoid, DIM_NUM_EM)) == -1) { /* no element maps so return 0 */ *ret_int = 0; return (EX_NOERR); } if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of element maps for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } *ret_int = ldum; break; case EX_INQ_EM_PROP: /* returns the number of element map properties */ *ret_int = ex_get_num_props (exoid, EX_ELEM_MAP); break; case EX_INQ_NODE_MAP: /* returns the number of node maps */ if ((dimid = ncdimid (exoid, DIM_NUM_NM)) == -1) { /* no node maps so return 0 */ *ret_int = 0; return (EX_NOERR); } if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1) { *ret_int = 0; exerrval = ncerr; sprintf(errmsg, "Error: failed to get number of node maps for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } *ret_int = ldum; break; case EX_INQ_NM_PROP: /* returns the number of element map properties */ *ret_int = ex_get_num_props (exoid, EX_NODE_MAP); break; case EX_INQ_EDGE: /* returns the number of edges (defined across all edge blocks). */ EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_EDGE, 1); break; case EX_INQ_EDGE_BLK: /* returns the number of edge blocks. */ EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_ED_BLK, 1); break; case EX_INQ_EDGE_SETS: /* returns the number of edge sets. */ EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_ES, 1); break; case EX_INQ_ES_LEN: /* returns the length of the concatenated edge set edge list. */ EX_GET_CONCAT_SET_LEN(ret_int,"edge",EX_EDGE_SET,DIM_NUM_ES,VAR_ES_STAT,DIM_NUM_EDGE_ES,0); break; case EX_INQ_ES_DF_LEN: /* returns the length of the concatenated edge set distribution factor list. */ EX_GET_CONCAT_SET_LEN(ret_int,"edge",EX_EDGE_SET,DIM_NUM_ES,VAR_ES_STAT,DIM_NUM_DF_ES,1); break; case EX_INQ_EDGE_PROP: /* returns the number of integer properties stored for each edge block. This includes the "ID" property. */ *ret_int = ex_get_num_props( exoid, EX_EDGE_BLOCK ); break; case EX_INQ_ES_PROP: /* returns the number of integer properties stored for each edge set.. This includes the "ID" property */ *ret_int = ex_get_num_props( exoid, EX_EDGE_SET ); break; case EX_INQ_FACE: /* returns the number of faces (defined across all face blocks). */ EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_FACE, 1); break; case EX_INQ_FACE_BLK: /* returns the number of edge blocks. */ EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_FA_BLK, 1); break; case EX_INQ_FACE_SETS: /* returns the number of edge sets. */ EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_FS, 1); break; case EX_INQ_FS_LEN: /* returns the length of the concatenated edge set edge list. */ EX_GET_CONCAT_SET_LEN(ret_int,"face",EX_FACE_SET,DIM_NUM_FS,VAR_FS_STAT,DIM_NUM_FACE_FS,0); break; case EX_INQ_FS_DF_LEN: /* returns the length of the concatenated edge set distribution factor list. */ EX_GET_CONCAT_SET_LEN(ret_int,"face",EX_FACE_SET,DIM_NUM_FS,VAR_FS_STAT,DIM_NUM_DF_FS,1); break; case EX_INQ_FACE_PROP: /* returns the number of integer properties stored for each edge block. This includes the "ID" property. */ *ret_int = ex_get_num_props( exoid, EX_FACE_BLOCK ); break; case EX_INQ_FS_PROP: /* returns the number of integer properties stored for each edge set.. This includes the "ID" property */ *ret_int = ex_get_num_props( exoid, EX_FACE_SET ); break; case EX_INQ_ELEM_SETS: /* returns the number of element sets. */ EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_ELS, 1); break; case EX_INQ_ELS_LEN: /* returns the length of the concatenated element set element list. */ EX_GET_CONCAT_SET_LEN(ret_int,"element",EX_ELEM_SET,DIM_NUM_ELS,VAR_ELS_STAT,DIM_NUM_ELE_ELS,0); break; case EX_INQ_ELS_DF_LEN: /* returns the length of the concatenated element set distribution factor list. */ EX_GET_CONCAT_SET_LEN(ret_int,"element",EX_ELEM_SET,DIM_NUM_ELS,VAR_ELS_STAT,DIM_NUM_DF_ELS,1); break; case EX_INQ_ELS_PROP: /* returns the number of integer properties stored for each element set. */ *ret_int = ex_get_num_props( exoid, EX_ELEM_SET ); break; case EX_INQ_EDGE_MAP: /* returns the number of edge sets. */ EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_EDM, 1); break; case EX_INQ_FACE_MAP: /* returns the number of edge sets. */ EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_FAM, 1); break; default: *ret_int = 0; exerrval = EX_FATAL; sprintf(errmsg, "Error: invalid inquiry %d", req_info); ex_err("ex_inquire",errmsg,exerrval); return(EX_FATAL); } return (EX_NOERR); }
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; 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 name[MAX_STR_LENGTH + 1]; 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]; 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); /* 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 = %d\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)); if (num_dim >= 2) y = (float *)calloc(num_nodes, sizeof(float)); else y = 0; 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 < num_nodes; i++) { printf("%5.1f\n", x[i]); } if (num_dim >= 2) { printf("y coords = \n"); for (i = 0; i < num_nodes; i++) { printf("%5.1f\n", y[i]); } } if (num_dim >= 3) { printf("z coords = \n"); for (i = 0; i < num_nodes; i++) { printf("%5.1f\n", z[i]); } } /* error = ex_get_1_coord (exoid, 2, x, y, z); printf ("\nafter ex_get_1_coord, error = %3d\n", error); printf ("x coord of node 2 = \n"); printf ("%f \n", x[0]); printf ("y coord of node 2 = \n"); printf ("%f \n", y[0]); */ free(x); if (num_dim >= 2) free(y); if (num_dim >= 3) free(z); for (i = 0; i < num_dim; i++) { coord_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_coord_names(exoid, coord_names); printf("\nafter ex_get_coord_names, error = %3d\n", error); printf("x coord name = '%s'\n", coord_names[0]); if (num_dim > 1) printf("y coord name = '%s'\n", coord_names[1]); if (num_dim > 2) printf("z coord name = '%s'\n", coord_names[2]); for (i = 0; i < num_dim; i++) free(coord_names[i]); { int num_attrs = 0; error = ex_get_attr_param(exoid, EX_NODAL, 0, &num_attrs); printf(" after ex_get_attr_param, error = %d\n", error); printf("num nodal attributes = %d\n", num_attrs); if (num_attrs > 0) { for (j = 0; j < num_attrs; j++) { attrib_names[j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_attr_names(exoid, EX_NODAL, 0, attrib_names); printf(" after ex_get_attr_names, error = %d\n", error); if (error == 0) { attrib = (float *)calloc(num_nodes, sizeof(float)); for (j = 0; j < num_attrs; j++) { printf("nodal attribute %d = '%s'\n", j, attrib_names[j]); error = ex_get_one_attr(exoid, EX_NODAL, 0, j + 1, attrib); printf(" after ex_get_one_attr, error = %d\n", error); for (i = 0; i < num_nodes; i++) { printf("%5.1f\n", attrib[i]); } free(attrib_names[j]); } free(attrib); } } } /* read element order map */ elem_map = (int *)calloc(num_elem, sizeof(int)); error = ex_get_map(exoid, elem_map); printf("\nafter ex_get_map, error = %3d\n", error); for (i = 0; i < num_elem; i++) { printf("elem_map(%d) = %d \n", i, elem_map[i]); } free(elem_map); /* read element block parameters */ if (num_elem_blk > 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 < num_elem_blk; i++) { block_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_names(exoid, EX_ELEM_BLOCK, block_names); printf("\nafter ex_get_names, error = %3d\n", error); for (i = 0; i < num_elem_blk; i++) { ex_get_name(exoid, EX_ELEM_BLOCK, ids[i], name); if (strcmp(name, block_names[i]) != 0) { printf("error in ex_get_name for block id %d\n", ids[i]); } error = ex_get_elem_block(exoid, ids[i], elem_type, &(num_elem_in_block[i]), &(num_nodes_per_elem[i]), &(num_attr[i])); printf("\nafter ex_get_elem_block, error = %d\n", error); printf("element block id = %2d\n", ids[i]); printf("element type = '%s'\n", elem_type); printf("num_elem_in_block = %2d\n", num_elem_in_block[i]); printf("num_nodes_per_elem = %2d\n", num_nodes_per_elem[i]); printf("num_attr = %2d\n", num_attr[i]); printf("name = '%s'\n", block_names[i]); free(block_names[i]); } /* read element block properties */ error = ex_inquire(exoid, EX_INQ_EB_PROP, &num_props, &fdum, cdum); printf("\nafter ex_inquire, error = %d\n", error); printf("\nThere are %2d properties for each element block\n", num_props); for (i = 0; i < num_props; i++) { prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_prop_names(exoid, EX_ELEM_BLOCK, prop_names); printf("after ex_get_prop_names, error = %d\n", error); for (i = 1; i < num_props; i++) /* Prop 1 is id; skip that here */ { for (j = 0; j < num_elem_blk; j++) { error = ex_get_prop(exoid, EX_ELEM_BLOCK, ids[j], prop_names[i], &prop_value); if (error == 0) printf("element block %2d, property(%2d): '%s'= %5d\n", j + 1, i + 1, prop_names[i], prop_value); else printf("after ex_get_prop, error = %d\n", error); } } for (i = 0; i < num_props; i++) free(prop_names[i]); } /* read element connectivity */ for (i = 0; i < num_elem_blk; i++) { if (num_elem_in_block[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 < num_nodes_per_elem[i]; j++) { printf("%3d\n", connect[j]); } /* error = ex_get_1_elem_conn (exoid, 1, ids[i], connect); printf ("\nafter ex_get_elem_conn, error = %d\n", error); printf ("node list for first element of element block %d \n ", ids[i]); for (j=0; j<num_nodes_per_elem[i]; j++) { printf ("%d \n", connect[j]); } */ free(connect); } } /* read element block attributes */ for (i = 0; i < num_elem_blk; i++) { if (num_elem_in_block[i] > 0) { for (j = 0; j < num_attr[i]; j++) attrib_names[j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); attrib = (float *)calloc(num_attr[i] * num_elem_in_block[i], sizeof(float)); error = ex_get_elem_attr(exoid, ids[i], attrib); printf("\n after ex_get_elem_attr, error = %d\n", error); if (error == 0) { error = ex_get_elem_attr_names(exoid, ids[i], attrib_names); printf(" after ex_get_elem_attr_names, error = %d\n", error); if (error == 0) { printf("element block %d attribute '%s' = %6.4f\n", ids[i], attrib_names[0], *attrib); } } free(attrib); for (j = 0; j < num_attr[i]; j++) free(attrib_names[j]); } } if (num_elem_blk > 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 < num_node_sets; i++) { nset_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_names(exoid, EX_NODE_SET, nset_names); printf("\nafter ex_get_names, error = %3d\n", error); for (i = 0; i < num_node_sets; i++) { ex_get_name(exoid, EX_NODE_SET, ids[i], name); if (strcmp(name, nset_names[i]) != 0) { printf("error in ex_get_name for nodeset id %d\n", ids[i]); } error = ex_get_node_set_param(exoid, ids[i], &num_nodes_in_set, &num_df_in_set); printf("\nafter ex_get_node_set_param, error = %3d\n", error); printf("\nnode set %2d parameters: \n", ids[i]); printf("num_nodes = %2d\n", num_nodes_in_set); printf("name = '%s'\n", nset_names[i]); free(nset_names[i]); node_list = (int *)calloc(num_nodes_in_set, sizeof(int)); dist_fact = (float *)calloc(num_nodes_in_set, sizeof(float)); error = ex_get_node_set(exoid, ids[i], node_list); printf("\nafter ex_get_node_set, error = %3d\n", error); if (num_df_in_set > 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 < num_nodes_in_set; j++) { printf("%3d\n", node_list[j]); } if (num_df_in_set > 0) { printf("dist factors for node set %2d\n", ids[i]); for (j = 0; j < num_df_in_set; j++) { printf("%5.2f\n", dist_fact[j]); } } else printf("no dist factors for node set %2d\n", ids[i]); free(node_list); free(dist_fact); { int num_attrs = 0; error = ex_get_attr_param(exoid, EX_NODE_SET, ids[i], &num_attrs); printf(" after ex_get_attr_param, error = %d\n", error); printf("num nodeset attributes for nodeset %d = %d\n", ids[i], num_attrs); if (num_attrs > 0) { for (j = 0; j < num_attrs; j++) { attrib_names[j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_attr_names(exoid, EX_NODE_SET, ids[i], attrib_names); printf(" after ex_get_attr_names, error = %d\n", error); if (error == 0) { attrib = (float *)calloc(num_nodes_in_set, sizeof(float)); for (j = 0; j < num_attrs; j++) { printf("nodeset attribute %d = '%s'\n", j, attrib_names[j]); error = ex_get_one_attr(exoid, EX_NODE_SET, ids[i], j + 1, attrib); printf(" after ex_get_one_attr, error = %d\n", error); for (k = 0; k < num_nodes_in_set; k++) { printf("%5.1f\n", attrib[k]); } free(attrib_names[j]); } free(attrib); } } } } free(ids); /* read node set properties */ error = ex_inquire(exoid, EX_INQ_NS_PROP, &num_props, &fdum, cdum); printf("\nafter ex_inquire, error = %d\n", error); printf("\nThere are %2d properties for each node set\n", num_props); for (i = 0; i < num_props; i++) { prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } prop_values = (int *)calloc(num_node_sets, sizeof(int)); error = ex_get_prop_names(exoid, EX_NODE_SET, prop_names); printf("after ex_get_prop_names, error = %d\n", error); for (i = 0; i < num_props; i++) { error = ex_get_prop_array(exoid, EX_NODE_SET, prop_names[i], prop_values); if (error == 0) for (j = 0; j < num_node_sets; j++) printf("node set %2d, property(%2d): '%s'= %5d\n", j + 1, i + 1, prop_names[i], prop_values[j]); else printf("after ex_get_prop_array, error = %d\n", error); } for (i = 0; i < num_props; i++) free(prop_names[i]); free(prop_values); /* read concatenated node sets; this produces the same information as * the above code which reads individual node sets */ error = ex_inquire(exoid, EX_INQ_NODE_SETS, &num_node_sets, &fdum, cdum); printf("\nafter ex_inquire, error = %3d\n", error); ids = (int *)calloc(num_node_sets, sizeof(int)); num_nodes_per_set = (int *)calloc(num_node_sets, sizeof(int)); num_df_per_set = (int *)calloc(num_node_sets, sizeof(int)); node_ind = (int *)calloc(num_node_sets, sizeof(int)); df_ind = (int *)calloc(num_node_sets, sizeof(int)); error = ex_inquire(exoid, EX_INQ_NS_NODE_LEN, &list_len, &fdum, cdum); printf("\nafter ex_inquire: EX_INQ_NS_NODE_LEN = %d, error = %3d\n", list_len, error); node_list = (int *)calloc(list_len, sizeof(int)); error = ex_inquire(exoid, EX_INQ_NS_DF_LEN, &list_len, &fdum, cdum); printf("\nafter ex_inquire: EX_INQ_NS_DF_LEN = %d, error = %3d\n", list_len, error); dist_fact = (float *)calloc(list_len, sizeof(float)); error = ex_get_concat_node_sets(exoid, ids, num_nodes_per_set, num_df_per_set, node_ind, df_ind, node_list, dist_fact); printf("\nafter ex_get_concat_node_sets, error = %3d\n", error); printf("\nconcatenated node set info\n"); printf("ids = \n"); for (i = 0; i < num_node_sets; i++) printf("%3d\n", ids[i]); printf("num_nodes_per_set = \n"); for (i = 0; i < num_node_sets; i++) printf("%3d\n", num_nodes_per_set[i]); printf("node_ind = \n"); for (i = 0; i < num_node_sets; i++) printf("%3d\n", node_ind[i]); printf("node_list = \n"); for (i = 0; i < list_len; i++) printf("%3d\n", node_list[i]); printf("dist_fact = \n"); for (i = 0; i < list_len; i++) printf("%5.3f\n", dist_fact[i]); free(ids); free(df_ind); free(node_ind); free(num_df_per_set); free(node_list); free(dist_fact); } /* read individual side sets */ if (num_side_sets > 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 < num_side_sets; i++) { sset_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_names(exoid, EX_SIDE_SET, sset_names); printf("\nafter ex_get_names, error = %3d\n", error); for (i = 0; i < num_side_sets; i++) { ex_get_name(exoid, EX_SIDE_SET, ids[i], name); if (strcmp(name, sset_names[i]) != 0) { printf("error in ex_get_name for sideset id %d\n", ids[i]); } error = ex_get_side_set_param(exoid, ids[i], &num_sides_in_set, &num_df_in_set); printf("\nafter ex_get_side_set_param, error = %3d\n", error); printf("side set %2d parameters:\n", ids[i]); printf("name = '%s'\n", sset_names[i]); printf("num_sides = %3d\n", num_sides_in_set); printf("num_dist_factors = %3d\n", num_df_in_set); free(sset_names[i]); /* Note: The # of elements is same as # of sides! */ num_elem_in_set = num_sides_in_set; elem_list = (int *)calloc(num_elem_in_set, sizeof(int)); side_list = (int *)calloc(num_sides_in_set, sizeof(int)); node_ctr_list = (int *)calloc(num_elem_in_set, sizeof(int)); node_list = (int *)calloc(num_elem_in_set * 21, sizeof(int)); dist_fact = (float *)calloc(num_df_in_set, sizeof(float)); error = ex_get_side_set(exoid, ids[i], elem_list, side_list); printf("\nafter ex_get_side_set, error = %3d\n", error); error = ex_get_side_set_node_list(exoid, ids[i], node_ctr_list, node_list); printf("\nafter ex_get_side_set_node_list, error = %3d\n", error); if (num_df_in_set > 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 < num_elem_in_set; j++) { printf("%3d\n", elem_list[j]); } printf("side list for side set %2d\n", ids[i]); for (j = 0; j < num_sides_in_set; j++) { printf("%3d\n", side_list[j]); } node_ctr = 0; printf("node list for side set %2d\n", ids[i]); for (k = 0; k < num_elem_in_set; k++) { for (j = 0; j < node_ctr_list[k]; j++) { printf("%3d\n", node_list[node_ctr + j]); } node_ctr += node_ctr_list[k]; } if (num_df_in_set > 0) { printf("dist factors for side set %2d\n", ids[i]); for (j = 0; j < num_df_in_set; j++) { printf("%5.3f\n", dist_fact[j]); } } else printf("no dist factors for side set %2d\n", ids[i]); free(elem_list); free(side_list); free(node_ctr_list); free(node_list); free(dist_fact); } /* read side set properties */ error = ex_inquire(exoid, EX_INQ_SS_PROP, &num_props, &fdum, cdum); printf("\nafter ex_inquire, error = %d\n", error); printf("\nThere are %2d properties for each side set\n", num_props); for (i = 0; i < num_props; i++) { prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_prop_names(exoid, EX_SIDE_SET, prop_names); printf("after ex_get_prop_names, error = %d\n", error); for (i = 0; i < num_props; i++) { for (j = 0; j < num_side_sets; j++) { error = ex_get_prop(exoid, EX_SIDE_SET, ids[j], prop_names[i], &prop_value); if (error == 0) printf("side set %2d, property(%2d): '%s'= %5d\n", j + 1, i + 1, prop_names[i], prop_value); else printf("after ex_get_prop, error = %d\n", error); } } for (i = 0; i < num_props; i++) free(prop_names[i]); free(ids); error = ex_inquire(exoid, EX_INQ_SIDE_SETS, &num_side_sets, &fdum, cdum); printf("\nafter ex_inquire: EX_INQ_SIDE_SETS = %d, error = %d\n", num_side_sets, error); if (num_side_sets > 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 < num_side_sets; i++) printf("%3d\n", ids[i]); printf("num_elem_per_set = \n"); for (i = 0; i < num_side_sets; i++) printf("%3d\n", num_elem_per_set[i]); printf("num_dist_per_set = \n"); for (i = 0; i < num_side_sets; i++) printf("%3d\n", num_df_per_set[i]); printf("elem_ind = \n"); for (i = 0; i < num_side_sets; i++) printf("%3d\n", elem_ind[i]); printf("dist_ind = \n"); for (i = 0; i < num_side_sets; i++) printf("%3d\n", df_ind[i]); printf("elem_list = \n"); for (i = 0; i < elem_list_len; i++) printf("%3d\n", elem_list[i]); printf("side_list = \n"); for (i = 0; i < elem_list_len; i++) printf("%3d\n", side_list[i]); printf("dist_fact = \n"); for (i = 0; i < df_list_len; i++) printf("%5.3f\n", dist_fact[i]); free(ids); free(num_df_per_set); free(df_ind); free(elem_ind); free(elem_list); free(side_list); free(dist_fact); } } /* end of concatenated side set read */ /* read QA records */ ex_inquire(exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum); for (i = 0; i < num_qa_rec; i++) { for (j = 0; j < 4; j++) { qa_record[i][j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } } error = ex_get_qa(exoid, qa_record); printf("\nafter ex_get_qa, error = %3d\n", error); printf("QA records = \n"); for (i = 0; i < num_qa_rec; i++) { for (j = 0; j < 4; j++) { printf(" '%s'\n", qa_record[i][j]); free(qa_record[i][j]); } } /* read information records */ error = ex_inquire(exoid, EX_INQ_INFO, &num_info, &fdum, cdum); printf("\nafter ex_inquire, error = %3d\n", error); for (i = 0; i < num_info; i++) { info[i] = (char *)calloc((MAX_LINE_LENGTH + 1), sizeof(char)); } error = ex_get_info(exoid, info); printf("\nafter ex_get_info, error = %3d\n", error); printf("info records = \n"); for (i = 0; i < num_info; i++) { printf(" '%s'\n", info[i]); free(info[i]); } /* read global variables parameters and names */ error = ex_get_var_param(exoid, "g", &num_glo_vars); printf("\nafter ex_get_var_param, error = %3d\n", error); for (i = 0; i < num_glo_vars; i++) { var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_var_names(exoid, "g", num_glo_vars, var_names); printf("\nafter ex_get_var_names, error = %3d\n", error); printf("There are %2d global variables; their names are :\n", num_glo_vars); for (i = 0; i < num_glo_vars; i++) { printf(" '%s'\n", var_names[i]); free(var_names[i]); } /* read nodal variables parameters and names */ num_nod_vars = 0; if (num_nodes > 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 < num_nod_vars; i++) { var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_var_names(exoid, "n", num_nod_vars, var_names); printf("\nafter ex_get_var_names, error = %3d\n", error); printf("There are %2d nodal variables; their names are :\n", num_nod_vars); for (i = 0; i < num_nod_vars; i++) { printf(" '%s'\n", var_names[i]); free(var_names[i]); } } /* read element variables parameters and names */ num_ele_vars = 0; if (num_elem > 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 < num_ele_vars; i++) { var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_var_names(exoid, "e", num_ele_vars, var_names); printf("\nafter ex_get_var_names, error = %3d\n", error); printf("There are %2d element variables; their names are :\n", num_ele_vars); for (i = 0; i < num_ele_vars; i++) { printf(" '%s'\n", var_names[i]); free(var_names[i]); } /* read element variable truth table */ if (num_ele_vars > 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 < num_elem_blk * num_ele_vars; i++) { printf("%2d\n", truth_tab[k++]); } free(truth_tab); } } /* read nodeset variables parameters and names */ num_nset_vars = 0; if (num_node_sets > 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 < num_nset_vars; i++) { var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_var_names(exoid, "m", num_nset_vars, var_names); printf("\nafter ex_get_var_names, error = %3d\n", error); printf("There are %2d nodeset variables; their names are :\n", num_nset_vars); for (i = 0; i < num_nset_vars; i++) { printf(" '%s'\n", var_names[i]); free(var_names[i]); } /* read nodeset variable truth table */ if (num_nset_vars > 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 < num_node_sets * num_nset_vars; i++) { printf("%2d\n", truth_tab[k++]); } free(truth_tab); } } } /* read sideset variables parameters and names */ num_sset_vars = 0; if (num_side_sets > 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 < num_sset_vars; i++) { var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_var_names(exoid, "s", num_sset_vars, var_names); printf("\nafter ex_get_var_names, error = %3d\n", error); printf("There are %2d sideset variables; their names are :\n", num_sset_vars); for (i = 0; i < num_sset_vars; i++) { printf(" '%s'\n", var_names[i]); free(var_names[i]); } /* read sideset variable truth table */ if (num_sset_vars > 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 < num_side_sets * num_sset_vars; i++) { printf("%2d\n", truth_tab[k++]); } free(truth_tab); } } } /* determine how many time steps are stored */ error = ex_inquire(exoid, EX_INQ_TIME, &num_time_steps, &fdum, cdum); printf("\nafter ex_inquire, error = %3d\n", error); printf("There are %2d time steps in the database.\n", num_time_steps); /* read time value at one time step */ time_step = 3; error = ex_get_time(exoid, time_step, &time_value); printf("\nafter ex_get_time, error = %3d\n", error); printf("time value at time step %2d = %5.3f\n", time_step, time_value); /* read time values at all time steps */ time_values = (float *)calloc(num_time_steps, sizeof(float)); error = ex_get_all_times(exoid, time_values); printf("\nafter ex_get_all_times, error = %3d\n", error); printf("time values at all time steps are:\n"); for (i = 0; i < num_time_steps; i++) printf("%5.3f\n", time_values[i]); free(time_values); /* read all global variables at one time step */ var_values = (float *)calloc(num_glo_vars, sizeof(float)); error = ex_get_glob_vars(exoid, time_step, num_glo_vars, var_values); printf("\nafter ex_get_glob_vars, error = %3d\n", error); printf("global variable values at time step %2d\n", time_step); for (i = 0; i < num_glo_vars; i++) printf("%5.3f\n", var_values[i]); free(var_values); /* read a single global variable through time */ var_index = 1; beg_time = 1; end_time = -1; var_values = (float *)calloc(num_time_steps, sizeof(float)); error = ex_get_glob_var_time(exoid, var_index, beg_time, end_time, var_values); printf("\nafter ex_get_glob_var_time, error = %3d\n", error); printf("global variable %2d values through time:\n", var_index); for (i = 0; i < num_time_steps; i++) printf("%5.3f\n", var_values[i]); free(var_values); /* read a nodal variable at one time step */ if (num_nodes > 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 < num_nodes; i++) printf("%5.3f\n", var_values[i]); free(var_values); /* read a nodal variable through time */ var_values = (float *)calloc(num_time_steps, sizeof(float)); node_num = 1; error = ex_get_nodal_var_time(exoid, var_index, node_num, beg_time, end_time, var_values); printf("\nafter ex_get_nodal_var_time, error = %3d\n", error); printf("nodal variable %2d values for node %2d through time:\n", var_index, node_num); for (i = 0; i < num_time_steps; i++) printf("%5.3f\n", var_values[i]); free(var_values); } /* read an element variable at one time step */ if (num_elem_blk > 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 < num_elem_blk; i++) { if (num_elem_in_block[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 < num_elem_in_block[i]; j++) printf("%5.3f\n", var_values[j]); } free(var_values); } } free(num_elem_in_block); free(ids); } /* read an element variable through time */ if (num_ele_vars > 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 < num_time_steps; i++) printf("%5.3f\n", var_values[i]); free(var_values); } /* read a sideset variable at one time step */ if (num_sset_vars > 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 < num_side_sets; i++) { var_values = (float *)calloc(num_elem_per_set[i], sizeof(float)); error = ex_get_sset_var(exoid, time_step, var_index, ids[i], num_elem_per_set[i], var_values); printf("\nafter ex_get_sset_var, error = %3d\n", error); if (!error) { printf("sideset variable %2d values of sideset %2d at time step %2d\n", var_index, ids[i], time_step); for (j = 0; j < num_elem_per_set[i]; j++) printf("%5.3f\n", var_values[j]); } free(var_values); } free(num_elem_per_set); free(ids); } /* read a nodeset variable at one time step */ if (num_nset_vars > 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 < num_node_sets; i++) { var_values = (float *)calloc(num_nodes_per_set[i], sizeof(float)); error = ex_get_nset_var(exoid, time_step, var_index, ids[i], num_nodes_per_set[i], var_values); printf("\nafter ex_get_nset_var, error = %3d\n", error); if (!error) { printf("nodeset variable %2d values of nodeset %2d at time step %2d\n", var_index, ids[i], time_step); for (j = 0; j < num_nodes_per_set[i]; j++) printf("%5.3f\n", var_values[j]); } free(var_values); } free(ids); } if (num_node_sets > 0) free(num_nodes_per_set); error = ex_close(exoid); printf("\nafter ex_close, error = %3d\n", error); return 0; }
int main(int argc, char **argv) { int exoid, exoid2, num_dim, num_nodes, num_elem, num_elem_blk; int num_elem_in_block, num_node_sets, num_nodes_per_elem, num_attr; int num_side_sets, error; int i, j; int *elem_map, *connect, *node_list, *node_ctr_list, *elem_list, *side_list; int *ids; int num_nodes_in_set, num_elem_in_set; int num_sides_in_set, num_df_in_set; int num_qa_rec, num_info; int CPU_word_size, IO_word_size; int num_props, prop_value, *prop_values; float *x, *y, *z; float *dist_fact; float version, fdum; float attrib[1]; char *coord_names[3], *qa_record[2][4], *info[3]; char title[MAX_LINE_LENGTH + 1], elem_type[MAX_STR_LENGTH + 1]; char *prop_names[3]; char *cdum = 0; /* Specify compute and i/o word size */ CPU_word_size = 0; /* sizeof(float) */ IO_word_size = 4; /* float */ /* open EXODUS II file for reading */ ex_opts(EX_VERBOSE | EX_ABORT); exoid = ex_open("test.exo", /* filename path */ EX_READ, /* access mode */ &CPU_word_size, /* CPU float word size in bytes */ &IO_word_size, /* I/O float word size in bytes */ &version); /* returned version number */ printf("after ex_open for test.exo\n"); printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size); /* create EXODUS II file for writing */ exoid2 = ex_create("test2.exo", /* filename path */ EX_CLOBBER, /* create mode */ &CPU_word_size, /* CPU float word size in bytes */ &IO_word_size); /* I/O float word size in bytes */ printf("after ex_create for test2.exo, exoid = %d\n", exoid2); /* read initialization 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 = %d\n", error); /* write initialization parameters */ error = ex_put_init(exoid2, title, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets); printf("after ex_put_init, error = %d\n", error); /* read nodal coordinate values */ 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); /* write nodal coordinate values */ error = ex_put_coord(exoid2, x, y, z); printf("after ex_put_coord, error = %d\n", error); free(x); free(y); if (num_dim >= 3) free(z); /* read nodal coordinate names */ for (i = 0; i < num_dim; i++) { coord_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_coord_names(exoid, coord_names); printf("\nafter ex_get_coord_names, error = %3d\n", error); /* write nodal coordinate names */ error = ex_put_coord_names(exoid2, coord_names); printf("after ex_put_coord_names, error = %d\n", error); for (i = 0; i < num_dim; i++) { free(coord_names[i]); } /* read element order map */ elem_map = (int *)calloc(num_elem, sizeof(int)); error = ex_get_map(exoid, elem_map); printf("\nafter ex_get_map, error = %3d\n", error); /* write element order map */ error = ex_put_map(exoid2, elem_map); printf("after ex_put_map, error = %d\n", error); free(elem_map); /* read and write element block parameters and element connectivity */ ids = (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); attrib[0] = 3.14159; for (i = 0; i < num_elem_blk; i++) { error = ex_get_elem_block(exoid, ids[i], elem_type, &num_elem_in_block, &num_nodes_per_elem, &num_attr); printf("\nafter ex_get_elem_block, error = %d\n", error); error = ex_put_elem_block(exoid2, ids[i], elem_type, num_elem_in_block, num_nodes_per_elem, num_attr); printf("after ex_put_elem_block, error = %d\n", error); connect = (int *)calloc((num_nodes_per_elem * num_elem_in_block), sizeof(int)); error = ex_get_elem_conn(exoid, ids[i], connect); printf("\nafter ex_get_elem_conn, error = %d\n", error); error = ex_put_elem_conn(exoid2, ids[i], connect); printf("after ex_put_elem_conn, error = %d\n", error); /* write element block attributes */ error = ex_put_attr(exoid2, EX_ELEM_BLOCK, ids[i], attrib); printf("after ex_put_elem_attr, error = %d\n", error); free(connect); } /* read and write element block properties */ error = ex_inquire(exoid, EX_INQ_EB_PROP, &num_props, &fdum, cdum); printf("\nafter ex_inquire, error = %d\n", error); for (i = 0; i < num_props; i++) { prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_prop_names(exoid, EX_ELEM_BLOCK, prop_names); printf("after ex_get_prop_names, error = %d\n", error); error = ex_put_prop_names(exoid2, EX_ELEM_BLOCK, num_props, prop_names); printf("after ex_put_prop_names, error = %d\n", error); for (i = 0; i < num_props; i++) { for (j = 0; j < num_elem_blk; j++) { error = ex_get_prop(exoid, EX_ELEM_BLOCK, ids[j], prop_names[i], &prop_value); printf("after ex_get_prop, error = %d\n", error); if (i > 0) { /* first property is the ID which is already stored */ error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ids[j], prop_names[i], prop_value); printf("after ex_put_prop, error = %d\n", error); } } } for (i = 0; i < num_props; i++) free(prop_names[i]); free(ids); /* read and write individual node sets */ 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 < num_node_sets; i++) { error = ex_get_node_set_param(exoid, ids[i], &num_nodes_in_set, &num_df_in_set); printf("\nafter ex_get_node_set_param, error = %3d\n", error); error = ex_put_node_set_param(exoid2, ids[i], num_nodes_in_set, num_df_in_set); printf("after ex_put_node_set_param, error = %d\n", error); node_list = (int *)calloc(num_nodes_in_set, sizeof(int)); dist_fact = (float *)calloc(num_nodes_in_set, sizeof(float)); error = ex_get_node_set(exoid, ids[i], node_list); printf("\nafter ex_get_node_set, error = %3d\n", error); error = ex_put_node_set(exoid2, ids[i], node_list); printf("after ex_put_node_set, error = %d\n", error); if (num_df_in_set > 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); error = ex_put_node_set_dist_fact(exoid2, ids[i], dist_fact); printf("after ex_put_node_set, error = %d\n", error); } free(node_list); free(dist_fact); } free(ids); /* read node set properties */ error = ex_inquire(exoid, EX_INQ_NS_PROP, &num_props, &fdum, cdum); printf("\nafter ex_inquire, error = %d\n", error); for (i = 0; i < num_props; i++) { prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } prop_values = (int *)calloc(num_node_sets, sizeof(int)); error = ex_get_prop_names(exoid, EX_NODE_SET, prop_names); printf("after ex_get_prop_names, error = %d\n", error); error = ex_put_prop_names(exoid2, EX_NODE_SET, num_props, prop_names); printf("after ex_put_prop_names, error = %d\n", error); for (i = 0; i < num_props; i++) { error = ex_get_prop_array(exoid, EX_NODE_SET, prop_names[i], prop_values); printf("after ex_get_prop_array, error = %d\n", error); error = ex_put_prop_array(exoid2, EX_NODE_SET, prop_names[i], prop_values); printf("after ex_put_prop_array, error = %d\n", error); } for (i = 0; i < num_props; i++) free(prop_names[i]); free(prop_values); /* read and write individual side sets */ 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 < num_side_sets; i++) { error = ex_get_side_set_param(exoid, ids[i], &num_sides_in_set, &num_df_in_set); printf("\nafter ex_get_side_set_param, error = %3d\n", error); error = ex_put_side_set_param(exoid2, ids[i], num_sides_in_set, num_df_in_set); printf("after ex_put_side_set_param, error = %d\n", error); /* Note: The # of elements is same as # of sides! */ num_elem_in_set = num_sides_in_set; elem_list = (int *)calloc(num_elem_in_set, sizeof(int)); side_list = (int *)calloc(num_sides_in_set, sizeof(int)); node_ctr_list = (int *)calloc(num_elem_in_set, sizeof(int)); node_list = (int *)calloc(num_elem_in_set * 21, sizeof(int)); dist_fact = (float *)calloc(num_df_in_set, sizeof(float)); error = ex_get_side_set(exoid, ids[i], elem_list, side_list); printf("\nafter ex_get_side_set, error = %3d\n", error); error = ex_put_side_set(exoid2, ids[i], elem_list, side_list); printf("after ex_put_side_set, error = %d\n", error); error = ex_get_side_set_node_list(exoid, ids[i], node_ctr_list, node_list); printf("\nafter ex_get_side_set_node_list, error = %3d\n", error); if (num_df_in_set > 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); error = ex_put_side_set_dist_fact(exoid2, ids[i], dist_fact); printf("after ex_put_side_set_dist_fact, error = %d\n", error); } free(elem_list); free(side_list); free(node_ctr_list); free(node_list); free(dist_fact); } /* read side set properties */ error = ex_inquire(exoid, EX_INQ_SS_PROP, &num_props, &fdum, cdum); printf("\nafter ex_inquire, error = %d\n", error); for (i = 0; i < num_props; i++) { prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_prop_names(exoid, EX_SIDE_SET, prop_names); printf("after ex_get_prop_names, error = %d\n", error); for (i = 0; i < num_props; i++) { for (j = 0; j < num_side_sets; j++) { error = ex_get_prop(exoid, EX_SIDE_SET, ids[j], prop_names[i], &prop_value); printf("after ex_get_prop, error = %d\n", error); if (i > 0) { /* first property is ID so it is already stored */ error = ex_put_prop(exoid2, EX_SIDE_SET, ids[j], prop_names[i], prop_value); printf("after ex_put_prop, error = %d\n", error); } } } for (i = 0; i < num_props; i++) free(prop_names[i]); free(ids); /* read and write QA records */ ex_inquire(exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum); for (i = 0; i < num_qa_rec; i++) { for (j = 0; j < 4; j++) { qa_record[i][j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } } error = ex_get_qa(exoid, qa_record); printf("\nafter ex_get_qa, error = %3d\n", error); error = ex_put_qa(exoid2, num_qa_rec, qa_record); printf("after ex_put_qa, error = %d\n", error); for (i = 0; i < num_qa_rec; i++) { for (j = 0; j < 4; j++) { free(qa_record[i][j]); } } /* read and write information records */ error = ex_inquire(exoid, EX_INQ_INFO, &num_info, &fdum, cdum); printf("\nafter ex_inquire, error = %3d\n", error); for (i = 0; i < num_info; i++) { info[i] = (char *)calloc((MAX_LINE_LENGTH + 1), sizeof(char)); } error = ex_get_info(exoid, info); printf("\nafter ex_get_info, error = %3d\n", error); error = ex_put_info(exoid2, num_info, info); printf("after ex_put_info, error = %d\n", error); for (i = 0; i < num_info; i++) { free(info[i]); } /* close the EXODUS files */ error = ex_close(exoid); printf("after ex_close, error = %d\n", error); error = ex_close(exoid2); printf("after ex_close (2), error = %d\n", error); return 0; }
static int ex_inquire_internal (int exoid, int req_info, int64_t *ret_int, float *ret_float, char *ret_char) { int dimid, varid, tmp_num; void_int *ids = NULL; size_t i; size_t ldum = 0; size_t num_sets, idum; int *stat_vals; char errmsg[MAX_ERR_LENGTH]; int status; char tmp_title[2048]; exerrval = 0; /* clear error code */ if (ret_char) *ret_char = '\0'; /* Only needs to be non-null for TITLE */ if (!ret_int) { exerrval = EX_BADPARAM; sprintf(errmsg, "Warning: integer argument is NULL which is not allowed."); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } switch (req_info) { case EX_INQ_FILE_TYPE: /* obsolete call */ /*returns "r" for regular EXODUS II file or "h" for history EXODUS file*/ exerrval = EX_BADPARAM; sprintf(errmsg, "Warning: file type inquire is obsolete"); ex_err("ex_inquire",errmsg,exerrval); return (EX_WARN); case EX_INQ_API_VERS: /* returns the EXODUS II API version number */ if (!ret_float) { exerrval = EX_BADPARAM; sprintf(errmsg, "Warning: float argument is NULL for EX_INQ_API_VERS which is not allowed."); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (nc_get_att_float(exoid, NC_GLOBAL, ATT_API_VERSION, ret_float) != NC_NOERR) { /* try old (prior to db version 2.02) attribute name */ if ((status = nc_get_att_float (exoid, NC_GLOBAL, ATT_API_VERSION_BLANK,ret_float)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get EXODUS API version for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } } break; case EX_INQ_DB_VERS: /* returns the EXODUS II database version number */ if (!ret_float) { exerrval = EX_BADPARAM; sprintf(errmsg, "Warning: float argument is NULL for EX_INQ_DB_VERS which is not allowed."); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if ((status = nc_get_att_float (exoid, NC_GLOBAL, ATT_VERSION, ret_float)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get EXODUS database version for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } break; case EX_INQ_LIB_VERS: /* returns the EXODUS II Library version number */ if (ret_float) flt_cvt(ret_float, EX_API_VERS); *ret_int = EX_API_VERS_NODOT; break; case EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH: /* Return the MAX_NAME_LENGTH size for this database It will not include the space for the trailing null, so if it is defined as 33 on the database, 32 will be returned. */ if ((status = nc_inq_dimid(exoid, DIM_STR_NAME, &dimid)) != NC_NOERR) { /* If not found, then an older database */ *ret_int = 32; } else { /* Get the name string length */ size_t name_length = 0; if ((status = nc_inq_dimlen(exoid,dimid,&name_length)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get name string length in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } else { *ret_int = name_length-1; } } break; case EX_INQ_DB_MAX_USED_NAME_LENGTH: /* Return the value of the ATT_MAX_NAME_LENGTH attribute (if it exists) which is the maximum length of any entity, variable, attribute, property name written to this database. If the attribute does not exist, then '32' is returned. The length does not include the trailing null. */ { nc_type att_type = NC_NAT; size_t att_len = 0; *ret_int = 32; /* Default size consistent with older databases */ status = nc_inq_att(exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, &att_type, &att_len); if (status == NC_NOERR && att_type == NC_INT) { /* The attribute exists, return it... */ nc_get_att_longlong(exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, (long long*)ret_int); } } break; case EX_INQ_MAX_READ_NAME_LENGTH: { /* Returns the user-specified maximum size of names that will be * returned to the user by any of the ex_get_ routines. If the * name is longer than this value, it will be truncated. The * default if not set by the client is 32 characters. The value * does not include the trailing null. */ struct file_item* file = ex_find_file_item(exoid); if (!file ) { exerrval = EX_BADFILEID; sprintf(errmsg,"Error: unknown file id %d for ex_inquire_int().",exoid); ex_err("ex_intquire",errmsg,exerrval); *ret_int = 0; } else { *ret_int = file->maximum_name_length; } } break; case EX_INQ_TITLE: if (!ret_char) { sprintf(errmsg, "Error: Requested title, but character pointer was null for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } else { /* returns the title of the database */ if ((status = nc_get_att_text (exoid, NC_GLOBAL, ATT_TITLE, tmp_title)) != NC_NOERR) { *ret_char = '\0'; exerrval = status; sprintf(errmsg, "Error: failed to get database title for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } else { strncpy(ret_char, tmp_title, MAX_LINE_LENGTH+1); ret_char[MAX_LINE_LENGTH] = '\0'; } } break; case EX_INQ_DIM: /* returns the dimensionality (2 or 3, for 2-d or 3-d) of the database */ if (ex_get_dimension(exoid, DIM_NUM_DIM, "database dimensionality", &ldum, &dimid, "ex_inquire") != NC_NOERR) return EX_FATAL; *ret_int = ldum; break; case EX_INQ_NODES: /* returns the number of nodes */ if (ex_get_dimension(exoid, DIM_NUM_NODES, "nodes", &ldum, &dimid, NULL) != NC_NOERR) *ret_int = 0; else *ret_int = ldum; break; case EX_INQ_ELEM: /* returns the number of elements */ if (ex_get_dimension(exoid, DIM_NUM_ELEM, "elements", &ldum, &dimid, NULL) != NC_NOERR) *ret_int = 0; else *ret_int = ldum; break; case EX_INQ_ELEM_BLK: /* returns the number of element blocks */ if (ex_get_dimension(exoid, DIM_NUM_EL_BLK, "element blocks", &ldum, &dimid, NULL) != NC_NOERR) *ret_int = 0; else *ret_int = ldum; break; case EX_INQ_NODE_SETS: /* returns the number of node sets */ if (ex_get_dimension(exoid, DIM_NUM_NS, "node sets", &ldum, &dimid, NULL) != NC_NOERR) *ret_int = 0; else *ret_int = ldum; break; case EX_INQ_NS_NODE_LEN: /* returns the length of the concatenated node sets node list */ ex_get_concat_set_len(exoid, ret_int,"node",EX_NODE_SET,DIM_NUM_NS,VAR_NS_STAT,"num_nod_ns",0); break; case EX_INQ_NS_DF_LEN: /* returns the length of the concatenated node sets dist factor list */ /* Determine the concatenated node sets distribution factor length: 2. Check see if the dist factor variable for a node set id exists. 3. If it exists, goto step 4, else the length is zero. 4. Get the dimension of the number of nodes in the node set -0 use this value as the length as by definition they are the same. 5. Sum the individual lengths for the total list length. */ *ret_int = 0; /* default value if no node sets defined */ if (nc_inq_dimid (exoid, DIM_NUM_NS, &dimid) == NC_NOERR) { if ((status = nc_inq_dimlen(exoid, dimid, &num_sets)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of node sets in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } for (i=0; i<num_sets; i++) { if ((status = nc_inq_varid (exoid, VAR_FACT_NS(i+1), &varid)) != NC_NOERR) { if (status == NC_ENOTVAR) { idum = 0; /* this dist factor doesn't exist */ } else { *ret_int = 0; exerrval = status; sprintf(errmsg, "Error: failed to locate number of dist fact for %"ST_ZU"'th node set in file id %d", i, exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } } else { if ((status = nc_inq_dimid (exoid, DIM_NUM_NOD_NS(i+1), &dimid)) != NC_NOERR) { *ret_int = 0; exerrval = status; sprintf(errmsg, "Error: failed to locate number of nodes in %"ST_ZU"'th node set in file id %d", i, exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if ((status = nc_inq_dimlen (exoid, dimid, &idum)) != NC_NOERR) { *ret_int = 0; exerrval = status; sprintf(errmsg, "Error: failed to get number of nodes in %"ST_ZU"'th node set in file id %d", i,exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } } *ret_int += idum; } } break; case EX_INQ_SIDE_SETS: /* returns the number of side sets */ if (ex_get_dimension(exoid, DIM_NUM_SS, "side sets", &ldum, &dimid, NULL) != NC_NOERR) *ret_int = 0; else *ret_int = ldum; break; case EX_INQ_SS_NODE_LEN: /* returns the length of the concatenated side sets node list */ *ret_int = 0; /* default return value */ if (nc_inq_dimid (exoid, DIM_NUM_SS, &dimid) == NC_NOERR) { if ((status = nc_inq_dimlen(exoid, dimid, &num_sets)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of side sets in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (!(ids = malloc(num_sets*sizeof(int64_t)))) { /* May be getting 2x what is needed, but should be OK */ exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate memory for side set ids for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } if (ex_get_side_set_ids (exoid, ids) == EX_FATAL) { sprintf(errmsg, "Error: failed to get side set ids in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); free(ids); return (EX_FATAL); } /* allocate space for stat array */ if (!(stat_vals = malloc((int)num_sets*sizeof(int)))) { exerrval = EX_MEMFAIL; free (ids); sprintf(errmsg, "Error: failed to allocate memory for side set status array for file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } /* get variable id of status array */ if ((status = nc_inq_varid (exoid, VAR_SS_STAT, &varid)) == NC_NOERR) { /* if status array exists, use it, otherwise assume, object exists to be backward compatible */ if ((status = nc_get_var_int(exoid, varid, stat_vals)) != NC_NOERR) { exerrval = status; free (ids); free(stat_vals); sprintf(errmsg, "Error: failed to get element block status array from file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } } else /* default: status is true */ for(i=0;i<num_sets;i++) stat_vals[i]=1; /* walk id list, get each side set node length and sum for total */ for (i=0; i<num_sets; i++) { ex_entity_id id; if (stat_vals[i] == 0) /* is this object null? */ continue; if (ex_int64_status(exoid) & EX_IDS_INT64_API) id = ((int64_t*)ids)[i]; else id = ((int*)ids)[i]; if ((status = ex_get_side_set_node_list_len(exoid, id, &tmp_num)) != NC_NOERR) { *ret_int = 0; exerrval = status; sprintf(errmsg, "Error: failed to side set %"PRId64" node length in file id %d", id,exoid); ex_err("ex_inquire",errmsg,exerrval); free(stat_vals); free(ids); return (EX_FATAL); } *ret_int += tmp_num; } free(stat_vals); free (ids); } break; case EX_INQ_SS_ELEM_LEN: /* returns the length of the concatenated side sets element list */ ex_get_concat_set_len(exoid, ret_int,"side",EX_SIDE_SET,DIM_NUM_SS,VAR_SS_STAT,"num_side_ss",0); break; case EX_INQ_SS_DF_LEN: /* returns the length of the concatenated side sets dist factor list */ /* Determine the concatenated side sets distribution factor length: 1. Get the side set ids list. 2. Check see if the dist factor dimension for a side set id exists. 3. If it exists, goto step 4, else set the individual length to zero. 4. Sum the dimension value into the running total length. */ *ret_int = 0; /* first check see if any side sets exist */ if (nc_inq_dimid (exoid, DIM_NUM_SS, &dimid) == NC_NOERR) { if ((status = nc_inq_dimlen (exoid, dimid, &num_sets)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of side sets in file id %d", exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } for (i=0; i<num_sets; i++) { if ((status = nc_inq_dimid (exoid, DIM_NUM_DF_SS(i+1), &dimid)) != NC_NOERR) { if (status == NC_EBADDIM) { ldum = 0; /* this dist factor doesn't exist */ } else { *ret_int = 0; exerrval = status; sprintf(errmsg, "Error: failed to locate number of dist fact for %"ST_ZU"'th side set in file id %d", i, exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } } else { if ((status = nc_inq_dimlen (exoid, dimid, &ldum)) != NC_NOERR) { *ret_int = 0; exerrval = status; sprintf(errmsg, "Error: failed to get number of dist factors in %"ST_ZU"'th side set in file id %d", i, exoid); ex_err("ex_inquire",errmsg,exerrval); return (EX_FATAL); } } *ret_int += ldum; } } break; case EX_INQ_QA: /* returns the number of QA records */ if (ex_get_dimension(exoid, DIM_NUM_QA, "QA records", &ldum, &dimid, NULL) != NC_NOERR) *ret_int = 0; else *ret_int = ldum; break; case EX_INQ_INFO: /* returns the number of information records */ if (ex_get_dimension(exoid, DIM_NUM_INFO, "info records", &ldum, &dimid, NULL) != NC_NOERR) *ret_int = 0; else *ret_int = ldum; break; case EX_INQ_TIME: /* returns the number of time steps stored in the database */ if (ex_get_dimension(exoid, DIM_TIME, "time dimension", &ldum, &dimid, "ex_inquire") != NC_NOERR) return EX_FATAL; *ret_int = ldum; break; case EX_INQ_EB_PROP: /* returns the number of element block properties */ *ret_int = ex_get_num_props (exoid, EX_ELEM_BLOCK); break; case EX_INQ_NS_PROP: /* returns the number of node set properties */ *ret_int = ex_get_num_props (exoid, EX_NODE_SET); break; case EX_INQ_SS_PROP: /* returns the number of side set properties */ *ret_int = ex_get_num_props (exoid, EX_SIDE_SET); break; case EX_INQ_ELEM_MAP: /* returns the number of element maps */ if (ex_get_dimension(exoid, DIM_NUM_EM, "element maps", &ldum, &dimid, NULL) != NC_NOERR) *ret_int = 0; else *ret_int = ldum; break; case EX_INQ_EM_PROP: /* returns the number of element map properties */ *ret_int = ex_get_num_props (exoid, EX_ELEM_MAP); break; case EX_INQ_NODE_MAP: /* returns the number of node maps */ if (ex_get_dimension(exoid, DIM_NUM_NM, "node maps", &ldum, &dimid, NULL) != NC_NOERR) *ret_int = 0; else *ret_int = ldum; break; case EX_INQ_NM_PROP: /* returns the number of node map properties */ *ret_int = ex_get_num_props (exoid, EX_NODE_MAP); break; case EX_INQ_EDGE: /* returns the number of edges (defined across all edge blocks). */ if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_EDGE, 1) != EX_NOERR) return EX_FATAL; break; case EX_INQ_EDGE_BLK: /* returns the number of edge blocks. */ if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_ED_BLK, 1) != EX_NOERR) return EX_FATAL; break; case EX_INQ_EDGE_SETS: /* returns the number of edge sets. */ if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_ES, 1) != EX_NOERR) return EX_FATAL; break; case EX_INQ_ES_LEN: /* returns the length of the concatenated edge set edge list. */ ex_get_concat_set_len(exoid, ret_int,"edge",EX_EDGE_SET,DIM_NUM_ES,VAR_ES_STAT,"num_edge_es",0); break; case EX_INQ_ES_DF_LEN: /* returns the length of the concatenated edge set distribution factor list. */ ex_get_concat_set_len(exoid, ret_int,"edge",EX_EDGE_SET,DIM_NUM_ES,VAR_ES_STAT,"num_df_es",1); break; case EX_INQ_EDGE_PROP: /* returns the number of integer properties stored for each edge block. This includes the "ID" property. */ *ret_int = ex_get_num_props( exoid, EX_EDGE_BLOCK ); break; case EX_INQ_ES_PROP: /* returns the number of integer properties stored for each edge set.. This includes the "ID" property */ *ret_int = ex_get_num_props( exoid, EX_EDGE_SET ); break; case EX_INQ_FACE: /* returns the number of faces (defined across all face blocks). */ if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FACE, 1) != EX_NOERR) return EX_FATAL; break; case EX_INQ_FACE_BLK: /* returns the number of face blocks. */ if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FA_BLK, 1) != EX_NOERR) return EX_FATAL; break; case EX_INQ_FACE_SETS: /* returns the number of face sets. */ if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FS, 1) != EX_NOERR) return EX_FATAL; break; case EX_INQ_FS_LEN: /* returns the length of the concatenated edge set edge list. */ ex_get_concat_set_len(exoid, ret_int,"face",EX_FACE_SET,DIM_NUM_FS,VAR_FS_STAT,"num_face_fs",0); break; case EX_INQ_FS_DF_LEN: /* returns the length of the concatenated edge set distribution factor list. */ ex_get_concat_set_len(exoid, ret_int,"face",EX_FACE_SET,DIM_NUM_FS,VAR_FS_STAT,"num_df_fs",1); break; case EX_INQ_FACE_PROP: /* returns the number of integer properties stored for each edge block. This includes the "ID" property. */ *ret_int = ex_get_num_props( exoid, EX_FACE_BLOCK ); break; case EX_INQ_FS_PROP: /* returns the number of integer properties stored for each edge set.. This includes the "ID" property */ *ret_int = ex_get_num_props( exoid, EX_FACE_SET ); break; case EX_INQ_ELEM_SETS: /* returns the number of element sets. */ if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_ELS, 1) != EX_NOERR) return EX_FATAL; break; case EX_INQ_ELS_LEN: /* returns the length of the concatenated element set element list. */ ex_get_concat_set_len(exoid, ret_int,"element",EX_ELEM_SET,DIM_NUM_ELS,VAR_ELS_STAT,"num_ele_els",0); break; case EX_INQ_ELS_DF_LEN: /* returns the length of the concatenated element set distribution factor list. */ ex_get_concat_set_len(exoid, ret_int,"element",EX_ELEM_SET,DIM_NUM_ELS,VAR_ELS_STAT,"num_df_els",1); break; case EX_INQ_ELS_PROP: /* returns the number of integer properties stored for each element set. */ *ret_int = ex_get_num_props( exoid, EX_ELEM_SET ); break; case EX_INQ_EDGE_MAP: /* returns the number of edge maps. */ if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_EDM, 1) != EX_NOERR) return EX_FATAL; break; case EX_INQ_FACE_MAP: /* returns the number of face maps. */ if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FAM, 1) != EX_NOERR) return EX_FATAL; break; case EX_INQ_COORD_FRAMES: /* return the number of coordinate frames */ if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_CFRAMES, 1) != EX_NOERR) return EX_FATAL; break; default: *ret_int = 0; exerrval = EX_FATAL; sprintf(errmsg, "Error: invalid inquiry %d", req_info); ex_err("ex_inquire",errmsg,exerrval); return(EX_FATAL); } return (EX_NOERR); }
/*@ DMPlexCreateExodus - Create a DMPlex mesh from an ExodusII file ID. Collective on comm Input Parameters: + comm - The MPI communicator . exoid - The ExodusII id associated with a exodus file and obtained using ex_open - interpolate - Create faces and edges in the mesh Output Parameter: . dm - The DM object representing the mesh Level: beginner .keywords: mesh,ExodusII .seealso: DMPLEX, DMCreate() @*/ PetscErrorCode DMPlexCreateExodus(MPI_Comm comm, PetscInt exoid, PetscBool interpolate, DM *dm) { #if defined(PETSC_HAVE_EXODUSII) PetscMPIInt num_proc, rank; PetscSection coordSection; Vec coordinates; PetscScalar *coords; PetscInt coordSize, v; PetscErrorCode ierr; /* Read from ex_get_init() */ char title[PETSC_MAX_PATH_LEN+1]; int dim = 0, numVertices = 0, numCells = 0; int num_cs = 0, num_vs = 0, num_fs = 0; #endif PetscFunctionBegin; #if defined(PETSC_HAVE_EXODUSII) ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); ierr = MPI_Comm_size(comm, &num_proc);CHKERRQ(ierr); ierr = DMCreate(comm, dm);CHKERRQ(ierr); ierr = DMSetType(*dm, DMPLEX);CHKERRQ(ierr); /* Open EXODUS II file and read basic informations on rank 0, then broadcast to all processors */ if (!rank) { ierr = PetscMemzero(title,(PETSC_MAX_PATH_LEN+1)*sizeof(char));CHKERRQ(ierr); ierr = ex_get_init(exoid, title, &dim, &numVertices, &numCells, &num_cs, &num_vs, &num_fs); if (ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"ExodusII ex_get_init() failed with error code %D\n",ierr); if (!num_cs) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Exodus file does not contain any cell set\n"); } ierr = MPI_Bcast(title, PETSC_MAX_PATH_LEN+1, MPI_CHAR, 0, comm);CHKERRQ(ierr); ierr = MPI_Bcast(&dim, 1, MPI_INT, 0, comm);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) *dm, title);CHKERRQ(ierr); ierr = DMSetDimension(*dm, dim);CHKERRQ(ierr); ierr = DMPlexSetChart(*dm, 0, numCells+numVertices);CHKERRQ(ierr); /* Read cell sets information */ if (!rank) { PetscInt *cone; int c, cs, c_loc, v, v_loc; /* Read from ex_get_elem_blk_ids() */ int *cs_id; /* Read from ex_get_elem_block() */ char buffer[PETSC_MAX_PATH_LEN+1]; int num_cell_in_set, num_vertex_per_cell, num_attr; /* Read from ex_get_elem_conn() */ int *cs_connect; /* Get cell sets IDs */ ierr = PetscMalloc1(num_cs, &cs_id);CHKERRQ(ierr); ierr = ex_get_elem_blk_ids(exoid, cs_id);CHKERRQ(ierr); /* Read the cell set connectivity table and build mesh topology EXO standard requires that cells in cell sets be numbered sequentially and be pairwise disjoint. */ /* First set sizes */ for (cs = 0, c = 0; cs < num_cs; cs++) { ierr = ex_get_elem_block(exoid, cs_id[cs], buffer, &num_cell_in_set, &num_vertex_per_cell, &num_attr);CHKERRQ(ierr); for (c_loc = 0; c_loc < num_cell_in_set; ++c_loc, ++c) { ierr = DMPlexSetConeSize(*dm, c, num_vertex_per_cell);CHKERRQ(ierr); } } ierr = DMSetUp(*dm);CHKERRQ(ierr); for (cs = 0, c = 0; cs < num_cs; cs++) { ierr = ex_get_elem_block(exoid, cs_id[cs], buffer, &num_cell_in_set, &num_vertex_per_cell, &num_attr);CHKERRQ(ierr); ierr = PetscMalloc2(num_vertex_per_cell*num_cell_in_set,&cs_connect,num_vertex_per_cell,&cone);CHKERRQ(ierr); ierr = ex_get_elem_conn(exoid, cs_id[cs], cs_connect);CHKERRQ(ierr); /* EXO uses Fortran-based indexing, sieve uses C-style and numbers cell first then vertices. */ for (c_loc = 0, v = 0; c_loc < num_cell_in_set; ++c_loc, ++c) { for (v_loc = 0; v_loc < num_vertex_per_cell; ++v_loc, ++v) { cone[v_loc] = cs_connect[v]+numCells-1; } if (dim == 3) { /* Tetrahedra are inverted */ if (num_vertex_per_cell == 4) { PetscInt tmp = cone[0]; cone[0] = cone[1]; cone[1] = tmp; } /* Hexahedra are inverted */ if (num_vertex_per_cell == 8) { PetscInt tmp = cone[1]; cone[1] = cone[3]; cone[3] = tmp; } } ierr = DMPlexSetCone(*dm, c, cone);CHKERRQ(ierr); ierr = DMSetLabelValue(*dm, "Cell Sets", c, cs_id[cs]);CHKERRQ(ierr); } ierr = PetscFree2(cs_connect,cone);CHKERRQ(ierr); } ierr = PetscFree(cs_id);CHKERRQ(ierr); } ierr = DMPlexSymmetrize(*dm);CHKERRQ(ierr); ierr = DMPlexStratify(*dm);CHKERRQ(ierr); if (interpolate) { DM idm = NULL; ierr = DMPlexInterpolate(*dm, &idm);CHKERRQ(ierr); /* Maintain Cell Sets label */ { DMLabel label; ierr = DMRemoveLabel(*dm, "Cell Sets", &label);CHKERRQ(ierr); if (label) {ierr = DMAddLabel(idm, label);CHKERRQ(ierr);} } ierr = DMDestroy(dm);CHKERRQ(ierr); *dm = idm; } /* Create vertex set label */ if (!rank && (num_vs > 0)) { int vs, v; /* Read from ex_get_node_set_ids() */ int *vs_id; /* Read from ex_get_node_set_param() */ int num_vertex_in_set, num_attr; /* Read from ex_get_node_set() */ int *vs_vertex_list; /* Get vertex set ids */ ierr = PetscMalloc1(num_vs, &vs_id);CHKERRQ(ierr); ierr = ex_get_node_set_ids(exoid, vs_id);CHKERRQ(ierr); for (vs = 0; vs < num_vs; ++vs) { ierr = ex_get_node_set_param(exoid, vs_id[vs], &num_vertex_in_set, &num_attr);CHKERRQ(ierr); ierr = PetscMalloc1(num_vertex_in_set, &vs_vertex_list);CHKERRQ(ierr); ierr = ex_get_node_set(exoid, vs_id[vs], vs_vertex_list);CHKERRQ(ierr); for (v = 0; v < num_vertex_in_set; ++v) { ierr = DMSetLabelValue(*dm, "Vertex Sets", vs_vertex_list[v]+numCells-1, vs_id[vs]);CHKERRQ(ierr); } ierr = PetscFree(vs_vertex_list);CHKERRQ(ierr); } ierr = PetscFree(vs_id);CHKERRQ(ierr); } /* Read coordinates */ ierr = DMGetCoordinateSection(*dm, &coordSection);CHKERRQ(ierr); ierr = PetscSectionSetNumFields(coordSection, 1);CHKERRQ(ierr); ierr = PetscSectionSetFieldComponents(coordSection, 0, dim);CHKERRQ(ierr); ierr = PetscSectionSetChart(coordSection, numCells, numCells + numVertices);CHKERRQ(ierr); for (v = numCells; v < numCells+numVertices; ++v) { ierr = PetscSectionSetDof(coordSection, v, dim);CHKERRQ(ierr); ierr = PetscSectionSetFieldDof(coordSection, v, 0, dim);CHKERRQ(ierr); } ierr = PetscSectionSetUp(coordSection);CHKERRQ(ierr); ierr = PetscSectionGetStorageSize(coordSection, &coordSize);CHKERRQ(ierr); ierr = VecCreate(PETSC_COMM_SELF, &coordinates);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) coordinates, "coordinates");CHKERRQ(ierr); ierr = VecSetSizes(coordinates, coordSize, PETSC_DETERMINE);CHKERRQ(ierr); ierr = VecSetBlockSize(coordinates, dim);CHKERRQ(ierr); ierr = VecSetType(coordinates,VECSTANDARD);CHKERRQ(ierr); ierr = VecGetArray(coordinates, &coords);CHKERRQ(ierr); if (!rank) { float *x, *y, *z; ierr = PetscMalloc3(numVertices,&x,numVertices,&y,numVertices,&z);CHKERRQ(ierr); ierr = ex_get_coord(exoid, x, y, z);CHKERRQ(ierr); if (dim > 0) { for (v = 0; v < numVertices; ++v) coords[v*dim+0] = x[v]; } if (dim > 1) { for (v = 0; v < numVertices; ++v) coords[v*dim+1] = y[v]; } if (dim > 2) { for (v = 0; v < numVertices; ++v) coords[v*dim+2] = z[v]; } ierr = PetscFree3(x,y,z);CHKERRQ(ierr); } ierr = VecRestoreArray(coordinates, &coords);CHKERRQ(ierr); ierr = DMSetCoordinatesLocal(*dm, coordinates);CHKERRQ(ierr); ierr = VecDestroy(&coordinates);CHKERRQ(ierr); /* Create side set label */ if (!rank && interpolate && (num_fs > 0)) { int fs, f, voff; /* Read from ex_get_side_set_ids() */ int *fs_id; /* Read from ex_get_side_set_param() */ int num_side_in_set, num_dist_fact_in_set; /* Read from ex_get_side_set_node_list() */ int *fs_vertex_count_list, *fs_vertex_list; /* Get side set ids */ ierr = PetscMalloc1(num_fs, &fs_id);CHKERRQ(ierr); ierr = ex_get_side_set_ids(exoid, fs_id);CHKERRQ(ierr); for (fs = 0; fs < num_fs; ++fs) { ierr = ex_get_side_set_param(exoid, fs_id[fs], &num_side_in_set, &num_dist_fact_in_set);CHKERRQ(ierr); ierr = PetscMalloc2(num_side_in_set,&fs_vertex_count_list,num_side_in_set*4,&fs_vertex_list);CHKERRQ(ierr); ierr = ex_get_side_set_node_list(exoid, fs_id[fs], fs_vertex_count_list, fs_vertex_list);CHKERRQ(ierr); for (f = 0, voff = 0; f < num_side_in_set; ++f) { const PetscInt *faces = NULL; PetscInt faceSize = fs_vertex_count_list[f], numFaces; PetscInt faceVertices[4], v; if (faceSize > 4) SETERRQ1(comm, PETSC_ERR_ARG_WRONG, "ExodusII side cannot have %d > 4 vertices", faceSize); for (v = 0; v < faceSize; ++v, ++voff) { faceVertices[v] = fs_vertex_list[voff]+numCells-1; } ierr = DMPlexGetFullJoin(*dm, faceSize, faceVertices, &numFaces, &faces);CHKERRQ(ierr); if (numFaces != 1) SETERRQ3(comm, PETSC_ERR_ARG_WRONG, "Invalid ExodusII side %d in set %d maps to %d faces", f, fs, numFaces); ierr = DMSetLabelValue(*dm, "Face Sets", faces[0], fs_id[fs]);CHKERRQ(ierr); ierr = DMPlexRestoreJoin(*dm, faceSize, faceVertices, &numFaces, &faces);CHKERRQ(ierr); } ierr = PetscFree2(fs_vertex_count_list,fs_vertex_list);CHKERRQ(ierr); } ierr = PetscFree(fs_id);CHKERRQ(ierr); } #else SETERRQ(comm, PETSC_ERR_SUP, "This method requires ExodusII support. Reconfigure using --download-exodusii"); #endif PetscFunctionReturn(0); }
int ex_put_all_var_param (int exoid, int num_g, int num_n, int num_e, int *elem_var_tab, int num_m, int *nset_var_tab, int num_s, int *sset_var_tab) { int in_define = 0; int time_dim, num_nod_dim, dimid, iresult; long num_elem_blk, num_nset, num_sset; int numelblkdim, numelvardim, numnsetdim, nsetvardim, numssetdim, ssetvardim; int i; int eblk_varid, nset_varid, sset_varid; int *eblk_ids = 0; int *nset_ids = 0; int *sset_ids = 0; nclong *eblk_stat = 0; nclong *nset_stat = 0; nclong *sset_stat = 0; int dims[3]; char errmsg[MAX_ERR_LENGTH]; const char* routine = "ex_put_all_var_param"; exerrval = 0; /* clear error code */ /* inquire previously defined dimensions */ if ((time_dim = ncdimid (exoid, DIM_TIME)) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to locate time dimension in file id %d", exoid); ex_err("ex_put_all_var_param",errmsg,exerrval); goto error_ret; } if ((num_nod_dim = ncdimid (exoid, DIM_NUM_NODES)) == -1) { if (num_n > 0) { exerrval = ncerr; sprintf(errmsg, "Error: failed to locate number of nodes in file id %d", exoid); ex_err("ex_put_all_var_param",errmsg,exerrval); goto error_ret; } } /* Check this now so we can use it later without checking for errors */ if (ncdimid (exoid, DIM_STR) < 0) { exerrval = ncerr; sprintf(errmsg, "Error: failed to get string length in file id %d",exoid); ex_err("ex_put_all_var_param",errmsg,exerrval); goto error_ret; } if (num_e > 0) { numelblkdim = ex_get_dimension(exoid, DIM_NUM_EL_BLK, "element blocks", &num_elem_blk, routine); if (numelblkdim == -1) goto error_ret; /* get element block IDs */ if (!(eblk_ids = static_cast<int*>(malloc(num_elem_blk*sizeof(int))))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate memory for element block id array for file id %d", exoid); ex_err("ex_put_all_var_param",errmsg,exerrval); goto error_ret; } ex_get_elem_blk_ids (exoid, eblk_ids); /* Get element block status array for later use (allocates memory) */ eblk_stat = get_status_array(exoid, num_elem_blk, VAR_STAT_EL_BLK, "element block"); if (eblk_stat == NULL) { goto error_ret; } } if (num_m > 0) { numnsetdim = ex_get_dimension(exoid, DIM_NUM_NS, "nodesets", &num_nset, routine); if (numnsetdim == -1) goto error_ret; /* get nodeset IDs */ if (!(nset_ids = static_cast<int*>(malloc(num_nset*sizeof(int))))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate memory for nodeset id array for file id %d", exoid); ex_err("ex_put_all_var_param",errmsg,exerrval); goto error_ret; } ex_get_node_set_ids (exoid, nset_ids); /* Get nodeset status array for later use (allocates memory) */ nset_stat = get_status_array(exoid, num_nset, VAR_NS_STAT, "nodeset"); if (nset_stat == NULL) { goto error_ret; } } if (num_s > 0) { numssetdim = ex_get_dimension(exoid, DIM_NUM_SS, "sidesets", &num_sset, routine); if (numssetdim == -1) goto error_ret; /* get sideset IDs */ if (!(sset_ids = static_cast<int*>(malloc(num_sset*sizeof(int))))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate memory for sideset id array for file id %d", exoid); ex_err("ex_put_all_var_param",errmsg,exerrval); goto error_ret; } ex_get_side_set_ids (exoid, sset_ids); /* Get sideset status array for later use (allocates memory) */ sset_stat = get_status_array(exoid, num_sset, VAR_SS_STAT, "sideset"); if (sset_stat == NULL) { goto error_ret; } } /* put file into define mode */ if (ncredef (exoid) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to put file id %d into define mode", exoid); ex_err("ex_put_all_var_param",errmsg,exerrval); goto error_ret; } in_define = 1; /* define dimensions and variables */ if (num_g > 0) { dimid = define_dimension(exoid, DIM_NUM_GLO_VAR, num_g, "global"); if (dimid == -1) goto error_ret; dims[0] = time_dim; dims[1] = dimid; if ((ncvardef (exoid, VAR_GLO_VAR, nc_flt_code(exoid), 2, dims)) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to define global variables in file id %d", exoid); ex_err("ex_put_all_var_param",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } /* Now define global variable name variable */ if (define_variable_name_variable(exoid, VAR_NAME_GLO_VAR, dimid, "global") == -1) goto error_ret; } if (num_n > 0) { /* * There are two ways to store the nodal variables. The old way * * was a blob (#times,#vars,#nodes), but that was exceeding the * netcdf maximum dataset size for large models. The new way is * to store #vars separate datasets each of size (#times,#nodes) * * We want this routine to be capable of storing both formats * based on some external flag. Since the storage format of the * coordinates have also been changed, we key off of their * storage type to decide which method to use for nodal * variables. If the variable 'coord' is defined, then store old * way; otherwise store new. */ dimid = define_dimension(exoid, DIM_NUM_NOD_VAR, num_n, "nodal"); if (dimid == -1) goto error_ret; if (ex_large_model(exoid) == 0) { /* Old way */ dims[0] = time_dim; dims[1] = dimid; dims[2] = num_nod_dim; if ((ncvardef (exoid, VAR_NOD_VAR, nc_flt_code(exoid), 3, dims)) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to define nodal variables in file id %d", exoid); ex_err("ex_put_all_var_param",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } else { /* Store new way */ for (i = 1; i <= num_n; i++) { dims[0] = time_dim; dims[1] = num_nod_dim; if ((ncvardef (exoid, VAR_NOD_VAR_NEW(i), nc_flt_code(exoid), 2, dims)) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to define nodal variable %d in file id %d", i, exoid); ex_err("ex_put_var_param",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } } /* Now define nodal variable name variable */ if (define_variable_name_variable(exoid, VAR_NAME_NOD_VAR, dimid, "nodal") == -1) goto error_ret; } if (num_e > 0) { numelvardim = define_dimension(exoid, DIM_NUM_ELE_VAR, num_e, "element"); if (numelvardim == -1) goto error_ret; /* Now define element variable name variable */ if (define_variable_name_variable(exoid, VAR_NAME_ELE_VAR, numelvardim, "element") == -1) goto error_ret; if (define_truth_table('e', exoid, num_elem_blk, num_e, elem_var_tab, eblk_stat, eblk_ids, "element block") == -1) goto error_ret; eblk_stat = static_cast<nclong*>(safe_free (eblk_stat)); eblk_ids = static_cast<int*>( safe_free (eblk_ids)); /* create a variable array in which to store the element variable truth * table */ dims[0] = numelblkdim; dims[1] = numelvardim; if ((eblk_varid = ncvardef (exoid, VAR_ELEM_TAB, NC_LONG, 2, dims)) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to define element variable truth table in file id %d", exoid); ex_err("ex_put_all_var_param",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } if (num_m > 0) { nsetvardim = define_dimension(exoid, DIM_NUM_NSET_VAR, num_m, "nodeset"); if (nsetvardim == -1) goto error_ret; /* Now define nodeset variable name variable */ if (define_variable_name_variable(exoid, VAR_NAME_NSET_VAR, nsetvardim, "nodeset") == -1) goto error_ret; if (define_truth_table('m', exoid, num_nset, num_m, nset_var_tab, nset_stat, nset_ids, "nodeset") == -1) goto error_ret; nset_stat = static_cast<nclong*>(safe_free (nset_stat)); nset_ids = static_cast<int*>(safe_free (nset_ids)); /* create a variable array in which to store the truth table */ dims[0] = numnsetdim; dims[1] = nsetvardim; if ((nset_varid = ncvardef (exoid, VAR_NSET_TAB, NC_LONG, 2, dims)) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to define nodeset variable truth table in file id %d", exoid); ex_err("ex_put_all_var_param",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } if (num_s > 0) { ssetvardim = define_dimension(exoid, DIM_NUM_SSET_VAR, num_s, "sideset"); if (ssetvardim == -1) goto error_ret; /* Now define sideset variable name variable */ if (define_variable_name_variable(exoid, VAR_NAME_SSET_VAR, ssetvardim, "sideset") == -1) goto error_ret; if (define_truth_table('s', exoid, num_sset, num_s, sset_var_tab, sset_stat, sset_ids, "sideset") == -1) goto error_ret; sset_stat = static_cast<nclong*>(safe_free (sset_stat)); sset_ids = static_cast<int*>(safe_free (sset_ids)); /* create a variable array in which to store the truth table */ dims[0] = numssetdim; dims[1] = ssetvardim; if ((sset_varid = ncvardef (exoid, VAR_SSET_TAB, NC_LONG, 2, dims)) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to define sideset variable truth table in file id %d", exoid); ex_err("ex_put_all_var_param",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } /* leave define mode */ in_define = 0; if (ncendef (exoid) == -1) { exerrval = ncerr; sprintf(errmsg, "Error: failed to complete definition in file id %d", exoid); ex_err("ex_put_all_var_param",errmsg,exerrval); goto error_ret; } /* write out the variable truth tables */ if (num_e > 0) { iresult = put_truth_table(exoid, num_elem_blk, num_e, eblk_varid, elem_var_tab, "element"); if (iresult == -1) goto error_ret; } if (num_m > 0) { iresult = put_truth_table(exoid, num_nset, num_m, nset_varid, nset_var_tab, "nodeset"); if (iresult == -1) goto error_ret; } if (num_s > 0) { iresult = put_truth_table(exoid, num_sset, num_s, sset_varid, sset_var_tab, "sideset"); if (iresult == -1) goto error_ret; } return(EX_NOERR); /* Fatal error: exit definition mode and return */ error_ret: if (in_define == 1) { if (ncendef (exoid) == -1) /* exit define mode */ { sprintf(errmsg, "Error: failed to complete definition for file id %d", exoid); ex_err("ex_put_all_var_param",errmsg,exerrval); } } safe_free(eblk_ids); safe_free(nset_ids); safe_free(sset_ids); safe_free(eblk_stat); safe_free(nset_stat); safe_free(sset_stat); return(EX_FATAL); }
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 *connect, *node_list, *node_ctr_list, *elem_list, *side_list; int *ids; int *num_elem_per_set; int *num_df_per_set; int *elem_ind, *df_ind; int *num_elem_in_block, *num_nodes_per_elem, *num_attr; int num_elem_in_set; int num_sides_in_set, num_df_in_set; int elem_list_len = 0; int node_list_len = 0; int df_list_len = 0; int CPU_word_size,IO_word_size; int idum; float *dist_fact; float version, fdum; char title[MAX_LINE_LENGTH+1], elem_type[MAX_STR_LENGTH+1]; char *cdum = 0; 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); /* ncopts = NC_VERBOSE; */ /* 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); /* read element block parameters */ 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<num_elem_blk; i++) { error = ex_get_elem_block (exoid, ids[i], elem_type, &(num_elem_in_block[i]), &(num_nodes_per_elem[i]), &(num_attr[i])); printf ("\nafter ex_get_elem_block, error = %d\n", error); printf ("element block id = %2d\n",ids[i]); printf ("element type = '%s'\n", elem_type); printf ("num_elem_in_block = %2d\n",num_elem_in_block[i]); printf ("num_nodes_per_elem = %2d\n",num_nodes_per_elem[i]); printf ("num_attr = %2d\n",num_attr[i]); } /* read element connectivity */ for (i=0; i<num_elem_blk; i++) { 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<num_nodes_per_elem[i]; j++) { printf ("%3d\n", connect[j]); } free (connect); } free(ids); free(num_elem_in_block); free(num_nodes_per_elem); free(num_attr); /* read individual side sets */ 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<num_side_sets; i++) { error = ex_get_side_set_param (exoid, ids[i], &num_sides_in_set, &num_df_in_set); printf ("\nafter ex_get_side_set_param, error = %3d\n", error); printf ("side set %2d parameters:\n",ids[i]); printf ("num_sides = %3d\n",num_sides_in_set); printf ("num_dist_factors = %3d\n", num_df_in_set); /* Note: The # of elements is same as # of sides! */ num_elem_in_set = num_sides_in_set; elem_list = (int *) calloc(num_elem_in_set, sizeof(int)); side_list = (int *) calloc(num_sides_in_set, sizeof(int)); node_ctr_list = (int *) calloc(num_elem_in_set, sizeof(int)); node_list = (int *) calloc(num_elem_in_set*21, sizeof(int)); dist_fact = (float *) calloc(num_df_in_set, sizeof(float)); error = ex_get_side_set (exoid, ids[i], elem_list, side_list); printf ("\nafter ex_get_side_set, error = %3d\n", error); error = ex_get_side_set_node_list (exoid, ids[i], node_ctr_list, node_list); printf ("\nafter ex_get_side_set_node_list, error = %3d\n", error); if (num_df_in_set > 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<num_elem_in_set; j++) { printf ("%3d\n", elem_list[j]); } printf ("side list for side set %2d\n", ids[i]); for (j=0; j<num_sides_in_set; j++) { printf ("%3d\n", side_list[j]); } node_ctr = 0; printf ("node list for side set %2d\n", ids[i]); for (k=0; k<num_elem_in_set; k++) { printf ("%3d nodes for side %3d\n", node_ctr_list[k], k); for (j=0; j<node_ctr_list[k]; j++) { printf ("%3d\n", node_list[node_ctr+j]); } node_ctr += node_ctr_list[k]; } if (num_df_in_set > 0) { printf ("dist factors for side set %2d\n", ids[i]); for (j=0; j<num_df_in_set; j++) { printf ("%5.3f\n", dist_fact[j]); } } else printf ("no dist factors for side set %2d\n", ids[i]); free (elem_list); free (side_list); free (node_ctr_list); free (node_list); free (dist_fact); } free(ids); if (num_side_sets > 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 */ 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<num_side_sets; i++) printf ("%3d\n", ids[i]); printf ("num_elem_per_set = \n"); for (i=0; i<num_side_sets; i++) printf ("%3d\n", num_elem_per_set[i]); printf ("num_dist_per_set = \n"); for (i=0; i<num_side_sets; i++) printf ("%3d\n", num_df_per_set[i]); printf ("elem_ind = \n"); for (i=0; i<num_side_sets; i++) printf ("%3d\n", elem_ind[i]); printf ("dist_ind = \n"); for (i=0; i<num_side_sets; i++) printf ("%3d\n", df_ind[i]); printf ("elem_list = \n"); for (i=0; i<elem_list_len; i++) printf ("%3d\n", elem_list[i]); printf ("side_list = \n"); for (i=0; i<elem_list_len; i++) printf ("%3d\n", side_list[i]); printf ("dist_fact = \n"); for (i=0; i<df_list_len; i++) printf ("%5.3f\n", dist_fact[i]); free (ids); free (num_elem_per_set); free (num_df_per_set); free (df_ind); free (elem_ind); free (elem_list); free (side_list); free (dist_fact); /* end of concatenated side set read */ error = ex_close (exoid); printf ("\nafter ex_close, error = %3d\n", error); return 0; }