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 int
mhdf_haveAdjacency(mhdf_FileHandle file,const char * elem_group,mhdf_Status * status)26 mhdf_haveAdjacency( mhdf_FileHandle file,
27 const char* elem_group,
28 mhdf_Status* status )
29 {
30 FileHandle* file_ptr;
31 hid_t elem_id;
32 int result;
33 API_BEGIN;
34
35 file_ptr = (FileHandle*)(file);
36 if (!mhdf_check_valid_file( file_ptr, status ))
37 return -1;
38
39 if (elem_group == mhdf_node_type_handle())
40 {
41 #if defined(H5Gopen_vers) && H5Gopen_vers > 1
42 elem_id = H5Gopen( file_ptr->hdf_handle, NODE_GROUP, H5P_DEFAULT );
43 #else
44 elem_id = H5Gopen( file_ptr->hdf_handle, NODE_GROUP );
45 #endif
46 if (elem_id < 0)
47 {
48 mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.\n", NODE_GROUP );
49 return -1;
50 }
51 }
52 else
53 {
54 elem_id = mhdf_elem_group_from_handle( file_ptr, elem_group, status );
55 if (elem_id < 0)
56 return -1;
57 }
58
59 result = mhdf_is_in_group( elem_id, ADJACENCY_NAME, status );
60 H5Gclose( elem_id );
61 mhdf_setOkay( status );
62 API_END;
63 return result;
64 }
65
66
67 hid_t
mhdf_createAdjacency(mhdf_FileHandle file,const char * elem_handle,long adj_list_size,mhdf_Status * status)68 mhdf_createAdjacency( mhdf_FileHandle file,
69 const char* elem_handle,
70 long adj_list_size,
71 mhdf_Status* status )
72 {
73 FileHandle* file_ptr;
74 hid_t elem_id, table_id;
75 hsize_t dim = (hsize_t)adj_list_size;
76 API_BEGIN;
77
78 file_ptr = (FileHandle*)(file);
79 if (!mhdf_check_valid_file( file_ptr, status ))
80 return -1;
81
82 if (adj_list_size < 1)
83 {
84 mhdf_setFail( status, "Invalid argument.\n" );
85 return -1;
86 }
87
88 if (elem_handle == mhdf_node_type_handle())
89 {
90 table_id = mhdf_create_table( file_ptr->hdf_handle,
91 NODE_ADJCY_PATH,
92 file_ptr->id_type,
93 1, &dim,
94 status );
95 }
96 else
97 {
98 elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
99 if (elem_id < 0) return -1;
100
101 table_id = mhdf_create_table( elem_id,
102 ADJACENCY_NAME,
103 file_ptr->id_type,
104 1, &dim,
105 status );
106 H5Gclose( elem_id );
107 }
108
109 API_END_H(1);
110 return table_id;
111 }
112
113
114
115 hid_t
mhdf_openAdjacency(mhdf_FileHandle file,const char * elem_handle,long * adj_list_size_out,mhdf_Status * status)116 mhdf_openAdjacency( mhdf_FileHandle file,
117 const char* elem_handle,
118 long* adj_list_size_out,
119 mhdf_Status* status )
120
121 {
122 FileHandle* file_ptr;
123 hid_t elem_id, table_id;
124 hsize_t dim;
125 API_BEGIN;
126
127 file_ptr = (FileHandle*)(file);
128 if (!mhdf_check_valid_file( file_ptr, status ))
129 return -1;
130
131 if (!adj_list_size_out)
132 {
133 mhdf_setFail( status, "Invalid argument.\n" );
134 return -1;
135 }
136
137 if (elem_handle == mhdf_node_type_handle())
138 {
139 table_id = mhdf_open_table( file_ptr->hdf_handle,
140 NODE_ADJCY_PATH,
141 1, &dim,
142 status );
143 }
144 else
145 {
146 elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
147 if (elem_id < 0) return -1;
148 table_id = mhdf_open_table( elem_id,
149 ADJACENCY_NAME,
150 1, &dim,
151 status );
152 H5Gclose( elem_id );
153 }
154
155 *adj_list_size_out = (long)dim;
156 API_END_H(1);
157 return table_id;
158 }
159
160 void
mhdf_writeAdjacency(hid_t table_id,long offset,long count,hid_t type,const void * data,mhdf_Status * status)161 mhdf_writeAdjacency( hid_t table_id,
162 long offset,
163 long count,
164 hid_t type,
165 const void* data,
166 mhdf_Status* status )
167 {
168 API_BEGIN;
169 mhdf_write_data( table_id, offset, count, type, data, H5P_DEFAULT, status );
170 API_END;
171 }
172
173 void
mhdf_writeAdjacencyWithOpt(hid_t table_id,long offset,long count,hid_t type,const void * data,hid_t prop,mhdf_Status * status)174 mhdf_writeAdjacencyWithOpt( hid_t table_id,
175 long offset,
176 long count,
177 hid_t type,
178 const void* data,
179 hid_t prop,
180 mhdf_Status* status )
181 {
182 API_BEGIN;
183 mhdf_write_data( table_id, offset, count, type, data, prop, status );
184 API_END;
185 }
186
187 void
mhdf_readAdjacency(hid_t table_id,long offset,long count,hid_t type,void * data,mhdf_Status * status)188 mhdf_readAdjacency( hid_t table_id,
189 long offset,
190 long count,
191 hid_t type,
192 void* data,
193 mhdf_Status* status )
194 {
195 API_BEGIN;
196 mhdf_read_data( table_id, offset, count, type, data, H5P_DEFAULT, status );
197 API_END;
198 }
199 void
mhdf_readAdjacencyWithOpt(hid_t table_id,long offset,long count,hid_t type,void * data,hid_t prop,mhdf_Status * status)200 mhdf_readAdjacencyWithOpt( hid_t table_id,
201 long offset,
202 long count,
203 hid_t type,
204 void* data,
205 hid_t prop,
206 mhdf_Status* status )
207 {
208 API_BEGIN;
209 mhdf_read_data( table_id, offset, count, type, data, prop, status );
210 API_END;
211 }
212
213
214
215