Skip to content

Commit e95c2b6

Browse files
committed
fixDataTypeErrors: add Matlab boolean/char write check
1 parent 2ca141c commit e95c2b6

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

+nix/DataArray.m

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,24 @@
8888
data = permute(tmp, length(size(tmp)):-1:1);
8989
end;
9090

91-
function write_all(obj, data) % TODO add (optional) offset
92-
% data must agree with file & dimensions
93-
% see mkarray.cc(42)
94-
tmp = permute(data, length(size(data)):-1:1);
95-
nix_mx('DataArray::writeAll', obj.nix_handle, tmp);
91+
%-- TODO add (optional) offset
92+
function write_all(obj, data)
93+
%-- Bugifx: if a data array has been created as
94+
%-- boolean or char, provide check that only logical or char
95+
%-- values can be written, otherwise the
96+
%-- error message from nix is too cryptic.
97+
if(islogical(obj.read_all) && ~islogical(data))
98+
error(strcat('Trying to write', 32, class(data), ...
99+
' to a logical DataArray. Provide data as logical.'));
100+
elseif(ischar(obj.read_all) && ~ischar(data))
101+
error(strcat('Trying to write', 32, class(data), ...
102+
' to a char DataArray. Provide data as char.'));
103+
else
104+
% data must agree with file & dimensions
105+
% see mkarray.cc(42)
106+
tmp = permute(data, length(size(data)):-1:1);
107+
nix_mx('DataArray::writeAll', obj.nix_handle, tmp);
108+
end;
96109
end;
97110

98111
end;

0 commit comments

Comments
 (0)