function readpairsmanage(filename,filepath,mode)
%   This software is protected by german copyright and international treaties.             
%   Copyright 2004 Markus Junghöfer & Peter Peyk. All Rights Reserved.                     
%                                                                                          
%   THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE        
%   NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO,    
%   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE    
%   OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
%   TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT,       
%   INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE      
%   OR DOCUMENTATION.                                                                      

if mode==0
   modefehler
   return

% directory mode   
elseif mode==11
	cd (filepath);
    filelist=dir(filepath);
    filelistsize=size(filelist);
    paarungen=cell(1);
    vpnummer=[];
	% Schleife für Files
   for filezaehler=3:filelistsize(1)
      [vpnummer(filezaehler-2),paarungen{filezaehler-2}]=readpairs(1,filelist(filezaehler).name,filepath);
   end
   
   %ergebnisfile schreiben
   %-----------------------
   [savefilename,savefilepath]=uiputfile('*.txt','Bitte benennen Sie das Ergebnisfile:');
   if isempty(findstr(savefilename,'.txt'))
       savefilename=[savefilename,'.txt'];
   end
   savefile=[savefilepath,savefilename];
   fid= fopen(savefile,'wt');
   %header
   for z=1:length(vpnummer)
       fprintf(fid,[num2str(vpnummer(z)),'\t']);
   end
   fprintf(fid,'\n');
   %data
   for r=1:15
       for s=1:length(vpnummer)
           fprintf(fid,[paarungen{s}{r},'\t']);
       end
       fprintf(fid,'\n');
   end
   fclose (fid);
   ok
   
% batchfile mode   
elseif mode==12
   filemat=batchfiletomat(filename,filepath);
   filematgroessevec=size(filemat);
   filematgroesse=filematgroessevec(2);
   for l=1:filematgroesse
      [vpnummer(l),paarungen{l}]=readpairs(1,filemat{l});
   end
   [savefilename,savefilepath]=uiputfile('*.txt','Bitte benennen Sie das Ergebnisfile:');
   if isempty(findstr(savefilename,'.txt'))
       savefilename=[savefilename,'.txt'];
   end
   savefile=[savefilepath,savefilename];
   fid= fopen(savefile,'wt');
   %header
   for z=1:length(vpnummer)
       fprintf(fid,[num2str(vpnummer(z)),'\t']);
   end
   fprintf(fid,'\n');
   %data
   for r=1:15
       for s=1:length(vpnummer)
           fprintf(fid,[paarungen{s}{r},'\t']);
       end
       fprintf(fid,'\n');
   end
   fclose(fid);
   ok
      
% single file mode   
elseif mode==2
   [vpnummer,paarungen]=readpairs(1,filename,filepath);
   [savefilename,savefilepath]=uiputfile('*.txt','Bitte benennen Sie das Ergebnisfile:');
   if isempty(findstr(savefilename,'.txt'))
       savefilename=[savefilename,'.txt'];
   end
   savefile=[savefilepath,savefilename];
   fid= fopen(savefile,'wt');
   %header
   for z=1:length(vpnummer)
       fprintf(fid,[num2str(vpnummer)]);
   end
   fprintf(fid,'\n');
   %data
   for r=1:15
       for s=1:length(vpnummer)
           fprintf(fid,[paarungen{r},'\t']);
       end
       fprintf(fid,'\n');
   end
   fclose(fid);
   ok
   
   
end


return