function [hutterflag macayealflag pattynflag stokesflag filltype]=recover_areas(md,varargin);
%RECOVER_AREAS - flag the element depending on the physical model that is assigned to them
%
%   This routine is called by setelementstype, do not use
%
%   Usage:
%      [hutterflag macayealflag pattynflag stokesflag filltype]=recover_areas(md,varargin);

	%initialize elementstype
	hutterflag=zeros(md.numberofelements,1);
	macayealflag=zeros(md.numberofelements,1);
	pattynflag=zeros(md.numberofelements,1);
	stokesflag=zeros(md.numberofelements,1);
	filltype='none';

	%make sure length(varargin) is even
	varargin=varargin{1};
	if mod(length(varargin),2),
		error('recover_elementstype_options error message: an even number of options is necessary');
	end

	%go through varargin, extract options and plug them into subtype options, by order of appearance
	for i=1:length(varargin)/2,

		optionstring=varargin{2*i-1};
		optionvalue=varargin{2*i};

		if strcmpi(optionstring,'hutter'),
			hutterflag=BuildFlag(md,optionvalue);
		elseif strcmpi(optionstring,'macayeal'),
			macayealflag=BuildFlag(md,optionvalue);
		elseif strcmpi(optionstring,'pattyn'),
			pattynflag=BuildFlag(md,optionvalue);
		elseif strcmpi(optionstring,'stokes'),
			stokesflag=BuildFlag(md,optionvalue);
		elseif strcmpi(optionstring,'fill'),
			filltype=optionvalue;
		else
			error('elementstype_options error message: bad elementstype options');
		end
	end
end %end function


function flag=BuildFlag(md,area),
	if ischar(area),
		if isempty(area),
			flag=zeros(md.numberofelements,1);
			invert=0;
		elseif strcmpi(area,'all')
			flag=ones(md.numberofelements,1);
			invert=0;
		else
			%make sure that we actually don't want the elements outside the domain outline!
			if strcmpi(area(1),'~'),
				area=area(2:length(area));
				invert=1;
			else
				invert=0;
			end
			%ok, flag elements
			flag=ArgusContourToMesh(md.elements(:,1:3),md.x,md.y,expread(area,1),'element',1);
		end
		if invert,
			flag=~flag;
		end
	elseif isfloat(area),
		if size(area,1)~=md.numberofelements,
			setelementstypeusage();
			error('Flags for elements_type must be of same size as number of elements in model');
		end
		flag=area;
	else
		error('Invalide elements_type option');
	end
end
