Skip to content

Commit 0356e50

Browse files
committed
[feat] support Octave low-level HDF5 IO via oct-hdf5
1 parent 9d0ba96 commit 0356e50

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

loadh5.m

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,21 @@
6666
opt.stringarray = jsonopt('StringArray', 0, opt);
6767
opt.rootpath = path;
6868

69-
if (exist('OCTAVE_VERSION', 'builtin') ~= 0)
70-
[varargout{1:nargout}] = load(filename, '-hdf5');
71-
if (opt.dotranspose)
72-
varargout{1} = transposemat(varargout{1});
69+
if (exist('OCTAVE_VERSION', 'builtin') ~= 0 && exist('h5info') == 0)
70+
try
71+
try
72+
[varargout{1:nargout}] = load(filename, '-hdf5');
73+
if (opt.dotranspose)
74+
varargout{1} = transposemat(varargout{1});
75+
end
76+
return
77+
catch
78+
pkg load oct-hdf5;
79+
end
80+
catch
81+
error(['To use EasyH5 in Octave, one must install oct-hdf5 first using\n\t' ...
82+
'pkg install https://github.com/fangq/oct-hdf5/archive/refs/heads/main.zip\n%s'], '');
7383
end
74-
return
7584
end
7685

7786
if (isa(filename, 'H5ML.id'))
@@ -103,12 +112,12 @@
103112
try
104113
if (nargin > 1 && ~isempty(path))
105114
try
106-
rootgid = H5G.open(loc, path);
115+
rootgid = H5G.open(loc, path, 0);
107116
[varargout{1:nargout}] = load_one(rootgid, opt);
108117
H5G.close(rootgid);
109118
catch
110119
[gname, dname] = fileparts(path);
111-
rootgid = H5G.open(loc, gname);
120+
rootgid = H5G.open(loc, gname, 0);
112121
[status, res] = group_iterate(rootgid, dname, struct('data', struct, 'meta', struct, 'opt', opt));
113122
if (nargout > 0)
114123
varargout{1} = res.data;
@@ -171,15 +180,20 @@
171180
meta = inputdata.meta;
172181

173182
% objtype index
174-
info = H5G.get_objinfo(group_id, objname, 0);
183+
if (exist('OCTAVE_VERSION', 'builtin') ~= 0)
184+
info = H5O.get_info_by_name(group_id, objname, 0);
185+
else
186+
info = H5G.get_objinfo(group_id, objname, 0);
187+
end
188+
175189
objtype = info.type;
176190
objtype = objtype + 1;
177191

178192
if objtype == 1
179193
% Group
180194
name = regexprep(objname, '.*/', '');
181195

182-
group_loc = H5G.open(group_id, name);
196+
group_loc = H5G.open(group_id, name, 0);
183197
try
184198
[sub_data, sub_meta] = load_one(group_loc, inputdata.opt);
185199
H5G.close(group_loc);
@@ -297,8 +311,8 @@
297311
end
298312

299313
% handeling string arrays (or cell of char strings)
300-
if (iscell(data) && length(data) > 1)
301-
if (all(cellfun(@ischar, data)) && exist('string') && opt.stringarray)
314+
if (iscell(data) && all(cellfun(@ischar, data)))
315+
if (exist('string') && opt.stringarray)
302316
data = string(data);
303317
end
304318
end

0 commit comments

Comments
 (0)