      subroutine gradxxdp1(m,n,nn,nc,inddyy,icentr,iicontr,cdfits,
     &                     cdfitp,cdfitd,gradient,density,pss0,psp0,
     &                     psd0,dss0,dsp0,dsd0,axbx,ayby,azbz,psscond,
     &                     pspcond,psdcond,dsscond,dspcond,dsdcond,
     &                     ppscond,pppcond,ppdcond,grad)

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 inddyy(m,*),icentr(m,*),iicontr(*)

      dimension cdfitp(*),cdfitd(*),gradient(3,*),density(*),pss0(n,*),
     &          psp0(n,*),psd0(n,*),dss0(n,*),dsp0(n,*),dsd0(n,*),
     &          axbx(*),ayby(*),azbz(*),psscond(m,*),pspcond(m,*),
     &          psdcond(m,*),dsscond(m,*),dspcond(m,*),dsdcond(m,*),
     &          ppscond(m,*),pppcond(m,*),ppdcond(m,*),grad(m,*)

      data zero,two/0.0d0,2.0d0/

      do 1001 j=1,3
      do 1001 i=1,m
 1001 psscond(i,j)=zero

      do 1002 j=1,6
      do 1002 i=1,m
 1002 dsscond(i,j)=zero

      do 1003 j=1,3
      do 1003 i=1,nn
 1003 psscond(iicontr(i),j)=psscond(iicontr(i),j)
     &                     -pss0(i,j)*cdfits

      do 1004 k=1,3
      do 1004 j=1,3
      do 1004 i=1,nn
 1004 psscond(iicontr(i),j)=psscond(iicontr(i),j)
     &                     -psp0(i,3*(j-1)+k)*cdfitp(k)

      do 1005 k=1,6
      do 1005 j=1,3
      do 1005 i=1,nn
 1005 psscond(iicontr(i),j)=psscond(iicontr(i),j)
     &                     -psd0(i,6*(j-1)+k)*cdfitd(k)

      do 1006 j=1,6
      do 1006 i=1,nn
 1006 dsscond(iicontr(i),j)=dsscond(iicontr(i),j)
     &                     -dss0(i,j)*cdfits

      do 1007 k=1,3
      do 1007 j=1,6
      do 1007 i=1,nn
 1007 dsscond(iicontr(i),j)=dsscond(iicontr(i),j)
     &                     -dsp0(i,3*(j-1)+k)*cdfitp(k)

      do 1008 k=1,6
      do 1008 j=1,6
      do 1008 i=1,nn
 1008 dsscond(iicontr(i),j)=dsscond(iicontr(i),j)
     &                     -dsd0(i,6*(j-1)+k)*cdfitd(k)

      do 1009 i=1,m
      ppscond(i,1)=axbx(i)*psscond(i,1)+dsscond(i,1)
      ppscond(i,2)=ayby(i)*psscond(i,1)+dsscond(i,2)
      ppscond(i,3)=azbz(i)*psscond(i,1)+dsscond(i,3)
      ppscond(i,4)=axbx(i)*psscond(i,2)+dsscond(i,2)
      ppscond(i,5)=ayby(i)*psscond(i,2)+dsscond(i,4)
      ppscond(i,6)=azbz(i)*psscond(i,2)+dsscond(i,5)
      ppscond(i,7)=axbx(i)*psscond(i,3)+dsscond(i,3)
      ppscond(i,8)=ayby(i)*psscond(i,3)+dsscond(i,5)
 1009 ppscond(i,9)=azbz(i)*psscond(i,3)+dsscond(i,6)

      do 1010 i=1,m
      grad(i,01)=ppscond(i,1)*density(inddyy(i,01))*two
      grad(i,02)=ppscond(i,2)*density(inddyy(i,02))*two
      grad(i,03)=ppscond(i,3)*density(inddyy(i,03))*two
      grad(i,04)=ppscond(i,4)*density(inddyy(i,04))
      grad(i,05)=ppscond(i,5)*density(inddyy(i,05))
      grad(i,06)=ppscond(i,6)*density(inddyy(i,06))
      grad(i,07)=ppscond(i,7)*density(inddyy(i,07))
      grad(i,08)=ppscond(i,8)*density(inddyy(i,08))
      grad(i,09)=ppscond(i,9)*density(inddyy(i,09))
      grad(i,10)=ppscond(i,1)*density(inddyy(i,04))
      grad(i,11)=ppscond(i,2)*density(inddyy(i,05))
      grad(i,12)=ppscond(i,3)*density(inddyy(i,06))
      grad(i,13)=ppscond(i,4)*density(inddyy(i,10))*two
      grad(i,14)=ppscond(i,5)*density(inddyy(i,11))*two
      grad(i,15)=ppscond(i,6)*density(inddyy(i,12))*two
      grad(i,16)=ppscond(i,7)*density(inddyy(i,13))
      grad(i,17)=ppscond(i,8)*density(inddyy(i,14))
      grad(i,18)=ppscond(i,9)*density(inddyy(i,15))
      grad(i,19)=ppscond(i,1)*density(inddyy(i,07))
      grad(i,20)=ppscond(i,2)*density(inddyy(i,08))
      grad(i,21)=ppscond(i,3)*density(inddyy(i,09))
      grad(i,22)=ppscond(i,4)*density(inddyy(i,13))
      grad(i,23)=ppscond(i,5)*density(inddyy(i,14))
      grad(i,24)=ppscond(i,6)*density(inddyy(i,15))
      grad(i,25)=ppscond(i,7)*density(inddyy(i,16))*two
      grad(i,26)=ppscond(i,8)*density(inddyy(i,17))*two
 1010 grad(i,27)=ppscond(i,9)*density(inddyy(i,18))*two

      do 1011 k=1,3
      do 1011 j=1,9
      do 1011 i=1,m
 1011 gradient(k,nc)=gradient(k,nc)-grad(i,9*(k-1)+j)

      do 1012 k=1,3
      do 1012 j=1,9
      do 1012 i=1,m
 1012 gradient(k,icentr(i,1))=gradient(k,icentr(i,1))+grad(i,9*(k-1)+j)

      do 1013 i=1,m
      grad(i,01)=dsscond(i,1)*density(inddyy(i,01))
      grad(i,02)=dsscond(i,2)*density(inddyy(i,04))
      grad(i,03)=dsscond(i,3)*density(inddyy(i,07))
      grad(i,04)=dsscond(i,4)*density(inddyy(i,10))
      grad(i,05)=dsscond(i,5)*density(inddyy(i,13))
      grad(i,06)=dsscond(i,6)*density(inddyy(i,16))
      grad(i,07)=dsscond(i,1)*density(inddyy(i,02))
      grad(i,08)=dsscond(i,2)*density(inddyy(i,05))
      grad(i,09)=dsscond(i,3)*density(inddyy(i,08))
      grad(i,10)=dsscond(i,4)*density(inddyy(i,11))
      grad(i,11)=dsscond(i,5)*density(inddyy(i,14))
      grad(i,12)=dsscond(i,6)*density(inddyy(i,17))
      grad(i,13)=dsscond(i,1)*density(inddyy(i,03))
      grad(i,14)=dsscond(i,2)*density(inddyy(i,06))
      grad(i,15)=dsscond(i,3)*density(inddyy(i,09))
      grad(i,16)=dsscond(i,4)*density(inddyy(i,12))
      grad(i,17)=dsscond(i,5)*density(inddyy(i,15))
 1013 grad(i,18)=dsscond(i,6)*density(inddyy(i,18))

      do 1014 k=1,3
      do 1014 j=1,6
      do 1014 i=1,m
 1014 gradient(k,nc)=gradient(k,nc)-grad(i,6*(k-1)+j)

      do 1015 k=1,3
      do 1015 j=1,6
      do 1015 i=1,m
 1015 gradient(k,icentr(i,2))=gradient(k,icentr(i,2))+grad(i,6*(k-1)+j)

      return
      end
