SUBROUTINE Z0SEATL(&
 & KPROMA,KIDIA,KFDIA,&
 & PAPHI5,PUB5,PVB5,PSLM5,PCHAR5,&
 & PAPHI,PUB,PVB,&
 & PAZO)  

!**** *Z0SEATL* - TANGENT LINEAR OF Z0SEA

!     PURPOSE
!     -------
!          TANGENT LINEAR OF Z0SEA

!        EXPLICIT ARGUMENTS
!        ------------------
!        TRAJECTORY
!        KPROMA             - HORIZONTAL DIMENSION.                    (INPUT-C)
!        KIDIA              - INDEX OF START POINT                     (INPUT-C)
!        KFDIA              - INDEX OF END   POINT                     (INPUT-C)
!        PAPHI5(KPROMA)     - GEOPOTENTIAL MODEL LEVELS     M**2/S**2  (INPUT)
!        PUB5(KPROMA)       - U-WIND COMPONENT                 M/S     (INPUT)
!        PVB5(KPROMA)       - V-WIND COMPONENT                 M/S     (INPUT)
!        PSLM5(KPROMA)      - SEA LAND MASK                            (INPUT)
!        PCHAR5(KPROMA)     - CHARNOCK PARAMETER                       (INPUT)

!        TANGENT-LINEAR VARIABLES
!        PAPHI(KPROMA)      - GEOPOTENTIAL MODEL LEVELS     M**2/S**2  (INPUT)
!        PUB(KPROMA)        - U-WIND COMPONENT                 M/S     (INPUT)
!        PVB(KPROMA)        - V-WIND COMPONENT                 M/S     (INPUT)
!        PAZO(KPROMA)       - ROUGHNESS LENGTH                 M       (OUTPUT)

!        IMPLICIT ARGUMENTS :  NONE.
!        --------------------

!     METHOD.
!     -------
!       SOLVES Z0=Z0(UN) FOR THE FOLLOWING IMPLICIT EQUATION
!       Z0 = MOLEC.VISC + CHARNOCK
!       MOLEC.VISC = RNUM/USTAR
!       CHARNOCK   = (ALPHA/RG)*USTAR**2
!       USTAR=(RKAP/BN)*UN
!       BN=LOG(1+ZN/Z0)

!       PROVIDES PARAMETRIZED SOLUTIONS OF DIMENSIONLESS EQUATION FOR BN
!       IN CASE EITHER THE MOLEC.VISC OR CHARNOCK TERM IS NEGLECTED.
!       THEN MERGES BOTH SOLUTIONS IN A PARAMETRIZED MANNER.

!     EXTERNALS.
!     ----------
!        NONE

!     REFERENCE.
!     ----------
!        ECMWF RESEARCH DEPARTMENT DOCUMENTATION OF THE IFS

!     AUTHOR.
!     -------
!        HANS HERSBACH *ECMWF*

!        ORIGINAL   : 08-07-02
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

USE YOMCST   , ONLY : RG
USE YOEVDF   , ONLY : RKAP

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KIDIA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFDIA 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHI5(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUB5(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVB5(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSLM5(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCHAR5(KPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHI(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUB(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVB(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PAZO(KPROMA) 

INTEGER(KIND=JPIM) :: JL
REAL(KIND=JPRB), PARAMETER :: ZRN5=0.11*1.5E-5
REAL(KIND=JPRB) :: ZUMIN5,ZPOW5,ZCR5(2),ZCC5(3)
REAL(KIND=JPRB) :: ZU5,ZUK5,ZNLEV5,ZULOGR5,ZBNR5,ZULOGC5,ZBNC5,ZPR5,ZPC5,ZBN5,ZEB5
REAL(KIND=JPRB) :: ZUK,ZNLEV,ZULOGR,ZBNR,ZULOGC,ZBNC,ZBN
REAL(KIND=JPRB) :: ZHOOK_HANDLE


!     1.     DEFINITION OF THE CONSTANTS
!            ---------------------------

IF (LHOOK) CALL DR_HOOK('Z0SEATL',0,ZHOOK_HANDLE)

ZUMIN5=0.1_JPRB
ZPOW5 =-12.0_JPRB

ZCR5  = (/-1.47_JPRB, 0.93_JPRB            /)
ZCC5  = (/ 2.65_JPRB,-1.44_JPRB,-0.015_JPRB/)


!*         2.     COMPUTATION OF THE TANGENT LINEAR

DO JL=KIDIA,KFDIA
  IF(PSLM5(JL) < 0.5_JPRB) THEN

!*         2.2    RECALCULATE REQUIRED NONLINEARITIES
    ZU5=SQRT(PUB5(JL)**2+PVB5(JL)**2)
    ZUK5=RKAP*MAX(ZUMIN5,ZU5)
    ZNLEV5=PAPHI5(JL)/RG

!   MOLECULAR VISCOSITY
    ZULOGR5=LOG(ZNLEV5*ZUK5/ZRN5)
    ZBNR5=ZCR5(1) + ZCR5(2)*ZULOGR5

!   CHARNOCK
    ZULOGC5=LOG(ZUK5*ZUK5*PCHAR5(JL)/PAPHI5(JL))
    ZBNC5=ZCC5(1) + ZCC5(2)*ZULOGC5 + ZCC5(3)*ZULOGC5*ZULOGC5

!   COMBINE TOGETHER
    ZPR5=ZBNR5**ZPOW5
    ZPC5=ZBNC5**ZPOW5
    ZBN5=(ZPR5+ZPC5)**(1.0_JPRB/ZPOW5)
    ZEB5=EXP(ZBN5)

!*         2.3    TANGENT LINEAR PART

    IF(ZU5>ZUMIN5) THEN
      ZUK=RKAP*(PUB(JL)*PUB5(JL) + PVB(JL)*PVB5(JL))/ZU5
    ELSE
      ZUK=0.0_JPRB
    ENDIF
    ZNLEV=PAPHI(JL)/RG

!   MOLECULAR VISCOSITY
    ZULOGR= ZNLEV/ZNLEV5 +ZUK/ZUK5
    ZBNR  = ZULOGR*ZCR5(2)

!   CHARNOCK
    ZULOGC=ZUK*2.0_JPRB/ZUK5 - PAPHI(JL)/PAPHI5(JL)
    ZBNC  =ZULOGC*(ZCC5(2)+2.0_JPRB*ZCC5(3)*ZULOGC5)

!   COMBINE TOGETHER
    ZBN = (ZBNR*(ZPR5/ZBNR5)+ZBNC*(ZPC5/ZBNC5))*ZBN5/(ZPR5+ZPC5)
    PAZO(JL)=(ZNLEV-ZBN*ZNLEV5*ZEB5/(ZEB5-1.0_JPRB))/(ZEB5-1.0_JPRB)

  ENDIF
ENDDO

!     --------------------------------------------------------------

IF (LHOOK) CALL DR_HOOK('Z0SEATL',1,ZHOOK_HANDLE)
END SUBROUTINE Z0SEATL
