function [meshelenew,meshnodnew,bathynew,bndelenew]=...
        cleanup(meshele,meshnod,bathy,bndele)
%[meshelenew,meshnodnew,bathynew,bndelenew]= ...
%       cleanup(meshele,meshnod,bathy,bndele);
% eliminate nodes not used in elements and renumbers
% everything accordingly

disp(' cleanup ')
egg = meshele(:,2:4);
l = []; l(:)=egg; l=union(l,[]);

x = zeros(length(meshnod),1);

x(l)=1:length(l);

meshelenew = meshele;
meshelenew(:,2) = x(meshele(:,2));
meshelenew(:,3) = x(meshele(:,3));
meshelenew(:,4) = x(meshele(:,4));
meshelenew(:,1) = [1:length(meshelenew)]';

meshnodnew = meshnod(l,:);
meshnodnew(:,1) = [1:length(l)]';

if nargin>2
bathynew= bathy(l,:);
bathynew(:,1) = [1:length(bathynew)]';
end
if nargin==4
bndelenew = bndele;
end



disp(' cleanup calling rghthand ')
meshelenew = rghthand(meshelenew,meshnodnew);
