      subroutine docdfit(ndim,ncds,ncdspd,ilfunc,dnorm,alpha,coeffs,
     &                   coeffd,cdfit,tvector,sinverse,wkvec)

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 ilfunc(*)

      dimension alpha(*),coeffs(*),coeffd(*)
      dimension cdfit(*),tvector(*),sinverse(ndim,*),wkvec(*)

      data zero,one,two,three,fortynine/0.0d0,1.0d0,2.0d0,3.0d0,49.0d0/
      data pi/3.1415926535898d0/

      ncoeffs=ncds+10*ncdspd

      do 1001 i=1,ncds
 1001 wkvec(i)=((pi/alpha(ilfunc(i)))**(three/two))*coeffs(ilfunc(i))

      do 1002 i=1,ncdspd

      val1=((pi/alpha(ilfunc(ncds+i)))**(three/two))
     &    *coeffs(ilfunc(ncds+i))

      val2=((pi/alpha(ilfunc(ncds+i)))**(three/two))
     &    *coeffd(ilfunc(ncds+i))/(two*alpha(ilfunc(ncds+i)))

      wkvec(ncds+10*(i-1)+01)=val1
      wkvec(ncds+10*(i-1)+02)=zero
      wkvec(ncds+10*(i-1)+03)=zero
      wkvec(ncds+10*(i-1)+04)=zero
      wkvec(ncds+10*(i-1)+05)=val2/sqrt(fortynine/three)
      wkvec(ncds+10*(i-1)+06)=zero
      wkvec(ncds+10*(i-1)+07)=zero
      wkvec(ncds+10*(i-1)+08)=val2/sqrt(fortynine/three)
      wkvec(ncds+10*(i-1)+09)=zero
      wkvec(ncds+10*(i-1)+10)=val2/sqrt(fortynine/three)

 1002 continue

      do 1003 i=1,ncoeffs
 1003 call fastrd(18,sinverse(1,i),ncoeffs)

      val1=dnorm
      val2=zero

      do 1004 i=1,ncoeffs
 1004 val1=val1-wkvec(i)*dot(ncoeffs,sinverse(1,i),tvector)

      do 1005 i=1,ncoeffs
 1005 val2=val2+wkvec(i)*dot(ncoeffs,sinverse(1,i),wkvec)

      do 1006 i=1,ncoeffs
 1006 tvector(i)=tvector(i)+val1*wkvec(i)/val2

      do 1007 i=1,ncoeffs
 1007 cdfit(i)=dot(ncoeffs,sinverse(1,i),tvector)

      return
      end
