Mercurial > octave-dspies
annotate libinterp/corefcn/ls-hdf5.cc @ 18678:6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 25 Apr 2014 13:25:25 -0700 |
parents | 5bd1ca29c5f0 |
children |
rev | line source |
---|---|
4634 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17709
diff
changeset
|
3 Copyright (C) 1996-2013 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 // Author: Steven G. Johnson <stevenj@alum.mit.edu> | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
29 #if defined (HAVE_HDF5) | |
30 | |
31 #include <cfloat> | |
32 #include <cstring> | |
33 #include <cctype> | |
34 | |
35 #include <fstream> | |
36 #include <iomanip> | |
37 #include <iostream> | |
38 #include <string> | |
4726 | 39 #include <vector> |
4634 | 40 |
41 #include "byte-swap.h" | |
42 #include "data-conv.h" | |
43 #include "file-ops.h" | |
44 #include "glob-match.h" | |
45 #include "lo-mappers.h" | |
46 #include "mach-info.h" | |
47 #include "oct-env.h" | |
48 #include "oct-time.h" | |
49 #include "quit.h" | |
50 #include "str-vec.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
51 #include "oct-locbuf.h" |
4634 | 52 |
53 #include "Cell.h" | |
54 #include "defun.h" | |
55 #include "error.h" | |
56 #include "gripes.h" | |
57 #include "load-save.h" | |
58 #include "oct-obj.h" | |
59 #include "oct-map.h" | |
60 #include "ov-cell.h" | |
61 #include "pager.h" | |
62 #include "pt-exp.h" | |
63 #include "sysdep.h" | |
64 #include "unwind-prot.h" | |
65 #include "utils.h" | |
66 #include "variables.h" | |
67 #include "version.h" | |
68 #include "dMatrix.h" | |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
69 #include "ov-lazy-idx.h" |
4634 | 70 |
71 #include "ls-utils.h" | |
72 #include "ls-hdf5.h" | |
73 | |
74 static std::string | |
75 make_valid_identifier (const std::string& nm) | |
76 { | |
77 std::string retval; | |
78 | |
79 size_t nm_len = nm.length (); | |
80 | |
81 if (nm_len > 0) | |
82 { | |
83 if (! isalpha (nm[0])) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
84 retval += '_'; |
4634 | 85 |
86 for (size_t i = 0; i < nm_len; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
87 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
88 char c = nm[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
89 retval += (isalnum (c) || c == '_') ? c : '_'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
90 } |
4634 | 91 } |
92 | |
93 return retval; | |
94 } | |
95 | |
96 // Define this to 1 if/when HDF5 supports automatic conversion between | |
97 // integer and floating-point binary data: | |
98 #define HAVE_HDF5_INT2FLOAT_CONVERSIONS 0 | |
99 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
100 // Given two compound types t1 and t2, determine whether they |
4634 | 101 // are compatible for reading/writing. This function only |
102 // works for non-nested types composed of simple elements (ints, floats...), | |
103 // which is all we need it for | |
104 | |
105 bool | |
106 hdf5_types_compatible (hid_t t1, hid_t t2) | |
107 { | |
108 int n; | |
109 if ((n = H5Tget_nmembers (t1)) != H5Tget_nmembers (t2)) | |
110 return false; | |
111 | |
112 for (int i = 0; i < n; ++i) | |
113 { | |
114 hid_t mt1 = H5Tget_member_type (t1, i); | |
115 hid_t mt2 = H5Tget_member_type (t2, i); | |
116 | |
117 if (H5Tget_class (mt1) != H5Tget_class (mt2)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
118 return false; |
4634 | 119 |
120 H5Tclose (mt2); | |
121 H5Tclose (mt1); | |
122 } | |
123 | |
124 return true; | |
125 } | |
126 | |
127 // Return true if loc_id has the attribute named attr_name, and false | |
128 // otherwise. | |
129 | |
130 bool | |
131 hdf5_check_attr (hid_t loc_id, const char *attr_name) | |
132 { | |
133 bool retval = false; | |
134 | |
135 // we have to pull some shenanigans here to make sure | |
136 // HDF5 doesn't print out all sorts of error messages if we | |
137 // call H5Aopen for a non-existing attribute | |
138 | |
139 H5E_auto_t err_func; | |
140 void *err_func_data; | |
141 | |
142 // turn off error reporting temporarily, but save the error | |
143 // reporting function: | |
144 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
145 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
146 H5Eget_auto (H5E_DEFAULT, &err_func, &err_func_data); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
147 H5Eset_auto (H5E_DEFAULT, 0, 0); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
148 #else |
4634 | 149 H5Eget_auto (&err_func, &err_func_data); |
150 H5Eset_auto (0, 0); | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
151 #endif |
4634 | 152 |
153 hid_t attr_id = H5Aopen_name (loc_id, attr_name); | |
154 | |
155 if (attr_id >= 0) | |
156 { | |
157 // successful | |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
158 retval = true; |
4634 | 159 H5Aclose (attr_id); |
160 } | |
161 | |
162 // restore error reporting: | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
163 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
164 H5Eset_auto (H5E_DEFAULT, err_func, err_func_data); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
165 #else |
4634 | 166 H5Eset_auto (err_func, err_func_data); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
167 #endif |
4634 | 168 return retval; |
169 } | |
170 | |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
171 bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
172 hdf5_get_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:
10325
diff
changeset
|
173 const char *attr_name, void *buf) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
174 { |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
175 bool retval = false; |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
176 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
177 // we have to pull some shenanigans here to make sure |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
178 // HDF5 doesn't print out all sorts of error messages if we |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
179 // call H5Aopen for a non-existing attribute |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
180 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
181 H5E_auto_t err_func; |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
182 void *err_func_data; |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
183 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
184 // turn off error reporting temporarily, but save the error |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
185 // reporting function: |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
186 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
187 #if HAVE_HDF5_18 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
188 H5Eget_auto (H5E_DEFAULT, &err_func, &err_func_data); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
189 H5Eset_auto (H5E_DEFAULT, 0, 0); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
190 #else |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
191 H5Eget_auto (&err_func, &err_func_data); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
192 H5Eset_auto (0, 0); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
193 #endif |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
194 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
195 hid_t attr_id = H5Aopen_name (loc_id, attr_name); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
196 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
197 if (attr_id >= 0) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
198 { |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
199 hid_t space_id = H5Aget_space (attr_id); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
200 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
201 hsize_t rank = H5Sget_simple_extent_ndims (space_id); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
202 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
203 if (rank == 0) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
204 retval = H5Aread (attr_id, type_id, buf) >= 0; |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
205 H5Aclose (attr_id); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
206 } |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
207 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
208 // restore error reporting: |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
209 #if HAVE_HDF5_18 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
210 H5Eset_auto (H5E_DEFAULT, err_func, err_func_data); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
211 #else |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
212 H5Eset_auto (err_func, err_func_data); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
213 #endif |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
214 return retval; |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
215 } |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
216 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
217 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
218 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
219 |
4687 | 220 // The following subroutines creates an HDF5 representations of the way |
221 // we will store Octave complex types (pairs of floating-point numbers). | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
222 // NUM_TYPE is the HDF5 numeric type to use for storage (e.g. |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
223 // H5T_NATIVE_DOUBLE to save as 'double'). Note that any necessary |
4687 | 224 // conversions are handled automatically by HDF5. |
4634 | 225 |
4687 | 226 hid_t |
4634 | 227 hdf5_make_complex_type (hid_t num_type) |
228 { | |
229 hid_t type_id = H5Tcreate (H5T_COMPOUND, sizeof (double) * 2); | |
230 | |
231 H5Tinsert (type_id, "real", 0 * sizeof (double), num_type); | |
232 H5Tinsert (type_id, "imag", 1 * sizeof (double), num_type); | |
233 | |
234 return type_id; | |
235 } | |
236 | |
237 // This function is designed to be passed to H5Giterate, which calls it | |
238 // on each data item in an HDF5 file. For the item whose name is NAME in | |
239 // the group GROUP_ID, this function sets dv->tc to an Octave representation | |
240 // of that item. (dv must be a pointer to hdf5_callback_data.) (It also | |
241 // sets the other fields of dv). | |
242 // | |
243 // It returns 1 on success (in which case H5Giterate stops and returns), | |
244 // -1 on error, and 0 to tell H5Giterate to continue on to the next item | |
245 // (e.g. if NAME was a data type we don't recognize). | |
246 | |
4687 | 247 herr_t |
4634 | 248 hdf5_read_next_data (hid_t group_id, const char *name, void *dv) |
249 { | |
250 hdf5_callback_data *d = static_cast <hdf5_callback_data *> (dv); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
251 hid_t type_id = -1; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
252 hid_t type_class_id = -1; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
253 hid_t data_id = -1; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
254 hid_t subgroup_id = -1; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
255 hid_t space_id = -1;; |
4634 | 256 |
257 H5G_stat_t info; | |
258 herr_t retval = 0; | |
259 bool ident_valid = valid_identifier (name); | |
260 | |
261 std::string vname = name; | |
262 | |
263 // Allow identifiers as all digits so we can load lists saved by | |
264 // earlier versions of Octave. | |
265 | |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18676
diff
changeset
|
266 if (! ident_valid) |
4634 | 267 { |
268 // fix the identifier, replacing invalid chars with underscores | |
269 vname = make_valid_identifier (vname); | |
270 | |
271 // check again (in case vname was null, empty, or some such thing): | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
272 ident_valid = valid_identifier (vname); |
4634 | 273 } |
274 | |
275 H5Gget_objinfo (group_id, name, 1, &info); | |
276 | |
4687 | 277 if (info.type == H5G_GROUP && ident_valid) |
4634 | 278 { |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
279 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
280 subgroup_id = H5Gopen (group_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
281 #else |
4687 | 282 subgroup_id = H5Gopen (group_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
283 #endif |
4634 | 284 |
285 if (subgroup_id < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
286 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
287 retval = subgroup_id; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
288 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
289 } |
4634 | 290 |
4687 | 291 if (hdf5_check_attr (subgroup_id, "OCTAVE_NEW_FORMAT")) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
292 { |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
293 #if HAVE_HDF5_18 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
294 data_id = H5Dopen (subgroup_id, "type", H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
295 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
296 data_id = H5Dopen (subgroup_id, "type"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
297 #endif |
4634 | 298 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
299 if (data_id < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
300 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
301 retval = data_id; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
302 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
303 } |
4634 | 304 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
305 type_id = H5Dget_type (data_id); |
4687 | 306 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
307 type_class_id = H5Tget_class (type_id); |
4687 | 308 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
309 if (type_class_id != H5T_STRING) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
310 goto done; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
311 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
312 space_id = H5Dget_space (data_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
313 hsize_t rank = H5Sget_simple_extent_ndims (space_id); |
4687 | 314 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
315 if (rank != 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
316 goto done; |
4687 | 317 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
318 int slen = H5Tget_size (type_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
319 if (slen < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
320 goto done; |
4687 | 321 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
322 OCTAVE_LOCAL_BUFFER (char, typ, slen); |
4687 | 323 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
324 // create datatype for (null-terminated) string to read into: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
325 hid_t st_id = H5Tcopy (H5T_C_S1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
326 H5Tset_size (st_id, slen); |
4687 | 327 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
328 if (H5Dread (data_id, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
329 typ) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
330 goto done; |
4687 | 331 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
332 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
333 H5Dclose (data_id); |
4687 | 334 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
335 d->tc = octave_value_typeinfo::lookup_type (typ); |
4687 | 336 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
337 retval = (d->tc.load_hdf5 (subgroup_id, "value") ? 1 : -1); |
4687 | 338 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
339 // check for OCTAVE_GLOBAL attribute: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
340 d->global = hdf5_check_attr (subgroup_id, "OCTAVE_GLOBAL"); |
4687 | 341 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
342 H5Gclose (subgroup_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
343 } |
4634 | 344 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
345 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
346 // an HDF5 group is treated as an octave structure by |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
347 // default (since that preserves name information), and an |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
348 // octave list otherwise. |
4687 | 349 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
350 if (hdf5_check_attr (subgroup_id, "OCTAVE_LIST")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
351 d->tc = octave_value_typeinfo::lookup_type ("list"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
352 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
353 d->tc = octave_value_typeinfo::lookup_type ("struct"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
354 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
355 // check for OCTAVE_GLOBAL attribute: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
356 d->global = hdf5_check_attr (subgroup_id, "OCTAVE_GLOBAL"); |
4687 | 357 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
358 H5Gclose (subgroup_id); |
4634 | 359 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
360 retval = (d->tc.load_hdf5 (group_id, name) ? 1 : -1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
361 } |
4687 | 362 |
363 } | |
364 else if (info.type == H5G_DATASET && ident_valid) | |
365 { | |
366 // For backwards compatiability. | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
367 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
368 data_id = H5Dopen (group_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
369 #else |
4687 | 370 data_id = H5Dopen (group_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
371 #endif |
4687 | 372 |
373 if (data_id < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
374 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
375 retval = data_id; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
376 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
377 } |
4634 | 378 |
4687 | 379 type_id = H5Dget_type (data_id); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
380 |
4687 | 381 type_class_id = H5Tget_class (type_id); |
382 | |
383 if (type_class_id == H5T_FLOAT) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
384 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
385 space_id = H5Dget_space (data_id); |
4687 | 386 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
387 hsize_t rank = H5Sget_simple_extent_ndims (space_id); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
388 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
389 if (rank == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
390 d->tc = octave_value_typeinfo::lookup_type ("scalar"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
391 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
392 d->tc = octave_value_typeinfo::lookup_type ("matrix"); |
4687 | 393 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
394 H5Sclose (space_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
395 } |
4948 | 396 else if (type_class_id == H5T_INTEGER) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
397 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
398 // What integer type do we really have.. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
399 std::string int_typ; |
4948 | 400 #ifdef HAVE_H5T_GET_NATIVE_TYPE |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
401 // FIXME: test this code and activated with an autoconf |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
402 // test!! It is also incorrect for 64-bit indexing!! |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
403 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
404 switch (H5Tget_native_type (type_id, H5T_DIR_ASCEND)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
405 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
406 case H5T_NATIVE_CHAR: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
407 int_typ = "int8 "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
408 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
409 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
410 case H5T_NATIVE_SHORT: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
411 int_typ = "int16 "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
412 break; |
4948 | 413 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
414 case H5T_NATIVE_INT: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
415 case H5T_NATIVE_LONG: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
416 int_typ = "int32 "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
417 break; |
4948 | 418 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
419 case H5T_NATIVE_LLONG: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
420 int_typ = "int64 "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
421 break; |
4948 | 422 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
423 case H5T_NATIVE_UCHAR: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
424 int_typ = "uint8 "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
425 break; |
4948 | 426 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
427 case H5T_NATIVE_USHORT: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
428 int_typ = "uint16 "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
429 break; |
4948 | 430 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
431 case H5T_NATIVE_UINT: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
432 case H5T_NATIVE_ULONG: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
433 int_typ = "uint32 "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
434 break; |
4948 | 435 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
436 case H5T_NATIVE_ULLONG: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
437 int_typ = "uint64 "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
438 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
439 } |
4948 | 440 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
441 hid_t int_sign = H5Tget_sign (type_id); |
4948 | 442 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
443 if (int_sign == H5T_SGN_ERROR) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
444 warning ("load: can't read '%s' (unknown datatype)", name); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
445 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
446 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
447 if (int_sign == H5T_SGN_NONE) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
448 int_typ.append ("u"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
449 int_typ.append ("int"); |
4948 | 450 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
451 int slen = H5Tget_size (type_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
452 if (slen < 0) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
453 warning ("load: can't read '%s' (unknown datatype)", name); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
454 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
455 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
456 switch (slen) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
457 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
458 case 1: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
459 int_typ.append ("8 "); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
460 break; |
4948 | 461 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
462 case 2: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
463 int_typ.append ("16 "); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
464 break; |
4948 | 465 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
466 case 4: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
467 int_typ.append ("32 "); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
468 break; |
4948 | 469 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
470 case 8: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
471 int_typ.append ("64 "); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
472 break; |
4948 | 473 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
474 default: |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
475 warning ("load: can't read '%s' (unknown datatype)", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
476 name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
477 int_typ = ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
478 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
479 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
480 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
481 } |
4948 | 482 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
483 if (int_typ == "") |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
484 warning ("load: can't read '%s' (unknown datatype)", name); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
485 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
486 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
487 // Matrix or scalar? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
488 space_id = H5Dget_space (data_id); |
4948 | 489 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
490 hsize_t rank = H5Sget_simple_extent_ndims (space_id); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
491 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
492 if (rank == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
493 int_typ.append ("scalar"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
494 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
495 int_typ.append ("matrix"); |
4948 | 496 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
497 d->tc = octave_value_typeinfo::lookup_type (int_typ); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
498 H5Sclose (space_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
499 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
500 } |
4687 | 501 else if (type_class_id == H5T_STRING) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
502 d->tc = octave_value_typeinfo::lookup_type ("string"); |
4687 | 503 else if (type_class_id == H5T_COMPOUND) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
504 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
505 hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); |
4687 | 506 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
507 if (hdf5_types_compatible (type_id, complex_type)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
508 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
509 // read complex matrix or scalar variable |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
510 space_id = H5Dget_space (data_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
511 hsize_t rank = H5Sget_simple_extent_ndims (space_id); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
512 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
513 if (rank == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
514 d->tc = octave_value_typeinfo::lookup_type ("complex scalar"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
515 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
516 d->tc = octave_value_typeinfo::lookup_type ("complex matrix"); |
4687 | 517 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
518 H5Sclose (space_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
519 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
520 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
521 // Assume that if its not complex its a range. If its not |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
522 // it'll be rejected later in the range code |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
523 d->tc = octave_value_typeinfo::lookup_type ("range"); |
4687 | 524 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
525 H5Tclose (complex_type); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
526 } |
4687 | 527 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
528 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
529 warning ("load: can't read '%s' (unknown datatype)", name); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
530 retval = 0; // unknown datatype; skip |
18676
5bd1ca29c5f0
Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
531 return retval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
532 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
533 |
4687 | 534 // check for OCTAVE_GLOBAL attribute: |
535 d->global = hdf5_check_attr (data_id, "OCTAVE_GLOBAL"); | |
536 | |
537 H5Tclose (type_id); | |
538 H5Dclose (data_id); | |
539 | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
8920
diff
changeset
|
540 retval = (d->tc.load_hdf5 (group_id, name) ? 1 : -1); |
4634 | 541 } |
4687 | 542 |
543 if (!ident_valid) | |
4634 | 544 { |
545 // should we attempt to handle invalid identifiers by converting | |
546 // bad characters to '_', say? | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
547 warning ("load: skipping invalid identifier '%s' in hdf5 file", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
548 name); |
4634 | 549 } |
550 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
551 done: |
4634 | 552 if (retval < 0) |
553 error ("load: error while reading hdf5 item %s", name); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
554 |
4634 | 555 if (retval > 0) |
556 { | |
557 // get documentation string, if any: | |
558 int comment_length = H5Gget_comment (group_id, name, 0, 0); | |
559 | |
560 if (comment_length > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
561 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
562 OCTAVE_LOCAL_BUFFER (char, tdoc, comment_length); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
563 H5Gget_comment (group_id, name, comment_length, tdoc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
564 d->doc = tdoc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
565 } |
4634 | 566 else if (vname != name) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
567 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
568 // the name was changed; store the original name |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
569 // as the documentation string: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
570 d->doc = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
571 } |
4634 | 572 |
573 // copy name (actually, vname): | |
574 d->name = vname; | |
575 } | |
576 | |
577 return retval; | |
578 } | |
579 | |
580 // Read the next Octave variable from the stream IS, which must really be | |
581 // an hdf5_ifstream. Return the variable value in tc, its doc string | |
582 // in doc, and whether it is global in global. The return value is | |
583 // the name of the variable, or NULL if none were found or there was | |
4687 | 584 // and error. |
4634 | 585 std::string |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
586 read_hdf5_data (std::istream& is, const std::string& /* filename */, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
587 bool& global, octave_value& tc, std::string& doc, |
17709
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
588 const string_vector& argv, int argv_idx, int argc) |
4634 | 589 { |
590 std::string retval; | |
591 | |
592 doc.resize (0); | |
593 | |
5760 | 594 hdf5_ifstream& hs = dynamic_cast<hdf5_ifstream&> (is); |
4634 | 595 hdf5_callback_data d; |
596 | |
4696 | 597 herr_t H5Giterate_retval = -1; |
598 | |
599 hsize_t num_obj = 0; | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
600 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
601 hid_t group_id = H5Gopen (hs.file_id, "/", H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
602 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
603 hid_t group_id = H5Gopen (hs.file_id, "/"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
604 #endif |
5060 | 605 H5Gget_num_objs (group_id, &num_obj); |
606 H5Gclose (group_id); | |
17709
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
607 |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
608 // For large datasets and out-of-core functionality, |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
609 // check if only parts of the data is requested |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
610 bool load_named_vars = argv_idx < argc; |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
611 while (load_named_vars && hs.current_item < static_cast<int> (num_obj)) |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
612 { |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
613 std::vector<char> var_name; |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
614 bool found = false; |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
615 size_t len = 0; |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
616 |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
617 len = H5Gget_objname_by_idx (hs.file_id, hs.current_item, 0, 0); |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
618 var_name.resize (len+1); |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18676
diff
changeset
|
619 H5Gget_objname_by_idx (hs.file_id, hs.current_item, &var_name[0], len+1); |
17709
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
620 |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
621 for (int i = argv_idx; i < argc; i++) |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
622 { |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
623 glob_match pattern (argv[i]); |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
624 if (pattern.match (std::string (&var_name[0]))) |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
625 { |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
626 found = true; |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
627 break; |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
628 } |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
629 } |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
630 |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
631 if (found) |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
632 break; |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
633 |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
634 hs.current_item++; |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
635 } |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
636 |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
637 |
4696 | 638 if (hs.current_item < static_cast<int> (num_obj)) |
639 H5Giterate_retval = H5Giterate (hs.file_id, "/", &hs.current_item, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
640 hdf5_read_next_data, &d); |
4634 | 641 |
642 if (H5Giterate_retval > 0) | |
643 { | |
644 global = d.global; | |
645 tc = d.tc; | |
646 doc = d.doc; | |
647 } | |
648 else | |
649 { | |
650 // an error occurred (H5Giterate_retval < 0) or there are no | |
651 // more datasets print an error message if retval < 0? | |
652 // hdf5_read_next_data already printed one, probably. | |
653 } | |
654 | |
655 if (! d.name.empty ()) | |
656 retval = d.name; | |
657 | |
658 return retval; | |
659 } | |
660 | |
661 // Add an attribute named attr_name to loc_id (a simple scalar | |
662 // attribute with value 1). Return value is >= 0 on success. | |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
663 herr_t |
4634 | 664 hdf5_add_attr (hid_t loc_id, const char *attr_name) |
665 { | |
666 herr_t retval = 0; | |
667 | |
668 hid_t as_id = H5Screate (H5S_SCALAR); | |
669 | |
670 if (as_id >= 0) | |
671 { | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
672 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
673 hid_t a_id = H5Acreate (loc_id, attr_name, H5T_NATIVE_UCHAR, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
674 as_id, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
675 #else |
4634 | 676 hid_t a_id = H5Acreate (loc_id, attr_name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
677 H5T_NATIVE_UCHAR, as_id, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
678 #endif |
4634 | 679 if (a_id >= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
680 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
681 unsigned char attr_val = 1; |
4634 | 682 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
683 retval = H5Awrite (a_id, H5T_NATIVE_UCHAR, &attr_val); |
4634 | 684 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
685 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
686 } |
4634 | 687 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
688 retval = a_id; |
4634 | 689 |
690 H5Sclose (as_id); | |
691 } | |
692 else | |
693 retval = as_id; | |
694 | |
695 return retval; | |
696 } | |
697 | |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
698 herr_t |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
699 hdf5_add_scalar_attr (hid_t loc_id, hid_t type_id, |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
700 const char *attr_name, void *buf) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
701 { |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
702 herr_t retval = 0; |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
703 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
704 hid_t as_id = H5Screate (H5S_SCALAR); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
705 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
706 if (as_id >= 0) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
707 { |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
708 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
709 hid_t a_id = H5Acreate (loc_id, attr_name, type_id, |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
710 as_id, H5P_DEFAULT, H5P_DEFAULT); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
711 #else |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
712 hid_t a_id = H5Acreate (loc_id, attr_name, |
11177
30bcd1aa9f09
Trivial patch to previous change
David Bateman <dbateman@free.fr>
parents:
11176
diff
changeset
|
713 type_id, as_id, H5P_DEFAULT); |
11176
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
714 #endif |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
715 if (a_id >= 0) |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
716 { |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
717 retval = H5Awrite (a_id, type_id, buf); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
718 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
719 H5Aclose (a_id); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
720 } |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
721 else |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
722 retval = a_id; |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
723 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
724 H5Sclose (as_id); |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
725 } |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
726 else |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
727 retval = as_id; |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
728 |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
729 return retval; |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
730 } |
2271261f088a
Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents:
10325
diff
changeset
|
731 |
4805 | 732 // Save an empty matrix, if needed. Returns |
733 // > 0 Saved empty matrix | |
734 // = 0 Not an empty matrix; did nothing | |
735 // < 0 Error condition | |
736 int | |
737 save_hdf5_empty (hid_t loc_id, const char *name, const dim_vector d) | |
738 { | |
739 hsize_t sz = d.length (); | |
6276 | 740 OCTAVE_LOCAL_BUFFER (octave_idx_type, dims, sz); |
4805 | 741 bool empty = false; |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
742 hid_t space_hid = -1; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
743 hid_t data_hid = -1; |
4805 | 744 int retval; |
745 for (hsize_t i = 0; i < sz; i++) | |
746 { | |
747 dims[i] = d(i); | |
748 if (dims[i] < 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
749 empty = true; |
4805 | 750 } |
751 | |
752 if (!empty) | |
753 return 0; | |
754 | |
5760 | 755 space_hid = H5Screate_simple (1, &sz, 0); |
4805 | 756 if (space_hid < 0) return space_hid; |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
757 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
758 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
759 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
760 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
761 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
762 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
763 #endif |
4805 | 764 if (data_hid < 0) |
765 { | |
766 H5Sclose (space_hid); | |
767 return data_hid; | |
768 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
769 |
5351 | 770 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
771 H5P_DEFAULT, dims) >= 0; |
4805 | 772 |
773 H5Dclose (data_hid); | |
774 H5Sclose (space_hid); | |
775 | |
776 if (retval >= 0) | |
777 retval = hdf5_add_attr (loc_id, "OCTAVE_EMPTY_MATRIX"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
778 |
4805 | 779 return (retval == 0 ? 1 : retval); |
780 } | |
781 | |
782 // Load an empty matrix, if needed. Returns | |
783 // > 0 loaded empty matrix, dimensions returned | |
784 // = 0 Not an empty matrix; did nothing | |
785 // < 0 Error condition | |
786 int | |
787 load_hdf5_empty (hid_t loc_id, const char *name, dim_vector &d) | |
788 { | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
789 if (! hdf5_check_attr (loc_id, "OCTAVE_EMPTY_MATRIX")) |
4805 | 790 return 0; |
791 | |
792 hsize_t hdims, maxdims; | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
793 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
794 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
795 #else |
4805 | 796 hid_t data_hid = H5Dopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
797 #endif |
4805 | 798 hid_t space_id = H5Dget_space (data_hid); |
799 H5Sget_simple_extent_dims (space_id, &hdims, &maxdims); | |
800 int retval; | |
801 | |
5351 | 802 OCTAVE_LOCAL_BUFFER (octave_idx_type, dims, hdims); |
803 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
804 retval = H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
805 H5P_DEFAULT, dims); |
4805 | 806 if (retval >= 0) |
807 { | |
808 d.resize (hdims); | |
809 for (hsize_t i = 0; i < hdims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
810 d(i) = dims[i]; |
4805 | 811 } |
812 | |
813 H5Sclose (space_id); | |
814 H5Dclose (data_hid); | |
815 | |
816 return (retval == 0 ? hdims : retval); | |
817 } | |
818 | |
4634 | 819 // save_type_to_hdf5 is not currently used, since hdf5 doesn't yet support |
820 // automatic float<->integer conversions: | |
821 | |
822 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS | |
823 | |
824 // return the HDF5 type id corresponding to the Octave save_type | |
825 | |
4687 | 826 hid_t |
4634 | 827 save_type_to_hdf5 (save_type st) |
828 { | |
829 switch (st) | |
830 { | |
831 case LS_U_CHAR: | |
832 return H5T_NATIVE_UCHAR; | |
833 | |
834 case LS_U_SHORT: | |
835 return H5T_NATIVE_USHORT; | |
836 | |
837 case LS_U_INT: | |
838 return H5T_NATIVE_UINT; | |
839 | |
840 case LS_CHAR: | |
841 return H5T_NATIVE_CHAR; | |
842 | |
843 case LS_SHORT: | |
844 return H5T_NATIVE_SHORT; | |
845 | |
846 case LS_INT: | |
847 return H5T_NATIVE_INT; | |
848 | |
849 case LS_FLOAT: | |
850 return H5T_NATIVE_FLOAT; | |
851 | |
852 case LS_DOUBLE: | |
853 default: | |
854 return H5T_NATIVE_DOUBLE; | |
855 } | |
856 } | |
857 #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */ | |
858 | |
859 // Add the data from TC to the HDF5 location loc_id, which could | |
860 // be either a file or a group within a file. Return true if | |
861 // successful. This function calls itself recursively for lists | |
862 // (stored as HDF5 groups). | |
863 | |
4687 | 864 bool |
4634 | 865 add_hdf5_data (hid_t loc_id, const octave_value& tc, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
866 const std::string& name, const std::string& doc, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
867 bool mark_as_global, bool save_as_floats) |
4634 | 868 { |
869 hsize_t dims[3]; | |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
870 hid_t type_id, space_id, data_id, data_type_id; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
871 type_id = space_id = data_id = data_type_id = -1; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
872 |
4687 | 873 bool retval = false; |
874 octave_value val = tc; | |
8401
712cfdc2e417
allow saving diagonal & permutation matrices to hdf5 as full
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
875 // FIXME: diagonal & permutation matrices currently don't know how to save |
712cfdc2e417
allow saving diagonal & permutation matrices to hdf5 as full
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
876 // themselves, so we convert them first to normal matrices using A = A(:,:). |
712cfdc2e417
allow saving diagonal & permutation matrices to hdf5 as full
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
877 // This is a temporary hack. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
878 if (val.is_diag_matrix () || val.is_perm_matrix () |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
879 || val.type_id () == octave_lazy_index::static_type_id ()) |
8914
354179c24c79
fix hdf5 saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8676
diff
changeset
|
880 val = val.full_value (); |
8401
712cfdc2e417
allow saving diagonal & permutation matrices to hdf5 as full
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
881 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
882 std::string t = val.type_name (); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
883 #if HAVE_HDF5_18 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
884 data_id = H5Gcreate (loc_id, name.c_str (), H5P_DEFAULT, H5P_DEFAULT, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
885 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
886 #else |
4687 | 887 data_id = H5Gcreate (loc_id, name.c_str (), 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
888 #endif |
4687 | 889 if (data_id < 0) |
890 goto error_cleanup; | |
4634 | 891 |
4687 | 892 // attach the type of the variable |
893 type_id = H5Tcopy (H5T_C_S1); H5Tset_size (type_id, t.length () + 1); | |
894 if (type_id < 0) | |
895 goto error_cleanup; | |
4634 | 896 |
4687 | 897 dims[0] = 0; |
5760 | 898 space_id = H5Screate_simple (0 , dims, 0); |
4687 | 899 if (space_id < 0) |
900 goto error_cleanup; | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
901 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
902 data_type_id = H5Dcreate (data_id, "type", type_id, space_id, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
903 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
904 #else |
4687 | 905 data_type_id = H5Dcreate (data_id, "type", type_id, space_id, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
906 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
907 if (data_type_id < 0 || H5Dwrite (data_type_id, type_id, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
908 H5P_DEFAULT, t.c_str ()) < 0) |
4687 | 909 goto error_cleanup; |
4634 | 910 |
4687 | 911 // Now call the real function to save the variable |
912 retval = val.save_hdf5 (data_id, "value", save_as_floats); | |
4634 | 913 |
914 // attach doc string as comment: | |
4687 | 915 if (retval && doc.length () > 0 |
4634 | 916 && H5Gset_comment (loc_id, name.c_str (), doc.c_str ()) < 0) |
4687 | 917 retval = false; |
4634 | 918 |
919 // if it's global, add an attribute "OCTAVE_GLOBAL" with value 1 | |
4687 | 920 if (retval && mark_as_global) |
4634 | 921 retval = hdf5_add_attr (data_id, "OCTAVE_GLOBAL") >= 0; |
922 | |
4687 | 923 // We are saving in the new variable format, so mark it |
924 if (retval) | |
925 retval = hdf5_add_attr (data_id, "OCTAVE_NEW_FORMAT") >= 0; | |
926 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
927 error_cleanup: |
4634 | 928 |
4687 | 929 if (data_type_id >= 0) |
930 H5Dclose (data_type_id); | |
4634 | 931 |
4687 | 932 if (type_id >= 0) |
933 H5Tclose (type_id); | |
4634 | 934 |
935 if (space_id >= 0) | |
936 H5Sclose (space_id); | |
937 | |
4687 | 938 if (data_id >= 0) |
939 H5Gclose (data_id); | |
940 | |
941 if (! retval) | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
942 error ("save: error while writing '%s' to hdf5 file", name.c_str ()); |
4634 | 943 |
944 return retval; | |
945 } | |
946 | |
947 // Write data from TC in HDF5 (binary) format to the stream OS, | |
948 // which must be an hdf5_ofstream, returning true on success. | |
949 | |
950 bool | |
951 save_hdf5_data (std::ostream& os, const octave_value& tc, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
952 const std::string& name, const std::string& doc, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
953 bool mark_as_global, bool save_as_floats) |
4634 | 954 { |
5760 | 955 hdf5_ofstream& hs = dynamic_cast<hdf5_ofstream&> (os); |
4634 | 956 |
957 return add_hdf5_data (hs.file_id, tc, name, doc, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
958 mark_as_global, save_as_floats); |
4634 | 959 } |
960 | |
961 #endif |