GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ls-hdf5.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2003-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_ls_hdf5_h)
24 #define octave_ls_hdf5_h 1
25 
26 #include "octave-config.h"
27 
28 #include <iostream>
29 
30 #include "oct-hdf5-types.h"
31 #include "ov.h"
32 
33 // first, we need to define our own dummy stream subclass, since
34 // HDF5 needs to do its own file i/o
35 
36 // hdf5_fstreambase is used for both input and output streams, modeled
37 // on the fstreambase class in <fstream.h>
38 
39 class hdf5_fstreambase : virtual public std::ios
40 {
41 public:
42 
43  // HDF5 uses an "id" to refer to an open file
45 
46  // keep track of current item index in the file
48 
50 
52 
53  hdf5_fstreambase (const char *name, int mode, int /* prot */ = 0);
54 
55  void close (void);
56 
57  void open (const char *name, int mode, int);
58 };
59 
60 // input and output streams, subclassing istream and ostream
61 // so that we can pass them for stream parameters in the functions below.
62 
63 class hdf5_ifstream : public hdf5_fstreambase, public std::istream
64 {
65 public:
66 
67  hdf5_ifstream () : hdf5_fstreambase (), std::istream (nullptr) { }
68 
69  hdf5_ifstream (const char *name, int mode = std::ios::in | std::ios::binary,
70  int prot = 0)
71  : hdf5_fstreambase (name, mode, prot), std::istream (nullptr) { }
72 
73  void open (const char *name, int mode = std::ios::in | std::ios::binary,
74  int prot = 0)
75  { hdf5_fstreambase::open (name, mode, prot); }
76 };
77 
78 class hdf5_ofstream : public hdf5_fstreambase, public std::ostream
79 {
80 public:
81 
82  hdf5_ofstream () : hdf5_fstreambase (), std::ostream (nullptr) { }
83 
84  hdf5_ofstream (const char *name, int mode = std::ios::out | std::ios::binary,
85  int prot = 0)
86  : hdf5_fstreambase (name, mode, prot), std::ostream (nullptr) { }
87 
88  void open (const char *name, int mode = std::ios::out | std::ios::binary,
89  int prot = 0)
90  { hdf5_fstreambase::open (name, mode, prot); }
91 };
92 
93 // Callback data structure for passing data to hdf5_read_next_data, below.
94 
95 struct
97 {
99  : name (), global (false), tc (), doc () { }
100 
101  // the following fields are set by hdf5_read_data on successful return:
102 
103  // the name of the variable
105 
106  // whether it is global
107  bool global;
108 
109  // the value of the variable, in Octave form
111 
112  // a documentation string (NULL if none)
114 };
115 
116 extern OCTINTERP_API octave_hdf5_id
118 
119 extern OCTINTERP_API octave_hdf5_id
121 
122 extern OCTINTERP_API bool
124 
125 extern OCTINTERP_API octave_hdf5_err
126 hdf5_read_next_data (octave_hdf5_id group_id, const char *name, void *dv);
127 
128 extern OCTINTERP_API octave_hdf5_err
129 hdf5_h5g_iterate (octave_hdf5_id loc_id, const char *name, int *idx,
130  void *operator_data);
131 
132 extern OCTINTERP_API bool
133 add_hdf5_data (octave_hdf5_id loc_id, const octave_value& tc,
134  const std::string& name, const std::string& doc,
135  bool mark_global, bool save_as_floats);
136 
137 extern OCTINTERP_API int
138 save_hdf5_empty (octave_hdf5_id loc_id, const char *name, const dim_vector& d);
139 
140 extern OCTINTERP_API int
141 load_hdf5_empty (octave_hdf5_id loc_id, const char *name, dim_vector& d);
142 
143 extern OCTINTERP_API std::string
144 read_hdf5_data (std::istream& is, const std::string& filename, bool& global,
145  octave_value& tc, std::string& doc,
146  const string_vector& argv, int argv_idx, int argc);
147 
148 extern OCTINTERP_API bool
149 save_hdf5_data (std::ostream& os, const octave_value& tc,
150  const std::string& name, const std::string& doc,
151  bool mark_global, bool save_as_floats);
152 
153 extern OCTINTERP_API bool
154 hdf5_check_attr (octave_hdf5_id loc_id, const char *attr_name);
155 
156 extern OCTINTERP_API bool
158  const char *attr_name, void *buf);
159 
160 extern OCTINTERP_API octave_hdf5_err
161 hdf5_add_attr (octave_hdf5_id loc_id, const char *attr_name);
162 
163 
164 extern OCTINTERP_API octave_hdf5_err
166  const char *attr_name, void *buf);
167 
168 #endif
save_type
Definition: data-conv.h:85
void close(void)
Definition: ls-hdf5.cc:113
hdf5_ifstream()
Definition: ls-hdf5.h:67
octave_value tc
Definition: ls-hdf5.h:110
OCTINTERP_API std::string read_hdf5_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, std::string &doc, const string_vector &argv, int argv_idx, int argc)
Definition: ls-hdf5.cc:727
int argc
Definition: load-save.cc:646
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
Definition: data.cc:6348
std::string name
Definition: ls-hdf5.h:104
OCTINTERP_API octave_hdf5_id hdf5_make_complex_type(octave_hdf5_id num_type)
Definition: ls-hdf5.cc:326
OCTINTERP_API octave_hdf5_err hdf5_read_next_data(octave_hdf5_id group_id, const char *name, void *dv)
Definition: ls-hdf5.cc:693
OCTINTERP_API bool add_hdf5_data(octave_hdf5_id loc_id, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
Definition: ls-hdf5.cc:1053
STL namespace.
std::string filename
Definition: urlwrite.cc:121
OCTINTERP_API bool save_hdf5_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
Definition: ls-hdf5.cc:1148
int octave_hdf5_err
OCTINTERP_API octave_hdf5_err hdf5_h5g_iterate(octave_hdf5_id loc_id, const char *name, int *idx, void *operator_data)
Definition: ls-hdf5.cc:707
void open(const char *name, int mode=std::ios::in|std::ios::binary, int prot=0)
Definition: ls-hdf5.h:73
OCTINTERP_API int load_hdf5_empty(octave_hdf5_id loc_id, const char *name, dim_vector &d)
Definition: ls-hdf5.cc:953
hdf5_ofstream(const char *name, int mode=std::ios::out|std::ios::binary, int prot=0)
Definition: ls-hdf5.h:84
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
std::string doc
Definition: ls-hdf5.h:113
string_vector argv
Definition: load-save.cc:648
OCTINTERP_API octave_hdf5_err hdf5_add_attr(octave_hdf5_id loc_id, const char *attr_name)
Definition: ls-hdf5.cc:812
nd deftypefn *std::string name
Definition: sysdep.cc:647
OCTINTERP_API bool hdf5_get_scalar_attr(octave_hdf5_id loc_id, octave_hdf5_id type_id, const char *attr_name, void *buf)
Definition: ls-hdf5.cc:268
OCTINTERP_API octave_hdf5_err hdf5_add_scalar_attr(octave_hdf5_id loc_id, octave_hdf5_id type_id, const char *attr_name, void *buf)
Definition: ls-hdf5.cc:853
hdf5_ifstream(const char *name, int mode=std::ios::in|std::ios::binary, int prot=0)
Definition: ls-hdf5.h:69
OCTINTERP_API bool hdf5_check_attr(octave_hdf5_id loc_id, const char *attr_name)
Definition: ls-hdf5.cc:221
hdf5_callback_data(void)
Definition: ls-hdf5.h:98
bool save_as_floats
Definition: load-save.cc:1617
is false
Definition: cellfun.cc:400
int64_t octave_hdf5_id
void open(const char *name, int mode=std::ios::out|std::ios::binary, int prot=0)
Definition: ls-hdf5.h:88
octave_hdf5_id file_id
Definition: ls-hdf5.h:44
OCTINTERP_API int save_hdf5_empty(octave_hdf5_id loc_id, const char *name, const dim_vector &d)
Definition: ls-hdf5.cc:897
hdf5_ofstream()
Definition: ls-hdf5.h:82
write the output to stdout if nargout is
Definition: load-save.cc:1612
int current_item
Definition: ls-hdf5.h:47
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
void open(const char *name, int mode, int)
Definition: ls-hdf5.cc:133
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
dim_vector dv
Definition: sub2ind.cc:263
octave::stream os
Definition: file-io.cc:627
OCTINTERP_API bool hdf5_types_compatible(octave_hdf5_id t1, octave_hdf5_id t2)
Definition: ls-hdf5.cc:190
OCTINTERP_API octave_hdf5_id save_type_to_hdf5(save_type st)
Definition: ls-hdf5.cc:997