source: trunk/src/hdf5load_recursion.m @ 1073

Last change on this file since 1073 was 1013, checked in by g7moreau, 6 years ago
  • Remove property svn:executable
File size: 3.0 KB
Line 
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
14function 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        end
47        name=GroupHierarchy.Datasets(i).Name;
48        name=strrep(name,'/','.');
49        eval(['datastruct' name '= data ;'])
50    end
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
80        end
81        name=GroupHierarchy.Attributes(i).Name;
82        name=strrep(name,'/','.');
83        eval(['datastruct' name '= data ;'])
84    end
85
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
94end
Note: See TracBrowser for help on using the repository browser.