Skip to content

Commit 5b5c757

Browse files
committed
allow empty filenames--returns empty
1 parent 20312e4 commit 5b5c757

File tree

8 files changed

+75
-18
lines changed

8 files changed

+75
-18
lines changed

+hdf5nc/TestHDF5.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ function test_get_variables(tc)
6969
import hdf5nc.h5variables
7070
basic = tc.TestData.basic;
7171

72+
tc.verifyEmpty(h5variables(string.empty))
73+
tc.verifyEmpty(h5variables(string.empty, string.empty))
74+
[a,b] = h5variables(string.empty, "hi");
75+
tc.verifyEmpty(a)
76+
tc.verifyEmpty(b)
77+
7278
v = h5variables(basic);
7379
tc.verifyEqual(sort(v), ["A0", "A1", "A2", "A3", "A4"])
7480

@@ -110,6 +116,9 @@ function test_exists(tc, vars)
110116
% empty
111117
e = h5exists(basic, string.empty);
112118
tc.verifyEmpty(e)
119+
120+
tc.verifyEqual(h5exists(string.empty, ["oops", "hi"]), [false, false])
121+
tc.verifyEmpty(h5exists(string.empty, string.empty))
113122
end
114123

115124

@@ -139,7 +148,9 @@ function test_size(tc)
139148
tc.verifyEqual(s, [4,3,2,5])
140149

141150
% empty
142-
tc.verifyError(@() h5size(basic, string.empty), 'MATLAB:validation:IncompatibleSize')
151+
tc.verifyEmpty(h5size(basic, string.empty))
152+
tc.verifyEmpty(h5size(string.empty, string.empty))
153+
tc.verifyEmpty(h5size(string.empty, "hi"))
143154
end
144155

145156

+hdf5nc/TestNetCDF.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ function cleanup(tc)
5454
methods (Test)
5555
function test_get_variables(tc)
5656
import hdf5nc.ncvariables
57+
basic = tc.TestData.basic;
58+
59+
tc.verifyEmpty(ncvariables(string.empty))
5760

58-
tc.verifyEqual(sort(ncvariables(tc.TestData.basic)), ["A0", "A1", "A2", "A3", "A4"])
61+
62+
tc.verifyEqual(sort(ncvariables(basic)), ["A0", "A1", "A2", "A3", "A4"])
5963
end
6064

6165

@@ -76,6 +80,9 @@ function test_exists(tc, vars)
7680
% empty
7781
e = ncexists(basic, string.empty);
7882
tc.verifyEmpty(e)
83+
84+
tc.verifyEqual(ncexists(string.empty, ["oops", "hi"]), [false, false])
85+
tc.verifyEmpty(ncexists(string.empty, string.empty))
7986
end
8087

8188

@@ -105,7 +112,9 @@ function test_size(tc)
105112
tc.verifyEqual(s, [4,3,2,5])
106113

107114
% empty
108-
tc.verifyError(@() ncsize(basic, string.empty), 'MATLAB:validation:IncompatibleSize')
115+
tc.verifyEmpty(ncsize(basic, string.empty))
116+
tc.verifyEmpty(ncsize(string.empty, string.empty))
117+
tc.verifyEmpty(ncsize(string.empty, "hi"))
109118
end
110119

111120

+hdf5nc/h5exists.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
% exists: boolean (scalar or vector)
1212

1313
arguments
14-
file (1,1) string
14+
file string
1515
varnames (1,:) string
1616
end
1717

+hdf5nc/h5size.m

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,27 @@
22
% get size (shape) of an HDF5 dataset
33
%
44
% filename: HDF5 filename
5-
% variable: name of variable inside HDF5 file
5+
% variable: name of variable inside file
66
%
77
% fsize: vector of variable size per dimension
88
arguments
9-
file (1,1) string
10-
variable (1,1) string
9+
file string
10+
variable string
1111
end
1212

13+
assert(length(file)<2, "one file at a time")
14+
assert(length(variable)<2, "one variable at a time")
15+
16+
fsize = [];
17+
1318
file = expanduser(file);
19+
20+
if isempty(file) || isempty(variable)
21+
return
22+
end
23+
1424
if ~isfile(file)
15-
error('hdf5nc:h5size:fileNotFound', "%s does not exist", file)
25+
error("hdf5nc:h5size:fileNotFound", "%s not found.", file)
1626
end
1727

1828
fsize = h5info(file, variable).Dataspace.Size;

+hdf5nc/h5variables.m

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,26 @@
1313
% groups: file groups
1414

1515
arguments
16-
file (1,1) string
16+
file string
1717
group string = string.empty
1818
end
1919

20+
assert(length(file)<2, "one file at a time")
21+
assert(length(group)<2, "one group at a time")
22+
2023
file = expanduser(file);
21-
if ~isfile(file)
22-
error('hdf5nc:h5variables:fileNotFound', "%s does not exist", file)
23-
end
2424

2525
names = string.empty;
2626
groups = string.empty;
2727

28+
if isempty(file)
29+
return
30+
end
31+
32+
if ~isfile(file)
33+
error("hdf5nc:h5variables:fileNotFound", "%s not found.", file)
34+
end
35+
2836
if isempty(group)
2937
finf = h5info(file);
3038
else

+hdf5nc/ncexists.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
% exists: boolean (scalar or vector)
1212

1313
arguments
14-
file (1,1) string
14+
file string
1515
varnames (1,:) string
1616
end
1717

+hdf5nc/ncsize.m

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,23 @@
66
%
77
% fsize: vector of variable size per dimension
88
arguments
9-
file (1,1) string
10-
variable (1,1) string
9+
file string
10+
variable string
1111
end
1212

13+
assert(length(file)<2, "one file at a time")
14+
assert(length(variable)<2, "one variable at a time")
15+
16+
fsize = [];
17+
1318
file = expanduser(file);
19+
20+
if isempty(file) || isempty(variable)
21+
return
22+
end
23+
1424
if ~isfile(file)
15-
error('hdf5nc:ncsize:fileNotFound', "%s does not exist", file)
25+
error("hdf5nc:ncsize:fileNotFound", "%s not found.", file)
1626
end
1727

1828
fsize = ncinfo(file, variable).Size;

+hdf5nc/ncvariables.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@
1010
% names: variable names
1111

1212
arguments
13-
file (1,1) string
13+
file string
1414
end
1515

16+
assert(length(file)<2, "one file at a time")
17+
1618
file = expanduser(file);
19+
20+
names = string.empty;
21+
22+
if isempty(file)
23+
return
24+
end
25+
1726
if ~isfile(file)
18-
error('hdf5nc:ncvariables:fileNotFound', "%s does not exist", file)
27+
error("hdf5nc:ncvariables:fileNotFound", "%s not found.", file)
1928
end
2029

2130
finf = ncinfo(file);

0 commit comments

Comments
 (0)