Debian Codegraph @

packages/seacas/libraries/exodus/test/testcp_tran.c

raw
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 * testcp - copy file test.exo created by testwt
11 *
12 * author - Sandia National Laboratories
13 * Larry A. Schoof - Original
14 *
15 *
16 * environment - UNIX
17 *
18 * entry conditions -
19 * input parameters:
20 *
21 * exit conditions -
22 *
23 * revision history -
24 *
25 *****************************************************************************/
26
27 #include "exodusII.h"
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 int main(int argc, char **argv)
32 {
33 int exoid, exoid1, error, idum;
34 int CPU_word_size, IO_word_size;
35 int num_nod_vars;
36 int num_ele_vars;
37 int i, j;
38
39 float version;
40
41 char *cdum = NULL;
42
43 ex_opts(EX_VERBOSE | EX_ABORT);
44
45 /* open EXODUS II files */
46
47 CPU_word_size = 0; /* sizeof(float) */
48 IO_word_size = 0; /* use size in file */
49
50 exoid = ex_open("test.exo", /* filename path */
51 EX_READ, /* access mode = READ */
52 &CPU_word_size, /* CPU word size */
53 &IO_word_size, /* IO word size */
54 &version); /* ExodusII library version */
55
56 printf("\nafter ex_open\n");
57 if (exoid < 0) {
58 exit(1);
59 }
60
61 printf("test.exo is an EXODUSII file; version %4.2f\n", version);
62 printf(" CPU word size %1d\n", CPU_word_size);
63 printf(" I/O word size %1d\n", IO_word_size);
64 ex_inquire(exoid, EX_INQ_API_VERS, &idum, &version, cdum);
65 printf("EXODUSII API; version %4.2f\n", version);
66
67 CPU_word_size = 4;
68 IO_word_size = 4;
69
70 exoid1 = ex_create("testcp.exo", /* filename */
71 EX_CLOBBER, /* OK to overwrite */
72 &CPU_word_size, /* CPU float word size in bytes */
73 &IO_word_size); /* I/O float word size in bytes */
74
75 printf("\nafter ex_create, exoid = %3d\n", exoid1);
76 if (exoid1 < 0) {
77 exit(1);
78 }
79
80 printf(" CPU word size %1d\n", CPU_word_size);
81 printf(" I/O word size %1d\n", IO_word_size);
82
83 error = ex_copy(exoid, exoid1);
84 printf("\nafter ex_copy, error = %3d\n", error);
85
86 /* See if any nodal transient variables on the input database */
87 error = ex_get_variable_param(exoid, EX_NODE_BLOCK, &num_nod_vars);
88 printf("\nafter ex_get_variable_param, error = %3d\n", error);
89 error = ex_get_variable_param(exoid, EX_ELEM_BLOCK, &num_ele_vars);
90 printf("\nafter ex_get_variable_param, error = %3d\n", error);
91
92 if (num_nod_vars > 0) {
93 num_nod_vars++;
94 error = ex_put_variable_param(exoid1, EX_NODE_BLOCK, num_nod_vars);
95 printf("\nafter ex_put_variable_param, error = %3d\n", error);
96 }
97
98 if (num_ele_vars > 0) {
99 num_ele_vars++;
100 error = ex_put_variable_param(exoid1, EX_ELEM_BLOCK, num_ele_vars);
101 printf("\nafter ex_put_variable_param, error = %3d\n", error);
102 }
103
104 error = ex_copy_transient(exoid, exoid1);
105 printf("\nafter ex_copy_transient, error = %3d\n", error);
106
107 if (num_nod_vars > 0) {
108 float node_vars[33]; /* Know that there are 33 nodes */
109 error = ex_put_variable_name(exoid1, EX_NODE_BLOCK, num_nod_vars, "GregNode");
110 printf("\nafter ex_put_variable_name, error = %3d\n", error);
111 for (i = 0; i < 10; i++) {
112 for (j = 0; j < 33; j++) {
113 node_vars[j] = 3 + (float)(j + 1) * ((float)(i + 1) / 100.0);
114 }
115 error = ex_put_var(exoid1, i + 1, EX_NODE_BLOCK, num_nod_vars, 1, 33, node_vars);
116 printf("\nafter ex_put_var, step %d, error = %3d\n", i + 1, error);
117 }
118 }
119
120 if (num_ele_vars > 0) {
121 error = ex_put_variable_name(exoid1, EX_ELEM_BLOCK, num_ele_vars, "GregElem");
122 printf("\nafter ex_put_variable_name, error = %3d\n", error);
123
124 /* Add the element variable to a single block. 1 element per block */
125 float ele_vars[1];
126 for (i = 0; i < 10; i++) { /* timesteps */
127 for (j = 0; j < 1; j++) {
128 ele_vars[j] = num_ele_vars + (float)(j + 1) * ((float)(i + 1) / 100.0);
129 }
130 error = ex_put_var(exoid1, i + 1, EX_ELEM_BLOCK, num_ele_vars, 10, 1, ele_vars);
131 printf("\nafter ex_put_var, step %d, error = %3d\n", i + 1, error);
132 }
133 }
134 error = ex_close(exoid);
135 printf("\nafter ex_close, error = %3d\n", error);
136
137 error = ex_close(exoid1);
138 printf("\nafter ex_close, error = %3d\n", error);
139 return 0;
140 }