function [MEAS,MEAS_NAME] = get_measurements(h,mode)

% get_measurements - get currently available measures
% -----------------------------------------------
%
% [MEAS,MEAS_NAME] = get_measurements(h)
%                  = get_measurements(h,'update')
%
% Output:
% -------
%  MEAS - measure structure array
%  MEAS_NAME - measure names cell array

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

%--
% set mode
%--

if (nargin < 2)
	mode = '';
end 

%--
% set handle
%--

if (nargin < 1)
	h = [];
end

%--
% create persistent measure structure array and names
%--

persistent PERSISTENT_MEAS PERSISTENT_MEAS_NAME;

%--
% get measure information if needed or 'update' requested
%--

if (isempty(PERSISTENT_MEAS) | ~isempty(h) | strcmp(mode,'update'))
	
	%--
	% get functions in 'measures' directory
	%--
	
	fun = what([extensions_root, filesep, 'Measures']); 
	
	fun = what([fun.path filesep 'Event']);

	fun = unique(file_ext({fun.m{:}, fun.p{:}}));
	
	%--
	% get measure information
	%--
	
	if (length(fun))
		j = 1;
		for k = 1:length(fun)
			if findstr(fun{k},'_measure')
				tmp = feval(file_ext(fun{k}),'create',h);
				if (j == 1)
					PERSISTENT_MEAS = tmp;
				else
					PERSISTENT_MEAS(j) = tmp;
				end
				PERSISTENT_MEAS_NAME{j} = tmp.name;
				j = j + 1;
			end
		end
	end
	
	%--
	% sort measures by names
	%--
	
	[PERSISTENT_MEAS_NAME,ix] = sort(PERSISTENT_MEAS_NAME);
	PERSISTENT_MEAS = PERSISTENT_MEAS(ix);
	
end

%--
% output measure structure array and measure names
%--

MEAS = PERSISTENT_MEAS;
MEAS_NAME = PERSISTENT_MEAS_NAME;
