function meshnodnew = rmwinnod(meshnod,lhighlight)
%   meshnodnew = rmwinnod(meshnod,lhighlight);
% Allows a rubberband box to be used to delete nodes from meshnod
%  lhighlight is optional,  meshnod(lhighlight,2:3) will be plotted as red *
clear global
clf
zoom off
hold off
if nargin==1
plot(meshnod(:,2),meshnod(:,3),'g.')
else
plot(meshnod(:,2),meshnod(:,3),'g.',...
   meshnod(lhighlight,2),meshnod(lhighlight,3),'r*')
end

grid
title('Remove Nodes in box. Click on lower left corner of box and pull')
axis('equal')
[XY]=ginput(1)
rbbox([get(gcf,'currentpoint') 0 0],get(gcf,'currentpoint'))
%rbbox([XY 1.0001*XY]    ,get(gcf,'currentpoint'))

    fig = gcf;
    ax = gca;
    fig_units = get(fig,'units');
    set(fig,'units','normalized');
    axu = get(ax,'units');
    set(ax,'units','normalized')
        norm_rect = get(ax,'Position');
        handle = ax;
        ydir = get(ax,'ydir');
        ax_lim  = axis;
         d_h = ax_lim(4) - ax_lim(3);
        if strcmp(ydir,'reverse'), ax_lim(3) = ax_lim(4); d_h = -d_h; end
        d_w = ax_lim(2) - ax_lim(1);
                scrn_pt = get(0, 'PointerLocation');
                set(fig,'units','pixels')
                loc = get(fig, 'Position');
                set(fig,'units','normalized')
                pt = [scrn_pt(1) - loc(1), scrn_pt(2) - loc(2)];
                ax_rect = [fix(norm_rect(1)*loc(3)),fix(norm_rect(2)*loc(4)),...
                    fix(norm_rect(3)*loc(3)),fix(norm_rect(4)*loc(4))];
                pt(1) = (pt(1) - ax_rect(1))/ax_rect(3);
                pt(2) = (pt(2) - ax_rect(2))/ax_rect(4);

                    pt(1) = ax_lim(1) + pt(1) * d_w;
                    pt(2) = ax_lim(3) + pt(2) * d_h;
    set(fig,'units',fig_units);
    set(ax,'units',axu)
 
XY2=pt;

L = [XY(1) XY2(1) XY(2) XY2(2)];
if L(1)>L(2)
L(1) = XY2(1) ;
L(2) = XY(1);
end
if L(3)>L(4)
L(3) = XY2(2) ;
L(4) = XY(2);
end

lbot = find(meshnod(:,3) < L(3));
ltop = find(meshnod(:,3) > L(4));
lback = find(meshnod(:,2) < L(1));
lfront = find(meshnod(:,2) > L(2));
l = union( union(lbot,ltop),union(lback,lfront));
meshnodnew= meshnod(l,:);


