File: readMeta.m

package info (click to toggle)
python-pyqtgraph 0.13.7-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 8,068 kB
  • sloc: python: 54,043; makefile: 129; ansic: 40; sh: 2
file content (83 lines) | stat: -rw-r--r-- 1,663 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function f = readMeta(file)
info = hdf5info(file);
f = readMetaRecursive(info.GroupHierarchy.Groups(1));
end


function f = readMetaRecursive(root)
typ = 0;
for i = 1:length(root.Attributes)
    if strcmp(root.Attributes(i).Shortname, '_metaType_')
        typ = root.Attributes(i).Value.Data;
        break
    end
end
if typ == 0
    printf('group has no _metaType_')
    typ = 'dict';
end

list = 0;
if strcmp(typ, 'list') || strcmp(typ, 'tuple')
    data = {};
    list = 1;
elseif strcmp(typ, 'dict')
    data = struct();
else
    printf('Unrecognized meta type %s', typ);
    data = struct();
end

for i = 1:length(root.Attributes)
    name = root.Attributes(i).Shortname;
    if strcmp(name, '_metaType_')
        continue
    end
    val = root.Attributes(i).Value;
    if isa(val, 'hdf5.h5string')
        val = val.Data;
    end
    if list
        ind = str2num(name)+1;
        data{ind} = val;
    else
        data.(name) = val;
    end
end

for i = 1:length(root.Datasets)
    fullName = root.Datasets(i).Name;
    name = stripName(fullName);
    file = root.Datasets(i).Filename;
    data2 = hdf5read(file, fullName);
    if list
        ind = str2num(name)+1;
        data{ind} = data2;
    else
        data.(name) = data2;
    end
end

for i = 1:length(root.Groups)
    name = stripName(root.Groups(i).Name);
    data2 = readMetaRecursive(root.Groups(i));
    if list
        ind = str2num(name)+1;
        data{ind} = data2;
    else
        data.(name) = data2;
    end
end
f = data;
return;
end


function f = stripName(str)
inds = strfind(str, '/');
if isempty(inds)
    f = str;
else
    f = str(inds(length(inds))+1:length(str));
end
end