Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-2022, 2024 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_FATAL, exi_comp_ws, etc
11
12 /*!
13 * writes the coordinates of some of the nodes in the model for the specified component
14 * \param exoid exodus file id
15 * \param start_node_num the starting index (1-based) of the coordinates to
16 * be written
17 * \param num_nodes the number of nodes to write coordinates for.
18 * \param component which component (1=X, 2=Y, 3=Z)
19 * \param coor coord array
20 */
21
22 int ex_put_partial_coord_component(int exoid, int64_t start_node_num, int64_t num_nodes,
23 int component, const void *coor)
24 {
25 EX_FUNC_ENTER();
26 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
27 EX_FUNC_LEAVE(EX_FATAL);
28 }
29
30 /* inquire id's of previously defined dimensions */
31
32 int status;
33 int numnoddim;
34 if (nc_inq_dimid(exoid, DIM_NUM_NODES, &numnoddim) != NC_NOERR) {
35 /* If not found, then this file is storing 0 nodes.
36 Return immediately */
37 EX_FUNC_LEAVE(EX_NOERR);
38 }
39
40 int64_t num_nod;
41 {
42 size_t tmp;
43 if ((status = nc_inq_dimlen(exoid, numnoddim, &tmp)) != NC_NOERR) {
44 char errmsg[MAX_ERR_LENGTH];
45 snprintf(errmsg, MAX_ERR_LENGTH,
46 "ERROR: inquire failed to return number of nodes in file id %d", exoid);
47 ex_err_fn(exoid, __func__, errmsg, status);
48 EX_FUNC_LEAVE(EX_FATAL);
49 }
50 num_nod = tmp;
51 }
52
53 int ndimdim;
54 if ((status = nc_inq_dimid(exoid, DIM_NUM_DIM, &ndimdim)) != NC_NOERR) {
55 char errmsg[MAX_ERR_LENGTH];
56 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate number of dimensions in file id %d",
57 exoid);
58 ex_err_fn(exoid, __func__, errmsg, status);
59 EX_FUNC_LEAVE(EX_FATAL);
60 }
61
62 size_t num_dim;
63 if ((status = nc_inq_dimlen(exoid, ndimdim, &num_dim)) != NC_NOERR) {
64 char errmsg[MAX_ERR_LENGTH];
65 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of dimensions in file id %d",
66 exoid);
67 ex_err_fn(exoid, __func__, errmsg, status);
68 EX_FUNC_LEAVE(EX_FATAL);
69 }
70
71 --start_node_num;
72 if (start_node_num + num_nodes > num_nod) {
73 char errmsg[MAX_ERR_LENGTH];
74 snprintf(errmsg, MAX_ERR_LENGTH,
75 "ERROR: start index (%" PRId64 ") + node count (%" PRId64
76 ") is larger than total number of nodes (%" PRId64 ") in file id %d",
77 start_node_num, num_nodes, num_nod, exoid);
78 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
79 EX_FUNC_LEAVE(EX_FATAL);
80 }
81
82 if (component > (int)num_dim) {
83 char errmsg[MAX_ERR_LENGTH];
84 snprintf(errmsg, MAX_ERR_LENGTH,
85 "ERROR: Component (%d) is larger than number of dimensions (%zu) in file id %d",
86 component, num_dim, exoid);
87 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
88 EX_FUNC_LEAVE(EX_FATAL);
89 }
90 --component;
91
92 /* write out the coordinates */
93 {
94 char *which = NULL;
95 char *comp = NULL;
96
97 size_t start[] = {start_node_num};
98 size_t count[] = {num_nodes};
99 if (count[0] == 0) {
100 start[0] = 0;
101 }
102
103 if (component == 0) {
104 which = "X";
105 comp = VAR_COORD_X;
106 }
107 else if (component == 1) {
108 which = "Y";
109 comp = VAR_COORD_Y;
110 }
111 else if (component == 2) {
112 which = "Z";
113 comp = VAR_COORD_Z;
114 }
115
116 int coordid;
117 if ((status = nc_inq_varid(exoid, comp, &coordid)) != NC_NOERR) {
118 char errmsg[MAX_ERR_LENGTH];
119 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s nodal coordinates in file id %d",
120 which, exoid);
121 ex_err_fn(exoid, __func__, errmsg, status);
122 EX_FUNC_LEAVE(EX_FATAL);
123 }
124
125 if (exi_comp_ws(exoid) == 4) {
126 status = nc_put_vara_float(exoid, coordid, start, count, coor);
127 }
128 else {
129 status = nc_put_vara_double(exoid, coordid, start, count, coor);
130 }
131
132 if (status != NC_NOERR) {
133 char errmsg[MAX_ERR_LENGTH];
134 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put %s coord array in file id %d", which,
135 exoid);
136 ex_err_fn(exoid, __func__, errmsg, status);
137 EX_FUNC_LEAVE(EX_FATAL);
138 }
139 }
140 EX_FUNC_LEAVE(EX_NOERR);
141 }