Skip to content

Commit

Permalink
use name=value syntax for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jun 14, 2022
1 parent c3d26d5 commit d2e1082
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 28 deletions.
5 changes: 2 additions & 3 deletions +stdlib/+fileio/which.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
import stdlib.fileio.expanduser

if ispc
pathext = ".exe";
if ~endsWith(name, pathext)
name = name + pathext;
if ~endsWith(name, ".exe")
name = name + ".exe";
end
end

Expand Down
8 changes: 4 additions & 4 deletions +stdlib/+hdf5nc/h5save.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ function exist_file(filename, varname, A, sizeA)
if isscalar(A)
h5write(filename, varname, A)
elseif all(diskshape == sizeA)
h5write(filename, varname, A, start, sizeA)
h5write(filename, varname, A, start, count=sizeA)
elseif all(diskshape == fliplr(sizeA))
h5write(filename, varname, A.', start, fliplr(sizeA))
h5write(filename, varname, A.', start, count=fliplr(sizeA))
else
error('hdf5nc:h5save:value_error', ['shape of ',varname,': ', int2str(sizeA), ' does not match existing HDF5 shape ', int2str(diskshape)])
end
Expand All @@ -74,7 +74,7 @@ function new_file(filename, varname, A, sizeA)
h5_write_scalar(filename, varname, A)
return
elseif isvector(A)
h5create(filename, varname, length(A), 'DataType', class(A))
h5create(filename, varname, length(A), Datatype=class(A))
else
create_compress(filename, varname, A, size(A))
end
Expand All @@ -84,7 +84,7 @@ function new_file(filename, varname, A, sizeA)
h5_write_scalar(filename, varname, A)
return
else
h5create(filename, varname, sizeA, 'DataType', class(A))
h5create(filename, varname, sizeA, Datatype=class(A))
end
else
create_compress(filename, varname, A, sizeA)
Expand Down
15 changes: 7 additions & 8 deletions +stdlib/+hdf5nc/ncsave.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,17 @@ function new_file(filename, varname, A, sizeA, ncdims)
end

if isscalar(A)
nccreate(filename, varname, 'Datatype', class(A), 'Format', 'netcdf4')
nccreate(filename, varname, Datatype=class(A), Format='netcdf4')
elseif isvector(A)
nccreate(filename, varname, 'Dimensions', ncdims, 'Datatype', class(A), 'Format', 'netcdf4')
nccreate(filename, varname, Dimensions=ncdims, Datatype=class(A), Format='netcdf4')
else
% enable Gzip compression--remember Matlab's dim order is flipped from
% C / Python
% "Datatype" to be Octave case-sensitive keyword compatible
nccreate(filename, varname, 'Dimensions', ncdims, ...
'Datatype', class(A), ...
'DeflateLevel', 1, 'Shuffle', true, ...
'ChunkSize', auto_chunk_size(sizeA), ...
'Format', 'netcdf4')
nccreate(filename, varname, Dimensions=ncdims, ...
Datatype=class(A), ...
DeflateLevel=1, Shuffle=true, ...
ChunkSize=auto_chunk_size(sizeA), ...
Format='netcdf4')
end

ncwrite(filename, varname, A)
Expand Down
6 changes: 3 additions & 3 deletions +stdlib/+hdf5nc/private/create_compress.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ function create_compress(filename, varname, A, sizeA)

import stdlib.hdf5nc.auto_chunk_size

h5create(filename, varname, sizeA, 'DataType', class(A), ...
'Deflate', 1, 'Fletcher32', true, 'Shuffle', true, ...
'ChunkSize', auto_chunk_size(sizeA))
h5create(filename, varname, sizeA, Datatype=class(A), ...
Deflate=1, Fletcher32=true, Shuffle=true, ...
ChunkSize=auto_chunk_size(sizeA))

end
8 changes: 4 additions & 4 deletions +stdlib/TestHDF5.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function setup_file(tc)
h5save(basic, '/A0', A0)
h5save(basic, '/A1', A1)
h5save(basic, '/A2', A2)
h5save(basic, '/A3', A3, "size", size(A3))
h5save(basic, '/A3', A3, size=size(A3))
h5save(basic, '/A4', A4)
h5save(basic, "/utf", utf)
h5save(basic, "/utf2", utf2)
Expand Down Expand Up @@ -204,11 +204,11 @@ function test_shape(tc)
import stdlib.hdf5nc.h5size
basic = tc.TestData.basic;

h5save(basic, "/vector1", 34, "size", 1)
h5save(basic, "/vector1", 34, size=1)
s = h5size(basic, '/vector1');
tc.verifyEqual(s, 1);

h5save(basic, "/scalar", 34, "size", 0)
h5save(basic, "/scalar", 34, size=0)
s = h5size(basic, '/scalar');
tc.verifyEmpty(s);

Expand All @@ -222,7 +222,7 @@ function test_coerce(tc, type)

vn = "/" + type;

h5save(basic, vn, 0, "type", type)
h5save(basic, vn, 0, type=type)

tc.assumeThat(basic, IsFile)

Expand Down
8 changes: 4 additions & 4 deletions +stdlib/TestNetCDF.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ function setup_file(tc)
% create test data first, so that parallel tests works
ncsave(basic, 'A0', A0)
ncsave(basic, 'A1', A1)
ncsave(basic, 'A2', A2, "dims", {'x2', size(A2,1), 'y2', size(A2,2)})
ncsave(basic, 'A3', A3, "dims", {'x3', size(A3,1), 'y3', size(A3,2), 'z3', size(A3,3)})
ncsave(basic, 'A4', A4, "dims", {'x4', size(A4,1), 'y4', size(A4,2), 'z4', size(A4,3), 'w4', size(A4,4)})
ncsave(basic, 'A2', A2, dims={'x2', size(A2,1), 'y2', size(A2,2)})
ncsave(basic, 'A3', A3, dims={'x3', size(A3,1), 'y3', size(A3,2), 'z3', size(A3,3)})
ncsave(basic, 'A4', A4, dims={'x4', size(A4,1), 'y4', size(A4,2), 'z4', size(A4,3), 'w4', size(A4,4)})
ncsave(basic, "utf0", utf0)
ncsave(basic, "utf1", utf1)
ncsave(basic, "utf2", utf2)
Expand Down Expand Up @@ -185,7 +185,7 @@ function test_coerce(tc, type)

vn = type;

ncsave(basic, vn, 0, "type", type)
ncsave(basic, vn, 0, type=type)

tc.assumeThat(basic, IsFile)

Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ This is particularly useful when writing HDF5 files to be used in other programm
Matlab may collapse singleton dimensions otherwise.

```matlab
h5save(filename, dataset_name, dataset, "size", [3,1])
h5save(filename, dataset_name, dataset, size=[3,1])
```

Likewise, the type of the dataset may be explicitly specified with the "type" argument:

```matlab
h5save(filename, dataset_name, dataset, "type", "int32")
h5save(filename, dataset_name, dataset, type="int32")
```

---
Expand Down
7 changes: 7 additions & 0 deletions buildfile.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function plan = buildfile
plan = buildplan(localfunctions);
end

function testTask(~)
assertSuccess(runtests('stdlib'))
end

0 comments on commit d2e1082

Please sign in to comment.