1 /*
2 * Copyright (c) 2006 Sandia Corporation. Under the terms of Contract
3 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Governement
4 * retains certain rights in this software.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 *
18 * * Neither the name of Sandia Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
35 /*****************************************************************************
36 *
37 * exgeat - ex_get_attr_names
38 *
39 * entry conditions -
40 * input parameters:
41 * int exoid exodus file id
42 * int obj_type object type (edge/face/elem block)
43 * int obj_id object id (edge/face/elem block id)
44 *
45 * exit conditions -
46 * char* names[] ptr array of attribute names
47 *
48 * revision history -
49 *
50 *
51 *****************************************************************************/
52
53 #include "exodusII.h"
54 #include "exodusII_int.h"
55
56 /*! \undoc */
57 /*
58 * reads the attribute names for an element block
59 */
ex_get_attr_names(int exoid,ex_entity_type obj_type,int obj_id,char ** names)60 int ex_get_attr_names( int exoid,
61 ex_entity_type obj_type,
62 int obj_id,
63 char **names)
64 {
65 int status;
66 int varid, numattrdim, obj_id_ndx;
67 size_t num_attr, start[2], count[2], i;
68 char errmsg[MAX_ERR_LENGTH];
69 const char* dnumobjatt;
70 const char* vattrbname;
71
72 exerrval = 0; /* clear error code */
73
74 /* Determine index of obj_id in vobjids array */
75 if (obj_type != EX_NODAL) {
76 obj_id_ndx = ex_id_lkup(exoid,obj_type,obj_id);
77 if (exerrval != 0) {
78 if (exerrval == EX_NULLENTITY) {
79 sprintf(errmsg,
80 "Warning: no attributes found for NULL %s %d in file id %d",
81 ex_name_of_object(obj_type), obj_id, exoid);
82 ex_err("ex_get_attr_names",errmsg,EX_MSG);
83 return (EX_WARN); /* no attributes for this object */
84 } else {
85 sprintf(errmsg,
86 "Warning: failed to locate %s id %d in id array in file id %d",
87 ex_name_of_object(obj_type), obj_id, exoid);
88 ex_err("ex_get_attr_names",errmsg,exerrval);
89 return (EX_WARN);
90 }
91 }
92 }
93
94 switch (obj_type) {
95 case EX_NODE_SET:
96 dnumobjatt = DIM_NUM_ATT_IN_NS(obj_id_ndx);
97 vattrbname = VAR_NAME_NSATTRIB(obj_id_ndx);
98 break;
99 case EX_SIDE_SET:
100 dnumobjatt = DIM_NUM_ATT_IN_SS(obj_id_ndx);
101 vattrbname = VAR_NAME_SSATTRIB(obj_id_ndx);
102 break;
103 case EX_EDGE_SET:
104 dnumobjatt = DIM_NUM_ATT_IN_ES(obj_id_ndx);
105 vattrbname = VAR_NAME_ESATTRIB(obj_id_ndx);
106 break;
107 case EX_FACE_SET:
108 dnumobjatt = DIM_NUM_ATT_IN_FS(obj_id_ndx);
109 vattrbname = VAR_NAME_FSATTRIB(obj_id_ndx);
110 break;
111 case EX_ELEM_SET:
112 dnumobjatt = DIM_NUM_ATT_IN_ELS(obj_id_ndx);
113 vattrbname = VAR_NAME_ELSATTRIB(obj_id_ndx);
114 break;
115 case EX_NODAL:
116 dnumobjatt = DIM_NUM_ATT_IN_NBLK;
117 vattrbname = VAR_NAME_NATTRIB;
118 break;
119 case EX_EDGE_BLOCK:
120 dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx);
121 vattrbname = VAR_NAME_EATTRIB(obj_id_ndx);
122 break;
123 case EX_FACE_BLOCK:
124 dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx);
125 vattrbname = VAR_NAME_FATTRIB(obj_id_ndx);
126 break;
127 case EX_ELEM_BLOCK:
128 dnumobjatt = DIM_NUM_ATT_IN_BLK(obj_id_ndx);
129 vattrbname = VAR_NAME_ATTRIB(obj_id_ndx);
130 break;
131 default:
132 exerrval = 1005;
133 sprintf(errmsg,
134 "Internal Error: unrecognized object type in switch: %d in file id %d",
135 obj_type,exoid);
136 ex_err("ex_get_attr_names",errmsg,EX_MSG);
137 return (EX_FATAL); /* number of attributes not defined */
138 }
139 /* inquire id's of previously defined dimensions */
140
141 if ((status = nc_inq_dimid(exoid, dnumobjatt, &numattrdim)) != NC_NOERR) {
142 exerrval = status;
143 sprintf(errmsg,
144 "Warning: no attributes found for %s %d in file id %d",
145 ex_name_of_object(obj_type),obj_id,exoid);
146 ex_err("ex_get_attr_names",errmsg,EX_MSG);
147 return (EX_WARN); /* no attributes for this object */
148 }
149
150 if ((status = nc_inq_dimlen(exoid, numattrdim, &num_attr)) != NC_NOERR) {
151 exerrval = status;
152 sprintf(errmsg,
153 "Error: failed to get number of attributes for %s %d in file id %d",
154 ex_name_of_object(obj_type),obj_id,exoid);
155 ex_err("ex_get_attr_names",errmsg,exerrval);
156 return (EX_FATAL);
157 }
158
159 /* It is OK if we don't find the attribute names since they were
160 added at version 4.26; earlier databases won't have the names.
161 */
162 status = nc_inq_varid(exoid, vattrbname, &varid);
163
164 /* read in the attributes */
165
166 if (status == NC_NOERR) {
167 /* read the names */
168 status = ex_get_names_internal(exoid, varid, num_attr, names, obj_type, "ex_get_attr_names");
169 if (status != NC_NOERR) {
170 return (EX_FATAL);
171 }
172 } else {
173 /* Names variable does not exist on the database; probably since this is an
174 * older version of the database. Return an empty array...
175 */
176 for (i=0; i<num_attr; i++) {
177 names[i][0] = '\0';
178 }
179 }
180 return(EX_NOERR);
181 }
182