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 * expatn - ex_put_attr_names
38 *
39 * entry conditions -
40 * input parameters:
41 * int exoid exodus file id
42 * int blk_type block type (edge, face, elem)
43 * int blk_id block id
44 * char* names ptr to array of attribute names
45
46 *
47 * exit conditions -
48 *
49 * revision history -
50 *
51 *
52 *****************************************************************************/
53
54 #include "exodusII.h"
55 #include "exodusII_int.h"
56 #include <string.h>
57
58 /*!
59 * writes the attribute names for a block
60 * \param exoid exodus file id
61 * \param blk_type block type (edge, face, elem)
62 * \param blk_id block id
63 * \param names ptr to array of attribute names
64 */
ex_put_attr_names(int exoid,ex_entity_type blk_type,int blk_id,char * names[])65 int ex_put_attr_names(int exoid,
66 ex_entity_type blk_type,
67 int blk_id,
68 char* names[])
69 {
70 int varid, numattrdim, blk_id_ndx;
71 size_t num_attr;
72
73 int status;
74 char errmsg[MAX_ERR_LENGTH];
75
76 exerrval = 0; /* clear error code */
77
78 blk_id_ndx = ex_id_lkup(exoid, blk_type, blk_id);
79
80 /* Determine index of blk_id in blk_id_ndx array */
81 if (exerrval != 0) {
82 if (exerrval == EX_NULLENTITY) {
83 sprintf(errmsg,
84 "Warning: no attributes allowed for NULL %s %d in file id %d",
85 ex_name_of_object(blk_type),blk_id,exoid);
86 ex_err("ex_put_attr_names",errmsg,EX_MSG);
87 return (EX_WARN); /* no attributes for this block */
88 } else {
89 sprintf(errmsg,
90 "Error: no %s id %d in %s array in file id %d",
91 ex_name_of_object(blk_type), blk_id, VAR_ID_EL_BLK, exoid);
92 ex_err("ex_put_attr_names",errmsg,exerrval);
93 return (EX_FATAL);
94 }
95 }
96
97 /* inquire id's of previously defined dimensions */
98 switch (blk_type) {
99 case EX_SIDE_SET:
100 status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_SS(blk_id_ndx), &numattrdim);
101 break;
102 case EX_NODE_SET:
103 status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_NS(blk_id_ndx), &numattrdim);
104 break;
105 case EX_EDGE_SET:
106 status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_ES(blk_id_ndx), &numattrdim);
107 break;
108 case EX_FACE_SET:
109 status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_FS(blk_id_ndx), &numattrdim);
110 break;
111 case EX_ELEM_SET:
112 status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_ELS(blk_id_ndx), &numattrdim);
113 break;
114 case EX_NODAL:
115 status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_NBLK, &numattrdim);
116 break;
117 case EX_EDGE_BLOCK:
118 status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_EBLK(blk_id_ndx), &numattrdim);
119 break;
120 case EX_FACE_BLOCK:
121 status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_FBLK(blk_id_ndx), &numattrdim);
122 break;
123 case EX_ELEM_BLOCK:
124 status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_BLK(blk_id_ndx), &numattrdim);
125 break;
126 default:
127 exerrval = 1005;
128 sprintf(errmsg,
129 "Internal Error: unrecognized object type in switch: %d in file id %d",
130 blk_type,exoid);
131 ex_err("ex_put_attr_names",errmsg,EX_MSG);
132 return (EX_FATAL); /* number of attributes not defined */
133 }
134
135 if (status != NC_NOERR) {
136 exerrval = status;
137 sprintf(errmsg,
138 "Error: number of attributes not defined for %s %d in file id %d",
139 ex_name_of_object(blk_type),blk_id,exoid);
140 ex_err("ex_put_attr_names",errmsg,EX_MSG);
141 return (EX_FATAL); /* number of attributes not defined */
142 }
143
144 if ((status = nc_inq_dimlen(exoid, numattrdim, &num_attr)) != NC_NOERR) {
145 exerrval = status;
146 sprintf(errmsg,
147 "Error: failed to get number of attributes for %s %d in file id %d",
148 ex_name_of_object(blk_type),blk_id,exoid);
149 ex_err("ex_put_attr_names",errmsg,exerrval);
150 return (EX_FATAL);
151 }
152
153 switch (blk_type) {
154 case EX_SIDE_SET:
155 status = nc_inq_varid (exoid, VAR_NAME_SSATTRIB(blk_id_ndx), &varid);
156 break;
157 case EX_NODE_SET:
158 status = nc_inq_varid (exoid, VAR_NAME_NSATTRIB(blk_id_ndx), &varid);
159 break;
160 case EX_EDGE_SET:
161 status = nc_inq_varid (exoid, VAR_NAME_ESATTRIB(blk_id_ndx), &varid);
162 break;
163 case EX_FACE_SET:
164 status = nc_inq_varid (exoid, VAR_NAME_FSATTRIB(blk_id_ndx), &varid);
165 break;
166 case EX_ELEM_SET:
167 status = nc_inq_varid (exoid, VAR_NAME_ELSATTRIB(blk_id_ndx), &varid);
168 break;
169 case EX_NODAL:
170 status = nc_inq_varid (exoid, VAR_NAME_NATTRIB, &varid);
171 break;
172 case EX_EDGE_BLOCK:
173 status = nc_inq_varid (exoid, VAR_NAME_EATTRIB(blk_id_ndx), &varid);
174 break;
175 case EX_FACE_BLOCK:
176 status = nc_inq_varid (exoid, VAR_NAME_FATTRIB(blk_id_ndx), &varid);
177 break;
178 case EX_ELEM_BLOCK:
179 status = nc_inq_varid (exoid, VAR_NAME_ATTRIB(blk_id_ndx), &varid);
180 break;
181 default:
182 exerrval = 1005;
183 sprintf(errmsg,
184 "Internal Error: unrecognized object type in switch: %d in file id %d",
185 blk_type,exoid);
186 ex_err("ex_put_attr_names",errmsg,EX_MSG);
187 return (EX_FATAL); /* number of attributes not defined */
188 }
189
190 if (status != NC_NOERR) {
191 exerrval = status;
192 sprintf(errmsg,
193 "Error: failed to locate %s attribute names for %s %d in file id %d",
194 ex_name_of_object(blk_type),ex_name_of_object(blk_type),blk_id, exoid);
195 ex_err("ex_put_attr_names",errmsg,exerrval);
196 return (EX_FATAL);
197 }
198
199 /* write out the attributes */
200 status = ex_put_names_internal(exoid, varid, num_attr, names, blk_type,
201 "attribute", "ex_put_attr_names");
202
203 return(status);
204 }
205