MOAB: Mesh Oriented datABase  (version 5.2.1)
adjacency.c
Go to the documentation of this file.
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 <H5Gpublic.h>
00018 #include <H5Ppublic.h>
00019 #include "mhdf.h"
00020 #include "util.h"
00021 #include "file-handle.h"
00022 #include "status.h"
00023 #include "names-and-paths.h"
00024 
00025 int mhdf_haveAdjacency( mhdf_FileHandle file, const char* elem_group, mhdf_Status* status )
00026 {
00027     FileHandle* file_ptr;
00028     hid_t       elem_id;
00029     int         result;
00030     API_BEGIN;
00031 
00032     file_ptr = (FileHandle*)( file );
00033     if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
00034 
00035     if( elem_group == mhdf_node_type_handle( ) )
00036     {
00037 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
00038         elem_id = H5Gopen( file_ptr->hdf_handle, NODE_GROUP, H5P_DEFAULT );
00039 #else
00040         elem_id = H5Gopen( file_ptr->hdf_handle, NODE_GROUP );
00041 #endif
00042         if( elem_id < 0 )
00043         {
00044             mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.\n", NODE_GROUP );
00045             return -1;
00046         }
00047     }
00048     else
00049     {
00050         elem_id = mhdf_elem_group_from_handle( file_ptr, elem_group, status );
00051         if( elem_id < 0 ) return -1;
00052     }
00053 
00054     result = mhdf_is_in_group( elem_id, ADJACENCY_NAME, status );
00055     H5Gclose( elem_id );
00056     mhdf_setOkay( status );
00057     API_END;
00058     return result;
00059 }
00060 
00061 hid_t mhdf_createAdjacency( mhdf_FileHandle file, const char* elem_handle, long adj_list_size, mhdf_Status* status )
00062 {
00063     FileHandle* file_ptr;
00064     hid_t       elem_id, table_id;
00065     hsize_t     dim = (hsize_t)adj_list_size;
00066     API_BEGIN;
00067 
00068     file_ptr = (FileHandle*)( file );
00069     if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
00070 
00071     if( adj_list_size < 1 )
00072     {
00073         mhdf_setFail( status, "Invalid argument.\n" );
00074         return -1;
00075     }
00076 
00077     if( elem_handle == mhdf_node_type_handle( ) )
00078     { table_id = mhdf_create_table( file_ptr->hdf_handle, NODE_ADJCY_PATH, file_ptr->id_type, 1, &dim, status ); }
00079     else
00080     {
00081         elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
00082         if( elem_id < 0 ) return -1;
00083 
00084         table_id = mhdf_create_table( elem_id, ADJACENCY_NAME, file_ptr->id_type, 1, &dim, status );
00085         H5Gclose( elem_id );
00086     }
00087 
00088     API_END_H( 1 );
00089     return table_id;
00090 }
00091 
00092 hid_t mhdf_openAdjacency( mhdf_FileHandle file, const char* elem_handle, long* adj_list_size_out, mhdf_Status* status )
00093 
00094 {
00095     FileHandle* file_ptr;
00096     hid_t       elem_id, table_id;
00097     hsize_t     dim;
00098     API_BEGIN;
00099 
00100     file_ptr = (FileHandle*)( file );
00101     if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
00102 
00103     if( !adj_list_size_out )
00104     {
00105         mhdf_setFail( status, "Invalid argument.\n" );
00106         return -1;
00107     }
00108 
00109     if( elem_handle == mhdf_node_type_handle( ) )
00110     { table_id = mhdf_open_table( file_ptr->hdf_handle, NODE_ADJCY_PATH, 1, &dim, status ); }
00111     else
00112     {
00113         elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
00114         if( elem_id < 0 ) return -1;
00115         table_id = mhdf_open_table( elem_id, ADJACENCY_NAME, 1, &dim, status );
00116         H5Gclose( elem_id );
00117     }
00118 
00119     *adj_list_size_out = (long)dim;
00120     API_END_H( 1 );
00121     return table_id;
00122 }
00123 
00124 void mhdf_writeAdjacency( hid_t table_id, long offset, long count, hid_t type, const void* data, mhdf_Status* status )
00125 {
00126     API_BEGIN;
00127     mhdf_write_data( table_id, offset, count, type, data, H5P_DEFAULT, status );
00128     API_END;
00129 }
00130 
00131 void mhdf_writeAdjacencyWithOpt( hid_t table_id, long offset, long count, hid_t type, const void* data, hid_t prop,
00132                                  mhdf_Status* status )
00133 {
00134     API_BEGIN;
00135     mhdf_write_data( table_id, offset, count, type, data, prop, status );
00136     API_END;
00137 }
00138 
00139 void mhdf_readAdjacency( hid_t table_id, long offset, long count, hid_t type, void* data, mhdf_Status* status )
00140 {
00141     API_BEGIN;
00142     mhdf_read_data( table_id, offset, count, type, data, H5P_DEFAULT, status );
00143     API_END;
00144 }
00145 void mhdf_readAdjacencyWithOpt( hid_t table_id, long offset, long count, hid_t type, void* data, hid_t prop,
00146                                 mhdf_Status* status )
00147 {
00148     API_BEGIN;
00149     mhdf_read_data( table_id, offset, count, type, data, prop, status );
00150     API_END;
00151 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines