function res=ier_tree(nb,ne,res,f1,f2,mode,FontSize,LineWidth);

col=res.col;
n=res.dnei;
a=res.matr;
str=res.str;
logm=zeros(ne-nb+1,col);
for j=1:col
    for i=nb:ne
            logm(i-nb+1,j)=log(a(i,j))-log(a(i-1,j));
    end
end
R=[];
R=corrcoef(logm);
dist=[];
dist=sqrt(2*(1-R));
dist=real(dist);
%ultramatrix
counter=1;
t=[];
clusters=[];
t=dist;
dul=zeros(col,col);
for i=1:col
    clusters(i).col=1;
    clusters(i).list=[];
    clusters(i).list=[clusters(i).list,i];
    clusters(i).pos=inf;
    t(i,i)=inf;
end
for i=1:(col-1)
    imin=0;
    jmin=0;
    minel=inf;
    %poisk min i ego indeksa
    for ii=1:col
        for jj=ii:col
            if t(ii,jj)<=minel
                minel=t(ii,jj);
                imin=ii;
                jmin=jj;
            end
        end
    end
      
    %poisk ego klastera
    f=0;
    cl1=0;
    for iii=1:col
        if clusters(iii).col~=0
            for jjj=1:clusters(iii).col
                if clusters(iii).list(jjj)==imin;
                    cl1=iii;%klaster nachala min rebra
                    f=f+1;
                    break;
                else
                    if clusters(iii).list(jjj)==jmin;
                        cl2=iii;
                        f=f+1;
                        break;
                    end
                end
            end
            if f==2
                break;
            end
        end
    end
    if clusters(cl1).pos>clusters(cl2).pos
        tmp=clusters(cl1);
        clusters(cl1)=clusters(cl2);
        clusters(cl2)=tmp;
    end
    
    
    %pereopredelenie dul-matritsy
     n1=clusters(cl1).col;
     n2=clusters(cl2).col;
      for ii=1:n1
        for jj=1:n2
             dul(clusters(cl1).list(ii),clusters(cl2).list(jj))=minel;
             dul(clusters(cl2).list(jj),clusters(cl1).list(ii))=minel;
         end
     end
     %pereopredelenie matritsy t
     
     for j=1:col
         if t(cl1,j)~=inf & j~=cl2
             if mode=='alca'
                 t(cl1,j)=(n1*t(cl1,j)+n2*t(cl2,j))/(n1+n2);
                 t(j,cl1)=t(cl1,j);
             else   
                if t(cl2,j)<=t(cl1,j)
                    t(cl1,j)=t(cl2,j);             
                    t(j,cl1)=t(cl1,j);
                end
            end
         end
     end
       for ii=1:col
           t(ii,cl2)=inf;
           t(cl2,ii)=t(ii,cl2);
       end
     %pereopredelenie clusters
     if clusters(cl1).col==1 & clusters(cl2).col==1 
         clusters(cl1).pos=counter;
         counter=counter+1;
     end
     clusters(cl1).col=clusters(cl1).col+clusters(cl2).col;
     clusters(cl1).list=[clusters(cl1).list,clusters(cl2).list];
     clusters(cl2).col=0;
     clusters(cl2).list=[];
     clnum=cl1;
     
 end
     
     list=clusters(clnum).list;
     
counter=1;     
R1=[];     
t=[];
clusters=[];
t=dist;
dul=zeros(col,col);
for i=1:col
    clusters(i).col=1;
    clusters(i).list=[];
    clusters(i).pos=inf;
    clusters(i).list=[clusters(i).list,i];
    t(i,i)=inf;
    for j=1:col
         if list(j)==i
            clusters(i).lnk=[j 0];
            break;
        end
    end
end
for i=1:(col-1)
    
    imin=0;
    jmin=0;
    minel=inf;
    %poisk min i ego indeksa
    for ii=1:col
        for jj=ii:col
            if t(ii,jj)<=minel
                minel=t(ii,jj);
                imin=ii;
                jmin=jj;
            end
        end
    end
     
    f=0;
    cl1=0;
    for iii=1:col
        if clusters(iii).col~=0
            for jjj=1:clusters(iii).col
                if clusters(iii).list(jjj)==imin;
                    cl1=iii;%klaster nachala min rebra
                    f=f+1;
                    break;
                else
                    if clusters(iii).list(jjj)==jmin;
                        cl2=iii;
                        f=f+1;
                        break;
                    end
                end
            end
            if f==2
                break;
            end
        end
    end
    if clusters(cl1).pos>clusters(cl2).pos
        tmp=clusters(cl1);
        clusters(cl1)=clusters(cl2);
        clusters(cl2)=tmp;
    end
     %pereopredelenie matritsy t
     value=minel;
     for j=1:col
         if t(cl1,j)~=inf & j~=cl2
             if mode=='alca'
                 t(cl1,j)=(n1*t(cl1,j)+n2*t(cl2,j))/(n1+n2);
                 t(j,cl1)=t(cl1,j);
             else   
                if t(cl2,j)<=t(cl1,j)
                    t(cl1,j)=t(cl2,j);             
                    t(j,cl1)=t(cl1,j);
                end
            end
         end
     end
       for ii=1:col
           t(ii,cl2)=inf;
           t(cl2,ii)=t(ii,cl2);
       end
     %pereopredelenie clusters
      if clusters(cl1).col==1 & clusters(cl2).col==1 
         clusters(cl1).pos=counter;
         counter=counter+1;
     end
     R1=[R1;clusters(cl1).lnk(1),clusters(cl1).lnk(2),value,clusters(cl2).lnk(1),clusters(cl2).lnk(2)];
     clusters(cl1).lnk(1)=(clusters(cl1).lnk(1)+clusters(cl2).lnk(1))/2;
     clusters(cl1).lnk(2)=value;
     clusters(cl1).col=clusters(cl1).col+clusters(cl2).col;
     clusters(cl1).list=[clusters(cl1).list,clusters(cl2).list];
     clusters(cl2).col=0;
     clusters(cl2).list=[];
 end
 R2=list;
res=treeplot2(R1,R2,str,f1,f2,FontSize,LineWidth);
