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