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 <H5Gpublic.h>
18 : : #include <H5Ppublic.h>
19 : : #include "mhdf.h"
20 : : #include "util.h"
21 : : #include "file-handle.h"
22 : : #include "status.h"
23 : : #include "names-and-paths.h"
24 : :
25 : 109 : int mhdf_haveAdjacency( mhdf_FileHandle file, const char* elem_group, mhdf_Status* status )
26 : : {
27 : : FileHandle* file_ptr;
28 : : hid_t elem_id;
29 : : int result;
30 : : API_BEGIN;
31 : :
32 : 109 : file_ptr = (FileHandle*)( file );
33 [ - + ]: 109 : if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
34 : :
35 [ - + ]: 109 : if( elem_group == mhdf_node_type_handle( ) )
36 : : {
37 : : #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
38 : 0 : elem_id = H5Gopen( file_ptr->hdf_handle, NODE_GROUP, H5P_DEFAULT );
39 : : #else
40 : : elem_id = H5Gopen( file_ptr->hdf_handle, NODE_GROUP );
41 : : #endif
42 [ # # ]: 0 : if( elem_id < 0 )
43 : : {
44 : 0 : mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.\n", NODE_GROUP );
45 : 0 : return -1;
46 : : }
47 : : }
48 : : else
49 : : {
50 : 109 : elem_id = mhdf_elem_group_from_handle( file_ptr, elem_group, status );
51 [ - + ]: 109 : if( elem_id < 0 ) return -1;
52 : : }
53 : :
54 : 109 : result = mhdf_is_in_group( elem_id, ADJACENCY_NAME, status );
55 : 109 : H5Gclose( elem_id );
56 : 109 : mhdf_setOkay( status );
57 : : API_END;
58 : 109 : return result;
59 : : }
60 : :
61 : 2 : hid_t mhdf_createAdjacency( mhdf_FileHandle file, const char* elem_handle, long adj_list_size, mhdf_Status* status )
62 : : {
63 : : FileHandle* file_ptr;
64 : : hid_t elem_id, table_id;
65 : 2 : hsize_t dim = (hsize_t)adj_list_size;
66 : : API_BEGIN;
67 : :
68 : 2 : file_ptr = (FileHandle*)( file );
69 [ - + ]: 2 : if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
70 : :
71 [ - + ]: 2 : if( adj_list_size < 1 )
72 : : {
73 : 0 : mhdf_setFail( status, "Invalid argument.\n" );
74 : 0 : return -1;
75 : : }
76 : :
77 [ - + ]: 2 : if( elem_handle == mhdf_node_type_handle( ) )
78 : 0 : { table_id = mhdf_create_table( file_ptr->hdf_handle, NODE_ADJCY_PATH, file_ptr->id_type, 1, &dim, status ); }
79 : : else
80 : : {
81 : 2 : elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
82 [ - + ]: 2 : if( elem_id < 0 ) return -1;
83 : :
84 : 2 : table_id = mhdf_create_table( elem_id, ADJACENCY_NAME, file_ptr->id_type, 1, &dim, status );
85 : 2 : H5Gclose( elem_id );
86 : : }
87 : :
88 : : API_END_H( 1 );
89 : 2 : return table_id;
90 : : }
91 : :
92 : 5 : hid_t mhdf_openAdjacency( mhdf_FileHandle file, const char* elem_handle, long* adj_list_size_out, mhdf_Status* status )
93 : :
94 : : {
95 : : FileHandle* file_ptr;
96 : : hid_t elem_id, table_id;
97 : : hsize_t dim;
98 : : API_BEGIN;
99 : :
100 : 5 : file_ptr = (FileHandle*)( file );
101 [ - + ]: 5 : if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
102 : :
103 [ - + ]: 5 : if( !adj_list_size_out )
104 : : {
105 : 0 : mhdf_setFail( status, "Invalid argument.\n" );
106 : 0 : return -1;
107 : : }
108 : :
109 [ - + ]: 5 : if( elem_handle == mhdf_node_type_handle( ) )
110 : 0 : { table_id = mhdf_open_table( file_ptr->hdf_handle, NODE_ADJCY_PATH, 1, &dim, status ); }
111 : : else
112 : : {
113 : 5 : elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
114 [ - + ]: 5 : if( elem_id < 0 ) return -1;
115 : 5 : table_id = mhdf_open_table( elem_id, ADJACENCY_NAME, 1, &dim, status );
116 : 5 : H5Gclose( elem_id );
117 : : }
118 : :
119 : 5 : *adj_list_size_out = (long)dim;
120 : : API_END_H( 1 );
121 : 5 : return table_id;
122 : : }
123 : :
124 : 0 : void mhdf_writeAdjacency( hid_t table_id, long offset, long count, hid_t type, const void* data, mhdf_Status* status )
125 : : {
126 : : API_BEGIN;
127 : 0 : mhdf_write_data( table_id, offset, count, type, data, H5P_DEFAULT, status );
128 : : API_END;
129 : 0 : }
130 : :
131 : 2 : void mhdf_writeAdjacencyWithOpt( hid_t table_id, long offset, long count, hid_t type, const void* data, hid_t prop,
132 : : mhdf_Status* status )
133 : : {
134 : : API_BEGIN;
135 : 2 : mhdf_write_data( table_id, offset, count, type, data, prop, status );
136 : : API_END;
137 : 2 : }
138 : :
139 : 0 : void mhdf_readAdjacency( hid_t table_id, long offset, long count, hid_t type, void* data, mhdf_Status* status )
140 : : {
141 : : API_BEGIN;
142 : 0 : mhdf_read_data( table_id, offset, count, type, data, H5P_DEFAULT, status );
143 : : API_END;
144 : 0 : }
145 : 3 : void mhdf_readAdjacencyWithOpt( hid_t table_id, long offset, long count, hid_t type, void* data, hid_t prop,
146 : : mhdf_Status* status )
147 : : {
148 : : API_BEGIN;
149 : 3 : mhdf_read_data( table_id, offset, count, type, data, prop, status );
150 : : API_END;
151 : 3 : }
|