MOAB: Mesh Oriented datABase
(version 5.4.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, 00027 const char* elem_handle, 00028 int nodes_per_elem, 00029 long count, 00030 long* first_id_out, 00031 mhdf_Status* status ) 00032 { 00033 FileHandle* file_ptr; 00034 hid_t elem_id, table_id; 00035 hsize_t dims[2]; 00036 long first_id; 00037 API_BEGIN; 00038 00039 file_ptr = (FileHandle*)( file_handle ); 00040 if( !mhdf_check_valid_file( file_ptr, status ) ) return -1; 00041 00042 if( nodes_per_elem <= 0 || count < 0 || !first_id_out ) 00043 { 00044 mhdf_setFail( status, "Invalid argument." ); 00045 return -1; 00046 } 00047 00048 elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status ); 00049 if( elem_id < 0 ) return -1; 00050 00051 dims[0] = (hsize_t)count; 00052 dims[1] = (hsize_t)nodes_per_elem; 00053 table_id = mhdf_create_table( elem_id, CONNECTIVITY_NAME, file_ptr->id_type, 2, dims, status ); 00054 H5Gclose( elem_id ); 00055 if( table_id < 0 ) return -1; 00056 00057 first_id = file_ptr->max_id + 1; 00058 if( !mhdf_create_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, &first_id, status ) ) 00059 { 00060 H5Dclose( table_id ); 00061 return -1; 00062 } 00063 00064 *first_id_out = first_id; 00065 file_ptr->max_id += count; 00066 if( !mhdf_write_max_id( file_ptr, status ) ) 00067 { 00068 H5Dclose( table_id ); 00069 return -1; 00070 } 00071 file_ptr->open_handle_count++; 00072 mhdf_setOkay( status ); 00073 00074 API_END_H( 1 ); 00075 return table_id; 00076 } 00077 00078 hid_t mhdf_openConnectivity( mhdf_FileHandle file_handle, 00079 const char* elem_handle, 00080 int* num_nodes_per_elem_out, 00081 long* num_elements_out, 00082 long* first_elem_id_out, 00083 mhdf_Status* status ) 00084 { 00085 FileHandle* file_ptr; 00086 hid_t elem_id, table_id; 00087 hsize_t dims[2]; 00088 API_BEGIN; 00089 00090 file_ptr = (FileHandle*)( file_handle ); 00091 if( !mhdf_check_valid_file( file_ptr, status ) ) return -1; 00092 00093 if( !num_nodes_per_elem_out || !num_elements_out || !first_elem_id_out ) 00094 { 00095 mhdf_setFail( status, "Invalid argument." ); 00096 return -1; 00097 } 00098 00099 elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status ); 00100 if( elem_id < 0 ) return -1; 00101 00102 table_id = mhdf_open_table2( elem_id, CONNECTIVITY_NAME, 2, dims, first_elem_id_out, status ); 00103 00104 H5Gclose( elem_id ); 00105 if( table_id < 0 ) return -1; 00106 00107 *num_elements_out = dims[0]; 00108 *num_nodes_per_elem_out = dims[1]; 00109 00110 file_ptr->open_handle_count++; 00111 mhdf_setOkay( status ); 00112 API_END_H( 1 ); 00113 return table_id; 00114 } 00115 00116 hid_t mhdf_openConnectivitySimple( mhdf_FileHandle file_handle, const char* elem_handle, mhdf_Status* status ) 00117 { 00118 FileHandle* file_ptr; 00119 hid_t elem_id, table_id; 00120 API_BEGIN; 00121 00122 file_ptr = (FileHandle*)( file_handle ); 00123 if( !mhdf_check_valid_file( file_ptr, status ) ) return -1; 00124 00125 elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status ); 00126 if( elem_id < 0 ) return -1; 00127 00128 table_id = mhdf_open_table_simple( elem_id, CONNECTIVITY_NAME, status ); 00129 00130 H5Gclose( elem_id ); 00131 if( table_id < 0 ) return -1; 00132 00133 file_ptr->open_handle_count++; 00134 mhdf_setOkay( status ); 00135 API_END_H( 1 ); 00136 return table_id; 00137 } 00138 00139 void mhdf_writeConnectivity( hid_t table_id, 00140 long offset, 00141 long count, 00142 hid_t hdf_integer_type, 00143 const void* nodes, 00144 mhdf_Status* status ) 00145 { 00146 API_BEGIN; 00147 mhdf_write_data( table_id, offset, count, hdf_integer_type, nodes, H5P_DEFAULT, status ); 00148 API_END; 00149 } 00150 void mhdf_writeConnectivityWithOpt( hid_t table_id, 00151 long offset, 00152 long count, 00153 hid_t hdf_integer_type, 00154 const void* nodes, 00155 hid_t prop, 00156 mhdf_Status* status ) 00157 { 00158 API_BEGIN; 00159 mhdf_write_data( table_id, offset, count, hdf_integer_type, nodes, prop, status ); 00160 API_END; 00161 } 00162 00163 void mhdf_readConnectivity( hid_t table_id, 00164 long offset, 00165 long count, 00166 hid_t hdf_integer_type, 00167 void* nodes, 00168 mhdf_Status* status ) 00169 { 00170 API_BEGIN; 00171 mhdf_read_data( table_id, offset, count, hdf_integer_type, nodes, H5P_DEFAULT, status ); 00172 API_END; 00173 } 00174 void mhdf_readConnectivityWithOpt( hid_t table_id, 00175 long offset, 00176 long count, 00177 hid_t hdf_integer_type, 00178 void* nodes, 00179 hid_t prop, 00180 mhdf_Status* status ) 00181 { 00182 API_BEGIN; 00183 mhdf_read_data( table_id, offset, count, hdf_integer_type, nodes, prop, status ); 00184 API_END; 00185 } 00186 00187 void mhdf_createPolyConnectivity( mhdf_FileHandle file_handle, 00188 const char* elem_type, 00189 long num_poly, 00190 long data_list_length, 00191 long* first_id_out, 00192 hid_t handles_out[2], 00193 mhdf_Status* status ) 00194 { 00195 FileHandle* file_ptr; 00196 hid_t elem_id, index_id, conn_id; 00197 hsize_t dim; 00198 long first_id; 00199 API_BEGIN; 00200 00201 file_ptr = (FileHandle*)( file_handle ); 00202 if( !mhdf_check_valid_file( file_ptr, status ) ) return; 00203 00204 if( num_poly <= 0 || data_list_length <= 0 || !first_id_out ) 00205 { 00206 mhdf_setFail( status, "Invalid argument." ); 00207 return; 00208 } 00209 00210 if( data_list_length < 3 * num_poly ) 00211 { 00212 /* Could check agains 4*num_poly, but allow degenerate polys 00213 (1 for count plus 2 dim-1 defining entities, where > 2 00214 defining entities is a normal poly, 2 defining entities 00215 is a degenerate poly and 1 defning entity is not valid.) 00216 */ 00217 00218 mhdf_setFail( status, 00219 "Invalid polygon data: data length of %ld is " 00220 "insufficient for %ld poly(gons/hedra).\n", 00221 data_list_length, num_poly ); 00222 return; 00223 } 00224 00225 elem_id = mhdf_elem_group_from_handle( file_ptr, elem_type, status ); 00226 if( elem_id < 0 ) return; 00227 00228 dim = (hsize_t)num_poly; 00229 index_id = mhdf_create_table( elem_id, POLY_INDEX_NAME, MHDF_INDEX_TYPE, 1, &dim, status ); 00230 if( index_id < 0 ) 00231 { 00232 H5Gclose( elem_id ); 00233 return; 00234 } 00235 00236 dim = (hsize_t)data_list_length; 00237 conn_id = mhdf_create_table( elem_id, CONNECTIVITY_NAME, file_ptr->id_type, 1, &dim, status ); 00238 H5Gclose( elem_id ); 00239 if( conn_id < 0 ) 00240 { 00241 H5Dclose( index_id ); 00242 return; 00243 } 00244 00245 first_id = file_ptr->max_id + 1; 00246 if( !mhdf_create_scalar_attrib( conn_id, START_ID_ATTRIB, H5T_NATIVE_LONG, &first_id, status ) ) 00247 { 00248 H5Dclose( index_id ); 00249 H5Dclose( conn_id ); 00250 return; 00251 } 00252 00253 *first_id_out = first_id; 00254 file_ptr->max_id += num_poly; 00255 if( !mhdf_write_max_id( file_ptr, status ) ) 00256 { 00257 H5Dclose( index_id ); 00258 H5Dclose( conn_id ); 00259 return; 00260 } 00261 file_ptr->open_handle_count++; 00262 mhdf_setOkay( status ); 00263 handles_out[0] = index_id; 00264 handles_out[1] = conn_id; 00265 API_END_H( 2 ); 00266 } 00267 00268 void mhdf_openPolyConnectivity( mhdf_FileHandle file_handle, 00269 const char* element_handle, 00270 long* num_poly_out, 00271 long* data_list_length_out, 00272 long* first_poly_id_out, 00273 hid_t handles_out[2], 00274 mhdf_Status* status ) 00275 { 00276 FileHandle* file_ptr; 00277 hid_t elem_id, table_id, index_id; 00278 hsize_t row_count; 00279 API_BEGIN; 00280 00281 file_ptr = (FileHandle*)( file_handle ); 00282 if( !mhdf_check_valid_file( file_ptr, status ) ) return; 00283 00284 if( !num_poly_out || !data_list_length_out || !first_poly_id_out ) 00285 { 00286 mhdf_setFail( status, "Invalid argument." ); 00287 return; 00288 } 00289 00290 elem_id = mhdf_elem_group_from_handle( file_ptr, element_handle, status ); 00291 if( elem_id < 0 ) return; 00292 00293 index_id = mhdf_open_table( elem_id, POLY_INDEX_NAME, 1, &row_count, status ); 00294 if( index_id < 0 ) 00295 { 00296 H5Gclose( elem_id ); 00297 return; 00298 } 00299 *num_poly_out = (int)row_count; 00300 00301 table_id = mhdf_open_table( elem_id, CONNECTIVITY_NAME, 1, &row_count, status ); 00302 00303 H5Gclose( elem_id ); 00304 if( table_id < 0 ) 00305 { 00306 H5Dclose( index_id ); 00307 return; 00308 } 00309 *data_list_length_out = (long)row_count; 00310 00311 if( !mhdf_read_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, first_poly_id_out, status ) ) 00312 { 00313 H5Dclose( table_id ); 00314 H5Dclose( index_id ); 00315 return; 00316 } 00317 00318 file_ptr->open_handle_count++; 00319 handles_out[0] = index_id; 00320 handles_out[1] = table_id; 00321 mhdf_setOkay( status ); 00322 API_END_H( 2 ); 00323 } 00324 00325 void mhdf_writePolyConnIndices( hid_t table_id, 00326 long offset, 00327 long count, 00328 hid_t hdf_integer_type, 00329 const void* index_list, 00330 mhdf_Status* status ) 00331 { 00332 API_BEGIN; 00333 mhdf_write_data( table_id, offset, count, hdf_integer_type, index_list, H5P_DEFAULT, status ); 00334 API_END; 00335 } 00336 void mhdf_writePolyConnIndicesWithOpt( hid_t table_id, 00337 long offset, 00338 long count, 00339 hid_t hdf_integer_type, 00340 const void* index_list, 00341 hid_t prop, 00342 mhdf_Status* status ) 00343 { 00344 API_BEGIN; 00345 mhdf_write_data( table_id, offset, count, hdf_integer_type, index_list, prop, status ); 00346 API_END; 00347 } 00348 00349 void mhdf_readPolyConnIndices( hid_t table_id, 00350 long offset, 00351 long count, 00352 hid_t hdf_integer_type, 00353 void* index_list, 00354 mhdf_Status* status ) 00355 { 00356 API_BEGIN; 00357 mhdf_read_data( table_id, offset, count, hdf_integer_type, index_list, H5P_DEFAULT, status ); 00358 API_END; 00359 } 00360 void mhdf_readPolyConnIndicesWithOpt( hid_t table_id, 00361 long offset, 00362 long count, 00363 hid_t hdf_integer_type, 00364 void* index_list, 00365 hid_t prop, 00366 mhdf_Status* status ) 00367 { 00368 API_BEGIN; 00369 mhdf_read_data( table_id, offset, count, hdf_integer_type, index_list, prop, status ); 00370 API_END; 00371 } 00372 00373 void mhdf_writePolyConnIDs( hid_t table_id, 00374 long offset, 00375 long count, 00376 hid_t hdf_integer_type, 00377 const void* id_list, 00378 mhdf_Status* status ) 00379 { 00380 API_BEGIN; 00381 mhdf_write_data( table_id, offset, count, hdf_integer_type, id_list, H5P_DEFAULT, status ); 00382 API_END; 00383 } 00384 void mhdf_writePolyConnIDsWithOpt( hid_t table_id, 00385 long offset, 00386 long count, 00387 hid_t hdf_integer_type, 00388 const void* id_list, 00389 hid_t prop, 00390 mhdf_Status* status ) 00391 { 00392 API_BEGIN; 00393 mhdf_write_data( table_id, offset, count, hdf_integer_type, id_list, prop, status ); 00394 API_END; 00395 } 00396 00397 void mhdf_readPolyConnIDs( hid_t table_id, 00398 long offset, 00399 long count, 00400 hid_t hdf_integer_type, 00401 void* id_list, 00402 mhdf_Status* status ) 00403 { 00404 API_BEGIN; 00405 mhdf_read_data( table_id, offset, count, hdf_integer_type, id_list, H5P_DEFAULT, status ); 00406 API_END; 00407 } 00408 void mhdf_readPolyConnIDsWithOpt( hid_t table_id, 00409 long offset, 00410 long count, 00411 hid_t hdf_integer_type, 00412 void* id_list, 00413 hid_t prop, 00414 mhdf_Status* status ) 00415 { 00416 API_BEGIN; 00417 mhdf_read_data( table_id, offset, count, hdf_integer_type, id_list, prop, status ); 00418 API_END; 00419 }