MOAB: Mesh Oriented datABase  (version 5.3.1)
nodes.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 <H5Dpublic.h>
00018 #include <H5Ppublic.h>
00019 #include <H5Gpublic.h>
00020 #include "mhdf.h"
00021 #include "status.h"
00022 #include "names-and-paths.h"
00023 #include "util.h"
00024 #include "file-handle.h"
00025 
00026 int mhdf_haveNodes( mhdf_FileHandle file, mhdf_Status* status )
00027 {
00028     FileHandle* file_ptr = (FileHandle*)file;
00029     hid_t       root_id, node_id;
00030     int         result;
00031     API_BEGIN;
00032 
00033     if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
00034 
00035 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
00036     root_id = H5Gopen2( file_ptr->hdf_handle, ROOT_GROUP, H5P_DEFAULT );
00037 #else
00038     root_id = H5Gopen( file_ptr->hdf_handle, ROOT_GROUP );
00039 #endif
00040     if( root_id < 0 )
00041     {
00042         mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.", ROOT_GROUP );
00043         return -1;
00044     }
00045 
00046     result = mhdf_is_in_group( root_id, NODE_GROUP_NAME, status );
00047     if( result < 1 )
00048     {
00049         H5Gclose( root_id );
00050         return result;
00051     }
00052 
00053 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
00054     node_id = H5Gopen2( root_id, NODE_GROUP_NAME, H5P_DEFAULT );
00055 #else
00056     node_id = H5Gopen( root_id, NODE_GROUP_NAME );
00057 #endif
00058     H5Gclose( root_id );
00059     if( node_id < 0 )
00060     {
00061         mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.", NODE_GROUP );
00062         return -1;
00063     }
00064 
00065     result = mhdf_is_in_group( node_id, NODE_COORD_NAME, status );
00066     if( result >= 0 ) mhdf_setOkay( status );
00067     H5Gclose( node_id );
00068     API_END;
00069     return result;
00070 }
00071 
00072 hid_t mhdf_createNodeCoords( mhdf_FileHandle file_handle, int dimension, long num_nodes, long* first_id_out,
00073                              mhdf_Status* status )
00074 {
00075     FileHandle* file_ptr = (FileHandle*)file_handle;
00076     hid_t       table_id;
00077     hsize_t     dims[ 2 ];
00078     long        first_id;
00079     API_BEGIN;
00080 
00081     if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
00082 
00083     if( dimension < 1 )
00084     {
00085         mhdf_setFail( status, "Invalid argument: dimension = %d.", dimension );
00086         return -1;
00087     }
00088 
00089     dims[ 0 ] = (hsize_t)num_nodes;
00090     dims[ 1 ] = (hsize_t)dimension;
00091     table_id = mhdf_create_table( file_ptr->hdf_handle, NODE_COORD_PATH, H5T_NATIVE_DOUBLE, 2, dims, status );
00092     if( table_id < 0 ) return -1;
00093 
00094     first_id = file_ptr->max_id + 1;
00095     if( !mhdf_create_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, &first_id, status ) )
00096     {
00097         H5Dclose( table_id );
00098         return -1;
00099     }
00100 
00101     *first_id_out = first_id;
00102     file_ptr->max_id += num_nodes;
00103     if( !mhdf_write_max_id( file_ptr, status ) )
00104     {
00105         H5Dclose( table_id );
00106         return -1;
00107     }
00108     file_ptr->open_handle_count++;
00109     mhdf_setOkay( status );
00110 
00111     API_END_H( 1 );
00112     return table_id;
00113 }
00114 
00115 hid_t mhdf_openNodeCoords( mhdf_FileHandle file_handle, long* num_nodes_out, int* dimension_out, long* first_id_out,
00116                            mhdf_Status* status )
00117 {
00118     FileHandle* file_ptr = (FileHandle*)file_handle;
00119     hid_t       table_id;
00120     hsize_t     dims[ 2 ];
00121     API_BEGIN;
00122 
00123     if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
00124 
00125     table_id = mhdf_open_table2( file_ptr->hdf_handle, NODE_COORD_PATH, 2, dims, first_id_out, status );
00126     if( table_id < 0 ) return -1;
00127 
00128     *num_nodes_out = dims[ 0 ];
00129     *dimension_out = dims[ 1 ];
00130     file_ptr->open_handle_count++;
00131     mhdf_setOkay( status );
00132     API_END_H( 1 );
00133     return table_id;
00134 }
00135 
00136 hid_t mhdf_openNodeCoordsSimple( mhdf_FileHandle file_handle, mhdf_Status* status )
00137 {
00138     FileHandle* file_ptr = (FileHandle*)file_handle;
00139     hid_t       table_id;
00140     API_BEGIN;
00141 
00142     if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
00143 
00144     table_id = mhdf_open_table_simple( file_ptr->hdf_handle, NODE_COORD_PATH, status );
00145     if( table_id < 0 ) return -1;
00146 
00147     file_ptr->open_handle_count++;
00148     mhdf_setOkay( status );
00149     API_END_H( 1 );
00150     return table_id;
00151 }
00152 
00153 void mhdf_writeNodeCoords( hid_t table_id, long offset, long count, const double* coords, mhdf_Status* status )
00154 {
00155     API_BEGIN;
00156     mhdf_write_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
00157     API_END;
00158 }
00159 void mhdf_writeNodeCoordsWithOpt( hid_t table_id, long offset, long count, const double* coords, hid_t prop,
00160                                   mhdf_Status* status )
00161 {
00162     API_BEGIN;
00163     mhdf_write_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
00164     API_END;
00165 }
00166 
00167 void mhdf_readNodeCoords( hid_t table_id, long offset, long count, double* coords, mhdf_Status* status )
00168 {
00169     API_BEGIN;
00170     mhdf_read_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
00171     API_END;
00172 }
00173 void mhdf_readNodeCoordsWithOpt( hid_t table_id, long offset, long count, double* coords, hid_t prop,
00174                                  mhdf_Status* status )
00175 {
00176     API_BEGIN;
00177     mhdf_read_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
00178     API_END;
00179 }
00180 
00181 void mhdf_writeNodeCoord( hid_t table_id, long offset, long count, int dimension, const double* coords,
00182                           mhdf_Status* status )
00183 {
00184     API_BEGIN;
00185     mhdf_write_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
00186     API_END;
00187 }
00188 void mhdf_writeNodeCoordWithOpt( hid_t table_id, long offset, long count, int dimension, const double* coords,
00189                                  hid_t prop, mhdf_Status* status )
00190 {
00191     API_BEGIN;
00192     mhdf_write_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
00193     API_END;
00194 }
00195 
00196 void mhdf_readNodeCoord( hid_t table_id, long offset, long count, int dimension, double* coords, mhdf_Status* status )
00197 {
00198     API_BEGIN;
00199     mhdf_read_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
00200     API_END;
00201 }
00202 void mhdf_readNodeCoordWithOpt( hid_t table_id, long offset, long count, int dimension, double* coords, hid_t prop,
00203                                 mhdf_Status* status )
00204 {
00205     API_BEGIN;
00206     mhdf_read_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
00207     API_END;
00208 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines