File tree Expand file tree Collapse file tree 10 files changed +146
-14
lines changed
Expand file tree Collapse file tree 10 files changed +146
-14
lines changed Original file line number Diff line number Diff line change 1+ function exists = h4exists(file , variable )
2+
3+ arguments
4+ file (1 ,1 ) string {mustBeFile }
5+ variable (1 ,1 ) string {mustBeNonzeroLengthText }
6+ end
7+
8+ exists = false ;
9+
10+ try
11+ sds = hdfinfo(file ).SDS;
12+ i = string(sds .Name ) == variable ;
13+ exists = any(i );
14+ catch e
15+ if e .identifier ~= " MATLAB:imagesci:h5info:unableToFind"
16+ rethrow(e )
17+ end
18+ end
Original file line number Diff line number Diff line change 77
88sds = hdfinfo(file ).SDS;
99
10- i = string(hdfinfo( file ).SDS .Name) == variable ;
10+ i = string(sds .Name ) == variable ;
1111if ~all(i )
1212 error(variable + " is not an SDS in " + file )
1313end
Original file line number Diff line number Diff line change 1+ function names = h4variables(file )
2+
3+ arguments
4+ file (1 ,1 ) string {mustBeFile }
5+ end
6+
7+ finf = hdfinfo(file );
8+
9+ ds = finf .SDS ;
10+
11+ names = string({ds .Name });
12+
13+ end
Original file line number Diff line number Diff line change 55 group string {mustBeScalarOrEmpty } = string.empty
66end
77
8- names = string .empty ;
9-
108if isempty(group ) || strlength(group ) == 0
119 finf = h5info(file );
1210else
1614ds = finf .Datasets ;
1715
1816if isempty(ds )
19- return
17+ names = string .empty ;
18+ else
19+ names = string({ds .Name });
2020end
2121
22- names = string({ds .Name });
23-
24- end % function
22+ end
Original file line number Diff line number Diff line change 55 group string {mustBeScalarOrEmpty } = string.empty
66end
77
8- names = string .empty ;
9-
108if isempty(group ) || strlength(group ) == 0
119 finf = ncinfo(file );
1210else
1311 finf = ncinfo(file , group );
1412end
1513
1614ds = finf .Variables(: );
15+
1716if isempty(ds )
18- return
17+ names = string .empty ;
18+ else
19+ names = string({ds .Name });
1920end
2021
21- names = string({ds .Name });
22-
23- end % function
22+ end
Original file line number Diff line number Diff line change 1+ function exists = h4exists(file , variable )
2+ %% H5EXISTS(file, variable)
3+ % check if object exists in HDF4 file
4+ %
5+ % %% Inputs
6+ % * file: data filename
7+ % * variable: path of variable in file
8+ %
9+ % %% Outputs
10+ % * exists: boolean
11+
12+ arguments
13+ file (1 ,1 ) string
14+ variable (1 ,1 ) string
15+ end
16+
17+ exists = stdlib .hdf5nc .h4exists(file , variable );
18+
19+ end
Original file line number Diff line number Diff line change 1+ function fsize = h4size(file , variable )
2+ %% h5size(file, variable)
3+ % get size (shape) of a data file variable
4+ %
5+ % %% Inputs
6+ % filename: data filename
7+ % variable: name of variable inside file
8+ %
9+ % %% Outputs
10+ % fsize: vector of variable size per dimension. Empty if scalar variable.
11+
12+ arguments
13+ file (1 ,1 ) string
14+ variable (1 ,1 ) string
15+ end
16+
17+ fsize = stdlib .hdf5nc .h4size(file , variable );
18+
19+ end
Original file line number Diff line number Diff line change 1+ function names = h4variables(file )
2+ %% h5variables(file, group)
3+ % get dataset names in a file under group
4+ % default is datasets under "/", optionally under "/group"
5+ %
6+ % %% Inputs
7+ % * file: filename
8+ % * group: group name (optional)
9+ %
10+ % %% Outputs
11+ % * names: variable names
12+
13+ arguments
14+ file (1 ,1 ) string
15+ end
16+
17+ names = stdlib .hdf5nc .h4variables(file );
18+
19+ end
Original file line number Diff line number Diff line change 1111% * names: variable names
1212
1313arguments
14- file (1 ,1 ) string { mustBeFile }
14+ file (1 ,1 ) string
1515 group string {mustBeScalarOrEmpty } = string.empty
1616end
1717
Original file line number Diff line number Diff line change 1+ classdef TestHDF4 < matlab .unittest .TestCase
2+
3+ properties
4+ TestData
5+ end
6+
7+ methods (TestClassSetup )
8+ function setup_path(tc )
9+ tc.TestData.basic = fullfile(matlabroot , " toolbox/matlab/demos/example.hdf" );
10+ end
11+ end
12+
13+ methods (Test )
14+
15+ function test_exists(tc )
16+ import matlab .unittest .constraints .IsScalar
17+ basic = tc .TestData .basic ;
18+
19+ e = stdlib .h4exists(basic , " Example SDS" );
20+
21+ tc .verifyThat(e , IsScalar )
22+ tc .verifyTrue(e );
23+
24+ tc .verifyFalse(stdlib .h4exists(basic , " /j" ))
25+
26+ end
27+
28+
29+ function test_size(tc )
30+ basic = tc .TestData .basic ;
31+
32+ s = stdlib .h4size(basic , " Example SDS" );
33+ tc .verifyEqual(s , [16 , 5 ])
34+
35+ end
36+
37+
38+ function test_vars(tc )
39+ basic = tc .TestData .basic ;
40+
41+ v = stdlib .h4variables(basic );
42+ tc .verifyTrue(any(contains(v , " Example SDS" )))
43+ end
44+
45+
46+ end
47+ end
You can’t perform that action at this time.
0 commit comments