      subroutine diffuse3(nxcs,nxcspd,ilaux,icaux,tolerance,alpha,
     &                    coeffs,coeffp,coeffd,cent,extent)

c  this subroutine written by alain st-amant of the department of
c  pharmaceutical chemistry, university of california, san francisco.
c  all rights reserved.  this is part of the DeFT project.

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

      dimension ilaux(*),icaux(*)

      dimension alpha(*),coeffs(*),coeffp(*),coeffd(*)
      dimension cent(3,*),extent(*)

      data nextent/50/
      data zero,one,expcut/0.0d0,1.0d0,50.0d0/

      do 1001 i=1,nxcspd
 1001 extent(i)=zero

      do 1002 iloop=1,nextent

      xx=real64(iloop)
      rr=xx*xx

c  now for lone-s exponent xc fitting functions

      do 1003 i=1,nxcs

      ilabel=ilaux(i)

      rralpha=rr*alpha(ilabel)

      s=zero

      if(rralpha.le.expcut) s=exp(-rralpha)*coeffs(ilabel)

      if(abs(s).gt.tolerance) then
                                    if(xx.gt.extent(i)) extent(i)=xx
                              endif

 1003 continue

c  now for shared exponent xc fitting functions

      do 1006 i=nxcs+1,nxcspd

      ilabel=ilaux(i)

      rralpha=rr*alpha(ilabel)

      dxx=zero

      if(rralpha.le.expcut) dxx=xx*xx*exp(-rralpha)*coeffd(ilabel)

      if(abs(dxx).gt.tolerance) then
                                      if(xx.gt.extent(i)) extent(i)=xx
                                endif

 1006 continue

 1002 continue

      do 1007 i=1,nxcspd
 1007 if(extent(i).ge.real64(nextent-1)) stop 'extent may be a problem'

      do 1008 i=1,nxcspd
 1008 extent(i)=extent(i)+one

      return
      end
