function user = set_active_user(user)

% set_active_user - set active user
% ---------------------------------
% 
% user = set_active_user(user)
%
% Input:
% ------
%  user - user to make active
%
% Output:
% -------
%  user - active user

%--------------------------------
% Author: Harold Figueroa
%--------------------------------
% $Revision: 132 $
% $Date: 2004-12-02 15:58:47 -0500 (Thu, 02 Dec 2004) $
%--------------------------------

%-------------------------------
% HANDLE INPUT
%-------------------------------

%--
% output active user when given no input
%--

if (nargin < 1)
	user = get_active_user; return;
end

%--
% check input and get user from input
%--

switch class(user)

	case 'char', user = get_users('name', user);
	
	case 'struct'

		if ~isfield(user, 'name')
			user = [];
		else
			try
				user = get_users('name', user.name);
			catch
				warning('Setting unverified active user.');
			end
		end

	otherwise, user = []; % NOTE: no proper way to set using input

end

%--
% return active user if no proper way to update
%--

if isempty(user)
	user = get_active_user; return;
end

% TODO: consider warning when we don't find the requested user

%-------------------------------
% SET ACTIVE USER
%-------------------------------

set_env('xbat_user', user);