      subroutine gradxxdp2(m,n,nn,nc,inddyy,icentr,iicontr,cdfits,
     &                     cdfitp,cdfitd,gradient,density,ttwozetaa,
     &                     fss0,fsp0,fsd0,gss0,gsp0,gsd0,axbx,ayby,azbz,
     &                     fsscond,fspcond,fsdcond,gsscond,gspcond,
     &                     gsdcond,fpscond,fppcond,fpdcond,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(*),
     &          ttwozetaa(*),fss0(n,*),fsp0(n,*),fsd0(n,*),gss0(n,*),
     &          gsp0(n,*),gsd0(n,*),axbx(*),ayby(*),azbz(*),
     &          fsscond(m,*),fspcond(m,*),fsdcond(m,*),gsscond(m,*),
     &          gspcond(m,*),gsdcond(m,*),fpscond(m,*),fppcond(m,*),
     &          fpdcond(m,*),grad(m,*)

      data zero/0.0d0/

      do 1001 j=1,10
      do 1001 i=1,m
 1001 fsscond(i,j)=zero

      do 1002 j=1,15
      do 1002 i=1,m
 1002 gsscond(i,j)=zero

      do 1003 j=1,10
      do 1003 i=1,nn
 1003 fsscond(iicontr(i),j)=fsscond(iicontr(i),j)
     &                     +fss0(i,j)*ttwozetaa(i)*cdfits

      do 1004 k=1,3
      do 1004 j=1,10
      do 1004 i=1,nn
 1004 fsscond(iicontr(i),j)=fsscond(iicontr(i),j)
     &                     +fsp0(i,3*(j-1)+k)*ttwozetaa(i)*cdfitp(k)

      do 1005 k=1,6
      do 1005 j=1,10
      do 1005 i=1,nn
 1005 fsscond(iicontr(i),j)=fsscond(iicontr(i),j)
     &                     +fsd0(i,6*(j-1)+k)*ttwozetaa(i)*cdfitd(k)

      do 1006 j=1,15
      do 1006 i=1,nn
 1006 gsscond(iicontr(i),j)=gsscond(iicontr(i),j)
     &                     +gss0(i,j)*ttwozetaa(i)*cdfits

      do 1007 k=1,3
      do 1007 j=1,15
      do 1007 i=1,nn
 1007 gsscond(iicontr(i),j)=gsscond(iicontr(i),j)
     &                     +gsp0(i,3*(j-1)+k)*ttwozetaa(i)*cdfitp(k)

      do 1008 k=1,6
      do 1008 j=1,15
      do 1008 i=1,nn
 1008 gsscond(iicontr(i),j)=gsscond(iicontr(i),j)
     &                     +gsd0(i,6*(j-1)+k)*ttwozetaa(i)*cdfitd(k)

      do 1009 i=1,m
      fpscond(i,01)=axbx(i)*fsscond(i,01)+gsscond(i,01)
      fpscond(i,02)=ayby(i)*fsscond(i,01)+gsscond(i,02)
      fpscond(i,03)=azbz(i)*fsscond(i,01)+gsscond(i,03)
      fpscond(i,04)=axbx(i)*fsscond(i,02)+gsscond(i,02)
      fpscond(i,05)=ayby(i)*fsscond(i,02)+gsscond(i,04)
      fpscond(i,06)=azbz(i)*fsscond(i,02)+gsscond(i,05)
      fpscond(i,07)=axbx(i)*fsscond(i,03)+gsscond(i,03)
      fpscond(i,08)=ayby(i)*fsscond(i,03)+gsscond(i,05)
      fpscond(i,09)=azbz(i)*fsscond(i,03)+gsscond(i,06)
      fpscond(i,10)=axbx(i)*fsscond(i,04)+gsscond(i,04)
      fpscond(i,11)=ayby(i)*fsscond(i,04)+gsscond(i,07)
      fpscond(i,12)=azbz(i)*fsscond(i,04)+gsscond(i,08)
      fpscond(i,13)=axbx(i)*fsscond(i,05)+gsscond(i,05)
      fpscond(i,14)=ayby(i)*fsscond(i,05)+gsscond(i,08)
      fpscond(i,15)=azbz(i)*fsscond(i,05)+gsscond(i,09)
      fpscond(i,16)=axbx(i)*fsscond(i,06)+gsscond(i,06)
      fpscond(i,17)=ayby(i)*fsscond(i,06)+gsscond(i,09)
      fpscond(i,18)=azbz(i)*fsscond(i,06)+gsscond(i,10)
      fpscond(i,19)=axbx(i)*fsscond(i,07)+gsscond(i,07)
      fpscond(i,20)=ayby(i)*fsscond(i,07)+gsscond(i,11)
      fpscond(i,21)=azbz(i)*fsscond(i,07)+gsscond(i,12)
      fpscond(i,22)=axbx(i)*fsscond(i,08)+gsscond(i,08)
      fpscond(i,23)=ayby(i)*fsscond(i,08)+gsscond(i,12)
      fpscond(i,24)=azbz(i)*fsscond(i,08)+gsscond(i,13)
      fpscond(i,25)=axbx(i)*fsscond(i,09)+gsscond(i,09)
      fpscond(i,26)=ayby(i)*fsscond(i,09)+gsscond(i,13)
      fpscond(i,27)=azbz(i)*fsscond(i,09)+gsscond(i,14)
      fpscond(i,28)=axbx(i)*fsscond(i,10)+gsscond(i,10)
      fpscond(i,29)=ayby(i)*fsscond(i,10)+gsscond(i,14)
 1009 fpscond(i,30)=azbz(i)*fsscond(i,10)+gsscond(i,15)

      do 1010 i=1,m
      grad(i,01)=fpscond(i,01)*density(inddyy(i,01))
      grad(i,02)=fpscond(i,02)*density(inddyy(i,02))
      grad(i,03)=fpscond(i,03)*density(inddyy(i,03))
      grad(i,04)=fpscond(i,04)*density(inddyy(i,04))
      grad(i,05)=fpscond(i,05)*density(inddyy(i,05))
      grad(i,06)=fpscond(i,06)*density(inddyy(i,06))
      grad(i,07)=fpscond(i,07)*density(inddyy(i,07))
      grad(i,08)=fpscond(i,08)*density(inddyy(i,08))
      grad(i,09)=fpscond(i,09)*density(inddyy(i,09))
      grad(i,10)=fpscond(i,10)*density(inddyy(i,10))
      grad(i,11)=fpscond(i,11)*density(inddyy(i,11))
      grad(i,12)=fpscond(i,12)*density(inddyy(i,12))
      grad(i,13)=fpscond(i,13)*density(inddyy(i,13))
      grad(i,14)=fpscond(i,14)*density(inddyy(i,14))
      grad(i,15)=fpscond(i,15)*density(inddyy(i,15))
      grad(i,16)=fpscond(i,16)*density(inddyy(i,16))
      grad(i,17)=fpscond(i,17)*density(inddyy(i,17))
      grad(i,18)=fpscond(i,18)*density(inddyy(i,18))
      grad(i,19)=fpscond(i,04)*density(inddyy(i,01))
      grad(i,20)=fpscond(i,05)*density(inddyy(i,02))
      grad(i,21)=fpscond(i,06)*density(inddyy(i,03))
      grad(i,22)=fpscond(i,10)*density(inddyy(i,04))
      grad(i,23)=fpscond(i,11)*density(inddyy(i,05))
      grad(i,24)=fpscond(i,12)*density(inddyy(i,06))
      grad(i,25)=fpscond(i,13)*density(inddyy(i,07))
      grad(i,26)=fpscond(i,14)*density(inddyy(i,08))
      grad(i,27)=fpscond(i,15)*density(inddyy(i,09))
      grad(i,28)=fpscond(i,19)*density(inddyy(i,10))
      grad(i,29)=fpscond(i,20)*density(inddyy(i,11))
      grad(i,30)=fpscond(i,21)*density(inddyy(i,12))
      grad(i,31)=fpscond(i,22)*density(inddyy(i,13))
      grad(i,32)=fpscond(i,23)*density(inddyy(i,14))
      grad(i,33)=fpscond(i,24)*density(inddyy(i,15))
      grad(i,34)=fpscond(i,25)*density(inddyy(i,16))
      grad(i,35)=fpscond(i,26)*density(inddyy(i,17))
      grad(i,36)=fpscond(i,27)*density(inddyy(i,18))
      grad(i,37)=fpscond(i,07)*density(inddyy(i,01))
      grad(i,38)=fpscond(i,08)*density(inddyy(i,02))
      grad(i,39)=fpscond(i,09)*density(inddyy(i,03))
      grad(i,40)=fpscond(i,13)*density(inddyy(i,04))
      grad(i,41)=fpscond(i,14)*density(inddyy(i,05))
      grad(i,42)=fpscond(i,15)*density(inddyy(i,06))
      grad(i,43)=fpscond(i,16)*density(inddyy(i,07))
      grad(i,44)=fpscond(i,17)*density(inddyy(i,08))
      grad(i,45)=fpscond(i,18)*density(inddyy(i,09))
      grad(i,46)=fpscond(i,22)*density(inddyy(i,10))
      grad(i,47)=fpscond(i,23)*density(inddyy(i,11))
      grad(i,48)=fpscond(i,24)*density(inddyy(i,12))
      grad(i,49)=fpscond(i,25)*density(inddyy(i,13))
      grad(i,50)=fpscond(i,26)*density(inddyy(i,14))
      grad(i,51)=fpscond(i,27)*density(inddyy(i,15))
      grad(i,52)=fpscond(i,28)*density(inddyy(i,16))
      grad(i,53)=fpscond(i,29)*density(inddyy(i,17))
 1010 grad(i,54)=fpscond(i,30)*density(inddyy(i,18))

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

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

      return
      end
