0001 function fiff_copy_tree(fidin, in_id, nodes, fidout)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
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
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
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