Loading [MathJax]/extensions/tex2jax.js
Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
nodes.c
Go to the documentation of this file.
1 /** 2  * MOAB, a Mesh-Oriented datABase, is a software component for creating, 3  * storing and accessing finite element mesh data. 4  * 5  * Copyright 2004 Sandia Corporation. Under the terms of Contract 6  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 7  * retains certain rights in this software. 8  * 9  * This library is free software; you can redistribute it and/or 10  * modify it under the terms of the GNU Lesser General Public 11  * License as published by the Free Software Foundation; either 12  * version 2.1 of the License, or (at your option) any later version. 13  * 14  */ 15  16 #include <H5Tpublic.h> 17 #include <H5Dpublic.h> 18 #include <H5Ppublic.h> 19 #include <H5Gpublic.h> 20 #include "mhdf.h" 21 #include "status.h" 22 #include "names-and-paths.h" 23 #include "util.h" 24 #include "file-handle.h" 25  26 int mhdf_haveNodes( mhdf_FileHandle file, mhdf_Status* status ) 27 { 28  FileHandle* file_ptr = (FileHandle*)file; 29  hid_t root_id, node_id; 30  int result; 31  API_BEGIN; 32  33  if( !mhdf_check_valid_file( file_ptr, status ) ) return -1; 34  35 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1 36  root_id = H5Gopen2( file_ptr->hdf_handle, ROOT_GROUP, H5P_DEFAULT ); 37 #else 38  root_id = H5Gopen( file_ptr->hdf_handle, ROOT_GROUP ); 39 #endif 40  if( root_id < 0 ) 41  { 42  mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.", ROOT_GROUP ); 43  return -1; 44  } 45  46  result = mhdf_is_in_group( root_id, NODE_GROUP_NAME, status ); 47  if( result < 1 ) 48  { 49  H5Gclose( root_id ); 50  return result; 51  } 52  53 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1 54  node_id = H5Gopen2( root_id, NODE_GROUP_NAME, H5P_DEFAULT ); 55 #else 56  node_id = H5Gopen( root_id, NODE_GROUP_NAME ); 57 #endif 58  H5Gclose( root_id ); 59  if( node_id < 0 ) 60  { 61  mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.", NODE_GROUP ); 62  return -1; 63  } 64  65  result = mhdf_is_in_group( node_id, NODE_COORD_NAME, status ); 66  if( result >= 0 ) mhdf_setOkay( status ); 67  H5Gclose( node_id ); 68  API_END; 69  return result; 70 } 71  72 hid_t mhdf_createNodeCoords( mhdf_FileHandle file_handle, 73  int dimension, 74  long num_nodes, 75  long* first_id_out, 76  mhdf_Status* status ) 77 { 78  FileHandle* file_ptr = (FileHandle*)file_handle; 79  hid_t table_id; 80  hsize_t dims[2]; 81  long first_id; 82  API_BEGIN; 83  84  if( !mhdf_check_valid_file( file_ptr, status ) ) return -1; 85  86  if( dimension < 1 ) 87  { 88  mhdf_setFail( status, "Invalid argument: dimension = %d.", dimension ); 89  return -1; 90  } 91  92  dims[0] = (hsize_t)num_nodes; 93  dims[1] = (hsize_t)dimension; 94  table_id = mhdf_create_table( file_ptr->hdf_handle, NODE_COORD_PATH, H5T_NATIVE_DOUBLE, 2, dims, status ); 95  if( table_id < 0 ) return -1; 96  97  first_id = file_ptr->max_id + 1; 98  if( !mhdf_create_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, &first_id, status ) ) 99  { 100  H5Dclose( table_id ); 101  return -1; 102  } 103  104  *first_id_out = first_id; 105  file_ptr->max_id += num_nodes; 106  if( !mhdf_write_max_id( file_ptr, status ) ) 107  { 108  H5Dclose( table_id ); 109  return -1; 110  } 111  file_ptr->open_handle_count++; 112  mhdf_setOkay( status ); 113  114  API_END_H( 1 ); 115  return table_id; 116 } 117  118 hid_t mhdf_openNodeCoords( mhdf_FileHandle file_handle, 119  long* num_nodes_out, 120  int* dimension_out, 121  long* first_id_out, 122  mhdf_Status* status ) 123 { 124  FileHandle* file_ptr = (FileHandle*)file_handle; 125  hid_t table_id; 126  hsize_t dims[2]; 127  API_BEGIN; 128  129  if( !mhdf_check_valid_file( file_ptr, status ) ) return -1; 130  131  table_id = mhdf_open_table2( file_ptr->hdf_handle, NODE_COORD_PATH, 2, dims, first_id_out, status ); 132  if( table_id < 0 ) return -1; 133  134  *num_nodes_out = dims[0]; 135  *dimension_out = dims[1]; 136  file_ptr->open_handle_count++; 137  mhdf_setOkay( status ); 138  API_END_H( 1 ); 139  return table_id; 140 } 141  142 hid_t mhdf_openNodeCoordsSimple( mhdf_FileHandle file_handle, mhdf_Status* status ) 143 { 144  FileHandle* file_ptr = (FileHandle*)file_handle; 145  hid_t table_id; 146  API_BEGIN; 147  148  if( !mhdf_check_valid_file( file_ptr, status ) ) return -1; 149  150  table_id = mhdf_open_table_simple( file_ptr->hdf_handle, NODE_COORD_PATH, status ); 151  if( table_id < 0 ) return -1; 152  153  file_ptr->open_handle_count++; 154  mhdf_setOkay( status ); 155  API_END_H( 1 ); 156  return table_id; 157 } 158  159 void mhdf_writeNodeCoords( hid_t table_id, long offset, long count, const double* coords, mhdf_Status* status ) 160 { 161  API_BEGIN; 162  mhdf_write_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status ); 163  API_END; 164 } 165 void mhdf_writeNodeCoordsWithOpt( hid_t table_id, 166  long offset, 167  long count, 168  const double* coords, 169  hid_t prop, 170  mhdf_Status* status ) 171 { 172  API_BEGIN; 173  mhdf_write_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status ); 174  API_END; 175 } 176  177 void mhdf_readNodeCoords( hid_t table_id, long offset, long count, double* coords, mhdf_Status* status ) 178 { 179  API_BEGIN; 180  mhdf_read_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status ); 181  API_END; 182 } 183 void mhdf_readNodeCoordsWithOpt( hid_t table_id, 184  long offset, 185  long count, 186  double* coords, 187  hid_t prop, 188  mhdf_Status* status ) 189 { 190  API_BEGIN; 191  mhdf_read_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status ); 192  API_END; 193 } 194  195 void mhdf_writeNodeCoord( hid_t table_id, 196  long offset, 197  long count, 198  int dimension, 199  const double* coords, 200  mhdf_Status* status ) 201 { 202  API_BEGIN; 203  mhdf_write_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status ); 204  API_END; 205 } 206 void mhdf_writeNodeCoordWithOpt( hid_t table_id, 207  long offset, 208  long count, 209  int dimension, 210  const double* coords, 211  hid_t prop, 212  mhdf_Status* status ) 213 { 214  API_BEGIN; 215  mhdf_write_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status ); 216  API_END; 217 } 218  219 void mhdf_readNodeCoord( hid_t table_id, long offset, long count, int dimension, double* coords, mhdf_Status* status ) 220 { 221  API_BEGIN; 222  mhdf_read_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status ); 223  API_END; 224 } 225 void mhdf_readNodeCoordWithOpt( hid_t table_id, 226  long offset, 227  long count, 228  int dimension, 229  double* coords, 230  hid_t prop, 231  mhdf_Status* status ) 232 { 233  API_BEGIN; 234  mhdf_read_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status ); 235  API_END; 236 }