function value = get_env(name,flag)

% get_env - get value of environment variable
% -------------------------------------------
%
% value = get_env(name,flag)
%
% Input:
% ------
%  name - variable name
%  flag - display flag (def: 0)
%
% Output:
% -------
%  value - variable value

%--------------------------------
% Author: Harold Figueroa
%--------------------------------
% $Revision: 498 $
% $Date: 2005-02-03 19:53:25 -0500 (Thu, 03 Feb 2005) $
%--------------------------------

% TODO: update the environment variable framework to use application data

%--
% set display flag
%--

if ((nargin < 2) | isempty(flag))
	flag = 0;
end

%--
% get root userdata
%--

data = get(0,'userdata');

%--
% check for existing environment variable
%--

if (isfield(data,'env'))
	
	%--
	% display named variable or existing environment variables
	%--
	
	if (nargin & ~isempty(name))
		
		%--
		% check for named variable
		%--
		
		if (isfield(data.env,name))
			
			%--
			% output value of environment variable
			%--
			
			value = getfield(data.env,name);
			
		else
			
			%--
			% output empty value
			%--
			
			value = [];
			
			%--
			% report non-existent named variable
			%--
			
			if (flag)
				disp(' ');
				warning(['Environment variable ''' name ''' is not currently defined.']);
				disp(' ');
			end
			
		end
		
	else
		
		%--
		% output full contents of environment variable structure
		%--
		
		value = data.env;
		
	end

else
	
	%--
	% output empty value
	%--
	
	value = [];
	
	%--
	% report non-existent environment variable structure
	%--
	
	disp(' ');
	warning('There is no environment variable structure available.');
	
end 