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