      FUNCTION POTG(R,CGAMA)
      IMPLICIT REAL*8(A-H,O-Z)
      COMMON/SLIMIT/ISPHERE,RMLEG0,EPSLEG
      COMMON /POTPAR/PARAM(9),DISP(3),ACC(3),RINNR,WAVENO,EREL,Q,D1POT,
     XD2POT,D3POT,IPOT,IDPOT,IJWKB,IACC,IORDR,INT,IDENT,ICOUNT
      DIMENSION COEF(10)
      DATA PI/3.141592654D0/
      DATA ISKIP/0/
      RM=PARAM(2)/WAVENO
      EPS=EREL/PARAM(3)
      RC=R*RM
      IF (ISKIP.NE.0) GO TO 10
      OPEN (UNIT=9,READONLY,STATUS='OLD')
      READ (9,30000) C60,C62,C80,C82,B0,B2,E
      WRITE (6,20000) C60,C62,C80,C82,B0,B2,E
      READ (9,30000) PALFA,PBETA,BOTH,EXPEPS
      WRITE (6,10000) PALFA,PBETA,BOTH,EXPEPS
      CLOSE (UNIT=9,STATUS='KEEP')
   10 ISKIP=1
      IF (IPOT.GT.0) GO TO 20
      IPOT=-IPOT
      RETURN
   20 CONTINUE
      IF (BOTH.EQ.0.0D+00) GO TO 50
      P2=0.5D+00*(3.0D+00*CGAMA*CGAMA-1.0D+00)
      P4=(35.D0*CGAMA**4-30.D0*CGAMA**2+3.D0)/8.D0
      IF (ISPHERE.EQ.2) THEN
      P2=0.D0
      P4=0.D0
      END IF
      IF (PARAM(9).LT.0.0D+00) GO TO 30
C-------------------------------------------------------
C     ...SUM OF 3 CENTRAL FIELD POTENTIALS
C-------------------------------------------------------
      RM=PARAM(2)/WAVENO
      EPS=EREL/PARAM(3)
      RC=R*RM
      RCS=RC*RC
      E2=2.0D+00*E
      ES=E*E
      COEF(1)=EPS
      COEF(2)=RM
      COEF(3)=PARAM(4)
      COEF(4)=C60+C62*P2
      COEF(5)=C80+C82*P2
      COEF(6)=B0
      IDENTC=PARAM(8)+0.005D+00
      IF (IDENTC.EQ.5) COEF(1)=COEF(1)*DEXP(COEF(3)*COEF(2))
      POTC=CFPOT(RC,COEF,IDENTC,DPOTC)
C-------------------------------------------------------
C     ...
C-------------------------------------------------------
      COEF(1)=PARAM(6)
      COEF(2)=PARAM(5)
      COEF(3)=PARAM(7)
      IF (PARAM(7).EQ.0.0D+00) COEF(3)=PARAM(4)
      COEF(4)=0.0D+00
      COEF(5)=0.0D+00
      COEF(6)=B2
      RO1S=RCS+ES-E2*RC*CGAMA
      RO1=DSQRT(RO1S)
      IDENTO=PARAM(9)+0.005D+00
      IF (IDENTO.EQ.5) COEF(1)=COEF(1)*DEXP(COEF(3)*COEF(2))
      POTO1=CFPOT(RO1,COEF,IDENTO,DPOTO1)
      DPOTO1=DPOTO1*(RC-E*CGAMA)/RO1
C-------------------------------------------------------
C     ...
C-------------------------------------------------------
      RO2S=RCS+ES+E2*RC*CGAMA
      RO2=DSQRT(RO2S)
      POTO2=CFPOT(RO2,COEF,IDENTO,DPOTO2)
      DPOTO2=DPOTO2*(RC+E*CGAMA)/RO2
      POTG=POTO1+POTO2+POTC
      POTG=POTG/EPS
      D1POT=DPOTO1+DPOTO2+DPOTC
      D1POT=D1POT/EPS*RM
      GO TO 40
C-------------------------------------------------------
C     ...POTENTIAL PARAMETERS ARE EXPANDED IN LEGENDRE POLYNOMIALS
C-------------------------------------------------------
   30 RM=PARAM(2)/WAVENO
      EPS=EREL/PARAM(3)
      PPP=PARAM(6)
      COEF(1)=EPS*(1.0D+00+PPP*P2)
      IF (EXPEPS.LT.0.0D+00) COEF(1)=DEXP(EPS*(1.0D+00+PARAM(6)*P2))
      COEF(2)=RM+PARAM(5)*P2
      COEF(3)=PARAM(4)
      COEF(4)=C60+C62*P2
      COEF(5)=C80+C82*P2
      COEF(6)=PARAM(7)
      COEF(7)=14.861000D+00+3.266720D+00*P2+0.854280D+00*P4
      COEF(8)= 3.733307D+00+0.124534D+00*P2+0.416159D+00*P4
      IDENTC=-PARAM(9)+0.005D+00
      RC=R*RM
      POTG=CFPOT(RC,COEF,IDENTC,D1POT)
      POTG=POTG/EPS
      D1POT=D1POT*RM/EPS
      GO TO 40
C-----------------------------------------------------------------------
C THE POTENTIAL IS EXPANED IN LEGENDRE POLYNOMIALS.
C-----------------------------------------------------------------------
   45 COEF(1)=EPS
      COEF(2)=RM
      COEF(3)=PARAM(4)
      COEF(4)=C60
      COEF(5)=C80
      COEF(6)=B0
      IDENTC=-PARAM(9)+0.005D+00-6.0D+00
      RC=R*RM
      IF (IDENTC.EQ.5) COEF(1)=COEF(1)*DEXP(COEF(3)*COEF(2))
      POT0=CFPOT(RC,COEF,IDENTC,D1POT)
      POT0=POT0/EPS
      D1POT0=D1POT*RM/EPS
      COEF(1)=PARAM(6)
      COEF(2)=PARAM(5)
      COEF(3)=PARAM(7)
      IF (PARAM(7).EQ.0.0D+00) COEF(3)=PARAM(4)
      COEF(4)=C62
      COEF(5)=C82
      COEF(6)=B2
      IF (IDENTC.EQ.5) COEF(1)=COEF(1)*DEXP(COEF(3)*COEF(2))
      POT2=CFPOT(RC,COEF,IDENTC,D1POT)
      POT2=POT2/EPS
      D1POT2=D1POT*RM/EPS
      POTG=POT0+POT2*P2
      D1POT=D1POT0+D1POT2*P2
   40 CONTINUE
      IF (BOTH.GE.0.0D+00) RETURN
C-----------------------------------------------------------------------
C THIS IS REACHED IF BOTH THE MODEL POTENTIAL AND EG POTENTIALS
C ARE TO USED...
C-----------------------------------------------------------------------
      RC=R*RM
      PXXX=POTG
      DPXXX=D1POT
      CALL PACKPOT(RC,CGAMA,QSQ)
      RC=RC+0.01D+00
      CALL PACKPOT(RC,CGAMA,QSQ1)
      D1POT=(QSQ1-QSQ)/0.01D+00
      POTG=QSQ/EPS
      D1POT=D1POT/EPS*RM
      IF(RC/.0529.LT.2.0)RETURN
      RHOM=3.31D+00*DSQRT((1.0D+00-0.52D+00*(1.0D+00-CGAMA*CGAMA))/
     X     0.48D+00)
      FFF=DEXP(-(PALFA*RHOM/RC)**PBETA)
      POTG=POTG*(1.0D+00-FFF)+PXXX*FFF
      D1POT=D1POT*(1.0D+00-FFF)+DPXXX*FFF
      RETURN
C-----------------------------------------------------------------------
C EG POTENTIALS ONLY...
C-----------------------------------------------------------------------
   50 RC=R*RM
      CALL PACKPOT(RC,CGAMA,QSQ)
      RC=RC+0.01D+00
      CALL PACKPOT(RC,CGAMA,QSQ1)
      D1POT=(QSQ1-QSQ)/0.01D+00
      POTG=QSQ/EPS
      D1POT=D1POT/EPS*RM
      RETURN
10000 FORMAT(1H ,'PALFA=',F10.5,'   PBETA=',F10.5,'    BOTH=',F10.5,
     X '     EXPEPS=',F10.5)
20000 FORMAT(1H0,4HC60=F10.4,2X,4HC62=,F10.4,2X,4HC80=,F10.4,
     X 2X,4HC82=,F10.4,2X,3HB0=,F10.4,2X,3HB2=,F10.4,2X,2HZ=,F10.4)
30000 FORMAT(8F10.5)
      END
