Debian Codegraph @

packages/seacas/libraries/exodus/src/ex__get_nodal_var_multi_time.c

raw
1 /*
2 * Copyright(C) 1999-2020, 2023 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 #include "exodusII.h" // for ex_err, etc
10 #include "exodusII_int.h" // for EX_NOERR, EX_WARN, etc
11
12 /*!
13 \internal
14 \ingroup ResultsData
15 \note This function is called internally by ex_get_var_multi_time() to handle
16 the reading of nodal variable values.
17
18 The function exi_get_nodal_var_multi_time() reads the values of a single nodal
19 variable for a one or more time steps. Memory must be allocated for the
20 nodal variable values array before this function is invoked.
21
22 Because nodal variables are floating point values, the application
23 code must declare the array passed to be the appropriate type
24 (float or double) to match the compute word size passed in
25 ex_create() or ex_open().
26
27 \return In case of an error, exi_get_nodal_var_multi_time() returns a negative
28 number; a warning will return a positive number. Possible causes of
29 errors include:
30 - data file not properly opened with call to ex_create() or ex_open()
31 - specified nodal variable does not exist.
32 - a warning value is returned if no nodal variables are stored in the file.
33
34 \param[in] exoid exodus file ID returned from a previous call to
35 ex_create()
36 or ex_open().
37
38 \param[in] nodal_var_index The index of the desired nodal variable. The
39 first variable has an index of 1.
40
41 \param[in] num_nodes The number of nodal points.
42
43 \param[in] beg_time_step The first time step to get values for.
44 \param[in] end_time_step The last time step to get values for.
45 \param[out] nodal_var_vals Returned array of num_nodes values of the
46 nodal_var_index-th nodal variable for the
47 desired timesteps.
48
49 For example, the following demonstrates how this function would be
50 used:
51
52 ~~~{.c}
53 int num_nodes, time_step, var_index;
54 float *var_values;
55
56 \comment{read the second nodal variable at the first time step}
57 time_step = 1;
58 var_index = 2;
59
60 var_values = (float *) calloc (num_nodes, sizeof(float));
61 error = exi_get_nodal_var_multi_time(exoid, var_index, num_nodes,
62 time_step, time_step, var_values);
63 ~~~
64
65 */
66
67 int exi_get_nodal_var_multi_time(int exoid, int nodal_var_index, int64_t num_nodes,
68 int beg_time_step, int end_time_step, void *nodal_var_vals)
69 {
70 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
71 EX_FUNC_LEAVE(EX_FATAL);
72 }
73
74 /* inquire previously defined variable */
75 /* Need to see how this works in the parallel-aware exodus... */
76 if (num_nodes == 0) {
77 return EX_NOERR;
78 }
79
80 size_t start[3];
81 size_t count[3];
82 int status;
83 int varid;
84 if (ex_large_model(exoid) == 0) {
85 /* read values of the nodal variable */
86 if ((status = nc_inq_varid(exoid, VAR_NOD_VAR, &varid)) != NC_NOERR) {
87 char errmsg[MAX_ERR_LENGTH];
88 snprintf(errmsg, MAX_ERR_LENGTH, "Warning: could not find nodal variables in file id %d",
89 exoid);
90 ex_err_fn(exoid, __func__, errmsg, status);
91 return EX_WARN;
92 }
93
94 start[0] = --beg_time_step;
95 start[1] = --nodal_var_index;
96 start[2] = 0;
97
98 count[0] = end_time_step - beg_time_step;
99 count[1] = 1;
100 count[2] = num_nodes;
101 }
102 else {
103 /* read values of the nodal variable -- stored as separate variables... */
104 /* Get the varid.... */
105 if ((status = nc_inq_varid(exoid, VAR_NOD_VAR_NEW(nodal_var_index), &varid)) != NC_NOERR) {
106 char errmsg[MAX_ERR_LENGTH];
107 snprintf(errmsg, MAX_ERR_LENGTH, "Warning: could not find nodal variable %d in file id %d",
108 nodal_var_index, exoid);
109 ex_err_fn(exoid, __func__, errmsg, status);
110 return EX_WARN;
111 }
112
113 start[0] = --beg_time_step;
114 start[1] = 0;
115
116 count[0] = end_time_step - beg_time_step;
117 count[1] = num_nodes;
118 }
119
120 if (exi_comp_ws(exoid) == 4) {
121 status = nc_get_vara_float(exoid, varid, start, count, nodal_var_vals);
122 }
123 else {
124 status = nc_get_vara_double(exoid, varid, start, count, nodal_var_vals);
125 }
126
127 if (status != NC_NOERR) {
128 char errmsg[MAX_ERR_LENGTH];
129 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get nodal variables in file id %d", exoid);
130 ex_err_fn(exoid, __func__, errmsg, status);
131 return EX_FATAL;
132 }
133 return EX_NOERR;
134 }