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

      SUBROUTINE BIOMIX (TA, IMT, KM, NT, DZ, ZDZ, RZ,                      1BIOMIX.22     
     &                   FM, KMT, MLD_MIX)                                 BIOMIX.23     
      IMPLICIT NONE                                                        BIOMIX.24     
! Description:                                                             BIOMIX.25     
!  Mixes the biology variables in the fully mixed part                     BIOMIX.26     
!  of the mixed layer, as defined by mixed layer depth                     BIOMIX.27     
!  'MLD_MIX'                                                               BIOMIX.28     
!  Required for minimising timestep dependence of long                     BIOMIX.29     
!  timestep (eg 12,24 hour) biology runs.                                  BIOMIX.30     
!                                                                          BIOMIX.31     
! Current Code Owner: Richard Wood                                         BIOMIX.32     
!                                                                          BIOMIX.33     
! History:                                                                 BIOMIX.34     
! Version  Date     Comment                                                BIOMIX.35     
! =======  ====     =======                                                BIOMIX.36     
!  UM4.4   9.97    Original code. (Jonathan Palmer)                        BIOMIX.37     
!                                                                          BIOMIX.38     
! Code description:                                                        BIOMIX.39     
!   FORTRAN 77 + common extensions also in fortran 90.                     BIOMIX.40     
!   This code is written to UM programming standards version 6             BIOMIX.41     
!                                                                          BIOMIX.42     
! Global variables (*CALLed common blocks etc.)                            BIOMIX.43     
*CALL CNTLOCN                                                              BIOMIX.44     
*CALL OARRYSIZ                                                             BIOMIX.45     
! Subroutine arguments                                                     BIOMIX.46     
!   Scalar arguments with intent(in):                                      BIOMIX.47     
      INTEGER IMT      ! IN  Number of points in first dimension           BIOMIX.48     
                       !     of arrays                                     BIOMIX.49     
      INTEGER KM       ! IN  Number of points in vertical                  BIOMIX.50     
      INTEGER NT       ! IN  Number of tracers                             BIOMIX.51     
      INTEGER KMT(IMT) ! IN  Number of gridpoints in each column           BIOMIX.52     
                                                                           BIOMIX.53     
!   Array  arguments with intent(in):                                      BIOMIX.54     
      REAL DZ(KM)      ! IN model layer thicknesses                        BIOMIX.55     
      REAL ZDZ(KM)     ! IN depth of base of layers                        BIOMIX.56     
      REAL RZ(KM)      ! IN layer thicknesses scaled by 1/RAT(K)           BIOMIX.57     
      REAL FM(IMT,KM)  ! IN Land/ea mask: 1.0=sea                          BIOMIX.58     
      REAL MLD_MIX(IMT) ! IN Instantaneous mixed layer depth from          BIOMIX.59     
                       ! previous call to MIXLAY in this timestep.         BIOMIX.60     
                       ! Note:MLD_MIX is in metres, DZ etc are in cm.      BIOMIX.61     
                                                                           BIOMIX.62     
!   Array  arguments with intent(InOut):                                   BIOMIX.63     
      REAL TA (IMT, KM, NT)  ! IN/OUT Tracer values                        BIOMIX.64     
                                                                           BIOMIX.65     
! Local parameters:                                                        BIOMIX.66     
      INTEGER firstbiotracer    ! index into TA of first tracer to mix     BIOMIX.67     
      INTEGER lastbiotracer     ! index into TA of last tracer to mix      BIOMIX.68     
      PARAMETER (firstbiotracer=3)                                         BIOMIX.69     
      PARAMETER (lastbiotracer=8)                                          BIOMIX.70     
                                                                           BIOMIX.71     
! Local scalars:                                                           BIOMIX.72     
      INTEGER i      ! zonal index for loops                               BIOMIX.73     
      INTEGER k      ! vertical index for loops                            BIOMIX.74     
      INTEGER m      ! tracer number in loops                              BIOMIX.75     
      REAL column_sum    ! Tracer integrated over fully mixed column       BIOMIX.76     
      REAL column_mean   ! Tracer meaned over column                       BIOMIX.77     
                                                                           BIOMIX.78     
!- End of header                                                           BIOMIX.79     
                                                                           BIOMIX.80     
! Loop over mixing tracers (m) and along row (i), averaging                BIOMIX.81     
! each tracer over the mixed layer depth (MLD_MIX).                        BIOMIX.82     
                                                                           BIOMIX.83     
      DO m=firstbiotracer,lastbiotracer                                    BIOMIX.84     
        DO i=1,IMT                                                         BIOMIX.85     
          column_sum=0.0                                                   BIOMIX.86     
          k=1                                                              BIOMIX.87     
          DO WHILE ( (ZDZ(k).LE.MLD_MIX(i)*100.0).AND.                     BIOMIX.88     
     &    ((k.LE.KMT(i)).AND.(FM(i,k).GT. 0.0)) )                          BIOMIX.89     
            column_sum=column_sum + TA(i,k,m)*DZ(k)*FM(i,k)                BIOMIX.90     
            k=k+1                                                          BIOMIX.91     
          ENDDO                                                            BIOMIX.92     
          IF (k.GT.1) THEN                                                 BIOMIX.93     
            column_mean=column_sum/ZDZ(k-1)                                BIOMIX.94     
            k=1                                                            BIOMIX.95     
            DO WHILE ( (ZDZ(k).LE.MLD_MIX(i)*100.0).AND.                   BIOMIX.96     
     &      ((k.LE.KMT(i)).AND.(FM(i,k).GT. 0.0)) )                        BIOMIX.97     
              TA(i,k,m)=column_mean                                        BIOMIX.98     
              k=k+1                                                        BIOMIX.99     
            ENDDO                                                          BIOMIX.100    
          ENDIF                                                            BIOMIX.101    
        ENDDO                                                              BIOMIX.102    
      ENDDO                                                                BIOMIX.103    
                                                                           BIOMIX.104    
      RETURN                                                               BIOMIX.105    
      END                                                                  BIOMIX.106    
*ENDIF                                                                     BIOMIX.107