C  4 MAR 08 - SS  - NEW FILE FOR DFT REPOSITORY FUNCTIONALS
C
C-----------------------------------------------------------------------
C--------FUNCTIONALS FROM THE DFT REPOSITORY ARE PROVIDED BELOW --------
C-----------------------------------------------------------------------
C     CITATION:
C
C     FUNCTIONALS WERE OBTAINED FROM THE DENSITY FUNCTIONAL REPOSITORY
C     AS DEVELOPED AND DISTRIBUTED BY THE QUANTUM CHEMISTRY GROUP,
C     CCLRC DARESBURY LABORATORY, DARESBURY, CHESHIRE, WA4 4AD
C     UNITED KINGDOM. CONTACT HUUB VAN DAM (H.J.J.VANDAM@DL.AC.UK) OR
C     PAUL SHERWOOD FOR FURTHER INFORMATION.
C
C     COPYRIGHT:
C
C     USERS MAY INCORPORATE THE SOURCE CODE INTO SOFTWARE PACKAGES AND
C     REDISTRIBUTE THE SOURCE CODE PROVIDED THE SOURCE CODE IS NOT
C     CHANGED IN ANYWAY AND IS PROPERLY CITED IN ANY DOCUMENTATION OR
C     PUBLICATION RELATED TO ITS USE.
C
C     ACKNOWLEDGEMENT:
C
C     THE SOURCE CODE WAS GENERATED USING MAPLE 8 THROUGH A MODIFIED
C     VERSION OF THE DFAUTO SCRIPT PUBLISHED IN:
C
C        R. STRANGE, F.R. MANBY, P.J. KNOWLES
C        AUTOMATIC CODE GENERATION IN DENSITY FUNCTIONAL THEORY
C        COMP. PHYS. COMM. 136 (2001) 310-318.
C
C*MODULE DFTXCB  *DECK UKS_X_PW91
      SUBROUTINE UKS_X_PW91
     & (IDERIV,NPT,RHOA1,RHOB1,SIGMAAA1,SIGMABB1,
     &  ZK,VRHOA,VRHOB,VSIGMAAA,VSIGMABB,VSIGMAAB,
     &  V2RHOA2,V2RHOB2,V2RHOAB,
     &  V2RHOASIGMAAA,V2RHOASIGMAAB,V2RHOASIGMABB,
     &  V2RHOBSIGMABB,V2RHOBSIGMAAB,V2RHOBSIGMAAA,
     &  V2SIGMAAA2,V2SIGMAAAAB,V2SIGMAAABB,
     &  V2SIGMAAB2,V2SIGMAABBB,V2SIGMABB2)
C
C     J.P. PERDEW, J.A. CHEVARY, S.H. VOSKO, K.A. JACKSON,
C     M.R. PEDERSON, D.J. SINGH, C. FIOLHAIS
C     ATOMS, MOLECULES, SOLIDS AND SURFACES:
C     APPLICATIONS OF THE GENERALIZED GRADIENT APPROXIMATION
C     FOR EXCHANGE AND CORRELATION
C     PHYS. REV. B 46 (1992) 6671--6687
C
      IMPLICIT DOUBLE PRECISION(A-H,O-Z)
      INTEGER IDERIV,NPT
      DOUBLE PRECISION RHOA1(NPT),RHOB1(NPT)
      DOUBLE PRECISION SIGMAAA1(NPT),SIGMABB1(NPT)
      DOUBLE PRECISION ZK(NPT),VRHOA(NPT),VRHOB(NPT)
      DOUBLE PRECISION VSIGMAAA(NPT),VSIGMABB(NPT),VSIGMAAB(NPT)
      DOUBLE PRECISION V2RHOA2(NPT),V2RHOB2(NPT),V2RHOAB(NPT)
      DOUBLE PRECISION V2RHOASIGMAAA(NPT),V2RHOASIGMAAB(NPT)
      DOUBLE PRECISION V2RHOASIGMABB(NPT),V2RHOBSIGMABB(NPT)
      DOUBLE PRECISION V2RHOBSIGMAAB(NPT),V2RHOBSIGMAAA(NPT)
      DOUBLE PRECISION V2SIGMAAA2(NPT),V2SIGMAAAAB(NPT),V2SIGMAAABB(NPT)
      DOUBLE PRECISION V2SIGMAAB2(NPT),V2SIGMAABBB(NPT),V2SIGMABB2(NPT)
      PARAMETER(TOL=1.0D-20)
C
      IF (IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      T2 = RHOB**(1.D0/3.D0)
      T3 = T2*RHOB
      T4 = SQRT(SIGMABB)
      T6 = T4/T3
      T8 = LOG(0.1000005877780776D1*T6+SQRT(1+0.10000117555961D1*T6**2))
      T10 = 0.2520026100493014D-1*T6*T8
      T11 = RHOB**2
      T12 = T2**2
      T14 = 1/T12/T11
      T17 = EXP(-0.1645530784602056D1*SIGMABB*T14)
      T25 = SIGMABB**2
      T26 = T11**2
      ZK(I) = -0.9305257363491D0*T3*(1.D0+T10+0.1645530784602056D-1*
     #(0.2743D0-0.1508D0*T17)*SIGMABB*T14)/(1.D0+T10
     #+0.1083108625229223D-5*T25/T2/T26/RHOB)
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      T2 = RHOA**(1.D0/3.D0)
      T3 = T2*RHOA
      T4 = SQRT(SIGMAAA)
      T6 = T4/T3
      T8 = LOG(0.1000005877780776D1*T6+SQRT(1+0.10000117555961D1*T6**2))
      T10 = 0.2520026100493014D-1*T6*T8
      T11 = RHOA**2
      T12 = T2**2
      T14 = 1/T12/T11
      T17 = EXP(-0.1645530784602056D1*SIGMAAA*T14)
      T25 = SIGMAAA**2
      T26 = T11**2
      ZK(I) = -0.9305257363491D0*T3*(1.D0+T10+0.1645530784602056D-1*
     #(0.2743D0-0.1508D0*T17)*SIGMAAA*T14)/(1.D0+T10
     #+0.1083108625229223D-5*T25/T2/T26/RHOA)
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      T4 = RHOA**(1.D0/3.D0)
      T5 = T4*RHOA
      T6 = SQRT(SIGMAAA)
      T8 = T6/T5
      T10 = LOG(0.1000005877780776D1*T8+SQRT(1+0.10000117555961D1*T8
     #**2))
      T12 = 0.2520026100493014D-1*T8*T10
      T13 = RHOA**2
      T14 = T4**2
      T16 = 1/T14/T13
      T19 = EXP(-0.1645530784602056D1*SIGMAAA*T16)
      T27 = SIGMAAA**2
      T28 = T13**2
      T38 = RHOB**(1.D0/3.D0)
      T39 = T38*RHOB
      T40 = SQRT(SIGMABB)
      T42 = T40/T39
      T44 = LOG(0.1000005877780776D1*T42+SQRT(1+0.10000117555961D1
     #*T42**2))
      T46 = 0.2520026100493014D-1*T42*T44
      T47 = RHOB**2
      T48 = T38**2
      T50 = 1/T48/T47
      T53 = EXP(-0.1645530784602056D1*SIGMABB*T50)
      T61 = SIGMABB**2
      T62 = T47**2
      ZK(I) = -0.9305257363491D0*T5*(1.D0+T12+0.1645530784602056D-1*
     #(0.2743D0-0.1508D0*T19)*SIGMAAA*T16)/(1.D0+T12
     #+0.1083108625229223D-5*T27/T4/T28/RHOA)-0.9305257363491D0*T39*
     #(1.D0+T46+0.1645530784602056D-1*(0.2743D0-0.1508D0*T53)*SIGMABB
     #*T50)/(1.D0+T46+0.1083108625229223D-5*T61/T38/T62/RHOB)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      T2 = RHOB**(1.D0/3.D0)
      T3 = T2*RHOB
      T4 = SQRT(SIGMABB)
      T5 = 1/T3
      T6 = T4*T5
      T8 = LOG(0.1000005877780776D1*T6+SQRT(1+0.10000117555961D1*T6**2))
      T10 = 0.2520026100493014D-1*T6*T8
      T11 = RHOB**2
      T12 = T2**2
      T14 = 1/T12/T11
      T15 = SIGMABB*T14
      T17 = EXP(-0.1645530784602056D1*T15)
      T19 = 0.2743D0-0.1508D0*T17
      T20 = T19*SIGMABB
      T23 = 1.D0+T10+0.1645530784602056D-1*T20*T14
      T24 = T3*T23
      T25 = SIGMABB**2
      T26 = T11**2
      T29 = 1/T2/T26/RHOB
      T32 = 1.D0+T10+0.1083108625229223D-5*T25*T29
      T33 = 1/T32
      ZK(I) = -0.9305257363491D0*T24*T33
      VRHOA(I) = 0.D0
      T43 = 0.3360034800657352D-1*T4/T2/T11*T8
      T46 = 1/T12/T11/RHOB
      T50 = SQRT(1.D0+0.10000117555961D1*T15)
      T51 = 1/T50
      T53 = 0.3360054550205309D-1*SIGMABB*T46*T51
      T57 = T25/T2/T26/T11
      T66 = T32**2
      T67 = 1/T66
      VRHOB(I) = -0.12407009817988D1*T2*T23*T33-0.9305257363491D0*T3*(
     #-T43-T53-0.1088885204563779D-1*T57*T17-0.4388082092272149D-1*T20
     #*T46)*T33+0.9305257363491D0*T24*T67*(-T43-T53
     #-0.5776579334555855D-5*T57)
      VSIGMAAA(I) = 0.D0
      VSIGMAAB(I) = 0.D0
      T76 = 0.1260013050246507D-1/T4*T5*T8
      T78 = 0.1260020456326991D-1*T14*T51
      VSIGMABB(I) = -0.9305257363491D0*T3*(T76+T78
     #+0.408331951711417D-2*T29*T17*SIGMABB+0.1645530784602056D-1*T19
     #*T14)*T33+0.9305257363491D0*T24*T67*(T76+T78
     #+0.2166217250458446D-5*SIGMABB*T29)
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      T2 = RHOA**(1.D0/3.D0)
      T3 = T2*RHOA
      T4 = SQRT(SIGMAAA)
      T5 = 1/T3
      T6 = T4*T5
      T8 = LOG(0.1000005877780776D1*T6+SQRT(1+0.10000117555961D1*T6**2))
      T10 = 0.2520026100493014D-1*T6*T8
      T11 = RHOA**2
      T12 = T2**2
      T14 = 1/T12/T11
      T15 = SIGMAAA*T14
      T17 = EXP(-0.1645530784602056D1*T15)
      T19 = 0.2743D0-0.1508D0*T17
      T20 = T19*SIGMAAA
      T23 = 1.D0+T10+0.1645530784602056D-1*T20*T14
      T24 = T3*T23
      T25 = SIGMAAA**2
      T26 = T11**2
      T29 = 1/T2/T26/RHOA
      T32 = 1.D0+T10+0.1083108625229223D-5*T25*T29
      T33 = 1/T32
      ZK(I) = -0.9305257363491D0*T24*T33
      T43 = 0.3360034800657352D-1*T4/T2/T11*T8
      T46 = 1/T12/T11/RHOA
      T50 = SQRT(1.D0+0.10000117555961D1*T15)
      T51 = 1/T50
      T53 = 0.3360054550205309D-1*SIGMAAA*T46*T51
      T57 = T25/T2/T26/T11
      T66 = T32**2
      T67 = 1/T66
      VRHOA(I) = -0.12407009817988D1*T2*T23*T33-0.9305257363491D0*T3*(
     #-T43-T53-0.1088885204563779D-1*T57*T17-0.4388082092272149D-1*T20
     #*T46)*T33+0.9305257363491D0*T24*T67*(-T43-T53
     #-0.5776579334555855D-5*T57)
      VRHOB(I) = 0.D0
      T76 = 0.1260013050246507D-1/T4*T5*T8
      T78 = 0.1260020456326991D-1*T14*T51
      VSIGMAAA(I) = -0.9305257363491D0*T3*(T76+T78
     #+0.408331951711417D-2*T29*T17*SIGMAAA+0.1645530784602056D-1*T19
     #*T14)*T33+0.9305257363491D0*T24*T67*(T76+T78
     #+0.2166217250458446D-5*SIGMAAA*T29)
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = 0.D0
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      T4 = RHOA**(1.D0/3.D0)
      T5 = T4*RHOA
      T6 = SQRT(SIGMAAA)
      T7 = 1/T5
      T8 = T6*T7
      T10 = LOG(0.1000005877780776D1*T8+SQRT(1+0.10000117555961D1*T8
     #**2))
      T12 = 0.2520026100493014D-1*T8*T10
      T13 = RHOA**2
      T14 = T4**2
      T16 = 1/T14/T13
      T17 = SIGMAAA*T16
      T19 = EXP(-0.1645530784602056D1*T17)
      T21 = 0.2743D0-0.1508D0*T19
      T22 = T21*SIGMAAA
      T25 = 1.D0+T12+0.1645530784602056D-1*T22*T16
      T26 = T5*T25
      T27 = SIGMAAA**2
      T28 = T13**2
      T31 = 1/T4/T28/RHOA
      T34 = 1.D0+T12+0.1083108625229223D-5*T27*T31
      T35 = 1/T34
      T38 = RHOB**(1.D0/3.D0)
      T39 = T38*RHOB
      T40 = SQRT(SIGMABB)
      T41 = 1/T39
      T42 = T40*T41
      T44 = LOG(0.1000005877780776D1*T42+SQRT(1+0.10000117555961D1
     #*T42**2))
      T46 = 0.2520026100493014D-1*T42*T44
      T47 = RHOB**2
      T48 = T38**2
      T50 = 1/T48/T47
      T51 = SIGMABB*T50
      T53 = EXP(-0.1645530784602056D1*T51)
      T55 = 0.2743D0-0.1508D0*T53
      T56 = T55*SIGMABB
      T59 = 1.D0+T46+0.1645530784602056D-1*T56*T50
      T60 = T39*T59
      T61 = SIGMABB**2
      T62 = T47**2
      T65 = 1/T38/T62/RHOB
      T68 = 1.D0+T46+0.1083108625229223D-5*T61*T65
      T69 = 1/T68
      ZK(I) = -0.9305257363491D0*T26*T35-0.9305257363491D0*T60*T69
      T79 = 0.3360034800657352D-1*T6/T4/T13*T10
      T82 = 1/T14/T13/RHOA
      T86 = SQRT(1.D0+0.10000117555961D1*T17)
      T87 = 1/T86
      T89 = 0.3360054550205309D-1*SIGMAAA*T82*T87
      T93 = T27/T4/T28/T13
      T102 = T34**2
      T103 = 1/T102
      VRHOA(I) = -0.12407009817988D1*T4*T25*T35-0.9305257363491D0*T5*(
     #-T79-T89-0.1088885204563779D-1*T93*T19-0.4388082092272149D-1*T22
     #*T82)*T35+0.9305257363491D0*T26*T103*(-T79-T89
     #-0.5776579334555855D-5*T93)
      T116 = 0.3360034800657352D-1*T40/T38/T47*T44
      T119 = 1/T48/T47/RHOB
      T123 = SQRT(1.D0+0.10000117555961D1*T51)
      T124 = 1/T123
      T126 = 0.3360054550205309D-1*SIGMABB*T119*T124
      T130 = T61/T38/T62/T47
      T139 = T68**2
      T140 = 1/T139
      VRHOB(I) = -0.12407009817988D1*T38*T59*T69-0.9305257363491D0*T39
     #*(-T116-T126-0.1088885204563779D-1*T130*T53
     #-0.4388082092272149D-1*T56*T119)*T69+0.9305257363491D0*T60*T140*
     #(-T116-T126-0.5776579334555855D-5*T130)
      T149 = 0.1260013050246507D-1/T6*T7*T10
      T151 = 0.1260020456326991D-1*T16*T87
      VSIGMAAA(I) = -0.9305257363491D0*T5*(T149+T151
     #+0.408331951711417D-2*T31*T19*SIGMAAA+0.1645530784602056D-1*T21
     #*T16)*T35+0.9305257363491D0*T26*T103*(T149+T151
     #+0.2166217250458446D-5*SIGMAAA*T31)
      VSIGMAAB(I) = 0.D0
      T170 = 0.1260013050246507D-1/T40*T41*T44
      T172 = 0.1260020456326991D-1*T50*T124
      VSIGMABB(I) = -0.9305257363491D0*T39*(T170+T172
     #+0.408331951711417D-2*T65*T53*SIGMABB+0.1645530784602056D-1*T55
     #*T50)*T69+0.9305257363491D0*T60*T140*(T170+T172
     #+0.2166217250458446D-5*SIGMABB*T65)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      VSIGMAAB(I) = 0.0D0
      VSIGMABB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      T2 = RHOB**(1.D0/3.D0)
      T3 = T2*RHOB
      T4 = SQRT(SIGMABB)
      T5 = 1/T3
      T6 = T4*T5
      T8 = LOG(0.1000005877780776D1*T6+SQRT(1+0.10000117555961D1*T6**2))
      T10 = 0.2520026100493014D-1*T6*T8
      T11 = RHOB**2
      T12 = T2**2
      T14 = 1/T12/T11
      T15 = SIGMABB*T14
      T17 = EXP(-0.1645530784602056D1*T15)
      T19 = 0.2743D0-0.1508D0*T17
      T20 = T19*SIGMABB
      T23 = 1.D0+T10+0.1645530784602056D-1*T20*T14
      T24 = T3*T23
      T25 = SIGMABB**2
      T26 = T11**2
      T29 = 1/T2/T26/RHOB
      T32 = 1.D0+T10+0.1083108625229223D-5*T25*T29
      T33 = 1/T32
      ZK(I) = -0.9305257363491D0*T24*T33
      VRHOA(I) = 0.D0
      T36 = T2*T23
      T43 = 0.3360034800657352D-1*T4/T2/T11*T8
      T44 = T11*RHOB
      T46 = 1/T12/T44
      T49 = 1.D0+0.10000117555961D1*T15
      T50 = SQRT(T49)
      T51 = 1/T50
      T53 = 0.3360054550205309D-1*SIGMABB*T46*T51
      T57 = T25/T2/T26/T11
      T62 = -T43-T53-0.1088885204563779D-1*T57*T17
     #-0.4388082092272149D-1*T20*T46
      T63 = T3*T62
      T66 = T32**2
      T67 = 1/T66
      T69 = -T43-T53-0.5776579334555855D-5*T57
      T70 = T67*T69
      VRHOB(I) = -0.12407009817988D1*T36*T33-0.9305257363491D0*T63*T33
     #+0.9305257363491D0*T24*T70
      VSIGMAAA(I) = 0.D0
      VSIGMAAB(I) = 0.D0
      T76 = 0.1260013050246507D-1/T4*T5*T8
      T78 = 0.1260020456326991D-1*T14*T51
      T79 = T29*T17
      T85 = T3*(T76+T78+0.408331951711417D-2*T79*SIGMABB
     #+0.1645530784602056D-1*T19*T14)
      T90 = T76+T78+0.2166217250458446D-5*SIGMABB*T29
      T91 = T67*T90
      VSIGMABB(I) = -0.9305257363491D0*T85*T33+0.9305257363491D0*T24*T91
      V2RHOA2(I) = 0.D0
      V2RHOAB(I) = 0.D0
      T107 = 0.7840081201533821D-1*T4/T2/T44*T8
      T109 = 1/T12/T26
      T112 = 0.1680027275102654D0*SIGMABB*T109*T51
      T116 = T25/T2/T26/T44
      T118 = 1/T50/T49
      T120 = 0.4480125399532632D-1*T116*T118
      T124 = T26**2
      T139 = 1/T66/T32
      T140 = T69**2
      V2RHOB2(I) = -0.4135669939329333D0/T12*T23*T33
     #-0.24814019635976D1*T2*T62*T33+0.24814019635976D1*T36*T70
     #-0.9305257363491D0*T3*(T107+T112-T120+0.9799966841074009D-1*T116
     #*T17-0.4778117666686413D-1*T25*SIGMABB/T124/T11*T17
     #+0.1608963433833121D0*T20*T109)*T33+0.18610514726982D1*T63*T70
     #-0.18610514726982D1*T24*T139*T140+0.9305257363491D0*T24*T67*
     #(T107+T112-T120+0.3658500245218708D-4*T116)
      V2SIGMAAA2(I) = 0.D0
      V2SIGMAAAAB(I) = 0.D0
      V2SIGMAAABB(I) = 0.D0
      V2SIGMAAB2(I) = 0.D0
      V2SIGMAABBB(I) = 0.D0
      T153 = 0.6300065251232535D-2/T4/SIGMABB*T5*T8
      T157 = 0.6300102281634954D-2/SIGMABB*T14*T51
      T159 = 0.6300176343092764D-2*T29*T118
      T171 = T90**2
      V2SIGMABB2(I) = -0.9305257363491D0*T3*(-T153+T157-T159
     #-0.6719227968777768D-2/T124*T17*SIGMABB+0.8166639034228341D-2
     #*T79)*T33+0.18610514726982D1*T85*T91-0.18610514726982D1*T24*T139
     #*T171+0.9305257363491D0*T24*T67*(-T153+T157-T159
     #+0.2166217250458446D-5*T29)
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      T2 = RHOA**(1.D0/3.D0)
      T3 = T2*RHOA
      T4 = SQRT(SIGMAAA)
      T5 = 1/T3
      T6 = T4*T5
      T8 = LOG(0.1000005877780776D1*T6+SQRT(1+0.10000117555961D1*T6**2))
      T10 = 0.2520026100493014D-1*T6*T8
      T11 = RHOA**2
      T12 = T2**2
      T14 = 1/T12/T11
      T15 = SIGMAAA*T14
      T17 = EXP(-0.1645530784602056D1*T15)
      T19 = 0.2743D0-0.1508D0*T17
      T20 = T19*SIGMAAA
      T23 = 1.D0+T10+0.1645530784602056D-1*T20*T14
      T24 = T3*T23
      T25 = SIGMAAA**2
      T26 = T11**2
      T29 = 1/T2/T26/RHOA
      T32 = 1.D0+T10+0.1083108625229223D-5*T25*T29
      T33 = 1/T32
      ZK(I) = -0.9305257363491D0*T24*T33
      T36 = T2*T23
      T43 = 0.3360034800657352D-1*T4/T2/T11*T8
      T44 = T11*RHOA
      T46 = 1/T12/T44
      T49 = 1.D0+0.10000117555961D1*T15
      T50 = SQRT(T49)
      T51 = 1/T50
      T53 = 0.3360054550205309D-1*SIGMAAA*T46*T51
      T57 = T25/T2/T26/T11
      T62 = -T43-T53-0.1088885204563779D-1*T57*T17
     #-0.4388082092272149D-1*T20*T46
      T63 = T3*T62
      T66 = T32**2
      T67 = 1/T66
      T69 = -T43-T53-0.5776579334555855D-5*T57
      T70 = T67*T69
      VRHOA(I) = -0.12407009817988D1*T36*T33-0.9305257363491D0*T63*T33
     #+0.9305257363491D0*T24*T70
      VRHOB(I) = 0.D0
      T76 = 0.1260013050246507D-1/T4*T5*T8
      T78 = 0.1260020456326991D-1*T14*T51
      T79 = T29*T17
      T85 = T3*(T76+T78+0.408331951711417D-2*T79*SIGMAAA
     #+0.1645530784602056D-1*T19*T14)
      T90 = T76+T78+0.2166217250458446D-5*SIGMAAA*T29
      T91 = T67*T90
      VSIGMAAA(I) = -0.9305257363491D0*T85*T33+0.9305257363491D0*T24*T91
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = 0.D0
      T107 = 0.7840081201533821D-1*T4/T2/T44*T8
      T109 = 1/T12/T26
      T112 = 0.1680027275102654D0*SIGMAAA*T109*T51
      T116 = T25/T2/T26/T44
      T118 = 1/T50/T49
      T120 = 0.4480125399532632D-1*T116*T118
      T124 = T26**2
      T139 = 1/T66/T32
      T140 = T69**2
      V2RHOA2(I) = -0.4135669939329333D0/T12*T23*T33
     #-0.24814019635976D1*T2*T62*T33+0.24814019635976D1*T36*T70
     #-0.9305257363491D0*T3*(T107+T112-T120+0.9799966841074009D-1*T116
     #*T17-0.4778117666686413D-1*T25*SIGMAAA/T124/T11*T17
     #+0.1608963433833121D0*T20*T109)*T33+0.18610514726982D1*T63*T70
     #-0.18610514726982D1*T24*T139*T140+0.9305257363491D0*T24*T67*
     #(T107+T112-T120+0.3658500245218708D-4*T116)
      V2RHOB2(I) = 0.D0
      V2RHOAB(I) = 0.D0
      T153 = 0.6300065251232535D-2/T4/SIGMAAA*T5*T8
      T157 = 0.6300102281634954D-2/SIGMAAA*T14*T51
      T159 = 0.6300176343092764D-2*T29*T118
      T171 = T90**2
      V2SIGMAAA2(I) = -0.9305257363491D0*T3*(-T153+T157-T159
     #-0.6719227968777768D-2/T124*T17*SIGMAAA+0.8166639034228341D-2
     #*T79)*T33+0.18610514726982D1*T85*T91-0.18610514726982D1*T24*T139
     #*T171+0.9305257363491D0*T24*T67*(-T153+T157-T159
     #+0.2166217250458446D-5*T29)
      V2SIGMAAAAB(I) = 0.D0
      V2SIGMAAABB(I) = 0.D0
      V2SIGMAAB2(I) = 0.D0
      V2SIGMAABBB(I) = 0.D0
      V2SIGMABB2(I) = 0.D0
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      T4 = RHOA**(1.D0/3.D0)
      T5 = T4*RHOA
      T6 = SQRT(SIGMAAA)
      T7 = 1/T5
      T8 = T6*T7
      T10 = LOG(0.1000005877780776D1*T8+SQRT(1+0.10000117555961D1*T8
     #**2))
      T12 = 0.2520026100493014D-1*T8*T10
      T13 = RHOA**2
      T14 = T4**2
      T16 = 1/T14/T13
      T17 = SIGMAAA*T16
      T19 = EXP(-0.1645530784602056D1*T17)
      T21 = 0.2743D0-0.1508D0*T19
      T22 = T21*SIGMAAA
      T25 = 1.D0+T12+0.1645530784602056D-1*T22*T16
      T26 = T5*T25
      T27 = SIGMAAA**2
      T28 = T13**2
      T31 = 1/T4/T28/RHOA
      T34 = 1.D0+T12+0.1083108625229223D-5*T27*T31
      T35 = 1/T34
      T38 = RHOB**(1.D0/3.D0)
      T39 = T38*RHOB
      T40 = SQRT(SIGMABB)
      T41 = 1/T39
      T42 = T40*T41
      T44 = LOG(0.1000005877780776D1*T42+SQRT(1+0.10000117555961D1
     #*T42**2))
      T46 = 0.2520026100493014D-1*T42*T44
      T47 = RHOB**2
      T48 = T38**2
      T50 = 1/T48/T47
      T51 = SIGMABB*T50
      T53 = EXP(-0.1645530784602056D1*T51)
      T55 = 0.2743D0-0.1508D0*T53
      T56 = T55*SIGMABB
      T59 = 1.D0+T46+0.1645530784602056D-1*T56*T50
      T60 = T39*T59
      T61 = SIGMABB**2
      T62 = T47**2
      T65 = 1/T38/T62/RHOB
      T68 = 1.D0+T46+0.1083108625229223D-5*T61*T65
      T69 = 1/T68
      ZK(I) = -0.9305257363491D0*T26*T35-0.9305257363491D0*T60*T69
      T72 = T4*T25
      T76 = 1/T4/T13
      T79 = 0.3360034800657352D-1*T6*T76*T10
      T80 = T13*RHOA
      T82 = 1/T14/T80
      T85 = 1.D0+0.10000117555961D1*T17
      T86 = SQRT(T85)
      T87 = 1/T86
      T89 = 0.3360054550205309D-1*SIGMAAA*T82*T87
      T92 = 1/T4/T28/T13
      T93 = T27*T92
      T98 = -T79-T89-0.1088885204563779D-1*T93*T19
     #-0.4388082092272149D-1*T22*T82
      T99 = T5*T98
      T102 = T34**2
      T103 = 1/T102
      T105 = -T79-T89-0.5776579334555855D-5*T93
      T106 = T103*T105
      VRHOA(I) = -0.12407009817988D1*T72*T35-0.9305257363491D0*T99*T35
     #+0.9305257363491D0*T26*T106
      T109 = T38*T59
      T113 = 1/T38/T47
      T116 = 0.3360034800657352D-1*T40*T113*T44
      T117 = T47*RHOB
      T119 = 1/T48/T117
      T122 = 1.D0+0.10000117555961D1*T51
      T123 = SQRT(T122)
      T124 = 1/T123
      T126 = 0.3360054550205309D-1*SIGMABB*T119*T124
      T129 = 1/T38/T62/T47
      T130 = T61*T129
      T135 = -T116-T126-0.1088885204563779D-1*T130*T53
     #-0.4388082092272149D-1*T56*T119
      T136 = T39*T135
      T139 = T68**2
      T140 = 1/T139
      T142 = -T116-T126-0.5776579334555855D-5*T130
      T143 = T140*T142
      VRHOB(I) = -0.12407009817988D1*T109*T69-0.9305257363491D0*T136
     #*T69+0.9305257363491D0*T60*T143
      T146 = 1/T6
      T149 = 0.1260013050246507D-1*T146*T7*T10
      T151 = 0.1260020456326991D-1*T16*T87
      T152 = T31*T19
      T157 = T149+T151+0.408331951711417D-2*T152*SIGMAAA
     #+0.1645530784602056D-1*T21*T16
      T158 = T5*T157
      T163 = T149+T151+0.2166217250458446D-5*SIGMAAA*T31
      T164 = T103*T163
      VSIGMAAA(I) = -0.9305257363491D0*T158*T35+0.9305257363491D0*T26
     #*T164
      VSIGMAAB(I) = 0.D0
      T167 = 1/T40
      T170 = 0.1260013050246507D-1*T167*T41*T44
      T172 = 0.1260020456326991D-1*T50*T124
      T173 = T65*T53
      T178 = T170+T172+0.408331951711417D-2*T173*SIGMABB
     #+0.1645530784602056D-1*T55*T50
      T179 = T39*T178
      T184 = T170+T172+0.2166217250458446D-5*SIGMABB*T65
      T185 = T140*T184
      VSIGMABB(I) = -0.9305257363491D0*T179*T69+0.9305257363491D0*T60
     #*T185
      T201 = 0.7840081201533821D-1*T6/T4/T80*T10
      T203 = 1/T14/T28
      T206 = 0.1680027275102654D0*SIGMAAA*T203*T87
      T210 = T27/T4/T28/T80
      T212 = 1/T86/T85
      T214 = 0.4480125399532632D-1*T210*T212
      T218 = T28**2
      T233 = 1/T102/T34
      T234 = T105**2
      V2RHOA2(I) = -0.4135669939329333D0/T14*T25*T35
     #-0.24814019635976D1*T4*T98*T35+0.24814019635976D1*T72*T106
     #-0.9305257363491D0*T5*(T201+T206-T214+0.9799966841074009D-1*T210
     #*T19-0.4778117666686413D-1*T27*SIGMAAA/T218/T13*T19
     #+0.1608963433833121D0*T22*T203)*T35+0.18610514726982D1*T99*T106
     #-0.18610514726982D1*T26*T233*T234+0.9305257363491D0*T26*T103*
     #(T201+T206-T214+0.3658500245218708D-4*T210)
      T256 = 0.7840081201533821D-1*T40/T38/T117*T44
      T258 = 1/T48/T62
      T261 = 0.1680027275102654D0*SIGMABB*T258*T124
      T265 = T61/T38/T62/T117
      T267 = 1/T123/T122
      T269 = 0.4480125399532632D-1*T265*T267
      T273 = T62**2
      T288 = 1/T139/T68
      T289 = T142**2
      V2RHOB2(I) = -0.4135669939329333D0/T48*T59*T69
     #-0.24814019635976D1*T38*T135*T69+0.24814019635976D1*T109*T143
     #-0.9305257363491D0*T39*(T256+T261-T269+0.9799966841074009D-1
     #*T265*T53-0.4778117666686413D-1*T61*SIGMABB/T273/T47*T53
     #+0.1608963433833121D0*T56*T258)*T69+0.18610514726982D1*T136*T143
     #-0.18610514726982D1*T60*T288*T289+0.9305257363491D0*T60*T140*
     #(T256+T261-T269+0.3658500245218708D-4*T265)
      V2RHOAB(I) = 0.D0
      T305 = 0.1680017400328676D-1*T146*T76*T10
      T307 = 0.5040081825307963D-1*T82*T87
      T308 = SIGMAAA*T92
      T310 = 0.1680047024824737D-1*T308*T212
      V2RHOASIGMAAA(I) = -0.12407009817988D1*T4*T157*T35
     #+0.12407009817988D1*T72*T164-0.9305257363491D0*T5*(-T305-T307
     #+T310-0.3266655613691336D-1*T92*T19*SIGMAAA
     #+0.1791794125007405D-1*T27/T218/RHOA*T19-0.4388082092272149D-1
     #*T21*T82)*T35+0.9305257363491D0*T99*T164+0.9305257363491D0*T158
     #*T106-0.18610514726982D1*T26*T233*T105*T163+0.9305257363491D0
     #*T26*T103*(-T305-T307+T310-0.1155315866911171D-4*T308)
      V2RHOASIGMAAB(I) = 0.D0
      V2RHOASIGMABB(I) = 0.D0
      V2RHOBSIGMAAA(I) = 0.D0
      V2RHOBSIGMAAB(I) = 0.D0
      T345 = 0.1680017400328676D-1*T167*T113*T44
      T347 = 0.5040081825307963D-1*T119*T124
      T348 = SIGMABB*T129
      T350 = 0.1680047024824737D-1*T348*T267
      V2RHOBSIGMABB(I) = -0.12407009817988D1*T38*T178*T69
     #+0.12407009817988D1*T109*T185-0.9305257363491D0*T39*(-T345-T347
     #+T350-0.3266655613691336D-1*T129*T53*SIGMABB
     #+0.1791794125007405D-1*T61/T273/RHOB*T53-0.4388082092272149D-1
     #*T55*T119)*T69+0.9305257363491D0*T136*T185+0.9305257363491D0
     #*T179*T143-0.18610514726982D1*T60*T288*T142*T184
     #+0.9305257363491D0*T60*T140*(-T345-T347+T350
     #-0.1155315866911171D-4*T348)
      T382 = 0.6300065251232535D-2/T6/SIGMAAA*T7*T10
      T386 = 0.6300102281634954D-2/SIGMAAA*T16*T87
      T388 = 0.6300176343092764D-2*T31*T212
      T400 = T163**2
      V2SIGMAAA2(I) = -0.9305257363491D0*T5*(-T382+T386-T388
     #-0.6719227968777768D-2/T218*T19*SIGMAAA+0.8166639034228341D-2
     #*T152)*T35+0.18610514726982D1*T158*T164-0.18610514726982D1*T26
     #*T233*T400+0.9305257363491D0*T26*T103*(-T382+T386-T388
     #+0.2166217250458446D-5*T31)
      V2SIGMAAAAB(I) = 0.D0
      V2SIGMAAABB(I) = 0.D0
      V2SIGMAAB2(I) = 0.D0
      V2SIGMAABBB(I) = 0.D0
      T413 = 0.6300065251232535D-2/T40/SIGMABB*T41*T44
      T417 = 0.6300102281634954D-2/SIGMABB*T50*T124
      T419 = 0.6300176343092764D-2*T65*T267
      T431 = T184**2
      V2SIGMABB2(I) = -0.9305257363491D0*T39*(-T413+T417-T419
     #-0.6719227968777768D-2/T273*T53*SIGMABB+0.8166639034228341D-2
     #*T173)*T69+0.18610514726982D1*T179*T185-0.18610514726982D1*T60
     #*T288*T431+0.9305257363491D0*T60*T140*(-T413+T417-T419
     #+0.2166217250458446D-5*T65)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      V2RHOB2(I) = 0.0D0
      V2RHOAB(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      VSIGMAAB(I) = 0.0D0
      VSIGMABB(I) = 0.0D0
      V2RHOASIGMAAA(I) = 0.0D0
      V2RHOASIGMAAB(I) = 0.0D0
      V2RHOASIGMABB(I) = 0.0D0
      V2RHOBSIGMAAA(I) = 0.0D0
      V2RHOBSIGMAAB(I) = 0.0D0
      V2RHOBSIGMABB(I) = 0.0D0
      V2SIGMAAA2(I) = 0.0D0
      V2SIGMAAB2(I) = 0.0D0
      V2SIGMABB2(I) = 0.0D0
      V2SIGMAAAAB(I) = 0.0D0
      V2SIGMAAABB(I) = 0.0D0
      V2SIGMAABBB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C*MODULE DFTXCB  *DECK RKS_X_PW91
      SUBROUTINE RKS_X_PW91
     & (IDERIV,NPT,RHOA1,SIGMAAA1,
     &  ZK,VRHOA,VSIGMAAA,
     &  V2RHOA2,V2RHOASIGMAAA,V2SIGMAAA2)
C
C     J.P. PERDEW, J.A. CHEVARY, S.H. VOSKO, K.A. JACKSON,
C     M.R. PEDERSON, D.J. SINGH, C. FIOLHAIS
C     ATOMS, MOLECULES, SOLIDS AND SURFACES:
C     APPLICATIONS OF THE GENERALIZED GRADIENT APPROXIMATION
C     FOR EXCHANGE AND CORRELATION
C     PHYS. REV. B 46 (1992) 6671--6687
C
      IMPLICIT DOUBLE PRECISION(A-H,O-Z)
      INTEGER IDERIV,NPT
      DOUBLE PRECISION RHOA1(NPT)
      DOUBLE PRECISION SIGMAAA1(NPT)
      DOUBLE PRECISION ZK(NPT),VRHOA(NPT),VSIGMAAA(NPT)
      DOUBLE PRECISION V2RHOA2(NPT),V2RHOASIGMAAA(NPT),V2SIGMAAA2(NPT)
      PARAMETER(TOL=1.0D-20)
C
      IF(IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.D0,SIGMAAA1(I))
      T2 = RHO**(1.D0/3.D0)
      T3 = T2*RHO
      T4 = SQRT(SIGMA)
      T6 = T4/T3
      T8 = LOG(0.1259928455434599D1*T6+SQRT(1+0.1587419712813814D1
     #*T6**2))
      T10 = 0.3175033930295641D-1*T6*T8
      T11 = RHO**2
      T12 = T2**2
      T14 = 1/T12/T11
      T17 = EXP(-0.261211729852336D1*SIGMA*T14)
      T25 = SIGMA**2
      T26 = T11**2
      ZK(I) = -0.7385587663820224D0*T3*(1.D0+T10+0.261211729852336D-1*
     #(0.2743D0-0.1508D0*T17)*SIGMA*T14)/(1.D0+T10
     #+0.272926271249799D-5*T25/T2/T26/RHO)
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.D0,SIGMAAA1(I))
      T2 = RHO**(1.D0/3.D0)
      T3 = T2*RHO
      T4 = SQRT(SIGMA)
      T5 = 1/T3
      T6 = T4*T5
      T8 = LOG(0.1259928455434599D1*T6+SQRT(1+0.1587419712813814D1
     #*T6**2))
      T10 = 0.3175033930295641D-1*T6*T8
      T11 = RHO**2
      T12 = T2**2
      T14 = 1/T12/T11
      T15 = SIGMA*T14
      T17 = EXP(-0.261211729852336D1*T15)
      T19 = 0.2743D0-0.1508D0*T17
      T20 = T19*SIGMA
      T23 = 1.D0+T10+0.261211729852336D-1*T20*T14
      T24 = T3*T23
      T25 = SIGMA**2
      T26 = T11**2
      T29 = 1/T2/T26/RHO
      T32 = 1.D0+T10+0.272926271249799D-5*T25*T29
      T33 = 1/T32
      ZK(I) = -0.7385587663820224D0*T24*T33
      T43 = 0.8466757147455043D-1*T4/T2/T11*T8
      T46 = 1/T12/T11/RHO
      T50 = SQRT(1.D0+0.1587419712813815D1*T15)
      T51 = 1/T50
      T53 = 0.1066750825533289D0*SIGMA*T46*T51
      T57 = T25/T2/T26/T11
      T66 = T32**2
      T67 = 1/T66
      VRHOA(I) = -0.9847450218426965D0*T2*T23*T33-0.3692793831910112D0
     #*T3*(-T43-T53-0.5487637560595959D-1*T57*T17-0.1393129225879125D0
     #*T20*T46)*T33+0.3692793831910112D0*T24*T67*(-T43-T53
     #-0.2911213559997856D-4*T57)
      T76 = 0.6350067860591282D-1/T4*T5*T8
      T78 = 0.8000631191499664D-1*T14*T51
      VSIGMAAA(I) = -0.7385587663820224D0*T3*(T76+T78
     #+0.411572817044697D-1*T29*T17*SIGMA+0.1044846919409344D0*T19*T14
     #)*T33+0.7385587663820224D0*T24*T67*(T76+T78
     #+0.2183410169998392D-4*SIGMA*T29)
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.D0,SIGMAAA1(I))
      T2 = RHO**(1.D0/3.D0)
      T3 = T2*RHO
      T4 = SQRT(SIGMA)
      T5 = 1/T3
      T6 = T4*T5
      T8 = LOG(0.1259928455434599D1*T6+SQRT(1+0.1587419712813814D1
     #*T6**2))
      T10 = 0.3175033930295641D-1*T6*T8
      T11 = RHO**2
      T12 = T2**2
      T14 = 1/T12/T11
      T15 = SIGMA*T14
      T17 = EXP(-0.261211729852336D1*T15)
      T19 = 0.2743D0-0.1508D0*T17
      T20 = T19*SIGMA
      T23 = 1.D0+T10+0.261211729852336D-1*T20*T14
      T24 = T3*T23
      T25 = SIGMA**2
      T26 = T11**2
      T29 = 1/T2/T26/RHO
      T32 = 1.D0+T10+0.272926271249799D-5*T25*T29
      T33 = 1/T32
      ZK(I) = -0.7385587663820224D0*T24*T33
      T36 = T2*T23
      T40 = 1/T2/T11
      T43 = 0.8466757147455043D-1*T4*T40*T8
      T44 = T11*RHO
      T46 = 1/T12/T44
      T49 = 1.D0+0.1587419712813815D1*T15
      T50 = SQRT(T49)
      T51 = 1/T50
      T53 = 0.1066750825533289D0*SIGMA*T46*T51
      T56 = 1/T2/T26/T11
      T57 = T25*T56
      T62 = -T43-T53-0.5487637560595959D-1*T57*T17
     #-0.1393129225879125D0*T20*T46
      T63 = T3*T62
      T66 = T32**2
      T67 = 1/T66
      T69 = -T43-T53-0.2911213559997856D-4*T57
      T70 = T67*T69
      VRHOA(I) = -0.9847450218426965D0*T36*T33-0.3692793831910112D0
     #*T63*T33+0.3692793831910112D0*T24*T70
      T73 = 1/T4
      T76 = 0.6350067860591282D-1*T73*T5*T8
      T78 = 0.8000631191499664D-1*T14*T51
      T79 = T29*T17
      T84 = T76+T78+0.411572817044697D-1*T79*SIGMA
     #+0.1044846919409344D0*T19*T14
      T85 = T3*T84
      T90 = T76+T78+0.2183410169998392D-4*SIGMA*T29
      T91 = T67*T90
      VSIGMAAA(I) = -0.7385587663820224D0*T85*T33+0.7385587663820224D0
     #*T24*T91
      T107 = 0.395115333547902D0*T4/T2/T44*T8
      T109 = 1/T12/T26
      T112 = 0.1066750825533289D1*SIGMA*T109*T51
      T116 = T25/T2/T26/T44
      T118 = 1/T50/T49
      T120 = 0.4515683437631874D0*T116*T118
      T124 = T26**2
      T139 = 1/T66/T32
      T140 = T69**2
      V2RHOA2(I) = -0.6564966812284644D0/T12*T23*T33
     #-0.1969490043685393D1*T2*T62*T33+0.1969490043685393D1*T36*T70
     #-0.3692793831910112D0*T3*(T107+T112-T120+0.9877747609072727D0
     #*T116*T17-0.764498826669826D0*T25*SIGMA/T124/T11*T17
     #+0.1021628098978025D1*T20*T109)*T33+0.7385587663820224D0*T63*T70
     #-0.7385587663820224D0*T24*T139*T140+0.3692793831910112D0*T24*T67
     #*(T107+T112-T120+0.3687537175997285D-3*T116)
      T156 = 0.1693351429491009D0*T73*T40*T8
      T158 = 0.6400504953199731D0*T46*T51
      T159 = SIGMA*T56
      T161 = 0.3386762578223905D0*T159*T118
      V2RHOASIGMAAA(I) = -0.9847450218426965D0*T2*T84*T33
     #+0.9847450218426965D0*T36*T91-0.3692793831910112D0*T3*(-T156
     #-T158+T161-0.6585165072715151D0*T56*T17*SIGMA
     #+0.5733741200023695D0*T25/T124/RHO*T17-0.5572516903516501D0*T19
     #*T46)*T33+0.3692793831910112D0*T63*T91+0.3692793831910112D0*T85
     #*T70-0.7385587663820224D0*T24*T139*T69*T90+0.3692793831910112D0
     #*T24*T67*(-T156-T158+T161-0.2328970847998285D-3*T159)
      T193 = 0.1270013572118256D0/T4/SIGMA*T5*T8
      T197 = 0.1600126238299933D0/SIGMA*T14*T51
      T199 = 0.2540071933667929D0*T29*T118
      T211 = T90**2
      V2SIGMAAA2(I) = -0.7385587663820224D0*T3*(-T193+T197-T199
     #-0.4300305900017772D0/T124*T17*SIGMA+0.3292582536357576D0*T79)
     #*T33+0.1477117532764045D1*T85*T91-0.1477117532764045D1*T24*T139
     #*T211+0.7385587663820224D0*T24*T67*(-T193+T197-T199
     #+0.8733640679993569D-4*T29)
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      V2RHOASIGMAAA(I) = 0.0D0
      V2SIGMAAA2(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C*MODULE DFTXCB  *DECK UKS_C_PW91
      SUBROUTINE UKS_C_PW91
     & (IDERIV,NPT,RHOA1,RHOB1,SIGMAAA1,SIGMABB1,SIGMAAB1,
     &  ZK,VRHOA,VRHOB,VSIGMAAA,VSIGMABB,VSIGMAAB,
     &  V2RHOA2,V2RHOB2,V2RHOAB,
     &  V2RHOASIGMAAA,V2RHOASIGMAAB,V2RHOASIGMABB,
     &  V2RHOBSIGMABB,V2RHOBSIGMAAB,V2RHOBSIGMAAA,
     &  V2SIGMAAA2,V2SIGMAAAAB,V2SIGMAAABB,
     &  V2SIGMAAB2,V2SIGMAABBB,V2SIGMABB2)
C
C     J.P. PERDEW, J.A. CHEVARY, S.H. VOSKO, K.A. JACKSON,
C     M.R. PEDERSON, D.J. SINGH, C. FIOLHAIS
C     ATOMS, MOLECULES, SOLIDS AND SURFACES:
C     APPLICATIONS OF THE GENERALIZED GRADIENT APPROXIMATION
C     FOR EXCHANGE AND CORRELATION
C     PHYS. REV. B 46 (1992) 6671--6687
C
      IMPLICIT DOUBLE PRECISION(A-H,O-Z)
      INTEGER IDERIV,NPT
      DOUBLE PRECISION RHOA1(NPT),RHOB1(NPT)
      DOUBLE PRECISION SIGMAAA1(NPT),SIGMABB1(NPT),SIGMAAB1(NPT)
      DOUBLE PRECISION ZK(NPT),VRHOA(NPT),VRHOB(NPT)
      DOUBLE PRECISION VSIGMAAA(NPT),VSIGMABB(NPT),VSIGMAAB(NPT)
      DOUBLE PRECISION V2RHOA2(NPT),V2RHOB2(NPT),V2RHOAB(NPT)
      DOUBLE PRECISION V2RHOASIGMAAA(NPT),V2RHOASIGMAAB(NPT)
      DOUBLE PRECISION V2RHOASIGMABB(NPT),V2RHOBSIGMABB(NPT)
      DOUBLE PRECISION V2RHOBSIGMAAB(NPT),V2RHOBSIGMAAA(NPT)
      DOUBLE PRECISION V2SIGMAAA2(NPT),V2SIGMAAAAB(NPT),V2SIGMAAABB(NPT)
      DOUBLE PRECISION V2SIGMAAB2(NPT),V2SIGMAABBB(NPT),V2SIGMABB2(NPT)
      PARAMETER(TOL=1.0D-20)
C
      IF (IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMABB
      T2 = 1/RHOB
      T3 = T2**(1.D0/3.D0)
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T17 = LOG(1.D0+0.321646831778707D2/(0.1112037486309468D2*T6
     #+0.3844746237447211D1*T3+0.1644733775567609D1*T9
     #+0.2405871291288192D0*T11))
      T18 = (1.D0+0.1274696188700087D0*T3)*T17
      T20 = RHOB**2
      T21 = RHOB**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513789108010112D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMABB**2
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T42 = T28**2
      T52 = LOG(1.D0+0.2697586091519874D1*(0.1007494971260294D0
     #*SIGMABB*T23+0.2738174287780083D-1*T29*T30*T35)/(1.D0
     #+0.2717804421747983D0*T29*SIGMABB*T23+0.7386460874872889D-1/T42
     #*T30*T35))
      T70 = EXP(-0.1645530784602056D1/T33/T20*SIGMABB)
      ZK(I) = RHOB*(-0.3109D-1*T18+0.1236778371778789D-1*T52
     #+0.7937005259840997D0*(0.1D-2*(0.2568D1+0.1443307452126544D2*T3
     #+0.2843543831490386D-2*T11)/(1.D0+0.5411317332115466D1*T3
     #+0.1816419932959077D0*T11+0.1763993811759022D-1*T2)
     #-0.1853571428571429D-2)*SIGMABB*T23*T70)
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMA = SIGMAAA
      T2 = 1/RHOA
      T3 = T2**(1.D0/3.D0)
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T17 = LOG(1.D0+0.321646831778707D2/(0.1112037486309468D2*T6
     #+0.3844746237447211D1*T3+0.1644733775567609D1*T9
     #+0.2405871291288192D0*T11))
      T18 = (1.D0+0.1274696188700087D0*T3)*T17
      T20 = RHOA**2
      T21 = RHOA**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513789108010112D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMAAA**2
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T42 = T28**2
      T52 = LOG(1.D0+0.2697586091519874D1*(0.1007494971260294D0
     #*SIGMAAA*T23+0.2738174287780083D-1*T29*T30*T35)/(1.D0
     #+0.2717804421747983D0*T29*SIGMAAA*T23+0.7386460874872889D-1/T42
     #*T30*T35))
      T70 = EXP(-0.1645530784602056D1/T33/T20*SIGMAAA)
      ZK(I) = RHOA*(-0.3109D-1*T18+0.1236778371778789D-1*T52
     #+0.7937005259840997D0*(0.1D-2*(0.2568D1+0.1443307452126544D2*T3
     #+0.2843543831490386D-2*T11)/(1.D0+0.5411317332115466D1*T3
     #+0.1816419932959077D0*T11+0.1763993811759022D-1*T2)
     #-0.1853571428571429D-2)*SIGMAAA*T23*T70)
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMAAB = SIGMAAB1(I)
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMAAA+SIGMABB+2.D0*SIGMAAB
      T4 = 1/RHO
      T5 = T4**(1.D0/3.D0)
      T8 = T4**(1.D0/6.D0)
      T11 = SQRT(T4)
      T13 = T5**2
      T19 = LOG(1.D0+0.160818243221511D2/(0.598255043577108D1*T8
     #+0.2225569421150687D1*T5+0.8004286349993634D0*T11
     #+0.1897004325747559D0*T13))
      T21 = 0.62182D-1*(1.D0+0.1325688999052018D0*T5)*T19
      T32 = LOG(1.D0+0.2960857464321668D2/(0.8157414703487641D1*T8
     #+0.2247591863577616D1*T5+0.4300972471276643D0*T11
     #+0.1911512595127338D0*T13))
      T35 = RHOA-1.D0*RHOB
      T36 = T35*T4
      T37 = 1.D0+T36
      T38 = T37**(1.D0/3.D0)
      T41 = 1.D0-1.D0*T36
      T42 = T41**(1.D0/3.D0)
      T44 = T38*T37+T42*T41-2.D0
      T45 = T35**2
      T46 = T45**2
      T47 = RHO**2
      T48 = T47**2
      T50 = T46/T48
      T55 = 0.3799575D-1*(1.D0+0.6901399211255825D-1*T5)*T32*T44*(1.D0
     #-1.D0*T50)
      T66 = LOG(1.D0+0.321646831778707D2/(0.1112037486309468D2*T8
     #+0.3844746237447211D1*T5+0.1644733775567609D1*T11
     #+0.2405871291288192D0*T13))
      T72 = 0.1923661050931536D1*(-0.3109D-1*(1.D0
     #+0.1274696188700087D0*T5)*T66+T21)*T44*T50
      T73 = T38**2
      T75 = T42**2
      T77 = 0.5D0*T73+0.5D0*T75
      T78 = T77**2
      T79 = T78*T77
      T80 = 1/T78
      T82 = RHO**(1.D0/3.D0)
      T84 = 1/T82/T47
      T91 = EXP(-0.4042761511756372D2*(-T21+T55+T72)/T79)
      T92 = T91-1.D0
      T93 = 1/T92
      T94 = SIGMA**2
      T96 = T78**2
      T98 = T82**2
      T101 = 1/T96/T98/T48
      T109 = T92**2
      T119 = LOG(1.D0+0.2697586091519874D1*(0.634682060977037D-1
     #*SIGMA*T80*T84+0.1086645186223595D-1*T93*T94*T101)/(1.D0
     #+0.1712109500228824D0*T93*SIGMA*T80*T84+0.2931318940773793D-1
     #/T109*T94*T101))
      T140 = EXP(-0.261211729852336D1*T78/T98/T47*SIGMA)
      ZK(I) = RHO*(-T21+T55+T72+0.2473556743557577D-1*T79*T119+0.1D1*
     #(0.1D-2*(0.2568D1+0.1443307452126544D2*T5+0.2843543831490386D-2
     #*T13)/(1.D0+0.5411317332115466D1*T5+0.1816419932959077D0*T13
     #+0.1763993811759022D-1*T4)-0.1853571428571429D-2)*T77*SIGMA*T84
     #*T140)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMABB
      T2 = 1/RHOB
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1274696188700087D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T3
     #+0.1644733775567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.321646831778707D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.3109D-1*T18
      T20 = RHOB**2
      T21 = RHOB**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513789108010112D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMABB**2
      T31 = T29*T30
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T38 = 0.1007494971260294D0*SIGMABB*T23+0.2738174287780083D-1*T31
     #*T35
      T39 = T29*SIGMABB
      T42 = T28**2
      T43 = 1/T42
      T44 = T43*T30
      T47 = 1.D0+0.2717804421747983D0*T39*T23+0.7386460874872889D-1
     #*T44*T35
      T48 = 1/T47
      T51 = 1.D0+0.2697586091519874D1*T38*T48
      T52 = LOG(T51)
      T53 = 0.1236778371778789D-1*T52
      T56 = 0.2568D1+0.1443307452126544D2*T3+0.2843543831490386D-2*T11
      T60 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T11
     #+0.1763993811759022D-1*T2
      T61 = 1/T60
      T64 = 0.1D-2*T56*T61-0.1853571428571429D-2
      T65 = T64*SIGMABB
      T70 = EXP(-0.1645530784602056D1/T33/T20*SIGMABB)
      T71 = T23*T70
      T73 = 0.7937005259840997D0*T65*T71
      ZK(I) = RHOB*(-T19+T53+T73)
      VRHOA(I) = 0.D0
      T76 = 1/T20
      T77 = 1/T11*T76
      T79 = 0.1321010150222857D-2*T77*T17
      T80 = T13**2
      T83 = T6**2
      T84 = T83**2
      T94 = 1/T3*T76
      T100 = 0.1D1*T5/T80*(-0.1853395810515781D1/T84/T6*T76
     #-0.128158207914907D1*T77-0.8223668877838045D0/T9*T76
     #-0.1603914194192128D0*T94)/T16
      T103 = 1/T21/T20/RHOB
      T106 = T79+T100
      T108 = T35*T106*T27
      T111 = T32*RHOB
      T113 = 1/T33/T111
      T119 = T47**2
      T121 = T38/T119
      T122 = T43*SIGMABB
      T140 = 1/T51
      T148 = T60**2
      VRHOB(I) = -T19+T53+T73+RHOB*(T79+T100+0.1236778371778789D-1*
     #(0.2697586091519874D1*(-0.2350821599607352D0*SIGMABB*T103
     #+0.2213957124623647D1*T44*T108-0.1277814667630705D0*T31*T113)
     #*T48-0.2697586091519874D1*T121*(0.2197487022544806D2*T122*T23
     #*T106*T27-0.6341543650745294D0*T39*T103+0.1194467989321217D2/T42
     #/T28*T30*T108-0.3447015074940681D0*T44*T113))*T140
     #+0.7937005259840997D0*(0.1D-2*(-0.4811024840421814D1*T77
     #-0.1895695887660258D-2*T94)*T61-0.1D-2*T56/T148*(
     #-0.1803772444038489D1*T77-0.1210946621972718D0*T94
     #-0.1763993811759022D-1*T76))*SIGMABB*T71-0.1851967893962899D1
     #*T65*T103*T70+0.3482823064697813D1*T64*T30/T32/T20*T70)
      VSIGMAAA(I) = 0.D0
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = RHOB*(0.1236778371778789D-1*(0.2697586091519874D1*
     #(0.1007494971260294D0*T23+0.5476348575560166D-1*T39*T35)*T48
     #-0.2697586091519874D1*T121*(0.2717804421747983D0*T29*T23
     #+0.1477292174974578D0*T122*T35))*T140+0.7937005259840997D0*T64
     #*T23*T70-0.130605864926168D1*T65/T111*T70)
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMA = SIGMAAA
      T2 = 1/RHOA
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1274696188700087D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T3
     #+0.1644733775567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.321646831778707D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.3109D-1*T18
      T20 = RHOA**2
      T21 = RHOA**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513789108010112D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMAAA**2
      T31 = T29*T30
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T38 = 0.1007494971260294D0*SIGMAAA*T23+0.2738174287780083D-1*T31
     #*T35
      T39 = T29*SIGMAAA
      T42 = T28**2
      T43 = 1/T42
      T44 = T43*T30
      T47 = 1.D0+0.2717804421747983D0*T39*T23+0.7386460874872889D-1
     #*T44*T35
      T48 = 1/T47
      T51 = 1.D0+0.2697586091519874D1*T38*T48
      T52 = LOG(T51)
      T53 = 0.1236778371778789D-1*T52
      T56 = 0.2568D1+0.1443307452126544D2*T3+0.2843543831490386D-2*T11
      T60 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T11
     #+0.1763993811759022D-1*T2
      T61 = 1/T60
      T64 = 0.1D-2*T56*T61-0.1853571428571429D-2
      T65 = T64*SIGMAAA
      T70 = EXP(-0.1645530784602056D1/T33/T20*SIGMAAA)
      T71 = T23*T70
      T73 = 0.7937005259840997D0*T65*T71
      ZK(I) = RHOA*(-T19+T53+T73)
      T76 = 1/T20
      T77 = 1/T11*T76
      T79 = 0.1321010150222857D-2*T77*T17
      T80 = T13**2
      T83 = T6**2
      T84 = T83**2
      T94 = 1/T3*T76
      T100 = 0.1D1*T5/T80*(-0.1853395810515781D1/T84/T6*T76
     #-0.128158207914907D1*T77-0.8223668877838045D0/T9*T76
     #-0.1603914194192128D0*T94)/T16
      T103 = 1/T21/T20/RHOA
      T106 = T79+T100
      T108 = T35*T106*T27
      T111 = T32*RHOA
      T113 = 1/T33/T111
      T119 = T47**2
      T121 = T38/T119
      T122 = T43*SIGMAAA
      T140 = 1/T51
      T148 = T60**2
      VRHOA(I) = -T19+T53+T73+RHOA*(T79+T100+0.1236778371778789D-1*
     #(0.2697586091519874D1*(-0.2350821599607352D0*SIGMAAA*T103
     #+0.2213957124623647D1*T44*T108-0.1277814667630705D0*T31*T113)
     #*T48-0.2697586091519874D1*T121*(0.2197487022544806D2*T122*T23
     #*T106*T27-0.6341543650745294D0*T39*T103+0.1194467989321217D2/T42
     #/T28*T30*T108-0.3447015074940681D0*T44*T113))*T140
     #+0.7937005259840997D0*(0.1D-2*(-0.4811024840421814D1*T77
     #-0.1895695887660258D-2*T94)*T61-0.1D-2*T56/T148*(
     #-0.1803772444038489D1*T77-0.1210946621972718D0*T94
     #-0.1763993811759022D-1*T76))*SIGMAAA*T71-0.1851967893962899D1
     #*T65*T103*T70+0.3482823064697813D1*T64*T30/T32/T20*T70)
      VRHOB(I) = 0.D0
      VSIGMAAA(I) = RHOA*(0.1236778371778789D-1*(0.2697586091519874D1*
     #(0.1007494971260294D0*T23+0.5476348575560166D-1*T39*T35)*T48
     #-0.2697586091519874D1*T121*(0.2717804421747983D0*T29*T23
     #+0.1477292174974578D0*T122*T35))*T140+0.7937005259840997D0*T64
     #*T23*T70-0.130605864926168D1*T65/T111*T70)
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = 0.D0
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMAAB = SIGMAAB1(I)
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMAAA+SIGMABB+2.D0*SIGMAAB
      T4 = 1/RHO
      T5 = T4**(1.D0/3.D0)
      T7 = 1.D0+0.1325688999052018D0*T5
      T8 = T4**(1.D0/6.D0)
      T11 = SQRT(T4)
      T13 = T5**2
      T15 = 0.598255043577108D1*T8+0.2225569421150687D1*T5
     #+0.8004286349993634D0*T11+0.1897004325747559D0*T13
      T18 = 1.D0+0.160818243221511D2/T15
      T19 = LOG(T18)
      T21 = 0.62182D-1*T7*T19
      T23 = 1.D0+0.6901399211255825D-1*T5
      T28 = 0.8157414703487641D1*T8+0.2247591863577616D1*T5
     #+0.4300972471276643D0*T11+0.1911512595127338D0*T13
      T31 = 1.D0+0.2960857464321668D2/T28
      T32 = LOG(T31)
      T33 = T23*T32
      T35 = RHOA-1.D0*RHOB
      T36 = T35*T4
      T37 = 1.D0+T36
      T38 = T37**(1.D0/3.D0)
      T41 = 1.D0-1.D0*T36
      T42 = T41**(1.D0/3.D0)
      T44 = T38*T37+T42*T41-2.D0
      T45 = T35**2
      T46 = T45**2
      T47 = RHO**2
      T48 = T47**2
      T49 = 1/T48
      T50 = T46*T49
      T52 = 1.D0-1.D0*T50
      T55 = 0.3799575D-1*T33*T44*T52
      T57 = 1.D0+0.1274696188700087D0*T5
      T62 = 0.1112037486309468D2*T8+0.3844746237447211D1*T5
     #+0.1644733775567609D1*T11+0.2405871291288192D0*T13
      T65 = 1.D0+0.321646831778707D2/T62
      T66 = LOG(T65)
      T69 = -0.3109D-1*T57*T66+T21
      T70 = T69*T44
      T72 = 0.1923661050931536D1*T70*T50
      T73 = T38**2
      T75 = T42**2
      T77 = 0.5D0*T73+0.5D0*T75
      T78 = T77**2
      T79 = T78*T77
      T80 = 1/T78
      T81 = SIGMA*T80
      T82 = RHO**(1.D0/3.D0)
      T84 = 1/T82/T47
      T87 = -T21+T55+T72
      T88 = 1/T79
      T91 = EXP(-0.4042761511756372D2*T87*T88)
      T92 = T91-1.D0
      T93 = 1/T92
      T94 = SIGMA**2
      T95 = T93*T94
      T96 = T78**2
      T97 = 1/T96
      T98 = T82**2
      T100 = 1/T98/T48
      T101 = T97*T100
      T104 = 0.634682060977037D-1*T81*T84+0.1086645186223595D-1*T95*T101
      T105 = T93*SIGMA
      T106 = T80*T84
      T109 = T92**2
      T110 = 1/T109
      T111 = T110*T94
      T114 = 1.D0+0.1712109500228824D0*T105*T106+0.2931318940773793D-1
     #*T111*T101
      T115 = 1/T114
      T118 = 1.D0+0.2697586091519874D1*T104*T115
      T119 = LOG(T118)
      T121 = 0.2473556743557577D-1*T79*T119
      T124 = 0.2568D1+0.1443307452126544D2*T5+0.2843543831490386D-2*T13
      T128 = 1.D0+0.5411317332115466D1*T5+0.1816419932959077D0*T13
     #+0.1763993811759022D-1*T4
      T129 = 1/T128
      T132 = 0.1D-2*T124*T129-0.1853571428571429D-2
      T133 = T132*T77
      T136 = 1/T98/T47
      T140 = EXP(-0.261211729852336D1*T78*T136*SIGMA)
      T141 = SIGMA*T84*T140
      T143 = 0.1D1*T133*T141
      ZK(I) = RHO*(-T21+T55+T72+T121+T143)
      T149 = 0.1333333333333333D1*T38*T4-0.1333333333333333D1*T42*T4
      T152 = 0.3799575D-1*T33*T149*T52
      T153 = T45*T35
      T156 = T33*T44*T153*T49
      T157 = 0.151983D0*T156
      T160 = 0.1923661050931536D1*T69*T149*T50
      T162 = T70*T153*T49
      T163 = 0.7694644203726145D1*T162
      T164 = T78*T119
      T165 = 1/T38
      T168 = 1/T42
      T171 = 0.3333333333333333D0*T165*T4-0.3333333333333333D0*T168*T4
      T174 = SIGMA*T88
      T178 = T111*T97
      T182 = T87*T97
      T185 = -0.4042761511756372D2*(T152-T157+T160+T163)*T88
     #+0.1212828453526912D3*T182*T171
      T187 = T100*T185*T91
      T192 = 1/T96/T77*T100
      T193 = T192*T171
      T199 = T114**2
      T201 = T104/T199
      T202 = T110*SIGMA
      T203 = T202*T80
      T208 = T88*T84
      T215 = 1/T109/T92*T94*T97
      T225 = 1/T118
      T232 = T132*T78*T94
      T233 = T48*RHO
      T234 = 1/T233
      T242 = 1/T47
      T243 = 1/T13*T242
      T244 = T243*T19
      T245 = 0.2747799777968419D-2*T244
      T246 = T15**2
      T249 = T8**2
      T250 = T249**2
      T253 = 1/T250/T8*T242
      T257 = 1/T11*T242
      T260 = 1/T5*T242
      T265 = T7/T246*(-0.99709173929518D0*T253-0.7418564737168958D0
     #*T243-0.4002143174996817D0*T257-0.1264669550498372D0*T260)/T18
      T266 = 0.1D1*T265
      T270 = 0.8740794636035784D-3*T243*T32*T44*T52
      T271 = T28**2
      T284 = 0.1125D1*T23/T271*(-0.135956911724794D1*T253
     #-0.7491972878592054D0*T243-0.2150486235638321D0*T257
     #-0.1274341730084892D0*T260)/T31*T44*T52
      T291 = -0.1333333333333333D1*T38*T35*T242+0.1333333333333333D1
     #*T42*T35*T242
      T294 = 0.3799575D-1*T33*T291*T52
      T298 = 0.151983D0*T33*T44*T46*T234
      T301 = T62**2
      T318 = 0.1923661050931536D1*(0.1321010150222857D-2*T243*T66
     #+0.1D1*T57/T301*(-0.1853395810515781D1*T253-0.128158207914907D1
     #*T243-0.8223668877838045D0*T257-0.1603914194192128D0*T260)/T65
     #-0.2747799777968419D-2*T244-0.1D1*T265)*T44*T50
      T321 = 0.1923661050931536D1*T69*T291*T50
      T324 = 0.7694644203726145D1*T70*T46*T234
      T331 = -0.3333333333333333D0*T165*T35*T242+0.3333333333333333D0
     #*T168*T35*T242
      T337 = T47*RHO
      T339 = 1/T82/T337
      T347 = -0.4042761511756372D2*(T245+T266-T270-T284+T294+T298+T318
     #+T321-T324)*T88+0.1212828453526912D3*T182*T331
      T349 = T100*T347*T91
      T352 = T192*T331
      T357 = T97/T98/T233
      T391 = T128**2
      S1 = T245+T266-T270-T284+T294+T298+T318
      S2 = S1+T321-T324+0.7420670230672731D-1*T164*T331
      S3 = S2+0.2473556743557577D-1*T79*(0.2697586091519874D1*(
     #-0.1269364121954074D0*T174*T84*T331-0.148092480894642D0*T81*T339
     #-0.1086645186223595D-1*T178*T349-0.4346580744894379D-1*T95*T352
     #-0.5071010869043442D-1*T95*T357)*T115-0.2697586091519874D1*T201*
     #(-0.1712109500228824D0*T203*T84*T347*T91-0.3424219000457648D0
     #*T105*T208*T331-0.3994922167200589D0*T105*T80*T339
     #-0.5862637881547585D-1*T215*T349-0.1172527576309517D0*T111*T352
     #-0.136794883902777D0*T111*T357))*T225+0.1D1*(0.1D-2*(
     #-0.4811024840421814D1*T243-0.1895695887660258D-2*T260)*T129
     #-0.1D-2*T124/T391*(-0.1803772444038489D1*T243
     #-0.1210946621972718D0*T260-0.1763993811759022D-1*T242))*T77*T141
      T426 = S3+0.1D1*T132*T331*T141-0.2333333333333333D1*T133*SIGMA
     #*T339*T140+0.1D1*T133*SIGMA*T84*(-0.522423459704672D1*T77*T136
     #*SIGMA*T331+0.6965646129395627D1*T78/T98/T337*SIGMA)*T140
      T427 = RHO*T426
      VRHOA(I) = RHO*(T152-T157+T160+T163+0.7420670230672731D-1*T164
     #*T171+0.2473556743557577D-1*T79*(0.2697586091519874D1*(
     #-0.1269364121954074D0*T174*T84*T171-0.1086645186223595D-1*T178
     #*T187-0.4346580744894379D-1*T95*T193)*T115-0.2697586091519874D1
     #*T201*(-0.1712109500228824D0*T203*T84*T185*T91
     #-0.3424219000457648D0*T105*T208*T171-0.5862637881547585D-1*T215
     #*T187-0.1172527576309517D0*T111*T193))*T225+0.1D1*T132*T171*T141
     #-0.522423459704672D1*T232*T234*T171*T140)-T21+T55+T72+T121+T143
     #+T427
      T428 = -T149
      T431 = 0.3799575D-1*T33*T428*T52
      T432 = 0.151983D0*T156
      T435 = 0.1923661050931536D1*T69*T428*T50
      T436 = 0.7694644203726145D1*T162
      T437 = -T171
      T448 = -0.4042761511756372D2*(T431+T432+T435-T436)*T88
     #+0.1212828453526912D3*T182*T437
      T450 = T100*T448*T91
      T453 = T192*T437
      VRHOB(I) = RHO*(T431+T432+T435-T436+0.7420670230672731D-1*T164
     #*T437+0.2473556743557577D-1*T79*(0.2697586091519874D1*(
     #-0.1269364121954074D0*T174*T84*T437-0.1086645186223595D-1*T178
     #*T450-0.4346580744894379D-1*T95*T453)*T115-0.2697586091519874D1
     #*T201*(-0.1712109500228824D0*T203*T84*T448*T91
     #-0.3424219000457648D0*T105*T208*T437-0.5862637881547585D-1*T215
     #*T450-0.1172527576309517D0*T111*T453))*T225+0.1D1*T132*T437*T141
     #-0.522423459704672D1*T232*T234*T437*T140)-T21+T55+T72+T121+T143
     #+T427
      VSIGMAAA(I) = RHO*(0.2473556743557577D-1*T79*
     #(0.2697586091519874D1*(0.634682060977037D-1*T106
     #+0.2173290372447189D-1*T105*T101)*T115-0.2697586091519874D1*T201
     #*(0.1712109500228824D0*T93*T80*T84+0.5862637881547585D-1*T202
     #*T101))*T225+0.1D1*T133*T84*T140-0.261211729852336D1*T132*T79
     #*SIGMA*T234*T140)
      VSIGMAAB(I) = 2.D0*VSIGMAAA(I)
      VSIGMABB(I) = VSIGMAAA(I)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      VSIGMAAB(I) = 0.0D0
      VSIGMABB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMABB
      T2 = 1/RHOB
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1274696188700087D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T3
     #+0.1644733775567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.321646831778707D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.3109D-1*T18
      T20 = RHOB**2
      T21 = RHOB**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513789108010112D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMABB**2
      T31 = T29*T30
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T38 = 0.1007494971260294D0*SIGMABB*T23+0.2738174287780083D-1*T31
     #*T35
      T39 = T29*SIGMABB
      T42 = T28**2
      T43 = 1/T42
      T44 = T43*T30
      T47 = 1.D0+0.2717804421747983D0*T39*T23+0.7386460874872889D-1
     #*T44*T35
      T48 = 1/T47
      T51 = 1.D0+0.2697586091519874D1*T38*T48
      T52 = LOG(T51)
      T53 = 0.1236778371778789D-1*T52
      T56 = 0.2568D1+0.1443307452126544D2*T3+0.2843543831490386D-2*T11
      T60 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T11
     #+0.1763993811759022D-1*T2
      T61 = 1/T60
      T64 = 0.1D-2*T56*T61-0.1853571428571429D-2
      T65 = T64*SIGMABB
      T70 = EXP(-0.1645530784602056D1/T33/T20*SIGMABB)
      T71 = T23*T70
      T73 = 0.7937005259840997D0*T65*T71
      ZK(I) = RHOB*(-T19+T53+T73)
      VRHOA(I) = 0.D0
      T75 = 1/T11
      T76 = 1/T20
      T77 = T75*T76
      T78 = T77*T17
      T79 = 0.1321010150222857D-2*T78
      T80 = T13**2
      T81 = 1/T80
      T82 = T5*T81
      T83 = T6**2
      T84 = T83**2
      T85 = T84*T6
      T86 = 1/T85
      T90 = 1/T9
      T93 = 1/T3
      T94 = T93*T76
      T96 = -0.1853395810515781D1*T86*T76-0.128158207914907D1*T77
     #-0.8223668877838045D0*T90*T76-0.1603914194192128D0*T94
      T97 = 1/T16
      T99 = T82*T96*T97
      T100 = 0.1D1*T99
      T101 = T20*RHOB
      T103 = 1/T21/T101
      T106 = T79+T100
      T108 = T35*T106*T27
      T111 = T32*RHOB
      T113 = 1/T33/T111
      T116 = -0.2350821599607352D0*SIGMABB*T103+0.2213957124623647D1
     #*T44*T108-0.1277814667630705D0*T31*T113
      T119 = T47**2
      T120 = 1/T119
      T121 = T38*T120
      T122 = T43*SIGMABB
      T130 = 1/T42/T28
      T131 = T130*T30
      T136 = 0.2197487022544806D2*T122*T23*T106*T27
     #-0.6341543650745294D0*T39*T103+0.1194467989321217D2*T131*T108
     #-0.3447015074940681D0*T44*T113
      T139 = 0.2697586091519874D1*T116*T48-0.2697586091519874D1*T121
     #*T136
      T140 = 1/T51
      T141 = T139*T140
      T145 = -0.4811024840421814D1*T77-0.1895695887660258D-2*T94
      T148 = T60**2
      T149 = 1/T148
      T150 = T56*T149
      T154 = -0.1803772444038489D1*T77-0.1210946621972718D0*T94
     #-0.1763993811759022D-1*T76
      T157 = 0.1D-2*T145*T61-0.1D-2*T150*T154
      T158 = T157*SIGMABB
      T159 = T158*T71
      T161 = T103*T70
      T162 = T65*T161
      T164 = T64*T30
      T165 = T32*T20
      T167 = 1/T165*T70
      T168 = T164*T167
      VRHOB(I) = -T19+T53+T73+RHOB*(T79+T100+0.1236778371778789D-1
     #*T141+0.7937005259840997D0*T159-0.1851967893962899D1*T162
     #+0.3482823064697813D1*T168)
      VSIGMAAA(I) = 0.D0
      VSIGMAAB(I) = 0.D0
      T175 = 0.1007494971260294D0*T23+0.5476348575560166D-1*T39*T35
      T182 = 0.2717804421747983D0*T29*T23+0.1477292174974578D0*T122*T35
      T185 = 0.2697586091519874D1*T175*T48-0.2697586091519874D1*T121
     #*T182
      T191 = 1/T111
      VSIGMABB(I) = RHOB*(0.1236778371778789D-1*T185*T140
     #+0.7937005259840997D0*T64*T23*T70-0.130605864926168D1*T65*T191
     #*T70)
      V2RHOA2(I) = 0.D0
      V2RHOAB(I) = 0.D0
      T204 = LOG(1.D0+0.160818243221511D2/(0.598255043577108D1*T6
     #+0.2225569421150687D1*T3+0.8004286349993634D0*T9
     #+0.1897004325747559D0*T11))
      T214 = 1/T21/T32
      T217 = T106**2
      T218 = T35*T217
      T220 = EXP(0.5027578216020225D1*T18)
      T221 = T218*T220
      T225 = T113*T106*T27
      T228 = 1/T101
      T229 = T75*T228
      T231 = 0.1D-22*T229*T204
      T234 = 1/T32
      T235 = 1/T11/T2*T234
      T237 = 0.8806734334819047D-3*T235*T17
      T239 = 0.2642020300445714D-2*T229*T17
      T243 = 0.8497974591333914D-1*T77*T81*T96*T97
      T247 = T96**2
      T250 = 0.2D1*T5/T80/T13*T247*T97
      T267 = 1/T3/T2*T234
      T269 = T93*T228
      T274 = 0.1D1*T82*(-0.1544496508763151D1/T85/T2*T234
     #+0.3706791621031562D1*T86*T228-0.854388052766047D0*T235
     #+0.2563164158298141D1*T229-0.4111834438919023D0/T9/T2*T234
     #+0.1644733775567609D1*T90*T228-0.5346380647307093D-1*T267
     #+0.3207828388384256D0*T269)*T97
      T275 = T80**2
      T278 = T16**2
      T282 = 0.321646831778707D2*T5/T275*T247/T278
      T283 = -T231+T237-T239-T243-T250+T274+T282
      T285 = T35*T283*T27
      T288 = T218*T27
      T292 = 1/T33/T165
      T303 = T38/T119/T47
      T304 = T136**2
      T308 = T23*T217
      T325 = T42**2
      T344 = T139**2
      T345 = T51**2
      T346 = 1/T345
      T362 = T154**2
      T379 = T32**2
      T386 = T32*T101
      S3 = 0.1236778371778789D-1*(0.2697586091519874D1*
     #(0.7836071998691172D0*SIGMABB*T214+0.3580200260842915D3*T131
     #*T221-0.2066359982982071D2*T44*T225+0.2213957124623647D1*T44
     #*T285-0.1790100130421458D3*T44*T288+0.7240949783240664D0*T31
     #*T292)*T48-0.5395172183039748D1*T116*T120*T136
     #+0.5395172183039748D1*T303*T304-0.2697586091519874D1*T121*
     #(0.35535663829313D4*T130*SIGMABB*T308*T220-0.1025493943854243D3
     #*T122*T103*T106*T27+0.2197487022544806D2*T122*T23*T283*T27
     #-0.177678319146565D4*T122*T308*T27+0.2113847883581765D1*T39*T214
     #+0.2897369528551702D4/T325*T30*T221-0.1114836790033136D3*T131
     #*T225+0.1194467989321217D2*T131*T285-0.9657898428505673D3*T131
     #*T288+0.1953308542466386D1*T44*T292))*T140
      S4 = -0.1236778371778789D-1*T344*T346+0.7937005259840997D0*
     #(0.1D-2*(-0.3207349893614542D1*T235+0.9622049680843627D1*T229
     #-0.6318986292200858D-3*T267+0.3791391775320515D-2*T269)*T61
     #-0.2D-2*T145*T149*T154+0.2D-2*T56/T148/T60*T362-0.1D-2*T150*(
     #-0.1202514962692326D1*T235+0.3607544888076978D1*T229
     #-0.4036488739909061D-1*T267+0.2421893243945437D0*T269
     #+0.3527987623518044D-1*T228))*SIGMABB*T71
      S2 = S3+S4
      S1 = S2+0.1528291352075288D2*T64*T30*SIGMABB/T33/T379/RHOB*T70
     #-0.2902352553914844D2*T164/T386*T70+0.6173226313209665D1*T65
     #*T214*T70-0.3703935787925799D1*T158*T161
      T399 = S1+0.6965646129395627D1*T157*T30*T167-T231-T250+T274+T282
     #+T237-T239-T243
      V2RHOB2(I) = -0.1D-22*T77*T204+0.2642020300445714D-2*T78+0.2D1
     #*T99+0.2473556743557577D-1*T141+0.1587401051968199D1*T159
     #-0.3703935787925799D1*T162+0.6965646129395627D1*T168+RHOB*T399
      V2SIGMAAA2(I) = 0.D0
      V2SIGMAAAAB(I) = 0.D0
      V2SIGMAAABB(I) = 0.D0
      V2SIGMAAB2(I) = 0.D0
      V2SIGMAABBB(I) = 0.D0
      T407 = T182**2
      T416 = T185**2
      V2SIGMABB2(I) = RHOB*(0.1236778371778789D-1*
     #(0.1477292174974578D0*T29*T35*T48-0.5395172183039748D1*T175*T120
     #*T182+0.5395172183039748D1*T303*T407-0.3985122824322565D0*T121
     #*T43*T35)*T140-0.1236778371778789D-1*T416*T346
     #-0.261211729852336D1*T64*T191*T70+0.2149159713855873D1*T65/T33
     #/T386*T70)
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMA = SIGMAAA
      T2 = 1/RHOA
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1274696188700087D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T3
     #+0.1644733775567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.321646831778707D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.3109D-1*T18
      T20 = RHOA**2
      T21 = RHOA**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513789108010112D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMAAA**2
      T31 = T29*T30
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T38 = 0.1007494971260294D0*SIGMAAA*T23+0.2738174287780083D-1*T31
     #*T35
      T39 = T29*SIGMAAA
      T42 = T28**2
      T43 = 1/T42
      T44 = T43*T30
      T47 = 1.D0+0.2717804421747983D0*T39*T23+0.7386460874872889D-1
     #*T44*T35
      T48 = 1/T47
      T51 = 1.D0+0.2697586091519874D1*T38*T48
      T52 = LOG(T51)
      T53 = 0.1236778371778789D-1*T52
      T56 = 0.2568D1+0.1443307452126544D2*T3+0.2843543831490386D-2*T11
      T60 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T11
     #+0.1763993811759022D-1*T2
      T61 = 1/T60
      T64 = 0.1D-2*T56*T61-0.1853571428571429D-2
      T65 = T64*SIGMAAA
      T70 = EXP(-0.1645530784602056D1/T33/T20*SIGMAAA)
      T71 = T23*T70
      T73 = 0.7937005259840997D0*T65*T71
      ZK(I) = RHOA*(-T19+T53+T73)
      T75 = 1/T11
      T76 = 1/T20
      T77 = T75*T76
      T78 = T77*T17
      T79 = 0.1321010150222857D-2*T78
      T80 = T13**2
      T81 = 1/T80
      T82 = T5*T81
      T83 = T6**2
      T84 = T83**2
      T85 = T84*T6
      T86 = 1/T85
      T90 = 1/T9
      T93 = 1/T3
      T94 = T93*T76
      T96 = -0.1853395810515781D1*T86*T76-0.128158207914907D1*T77
     #-0.8223668877838045D0*T90*T76-0.1603914194192128D0*T94
      T97 = 1/T16
      T99 = T82*T96*T97
      T100 = 0.1D1*T99
      T101 = T20*RHOA
      T103 = 1/T21/T101
      T106 = T79+T100
      T108 = T35*T106*T27
      T111 = T32*RHOA
      T113 = 1/T33/T111
      T116 = -0.2350821599607352D0*SIGMAAA*T103+0.2213957124623647D1
     #*T44*T108-0.1277814667630705D0*T31*T113
      T119 = T47**2
      T120 = 1/T119
      T121 = T38*T120
      T122 = T43*SIGMAAA
      T130 = 1/T42/T28
      T131 = T130*T30
      T136 = 0.2197487022544806D2*T122*T23*T106*T27
     #-0.6341543650745294D0*T39*T103+0.1194467989321217D2*T131*T108
     #-0.3447015074940681D0*T44*T113
      T139 = 0.2697586091519874D1*T116*T48-0.2697586091519874D1*T121
     #*T136
      T140 = 1/T51
      T141 = T139*T140
      T145 = -0.4811024840421814D1*T77-0.1895695887660258D-2*T94
      T148 = T60**2
      T149 = 1/T148
      T150 = T56*T149
      T154 = -0.1803772444038489D1*T77-0.1210946621972718D0*T94
     #-0.1763993811759022D-1*T76
      T157 = 0.1D-2*T145*T61-0.1D-2*T150*T154
      T158 = T157*SIGMAAA
      T159 = T158*T71
      T161 = T103*T70
      T162 = T65*T161
      T164 = T64*T30
      T165 = T32*T20
      T167 = 1/T165*T70
      T168 = T164*T167
      VRHOA(I) = -T19+T53+T73+RHOA*(T79+T100+0.1236778371778789D-1
     #*T141+0.7937005259840997D0*T159-0.1851967893962899D1*T162
     #+0.3482823064697813D1*T168)
      VRHOB(I) = 0.D0
      T175 = 0.1007494971260294D0*T23+0.5476348575560166D-1*T39*T35
      T182 = 0.2717804421747983D0*T29*T23+0.1477292174974578D0*T122*T35
      T185 = 0.2697586091519874D1*T175*T48-0.2697586091519874D1*T121
     #*T182
      T191 = 1/T111
      VSIGMAAA(I) = RHOA*(0.1236778371778789D-1*T185*T140
     #+0.7937005259840997D0*T64*T23*T70-0.130605864926168D1*T65*T191
     #*T70)
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = 0.D0
      T204 = LOG(1.D0+0.160818243221511D2/(0.598255043577108D1*T6
     #+0.2225569421150687D1*T3+0.8004286349993634D0*T9
     #+0.1897004325747559D0*T11))
      T214 = 1/T21/T32
      T217 = T106**2
      T218 = T35*T217
      T220 = EXP(0.5027578216020225D1*T18)
      T221 = T218*T220
      T225 = T113*T106*T27
      T228 = 1/T101
      T229 = T75*T228
      T231 = 0.1D-22*T229*T204
      T234 = 1/T32
      T235 = 1/T11/T2*T234
      T237 = 0.8806734334819047D-3*T235*T17
      T239 = 0.2642020300445714D-2*T229*T17
      T243 = 0.8497974591333914D-1*T77*T81*T96*T97
      T247 = T96**2
      T250 = 0.2D1*T5/T80/T13*T247*T97
      T267 = 1/T3/T2*T234
      T269 = T93*T228
      T274 = 0.1D1*T82*(-0.1544496508763151D1/T85/T2*T234
     #+0.3706791621031562D1*T86*T228-0.854388052766047D0*T235
     #+0.2563164158298141D1*T229-0.4111834438919023D0/T9/T2*T234
     #+0.1644733775567609D1*T90*T228-0.5346380647307093D-1*T267
     #+0.3207828388384256D0*T269)*T97
      T275 = T80**2
      T278 = T16**2
      T282 = 0.321646831778707D2*T5/T275*T247/T278
      T283 = -T231+T237-T239-T243-T250+T274+T282
      T285 = T35*T283*T27
      T288 = T218*T27
      T292 = 1/T33/T165
      T303 = T38/T119/T47
      T304 = T136**2
      T308 = T23*T217
      T325 = T42**2
      T344 = T139**2
      T345 = T51**2
      T346 = 1/T345
      T362 = T154**2
      T379 = T32**2
      T386 = T32*T101
      S3 = 0.1236778371778789D-1*(0.2697586091519874D1*
     #(0.7836071998691172D0*SIGMAAA*T214+0.3580200260842915D3*T131
     #*T221-0.2066359982982071D2*T44*T225+0.2213957124623647D1*T44
     #*T285-0.1790100130421458D3*T44*T288+0.7240949783240664D0*T31
     #*T292)*T48-0.5395172183039748D1*T116*T120*T136
     #+0.5395172183039748D1*T303*T304-0.2697586091519874D1*T121*
     #(0.35535663829313D4*T130*SIGMAAA*T308*T220-0.1025493943854243D3
     #*T122*T103*T106*T27+0.2197487022544806D2*T122*T23*T283*T27
     #-0.177678319146565D4*T122*T308*T27+0.2113847883581765D1*T39*T214
     #+0.2897369528551702D4/T325*T30*T221-0.1114836790033136D3*T131
     #*T225+0.1194467989321217D2*T131*T285-0.9657898428505673D3*T131
     #*T288+0.1953308542466386D1*T44*T292))*T140
      S4 = -0.1236778371778789D-1*T344*T346+0.7937005259840997D0*
     #(0.1D-2*(-0.3207349893614542D1*T235+0.9622049680843627D1*T229
     #-0.6318986292200858D-3*T267+0.3791391775320515D-2*T269)*T61
     #-0.2D-2*T145*T149*T154+0.2D-2*T56/T148/T60*T362-0.1D-2*T150*(
     #-0.1202514962692326D1*T235+0.3607544888076978D1*T229
     #-0.4036488739909061D-1*T267+0.2421893243945437D0*T269
     #+0.3527987623518044D-1*T228))*SIGMAAA*T71
      S2 = S3+S4
      S1 = S2+0.1528291352075288D2*T64*T30*SIGMAAA/T33/T379/RHOA*T70
     #-0.2902352553914844D2*T164/T386*T70+0.6173226313209665D1*T65
     #*T214*T70-0.3703935787925799D1*T158*T161
      T399 = S1+0.6965646129395627D1*T157*T30*T167-T231-T250+T274+T282
     #+T237-T239-T243
      V2RHOA2(I) = -0.1D-22*T77*T204+0.2642020300445714D-2*T78+0.2D1
     #*T99+0.2473556743557577D-1*T141+0.1587401051968199D1*T159
     #-0.3703935787925799D1*T162+0.6965646129395627D1*T168+RHOA*T399
      V2RHOB2(I) = 0.D0
      V2RHOAB(I) = 0.D0
      T407 = T182**2
      T416 = T185**2
      V2SIGMAAA2(I) = RHOA*(0.1236778371778789D-1*
     #(0.1477292174974578D0*T29*T35*T48-0.5395172183039748D1*T175*T120
     #*T182+0.5395172183039748D1*T303*T407-0.3985122824322565D0*T121
     #*T43*T35)*T140-0.1236778371778789D-1*T416*T346
     #-0.261211729852336D1*T64*T191*T70+0.2149159713855873D1*T65/T33
     #/T386*T70)
      V2SIGMAAAAB(I) = 0.D0
      V2SIGMAAABB(I) = 0.D0
      V2SIGMAAB2(I) = 0.D0
      V2SIGMAABBB(I) = 0.D0
      V2SIGMABB2(I) = 0.D0
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMAAB = SIGMAAB1(I)
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMAAA+SIGMABB+2.D0*SIGMAAB
      T4 = 1/RHO
      T5 = T4**(1.D0/3.D0)
      T7 = 1.D0+0.1325688999052018D0*T5
      T8 = T4**(1.D0/6.D0)
      T11 = SQRT(T4)
      T13 = T5**2
      T15 = 0.598255043577108D1*T8+0.2225569421150687D1*T5
     #+0.8004286349993634D0*T11+0.1897004325747559D0*T13
      T18 = 1.D0+0.160818243221511D2/T15
      T19 = LOG(T18)
      T21 = 0.62182D-1*T7*T19
      T23 = 1.D0+0.6901399211255825D-1*T5
      T28 = 0.8157414703487641D1*T8+0.2247591863577616D1*T5
     #+0.4300972471276643D0*T11+0.1911512595127338D0*T13
      T31 = 1.D0+0.2960857464321668D2/T28
      T32 = LOG(T31)
      T33 = T23*T32
      T35 = RHOA-1.D0*RHOB
      T36 = T35*T4
      T37 = 1.D0+T36
      T38 = T37**(1.D0/3.D0)
      T39 = T38*T37
      T41 = 1.D0-1.D0*T36
      T42 = T41**(1.D0/3.D0)
      T43 = T42*T41
      T44 = T39+T43-2.D0
      T45 = T35**2
      T46 = T45**2
      T47 = RHO**2
      T48 = T47**2
      T49 = 1/T48
      T50 = T46*T49
      T52 = 1.D0-1.D0*T50
      T53 = T44*T52
      T55 = 0.3799575D-1*T33*T53
      T57 = 1.D0+0.1274696188700087D0*T5
      T62 = 0.1112037486309468D2*T8+0.3844746237447211D1*T5
     #+0.1644733775567609D1*T11+0.2405871291288192D0*T13
      T65 = 1.D0+0.321646831778707D2/T62
      T66 = LOG(T65)
      T69 = -0.3109D-1*T57*T66+T21
      T70 = T69*T44
      T72 = 0.1923661050931536D1*T70*T50
      T73 = T38**2
      T75 = T42**2
      T77 = 0.5D0*T73+0.5D0*T75
      T78 = T77**2
      T79 = T78*T77
      T80 = 1/T78
      T81 = SIGMA*T80
      T82 = RHO**(1.D0/3.D0)
      T84 = 1/T82/T47
      T87 = -T21+T55+T72
      T88 = 1/T79
      T89 = T87*T88
      T91 = EXP(-0.4042761511756372D2*T89)
      T92 = T91-1.D0
      T93 = 1/T92
      T94 = SIGMA**2
      T95 = T93*T94
      T96 = T78**2
      T97 = 1/T96
      T98 = T82**2
      T100 = 1/T98/T48
      T101 = T97*T100
      T104 = 0.634682060977037D-1*T81*T84+0.1086645186223595D-1*T95*T101
      T105 = T93*SIGMA
      T106 = T80*T84
      T109 = T92**2
      T110 = 1/T109
      T111 = T110*T94
      T114 = 1.D0+0.1712109500228824D0*T105*T106+0.2931318940773793D-1
     #*T111*T101
      T115 = 1/T114
      T118 = 1.D0+0.2697586091519874D1*T104*T115
      T119 = LOG(T118)
      T121 = 0.2473556743557577D-1*T79*T119
      T124 = 0.2568D1+0.1443307452126544D2*T5+0.2843543831490386D-2*T13
      T128 = 1.D0+0.5411317332115466D1*T5+0.1816419932959077D0*T13
     #+0.1763993811759022D-1*T4
      T129 = 1/T128
      T132 = 0.1D-2*T124*T129-0.1853571428571429D-2
      T133 = T132*T77
      T136 = 1/T98/T47
      T140 = EXP(-0.261211729852336D1*T78*T136*SIGMA)
      T141 = SIGMA*T84*T140
      T143 = 0.1D1*T133*T141
      ZK(I) = RHO*(-T21+T55+T72+T121+T143)
      T149 = 0.1333333333333333D1*T38*T4-0.1333333333333333D1*T42*T4
      T151 = T33*T149*T52
      T152 = 0.3799575D-1*T151
      T153 = T45*T35
      T154 = T44*T153
      T156 = T33*T154*T49
      T157 = 0.151983D0*T156
      T158 = T69*T149
      T159 = T158*T50
      T160 = 0.1923661050931536D1*T159
      T161 = T153*T49
      T162 = T70*T161
      T163 = 0.7694644203726145D1*T162
      T164 = T78*T119
      T165 = 1/T38
      T168 = 1/T42
      T171 = 0.3333333333333333D0*T165*T4-0.3333333333333333D0*T168*T4
      T172 = T164*T171
      T173 = 0.7420670230672731D-1*T172
      T174 = SIGMA*T88
      T175 = T84*T171
      T178 = T111*T97
      T179 = T152-T157+T160+T163
      T182 = T87*T97
      T185 = -0.4042761511756372D2*T179*T88+0.1212828453526912D3*T182
     #*T171
      T186 = T100*T185
      T187 = T186*T91
      T190 = T96*T77
      T191 = 1/T190
      T192 = T191*T100
      T193 = T192*T171
      T196 = -0.1269364121954074D0*T174*T175-0.1086645186223595D-1
     #*T178*T187-0.4346580744894379D-1*T95*T193
      T199 = T114**2
      T200 = 1/T199
      T201 = T104*T200
      T202 = T110*SIGMA
      T203 = T202*T80
      T204 = T84*T185
      T205 = T204*T91
      T208 = T88*T84
      T209 = T208*T171
      T213 = 1/T109/T92
      T214 = T213*T94
      T215 = T214*T97
      T220 = -0.1712109500228824D0*T203*T205-0.3424219000457648D0*T105
     #*T209-0.5862637881547585D-1*T215*T187-0.1172527576309517D0*T111
     #*T193
      T223 = 0.2697586091519874D1*T196*T115-0.2697586091519874D1*T201
     #*T220
      T224 = T79*T223
      T225 = 1/T118
      T226 = T224*T225
      T227 = 0.2473556743557577D-1*T226
      T228 = T132*T171
      T229 = T228*T141
      T230 = 0.1D1*T229
      T232 = T132*T78*T94
      T233 = T48*RHO
      T234 = 1/T233
      T236 = T234*T171*T140
      T237 = T232*T236
      T238 = 0.522423459704672D1*T237
      T241 = 1/T13
      T242 = 1/T47
      T243 = T241*T242
      T244 = T243*T19
      T245 = 0.2747799777968419D-2*T244
      T246 = T15**2
      T247 = 1/T246
      T248 = T7*T247
      T249 = T8**2
      T250 = T249**2
      T251 = T250*T8
      T252 = 1/T251
      T253 = T252*T242
      T256 = 1/T11
      T257 = T256*T242
      T259 = 1/T5
      T260 = T259*T242
      T262 = -0.99709173929518D0*T253-0.7418564737168958D0*T243
     #-0.4002143174996817D0*T257-0.1264669550498372D0*T260
      T263 = 1/T18
      T265 = T248*T262*T263
      T266 = 0.1D1*T265
      T267 = T32*T44
      T268 = T267*T52
      T269 = T243*T268
      T270 = 0.8740794636035784D-3*T269
      T271 = T28**2
      T272 = 1/T271
      T273 = T23*T272
      T278 = -0.135956911724794D1*T253-0.7491972878592054D0*T243
     #-0.2150486235638321D0*T257-0.1274341730084892D0*T260
      T279 = T273*T278
      T280 = 1/T31
      T281 = T280*T44
      T282 = T281*T52
      T283 = T279*T282
      T284 = 0.1125D1*T283
      T285 = T38*T35
      T288 = T42*T35
      T291 = -0.1333333333333333D1*T285*T242+0.1333333333333333D1*T288
     #*T242
      T293 = T33*T291*T52
      T294 = 0.3799575D-1*T293
      T295 = T44*T46
      T297 = T33*T295*T234
      T298 = 0.151983D0*T297
      T301 = T62**2
      T302 = 1/T301
      T303 = T57*T302
      T308 = -0.1853395810515781D1*T253-0.128158207914907D1*T243
     #-0.8223668877838045D0*T257-0.1603914194192128D0*T260
      T309 = 1/T65
      T315 = 0.1321010150222857D-2*T243*T66+0.1D1*T303*T308*T309
     #-0.2747799777968419D-2*T244-0.1D1*T265
      T316 = T315*T44
      T317 = T316*T50
      T318 = 0.1923661050931536D1*T317
      T319 = T69*T291
      T320 = T319*T50
      T321 = 0.1923661050931536D1*T320
      T322 = T46*T234
      T323 = T70*T322
      T324 = 0.7694644203726145D1*T323
      T325 = T165*T35
      T328 = T168*T35
      T331 = -0.3333333333333333D0*T325*T242+0.3333333333333333D0*T328
     #*T242
      T332 = T164*T331
      T334 = T84*T331
      T337 = T47*RHO
      T339 = 1/T82/T337
      T342 = T245+T266-T270-T284+T294+T298+T318+T321-T324
      T347 = -0.4042761511756372D2*T342*T88+0.1212828453526912D3*T182
     #*T331
      T348 = T100*T347
      T349 = T348*T91
      T352 = T192*T331
      T356 = 1/T98/T233
      T357 = T97*T356
      T360 = -0.1269364121954074D0*T174*T334-0.148092480894642D0*T81
     #*T339-0.1086645186223595D-1*T178*T349-0.4346580744894379D-1*T95
     #*T352-0.5071010869043442D-1*T95*T357
      T363 = T84*T347
      T364 = T363*T91
      T367 = T208*T331
      T370 = T80*T339
      T379 = -0.1712109500228824D0*T203*T364-0.3424219000457648D0*T105
     #*T367-0.3994922167200589D0*T105*T370-0.5862637881547585D-1*T215
     #*T349-0.1172527576309517D0*T111*T352-0.136794883902777D0*T111*T357
      T382 = 0.2697586091519874D1*T360*T115-0.2697586091519874D1*T201
     #*T379
      T383 = T79*T382
      T384 = T383*T225
      T388 = -0.4811024840421814D1*T243-0.1895695887660258D-2*T260
      T391 = T128**2
      T392 = 1/T391
      T393 = T124*T392
      T397 = -0.1803772444038489D1*T243-0.1210946621972718D0*T260
     #-0.1763993811759022D-1*T242
      T400 = 0.1D-2*T388*T129-0.1D-2*T393*T397
      T401 = T400*T77
      T402 = T401*T141
      T404 = T132*T331
      T405 = T404*T141
      T408 = SIGMA*T339*T140
      T409 = T133*T408
      T411 = T133*SIGMA
      T412 = T77*T136
      T413 = SIGMA*T331
      T417 = 1/T98/T337
      T418 = T78*T417
      T421 = -0.522423459704672D1*T412*T413+0.6965646129395627D1*T418
     #*SIGMA
      T423 = T84*T421*T140
      T424 = T411*T423
      T426 = T245+T266-T270-T284+T294+T298+T318+T321-T324
     #+0.7420670230672731D-1*T332+0.2473556743557577D-1*T384+0.1D1
     #*T402+0.1D1*T405-0.2333333333333333D1*T409+0.1D1*T424
      T427 = RHO*T426
      VRHOA(I) = RHO*(T152-T157+T160+T163+T173+T227+T230-T238)-T21+T55
     #+T72+T121+T143+T427
      T428 = -T149
      T430 = T33*T428*T52
      T431 = 0.3799575D-1*T430
      T432 = 0.151983D0*T156
      T433 = T69*T428
      T434 = T433*T50
      T435 = 0.1923661050931536D1*T434
      T436 = 0.7694644203726145D1*T162
      T437 = -T171
      T438 = T164*T437
      T439 = 0.7420670230672731D-1*T438
      T440 = T84*T437
      T443 = T431+T432+T435-T436
      T448 = -0.4042761511756372D2*T443*T88+0.1212828453526912D3*T182
     #*T437
      T449 = T100*T448
      T450 = T449*T91
      T453 = T192*T437
      T456 = -0.1269364121954074D0*T174*T440-0.1086645186223595D-1
     #*T178*T450-0.4346580744894379D-1*T95*T453
      T459 = T84*T448
      T460 = T459*T91
      T463 = T208*T437
      T470 = -0.1712109500228824D0*T203*T460-0.3424219000457648D0*T105
     #*T463-0.5862637881547585D-1*T215*T450-0.1172527576309517D0*T111
     #*T453
      T473 = 0.2697586091519874D1*T456*T115-0.2697586091519874D1*T201
     #*T470
      T474 = T79*T473
      T475 = T474*T225
      T476 = 0.2473556743557577D-1*T475
      T477 = T132*T437
      T478 = T477*T141
      T479 = 0.1D1*T478
      T481 = T234*T437*T140
      T482 = T232*T481
      T483 = 0.522423459704672D1*T482
      VRHOB(I) = RHO*(T431+T432+T435-T436+T439+T476+T479-T483)-T21+T55
     #+T72+T121+T143+T427
      T489 = 0.634682060977037D-1*T106+0.2173290372447189D-1*T105*T101
      T492 = T93*T80
      T497 = 0.1712109500228824D0*T492*T84+0.5862637881547585D-1*T202
     #*T101
      T500 = 0.2697586091519874D1*T489*T115-0.2697586091519874D1*T201
     #*T497
      T502 = T79*T500*T225
      T503 = 0.2473556743557577D-1*T502
      T504 = T84*T140
      T505 = T133*T504
      T506 = 0.1D1*T505
      T507 = T132*T79
      T509 = SIGMA*T234*T140
      T510 = T507*T509
      T511 = 0.261211729852336D1*T510
      VSIGMAAA(I) = RHO*(T503+T506-T511)
      VSIGMAAB(I) = 2.D0*VSIGMAAA(I)
      VSIGMABB(I) = VSIGMAAA(I)
      T519 = 0.5495599555936838D-2*T244
      T520 = 0.2D1*T265
      T521 = 0.759915D-1*T293
      T522 = 0.3847322101863073D1*T317
      T523 = 0.3847322101863073D1*T320
      T524 = 0.1538928840745229D2*T323
      T526 = 0.759915D-1*T151+0.3847322101863073D1*T159
     #+0.1538928840745229D2*T162+0.1484134046134546D0*T172-0.303966D0
     #*T156+0.4947113487115154D-1*T226+T519+T520+T521+T522+T523-T524
     #+0.2D1*T229
      T528 = 0.1748158927207157D-2*T269
      T529 = 0.225D1*T283
      T530 = 0.1484134046134546D0*T332
      T531 = 0.303966D0*T297
      T532 = 0.4947113487115154D-1*T384
      T533 = 0.2D1*T402
      T534 = 0.2D1*T405
      T537 = 1/T13/T4*T49
      T539 = 1/T337
      T540 = T241*T539
      T544 = 1/T5/T4*T49
      T546 = T259*T539
      T557 = T397**2
      T577 = T421**2
      T583 = 1/T82/T48
      T590 = T331**2
      T594 = T77*T417
      T597 = 1/T39
      T603 = 1/T43
      T609 = -0.1111111111111111D0*T597*T45*T49+0.6666666666666667D0
     #*T325*T539-0.1111111111111111D0*T603*T45*T49
     #-0.6666666666666667D0*T328*T539
      T621 = T404*SIGMA
      T627 = T111*T191
      T628 = T91*T331
      T629 = T348*T628
      T633 = T356*T347*T91
      T636 = T537*T19
      T637 = 0.1831866518645613D-2*T636
      T638 = T540*T19
      T639 = 0.5495599555936838D-2*T638
      T642 = 0.9D1*T279*T281*T322
      T646 = 0.1748158927207157D-2*T243*T32*T291*T52
      T648 = 0.5827196424023856D-3*T537*T268
      T651 = T243*T247*T262*T263
      T652 = 0.8837926660346786D-1*T651
      T656 = T262**2
      T658 = T7/T246/T15*T656*T263
      T659 = 0.2D1*T658
      T662 = 1/T251/T4*T49
      T664 = T252*T539
      T670 = 1/T11/T4*T49
      T672 = T256*T539
      T678 = T248*(-0.8309097827459833D0*T662+0.199418347859036D1*T664
     #-0.4945709824779306D0*T537+0.1483712947433792D1*T540
     #-0.2001071587498409D0*T670+0.8004286349993634D0*T672
     #-0.4215565168327908D-1*T544+0.2529339100996745D0*T546)*T263
      T679 = 0.1D1*T678
      T680 = T246**2
      T683 = T18**2
      T686 = T7/T680*T656/T683
      T687 = 0.160818243221511D2*T686
      T699 = T308**2
      T715 = T301**2
      T718 = T65**2
      T729 = 0.8806734334819047D-3*T537*T66-0.2642020300445714D-2*T540
     #*T66-0.8497974591333914D-1*T243*T302*T308*T309-0.2D1*T57/T301
     #/T62*T699*T309+0.1D1*T303*(-0.1544496508763151D1*T662
     #+0.3706791621031562D1*T664-0.854388052766047D0*T537
     #+0.2563164158298141D1*T540-0.4111834438919023D0*T670
     #+0.1644733775567609D1*T672-0.5346380647307093D-1*T544
     #+0.3207828388384256D0*T546)*T309+0.321646831778707D2*T57/T715
     #*T699/T718-0.1831866518645613D-2*T636+0.5495599555936838D-2*T638
     #+0.8837926660346786D-1*T651+0.2D1*T658-0.1D1*T678
     #-0.160818243221511D2*T686
      T732 = 0.1923661050931536D1*T729*T44*T50
      T733 = 1/T73
      T739 = 1/T75
      T745 = 0.4444444444444444D0*T733*T45*T49+0.2666666666666667D1
     #*T285*T539+0.4444444444444444D0*T739*T45*T49
     #-0.2666666666666667D1*T288*T539
      T748 = 0.1923661050931536D1*T69*T745*T50
      T749 = T48*T47
      T750 = 1/T749
      T753 = 0.3847322101863073D2*T70*T46*T750
      T754 = T637-T639-T642-T646-T648-T652-T659+T679+T687+T732+T748+T753
      T757 = 0.3799575D-1*T33*T745*T52
      T759 = 0.1538928840745229D2*T319*T322
      T761 = 0.1538928840745229D2*T316*T322
      T764 = 0.3847322101863073D1*T315*T291*T50
      T765 = T271**2
      T768 = T278**2
      T770 = T31**2
      T775 = 0.3330964647361876D2*T23/T765*T768/T770*T44*T52
      T779 = 0.303966D0*T33*T291*T46*T234
      T785 = 0.225D1*T23/T271/T28*T768*T282
      T787 = 0.1748158927207157D-2*T540*T268
      T788 = T48*T337
      T793 = 0.6992635708828627D-2*T241/T788*T267*T46
      T798 = 0.5176049408441869D-1*T243*T272*T278*T280*T53
      T802 = 0.225D1*T279*T280*T291*T52
      T814 = 0.1125D1*T273*(-0.1132974264373283D1*T662
     #+0.271913823449588D1*T664-0.4994648585728036D0*T537
     #+0.1498394575718411D1*T540-0.1075243117819161D0*T670
     #+0.4300972471276643D0*T672-0.4247805766949639D-1*T544
     #+0.2548683460169784D0*T546)*T282
      T817 = 0.759915D0*T33*T295*T750
         T818 = T757-T759-T761+T764-T775+T779+T785+T787-T793+T798-T802
     #-T814-T817
      T822 = T342*T97
      T825 = T87*T191
      T830 = -0.4042761511756372D2*(T754+T818)*T88
     #+0.2425656907053823D3*T822*T331-0.4851313814107647D3*T825*T590
     #+0.1212828453526912D3*T182*T609
      T832 = T100*T830*T91
      T835 = SIGMA*T97
      T847 = T347**2
      T848 = T100*T847
      T850 = EXP(-0.8085523023512745D2*T89)
      T851 = T848*T850
      T854 = T848*T91
      T859 = T97/T98/T749
      T863 = 1/T96/T78
      T864 = T863*T100
      T865 = T864*T590
      T868 = T191*T356
      T869 = T868*T331
      T872 = T192*T609
      T875 = 0.8693161489788758D-1*T627*T629+0.1014202173808688D0*T178
     #*T633-0.1086645186223595D-1*T178*T832+0.3808092365862222D0*T835
     #*T84*T590+0.5923699235785679D0*T174*T339*T331
     #-0.1269364121954074D0*T174*T84*T609+0.4936416029821399D0*T81
     #*T583+0.2173290372447189D-1*T215*T851-0.1086645186223595D-1*T178
     #*T854+0.2873572825791284D0*T95*T859+0.2173290372447189D0*T95
     #*T865+0.4056808695234754D0*T95*T869-0.4346580744894379D-1*T95*T872
      T878 = T360*T200
      T883 = T104/T199/T114
      T884 = T379**2
      T891 = T202*T88
      T903 = T97*T84
      T907 = T88*T339
      T914 = T213*SIGMA
      T915 = T914*T80
      T916 = T84*T847
      T926 = T109**2
      T929 = 1/T926*T94*T97
      T932 = T214*T191
      T945 = 0.547179535611108D0*T215*T633+0.5862637881547585D0*T111
     #*T865+0.6848438000915295D0*T891*T363*T628-0.1712109500228824D0
     #*T203*T84*T830*T91+0.7989844334401178D0*T203*T339*T347*T91
     #+0.1027265700137294D1*T105*T903*T590+0.1597968866880236D1*T105
     #*T907*T331-0.3424219000457648D0*T105*T208*T609
     #+0.3424219000457648D0*T915*T916*T850+0.1331640722400196D1*T105
     #*T80*T583-0.1712109500228824D0*T203*T916*T91
     #+0.1758791364464276D0*T929*T851+0.4690110305238068D0*T932*T629
     #-0.5862637881547585D-1*T215*T854+0.7751710087824029D0*T111*T859
     #-0.5862637881547585D-1*T215*T832+0.1094359071222216D1*T111*T869
     #-0.1172527576309517D0*T111*T872
      T952 = T77*T119
      S2 = 0.1D1*(0.1D-2*(-0.3207349893614542D1*T537
     #+0.9622049680843627D1*T540-0.6318986292200858D-3*T544
     #+0.3791391775320515D-2*T546)*T129-0.2D-2*T388*T392*T397+0.2D-2
     #*T124/T391/T128*T557-0.1D-2*T393*(-0.1202514962692326D1*T537
     #+0.3607544888076978D1*T540-0.4036488739909061D-1*T544
     #+0.2421893243945437D0*T546+0.3527987623518044D-1*T539))*T77*T141
     #-0.4666666666666667D1*T401*T408+0.2D1*T400*T331*T141+0.1D1*T411
     #*T84*T577*T140+0.7777777777777778D1*T133*SIGMA*T583*T140
      S1 = S2-0.4666666666666667D1*T404*T408+0.1D1*T411*T84*(
     #-0.522423459704672D1*T590*T136*SIGMA+0.2786258451758251D2*T594
     #*T413-0.522423459704672D1*T412*SIGMA*T609-0.2554070247445063D2
     #*T78*T100*SIGMA)*T140+0.2D1*T621*T423+0.1D1*T132*T609*T141
     #+0.2473556743557577D-1*T79*(0.2697586091519874D1*T875*T115
     #-0.5395172183039748D1*T878*T379+0.5395172183039748D1*T883*T884
     #-0.2697586091519874D1*T201*T945)*T225
      T955 = S1+0.1484134046134546D0*T952*T590+T637-T639-T642-T646
     #-T648-T652-T659+T679+T687
      T956 = T382**2
      T958 = T118**2
      T959 = 1/T958
      T963 = T78*T382
      T964 = T225*T331
      T976 = T785+T787-T793+T798-T802-T814+0.1484134046134546D0*T963
     #*T964-T817-0.4666666666666667D1*T411*T339*T421*T140
     #+0.7420670230672731D-1*T164*T609+0.2D1*T401*SIGMA*T423
      T979 = RHO*(T955+T732+T748+T753+T757-T759-T761+T764-T775
     #-0.2473556743557577D-1*T79*T956*T959+T779+T976)
      T980 = 0.4666666666666667D1*T409
      T981 = 0.2D1*T424
      T982 = T78*T223
      T985 = T331*T171
      T998 = -0.4444444444444444D0*T733*T35*T539-0.1333333333333333D1
     #*T38*T242-0.4444444444444444D0*T739*T35*T539
     #+0.1333333333333333D1*T42*T242
      T1001 = 0.3799575D-1*T33*T998*T52
      T1003 = 0.7694644203726145D1*T158*T322
      T1014 = 0.1111111111111111D0*T597*T35*T539-0.3333333333333333D0
     #*T165*T242+0.1111111111111111D0*T603*T35*T539
     #+0.3333333333333333D0*T168*T242
      T1020 = 0.8740794636035784D-3*T243*T32*T149*T52
      T1024 = 0.1125D1*T279*T280*T149*T52
      T1026 = T33*T154*T234
      T1027 = 0.607932D0*T1026
      T1030 = T33*T291*T153*T49
      T1031 = 0.151983D0*T1030
      T1034 = T241*T750*T267*T153
      T1035 = 0.3496317854414314D-2*T1034
      T1038 = 0.1923661050931536D1*T315*T149*T50
      T1041 = 0.1923661050931536D1*T69*T998*T50
      T1042 = T316*T161
      T1043 = 0.7694644203726145D1*T1042
      T1044 = T319*T161
      T1045 = 0.7694644203726145D1*T1044
      T1046 = 0.7420670230672731D-1*T982*T964+0.1484134046134546D0
     #*T952*T985+T1001-T1003+0.7420670230672731D-1*T164*T1014-T1020
     #-T1024+T1027-T1031+T1035+T1038+T1041+T1043+T1045
      T1048 = T70*T153*T234
      T1049 = 0.3077857681490458D2*T1048
      T1053 = 0.151983D0*T33*T149*T46*T234
      T1055 = 0.2333333333333333D1*T228*T408
      T1056 = T334*T171
      T1058 = 0.3808092365862222D0*T835*T1056
      T1061 = 0.1269364121954074D0*T174*T84*T1014
      T1064 = 0.296184961789284D0*T174*T339*T171
      T1065 = T850*T185
      T1066 = T348*T1065
      T1068 = 0.2173290372447189D-1*T215*T1066
      T1069 = T91*T171
      T1070 = T348*T1069
      T1072 = 0.4346580744894379D-1*T627*T1070
      T1074 = T279*T281*T161
      T1075 = 0.45D1*T1074
      T1076 = -T1020+T1035-T1024+T1075+T1001-T1031+T1053+T1027+T1038
     #+T1043+T1041+T1045-T1003-T1049
      T1080 = 0.1212828453526912D3*T822*T171
      T1081 = T179*T97
      T1083 = 0.1212828453526912D3*T1081*T331
      T1085 = 0.4851313814107647D3*T825*T985
      T1087 = 0.1212828453526912D3*T182*T1014
      T1088 = -0.4042761511756372D2*T1076*T88+T1080+T1083-T1085+T1087
      T1090 = T100*T1088*T91
      T1093 = T185*T91
      T1094 = T348*T1093
      T1096 = 0.1086645186223595D-1*T178*T1094
      T1097 = T100*T331
      T1098 = T1097*T1093
      T1100 = 0.4346580744894379D-1*T627*T1098
      T1101 = T95*T863
      T1102 = T1097*T171
      T1104 = 0.2173290372447189D0*T1101*T1102
      T1105 = T192*T1014
      T1107 = 0.4346580744894379D-1*T95*T1105
      T1109 = T356*T185*T91
      T1111 = 0.5071010869043442D-1*T178*T1109
      T1112 = T868*T171
      T1114 = 0.2028404347617377D0*T95*T1112
      T1115 = T1058-T1061+T1064+T1068+T1072-0.1086645186223595D-1*T178
     #*T1090-T1096+T1100+T1104-T1107+T1111+T1114
      T1119 = 0.2697586091519874D1*T878*T220
      T1120 = T196*T200
      T1122 = 0.2697586091519874D1*T1120*T379
      T1125 = 0.5395172183039748D1*T883*T379*T220
      T1128 = 0.3424219000457648D0*T915*T363*T1065
      T1131 = 0.3424219000457648D0*T891*T363*T1069
      T1138 = 0.1712109500228824D0*T203*T363*T1093
      T1141 = 0.3424219000457648D0*T891*T334*T1093
      T1142 = T105*T97
      T1144 = 0.1027265700137294D1*T1142*T1056
      T1147 = 0.3424219000457648D0*T105*T208*T1014
      T1151 = 0.3994922167200589D0*T203*T339*T185*T91
      T1154 = 0.7989844334401178D0*T105*T907*T171
      T1156 = 0.1758791364464276D0*T929*T1066
      T1158 = 0.2345055152619034D0*T932*T1070
      T1162 = 0.5862637881547585D-1*T215*T1094
      T1164 = 0.2345055152619034D0*T932*T1098
      T1165 = T111*T863
      T1167 = 0.5862637881547585D0*T1165*T1102
      T1169 = 0.1172527576309517D0*T111*T1105
      T1171 = 0.273589767805554D0*T215*T1109
      T1173 = 0.547179535611108D0*T111*T1112
      T1174 = T1128+T1131-0.1712109500228824D0*T203*T84*T1088*T91
     #-T1138+T1141+T1144-T1147+T1151+T1154+T1156+T1158
     #-0.5862637881547585D-1*T215*T1090-T1162+T1164+T1167-T1169+T1171
     #+T1173
      T1183 = 0.2473556743557577D-1*T383*T959*T223
      T1200 = 0.1D1*T400*T171*T141
      T1202 = T400*T78*T94
      T1204 = 0.522423459704672D1*T1202*T236
      T1207 = 0.1D1*T132*T1014*T141
      T1208 = T404*T94
      T1209 = T234*T77
      T1210 = T171*T140
      T1212 = T1208*T1209*T1210
      T1214 = T234*T421
      T1217 = 0.522423459704672D1*T232*T1214*T1210
      T1220 = T232*T750*T171*T140
      T1222 = T225*T171
      T1224 = 0.7420670230672731D-1*T963*T1222
      T1225 = T228*SIGMA
      T1227 = 0.1D1*T1225*T423
      T1228 = -T1049+T1053-T1055+0.2473556743557577D-1*T79*
     #(0.2697586091519874D1*T1115*T115-T1119-T1122+T1125
     #-0.2697586091519874D1*T201*T1174)*T225-T1183+T1075+0.1D1*T411
     #*T84*(-0.522423459704672D1*T171*T136*T413-0.522423459704672D1
     #*T412*SIGMA*T1014+0.1393129225879125D2*T594*SIGMA*T171)*T140
     #+T1200-T1204+T1207-0.522423459704672D1*T1212-T1217
     #+0.1218988072644235D2*T1220+T1224+T1227
      T1230 = RHO*(T1046+T1228)
      T1235 = 0.45D1*T1074
      T1238 = -T1020-T1024+T1001+T1053+T1035+T1235-T1031+T1027+T1038
     #+T1041-T1003+T1043+T1045-T1049
      T1241 = -0.4042761511756372D2*T1238*T88+T1083+T1080-T1085+T1087
      T1243 = T100*T1241*T91
      T1246 = T1058+T1064-T1061+T1068+T1100+T1111
     #-0.1086645186223595D-1*T178*T1243-T1096+T1072+T1104+T1114-T1107
      T1255 = T1128+T1141+T1151-0.1712109500228824D0*T203*T84*T1241
     #*T91-T1138+T1131+T1144+T1154-T1147+T1156+T1164+T1171
     #-0.5862637881547585D-1*T215*T1243-T1162+T1158+T1167+T1173-T1169
      T1262 = -T1049+T1053-0.522423459704672D1*T232*T234*T1014*T140
     #-T1055-T1183+T1235+T1200-T1204+T1207-0.1044846919409344D2*T1212
     #-T1217+0.261211729852336D2*T1220+0.2473556743557577D-1*T79*
     #(0.2697586091519874D1*T1246*T115-T1122-T1119+T1125
     #-0.2697586091519874D1*T201*T1255)*T225+T1224+T1227
      T1264 = RHO*(T1046+T1262)
      T1269 = 0.4444444444444444D0*T733*T242+0.4444444444444444D0*T739
     #*T242
      T1272 = 0.3799575D-1*T33*T1269*T52
      T1275 = T33*T149*T153*T49
      T1276 = 0.303966D0*T1275
      T1279 = T33*T44*T45*T49
      T1280 = 0.455949D0*T1279
      T1283 = 0.1923661050931536D1*T69*T1269*T50
      T1284 = T158*T161
      T1285 = 0.1538928840745229D2*T1284
      T1287 = T70*T45*T49
      T1288 = 0.2308393261117844D2*T1287
      T1289 = T171**2
      T1298 = -0.1111111111111111D0*T597*T242-0.1111111111111111D0
     #*T603*T242
      T1300 = 0.7420670230672731D-1*T164*T1298
      T1306 = 0.1269364121954074D0*T174*T84*T1298
      T1307 = T185**2
      T1308 = T100*T1307
      T1309 = T1308*T850
      T1312 = T186*T1069
      T1323 = 0.1212828453526912D3*T182*T1298
      T1324 = -0.4042761511756372D2*(T1272-T1276-T1280+T1283+T1285
     #+T1288)*T88+0.2425656907053823D3*T1081*T171-0.4851313814107647D3
     #*T825*T1289+T1323
      T1326 = T100*T1324*T91
      T1329 = T1308*T91
      T1332 = T864*T1289
      T1335 = T192*T1298
      T1337 = 0.4346580744894379D-1*T95*T1335
      T1343 = T220**2
      T1346 = T84*T1307
      T1365 = 0.3424219000457648D0*T105*T208*T1298
      T1377 = 0.1172527576309517D0*T111*T1335
      T1378 = 0.3424219000457648D0*T915*T1346*T850
     #+0.6848438000915295D0*T891*T204*T1069-0.1712109500228824D0*T203
     #*T84*T1324*T91-0.1712109500228824D0*T203*T1346*T91
     #+0.1027265700137294D1*T105*T903*T1289-T1365+0.1758791364464276D0
     #*T929*T1309+0.4690110305238068D0*T932*T1312
     #-0.5862637881547585D-1*T215*T1326-0.5862637881547585D-1*T215
     #*T1329+0.5862637881547585D0*T111*T1332-T1377
      T1385 = T223**2
      T1391 = 0.1D1*T132*T1298*T141
      T1394 = T1209*T140
      T1400 = 0.522423459704672D1*T232*T234*T1298*T140
      T1402 = T507*T94*SIGMA
      T1404 = 1/T98/T788
      T1409 = T1272-T1276-T1280+T1283+T1285+T1288+0.1484134046134546D0
     #*T952*T1289+0.1484134046134546D0*T982*T1222+T1300
     #+0.2473556743557577D-1*T79*(0.2697586091519874D1*
     #(0.3808092365862222D0*T835*T84*T1289-T1306+0.2173290372447189D-1
     #*T215*T1309+0.8693161489788758D-1*T627*T1312
     #-0.1086645186223595D-1*T178*T1326-0.1086645186223595D-1*T178
     #*T1329+0.2173290372447189D0*T95*T1332-T1337)*T115
     #-0.5395172183039748D1*T1120*T220+0.5395172183039748D1*T883*T1343
     #-0.2697586091519874D1*T201*T1378)*T225-0.2473556743557577D-1*T79
     #*T1385*T959+T1391-0.1567270379114016D2*T132*T1289*T94*T1394
     #-T1400+0.272926271249799D2*T1402*T1404*T1289*T140
      T1411 = -0.1044846919409344D2*T237-T528-T529+T530+T531+T532+T533
     #+T534+T979-T980+T981+T1230+T1264+RHO*T1409
      V2RHOA2(I) = T526+T1411
      T1414 = -0.1538928840745229D2*T162+0.303966D0*T156+T519+T520
     #+T521+T522+T523-T524-T528-T529+T530+T531+T532
      T1418 = T78*T473
      T1421 = T331*T437
      T1424 = -T1014
      T1427 = 0.607932D0*T1026
      T1428 = 0.151983D0*T1030
      T1429 = 0.3496317854414314D-2*T1034
      T1430 = 0.7694644203726145D1*T1042
      T1431 = 0.7694644203726145D1*T1044
      T1432 = 0.3077857681490458D2*T1048
      T1433 = T334*T437
      T1442 = T850*T448
      T1443 = T348*T1442
      T1446 = T448*T91
      T1447 = T1097*T1446
      T1451 = T356*T448*T91
      T1457 = 0.8740794636035784D-3*T243*T32*T428*T52
      T1461 = 0.1125D1*T279*T280*T428*T52
      T1462 = -T998
      T1465 = 0.3799575D-1*T33*T1462*T52
      T1469 = 0.151983D0*T33*T428*T46*T234
      T1470 = 0.45D1*T1074
      T1473 = 0.1923661050931536D1*T315*T428*T50
      T1476 = 0.1923661050931536D1*T69*T1462*T50
      T1478 = 0.7694644203726145D1*T433*T322
      T1479 = -T1457-T1461+T1465+T1469-T1429-T1470+T1428-T1427+T1473
     #+T1476-T1478-T1430-T1431+T1432
      T1482 = T443*T97
      T1491 = -0.4042761511756372D2*T1479*T88+0.1212828453526912D3
     #*T1482*T331+0.1212828453526912D3*T822*T437-0.4851313814107647D3
     #*T825*T1421+0.1212828453526912D3*T182*T1424
      T1493 = T100*T1491*T91
      T1496 = T348*T1446
      T1499 = T91*T437
      T1500 = T348*T1499
      T1503 = T1097*T437
      T1506 = T868*T437
      T1509 = T192*T1424
      T1512 = 0.3808092365862222D0*T835*T1433+0.296184961789284D0*T174
     #*T339*T437-0.1269364121954074D0*T174*T84*T1424
     #+0.2173290372447189D-1*T215*T1443+0.4346580744894379D-1*T627
     #*T1447+0.5071010869043442D-1*T178*T1451-0.1086645186223595D-1
     #*T178*T1493-0.1086645186223595D-1*T178*T1496
     #+0.4346580744894379D-1*T627*T1500+0.2173290372447189D0*T1101
     #*T1503+0.2028404347617377D0*T95*T1506-0.4346580744894379D-1*T95
     #*T1509
      T1515 = T456*T200
      T1569 = 0.3424219000457648D0*T915*T363*T1442
     #+0.3424219000457648D0*T891*T334*T1446+0.3994922167200589D0*T203
     #*T339*T448*T91-0.1712109500228824D0*T203*T84*T1491*T91
     #-0.1712109500228824D0*T203*T363*T1446+0.3424219000457648D0*T891
     #*T363*T1499+0.1027265700137294D1*T1142*T1433
     #+0.7989844334401178D0*T105*T907*T437-0.3424219000457648D0*T105
     #*T208*T1424+0.1758791364464276D0*T929*T1443+0.2345055152619034D0
     #*T932*T1447+0.273589767805554D0*T215*T1451-0.5862637881547585D-1
     #*T215*T1493-0.5862637881547585D-1*T215*T1496
     #+0.2345055152619034D0*T932*T1500+0.5862637881547585D0*T1165
     #*T1503+0.547179535611108D0*T111*T1506-0.1172527576309517D0*T111
     #*T1509
      T1576 = T959*T473
      T1585 = 0.7420670230672731D-1*T1418*T964+0.1484134046134546D0
     #*T952*T1421+0.7420670230672731D-1*T164*T1424-T1427+T1428-T1429
     #-T1430-T1431+T1432+0.2473556743557577D-1*T79*
     #(0.2697586091519874D1*T1512*T115-0.2697586091519874D1*T1515*T379
     #-0.2697586091519874D1*T878*T470+0.5395172183039748D1*T883*T379
     #*T470-0.2697586091519874D1*T201*T1569)*T225
     #-0.2473556743557577D-1*T383*T1576-T1470+0.1D1*T132*T1424*T141
     #+0.1D1*T400*T437*T141
      T1587 = 0.522423459704672D1*T1202*T481
      T1588 = T437*T140
      T1589 = T1209*T1588
      T1590 = T1208*T1589
      T1594 = 0.522423459704672D1*T232*T1214*T1588
      T1596 = 0.2333333333333333D1*T477*T408
      T1597 = T225*T437
      T1599 = 0.7420670230672731D-1*T963*T1597
      T1606 = T232*T750*T437*T140
      T1608 = T477*SIGMA
      T1610 = 0.1D1*T1608*T423
      T1611 = -T1587-0.1044846919409344D2*T1590-T1594-T1596+T1599
     #+T1465+T1473+T1476-T1478-0.522423459704672D1*T232*T234*T1424
     #*T140-T1457+0.261211729852336D2*T1606-T1461+T1469+T1610
      T1613 = RHO*(T1585+T1611)
      T1632 = -T1587-0.522423459704672D1*T1590-T1594-T1596+T1599+T1465
     #+T1473+T1476-T1478-T1457+0.1218988072644235D2*T1606-T1461+T1469
     #+T1610+0.1D1*T411*T84*(-0.522423459704672D1*T437*T136*T413
     #-0.522423459704672D1*T412*SIGMA*T1424+0.1393129225879125D2*T594
     #*SIGMA*T437)*T140
      T1634 = RHO*(T1585+T1632)
      T1638 = T33*T428*T153*T49
      T1639 = 0.303966D0*T1638
      T1640 = T433*T161
      T1641 = 0.1538928840745229D2*T1640
      T1642 = T437**2
      T1650 = T448**2
      T1651 = T100*T1650
      T1652 = T1651*T850
      T1655 = T449*T1499
      T1665 = -0.4042761511756372D2*(T1272+T1639-T1280+T1283-T1641
     #+T1288)*T88+0.2425656907053823D3*T1482*T437-0.4851313814107647D3
     #*T825*T1642+T1323
      T1667 = T100*T1665*T91
      T1670 = T1651*T91
      T1673 = T864*T1642
      T1681 = T470**2
      T1684 = T84*T1650
      T1711 = 0.3424219000457648D0*T915*T1684*T850
     #+0.6848438000915295D0*T891*T459*T1499-0.1712109500228824D0*T203
     #*T84*T1665*T91-0.1712109500228824D0*T203*T1684*T91
     #+0.1027265700137294D1*T105*T903*T1642-T1365+0.1758791364464276D0
     #*T929*T1652+0.4690110305238068D0*T932*T1655
     #-0.5862637881547585D-1*T215*T1667-0.5862637881547585D-1*T215
     #*T1670+0.5862637881547585D0*T111*T1673-T1377
      T1718 = T473**2
      T1730 = T1272+T1639-T1280+T1283-T1641+T1288+0.1484134046134546D0
     #*T952*T1642+0.1484134046134546D0*T1418*T1597+T1300
     #+0.2473556743557577D-1*T79*(0.2697586091519874D1*
     #(0.3808092365862222D0*T835*T84*T1642-T1306+0.2173290372447189D-1
     #*T215*T1652+0.8693161489788758D-1*T627*T1655
     #-0.1086645186223595D-1*T178*T1667-0.1086645186223595D-1*T178
     #*T1670+0.2173290372447189D0*T95*T1673-T1337)*T115
     #-0.5395172183039748D1*T1515*T470+0.5395172183039748D1*T883*T1681
     #-0.2697586091519874D1*T201*T1711)*T225-0.2473556743557577D-1*T79
     #*T1718*T959+T1391-0.1567270379114016D2*T132*T1642*T94*T1394
     #-T1400+0.272926271249799D2*T1402*T1404*T1642*T140
      T1732 = 0.759915D-1*T430+0.3847322101863073D1*T434+T533+T534
     #+0.1484134046134546D0*T438+T979-T980+T981+T1613
     #+0.4947113487115154D-1*T475+0.2D1*T478+T1634
     #-0.1044846919409344D2*T482+RHO*T1730
      V2RHOB2(I) = T1414+T1732
      T1733 = T152+T160+T173+T227+T519+T520+T521+T522+T523-T524+T230
     #-T238-T528-T529+T530+T531
      T1738 = -T1269
      T1741 = 0.3799575D-1*T33*T1738*T52
      T1742 = 0.151983D0*T1275
      T1743 = 0.151983D0*T1638
      T1744 = 0.455949D0*T1279
      T1747 = 0.1923661050931536D1*T69*T1738*T50
      T1748 = 0.7694644203726145D1*T1284
      T1749 = 0.7694644203726145D1*T1640
      T1750 = 0.2308393261117844D2*T1287
      T1751 = T171*T437
      T1756 = -T1298
      T1761 = T175*T437
      T1767 = T186*T1442
      T1770 = T186*T1499
      T1784 = -0.4042761511756372D2*(T1741+T1742-T1743+T1744+T1747
     #-T1748+T1749-T1750)*T88+0.1212828453526912D3*T1081*T437
     #+0.1212828453526912D3*T1482*T171-0.4851313814107647D3*T825*T1751
     #+0.1212828453526912D3*T182*T1756
      T1786 = T100*T1784*T91
      T1789 = T186*T1446
      T1792 = T100*T171
      T1793 = T1792*T1446
      T1796 = T1792*T437
      T1799 = T192*T1756
      T1847 = 0.3424219000457648D0*T915*T204*T1442
     #+0.3424219000457648D0*T891*T204*T1499-0.1712109500228824D0*T203
     #*T84*T1784*T91-0.1712109500228824D0*T203*T204*T1446
     #+0.3424219000457648D0*T891*T175*T1446+0.1027265700137294D1*T1142
     #*T1761-0.3424219000457648D0*T105*T208*T1756+0.1758791364464276D0
     #*T929*T1767+0.2345055152619034D0*T932*T1770
     #-0.5862637881547585D-1*T215*T1786-0.5862637881547585D-1*T215
     #*T1789+0.2345055152619034D0*T932*T1793+0.5862637881547585D0
     #*T1165*T1796-0.1172527576309517D0*T111*T1799
      T1866 = T1404*T171
      S1 = T1741+T1742-T1743+T1744+T1747-T1748+T1749-T1750
     #+0.1484134046134546D0*T952*T1751
      S2 = S1+0.7420670230672731D-1*T1418*T1222+0.7420670230672731D-1
     #*T164*T1756+0.7420670230672731D-1*T982*T1597
     #+0.2473556743557577D-1*T79*(0.2697586091519874D1*
     #(0.3808092365862222D0*T835*T1761-0.1269364121954074D0*T174*T84
     #*T1756+0.2173290372447189D-1*T215*T1767+0.4346580744894379D-1
     #*T627*T1770-0.1086645186223595D-1*T178*T1786
     #-0.1086645186223595D-1*T178*T1789+0.4346580744894379D-1*T627
     #*T1793+0.2173290372447189D0*T1101*T1796-0.4346580744894379D-1
     #*T95*T1799)*T115-0.2697586091519874D1*T1120*T470
     #-0.2697586091519874D1*T1515*T220+0.5395172183039748D1*T883*T220
     #*T470-0.2697586091519874D1*T201*T1847)*T225
      T1870 = S2-0.2473556743557577D-1*T224*T1576+0.1D1*T132*T1756
     #*T141-0.1567270379114016D2*T228*T94*T1589-0.522423459704672D1
     #*T232*T234*T1756*T140+0.272926271249799D2*T1402*T1866*T1588
      T1872 = T532+T431+T435+T533+T534+T439+T979-T980+T981+0.5D0*T1613
     #+T476+0.5D0*T1230+T479+0.5D0*T1634-T483+0.5D0*T1264+RHO*T1870
      V2RHOAB(I) = T1733+T1872
      T1873 = T78*T500
      T1877 = T202*T97
      T1887 = T489*T200
      T1893 = T110*T80
      T1896 = T93*T88
      T1899 = T914*T97
      T1911 = T959*T500
      T1917 = T234*T78*T140
      T1921 = T132*T96*T94
      T1926 = RHO*(0.7420670230672731D-1*T1873*T1222
     #+0.2473556743557577D-1*T79*(0.2697586091519874D1*(
     #-0.1269364121954074D0*T209-0.2173290372447189D-1*T1877*T187
     #-0.8693161489788758D-1*T105*T193)*T115-0.2697586091519874D1
     #*T1120*T497-0.2697586091519874D1*T1887*T220+0.5395172183039748D1
     #*T883*T220*T497-0.2697586091519874D1*T201*(-0.1712109500228824D0
     #*T1893*T205-0.3424219000457648D0*T1896*T175-0.1172527576309517D0
     #*T1899*T187-0.2345055152619034D0*T202*T193))*T225
     #-0.2473556743557577D-1*T224*T1911+0.1D1*T228*T504
     #-0.130605864926168D2*T1225*T1917+0.1364631356248995D2*T1921
     #*T1866*T140)
      S1 = 0.7420670230672731D-1*T1873*T964+0.2473556743557577D-1*T79*
     #(0.2697586091519874D1*(-0.1269364121954074D0*T367
     #-0.148092480894642D0*T370-0.2173290372447189D-1*T1877*T349
     #-0.8693161489788758D-1*T105*T352-0.1014202173808688D0*T105*T357)
     #*T115-0.2697586091519874D1*T878*T497-0.2697586091519874D1*T1887
     #*T379+0.5395172183039748D1*T883*T379*T497-0.2697586091519874D1
     #*T201*(-0.1712109500228824D0*T1893*T364-0.3424219000457648D0
     #*T1896*T334-0.3994922167200589D0*T492*T339-0.1172527576309517D0
     #*T1899*T349-0.2345055152619034D0*T202*T352-0.273589767805554D0
     #*T202*T357))*T225-0.2473556743557577D-1*T383*T1911+0.1D1*T401
     #*T504-0.261211729852336D1*T400*T79*T509+0.1D1*T404*T504
      T1998 = S1-0.261211729852336D1*T621*T1917-0.2333333333333333D1
     #*T133*T339*T140+0.6094940363221173D1*T507*SIGMA*T750*T140+0.1D1
     #*T133*T423+0.1D1*T411*T84*(-0.522423459704672D1*T412*T331
     #+0.6965646129395627D1*T418)*T140-0.261211729852336D1*T507*SIGMA
     #*T1214*T140
      T1999 = RHO*T1998
      V2RHOASIGMAAA(I) = T1926+T503+T506-T511+T1999
      T2001 = 0.4947113487115154D-1*T502
      T2002 = 0.2D1*T505
      T2003 = 0.522423459704672D1*T510
      T2004 = 2.D0*T1999
      V2RHOASIGMAAB(I) = 2.D0*T1926+T2001+T2002-T2003+T2004
      V2RHOASIGMABB(I) = V2RHOASIGMAAA(I)
      T2048 = RHO*(0.7420670230672731D-1*T1873*T1597
     #+0.2473556743557577D-1*T79*(0.2697586091519874D1*(
     #-0.1269364121954074D0*T463-0.2173290372447189D-1*T1877*T450
     #-0.8693161489788758D-1*T105*T453)*T115-0.2697586091519874D1
     #*T1515*T497-0.2697586091519874D1*T1887*T470+0.5395172183039748D1
     #*T883*T470*T497-0.2697586091519874D1*T201*(-0.1712109500228824D0
     #*T1893*T460-0.3424219000457648D0*T1896*T440-0.1172527576309517D0
     #*T1899*T450-0.2345055152619034D0*T202*T453))*T225
     #-0.2473556743557577D-1*T474*T1911+0.1D1*T477*T504
     #-0.130605864926168D2*T1608*T1917+0.1364631356248995D2*T1921
     #*T1404*T437*T140)
      V2RHOBSIGMAAA(I) = T2048+T503+T506-T511+T1999
      V2RHOBSIGMAAB(I) = 2.D0*T2048+T2001+T2002-T2003+T2004
      V2RHOBSIGMABB(I) = V2RHOBSIGMAAA(I)
      T2056 = T497**2
      T2067 = T500**2
      V2SIGMAAA2(I) = RHO*(0.2473556743557577D-1*T79*
     #(0.5862637881547585D-1*T93*T97*T100*T115-0.5395172183039748D1
     #*T1887*T497+0.5395172183039748D1*T883*T2056-0.1581497040888031D0
     #*T201*T110*T97*T100)*T225-0.2473556743557577D-1*T79*T2067*T959
     #-0.522423459704672D1*T507*T234*T140+0.6823156781244976D1*T132
     #*T190*SIGMA*T1404*T140)
      V2SIGMAAAAB(I) = 2.D0*V2SIGMAAA2(I)
      V2SIGMAAABB(I) = V2SIGMAAA2(I)
      V2SIGMAAB2(I) = 4.D0*V2SIGMAAABB(I)
      V2SIGMAABBB(I) = V2SIGMAAAAB(I)
      V2SIGMABB2(I) = V2SIGMAAABB(I)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      V2RHOB2(I) = 0.0D0
      V2RHOAB(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      VSIGMAAB(I) = 0.0D0
      VSIGMABB(I) = 0.0D0
      V2RHOASIGMAAA(I) = 0.0D0
      V2RHOASIGMAAB(I) = 0.0D0
      V2RHOASIGMABB(I) = 0.0D0
      V2RHOBSIGMAAA(I) = 0.0D0
      V2RHOBSIGMAAB(I) = 0.0D0
      V2RHOBSIGMABB(I) = 0.0D0
      V2SIGMAAA2(I) = 0.0D0
      V2SIGMAAB2(I) = 0.0D0
      V2SIGMABB2(I) = 0.0D0
      V2SIGMAAAAB(I) = 0.0D0
      V2SIGMAAABB(I) = 0.0D0
      V2SIGMAABBB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C*MODULE DFTXCB  *DECK RKS_C_PW91
      SUBROUTINE RKS_C_PW91
     & (IDERIV,NPT,RHOA1,SIGMAAA1,
     &  ZK,VRHOA,VSIGMAAA,
     &  V2RHOA2,V2RHOASIGMAAA,V2SIGMAAA2)
C
C     J.P. PERDEW, J.A. CHEVARY, S.H. VOSKO, K.A. JACKSON,
C     M.R. PEDERSON, D.J. SINGH, C. FIOLHAIS
C     ATOMS, MOLECULES, SOLIDS AND SURFACES:
C     APPLICATIONS OF THE GENERALIZED GRADIENT APPROXIMATION
C     FOR EXCHANGE AND CORRELATION
C     PHYS. REV. B 46 (1992) 6671--6687
C
      IMPLICIT DOUBLE PRECISION(A-H,O-Z)
      INTEGER IDERIV,NPT
      DOUBLE PRECISION RHOA1(NPT)
      DOUBLE PRECISION SIGMAAA1(NPT)
      DOUBLE PRECISION ZK(NPT),VRHOA(NPT),VSIGMAAA(NPT)
      DOUBLE PRECISION V2RHOA2(NPT),V2RHOASIGMAAA(NPT),V2SIGMAAA2(NPT)
      PARAMETER(TOL=1.0D-20)
C
      IF(IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.D0,SIGMAAA1(I))
      T2 = 1/RHO
      T3 = T2**(1.D0/3.D0)
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T17 = LOG(1.D0+0.160818243221511D2/(0.598255043577108D1*T6
     #+0.2225569421150687D1*T3+0.8004286349993634D0*T9
     #+0.1897004325747559D0*T11))
      T18 = (1.D0+0.1325688999052018D0*T3)*T17
      T20 = RHO**2
      T21 = RHO**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513869963240348D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMA**2
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T42 = T28**2
      T52 = LOG(1.D0+0.2697586091519874D1*(0.634682060977037D-1*SIGMA
     #*T23+0.1086645186223595D-1*T29*T30*T35)/(1.D0
     #+0.1712109500228824D0*T29*SIGMA*T23+0.2931318940773793D-1/T42
     #*T30*T35))
      T70 = EXP(-0.261211729852336D1/T33/T20*SIGMA)
      ZK(I) = RHO*(-0.62182D-1*T18+0.2473556743557577D-1*T52+0.1D1*
     #(0.1D-2*(0.2568D1+0.1443307452126544D2*T3+0.2843543831490386D-2
     #*T11)/(1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T11
     #+0.1763993811759022D-1*T2)-0.1853571428571429D-2)*SIGMA*T23*T70)
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.D0,SIGMAAA1(I))
      T2 = 1/RHO
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1325688999052018D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.598255043577108D1*T6+0.2225569421150687D1*T3
     #+0.8004286349993634D0*T9+0.1897004325747559D0*T11
      T16 = 1.D0+0.160818243221511D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.62182D-1*T18
      T20 = RHO**2
      T21 = RHO**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513869963240348D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMA**2
      T31 = T29*T30
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T38 = 0.634682060977037D-1*SIGMA*T23+0.1086645186223595D-1*T31*T35
      T39 = T29*SIGMA
      T42 = T28**2
      T43 = 1/T42
      T44 = T43*T30
      T47 = 1.D0+0.1712109500228824D0*T39*T23+0.2931318940773793D-1
     #*T44*T35
      T48 = 1/T47
      T51 = 1.D0+0.2697586091519874D1*T38*T48
      T52 = LOG(T51)
      T53 = 0.2473556743557577D-1*T52
      T56 = 0.2568D1+0.1443307452126544D2*T3+0.2843543831490386D-2*T11
      T60 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T11
     #+0.1763993811759022D-1*T2
      T61 = 1/T60
      T64 = 0.1D-2*T56*T61-0.1853571428571429D-2
      T65 = T64*SIGMA
      T70 = EXP(-0.261211729852336D1/T33/T20*SIGMA)
      T71 = T23*T70
      T73 = 0.1D1*T65*T71
      ZK(I) = RHO*(-T19+T53+T73)
      T76 = 1/T20
      T77 = 1/T11*T76
      T78 = T77*T17
      T80 = T13**2
      T83 = T6**2
      T84 = T83**2
      T94 = 1/T3*T76
      T99 = T5/T80*(-0.99709173929518D0/T84/T6*T76
     #-0.7418564737168958D0*T77-0.4002143174996817D0/T9*T76
     #-0.1264669550498372D0*T94)/T16
      T103 = 1/T21/T20/RHO
      T108 = -0.1110869918438343D0*T78-0.4042761511756372D2*T99
      T110 = T35*T108*T27
      T113 = T32*RHO
      T115 = 1/T33/T113
      T121 = T47**2
      T123 = T38/T121
      T124 = T43*SIGMA
      T142 = 1/T51
      T150 = T60**2
      VRHOA(I) = -T19+T53+T73+RHO*(0.2747799777968419D-2*T78+0.1D1*T99
     #+0.2473556743557577D-1*(0.2697586091519874D1*(
     #-0.148092480894642D0*SIGMA*T103-0.1086645186223595D-1*T44*T110
     #-0.5071010869043442D-1*T31*T115)*T48-0.2697586091519874D1*T123*(
     #-0.1712109500228824D0*T124*T23*T108*T27-0.3994922167200589D0*T39
     #*T103-0.5862637881547585D-1/T42/T28*T30*T110-0.136794883902777D0
     #*T44*T115))*T142+0.1D1*(0.1D-2*(-0.4811024840421814D1*T77
     #-0.1895695887660258D-2*T94)*T61-0.1D-2*T56/T150*(
     #-0.1803772444038489D1*T77-0.1210946621972718D0*T94
     #-0.1763993811759022D-1*T76))*SIGMA*T71-0.2333333333333333D1*T65
     #*T103*T70+0.6965646129395627D1*T64*T30/T32/T20*T70)
      VSIGMAAA(I) = 4.D0*RHO*(0.2473556743557577D-1*
     #(0.2697586091519874D1*(0.634682060977037D-1*T23
     #+0.2173290372447189D-1*T39*T35)*T48-0.2697586091519874D1*T123*
     #(0.1712109500228824D0*T29*T23+0.5862637881547585D-1*T124*T35))
     #*T142+0.1D1*T64*T23*T70-0.261211729852336D1*T65/T113*T70)
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.D0,SIGMAAA1(I))
      T2 = 1/RHO
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1325688999052018D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.598255043577108D1*T6+0.2225569421150687D1*T3
     #+0.8004286349993634D0*T9+0.1897004325747559D0*T11
      T16 = 1.D0+0.160818243221511D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.62182D-1*T18
      T20 = RHO**2
      T21 = RHO**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513869963240348D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMA**2
      T31 = T29*T30
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T38 = 0.634682060977037D-1*SIGMA*T23+0.1086645186223595D-1*T31*T35
      T39 = T29*SIGMA
      T42 = T28**2
      T43 = 1/T42
      T44 = T43*T30
      T47 = 1.D0+0.1712109500228824D0*T39*T23+0.2931318940773793D-1
     #*T44*T35
      T48 = 1/T47
      T51 = 1.D0+0.2697586091519874D1*T38*T48
      T52 = LOG(T51)
      T53 = 0.2473556743557577D-1*T52
      T56 = 0.2568D1+0.1443307452126544D2*T3+0.2843543831490386D-2*T11
      T60 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T11
     #+0.1763993811759022D-1*T2
      T61 = 1/T60
      T64 = 0.1D-2*T56*T61-0.1853571428571429D-2
      T65 = T64*SIGMA
      T70 = EXP(-0.261211729852336D1/T33/T20*SIGMA)
      T71 = T23*T70
      T73 = 0.1D1*T65*T71
      ZK(I) = RHO*(-T19+T53+T73)
      T75 = 1/T11
      T76 = 1/T20
      T77 = T75*T76
      T78 = T77*T17
      T80 = T13**2
      T81 = 1/T80
      T82 = T5*T81
      T83 = T6**2
      T84 = T83**2
      T85 = T84*T6
      T86 = 1/T85
      T90 = 1/T9
      T93 = 1/T3
      T94 = T93*T76
      T96 = -0.99709173929518D0*T86*T76-0.7418564737168958D0*T77
     #-0.4002143174996817D0*T90*T76-0.1264669550498372D0*T94
      T97 = 1/T16
      T99 = T82*T96*T97
      T101 = T20*RHO
      T103 = 1/T21/T101
      T108 = -0.1110869918438343D0*T78-0.4042761511756372D2*T99
      T110 = T35*T108*T27
      T113 = T32*RHO
      T115 = 1/T33/T113
      T118 = -0.148092480894642D0*SIGMA*T103-0.1086645186223595D-1*T44
     #*T110-0.5071010869043442D-1*T31*T115
      T121 = T47**2
      T122 = 1/T121
      T123 = T38*T122
      T124 = T43*SIGMA
      T132 = 1/T42/T28
      T133 = T132*T30
      T138 = -0.1712109500228824D0*T124*T23*T108*T27
     #-0.3994922167200589D0*T39*T103-0.5862637881547585D-1*T133*T110
     #-0.136794883902777D0*T44*T115
      T141 = 0.2697586091519874D1*T118*T48-0.2697586091519874D1*T123
     #*T138
      T142 = 1/T51
      T143 = T141*T142
      T147 = -0.4811024840421814D1*T77-0.1895695887660258D-2*T94
      T150 = T60**2
      T151 = 1/T150
      T152 = T56*T151
      T156 = -0.1803772444038489D1*T77-0.1210946621972718D0*T94
     #-0.1763993811759022D-1*T76
      T159 = 0.1D-2*T147*T61-0.1D-2*T152*T156
      T160 = T159*SIGMA
      T161 = T160*T71
      T163 = T103*T70
      T164 = T65*T163
      T166 = T64*T30
      T167 = T32*T20
      T169 = 1/T167*T70
      T170 = T166*T169
      VRHOA(I) = -T19+T53+T73+RHO*(0.2747799777968419D-2*T78+0.1D1*T99
     #+0.2473556743557577D-1*T143+0.1D1*T161-0.2333333333333333D1*T164
     #+0.6965646129395627D1*T170)
      T177 = 0.634682060977037D-1*T23+0.2173290372447189D-1*T39*T35
      T184 = 0.1712109500228824D0*T29*T23+0.5862637881547585D-1*T124*T35
      T187 = 0.2697586091519874D1*T177*T48-0.2697586091519874D1*T123
     #*T184
      T188 = T187*T142
      T191 = T64*T23*T70
      T193 = 1/T113
      T194 = T193*T70
      T195 = T65*T194
      VSIGMAAA(I) = 4.D0*RHO*(0.2473556743557577D-1*T188+0.1D1*T191
     #-0.261211729852336D1*T195)
      T215 = LOG(1.D0+0.2960857464321668D2/(0.8157414703487641D1*T6
     #+0.2247591863577616D1*T3+0.4300972471276643D0*T9
     #+0.1911512595127338D0*T11))
      T217 = (1.D0+0.6901399211255825D-1*T3)*T215*T76
      T219 = T52*T76
      T222 = 1/T21/T32
      T223 = SIGMA*T222
      T228 = 0.1365402272980597D1*T217-0.1675913308826898D1*T18*T76
      T230 = T35*T228*T27
      T234 = 1/T33/T167
      T235 = T31*T234
      T244 = T39*T222
      T248 = T44*T234
      T258 = T64*T222*SIGMA*T70
      T260 = T32*T101
      T263 = T166/T260*T70
      T270 = -T228
      T272 = T35*T270*T27
      T299 = 1/T32
      T300 = 1/T11/T2*T299
      T301 = T300*T17
      T303 = 1/T101
      T304 = T75*T303
      T305 = T304*T17
      T310 = T96**2
      T312 = T5/T80/T13*T310*T97
      T316 = T77*T81*T96*T97
      T334 = 1/T3/T2*T299
      T336 = T93*T303
      T340 = T82*(-0.8309097827459833D0/T85/T2*T299
     #+0.199418347859036D1*T86*T303-0.4945709824779306D0*T300
     #+0.1483712947433792D1*T304-0.2001071587498409D0/T9/T2*T299
     #+0.8004286349993634D0*T90*T303-0.4215565168327908D-1*T334
     #+0.2529339100996745D0*T336)*T97
      T342 = T80**2
      T345 = T16**2
      T348 = T5/T342*T310/T345
      T357 = T32**2
      T364 = T141**2
      T365 = T51**2
      T366 = 1/T365
      T371 = T115*T108*T27
      T380 = -0.740579945625562D-1*T301+0.2221739836876686D0*T305
     #+0.8085523023512745D2*T312+0.3572962974617552D1*T316
     #-0.4042761511756372D2*T340-0.6501498040842D3*T348
      T382 = T35*T380*T27
      T385 = T108**2
      T386 = T35*T385
      T388 = EXP(0.5027739926480695D1*T18)
      T389 = T386*T388
      T392 = T386*T27
      T399 = T118*T122
      T404 = T38/T121/T47
      T405 = T138**2
      T418 = T132*SIGMA
      T419 = T23*T385
      T429 = T42**2
      T456 = T156**2
      S1 = 0.1831866518645613D-2*T301-0.5495599555936838D-2*T305-0.2D1
     #*T312-0.8837926660346786D-1*T316+0.1D1*T340+0.160818243221511D2
     #*T348-0.5804705107829689D2*T263
      S2 = S1+0.7777777777777778D1*T258+0.1393129225879125D2*T159*T30
     #*T169+0.4852022599996427D2*T64*T30*SIGMA/T33/T357/RHO*T70
      S3 = S2-0.2473556743557577D-1*T364*T366
      S4 = S3+0.2473556743557577D-1*(0.2697586091519874D1*
     #(0.4936416029821399D0*T223+0.1014202173808688D0*T44*T371
     #-0.1086645186223595D-1*T44*T382+0.2173290372447189D-1*T133*T389
     #-0.1086645186223595D-1*T44*T392+0.2873572825791284D0*T235)*T48
     #-0.5395172183039748D1*T399*T138+0.5395172183039748D1*T404*T405
     #-0.2697586091519874D1*T123*(0.7989844334401178D0*T124*T103*T108
     #*T27-0.1712109500228824D0*T124*T23*T380*T27
     #-0.5862637881547585D-1*T133*T382+0.3424219000457648D0*T418*T419
     #*T388-0.1712109500228824D0*T124*T419*T27+0.1331640722400196D1
     #*T244+0.547179535611108D0*T133*T371+0.1758791364464276D0/T429
     #*T30*T389+0.7751710087824029D0*T248-0.5862637881547585D-1*T133
     #*T392))*T142
      T473 = S4+0.1D1*(0.1D-2*(-0.3207349893614542D1*T300
     #+0.9622049680843627D1*T304-0.6318986292200858D-3*T334
     #+0.3791391775320515D-2*T336)*T61-0.2D-2*T147*T151*T156+0.2D-2
     #*T56/T150/T60*T456-0.1D-2*T152*(-0.1202514962692326D1*T300
     #+0.3607544888076978D1*T304-0.4036488739909061D-1*T334
     #+0.2421893243945437D0*T336+0.3527987623518044D-1*T303))*SIGMA
     #*T71-0.4666666666666667D1*T160*T163
      S1 = 0.1099119911187368D-1*T78+0.4D1*T99-0.9333333333333333D1
     #*T164+0.2786258451758251D2*T170
      S2 = S1+0.9894226974230308D-1*T143+0.4D1*T161
      S3 = S2+RHO*(-0.33774D-1*T217+0.1649037829038385D-1*T219
     #+0.2473556743557577D-1*(0.2697586091519874D1*(
     #-0.2820809159897942D-1*T223-0.1086645186223595D-1*T44*T230
     #-0.9659068321987509D-2*T235)*T48-0.2697586091519874D1*T123*(
     #-0.1712109500228824D0*T124*T23*T228*T27-0.760937555657255D-1
     #*T244-0.5862637881547585D-1*T133*T230-0.2605616836243371D-1*T248
     #))*T142+0.2222222222222222D0*T258-0.1160941021565938D1*T263)
      V2RHOA2(I) = S3+RHO*(0.33774D-1*T217-0.1649037829038385D-1*T219
     #+0.2473556743557577D-1*(0.2697586091519874D1*
     #(0.2820809159897942D-1*T223-0.1086645186223595D-1*T44*T272
     #+0.9659068321987509D-2*T235)*T48-0.2697586091519874D1*T123*(
     #-0.1712109500228824D0*T124*T23*T270*T27+0.760937555657255D-1
     #*T244-0.5862637881547585D-1*T133*T272+0.2605616836243371D-1*T248
     #))*T142-0.2222222222222222D0*T258+0.1160941021565938D1*T263)
     #+2.D0*RHO*T473
      T489 = T177*T122
      V2RHOASIGMAAA(I) = 0.9894226974230308D-1*T188+0.4D1*T191
     #-0.1044846919409344D2*T195+4.D0*RHO*(0.2473556743557577D-1*
     #(0.2697586091519874D1*(-0.148092480894642D0*T103
     #-0.2173290372447189D-1*T124*T110-0.1014202173808688D0*T39*T115)
     #*T48-0.2697586091519874D1*T399*T184-0.2697586091519874D1*T489
     #*T138+0.5395172183039748D1*T404*T138*T184-0.2697586091519874D1
     #*T123*(-0.1712109500228824D0*T43*T23*T108*T27
     #-0.3994922167200589D0*T29*T103-0.1172527576309517D0*T418*T110
     #-0.273589767805554D0*T124*T115))*T142-0.2473556743557577D-1*T141
     #*T366*T187+0.1D1*T159*T23*T70-0.261211729852336D1*T160*T194
     #-0.2333333333333333D1*T64*T103*T70+0.2002623262201243D2*T65*T169
     #-0.181950847499866D2*T166/T33/T357*T70)
      T537 = T184**2
      T546 = T187**2
      V2SIGMAAA2(I) = 16.D0*RHO*(0.2473556743557577D-1*
     #(0.5862637881547585D-1*T29*T35*T48-0.5395172183039748D1*T489
     #*T184+0.5395172183039748D1*T404*T537-0.1581497040888031D0*T123
     #*T43*T35)*T142-0.2473556743557577D-1*T546*T366
     #-0.522423459704672D1*T64*T193*T70+0.6823156781244976D1*T65/T33
     #/T260*T70)
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      V2RHOASIGMAAA(I) = 0.0D0
      V2SIGMAAA2(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C*MODULE DFTXCB  *DECK UKS_C_PBE
      SUBROUTINE UKS_C_PBE
     & (IDERIV,NPT,RHOA1,RHOB1,SIGMAAA1,SIGMABB1,SIGMAAB1,
     &  ZK,VRHOA,VRHOB,VSIGMAAA,VSIGMABB,VSIGMAAB,
     &  V2RHOA2,V2RHOB2,V2RHOAB,
     &  V2RHOASIGMAAA,V2RHOASIGMAAB,V2RHOASIGMABB,
     &  V2RHOBSIGMABB,V2RHOBSIGMAAB,V2RHOBSIGMAAA,
     &  V2SIGMAAA2,V2SIGMAAAAB,V2SIGMAAABB,
     &  V2SIGMAAB2,V2SIGMAABBB,V2SIGMABB2)
C
C     J.P. PERDEW, K. BURKE, AND M. ERNZERHOF
C     GENERALIZED GRADIENT APPROXIMATION MADE SIMPLE
C     PHYS. REV. LETT. 77 (1996) 3865-3868
C
      IMPLICIT DOUBLE PRECISION(A-H,O-Z)
      INTEGER IDERIV,NPT
      DOUBLE PRECISION RHOA1(NPT),RHOB1(NPT)
      DOUBLE PRECISION SIGMAAA1(NPT),SIGMABB1(NPT),SIGMAAB1(NPT)
      DOUBLE PRECISION ZK(NPT),VRHOA(NPT),VRHOB(NPT)
      DOUBLE PRECISION VSIGMAAA(NPT),VSIGMABB(NPT),VSIGMAAB(NPT)
      DOUBLE PRECISION V2RHOA2(NPT),V2RHOB2(NPT),V2RHOAB(NPT)
      DOUBLE PRECISION V2RHOASIGMAAA(NPT),V2RHOASIGMAAB(NPT)
      DOUBLE PRECISION V2RHOASIGMABB(NPT),V2RHOBSIGMABB(NPT)
      DOUBLE PRECISION V2RHOBSIGMAAB(NPT),V2RHOBSIGMAAA(NPT)
      DOUBLE PRECISION V2SIGMAAA2(NPT),V2SIGMAAAAB(NPT),V2SIGMAAABB(NPT)
      DOUBLE PRECISION V2SIGMAAB2(NPT),V2SIGMAABBB(NPT),V2SIGMABB2(NPT)
      PARAMETER(TOL=1.0D-20)
C
      IF (IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMABB
      T2 = 1/RHOB
      T3 = T2**(1.D0/3.D0)
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T17 = LOG(1.D0+0.3216395899738507D2/(0.1112037486309468D2*T6
     #+0.3844746237447211D1*T3+0.1644733775567609D1*T9
     #+0.2405871291288192D0*T11))
      T18 = (1.D0+0.1274696188700087D0*T3)*T17
      T20 = RHOB**2
      T21 = RHOB**(1.D0/3.D0)
      T23 = 1/T21/T20
      T26 = EXP(0.2000000587336264D1*T18)
      T27 = T26-1.D0
      T31 = 0.2162211495206379D0/T27*SIGMABB*T23
      T33 = T27**2
      T35 = SIGMABB**2
      T37 = T20**2
      T38 = T21**2
      T49 = LOG(1.D0+0.2162211495206379D0*SIGMABB*T23*(1.D0+T31)/
     #(1.D0+T31+0.4675158550002605D-1/T33*T35/T38/T37))
      ZK(I) = RHOB*(-0.310907D-1*T18+0.1554534543482745D-1*T49)
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMA = SIGMAAA
      T2 = 1/RHOA
      T3 = T2**(1.D0/3.D0)
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T17 = LOG(1.D0+0.3216395899738507D2/(0.1112037486309468D2*T6
     #+0.3844746237447211D1*T3+0.1644733775567609D1*T9
     #+0.2405871291288192D0*T11))
      T18 = (1.D0+0.1274696188700087D0*T3)*T17
      T20 = RHOA**2
      T21 = RHOA**(1.D0/3.D0)
      T23 = 1/T21/T20
      T26 = EXP(0.2000000587336264D1*T18)
      T27 = T26-1.D0
      T31 = 0.2162211495206379D0/T27*SIGMAAA*T23
      T33 = T27**2
      T35 = SIGMAAA**2
      T37 = T20**2
      T38 = T21**2
      T49 = LOG(1.D0+0.2162211495206379D0*SIGMAAA*T23*(1.D0+T31)/
     #(1.D0+T31+0.4675158550002605D-1/T33*T35/T38/T37))
      ZK(I) = RHOA*(-0.310907D-1*T18+0.1554534543482745D-1*T49)
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMAAB = SIGMAAB1(I)
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMAAA+SIGMABB+2.D0*SIGMAAB
      T4 = 1/RHO
      T5 = T4**(1.D0/3.D0)
      T8 = T4**(1.D0/6.D0)
      T11 = SQRT(T4)
      T13 = T5**2
      T19 = LOG(1.D0+0.1608197949869254D2/(0.598255043577108D1*T8
     #+0.2225569421150687D1*T5+0.8004286349993634D0*T11
     #+0.1897004325747559D0*T13))
      T21 = 0.621814D-1*(1.D0+0.1325688999052018D0*T5)*T19
      T32 = LOG(1.D0+0.2960874997779344D2/(0.8157414703487641D1*T8
     #+0.2247591863577616D1*T5+0.4300972471276643D0*T11
     #+0.1911512595127338D0*T13))
      T35 = RHOA-1.D0*RHOB
      T36 = T35*T4
      T37 = 1.D0+T36
      T38 = T37**(1.D0/3.D0)
      T41 = 1.D0-1.D0*T36
      T42 = T41**(1.D0/3.D0)
      T44 = T38*T37+T42*T41-2.D0
      T45 = T35**2
      T46 = T45**2
      T47 = RHO**2
      T48 = T47**2
      T50 = T46/T48
      T55 = 0.37995525D-1*(1.D0+0.6901399211255825D-1*T5)*T32*T44*
     #(1.D0-1.D0*T50)
      T66 = LOG(1.D0+0.3216395899738507D2/(0.1112037486309468D2*T8
     #+0.3844746237447211D1*T5+0.1644733775567609D1*T11
     #+0.2405871291288192D0*T13))
      T72 = 0.1923661050931536D1*(-0.310907D-1*(1.D0
     #+0.1274696188700087D0*T5)*T66+T21)*T44*T50
      T73 = T38**2
      T75 = T42**2
      T77 = 0.5D0*T73+0.5D0*T75
      T78 = T77**2
      T79 = T78*T77
      T80 = 1/T78
      T82 = RHO**(1.D0/3.D0)
      T84 = 1/T82/T47
      T89 = EXP(-0.3216396844291482D2*(-T21+T55+T72)/T79)
      T90 = T89-1.D0
      T95 = 0.1362107888567592D0/T90*SIGMA*T80*T84
      T98 = T90**2
      T100 = SIGMA**2
      T102 = T78**2
      T104 = T82**2
      T116 = LOG(1.D0+0.1362107888567592D0*SIGMA*T80*T84*(1.D0+T95)/
     #(1.D0+T95+0.1855337900098064D-1/T98*T100/T102/T104/T48))
      ZK(I) = RHO*(-T21+T55+T72+0.310906908696549D-1*T79*T116)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMABB
      T2 = 1/RHOB
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1274696188700087D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T3
     #+0.1644733775567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.3216395899738507D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.310907D-1*T18
      T20 = RHOB**2
      T21 = RHOB**(1.D0/3.D0)
      T23 = 1/T21/T20
      T24 = SIGMABB*T23
      T26 = EXP(0.2000000587336264D1*T18)
      T27 = T26-1.D0
      T28 = 1/T27
      T29 = T28*SIGMABB
      T31 = 0.2162211495206379D0*T29*T23
      T32 = 1.D0+T31
      T33 = T27**2
      T34 = 1/T33
      T35 = SIGMABB**2
      T36 = T34*T35
      T37 = T20**2
      T38 = T21**2
      T40 = 1/T38/T37
      T41 = T36*T40
      T43 = 1.D0+T31+0.4675158550002605D-1*T41
      T44 = 1/T43
      T45 = T32*T44
      T48 = 1.D0+0.2162211495206379D0*T24*T45
      T49 = LOG(T48)
      T50 = 0.1554534543482745D-1*T49
      ZK(I) = RHOB*(-T19+T50)
      VRHOA(I) = 0.D0
      T54 = 1/T21/T20/RHOB
      T60 = 1/T38/T37/RHOB
      T62 = T28*T44
      T65 = T43**2
      T67 = T32/T65
      T78 = 1/T48
      T82 = 1/T20
      T83 = 1/T11*T82
      T84 = T83*T17
      T86 = T13**2
      T89 = T6**2
      T90 = T89**2
      T105 = T5/T86*(-0.1853395810515781D1/T90/T6*T82
     #-0.128158207914907D1*T83-0.8223668877838045D0/T9*T82
     #-0.1603914194192128D0/T3*T82)/T16
      T109 = -0.8497977086918237D-1*T84-0.6432793688582964D2*T105
      T114 = T34*SIGMABB
      VRHOB(I) = -T19+T50+0.1554534543482745D-1*RHOB*(
     #-0.5045160155481551D0*SIGMABB*T54*T45-0.1090870328333941D0*T35
     #*T60*T62-0.2162211495206379D0*T24*T67*(-0.5045160155481551D0*T29
     #*T54-0.2181740656667882D0*T36*T60))*T78+RHOB*
     #(0.1321039893133927D-2*T84+0.1D1*T105+0.1554534543482745D-1*(
     #-0.4675158550002605D-1*T41*T109*T26*T44-0.2162211495206379D0*T24
     #*T67*(-0.2162211495206379D0*T114*T23*T109*T26
     #-0.935031710000521D-1/T33/T27*T35*T40*T109*T26))*T78)
      VSIGMAAA(I) = 0.D0
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = 0.1554534543482745D-1*RHOB*(0.2162211495206379D0
     #*T23*T32*T44+0.4675158550002605D-1*SIGMABB*T40*T62
     #-0.2162211495206379D0*T24*T67*(0.2162211495206379D0*T28*T23
     #+0.935031710000521D-1*T114*T40))*T78
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMA = SIGMAAA
      T2 = 1/RHOA
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1274696188700087D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T3
     #+0.1644733775567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.3216395899738507D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.310907D-1*T18
      T20 = RHOA**2
      T21 = RHOA**(1.D0/3.D0)
      T23 = 1/T21/T20
      T24 = SIGMAAA*T23
      T26 = EXP(0.2000000587336264D1*T18)
      T27 = T26-1.D0
      T28 = 1/T27
      T29 = T28*SIGMAAA
      T31 = 0.2162211495206379D0*T29*T23
      T32 = 1.D0+T31
      T33 = T27**2
      T34 = 1/T33
      T35 = SIGMAAA**2
      T36 = T34*T35
      T37 = T20**2
      T38 = T21**2
      T40 = 1/T38/T37
      T41 = T36*T40
      T43 = 1.D0+T31+0.4675158550002605D-1*T41
      T44 = 1/T43
      T45 = T32*T44
      T48 = 1.D0+0.2162211495206379D0*T24*T45
      T49 = LOG(T48)
      T50 = 0.1554534543482745D-1*T49
      ZK(I) = RHOA*(-T19+T50)
      T54 = 1/T21/T20/RHOA
      T60 = 1/T38/T37/RHOA
      T62 = T28*T44
      T65 = T43**2
      T67 = T32/T65
      T78 = 1/T48
      T82 = 1/T20
      T83 = 1/T11*T82
      T84 = T83*T17
      T86 = T13**2
      T89 = T6**2
      T90 = T89**2
      T105 = T5/T86*(-0.1853395810515781D1/T90/T6*T82
     #-0.128158207914907D1*T83-0.8223668877838045D0/T9*T82
     #-0.1603914194192128D0/T3*T82)/T16
      T109 = -0.8497977086918237D-1*T84-0.6432793688582964D2*T105
      T114 = T34*SIGMAAA
      VRHOA(I) = -T19+T50+0.1554534543482745D-1*RHOA*(
     #-0.5045160155481551D0*SIGMAAA*T54*T45-0.1090870328333941D0*T35
     #*T60*T62-0.2162211495206379D0*T24*T67*(-0.5045160155481551D0*T29
     #*T54-0.2181740656667882D0*T36*T60))*T78+RHOA*
     #(0.1321039893133927D-2*T84+0.1D1*T105+0.1554534543482745D-1*(
     #-0.4675158550002605D-1*T41*T109*T26*T44-0.2162211495206379D0*T24
     #*T67*(-0.2162211495206379D0*T114*T23*T109*T26
     #-0.935031710000521D-1/T33/T27*T35*T40*T109*T26))*T78)
      VRHOB(I) = 0.D0
      VSIGMAAA(I) = 0.1554534543482745D-1*RHOA*(0.2162211495206379D0
     #*T23*T32*T44+0.4675158550002605D-1*SIGMAAA*T40*T62
     #-0.2162211495206379D0*T24*T67*(0.2162211495206379D0*T28*T23
     #+0.935031710000521D-1*T114*T40))*T78
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = 0.D0
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMAAB = SIGMAAB1(I)
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMAAA+SIGMABB+2.D0*SIGMAAB
      T4 = 1/RHO
      T5 = T4**(1.D0/3.D0)
      T7 = 1.D0+0.1325688999052018D0*T5
      T8 = T4**(1.D0/6.D0)
      T11 = SQRT(T4)
      T13 = T5**2
      T15 = 0.598255043577108D1*T8+0.2225569421150687D1*T5
     #+0.8004286349993634D0*T11+0.1897004325747559D0*T13
      T18 = 1.D0+0.1608197949869254D2/T15
      T19 = LOG(T18)
      T21 = 0.621814D-1*T7*T19
      T23 = 1.D0+0.6901399211255825D-1*T5
      T28 = 0.8157414703487641D1*T8+0.2247591863577616D1*T5
     #+0.4300972471276643D0*T11+0.1911512595127338D0*T13
      T31 = 1.D0+0.2960874997779344D2/T28
      T32 = LOG(T31)
      T33 = T23*T32
      T35 = RHOA-1.D0*RHOB
      T36 = T35*T4
      T37 = 1.D0+T36
      T38 = T37**(1.D0/3.D0)
      T41 = 1.D0-1.D0*T36
      T42 = T41**(1.D0/3.D0)
      T44 = T38*T37+T42*T41-2.D0
      T45 = T35**2
      T46 = T45**2
      T47 = RHO**2
      T48 = T47**2
      T49 = 1/T48
      T50 = T46*T49
      T52 = 1.D0-1.D0*T50
      T55 = 0.37995525D-1*T33*T44*T52
      T57 = 1.D0+0.1274696188700087D0*T5
      T62 = 0.1112037486309468D2*T8+0.3844746237447211D1*T5
     #+0.1644733775567609D1*T11+0.2405871291288192D0*T13
      T65 = 1.D0+0.3216395899738507D2/T62
      T66 = LOG(T65)
      T69 = -0.310907D-1*T57*T66+T21
      T70 = T69*T44
      T72 = 0.1923661050931536D1*T70*T50
      T73 = T38**2
      T75 = T42**2
      T77 = 0.5D0*T73+0.5D0*T75
      T78 = T77**2
      T79 = T78*T77
      T80 = 1/T78
      T81 = SIGMA*T80
      T82 = RHO**(1.D0/3.D0)
      T84 = 1/T82/T47
      T85 = -T21+T55+T72
      T86 = 1/T79
      T89 = EXP(-0.3216396844291482D2*T85*T86)
      T90 = T89-1.D0
      T91 = 1/T90
      T92 = T91*SIGMA
      T93 = T80*T84
      T95 = 0.1362107888567592D0*T92*T93
      T96 = 1.D0+T95
      T98 = T90**2
      T99 = 1/T98
      T100 = SIGMA**2
      T101 = T99*T100
      T102 = T78**2
      T103 = 1/T102
      T104 = T82**2
      T106 = 1/T104/T48
      T107 = T103*T106
      T110 = 1.D0+T95+0.1855337900098064D-1*T101*T107
      T111 = 1/T110
      T115 = 1.D0+0.1362107888567592D0*T81*T84*T96*T111
      T116 = LOG(T115)
      T118 = 0.310906908696549D-1*T79*T116
      ZK(I) = RHO*(-T21+T55+T72+T118)
      T124 = 0.1333333333333333D1*T38*T4-0.1333333333333333D1*T42*T4
      T127 = 0.37995525D-1*T33*T124*T52
      T128 = T45*T35
      T131 = T33*T44*T128*T49
      T132 = 0.1519821D0*T131
      T135 = 0.1923661050931536D1*T69*T124*T50
      T137 = T70*T128*T49
      T138 = 0.7694644203726145D1*T137
      T139 = T78*T116
      T140 = 1/T38
      T143 = 1/T42
      T146 = 0.3333333333333333D0*T140*T4-0.3333333333333333D0*T143*T4
      T150 = SIGMA*T86*T84
      T151 = T96*T111
      T155 = T99*SIGMA
      T156 = T155*T80
      T160 = T85*T103
      T163 = -0.3216396844291482D2*(T127-T132+T135+T138)*T86
     #+0.9649190532874446D2*T160*T146
      T167 = 0.1362107888567592D0*T156*T84*T163*T89
      T168 = T86*T84
      T171 = 0.2724215777135184D0*T92*T168*T146
      T177 = T81*T84
      T178 = T110**2
      T180 = T96/T178
      T184 = 1/T98/T90*T100*T103
      T191 = 1/T102/T77*T106
      T201 = 1/T115
      T207 = 1/T47
      T208 = 1/T13*T207
      T209 = T208*T19
      T210 = 0.2747773264188438D-2*T209
      T211 = T15**2
      T214 = T8**2
      T215 = T214**2
      T218 = 1/T215/T8*T207
      T222 = 1/T11*T207
      T225 = 1/T5*T207
      T230 = T7/T211*(-0.99709173929518D0*T218-0.7418564737168958D0
     #*T208-0.4002143174996817D0*T222-0.1264669550498372D0*T225)/T18
      T231 = 0.1D1*T230
      T235 = 0.87407428755417D-3*T208*T32*T44*T52
      T236 = T28**2
      T249 = 0.1125D1*T23/T236*(-0.135956911724794D1*T218
     #-0.7491972878592054D0*T208-0.2150486235638321D0*T222
     #-0.1274341730084892D0*T225)/T31*T44*T52
      T256 = -0.1333333333333333D1*T38*T35*T207+0.1333333333333333D1
     #*T42*T35*T207
      T259 = 0.37995525D-1*T33*T256*T52
      T261 = T48*RHO
      T262 = 1/T261
      T265 = 0.1519821D0*T33*T44*T46*T262
      T268 = T62**2
      T285 = 0.1923661050931536D1*(0.1321039893133927D-2*T208*T66
     #+0.1D1*T57/T268*(-0.1853395810515781D1*T218-0.128158207914907D1
     #*T208-0.8223668877838045D0*T222-0.1603914194192128D0*T225)/T65
     #-0.2747773264188438D-2*T209-0.1D1*T230)*T44*T50
      T288 = 0.1923661050931536D1*T69*T256*T50
      T291 = 0.7694644203726145D1*T70*T46*T262
      T298 = -0.3333333333333333D0*T140*T35*T207+0.3333333333333333D0
     #*T143*T35*T207
      T306 = 1/T82/T47/RHO
      T316 = -0.3216396844291482D2*(T210+T231-T235-T249+T259+T265+T285
     #+T288-T291)*T86+0.9649190532874446D2*T160*T298
      T320 = 0.1362107888567592D0*T156*T84*T316*T89
      T323 = 0.2724215777135184D0*T92*T168*T298
      T326 = 0.3178251739991049D0*T92*T80*T306
      T352 = T210+T231-T235-T249+T259+T265+T285+T288-T291
     #+0.9327207260896469D-1*T139*T298+0.310906908696549D-1*T79*(
     #-0.2724215777135184D0*T150*T151*T298-0.3178251739991049D0*T81
     #*T306*T96*T111+0.1362107888567592D0*T81*T84*(-T320-T323-T326)
     #*T111-0.1362107888567592D0*T177*T180*(-T320-T323-T326
     #-0.3710675800196129D-1*T184*T106*T316*T89-0.7421351600392257D-1
     #*T101*T191*T298-0.8658243533790967D-1*T101*T103/T104/T261))*T201
      T353 = RHO*T352
      VRHOA(I) = RHO*(T127-T132+T135+T138+0.9327207260896469D-1*T139
     #*T146+0.310906908696549D-1*T79*(-0.2724215777135184D0*T150*T151
     #*T146+0.1362107888567592D0*T81*T84*(-T167-T171)*T111
     #-0.1362107888567592D0*T177*T180*(-T167-T171
     #-0.3710675800196129D-1*T184*T106*T163*T89-0.7421351600392257D-1
     #*T101*T191*T146))*T201)-T21+T55+T72+T118+T353
      T354 = -T124
      T357 = 0.37995525D-1*T33*T354*T52
      T358 = 0.1519821D0*T131
      T361 = 0.1923661050931536D1*T69*T354*T50
      T362 = 0.7694644203726145D1*T137
      T363 = -T146
      T374 = -0.3216396844291482D2*(T357+T358+T361-T362)*T86
     #+0.9649190532874446D2*T160*T363
      T378 = 0.1362107888567592D0*T156*T84*T374*T89
      T381 = 0.2724215777135184D0*T92*T168*T363
      VRHOB(I) = RHO*(T357+T358+T361-T362+0.9327207260896469D-1*T139
     #*T363+0.310906908696549D-1*T79*(-0.2724215777135184D0*T150*T151
     #*T363+0.1362107888567592D0*T81*T84*(-T378-T381)*T111
     #-0.1362107888567592D0*T177*T180*(-T378-T381
     #-0.3710675800196129D-1*T184*T106*T374*T89-0.7421351600392257D-1
     #*T101*T191*T363))*T201)-T21+T55+T72+T118+T353
      T423 = RHO*T79*(0.1362107888567592D0*T93*T151
     #+0.1855337900098064D-1*SIGMA*T103*T106*T91*T111
     #-0.1362107888567592D0*T177*T180*(0.1362107888567592D0*T91*T80
     #*T84+0.3710675800196129D-1*T155*T107))*T201
      VSIGMAAA(I) = 0.310906908696549D-1*T423
      VSIGMAAB(I) = 0.6218138173930979D-1*T423
      VSIGMABB(I) = VSIGMAAA(I)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      VSIGMAAB(I) = 0.0D0
      VSIGMABB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMABB
      T2 = 1/RHOB
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1274696188700087D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T3
     #+0.1644733775567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.3216395899738507D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.310907D-1*T18
      T20 = RHOB**2
      T21 = RHOB**(1.D0/3.D0)
      T23 = 1/T21/T20
      T24 = SIGMABB*T23
      T26 = EXP(0.2000000587336264D1*T18)
      T27 = T26-1.D0
      T28 = 1/T27
      T29 = T28*SIGMABB
      T31 = 0.2162211495206379D0*T29*T23
      T32 = 1.D0+T31
      T33 = T27**2
      T34 = 1/T33
      T35 = SIGMABB**2
      T36 = T34*T35
      T37 = T20**2
      T38 = T21**2
      T40 = 1/T38/T37
      T41 = T36*T40
      T43 = 1.D0+T31+0.4675158550002605D-1*T41
      T44 = 1/T43
      T45 = T32*T44
      T48 = 1.D0+0.2162211495206379D0*T24*T45
      T49 = LOG(T48)
      T50 = 0.1554534543482745D-1*T49
      ZK(I) = RHOB*(-T19+T50)
      VRHOA(I) = 0.D0
      T52 = T20*RHOB
      T54 = 1/T21/T52
      T55 = SIGMABB*T54
      T60 = 1/T38/T37/RHOB
      T61 = T35*T60
      T62 = T28*T44
      T65 = T43**2
      T66 = 1/T65
      T67 = T32*T66
      T70 = T36*T60
      T72 = -0.5045160155481551D0*T29*T54-0.2181740656667882D0*T70
      T73 = T67*T72
      T76 = -0.5045160155481551D0*T55*T45-0.1090870328333941D0*T61*T62
     #-0.2162211495206379D0*T24*T73
      T77 = RHOB*T76
      T78 = 1/T48
      T81 = 1/T11
      T82 = 1/T20
      T83 = T81*T82
      T84 = T83*T17
      T86 = T13**2
      T87 = 1/T86
      T88 = T5*T87
      T89 = T6**2
      T90 = T89**2
      T91 = T90*T6
      T92 = 1/T91
      T96 = 1/T9
      T99 = 1/T3
      T102 = -0.1853395810515781D1*T92*T82-0.128158207914907D1*T83
     #-0.8223668877838045D0*T96*T82-0.1603914194192128D0*T99*T82
      T103 = 1/T16
      T105 = T88*T102*T103
      T109 = -0.8497977086918237D-1*T84-0.6432793688582964D2*T105
      T110 = T109*T26
      T111 = T110*T44
      T114 = T34*SIGMABB
      T120 = 1/T33/T27
      T121 = T120*T35
      T126 = -0.2162211495206379D0*T114*T23*T109*T26
     #-0.935031710000521D-1*T121*T40*T109*T26
      T127 = T67*T126
      T130 = -0.4675158550002605D-1*T41*T111-0.2162211495206379D0*T24
     #*T127
      T131 = T130*T78
      VRHOB(I) = -T19+T50+0.1554534543482745D-1*T77*T78+RHOB*
     #(0.1321039893133927D-2*T84+0.1D1*T105+0.1554534543482745D-1*T131)
      VSIGMAAA(I) = 0.D0
      VSIGMAAB(I) = 0.D0
      T135 = T23*T32
      T138 = SIGMABB*T40
      T145 = 0.2162211495206379D0*T28*T23+0.935031710000521D-1*T114*T40
      T149 = 0.2162211495206379D0*T135*T44+0.4675158550002605D-1*T138
     #*T62-0.2162211495206379D0*T24*T67*T145
      VSIGMABB(I) = 0.1554534543482745D-1*RHOB*T149*T78
      V2RHOA2(I) = 0.D0
      V2RHOAB(I) = 0.D0
      T155 = 1/T21/T37
      T161 = 1/T38/T37/T20
      T167 = T28*T66
      T172 = 1/T65/T43
      T173 = T32*T172
      T174 = T72**2
      T190 = T76**2
      T192 = T48**2
      T193 = 1/T192
      T199 = T70*T111
      T204 = 0.4675158550002605D-1*T41*T110*T66*T72
      T206 = 0.5045160155481551D0*T55*T127
      T209 = 0.1090870328333941D0*T61*T167*T126
      T214 = 0.4324422990412758D0*T24*T32*T172*T126*T72
      T226 = 0.2162211495206379D0*T24*T67*(0.5045160155481551D0*T114
     #*T54*T109*T26+0.4363481313335765D0*T121*T60*T109*T26)
      T230 = T130*T193
      T244 = 1/T37
      T245 = 1/T11/T2*T244
      T246 = T245*T17
      T248 = 1/T52
      T249 = T81*T248
      T250 = T249*T17
      T254 = T83*T87*T102*T103
      T259 = T102**2
      T261 = T5/T86/T13*T259*T103
      T285 = T88*(-0.1544496508763151D1/T91/T2*T244
     #+0.3706791621031562D1*T92*T248-0.854388052766047D0*T245
     #+0.2563164158298141D1*T249-0.4111834438919023D0/T9/T2*T244
     #+0.1644733775567609D1*T96*T248-0.5346380647307093D-1/T3/T2*T244
     #+0.3207828388384256D0*T99*T248)*T103
      T287 = T86**2
      T290 = T16**2
      T293 = T5/T287*T259/T290
      T297 = T109**2
      T298 = T26**2
      T309 = -0.5665318057945491D-1*T246+0.1699595417383647D0*T250
     #+0.546657173168712D1*T254+0.1286558737716593D3*T261
     #-0.6432793688582964D2*T285-0.2069041124382199D4*T293
      T322 = T126**2
      T327 = T23*T297
      T338 = T33**2
      T341 = T40*T297
      T359 = T130**2
      S1 = 0.310906908696549D-1*T76*T78+0.1554534543482745D-1*RHOB*
     #(0.1681720051827184D1*SIGMABB*T155*T45+0.8726962626671529D0*T35
     #*T161*T62+0.100903203109631D1*T55*T73+0.2181740656667882D0*T61
     #*T167*T72+0.4324422990412758D0*T24*T173*T174
     #-0.2162211495206379D0*T24*T67*(0.1681720051827184D1*T29*T155
     #+0.1236319705445133D1*T36*T161))*T78-0.1554534543482745D-1*RHOB
     #*T190*T193+0.2642079786267853D-2*T84+0.2D1*T105
      S2 = S1+0.310906908696549D-1*T131+RHOB*(0.1554534543482745D-1*
     #(0.2181740656667882D0*T199+T204+T206+T209+T214-T226)*T78
     #-0.1554534543482745D-1*T230*T76)
      S3 = S2+0.1554534543482745D-1*RHOB*(0.2181740656667882D0*T199
     #+T206+T209+T204+T214-T226)*T78
      V2RHOB2(I) = S3-0.1554534543482745D-1*T77*T230+RHOB*
     #(0.8806932620892844D-3*T246-0.2642079786267853D-2*T250
     #-0.8497974591333914D-1*T254-0.2D1*T261+0.1D1*T285
     #+0.3216395899738507D2*T293+0.1554534543482745D-1*
     #(0.935031710000521D-1*T35*T40*T120*T297*T298*T44
     #-0.4675158550002605D-1*T41*T309*T26*T44-0.4675158550002605D-1
     #*T41*T297*T26*T44+0.935031710000521D-1*T41*T110*T66*T126
     #+0.4324422990412758D0*T24*T173*T322-0.2162211495206379D0*T24*T67
     #*(0.4324422990412758D0*T120*SIGMABB*T327*T298
     #-0.2162211495206379D0*T114*T23*T309*T26-0.2162211495206379D0
     #*T114*T327*T26+0.2805095130001563D0/T338*T35*T341*T298
     #-0.935031710000521D-1*T121*T40*T309*T26-0.935031710000521D-1
     #*T121*T341*T26))*T78-0.1554534543482745D-1*T359*T193)
      V2SIGMAAA2(I) = 0.D0
      V2SIGMAAAAB(I) = 0.D0
      V2SIGMAAABB(I) = 0.D0
      V2SIGMAAB2(I) = 0.D0
      V2SIGMAABBB(I) = 0.D0
      T373 = T145**2
      T387 = T149**2
      V2SIGMABB2(I) = 0.1554534543482745D-1*RHOB*(0.935031710000521D-1
     #*T40*T28*T44-0.4324422990412758D0*T135*T66*T145
     #-0.935031710000521D-1*T138*T167*T145+0.4324422990412758D0*T24
     #*T173*T373-0.2021736311745604D-1*SIGMABB/T37/T52*T67*T34)*T78
     #-0.1554534543482745D-1*RHOB*T387*T193
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMA = SIGMAAA
      T2 = 1/RHOA
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1274696188700087D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T3
     #+0.1644733775567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.3216395899738507D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.310907D-1*T18
      T20 = RHOA**2
      T21 = RHOA**(1.D0/3.D0)
      T23 = 1/T21/T20
      T24 = SIGMAAA*T23
      T26 = EXP(0.2000000587336264D1*T18)
      T27 = T26-1.D0
      T28 = 1/T27
      T29 = T28*SIGMAAA
      T31 = 0.2162211495206379D0*T29*T23
      T32 = 1.D0+T31
      T33 = T27**2
      T34 = 1/T33
      T35 = SIGMAAA**2
      T36 = T34*T35
      T37 = T20**2
      T38 = T21**2
      T40 = 1/T38/T37
      T41 = T36*T40
      T43 = 1.D0+T31+0.4675158550002605D-1*T41
      T44 = 1/T43
      T45 = T32*T44
      T48 = 1.D0+0.2162211495206379D0*T24*T45
      T49 = LOG(T48)
      T50 = 0.1554534543482745D-1*T49
      ZK(I) = RHOA*(-T19+T50)
      T52 = T20*RHOA
      T54 = 1/T21/T52
      T55 = SIGMAAA*T54
      T60 = 1/T38/T37/RHOA
      T61 = T35*T60
      T62 = T28*T44
      T65 = T43**2
      T66 = 1/T65
      T67 = T32*T66
      T70 = T36*T60
      T72 = -0.5045160155481551D0*T29*T54-0.2181740656667882D0*T70
      T73 = T67*T72
      T76 = -0.5045160155481551D0*T55*T45-0.1090870328333941D0*T61*T62
     #-0.2162211495206379D0*T24*T73
      T77 = RHOA*T76
      T78 = 1/T48
      T81 = 1/T11
      T82 = 1/T20
      T83 = T81*T82
      T84 = T83*T17
      T86 = T13**2
      T87 = 1/T86
      T88 = T5*T87
      T89 = T6**2
      T90 = T89**2
      T91 = T90*T6
      T92 = 1/T91
      T96 = 1/T9
      T99 = 1/T3
      T102 = -0.1853395810515781D1*T92*T82-0.128158207914907D1*T83
     #-0.8223668877838045D0*T96*T82-0.1603914194192128D0*T99*T82
      T103 = 1/T16
      T105 = T88*T102*T103
      T109 = -0.8497977086918237D-1*T84-0.6432793688582964D2*T105
      T110 = T109*T26
      T111 = T110*T44
      T114 = T34*SIGMAAA
      T120 = 1/T33/T27
      T121 = T120*T35
      T126 = -0.2162211495206379D0*T114*T23*T109*T26
     #-0.935031710000521D-1*T121*T40*T109*T26
      T127 = T67*T126
      T130 = -0.4675158550002605D-1*T41*T111-0.2162211495206379D0*T24
     #*T127
      T131 = T130*T78
      VRHOA(I) = -T19+T50+0.1554534543482745D-1*T77*T78+RHOA*
     #(0.1321039893133927D-2*T84+0.1D1*T105+0.1554534543482745D-1*T131)
      VRHOB(I) = 0.D0
      T135 = T23*T32
      T138 = SIGMAAA*T40
      T145 = 0.2162211495206379D0*T28*T23+0.935031710000521D-1*T114*T40
      T149 = 0.2162211495206379D0*T135*T44+0.4675158550002605D-1*T138
     #*T62-0.2162211495206379D0*T24*T67*T145
      VSIGMAAA(I) = 0.1554534543482745D-1*RHOA*T149*T78
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = 0.D0
      T155 = 1/T21/T37
      T161 = 1/T38/T37/T20
      T167 = T28*T66
      T172 = 1/T65/T43
      T173 = T32*T172
      T174 = T72**2
      T190 = T76**2
      T192 = T48**2
      T193 = 1/T192
      T199 = T70*T111
      T204 = 0.4675158550002605D-1*T41*T110*T66*T72
      T206 = 0.5045160155481551D0*T55*T127
      T209 = 0.1090870328333941D0*T61*T167*T126
      T214 = 0.4324422990412758D0*T24*T32*T172*T126*T72
      T226 = 0.2162211495206379D0*T24*T67*(0.5045160155481551D0*T114
     #*T54*T109*T26+0.4363481313335765D0*T121*T60*T109*T26)
      T230 = T130*T193
      T244 = 1/T37
      T245 = 1/T11/T2*T244
      T246 = T245*T17
      T248 = 1/T52
      T249 = T81*T248
      T250 = T249*T17
      T254 = T83*T87*T102*T103
      T259 = T102**2
      T261 = T5/T86/T13*T259*T103
      T285 = T88*(-0.1544496508763151D1/T91/T2*T244
     #+0.3706791621031562D1*T92*T248-0.854388052766047D0*T245
     #+0.2563164158298141D1*T249-0.4111834438919023D0/T9/T2*T244
     #+0.1644733775567609D1*T96*T248-0.5346380647307093D-1/T3/T2*T244
     #+0.3207828388384256D0*T99*T248)*T103
      T287 = T86**2
      T290 = T16**2
      T293 = T5/T287*T259/T290
      T297 = T109**2
      T298 = T26**2
      T309 = -0.5665318057945491D-1*T246+0.1699595417383647D0*T250
     #+0.546657173168712D1*T254+0.1286558737716593D3*T261
     #-0.6432793688582964D2*T285-0.2069041124382199D4*T293
      T322 = T126**2
      T327 = T23*T297
      T338 = T33**2
      T341 = T40*T297
      T359 = T130**2
      S1 = 0.310906908696549D-1*T76*T78+0.1554534543482745D-1*RHOA*
     #(0.1681720051827184D1*SIGMAAA*T155*T45+0.8726962626671529D0*T35
     #*T161*T62+0.100903203109631D1*T55*T73+0.2181740656667882D0*T61
     #*T167*T72+0.4324422990412758D0*T24*T173*T174
     #-0.2162211495206379D0*T24*T67*(0.1681720051827184D1*T29*T155
     #+0.1236319705445133D1*T36*T161))*T78-0.1554534543482745D-1*RHOA
     #*T190*T193+0.2642079786267853D-2*T84+0.2D1*T105
      S2 = S1+0.310906908696549D-1*T131+RHOA*(0.1554534543482745D-1*
     #(0.2181740656667882D0*T199+T204+T206+T209+T214-T226)*T78
     #-0.1554534543482745D-1*T230*T76)
      S3 = S2+0.1554534543482745D-1*RHOA*(0.2181740656667882D0*T199
     #+T206+T209+T204+T214-T226)*T78
      V2RHOA2(I) = S3-0.1554534543482745D-1*T77*T230+RHOA*
     #(0.8806932620892844D-3*T246-0.2642079786267853D-2*T250
     #-0.8497974591333914D-1*T254-0.2D1*T261+0.1D1*T285
     #+0.3216395899738507D2*T293+0.1554534543482745D-1*
     #(0.935031710000521D-1*T35*T40*T120*T297*T298*T44
     #-0.4675158550002605D-1*T41*T309*T26*T44-0.4675158550002605D-1
     #*T41*T297*T26*T44+0.935031710000521D-1*T41*T110*T66*T126
     #+0.4324422990412758D0*T24*T173*T322-0.2162211495206379D0*T24*T67
     #*(0.4324422990412758D0*T120*SIGMAAA*T327*T298
     #-0.2162211495206379D0*T114*T23*T309*T26-0.2162211495206379D0
     #*T114*T327*T26+0.2805095130001563D0/T338*T35*T341*T298
     #-0.935031710000521D-1*T121*T40*T309*T26-0.935031710000521D-1
     #*T121*T341*T26))*T78-0.1554534543482745D-1*T359*T193)
      V2RHOB2(I) = 0.D0
      V2RHOAB(I) = 0.D0
      T373 = T145**2
      T387 = T149**2
      V2SIGMAAA2(I) = 0.1554534543482745D-1*RHOA*(0.935031710000521D-1
     #*T40*T28*T44-0.4324422990412758D0*T135*T66*T145
     #-0.935031710000521D-1*T138*T167*T145+0.4324422990412758D0*T24
     #*T173*T373-0.2021736311745604D-1*SIGMAAA/T37/T52*T67*T34)*T78
     #-0.1554534543482745D-1*RHOA*T387*T193
      V2SIGMAAAAB(I) = 0.D0
      V2SIGMAAABB(I) = 0.D0
      V2SIGMAAB2(I) = 0.D0
      V2SIGMAABBB(I) = 0.D0
      V2SIGMABB2(I) = 0.D0
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMAAB = SIGMAAB1(I)
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMAAA+SIGMABB+2.D0*SIGMAAB
      T4 = 1/RHO
      T5 = T4**(1.D0/3.D0)
      T7 = 1.D0+0.1325688999052018D0*T5
      T8 = T4**(1.D0/6.D0)
      T11 = SQRT(T4)
      T13 = T5**2
      T15 = 0.598255043577108D1*T8+0.2225569421150687D1*T5
     #+0.8004286349993634D0*T11+0.1897004325747559D0*T13
      T18 = 1.D0+0.1608197949869254D2/T15
      T19 = LOG(T18)
      T21 = 0.621814D-1*T7*T19
      T23 = 1.D0+0.6901399211255825D-1*T5
      T28 = 0.8157414703487641D1*T8+0.2247591863577616D1*T5
     #+0.4300972471276643D0*T11+0.1911512595127338D0*T13
      T31 = 1.D0+0.2960874997779344D2/T28
      T32 = LOG(T31)
      T33 = T23*T32
      T35 = RHOA-1.D0*RHOB
      T36 = T35*T4
      T37 = 1.D0+T36
      T38 = T37**(1.D0/3.D0)
      T39 = T38*T37
      T41 = 1.D0-1.D0*T36
      T42 = T41**(1.D0/3.D0)
      T43 = T42*T41
      T44 = T39+T43-2.D0
      T45 = T35**2
      T46 = T45**2
      T47 = RHO**2
      T48 = T47**2
      T49 = 1/T48
      T50 = T46*T49
      T52 = 1.D0-1.D0*T50
      T53 = T44*T52
      T55 = 0.37995525D-1*T33*T53
      T57 = 1.D0+0.1274696188700087D0*T5
      T62 = 0.1112037486309468D2*T8+0.3844746237447211D1*T5
     #+0.1644733775567609D1*T11+0.2405871291288192D0*T13
      T65 = 1.D0+0.3216395899738507D2/T62
      T66 = LOG(T65)
      T69 = -0.310907D-1*T57*T66+T21
      T70 = T69*T44
      T72 = 0.1923661050931536D1*T70*T50
      T73 = T38**2
      T75 = T42**2
      T77 = 0.5D0*T73+0.5D0*T75
      T78 = T77**2
      T79 = T78*T77
      T80 = 1/T78
      T81 = SIGMA*T80
      T82 = RHO**(1.D0/3.D0)
      T84 = 1/T82/T47
      T85 = -T21+T55+T72
      T86 = 1/T79
      T89 = EXP(-0.3216396844291482D2*T85*T86)
      T90 = T89-1.D0
      T91 = 1/T90
      T92 = T91*SIGMA
      T93 = T80*T84
      T95 = 0.1362107888567592D0*T92*T93
      T96 = 1.D0+T95
      T98 = T90**2
      T99 = 1/T98
      T100 = SIGMA**2
      T101 = T99*T100
      T102 = T78**2
      T103 = 1/T102
      T104 = T82**2
      T106 = 1/T104/T48
      T107 = T103*T106
      T110 = 1.D0+T95+0.1855337900098064D-1*T101*T107
      T111 = 1/T110
      T115 = 1.D0+0.1362107888567592D0*T81*T84*T96*T111
      T116 = LOG(T115)
      T118 = 0.310906908696549D-1*T79*T116
      ZK(I) = RHO*(-T21+T55+T72+T118)
      T124 = 0.1333333333333333D1*T38*T4-0.1333333333333333D1*T42*T4
      T126 = T33*T124*T52
      T127 = 0.37995525D-1*T126
      T128 = T45*T35
      T129 = T44*T128
      T131 = T33*T129*T49
      T132 = 0.1519821D0*T131
      T133 = T69*T124
      T134 = T133*T50
      T135 = 0.1923661050931536D1*T134
      T136 = T128*T49
      T137 = T70*T136
      T138 = 0.7694644203726145D1*T137
      T139 = T78*T116
      T140 = 1/T38
      T143 = 1/T42
      T146 = 0.3333333333333333D0*T140*T4-0.3333333333333333D0*T143*T4
      T147 = T139*T146
      T148 = 0.9327207260896469D-1*T147
      T149 = SIGMA*T86
      T150 = T149*T84
      T151 = T96*T111
      T152 = T151*T146
      T155 = T99*SIGMA
      T156 = T155*T80
      T157 = T127-T132+T135+T138
      T160 = T85*T103
      T163 = -0.3216396844291482D2*T157*T86+0.9649190532874446D2*T160
     #*T146
      T164 = T84*T163
      T165 = T164*T89
      T167 = 0.1362107888567592D0*T156*T165
      T168 = T86*T84
      T171 = 0.2724215777135184D0*T92*T168*T146
      T172 = -T167-T171
      T177 = T81*T84
      T178 = T110**2
      T179 = 1/T178
      T180 = T96*T179
      T182 = 1/T98/T90
      T183 = T182*T100
      T184 = T183*T103
      T185 = T106*T163
      T186 = T185*T89
      T190 = 1/T102/T77
      T191 = T190*T106
      T192 = T191*T146
      T195 = -T167-T171-0.3710675800196129D-1*T184*T186
     #-0.7421351600392257D-1*T101*T192
      T196 = T180*T195
      T199 = -0.2724215777135184D0*T150*T152+0.1362107888567592D0*T81
     #*T84*T172*T111-0.1362107888567592D0*T177*T196
      T200 = T79*T199
      T201 = 1/T115
      T202 = T200*T201
      T203 = 0.310906908696549D-1*T202
      T206 = 1/T13
      T207 = 1/T47
      T208 = T206*T207
      T209 = T208*T19
      T210 = 0.2747773264188438D-2*T209
      T211 = T15**2
      T212 = 1/T211
      T213 = T7*T212
      T214 = T8**2
      T215 = T214**2
      T216 = T215*T8
      T217 = 1/T216
      T218 = T217*T207
      T221 = 1/T11
      T222 = T221*T207
      T224 = 1/T5
      T225 = T224*T207
      T227 = -0.99709173929518D0*T218-0.7418564737168958D0*T208
     #-0.4002143174996817D0*T222-0.1264669550498372D0*T225
      T228 = 1/T18
      T230 = T213*T227*T228
      T231 = 0.1D1*T230
      T232 = T32*T44
      T233 = T232*T52
      T234 = T208*T233
      T235 = 0.87407428755417D-3*T234
      T236 = T28**2
      T237 = 1/T236
      T238 = T23*T237
      T243 = -0.135956911724794D1*T218-0.7491972878592054D0*T208
     #-0.2150486235638321D0*T222-0.1274341730084892D0*T225
      T244 = T238*T243
      T245 = 1/T31
      T246 = T245*T44
      T247 = T246*T52
      T248 = T244*T247
      T249 = 0.1125D1*T248
      T250 = T38*T35
      T253 = T42*T35
      T256 = -0.1333333333333333D1*T250*T207+0.1333333333333333D1*T253
     #*T207
      T258 = T33*T256*T52
      T259 = 0.37995525D-1*T258
      T260 = T44*T46
      T261 = T48*RHO
      T262 = 1/T261
      T264 = T33*T260*T262
      T265 = 0.1519821D0*T264
      T268 = T62**2
      T269 = 1/T268
      T270 = T57*T269
      T275 = -0.1853395810515781D1*T218-0.128158207914907D1*T208
     #-0.8223668877838045D0*T222-0.1603914194192128D0*T225
      T276 = 1/T65
      T282 = 0.1321039893133927D-2*T208*T66+0.1D1*T270*T275*T276
     #-0.2747773264188438D-2*T209-0.1D1*T230
      T283 = T282*T44
      T284 = T283*T50
      T285 = 0.1923661050931536D1*T284
      T286 = T69*T256
      T287 = T286*T50
      T288 = 0.1923661050931536D1*T287
      T289 = T46*T262
      T290 = T70*T289
      T291 = 0.7694644203726145D1*T290
      T292 = T140*T35
      T295 = T143*T35
      T298 = -0.3333333333333333D0*T292*T207+0.3333333333333333D0*T295
     #*T207
      T299 = T139*T298
      T301 = T151*T298
      T304 = T47*RHO
      T306 = 1/T82/T304
      T311 = T210+T231-T235-T249+T259+T265+T285+T288-T291
      T316 = -0.3216396844291482D2*T311*T86+0.9649190532874446D2*T160
     #*T298
      T317 = T84*T316
      T318 = T317*T89
      T320 = 0.1362107888567592D0*T156*T318
      T323 = 0.2724215777135184D0*T92*T168*T298
      T324 = T80*T306
      T326 = 0.3178251739991049D0*T92*T324
      T327 = -T320-T323-T326
      T332 = T106*T316
      T333 = T332*T89
      T336 = T191*T298
      T340 = 1/T104/T261
      T341 = T103*T340
      T344 = -T320-T323-T326-0.3710675800196129D-1*T184*T333
     #-0.7421351600392257D-1*T101*T336-0.8658243533790967D-1*T101*T341
      T345 = T180*T344
      T348 = -0.2724215777135184D0*T150*T301-0.3178251739991049D0*T81
     #*T306*T96*T111+0.1362107888567592D0*T81*T84*T327*T111
     #-0.1362107888567592D0*T177*T345
      T349 = T79*T348
      T350 = T349*T201
      T352 = T210+T231-T235-T249+T259+T265+T285+T288-T291
     #+0.9327207260896469D-1*T299+0.310906908696549D-1*T350
      T353 = RHO*T352
      VRHOA(I) = RHO*(T127-T132+T135+T138+T148+T203)-T21+T55+T72+T118
     #+T353
      T354 = -T124
      T356 = T33*T354*T52
      T357 = 0.37995525D-1*T356
      T358 = 0.1519821D0*T131
      T359 = T69*T354
      T360 = T359*T50
      T361 = 0.1923661050931536D1*T360
      T362 = 0.7694644203726145D1*T137
      T363 = -T146
      T364 = T139*T363
      T365 = 0.9327207260896469D-1*T364
      T366 = T151*T363
      T369 = T357+T358+T361-T362
      T374 = -0.3216396844291482D2*T369*T86+0.9649190532874446D2*T160
     #*T363
      T375 = T84*T374
      T376 = T375*T89
      T378 = 0.1362107888567592D0*T156*T376
      T381 = 0.2724215777135184D0*T92*T168*T363
      T382 = -T378-T381
      T387 = T106*T374
      T388 = T387*T89
      T391 = T191*T363
      T394 = -T378-T381-0.3710675800196129D-1*T184*T388
     #-0.7421351600392257D-1*T101*T391
      T395 = T180*T394
      T398 = -0.2724215777135184D0*T150*T366+0.1362107888567592D0*T81
     #*T84*T382*T111-0.1362107888567592D0*T177*T395
      T399 = T79*T398
      T400 = T399*T201
      T401 = 0.310906908696549D-1*T400
      VRHOB(I) = RHO*(T357+T358+T361-T362+T365+T401)-T21+T55+T72+T118
     #+T353
      T404 = RHO*T79
      T407 = SIGMA*T103
      T412 = T91*T80
      T417 = 0.1362107888567592D0*T412*T84+0.3710675800196129D-1*T155
     #*T107
      T418 = T180*T417
      T421 = 0.1362107888567592D0*T93*T151+0.1855337900098064D-1*T407
     #*T106*T91*T111-0.1362107888567592D0*T177*T418
      T423 = T404*T421*T201
      VSIGMAAA(I) = 0.310906908696549D-1*T423
      VSIGMAAB(I) = 0.6218138173930979D-1*T423
      VSIGMABB(I) = VSIGMAAA(I)
      T427 = 0.87407428755417D-3*T208*T32*T124*T52
      T428 = T48*T47
      T429 = 1/T428
      T432 = T206*T429*T232*T128
      T433 = 0.349629715021668D-2*T432
      T437 = 0.1125D1*T244*T245*T124*T52
      T439 = T244*T246*T136
      T440 = 0.45D1*T439
      T441 = 1/T73
      T443 = 1/T304
      T448 = 1/T75
      T454 = -0.4444444444444444D0*T441*T35*T443-0.1333333333333333D1
     #*T38*T207-0.4444444444444444D0*T448*T35*T443
     #+0.1333333333333333D1*T42*T207
      T457 = 0.37995525D-1*T33*T454*T52
      T460 = T33*T256*T128*T49
      T461 = 0.1519821D0*T460
      T465 = 0.1519821D0*T33*T124*T46*T262
      T467 = T33*T129*T262
      T468 = 0.6079284D0*T467
      T471 = 0.1923661050931536D1*T282*T124*T50
      T472 = T283*T136
      T473 = 0.7694644203726145D1*T472
      T476 = 0.1923661050931536D1*T69*T454*T50
      T477 = T286*T136
      T478 = 0.7694644203726145D1*T477
      T480 = 0.7694644203726145D1*T133*T289
      T482 = T70*T128*T262
      T483 = 0.3077857681490458D2*T482
      T484 = T77*T116
      T485 = T298*T146
      T487 = 0.1865441452179294D0*T484*T485
      T488 = T78*T199
      T489 = T201*T298
      T491 = 0.9327207260896469D-1*T488*T489
      T492 = 1/T39
      T498 = 1/T43
      T504 = 0.1111111111111111D0*T492*T35*T443-0.3333333333333333D0
     #*T140*T207+0.1111111111111111D0*T498*T35*T443
     #+0.3333333333333333D0*T143*T207
      T506 = 0.9327207260896469D-1*T139*T504
      T507 = T78*T348
      T508 = T201*T146
      T510 = 0.9327207260896469D-1*T507*T508
      T511 = T407*T84
      T514 = 0.8172647331405553D0*T511*T151*T485
      T515 = T172*T111
      T518 = 0.2724215777135184D0*T150*T515*T298
      T522 = 0.2724215777135184D0*T150*T180*T298*T195
      T525 = 0.2724215777135184D0*T150*T151*T504
      T526 = T149*T306
      T528 = 0.6356503479982097D0*T526*T152
      T532 = 0.3178251739991049D0*T81*T306*T172*T111
      T533 = T81*T306
      T535 = 0.3178251739991049D0*T533*T196
      T536 = T327*T111
      T539 = 0.2724215777135184D0*T150*T536*T146
      T540 = T182*SIGMA
      T541 = T540*T80
      T542 = T89**2
      T543 = T542*T163
      T546 = 0.2724215777135184D0*T541*T317*T543
      T547 = T155*T86
      T548 = T89*T146
      T551 = 0.2724215777135184D0*T547*T317*T548
      T552 = -T427+T433-T437+T440+T457-T461+T465+T468+T471+T473+T476
     #+T478-T480-T483
      T555 = T311*T103
      T557 = 0.9649190532874446D2*T555*T146
      T558 = T157*T103
      T560 = 0.9649190532874446D2*T558*T298
      T561 = T85*T190
      T563 = 0.3859676213149779D3*T561*T485
      T565 = 0.9649190532874446D2*T160*T504
      T566 = -0.3216396844291482D2*T552*T86+T557+T560-T563+T565
      T570 = 0.1362107888567592D0*T156*T84*T566*T89
      T571 = T163*T89
      T574 = 0.1362107888567592D0*T156*T317*T571
      T575 = T84*T298
      T578 = 0.2724215777135184D0*T547*T575*T571
      T579 = T92*T103
      T582 = 0.8172647331405553D0*T579*T575*T146
      T585 = 0.2724215777135184D0*T92*T168*T504
      T589 = 0.3178251739991049D0*T156*T306*T163*T89
      T590 = T86*T306
      T593 = 0.6356503479982097D0*T92*T590*T146
      T599 = T327*T179
      T602 = 0.1362107888567592D0*T177*T599*T195
      T606 = 0.2724215777135184D0*T150*T180*T344*T146
      T607 = T172*T179
      T610 = 0.1362107888567592D0*T177*T607*T344
      T613 = T96/T178/T110
      T617 = 0.2724215777135184D0*T177*T613*T344*T195
      T618 = T98**2
      T621 = 1/T618*T100*T103
      T624 = 0.1113202740058839D0*T621*T332*T543
      T625 = T183*T190
      T628 = 0.1484270320078451D0*T625*T332*T548
      T635 = 0.3710675800196129D-1*T184*T332*T571
      T636 = T106*T298
      T639 = 0.1484270320078451D0*T625*T636*T571
      T641 = 1/T102/T78
      T642 = T101*T641
      T645 = 0.3710675800196129D0*T642*T636*T146
      T648 = 0.7421351600392257D-1*T101*T191*T504
      T652 = 0.1731648706758193D0*T184*T340*T163*T89
      T653 = T190*T340
      T656 = 0.3463297413516387D0*T101*T653*T146
      T657 = T546+T551-T570-T574+T578+T582-T585+T589+T593+T624+T628
     #-0.3710675800196129D-1*T184*T106*T566*T89-T635+T639+T645-T648
     #+T652+T656
      T661 = T514-T518+T522-T525+T528-T532+T535-T539
     #+0.1362107888567592D0*T81*T84*(T546+T551-T570-T574+T578+T582
     #-T585+T589+T593)*T111-T602+T606-T610+T617-0.1362107888567592D0
     #*T177*T180*T657
      T665 = T115**2
      T666 = 1/T665
      T669 = 0.310906908696549D-1*T349*T666*T199
      T670 = -T427+T433-T437+T440+T457-T461+T465+T468+T471+T473+T476
     #+T478-T480-T483+T487+T491+T506+T510+0.310906908696549D-1*T79
     #*T661*T201-T669
      T671 = RHO*T670
      T677 = 0.4444444444444444D0*T441*T207+0.4444444444444444D0*T448
     #*T207
      T680 = 0.37995525D-1*T33*T677*T52
      T683 = T33*T124*T128*T49
      T684 = 0.3039642D0*T683
      T687 = T33*T44*T45*T49
      T688 = 0.4559463D0*T687
      T691 = 0.1923661050931536D1*T69*T677*T50
      T692 = T133*T136
      T693 = 0.1538928840745229D2*T692
      T695 = T70*T45*T49
      T696 = 0.2308393261117844D2*T695
      T697 = T146**2
      T706 = -0.1111111111111111D0*T492*T207-0.1111111111111111D0*T498
     #*T207
      T708 = 0.9327207260896469D-1*T139*T706
      T721 = 0.2724215777135184D0*T150*T151*T706
      T722 = T163**2
      T723 = T84*T722
      T726 = 0.2724215777135184D0*T541*T723*T542
      T729 = 0.5448431554270369D0*T547*T164*T548
      T738 = 0.9649190532874446D2*T160*T706
      T739 = -0.3216396844291482D2*(T680-T684-T688+T691+T693+T696)*T86
     #+0.1929838106574889D3*T558*T146-0.3859676213149779D3*T561*T697
     #+T738
      T743 = 0.1362107888567592D0*T156*T84*T739*T89
      T746 = 0.1362107888567592D0*T156*T723*T89
      T747 = T103*T84
      T750 = 0.8172647331405553D0*T92*T747*T697
      T753 = 0.2724215777135184D0*T92*T168*T706
      T762 = T195**2
      T766 = T106*T722
      T780 = T641*T106
      T786 = 0.7421351600392257D-1*T101*T191*T706
      T787 = T726+T729-T743-T746+T750-T753+0.1113202740058839D0*T621
     #*T766*T542+0.2968540640156903D0*T625*T185*T548
     #-0.3710675800196129D-1*T184*T106*T739*T89-0.3710675800196129D-1
     #*T184*T766*T89+0.3710675800196129D0*T101*T780*T697-T786
      T795 = T199**2
      T799 = T680-T684-T688+T691+T693+T696+0.1865441452179294D0*T484
     #*T697+0.1865441452179294D0*T488*T508+T708+0.310906908696549D-1
     #*T79*(0.8172647331405553D0*T511*T151*T697-0.5448431554270369D0
     #*T150*T515*T146+0.5448431554270369D0*T150*T180*T146*T195-T721
     #+0.1362107888567592D0*T81*T84*(T726+T729-T743-T746+T750-T753)
     #*T111-0.2724215777135184D0*T177*T607*T195+0.2724215777135184D0
     #*T177*T613*T762-0.1362107888567592D0*T177*T180*T787)*T201
     #-0.310906908696549D-1*T79*T795*T666
      T801 = 0.45D1*T439
      T802 = -T427-T437+T457+T465+T433+T801-T461+T468+T471+T476-T480
     #+T473+T478-T483
      T805 = -0.3216396844291482D2*T802*T86+T560+T557-T563+T565
      T809 = 0.1362107888567592D0*T156*T84*T805*T89
      T819 = T546+T578+T589-T809-T574+T551+T582+T593-T585+T624+T639
     #+T652-0.3710675800196129D-1*T184*T106*T805*T89-T635+T628+T645
     #+T656-T648
      T823 = T514+T528-T539+T606-T525-T518-T532+0.1362107888567592D0
     #*T81*T84*(T546+T578+T589-T809-T574+T551+T582+T593-T585)*T111
     #-T610+T522+T535-T602+T617-0.1362107888567592D0*T177*T180*T819
      T827 = -T427-T437+T457+T465+T433+T801-T461+T468+T471+T476-T480
     #+T473+T478-T483+T487+T510+T506+T491+0.310906908696549D-1*T79
     #*T823*T201-T669
      T828 = RHO*T827
      T829 = 0.5495546528376876D-2*T209
      T831 = 0.2D1*T230
      T836 = 0.1538928840745229D2*T290
      T837 = 0.1865441452179294D0*T299
      T838 = 0.3847322101863073D1*T287
      T839 = 0.7599105D-1*T258
      T840 = 0.174814857510834D-2*T234
      T841 = 0.225D1*T248
      T842 = 0.3039642D0*T264
      T843 = 0.3847322101863073D1*T284
      T844 = 0.6218138173930979D-1*T350
      T848 = 1/T13/T4*T49
      T849 = T848*T19
      T850 = 0.1831848842792292D-2*T849
      T851 = T348**2
      T858 = T227**2
      T860 = T7/T211/T15*T858*T228
      T861 = 0.2D1*T860
      T864 = 1/T216/T4*T49
      T866 = T217*T443
      T869 = T206*T443
      T873 = 1/T11/T4*T49
      T875 = T221*T443
      T879 = 1/T5/T4*T49
      T881 = T224*T443
      T885 = T213*(-0.8309097827459833D0*T864+0.199418347859036D1*T866
     #-0.4945709824779306D0*T848+0.1483712947433792D1*T869
     #-0.2001071587498409D0*T873+0.8004286349993634D0*T875
     #-0.4215565168327908D-1*T879+0.2529339100996745D0*T881)*T228
      T886 = 0.1D1*T885
      T887 = T211**2
      T890 = T18**2
      T893 = T7/T887*T858/T890
      T894 = 0.1608197949869254D2*T893
      T898 = 0.225D1*T244*T245*T256*T52
      T900 = 0.174814857510834D-2*T869*T233
      T901 = T236**2
      T904 = T243**2
      T906 = T31**2
      T911 = 0.3330984372501762D2*T23/T901*T904/T906*T44*T52
      T914 = 0.9D1*T244*T246*T289
      T917 = T208*T212*T227*T228
      T918 = 0.8837926660346786D-1*T917
      T919 = T869*T19
      T920 = 0.5495546528376876D-2*T919
      T923 = 0.7599105D0*T33*T260*T429
      T927 = 0.3039642D0*T33*T256*T46*T262
      T939 = T275**2
      T955 = T268**2
      T958 = T65**2
      T969 = 0.8806932620892844D-3*T848*T66-0.2642079786267853D-2*T869
     #*T66-0.8497974591333914D-1*T208*T269*T275*T276-0.2D1*T57/T268
     #/T62*T939*T276+0.1D1*T270*(-0.1544496508763151D1*T864
     #+0.3706791621031562D1*T866-0.854388052766047D0*T848
     #+0.2563164158298141D1*T869-0.4111834438919023D0*T873
     #+0.1644733775567609D1*T875-0.5346380647307093D-1*T879
     #+0.3207828388384256D0*T881)*T276+0.3216395899738507D2*T57/T955
     #*T939/T958-0.1831848842792292D-2*T849+0.5495546528376876D-2*T919
     #+0.8837926660346786D-1*T917+0.2D1*T860-0.1D1*T885
     #-0.1608197949869254D2*T893
      T972 = 0.1923661050931536D1*T969*T44*T50
      T983 = 0.4444444444444444D0*T441*T45*T49+0.2666666666666667D1
     #*T250*T443+0.4444444444444444D0*T448*T45*T49
     #-0.2666666666666667D1*T253*T443
      T986 = 0.37995525D-1*T33*T983*T52
      T987 = T850-0.310906908696549D-1*T79*T851*T666-T861+T886+T894
     #-T898+T900-T911-T914-T918-T920-T923+T927+T972+T986
      T989 = 0.1538928840745229D2*T286*T289
      T992 = 0.1923661050931536D1*T69*T983*T50
      T994 = 0.58271619170278D-3*T848*T233
      T1006 = 0.1125D1*T238*(-0.1132974264373283D1*T864
     #+0.271913823449588D1*T866-0.4994648585728036D0*T848
     #+0.1498394575718411D1*T869-0.1075243117819161D0*T873
     #+0.4300972471276643D0*T875-0.4247805766949639D-1*T879
     #+0.2548683460169784D0*T881)*T247
      T1008 = 1/T48/T304
      T1012 = 0.699259430043336D-2*T206*T1008*T232*T46
      T1017 = 0.5176049408441869D-1*T208*T237*T243*T245*T53
      T1023 = 0.225D1*T23/T236/T28*T904*T247
      T1024 = T298**2
      T1029 = 0.3847322101863073D1*T282*T256*T50
      T1031 = 0.1538928840745229D2*T283*T289
      T1034 = 0.3847322101863073D2*T70*T46*T429
      T1038 = 0.174814857510834D-2*T208*T32*T256*T52
      T1054 = 1/T82/T48
      T1073 = -0.1111111111111111D0*T492*T45*T49+0.6666666666666667D0
     #*T292*T443-0.1111111111111111D0*T498*T45*T49
     #-0.6666666666666667D0*T295*T443
      T1077 = T316**2
      T1078 = T84*T1077
      T1081 = 0.2724215777135184D0*T541*T1078*T542
      T1082 = T89*T298
      T1085 = 0.5448431554270369D0*T547*T317*T1082
      T1089 = 0.6356503479982097D0*T156*T306*T316*T89
      T1090 = T850-T861+T886+T894-T898+T900-T911-T914-T918-T920-T923
     #+T927
      T1091 = T972+T986-T989+T992-T994-T1006-T1012+T1017+T1023+T1029
     #-T1031+T1034-T1038
      T1101 = -0.3216396844291482D2*(T1090+T1091)*T86
     #+0.1929838106574889D3*T555*T298-0.3859676213149779D3*T561*T1024
     #+0.9649190532874446D2*T160*T1073
      T1105 = 0.1362107888567592D0*T156*T84*T1101*T89
      T1108 = 0.1362107888567592D0*T156*T1078*T89
      T1111 = 0.8172647331405553D0*T92*T747*T1024
      T1114 = 0.1271300695996419D1*T92*T590*T298
      T1117 = 0.2724215777135184D0*T92*T168*T1073
      T1120 = 0.1059417246663683D1*T92*T80*T1054
      T1129 = T344**2
      T1150 = T106*T1077
      T1165 = T1111+T1114-T1117+T1120+T1089+T1081+T1085-T1108-T1105
     #+0.3710675800196129D0*T101*T780*T1024+0.6926594827032773D0*T101
     #*T653*T298+0.3463297413516387D0*T184*T340*T316*T89
     #-0.7421351600392257D-1*T101*T191*T1073-0.3710675800196129D-1
     #*T184*T106*T1101*T89+0.1113202740058839D0*T621*T1150*T542
     #+0.4906338002481548D0*T101*T103/T104/T428+0.2968540640156903D0
     #*T625*T332*T1082-0.3710675800196129D-1*T184*T1150*T89
      T1169 = 0.8172647331405553D0*T511*T151*T1024
     #+0.1271300695996419D1*T526*T301-0.5448431554270369D0*T150*T536
     #*T298+0.5448431554270369D0*T150*T180*T298*T344
     #+0.6356503479982097D0*T533*T345+0.1059417246663683D1*T81*T1054
     #*T96*T111-0.6356503479982097D0*T81*T306*T327*T111
     #-0.2724215777135184D0*T150*T151*T1073+0.1362107888567592D0*T81
     #*T84*(T1081+T1085+T1089-T1105-T1108+T1111+T1114-T1117+T1120)
     #*T111-0.2724215777135184D0*T177*T599*T344+0.2724215777135184D0
     #*T177*T613*T1129-0.1362107888567592D0*T177*T180*T1165
      T1177 = -T989+T992-T994-T1006-T1012+T1017+T1023
     #+0.1865441452179294D0*T484*T1024+T1029-T1031+T1034-T1038
     #+0.310906908696549D-1*T79*T1169*T201+0.1865441452179294D0*T507
     #*T489+0.9327207260896469D-1*T139*T1073
      T1179 = RHO*(T987+T1177)
      T1180 = -T836+T837+T838+T839-T840-T841+T842+T843+T844
     #+0.3847322101863073D1*T134+T1179
      V2RHOA2(I) = T671-0.3039642D0*T131+RHO*T799+T828+T829
     #+0.6218138173930979D-1*T202+T831+0.1538928840745229D2*T137
     #+0.1865441452179294D0*T147+0.7599105D-1*T126+T1180
      T1184 = T33*T354*T128*T49
      T1185 = 0.3039642D0*T1184
      T1186 = T359*T136
      T1187 = 0.1538928840745229D2*T1186
      T1188 = T363**2
      T1191 = T78*T398
      T1192 = T201*T363
      T1198 = T382*T111
      T1206 = T374**2
      T1207 = T84*T1206
      T1210 = 0.2724215777135184D0*T541*T1207*T542
      T1211 = T89*T363
      T1214 = 0.5448431554270369D0*T547*T375*T1211
      T1218 = T369*T103
      T1223 = -0.3216396844291482D2*(T680+T1185-T688+T691-T1187+T696)
     #*T86+0.1929838106574889D3*T1218*T363-0.3859676213149779D3*T561
     #*T1188+T738
      T1227 = 0.1362107888567592D0*T156*T84*T1223*T89
      T1230 = 0.1362107888567592D0*T156*T1207*T89
      T1233 = 0.8172647331405553D0*T92*T747*T1188
      T1239 = T382*T179
      T1243 = T394**2
      T1247 = T106*T1206
      T1264 = T1210+T1214-T1227-T1230+T1233-T753+0.1113202740058839D0
     #*T621*T1247*T542+0.2968540640156903D0*T625*T387*T1211
     #-0.3710675800196129D-1*T184*T106*T1223*T89-0.3710675800196129D-1
     #*T184*T1247*T89+0.3710675800196129D0*T101*T780*T1188-T786
      T1272 = T398**2
      T1276 = T680+T1185-T688+T691-T1187+T696+0.1865441452179294D0
     #*T484*T1188+0.1865441452179294D0*T1191*T1192+T708
     #+0.310906908696549D-1*T79*(0.8172647331405553D0*T511*T151*T1188
     #-0.5448431554270369D0*T150*T1198*T363+0.5448431554270369D0*T150
     #*T180*T363*T394-T721+0.1362107888567592D0*T81*T84*(T1210+T1214
     #-T1227-T1230+T1233-T753)*T111-0.2724215777135184D0*T177*T1239
     #*T394+0.2724215777135184D0*T177*T613*T1243-0.1362107888567592D0
     #*T177*T180*T1264)*T201-0.310906908696549D-1*T79*T1272*T666
      T1285 = 0.87407428755417D-3*T208*T32*T354*T52
      T1286 = 0.349629715021668D-2*T432
      T1290 = 0.1125D1*T244*T245*T354*T52
      T1291 = 0.45D1*T439
      T1292 = -T454
      T1295 = 0.37995525D-1*T33*T1292*T52
      T1296 = 0.1519821D0*T460
      T1300 = 0.1519821D0*T33*T354*T46*T262
      T1301 = 0.6079284D0*T467
      T1304 = 0.1923661050931536D1*T282*T354*T50
      T1305 = 0.7694644203726145D1*T472
      T1308 = 0.1923661050931536D1*T69*T1292*T50
      T1309 = 0.7694644203726145D1*T477
      T1311 = 0.7694644203726145D1*T359*T289
      T1312 = 0.3077857681490458D2*T482
      T1313 = T298*T363
      T1318 = -T504
      T1347 = T542*T374
      T1350 = 0.2724215777135184D0*T541*T317*T1347
      T1353 = 0.2724215777135184D0*T547*T317*T1211
      T1354 = -T1285-T1286-T1290-T1291+T1295+T1296+T1300-T1301+T1304
     #-T1305+T1308-T1309-T1311+T1312
      T1365 = -0.3216396844291482D2*T1354*T86+0.9649190532874446D2
     #*T555*T363+0.9649190532874446D2*T1218*T298-0.3859676213149779D3
     #*T561*T1313+0.9649190532874446D2*T160*T1318
      T1369 = 0.1362107888567592D0*T156*T84*T1365*T89
      T1370 = T374*T89
      T1373 = 0.1362107888567592D0*T156*T317*T1370
      T1376 = 0.2724215777135184D0*T547*T575*T1370
      T1379 = 0.8172647331405553D0*T579*T575*T363
      T1382 = 0.2724215777135184D0*T92*T168*T1318
      T1386 = 0.3178251739991049D0*T156*T306*T374*T89
      T1389 = 0.6356503479982097D0*T92*T590*T363
      T1438 = T1350+T1353-T1369-T1373+T1376+T1379-T1382+T1386+T1389
     #+0.1113202740058839D0*T621*T332*T1347+0.1484270320078451D0*T625
     #*T332*T1211-0.3710675800196129D-1*T184*T106*T1365*T89
     #-0.3710675800196129D-1*T184*T332*T1370+0.1484270320078451D0*T625
     #*T636*T1370+0.3710675800196129D0*T642*T636*T363
     #-0.7421351600392257D-1*T101*T191*T1318+0.1731648706758193D0*T184
     #*T340*T374*T89+0.3463297413516387D0*T101*T653*T363
      T1442 = 0.8172647331405553D0*T511*T151*T1313
     #-0.2724215777135184D0*T150*T1198*T298+0.2724215777135184D0*T150
     #*T180*T298*T394-0.2724215777135184D0*T150*T151*T1318
     #+0.6356503479982097D0*T526*T366-0.3178251739991049D0*T81*T306
     #*T382*T111+0.3178251739991049D0*T533*T395-0.2724215777135184D0
     #*T150*T536*T363+0.1362107888567592D0*T81*T84*(T1350+T1353-T1369
     #-T1373+T1376+T1379-T1382+T1386+T1389)*T111-0.1362107888567592D0
     #*T177*T599*T394+0.2724215777135184D0*T150*T180*T344*T363
     #-0.1362107888567592D0*T177*T1239*T344+0.2724215777135184D0*T177
     #*T613*T344*T394-0.1362107888567592D0*T177*T180*T1438
      T1446 = T666*T398
      T1449 = -T1285-T1286-T1290-T1291+T1295+T1296+T1300-T1301+T1304
     #-T1305+T1308-T1309-T1311+T1312+0.1865441452179294D0*T484*T1313
     #+0.9327207260896469D-1*T1191*T489+0.9327207260896469D-1*T139
     #*T1318+0.9327207260896469D-1*T507*T1192+0.310906908696549D-1*T79
     #*T1442*T201-0.310906908696549D-1*T349*T1446
      T1450 = RHO*T1449
      V2RHOB2(I) = 0.3039642D0*T131+T829+RHO*T1276+T831
     #-0.1538928840745229D2*T137-T836+T837+T838+T839-T840-T841+T842
     #+T843+T844+0.3847322101863073D1*T360+0.7599105D-1*T356+2*T1450
     #+T1179+0.6218138173930979D-1*T400+0.1865441452179294D0*T364
      T1455 = -T677
      T1458 = 0.37995525D-1*T33*T1455*T52
      T1459 = 0.1519821D0*T683
      T1460 = 0.1519821D0*T1184
      T1461 = 0.4559463D0*T687
      T1464 = 0.1923661050931536D1*T69*T1455*T50
      T1465 = 0.7694644203726145D1*T692
      T1466 = 0.7694644203726145D1*T1186
      T1467 = 0.2308393261117844D2*T695
      T1468 = T146*T363
      T1473 = -T706
      T1496 = 0.2724215777135184D0*T541*T164*T1347
      T1499 = 0.2724215777135184D0*T547*T164*T1211
      T1511 = -0.3216396844291482D2*(T1458+T1459-T1460+T1461+T1464
     #-T1465+T1466-T1467)*T86+0.9649190532874446D2*T558*T363
     #+0.9649190532874446D2*T1218*T146-0.3859676213149779D3*T561*T1468
     #+0.9649190532874446D2*T160*T1473
      T1515 = 0.1362107888567592D0*T156*T84*T1511*T89
      T1518 = 0.1362107888567592D0*T156*T164*T1370
      T1519 = T84*T146
      T1522 = 0.2724215777135184D0*T547*T1519*T1370
      T1525 = 0.8172647331405553D0*T579*T1519*T363
      T1528 = 0.2724215777135184D0*T92*T168*T1473
      T1561 = T106*T146
      T1571 = T1496+T1499-T1515-T1518+T1522+T1525-T1528
     #+0.1113202740058839D0*T621*T185*T1347+0.1484270320078451D0*T625
     #*T185*T1211-0.3710675800196129D-1*T184*T106*T1511*T89
     #-0.3710675800196129D-1*T184*T185*T1370+0.1484270320078451D0*T625
     #*T1561*T1370+0.3710675800196129D0*T642*T1561*T363
     #-0.7421351600392257D-1*T101*T191*T1473
      T1575 = 0.8172647331405553D0*T511*T151*T1468
     #-0.2724215777135184D0*T150*T1198*T146+0.2724215777135184D0*T150
     #*T180*T146*T394-0.2724215777135184D0*T150*T151*T1473
     #-0.2724215777135184D0*T150*T515*T363+0.1362107888567592D0*T81
     #*T84*(T1496+T1499-T1515-T1518+T1522+T1525-T1528)*T111
     #-0.1362107888567592D0*T177*T607*T394+0.2724215777135184D0*T150
     #*T180*T195*T363-0.1362107888567592D0*T177*T1239*T195
     #+0.2724215777135184D0*T177*T613*T195*T394-0.1362107888567592D0
     #*T177*T180*T1571
      T1581 = T1458+T1459-T1460+T1461+T1464-T1465+T1466-T1467
     #+0.1865441452179294D0*T484*T1468+0.9327207260896469D-1*T1191
     #*T508+0.9327207260896469D-1*T139*T1473+0.9327207260896469D-1
     #*T488*T1192+0.310906908696549D-1*T79*T1575*T201
     #-0.310906908696549D-1*T200*T1446
      T1584 = T829+0.5D0*T671-T840+T148-T841+RHO*T1581+T842+T1179+T831
     #+T839+T843+0.5D0*T828
      T1586 = -T836+T838+T203+T844+T357+T361+T365+T401+0.1D1*T1450
     #+T127+T135+T837
      V2RHOAB(I) = T1584+T1586
      T1587 = T78*T421
      T1593 = SIGMA*T190*T106
      T1594 = T91*T111
      T1604 = T99*T80
      T1606 = 0.1362107888567592D0*T1604*T165
      T1607 = T91*T86
      T1609 = 0.2724215777135184D0*T1607*T1519
      T1620 = T407*T106
      T1621 = T91*T179
      T1629 = T540*T103
      T1642 = T666*T421
      T1646 = RHO*(0.9327207260896469D-1*T1587*T508
     #+0.310906908696549D-1*T79*(-0.2724215777135184D0*T168*T152
     #-0.3710675800196129D-1*T1593*T1594*T146+0.2724215777135184D0
     #*T150*T180*T146*T417+0.1362107888567592D0*T93*T515
     #+0.1362107888567592D0*T81*T84*(-T1606-T1609)*T111
     #-0.1362107888567592D0*T177*T607*T417-0.1362107888567592D0*T93
     #*T196-0.1855337900098064D-1*T1620*T1621*T195
     #+0.2724215777135184D0*T177*T613*T195*T417-0.1362107888567592D0
     #*T177*T180*(-T1606-T1609-0.7421351600392257D-1*T1629*T186
     #-0.1484270320078451D0*T155*T192))*T201-0.310906908696549D-1*T200
     #*T1642)
      T1648 = T79*T421*T201
      T1649 = 0.310906908696549D-1*T1648
      T1672 = 0.1362107888567592D0*T1604*T318
      T1674 = 0.2724215777135184D0*T1607*T575
      T1676 = 0.3178251739991049D0*T412*T306
      T1704 = -0.2724215777135184D0*T168*T301-0.3710675800196129D-1
     #*T1593*T1594*T298+0.2724215777135184D0*T150*T180*T298*T417
     #-0.3178251739991049D0*T324*T151-0.4329121766895483D-1*T407*T340
     #*T91*T111+0.3178251739991049D0*T533*T418+0.1362107888567592D0
     #*T93*T536+0.1362107888567592D0*T81*T84*(-T1672-T1674-T1676)*T111
     #-0.1362107888567592D0*T177*T599*T417-0.1362107888567592D0*T93
     #*T345-0.1855337900098064D-1*T1620*T1621*T344
     #+0.2724215777135184D0*T177*T613*T344*T417-0.1362107888567592D0
     #*T177*T180*(-T1672-T1674-T1676-0.7421351600392257D-1*T1629*T333
     #-0.1484270320078451D0*T155*T336-0.1731648706758193D0*T155*T341)
      T1711 = RHO*(0.9327207260896469D-1*T1587*T489
     #+0.310906908696549D-1*T79*T1704*T201-0.310906908696549D-1*T349
     #*T1642)
      V2RHOASIGMAAA(I) = T1646+T1649+T1711
      T1713 = 0.6218138173930979D-1*T1648
      T1714 = 2.D0*T1711
      V2RHOASIGMAAB(I) = 2.D0*T1646+T1713+T1714
      V2RHOASIGMABB(I) = V2RHOASIGMAAA(I)
      T1729 = 0.1362107888567592D0*T1604*T376
      T1732 = 0.2724215777135184D0*T1607*T84*T363
      T1765 = RHO*(0.9327207260896469D-1*T1587*T1192
     #+0.310906908696549D-1*T79*(-0.2724215777135184D0*T168*T366
     #-0.3710675800196129D-1*T1593*T1594*T363+0.2724215777135184D0
     #*T150*T180*T363*T417+0.1362107888567592D0*T93*T1198
     #+0.1362107888567592D0*T81*T84*(-T1729-T1732)*T111
     #-0.1362107888567592D0*T177*T1239*T417-0.1362107888567592D0*T93
     #*T395-0.1855337900098064D-1*T1620*T1621*T394
     #+0.2724215777135184D0*T177*T613*T394*T417-0.1362107888567592D0
     #*T177*T180*(-T1729-T1732-0.7421351600392257D-1*T1629*T388
     #-0.1484270320078451D0*T155*T391))*T201-0.310906908696549D-1*T399
     #*T1642)
      V2RHOBSIGMAAA(I) = T1765+T1649+T1711
      V2RHOBSIGMAAB(I) = 2.D0*T1765+T1713+T1714
      V2RHOBSIGMABB(I) = V2RHOBSIGMAAA(I)
      T1774 = T417**2
      T1785 = T404*(0.3710675800196129D-1*T107*T1594
     #-0.2724215777135184D0*T93*T418-0.3710675800196129D-1*T1620*T1621
     #*T417+0.2724215777135184D0*T177*T613*T1774-0.5054340779364009D-2
     #*SIGMA*T641*T1008*T180*T99)*T201
      T1787 = T421**2
      T1789 = T404*T1787*T666
      V2SIGMAAA2(I) = 0.310906908696549D-1*T1785-0.310906908696549D-1
     #*T1789
      V2SIGMAAAAB(I) = 0.6218138173930979D-1*T1785
     #-0.6218138173930979D-1*T1789
      V2SIGMAAABB(I) = V2SIGMAAA2(I)
      V2SIGMAAB2(I) = 0.1243627634786196D0*T1785-0.1243627634786196D0
     #*T1789
      V2SIGMAABBB(I) = V2SIGMAAAAB(I)
      V2SIGMABB2(I) = V2SIGMAAABB(I)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      V2RHOB2(I) = 0.0D0
      V2RHOAB(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      VSIGMAAB(I) = 0.0D0
      VSIGMABB(I) = 0.0D0
      V2RHOASIGMAAA(I) = 0.0D0
      V2RHOASIGMAAB(I) = 0.0D0
      V2RHOASIGMABB(I) = 0.0D0
      V2RHOBSIGMAAA(I) = 0.0D0
      V2RHOBSIGMAAB(I) = 0.0D0
      V2RHOBSIGMABB(I) = 0.0D0
      V2SIGMAAA2(I) = 0.0D0
      V2SIGMAAB2(I) = 0.0D0
      V2SIGMABB2(I) = 0.0D0
      V2SIGMAAAAB(I) = 0.0D0
      V2SIGMAAABB(I) = 0.0D0
      V2SIGMAABBB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C*MODULE DFTXCB  *DECK RKS_C_PBE
      SUBROUTINE RKS_C_PBE
     & (IDERIV,NPT,RHOA1,SIGMAAA1,
     &  ZK,VRHOA,VSIGMAAA,
     &  V2RHOA2,V2RHOASIGMAAA,V2SIGMAAA2)
C
C     J.P. PERDEW, K. BURKE, AND M. ERNZERHOF
C     GENERALIZED GRADIENT APPROXIMATION MADE SIMPLE
C     PHYS. REV. LETT. 77 (1996) 3865-3868
C
      IMPLICIT DOUBLE PRECISION(A-H,O-Z)
      INTEGER IDERIV,NPT
      DOUBLE PRECISION RHOA1(NPT)
      DOUBLE PRECISION SIGMAAA1(NPT)
      DOUBLE PRECISION ZK(NPT),VRHOA(NPT),VSIGMAAA(NPT)
      DOUBLE PRECISION V2RHOA2(NPT),V2RHOASIGMAAA(NPT),V2SIGMAAA2(NPT)
      PARAMETER(TOL=1.0D-20)
C
      IF(IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.D0,SIGMAAA1(I))
      T2 = 1/RHO
      T3 = T2**(1.D0/3.D0)
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T17 = LOG(1.D0+0.1608197949869254D2/(0.598255043577108D1*T6
     #+0.2225569421150687D1*T3+0.8004286349993634D0*T9
     #+0.1897004325747559D0*T11))
      T18 = (1.D0+0.1325688999052018D0*T3)*T17
      T20 = RHO**2
      T21 = RHO**(1.D0/3.D0)
      T23 = 1/T21/T20
      T26 = EXP(0.2000000587336264D1*T18)
      T27 = T26-1.D0
      T31 = 0.1362107888567592D0/T27*SIGMA*T23
      T33 = T27**2
      T35 = SIGMA**2
      T37 = T20**2
      T38 = T21**2
      T49 = LOG(1.D0+0.1362107888567592D0*SIGMA*T23*(1.D0+T31)/(1.D0
     #+T31+0.1855337900098064D-1/T33*T35/T38/T37))
      ZK(I) = RHO*(-0.621814D-1*T18+0.310906908696549D-1*T49)
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.D0,SIGMAAA1(I))
      T2 = 1/RHO
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1325688999052018D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.598255043577108D1*T6+0.2225569421150687D1*T3
     #+0.8004286349993634D0*T9+0.1897004325747559D0*T11
      T16 = 1.D0+0.1608197949869254D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.621814D-1*T18
      T20 = RHO**2
      T21 = RHO**(1.D0/3.D0)
      T23 = 1/T21/T20
      T24 = SIGMA*T23
      T26 = EXP(0.2000000587336264D1*T18)
      T27 = T26-1.D0
      T28 = 1/T27
      T29 = T28*SIGMA
      T31 = 0.1362107888567592D0*T29*T23
      T32 = 1.D0+T31
      T33 = T27**2
      T34 = 1/T33
      T35 = SIGMA**2
      T36 = T34*T35
      T37 = T20**2
      T38 = T21**2
      T40 = 1/T38/T37
      T43 = 1.D0+T31+0.1855337900098064D-1*T36*T40
      T44 = 1/T43
      T45 = T32*T44
      T48 = 1.D0+0.1362107888567592D0*T24*T45
      T49 = LOG(T48)
      T50 = 0.310906908696549D-1*T49
      ZK(I) = RHO*(-T19+T50)
      T53 = 1/T20
      T54 = 1/T11*T53
      T56 = 0.2747773264188438D-2*T54*T17
      T57 = T13**2
      T60 = T6**2
      T61 = T60**2
      T77 = 0.1D1*T5/T57*(-0.99709173929518D0/T61/T6*T53
     #-0.7418564737168958D0*T54-0.4002143174996817D0/T9*T53
     #-0.1264669550498372D0/T3*T53)/T16
      T80 = 1/T21/T20/RHO
      T84 = T34*SIGMA
      T85 = T56+T77
      T89 = 0.4381079514373337D1*T84*T23*T85*T26
      T91 = 0.3178251739991049D0*T29*T80
      T96 = T43**2
      T98 = T32/T96
      T116 = 1/T48
      VRHOA(I) = -T19+T50+RHO*(T56+T77+0.310906908696549D-1*(
     #-0.3178251739991049D0*SIGMA*T80*T45+0.1362107888567592D0*T24*
     #(T89-T91)*T44-0.1362107888567592D0*T24*T98*(T89-T91
     #+0.119350059339396D1/T33/T27*T35*T40*T85*T26
     #-0.8658243533790967D-1*T36/T38/T37/RHO))*T116)
      VSIGMAAA(I) = 0.1243627634786196D0*RHO*(0.1362107888567592D0*T23
     #*T32*T44+0.1855337900098064D-1*SIGMA*T40*T28*T44
     #-0.1362107888567592D0*T24*T98*(0.1362107888567592D0*T28*T23
     #+0.3710675800196129D-1*T84*T40))*T116
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.D0,SIGMAAA1(I))
      T2 = 1/RHO
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1325688999052018D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.598255043577108D1*T6+0.2225569421150687D1*T3
     #+0.8004286349993634D0*T9+0.1897004325747559D0*T11
      T16 = 1.D0+0.1608197949869254D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.621814D-1*T18
      T20 = RHO**2
      T21 = RHO**(1.D0/3.D0)
      T23 = 1/T21/T20
      T24 = SIGMA*T23
      T26 = EXP(0.2000000587336264D1*T18)
      T27 = T26-1.D0
      T28 = 1/T27
      T29 = T28*SIGMA
      T31 = 0.1362107888567592D0*T29*T23
      T32 = 1.D0+T31
      T33 = T27**2
      T34 = 1/T33
      T35 = SIGMA**2
      T36 = T34*T35
      T37 = T20**2
      T38 = T21**2
      T40 = 1/T38/T37
      T43 = 1.D0+T31+0.1855337900098064D-1*T36*T40
      T44 = 1/T43
      T45 = T32*T44
      T48 = 1.D0+0.1362107888567592D0*T24*T45
      T49 = LOG(T48)
      T50 = 0.310906908696549D-1*T49
      ZK(I) = RHO*(-T19+T50)
      T52 = 1/T11
      T53 = 1/T20
      T54 = T52*T53
      T55 = T54*T17
      T56 = 0.2747773264188438D-2*T55
      T57 = T13**2
      T58 = 1/T57
      T59 = T5*T58
      T60 = T6**2
      T61 = T60**2
      T62 = T61*T6
      T63 = 1/T62
      T67 = 1/T9
      T70 = 1/T3
      T73 = -0.99709173929518D0*T63*T53-0.7418564737168958D0*T54
     #-0.4002143174996817D0*T67*T53-0.1264669550498372D0*T70*T53
      T74 = 1/T16
      T76 = T59*T73*T74
      T77 = 0.1D1*T76
      T78 = T20*RHO
      T80 = 1/T21/T78
      T81 = SIGMA*T80
      T84 = T34*SIGMA
      T85 = T56+T77
      T89 = 0.4381079514373337D1*T84*T23*T85*T26
      T91 = 0.3178251739991049D0*T29*T80
      T92 = T89-T91
      T93 = T92*T44
      T96 = T43**2
      T97 = 1/T96
      T98 = T32*T97
      T100 = 1/T33/T27
      T101 = T100*T35
      T103 = T40*T85*T26
      T108 = 1/T38/T37/RHO
      T111 = T89-T91+0.119350059339396D1*T101*T103
     #-0.8658243533790967D-1*T36*T108
      T112 = T98*T111
      T115 = -0.3178251739991049D0*T81*T45+0.1362107888567592D0*T24
     #*T93-0.1362107888567592D0*T24*T112
      T116 = 1/T48
      T117 = T115*T116
      VRHOA(I) = -T19+T50+RHO*(T56+T77+0.310906908696549D-1*T117)
      T121 = T23*T32
      T124 = SIGMA*T40
      T125 = T28*T44
      T132 = 0.1362107888567592D0*T28*T23+0.3710675800196129D-1*T84*T40
      T133 = T98*T132
      T136 = 0.1362107888567592D0*T121*T44+0.1855337900098064D-1*T124
     #*T125-0.1362107888567592D0*T24*T133
      VSIGMAAA(I) = 0.1243627634786196D0*RHO*T136*T116
      T151 = LOG(1.D0+0.2960874997779344D2/(0.8157414703487641D1*T6
     #+0.2247591863577616D1*T3+0.4300972471276643D0*T9
     #+0.1911512595127338D0*T11))
      T153 = (1.D0+0.6901399211255825D-1*T3)*T151*T53
      T155 = T49*T53
      T158 = 1/T21/T37
      T160 = SIGMA*T158*T45
      T165 = -0.1086299437397317D1*T153+0.1333333724890842D1*T18*T53
      T169 = 0.1362107888567592D0*T84*T23*T165*T26
      T170 = T29*T158
      T171 = 0.6053812838078188D-1*T170
      T183 = T36/T38/T37/T20
      T197 = -T165
      T201 = 0.1362107888567592D0*T84*T23*T197*T26
      T202 = 0.6053812838078188D-1*T170
      T223 = 1/T37
      T226 = 1/T78
      T231 = 1/T11/T2*T223
      T233 = T52*T226
      T250 = 0.1D1*T59*(-0.8309097827459833D0/T62/T2*T223
     #+0.199418347859036D1*T63*T226-0.4945709824779306D0*T231
     #+0.1483712947433792D1*T233-0.2001071587498409D0/T9/T2*T223
     #+0.8004286349993634D0*T67*T226-0.4215565168327908D-1/T3/T2*T223
     #+0.2529339100996745D0*T70*T226)*T74
      T251 = T57**2
      T254 = T73**2
      T255 = T16**2
      T259 = 0.1608197949869254D2*T5/T251*T254/T255
      T261 = 0.1831848842792292D-2*T231*T17
      T265 = 0.8837926660346786D-1*T54*T58*T73*T74
      T271 = 0.2D1*T5/T57/T13*T254*T74
      T273 = 0.5495546528376876D-2*T233*T17
      T274 = T115**2
      T275 = T48**2
      T276 = 1/T275
      T282 = T92*T97
      T287 = 1/T96/T43
      T288 = T32*T287
      T289 = T111**2
      T293 = T250+T259+T261-T265-T271-T273
      T297 = 0.4381079514373337D1*T84*T23*T293*T26
      T298 = T85**2
      T299 = T23*T298
      T302 = 0.1409129032462046D3*T84*T299*T26
      T311 = T33**2
      T314 = T40*T298
      T315 = T26**2
      T325 = 0.2044503773374224D2*T84*T80*T85*T26
      T326 = T100*SIGMA
      T329 = 0.2818258064924092D3*T326*T299*T315
      T330 = 0.1059417246663683D1*T170
      S1 = 0.1099109305675375D-1*T55+0.4D1*T76+RHO*(0.337738D-1*T153
     #-0.207271272464366D-1*T155+0.310906908696549D-1*
     #(0.6053812838078188D-1*T160+0.1362107888567592D0*T24*(-T169+T171
     #)*T44-0.1362107888567592D0*T24*T98*(-T169+T171
     #-0.3710675800196129D-1*T101*T40*T165*T26+0.1649189244531613D-1
     #*T183))*T116)
      S2 = S1+RHO*(-0.337738D-1*T153+0.207271272464366D-1*T155
     #+0.310906908696549D-1*(-0.6053812838078188D-1*T160
     #+0.1362107888567592D0*T24*(-T201-T202)*T44-0.1362107888567592D0
     #*T24*T98*(-T201-T202-0.3710675800196129D-1*T101*T40*T197*T26
     #-0.1649189244531613D-1*T183))*T116)
      V2RHOA2(I) = S2+2.D0*RHO*(T250+T259+T261-T265-T271-T273
     #-0.310906908696549D-1*T274*T276+0.310906908696549D-1*
     #(0.1059417246663683D1*T160-0.6356503479982097D0*T81*T93
     #-0.2724215777135184D0*T24*T282*T111+0.2724215777135184D0*T24
     #*T288*T289-0.1362107888567592D0*T24*T98*(T297-T302
     #-0.1113933887167696D2*T101*T108*T85*T26+0.119350059339396D1*T101
     #*T40*T293*T26+0.1151631462675703D3/T311*T35*T314*T315
     #-0.3838771542252344D2*T101*T314*T26-T325+T329+T330
     #+0.4906338002481548D0*T183)+0.6356503479982097D0*T81*T112
     #+0.1362107888567592D0*T24*(T329-T325+T297-T302+T330)*T44)*T116)
     #+0.1243627634786196D0*T117
      T365 = 0.4381079514373337D1*T34*T23*T85*T26
      T367 = 0.3178251739991049D0*T28*T80
      T378 = T28*T97
      V2RHOASIGMAAA(I) = 0.1243627634786196D0*T136*T116+4.D0*RHO*
     #(0.310906908696549D-1*(-0.3178251739991049D0*T80*T32*T44
     #-0.4329121766895483D-1*SIGMA*T108*T125+0.3178251739991049D0*T81
     #*T133+0.1362107888567592D0*T23*T92*T44+0.1362107888567592D0*T24*
     #(T365-T367)*T44-0.1362107888567592D0*T24*T282*T132
     #-0.1362107888567592D0*T121*T97*T111-0.1855337900098064D-1*T124
     #*T378*T111+0.2724215777135184D0*T24*T32*T287*T111*T132
     #-0.1362107888567592D0*T24*T98*(T365-T367+0.238700118678792D1
     #*T326*T103-0.1731648706758193D0*T84*T108))*T116
     #-0.310906908696549D-1*T115*T276*T136)
      T413 = T132**2
      T427 = T136**2
      V2SIGMAAA2(I) = 0.4974510539144783D0*RHO*(0.3710675800196129D-1
     #*T40*T28*T44-0.2724215777135184D0*T121*T97*T132
     #-0.3710675800196129D-1*T124*T378*T132+0.2724215777135184D0*T24
     #*T288*T413-0.5054340779364009D-2*SIGMA/T37/T78*T98*T34)*T116
     #-0.4974510539144783D0*RHO*T427*T276
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      V2RHOASIGMAAA(I) = 0.0D0
      V2SIGMAAA2(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C*MODULE DFTXCB  *DECK UKS_X_PBE
      SUBROUTINE UKS_X_PBE
     & (IDERIV,NPT,RHOA1,RHOB1,SIGMAAA1,SIGMABB1,
     &  ZK,VRHOA,VRHOB,VSIGMAAA,VSIGMABB,VSIGMAAB,
     &  V2RHOA2,V2RHOB2,V2RHOAB,
     &  V2RHOASIGMAAA,V2RHOASIGMAAB,V2RHOASIGMABB,
     &  V2RHOBSIGMABB,V2RHOBSIGMAAB,V2RHOBSIGMAAA,
     &  V2SIGMAAA2,V2SIGMAAAAB,V2SIGMAAABB,
     &  V2SIGMAAB2,V2SIGMAABBB,V2SIGMABB2)
C
C     J.P. PERDEW, K. BURKE, AND M. ERNZERHOF
C     GENERALIZED GRADIENT APPROXIMATION MADE SIMPLE
C     PHYS. REV. LETT. 77 (1996) 3865-3868
C
      IMPLICIT DOUBLE PRECISION(A-H,O-Z)
      INTEGER IDERIV,NPT
      DOUBLE PRECISION RHOA1(NPT),RHOB1(NPT)
      DOUBLE PRECISION SIGMAAA1(NPT),SIGMABB1(NPT)
      DOUBLE PRECISION ZK(NPT),VRHOA(NPT),VRHOB(NPT)
      DOUBLE PRECISION VSIGMAAA(NPT),VSIGMABB(NPT),VSIGMAAB(NPT)
      DOUBLE PRECISION V2RHOA2(NPT),V2RHOB2(NPT),V2RHOAB(NPT)
      DOUBLE PRECISION V2RHOASIGMAAA(NPT),V2RHOASIGMAAB(NPT)
      DOUBLE PRECISION V2RHOASIGMABB(NPT),V2RHOBSIGMABB(NPT)
      DOUBLE PRECISION V2RHOBSIGMAAB(NPT),V2RHOBSIGMAAA(NPT)
      DOUBLE PRECISION V2SIGMAAA2(NPT),V2SIGMAAAAB(NPT),V2SIGMAAABB(NPT)
      DOUBLE PRECISION V2SIGMAAB2(NPT),V2SIGMAABBB(NPT),V2SIGMABB2(NPT)
      PARAMETER(TOL=1.0D-20)
C
      IF (IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      T2 = RHOB**(1.D0/3.D0)
      T4 = RHOB**2
      T5 = T2**2
      ZK(I) = -0.9305257363491D0*T2*RHOB*(0.1804D1-0.804D0/(1.D0
     #+0.449276922095889D-2*SIGMABB/T5/T4))
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      T2 = RHOA**(1.D0/3.D0)
      T4 = RHOA**2
      T5 = T2**2
      ZK(I) = -0.9305257363491D0*T2*RHOA*(0.1804D1-0.804D0/(1.D0
     #+0.449276922095889D-2*SIGMAAA/T5/T4))
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      T4 = RHOA**(1.D0/3.D0)
      T6 = RHOA**2
      T7 = T4**2
      T18 = RHOB**(1.D0/3.D0)
      T20 = RHOB**2
      T21 = T18**2
      ZK(I) = -0.9305257363491D0*T4*RHOA*(0.1804D1-0.804D0/(1.D0
     #+0.449276922095889D-2*SIGMAAA/T7/T6))-0.9305257363491D0*T18*RHOB
     #*(0.1804D1-0.804D0/(1.D0+0.449276922095889D-2*SIGMABB/T21/T20))
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      T2 = RHOB**(1.D0/3.D0)
      T3 = T2*RHOB
      T4 = RHOB**2
      T5 = T2**2
      T10 = 1.D0+0.449276922095889D-2*SIGMABB/T5/T4
      T13 = 0.1804D1-0.804D0/T10
      ZK(I) = -0.9305257363491D0*T3*T13
      VRHOA(I) = 0.D0
      T20 = T10**2
      T21 = 1/T20
      VRHOB(I) = -0.12407009817988D1*T2*T13+0.8963286558970112D-2/T2
     #/T4*T21*SIGMABB
      VSIGMAAA(I) = 0.D0
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = -0.3361232459613792D-2/T3*T21
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      T2 = RHOA**(1.D0/3.D0)
      T3 = T2*RHOA
      T4 = RHOA**2
      T5 = T2**2
      T10 = 1.D0+0.449276922095889D-2*SIGMAAA/T5/T4
      T13 = 0.1804D1-0.804D0/T10
      ZK(I) = -0.9305257363491D0*T3*T13
      T20 = T10**2
      T21 = 1/T20
      VRHOA(I) = -0.12407009817988D1*T2*T13+0.8963286558970112D-2/T2
     #/T4*T21*SIGMAAA
      VRHOB(I) = 0.D0
      VSIGMAAA(I) = -0.3361232459613792D-2/T3*T21
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = 0.D0
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      T4 = RHOA**(1.D0/3.D0)
      T5 = T4*RHOA
      T6 = RHOA**2
      T7 = T4**2
      T12 = 1.D0+0.449276922095889D-2*SIGMAAA/T7/T6
      T15 = 0.1804D1-0.804D0/T12
      T18 = RHOB**(1.D0/3.D0)
      T19 = T18*RHOB
      T20 = RHOB**2
      T21 = T18**2
      T26 = 1.D0+0.449276922095889D-2*SIGMABB/T21/T20
      T29 = 0.1804D1-0.804D0/T26
      ZK(I) = -0.9305257363491D0*T5*T15-0.9305257363491D0*T19*T29
      T36 = T12**2
      T37 = 1/T36
      VRHOA(I) = -0.12407009817988D1*T4*T15+0.8963286558970112D-2/T4
     #/T6*T37*SIGMAAA
      T45 = T26**2
      T46 = 1/T45
      VRHOB(I) = -0.12407009817988D1*T18*T29+0.8963286558970112D-2/T18
     #/T20*T46*SIGMABB
      VSIGMAAA(I) = -0.3361232459613792D-2/T5*T37
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = -0.3361232459613792D-2/T19*T46
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      VSIGMAAB(I) = 0.0D0
      VSIGMABB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      T2 = RHOB**(1.D0/3.D0)
      T3 = T2*RHOB
      T4 = RHOB**2
      T5 = T2**2
      T10 = 1.D0+0.449276922095889D-2*SIGMABB/T5/T4
      T13 = 0.1804D1-0.804D0/T10
      ZK(I) = -0.9305257363491D0*T3*T13
      VRHOA(I) = 0.D0
      T20 = T10**2
      T21 = 1/T20
      VRHOB(I) = -0.12407009817988D1*T2*T13+0.8963286558970112D-2/T2
     #/T4*T21*SIGMABB
      VSIGMAAA(I) = 0.D0
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = -0.3361232459613792D-2/T3*T21
      V2RHOA2(I) = 0.D0
      V2RHOAB(I) = 0.D0
      T37 = T4**2
      T41 = 1/T20/T10
      T43 = SIGMABB**2
      V2RHOB2(I) = -0.4135669939329333D0/T5*T13-0.8963286558970112D-2
     #/T2/T4/RHOB*T21*SIGMABB+0.2147732158441357D-3/T37/T4*T41*T43
      V2SIGMAAA2(I) = 0.D0
      V2SIGMAAAAB(I) = 0.D0
      V2SIGMAAABB(I) = 0.D0
      V2SIGMAAB2(I) = 0.D0
      V2SIGMAABBB(I) = 0.D0
      V2SIGMABB2(I) = 0.3020248347808158D-4/T37*T41
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      T2 = RHOA**(1.D0/3.D0)
      T3 = T2*RHOA
      T4 = RHOA**2
      T5 = T2**2
      T10 = 1.D0+0.449276922095889D-2*SIGMAAA/T5/T4
      T13 = 0.1804D1-0.804D0/T10
      ZK(I) = -0.9305257363491D0*T3*T13
      T20 = T10**2
      T21 = 1/T20
      VRHOA(I) = -0.12407009817988D1*T2*T13+0.8963286558970112D-2/T2
     #/T4*T21*SIGMAAA
      VRHOB(I) = 0.D0
      VSIGMAAA(I) = -0.3361232459613792D-2/T3*T21
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = 0.D0
      T37 = T4**2
      T41 = 1/T20/T10
      T43 = SIGMAAA**2
      V2RHOA2(I) = -0.4135669939329333D0/T5*T13-0.8963286558970112D-2
     #/T2/T4/RHOA*T21*SIGMAAA+0.2147732158441357D-3/T37/T4*T41*T43
      V2RHOB2(I) = 0.D0
      V2RHOAB(I) = 0.D0
      V2SIGMAAA2(I) = 0.3020248347808158D-4/T37*T41
      V2SIGMAAAAB(I) = 0.D0
      V2SIGMAAABB(I) = 0.D0
      V2SIGMAAB2(I) = 0.D0
      V2SIGMAABBB(I) = 0.D0
      V2SIGMABB2(I) = 0.D0
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      T4 = RHOA**(1.D0/3.D0)
      T5 = T4*RHOA
      T6 = RHOA**2
      T7 = T4**2
      T12 = 1.D0+0.449276922095889D-2*SIGMAAA/T7/T6
      T15 = 0.1804D1-0.804D0/T12
      T18 = RHOB**(1.D0/3.D0)
      T19 = T18*RHOB
      T20 = RHOB**2
      T21 = T18**2
      T26 = 1.D0+0.449276922095889D-2*SIGMABB/T21/T20
      T29 = 0.1804D1-0.804D0/T26
      ZK(I) = -0.9305257363491D0*T5*T15-0.9305257363491D0*T19*T29
      T36 = T12**2
      T37 = 1/T36
      T38 = 1/T4/T6*T37
      VRHOA(I) = -0.12407009817988D1*T4*T15+0.8963286558970112D-2*T38
     #*SIGMAAA
      T45 = T26**2
      T46 = 1/T45
      T47 = 1/T18/T20*T46
      VRHOB(I) = -0.12407009817988D1*T18*T29+0.8963286558970112D-2*T47
     #*SIGMABB
      VSIGMAAA(I) = -0.3361232459613792D-2/T5*T37
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = -0.3361232459613792D-2/T19*T46
      T65 = T6**2
      T69 = 1/T36/T12
      T71 = SIGMAAA**2
      V2RHOA2(I) = -0.4135669939329333D0/T7*T15-0.8963286558970112D-2
     #/T4/T6/RHOA*T37*SIGMAAA+0.2147732158441357D-3/T65/T6*T69*T71
      T83 = T20**2
      T87 = 1/T45/T26
      T89 = SIGMABB**2
      V2RHOB2(I) = -0.4135669939329333D0/T21*T29-0.8963286558970112D-2
     #/T18/T20/RHOB*T46*SIGMABB+0.2147732158441357D-3/T83/T20*T87*T89
      V2RHOAB(I) = 0.D0
      V2RHOASIGMAAA(I) = 0.4481643279485056D-2*T38
     #-0.8053995594155087D-4/T65/RHOA*T69*SIGMAAA
      V2RHOASIGMAAB(I) = 0.D0
      V2RHOASIGMABB(I) = 0.D0
      V2RHOBSIGMAAA(I) = 0.D0
      V2RHOBSIGMAAB(I) = 0.D0
      V2RHOBSIGMABB(I) = 0.4481643279485056D-2*T47
     #-0.8053995594155087D-4/T83/RHOB*T87*SIGMABB
      V2SIGMAAA2(I) = 0.3020248347808158D-4/T65*T69
      V2SIGMAAAAB(I) = 0.D0
      V2SIGMAAABB(I) = 0.D0
      V2SIGMAAB2(I) = 0.D0
      V2SIGMAABBB(I) = 0.D0
      V2SIGMABB2(I) = 0.3020248347808158D-4/T83*T87
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      V2RHOB2(I) = 0.0D0
      V2RHOAB(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      VSIGMAAB(I) = 0.0D0
      VSIGMABB(I) = 0.0D0
      V2RHOASIGMAAA(I) = 0.0D0
      V2RHOASIGMAAB(I) = 0.0D0
      V2RHOASIGMABB(I) = 0.0D0
      V2RHOBSIGMAAA(I) = 0.0D0
      V2RHOBSIGMAAB(I) = 0.0D0
      V2RHOBSIGMABB(I) = 0.0D0
      V2SIGMAAA2(I) = 0.0D0
      V2SIGMAAB2(I) = 0.0D0
      V2SIGMABB2(I) = 0.0D0
      V2SIGMAAAAB(I) = 0.0D0
      V2SIGMAAABB(I) = 0.0D0
      V2SIGMAABBB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C---C*MODULE DFTXCB  *DECK RKS_X_PBE
C---      SUBROUTINE RKS_X_PBE
C---     & (IDERIV,NPT,RHOA1,SIGMAAA1,
C---     &  ZK,VRHOA,VSIGMAAA,
C---     &  V2RHOA2,V2RHOASIGMAAA,V2SIGMAAA2)
C---C
C---C     J.P. PERDEW, K. BURKE, AND M. ERNZERHOF
C---C     GENERALIZED GRADIENT APPROXIMATION MADE SIMPLE
C---C     PHYS. REV. LETT. 77 (1996) 3865-3868
C---C
C---      IMPLICIT DOUBLE PRECISION(A-H,O-Z)
C---      INTEGER IDERIV,NPT
C---      DOUBLE PRECISION RHOA1(NPT)
C---      DOUBLE PRECISION SIGMAAA1(NPT)
C---      DOUBLE PRECISION ZK(NPT),VRHOA(NPT),VSIGMAAA(NPT)
C---      DOUBLE PRECISION V2RHOA2(NPT),V2RHOASIGMAAA(NPT),
C---      DOUBLE PRECISION V2SIGMAAA2(NPT)
C---      PARAMETER(TOL=1.0D-20)
C---C
C---      IF(IDERIV.EQ.0) THEN
C---C
C---      DO I=1,NPT
C---      RHO = MAX(0.D0,RHOA1(I))
C---      IF(RHO.GT.TOL) THEN
C---      SIGMA = MAX(0.D0,SIGMAAA1(I))
C---      T2 = RHO**(1.D0/3.D0)
C---      T4 = RHO**2
C---      T5 = T2**2
C---      ZK(I) = -0.7385587663820224D0*T2*RHO
C---     #  *(0.1804D1-0.804D0/(1.D0+0.7131826587600489D-2*SIGMA/T5/T4))
C---      ELSE ! RHO
C---      ZK(I) = 0.0D0
C---      ENDIF ! RHO
C---      ENDDO
C---C
C---      ELSE IF(IDERIV.EQ.1) THEN
C---C
C---      DO I=1,NPT
C---      RHO = MAX(0.D0,RHOA1(I))
C---      IF(RHO.GT.TOL) THEN
C---      SIGMA = MAX(0.D0,SIGMAAA1(I))
C---      T2 = RHO**(1.D0/3.D0)
C---      T3 = T2*RHO
C---      T4 = RHO**2
C---      T5 = T2**2
C---      T10 = 1.D0+0.7131826587600489D-2*SIGMA/T5/T4
C---      T13 = 0.1804D1-0.804D0/T10
C---      ZK(I) = -0.7385587663820224D0*T3*T13
C---      T20 = T10**2
C---      T21 = 1/T20
C---      VRHOA(I) = -0.9847450218426965D0*T2*T13
C---     #     +0.1129303341188623D-1/T2/T4*T21*SIGMA
C---      VSIGMAAA(I) = -0.1693955011782934D-1/T3*T21
C---      ELSE ! RHO
C---      ZK(I) = 0.0D0
C---      VRHOA(I) = 0.0D0
C---      VSIGMAAA(I) = 0.0D0
C---      ENDIF ! RHO
C---      ENDDO
C---C
C---      ELSE IF(IDERIV.EQ.2) THEN
C---C
C---      DO I=1,NPT
C---      RHO = MAX(0.D0,RHOA1(I))
C---      IF(RHO.GT.TOL) THEN
C---      SIGMA = MAX(0.D0,SIGMAAA1(I))
C---      T2 = RHO**(1.D0/3.D0)
C---      T3 = T2*RHO
C---      T4 = RHO**2
C---      T5 = T2**2
C---      T10 = 1.D0+0.7131826587600489D-2*SIGMA/T5/T4
C---      T13 = 0.1804D1-0.804D0/T10
C---      ZK(I) = -0.7385587663820224D0*T3*T13
C---      T20 = T10**2
C---      T21 = 1/T20
C---      T22 = 1/T2/T4*T21
C---      VRHOA(I) = -0.9847450218426965D0*T2*T13
C---     #   +0.1129303341188623D-01*T22*SIGMA
C---      VSIGMAAA(I) = -0.1693955011782934D-1/T3*T21
C---      T37 = T4**2
C---      T41 = 1/T20/T10
C---      T43 = SIGMA**2
C---      V2RHOA2(I) = -0.6564966812284644D+00/T5*T13
C---     #     -0.2258606682377246D-01/T2/T4/RHO*T21*SIGMA
C---     #     +0.8590928633765426D-03/T37/T4*T41*T43
C---      V2RHOASIGMAAA(I) = 0.2258606682377246D-1*T22
C---     #-0.644319647532407D-3/T37/RHO*T41*SIGMA
C---      V2SIGMAAA2(I) = 0.9664794712986105D-3/T37*T41
C---      ELSE ! RHO
C---      ZK(I) = 0.0D0
C---      VRHOA(I) = 0.0D0
C---      V2RHOA2(I) = 0.0D0
C---      VSIGMAAA(I) = 0.0D0
C---      V2RHOASIGMAAA(I) = 0.0D0
C---      V2SIGMAAA2(I) = 0.0D0
C---      ENDIF ! RHO
C---      ENDDO
C---C
C---      ENDIF ! IDERIV
C---      RETURN
C---      END
C*MODULE DFTXCB  *DECK UKS_C_VWN1RPA
      SUBROUTINE UKS_C_VWN1RPA(IDERIV,NPT,RHOA1,RHOB1,ZK,
     *                         VRHOA,VRHOB,V2RHOA2,V2RHOB2,V2RHOAB)
      IMPLICIT DOUBLE PRECISION(A-H,O-Z)
      INTEGER IDERIV,NPT
      DIMENSION RHOA1(NPT),RHOB1(NPT),
     *          ZK(NPT),VRHOA(NPT),VRHOB(NPT),
     *          V2RHOA2(NPT),V2RHOB2(NPT),V2RHOAB(NPT)
      PARAMETER(TOL=1.0D-20)
C
      IF (IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T4 = T1**(1.D0/6.D0)
      T7 = 1/(T3+0.1029581201158544D2*T4+0.427198D2)
      T10 = LOG(0.6203504908994D0*T2*T7)
      T12 = 0.1575246635799487D1*T4
      T16 = ATAN(0.448998886412873D-1/(T12+0.13072D2))
      T18 = 0.7876233178997433D0*T4
      T20 = (T18+0.409286D0)**2
      T22 = LOG(T20*T7)
      T26 = 1/(T3+0.1584942278842832D2*T4+0.101578D3)
      T29 = LOG(0.6203504908994D0*T2*T26)
      T34 = ATAN(0.1171685277708993D1/(T12+0.201231D2))
      T37 = (T18+0.743294D0)**2
      T39 = LOG(T37*T26)
      T47 = (RHOA-1.D0*RHOB)*T1
      T48 = 1.D0+T47
      T49 = T48**(1.D0/3.D0)
      T52 = 1.D0-1.D0*T47
      T53 = T52**(1.D0/3.D0)
      ZK(I) = RHO*(0.310907D-1*T10+0.205219729378375D2*T16+0.44313737677
     #49538D-2*T22+0.1923661050931536D1*(0.1554535D-1*T29+0.618818029790
     #6063D0*T34+0.2667310007273315D-2*T39-0.310907D-1*T10-0.20521972937
     #8375D2*T16-0.4431373767749538D-2*T22)*(T49*T48+T53*T52-2.D0))
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T4 = T1**(1.D0/6.D0)
      T6 = T3+0.1029581201158544D2*T4+0.427198D2
      T7 = 1/T6
      T10 = LOG(0.6203504908994D0*T2*T7)
      T11 = 0.310907D-1*T10
      T12 = 0.1575246635799487D1*T4
      T13 = T12+0.13072D2
      T16 = ATAN(0.448998886412873D-1/T13)
      T17 = 0.205219729378375D2*T16
      T18 = 0.7876233178997433D0*T4
      T19 = T18+0.409286D0
      T20 = T19**2
      T22 = LOG(T20*T7)
      T23 = 0.4431373767749538D-2*T22
      T25 = T3+0.1584942278842832D2*T4+0.101578D3
      T26 = 1/T25
      T29 = LOG(0.6203504908994D0*T2*T26)
      T31 = T12+0.201231D2
      T34 = ATAN(0.1171685277708993D1/T31)
      T36 = T18+0.743294D0
      T37 = T36**2
      T39 = LOG(T37*T26)
      T44 = 0.1554535D-1*T29+0.6188180297906063D0*T34+0.2667310007273315
     #D-2*T39-0.310907D-1*T10-0.205219729378375D2*T16-0.4431373767749538
     #D-2*T22
      T46 = RHOA-1.D0*RHOB
      T47 = T46*T1
      T48 = 1.D0+T47
      T49 = T48**(1.D0/3.D0)
      T52 = 1.D0-1.D0*T47
      T53 = T52**(1.D0/3.D0)
      T55 = T49*T48+T53*T52-2.D0
      T57 = 0.1923661050931536D1*T44*T55
      ZK(I) = RHO*(T11+T17+T23+T57)
      T59 = RHO*T44
      T64 = 0.1333333333333333D1*T49*T1-0.1333333333333333D1*T53*T1
      T67 = T2**2
      T68 = 1/T67
      T70 = RHO**2
      T71 = 1/T70
      T74 = T6**2
      T75 = 1/T74
      T78 = 0.2067834969664667D0*T68*T71
      T79 = T4**2
      T80 = T79**2
      T82 = 1/T80/T4
      T83 = T82*T71
      T85 = -T78-0.1715968668597574D1*T83
      T89 = 1/T2
      T91 = (-0.2067834969664667D0*T68*T7*T71-0.6203504908994D0*T2*T75*T
     #85)*T89*T6
      T93 = T13**2
      T94 = 1/T93
      T100 = T94*T82*T71/(1.D0+0.2016D-2*T94)
      T111 = (-0.2625411059665811D0*T19*T7*T83-1.D0*T20*T75*T85)/T20*T6
      T116 = T25**2
      T117 = 1/T116
      T120 = -T78-0.2641570464738054D1*T83
      T127 = T31**2
      T128 = 1/T127
      T163 = RHO*(0.5011795824473985D-1*T91+0.2419143800947354D0*T100+0.
     #4431373767749538D-2*T111+0.1923661050931536D1*(0.2505897912236993D
     #-1*(-0.2067834969664667D0*T68*T26*T71-0.6203504908994D0*T2*T117*T1
     #20)*T89*T25+0.1903580477513215D0*T128*T82*T71/(1.D0+0.137284639D1*
     #T128)+0.2667310007273315D-2*(-0.2625411059665811D0*T36*T26*T83-1.D
     #0*T37*T117*T120)/T37*T25-0.5011795824473985D-1*T91-0.2419143800947
     #354D0*T100-0.4431373767749538D-2*T111)*T55+0.1923661050931536D1*T4
     #4*(-0.1333333333333333D1*T49*T46*T71+0.1333333333333333D1*T53*T46*
     #T71))
      VRHOA(I) = 0.1923661050931536D1*T59*T64+T11+T17+T23+T57+T163
      VRHOB(I) = -0.1923661050931536D1*T59*T64+T11+T17+T23+T57+T163
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T4 = T1**(1.D0/6.D0)
      T6 = T3+0.1029581201158544D2*T4+0.427198D2
      T7 = 1/T6
      T10 = LOG(0.6203504908994D0*T2*T7)
      T11 = 0.310907D-1*T10
      T12 = 0.1575246635799487D1*T4
      T13 = T12+0.13072D2
      T16 = ATAN(0.448998886412873D-1/T13)
      T17 = 0.205219729378375D2*T16
      T18 = 0.7876233178997433D0*T4
      T19 = T18+0.409286D0
      T20 = T19**2
      T22 = LOG(T20*T7)
      T23 = 0.4431373767749538D-2*T22
      T25 = T3+0.1584942278842832D2*T4+0.101578D3
      T26 = 1/T25
      T29 = LOG(0.6203504908994D0*T2*T26)
      T31 = T12+0.201231D2
      T34 = ATAN(0.1171685277708993D1/T31)
      T36 = T18+0.743294D0
      T37 = T36**2
      T39 = LOG(T37*T26)
      T44 = 0.1554535D-1*T29+0.6188180297906063D0*T34+0.2667310007273315
     #D-2*T39-0.310907D-1*T10-0.205219729378375D2*T16-0.4431373767749538
     #D-2*T22
      T46 = RHOA-1.D0*RHOB
      T47 = T46*T1
      T48 = 1.D0+T47
      T49 = T48**(1.D0/3.D0)
      T52 = 1.D0-1.D0*T47
      T53 = T52**(1.D0/3.D0)
      T55 = T49*T48+T53*T52-2.D0
      T57 = 0.1923661050931536D1*T44*T55
      ZK(I) = RHO*(T11+T17+T23+T57)
      T59 = RHO*T44
      T64 = 0.1333333333333333D1*T49*T1-0.1333333333333333D1*T53*T1
      T67 = T2**2
      T68 = 1/T67
      T69 = T68*T7
      T70 = RHO**2
      T71 = 1/T70
      T74 = T6**2
      T75 = 1/T74
      T76 = T2*T75
      T78 = 0.2067834969664667D0*T68*T71
      T79 = T4**2
      T80 = T79**2
      T81 = T80*T4
      T82 = 1/T81
      T83 = T82*T71
      T85 = -T78-0.1715968668597574D1*T83
      T88 = -0.2067834969664667D0*T69*T71-0.6203504908994D0*T76*T85
      T89 = 1/T2
      T90 = T88*T89
      T91 = T90*T6
      T93 = T13**2
      T94 = 1/T93
      T95 = T94*T82
      T97 = 1.D0+0.2016D-2*T94
      T98 = 1/T97
      T100 = T95*T71*T98
      T102 = T19*T7
      T105 = T20*T75
      T108 = -0.2625411059665811D0*T102*T83-1.D0*T105*T85
      T109 = 1/T20
      T110 = T108*T109
      T111 = T110*T6
      T113 = T68*T26
      T116 = T25**2
      T117 = 1/T116
      T118 = T2*T117
      T120 = -T78-0.2641570464738054D1*T83
      T123 = -0.2067834969664667D0*T113*T71-0.6203504908994D0*T118*T120
      T124 = T123*T89
      T127 = T31**2
      T128 = 1/T127
      T129 = T128*T82
      T131 = 1.D0+0.137284639D1*T128
      T132 = 1/T131
      T136 = T36*T26
      T139 = T37*T117
      T142 = -0.2625411059665811D0*T136*T83-1.D0*T139*T120
      T143 = 1/T37
      T144 = T142*T143
      T150 = 0.2505897912236993D-1*T124*T25+0.1903580477513215D0*T129*T7
     #1*T132+0.2667310007273315D-2*T144*T25-0.5011795824473985D-1*T91-0.
     #2419143800947354D0*T100-0.4431373767749538D-2*T111
      T151 = T150*T55
      T153 = T49*T46
      T156 = T53*T46
      T159 = -0.1333333333333333D1*T153*T71+0.1333333333333333D1*T156*T7
     #1
      T160 = T44*T159
      T163 = RHO*(0.5011795824473985D-1*T91+0.2419143800947354D0*T100+0.
     #4431373767749538D-2*T111+0.1923661050931536D1*T151+0.1923661050931
     #536D1*T160)
      VRHOA(I) = 0.1923661050931536D1*T59*T64+T11+T17+T23+T57+T163
      T164 = -T64
      VRHOB(I) = 0.1923661050931536D1*T59*T164+T11+T17+T23+T57+T163
      T167 = T49**2
      T168 = 1/T167
      T171 = T53**2
      T172 = 1/T171
      T175 = 0.4444444444444444D0*T168*T71+0.4444444444444444D0*T172*T71
      T177 = 0.1923661050931536D1*T59*T175
      T178 = T44*T64
      T184 = 1/T70/RHO
      T194 = -0.4444444444444444D0*T168*T46*T184-0.1333333333333333D1*T4
     #9*T71-0.4444444444444444D0*T172*T46*T184+0.1333333333333333D1*T53*
     #T71
      T198 = RHO*(0.1923661050931536D1*T150*T64+0.1923661050931536D1*T44
     #*T194)
      T199 = RHO*T150
      T200 = T199*T64
      T202 = T59*T194
      T204 = 0.1002359164894797D0*T91
      T205 = 0.4838287601894708D0*T100
      T206 = 0.8862747535499077D-2*T111
      T207 = 0.3847322101863073D1*T151
      T208 = 0.3847322101863073D1*T160
      T210 = 1/T67/T1
      T212 = T70**2
      T213 = 1/T212
      T214 = T210*T7*T213
      T223 = 1/T74/T6
      T225 = T85**2
      T229 = 0.1378556646443111D0*T210*T213
      T231 = 0.4135669939329333D0*T68*T184
      T233 = 1/T81/T1
      T234 = T233*T213
      T236 = T82*T184
      T238 = -T229+T231-0.1429973890497978D1*T234+0.3431937337195148D1*T
     #236
      T243 = (-0.1378556646443111D0*T214+0.4135669939329333D0*T68*T75*T7
     #1*T85+0.4135669939329333D0*T69*T184+0.12407009817988D1*T2*T223*T22
     #5-0.6203504908994D0*T76*T238)*T89*T6
      T246 = 1/T2/T1
      T249 = T88*T246*T6*T71
      T251 = T90*T85
      T256 = T213*T98
      T257 = 1/T93/T13*T210*T256
      T260 = T94*T233*T256
      T263 = T95*T184*T98
      T265 = T93**2
      T269 = T97**2
      T272 = 1/T265/T13*T210*T213/T269
      T290 = (0.3446391616107778D-1*T214+0.5250822119331622D0*T19*T75*T8
     #3*T85-0.2187842549721509D0*T102*T234+0.5250822119331622D0*T102*T23
     #6+2.D0*T20*T223*T225-1.D0*T105*T238)*T109*T6
      T297 = T108/T20/T19*T6*T82*T71
      T299 = T110*T85
      T302 = T210*T26*T213
      T311 = 1/T116/T25
      T313 = T120**2
      T318 = -T229+T231-0.2201308720615045D1*T234+0.5283140929476108D1*T
     #236
      T334 = T213*T132
      T343 = T127**2
      T347 = T131**2
      S1 = 0.2505897912236993D-1*(-0.1378556646443111D0*T302+0.413566993
     #9329333D0*T68*T117*T71*T120+0.4135669939329333D0*T113*T184+0.12407
     #009817988D1*T2*T311*T313-0.6203504908994D0*T118*T318)*T89*T25+0.83
     #52993040789975D-2*T123*T246*T25*T71+0.2505897912236993D-1*T124*T12
     #0+0.9995362477254242D-1/T127/T31*T210*T334+0.1586317064594346D0*T1
     #28*T233*T334-0.3807160955026431D0*T129*T184*T132-0.137220972936399
     #4D0/T343/T31*T210*T213/T347+0.2667310007273315D-2*(0.3446391616107
     #778D-1*T302+0.5250822119331622D0*T36*T117*T83*T120-0.2187842549721
     #509D0*T136*T234+0.5250822119331622D0*T136*T236+2.D0*T37*T311*T313-
     #1.D0*T139*T318)*T143*T25+0.7002785192652656D-3*T142/T37/T36*T25*T8
     #2*T71+0.2667310007273315D-2*T144*T120
      T389 = S1-0.5011795824473985D-1*T243-0.1670598608157995D-1*T249-0.
     #5011795824473985D-1*T251-0.1270249377985834D0*T257-0.2015953167456
     #128D0*T260+0.4838287601894708D0*T263+0.2560822746019441D-3*T272-0.
     #4431373767749538D-2*T290-0.1163417769936259D-2*T297-0.443137376774
     #9538D-2*T299
      T394 = T46**2
      T408 = 0.5011795824473985D-1*T243+0.1670598608157995D-1*T249+0.501
     #1795824473985D-1*T251+0.1270249377985834D0*T257+0.2015953167456128
     #D0*T260-0.4838287601894708D0*T263-0.2560822746019441D-3*T272+0.443
     #1373767749538D-2*T290+0.1163417769936259D-2*T297+0.443137376774953
     #8D-2*T299+0.1923661050931536D1*T389*T55+0.3847322101863073D1*T150*
     #T159+0.1923661050931536D1*T44*(0.4444444444444444D0*T168*T394*T213
     #+0.2666666666666667D1*T153*T184+0.4444444444444444D0*T172*T394*T21
     #3-0.2666666666666667D1*T156*T184)
      T409 = RHO*T408
      V2RHOA2(I) = T177+0.3847322101863073D1*T178+T198+0.192366105093153
     #6D1*T200+0.1923661050931536D1*T202+T204+T205+T206+T207+T208+T409
      T410 = T44*T164
      T414 = -T194
      T418 = RHO*(0.1923661050931536D1*T150*T164+0.1923661050931536D1*T4
     #4*T414)
      T419 = T199*T164
      T421 = T59*T414
      V2RHOB2(I) = T177+0.3847322101863073D1*T410+T418+0.192366105093153
     #6D1*T419+0.1923661050931536D1*T421+T204+T205+T206+T207+T208+T409
      V2RHOAB(I) = -0.1923661050931536D1*T59*T175+0.1923661050931536D1*T
     #410+0.5D0*T418+0.1923661050931536D1*T178+0.9618305254657682D0*T200
     #+0.9618305254657682D0*T202+T204+T205+T206+T207+T208+T409+0.5D0*T19
     #8+0.9618305254657682D0*T419+0.9618305254657682D0*T421
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      V2RHOB2(I) = 0.0D0
      V2RHOAB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C*MODULE DFTXCB  *DECK RKS_C_VWN1RPA
      SUBROUTINE RKS_C_VWN1RPA(IDERIV,NPT,RHOA1,ZK,VRHOA,V2RHOA2)
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      INTEGER IDERIV,NPT
      DIMENSION RHOA1(NPT),ZK(NPT),VRHOA(NPT),V2RHOA2(NPT)
      PARAMETER(TOL=1.0D-20)
C
      IF(IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T4 = T1**(1.D0/6.D0)
      T7 = 1/(0.6203504908994D0*T2+0.1029581201158544D2*T4+0.427198D2)
      T10 = LOG(0.6203504908994D0*T2*T7)
      T16 = ATAN(0.448998886412873D-1/(0.1575246635799487D1*T4+0.13072D
     #2))
      T20 = (0.7876233178997433D0*T4+0.409286D0)**2
      T22 = LOG(T20*T7)
      ZK(I) = RHO*(0.310907D-1*T10+0.205219729378375D2*T16+0.44313737677
     #49538D-2*T22)
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T4 = T1**(1.D0/6.D0)
      T6 = 0.6203504908994D0*T2+0.1029581201158544D2*T4+0.427198D2
      T7 = 1/T6
      T10 = LOG(0.6203504908994D0*T2*T7)
      T11 = 0.310907D-1*T10
      T13 = 0.1575246635799487D1*T4+0.13072D2
      T16 = ATAN(0.448998886412873D-1/T13)
      T17 = 0.205219729378375D2*T16
      T19 = 0.7876233178997433D0*T4+0.409286D0
      T20 = T19**2
      T22 = LOG(T20*T7)
      T23 = 0.4431373767749538D-2*T22
      ZK(I) = RHO*(T11+T17+T23)
      T25 = T2**2
      T26 = 1/T25
      T28 = RHO**2
      T29 = 1/T28
      T32 = T6**2
      T33 = 1/T32
      T37 = T4**2
      T38 = T37**2
      T40 = 1/T38/T4
      T41 = T40*T29
      T43 = -0.2067834969664667D0*T26*T29-0.1715968668597574D1*T41
      T51 = T13**2
      T52 = 1/T51
      VRHOA(I) = T11+T17+T23+RHO*(0.5011795824473985D-1*(-0.206783496966
     #4667D0*T26*T7*T29-0.6203504908994D0*T2*T33*T43)/T2*T6+0.2419143800
     #947354D0*T52*T40*T29/(1.D0+0.2016D-2*T52)+0.4431373767749538D-2*(-
     #0.2625411059665811D0*T19*T7*T41-1.D0*T20*T33*T43)/T20*T6)
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T4 = T1**(1.D0/6.D0)
      T6 = 0.6203504908994D0*T2+0.1029581201158544D2*T4+0.427198D2
      T7 = 1/T6
      T10 = LOG(0.6203504908994D0*T2*T7)
      T11 = 0.310907D-1*T10
      T13 = 0.1575246635799487D1*T4+0.13072D2
      T16 = ATAN(0.448998886412873D-1/T13)
      T17 = 0.205219729378375D2*T16
      T19 = 0.7876233178997433D0*T4+0.409286D0
      T20 = T19**2
      T22 = LOG(T20*T7)
      T23 = 0.4431373767749538D-2*T22
      ZK(I) = RHO*(T11+T17+T23)
      T25 = T2**2
      T26 = 1/T25
      T27 = T26*T7
      T28 = RHO**2
      T29 = 1/T28
      T32 = T6**2
      T33 = 1/T32
      T34 = T2*T33
      T37 = T4**2
      T38 = T37**2
      T39 = T38*T4
      T40 = 1/T39
      T41 = T40*T29
      T43 = -0.2067834969664667D0*T26*T29-0.1715968668597574D1*T41
      T46 = -0.2067834969664667D0*T27*T29-0.6203504908994D0*T34*T43
      T47 = 1/T2
      T48 = T46*T47
      T49 = T48*T6
      T51 = T13**2
      T52 = 1/T51
      T53 = T52*T40
      T55 = 1.D0+0.2016D-2*T52
      T56 = 1/T55
      T58 = T53*T29*T56
      T60 = T19*T7
      T63 = T20*T33
      T66 = -0.2625411059665811D0*T60*T41-1.D0*T63*T43
      T67 = 1/T20
      T68 = T66*T67
      T69 = T68*T6
      VRHOA(I) = T11+T17+T23+RHO*(0.5011795824473985D-1*T49+0.2419143800
     #947354D0*T58+0.4431373767749538D-2*T69)
      T77 = 1/T25/T1
      T79 = T28**2
      T80 = 1/T79
      T81 = T77*T7*T80
      T88 = 1/T28/RHO
      T92 = 1/T32/T6
      T94 = T43**2
      T102 = 1/T39/T1
      T103 = T102*T80
      T105 = T40*T88
      T107 = -0.1378556646443111D0*T77*T80+0.4135669939329333D0*T26*T88-
     #0.1429973890497978D1*T103+0.3431937337195148D1*T105
      T125 = T80*T56
      T134 = T51**2
      T138 = T55**2
      S1 = 0.2004718329789594D0*T49+0.9676575203789416D0*T58
      V2RHOA2(I) = S1+0.1772549507099815D-1*T69+2.D0*RHO*(0.501179582447
     #3985D-1*(-0.1378556646443111D0*T81+0.4135669939329333D0*T26*T33*T2
     #9*T43+0.4135669939329333D0*T27*T88+0.12407009817988D1*T2*T92*T94-0
     #.6203504908994D0*T34*T107)*T47*T6+0.1670598608157995D-1*T46/T2/T1*
     #T6*T29+0.5011795824473985D-1*T48*T43+0.1270249377985834D0/T51/T13*
     #T77*T125+0.2015953167456128D0*T52*T102*T125-0.4838287601894708D0*T
     #53*T88*T56-0.2560822746019441D-3/T134/T13*T77*T80/T138+0.443137376
     #7749538D-2*(0.3446391616107778D-1*T81+0.5250822119331622D0*T19*T33
     #*T41*T43-0.2187842549721509D0*T60*T103+0.5250822119331622D0*T60*T1
     #05+2.D0*T20*T92*T94-1.D0*T63*T107)*T67*T6+0.1163417769936259D-2*T6
     #6/T20/T19*T6*T40*T29+0.4431373767749538D-2*T68*T43)
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C*MODULE DFTXCB  *DECK UKS_C_PW92
      SUBROUTINE UKS_C_PW92(IDERIV,NPT,RHOA1,RHOB1,ZK,
     *                      VRHOA,VRHOB,V2RHOA2,V2RHOB2,V2RHOAB)
C
C     J.P. PERDEW, Y. WANG
C     ACCURATE AND SIMPLE ANALYTIC REPRESENTATION OF
C     THE ELECTRON-GAS CORRELATION ENERGY
C     PHYS. REV. B 45 (1992) 13244-13249
C
C     NOTE: PLEASE SEE A REMARK IN -PW91CF- REGARDING THE NUMBER
C           OF DIGITS USED IN CONSTANTS TO GENERATE THIS ROUTINE.
C
      IMPLICIT DOUBLE PRECISION(A-H,O-Z)
      INTEGER IDERIV,NPT
      DIMENSION RHOA1(NPT),RHOB1(NPT),
     *          ZK(NPT),VRHOA(NPT),VRHOB(NPT),
     *          V2RHOA2(NPT),V2RHOB2(NPT),V2RHOAB(NPT)
      PARAMETER(TOL=1.0D-20)
C
      IF (IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      T1 = 1/RHOB
      T2 = T1**(1.D0/3.D0)
      T6 = T1**(1.D0/6.D0)
      T9 = SQRT(T1)
      T11 = T2**2
      T17 = LOG(1.D0+0.321646831778707D2/(0.1112037486309468D2*T6
     #+0.3844746237447211D1*T2+0.1644733775567609D1*T9
     #+0.2405871291288192D0*T11))
      ZK(I) = -0.3109D-1*RHOB*(1.D0+0.1274696188700087D0*T2)*T17
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      T1 = 1/RHOA
      T2 = T1**(1.D0/3.D0)
      T6 = T1**(1.D0/6.D0)
      T9 = SQRT(T1)
      T11 = T2**2
      T17 = LOG(1.D0+0.321646831778707D2/(0.1112037486309468D2*T6
     #+0.3844746237447211D1*T2+0.1644733775567609D1*T9
     #+0.2405871291288192D0*T11))
      ZK(I) = -0.3109D-1*RHOA*(1.D0+0.1274696188700087D0*T2)*T17
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      T1 = RHOA+RHOB
      T2 = 1/T1
      T3 = T2**(1.D0/3.D0)
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T17 = LOG(1.D0+0.160818243221511D2/(0.598255043577108D1*T6
     #+0.2225569421150687D1*T3+0.8004286349993634D0*T9
     #+0.1897004325747559D0*T11))
      T19 = 0.62182D-1*(1.D0+0.1325688999052018D0*T3)*T17
      T30 = LOG(1.D0+0.2960857464321668D2/(0.8157414703487641D1*T6
     #+0.2247591863577616D1*T3+0.4300972471276643D0*T9
     #+0.1911512595127338D0*T11))
      T33 = RHOA-1.D0*RHOB
      T34 = T33*T2
      T35 = 1.D0+T34
      T36 = T35**(1.D0/3.D0)
      T39 = 1.D0-1.D0*T34
      T40 = T39**(1.D0/3.D0)
      T42 = T36*T35+T40*T39-2.D0
      T43 = T33**2
      T44 = T43**2
      T45 = T1**2
      T46 = T45**2
      T48 = T44/T46
      T64 = LOG(1.D0+0.321646831778707D2/(0.1112037486309468D2*T6
     #+0.3844746237447211D1*T3+0.1644733775567609D1*T9
     #+0.2405871291288192D0*T11))
      ZK(I) = T1*(-T19+0.3799574853701528D-1*(1.D0
     #+0.6901399211255825D-1*T3)*T30*T42*(1.D0-1.D0*T48)
     #+0.1923661050931536D1*(-0.3109D-1*(1.D0+0.1274696188700087D0*T3)
     #*T64+T19)*T42*T48)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      T1 = 1/RHOB
      T2 = T1**(1.D0/3.D0)
      T4 = 1.D0+0.1274696188700087D0*T2
      T5 = RHOB*T4
      T6 = T1**(1.D0/6.D0)
      T9 = SQRT(T1)
      T11 = T2**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T2
     #+0.1644733775567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.321646831778707D2/T13
      T17 = LOG(T16)
      ZK(I) = -0.3109D-1*T5*T17
      VRHOA(I) = 0.D0
      T22 = 1/T11
      T26 = T13**2
      T28 = T6**2
      T29 = T28**2
      T32 = RHOB**2
      T33 = 1/T32
      VRHOB(I) = -0.3109D-1*T4*T17+0.1321010150222857D-2*T1*T22*T17
     #+0.1D1*T5/T26*(-0.1853395810515781D1/T29/T6*T33
     #-0.128158207914907D1*T22*T33-0.8223668877838045D0/T9*T33
     #-0.1603914194192128D0/T2*T33)/T16
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      T1 = 1/RHOA
      T2 = T1**(1.D0/3.D0)
      T4 = 1.D0+0.1274696188700087D0*T2
      T5 = RHOA*T4
      T6 = T1**(1.D0/6.D0)
      T9 = SQRT(T1)
      T11 = T2**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T2
     #+0.1644733775567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.321646831778707D2/T13
      T17 = LOG(T16)
      ZK(I) = -0.3109D-1*T5*T17
      T22 = 1/T11
      T26 = T13**2
      T28 = T6**2
      T29 = T28**2
      T32 = RHOA**2
      T33 = 1/T32
      VRHOA(I) = -0.3109D-1*T4*T17+0.1321010150222857D-2*T1*T22*T17
     #+0.1D1*T5/T26*(-0.1853395810515781D1/T29/T6*T33
     #-0.128158207914907D1*T22*T33-0.8223668877838045D0/T9*T33
     #-0.1603914194192128D0/T2*T33)/T16
      VRHOB(I) = 0.D0
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      T1 = RHOA+RHOB
      T2 = 1/T1
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1325688999052018D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.598255043577108D1*T6+0.2225569421150687D1*T3
     #+0.8004286349993634D0*T9+0.1897004325747559D0*T11
      T16 = 1.D0+0.160818243221511D2/T13
      T17 = LOG(T16)
      T19 = 0.62182D-1*T5*T17
      T21 = 1.D0+0.6901399211255825D-1*T3
      T26 = 0.8157414703487641D1*T6+0.2247591863577616D1*T3
     #+0.4300972471276643D0*T9+0.1911512595127338D0*T11
      T29 = 1.D0+0.2960857464321668D2/T26
      T30 = LOG(T29)
      T31 = T21*T30
      T33 = RHOA-1.D0*RHOB
      T34 = T33*T2
      T35 = 1.D0+T34
      T36 = T35**(1.D0/3.D0)
      T39 = 1.D0-1.D0*T34
      T40 = T39**(1.D0/3.D0)
      T42 = T36*T35+T40*T39-2.D0
      T43 = T33**2
      T44 = T43**2
      T45 = T1**2
      T46 = T45**2
      T47 = 1/T46
      T48 = T44*T47
      T50 = 1.D0-1.D0*T48
      T53 = 0.3799574853701528D-1*T31*T42*T50
      T55 = 1.D0+0.1274696188700087D0*T3
      T60 = 0.1112037486309468D2*T6+0.3844746237447211D1*T3
     #+0.1644733775567609D1*T9+0.2405871291288192D0*T11
      T63 = 1.D0+0.321646831778707D2/T60
      T64 = LOG(T63)
      T67 = -0.3109D-1*T55*T64+T19
      T68 = T67*T42
      T70 = 0.1923661050931536D1*T68*T48
      ZK(I) = T1*(-T19+T53+T70)
      T73 = 1/T45
      T74 = 1/T11*T73
      T75 = T74*T17
      T76 = 0.2747799777968419D-2*T75
      T77 = T13**2
      T80 = T6**2
      T81 = T80**2
      T84 = 1/T81/T6*T73
      T88 = 1/T9*T73
      T91 = 1/T3*T73
      T96 = T5/T77*(-0.99709173929518D0*T84-0.7418564737168958D0*T74
     #-0.4002143174996817D0*T88-0.1264669550498372D0*T91)/T16
      T97 = 0.1D1*T96
      T101 = 0.8740794299481065D-3*T74*T30*T42*T50
      T102 = T26**2
      T115 = 0.1124999956683108D1*T21/T102*(-0.135956911724794D1*T84
     #-0.7491972878592054D0*T74-0.2150486235638321D0*T88
     #-0.1274341730084892D0*T91)/T29*T42*T50
      T116 = T33*T73
      T117 = 1.D0*T116
      T121 = 1.D0*T2
      T125 = 0.1333333333333333D1*T36*(T2-T117)+0.1333333333333333D1
     #*T40*(-T121+T116)
      T130 = T43*T33*T47
      T131 = 4.D0*T130
      T134 = T44/T46/T1
      T135 = 4.D0*T134
      T142 = T60**2
      T159 = 0.1923661050931536D1*(0.1321010150222857D-2*T74*T64+0.1D1
     #*T55/T142*(-0.1853395810515781D1*T84-0.128158207914907D1*T74
     #-0.8223668877838045D0*T88-0.1603914194192128D0*T91)/T63
     #-0.2747799777968419D-2*T75-0.1D1*T96)*T42*T48
      T163 = T68*T130
      T166 = 0.7694644203726145D1*T68*T134
      VRHOA(I) = -T19+T53+T70+T1*(T76+T97-T101-T115
     #+0.3799574853701528D-1*T31*T125*T50+0.3799574853701528D-1*T31
     #*T42*(-T131+T135)+T159+0.1923661050931536D1*T67*T125*T48
     #+0.7694644203726145D1*T163-T166)
      T175 = 0.1333333333333333D1*T36*(-T121-T117)
     #+0.1333333333333333D1*T40*(T2+T116)
      VRHOB(I) = -T19+T53+T70+T1*(T76+T97-T101-T115
     #+0.3799574853701528D-1*T31*T175*T50+0.3799574853701528D-1*T31
     #*T42*(T131+T135)+T159+0.1923661050931536D1*T67*T175*T48
     #-0.7694644203726145D1*T163-T166)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      T1 = 1/RHOB
      T2 = T1**(1.D0/3.D0)
      T4 = 1.D0+0.1274696188700087D0*T2
      T5 = RHOB*T4
      T6 = T1**(1.D0/6.D0)
      T9 = SQRT(T1)
      T11 = T2**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T2
     #+0.1644733775567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.321646831778707D2/T13
      T17 = LOG(T16)
      ZK(I) = -0.3109D-1*T5*T17
      VRHOA(I) = 0.D0
      T22 = 1/T11
      T23 = T1*T22
      T26 = T13**2
      T27 = 1/T26
      T28 = T6**2
      T29 = T28**2
      T30 = T29*T6
      T31 = 1/T30
      T32 = RHOB**2
      T33 = 1/T32
      T38 = 1/T9
      T41 = 1/T2
      T44 = -0.1853395810515781D1*T31*T33-0.128158207914907D1*T22*T33
     #-0.8223668877838045D0*T38*T33-0.1603914194192128D0*T41*T33
      T46 = 1/T16
      T47 = T27*T44*T46
      VRHOB(I) = -0.3109D-1*T4*T17+0.1321010150222857D-2*T23*T17+0.1D1
     #*T5*T47
      V2RHOA2(I) = 0.D0
      V2RHOAB(I) = 0.D0
      T55 = 1/T32/RHOB
      T57 = 1/T11/T1
      T65 = T44**2
      T72 = T32**2
      T73 = 1/T72
      T99 = T26**2
      T102 = T16**2
      V2RHOB2(I) = 0.2D1*T4*T27*T44*T46+0.8806734334819047D-3*T55*T57
     #*T17-0.8497974591333914D-1*T23*T47-0.2D1*T5/T26/T13*T65*T46
     #+0.1D1*T5*T27*(-0.1544496508763151D1/T30/T1*T73
     #+0.3706791621031562D1*T31*T55-0.854388052766047D0*T57*T73
     #+0.2563164158298141D1*T22*T55-0.4111834438919023D0/T9/T1*T73
     #+0.1644733775567609D1*T38*T55-0.5346380647307093D-1/T2/T1*T73
     #+0.3207828388384256D0*T41*T55)*T46+0.321646831778707D2*T5/T99
     #*T65/T102
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      T1 = 1/RHOA
      T2 = T1**(1.D0/3.D0)
      T4 = 1.D0+0.1274696188700087D0*T2
      T5 = RHOA*T4
      T6 = T1**(1.D0/6.D0)
      T9 = SQRT(T1)
      T11 = T2**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T2
     #+0.1644733775567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.321646831778707D2/T13
      T17 = LOG(T16)
      ZK(I) = -0.3109D-1*T5*T17
      T22 = 1/T11
      T23 = T1*T22
      T26 = T13**2
      T27 = 1/T26
      T28 = T6**2
      T29 = T28**2
      T30 = T29*T6
      T31 = 1/T30
      T32 = RHOA**2
      T33 = 1/T32
      T38 = 1/T9
      T41 = 1/T2
      T44 = -0.1853395810515781D1*T31*T33-0.128158207914907D1*T22*T33
     #-0.8223668877838045D0*T38*T33-0.1603914194192128D0*T41*T33
      T46 = 1/T16
      T47 = T27*T44*T46
      VRHOA(I) = -0.3109D-1*T4*T17+0.1321010150222857D-2*T23*T17+0.1D1
     #*T5*T47
      VRHOB(I) = 0.D0
      T55 = 1/T32/RHOA
      T57 = 1/T11/T1
      T65 = T44**2
      T72 = T32**2
      T73 = 1/T72
      T99 = T26**2
      T102 = T16**2
      V2RHOA2(I) = 0.2D1*T4*T27*T44*T46+0.8806734334819047D-3*T55*T57
     #*T17-0.8497974591333914D-1*T23*T47-0.2D1*T5/T26/T13*T65*T46
     #+0.1D1*T5*T27*(-0.1544496508763151D1/T30/T1*T73
     #+0.3706791621031562D1*T31*T55-0.854388052766047D0*T57*T73
     #+0.2563164158298141D1*T22*T55-0.4111834438919023D0/T9/T1*T73
     #+0.1644733775567609D1*T38*T55-0.5346380647307093D-1/T2/T1*T73
     #+0.3207828388384256D0*T41*T55)*T46+0.321646831778707D2*T5/T99
     #*T65/T102
      V2RHOB2(I) = 0.D0
      V2RHOAB(I) = 0.D0
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      T1 = RHOA+RHOB
      T2 = 1/T1
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1325688999052018D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.598255043577108D1*T6+0.2225569421150687D1*T3
     #+0.8004286349993634D0*T9+0.1897004325747559D0*T11
      T16 = 1.D0+0.160818243221511D2/T13
      T17 = LOG(T16)
      T19 = 0.62182D-1*T5*T17
      T21 = 1.D0+0.6901399211255825D-1*T3
      T26 = 0.8157414703487641D1*T6+0.2247591863577616D1*T3
     #+0.4300972471276643D0*T9+0.1911512595127338D0*T11
      T29 = 1.D0+0.2960857464321668D2/T26
      T30 = LOG(T29)
      T31 = T21*T30
      T33 = RHOA-1.D0*RHOB
      T34 = T33*T2
      T35 = 1.D0+T34
      T36 = T35**(1.D0/3.D0)
      T39 = 1.D0-1.D0*T34
      T40 = T39**(1.D0/3.D0)
      T42 = T36*T35+T40*T39-2.D0
      T43 = T33**2
      T44 = T43**2
      T45 = T1**2
      T46 = T45**2
      T47 = 1/T46
      T48 = T44*T47
      T50 = 1.D0-1.D0*T48
      T51 = T42*T50
      T53 = 0.3799574853701528D-1*T31*T51
      T55 = 1.D0+0.1274696188700087D0*T3
      T60 = 0.1112037486309468D2*T6+0.3844746237447211D1*T3
     #+0.1644733775567609D1*T9+0.2405871291288192D0*T11
      T63 = 1.D0+0.321646831778707D2/T60
      T64 = LOG(T63)
      T67 = -0.3109D-1*T55*T64+T19
      T68 = T67*T42
      T70 = 0.1923661050931536D1*T68*T48
      ZK(I) = T1*(-T19+T53+T70)
      T72 = 1/T11
      T73 = 1/T45
      T74 = T72*T73
      T75 = T74*T17
      T76 = 0.2747799777968419D-2*T75
      T77 = T13**2
      T78 = 1/T77
      T79 = T5*T78
      T80 = T6**2
      T81 = T80**2
      T82 = T81*T6
      T83 = 1/T82
      T84 = T83*T73
      T87 = 1/T9
      T88 = T87*T73
      T90 = 1/T3
      T91 = T90*T73
      T93 = -0.99709173929518D0*T84-0.7418564737168958D0*T74
     #-0.4002143174996817D0*T88-0.1264669550498372D0*T91
      T94 = 1/T16
      T96 = T79*T93*T94
      T97 = 0.1D1*T96
      T98 = T30*T42
      T99 = T98*T50
      T100 = T74*T99
      T101 = 0.8740794299481065D-3*T100
      T102 = T26**2
      T103 = 1/T102
      T104 = T21*T103
      T109 = -0.135956911724794D1*T84-0.7491972878592054D0*T74
     #-0.2150486235638321D0*T88-0.1274341730084892D0*T91
      T110 = T104*T109
      T111 = 1/T29
      T112 = T111*T42
      T113 = T112*T50
      T114 = T110*T113
      T115 = 0.1124999956683108D1*T114
      T116 = T33*T73
      T117 = 1.D0*T116
      T118 = T2-T117
      T121 = 1.D0*T2
      T122 = -T121+T116
      T125 = 0.1333333333333333D1*T36*T118+0.1333333333333333D1*T40*T122
      T127 = T31*T125*T50
      T128 = 0.3799574853701528D-1*T127
      T129 = T43*T33
      T130 = T129*T47
      T131 = 4.D0*T130
      T133 = 1/T46/T1
      T134 = T44*T133
      T135 = 4.D0*T134
      T136 = -T131+T135
      T138 = T31*T42*T136
      T139 = 0.3799574853701528D-1*T138
      T142 = T60**2
      T143 = 1/T142
      T144 = T55*T143
      T149 = -0.1853395810515781D1*T84-0.128158207914907D1*T74
     #-0.8223668877838045D0*T88-0.1603914194192128D0*T91
      T150 = 1/T63
      T156 = 0.1321010150222857D-2*T74*T64+0.1D1*T144*T149*T150
     #-0.2747799777968419D-2*T75-0.1D1*T96
      T157 = T156*T42
      T158 = T157*T48
      T159 = 0.1923661050931536D1*T158
      T160 = T67*T125
      T161 = T160*T48
      T162 = 0.1923661050931536D1*T161
      T163 = T68*T130
      T165 = T68*T134
      T166 = 0.7694644203726145D1*T165
      VRHOA(I) = -T19+T53+T70+T1*(T76+T97-T101-T115+T128+T139+T159
     #+T162+0.7694644203726145D1*T163-T166)
      T169 = -T121-T117
      T172 = T2+T116
      T175 = 0.1333333333333333D1*T36*T169+0.1333333333333333D1*T40*T172
      T177 = T31*T175*T50
      T178 = 0.3799574853701528D-1*T177
      T179 = T131+T135
      T181 = T31*T42*T179
      T182 = 0.3799574853701528D-1*T181
      T183 = T67*T175
      T184 = T183*T48
      T185 = 0.1923661050931536D1*T184
      VRHOB(I) = -T19+T53+T70+T1*(T76+T97-T101-T115+T178+T182+T159
     #+T185-0.7694644203726145D1*T163-T166)
      T189 = 0.5495599555936838D-2*T75
      T190 = 0.2D1*T96
      T191 = 0.1748158859896213D-2*T100
      T192 = 0.2249999913366216D1*T114
      T195 = 0.3847322101863073D1*T158
      T198 = 0.1538928840745229D2*T165
      T199 = T36**2
      T200 = 1/T199
      T201 = T118**2
      T204 = 2.D0*T73
      T206 = 1/T45/T1
      T208 = 2.D0*T33*T206
      T209 = -T204+T208
      T212 = T40**2
      T213 = 1/T212
      T214 = T122**2
      T220 = 0.4444444444444444D0*T200*T201+0.1333333333333333D1*T36
     #*T209+0.4444444444444444D0*T213*T214-0.1333333333333333D1*T40*T209
      T226 = 1/T11/T2*T47
      T228 = 0.5827196199654043D-3*T226*T99
      T229 = T43*T47
      T230 = T68*T229
      T231 = 0.2308393261117844D2*T230
      T234 = T44/T46/T45
      T236 = 0.3847322101863073D2*T68*T234
      T238 = 0.1538928840745229D2*T157*T134
      T239 = T129*T133
      T240 = T68*T239
      T242 = T77**2
      T245 = T93**2
      T246 = T16**2
      T249 = T5/T242*T245/T246
      T250 = 0.160818243221511D2*T249
      T255 = T5/T77/T13*T245*T94
      T256 = 0.2D1*T255
      T259 = 1/T82/T2*T47
      T261 = T83*T206
      T264 = T72*T206
      T268 = 1/T9/T2*T47
      T270 = T87*T206
      T274 = 1/T3/T2*T47
      T276 = T90*T206
      T280 = T79*(-0.8309097827459833D0*T259+0.199418347859036D1*T261
     #-0.4945709824779306D0*T226+0.1483712947433792D1*T264
     #-0.2001071587498409D0*T268+0.8004286349993634D0*T270
     #-0.4215565168327908D-1*T274+0.2529339100996745D0*T276)*T94
      T281 = 0.1D1*T280
      T282 = 12.D0*T229
      T283 = 32.D0*T239
      T284 = 20.D0*T234
      T300 = T149**2
      T316 = T142**2
      T319 = T63**2
      T324 = T226*T17
      T326 = T264*T17
      T330 = T74*T78*T93*T94
      T335 = 0.8806734334819047D-3*T226*T64-0.2642020300445714D-2*T264
     #*T64-0.8497974591333914D-1*T74*T143*T149*T150-0.2D1*T55/T142/T60
     #*T300*T150+0.1D1*T144*(-0.1544496508763151D1*T259
     #+0.3706791621031562D1*T261-0.854388052766047D0*T226
     #+0.2563164158298141D1*T264-0.4111834438919023D0*T268
     #+0.1644733775567609D1*T270-0.5346380647307093D-1*T274
     #+0.3207828388384256D0*T276)*T150+0.321646831778707D2*T55/T316
     #*T300/T319-0.1831866518645613D-2*T324+0.5495599555936838D-2*T326
     #+0.8837926660346786D-1*T330+0.2D1*T255-0.1D1*T280
     #-0.160818243221511D2*T249
      T338 = 0.1923661050931536D1*T335*T42*T48
      T345 = T157*T130
      T347 = 0.3799574853701528D-1*T31*T220*T50-T228+T231+T236-T238
     #-0.6155715362980916D2*T240+T250-T256+T281+0.3799574853701528D-1
     #*T31*T42*(-T282+T283-T284)+T338+0.7599149707403056D-1*T31*T125
     #*T136+0.1923661050931536D1*T67*T220*T48+0.1538928840745229D2*T345
      T348 = T160*T130
      T350 = 0.1831866518645613D-2*T324
      T351 = 0.5495599555936838D-2*T326
      T353 = 0.1748158859896213D-2*T264*T99
      T354 = T160*T134
      T357 = T74*T98*T136
      T361 = T74*T30*T125*T50
      T366 = T109**2
      T369 = 0.2249999913366216D1*T21/T102/T26*T366*T113
      T374 = 0.5176049209143758D-1*T74*T103*T109*T111*T51
      T375 = 0.8837926660346786D-1*T330
      T376 = T102**2
      T380 = T29**2
      T385 = 0.3330964519106732D2*T21/T376*T366/T380*T42*T50
      T388 = T110*T111*T125*T50
      T391 = T110*T112*T136
      T404 = 0.1124999956683108D1*T104*(-0.1132974264373283D1*T259
     #+0.271913823449588D1*T261-0.4994648585728036D0*T226
     #+0.1498394575718411D1*T264-0.1075243117819161D0*T268
     #+0.4300972471276643D0*T270-0.4247805766949639D-1*T274
     #+0.2548683460169784D0*T276)*T113
      T406 = T156*T125*T48
      T408 = 0.1538928840745229D2*T348+T350-T351+T353
     #-0.1538928840745229D2*T354-0.1748158859896213D-2*T357
     #-0.1748158859896213D-2*T361+T369+T374-T375-T385
     #-0.2249999913366216D1*T388-0.2249999913366216D1*T391-T404
     #+0.3847322101863073D1*T406
      V2RHOA2(I) = T189+T190-T191-T192+0.7599149707403056D-1*T127
     #+0.7599149707403056D-1*T138+T195+0.3847322101863073D1*T161
     #+0.1538928840745229D2*T163-T198+T1*(T347+T408)
      T415 = T169**2
      T418 = T204+T208
      T421 = T172**2
      T427 = 0.4444444444444444D0*T200*T415+0.1333333333333333D1*T36
     #*T418+0.4444444444444444D0*T213*T421-0.1333333333333333D1*T40*T418
      T439 = T156*T175*T48
      T441 = T183*T134
      T443 = T183*T130
      T450 = T110*T111*T175*T50
      T453 = 0.3799574853701528D-1*T31*T427*T50+0.7599149707403056D-1
     #*T31*T175*T179+0.3799574853701528D-1*T31*T42*(-T282-T283-T284)
     #+0.3847322101863073D1*T439-0.1538928840745229D2*T441
     #-0.1538928840745229D2*T443+0.1923661050931536D1*T67*T427*T48
     #-0.2249999913366216D1*T450-T228+T231+T236-T238
     #+0.6155715362980916D2*T240+T250
      T456 = T74*T98*T179
      T460 = T74*T30*T175*T50
      T463 = T110*T112*T179
      T465 = -T256+T281+T338-0.1538928840745229D2*T345+T350-T351+T353
     #+T369+T374-T375-T385-T404-0.1748158859896213D-2*T456
     #-0.1748158859896213D-2*T460-0.2249999913366216D1*T463
      V2RHOB2(I) = T189+T190-T191-T192+0.7599149707403056D-1*T177
     #+0.7599149707403056D-1*T181+T195+0.3847322101863073D1*T184
     #-0.1538928840745229D2*T163-T198+T1*(T453+T465)
      T484 = 0.4444444444444444D0*T200*T118*T169+0.2666666666666667D1
     #*T36*T33*T206+0.4444444444444444D0*T213*T122*T172
     #-0.2666666666666667D1*T40*T33*T206
      T502 = 0.1923661050931536D1*T439-0.7694644203726145D1*T441
     #+0.7694644203726145D1*T443-0.1124999956683108D1*T450
     #+0.3799574853701528D-1*T31*T484*T50+0.3799574853701528D-1*T31
     #*T125*T179+0.3799574853701528D-1*T31*T175*T136
     #+0.3799574853701528D-1*T31*T42*(T282-T284)+0.1923661050931536D1
     #*T67*T484*T48-T228-0.2308393261117844D2*T230+T236-T238+T250-T256
     #+T281+T338
      T513 = -0.7694644203726145D1*T348+T350-T351+T353
     #-0.7694644203726145D1*T354-0.8740794299481065D-3*T357
     #-0.8740794299481065D-3*T361+T369+T374-T375-T385
     #-0.1124999956683108D1*T388-0.1124999956683108D1*T391-T404
     #+0.1923661050931536D1*T406-0.8740794299481065D-3*T456
     #-0.8740794299481065D-3*T460-0.1124999956683108D1*T463
      V2RHOAB(I) = T189+T190-T191-T192+T178+T182+T195+T185-T198+T128
     #+T139+T162+T1*(T502+T513)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      V2RHOB2(I) = 0.0D0
      V2RHOAB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C*MODULE DFTXCB  *DECK RKS_C_PW92
      SUBROUTINE RKS_C_PW92(IDERIV,NPT,RHOA1,ZK,VRHOA,V2RHOA2)
C
C     J.P. PERDEW, Y. WANG
C     ACCURATE AND SIMPLE ANALYTIC REPRESENTATION OF
C     THE ELECTRON-GAS CORRELATION ENERGY
C     PHYS. REV. B 45 (1992) 13244-13249
C
C     NOTE: PLEASE SEE A REMARK IN -PW91CF- REGARDING THE NUMBER
C           OF DIGITS USED IN CONSTANTS TO GENERATE THIS ROUTINE.
C
      IMPLICIT DOUBLE PRECISION(A-H,O-Z)
      INTEGER IDERIV,NPT
      DIMENSION RHOA1(NPT),ZK(NPT),VRHOA(NPT),V2RHOA2(NPT)
      PARAMETER(TOL=1.0D-20)
C
      IF(IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T6 = T1**(1.D0/6.D0)
      T9 = SQRT(T1)
      T11 = T2**2
      T17 = LOG(1.D0+0.160818243221511D2/(0.598255043577108D1*T6
     #+0.2225569421150687D1*T2+0.8004286349993634D0*T9
     #+0.1897004325747559D0*T11))
      ZK(I) = -0.62182D-1*RHO*(1.D0+0.1325688999052018D0*T2)*T17
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T4 = 1.D0+0.1325688999052018D0*T2
      T6 = T1**(1.D0/6.D0)
      T9 = SQRT(T1)
      T11 = T2**2
      T13 = 0.598255043577108D1*T6+0.2225569421150687D1*T2
     #+0.8004286349993634D0*T9+0.1897004325747559D0*T11
      T16 = 1.D0+0.160818243221511D2/T13
      T17 = LOG(T16)
      ZK(I) = -0.62182D-1*RHO*T4*T17
      T23 = RHO**2
      T24 = 1/T23
      T25 = 1/T11*T24
      T28 = T13**2
      T31 = T6**2
      T32 = T31**2
      VRHOA(I) = -0.62182D-1*T4*T17+RHO*(0.2747799777968419D-2*T25*T17
     #+0.1D1*T4/T28*(-0.99709173929518D0/T32/T6*T24
     #-0.7418564737168958D0*T25-0.4002143174996817D0/T9*T24
     #-0.1264669550498372D0/T2*T24)/T16)
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T4 = 1.D0+0.1325688999052018D0*T2
      T6 = T1**(1.D0/6.D0)
      T9 = SQRT(T1)
      T11 = T2**2
      T13 = 0.598255043577108D1*T6+0.2225569421150687D1*T2
     #+0.8004286349993634D0*T9+0.1897004325747559D0*T11
      T16 = 1.D0+0.160818243221511D2/T13
      T17 = LOG(T16)
      ZK(I) = -0.62182D-1*RHO*T4*T17
      T22 = 1/T11
      T23 = RHO**2
      T24 = 1/T23
      T25 = T22*T24
      T26 = T25*T17
      T28 = T13**2
      T29 = 1/T28
      T30 = T4*T29
      T31 = T6**2
      T32 = T31**2
      T33 = T32*T6
      T34 = 1/T33
      T38 = 1/T9
      T41 = 1/T2
      T44 = -0.99709173929518D0*T34*T24-0.7418564737168958D0*T25
     #-0.4002143174996817D0*T38*T24-0.1264669550498372D0*T41*T24
      T45 = 1/T16
      T47 = T30*T44*T45
      VRHOA(I) = -0.62182D-1*T4*T17+RHO*(0.2747799777968419D-2*T26
     #+0.1D1*T47)
      T55 = T23**2
      T56 = 1/T55
      T57 = 1/T11/T1*T56
      T59 = 0.1831866518645613D-2*T57*T17
      T61 = 1/T23/RHO
      T62 = T22*T61
      T64 = 0.5495599555936838D-2*T62*T17
      T75 = LOG(1.D0+0.2960857464321668D2/(0.8157414703487641D1*T6
     #+0.2247591863577616D1*T2+0.4300972471276643D0*T9
     #+0.1911512595127338D0*T11))
      T77 = (1.D0+0.6901399211255825D-1*T2)*T75*T24
      T82 = 0.8837926660346786D-1*T25*T29*T44*T45
      T83 = T28**2
      T86 = T44**2
      T87 = T16**2
      T91 = 0.160818243221511D2*T4/T83*T86/T87
      T115 = 0.1D1*T30*(-0.8309097827459833D0/T33/T1*T56
     #+0.199418347859036D1*T34*T61-0.4945709824779306D0*T57
     #+0.1483712947433792D1*T62-0.2001071587498409D0/T9/T1*T56
     #+0.8004286349993634D0*T38*T61-0.4215565168327908D-1/T2/T1*T56
     #+0.2529339100996745D0*T41*T61)*T45
      T121 = 0.2D1*T4/T28/T13*T86*T45
      V2RHOA2(I) = 0.4D1*T47+0.1099119911187368D-1*T26+RHO*(T59-T64
     #+0.3377399869956914D-1*T77-T82+T91+T115-T121)+RHO*(T59-T64
     #-0.3377399869956914D-1*T77-T82+T91+T115-T121)
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C
C*MODULE DFTXCB  *DECK PIECEWISE
      DOUBLE PRECISION FUNCTION PIECEWISE(O,A,B)
C
C     FIX FOR A MAPLE PROBLEM. THE MAPLE FORTRAN GENERATOR IS NOT
C     ABLE TO TRANSFORM ITS PIECEWISE COMMAND TO FORTRAN. THEREFORE
C     THIS FUNCTION WAS WRITTEN TO TAKE CARE OF THIS.
C
      IMPLICIT NONE
      LOGICAL O
      DOUBLE PRECISION A, B
      IF (O) THEN
         PIECEWISE = A
      ELSE
         PIECEWISE = B
      ENDIF
      RETURN
      END
C*MODULE DFTXCB  *DECK UKS_C_P86
      SUBROUTINE UKS_C_P86
     & (IDERIV,NPT,RHOA1,RHOB1,SIGMAAA1,SIGMABB1,SIGMAAB1,
     &  ZK,VRHOA,VRHOB,VSIGMAAA,VSIGMABB,VSIGMAAB,
     &  V2RHOA2,V2RHOB2,V2RHOAB,
     &  V2RHOASIGMAAA,V2RHOASIGMAAB,V2RHOASIGMABB,
     &  V2RHOBSIGMABB,V2RHOBSIGMAAB,V2RHOBSIGMAAA,
     &  V2SIGMAAA2,V2SIGMAAAAB,V2SIGMAAABB,
     &  V2SIGMAAB2,V2SIGMAABBB,V2SIGMABB2)
C
C     J.P. PERDEW
C     DENSITY-FUNCTIONAL APPROXIMATION FOR THE CORRELATION ENERGY OF
C     THE INHOMOGENEOUS ELECTRON GAS
C     PHYS. REV. B33 (1986) 8822-8824
C
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      INTEGER IDERIV,NPT
      DOUBLE PRECISION RHOA1(NPT),RHOB1(NPT)
      DOUBLE PRECISION SIGMAAA1(NPT),SIGMABB1(NPT),SIGMAAB1(NPT)
      DOUBLE PRECISION ZK(NPT),VRHOA(NPT),VRHOB(NPT)
      DOUBLE PRECISION VSIGMAAA(NPT),VSIGMABB(NPT),VSIGMAAB(NPT)
      DOUBLE PRECISION V2RHOA2(NPT),V2RHOB2(NPT),V2RHOAB(NPT)
      DOUBLE PRECISION V2RHOASIGMAAA(NPT),V2RHOASIGMAAB(NPT)
      DOUBLE PRECISION V2RHOASIGMABB(NPT),V2RHOBSIGMABB(NPT)
      DOUBLE PRECISION V2RHOBSIGMAAB(NPT),V2RHOBSIGMAAA(NPT)
      DOUBLE PRECISION V2SIGMAAA2(NPT),V2SIGMAAAAB(NPT),V2SIGMAAABB(NPT)
      DOUBLE PRECISION V2SIGMAAB2(NPT),V2SIGMAABBB(NPT),V2SIGMABB2(NPT)
      PARAMETER(TOL=1.0D-20)
      LOGICAL T7
C
      IF (IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.0D+00,RHOA1(I))
      RHOB = MAX(0.0D+00,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.0D+00,SIGMABB1(I))
      SIGMA = SIGMABB
      T2 = 1/RHOB
      T3 = T2**(1.D0/3.D0)
      T4 = 0.6203504908994D0*T3
      T6 = T2**(1.D0/6.D0)
      T12 = LOG(T4)
      T18 = PIECEWISE(1.D0 .LE. T4,-0.843D-1/(1.D0
     #+0.1101176160755631D1*T6+0.1619735131738333D0*T3),0.1555D-1*T12
     #-0.269D-1+0.43424534362958D-3*T3*T12-0.297768235631712D-2*T3)
      T20 = SQRT(SIGMABB)
      T22 = T3**2
      T31 = 0.1667D-2+(0.2568D-2+0.1443307452126544D-1*T3
     #+0.2843543831490386D-5*T22)/(1.D0+0.5411317332115466D1*T3
     #+0.1816419932959077D0*T22+0.1763993811759022D-1*T2)
      T34 = RHOB**(1.D0/6.D0)
      T39 = EXP(-0.81290825D-3*T20/T31/T34/RHOB)
      T41 = RHOB**(1.D0/3.D0)
      ZK(I) = RHOB*T18+0.7937005259840997D0*T39*T31*SIGMABB/T41/RHOB
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.0D+00,SIGMAAA1(I))
      SIGMA = SIGMAAA
      T2 = 1/RHOA
      T3 = T2**(1.D0/3.D0)
      T4 = 0.6203504908994D0*T3
      T6 = T2**(1.D0/6.D0)
      T12 = LOG(T4)
      T18 = PIECEWISE(1.D0 .LE. T4,-0.843D-1/(1.D0
     #+0.1101176160755631D1*T6+0.1619735131738333D0*T3),0.1555D-1*T12
     #-0.269D-1+0.43424534362958D-3*T3*T12-0.297768235631712D-2*T3)
      T20 = SQRT(SIGMAAA)
      T22 = T3**2
      T31 = 0.1667D-2+(0.2568D-2+0.1443307452126544D-1*T3
     #+0.2843543831490386D-5*T22)/(1.D0+0.5411317332115466D1*T3
     #+0.1816419932959077D0*T22+0.1763993811759022D-1*T2)
      T34 = RHOA**(1.D0/6.D0)
      T39 = EXP(-0.81290825D-3*T20/T31/T34/RHOA)
      T41 = RHOA**(1.D0/3.D0)
      ZK(I) = RHOA*T18+0.7937005259840997D0*T39*T31*SIGMAAA/T41/RHOA
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.0D+00,SIGMAAA1(I))
      SIGMAAB = SIGMAAB1(I)
      SIGMABB = MAX(0.0D+00,SIGMABB1(I))
      SIGMA = SIGMAAA+SIGMABB+2.D0*SIGMAAB
      T4 = 1/RHO
      T5 = T4**(1.D0/3.D0)
      T6 = 0.6203504908994D0*T5
      T8 = T4**(1.D0/6.D0)
      T13 = 0.1423D0/(1.D0+0.8292885914166397D0*T8+0.20682485366586D0
     #*T5)
      T22 = (RHOA-1.D0*RHOB)*T4
      T23 = 1.D0+T22
      T24 = T23**(1.D0/3.D0)
      T27 = 1.D0-1.D0*T22
      T28 = T27**(1.D0/3.D0)
      T30 = T24*T23+T28*T27-2.D0
      T34 = LOG(T6)
      T36 = T5*T34
      T46 = PIECEWISE(1.D0 .LE. T6,-T13+0.1923661050931536D1*(
     #-0.843D-1/(1.D0+0.1101176160755631D1*T8+0.1619735131738333D0*T5)
     #+T13)*T30,0.311D-1*T34-0.48D-1+0.12407009817988D-2*T36
     #-0.719606569443304D-2*T5+0.1923661050931536D1*(-0.1555D-1*T34
     #+0.211D-1-0.80645563816922D-3*T36+0.421838333811592D-2*T5)*T30)
      T48 = SQRT(SIGMA)
      T50 = T5**2
      T59 = 0.1667D-2+(0.2568D-2+0.1443307452126544D-1*T5
     #+0.2843543831490386D-5*T50)/(1.D0+0.5411317332115466D1*T5
     #+0.1816419932959077D0*T50+0.1763993811759022D-1*T4)
      T62 = RHO**(1.D0/6.D0)
      T67 = EXP(-0.81290825D-3*T48/T59/T62/RHO)
      T69 = RHO**(1.D0/3.D0)
      T74 = 0.5D0+0.5D0*T22
      T75 = T74**(1.D0/3.D0)
      T76 = T75**2
      T79 = 0.5D0-0.5D0*T22
      T80 = T79**(1.D0/3.D0)
      T81 = T80**2
      T84 = SQRT(T76*T74+T81*T79)
      ZK(I) = RHO*T46+0.7937005259840997D0*T67*T59*SIGMA/T69/RHO/T84
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.0D+00,RHOA1(I))
      RHOB = MAX(0.0D+00,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.0D+00,SIGMABB1(I))
      SIGMA = SIGMABB
      T2 = 1/RHOB
      T3 = T2**(1.D0/3.D0)
      T4 = 0.6203504908994D0*T3
      T7 = 1.D0 .LE. T4
      T6 = T2**(1.D0/6.D0)
      T9 = 1.D0+0.1101176160755631D1*T6+0.1619735131738333D0*T3
      T12 = LOG(T4)
      T18 = PIECEWISE(T7,-0.843D-1/T9,0.1555D-1*T12-0.269D-1
     #+0.43424534362958D-3*T3*T12-0.297768235631712D-2*T3)
      T20 = SQRT(SIGMABB)
      T22 = T3**2
      T24 = 0.2568D-2+0.1443307452126544D-1*T3+0.2843543831490386D-5*T22
      T28 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T22
     #+0.1763993811759022D-1*T2
      T29 = 1/T28
      T31 = 0.1667D-2+T24*T29
      T33 = T20/T31
      T34 = RHOB**(1.D0/6.D0)
      T36 = 1/T34/RHOB
      T39 = EXP(-0.81290825D-3*T33*T36)
      T40 = T39*T31
      T41 = RHOB**(1.D0/3.D0)
      T43 = 1/T41/RHOB
      T44 = SIGMABB*T43
      ZK(I) = RHOB*T18+0.7937005259840997D0*T40*T44
      VRHOA(I) = 0.0D+00
      T47 = T9**2
      T49 = T6**2
      T50 = T49**2
      T53 = RHOB**2
      T54 = 1/T53
      T57 = 1/T22
      T58 = T57*T54
      T71 = PIECEWISE(T7,0.843D-1/T47*(-0.1835293601259385D0/T50/T6
     #*T54-0.5399117105794445D-1*T58),-0.5183333333333333D-2*T2
     #-0.1447484478765267D-3*T57*T12*T54-0.1447484478765267D-3*T3*T2
     #+0.99256078543904D-3*T58)
      T73 = T31**2
      T78 = 1/T3*T54
      T82 = T28**2
      T91 = (-0.4811024840421814D-2*T58-0.1895695887660258D-5*T78)*T29
     #-1.D0*T24/T82*(-0.1803772444038489D1*T58-0.1210946621972718D0
     #*T78-0.1763993811759022D-1*T54)
      VRHOB(I) = T18+RHOB*T71+0.7937005259840997D0*(0.81290825D-3*T20
     #/T73*T36*T91+0.9483929583333333D-3*T33/T34/T53)*T39*T31*SIGMABB
     #*T43+0.7937005259840997D0*T39*T91*T44-0.10582673679788D1*T40
     #*SIGMABB/T41/T53
      VSIGMAAA(I) = 0.0D+00
      VSIGMAAB(I) = 0.0D+00
      T113 = SQRT(RHOB)
      VSIGMABB(I) = -0.322602852800907D-3*T20/T113/T53*T39
     #+0.7937005259840997D0*T40*T43
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.0D+00,SIGMAAA1(I))
      SIGMA = SIGMAAA
      T2 = 1/RHOA
      T3 = T2**(1.D0/3.D0)
      T4 = 0.6203504908994D0*T3
      T7 = 1.D0 .LE. T4
      T6 = T2**(1.D0/6.D0)
      T9 = 1.D0+0.1101176160755631D1*T6+0.1619735131738333D0*T3
      T12 = LOG(T4)
      T18 = PIECEWISE(T7,-0.843D-1/T9,0.1555D-1*T12-0.269D-1
     #+0.43424534362958D-3*T3*T12-0.297768235631712D-2*T3)
      T20 = SQRT(SIGMAAA)
      T22 = T3**2
      T24 = 0.2568D-2+0.1443307452126544D-1*T3+0.2843543831490386D-5*T22
      T28 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T22
     #+0.1763993811759022D-1*T2
      T29 = 1/T28
      T31 = 0.1667D-2+T24*T29
      T33 = T20/T31
      T34 = RHOA**(1.D0/6.D0)
      T36 = 1/T34/RHOA
      T39 = EXP(-0.81290825D-3*T33*T36)
      T40 = T39*T31
      T41 = RHOA**(1.D0/3.D0)
      T43 = 1/T41/RHOA
      T44 = SIGMAAA*T43
      ZK(I) = RHOA*T18+0.7937005259840997D0*T40*T44
      T47 = T9**2
      T49 = T6**2
      T50 = T49**2
      T53 = RHOA**2
      T54 = 1/T53
      T57 = 1/T22
      T58 = T57*T54
      T71 = PIECEWISE(T7,0.843D-1/T47*(-0.1835293601259385D0/T50/T6
     #*T54-0.5399117105794445D-1*T58),-0.5183333333333333D-2*T2
     #-0.1447484478765267D-3*T57*T12*T54-0.1447484478765267D-3*T3*T2
     #+0.99256078543904D-3*T58)
      T73 = T31**2
      T78 = 1/T3*T54
      T82 = T28**2
      T91 = (-0.4811024840421814D-2*T58-0.1895695887660258D-5*T78)*T29
     #-1.D0*T24/T82*(-0.1803772444038489D1*T58-0.1210946621972718D0
     #*T78-0.1763993811759022D-1*T54)
      VRHOA(I) = T18+RHOA*T71+0.7937005259840997D0*(0.81290825D-3*T20
     #/T73*T36*T91+0.9483929583333333D-3*T33/T34/T53)*T39*T31*SIGMAAA
     #*T43+0.7937005259840997D0*T39*T91*T44-0.10582673679788D1*T40
     #*SIGMAAA/T41/T53
      VRHOB(I) = 0.0D+00
      T113 = SQRT(RHOA)
      VSIGMAAA(I) = -0.322602852800907D-3*T20/T113/T53*T39
     #+0.7937005259840997D0*T40*T43
      VSIGMAAB(I) = 0.0D+00
      VSIGMABB(I) = 0.0D+00
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.0D+00,SIGMAAA1(I))
      SIGMAAB = SIGMAAB1(I)
      SIGMABB = MAX(0.0D+00,SIGMABB1(I))
      SIGMA = SIGMAAA+SIGMABB+2.D0*SIGMAAB
      T4 = 1/RHO
      T5 = T4**(1.D0/3.D0)
      T6 = 0.6203504908994D0*T5
      T7 = 1.D0 .LE. T6
      T8 = T4**(1.D0/6.D0)
      T11 = 1.D0+0.8292885914166397D0*T8+0.20682485366586D0*T5
      T13 = 0.1423D0/T11
      T16 = 1.D0+0.1101176160755631D1*T8+0.1619735131738333D0*T5
      T19 = -0.843D-1/T16+T13
      T21 = RHOA-1.D0*RHOB
      T22 = T21*T4
      T23 = 1.D0+T22
      T24 = T23**(1.D0/3.D0)
      T27 = 1.D0-1.D0*T22
      T28 = T27**(1.D0/3.D0)
      T30 = T24*T23+T28*T27-2.D0
      T34 = LOG(T6)
      T36 = T5*T34
      T42 = -0.1555D-1*T34+0.211D-1-0.80645563816922D-3*T36
     #+0.421838333811592D-2*T5
      T46 = PIECEWISE(T7,-T13+0.1923661050931536D1*T19*T30,0.311D-1
     #*T34-0.48D-1+0.12407009817988D-2*T36-0.719606569443304D-2*T5
     #+0.1923661050931536D1*T42*T30)
      T48 = SQRT(SIGMA)
      T50 = T5**2
      T52 = 0.2568D-2+0.1443307452126544D-1*T5+0.2843543831490386D-5*T50
      T56 = 1.D0+0.5411317332115466D1*T5+0.1816419932959077D0*T50
     #+0.1763993811759022D-1*T4
      T57 = 1/T56
      T59 = 0.1667D-2+T52*T57
      T61 = T48/T59
      T62 = RHO**(1.D0/6.D0)
      T64 = 1/T62/RHO
      T67 = EXP(-0.81290825D-3*T61*T64)
      T68 = T67*T59
      T69 = RHO**(1.D0/3.D0)
      T71 = 1/T69/RHO
      T74 = 0.5D0+0.5D0*T22
      T75 = T74**(1.D0/3.D0)
      T76 = T75**2
      T79 = 0.5D0-0.5D0*T22
      T80 = T79**(1.D0/3.D0)
      T81 = T80**2
      T83 = T76*T74+T81*T79
      T84 = SQRT(T83)
      T85 = 1/T84
      T86 = SIGMA*T71*T85
      ZK(I) = RHO*T46+0.7937005259840997D0*T68*T86
      T93 = 0.1333333333333333D1*T24*T4-0.1333333333333333D1*T28*T4
      T98 = PIECEWISE(T7,0.1923661050931536D1*T19
     #*T93,0.1923661050931536D1*T42*T93)
      T100 = T68*SIGMA
      T103 = T71/T84/T83
      T108 = 0.8333333333333333D0*T76*T4-0.8333333333333333D0*T81*T4
      T112 = T11**2
      T114 = T8**2
      T115 = T114**2
      T118 = RHO**2
      T119 = 1/T118
      T120 = 1/T115/T8*T119
      T122 = 1/T50
      T123 = T122*T119
      T127 = 0.1423D0/T112*(-0.1382147652361066D0*T120
     #-0.6894161788861999D-1*T123)
      T128 = T16**2
      T144 = -0.1333333333333333D1*T24*T21*T119+0.1333333333333333D1
     #*T28*T21*T119
      T150 = T122*T34*T119
      T152 = T5*T4
      T165 = PIECEWISE(T7,T127+0.1923661050931536D1*(0.843D-1/T128*(
     #-0.1835293601259385D0*T120-0.5399117105794445D-1*T123)-T127)*T30
     #+0.1923661050931536D1*T19*T144,-0.1036666666666667D-1*T4
     #-0.4135669939329333D-3*T150-0.4135669939329333D-3*T152
     #+0.2398688564811013D-2*T123+0.1923661050931536D1*
     #(0.5183333333333333D-2*T4+0.2688185460564067D-3*T150
     #+0.2688185460564067D-3*T152-0.1406127779371973D-2*T123)*T30
     #+0.1923661050931536D1*T42*T144)
      T166 = RHO*T165
      T167 = T59**2
      T172 = 1/T5*T119
      T176 = T56**2
      T185 = (-0.4811024840421814D-2*T123-0.1895695887660258D-5*T172)
     #*T57-1.D0*T52/T176*(-0.1803772444038489D1*T123
     #-0.1210946621972718D0*T172-0.1763993811759022D-1*T119)
      T197 = 0.7937005259840997D0*(0.81290825D-3*T48/T167*T64*T185
     #+0.9483929583333333D-3*T61/T62/T118)*T67*T59*T86
      T200 = 0.7937005259840997D0*T67*T185*T86
      T206 = 0.10582673679788D1*T68*SIGMA/T69/T118*T85
      T216 = 0.3968502629920499D0*T100*T103*(-0.8333333333333333D0*T76
     #*T21*T119+0.8333333333333333D0*T81*T21*T119)
      VRHOA(I) = RHO*T98-0.3968502629920499D0*T100*T103*T108+T46+T166
     #+T197+T200-T206-T216
      T217 = -T93
      T222 = PIECEWISE(T7,0.1923661050931536D1*T19
     #*T217,0.1923661050931536D1*T42*T217)
      VRHOB(I) = RHO*T222+0.3968502629920499D0*T100*T103*T108+T46+T166
     #+T197+T200-T206-T216
      T228 = SQRT(RHO)
      T233 = T48/T228/T118*T67*T85
      T236 = T68*T71*T85
      VSIGMAAA(I) = -0.322602852800907D-3*T233+0.7937005259840997D0*T236
      VSIGMAAB(I) = -0.645205705601814D-3*T233+0.1587401051968199D1*T236
      VSIGMABB(I) = VSIGMAAA(I)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      VSIGMAAB(I) = 0.0D0
      VSIGMABB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.0D+00,RHOA1(I))
      RHOB = MAX(0.0D+00,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.0D+00,SIGMABB1(I))
      SIGMA = SIGMABB
      T2 = 1/RHOB
      T3 = T2**(1.D0/3.D0)
      T4 = 0.6203504908994D0*T3
      T7 = 1.D0 .LE. T4
      T6 = T2**(1.D0/6.D0)
      T9 = 1.D0+0.1101176160755631D1*T6+0.1619735131738333D0*T3
      T12 = LOG(T4)
      T18 = PIECEWISE(T7,-0.843D-1/T9,0.1555D-1*T12-0.269D-1
     #+0.43424534362958D-3*T3*T12-0.297768235631712D-2*T3)
      T20 = SQRT(SIGMABB)
      T22 = T3**2
      T24 = 0.2568D-2+0.1443307452126544D-1*T3+0.2843543831490386D-5*T22
      T28 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T22
     #+0.1763993811759022D-1*T2
      T29 = 1/T28
      T31 = 0.1667D-2+T24*T29
      T32 = 1/T31
      T33 = T20*T32
      T34 = RHOB**(1.D0/6.D0)
      T36 = 1/T34/RHOB
      T39 = EXP(-0.81290825D-3*T33*T36)
      T40 = T39*T31
      T41 = RHOB**(1.D0/3.D0)
      T43 = 1/T41/RHOB
      T44 = SIGMABB*T43
      ZK(I) = RHOB*T18+0.7937005259840997D0*T40*T44
      VRHOA(I) = 0.0D+00
      T47 = T9**2
      T48 = 1/T47
      T49 = T6**2
      T50 = T49**2
      T51 = T50*T6
      T52 = 1/T51
      T53 = RHOB**2
      T54 = 1/T53
      T57 = 1/T22
      T58 = T57*T54
      T60 = -0.1835293601259385D0*T52*T54-0.5399117105794445D-1*T58
      T64 = T57*T12
      T67 = T3*T2
      T71 = PIECEWISE(T7,0.843D-1*T48*T60,-0.5183333333333333D-2*T2
     #-0.1447484478765267D-3*T64*T54-0.1447484478765267D-3*T67
     #+0.99256078543904D-3*T58)
      T73 = T31**2
      T75 = T20/T73
      T77 = 1/T3
      T78 = T77*T54
      T80 = -0.4811024840421814D-2*T58-0.1895695887660258D-5*T78
      T82 = T28**2
      T83 = 1/T82
      T84 = T24*T83
      T88 = -0.1803772444038489D1*T58-0.1210946621972718D0*T78
     #-0.1763993811759022D-1*T54
      T91 = T80*T29-1.D0*T84*T88
      T96 = 1/T34/T53
      T99 = 0.81290825D-3*T75*T36*T91+0.9483929583333333D-3*T33*T96
      T100 = T99*T39
      T101 = T31*SIGMABB
      T102 = T101*T43
      T105 = T39*T91
      T109 = 1/T41/T53
      T110 = SIGMABB*T109
      VRHOB(I) = T18+RHOB*T71+0.7937005259840997D0*T100*T102
     #+0.7937005259840997D0*T105*T44-0.10582673679788D1*T40*T110
      VSIGMAAA(I) = 0.0D+00
      VSIGMAAB(I) = 0.0D+00
      T113 = SQRT(RHOB)
      T115 = 1/T113/T53
      VSIGMABB(I) = -0.322602852800907D-3*T20*T115*T39
     #+0.7937005259840997D0*T40*T43
      V2RHOA2(I) = 0.0D+00
      V2RHOAB(I) = 0.0D+00
      T124 = T60**2
      T129 = T53**2
      T130 = 1/T129
      T133 = T53*RHOB
      T134 = 1/T133
      T138 = 1/T22/T2
      T139 = T138*T130
      T141 = T57*T134
      T158 = PIECEWISE(T7,-0.1686D0/T47/T9*T124+0.843D-1*T48*(
     #-0.1529411334382821D0/T51/T2*T130+0.367058720251877D0*T52*T134
     #-0.3599411403862963D-1*T139+0.1079823421158889D0*T141
     #),0.5183333333333333D-2*T54-0.9649896525101778D-4*T138*T12*T130
     #-0.1888622605627062D-2*T141+0.2894968957530533D-3*T64*T134
     #+0.1447484478765267D-3*T3*T54+0.6617071902926934D-3*T139)
      T163 = T91**2
      T173 = 1/T67*T130
      T175 = T77*T134
      T185 = T88**2
      T196 = (-0.3207349893614542D-2*T139+0.9622049680843627D-2*T141
     #-0.6318986292200858D-6*T173+0.3791391775320515D-5*T175)*T29-2.D0
     #*T80*T83*T88+2.D0*T24/T82/T28*T185-1.D0*T84*(
     #-0.1202514962692326D1*T139+0.3607544888076978D1*T141
     #-0.4036488739909061D-1*T173+0.2421893243945437D0*T175
     #+0.3527987623518044D-1*T134)
      T208 = T99**2
      V2RHOB2(I) = 2.D0*T71+RHOB*T158+0.7937005259840997D0*(
     #-0.16258165D-2*T20/T73/T31*T36*T163-0.1896785916666667D-2*T75
     #*T96*T91+0.81290825D-3*T75*T36*T196-0.2054851409722222D-2*T33
     #/T34/T133)*T39*T102+0.7937005259840997D0*T208*T39*T102
     #+0.1587401051968199D1*T100*T91*SIGMABB*T43-0.2116534735957599D1
     #*T100*T101*T109+0.7937005259840997D0*T39*T196*T44
     #-0.2116534735957599D1*T105*T110+0.2469290525283866D1*T40*SIGMABB
     #/T41/T133
      V2SIGMAAA2(I) = 0.0D+00
      V2SIGMAAAAB(I) = 0.0D+00
      V2SIGMAAABB(I) = 0.0D+00
      V2SIGMAAB2(I) = 0.0D+00
      V2SIGMAABBB(I) = 0.0D+00
      T233 = T41**2
      V2SIGMABB2(I) = -0.4839042792013605D-3/T20*T115*T39
     #+0.1311232602576965D-6/T233/T133*T32*T39
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.0D+00,SIGMAAA1(I))
      SIGMA = SIGMAAA
      T2 = 1/RHOA
      T3 = T2**(1.D0/3.D0)
      T4 = 0.6203504908994D0*T3
      T7 = 1.D0 .LE. T4
      T6 = T2**(1.D0/6.D0)
      T9 = 1.D0+0.1101176160755631D1*T6+0.1619735131738333D0*T3
      T12 = LOG(T4)
      T18 = PIECEWISE(T7,-0.843D-1/T9,0.1555D-1*T12-0.269D-1
     #+0.43424534362958D-3*T3*T12-0.297768235631712D-2*T3)
      T20 = SQRT(SIGMAAA)
      T22 = T3**2
      T24 = 0.2568D-2+0.1443307452126544D-1*T3+0.2843543831490386D-5*T22
      T28 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T22
     #+0.1763993811759022D-1*T2
      T29 = 1/T28
      T31 = 0.1667D-2+T24*T29
      T32 = 1/T31
      T33 = T20*T32
      T34 = RHOA**(1.D0/6.D0)
      T36 = 1/T34/RHOA
      T39 = EXP(-0.81290825D-3*T33*T36)
      T40 = T39*T31
      T41 = RHOA**(1.D0/3.D0)
      T43 = 1/T41/RHOA
      T44 = SIGMAAA*T43
      ZK(I) = RHOA*T18+0.7937005259840997D0*T40*T44
      T47 = T9**2
      T48 = 1/T47
      T49 = T6**2
      T50 = T49**2
      T51 = T50*T6
      T52 = 1/T51
      T53 = RHOA**2
      T54 = 1/T53
      T57 = 1/T22
      T58 = T57*T54
      T60 = -0.1835293601259385D0*T52*T54-0.5399117105794445D-1*T58
      T64 = T57*T12
      T67 = T3*T2
      T71 = PIECEWISE(T7,0.843D-1*T48*T60,-0.5183333333333333D-2*T2
     #-0.1447484478765267D-3*T64*T54-0.1447484478765267D-3*T67
     #+0.99256078543904D-3*T58)
      T73 = T31**2
      T75 = T20/T73
      T77 = 1/T3
      T78 = T77*T54
      T80 = -0.4811024840421814D-2*T58-0.1895695887660258D-5*T78
      T82 = T28**2
      T83 = 1/T82
      T84 = T24*T83
      T88 = -0.1803772444038489D1*T58-0.1210946621972718D0*T78
     #-0.1763993811759022D-1*T54
      T91 = T80*T29-1.D0*T84*T88
      T96 = 1/T34/T53
      T99 = 0.81290825D-3*T75*T36*T91+0.9483929583333333D-3*T33*T96
      T100 = T99*T39
      T101 = T31*SIGMAAA
      T102 = T101*T43
      T105 = T39*T91
      T109 = 1/T41/T53
      T110 = SIGMAAA*T109
      VRHOA(I) = T18+RHOA*T71+0.7937005259840997D0*T100*T102
     #+0.7937005259840997D0*T105*T44-0.10582673679788D1*T40*T110
      VRHOB(I) = 0.0D+00
      T113 = SQRT(RHOA)
      T115 = 1/T113/T53
      VSIGMAAA(I) = -0.322602852800907D-3*T20*T115*T39
     #+0.7937005259840997D0*T40*T43
      VSIGMAAB(I) = 0.0D+00
      VSIGMABB(I) = 0.0D+00
      T124 = T60**2
      T129 = T53**2
      T130 = 1/T129
      T133 = T53*RHOA
      T134 = 1/T133
      T138 = 1/T22/T2
      T139 = T138*T130
      T141 = T57*T134
      T158 = PIECEWISE(T7,-0.1686D0/T47/T9*T124+0.843D-1*T48*(
     #-0.1529411334382821D0/T51/T2*T130+0.367058720251877D0*T52*T134
     #-0.3599411403862963D-1*T139+0.1079823421158889D0*T141
     #),0.5183333333333333D-2*T54-0.9649896525101778D-4*T138*T12*T130
     #-0.1888622605627062D-2*T141+0.2894968957530533D-3*T64*T134
     #+0.1447484478765267D-3*T3*T54+0.6617071902926934D-3*T139)
      T163 = T91**2
      T173 = 1/T67*T130
      T175 = T77*T134
      T185 = T88**2
      T196 = (-0.3207349893614542D-2*T139+0.9622049680843627D-2*T141
     #-0.6318986292200858D-6*T173+0.3791391775320515D-5*T175)*T29-2.D0
     #*T80*T83*T88+2.D0*T24/T82/T28*T185-1.D0*T84*(
     #-0.1202514962692326D1*T139+0.3607544888076978D1*T141
     #-0.4036488739909061D-1*T173+0.2421893243945437D0*T175
     #+0.3527987623518044D-1*T134)
      T208 = T99**2
      V2RHOA2(I) = 2.D0*T71+RHOA*T158+0.7937005259840997D0*(
     #-0.16258165D-2*T20/T73/T31*T36*T163-0.1896785916666667D-2*T75
     #*T96*T91+0.81290825D-3*T75*T36*T196-0.2054851409722222D-2*T33
     #/T34/T133)*T39*T102+0.7937005259840997D0*T208*T39*T102
     #+0.1587401051968199D1*T100*T91*SIGMAAA*T43-0.2116534735957599D1
     #*T100*T101*T109+0.7937005259840997D0*T39*T196*T44
     #-0.2116534735957599D1*T105*T110+0.2469290525283866D1*T40*SIGMAAA
     #/T41/T133
      V2RHOB2(I) = 0.0D+00
      V2RHOAB(I) = 0.0D+00
      T233 = T41**2
      V2SIGMAAA2(I) = -0.4839042792013605D-3/T20*T115*T39
     #+0.1311232602576965D-6/T233/T133*T32*T39
      V2SIGMAAAAB(I) = 0.0D+00
      V2SIGMAAABB(I) = 0.0D+00
      V2SIGMAAB2(I) = 0.0D+00
      V2SIGMAABBB(I) = 0.0D+00
      V2SIGMABB2(I) = 0.0D+00
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.0D+00,SIGMAAA1(I))
      SIGMAAB = SIGMAAB1(I)
      SIGMABB = MAX(0.0D+00,SIGMABB1(I))
      SIGMA = SIGMAAA+SIGMABB+2.D0*SIGMAAB
      T4 = 1/RHO
      T5 = T4**(1.D0/3.D0)
      T6 = 0.6203504908994D0*T5
      T7 = 1.D0 .LE. T6
      T8 = T4**(1.D0/6.D0)
      T11 = 1.D0+0.8292885914166397D0*T8+0.20682485366586D0*T5
      T13 = 0.1423D0/T11
      T16 = 1.D0+0.1101176160755631D1*T8+0.1619735131738333D0*T5
      T19 = -0.843D-1/T16+T13
      T21 = RHOA-1.D0*RHOB
      T22 = T21*T4
      T23 = 1.D0+T22
      T24 = T23**(1.D0/3.D0)
      T27 = 1.D0-1.D0*T22
      T28 = T27**(1.D0/3.D0)
      T30 = T24*T23+T28*T27-2.D0
      T34 = LOG(T6)
      T36 = T5*T34
      T42 = -0.1555D-1*T34+0.211D-1-0.80645563816922D-3*T36
     #+0.421838333811592D-2*T5
      T46 = PIECEWISE(T7,-T13+0.1923661050931536D1*T19*T30,0.311D-1
     #*T34-0.48D-1+0.12407009817988D-2*T36-0.719606569443304D-2*T5
     #+0.1923661050931536D1*T42*T30)
      T48 = SQRT(SIGMA)
      T50 = T5**2
      T52 = 0.2568D-2+0.1443307452126544D-1*T5+0.2843543831490386D-5*T50
      T56 = 1.D0+0.5411317332115466D1*T5+0.1816419932959077D0*T50
     #+0.1763993811759022D-1*T4
      T57 = 1/T56
      T59 = 0.1667D-2+T52*T57
      T60 = 1/T59
      T61 = T48*T60
      T62 = RHO**(1.D0/6.D0)
      T64 = 1/T62/RHO
      T67 = EXP(-0.81290825D-3*T61*T64)
      T68 = T67*T59
      T69 = RHO**(1.D0/3.D0)
      T71 = 1/T69/RHO
      T72 = SIGMA*T71
      T74 = 0.5D0+0.5D0*T22
      T75 = T74**(1.D0/3.D0)
      T76 = T75**2
      T79 = 0.5D0-0.5D0*T22
      T80 = T79**(1.D0/3.D0)
      T81 = T80**2
      T83 = T76*T74+T81*T79
      T84 = SQRT(T83)
      T85 = 1/T84
      T86 = T72*T85
      ZK(I) = RHO*T46+0.7937005259840997D0*T68*T86
      T93 = 0.1333333333333333D1*T24*T4-0.1333333333333333D1*T28*T4
      T98 = PIECEWISE(T7,0.1923661050931536D1*T19
     #*T93,0.1923661050931536D1*T42*T93)
      T100 = T68*SIGMA
      T102 = 1/T84/T83
      T103 = T71*T102
      T108 = 0.8333333333333333D0*T76*T4-0.8333333333333333D0*T81*T4
      T109 = T103*T108
      T112 = T11**2
      T113 = 1/T112
      T114 = T8**2
      T115 = T114**2
      T116 = T115*T8
      T117 = 1/T116
      T118 = RHO**2
      T119 = 1/T118
      T120 = T117*T119
      T122 = 1/T50
      T123 = T122*T119
      T125 = -0.1382147652361066D0*T120-0.6894161788861999D-1*T123
      T127 = 0.1423D0*T113*T125
      T128 = T16**2
      T129 = 1/T128
      T132 = -0.1835293601259385D0*T120-0.5399117105794445D-1*T123
      T135 = 0.843D-1*T129*T132-T127
      T138 = T24*T21
      T141 = T28*T21
      T144 = -0.1333333333333333D1*T138*T119+0.1333333333333333D1*T141
     #*T119
      T149 = T122*T34
      T150 = T149*T119
      T152 = T5*T4
      T159 = 0.5183333333333333D-2*T4+0.2688185460564067D-3*T150
     #+0.2688185460564067D-3*T152-0.1406127779371973D-2*T123
      T165 = PIECEWISE(T7,T127+0.1923661050931536D1*T135*T30
     #+0.1923661050931536D1*T19*T144,-0.1036666666666667D-1*T4
     #-0.4135669939329333D-3*T150-0.4135669939329333D-3*T152
     #+0.2398688564811013D-2*T123+0.1923661050931536D1*T159*T30
     #+0.1923661050931536D1*T42*T144)
      T166 = RHO*T165
      T167 = T59**2
      T168 = 1/T167
      T169 = T48*T168
      T171 = 1/T5
      T172 = T171*T119
      T174 = -0.4811024840421814D-2*T123-0.1895695887660258D-5*T172
      T176 = T56**2
      T177 = 1/T176
      T178 = T52*T177
      T182 = -0.1803772444038489D1*T123-0.1210946621972718D0*T172
     #-0.1763993811759022D-1*T119
      T185 = T174*T57-1.D0*T178*T182
      T186 = T64*T185
      T190 = 1/T62/T118
      T193 = 0.81290825D-3*T169*T186+0.9483929583333333D-3*T61*T190
      T194 = T193*T67
      T195 = T194*T59
      T197 = 0.7937005259840997D0*T195*T86
      T198 = T67*T185
      T200 = 0.7937005259840997D0*T198*T86
      T202 = 1/T69/T118
      T204 = SIGMA*T202*T85
      T206 = 0.10582673679788D1*T68*T204
      T207 = T76*T21
      T210 = T81*T21
      T213 = -0.8333333333333333D0*T207*T119+0.8333333333333333D0*T210
     #*T119
      T214 = T103*T213
      T216 = 0.3968502629920499D0*T100*T214
      VRHOA(I) = RHO*T98-0.3968502629920499D0*T100*T109+T46+T166+T197
     #+T200-T206-T216
      T217 = -T93
      T222 = PIECEWISE(T7,0.1923661050931536D1*T19
     #*T217,0.1923661050931536D1*T42*T217)
      T224 = -T108
      T225 = T103*T224
      VRHOB(I) = RHO*T222-0.3968502629920499D0*T100*T225+T46+T166+T197
     #+T200-T206-T216
      T228 = SQRT(RHO)
      T230 = 1/T228/T118
      T231 = T48*T230
      T232 = T67*T85
      T233 = T231*T232
      T235 = T71*T85
      T236 = T68*T235
      VSIGMAAA(I) = -0.322602852800907D-3*T233+0.7937005259840997D0*T236
      VSIGMAAB(I) = -0.645205705601814D-3*T233+0.1587401051968199D1*T236
      VSIGMABB(I) = VSIGMAAA(I)
      T240 = 2.D0*T165
      T244 = T185**2
      T252 = 1/T50/T4
      T253 = T118**2
      T254 = 1/T253
      T255 = T252*T254
      T257 = T118*RHO
      T258 = 1/T257
      T259 = T122*T258
      T262 = 1/T152*T254
      T264 = T171*T258
      T274 = T182**2
      T285 = (-0.3207349893614542D-2*T255+0.9622049680843627D-2*T259
     #-0.6318986292200858D-6*T262+0.3791391775320515D-5*T264)*T57-2.D0
     #*T174*T177*T182+2.D0*T52/T176/T56*T274-1.D0*T178*(
     #-0.1202514962692326D1*T255+0.3607544888076978D1*T259
     #-0.4036488739909061D-1*T262+0.2421893243945437D0*T264
     #+0.3527987623518044D-1*T258)
      T297 = 0.7937005259840997D0*(-0.16258165D-2*T48/T167/T59*T64
     #*T244-0.1896785916666667D-2*T169*T190*T185+0.81290825D-3*T169
     #*T64*T285-0.2054851409722222D-2*T61/T62/T257)*T67*T59*T86
      T298 = T193**2
      T302 = 0.7937005259840997D0*T298*T67*T59*T86
      T306 = 0.7937005259840997D0*T195*T72*T102*T213
      T308 = 0.2116534735957599D1*T195*T204
      T311 = 0.1587401051968199D1*T194*T185*T86
      T314 = 0.7937005259840997D0*T67*T285*T86
      T315 = T198*SIGMA
      T317 = 0.7937005259840997D0*T315*T214
      T319 = 0.2116534735957599D1*T198*T204
      T320 = T24**2
      T321 = 1/T320
      T324 = T28**2
      T325 = 1/T324
      T328 = 0.4444444444444444D0*T321*T119+0.4444444444444444D0*T325
     #*T119
      T333 = PIECEWISE(T7,0.1923661050931536D1*T19
     #*T328,0.1923661050931536D1*T42*T328)
      T334 = RHO*T333
      T335 = T83**2
      T338 = T71/T84/T335
      T339 = T108**2
      T343 = 1/T75
      T346 = 1/T80
      T349 = 0.2777777777777778D0*T343*T119+0.2777777777777778D0*T346
     #*T119
      T352 = 0.3968502629920499D0*T100*T103*T349
      T353 = T240+T297+T302-T306-T308+T311+T314-T317-T319+T334
     #+0.5952753944880748D0*T100*T338*T339-T352
      T355 = T202*T102
      T358 = 0.10582673679788D1*T100*T355*T213
      T364 = 0.2469290525283866D1*T68*SIGMA/T69/T257*T85
      T375 = -0.2777777777777778D0*T343*T21*T258-0.8333333333333333D0
     #*T76*T119-0.2777777777777778D0*T346*T21*T258
     #+0.8333333333333333D0*T81*T119
      T377 = T100*T103*T375
      T379 = T315*T109
      T383 = T195*T72*T102*T108
      T397 = -0.4444444444444444D0*T321*T21*T258-0.1333333333333333D1
     #*T24*T119-0.4444444444444444D0*T325*T21*T258
     #+0.1333333333333333D1*T28*T119
      T406 = PIECEWISE(T7,0.1923661050931536D1*T135*T93
     #+0.1923661050931536D1*T19*T397,0.1923661050931536D1*T159*T93
     #+0.1923661050931536D1*T42*T397)
      T407 = RHO*T406
      T411 = T100*T338*T213*T108
      T414 = T100*T355*T108
      T416 = T213**2
      T419 = 0.5952753944880748D0*T100*T338*T416
      T420 = T21**2
      T434 = 0.3968502629920499D0*T100*T103*(0.2777777777777778D0*T343
     #*T420*T254+0.1666666666666667D1*T207*T258+0.2777777777777778D0
     #*T346*T420*T254-0.1666666666666667D1*T210*T258)
      T437 = T125**2
      T439 = 0.2846D0/T112/T11*T437
      T442 = 1/T116/T4*T254
      T444 = T117*T258
      T450 = 0.1423D0*T113*(-0.1151789710300888D0*T442
     #+0.2764295304722132D0*T444-0.4596107859241333D-1*T255
     #+0.13788323577724D0*T259)
      T453 = T132**2
      T478 = 0.4444444444444444D0*T321*T420*T254+0.2666666666666667D1
     #*T138*T258+0.4444444444444444D0*T325*T420*T254
     #-0.2666666666666667D1*T141*T258
      T484 = T252*T34*T254
      T487 = T149*T258
      T489 = T5*T119
      T506 = PIECEWISE(T7,-T439+T450+0.1923661050931536D1*(-0.1686D0
     #/T128/T16*T453+0.843D-1*T129*(-0.1529411334382821D0*T442
     #+0.367058720251877D0*T444-0.3599411403862963D-1*T255
     #+0.1079823421158889D0*T259)+T439-T450)*T30+0.3847322101863073D1
     #*T135*T144+0.1923661050931536D1*T19*T478,0.1036666666666667D-1
     #*T119-0.2757113292886222D-3*T484-0.4521665800333405D-2*T259
     #+0.8271339878658667D-3*T487+0.4135669939329333D-3*T489
     #+0.1599125709874009D-2*T255+0.1923661050931536D1*(
     #-0.5183333333333333D-2*T119+0.1792123640376044D-3*T484
     #+0.2633043194706342D-2*T259-0.5376370921128133D-3*T487
     #-0.2688185460564067D-3*T489-0.9374185195813156D-3*T255)*T30
     #+0.3847322101863073D1*T159*T144+0.1923661050931536D1*T42*T478)
      T507 = RHO*T506
      T508 = 2.D0*T98+T358+T364-0.7937005259840997D0*T377
     #-0.7937005259840997D0*T379-0.7937005259840997D0*T383+2.D0*T407
     #+0.119055078897615D1*T411+0.10582673679788D1*T414+T419-T434+T507
      V2RHOA2(I) = T353+T508
      T510 = T224**2
      T516 = -T397
      T525 = PIECEWISE(T7,0.1923661050931536D1*T135*T217
     #+0.1923661050931536D1*T19*T516,0.1923661050931536D1*T159*T217
     #+0.1923661050931536D1*T42*T516)
      T526 = RHO*T525
      T530 = -T100*T103*T375
      T532 = T315*T225
      T534 = T240+T297+2.D0*T222+0.5952753944880748D0*T100*T338*T510
     #+T302-T306-T308+T311+T314+2.D0*T526-0.7937005259840997D0*T530
     #-0.7937005259840997D0*T532
      T536 = T100*T355*T224
      T540 = T100*T338*T213*T224
      T544 = T195*T72*T102*T224
      T546 = 0.10582673679788D1*T536+0.119055078897615D1*T540
     #-0.7937005259840997D0*T544-T317-T319+T334-T352+T358+T364+T419
     #-T434+T507
      V2RHOB2(I) = T534+T546
      T560 = -T328
      T565 = PIECEWISE(T7,0.1923661050931536D1*T19
     #*T560,0.1923661050931536D1*T42*T560)
      T567 = T526-0.3968502629920499D0*T530-0.3968502629920499D0*T532
     #+0.5291336839893998D0*T536+0.5952753944880748D0*T540
     #-0.3968502629920499D0*T544+0.3968502629920499D0*T100*T103*T349
     #+0.5952753944880748D0*T100*T338*T108*T224+T98+RHO*T565+T240+T222
     #+T297+T302-T306
      T573 = -T308+T311+T314-T319-T317+T358+T364-0.3968502629920499D0
     #*T377-0.3968502629920499D0*T379-0.3968502629920499D0*T383+T407
     #+0.5952753944880748D0*T411+T507+0.5291336839893998D0*T414-T434
     #+T419
      V2RHOAB(I) = T567+T573
      T574 = T67*T102
      T576 = T231*T574*T108
      T578 = T68*T109
      T580 = 1/T48
      T590 = (0.406454125D-3*T580*T168*T186+0.4741964791666667D-3*T580
     #*T60*T190)*T67*T59*T86
      T591 = 0.7937005259840997D0*T590
      T595 = T193*T48*T230*T67*T85
      T596 = 0.322602852800907D-3*T595
      T599 = T194*T59*T71*T85
      T600 = 0.7937005259840997D0*T599
      T603 = T61*T230*T198*T85
      T604 = 0.322602852800907D-3*T603
      T605 = T198*T235
      T606 = 0.7937005259840997D0*T605
      T610 = T48/T228/T257*T232
      T611 = 0.430137137067876D-3*T610
      T613 = T68*T202*T85
      T614 = 0.10582673679788D1*T613
      T616 = T231*T574*T213
      T617 = 0.1613014264004535D-3*T616
      T618 = T68*T214
      T619 = 0.3968502629920499D0*T618
      V2RHOASIGMAAA(I) = 0.1613014264004535D-3*T576
     #-0.3968502629920499D0*T578+T591-T596+T600-T604+T606+T611-T614
     #+T617-T619
      T622 = 0.1587401051968199D1*T590
      T623 = 0.645205705601814D-3*T595
      T624 = 0.1587401051968199D1*T599
      T625 = 0.645205705601814D-3*T603
      T626 = 0.1587401051968199D1*T605
      T627 = 0.8602742741357521D-3*T610
      T628 = 0.2116534735957599D1*T613
      T629 = 0.322602852800907D-3*T616
      T630 = 0.7937005259840997D0*T618
      V2RHOASIGMAAB(I) = 0.322602852800907D-3*T576
     #-0.7937005259840997D0*T578+T622-T623+T624-T625+T626+T627-T628
     #+T629-T630
      V2RHOASIGMABB(I) = V2RHOASIGMAAA(I)
      T632 = T231*T574*T224
      T634 = T68*T225
      V2RHOBSIGMAAA(I) = 0.1613014264004535D-3*T632
     #-0.3968502629920499D0*T634+T591-T596+T600-T604+T606+T611-T614
     #+T617-T619
      V2RHOBSIGMAAB(I) = 0.322602852800907D-3*T632
     #-0.7937005259840997D0*T634+T622-T623+T624-T625+T626+T627-T628
     #+T629-T630
      V2RHOBSIGMABB(I) = V2RHOBSIGMAAA(I)
      T639 = T580*T230*T232
      T641 = T69**2
      T645 = 1/T641/T257*T60*T232
      V2SIGMAAA2(I) = -0.4839042792013605D-3*T639
     #+0.1311232602576965D-6*T645
      V2SIGMAAAAB(I) = -0.9678085584027211D-3*T639
     #+0.2622465205153929D-6*T645
      V2SIGMAAABB(I) = V2SIGMAAA2(I)
      V2SIGMAAB2(I) = -0.1935617116805442D-2*T639
     #+0.5244930410307859D-6*T645
      V2SIGMAABBB(I) = V2SIGMAAAAB(I)
      V2SIGMABB2(I) = V2SIGMAAABB(I)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      V2RHOB2(I) = 0.0D0
      V2RHOAB(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      VSIGMAAB(I) = 0.0D0
      VSIGMABB(I) = 0.0D0
      V2RHOASIGMAAA(I) = 0.0D0
      V2RHOASIGMAAB(I) = 0.0D0
      V2RHOASIGMABB(I) = 0.0D0
      V2RHOBSIGMAAA(I) = 0.0D0
      V2RHOBSIGMAAB(I) = 0.0D0
      V2RHOBSIGMABB(I) = 0.0D0
      V2SIGMAAA2(I) = 0.0D0
      V2SIGMAAB2(I) = 0.0D0
      V2SIGMABB2(I) = 0.0D0
      V2SIGMAAAAB(I) = 0.0D0
      V2SIGMAAABB(I) = 0.0D0
      V2SIGMAABBB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C*MODULE DFTXCB  *DECK RKS_C_P86
      SUBROUTINE RKS_C_P86
     & (IDERIV,NPT,RHOA1,SIGMAAA1,
     &  ZK,VRHOA,VSIGMAAA,
     &  V2RHOA2,V2RHOASIGMAAA,V2SIGMAAA2)
C
C     J.P. PERDEW
C     DENSITY-FUNCTIONAL APPROXIMATION FOR THE CORRELATION ENERGY OF
C     THE INHOMOGENEOUS ELECTRON GAS
C     PHYS. REV. B33 (1986) 8822-8824
C
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      INTEGER IDERIV,NPT
      DOUBLE PRECISION RHOA1(NPT)
      DOUBLE PRECISION SIGMAAA1(NPT)
      DOUBLE PRECISION ZK(NPT),VRHOA(NPT),VSIGMAAA(NPT)
      DOUBLE PRECISION V2RHOA2(NPT),V2RHOASIGMAAA(NPT),V2SIGMAAA2(NPT)
      PARAMETER(TOL=1.0D-20)
      LOGICAL T5
C
      IF(IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHO = MAX(0.0D+00,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.0D+00,SIGMAAA1(I))
      T2 = 1/RHO
      T3 = T2**(1.D0/3.D0)
      T4 = 0.6203504908994D0*T3
      T6 = T2**(1.D0/6.D0)
      T12 = LOG(T4)
      T18 = PIECEWISE(1.D0 .LE. T4,-0.1423D0/(1.D0
     #+0.8292885914166397D0*T6+0.20682485366586D0*T3),0.311D-1*T12
     #-0.48D-1+0.12407009817988D-2*T3*T12-0.719606569443304D-2*T3)
      T20 = SQRT(SIGMA)
      T22 = T3**2
      T31 = 0.1667D-2+(0.2568D-2+0.1443307452126544D-1*T3
     #+0.2843543831490386D-5*T22)/(1.D0+0.5411317332115466D1*T3
     #+0.1816419932959077D0*T22+0.1763993811759022D-1*T2)
      T34 = RHO**(1.D0/6.D0)
      T39 = EXP(-0.81290825D-3*T20/T31/T34/RHO)
      T41 = RHO**(1.D0/3.D0)
      ZK(I) = RHO*T18+0.1D1*T39*T31*SIGMA/T41/RHO
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHO = MAX(0.0D+00,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.0D+00,SIGMAAA1(I))
      T2 = 1/RHO
      T3 = T2**(1.D0/3.D0)
      T4 = 0.6203504908994D0*T3
      T5 = 1.D0 .LE. T4
      T6 = T2**(1.D0/6.D0)
      T9 = 1.D0+0.8292885914166397D0*T6+0.20682485366586D0*T3
      T12 = LOG(T4)
      T18 = PIECEWISE(T5,-0.1423D0/T9,0.311D-1*T12-0.48D-1
     #+0.12407009817988D-2*T3*T12-0.719606569443304D-2*T3)
      T20 = SQRT(SIGMA)
      T22 = T3**2
      T24 = 0.2568D-2+0.1443307452126544D-1*T3+0.2843543831490386D-5*T22
      T28 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T22
     #+0.1763993811759022D-1*T2
      T29 = 1/T28
      T31 = 0.1667D-2+T24*T29
      T33 = T20/T31
      T34 = RHO**(1.D0/6.D0)
      T36 = 1/T34/RHO
      T39 = EXP(-0.81290825D-3*T33*T36)
      T40 = T39*T31
      T41 = RHO**(1.D0/3.D0)
      T43 = 1/T41/RHO
      T44 = SIGMA*T43
      ZK(I) = RHO*T18+0.1D1*T40*T44
      T47 = PIECEWISE(T5,0.0D+00,0.0D+00)
      T49 = T9**2
      T51 = T6**2
      T52 = T51**2
      T55 = RHO**2
      T56 = 1/T55
      T59 = 1/T22
      T60 = T59*T56
      T73 = PIECEWISE(T5,0.1423D0/T49*(-0.1382147652361066D0/T52/T6
     #*T56-0.6894161788861999D-1*T60),-0.1036666666666667D-1*T2
     #-0.4135669939329333D-3*T59*T12*T56-0.4135669939329333D-3*T3*T2
     #+0.2398688564811013D-2*T60)
      T75 = T31**2
      T80 = 1/T3*T56
      T84 = T28**2
      T93 = (-0.4811024840421814D-2*T60-0.1895695887660258D-5*T80)*T29
     #-1.D0*T24/T84*(-0.1803772444038489D1*T60-0.1210946621972718D0
     #*T80-0.1763993811759022D-1*T56)
      VRHOA(I) = RHO*T47+T18+RHO*T73+0.1D1*(0.81290825D-3*T20/T75*T36
     #*T93+0.9483929583333333D-3*T33/T34/T55)*T39*T31*SIGMA*T43+0.1D1
     #*T39*T93*T44-0.1333333333333333D1*T40*SIGMA/T41/T55
      T115 = SQRT(RHO)
      VSIGMAAA(I) = -0.16258165D-2*T20/T115/T55*T39+0.4D1*T40*T43
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHO = MAX(0.0D+00,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.0D+00,SIGMAAA1(I))
      T2 = 1/RHO
      T3 = T2**(1.D0/3.D0)
      T4 = 0.6203504908994D0*T3
      T5 = 1.D0 .LE. T4
      T6 = T2**(1.D0/6.D0)
      T9 = 1.D0+0.8292885914166397D0*T6+0.20682485366586D0*T3
      T11 = 0.1423D0/T9
      T12 = LOG(T4)
      T14 = T3*T12
      T18 = PIECEWISE(T5,-T11,0.311D-1*T12-0.48D-1+0.12407009817988D-2
     #*T14-0.719606569443304D-2*T3)
      T20 = SQRT(SIGMA)
      T22 = T3**2
      T24 = 0.2568D-2+0.1443307452126544D-1*T3+0.2843543831490386D-5*T22
      T28 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T22
     #+0.1763993811759022D-1*T2
      T29 = 1/T28
      T31 = 0.1667D-2+T24*T29
      T32 = 1/T31
      T33 = T20*T32
      T34 = RHO**(1.D0/6.D0)
      T36 = 1/T34/RHO
      T39 = EXP(-0.81290825D-3*T33*T36)
      T40 = T39*T31
      T41 = RHO**(1.D0/3.D0)
      T43 = 1/T41/RHO
      T44 = SIGMA*T43
      ZK(I) = RHO*T18+0.1D1*T40*T44
      T47 = PIECEWISE(T5,0.0D+00,0.0D+00)
      T48 = RHO*T47
      T49 = T9**2
      T50 = 1/T49
      T51 = T6**2
      T52 = T51**2
      T53 = T52*T6
      T54 = 1/T53
      T55 = RHO**2
      T56 = 1/T55
      T59 = 1/T22
      T60 = T59*T56
      T62 = -0.1382147652361066D0*T54*T56-0.6894161788861999D-1*T60
      T66 = T59*T12
      T69 = T3*T2
      T73 = PIECEWISE(T5,0.1423D0*T50*T62,-0.1036666666666667D-1*T2
     #-0.4135669939329333D-3*T66*T56-0.4135669939329333D-3*T69
     #+0.2398688564811013D-2*T60)
      T75 = T31**2
      T76 = 1/T75
      T77 = T20*T76
      T79 = 1/T3
      T80 = T79*T56
      T82 = -0.4811024840421814D-2*T60-0.1895695887660258D-5*T80
      T84 = T28**2
      T85 = 1/T84
      T86 = T24*T85
      T90 = -0.1803772444038489D1*T60-0.1210946621972718D0*T80
     #-0.1763993811759022D-1*T56
      T93 = T82*T29-1.D0*T86*T90
      T94 = T36*T93
      T98 = 1/T34/T55
      T101 = 0.81290825D-3*T77*T94+0.9483929583333333D-3*T33*T98
      T102 = T101*T39
      T103 = T31*SIGMA
      T104 = T103*T43
      T107 = T39*T93
      T111 = 1/T41/T55
      T112 = SIGMA*T111
      VRHOA(I) = T48+T18+RHO*T73+0.1D1*T102*T104+0.1D1*T107*T44
     #-0.1333333333333333D1*T40*T112
      T115 = SQRT(RHO)
      T117 = 1/T115/T55
      VSIGMAAA(I) = -0.16258165D-2*T20*T117*T39+0.4D1*T40*T43
      T129 = (-0.843D-1/(1.D0+0.1101176160755631D1*T6
     #+0.1619735131738333D0*T3)+T11)*T56
      T135 = (-0.1555D-1*T12+0.211D-1-0.80645563816922D-3*T14
     #+0.421838333811592D-2*T3)*T56
      T137 = PIECEWISE(T5,0.1709920934161366D1
     #*T129,0.1709920934161366D1*T135)
      T139 = T55*RHO
      T147 = T62**2
      T152 = T55**2
      T153 = 1/T152
      T156 = 1/T139
      T160 = 1/T22/T2
      T161 = T160*T153
      T163 = T59*T156
      T180 = PIECEWISE(T5,-0.2846D0/T49/T9*T147+0.1423D0*T50*(
     #-0.1151789710300888D0/T53/T2*T153+0.2764295304722132D0*T54*T156
     #-0.4596107859241333D-1*T161+0.13788323577724D0*T163
     #),0.1036666666666667D-1*T56-0.2757113292886222D-3*T160*T12*T153
     #-0.4521665800333405D-2*T163+0.8271339878658667D-3*T66*T156
     #+0.4135669939329333D-3*T3*T56+0.1599125709874009D-2*T161)
      T185 = PIECEWISE(T5,-0.1709920934161366D1*T129,
     #-0.1709920934161366D1*T135)
      T193 = T93**2
      T203 = 1/T69*T153
      T205 = T79*T156
      T215 = T90**2
      T226 = (-0.3207349893614542D-2*T161+0.9622049680843627D-2*T163
     #-0.6318986292200858D-6*T203+0.3791391775320515D-5*T205)*T29-2.D0
     #*T82*T85*T90+2.D0*T24/T84/T28*T215-1.D0*T86*(
     #-0.1202514962692326D1*T161+0.3607544888076978D1*T163
     #-0.4036488739909061D-1*T203+0.2421893243945437D0*T205
     #+0.3527987623518044D-1*T156)
      T247 = T101**2
      V2RHOA2(I) = RHO*T137+0.6222222222222222D1*T40*SIGMA/T41/T139
     #+2.D0*RHO*T180+RHO*T185-0.5333333333333333D1*T102*T103*T111
     #+0.2D1*(-0.16258165D-2*T20/T75/T31*T36*T193
     #-0.1896785916666667D-2*T77*T98*T93+0.81290825D-3*T77*T36*T226
     #-0.2054851409722222D-2*T33/T34/T139)*T39*T104+0.4D1*T102*T93
     #*SIGMA*T43+0.2D1*T39*T226*T44-0.5333333333333333D1*T107*T112
     #+0.2D1*T247*T39*T104+4.D0*T48+4.D0*T47+4.D0*T73
      T254 = 1/T20
      T266 = T117*T39
      V2RHOASIGMAAA(I) = 0.4D1*(0.406454125D-3*T254*T76*T94
     #+0.4741964791666667D-3*T254*T32*T98)*T39*T104-0.16258165D-2*T101
     #*T20*T266+0.4D1*T102*T31*T43-0.16258165D-2*T33*T266*T93+0.4D1
     #*T107*T43+0.2167755333333333D-2*T20/T115/T139*T39
     #-0.5333333333333333D1*T40*T111
      T287 = T41**2
      V2SIGMAAA2(I) = -0.9754899D-2*T254*T117*T39+0.264327929167225D-5
     #/T287/T139*T32*T39
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      V2RHOASIGMAAA(I) = 0.0D0
      V2SIGMAAA2(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C*MODULE DFTXCB  *DECK UKS_C_PZ81
      SUBROUTINE UKS_C_PZ81(IDERIV,NPT,RHOA1,RHOB1,ZK,VRHOA,VRHOB,
     *                      V2RHOA2,V2RHOB2,V2RHOAB)
C
C     J.P. PERDEW, AND A. ZUNGER
C     SELF-INTERACTION CORRECTION TO DENSITY-FUNCTIONAL APPROXIMATIONS
C     FOR MANY-ELECTRON SYSTEMS
C     PHYS. REV. B23 (1981) 5048-5079
C
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      INTEGER IDERIV,NPT
      DOUBLE PRECISION RHOA1(NPT),RHOB1(NPT)
      DOUBLE PRECISION ZK(NPT),VRHOA(NPT),VRHOB(NPT)
      DOUBLE PRECISION V2RHOA2(NPT),V2RHOB2(NPT),V2RHOAB(NPT)
      PARAMETER(TOL=1.0D-20)
      LOGICAL T4
C
      IF (IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.0D+00,RHOA1(I))
      RHOB = MAX(0.0D+00,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      T1 = 1/RHOB
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T5 = T1**(1.D0/6.D0)
      T11 = LOG(T3)
      T17 = PIECEWISE(1.D0 .LE. T3,-0.843D-1/(1.D0
     #+0.1101176160755631D1*T5+0.1619735131738333D0*T2),0.1555D-1*T11
     #-0.269D-1+0.43424534362958D-3*T2*T11-0.297768235631712D-2*T2)
      ZK(I) = RHOB*T17
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      T1 = 1/RHOA
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T5 = T1**(1.D0/6.D0)
      T11 = LOG(T3)
      T17 = PIECEWISE(1.D0 .LE. T3,-0.843D-1/(1.D0
     #+0.1101176160755631D1*T5+0.1619735131738333D0*T2),0.1555D-1*T11
     #-0.269D-1+0.43424534362958D-3*T2*T11-0.297768235631712D-2*T2)
      ZK(I) = RHOA*T17
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T5 = T1**(1.D0/6.D0)
      T10 = 0.1423D0/(1.D0+0.8292885914166397D0*T5+0.20682485366586D0
     #*T2)
      T19 = (RHOA-1.D0*RHOB)*T1
      T20 = 1.D0+T19
      T21 = T20**(1.D0/3.D0)
      T24 = 1.D0-1.D0*T19
      T25 = T24**(1.D0/3.D0)
      T27 = T21*T20+T25*T24-2.D0
      T31 = LOG(T3)
      T33 = T2*T31
      T43 = PIECEWISE(1.D0 .LE. T3,-T10+0.1923661050931536D1*(
     #-0.843D-1/(1.D0+0.1101176160755631D1*T5+0.1619735131738333D0*T2)
     #+T10)*T27,0.311D-1*T31-0.48D-1+0.12407009817988D-2*T33
     #-0.719606569443304D-2*T2+0.1923661050931536D1*(-0.1555D-1*T31
     #+0.211D-1-0.80645563816922D-3*T33+0.421838333811592D-2*T2)*T27)
      ZK(I) = RHO*T43
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.0D+00,RHOA1(I))
      RHOB = MAX(0.0D+00,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      T1 = 1/RHOB
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T4 = 1.D0 .LE. T3
      T5 = T1**(1.D0/6.D0)
      T8 = 1.D0+0.1101176160755631D1*T5+0.1619735131738333D0*T2
      T11 = LOG(T3)
      T17 = PIECEWISE(T4,-0.843D-1/T8,0.1555D-1*T11-0.269D-1
     #+0.43424534362958D-3*T2*T11-0.297768235631712D-2*T2)
      ZK(I) = RHOB*T17
      VRHOA(I) = 0.0D+00
      T18 = T8**2
      T20 = T5**2
      T21 = T20**2
      T24 = RHOB**2
      T25 = 1/T24
      T28 = T2**2
      T29 = 1/T28
      T30 = T29*T25
      T43 = PIECEWISE(T4,0.843D-1/T18*(-0.1835293601259385D0/T21/T5
     #*T25-0.5399117105794445D-1*T30),-0.5183333333333333D-2*T1
     #-0.1447484478765267D-3*T29*T11*T25-0.1447484478765267D-3*T2*T1
     #+0.99256078543904D-3*T30)
      VRHOB(I) = T17+RHOB*T43
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      T1 = 1/RHOA
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T4 = 1.D0 .LE. T3
      T5 = T1**(1.D0/6.D0)
      T8 = 1.D0+0.1101176160755631D1*T5+0.1619735131738333D0*T2
      T11 = LOG(T3)
      T17 = PIECEWISE(T4,-0.843D-1/T8,0.1555D-1*T11-0.269D-1
     #+0.43424534362958D-3*T2*T11-0.297768235631712D-2*T2)
      ZK(I) = RHOA*T17
      T18 = T8**2
      T20 = T5**2
      T21 = T20**2
      T24 = RHOA**2
      T25 = 1/T24
      T28 = T2**2
      T29 = 1/T28
      T30 = T29*T25
      T43 = PIECEWISE(T4,0.843D-1/T18*(-0.1835293601259385D0/T21/T5
     #*T25-0.5399117105794445D-1*T30),-0.5183333333333333D-2*T1
     #-0.1447484478765267D-3*T29*T11*T25-0.1447484478765267D-3*T2*T1
     #+0.99256078543904D-3*T30)
      VRHOA(I) = T17+RHOA*T43
      VRHOB(I) = 0.0D+00
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T4 = 1.D0 .LE. T3
      T5 = T1**(1.D0/6.D0)
      T8 = 1.D0+0.8292885914166397D0*T5+0.20682485366586D0*T2
      T10 = 0.1423D0/T8
      T13 = 1.D0+0.1101176160755631D1*T5+0.1619735131738333D0*T2
      T16 = -0.843D-1/T13+T10
      T18 = RHOA-1.D0*RHOB
      T19 = T18*T1
      T20 = 1.D0+T19
      T21 = T20**(1.D0/3.D0)
      T24 = 1.D0-1.D0*T19
      T25 = T24**(1.D0/3.D0)
      T27 = T21*T20+T25*T24-2.D0
      T31 = LOG(T3)
      T33 = T2*T31
      T39 = -0.1555D-1*T31+0.211D-1-0.80645563816922D-3*T33
     #+0.421838333811592D-2*T2
      T43 = PIECEWISE(T4,-T10+0.1923661050931536D1*T16*T27,0.311D-1
     #*T31-0.48D-1+0.12407009817988D-2*T33-0.719606569443304D-2*T2
     #+0.1923661050931536D1*T39*T27)
      ZK(I) = RHO*T43
      T48 = 0.1333333333333333D1*T21*T1-0.1333333333333333D1*T25*T1
      T53 = PIECEWISE(T4,0.1923661050931536D1*T16
     #*T48,0.1923661050931536D1*T39*T48)
      T55 = T8**2
      T57 = T5**2
      T58 = T57**2
      T61 = RHO**2
      T62 = 1/T61
      T63 = 1/T58/T5*T62
      T65 = T2**2
      T66 = 1/T65
      T67 = T66*T62
      T71 = 0.1423D0/T55*(-0.1382147652361066D0*T63
     #-0.6894161788861999D-1*T67)
      T72 = T13**2
      T88 = -0.1333333333333333D1*T21*T18*T62+0.1333333333333333D1*T25
     #*T18*T62
      T94 = T66*T31*T62
      T96 = T2*T1
      T109 = PIECEWISE(T4,T71+0.1923661050931536D1*(0.843D-1/T72*(
     #-0.1835293601259385D0*T63-0.5399117105794445D-1*T67)-T71)*T27
     #+0.1923661050931536D1*T16*T88,-0.1036666666666667D-1*T1
     #-0.4135669939329333D-3*T94-0.4135669939329333D-3*T96
     #+0.2398688564811013D-2*T67+0.1923661050931536D1*
     #(0.5183333333333333D-2*T1+0.2688185460564067D-3*T94
     #+0.2688185460564067D-3*T96-0.1406127779371973D-2*T67)*T27
     #+0.1923661050931536D1*T39*T88)
      T110 = RHO*T109
      VRHOA(I) = RHO*T53+T43+T110
      T111 = -T48
      T116 = PIECEWISE(T4,0.1923661050931536D1*T16
     #*T111,0.1923661050931536D1*T39*T111)
      VRHOB(I) = RHO*T116+T43+T110
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.0D+00,RHOA1(I))
      RHOB = MAX(0.0D+00,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      T1 = 1/RHOB
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T4 = 1.D0 .LE. T3
      T5 = T1**(1.D0/6.D0)
      T8 = 1.D0+0.1101176160755631D1*T5+0.1619735131738333D0*T2
      T11 = LOG(T3)
      T17 = PIECEWISE(T4,-0.843D-1/T8,0.1555D-1*T11-0.269D-1
     #+0.43424534362958D-3*T2*T11-0.297768235631712D-2*T2)
      ZK(I) = RHOB*T17
      VRHOA(I) = 0.0D+00
      T18 = T8**2
      T19 = 1/T18
      T20 = T5**2
      T21 = T20**2
      T22 = T21*T5
      T23 = 1/T22
      T24 = RHOB**2
      T25 = 1/T24
      T28 = T2**2
      T29 = 1/T28
      T30 = T29*T25
      T32 = -0.1835293601259385D0*T23*T25-0.5399117105794445D-1*T30
      T36 = T29*T11
      T43 = PIECEWISE(T4,0.843D-1*T19*T32,-0.5183333333333333D-2*T1
     #-0.1447484478765267D-3*T36*T25-0.1447484478765267D-3*T2*T1
     #+0.99256078543904D-3*T30)
      VRHOB(I) = T17+RHOB*T43
      V2RHOA2(I) = 0.0D+00
      V2RHOAB(I) = 0.0D+00
      T48 = T32**2
      T53 = T24**2
      T54 = 1/T53
      T58 = 1/T24/RHOB
      T62 = 1/T28/T1
      T63 = T62*T54
      T65 = T29*T58
      T82 = PIECEWISE(T4,-0.1686D0/T18/T8*T48+0.843D-1*T19*(
     #-0.1529411334382821D0/T22/T1*T54+0.367058720251877D0*T23*T58
     #-0.3599411403862963D-1*T63+0.1079823421158889D0*T65
     #),0.5183333333333333D-2*T25-0.9649896525101778D-4*T62*T11*T54
     #-0.1888622605627062D-2*T65+0.2894968957530533D-3*T36*T58
     #+0.1447484478765267D-3*T2*T25+0.6617071902926934D-3*T63)
      V2RHOB2(I) = 2.D0*T43+RHOB*T82
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      T1 = 1/RHOA
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T4 = 1.D0 .LE. T3
      T5 = T1**(1.D0/6.D0)
      T8 = 1.D0+0.1101176160755631D1*T5+0.1619735131738333D0*T2
      T11 = LOG(T3)
      T17 = PIECEWISE(T4,-0.843D-1/T8,0.1555D-1*T11-0.269D-1
     #+0.43424534362958D-3*T2*T11-0.297768235631712D-2*T2)
      ZK(I) = RHOA*T17
      T18 = T8**2
      T19 = 1/T18
      T20 = T5**2
      T21 = T20**2
      T22 = T21*T5
      T23 = 1/T22
      T24 = RHOA**2
      T25 = 1/T24
      T28 = T2**2
      T29 = 1/T28
      T30 = T29*T25
      T32 = -0.1835293601259385D0*T23*T25-0.5399117105794445D-1*T30
      T36 = T29*T11
      T43 = PIECEWISE(T4,0.843D-1*T19*T32,-0.5183333333333333D-2*T1
     #-0.1447484478765267D-3*T36*T25-0.1447484478765267D-3*T2*T1
     #+0.99256078543904D-3*T30)
      VRHOA(I) = T17+RHOA*T43
      VRHOB(I) = 0.0D+00
      T48 = T32**2
      T53 = T24**2
      T54 = 1/T53
      T58 = 1/T24/RHOA
      T62 = 1/T28/T1
      T63 = T62*T54
      T65 = T29*T58
      T82 = PIECEWISE(T4,-0.1686D0/T18/T8*T48+0.843D-1*T19*(
     #-0.1529411334382821D0/T22/T1*T54+0.367058720251877D0*T23*T58
     #-0.3599411403862963D-1*T63+0.1079823421158889D0*T65
     #),0.5183333333333333D-2*T25-0.9649896525101778D-4*T62*T11*T54
     #-0.1888622605627062D-2*T65+0.2894968957530533D-3*T36*T58
     #+0.1447484478765267D-3*T2*T25+0.6617071902926934D-3*T63)
      V2RHOA2(I) = 2.D0*T43+RHOA*T82
      V2RHOB2(I) = 0.0D+00
      V2RHOAB(I) = 0.0D+00
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T4 = 1.D0 .LE. T3
      T5 = T1**(1.D0/6.D0)
      T8 = 1.D0+0.8292885914166397D0*T5+0.20682485366586D0*T2
      T10 = 0.1423D0/T8
      T13 = 1.D0+0.1101176160755631D1*T5+0.1619735131738333D0*T2
      T16 = -0.843D-1/T13+T10
      T18 = RHOA-1.D0*RHOB
      T19 = T18*T1
      T20 = 1.D0+T19
      T21 = T20**(1.D0/3.D0)
      T24 = 1.D0-1.D0*T19
      T25 = T24**(1.D0/3.D0)
      T27 = T21*T20+T25*T24-2.D0
      T31 = LOG(T3)
      T33 = T2*T31
      T39 = -0.1555D-1*T31+0.211D-1-0.80645563816922D-3*T33
     #+0.421838333811592D-2*T2
      T43 = PIECEWISE(T4,-T10+0.1923661050931536D1*T16*T27,0.311D-1
     #*T31-0.48D-1+0.12407009817988D-2*T33-0.719606569443304D-2*T2
     #+0.1923661050931536D1*T39*T27)
      ZK(I) = RHO*T43
      T48 = 0.1333333333333333D1*T21*T1-0.1333333333333333D1*T25*T1
      T53 = PIECEWISE(T4,0.1923661050931536D1*T16
     #*T48,0.1923661050931536D1*T39*T48)
      T55 = T8**2
      T56 = 1/T55
      T57 = T5**2
      T58 = T57**2
      T59 = T58*T5
      T60 = 1/T59
      T61 = RHO**2
      T62 = 1/T61
      T63 = T60*T62
      T65 = T2**2
      T66 = 1/T65
      T67 = T66*T62
      T69 = -0.1382147652361066D0*T63-0.6894161788861999D-1*T67
      T71 = 0.1423D0*T56*T69
      T72 = T13**2
      T73 = 1/T72
      T76 = -0.1835293601259385D0*T63-0.5399117105794445D-1*T67
      T79 = 0.843D-1*T73*T76-T71
      T82 = T21*T18
      T85 = T25*T18
      T88 = -0.1333333333333333D1*T82*T62+0.1333333333333333D1*T85*T62
      T93 = T66*T31
      T94 = T93*T62
      T96 = T2*T1
      T103 = 0.5183333333333333D-2*T1+0.2688185460564067D-3*T94
     #+0.2688185460564067D-3*T96-0.1406127779371973D-2*T67
      T109 = PIECEWISE(T4,T71+0.1923661050931536D1*T79*T27
     #+0.1923661050931536D1*T16*T88,-0.1036666666666667D-1*T1
     #-0.4135669939329333D-3*T94-0.4135669939329333D-3*T96
     #+0.2398688564811013D-2*T67+0.1923661050931536D1*T103*T27
     #+0.1923661050931536D1*T39*T88)
      T110 = RHO*T109
      VRHOA(I) = RHO*T53+T43+T110
      T111 = -T48
      T116 = PIECEWISE(T4,0.1923661050931536D1*T16
     #*T111,0.1923661050931536D1*T39*T111)
      VRHOB(I) = RHO*T116+T43+T110
      T118 = T21**2
      T119 = 1/T118
      T122 = T25**2
      T123 = 1/T122
      T126 = 0.4444444444444444D0*T119*T62+0.4444444444444444D0*T123*T62
      T131 = PIECEWISE(T4,0.1923661050931536D1*T16
     #*T126,0.1923661050931536D1*T39*T126)
      T132 = RHO*T131
      T138 = 1/T61/RHO
      T148 = -0.4444444444444444D0*T119*T18*T138-0.1333333333333333D1
     #*T21*T62-0.4444444444444444D0*T123*T18*T138+0.1333333333333333D1
     #*T25*T62
      T157 = PIECEWISE(T4,0.1923661050931536D1*T79*T48
     #+0.1923661050931536D1*T16*T148,0.1923661050931536D1*T103*T48
     #+0.1923661050931536D1*T39*T148)
      T158 = RHO*T157
      T160 = 2.D0*T109
      T163 = T69**2
      T165 = 0.2846D0/T55/T8*T163
      T168 = T61**2
      T169 = 1/T168
      T170 = 1/T59/T1*T169
      T172 = T60*T138
      T175 = 1/T65/T1
      T176 = T175*T169
      T178 = T66*T138
      T182 = 0.1423D0*T56*(-0.1151789710300888D0*T170
     #+0.2764295304722132D0*T172-0.4596107859241333D-1*T176
     #+0.13788323577724D0*T178)
      T185 = T76**2
      T200 = T18**2
      T211 = 0.4444444444444444D0*T119*T200*T169+0.2666666666666667D1
     #*T82*T138+0.4444444444444444D0*T123*T200*T169
     #-0.2666666666666667D1*T85*T138
      T217 = T175*T31*T169
      T220 = T93*T138
      T222 = T2*T62
      T239 = PIECEWISE(T4,-T165+T182+0.1923661050931536D1*(-0.1686D0
     #/T72/T13*T185+0.843D-1*T73*(-0.1529411334382821D0*T170
     #+0.367058720251877D0*T172-0.3599411403862963D-1*T176
     #+0.1079823421158889D0*T178)+T165-T182)*T27+0.3847322101863073D1
     #*T79*T88+0.1923661050931536D1*T16*T211,0.1036666666666667D-1*T62
     #-0.2757113292886222D-3*T217-0.4521665800333405D-2*T178
     #+0.8271339878658667D-3*T220+0.4135669939329333D-3*T222
     #+0.1599125709874009D-2*T176+0.1923661050931536D1*(
     #-0.5183333333333333D-2*T62+0.1792123640376044D-3*T217
     #+0.2633043194706342D-2*T178-0.5376370921128133D-3*T220
     #-0.2688185460564067D-3*T222-0.9374185195813156D-3*T176)*T27
     #+0.3847322101863073D1*T103*T88+0.1923661050931536D1*T39*T211)
      T240 = RHO*T239
      V2RHOA2(I) = T132+2.D0*T53+2.D0*T158+T160+T240
      T244 = -T148
      T253 = PIECEWISE(T4,0.1923661050931536D1*T79*T111
     #+0.1923661050931536D1*T16*T244,0.1923661050931536D1*T103*T111
     #+0.1923661050931536D1*T39*T244)
      T254 = RHO*T253
      V2RHOB2(I) = T132+2.D0*T116+2.D0*T254+T160+T240
      T256 = -T126
      T261 = PIECEWISE(T4,0.1923661050931536D1*T16
     #*T256,0.1923661050931536D1*T39*T256)
      V2RHOAB(I) = RHO*T261+T116+T254+T53+T158+T160+T240
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      V2RHOB2(I) = 0.0D0
      V2RHOAB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C*MODULE DFTXCB  *DECK RKS_C_PZ81
      SUBROUTINE RKS_C_PZ81(IDERIV,NPT,RHOA1,ZK,VRHOA,V2RHOA2)
C
C     J.P. PERDEW, AND A. ZUNGER
C     SELF-INTERACTION CORRECTION TO DENSITY-FUNCTIONAL APPROXIMATIONS
C     FOR MANY-ELECTRON SYSTEMS
C     PHYS. REV. B23 (1981) 5048-5079
C
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      INTEGER IDERIV,NPT
      DOUBLE PRECISION RHOA1(NPT),ZK(NPT),VRHOA(NPT),V2RHOA2(NPT)
      PARAMETER(TOL=1.0D-20)
      LOGICAL T4
C
      IF(IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHO = MAX(0.0D+00,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T5 = T1**(1.D0/6.D0)
      T11 = LOG(T3)
      T17 = PIECEWISE(1.D0 .LE. T3,-0.1423D0/(1.D0
     #+0.8292885914166397D0*T5+0.20682485366586D0*T2),0.311D-1*T11
     #-0.48D-1+0.12407009817988D-2*T2*T11-0.719606569443304D-2*T2)
      ZK(I) = RHO*T17
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHO = MAX(0.0D+00,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T4 = 1.D0 .LE. T3
      T5 = T1**(1.D0/6.D0)
      T8 = 1.D0+0.8292885914166397D0*T5+0.20682485366586D0*T2
      T11 = LOG(T3)
      T17 = PIECEWISE(T4,-0.1423D0/T8,0.311D-1*T11-0.48D-1
     #+0.12407009817988D-2*T2*T11-0.719606569443304D-2*T2)
      ZK(I) = RHO*T17
      T18 = PIECEWISE(T4,0.0D+00,0.0D+00)
      T20 = T8**2
      T22 = T5**2
      T23 = T22**2
      T26 = RHO**2
      T27 = 1/T26
      T30 = T2**2
      T31 = 1/T30
      T32 = T31*T27
      T45 = PIECEWISE(T4,0.1423D0/T20*(-0.1382147652361066D0/T23/T5
     #*T27-0.6894161788861999D-1*T32),-0.1036666666666667D-1*T1
     #-0.4135669939329333D-3*T31*T11*T27-0.4135669939329333D-3*T2*T1
     #+0.2398688564811013D-2*T32)
      VRHOA(I) = RHO*T18+T17+RHO*T45
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHO = MAX(0.0D+00,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      T1 = 1/RHO
      T2 = T1**(1.D0/3.D0)
      T3 = 0.6203504908994D0*T2
      T4 = 1.D0 .LE. T3
      T5 = T1**(1.D0/6.D0)
      T8 = 1.D0+0.8292885914166397D0*T5+0.20682485366586D0*T2
      T10 = 0.1423D0/T8
      T11 = LOG(T3)
      T13 = T2*T11
      T17 = PIECEWISE(T4,-T10,0.311D-1*T11-0.48D-1+0.12407009817988D-2
     #*T13-0.719606569443304D-2*T2)
      ZK(I) = RHO*T17
      T18 = PIECEWISE(T4,0.0D+00,0.0D+00)
      T19 = RHO*T18
      T20 = T8**2
      T21 = 1/T20
      T22 = T5**2
      T23 = T22**2
      T24 = T23*T5
      T25 = 1/T24
      T26 = RHO**2
      T27 = 1/T26
      T30 = T2**2
      T31 = 1/T30
      T32 = T31*T27
      T34 = -0.1382147652361066D0*T25*T27-0.6894161788861999D-1*T32
      T38 = T31*T11
      T45 = PIECEWISE(T4,0.1423D0*T21*T34,-0.1036666666666667D-1*T1
     #-0.4135669939329333D-3*T38*T27-0.4135669939329333D-3*T2*T1
     #+0.2398688564811013D-2*T32)
      VRHOA(I) = T19+T17+RHO*T45
      T53 = (-0.843D-1/(1.D0+0.1101176160755631D1*T5
     #+0.1619735131738333D0*T2)+T10)*T27
      T59 = (-0.1555D-1*T11+0.211D-1-0.80645563816922D-3*T13
     #+0.421838333811592D-2*T2)*T27
      T61 = PIECEWISE(T4,0.1709920934161366D1*T53,0.1709920934161366D1
     #*T59)
      T68 = T34**2
      T73 = T26**2
      T74 = 1/T73
      T78 = 1/T26/RHO
      T82 = 1/T30/T1
      T83 = T82*T74
      T85 = T31*T78
      T102 = PIECEWISE(T4,-0.2846D0/T20/T8*T68+0.1423D0*T21*(
     #-0.1151789710300888D0/T24/T1*T74+0.2764295304722132D0*T25*T78
     #-0.4596107859241333D-1*T83+0.13788323577724D0*T85
     #),0.1036666666666667D-1*T27-0.2757113292886222D-3*T82*T11*T74
     #-0.4521665800333405D-2*T85+0.8271339878658667D-3*T38*T78
     #+0.4135669939329333D-3*T2*T27+0.1599125709874009D-2*T83)
      T107 = PIECEWISE(T4,-0.1709920934161366D1*T53,
     #-0.1709920934161366D1*T59)
      V2RHOA2(I) = RHO*T61+4.D0*T18+4.D0*T19+4.D0*T45+2.D0*RHO*T102
     #+RHO*T107
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C*MODULE DFTXCB  *DECK UKS_PW91C_NWCHEM
      SUBROUTINE UKS_PW91C_NWCHEM
     & (IDERIV,NPT,RHOA1,RHOB1,SIGMAAA1,SIGMABB1,SIGMAAB1,
     &  ZK,VRHOA,VRHOB,VSIGMAAA,VSIGMABB,VSIGMAAB,
     &  V2RHOA2,V2RHOB2,V2RHOAB,
     &  V2RHOASIGMAAA,V2RHOASIGMAAB,V2RHOASIGMABB,
     &  V2RHOBSIGMABB,V2RHOBSIGMAAB,V2RHOBSIGMAAA,
     &  V2SIGMAAA2,V2SIGMAAAAB,V2SIGMAAABB,
     &  V2SIGMAAB2,V2SIGMAABBB,V2SIGMABB2)
C
C     J.P. PERDEW, J.A. CHEVARY, S.H. VOSKO, K.A. JACKSON,
C     M.R. PEDERSON, D.J. SINGH, C. FIOLHAIS
C     ATOMS, MOLECULES, SOLIDS AND SURFACES:
C     APPLICATIONS OF THE GENERALIZED GRADIENT APPROXIMATION
C     FOR EXCHANGE AND CORRELATION
C     PHYS. REV. B 46 (1992) 6671--6687
C
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      INTEGER IDERIV,NPT
      DOUBLE PRECISION RHOA1(NPT),RHOB1(NPT)
      DOUBLE PRECISION SIGMAAA1(NPT),SIGMABB1(NPT),SIGMAAB1(NPT)
      DOUBLE PRECISION ZK(NPT),VRHOA(NPT),VRHOB(NPT)
      DOUBLE PRECISION VSIGMAAA(NPT),VSIGMABB(NPT),VSIGMAAB(NPT)
      DOUBLE PRECISION V2RHOA2(NPT),V2RHOB2(NPT),V2RHOAB(NPT)
      DOUBLE PRECISION V2RHOASIGMAAA(NPT),V2RHOASIGMAAB(NPT)
      DOUBLE PRECISION V2RHOASIGMABB(NPT),V2RHOBSIGMABB(NPT)
      DOUBLE PRECISION V2RHOBSIGMAAB(NPT),V2RHOBSIGMAAA(NPT)
      DOUBLE PRECISION V2SIGMAAA2(NPT),V2SIGMAAAAB(NPT),V2SIGMAAABB(NPT)
      DOUBLE PRECISION V2SIGMAAB2(NPT),V2SIGMAABBB(NPT),V2SIGMABB2(NPT)
      PARAMETER(TOL=1.0D-20)
C
      IF (IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMABB
      T2 = 1/RHOB
      T3 = T2**(1.D0/3.D0)
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T17 = LOG(1.D0+0.3216395899738507D2/(0.1112037486309468D2*T6+0.38
     #44746237447211D1*T3+0.1644733775567609D1*T9+0.2405871291288192D0*T
     #11))
      T18 = (1.D0+0.1274696188700087D0*T3)*T17
      T20 = RHOB**2
      T21 = RHOB**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513845706671277D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMABB**2
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T42 = T28**2
      T52 = LOG(1.D0+0.2697586091519874D1*(0.1007494971260294D0*SIGMABB
     #*T23+0.2738174287780083D-1*T29*T30*T35)/(1.D0+0.2717804421747983D0
     #*T29*SIGMABB*T23+0.7386460874872889D-1/T42*T30*T35))
      T70 = EXP(-0.1044846919409344D2/T33/T20*SIGMABB)
      ZK(I) = RHOB*(-0.310907D-1*T18+0.1236778371778789D-1*T52+0.7937005
     #259840997D0*(0.1D-2*(0.2568D1+0.1443307452126544D2*T3+0.2843543831
     #490386D-2*T11)/(1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*
     #T11+0.1763993811759022D-1*T2)-0.1853571428571429D-2)*SIGMABB*T23*T
     #70)
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMA = SIGMAAA
      T2 = 1/RHOA
      T3 = T2**(1.D0/3.D0)
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T17 = LOG(1.D0+0.3216395899738507D2/(0.1112037486309468D2*T6+0.38
     #44746237447211D1*T3+0.1644733775567609D1*T9+0.2405871291288192D0*T
     #11))
      T18 = (1.D0+0.1274696188700087D0*T3)*T17
      T20 = RHOA**2
      T21 = RHOA**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513845706671277D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMAAA**2
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T42 = T28**2
      T52 = LOG(1.D0+0.2697586091519874D1*(0.1007494971260294D0*SIGMAAA
     #*T23+0.2738174287780083D-1*T29*T30*T35)/(1.D0+0.2717804421747983D0
     #*T29*SIGMAAA*T23+0.7386460874872889D-1/T42*T30*T35))
      T70 = EXP(-0.1044846919409344D2/T33/T20*SIGMAAA)
      ZK(I) = RHOA*(-0.310907D-1*T18+0.1236778371778789D-1*T52+0.7937005
     #259840997D0*(0.1D-2*(0.2568D1+0.1443307452126544D2*T3+0.2843543831
     #490386D-2*T11)/(1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*
     #T11+0.1763993811759022D-1*T2)-0.1853571428571429D-2)*SIGMAAA*T23*T
     #70)
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMAAB = SIGMAAB1(I)
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMAAA+SIGMABB+2.D0*SIGMAAB
      T4 = RHOA+RHOB
      T5 = 1/T4
      T6 = T5**(1.D0/3.D0)
      T9 = T5**(1.D0/6.D0)
      T12 = SQRT(T5)
      T14 = T6**2
      T20 = LOG(1.D0+0.1608197949869254D2/(0.598255043577108D1*T9+0.222
     #5569421150687D1*T6+0.8004286349993634D0*T12+0.1897004325747559D0*T
     #14))
      T22 = 0.621814D-1*(1.D0+0.1325688999052018D0*T6)*T20
      T33 = LOG(1.D0+0.2960874997779344D2/(0.8157414703487641D1*T9+0.22
     #47591863577616D1*T6+0.4300972471276643D0*T12+0.1911512595127338D0*
     #T14))
      T36 = RHOA-1.D0*RHOB
      T37 = T36*T5
      T38 = 1.D0+T37
      T39 = T38**(1.D0/3.D0)
      T42 = 1.D0-1.D0*T37
      T43 = T42**(1.D0/3.D0)
      T45 = T39*T38+T43*T42-2.D0
      T46 = T36**2
      T47 = T46**2
      T48 = T4**2
      T49 = T48**2
      T51 = T47/T49
      T56 = 0.3799552353702395D-1*(1.D0+0.6901399211255825D-1*T6)*T33*T4
     #5*(1.D0-1.D0*T51)
      T67 = LOG(1.D0+0.3216395899738507D2/(0.1112037486309468D2*T9+0.38
     #44746237447211D1*T6+0.1644733775567609D1*T12+0.2405871291288192D0*
     #T14))
      T73 = 0.1923661050931536D1*(-0.310907D-1*(1.D0+0.1274696188700087D
     #0*T6)*T67+T22)*T45*T51
      T74 = T39**2
      T76 = T43**2
      T78 = 0.5D0*T74+0.5D0*T76
      T79 = T78**2
      T80 = T79*T78
      T81 = 1/T79
      T83 = RHO**2
      T84 = RHO**(1.D0/3.D0)
      T86 = 1/T84/T83
      T93 = EXP(-0.4042761511756372D2*(-T22+T56+T73)/T80)
      T94 = T93-1.D0
      T95 = 1/T94
      T96 = SIGMA**2
      T98 = T79**2
      T100 = T83**2
      T101 = T84**2
      T104 = 1/T98/T101/T100
      T112 = T94**2
      T122 = LOG(1.D0+0.2697586091519874D1*(0.634682060977037D-1*SIGMA*
     #T81*T86+0.1086645186223595D-1*T95*T96*T104)/(1.D0+0.17121095002288
     #24D0*T95*SIGMA*T81*T86+0.2931318940773793D-1/T112*T96*T104))
      T143 = EXP(-0.261211729852336D1*T79/T101/T83*SIGMA)
      ZK(I) = RHO*(-T22+T56+T73+0.2473556743557577D-1*T80*T122+0.1D1*(0.
     #1D-2*(0.2568D1+0.1443307452126544D2*T6+0.2843543831490386D-2*T14)/
     #(1.D0+0.5411317332115466D1*T6+0.1816419932959077D0*T14+0.176399381
     #1759022D-1*T5)-0.1853571428571429D-2)*T78*SIGMA*T86*T143)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMABB
      T2 = 1/RHOB
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1274696188700087D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T3+0.1644733775
     #567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.3216395899738507D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.310907D-1*T18
      T20 = RHOB**2
      T21 = RHOB**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513845706671277D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMABB**2
      T31 = T29*T30
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T38 = 0.1007494971260294D0*SIGMABB*T23+0.2738174287780083D-1*T31*T
     #35
      T39 = T29*SIGMABB
      T42 = T28**2
      T43 = 1/T42
      T44 = T43*T30
      T45 = T44*T35
      T47 = 1.D0+0.2717804421747983D0*T39*T23+0.7386460874872889D-1*T45
      T48 = 1/T47
      T51 = 1.D0+0.2697586091519874D1*T38*T48
      T52 = LOG(T51)
      T53 = 0.1236778371778789D-1*T52
      T56 = 0.2568D1+0.1443307452126544D2*T3+0.2843543831490386D-2*T11
      T60 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T11+0.1763
     #993811759022D-1*T2
      T61 = 1/T60
      T64 = 0.1D-2*T56*T61-0.1853571428571429D-2
      T65 = T64*SIGMABB
      T70 = EXP(-0.1044846919409344D2/T33/T20*SIGMABB)
      T71 = T23*T70
      T73 = 0.7937005259840997D0*T65*T71
      ZK(I) = RHOB*(-T19+T53+T73)
      VRHOA(I) = 0.D0
      T76 = 1/T20
      T77 = 1/T11*T76
      T78 = T77*T17
      T80 = T13**2
      T83 = T6**2
      T84 = T83**2
      T94 = 1/T3*T76
      T99 = T5/T80*(-0.1853395810515781D1/T84/T6*T76-0.128158207914907D1
     #*T77-0.8223668877838045D0/T9*T76-0.1603914194192128D0*T94)/T16
      T103 = -0.1068129847091318D0*T78-0.8085523023512745D2*T99
      T108 = T47**2
      T110 = T38/T108
      T111 = T43*SIGMABB
      T127 = 1/T51
      T135 = T60**2
      T152 = 1/T21/T20/RHOB
      T155 = T32*RHOB
      T157 = 1/T33/T155
      VRHOB(I) = RHOB*(0.1321039893133927D-2*T78+0.1D1*T99+0.12367783717
     #78789D-1*(-0.7386460874872889D-1*T45*T103*T27*T48-0.26975860915198
     #74D1*T110*(-0.2717804421747983D0*T111*T23*T103*T27-0.1477292174974
     #578D0/T42/T28*T30*T35*T103*T27))*T127+0.7937005259840997D0*(0.1D-2
     #*(-0.4811024840421814D1*T77-0.1895695887660258D-2*T94)*T61-0.1D-2*
     #T56/T135*(-0.1803772444038489D1*T77-0.1210946621972718D0*T94-0.176
     #3993811759022D-1*T76))*SIGMABB*T71)-T19+T53+T73+RHOB*(0.1236778371
     #778789D-1*(0.2697586091519874D1*(-0.2350821599607352D0*SIGMABB*T15
     #2-0.1277814667630705D0*T31*T157)*T48-0.2697586091519874D1*T110*(-0
     #.6341543650745294D0*T39*T152-0.3447015074940681D0*T44*T157))*T127-
     #0.1851967893962899D1*T65*T152*T70+0.2211454798688167D2*T64*T30/T32
     #/T20*T70)
      VSIGMAAA(I) = 0.D0
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = RHOB*(0.1236778371778789D-1*(0.2697586091519874D1*(0
     #.1007494971260294D0*T23+0.5476348575560166D-1*T39*T35)*T48-0.26975
     #86091519874D1*T110*(0.2717804421747983D0*T29*T23+0.147729217497457
     #8D0*T111*T35))*T127+0.7937005259840997D0*T64*T23*T70-0.82929554950
     #80626D1*T65/T155*T70)
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMA = SIGMAAA
      T2 = 1/RHOA
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1274696188700087D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T3+0.1644733775
     #567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.3216395899738507D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.310907D-1*T18
      T20 = RHOA**2
      T21 = RHOA**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513845706671277D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMAAA**2
      T31 = T29*T30
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T38 = 0.1007494971260294D0*SIGMAAA*T23+0.2738174287780083D-1*T31*T
     #35
      T39 = T29*SIGMAAA
      T42 = T28**2
      T43 = 1/T42
      T44 = T43*T30
      T45 = T44*T35
      T47 = 1.D0+0.2717804421747983D0*T39*T23+0.7386460874872889D-1*T45
      T48 = 1/T47
      T51 = 1.D0+0.2697586091519874D1*T38*T48
      T52 = LOG(T51)
      T53 = 0.1236778371778789D-1*T52
      T56 = 0.2568D1+0.1443307452126544D2*T3+0.2843543831490386D-2*T11
      T60 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T11+0.1763
     #993811759022D-1*T2
      T61 = 1/T60
      T64 = 0.1D-2*T56*T61-0.1853571428571429D-2
      T65 = T64*SIGMAAA
      T70 = EXP(-0.1044846919409344D2/T33/T20*SIGMAAA)
      T71 = T23*T70
      T73 = 0.7937005259840997D0*T65*T71
      ZK(I) = RHOA*(-T19+T53+T73)
      T76 = 1/T20
      T77 = 1/T11*T76
      T78 = T77*T17
      T80 = T13**2
      T83 = T6**2
      T84 = T83**2
      T94 = 1/T3*T76
      T99 = T5/T80*(-0.1853395810515781D1/T84/T6*T76-0.128158207914907D1
     #*T77-0.8223668877838045D0/T9*T76-0.1603914194192128D0*T94)/T16
      T103 = -0.1068129847091318D0*T78-0.8085523023512745D2*T99
      T108 = T47**2
      T110 = T38/T108
      T111 = T43*SIGMAAA
      T127 = 1/T51
      T135 = T60**2
      T152 = 1/T21/T20/RHOA
      T155 = T32*RHOA
      T157 = 1/T33/T155
      VRHOA(I) = RHOA*(0.1321039893133927D-2*T78+0.1D1*T99+0.12367783717
     #78789D-1*(-0.7386460874872889D-1*T45*T103*T27*T48-0.26975860915198
     #74D1*T110*(-0.2717804421747983D0*T111*T23*T103*T27-0.1477292174974
     #578D0/T42/T28*T30*T35*T103*T27))*T127+0.7937005259840997D0*(0.1D-2
     #*(-0.4811024840421814D1*T77-0.1895695887660258D-2*T94)*T61-0.1D-2*
     #T56/T135*(-0.1803772444038489D1*T77-0.1210946621972718D0*T94-0.176
     #3993811759022D-1*T76))*SIGMAAA*T71)-T19+T53+T73+RHOA*(0.1236778371
     #778789D-1*(0.2697586091519874D1*(-0.2350821599607352D0*SIGMAAA*T15
     #2-0.1277814667630705D0*T31*T157)*T48-0.2697586091519874D1*T110*(-0
     #.6341543650745294D0*T39*T152-0.3447015074940681D0*T44*T157))*T127-
     #0.1851967893962899D1*T65*T152*T70+0.2211454798688167D2*T64*T30/T32
     #/T20*T70)
      VRHOB(I) = 0.D0
      VSIGMAAA(I) = RHOA*(0.1236778371778789D-1*(0.2697586091519874D1*(0
     #.1007494971260294D0*T23+0.5476348575560166D-1*T39*T35)*T48-0.26975
     #86091519874D1*T110*(0.2717804421747983D0*T29*T23+0.147729217497457
     #8D0*T111*T35))*T127+0.7937005259840997D0*T64*T23*T70-0.82929554950
     #80626D1*T65/T155*T70)
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = 0.D0
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMAAB = SIGMAAB1(I)
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMAAA+SIGMABB+2.D0*SIGMAAB
      T4 = RHOA+RHOB
      T5 = 1/T4
      T6 = T5**(1.D0/3.D0)
      T8 = 1.D0+0.1325688999052018D0*T6
      T9 = T5**(1.D0/6.D0)
      T12 = SQRT(T5)
      T14 = T6**2
      T16 = 0.598255043577108D1*T9+0.2225569421150687D1*T6+0.80042863499
     #93634D0*T12+0.1897004325747559D0*T14
      T19 = 1.D0+0.1608197949869254D2/T16
      T20 = LOG(T19)
      T22 = 0.621814D-1*T8*T20
      T24 = 1.D0+0.6901399211255825D-1*T6
      T29 = 0.8157414703487641D1*T9+0.2247591863577616D1*T6+0.4300972471
     #276643D0*T12+0.1911512595127338D0*T14
      T32 = 1.D0+0.2960874997779344D2/T29
      T33 = LOG(T32)
      T34 = T24*T33
      T36 = RHOA-1.D0*RHOB
      T37 = T36*T5
      T38 = 1.D0+T37
      T39 = T38**(1.D0/3.D0)
      T42 = 1.D0-1.D0*T37
      T43 = T42**(1.D0/3.D0)
      T45 = T39*T38+T43*T42-2.D0
      T46 = T36**2
      T47 = T46**2
      T48 = T4**2
      T49 = T48**2
      T50 = 1/T49
      T51 = T47*T50
      T53 = 1.D0-1.D0*T51
      T56 = 0.3799552353702395D-1*T34*T45*T53
      T58 = 1.D0+0.1274696188700087D0*T6
      T63 = 0.1112037486309468D2*T9+0.3844746237447211D1*T6+0.1644733775
     #567609D1*T12+0.2405871291288192D0*T14
      T66 = 1.D0+0.3216395899738507D2/T63
      T67 = LOG(T66)
      T70 = -0.310907D-1*T58*T67+T22
      T71 = T70*T45
      T73 = 0.1923661050931536D1*T71*T51
      T74 = T39**2
      T76 = T43**2
      T78 = 0.5D0*T74+0.5D0*T76
      T79 = T78**2
      T80 = T79*T78
      T81 = 1/T79
      T82 = SIGMA*T81
      T83 = RHO**2
      T84 = RHO**(1.D0/3.D0)
      T86 = 1/T84/T83
      T89 = -T22+T56+T73
      T90 = 1/T80
      T93 = EXP(-0.4042761511756372D2*T89*T90)
      T94 = T93-1.D0
      T95 = 1/T94
      T96 = SIGMA**2
      T97 = T95*T96
      T98 = T79**2
      T99 = 1/T98
      T100 = T83**2
      T101 = T84**2
      T103 = 1/T101/T100
      T104 = T99*T103
      T107 = 0.634682060977037D-1*T82*T86+0.1086645186223595D-1*T97*T104
      T108 = T95*SIGMA
      T109 = T81*T86
      T112 = T94**2
      T113 = 1/T112
      T114 = T113*T96
      T117 = 1.D0+0.1712109500228824D0*T108*T109+0.2931318940773793D-1*T
     #114*T104
      T118 = 1/T117
      T121 = 1.D0+0.2697586091519874D1*T107*T118
      T122 = LOG(T121)
      T124 = 0.2473556743557577D-1*T80*T122
      T127 = 0.2568D1+0.1443307452126544D2*T6+0.2843543831490386D-2*T14
      T131 = 1.D0+0.5411317332115466D1*T6+0.1816419932959077D0*T14+0.176
     #3993811759022D-1*T5
      T132 = 1/T131
      T135 = 0.1D-2*T127*T132-0.1853571428571429D-2
      T136 = T135*T78
      T143 = EXP(-0.261211729852336D1*T79/T101/T83*SIGMA)
      T144 = SIGMA*T86*T143
      T146 = 0.1D1*T136*T144
      ZK(I) = RHO*(-T22+T56+T73+T124+T146)
      T149 = 1/T48
      T150 = 1/T14*T149
      T151 = T150*T20
      T152 = 0.2747773264188438D-2*T151
      T153 = T16**2
      T156 = T9**2
      T157 = T156**2
      T160 = 1/T157/T9*T149
      T164 = 1/T12*T149
      T167 = 1/T6*T149
      T172 = T8/T153*(-0.99709173929518D0*T160-0.7418564737168958D0*T150
     #-0.4002143174996817D0*T164-0.1264669550498372D0*T167)/T19
      T173 = 0.1D1*T172
      T177 = 0.8740742538988973D-3*T150*T33*T45*T53
      T178 = T29**2
      T191 = 0.1124999956683108D1*T24/T178*(-0.135956911724794D1*T160-0.
     #7491972878592054D0*T150-0.2150486235638321D0*T164-0.12743417300848
     #92D0*T167)/T32*T45*T53
      T192 = T36*T149
      T193 = 1.D0*T192
      T194 = T5-T193
      T197 = 1.D0*T5
      T198 = -T197+T192
      T201 = 0.1333333333333333D1*T39*T194+0.1333333333333333D1*T43*T198
      T204 = 0.3799552353702395D-1*T34*T201*T53
      T206 = T46*T36*T50
      T207 = 4.D0*T206
      T210 = T47/T49/T4
      T211 = 4.D0*T210
      T215 = 0.3799552353702395D-1*T34*T45*(-T207+T211)
      T218 = T63**2
      T235 = 0.1923661050931536D1*(0.1321039893133927D-2*T150*T67+0.1D1*
     #T58/T218*(-0.1853395810515781D1*T160-0.128158207914907D1*T150-0.82
     #23668877838045D0*T164-0.1603914194192128D0*T167)/T66-0.27477732641
     #88438D-2*T151-0.1D1*T172)*T45*T51
      T238 = 0.1923661050931536D1*T70*T201*T51
      T239 = T71*T206
      T240 = 0.7694644203726145D1*T239
      T242 = 0.7694644203726145D1*T71*T210
      T243 = T79*T122
      T244 = 1/T39
      T247 = 1/T43
      T250 = 0.3333333333333333D0*T244*T194+0.3333333333333333D0*T247*T1
     #98
      T253 = SIGMA*T90
      T257 = T114*T99
      T261 = T89*T99
      T264 = -0.4042761511756372D2*(T152+T173-T177-T191+T204+T215+T235+T
     #238+T240-T242)*T90+0.1212828453526912D3*T261*T250
      T266 = T103*T264*T93
      T271 = 1/T98/T78*T103
      T272 = T271*T250
      T278 = T117**2
      T280 = T107/T278
      T281 = T113*SIGMA
      T282 = T281*T81
      T287 = T90*T86
      T294 = 1/T112/T94*T96*T99
      T304 = 1/T121
      T312 = T131**2
      T324 = 0.1D1*(0.1D-2*(-0.4811024840421814D1*T150-0.189569588766025
     #8D-2*T167)*T132-0.1D-2*T127/T312*(-0.1803772444038489D1*T150-0.121
     #0946621972718D0*T167-0.1763993811759022D-1*T149))*T78*T144
      T329 = T135*T79*T96
      T330 = T100*RHO
      T331 = 1/T330
      T336 = T152+T173-T177-T191+T204+T215+T235+T238+T240-T242+0.7420670
     #230672731D-1*T243*T250+0.2473556743557577D-1*T80*(0.26975860915198
     #74D1*(-0.1269364121954074D0*T253*T86*T250-0.1086645186223595D-1*T2
     #57*T266-0.4346580744894379D-1*T97*T272)*T118-0.2697586091519874D1*
     #T280*(-0.1712109500228824D0*T282*T86*T264*T93-0.3424219000457648D0
     #*T108*T287*T250-0.5862637881547585D-1*T294*T266-0.1172527576309517
     #D0*T114*T272))*T304+T324+0.1D1*T135*T250*T144-0.522423459704672D1*
     #T329*T331*T250*T143
      T340 = 1/T84/T83/RHO
      T345 = T99/T101/T330
      T367 = T135*T80
      T375 = RHO*(0.2473556743557577D-1*T80*(0.2697586091519874D1*(-0.14
     #8092480894642D0*T82*T340-0.5071010869043442D-1*T97*T345)*T118-0.26
     #97586091519874D1*T280*(-0.3994922167200589D0*T108*T81*T340-0.13679
     #4883902777D0*T114*T345))*T304-0.2333333333333333D1*T136*SIGMA*T340
     #*T143+0.6965646129395627D1*T367*T96/T100/T83*T143)
      VRHOA(I) = RHO*T336-T22+T56+T73+T124+T146+T375
      T376 = -T197-T193
      T379 = T5+T192
      T382 = 0.1333333333333333D1*T39*T376+0.1333333333333333D1*T43*T379
      T385 = 0.3799552353702395D-1*T34*T382*T53
      T389 = 0.3799552353702395D-1*T34*T45*(T207+T211)
      T392 = 0.1923661050931536D1*T70*T382*T51
      T393 = 0.7694644203726145D1*T239
      T398 = 0.3333333333333333D0*T244*T376+0.3333333333333333D0*T247*T3
     #79
      T409 = -0.4042761511756372D2*(T152+T173-T177-T191+T385+T389+T235+T
     #392-T393-T242)*T90+0.1212828453526912D3*T261*T398
      T411 = T103*T409*T93
      T414 = T271*T398
      T445 = T152+T173-T177-T191+T385+T389+T235+T392-T393-T242+0.7420670
     #230672731D-1*T243*T398+0.2473556743557577D-1*T80*(0.26975860915198
     #74D1*(-0.1269364121954074D0*T253*T86*T398-0.1086645186223595D-1*T2
     #57*T411-0.4346580744894379D-1*T97*T414)*T118-0.2697586091519874D1*
     #T280*(-0.1712109500228824D0*T282*T86*T409*T93-0.3424219000457648D0
     #*T108*T287*T398-0.5862637881547585D-1*T294*T411-0.1172527576309517
     #D0*T114*T414))*T304+T324+0.1D1*T135*T398*T144-0.522423459704672D1*
     #T329*T331*T398*T143
      VRHOB(I) = RHO*T445-T22+T56+T73+T124+T146+T375
      VSIGMAAA(I) = RHO*(0.2473556743557577D-1*T80*(0.2697586091519874D1
     #*(0.634682060977037D-1*T109+0.2173290372447189D-1*T108*T104)*T118-
     #0.2697586091519874D1*T280*(0.1712109500228824D0*T95*T81*T86+0.5862
     #637881547585D-1*T281*T104))*T304+0.1D1*T136*T86*T143-0.26121172985
     #2336D1*T367*SIGMA*T331*T143)
      VSIGMAAB(I) = 2.D0*VSIGMAAA(I)
      VSIGMABB(I) = VSIGMAAA(I)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      VSIGMAAB(I) = 0.0D0
      VSIGMABB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN
C
      DO I=1,NPT
      RHOA = MAX(0.D0,RHOA1(I))
      RHOB = MAX(0.D0,RHOB1(I))
      RHO = RHOA+RHOB
      IF(RHO.GT.TOL) THEN
      IF(RHOA.LT.TOL) THEN
      RHO = RHOB
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMABB
      T2 = 1/RHOB
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1274696188700087D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T3+0.1644733775
     #567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.3216395899738507D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.310907D-1*T18
      T20 = RHOB**2
      T21 = RHOB**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513845706671277D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMABB**2
      T31 = T29*T30
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T38 = 0.1007494971260294D0*SIGMABB*T23+0.2738174287780083D-1*T31*T
     #35
      T39 = T29*SIGMABB
      T42 = T28**2
      T43 = 1/T42
      T44 = T43*T30
      T45 = T44*T35
      T47 = 1.D0+0.2717804421747983D0*T39*T23+0.7386460874872889D-1*T45
      T48 = 1/T47
      T51 = 1.D0+0.2697586091519874D1*T38*T48
      T52 = LOG(T51)
      T53 = 0.1236778371778789D-1*T52
      T56 = 0.2568D1+0.1443307452126544D2*T3+0.2843543831490386D-2*T11
      T60 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T11+0.1763
     #993811759022D-1*T2
      T61 = 1/T60
      T64 = 0.1D-2*T56*T61-0.1853571428571429D-2
      T65 = T64*SIGMABB
      T70 = EXP(-0.1044846919409344D2/T33/T20*SIGMABB)
      T71 = T23*T70
      T73 = 0.7937005259840997D0*T65*T71
      ZK(I) = RHOB*(-T19+T53+T73)
      VRHOA(I) = 0.D0
      T75 = 1/T11
      T76 = 1/T20
      T77 = T75*T76
      T78 = T77*T17
      T80 = T13**2
      T81 = 1/T80
      T82 = T5*T81
      T83 = T6**2
      T84 = T83**2
      T85 = T84*T6
      T86 = 1/T85
      T90 = 1/T9
      T93 = 1/T3
      T94 = T93*T76
      T96 = -0.1853395810515781D1*T86*T76-0.128158207914907D1*T77-0.8223
     #668877838045D0*T90*T76-0.1603914194192128D0*T94
      T97 = 1/T16
      T99 = T82*T96*T97
      T103 = -0.1068129847091318D0*T78-0.8085523023512745D2*T99
      T104 = T103*T27
      T105 = T104*T48
      T108 = T47**2
      T109 = 1/T108
      T110 = T38*T109
      T111 = T43*SIGMABB
      T117 = 1/T42/T28
      T118 = T117*T30
      T123 = -0.2717804421747983D0*T111*T23*T103*T27-0.1477292174974578D
     #0*T118*T35*T103*T27
      T126 = -0.7386460874872889D-1*T45*T105-0.2697586091519874D1*T110*T
     #123
      T127 = 1/T51
      T128 = T126*T127
      T132 = -0.4811024840421814D1*T77-0.1895695887660258D-2*T94
      T135 = T60**2
      T136 = 1/T135
      T137 = T56*T136
      T141 = -0.1803772444038489D1*T77-0.1210946621972718D0*T94-0.176399
     #3811759022D-1*T76
      T144 = 0.1D-2*T132*T61-0.1D-2*T137*T141
      T145 = T144*SIGMABB
      T146 = T145*T71
      T150 = T20*RHOB
      T152 = 1/T21/T150
      T155 = T32*RHOB
      T157 = 1/T33/T155
      T160 = -0.2350821599607352D0*SIGMABB*T152-0.1277814667630705D0*T31
     #*T157
      T165 = T44*T157
      T167 = -0.6341543650745294D0*T39*T152-0.3447015074940681D0*T165
      T170 = 0.2697586091519874D1*T160*T48-0.2697586091519874D1*T110*T16
     #7
      T171 = T170*T127
      T173 = T152*T70
      T174 = T65*T173
      T176 = T64*T30
      T177 = T32*T20
      T179 = 1/T177*T70
      T180 = T176*T179
      VRHOB(I) = RHOB*(0.1321039893133927D-2*T78+0.1D1*T99+0.12367783717
     #78789D-1*T128+0.7937005259840997D0*T146)-T19+T53+T73+RHOB*(0.12367
     #78371778789D-1*T171-0.1851967893962899D1*T174+0.2211454798688167D2
     #*T180)
      VSIGMAAA(I) = 0.D0
      VSIGMAAB(I) = 0.D0
      T187 = 0.1007494971260294D0*T23+0.5476348575560166D-1*T39*T35
      T194 = 0.2717804421747983D0*T29*T23+0.1477292174974578D0*T111*T35
      T197 = 0.2697586091519874D1*T187*T48-0.2697586091519874D1*T110*T19
     #4
      T203 = 1/T155
      VSIGMABB(I) = RHOB*(0.1236778371778789D-1*T197*T127+0.793700525984
     #0997D0*T64*T23*T70-0.8292955495080626D1*T65*T203*T70)
      V2RHOA2(I) = 0.D0
      V2RHOAB(I) = 0.D0
      T210 = 1/T32
      T211 = 1/T11/T2*T210
      T212 = T211*T17
      T214 = 1/T150
      T215 = T75*T214
      T216 = T215*T17
      T220 = T77*T81*T96*T97
      T225 = T96**2
      T227 = T5/T80/T13*T225*T97
      T245 = 1/T3/T2*T210
      T247 = T93*T214
      T251 = T82*(-0.1544496508763151D1/T85/T2*T210+0.3706791621031562D1
     #*T86*T214-0.854388052766047D0*T211+0.2563164158298141D1*T215-0.411
     #1834438919023D0/T9/T2*T210+0.1644733775567609D1*T90*T214-0.5346380
     #647307093D-1*T245+0.3207828388384256D0*T247)*T97
      T253 = T80**2
      T256 = T16**2
      T259 = T5/T253*T225/T256
      T262 = T103**2
      T264 = EXP(0.5027691413342554D1*T18)
      T275 = -0.7120865647275453D-1*T212+0.2136259694182636D0*T216+0.687
     #1056921145667D1*T220+0.1617104604702549D3*T227-0.8085523023512745D
     #2*T251-0.2600624310006769D4*T259
      T290 = T38/T108/T47
      T291 = T123**2
      T295 = T23*T262
      T306 = T42**2
      T309 = T35*T262
      T326 = T126**2
      T327 = T51**2
      T328 = 1/T327
      T344 = T141**2
      T366 = 0.3447015074940681D0*T165*T105
      T367 = T160*T109
      T369 = 0.2697586091519874D1*T367*T123
      T373 = 0.7386460874872889D-1*T45*T104*T109*T167
      T376 = 0.5395172183039748D1*T290*T167*T123
      T380 = 0.6341543650745294D0*T111*T152*T103*T27
      T383 = T118*T157*T103*T27
      T393 = 0.1236778371778789D-1*T170*T328*T126
      T395 = 0.1851967893962899D1*T145*T173
      T398 = 0.2211454798688167D2*T144*T30*T179
      T414 = 1/T21/T32
      T418 = 1/T33/T177
      T426 = T167**2
      T439 = T170**2
      T445 = T32*T150
      T452 = T32**2
      S4 = RHOB
      S6 = 0.8806932620892844D-3*T212-0.2642079786267853D-2*T216-0.84979
     #74591333914D-1*T220-0.2D1*T227
      S7 = S6+0.1D1*T251+0.3216395899738507D2*T259
      S8 = S7+0.1236778371778789D-1*(0.1477292174974578D0*T118*T35*T262*
     #T264*T48-0.7386460874872889D-1*T45*T275*T27*T48-0.7386460874872889
     #D-1*T45*T262*T27*T48+0.1477292174974578D0*T45*T104*T109*T123+0.539
     #5172183039748D1*T290*T291-0.2697586091519874D1*T110*(0.54356088434
     #95966D0*T117*SIGMABB*T295*T264-0.2717804421747983D0*T111*T23*T275*
     #T27-0.2717804421747983D0*T111*T295*T27+0.4431876524923733D0/T306*T
     #30*T309*T264-0.1477292174974578D0*T118*T35*T275*T27-0.147729217497
     #4578D0*T118*T309*T27))*T127
      S5 = S8-0.1236778371778789D-1*T326*T328+0.7937005259840997D0*(0.1D
     #-2*(-0.3207349893614542D1*T211+0.9622049680843627D1*T215-0.6318986
     #292200858D-3*T245+0.3791391775320515D-2*T247)*T61-0.2D-2*T132*T136
     #*T141+0.2D-2*T56/T135/T60*T344-0.1D-2*T137*(-0.1202514962692326D1*
     #T211+0.3607544888076978D1*T215-0.4036488739909061D-1*T245+0.242189
     #3243945437D0*T247+0.3527987623518044D-1*T214))*SIGMABB*T71
      S3 = S4*S5
      S4 = 0.2642079786267853D-2*T78
      S2 = S3+S4
      S1 = S2+0.2D1*T99+0.2473556743557577D-1*T128+0.1587401051968199D1*
     #T146
      S2 = S1+RHOB*(0.1236778371778789D-1*(T366-T369+T373+T376-0.2697586
     #091519874D1*T110*(T380+0.6894030149881363D0*T383))*T127-T393-T395+
     #T398)+RHOB*(0.1236778371778789D-1*(T366+T373-T369+T376-0.269758609
     #1519874D1*T110*(T380+0.6894030149881363D0*T383))*T127-T393-T395+T3
     #98)
      V2RHOB2(I) = S2+0.2473556743557577D-1*T171-0.3703935787925799D1*T1
     #74+0.4422909597376334D2*T180+RHOB*(0.1236778371778789D-1*(0.269758
     #6091519874D1*(0.7836071998691172D0*SIGMABB*T414+0.7240949783240664
     #D0*T31*T418)*T48-0.5395172183039748D1*T367*T167+0.5395172183039748
     #D1*T290*T426-0.2697586091519874D1*T110*(0.2113847883581765D1*T39*T
     #414+0.1953308542466386D1*T44*T418))*T127-0.1236778371778789D-1*T43
     #9*T328+0.6173226313209665D1*T65*T414*T70-0.1842878998906806D3*T176
     #/T445*T70+0.6161684623526246D3*T64*T30*SIGMABB/T33/T452/RHOB*T70)
      V2SIGMAAA2(I) = 0.D0
      V2SIGMAAAAB(I) = 0.D0
      V2SIGMAAABB(I) = 0.D0
      V2SIGMAAB2(I) = 0.D0
      V2SIGMAABBB(I) = 0.D0
      T467 = T194**2
      T476 = T197**2
      V2SIGMABB2(I) = RHOB*(0.1236778371778789D-1*(0.1477292174974578D0*
     #T29*T35*T48-0.5395172183039748D1*T187*T109*T194+0.5395172183039748
     #D1*T290*T467-0.3985122824322565D0*T110*T43*T35)*T127-0.12367783717
     #78789D-1*T476*T328-0.1658591099016125D2*T64*T203*T70+0.86648690018
     #33783D2*T65/T33/T445*T70)
      ELSEIF(RHOB.LT.TOL) THEN
      RHO = RHOA
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMA = SIGMAAA
      T2 = 1/RHOA
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1274696188700087D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.1112037486309468D2*T6+0.3844746237447211D1*T3+0.1644733775
     #567609D1*T9+0.2405871291288192D0*T11
      T16 = 1.D0+0.3216395899738507D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.310907D-1*T18
      T20 = RHOA**2
      T21 = RHOA**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513845706671277D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMAAA**2
      T31 = T29*T30
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T38 = 0.1007494971260294D0*SIGMAAA*T23+0.2738174287780083D-1*T31*T
     #35
      T39 = T29*SIGMAAA
      T42 = T28**2
      T43 = 1/T42
      T44 = T43*T30
      T45 = T44*T35
      T47 = 1.D0+0.2717804421747983D0*T39*T23+0.7386460874872889D-1*T45
      T48 = 1/T47
      T51 = 1.D0+0.2697586091519874D1*T38*T48
      T52 = LOG(T51)
      T53 = 0.1236778371778789D-1*T52
      T56 = 0.2568D1+0.1443307452126544D2*T3+0.2843543831490386D-2*T11
      T60 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T11+0.1763
     #993811759022D-1*T2
      T61 = 1/T60
      T64 = 0.1D-2*T56*T61-0.1853571428571429D-2
      T65 = T64*SIGMAAA
      T70 = EXP(-0.1044846919409344D2/T33/T20*SIGMAAA)
      T71 = T23*T70
      T73 = 0.7937005259840997D0*T65*T71
      ZK(I) = RHOA*(-T19+T53+T73)
      T75 = 1/T11
      T76 = 1/T20
      T77 = T75*T76
      T78 = T77*T17
      T80 = T13**2
      T81 = 1/T80
      T82 = T5*T81
      T83 = T6**2
      T84 = T83**2
      T85 = T84*T6
      T86 = 1/T85
      T90 = 1/T9
      T93 = 1/T3
      T94 = T93*T76
      T96 = -0.1853395810515781D1*T86*T76-0.128158207914907D1*T77-0.8223
     #668877838045D0*T90*T76-0.1603914194192128D0*T94
      T97 = 1/T16
      T99 = T82*T96*T97
      T103 = -0.1068129847091318D0*T78-0.8085523023512745D2*T99
      T104 = T103*T27
      T105 = T104*T48
      T108 = T47**2
      T109 = 1/T108
      T110 = T38*T109
      T111 = T43*SIGMAAA
      T117 = 1/T42/T28
      T118 = T117*T30
      T123 = -0.2717804421747983D0*T111*T23*T103*T27-0.1477292174974578D
     #0*T118*T35*T103*T27
      T126 = -0.7386460874872889D-1*T45*T105-0.2697586091519874D1*T110*T
     #123
      T127 = 1/T51
      T128 = T126*T127
      T132 = -0.4811024840421814D1*T77-0.1895695887660258D-2*T94
      T135 = T60**2
      T136 = 1/T135
      T137 = T56*T136
      T141 = -0.1803772444038489D1*T77-0.1210946621972718D0*T94-0.176399
     #3811759022D-1*T76
      T144 = 0.1D-2*T132*T61-0.1D-2*T137*T141
      T145 = T144*SIGMAAA
      T146 = T145*T71
      T150 = T20*RHOA
      T152 = 1/T21/T150
      T155 = T32*RHOA
      T157 = 1/T33/T155
      T160 = -0.2350821599607352D0*SIGMAAA*T152-0.1277814667630705D0*T31
     #*T157
      T165 = T44*T157
      T167 = -0.6341543650745294D0*T39*T152-0.3447015074940681D0*T165
      T170 = 0.2697586091519874D1*T160*T48-0.2697586091519874D1*T110*T16
     #7
      T171 = T170*T127
      T173 = T152*T70
      T174 = T65*T173
      T176 = T64*T30
      T177 = T32*T20
      T179 = 1/T177*T70
      T180 = T176*T179
      VRHOA(I) = RHOA*(0.1321039893133927D-2*T78+0.1D1*T99+0.12367783717
     #78789D-1*T128+0.7937005259840997D0*T146)-T19+T53+T73+RHOA*(0.12367
     #78371778789D-1*T171-0.1851967893962899D1*T174+0.2211454798688167D2
     #*T180)
      VRHOB(I) = 0.D0
      T187 = 0.1007494971260294D0*T23+0.5476348575560166D-1*T39*T35
      T194 = 0.2717804421747983D0*T29*T23+0.1477292174974578D0*T111*T35
      T197 = 0.2697586091519874D1*T187*T48-0.2697586091519874D1*T110*T19
     #4
      T203 = 1/T155
      VSIGMAAA(I) = RHOA*(0.1236778371778789D-1*T197*T127+0.793700525984
     #0997D0*T64*T23*T70-0.8292955495080626D1*T65*T203*T70)
      VSIGMAAB(I) = 0.D0
      VSIGMABB(I) = 0.D0
      T210 = 1/T32
      T211 = 1/T11/T2*T210
      T212 = T211*T17
      T214 = 1/T150
      T215 = T75*T214
      T216 = T215*T17
      T220 = T77*T81*T96*T97
      T225 = T96**2
      T227 = T5/T80/T13*T225*T97
      T245 = 1/T3/T2*T210
      T247 = T93*T214
      T251 = T82*(-0.1544496508763151D1/T85/T2*T210+0.3706791621031562D1
     #*T86*T214-0.854388052766047D0*T211+0.2563164158298141D1*T215-0.411
     #1834438919023D0/T9/T2*T210+0.1644733775567609D1*T90*T214-0.5346380
     #647307093D-1*T245+0.3207828388384256D0*T247)*T97
      T253 = T80**2
      T256 = T16**2
      T259 = T5/T253*T225/T256
      T262 = T103**2
      T264 = EXP(0.5027691413342554D1*T18)
      T275 = -0.7120865647275453D-1*T212+0.2136259694182636D0*T216+0.687
     #1056921145667D1*T220+0.1617104604702549D3*T227-0.8085523023512745D
     #2*T251-0.2600624310006769D4*T259
      T290 = T38/T108/T47
      T291 = T123**2
      T295 = T23*T262
      T306 = T42**2
      T309 = T35*T262
      T326 = T126**2
      T327 = T51**2
      T328 = 1/T327
      T344 = T141**2
      T366 = 0.3447015074940681D0*T165*T105
      T367 = T160*T109
      T369 = 0.2697586091519874D1*T367*T123
      T373 = 0.7386460874872889D-1*T45*T104*T109*T167
      T376 = 0.5395172183039748D1*T290*T167*T123
      T380 = 0.6341543650745294D0*T111*T152*T103*T27
      T383 = T118*T157*T103*T27
      T393 = 0.1236778371778789D-1*T170*T328*T126
      T395 = 0.1851967893962899D1*T145*T173
      T398 = 0.2211454798688167D2*T144*T30*T179
      T414 = 1/T21/T32
      T418 = 1/T33/T177
      T426 = T167**2
      T439 = T170**2
      T445 = T32*T150
      T452 = T32**2
      S4 = RHOA
      S6 = 0.8806932620892844D-3*T212-0.2642079786267853D-2*T216-0.84979
     #74591333914D-1*T220-0.2D1*T227
      S7 = S6+0.1D1*T251+0.3216395899738507D2*T259
      S8 = S7+0.1236778371778789D-1*(0.1477292174974578D0*T118*T35*T262*
     #T264*T48-0.7386460874872889D-1*T45*T275*T27*T48-0.7386460874872889
     #D-1*T45*T262*T27*T48+0.1477292174974578D0*T45*T104*T109*T123+0.539
     #5172183039748D1*T290*T291-0.2697586091519874D1*T110*(0.54356088434
     #95966D0*T117*SIGMAAA*T295*T264-0.2717804421747983D0*T111*T23*T275*
     #T27-0.2717804421747983D0*T111*T295*T27+0.4431876524923733D0/T306*T
     #30*T309*T264-0.1477292174974578D0*T118*T35*T275*T27-0.147729217497
     #4578D0*T118*T309*T27))*T127
      S5 = S8-0.1236778371778789D-1*T326*T328+0.7937005259840997D0*(0.1D
     #-2*(-0.3207349893614542D1*T211+0.9622049680843627D1*T215-0.6318986
     #292200858D-3*T245+0.3791391775320515D-2*T247)*T61-0.2D-2*T132*T136
     #*T141+0.2D-2*T56/T135/T60*T344-0.1D-2*T137*(-0.1202514962692326D1*
     #T211+0.3607544888076978D1*T215-0.4036488739909061D-1*T245+0.242189
     #3243945437D0*T247+0.3527987623518044D-1*T214))*SIGMAAA*T71
      S3 = S4*S5
      S4 = 0.2642079786267853D-2*T78
      S2 = S3+S4
      S1 = S2+0.2D1*T99+0.2473556743557577D-1*T128+0.1587401051968199D1*
     #T146
      S2 = S1+RHOA*(0.1236778371778789D-1*(T366-T369+T373+T376-0.2697586
     #091519874D1*T110*(T380+0.6894030149881363D0*T383))*T127-T393-T395+
     #T398)+RHOA*(0.1236778371778789D-1*(T366+T373-T369+T376-0.269758609
     #1519874D1*T110*(T380+0.6894030149881363D0*T383))*T127-T393-T395+T3
     #98)
      V2RHOA2(I) = S2+0.2473556743557577D-1*T171-0.3703935787925799D1*T1
     #74+0.4422909597376334D2*T180+RHOA*(0.1236778371778789D-1*(0.269758
     #6091519874D1*(0.7836071998691172D0*SIGMAAA*T414+0.7240949783240664
     #D0*T31*T418)*T48-0.5395172183039748D1*T367*T167+0.5395172183039748
     #D1*T290*T426-0.2697586091519874D1*T110*(0.2113847883581765D1*T39*T
     #414+0.1953308542466386D1*T44*T418))*T127-0.1236778371778789D-1*T43
     #9*T328+0.6173226313209665D1*T65*T414*T70-0.1842878998906806D3*T176
     #/T445*T70+0.6161684623526246D3*T64*T30*SIGMAAA/T33/T452/RHOA*T70)
      V2RHOB2(I) = 0.D0
      V2RHOAB(I) = 0.D0
      T467 = T194**2
      T476 = T197**2
      V2SIGMAAA2(I) = RHOA*(0.1236778371778789D-1*(0.1477292174974578D0*
     #T29*T35*T48-0.5395172183039748D1*T187*T109*T194+0.5395172183039748
     #D1*T290*T467-0.3985122824322565D0*T110*T43*T35)*T127-0.12367783717
     #78789D-1*T476*T328-0.1658591099016125D2*T64*T203*T70+0.86648690018
     #33783D2*T65/T33/T445*T70)
      V2SIGMAAAAB(I) = 0.D0
      V2SIGMAAABB(I) = 0.D0
      V2SIGMAAB2(I) = 0.D0
      V2SIGMAABBB(I) = 0.D0
      V2SIGMABB2(I) = 0.D0
      ELSE ! (.NOT.(RHOA.LT.TOL).AND..NOT.(RHOB.LT.TOL))
      SIGMAAA = MAX(0.D0,SIGMAAA1(I))
      SIGMAAB = SIGMAAB1(I)
      SIGMABB = MAX(0.D0,SIGMABB1(I))
      SIGMA = SIGMAAA+SIGMABB+2.D0*SIGMAAB
      T4 = RHOA+RHOB
      T5 = 1/T4
      T6 = T5**(1.D0/3.D0)
      T8 = 1.D0+0.1325688999052018D0*T6
      T9 = T5**(1.D0/6.D0)
      T12 = SQRT(T5)
      T14 = T6**2
      T16 = 0.598255043577108D1*T9+0.2225569421150687D1*T6+0.80042863499
     #93634D0*T12+0.1897004325747559D0*T14
      T19 = 1.D0+0.1608197949869254D2/T16
      T20 = LOG(T19)
      T22 = 0.621814D-1*T8*T20
      T24 = 1.D0+0.6901399211255825D-1*T6
      T29 = 0.8157414703487641D1*T9+0.2247591863577616D1*T6+0.4300972471
     #276643D0*T12+0.1911512595127338D0*T14
      T32 = 1.D0+0.2960874997779344D2/T29
      T33 = LOG(T32)
      T34 = T24*T33
      T36 = RHOA-1.D0*RHOB
      T37 = T36*T5
      T38 = 1.D0+T37
      T39 = T38**(1.D0/3.D0)
      T40 = T39*T38
      T42 = 1.D0-1.D0*T37
      T43 = T42**(1.D0/3.D0)
      T44 = T43*T42
      T45 = T40+T44-2.D0
      T46 = T36**2
      T47 = T46**2
      T48 = T4**2
      T49 = T48**2
      T50 = 1/T49
      T51 = T47*T50
      T53 = 1.D0-1.D0*T51
      T54 = T45*T53
      T56 = 0.3799552353702395D-1*T34*T54
      T58 = 1.D0+0.1274696188700087D0*T6
      T63 = 0.1112037486309468D2*T9+0.3844746237447211D1*T6+0.1644733775
     #567609D1*T12+0.2405871291288192D0*T14
      T66 = 1.D0+0.3216395899738507D2/T63
      T67 = LOG(T66)
      T70 = -0.310907D-1*T58*T67+T22
      T71 = T70*T45
      T73 = 0.1923661050931536D1*T71*T51
      T74 = T39**2
      T76 = T43**2
      T78 = 0.5D0*T74+0.5D0*T76
      T79 = T78**2
      T80 = T79*T78
      T81 = 1/T79
      T82 = SIGMA*T81
      T83 = RHO**2
      T84 = RHO**(1.D0/3.D0)
      T86 = 1/T84/T83
      T89 = -T22+T56+T73
      T90 = 1/T80
      T91 = T89*T90
      T93 = EXP(-0.4042761511756372D2*T91)
      T94 = T93-1.D0
      T95 = 1/T94
      T96 = SIGMA**2
      T97 = T95*T96
      T98 = T79**2
      T99 = 1/T98
      T100 = T83**2
      T101 = T84**2
      T103 = 1/T101/T100
      T104 = T99*T103
      T107 = 0.634682060977037D-1*T82*T86+0.1086645186223595D-1*T97*T104
      T108 = T95*SIGMA
      T109 = T81*T86
      T112 = T94**2
      T113 = 1/T112
      T114 = T113*T96
      T117 = 1.D0+0.1712109500228824D0*T108*T109+0.2931318940773793D-1*T
     #114*T104
      T118 = 1/T117
      T121 = 1.D0+0.2697586091519874D1*T107*T118
      T122 = LOG(T121)
      T124 = 0.2473556743557577D-1*T80*T122
      T127 = 0.2568D1+0.1443307452126544D2*T6+0.2843543831490386D-2*T14
      T131 = 1.D0+0.5411317332115466D1*T6+0.1816419932959077D0*T14+0.176
     #3993811759022D-1*T5
      T132 = 1/T131
      T135 = 0.1D-2*T127*T132-0.1853571428571429D-2
      T136 = T135*T78
      T143 = EXP(-0.261211729852336D1*T79/T101/T83*SIGMA)
      T144 = SIGMA*T86*T143
      T146 = 0.1D1*T136*T144
      ZK(I) = RHO*(-T22+T56+T73+T124+T146)
      T148 = 1/T14
      T149 = 1/T48
      T150 = T148*T149
      T151 = T150*T20
      T152 = 0.2747773264188438D-2*T151
      T153 = T16**2
      T154 = 1/T153
      T155 = T8*T154
      T156 = T9**2
      T157 = T156**2
      T158 = T157*T9
      T159 = 1/T158
      T160 = T159*T149
      T163 = 1/T12
      T164 = T163*T149
      T166 = 1/T6
      T167 = T166*T149
      T169 = -0.99709173929518D0*T160-0.7418564737168958D0*T150-0.400214
     #3174996817D0*T164-0.1264669550498372D0*T167
      T170 = 1/T19
      T172 = T155*T169*T170
      T173 = 0.1D1*T172
      T174 = T33*T45
      T175 = T174*T53
      T176 = T150*T175
      T177 = 0.8740742538988973D-3*T176
      T178 = T29**2
      T179 = 1/T178
      T180 = T24*T179
      T185 = -0.135956911724794D1*T160-0.7491972878592054D0*T150-0.21504
     #86235638321D0*T164-0.1274341730084892D0*T167
      T186 = T180*T185
      T187 = 1/T32
      T188 = T187*T45
      T189 = T188*T53
      T190 = T186*T189
      T191 = 0.1124999956683108D1*T190
      T192 = T36*T149
      T193 = 1.D0*T192
      T194 = T5-T193
      T197 = 1.D0*T5
      T198 = -T197+T192
      T201 = 0.1333333333333333D1*T39*T194+0.1333333333333333D1*T43*T198
      T203 = T34*T201*T53
      T204 = 0.3799552353702395D-1*T203
      T205 = T46*T36
      T206 = T205*T50
      T207 = 4.D0*T206
      T209 = 1/T49/T4
      T210 = T47*T209
      T211 = 4.D0*T210
      T212 = -T207+T211
      T214 = T34*T45*T212
      T215 = 0.3799552353702395D-1*T214
      T218 = T63**2
      T219 = 1/T218
      T220 = T58*T219
      T225 = -0.1853395810515781D1*T160-0.128158207914907D1*T150-0.82236
     #68877838045D0*T164-0.1603914194192128D0*T167
      T226 = 1/T66
      T232 = 0.1321039893133927D-2*T150*T67+0.1D1*T220*T225*T226-0.27477
     #73264188438D-2*T151-0.1D1*T172
      T233 = T232*T45
      T234 = T233*T51
      T235 = 0.1923661050931536D1*T234
      T236 = T70*T201
      T237 = T236*T51
      T238 = 0.1923661050931536D1*T237
      T239 = T71*T206
      T240 = 0.7694644203726145D1*T239
      T241 = T71*T210
      T242 = 0.7694644203726145D1*T241
      T243 = T79*T122
      T244 = 1/T39
      T247 = 1/T43
      T250 = 0.3333333333333333D0*T244*T194+0.3333333333333333D0*T247*T1
     #98
      T251 = T243*T250
      T252 = 0.7420670230672731D-1*T251
      T253 = SIGMA*T90
      T254 = T86*T250
      T257 = T114*T99
      T258 = T152+T173-T177-T191+T204+T215+T235+T238+T240-T242
      T261 = T89*T99
      T264 = -0.4042761511756372D2*T258*T90+0.1212828453526912D3*T261*T2
     #50
      T265 = T103*T264
      T266 = T265*T93
      T269 = T98*T78
      T270 = 1/T269
      T271 = T270*T103
      T272 = T271*T250
      T275 = -0.1269364121954074D0*T253*T254-0.1086645186223595D-1*T257*
     #T266-0.4346580744894379D-1*T97*T272
      T278 = T117**2
      T279 = 1/T278
      T280 = T107*T279
      T281 = T113*SIGMA
      T282 = T281*T81
      T283 = T86*T264
      T284 = T283*T93
      T287 = T90*T86
      T288 = T287*T250
      T292 = 1/T112/T94
      T293 = T292*T96
      T294 = T293*T99
      T299 = -0.1712109500228824D0*T282*T284-0.3424219000457648D0*T108*T
     #288-0.5862637881547585D-1*T294*T266-0.1172527576309517D0*T114*T272
      T302 = 0.2697586091519874D1*T275*T118-0.2697586091519874D1*T280*T2
     #99
      T303 = T80*T302
      T304 = 1/T121
      T305 = T303*T304
      T306 = 0.2473556743557577D-1*T305
      T309 = -0.4811024840421814D1*T150-0.1895695887660258D-2*T167
      T312 = T131**2
      T313 = 1/T312
      T314 = T127*T313
      T318 = -0.1803772444038489D1*T150-0.1210946621972718D0*T167-0.1763
     #993811759022D-1*T149
      T321 = 0.1D-2*T309*T132-0.1D-2*T314*T318
      T322 = T321*T78
      T323 = T322*T144
      T324 = 0.1D1*T323
      T325 = T135*T250
      T326 = T325*T144
      T327 = 0.1D1*T326
      T329 = T135*T79*T96
      T330 = T100*RHO
      T331 = 1/T330
      T333 = T331*T250*T143
      T334 = T329*T333
      T335 = 0.522423459704672D1*T334
      T336 = T152+T173-T177-T191+T204+T215+T235+T238+T240-T242+T252+T306
     #+T324+T327-T335
      T338 = T83*RHO
      T340 = 1/T84/T338
      T344 = 1/T101/T330
      T345 = T99*T344
      T348 = -0.148092480894642D0*T82*T340-0.5071010869043442D-1*T97*T34
     #5
      T351 = T81*T340
      T356 = -0.3994922167200589D0*T108*T351-0.136794883902777D0*T114*T3
     #45
      T359 = 0.2697586091519874D1*T348*T118-0.2697586091519874D1*T280*T3
     #56
      T360 = T80*T359
      T361 = T360*T304
      T364 = SIGMA*T340*T143
      T365 = T136*T364
      T367 = T135*T80
      T368 = T100*T83
      T369 = 1/T368
      T371 = T96*T369*T143
      T372 = T367*T371
      T375 = RHO*(0.2473556743557577D-1*T361-0.2333333333333333D1*T365+0
     #.6965646129395627D1*T372)
      VRHOA(I) = RHO*T336-T22+T56+T73+T124+T146+T375
      T376 = -T197-T193
      T379 = T5+T192
      T382 = 0.1333333333333333D1*T39*T376+0.1333333333333333D1*T43*T379
      T384 = T34*T382*T53
      T385 = 0.3799552353702395D-1*T384
      T386 = T207+T211
      T388 = T34*T45*T386
      T389 = 0.3799552353702395D-1*T388
      T390 = T70*T382
      T391 = T390*T51
      T392 = 0.1923661050931536D1*T391
      T393 = 0.7694644203726145D1*T239
      T398 = 0.3333333333333333D0*T244*T376+0.3333333333333333D0*T247*T3
     #79
      T399 = T243*T398
      T400 = 0.7420670230672731D-1*T399
      T401 = T86*T398
      T404 = T152+T173-T177-T191+T385+T389+T235+T392-T393-T242
      T409 = -0.4042761511756372D2*T404*T90+0.1212828453526912D3*T261*T3
     #98
      T410 = T103*T409
      T411 = T410*T93
      T414 = T271*T398
      T417 = -0.1269364121954074D0*T253*T401-0.1086645186223595D-1*T257*
     #T411-0.4346580744894379D-1*T97*T414
      T420 = T86*T409
      T421 = T420*T93
      T424 = T287*T398
      T431 = -0.1712109500228824D0*T282*T421-0.3424219000457648D0*T108*T
     #424-0.5862637881547585D-1*T294*T411-0.1172527576309517D0*T114*T414
      T434 = 0.2697586091519874D1*T417*T118-0.2697586091519874D1*T280*T4
     #31
      T435 = T80*T434
      T436 = T435*T304
      T437 = 0.2473556743557577D-1*T436
      T438 = T135*T398
      T439 = T438*T144
      T440 = 0.1D1*T439
      T442 = T331*T398*T143
      T443 = T329*T442
      T444 = 0.522423459704672D1*T443
      T445 = T152+T173-T177-T191+T385+T389+T235+T392-T393-T242+T400+T437
     #+T324+T440-T444
      VRHOB(I) = RHO*T445-T22+T56+T73+T124+T146+T375
      T450 = 0.634682060977037D-1*T109+0.2173290372447189D-1*T108*T104
      T453 = T95*T81
      T458 = 0.1712109500228824D0*T453*T86+0.5862637881547585D-1*T281*T1
     #04
      T461 = 0.2697586091519874D1*T450*T118-0.2697586091519874D1*T280*T4
     #58
      T463 = T80*T461*T304
      T464 = 0.2473556743557577D-1*T463
      T465 = T86*T143
      T466 = T136*T465
      T467 = 0.1D1*T466
      T469 = SIGMA*T331*T143
      T470 = T367*T469
      T471 = 0.261211729852336D1*T470
      VSIGMAAA(I) = RHO*(T464+T467-T471)
      VSIGMAAB(I) = 2.D0*VSIGMAAA(I)
      VSIGMABB(I) = VSIGMAAA(I)
      T473 = 0.4947113487115154D-1*T361
      T474 = 0.4666666666666667D1*T365
      T475 = 0.1393129225879125D2*T372
      T476 = T79*T359
      T477 = T304*T250
      T479 = 0.7420670230672731D-1*T476*T477
      T482 = 0.296184961789284D0*T253*T340*T250
      T484 = T344*T264*T93
      T486 = 0.5071010869043442D-1*T257*T484
      T487 = T270*T344
      T488 = T487*T250
      T489 = T97*T488
      T494 = T348*T279
      T496 = 0.2697586091519874D1*T494*T299
      T497 = T275*T279
      T499 = 0.2697586091519874D1*T497*T356
      T502 = T107/T278/T117
      T505 = 0.5395172183039748D1*T502*T356*T299
      T509 = 0.3994922167200589D0*T282*T340*T264*T93
      T510 = T90*T340
      T513 = 0.7989844334401178D0*T108*T510*T250
      T515 = 0.273589767805554D0*T294*T484
      T516 = T114*T488
      T525 = T121**2
      T526 = 1/T525
      T529 = 0.2473556743557577D-1*T360*T526*T302
      T531 = 0.2333333333333333D1*T322*T364
      T533 = 0.2333333333333333D1*T325*T364
      T537 = 0.3308681911462923D2*T329*T369*T250*T143
      T538 = T321*T80
      T540 = 0.6965646129395627D1*T538*T371
      T541 = T135*T98
      T542 = T96*SIGMA
      T543 = T541*T542
      T544 = T100**2
      T546 = 1/T101/T544
      T550 = 0.3639016949997321D2*T543*T546*T250*T143
      T552 = RHO*(T479+0.2473556743557577D-1*T80*(0.2697586091519874D1*(
     #T482+T486+0.2028404347617377D0*T489)*T118-T496-T499+T505-0.2697586
     #091519874D1*T280*(T509+T513+T515+0.547179535611108D0*T516))*T304-T
     #529-T531-T533+T537+T540-T550)
      T566 = RHO*(T479+0.2473556743557577D-1*T80*(0.2697586091519874D1*(
     #T482+T486+0.2028404347617377D0*T489)*T118-T499-T496+T505-0.2697586
     #091519874D1*T280*(T509+T513+T515+0.547179535611108D0*T516))*T304-T
     #529-T531+T540-T533+T537-T550)
      T568 = 1/T84/T100
      T573 = T99/T101/T368
      T581 = T356**2
      T596 = T359**2
      T604 = T100*T338
      T610 = T135*T269
      T619 = RHO*(0.2473556743557577D-1*T80*(0.2697586091519874D1*(0.493
     #6416029821399D0*T82*T568+0.2873572825791284D0*T97*T573)*T118-0.539
     #5172183039748D1*T494*T356+0.5395172183039748D1*T502*T581-0.2697586
     #091519874D1*T280*(0.1331640722400196D1*T108*T81*T568+0.77517100878
     #24029D0*T114*T573))*T304-0.2473556743557577D-1*T80*T596*T526+0.777
     #7777777777778D1*T136*SIGMA*T568*T143-0.5804705107829689D2*T367*T96
     #/T604*T143+0.4852022599996427D2*T610*T542/T101/T544/RHO*T143)
      T620 = 0.2249999913366216D1*T190
      T621 = 0.3847322101863073D1*T234
      T624 = 0.1748148507797795D-2*T176
      T625 = T473-T474+T475+T552+T566+T619-T620+T621+0.7599104707404789D
     #-1*T203+0.7599104707404789D-1*T214-T624
      T626 = 0.5495546528376876D-2*T151
      T627 = 0.2D1*T172
      T630 = 0.1538928840745229D2*T241
      T634 = 0.2D1*T323
      T639 = T169**2
      T641 = T8/T153/T16*T639*T170
      T642 = 0.2D1*T641
      T645 = T150*T154*T169*T170
      T646 = 0.8837926660346786D-1*T645
      T647 = SIGMA*T99
      T648 = T250**2
      T652 = 1/T40
      T653 = T194**2
      T656 = 2.D0*T149
      T658 = 1/T48/T4
      T660 = 2.D0*T36*T658
      T661 = -T656+T660
      T664 = 1/T44
      T665 = T198**2
      T668 = -T661
      T671 = -0.1111111111111111D0*T652*T653+0.3333333333333333D0*T244*T
     #661-0.1111111111111111D0*T664*T665+0.3333333333333333D0*T247*T668
      T675 = T264**2
      T676 = T103*T675
      T678 = EXP(-0.8085523023512745D2*T91)
      T679 = T676*T678
      T682 = T114*T270
      T683 = T93*T250
      T684 = T265*T683
      T687 = T148*T658
      T688 = T687*T20
      T689 = 0.5495546528376876D-2*T688
      T692 = 1/T14/T5*T50
      T693 = T692*T20
      T694 = 0.1831848842792292D-2*T693
      T697 = 1/T158/T5*T50
      T699 = T159*T658
      T705 = 1/T12/T5*T50
      T707 = T163*T658
      T711 = 1/T6/T5*T50
      T713 = T166*T658
      T717 = T155*(-0.8309097827459833D0*T697+0.199418347859036D1*T699-0
     #.4945709824779306D0*T692+0.1483712947433792D1*T687-0.2001071587498
     #409D0*T705+0.8004286349993634D0*T707-0.4215565168327908D-1*T711+0.
     #2529339100996745D0*T713)*T170
      T718 = 0.1D1*T717
      T719 = T153**2
      T722 = T19**2
      T725 = T8/T719*T639/T722
      T726 = 0.1608197949869254D2*T725
      T738 = T225**2
      T754 = T218**2
      T757 = T66**2
      T768 = 0.8806932620892844D-3*T692*T67-0.2642079786267853D-2*T687*T
     #67-0.8497974591333914D-1*T150*T219*T225*T226-0.2D1*T58/T218/T63*T7
     #38*T226+0.1D1*T220*(-0.1544496508763151D1*T697+0.3706791621031562D
     #1*T699-0.854388052766047D0*T692+0.2563164158298141D1*T687-0.411183
     #4438919023D0*T705+0.1644733775567609D1*T707-0.5346380647307093D-1*
     #T711+0.3207828388384256D0*T713)*T226+0.3216395899738507D2*T58/T754
     #*T738/T757-0.1831848842792292D-2*T693+0.5495546528376876D-2*T688+0
     #.8837926660346786D-1*T645+0.2D1*T641-0.1D1*T717-0.1608197949869254
     #D2*T725
      T771 = 0.1923661050931536D1*T768*T45*T51
      T772 = 1/T74
      T777 = 1/T76
      T782 = 0.4444444444444444D0*T772*T653+0.1333333333333333D1*T39*T66
     #1+0.4444444444444444D0*T777*T665+0.1333333333333333D1*T43*T668
      T785 = 0.1923661050931536D1*T70*T782*T51
      T788 = 0.3799552353702395D-1*T34*T782*T53
      T789 = T236*T206
      T790 = 0.1538928840745229D2*T789
      T791 = T236*T210
      T792 = 0.1538928840745229D2*T791
      T793 = T46*T50
      T794 = T71*T793
      T795 = 0.2308393261117844D2*T794
      T796 = T205*T209
      T797 = T71*T796
      T798 = 0.6155715362980916D2*T797
      T801 = T47/T49/T48
      T803 = 0.3847322101863073D2*T71*T801
      T804 = -T642-T646-T689+T694+T718+T726+T771+T785+T788+T790-T792+T79
     #5-T798+T803
      T807 = 0.7599104707404789D-1*T34*T201*T212
      T808 = 12.D0*T793
      T809 = 32.D0*T796
      T810 = 20.D0*T801
      T814 = 0.3799552353702395D-1*T34*T45*(-T808+T809-T810)
      T816 = 0.5827161692659315D-3*T692*T175
      T821 = 0.5176049209143758D-1*T150*T179*T185*T187*T54
      T823 = T150*T174*T212
      T824 = 0.1748148507797795D-2*T823
      T827 = T150*T33*T201*T53
      T828 = 0.1748148507797795D-2*T827
      T830 = 0.1748148507797795D-2*T687*T175
      T834 = T185**2
      T837 = 0.2249999913366216D1*T24/T178/T29*T834*T189
      T840 = T186*T187*T201*T53
      T841 = 0.2249999913366216D1*T840
      T843 = 0.1538928840745229D2*T233*T210
      T845 = T232*T201*T51
      T846 = 0.3847322101863073D1*T845
      T847 = T233*T206
      T848 = 0.1538928840745229D2*T847
      T850 = T186*T188*T212
      T851 = 0.2249999913366216D1*T850
      T852 = T178**2
      T856 = T32**2
      T861 = 0.3330984244245859D2*T24/T852*T834/T856*T45*T53
      T873 = 0.1124999956683108D1*T180*(-0.1132974264373283D1*T697+0.271
     #913823449588D1*T699-0.4994648585728036D0*T692+0.1498394575718411D1
     #*T687-0.1075243117819161D0*T705+0.4300972471276643D0*T707-0.424780
     #5766949639D-1*T711+0.2548683460169784D0*T713)*T189
      T874 = T807+T814-T816+T821-T824-T828+T830+T837-T841-T843+T846+T848
     #-T851-T861-T873
      T878 = T258*T99
      T881 = T89*T270
      T886 = -0.4042761511756372D2*(T804+T874)*T90+0.2425656907053823D3*
     #T878*T250-0.4851313814107647D3*T881*T648+0.1212828453526912D3*T261
     #*T671
      T888 = T103*T886*T93
      T891 = T676*T93
      T895 = 1/T98/T79
      T896 = T895*T103
      T897 = T896*T648
      T900 = T271*T671
      T908 = T299**2
      T911 = T292*SIGMA
      T912 = T911*T81
      T913 = T86*T675
      T917 = T281*T90
      T928 = T99*T86
      T935 = T112**2
      T938 = 1/T935*T96*T99
      T941 = T293*T270
      T952 = 0.3424219000457648D0*T912*T913*T678+0.6848438000915295D0*T9
     #17*T283*T683-0.1712109500228824D0*T282*T86*T886*T93-0.171210950022
     #8824D0*T282*T913*T93+0.1027265700137294D1*T108*T928*T648-0.3424219
     #000457648D0*T108*T287*T671+0.1758791364464276D0*T938*T679+0.469011
     #0305238068D0*T941*T684-0.5862637881547585D-1*T294*T888-0.586263788
     #1547585D-1*T294*T891+0.5862637881547585D0*T114*T897-0.117252757630
     #9517D0*T114*T900
      T959 = T367*T542
      T961 = 1/T101/T604
      T966 = -T642-T646+0.2473556743557577D-1*T80*(0.2697586091519874D1*
     #(0.3808092365862222D0*T647*T86*T648-0.1269364121954074D0*T253*T86*
     #T671+0.2173290372447189D-1*T294*T679+0.8693161489788758D-1*T682*T6
     #84-0.1086645186223595D-1*T257*T888-0.1086645186223595D-1*T257*T891
     #+0.2173290372447189D0*T97*T897-0.4346580744894379D-1*T97*T900)*T11
     #8-0.5395172183039748D1*T497*T299+0.5395172183039748D1*T502*T908-0.
     #2697586091519874D1*T280*T952)*T304-T689+T694+T718+T726+T771+T785+T
     #788+T790-T792+T795-T798+T803+T807+T814+0.272926271249799D2*T959*T9
     #61*T648*T143-T816+T821
      T967 = T78*T122
      T970 = T79*T302
      T976 = T302**2
      T982 = T331*T78
      T983 = T982*T143
      T991 = T321*T79*T96
      T992 = T991*T333
      T995 = T321*T250*T144
      T1010 = T318**2
      T1024 = 0.1D1*(0.1D-2*(-0.3207349893614542D1*T692+0.96220496808436
     #27D1*T687-0.6318986292200858D-3*T711+0.3791391775320515D-2*T713)*T
     #132-0.2D-2*T309*T313*T318+0.2D-2*T127/T312/T131*T1010-0.1D-2*T314*
     #(-0.1202514962692326D1*T692+0.3607544888076978D1*T687-0.4036488739
     #909061D-1*T711+0.2421893243945437D0*T713+0.3527987623518044D-1*T65
     #8))*T78*T144
      T1028 = T848-T851-0.2473556743557577D-1*T80*T976*T526-T861-0.15672
     #70379114016D2*T135*T648*T96*T983-0.522423459704672D1*T329*T331*T67
     #1*T143-0.1044846919409344D2*T992-T873+0.2D1*T995+T1024+0.1D1*T135*
     #T671*T144
      T1032 = T626+T627+0.3847322101863073D1*T237+0.1538928840745229D2*T
     #239-T630+0.1484134046134546D0*T251-0.1044846919409344D2*T334+0.494
     #7113487115154D-1*T305+T634+0.2D1*T326+RHO*(T966-T824-T828+T830+T83
     #7+0.1484134046134546D0*T967*T648+0.1484134046134546D0*T970*T477+0.
     #7420670230672731D-1*T243*T671-T841-T843+T846+T1028)
      V2RHOA2(I) = T625+T1032
      T1033 = T304*T398
      T1035 = 0.7420670230672731D-1*T476*T1033
      T1038 = 0.296184961789284D0*T253*T340*T398
      T1040 = T344*T409*T93
      T1042 = 0.5071010869043442D-1*T257*T1040
      T1043 = T487*T398
      T1044 = T97*T1043
      T1049 = T417*T279
      T1051 = 0.2697586091519874D1*T1049*T356
      T1053 = 0.2697586091519874D1*T494*T431
      T1056 = 0.5395172183039748D1*T502*T356*T431
      T1060 = 0.3994922167200589D0*T282*T340*T409*T93
      T1063 = 0.7989844334401178D0*T108*T510*T398
      T1065 = 0.273589767805554D0*T294*T1040
      T1066 = T114*T1043
      T1075 = T526*T434
      T1077 = 0.2473556743557577D-1*T360*T1075
      T1079 = 0.2333333333333333D1*T438*T364
      T1084 = 0.3308681911462923D2*T438*T96*T369*T79*T143
      T1088 = 0.3639016949997321D2*T543*T546*T398*T143
      T1090 = RHO*(T1035+0.2473556743557577D-1*T80*(0.2697586091519874D1
     #*(T1038+T1042+0.2028404347617377D0*T1044)*T118-T1051-T1053+T1056-0
     #.2697586091519874D1*T280*(T1060+T1063+T1065+0.547179535611108D0*T1
     #066))*T304-T1077-T531+T540-T1079+T1084-T1088)
      T1092 = T619+T1090+T473-T474+T475-T620+T621-T624+T626+T627-0.15389
     #28840745229D2*T239
      T1101 = T186*T187*T382*T53
      T1102 = 0.2249999913366216D1*T1101
      T1103 = T79*T434
      T1106 = 0.6155715362980916D2*T797
      T1107 = T376**2
      T1110 = T656+T660
      T1113 = T379**2
      T1116 = -T1110
      T1119 = -0.1111111111111111D0*T652*T1107+0.3333333333333333D0*T244
     #*T1110-0.1111111111111111D0*T664*T1113+0.3333333333333333D0*T247*T
     #1116
      T1124 = T398**2
      T1131 = 0.7599104707404789D-1*T34*T382*T386
      T1132 = -T1102-T642-T646-T689+T694+T718+T726+T771+0.14841340461345
     #46D0*T1103*T1033+T795+T1106+T803-T816+T821+T830+T837-0.52242345970
     #4672D1*T329*T331*T1119*T143+0.1484134046134546D0*T967*T1124+0.7420
     #670230672731D-1*T243*T1119+T1131
      T1141 = 0.4444444444444444D0*T772*T1107+0.1333333333333333D1*T39*T
     #1110+0.4444444444444444D0*T777*T1113+0.1333333333333333D1*T43*T111
     #6
      T1144 = 0.3799552353702395D-1*T34*T1141*T53
      T1148 = 0.3799552353702395D-1*T34*T45*(-T808-T809-T810)
      T1151 = 0.1923661050931536D1*T70*T1141*T51
      T1152 = T390*T210
      T1153 = 0.1538928840745229D2*T1152
      T1154 = T434**2
      T1158 = T390*T206
      T1159 = 0.1538928840745229D2*T1158
      T1160 = T991*T442
      T1167 = T321*T398*T144
      T1179 = T150*T33*T382*T53
      T1180 = 0.1748148507797795D-2*T1179
      T1182 = T150*T174*T386
      T1183 = 0.1748148507797795D-2*T1182
      T1185 = T186*T188*T386
      T1186 = 0.2249999913366216D1*T1185
      T1188 = T232*T382*T51
      T1189 = 0.3847322101863073D1*T1188
      T1190 = 0.1538928840745229D2*T847
      T1197 = T409**2
      T1198 = T103*T1197
      T1199 = T1198*T678
      T1202 = T93*T398
      T1203 = T410*T1202
      T1206 = -T1102-T642-T646-T689+T694+T718+T726+T771+T795+T1106+T803-
     #T816+T821+T830
      T1207 = T837+T1131+T1144+T1148+T1151-T1153-T1159-T1180-T1183-T1186
     #+T1189-T843-T1190-T861-T873
      T1211 = T404*T99
      T1218 = -0.4042761511756372D2*(T1206+T1207)*T90+0.2425656907053823
     #D3*T1211*T398-0.4851313814107647D3*T881*T1124+0.1212828453526912D3
     #*T261*T1119
      T1220 = T103*T1218*T93
      T1223 = T1198*T93
      T1226 = T896*T1124
      T1229 = T271*T1119
      T1237 = T431**2
      T1240 = T86*T1197
      T1272 = 0.3424219000457648D0*T912*T1240*T678+0.6848438000915295D0*
     #T917*T420*T1202-0.1712109500228824D0*T282*T86*T1218*T93-0.17121095
     #00228824D0*T282*T1240*T93+0.1027265700137294D1*T108*T928*T1124-0.3
     #424219000457648D0*T108*T287*T1119+0.1758791364464276D0*T938*T1199+
     #0.4690110305238068D0*T941*T1203-0.5862637881547585D-1*T294*T1220-0
     #.5862637881547585D-1*T294*T1223+0.5862637881547585D0*T114*T1226-0.
     #1172527576309517D0*T114*T1229
      T1279 = 0.1D1*T135*T1119*T144-T1180-T1183-T1186+T1189-T843-T1190-T
     #861-T873+0.2473556743557577D-1*T80*(0.2697586091519874D1*(0.380809
     #2365862222D0*T647*T86*T1124-0.1269364121954074D0*T253*T86*T1119+0.
     #2173290372447189D-1*T294*T1199+0.8693161489788758D-1*T682*T1203-0.
     #1086645186223595D-1*T257*T1220-0.1086645186223595D-1*T257*T1223+0.
     #2173290372447189D0*T97*T1226-0.4346580744894379D-1*T97*T1229)*T118
     #-0.5395172183039748D1*T1049*T431+0.5395172183039748D1*T502*T1237-0
     #.2697586091519874D1*T280*T1272)*T304+T1024
      T1297 = RHO*(T1035+0.2473556743557577D-1*T80*(0.2697586091519874D1
     #*(T1038+T1042+0.2028404347617377D0*T1044)*T118-T1053-T1051+T1056-0
     #.2697586091519874D1*T280*(T1060+T1063+T1065+0.547179535611108D0*T1
     #066))*T304-T1077-T531-T1079+T1084+T540-T1088)
      T1298 = -T630+T634+0.7599104707404789D-1*T388+0.4947113487115154D-
     #1*T436+0.7599104707404789D-1*T384+0.3847322101863073D1*T391+0.1484
     #134046134546D0*T399+0.2D1*T439+RHO*(T1132+T1144+T1148+T1151-T1153-
     #0.2473556743557577D-1*T80*T1154*T526-T1159-0.1044846919409344D2*T1
     #160-0.1567270379114016D2*T135*T1124*T96*T983+0.2D1*T1167+0.2729262
     #71249799D2*T959*T961*T1124*T143+T1279)-0.1044846919409344D2*T443+T
     #1297
      V2RHOB2(I) = T1092+T1298
      T1302 = T627+T626+T204+T215+T621+T238-T630-T620+T252-T624+0.5D0*T5
     #66+0.5D0*T1090+T306+T473+0.5D0*T552
      T1303 = 0.1124999956683108D1*T1101
      T1304 = 0.7694644203726145D1*T789
      T1305 = 0.7694644203726145D1*T791
      T1306 = 0.2308393261117844D2*T794
      T1307 = -T1303-T642-T646-T689+T694+T718+T726+T771-T1304-T1305-T130
     #6+T803
      T1310 = 0.8740742538988973D-3*T823
      T1311 = 0.8740742538988973D-3*T827
      T1324 = -0.1111111111111111D0*T652*T194*T376+0.6666666666666667D0*
     #T244*T36*T658-0.1111111111111111D0*T664*T198*T379-0.66666666666666
     #67D0*T247*T36*T658
      T1329 = T398*T143
      T1337 = T961*T250
      T1341 = 0.7694644203726145D1*T1152
      T1344 = -0.2473556743557577D-1*T303*T1075-T816+T821-T1310-T1311+T8
     #30+T837+0.1D1*T135*T1324*T144-0.1567270379114016D2*T325*T96*T982*T
     #1329-0.522423459704672D1*T329*T331*T1324*T143+0.272926271249799D2*
     #T959*T1337*T1329-T1341+0.7420670230672731D-1*T970*T1033
      T1346 = 0.7694644203726145D1*T1158
      T1347 = 0.1124999956683108D1*T840
      T1351 = 0.3799552353702395D-1*T34*T201*T386
      T1364 = 0.4444444444444444D0*T772*T194*T376+0.2666666666666667D1*T
     #39*T36*T658+0.4444444444444444D0*T777*T198*T379-0.2666666666666667
     #D1*T43*T36*T658
      T1367 = 0.3799552353702395D-1*T34*T1364*T53
      T1370 = 0.3799552353702395D-1*T34*T382*T212
      T1374 = 0.3799552353702395D-1*T34*T45*(T808-T810)
      T1377 = 0.1923661050931536D1*T70*T1364*T51
      T1378 = T250*T398
      T1382 = 0.8740742538988973D-3*T1179
      T1383 = 0.8740742538988973D-3*T1182
      T1384 = T1346-T1347-0.522423459704672D1*T1160+T1351+T1367+T1370+T1
     #374+T1377+0.1484134046134546D0*T967*T1378+0.1D1*T1167-T1382-T1383
      T1385 = 0.1124999956683108D1*T1185
      T1386 = 0.1923661050931536D1*T1188
      T1387 = T254*T398
      T1393 = T678*T409
      T1394 = T265*T1393
      T1397 = T265*T1202
      T1400 = -T1303-T642-T646-T689+T694+T718+T726+T771-T1304-T1305-T130
     #6+T803-T816+T821-T1310-T1311+T830
      T1401 = 0.1923661050931536D1*T845
      T1402 = 0.1124999956683108D1*T850
      T1403 = T837-T1341+T1346-T1347+T1351+T1367+T1370+T1374+T1377-T1382
     #-T1383-T1385+T1386-T843+T1401-T1402-T861-T873
      T1415 = -0.4042761511756372D2*(T1400+T1403)*T90+0.1212828453526912
     #D3*T878*T398+0.1212828453526912D3*T1211*T250-0.4851313814107647D3*
     #T881*T1378+0.1212828453526912D3*T261*T1324
      T1417 = T103*T1415*T93
      T1420 = T409*T93
      T1421 = T265*T1420
      T1424 = T103*T250
      T1425 = T1424*T1420
      T1429 = T1424*T398
      T1432 = T271*T1324
      T1482 = 0.3424219000457648D0*T912*T283*T1393+0.3424219000457648D0*
     #T917*T283*T1202-0.1712109500228824D0*T282*T86*T1415*T93-0.17121095
     #00228824D0*T282*T283*T1420+0.3424219000457648D0*T917*T254*T1420+0.
     #1027265700137294D1*T108*T99*T1387-0.3424219000457648D0*T108*T287*T
     #1324+0.1758791364464276D0*T938*T1394+0.2345055152619034D0*T941*T13
     #97-0.5862637881547585D-1*T294*T1417-0.5862637881547585D-1*T294*T14
     #21+0.2345055152619034D0*T941*T1425+0.5862637881547585D0*T114*T895*
     #T1429-0.1172527576309517D0*T114*T1432
      T1495 = -T1385+T1386+0.2473556743557577D-1*T80*(0.2697586091519874
     #D1*(0.3808092365862222D0*T647*T1387-0.1269364121954074D0*T253*T86*
     #T1324+0.2173290372447189D-1*T294*T1394+0.4346580744894379D-1*T682*
     #T1397-0.1086645186223595D-1*T257*T1417-0.1086645186223595D-1*T257*
     #T1421+0.4346580744894379D-1*T682*T1425+0.2173290372447189D0*T97*T8
     #95*T1429-0.4346580744894379D-1*T97*T1432)*T118-0.2697586091519874D
     #1*T497*T431-0.2697586091519874D1*T1049*T299+0.5395172183039748D1*T
     #502*T299*T431-0.2697586091519874D1*T280*T1482)*T304-T843+T1401+0.7
     #420670230672731D-1*T1103*T477-T1402-T861-0.522423459704672D1*T992-
     #T873+0.1D1*T995+T1024+0.7420670230672731D-1*T243*T1324
      T1500 = T619+T475+T385+T389+T392+T400+RHO*(T1307+T1344+T1384+T1495
     #)+T327-T335+T634-T474+T437-T444+T440+0.5D0*T1297
      V2RHOAB(I) = T1302+T1500
      T1501 = T79*T461
      T1505 = T281*T99
      T1515 = T450*T279
      T1521 = T113*T81
      T1524 = T95*T90
      T1527 = T911*T99
      T1539 = T526*T461
      T1543 = 0.1D1*T322*T465
      T1545 = 0.261211729852336D1*T538*T469
      T1550 = T331*T79*T143
      T1553 = T541*T96
      T1558 = RHO*(0.7420670230672731D-1*T1501*T477+0.2473556743557577D-
     #1*T80*(0.2697586091519874D1*(-0.1269364121954074D0*T288-0.21732903
     #72447189D-1*T1505*T266-0.8693161489788758D-1*T108*T272)*T118-0.269
     #7586091519874D1*T497*T458-0.2697586091519874D1*T1515*T299+0.539517
     #2183039748D1*T502*T299*T458-0.2697586091519874D1*T280*(-0.17121095
     #00228824D0*T1521*T284-0.3424219000457648D0*T1524*T254-0.1172527576
     #309517D0*T1527*T266-0.2345055152619034D0*T281*T272))*T304-0.247355
     #6743557577D-1*T303*T1539+T1543-T1545+0.1D1*T325*T465-0.13060586492
     #6168D2*T325*SIGMA*T1550+0.1364631356248995D2*T1553*T1337*T143)
      T1597 = RHO*(0.2473556743557577D-1*T80*(0.2697586091519874D1*(-0.1
     #48092480894642D0*T351-0.1014202173808688D0*T108*T345)*T118-0.26975
     #86091519874D1*T494*T458-0.2697586091519874D1*T1515*T356+0.53951721
     #83039748D1*T502*T356*T458-0.2697586091519874D1*T280*(-0.3994922167
     #200589D0*T453*T340-0.273589767805554D0*T281*T345))*T304-0.24735567
     #43557577D-1*T360*T1539-0.2333333333333333D1*T136*T340*T143+0.20026
     #23262201243D2*T367*SIGMA*T369*T143-0.181950847499866D2*T610*T96*T5
     #46*T143)
      V2RHOASIGMAAA(I) = T1558+T464+T467-T471+T1597
      T1599 = 0.4947113487115154D-1*T463
      T1600 = 0.2D1*T466
      T1601 = 0.522423459704672D1*T470
      T1602 = 2.D0*T1597
      V2RHOASIGMAAB(I) = 2.D0*T1558+T1599+T1600-T1601+T1602
      V2RHOASIGMABB(I) = V2RHOASIGMAAA(I)
      T1647 = RHO*(0.7420670230672731D-1*T1501*T1033+0.2473556743557577D
     #-1*T80*(0.2697586091519874D1*(-0.1269364121954074D0*T424-0.2173290
     #372447189D-1*T1505*T411-0.8693161489788758D-1*T108*T414)*T118-0.26
     #97586091519874D1*T1049*T458-0.2697586091519874D1*T1515*T431+0.5395
     #172183039748D1*T502*T431*T458-0.2697586091519874D1*T280*(-0.171210
     #9500228824D0*T1521*T421-0.3424219000457648D0*T1524*T401-0.11725275
     #76309517D0*T1527*T411-0.2345055152619034D0*T281*T414))*T304-0.2473
     #556743557577D-1*T435*T1539+T1543-T1545+0.1D1*T438*T465-0.130605864
     #926168D2*T438*SIGMA*T1550+0.1364631356248995D2*T1553*T961*T398*T14
     #3)
      V2RHOBSIGMAAA(I) = T1647+T464+T467-T471+T1597
      V2RHOBSIGMAAB(I) = 2.D0*T1647+T1599+T1600-T1601+T1602
      V2RHOBSIGMABB(I) = V2RHOBSIGMAAA(I)
      T1655 = T458**2
      T1666 = T461**2
      V2SIGMAAA2(I) = RHO*(0.2473556743557577D-1*T80*(0.5862637881547585
     #D-1*T95*T99*T103*T118-0.5395172183039748D1*T1515*T458+0.5395172183
     #039748D1*T502*T1655-0.1581497040888031D0*T280*T113*T99*T103)*T304-
     #0.2473556743557577D-1*T80*T1666*T526-0.522423459704672D1*T367*T331
     #*T143+0.6823156781244976D1*T610*SIGMA*T961*T143)
      V2SIGMAAAAB(I) = 2.D0*V2SIGMAAA2(I)
      V2SIGMAAABB(I) = V2SIGMAAA2(I)
      V2SIGMAAB2(I) = 4.D0*V2SIGMAAABB(I)
      V2SIGMAABBB(I) = V2SIGMAAAAB(I)
      V2SIGMABB2(I) = V2SIGMAAABB(I)
      ENDIF ! RHOA,RHOB
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VRHOB(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      V2RHOB2(I) = 0.0D0
      V2RHOAB(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      VSIGMAAB(I) = 0.0D0
      VSIGMABB(I) = 0.0D0
      V2RHOASIGMAAA(I) = 0.0D0
      V2RHOASIGMAAB(I) = 0.0D0
      V2RHOASIGMABB(I) = 0.0D0
      V2RHOBSIGMAAA(I) = 0.0D0
      V2RHOBSIGMAAB(I) = 0.0D0
      V2RHOBSIGMABB(I) = 0.0D0
      V2SIGMAAA2(I) = 0.0D0
      V2SIGMAAB2(I) = 0.0D0
      V2SIGMABB2(I) = 0.0D0
      V2SIGMAAAAB(I) = 0.0D0
      V2SIGMAAABB(I) = 0.0D0
      V2SIGMAABBB(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
C*MODULE DFTXCB  *DECK RKS_PW91C_NWCHEM
      SUBROUTINE RKS_PW91C_NWCHEM
     & (IDERIV,NPT,RHOA1,SIGMAAA1,
     &  ZK,VRHOA,VSIGMAAA,
     &  V2RHOA2,V2RHOASIGMAAA,V2SIGMAAA2)
C
C     J.P. PERDEW, J.A. CHEVARY, S.H. VOSKO, K.A. JACKSON,
C     M.R. PEDERSON, D.J. SINGH, C. FIOLHAIS
C     ATOMS, MOLECULES, SOLIDS AND SURFACES:
C     APPLICATIONS OF THE GENERALIZED GRADIENT APPROXIMATION
C     FOR EXCHANGE AND CORRELATION
C     PHYS. REV. B 46 (1992) 6671--6687
C
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      INTEGER IDERIV,NPT
      DOUBLE PRECISION RHOA1(NPT)
      DOUBLE PRECISION SIGMAAA1(NPT)
      DOUBLE PRECISION ZK(NPT),VRHOA(NPT),VSIGMAAA(NPT)
      DOUBLE PRECISION V2RHOA2(NPT),V2RHOASIGMAAA(NPT),V2SIGMAAA2(NPT)
      PARAMETER(TOL=1.0D-20)
C
      IF(IDERIV.EQ.0) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.D0,SIGMAAA1(I))
      T2 = 1/RHO
      T3 = T2**(1.D0/3.D0)
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T17 = LOG(1.D0+0.1608197949869254D2/(0.598255043577108D1*T6+0.222
     #5569421150687D1*T3+0.8004286349993634D0*T9+0.1897004325747559D0*T1
     #1))
      T18 = (1.D0+0.1325688999052018D0*T3)*T17
      T20 = RHO**2
      T21 = RHO**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513845706671277D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMA**2
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T42 = T28**2
      T52 = LOG(1.D0+0.2697586091519874D1*(0.634682060977037D-1*SIGMA*T2
     #3+0.1086645186223595D-1*T29*T30*T35)/(1.D0+0.1712109500228824D0*T2
     #9*SIGMA*T23+0.2931318940773793D-1/T42*T30*T35))
      T70 = EXP(-0.261211729852336D1/T33/T20*SIGMA)
      ZK(I) = RHO*(-0.621814D-1*T18+0.2473556743557577D-1*T52+0.1D1*(0.1
     #D-2*(0.2568D1+0.1443307452126544D2*T3+0.2843543831490386D-2*T11)/(
     #1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T11+0.1763993811
     #759022D-1*T2)-0.1853571428571429D-2)*SIGMA*T23*T70)
      ELSE ! RHO
      ZK(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.1) THEN
C
      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.D0,SIGMAAA1(I))
      T2 = 1/RHO
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1325688999052018D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.598255043577108D1*T6+0.2225569421150687D1*T3+0.80042863499
     #93634D0*T9+0.1897004325747559D0*T11
      T16 = 1.D0+0.1608197949869254D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.621814D-1*T18
      T20 = RHO**2
      T21 = RHO**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513845706671277D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMA**2
      T31 = T29*T30
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T38 = 0.634682060977037D-1*SIGMA*T23+0.1086645186223595D-1*T31*T35
      T39 = T29*SIGMA
      T42 = T28**2
      T43 = 1/T42
      T44 = T43*T30
      T45 = T44*T35
      T47 = 1.D0+0.1712109500228824D0*T39*T23+0.2931318940773793D-1*T45
      T48 = 1/T47
      T51 = 1.D0+0.2697586091519874D1*T38*T48
      T52 = LOG(T51)
      T53 = 0.2473556743557577D-1*T52
      T56 = 0.2568D1+0.1443307452126544D2*T3+0.2843543831490386D-2*T11
      T60 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T11+0.1763
     #993811759022D-1*T2
      T61 = 1/T60
      T64 = 0.1D-2*T56*T61-0.1853571428571429D-2
      T65 = T64*SIGMA
      T70 = EXP(-0.261211729852336D1/T33/T20*SIGMA)
      T71 = T23*T70
      T73 = 0.1D1*T65*T71
      ZK(I) = RHO*(-T19+T53+T73)
      T76 = 1/T20
      T77 = 1/T11*T76
      T78 = T77*T17
      T80 = T13**2
      T83 = T6**2
      T84 = T83**2
      T94 = 1/T3*T76
      T99 = T5/T80*(-0.99709173929518D0/T84/T6*T76-0.7418564737168958D0*
     #T77-0.4002143174996817D0/T9*T76-0.1264669550498372D0*T94)/T16
      T103 = -0.1110859199549419D0*T78-0.4042761511756372D2*T99
      T108 = T47**2
      T110 = T38/T108
      T111 = T43*SIGMA
      T127 = 1/T51
      T135 = T60**2
      T152 = 1/T21/T20/RHO
      T155 = T32*RHO
      T157 = 1/T33/T155
      VRHOA(I) = RHO*(0.2747773264188438D-2*T78+0.1D1*T99+0.247355674355
     #7577D-1*(-0.2931318940773793D-1*T45*T103*T27*T48-0.269758609151987
     #4D1*T110*(-0.1712109500228824D0*T111*T23*T103*T27-0.58626378815475
     #85D-1/T42/T28*T30*T35*T103*T27))*T127+0.1D1*(0.1D-2*(-0.4811024840
     #421814D1*T77-0.1895695887660258D-2*T94)*T61-0.1D-2*T56/T135*(-0.18
     #03772444038489D1*T77-0.1210946621972718D0*T94-0.1763993811759022D-
     #1*T76))*SIGMA*T71)-T19+T53+T73+RHO*(0.2473556743557577D-1*(0.26975
     #86091519874D1*(-0.148092480894642D0*SIGMA*T152-0.5071010869043442D
     #-1*T31*T157)*T48-0.2697586091519874D1*T110*(-0.3994922167200589D0*
     #T39*T152-0.136794883902777D0*T44*T157))*T127-0.2333333333333333D1*
     #T65*T152*T70+0.6965646129395627D1*T64*T30/T32/T20*T70)
      VSIGMAAA(I) = 4.D0*RHO*(0.2473556743557577D-1*(0.2697586091519874D
     #1*(0.634682060977037D-1*T23+0.2173290372447189D-1*T39*T35)*T48-0.2
     #697586091519874D1*T110*(0.1712109500228824D0*T29*T23+0.58626378815
     #47585D-1*T111*T35))*T127+0.1D1*T64*T23*T70-0.261211729852336D1*T65
     #/T155*T70)
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ELSE IF(IDERIV.EQ.2) THEN

      DO I=1,NPT
      RHO = MAX(0.D0,RHOA1(I))
      IF(RHO.GT.TOL) THEN
      SIGMA = MAX(0.D0,SIGMAAA1(I))
      T2 = 1/RHO
      T3 = T2**(1.D0/3.D0)
      T5 = 1.D0+0.1325688999052018D0*T3
      T6 = T2**(1.D0/6.D0)
      T9 = SQRT(T2)
      T11 = T3**2
      T13 = 0.598255043577108D1*T6+0.2225569421150687D1*T3+0.80042863499
     #93634D0*T9+0.1897004325747559D0*T11
      T16 = 1.D0+0.1608197949869254D2/T13
      T17 = LOG(T16)
      T18 = T5*T17
      T19 = 0.621814D-1*T18
      T20 = RHO**2
      T21 = RHO**(1.D0/3.D0)
      T23 = 1/T21/T20
      T27 = EXP(0.2513845706671277D1*T18)
      T28 = T27-1.D0
      T29 = 1/T28
      T30 = SIGMA**2
      T31 = T29*T30
      T32 = T20**2
      T33 = T21**2
      T35 = 1/T33/T32
      T38 = 0.634682060977037D-1*SIGMA*T23+0.1086645186223595D-1*T31*T35
      T39 = T29*SIGMA
      T42 = T28**2
      T43 = 1/T42
      T44 = T43*T30
      T45 = T44*T35
      T47 = 1.D0+0.1712109500228824D0*T39*T23+0.2931318940773793D-1*T45
      T48 = 1/T47
      T51 = 1.D0+0.2697586091519874D1*T38*T48
      T52 = LOG(T51)
      T53 = 0.2473556743557577D-1*T52
      T56 = 0.2568D1+0.1443307452126544D2*T3+0.2843543831490386D-2*T11
      T60 = 1.D0+0.5411317332115466D1*T3+0.1816419932959077D0*T11+0.1763
     #993811759022D-1*T2
      T61 = 1/T60
      T64 = 0.1D-2*T56*T61-0.1853571428571429D-2
      T65 = T64*SIGMA
      T70 = EXP(-0.261211729852336D1/T33/T20*SIGMA)
      T71 = T23*T70
      T73 = 0.1D1*T65*T71
      ZK(I) = RHO*(-T19+T53+T73)
      T75 = 1/T11
      T76 = 1/T20
      T77 = T75*T76
      T78 = T77*T17
      T80 = T13**2
      T81 = 1/T80
      T82 = T5*T81
      T83 = T6**2
      T84 = T83**2
      T85 = T84*T6
      T86 = 1/T85
      T90 = 1/T9
      T93 = 1/T3
      T94 = T93*T76
      T96 = -0.99709173929518D0*T86*T76-0.7418564737168958D0*T77-0.40021
     #43174996817D0*T90*T76-0.1264669550498372D0*T94
      T97 = 1/T16
      T99 = T82*T96*T97
      T103 = -0.1110859199549419D0*T78-0.4042761511756372D2*T99
      T104 = T103*T27
      T105 = T104*T48
      T108 = T47**2
      T109 = 1/T108
      T110 = T38*T109
      T111 = T43*SIGMA
      T117 = 1/T42/T28
      T118 = T117*T30
      T120 = T35*T103*T27
      T123 = -0.1712109500228824D0*T111*T23*T103*T27-0.5862637881547585D
     #-1*T118*T120
      T126 = -0.2931318940773793D-1*T45*T105-0.2697586091519874D1*T110*T
     #123
      T127 = 1/T51
      T128 = T126*T127
      T132 = -0.4811024840421814D1*T77-0.1895695887660258D-2*T94
      T135 = T60**2
      T136 = 1/T135
      T137 = T56*T136
      T141 = -0.1803772444038489D1*T77-0.1210946621972718D0*T94-0.176399
     #3811759022D-1*T76
      T144 = 0.1D-2*T132*T61-0.1D-2*T137*T141
      T145 = T144*SIGMA
      T146 = T145*T71
      T150 = T20*RHO
      T152 = 1/T21/T150
      T155 = T32*RHO
      T157 = 1/T33/T155
      T160 = -0.148092480894642D0*SIGMA*T152-0.5071010869043442D-1*T31*T
     #157
      T165 = T44*T157
      T167 = -0.3994922167200589D0*T39*T152-0.136794883902777D0*T165
      T170 = 0.2697586091519874D1*T160*T48-0.2697586091519874D1*T110*T16
     #7
      T171 = T170*T127
      T173 = T152*T70
      T174 = T65*T173
      T176 = T64*T30
      T177 = T32*T20
      T179 = 1/T177*T70
      T180 = T176*T179
      VRHOA(I) = RHO*(0.2747773264188438D-2*T78+0.1D1*T99+0.247355674355
     #7577D-1*T128+0.1D1*T146)-T19+T53+T73+RHO*(0.2473556743557577D-1*T1
     #71-0.2333333333333333D1*T174+0.6965646129395627D1*T180)
      T187 = 0.634682060977037D-1*T23+0.2173290372447189D-1*T39*T35
      T192 = T111*T35
      T194 = 0.1712109500228824D0*T29*T23+0.5862637881547585D-1*T192
      T197 = 0.2697586091519874D1*T187*T48-0.2697586091519874D1*T110*T19
     #4
      T198 = T197*T127
      T201 = T64*T23*T70
      T203 = 1/T155
      T204 = T203*T70
      T205 = T65*T204
      VSIGMAAA(I) = 4.D0*RHO*(0.2473556743557577D-1*T198+0.1D1*T201-0.26
     #1211729852336D1*T205)
      T218 = T160*T109
      T227 = T38/T108/T47
      T245 = T51**2
      T246 = 1/T245
      T247 = T170*T246
      T259 = 1/T21/T32
      T260 = SIGMA*T259
      T263 = 1/T33/T177
      T264 = T31*T263
      T271 = T167**2
      T274 = T39*T259
      T276 = T44*T263
      T284 = T170**2
      T288 = T65*T259*T70
      T290 = T32*T150
      T293 = T176/T290*T70
      T297 = T32**2
      T309 = 1/T32
      T310 = 1/T11/T2*T309
      T311 = T310*T17
      T312 = 0.1831848842792292D-2*T311
      T313 = T80**2
      T316 = T96**2
      T317 = T16**2
      T320 = T5/T313*T316/T317
      T321 = 0.1608197949869254D2*T320
      T326 = T5/T80/T13*T316*T97
      T327 = 0.2D1*T326
      T332 = 1/T150
      T336 = T75*T332
      T346 = 1/T3/T2*T309
      T348 = T93*T332
      T352 = T82*(-0.8309097827459833D0/T85/T2*T309+0.199418347859036D1*
     #T86*T332-0.4945709824779306D0*T310+0.1483712947433792D1*T336-0.200
     #1071587498409D0/T9/T2*T309+0.8004286349993634D0*T90*T332-0.4215565
     #168327908D-1*T346+0.2529339100996745D0*T348)*T97
      T353 = 0.1D1*T352
      T354 = T336*T17
      T355 = 0.5495546528376876D-2*T354
      T358 = T77*T81*T96*T97
      T359 = 0.8837926660346786D-1*T358
      T375 = T141**2
      T389 = 0.1D1*(0.1D-2*(-0.3207349893614542D1*T310+0.962204968084362
     #7D1*T336-0.6318986292200858D-3*T346+0.3791391775320515D-2*T348)*T6
     #1-0.2D-2*T132*T136*T141+0.2D-2*T56/T135/T60*T375-0.1D-2*T137*(-0.1
     #202514962692326D1*T310+0.3607544888076978D1*T336-0.403648873990906
     #1D-1*T346+0.2421893243945437D0*T348+0.3527987623518044D-1*T332))*S
     #IGMA*T71
      T390 = T52*T76
      T402 = LOG(1.D0+0.2960874997779344D2/(0.8157414703487641D1*T6+0.2
     #247591863577616D1*T3+0.4300972471276643D0*T9+0.1911512595127338D0*
     #T11))
      T404 = (1.D0+0.6901399211255825D-1*T3)*T402*T76
      T406 = T126**2
      T408 = 0.2473556743557577D-1*T406*T246
      T410 = T103**2
      T411 = T35*T410
      T413 = EXP(0.5027691413342554D1*T18)
      T414 = T411*T413
      T416 = 0.2173290372447189D-1*T118*T414
      T417 = 0.7405727996996128D-1*T311
      T418 = 0.6501560775016922D3*T320
      T419 = 0.8085523023512745D2*T326
      T420 = 0.4042761511756372D2*T352
      T421 = 0.2221718399098838D0*T354
      T422 = 0.3572962974617552D1*T358
      T424 = T18*T76
      T426 = -T417-T418+T419-T420+T421+T422+0.1365394134884567D1*T404-0.
     #1675897137780851D1*T424
      T428 = T35*T426*T27
      T431 = T411*T27
      T433 = 0.1086645186223595D-1*T44*T431
      T441 = 0.5862637881547585D-1*T45*T104*T109*T123
      T442 = T123**2
      T444 = 0.5395172183039748D1*T227*T442
      T445 = T117*SIGMA
      T446 = T23*T410
      T449 = 0.3424219000457648D0*T445*T446*T413
      T456 = 0.1712109500228824D0*T111*T446*T27
      T458 = T42**2
      T462 = 0.1758791364464276D0/T458*T30*T414
      T466 = 0.5862637881547585D-1*T118*T431
      T474 = T312+T321-T327+T353-T355-T359+0.2222222222222222D0*T288-0.1
     #160941021565938D1*T293+T389+0.1649037829038385D-1*T390-0.337737986
     #9957684D-1*T404-T408+0.2473556743557577D-1*(0.2697586091519874D1*(
     #-0.2820809159897942D-1*T260+T416-0.1086645186223595D-1*T44*T428-T4
     #33-0.9659068321987509D-2*T264)*T48+T441+T444-0.2697586091519874D1*
     #T110*(T449-0.1712109500228824D0*T111*T23*T426*T27-T456-0.760937555
     #657255D-1*T274+T462-0.5862637881547585D-1*T118*T428-T466-0.2605616
     #836243371D-1*T276))*T127
      T483 = -T417-T418+T419-T420+T421+T422-0.1365394134884567D1*T404+0.
     #1675897137780851D1*T424
      T485 = T35*T483*T27
      T506 = T312+T321-T327+T353-T355-T359-0.2222222222222222D0*T288+0.1
     #160941021565938D1*T293+T389-0.1649037829038385D-1*T390+0.337737986
     #9957684D-1*T404-T408+0.2473556743557577D-1*(0.2697586091519874D1*(
     #0.2820809159897942D-1*T260+T416-0.1086645186223595D-1*T44*T485-T43
     #3+0.9659068321987509D-2*T264)*T48+T441+T444-0.2697586091519874D1*T
     #110*(T449-0.1712109500228824D0*T111*T23*T483*T27-T456+0.7609375556
     #57255D-1*T274+T462-0.5862637881547585D-1*T118*T485-T466+0.26056168
     #36243371D-1*T276))*T127
      S1 = 0.1099109305675375D-1*T78+0.4D1*T99+0.4D1*T146+0.989422697423
     #0308D-1*T128-0.9333333333333333D1*T174
      S2 = S1+0.2786258451758251D2*T180+0.9894226974230308D-1*T171
      S3 = S2+4.D0*RHO*(0.2473556743557577D-1*(0.136794883902777D0*T165*
     #T105-0.2697586091519874D1*T218*T123+0.2931318940773793D-1*T45*T104
     #*T109*T167+0.5395172183039748D1*T227*T167*T123-0.2697586091519874D
     #1*T110*(0.3994922167200589D0*T111*T152*T103*T27+0.273589767805554D
     #0*T118*T157*T103*T27))*T127-0.2473556743557577D-1*T247*T126-0.2333
     #333333333333D1*T145*T173+0.6965646129395627D1*T144*T30*T179)
      V2RHOA2(I) = S3+2.D0*RHO*(0.2473556743557577D-1*(0.269758609151987
     #4D1*(0.4936416029821399D0*T260+0.2873572825791284D0*T264)*T48-0.53
     #95172183039748D1*T218*T167+0.5395172183039748D1*T227*T271-0.269758
     #6091519874D1*T110*(0.1331640722400196D1*T274+0.7751710087824029D0*
     #T276))*T127-0.2473556743557577D-1*T284*T246+0.7777777777777778D1*T
     #288-0.5804705107829689D2*T293+0.4852022599996427D2*T64*T30*SIGMA/T
     #33/T297/RHO*T70)+RHO*T474+RHO*T506
      T514 = T187*T109
      S1 = 4.D0*RHO*(0.2473556743557577D-1*(-0.5862637881547585D-1*T192*
     #T105+0.2931318940773793D-1*T45*T104*T109*T194-0.2697586091519874D1
     #*T514*T123+0.5395172183039748D1*T227*T123*T194-0.2697586091519874D
     #1*T110*(-0.1712109500228824D0*T43*T23*T104-0.1172527576309517D0*T4
     #45*T120))*T127-0.2473556743557577D-1*T126*T246*T197+0.1D1*T144*T23
     #*T70-0.261211729852336D1*T145*T204)+0.9894226974230308D-1*T198
      V2RHOASIGMAAA(I) = S1+0.4D1*T201-0.1044846919409344D2*T205+4.D0*RH
     #O*(0.2473556743557577D-1*(0.2697586091519874D1*(-0.148092480894642
     #D0*T152-0.1014202173808688D0*T39*T157)*T48-0.2697586091519874D1*T2
     #18*T194-0.2697586091519874D1*T514*T167+0.5395172183039748D1*T227*T
     #167*T194-0.2697586091519874D1*T110*(-0.3994922167200589D0*T29*T152
     #-0.273589767805554D0*T111*T157))*T127-0.2473556743557577D-1*T247*T
     #197-0.2333333333333333D1*T64*T152*T70+0.2002623262201243D2*T65*T17
     #9-0.181950847499866D2*T176/T33/T297*T70)
      T588 = T194**2
      T597 = T197**2
      V2SIGMAAA2(I) = 16.D0*RHO*(0.2473556743557577D-1*(0.58626378815475
     #85D-1*T29*T35*T48-0.5395172183039748D1*T514*T194+0.539517218303974
     #8D1*T227*T588-0.1581497040888031D0*T110*T43*T35)*T127-0.2473556743
     #557577D-1*T597*T246-0.522423459704672D1*T64*T203*T70+0.68231567812
     #44976D1*T65/T33/T290*T70)
      ELSE ! RHO
      ZK(I) = 0.0D0
      VRHOA(I) = 0.0D0
      V2RHOA2(I) = 0.0D0
      VSIGMAAA(I) = 0.0D0
      V2RHOASIGMAAA(I) = 0.0D0
      V2SIGMAAA2(I) = 0.0D0
      ENDIF ! RHO
      ENDDO
C
      ENDIF ! IDERIV
      RETURN
      END
