function[NChan,SpherRadius,EPosSpher,ENames,EConfigFile,EConfigPath,EConfigFilePath]=ReadEConfig(EConfigFilePath,PrintStatus)


%	ReadEConfig.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<2;PrintStatus = 0;end
if nargin<1; EConfigFilePath=[]; end;

[EConfigFile,EConfigPath,EConfigFilePath]=ReadFilePath(EConfigFilePath,'*.ecfg','Choose a SCADS .ecfg file:');
if EConfigFile==0; return; end;
fid=fopen(EConfigFilePath,'r','b');
if fid < 3
	fprintf('Cant find the file:\n') 
	fprintf(EConfigFilePath);
	fprintf('\n');
	[ch_TakeOrCancel]=IfEmptyInputSpecVal([],[1 2],1,...
					  	['Do you want to choose a different file         [1]'],...
						['or do you want to cancel ?                     [2]']);
	if ch_TakeOrCancel==1
		[EConfigFile,EConfigPath,EConfigFilePath]=ReadFilePath([]);
	end
	if isempty(EConfigFilePath) | ch_TakeOrCancel==2
		EPosSpher=[]; EPosCart=[]; return; 
	else
		fid=fopen(EConfigFilePath,'r','b');
	end
end
if	fid > 2
    if PrintStatus
	    fprintf('Start reading electrode configuration from file:\n');
	    disp(EConfigFilePath);
	    fprintf('\n');
    end
	[NChan,count] = fread(fid,1,'int16');
	[SpherRadius,count] = fread(fid,1,'float32');
	[EPosSpher,count]= fread(fid,[NChan,2],'float32');
	[ENames,count]= fread(fid,[NChan,6],'uchar');
	ENames=setstr(ENames);
	if PrintStatus
        fprintf('End reading electrode configuration.\n');
    end
	fclose(fid);
end
return;
