Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_put_processor_elem_maps.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 /*****************************************************************************/
11 /* Function(s) contained in this file:
12 * ex_put_elem_map()
13 *****************************************************************************
14 * This function outputs the elemental map.
15 *****************************************************************************
16 * Variable Index:
17 * exoid - The NetCDF ID of an already open NemesisI file.
18 * elem_mapi - Vector of internal element IDs.
19 * elem_mapb - Vector of border element IDs.
20 * processor - The processor ID for which info is to be read.
21 */
22 /*****************************************************************************/
23 /*****************************************************************************/
24 /*****************************************************************************/
25
26 #include <exodusII.h> // for ex_err, etc
27 #include <exodusII_int.h> // for EX_FATAL, DIM_NUM_BOR_ELEMS, etc
28
29 int ex_put_processor_elem_maps(int exoid, const void_int *elem_mapi, const void_int *elem_mapb,
30 int processor)
31 {
32 char ftype[2];
33 int status, dimid, varid;
34 size_t start[1], count[1];
35 int64_t varidx[2];
36 int nmstat;
37
38 char errmsg[MAX_ERR_LENGTH];
39 /*-----------------------------Execution begins-----------------------------*/
40
41 EX_FUNC_ENTER();
42 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
43 EX_FUNC_LEAVE(EX_FATAL);
44 }
45
46 /* Get the file type */
47 if (exi_get_file_type(exoid, ftype) != EX_NOERR) {
48 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to find file type for file ID %d", exoid);
49 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
50
51 EX_FUNC_LEAVE(EX_FATAL);
52 }
53
54 /* Get the status of the internal element map */
55 if ((status = nc_inq_varid(exoid, VAR_INT_E_STAT, &varid)) != NC_NOERR) {
56 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
57 VAR_INT_E_STAT, exoid);
58 ex_err_fn(exoid, __func__, errmsg, status);
59
60 EX_FUNC_LEAVE(EX_FATAL);
61 }
62
63 if (ftype[0] == 's') {
64 start[0] = processor;
65 }
66 else {
67 start[0] = 0;
68 }
69
70 if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) {
71 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
72 VAR_INT_E_STAT, exoid);
73 ex_err_fn(exoid, __func__, errmsg, status);
74
75 EX_FUNC_LEAVE(EX_FATAL);
76 }
77
78 if (nmstat == 1) {
79 /* get the index */
80 if (ex_get_idx(exoid, VAR_ELEM_MAP_INT_IDX, varidx, processor) == -1) {
81 snprintf(errmsg, MAX_ERR_LENGTH,
82 "ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_ELEM_MAP_INT_IDX,
83 exoid);
84 ex_err_fn(exoid, __func__, errmsg, status);
85
86 EX_FUNC_LEAVE(EX_FATAL);
87 }
88
89 if (varidx[1] == -1) {
90 /* Get the size of the internal element map */
91 if ((status = nc_inq_dimid(exoid, DIM_NUM_INT_ELEMS, &dimid)) != NC_NOERR) {
92 snprintf(errmsg, MAX_ERR_LENGTH,
93 "ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_INT_ELEMS,
94 exoid);
95 ex_err_fn(exoid, __func__, errmsg, status);
96 EX_FUNC_LEAVE(EX_FATAL);
97 }
98
99 if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
100 snprintf(errmsg, MAX_ERR_LENGTH,
101 "ERROR: failed to find length of dimension \"%s\" in file ID %d",
102 DIM_NUM_INT_ELEMS, exoid);
103 ex_err_fn(exoid, __func__, errmsg, status);
104 EX_FUNC_LEAVE(EX_FATAL);
105 }
106
107 varidx[1] = count[0];
108 }
109
110 if ((status = nc_inq_varid(exoid, VAR_ELEM_MAP_INT, &varid)) != NC_NOERR) {
111 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
112 VAR_ELEM_MAP_INT, exoid);
113 ex_err_fn(exoid, __func__, errmsg, status);
114 EX_FUNC_LEAVE(EX_FATAL);
115 }
116
117 /* Output the map */
118 start[0] = varidx[0];
119 count[0] = varidx[1] - varidx[0];
120 if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
121 status = nc_put_vara_longlong(exoid, varid, start, count, elem_mapi);
122 }
123 else {
124 status = nc_put_vara_int(exoid, varid, start, count, elem_mapi);
125 }
126 if (status != NC_NOERR) {
127 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d",
128 VAR_ELEM_MAP_INT, exoid);
129 ex_err_fn(exoid, __func__, errmsg, status);
130 EX_FUNC_LEAVE(EX_FATAL);
131 }
132
133 } /* End "if (nmstat == 1)" */
134
135 /* Get the status of the border element map */
136 if ((status = nc_inq_varid(exoid, VAR_BOR_E_STAT, &varid)) != NC_NOERR) {
137 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
138 VAR_BOR_E_STAT, exoid);
139 ex_err_fn(exoid, __func__, errmsg, status);
140
141 EX_FUNC_LEAVE(EX_FATAL);
142 }
143
144 if (ftype[0] == 's') {
145 start[0] = processor;
146 }
147 else {
148 start[0] = 0;
149 }
150
151 if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) {
152 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" from file %d",
153 VAR_BOR_E_STAT, exoid);
154 ex_err_fn(exoid, __func__, errmsg, status);
155
156 EX_FUNC_LEAVE(EX_FATAL);
157 }
158
159 if (nmstat == 1) {
160 /* get the index */
161 if (ex_get_idx(exoid, VAR_ELEM_MAP_BOR_IDX, varidx, processor) == -1) {
162 snprintf(errmsg, MAX_ERR_LENGTH,
163 "ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_ELEM_MAP_BOR_IDX,
164 exoid);
165 ex_err_fn(exoid, __func__, errmsg, status);
166
167 EX_FUNC_LEAVE(EX_FATAL);
168 }
169
170 if (varidx[1] == -1) {
171 /* Get the size of the border element map */
172 if ((status = nc_inq_dimid(exoid, DIM_NUM_BOR_ELEMS, &dimid)) != NC_NOERR) {
173 snprintf(errmsg, MAX_ERR_LENGTH,
174 "ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_BOR_ELEMS,
175 exoid);
176 ex_err_fn(exoid, __func__, errmsg, status);
177 EX_FUNC_LEAVE(EX_FATAL);
178 }
179
180 if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
181 snprintf(errmsg, MAX_ERR_LENGTH,
182 "ERROR: failed to find length of dimension \"%s\" in file ID %d",
183 DIM_NUM_BOR_ELEMS, exoid);
184 ex_err_fn(exoid, __func__, errmsg, status);
185 EX_FUNC_LEAVE(EX_FATAL);
186 }
187
188 varidx[1] = count[0];
189 }
190
191 if ((status = nc_inq_varid(exoid, VAR_ELEM_MAP_BOR, &varid)) != NC_NOERR) {
192 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
193 VAR_ELEM_MAP_BOR, exoid);
194 ex_err_fn(exoid, __func__, errmsg, status);
195 EX_FUNC_LEAVE(EX_FATAL);
196 }
197
198 /* Output the map */
199 start[0] = varidx[0];
200 count[0] = varidx[1] - varidx[0];
201 if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
202 status = nc_put_vara_longlong(exoid, varid, start, count, elem_mapb);
203 }
204 else {
205 status = nc_put_vara_int(exoid, varid, start, count, elem_mapb);
206 }
207 if (status != NC_NOERR) {
208 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d",
209 VAR_ELEM_MAP_BOR, exoid);
210 ex_err_fn(exoid, __func__, errmsg, status);
211 EX_FUNC_LEAVE(EX_FATAL);
212 }
213 } /* End "if (nmstat == 1)" */
214 EX_FUNC_LEAVE(EX_NOERR);
215 }