Skip to content

Commit eed2abd

Browse files
committed
ncsave,h5save: use try-catch for dedupe
1 parent 3b02a0e commit eed2abd

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

+stdlib/h5save.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ function h5save(filename, varname, A, opts)
3838
% coerce if needed
3939
A = coerce_ds(A, opts.type);
4040

41-
if isfile(filename)
42-
if stdlib.h5exists(filename, varname)
43-
stdlib.h5save_exist(filename, varname, A, opts.size)
44-
else
41+
try
42+
stdlib.h5save_exist(filename, varname, A, opts.size)
43+
catch e
44+
if any(e.identifier == ["MATLAB:imagesci:hdf5io:resourceNotFound", "MATLAB:imagesci:h5info:unableToFind"])
4545
stdlib.h5save_new(filename, varname, A, opts.size, opts.compressLevel)
46+
else
47+
rethrow(e)
4648
end
47-
else
48-
stdlib.h5save_new(filename, varname, A, opts.size, opts.compressLevel)
4949
end
5050

5151
end

+stdlib/ncsave.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ function ncsave(filename, varname, A, opts)
4141
end
4242
end
4343

44-
if isfile(filename)
45-
if stdlib.ncexists(filename, varname)
46-
stdlib.ncsave_exist(filename, varname, A, sizeA)
47-
else
44+
try
45+
stdlib.ncsave_exist(filename, varname, A, sizeA)
46+
catch e
47+
if any(e.identifier == ["MATLAB:imagesci:netcdf:unableToOpenFileforRead", "MATLAB:imagesci:netcdf:unknownLocation"])
4848
stdlib.ncsave_new(filename, varname, A, sizeA, opts.dims, opts.compressLevel)
49+
else
50+
rethrow(e)
4951
end
50-
else
51-
stdlib.ncsave_new(filename, varname, A, sizeA, opts.dims, opts.compressLevel)
5252
end
5353

5454
end

+stdlib/ncsave_exist.m

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

44
function ncsave_exist(filename, varname, A, sizeA)
5+
arguments
6+
filename {mustBeTextScalar}
7+
varname {mustBeTextScalar}
8+
A {mustBeNonempty}
9+
sizeA (1,:) {mustBePositive, mustBeInteger}
10+
end
511

612
diskshape = stdlib.ncsize(filename, varname);
713

private/publish_gen_index_html.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
function publish_gen_index_html(pkg_name, tagline, project_url, outdir)
1414
arguments
15-
pkg_name (1,1) string
16-
tagline (1,1) string
17-
project_url (1,1) string
18-
outdir (1,1) string
15+
pkg_name {mustBeTextScalar}
16+
tagline {mustBeTextScalar}
17+
project_url {mustBeTextScalar}
18+
outdir {mustBeTextScalar}
1919
end
2020

2121
pkg = what("+" + pkg_name);

0 commit comments

Comments
 (0)