      SUBROUTINE CFACIN(FREQ,DEPB,SVPB,DBPWLB,CGRADB,CINTB,NPB,MX)
C
C     THIS SUBROUTINE GENERATES THE COEFFICIENTS CGRADB AND CINTB 
C     IN A PIECEWISE LINEAR REPRESENTATION OF THE SQUARE OF THE 
C     COMPLEX INDEX OF REFRACTION IN THE BOTTOM.
C
C     N(Z)**2 = CGRADB(I)*Z + CINTB(I), I=1,NPB
C
      IMPLICIT REAL*8 (A-H,O-Z)
C
      COMMON /BLKEVN/ HB,CW,CB,FKW,FKB,ROHW,ROHB,ATEN
C
      DIMENSION DEPB(MX),SVPB(MX),DBPWLB(MX)
      COMPLEX*16 CGRADB(MX),CINTB(MX)
      COMPLEX*16 CI,CK,CKP1,CONSQ,CONSQP1
C
      CI=DCMPLX(0.0D0,1.0D0)
      PI=2.0D0*DACOS(0.0D0)
C
C     CONVERSION FACTOR OF DB/WAVELENGTH TO IMAG PART OF 
C     THE COMPLEX WAVE NUMBER 
C
      ETA=1.0D0/(40.0D0*PI*DLOG10(DEXP(1.0D0)))
C
      NPBM1=NPB-1
C
C     FIND THE SQUARE OF THE WAVE NUMBER AND INDEX OF REFARCTION
C     AT THE DEPB(1)
C
      CK=(2.0D0*PI*FREQ/SVPB(1))*(1.0D0+CI*ETA*DBPWLB(1))
      CONSQ=(CK/DCMPLX(FKB))**2
C
      DO 100 I=1,NPBM1
C
C     FIND THE SQUARE OF THE WAVE NUMBER AND INDEX OF REFARCTION
C     AT THE DEPB(I+1)
C
      CKP1=(2.0D0*PI*FREQ/SVPB(I+1))*(1.0D0+CI*ETA*DBPWLB(I+1))
      CONSQP1=(CKP1/DCMPLX(FKB))**2
C
C     COMPUTE THE GRADIENT AND INTERCEPT
C
      CGRADB(I)=(CONSQP1-CONSQ)/(DEPB(I+1)-DEPB(I))
      CINTB(I)=CONSQ-CGRADB(I)*DEPB(I)
C
      CONSQ=CONSQP1
C
  100 CONTINUE
C
C     THE GRADIENT IN THE LAST LAYER (NPBM1) WILL BE USED TO 
C     EXTRAPOLATE VALUES BELOW THE LAST POINT ON THE PROFILE
C
      CGRADB(NPB)=CGRADB(NPBM1)
      CINTB(NPB)=CONSQ-CGRADB(NPB)*DEPB(NPB)
C
      RETURN
      END
