function findnode(node,range,varargin)
% FINDNODE highlights some nodes.
%
%    findnode(node,range) finds all nodes whose indices are in the range
%    array. It plots these nodes using larger black dots and display the indices.
%
%    findnode(node) finds all nodes.
%   
%    findnode(...,'noindex') skip the display of indices.
%
%    findnode(node,range,'param','value','param','value'...) allows
%    additional patch param/value pairs to highlight the nodes.
%    
% Example
%     node = [1,0; 1,1; 0,1; -1,1; -1,0; -1,-1; 0,-1; 0,0];
%     elem = [1,2,8; 3,8,2; 8,3,5; 4,5,3; 7,8,6; 5,6,8];
%     subplot(1,2,1);
%     showmesh(node,elem);
%     findnode(node,[1 3],'noindex','color','r','MarkerSize',24)
%     subplot(1,2,2);
%     showmesh(node,elem);
%     findnode(node);
%
%   See also findelem, findnode3, findedge.

% Copyright (C) Long Chen. See COPYRIGHT.txt for details. 

hold on
if (nargin==1)
    range = (1:size(node,1))'; 
end
if islogical(range) 
    range = find(range); 
end
if size(range,2)>size(range,1)
    range = range'; 
end

h = plot(node(range,1),node(range,2),'k.', 'MarkerSize', 18);
if nargin>2
    if strcmp(varargin{1},'noindex') || strcmp(varargin{1},'index')
        startidx = 2;
    else
        startidx = 1;
    end
    set(h,varargin{startidx:end});
end
if (nargin <3) || ~(strcmp(varargin{1},'noindex'))
   text(node(range,1)+0.05,node(range,2)+0.05,int2str(range), ...
     'FontSize',14,'FontWeight','bold');
end