Mercurial > octave
annotate libinterp/corefcn/ls-hdf5.h @ 32060:1203a2d81a42
Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
* data.cc (Fones, Finf, Feps, Feye): Add BIST test for negative dimensions.
* rand.cc (Frand): Add BIST test for negative dimensions.
* ov-cell.cc (Fcell): Add BIST test for negative dimensions.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 26 Apr 2023 16:26:32 -0700 |
parents | 56809fe23e53 |
children | 2e484f9f1f18 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
31706
597f3ee61a48
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30565
diff
changeset
|
3 // Copyright (C) 2003-2023 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
4634 | 25 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20264
diff
changeset
|
26 #if ! defined (octave_ls_hdf5_h) |
4634 | 27 #define octave_ls_hdf5_h 1 |
28 | |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21211
diff
changeset
|
29 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21211
diff
changeset
|
30 |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
31 #include <iosfwd> |
23442
53f5f8231c37
allow most header files to be compiled separately
John W. Eaton <jwe@octave.org>
parents:
23440
diff
changeset
|
32 |
20264
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
33 #include "oct-hdf5-types.h" |
23442
53f5f8231c37
allow most header files to be compiled separately
John W. Eaton <jwe@octave.org>
parents:
23440
diff
changeset
|
34 #include "ov.h" |
8676 | 35 |
4634 | 36 // first, we need to define our own dummy stream subclass, since |
37 // HDF5 needs to do its own file i/o | |
38 | |
39 // hdf5_fstreambase is used for both input and output streams, modeled | |
40 // on the fstreambase class in <fstream.h> | |
41 | |
42 class hdf5_fstreambase : virtual public std::ios | |
43 { | |
44 public: | |
45 | |
46 // HDF5 uses an "id" to refer to an open file | |
20264
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
47 octave_hdf5_id file_id; |
4634 | 48 |
49 // keep track of current item index in the file | |
50 int current_item; | |
51 | |
11584
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11523
diff
changeset
|
52 hdf5_fstreambase () : file_id (-1), current_item () { } |
4634 | 53 |
31883
56809fe23e53
eliminate some clang warnings about defaulted functions being deleted
John W. Eaton <jwe@octave.org>
parents:
31855
diff
changeset
|
54 OCTAVE_DISABLE_COPY_MOVE (hdf5_fstreambase) |
31855
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
55 |
6760 | 56 ~hdf5_fstreambase () { close (); } |
57 | |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30155
diff
changeset
|
58 OCTINTERP_API hdf5_fstreambase (const char *name, int mode, |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30155
diff
changeset
|
59 int /* prot */ = 0); |
4634 | 60 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
61 OCTINTERP_API void close (); |
4634 | 62 |
29233
665c9ed14c97
Set API tags in files in libinterp/corefcn (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27932
diff
changeset
|
63 OCTINTERP_API void open (const char *name, int mode, int); |
25693
038fb01854a0
Save to hdf5 file with non-ASCII chars on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25438
diff
changeset
|
64 |
29233
665c9ed14c97
Set API tags in files in libinterp/corefcn (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27932
diff
changeset
|
65 OCTINTERP_API void open_create (const char *name, int mode); |
4634 | 66 }; |
67 | |
68 // input and output streams, subclassing istream and ostream | |
69 // so that we can pass them for stream parameters in the functions below. | |
70 | |
71 class hdf5_ifstream : public hdf5_fstreambase, public std::istream | |
72 { | |
73 public: | |
74 | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
75 hdf5_ifstream () : hdf5_fstreambase (), std::istream (nullptr) { } |
4634 | 76 |
21662
5b9868c2e212
maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents:
21355
diff
changeset
|
77 hdf5_ifstream (const char *name, int mode = std::ios::in | std::ios::binary, |
10313 | 78 int prot = 0) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
79 : hdf5_fstreambase (name, mode, prot), std::istream (nullptr) { } |
4634 | 80 |
21662
5b9868c2e212
maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents:
21355
diff
changeset
|
81 void open (const char *name, int mode = std::ios::in | std::ios::binary, |
10313 | 82 int prot = 0) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
83 { hdf5_fstreambase::open (name, mode, prot); } |
4634 | 84 }; |
85 | |
86 class hdf5_ofstream : public hdf5_fstreambase, public std::ostream | |
87 { | |
88 public: | |
89 | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
90 hdf5_ofstream () : hdf5_fstreambase (), std::ostream (nullptr) { } |
4634 | 91 |
21662
5b9868c2e212
maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents:
21355
diff
changeset
|
92 hdf5_ofstream (const char *name, int mode = std::ios::out | std::ios::binary, |
10313 | 93 int prot = 0) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
94 : hdf5_fstreambase (name, mode, prot), std::ostream (nullptr) { } |
4634 | 95 |
21662
5b9868c2e212
maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents:
21355
diff
changeset
|
96 void open (const char *name, int mode = std::ios::out | std::ios::binary, |
10313 | 97 int prot = 0) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
98 { hdf5_fstreambase::open (name, mode, prot); } |
4634 | 99 }; |
100 | |
4687 | 101 // Callback data structure for passing data to hdf5_read_next_data, below. |
102 | |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
103 struct hdf5_callback_data |
4687 | 104 { |
30155
14b098a6ba46
maint: Use public: qualifier in structs that are really classes.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
105 public: |
31855
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
106 |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
107 hdf5_callback_data () |
4687 | 108 : name (), global (false), tc (), doc () { } |
109 | |
31855
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
110 OCTAVE_DEFAULT_COPY_MOVE_DELETE (hdf5_callback_data) |
1daf8bfceac3
default or disable more ctors, dtors, and assignment ops
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
111 |
4687 | 112 // the following fields are set by hdf5_read_data on successful return: |
113 | |
114 // the name of the variable | |
115 std::string name; | |
116 | |
117 // whether it is global | |
118 bool global; | |
119 | |
120 // the value of the variable, in Octave form | |
121 octave_value tc; | |
122 | |
123 // a documentation string (NULL if none) | |
124 std::string doc; | |
125 }; | |
126 | |
20264
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
127 extern OCTINTERP_API octave_hdf5_id |
21355
28d9bce20aa7
eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
128 save_type_to_hdf5 (save_type st); |
4687 | 129 |
20264
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
130 extern OCTINTERP_API octave_hdf5_id |
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
131 hdf5_make_complex_type (octave_hdf5_id num_type); |
4687 | 132 |
6693 | 133 extern OCTINTERP_API bool |
20264
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
134 hdf5_types_compatible (octave_hdf5_id t1, octave_hdf5_id t2); |
4687 | 135 |
20264
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
136 extern OCTINTERP_API octave_hdf5_err |
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
137 hdf5_read_next_data (octave_hdf5_id group_id, const char *name, void *dv); |
4687 | 138 |
22028
5c949eecb6dd
use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents:
22022
diff
changeset
|
139 extern OCTINTERP_API octave_hdf5_err |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23442
diff
changeset
|
140 hdf5_h5g_iterate (octave_hdf5_id loc_id, const char *name, int *idx, |
22028
5c949eecb6dd
use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents:
22022
diff
changeset
|
141 void *operator_data); |
5c949eecb6dd
use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents:
22022
diff
changeset
|
142 |
6693 | 143 extern OCTINTERP_API bool |
20264
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
144 add_hdf5_data (octave_hdf5_id loc_id, const octave_value& tc, |
10313 | 145 const std::string& name, const std::string& doc, |
23470
a41fdb801db6
use mark_global and mark_persistent consistently
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
146 bool mark_global, bool save_as_floats); |
4687 | 147 |
6693 | 148 extern OCTINTERP_API int |
23440
f15f0d8b78c8
pass dim_vector as const reference, not by value
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
149 save_hdf5_empty (octave_hdf5_id loc_id, const char *name, const dim_vector& d); |
4805 | 150 |
6693 | 151 extern OCTINTERP_API int |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
152 load_hdf5_empty (octave_hdf5_id loc_id, const char *name, dim_vector& d); |
4805 | 153 |
6693 | 154 extern OCTINTERP_API std::string |
4687 | 155 read_hdf5_data (std::istream& is, const std::string& filename, bool& global, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
156 octave_value& tc, std::string& doc, |
17709
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
157 const string_vector& argv, int argv_idx, int argc); |
4634 | 158 |
6693 | 159 extern OCTINTERP_API bool |
4634 | 160 save_hdf5_data (std::ostream& os, const octave_value& tc, |
10313 | 161 const std::string& name, const std::string& doc, |
23470
a41fdb801db6
use mark_global and mark_persistent consistently
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
162 bool mark_global, bool save_as_floats); |
4634 | 163 |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
164 extern OCTINTERP_API bool |
20264
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
165 hdf5_check_attr (octave_hdf5_id loc_id, const char *attr_name); |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
166 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
167 extern OCTINTERP_API bool |
20264
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
168 hdf5_get_scalar_attr (octave_hdf5_id loc_id, octave_hdf5_id type_id, |
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
169 const char *attr_name, void *buf); |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
170 |
20264
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
171 extern OCTINTERP_API octave_hdf5_err |
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
172 hdf5_add_attr (octave_hdf5_id loc_id, const char *attr_name); |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
173 |
22028
5c949eecb6dd
use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents:
22022
diff
changeset
|
174 |
20264
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
175 extern OCTINTERP_API octave_hdf5_err |
bfe66db8addb
don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
176 hdf5_add_scalar_attr (octave_hdf5_id loc_id, octave_hdf5_id type_id, |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
177 const char *attr_name, void *buf); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
178 |
4634 | 179 #endif |