From dd727139c07df123c2854c43c66a6af541d13acd Mon Sep 17 00:00:00 2001 From: scivision Date: Mon, 8 Jul 2024 12:16:16 -0400 Subject: [PATCH] remove redundant h5ndims, ncndims --- +stdlib/+hdf5nc/h4size.m | 17 +++++++++++++++++ +stdlib/+hdf5nc/h5ndims.m | 20 -------------------- +stdlib/+hdf5nc/ncndims.m | 20 -------------------- +stdlib/h5ndims.m | 19 ------------------- +stdlib/h5size.m | 4 ++-- +stdlib/ncndims.m | 19 ------------------- +stdlib/ncsave.m | 4 ++-- test/TestHDF5.m | 18 +----------------- test/TestNetCDF.m | 20 +------------------- 9 files changed, 23 insertions(+), 118 deletions(-) create mode 100644 +stdlib/+hdf5nc/h4size.m delete mode 100644 +stdlib/+hdf5nc/h5ndims.m delete mode 100644 +stdlib/+hdf5nc/ncndims.m delete mode 100644 +stdlib/h5ndims.m delete mode 100644 +stdlib/ncndims.m diff --git a/+stdlib/+hdf5nc/h4size.m b/+stdlib/+hdf5nc/h4size.m new file mode 100644 index 0000000..bcf6a0a --- /dev/null +++ b/+stdlib/+hdf5nc/h4size.m @@ -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 diff --git a/+stdlib/+hdf5nc/h5ndims.m b/+stdlib/+hdf5nc/h5ndims.m deleted file mode 100644 index 6de2ff1..0000000 --- a/+stdlib/+hdf5nc/h5ndims.m +++ /dev/null @@ -1,20 +0,0 @@ -function frank = h5ndims(file, variable) - -arguments - file (1,1) string {mustBeFile} - variable string {mustBeScalarOrEmpty} -end - -if isempty(variable) || strlength(variable) == 0 - frank = []; - return -end - -dsi = h5info(file, variable).Dataspace; -if dsi.Type == "scalar" - frank = 0; -else - frank = length(dsi.Size); -end - -end diff --git a/+stdlib/+hdf5nc/ncndims.m b/+stdlib/+hdf5nc/ncndims.m deleted file mode 100644 index 1862711..0000000 --- a/+stdlib/+hdf5nc/ncndims.m +++ /dev/null @@ -1,20 +0,0 @@ -function frank = ncndims(file, variable) - -arguments - file (1,1) string {mustBeFile} - variable string {mustBeScalarOrEmpty} -end - -if isempty(variable) || strlength(variable) == 0 - frank = []; - return -end - -dsi = ncinfo(file, variable); -if isempty(dsi.Dimensions) - frank = 0; -else - frank = length(dsi.Size); -end - -end diff --git a/+stdlib/h5ndims.m b/+stdlib/h5ndims.m deleted file mode 100644 index 42c9a4e..0000000 --- a/+stdlib/h5ndims.m +++ /dev/null @@ -1,19 +0,0 @@ -function frank = h5ndims(file, variable) -%% h5ndims(file, variable) -% get number of dimensions of an HDF5 dataset -% -%%% Inputs -% * file: data filename -% * variable: name of variable inside file -% -%%% Outputs -% * frank: number of variable dimensions (like Matlab ndims) - -arguments - file (1,1) string {mustBeFile} - variable string {mustBeScalarOrEmpty} -end - -frank = stdlib.hdf5nc.h5ndims(file, variable); - -end diff --git a/+stdlib/h5size.m b/+stdlib/h5size.m index eb7718f..8a0295d 100644 --- a/+stdlib/h5size.m +++ b/+stdlib/h5size.m @@ -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); diff --git a/+stdlib/ncndims.m b/+stdlib/ncndims.m deleted file mode 100644 index 9b3f852..0000000 --- a/+stdlib/ncndims.m +++ /dev/null @@ -1,19 +0,0 @@ -function frank = ncndims(file, variable) -%% ncndims(file, variable) -% get number of dimensions of a variable in the file -% -%%% Inputs -% * file: data filename -% * variable: name of variable inside file -% -%%% Outputs -% * frank: number of variable dimensions (like Matlab ndims) - -arguments - file (1,1) string {mustBeFile} - variable string {mustBeScalarOrEmpty} -end - -frank = stdlib.hdf5nc.ncndims(file, variable); - -end diff --git a/+stdlib/ncsave.m b/+stdlib/ncsave.m index 287d429..f70e6bd 100644 --- a/+stdlib/ncsave.m +++ b/+stdlib/ncsave.m @@ -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 diff --git a/test/TestHDF5.m b/test/TestHDF5.m index 8a371b8..07a07ae 100644 --- a/test/TestHDF5.m +++ b/test/TestHDF5.m @@ -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 diff --git a/test/TestNetCDF.m b/test/TestNetCDF.m index dbcbfc0..1c692b2 100644 --- a/test/TestNetCDF.m +++ b/test/TestNetCDF.m @@ -103,37 +103,25 @@ 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) @@ -141,20 +129,14 @@ function test_size_string(tc) 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