Skip to content

Commit fb1ddad

Browse files
committed
[Matlab] Refactor DataArray creation error struct
1 parent ffd1437 commit fb1ddad

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

+nix/Block.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@
9595
shape(2:size(shape, 2));
9696
end
9797

98-
errorStruct.identifier = 'Block:unsupportedDataType';
98+
err.identifier = 'Block:unsupportedDataType';
9999
if (~isa(datatype, 'nix.DataType'))
100-
errorStruct.message = 'Please provide a valid nix.DataType';
101-
error(errorStruct);
100+
err.message = 'Please provide a valid nix.DataType';
101+
error(err);
102102
elseif (isequal(datatype, nix.DataType.String))
103-
errorStruct.message = 'Writing Strings to DataArrays is not supported as of yet.';
104-
error(errorStruct);
103+
err.message = 'Writing char/string DataArrays is currently not supported.';
104+
error(err);
105105
else
106106
fname = strcat(obj.alias, '::createDataArray');
107107
h = nix_mx(fname, obj.nix_handle, name, nixtype, lower(datatype.char), shape);
@@ -119,17 +119,17 @@
119119
shape = size(data, 2);
120120
end
121121

122-
errorStruct.identifier = 'Block:unsupportedDataType';
122+
err.identifier = 'Block:unsupportedDataType';
123123
if (ischar(data))
124-
errorStruct.message = 'Writing Strings to DataArrays is not supported as of yet.';
125-
error(errorStruct);
124+
err.message = 'Writing char/string DataArrays is currently not supported.';
125+
error(err);
126126
elseif (islogical(data))
127127
dtype = nix.DataType.Bool;
128128
elseif (isnumeric(data))
129129
dtype = nix.DataType.Double;
130130
else
131-
errorStruct.message = 'DataType of provided data is not supported.';
132-
error(errorStruct);
131+
err.message = 'DataType of provided data is not supported.';
132+
error(err);
133133
end
134134

135135
r = obj.create_data_array(name, nixtype, dtype, shape);

+nix/DataArray.m

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,26 @@
121121
disp('Warning: Writing Float data to an Integer DataArray');
122122
end
123123

124-
errorStruct.identifier = 'DataArray:improperDataType';
124+
err.identifier = 'DataArray:improperDataType';
125125
if (islogical(obj.read_all) && ~islogical(data))
126-
errorStruct.message = strcat('Trying to write', ...
127-
32, class(data), ' to a logical DataArray.');
128-
error(errorStruct);
126+
m = sprintf('Trying to write %s to a logical DataArray', class(data));
127+
err.message = m;
128+
error(err);
129129
elseif (isnumeric(obj.read_all) && ~isnumeric(data))
130-
errorStruct.message = strcat('Trying to write', ...
131-
32, class(data), ' to a ', 32, class(obj.read_all), ...
132-
' DataArray.');
133-
error(errorStruct);
130+
m = sprintf('Trying to write %s to a %s DataArray', class(data), class(obj.read_all));
131+
err.message = m;
132+
error(err);
134133
elseif (ischar(data))
135134
%-- Should actually not be reachable at the moment,
136135
%-- since writing Strings to DataArrays is not supported,
137136
%-- but safety first.
138-
errorStruct.identifier = 'DataArray:unsupportedDataType';
139-
errorStruct.message = ('Writing char/string DataArrays is not supported as of yet.');
140-
error(errorStruct);
141-
else
142-
fname = strcat(obj.alias, '::writeAll');
143-
nix_mx(fname, obj.nix_handle, nix.Utils.transpose_array(data));
137+
err.identifier = 'DataArray:unsupportedDataType';
138+
err.message = 'Writing char/string DataArrays is currently not supported.';
139+
error(err);
144140
end
141+
142+
fname = strcat(obj.alias, '::writeAll');
143+
nix_mx(fname, obj.nix_handle, nix.Utils.transpose_array(data));
145144
end
146145

147146
function r = datatype(obj)

0 commit comments

Comments
 (0)