1+ function nwbTree(nwbfile )
2+
3+ f = uifigure(' Name' , ' NWB Tree' );
4+ tree = uitree(f ,' Position' ,[20 , 20 f .Position(3 ) - 20 , f .Position(4 ) - 20 ]);
5+ traverse_node(nwbfile , tree )
6+
7+ end
8+
9+
10+ function out = traverse_node(node , tree_node )
11+
12+ if any(strcmp(superclasses(node ), ' types.untyped.GroupClass' )) || isa(node , ' types.untyped.DataStub' )
13+ pp = properties(node );
14+ for p = pp '
15+ if ~isempty(node.(p{1 }))
16+ new_node = node.(p{1 });
17+ if any(strcmp(superclasses(new_node ), ' types.untyped.GroupClass' ))
18+ new_tree_node = uitreenode(tree_node , ' Text' , p{1 });
19+ traverse_node(new_node , new_tree_node )
20+ elseif isa(new_node , ' types.untyped.Set' )
21+ if new_node .Count
22+ new_tree_node = uitreenode(tree_node , ' Text' , p{1 });
23+ traverse_node(new_node , new_tree_node )
24+ end
25+ elseif isa(new_node , ' types.untyped.DataStub' )
26+ new_tree_node = uitreenode(tree_node , ' Text' , p{1 });
27+ traverse_node(new_node , new_tree_node )
28+ elseif isa(new_node , ' char' )
29+ uitreenode(tree_node , ' Text' , [p{1 } ' : ' new_node ]);
30+ elseif isnumeric(new_node )
31+ if numel(new_node ) == 1
32+ uitreenode(tree_node , ' Text' , [p{1 } ' : ' num2str(new_node )]);
33+ else
34+ data_node = uitreenode(tree_node , ' Text' , p{1 });
35+ uitreenode(data_node , ' Text' , [' shape: [' num2str(size(new_node )) ' ]' ])
36+ uitreenode(data_node , ' Text' , [' class: ' class(new_node )])
37+ end
38+ else
39+ uitreenode(tree_node , ' Text' , p{1 });
40+ end
41+ end
42+ end
43+ elseif isa(node , ' types.untyped.Set' )
44+ for key = node .keys()
45+ new_tree_node = uitreenode(tree_node , ' Text' , key{1 });
46+ traverse_node(node .get(key{1 }), new_tree_node )
47+ end
48+ end
49+
50+
51+ function [ bytes ] = getMemSize( variable , sizelimit , name , indent )
52+ if nargin < 2
53+ sizelimit = - 1 ;
54+ end
55+ if nargin < 3
56+ name = ' variable' ;
57+ end
58+ if nargin < 4
59+ indent = ' ' ;
60+ end
61+
62+ strsize = 30 ;
63+
64+ props = properties(variable );
65+ if size(props , 1 ) < 1
66+
67+ bytes = whos(varname(variable ));
68+ bytes = bytes .bytes ;
69+
70+ if bytes > sizelimit
71+ if bytes < 1024
72+ fprintf(' %s%s : %i\n ' , indent , pad(name , strsize - length(indent )), bytes );
73+ elseif bytes < 2 ^ 20
74+ fprintf(' %s%s : %i Kb\n ' , indent , pad(name , strsize - length(indent )), round(bytes / 2 ^ 10 ));
75+ elseif bytes < 2 ^ 30
76+ fprintf(' %s%s : %i Mb\n ' , indent , pad(name , strsize - length(indent )), round(bytes / 2 ^ 20 ));
77+ else
78+ fprintf(' %s%s : %i Gb [!]\n ' , indent , pad(name , strsize - length(indent )), round(bytes / 2 ^ 30 ));
79+ end
80+ end
81+ else
82+
83+ fprintf(' \n%s [%s ] \n\n ' , indent , name );
84+ bytes = 0 ;
85+ for ii= 1 : length(props )
86+ currentProperty = getfield(variable , char(props(ii )));
87+ pp = props(ii );
88+ bytes = bytes + getMemSize(currentProperty , sizelimit , pp{1 }, [indent , ' ' ]);
89+ end
90+
91+ if length(indent ) == 0
92+ fprintf(' \n ' );
93+ name = ' TOTAL' ;
94+ if bytes < 1024
95+ fprintf(' %s%s : %i\n ' , indent , pad(name , strsize - length(indent )), bytes );
96+ elseif bytes < 2 ^ 20
97+ fprintf(' %s%s : %i Kb\n ' , indent , pad(name , strsize - length(indent )), round(bytes / 2 ^ 10 ));
98+ elseif bytes < 2 ^ 30
99+ fprintf(' %s%s : %i Mb\n ' , indent , pad(name , strsize - length(indent )), round(bytes / 2 ^ 20 ));
100+ else
101+ fprintf(' %s%s : %i Gb [!]\n ' , indent , pad(name , strsize - length(indent )), round(bytes / 2 ^ 30 ));
102+ end
103+ end
104+
105+ end
106+
107+ end
108+
109+
110+ end
0 commit comments