      subroutine latt_small(alat,pos3,xx,yy,zz,m)
      implicit double precision (A-H,O-Z)
      parameter (nat=160,n=108)
      dimension pos(nat,3),pos1(8,3),pos3(4320,3)
      dimension xp(3),yp(3),zp(3)
      dimension x(n),y(n),z(n),xn(n),yn(n),zn(n)
      alat2=0.5d0*alat
c     1 atom
      pos1(1,1)=0.0d0
      pos1(1,2)=0.0d0
      pos1(1,3)=0.0d0
c     2 atom
      pos1(2,1)=alat2
      pos1(2,2)=alat2
      pos1(2,3)=0.0d0
c     3 atom
      pos1(3,1)=alat2
      pos1(3,2)=0.0d0
      pos1(3,3)=alat2
c     4 atom
      pos1(4,1)=0.0d0
      pos1(4,2)=alat2
      pos1(4,3)=alat2
c ================================
      n1=0
      do i1=1,3
       do i2=1,3
        do i3=1,3
         do k=1,4
            pos(n1+k,1)=pos1(k,1)+dble(i1-1)*alat
            pos(n1+k,2)=pos1(k,2)+dble(i2-1)*alat
            pos(n1+k,3)=pos1(k,3)+dble(i3-1)*alat
         end do
         n1=n1+4
        end do
       end do
      end do
c
      do i=1,n
    	 x(i)=pos(i,1)
    	 y(i)=pos(i,2)
	     z(i)=pos(i,3)
      end do
c
      xd=3.0d0*alat
      xdn=-xd
      yd=3.d0*alat
      ydn=-yd
      zd=3.0d0*alat
      zdn=-zd
      xp(1)=0.d0
      yp(1)=0.d0
      zp(1)=0.d0
      xp(2)=xdn
      yp(2)=ydn
      zp(2)=zdn
      xp(3)=xd
      yp(3)=yd
      zp(3)=zd
c
      call multy(n,x,y,z,pos3,xp,yp,zp,0.0d0)
c
      m=0
      n27=n*27
      do i=1,n27
c         ss1=(pos3(i,1))+(pos3(i,2))
c         ss2=(pos3(i,1))+(pos3(i,3))
c         ss3=(pos3(i,2))+(pos3(i,3))
         ss=3.d0*alat
         pp=(1.d0/ss)*(pos3(i,1)+pos3(i,2)+pos3(i,3))
        if (pp.GE.1.d0) then
c         if ((ss1.GE.ss0).AND.(ss2.GE.ss0).AND.(ss3.GE.ss0)) then
            m=m+1
            pos3(i,1)=pos3(i,1)+xx
            pos3(i,2)=pos3(i,2)+yy
            pos3(i,3)=pos3(i,3)+zz
         end if
      end do
      return
      end
