Skip to content

Commit e46010b

Browse files
committed
remove unused import
1 parent 0b24824 commit e46010b

File tree

6 files changed

+56
-30
lines changed

6 files changed

+56
-30
lines changed

+hdf5nc/h5exists.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
function exists = h5exists(filename, varnames)
22
% check if variable(s) exists in HDF5 file
33
%
4+
% parameters
5+
% ----------
46
% filename: HDF5 filename
57
% varname: name of variable inside HDF5 file
68
%
9+
% returns
10+
% -------
711
% exists: boolean (scalar or vector)
812

913
arguments
1014
filename (1,1) string
1115
varnames (1,:) string
1216
end
1317

14-
import hdf5nc.h5variables
15-
1618
i = startsWith(varnames, "/");
1719
varnames(i) = extractAfter(varnames(i), 1);
1820
% NOT contains because we want exact string match
19-
exists = ismember(varnames, h5variables(filename));
21+
exists = ismember(varnames, hdf5nc.h5variables(filename));
2022

2123
end % function

+hdf5nc/h5save.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ function h5save(filename, varname, A, opts)
22
% H5SAVE
33
% create or append to HDF5 file
44
% parent folder (file directory) must already exist
5+
56
arguments
67
filename (1,1) string
78
varname (1,1) string
@@ -10,8 +11,6 @@ function h5save(filename, varname, A, opts)
1011
opts.type string = string.empty
1112
end
1213

13-
import hdf5nc.h5exists
14-
1514
if isnumeric(A)
1615
mustBeReal(A)
1716
end
@@ -34,7 +33,7 @@ function h5save(filename, varname, A, opts)
3433
sizeA = size(A);
3534
end
3635

37-
if isfile(filename) && h5exists(filename, varname)
36+
if isfile(filename) && hdf5nc.h5exists(filename, varname)
3837
exist_file(filename, varname, A, sizeA)
3938
else
4039
new_file(filename, varname, A, sizeA)
@@ -44,8 +43,8 @@ function h5save(filename, varname, A, opts)
4443

4544

4645
function exist_file(filename, varname, A, sizeA)
47-
import hdf5nc.h5size
48-
diskshape = h5size(filename, varname);
46+
47+
diskshape = hdf5nc.h5size(filename, varname);
4948
if length(diskshape) >= 2
5049
% start is always a row vector, regardless of shape of array
5150
start = ones(1,ndims(A));

+hdf5nc/h5variables.m

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
function [names, groups] = h5variables(filename, group)
2-
% get dataset names and groups in an HDF5 file
1+
function [names, groups] = h5variables(file, group)
2+
% get dataset names in a file
3+
% Optionally, get first level of groups in a file.
4+
%
5+
% parameters
6+
% ----------
7+
% file: filename
8+
% group: group name (optional)
9+
%
10+
% returns
11+
% -------
12+
% names: variable names
13+
% groups: file groups
14+
315
arguments
4-
filename (1,1) string
16+
file (1,1) string
517
group string = string.empty
618
end
719

820
names = string.empty;
921
groups = string.empty;
1022

11-
finf = h5info(expanduser(filename));
23+
finf = h5info(expanduser(file));
1224
ds = finf.Datasets;
1325
if isempty(ds)
1426
return

+hdf5nc/ncsave.m

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ function ncsave(filename, varname, A, opts)
1010
opts.type string = string.empty
1111
end
1212

13-
import hdf5nc.ncexists
14-
1513
filename = expanduser(filename);
1614

1715
if isempty(opts.dims)
@@ -42,7 +40,7 @@ function ncsave(filename, varname, A, opts)
4240
% coerce if needed
4341
A = coerce_ds(A, opts.type);
4442

45-
if isfile(filename) && ncexists(filename, varname)
43+
if isfile(filename) && hdf5nc.ncexists(filename, varname)
4644
exist_file(filename, varname, A, sizeA)
4745
else
4846
new_file(filename, varname, A, sizeA, ncdims)
@@ -52,8 +50,8 @@ function ncsave(filename, varname, A, opts)
5250

5351

5452
function exist_file(filename, varname, A, sizeA)
55-
import hdf5nc.ncsize
56-
diskshape = ncsize(filename, varname);
53+
54+
diskshape = hdf5nc.ncsize(filename, varname);
5755

5856
if all(diskshape == sizeA)
5957
ncwrite(filename, varname, A)
@@ -71,7 +69,6 @@ function new_file(filename, varname, A, sizeA, ncdims)
7169
folder = fileparts(filename);
7270
assert(isfolder(folder), '%s is not a folder, cannot create %s', folder, filename)
7371

74-
7572
if isscalar(A)
7673
nccreate(filename, varname, 'Datatype', class(A), 'Format', 'netcdf4')
7774
elseif isvector(A)

+hdf5nc/ncvariables.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
function names = ncvariables(filename)
2-
% get dataset names and groups in an NetCDF4 file
2+
% get dataset names in a file
3+
%
4+
% parameters
5+
% ----------
6+
% file: filename
7+
%
8+
% returns
9+
% -------
10+
% names: variable names
11+
312
arguments
413
filename (1,1) string
514
end

Readme.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
These HDF5 and NetCDF4 functions should be built into Matlab itself, but since they're not yet, we provide them.
88

9-
## HDF5
9+
## Usage
1010

11-
This package is setup as a Matlab package, so we assume you have either:
11+
This package is a Matlab package, so we assume you have either:
1212

1313
```matlab
1414
import hdf5nc.*
@@ -22,6 +22,15 @@ Run selftests by:
2222
runtests('hdf5nc')
2323
```
2424

25+
### HDF5
26+
27+
Matlab R2020b uses HDF5 1.8.12.
28+
29+
```matlab
30+
[major,minor,rel] = H5.get_libversion()
31+
```
32+
33+
2534
* Check that a dataset exists in file:
2635

2736
```matlab
@@ -46,7 +55,13 @@ runtests('hdf5nc')
4655
h5variables(filename)
4756
```
4857
49-
## NetCDF4
58+
### NetCDF4
59+
60+
Matlab R2020b uses NetCDF4 4.7.3.
61+
62+
```matlab
63+
netcdf.inqLibVers
64+
```
5065

5166
* Check that a variable exists in file:
5267

@@ -71,11 +86,3 @@ runtests('hdf5nc')
7186
```matlab
7287
ncvariables(filename)
7388
```
74-
75-
## General utilities
76-
77-
* expand a leading tilde to the current user home directory
78-
79-
```matlab
80-
expanduser(path)
81-
```

0 commit comments

Comments
 (0)