1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419 | /**
* MOAB, a Mesh-Oriented datABase, is a software component for creating,
* storing and accessing finite element mesh data.
*
* Copyright 2004 Sandia Corporation. Under the terms of Contract
* DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
* retains certain rights in this software.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
*/
#include <H5Tpublic.h>
#include <H5Dpublic.h>
#include <H5Gpublic.h>
#include <H5Ppublic.h>
#include "mhdf.h"
#include "util.h"
#include "file-handle.h"
#include "status.h"
#include "names-and-paths.h"
hid_t mhdf_createConnectivity( mhdf_FileHandle file_handle,
const char* elem_handle,
int nodes_per_elem,
long count,
long* first_id_out,
mhdf_Status* status )
{
FileHandle* file_ptr;
hid_t elem_id, table_id;
hsize_t dims[2];
long first_id;
API_BEGIN;
file_ptr = (FileHandle*)( file_handle );
if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
if( nodes_per_elem <= 0 || count < 0 || !first_id_out )
{
mhdf_setFail( status, "Invalid argument." );
return -1;
}
elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
if( elem_id < 0 ) return -1;
dims[0] = (hsize_t)count;
dims[1] = (hsize_t)nodes_per_elem;
table_id = mhdf_create_table( elem_id, CONNECTIVITY_NAME, file_ptr->id_type, 2, dims, status );
H5Gclose( elem_id );
if( table_id < 0 ) return -1;
first_id = file_ptr->max_id + 1;
if( !mhdf_create_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, &first_id, status ) )
{
H5Dclose( table_id );
return -1;
}
*first_id_out = first_id;
file_ptr->max_id += count;
if( !mhdf_write_max_id( file_ptr, status ) )
{
H5Dclose( table_id );
return -1;
}
file_ptr->open_handle_count++;
mhdf_setOkay( status );
API_END_H( 1 );
return table_id;
}
hid_t mhdf_openConnectivity( mhdf_FileHandle file_handle,
const char* elem_handle,
int* num_nodes_per_elem_out,
long* num_elements_out,
long* first_elem_id_out,
mhdf_Status* status )
{
FileHandle* file_ptr;
hid_t elem_id, table_id;
hsize_t dims[2];
API_BEGIN;
file_ptr = (FileHandle*)( file_handle );
if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
if( !num_nodes_per_elem_out || !num_elements_out || !first_elem_id_out )
{
mhdf_setFail( status, "Invalid argument." );
return -1;
}
elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
if( elem_id < 0 ) return -1;
table_id = mhdf_open_table2( elem_id, CONNECTIVITY_NAME, 2, dims, first_elem_id_out, status );
H5Gclose( elem_id );
if( table_id < 0 ) return -1;
*num_elements_out = dims[0];
*num_nodes_per_elem_out = dims[1];
file_ptr->open_handle_count++;
mhdf_setOkay( status );
API_END_H( 1 );
return table_id;
}
hid_t mhdf_openConnectivitySimple( mhdf_FileHandle file_handle, const char* elem_handle, mhdf_Status* status )
{
FileHandle* file_ptr;
hid_t elem_id, table_id;
API_BEGIN;
file_ptr = (FileHandle*)( file_handle );
if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
if( elem_id < 0 ) return -1;
table_id = mhdf_open_table_simple( elem_id, CONNECTIVITY_NAME, status );
H5Gclose( elem_id );
if( table_id < 0 ) return -1;
file_ptr->open_handle_count++;
mhdf_setOkay( status );
API_END_H( 1 );
return table_id;
}
void mhdf_writeConnectivity( hid_t table_id,
long offset,
long count,
hid_t hdf_integer_type,
const void* nodes,
mhdf_Status* status )
{
API_BEGIN;
mhdf_write_data( table_id, offset, count, hdf_integer_type, nodes, H5P_DEFAULT, status );
API_END;
}
void mhdf_writeConnectivityWithOpt( hid_t table_id,
long offset,
long count,
hid_t hdf_integer_type,
const void* nodes,
hid_t prop,
mhdf_Status* status )
{
API_BEGIN;
mhdf_write_data( table_id, offset, count, hdf_integer_type, nodes, prop, status );
API_END;
}
void mhdf_readConnectivity( hid_t table_id,
long offset,
long count,
hid_t hdf_integer_type,
void* nodes,
mhdf_Status* status )
{
API_BEGIN;
mhdf_read_data( table_id, offset, count, hdf_integer_type, nodes, H5P_DEFAULT, status );
API_END;
}
void mhdf_readConnectivityWithOpt( hid_t table_id,
long offset,
long count,
hid_t hdf_integer_type,
void* nodes,
hid_t prop,
mhdf_Status* status )
{
API_BEGIN;
mhdf_read_data( table_id, offset, count, hdf_integer_type, nodes, prop, status );
API_END;
}
void mhdf_createPolyConnectivity( mhdf_FileHandle file_handle,<--- The function 'mhdf_createPolyConnectivity' is never used.
const char* elem_type,
long num_poly,
long data_list_length,
long* first_id_out,
hid_t handles_out[2],
mhdf_Status* status )
{
FileHandle* file_ptr;
hid_t elem_id, index_id, conn_id;
hsize_t dim;
long first_id;
API_BEGIN;
file_ptr = (FileHandle*)( file_handle );
if( !mhdf_check_valid_file( file_ptr, status ) ) return;
if( num_poly <= 0 || data_list_length <= 0 || !first_id_out )
{
mhdf_setFail( status, "Invalid argument." );
return;
}
if( data_list_length < 3 * num_poly )
{
/* Could check agains 4*num_poly, but allow degenerate polys
(1 for count plus 2 dim-1 defining entities, where > 2
defining entities is a normal poly, 2 defining entities
is a degenerate poly and 1 defning entity is not valid.)
*/
mhdf_setFail( status,
"Invalid polygon data: data length of %ld is "
"insufficient for %ld poly(gons/hedra).\n",
data_list_length, num_poly );
return;
}
elem_id = mhdf_elem_group_from_handle( file_ptr, elem_type, status );
if( elem_id < 0 ) return;
dim = (hsize_t)num_poly;
index_id = mhdf_create_table( elem_id, POLY_INDEX_NAME, MHDF_INDEX_TYPE, 1, &dim, status );
if( index_id < 0 )
{
H5Gclose( elem_id );
return;
}
dim = (hsize_t)data_list_length;
conn_id = mhdf_create_table( elem_id, CONNECTIVITY_NAME, file_ptr->id_type, 1, &dim, status );
H5Gclose( elem_id );
if( conn_id < 0 )
{
H5Dclose( index_id );
return;
}
first_id = file_ptr->max_id + 1;
if( !mhdf_create_scalar_attrib( conn_id, START_ID_ATTRIB, H5T_NATIVE_LONG, &first_id, status ) )
{
H5Dclose( index_id );
H5Dclose( conn_id );
return;
}
*first_id_out = first_id;
file_ptr->max_id += num_poly;
if( !mhdf_write_max_id( file_ptr, status ) )
{
H5Dclose( index_id );
H5Dclose( conn_id );
return;
}
file_ptr->open_handle_count++;
mhdf_setOkay( status );
handles_out[0] = index_id;
handles_out[1] = conn_id;
API_END_H( 2 );
}
void mhdf_openPolyConnectivity( mhdf_FileHandle file_handle,
const char* element_handle,
long* num_poly_out,
long* data_list_length_out,
long* first_poly_id_out,
hid_t handles_out[2],
mhdf_Status* status )
{
FileHandle* file_ptr;
hid_t elem_id, table_id, index_id;
hsize_t row_count;
API_BEGIN;
file_ptr = (FileHandle*)( file_handle );
if( !mhdf_check_valid_file( file_ptr, status ) ) return;
if( !num_poly_out || !data_list_length_out || !first_poly_id_out )
{
mhdf_setFail( status, "Invalid argument." );
return;
}
elem_id = mhdf_elem_group_from_handle( file_ptr, element_handle, status );
if( elem_id < 0 ) return;
index_id = mhdf_open_table( elem_id, POLY_INDEX_NAME, 1, &row_count, status );
if( index_id < 0 )
{
H5Gclose( elem_id );
return;
}
*num_poly_out = (int)row_count;
table_id = mhdf_open_table( elem_id, CONNECTIVITY_NAME, 1, &row_count, status );
H5Gclose( elem_id );
if( table_id < 0 )
{
H5Dclose( index_id );
return;
}
*data_list_length_out = (long)row_count;
if( !mhdf_read_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, first_poly_id_out, status ) )
{
H5Dclose( table_id );
H5Dclose( index_id );
return;
}
file_ptr->open_handle_count++;
handles_out[0] = index_id;
handles_out[1] = table_id;
mhdf_setOkay( status );
API_END_H( 2 );
}
void mhdf_writePolyConnIndices( hid_t table_id,<--- The function 'mhdf_writePolyConnIndices' is never used.
long offset,
long count,
hid_t hdf_integer_type,
const void* index_list,
mhdf_Status* status )
{
API_BEGIN;
mhdf_write_data( table_id, offset, count, hdf_integer_type, index_list, H5P_DEFAULT, status );
API_END;
}
void mhdf_writePolyConnIndicesWithOpt( hid_t table_id,<--- The function 'mhdf_writePolyConnIndicesWithOpt' is never used.
long offset,
long count,
hid_t hdf_integer_type,
const void* index_list,
hid_t prop,
mhdf_Status* status )
{
API_BEGIN;
mhdf_write_data( table_id, offset, count, hdf_integer_type, index_list, prop, status );
API_END;
}
void mhdf_readPolyConnIndices( hid_t table_id,
long offset,
long count,
hid_t hdf_integer_type,
void* index_list,
mhdf_Status* status )
{
API_BEGIN;
mhdf_read_data( table_id, offset, count, hdf_integer_type, index_list, H5P_DEFAULT, status );
API_END;
}
void mhdf_readPolyConnIndicesWithOpt( hid_t table_id,<--- The function 'mhdf_readPolyConnIndicesWithOpt' is never used.
long offset,
long count,
hid_t hdf_integer_type,
void* index_list,
hid_t prop,
mhdf_Status* status )
{
API_BEGIN;
mhdf_read_data( table_id, offset, count, hdf_integer_type, index_list, prop, status );
API_END;
}
void mhdf_writePolyConnIDs( hid_t table_id,<--- The function 'mhdf_writePolyConnIDs' is never used.
long offset,
long count,
hid_t hdf_integer_type,
const void* id_list,
mhdf_Status* status )
{
API_BEGIN;
mhdf_write_data( table_id, offset, count, hdf_integer_type, id_list, H5P_DEFAULT, status );
API_END;
}
void mhdf_writePolyConnIDsWithOpt( hid_t table_id,<--- The function 'mhdf_writePolyConnIDsWithOpt' is never used.
long offset,
long count,
hid_t hdf_integer_type,
const void* id_list,
hid_t prop,
mhdf_Status* status )
{
API_BEGIN;
mhdf_write_data( table_id, offset, count, hdf_integer_type, id_list, prop, status );
API_END;
}
void mhdf_readPolyConnIDs( hid_t table_id,
long offset,
long count,
hid_t hdf_integer_type,
void* id_list,
mhdf_Status* status )
{
API_BEGIN;
mhdf_read_data( table_id, offset, count, hdf_integer_type, id_list, H5P_DEFAULT, status );
API_END;
}
void mhdf_readPolyConnIDsWithOpt( hid_t table_id,<--- The function 'mhdf_readPolyConnIDsWithOpt' is never used.
long offset,
long count,
hid_t hdf_integer_type,
void* id_list,
hid_t prop,
mhdf_Status* status )
{
API_BEGIN;
mhdf_read_data( table_id, offset, count, hdf_integer_type, id_list, prop, status );
API_END;
}
|