1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/**
 * MOAB, a Mesh-Oriented datABase, is a software component for creating,
 * storing and accessing finite element mesh data.
 *
 * Copyright 2004 Sandia Corporation.  Under the terms of Contract
 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
 * retains certain rights in this software.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 */

#include <H5Tpublic.h>
#include <H5Dpublic.h>
#include <H5Ppublic.h>
#include <H5Gpublic.h>
#include "mhdf.h"
#include "status.h"
#include "names-and-paths.h"
#include "util.h"
#include "file-handle.h"

int mhdf_haveNodes( mhdf_FileHandle file, mhdf_Status* status )
{
    FileHandle* file_ptr = (FileHandle*)file;
    hid_t root_id, node_id;
    int result;
    API_BEGIN;

    if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;

#if defined( H5Gopen_vers ) && H5Gopen_vers > 1
    root_id = H5Gopen2( file_ptr->hdf_handle, ROOT_GROUP, H5P_DEFAULT );
#else
    root_id = H5Gopen( file_ptr->hdf_handle, ROOT_GROUP );
#endif
    if( root_id < 0 )
    {
        mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.", ROOT_GROUP );
        return -1;
    }

    result = mhdf_is_in_group( root_id, NODE_GROUP_NAME, status );
    if( result < 1 )
    {
        H5Gclose( root_id );
        return result;
    }

#if defined( H5Gopen_vers ) && H5Gopen_vers > 1
    node_id = H5Gopen2( root_id, NODE_GROUP_NAME, H5P_DEFAULT );
#else
    node_id = H5Gopen( root_id, NODE_GROUP_NAME );
#endif
    H5Gclose( root_id );
    if( node_id < 0 )
    {
        mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.", NODE_GROUP );
        return -1;
    }

    result = mhdf_is_in_group( node_id, NODE_COORD_NAME, status );
    if( result >= 0 ) mhdf_setOkay( status );
    H5Gclose( node_id );
    API_END;
    return result;
}

hid_t mhdf_createNodeCoords( mhdf_FileHandle file_handle,
                             int dimension,
                             long num_nodes,
                             long* first_id_out,
                             mhdf_Status* status )
{
    FileHandle* file_ptr = (FileHandle*)file_handle;
    hid_t table_id;
    hsize_t dims[2];
    long first_id;
    API_BEGIN;

    if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;

    if( dimension < 1 )
    {
        mhdf_setFail( status, "Invalid argument: dimension = %d.", dimension );
        return -1;
    }

    dims[0]  = (hsize_t)num_nodes;
    dims[1]  = (hsize_t)dimension;
    table_id = mhdf_create_table( file_ptr->hdf_handle, NODE_COORD_PATH, H5T_NATIVE_DOUBLE, 2, dims, status );
    if( table_id < 0 ) return -1;

    first_id = file_ptr->max_id + 1;
    if( !mhdf_create_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, &first_id, status ) )
    {
        H5Dclose( table_id );
        return -1;
    }

    *first_id_out = first_id;
    file_ptr->max_id += num_nodes;
    if( !mhdf_write_max_id( file_ptr, status ) )
    {
        H5Dclose( table_id );
        return -1;
    }
    file_ptr->open_handle_count++;
    mhdf_setOkay( status );

    API_END_H( 1 );
    return table_id;
}

hid_t mhdf_openNodeCoords( mhdf_FileHandle file_handle,
                           long* num_nodes_out,
                           int* dimension_out,
                           long* first_id_out,
                           mhdf_Status* status )
{
    FileHandle* file_ptr = (FileHandle*)file_handle;
    hid_t table_id;
    hsize_t dims[2];
    API_BEGIN;

    if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;

    table_id = mhdf_open_table2( file_ptr->hdf_handle, NODE_COORD_PATH, 2, dims, first_id_out, status );
    if( table_id < 0 ) return -1;

    *num_nodes_out = dims[0];
    *dimension_out = dims[1];
    file_ptr->open_handle_count++;
    mhdf_setOkay( status );
    API_END_H( 1 );
    return table_id;
}

hid_t mhdf_openNodeCoordsSimple( mhdf_FileHandle file_handle, mhdf_Status* status )
{
    FileHandle* file_ptr = (FileHandle*)file_handle;
    hid_t table_id;
    API_BEGIN;

    if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;

    table_id = mhdf_open_table_simple( file_ptr->hdf_handle, NODE_COORD_PATH, status );
    if( table_id < 0 ) return -1;

    file_ptr->open_handle_count++;
    mhdf_setOkay( status );
    API_END_H( 1 );
    return table_id;
}

void mhdf_writeNodeCoords( hid_t table_id, long offset, long count, const double* coords, mhdf_Status* status )
{
    API_BEGIN;
    mhdf_write_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
    API_END;
}
void mhdf_writeNodeCoordsWithOpt( hid_t table_id,
                                  long offset,
                                  long count,
                                  const double* coords,
                                  hid_t prop,
                                  mhdf_Status* status )
{
    API_BEGIN;
    mhdf_write_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
    API_END;
}

void mhdf_readNodeCoords( hid_t table_id, long offset, long count, double* coords, mhdf_Status* status )
{
    API_BEGIN;
    mhdf_read_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
    API_END;
}
void mhdf_readNodeCoordsWithOpt( hid_t table_id,<--- The function 'mhdf_readNodeCoordsWithOpt' is never used.
                                 long offset,
                                 long count,
                                 double* coords,
                                 hid_t prop,
                                 mhdf_Status* status )
{
    API_BEGIN;
    mhdf_read_data( table_id, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
    API_END;
}

void mhdf_writeNodeCoord( hid_t table_id,<--- The function 'mhdf_writeNodeCoord' is never used.
                          long offset,
                          long count,
                          int dimension,
                          const double* coords,
                          mhdf_Status* status )
{
    API_BEGIN;
    mhdf_write_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
    API_END;
}
void mhdf_writeNodeCoordWithOpt( hid_t table_id,<--- The function 'mhdf_writeNodeCoordWithOpt' is never used.
                                 long offset,
                                 long count,
                                 int dimension,
                                 const double* coords,
                                 hid_t prop,
                                 mhdf_Status* status )
{
    API_BEGIN;
    mhdf_write_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
    API_END;
}

void mhdf_readNodeCoord( hid_t table_id, long offset, long count, int dimension, double* coords, mhdf_Status* status )<--- The function 'mhdf_readNodeCoord' is never used.
{
    API_BEGIN;
    mhdf_read_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, H5P_DEFAULT, status );
    API_END;
}
void mhdf_readNodeCoordWithOpt( hid_t table_id,<--- The function 'mhdf_readNodeCoordWithOpt' is never used.
                                long offset,
                                long count,
                                int dimension,
                                double* coords,
                                hid_t prop,
                                mhdf_Status* status )
{
    API_BEGIN;
    mhdf_read_column( table_id, dimension, offset, count, H5T_NATIVE_DOUBLE, coords, prop, status );
    API_END;
}