function type = type_norm(type,skip)

% type_norm - flexible handling of type through normalization
% -----------------------------------------------------------
%
% type = type_norm(type,skip)
%
% Input:
% ------
%  type - type string
%  skip - skip available types check
%
% Output:
% -------
%  type - normalized type string

%--------------------------------
% Author: Harold Figueroa
%--------------------------------
% $Revision: 1035 $
% $Date: 2005-05-11 15:37:03 -0400 (Wed, 11 May 2005) $
%--------------------------------

% TODO: this function can be generalized by providing types list input

%--
% set default no skip
%--

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

%--
% normalize input string
%--

% NOTE: allow spaces, capitalization, irrelevant whitespace, and simple plural

type = lower(strrep(strtrim(type),' ','_'));

if (type(end) == 's')
	type(end) = [];
end

%--
% possibly check normalized type against available types
%--

if (skip)
	return;
end

% NOTE: this could be an 'is_type' function

if (isempty(find(strcmp(type,get_extension_types))))
	error(['Unrecognized extension type ''', type, '''.']);
end