Skip to content

Commit 0012e6b

Browse files
committed
hdf5: work more broadly
1 parent 3d2e831 commit 0012e6b

File tree

8 files changed

+52
-37
lines changed

8 files changed

+52
-37
lines changed

+stdlib/h5create_group.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
if isa(file, 'H5ML.id')
1717
fid = file;
1818
else
19+
file = string(file);
1920
dcpl = 'H5P_DEFAULT';
2021
if isfile(file)
2122
fid = H5F.open(file, 'H5F_ACC_RDWR', dcpl);

+stdlib/h5save.m

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,23 @@
1818
% Likewise, the type of the dataset may be explicitly specified with the "type" argument.
1919
% h5save(filename, dataset_name, dataset, type="int32")
2020

21-
function h5save(filename, varname, A, opts)
22-
arguments
23-
filename (1,1) string
24-
varname (1,1) string
25-
A {mustBeNonempty}
26-
opts.size (1,:) double {mustBeInteger,mustBeNonnegative} = []
27-
opts.type (1,1) string = ""
28-
opts.compressLevel (1,1) double {mustBeInteger,mustBeNonnegative} = 0
29-
end
21+
function h5save(filename, varname, A, varargin)
22+
% arguments
23+
% filename (1,1) string
24+
% varname (1,1) string
25+
% A {mustBeNonempty}
26+
% opts.size (1,:) double {mustBeInteger,mustBeNonnegative} = []
27+
% opts.type (1,1) string = ""
28+
% opts.compressLevel (1,1) double {mustBeInteger,mustBeNonnegative} = 0
29+
% end
30+
31+
p = inputParser;
32+
addParameter(p, 'size', []);
33+
addParameter(p, 'type', "");
34+
addParameter(p, 'compressLevel', 0, @(x) mustBeInteger(x) && mustBeNonnegative(x));
35+
parse(p, varargin{:});
36+
37+
opts = p.Results;
3038

3139
if isnumeric(A)
3240
mustBeReal(A)

+stdlib/h5size.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
function fsize = h5size(file, variable)
1010

11-
dsi = h5info(file, variable).Dataspace;
11+
finf = h5info(file, variable);
12+
dsi = finf.Dataspace;
1213

1314
if dsi.Type == "scalar"
1415
fsize = [];

+stdlib/h5variables.m

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@
99
% * names: variable names
1010

1111
function names = h5variables(file, group)
12-
arguments
13-
file
14-
group (1,1) string = ""
12+
if nargin < 2
13+
group = '/';
1514
end
1615

17-
if stdlib.strempty(group)
18-
finf = h5info(file);
19-
else
20-
finf = h5info(file, group);
21-
end
16+
finf = h5info(file, group);
2217

2318
ds = finf.Datasets;
2419

+stdlib/private/h5save_exist.m

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
% normally users use h5save() instead of this function
33

44
function h5save_exist(filename, varname, A, sizeA)
5-
arguments
6-
filename
7-
varname
8-
A
9-
sizeA (1,:) double {mustBeInteger,mustBeNonnegative} = []
5+
% arguments
6+
% filename
7+
% varname
8+
% A
9+
% sizeA (1,:) double {mustBeInteger,mustBeNonnegative} = []
10+
% end
11+
if nargin < 4
12+
sizeA = [];
1013
end
1114

1215
diskshape = stdlib.h5size(filename, varname);

+stdlib/private/h5save_new.m

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
% normally users will use h5save() instead of this function
33

44
function h5save_new(filename, varname, A, sizeA, compressLevel)
5-
arguments
6-
filename
7-
varname
8-
A
9-
sizeA (1,:) double {mustBeInteger,mustBeNonnegative} = []
10-
compressLevel (1,1) double {mustBeInteger,mustBeNonnegative} = 0
5+
% arguments
6+
% filename
7+
% varname
8+
% A
9+
% sizeA (1,:) double {mustBeInteger,mustBeNonnegative} = []
10+
% compressLevel (1,1) double {mustBeInteger,mustBeNonnegative} = 0
11+
% end
12+
if nargin < 4
13+
sizeA = [];
1114
end
15+
if nargin < 5
16+
compressLevel = 0;
17+
end
18+
1219

1320
if isempty(sizeA)
1421
sizeA = defaultSize(A);

+stdlib/private/h5save_scalar.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
function h5save_scalar(filename, hpath, A)
22
%% write HDF5 scalar as a scalar
33
% h5create doesn't support scalars
4-
arguments
5-
filename (1,1) string
6-
hpath (1,1) string
7-
A (1,1)
8-
end
9-
% filename must be a scalar string--char does not work
4+
% arguments
5+
% filename (1,1) string
6+
% hpath (1,1) string
7+
% A (1,1)
8+
% end
9+
1010

1111
dcpl = 'H5P_DEFAULT';
1212

test/TestHDF5.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function setup_file(tc)
6363
end
6464

6565

66-
methods (Test, TestTags = {'R2019b'})
66+
methods (Test, TestTags = {'R2017b'})
6767

6868
function test_auto_chunk_size(tc)
6969

@@ -242,7 +242,7 @@ function test_real_only(tc)
242242
end
243243

244244

245-
methods (Test, TestTags=["R2020b", "hdf5"])
245+
methods (Test, TestTags={'R2020b'})
246246

247247
function test_string(tc, str)
248248
tc.assumeFalse(stdlib.matlabOlderThan("R2020b"))

0 commit comments

Comments
 (0)