function [n,f]=mphselectcoords(model,geomname,coord,entity,varargin)
% MPHSELECTCOORDS Select geometric entity using point coordinates
% 
%   N = MPHSELECTCOORDS(MODEL,GEOMNAME,COORD,ENTITY,...) finds geometry 
%   entity numbers based on their vertex coordinates.
% 
%   One or more coordinate may be provided. The function searches for
%   vertices near these coordinates using a tolerance radius.
%   The list of the entities that are adjacent to such vertices is returned.
% 
%   COORD is a NxM array where N correspond of the number of point to use
%   and M the space dimension of the geometry.
%   ENTITY can be one of 'point', 'edge', 'boundary' or 'domain'.  See the
%   entry MPHSELECTCOORDS in the LiveLink for MATLAB User's Guide for more
%   information about the entity type definition.
% 
%   The following options are available:
%   Property    Value/{Default}      Description
%   -----------------------------------------------------------------------
%   Adjnumber   Scalar | {[]}        Adjacent entity number
%   Radius      Scalar | {'auto'}    Search radius
%   Include     'Any' | {'all'}      Include all vertices or any vertex
% 
%   When a model uses "form an assembly" more than one vertex may have the
%   same coordinate if the coordinate is shared be separate geometric
%   objects. In that case one can use the adjnumber property in order to
%   identify the domain that the vertices should be adjacent to.
% 
%   The 'radius' property is used to specify the radius of the sphere/
%   circle that the search should be within.
%   A small positive radius (based on the geometry size) is used by default
%   in order to compensate for rounding errors.
% 
%   If the 'include' property is 'all' then all vertices must belong to the
%   entity in order to be considered a match. If the include property is
%   'any' then an entity is considered a match as long as any of the
%   vertices are adjacent to the entity.
% 
%   Example 1:
%     % Load busbar.mph from the Model Library:
%     model = mphload('busbar.mph');
%     % Select the vertex near [0.095,0,0.1]:
%     n = mphselectcoords(model, 'geom1', [0.095,0,0.1], 'point');
%     % Select the edge from [0.095 0 0.1] to [0.095 0 0.01]:
%     n = mphselectcoords(model, 'geom1', [0.095 0 0.1;0.095 0 0.01]',...
%       'edge');
%     % Select edges that are adjacent to the points [0.095 0 0.1] and
%     % [0.095 0 0.01]:
%     n = mphselectcoords(model, 'geom1', [0.095 0 0.1;0.095 0 0.01]', ...
%       'edge','include', 'any');
%     % Select boundaries that are adjacent to the points [0.09 0 0.1] and
%     % [0.09 0 0.015] with a search radius of 0.01:
%     n = mphselectcoords(model, 'geom1', [0.09 0 0.1;0.09 0 0]',...
%       'boundary','radius',0.01);
% 
%   Example 2:
%     % Load thin_layer_diffusion.mph from the Model Library:
%     model = mphload('thin_layer_diffusion.mph');
%     % Use imprints and finalize the geometry:
%     model.geom('geom1').feature('fin').set('imprint','on');
%     model.geom('geom1').runAll;
%     % Select edges that are adjacent to point [1.1e-5 4e-6 0]:
%     n = mphselectcoords(model,'geom1',[1.1e-5 4e-6 0],'boundary');
%     % Select edges that are adjacent to point [1.1e-5 4e-6 0] and
%     % domain 4:
%     n = mphselectcoords(model,'geom1',[1.1e-5 4e-6 0],'boundary',...
%       'adjnumber',4);
% 
%   See also: mphgetadj, mphgetcoords, mphselectbox

% Copyright 2010-2011 COMSOL
