annotate libinterp/corefcn/ls-hdf5.cc @ 23807:336f89b6208b

Use character literals 'c' rather than string literals "c" when possible. Better performance when string constructor isn't required. * Figure.cc, __init_qt__.cc, files-dock-widget.cc, file-editor-tab.cc, file-editor.cc, octave-qscintilla.cc, main-window.cc, octave-dock-widget.cc, octave-qt-link.cc, parser.cc, webinfo.cc, resource-manager.cc, settings-dialog.cc, workspace-view.cc, __magick_read__.cc, balance.cc, debug.cc, dynamic-ld.cc, ft-text-renderer.cc, gl-render.cc, gl2ps-print.cc, graphics.cc, hook-fcn.h, input.cc, load-path.cc, load-save.cc, ls-hdf5.cc, oct-hist.cc, oct-stream.cc, pager.cc, pr-output.cc, qz.cc, symtab.cc, symtab.h, tril.cc, __delaunayn__.cc, __init_fltk__.cc, __voronoi__.cc, audioread.cc, ccolamd.cc, colamd.cc, convhulln.cc, ov-base-int.cc, ov-base-mat.cc, ov-base-scalar.cc, ov-base.cc, ov-bool-mat.cc, ov-cell.cc, ov-class.cc, ov-classdef.cc, ov-colon.cc, ov-complex.cc, ov-cx-mat.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-fcn.h, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-java.cc, ov-oncleanup.cc, ov-range.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-str-mat.cc, ov-struct.cc, ov-usr-fcn.cc, ov.cc, octave.cc, bp-table.cc, jit-ir.cc, jit-ir.h, jit-typeinfo.cc, pt-funcall.cc, pt-idx.cc, pt-pr-code.cc, pt.h, Array.cc, CDiagMatrix.cc, CMatrix.cc, CNDArray.cc, CRowVector.cc, CSparse.cc, Range.cc, boolSparse.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc, fDiagMatrix.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc, idx-vector.cc, intNDArray.cc, CollocWt.cc, DASPK.cc, DASRT.cc, DASSL.cc, LSODE.cc, oct-time.cc, cmd-hist.cc, kpse.cc, lo-array-errwarn.cc, lo-regexp.cc, lo-utils.cc, str-vec.cc, url-transfer.cc, main-cli.cc, main-gui.cc, mkoctfile.in.cc: Replace 1-character string literals "c" with the character literal 'c'.
author Rik <rik@octave.org>
date Fri, 28 Jul 2017 15:40:00 -0700
parents 4f12819a634f
children 057a894914df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1 /*
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 1996-2017 John W. Eaton
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
4
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
6
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
8 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
10 (at your option) any later version.
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
15 GNU General Public License for more details.
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
16
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6276
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6276
diff changeset
19 <http://www.gnu.org/licenses/>.
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
20
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
21 */
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
22
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
23 // Author: Steven G. Johnson <stevenj@alum.mit.edu>
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
24
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
25 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21211
diff changeset
26 # include "config.h"
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
27 #endif
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
28
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
29 #if defined (HAVE_HDF5)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
30
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
31 #include <cctype>
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
32
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
33 #include <iomanip>
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
34 #include <iostream>
22028
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
35 #include <limits>
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
36 #include <string>
4726
14dc2267c343 [project @ 2004-01-23 20:04:35 by jwe]
jwe
parents: 4696
diff changeset
37 #include <vector>
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
38
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
39 #include "byte-swap.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
40 #include "data-conv.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
41 #include "file-ops.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
42 #include "glob-match.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
43 #include "lo-mappers.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
44 #include "mach-info.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
45 #include "oct-env.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
46 #include "oct-time.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
47 #include "quit.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
48 #include "str-vec.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 7336
diff changeset
49 #include "oct-locbuf.h"
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
50
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
51 #include "Cell.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
52 #include "defun.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
53 #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
54 #include "errwarn.h"
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
55 #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
56 #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
57 #include "ovl.h"
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
58 #include "oct-map.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
59 #include "ov-cell.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
60 #include "pager.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
61 #include "pt-exp.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
62 #include "sysdep.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
63 #include "unwind-prot.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
64 #include "utils.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
65 #include "variables.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
66 #include "version.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
67 #include "dMatrix.h"
10325
8b3cfc1288e2 implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
68 #include "ov-lazy-idx.h"
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
69
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
70 #include "ls-utils.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
71 #include "ls-hdf5.h"
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
72
22028
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
73 #if defined (HAVE_HDF5)
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
74
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
75 static hid_t
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
76 check_hdf5_id_value (octave_hdf5_id id, const char *who)
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
77 {
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
78 if (id > std::numeric_limits<hid_t>::max ())
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
79 error ("%s: internal error: ID too large for hid_t", who);
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
80
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
81 return static_cast<hid_t> (id);
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
82 }
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
83
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
84 #endif
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
85
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
86 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
87 : 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
88 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
89 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
90
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
91 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
92 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
93 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
94 {
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 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
96 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
97 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
98 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
99 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
100 }
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 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
102 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
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 current_item = 0;
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
105
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
106 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
107 err_disabled_feature ("hdf5_fstreambase", "HDF5");
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
108 #endif
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
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
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
111 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
112 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
113 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
114 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
115
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 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
117 {
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
118 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
119 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
120 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
121 }
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
122
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
123 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
124 // This shouldn't happen because construction of hdf5_fstreambase
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
125 // objects is supposed to be impossible if HDF5 is not available.
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
126
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
127 panic_impossible ();
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
128 #endif
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
129 }
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
130
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
131 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
132 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
133 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
134 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
135
20264
bfe66db8addb don't include hdf5.h or use HDF5 typedefs in public header files (bug #43180)
John W. Eaton <jwe@octave.org>
parents: 19863
diff changeset
136 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
137
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
138 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
139 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
140 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
141 {
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
142 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
143 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
144 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
145 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
146 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
147 }
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
148 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
149 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
150
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
151 current_item = 0;
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
152
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
153 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
154 // This shouldn't happen because construction of hdf5_fstreambase
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
155 // objects is supposed to be impossible if HDF5 is not available.
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
156
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
157 panic_impossible ();
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
158 #endif
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
159 }
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
160
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
161 static std::string
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
162 make_valid_identifier (const std::string& nm)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
163 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
164 std::string retval;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
165
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
166 size_t nm_len = nm.length ();
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
167
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
168 if (nm_len > 0)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
169 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
170 if (! isalpha (nm[0]))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
171 retval += '_';
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
172
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
173 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
174 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
175 char c = nm[i];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
176 retval += (isalnum (c) || c == '_') ? c : '_';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
177 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
178 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
179
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
180 return retval;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
181 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
182
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
183 // Given two compound types t1 and t2, determine whether they
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
184 // are compatible for reading/writing. This function only
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
185 // works for non-nested types composed of simple elements (ints, floats...),
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
186 // which is all we need it for
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
187
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
188 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
189 hdf5_types_compatible (octave_hdf5_id t1, octave_hdf5_id t2)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
190 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
191 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
192
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
193 int n;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
194 if ((n = H5Tget_nmembers (t1)) != H5Tget_nmembers (t2))
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
195 return false;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
196
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
197 for (int i = 0; i < n; ++i)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
198 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
199 hid_t mt1 = H5Tget_member_type (t1, i);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
200 hid_t mt2 = H5Tget_member_type (t2, i);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
201
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
202 if (H5Tget_class (mt1) != H5Tget_class (mt2))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
203 return false;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
204
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
205 H5Tclose (mt2);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
206 H5Tclose (mt1);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
207 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
208
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
209 return true;
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
210
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
211 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
212 err_disabled_feature ("hdf5_types_compatible", "HDF5");
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
213 #endif
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
214 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
215
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
216 // Return true if loc_id has the attribute named attr_name, and false
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
217 // otherwise.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
218
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
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_check_attr (octave_hdf5_id loc_id, const char *attr_name)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
221 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
222 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
223
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
224 bool retval = false;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
225
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
226 // we have to pull some shenanigans here to make sure
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
227 // HDF5 doesn't print out all sorts of error messages if we
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
228 // call H5Aopen for a non-existing attribute
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
229
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
230 H5E_auto_t err_func;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
231 void *err_func_data;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
232
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
233 // turn off error reporting temporarily, but save the error
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
234 // reporting function:
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
235
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
236 #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
237 H5Eget_auto (octave_H5E_DEFAULT, &err_func, &err_func_data);
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
238 H5Eset_auto (octave_H5E_DEFAULT, nullptr, nullptr);
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
239 #else
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
240 H5Eget_auto (&err_func, &err_func_data);
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
241 H5Eset_auto (nullptr, nullptr);
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
242 #endif
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
243
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
244 hid_t attr_id = H5Aopen_name (loc_id, attr_name);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
245
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
246 if (attr_id >= 0)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
247 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
248 // successful
11176
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
249 retval = true;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
250 H5Aclose (attr_id);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
251 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
252
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
253 // 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
254 #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
255 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
256 #else
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
257 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
258 #endif
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
259 return retval;
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
260
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
261 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
262 err_disabled_feature ("hdf5_check_attr", "HDF5");
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
263 #endif
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
264 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
265
11176
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
266 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
267 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
268 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
269 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
270 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
271
11176
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
272 bool retval = false;
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
273
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
274 // 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
275 // 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
276 // 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
277
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
278 H5E_auto_t err_func;
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
279 void *err_func_data;
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
280
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
281 // 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
282 // reporting function:
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
283
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
284 #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
285 H5Eget_auto (octave_H5E_DEFAULT, &err_func, &err_func_data);
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
286 H5Eset_auto (octave_H5E_DEFAULT, nullptr, nullptr);
11176
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
287 #else
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
288 H5Eget_auto (&err_func, &err_func_data);
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
289 H5Eset_auto (nullptr, nullptr);
11176
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
290 #endif
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
291
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
292 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
293
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
294 if (attr_id >= 0)
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
295 {
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
296 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
297
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
298 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
299
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
300 if (rank == 0)
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
301 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
302 H5Aclose (attr_id);
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
303 }
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
304
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
305 // 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
306 #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
307 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
308 #else
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
309 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
310 #endif
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
311 return retval;
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
312
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
313 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
314 err_disabled_feature ("hdf5_get_scalar_attr", "HDF5");
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
315 #endif
11176
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
316 }
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
317
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
318 // The following subroutines creates an HDF5 representations of the way
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
319 // 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
320 // NUM_TYPE is the HDF5 numeric type to use for storage (e.g.
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
321 // H5T_NATIVE_DOUBLE to save as 'double'). Note that any necessary
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
322 // conversions are handled automatically by HDF5.
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
323
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
324 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
325 hdf5_make_complex_type (octave_hdf5_id num_type)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
326 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
327 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
328
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
329 hid_t type_id = H5Tcreate (H5T_COMPOUND, sizeof (double) * 2);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
330
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
331 H5Tinsert (type_id, "real", 0 * sizeof (double), num_type);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
332 H5Tinsert (type_id, "imag", 1 * sizeof (double), num_type);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
333
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
334 return type_id;
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
335
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
336 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
337 err_disabled_feature ("hdf5_make_complex_type", "HDF5");
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
338 #endif
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
339 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
340
22028
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
341 #if defined (HAVE_HDF5)
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
342
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
343 // This function is designed to be passed to H5Giterate, which calls it
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
344 // on each data item in an HDF5 file. For the item whose name is NAME in
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
345 // the group GROUP_ID, this function sets dv->tc to an Octave representation
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
346 // of that item. (dv must be a pointer to hdf5_callback_data.) (It also
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
347 // sets the other fields of dv).
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
348 //
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
349 // It returns 1 on success (in which case H5Giterate stops and returns),
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
350 // -1 on error, and 0 to tell H5Giterate to continue on to the next item
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
351 // (e.g., if NAME was a data type we don't recognize).
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
352
22028
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
353 static herr_t
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
354 hdf5_read_next_data_internal (hid_t group_id, const char *name, void *dv)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
355 {
19739
3fa35defe495 Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
356 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
357 hid_t type_id = -1;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
358 hid_t type_class_id = -1;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
359 hid_t data_id = -1;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
360 hid_t subgroup_id = -1;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
361 hid_t space_id = -1;;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
362
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
363 H5G_stat_t info;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
364 herr_t retval = 0;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
365 bool ident_valid = valid_identifier (name);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
366
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
367 std::string vname = name;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
368
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
369 // Allow identifiers as all digits so we can load lists saved by
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
370 // earlier versions of Octave.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
371
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18676
diff changeset
372 if (! ident_valid)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
373 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
374 // fix the identifier, replacing invalid chars with underscores
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
375 vname = make_valid_identifier (vname);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
376
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
377 // 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
378 ident_valid = valid_identifier (vname);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
379 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
380
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
381 H5Gget_objinfo (group_id, name, 1, &info);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
382
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
383 if (info.type == H5G_GROUP && ident_valid)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
384 {
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
385 #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
386 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
387 #else
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
388 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
389 #endif
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
390
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
391 if (subgroup_id < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
392 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
393 retval = subgroup_id;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
394 goto done;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
395 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
396
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
397 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
398 {
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
399 #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
400 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
401 #else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
402 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
403 #endif
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
404
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
405 if (data_id < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
406 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
407 retval = data_id;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
408 goto done;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
409 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
410
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
411 type_id = H5Dget_type (data_id);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
412
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
413 type_class_id = H5Tget_class (type_id);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
414
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
415 if (type_class_id != H5T_STRING)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
416 goto done;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
417
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
418 space_id = H5Dget_space (data_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
419 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
420
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
421 if (rank != 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
422 goto done;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
423
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
424 int slen = H5Tget_size (type_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
425 if (slen < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
426 goto done;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
427
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
428 OCTAVE_LOCAL_BUFFER (char, typ, slen);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
429
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
430 // 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
431 hid_t st_id = H5Tcopy (H5T_C_S1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
432 H5Tset_size (st_id, slen);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
433
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
434 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
435 typ) < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
436 goto done;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
437
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
438 H5Tclose (st_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
439 H5Dclose (data_id);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
440
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
441 d->tc = octave_value_typeinfo::lookup_type (typ);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
442
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
443 retval = (d->tc.load_hdf5 (subgroup_id, "value") ? 1 : -1);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
444
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
445 // check for OCTAVE_GLOBAL attribute:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
446 d->global = hdf5_check_attr (subgroup_id, "OCTAVE_GLOBAL");
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
447
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
448 H5Gclose (subgroup_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
449 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
450 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
451 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
452 // 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
453 // default (since that preserves name information), and an
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
454 // octave list otherwise.
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
455
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
456 if (hdf5_check_attr (subgroup_id, "OCTAVE_LIST"))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
457 d->tc = octave_value_typeinfo::lookup_type ("list");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
458 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
459 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
460
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
461 // check for OCTAVE_GLOBAL attribute:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
462 d->global = hdf5_check_attr (subgroup_id, "OCTAVE_GLOBAL");
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
463
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
464 H5Gclose (subgroup_id);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
465
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
466 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
467 }
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
468
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
469 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
470 else if (info.type == H5G_DATASET && ident_valid)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
471 {
20449
df4165dfc676 maint: Fix misspelled word compatibility in code comments.
Rik <rik@octave.org>
parents: 20264
diff changeset
472 // 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
473 #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
474 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
475 #else
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
476 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
477 #endif
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
478
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
479 if (data_id < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
480 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
481 retval = data_id;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
482 goto done;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
483 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
484
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
485 type_id = H5Dget_type (data_id);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
486
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
487 type_class_id = H5Tget_class (type_id);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
488
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
489 if (type_class_id == H5T_FLOAT)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
490 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
491 space_id = H5Dget_space (data_id);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
492
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
493 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
494
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
495 if (rank == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
496 d->tc = octave_value_typeinfo::lookup_type ("scalar");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
497 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
498 d->tc = octave_value_typeinfo::lookup_type ("matrix");
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
499
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
500 H5Sclose (space_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
501 }
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
502 else if (type_class_id == H5T_INTEGER)
10315
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 // What integer type do we really have..
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
505 std::string int_typ;
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
506 #if defined (HAVE_H5T_GET_NATIVE_TYPE)
17861
870f3e12e163 maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents: 17787
diff changeset
507 // 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
508 // 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
509
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
510 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
511 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
512 case H5T_NATIVE_CHAR:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
513 int_typ = "int8 ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
514 break;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
515
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
516 case H5T_NATIVE_SHORT:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
517 int_typ = "int16 ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
518 break;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
519
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
520 case H5T_NATIVE_INT:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
521 case H5T_NATIVE_LONG:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
522 int_typ = "int32 ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
523 break;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
524
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
525 case H5T_NATIVE_LLONG:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
526 int_typ = "int64 ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
527 break;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
528
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
529 case H5T_NATIVE_UCHAR:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
530 int_typ = "uint8 ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
531 break;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
532
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
533 case H5T_NATIVE_USHORT:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
534 int_typ = "uint16 ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
535 break;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
536
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
537 case H5T_NATIVE_UINT:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
538 case H5T_NATIVE_ULONG:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
539 int_typ = "uint32 ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
540 break;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
541
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
542 case H5T_NATIVE_ULLONG:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
543 int_typ = "uint64 ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
544 break;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
545 }
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
546 #else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
547 hid_t int_sign = H5Tget_sign (type_id);
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
548
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
549 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
550 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
551 else
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 if (int_sign == H5T_SGN_NONE)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23796
diff changeset
554 int_typ.push_back ('u');
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
555 int_typ.append ("int");
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
556
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
557 int slen = H5Tget_size (type_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
558 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
559 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
560 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
561 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
562 switch (slen)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
563 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
564 case 1:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
565 int_typ.append ("8 ");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
566 break;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
567
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
568 case 2:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
569 int_typ.append ("16 ");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
570 break;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
571
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
572 case 4:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
573 int_typ.append ("32 ");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
574 break;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
575
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
576 case 8:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
577 int_typ.append ("64 ");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
578 break;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
579
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
580 default:
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
581 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
582 name);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
583 int_typ = "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
584 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
585 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
586 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
587 }
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
588 #endif
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
589 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
590 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
591 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
592 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
593 // Matrix or scalar?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
594 space_id = H5Dget_space (data_id);
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
595
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
596 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
597
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
598 if (rank == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
599 int_typ.append ("scalar");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
600 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
601 int_typ.append ("matrix");
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4805
diff changeset
602
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
603 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
604 H5Sclose (space_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
605 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
606 }
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
607 else if (type_class_id == H5T_STRING)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
608 d->tc = octave_value_typeinfo::lookup_type ("string");
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
609 else if (type_class_id == H5T_COMPOUND)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
610 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
611 hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
612
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
613 if (hdf5_types_compatible (type_id, complex_type))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
614 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
615 // read complex matrix or scalar variable
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
616 space_id = H5Dget_space (data_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
617 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
618
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
619 if (rank == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
620 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
621 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
622 d->tc = octave_value_typeinfo::lookup_type ("complex matrix");
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
623
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
624 H5Sclose (space_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
625 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
626 else
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
627 // Assume that if its not complex its a range.
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
628 // If its not, it'll be rejected later in the range code.
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
629 d->tc = octave_value_typeinfo::lookup_type ("range");
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
630
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
631 H5Tclose (complex_type);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
632 }
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
633 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
634 {
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
635 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
636 retval = 0; // unknown datatype; skip
18676
5bd1ca29c5f0 Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents: 18100
diff changeset
637 return retval;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
638 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
639
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
640 // check for OCTAVE_GLOBAL attribute:
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
641 d->global = hdf5_check_attr (data_id, "OCTAVE_GLOBAL");
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
642
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
643 H5Tclose (type_id);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
644 H5Dclose (data_id);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
645
9881
b3089dba88bf Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents: 8920
diff changeset
646 retval = (d->tc.load_hdf5 (group_id, name) ? 1 : -1);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
647 }
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
648
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20945
diff changeset
649 if (! ident_valid)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
650 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
651 // should we attempt to handle invalid identifiers by converting
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
652 // 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
653 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
654 name);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
655 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
656
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
657 done:
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
658 if (retval < 0)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
659 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
660
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
661 if (retval > 0)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
662 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
663 // get documentation string, if any:
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23470
diff changeset
664 int comment_length = H5Gget_comment (group_id, name, 0, nullptr);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
665
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
666 if (comment_length > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
667 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
668 OCTAVE_LOCAL_BUFFER (char, tdoc, comment_length);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
669 H5Gget_comment (group_id, name, comment_length, tdoc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
670 d->doc = tdoc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
671 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
672 else if (vname != name)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
673 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
674 // the name was changed; store the original name
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
675 // as the documentation string:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
676 d->doc = name;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
677 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
678
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
679 // copy name (actually, vname):
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
680 d->name = vname;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
681 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
682
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
683 return retval;
22028
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
684 }
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
685
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
686 #endif
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
687
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
688 octave_hdf5_err
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
689 hdf5_read_next_data (octave_hdf5_id group_id, const char *name, void *dv)
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
690 {
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
691 #if defined (HAVE_HDF5)
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
692
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
693 hid_t new_id = check_hdf5_id_value (group_id, "hdf5_read_next_data");
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
694
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
695 return hdf5_read_next_data_internal (new_id, name, dv);
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
696
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
697 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
698 err_disabled_feature ("hdf5_read_next_data", "HDF5");
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
699 #endif
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
700 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
701
22028
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
702 octave_hdf5_err
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23440
diff changeset
703 hdf5_h5g_iterate (octave_hdf5_id loc_id, const char *name, int *idx,
22028
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
704 void *operator_data)
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
705 {
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
706 #if defined (HAVE_HDF5)
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
707
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
708 hid_t new_id = check_hdf5_id_value (loc_id, "hdf5_h5g_iterate");
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
709
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
710 return H5Giterate (new_id, name, idx, hdf5_read_next_data_internal,
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
711 operator_data);
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
712
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
713 #else
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
714 err_disabled_feature ("hdf5_h5g_iterate", "HDF5");
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
715 #endif
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
716 }
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
717
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23455
diff changeset
718 // Read the next Octave variable from the stream IS, which must really be an
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23455
diff changeset
719 // hdf5_ifstream. Return the variable value in tc, its doc string in doc, and
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23455
diff changeset
720 // whether it is global in global. The return value is the name of the
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23455
diff changeset
721 // variable, or NULL if none were found or there was an error.
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
722 std::string
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
723 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
724 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
725 const string_vector& argv, int argv_idx, int argc)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
726 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
727 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
728
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
729 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
730
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
731 std::string retval;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
732
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
733 doc.resize (0);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
734
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5351
diff changeset
735 hdf5_ifstream& hs = dynamic_cast<hdf5_ifstream&> (is);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
736 hdf5_callback_data d;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
737
4696
fcab389ad291 [project @ 2004-01-15 02:11:59 by jwe]
jwe
parents: 4687
diff changeset
738 herr_t H5Giterate_retval = -1;
fcab389ad291 [project @ 2004-01-15 02:11:59 by jwe]
jwe
parents: 4687
diff changeset
739
fcab389ad291 [project @ 2004-01-15 02:11:59 by jwe]
jwe
parents: 4687
diff changeset
740 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
741 #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
742 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
743 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
744 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
745 #endif
5060
34a904ac130d [project @ 2004-11-02 03:08:10 by jwe]
jwe
parents: 4948
diff changeset
746 H5Gget_num_objs (group_id, &num_obj);
34a904ac130d [project @ 2004-11-02 03:08:10 by jwe]
jwe
parents: 4948
diff changeset
747 H5Gclose (group_id);
17709
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
748
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
749 // For large datasets and out-of-core functionality,
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
750 // 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
751 bool load_named_vars = argv_idx < argc;
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
752 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
753 {
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
754 std::vector<char> var_name;
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
755 bool found = false;
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
756 size_t len = 0;
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
757
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23470
diff changeset
758 len = H5Gget_objname_by_idx (hs.file_id, hs.current_item, nullptr, 0);
17709
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
759 var_name.resize (len+1);
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18676
diff changeset
760 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
761
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
762 for (int i = argv_idx; i < argc; i++)
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
763 {
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
764 glob_match pattern (argv[i]);
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
765 if (pattern.match (std::string (&var_name[0])))
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
766 {
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
767 found = true;
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
768 break;
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
769 }
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
770 }
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
771
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
772 if (found)
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
773 break;
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
774
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
775 hs.current_item++;
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
776 }
5415a9cd61d4 Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents: 16892
diff changeset
777
4696
fcab389ad291 [project @ 2004-01-15 02:11:59 by jwe]
jwe
parents: 4687
diff changeset
778 if (hs.current_item < static_cast<int> (num_obj))
fcab389ad291 [project @ 2004-01-15 02:11:59 by jwe]
jwe
parents: 4687
diff changeset
779 H5Giterate_retval = H5Giterate (hs.file_id, "/", &hs.current_item,
22028
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
780 hdf5_read_next_data_internal, &d);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
781
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
782 if (H5Giterate_retval > 0)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
783 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
784 global = d.global;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
785 tc = d.tc;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
786 doc = d.doc;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
787 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
788 else
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
789 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
790 // an error occurred (H5Giterate_retval < 0) or there are no
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
791 // more datasets print an error message if retval < 0?
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
792 // hdf5_read_next_data already printed one, probably.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
793 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
794
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
795 if (! d.name.empty ())
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
796 retval = d.name;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
797
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
798 return retval;
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
799
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
800 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
801 err_disabled_feature ("read_hdf5_data", "HDF5");
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
802 #endif
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
803 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
804
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
805 // Add an attribute named attr_name to loc_id (a simple scalar
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
806 // 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
807 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
808 hdf5_add_attr (octave_hdf5_id loc_id, const char *attr_name)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
809 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
810 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
811
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
812 herr_t retval = 0;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
813
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
814 hid_t as_id = H5Screate (H5S_SCALAR);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
815
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
816 if (as_id >= 0)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
817 {
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
818 #if defined (HAVE_HDF5_18)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
819 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
820 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
821 #else
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
822 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
823 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
824 #endif
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
825 if (a_id >= 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
826 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
827 unsigned char attr_val = 1;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
828
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
829 retval = H5Awrite (a_id, H5T_NATIVE_UCHAR, &attr_val);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
830
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
831 H5Aclose (a_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
832 }
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
833 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
834 retval = a_id;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
835
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
836 H5Sclose (as_id);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
837 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
838 else
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
839 retval = as_id;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
840
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
841 return retval;
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
842
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
843 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
844 err_disabled_feature ("hdf5_add_attr", "HDF5");
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
845 #endif
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
846 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
847
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
848 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
849 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
850 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
851 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
852 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
853
11176
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
854 herr_t retval = 0;
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
855
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
856 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
857
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
858 if (as_id >= 0)
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
859 {
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
860 #if defined (HAVE_HDF5_18)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
861 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
862 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
863 #else
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
864 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
865 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
866 #endif
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
867 if (a_id >= 0)
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
868 {
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
869 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
870
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
871 H5Aclose (a_id);
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
872 }
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
873 else
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
874 retval = a_id;
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
875
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
876 H5Sclose (as_id);
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
877 }
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
878 else
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
879 retval = as_id;
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
880
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
881 return retval;
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
882
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
883 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
884 err_disabled_feature ("hdf5_add_scalar_attr", "HDF5");
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
885 #endif
11176
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
886 }
2271261f088a Address precision issue in ranges saved to HDF5 files
David Bateman <dbateman@free.fr>
parents: 10325
diff changeset
887
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
888 // Save an empty matrix, if needed. Returns
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
889 // > 0 Saved empty matrix
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
890 // = 0 Not an empty matrix; did nothing
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
891 // < 0 Error condition
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
892 int
23440
f15f0d8b78c8 pass dim_vector as const reference, not by value
John W. Eaton <jwe@octave.org>
parents: 23433
diff changeset
893 save_hdf5_empty (octave_hdf5_id loc_id, const char *name, const dim_vector& d)
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
894 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
895 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
896
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
897 hsize_t sz = d.length ();
6276
d26c558691cd [project @ 2007-02-07 09:01:24 by jwe]
jwe
parents: 5775
diff changeset
898 OCTAVE_LOCAL_BUFFER (octave_idx_type, dims, sz);
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
899 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
900 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
901 hid_t data_hid = -1;
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
902 int retval;
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
903 for (hsize_t i = 0; i < sz; i++)
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
904 {
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
905 dims[i] = d(i);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
906 if (dims[i] < 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
907 empty = true;
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
908 }
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
909
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20945
diff changeset
910 if (! empty)
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
911 return 0;
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
912
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23470
diff changeset
913 space_hid = H5Screate_simple (1, &sz, nullptr);
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
914 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
915 #if defined (HAVE_HDF5_18)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
916 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
917 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
918 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
919 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
920 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
921 #endif
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
922 if (data_hid < 0)
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
923 {
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
924 H5Sclose (space_hid);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
925 return data_hid;
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
926 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
927
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
928 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
929 octave_H5P_DEFAULT, dims) >= 0;
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
930
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
931 H5Dclose (data_hid);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
932 H5Sclose (space_hid);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
933
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
934 if (retval >= 0)
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
935 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
936
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
937 return (retval == 0 ? 1 : retval);
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
938
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
939 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
940 err_disabled_feature ("save_hdf5_empty", "HDF5");
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
941 #endif
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
942 }
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
943
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
944 // Load an empty matrix, if needed. Returns
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
945 // > 0 loaded empty matrix, dimensions returned
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
946 // = 0 Not an empty matrix; did nothing
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
947 // < 0 Error condition
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
948 int
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
949 load_hdf5_empty (octave_hdf5_id loc_id, const char *name, dim_vector& d)
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
950 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
951 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
952
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
953 if (! hdf5_check_attr (loc_id, "OCTAVE_EMPTY_MATRIX"))
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
954 return 0;
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
955
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
956 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
957 #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
958 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
959 #else
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
960 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
961 #endif
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
962 hid_t space_id = H5Dget_space (data_hid);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
963 H5Sget_simple_extent_dims (space_id, &hdims, &maxdims);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
964 int retval;
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
965
5351
05adf9de7657 [project @ 2005-05-16 20:07:36 by dbateman]
dbateman
parents: 5307
diff changeset
966 OCTAVE_LOCAL_BUFFER (octave_idx_type, dims, hdims);
05adf9de7657 [project @ 2005-05-16 20:07:36 by dbateman]
dbateman
parents: 5307
diff changeset
967
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20955
diff changeset
968 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
969 octave_H5P_DEFAULT, dims);
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
970 if (retval >= 0)
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
971 {
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
972 d.resize (hdims);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
973 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
974 d(i) = dims[i];
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
975 }
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
976
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
977 H5Sclose (space_id);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
978 H5Dclose (data_hid);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
979
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
980 return (retval == 0 ? hdims : retval);
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
981
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
982 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
983 err_disabled_feature ("load_hdf5_empty", "HDF5");
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
984 #endif
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
985 }
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
986
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
987 // save_type_to_hdf5 is not currently used, since hdf5 doesn't yet support
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
988 // automatic float<->integer conversions:
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
989
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
990 // return the HDF5 type id corresponding to the Octave save_type
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
991
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
992 octave_hdf5_id
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
993 save_type_to_hdf5 (save_type st)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
994 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
995 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
996 # if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
997
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
998 switch (st)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
999 {
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1000 case LS_U_CHAR:
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1001 return H5T_NATIVE_UCHAR;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1002
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1003 case LS_U_SHORT:
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1004 return H5T_NATIVE_USHORT;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1005
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1006 case LS_U_INT:
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1007 return H5T_NATIVE_UINT;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1008
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1009 case LS_CHAR:
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1010 return H5T_NATIVE_CHAR;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1011
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1012 case LS_SHORT:
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1013 return H5T_NATIVE_SHORT;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1014
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1015 case LS_INT:
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1016 return H5T_NATIVE_INT;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1017
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1018 case LS_FLOAT:
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1019 return H5T_NATIVE_FLOAT;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1020
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1021 case LS_DOUBLE:
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1022 default:
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1023 return H5T_NATIVE_DOUBLE;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1024 }
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1025
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1026 # else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21682
diff changeset
1027
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21682
diff changeset
1028 octave_unused_parameter (st);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21682
diff changeset
1029
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1030 return -1;
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21682
diff changeset
1031
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1032 # endif
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21682
diff changeset
1033
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1034 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21682
diff changeset
1035
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21682
diff changeset
1036 octave_unused_parameter (st);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21682
diff changeset
1037
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1038 err_disabled_feature ("save_type_to_hdf5", "HDF5");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21682
diff changeset
1039
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1040 #endif
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1041 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1042
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1043 // Add the data from TC to the HDF5 location loc_id, which could
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1044 // be either a file or a group within a file. Return true if
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1045 // successful. This function calls itself recursively for lists
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1046 // (stored as HDF5 groups).
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1047
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1048 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
1049 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
1050 const std::string& name, const std::string& doc,
23470
a41fdb801db6 use mark_global and mark_persistent consistently
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
1051 bool mark_global, bool save_as_floats)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1052 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1053 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1054
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1055 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
1056 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
1057 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
1058
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1059 bool retval = false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1060 octave_value val = tc;
8401
712cfdc2e417 allow saving diagonal & permutation matrices to hdf5 as full
Jaroslav Hajek <highegg@gmail.com>
parents: 8377
diff changeset
1061 // 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
1062 // 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
1063 // This is a temporary hack.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1064 if (val.is_diag_matrix () || val.is_perm_matrix ()
10325
8b3cfc1288e2 implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1065 || 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
1066 val = val.full_value ();
8401
712cfdc2e417 allow saving diagonal & permutation matrices to hdf5 as full
Jaroslav Hajek <highegg@gmail.com>
parents: 8377
diff changeset
1067
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
1068 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
1069 #if defined (HAVE_HDF5_18)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1070 data_id = H5Gcreate (loc_id, name.c_str (), octave_H5P_DEFAULT,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1071 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
1072 #else
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1073 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
1074 #endif
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1075 if (data_id < 0)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1076 goto error_cleanup;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1077
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1078 // attach the type of the variable
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1079 type_id = H5Tcopy (H5T_C_S1); H5Tset_size (type_id, t.length () + 1);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1080 if (type_id < 0)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1081 goto error_cleanup;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1082
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1083 dims[0] = 0;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23470
diff changeset
1084 space_id = H5Screate_simple (0 , dims, nullptr);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1085 if (space_id < 0)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1086 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
1087 #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
1088 data_type_id = H5Dcreate (data_id, "type", type_id, space_id,
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1089 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1090 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
1091 #else
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1092 data_type_id = H5Dcreate (data_id, "type", type_id, space_id,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1093 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
1094 #endif
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1095 if (data_type_id < 0
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1096 || H5Dwrite (data_type_id, type_id, octave_H5S_ALL, octave_H5S_ALL,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1097 octave_H5P_DEFAULT, t.c_str ()) < 0)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1098 goto error_cleanup;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1099
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1100 // Now call the real function to save the variable
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1101 retval = val.save_hdf5 (data_id, "value", save_as_floats);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1102
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1103 // attach doc string as comment:
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1104 if (retval && doc.length () > 0
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1105 && H5Gset_comment (loc_id, name.c_str (), doc.c_str ()) < 0)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1106 retval = false;
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1107
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1108 // if it's global, add an attribute "OCTAVE_GLOBAL" with value 1
23470
a41fdb801db6 use mark_global and mark_persistent consistently
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
1109 if (retval && mark_global)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1110 retval = hdf5_add_attr (data_id, "OCTAVE_GLOBAL") >= 0;
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1111
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1112 // We are saving in the new variable format, so mark it
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1113 if (retval)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1114 retval = hdf5_add_attr (data_id, "OCTAVE_NEW_FORMAT") >= 0;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1115
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1116 error_cleanup:
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1117
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1118 if (data_type_id >= 0)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1119 H5Dclose (data_type_id);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1120
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1121 if (type_id >= 0)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1122 H5Tclose (type_id);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1123
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1124 if (space_id >= 0)
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1125 H5Sclose (space_id);
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1126
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1127 if (data_id >= 0)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1128 H5Gclose (data_id);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1129
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4675
diff changeset
1130 if (! retval)
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1131 error ("save: error while writing '%s' to hdf5 file", name.c_str ());
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1132
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1133 return retval;
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1134
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1135 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1136 err_disabled_feature ("add_hdf5_data", "HDF5");
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1137 #endif
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1138 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1139
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1140 // Write data from TC in HDF5 (binary) format to the stream OS,
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1141 // which must be an hdf5_ofstream, returning true on success.
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1142
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1143 bool
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1144 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
1145 const std::string& name, const std::string& doc,
23470
a41fdb801db6 use mark_global and mark_persistent consistently
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
1146 bool mark_global, bool save_as_floats)
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1147 {
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1148 #if defined (HAVE_HDF5)
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1149
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
1150 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
1151
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5351
diff changeset
1152 hdf5_ofstream& hs = dynamic_cast<hdf5_ofstream&> (os);
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1153
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1154 return add_hdf5_data (hs.file_id, tc, name, doc,
23470
a41fdb801db6 use mark_global and mark_persistent consistently
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
1155 mark_global, save_as_floats);
21355
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1156
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1157 #else
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1158 err_disabled_feature ("save_hdf5_data", "HDF5");
28d9bce20aa7 eliminate HAVE_HDF5 macros from public header files
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1159 #endif
4634
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1160 }
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1161
79fe96966ca0 [project @ 2003-11-19 21:22:39 by jwe]
jwe
parents:
diff changeset
1162 #endif