function fappend(file1,file2)
%Append one file to another
%
%Usage
%
% fappend(file1,file2)
%
% Simple function that appends file2 to file1 byte by byte
% Can be used to append raw data files
% or files split using fsplit
%
% SEE ALSO fsplit, mfappend, uimfappend
%Suresh Joel - April 10,2003
switch(nargin)
case 0
[filename pathname]=uigetfile('*.*','File to append to');
file1=strcat(pathname,filename);
[filename pathname]=uigetfile('*.*','File to be appended');
file2=strcat(pathname,filename);
case 1
[filename pathname]=uigetfile('*.*','File to be appended');
file2=strcat(pathname,filename);
case 2
file1=char(file1);
file2=char(file2);
end
if(~exist(file1))
status=-1;
error(strcat('Cant find source file -',file1));
end
if(~exist(file2))
status=-1;
error(strcat('Cant find source file -', file2));
end;
blk_size=1024*1024; % 1 MB per copy
fid1=fopen(file1,'a');
fid2=fopen(file2,'r');
fseek(fid1,'0','eof');
c=fread(fid2,blk_size,'uchar');
while(~isempty(c)),
fwrite(fid1,c,'uchar');
c=fread(fid2,blk_size,'uchar');
end;
fclose(fid1);
fclose(fid2);
disp('File appended successfully');