Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-2020, 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 *
10 * exgeat - ex_get_partial_one_attr
11 *
12 * entry conditions -
13 * input parameters:
14 * int exoid exodus file id
15 * int obj_type object type (edge, face, elem block)
16 * int obj_id object id (edge face, elem block ID)
17 * int start_num starting index of attributes to be
18 *returned.
19 * int num_ent number of entities to read attributes
20 *for.
21 *
22 * exit conditions -
23 * float* attrib array of attributes
24 *
25 * revision history -
26 *
27 *
28 *****************************************************************************/
29
30 #include "exodusII.h" // for ex_err, etc
31 #include "exodusII_int.h" // for EX_FATAL, exi_get_dimension, etc
32
33 /*!
34 * reads the specified attribute for a subsect of a block
35 * \param exoid exodus file id
36 * \param obj_type object type (edge, face, elem block)
37 * \param obj_id object id (edge, face, elem block ID)
38 * \param start_num the starting index of the attributes to be
39 * returned.
40 * \param num_ent the number of entities to read attributes for.
41 * \param attrib_index index of attribute to write
42 * \param attrib array of attributes
43 */
44 /*
45 */
46 int ex_get_partial_one_attr(int exoid, ex_entity_type obj_type, ex_entity_id obj_id,
47 int64_t start_num, int64_t num_ent, int attrib_index, void *attrib)
48
49 {
50 int status;
51 int attrid, obj_id_ndx;
52 int temp;
53 size_t num_entries_this_obj, num_attr;
54 size_t start[2], count[2];
55 ptrdiff_t stride[2];
56 char errmsg[MAX_ERR_LENGTH];
57 const char *dnumobjent;
58 const char *dnumobjatt;
59 const char *vattrbname;
60
61 EX_FUNC_ENTER();
62 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
63 EX_FUNC_LEAVE(EX_FATAL);
64 }
65
66 #if !defined(PARALLEL_AWARE_EXODUS)
67 if (num_ent == 0) {
68 EX_FUNC_LEAVE(EX_NOERR);
69 }
70 #endif
71
72 /* Determine index of obj_id in vobjids array */
73 if (obj_type != EX_NODAL) {
74 obj_id_ndx = exi_id_lkup(exoid, obj_type, obj_id);
75 if (obj_id_ndx <= 0) {
76 ex_get_err(NULL, NULL, &status);
77
78 if (status != 0) {
79 if (status == EX_NULLENTITY) {
80 snprintf(errmsg, MAX_ERR_LENGTH,
81 "Warning: no attributes found for NULL %s %" PRId64 " in file id %d",
82 ex_name_of_object(obj_type), obj_id, exoid);
83 ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY);
84 EX_FUNC_LEAVE(EX_WARN); /* no attributes for this object */
85 }
86 snprintf(errmsg, MAX_ERR_LENGTH,
87 "Warning: failed to locate %s id%" PRId64 " in id array in file id %d",
88 ex_name_of_object(obj_type), obj_id, exoid);
89 ex_err_fn(exoid, __func__, errmsg, status);
90 EX_FUNC_LEAVE(EX_WARN);
91 }
92 }
93 }
94
95 switch (obj_type) {
96 case EX_SIDE_SET:
97 dnumobjent = DIM_NUM_SIDE_SS(obj_id_ndx);
98 dnumobjatt = DIM_NUM_ATT_IN_SS(obj_id_ndx);
99 vattrbname = VAR_SSATTRIB(obj_id_ndx);
100 break;
101 case EX_NODE_SET:
102 dnumobjent = DIM_NUM_NOD_NS(obj_id_ndx);
103 dnumobjatt = DIM_NUM_ATT_IN_NS(obj_id_ndx);
104 vattrbname = VAR_NSATTRIB(obj_id_ndx);
105 break;
106 case EX_EDGE_SET:
107 dnumobjent = DIM_NUM_EDGE_ES(obj_id_ndx);
108 dnumobjatt = DIM_NUM_ATT_IN_ES(obj_id_ndx);
109 vattrbname = VAR_ESATTRIB(obj_id_ndx);
110 break;
111 case EX_FACE_SET:
112 dnumobjent = DIM_NUM_FACE_FS(obj_id_ndx);
113 dnumobjatt = DIM_NUM_ATT_IN_FS(obj_id_ndx);
114 vattrbname = VAR_FSATTRIB(obj_id_ndx);
115 break;
116 case EX_ELEM_SET:
117 dnumobjent = DIM_NUM_ELE_ELS(obj_id_ndx);
118 dnumobjatt = DIM_NUM_ATT_IN_ELS(obj_id_ndx);
119 vattrbname = VAR_ELSATTRIB(obj_id_ndx);
120 break;
121 case EX_NODAL:
122 dnumobjent = DIM_NUM_NODES;
123 dnumobjatt = DIM_NUM_ATT_IN_NBLK;
124 vattrbname = VAR_NATTRIB;
125 break;
126 case EX_EDGE_BLOCK:
127 dnumobjent = DIM_NUM_ED_IN_EBLK(obj_id_ndx);
128 dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx);
129 vattrbname = VAR_EATTRIB(obj_id_ndx);
130 break;
131 case EX_FACE_BLOCK:
132 dnumobjent = DIM_NUM_FA_IN_FBLK(obj_id_ndx);
133 dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx);
134 vattrbname = VAR_FATTRIB(obj_id_ndx);
135 break;
136 case EX_ELEM_BLOCK:
137 dnumobjent = DIM_NUM_EL_IN_BLK(obj_id_ndx);
138 dnumobjatt = DIM_NUM_ATT_IN_BLK(obj_id_ndx);
139 vattrbname = VAR_ATTRIB(obj_id_ndx);
140 break;
141 default:
142 snprintf(errmsg, MAX_ERR_LENGTH,
143 "Internal ERROR: unrecognized object type in switch: %d in file id %d", obj_type,
144 exoid);
145 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
146 EX_FUNC_LEAVE(EX_FATAL); /* number of attributes not defined */
147 }
148
149 /* inquire id's of previously defined dimensions */
150 if (exi_get_dimension(exoid, dnumobjent, "entries", &num_entries_this_obj, &temp, __func__) !=
151 NC_NOERR) {
152 EX_FUNC_LEAVE(EX_FATAL);
153 }
154
155 if (start_num + num_ent - 1 > (int64_t)num_entries_this_obj && num_ent > 0) {
156 snprintf(errmsg, MAX_ERR_LENGTH,
157 "ERROR: start index (%" PRId64 ") + count (%" PRId64
158 ") is larger than total number of entities (%zu) in file id %d",
159 start_num, num_ent, num_entries_this_obj, exoid);
160 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
161 EX_FUNC_LEAVE(EX_FATAL);
162 }
163
164 if (exi_get_dimension(exoid, dnumobjatt, "attributes", &num_attr, &temp, __func__) != NC_NOERR) {
165 EX_FUNC_LEAVE(EX_FATAL);
166 }
167
168 if (attrib_index < 1 || attrib_index > (int)num_attr) {
169 snprintf(errmsg, MAX_ERR_LENGTH,
170 "ERROR: Invalid attribute index specified: %d. Valid "
171 "range is 1 to %d for %s %" PRId64 " in file id %d",
172 attrib_index, (int)num_attr, ex_name_of_object(obj_type), obj_id, exoid);
173 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
174 EX_FUNC_LEAVE(EX_FATAL);
175 }
176
177 if ((status = nc_inq_varid(exoid, vattrbname, &attrid)) != NC_NOERR) {
178 snprintf(errmsg, MAX_ERR_LENGTH,
179 "ERROR: failed to locate attributes for %s %" PRId64 " in file id %d",
180 ex_name_of_object(obj_type), obj_id, exoid);
181 ex_err_fn(exoid, __func__, errmsg, status);
182 EX_FUNC_LEAVE(EX_FATAL);
183 }
184
185 /* read in the attributes */
186 start[0] = start_num - 1;
187 start[1] = attrib_index - 1;
188
189 count[0] = num_ent;
190 count[1] = 1;
191
192 stride[0] = 1;
193 stride[1] = num_attr;
194
195 if (count[0] == 0) {
196 start[0] = 0;
197 }
198 if (exi_comp_ws(exoid) == 4) {
199 status = nc_get_vars_float(exoid, attrid, start, count, stride, attrib);
200 }
201 else {
202 status = nc_get_vars_double(exoid, attrid, start, count, stride, attrib);
203 }
204
205 if (status != NC_NOERR) {
206 snprintf(errmsg, MAX_ERR_LENGTH,
207 "ERROR: failed to get attribute %d for %s %" PRId64 " in file id %d", attrib_index,
208 ex_name_of_object(obj_type), obj_id, exoid);
209 ex_err_fn(exoid, __func__, errmsg, status);
210 EX_FUNC_LEAVE(EX_FATAL);
211 }
212 EX_FUNC_LEAVE(EX_NOERR);
213 }