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 * expatt - ex_put_attr
38 *
39 * entry conditions -
40 * input parameters:
41 * int exoid exodus file id
42 * int blk_type block type
43 * int blk_id block id
44 * float* attrib array of attributes
45 *
46 * exit conditions -
47 *
48 * revision history -
49 *
50 *
51 *****************************************************************************/
52
53 #include "exodusII.h"
54 #include "exodusII_int.h"
55
56 /*!
57 * writes the attributes for an edge/face/element block
58 * \param exoid exodus file id
59 * \param blk_type block type
60 * \param blk_id block id
61 * \param attrib array of attributes
62 */
63
ex_put_attr(int exoid,ex_entity_type blk_type,int blk_id,const void * attrib)64 int ex_put_attr (int exoid,
65 ex_entity_type blk_type,
66 int blk_id,
67 const void *attrib)
68 {
69 int status;
70 int attrid, blk_id_ndx;
71 char errmsg[MAX_ERR_LENGTH];
72
73 exerrval = 0; /* clear error code */
74
75 if ( blk_type != EX_NODAL ) {
76 /* Determine index of blk_id in VAR_ID_EL_BLK array */
77 blk_id_ndx = ex_id_lkup(exoid,blk_type,blk_id);
78 if (exerrval != 0) {
79 if (exerrval == EX_NULLENTITY) {
80 sprintf(errmsg,
81 "Warning: no attributes allowed for NULL %s %d in file id %d",
82 ex_name_of_object(blk_type),blk_id,exoid);
83 ex_err("ex_put_attr",errmsg,EX_MSG);
84 return (EX_WARN); /* no attributes for this block */
85 } else {
86 sprintf(errmsg,
87 "Error: no %s id %d in in file id %d",
88 ex_name_of_object(blk_type), blk_id, exoid);
89 ex_err("ex_put_attr",errmsg,exerrval);
90 return (EX_FATAL);
91 }
92 }
93 }
94
95 switch (blk_type) {
96 case EX_SIDE_SET:
97 status = nc_inq_varid (exoid, VAR_SSATTRIB(blk_id_ndx), &attrid);
98 break;
99 case EX_NODE_SET:
100 status = nc_inq_varid (exoid, VAR_NSATTRIB(blk_id_ndx), &attrid);
101 break;
102 case EX_EDGE_SET:
103 status = nc_inq_varid (exoid, VAR_ESATTRIB(blk_id_ndx), &attrid);
104 break;
105 case EX_FACE_SET:
106 status = nc_inq_varid (exoid, VAR_FSATTRIB(blk_id_ndx), &attrid);
107 break;
108 case EX_ELEM_SET:
109 status = nc_inq_varid (exoid, VAR_ELSATTRIB(blk_id_ndx), &attrid);
110 break;
111 case EX_NODAL:
112 status = nc_inq_varid (exoid, VAR_NATTRIB, &attrid);
113 break;
114 case EX_EDGE_BLOCK:
115 status = nc_inq_varid (exoid, VAR_EATTRIB(blk_id_ndx), &attrid);
116 break;
117 case EX_FACE_BLOCK:
118 status = nc_inq_varid (exoid, VAR_FATTRIB(blk_id_ndx), &attrid);
119 break;
120 case EX_ELEM_BLOCK:
121 status = nc_inq_varid (exoid, VAR_ATTRIB(blk_id_ndx), &attrid);
122 break;
123 default:
124 exerrval = 1005;
125 sprintf(errmsg,
126 "Internal Error: unrecognized object type in switch: %d in file id %d",
127 blk_type,exoid);
128 ex_err("ex_put_attr",errmsg,EX_MSG);
129 return (EX_FATAL); /* number of attributes not defined */
130 }
131
132 if (status != NC_NOERR) {
133 exerrval = status;
134 sprintf(errmsg,
135 "Error: failed to locate attribute variable for %s %d in file id %d",
136 ex_name_of_object(blk_type),blk_id,exoid);
137 ex_err("ex_put_attr",errmsg,exerrval);
138 return (EX_FATAL);
139 }
140
141 /* write out the attributes */
142 if (ex_comp_ws(exoid) == 4) {
143 status = nc_put_var_float(exoid, attrid, attrib);
144 } else {
145 status = nc_put_var_double(exoid, attrid, attrib);
146 }
147
148 if (status != NC_NOERR) {
149 exerrval = status;
150 sprintf(errmsg,
151 "Error: failed to put attributes for %s %d in file id %d",
152 ex_name_of_object(blk_type),blk_id,exoid);
153 ex_err("ex_put_attr",errmsg,exerrval);
154 return (EX_FATAL);
155 }
156 return(EX_NOERR);
157 }
158