Skip to content

Commit

Permalink
remove redundant h5ndims, ncndims
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jul 8, 2024
1 parent bff33d1 commit dd72713
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 118 deletions.
17 changes: 17 additions & 0 deletions +stdlib/+hdf5nc/h4size.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function fsize = h4size(file, variable)

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

sds = hdfinfo(file).SDS;

i = string(hdfinfo(file).SDS.Name) == variable;
if ~all(i)
error(variable + " is not an SDS in " + file)
end

fsize = cell2mat({sds(i).Dims.Size});

end
20 changes: 0 additions & 20 deletions +stdlib/+hdf5nc/h5ndims.m

This file was deleted.

20 changes: 0 additions & 20 deletions +stdlib/+hdf5nc/ncndims.m

This file was deleted.

19 changes: 0 additions & 19 deletions +stdlib/h5ndims.m

This file was deleted.

4 changes: 2 additions & 2 deletions +stdlib/h5size.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
% fsize: vector of variable size per dimension. Empty if scalar variable.

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

fsize = stdlib.hdf5nc.h5size(file, variable);
Expand Down
19 changes: 0 additions & 19 deletions +stdlib/ncndims.m

This file was deleted.

4 changes: 2 additions & 2 deletions +stdlib/ncsave.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function ncsave(filename, varname, A, opts)

arguments
filename (1,1) string {mustBeNonzeroLengthText}
varname (1,1) string {mustBeNonzeroLengthText}
filename (1,1) string
varname (1,1) string
A {mustBeNonempty}
opts.dims cell = {}
opts.type string {mustBeScalarOrEmpty} = string.empty
Expand Down
18 changes: 1 addition & 17 deletions test/TestHDF5.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,47 +112,31 @@ function test_size(tc)
import matlab.unittest.constraints.IsScalar
basic = tc.TestData.basic;

tc.verifyEmpty(stdlib.h5ndims(basic, string.empty))
tc.verifyEmpty(stdlib.h5ndims(basic, ""))

r = stdlib.h5ndims(basic, '/A0');
s = stdlib.h5size(basic, '/A0');
tc.verifyEmpty(s)
tc.verifyEqual(r, 0)

r = stdlib.h5ndims(basic, '/A1');
s = stdlib.h5size(basic, '/A1');
tc.verifyThat(s, IsScalar)
tc.verifyEqual(s, 2)
tc.verifyEqual(r, 1)

r = stdlib.h5ndims(basic, '/A2');
s = stdlib.h5size(basic, '/A2');
tc.verifyTrue(isvector(s))
tc.verifyEqual(s, [4,4])
tc.verifyEqual(r, 2)

r = stdlib.h5ndims(basic, '/A3');
s = stdlib.h5size(basic, '/A3');
tc.verifyTrue(isvector(s))
tc.verifyEqual(s, [4,3,2])
tc.verifyEqual(r, 3)

r = stdlib.h5ndims(basic, '/A4');
s = stdlib.h5size(basic, '/A4');
tc.verifyTrue(isvector(s))
tc.verifyEqual(s, [4,3,2,5])
tc.verifyEqual(r, 4)

r = stdlib.h5ndims(basic, '/utf');
s = stdlib.h5size(basic, '/utf');
tc.verifyEmpty(s)
tc.verifyEqual(r, 0)

r = stdlib.h5ndims(basic, '/utf2');
s = stdlib.h5size(basic, '/utf2');
tc.verifyEqual(s, 2)
tc.verifyEqual(r, 1)

end


Expand Down
20 changes: 1 addition & 19 deletions test/TestNetCDF.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,58 +103,40 @@ function test_size(tc)
import matlab.unittest.constraints.IsScalar
basic = tc.TestData.basic;

tc.verifyEmpty(stdlib.ncndims(basic, string.empty))
tc.verifyEmpty(stdlib.ncndims(basic, ""))

r = stdlib.ncndims(basic, 'A0');
s = stdlib.ncsize(basic, 'A0');
tc.verifyEmpty(s)
tc.verifyEqual(r, 0)

r = stdlib.ncndims(basic, 'A1');
s = stdlib.ncsize(basic, 'A1');
tc.verifyThat(s, IsScalar)
tc.verifyEqual(s, 2)
tc.verifyEqual(r, 1)

r = stdlib.ncndims(basic, 'A2');
s = stdlib.ncsize(basic, 'A2');
tc.verifyTrue(isvector(s))
tc.verifyEqual(s, [4,4])
tc.verifyEqual(r, 2)

r = stdlib.ncndims(basic, 'A3');
s = stdlib.ncsize(basic, 'A3');
tc.verifyTrue(isvector(s))
tc.verifyEqual(s, [4,3,2])
tc.verifyEqual(r, 3)

r = stdlib.ncndims(basic, 'A4');
s = stdlib.ncsize(basic, 'A4');
tc.verifyTrue(isvector(s))
tc.verifyEqual(s, [4,3,2,5])
tc.verifyEqual(r, 4)

end

function test_size_string(tc)
basic = tc.TestData.basic;

tc.assumeFalse(isMATLABReleaseOlderThan('R2021b'), "NetCDF4 string requires Matlab >= R2021b")

r = stdlib.ncndims(basic, 'utf0');
s = stdlib.ncsize(basic, 'utf0');
tc.verifyEmpty(s)
tc.verifyEqual(r, 0)

r = stdlib.ncndims(basic, 'utf1');
s = stdlib.ncsize(basic, 'utf1');
tc.verifyEqual(s, 2)
tc.verifyEqual(r, 1)

r = stdlib.ncndims(basic, 'utf2');
s = stdlib.ncsize(basic, 'utf2');
tc.verifyEqual(s, [2, 2])
tc.verifyEqual(r, 2)
end


Expand Down

0 comments on commit dd72713

Please sign in to comment.