      subroutine basize(natoms,nmos,naos,nconts,ncontp,ncontd,nshels,
     &                  nshelp,nsheld,icfunc,nfuncatom,iatom_center,
     &                  istart,ibasis_size,ibasis,iatom_last,cutoff,
     &                  coord)

      implicit real*8(a-h,o-z)

      dimension nshels(*),nshelp(*),nsheld(*),icfunc(*),nfuncatom(*)
      dimension iatom_center(*),istart(*),ibasis_size(*),ibasis(naos,*),
     &          iatom_last(*)

      dimension coord(3,*)

      data zero/0.0d0/

      ii=0

      do 1001 i=1,nconts
      nfuncatom(ii+1)=icfunc(nshels(i))
 1001 ii=ii+1

      do 1002 i=1,ncontp
      do 1003 k=1,3
 1003 nfuncatom(ii+k)=icfunc(nshelp(i))
 1002 ii=ii+3

      do 1004 i=1,ncontd
      do 1005 k=1,6
 1005 nfuncatom(ii+k)=icfunc(nsheld(i))
 1004 ii=ii+6

      if(iatom_center(1).eq.0) then
                                     do 1006 i=1,nmos
 1006                                iatom_center(i)=nfuncatom(i)
                               endif

      do 1007 j=1,nmos

      nkeep=0

      do 1008 i=1,naos
      distance=dist(coord(1,nfuncatom(i)),coord(1,iatom_center(j)))
      if(distance.le.cutoff) then
                                   nkeep=nkeep+1
                                   ibasis(nkeep,j)=i
                             endif
 1008 continue

 1007 ibasis_size(j)=nkeep

      do 1009 i=1,natoms
 1009 iatom_last(i)=0

      do 1010 j=1,nmos

      ihits=0

      icenter=iatom_center(j)

      do 1011 i=1,ibasis_size(j)

      if(nfuncatom(ibasis(i,j)).eq.icenter) ihits=ihits+1

      if(ihits.eq.(iatom_last(icenter)+1)) then
                                                 istart(j)=i
                                                 goto 1012
                                           endif
 1011 continue

 1012 iatom_last(iatom_center(j))=ihits

 1010 continue

      return
      end
