11function parsed = parseDataset(filename , info , fullpath , Blacklist )
2- % typed and untyped being container maps containing type and untyped datasets
3- % the maps store information regarding information and stored data
4- % NOTE, dataset name is in path format so we need to parse that out.
5- name = info .Name ;
2+ % typed and untyped being container maps containing type and untyped datasets
3+ % the maps store information regarding information and stored data
4+ % NOTE, dataset name is in path format so we need to parse that out.
5+ name = info .Name ;
66
7- % check if typed and parse attributes
8- [attrargs , Type ] = io .parseAttributes(filename , info .Attributes , fullpath , Blacklist );
7+ % check if typed and parse attributes
8+ [attrargs , Type ] = io .parseAttributes(filename , info .Attributes , fullpath , Blacklist );
99
10- fid = H5F .open(filename , ' H5F_ACC_RDONLY' , ' H5P_DEFAULT' );
11- did = H5D .open(fid , fullpath );
12- props = attrargs ;
13- datatype = info .Datatype ;
14- dataspace = info .Dataspace ;
10+ fid = H5F .open(filename , ' H5F_ACC_RDONLY' , ' H5P_DEFAULT' );
11+ did = H5D .open(fid , fullpath );
12+ props = attrargs ;
13+ datatype = info .Datatype ;
14+ dataspace = info .Dataspace ;
1515
16- parsed = containers .Map ;
17- afields = keys(attrargs );
18- if ~isempty(afields )
19- anames = strcat(name , ' _' , afields );
20- parsed = [parsed ; containers .Map(anames , attrargs .values(afields ))];
21- end
16+ parsed = containers .Map ;
17+ afields = keys(attrargs );
18+ if ~isempty(afields )
19+ anames = strcat(name , ' _' , afields );
20+ parsed = [parsed ; containers .Map(anames , attrargs .values(afields ))];
21+ end
2222
23- % loading h5t references are required
24- % unfortunately also a bottleneck
25- if strcmp(datatype .Class , ' H5T_REFERENCE' )
26- tid = H5D .get_type(did );
27- data = io .parseReference(did , tid , H5D .read(did ));
28- H5T .close(tid );
29- elseif ~strcmp(dataspace .Type , ' simple' )
30- data = H5D .read(did );
23+ % loading h5t references are required
24+ % unfortunately also a bottleneck
25+ if strcmp(datatype .Class , ' H5T_REFERENCE' )
26+ tid = H5D .get_type(did );
27+ data = io .parseReference(did , tid , H5D .read(did ));
28+ H5T .close(tid );
29+ elseif ~strcmp(dataspace .Type , ' simple' )
30+ data = H5D .read(did );
3131
32- switch datatype .Class
33- case ' H5T_STRING'
34- if datetime(version(' -date' )) < datetime(' 25-Feb-2020' )
35- % MATLAB 2020a fixed string support for HDF5, making
36- % reading strings "consistent" with regular use.
37- data = data .' ;
38- end
39- datadim = size(data );
40- if datadim(1 ) > 1
41- % multidimensional strings should become cellstr
42- data = strtrim(mat2cell(data , ones(datadim(1 ), 1 ), datadim(2 )));
43- end
44- case ' H5T_ENUM'
45- if io .isBool(datatype .Type )
46- data = strcmp(' TRUE' , data );
47- else
48- warning(' NWB:Dataset:UnknownEnum' , ...
49- [' Encountered unknown enum under field `%s ` with %d members. ' ...
50- ' Will be saved as cell array of characters.' ], ...
51- info .Name , length(datatype .Type .Member ));
52- end
53- end
54- else
55- sid = H5D .get_space(did );
56- pid = H5D .get_create_plist(did );
57- isChunked = H5P .get_layout(pid ) == H5ML .get_constant_value(' H5D_CHUNKED' );
58-
59- tid = H5D .get_type(did );
60- class_id = H5T .get_class(tid );
61- isNumeric = class_id == H5ML .get_constant_value(' H5T_INTEGER' )...
62- || class_id == H5ML .get_constant_value(' H5T_FLOAT' );
63- if isChunked && isNumeric
64- data = types .untyped .DataPipe(' filename' , filename , ' path' , fullpath );
65- elseif any(dataspace .Size == 0 )
66- data = [];
32+ switch datatype .Class
33+ case ' H5T_STRING'
34+ if verLessThan(' MATLAB' , ' 9.8' )
35+ % MATLAB 2020a fixed string support for HDF5, making
36+ % reading strings "consistent" with regular use.
37+ data = data .' ;
38+ end
39+ datadim = size(data );
40+ if datadim(1 ) > 1
41+ % multidimensional strings should become cellstr
42+ data = strtrim(mat2cell(data , ones(datadim(1 ), 1 ), datadim(2 )));
43+ end
44+ case ' H5T_ENUM'
45+ if io .isBool(datatype .Type )
46+ data = strcmp(' TRUE' , data );
47+ else
48+ warning(' NWB:Dataset:UnknownEnum' , ...
49+ [' Encountered unknown enum under field `%s ` with %d members. ' ...
50+ ' Will be saved as cell array of characters.' ], ...
51+ info .Name , length(datatype .Type .Member ));
52+ end
53+ end
6754 else
68- data = types .untyped .DataStub(filename , fullpath );
55+ sid = H5D .get_space(did );
56+ pid = H5D .get_create_plist(did );
57+ isChunked = H5P .get_layout(pid ) == H5ML .get_constant_value(' H5D_CHUNKED' );
58+
59+ tid = H5D .get_type(did );
60+ class_id = H5T .get_class(tid );
61+ isNumeric = class_id == H5ML .get_constant_value(' H5T_INTEGER' )...
62+ || class_id == H5ML .get_constant_value(' H5T_FLOAT' );
63+ if isChunked && isNumeric
64+ data = types .untyped .DataPipe(' filename' , filename , ' path' , fullpath );
65+ elseif any(dataspace .Size == 0 )
66+ data = [];
67+ else
68+ data = types .untyped .DataStub(filename , fullpath );
69+ end
70+ H5T .close(tid );
71+ H5P .close(pid );
72+ H5S .close(sid );
6973 end
70- H5T .close(tid );
71- H5P .close(pid );
72- H5S .close(sid );
73- end
7474
75- if isempty(Type .typename )
76- % untyped group
77- parsed(name ) = data ;
78- else
79- props(' data' ) = data ;
80- kwargs = io .map2kwargs(props );
81- parsed = eval([Type .typename ' (kwargs{:})' ]);
82- end
83- H5D .close(did );
84- H5F .close(fid );
75+ if isempty(Type .typename )
76+ % untyped group
77+ parsed(name ) = data ;
78+ else
79+ props(' data' ) = data ;
80+ kwargs = io .map2kwargs(props );
81+ parsed = eval([Type .typename ' (kwargs{:})' ]);
82+ end
83+ H5D .close(did );
84+ H5F .close(fid );
8585end
0 commit comments