function root = xbat_root

% xbat_root - get XBAT root directory
% -----------------------------------
%
% root = xbat_root
%
% Output:
% -------
%  root - XBAT root directory

%--------------------------------
% Author: Harold Figueroa
%--------------------------------
% $Revision: 1631 $
% $Date: 2005-08-23 12:41:39 -0400 (Tue, 23 Aug 2005) $
%--------------------------------

%--
% try to get environment variable
%--

root = get_env('xbat_root');

%--
% set environment variable if needed
%--

if (isempty(root))

	%--
	% get root by parsing path for this file
	%--
	
	% NOTE: the logical root may change as directory organization changes
	
	root = mfilename('fullpath'); 
	
	ix = findstr(root,filesep); 
	
	root = root(1:ix(end - 1) - 1);

	%--
	% set environment variable
	%--
	
	set_env('xbat_root',root);
	
end