Skip to content

Commit e67dcc0

Browse files
committed
hdf5, netcdf4: can write more integer types
'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64'
1 parent 5823bba commit e67dcc0

File tree

4 files changed

+10
-29
lines changed

4 files changed

+10
-29
lines changed

+stdlib/+hdf5nc/private/class2h5t.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
function t = class2h5t(A)
22
% gets HDF5 H5T of variable A
33

4-
switch class(A)
4+
C = class(A);
5+
switch C
56
case 'double', t = 'H5T_NATIVE_DOUBLE';
67
case 'single', t = 'H5T_NATIVE_FLOAT';
7-
case 'int32', t = 'H5T_STD_I32LE';
8-
case 'int64', t = 'H5T_STD_I64LE';
8+
case {'int8', 'int16', 'int32', 'int64'}
9+
t = "H5T_STD_I" + extractBetween(C, 4, strlength(C)) + "LE";
10+
case {'uint8', 'uint16', 'uint32', 'uint64'}
11+
t = "H5T_STD_U" + extractBetween(C, 5, strlength(C)) + "LE";
912
otherwise, error('h5save:class2h5t: unknown data class %s', class(A))
1013
end
1114

+stdlib/+hdf5nc/private/coerce_ds.m

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,8 @@
1717
switch dtype
1818
case ""
1919
return
20-
case {'float64', 'double'}
21-
if ~isa(A, 'double')
22-
A = double(A);
23-
end
24-
case {'float32', 'single'}
25-
if ~isa(A, 'single')
26-
A = single(A);
27-
end
28-
case 'int8'
29-
if ~isa(A, 'int8')
30-
A = int8(A);
31-
end
32-
case 'int16'
33-
if ~isa(A, 'int16')
34-
A = int16(A);
35-
end
36-
case 'int32'
37-
if ~isa(A, 'int32')
38-
A = int32(A);
39-
end
40-
case 'int64'
41-
if ~isa(A, 'int64')
42-
A = int64(A);
43-
end
20+
case {'float64', 'double', 'float32', 'single', 'int8', 'int16', 'int32', 'int64','uint8', 'uint16', 'uint32', 'uint64'}
21+
A = cast(A, dtype);
4422
case 'char'
4523
A = string(A);
4624
case 'string'

+stdlib/TestHDF5.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
end
66

77
properties (TestParameter)
8-
type = {'single', 'double', 'int8', 'int16', 'int32', 'int64'}
8+
type = {'single', 'double', 'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64'}
99
vars = {'A0', 'A1', 'A2', 'A3', 'A4'}
1010
str = {"string", 'char'}
1111
end

+stdlib/TestNetCDF.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
end
66

77
properties (TestParameter)
8-
type = {'single', 'double', 'int32', 'int64'}
8+
type = {'single', 'double', 'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64'}
99
vars = {'A0', 'A1', 'A2', 'A3', 'A4'}
1010
end
1111

0 commit comments

Comments
 (0)