function [ME,CE,CONV] = wan_shr_adap(A,EXTTRESH)

samples = size(A,2);
CE=zeros(1,samples);

MAXITER=100;
NRWAN=30;

ME1=mean_misval(A,2);
DMI=dist_misval(A,ME1,2);
RAD=max(DMI);
DELTARAD=(RAD-EXTTRESH)/NRWAN;
RADPR=RAD;
RAD=RAD-DELTARAD;
Q=find(DMI<RAD);
if isempty(Q)
   MDIS=min(DMI);
   RAD=(RADPR+MDIS)/2;
   Q=find(DMI<RAD);
end

CONV=0;
TEL=0;

for iter=1:MAXITER
   ME2=mean_misval(A(:,Q),2);
   RADPRPR=RADPR;
   RADPR=RAD;
   RAD=max(EXTTRESH,RAD-DELTARAD);
   DMI=dist_misval(A,ME2,2);
   Q=find(DMI<RAD);
   if isempty(Q) & ~(RADPR==EXTTRESH)
      TEL=TEL+1;
      if TEL<6 
          MDIS=min(DMI);
          RAD=(RADPR+MDIS)/2;
          Q=find(DMI<RAD);
      else
          break
      end
   else
      TEL=0;
   end
   if RADPRPR==EXTTRESH
      if ((ME1==ME2)+((~finite(ME1))&(~finite(ME2))))
         CONV=1;
         break
      end
   end
   if isempty(Q)
       break
   end
   ME1=ME2;
end
   
if CONV==1
   ME=ME2;
   CE(Q)=1;
else
   ME=[];
end