1 | % hdf5load.m |
---|
2 | % |
---|
3 | % datastruct = hdf5load_recursive(datastruct,GroupHierarchy) |
---|
4 | % |
---|
5 | % Recursive procedure used to walk the Group Hierarchy of a given hinfo |
---|
6 | % HDF info struct and load the data in the return struct datastruct. |
---|
7 | |
---|
8 | % Author: Gael Varoquaux <gael.varoquaux@normalesup.org> |
---|
9 | % Copyright: Gael Varoquaux |
---|
10 | % License: BSD-like |
---|
11 | |
---|
12 | % 2016-05-24: Modifications by Antoine Campagne |
---|
13 | |
---|
14 | function datastruct = hdf5load_recursive(datastruct,GroupHierarchy) |
---|
15 | |
---|
16 | % Load the datasets (the leafs of the tree): |
---|
17 | for i=[1:size(GroupHierarchy.Datasets,2)] |
---|
18 | data=hdf5read(GroupHierarchy.Datasets(i)); |
---|
19 | switch class(data) |
---|
20 | case 'hdf5.h5string' |
---|
21 | try |
---|
22 | if size(data,2)>1 |
---|
23 | buffer=data ; |
---|
24 | data = {} ; |
---|
25 | for j=1:size(buffer,2) |
---|
26 | data{j}=buffer(j).Data; |
---|
27 | end |
---|
28 | else |
---|
29 | data=data.Data; |
---|
30 | end |
---|
31 | catch |
---|
32 | end |
---|
33 | case 'hdf5.h5array' |
---|
34 | try |
---|
35 | if size(data,2)>1 |
---|
36 | buffer=data ; |
---|
37 | data = {} ; |
---|
38 | for j=1:size(buffer,2) |
---|
39 | data{j}=buffer(j).Data; |
---|
40 | end |
---|
41 | else |
---|
42 | data=data.Data; |
---|
43 | end |
---|
44 | catch |
---|
45 | end |
---|
46 | |
---|
47 | end |
---|
48 | name=GroupHierarchy.Datasets(i).Name; |
---|
49 | name=strrep(name,'/','.'); |
---|
50 | eval(['datastruct' name '= data ;']) |
---|
51 | end |
---|
52 | for i=[1:size(GroupHierarchy.Attributes,2)] |
---|
53 | data=hdf5read(GroupHierarchy.Attributes(i)); |
---|
54 | switch class(data) |
---|
55 | case 'hdf5.h5string' |
---|
56 | try |
---|
57 | if size(data,2)>1 |
---|
58 | buffer=data ; |
---|
59 | data = {} ; |
---|
60 | for j=1:size(buffer,2) |
---|
61 | data{j}=buffer(j).Data; |
---|
62 | end |
---|
63 | else |
---|
64 | data=data.Data; |
---|
65 | end |
---|
66 | catch |
---|
67 | end |
---|
68 | case 'hdf5.h5array' |
---|
69 | try |
---|
70 | if size(data,2)>1 |
---|
71 | buffer=data ; |
---|
72 | data = {} ; |
---|
73 | for j=1:size(buffer,2) |
---|
74 | data{j}=buffer(j).Data; |
---|
75 | end |
---|
76 | else |
---|
77 | data=data.Data; |
---|
78 | end |
---|
79 | catch |
---|
80 | end |
---|
81 | end |
---|
82 | name=GroupHierarchy.Attributes(i).Name; |
---|
83 | name=strrep(name,'/','.'); |
---|
84 | eval(['datastruct' name '= data ;']) |
---|
85 | end |
---|
86 | |
---|
87 | % Then load the branches: |
---|
88 | % Create structures for the group and pass them on recursively: |
---|
89 | for i=[1:size(GroupHierarchy.Groups,2)] |
---|
90 | name=GroupHierarchy.Groups(i).Name; |
---|
91 | name=strrep(name,'/','.'); |
---|
92 | eval(['datastruct' name '= struct ;']); |
---|
93 | datastruct = hdf5load_recursion(datastruct,GroupHierarchy.Groups(i)); |
---|
94 | end |
---|
95 | |
---|