Exodus 8.24
Loading...
Searching...
No Matches
/test/testrdwt.c
/*
* Copyright(C) 1999-2021 National Technology & Engineering Solutions
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
* NTESS, the U.S. Government retains certain rights in this software.
*
* See packages/seacas/LICENSE for details
*/
/*****************************************************************************
*
* testrdwt - test reading from one ExodusII file and writing to another
* ExodusII file open concurrently
*
* author - Sandia National Laboratories
* Larry A. Schoof - Original
*
* environment - UNIX
*
* entry conditions -
*
* exit conditions -
*
* revision history -
*
* This is a test program for the C binding of the EXODUS II
* database read and write routines. It tests reading from an open EXODUSII
* file and writing to another concurrently opened EXODUSII file.
*
*
*****************************************************************************/
#include "exodusII.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int num_elem_in_block, num_nodes_per_elem, num_attr;
int num_nodes_in_set;
int num_sides_in_set, num_df_in_set;
char title[MAX_LINE_LENGTH + 1], elem_type[MAX_STR_LENGTH + 1];
/* Specify compute and i/o word size */
int CPU_word_size = 0; /* sizeof(float) */
int IO_word_size = 4; /* float */
/* open EXODUS II file for reading */
float version;
int exoid = ex_open("test.exo", /* filename path */
EX_READ, /* access mode */
&CPU_word_size, /* CPU float word size in bytes */
&IO_word_size, /* I/O float word size in bytes */
&version); /* returned version number */
printf("after ex_open for test.exo\n");
printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);
/* create EXODUS II file for writing */
int exoid2 = ex_create("test2.exo", /* filename path */
EX_CLOBBER, /* create mode */
&CPU_word_size, /* CPU float word size in bytes */
&IO_word_size); /* I/O float word size in bytes */
printf("after ex_create for test2.exo, exoid = %d\n", exoid2);
/* read initialization parameters */
int num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets;
int error = ex_get_init(exoid, title, &num_dim, &num_nodes, &num_elem, &num_elem_blk,
&num_node_sets, &num_side_sets);
printf("after ex_get_init, error = %d\n", error);
/* write initialization parameters */
error = ex_put_init(exoid2, title, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets,
num_side_sets);
printf("after ex_put_init, error = %d\n", error);
/* read nodal coordinate values */
float *x = (float *)calloc(num_nodes, sizeof(float));
float *y = (float *)calloc(num_nodes, sizeof(float));
float *z = (num_dim >= 3) ? (float *)calloc(num_nodes, sizeof(float)) : NULL;
error = ex_get_coord(exoid, x, y, z);
printf("\nafter ex_get_coord, error = %3d\n", error);
/* write nodal coordinate values */
error = ex_put_coord(exoid2, x, y, z);
printf("after ex_put_coord, error = %d\n", error);
free(x);
free(y);
if (num_dim >= 3) {
free(z);
}
/* read nodal coordinate names */
char *coord_names[3];
for (int i = 0; i < num_dim; i++) {
coord_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
}
error = ex_get_coord_names(exoid, coord_names);
printf("\nafter ex_get_coord_names, error = %3d\n", error);
/* write nodal coordinate names */
error = ex_put_coord_names(exoid2, coord_names);
printf("after ex_put_coord_names, error = %d\n", error);
for (int i = 0; i < num_dim; i++) {
free(coord_names[i]);
}
/* read element order map */
int *elem_map = (int *)calloc(num_elem, sizeof(int));
error = ex_get_id_map(exoid, EX_ELEM_MAP, elem_map);
printf("\nafter ex_get_id_map, error = %3d\n", error);
/* write element order map */
error = ex_put_id_map(exoid2, EX_ELEM_MAP, elem_map);
printf("after ex_put_id_map, error = %d\n", error);
free(elem_map);
/* read and write element block parameters and element connectivity */
int *ids = (int *)calloc(num_elem_blk, sizeof(int));
error = ex_get_ids(exoid, EX_ELEM_BLOCK, ids);
printf("\nafter ex_get_elem_blk_ids, error = %3d\n", error);
float attrib[] = {3.14159};
for (int i = 0; i < num_elem_blk; i++) {
error = ex_get_block(exoid, EX_ELEM_BLOCK, ids[i], elem_type, &num_elem_in_block,
&num_nodes_per_elem, 0, 0, &num_attr);
printf("\nafter ex_get_elem_block, error = %d\n", error);
error = ex_put_block(exoid2, EX_ELEM_BLOCK, ids[i], elem_type, num_elem_in_block,
num_nodes_per_elem, 0, 0, num_attr);
printf("after ex_put_elem_block, error = %d\n", error);
int *connect = (int *)calloc((num_nodes_per_elem * num_elem_in_block), sizeof(int));
error = ex_get_conn(exoid, EX_ELEM_BLOCK, ids[i], connect, NULL, NULL);
printf("\nafter ex_get_elem_conn, error = %d\n", error);
error = ex_put_conn(exoid2, EX_ELEM_BLOCK, ids[i], connect, NULL, NULL);
printf("after ex_put_elem_conn, error = %d\n", error);
/* write element block attributes */
error = ex_put_attr(exoid2, EX_ELEM_BLOCK, ids[i], attrib);
printf("after ex_put_elem_attr, error = %d\n", error);
free(connect);
}
/* read and write element block properties */
int num_props = ex_inquire_int(exoid, EX_INQ_EB_PROP);
printf("\nafter ex_inquire, error = %d\n", error);
char *prop_names[3];
for (int i = 0; i < num_props; i++) {
prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
}
error = ex_get_prop_names(exoid, EX_ELEM_BLOCK, prop_names);
printf("after ex_get_prop_names, error = %d\n", error);
error = ex_put_prop_names(exoid2, EX_ELEM_BLOCK, num_props, prop_names);
printf("after ex_put_prop_names, error = %d\n", error);
for (int i = 0; i < num_props; i++) {
for (int j = 0; j < num_elem_blk; j++) {
int prop_value;
error = ex_get_prop(exoid, EX_ELEM_BLOCK, ids[j], prop_names[i], &prop_value);
printf("after ex_get_prop, error = %d\n", error);
if (i > 0) { /* first property is the ID which is already stored */
error = ex_put_prop(exoid2, EX_ELEM_BLOCK, ids[j], prop_names[i], prop_value);
printf("after ex_put_prop, error = %d\n", error);
}
}
}
for (int i = 0; i < num_props; i++) {
free(prop_names[i]);
}
free(ids);
/* read and write individual node sets */
ids = (int *)calloc(num_node_sets, sizeof(int));
error = ex_get_ids(exoid, EX_NODE_SET, ids);
printf("\nafter ex_get_node_set_ids, error = %3d\n", error);
for (int i = 0; i < num_node_sets; i++) {
error = ex_get_set_param(exoid, EX_NODE_SET, ids[i], &num_nodes_in_set, &num_df_in_set);
printf("\nafter ex_get_node_set_param, error = %3d\n", error);
error = ex_put_set_param(exoid2, EX_NODE_SET, ids[i], num_nodes_in_set, num_df_in_set);
printf("after ex_put_node_set_param, error = %d\n", error);
int *node_list = (int *)calloc(num_nodes_in_set, sizeof(int));
float *dist_fact = (float *)calloc(num_nodes_in_set, sizeof(float));
error = ex_get_set(exoid, EX_NODE_SET, ids[i], node_list, NULL);
printf("\nafter ex_get_node_set, error = %3d\n", error);
error = ex_put_set(exoid2, EX_NODE_SET, ids[i], node_list, NULL);
printf("after ex_put_node_set, error = %d\n", error);
if (num_df_in_set > 0) {
error = ex_get_set_dist_fact(exoid, EX_NODE_SET, ids[i], dist_fact);
printf("\nafter ex_get_node_set_dist_fact, error = %3d\n", error);
error = ex_put_set_dist_fact(exoid2, EX_NODE_SET, ids[i], dist_fact);
printf("after ex_put_node_set, error = %d\n", error);
}
free(node_list);
free(dist_fact);
}
free(ids);
/* read node set properties */
num_props = ex_inquire_int(exoid, EX_INQ_NS_PROP);
printf("\nafter ex_inquire, error = %d\n", error);
for (int i = 0; i < num_props; i++) {
prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
}
int *prop_values = (int *)calloc(num_node_sets, sizeof(int));
error = ex_get_prop_names(exoid, EX_NODE_SET, prop_names);
printf("after ex_get_prop_names, error = %d\n", error);
error = ex_put_prop_names(exoid2, EX_NODE_SET, num_props, prop_names);
printf("after ex_put_prop_names, error = %d\n", error);
for (int i = 0; i < num_props; i++) {
error = ex_get_prop_array(exoid, EX_NODE_SET, prop_names[i], prop_values);
printf("after ex_get_prop_array, error = %d\n", error);
error = ex_put_prop_array(exoid2, EX_NODE_SET, prop_names[i], prop_values);
printf("after ex_put_prop_array, error = %d\n", error);
}
for (int i = 0; i < num_props; i++) {
free(prop_names[i]);
}
free(prop_values);
/* read and write individual side sets */
ids = (int *)calloc(num_side_sets, sizeof(int));
error = ex_get_ids(exoid, EX_SIDE_SET, ids);
printf("\nafter ex_get_side_set_ids, error = %3d\n", error);
for (int i = 0; i < num_side_sets; i++) {
error = ex_get_set_param(exoid, EX_SIDE_SET, ids[i], &num_sides_in_set, &num_df_in_set);
printf("\nafter ex_get_side_set_param, error = %3d\n", error);
error = ex_put_set_param(exoid2, EX_SIDE_SET, ids[i], num_sides_in_set, num_df_in_set);
printf("after ex_put_side_set_param, error = %d\n", error);
/* Note: The # of elements is same as # of sides! */
int num_elem_in_set = num_sides_in_set;
int *elem_list = (int *)calloc(num_elem_in_set, sizeof(int));
int *side_list = (int *)calloc(num_sides_in_set, sizeof(int));
int *node_ctr_list = (int *)calloc(num_elem_in_set, sizeof(int));
int *node_list = (int *)calloc(num_elem_in_set * 21, sizeof(int));
float *dist_fact = (float *)calloc(num_df_in_set, sizeof(float));
error = ex_get_set(exoid, EX_SIDE_SET, ids[i], elem_list, side_list);
printf("\nafter ex_get_side_set, error = %3d\n", error);
error = ex_put_set(exoid2, EX_SIDE_SET, ids[i], elem_list, side_list);
printf("after ex_put_side_set, error = %d\n", error);
error = ex_get_side_set_node_list(exoid, ids[i], node_ctr_list, node_list);
printf("\nafter ex_get_side_set_node_list, error = %3d\n", error);
if (num_df_in_set > 0) {
error = ex_get_set_dist_fact(exoid, EX_SIDE_SET, ids[i], dist_fact);
printf("\nafter ex_get_side_set_dist_fact, error = %3d\n", error);
error = ex_put_set_dist_fact(exoid2, EX_SIDE_SET, ids[i], dist_fact);
printf("after ex_put_side_set_dist_fact, error = %d\n", error);
}
free(elem_list);
free(side_list);
free(node_ctr_list);
free(node_list);
free(dist_fact);
}
/* read side set properties */
num_props = ex_inquire_int(exoid, EX_INQ_SS_PROP);
printf("\nafter ex_inquire, error = %d\n", error);
for (int i = 0; i < num_props; i++) {
prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
}
error = ex_get_prop_names(exoid, EX_SIDE_SET, prop_names);
printf("after ex_get_prop_names, error = %d\n", error);
for (int i = 0; i < num_props; i++) {
for (int j = 0; j < num_side_sets; j++) {
int prop_value;
error = ex_get_prop(exoid, EX_SIDE_SET, ids[j], prop_names[i], &prop_value);
printf("after ex_get_prop, error = %d\n", error);
if (i > 0) { /* first property is ID so it is already stored */
error = ex_put_prop(exoid2, EX_SIDE_SET, ids[j], prop_names[i], prop_value);
printf("after ex_put_prop, error = %d\n", error);
}
}
}
for (int i = 0; i < num_props; i++) {
free(prop_names[i]);
}
free(ids);
/* read and write QA records */
int num_qa_rec = ex_inquire_int(exoid, EX_INQ_QA);
char *qa_record[2][4];
for (int i = 0; i < num_qa_rec; i++) {
for (int j = 0; j < 4; j++) {
qa_record[i][j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char));
}
}
error = ex_get_qa(exoid, qa_record);
printf("\nafter ex_get_qa, error = %3d\n", error);
error = ex_put_qa(exoid2, num_qa_rec, qa_record);
printf("after ex_put_qa, error = %d\n", error);
for (int i = 0; i < num_qa_rec; i++) {
for (int j = 0; j < 4; j++) {
free(qa_record[i][j]);
}
}
/* read and write information records */
int num_info = ex_inquire_int(exoid, EX_INQ_INFO);
printf("\nafter ex_inquire, error = %3d\n", error);
char *info[3];
for (int i = 0; i < num_info; i++) {
info[i] = (char *)calloc((MAX_LINE_LENGTH + 1), sizeof(char));
}
error = ex_get_info(exoid, info);
printf("\nafter ex_get_info, error = %3d\n", error);
error = ex_put_info(exoid2, num_info, info);
printf("after ex_put_info, error = %d\n", error);
for (int i = 0; i < num_info; i++) {
free(info[i]);
}
/* close the EXODUS files */
error = ex_close(exoid);
printf("after ex_close, error = %d\n", error);
error = ex_close(exoid2);
printf("after ex_close (2), error = %d\n", error);
return 0;
}
@ EX_SIDE_SET
Definition exodusII.h:270
@ EX_NODE_SET
Definition exodusII.h:262
@ EX_ELEM_MAP
Definition exodusII.h:272
@ EX_ELEM_BLOCK
Definition exodusII.h:267
@ EX_ABORT
Definition exodusII.h:292
@ EX_VERBOSE
Definition exodusII.h:290
@ EX_INQ_INFO
Definition exodusII.h:155
@ EX_INQ_NS_PROP
Definition exodusII.h:158
@ EX_INQ_QA
Definition exodusII.h:154
@ EX_INQ_SS_PROP
Definition exodusII.h:159
@ EX_INQ_EB_PROP
Definition exodusII.h:157
#define EX_READ
Definition exodusII.h:95
#define EX_CLOBBER
Definition exodusII.h:98
int ex_put_set_param(int exoid, ex_entity_type set_type, ex_entity_id set_id, int64_t num_entries_in_set, int64_t num_dist_fact_in_set)
Definition ex_put_set_param.c:39
int ex_get_coord_names(int exoid, char **coord_names)
Definition ex_get_coord_names.c:46
int ex_get_coord(int exoid, void *x_coor, void *y_coor, void *z_coor)
Definition ex_get_coord.c:71
int ex_put_conn(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, const void_int *node_conn, const void_int *elem_edge_conn, const void_int *elem_face_conn)
Definition ex_put_conn.c:44
int ex_put_prop_names(int exoid, ex_entity_type obj_type, int num_props, char **prop_names)
Definition ex_put_prop_names.c:97
int ex_get_set(int exoid, ex_entity_type set_type, ex_entity_id set_id, void_int *set_entry_list, void_int *set_extra_list)
Definition ex_get_set.c:23
int ex_put_coord_names(int exoid, char *const coord_names[])
Definition ex_put_coord_names.c:46
int ex_get_set_param(int exoid, ex_entity_type set_type, ex_entity_id set_id, void_int *num_entry_in_set, void_int *num_dist_fact_in_set)
Definition ex_get_set_param.c:36
int ex_get_prop_array(int exoid, ex_entity_type obj_type, const char *prop_name, void_int *values)
Definition ex_get_prop_array.c:87
int ex_put_coord(int exoid, const void *x_coor, const void *y_coor, const void *z_coor)
Definition ex_put_coord.c:87
int ex_put_prop(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, const char *prop_name, ex_entity_id value)
Definition ex_put_prop.c:77
int ex_put_attr(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, const void *attrib)
Definition ex_put_attr.c:37
int ex_put_prop_array(int exoid, ex_entity_type obj_type, const char *prop_name, const void_int *values)
Definition ex_put_prop_array.c:71
int ex_put_init(int exoid, const char *title, int64_t num_dim, int64_t num_nodes, int64_t num_elem, int64_t num_elem_blk, int64_t num_node_sets, int64_t num_side_sets)
Definition ex_put_init.c:53
int ex_get_side_set_node_list(int exoid, ex_entity_id side_set_id, void_int *side_set_node_cnt_list, void_int *side_set_node_list)
Definition ex_get_side_set_node_list.c:58
int ex_get_set_dist_fact(int exoid, ex_entity_type set_type, ex_entity_id set_id, void *set_dist_fact)
Definition ex_get_set_dist_fact.c:33
int ex_get_block(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, char *elem_type, void_int *num_entries_this_blk, void_int *num_nodes_per_entry, void_int *num_edges_per_entry, void_int *num_faces_per_entry, void_int *num_attr_per_entry)
Definition ex_get_block.c:36
int ex_get_prop(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, const char *prop_name, void_int *value)
Definition ex_get_prop.c:55
int ex_get_init(int exoid, char *title, void_int *num_dim, void_int *num_nodes, void_int *num_elem, void_int *num_elem_blk, void_int *num_node_sets, void_int *num_side_sets)
Definition ex_get_init.c:75
int ex_get_ids(int exoid, ex_entity_type obj_type, void_int *ids)
Definition ex_get_ids.c:96
int ex_put_block(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, const char *entry_descrip, int64_t num_entries_this_blk, int64_t num_nodes_per_entry, int64_t num_edges_per_entry, int64_t num_faces_per_entry, int64_t num_attr_per_entry)
Definition ex_put_block.c:47
int ex_put_set_dist_fact(int exoid, ex_entity_type set_type, ex_entity_id set_id, const void *set_dist_fact)
Definition ex_put_set_dist_fact.c:37
int ex_put_set(int exoid, ex_entity_type set_type, ex_entity_id set_id, const void_int *set_entry_list, const void_int *set_extra_list)
Definition ex_put_set.c:41
int ex_put_id_map(int exoid, ex_entity_type map_type, const void_int *map)
Definition ex_put_id_map.c:37
int ex_get_conn(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, void_int *nodeconn, void_int *edgeconn, void_int *faceconn)
Definition ex_get_conn.c:29
int ex_get_id_map(int exoid, ex_entity_type map_type, void_int *map)
Definition ex_get_id_map.c:29
int ex_get_prop_names(int exoid, ex_entity_type obj_type, char **prop_names)
Definition ex_get_prop_names.c:78
#define MAX_STR_LENGTH
Definition exodusII.h:312
#define MAX_LINE_LENGTH
Definition exodusII.h:318
int64_t ex_inquire_int(int exoid, ex_inquiry req_info)
Definition ex_inquire.c:1021
#define ex_create(path, mode, comp_ws, io_ws)
Definition exodusII.h:494
int ex_put_qa(int exoid, int num_qa_records, char *qa_record[][4])
Definition ex_put_qa.c:63
int ex_get_info(int exoid, char **info)
Definition ex_get_info.c:48
int ex_opts(int options)
Definition ex_opts.c:56
#define ex_open(path, mode, comp_ws, io_ws, version)
Definition exodusII.h:500
int ex_put_info(int exoid, int num_info, char *const info[])
Definition ex_put_info.c:73
int ex_close(int exoid)
Definition ex_close.c:47
int ex_get_qa(int exoid, char *qa_record[][4])
Definition ex_get_qa.c:56