      subroutine neighcls(neighb,n_neighb,iborder)
      use grid_module
      implicit none
      integer i,j,k,neighb(6)
      integer n_neighb(6)
      integer iborder
      do i=1,6
         j=neighb(i)
         if(j.ne.0) then
            n_neighb(i)=abs(attract_code(j))
         else
            n_neighb(i)=0
         endif
      enddo
      do i=1,6
         if(n_neighb(i).eq.0) then
            neighb(i)=0
         endif
      enddo
      do i=1,5
         k=n_neighb(i)
         do j=i+1,6
            if(n_neighb(j).gt.k) then
               k=n_neighb(j)
               n_neighb(j)=n_neighb(i)
               n_neighb(i)=k
            else if (n_neighb(j).eq.k) then
               n_neighb(j)=0
            endif
         enddo
      enddo
      i=1
      do while (n_neighb(i).ne.0)
         i=i+1
      enddo
      iborder=i-1
      return
      end      
