1 /**
2 * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3 * storing and accessing finite element mesh data.
4 *
5 * Copyright 2004 Sandia Corporation. Under the terms of Contract
6 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7 * retains certain rights in this software.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 */
15
16 #include <H5Tpublic.h>
17 #include <H5Dpublic.h>
18 #include <H5Ppublic.h>
19 #include <H5Gpublic.h>
20 #include "mhdf.h"
21 #include "status.h"
22 #include "names-and-paths.h"
23 #include "util.h"
24 #include "file-handle.h"
25
26
27 int
mhdf_haveNodes(mhdf_FileHandle file,mhdf_Status * status)28 mhdf_haveNodes( mhdf_FileHandle file, mhdf_Status* status )
29 {
30 FileHandle* file_ptr = (FileHandle*)file;
31 hid_t root_id, node_id;
32 int result;
33 API_BEGIN;
34
35 if (!mhdf_check_valid_file( file_ptr, status ))
36 return -1;
37
38 #if defined(H5Gopen_vers) && H5Gopen_vers > 1
39 root_id = H5Gopen2( file_ptr->hdf_handle, ROOT_GROUP, H5P_DEFAULT );
40 #else
41 root_id = H5Gopen( file_ptr->hdf_handle, ROOT_GROUP );
42 #endif
43 if (root_id < 0)
44 {
45 mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.", ROOT_GROUP );
46 return -1;
47 }
48
49 result = mhdf_is_in_group( root_id, NODE_GROUP_NAME, status );
50 if (result < 1)
51 {
52 H5Gclose(root_id);
53 return result;
54 }
55
56 #if defined(H5Gopen_vers) && H5Gopen_vers > 1
57 node_id = H5Gopen2( root_id, NODE_GROUP_NAME, H5P_DEFAULT );
58 #else
59 node_id = H5Gopen( root_id, NODE_GROUP_NAME );
60 #endif
61 H5Gclose( root_id );
62 if (node_id < 0)
63 {
64 mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.", NODE_GROUP );
65 return -1;
66 }
67
68 result = mhdf_is_in_group( node_id, NODE_COORD_NAME, status );
69 if (result >= 0)
70 mhdf_setOkay( status );
71 H5Gclose( node_id );
72 API_END;
73 return result;
74 }
75
76 hid_t
mhdf_createNodeCoords(mhdf_FileHandle file_handle,int dimension,long num_nodes,long * first_id_out,mhdf_Status * status)77 mhdf_createNodeCoords( mhdf_FileHandle file_handle,
78 int dimension,
79 long num_nodes,
80 long* first_id_out,
81 mhdf_Status* status )
82 {
83 FileHandle* file_ptr = (FileHandle*)file_handle;
84 hid_t table_id;
85 hsize_t dims[2];
86 long first_id;
87 API_BEGIN;
88
89 if (!mhdf_check_valid_file( file_ptr, status ))
90 return -1;
91
92 if (dimension < 1)
93 {
94 mhdf_setFail( status, "Invalid argument: dimension = %d.", dimension );
95 return -1;
96 }
97
98 dims[0] = (hsize_t)num_nodes;
99 dims[1] = (hsize_t)dimension;
100 table_id = mhdf_create_table( file_ptr->hdf_handle,
101 NODE_COORD_PATH,
102 H5T_NATIVE_DOUBLE,
103 2, dims,
104 status );
105 if (table_id < 0)
106 return -1;
107
108 first_id = file_ptr->max_id + 1;
109 if (!mhdf_create_scalar_attrib( table_id,
110 START_ID_ATTRIB,
111 H5T_NATIVE_LONG,
112 &first_id,
113 status ))
114 {
115 H5Dclose( table_id );
116 return -1;
117 }
118
119 *first_id_out = first_id;
120 file_ptr->max_id += num_nodes;
121 if (!mhdf_write_max_id( file_ptr, status ))
122 {
123 H5Dclose( table_id );
124 return -1;
125 }
126 file_ptr->open_handle_count++;
127 mhdf_setOkay( status );
128
129 API_END_H(1);
130 return table_id;
131 }
132
133
134 hid_t
mhdf_openNodeCoords(mhdf_FileHandle file_handle,long * num_nodes_out,int * dimension_out,long * first_id_out,mhdf_Status * status)135 mhdf_openNodeCoords( mhdf_FileHandle file_handle,
136 long* num_nodes_out,
137 int* dimension_out,
138 long* first_id_out,
139 mhdf_Status* status )
140 {
141 FileHandle* file_ptr = (FileHandle*)file_handle;
142 hid_t table_id;
143 hsize_t dims[2];
144 API_BEGIN;
145
146 if (!mhdf_check_valid_file( file_ptr, status ))
147 return -1;
148
149 table_id = mhdf_open_table2( file_ptr->hdf_handle,
150 NODE_COORD_PATH, 2,
151 dims, first_id_out, status );
152 if (table_id < 0)
153 return -1;
154
155 *num_nodes_out = dims[0];
156 *dimension_out = dims[1];
157 file_ptr->open_handle_count++;
158 mhdf_setOkay( status );
159 API_END_H(1);
160 return table_id;
161 }
162
163 hid_t
mhdf_openNodeCoordsSimple(mhdf_FileHandle file_handle,mhdf_Status * status)164 mhdf_openNodeCoordsSimple( mhdf_FileHandle file_handle, mhdf_Status* status )
165 {
166 FileHandle* file_ptr = (FileHandle*)file_handle;
167 hid_t table_id;
168 API_BEGIN;
169
170 if (!mhdf_check_valid_file( file_ptr, status ))
171 return -1;
172
173 table_id = mhdf_open_table_simple( file_ptr->hdf_handle,
174 NODE_COORD_PATH, status );
175 if (table_id < 0)
176 return -1;
177
178 file_ptr->open_handle_count++;
179 mhdf_setOkay( status );
180 API_END_H(1);
181 return table_id;
182 }
183
184 void
mhdf_writeNodeCoords(hid_t table_id,long offset,long count,const double * coords,mhdf_Status * status)185 mhdf_writeNodeCoords( hid_t table_id,
186 long offset,
187 long count,
188 const double* coords,
189 mhdf_Status* status )
190 {
191 API_BEGIN;
192 mhdf_write_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
193 API_END;
194 }
195 void
mhdf_writeNodeCoordsWithOpt(hid_t table_id,long offset,long count,const double * coords,hid_t prop,mhdf_Status * status)196 mhdf_writeNodeCoordsWithOpt( hid_t table_id,
197 long offset,
198 long count,
199 const double* coords,
200 hid_t prop,
201 mhdf_Status* status )
202 {
203 API_BEGIN;
204 mhdf_write_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
205 API_END;
206 }
207
208 void
mhdf_readNodeCoords(hid_t table_id,long offset,long count,double * coords,mhdf_Status * status)209 mhdf_readNodeCoords( hid_t table_id,
210 long offset,
211 long count,
212 double* coords,
213 mhdf_Status* status )
214 {
215 API_BEGIN;
216 mhdf_read_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
217 API_END;
218 }
219 void
mhdf_readNodeCoordsWithOpt(hid_t table_id,long offset,long count,double * coords,hid_t prop,mhdf_Status * status)220 mhdf_readNodeCoordsWithOpt( hid_t table_id,
221 long offset,
222 long count,
223 double* coords,
224 hid_t prop,
225 mhdf_Status* status )
226 {
227 API_BEGIN;
228 mhdf_read_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
229 API_END;
230 }
231
232 void
mhdf_writeNodeCoord(hid_t table_id,long offset,long count,int dimension,const double * coords,mhdf_Status * status)233 mhdf_writeNodeCoord( hid_t table_id,
234 long offset,
235 long count,
236 int dimension,
237 const double* coords,
238 mhdf_Status* status )
239 {
240 API_BEGIN;
241 mhdf_write_column( table_id, dimension, offset, count,
242 H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
243 API_END;
244 }
245 void
mhdf_writeNodeCoordWithOpt(hid_t table_id,long offset,long count,int dimension,const double * coords,hid_t prop,mhdf_Status * status)246 mhdf_writeNodeCoordWithOpt( hid_t table_id,
247 long offset,
248 long count,
249 int dimension,
250 const double* coords,
251 hid_t prop,
252 mhdf_Status* status )
253 {
254 API_BEGIN;
255 mhdf_write_column( table_id, dimension, offset, count,
256 H5T_NATIVE_DOUBLE, coords, prop, status );
257 API_END;
258 }
259
260
261 void
mhdf_readNodeCoord(hid_t table_id,long offset,long count,int dimension,double * coords,mhdf_Status * status)262 mhdf_readNodeCoord( hid_t table_id,
263 long offset,
264 long count,
265 int dimension,
266 double* coords,
267 mhdf_Status* status )
268 {
269 API_BEGIN;
270 mhdf_read_column( table_id, dimension, offset, count,
271 H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
272 API_END;
273 }
274 void
mhdf_readNodeCoordWithOpt(hid_t table_id,long offset,long count,int dimension,double * coords,hid_t prop,mhdf_Status * status)275 mhdf_readNodeCoordWithOpt( hid_t table_id,
276 long offset,
277 long count,
278 int dimension,
279 double* coords,
280 hid_t prop,
281 mhdf_Status* status )
282 {
283 API_BEGIN;
284 mhdf_read_column( table_id, dimension, offset, count,
285 H5T_NATIVE_DOUBLE, coords, prop, status );
286 API_END;
287 }
288
289