      SUBROUTINE PAULI (DDINV,NCH)
C *** SEE R H LANDAU, PROGRAM LPOTT, 1981
C     CALCULATES MODIFICATION OF PI N DENOMINATOR FUNCTION FROM PAULI
C     AUTHOR..A.W.THOMAS
      IMPLICIT  REAL*8   (A-H,O-Z)
      COMMON /ENPAUL/ PF,AK,AKD,CSKKD,XI,E,XON
      COMMON /ENINT/ AA,BB,LPAULI
      COMMON /DEINT/ ANS
      COMMON /ENQAV/ XIP
      COMPLEX*16 DDINV,CI,ANS
C     COMPLEX CMPLX
      LOGICAL LIN,LXIP,LDIFF,LPAULI,L1,L2
C
      DATA LIN/.FALSE./
      DATA EPS1,EPS2,EPS1H,EPS5,CI/0.1,0.01,0.05,0.00001,(0.0,1.0)/
      IF (LIN) GO TO 10
      LIN = .TRUE.
      AMPI = 137.3/197.33
      AMN = 938.91/197.33
      AMPISQ = AMPI**2
C     CARD GONE
      PI = 3.14159265
 10   CONTINUE
C
C     CALCULATE XIP PARAMETER...AND CARRY OUT TESTS..
C     ALL MOMENTA ,ENERGIES ETC. IN FM**-1
      XIP = AK**2+AKD**2+2.0*AK*AKD*CSKKD
      XIP = XI*SQRT(XIP)/2.0
      LXIP = .TRUE.
      IF (XIP.LT.EPS2) LXIP = .FALSE.
      DIFF = PF-XIP
      LDIFF = .TRUE.
      IF (ABS(DIFF).LT.EPS1) LDIFF = .FALSE.
      IF (LDIFF) GO TO 20
      GO TO 150
C
C     HERE WE ARE GAURANTEED  REASONABLE SIZE FOR DIFF...
 20   CONTINUE
      IF (DIFF.LT.0.0) GO TO 110
C
C     NOW THERE 2 CORRN. INTEGRALS..
C      I.E. PF.GT.XIP,AND PF-XIP GT EPS2  (C.F. EQU.(2) P10)
      LPAULI = .FALSE.
      AA = 0.0
      BB = DIFF
C         FIRST CHECK UNLIKELY COINCIDENCE GIVING TROUBLE..
      IF (E.LT.0.0) GO TO 30
      IF (ABS(DIFF-XON).GT.EPS5) GO TO 30
      PRINT 230, DIFF,XON
      STOP
 30   CONTINUE
      CALL INTGL (NCH)
      DDINV = ANS
C
C      NOW FOR SECOND INTEGRAL
      IF (LXIP) GO TO 40
      GO TO 60
C
C      HERE 2ND INTERVAL IS GT =01.
 40   CONTINUE
      AA = DIFF
      BB = PF+XIP
      LPAULI = .TRUE.
C
C     UNLIKELY COINCIDENCE&
      IF (E.LT.0.0) GO TO 50
      IF (ABS(BB-XON).GT.EPS5) GO TO 50
      PRINT 240, BB,XON
      STOP
 50   CONTINUE
      CALL INTGL (NCH)
      GO TO 100
C
C       HERE XIP IS LT =01
 60   CONTINUE
      IF (E.LT.0.0) GO TO 90
      AA = DIFF
      BB = PF+XIP
      L1 = XON.GT.AA
      L2 = XON.LT.BB
      IF (ABS(XON-BB).GT.EPS5) GO TO 70
      PRINT 250, XON,BB
      STOP
 70   CONTINUE
      IF (L1.AND.L2) GO TO 80
      GO TO 90
C
C     HERE WE HAVE XON IN INTERVAL OF SIZE LT =01---USE APPENDIX 1.
 80   CONTINUE
      WPF = SQRT(AMPISQ+PF**2)
      AMU = WPF*AMN/(AMN+WPF)
      RANS = AMU*G(PF,NCH)**2*PF/2.0
      ANS = RANS*LOG((XON-AA)/(BB-XON))
      ANS = ANS-CI*(RANS*PI)
      GO TO 100
C
C     HERE THE INTERVAL IS LT =01 , BUT NO SINGULARIYT(APPENDIX 1)
 90   CONTINUE
      PFSQ = PF**2
      WPF = SQRT(AMPISQ+PFSQ)
      EPF = WPF-AMPI+PFSQ/(2.0*AMN)
      RANS = XIP*PFSQ*G(PF,NCH)**2
      RANS = RANS/(E-EPF)
      XZERO=0.D0
      ANS = CMPLX(RANS,XZERO)
C
C       NOW PUT THE 2 INTEGRALS TOGETHER..
 100  CONTINUE
      DDINV = DDINV+ANS
      RETURN
C
C     THIS IS THE ENTRY TO PART OF PROGRAM DEALING WITH XIP.GT.PF..
 110  CONTINUE
C     THERE IS NOW ONLY ONE INTEGRAL(SEE EQU. 4)
      AA = -DIFF
      BB = PF+XIP
      IF (PF.GT.EPS2) GO TO 120
      PRINT 260, PF
      STOP
 120  CONTINUE
      IF (E.LT.0.0) GO TO 140
      IF (ABS(XON-AA).GT.EPS5) GO TO 130
      PRINT 270, XON,AA
      STOP
 130  IF (ABS(XON-BB).GT.EPS5) GO TO 140
      PRINT 280, XON,BB
      STOP
C
 140  CONTINUE
C     NOW THERE ARE NO END PT. PROBLEMS..
      LPAULI = .TRUE.
      CALL INTGL (NCH)
      DDINV = ANS
      RETURN
C
 150  CONTINUE
C
C     COME HERE ONLT IF /PF-XIP/ LT .1
C      THUS,IF XIP IS SMALL ,SO ISPF,AND WHOLE PAULI CORRN IS SMALL..
      IF (LXIP) GO TO 160
C   ***                                                        *******
      DDINV = (0.0,0.0)
C   ***                                                        *******
      RETURN
 160  CONTINUE
C     HERE NEITHER XIP NOR PF IS RIDICULUSLY SMALL..
      IF (DIFF.GT.0.0) GO TO 170
      GO TO 200
C   ***                                                        *******
C     HERE PF GT XIP. USE EQU. 2--ONCE AGAIN NEGLECT SMALL INTERVAL..
C   ***                                                        *******
 170  CONTINUE
      AA = DIFF
      BB = DIFF+2.0*XIP
      LPAULI = .TRUE.
      IF (E.LT.0.0) GO TO 180
      L1 = ABS(XON-AA).LT.EPS5
      L2 = ABS(XON-BB).LT.EPS5
      IF (L1.OR.L2) GO TO 190
 180  CONTINUE
C
C     HERE THERE ARE NO END PT PROBLEMS
      CALL INTGL (NCH)
      DDINV = ANS
      RETURN
 190  PRINT 290, XON,AA,BB
      STOP
C
 200  CONTINUE
C     HERE XIP.GT.PF..(EQU. 4 )
      AA = -DIFF
      BB = -DIFF+2.0*PF
      LPAULI = .TRUE.
      IF (E.LT.0.0) GO TO 210
      L1 = ABS(XON-AA).LT.EPS5
      L2 = ABS(XON-BB).LT.EPS5
      IF (L1.OR.L2) GO TO 220
 210  CONTINUE
      CALL INTGL (NCH)
      DDINV = ANS
      RETURN
C
 220  PRINT 300, XON,AA,BB
      STOP
C
 230  FORMAT (30H POSSIBLE ERROR IN PAULI (15) ,2F20.8)
 240  FORMAT (18H PAULI ERROR (35) ,2F20.8)
 250  FORMAT (19H PAULI ERROR (105) ,2F20.8)
 260  FORMAT (17H PAULI ERROR 305 ,F20.8)
 270  FORMAT (11H PAULI 315 ,2F20.8)
 280  FORMAT (11H PAULI 325 ,2F20.8)
 290  FORMAT (7H 560 = ,3F20.8)
 300  FORMAT (7H 660 = ,3F20.8)
      END
