[947] | 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 | |
---|
[1013] | 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 | end |
---|
| 47 | name=GroupHierarchy.Datasets(i).Name; |
---|
| 48 | name=strrep(name,'/','.'); |
---|
| 49 | eval(['datastruct' name '= data ;']) |
---|
[947] | 50 | end |
---|
[1013] | 51 | for i=[1:size(GroupHierarchy.Attributes,2)] |
---|
| 52 | data=hdf5read(GroupHierarchy.Attributes(i)); |
---|
| 53 | switch class(data) |
---|
| 54 | case 'hdf5.h5string' |
---|
| 55 | try |
---|
| 56 | if size(data,2)>1 |
---|
| 57 | buffer=data; |
---|
| 58 | data = {}; |
---|
| 59 | for j=1:size(buffer,2) |
---|
| 60 | data{j}=buffer(j).Data; |
---|
| 61 | end |
---|
| 62 | else |
---|
| 63 | data=data.Data; |
---|
| 64 | end |
---|
| 65 | catch |
---|
| 66 | end |
---|
| 67 | case 'hdf5.h5array' |
---|
| 68 | try |
---|
| 69 | if size(data,2)>1 |
---|
| 70 | buffer=data; |
---|
| 71 | data = {}; |
---|
| 72 | for j=1:size(buffer,2) |
---|
| 73 | data{j}=buffer(j).Data; |
---|
| 74 | end |
---|
| 75 | else |
---|
| 76 | data=data.Data; |
---|
| 77 | end |
---|
| 78 | catch |
---|
| 79 | end |
---|
[947] | 80 | end |
---|
[1013] | 81 | name=GroupHierarchy.Attributes(i).Name; |
---|
| 82 | name=strrep(name,'/','.'); |
---|
| 83 | eval(['datastruct' name '= data ;']) |
---|
[947] | 84 | end |
---|
| 85 | |
---|
[1013] | 86 | % Then load the branches: |
---|
| 87 | % Create structures for the group and pass them on recursively: |
---|
| 88 | for i=[1:size(GroupHierarchy.Groups,2)] |
---|
| 89 | name=GroupHierarchy.Groups(i).Name; |
---|
| 90 | name=strrep(name,'/','.'); |
---|
| 91 | eval(['datastruct' name '= struct ;']); |
---|
| 92 | datastruct = hdf5load_recursion(datastruct,GroupHierarchy.Groups(i)); |
---|
| 93 | end |
---|
[947] | 94 | end |
---|