Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
adjacency.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 <H5Gpublic.h>
18 #include <H5Ppublic.h>
19 #include "mhdf.h"
20 #include "util.h"
21 #include "file-handle.h"
22 #include "status.h"
23 #include "names-and-paths.h"
24 
25 int mhdf_haveAdjacency( mhdf_FileHandle file, const char* elem_group, mhdf_Status* status )
26 {
27  FileHandle* file_ptr;
28  hid_t elem_id;
29  int result;
30  API_BEGIN;
31 
32  file_ptr = (FileHandle*)( file );
33  if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
34 
35  if( elem_group == mhdf_node_type_handle() )
36  {
37 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
38  elem_id = H5Gopen( file_ptr->hdf_handle, NODE_GROUP, H5P_DEFAULT );
39 #else
40  elem_id = H5Gopen( file_ptr->hdf_handle, NODE_GROUP );
41 #endif
42  if( elem_id < 0 )
43  {
44  mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.\n", NODE_GROUP );
45  return -1;
46  }
47  }
48  else
49  {
50  elem_id = mhdf_elem_group_from_handle( file_ptr, elem_group, status );
51  if( elem_id < 0 ) return -1;
52  }
53 
54  result = mhdf_is_in_group( elem_id, ADJACENCY_NAME, status );
55  H5Gclose( elem_id );
56  mhdf_setOkay( status );
57  API_END;
58  return result;
59 }
60 
61 hid_t mhdf_createAdjacency( mhdf_FileHandle file, const char* elem_handle, long adj_list_size, mhdf_Status* status )
62 {
63  FileHandle* file_ptr;
64  hid_t elem_id, table_id;
65  hsize_t dim = (hsize_t)adj_list_size;
66  API_BEGIN;
67 
68  file_ptr = (FileHandle*)( file );
69  if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
70 
71  if( adj_list_size < 1 )
72  {
73  mhdf_setFail( status, "Invalid argument.\n" );
74  return -1;
75  }
76 
77  if( elem_handle == mhdf_node_type_handle() )
78  {
79  table_id = mhdf_create_table( file_ptr->hdf_handle, NODE_ADJCY_PATH, file_ptr->id_type, 1, &dim, status );
80  }
81  else
82  {
83  elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
84  if( elem_id < 0 ) return -1;
85 
86  table_id = mhdf_create_table( elem_id, ADJACENCY_NAME, file_ptr->id_type, 1, &dim, status );
87  H5Gclose( elem_id );
88  }
89 
90  API_END_H( 1 );
91  return table_id;
92 }
93 
94 hid_t mhdf_openAdjacency( mhdf_FileHandle file, const char* elem_handle, long* adj_list_size_out, mhdf_Status* status )
95 
96 {
97  FileHandle* file_ptr;
98  hid_t elem_id, table_id;
99  hsize_t dim;
100  API_BEGIN;
101 
102  file_ptr = (FileHandle*)( file );
103  if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
104 
105  if( !adj_list_size_out )
106  {
107  mhdf_setFail( status, "Invalid argument.\n" );
108  return -1;
109  }
110 
111  if( elem_handle == mhdf_node_type_handle() )
112  {
113  table_id = mhdf_open_table( file_ptr->hdf_handle, NODE_ADJCY_PATH, 1, &dim, status );
114  }
115  else
116  {
117  elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
118  if( elem_id < 0 ) return -1;
119  table_id = mhdf_open_table( elem_id, ADJACENCY_NAME, 1, &dim, status );
120  H5Gclose( elem_id );
121  }
122 
123  *adj_list_size_out = (long)dim;
124  API_END_H( 1 );
125  return table_id;
126 }
127 
128 void mhdf_writeAdjacency( hid_t table_id, long offset, long count, hid_t type, const void* data, mhdf_Status* status )
129 {
130  API_BEGIN;
131  mhdf_write_data( table_id, offset, count, type, data, H5P_DEFAULT, status );
132  API_END;
133 }
134 
135 void mhdf_writeAdjacencyWithOpt( hid_t table_id,
136  long offset,
137  long count,
138  hid_t type,
139  const void* data,
140  hid_t prop,
141  mhdf_Status* status )
142 {
143  API_BEGIN;
144  mhdf_write_data( table_id, offset, count, type, data, prop, status );
145  API_END;
146 }
147 
148 void mhdf_readAdjacency( hid_t table_id, long offset, long count, hid_t type, void* data, mhdf_Status* status )
149 {
150  API_BEGIN;
151  mhdf_read_data( table_id, offset, count, type, data, H5P_DEFAULT, status );
152  API_END;
153 }
154 void mhdf_readAdjacencyWithOpt( hid_t table_id,
155  long offset,
156  long count,
157  hid_t type,
158  void* data,
159  hid_t prop,
160  mhdf_Status* status )
161 {
162  API_BEGIN;
163  mhdf_read_data( table_id, offset, count, type, data, prop, status );
164  API_END;
165 }