Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_get_partial_nodal_var_int.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 * exgnnv - ex_get_partial_nodal_var
11 *
12 * environment - UNIX
13 *
14 * entry conditions -
15 * input parameters:
16 * int exoid exodus file id
17 * int time_step whole time step number
18 * int nodeal_var_index index of desired nodal variable
19 * int start_node starting location for read
20 * int num_nodes number of nodal points
21 *
22 * exit conditions -
23 * float* var_vals array of nodal variable values
24 *
25 * revision history -
26 *
27 *
28 *****************************************************************************/
29
30 #include <exodusII.h> // for ex_err, etc
31 #include <exodusII_int.h> // for EX_WARN, exi_comp_ws, etc
32
33 /*!
34 \internal
35 \ingroup ResultsData
36 \note This function is called internally by ex_get_partial_var() to handle
37 the reading of nodal variable values.
38 */
39
40 int exi_get_partial_nodal_var(int exoid, int time_step, int nodal_var_index, int64_t start_node,
41 int64_t num_nodes, void *var_vals)
42 {
43 int varid;
44 int status;
45 size_t start[3], count[3];
46 char errmsg[MAX_ERR_LENGTH];
47
48 EX_FUNC_ENTER();
49 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
50 EX_FUNC_LEAVE(EX_FATAL);
51 }
52
53 if (ex_large_model(exoid) == 0) {
54 /* read values of the nodal variable */
55 if ((status = nc_inq_varid(exoid, VAR_NOD_VAR, &varid)) != NC_NOERR) {
56 snprintf(errmsg, MAX_ERR_LENGTH, "Warning: could not find nodal variables in file id %d",
57 exoid);
58 ex_err_fn(exoid, __func__, errmsg, status);
59 EX_FUNC_LEAVE(EX_WARN);
60 }
61
62 start[0] = --time_step;
63 start[1] = --nodal_var_index;
64 start[2] = --start_node;
65
66 count[0] = 1;
67 count[1] = 1;
68 count[2] = num_nodes;
69 }
70 else {
71 /* read values of the nodal variable -- stored as separate variables... */
72 /* Get the varid.... */
73 if ((status = nc_inq_varid(exoid, VAR_NOD_VAR_NEW(nodal_var_index), &varid)) != NC_NOERR) {
74 snprintf(errmsg, MAX_ERR_LENGTH, "Warning: could not find nodal variable %d in file id %d",
75 nodal_var_index, exoid);
76 ex_err_fn(exoid, __func__, errmsg, status);
77 EX_FUNC_LEAVE(EX_WARN);
78 }
79
80 start[0] = --time_step;
81 start[1] = --start_node;
82
83 count[0] = 1;
84 count[1] = num_nodes;
85 if (count[1] == 0) {
86 start[1] = 0;
87 }
88 }
89
90 if (exi_comp_ws(exoid) == 4) {
91 status = nc_get_vara_float(exoid, varid, start, count, var_vals);
92 }
93 else {
94 status = nc_get_vara_double(exoid, varid, start, count, var_vals);
95 }
96
97 if (status != NC_NOERR) {
98 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get nodal variables in file id %d", exoid);
99 ex_err_fn(exoid, __func__, errmsg, status);
100 EX_FUNC_LEAVE(EX_FATAL);
101 }
102 EX_FUNC_LEAVE(EX_NOERR);
103 }