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 7
7
8
8
sds = hdfinfo(file ).SDS;
9
9
10
- i = string(hdfinfo( file ).SDS .Name) == variable ;
10
+ i = string(sds .Name ) == variable ;
11
11
if ~all(i )
12
12
error(variable + " is not an SDS in " + file )
13
13
end
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 5
5
group string {mustBeScalarOrEmpty } = string.empty
6
6
end
7
7
8
- names = string .empty ;
9
-
10
8
if isempty(group ) || strlength(group ) == 0
11
9
finf = h5info(file );
12
10
else
16
14
ds = finf .Datasets ;
17
15
18
16
if isempty(ds )
19
- return
17
+ names = string .empty ;
18
+ else
19
+ names = string({ds .Name });
20
20
end
21
21
22
- names = string({ds .Name });
23
-
24
- end % function
22
+ end
Original file line number Diff line number Diff line change 5
5
group string {mustBeScalarOrEmpty } = string.empty
6
6
end
7
7
8
- names = string .empty ;
9
-
10
8
if isempty(group ) || strlength(group ) == 0
11
9
finf = ncinfo(file );
12
10
else
13
11
finf = ncinfo(file , group );
14
12
end
15
13
16
14
ds = finf .Variables(: );
15
+
17
16
if isempty(ds )
18
- return
17
+ names = string .empty ;
18
+ else
19
+ names = string({ds .Name });
19
20
end
20
21
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 11
11
% * names: variable names
12
12
13
13
arguments
14
- file (1 ,1 ) string { mustBeFile }
14
+ file (1 ,1 ) string
15
15
group string {mustBeScalarOrEmpty } = string.empty
16
16
end
17
17
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