function [meshelenew]=rmvtri(L,meshele,meshnod)
% [meshelenew]=rmvtri(L,meshele,meshnod);
%  New version July 1995
% Remove selected elements from the grid
% L = min and max for x,y axis
disp(['Click on triangles to be removed '])
disp(['Pushbutton quit method of meshtools/rmvtri'])
clf
axis(L)
axis('equal')


sou = ones(100,1);  
l = 1:2:99;
sou(l) = 0*sou(l);

x = meshnod(:,2);
y = meshnod(:,3);
meshele(:,1) = [1:length(meshele(:,1))]';


ploteles(meshele,meshnod,.9);

axis(L)
axis('equal')
title('Remove triangles')
figure(gcf)

lrmv = [];

pbquit = uicontrol(gcf,'Style','radio','String','QUIT','Value',0 ...
 ,'units','normalized','position',[.02 .45 .107 .047] );

%     ...   ,'interruptible','no','callback','break');

sound(sou)

while (1)
%waitforbuttonpress;
%[pt] = get(gca,'currentpoint');
%xin = pt(1,1); yin = pt(1,2);
[xin,yin]=ginput(1);
drawnow

if get(pbquit,'value')
  disp('  QUIT movenod')
  break
end


d = (x-xin).^2+(y-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
fill(x(meshele(ele3,2:4)),y(meshele(ele3,2:4)),'g')
drawnow
else
disp(['Could not kill that one. Sorry '])
end

%disp([ l1(l2(l3)), ele , meshele(l1(l2(l3)),:)])
l = find(meshele(:,1)~=ele3 );
meshele=meshele(l,:);
meshele(:,1) = [1:length(l)]';
%
end    %   End While


hold off
meshelenew = meshele;
delete(pbquit)
disp('End of rmvtri')

