#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#define EX_TEST_FILENAME "edgeFace.exo"
#define EXCHECK(funcall, errmsg) \
if ((funcall) < 0) { \
fprintf(stderr, errmsg); \
return 1; \
}
#define EXCHKPI(funcall, errmsg, sucmsg, ival) \
if ((funcall) < 0) { \
fprintf(stderr, errmsg); \
return 1; \
} \
else { \
fprintf(stdout, sucmsg, ival); \
}
};
const char *obj_typenames[] = {" Edge block", " Face block", "Element block", " Node set",
" Edge set", " Face set", " Side set", " Element set",
" Node map", " Edge map", " Face map", " Element map"};
-1,
-1,
-1,
-1};
#define OBJECT_IS_BLOCK(i) ((i >= 0) && (i < 3))
#define OBJECT_IS_SET(i) ((i > 2) && (i < 8))
{
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;
int num_entries;
double * entry_vals;
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;
}
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",
for (i = 0; i < sizeof(obj_types) / sizeof(obj_types[0]); ++i) {
have_var_names = 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) {
}
if ((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) {
int *tp;
"Could not read number of variables.\n");
if (num_vars && num_timesteps > 0) {
truth_tab = (
int *)malloc(num_vars * nids *
sizeof(
int));
"Could not read truth table.\n");
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) {
}
"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;
&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 {
"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;
"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) {
}
"Could not read attributes names.\n");
"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;
"Could not read set parameters.\n");
set_entry = (int *)malloc(num_entries * sizeof(int));
? (int *)malloc(num_entries * sizeof(int))
: 0;
"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) {
"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 {
int *map;
switch (obj_types[i]) {
default: num_entries = 0;
}
if (num_entries) {
fprintf(stdout, "Entries: %3d\n :", num_entries);
map = (int *)malloc(num_entries * sizeof(int));
for (j = 0; j < num_entries; ++j) {
fprintf(stdout, " %d", map[j]);
}
free(map);
}
else {
fprintf(stdout, "Entries: none");
}
}
fprintf(stdout, "\n");
if (((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) && num_vars && num_timesteps > 0) {
entry_vals = (double *)malloc(num_entries * sizeof(double));
for (j = 0; j < num_vars; ++j) {
int k;
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) {
entry_vals = (double *)malloc(num_timesteps * sizeof(double));
itmp[1] = 11;
while (itmp[1] > itmp[0]) {
itmp[1] /= 2;
}
for (j = 0; j < num_vars; ++j) {
"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(ids);
for (obj = 0; obj < nids; ++obj) {
free(obj_names[obj]);
}
free(obj_names);
fprintf(stdout, "\n");
}
return 0;
}
#if !defined(USING_CMAKE)
int main(
int argc,
char *argv[]) {
return cReadEdgeFace(argc, argv); }
#endif