function [ni,x]=corr(ni,x,res,errnorm,tol)
disp('corr')
h=x(2:ni+1)-x(1:ni);
%
%computing new mesh size
%
if errnorm=='en';
hnew=tol*ones(size(h))./(res+eps*ones(size(res)))/sqrt(ni);
%
elseif errnorm=='l2'
hnew=sqrt(tol*ones(size(h))./(res+eps*ones(size(res)))/sqrt(ni));
%
elseif errnorm=='ma'
hnew=sqrt(tol*ones(size(h))./(res+eps*ones(size(res))));
end
%
%computing new mesh points
%
front=x(1);
xnew(1)=front;
interval=1;
%
while front<x(ni+1)-eps;
%
   if front+hnew(interval)<=x(interval+1);
     front=front+hnew(interval);
     xnew=[xnew,front];
   else
     hmin=hnew(interval);
     while x(interval+1)-front<min(hmin,hnew(interval));
       if interval==ni;
         front=x(interval+1);
         x=[xnew,front];
         ni=length(x)-1;
         return
       else
         interval=interval+1;
         hmin=min(hmin,hnew(interval));
       end
     end      %of inner while
     front=front+hmin;
     xnew=[xnew,front];
   end      %of if
%
end       %of outer while
%
%sons=max(ones(size(h)),ceil(h./hnew));
%hnew=h./sons;
%xnew=[x(1):hnew(1):x(2)];
%for j=2:ni;
%add=[x(j)+hnew(j):hnew(j):x(j+1)];
%xnew=[xnew,add];
%end
x=xnew
ni=length(x)-1;


