Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_get_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 * exgatt - ex_get_attr
11 *
12 * entry conditions -
13 * input parameters:
14 * int exoid exodus file id
15 * int obj_type object type (edge/face/element block)
16 * int obj_id object id (edge id, face id, elem 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, EX_WARN, etc
28
29 /*!
30 * \undoc reads the attributes for an edge, face, or element block
31 */
32
33 int ex_get_attr(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, void *attrib)
34
35 {
36 int status;
37 int attrid, obj_id_ndx;
38 char errmsg[MAX_ERR_LENGTH];
39 const char *vattrbname;
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 /* Determine index of obj_id in vobjids array */
47 if (obj_type == EX_NODAL) {
48 obj_id_ndx = 0;
49 }
50 else {
51 obj_id_ndx = exi_id_lkup(exoid, obj_type, obj_id);
52 if (obj_id_ndx <= 0) {
53 ex_get_err(NULL, NULL, &status);
54
55 if (status != 0) {
56 if (status == EX_NULLENTITY) {
57 snprintf(errmsg, MAX_ERR_LENGTH,
58 "Warning: no attributes found for NULL %s %" PRId64 " in file id %d",
59 ex_name_of_object(obj_type), obj_id, exoid);
60 ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY);
61 EX_FUNC_LEAVE(EX_WARN); /* no attributes for this object */
62 }
63 snprintf(errmsg, MAX_ERR_LENGTH,
64 "Warning: failed to locate %s id %" PRId64 " in id array in file id %d",
65 ex_name_of_object(obj_type), obj_id, exoid);
66 ex_err_fn(exoid, __func__, errmsg, status);
67 EX_FUNC_LEAVE(EX_WARN);
68 }
69 }
70 }
71
72 switch (obj_type) {
73 case EX_SIDE_SET: vattrbname = VAR_SSATTRIB(obj_id_ndx); break;
74 case EX_NODE_SET: vattrbname = VAR_NSATTRIB(obj_id_ndx); break;
75 case EX_EDGE_SET: vattrbname = VAR_ESATTRIB(obj_id_ndx); break;
76 case EX_FACE_SET: vattrbname = VAR_FSATTRIB(obj_id_ndx); break;
77 case EX_ELEM_SET: vattrbname = VAR_ELSATTRIB(obj_id_ndx); break;
78 case EX_NODAL: vattrbname = VAR_NATTRIB; break;
79 case EX_EDGE_BLOCK: vattrbname = VAR_EATTRIB(obj_id_ndx); break;
80 case EX_FACE_BLOCK: vattrbname = VAR_FATTRIB(obj_id_ndx); break;
81 case EX_ELEM_BLOCK: vattrbname = VAR_ATTRIB(obj_id_ndx); break;
82 default:
83 snprintf(errmsg, MAX_ERR_LENGTH,
84 "Internal ERROR: unrecognized object type in switch: %d in file id %d", obj_type,
85 exoid);
86 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
87 EX_FUNC_LEAVE(EX_FATAL); /* number of attributes not defined */
88 }
89
90 /* inquire id's of previously defined dimensions */
91 if ((status = nc_inq_varid(exoid, vattrbname, &attrid)) != NC_NOERR) {
92 snprintf(errmsg, MAX_ERR_LENGTH,
93 "ERROR: failed to locate attributes for %s %" PRId64 " in file id %d",
94 ex_name_of_object(obj_type), obj_id, exoid);
95 ex_err_fn(exoid, __func__, errmsg, status);
96 EX_FUNC_LEAVE(EX_FATAL);
97 }
98
99 /* read in the attributes */
100 if (exi_comp_ws(exoid) == 4) {
101 status = nc_get_var_float(exoid, attrid, attrib);
102 }
103 else {
104 status = nc_get_var_double(exoid, attrid, attrib);
105 }
106
107 if (status != NC_NOERR) {
108 snprintf(errmsg, MAX_ERR_LENGTH,
109 "ERROR: failed to get attributes for %s %" PRId64 " in file id %d",
110 ex_name_of_object(obj_type), obj_id, exoid);
111 ex_err_fn(exoid, __func__, errmsg, status);
112 EX_FUNC_LEAVE(EX_FATAL);
113 }
114 EX_FUNC_LEAVE(EX_NOERR);
115 }