int cReadEdgeFace(int argc, char *argv[]) { int exoid; int appWordSize = 8; int diskWordSize = 8; float exoVersion; int itmp[5]; int * ids; int nids; int obj; int i, j; int num_timesteps; int ti; char ** obj_names; char ** var_names; int have_var_names; int num_vars; /* number of variables per object */ int num_entries; /* number of values per variable per object */ double * entry_vals; /* variable values for each entry of an object */ ex_init_params modelParams; exoid = ex_open(EX_TEST_FILENAME, EX_READ, &appWordSize, &diskWordSize, &exoVersion); if (exoid <= 0) { fprintf(stderr, "Unable to open \"%s\" for reading.\n", EX_TEST_FILENAME); return 1; } EXCHECK(ex_get_init_ext(exoid, &modelParams), "Unable to read database parameters.\n"); fprintf(stdout, "Title: <%s>\n" "Dimension: %" PRId64 "\n" "Nodes: %" PRId64 "\n" "Edges: %" PRId64 "\n" "Faces: %" PRId64 "\n" "Elements: %" PRId64 "\n" "Edge Blocks: %" PRId64 "\n" "Face Blocks: %" PRId64 "\n" "Element Blocks: %" PRId64 "\n" "Node Sets: %" PRId64 "\n" "Edge Sets: %" PRId64 "\n" "Face Sets: %" PRId64 "\n" "Side Sets: %" PRId64 "\n" "Element Sets: %" PRId64 "\n" "Node Maps: %" PRId64 "\n" "Edge Maps: %" PRId64 "\n" "Face Maps: %" PRId64 "\n" "Element Maps: %" PRId64 "\n", modelParams.title, modelParams.num_dim, modelParams.num_nodes, modelParams.num_edge, modelParams.num_face, modelParams.num_elem, modelParams.num_edge_blk, modelParams.num_face_blk, modelParams.num_elem_blk, modelParams.num_node_sets, modelParams.num_edge_sets, modelParams.num_face_sets, modelParams.num_side_sets, modelParams.num_elem_sets, modelParams.num_node_maps, modelParams.num_edge_maps, modelParams.num_face_maps, modelParams.num_elem_maps); num_timesteps = ex_inquire_int(exoid, EX_INQ_TIME); /* *** NEW API *** */ for (i = 0; i < sizeof(obj_types) / sizeof(obj_types[0]); ++i) { int *truth_tab = 0; have_var_names = 0; EXCHECK(ex_inquire(exoid, obj_sizes[i], &nids, 0, 0), "Object ID list size could not be determined.\n"); if (!nids) { fprintf(stdout, "=== %ss: none\n\n", obj_typenames[i]); continue; } else { fprintf(stdout, "=== %ss: %d\n", obj_typenames[i], nids); } ids = (int *)malloc(nids * sizeof(int)); obj_names = (char **)malloc(nids * sizeof(char *)); for (obj = 0; obj < nids; ++obj) obj_names[obj] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char)); EXCHECK(ex_get_ids(exoid, obj_types[i], ids), "Could not read object ids.\n"); EXCHECK(ex_get_names(exoid, obj_types[i], obj_names), "Could not read object ids.\n"); if ((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) { int *tp; EXCHECK(ex_get_variable_param(exoid, obj_types[i], &num_vars), "Could not read number of variables.\n"); if (num_vars && num_timesteps > 0) { truth_tab = (int *)malloc(num_vars * nids * sizeof(int)); EXCHECK(ex_get_truth_table(exoid, obj_types[i], nids, num_vars, truth_tab), "Could not read truth table.\n"); tp = truth_tab; fprintf(stdout, "Truth:"); for (obj = 0; obj < nids; ++obj) { for (j = 0; j < num_vars; ++j, ++tp) { fprintf(stdout, " %d", *tp); } fprintf(stdout, "\n "); } fprintf(stdout, "\n"); var_names = (char **)malloc(num_vars * sizeof(char *)); for (j = 0; j < num_vars; ++j) var_names[j] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char)); EXCHECK(ex_get_variable_names(exoid, obj_types[i], num_vars, var_names), "Could not read variable names.\n"); have_var_names = 1; } } if (!have_var_names) var_names = 0; for (obj = 0; obj < nids; ++obj) { if (obj_names[obj]) fprintf(stdout, "%s %3d (%s): ", obj_typenames[i], ids[obj], obj_names[obj]); else fprintf(stdout, "%s %3d: ", obj_typenames[i], ids[obj]); if (OBJECT_IS_BLOCK(i)) { int *nconn; int *econn; int *fconn; int ele; int ctr; int num_attrs; if (obj_types[i] == EX_ELEM_BLOCK) { EXCHECK(ex_get_block(exoid, obj_types[i], ids[obj], 0, itmp, itmp + 1, itmp + 2, itmp + 3, &num_attrs), "Could not read block params.\n"); fprintf(stdout, "Entries: %3d Nodes/entry: %d Edges/entry: %d Faces/entry: %d Attributes: %d", itmp[0], itmp[1], itmp[2], itmp[3], num_attrs); } else { EXCHECK(ex_get_block(exoid, obj_types[i], ids[obj], 0, itmp, itmp + 1, 0, 0, &num_attrs), "Could not read block params.\n"); fprintf(stdout, "Entries: %3d Nodes/entry: %d Attributes: %d", itmp[0], itmp[1], num_attrs); itmp[2] = itmp[3] = 0; } fprintf(stdout, "\n "); num_entries = itmp[0]; nconn = itmp[1] ? (int *)malloc(itmp[1] * num_entries * sizeof(int)) : 0; econn = itmp[2] ? (int *)malloc(itmp[2] * num_entries * sizeof(int)) : 0; fconn = itmp[3] ? (int *)malloc(itmp[3] * num_entries * sizeof(int)) : 0; EXCHECK(ex_get_conn(exoid, obj_types[i], ids[obj], nconn, econn, fconn), "Could not read connectivity.\n"); for (ele = 0; ele < num_entries; ++ele) { for (ctr = 0; ctr < itmp[1]; ++ctr) { fprintf(stdout, " %2d", nconn[ele * itmp[1] + ctr]); } if (itmp[2]) { fprintf(stdout, " ++"); for (ctr = 0; ctr < itmp[2]; ++ctr) { fprintf(stdout, " %2d", econn[ele * itmp[2] + ctr]); } } if (itmp[3]) { fprintf(stdout, " ++"); for (ctr = 0; ctr < itmp[3]; ++ctr) { fprintf(stdout, " %2d", fconn[ele * itmp[3] + ctr]); } } fprintf(stdout, "\n "); } free(nconn); free(econn); free(fconn); if (num_attrs) { char ** attr_names; double *attr; attr = (double *)malloc(num_entries * num_attrs * sizeof(double)); attr_names = (char **)malloc(num_attrs * sizeof(char *)); for (j = 0; j < num_attrs; ++j) attr_names[j] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char)); EXCHECK(ex_get_attr_names(exoid, obj_types[i], ids[obj], attr_names), "Could not read attributes names.\n"); EXCHECK(ex_get_attr(exoid, obj_types[i], ids[obj], attr), "Could not read attribute values.\n"); fprintf(stdout, "\n Attributes:\n ID "); for (j = 0; j < num_attrs; ++j) fprintf(stdout, " %s", attr_names[j]); fprintf(stdout, "\n"); for (j = 0; j < num_entries; ++j) { int k; fprintf(stdout, " %2d ", j + 1); for (k = 0; k < num_attrs; ++k) { fprintf(stdout, " %4.1f", attr[j * num_attrs + k]); } fprintf(stdout, "\n"); } for (j = 0; j < num_attrs; ++j) free(attr_names[j]); free(attr_names); free(attr); } } else if (OBJECT_IS_SET(i)) { int num_df; int * set_entry; int * set_extra; double *set_df; EXCHECK(ex_get_set_param(exoid, obj_types[i], ids[obj], &num_entries, &num_df), "Could not read set parameters.\n"); set_entry = (int *)malloc(num_entries * sizeof(int)); set_extra = (obj_types[i] != EX_NODE_SET && obj_types[i] != EX_ELEM_SET) ? (int *)malloc(num_entries * sizeof(int)) : 0; EXCHECK(ex_get_set(exoid, obj_types[i], ids[obj], set_entry, set_extra), "Could not read set.\n"); fprintf(stdout, "Entries: %3d Distribution factors: %3d\n", num_entries, num_df); if (set_extra) { for (j = 0; j < num_entries; ++j) fprintf(stdout, " %2d %2d\n", set_entry[j], set_extra[j]); } else { for (j = 0; j < num_entries; ++j) fprintf(stdout, " %2d\n", set_entry[j]); } free(set_entry); free(set_extra); set_df = num_df ? (double *)malloc(num_df * sizeof(double)) : 0; if (set_df) { EXCHECK(ex_get_set_dist_fact(exoid, obj_types[i], ids[obj], set_df), "Could not read set distribution factors.\n"); fprintf(stdout, "\n Distribution factors:\n"); for (j = 0; j < num_df; ++j) fprintf(stdout, " %4.1f\n", set_df[j]); free(set_df); } } else { /* object is map */ int *map; switch (obj_types[i]) { case EX_NODE_MAP: num_entries = modelParams.num_nodes; break; case EX_EDGE_MAP: num_entries = modelParams.num_edge; break; case EX_FACE_MAP: num_entries = modelParams.num_face; break; case EX_ELEM_MAP: num_entries = modelParams.num_elem; break; default: num_entries = 0; } if (num_entries) { fprintf(stdout, "Entries: %3d\n :", num_entries); map = (int *)malloc(num_entries * sizeof(int)); EXCHECK(ex_get_num_map(exoid, obj_types[i], ids[obj], map), "Could not read map.\n"); for (j = 0; j < num_entries; ++j) { fprintf(stdout, " %d", map[j]); } } else { fprintf(stdout, "Entries: none"); } } fprintf(stdout, "\n"); /* Read results variables */ if (((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) && num_vars && num_timesteps > 0) { /* Print out all the time values to exercise get_var */ entry_vals = (double *)malloc(num_entries * sizeof(double)); for (j = 0; j < num_vars; ++j) { int k; if (!truth_tab[num_vars * obj + j]) continue; fprintf(stdout, " Variable: %s", var_names[j]); for (ti = 1; ti <= num_timesteps; ++ti) { EXCHECK(ex_get_var(exoid, ti, obj_types[i], 1 + j, ids[obj], num_entries, entry_vals), "Could not read variable values.\n"); fprintf(stdout, "\n @t%d ", ti); for (k = 0; k < num_entries; ++k) { fprintf(stdout, " %4.1f", entry_vals[k]); } } fprintf(stdout, "\n"); } fprintf(stdout, "\n"); free(entry_vals); } } if (((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) && num_vars && num_timesteps > 0) { /* Print out one element's time values to exercise get_var_time */ entry_vals = (double *)malloc(num_timesteps * sizeof(double)); EXCHECK(ex_inquire(exoid, obj_sizeinq[i], itmp, 0, 0), "Inquire failed.\n"); itmp[1] = 11; while (itmp[1] > itmp[0]) itmp[1] /= 2; for (j = 0; j < num_vars; ++j) { /* FIXME: This works for the dataset created by CreateEdgeFace, but not for any dataset in * general since * NULL truth table entries may mean the referenced elements don't have variable values. */ EXCHECK(ex_get_var_time(exoid, obj_types[i], j + 1, itmp[1], 1, num_timesteps, entry_vals), "Could not read variable over time.\n"); fprintf(stdout, " Variable over time: %s Entry: %3d ", var_names[j], itmp[1]); for (ti = 1; ti <= num_timesteps; ++ti) fprintf(stdout, " @t%d: %4.1f", ti, entry_vals[ti - 1]); fprintf(stdout, "\n"); } free(entry_vals); } if (var_names) { for (j = 0; j < num_vars; ++j) free(var_names[j]); free(var_names); } free(truth_tab); free(ids); for (obj = 0; obj < nids; ++obj) free(obj_names[obj]); free(obj_names); fprintf(stdout, "\n"); } EXCHECK(ex_close(exoid), "Unable to close database.\n"); return 0; }
int ex_put_prop_names (int exoid, ex_entity_type obj_type, int num_props, char **prop_names) { int status; int oldfill, temp; int i, propid, dimid, dims[1]; size_t name_length, prop_name_len; char name[MAX_VAR_NAME_LENGTH+1]; int vals[1]; int max_name_len = 0; char errmsg[MAX_ERR_LENGTH]; exerrval = 0; /* clear error code */ /* Get the name string length */ name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH)+1; /* inquire id of previously defined dimension (number of objects) */ if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(obj_type), &dimid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate number of %s in file id %d", ex_name_of_object(obj_type), exoid); ex_err("ex_put_prop_names",errmsg, exerrval); return(EX_FATAL); } nc_set_fill(exoid, NC_FILL, &oldfill); /* fill with zeros per routine spec */ /* put netcdf file into define mode */ if ((status = nc_redef (exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid); ex_err("ex_put_prop_names",errmsg,exerrval); return (EX_FATAL); } /* define num_props variables; we postpend the netcdf variable name with */ /* a counter starting at 2 because "xx_prop1" is reserved for the id array*/ dims[0] = dimid; for (i=0; i<num_props; i++) { switch (obj_type) { case EX_ELEM_BLOCK: strcpy (name, VAR_EB_PROP(i+2)); break; case EX_FACE_BLOCK: strcpy (name, VAR_FA_PROP(i+2)); break; case EX_EDGE_BLOCK: strcpy (name, VAR_ED_PROP(i+2)); break; case EX_NODE_SET: strcpy (name, VAR_NS_PROP(i+2)); break; case EX_SIDE_SET: strcpy (name, VAR_SS_PROP(i+2)); break; case EX_EDGE_SET: strcpy (name, VAR_ES_PROP(i+2)); break; case EX_FACE_SET: strcpy (name, VAR_FS_PROP(i+2)); break; case EX_ELEM_SET: strcpy (name, VAR_ELS_PROP(i+2)); break; case EX_ELEM_MAP: strcpy (name, VAR_EM_PROP(i+2)); break; case EX_FACE_MAP: strcpy (name, VAR_FAM_PROP(i+2)); break; case EX_EDGE_MAP: strcpy (name, VAR_EDM_PROP(i+2)); break; case EX_NODE_MAP: strcpy (name, VAR_NM_PROP(i+2)); break; default: exerrval = EX_BADPARAM; sprintf(errmsg, "Error: object type %d not supported; file id %d", obj_type, exoid); ex_err("ex_put_prop_names",errmsg,exerrval); goto error_ret; /* Exit define mode and return */ } if ((status = nc_def_var(exoid, name, NC_INT, 1, dims, &propid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create property array variable in file id %d", exoid); ex_err("ex_put_prop_names",errmsg,exerrval); goto error_ret; /* Exit define mode and return */ } vals[0] = 0; /* fill value */ /* create attribute to cause variable to fill with zeros per routine spec */ if ((status = nc_put_att_int(exoid, propid, _FillValue, NC_INT, 1, vals)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to create property name fill attribute in file id %d", exoid); ex_err("ex_put_prop_names",errmsg,exerrval); goto error_ret; /* Exit define mode and return */ } /* Check that the property name length is less than MAX_NAME_LENGTH */ prop_name_len = strlen(prop_names[i])+1; if (prop_name_len > name_length) { fprintf(stderr, "Warning: The property name '%s' is too long.\n\tIt will be truncated from %d to %d characters\n", prop_names[i], (int)prop_name_len-1, (int)name_length-1); prop_name_len = name_length; } if (prop_name_len > max_name_len) max_name_len = prop_name_len; /* store property name as attribute of property array variable */ if ((status = nc_put_att_text(exoid, propid, ATT_PROP_NAME, prop_name_len, prop_names[i])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store property name %s in file id %d", prop_names[i],exoid); ex_err("ex_put_prop_names",errmsg,exerrval); goto error_ret; /* Exit define mode and return */ } } /* leave define mode */ if ((status = nc_enddef(exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to leave define mode in file id %d", exoid); ex_err("ex_put_prop_names",errmsg,exerrval); return (EX_FATAL); } /* Update the maximum_name_length attribute on the file. */ ex_update_max_name_length(exoid, max_name_len-1); nc_set_fill(exoid, oldfill, &temp); /* default: turn off fill */ return (EX_NOERR); /* Fatal error: exit definition mode and return */ error_ret: if (nc_enddef (exoid) != NC_NOERR) { /* exit define mode */ sprintf(errmsg, "Error: failed to complete definition for file id %d", exoid); ex_err("ex_put_prop_names",errmsg,exerrval); } return (EX_FATAL); }
bool Excn::ExodusFile::initialize(const SystemInterface& si, int start_part, int part_count) { processorCount_ = si.processor_count(); // Total number processors partCount_ = part_count; // Total parts we are processing startPart_ = start_part; // Which one to start with SMART_ASSERT(partCount_ + startPart_ <= processorCount_)(partCount_)(startPart_)(processorCount_); // EPU always wants entity (block, set, map) ids as 64-bit quantities... mode64bit_ = EX_IDS_INT64_API; if (si.int64()) { mode64bit_ |= EX_ALL_INT64_API; // For output... mode64bit_ |= EX_ALL_INT64_DB; } // See if we can keep files open int max_files = get_free_descriptor_count(); if (partCount_ <= max_files) { keepOpen_ = true; if (si.debug() & 1) std::cout << "Files kept open... (Max open = " << max_files << ")\n\n"; } else { keepOpen_ = false; std::cout << "Single file mode... (Max open = " << max_files << ")\n" << "Consider using the -subcycle option for faster execution...\n\n"; } fileids_.resize(processorCount_); filenames_.resize(processorCount_); std::string curdir = si.cwd(); std::string file_prefix = si.basename(); std::string exodus_suffix = si.exodus_suffix(); std::string root_dir = si.root_dir(); std::string sub_dir = si.sub_dir(); ParallelDisks disks; disks.Raid_Offset(si.raid_offset()); disks.Number_of_Raids(si.raid_count()); float version = 0.0; // create exo names for(int p = 0; p < partCount_; p++) { std::string name = file_prefix; if (!exodus_suffix.empty()) { name += "." + exodus_suffix; } int proc = p + startPart_; disks.rename_file_for_mp(root_dir, sub_dir, name, proc, processorCount_); filenames_[p] = name; if (p == 0) { int cpu_word_size = sizeof(float); int io_word_size_var = 0; int mode = EX_READ; mode |= mode64bit_; int exoid = ex_open(filenames_[p].c_str(), mode, &cpu_word_size, &io_word_size_var, &version); if (exoid < 0) { std::cerr << "Cannot open file '" << filenames_[p] << "'" << std::endl; return false; } int int64db = ex_int64_status(exoid) & EX_ALL_INT64_DB; if (int64db) { // If anything stored on input db as 64-bit int, then output db will have // everything stored as 64-bit ints and all API functions will use 64-bit mode64bit_ |= EX_ALL_INT64_API; mode64bit_ |= EX_ALL_INT64_DB; } int max_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH); if (max_name_length > maximumNameLength_) maximumNameLength_ = max_name_length; ex_close(exoid); if (io_word_size_var < (int)sizeof(float)) io_word_size_var = sizeof(float); ioWordSize_ = io_word_size_var; cpuWordSize_ = io_word_size_var; } if (keepOpen_ || p == 0) { int io_word_size_var = 0; int mode = EX_READ; // All entity ids (block, sets) are read/written as 64-bit... mode |= mode64bit_; fileids_[p] = ex_open(filenames_[p].c_str(), mode, &cpuWordSize_, &io_word_size_var, &version); if (fileids_[p] < 0) { std::cerr << "Cannot open file '" << filenames_[p] << "'" << std::endl; return false; } ex_set_max_name_length(fileids_[p], maximumNameLength_); SMART_ASSERT(ioWordSize_ == io_word_size_var)(ioWordSize_)(io_word_size_var); } if (si.debug()&64 || p==0 || p==partCount_-1) { std::cout << "Input(" << p << "): '" << name.c_str() << "'" << std::endl; if (!(si.debug()&64) && p==0) std::cout << "..." << std::endl; } } if (mode64bit_ & EX_ALL_INT64_DB) { std::cout << "Input files contain 8-byte integers.\n"; si.set_int64(); } return true; }
int ex_put_init_ext (int exoid, const ex_init_params *model) { int numdimdim, numnoddim, elblkdim, edblkdim, fablkdim, esetdim, fsetdim, elsetdim, nsetdim, ssetdim, dim_str_name, dim[2], temp; int nmapdim,edmapdim,famapdim,emapdim,timedim; int status; int title_len; #if 0 /* used for header size calculations which are turned off for now */ int header_size, fixed_var_size, iows; #endif char errmsg[MAX_ERR_LENGTH]; int rootid = exoid & EX_FILE_ID_MASK; exerrval = 0; /* clear error code */ if (rootid == exoid && nc_inq_dimid (exoid, DIM_NUM_DIM, &temp) == NC_NOERR) { exerrval = EX_MSG; sprintf(errmsg, "Error: initialization already done for file id %d",exoid); ex_err("ex_put_init_ext",errmsg,exerrval); return (EX_FATAL); } /* put file into define mode */ if ((status = nc_redef (exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to put file id %d into define mode", exoid); ex_err("ex_put_init_ext",errmsg,exerrval); return (EX_FATAL); } /* define some attributes... */ title_len = strlen(model->title) < MAX_LINE_LENGTH ? strlen(model->title) : MAX_LINE_LENGTH; if ((status = nc_put_att_text(rootid, NC_GLOBAL, (const char*)ATT_TITLE, title_len+1, model->title)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define model->title attribute to file id %d", rootid); ex_err("ex_put_init_ext",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } /* ...and some dimensions... */ /* create name string length dimension */ if (nc_inq_dimid (rootid, DIM_STR_NAME, &dim_str_name) != NC_NOERR) { int max_name = ex_inquire_int(exoid, EX_INQ_MAX_READ_NAME_LENGTH); if (max_name < ex_default_max_name_length) { max_name = ex_default_max_name_length; } if ((status=nc_def_dim (rootid, DIM_STR_NAME, max_name+1, &dim_str_name)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define name string length in file id %d",rootid); ex_err("ex_put_init_ext",errmsg,exerrval); goto error_ret; } } if ((status = nc_def_dim(exoid, DIM_TIME, NC_UNLIMITED, &timedim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define time dimension in file id %d", exoid); ex_err("ex_create",errmsg,exerrval); return (EX_FATAL); } dim[0] = timedim; if ((status = nc_def_var(exoid, VAR_WHOLE_TIME, nc_flt_code(exoid), 1, dim, &temp)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define whole time step variable in file id %d", exoid); ex_err("ex_create",errmsg,exerrval); return (EX_FATAL); } ex_compress_variable(exoid, temp, 2); if ((status = nc_def_dim(exoid, DIM_NUM_DIM, model->num_dim, &numdimdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of dimensions in file id %d",exoid); ex_err("ex_put_init_ext",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } /* * Need to handle "empty file" that may be the result of a strange * load balance or some other strange run. Note that if num_node * == 0, then model->num_elem must be zero since you cannot have elements * with no nodes. It *is* permissible to have zero elements with * non-zero node count. */ if (model->num_nodes > 0) { if ((status = nc_def_dim(exoid, DIM_NUM_NODES, model->num_nodes, &numnoddim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of nodes in file id %d",exoid); ex_err("ex_put_init_ext",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } if (model->num_elem > 0) { if (model->num_nodes <= 0) { exerrval = EX_MSG; sprintf(errmsg, "Error: Cannot have non-zero element count if node count is zero.in file id %d",exoid); ex_err("ex_put_init_ext",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } if ((status = nc_def_dim(exoid, DIM_NUM_ELEM, model->num_elem, &temp)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of elements in file id %d",exoid); ex_err("ex_put_init_ext",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } if (model->num_edge > 0) { if (model->num_nodes <= 0) { exerrval = EX_MSG; sprintf(errmsg, "Error: Cannot have non-zero edge count if node count is zero.in file id %d",exoid); ex_err("ex_put_init_ext",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } if ((status = nc_def_dim(exoid, DIM_NUM_EDGE, model->num_edge, &temp)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of edges in file id %d",exoid); ex_err("ex_put_init_ext",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } if (model->num_face > 0) { if (model->num_nodes <= 0) { exerrval = EX_MSG; sprintf(errmsg, "Error: Cannot have non-zero face count if node count is zero.in file id %d",exoid); ex_err("ex_put_init_ext",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } if ((status = nc_def_dim(exoid, DIM_NUM_FACE, model->num_face, &temp)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of faces in file id %d",exoid); ex_err("ex_put_init_ext",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } if (ex_write_object_params(exoid, "element block", DIM_NUM_EL_BLK, VAR_STAT_EL_BLK, VAR_ID_EL_BLK, model->num_elem_blk, &elblkdim)) { goto error_ret; } if (ex_write_object_params(exoid, "edge block", DIM_NUM_ED_BLK, VAR_STAT_ED_BLK, VAR_ID_ED_BLK, model->num_edge_blk, &edblkdim)) { goto error_ret; } if (ex_write_object_params(exoid, "face block", DIM_NUM_FA_BLK, VAR_STAT_FA_BLK, VAR_ID_FA_BLK, model->num_face_blk, &fablkdim)) { goto error_ret; } if (ex_write_object_params(exoid, "node set", DIM_NUM_NS, VAR_NS_STAT, VAR_NS_IDS, model->num_node_sets, &nsetdim)) { goto error_ret; } if (ex_write_object_params(exoid, "edge set", DIM_NUM_ES, VAR_ES_STAT, VAR_ES_IDS, model->num_edge_sets, &esetdim)) { goto error_ret; } if (ex_write_object_params(exoid, "face set", DIM_NUM_FS, VAR_FS_STAT, VAR_FS_IDS, model->num_face_sets, &fsetdim)) { goto error_ret; } if (ex_write_object_params(exoid, "side set", DIM_NUM_SS, VAR_SS_STAT, VAR_SS_IDS, model->num_side_sets, &ssetdim)) { goto error_ret; } if (ex_write_object_params(exoid, "elem set", DIM_NUM_ELS, VAR_ELS_STAT, VAR_ELS_IDS, model->num_elem_sets, &elsetdim)) { goto error_ret; } if (ex_write_map_params(exoid, "node map", DIM_NUM_NM, VAR_NM_PROP(1), model->num_node_maps, &nmapdim) != NC_NOERR) { goto error_ret; } if (ex_write_map_params(exoid, "edge map", DIM_NUM_EDM, VAR_EDM_PROP(1), model->num_edge_maps, &edmapdim) != NC_NOERR) { goto error_ret; } if (ex_write_map_params(exoid, "face map", DIM_NUM_FAM, VAR_FAM_PROP(1), model->num_face_maps, &famapdim) != NC_NOERR) { goto error_ret; } if (ex_write_map_params(exoid, "element map", DIM_NUM_EM, VAR_EM_PROP(1), model->num_elem_maps, &emapdim) != NC_NOERR) { goto error_ret; } /* * To reduce the maximum dataset sizes, the storage of the nodal * coordinates and the nodal variables was changed from a single * dataset to a dataset per component or variable. However, we * want to maintain some form of compatability with the old * exodusII version. It is easy to do this on read; however, we * also want to be able to store in the old format using the new * library. * * The mode is set in the ex_create call. The setting can be checked * via the ATT_FILESIZE attribute in the file (1=large, * 0=normal). Also handle old files that do not contain this * attribute. */ if (model->num_nodes > 0) { if (ex_large_model(exoid) == 1) { /* node coordinate arrays -- separate storage... */ dim[0] = numnoddim; if (model->num_dim > 0) { if ((status = nc_def_var (exoid, VAR_COORD_X, nc_flt_code(exoid), 1, dim, &temp)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define node x coordinate array in file id %d",exoid); ex_err("ex_put_init_ext",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } ex_compress_variable(exoid, temp, 2); } if (model->num_dim > 1) { if ((status = nc_def_var(exoid, VAR_COORD_Y, nc_flt_code(exoid), 1, dim, &temp)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define node y coordinate array in file id %d",exoid); ex_err("ex_put_init_ext",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } ex_compress_variable(exoid, temp, 2); } if (model->num_dim > 2) { if ((status = nc_def_var(exoid, VAR_COORD_Z, nc_flt_code(exoid), 1, dim, &temp)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define node z coordinate array in file id %d",exoid); ex_err("ex_put_init_ext",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } ex_compress_variable(exoid, temp, 2); } } else { /* node coordinate arrays: -- all stored together (old method) */ dim[0] = numdimdim; dim[1] = numnoddim; if ((status = nc_def_var(exoid, VAR_COORD, nc_flt_code(exoid), 2, dim, &temp)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define node coordinate array in file id %d",exoid); ex_err("ex_put_init_ext",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } } } if (ex_write_object_names(exoid, "element block",VAR_NAME_EL_BLK,elblkdim, dim_str_name, model->num_elem_blk) != NC_NOERR) { goto error_ret; } if (ex_write_object_names(exoid, "edge block", VAR_NAME_ED_BLK,edblkdim, dim_str_name, model->num_edge_blk) != NC_NOERR) { goto error_ret; } if (ex_write_object_names(exoid, "face block", VAR_NAME_FA_BLK,fablkdim, dim_str_name, model->num_face_blk) != NC_NOERR) { goto error_ret; } if (ex_write_object_names(exoid, "node set", VAR_NAME_NS, nsetdim, dim_str_name, model->num_node_sets) != NC_NOERR) { goto error_ret; } if (ex_write_object_names(exoid, "edge set", VAR_NAME_ES, esetdim, dim_str_name, model->num_edge_sets) != NC_NOERR) { goto error_ret; } if (ex_write_object_names(exoid, "face set", VAR_NAME_FS, fsetdim, dim_str_name, model->num_face_sets) != NC_NOERR) { goto error_ret; } if (ex_write_object_names(exoid, "side set", VAR_NAME_SS, ssetdim, dim_str_name, model->num_side_sets) != NC_NOERR) { goto error_ret; } if (ex_write_object_names(exoid, "element set", VAR_NAME_ELS, elsetdim, dim_str_name, model->num_elem_sets) != NC_NOERR) { goto error_ret; } if (ex_write_object_names(exoid, "node map", VAR_NAME_NM, nmapdim, dim_str_name, model->num_node_maps) != NC_NOERR) { goto error_ret; } if (ex_write_object_names(exoid, "edge map", VAR_NAME_EDM, edmapdim, dim_str_name, model->num_edge_maps) != NC_NOERR) { goto error_ret; } if (ex_write_object_names(exoid, "face map", VAR_NAME_FAM, famapdim, dim_str_name, model->num_face_maps) != NC_NOERR) { goto error_ret; } if (ex_write_object_names(exoid, "element map", VAR_NAME_EM, emapdim, dim_str_name, model->num_elem_maps) != NC_NOERR) { goto error_ret; } if (ex_write_object_names(exoid, "coordinate", VAR_NAME_COOR, numdimdim,dim_str_name, model->num_dim) != NC_NOERR) { goto error_ret; } /* leave define mode */ if ((status = nc_enddef (exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to complete variable definitions in file id %d",exoid); ex_err("ex_put_init_ext",errmsg,exerrval); return (EX_FATAL); } /* Fill the id and status arrays with EX_INVALID_ID */ { int *invalid_ids = NULL; int maxset = model->num_elem_blk; if (maxset < model->num_edge_blk) { maxset = model->num_edge_blk; } if (maxset < model->num_face_blk) { maxset = model->num_face_blk; } if (maxset < model->num_node_sets) { maxset = model->num_node_sets; } if (maxset < model->num_edge_sets) { maxset = model->num_edge_sets; } if (maxset < model->num_face_sets) { maxset = model->num_face_sets; } if (maxset < model->num_side_sets) { maxset = model->num_side_sets; } if (maxset < model->num_elem_sets) { maxset = model->num_elem_sets; } if (maxset < model->num_node_maps) { maxset = model->num_node_maps; } if (maxset < model->num_edge_maps) { maxset = model->num_edge_maps; } if (maxset < model->num_face_maps) { maxset = model->num_face_maps; } if (maxset < model->num_elem_maps) { maxset = model->num_elem_maps; } /* allocate space for id/status array */ if (!(invalid_ids = malloc(maxset*sizeof(int)))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate memory for id/status array for file id %d", exoid); ex_err("ex_put_init_ext",errmsg,exerrval); return (EX_FATAL); } invalidate_id_status(exoid, VAR_STAT_EL_BLK, VAR_ID_EL_BLK, model->num_elem_blk, invalid_ids); invalidate_id_status(exoid, VAR_STAT_ED_BLK, VAR_ID_ED_BLK, model->num_edge_blk, invalid_ids); invalidate_id_status(exoid, VAR_STAT_FA_BLK, VAR_ID_FA_BLK, model->num_face_blk, invalid_ids); invalidate_id_status(exoid, VAR_NS_STAT, VAR_NS_IDS, model->num_node_sets, invalid_ids); invalidate_id_status(exoid, VAR_ES_STAT, VAR_ES_IDS, model->num_edge_sets, invalid_ids); invalidate_id_status(exoid, VAR_FS_STAT, VAR_FS_IDS, model->num_face_sets, invalid_ids); invalidate_id_status(exoid, VAR_SS_STAT, VAR_SS_IDS, model->num_side_sets, invalid_ids); invalidate_id_status(exoid, VAR_ELS_STAT, VAR_ELS_IDS, model->num_elem_sets, invalid_ids); invalidate_id_status(exoid, 0, VAR_NM_PROP(1), model->num_node_maps, invalid_ids); invalidate_id_status(exoid, 0, VAR_EDM_PROP(1), model->num_edge_maps, invalid_ids); invalidate_id_status(exoid, 0, VAR_FAM_PROP(1), model->num_face_maps, invalid_ids); invalidate_id_status(exoid, 0, VAR_EM_PROP(1), model->num_elem_maps, invalid_ids); if (invalid_ids != NULL) { free(invalid_ids); invalid_ids = NULL; } } /* Write dummy values to the names arrays to avoid corruption issues on some platforms */ if (model->num_elem_blk > 0) { write_dummy_names(exoid, EX_ELEM_BLOCK); } if (model->num_edge_blk > 0) { write_dummy_names(exoid, EX_EDGE_BLOCK); } if (model->num_face_blk > 0) { write_dummy_names(exoid, EX_FACE_BLOCK); } if (model->num_node_sets> 0) { write_dummy_names(exoid, EX_NODE_SET); } if (model->num_edge_sets> 0) { write_dummy_names(exoid, EX_EDGE_SET); } if (model->num_face_sets> 0) { write_dummy_names(exoid, EX_FACE_SET); } if (model->num_side_sets> 0) { write_dummy_names(exoid, EX_SIDE_SET); } if (model->num_elem_sets> 0) { write_dummy_names(exoid, EX_ELEM_SET); } if (model->num_node_maps> 0) { write_dummy_names(exoid, EX_NODE_MAP); } if (model->num_edge_maps> 0) { write_dummy_names(exoid, EX_EDGE_MAP); } if (model->num_face_maps> 0) { write_dummy_names(exoid, EX_FACE_MAP); } if (model->num_elem_maps> 0) { write_dummy_names(exoid, EX_ELEM_MAP); } return (EX_NOERR); /* Fatal error: exit definition mode and return */ error_ret: if (nc_enddef (exoid) != NC_NOERR) /* exit define mode */ { sprintf(errmsg, "Error: failed to complete definition for file id %d", exoid); ex_err("ex_put_init_ext",errmsg,exerrval); } return (EX_FATAL); }
int main (int argc, char *argv[]) { char *oname = nullptr, *dot = nullptr, *filename = nullptr; char str[32]; const char* ext=EXT; int n, n1,n2,err, num_axes,num_blocks, num_side_sets,num_node_sets,num_time_steps, num_info_lines,num_global_vars, num_nodal_vars,num_element_vars,num_nodeset_vars, num_sideset_vars; size_t num_nodes = 0; size_t num_elements = 0; int mat_version = 73; /* process arguments */ for (int j=1; j< argc; j++){ if ( strcmp(argv[j],"-t")==0){ /* write text file (*.m) */ del_arg(&argc,argv,j); textfile=1; j--; continue; } if ( strcmp(argv[j],"-h")==0){ /* write help info */ del_arg(&argc,argv,j); usage(); exit(1); } if ( strcmp(argv[j],"-d")==0){ /* write help info */ del_arg(&argc,argv,j); j--; debug = 1; continue; } if ( strcmp(argv[j],"-v73")==0){ /* Version 7.3 */ del_arg(&argc,argv,j); mat_version = 73; j--; continue; } // This matches the option used in matlab if ( (strcmp(argv[j],"-v7.3")==0) || (strcmp(argv[j],"-V7.3")==0)){ /* Version 7.3 */ del_arg(&argc,argv,j); mat_version = 73; j--; continue; } if ( strcmp(argv[j],"-v5")==0){ /* Version 5 (default) */ del_arg(&argc,argv,j); mat_version = 50; j--; continue; } if ( strcmp(argv[j],"-o")==0){ /* specify output file name */ del_arg(&argc,argv,j); if ( argv[j] ){ oname=(char*)calloc(strlen(argv[j])+10,sizeof(char)); strcpy(oname,argv[j]); del_arg(&argc,argv,j); std::cout << "output file: " << oname << "\n"; } else { std::cerr << "ERROR: Invalid output file specification.\n"; return 2; } j--; continue; } } /* QA Info */ printf("%s: %s, %s\n", qainfo[0], qainfo[2], qainfo[1]); /* usage message*/ if (argc != 2){ usage(); exit(1); } /* open output file */ if ( textfile ) ext=".m"; if ( !oname ){ filename = (char*)malloc( strlen(argv[1])+10); strcpy(filename,argv[1]); dot=strrchr(filename,'.'); if ( dot ) *dot='\0'; strcat(filename,ext); } else { filename=oname; } if ( textfile ){ m_file = fopen(filename,"w"); if (!m_file ){ std::cerr << "ERROR: Unable to open " << filename << "\n"; exit(1); } } else { if (mat_version == 50) { mat_file = Mat_CreateVer(filename, nullptr, MAT_FT_MAT5); } else if (mat_version == 73) { mat_file = Mat_CreateVer(filename, nullptr, MAT_FT_MAT73); } if (mat_file == nullptr) { std::cerr << "ERROR: Unable to create matlab file " << filename << "\n"; exit(1); } } /* word sizes */ int cpu_word_size=sizeof(double); int io_word_size=0; /* open exodus file */ float exo_version; int exo_file=ex_open(argv[1],EX_READ,&cpu_word_size,&io_word_size,&exo_version); if (exo_file < 0){ std::cerr << "ERROR: Cannot open " << argv[1] << "\n"; exit(1); } /* print */ std::cout << "\ttranslating " << argv[1] << " to " << filename << "...\n"; /* read database paramters */ char *line=(char *) calloc ((MAX_LINE_LENGTH+1),sizeof(char)); ex_get_init(exo_file,line, &num_axes,&num_nodes,&num_elements,&num_blocks, &num_node_sets,&num_side_sets); num_info_lines = ex_inquire_int(exo_file,EX_INQ_INFO); num_time_steps = ex_inquire_int(exo_file,EX_INQ_TIME); ex_get_variable_param(exo_file,EX_GLOBAL,&num_global_vars); ex_get_variable_param(exo_file,EX_NODAL,&num_nodal_vars); ex_get_variable_param(exo_file,EX_ELEM_BLOCK,&num_element_vars); ex_get_variable_param(exo_file,EX_NODE_SET,&num_nodeset_vars); ex_get_variable_param(exo_file,EX_SIDE_SET,&num_sideset_vars); /* export paramters */ PutInt("naxes", num_axes); PutInt("nnodes", num_nodes); PutInt("nelems", num_elements); PutInt("nblks", num_blocks); PutInt("nnsets", num_node_sets); PutInt("nssets", num_side_sets); PutInt("nsteps", num_time_steps); PutInt("ngvars", num_global_vars); PutInt("nnvars", num_nodal_vars); PutInt("nevars", num_element_vars); PutInt("nnsvars",num_nodeset_vars); PutInt("nssvars",num_sideset_vars); /* allocate -char- scratch space*/ int nstr2 = num_info_lines; nstr2 = std::max(nstr2, num_blocks); nstr2 = std::max(nstr2, num_node_sets); nstr2 = std::max(nstr2, num_side_sets); char **str2 = get_exodus_names(nstr2, 512); /* title */ PutStr("Title",line); /* information records */ if (num_info_lines > 0 ){ ex_get_info(exo_file,str2); std::string ostr; for (int i=0;i<num_info_lines;i++) { if (strlen(str2[i]) > 0) { ostr += str2[i]; ostr += "\n"; } } PutStr("info",ostr.c_str()); ostr = ""; for (int i=0;i<num_info_lines;i++) { if (strlen(str2[i]) > 0 && strncmp(str2[i],"cavi",4)==0) { ostr += str2[i]; ostr += "\n"; } } PutStr("cvxp",ostr.c_str()); } /* nodal coordinates */ { if (debug) {logger("Coordinates");} std::vector<double> x, y, z; x.resize(num_nodes); if (num_axes >= 2) y.resize(num_nodes); if (num_axes == 3) z.resize(num_nodes); ex_get_coord(exo_file,TOPTR(x), TOPTR(y), TOPTR(z)); PutDbl("x0", num_nodes, 1, TOPTR(x)); if (num_axes >= 2) { PutDbl("y0", num_nodes, 1, TOPTR(y)); } if (num_axes == 3){ PutDbl("z0",num_nodes,1, TOPTR(z)); } } /* side sets */ std::vector<int> num_sideset_sides(num_side_sets); std::vector<int> ids; if (num_side_sets > 0) { if (debug) {logger("Side Sets");} ids.resize(num_side_sets); ex_get_ids(exo_file,EX_SIDE_SET,TOPTR(ids)); PutInt( "ssids",num_side_sets, 1,TOPTR(ids)); std::vector<int> nssdfac(num_side_sets); std::vector<int> iscr; std::vector<int> jscr; std::vector<double> scr; std::vector<int> elem_list; std::vector<int> side_list; std::vector<int> junk; for (int i=0;i<num_side_sets;i++) { ex_get_set_param(exo_file,EX_SIDE_SET, ids[i],&n1,&n2); num_sideset_sides[i]=n1; nssdfac[i]=n2; /* * the following provision is from Version 1.6 when there are no * distribution factors in exodus file */ bool has_ss_dfac = (n2 != 0); if (n2==0 || n1==n2){ std::cerr << "WARNING: Exodus II file does not contain distribution factors.\n"; /* n1=number of faces, n2=number of df */ /* using distribution factors to determine number of nodes in the sideset causes a lot grief since some codes do not output distribution factors if they are all equal to 1. mkbhard: I am using the function call below to figure out the total number of nodes in this sideset. Some redundancy exists, but it works for now */ junk.resize(n1); ex_get_side_set_node_count(exo_file,ids[i],TOPTR(junk)); n2=0; /* n2 will be equal to the total number of nodes in the sideset */ for (int j=0; j<n1; j++) n2+=junk[j]; } iscr.resize(n1); jscr.resize(n2); ex_get_side_set_node_list(exo_file,ids[i],TOPTR(iscr),TOPTR(jscr)); /* number-of-nodes-per-side list */ sprintf(str,"ssnum%02d",i+1); PutInt(str,n1,1,TOPTR(iscr)); /* nodes list */ sprintf(str,"ssnod%02d",i+1); PutInt(str,n2,1,TOPTR(jscr)); /* distribution-factors list */ scr.resize(n2); if (has_ss_dfac) { ex_get_side_set_dist_fact(exo_file,ids[i], TOPTR(scr)); } else { for (int j=0; j<n2; j++) { scr[j] = 1.0; } } sprintf(str,"ssfac%02d",i+1); PutDbl(str,n2,1,TOPTR(scr)); /* element and side list for side sets (dgriffi) */ elem_list.resize(n1); side_list.resize(n1); ex_get_set(exo_file,EX_SIDE_SET,ids[i],TOPTR(elem_list),TOPTR(side_list)); sprintf(str,"ssside%02d",i+1); PutInt(str,n1,1,TOPTR(side_list)); sprintf(str,"sselem%02d",i+1); PutInt(str,n1,1,TOPTR(elem_list)); } /* Store # sides and # dis. factors per side set (dgriffi) */ PutInt("nsssides",num_side_sets,1,TOPTR(num_sideset_sides)); PutInt("nssdfac",num_side_sets,1,TOPTR(nssdfac)); } /* node sets (section by dgriffi) */ std::vector<int> num_nodeset_nodes(num_node_sets); if (num_node_sets > 0){ if (debug) {logger("Node Sets");} std::vector<int> iscr; std::vector<double> scr; ids.resize(num_node_sets); ex_get_ids(exo_file,EX_NODE_SET, TOPTR(ids)); PutInt( "nsids",num_node_sets, 1,TOPTR(ids)); std::vector<int> num_nodeset_df(num_node_sets); for (int i=0;i<num_node_sets;i++){ ex_get_set_param(exo_file,EX_NODE_SET,ids[i],&n1,&n2); iscr.resize(n1); ex_get_node_set(exo_file,ids[i],TOPTR(iscr)); /* nodes list */ sprintf(str,"nsnod%02d",i+1); PutInt(str,n1,1,TOPTR(iscr)); { /* distribution-factors list */ scr.resize(n2); ex_get_node_set_dist_fact(exo_file,ids[i],TOPTR(scr)); sprintf(str,"nsfac%02d",i+1); PutDbl(str,n2,1,TOPTR(scr)); } num_nodeset_nodes[i]=n1; num_nodeset_df[i]=n2; } /* Store # nodes and # dis. factors per node set */ PutInt("nnsnodes",num_node_sets,1,TOPTR(num_nodeset_nodes)); PutInt("nnsdfac",num_node_sets,1,TOPTR(num_nodeset_df)); } /* element blocks */ if (debug) {logger("Element Blocks");} std::vector<int> num_elem_in_block(num_blocks); { ids.resize(num_blocks); std::vector<int> iscr; ex_get_ids(exo_file,EX_ELEM_BLOCK,TOPTR(ids)); PutInt( "blkids",num_blocks, 1,TOPTR(ids)); for (int i=0;i<num_blocks;i++) { ex_get_elem_block(exo_file,ids[i],str2[i],&n,&n1,&n2); num_elem_in_block[i]=n; iscr.resize(n*n1); ex_get_conn(exo_file,EX_ELEM_BLOCK,ids[i],TOPTR(iscr), nullptr, nullptr); sprintf(str,"blk%02d",i+1); PutInt(str,n1,n,TOPTR(iscr)); } str[0]='\0'; for (int i=0;i<num_blocks;i++) { strcat(str, str2[i]); strcat(str, "\n"); } PutStr("blknames",str); } /* time values */ if (num_time_steps > 0 ) { if (debug) {logger("Time Steps");} std::vector<double> scr(num_time_steps); ex_get_all_times (exo_file, TOPTR(scr)); PutDbl( "time", num_time_steps, 1, TOPTR(scr)); } /* global variables */ if (num_global_vars > 0 ) { if (debug) {logger("Global Variables");} get_put_names(exo_file, EX_GLOBAL, num_global_vars, "gnames"); std::vector<double> scr(num_time_steps); for (int i=0;i<num_global_vars;i++){ sprintf(str,"gvar%02d",i+1); ex_get_glob_var_time(exo_file,i+1,1,num_time_steps,TOPTR(scr)); PutDbl(str,num_time_steps,1,TOPTR(scr)); } } /* nodal variables */ if (num_nodal_vars > 0 ) { if (debug) {logger("Nodal Variables");} if (debug) {logger("\tNames");} get_put_names(exo_file, EX_NODAL, num_nodal_vars, "nnames"); std::vector<double> scr(num_nodes*num_time_steps); for (int i=0; i<num_nodal_vars; i++){ sprintf(str,"nvar%02d",i+1); if (debug) {logger("\tReading");} for (int j=0; j<num_time_steps; j++) { ex_get_nodal_var(exo_file,j+1,i+1,num_nodes, &scr[num_nodes*j]); } if (debug) {logger("\tWriting");} PutDbl(str,num_nodes,num_time_steps,TOPTR(scr)); } } /* element variables */ if (num_element_vars > 0 ) { if (debug) {logger("Element Variables");} get_put_names(exo_file, EX_ELEM_BLOCK, num_element_vars, "enames"); get_put_vars(exo_file, EX_ELEM_BLOCK, num_blocks, num_element_vars, num_time_steps, num_elem_in_block, "evar%02d"); } /* nodeset variables */ if (num_nodeset_vars > 0 ) { if (debug) {logger("Nodeset Variables");} get_put_names(exo_file, EX_NODE_SET, num_nodeset_vars, "nsnames"); get_put_vars(exo_file, EX_NODE_SET, num_node_sets, num_nodeset_vars, num_time_steps, num_nodeset_nodes, "nsvar%02d"); } /* sideset variables */ if (num_sideset_vars > 0 ) { if (debug) {logger("Sideset Variables");} get_put_names(exo_file, EX_SIDE_SET, num_sideset_vars, "ssnames"); get_put_vars(exo_file, EX_SIDE_SET, num_side_sets, num_sideset_vars, num_time_steps, num_sideset_sides, "ssvar%02d"); } /* node and element number maps */ if (debug) {logger("Node and Element Number Maps");} ex_opts(0); /* turn off error reporting. It is not an error to have no map*/ ids.resize(num_nodes); err = ex_get_node_num_map(exo_file,TOPTR(ids)); if ( err==0 ){ PutInt("node_num_map",num_nodes,1,TOPTR(ids)); } ids.resize(num_elements); err = ex_get_elem_num_map(exo_file,TOPTR(ids)); if ( err==0 ){ PutInt("elem_num_map",num_elements,1,TOPTR(ids)); } if (debug) {logger("Closing file");} ex_close(exo_file); if ( textfile ) fclose(m_file); else Mat_Close(mat_file); std::cout << "done...\n"; free(filename); free(line); delete_exodus_names(str2, nstr2); /* exit status */ add_to_log("exo2mat", 0); return(0); }
int ex_put_prop(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, const char *prop_name, ex_entity_id value) { int status; int oldfill = 0; int temp; int found = EX_FALSE; int num_props, i, dimid, propid, dims[1]; int int_type; size_t start[1]; size_t prop_name_len, name_length; char * name; char tmpstr[MAX_STR_LENGTH + 1]; char * dim_name; long long vals[1]; char errmsg[MAX_ERR_LENGTH]; ex_check_valid_file_id(exoid); exerrval = 0; /* clear error code */ /* check if property has already been created */ num_props = ex_get_num_props(exoid, obj_type); if (num_props > 1) { /* any properties other than the default 1? */ for (i = 1; i <= num_props; i++) { switch (obj_type) { case EX_ELEM_BLOCK: name = VAR_EB_PROP(i); break; case EX_EDGE_BLOCK: name = VAR_ED_PROP(i); break; case EX_FACE_BLOCK: name = VAR_FA_PROP(i); break; case EX_NODE_SET: name = VAR_NS_PROP(i); break; case EX_EDGE_SET: name = VAR_ES_PROP(i); break; case EX_FACE_SET: name = VAR_FS_PROP(i); break; case EX_ELEM_SET: name = VAR_ELS_PROP(i); break; case EX_SIDE_SET: name = VAR_SS_PROP(i); break; case EX_ELEM_MAP: name = VAR_EM_PROP(i); break; case EX_FACE_MAP: name = VAR_FAM_PROP(i); break; case EX_EDGE_MAP: name = VAR_EDM_PROP(i); break; case EX_NODE_MAP: name = VAR_NM_PROP(i); break; default: exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: object type %d not supported; file id %d", obj_type, exoid); ex_err("ex_put_prop", errmsg, exerrval); return (EX_FATAL); } if ((status = nc_inq_varid(exoid, name, &propid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get property array id in file id %d", exoid); ex_err("ex_put_prop", errmsg, exerrval); return (EX_FATAL); } /* compare stored attribute name with passed property name */ memset(tmpstr, 0, MAX_STR_LENGTH + 1); if ((status = nc_get_att_text(exoid, propid, ATT_PROP_NAME, tmpstr)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get property name in file id %d", exoid); ex_err("ex_put_prop", errmsg, exerrval); return (EX_FATAL); } if (strcmp(tmpstr, prop_name) == 0) { found = EX_TRUE; break; } } } /* if property array has not been created, create it */ if (!found) { name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH) + 1; /* put netcdf file into define mode */ if ((status = nc_redef(exoid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to place file id %d into define mode", exoid); ex_err("ex_put_prop", errmsg, exerrval); return (EX_FATAL); } /* create a variable with a name xx_prop#, where # is the new number */ /* of the property */ switch (obj_type) { case EX_ELEM_BLOCK: name = VAR_EB_PROP(num_props + 1); dim_name = DIM_NUM_EL_BLK; break; case EX_FACE_BLOCK: name = VAR_FA_PROP(num_props + 1); dim_name = DIM_NUM_FA_BLK; break; case EX_EDGE_BLOCK: name = VAR_ED_PROP(num_props + 1); dim_name = DIM_NUM_ED_BLK; break; case EX_NODE_SET: name = VAR_NS_PROP(num_props + 1); dim_name = DIM_NUM_NS; break; case EX_EDGE_SET: name = VAR_ES_PROP(num_props + 1); dim_name = DIM_NUM_ES; break; case EX_FACE_SET: name = VAR_FS_PROP(num_props + 1); dim_name = DIM_NUM_FS; break; case EX_ELEM_SET: name = VAR_ELS_PROP(num_props + 1); dim_name = DIM_NUM_ELS; break; case EX_SIDE_SET: name = VAR_SS_PROP(num_props + 1); dim_name = DIM_NUM_SS; break; case EX_ELEM_MAP: name = VAR_EM_PROP(num_props + 1); dim_name = DIM_NUM_EM; break; case EX_FACE_MAP: name = VAR_FAM_PROP(num_props + 1); dim_name = DIM_NUM_FAM; break; case EX_EDGE_MAP: name = VAR_EDM_PROP(num_props + 1); dim_name = DIM_NUM_EDM; break; case EX_NODE_MAP: name = VAR_NM_PROP(num_props + 1); dim_name = DIM_NUM_NM; break; default: exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: object type %d not supported; file id %d", obj_type, exoid); ex_err("ex_put_prop", errmsg, exerrval); goto error_ret; /* Exit define mode and return */ } /* inquire id of previously defined dimension (number of objects) */ if ((status = nc_inq_dimid(exoid, dim_name, &dimid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate number of objects in file id %d", exoid); ex_err("ex_put_prop", errmsg, exerrval); goto error_ret; /* Exit define mode and return */ } dims[0] = dimid; nc_set_fill(exoid, NC_FILL, &oldfill); /* fill with zeros per routine spec */ int_type = NC_INT; if (ex_int64_status(exoid) & EX_IDS_INT64_DB) { int_type = NC_INT64; } if ((status = nc_def_var(exoid, name, int_type, 1, dims, &propid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to create property array variable in file id %d", exoid); ex_err("ex_put_prop", errmsg, exerrval); goto error_ret; /* Exit define mode and return */ } vals[0] = 0; /* fill value */ /* create attribute to cause variable to fill with zeros per routine spec */ if ((status = nc_put_att_longlong(exoid, propid, _FillValue, int_type, 1, vals)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to create property name fill attribute in file id %d", exoid); ex_err("ex_put_prop", errmsg, exerrval); goto error_ret; /* Exit define mode and return */ } /* Check that the property name length is less than MAX_NAME_LENGTH */ prop_name_len = strlen(prop_name) + 1; if (prop_name_len > name_length) { fprintf(stderr, "Warning: The property name '%s' is too long.\n\tIt will " "be truncated from %d to %d characters\n", prop_name, (int)prop_name_len - 1, (int)name_length - 1); prop_name_len = name_length; } /* store property name as attribute of property array variable */ if ((status = nc_put_att_text(exoid, propid, ATT_PROP_NAME, prop_name_len, (void *)prop_name)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store property name %s in file id %d", prop_name, exoid); ex_err("ex_put_prop", errmsg, exerrval); goto error_ret; /* Exit define mode and return */ } ex_update_max_name_length(exoid, prop_name_len - 1); /* leave define mode */ if ((status = nc_enddef(exoid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to leave define mode in file id %d", exoid); ex_err("ex_put_prop", errmsg, exerrval); return (EX_FATAL); } nc_set_fill(exoid, oldfill, &temp); /* default: nofill */ } /* find index into property array using obj_id; put value in property */ /* array at proper index; ex_id_lkup returns an index that is 1-based,*/ /* but netcdf expects 0-based arrays so subtract 1 */ /* special case: property name ID - check for duplicate ID assignment */ if (strcmp("ID", prop_name) == 0) { start[0] = ex_id_lkup(exoid, obj_type, value); if (exerrval != EX_LOOKUPFAIL) /* found the id */ { exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "Warning: attempt to assign duplicate %s ID %" PRId64 " in file id %d", ex_name_of_object(obj_type), value, exoid); ex_err("ex_put_prop", errmsg, exerrval); return (EX_WARN); } } start[0] = ex_id_lkup(exoid, obj_type, obj_id); if (exerrval != 0) { if (exerrval == EX_NULLENTITY) { snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no properties allowed for NULL %s id %" PRId64 " in file id %d", ex_name_of_object(obj_type), obj_id, exoid); ex_err("ex_put_prop", errmsg, EX_NULLENTITY); return (EX_WARN); } snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find value %" PRId64 " in %s property array in file id %d", obj_id, ex_name_of_object(obj_type), exoid); ex_err("ex_put_prop", errmsg, exerrval); return (EX_FATAL); } start[0] = start[0] - 1; /* value is of type 'ex_entity_id' which is a typedef to int64_t or long long */ status = nc_put_var1_longlong(exoid, propid, start, (long long *)&value); if (status != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store property value in file id %d", exoid); ex_err("ex_put_prop", errmsg, exerrval); return (EX_FATAL); } return (EX_NOERR); /* Fatal error: exit definition mode and return */ error_ret: nc_set_fill(exoid, oldfill, &temp); /* default: nofill */ if (nc_enddef(exoid) != NC_NOERR) { /* exit define mode */ snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition for file id %d", exoid); ex_err("ex_put_prop", errmsg, exerrval); } return (EX_FATAL); }
template <typename INT> void ExoII_Read<INT>::Get_Init_Data() { SMART_ASSERT(Check_State()); SMART_ASSERT(file_id >= 0); // Determine max size of entity and variable names on the database int name_length = ex_inquire_int(file_id, EX_INQ_DB_MAX_USED_NAME_LENGTH); ex_set_max_name_length(file_id, name_length); ex_init_params info; info.title[0] = '\0'; int err = ex_get_init_ext(file_id, &info); if (err < 0) { std::cout << "EXODIFF ERROR: Failed to get init data!" << " Error number = " << err << ". Aborting..." << '\n'; exit(1); } dimension = info.num_dim; num_nodes = info.num_nodes; num_elmts = info.num_elem; num_elmt_blocks = info.num_elem_blk; num_node_sets = info.num_node_sets; num_side_sets = info.num_side_sets; title = info.title; if (err > 0 && !interface.quiet_flag) std::cout << "EXODIFF WARNING: was issued, number = " << err << '\n'; if (dimension < 1 || dimension > 3 || num_elmt_blocks < 0 || num_node_sets < 0 || num_side_sets < 0) { std::cout << "EXODIFF ERROR: Init data appears corrupt:" << '\n' << " dimension = " << dimension << '\n' << " num_nodes = " << num_nodes << '\n' << " num_elmts = " << num_elmts << '\n' << " num_elmt_blocks = " << num_elmt_blocks << '\n' << " num_node_sets = " << num_node_sets << '\n' << " num_side_sets = " << num_side_sets << '\n' << " ... Aborting..." << '\n'; exit(1); } int num_qa = ex_inquire_int(file_id, EX_INQ_QA); int num_info = ex_inquire_int(file_id, EX_INQ_INFO); if (num_qa < 0 || num_info < 0) { std::cout << "EXODIFF ERROR: inquire data appears corrupt:" << '\n' << " num_qa = " << num_qa << '\n' << " num_info = " << num_info << '\n' << " ... Aborting..." << '\n'; exit(1); } // Coordinate Names... char **coords = get_name_array(3, name_length); err = ex_get_coord_names(file_id, coords); if (err < 0) { std::cout << "EXODIFF ERROR: Failed to get coordinate" << " names! Aborting..." << '\n'; exit(1); } coord_names.clear(); for (size_t i = 0; i < dimension; ++i) { coord_names.push_back(coords[i]); } free_name_array(coords, 3); // Element Block Data... if (eblocks) delete[] eblocks; eblocks = nullptr; if (num_elmt_blocks > 0) { eblocks = new Exo_Block<INT>[num_elmt_blocks]; SMART_ASSERT(eblocks != nullptr); std::vector<INT> ids(num_elmt_blocks); err = ex_get_ids(file_id, EX_ELEM_BLOCK, TOPTR(ids)); if (err < 0) { std::cout << "EXODIFF ERROR: Failed to get element" << " block ids! Aborting..." << '\n'; exit(1); } size_t e_count = 0; for (size_t b = 0; b < num_elmt_blocks; ++b) { if (ids[b] <= EX_INVALID_ID) { std::cout << "EXODIFF WARNING: Element block Id " << "for block index " << b << " is " << ids[b] << " which is negative. This was returned by call to ex_get_elem_blk_ids()." << '\n'; } eblocks[b].initialize(file_id, ids[b]); e_count += eblocks[b].Size(); } if (e_count != num_elmts && !interface.quiet_flag) { std::cout << "EXODIFF WARNING: Total number of elements " << num_elmts << " does not equal the sum of the number of elements " << "in each block " << e_count << '\n'; } // Gather the attribute names (even though not all attributes are on all blocks) std::set<std::string> names; for (size_t b = 0; b < num_elmt_blocks; ++b) { for (int a = 0; a < eblocks[b].attr_count(); a++) { names.insert(eblocks[b].Get_Attribute_Name(a)); } } elmt_atts.resize(names.size()); std::copy(names.begin(), names.end(), elmt_atts.begin()); } // Node & Side sets... if (nsets) delete[] nsets; nsets = nullptr; if (num_node_sets > 0) { nsets = new Node_Set<INT>[num_node_sets]; SMART_ASSERT(nsets != nullptr); std::vector<INT> ids(num_node_sets); err = ex_get_ids(file_id, EX_NODE_SET, TOPTR(ids)); if (err < 0) { std::cout << "EXODIFF ERROR: Failed to get " << "nodeset ids! Aborting..." << '\n'; exit(1); } for (size_t nset = 0; nset < num_node_sets; ++nset) { if (ids[nset] <= EX_INVALID_ID) { std::cout << "EXODIFF WARNING: Nodeset Id " << "for nodeset index " << nset << " is " << ids[nset] << " which is negative. This was returned by call to ex_get_ids()." << '\n'; } nsets[nset].initialize(file_id, ids[nset]); } } if (ssets) delete[] ssets; ssets = nullptr; if (num_side_sets) { ssets = new Side_Set<INT>[num_side_sets]; SMART_ASSERT(ssets != nullptr); std::vector<INT> ids(num_side_sets); err = ex_get_ids(file_id, EX_SIDE_SET, TOPTR(ids)); if (err < 0) { std::cout << "EXODIFF ERROR: Failed to get " << "sideset ids! Aborting..." << '\n'; exit(1); } for (size_t sset = 0; sset < num_side_sets; ++sset) { if (ids[sset] <= EX_INVALID_ID) { std::cout << "EXODIFF WARNING: Sideset Id " << "for sideset index " << sset << " is " << ids[sset] << " which is negative. This was returned by call to ex_get_ids()." << '\n'; } ssets[sset].initialize(file_id, ids[sset]); } } // ************** RESULTS info *************** // int num_global_vars, num_nodal_vars, num_elmt_vars, num_ns_vars, num_ss_vars; err = ex_get_variable_param(file_id, EX_GLOBAL, &num_global_vars); if (err < 0) { std::cout << "EXODIFF ERROR: Failed to get number of" << " global variables! Aborting..." << '\n'; exit(1); } err = ex_get_variable_param(file_id, EX_NODAL, &num_nodal_vars); if (err < 0) { std::cout << "EXODIFF ERROR: Failed to get number of" << " nodal variables! Aborting..." << '\n'; exit(1); } err = ex_get_variable_param(file_id, EX_ELEM_BLOCK, &num_elmt_vars); if (err < 0) { std::cout << "EXODIFF ERROR: Failed to get number of" << " element variables! Aborting..." << '\n'; exit(1); } err = ex_get_variable_param(file_id, EX_NODE_SET, &num_ns_vars); if (err < 0) { std::cout << "EXODIFF ERROR: Failed to get number of" << " nodeset variables! Aborting..." << '\n'; exit(1); } err = ex_get_variable_param(file_id, EX_SIDE_SET, &num_ss_vars); if (err < 0) { std::cout << "EXODIFF ERROR: Failed to get number of" << " sideset variables! Aborting..." << '\n'; exit(1); } if (num_global_vars < 0 || num_nodal_vars < 0 || num_elmt_vars < 0 || num_ns_vars < 0 || num_ss_vars < 0) { std::cout << "EXODIFF ERROR: Data appears corrupt for" << " number of variables !" << '\n' << "\tnum global vars = " << num_global_vars << '\n' << "\tnum nodal vars = " << num_nodal_vars << '\n' << "\tnum element vars = " << num_elmt_vars << '\n' << " ... Aborting..." << '\n'; exit(1); } read_vars(file_id, EX_GLOBAL, "Global", num_global_vars, global_vars); read_vars(file_id, EX_NODAL, "Nodal", num_nodal_vars, nodal_vars); read_vars(file_id, EX_ELEM_BLOCK, "Element", num_elmt_vars, elmt_vars); read_vars(file_id, EX_NODE_SET, "Nodeset", num_ns_vars, ns_vars); read_vars(file_id, EX_SIDE_SET, "Sideset", num_ss_vars, ss_vars); // Times: num_times = ex_inquire_int(file_id, EX_INQ_TIME); if (num_times < 0) { std::cout << "EXODIFF ERROR: Number of time steps came" << " back negative (" << num_times << ")! Aborting..." << '\n'; exit(1); } if ((num_global_vars > 0 || num_nodal_vars > 0 || num_elmt_vars > 0 || num_ns_vars > 0 || num_ss_vars > 0) && num_times == 0) { std::cout << "EXODIFF Consistency error -- The database contains transient variables, but no " "timesteps!" << '\n'; exit(1); } if (num_times) { times = new double[num_times]; SMART_ASSERT(times != nullptr); err = ex_get_all_times(file_id, times); } if (num_nodal_vars) { if (num_times == 0) { std::cout << "EXODIFF Consistency error--The database contains " << num_nodal_vars << " nodal variables, but there are no time steps defined." << '\n'; } if (num_times) { results = new double *[num_nodal_vars]; for (int i = 0; i < num_nodal_vars; ++i) results[i] = nullptr; } } } // End of EXODIFF
bool Excn::ExodusFile::initialize(const SystemInterface& si) { // See if we can keep files open size_t max_files = get_free_descriptor_count(); if (si.inputFiles_.size() <= max_files) { keepOpen_ = true; if (si.debug() & 1) std::cout << "Files kept open... (Max open = " << max_files << ")\n\n"; } else { keepOpen_ = false; std::cout << "Single file mode... (Max open = " << max_files << ")\n" << "Consider using the -subcycle option for faster execution...\n\n"; } float version = 0.0; // create exo names filenames_.resize(si.inputFiles_.size()); fileids_.resize(si.inputFiles_.size()); int int_byte_size_api = 4; if (si.ints_64_bit()) int_byte_size_api = 8; int overall_max_name_length = 0; for(size_t p = 0; p < si.inputFiles_.size(); p++) { std::string name = si.inputFiles_[p]; filenames_[p] = name; if (p == 0) { int cpu_word_size = sizeof(float); int io_wrd_size = 0; int exoid = ex_open(filenames_[p].c_str(), EX_READ, &cpu_word_size, &io_wrd_size, &version); if (exoid < 0) { std::cerr << "Cannot open file '" << filenames_[p] << "'" << std::endl; return false; } int max_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH); if (max_name_length > overall_max_name_length) overall_max_name_length = max_name_length; ex_close(exoid); if (io_wrd_size < (int)sizeof(float)) io_wrd_size = sizeof(float); ioWordSize_ = io_wrd_size; cpuWordSize_ = io_wrd_size; if (ex_int64_status(exoid & EX_ALL_INT64_DB) || si.ints_64_bit()) { exodusMode_ = EX_ALL_INT64_API; } } if (keepOpen_ || p == 0) { int io_wrd_size = 0; int mode = EX_READ | exodusMode_; fileids_[p] = ex_open(filenames_[p].c_str(), mode, &cpuWordSize_, &io_wrd_size, &version); if (fileids_[p] < 0) { std::cerr << "Cannot open file '" << filenames_[p] << "'" << std::endl; return false; } SMART_ASSERT(ioWordSize_ == io_wrd_size)(ioWordSize_)(io_wrd_size); } std::cout << "Part " << p+1 << ": '" << name.c_str() << "'" << std::endl; } maximumNameLength_ = overall_max_name_length; for(size_t p = 0; p < si.inputFiles_.size(); p++) { ex_set_max_name_length(fileids_[p], maximumNameLength_); } return true; }
printf("\tNumber of element blocks: %d\n", num_elem_blk); printf("---------------------------------------------------------\n"); } #endif /* Cross-check the load balance file info against the mesh info */ if(((size_t)num_nodes != globals.Num_Node) || ((size_t)num_elem != globals.Num_Elem) || (num_elem_blk != globals.Num_Elem_Blk)) { fprintf(stderr, "%s: ERROR: Problem dimensions in the LB File don't match with those \ in mesh file",yo); exit(1); } /* Read the QA Records */ num_qa_rec = ex_inquire_int(lb_exoid, EX_INQ_QA); if(num_qa_rec > 0) { length_qa = 4 * num_qa_rec; qa_record_ptr = (char **)array_alloc(__FILE__, __LINE__, 1, length_qa, sizeof(char *)); for(int i = 0; i < length_qa; i++) { qa_record_ptr[i] = (char *) array_alloc (__FILE__, __LINE__, 1, (MAX_STR_LENGTH+1), sizeof(char)); } error = ex_get_qa(lb_exoid, (char *(*)[4]) &qa_record_ptr[0]); check_exodus_error(error, "ex_get_qa"); } /* Read the Info Records */ num_inf_rec = ex_inquire_int(lb_exoid, EX_INQ_INFO);
bool exodus_file_query(const char* filename, size_t* real_size, float* version, int* num_mpi_processes, real_array_t* times) { set_ex_opts(); if (!file_exists(filename)) return false; bool valid = true; bool is_parallel = false; int my_real_size = (int)sizeof(real_t); int io_real_size = 0; #if POLYMEC_HAVE_MPI MPI_Info info; MPI_Info_create(&info); int id = ex_open_par(filename, EX_READ, &my_real_size, &io_real_size, version, MPI_COMM_WORLD, info); // Did that work? If not, try the serial opener. if (id < 0) { MPI_Info_free(&info); id = ex_open(filename, EX_READ, &my_real_size, &io_real_size, version); } else is_parallel = true; #else int id = ex_open(filename, EX_READ, &my_real_size, &io_real_size, version); #endif if (id < 0) valid = false; else { *real_size = (size_t)io_real_size; // Make sure that the file has 3D data. ex_init_params mesh_info; int status = ex_get_init_ext(id, &mesh_info); if ((status < 0) || (mesh_info.num_dim != 3)) valid = false; else { // Make sure that each of the element blocks in this file have // valid 3D element types. int num_elem_blocks = (int)mesh_info.num_elem_blk; int elem_block_ids[num_elem_blocks]; ex_get_ids(id, EX_ELEM_BLOCK, elem_block_ids); for (int i = 0; i < num_elem_blocks; ++i) { int elem_block = elem_block_ids[i]; char elem_type_name[MAX_NAME_LENGTH+1]; int num_elem, num_nodes_per_elem, num_faces_per_elem; ex_get_block(id, EX_ELEM_BLOCK, elem_block, elem_type_name, &num_elem, &num_nodes_per_elem, NULL, &num_faces_per_elem, NULL); fe_mesh_element_t elem_type = get_element_type(elem_type_name); if (elem_type == FE_INVALID) { valid = false; break; } } if (valid) { // Query the number of processes for which this file has data. // Recently, we've had to add guards to check to see whether // DIM_NUM_PROCS exists in the file. If it doesn't, we assume that // the file corresponds to a serial data set. int num_proc_in_file; char file_type[2]; int dim_id, status1 = nc_inq_dimid(id, DIM_NUM_PROCS, &dim_id); if (status1 == NC_NOERR) { ex_get_init_info(id, num_mpi_processes, &num_proc_in_file, file_type); if (is_parallel) { ASSERT(*num_mpi_processes == num_proc_in_file); } } else { *num_mpi_processes = num_proc_in_file = 1; } if (times != NULL) { // Ask for the times within the file. int num_times = (int)ex_inquire_int(id, EX_INQ_TIME); real_array_resize(times, num_times); if (num_times > 0) { ex_get_all_times(id, times->data); } } } } ex_close(id); } #if POLYMEC_HAVE_MPI if (is_parallel) MPI_Info_free(&info); #endif return valid; }
int ex_get_partial_nodal_var_int(int exoid, int time_step, int nodal_var_index, int64_t start_node, int64_t num_nodes, void *var_vals) { int varid; int status; size_t start[3], count[3]; char errmsg[MAX_ERR_LENGTH]; ex_check_valid_file_id(exoid); exerrval = 0; /* clear error code */ /* Verify that time_step is within bounds */ { int num_time_steps = ex_inquire_int(exoid, EX_INQ_TIME); if (time_step <= 0 || time_step > num_time_steps) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: time_step is out-of-range. Value = %d, valid " "range is 1 to %d in file id %d", time_step, num_time_steps, exoid); ex_err("ex_get_partial_nodal_var", errmsg, EX_BADPARAM); return (EX_FATAL); } } if (ex_large_model(exoid) == 0) { /* read values of the nodal variable */ if ((status = nc_inq_varid(exoid, VAR_NOD_VAR, &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "Warning: could not find nodal variables in file id %d", exoid); ex_err("ex_get_partial_nodal_var", errmsg, exerrval); return (EX_WARN); } start[0] = --time_step; start[1] = --nodal_var_index; start[2] = --start_node; count[0] = 1; count[1] = 1; count[2] = num_nodes; } else { /* read values of the nodal variable -- stored as separate variables... */ /* Get the varid.... */ if ((status = nc_inq_varid(exoid, VAR_NOD_VAR_NEW(nodal_var_index), &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "Warning: could not find nodal variable %d in file id %d", nodal_var_index, exoid); ex_err("ex_get_partial_nodal_var", errmsg, exerrval); return (EX_WARN); } start[0] = --time_step; start[1] = --start_node; count[0] = 1; count[1] = num_nodes; } if (ex_comp_ws(exoid) == 4) { status = nc_get_vara_float(exoid, varid, start, count, var_vals); } else { status = nc_get_vara_double(exoid, varid, start, count, var_vals); } if (status != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get nodal variables in file id %d", exoid); ex_err("ex_get_partial_nodal_var", errmsg, exerrval); return (EX_FATAL); } return (EX_NOERR); }
int ex_get_nodal_var_time_int(int exoid, int nodal_var_index, int64_t node_number, int beg_time_step, int end_time_step, void *nodal_var_vals) { int status; int varid; size_t start[3], count[3]; char errmsg[MAX_ERR_LENGTH]; /* Check that times are in range */ { int num_time_steps = ex_inquire_int(exoid, EX_INQ_TIME); if (beg_time_step <= 0 || beg_time_step > num_time_steps) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: beginning time_step is out-of-range. Value = %d, " "valid range is 1 to %d in file id %d", beg_time_step, num_time_steps, exoid); ex_err("ex_get_nodal_var_time", errmsg, EX_BADPARAM); return (EX_FATAL); } if (end_time_step < 0) { /* user is requesting the maximum time step; we find this out using the * database inquire function to get the number of time steps; the ending * time step number is 1 less due to 0 based array indexing in C */ end_time_step = num_time_steps; } else if (end_time_step < beg_time_step || end_time_step > num_time_steps) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: end time_step is out-of-range. Value = %d, valid " "range is %d to %d in file id %d", beg_time_step, end_time_step, num_time_steps, exoid); ex_err("ex_get_nodal_var_time", errmsg, EX_BADPARAM); return (EX_FATAL); } } beg_time_step--; end_time_step--; node_number--; if (ex_large_model(exoid) == 0) { /* read values of the nodal variable; * assume node number is 1-based (first node is numbered 1); adjust * so it is 0-based */ if ((status = nc_inq_varid(exoid, VAR_NOD_VAR, &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "Warning: could not find nodal variable %d in file id %d", nodal_var_index, exoid); ex_err("ex_get_nodal_var_time", errmsg, exerrval); return (EX_WARN); } start[0] = beg_time_step; start[1] = --nodal_var_index; start[2] = node_number; count[0] = end_time_step - beg_time_step + 1; count[1] = 1; count[2] = 1; } else { if ((status = nc_inq_varid(exoid, VAR_NOD_VAR_NEW(nodal_var_index), &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "Warning: could not find nodal variable %d in file id %d", nodal_var_index, exoid); ex_err("ex_get_nodal_var_time", errmsg, exerrval); return (EX_WARN); } /* read values of the nodal variable; * assume node number is 1-based (first node is numbered 1); adjust * so it is 0-based */ start[0] = beg_time_step; start[1] = node_number; count[0] = end_time_step - beg_time_step + 1; count[1] = 1; } if (ex_comp_ws(exoid) == 4) { status = nc_get_vara_float(exoid, varid, start, count, nodal_var_vals); } else { status = nc_get_vara_double(exoid, varid, start, count, nodal_var_vals); } if (status != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get nodal variables in file id %d", exoid); ex_err("ex_get_nodal_var_time", errmsg, exerrval); return (EX_FATAL); } return (EX_NOERR); }
/*! \undoc */ int ex_get_concat_side_set_node_count(int exoid, int *side_set_node_cnt_list) { size_t m; int ii, i, j, iss, ioff; ex_entity_id side_set_id; int num_side_sets, num_elem_blks, num_df, ndim; int64_t tot_num_elem = 0, tot_num_ss_elem = 0, side, elem; void_int *elem_blk_ids = NULL; void_int *side_set_ids = NULL; void_int *ss_elem_ndx = NULL; void_int *side_set_elem_list = NULL; void_int *side_set_side_list = NULL; size_t elem_ctr; int int_size, ids_size; int status; struct elem_blk_parm *elem_blk_parms; char errmsg[MAX_ERR_LENGTH]; exerrval = 0; /* clear error code */ /* first check if any side sets are specified */ /* inquire how many side sets have been stored */ num_side_sets = ex_inquire_int(exoid, EX_INQ_SIDE_SETS); if (num_side_sets < 0) { sprintf(errmsg, "Error: failed to get number of side sets in file id %d",exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,exerrval); return(EX_FATAL); } if (num_side_sets == 0) { sprintf(errmsg, "Warning: no side sets defined in file id %d",exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,EX_WARN); return(EX_WARN); } num_elem_blks = ex_inquire_int(exoid, EX_INQ_ELEM_BLK); if (num_elem_blks < 0) { sprintf(errmsg, "Error: failed to get number of element blocks in file id %d",exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,exerrval); return(EX_FATAL); } tot_num_elem = ex_inquire_int(exoid, EX_INQ_ELEM); if (tot_num_elem < 0) { sprintf(errmsg, "Error: failed to get total number of elements in file id %d",exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,exerrval); return(EX_FATAL); } /* get the dimensionality of the coordinates; this is necessary to distinguish between 2d TRIs and 3d TRIs */ ndim = ex_inquire_int(exoid, EX_INQ_DIM); if (ndim < 0) { sprintf(errmsg, "Error: failed to get dimensionality in file id %d",exoid); ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval); return(EX_FATAL); } int_size = sizeof(int); if (ex_int64_status(exoid) & EX_BULK_INT64_API) int_size = sizeof(int64_t); /* Allocate space for the element block ids */ ids_size = sizeof(int); if (ex_int64_status(exoid) & EX_IDS_INT64_API) { ids_size = sizeof(int64_t); } if (!(elem_blk_ids=malloc(num_elem_blks*ids_size))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate space for element block ids for file id %d", exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,exerrval); goto error_ret; } if (ex_get_ids(exoid, EX_ELEM_BLOCK, elem_blk_ids) == -1) { sprintf(errmsg, "Error: failed to get element block ids in file id %d", exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,EX_MSG); return(EX_FATAL); } /* Allocate space for the element block params */ if (!(elem_blk_parms=malloc(num_elem_blks*sizeof(struct elem_blk_parm)))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate space for element block params for file id %d", exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,exerrval); goto error_ret; } elem_ctr = 0; for (i=0; i<num_elem_blks; i++) { ex_entity_id id; ex_block block; if (ex_int64_status(exoid) & EX_IDS_INT64_API) { id = ((int64_t*)elem_blk_ids)[i]; } else { id = ((int*)elem_blk_ids)[i]; } /* read in an element block parameter */ block.type = EX_ELEM_BLOCK; block.id = id; /* read in an element block parameter */ if ((ex_get_block_param (exoid, &block)) == -1) { sprintf(errmsg, "Error: failed to get element block %"PRId64" parameters in file id %d", block.id, exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,EX_MSG); return(EX_FATAL); } elem_blk_parms[i].num_elem_in_blk = block.num_entry; elem_blk_parms[i].num_nodes_per_elem = block.num_nodes_per_entry; elem_blk_parms[i].num_attr = block.num_attribute; for (m=0; m < strlen(block.topology); m++) { elem_blk_parms[i].elem_type[m] = toupper(block.topology[m]); } elem_blk_parms[i].elem_type[m] = '\0'; if (strncmp(elem_blk_parms[i].elem_type,"CIRCLE",3) == 0) { elem_blk_parms[i].elem_type_val = EX_EL_CIRCLE; elem_blk_parms[i].num_sides = 1; elem_blk_parms[i].num_nodes_per_side[0] = 1; } else if (strncmp(elem_blk_parms[i].elem_type,"SPHERE",3) == 0) { elem_blk_parms[i].elem_type_val = EX_EL_SPHERE; elem_blk_parms[i].num_sides = 1; elem_blk_parms[i].num_nodes_per_side[0] = 1; } else if (strncmp(elem_blk_parms[i].elem_type,"QUAD",3) == 0) { elem_blk_parms[i].elem_type_val = EX_EL_QUAD; elem_blk_parms[i].num_sides = 4; if (elem_blk_parms[i].num_nodes_per_elem == 4) { elem_blk_parms[i].num_nodes_per_side[0] = 2; elem_blk_parms[i].num_nodes_per_side[1] = 2; elem_blk_parms[i].num_nodes_per_side[2] = 2; elem_blk_parms[i].num_nodes_per_side[3] = 2; } else if (elem_blk_parms[i].num_nodes_per_elem == 5) { elem_blk_parms[i].num_nodes_per_side[0] = 2; elem_blk_parms[i].num_nodes_per_side[1] = 2; elem_blk_parms[i].num_nodes_per_side[2] = 2; elem_blk_parms[i].num_nodes_per_side[3] = 2; } else if (elem_blk_parms[i].num_nodes_per_elem == 9 || elem_blk_parms[i].num_nodes_per_elem == 8) { elem_blk_parms[i].num_nodes_per_side[0] = 3; elem_blk_parms[i].num_nodes_per_side[1] = 3; elem_blk_parms[i].num_nodes_per_side[2] = 3; elem_blk_parms[i].num_nodes_per_side[3] = 3; } else { EL_NODE_COUNT_ERROR; } } else if (strncmp(elem_blk_parms[i].elem_type,"TRIANGLE",3) == 0) { elem_blk_parms[i].elem_type_val = EX_EL_TRIANGLE; if (ndim == 2) { /* 2d TRIs */ elem_blk_parms[i].num_sides = 3; if (elem_blk_parms[i].num_nodes_per_elem == 3) { elem_blk_parms[i].num_nodes_per_side[0] = 2; elem_blk_parms[i].num_nodes_per_side[1] = 2; elem_blk_parms[i].num_nodes_per_side[2] = 2; } else if (elem_blk_parms[i].num_nodes_per_elem == 6) { elem_blk_parms[i].num_nodes_per_side[0] = 3; elem_blk_parms[i].num_nodes_per_side[1] = 3; elem_blk_parms[i].num_nodes_per_side[2] = 3; } } else if (ndim == 3) { /* 3d TRIs -- triangular shell*/ elem_blk_parms[i].num_sides = 5; /* 2 Faces and 3 Edges */ if (elem_blk_parms[i].num_nodes_per_elem == 3) { elem_blk_parms[i].num_nodes_per_side[0] = 3; elem_blk_parms[i].num_nodes_per_side[1] = 3; elem_blk_parms[i].num_nodes_per_side[2] = 2; elem_blk_parms[i].num_nodes_per_side[3] = 2; elem_blk_parms[i].num_nodes_per_side[4] = 2; } else if (elem_blk_parms[i].num_nodes_per_elem == 6) { elem_blk_parms[i].num_nodes_per_side[0] = 6; elem_blk_parms[i].num_nodes_per_side[1] = 6; elem_blk_parms[i].num_nodes_per_side[2] = 3; elem_blk_parms[i].num_nodes_per_side[3] = 3; elem_blk_parms[i].num_nodes_per_side[4] = 3; } else { EL_NODE_COUNT_ERROR; } } } else if (strncmp(elem_blk_parms[i].elem_type,"SHELL",3) == 0) { elem_blk_parms[i].elem_type_val = EX_EL_SHELL; if (elem_blk_parms[i].num_nodes_per_elem == 2) {/* KLUDGE for 2D Shells*/ elem_blk_parms[i].num_sides = 2; elem_blk_parms[i].num_nodes_per_side[0] = 2; elem_blk_parms[i].num_nodes_per_side[1] = 2; } else if (elem_blk_parms[i].num_nodes_per_elem == 4) { elem_blk_parms[i].num_sides = 6; /* 2 Faces, 4 Edges */ elem_blk_parms[i].num_nodes_per_side[0] = 4; elem_blk_parms[i].num_nodes_per_side[1] = 4; elem_blk_parms[i].num_nodes_per_side[2] = 2; elem_blk_parms[i].num_nodes_per_side[3] = 2; elem_blk_parms[i].num_nodes_per_side[4] = 2; elem_blk_parms[i].num_nodes_per_side[5] = 2; } else if (elem_blk_parms[i].num_nodes_per_elem == 8 || elem_blk_parms[i].num_nodes_per_elem == 9) { elem_blk_parms[i].num_sides = 6; /* 2 Faces, 4 Edges */ elem_blk_parms[i].num_nodes_per_side[0] = elem_blk_parms[i].num_nodes_per_elem; /* 8 or 9 */ elem_blk_parms[i].num_nodes_per_side[1] = elem_blk_parms[i].num_nodes_per_elem; /* 8 or 9 */ elem_blk_parms[i].num_nodes_per_side[2] = 3; elem_blk_parms[i].num_nodes_per_side[3] = 3; elem_blk_parms[i].num_nodes_per_side[4] = 3; elem_blk_parms[i].num_nodes_per_side[5] = 3; } else { EL_NODE_COUNT_ERROR; } } else if (strncmp(elem_blk_parms[i].elem_type,"HEX",3) == 0) { elem_blk_parms[i].elem_type_val = EX_EL_HEX; elem_blk_parms[i].num_sides = 6; /* determine side set node stride */ if (elem_blk_parms[i].num_nodes_per_elem == 8) { /* 8-node bricks */ elem_blk_parms[i].num_nodes_per_side[0] = 4; elem_blk_parms[i].num_nodes_per_side[1] = 4; elem_blk_parms[i].num_nodes_per_side[2] = 4; elem_blk_parms[i].num_nodes_per_side[3] = 4; elem_blk_parms[i].num_nodes_per_side[4] = 4; elem_blk_parms[i].num_nodes_per_side[5] = 4; } else if (elem_blk_parms[i].num_nodes_per_elem == 9) { /* 9-node bricks */ elem_blk_parms[i].num_nodes_per_side[0] = 4; elem_blk_parms[i].num_nodes_per_side[1] = 4; elem_blk_parms[i].num_nodes_per_side[2] = 4; elem_blk_parms[i].num_nodes_per_side[3] = 4; elem_blk_parms[i].num_nodes_per_side[4] = 4; elem_blk_parms[i].num_nodes_per_side[5] = 4; } else if (elem_blk_parms[i].num_nodes_per_elem == 12) { /* HEXSHELLS */ elem_blk_parms[i].num_nodes_per_side[0] = 6; elem_blk_parms[i].num_nodes_per_side[1] = 6; elem_blk_parms[i].num_nodes_per_side[2] = 6; elem_blk_parms[i].num_nodes_per_side[3] = 6; elem_blk_parms[i].num_nodes_per_side[4] = 4; elem_blk_parms[i].num_nodes_per_side[5] = 4; } else if (elem_blk_parms[i].num_nodes_per_elem == 20) { /* 20-node bricks */ elem_blk_parms[i].num_nodes_per_side[0] = 8; elem_blk_parms[i].num_nodes_per_side[1] = 8; elem_blk_parms[i].num_nodes_per_side[2] = 8; elem_blk_parms[i].num_nodes_per_side[3] = 8; elem_blk_parms[i].num_nodes_per_side[4] = 8; elem_blk_parms[i].num_nodes_per_side[5] = 8; } else if (elem_blk_parms[i].num_nodes_per_elem == 27) { /* 27-node bricks */ elem_blk_parms[i].num_nodes_per_side[0] = 9; elem_blk_parms[i].num_nodes_per_side[1] = 9; elem_blk_parms[i].num_nodes_per_side[2] = 9; elem_blk_parms[i].num_nodes_per_side[3] = 9; elem_blk_parms[i].num_nodes_per_side[4] = 9; elem_blk_parms[i].num_nodes_per_side[5] = 9; } else { EL_NODE_COUNT_ERROR; } } else if (strncmp(elem_blk_parms[i].elem_type,"TETRA",3) == 0) { elem_blk_parms[i].elem_type_val = EX_EL_TETRA; elem_blk_parms[i].num_sides = 4; /* determine side set node stride */ if (elem_blk_parms[i].num_nodes_per_elem == 4) { elem_blk_parms[i].num_nodes_per_side[0] = 3; elem_blk_parms[i].num_nodes_per_side[1] = 3; elem_blk_parms[i].num_nodes_per_side[2] = 3; elem_blk_parms[i].num_nodes_per_side[3] = 3; } else if (elem_blk_parms[i].num_nodes_per_elem == 8) { elem_blk_parms[i].num_nodes_per_side[0] = 4; elem_blk_parms[i].num_nodes_per_side[1] = 4; elem_blk_parms[i].num_nodes_per_side[2] = 4; elem_blk_parms[i].num_nodes_per_side[3] = 4; } else if (elem_blk_parms[i].num_nodes_per_elem == 10) { elem_blk_parms[i].num_nodes_per_side[0] = 6; elem_blk_parms[i].num_nodes_per_side[1] = 6; elem_blk_parms[i].num_nodes_per_side[2] = 6; elem_blk_parms[i].num_nodes_per_side[3] = 6; } else { EL_NODE_COUNT_ERROR; } } else if (strncmp(elem_blk_parms[i].elem_type,"WEDGE",3) == 0) { elem_blk_parms[i].elem_type_val = EX_EL_WEDGE; elem_blk_parms[i].num_sides = 5; if (elem_blk_parms[i].num_nodes_per_elem == 6) { elem_blk_parms[i].num_nodes_per_side[0] = 4; elem_blk_parms[i].num_nodes_per_side[1] = 4; elem_blk_parms[i].num_nodes_per_side[2] = 4; elem_blk_parms[i].num_nodes_per_side[3] = 3; elem_blk_parms[i].num_nodes_per_side[4] = 3; } else if (elem_blk_parms[i].num_nodes_per_elem == 15){ elem_blk_parms[i].num_nodes_per_side[0] = 8; elem_blk_parms[i].num_nodes_per_side[1] = 8; elem_blk_parms[i].num_nodes_per_side[2] = 8; elem_blk_parms[i].num_nodes_per_side[3] = 6; elem_blk_parms[i].num_nodes_per_side[4] = 6; } else { EL_NODE_COUNT_ERROR; } } else if (strncmp(elem_blk_parms[i].elem_type,"PYRAMID",3) == 0) { elem_blk_parms[i].elem_type_val = EX_EL_PYRAMID; elem_blk_parms[i].num_sides = 5; if (elem_blk_parms[i].num_nodes_per_elem == 5) { elem_blk_parms[i].num_nodes_per_side[0] = 3; elem_blk_parms[i].num_nodes_per_side[1] = 3; elem_blk_parms[i].num_nodes_per_side[2] = 3; elem_blk_parms[i].num_nodes_per_side[3] = 3; elem_blk_parms[i].num_nodes_per_side[4] = 4; } else if (elem_blk_parms[i].num_nodes_per_elem == 13){ elem_blk_parms[i].num_nodes_per_side[0] = 6; elem_blk_parms[i].num_nodes_per_side[1] = 6; elem_blk_parms[i].num_nodes_per_side[2] = 6; elem_blk_parms[i].num_nodes_per_side[3] = 6; elem_blk_parms[i].num_nodes_per_side[4] = 8; } else { EL_NODE_COUNT_ERROR; } } else if (strncmp(elem_blk_parms[i].elem_type,"BEAM",3) == 0) { elem_blk_parms[i].elem_type_val = EX_EL_BEAM; elem_blk_parms[i].num_sides = 2; if (elem_blk_parms[i].num_nodes_per_elem == 2) { elem_blk_parms[i].num_nodes_per_side[0] = 2; elem_blk_parms[i].num_nodes_per_side[1] = 2; } else if (elem_blk_parms[i].num_nodes_per_elem == 3){ elem_blk_parms[i].num_nodes_per_side[0] = 3; elem_blk_parms[i].num_nodes_per_side[1] = 3; } else { EL_NODE_COUNT_ERROR; } } else if ( (strncmp(elem_blk_parms[i].elem_type,"TRUSS",3) == 0) || (strncmp(elem_blk_parms[i].elem_type,"BAR",3) == 0) || (strncmp(elem_blk_parms[i].elem_type,"EDGE",3) == 0) ) { elem_blk_parms[i].elem_type_val = EX_EL_TRUSS; elem_blk_parms[i].num_sides = 2; if (elem_blk_parms[i].num_nodes_per_elem == 2) { elem_blk_parms[i].num_nodes_per_side[0] = 2; elem_blk_parms[i].num_nodes_per_side[1] = 2; } else if (elem_blk_parms[i].num_nodes_per_elem == 3) { elem_blk_parms[i].num_nodes_per_side[0] = 3; elem_blk_parms[i].num_nodes_per_side[1] = 3; } else { EL_NODE_COUNT_ERROR; } } /* Used for an empty block in a parallel decomposition */ else if (strncmp(elem_blk_parms[i].elem_type,"NULL",3) == 0) { elem_blk_parms[i].elem_type_val = EX_EL_NULL_ELEMENT; elem_blk_parms[i].num_sides = 0; elem_blk_parms[i].num_nodes_per_side[0] = 0; elem_blk_parms[i].num_elem_in_blk = 0; } else { /* unsupported element type; no problem if no sides specified for this element block */ elem_blk_parms[i].elem_type_val = EX_EL_UNK; elem_blk_parms[i].num_sides = 0; elem_blk_parms[i].num_nodes_per_side[0] = 0; } elem_blk_parms[i].elem_blk_id = id; /* save id */ elem_ctr += elem_blk_parms[i].num_elem_in_blk; elem_blk_parms[i].elem_ctr = elem_ctr; /* save elem number max */ } /* Finally... Create the list of node counts for each face in the * side set. */ /* Allocate space for the sideset ids */ if (!(side_set_ids=malloc(num_side_sets*ids_size))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate space for side set ids for file id %d", exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,exerrval); goto error_ret; } if (ex_get_ids(exoid, EX_SIDE_SET, side_set_ids) == -1) { sprintf(errmsg, "Error: failed to get side set ids in file id %d", exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,EX_MSG); goto error_ret; } /* Lookup index of side set id in VAR_SS_IDS array */ ioff = 0; for (iss=0; iss<num_side_sets; iss++) { if (ex_int64_status(exoid) & EX_IDS_INT64_API) { side_set_id = ((int64_t*)side_set_ids)[iss]; } else { side_set_id = ((int*)side_set_ids)[iss]; } /* First determine the # of elements in the side set*/ if (int_size == sizeof(int64_t)) { status = ex_get_set_param(exoid,EX_SIDE_SET, side_set_id,&tot_num_ss_elem,&num_df); } else { int tot, df; status = ex_get_set_param(exoid,EX_SIDE_SET, side_set_id,&tot,&df); tot_num_ss_elem = tot; num_df = df; } if (status != EX_NOERR) { sprintf(errmsg, "Error: failed to get number of elements in side set %"PRId64" in file id %d", side_set_id, exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,exerrval); goto error_ret; } if (tot_num_ss_elem == 0) continue; /* Allocate space for the side set element list */ if (!(side_set_elem_list=malloc(tot_num_ss_elem*int_size))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate space for side set element list for file id %d", exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,exerrval); goto error_ret; } /* Allocate space for the side set side list */ if (!(side_set_side_list=malloc(tot_num_ss_elem*int_size))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate space for side set side list for file id %d", exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,exerrval); goto error_ret; } if (ex_get_set(exoid, EX_SIDE_SET, side_set_id, side_set_elem_list, side_set_side_list) == -1) { sprintf(errmsg, "Error: failed to get side set %"PRId64" in file id %d", side_set_id, exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,exerrval); goto error_ret; } /* Allocate space for the ss element index array */ if (!(ss_elem_ndx=malloc(tot_num_ss_elem*int_size))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate space for side set elem sort array for file id %d", exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,exerrval); goto error_ret; } /* Sort side set element list into index array - non-destructive */ if (int_size == sizeof(int64_t)) { /* Sort side set element list into index array - non-destructive */ int64_t *elems = (int64_t*)ss_elem_ndx; for (i=0;i<tot_num_ss_elem;i++) { elems[i] = i; /* init index array to current position */ } ex_iqsort64(side_set_elem_list, ss_elem_ndx,tot_num_ss_elem); } else { /* Sort side set element list into index array - non-destructive */ int *elems = (int*)ss_elem_ndx; for (i=0;i<tot_num_ss_elem;i++) { elems[i] = i; /* init index array to current position */ } ex_iqsort(side_set_elem_list, ss_elem_ndx,tot_num_ss_elem); } j = 0; /* The current element block... */ for (ii=0;ii<tot_num_ss_elem;ii++) { int64_t elem_ndx; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { elem_ndx = ((int64_t*)ss_elem_ndx)[ii]; elem = ((int64_t*)side_set_elem_list)[elem_ndx]; side = ((int64_t*)side_set_side_list)[elem_ndx]-1; } else { elem_ndx = ((int*)ss_elem_ndx)[ii]; elem = ((int*)side_set_elem_list)[elem_ndx]; side = ((int*)side_set_side_list)[elem_ndx]-1; } /* * Since the elements are being accessed in sorted, order, the * block that contains the elements must progress sequentially * from block 0 to block[num_elem_blks-1]. Once we find an element * not in this block, find a following block that contains it... */ for ( ; j<num_elem_blks; j++) { if (elem <= elem_blk_parms[j].elem_ctr) { break; } } if (j < num_elem_blks) { assert(side < elem_blk_parms[j].num_sides); side_set_node_cnt_list[elem_ndx+ioff] = elem_blk_parms[j].num_nodes_per_side[side]; } else { exerrval = EX_BADPARAM; sprintf(errmsg, "Error: Invalid element number %"PRId64" found in side set %"PRId64" in file %d", elem, side_set_id, exoid); ex_err("ex_get_concat_side_set_node_count",errmsg,EX_MSG); goto error_ret; } } ss_elem_ndx = safe_free(ss_elem_ndx); side_set_elem_list = safe_free(side_set_elem_list); side_set_side_list = safe_free(side_set_side_list); ioff += tot_num_ss_elem; } /* All done: release allocated memory */ safe_free(elem_blk_ids); safe_free(side_set_ids); return(EX_NOERR); error_ret: safe_free(elem_blk_ids); safe_free(side_set_ids); safe_free(ss_elem_ndx); safe_free(side_set_elem_list); safe_free(side_set_side_list); return (EX_FATAL); }
char *do_exodus_meta(char *filename) { int exoid; int ndim, nnodes, nelems, nblks, nnsets, nssets; char *title; symrec *ptr; int *ids = NULL; /* * Open the specified exodusII file, read the metadata and set * variables for each item. * Examples include "node_count", "element_count", ... */ exoid = open_exodus_file(filename); if (exoid < 0) return ""; /* read database paramters */ title = (char *)calloc ((MAX_LINE_LENGTH+1),sizeof(char *)); ex_get_init(exoid,title,&ndim,&nnodes,&nelems,&nblks,&nnsets,&nssets); ptr = putsym("ex_title", SVAR, 0); ptr->value.svar = title; ptr = putsym("ex_dimension", VAR, 0); ptr->value.var = ndim; ptr = putsym("ex_node_count", VAR, 0); ptr->value.var = nnodes; ptr = putsym("ex_element_count", VAR, 0); ptr->value.var = nelems; ptr = putsym("ex_block_count", VAR, 0); ptr->value.var = nblks; ptr = putsym("ex_nset_count", VAR, 0); ptr->value.var = nnsets; ptr = putsym("ex_sset_count", VAR, 0); ptr->value.var = nssets; { /* Nemesis Information */ int proc_count; int proc_in_file; char file_type[MAX_STR_LENGTH+1]; int global_nodes; int global_elements; int global_blocks; int global_nsets; int global_ssets; int error; error = ex_get_init_info(exoid, &proc_count, &proc_in_file, file_type); if (error >= 0) { ptr = putsym("ex_processor_count", VAR, 0); ptr->value.var = proc_count; ex_get_init_global(exoid, &global_nodes, &global_elements, &global_blocks, &global_nsets, &global_ssets); ptr = putsym("ex_node_count_global", VAR, 0); ptr->value.var = global_nodes; ptr = putsym("ex_element_count_global", VAR, 0); ptr->value.var = global_elements; } } /* * Read The Element Blocks And Set Variables For Those Also. * The Scheme Is: * -- 'Ex_Block_Ids' Is A List Of Ids. Due To Aprepro Limitations, * This List Is A String, Not An Integer List... * -- Each Block Is Named 'Ex_Block_X' Where X Is Replaced By The * Blocks Position In The List. For Example, The First Block Will * Be Named 'Ex_Block_1' * * -- Each Block Will Have The Following Symbols: * -- Ex_Block_X_Id = Id Of This Element Block * -- Ex_Block_X_Name = Composed Name "Block_" + Id * -- Ex_Block_X_Element_Count = Number Of Elements In Block * -- Ex_Block_X_Nodes_Per_Element = Number Of Nodes Per Element * -- Ex_Block_X_Topology = Type Of Elements In Block * (Lowercased) * -- Ex_Block_X_Attribute_Count = Number Of Attributes. */ ids = malloc(nblks * sizeof(int)); ex_get_elem_blk_ids (exoid, ids); { int i; char *buffer = NULL; char cid[33]; /* arbitrary size, large enough for INT_MAX */ int size = 2048; char *tmp = NULL; buffer = calloc(size, sizeof(char)); if (buffer != NULL) { for (i=0; i < nblks; i++) { sprintf(cid, "%d ", ids[i]); if (strlen(buffer) + strlen(cid) +1 > size) { if (realloc(buffer, size *=2) == NULL) { free(buffer); yyerror("Error allocating memory."); } memset(&buffer[size/2], 0, size/2); } strcat(buffer, cid); } NEWSTR(buffer, tmp); ptr = putsym("ex_block_ids", SVAR, 0); ptr->value.svar = tmp; free(buffer); } } { int i; char var[128]; char type[MAX_STR_LENGTH+1]; char *tmp = NULL; int nel; int nnel; int natr; for (i=0; i < nblks; i++) { ex_get_elem_block(exoid, ids[i], type, &nel, &nnel, &natr); sprintf(var, "ex_block_seq_%d_id", i+1); ptr = putsym(var, VAR, 0); ptr->value.var = ids[i]; sprintf(var, "ex_block_%d_name", ids[i]); ptr = putsym(var, SVAR, 0); sprintf(var, "block_%d", ids[i]); NEWSTR(var, tmp); ptr->value.svar = tmp; sprintf(var, "ex_block_%d_element_count", ids[i]); ptr = putsym(var, VAR, 0); ptr->value.var = nel; sprintf(var, "ex_block_%d_nodes_per_element", ids[i]); ptr = putsym(var, VAR, 0); ptr->value.var = nnel; sprintf(var, "ex_block_%d_topology", ids[i]); ptr = putsym(var, SVAR, 0); NEWSTR(type, tmp); /* lowercase the string */ LowerCaseTrim(tmp); ptr->value.svar = tmp; sprintf(var, "ex_block_%d_attribute_count", ids[i]); ptr = putsym(var, VAR, 0); ptr->value.var = natr; } } if (ids != NULL) free(ids); { /* Get timestep count */ int ts_count = ex_inquire_int(exoid, EX_INQ_TIME); ptr = putsym("ex_timestep_count", VAR, 0); ptr->value.var = ts_count; if (ts_count > 0) { int i; symrec *format = getsym("_FORMAT"); char *buffer = NULL; char cid[33]; /* arbitrary size, large enough for double... */ int size = 2048; char *tmp = NULL; double *timesteps = malloc(ts_count * sizeof(double)); ex_get_all_times(exoid, timesteps); buffer = calloc(size, sizeof(char)); if (buffer != NULL) { for (i=0; i < ts_count; i++) { sprintf(cid, format->value.svar, timesteps[i]); if (strlen(buffer) + strlen(cid) +2 > size) { if (realloc(buffer, size *=2) == NULL) { free(buffer); yyerror("Error allocating memory."); } memset(&buffer[size/2], 0, size/2); } strcat(buffer, cid); strcat(buffer, " "); } NEWSTR(buffer, tmp); ptr = putsym("ex_timestep_times", SVAR, 0); ptr->value.svar = tmp; free(buffer); } } } ex_close(exoid); return ""; }
int ex_get_concat_sets(int exoid, ex_entity_type set_type, struct ex_set_specs *set_specs) { int status, dimid; void_int *num_entries_per_set = set_specs->num_entries_per_set; void_int *num_dist_per_set = set_specs->num_dist_per_set; void_int *sets_entry_index = set_specs->sets_entry_index; void_int *sets_dist_index = set_specs->sets_dist_index; void *sets_dist_fact = set_specs->sets_dist_fact; int num_sets, i; float * flt_dist_fact; double * dbl_dist_fact; char errmsg[MAX_ERR_LENGTH]; ex_inquiry ex_inq_val; exerrval = 0; /* clear error code */ /* setup pointers based on set_type NOTE: there is another block that sets more stuff later ... */ if (set_type == EX_NODE_SET) { ex_inq_val = EX_INQ_NODE_SETS; } else if (set_type == EX_EDGE_SET) { ex_inq_val = EX_INQ_EDGE_SETS; } else if (set_type == EX_FACE_SET) { ex_inq_val = EX_INQ_FACE_SETS; } else if (set_type == EX_SIDE_SET) { ex_inq_val = EX_INQ_SIDE_SETS; } else if (set_type == EX_ELEM_SET) { ex_inq_val = EX_INQ_ELEM_SETS; } else { exerrval = EX_FATAL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: invalid set type (%d)", set_type); ex_err("ex_get_concat_sets", errmsg, exerrval); return (EX_FATAL); } /* first check if any sets are specified */ if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(set_type), &dimid)) != NC_NOERR) { exerrval = status; if (status == NC_EBADDIM) { snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no %ss defined for file id %d", ex_name_of_object(set_type), exoid); ex_err("ex_get_concat_sets", errmsg, exerrval); return (EX_WARN); } snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %ss defined in file id %d", ex_name_of_object(set_type), exoid); ex_err("ex_get_concat_sets", errmsg, exerrval); return (EX_FATAL); } /* inquire how many sets have been stored */ num_sets = ex_inquire_int(exoid, ex_inq_val); if (num_sets < 0) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of %ss defined for file id %d", ex_name_of_object(set_type), exoid); /* use error val from inquire */ ex_err("ex_get_concat_sets", errmsg, exerrval); return (EX_FATAL); } if (ex_get_ids(exoid, set_type, set_specs->sets_ids) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s ids for file id %d", ex_name_of_object(set_type), exoid); /* use error val from inquire */ ex_err("ex_get_concat_sets", errmsg, exerrval); return (EX_FATAL); } if (ex_int64_status(exoid) & EX_IDS_INT64_API) { ((int64_t *)sets_entry_index)[0] = 0; ((int64_t *)sets_dist_index)[0] = 0; } else { ((int *)sets_entry_index)[0] = 0; ((int *)sets_dist_index)[0] = 0; } for (i = 0; i < num_sets; i++) { int set_id; if (ex_int64_status(exoid) & EX_IDS_INT64_API) { set_id = ((int64_t *)set_specs->sets_ids)[i]; } else { set_id = ((int *)set_specs->sets_ids)[i]; } if (ex_int64_status(exoid) & EX_BULK_INT64_API) { if (ex_get_set_param(exoid, set_type, set_id, &(((int64_t *)num_entries_per_set)[i]), &(((int64_t *)num_dist_per_set)[i])) != NC_NOERR) { return (EX_FATAL); /* error will be reported by sub */ } if (i < num_sets - 1) { /* fill in entry and dist factor index arrays */ ((int64_t *)sets_entry_index)[i + 1] = ((int64_t *)sets_entry_index)[i] + ((int64_t *)num_entries_per_set)[i]; ((int64_t *)sets_dist_index)[i + 1] = ((int64_t *)sets_dist_index)[i] + ((int64_t *)num_dist_per_set)[i]; } if (((int64_t *)num_entries_per_set)[i] == 0) { /* NULL set? */ continue; } { /* Now, use ExodusII call to get sets */ int64_t *sets_entry_list = set_specs->sets_entry_list; int64_t *sets_extra_list = set_specs->sets_extra_list; int64_t *sets_extra = sets_extra_list ? &((int64_t *)sets_extra_list)[((int64_t *)sets_entry_index)[i]] : NULL; status = ex_get_set(exoid, set_type, set_id, &(sets_entry_list[((int64_t *)sets_entry_index)[i]]), sets_extra); } } else { if (ex_get_set_param(exoid, set_type, set_id, &(((int *)num_entries_per_set)[i]), &(((int *)num_dist_per_set)[i])) != NC_NOERR) { return (EX_FATAL); /* error will be reported by sub */ } if (i < num_sets - 1) { /* fill in entry and dist factor index arrays */ ((int *)sets_entry_index)[i + 1] = ((int *)sets_entry_index)[i] + ((int *)num_entries_per_set)[i]; ((int *)sets_dist_index)[i + 1] = ((int *)sets_dist_index)[i] + ((int *)num_dist_per_set)[i]; } if (((int *)num_entries_per_set)[i] == 0) { /* NULL set? */ continue; } { /* Now, use ExodusII call to get sets */ int *sets_entry_list = set_specs->sets_entry_list; int *sets_extra_list = set_specs->sets_extra_list; int *sets_extra = sets_extra_list ? &((int *)sets_extra_list)[((int *)sets_entry_index)[i]] : NULL; status = ex_get_set(exoid, set_type, set_id, &(sets_entry_list[((int *)sets_entry_index)[i]]), sets_extra); } } if (status != NC_NOERR) { return (EX_FATAL); /* error will be reported by subroutine */ } /* get distribution factors for this set */ if (sets_dist_fact != 0) { size_t df_idx; size_t num_dist; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { df_idx = ((int64_t *)sets_dist_index)[i]; num_dist = ((int64_t *)num_dist_per_set)[i]; } else { df_idx = ((int *)sets_dist_index)[i]; num_dist = ((int *)num_dist_per_set)[i]; } if (num_dist > 0) { /* only get df if they exist */ if (ex_comp_ws(exoid) == sizeof(float)) { flt_dist_fact = sets_dist_fact; status = ex_get_set_dist_fact(exoid, set_type, set_id, &(flt_dist_fact[df_idx])); } else { dbl_dist_fact = sets_dist_fact; status = ex_get_set_dist_fact(exoid, set_type, set_id, &(dbl_dist_fact[df_idx])); } if (status != NC_NOERR) { return (EX_FATAL); /* error will be reported by subroutine */ } } } } return (EX_NOERR); }
/* // Read and EXODUSII database and return a TECPLOT file */ void tec(int exoid, const char *filename) { int i, j, k, idum; int ndim, nnode, nelem, nblk, nnset, neset, nvar, ntime, itime; char title[MAX_LINE_LENGTH + 1]; char * nameco[3], **varnames = NULL; double *x[3], **q = NULL, *time; int * elem_id = NULL, *node_per_elem = NULL, *elem_per_blk = NULL, *attr_per_blk = NULL; int ** icon = NULL, *ic = NULL, izone; char ** elem_type = NULL; int name_size = 0; FILE * tecfile = NULL; void teczone(int, int, int, char *, int, int, int *, int, double **, int, double **, FILE *); /* * FIRST, READ THE EXODUS DATA BASE */ /* * Open the output file, if we can */ tecfile = fopen(filename, "w"); if (tecfile == NULL) { printf("\nCannot open file %s for writing\n\n", filename); exit(1); } /* * Determine max name size used in databsae... */ name_size = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH); ex_set_max_name_length(exoid, name_size); /* * Read database size, get coordinates and connectivity */ memset(title, 0, MAX_LINE_LENGTH + 1); ex_get_init(exoid, title, &ndim, &nnode, &nelem, &nblk, &nnset, &neset); x[0] = x[1] = x[2] = NULL; for (i = 0; i < ndim; i++) { nameco[i] = (char *)malloc((name_size + 1) * sizeof(char)); x[i] = (double *)malloc(nnode * sizeof(double)); } ex_get_coord_names(exoid, nameco); if (strlen(nameco[0]) == 0) strcpy(nameco[0], "X"); if (strlen(nameco[1]) == 0) strcpy(nameco[1], "Y"); if (ndim > 2) if (strlen(nameco[2]) == 0) strcpy(nameco[2], "Z"); ex_get_coord(exoid, x[0], x[1], x[2]); elem_id = (int *)malloc(nblk * sizeof(int)); node_per_elem = (int *)malloc(nblk * sizeof(int)); elem_per_blk = (int *)malloc(nblk * sizeof(int)); attr_per_blk = (int *)malloc(nblk * sizeof(int)); elem_type = (char **)malloc(nblk * sizeof(char *)); icon = (int **)malloc(nblk * sizeof(int *)); for (i = 0; i < nblk; i++) elem_type[i] = (char *)malloc((name_size + 1) * sizeof(char)); ex_get_elem_blk_ids(exoid, elem_id); for (i = 0; i < nblk; i++) { ex_get_elem_block(exoid, elem_id[i], elem_type[i], &elem_per_blk[i], &node_per_elem[i], &attr_per_blk[i]); icon[i] = (int *)malloc(elem_per_blk[i] * node_per_elem[i] * sizeof(int)); ex_get_elem_conn(exoid, elem_id[i], icon[i]); } /* * Read time step information */ ntime = ex_inquire_int(exoid, EX_INQ_TIME); if (ntime > 0) { time = (double *)malloc(ntime * sizeof(double)); ex_get_all_times(exoid, time); } /* * Read number of nodal variables and save space */ nvar = 0; ex_get_var_param(exoid, "n", &nvar); if (nvar > 0) { varnames = (char **)malloc(nvar * sizeof(char *)); q = (double **)malloc(nvar * sizeof(double *)); for (i = 0; i < nvar; i++) { varnames[i] = (char *)malloc((name_size + 1) * sizeof(char)); q[i] = (double *)malloc(nnode * sizeof(double)); } ex_get_var_names(exoid, "n", nvar, varnames); } /* ///////////////////////////////////////////////////////////////////// // PROMPT USER FOR INFO AND WRITE TECPLOT FILE ///////////////////////////////////////////////////////////////////// */ /* * Write the TECPLOT header information */ assert(strlen(title) < (MAX_LINE_LENGTH + 1)); fprintf(tecfile, "TITLE = \"%s\"\n", title); fprintf(tecfile, "VARIABLES = "); for (i = 0; i < ndim; i++) { fprintf(tecfile, "\"%s\"", nameco[i]); if (i < (ndim - 1)) fprintf(tecfile, ", "); } if (nvar == 0) fprintf(tecfile, "\n"); else fprintf(tecfile, ",\n "); idum = 0; for (i = 0; i < nvar; i++) { idum += strlen(varnames[i]); assert(idum < 1022); fprintf(tecfile, "\"%s\"", varnames[i]); if (i < (nvar - 1)) { if ((i + 1) % 4 == 0) { idum = 0; fprintf(tecfile, ",\n "); } else fprintf(tecfile, ", "); } } fprintf(tecfile, "\n"); /* * Select a time step */ izone = 0; if (ntime == 0) { printf("\nNo solution variables available, saving mesh only\n\n"); izone = 1; } else { printf("\nTime step information:\n\n"); for (i = 0; i < ntime; i++) printf(" Time step %5d, time = %e\n", i + 1, time[i]); do { printf("\nSelect time step number to save,\n"); printf(" or 0 for zone animation of all time steps: "); scanf("%d", &itime); printf("\n"); } while (itime < 0 || itime > ntime); printf("\n"); if (itime == 0) izone = 0; else izone = 1; } /* * Write time steps */ if (izone == 0) { /* * Collapse the zones into one */ /* * Make sure we are using all the same element types * Create one master connectivity array */ for (i = 1; i < nblk; i++) if (strcmp(elem_type[0], elem_type[i]) != 0) { printf("\nCannot create zone animation because\n"); ; printf("\n there are multiple element types."); exit(1); } ic = (int *)malloc(nelem * node_per_elem[0] * sizeof(int)); k = 0; for (j = 0; j < nblk; j++) for (i = 0; i < node_per_elem[j] * elem_per_blk[j]; i++) ic[k++] = icon[j][i]; assert(k == nelem * node_per_elem[0]); if (itime == 0) { for (j = 0; j < ntime; j++) { for (i = 0; i < nvar; i++) ex_get_nodal_var(exoid, j + 1, i + 1, nnode, q[i]); i = 0; teczone(1, nnode, j + 1, elem_type[i], node_per_elem[i], nelem, ic, ndim, x, nvar, q, tecfile); } printf("\n"); } free(ic); } else if (izone == 1) { /* || Write out each zone individually */ for (i = 0; i < nvar; i++) ex_get_nodal_var(exoid, itime, i + 1, nnode, q[i]); for (i = 0; i < nblk; i++) teczone(nblk, nnode, elem_id[i], elem_type[i], node_per_elem[i], elem_per_blk[i], icon[i], ndim, x, nvar, q, tecfile); printf("\n"); } /* ///////////////////////////////////////////////////////////////////// // CLEAN UP ///////////////////////////////////////////////////////////////////// */ fclose(tecfile); /* * Free up allocated memory */ for (i = 0; i < ndim; i++) { free(nameco[i]); free(x[i]); } free(elem_id); free(node_per_elem); free(elem_per_blk); free(attr_per_blk); if (elem_type != NULL) { for (i = 0; i < nblk; i++) { free(elem_type[i]); } free(elem_type); } if (icon != NULL) { for (i = 0; i < nblk; i++) { free(icon[i]); } free(icon); } if (nvar > 0) { if (varnames != NULL) { for (i = 0; i < nvar; i++) { free(varnames[i]); } free(varnames); } if (q != NULL) { for (i = 0; i < nvar; i++) { free(q[i]); } free(q); } } }
int main (int argc, char *argv[]) { char *str,**str2,*(*qa_records)[4],*line, *oname, *dot, *filename; const char* ext=EXT; int i,j,k,n,n1,n2,cpu_word_size,io_word_size,exo_file,err, num_axes,num_nodes,num_elements,num_blocks, num_side_sets,num_node_sets,num_time_steps, num_qa_lines,num_info_lines,num_global_vars, num_nodal_vars,num_element_vars,num_nodeset_vars, num_sideset_vars, *ids,*iscr,*num_elem_in_block,*junk, *elem_list,*side_list, *nsssides,*nssdfac, *nnsnodes,*nnsdfac, nstr2, has_ss_dfac; float exo_version; double *scr,*x,*y,*z; oname=0; /* process arguments */ for (j=1; j< argc; j++){ if ( strcmp(argv[j],"-t")==0){ /* write text file (*.m) */ del_arg(&argc,argv,j); textfile=1; j--; continue; } if ( strcmp(argv[j],"-o")==0){ /* specify output file name */ del_arg(&argc,argv,j); if ( argv[j] ){ oname=(char*)calloc(strlen(argv[j])+10,sizeof(char)); strcpy(oname,argv[j]); del_arg(&argc,argv,j); printf("output file: %s\n",oname); } else { fprintf(stderr,"Invalid output file specification.\n"); return 2; } j--; continue; } } /* QA Info */ printf("%s: %s, %s\n", qainfo[0], qainfo[2], qainfo[1]); /* usage message*/ if(argc != 2){ printf("%s [options] exodus_file_name.\n",argv[0]); printf(" the exodus_file_name is required (exodusII only).\n"); printf(" Options:\n"); printf(" -t write a text (.m) file rather than a binary .mat\n"); printf(" -o output file name (rather than auto generate)\n"); printf(" ** note **\n"); printf("Binary files are written by default on all platforms with"); printf(" available libraries.\n"); exit(1); } /* open output file */ if ( textfile ) ext=".m"; if ( !oname ){ filename = (char*)malloc( strlen(argv[1])+10); strcpy(filename,argv[1]); dot=strrchr(filename,'.'); if ( dot ) *dot=0; strcat(filename,ext); } else { filename=oname; } if ( textfile ){ m_file = fopen(filename,"w"); if (!m_file ){ fprintf(stderr,"Unable to open %s\n",filename); exit(1); } } else { mat_file = Mat_CreateVer(filename, NULL, MAT_FT_MAT5); if (mat_file == NULL) { fprintf(stderr,"Unable to create matlab file %s\n",filename); exit(1); } } /* word sizes */ cpu_word_size=sizeof(double); io_word_size=0; /* open exodus file */ exo_file=ex_open(argv[1],EX_READ,&cpu_word_size,&io_word_size,&exo_version); if (exo_file < 0){ printf("error opening %s\n",argv[1]); exit(1); } /* print */ fprintf(stderr,"translating %s to %s ...\n",argv[1],filename); /* read database paramters */ line=(char *) calloc ((MAX_LINE_LENGTH+1),sizeof(char *)); err = ex_get_init(exo_file,line, &num_axes,&num_nodes,&num_elements,&num_blocks, &num_node_sets,&num_side_sets); num_qa_lines = ex_inquire_int(exo_file,EX_INQ_QA); num_info_lines = ex_inquire_int(exo_file,EX_INQ_INFO); num_time_steps = ex_inquire_int(exo_file,EX_INQ_TIME); err=ex_get_variable_param(exo_file,EX_GLOBAL,&num_global_vars); err=ex_get_variable_param(exo_file,EX_NODAL,&num_nodal_vars); err=ex_get_variable_param(exo_file,EX_ELEM_BLOCK,&num_element_vars); err=ex_get_variable_param(exo_file,EX_NODE_SET,&num_nodeset_vars); err=ex_get_variable_param(exo_file,EX_SIDE_SET,&num_sideset_vars); /* export paramters */ PutInt("naxes", 1, 1,&num_axes); PutInt("nnodes", 1, 1,&num_nodes); PutInt("nelems", 1, 1,&num_elements); PutInt("nblks", 1, 1,&num_blocks); PutInt("nnsets", 1, 1,&num_node_sets); PutInt("nssets", 1, 1,&num_side_sets); PutInt("nsteps", 1, 1,&num_time_steps); PutInt("ngvars", 1, 1,&num_global_vars); PutInt("nnvars", 1, 1,&num_nodal_vars); PutInt("nevars", 1, 1,&num_element_vars); PutInt("nnsvars", 1, 1,&num_nodeset_vars); PutInt("nssvars", 1, 1,&num_sideset_vars); /* allocate -char- scratch space*/ n = num_info_lines; n = (n > num_global_vars) ? n : num_global_vars; n = (n > num_nodal_vars) ? n : num_nodal_vars; n = (n > num_element_vars) ? n : num_element_vars; n = (n > num_blocks) ? n : num_blocks; nstr2 = n; str2= (char **) calloc (n,sizeof(char *)); for (i=0;i<nstr2;i++) str2[i]=(char *) calloc ((MAX_LINE_LENGTH+1),sizeof(char)); str= (char *) calloc ((MAX_LINE_LENGTH+1)*n,sizeof(char *)); /* title */ PutStr("Title",line); /* QA records */ if (num_qa_lines > 0 ){ qa_records =(char *(*)[4]) calloc (num_qa_lines*4,sizeof(char **)); for (i=0;i<num_qa_lines;i++) for (j=0;j<4;j++) qa_records[i][j]=(char *) calloc ((MAX_STR_LENGTH+1),sizeof(char)); err=ex_get_qa(exo_file,qa_records); str[0]='\0'; for (i=0;i<num_qa_lines;i++){ for (j=0;j<4;j++) sprintf(str+strlen(str),"%s ",qa_records[i][j]); strcat(str,"\n"); } for (i=0;i<num_qa_lines;i++){ for (j=0;j<4;j++) free(qa_records[i][j]); } free(qa_records); } /* information records */ if (num_info_lines > 0 ){ err = ex_get_info(exo_file,str2); str[0]='\0'; for (i=0;i<num_info_lines;i++) sprintf(str+strlen(str),"%s\n",str2[i]); PutStr("info",str); str[0]='\0'; for (i=0;i<num_info_lines;i++) if (strncmp(str2[i],"cavi",4)==0) sprintf(str+strlen(str),"%s\n",str2[i]); PutStr("cvxp",str); } /* nodal coordinates */ x = (double *) calloc(num_nodes,sizeof(double)); y = (double *) calloc(num_nodes,sizeof(double)); if (num_axes == 3) z = (double *) calloc(num_nodes,sizeof(double)); else z = NULL; err = ex_get_coord(exo_file,x,y,z); PutDbl("x0", num_nodes, 1, x); PutDbl("y0", num_nodes, 1, y); free(x); free(y); if (num_axes == 3){ PutDbl("z0",num_nodes,1, z); free(z); } /* side sets */ if(num_side_sets > 0){ ids=(int *) calloc(num_side_sets,sizeof(int)); err = ex_get_ids(exo_file,EX_SIDE_SET,ids); PutInt( "ssids",num_side_sets, 1,ids); nsssides = (int *) calloc(num_side_sets,sizeof(int)); /*dgriffi */ nssdfac = (int *) calloc(num_side_sets,sizeof(int)); /*dgriffi */ for (i=0;i<num_side_sets;i++){ err = ex_get_set_param(exo_file,EX_SIDE_SET, ids[i],&n1,&n2); nsssides[i]=n1; /* dgriffi */ nssdfac[i]=n2; /* dgriffi */ /* * the following provision is from Version 1.6 when there are no * distribution factors in exodus file */ has_ss_dfac = (n2 != 0); if(n2==0 || n1==n2){ printf(" WARNING: Exodus II file does not contain distribution factors.\n"); /* n1=number of faces, n2=number of df */ /* using distribution factors to determine number of nodes in the sideset causes a lot grief since some codes do not output distribution factors if they are all equal to 1. mkbhard: I am using the function call below to figure out the total number of nodes in this sideset. Some redundancy exists, but it works for now */ junk = (int*) calloc(n1,sizeof(int)); err = ex_get_side_set_node_count(exo_file,ids[i],junk); n2=0; /* n2 will be equal to the total number of nodes in the sideset */ for (j=0;j<n1;j++) n2+=junk[j]; free(junk); } iscr = (int *) calloc(n1+n2,sizeof(int)); err = ex_get_side_set_node_list(exo_file,ids[i],iscr,iscr+n1); /* number-of-nodes-per-side list */ sprintf(str,"ssnum%02d",i+1); PutInt(str,n1,1,iscr); /* nodes list */ sprintf(str,"ssnod%02d",i+1); PutInt(str,n2,1,iscr+n1); free(iscr); /* distribution-factors list */ scr = (double *) calloc (n2,sizeof(double)); if (has_ss_dfac) { ex_get_side_set_dist_fact(exo_file,ids[i],scr); } else { for (j=0; j<n2; j++) { scr[j] = 1.0; } } sprintf(str,"ssfac%02d",i+1); PutDbl(str,n2,1,scr); free(scr); /* element and side list for side sets (dgriffi) */ elem_list = (int *) calloc(n1, sizeof(int)); side_list = (int *) calloc(n1, sizeof(int)); err = ex_get_set(exo_file,EX_SIDE_SET,ids[i],elem_list,side_list); sprintf(str,"ssside%02d",i+1); PutInt(str,n1,1,side_list); sprintf(str,"sselem%02d",i+1); PutInt(str,n1,1,elem_list); free(elem_list); free(side_list); } /* Store # sides and # dis. factors per side set (dgriffi) */ PutInt("nsssides",num_side_sets,1,nsssides); PutInt("nssdfac",num_side_sets,1,nssdfac); free(ids); free(nsssides); free(nssdfac); } /* node sets (section by dgriffi) */ if(num_node_sets > 0){ ids=(int *) calloc(num_node_sets,sizeof(int)); err = ex_get_ids(exo_file,EX_NODE_SET, ids); PutInt( "nsids",num_node_sets, 1,ids); nnsnodes = (int *) calloc(num_node_sets,sizeof(int)); nnsdfac = (int *) calloc(num_node_sets,sizeof(int)); for (i=0;i<num_node_sets;i++){ err = ex_get_set_param(exo_file,EX_NODE_SET,ids[i],&n1,&n2); iscr = (int *) calloc(n1,sizeof(int)); err = ex_get_node_set(exo_file,ids[i],iscr); /* nodes list */ sprintf(str,"nsnod%02d",i+1); PutInt(str,n1,1,iscr); free(iscr); /* distribution-factors list */ scr = (double *) calloc (n2,sizeof(double)); ex_get_node_set_dist_fact(exo_file,ids[i],scr); sprintf(str,"nsfac%02d",i+1); PutDbl(str,n2,1,scr); free(scr); nnsnodes[i]=n1; nnsdfac[i]=n2; } /* Store # nodes and # dis. factors per node set */ PutInt("nnsnodes",num_node_sets,1,nnsnodes); PutInt("nnsdfac",num_node_sets,1,nnsdfac); free(ids); free(nnsdfac); free(nnsnodes); } /* element blocks */ ids=(int *) calloc(num_blocks,sizeof(int)); num_elem_in_block=(int *) calloc(num_blocks,sizeof(int)); err = ex_get_ids(exo_file,EX_ELEM_BLOCK,ids); PutInt( "blkids",num_blocks, 1,ids); for (i=0;i<num_blocks;i++) { err = ex_get_elem_block(exo_file,ids[i],str2[i],&n,&n1,&n2); num_elem_in_block[i]=n; iscr = (int *) calloc(n*n1,sizeof(int)); err = ex_get_conn(exo_file,EX_ELEM_BLOCK,ids[i],iscr, NULL, NULL); sprintf(str,"blk%02d",i+1); PutInt(str,n1,n,iscr); free(iscr); } str[0]='\0'; for (i=0;i<num_blocks;i++) sprintf(str+strlen(str),"%s\n",str2[i]); PutStr("blknames",str); /* time values */ if (num_time_steps > 0 ) { scr = (double *) calloc (num_time_steps,sizeof(double)); err= ex_get_all_times (exo_file,scr); PutDbl( "time", num_time_steps, 1,scr); free(scr); } /* global variables */ if (num_global_vars > 0 ) { err = ex_get_variable_names(exo_file,EX_GLOBAL,num_global_vars,str2); str[0]='\0'; for (i=0;i<num_global_vars;i++) sprintf(str+strlen(str),"%s\n",str2[i]); PutStr("gnames",str); scr = (double *) calloc (num_time_steps,sizeof(double)); for (i=0;i<num_global_vars;i++){ sprintf(str,"gvar%02d",i+1); err=ex_get_glob_var_time(exo_file,i+1,1,num_time_steps,scr); PutDbl(str,num_time_steps,1,scr); } free(scr); } /* nodal variables */ if (num_nodal_vars > 0 ) { err = ex_get_variable_names(exo_file,EX_NODAL,num_nodal_vars,str2); str[0]='\0'; for (i=0;i<num_nodal_vars;i++) sprintf(str+strlen(str),"%s\n",str2[i]); PutStr("nnames",str); scr = (double *) calloc (num_nodes*num_time_steps,sizeof(double)); for (i=0;i<num_nodal_vars;i++){ sprintf(str,"nvar%02d",i+1); for (j=0;j<num_time_steps;j++) err=ex_get_nodal_var(exo_file,j+1,i+1,num_nodes, scr+num_nodes*j); PutDbl(str,num_nodes,num_time_steps,scr); } free(scr); } /* element variables */ if (num_element_vars > 0 ) { err = ex_get_variable_names(exo_file,EX_ELEM_BLOCK,num_element_vars,str2); str[0]='\0'; for (i=0;i<num_element_vars;i++) sprintf(str+strlen(str),"%s\n",str2[i]); PutStr("enames",str); /* truth table */ iscr = (int *) calloc(num_element_vars*num_blocks, sizeof(int)); ex_get_elem_var_tab(exo_file,num_blocks,num_element_vars,iscr); for (i=0;i<num_element_vars;i++){ scr = (double *) calloc (num_elements*num_time_steps,sizeof(double)); n=0; sprintf(str,"evar%02d",i+1); for (j=0;j<num_time_steps;j++){ for (k=0;k<num_blocks;k++){ if(iscr[num_element_vars*k+i]==1) ex_get_elem_var(exo_file,j+1,i+1,ids[k],num_elem_in_block[k],scr+n); n=n+num_elem_in_block[k]; } } PutDbl(str,num_elements,num_time_steps,scr); free(scr); } free(iscr); } free(num_elem_in_block); free(ids); /* node and element number maps */ ex_opts(0); /* turn off error reporting. It is not an error to have no map*/ ids = (int *)malloc(num_nodes*sizeof(int)); err = ex_get_node_num_map(exo_file,ids); if ( err==0 ){ PutInt("node_num_map",num_nodes,1,ids); } free(ids); ids = (int *)malloc(num_elements*sizeof(int)); err = ex_get_elem_num_map(exo_file,ids); if ( err==0 ){ PutInt("elem_num_map",num_elements,1,ids); } free(ids); /* close exo file */ ex_close(exo_file); /* close mat file */ if ( textfile ) fclose(m_file); else Mat_Close(mat_file); /* */ fprintf(stderr,"done.\n"); free(filename); free(line); free(str); for (i=0;i<nstr2;i++) free(str2[i]); free(str2); /* exit status */ add_to_log("exo2mat", 0); return(0); }
int NemSpread<T,INT>::read_var_param (int exoid, int max_name_length) { const char *yo="read_var_param"; /* Get the number of time indices contained in the file */ int ret_int = ex_inquire_int(exoid, EX_INQ_TIME); /* see if the user want to get all of the time indices */ if (Restart_Info.Num_Times == -1) { Restart_Info.Num_Times = ret_int; if (ret_int > 0) { /* allocate array space */ Restart_Info.Time_Idx.resize(Restart_Info.Num_Times); for (int cnt = 0; cnt < Restart_Info.Num_Times; cnt++) Restart_Info.Time_Idx[cnt] = cnt + 1; } } else { /* Check to see if the requested indeces are valid */ for (int cnt = 0; cnt < Restart_Info.Num_Times; cnt++) { /* if the user wants the last time, then set it */ if (Restart_Info.Time_Idx[cnt] == 0) Restart_Info.Time_Idx[cnt] = ret_int; if (Restart_Info.Time_Idx[cnt] > ret_int) { fprintf(stderr, "%s: Requested time index, %d, out of range.\n", yo, Restart_Info.Time_Idx[cnt]); fprintf(stderr, "%s: Valid time indices in %s are from 1 to %d.\n", yo, Exo_Res_File, ret_int); return -1; } } } /* if there are not any time steps, then return here without an error */ if (Restart_Info.Num_Times == 0) { Restart_Info.Flag = 0; Restart_Info.NVar_Glob = 0; Restart_Info.NVar_Node = 0; Restart_Info.NVar_Elem = 0; return 0; } /***************** Global Variables ********************/ if (ex_get_variable_param(exoid, EX_GLOBAL, &(Restart_Info.NVar_Glob)) < 0) { fprintf(stderr, "%s: Could not get global variable parameter from file\n", yo); return -1; } /* allocate space for the global variable names */ if (Restart_Info.NVar_Glob > 0) { Restart_Info.GV_Name = (char **) array_alloc(__FILE__, __LINE__, 2, Restart_Info.NVar_Glob, max_name_length+1, sizeof(char)); /* get the global variable names */ if (ex_get_variable_names(exoid, EX_GLOBAL, Restart_Info.NVar_Glob, Restart_Info.GV_Name) < 0) { fprintf(stderr, "%s: Could not get global variable names from file\n", yo); return -1; } } /***************** Elemental Variables ********************/ if (ex_get_variable_param(exoid, EX_ELEM_BLOCK, &(Restart_Info.NVar_Elem)) < 0) { fprintf(stderr, "%s: Could not get elemental variable param from file\n", yo); return -1; } /* allocate space for the elemental variable names */ if (Restart_Info.NVar_Elem > 0) { Restart_Info.EV_Name = (char **) array_alloc(__FILE__, __LINE__, 2, Restart_Info.NVar_Elem, max_name_length+1, sizeof(char)); /* get the elemental variable names */ if (ex_get_variable_names(exoid, EX_ELEM_BLOCK, Restart_Info.NVar_Elem, Restart_Info.EV_Name) < 0) { fprintf(stderr, "%s: Could not get elemental variable names from file\n", yo); return -1; } /* and get the truth table */ Restart_Info.GElem_TT.resize(globals.Num_Elem_Blk * Restart_Info.NVar_Elem); check_exodus_error(ex_get_truth_table(exoid, EX_ELEM_BLOCK, globals.Num_Elem_Blk, Restart_Info.NVar_Elem, TOPTR(Restart_Info.GElem_TT)), "ex_get_truth_table"); } /******************* Nodal Variables **********************/ if (ex_get_variable_param(exoid, EX_NODAL, &(Restart_Info.NVar_Node)) < 0) { fprintf(stderr, "%s: Could not get nodal variable param from file\n", yo); return -1; } /* allocate space for the nodal variable names */ if (Restart_Info.NVar_Node > 0) { Restart_Info.NV_Name = (char **) array_alloc(__FILE__, __LINE__, 2, Restart_Info.NVar_Node, max_name_length+1, sizeof(char)); /* get the nodal variable names */ if (ex_get_variable_names(exoid, EX_NODAL, Restart_Info.NVar_Node, Restart_Info.NV_Name) < 0) { fprintf(stderr, "%s: Could not get nodal variable names from file\n", yo); return -1; } } /******************* Sideset Variables **********************/ if (ex_get_variable_param(exoid, EX_SIDE_SET, &(Restart_Info.NVar_Sset)) < 0) { fprintf(stderr, "%s: Could not get sideset variable param from file\n", yo); return -1; } /* allocate space for the variable names */ if (Restart_Info.NVar_Sset > 0) { Restart_Info.SSV_Name = (char **) array_alloc(__FILE__, __LINE__, 2, Restart_Info.NVar_Sset, max_name_length+1, sizeof(char)); /* get the variable names */ if (ex_get_variable_names(exoid, EX_SIDE_SET, Restart_Info.NVar_Sset, Restart_Info.SSV_Name) < 0) { fprintf(stderr, "%s: Could not get sideset variable names from file\n", yo); return -1; } /* and get the truth table */ Restart_Info.GSset_TT.resize(globals.Num_Side_Set * Restart_Info.NVar_Sset); check_exodus_error(ex_get_truth_table(exoid, EX_SIDE_SET, globals.Num_Side_Set, Restart_Info.NVar_Sset, TOPTR(Restart_Info.GSset_TT)), "ex_get_truth_table"); } /******************* Nodeset Variables **********************/ if (ex_get_variable_param(exoid, EX_NODE_SET, &(Restart_Info.NVar_Nset)) < 0) { fprintf(stderr, "%s: Could not get nodeset variable param from file\n", yo); return -1; } /* allocate space for the variable names */ if (Restart_Info.NVar_Nset > 0) { Restart_Info.NSV_Name = (char **) array_alloc(__FILE__, __LINE__, 2, Restart_Info.NVar_Nset, max_name_length+1, sizeof(char)); /* get the variable names */ if (ex_get_variable_names(exoid, EX_NODE_SET, Restart_Info.NVar_Nset, Restart_Info.NSV_Name) < 0) { fprintf(stderr, "%s: Could not get nodeset variable names from file\n", yo); return -1; } /* and get the truth table */ Restart_Info.GNset_TT.resize(globals.Num_Node_Set * Restart_Info.NVar_Nset); check_exodus_error(ex_get_truth_table(exoid, EX_NODE_SET, globals.Num_Node_Set, Restart_Info.NVar_Nset, TOPTR(Restart_Info.GNset_TT)), "ex_get_var_tab"); } #ifdef DEBUG if (Debug_Flag >= 2) { printf("\n\nRestart Parameters:\n"); printf("\tNumber of time indices: %d\n", Restart_Info.Num_Times); for (int cnt = 0; cnt < Restart_Info.Num_Times; cnt++) printf("\t\tTime index: %d\n", Restart_Info.Time_Idx[cnt]); printf("\tNumber of global variables: %d\n", Restart_Info.NVar_Glob); for (int cnt = 0; cnt < Restart_Info.NVar_Glob; cnt++) printf("\t\tGlobal variable %d: %s\n", (cnt+1), Restart_Info.GV_Name[cnt]); printf("\tNumber of elental variables: %d\n", Restart_Info.NVar_Elem); for (int cnt = 0; cnt < Restart_Info.NVar_Elem; cnt++) printf("\t\tElemental variable %d: %s\n", (cnt+1), Restart_Info.EV_Name[cnt]); printf("\tNumber of nodal variables: %d\n", Restart_Info.NVar_Node); for (int cnt = 0; cnt < Restart_Info.NVar_Node; cnt++) printf("\t\tNodal variable %d: %s\n", (cnt+1), Restart_Info.NV_Name[cnt]); } #endif return 0; }
int ex_get_var_time(int exoid, ex_entity_type var_type, int var_index, int64_t id, int beg_time_step, int end_time_step, void *var_vals) { int dimid, varid, numel = 0, offset; int status; int * stat_vals = NULL; size_t num_obj, i; size_t num_entries_this_obj = 0; size_t start[2], count[2]; char errmsg[MAX_ERR_LENGTH]; const char *varobjids; const char *varobstat; switch (var_type) { case EX_GLOBAL: return ex_get_glob_var_time_int(exoid, var_index, beg_time_step, end_time_step, var_vals); case EX_NODAL: return ex_get_nodal_var_time_int(exoid, var_index, id, beg_time_step, end_time_step, var_vals); case EX_EDGE_BLOCK: varobjids = VAR_ID_ED_BLK; varobstat = VAR_STAT_ED_BLK; break; case EX_FACE_BLOCK: varobjids = VAR_ID_FA_BLK; varobstat = VAR_STAT_FA_BLK; break; case EX_ELEM_BLOCK: varobjids = VAR_ID_EL_BLK; varobstat = VAR_STAT_EL_BLK; break; case EX_NODE_SET: varobjids = VAR_NS_IDS; varobstat = VAR_NS_STAT; break; case EX_EDGE_SET: varobjids = VAR_ES_IDS; varobstat = VAR_ES_STAT; break; case EX_FACE_SET: varobjids = VAR_FS_IDS; varobstat = VAR_FS_STAT; break; case EX_SIDE_SET: varobjids = VAR_SS_IDS; varobstat = VAR_SS_STAT; break; case EX_ELEM_SET: varobjids = VAR_ELS_IDS; varobstat = VAR_ELS_STAT; break; default: exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid variable type (%d) specified for file id %d", var_type, exoid); ex_err("ex_get_var_time", errmsg, exerrval); return (EX_FATAL); } exerrval = 0; /* clear error code */ /* assume entry number is 1-based (the first entry of an object is 1, not 0); * adjust so it is 0-based */ id--; /* find what object the entry is in */ /* first, find out how many objects there are */ status = ex_get_dimension(exoid, ex_dim_num_objects(var_type), ex_name_of_object(var_type), &num_obj, &dimid, "ex_get_var_time"); if (status != NC_NOERR) { return status; } /* get the array of object ids */ /* don't think we need this anymore since the netcdf variable names associated with objects don't contain the object ids */ if ((status = nc_inq_varid(exoid, varobjids, &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s ids in file id %d", ex_name_of_object(var_type), exoid); ex_err("ex_get_var_time", errmsg, exerrval); return (EX_FATAL); } /* allocate space for stat array */ if (!(stat_vals = malloc((int)num_obj * sizeof(int)))) { exerrval = EX_MEMFAIL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate memory for %s status array for file id %d", ex_name_of_object(var_type), exoid); ex_err("ex_get_var_time", errmsg, exerrval); return (EX_FATAL); } /* get variable id of status array */ if (nc_inq_varid(exoid, varobstat, &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(stat_vals); snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s status array from file id %d", ex_name_of_object(var_type), exoid); ex_err("ex_get_var_time", errmsg, exerrval); return (EX_FATAL); } } else { /* default: status is true */ for (i = 0; i < num_obj; i++) { stat_vals[i] = 1; } } /* loop through each object until id is found; since entry * numbers are sequential (beginning with 1) id is in obj_i * when id_first_i <= id <= id_last_i, where * id_first_i is the entry number of the first entry in * obj_i and id_last_i is the entry number of the last * entry in obj_i */ i = 0; if (stat_vals[i] != 0) { if ((status = nc_inq_dimid(exoid, ex_dim_num_entries_in_object(var_type, i + 1), &dimid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate number of entries in %" ST_ZU "th %s in file id %d", i, ex_name_of_object(var_type), exoid); ex_err("ex_get_var_time", errmsg, exerrval); free(stat_vals); return (EX_FATAL); } if ((status = nc_inq_dimlen(exoid, dimid, &num_entries_this_obj)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of entries in %" ST_ZU "th %s in file id %d", i, ex_name_of_object(var_type), exoid); ex_err("ex_get_var_time", errmsg, exerrval); free(stat_vals); return (EX_FATAL); } } /* End NULL object check */ numel = num_entries_this_obj; while (numel <= id) { if (stat_vals[++i] != 0) { if ((status = nc_inq_dimid(exoid, ex_dim_num_entries_in_object(var_type, i + 1), &dimid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate number of entries in %" ST_ZU "th %s in file id %d", i, ex_name_of_object(var_type), exoid); ex_err("ex_get_var_time", errmsg, exerrval); free(stat_vals); return (EX_FATAL); } if ((status = nc_inq_dimlen(exoid, dimid, &num_entries_this_obj)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of entries in %" ST_ZU "th %s in file id %d", i, ex_name_of_object(var_type), exoid); ex_err("ex_get_var_time", errmsg, exerrval); free(stat_vals); return (EX_FATAL); } numel += num_entries_this_obj; } } offset = id - (numel - num_entries_this_obj); /* inquire previously defined variable */ if ((status = nc_inq_varid(exoid, ex_name_var_of_object(var_type, var_index, i + 1), &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate variable %" ST_ZU " for %dth %s in file id %d", i, var_index, ex_name_of_object(var_type), exoid); ex_err("ex_get_var_time", errmsg, exerrval); free(stat_vals); return (EX_FATAL); } free(stat_vals); /* Check that times are in range */ { int num_time_steps = ex_inquire_int(exoid, EX_INQ_TIME); if (beg_time_step <= 0 || beg_time_step > num_time_steps) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: beginning time_step is out-of-range. Value = %d, " "valid range is 1 to %d in file id %d", beg_time_step, num_time_steps, exoid); ex_err("ex_get_var_time", errmsg, EX_BADPARAM); return (EX_FATAL); } if (end_time_step < 0) { /* user is requesting the maximum time step; we find this out using the * database inquire function to get the number of time steps; the ending * time step number is 1 less due to 0 based array indexing in C */ end_time_step = ex_inquire_int(exoid, EX_INQ_TIME); } else if (end_time_step < beg_time_step || end_time_step > num_time_steps) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: end time_step is out-of-range. Value = %d, valid " "range is %d to %d in file id %d", beg_time_step, end_time_step, num_time_steps, exoid); ex_err("ex_get_var_time", errmsg, EX_BADPARAM); return (EX_FATAL); } } /* read values of object variable */ start[0] = --beg_time_step; start[1] = offset; end_time_step--; count[0] = end_time_step - beg_time_step + 1; count[1] = 1; if (ex_comp_ws(exoid) == 4) { status = nc_get_vara_float(exoid, varid, start, count, var_vals); } else { status = nc_get_vara_double(exoid, varid, start, count, var_vals); } if (status != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s variable values in file id %d", ex_name_of_object(var_type), exoid); ex_err("ex_get_var_time", errmsg, exerrval); return (EX_FATAL); } return (EX_NOERR); }
void NemSpread<T,INT>::read_restart_params() /* Function which reads the restart variable parameters for the EXODUS II * database which contains the results information. Allocate necessary * memory on each processor. * *---------------------------------------------------------------------------- * * Functions called: * * compare_mesh_param -- function which checks that parameters in * the restart EXODUS II file are the same as in * the mesh EXODUS II file * read_var_param -- function which reads the time indicies, number * of variables, and their names from the restart file * *---------------------------------------------------------------------------- */ { const char *yo="read_restart_params"; int exoid, cpu_ws=0; float vers; int max_name_length = 0; /* Open the ExodusII file */ cpu_ws = io_ws; int mode = EX_READ | int64api; if ((exoid=ex_open(Exo_Res_File, mode, &cpu_ws, &io_ws, &vers)) < 0) { fprintf(stderr, "%s: Could not open file %s for restart info\n", yo, Exo_Res_File); exit(1); } max_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH); ex_set_max_name_length(exoid, max_name_length); /* * Just do a rudimentary check to figure out if the mesh parameters * in the results file are the same as the mesh parameters in the * mesh file. */ if (strcmp(ExoFile, Exo_Res_File) != 0) if (!compare_mesh_param(exoid)) { fprintf(stderr, "%s: Mesh parameters in mesh and result files" " differ\n", yo); exit(1); } /* get the time, and the variable names */ if (read_var_param(exoid, max_name_length) < 0) { fprintf(stderr, "%s: Error occured while reading variable parameters\n", yo); exit(1); } /* Close the ExodusII file */ ex_close(exoid); return; }
int main (int argc, char **argv) { int exoid, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets; int num_side_sets, error; int i, j, k, node_ctr; int *elem_map, *connect, *node_list, *node_ctr_list, *elem_list, *side_list; int *ids; int *num_nodes_per_set = NULL; int *num_elem_per_set = NULL; int *num_df_per_set = NULL; int *node_ind = NULL; int *elem_ind = NULL; int *df_ind = NULL; int num_qa_rec, num_info; int num_glo_vars, num_nod_vars, num_ele_vars; int num_nset_vars, num_sset_vars; int *truth_tab; int num_time_steps; int *num_elem_in_block = NULL; int *num_nodes_per_elem = NULL; int *num_attr = NULL; int num_nodes_in_set, num_elem_in_set; int num_sides_in_set, num_df_in_set; int list_len, elem_list_len, node_list_len, df_list_len; int node_num, time_step, var_index, beg_time, end_time, elem_num; int CPU_word_size,IO_word_size; int num_props, prop_value, *prop_values; int idum; int max_name_length; float time_value, *time_values, *var_values; float *x, *y, *z; float *attrib, *dist_fact; float version, fdum; char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3]; char *block_names[10], *nset_names[10], *sset_names[10]; char *attrib_names[10]; char title[MAX_LINE_LENGTH+1], elem_type[MAX_STR_LENGTH+1]; char title_chk[MAX_LINE_LENGTH+1]; char *cdum = 0; char *prop_names[3]; char *name = NULL; CPU_word_size = 0; /* sizeof(float) */ IO_word_size = 0; /* use what is stored in file */ ex_opts (EX_VERBOSE | EX_ABORT ); /* open EXODUS II files */ exoid = ex_open ("test.exo", /* filename path */ EX_READ, /* access mode = READ */ &CPU_word_size, /* CPU word size */ &IO_word_size, /* IO word size */ &version); /* ExodusII library version */ printf ("\nafter ex_open\n"); if (exoid < 0) exit(1); printf ("test.exo is an EXODUSII file; version %4.2f\n", version); /* printf (" CPU word size %1d\n",CPU_word_size); */ printf (" I/O word size %1d\n",IO_word_size); ex_inquire(exoid,EX_INQ_API_VERS, &idum, &version, cdum); printf ("EXODUSII API; version %4.2f\n", version); ex_inquire(exoid,EX_INQ_LIB_VERS, &idum, &version, cdum); printf ("EXODUSII Library API; version %4.2f (%d)\n", version, idum); /* Query size of names used in this file */ { int max_all_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH); int max_use_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH); printf ("This file can use at most %d-character names\n", max_all_name_length); printf ("The maximum name length used is %d-character names\n", max_use_name_length); max_name_length = max_use_name_length; ex_set_max_name_length(exoid, max_name_length); } name = (char *) calloc(max_name_length+1, sizeof(char)); /* read database parameters */ error = ex_get_init (exoid, title, &num_dim, &num_nodes, &num_elem, &num_elem_blk, &num_node_sets, &num_side_sets); printf ("after ex_get_init, error = %3d\n", error); printf ("database parameters:\n"); printf ("title = '%s'\n",title); printf ("num_dim = %3d\n",num_dim); printf ("num_nodes = %3d\n",num_nodes); printf ("num_elem = %3d\n",num_elem); printf ("num_elem_blk = %3d\n",num_elem_blk); printf ("num_node_sets = %3d\n",num_node_sets); printf ("num_side_sets = %3d\n",num_side_sets); /* Check that ex_inquire gives same title */ error = ex_inquire (exoid, EX_INQ_TITLE, &idum, &fdum, title_chk); printf ("after ex_inquire, error = %3d\n", error); if (strcmp(title, title_chk) != 0) { printf ("error in ex_inquire for EX_INQ_TITLE\n"); } /* read nodal coordinates values and names from database */ x = (float *) calloc(num_nodes, sizeof(float)); y = (float *) calloc(num_nodes, sizeof(float)); if (num_dim >= 3) z = (float *) calloc(num_nodes, sizeof(float)); else z = 0; error = ex_get_coord (exoid, x, y, z); printf ("\nafter ex_get_coord, error = %3d\n", error); printf ("x coords = \n"); for (i=0; i<num_nodes; i++) { printf ("%5.1f\n", x[i]); } 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); free (y); if (num_dim >= 3) free (z); for (i=0; i<num_dim; i++) { coord_names[i] = (char *) calloc ((max_name_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]); 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_name_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_name_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_name_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_name_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_name_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_name_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_name_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_name_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_name_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_name_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_name_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_name_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_name_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_name_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_name_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); free (name); error = ex_close (exoid); printf ("\nafter ex_close, error = %3d\n", error); return 0; }
int main (int argc, char *argv[]){ char **str2,*line,*curr; const char* ext=".exo"; int i,j,k,n,n1,cpu_word_size,io_word_size,exo_file, num_axes,num_nodes,num_elements,num_blocks, num_side_sets,num_node_sets,num_time_steps, num_global_vars, num_nodal_vars,num_element_vars,*ids,*iscr, *nsssides,*nssdfac,*elem_list,*side_list, *nnsnodes,*nnsdfac,*node_list; double *scr,*x,*y,*z, *escr; char * blknames = NULL; int *num_elem_in_block = NULL; /* QA Info */ printf("%s: %s, %s\n", qainfo[0], qainfo[2], qainfo[1]); /* usage message*/ if(argc != 2){ printf("%s matlab_file_name.\n",argv[0]); printf(" the matlab_file_name is required\n"); printf("%d", argc); exit(1); } /*open input file*/ mat_file = Mat_Open(argv[1], MAT_ACC_RDONLY); if (mat_file == NULL) { printf("Error opening matlab file %s\n", argv[1]); return(1); } /*open output file*/ cpu_word_size=sizeof(double); io_word_size=sizeof(double); /* QA records */ ext=".exo"; line = (char *) calloc (2049,sizeof(char)); strcpy(line,argv[1]); strtok(line,"."); strcat(line,ext); exo_file = ex_create(line,EX_CLOBBER,&cpu_word_size,&io_word_size); if (exo_file < 0){ printf("error creating %s\n",line); exit(1); } /* print */ fprintf(stderr,"translating %s to %s ... ",argv[1],line); /* read database parameters */ matGetInt("naxes", 1, 1,&num_axes); matGetInt("nnodes", 1, 1,&num_nodes); matGetInt("nelems", 1, 1,&num_elements); matGetInt("nblks", 1, 1,&num_blocks); matGetInt("nnsets", 1, 1,&num_node_sets); matGetInt("nssets", 1, 1,&num_side_sets); matGetInt("nsteps", 1, 1,&num_time_steps); matGetInt("ngvars", 1, 1,&num_global_vars); matGetInt("nnvars", 1, 1,&num_nodal_vars); matGetInt("nevars", 1, 1,&num_element_vars); /*export parameters */ ex_put_init(exo_file,line, num_axes,num_nodes,num_elements,num_blocks, num_node_sets,num_side_sets); free(line); if ( num_global_vars > 0 ){ ex_put_variable_param(exo_file,EX_GLOBAL,num_global_vars); } if ( num_nodal_vars > 0 ){ ex_put_variable_param(exo_file,EX_NODAL,num_nodal_vars); } if ( num_element_vars > 0 ){ ex_put_variable_param(exo_file,EX_ELEM_BLOCK,num_element_vars); } /* nodal coordinates */ x = (double *) calloc(num_nodes,sizeof(double)); y = (double *) calloc(num_nodes,sizeof(double)); if (num_axes == 3) z = (double *) calloc(num_nodes,sizeof(double)); else z = NULL; matGetDbl("x0", num_nodes, 1, x); matGetDbl("y0", num_nodes, 1, y); if (num_axes == 3) matGetDbl("z0", num_nodes,1,z); ex_put_coord(exo_file,x,y,z); free(x); free(y); if (num_axes == 3){ free(z); } /* side sets (section by dgriffi) */ if(num_side_sets > 0){ /* ssids */ ids = (int *) calloc(num_side_sets,sizeof(int)); matGetInt("ssids",num_side_sets, 1,ids); /* nsssides */ nsssides = (int *) calloc(num_side_sets,sizeof(int)); matGetInt("nsssides",num_side_sets,1,nsssides); /* nssdfac */ nssdfac = (int *) calloc(num_side_sets,sizeof(int)); matGetInt("nssdfac",num_side_sets,1,nssdfac); for(i=0;i<num_side_sets;i++){ char name[32]; ex_put_set_param(exo_file,EX_SIDE_SET,ids[i],nsssides[i],nssdfac[i]); elem_list = (int *) calloc(nsssides[i],sizeof(int)); side_list = (int *) calloc(nsssides[i],sizeof(int)); escr = (double *) calloc(nssdfac[i],sizeof(double)); sprintf(name,"sselem%02d",i+1); matGetInt(name,nsssides[i],1,elem_list); sprintf(name,"ssside%02d",i+1); matGetInt(name,nsssides[i],1,side_list); ex_put_set(exo_file,EX_SIDE_SET,ids[i],elem_list,side_list); free(elem_list); free(side_list); sprintf(name,"ssfac%02d",i+1); matGetDbl(name,nssdfac[i],1,escr); ex_put_set_dist_fact(exo_file,EX_SIDE_SET,ids[i],escr); free(escr); } free(nsssides); free(nssdfac); free(ids); } /* node sets (section by dgriffi) */ if(num_node_sets > 0){ /* nsids */ ids = (int *) calloc(num_node_sets,sizeof(int)); matGetInt("nsids",num_node_sets, 1,ids); /* nnsnodes */ nnsnodes = (int *) calloc(num_node_sets,sizeof(int)); matGetInt("nnsnodes",num_node_sets,1,nnsnodes); /* nnsdfac */ nnsdfac = (int *) calloc(num_node_sets,sizeof(int)); matGetInt("nnsdfac",num_node_sets,1,nnsdfac); for(i=0;i<num_node_sets;i++){ char name[32]; ex_put_set_param(exo_file,EX_NODE_SET,ids[i],nnsnodes[i],nnsdfac[i]); node_list = (int *) calloc(nnsnodes[i],sizeof(int)); escr = (double *) calloc(nnsdfac[i],sizeof(double)); sprintf(name,"nsnod%02d",i+1); matGetInt(name,nnsnodes[i],1,node_list); ex_put_set(exo_file,EX_NODE_SET,ids[i],node_list,NULL); free(node_list); sprintf(name,"nsfac%02d",i+1); matGetDbl(name,nnsdfac[i],1,escr); ex_put_set_dist_fact(exo_file,EX_NODE_SET,ids[i],escr); free(escr); } free(nnsdfac); free(nnsnodes); free(ids); } /* element blocks */ /* get elem block ids */ ids = (int *) calloc(num_blocks,sizeof(int)); matGetInt("blkids",num_blocks,1,ids); /* get elem block types */ blknames = (char *) calloc(num_blocks*(MAX_STR_LENGTH+1),sizeof(char)); matGetStr("blknames",blknames); num_elem_in_block = (int *) calloc(num_blocks,sizeof(int)); curr = blknames; curr = strtok(curr,"\n"); for(i=0;i<num_blocks;i++){ char name[32]; sprintf(name,"blk%02d",i+1); n1 = matArrNRow(name); n = matArrNCol(name); iscr = (int *) calloc(n*n1,sizeof(int)); matGetInt(name,n1,n,iscr); num_elem_in_block[i]=n; ex_put_elem_block(exo_file,ids[i],curr,n,n1,0); ex_put_conn(exo_file,EX_ELEM_BLOCK,ids[i],iscr,NULL,NULL); free(iscr); curr = strtok(NULL, "\n"); } free(blknames); /* time values */ if (num_time_steps > 0 ) { scr = (double *) calloc(num_time_steps,sizeof(double)); matGetDbl( "time", num_time_steps, 1,scr); for (i=0;i<num_time_steps;i++){ ex_put_time(exo_file,i+1,&scr[i]); } free(scr); } /* global variables */ if (num_global_vars > 0 ){ int max_name_length = ex_inquire_int(exo_file, EX_INQ_DB_MAX_USED_NAME_LENGTH); char *str = (char *) calloc(num_global_vars * (max_name_length+1), sizeof(char)); matGetStr("gnames",str); str2 = (char **) calloc(num_global_vars,sizeof(char*)); curr = strtok(str,"\n"); for(i=0;i<num_global_vars;i++){ str2[i]=curr; curr = strtok(NULL,"\n"); } ex_put_variable_names(exo_file, EX_GLOBAL, num_global_vars, str2); free(str); free(str2); { double * global_var_vals; double * temp; global_var_vals = (double *) calloc(num_global_vars*num_time_steps,sizeof(double)); temp = (double *) calloc(num_time_steps,sizeof(double)); for (j=0;j<num_global_vars;j++) { char name[32]; sprintf(name,"gvar%02d",j+1); matGetDbl(name,num_time_steps,1,temp); for (i=0; i < num_time_steps; i++) { global_var_vals[num_global_vars*i+j]=temp[i]; } } for (i=0; i<num_time_steps; i++) { size_t offset = num_global_vars * i; ex_put_var(exo_file,i+1,EX_GLOBAL,1,0,num_global_vars,&global_var_vals[offset]); } free(temp); free(global_var_vals); } } /* nodal variables */ /* section by dtg */ if (num_nodal_vars > 0){ int max_name_length = ex_inquire_int(exo_file, EX_INQ_DB_MAX_USED_NAME_LENGTH); char *str = (char *) calloc(num_nodal_vars * (max_name_length+1), sizeof(char)); matGetStr("nnames",str); str2 = (char **) calloc(num_nodal_vars,sizeof(char*)); curr = strtok(str,"\n"); for(i=0;i<num_nodal_vars;i++){ str2[i]=curr; curr = strtok(NULL,"\n"); } ex_put_variable_names(exo_file, EX_NODAL, num_nodal_vars, str2); free(str); free(str2); { double * nodal_var_vals; for (i=0;i<num_nodal_vars;i++) { char name[32]; nodal_var_vals = (double *) calloc(num_nodes*num_time_steps,sizeof(double)); sprintf(name,"nvar%02d",i+1); matGetDbl(name,num_nodes,num_time_steps,nodal_var_vals); for (j=0;j<num_time_steps;j++) { ex_put_var(exo_file,j+1,EX_NODAL,i+1,num_nodes,1,nodal_var_vals+num_nodes*j); } free(nodal_var_vals); } } } /* elemental variables */ /* section by dtg */ if (num_element_vars > 0){ int max_name_length = ex_inquire_int(exo_file, EX_INQ_DB_MAX_USED_NAME_LENGTH); char *str = (char *) calloc(num_element_vars * (max_name_length+1), sizeof(char)); matGetStr("enames",str); str2 = (char **) calloc(num_element_vars,sizeof(char*)); curr = strtok(str,"\n"); for(i=0;i<num_element_vars;i++){ str2[i]=curr; curr = strtok(NULL,"\n"); } ex_put_variable_names(exo_file, EX_ELEM_BLOCK, num_element_vars, str2); free(str); free(str2); { double * element_var_vals; for (i=0;i<num_element_vars;i++) { char name[32]; element_var_vals = (double *) calloc(num_elements*num_time_steps,sizeof(double)); sprintf(name,"evar%02d",i+1); matGetDbl(name,num_elements,num_time_steps,element_var_vals); n=0; for (j=0;j<num_time_steps;j++) { for (k=0;k<num_blocks;k++) { ex_put_var(exo_file,j+1,EX_ELEM_BLOCK, i+1,ids[k],num_elem_in_block[k],element_var_vals+n); n=n+num_elem_in_block[k]; } } free(element_var_vals); } } } free(ids); /* node and element number maps */ ids = (int *) calloc (num_nodes,sizeof(int)); if ( !matGetInt("node_num_map",num_nodes,1,ids)){ ex_put_node_num_map(exo_file,ids); } free(ids); ids = (int *) calloc (num_elements,sizeof(int)); if ( !matGetInt("elem_num_map",num_elements,1,ids)){ ex_put_elem_num_map(exo_file,ids); } free(ids); free(num_elem_in_block); /* close exo file */ ex_close(exo_file); /* close mat file */ Mat_Close(mat_file); /* */ fprintf(stderr,"done.\n"); /* exit status */ add_to_log("mat2exo", 0); return(0); }
int ex_cvt_nodes_to_sides(int exoid, void_int *num_elem_per_set, void_int *num_nodes_per_set, void_int *side_sets_elem_index, /* unused */ void_int *side_sets_node_index, /* unused */ void_int *side_sets_elem_list, void_int *side_sets_node_list, void_int *side_sets_side_list) { size_t i, j, k, n; int num_side_sets, num_elem_blks; int64_t tot_num_elem = 0, tot_num_ss_elem = 0, elem_num = 0, ndim; void_int *elem_blk_ids = NULL; void_int *connect = NULL; void_int *ss_elem_ndx = NULL; void_int *ss_elem_node_ndx = NULL; void_int *ss_parm_ndx = NULL; size_t elem_ctr, node_ctr, elem_num_pos; int num_nodes_per_elem, num_node_per_side; int *same_elem_type = NULL; int el_type = 0; int int_size; int ids_size; struct elem_blk_parm *elem_blk_parms = NULL; int err_stat = EX_NOERR; /* node to side translation tables - These tables are used to look up the side number based on the first and second node in the side/face list. The side node order is found in the original Exodus document, SAND87-2997. The element node order is found in the ExodusII document, SAND92-2137. These tables were generated by following the right-hand rule for determining the outward normal. Note: Only the more complex 3-D shapes require these tables, the simple shapes are trivial - the first node found is also the side number. */ /* 1 2 3 4 node 1 */ static int shell_table[2][8] = { {2, 4, 3, 1, 4, 2, 1, 3}, /* node 2 */ {1, 2, 1, 2, 1, 2, 1, 2} /* side # */ }; /* 1 2 3 4 node 1 */ static int shell_edge_table[2][8] = { {2, 4, 3, 1, 4, 2, 1, 3}, /* node 2 */ {3, 6, 4, 3, 5, 4, 6, 5} /* side # */ }; /* 1 2 3 node 1 */ static int trishell_table[2][6] = { {2, 3, 3, 1, 1, 2}, /* node 2 */ {1, 2, 1, 2, 1, 2} /* side # */ }; /* 1 2 3 4 node 1 */ static int tetra_table[2][12] = { {2, 3, 4, 1, 3, 4, 4, 1, 2, 1, 2, 3}, /* node 2 */ {1, 4, 3, 4, 2, 1, 2, 3, 4, 1, 2, 3} /* side # */ }; #if 0 static int wedge_table[2][18] = { /* 1 2 3 4 5 6 node 1 */ {2,4,3, 5,1,3, 6,1,2, 1,6,5, 6,2,4, 4,3,5}, /* node 2 */ {1,3,4, 1,4,2, 2,3,4, 1,3,5, 5,2,1, 5,3,2} /* side # */ }; #endif static int hex_table[2][24] = { /* 1 2 3 4 5 6 7 8 node 1 */ {4, 2, 5, 1, 3, 6, 7, 4, 2, 3, 1, 8, 6, 8, 1, 5, 2, 7, 8, 6, 3, 7, 5, 4}, /* node 2 */ {5, 1, 4, 5, 2, 1, 2, 3, 5, 5, 4, 3, 6, 4, 1, 1, 2, 6, 6, 2, 3, 3, 6, 4} /* side # */ }; char errmsg[MAX_ERR_LENGTH]; exerrval = 0; /* clear error code */ /* first check if any side sets are specified */ /* inquire how many side sets have been stored */ num_side_sets = ex_inquire_int(exoid, EX_INQ_SIDE_SETS); if (num_side_sets < 0) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of side sets in file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); return (EX_FATAL); } if (num_side_sets == 0) { snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no side sets defined in file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, EX_WARN); return (EX_WARN); } num_elem_blks = ex_inquire_int(exoid, EX_INQ_ELEM_BLK); if (num_elem_blks < 0) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of element blocks in file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); return (EX_FATAL); } tot_num_elem = ex_inquire_int(exoid, EX_INQ_ELEM); if (tot_num_elem < 0) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get total number of elements in file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); return (EX_FATAL); } /* get the dimensionality of the coordinates; this is necessary to distinguish between 2d TRIs and 3d TRIs */ ndim = ex_inquire_int(exoid, EX_INQ_DIM); int_size = sizeof(int); if (ex_int64_status(exoid) & EX_BULK_INT64_API) { int_size = sizeof(int64_t); } /* First count up # of elements in the side sets*/ if (ex_int64_status(exoid) & EX_BULK_INT64_API) { for (i = 0; i < num_side_sets; i++) { tot_num_ss_elem += ((int64_t *)num_elem_per_set)[i]; } } else { for (i = 0; i < num_side_sets; i++) { tot_num_ss_elem += ((int *)num_elem_per_set)[i]; } } /* Allocate space for the ss element index array */ if (!(ss_elem_ndx = malloc(tot_num_ss_elem * int_size))) { exerrval = EX_MEMFAIL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate space for side set elem sort " "array for file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } if (int_size == sizeof(int64_t)) { /* Sort side set element list into index array - non-destructive */ int64_t *elems = (int64_t *)ss_elem_ndx; for (i = 0; i < tot_num_ss_elem; i++) { elems[i] = i; /* init index array to current position */ } ex_iqsort64(side_sets_elem_list, elems, tot_num_ss_elem); } else { /* Sort side set element list into index array - non-destructive */ int *elems = (int *)ss_elem_ndx; for (i = 0; i < tot_num_ss_elem; i++) { elems[i] = i; /* init index array to current position */ } ex_iqsort(side_sets_elem_list, elems, tot_num_ss_elem); } /* Allocate space for the element block ids */ ids_size = sizeof(int); if (ex_int64_status(exoid) & EX_IDS_INT64_API) { ids_size = sizeof(int64_t); } if (!(elem_blk_ids = malloc(num_elem_blks * ids_size))) { exerrval = EX_MEMFAIL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate space for element block ids for file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } if (ex_get_ids(exoid, EX_ELEM_BLOCK, elem_blk_ids)) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get element block ids in file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, EX_MSG); err_stat = EX_FATAL; goto cleanup; } /* Allocate space for the element block params */ if (!(elem_blk_parms = malloc(num_elem_blks * sizeof(struct elem_blk_parm)))) { exerrval = EX_MEMFAIL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate space for element block params " "for file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } elem_ctr = 0; for (i = 0; i < num_elem_blks; i++) { ex_entity_id id; if (ex_int64_status(exoid) & EX_IDS_INT64_API) { id = ((int64_t *)elem_blk_ids)[i]; } else { id = ((int *)elem_blk_ids)[i]; } err_stat = ex_int_get_block_param(exoid, id, ndim, &elem_blk_parms[i]); if (err_stat != EX_NOERR) { goto cleanup; } elem_ctr += elem_blk_parms[i].num_elem_in_blk; elem_blk_parms[i].elem_ctr = elem_ctr; /* save elem number max */ } /* Allocate space for the ss element to element block parameter index array */ if (!(ss_parm_ndx = malloc(tot_num_ss_elem * int_size))) { exerrval = EX_MEMFAIL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate space for side set elem parms " "index for file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } /* Allocate space for the ss element to node list index array */ if (!(ss_elem_node_ndx = malloc((tot_num_ss_elem + 1) * int_size))) { exerrval = EX_MEMFAIL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate space for side set elem to node " "index for file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } /* determine if each side set has uniform element types; this will be used to help determine the stride through the node list */ /* Allocate space for same element type flag array*/ if (!(same_elem_type = malloc(num_side_sets * sizeof(int)))) { exerrval = EX_MEMFAIL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate space for element type flag " "array for file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } same_elem_type[0] = EX_TRUE; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { elem_ctr = ((int64_t *)num_elem_per_set)[0]; for (i = 0, k = 0; i < tot_num_ss_elem; i++) { int64_t elem = ((int64_t *)side_sets_elem_list)[i]; for (j = 0; j < num_elem_blks; j++) { if (elem <= elem_blk_parms[j].elem_ctr) { break; } } if (j >= num_elem_blks) { exerrval = EX_INTERNAL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: internal logic error for file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } if (i == 0) { el_type = elem_blk_parms[j].elem_type_val; } /* determine which side set this element is in; assign to kth side set */ if (i >= elem_ctr) { elem_ctr += ((int64_t *)num_elem_per_set)[++k]; el_type = elem_blk_parms[j].elem_type_val; same_elem_type[k] = EX_TRUE; } if (el_type != elem_blk_parms[j].elem_type_val) { same_elem_type[k] = EX_FALSE; } } /* Build side set element to node list index and side set element parameter index. */ node_ctr = 0; elem_ctr = ((int64_t *)num_elem_per_set)[0]; for (i = 0, k = 0; i < tot_num_ss_elem; i++) { int64_t elem = ((int64_t *)side_sets_elem_list)[i]; for (j = 0; j < num_elem_blks; j++) { if (elem <= elem_blk_parms[j].elem_ctr) { break; } } if (j >= num_elem_blks) { exerrval = EX_INTERNAL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: internal logic error for file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } ((int64_t *)ss_parm_ndx)[i] = j; /* assign parameter block index */ ((int64_t *)ss_elem_node_ndx)[i] = node_ctr; /* assign node list index */ /* determine which side set this element is in; assign to kth side set */ if (i >= elem_ctr) { /* skip over NULL side sets */ while (((int64_t *)num_elem_per_set)[++k] == 0) { ; } elem_ctr += ((int64_t *)num_elem_per_set)[k]; } /* determine number of nodes per side */ if (((((int64_t *)num_nodes_per_set)[k] % ((int64_t *)num_elem_per_set)[k]) == 0) && (same_elem_type[k] == EX_TRUE)) { /* all side set elements are same type */ node_ctr += ((int64_t *)num_nodes_per_set)[k] / ((int64_t *)num_elem_per_set)[k]; } else { node_ctr += elem_blk_parms[j].num_nodes_per_side[0]; } } ((int64_t *)ss_elem_node_ndx)[i] = node_ctr; /* assign node list index */ } else { elem_ctr = ((int *)num_elem_per_set)[0]; for (i = 0, k = 0; i < tot_num_ss_elem; i++) { int elem = ((int *)side_sets_elem_list)[i]; for (j = 0; j < num_elem_blks; j++) { if (elem <= elem_blk_parms[j].elem_ctr) { break; } } if (j >= num_elem_blks) { exerrval = EX_INTERNAL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: internal logic error for file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } if (i == 0) { el_type = elem_blk_parms[j].elem_type_val; } /* determine which side set this element is in; assign to kth side set */ if (i >= elem_ctr) { elem_ctr += ((int *)num_elem_per_set)[++k]; el_type = elem_blk_parms[j].elem_type_val; same_elem_type[k] = EX_TRUE; } if (el_type != elem_blk_parms[j].elem_type_val) { same_elem_type[k] = EX_FALSE; } } /* Build side set element to node list index and side set element parameter index. */ node_ctr = 0; elem_ctr = ((int *)num_elem_per_set)[0]; for (i = 0, k = 0; i < tot_num_ss_elem; i++) { int elem = ((int *)side_sets_elem_list)[i]; for (j = 0; j < num_elem_blks; j++) { if (elem <= elem_blk_parms[j].elem_ctr) { break; } } if (j >= num_elem_blks) { exerrval = EX_INTERNAL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: internal logic error for file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } ((int *)ss_parm_ndx)[i] = j; /* assign parameter block index */ ((int *)ss_elem_node_ndx)[i] = node_ctr; /* assign node list index */ /* determine which side set this element is in; assign to kth side set */ if (i >= elem_ctr) { /* skip over NULL side sets */ while (((int *)num_elem_per_set)[++k] == 0) { ; } elem_ctr += ((int *)num_elem_per_set)[k]; } /* determine number of nodes per side */ if (((((int *)num_nodes_per_set)[k] % ((int *)num_elem_per_set)[k]) == 0) && (same_elem_type[k])) { /* all side set elements are same type */ node_ctr += ((int *)num_nodes_per_set)[k] / ((int *)num_elem_per_set)[k]; } else { node_ctr += elem_blk_parms[j].num_nodes_per_side[0]; } } ((int *)ss_elem_node_ndx)[i] = node_ctr; /* assign node list index */ } /* All setup, ready to go ... */ elem_ctr = 0; for (j = 0; j < tot_num_ss_elem; j++) { int64_t elem; int64_t idx; int64_t ss_node0, ss_node1; int64_t p_ndx; if (int_size == sizeof(int64_t)) { idx = ((int64_t *)ss_elem_ndx)[j]; elem = ((int64_t *)side_sets_elem_list)[idx]; ss_node0 = ((int64_t *)side_sets_node_list)[((int64_t *)ss_elem_node_ndx)[idx]]; ss_node1 = ((int64_t *)side_sets_node_list)[((int64_t *)ss_elem_node_ndx)[idx] + 1]; p_ndx = ((int64_t *)ss_parm_ndx)[idx]; } else { idx = ((int *)ss_elem_ndx)[j]; elem = ((int *)side_sets_elem_list)[idx]; ss_node0 = ((int *)side_sets_node_list)[((int *)ss_elem_node_ndx)[idx]]; ss_node1 = ((int *)side_sets_node_list)[((int *)ss_elem_node_ndx)[idx] + 1]; p_ndx = ((int *)ss_parm_ndx)[idx]; } elem_num = elem - 1; if (elem > elem_ctr) { /* release connectivity array space and get next one */ if (elem_ctr > 0) { free(connect); } /* Allocate space for the connectivity array for new element block */ if (!(connect = malloc(elem_blk_parms[p_ndx].num_elem_in_blk * elem_blk_parms[p_ndx].num_nodes_per_elem * int_size))) { exerrval = EX_MEMFAIL; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate space for connectivity " "array for file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } /* get connectivity array */ if (ex_get_conn(exoid, EX_ELEM_BLOCK, elem_blk_parms[p_ndx].elem_blk_id, connect, NULL, NULL) == -1) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get connectivity array for elem blk %" PRId64 " for file id %d", elem_blk_parms[p_ndx].elem_blk_id, exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } elem_ctr = elem_blk_parms[p_ndx].elem_ctr; } /* For the first node of each side in side set, using a linear search (of up to num_nodes_per_elem) of the connectivity array, locate the node position in the element. The first node position and the second node position are used with a element type specific table to determine the side. */ if (connect == NULL) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: logic error. Connect pointer is null for elem blk %" PRId64 " for file id %d", elem_blk_parms[p_ndx].elem_blk_id, exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } /* calculate the relative element number position in it's block*/ elem_num_pos = elem_num - (elem_blk_parms[p_ndx].elem_ctr - elem_blk_parms[p_ndx].num_elem_in_blk); /* calculate the beginning of the node list for this element by using the ss_elem_node_ndx index into the side_sets_node_index and adding the element number position * number of nodes per elem */ num_nodes_per_elem = elem_blk_parms[p_ndx].num_nodes_per_elem; for (n = 0; n < num_nodes_per_elem; n++) { /* find node in connectivity array that matches first node in side set */ if (((int_size == sizeof(int64_t)) && (ss_node0 == ((int64_t *)connect)[num_nodes_per_elem * (elem_num_pos) + n])) || ((int_size == sizeof(int)) && (ss_node0 == ((int *)connect)[num_nodes_per_elem * (elem_num_pos) + n]))) { switch (elem_blk_parms[p_ndx].elem_type_val) { case EX_EL_CIRCLE: case EX_EL_SPHERE: { /* simple case: 1st node number is same as side # */ put_side(side_sets_side_list, idx, n + 1, int_size); break; } case EX_EL_QUAD: case EX_EL_TRIANGLE: case EX_EL_TRUSS: case EX_EL_BEAM: { /* simple case: 1st node number is same as side # */ put_side(side_sets_side_list, idx, n + 1, int_size); break; } case EX_EL_TRISHELL: { /* use table to find which node to compare to next */ if (ss_node1 == get_node(connect, num_nodes_per_elem * (elem_num_pos) + (trishell_table[0][2 * n] - 1), int_size)) { /* Assume only front or back, no edges... */ put_side(side_sets_side_list, idx, trishell_table[1][2 * n], int_size); } else if (ss_node1 == get_node(connect, num_nodes_per_elem * (elem_num_pos) + (trishell_table[0][2 * n + 1] - 1), int_size)) { /* Assume only front or back, no edges... */ put_side(side_sets_side_list, idx, trishell_table[1][2 * n + 1], int_size); } else if (ss_node1 == get_node(connect, num_nodes_per_elem * (elem_num_pos) + (trishell_table[0][2 * n + 2] - 1), int_size)) { /* Assume only front or back, no edges... */ put_side(side_sets_side_list, idx, trishell_table[1][2 * n + 2], int_size); } else { exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find TRIANGULAR SHELL element %" PRId64 ", node %" PRId64 " in connectivity array %" PRId64 " for file id %d", elem_num + 1, ss_node1, elem_blk_parms[p_ndx].elem_blk_id, exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } break; } case EX_EL_SHELL: { /* use table to find which node to compare to next */ if (ex_int64_status(exoid) & EX_BULK_INT64_API) { num_node_per_side = ((int64_t *)ss_elem_node_ndx)[idx + 1] - ((int64_t *)ss_elem_node_ndx)[idx]; } else { num_node_per_side = ((int *)ss_elem_node_ndx)[idx + 1] - ((int *)ss_elem_node_ndx)[idx]; } if (ss_node1 == get_node(connect, num_nodes_per_elem * (elem_num_pos) + (shell_table[0][2 * n] - 1), int_size)) { if (num_node_per_side >= 4) { /* 4- or 8-node side (front or back face) */ put_side(side_sets_side_list, idx, shell_table[1][2 * n], int_size); } else { /* 2- or 3-node side (edge of shell) */ put_side(side_sets_side_list, idx, shell_edge_table[1][2 * n], int_size); } } else if (ss_node1 == get_node(connect, num_nodes_per_elem * (elem_num_pos) + (shell_table[0][2 * n + 1] - 1), int_size)) { if (num_node_per_side >= 4) { /* 4- or 8-node side (front or back face) */ put_side(side_sets_side_list, idx, shell_table[1][2 * n + 1], int_size); } else { /* 2- or 3-node side (edge of shell) */ put_side(side_sets_side_list, idx, shell_edge_table[1][2 * n + 1], int_size); } } else if (ss_node1 == get_node(connect, num_nodes_per_elem * (elem_num_pos) + (shell_table[0][2 * n + 2] - 1), int_size)) { if (num_node_per_side >= 4) { /* 4- or 8-node side (front or back face) */ put_side(side_sets_side_list, idx, shell_table[1][2 * n + 2], int_size); } else { /* 2- or 3-node side (edge of shell) */ put_side(side_sets_side_list, idx, shell_edge_table[1][2 * n + 2], int_size); } } else { exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find SHELL element %" PRId64 ", node %" PRId64 " in connectivity array %" PRId64 " for file id %d", elem_num + 1, ss_node1, elem_blk_parms[p_ndx].elem_blk_id, exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } break; } case EX_EL_HEX: { /* use table to find which node to compare to next */ if (ss_node1 == get_node(connect, num_nodes_per_elem * (elem_num_pos) + (hex_table[0][3 * n] - 1), int_size)) { put_side(side_sets_side_list, idx, hex_table[1][3 * n], int_size); } else if (ss_node1 == get_node(connect, num_nodes_per_elem * (elem_num_pos) + (hex_table[0][3 * n + 1] - 1), int_size)) { put_side(side_sets_side_list, idx, hex_table[1][3 * n + 1], int_size); } else if (ss_node1 == get_node(connect, num_nodes_per_elem * (elem_num_pos) + (hex_table[0][3 * n + 2] - 1), int_size)) { put_side(side_sets_side_list, idx, hex_table[1][3 * n + 2], int_size); } else { exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find HEX element %" PRId64 ", node %" PRId64 " in connectivity array %" PRId64 " for file id %d", elem_num + 1, ss_node1, elem_blk_parms[p_ndx].elem_blk_id, exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } break; } case EX_EL_TETRA: { /* use table to find which node to compare to next */ if (ss_node1 == get_node(connect, num_nodes_per_elem * (elem_num_pos) + (tetra_table[0][3 * n] - 1), int_size)) { put_side(side_sets_side_list, idx, tetra_table[1][3 * n], int_size); } else if (ss_node1 == get_node(connect, num_nodes_per_elem * (elem_num_pos) + (tetra_table[0][3 * n + 1] - 1), int_size)) { put_side(side_sets_side_list, idx, tetra_table[1][3 * n + 1], int_size); } else if (ss_node1 == get_node(connect, num_nodes_per_elem * (elem_num_pos) + (tetra_table[0][3 * n + 2] - 1), int_size)) { put_side(side_sets_side_list, idx, tetra_table[1][3 * n + 2], int_size); } else { exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find TETRA element %" PRId64 ", node %" PRId64 " in connectivity array %" PRId64 " for file id %d", elem_num + 1, ss_node1, elem_blk_parms[p_ndx].elem_blk_id, exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } break; } case EX_EL_PYRAMID: { /* NOTE: PYRAMID elements in side set node lists are currently not * supported */ exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unsupported PYRAMID element found in side " "set node list in file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } case EX_EL_WEDGE: { /* NOTE: WEDGE elements in side set node lists are currently not * supported */ exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unsupported WEDGE element found in side set " "node list in file id %d", exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } default: { exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: %s is an unsupported element type", elem_blk_parms[p_ndx].elem_type); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } } break; /* done with this element */ } } if (n >= num_nodes_per_elem) /* did we find the node? */ { exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find element %" PRId64 ", node %" PRId64 " in element block %" PRId64 " for file id %d", elem_num + 1, ss_node0, elem_blk_parms[p_ndx].elem_blk_id, exoid); ex_err("ex_cvt_nodes_to_sides", errmsg, exerrval); err_stat = EX_FATAL; goto cleanup; } } /* All done: release connectivity array space, element block ids array, element block parameters array, and side set element index array */ cleanup: free(connect); free(ss_elem_node_ndx); free(ss_parm_ndx); free(elem_blk_parms); free(elem_blk_ids); free(ss_elem_ndx); free(same_elem_type); return (err_stat); }
int ex_get_nodal_var_time (int exoid, int nodal_var_index, int64_t node_number, int beg_time_step, int end_time_step, void *nodal_var_vals) { int status; int varid; size_t start[3], count[3]; char errmsg[MAX_ERR_LENGTH]; beg_time_step--; node_number--; /* inquire previously defined variable */ if (end_time_step < 0) { /* user is requesting the maximum time step; we find this out using the * database inquire function to get the number of time steps; the ending * time step number is 1 less due to 0 based array indexing in C */ end_time_step = ex_inquire_int (exoid, EX_INQ_TIME); } end_time_step--; if (ex_large_model(exoid) == 0) { /* read values of the nodal variable; * assume node number is 1-based (first node is numbered 1); adjust * so it is 0-based */ if ((status = nc_inq_varid(exoid, VAR_NOD_VAR, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Warning: could not find nodal variable %d in file id %d", nodal_var_index, exoid); ex_err("ex_get_nodal_var",errmsg,exerrval); return (EX_WARN); } start[0] = beg_time_step; start[1] = --nodal_var_index; start[2] = node_number; count[0] = end_time_step - beg_time_step + 1; count[1] = 1; count[2] = 1; } else { if ((status = nc_inq_varid(exoid, VAR_NOD_VAR_NEW(nodal_var_index), &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Warning: could not find nodal variable %d in file id %d", nodal_var_index, exoid); ex_err("ex_get_nodal_var",errmsg,exerrval); return (EX_WARN); } /* read values of the nodal variable; * assume node number is 1-based (first node is numbered 1); adjust * so it is 0-based */ start[0] = beg_time_step; start[1] = node_number; count[0] = end_time_step - beg_time_step + 1; count[1] = 1; } if (ex_comp_ws(exoid) == 4) { status = nc_get_vara_float(exoid, varid, start, count, nodal_var_vals); } else { status = nc_get_vara_double(exoid, varid, start, count, nodal_var_vals); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get nodal variables in file id %d", exoid); ex_err("ex_get_nodal_var_time",errmsg,exerrval); return (EX_FATAL); } return (EX_NOERR); }