*IF DEF,OCEAN                                                              COXCNVC.2      
C ******************************COPYRIGHT******************************    COXCNVC.3      
C (c) CROWN COPYRIGHT 1997, METEOROLOGICAL OFFICE, All Rights Reserved.    COXCNVC.4      
C                                                                          COXCNVC.5      
C Use, duplication or disclosure of this code is subject to the            COXCNVC.6      
C restrictions as set forth in the contract.                               COXCNVC.7      
C                                                                          COXCNVC.8      
C                Meteorological Office                                     COXCNVC.9      
C                London Road                                               COXCNVC.10     
C                BRACKNELL                                                 COXCNVC.11     
C                Berkshire UK                                              COXCNVC.12     
C                RG12 2SZ                                                  COXCNVC.13     
C                                                                          COXCNVC.14     
C If no contract has been raised with this copy of the code, the use,      COXCNVC.15     
C duplication or disclosure of it is strictly prohibited.  Permission      COXCNVC.16     
C to do so must first be obtained in writing from the Head of Numerical    COXCNVC.17     
C Modelling at the above address.                                          COXCNVC.18     
C ******************************COPYRIGHT******************************    COXCNVC.19     
C ****************************ACKNOWLEDGMENT***************************    COXCNVC.20     
C This code is derived from Public Domain code (the Cox 1984 Ocean         COXCNVC.21     
C Model) distributed by the Geophysical Fluid Dynamics Laboratory.         COXCNVC.22     
C               NOAA                                                       COXCNVC.23     
C               PO Box 308                                                 COXCNVC.24     
C               Princeton                                                  COXCNVC.25     
C               New Jersey USA                                             COXCNVC.26     
C If you wish to obtain a copy of the original code that does not have     COXCNVC.27     
C Crown Copyright use, duplication or disclosure restrictions, please      COXCNVC.28     
C contact them at the above address.                                       COXCNVC.29     
C ****************************ACKNOWLEDGMENT***************************    COXCNVC.30     
C                                                                          COXCNVC.31     
C     Subroutine COXCNVC                                                   COXCNVC.32     
C                                                                          COXCNVC.33     
C     This is the original Cox convection scheme.                          COXCNVC.34     
C                                                                          COXCNVC.35     
C     It runs through all ocean levels a number of times, mixing           COXCNVC.36     
C     adjacent levels where the lower has a lower density. Each time       COXCNVC.37     
C     it goes through the whole set of levels, it does it in two           COXCNVC.38     
C     passes: firstly over odd levels, then even.                          COXCNVC.39     
C                                                                          COXCNVC.40     
C     History:                                                             COXCNVC.41     
C                                                                          COXCNVC.42     
C     4.2  Restored to the UM for use by HADCM2 in particular, having      COXCNVC.43     
C          been removed at 4.0 in favour of the Rahmstorf scheme.          COXCNVC.44     
C          This code was formerly in-line in TRACER. JMG 8.11.96           COXCNVC.45     
!    4.4  10/09/97  Remove all references to SKIPLAND code. R.Hill         ORH7F404.4      
C                                                                          COXCNVC.46     
C----------------------------------------------------------------------    COXCNVC.47     
C                                                                          COXCNVC.48     

      SUBROUTINE COXCNVC(                                                   1,1COXCNVC.49     
     & NT,NTMIN2,IMT,IMTM1,JMT,J,KM,KMM1,KMP1,KMP2                         COXCNVC.50     
     &,DZ,DZZ2R,RZ,RZZ2R                                                   COXCNVC.52     
     &,TCHECK,TDIF,TA                                                      COXCNVC.53     
     & )                                                                   COXCNVC.54     
C                                                                          COXCNVC.55     
      IMPLICIT NONE                                                        COXCNVC.56     
C                                                                          COXCNVC.57     
C Arguments ------------------------------------------------------         COXCNVC.58     
C                                                                          COXCNVC.59     
      INTEGER                                                              COXCNVC.60     
     & NT               ! IN Number of tracers                             COXCNVC.61     
     &,NTMIN2           ! IN NT+1/NT                                       COXCNVC.62     
     &,IMT              ! IN Row length                                    COXCNVC.63     
     &,IMTM1            ! IN Row length - 1                                COXCNVC.64     
     &,JMT              ! IN Number of rows                                COXCNVC.65     
     &,J                ! IN current row number                            COXCNVC.66     
     &,KM               ! IN Number of levels                              COXCNVC.67     
     &,KMM1             ! IN Number of levels - 1                          COXCNVC.68     
     &,KMP1             ! IN Number of levels + 1                          COXCNVC.69     
     &,KMP2             ! IN Number of levels + 2                          COXCNVC.70     
C                                                                          COXCNVC.78     
      REAL                                                                 COXCNVC.79     
     & DZ   ( KM)       ! IN Layer thickness                               COXCNVC.80     
     &,DZZ2R(KMP1)      ! IN Half spacing between layer centres            COXCNVC.81     
     &,RZ(KM)           ! IN Array of level thicknesses, scaled by RAT     COXCNVC.82     
     &,RZZ2R(KMP1)      ! IN The reciprocal of twice RZZ                   COXCNVC.83     
     &,TCHECK           ! IN A temperature slightly above freezing         COXCNVC.84     
     &,TDIF(IMT,KMP2,NTMIN2)       ! INOUT workspace                       COXCNVC.85     
     &,TA(IMT,KM,NT)    ! INOUT Tracer prognostic variable                 COXCNVC.86     
C                                                                          COXCNVC.87     
      EXTERNAL STATEC                                                      COXCNVC.88     
C                                                                          COXCNVC.89     
*CALL CNTLOCN                                                              COXCNVC.90     
C                                                                          COXCNVC.91     
C      Local variables                                                     COXCNVC.92     
C                                                                          COXCNVC.93     
      INTEGER                                                              COXCNVC.94     
     & K                ! Loop variable (level)                            COXCNVC.95     
     &,I                ! Loop variable (column)                           COXCNVC.96     
     &,NCON             ! No of passes to make on convection               COXCNVC.97     
     &,N                ! Loop variable (iteration)                        COXCNVC.98     
     &,KS               ! Loop variable (first level considered)           COXCNVC.99     
     &,M                ! Loop variable (tracer)                           COXCNVC.100    
     &,ISG              ! Loop variable (segment)                          COXCNVC.101    
     &,ISGS             ! Start column in segment                          COXCNVC.102    
     &,ISGF             ! Finish column in segment                         COXCNVC.103    
C                                                                          COXCNVC.104    
      REAL                                                                 COXCNVC.105    
     & FX               ! Temporary variable                               COXCNVC.106    
     &,TEMPA(IMT,KMP1 ) ! Temporary work space                             COXCNVC.107    
C                                                                          COXCNVC.108    
C                                                                          COXCNVC.109    
C  SET NCON FOR NUMBER OF PASSES THROUGH CONVECTION LOOP                   COXCNVC.110    
C  KS=1: COMPARE LEV. 1 TO 2; 3 TO 4; ETC. AND ADJUST IF NECESSARY         COXCNVC.111    
C  KS=2: COMPARE LEV. 2 TO 3; 4 TO 5; ETC. AND ADJUST IF NECESSARY         COXCNVC.112    
C                                                                          COXCNVC.113    
      NCON=5      ! Was set to 1 in original Cox code  RAW 05/11/91        COXCNVC.114    
                                                                           COXCNVC.115    
C                                                                          COXCNVC.127    
      DO N=1,NCON                                                          COXCNVC.128    
      DO KS=1,2                                                            COXCNVC.129    
C                                                                          COXCNVC.130    
C  1ST, FIND DENSITY FOR ENTIRE SLAB FOR STABILITY DETERMINATION           COXCNVC.131    
C                                                                          COXCNVC.132    
        CALL STATEC(TA,TA(1,1,2),TEMPA,TDIF,TDIF(1,1,2),KS,IMT,KM,J        COXCNVC.133    
     &  ,JMT                                                               ORH7F404.5      
     &  )                                                                  COXCNVC.136    
C                                                                          COXCNVC.137    
C  2ND, FOR EACH TRACER, MIX ADJOINING LEVELS IF UNSTABLE                  COXCNVC.138    
C  Convection is suppressed at pseudo-ice points                           COXCNVC.139    
C                                                                          COXCNVC.140    
        DO K=KS,KMM1,2                                                     COXCNVC.141    
        DO M=1,NT                                                          COXCNVC.142    
C                                                                          COXCNVC.143    
C                                                                          COXCNVC.168    
            DO I=2,IMTM1                                                   COXCNVC.169    
C                                                                          COXCNVC.170    
              IF (TEMPA(I,K).GT.TEMPA(I,K+1).AND.                          COXCNVC.171    
     &        ((.NOT.(L_OPSEUDIC)).OR.                                     COXCNVC.172    
     &        (L_OPSEUDIC.AND.TA(I,K,1).GE.TCHECK))) THEN                  COXCNVC.173    
                IF (.NOT.(L_OVARYT)) THEN                                  COXCNVC.174    
                  TA(I,K,M)=(DZ(K)*TA(I,K,M)+DZ(K+1)*TA(I,K+1,M))          COXCNVC.175    
     &            *DZZ2R(K+1)                                              COXCNVC.176    
                ELSE                                                       COXCNVC.177    
                  TA(I,K,M)=(RZ(K)*TA(I,K,M)+RZ(K+1)*TA(I,K+1,M))          COXCNVC.178    
     &            *RZZ2R(K+1)                                              COXCNVC.179    
                ENDIF                                                      COXCNVC.180    
                TA(I,K+1,M)=TA(I,K,M)                                      COXCNVC.181    
              ENDIF                                                        COXCNVC.182    
            ENDDO ! over I                                                 COXCNVC.183    
C                                                                          COXCNVC.184    
C                                                                          COXCNVC.186    
        ENDDO   ! over M                                                   COXCNVC.187    
        ENDDO   ! over K                                                   COXCNVC.188    
C                                                                          COXCNVC.189    
      ENDDO   ! over KS                                                    COXCNVC.190    
      ENDDO   ! over N                                                     COXCNVC.191    
C                                                                          COXCNVC.192    
      RETURN                                                               COXCNVC.193    
      END                                                                  COXCNVC.194    
*ENDIF                                                                     COXCNVC.195