*IF DEF,RECON                                                              VERTCLD1.2      
C *****************************COPYRIGHT******************************     VERTCLD1.3      
C (c) CROWN COPYRIGHT 1997, METEOROLOGICAL OFFICE, All Rights Reserved.    VERTCLD1.4      
C                                                                          VERTCLD1.5      
C Use, duplication or disclosure of this code is subject to the            VERTCLD1.6      
C restrictions as set forth in the contract.                               VERTCLD1.7      
C                                                                          VERTCLD1.8      
C                Meteorological Office                                     VERTCLD1.9      
C                London Road                                               VERTCLD1.10     
C                BRACKNELL                                                 VERTCLD1.11     
C                Berkshire UK                                              VERTCLD1.12     
C                RG12 2SZ                                                  VERTCLD1.13     
C                                                                          VERTCLD1.14     
C If no contract has been raised with this copy of the code, the use,      VERTCLD1.15     
C duplication or disclosure of it is strictly prohibited.  Permission      VERTCLD1.16     
C to do so must first be obtained in writing from the Head of Numerical    VERTCLD1.17     
C Modelling at the above address.                                          VERTCLD1.18     
C ******************************COPYRIGHT******************************    VERTCLD1.19     
!+ This routine vertically interpolates convective cloud base and top      VERTCLD1.20     
!                                                                          VERTCLD1.21     
! Subroutine Interface:                                                    VERTCLD1.22     

      SUBROUTINE VERT_CLD(P_FIELD_OUT,LEVELS_IN,LEVELS_OUT,                 1VERTCLD1.23     
     &                    LEN1_LEVDEPC_IN,LEN2_LEVDEPC_IN,                 VERTCLD1.24     
     &                    LEVDEPC_IN,IFIELD)                               VERTCLD1.25     
      IMPLICIT NONE                                                        VERTCLD1.26     
!                                                                          VERTCLD1.27     
! Description:                                                             VERTCLD1.28     
!   This routine takes an integer field containing level information.      VERTCLD1.29     
!   such as convective cloud base or convective cloud top and              VERTCLD1.30     
!   replaces each value to a value which represents the equivalent         VERTCLD1.31     
!   height on the output vertical coordinate system.                       VERTCLD1.32     
!                                                                          VERTCLD1.33     
!                                                                          VERTCLD1.34     
! Method:                                                                  VERTCLD1.35     
!                                                                          VERTCLD1.36     
!   (1) Read in ETA half levels for the output grid ETAH from              VERTCLD1.37     
!       namelist VERTICAL                                                  VERTCLD1.38     
!   (2) Derive ETA levels for input grid ETAL for input grid from          VERTCLD1.39     
!       level dependent constants                                          VERTCLD1.40     
!   (3) Build index array containing level on poutput dird which matches   VERTCLD1.41     
!       level on input grid                                                VERTCLD1.42     
!   (4) Replace field with equivalent value on output grid                 VERTCLD1.43     
!                                                                          VERTCLD1.44     
! Current Code Owner: D.M. Goddard                                         VERTCLD1.45     
!                                                                          VERTCLD1.46     
! History:                                                                 VERTCLD1.47     
! Version   Date     Comment                                               VERTCLD1.48     
! -------   ----     -------                                               VERTCLD1.49     
!   4.4   07/10/97   Original code. D.M. Goddard                           VERTCLD1.50     
!                                                                          VERTCLD1.51     
! Code Description:                                                        VERTCLD1.52     
!   Language: FORTRAN 77 + common extensions.                              VERTCLD1.53     
!   This code is written to UMDP3 v6 programming standards.                VERTCLD1.54     
!                                                                          VERTCLD1.55     
! System component covered: <appropriate code>                             VERTCLD1.56     
! System Task:              <appropriate code>                             VERTCLD1.57     
!                                                                          VERTCLD1.58     
! Declarations:                                                            VERTCLD1.59     
!   These are of the form:-                                                VERTCLD1.60     
!     INTEGER      ExampleVariable      !Description of variable           VERTCLD1.61     
!                                                                          VERTCLD1.62     
! Global variables (*CALLed COMDECKs etc...):                              VERTCLD1.63     
*CALL C_R_CP                                                               VERTCLD1.64     
*CALL C_MDI                                                                VERTCLD1.65     
*CALL C_VERT                                                               VERTCLD1.66     
! Subroutine arguments                                                     VERTCLD1.67     
!   Scalar arguments with intent(in):                                      VERTCLD1.68     
      INTEGER      P_FIELD_OUT         !Number of points in field          VERTCLD1.69     
      INTEGER      LEVELS_IN           !Number of levels on input grid     VERTCLD1.70     
      INTEGER      LEVELS_OUT          !Number of levels on output grid    VERTCLD1.71     
      INTEGER      LEN1_LEVDEPC_IN     !1st dim of level dependent         VERTCLD1.72     
                                       !constants on input grid            VERTCLD1.73     
      INTEGER      LEN2_LEVDEPC_IN     !2nd dim of level dependent         VERTCLD1.74     
                                       !constants on input grid            VERTCLD1.75     
!   Array  arguments with intent(in):                                      VERTCLD1.76     
      REAL         LEVDEPC_IN(LEN1_LEVDEPC_IN*LEN2_LEVDEPC_IN)             VERTCLD1.77     
!                                      !Level dependent constants on       VERTCLD1.78     
!                                      !input grid                         VERTCLD1.79     
!   Array  arguments with intent(InOut):                                   VERTCLD1.80     
      INTEGER      IFIELD(P_FIELD_OUT) !Field to be interpolated           VERTCLD1.81     
! Local scalars:                                                           VERTCLD1.82     
      INTEGER      I,J                 !Do loop indices                    VERTCLD1.83     
! Local dynamic arrays:                                                    VERTCLD1.84     
      INTEGER      INDEX(LEVELS_IN)    !Index array                        VERTCLD1.85     
      REAL         ETAL(LEVELS_IN)     !Derived ETA lvls on input grid     VERTCLD1.86     
!- End of header                                                           VERTCLD1.87     
!--------------------------------------------------------------------      VERTCLD1.88     
! 1: Read in ETA half levels for the output grid ETAH from                 VERTCLD1.89     
!    namelist VERTICAL                                                     VERTCLD1.90     
      REWIND 5                                                             VERTCLD1.91     
      READ(5,VERTICAL)                                                     VERTCLD1.92     
! 2: Derive ETA levels for input grid ETAL for input grid from             VERTCLD1.93     
!    level dependent constants                                             VERTCLD1.94     
      DO I=1,LEVELS_IN                                                     VERTCLD1.95     
        ETAL(I)=LEVDEPC_IN(I)/PREF+LEVDEPC_IN(I+LEN1_LEVDEPC_IN)           VERTCLD1.96     
      END DO                                                               VERTCLD1.97     
! 3: Build index array containing level on output grid which matches       VERTCLD1.98     
!    level on input grid                                                   VERTCLD1.99     
      DO J=1,LEVELS_IN                                                     PXVERTCD.1      
        INDEX(J)=0                                                         VERTCLD1.101    
        DO I=1,LEVELS_OUT                                                  VERTCLD1.102    
          IF(ETAL(J).LT.ETAH(I).AND.ETAL(J).GE.ETAH(I+1))INDEX(J)=I        VERTCLD1.103    
        END DO                                                             VERTCLD1.104    
      END DO                                                               VERTCLD1.105    
! 4:  Replace field with equivalent value on output grid                   VERTCLD1.106    
      DO I=1,P_FIELD_OUT                                                   VERTCLD1.107    
        IF(IFIELD(I).NE.0)IFIELD(I)=INDEX(IFIELD(I))                       VERTCLD1.108    
      END DO                                                               VERTCLD1.109    
      RETURN                                                               VERTCLD1.110    
      END                                                                  VERTCLD1.111    
*ENDIF                                                                     VERTCLD1.112