      subroutine neighbor(i,neighb)
      use grid_module
      implicit none
      integer i,k,ix,iy,iz,npyz,neighb(6)
      integer npx,npy,npz
      npx=np(1)-1
      npy=np(2)-1
      npz=np(3)-1
      npyz=np(2)*np(3)
      ix=(i-1)/npyz
      iy=(i-1-ix*npyz)/np(3)
      iz=i-1-ix*npyz-iy*np(3)
      do k=1,6
         neighb(k)=0
      enddo
      if(ix.gt.0) then
         neighb(1)=i-npyz
      endif
      if(ix.lt.npx) then
         neighb(2)=i+npyz
      endif
      if(iy.gt.0) then
         neighb(3)=i-np(3)
      endif
      if(iy.lt.npy) then
         neighb(4)=i+np(3)
      endif
      if(iz.gt.0) then
         neighb(5)=i-1
      endif
      if(iz.lt.npz) then
         neighb(6)=i+1
      endif
      return
      end
