*IF DEF,OCEAN                                                              ORH1F305.438    
C ******************************COPYRIGHT******************************    GTS2F400.487    
C (c) CROWN COPYRIGHT 1995, METEOROLOGICAL OFFICE, All Rights Reserved.    GTS2F400.488    
C                                                                          GTS2F400.489    
C Use, duplication or disclosure of this code is subject to the            GTS2F400.490    
C restrictions as set forth in the contract.                               GTS2F400.491    
C                                                                          GTS2F400.492    
C                Meteorological Office                                     GTS2F400.493    
C                London Road                                               GTS2F400.494    
C                BRACKNELL                                                 GTS2F400.495    
C                Berkshire UK                                              GTS2F400.496    
C                RG12 2SZ                                                  GTS2F400.497    
C                                                                          GTS2F400.498    
C If no contract has been raised with this copy of the code, the use,      GTS2F400.499    
C duplication or disclosure of it is strictly prohibited.  Permission      GTS2F400.500    
C to do so must first be obtained in writing from the Head of Numerical    GTS2F400.501    
C Modelling at the above address.                                          GTS2F400.502    
C ******************************COPYRIGHT******************************    GTS2F400.503    
C                                                                          GTS2F400.504    
C*LL  Subroutine BIOLOGY                                                   BIOLOGY.3      
CLL   Can run on any FORTRAN 77 compiler with long lower case variables    BIOLOGY.4      
CLL                                                                        BIOLOGY.5      
CLL   Author: N.K. TAYLOR                                                  BIOLOGY.6      
CLL   Date: 17 December 1993                                               BIOLOGY.7      
CLL   Version 3.3                                                          BIOLOGY.8      
CLL                                                                        BIOLOGY.9      
CLL   Programming standards use Cox naming convention for Cox variables    BIOLOGY.10     
CLL     with the addition that lower case variables are local to the       BIOLOGY.11     
CLL     routine.                                                           BIOLOGY.12     
CLL                                                                        BIOLOGY.13     
CLL   This routine calculates the growth of phytoplankton, and the         BIOLOGY.14     
CLL   consequent effect on the carbon cycle. 6 additional tracers are      BIOLOGY.15     
CLL   used for this purpose : they represent TCO2, Alkalinity, Nutrient,   BIOLOGY.16     
CLL   Phytoplankton, Zooplankton (Grazers), and Detritus.                  BIOLOGY.17     
CLL   The processes described in this model are based upon those used      BIOLOGY.18     
CLL   in a single-column model written by Ian Totterdell at the James      BIOLOGY.19     
CLL   Rennell Centre.                                                      BIOLOGY.20     
CLL   This model requires that the basic inorganic carbon cycle option     BIOLOGY.21     
CLL   is already selected.                                                 BIOLOGY.22     
CLL                                                                        ONT1F304.453    
CLL  Modification history:                                                 ONT1F304.454    
CLL  Vn 3.4 31/8/94 Added diagnostics      (Nick Taylor)                   ONT1F304.455    
!     3.5    16.01.95   Remove *IF dependency. R.Hill                      ORH1F305.4243   
CLL  Vn 4.4 9/97 Extensively rewritten, with simple light model,           OJP0F404.1      
CLL              semiimplicit growth and detrital sinking, carbonate       OJP0F404.2      
CLL              pump, positive tracers in ecosystem equations,            OJP0F404.3      
CLL              pointers into tracer arrays, major changes to the         OJP0F404.4      
CLL              grazing formulation.             (JRPalmer).              OJP0F404.5      
CLL                                                                        BIOLOGY.23     
CLL                                                                        BIOLOGY.24     
CLLEND -----------------------------------------------------------------   BIOLOGY.25     
C*                                                                         BIOLOGY.26     
C*L--------------------------------  Arguments  ------------------------   BIOLOGY.27     
C                                                                          BIOLOGY.28     

      SUBROUTINE BIOLOGY (T,TA,TB,SOL_PEN,KFIX,RTPIG,PI,                    1,1OJP0F404.6      
     +                    TIMESTEP,ETA,                                    OJP0F404.7      
     +                    DAYLEN,DLCO,SOL,                                 OJP0F404.8      
     +                    PRIM_PROD,ZOO_PROD,PHYTO_GROW,                   ONT1F304.456    
     +                    PHYTO_GRAZE,PHYTO_MORT,                          ONT1F304.457    
     +                    EXCRETE_NUT,GROW_NUT,PMORT_NUT,ZMORT_NUT,        ONT1F304.458    
     +                    PRESP_NUT,REMIN_NUT,                             ONT1F304.459    
     +                    NUT_LIMIT,LIGHT_LIMIT,TEMP_LIMIT,                ONT1F304.460    
     +                    DETRI_FLUX,                                      ONT1F304.461    
     +                    SF_BIO,                                          ONT1F304.462    
     +                    DZ,ZDZ,JMT,FM,                                   OJP0F404.9      
     +                    SWNCOL,                                          ONT1F304.463    
     +                    J,IMT, KM, KMP1, KMT, NT)                        OJP0F404.10     
C                                                                          BIOLOGY.37     
      IMPLICIT NONE                                                        BIOLOGY.38     
C                                                                          BIOLOGY.39     
! The following declarations are necessary at this point                   ORH6F401.78     
! for portability reasons                                                  ORH6F401.79     
      INTEGER                                                              ORH6F401.80     
     &   JMT                    ! IN  Number of rows                       ORH6F401.81     
     &,  KM                     ! IN  Number of layers in model            ORH6F401.82     
C     Common blocks                                                        BIOLOGY.40     
C                                                                          BIOLOGY.41     
*CALL CMAXSIZE                                                             ORH1F305.4244   
*CALL CSUBMODL                                                             ORH1F305.4245   
*CALL TYPOCBIO                                                             BIOLOGY.42     
*CALL CTIME                                                                BIOLOGY.43     
*CALL CNTLOCN                                                              ORH1F305.4246   
*CALL OARRYSIZ                                                             ORH1F305.4247   
*CALL OTRACPNT                                                             OJP0F404.11     
C                                                                          BIOLOGY.44     
C     Define constants for array sizes                                     BIOLOGY.45     
C                                                                          BIOLOGY.46     
      INTEGER                                                              BIOLOGY.47     
     +   IMT                    ! IN  Number of points in horizontal       BIOLOGY.48     
     +,  KMP1                   ! IN  Number of layers in model plus 1     BIOLOGY.51     
     +,  KMT(IMT)               ! IN  Number of levs at each tracer pnt    OJP0F404.12     
     +,  NT                     ! IN  Number of tracers                    BIOLOGY.52     
     +,  KFIX                   ! IN Layer to which solar rad penetrates   BIOLOGY.53     
     +,  J                      ! IN  Current row number                   BIOLOGY.54     
     +,  SWNCOL            ! IN Number of columns in a row                 ONT1F304.464    
C                                                                          BIOLOGY.55     
C     Physical arguments                                                   BIOLOGY.56     
C                                                                          BIOLOGY.57     
      REAL                                                                 BIOLOGY.58     
     +   T (IMT, KM, NT)        ! IN Tracer vals for leapfrog timestep     OJP0F404.13     
     +  ,TA(IMT,KM,NT)          ! INOUT Tracers on new timestep            OJP0F404.14     
     +  ,TB(IMT, KM, NT)        ! IN Tracer values for forward timestep    OJP0F404.15     
     +  ,SOL (IMT)              ! IN Solar irradiance (W/m2) at surface    BIOLOGY.60     
     +  ,SOL_PEN (IMT,0:KM)     ! IN Proportion of SOL at bottom of laye   BIOLOGY.61     
     +  ,RTPIG (IMT,KM)         ! IN SQRT of total pigment conc.           BIOLOGY.62     
     +  ,ETA (IMT,KM)           ! IN Light extinction coeff. (1/m)         BIOLOGY.63     
     +  ,PI                     ! IN 3.14159                               BIOLOGY.64     
     +  ,TIMESTEP(KM)           ! IN Tracer timestep incl. gamma accn.     OJP0F404.16     
     +  ,FM (IMT,KM)            ! IN Land-sea mask                         BIOLOGY.66     
     +  ,DZ(KM)                 ! IN Thickness of each level               OJP0F404.17     
     +  ,ZDZ(KM)                ! IN depth of base of layers               OJP0F404.18     
C                                                                          ONT1F304.465    
C   DIAGNOSTICS                                                            ONT1F304.466    
C                                                                          ONT1F304.467    
C  Integrated production                                                   ONT1F304.468    
      REAL PRIM_PROD(SWNCOL,JMT) ! Primary production (gross)              ONT1F304.469    
C                                ! (gC/m2/day) -Integrated over top 200m   ONT1F304.470    
      REAL ZOO_PROD(SWNCOL,JMT)  ! Zooplankton production (gross)          ONT1F304.471    
C                                ! Totalled over top 200m (gC/m2/day)      ONT1F304.472    
C  Growth limitation terms                                                 ONT1F304.473    
      REAL NUT_LIMIT(SWNCOL,JMT,KM) ! Phytoplankton growth                 ONT1F304.474    
      REAL LIGHT_LIMIT(SWNCOL,JMT,KM) ! limitation terms                   ONT1F304.475    
      REAL TEMP_LIMIT(SWNCOL,JMT,KM)                                       ONT1F304.476    
C                                                                          ONT1F304.477    
C  Phyto specific rates                                                    ONT1F304.478    
      REAL PHYTO_GROW (SWNCOL,JMT,KM) ! Phyto growth specific rate         ONT1F304.479    
      REAL PHYTO_GRAZE(SWNCOL,JMT,KM) ! Phyto grazing specific rate        ONT1F304.480    
      REAL PHYTO_MORT (SWNCOL,JMT,KM) ! Phyto mortality spec. rate         ONT1F304.481    
C                                     ! Specific rates in (day)-1          ONT1F304.482    
!  Rate of change of Detritus due to sinking                               OJP0F404.19     
      REAL DETRI_FLUX (SWNCOL,JMT,KM) ! Detrital rate of change due        OJP0F404.20     
                                      ! to sinking, mMol-N/m3/day          OJP0F404.21     
C                                                                          ONT1F304.486    
C Terms in Nitrate balance (all in units mMol-N/m3/day)                    ONT1F304.487    
      REAL EXCRETE_NUT(SWNCOL,JMT,KM) ! Nutrient excretion rate            ONT1F304.488    
     &    ,GROW_NUT(SWNCOL,JMT,KM)   ! Loss rate of N due to phyto         ONT1F304.489    
     &    ,PMORT_NUT(SWNCOL,JMT,KM)  ! Gain due to phyto death             ONT1F304.490    
     &    ,ZMORT_NUT(SWNCOL,JMT,KM)  ! Gain due to zoo death               ONT1F304.491    
     &    ,PRESP_NUT(SWNCOL,JMT,KM)  ! Gain due to phyto resp              ONT1F304.492    
     &    ,REMIN_NUT(SWNCOL,JMT,KM)  ! Gain due to detrtus remin.          ONT1F304.493    
C                                                                          ONT1F304.494    
      LOGICAL SF_BIO(*)          ! Diagnostic switch                       ONT1F304.495    
C*                                                                         BIOLOGY.71     
*IF DEF,OBIOLOGY                                                           ORH1F305.439    
C                                                                          BIOLOGY.72     
C                                                                          BIOLOGY.73     
C     Locally defined variables                                            BIOLOGY.74     
C                                                                          BIOLOGY.75     
      INTEGER                                                              BIOLOGY.76     
     +     I                    ! Horizontal loop index                    BIOLOGY.77     
     +    ,K                    ! Vertical   loop index                    BIOLOGY.78     
     +  ,II                ! Loop index                                    ONT1F304.496    
     +  ,issw,iesw         ! 1st & last stashwork columns                  ONT1F304.497    
C                                                                          BIOLOGY.79     
!                                                                          OJP0F404.22     
!    Positive copies of biological tracers (negatives set to zero)         OJP0F404.23     
!    for doing calculations                                                OJP0F404.24     
      REAL                                                                 OJP0F404.25     
     +   N(IMT,KM)          ! Nutrient tracer on old timestep              OJP0F404.26     
     +  ,P(IMT,KM)          ! Phytoplankton                                OJP0F404.27     
     +  ,Z(IMT,KM)          ! Zooplankton                                  OJP0F404.28     
     +  ,D(IMT,KM)          ! Detritus                                     OJP0F404.29     
                                                                           OJP0F404.30     
!    Implicitly calculated nutrient for use in growth dynamics             OJP0F404.31     
      REAL NI(IMT,KM)                                                      OJP0F404.32     
!    Nutrient supply from difference between TB and TA                     OJP0F404.33     
      REAL Nsupply(IMT,KM)                                                 OJP0F404.34     
!    BIOLOGY change of detritus for use in semi-implicit sinking           OJP0F404.35     
      REAL DDT(IMT,KM)                                                     OJP0F404.36     
                                                                           OJP0F404.37     
!    Intermediates in calculations                                         OJP0F404.38     
      REAL lim_nut (IMT,KM)     ! Nutrient limitation factor               BIOLOGY.80     
     +,    lim_temp (IMT,KM)    ! Temperature limitation factor            BIOLOGY.81     
     +,    lim_light (IMT,KM)   ! Light limitation factor                  BIOLOGY.82     
     +,    pigment (IMT,KM)     ! Total pigment concentration              BIOLOGY.83     
     +,    sol_noon (IMT)       ! Noon irradiance (p/s active) (uEinstei   BIOLOGY.84     
     +,    psynth (IMT,KM)      ! Photosynthesis per unit biomass          BIOLOGY.85     
     +                          ! per unit volume (averaged over diurnal   BIOLOGY.86     
     +,    ingestion_rate(IMT,KM) ! zooplankton ingestion rate in          OJP0F404.39     
     +                            ! biomass equivalent units               OJP0F404.40     
     +,    growth_p (IMT,KM)    ! Rate of phyto growth (mMoles-N/m3)       BIOLOGY.87     
     +,    growth_n (IMT,KM)    ! Flows from N and TCO2 associated with    BIOLOGY.88     
     +,    growth_c (IMT,KM)    !   the growth of phytoplankton            BIOLOGY.89     
     +,    zgrowth (IMT,KM)     ! Rate of zoo growth (mMoles-N/m3)         BIOLOGY.90     
     +,    p_resp_p (IMT,KM)    ! Rate of phyto respiration                BIOLOGY.91     
     +,    p_resp_n (IMT,KM)    ! Flows to N and TCO2 associated with      BIOLOGY.92     
     +,    p_resp_c (IMT,KM)    !  phyto respiration                       BIOLOGY.93     
     +,    p_mort (IMT,KM)      ! Phytoplankton mortality (mMoles-N/m3)    BIOLOGY.94     
     +,    p_mort_dt (IMT,KM)   ! Flows to detritus, N and TCO2            BIOLOGY.95     
     +,    p_mort_n (IMT,KM)    !  associated with phyto mortality         BIOLOGY.96     
     +,    p_mort_c (IMT,KM)    !                                          BIOLOGY.97     
     +,    z_mort (IMT,KM)      ! Zooplankton mortality (mMoles-N/m3)      BIOLOGY.98     
     +,    z_mort_dt (IMT,KM)   ! Flows to detritus, N and TCO2            BIOLOGY.99     
     +,    z_mort_n (IMT,KM)    !  associated with zooplankton             BIOLOGY.100    
     +,    z_mort_c (IMT,KM)    !  mortality                               BIOLOGY.101    
     +,    pgraze (IMT,KM)      ! Loss of phyto by zoo grazing             BIOLOGY.102    
     +,    dgraze (IMT,KM)      ! Loss of detritus by zoo grazing          BIOLOGY.103    
     +,    d_remin (IMT,KM)     ! Remineralization of detritus             BIOLOGY.104    
     +,    d_remin_n (IMT,KM)   ! Remineralization of detritus to N        BIOLOGY.105    
     +,    d_remin_c (IMT,KM)   ! Remineralization of detritus to C        BIOLOGY.106    
     +,    unassim_n (IMT,KM)   ! Unassimilated N in gut of zooplankton    BIOLOGY.107    
     +,    unassim_c (IMT,KM)   ! Unassimilated C in gut of zooplankton    BIOLOGY.108    
     +,    c2n_food (IMT,KM)    ! C:N ratio of food ingested by zoopl.     BIOLOGY.109    
     +,    c2n_junk (IMT,KM)    ! C:N ratio of unassimilated material      BIOLOGY.110    
     +,    excrete_n (IMT,KM)   ! N excreted by zooplankton                BIOLOGY.111    
     +,    excrete_c (IMT,KM)   ! C excreted by zooplankton                BIOLOGY.112    
     +,    excrete_dt (IMT,KM)  ! DETRITUS excreted by zooplankton         BIOLOGY.113    
     +,    export_co3 (IMT)     ! Column Carbon export calcite flux        OJP0F404.41     
     +                          ! (umoles/m2)                              OJP0F404.42     
     +,    local_export         ! Local carbon export calcite flux         OJP0F404.43     
     +                          ! (umoles/litre)                           OJP0F404.44     
     +,    column_depth         ! deep water column below lysocline (m)    OJP0F404.45     
                                                                           BIOLOGY.114    
!      Some more variables for the standard light model photosynthesis     OJP0F404.46     
      REAL A,Pmx_10degC                                                    OJP0F404.47     
      REAL Iav(IMT,KM)                                                     OJP0F404.48     
      REAL Pmx(IMT,KM)                                                     OJP0F404.49     
                                                                           BIOLOGY.115    
      REAL worka (IMT,KM+2)     ! Temporary workspace                      OJP0F404.50     
     +,    workb (IMT,KM+2)     !     "         "                          OJP0F404.51     
     +,    work  (IMT,KM)       !     "         "                          BIOLOGY.118    
     +,    numer (IMT,KM)       !     "         "                          BIOLOGY.119    
     +,    denom (IMT,KM)       !     "         "                          BIOLOGY.120    
     +,    fxa,fxb,fxc,fxd                                                 BIOLOGY.121    
     +,    remin_rate                                                      OJP0F404.52     
                                                                           BIOLOGY.122    
      REAL daylength            ! Daylength (hours) for this row at this   BIOLOGY.123    
                                !  time of year                            BIOLOGY.124    
      REAL TIMESTEP_DAYS(KM)    ! Timestep in days (the biological model   OJP0F404.53     
                                ! requires timestep to be in fraction      BIOLOGY.126    
                                ! of a day, which makes the specificatio   BIOLOGY.127    
                                ! of rate constants somewhat easier).      BIOLOGY.128    
C                                                                          ONT1F304.498    
C     Workspace, intercepted for full-field diagnostics                    ONT1F304.499    
C                                                                          ONT1F304.500    
      REAL WPRIM_PROD(IMT)                                                 ONT1F304.501    
     &    ,WZOO_PROD(IMT)                                                  ONT1F304.502    
     &    ,WPHYTO_GROW (IMT,KM)                                            ONT1F304.503    
     &    ,WPHYTO_MORT(IMT,KM)                                             ONT1F304.504    
                                                                           BIOLOGY.129    
C                                                                          BIOLOGY.130    
C     Set up the constants used by the model.  The values used are         BIOLOGY.131    
C     hard-wired in - they are NOT designed to be adjusted by the          BIOLOGY.132    
C     user. These values have been assigned from the results of            BIOLOGY.133    
C     extensive testing of the 1-D version of the model.                   BIOLOGY.134    
C                                                                          BIOLOGY.135    
!     Comdeck OBIOCONST types and evaluates the ecomodel constants.        OJP0F404.54     
*CALL OBIOCONST                                                            OJP0F404.55     
      REAL                                                                 OJP0F404.56     
     +    const1_p,const1_dt,const2_p,const2_dt,const3_p,const3_dt         OJP0F404.57     
     +    ,const4_p,const4_dt,const5,const6,const7,const8                  OJP0F404.58     
                                                                           BIOLOGY.142    
      PARAMETER (const1_p = 1.0 - beta_p)                                  BIOLOGY.190    
      PARAMETER (const1_dt = 1.0 - beta_dt)                                BIOLOGY.191    
      PARAMETER (const2_p = c2n_p - beta_p*c2n_z)                          BIOLOGY.192    
      PARAMETER (const2_dt = c2n_d - beta_dt*c2n_z)                        BIOLOGY.193    
      PARAMETER (const3_p = 1.0 - beta_p*c2n_p/c2n_z)                      BIOLOGY.194    
      PARAMETER (const3_dt = 1.0 - beta_dt*c2n_d/c2n_z)                    BIOLOGY.195    
      PARAMETER (const4_p = c2n_p * const1_p)                              BIOLOGY.196    
      PARAMETER (const4_dt = c2n_d * const1_dt)                            BIOLOGY.197    
      PARAMETER (const5 = c2n_p - c2n_d)                                   BIOLOGY.198    
      PARAMETER (const6 = c2n_p / c2n_d)                                   BIOLOGY.199    
      PARAMETER (const7 =  c2n_z/c2n_d)                                    BIOLOGY.200    
      PARAMETER (const8 = 1.0 - const7)                                    BIOLOGY.201    
C                                                                          BIOLOGY.202    
!  Allow for any of the biological tracers being negative, by              OJP0F404.59     
!  creating a copy which is minimum zero for calculating rates.            OJP0F404.60     
!  Note that the local biology uses a forward time step for                OJP0F404.61     
!  stability of the decay-type components.                                 OJP0F404.62     
      DO K=1,KM                                                            OJP0F404.63     
        DO I=1,IMT                                                         OJP0F404.64     
          N(I,K)=AMAX1(TB(I,K,NUTRIENT_TRACER),0.0)                        OJP0F404.65     
          P(I,K)=AMAX1(TB(I,K,PHYTO_TRACER),0.0)                           OJP0F404.66     
          Z(I,K)=AMAX1(TB(I,K,ZOO_TRACER),0.0)                             OJP0F404.67     
          D(I,K)=AMAX1(TB(I,K,DETRITUS_TRACER),0.0)                        OJP0F404.68     
        ENDDO                                                              OJP0F404.69     
      ENDDO                                                                OJP0F404.70     
                                                                           OJP0F404.71     
C  Set indices for copying working arrays to STASH workspace               ONT1F304.505    
C                                                                          ONT1F304.506    
      IF (L_OCYCLIC) THEN                                                  ORH1F305.4249   
         ISSW=2                                                            ONT1F304.508    
         IESW=IMT-1                                                        ONT1F304.509    
      ELSE                                                                 ORH1F305.4250   
         ISSW=1                                                            ONT1F304.511    
         IESW=IMT                                                          ONT1F304.512    
      ENDIF                                                                ORH1F305.4251   
C                                                                          BIOLOGY.203    
C    Convert timestep from seconds to days and set daylength               BIOLOGY.204    
C                                                                          BIOLOGY.205    
      DO K=1,KM                                                            OJP0F404.72     
        TIMESTEP_DAYS(K)  = TIMESTEP(K) / (86400.0)                        OJP0F404.73     
      ENDDO                                                                OJP0F404.74     
      daylength = DAYLEN(J,I_DAY_NUMBER)                                   BIOLOGY.207    
                                                                           OJP0F404.75     
!  Calculate the tracer physics nutrient supply rate for implicit          OJP0F404.76     
!  nutrient calculations                                                   OJP0F404.77     
      DO K=1,KM                                                            BIOLOGY.209    
        DO I=1,IMT                                                         OJP0F404.78     
          Nsupply(I,K)=(TA(I,K,NUTRIENT_TRACER)-                           OJP0F404.79     
     +                  TB(I,K,NUTRIENT_TRACER))/TIMESTEP_DAYS(K)          OJP0F404.80     
        ENDDO                                                              OJP0F404.81     
      ENDDO                                                                OJP0F404.82     
                                                                           OJP0F404.83     
      DO K=1,KM                                                            OJP0F404.84     
        DO I=ISSW,IESW                                                     ORH1F305.4252   
C                                                                          BIOLOGY.218    
C    Compute temperature function (higher temps => faster growth)          BIOLOGY.219    
C                                                                          BIOLOGY.220    
        lim_temp(i,k) = Q10H **(0.1*(TB(I,K,1)-ref_t))                     OJP0F404.85     
        ENDDO                                                              BIOLOGY.222    
      ENDDO                                                                BIOLOGY.223    
                                                                           BIOLOGY.224    
C    Convert from solar radiation averaged over a diurnal cycle, to        BIOLOGY.225    
C    noon irradiance, as required for calculating photosynthesis           BIOLOGY.226    
C    The factor 172.5755 converts from W/m2 to uEinsteins/s and assumes    BIOLOGY.227    
C    that suns zenith angle at noon is pi/2. Daylength must be > 0,        BIOLOGY.228    
C    else noon irradiance is zero (by definition - polar night).           BIOLOGY.229    
C    Also assume that all incident radiation is PAR - this is true for     BIOLOGY.230    
C    output from the atmospheric model, but may not be true for            BIOLOGY.231    
C    climatological forcing. ==> May need to scale SOL depending on        BIOLOGY.232    
C    whether the switch for the COUPLED model is set or not                BIOLOGY.233    
C    These points will have to be cleared up before finalising the model   BIOLOGY.234    
C                                                                          BIOLOGY.235    
                                                                           OJP0F404.86     
!    Quick and dirty light limitation using standard two band light        OJP0F404.87     
!    model if .NOT: L_OSOLAR                                               OJP0F404.88     
                                                                           OJP0F404.89     
      IF (L_OSOLARAL) THEN                                                 OJP0F404.90     
                                                                           OJP0F404.91     
      IF (daylength .NE. 0.0) THEN                                         BIOLOGY.236    
       DO I = 1,IMT                                                        BIOLOGY.237    
        sol_noon(I) = SOL(I)                                               BIOLOGY.238    
     +              * (172.5755 / daylength)                               BIOLOGY.239    
     +              * par                                                  BIOLOGY.240    
       ENDDO                                                               BIOLOGY.241    
      ELSE                                                                 BIOLOGY.242    
       DO I = 1,IMT                                                        BIOLOGY.243    
        sol_noon(I) = 0.0                                                  BIOLOGY.244    
       ENDDO                                                               BIOLOGY.245    
      ENDIF                                                                BIOLOGY.246    
C                                                                          BIOLOGY.247    
C    Call SPECTRAL to obtain the average rate of photosynthesis over       BIOLOGY.248    
C    the diurnal cycle (mg   /m3/day)                                      BIOLOGY.249    
C                                                                          BIOLOGY.250    
      CALL SPECTRAL (SOL_NOON,SOL_PEN,RTPIG,                               BIOLOGY.251    
*CALL ARGOCBIO                                                             BIOLOGY.252    
     +               KFIX,ALPHMX,ETA,                                      BIOLOGY.253    
     +               DZ,JMT,                                               BIOLOGY.254    
     +               IMT,KM,PSMAX,PSYNTH)                                  BIOLOGY.255    
                                                                           BIOLOGY.256    
C    Compute light limitation factor                                       BIOLOGY.257    
C     NB The factor 100.0 in fxa converts DZ from cms to metres.           BIOLOGY.258    
C                                                                          BIOLOGY.259    
      fxa = (daylength*psmax*100.0) / (pi*c2chl)                           BIOLOGY.260    
      DO K=1,KM                                                            BIOLOGY.261    
        DO I=ISSW,IESW                                                     ORH1F305.4253   
        lim_light (I,K) = psynth(I,K) * fxa/ DZ(K)                         BIOLOGY.268    
        ENDDO                                                              BIOLOGY.269    
      ENDDO                                                                BIOLOGY.270    
                                                                           OJP0F404.92     
      ELSE                                                                 OJP0F404.93     
!     use normal light model IF NOT L_OSOLARAL...                          OJP0F404.94     
!     Works in W/m2, so can use SOL(I) directly.                           OJP0F404.95     
!     Mean production in a level is calculated by using averaging          OJP0F404.96     
!     the solar irradiance at the top and bottom of the layer.             OJP0F404.97     
        A=0.055                                                            OJP0F404.98     
        Pmx_10degC=psmax                                                   OJP0F404.99     
      DO K=1,KM                                                            BIOLOGY.280    
        DO I=ISSW,IESW                                                     ORH1F305.4254   
            Iav(I,K)=SOL(I)*(SOL_PEN(I,K-1)+SOL_PEN(I,K))/2.0              OJP0F404.100    
            Pmx(I,K)=Pmx_10degC * lim_temp(I,K)                            OJP0F404.101    
            lim_light(I,K)=Pmx(I,K)*Iav(I,K)/((Pmx(I,K)/A)+Iav(I,K))       OJP0F404.102    
        ENDDO                                                              BIOLOGY.297    
      ENDDO                                                                BIOLOGY.298    
      ENDIF   !(IF L_OSOLARAL ELSE)                                        OJP0F404.103    
                                                                           OJP0F404.104    
C ----------------------------------------------------------------------   BIOLOGY.300    
C    Compute phytoplankton respiration. The rate of respiration,           BIOLOGY.301    
C    expressed as fraction of biomass lost per day, is assumed to          BIOLOGY.302    
C    be constant. This is because it is inappropriate to specify a         BIOLOGY.303    
C    simple time-varying rate in a global model.                           BIOLOGY.304    
C    Note that there are also associated flows to the nutrient and         BIOLOGY.305    
C    carbon boxes.                                                         BIOLOGY.306    
C                                                                          BIOLOGY.307    
      DO K=1,KM                                                            BIOLOGY.308    
        DO I=ISSW,IESW                                                     ORH1F305.4255   
        p_resp_p (I,K) = P(I,K) * resp_rate * FM(I,K)                      OJP0F404.105    
        p_resp_n (I,K) = p_resp_p(I,K)                                     OJP0F404.106    
        p_resp_c (I,K) = p_resp_p(I,K) * c2n_p                             OJP0F404.107    
        ENDDO                                                              BIOLOGY.320    
      ENDDO                                                                BIOLOGY.321    
C                                                                          BIOLOGY.322    
C ----------------------------------------------------------------------   BIOLOGY.323    
C    Compute zooplankton feeding fluxes                                    BIOLOGY.324    
C ----------------------------------------------------------------------   BIOLOGY.325    
C                                                                          BIOLOGY.326    
C    Now calculate grazing terms. Note that the loss of phytoplankton      BIOLOGY.327    
C    and detritus represents a gain by zooplankton, but remember           BIOLOGY.328    
C    that we have to take account of the differing bodily compositions     BIOLOGY.329    
C    of each component and balance the C and N budgets accordingly.        BIOLOGY.330    
C                                                                          BIOLOGY.331    
!    Use the array WORK to store the total amount of food (in              OJP0F404.108    
!    common "biomass equivalent" units) in excess of the                   OJP0F404.109    
!    grazing threshold, raised to the power of the Holling                 OJP0F404.110    
!    coefficient.                                                          OJP0F404.111    
      DO K=1,KM                                                            BIOLOGY.332    
        DO I=ISSW,IESW                                                     ORH1F305.4256   
         work (I,K) =                                                      OJP0F404.112    
     &             (amax1(0.0,((n2be_p*P(I,K)+n2be_d*D(I,K))               OJP0F404.113    
     &                 -graze_threshold)))                                 OJP0F404.114    
     &                **holling_coef                                       OJP0F404.115    
                                                                           BIOLOGY.342    
         ingestion_rate(I,K) = (n2be_z*Z(I,K)*graze_max*work(I,K))         OJP0F404.116    
     &                       * FM(I,K)                                     OJP0F404.117    
     &                       / (work(I,K) + graze_sat**holling_coef)       OJP0F404.118    
C                                                                          BIOLOGY.343    
C    Compute loss of phytoplankton due to grazing by zooplankton           BIOLOGY.344    
!    Small extra term in denominator prevents zero divide when grazing     OJP0F404.119    
!    is zero (as over land points).                                        OJP0F404.120    
          pgraze(I,K) = ingestion_rate(I,K) * P(I,K)                       OJP0F404.121    
     &              / (1.0e-10 + n2be_p*P(I,K) + n2be_d*D(I,K))            OJP0F404.122    
C                                                                          BIOLOGY.345    
C    Compute loss of detritus due to grazing by zooplankton                BIOLOGY.349    
          dgraze(I,K) = ingestion_rate(I,K) * D(I,K)                       OJP0F404.123    
     &              / (1.0e-10 + n2be_d*P(I,K) + n2be_d*D(I,K))            OJP0F404.124    
        ENDDO                                                              BIOLOGY.352    
      ENDDO                                                                BIOLOGY.353    
                                                                           BIOLOGY.354    
C    The total ingestion rate by zooplankton is the sum of the two         BIOLOGY.355    
C    terms pgraze and dgraze. Now work out the C:N ratio of this           BIOLOGY.356    
C    pool of assimilatable material.                                       BIOLOGY.357    
C                                                                          BIOLOGY.358    
      DO K=1,KM                                                            BIOLOGY.359    
        DO I=ISSW,IESW                                                     ORH1F305.4257   
          numer(I,K) = pgraze(I,K) * beta_p * c2n_p                        OJP0F404.125    
     +              + dgraze(I,K) * beta_dt * c2n_d                        BIOLOGY.367    
          denom(I,K) = pgraze(I,K) * beta_p + dgraze(I,K) * beta_dt        OJP0F404.126    
C                                                                          BIOLOGY.369    
C    Small extra term in denominator prevents zero divide when grazing     BIOLOGY.370    
C    is zero (as over land points).                                        BIOLOGY.371    
        c2n_food (I,K) = numer(I,K) / (1.0e-10 + denom(I,K))               BIOLOGY.373    
        ENDDO                                                              BIOLOGY.374    
      ENDDO                                                                BIOLOGY.375    
C                                                                          BIOLOGY.376    
C    Test whether the food's C:N ratio is greater or less than that        BIOLOGY.377    
C    of zooplankton, and work out the flux of material into the            BIOLOGY.378    
C    zooplankton accordingly. Also compute the amounts of N and C          BIOLOGY.379    
c    left unassimilated.                                                   BIOLOGY.380    
C                                                                          BIOLOGY.381    
      DO K=1,KM                                                            BIOLOGY.382    
        DO I=ISSW,IESW                                                     ORH1F305.4258   
          IF (c2n_food(I,K) .GE. c2n_z) THEN  !nitrogen limits uptake      OJP0F404.127    
          zgrowth (I,K) = denom(I,K)                                       BIOLOGY.390    
     +                           * FM(I,K)                                 BIOLOGY.391    
          unassim_n (I,K) = pgraze(I,K)*const1_p                           BIOLOGY.392    
     +                    + dgraze(I,K)*const1_dt                          BIOLOGY.393    
          unassim_c (I,K) = pgraze(I,K)*const2_p                           BIOLOGY.394    
     +                    + dgraze(I,K)*const2_dt                          BIOLOGY.395    
        ELSE                                ! carbon limits uptake         BIOLOGY.396    
          zgrowth (I,K) = numer(I,K) / c2n_z                               BIOLOGY.397    
     +                           * FM(I,K)                                 BIOLOGY.398    
          unassim_n (I,K) = pgraze(I,K)*const3_p                           BIOLOGY.399    
     +                    + dgraze(I,K)*const3_dt                          BIOLOGY.400    
          unassim_c (I,K) = pgraze(I,K)*const4_p                           BIOLOGY.401    
     +                    + dgraze(I,K)*const4_dt                          BIOLOGY.402    
        ENDIF                                                              BIOLOGY.403    
        ENDDO                                                              BIOLOGY.404    
      ENDDO                                                                BIOLOGY.405    
                                                                           BIOLOGY.406    
C    Compute C:N ratio of the unassimilated material and excrete as        BIOLOGY.407    
C    much as possible in the form of detritus - the amount excreted        BIOLOGY.408    
C    will depend on the C:N ratio as compared with that of detritus.       BIOLOGY.409    
C    Release excess material to nutrient and carbon boxes as appropriate   BIOLOGY.410    
C                                                                          BIOLOGY.411    
C    Small extra term in denominator prevents zero divide when grazing     BIOLOGY.413    
C    is zero (as over land points).                                        BIOLOGY.414    
C                                                                          BIOLOGY.415    
      DO K=1,KM                                                            BIOLOGY.416    
        DO I=ISSW,IESW                                                     ORH1F305.4259   
          c2n_junk(I,K) = unassim_c(I,K)/(1.0e-10 + unassim_n(I,K))        OJP0F404.128    
        ENDDO                                                              BIOLOGY.424    
      ENDDO                                                                BIOLOGY.425    
                                                                           BIOLOGY.426    
      DO K=1,KM                                                            BIOLOGY.427    
        DO I=ISSW,IESW                                                     ORH1F305.4260   
          IF (c2n_junk(I,K) .GE. c2n_d) THEN  !nitrogen limits egestion    OJP0F404.129    
          excrete_n(I,K) = 0.0                                             BIOLOGY.436    
          excrete_c(I,K) = unassim_c (I,K) - c2n_d * unassim_n (I,K)       BIOLOGY.437    
          excrete_dt(I,K) = unassim_n (I,K)                                BIOLOGY.438    
          ELSE                                !carbon limits egestion      OJP0F404.130    
          excrete_n(I,K) = unassim_n (I,K) - (unassim_c (I,K)/c2n_d)       BIOLOGY.442    
          excrete_c(I,K) = 0.0                                             BIOLOGY.443    
          excrete_dt(I,K) = unassim_c (I,K)/c2n_d                          BIOLOGY.444    
        ENDIF                                                              BIOLOGY.446    
        ENDDO                                                              BIOLOGY.447    
      ENDDO                                                                BIOLOGY.448    
C                                                                          BIOLOGY.449    
C ----------------------------------------------------------------------   BIOLOGY.450    
C                                                                          BIOLOGY.451    
!  Compute natural mortality of phytoplankton and the associated fluxes.   OJP0F404.131    
!  Specific mortality is a linear function of P (eg overpopulation).       OJP0F404.132    
C ----------------------------------------------------------------------   BIOLOGY.458    
C                                                                          BIOLOGY.459    
      DO K=1,KM                                                            BIOLOGY.460    
        DO I=ISSW,IESW                                                     ORH1F305.4261   
          wphyto_mort (I,K) = pmort_max * P(I,K) * FM(I,K)                 OJP0F404.133    
          p_mort(I,K) = P(I,K) * wphyto_mort(I,K)                          OJP0F404.134    
C                                                                          BIOLOGY.470    
C    Switch off mortality if Phyto Conc. falls below a threshold           BIOLOGY.471    
C    value.                                                                BIOLOGY.472    
          IF (P(I,K) .LT. phyto_min) p_mort(I,K)=0.0                       OJP0F404.135    
        ENDDO                                                              BIOLOGY.475    
      ENDDO                                                                BIOLOGY.476    
                                                                           BIOLOGY.477    
C                                                                          BIOLOGY.478    
C    As much as possible of the material flowing out of the phytoplankto   BIOLOGY.479    
C    compartment goes to detritus, depending on the C:N ratios of each     BIOLOGY.480    
C    component. The remainder goes to N or TCO2 as appropriate             BIOLOGY.481    
C                                                                          BIOLOGY.482    
      DO K=1,KM                                                            BIOLOGY.483    
        DO I=ISSW,IESW                                                     ORH1F305.4262   
        IF (c2n_p .GE. c2n_d) THEN                                         BIOLOGY.490    
          p_mort_dt (I,K) = p_mort(I,K)                                    BIOLOGY.491    
          p_mort_n (I,K) = 0.0                                             BIOLOGY.492    
          p_mort_c (I,K) = p_mort(I,K) * const5                            BIOLOGY.493    
        ELSE                                                               BIOLOGY.494    
          p_mort_dt (I,K) = p_mort(I,K) * const6                           BIOLOGY.495    
          p_mort_n (I,K) = p_mort(I,K) - p_mort_dt(I,K)                    BIOLOGY.496    
          p_mort_c (I,K) = 0.0                                             BIOLOGY.497    
        ENDIF                                                              BIOLOGY.498    
        ENDDO                                                              BIOLOGY.499    
      ENDDO                                                                BIOLOGY.500    
                                                                           BIOLOGY.501    
C ----------------------------------------------------------------------   BIOLOGY.502    
!    Compute zooplankton mortality.                                        OJP0F404.136    
C ----------------------------------------------------------------------   BIOLOGY.505    
C                                                                          BIOLOGY.506    
      DO K=1,KM                                                            BIOLOGY.507    
        DO I=ISSW,IESW                                                     ORH1F305.4263   
        z_mort (I,K) = ( z_mort_1 * Z(I,K) +                               OJP0F404.137    
     &                   z_mort_2 * Z(I,K) * Z(I,K) ) * FM(I,K)            OJP0F404.138    
                                                                           BIOLOGY.516    
C    A certain proportion of the flux from zooplankton is remineralized    BIOLOGY.517    
C    to N and TCO2, representing material travelling up the food chain     BIOLOGY.518    
C    and being excreted at each stage. The remainder is egested as         BIOLOGY.519    
C    detritus. In some cases, depending on the fraction to be reminerali   BIOLOGY.520    
C    and the ratio of C:N ratios for zooplankton and detritus, there       BIOLOGY.521    
C    may be no release of C to TCO2 at all, and the flux to detritus       BIOLOGY.522    
C    is then limited by the carbon available.                              BIOLOGY.523    
C                                                                          BIOLOGY.524    
        IF (z_remin .GE. const8) THEN                                      BIOLOGY.525    
          z_mort_n(I,K) = z_mort(I,K) * z_remin                            BIOLOGY.526    
          z_mort_dt(I,K) = z_mort(I,K) * z_detrit                          BIOLOGY.527    
          z_mort_c(I,K) = z_mort(I,K) * (z_remin-const8) * c2n_d           BIOLOGY.528    
        ELSE                                                               BIOLOGY.529    
          z_mort_n(I,K) = z_mort(I,K) * const8                             BIOLOGY.530    
          z_mort_dt(I,K) = z_mort(I,K) * const7                            BIOLOGY.531    
          z_mort_c(I,K) = 0.0                                              BIOLOGY.532    
        ENDIF                                                              BIOLOGY.533    
        ENDDO                                                              BIOLOGY.534    
      ENDDO                                                                BIOLOGY.535    
                                                                           BIOLOGY.536    
C ----------------------------------------------------------------------   BIOLOGY.537    
C    Compute remineralization of detritus into nutrient (remembering       BIOLOGY.538    
C    that there is an associated release of carbon and nutrient)           BIOLOGY.539    
C ----------------------------------------------------------------------   BIOLOGY.540    
C                                                                          BIOLOGY.541    
      DO K=1,KM                                                            BIOLOGY.542    
        IF (K .GT. 8) THEN                                                 OJP0F404.139    
          remin_rate=remin_rate_deep                                       OJP0F404.140    
        ELSE                                                               OJP0F404.141    
          remin_rate=remin_rate_shallow                                    OJP0F404.142    
        ENDIF                                                              OJP0F404.143    
        DO I=ISSW,IESW                                                     ORH1F305.4264   
          d_remin(I,K)   = remin_rate * D(I,K) * FM(I,K)                   OJP0F404.144    
          d_remin_n(I,K) = d_remin(I,K)                                    OJP0F404.145    
          d_remin_c(I,K) = d_remin(I,K) * c2n_d                            OJP0F404.146    
        ENDDO                                                              OJP0F404.147    
      ENDDO                                                                OJP0F404.148    
                                                                           OJP0F404.149    
! ---- Do the semi-implicit phyto growth calculations ------------         OJP0F404.150    
                                                                           OJP0F404.151    
!    Calculate the nutrient at the end of the timestep using a             OJP0F404.152    
!    semi-implicit scheme to stabilize the explicit growth term.           OJP0F404.153    
!    Find the semi-implicit lim_nut in the same loop. Nsupply is           OJP0F404.154    
!    the physical nutrient supply calculated from TA-TB                    OJP0F404.155    
                                                                           OJP0F404.156    
      DO K=1,KM                                                            OJP0F404.157    
        DO I=ISSW,IESW                                                     OJP0F404.158    
          work(I,K) = (  d_remin_n(I,K)                                    OJP0F404.159    
     &                 + p_mort_n(I,K)                                     OJP0F404.160    
     &                 + excrete_n(I,K)                                    OJP0F404.161    
     &                 + z_mort_n(I,K)                                     OJP0F404.162    
     &                 + p_resp_n(I,K)                                     OJP0F404.163    
     &                 + Nsupply(I,K) ) * TIMESTEP_DAYS(K)                 OJP0F404.164    
          NI(I,K)=(work(I,K)+N(I,K))/                                      OJP0F404.165    
     &         (1 + ((lim_light(I,K)*TIMESTEP_DAYS(K)*P(I,K))/             OJP0F404.166    
     &                (N(I,K) + grow_sat)) )                               OJP0F404.167    
          NI(I,K)=AMAX1(NI(I,K),0.0)                                       OJP0F404.168    
!    Compute nutrient limitation factor                                    OJP0F404.169    
          lim_nut(i,k) = NI(I,K) / (N(I,K) + grow_sat)                     OJP0F404.170    
        ENDDO                                                              OJP0F404.171    
      ENDDO                                                                OJP0F404.172    
                                                                           OJP0F404.173    
!    Combine the limitation factors and compute the rate of flow of        OJP0F404.174    
!    material into the phytoplankton component due to growth.              OJP0F404.175    
                                                                           OJP0F404.176    
      DO K=1,KM                                                            OJP0F404.177    
        DO I=ISSW,IESW                                                     OJP0F404.178    
        wphyto_grow(I,K) = lim_nut(I,K)                                    OJP0F404.179    
     &                           * lim_light(I,K)                          OJP0F404.180    
     +                           * FM(I,K)                                 BIOLOGY.550    
        growth_p(I,K) = P(I,K) * wphyto_grow(I,K)                          OJP0F404.181    
        growth_n(I,K) = growth_p (I,K)                                     OJP0F404.182    
        growth_c(I,K) = growth_p (I,K) * c2n_p                             OJP0F404.183    
        ENDDO                                                              BIOLOGY.553    
      ENDDO                                                                BIOLOGY.554    
C                                                                          BIOLOGY.555    
C ----------------------------------------------------------------------   BIOLOGY.556    
C ----------------------------------------------------------------------   BIOLOGY.557    
!     UPDATE {N,P,Z,D,TCO2,ALK} in the end of timestep array TA            OJP0F404.184    
C                                                                          BIOLOGY.560    
      DO K=1,KM                                                            BIOLOGY.563    
        DO I=ISSW,IESW                                                     ORH1F305.4265   
C     The equation for phytoplankton is :                                  BIOLOGY.570    
C     dP/dt = (growth) - (grazing) - (natural mortality) - (respiration)   BIOLOGY.571    
C           - (sinking out of layer) + (sinking in to layer)               BIOLOGY.572    
C                                                                          BIOLOGY.573    
          TA(I,K,PHYTO_TRACER) = TA(I,K,PHYTO_TRACER) +                    OJP0F404.185    
     &       TIMESTEP_DAYS(K) *                                            OJP0F404.186    
     &     (growth_p(I,K) - pgraze(I,K) - p_mort(I,K) - p_resp_p(I,K))     OJP0F404.187    
C                                                                          BIOLOGY.577    
C     The eqn for zooplankton is :                                         BIOLOGY.578    
C     dZ/dt = (grazing_phyto + grazing_detritus) - (mortality)             BIOLOGY.579    
C           - (sinking out of layer) + (sinking in to layer)               BIOLOGY.580    
          TA(I,K,ZOO_TRACER) = TA(I,K,ZOO_TRACER) +                        OJP0F404.188    
     &        TIMESTEP_DAYS(K) * ( zgrowth(I,K) - z_mort(I,K) )            OJP0F404.189    
C                                                                          BIOLOGY.581    
C     The eqn for nutrients is :                                           BIOLOGY.585    
C     dN/dt = -(growth) + (detritus re-min) + (unassimilated grazing)      BIOLOGY.586    
C           + (zoopl mortality) + (phyto mortality)                        BIOLOGY.587    
C           + (phyto respiration)                                          BIOLOGY.588    
C                                                                          BIOLOGY.589    
          TA(I,K,NUTRIENT_TRACER) = TA(I,K,NUTRIENT_TRACER) +              OJP0F404.190    
     &       TIMESTEP_DAYS(K) *                                            OJP0F404.191    
     +       ( - growth_n(I,K) + d_remin_n(I,K) + excrete_n(I,K)           BIOLOGY.591    
     +         + z_mort_n(I,K) + p_mort_n(I,K)                             BIOLOGY.592    
     +         + p_resp_n(I,K) )                                           BIOLOGY.593    
C                                                                          BIOLOGY.604    
C     The eqn for carbon is :                                              BIOLOGY.605    
C     dC/dt = -(growth) + (detritus re-min) + (unassimilated grazing)      BIOLOGY.606    
C           + (zoopl mortality) + (phyto mortality)                        BIOLOGY.607    
C           + (phyto respiration)                                          BIOLOGY.608    
C                                                                          BIOLOGY.609    
          TA(I,K,TCO2_TRACER) = TA(I,K,TCO2_TRACER) +                      OJP0F404.192    
     &         TIMESTEP_DAYS(K) *                                          OJP0F404.193    
     +       ( - growth_c(I,K) + d_remin_c(I,K) + excrete_c(I,K)           BIOLOGY.611    
     +         + z_mort_c(I,K) + p_mort_c(I,K)                             BIOLOGY.612    
     +         + p_resp_c(I,K) )                                           BIOLOGY.613    
                                                                           BIOLOGY.614    
C                                                                          BIOLOGY.615    
C     The eqn for Alkalinity is :                                          BIOLOGY.625    
C     dALK/dt = -(flux into nutrients) - 2*(caCO3 production rate)         BIOLOGY.626    
C                                                                          BIOLOGY.627    
          TA(I,K,ALK_TRACER) = TA(I,K,ALK_TRACER) +                        OJP0F404.194    
     &        TIMESTEP_DAYS(K) *                                           OJP0F404.195    
     &       (   growth_n(I,K) - d_remin_n(I,K) - excrete_n(I,K)           OJP0F404.196    
     &         - z_mort_n(I,K) - p_mort_n(I,K)                             OJP0F404.197    
     &         - p_resp_n(I,K) )                                           OJP0F404.198    
                                                                           BIOLOGY.634    
        ENDDO                                                              BIOLOGY.635    
      ENDDO                                                                BIOLOGY.636    
                                                                           BIOLOGY.637    
C                                                                          BIOLOGY.638    
!     The eqn for detritus is :                                            OJP0F404.199    
!     dD/dt = (zooplankton mortality) + (phytoplankton mortality)          OJP0F404.200    
!           - (detritus remin) - (zoopl grazing) + (zoopl egestion)        OJP0F404.201    
!           - (sinking out of layer) + (sinking in to layer)               OJP0F404.202    
!                                                                          OJP0F404.203    
!     Treat the sinking flux and the biology sources and sinks             OJP0F404.204    
!     together, semi-implicitly.                                           OJP0F404.205    
C     Note: factor 100.0 converts from metres to cms.                      BIOLOGY.642    
!     The scheme used is semi-implicit in the sinking to                   OJP0F404.206    
!     allow long timesteps despite the fast sinking rate. This is          OJP0F404.207    
!     rather simple because sinking is downwards only.                     OJP0F404.208    
C                                                                          BIOLOGY.644    
!     work(I,K) holds the sum of the local sources and sinks.              OJP0F404.209    
!     WORKA(K) holds the detritus density of the level (K-1) at the        OJP0F404.210    
!       end of the timestep                                                OJP0F404.211    
!     DDT(I,K) holds the timestep change in D calculated here by           OJP0F404.212    
!       subtracting D from the new implicitly calculated value.            OJP0F404.213    
      DO K = 1,KM                                                          OJP0F404.214    
            DO I = ISSW, IESW                                              ORH1F305.4269   
           work(I,K) = z_mort_dt(I,K) + p_mort_dt(I,K) - d_remin(I,K)      OJP0F404.215    
     &               - dgraze(I,K) + excrete_dt(I,K)                       OJP0F404.216    
           IF (K.EQ.1) THEN                                                OJP0F404.217    
             WORKA(I,K) = 0.0                                              OJP0F404.218    
           ELSE                                                            OJP0F404.219    
             WORKA(I,K) = D(I,K-1) + DDT(I,K-1)                            OJP0F404.220    
           ENDIF                                                           OJP0F404.221    
           DDT(I,K)=-D(I,K) +                                              OJP0F404.222    
     &    ( (TIMESTEP_DAYS(K) * work(I,K))                                 OJP0F404.223    
     &    + (TIMESTEP_DAYS(K) * sink_rate_dt*WORKA(I,K)/(DZ(K)/100.0))     OJP0F404.224    
     &    +  D(I,K)                                                        OJP0F404.225    
     &    ) /                                                              OJP0F404.226    
     &    (1 + sink_rate_dt*TIMESTEP_DAYS(K)/(DZ(K)/100.0))                OJP0F404.227    
           TA(I,K,DETRITUS_TRACER)=TA(I,K,DETRITUS_TRACER) +               OJP0F404.228    
     &        DDT(I,K) * FM(I,K)                                           OJP0F404.229    
            ENDDO   ! OVER I                                               ORH5F400.12     
         ENDDO      ! OVER K                                               ORH5F400.13     
                                                                           OJP0F404.230    
!  Explicitly reflux detritus that hits the bottom at level KMT back       OJP0F404.231    
!  into top box:                                                           OJP0F404.232    
            DO I = ISSW, IESW                                              ORH1F305.4280   
         DDT(I,1)=DDT(I,1)+TIMESTEP_DAYS(1) * sink_rate_dt *               OJP0F404.233    
     &      (D(I,KMT(I)) + DDT(I,KMT(I))) / (DZ(1)/100.0)                  OJP0F404.234    
         TA(I,1,DETRITUS_TRACER)=TA(I,1,DETRITUS_TRACER) +                 OJP0F404.235    
     &     TIMESTEP_DAYS(1) * sink_rate_dt *                               OJP0F404.236    
     &      (D(I,KMT(I)) + DDT(I,KMT(I))) / (DZ(1)/100.0) * FM(I,1)        OJP0F404.237    
            ENDDO   ! OVER I                                               ORH5F400.14     
                                                                           BIOLOGY.671    
!                                                                          OJP0F404.238    
! ------------ Carbonate pump -------------                                OJP0F404.239    
!                                                                          OJP0F404.240    
! If water column is deeper than lysocline then the carbonate pump can     OJP0F404.241    
! pump carbon and alkalinity to the deep ocean.                            OJP0F404.242    
! If carbonate production is based on primary production, as one might     OJP0F404.243    
! expect if zooplankton do not assimilate shells, then to get a Broeker    OJP0F404.244    
! 'rain ratio' of 0.25 export production, use pri_prod_c * 1/4 * 0.25,     OJP0F404.245    
! where our f-ratio at 50m is typically 4.                                 OJP0F404.246    
! ie set our rain_ratio ~ 0.06                                             OJP0F404.247    
! For a Yamanaka-type lower rain_ratio of 0.1 use our rain_ratio ~0.025    OJP0F404.248    
      DO I = ISSW, IESW                                                    OJP0F404.249    
        IF (FM(I,lysocline) .GT. 0.0) THEN                                 OJP0F404.250    
                                                                           BIOLOGY.683    
!  Integrate detritus production over water column and multiply by         OJP0F404.251    
!  Redfield and rain ratios to get carbonate export in umoles/m2:          OJP0F404.252    
          DO K = 1,KMT(I)                                                  OJP0F404.253    
            IF (K.EQ.1) THEN                                               OJP0F404.254    
              export_co3(I) = 0.0                                          OJP0F404.255    
      ENDIF                                                                ORH1F305.4309   
            local_export = growth_p(I,K) * c2n_d * rain_ratio              OJP0F404.256    
!            local_export= (z_mort_dt(I,K) + p_mort_dt(I,K)                OJP0F404.257    
!     &                      + excrete_dt(I,K))                            OJP0F404.258    
!     &                      * c2n_d * rain_ratio                          OJP0F404.259    
            export_co3(I) = export_co3(I)                                  OJP0F404.260    
     &                    + local_export                                   OJP0F404.261    
     &                    * 1000.0 * DZ(K) / 100.0 ! in umoles/m2          OJP0F404.262    
!  Remove carbon and alkalinity from where carbonate is produced:          OJP0F404.263    
            TA(I,K,TCO2_TRACER) = TA(I,K,TCO2_TRACER)                      OJP0F404.264    
     &         - (local_export*TIMESTEP_DAYS(K))                           OJP0F404.265    
            TA(I,K,ALK_TRACER) = TA(I,K,ALK_TRACER)                        OJP0F404.266    
     &         - (local_export*2.0*TIMESTEP_DAYS(K))                       OJP0F404.267    
          ENDDO  ! over K                                                  OJP0F404.268    
                                                                           ORH1F305.4310   
!  Deposit exported carbonate as TCO2 and ALK over water column below      OJP0F404.269    
!  lysocline:                                                              OJP0F404.270    
          column_depth = (ZDZ(KMT(I)) - ZDZ(lysocline-1))/100.0 !metres    OJP0F404.271    
          DO K = lysocline,KMT(I)                                          OJP0F404.272    
            TA(I,K,TCO2_TRACER)=TA(I,K,TCO2_TRACER)                        OJP0F404.273    
     &       + TIMESTEP_DAYS(K)*(export_co3(I) / column_depth)/1000.0      OJP0F404.274    
            TA(I,K,ALK_TRACER)=TA(I,K,ALK_TRACER)                          OJP0F404.275    
     &       + TIMESTEP_DAYS(K)*(export_co3(I) / column_depth)*2.0/1000.   OJP0F404.276    
          ENDDO ! over K                                                   OJP0F404.277    
        ELSE                                                               OJP0F404.278    
          export_co3(I)=0.0  ! Set to zero as this may be a diagnostic.    OJP0F404.279    
        ENDIF ! (FM(I,lysocline) .GT. 0.0)                                 OJP0F404.280    
      ENDDO  ! over I                                                      OJP0F404.281    
C                                                                          ONT1F304.522    
C Compute diagnostics                                                      ONT1F304.523    
C                                                                          ONT1F304.524    
C Zero workspace before integrating downwards from surface.                ONT1F304.525    
C fxa converts from cms to metres and from mmols-N to gC                   ONT1F304.526    
C (Molecular weight of carbon is 12)                                       ONT1F304.527    
C                                                                          ONT1F304.528    
      DO I=ISSW,IESW                                                       ONT1F304.529    
        WPRIM_PROD(I)=0.0                                                  ONT1F304.530    
        WZOO_PROD(I)=0.0                                                   ONT1F304.531    
      ENDDO                                                                ONT1F304.532    
                                                                           ONT1F304.533    
      fxa=1.0E-5 * c2n_p * 12                                              ONT1F304.534    
                                                                           ONT1F304.535    
      DO K=1,KM                                                            OJP0F404.282    
        DO I=ISSW,IESW                                                     ONT1F304.537    
          WPRIM_PROD(I)=WPRIM_PROD(I)+DZ(K)*growth_p(I,K)*fxa              ONT1F304.538    
          WZOO_PROD(I)=WZOO_PROD(I)+DZ(K)*zgrowth(I,K)*fxa                 ONT1F304.539    
        ENDDO                                                              ONT1F304.540    
      ENDDO                                                                ONT1F304.541    
C                                                                          ONT1F304.542    
C Copy diagnostics from working arrays into full field arrays              ONT1F304.543    
C 1. Single-level diagnostics                                              ONT1F304.544    
C                                                                          ONT1F304.545    
      DO I=ISSW,IESW                                                       ONT1F304.546    
          II=MOD(I-1,SWNCOL)+1                                             ONT1F304.547    
          IF (SF_BIO(1)) PRIM_PROD(II,J)=WPRIM_PROD(I)                     ONT1F304.548    
!          IF (SF_BIO(2)) ZOO_PROD(II,J)=WZOO_PROD(I)                      OJP0F404.283    
! Hijack bio diagnostic 2 to get export_co3 out                            OJP0F404.284    
          IF (SF_BIO(2)) ZOO_PROD(II,J)=export_co3(I)                      OJP0F404.285    
                                                                           OJP0F404.286    
      ENDDO                                                                ONT1F304.550    
C                                                                          ONT1F304.551    
C 2. Fully-dimensioned diagnostics                                         ONT1F304.552    
C                                                                          ONT1F304.553    
      DO K=1,KM                                                            ONT1F304.555    
        DO I=ISSW,IESW                                                     ONT1F304.556    
          II=MOD(I-1,SWNCOL)+1                                             ONT1F304.557    
          IF (SF_BIO(3)) PHYTO_GROW(II,J,K)=wphyto_grow(I,K)               ONT1F304.558    
          IF (SF_BIO(4)) PHYTO_GRAZE(II,J,K) = pgraze(I,K)                 OJP0F404.287    
     &                                         * FM(I,K)                   OJP0F404.288    
     &                                       / (P(I,K) + 1.0e-10)          OJP0F404.289    
          IF (SF_BIO(5)) PHYTO_MORT(II,J,K)=wphyto_mort(I,K)               ONT1F304.560    
          IF (SF_BIO(6)) EXCRETE_NUT(II,J,K)=excrete_n(I,K)                ONT1F304.561    
          IF (SF_BIO(7)) GROW_NUT(II,J,K)=-growth_n(I,K)                   ONT1F304.562    
          IF (SF_BIO(8)) PMORT_NUT(II,J,K)=p_mort_n(I,K)                   ONT1F304.563    
          IF (SF_BIO(9)) ZMORT_NUT(II,J,K)=z_mort_n(I,K)                   ONT1F304.564    
          IF (SF_BIO(10)) PRESP_NUT(II,J,K)=p_resp_n(I,K)                  ONT1F304.565    
          IF (SF_BIO(11)) REMIN_NUT(II,J,K)=d_remin_n(I,K)                 ONT1F304.566    
          IF (SF_BIO(12)) NUT_LIMIT(II,J,K)=lim_nut(I,K)                   ONT1F304.567    
          IF (SF_BIO(13)) LIGHT_LIMIT(II,J,K)=lim_light(I,K)               ONT1F304.568    
          IF (SF_BIO(14)) TEMP_LIMIT(II,J,K)=lim_temp(I,K)                 ONT1F304.569    
          IF (SF_BIO(15)) DETRI_FLUX(II,J,K)=DDT(I,K)                      OJP0F404.290    
                                                                           OJP0F404.291    
        ENDDO                                                              ONT1F304.571    
      ENDDO                                                                ONT1F304.572    
C                                                                          ONT1F304.573    
                                                                           BIOLOGY.709    
C                                                                          BIOLOGY.710    
CL    Return from BIOLOGY                                                  BIOLOGY.711    
C                                                                          BIOLOGY.712    
*ENDIF                                                                     ORH1F305.440    
      RETURN                                                               BIOLOGY.713    
      END                                                                  BIOLOGY.714    
*ENDIF                                                                     BIOLOGY.715