C 30 APR 07 - SPW - NEW MODULE FOR NEO DERIVATIVE INTEGRALS
C                   (BASED ON GRD2C.SRC)
C
C*MODULE NEOG2C  *DECK JKDSPD
      SUBROUTINE JKDSPD_MIX(NIJ0,NKL,NKL0,DCHRG,GINT,FINT,SINT,IJKLG,
     1                  GIJKL,GNKL,GNM,XY,XZ,YZ,X,Y,Z,SJ,SK,SL,
     2                  B00,B01,B10,C00,D00,F00,DIJ,DKL,DIJSI,DIJSJ,
     3                  DKLSK,DKLSL,ABV,CV,RWV,AAI,AAJ,BBK,BBL,FI,FJ,
     4                  FK,FL,SII,SJJ,SKK,SLL,SIJ,SIK,SIL,SJK,SJL,SKL,
     5                  DAB,MAXXYZ,QQ4,MINVEC,
     6                  DABCUT, DABMAX,DCHRKL)
C
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      LOGICAL SKIPI,SKIPJ,SKIPK,SKIPL
      LOGICAL SPI,SPJ,SPK,SPL,SPIJ,SPKL,SPIJKL
      LOGICAL NMAXS,NMAXP,MMAXS,MMAXP
      LOGICAL EXPNDI,EXPNDK
      LOGICAL FIRST
      LOGICAL LAST
      LOGICAL OUT,DBG
      LOGICAL LCFLAG,LRINT
      COMMON/DERPAR/IDER,JDER,KDER,LDER,NDER
      COMMON/DERSKP/IIAT,JJAT,KKAT,LLAT,SKIPI,SKIPJ,SKIPK,SKIPL
      COMMON /DSHLNO/ LIT,LJT,LKT,LLT,LOCI,LOCJ,LOCK,LOCL,
     *                MINI,MINJ,MINK,MINL,MAXI,MAXJ,MAXK,MAXL,
     *                NIJ,IJD,KLD,IJ,KL
      COMMON /DSHLT / RTOL,DTOL,VTOL1,VTOL2,VTOLS,OUT,DBG
      COMMON /NLRC  / LCFLAG,LRINT,EMU,EMU2,LRFILE
      COMMON /ROOT  / XX,U(13),W(13),NROOTS
      COMMON/SHLGNM/NMAXS,NMAXP,MMAXS,MMAXP
      COMMON/SHLTYP/SPI,SPJ,SPK,SPL,SPIJ,SPKL,SPIJKL
      COMMON/SHLXPN/EXPNDI,EXPNDK
      DIMENSION DCHRG(15,*)
      DIMENSION DCHRKL(15,*)
      DIMENSION GINT(1),FINT(12,1),SINT(78,1),IJKLG(4,1)
      DIMENSION XY(1),XZ(1),YZ(1),X(1),Y(1),Z(1),SJ(1),SK(1),SL(1)
      DIMENSION GIJKL(1),GNKL(1),GNM(1)
      DIMENSION DIJ(1),DKL(1),DIJSI(1),DIJSJ(1),DKLSK(1),DKLSL(1)
      DIMENSION FI(1),FJ(1),FK(1),FL(1)
      DIMENSION SII(1),SJJ(1),SKK(1),SLL(1)
      DIMENSION SIJ(1),SIK(1),SIL(1),SJK(1),SJL(1),SKL(1)
      DIMENSION B00(1),B01(1),B10(1),C00(1),D00(1),F00(1)
      DIMENSION AAI(1),AAJ(1),BBK(1),BBL(1)
      DIMENSION ABV(5,1),CV(18,1),RWV(2,1)
      DIMENSION DAB(1)
      PARAMETER(PI252=34.986836655250D+00, ONE=1.0D+00)
C
      Q4=PI252*QQ4
C
      NIMAX=LIT + IDER
      NJMAX=LJT + JDER
      NKMAX=LKT + KDER
      NLMAX=LLT + LDER
      NMAX=LIT+LJT-1 + MIN0(IDER+JDER,NDER)
      MMAX=LKT+LLT-1 + MIN0(KDER+LDER,NDER)
      NMAXS=NMAX.EQ.1
      NMAXP=NMAX.LE.2
      MMAXS=MMAX.EQ.1
      MMAXP=MMAX.LE.2
C
      MAXG=MAXXYZ/NROOTS
C
C     ----- PAIR OF K,L PRIMITIVES -----
C
      FIRST=.TRUE.
      NG=0
      KLG=0
  100 KLG=KLG+1
      IF(KLG.GT.NKL) GO TO 300
      DB=DCHRKL( 1,KLG+NKL0)
      BB=DCHRKL( 2,KLG+NKL0)
      XB=DCHRKL( 3,KLG+NKL0)
      YB=DCHRKL( 4,KLG+NKL0)
      ZB=DCHRKL( 5,KLG+NKL0)
      XD=DCHRKL( 6,KLG+NKL0)
      YD=DCHRKL( 7,KLG+NKL0)
      ZD=DCHRKL( 8,KLG+NKL0)
      DXKL=DCHRKL( 9,KLG+NKL0)
      DYKL=DCHRKL(10,KLG+NKL0)
      DZKL=DCHRKL(11,KLG+NKL0)
      Q4DB=Q4*DB
C
C     ----- PAIR OF I,J PRIMITIVES -----
C
      IJG=0
  200 IJG=IJG+1
      IF(IJG.GT.NIJ) GO TO 100
      DA=DCHRG( 1,IJG+NIJ0)
      AA=DCHRG( 2,IJG+NIJ0)
      XA=DCHRG( 3,IJG+NIJ0)
      YA=DCHRG( 4,IJG+NIJ0)
      ZA=DCHRG( 5,IJG+NIJ0)
      AANDB1=ONE/(AA+BB)
      Q4DBDA=Q4DB*DA
      DUM   =Q4DBDA*Q4DBDA*AANDB1
      IF(DUM.LE.DTOL) GO TO 200
      Q4DBDA=Q4DBDA* SQRT(AANDB1)
      IF( ABS(Q4DBDA*DABMAX).LT.DABCUT) GO TO 200
      RHO   =AA*BB*AANDB1
      IF(LRINT) THEN
         RHO0 = RHO
         RHO  = RHO0*(EMU2/(RHO0+EMU2))
      ENDIF
      XX=RHO*((XA-XB)**2+(YA-YB)**2+(ZA-ZB)**2)
C
      NG=NG+1
      ABV(1,NG)=AA
      ABV(2,NG)=BB
      ABV(3,NG)=RHO
      ABV(4,NG)=Q4DBDA
      ABV(5,NG)=XX
C
      XC=DCHRG( 6,IJG+NIJ0)
      YC=DCHRG( 7,IJG+NIJ0)
      ZC=DCHRG( 8,IJG+NIJ0)
      DXIJ=DCHRG( 9,IJG+NIJ0)
      DYIJ=DCHRG(10,IJG+NIJ0)
      DZIJ=DCHRG(11,IJG+NIJ0)
C
      AAI(NG)=DCHRG(12,IJG+NIJ0)
      AAJ(NG)=DCHRG(13,IJG+NIJ0)
      BBK(NG)=DCHRKL(12,KLG+NKL0)
      BBL(NG)=DCHRKL(13,KLG+NKL0)
C
      IF(MMAXS) GO TO 210
      CV( 1,NG)=AA*(XA-XD)
      CV( 2,NG)=BB*(XB-XD)
      CV( 3,NG)=AA*(YA-YD)
      CV( 4,NG)=BB*(YB-YD)
      CV( 5,NG)=AA*(ZA-ZD)
      CV( 6,NG)=BB*(ZB-ZD)
  210 IF(NMAXS) GO TO 220
      CV( 7,NG)=AA*(XA-XC)
      CV( 8,NG)=BB*(XB-XC)
      CV( 9,NG)=AA*(YA-YC)
      CV(10,NG)=BB*(YB-YC)
      CV(11,NG)=AA*(ZA-ZC)
      CV(12,NG)=BB*(ZB-ZC)
  220 CONTINUE
      CV(13,NG)=DXIJ
      CV(14,NG)=DYIJ
      CV(15,NG)=DZIJ
      CV(16,NG)=DXKL
      CV(17,NG)=DYKL
      CV(18,NG)=DZKL
      IF(SPI) DIJSI(NG)=DCHRG(14,IJG+NIJ0)
      IF(SPJ) DIJSJ(NG)=DCHRG(15,IJG+NIJ0)
      IF(SPK) DKLSK(NG)=DCHRKL(14,KLG+NKL0)
      IF(SPL) DKLSL(NG)=DCHRKL(15,KLG+NKL0)
C
      IF(NG.LT.MAXG) GO TO 200
      LAST=.FALSE.
      GO TO 310
C
  300 CONTINUE
      LAST=.TRUE.
  310 CONTINUE
      NUMG=NG
      IF(NUMG.EQ.0) GO TO 1000
C
      IF(NROOTS.EQ.1) GO TO 480
      IF (SPI) THEN
          DO 410 IROOT=2,NROOTS
          DO 410 IG=1,NUMG
              DIJSI(IG+NUMG*(IROOT-1))=DIJSI(IG)
  410     CONTINUE
      ENDIF
      IF (SPJ) THEN
         DO 430 IROOT=2,NROOTS
         DO 430 IG=1,NUMG
            DIJSJ(IG+NUMG*(IROOT-1))=DIJSJ(IG)
  430    CONTINUE
      ENDIF
      IF (SPK) THEN
         DO 450 IROOT=2,NROOTS
         DO 450 IG=1,NUMG
            DKLSK(IG+NUMG*(IROOT-1))=DKLSK(IG)
  450    CONTINUE
      ENDIF
      IF (SPL) THEN
         DO 470 IROOT=2,NROOTS
         DO 470 IG=1,NUMG
            DKLSL(IG+NUMG*(IROOT-1))=DKLSL(IG)
  470    CONTINUE
      ENDIF
C
  480 IF(SKIPI) GO TO 520
      DO 510 IRXYZ=2,NROOTS*3
      DO 510 IG=1,NUMG
      AAI(IG+NUMG*(IRXYZ-1))=AAI(IG)
  510 CONTINUE
  520 IF(SKIPJ) GO TO 540
      DO 530 IRXYZ=2,NROOTS*3
      DO 530 IG=1,NUMG
      AAJ(IG+NUMG*(IRXYZ-1))=AAJ(IG)
  530 CONTINUE
  540 IF(SKIPK) GO TO 560
      DO 550 IRXYZ=2,NROOTS*3
      DO 550 IG=1,NUMG
      BBK(IG+NUMG*(IRXYZ-1))=BBK(IG)
  550 CONTINUE
  560 IF(SKIPL) GO TO 580
      DO 570 IRXYZ=2,NROOTS*3
      DO 570 IG=1,NUMG
      BBL(IG+NUMG*(IRXYZ-1))=BBL(IG)
  570 CONTINUE
  580 CONTINUE
C
C     ----- COMPUTE ROOTS AND WEIGHTS FOR QUADRATURE -----
C
      CALL JKWRYS(RWV,ABV,NUMG)
C
C     ----- COMPUTE COEFFICIENTS FOR RECURSION FORMULAE -----
C
      CALL JKBCDF(B00,B01,B10,C00,D00,F00,DIJ,DKL,
     1            ABV,CV,RWV,NUMG,NROOTS)
C
C     ----- COMPUTE -X- , -Y- , -Z- INTEGRALS ( 2 CENTERS, 2-D ) -----
C
      IF(NUMG*NROOTS*3.LT.MINVEC) THEN
         CALL JKGNMS(GNM,NUMG*NROOTS*3,NMAX,MMAX,
     *               B00,B01,B10,C00,D00,F00)
      ELSE
         CALL JKGNMV(GNM,NUMG*NROOTS*3,NMAX,MMAX,
     *               B00,B01,B10,C00,D00,F00)
      END IF
C
C     ----- COMPUTE -X- , -Y- , -Z- INTEGRALS ( 4 CENTERS, 2-D ) -----
C
      IF(NUMG*NROOTS*3.LT.MINVEC) THEN
         CALL JKXYZS(GIJKL,GIJKL,GNKL,GNKL,GNKL,GNM,GNM,
     *               NUMG*NROOTS*3,NMAX,MMAX,NIMAX,NJMAX,NKMAX,NLMAX,
     *               DIJ,DKL,EXPNDI,EXPNDK)
      ELSE
         CALL JKXYZV(GIJKL,GIJKL,GNKL,GNKL,GNKL,GNM,GNM,
     *               NUMG*NROOTS*3,NMAX,MMAX,NIMAX,NJMAX,NKMAX,NLMAX,
     *               DIJ,DKL,EXPNDI,EXPNDK)
      END IF
C
C     ----- COMPUTE -X- , -Y- , -Z- INTEGRALS FOR DERIVATIVES -----
C
      IF(NUMG*NROOTS*3.LT.MINVEC) THEN
         CALL JDXYZS(GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,
     *               NUMG*NROOTS*3,NIMAX,NJMAX,NKMAX,NLMAX,
     *               LIT,LJT,LKT,LLT,AAI,AAJ,BBK,BBL,FI,FJ,FK,FL,
     *               SII,SJJ,SKK,SLL,SIJ,SIK,SIL,SJK,SJL,SKL)
      ELSE
         CALL JDXYZV(GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,
     *               NUMG*NROOTS*3,NIMAX,NJMAX,NKMAX,NLMAX,
     *               LIT,LJT,LKT,LLT,AAI,AAJ,BBK,BBL,FI,FJ,FK,FL,
     *               SII,SJJ,SKK,SLL,SIJ,SIK,SIL,SJK,SJL,SKL)
      END IF
C
C     ----- ZERO OUT FIRST TIME AROUND -----
C
      IF(FIRST) THEN
         CALL JKDZER(GINT,FINT,SINT,IJKLG)
         FIRST=.FALSE.
      ENDIF
C
C     ----- COMPUTE DERIVATIVE INTEGRALS -----
C
      IF(NUMG*NROOTS.LT.MINVEC) THEN
         CALL DSPDFS(NUMG,NROOTS,IJKLG,GINT,FINT,SINT,GIJKL,
     *               FI,FJ,FK,FL,SII,SJJ,SKK,SLL,SIJ,SIK,SIL,SJK,
     *               SJL,SKL,XY,XZ,YZ,X,Y,Z,SJ,SK,SL,
     *               DIJSI,DIJSJ,DKLSK,DKLSL,DAB)
      ELSE
         CALL DSPDFV(NUMG,NROOTS,IJKLG,GINT,FINT,SINT,GIJKL,
     *               FI,FJ,FK,FL,SII,SJJ,SKK,SLL,SIJ,SIK,SIL,SJK,
     *               SJL,SKL,XY,XZ,YZ,X,Y,Z,SJ,SK,SL,
     *               DIJSI,DIJSJ,DKLSK,DKLSL,DAB)
      END IF
C
      IF(LAST) GO TO 1000
      NG=0
      GO TO 200
 1000 IF(NUMG.EQ.0.AND.FIRST) RETURN
C
C     ----- PROCESS DERIVATIVE INTEGRALS -----
C
      CALL JKDINV_NEO
C
      IF(OUT) CALL JKDOUT(GINT,FINT,SINT,IJKLG,DAB)
      RETURN
      END
C*MODULE NEOG2C  *DECK JKDINV_NEO
      SUBROUTINE JKDINV_NEO
C
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      PARAMETER (MXATM=2000)
C
      LOGICAL OUT,DBG
      LOGICAL SKIPI,SKIPJ,SKIPK,SKIPL
      COMMON /DSHLT / RTOL,DTOL,VTOL1,VTOL2,VTOLS,OUT,DBG
CSPW  COMMON /GRAD  / DE(3,MXATM)
      COMMON /GRDNEO/ DE(3,MXATM)
      COMMON /IOFILE/ IR,IW,IP,IJK,IPK,IDAF,NAV,IODA(950)
      COMMON/DERINV/INVTYP
      COMMON/DERSHL/FD(3,4),SD(78)
      COMMON/DERPAR/IDER,JDER,KDER,LDER,NDER
      COMMON/DERSKP/IIAT,JJAT,KKAT,LLAT,SKIPI,SKIPJ,SKIPK,SKIPL
      DIMENSION KAT(4)
      EQUIVALENCE (KAT(1),IIAT)
C
      IF(NDER.EQ.0) RETURN
C
C     ----- TRANSLATIONAL INVARIANCE FOR GRADIENT ELEMENTS -----
C
      IF (INVTYP.EQ.2) THEN
        DO 210 IXYZ=1,3
  210     FD(IXYZ,1)=- FD(IXYZ,4)
      ELSE IF (INVTYP.EQ.3) THEN
        DO 310 IXYZ=1,3
  310     FD(IXYZ,1)=- FD(IXYZ,3)
      ELSE IF (INVTYP.EQ.4.OR.INVTYP.EQ.5) THEN
        DO 410 IXYZ=1,3
  410     FD(IXYZ,1)=-(FD(IXYZ,3)+FD(IXYZ,4))
      ELSE IF (INVTYP.EQ.6) THEN
        DO 610 IXYZ=1,3
  610     FD(IXYZ,1)=- FD(IXYZ,2)
      ELSE IF (INVTYP.EQ.7) THEN
        DO 710 IXYZ=1,3
  710     FD(IXYZ,1)=-(FD(IXYZ,2)+FD(IXYZ,4))
      ELSE IF (INVTYP.EQ.8) THEN
        DO 810 IXYZ=1,3
  810     FD(IXYZ,1)=-(FD(IXYZ,2)+FD(IXYZ,4))
      ELSE IF (INVTYP.EQ.9.OR.INVTYP.EQ.10) THEN
        DO 910 IXYZ=1,3
  910     FD(IXYZ,1)=-(FD(IXYZ,2)+FD(IXYZ,3))
      ELSE IF (INVTYP.EQ.11) THEN
        DO 1110 IXYZ=1,3
 1110     FD(IXYZ,2)=- FD(IXYZ,1)
      ELSE IF (INVTYP.EQ.12) THEN
        DO 1210 IXYZ=1,3
 1210     FD(IXYZ,2)=-(FD(IXYZ,1)+FD(IXYZ,4))
      ELSE IF (INVTYP.EQ.13) THEN
        DO 1310 IXYZ=1,3
 1310     FD(IXYZ,2)=-(FD(IXYZ,1)+FD(IXYZ,3))
      ELSE IF (INVTYP.EQ.14) THEN
        DO 1410 IXYZ=1,3
 1410     FD(IXYZ,3)=-(FD(IXYZ,1)+FD(IXYZ,2))
      ELSE IF (INVTYP.EQ.15) THEN
        DO 1510 IXYZ=1,3
 1510     FD(IXYZ,4)=-(FD(IXYZ,1)+FD(IXYZ,2)+FD(IXYZ,3))
      ENDIF
C
      DO 2010 I=1,4
        IAT=KAT(I)
        DO 2010 IXYZ=1,3
 2010     DE(IXYZ,IAT)=DE(IXYZ,IAT)+FD(IXYZ,I)
C
      IF(OUT) WRITE(IW,9999)(I,IIAT,DE(I,IIAT),I,JJAT,DE(I,JJAT),
     1                       I,KKAT,DE(I,KKAT),I,LLAT,DE(I,LLAT),I=1,3)
C
      RETURN
 9999 FORMAT(4(' DE(',I2,',',I3,') = ',E18.11))
      END
C*MODULE NEOG2C  *DECK JKDSPD
      SUBROUTINE JKDSPD_NEO(NIJ0,NKL,NKL0,DCHRG,GINT,FINT,SINT,IJKLG,
     1                  GIJKL,GNKL,GNM,XY,XZ,YZ,X,Y,Z,SJ,SK,SL,
     2                  B00,B01,B10,C00,D00,F00,DIJ,DKL,DIJSI,DIJSJ,
     3                  DKLSK,DKLSL,ABV,CV,RWV,AAI,AAJ,BBK,BBL,FI,FJ,
     4                  FK,FL,SII,SJJ,SKK,SLL,SIJ,SIK,SIL,SJK,SJL,SKL,
     5                  DAB,MAXXYZ,QQ4,MINVEC,
     6                  DABCUT, DABMAX)
C
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      LOGICAL SKIPI,SKIPJ,SKIPK,SKIPL
      LOGICAL SPI,SPJ,SPK,SPL,SPIJ,SPKL,SPIJKL
      LOGICAL NMAXS,NMAXP,MMAXS,MMAXP
      LOGICAL EXPNDI,EXPNDK
      LOGICAL FIRST
      LOGICAL LAST
      LOGICAL OUT,DBG
      LOGICAL LCFLAG,LRINT
      COMMON/DERPAR/IDER,JDER,KDER,LDER,NDER
      COMMON/DERSKP/IIAT,JJAT,KKAT,LLAT,SKIPI,SKIPJ,SKIPK,SKIPL
      COMMON /DSHLNO/ LIT,LJT,LKT,LLT,LOCI,LOCJ,LOCK,LOCL,
     *                MINI,MINJ,MINK,MINL,MAXI,MAXJ,MAXK,MAXL,
     *                NIJ,IJD,KLD,IJ,KL
      COMMON /DSHLT / RTOL,DTOL,VTOL1,VTOL2,VTOLS,OUT,DBG
      COMMON /NLRC  / LCFLAG,LRINT,EMU,EMU2,LRFILE
      COMMON /ROOT  / XX,U(13),W(13),NROOTS
      COMMON/SHLGNM/NMAXS,NMAXP,MMAXS,MMAXP
      COMMON/SHLTYP/SPI,SPJ,SPK,SPL,SPIJ,SPKL,SPIJKL
      COMMON/SHLXPN/EXPNDI,EXPNDK
      DIMENSION DCHRG(15,*)
      DIMENSION GINT(1),FINT(12,1),SINT(78,1),IJKLG(4,1)
      DIMENSION XY(1),XZ(1),YZ(1),X(1),Y(1),Z(1),SJ(1),SK(1),SL(1)
      DIMENSION GIJKL(1),GNKL(1),GNM(1)
      DIMENSION DIJ(1),DKL(1),DIJSI(1),DIJSJ(1),DKLSK(1),DKLSL(1)
      DIMENSION FI(1),FJ(1),FK(1),FL(1)
      DIMENSION SII(1),SJJ(1),SKK(1),SLL(1)
      DIMENSION SIJ(1),SIK(1),SIL(1),SJK(1),SJL(1),SKL(1)
      DIMENSION B00(1),B01(1),B10(1),C00(1),D00(1),F00(1)
      DIMENSION AAI(1),AAJ(1),BBK(1),BBL(1)
      DIMENSION ABV(5,1),CV(18,1),RWV(2,1)
      DIMENSION DAB(1)
      PARAMETER(PI252=34.986836655250D+00, ONE=1.0D+00)
C
      Q4=PI252*QQ4
C
      NIMAX=LIT + IDER
      NJMAX=LJT + JDER
      NKMAX=LKT + KDER
      NLMAX=LLT + LDER
      NMAX=LIT+LJT-1 + MIN0(IDER+JDER,NDER)
      MMAX=LKT+LLT-1 + MIN0(KDER+LDER,NDER)
      NMAXS=NMAX.EQ.1
      NMAXP=NMAX.LE.2
      MMAXS=MMAX.EQ.1
      MMAXP=MMAX.LE.2
C
      MAXG=MAXXYZ/NROOTS
C
C     ----- PAIR OF K,L PRIMITIVES -----
C
      FIRST=.TRUE.
      NG=0
      KLG=0
  100 KLG=KLG+1
      IF(KLG.GT.NKL) GO TO 300
      DB=DCHRG( 1,KLG+NKL0)
      BB=DCHRG( 2,KLG+NKL0)
      XB=DCHRG( 3,KLG+NKL0)
      YB=DCHRG( 4,KLG+NKL0)
      ZB=DCHRG( 5,KLG+NKL0)
      XD=DCHRG( 6,KLG+NKL0)
      YD=DCHRG( 7,KLG+NKL0)
      ZD=DCHRG( 8,KLG+NKL0)
      DXKL=DCHRG( 9,KLG+NKL0)
      DYKL=DCHRG(10,KLG+NKL0)
      DZKL=DCHRG(11,KLG+NKL0)
      Q4DB=Q4*DB
C
C     ----- PAIR OF I,J PRIMITIVES -----
C
      IJG=0
  200 IJG=IJG+1
      IF(IJG.GT.NIJ) GO TO 100
      DA=DCHRG( 1,IJG+NIJ0)
      AA=DCHRG( 2,IJG+NIJ0)
      XA=DCHRG( 3,IJG+NIJ0)
      YA=DCHRG( 4,IJG+NIJ0)
      ZA=DCHRG( 5,IJG+NIJ0)
      AANDB1=ONE/(AA+BB)
      Q4DBDA=Q4DB*DA
      DUM   =Q4DBDA*Q4DBDA*AANDB1
      IF(DUM.LE.DTOL) GO TO 200
      Q4DBDA=Q4DBDA* SQRT(AANDB1)
      IF( ABS(Q4DBDA*DABMAX).LT.DABCUT) GO TO 200
      RHO   =AA*BB*AANDB1
      IF(LRINT) THEN
         RHO0 = RHO
         RHO  = RHO0*(EMU2/(RHO0+EMU2))
      ENDIF
      XX=RHO*((XA-XB)**2+(YA-YB)**2+(ZA-ZB)**2)
C
      NG=NG+1
      ABV(1,NG)=AA
      ABV(2,NG)=BB
      ABV(3,NG)=RHO
      ABV(4,NG)=Q4DBDA
      ABV(5,NG)=XX
C
      XC=DCHRG( 6,IJG+NIJ0)
      YC=DCHRG( 7,IJG+NIJ0)
      ZC=DCHRG( 8,IJG+NIJ0)
      DXIJ=DCHRG( 9,IJG+NIJ0)
      DYIJ=DCHRG(10,IJG+NIJ0)
      DZIJ=DCHRG(11,IJG+NIJ0)
C
      AAI(NG)=DCHRG(12,IJG+NIJ0)
      AAJ(NG)=DCHRG(13,IJG+NIJ0)
      BBK(NG)=DCHRG(12,KLG+NKL0)
      BBL(NG)=DCHRG(13,KLG+NKL0)
C
      IF(MMAXS) GO TO 210
      CV( 1,NG)=AA*(XA-XD)
      CV( 2,NG)=BB*(XB-XD)
      CV( 3,NG)=AA*(YA-YD)
      CV( 4,NG)=BB*(YB-YD)
      CV( 5,NG)=AA*(ZA-ZD)
      CV( 6,NG)=BB*(ZB-ZD)
  210 IF(NMAXS) GO TO 220
      CV( 7,NG)=AA*(XA-XC)
      CV( 8,NG)=BB*(XB-XC)
      CV( 9,NG)=AA*(YA-YC)
      CV(10,NG)=BB*(YB-YC)
      CV(11,NG)=AA*(ZA-ZC)
      CV(12,NG)=BB*(ZB-ZC)
  220 CONTINUE
      CV(13,NG)=DXIJ
      CV(14,NG)=DYIJ
      CV(15,NG)=DZIJ
      CV(16,NG)=DXKL
      CV(17,NG)=DYKL
      CV(18,NG)=DZKL
      IF(SPI) DIJSI(NG)=DCHRG(14,IJG+NIJ0)
      IF(SPJ) DIJSJ(NG)=DCHRG(15,IJG+NIJ0)
      IF(SPK) DKLSK(NG)=DCHRG(14,KLG+NKL0)
      IF(SPL) DKLSL(NG)=DCHRG(15,KLG+NKL0)
C
      IF(NG.LT.MAXG) GO TO 200
      LAST=.FALSE.
      GO TO 310
C
  300 CONTINUE
      LAST=.TRUE.
  310 CONTINUE
      NUMG=NG
      IF(NUMG.EQ.0) GO TO 1000
C
      IF(NROOTS.EQ.1) GO TO 480
      IF (SPI) THEN
          DO 410 IROOT=2,NROOTS
          DO 410 IG=1,NUMG
              DIJSI(IG+NUMG*(IROOT-1))=DIJSI(IG)
  410     CONTINUE
      ENDIF
      IF (SPJ) THEN
         DO 430 IROOT=2,NROOTS
         DO 430 IG=1,NUMG
            DIJSJ(IG+NUMG*(IROOT-1))=DIJSJ(IG)
  430    CONTINUE
      ENDIF
      IF (SPK) THEN
         DO 450 IROOT=2,NROOTS
         DO 450 IG=1,NUMG
            DKLSK(IG+NUMG*(IROOT-1))=DKLSK(IG)
  450    CONTINUE
      ENDIF
      IF (SPL) THEN
         DO 470 IROOT=2,NROOTS
         DO 470 IG=1,NUMG
            DKLSL(IG+NUMG*(IROOT-1))=DKLSL(IG)
  470    CONTINUE
      ENDIF
C
  480 IF(SKIPI) GO TO 520
      DO 510 IRXYZ=2,NROOTS*3
      DO 510 IG=1,NUMG
      AAI(IG+NUMG*(IRXYZ-1))=AAI(IG)
  510 CONTINUE
  520 IF(SKIPJ) GO TO 540
      DO 530 IRXYZ=2,NROOTS*3
      DO 530 IG=1,NUMG
      AAJ(IG+NUMG*(IRXYZ-1))=AAJ(IG)
  530 CONTINUE
  540 IF(SKIPK) GO TO 560
      DO 550 IRXYZ=2,NROOTS*3
      DO 550 IG=1,NUMG
      BBK(IG+NUMG*(IRXYZ-1))=BBK(IG)
  550 CONTINUE
  560 IF(SKIPL) GO TO 580
      DO 570 IRXYZ=2,NROOTS*3
      DO 570 IG=1,NUMG
      BBL(IG+NUMG*(IRXYZ-1))=BBL(IG)
  570 CONTINUE
  580 CONTINUE
C
C     ----- COMPUTE ROOTS AND WEIGHTS FOR QUADRATURE -----
C
      CALL JKWRYS(RWV,ABV,NUMG)
C
C     ----- COMPUTE COEFFICIENTS FOR RECURSION FORMULAE -----
C
      CALL JKBCDF(B00,B01,B10,C00,D00,F00,DIJ,DKL,
     1            ABV,CV,RWV,NUMG,NROOTS)
C
C     ----- COMPUTE -X- , -Y- , -Z- INTEGRALS ( 2 CENTERS, 2-D ) -----
C
      IF(NUMG*NROOTS*3.LT.MINVEC) THEN
         CALL JKGNMS(GNM,NUMG*NROOTS*3,NMAX,MMAX,
     *               B00,B01,B10,C00,D00,F00)
      ELSE
         CALL JKGNMV(GNM,NUMG*NROOTS*3,NMAX,MMAX,
     *               B00,B01,B10,C00,D00,F00)
      END IF
C
C     ----- COMPUTE -X- , -Y- , -Z- INTEGRALS ( 4 CENTERS, 2-D ) -----
C
      IF(NUMG*NROOTS*3.LT.MINVEC) THEN
         CALL JKXYZS(GIJKL,GIJKL,GNKL,GNKL,GNKL,GNM,GNM,
     *               NUMG*NROOTS*3,NMAX,MMAX,NIMAX,NJMAX,NKMAX,NLMAX,
     *               DIJ,DKL,EXPNDI,EXPNDK)
      ELSE
         CALL JKXYZV(GIJKL,GIJKL,GNKL,GNKL,GNKL,GNM,GNM,
     *               NUMG*NROOTS*3,NMAX,MMAX,NIMAX,NJMAX,NKMAX,NLMAX,
     *               DIJ,DKL,EXPNDI,EXPNDK)
      END IF
C
C     ----- COMPUTE -X- , -Y- , -Z- INTEGRALS FOR DERIVATIVES -----
C
      IF(NUMG*NROOTS*3.LT.MINVEC) THEN
         CALL JDXYZS(GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,
     *               NUMG*NROOTS*3,NIMAX,NJMAX,NKMAX,NLMAX,
     *               LIT,LJT,LKT,LLT,AAI,AAJ,BBK,BBL,FI,FJ,FK,FL,
     *               SII,SJJ,SKK,SLL,SIJ,SIK,SIL,SJK,SJL,SKL)
      ELSE
         CALL JDXYZV(GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,GIJKL,
     *               NUMG*NROOTS*3,NIMAX,NJMAX,NKMAX,NLMAX,
     *               LIT,LJT,LKT,LLT,AAI,AAJ,BBK,BBL,FI,FJ,FK,FL,
     *               SII,SJJ,SKK,SLL,SIJ,SIK,SIL,SJK,SJL,SKL)
      END IF
C
C     ----- ZERO OUT FIRST TIME AROUND -----
C
      IF(FIRST) THEN
         CALL JKDZER(GINT,FINT,SINT,IJKLG)
         FIRST=.FALSE.
      ENDIF
C
C     ----- COMPUTE DERIVATIVE INTEGRALS -----
C
      IF(NUMG*NROOTS.LT.MINVEC) THEN
         CALL DSPDFS(NUMG,NROOTS,IJKLG,GINT,FINT,SINT,GIJKL,
     *               FI,FJ,FK,FL,SII,SJJ,SKK,SLL,SIJ,SIK,SIL,SJK,
     *               SJL,SKL,XY,XZ,YZ,X,Y,Z,SJ,SK,SL,
     *               DIJSI,DIJSJ,DKLSK,DKLSL,DAB)
      ELSE
         CALL DSPDFV(NUMG,NROOTS,IJKLG,GINT,FINT,SINT,GIJKL,
     *               FI,FJ,FK,FL,SII,SJJ,SKK,SLL,SIJ,SIK,SIL,SJK,
     *               SJL,SKL,XY,XZ,YZ,X,Y,Z,SJ,SK,SL,
     *               DIJSI,DIJSJ,DKLSK,DKLSL,DAB)
      END IF
C
      IF(LAST) GO TO 1000
      NG=0
      GO TO 200
 1000 IF(NUMG.EQ.0.AND.FIRST) RETURN
C
C     ----- PROCESS DERIVATIVE INTEGRALS -----
C
      CALL JKDINV_NEO
C
      IF(OUT) CALL JKDOUT(GINT,FINT,SINT,IJKLG,DAB)
      RETURN
      END
