function [idiff,jmem,memjt] = setup(numnp,numel,np)
%compute topology array for renumbering algorithm

%
%
%     subroutine setup and subroutine optinum were written by R. J. Col.
%
%     Ref. Bandwidth Reduction by Automatic Renumbering
%
%          International Journal for Numerical Methods in
%                        Engineering
%
%          Vol. 6, pp.345-356  (1973)
%

idiff=0;
memjtbreak = 0;

for j=1:numnp
    jmem(j)=0;
end

for j=1:numel

    for  i=1:3

        jnti=np(j,i);

        if(jnti == 0)
            break
        end

        jsub=(jnti - 1)*8;


        for ii=1:3

            if(ii == i)
                continue
            end

            jjt=np(j,ii);

            if(jjt == 0)
                break
            end

            mem1=jmem(jnti);

            if(mem1 ~= 0)

                for iii=1:mem1
                    if(memjt(jsub + iii) == jjt)
                        memjtbreak= 1;
                        break
                    end
                end

                if(memjtbreak==1)
                    memjtbreak = 0;
                    continue
                end

            end

            jmem(jnti)=jmem(jnti) + 1;
            memjt(jsub + jmem(jnti))=jjt;

            if(abs(jnti - jjt) > idiff)
                idiff=abs(jnti - jjt);
            end


        end


    end


end





