0001 function [tree, last] = fiff_make_dir_tree(fid,dir,start,indent)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 FIFF_BLOCK_START = 104;
0037 FIFF_BLOCK_END = 105;
0038 FIFF_FILE_ID = 100;
0039 FIFF_BLOCK_ID = 103;
0040 FIFF_PARENT_BLOCK_ID = 110;
0041
0042 me='MNE:fiff_make_dir_tree';
0043
0044 verbose=0;
0045
0046 if nargin == 2
0047 indent = 0;
0048 start = 1;
0049 elseif nargin == 3
0050 indent = 0;
0051 elseif nargin ~= 4
0052 error(me,'Incorrect number of arguments');
0053 end
0054
0055 if dir(start).kind == FIFF_BLOCK_START
0056 tag = fiff_read_tag(fid,dir(start).pos);
0057 block = tag.data;
0058 else
0059 block = 0;
0060 end
0061
0062 if verbose ~= 0
0063 for k = 1:indent
0064 fprintf(1,'\t');
0065 end
0066 fprintf(1,'start { %d\n',block);
0067 end
0068
0069 nchild = 0;
0070 this = start;
0071
0072 tree.block = block;
0073 tree.id = [];
0074 tree.parent_id = [];
0075 tree.nent = 0;
0076 tree.nchild = 0;
0077 tree.dir = dir(this);
0078 tree.children = struct('block', {}, 'id', {}, 'parent_id', {}, 'nent', {}, 'nchild', {}, 'dir', {}, 'children', {});
0079 while this <= length(dir)
0080 if dir(this).kind == FIFF_BLOCK_START
0081 if this ~= start
0082 [ child , this ] = fiff_make_dir_tree(fid,dir,this,indent+1);
0083 tree.nchild = tree.nchild + 1;
0084 tree.children(tree.nchild) = child;
0085
0086 end
0087 elseif dir(this).kind == FIFF_BLOCK_END
0088 tag = fiff_read_tag(fid,dir(start).pos);
0089 if tag.data == block
0090 break;
0091 end
0092 else
0093 tree.nent = tree.nent + 1;
0094 tree.dir(tree.nent) = dir(this);
0095
0096
0097
0098 if block == 0
0099 if dir(this).kind == FIFF_FILE_ID
0100 tag = fiff_read_tag(fid,dir(this).pos);
0101 tree.id = tag.data;
0102 end
0103 else
0104 if dir(this).kind == FIFF_BLOCK_ID
0105 tag = fiff_read_tag(fid,dir(this).pos);
0106 tree.id = tag.data;
0107 elseif dir(this).kind == FIFF_PARENT_BLOCK_ID
0108 tag = fiff_read_tag(fid,dir(this).pos);
0109 tree.parent_id = tag.data;
0110 end
0111 end
0112 end
0113 this = this + 1;
0114 end
0115
0116
0117
0118 if tree.nent == 0
0119 tree.dir = [];
0120 end
0121 if verbose ~= 0
0122 for k = 1:indent+1
0123 fprintf(1,'\t');
0124 end
0125
0126 fprintf(1,'block=%d\n',tree.block);
0127 for k = 1:indent
0128 fprintf(1,'\t');
0129 end
0130 fprintf(1,'end } %d\n',block);
0131 end
0132
0133 last = this;
0134
0135 return;
0136