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 <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 : 68 : int mhdf_haveNodes( mhdf_FileHandle file, mhdf_Status* status )
27 : : {
28 : 68 : FileHandle* file_ptr = (FileHandle*)file;
29 : : hid_t root_id, node_id;
30 : : int result;
31 : : API_BEGIN;
32 : :
33 [ - + ]: 68 : if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
34 : :
35 : : #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
36 : 68 : root_id = H5Gopen2( file_ptr->hdf_handle, ROOT_GROUP, H5P_DEFAULT );
37 : : #else
38 : : root_id = H5Gopen( file_ptr->hdf_handle, ROOT_GROUP );
39 : : #endif
40 [ - + ]: 68 : if( root_id < 0 )
41 : : {
42 : 0 : mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.", ROOT_GROUP );
43 : 0 : return -1;
44 : : }
45 : :
46 : 68 : result = mhdf_is_in_group( root_id, NODE_GROUP_NAME, status );
47 [ - + ]: 68 : if( result < 1 )
48 : : {
49 : 0 : H5Gclose( root_id );
50 : 0 : return result;
51 : : }
52 : :
53 : : #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
54 : 68 : node_id = H5Gopen2( root_id, NODE_GROUP_NAME, H5P_DEFAULT );
55 : : #else
56 : : node_id = H5Gopen( root_id, NODE_GROUP_NAME );
57 : : #endif
58 : 68 : H5Gclose( root_id );
59 [ - + ]: 68 : if( node_id < 0 )
60 : : {
61 : 0 : mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.", NODE_GROUP );
62 : 0 : return -1;
63 : : }
64 : :
65 : 68 : result = mhdf_is_in_group( node_id, NODE_COORD_NAME, status );
66 [ + - ]: 68 : if( result >= 0 ) mhdf_setOkay( status );
67 : 68 : H5Gclose( node_id );
68 : : API_END;
69 : 68 : return result;
70 : : }
71 : :
72 : 38 : hid_t mhdf_createNodeCoords( mhdf_FileHandle file_handle, int dimension, long num_nodes, long* first_id_out,
73 : : mhdf_Status* status )
74 : : {
75 : 38 : FileHandle* file_ptr = (FileHandle*)file_handle;
76 : : hid_t table_id;
77 : : hsize_t dims[ 2 ];
78 : : long first_id;
79 : : API_BEGIN;
80 : :
81 [ - + ]: 38 : if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
82 : :
83 [ - + ]: 38 : if( dimension < 1 )
84 : : {
85 : 0 : mhdf_setFail( status, "Invalid argument: dimension = %d.", dimension );
86 : 0 : return -1;
87 : : }
88 : :
89 : 38 : dims[ 0 ] = (hsize_t)num_nodes;
90 : 38 : dims[ 1 ] = (hsize_t)dimension;
91 : 38 : table_id = mhdf_create_table( file_ptr->hdf_handle, NODE_COORD_PATH, H5T_NATIVE_DOUBLE, 2, dims, status );
92 [ - + ]: 38 : if( table_id < 0 ) return -1;
93 : :
94 : 38 : first_id = file_ptr->max_id + 1;
95 [ - + ]: 38 : if( !mhdf_create_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, &first_id, status ) )
96 : : {
97 : 0 : H5Dclose( table_id );
98 : 0 : return -1;
99 : : }
100 : :
101 : 38 : *first_id_out = first_id;
102 : 38 : file_ptr->max_id += num_nodes;
103 [ - + ]: 38 : if( !mhdf_write_max_id( file_ptr, status ) )
104 : : {
105 : 0 : H5Dclose( table_id );
106 : 0 : return -1;
107 : : }
108 : 38 : file_ptr->open_handle_count++;
109 : 38 : mhdf_setOkay( status );
110 : :
111 : : API_END_H( 1 );
112 : 38 : return table_id;
113 : : }
114 : :
115 : 105 : hid_t mhdf_openNodeCoords( mhdf_FileHandle file_handle, long* num_nodes_out, int* dimension_out, long* first_id_out,
116 : : mhdf_Status* status )
117 : : {
118 : 105 : FileHandle* file_ptr = (FileHandle*)file_handle;
119 : : hid_t table_id;
120 : : hsize_t dims[ 2 ];
121 : : API_BEGIN;
122 : :
123 [ - + ]: 105 : if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
124 : :
125 : 105 : table_id = mhdf_open_table2( file_ptr->hdf_handle, NODE_COORD_PATH, 2, dims, first_id_out, status );
126 [ - + ]: 105 : if( table_id < 0 ) return -1;
127 : :
128 : 105 : *num_nodes_out = dims[ 0 ];
129 : 105 : *dimension_out = dims[ 1 ];
130 : 105 : file_ptr->open_handle_count++;
131 : 105 : mhdf_setOkay( status );
132 : : API_END_H( 1 );
133 : 105 : return table_id;
134 : : }
135 : :
136 : 65 : hid_t mhdf_openNodeCoordsSimple( mhdf_FileHandle file_handle, mhdf_Status* status )
137 : : {
138 : 65 : FileHandle* file_ptr = (FileHandle*)file_handle;
139 : : hid_t table_id;
140 : : API_BEGIN;
141 : :
142 [ - + ]: 65 : if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
143 : :
144 : 65 : table_id = mhdf_open_table_simple( file_ptr->hdf_handle, NODE_COORD_PATH, status );
145 [ - + ]: 65 : if( table_id < 0 ) return -1;
146 : :
147 : 65 : file_ptr->open_handle_count++;
148 : 65 : mhdf_setOkay( status );
149 : : API_END_H( 1 );
150 : 65 : return table_id;
151 : : }
152 : :
153 : 0 : void mhdf_writeNodeCoords( hid_t table_id, long offset, long count, const double* coords, mhdf_Status* status )
154 : : {
155 : : API_BEGIN;
156 : 0 : mhdf_write_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
157 : : API_END;
158 : 0 : }
159 : 38 : void mhdf_writeNodeCoordsWithOpt( hid_t table_id, long offset, long count, const double* coords, hid_t prop,
160 : : mhdf_Status* status )
161 : : {
162 : : API_BEGIN;
163 : 38 : mhdf_write_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
164 : : API_END;
165 : 38 : }
166 : :
167 : 0 : void mhdf_readNodeCoords( hid_t table_id, long offset, long count, double* coords, mhdf_Status* status )
168 : : {
169 : : API_BEGIN;
170 : 0 : mhdf_read_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
171 : : API_END;
172 : 0 : }
173 : 0 : void mhdf_readNodeCoordsWithOpt( hid_t table_id, long offset, long count, double* coords, hid_t prop,
174 : : mhdf_Status* status )
175 : : {
176 : : API_BEGIN;
177 : 0 : mhdf_read_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
178 : : API_END;
179 : 0 : }
180 : :
181 : 0 : void mhdf_writeNodeCoord( hid_t table_id, long offset, long count, int dimension, const double* coords,
182 : : mhdf_Status* status )
183 : : {
184 : : API_BEGIN;
185 : 0 : mhdf_write_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
186 : : API_END;
187 : 0 : }
188 : 0 : void mhdf_writeNodeCoordWithOpt( hid_t table_id, long offset, long count, int dimension, const double* coords,
189 : : hid_t prop, mhdf_Status* status )
190 : : {
191 : : API_BEGIN;
192 : 0 : mhdf_write_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
193 : : API_END;
194 : 0 : }
195 : :
196 : 0 : void mhdf_readNodeCoord( hid_t table_id, long offset, long count, int dimension, double* coords, mhdf_Status* status )
197 : : {
198 : : API_BEGIN;
199 : 0 : mhdf_read_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
200 : : API_END;
201 : 0 : }
202 : 0 : void mhdf_readNodeCoordWithOpt( hid_t table_id, long offset, long count, int dimension, double* coords, hid_t prop,
203 : : mhdf_Status* status )
204 : : {
205 : : API_BEGIN;
206 : 0 : mhdf_read_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
207 : : API_END;
208 : 0 : }
|