Home > vbmeg > external > mne > fiff_copy_tree.m

fiff_copy_tree

PURPOSE ^

SYNOPSIS ^

function fiff_copy_tree(fidin, in_id, nodes, fidout)

DESCRIPTION ^

    fiff_copy_tree(fidin, in_id, nodes, fidout)

    Copies directory subtrees from fidin to fidout

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function fiff_copy_tree(fidin, in_id, nodes, fidout)
0002 %
0003 %    fiff_copy_tree(fidin, in_id, nodes, fidout)
0004 %
0005 %    Copies directory subtrees from fidin to fidout
0006 %
0007 
0008 %
0009 %   Author : Matti Hamalainen, MGH Martinos Center
0010 %   License : BSD 3-clause
0011 %
0012 %    Revision 1.2  2009/04/01 21:25:50  msh
0013 %    Fixed problems with fiff nodes with no tags in them
0014 %
0015 %    Revision 1.1  2009/03/30 11:37:37  msh
0016 %    Added copying of measurement info blocks from the original like in mne_browse_raw
0017 %
0018 %
0019 
0020 me = 'MNE:fiff_copy_tree';
0021 
0022 global FIFF;
0023 if isempty(FIFF)
0024     FIFF = fiff_define_constants();
0025 end
0026 
0027 if nargin ~= 4
0028     error(me, 'Incorrect number of arguments');
0029 end
0030 
0031 if length(nodes) <= 0
0032     return
0033 end
0034 
0035 FIFFV_NEXT_SEQ = 0;
0036 
0037 for k = 1:length(nodes)
0038     fiff_start_block(fidout, nodes(k).block);
0039     if ~isempty(nodes(k).id)
0040         if ~isempty(in_id)
0041             fiff_write_id(fidout, FIFF.FIFF_PARENT_FILE_ID, in_id);
0042         end
0043         fiff_write_id(fidout, FIFF.FIFF_BLOCK_ID);
0044         fiff_write_id(fidout, FIFF.FIFF_PARENT_BLOCK_ID, nodes(k).id);
0045     end
0046     for p = 1:nodes(k).nent
0047         %
0048         %   Do not copy these tags
0049         %
0050         if nodes(k).dir(p).kind == FIFF.FIFF_BLOCK_ID || nodes(k).dir(p).kind == FIFF.FIFF_PARENT_BLOCK_ID || nodes(k).dir(p).kind == FIFF.FIFF_PARENT_FILE_ID
0051             continue;
0052         end
0053         %
0054         %   Read and write tags, pass data through transparently
0055         %
0056         if fseek(fidin, nodes(k).dir(p).pos, 'bof') == -1
0057             error(me, 'Could not seek to the tag');
0058         end
0059         tag.kind = fread(fidin, 1, 'int32');
0060         tag.type = fread(fidin, 1, 'uint32');
0061         tag.size = fread(fidin, 1, 'int32');
0062         tag.next = fread(fidin, 1, 'int32');
0063         tag.data = fread(fidin, tag.size, 'uchar');
0064         count = fwrite(fidout, tag.kind, 'int32');
0065         if count ~= 1
0066             error(me, 'write failed.');
0067         end
0068         count = fwrite(fidout, tag.type, 'int32');
0069         if count ~= 1
0070             error(me, 'write failed.');
0071         end
0072         count = fwrite(fidout, tag.size, 'int32');
0073         if count ~= 1
0074             error(me, 'write failed');
0075         end
0076         count = fwrite(fidout, int32(FIFFV_NEXT_SEQ), 'int32');
0077         if count ~= 1
0078             error(me, 'write failed');
0079         end
0080         count = fwrite(fidout, tag.data, 'uchar');
0081         if count ~= tag.size
0082             error(me, 'write failed');
0083         end
0084     end
0085     for p = 1:nodes(k).nchild
0086         fiff_copy_tree(fidin, in_id, nodes(k).children(p), fidout);
0087     end
0088     fiff_end_block(fidout, nodes(k).block);
0089 end
0090 
0091 return
0092 
0093

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