Skip to content

Commit 6f66686

Browse files
committed
h5exists, ncexists: correct/simplify
1 parent ac551e5 commit 6f66686

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

+stdlib/h5exists.m

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@
1818
h5info(file, variable);
1919
exists = true;
2020
catch e
21-
if stdlib.isoctave
22-
disp(e.message)
23-
if strcmp(e.identifier, "Octave:undefined-function") || isempty(strfind(e.message, 'does not exist'))
24-
rethrow(e)
25-
end
26-
else
27-
if ~strcmp(e.identifier, 'MATLAB:imagesci:h5info:unableToFind')
28-
rethrow(e)
29-
end
21+
if ~strcmp(e.identifier, 'MATLAB:imagesci:h5info:unableToFind') && ...
22+
~strncmp(e.message, "h5info: location", 16)
23+
disp(e)
24+
rethrow(e)
3025
end
3126
end
3227

@@ -38,4 +33,5 @@
3833
%! ds = '/a';
3934
%! h5create(fn, ds, [1])
4035
%! assert(h5exists(fn, ds))
36+
%! assert(!h5exists(fn, '/b'))
4137
%! delete(fn)

+stdlib/ncexists.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
exists = true;
2020
catch e
2121
if ~strcmp(e.identifier, "MATLAB:imagesci:netcdf:badLocationString") && ...
22-
~strcmp(e.identifier, "MATLAB:imagesci:netcdf:unknownLocation")
22+
~strcmp(e.identifier, "MATLAB:imagesci:netcdf:unknownLocation") && ...
23+
~strcmp(e.message, "NetCDF: Variable not found")
2324

2425
rethrow(e)
2526
end
@@ -34,4 +35,5 @@
3435
%! ds = 'a';
3536
%! nccreate(fn, ds)
3637
%! assert(ncexists(fn, ds))
38+
%! assert(!ncexists(fn, 'b'))
3739
%! delete(fn)

0 commit comments

Comments
 (0)