Debian Codegraph @

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