function[NM1RawFileMat]=TestRawFiles(RawFileMat,MaxMemory,PrintStatus,PrintSubStatus);

%   TestRawFiles.m

%   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 nargin<4; PrintSubStatus = 1;end
if nargin<3; PrintStatus = 1;end
if nargin<2; MaxMemory=20; end;
if nargin<1; NRawFileMat=[]; end;

if PrintStatus
    fprintf(1,'Checking for additional reference channels to remove...\n');
end
pause(1);

DefDataFilePath=SetDefPath('r','.RAW',[],0);
[NNetFiles,RawFileMat,NonUse,BatchFilePath]=ReadFileNames(RawFileMat,DefDataFilePath,'Choose a NetStation RAW file:',[],[],0);
SetDefPath('w',BatchFilePath,[],0);
NM1RawFileMat=[];
for FileInd=1:NNetFiles
    [NoUse,NoUse,NetFilePath]=GetFileNameOfMat(RawFileMat,FileInd);
    [NoUse,NoUse,NoUse,NoUse,NoUse,NoUse,NoUse,NoUse,NoUse,NoUse,NoUse, ...
    SampRateTmp,NChan]=ReadNetHeader(NetFilePath,0,[],PrintSubStatus);
    if any(NChan-[65,129,257]==0)
        NRaw2NM1RawStatus(FileInd)=1;
    else
        NRaw2NM1RawStatus(FileInd)=0;
    end
end
if any(NRaw2NM1RawStatus)
    NRaw2NM1RawIndVec=find(NRaw2NM1RawStatus);
    NRaw2NM1RawFileMat=RawFileMat(NRaw2NM1RawIndVec,:);
    [NRaw2NM1RawFiles,NonUse]=size(NRaw2NM1RawFileMat);
	fprintf(1,'\n'); 
    Message=char(' ');
	if NRaw2NM1RawFiles==1
		Message=char(Message,['Extract last sensor of the following RAW file:']);
		fprintf(1,'Extract last sensor of the following RAW file:\n\n');
	else
		Message=char(Message,['Extract last sensor of the following ',int2str(NRaw2NM1RawFiles),' RAW files:']);
		fprintf(1,'Extract last sensor of the following %g RAW files:\n\n',NRaw2NM1RawFiles);
	end
	Message=char(Message,' ');
	Message=char(Message,NRaw2NM1RawFileMat);
	Message=char(Message,'');
	Message=char(Message,'');
	hmsgbox=msgbox(Message,'Info','help'); 
    [NRaw2NM1RawFileMat]=NRaw2NM1Raw(NRaw2NM1RawFileMat,MaxMemory);
end   
return;