1 /*
2 * Copyright (c) 2005 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 *
38 * expfrm - ex_put_coordinate_frames: write coordinate frames
39 *
40 * \param exoid exodus file id
41 * \param nframes number of coordinate frames in model
42 * \param cf_ids coordinate ids
43 * \param pt_coordinates pointer to coordinates. 9 values per coordinate frame
44 * \param tags character tag for each frame. 'r' - rectangular, 'c' - cylindrical, 's' - spherical
45 *
46 * returns -
47 * EX_NOERR for no error
48 * EX_FATAL for fatal errors
49 * 1 number frames < 0
50 *
51 *****************************************************************************/
52
53 #include <assert.h>
54 #include <string.h>
55 #include "exodusII.h"
56 #include "exodusII_int.h"
57
58 /* -------------------- local defines --------------------------- */
59 #define PROCNAME "ex_put_coordinate_frames"
60 /* -------------------- end of local defines -------------------- */
ex_put_coordinate_frames(int exoid,int nframes,const void_int * cf_ids,void * pt_coordinates,const char * tags)61 int ex_put_coordinate_frames( int exoid,
62 int nframes,
63 const void_int *cf_ids,
64 void* pt_coordinates,
65 const char* tags)
66 {
67 int status;
68 int dim, dim9; /* dimension id for nframes, nframes*9 */
69 char errmsg[MAX_ERR_LENGTH]; /* buffer for error messages */
70 int varcoords; /* variable id for the coordinates */
71 int varids; /* variable id for the frame ids */
72 int vartags; /* variable id for the frame tags */
73 int i; /* general indices */
74 int int_type;
75
76 if ( exoid < 0 )
77 return exoid;
78
79 if ( nframes == 0 ) /* write nothing */
80 return (EX_NOERR);
81
82 if ( nframes<0 )
83 return 1;
84
85 assert( cf_ids!=0 );
86 assert( pt_coordinates !=0 );
87 assert( tags != 0 );
88
89 /* make the definitions */
90 /* go into define mode. define num_frames, num_frames9 */
91 if ((status = nc_redef (exoid)) != NC_NOERR) {
92 exerrval = status;
93 sprintf(errmsg,"Error: failed to place file id %d into define mode",
94 exoid);
95 ex_err(PROCNAME,errmsg,exerrval);
96 return (EX_FATAL);
97 }
98
99 if ((status = nc_def_dim(exoid, DIM_NUM_CFRAMES, nframes, &dim)) != NC_NOERR ||
100 (nc_def_dim(exoid, DIM_NUM_CFRAME9, nframes*9, &dim9) != NC_NOERR)) {
101 exerrval = status;
102 sprintf(errmsg,
103 "Error: failed to define number of coordinate frames in file id %d",
104 exoid);
105 ex_err(PROCNAME,errmsg,exerrval);
106 goto error_ret;
107 }
108
109 int_type = NC_INT;
110 if (ex_int64_status(exoid) & EX_IDS_INT64_DB) {
111 int_type = NC_INT64;
112 }
113
114 /* define the variables. coordinates, tags and ids */
115 if (nc_def_var (exoid, VAR_FRAME_COORDS,
116 nc_flt_code(exoid), 1, &dim9, &varcoords) != NC_NOERR ||
117 (nc_def_var(exoid, VAR_FRAME_IDS,int_type, 1, &dim, &varids) != NC_NOERR) ||
118 (nc_def_var(exoid, VAR_FRAME_TAGS,NC_CHAR,1,&dim, &vartags) != NC_NOERR) ) {
119 exerrval = EX_FATAL;
120 sprintf(errmsg,
121 "Error: failed to define coordinate frames in file id %d",
122 exoid);
123 ex_err(PROCNAME,errmsg,exerrval);
124 goto error_ret; /* exit define mode and return */
125 }
126
127 /* leave define mode */
128 if ((status = nc_enddef (exoid)) != NC_NOERR) {
129 exerrval = status;
130 sprintf(errmsg,
131 "Error: failed to complete coordinate frame definition in file id %d",
132 exoid);
133 ex_err(PROCNAME,errmsg,exerrval);
134 return (EX_FATAL);
135 }
136
137 /* check variables consistency */
138 exerrval = EX_NOERR;
139 for (i=0;i<nframes;i++)
140 if ( strchr("RrCcSs",tags[i])==0 ){
141 sprintf(errmsg,"Warning: Unrecognized coordinate frame tag: '%c'.",
142 tags[i]);
143 exerrval=2;
144 ex_err(PROCNAME,errmsg,exerrval);
145 }
146 /* could also check vectors. Leave this up to the application */
147
148 /* put the variables into the file */
149 if (nc_put_var_text(exoid, vartags, tags) != NC_NOERR) {
150 exerrval = status;
151 sprintf(errmsg,
152 "Error: failed writing frame data in file id %d",exoid);
153 ex_err(PROCNAME,errmsg,exerrval);
154 return (EX_FATAL);
155 }
156
157 if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
158 status = nc_put_var_longlong(exoid, varids, cf_ids);
159 } else {
160 status = nc_put_var_int(exoid, varids, cf_ids);
161 }
162
163 if (status != NC_NOERR) {
164 exerrval = status;
165 sprintf(errmsg,
166 "Error: failed writing frame data in file id %d",exoid);
167 ex_err(PROCNAME,errmsg,exerrval);
168 return (EX_FATAL);
169 }
170
171 if (ex_comp_ws(exoid) == 4) {
172 status = nc_put_var_float(exoid, varcoords, pt_coordinates);
173 } else {
174 status = nc_put_var_double(exoid, varcoords, pt_coordinates);
175 }
176
177 if (status != NC_NOERR) {
178 exerrval = status;
179 sprintf(errmsg,
180 "Error: failed writing frame data in file id %d",exoid);
181 ex_err(PROCNAME,errmsg,exerrval);
182 return (EX_FATAL);
183 }
184 return (EX_NOERR);
185
186 error_ret:
187 if (nc_enddef (exoid) != NC_NOERR) { /* exit define mode */
188 sprintf(errmsg,
189 "Error: failed to complete frame definition for file id %d",
190 exoid);
191 ex_err(PROCNAME,errmsg,exerrval);
192 }
193 return (EX_FATAL);
194
195
196 }
197
198
199