Skip to content

Commit a6b592d

Browse files
committed
Merge remote-tracking branch 'remotes/origin/development'
2 parents 666ab6d + f83beb3 commit a6b592d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2351
-423
lines changed

DataTree/AcquiredData/DataFiles/DataFilesClass.m

Lines changed: 294 additions & 39 deletions
Large diffs are not rendered by default.

DataTree/AcquiredData/DataFiles/FileClass.m

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
err
2121
logger
2222
errmsg
23+
errcodeUnvalidated
2324
end
2425

2526
methods
@@ -40,8 +41,8 @@
4041
obj.rootdir = '';
4142
obj.errmsg = ''; % Assume file is not loadable
4243
obj.logger = InitLogger(logger);
43-
obj.errmsg = '';
4444

45+
obj.errcodeUnvalidated = -9999;
4546

4647
if nargin==0
4748
return;
@@ -88,7 +89,13 @@ function Add(obj, obj2)
8889
obj.filename = obj2.name;
8990
obj.name = getPathRelative(rootpath, obj2.rootdir);
9091
obj.rootdir = obj2.rootdir;
91-
obj.err = 0; % Set error to NO ERROR
92+
obj.date = obj2.date;
93+
obj.datenum = datestr2datenum(obj.date);
94+
if obj.IsFile()
95+
obj.err = obj.errcodeUnvalidated; % Set error to unvalidated
96+
else
97+
obj.err = 0;
98+
end
9299
end
93100

94101

@@ -434,7 +441,7 @@ function Loaded(obj)
434441
if isempty(obj.name)
435442
return;
436443
end
437-
if obj.err ~= 0
444+
if (obj.err ~= 0) && (obj.IsValidated)
438445
return;
439446
end
440447
b = false;
@@ -443,19 +450,22 @@ function Loaded(obj)
443450

444451
% ----------------------------------------------------
445452
function err = ErrorCheckName(obj)
453+
err = 0;
446454
[p1,f1] = fileparts(obj.name);
447455
[p2,f2] = fileparts(filesepStandard(obj.rootdir,'nameonly:file'));
448456
[~,f3] = fileparts(p2);
449457
if strcmp(f1, p1)
450-
obj.err = -1;
458+
err = -1;
451459
end
452460
if strcmp(f1, f2)
453-
obj.err = -2;
461+
err = -2;
454462
end
455463
if strcmp(f1, f3)
456-
obj.err = -3;
464+
err = -3;
465+
end
466+
if err ~= 0
467+
obj.err = err;
457468
end
458-
err = obj.err;
459469
end
460470

461471

@@ -545,6 +555,7 @@ function NameConflictFixed(obj)
545555
% -----------------------------------------------------
546556
function SetError(obj, errmsg)
547557
obj.errmsg = errmsg;
558+
obj.err = -1;
548559
end
549560

550561

@@ -553,6 +564,62 @@ function SetError(obj, errmsg)
553564
msg = obj.errmsg;
554565
end
555566

567+
568+
% -----------------------------------------------------
569+
function SetValid(obj)
570+
obj.err = 0;
571+
end
572+
573+
574+
% -----------------------------------------------------
575+
function SetErrorUnvalidated(obj)
576+
obj.err = obj.errcodeUnvalidated;
577+
end
578+
579+
580+
% -----------------------------------------------------
581+
function b = IsValidated(obj)
582+
b = false;
583+
if obj.err == obj.errcodeUnvalidated
584+
return
585+
end
586+
b = true;
587+
end
588+
589+
590+
591+
% -----------------------------------------------------
592+
function b = IsUnValidated(obj)
593+
b = true;
594+
if obj.err == obj.errcodeUnvalidated
595+
return
596+
end
597+
b = false;
598+
end
599+
600+
601+
602+
% ----------------------------------------------------------
603+
function b = eq(obj, obj2)
604+
b = false;
605+
if ~strcmp(obj.name, obj2.name)
606+
return;
607+
end
608+
if ~strcmp(obj.date, obj2.date)
609+
return;
610+
end
611+
if obj.isdir ~= obj2.isdir
612+
return;
613+
end
614+
if obj.bytes ~= obj2.bytes
615+
return;
616+
end
617+
if obj.datenum ~= obj2.datenum
618+
return;
619+
end
620+
b = true;
621+
end
622+
556623
end
557624

558625
end

DataTree/AcquiredData/DataFiles/Hdf5/HDF5_DatasetLoad.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,20 @@
88
end
99

1010
try
11-
dsetid = H5D.open(gid, name);
1211

12+
if ~H5L.exists(gid, name, 'H5P_DEFAULT')
13+
switch(class(val0))
14+
case 'char'
15+
val = '';
16+
case 'cell'
17+
val = {};
18+
otherwise
19+
val = [];
20+
end
21+
return
22+
end
23+
24+
dsetid = H5D.open(gid, name);
1325
% NOTE: HDF5 stores contiguous muti-dimensional arrays in row-major order.
1426
% Matlab stores them in row-major order. We want to transpose the loaded data
1527
% it back to Matlab's column-major storage order and thus get back the
@@ -29,3 +41,5 @@
2941
val = [];
3042
end
3143
end
44+
45+

DataTree/AcquiredData/DataFiles/Hdf5/HDF5_Transpose.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
function val = HDF5_Transpose(val, options)
1+
function val = HDF5_Transpose(val, option)
22

3-
if ~exist('options','var')
4-
options = '';
3+
if ~exist('option','var')
4+
option = '';
55
end
66

77
% Matlab stores contiguous muti-dimensional arrays in column-major order.
88
% HDF5 stores them in row-major order. We want to transpose the data to agree
99
% with the file format's storage order.
1010
if (~isrow(val) && ~iscolumn(val)) || ... % Matrices
11-
~isempty(findstr('multidim', options)) || ... % Force multi-dimensional even if vector
12-
~isempty(findstr('2D', options)) || ... % Force 2D even if vector
13-
~isempty(findstr('3D', options)) % Force 3D even if vector
11+
~isempty(findstr('multidim', option)) || ... % Force multi-dimensional even if vector
12+
~isempty(findstr('2D', option)) || ... % Force 2D even if vector
13+
~isempty(findstr('3D', option)) % Force 3D even if vector
1414

1515
val = permute(val, ndims(val):-1:1);
1616

DataTree/AcquiredData/DataFiles/Hdf5/hdf5write_safe.m

Lines changed: 81 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
function err = hdf5write_safe(fileobj, name, val, options)
22
err = -1;
3-
if isempty(val)
3+
if ~exist('val','var')
44
return;
55
end
66
if ~exist('options','var')
77
options = '';
88
end
99

10-
force_scalar = false;
1110
force_array = false;
11+
force_vector = false;
1212
if any(strcmp(options, 'array'))
1313
force_array = true;
14-
elseif any(strcmp(options, 'scalar'))
15-
force_scalar = true;
14+
elseif any(strcmp(options, 'vector'))
15+
force_vector = true;
1616
end
1717

1818
% Identify type of val and use SNIRF v1.1-compliant write function
@@ -32,25 +32,21 @@
3232

3333
% Create dataset
3434
if iscell(val) || isstring(val)
35-
if length(val) > 1 && ~force_scalar || force_array % Returns true for single strings, believe it or not
35+
if (length(val) > 1) || force_array % Returns true for single strings, believe it or not
3636
write_string_array(fid, name, val);
3737
else
3838
write_string(fid, name, val);
3939
end
4040
elseif ischar(val)
4141
write_string(fid, name, val);
42-
elseif isfloat(val)
43-
if length(val) > 1 && ~force_scalar || force_array
42+
elseif isfloat(val) || isinteger(val)
43+
if force_vector
44+
write_numeric_vector(fid, name, val);
45+
elseif (length(val) > 1) || force_array
4446
write_numeric_array(fid, name, val);
4547
else
4648
write_numeric(fid, name, val);
4749
end
48-
elseif isinteger(val)
49-
if length(val) > 1 && ~force_scalar || force_array
50-
write_numeric_array(fid, name, val); % As of now, no integer arrays exist
51-
else
52-
write_integer(fid, name, val);
53-
end
5450
else
5551
warning(['An unrecognized variable was saved to ', name])
5652
end
@@ -82,50 +78,76 @@
8278

8379

8480

81+
8582
% -----------------------------------------------------------------
8683
function err = write_numeric(fid, name, val)
87-
tid = H5T.copy('H5T_NATIVE_DOUBLE');
84+
warning off; % Suppress the int truncation warning
85+
hdftype = convert_to_hdf5_type(val);
86+
tid = H5T.copy(hdftype);
8887
sid = H5S.create('H5S_SCALAR');
8988
dsid = H5D.create(fid, name, tid, sid, 'H5P_DEFAULT');
9089
H5D.write(dsid, tid, 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT', val);
9190
err = 0;
91+
warning on;
92+
9293

9394

9495

9596
% -----------------------------------------------------------------
96-
function err = write_integer(fid, name, val)
97-
warning off; % Suppress the int truncation warning
98-
tid = H5T.copy('H5T_NATIVE_ULONG');
99-
sid = H5S.create('H5S_SCALAR');
100-
dsid = H5D.create(fid, name, tid, sid, 'H5P_DEFAULT');
101-
H5D.write(dsid, tid, 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT', int32(val));
97+
function err = write_numeric_array(fid, name, data)
10298
err = 0;
103-
warning on;
99+
data = HDF5_Transpose(data, '2D');
100+
sizedata = size(data);
101+
n = sizedata;
102+
103+
tid = -1;
104+
sid = -1;
105+
gid = -1;
106+
dsid = -1;
107+
108+
maxdims = n;
109+
110+
hdftype = convert_to_hdf5_type(data);
111+
112+
try
113+
114+
sid = H5S.create_simple(numel(n), fliplr(n), fliplr(maxdims));
115+
gid = HDF5_CreateGroup(fid, fileparts(name));
116+
dsid = H5D.create(gid, name, hdftype, sid, 'H5P_DEFAULT');
117+
H5D.write(dsid, 'H5ML_DEFAULT', 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT', data);
118+
119+
catch
120+
121+
% Clean up; Close everything
122+
cleanUp(tid, sid, gid, dsid);
123+
err = -1;
124+
return;
125+
126+
end
127+
cleanUp(tid, sid, gid, dsid);
128+
104129

105130

106131

107132
% -----------------------------------------------------------------
108-
function err = write_numeric_array(fid, name, data)
133+
function err = write_numeric_vector(fid, name, data)
109134
err = 0;
110-
data = HDF5_Transpose(data);
111-
sizedata = size(data);
112-
if sizedata(1) == 1 || sizedata(2) == 1
113-
n = length(data);
114-
else
115-
n = sizedata;
116-
end
135+
data = HDF5_Transpose(data, '2D');
136+
sizedata = length(data);
137+
n = sizedata;
117138

118139
tid = -1;
119140
sid = -1;
120141
gid = -1;
121142
dsid = -1;
122143

123144
maxdims = n;
145+
hdftype = convert_to_hdf5_type(data);
124146
try
125147

126-
sid = H5S.create_simple(numel(n), fliplr(n), fliplr(maxdims));
148+
sid = H5S.create_simple(numel(n), fliplr(n), fliplr(maxdims));
127149
gid = HDF5_CreateGroup(fid, fileparts(name));
128-
dsid = H5D.create(gid, name, 'H5T_NATIVE_DOUBLE', sid, 'H5P_DEFAULT');
150+
dsid = H5D.create(gid, name, hdftype, sid, 'H5P_DEFAULT');
129151
H5D.write(dsid, 'H5ML_DEFAULT', 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT', data);
130152

131153
catch
@@ -140,6 +162,7 @@
140162

141163

142164

165+
143166
% ------------------------------------------------------
144167
function cleanUp(tid, sid, gid, dsid)
145168
if ~isnumeric(tid)
@@ -156,3 +179,30 @@ function cleanUp(tid, sid, gid, dsid)
156179
end
157180

158181

182+
183+
184+
% -------------------------------------------------------
185+
function hdftype = convert_to_hdf5_type(val)
186+
hdftype = '';
187+
switch class(val)
188+
case 'int8'
189+
hdftype = 'H5T_STD_8LE';
190+
case 'uint8'
191+
hdftype = 'H5T_STD_U8LE';
192+
case 'int16'
193+
hdftype = 'H5T_STD_16LE';
194+
case 'uint16'
195+
hdftype = 'H5T_STD_U16LE';
196+
case 'int32'
197+
hdftype = 'H5T_STD_32LE';
198+
case 'uint32'
199+
hdftype = 'H5T_STD_U32LE';
200+
case 'int64'
201+
hdftype = 'H5T_STD_64LE';
202+
case 'uint64'
203+
hdftype = 'H5T_STD_U64LE';
204+
case 'double'
205+
hdftype = 'H5T_NATIVE_DOUBLE';
206+
end
207+
208+

0 commit comments

Comments
 (0)