function [meshelenew,meshnodnew,bathynew,meshcdnew,bndelenew]=...
        reelems(meshele,meshnod,bathy,meshcd,bndele)
%[meshelenew,meshnodnew,bathynew,meshcdnew,bndelenew]= ...
%       reelems(meshele,meshnod,bathy,meshcd,bndele);
% eliminate nodes not used in elements and renumbers
% everything accordingly
%  Just like meshcleanup, but with meshcd included.
%     Sept. 1995


disp(' reelems with meshcd')
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)]';

bathynew= bathy(l,:);
bathynew(:,1) = [1:length(bathynew)]';

meshcdnew= meshcd(l,:);
meshcdnew(:,1) = [1:length(meshcdnew)]';

bndelenew = bndele;


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