MOAB: Mesh Oriented datABase
(version 5.2.1)
|
00001 /** 00002 * MOAB, a Mesh-Oriented datABase, is a software component for creating, 00003 * storing and accessing finite element mesh data. 00004 * 00005 * Copyright 2004 Sandia Corporation. Under the terms of Contract 00006 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 00007 * retains certain rights in this software. 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 2.1 of the License, or (at your option) any later version. 00013 * 00014 */ 00015 00016 #include <H5Tpublic.h> 00017 #include <H5Dpublic.h> 00018 #include <H5Gpublic.h> 00019 #include <H5Ppublic.h> 00020 #include "mhdf.h" 00021 #include "util.h" 00022 #include "file-handle.h" 00023 #include "status.h" 00024 #include "names-and-paths.h" 00025 00026 hid_t mhdf_createConnectivity( mhdf_FileHandle file_handle, const char* elem_handle, int nodes_per_elem, long count, 00027 long* first_id_out, mhdf_Status* status ) 00028 { 00029 FileHandle* file_ptr; 00030 hid_t elem_id, table_id; 00031 hsize_t dims[ 2 ]; 00032 long first_id; 00033 API_BEGIN; 00034 00035 file_ptr = (FileHandle*)( file_handle ); 00036 if( !mhdf_check_valid_file( file_ptr, status ) ) return -1; 00037 00038 if( nodes_per_elem <= 0 || count < 0 || !first_id_out ) 00039 { 00040 mhdf_setFail( status, "Invalid argument." ); 00041 return -1; 00042 } 00043 00044 elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status ); 00045 if( elem_id < 0 ) return -1; 00046 00047 dims[ 0 ] = (hsize_t)count; 00048 dims[ 1 ] = (hsize_t)nodes_per_elem; 00049 table_id = mhdf_create_table( elem_id, CONNECTIVITY_NAME, file_ptr->id_type, 2, dims, status ); 00050 H5Gclose( elem_id ); 00051 if( table_id < 0 ) return -1; 00052 00053 first_id = file_ptr->max_id + 1; 00054 if( !mhdf_create_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, &first_id, status ) ) 00055 { 00056 H5Dclose( table_id ); 00057 return -1; 00058 } 00059 00060 *first_id_out = first_id; 00061 file_ptr->max_id += count; 00062 if( !mhdf_write_max_id( file_ptr, status ) ) 00063 { 00064 H5Dclose( table_id ); 00065 return -1; 00066 } 00067 file_ptr->open_handle_count++; 00068 mhdf_setOkay( status ); 00069 00070 API_END_H( 1 ); 00071 return table_id; 00072 } 00073 00074 hid_t mhdf_openConnectivity( mhdf_FileHandle file_handle, const char* elem_handle, int* num_nodes_per_elem_out, 00075 long* num_elements_out, long* first_elem_id_out, mhdf_Status* status ) 00076 { 00077 FileHandle* file_ptr; 00078 hid_t elem_id, table_id; 00079 hsize_t dims[ 2 ]; 00080 API_BEGIN; 00081 00082 file_ptr = (FileHandle*)( file_handle ); 00083 if( !mhdf_check_valid_file( file_ptr, status ) ) return -1; 00084 00085 if( !num_nodes_per_elem_out || !num_elements_out || !first_elem_id_out ) 00086 { 00087 mhdf_setFail( status, "Invalid argument." ); 00088 return -1; 00089 } 00090 00091 elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status ); 00092 if( elem_id < 0 ) return -1; 00093 00094 table_id = mhdf_open_table2( elem_id, CONNECTIVITY_NAME, 2, dims, first_elem_id_out, status ); 00095 00096 H5Gclose( elem_id ); 00097 if( table_id < 0 ) return -1; 00098 00099 *num_elements_out = dims[ 0 ]; 00100 *num_nodes_per_elem_out = dims[ 1 ]; 00101 00102 file_ptr->open_handle_count++; 00103 mhdf_setOkay( status ); 00104 API_END_H( 1 ); 00105 return table_id; 00106 } 00107 00108 hid_t mhdf_openConnectivitySimple( mhdf_FileHandle file_handle, const char* elem_handle, mhdf_Status* status ) 00109 { 00110 FileHandle* file_ptr; 00111 hid_t elem_id, table_id; 00112 API_BEGIN; 00113 00114 file_ptr = (FileHandle*)( file_handle ); 00115 if( !mhdf_check_valid_file( file_ptr, status ) ) return -1; 00116 00117 elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status ); 00118 if( elem_id < 0 ) return -1; 00119 00120 table_id = mhdf_open_table_simple( elem_id, CONNECTIVITY_NAME, status ); 00121 00122 H5Gclose( elem_id ); 00123 if( table_id < 0 ) return -1; 00124 00125 file_ptr->open_handle_count++; 00126 mhdf_setOkay( status ); 00127 API_END_H( 1 ); 00128 return table_id; 00129 } 00130 00131 void mhdf_writeConnectivity( hid_t table_id, long offset, long count, hid_t hdf_integer_type, const void* nodes, 00132 mhdf_Status* status ) 00133 { 00134 API_BEGIN; 00135 mhdf_write_data( table_id, offset, count, hdf_integer_type, nodes, H5P_DEFAULT, status ); 00136 API_END; 00137 } 00138 void mhdf_writeConnectivityWithOpt( hid_t table_id, long offset, long count, hid_t hdf_integer_type, const void* nodes, 00139 hid_t prop, mhdf_Status* status ) 00140 { 00141 API_BEGIN; 00142 mhdf_write_data( table_id, offset, count, hdf_integer_type, nodes, prop, status ); 00143 API_END; 00144 } 00145 00146 void mhdf_readConnectivity( hid_t table_id, long offset, long count, hid_t hdf_integer_type, void* nodes, 00147 mhdf_Status* status ) 00148 { 00149 API_BEGIN; 00150 mhdf_read_data( table_id, offset, count, hdf_integer_type, nodes, H5P_DEFAULT, status ); 00151 API_END; 00152 } 00153 void mhdf_readConnectivityWithOpt( hid_t table_id, long offset, long count, hid_t hdf_integer_type, void* nodes, 00154 hid_t prop, mhdf_Status* status ) 00155 { 00156 API_BEGIN; 00157 mhdf_read_data( table_id, offset, count, hdf_integer_type, nodes, prop, status ); 00158 API_END; 00159 } 00160 00161 void mhdf_createPolyConnectivity( mhdf_FileHandle file_handle, const char* elem_type, long num_poly, 00162 long data_list_length, long* first_id_out, hid_t handles_out[ 2 ], 00163 mhdf_Status* status ) 00164 { 00165 FileHandle* file_ptr; 00166 hid_t elem_id, index_id, conn_id; 00167 hsize_t dim; 00168 long first_id; 00169 API_BEGIN; 00170 00171 file_ptr = (FileHandle*)( file_handle ); 00172 if( !mhdf_check_valid_file( file_ptr, status ) ) return; 00173 00174 if( num_poly <= 0 || data_list_length <= 0 || !first_id_out ) 00175 { 00176 mhdf_setFail( status, "Invalid argument." ); 00177 return; 00178 } 00179 00180 if( data_list_length < 3 * num_poly ) 00181 { 00182 /* Could check agains 4*num_poly, but allow degenerate polys 00183 (1 for count plus 2 dim-1 defining entities, where > 2 00184 defining entities is a normal poly, 2 defining entities 00185 is a degenerate poly and 1 defning entity is not valid.) 00186 */ 00187 00188 mhdf_setFail( status, 00189 "Invalid polygon data: data length of %ld is " 00190 "insufficient for %ld poly(gons/hedra).\n", 00191 data_list_length, num_poly ); 00192 return; 00193 } 00194 00195 elem_id = mhdf_elem_group_from_handle( file_ptr, elem_type, status ); 00196 if( elem_id < 0 ) return; 00197 00198 dim = (hsize_t)num_poly; 00199 index_id = mhdf_create_table( elem_id, POLY_INDEX_NAME, MHDF_INDEX_TYPE, 1, &dim, status ); 00200 if( index_id < 0 ) 00201 { 00202 H5Gclose( elem_id ); 00203 return; 00204 } 00205 00206 dim = (hsize_t)data_list_length; 00207 conn_id = mhdf_create_table( elem_id, CONNECTIVITY_NAME, file_ptr->id_type, 1, &dim, status ); 00208 H5Gclose( elem_id ); 00209 if( conn_id < 0 ) 00210 { 00211 H5Dclose( index_id ); 00212 return; 00213 } 00214 00215 first_id = file_ptr->max_id + 1; 00216 if( !mhdf_create_scalar_attrib( conn_id, START_ID_ATTRIB, H5T_NATIVE_LONG, &first_id, status ) ) 00217 { 00218 H5Dclose( index_id ); 00219 H5Dclose( conn_id ); 00220 return; 00221 } 00222 00223 *first_id_out = first_id; 00224 file_ptr->max_id += num_poly; 00225 if( !mhdf_write_max_id( file_ptr, status ) ) 00226 { 00227 H5Dclose( index_id ); 00228 H5Dclose( conn_id ); 00229 return; 00230 } 00231 file_ptr->open_handle_count++; 00232 mhdf_setOkay( status ); 00233 handles_out[ 0 ] = index_id; 00234 handles_out[ 1 ] = conn_id; 00235 API_END_H( 2 ); 00236 } 00237 00238 void mhdf_openPolyConnectivity( mhdf_FileHandle file_handle, const char* element_handle, long* num_poly_out, 00239 long* data_list_length_out, long* first_poly_id_out, hid_t handles_out[ 2 ], 00240 mhdf_Status* status ) 00241 { 00242 FileHandle* file_ptr; 00243 hid_t elem_id, table_id, index_id; 00244 hsize_t row_count; 00245 API_BEGIN; 00246 00247 file_ptr = (FileHandle*)( file_handle ); 00248 if( !mhdf_check_valid_file( file_ptr, status ) ) return; 00249 00250 if( !num_poly_out || !data_list_length_out || !first_poly_id_out ) 00251 { 00252 mhdf_setFail( status, "Invalid argument." ); 00253 return; 00254 } 00255 00256 elem_id = mhdf_elem_group_from_handle( file_ptr, element_handle, status ); 00257 if( elem_id < 0 ) return; 00258 00259 index_id = mhdf_open_table( elem_id, POLY_INDEX_NAME, 1, &row_count, status ); 00260 if( index_id < 0 ) 00261 { 00262 H5Gclose( elem_id ); 00263 return; 00264 } 00265 *num_poly_out = (int)row_count; 00266 00267 table_id = mhdf_open_table( elem_id, CONNECTIVITY_NAME, 1, &row_count, status ); 00268 00269 H5Gclose( elem_id ); 00270 if( table_id < 0 ) 00271 { 00272 H5Dclose( index_id ); 00273 return; 00274 } 00275 *data_list_length_out = (long)row_count; 00276 00277 if( !mhdf_read_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, first_poly_id_out, status ) ) 00278 { 00279 H5Dclose( table_id ); 00280 H5Dclose( index_id ); 00281 return; 00282 } 00283 00284 file_ptr->open_handle_count++; 00285 handles_out[ 0 ] = index_id; 00286 handles_out[ 1 ] = table_id; 00287 mhdf_setOkay( status ); 00288 API_END_H( 2 ); 00289 } 00290 00291 void mhdf_writePolyConnIndices( hid_t table_id, long offset, long count, hid_t hdf_integer_type, const void* index_list, 00292 mhdf_Status* status ) 00293 { 00294 API_BEGIN; 00295 mhdf_write_data( table_id, offset, count, hdf_integer_type, index_list, H5P_DEFAULT, status ); 00296 API_END; 00297 } 00298 void mhdf_writePolyConnIndicesWithOpt( hid_t table_id, long offset, long count, hid_t hdf_integer_type, 00299 const void* index_list, hid_t prop, mhdf_Status* status ) 00300 { 00301 API_BEGIN; 00302 mhdf_write_data( table_id, offset, count, hdf_integer_type, index_list, prop, status ); 00303 API_END; 00304 } 00305 00306 void mhdf_readPolyConnIndices( hid_t table_id, long offset, long count, hid_t hdf_integer_type, void* index_list, 00307 mhdf_Status* status ) 00308 { 00309 API_BEGIN; 00310 mhdf_read_data( table_id, offset, count, hdf_integer_type, index_list, H5P_DEFAULT, status ); 00311 API_END; 00312 } 00313 void mhdf_readPolyConnIndicesWithOpt( hid_t table_id, long offset, long count, hid_t hdf_integer_type, void* index_list, 00314 hid_t prop, mhdf_Status* status ) 00315 { 00316 API_BEGIN; 00317 mhdf_read_data( table_id, offset, count, hdf_integer_type, index_list, prop, status ); 00318 API_END; 00319 } 00320 00321 void mhdf_writePolyConnIDs( hid_t table_id, long offset, long count, hid_t hdf_integer_type, const void* id_list, 00322 mhdf_Status* status ) 00323 { 00324 API_BEGIN; 00325 mhdf_write_data( table_id, offset, count, hdf_integer_type, id_list, H5P_DEFAULT, status ); 00326 API_END; 00327 } 00328 void mhdf_writePolyConnIDsWithOpt( hid_t table_id, long offset, long count, hid_t hdf_integer_type, const void* id_list, 00329 hid_t prop, mhdf_Status* status ) 00330 { 00331 API_BEGIN; 00332 mhdf_write_data( table_id, offset, count, hdf_integer_type, id_list, prop, status ); 00333 API_END; 00334 } 00335 00336 void mhdf_readPolyConnIDs( hid_t table_id, long offset, long count, hid_t hdf_integer_type, void* id_list, 00337 mhdf_Status* status ) 00338 { 00339 API_BEGIN; 00340 mhdf_read_data( table_id, offset, count, hdf_integer_type, id_list, H5P_DEFAULT, status ); 00341 API_END; 00342 } 00343 void mhdf_readPolyConnIDsWithOpt( hid_t table_id, long offset, long count, hid_t hdf_integer_type, void* id_list, 00344 hid_t prop, mhdf_Status* status ) 00345 { 00346 API_BEGIN; 00347 mhdf_read_data( table_id, offset, count, hdf_integer_type, id_list, prop, status ); 00348 API_END; 00349 }