Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-2022 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_attr_names
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 * char* names[] ptr array of attribute names
20 *
21 * revision history -
22 *
23 *
24 *****************************************************************************/
25
26 #include "exodusII.h" // for ex_err, ex_name_of_object, etc
27 #include "exodusII_int.h" // for EX_FATAL, EX_WARN, etc
28
29 /*! \undoc */
30 /*
31 * reads the attribute names for an element block
32 */
33 int ex_get_attr_names(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, char **names)
34 {
35 int status;
36 int varid, numattrdim, obj_id_ndx;
37 char errmsg[MAX_ERR_LENGTH];
38 const char *dnumobjatt;
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 = exi_id_lkup(exoid, obj_type, obj_id);
49 if (obj_id_ndx <= 0) {
50 ex_get_err(NULL, NULL, &status);
51
52 if (status != 0) {
53 if (status == EX_NULLENTITY) {
54 snprintf(errmsg, MAX_ERR_LENGTH,
55 "Warning: no attributes found for NULL %s %" PRId64 " in file id %d",
56 ex_name_of_object(obj_type), obj_id, exoid);
57 ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY);
58 EX_FUNC_LEAVE(EX_WARN); /* no attributes for this object */
59 }
60 snprintf(errmsg, MAX_ERR_LENGTH,
61 "Warning: failed to locate %s id %" PRId64 " in id array in file id %d",
62 ex_name_of_object(obj_type), obj_id, exoid);
63 ex_err_fn(exoid, __func__, errmsg, status);
64 EX_FUNC_LEAVE(EX_WARN);
65 }
66 }
67 }
68
69 switch (obj_type) {
70 case EX_NODE_SET:
71 dnumobjatt = DIM_NUM_ATT_IN_NS(obj_id_ndx);
72 vattrbname = VAR_NAME_NSATTRIB(obj_id_ndx);
73 break;
74 case EX_SIDE_SET:
75 dnumobjatt = DIM_NUM_ATT_IN_SS(obj_id_ndx);
76 vattrbname = VAR_NAME_SSATTRIB(obj_id_ndx);
77 break;
78 case EX_EDGE_SET:
79 dnumobjatt = DIM_NUM_ATT_IN_ES(obj_id_ndx);
80 vattrbname = VAR_NAME_ESATTRIB(obj_id_ndx);
81 break;
82 case EX_FACE_SET:
83 dnumobjatt = DIM_NUM_ATT_IN_FS(obj_id_ndx);
84 vattrbname = VAR_NAME_FSATTRIB(obj_id_ndx);
85 break;
86 case EX_ELEM_SET:
87 dnumobjatt = DIM_NUM_ATT_IN_ELS(obj_id_ndx);
88 vattrbname = VAR_NAME_ELSATTRIB(obj_id_ndx);
89 break;
90 case EX_NODAL:
91 dnumobjatt = DIM_NUM_ATT_IN_NBLK;
92 vattrbname = VAR_NAME_NATTRIB;
93 break;
94 case EX_EDGE_BLOCK:
95 dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx);
96 vattrbname = VAR_NAME_EATTRIB(obj_id_ndx);
97 break;
98 case EX_FACE_BLOCK:
99 dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx);
100 vattrbname = VAR_NAME_FATTRIB(obj_id_ndx);
101 break;
102 case EX_ELEM_BLOCK:
103 dnumobjatt = DIM_NUM_ATT_IN_BLK(obj_id_ndx);
104 vattrbname = VAR_NAME_ATTRIB(obj_id_ndx);
105 break;
106 default:
107 snprintf(errmsg, MAX_ERR_LENGTH,
108 "Internal ERROR: unrecognized object type in switch: %d in file id %d", obj_type,
109 exoid);
110 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
111 EX_FUNC_LEAVE(EX_FATAL); /* number of attributes not defined */
112 }
113 /* inquire id's of previously defined dimensions */
114
115 if ((status = nc_inq_dimid(exoid, dnumobjatt, &numattrdim)) != NC_NOERR) {
116 snprintf(errmsg, MAX_ERR_LENGTH,
117 "Warning: no attributes found for %s %" PRId64 " in file id %d",
118 ex_name_of_object(obj_type), obj_id, exoid);
119 ex_err_fn(exoid, __func__, errmsg, status);
120 EX_FUNC_LEAVE(EX_WARN); /* no attributes for this object */
121 }
122
123 size_t num_attr = 0;
124 if ((status = nc_inq_dimlen(exoid, numattrdim, &num_attr)) != NC_NOERR) {
125 snprintf(errmsg, MAX_ERR_LENGTH,
126 "ERROR: failed to get number of attributes for %s %" PRId64 " in file id %d",
127 ex_name_of_object(obj_type), obj_id, exoid);
128 ex_err_fn(exoid, __func__, errmsg, status);
129 EX_FUNC_LEAVE(EX_FATAL);
130 }
131
132 /* It is OK if we don't find the attribute names since they were
133 added at version 4.26; earlier databases won't have the names.
134 */
135 status = nc_inq_varid(exoid, vattrbname, &varid);
136
137 /* read in the attributes */
138
139 if (status == NC_NOERR) {
140 /* read the names */
141 status = exi_get_names(exoid, varid, num_attr, names, obj_type, __func__);
142 if (status != NC_NOERR) {
143 EX_FUNC_LEAVE(EX_FATAL);
144 }
145 }
146 else {
147 /* Names variable does not exist on the database; probably since this is an
148 * older version of the database. Return an empty array...
149 */
150 for (size_t i = 0; i < num_attr; i++) {
151 names[i][0] = '\0';
152 }
153 }
154 EX_FUNC_LEAVE(EX_NOERR);
155 }