Skip to content

Commit

Permalink
h5exists: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jul 8, 2024
1 parent dd72713 commit 7355fa8
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 18 deletions.
10 changes: 1 addition & 9 deletions +stdlib/+hdf5nc/h5exists.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@

arguments
file (1,1) string {mustBeFile}
variable string {mustBeScalarOrEmpty}
variable (1,1) string
end

exists = false;

if(strlength(variable) == 0)
return
end

if ~startsWith(variable, "/")
variable = "/" + variable;
end

try
h5info(file, variable);
exists = true;
Expand Down
2 changes: 1 addition & 1 deletion +stdlib/+hdf5nc/ncexists.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

arguments
file (1,1) string {mustBeFile}
variable string {mustBeScalarOrEmpty}
variable (1,1) string
end

exists = false;
Expand Down
2 changes: 1 addition & 1 deletion +stdlib/h5exists.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

arguments
file (1,1) string
variable string {mustBeScalarOrEmpty}
variable (1,1) string
end

exists = stdlib.hdf5nc.h5exists(file, variable);
Expand Down
2 changes: 1 addition & 1 deletion +stdlib/ncexists.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

arguments
file (1,1) string
variable string {mustBeScalarOrEmpty}
variable (1,1) string
end

exists = stdlib.hdf5nc.ncexists(file, variable);
Expand Down
9 changes: 3 additions & 6 deletions test/TestHDF5.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,10 @@ function test_exists(tc)
import matlab.unittest.constraints.IsScalar
basic = tc.TestData.basic;

e = stdlib.h5exists(basic, "");
e = stdlib.h5exists(basic, "/A0");

tc.verifyThat(e, IsScalar)
tc.verifyFalse(e)

tc.verifyTrue(stdlib.h5exists(basic, "/A0"));
tc.verifyTrue(stdlib.h5exists(basic, "A0"));
tc.verifyTrue(e);

end

Expand Down Expand Up @@ -194,7 +191,7 @@ function test_shape(tc)
function test_coerce(tc, type)
basic = tc.TestData.basic;

stdlib.h5save(basic, type, 0, "type",type)
stdlib.h5save(basic, "/"+type, 0, "type",type)

switch type
case "string", vt = 'char';
Expand Down

0 comments on commit 7355fa8

Please sign in to comment.