C
C *** FNC1 (The case of that SP and OP are in the surface layer,
C           and SP is deeper than OP) ***
C
      COMPLEX FUNCTION FNC1*16 (WN)
C
      IMPLICIT REAL*8(A-H,O-Z)
      COMPLEX*16 SM1,SM2,WB1,WB2,CM1,CM2,CQ1,SQ1,FF,SCM,AS,AR
      COMMON /DATA/ X,WB1,WB2,SM1,SM2,THK,SDEP,ODEP
C
      W2=WN*WN
      CM1=CDSQRT(WB1-W2)
      CM2=CDSQRT(WB2-W2)
      IF(IMAG(CM1).GT.0.D0)CM1=-CM1
      IF(IMAG(CM2).GT.0.D0)CM2=-CM2
C
      CQ1=CDCOS(THK*CM1)
      SQ1=CDSIN(THK*CM1)
      FF=DCMPLX(0.D0,1.D0)*SM2*CM2*CQ1-SM1*CM1*SQ1
      SCM=SM2*CM2/(SM1*CM1)
      CQ1=CDCOS((THK-SDEP)*CM1)
      SQ1=CDSIN((THK-SDEP)*CM1)
      AS=CQ1+DCMPLX(0.D0,1.D0)*SCM*SQ1
      AR=CDCOS(ODEP*CM1)
C
      FNC1=DCOS(WN*X)*AS*AR/FF
C
      RETURN
      END
C
C
C
C *** FNC2 (The case of that SP and OP are in the surface layer,
C           and OP is deeper than OP) ***
C
      COMPLEX FUNCTION FNC2*16 (WN)
C
      IMPLICIT REAL*8(A-H,O-Z)
      COMPLEX*16 SM1,SM2,WB1,WB2,CM1,CM2,CQ1,SQ1,FF,SCM,AS,AR
      COMMON /DATA/ X,WB1,WB2,SM1,SM2,THK,SDEP,ODEP
C
      W2=WN*WN
      CM1=CDSQRT(WB1-W2)
      CM2=CDSQRT(WB2-W2)
      IF(IMAG(CM1).GT.0.D0)CM1=-CM1
      IF(IMAG(CM2).GT.0.D0)CM2=-CM2
C
      CQ1=CDCOS(THK*CM1)
      SQ1=CDSIN(THK*CM1)
      FF=DCMPLX(0.D0,1.D0)*SM2*CM2*CQ1-SM1*CM1*SQ1
      AS=CDCOS(SDEP*CM1)
      SCM=SM2*CM2/(SM1*CM1)
      CQ1=CDCOS((THK-ODEP)*CM1)
      SQ1=CDSIN((THK-ODEP)*CM1)
      AR=CQ1+DCMPLX(0.D0,1.D0)*SCM*SQ1
C
      FNC2=DCOS(WN*X)*AS*AR/FF
C
      RETURN
      END
C
C
C
C *** FNC3 (The case of that SP is in the surface layer 
C                    and OP iS in the bedrock) ***
C
      COMPLEX FUNCTION FNC3*16 (WN)
C
      IMPLICIT REAL*8(A-H,O-Z)
      COMPLEX*16 SM1,SM2,WB1,WB2,CM1,CM2,CQ1,SQ1,FF,AS,AR
      COMMON /DATA/ X,WB1,WB2,SM1,SM2,THK,SDEP,ODEP
C
      W2=WN*WN
      CM1=CDSQRT(WB1-W2)
      CM2=CDSQRT(WB2-W2)
      IF(IMAG(CM1).GT.0.D0)CM1=-CM1
      IF(IMAG(CM2).GT.0.D0)CM2=-CM2
C
      CQ1=CDCOS(THK*CM1)
      SQ1=CDSIN(THK*CM1)
      FF=DCMPLX(0.D0,1.D0)*SM2*CM2*CQ1-SM1*CM1*SQ1
      AS=CDCOS(SDEP*CM1)
      AR=CDEXP(-DCMPLX(0.D0,1.D0)*ODEP*CM2)
C
      FNC3=DCOS(WN*X)*AS*AR/FF
C
      RETURN
      END
C
C
C
C *** FNC4 (Case of that SP is in the bedrock
C                    and OP iS in the surface layer) ***
C
      COMPLEX FUNCTION FNC4*16 (WN)
C
      IMPLICIT REAL*8(A-H,O-Z)
      COMPLEX*16 SM1,SM2,WB1,WB2,CM1,CM2,CQ1,SQ1,FF,SCM,AS,AR
      COMMON /DATA/ X,WB1,WB2,SM1,SM2,THK,SDEP,ODEP
C
      W2=WN*WN
      CM1=CDSQRT(WB1-W2)
      CM2=CDSQRT(WB2-W2)
      IF(IMAG(CM1).GT.0.D0)CM1=-CM1
      IF(IMAG(CM2).GT.0.D0)CM2=-CM2
C
      CQ1=CDCOS(THK*CM1)
      SQ1=CDSIN(THK*CM1)
      FF=DCMPLX(0.D0,1.D0)*SM2*CM2*CQ1-SM1*CM1*SQ1
      AS=CDEXP(-DCMPLX(0.D0,1.D0)*SDEP*CM2)
      AR=CDCOS(ODEP*CM1)
C
      FNC4=DCOS(WN*X)*AS*AR/FF
C
      RETURN
      END
C
C
C
C *** FNC5 (Case of that SP and OP are in the bedrock,
C           and SP is deeper than OP) ***
C
      COMPLEX FUNCTION FNC5*16 (WN)
C
      IMPLICIT REAL*8(A-H,O-Z)
      COMPLEX*16 SM1,SM2,WB1,WB2,CM1,CM2,CQ1,SQ1,CQ2,SQ2
     *          ,FF,SCM,AS,AR
      COMMON /DATA/ X,WB1,WB2,SM1,SM2,THK,SDEP,ODEP
C
      W2=WN*WN
      CM1=CDSQRT(WB1-W2)
      CM2=CDSQRT(WB2-W2)
      IF(IMAG(CM1).GT.0.D0)CM1=-CM1
      IF(IMAG(CM2).GT.0.D0)CM2=-CM2
C
      CQ1=CDCOS(THK*CM1)
      SQ1=CDSIN(THK*CM1)
      FF=DCMPLX(0.D0,1.D0)*SM2*CM2*CQ1-SM1*CM1*SQ1
      AS=CDEXP(-DCMPLX(0.D0,1.D0)*SDEP*CM2)
      SCM=SM1*CM1/(SM2*CM2)
      CQ2=CDCOS(ODEP*CM2)
      SQ2=CDSIN(ODEP*CM2)
      AR=CQ2*CQ1-SQ2*SQ1*SCM
C
      FNC5=DCOS(WN*X)*AS*AR/FF
C
      RETURN
      END
C
C
C
C *** FNC6 (Case of that SP and OP are in the bedrock,
C           and OP is deeper than SP) ***
C
      COMPLEX FUNCTION FNC6*16 (WN)
C
      IMPLICIT REAL*8(A-H,O-Z)
      COMPLEX*16 SM1,SM2,WB1,WB2,CM1,CM2,CQ1,SQ1,CQ2,SQ2
     *          ,FF,SCM,AS,AR
      COMMON /DATA/ X,WB1,WB2,SM1,SM2,THK,SDEP,ODEP
C
      W2=WN*WN
      CM1=CDSQRT(WB1-W2)
      CM2=CDSQRT(WB2-W2)
      IF(IMAG(CM1).GT.0.D0)CM1=-CM1
      IF(IMAG(CM2).GT.0.D0)CM2=-CM2
C
      CQ1=CDCOS(THK*CM1)
      SQ1=CDSIN(THK*CM1)
      FF=DCMPLX(0.D0,1.D0)*SM2*CM2*CQ1-SM1*CM1*SQ1
      SCM=SM1*CM1/(SM2*CM2)
      CQ2=CDCOS(SDEP*CM2)
      SQ2=CDSIN(SDEP*CM2)
      AS=CQ2*CQ1-SQ2*SQ1*SCM
      AR=CDEXP(-DCMPLX(0.D0,1.D0)*ODEP*CM2)
C
      FNC6=DCOS(WN*X)*AS*AR/FF
C
      RETURN
      END
