*IF DEF,CONTROL                                                            GLW1F404.10     
C*LL                                                                       CONVFULL.2      
C (c) CROWN COPYRIGHT 1995, METEOROLOGICAL OFFICE, All Rights Reserved.    GTS2F400.15184  
C                                                                          GTS2F400.15185  
C Use, duplication or disclosure of this code is subject to the            GTS2F400.15186  
C restrictions as set forth in the contract.                               GTS2F400.15187  
C                                                                          GTS2F400.15188  
C                Meteorological Office                                     GTS2F400.15189  
C                London Road                                               GTS2F400.15190  
C                BRACKNELL                                                 GTS2F400.15191  
C                Berkshire UK                                              GTS2F400.15192  
C                RG12 2SZ                                                  GTS2F400.15193  
C                                                                          GTS2F400.15194  
C If no contract has been raised with this copy of the code, the use,      GTS2F400.15195  
C duplication or disclosure of it is strictly prohibited.  Permission      GTS2F400.15196  
C to do so must first be obtained in writing from the Head of Numerical    GTS2F400.15197  
C Modelling at the above address.                                          GTS2F400.15198  
C ******************************COPYRIGHT******************************    GTS2F400.15199  
C                                                                          GTS2F400.15200  
CLL   Subroutine CONVFULL                                                  CONVFULL.3      
CLL   Can run on any compiler accepting long lower case variables.         CONVFULL.4      
CLL                                                                        CONVFULL.5      
CLL                                                                        CONVFULL.6      
CLL   Author: R A Wood                                                     CONVFULL.7      
CLL   Date 7 September 1995                                                CONVFULL.8      
CLL   Reviewer: M J Bell                                                   CONVFULL.9      
CLL   Review date: 25 July 1995                                            CONVFULL.10     
CLL   Version 1.00 date 7 September 1995                                   CONVFULL.11     
CLL                                                                        CONVFULL.12     
CLL   Modification history:                                                CONVFULL.13     
CLL   Version 1.00 implemented at UM vn 4.0  7/9/95  R.A.Wood              CONVFULL.14     
!LL   4.5     17/09/98 Update calls to timer, required because of          GPB8F405.92     
!LL                    new barrier inside timer.         P.Burton          GPB8F405.93     
CLL                                                                        CONVFULL.15     
CLL   Programming standards use Cox naming convention for Cox variables    CONVFULL.16     
CLL   with the addition that lower case variables are local to the         CONVFULL.17     
CLL   routine.                                                             CONVFULL.18     
CLL   Otherwise follows UM doc paper 4 version 1.                          CONVFULL.19     
CLL                                                                        CONVFULL.20     
CLL   This routine performs full convective mixing using the               CONVFULL.21     
CLL   algorithm of Stefan Rahmstorf. The code is based on a MOM            CONVFULL.22     
CLL   update supplied by him. Complete static stability is                 CONVFULL.23     
CLL   guaranteed at the end of the routine, unlike with the                CONVFULL.24     
CLL   standard Cox algorithm.                                              CONVFULL.25     
CLL                                                                        CONVFULL.26     
CLL   External documentation:                                              CONVFULL.27     
CLL      scientific: S. Rahmstorf,Ocean Modelling 101, 9-11,1993.          CONVFULL.28     
CLL                                                                        CONVFULL.29     
CLL   Subroutine dependencies.  This routine defines the statement         CONVFULL.30     
CLL   function 'dens'. This function performs the same calculation         CONVFULL.31     
CLL   as STATEC, but on a single set of (T,S,K) values. Any change         CONVFULL.32     
CLL   to STATEC should therefore be reflected in the definition of         CONVFULL.33     
CLL   dens.                                                                CONVFULL.34     
CLL                                                                        CONVFULL.35     
CLL   Notes:                                                               CONVFULL.36     
CLL     1. Rahmstorf's original code has been retained as far as           CONVFULL.37     
CLL        possible. This includes some goto constructs which could        CONVFULL.38     
CLL        possibly be tidied up.                                          CONVFULL.39     
CLL     2. Part 4 ('Test layer above lcona') is unlikely to be needed      CONVFULL.40     
CLL      very often. If it were not needed at all the code could be made   CONVFULL.41     
CLL        more vectorisable by working down from surface one level at     CONVFULL.42     
CLL        a time, calculating rhoup and rholo and keeping track of        CONVFULL.43     
CLL        current mixing levels. May be useful if optimisation required   CONVFULL.44     
CLL        in future.                                                      CONVFULL.45     
CLL     3. Statement function definition (dens) can cause spurious out     CONVFULL.46     
CLL        of bounds messages on c90 when array bounds checker is on.      CONVFULL.47     
CLL                                                                        CONVFULL.48     
CLLEND------------------------------------------------------------------   CONVFULL.49     
C*                                                                         CONVFULL.50     
C*L   -------------Arguments--------------------------------------------   CONVFULL.51     
C                                                                          CONVFULL.52     

      SUBROUTINE CONVFULL(                                                  2,2CONVFULL.53     
     *                    IMT,KM,NT,                                       CONVFULL.54     
     *                    KMT,DZ,TA                                        CONVFULL.55     
     *                   )                                                 CONVFULL.56     
C                                                                          CONVFULL.57     
      IMPLICIT NONE                                                        CONVFULL.58     
                                                                           CONVFULL.59     
*CALL COCSTATE                                                             CONVFULL.60     
*CALL OTIMER                                                               CONVFULL.61     
                                                                           CONVFULL.62     
C                                                                          CONVFULL.63     
C     Define constants for array sizes                                     CONVFULL.64     
C                                                                          CONVFULL.65     
C                                                                          CONVFULL.66     
      INTEGER                                                              CONVFULL.67     
     +   IMT      ! IN  Number of points in first dimension of arrays      CONVFULL.68     
     +,  KM       ! IN  Number of points in vertical                       CONVFULL.69     
     +,  NT       ! IN  Number of tracers                                  CONVFULL.70     
C                                                                          CONVFULL.71     
      INTEGER                                                              CONVFULL.72     
     +   KMT (IMT)! IN  Number of gridpoints in column                     CONVFULL.73     
C                                                                          CONVFULL.74     
C     Physical arguments                                                   CONVFULL.75     
C                                                                          CONVFULL.76     
      REAL                                                                 CONVFULL.77     
     +   DZ(KM)               ! IN     Thickness of tracer gridbox (cm)    CONVFULL.78     
     +,  TA (IMT,KM,NT)       ! INOUT  Array of tracers                    CONVFULL.79     
C*                                                                         CONVFULL.80     
C                                                                          CONVFULL.81     
C     Locally defined variables and arrays                                 CONVFULL.82     
C                                                                          CONVFULL.83     
      INTEGER                                                              CONVFULL.84     
     +   i                    !  Zonal index for loops                     CONVFULL.85     
     +,  k                    !  Vert loop index & dummy vble in stmt fn   CONVFULL.86     
     +,  l                    !  Vertical loop index                       CONVFULL.87     
     +,  l1                   !  l+1 within loops                          CONVFULL.88     
     +,  m                    !  Tracer number in loops                    CONVFULL.89     
     +,  kcon                 !  Max no of levels at this location         CONVFULL.90     
     +,  lcon                 !  Counts levels down                        CONVFULL.91     
     +,  lcona                !  Top level of a convective part of         CONVFULL.92     
C                                water column                              CONVFULL.93     
     +,  lconb                !  Lower level of a convective part of       CONVFULL.94     
C                                water column                              CONVFULL.95     
     +,  lmix                 !  Loop index running from lcona to lconb    CONVFULL.96     
     +,  lctot(IMT)           !  Total of number of levels involved        CONVFULL.97     
C                                in convection                             CONVFULL.98     
     +,  lcven(IMT)           !  Number of levels ventilated               CONVFULL.99     
C                                (convection to surface)                   CONVFULL.100    
C                                note: lctot can in rare cases count       CONVFULL.101    
C                                some levels twice, if they get involved   CONVFULL.102    
C                                in two originally separte, but then       CONVFULL.103    
C                                overlapping convection areas in the       CONVFULL.104    
C                                water column. It is a control             CONVFULL.105    
C                                parameter; the useful parameter for       CONVFULL.106    
C                                diagnostic purposes is lcven. Lcven is    CONVFULL.107    
C                                0 on land, 1 on ocean points with no      CONVFULL.108    
C                                convection, and anything up to km on      CONVFULL.109    
C                                convecting points.                        CONVFULL.110    
C                                                                          CONVFULL.111    
      REAL                                                                 CONVFULL.112    
     +    dens                 ! Statement fn to calculate density         CONVFULL.113    
     +,   tq,sq                ! Dummy vbles in stmt fn dens               CONVFULL.114    
     +,   rhoup(imt,km)        ! Density referenced to same level          CONVFULL.115    
     +,   rholo(imt,km)        ! Density referenced to level below         CONVFULL.116    
C                                (note that densities are not absolute!)   CONVFULL.117    
     +,   dztsum               ! Sum of layer thicknesses                  CONVFULL.118    
     +,   trasum(nt)           ! Sum of layer tracer values                CONVFULL.119    
     +,   tramix               ! Mixed tracer value after convection       CONVFULL.120    
C                                                                          CONVFULL.121    
c                                                                          CONVFULL.122    
c                                                                          CONVFULL.123    
c         This function has been taken from STATE to allow direct          CONVFULL.124    
c         use of dens (instead of wasteful calls to STATEC).               CONVFULL.125    
c         Referencing to the appropriate levels is taken care of           CONVFULL.126    
c         in the calculation of rhoup and rholo below (1311 loop).         CONVFULL.127    
c-----------------------------------------------------------------------   CONVFULL.128    
c     statement function dens   ! Note may cause spurious OOB messages     CONVFULL.129    
c-----------------------------------------------------------------------   CONVFULL.130    
c                                                                          CONVFULL.131    
      dens(tq,sq,k) = (C(k,1) + (C(k,4) + C(k,7)*sq)*sq                    CONVFULL.132    
     $               +(C(k,3) + C(k,8)*sq + C(k,6)*tq)*tq)*tq              CONVFULL.133    
     $               +(C(k,2) + (C(k,5) + C(k,9)*sq)*sq)*sq                CONVFULL.134    
c                                                                          CONVFULL.135    
c                                                                          CONVFULL.136    
c-----------------------------------------------------------------------   CONVFULL.137    
c                                                                          CONVFULL.138    
c   Stefan Rahmstorf's original introductory comments...                   CONVFULL.139    
c                                                                          CONVFULL.140    
c         The following convection scheme is an alternative to the         CONVFULL.141    
c         standard scheme. In contrast to the standard scheme,             CONVFULL.142    
c         it totally removes all gravitational instability in the          CONVFULL.143    
c         water column. It does that in one pass, so the parameter         CONVFULL.144    
c         ncon becomes irrelevant if this option is selected.              CONVFULL.145    
c         The scheme is equivalent to that used by Rahmstorf               CONVFULL.146    
c         (jgr 96,6951-6963) and [...similar to that used... R.A.W]        CONVFULL.147    
c         by Marotzke (jpo 21,903-907).                                    CONVFULL.148    
c         It is discussed in a note to Ocean Modelling (101). It uses      CONVFULL.149    
c         as much cpu time as 1-3 passes of the standard scheme,           CONVFULL.150    
c         depending on the amount of static instability found in the       CONVFULL.151    
c         model, and is much faster than using "implicitvmix".             CONVFULL.152    
c                                                                          CONVFULL.153    
c         Written by Stefan Rahmstorf, Institut fuer Meereskunde,          CONVFULL.154    
c         Kiel, Germany.            Comments welcome:                      CONVFULL.155    
c                         srahmstorf@meereskunde.uni-kiel.d400.de          CONVFULL.156    
c-----------------------------------------------------------------------   CONVFULL.157    
c                                                                          CONVFULL.158    
      IF (L_OTIMER) CALL TIMER('CONVFULL',103)                             GPB8F405.94     
c                                                                          CONVFULL.160    
c             find density for entire slab for stability determination     CONVFULL.161    
c                                                                          CONVFULL.162    
        do 1311 l=1,km-1                                                   CONVFULL.163    
          do 1312 i=1,imt                                                  CONVFULL.164    
            l1=l+1                                                         CONVFULL.165    
            rhoup(i,l1) = dens(ta(i,l1,1)-to(l1),ta(i,l1,2)-so(l1),l1)     CONVFULL.166    
            rholo(i,l)  = dens(ta(i,l ,1)-to(l1),ta(i,l ,2)-so(l1),l1)     CONVFULL.167    
1312      continue                                                         CONVFULL.168    
1311    continue                                                           CONVFULL.169    
                                                                           CONVFULL.170    
                                                                           CONVFULL.171    
c                                                                          CONVFULL.172    
c        Do the slab column by column; note that 'goto 1310'               CONVFULL.173    
c        finishes a particular column and moves to the next one.           CONVFULL.174    
c                                                                          CONVFULL.175    
      do 1310 i=1,IMT                                                      CONVFULL.176    
        kcon = kmt(i)                                                      CONVFULL.177    
        lctot(i) = 0                                                       CONVFULL.178    
        lcven(i) = 0                                                       CONVFULL.179    
        if (kcon.eq.0) goto 1310                                           CONVFULL.180    
        lcven(i) = 1                                                       CONVFULL.181    
        lcon=0                                                             CONVFULL.182    
                                                                           CONVFULL.183    
c                                                                          CONVFULL.184    
c        1. initial search for uppermost unstable pair; if none is         CONVFULL.185    
c           found, move on to next column                                  CONVFULL.186    
c                                                                          CONVFULL.187    
        do 1313 k=kcon-1,1,-1                                              CONVFULL.188    
1313    if(rholo(i,k).gt.rhoup(i,k+1)) lcon=k                              CONVFULL.189    
                                                                           CONVFULL.190    
        if(lcon.eq.0) goto 1310                                            CONVFULL.191    
                                                                           CONVFULL.192    
1319    lcona = lcon                                                       CONVFULL.193    
        lconb = lcon + 1                                                   CONVFULL.194    
c                                                                          CONVFULL.195    
c        2. mix the first two unstable layers                              CONVFULL.196    
c                                                                          CONVFULL.197    
        dztsum = dz(lcona) + dz(lconb)                                     CONVFULL.198    
        do 1301 m=1,nt                                                     CONVFULL.199    
          trasum(m) = ta(i,lcona,m)*dz(lcona) +ta(i,lconb,m)*dz(lconb)     CONVFULL.200    
          tramix = trasum(m) / dztsum                                      CONVFULL.201    
          ta(i,lcona,m) = tramix                                           CONVFULL.202    
          ta(i,lconb,m) = tramix                                           CONVFULL.203    
1301    continue                                                           CONVFULL.204    
c                                                                          CONVFULL.205    
c        3. test layer below lconb                                         CONVFULL.206    
c                                                                          CONVFULL.207    
1306    if (lconb.eq.kcon) goto 1308                                       CONVFULL.208    
                                                                           CONVFULL.209    
        l1=lconb+1                                                         CONVFULL.210    
        rholo(i,lconb) =                                                   CONVFULL.211    
     $    dens(ta(i,lconb,1)-to(l1),ta(i,lconb,2)-so(l1),l1)               CONVFULL.212    
        if (rholo(i,lconb).gt.rhoup(i,l1)) then                            CONVFULL.213    
                                                                           CONVFULL.214    
          lconb = lconb+1                                                  CONVFULL.215    
          dztsum = dztsum + dz(lconb)                                      CONVFULL.216    
          do 1304 m=1,nt                                                   CONVFULL.217    
            trasum(m) = trasum(m) + ta(i,lconb,m)*dz(lconb)                CONVFULL.218    
            tramix = trasum(m) / dztsum                                    CONVFULL.219    
            do 1307 lmix=lcona,lconb                                       CONVFULL.220    
1307        ta(i,lmix,m) = tramix                                          CONVFULL.221    
1304      continue                                                         CONVFULL.222    
          goto 1306                                                        CONVFULL.223    
        end if                                                             CONVFULL.224    
c                                                                          CONVFULL.225    
c        4. test layer above lcona                                         CONVFULL.226    
c                                                                          CONVFULL.227    
1308    if (lcona.gt.1) then                                               CONVFULL.228    
                                                                           CONVFULL.229    
          l1 = lcona-1                                                     CONVFULL.230    
          rholo(i,l1) =                                                    CONVFULL.231    
     $      dens(ta(i,l1,1)-to(lcona),ta(i,l1,2)-so(lcona),lcona)          CONVFULL.232    
          rhoup(i,lcona) =                                                 CONVFULL.233    
     $      dens(ta(i,lcona,1)-to(lcona),ta(i,lcona,2)-so(lcona),lcona)    CONVFULL.234    
          if (rholo(i,lcona-1).gt.rhoup(i,lcona)) then                     CONVFULL.235    
                                                                           CONVFULL.236    
            lcona = lcona-1                                                CONVFULL.237    
            dztsum = dztsum + dz(lcona)                                    CONVFULL.238    
            do 1305 m=1,nt                                                 CONVFULL.239    
              trasum(m) = trasum(m) + ta(i,lcona,m)*dz(lcona)              CONVFULL.240    
              tramix = trasum(m) / dztsum                                  CONVFULL.241    
              do 1309 lmix=lcona,lconb                                     CONVFULL.242    
1309          ta(i,lmix,m) = tramix                                        CONVFULL.243    
1305        continue                                                       CONVFULL.244    
            goto 1306                                                      CONVFULL.245    
          end if                                                           CONVFULL.246    
        end if                                                             CONVFULL.247    
c                                                                          CONVFULL.248    
c        5. remember the total number of levels mixed by convection        CONVFULL.249    
c           in this water column, as well as the ventilated column.        CONVFULL.250    
c           [This code is left in but commented out in case these          CONVFULL.251    
c           diagnostics are required in future. R.A.W.]                    CONVFULL.252    
c                                                                          CONVFULL.253    
c       lctot(i) = lctot(i) + lconb - lcona + 1                            CONVFULL.254    
c       if(lcona.eq.1) lcven(i) = lconb - lcona + 1                        CONVFULL.255    
c                                                                          CONVFULL.256    
c        6. resume search if step 3. and 4. have been passed and this      CONVFULL.257    
c           unstable part of the water column has thus been removed,       CONVFULL.258    
c           i.e. find further unstable areas further down the column       CONVFULL.259    
c           [Note construction could be tidied up. R.A.W]                  CONVFULL.260    
c                                                                          CONVFULL.261    
        if (lconb.eq.kcon) goto 1310                                       CONVFULL.262    
        lcon = lconb                                                       CONVFULL.263    
                                                                           CONVFULL.264    
1302    lcon = lcon + 1                                                    CONVFULL.265    
                                                                           CONVFULL.266    
        if (lcon.eq.kcon) goto 1310                                        CONVFULL.267    
                                                                           CONVFULL.268    
        if (rholo(i,lcon).le.rhoup(i,lcon+1)) goto 1302                    CONVFULL.269    
                                                                           CONVFULL.270    
        goto 1319                                                          CONVFULL.271    
c                                                                          CONVFULL.272    
                                                                           CONVFULL.273    
1310  continue                                                             CONVFULL.274    
                                                                           CONVFULL.275    
      IF (L_OTIMER) CALL TIMER('CONVFULL',104)                             GPB8F405.95     
                                                                           CONVFULL.277    
      return                                                               CONVFULL.278    
      end                                                                  CONVFULL.279    
*ENDIF                                                                     GLW1F404.11