hdf5_tools.hpp 4.86 KB
Newer Older
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
/**********************************************************************
*                                                                     *
*  Copyright 2017 Max Planck Institute                                *
*                 for Dynamics and Self-Organization                  *
*                                                                     *
*  This file is part of bfps.                                         *
*                                                                     *
*  bfps is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU General Public License as published  *
*  by the Free Software Foundation, either version 3 of the License,  *
*  or (at your option) any later version.                             *
*                                                                     *
*  bfps is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of     *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *
*  GNU General Public License for more details.                       *
*                                                                     *
*  You should have received a copy of the GNU General Public License  *
*  along with bfps.  If not, see <http://www.gnu.org/licenses/>       *
*                                                                     *
* Contact: Cristian.Lalescu@ds.mpg.de                                 *
*                                                                     *
**********************************************************************/



#ifndef HDF5_TOOLS_HPP
#define HDF5_TOOLS_HPP

30
31
#include <vector>
#include <hdf5.h>
32
33
34
35
#include "base.hpp"

namespace hdf5_tools
{
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
    // see https://support.hdfgroup.org/HDF5/doc/H5.user/Datatypes.html
    template <typename data_type> hid_t hdf5_type_id();
    template <> hid_t hdf5_type_id<char>()
    {
        return H5T_NATIVE_CHAR;
    }
    template <> hid_t hdf5_type_id<signed char>()
    {
        return H5T_NATIVE_SCHAR;
    }
    template <> hid_t hdf5_type_id<unsigned char>()
    {
        return H5T_NATIVE_UCHAR;
    }
    template <> hid_t hdf5_type_id<short>()
    {
        return H5T_NATIVE_SHORT;
    }
    template <> hid_t hdf5_type_id<unsigned short>()
    {
        return H5T_NATIVE_USHORT;
    }
    template <> hid_t hdf5_type_id<int>()
    {
        return H5T_NATIVE_INT;
    }
    template <> hid_t hdf5_type_id<unsigned>()
    {
        return H5T_NATIVE_UINT;
    }
    template <> hid_t hdf5_type_id<long>()
    {
        return H5T_NATIVE_LONG;
    }
    template <> hid_t hdf5_type_id<unsigned long>()
    {
        return H5T_NATIVE_ULONG;
    }
    template <> hid_t hdf5_type_id<long long>()
    {
        return H5T_NATIVE_LLONG;
    }
    template <> hid_t hdf5_type_id<unsigned long long>()
    {
        return H5T_NATIVE_ULLONG;
    }
    template <> hid_t hdf5_type_id<float>()
    {
        return H5T_NATIVE_FLOAT;
    }
    template <> hid_t hdf5_type_id<double>()
    {
        return H5T_NATIVE_DOUBLE;
    }
    template <> hid_t hdf5_type_id<long double>()
    {
        return H5T_NATIVE_LDOUBLE;
    }

95
96
97
98
99
100
101
102
103
104
105
106
107
    int grow_single_dataset(
            hid_t dset,
            int tincrement);

    herr_t grow_dataset_visitor(
        hid_t o_id,
        const char *name,
        const H5O_info_t *info,
        void *op_data);

    int grow_file_datasets(
            const hid_t stat_file,
            const std::string group_name,
108
            int tincrement);
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
    int require_size_single_dataset(
            hid_t dset,
            int tincrement);

    herr_t require_size_dataset_visitor(
        hid_t o_id,
        const char *name,
        const H5O_info_t *info,
        void *op_data);

    int require_size_file_datasets(
            const hid_t stat_file,
            const std::string group_name,
            int tincrement);

125
126
127
128
129
130
131
132
133
134
135
136
    template <typename number>
    std::vector<number> read_vector(
            const hid_t group,
            const std::string dset_name);

    template <typename number>
    std::vector<number> read_vector_with_single_rank(
            const int myrank,
            const int rank_to_use,
            const MPI_Comm COMM,
            const hid_t group,
            const std::string dset_name);
Cristian Lalescu's avatar
Cristian Lalescu committed
137
138
139
140

    std::string read_string(
            const hid_t group,
            const std::string dset_name);
Cristian Lalescu's avatar
Cristian Lalescu committed
141
142
143
144
145

    template <typename number>
    number read_value(
            const hid_t group,
            const std::string dset_name);
146
147
148
149
150
151

    template <typename number>
    int write_value_with_single_rank(
            const hid_t group,
            const std::string dset_name,
            const number value);
152
153
154
155
156
157

    template <class partsize_t>
    int write_particle_ID_pairs_with_single_rank(
            const std::vector<partsize_t> v,
            const hid_t group,
            const std::string dset_name);
158
159
160
161
}

#endif//HDF5_TOOLS_HPP