MOAB: Mesh Oriented datABase  (version 5.4.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     {
00079         table_id = mhdf_create_table( file_ptr->hdf_handle, NODE_ADJCY_PATH, file_ptr->id_type, 1, &dim, status );
00080     }
00081     else
00082     {
00083         elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
00084         if( elem_id < 0 ) return -1;
00085 
00086         table_id = mhdf_create_table( elem_id, ADJACENCY_NAME, file_ptr->id_type, 1, &dim, status );
00087         H5Gclose( elem_id );
00088     }
00089 
00090     API_END_H( 1 );
00091     return table_id;
00092 }
00093 
00094 hid_t mhdf_openAdjacency( mhdf_FileHandle file, const char* elem_handle, long* adj_list_size_out, mhdf_Status* status )
00095 
00096 {
00097     FileHandle* file_ptr;
00098     hid_t elem_id, table_id;
00099     hsize_t dim;
00100     API_BEGIN;
00101 
00102     file_ptr = (FileHandle*)( file );
00103     if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
00104 
00105     if( !adj_list_size_out )
00106     {
00107         mhdf_setFail( status, "Invalid argument.\n" );
00108         return -1;
00109     }
00110 
00111     if( elem_handle == mhdf_node_type_handle() )
00112     {
00113         table_id = mhdf_open_table( file_ptr->hdf_handle, NODE_ADJCY_PATH, 1, &dim, status );
00114     }
00115     else
00116     {
00117         elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
00118         if( elem_id < 0 ) return -1;
00119         table_id = mhdf_open_table( elem_id, ADJACENCY_NAME, 1, &dim, status );
00120         H5Gclose( elem_id );
00121     }
00122 
00123     *adj_list_size_out = (long)dim;
00124     API_END_H( 1 );
00125     return table_id;
00126 }
00127 
00128 void mhdf_writeAdjacency( hid_t table_id, long offset, long count, hid_t type, const void* data, mhdf_Status* status )
00129 {
00130     API_BEGIN;
00131     mhdf_write_data( table_id, offset, count, type, data, H5P_DEFAULT, status );
00132     API_END;
00133 }
00134 
00135 void mhdf_writeAdjacencyWithOpt( hid_t table_id,
00136                                  long offset,
00137                                  long count,
00138                                  hid_t type,
00139                                  const void* data,
00140                                  hid_t prop,
00141                                  mhdf_Status* status )
00142 {
00143     API_BEGIN;
00144     mhdf_write_data( table_id, offset, count, type, data, prop, status );
00145     API_END;
00146 }
00147 
00148 void mhdf_readAdjacency( hid_t table_id, long offset, long count, hid_t type, void* data, mhdf_Status* status )
00149 {
00150     API_BEGIN;
00151     mhdf_read_data( table_id, offset, count, type, data, H5P_DEFAULT, status );
00152     API_END;
00153 }
00154 void mhdf_readAdjacencyWithOpt( hid_t table_id,
00155                                 long offset,
00156                                 long count,
00157                                 hid_t type,
00158                                 void* data,
00159                                 hid_t prop,
00160                                 mhdf_Status* status )
00161 {
00162     API_BEGIN;
00163     mhdf_read_data( table_id, offset, count, type, data, prop, status );
00164     API_END;
00165 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines