*IF DEF,A03_7A                                                             EXCOEF7A.2      
C *****************************COPYRIGHT******************************     EXCOEF7A.3      
C (c) CROWN COPYRIGHT 1998, METEOROLOGICAL OFFICE, All Rights Reserved.    EXCOEF7A.4      
C                                                                          EXCOEF7A.5      
C Use, duplication or disclosure of this code is subject to the            EXCOEF7A.6      
C restrictions as set forth in the contract.                               EXCOEF7A.7      
C                                                                          EXCOEF7A.8      
C                Meteorological Office                                     EXCOEF7A.9      
C                London Road                                               EXCOEF7A.10     
C                BRACKNELL                                                 EXCOEF7A.11     
C                Berkshire UK                                              EXCOEF7A.12     
C                RG12 2SZ                                                  EXCOEF7A.13     
C                                                                          EXCOEF7A.14     
C If no contract has been raised with this copy of the code, the use,      EXCOEF7A.15     
C duplication or disclosure of it is strictly prohibited.  Permission      EXCOEF7A.16     
C to do so must first be obtained in writing from the Head of Numerical    EXCOEF7A.17     
C Modelling at the above address.                                          EXCOEF7A.18     
C ******************************COPYRIGHT******************************    EXCOEF7A.19     
!!!  SUBROUTINE EX_COEF------------------------------------------------    EXCOEF7A.20     
!!!                                                                        EXCOEF7A.21     
!!!  Purpose: To calculate exchange coefficients for boundary layer        EXCOEF7A.22     
!!!           subroutine KMKH.                                             EXCOEF7A.23     
!!!                                                                        EXCOEF7A.24     
!!!  Suitable for single column use.                                       EXCOEF7A.25     
!!!                                                                        EXCOEF7A.26     
!!!  Model            Modification history:                                EXCOEF7A.27     
!!! version  Date                                                          EXCOEF7A.28     
!!!                                                                        EXCOEF7A.29     
!!!   4.5  13/05/98   New deck.  Richard Betts                             EXCOEF7A.30     
!!!                                                                        EXCOEF7A.31     
!!!  Documentation: UMDP No.24                                             EXCOEF7A.32     
!!!                                                                        EXCOEF7A.33     
!!!---------------------------------------------------------------------   EXCOEF7A.34     
                                                                           EXCOEF7A.35     
!!  Arguments :-                                                           EXCOEF7A.36     

      SUBROUTINE EX_COEF (                                                  5,6EXCOEF7A.37     
     & P_FIELD,P1,P_POINTS,BL_LEVELS                                       EXCOEF7A.38     
     &,CCB,CCT,NTML,L_MOM                                                  EXCOEF7A.39     
     &,CCA,DZL,RDZ,RI,U_P,V_P                                              EXCOEF7A.40     
     &,RHO,ZH,ZLB,Z0M,H_BLEND                                              EXCOEF7A.41     
     &,RHOKM,RHOKH,LTIMER                                                  EXCOEF7A.42     
     & )                                                                   EXCOEF7A.43     
                                                                           EXCOEF7A.44     
      IMPLICIT NONE                                                        EXCOEF7A.45     
                                                                           EXCOEF7A.46     
      LOGICAL LTIMER                                                       EXCOEF7A.47     
      LOGICAL                                                              EXCOEF7A.48     
     & L_MOM       ! IN Switch for convective momentum transport.          EXCOEF7A.49     
                                                                           EXCOEF7A.50     
      INTEGER                                                              EXCOEF7A.51     
     & P_FIELD     ! IN No. of P-grid points in whole field.               EXCOEF7A.52     
     &,P1          ! IN First P-grid point to be processed.                EXCOEF7A.53     
     &,P_POINTS    ! IN No. of P-grid points to be processed.              EXCOEF7A.54     
     &,BL_LEVELS   ! IN maximum number of boundary layer levels            EXCOEF7A.55     
                                                                           EXCOEF7A.56     
      INTEGER                                                              EXCOEF7A.57     
     & CCB(P_FIELD)              ! IN  Convective Cloud Base.              EXCOEF7A.58     
     &,CCT(P_FIELD)              ! IN  Convective Cloud Top.               EXCOEF7A.59     
     &,NTML(P_FIELD)             ! IN  Number of turbulently mixed         EXCOEF7A.60     
                                 !     layers.                             EXCOEF7A.61     
                                                                           EXCOEF7A.62     
      REAL                                                                 EXCOEF7A.63     
     & CCA(P_FIELD)              ! IN Convective Cloud Amount.             EXCOEF7A.64     
     &,DZL(P_FIELD,BL_LEVELS)    ! IN Layer depths (m).  DZL(,K) is the    EXCOEF7A.65     
!                                     distance from layer boundary K-1/2   EXCOEF7A.66     
!                                     to layer boundary K+1/2.  For K=1    EXCOEF7A.67     
!                                     the lower boundary is the surface.   EXCOEF7A.68     
     &,RDZ(P_FIELD,BL_LEVELS)    ! IN Reciprocal of distance between       EXCOEF7A.69     
!                                     hybrid levels (m-1).  1/RDZ(,K) is   EXCOEF7A.70     
!                                     the vertical distance from level     EXCOEF7A.71     
!                                     K-1 to level K, except that for      EXCOEF7A.72     
!                                     K=1 it is just the height of the     EXCOEF7A.73     
!                                     lowest atmospheric level.            EXCOEF7A.74     
     &,RHO(P_FIELD,BL_LEVELS)    ! IN Density at theta_levels              EXCOEF7A.75     
     &,RI(P_FIELD,2:BL_LEVELS)   ! IN Richardson number for lower          EXCOEF7A.76     
!                                     interface of layer.                  EXCOEF7A.77     
     &,U_P(P_FIELD,BL_LEVELS)    ! IN Westerly wind component on P-grid    EXCOEF7A.78     
!                                     (m per s).                           EXCOEF7A.79     
     &,V_P(P_FIELD,BL_LEVELS)    ! IN Southerly wind component on P-grid   EXCOEF7A.80     
!                                     (m per s).                           EXCOEF7A.81     
     &,ZH(P_FIELD)               ! IN Boundary layer height (m).           EXCOEF7A.82     
     &,ZLB(P_FIELD,BL_LEVELS)    ! IN ZLB(,K) is height above surface of   EXCOEF7A.83     
!                                     lower boundary of layer K (m).       EXCOEF7A.84     
     &,Z0M(P_FIELD)              ! IN Roughness length for momentum (m).   EXCOEF7A.85     
     &,H_BLEND(P_FIELD)          ! IN Blending height for effective        EXCOEF7A.86     
!                                     roughness length scheme              EXCOEF7A.87     
                                                                           EXCOEF7A.88     
      REAL                                                                 EXCOEF7A.89     
     & RHOKM(P_FIELD,BL_LEVELS)  ! INOUT Layer K-1 - to - layer K          EXCOEF7A.90     
!                                        exchange coefficient for          EXCOEF7A.91     
!                                        momentum, on UV-grid with first   EXCOEF7A.92     
!                                        and last rows set to "missing     EXCOEF7A.93     
!                                        data".Output as GAMMA*RHOKM*      EXCOEF7A.94     
!                                        RDZUV for P244 (IMPL_CAL).        EXCOEF7A.95     
     &,RHOKH(P_FIELD,BL_LEVELS)  ! OUT Layer K-1 - to - layer K            EXCOEF7A.96     
!                                      exchange coefficient for FTL,       EXCOEF7A.97     
!                                      on P-grid.Output as GAMMA*          EXCOEF7A.98     
!                                      *RHOKH*RDZ for P244(IMPL_CAL)       EXCOEF7A.99     
                                                                           EXCOEF7A.100    
!-----------------------------------------------------------------------   EXCOEF7A.101    
      EXTERNAL TIMER                                                       EXCOEF7A.102    
                                                                           EXCOEF7A.103    
!-----------------------------------------------------------------------   EXCOEF7A.104    
                                                                           EXCOEF7A.105    
!    Local and other symbolic constants :-                                 EXCOEF7A.106    
*CALL C_LHEAT                                                              EXCOEF7A.107    
*CALL C_R_CP                                                               EXCOEF7A.108    
*CALL C_EPSLON                                                             EXCOEF7A.109    
*CALL C_VKMAN                                                              EXCOEF7A.110    
                                                                           EXCOEF7A.111    
      REAL EH,EM,G0,DH,DM,LAMBDA_MIN,A_LAMBDA                              EXCOEF7A.112    
      PARAMETER (                                                          EXCOEF7A.113    
     & EH=25.0                  ! Used in calc of stability function FH.   EXCOEF7A.114    
     &,EM=4.0                   ! Used in calc of stability function FM.   EXCOEF7A.115    
     &,G0=10.0                  ! Used in stability function calcs.        EXCOEF7A.116    
     &,DH=G0/EH                 ! Used in calc of stability function FH.   EXCOEF7A.117    
     &,DM=G0/EM                 ! Used in calc of stability function FM.   EXCOEF7A.118    
     &,LAMBDA_MIN=40.0          ! Minimum value of length scale LAMBDA.    EXCOEF7A.119    
     &,A_LAMBDA=2.0             ! used in calc of LAMBDA_EFF               EXCOEF7A.120    
     &)                                                                    EXCOEF7A.121    
                                                                           EXCOEF7A.122    
                                                                           EXCOEF7A.123    
!  Define local storage.                                                   EXCOEF7A.124    
                                                                           EXCOEF7A.125    
!  Scalars.                                                                EXCOEF7A.126    
                                                                           EXCOEF7A.127    
      REAL                                                                 EXCOEF7A.128    
     & DVDZM     ! Modulus of wind shear gradient across lower level bdy   EXCOEF7A.129    
     &,DZU       ! Westerly wind shear between adjacent levels.            EXCOEF7A.130    
     &,DZV       ! Southerly wind shear between adjacent levels.           EXCOEF7A.131    
     &,DVMOD2    ! Square of modulus of wind shear between adjacent        EXCOEF7A.132    
!                  levels                                                  EXCOEF7A.133    
     &,ELH       ! Mixing length for heat & moisture at lower layer bdy.   EXCOEF7A.134    
     &,ELM       ! Mixing length for momentum at lower layer boundary.     EXCOEF7A.135    
     &,FH        ! (Value of) stability function for heat & moisture.      EXCOEF7A.136    
     &,FM        ! (Value of) stability function for momentum transport.   EXCOEF7A.137    
     &,RTMRI     ! Temporary in stability function calculation.            EXCOEF7A.138    
     &,VKZ       ! Temporary in calculation of ELH.                        EXCOEF7A.139    
     &,LAMBDAM   ! Asymptotic mixing length for turbulent transport        EXCOEF7A.140    
!                  of momentum.                                            EXCOEF7A.141    
     &,LAMBDAH   ! Asymptotic mixing length for turbulent transport        EXCOEF7A.142    
!                  of heat/moisture.                                       EXCOEF7A.143    
     &,LAMBDA_EFF! Effective mixing length used with effective             EXCOEF7A.144    
!                  roughness length scheme.                                EXCOEF7A.145    
      INTEGER                                                              EXCOEF7A.146    
     & I         ! Loop counter (horizontal field index).                  EXCOEF7A.147    
     &,K         ! Loop counter (vertical level index).                    EXCOEF7A.148    
     &,KM1       ! K-1.                                                    EXCOEF7A.149    
                                                                           EXCOEF7A.150    
! Layer interface K_LOG_LAYR-1/2 is the highest which requires log         EXCOEF7A.151    
! profile correction factors to the vertical finite differences.           EXCOEF7A.152    
! The value should be reassessed if the vertical resolution is changed.    EXCOEF7A.153    
! We could set K_LOG_LAYR = BL_LEVELS and thus apply the correction        EXCOEF7A.154    
! factors for all the interfaces treated by the boundary layer scheme;     EXCOEF7A.155    
! this would be desirable theoretically but expensive computationally      EXCOEF7A.156    
! because of the use of the log function.                                  EXCOEF7A.157    
                                                                           EXCOEF7A.158    
      INTEGER    K_LOG_LAYR                                                EXCOEF7A.159    
      PARAMETER (K_LOG_LAYR=2)                                             EXCOEF7A.160    
                                                                           EXCOEF7A.161    
      IF (LTIMER) THEN                                                     EXCOEF7A.162    
        CALL TIMER('EX_COEF ',103)                                         EXCOEF7A.163    
      ENDIF                                                                EXCOEF7A.164    
                                                                           EXCOEF7A.165    
!-----------------------------------------------------------------------   EXCOEF7A.166    
!! 1.  Loop round "boundary" levels; calculate the stability-              EXCOEF7A.167    
!!     dependent turbulent mixing coefficients.                            EXCOEF7A.168    
!-----------------------------------------------------------------------   EXCOEF7A.169    
                                                                           EXCOEF7A.170    
      DO K=2,BL_LEVELS                                                     EXCOEF7A.171    
        KM1 = K-1                                                          EXCOEF7A.172    
        DO I=P1,P1+P_POINTS-1                                              EXCOEF7A.173    
!-----------------------------------------------------------------------   EXCOEF7A.174    
!! 2.1 Calculate asymptotic mixing lengths LAMBDAM and LAMBDAH             EXCOEF7A.175    
!!     (currently assumed equal).                                          EXCOEF7A.176    
!-----------------------------------------------------------------------   EXCOEF7A.177    
                                                                           EXCOEF7A.178    
        LAMBDAM = MAX ( LAMBDA_MIN , 0.15*ZH(I) )                          EXCOEF7A.179    
        LAMBDAH = LAMBDAM                                                  EXCOEF7A.180    
        LAMBDA_EFF = MAX (LAMBDAM, A_LAMBDA*H_BLEND(I) )                   EXCOEF7A.181    
        IF ( K .GE. NTML(I) + 2) THEN                                      EXCOEF7A.182    
          LAMBDAM = LAMBDA_MIN                                             EXCOEF7A.183    
          LAMBDAH = LAMBDA_MIN                                             EXCOEF7A.184    
          IF (ZLB(I,K) .GT. A_LAMBDA*H_BLEND(I)) LAMBDA_EFF = LAMBDA_MIN   EXCOEF7A.185    
        ENDIF                                                              EXCOEF7A.186    
                                                                           EXCOEF7A.187    
!-----------------------------------------------------------------------   EXCOEF7A.188    
!! 2.2 Calculate mixing lengths ELH, ELM at layer interface K-1/2.         EXCOEF7A.189    
!-----------------------------------------------------------------------   EXCOEF7A.190    
                                                                           EXCOEF7A.191    
!  Incorporate log profile corrections to the vertical finite              EXCOEF7A.192    
!  differences into the definitions of ELM and ELH.                        EXCOEF7A.193    
!  To save computing logarithms for all K, the values of ELM and ELH       EXCOEF7A.194    
!  are unchanged for K > K_LOG_LAYR.                                       EXCOEF7A.195    
                                                                           EXCOEF7A.196    
          IF (K .LE. K_LOG_LAYR) THEN                                      EXCOEF7A.197    
            VKZ = VKMAN / RDZ(I,K)                                         EXCOEF7A.198    
            ELM = VKZ / ( LOG( ( ZLB(I,K) + Z0M(I) + 0.5*DZL(I,K)   ) /    EXCOEF7A.199    
     &                          ( ZLB(I,K) + Z0M(I) - 0.5*DZL(I,KM1) ) )   EXCOEF7A.200    
     &                     + VKZ / LAMBDA_EFF )                            EXCOEF7A.201    
            ELH = VKZ / ( LOG( ( ZLB(I,K) + Z0M(I) + 0.5*DZL(I,K)   ) /    EXCOEF7A.202    
     &                          ( ZLB(I,K) + Z0M(I) - 0.5*DZL(I,KM1) ) )   EXCOEF7A.203    
     &                     + VKZ / LAMBDAH )                               EXCOEF7A.204    
          ELSE                                                             EXCOEF7A.205    
            VKZ = VKMAN * ( ZLB(I,K) + Z0M(I) )                            EXCOEF7A.206    
            ELM = VKZ / (1.0 + VKZ/LAMBDA_EFF )                            EXCOEF7A.207    
            ELH = VKZ / (1.0 + VKZ/LAMBDAH )                               EXCOEF7A.208    
          ENDIF                                                            EXCOEF7A.209    
                                                                           EXCOEF7A.210    
!-----------------------------------------------------------------------   EXCOEF7A.211    
!! 2.3 Calculate wind shear and magnitude of gradient thereof across       EXCOEF7A.212    
!!     interface K-1/2.                                                    EXCOEF7A.213    
!-----------------------------------------------------------------------   EXCOEF7A.214    
                                                                           EXCOEF7A.215    
! Repeat of KMKH calculation, could be passed in from KMKH.                EXCOEF7A.216    
          DZU = U_P(I,K) - U_P(I,KM1)                                      EXCOEF7A.217    
          DZV = V_P(I,K) - V_P(I,KM1)                                      EXCOEF7A.218    
          DVMOD2 = MAX ( 1.0E-12 , DZU*DZU + DZV*DZV )                     EXCOEF7A.219    
          DVDZM = SQRT (DVMOD2) * RDZ(I,K)                                 EXCOEF7A.220    
                                                                           EXCOEF7A.221    
!-----------------------------------------------------------------------   EXCOEF7A.222    
!! 2.4 Calculate (values of) stability functions FH, FM.                   EXCOEF7A.223    
!-----------------------------------------------------------------------   EXCOEF7A.224    
                                                                           EXCOEF7A.225    
          IF (RI(I,K) .GE. 0.0) THEN                                       EXCOEF7A.226    
            RTMRI = 0.0                                                    EXCOEF7A.227    
            FM = 1.0 / ( 1.0 + G0*RI(I,K) )                                EXCOEF7A.228    
            FH = FM                                                        EXCOEF7A.229    
                                                                           EXCOEF7A.230    
!           !-----------------------------------------------------------   EXCOEF7A.231    
!           ! If convective cloud exists in layer K allow neutral mixing   EXCOEF7A.232    
!           ! of momentum between layers K-1 and K. This is to ensure      EXCOEF7A.233    
!           ! that a reasonable amount of momentum is mixed in the         EXCOEF7A.234    
!           ! presence of convection; it is not be required when           EXCOEF7A.235    
!           ! momentum transport is included in the convection scheme.     EXCOEF7A.236    
!           !-----------------------------------------------------------   EXCOEF7A.237    
                                                                           EXCOEF7A.238    
            IF ( .NOT.L_MOM .AND. (CCA(I) .GT. 0.0) .AND.                  EXCOEF7A.239    
     &           (K .GE. CCB(I)) .AND. (K .LT. CCT(I)) )                   EXCOEF7A.240    
     &         FM = 1.0                                                    EXCOEF7A.241    
          ELSE                                                             EXCOEF7A.242    
            RTMRI = (ELM/ELH) * SQRT ( -RI(I,K) )                          EXCOEF7A.243    
            FM = 1.0 - ( G0*RI(I,K) / ( 1.0 + DM*RTMRI ) )                 EXCOEF7A.244    
            FH = 1.0 - ( G0*RI(I,K) / ( 1.0 + DH*RTMRI ) )                 EXCOEF7A.245    
          ENDIF                                                            EXCOEF7A.246    
                                                                           EXCOEF7A.247    
!-----------------------------------------------------------------------   EXCOEF7A.248    
!! 2.5 Calculate exchange coefficients RHO*KM, RHO*KH for interface        EXCOEF7A.249    
!!     K-1/2.                                                              EXCOEF7A.250    
!-----------------------------------------------------------------------   EXCOEF7A.251    
                                                                           EXCOEF7A.252    
          RHOKM(I,K) = RHO(I, K) * ELM * ELM * DVDZM * FM                  EXCOEF7A.253    
          RHOKH(I,K) = RHO (I, K)* ELH * ELM * DVDZM * FH                  EXCOEF7A.254    
                                                                           EXCOEF7A.255    
        ENDDO ! p_points                                                   EXCOEF7A.256    
      ENDDO ! bl_levels                                                    EXCOEF7A.257    
                                                                           EXCOEF7A.258    
! Initialise unused 1st level of RHOKH to prevent compilation error        EXCOEF7A.259    
      DO I=P1,P1+P_POINTS-1                                                EXCOEF7A.260    
        RHOKH(I,1)=0.0                                                     EXCOEF7A.261    
      ENDDO                                                                EXCOEF7A.262    
                                                                           EXCOEF7A.263    
      IF (LTIMER) THEN                                                     EXCOEF7A.264    
        CALL TIMER('EX_COEF ',104)                                         EXCOEF7A.265    
      ENDIF                                                                EXCOEF7A.266    
                                                                           EXCOEF7A.267    
      RETURN                                                               EXCOEF7A.268    
      END                                                                  EXCOEF7A.269    
*ENDIF                                                                     EXCOEF7A.270