Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
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,
00073                              int dimension,
00074                              long num_nodes,
00075                              long* first_id_out,
00076                              mhdf_Status* status )
00077 {
00078     FileHandle* file_ptr = (FileHandle*)file_handle;
00079     hid_t table_id;
00080     hsize_t dims[2];
00081     long first_id;
00082     API_BEGIN;
00083 
00084     if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
00085 
00086     if( dimension < 1 )
00087     {
00088         mhdf_setFail( status, "Invalid argument: dimension = %d.", dimension );
00089         return -1;
00090     }
00091 
00092     dims[0]  = (hsize_t)num_nodes;
00093     dims[1]  = (hsize_t)dimension;
00094     table_id = mhdf_create_table( file_ptr->hdf_handle, NODE_COORD_PATH, H5T_NATIVE_DOUBLE, 2, dims, status );
00095     if( table_id < 0 ) return -1;
00096 
00097     first_id = file_ptr->max_id + 1;
00098     if( !mhdf_create_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, &first_id, status ) )
00099     {
00100         H5Dclose( table_id );
00101         return -1;
00102     }
00103 
00104     *first_id_out = first_id;
00105     file_ptr->max_id += num_nodes;
00106     if( !mhdf_write_max_id( file_ptr, status ) )
00107     {
00108         H5Dclose( table_id );
00109         return -1;
00110     }
00111     file_ptr->open_handle_count++;
00112     mhdf_setOkay( status );
00113 
00114     API_END_H( 1 );
00115     return table_id;
00116 }
00117 
00118 hid_t mhdf_openNodeCoords( mhdf_FileHandle file_handle,
00119                            long* num_nodes_out,
00120                            int* dimension_out,
00121                            long* first_id_out,
00122                            mhdf_Status* status )
00123 {
00124     FileHandle* file_ptr = (FileHandle*)file_handle;
00125     hid_t table_id;
00126     hsize_t dims[2];
00127     API_BEGIN;
00128 
00129     if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
00130 
00131     table_id = mhdf_open_table2( file_ptr->hdf_handle, NODE_COORD_PATH, 2, dims, first_id_out, status );
00132     if( table_id < 0 ) return -1;
00133 
00134     *num_nodes_out = dims[0];
00135     *dimension_out = dims[1];
00136     file_ptr->open_handle_count++;
00137     mhdf_setOkay( status );
00138     API_END_H( 1 );
00139     return table_id;
00140 }
00141 
00142 hid_t mhdf_openNodeCoordsSimple( mhdf_FileHandle file_handle, mhdf_Status* status )
00143 {
00144     FileHandle* file_ptr = (FileHandle*)file_handle;
00145     hid_t table_id;
00146     API_BEGIN;
00147 
00148     if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
00149 
00150     table_id = mhdf_open_table_simple( file_ptr->hdf_handle, NODE_COORD_PATH, status );
00151     if( table_id < 0 ) return -1;
00152 
00153     file_ptr->open_handle_count++;
00154     mhdf_setOkay( status );
00155     API_END_H( 1 );
00156     return table_id;
00157 }
00158 
00159 void mhdf_writeNodeCoords( hid_t table_id, long offset, long count, const double* coords, mhdf_Status* status )
00160 {
00161     API_BEGIN;
00162     mhdf_write_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
00163     API_END;
00164 }
00165 void mhdf_writeNodeCoordsWithOpt( hid_t table_id,
00166                                   long offset,
00167                                   long count,
00168                                   const double* coords,
00169                                   hid_t prop,
00170                                   mhdf_Status* status )
00171 {
00172     API_BEGIN;
00173     mhdf_write_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
00174     API_END;
00175 }
00176 
00177 void mhdf_readNodeCoords( hid_t table_id, long offset, long count, double* coords, mhdf_Status* status )
00178 {
00179     API_BEGIN;
00180     mhdf_read_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
00181     API_END;
00182 }
00183 void mhdf_readNodeCoordsWithOpt( hid_t table_id,
00184                                  long offset,
00185                                  long count,
00186                                  double* coords,
00187                                  hid_t prop,
00188                                  mhdf_Status* status )
00189 {
00190     API_BEGIN;
00191     mhdf_read_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
00192     API_END;
00193 }
00194 
00195 void mhdf_writeNodeCoord( hid_t table_id,
00196                           long offset,
00197                           long count,
00198                           int dimension,
00199                           const double* coords,
00200                           mhdf_Status* status )
00201 {
00202     API_BEGIN;
00203     mhdf_write_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
00204     API_END;
00205 }
00206 void mhdf_writeNodeCoordWithOpt( hid_t table_id,
00207                                  long offset,
00208                                  long count,
00209                                  int dimension,
00210                                  const double* coords,
00211                                  hid_t prop,
00212                                  mhdf_Status* status )
00213 {
00214     API_BEGIN;
00215     mhdf_write_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
00216     API_END;
00217 }
00218 
00219 void mhdf_readNodeCoord( hid_t table_id, long offset, long count, int dimension, double* coords, mhdf_Status* status )
00220 {
00221     API_BEGIN;
00222     mhdf_read_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
00223     API_END;
00224 }
00225 void mhdf_readNodeCoordWithOpt( hid_t table_id,
00226                                 long offset,
00227                                 long count,
00228                                 int dimension,
00229                                 double* coords,
00230                                 hid_t prop,
00231                                 mhdf_Status* status )
00232 {
00233     API_BEGIN;
00234     mhdf_read_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
00235     API_END;
00236 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines