function [l]=findtri(meshele,meshnod,xin,yin)
% [l]=findtri(meshele,meshnod,x,y);
%find the triangle element which contains x,y
%


meshele(:,1) = [1:length(meshele(:,1))]';

d = (meshnod(:,2)-xin).^2+(meshnod(:,3)-yin).^2;
[d,lnod]=sort(d);
nod1 = lnod(1:10);


ele3 = -1;
for i = 1:10
 l1 =[find(meshele(:,2)==nod1(i))',...
 find( meshele(:,3)==nod1(i) )' ,find(meshele(:,4)==nod1(i) )' ];
 for el = 1:length(l1)

   if interior(xin,yin,...
   meshnod(meshele(l1(el),2:4),2) , meshnod(meshele(l1(el),2:4),3) )
      ele3 = l1(el);
      break     % fall out of loop of triangles sharing one of 10 nodes
   end
 end
 if ele3>0 
   break        % fall out of loop of  10 closest nodes
 end

end

hold on

if ele3==-1
disp(['Not inside any element, Sorry '])
l = [];
else
l = ele3
end
