Home > vbmeg > external > mne > fiff_make_dir_tree.m

fiff_make_dir_tree

PURPOSE ^

SYNOPSIS ^

function [tree, last] = fiff_make_dir_tree(fid,dir,start,indent)

DESCRIPTION ^

 [tree, last] = fiff_make_dir_tree(fid,dir,start,indent)

 Create the directory tree structure

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [tree, last] = fiff_make_dir_tree(fid,dir,start,indent)
0002 %
0003 % [tree, last] = fiff_make_dir_tree(fid,dir,start,indent)
0004 %
0005 % Create the directory tree structure
0006 %
0007 
0008 %
0009 %   Author : Matti Hamalainen, MGH Martinos Center
0010 %   License : BSD 3-clause
0011 %
0012 %   Revision 1.6  2009/04/01 21:25:50  msh
0013 %   Fixed problems with fiff nodes with no tags in them
0014 %
0015 %   Revision 1.5  2006/04/26 19:50:58  msh
0016 %   Added fiff_read_mri
0017 %
0018 %   Revision 1.4  2006/04/23 15:29:40  msh
0019 %   Added MGH to the copyright
0020 %
0021 %   Revision 1.3  2006/04/18 20:44:46  msh
0022 %   Added reading of forward solution.
0023 %   Use length instead of size when appropriate
0024 %
0025 %   Revision 1.2  2006/04/12 10:29:02  msh
0026 %   Made evoked data writing compatible with the structures returned in reading.
0027 %
0028 %   Revision 1.1  2006/04/10 23:26:54  msh
0029 %   Added fiff reading routines
0030 %
0031 
0032 %
0033 %  Define the relevant constants here
0034 %  no need to get the whole fiff_define_costants
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         %  Add the id information if available
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 % Eliminate the empty directory
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     % fprintf(1,'block = %d nent = %d nchild = %d\n',tree.block,tree.nent,tree.nchild);
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

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005