Skip to content

Commit 4baab54

Browse files
committed
[feat] initial support of saveh5 using oct-hdf5 in octave
1 parent a2b62c1 commit 4baab54

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

saveh5.m

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,24 @@ function saveh5(data, fname, varargin)
8282
opt.scalar = jsonopt('Scalar', 1, opt);
8383

8484
opt.releaseid = 0;
85+
opt.isoctave = 0;
8586
vers = ver('MATLAB');
8687
if (~isempty(vers))
8788
opt.releaseid = datenum(vers(1).Date);
89+
opt.skipempty = (opt.releaseid < datenum('1-Jan-2015'));
90+
else
91+
opt.isoctave = 1;
92+
opt.skipempty = 0;
93+
end
94+
95+
if (exist('OCTAVE_VERSION', 'builtin') ~= 0 && exist('h5info') == 0)
96+
try
97+
pkg load oct-hdf5;
98+
catch
99+
error(['To use EasyH5 in Octave, one must install oct-hdf5 first using\n\t' ...
100+
'pkg install https://github.com/fangq/oct-hdf5/archive/refs/heads/main.zip\n%s'], '');
101+
end
88102
end
89-
opt.skipempty = (opt.releaseid < datenum('1-Jan-2015'));
90103

91104
if (isfield(opt, 'rootname'))
92105
rootname = ['/' opt.rootname];
@@ -100,11 +113,6 @@ function saveh5(data, fname, varargin)
100113
data = jdataencode(data, 'Base64', 0, 'UseArrayZipSize', 0, opt);
101114
end
102115

103-
if (exist('OCTAVE_VERSION', 'builtin') ~= 0)
104-
save(fname, 'data', '-hdf5');
105-
return
106-
end
107-
108116
try
109117
if (isa(fname, 'H5ML.id'))
110118
fid = fname;
@@ -174,7 +182,9 @@ function saveh5(data, fname, varargin)
174182
tracked = H5ML.get_constant_value('H5P_CRT_ORDER_TRACKED');
175183
indexed = H5ML.get_constant_value('H5P_CRT_ORDER_INDEXED');
176184
order = bitor(tracked, indexed);
177-
H5P.set_link_creation_order(gcpl, order);
185+
if (~varargin{1}.isoctave)
186+
H5P.set_link_creation_order(gcpl, order);
187+
end
178188
if (varargin{1}.unpackhex)
179189
name = decodevarname(name);
180190
end
@@ -204,7 +214,9 @@ function saveh5(data, fname, varargin)
204214
tracked = H5ML.get_constant_value('H5P_CRT_ORDER_TRACKED');
205215
indexed = H5ML.get_constant_value('H5P_CRT_ORDER_INDEXED');
206216
order = bitor(tracked, indexed);
207-
H5P.set_link_creation_order(gcpl, order);
217+
if (~varargin{1}.isoctave)
218+
H5P.set_link_creation_order(gcpl, order);
219+
end
208220
try
209221
if (varargin{1}.unpackhex)
210222
name = decodevarname(name);
@@ -253,7 +265,9 @@ function saveh5(data, fname, varargin)
253265
tracked = H5ML.get_constant_value('H5P_CRT_ORDER_TRACKED');
254266
indexed = H5ML.get_constant_value('H5P_CRT_ORDER_INDEXED');
255267
order = bitor(tracked, indexed);
256-
H5P.set_link_creation_order(gcpl, order);
268+
if (~varargin{1}.isoctave)
269+
H5P.set_link_creation_order(gcpl, order);
270+
end
257271

258272
if (~(isfield(opt, 'complexformat') && iscellstr(opt.complexformat) && numel(opt.complexformat) == 2) || strcmp(opt.complexformat{1}, opt.complexformat{2}))
259273
opt.complexformat = {'Real', 'Imag'};

0 commit comments

Comments
 (0)