Skip to content

Commit d72dbe3

Browse files
committed
Merge branch 'master' into aliasRangeDim
Resolve Merge conflict: +nix/Block.m
2 parents fc64580 + 41a28dc commit d72dbe3

File tree

14 files changed

+462
-203
lines changed

14 files changed

+462
-203
lines changed

+nix/Block.m

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,19 @@
5252
'Block::openDataArray', id_or_name, @nix.DataArray);
5353
end;
5454

55-
%-- As "datatype" provide one of the nix.DataTypes. Alternatively
56-
%-- a string stating one of the datatypes supported by nix can be provided.
5755
function da = create_data_array(obj, name, nixtype, datatype, shape)
58-
handle = nix_mx('Block::createDataArray', obj.nix_handle, ...
59-
name, nixtype, datatype, shape);
60-
da = nix.DataArray(handle);
56+
errorStruct.identifier = 'Block:unsupportedDataType';
57+
if(~isa(datatype, 'nix.DataType'))
58+
errorStruct.message = 'Please provide a valid nix.DataType';
59+
error(errorStruct);
60+
elseif(isequal(datatype, nix.DataType.String))
61+
errorStruct.message = 'Writing Strings to DataArrays is not supported as of yet.';
62+
error(errorStruct);
63+
else
64+
handle = nix_mx('Block::createDataArray', obj.nix_handle, ...
65+
name, nixtype, lower(datatype.char), shape);
66+
da = nix.DataArray(handle);
67+
end;
6168
end
6269

6370
function da = create_data_array_from_data(obj, name, nixtype, data)
@@ -66,12 +73,23 @@
6673
%-- 1D data arrays created with this function.
6774
%-- e.g. size([1 2 3]) returns shape [1 3], which would not
6875
%-- be accepted when trying to add an alias range dimension.
69-
%-- TODO Remove this when a cleverer solution presents itself.
7076
if(size(data, 1) == 1)
7177
shape = size(data, 2);
7278
end;
73-
dtype = class(data);
74-
79+
80+
errorStruct.identifier = 'Block:unsupportedDataType';
81+
if(ischar(data))
82+
errorStruct.message = 'Writing Strings to DataArrays is not supported as of yet.';
83+
error(errorStruct);
84+
elseif(islogical(data))
85+
dtype = nix.DataType.Bool;
86+
elseif(isnumeric(data))
87+
dtype = nix.DataType.Double;
88+
else
89+
errorStruct.message = 'DataType of provided data is not supported.';
90+
error(errorStruct);
91+
end;
92+
7593
da = obj.create_data_array(name, nixtype, dtype, shape);
7694
da.write_all(data);
7795
end
@@ -145,7 +163,7 @@
145163
'Block::openMultiTag', id_or_name, @nix.MultiTag);
146164
end;
147165

148-
%-- creating a multitag requires an already existing data array
166+
%-- Creating a multitag requires an already existing data array
149167
function multitag = create_multi_tag(obj, name, type, add_data_array)
150168
if(strcmp(class(add_data_array), 'nix.DataArray'))
151169
addID = add_data_array.id;
@@ -161,6 +179,6 @@
161179
delCheck = nix.Utils.delete_entity(obj, ...
162180
del, 'nix.MultiTag', 'Block::deleteMultiTag');
163181
end;
164-
end;
165182

183+
end;
166184
end

+nix/DataArray.m

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,38 @@
8181
data = permute(tmp, length(size(tmp)):-1:1);
8282
end;
8383

84-
function write_all(obj, data) % TODO add (optional) offset
85-
% data must agree with file & dimensions
86-
% see mkarray.cc(42)
87-
tmp = permute(data, length(size(data)):-1:1);
88-
nix_mx('DataArray::writeAll', obj.nix_handle, tmp);
84+
%-- TODO add (optional) offset
85+
%-- If a DataArray has been created as boolean or numeric,
86+
%-- provide that only values of the proper DataType can be written.
87+
function write_all(obj, data)
88+
if(isinteger(obj.read_all) && isfloat(data))
89+
disp('Warning: Writing Float data to an Integer DataArray');
90+
end;
91+
92+
errorStruct.identifier = 'DataArray:improperDataType';
93+
if(islogical(obj.read_all) && ~islogical(data))
94+
errorStruct.message = strcat('Trying to write', ...
95+
32, class(data), ' to a logical DataArray.');
96+
error(errorStruct);
97+
elseif(isnumeric(obj.read_all) && ~isnumeric(data))
98+
errorStruct.message = strcat('Trying to write', ...
99+
32, class(data), ' to a ', 32, class(obj.read_all), ...
100+
' DataArray.');
101+
error(errorStruct);
102+
elseif(ischar(data))
103+
%-- Should actually not be reachable at the moment,
104+
%-- since writing Strings to DataArrays is not supported,
105+
%-- but safety first.
106+
errorStruct.identifier = 'DataArray:unsupportedDataType';
107+
errorStruct.message = ('Writing char/string DataArrays is not supported as of yet.');
108+
error(errorStruct);
109+
else
110+
% data must agree with file & dimensions
111+
% see mkarray.cc(42)
112+
tmp = permute(data, length(size(data)):-1:1);
113+
nix_mx('DataArray::writeAll', obj.nix_handle, tmp);
114+
end;
89115
end;
90-
116+
91117
end;
92118
end

+nix/DataType.m

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
classdef DataType
2-
%DATATYPE datatypes supported by nix
2+
% DataTypes supported by nix.
33

4-
properties (Constant)
5-
Boolean = 'bool';
6-
String = 'string';
7-
Double = 'double';
8-
Char = 'char';
9-
Float = 'float';
10-
Int8 = 'int8';
11-
Int16 = 'int16';
12-
Int32 = 'int32';
13-
Int64 = 'int64';
14-
UInt8 = 'uint8';
15-
UInt16 = 'uint16';
16-
UInt32 = 'uint32';
17-
UInt64 = 'uint64';
4+
enumeration
5+
Bool;
6+
String;
7+
Double;
8+
Float;
9+
Int8;
10+
Int16;
11+
Int32;
12+
Int64;
13+
UInt8;
14+
UInt16;
15+
UInt32;
16+
UInt64;
1817
end
19-
18+
2019
end
20+

+nix/Section.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,13 @@
8484
% Property methods
8585
% ----------------
8686

87-
%-- As "datatype" provide one of the nix.DataTypes. Alternatively
88-
%-- a string stating one of the datatypes supported by nix can be provided.
8987
function p = create_property(obj, name, datatype)
90-
p = nix.Property(nix_mx('Section::createProperty', ...
91-
obj.nix_handle, name, datatype));
88+
if(~isa(datatype, 'nix.DataType'))
89+
error('Please provide a valid nix.DataType');
90+
else
91+
p = nix.Property(nix_mx('Section::createProperty', ...
92+
obj.nix_handle, name, lower(datatype.char)));
93+
end;
9294
end;
9395

9496
function p = create_property_with_value(obj, name, val)
@@ -128,5 +130,5 @@
128130
end
129131
end;
130132

131-
end
133+
end;
132134
end

src/nixdataarray.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ namespace nixdataarray {
4242

4343
void read_all(const extractor &input, infusor &output)
4444
{
45-
//nix::DataArray da = input.entity<nix::DataArray>(1);
46-
4745
nix::DataArray da = input.entity<nix::DataArray>(1);
4846
mxArray *data = make_mx_array_from_ds(da);
4947
output.set(0, data);
@@ -52,13 +50,17 @@ namespace nixdataarray {
5250
void write_all(const extractor &input, infusor &output)
5351
{
5452
nix::DataArray da = input.entity<nix::DataArray>(1);
55-
5653
nix::DataType dtype = input.dtype(2);
54+
5755
nix::NDSize count = input.ndsize(2);
5856
nix::NDSize offset(0);
5957
double *ptr = input.get_raw(2);
60-
61-
da.setData(dtype, ptr, count, offset);
58+
59+
if (dtype == nix::DataType::String) {
60+
throw std::domain_error("Writing Strings to DataArrays is not supported as of yet.");
61+
} else {
62+
da.setData(dtype, ptr, count, offset);
63+
}
6264
}
6365

6466
void delete_dimension(const extractor &input, infusor &output) {
@@ -70,4 +72,4 @@ namespace nixdataarray {
7072
output.set(0, res);
7173
}
7274

73-
} // namespace nixdataarray
75+
} // namespace nixdataarray

src/utils/mkarray.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,22 @@ mxArray* make_mx_array_from_ds(const nix::DataSet &da) {
1414
for (size_t i = 0; i < len; i++) {
1515
dims[len - (i + 1)] = static_cast<mwSize>(size[i]);
1616
}
17-
1817
nix::DataType da_type = da.dataType();
1918
DType2 dtype = dtype_nix2mex(da_type);
2019

2120
if (!dtype.is_valid) {
2221
throw std::domain_error("Unsupported data type");
2322
}
2423

25-
mxArray *data = mxCreateNumericArray(dims.size(), dims.data(), dtype.cid, dtype.clx);
26-
double *ptr = mxGetPr(data);
27-
28-
nix::NDSize offset(size.size(), 0);
29-
da.getData(da_type, ptr, size, offset);
24+
mxArray *data;
25+
if (dtype.cid == mxCHAR_CLASS) {
26+
throw std::domain_error("String DataArrays are not supported as of yet.");
27+
} else {
28+
data = mxCreateNumericArray(dims.size(), dims.data(), dtype.cid, dtype.clx);
29+
double *ptr = mxGetPr(data);
30+
nix::NDSize offset(size.size(), 0);
31+
da.getData(da_type, ptr, size, offset);
32+
}
3033

3134
return data;
3235
}
@@ -94,4 +97,3 @@ mxArray* make_mx_array(const nix::Value &v)
9497
return res;
9598

9699
}
97-

0 commit comments

Comments
 (0)