Mercurial > hg > octave-nkf
annotate libinterp/corefcn/ls-hdf5.h @ 20471:2691947f5409 stable
Change mxCreateNumericArray to be Matlab compatible for ndims < 2 (bug #45319).
* mex.cc (mxArray_matlab::mxArray_matlab ()): If ndims < 2, create a 2-D object
that is 0x0.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 15 Jun 2015 09:07:17 -0700 |
parents | 4197fc428c7d |
children | bfe66db8addb |
rev | line source |
---|---|
4634 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19409
diff
changeset
|
3 Copyright (C) 2003-2015 John W. Eaton |
4634 | 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 the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
4634 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4634 | 20 |
21 */ | |
22 | |
23 #if !defined (octave_ls_hdf5_h) | |
24 #define octave_ls_hdf5_h 1 | |
25 | |
4695 | 26 #if defined (HAVE_HDF5) |
27 | |
8676 | 28 #include "oct-hdf5.h" |
29 | |
4634 | 30 // first, we need to define our own dummy stream subclass, since |
31 // HDF5 needs to do its own file i/o | |
32 | |
33 // hdf5_fstreambase is used for both input and output streams, modeled | |
34 // on the fstreambase class in <fstream.h> | |
35 | |
36 class hdf5_fstreambase : virtual public std::ios | |
37 { | |
38 public: | |
39 | |
40 // HDF5 uses an "id" to refer to an open file | |
41 hid_t file_id; | |
42 | |
43 // keep track of current item index in the file | |
44 int current_item; | |
45 | |
11584
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11523
diff
changeset
|
46 hdf5_fstreambase () : file_id (-1), current_item () { } |
4634 | 47 |
6760 | 48 ~hdf5_fstreambase () { close (); } |
49 | |
4663 | 50 hdf5_fstreambase (const char *name, int mode, int /* prot */ = 0) |
11584
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11523
diff
changeset
|
51 : file_id (-1), current_item (-1) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
52 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
53 if (mode & std::ios::in) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
54 file_id = H5Fopen (name, H5F_ACC_RDONLY, H5P_DEFAULT); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
55 else if (mode & std::ios::out) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
56 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
57 if (mode & std::ios::app && H5Fis_hdf5 (name) > 0) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
58 file_id = H5Fopen (name, H5F_ACC_RDWR, H5P_DEFAULT); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
59 else |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
60 file_id = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
61 H5P_DEFAULT); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
62 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
63 if (file_id < 0) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
64 std::ios::setstate (std::ios::badbit); |
4634 | 65 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
66 current_item = 0; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
67 } |
4634 | 68 |
69 void close () | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
70 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
71 if (file_id >= 0) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
72 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
73 if (H5Fclose (file_id) < 0) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
74 std::ios::setstate (std::ios::badbit); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
75 file_id = -1; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
76 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
77 } |
4634 | 78 |
5728 | 79 void open (const char *name, int mode, int) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
80 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
81 clear (); |
4634 | 82 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
83 if (mode & std::ios::in) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
84 file_id = H5Fopen (name, H5F_ACC_RDONLY, H5P_DEFAULT); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
85 else if (mode & std::ios::out) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
86 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
87 if (mode & std::ios::app && H5Fis_hdf5 (name) > 0) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
88 file_id = H5Fopen (name, H5F_ACC_RDWR, H5P_DEFAULT); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
89 else |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
90 file_id = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
91 H5P_DEFAULT); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
92 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
93 if (file_id < 0) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
94 std::ios::setstate (std::ios::badbit); |
4634 | 95 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
96 current_item = 0; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
97 } |
4634 | 98 }; |
99 | |
100 // input and output streams, subclassing istream and ostream | |
101 // so that we can pass them for stream parameters in the functions below. | |
102 | |
103 class hdf5_ifstream : public hdf5_fstreambase, public std::istream | |
104 { | |
105 public: | |
106 | |
107 hdf5_ifstream () : hdf5_fstreambase (), std::istream (0) { } | |
108 | |
5255 | 109 hdf5_ifstream (const char *name, int mode = std::ios::in|std::ios::binary, |
10313 | 110 int prot = 0) |
4634 | 111 : hdf5_fstreambase (name, mode, prot), std::istream (0) { } |
112 | |
5255 | 113 void open (const char *name, int mode = std::ios::in|std::ios::binary, |
10313 | 114 int prot = 0) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
115 { hdf5_fstreambase::open (name, mode, prot); } |
4634 | 116 }; |
117 | |
118 class hdf5_ofstream : public hdf5_fstreambase, public std::ostream | |
119 { | |
120 public: | |
121 | |
122 hdf5_ofstream () : hdf5_fstreambase (), std::ostream (0) { } | |
123 | |
5255 | 124 hdf5_ofstream (const char *name, int mode = std::ios::out|std::ios::binary, |
10313 | 125 int prot = 0) |
4634 | 126 : hdf5_fstreambase (name, mode, prot), std::ostream (0) { } |
127 | |
5255 | 128 void open (const char *name, int mode = std::ios::out|std::ios::binary, |
10313 | 129 int prot = 0) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
130 { hdf5_fstreambase::open (name, mode, prot); } |
4634 | 131 }; |
132 | |
4687 | 133 // Callback data structure for passing data to hdf5_read_next_data, below. |
134 | |
135 struct | |
136 hdf5_callback_data | |
137 { | |
138 hdf5_callback_data (void) | |
139 : name (), global (false), tc (), doc () { } | |
140 | |
141 // the following fields are set by hdf5_read_data on successful return: | |
142 | |
143 // the name of the variable | |
144 std::string name; | |
145 | |
146 // whether it is global | |
147 bool global; | |
148 | |
149 // the value of the variable, in Octave form | |
150 octave_value tc; | |
151 | |
152 // a documentation string (NULL if none) | |
153 std::string doc; | |
154 }; | |
155 | |
156 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS | |
6693 | 157 extern OCTINTERP_API hid_t |
4687 | 158 save_type_to_hdf5 (save_type st) |
159 #endif | |
160 | |
6693 | 161 extern OCTINTERP_API hid_t |
4687 | 162 hdf5_make_complex_type (hid_t num_type); |
163 | |
6693 | 164 extern OCTINTERP_API bool |
4687 | 165 hdf5_types_compatible (hid_t t1, hid_t t2); |
166 | |
6693 | 167 extern OCTINTERP_API herr_t |
4687 | 168 hdf5_read_next_data (hid_t group_id, const char *name, void *dv); |
169 | |
6693 | 170 extern OCTINTERP_API bool |
4687 | 171 add_hdf5_data (hid_t loc_id, const octave_value& tc, |
10313 | 172 const std::string& name, const std::string& doc, |
173 bool mark_as_global, bool save_as_floats); | |
4687 | 174 |
6693 | 175 extern OCTINTERP_API int |
4805 | 176 save_hdf5_empty (hid_t loc_id, const char *name, const dim_vector d); |
177 | |
6693 | 178 extern OCTINTERP_API int |
4805 | 179 load_hdf5_empty (hid_t loc_id, const char *name, dim_vector &d); |
180 | |
6693 | 181 extern OCTINTERP_API std::string |
4687 | 182 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
|
183 octave_value& tc, std::string& doc, |
17709
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
184 const string_vector& argv, int argv_idx, int argc); |
4634 | 185 |
6693 | 186 extern OCTINTERP_API bool |
4634 | 187 save_hdf5_data (std::ostream& os, const octave_value& tc, |
10313 | 188 const std::string& name, const std::string& doc, |
189 bool mark_as_global, bool save_as_floats); | |
4634 | 190 |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
191 extern OCTINTERP_API bool |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
192 hdf5_check_attr (hid_t loc_id, const char *attr_name); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
193 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
194 extern OCTINTERP_API bool |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
195 hdf5_get_scalar_attr (hid_t loc_id, hid_t type_id, const char *attr_name, |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
196 void *buf); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
197 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
198 extern OCTINTERP_API herr_t |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
199 hdf5_add_attr (hid_t loc_id, const char *attr_name); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
200 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
201 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
202 extern OCTINTERP_API herr_t |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
203 hdf5_add_scalar_attr (hid_t loc_id, hid_t type_id, |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10313
diff
changeset
|
204 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
|
205 |
16313
6aafe87a3144
use int64_t for idx type if --enable-64
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
206 #ifdef USE_64_BIT_IDX_T |
19409
3ffb8f53e940
use correct HDF5 size for octave_idx_type on Windows-64 (bug #43101)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
207 #define H5T_NATIVE_IDX H5T_NATIVE_INT64 |
5351 | 208 #else |
209 #define H5T_NATIVE_IDX H5T_NATIVE_INT | |
210 #endif | |
211 | |
4634 | 212 #endif |
213 | |
4695 | 214 #endif |