| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
/***************************************************************************** |
| 9 |
* |
| 10 |
* testwt - test write an ExodusII database file |
| 11 |
* |
| 12 |
* author - Sandia National Laboratories |
| 13 |
* Larry A. Schoof - Original |
| 14 |
* Vic Yarberry - Added headers and error logging |
| 15 |
* 7/7/93 Modified for use with Exodus 2.00 |
| 16 |
* |
| 17 |
* |
| 18 |
* environment - UNIX |
| 19 |
* |
| 20 |
* entry conditions - |
| 21 |
* |
| 22 |
* exit conditions - |
| 23 |
* |
| 24 |
* revision history - |
| 25 |
* |
| 26 |
* This is a test program for the C binding of the EXODUS II |
| 27 |
* database write routines. |
| 28 |
* |
| 29 |
* |
| 30 |
*****************************************************************************/ |
| 31 |
|
| 32 |
#include "exodusII.h" |
| 33 |
#include <stdio.h> |
| 34 |
#include <stdlib.h> |
| 35 |
|
| 36 |
int main(int argc, char **argv) |
| 37 |
{ |
| 38 |
int exoid, num_dim, num_nodes, num_elem, num_elem_blk; |
| 39 |
int num_node_sets, num_side_sets, error; |
| 40 |
int i, j; |
| 41 |
int num_qa_rec, num_info; |
| 42 |
int num_glo_vars; |
| 43 |
int whole_time_step, num_time_steps; |
| 44 |
int CPU_word_size, IO_word_size; |
| 45 |
|
| 46 |
float *glob_var_vals; |
| 47 |
float time_value; |
| 48 |
char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3]; |
| 49 |
|
| 50 |
ex_opts(EX_VERBOSE | EX_ABORT); |
| 51 |
|
| 52 |
/* Specify compute and i/o word size */ |
| 53 |
|
| 54 |
CPU_word_size = 0; /* sizeof(float) */ |
| 55 |
IO_word_size = 4; /* (4 bytes) */ |
| 56 |
|
| 57 |
/* create EXODUS II file */ |
| 58 |
|
| 59 |
exoid = ex_create("test.exo", /* filename path */ |
| 60 |
EX_CLOBBER, /* create mode */ |
| 61 |
&CPU_word_size, /* CPU float word size in bytes */ |
| 62 |
&IO_word_size); /* I/O float word size in bytes */ |
| 63 |
printf("after ex_create for test.exo, exoid = %d\n", exoid); |
| 64 |
printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size); |
| 65 |
|
| 66 |
/* initialize file with parameters */ |
| 67 |
|
| 68 |
num_dim = 1; |
| 69 |
num_nodes = 0; |
| 70 |
num_elem = 0; |
| 71 |
num_elem_blk = 0; |
| 72 |
num_node_sets = 0; |
| 73 |
num_side_sets = 0; |
| 74 |
|
| 75 |
error = ex_put_init(exoid, "This is a test", num_dim, num_nodes, num_elem, num_elem_blk, |
| 76 |
num_node_sets, num_side_sets); |
| 77 |
|
| 78 |
printf("after ex_put_init, error = %d\n", error); |
| 79 |
|
| 80 |
if (error) { |
| 81 |
ex_close(exoid); |
| 82 |
exit(-1); |
| 83 |
} |
| 84 |
|
| 85 |
coord_names[0] = "xcoor"; |
| 86 |
|
| 87 |
error = ex_put_coord_names(exoid, coord_names); |
| 88 |
printf("after ex_put_coord_names, error = %d\n", error); |
| 89 |
|
| 90 |
if (error) { |
| 91 |
ex_close(exoid); |
| 92 |
exit(-1); |
| 93 |
} |
| 94 |
|
| 95 |
/* write QA records; test empty and just blank-filled records */ |
| 96 |
|
| 97 |
num_qa_rec = 2; |
| 98 |
|
| 99 |
qa_record[0][0] = "TESTWT"; |
| 100 |
qa_record[0][1] = "testwt"; |
| 101 |
qa_record[0][2] = "07/07/93"; |
| 102 |
qa_record[0][3] = "15:41:33"; |
| 103 |
qa_record[1][0] = ""; |
| 104 |
qa_record[1][1] = " "; |
| 105 |
qa_record[1][2] = ""; |
| 106 |
qa_record[1][3] = " "; |
| 107 |
|
| 108 |
error = ex_put_qa(exoid, num_qa_rec, qa_record); |
| 109 |
printf("after ex_put_qa, error = %d\n", error); |
| 110 |
|
| 111 |
if (error) { |
| 112 |
ex_close(exoid); |
| 113 |
exit(-1); |
| 114 |
} |
| 115 |
|
| 116 |
/* write information records; test empty and just blank-filled records */ |
| 117 |
|
| 118 |
num_info = 3; |
| 119 |
|
| 120 |
info[0] = "This is the first information record."; |
| 121 |
info[1] = ""; |
| 122 |
info[2] = " "; |
| 123 |
|
| 124 |
error = ex_put_info(exoid, num_info, info); |
| 125 |
printf("after ex_put_info, error = %d\n", error); |
| 126 |
|
| 127 |
if (error) { |
| 128 |
ex_close(exoid); |
| 129 |
exit(-1); |
| 130 |
} |
| 131 |
|
| 132 |
/* write results variables parameters and names */ |
| 133 |
|
| 134 |
num_glo_vars = 1; |
| 135 |
|
| 136 |
var_names[0] = "glo_vars"; |
| 137 |
|
| 138 |
error = ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars); |
| 139 |
printf("after ex_put_variable_param, error = %d\n", error); |
| 140 |
if (error) { |
| 141 |
ex_close(exoid); |
| 142 |
exit(-1); |
| 143 |
} |
| 144 |
|
| 145 |
error = ex_put_variable_names(exoid, EX_GLOBAL, num_glo_vars, var_names); |
| 146 |
printf("after ex_put_variable_names, error = %d\n", error); |
| 147 |
if (error) { |
| 148 |
ex_close(exoid); |
| 149 |
exit(-1); |
| 150 |
} |
| 151 |
|
| 152 |
/* for each time step, write the analysis results; |
| 153 |
* the code below fills the arrays glob_var_vals, |
| 154 |
* nodal_var_vals, and elem_var_vals with values for debugging purposes; |
| 155 |
* obviously the analysis code will populate these arrays |
| 156 |
*/ |
| 157 |
|
| 158 |
whole_time_step = 1; |
| 159 |
num_time_steps = 10; |
| 160 |
|
| 161 |
glob_var_vals = (float *)calloc(num_glo_vars, CPU_word_size); |
| 162 |
|
| 163 |
for (i = 0; i < num_time_steps; i++) { |
| 164 |
time_value = (float)(i + 1) / 100.; |
| 165 |
|
| 166 |
/* write time value */ |
| 167 |
|
| 168 |
error = ex_put_time(exoid, whole_time_step, &time_value); |
| 169 |
printf("after ex_put_time, error = %d\n", error); |
| 170 |
|
| 171 |
if (error) { |
| 172 |
ex_close(exoid); |
| 173 |
exit(-1); |
| 174 |
} |
| 175 |
|
| 176 |
/* write global variables */ |
| 177 |
|
| 178 |
for (j = 0; j < num_glo_vars; j++) { |
| 179 |
glob_var_vals[j] = (float)(j + 2) * time_value; |
| 180 |
} |
| 181 |
|
| 182 |
error = ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals); |
| 183 |
printf("after ex_put_glob_vars, error = %d\n", error); |
| 184 |
|
| 185 |
if (error) { |
| 186 |
ex_close(exoid); |
| 187 |
exit(-1); |
| 188 |
} |
| 189 |
|
| 190 |
whole_time_step++; |
| 191 |
|
| 192 |
/* update the data file; this should be done at the end of every time step |
| 193 |
* to ensure that no data is lost if the analysis dies |
| 194 |
*/ |
| 195 |
error = ex_update(exoid); |
| 196 |
printf("after ex_update, error = %d\n", error); |
| 197 |
if (error) { |
| 198 |
ex_close(exoid); |
| 199 |
exit(-1); |
| 200 |
} |
| 201 |
} |
| 202 |
free(glob_var_vals); |
| 203 |
|
| 204 |
/* close the EXODUS files |
| 205 |
*/ |
| 206 |
error = ex_close(exoid); |
| 207 |
printf("after ex_close, error = %d\n", error); |
| 208 |
if (error) { |
| 209 |
ex_close(exoid); |
| 210 |
exit(-1); |
| 211 |
} |
| 212 |
return 0; |
| 213 |
} |