Branch data Line data Source code
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 <H5Gpublic.h>
19 : : #include <H5Ppublic.h>
20 : : #include "mhdf.h"
21 : : #include "util.h"
22 : : #include "file-handle.h"
23 : : #include "status.h"
24 : : #include "names-and-paths.h"
25 : :
26 : 52 : hid_t mhdf_createConnectivity( mhdf_FileHandle file_handle, const char* elem_handle, int nodes_per_elem, long count,
27 : : long* first_id_out, mhdf_Status* status )
28 : : {
29 : : FileHandle* file_ptr;
30 : : hid_t elem_id, table_id;
31 : : hsize_t dims[ 2 ];
32 : : long first_id;
33 : : API_BEGIN;
34 : :
35 : 52 : file_ptr = (FileHandle*)( file_handle );
36 [ - + ]: 52 : if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
37 : :
38 [ + - ][ + - ]: 52 : if( nodes_per_elem <= 0 || count < 0 || !first_id_out )
[ - + ]
39 : : {
40 : 0 : mhdf_setFail( status, "Invalid argument." );
41 : 0 : return -1;
42 : : }
43 : :
44 : 52 : elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
45 [ - + ]: 52 : if( elem_id < 0 ) return -1;
46 : :
47 : 52 : dims[ 0 ] = (hsize_t)count;
48 : 52 : dims[ 1 ] = (hsize_t)nodes_per_elem;
49 : 52 : table_id = mhdf_create_table( elem_id, CONNECTIVITY_NAME, file_ptr->id_type, 2, dims, status );
50 : 52 : H5Gclose( elem_id );
51 [ - + ]: 52 : if( table_id < 0 ) return -1;
52 : :
53 : 52 : first_id = file_ptr->max_id + 1;
54 [ - + ]: 52 : if( !mhdf_create_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, &first_id, status ) )
55 : : {
56 : 0 : H5Dclose( table_id );
57 : 0 : return -1;
58 : : }
59 : :
60 : 52 : *first_id_out = first_id;
61 : 52 : file_ptr->max_id += count;
62 [ - + ]: 52 : if( !mhdf_write_max_id( file_ptr, status ) )
63 : : {
64 : 0 : H5Dclose( table_id );
65 : 0 : return -1;
66 : : }
67 : 52 : file_ptr->open_handle_count++;
68 : 52 : mhdf_setOkay( status );
69 : :
70 : : API_END_H( 1 );
71 : 52 : return table_id;
72 : : }
73 : :
74 : 161 : hid_t mhdf_openConnectivity( mhdf_FileHandle file_handle, const char* elem_handle, int* num_nodes_per_elem_out,
75 : : long* num_elements_out, long* first_elem_id_out, mhdf_Status* status )
76 : : {
77 : : FileHandle* file_ptr;
78 : : hid_t elem_id, table_id;
79 : : hsize_t dims[ 2 ];
80 : : API_BEGIN;
81 : :
82 : 161 : file_ptr = (FileHandle*)( file_handle );
83 [ - + ]: 161 : if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
84 : :
85 [ + - ][ + - ]: 161 : if( !num_nodes_per_elem_out || !num_elements_out || !first_elem_id_out )
[ - + ]
86 : : {
87 : 0 : mhdf_setFail( status, "Invalid argument." );
88 : 0 : return -1;
89 : : }
90 : :
91 : 161 : elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
92 [ - + ]: 161 : if( elem_id < 0 ) return -1;
93 : :
94 : 161 : table_id = mhdf_open_table2( elem_id, CONNECTIVITY_NAME, 2, dims, first_elem_id_out, status );
95 : :
96 : 161 : H5Gclose( elem_id );
97 [ - + ]: 161 : if( table_id < 0 ) return -1;
98 : :
99 : 161 : *num_elements_out = dims[ 0 ];
100 : 161 : *num_nodes_per_elem_out = dims[ 1 ];
101 : :
102 : 161 : file_ptr->open_handle_count++;
103 : 161 : mhdf_setOkay( status );
104 : : API_END_H( 1 );
105 : 161 : return table_id;
106 : : }
107 : :
108 : 105 : hid_t mhdf_openConnectivitySimple( mhdf_FileHandle file_handle, const char* elem_handle, mhdf_Status* status )
109 : : {
110 : : FileHandle* file_ptr;
111 : : hid_t elem_id, table_id;
112 : : API_BEGIN;
113 : :
114 : 105 : file_ptr = (FileHandle*)( file_handle );
115 [ - + ]: 105 : if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
116 : :
117 : 105 : elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
118 [ - + ]: 105 : if( elem_id < 0 ) return -1;
119 : :
120 : 105 : table_id = mhdf_open_table_simple( elem_id, CONNECTIVITY_NAME, status );
121 : :
122 : 105 : H5Gclose( elem_id );
123 [ - + ]: 105 : if( table_id < 0 ) return -1;
124 : :
125 : 105 : file_ptr->open_handle_count++;
126 : 105 : mhdf_setOkay( status );
127 : : API_END_H( 1 );
128 : 105 : return table_id;
129 : : }
130 : :
131 : 0 : void mhdf_writeConnectivity( hid_t table_id, long offset, long count, hid_t hdf_integer_type, const void* nodes,
132 : : mhdf_Status* status )
133 : : {
134 : : API_BEGIN;
135 : 0 : mhdf_write_data( table_id, offset, count, hdf_integer_type, nodes, H5P_DEFAULT, status );
136 : : API_END;
137 : 0 : }
138 : 52 : void mhdf_writeConnectivityWithOpt( hid_t table_id, long offset, long count, hid_t hdf_integer_type, const void* nodes,
139 : : hid_t prop, mhdf_Status* status )
140 : : {
141 : : API_BEGIN;
142 : 52 : mhdf_write_data( table_id, offset, count, hdf_integer_type, nodes, prop, status );
143 : : API_END;
144 : 52 : }
145 : :
146 : 0 : void mhdf_readConnectivity( hid_t table_id, long offset, long count, hid_t hdf_integer_type, void* nodes,
147 : : mhdf_Status* status )
148 : : {
149 : : API_BEGIN;
150 : 0 : mhdf_read_data( table_id, offset, count, hdf_integer_type, nodes, H5P_DEFAULT, status );
151 : : API_END;
152 : 0 : }
153 : 0 : void mhdf_readConnectivityWithOpt( hid_t table_id, long offset, long count, hid_t hdf_integer_type, void* nodes,
154 : : hid_t prop, mhdf_Status* status )
155 : : {
156 : : API_BEGIN;
157 : 0 : mhdf_read_data( table_id, offset, count, hdf_integer_type, nodes, prop, status );
158 : : API_END;
159 : 0 : }
160 : :
161 : 0 : void mhdf_createPolyConnectivity( mhdf_FileHandle file_handle, const char* elem_type, long num_poly,
162 : : long data_list_length, long* first_id_out, hid_t handles_out[ 2 ],
163 : : mhdf_Status* status )
164 : : {
165 : : FileHandle* file_ptr;
166 : : hid_t elem_id, index_id, conn_id;
167 : : hsize_t dim;
168 : : long first_id;
169 : : API_BEGIN;
170 : :
171 : 0 : file_ptr = (FileHandle*)( file_handle );
172 [ # # ]: 0 : if( !mhdf_check_valid_file( file_ptr, status ) ) return;
173 : :
174 [ # # ][ # # ]: 0 : if( num_poly <= 0 || data_list_length <= 0 || !first_id_out )
[ # # ]
175 : : {
176 : 0 : mhdf_setFail( status, "Invalid argument." );
177 : 0 : return;
178 : : }
179 : :
180 [ # # ]: 0 : if( data_list_length < 3 * num_poly )
181 : : {
182 : : /* Could check agains 4*num_poly, but allow degenerate polys
183 : : (1 for count plus 2 dim-1 defining entities, where > 2
184 : : defining entities is a normal poly, 2 defining entities
185 : : is a degenerate poly and 1 defning entity is not valid.)
186 : : */
187 : :
188 : 0 : mhdf_setFail( status,
189 : : "Invalid polygon data: data length of %ld is "
190 : : "insufficient for %ld poly(gons/hedra).\n",
191 : : data_list_length, num_poly );
192 : 0 : return;
193 : : }
194 : :
195 : 0 : elem_id = mhdf_elem_group_from_handle( file_ptr, elem_type, status );
196 [ # # ]: 0 : if( elem_id < 0 ) return;
197 : :
198 : 0 : dim = (hsize_t)num_poly;
199 : 0 : index_id = mhdf_create_table( elem_id, POLY_INDEX_NAME, MHDF_INDEX_TYPE, 1, &dim, status );
200 [ # # ]: 0 : if( index_id < 0 )
201 : : {
202 : 0 : H5Gclose( elem_id );
203 : 0 : return;
204 : : }
205 : :
206 : 0 : dim = (hsize_t)data_list_length;
207 : 0 : conn_id = mhdf_create_table( elem_id, CONNECTIVITY_NAME, file_ptr->id_type, 1, &dim, status );
208 : 0 : H5Gclose( elem_id );
209 [ # # ]: 0 : if( conn_id < 0 )
210 : : {
211 : 0 : H5Dclose( index_id );
212 : 0 : return;
213 : : }
214 : :
215 : 0 : first_id = file_ptr->max_id + 1;
216 [ # # ]: 0 : if( !mhdf_create_scalar_attrib( conn_id, START_ID_ATTRIB, H5T_NATIVE_LONG, &first_id, status ) )
217 : : {
218 : 0 : H5Dclose( index_id );
219 : 0 : H5Dclose( conn_id );
220 : 0 : return;
221 : : }
222 : :
223 : 0 : *first_id_out = first_id;
224 : 0 : file_ptr->max_id += num_poly;
225 [ # # ]: 0 : if( !mhdf_write_max_id( file_ptr, status ) )
226 : : {
227 : 0 : H5Dclose( index_id );
228 : 0 : H5Dclose( conn_id );
229 : 0 : return;
230 : : }
231 : 0 : file_ptr->open_handle_count++;
232 : 0 : mhdf_setOkay( status );
233 : 0 : handles_out[ 0 ] = index_id;
234 : 0 : handles_out[ 1 ] = conn_id;
235 : : API_END_H( 2 );
236 : : }
237 : :
238 : 0 : void mhdf_openPolyConnectivity( mhdf_FileHandle file_handle, const char* element_handle, long* num_poly_out,
239 : : long* data_list_length_out, long* first_poly_id_out, hid_t handles_out[ 2 ],
240 : : mhdf_Status* status )
241 : : {
242 : : FileHandle* file_ptr;
243 : : hid_t elem_id, table_id, index_id;
244 : : hsize_t row_count;
245 : : API_BEGIN;
246 : :
247 : 0 : file_ptr = (FileHandle*)( file_handle );
248 [ # # ]: 0 : if( !mhdf_check_valid_file( file_ptr, status ) ) return;
249 : :
250 [ # # ][ # # ]: 0 : if( !num_poly_out || !data_list_length_out || !first_poly_id_out )
[ # # ]
251 : : {
252 : 0 : mhdf_setFail( status, "Invalid argument." );
253 : 0 : return;
254 : : }
255 : :
256 : 0 : elem_id = mhdf_elem_group_from_handle( file_ptr, element_handle, status );
257 [ # # ]: 0 : if( elem_id < 0 ) return;
258 : :
259 : 0 : index_id = mhdf_open_table( elem_id, POLY_INDEX_NAME, 1, &row_count, status );
260 [ # # ]: 0 : if( index_id < 0 )
261 : : {
262 : 0 : H5Gclose( elem_id );
263 : 0 : return;
264 : : }
265 : 0 : *num_poly_out = (int)row_count;
266 : :
267 : 0 : table_id = mhdf_open_table( elem_id, CONNECTIVITY_NAME, 1, &row_count, status );
268 : :
269 : 0 : H5Gclose( elem_id );
270 [ # # ]: 0 : if( table_id < 0 )
271 : : {
272 : 0 : H5Dclose( index_id );
273 : 0 : return;
274 : : }
275 : 0 : *data_list_length_out = (long)row_count;
276 : :
277 [ # # ]: 0 : if( !mhdf_read_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, first_poly_id_out, status ) )
278 : : {
279 : 0 : H5Dclose( table_id );
280 : 0 : H5Dclose( index_id );
281 : 0 : return;
282 : : }
283 : :
284 : 0 : file_ptr->open_handle_count++;
285 : 0 : handles_out[ 0 ] = index_id;
286 : 0 : handles_out[ 1 ] = table_id;
287 : 0 : mhdf_setOkay( status );
288 : : API_END_H( 2 );
289 : : }
290 : :
291 : 0 : void mhdf_writePolyConnIndices( hid_t table_id, long offset, long count, hid_t hdf_integer_type, const void* index_list,
292 : : mhdf_Status* status )
293 : : {
294 : : API_BEGIN;
295 : 0 : mhdf_write_data( table_id, offset, count, hdf_integer_type, index_list, H5P_DEFAULT, status );
296 : : API_END;
297 : 0 : }
298 : 0 : void mhdf_writePolyConnIndicesWithOpt( hid_t table_id, long offset, long count, hid_t hdf_integer_type,
299 : : const void* index_list, hid_t prop, mhdf_Status* status )
300 : : {
301 : : API_BEGIN;
302 : 0 : mhdf_write_data( table_id, offset, count, hdf_integer_type, index_list, prop, status );
303 : : API_END;
304 : 0 : }
305 : :
306 : 0 : void mhdf_readPolyConnIndices( hid_t table_id, long offset, long count, hid_t hdf_integer_type, void* index_list,
307 : : mhdf_Status* status )
308 : : {
309 : : API_BEGIN;
310 : 0 : mhdf_read_data( table_id, offset, count, hdf_integer_type, index_list, H5P_DEFAULT, status );
311 : : API_END;
312 : 0 : }
313 : 0 : void mhdf_readPolyConnIndicesWithOpt( hid_t table_id, long offset, long count, hid_t hdf_integer_type, void* index_list,
314 : : hid_t prop, mhdf_Status* status )
315 : : {
316 : : API_BEGIN;
317 : 0 : mhdf_read_data( table_id, offset, count, hdf_integer_type, index_list, prop, status );
318 : : API_END;
319 : 0 : }
320 : :
321 : 0 : void mhdf_writePolyConnIDs( hid_t table_id, long offset, long count, hid_t hdf_integer_type, const void* id_list,
322 : : mhdf_Status* status )
323 : : {
324 : : API_BEGIN;
325 : 0 : mhdf_write_data( table_id, offset, count, hdf_integer_type, id_list, H5P_DEFAULT, status );
326 : : API_END;
327 : 0 : }
328 : 0 : void mhdf_writePolyConnIDsWithOpt( hid_t table_id, long offset, long count, hid_t hdf_integer_type, const void* id_list,
329 : : hid_t prop, mhdf_Status* status )
330 : : {
331 : : API_BEGIN;
332 : 0 : mhdf_write_data( table_id, offset, count, hdf_integer_type, id_list, prop, status );
333 : : API_END;
334 : 0 : }
335 : :
336 : 0 : void mhdf_readPolyConnIDs( hid_t table_id, long offset, long count, hid_t hdf_integer_type, void* id_list,
337 : : mhdf_Status* status )
338 : : {
339 : : API_BEGIN;
340 : 0 : mhdf_read_data( table_id, offset, count, hdf_integer_type, id_list, H5P_DEFAULT, status );
341 : : API_END;
342 : 0 : }
343 : 0 : void mhdf_readPolyConnIDsWithOpt( hid_t table_id, long offset, long count, hid_t hdf_integer_type, void* id_list,
344 : : hid_t prop, mhdf_Status* status )
345 : : {
346 : : API_BEGIN;
347 : 0 : mhdf_read_data( table_id, offset, count, hdf_integer_type, id_list, prop, status );
348 : : API_END;
349 : 0 : }
|