*IF DEF,A03_6A                                                             KMKH6A.2      
C *****************************COPYRIGHT******************************     KMKH6A.3      
C (c) CROWN COPYRIGHT 1997, METEOROLOGICAL OFFICE, All Rights Reserved.    KMKH6A.4      
C                                                                          KMKH6A.5      
C Use, duplication or disclosure of this code is subject to the            KMKH6A.6      
C restrictions as set forth in the contract.                               KMKH6A.7      
C                                                                          KMKH6A.8      
C                Meteorological Office                                     KMKH6A.9      
C                London Road                                               KMKH6A.10     
C                BRACKNELL                                                 KMKH6A.11     
C                Berkshire UK                                              KMKH6A.12     
C                RG12 2SZ                                                  KMKH6A.13     
C                                                                          KMKH6A.14     
C If no contract has been raised with this copy of the code, the use,      KMKH6A.15     
C duplication or disclosure of it is strictly prohibited.  Permission      KMKH6A.16     
C to do so must first be obtained in writing from the Head of Numerical    KMKH6A.17     
C Modelling at the above address.                                          KMKH6A.18     
C ******************************COPYRIGHT******************************    KMKH6A.19     
!  SUBROUTINE KMKH---------------------------------------------------      KMKH6A.20     
!!!                                                                        KMKH6A.21     
!!!  Purpose: To set the turbulent mixing coefficients KM and KH           KMKH6A.22     
!!!           (Note: should be used after any vertical interpolation       KMKH6A.23     
!!!                  but before any horizontal interpolation.)             KMKH6A.24     
!!!                                                                        KMKH6A.25     
!!!                                                                        KMKH6A.27     
!!!  Model            Modification history                                 KMKH6A.28     
!!! version  date                                                          KMKH6A.29     
!!!                                                                        KMKH6A.30     
!!!   4.4  09/09/97   New deck R.N.B.Smith                                 KMKH6A.31     
!!!  4.5    Jul. 98  Kill the IBM specific lines (JCThil)                  AJC1F405.132    
!!!                                                                        KMKH6A.32     
!!!  Programming standard:                                                 KMKH6A.33     
!!!                                                                        KMKH6A.34     
!!!  System component covered: Part of P243.                               KMKH6A.35     
!!!                                                                        KMKH6A.36     
!!!  Documentation: UMDP No.24                                             KMKH6A.37     
!!!                                                                        KMKH6A.38     
!!!---------------------------------------------------------------------   KMKH6A.39     
                                                                           KMKH6A.40     
! Arguments :-                                                             KMKH6A.41     
                                                                           KMKH6A.42     

      SUBROUTINE KMKH (                                                     4,16KMKH6A.43     
     & P_FIELD,P1,P_POINTS,BL_LEVELS                                       KMKH6A.44     
     &,RHOKM,RHO_KM,RHOKH                                                  KMKH6A.45     
     &,RHOKMZ,RHOKHZ                                                       KMKH6A.46     
     &,NTML,CUMULUS,RHOKM_TOP,RHOKH_TOP                                    ARN0F405.831    
     &,UNSTABLE,NTDSC,DSC                                                  ARN0F405.832    
     &,LTIMER                                                              KMKH6A.47     
     & )                                                                   KMKH6A.48     
                                                                           KMKH6A.49     
      IMPLICIT NONE                                                        KMKH6A.50     
                                                                           KMKH6A.51     
      LOGICAL LTIMER             ! IN Flag for TIMER diagnostics           KMKH6A.52     
                                                                           KMKH6A.53     
      INTEGER                                                              KMKH6A.54     
     & P_FIELD                ! IN No. of P-grid points in whole field     KMKH6A.55     
     &,P1                     ! IN First P-grid point to be processed.     KMKH6A.56     
     &,P_POINTS               ! IN No. of P-grid points to be              KMKH6A.57     
!                                  processed.                              KMKH6A.58     
     &,BL_LEVELS              ! IN No. of atmospheric levels for           KMKH6A.62     
!                                  which boundary layer fluxes are         KMKH6A.63     
!                                  calculated.                             KMKH6A.64     
      LOGICAL                                                              ARN0F405.833    
     & CUMULUS(P_FIELD)       ! IN Flag for cumulus the the b.l.           ARN0F405.834    
     &,UNSTABLE(P_FIELD)      ! IN Flag for unstable surface layer.        ARN0F405.835    
                                                                           KMKH6A.65     
     &,DSC(P_FIELD)           ! IN Flag set if decoupled stratocumulus     ARN0F405.836    
!                             !    layer found.                            ARN0F405.837    
      INTEGER                                                              ARN0F405.838    
     & NTML(P_FIELD)          ! IN Number of model levels in the           ARN0F405.839    
!                                   turbulently mixed layer.               ARN0F405.840    
     &,NTDSC(P_FIELD)         ! IN Top level for turbulent mixing in       ARN0F405.841    
!                             !    cloud layer.                            ARN0F405.842    
                                                                           ARN0F405.843    
      REAL                                                                 KMKH6A.66     
     & RHOKMZ(P_FIELD,2:BL_LEVELS)                                         KMKH6A.67     
!                             ! IN Non-local turbulent mixing              KMKH6A.68     
!                                  coefficient for momentum.               KMKH6A.69     
     &,RHOKHZ(P_FIELD,2:BL_LEVELS)                                         KMKH6A.70     
!                             ! IN Non-local turbulent mixing              KMKH6A.71     
!                                  coefficient for heat and moisture.      ARN0F405.844    
     &,RHOKM_TOP(P_FIELD,2:BL_LEVELS)                                      ARN0F405.845    
!                             ! IN Non-local top-down turbulent            ARN0F405.846    
!                             !    mixing coefficient for momentum.        ARN0F405.847    
     &,RHOKH_TOP(P_FIELD,2:BL_LEVELS)                                      ARN0F405.848    
!                             ! IN Non-local top-down turbulent            ARN0F405.849    
!                             !    mixing coefficient for heat             ARN0F405.850    
!                             !    and moisture.                           ARN0F405.851    
      REAL                                                                 KMKH6A.73     
     & RHOKM(P_FIELD,BL_LEVELS)                                            KMKH6A.74     
!                             ! INOUT Layer K-1 - to - layer K             KMKH6A.75     
!                                     turbulent mixing coefficient         KMKH6A.76     
!                                     for momentum.                        KMKH6A.77     
     &,RHOKH(P_FIELD,BL_LEVELS)                                            KMKH6A.78     
!                             ! INOUT Layer K-1 - to - layer K             KMKH6A.79     
!                                     turbulent mixing coefficient         KMKH6A.80     
!                                     for heat and moisture.               KMKH6A.81     
                                                                           KMKH6A.82     
      REAL                                                                 KMKH6A.83     
     & RHO_KM(P_FIELD,2:BL_LEVELS)                                         KMKH6A.84     
!                             ! OUT RHO * KM before horizontal             KMKH6A.85     
!                                   interpolation to UV-grid.              KMKH6A.86     
                                                                           KMKH6A.87     
                                                                           KMKH6A.88     
!!----------------------------------------------------------------------   KMKH6A.89     
!    External references :-                                                KMKH6A.90     
      EXTERNAL TIMER                                                       KMKH6A.91     
                                                                           KMKH6A.92     
!!----------------------------------------------------------------------   KMKH6A.93     
                                                                           KMKH6A.94     
!  Define local storage.                                                   KMKH6A.95     
                                                                           KMKH6A.96     
      INTEGER                                                              KMKH6A.97     
     & I             ! Loop counter (horizontal field index).              KMKH6A.98     
     &,K             ! Loop counter (vertical level index).                KMKH6A.99     
                                                                           KMKH6A.100    
                                                                           KMKH6A.101    
      IF (LTIMER) THEN                                                     KMKH6A.102    
        CALL TIMER('KMKH    ',3)                                           KMKH6A.103    
      ENDIF                                                                KMKH6A.104    
                                                                           KMKH6A.105    
!-----------------------------------------------------------------------   KMKH6A.106    
!! Set KM and KH to be the maximum of the local and non-local values and   KMKH6A.107    
!! store RHO_KM on P-grid for output.                                      KMKH6A.108    
!-----------------------------------------------------------------------   KMKH6A.109    
      DO K=2,BL_LEVELS                                                     KMKH6A.110    
        DO I=P1,P1+P_POINTS-1                                              KMKH6A.111    
          IF(CUMULUS(I) .AND. K.GE.NTML(I)) THEN                           ARN0F405.852    
            RHOKH(I,K) = 0.0                                               ARN0F405.853    
            RHOKM(I,K) = 0.0                                               ARN0F405.854    
          ENDIF                                                            ARN0F405.855    
          IF(UNSTABLE(I) .AND. K.GT.NTML(I)) THEN                          ARN0F405.856    
            RHOKH(I,K) = 0.0                                               ARN0F405.857    
            RHOKM(I,K) = 0.0                                               ARN0F405.858    
          ENDIF                                                            ARN0F405.859    
          IF(CUMULUS(I) .AND. K.GE.NTML(I) .AND. K.LT.NTML(I)+2) THEN      ARN0F405.860    
            RHOKHZ(I,K)=0.0                                                ARN0F405.861    
            RHOKMZ(I,K)=0.0                                                ARN0F405.862    
            RHOKH_TOP(I,K)=0.0                                             ARN0F405.863    
            RHOKM_TOP(I,K)=0.0                                             ARN0F405.864    
          ENDIF                                                            ARN0F405.865    
          IF(DSC(I) .AND. K.GT.NTDSC(I)) THEN                              ARN0F405.866    
            RHOKH(I,K) = 0.0                                               ARN0F405.867    
            RHOKM(I,K) = 0.0                                               ARN0F405.868    
          ENDIF                                                            ARN0F405.869    
!                                                                          ARN0F405.870    
          RHOKH(I,K) = MAX( RHOKH(I,K) , RHOKHZ(I,K)+RHOKH_TOP(I,K) )      ARN0F405.871    
          RHOKM(I,K) = MAX( RHOKM(I,K) , RHOKMZ(I,K)+RHOKM_TOP(I,K) )      ARN0F405.872    
!                                                                          ARN0F405.873    
          RHO_KM(I,K) = RHOKM(I,K)                                         KMKH6A.114    
        ENDDO ! P_POINTS                                                   KMKH6A.115    
      ENDDO ! BL_LEVELS                                                    KMKH6A.116    
                                                                           KMKH6A.117    
      IF (LTIMER) THEN                                                     KMKH6A.118    
        CALL TIMER('KMKH    ',4)                                           KMKH6A.119    
      ENDIF                                                                KMKH6A.120    
                                                                           KMKH6A.121    
      RETURN                                                               KMKH6A.122    
      END                                                                  KMKH6A.123    
*ENDIF                                                                     KMKH6A.124