Exodus  7.22
/test/testwt-zeron.c
/*
* Copyright (c) 2005-2017 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.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of NTESS nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*****************************************************************************
*
* testwt - test write an ExodusII database file
*
* author - Sandia National Laboratories
* Larry A. Schoof - Original
* Vic Yarberry - Added headers and error logging
* 7/7/93 Modified for use with Exodus 2.00
*
*
* environment - UNIX
*
* entry conditions -
*
* exit conditions -
*
* revision history -
*
* This is a test program for the C binding of the EXODUS II
* database write routines.
*
*
*****************************************************************************/
#include "exodusII.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
int num_node_sets, num_side_sets, error;
int i, j;
int num_qa_rec, num_info;
int num_glo_vars;
int whole_time_step, num_time_steps;
int CPU_word_size, IO_word_size;
float *glob_var_vals;
float time_value;
char * coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
/* Specify compute and i/o word size */
CPU_word_size = 0; /* sizeof(float) */
IO_word_size = 4; /* (4 bytes) */
/* create EXODUS II file */
exoid = ex_create("test.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 test.exo, exoid = %d\n", exoid);
printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);
/* initialize file with parameters */
num_dim = 1;
num_nodes = 0;
num_elem = 0;
num_elem_blk = 0;
num_node_sets = 0;
num_side_sets = 0;
error = ex_put_init(exoid, "This is a test", num_dim, num_nodes, num_elem, num_elem_blk,
num_node_sets, num_side_sets);
printf("after ex_put_init, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
coord_names[0] = "xcoor";
error = ex_put_coord_names(exoid, coord_names);
printf("after ex_put_coord_names, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
/* write QA records; test empty and just blank-filled records */
num_qa_rec = 2;
qa_record[0][0] = "TESTWT";
qa_record[0][1] = "testwt";
qa_record[0][2] = "07/07/93";
qa_record[0][3] = "15:41:33";
qa_record[1][0] = "";
qa_record[1][1] = " ";
qa_record[1][2] = "";
qa_record[1][3] = " ";
error = ex_put_qa(exoid, num_qa_rec, qa_record);
printf("after ex_put_qa, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
/* write information records; test empty and just blank-filled records */
num_info = 3;
info[0] = "This is the first information record.";
info[1] = "";
info[2] = " ";
error = ex_put_info(exoid, num_info, info);
printf("after ex_put_info, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
/* write results variables parameters and names */
num_glo_vars = 1;
var_names[0] = "glo_vars";
error = ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars);
printf("after ex_put_variable_param, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
error = ex_put_variable_names(exoid, EX_GLOBAL, num_glo_vars, var_names);
printf("after ex_put_variable_names, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
/* for each time step, write the analysis results;
* the code below fills the arrays glob_var_vals,
* nodal_var_vals, and elem_var_vals with values for debugging purposes;
* obviously the analysis code will populate these arrays
*/
whole_time_step = 1;
num_time_steps = 10;
glob_var_vals = (float *)calloc(num_glo_vars, CPU_word_size);
for (i = 0; i < num_time_steps; i++) {
time_value = (float)(i + 1) / 100.;
/* write time value */
error = ex_put_time(exoid, whole_time_step, &time_value);
printf("after ex_put_time, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
/* write global variables */
for (j = 0; j < num_glo_vars; j++) {
glob_var_vals[j] = (float)(j + 2) * time_value;
}
error = ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals);
printf("after ex_put_glob_vars, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
whole_time_step++;
/* update the data file; this should be done at the end of every time step
* to ensure that no data is lost if the analysis dies
*/
error = ex_update(exoid);
printf("after ex_update, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
}
free(glob_var_vals);
/* close the EXODUS files
*/
error = ex_close(exoid);
printf("after ex_close, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
return 0;
}
ex_put_qa
int ex_put_qa(int exoid, int num_qa_records, char *qa_record[][4])
Definition: ex_put_qa.c:90
ex_opts
int ex_opts(int options)
Definition: ex_opts.c:83
error
error
Definition: ex_put_elem_var_tab.c:115
ex_put_variable_param
int ex_put_variable_param(int exoid, ex_entity_type obj_type, int num_vars)
Definition: ex_put_variable_param.c:152
ex_put_time
int ex_put_time(int exoid, int time_step, const void *time_value)
Definition: ex_put_time.c:78
ex_create
#define ex_create(path, mode, comp_ws, io_ws)
Definition: exodusII.h:444
ex_close
int ex_close(int exoid)
Definition: ex_close.c:73
ex_put_coord_names
int ex_put_coord_names(int exoid, char *coord_names[])
Definition: ex_put_coord_names.c:73
EX_GLOBAL
Definition: exodusII.h:271
EX_ABORT
Definition: exodusII.h:284
ex_put_variable_names
int ex_put_variable_names(int exoid, ex_entity_type obj_type, int num_vars, char *var_names[])
Definition: ex_put_variable_names.c:151
EX_CLOBBER
#define EX_CLOBBER
Definition: exodusII.h:114
ex_put_info
int ex_put_info(int exoid, int num_info, char *info[])
Definition: ex_put_info.c:102
exodusII.h
ex_update
int ex_update(int exoid)
Definition: ex_update.c:56
ex_put_init
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:80
EX_VERBOSE
Definition: exodusII.h:282
ex_put_var
int ex_put_var(int exoid, int time_step, ex_entity_type var_type, int var_index, ex_entity_id obj_id, int64_t num_entries_this_obj, const void *var_vals)
Definition: ex_put_var.c:238