Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/par_idtra.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/par_idtra.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/par_idtra.F90	(revision 5707)
@@ -0,0 +1,69 @@
+MODULE par_idtra
+   !!======================================================================
+   !!                        ***  par_idtra  ***
+   !! TOP :   set the IDEAL-TRACER parameters
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007)
+   !! $Id: par_idtra.F90 1253 2009-01-13 09:55:38Z cetlod $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+   USE par_pisces , ONLY : jp_pisces       !: number of tracers in PISCES
+   USE par_pisces , ONLY : jp_pisces_2d    !: number of 2D diag in PISCES
+   USE par_pisces , ONLY : jp_pisces_3d    !: number of 3D diag in PISCES
+   USE par_pisces , ONLY : jp_pisces_trd   !: number of biological diag in PISCES
+
+   USE par_medusa , ONLY : jp_medusa       !: number of tracers in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_2d    !: number of 2D diag in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_3d    !: number of 3D diag in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_trd   !: number of biological diag in MEDUSA
+
+
+   IMPLICIT NONE
+   PUBLIC
+
+   INTEGER, PUBLIC, PARAMETER ::   jp_lp      =  jp_pisces     + jp_medusa     !: cumulative number of passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_lp_2d   =  jp_pisces_2d  + jp_medusa_2d  !:
+   INTEGER, PUBLIC, PARAMETER ::   jp_lp_3d   =  jp_pisces_3d  + jp_medusa_3d  !:
+   INTEGER, PUBLIC, PARAMETER ::   jp_lp_trd  =  jp_pisces_trd + jp_medusa_trd !:
+
+#if defined key_idtra
+   !!---------------------------------------------------------------------
+   !!   'key_idtra'   :                                          Ideal tracers
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_idtra     = .TRUE.      !: IDEAL-TRACER flag
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra     =  1          !: number of passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra_2d  =  0          !: additional 2d output arrays ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra_3d  =  0          !: additional 3d output arrays ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra_trd =  0          !: number of sms trends for IDEAL-TRACER
+
+   ! assign an index in trc arrays for each IDEAL-TRACER prognostic variables
+   INTEGER, PUBLIC, PARAMETER ::   jpidtra       = jp_lp + 1   !: IDEAL-TRACER
+#else
+   !!---------------------------------------------------------------------
+   !!   Default     :                                       No IDEAL-TRACER tracers
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_idtra     = .FALSE.     !: IDEAL-TRACER flag
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra     =  0          !: No IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra_2d  =  0          !: No IDEAL-TRACER additional 2d output arrays
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra_3d  =  0          !: No IDEAL-TRACER additional 3d output arrays
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra_trd =  0          !: number of sms trends for IDEAL-TRACER
+#endif
+
+   ! Starting/ending IDEAL-TRACER do-loop indices (N.B. no IDEAL-TRACER : jp_idtra0 > jp_idtra1 the do-loop are never done)
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra0     = jp_lp + 1                !: First index of IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra1     = jp_lp + jp_idtra         !: Last  index of IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra0_2d  = jp_lp_2d  + 1            !: First index of IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra1_2d  = jp_lp_2d  + jp_idtra_2d  !: Last  index of IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra0_3d  = jp_lp_3d  + 1            !: First index of IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra1_3d  = jp_lp_3d  + jp_idtra_3d  !: Last  index of IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra0_trd = jp_lp_trd + 0            !: First index of IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra1_trd = jp_lp_trd + jp_idtra_trd !: Last  index of IDEAL-TRACER tracers
+
+   !!======================================================================
+END MODULE par_idtra
+
+
+
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcctl_idtra.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcctl_idtra.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcctl_idtra.F90	(revision 5707)
@@ -0,0 +1,105 @@
+MODULE trcctl_idtra
+   !!======================================================================
+   !!                         ***  trcctl.idtra.F90  ***
+   !! TOP :                Control of IDEAL-TRA chemical model
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !! History :   1.0  !  2005-10 (C. Ethe) assign a parameter to name individual tracers
+   !!----------------------------------------------------------------------
+
+#if defined key_idtra
+
+   USE oce_trc
+   USE trc
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_ctl_idtra      ! called by ???
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005)
+   !! $Id: trcctl_idtra.F90 1255 2009-01-13 10:20:17Z cetlod $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_ctl_idtra
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_ctl_idtra  ***
+      !!
+      !! ** Purpose :   control the cpp options, namelist and files
+      !!----------------------------------------------------------------------
+      INTEGER :: jl, jn
+
+      IF(lwp) THEN
+          WRITE(numout,*) ' IDEAL-TRA Model '
+          WRITE(numout,*) ' '
+      ENDIF
+
+      ! Check number of tracers
+      ! -----------------------
+      IF( jp_idtra > 5) THEN
+          IF(lwp) THEN
+              WRITE (numout,*) ' ===>>>> : w a r n i n g '
+              WRITE (numout,*) ' =======   ============= '
+              WRITE (numout,*)                             &
+              &   ' STOP, change jp_idtra to 1 in par_IDEAL-TRA module '
+          END IF
+          STOP 'TRC_CTL'
+      END IF
+
+      ! Check tracer names
+      ! ------------------
+      IF ( ctrcnm(jpidtra) /= 'Ideal-Tracer' ) THEN
+            ctrcnm(jpidtra) = 'Ideal-Tracer'
+            ctrcln(jpidtra) = 'Ideal-Tracer concentration'
+      ENDIF
+
+      IF(lwp) THEN
+         WRITE (numout,*) ' ===>>>> : w a r n i n g '
+         WRITE (numout,*) ' =======   ============= '
+         WRITE (numout,*) ' we force tracer names'
+         DO jl = 1, jp_idtra
+            jn = jp_idtra0 + jl - 1
+            WRITE(numout,*) ' tracer nb: ',jn,' name = ',ctrcnm(jn), ctrcln(jn)
+         END DO
+         WRITE(numout,*) ' '
+      ENDIF
+
+
+      ! Check tracer units
+      ! ------------------
+      DO jl = 1, jp_idtra
+         jn = jp_idtra0 + jl - 1
+        IF( ctrcun(jn) /= 'unit' ) THEN
+            ctrcun(jn) = 'unit'
+            IF(lwp) THEN
+               WRITE (numout,*) ' ===>>>> : w a r n i n g '
+               WRITE (numout,*) ' =======   ============= '
+               WRITE (numout,*) ' we force tracer unit'
+               WRITE(numout,*) ' tracer  ',ctrcnm(jn), 'UNIT= ',ctrcun(jn)
+               WRITE(numout,*) ' '
+            ENDIF
+         ENDIF
+      END DO
+      !
+   END SUBROUTINE trc_ctl_idtra
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Empty module :                                                No IDEAL-TRA
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ctl_idtra                      ! Dummy routine
+   END SUBROUTINE trc_ctl_idtra
+#endif
+
+   !!======================================================================
+END MODULE trcctl_idtra
+
+
+
+
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcini_idtra.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcini_idtra.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcini_idtra.F90	(revision 5707)
@@ -0,0 +1,95 @@
+MODULE trcini_idtra
+   !!======================================================================
+   !!                         ***  MODULE trcini_idtra  ***
+   !! TOP :   initialisation of the IDEAL-TRACER tracers
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) from trcini.idtra.h90
+   !!----------------------------------------------------------------------
+#if defined key_idtra
+   !!----------------------------------------------------------------------
+   !!   'key_idtra'                                               IDEAL-TRACER tracers
+   !!----------------------------------------------------------------------
+   !! trc_ini_idtra      : IDEAL-TRACER model initialisation
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! TOP variables
+   USE trcsms_idtra    ! IDEAL-TRACER sms trends
+   USE par_idtra       ! IDEAL-TRACER parameters
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp
+   USE iom
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_ini_idtra   ! called by trcini.F90 module
+
+   INTEGER  ::   inum                   ! unit number
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007)
+   !! $Id: trcini_idtra.F90 1581 2009-08-05 14:53:12Z smasson $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trc_ini_idtra
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_ini_idtra  ***
+      !!
+      !! ** Purpose :   initialization for idtra model
+      !!
+      !! ** Method  : - Read the namidtra namelist and check the parameter values
+      !!----------------------------------------------------------------------
+      INTEGER  ::    jn, jl 
+      !!----------------------------------------------------------------------
+
+
+      ! Initialization of trn in case of  no restart
+      !----------------------------------------------
+      IF( .NOT. ln_rsttr ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'Initialization de id-tracers ; No restart : '
+            WRITE(numout,*) '                             ; Init field equal 1 at surface - zero elsewhere'
+         ENDIF
+         DO jn = jp_idtra0, jp_idtra1
+             trn(:,:,:,jn) = 0.e0
+             trn(:,:,1,jn) = 1.0
+           IF(lwp) WRITE(numout,*) 'Idealise Tracer initialisation -- jn = ',jn
+         END DO
+      ENDIF
+
+
+      !   Ideal traceur do not need any atmospheric concentration.
+      ! We consider that sucface concentration is equal to 1,
+      ! that it is advectied within the water circulation,
+      ! and that it is regularly degraded as if it was a radiactive tracer (tricium for example)
+      ! But we can play with tha caracteristic time of
+      !--------------------------------------------------------------------
+
+
+
+      IF(lwp) WRITE(numout,*) 'Initialization of IDEAL-TRACER tracers done'
+      IF(lwp) WRITE(numout,*) ' '
+
+   END SUBROUTINE trc_ini_idtra
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                         No IDEAL-TRACER tracers
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ini_idtra             ! Empty routine
+
+
+   END SUBROUTINE trc_ini_idtra
+#endif
+
+   !!======================================================================
+END MODULE trcini_idtra
+                                                
+
+
+
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcnam_idtra.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcnam_idtra.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcnam_idtra.F90	(revision 5707)
@@ -0,0 +1,121 @@
+MODULE trcnam_idtra
+   !!======================================================================
+   !!                         ***  MODULE trcnam_idtra  ***
+   !! TOP :   initialisation of some run parameters for IDEAL-TRACER chemical model
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) from trcnam.idtra.h90
+   !!----------------------------------------------------------------------
+#if defined key_idtra
+   !!----------------------------------------------------------------------
+   !!   'key_idtra'                                               IDEAL-TRACER tracers
+   !!----------------------------------------------------------------------
+   !! trc_nam_idtra      : IDEAL-TRACER model initialisation
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! TOP variables
+   USE trcsms_idtra      ! IDEAL-TRACER specific variable
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_nam_idtra   ! called by trcnam.F90 module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007)
+   !! $Id: trcnam_idtra.F90 1581 2009-08-05 14:53:12Z smasson $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_nam_idtra
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_nam_idtra  ***
+      !!
+      !! ** Purpose :   Definition some run parameter for IDEAL-TRACER model
+      !!
+      !! ** Method  :   Read the namidtra namelist and check the parameter
+      !!       values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namidtra
+      !!----------------------------------------------------------------------
+      REAL(wp) ::   tmp_decay          !! Years ; half time decay of our idealize tracer
+      REAL(wp) ::   TDECyr, TDEC   
+      CHARACTER(LEN=32)   ::   clname
+      !! 
+      NAMELIST/namidtra/tmp_decay
+!! #if defined key_trc_diaadd
+!!      ! definition of additional diagnostic as a structure
+!!      INTEGER :: jl, jn
+!!
+!! #endif
+      !!
+
+!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+!! Jpalm -- 4-11-2014
+!! namelist for idealize tracer
+!! only thing in namelist is the chosen half time decay
+!! no atmospheric conditions, cause we do impose a surface concentration of 1,
+!! and no additionnal diagnostics, 
+!! because the only thing we are interested in is the water mass concentration on this tracer.
+!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+      IF(lwp) WRITE(numout,*)
+      clname = 'namelist_idtra'
+      IF(lwp) WRITE(numout,*) ' trc_nam_idtra: read IDEAL-TRACER namelist'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+      !!
+      !! Open the namelist file :
+      !!~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      CALL ctl_opn( numnatm, TRIM( clname ), 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+
+      !! Read the namelists :
+      !!~~~~~~~~~~~~~~~~~~~~~~~
+      !! First namelist of our idealize tracer :
+      !! read the decay 1/2 time of our tracer, to define in the namelist.
+      !! tmp_decay = 1y ; 10y ; 100y or 1000y depending of which water mass you want to track
+      !!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      READ(numnatm,namidtra)
+
+      IF(lwp) WRITE(numout,*) '   -  half time decay of our idealize tracer : ', tmp_decay
+
+      ! decroissance radioactive du traceur ideal
+      ! ---------------------------------------
+      ! TDECyr = 12.43/LOG(2.)             !! Tricium as example
+       TDECyr = tmp_decay/LOG(2.)          !! Idealise tracer -- with tmp_decay given in the idtracer namelist
+       TDEC = TDECyr*365.*24.*60.*60.      !! translate in second
+       FDEC = EXP( -rdt/TDEC )
+
+
+!! #if defined key_trc_diaadd  && ! defined key_iomput
+      !!
+      !!  -Here you can add tracers names to be read
+      !! in a namelist.
+      !!  -But this is not necessary with the iomput module
+      !! cause names are written in the Iodef file.
+      !!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+!! #endif
+
+   END SUBROUTINE trc_nam_idtra
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                                No IDEAL-TRACER
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_nam_idtra                      ! Empty routine
+   END  SUBROUTINE  trc_nam_idtra
+#endif
+
+   !!======================================================================
+END MODULE trcnam_idtra
+
+
+
+
+
+
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcsms_idtra.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcsms_idtra.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcsms_idtra.F90	(revision 5707)
@@ -0,0 +1,153 @@
+MODULE trcsms_idtra
+   !!======================================================================
+   !!                      ***  MODULE trcsms_idtra  ***
+   !! TOP : TRI main model
+   !!======================================================================
+   !! History :    -   !  1999-10  (JC. Dutay)  original code
+   !!             1.0  !  2004-03 (C. Ethe) free form + modularity
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  reorganisation
+   !!----------------------------------------------------------------------
+#if defined key_idtra
+   !!----------------------------------------------------------------------
+   !!   'key_idtra'                                               TRI tracers
+   !!----------------------------------------------------------------------
+   !!   trc_sms_idtra     :  compute and add TRI suface forcing to TRI trends
+   !!   trc_idtra_cst :  sets constants for TRI surface forcing computation
+   !!----------------------------------------------------------------------
+   USE oce_trc      ! Ocean variables
+   USE par_trc      ! TOP parameters
+   USE trc          ! TOP variables
+   USE trdtrc_oce
+   USE trdtrc
+   USE iom
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_sms_idtra       ! called in ???
+
+   INTEGER , PUBLIC    ::   nyear_res      ! restoring time constant (year)
+   INTEGER , PUBLIC    ::   numnatm
+
+   REAL(wp), PUBLIC    ::   FDEC
+   !                          ! coefficients for conversion
+   REAL(wp) ::  WTEMP
+
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007)
+   !! $Id: trcsms_idtra.F90 1459 2009-05-23 08:53:26Z cetlod $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_sms_idtra( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_sms_idtra  ***
+      !!
+      !! ** Purpose :   Compute the surface boundary contition on TRI 11
+      !!             passive tracer associated with air-mer fluxes and add it
+      !!             to the general trend of tracers equations.
+      !!
+      !! ** Method  : - get the atmospheric partial pressure - given in pico -
+      !!              - computation of solubility ( in 1.e-12 mol/l then in 1.e-9 mol/m3)
+      !!              - computation of transfert speed ( given in cm/hour ----> cm/s )
+      !!              - the input function is given by :
+      !!                speed * ( concentration at equilibrium - concentration at surface )
+      !!              - the input function is in pico-mol/m3/s and the
+      !!                TRI concentration in pico-mol/m3
+      !!               
+      !! *** For Idealized Tracers              
+      !!              - no need for any temporal references, 
+      !!              nor any atmospheric concentration, nor air -sea fluxes
+      !!              - Here we fixe surface concentration to 1.0 Tracer-Unit/m3
+      !!              - Then we add a decay (radioactive-like) to this tracer concentration 
+      !!              - the Half life deccay is chosen by the user, depending of the experiment. 
+      !!              
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt    ! ocean time-step index
+      !!
+      INTEGER ::   ji, jj, jn, jl, jk
+
+
+
+      !!----------------------------------------------------------------------
+      IF(lwp) WRITE(numout,*) '   - JPALM - verif :'
+      IF(lwp) WRITE(numout,*) '   ~~~~~~~~~~~~~~~~~'
+      IF(lwp) WRITE(numout,*) '   - idtra decay factor : ', FDEC
+
+
+         !
+DO jn = jp_idtra0, jp_idtra1
+
+        ! DO jj = 1, jpj
+        !    DO ji = 1, jpi
+               ! Surface concentrarion fixed to 1 (ideal tracer concentration unit)
+               trn(:,:,1,jn) = 1.
+               trb(:,:,1,jn) = 1.
+               !
+        !    ENDDO
+        ! ENDDO
+
+!
+!DECAY of OUR IDEALIZED TRACER
+! ---------------------------------------
+
+         DO  jk =1,jpk
+            DO jj=1,jpj
+              DO  ji =1,jpi
+               !  IF (trn(ji,jj,jk,jn) > 0.0) THEN
+                    WTEMP = trn(ji,jj,jk,jn) * (1. - FDEC )
+                    tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) - WTEMP/rdt
+               !  ENDIF 
+              ENDDO 
+            ENDDO
+         ENDDO
+
+ENDDO
+    !! jn loop
+!
+
+!!!!!! No added diagnostics to save here for idealize tracers...
+!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+!! #if defined key_trc_diaadd
+!!       ! Save diagnostics , just for TRI111
+!! # if ! defined key_iomput
+!!       trc2d(:,:,jp_idtra0_2d    ) = zpp_idtra(:,:)
+!! # else
+!! !           WRITE(NUMOUT,*) 'Iomput idtrasurf '
+!!       CALL iom_put( "TRISURF"  , zpp_idtra(:,:) )
+!! !      CALL iom_put( "TRISURF"  , xphem(:,:) )
+!! !           WRITE(NUMOUT,*) 'Iomputage '
+!!        CALL iom_put( "AGE"  , zage(:,:,:) )
+!! # endif
+!! #endif
+!!
+
+!!      IF( l_trdtrc ) THEN
+!!          DO jn = jp_idtra0, jp_idtra1
+!!            zidtradtra(:,:,:) = tra(:,:,:,jn)
+!!            CALL trd_mod_trc( zidtradtra, jn, jptrc_trd_sms, kt )   ! save trends
+!!          END DO
+!!      END IF
+
+   END SUBROUTINE trc_sms_idtra
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                         No TRI tracers
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_sms_idtra( kt )       ! Empty routine
+      WRITE(*,*) 'trc_sms_idtra: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_sms_idtra
+#endif
+
+   !!======================================================================
+END MODULE trcsms_idtra
+
+
+
+
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcwri_idtra.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcwri_idtra.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcwri_idtra.F90	(revision 5707)
@@ -0,0 +1,63 @@
+MODULE trcwri_idtra
+   !!======================================================================
+   !!                       *** MODULE trcwri ***
+   !!    IDEALIZED Tracer :   Output of IDEALIZED Tracer tracers
+   !!======================================================================
+   !! History :   1.0  !  2009-05 (C. Ethe)  Original code
+   !!             1.1  !  2013-05 (A. Yool)  converted for MEDUSA
+   !!----------------------------------------------------------------------
+#if defined key_top && defined key_iomput && defined key_idtra
+   !!----------------------------------------------------------------------
+   !!   'key_idtra'                                           IDEALIZED Tracer model
+   !!----------------------------------------------------------------------
+   !! trc_wri_idtra   :  outputs of concentration fields
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! passive tracers common variables
+   USE trcsms_idtra    ! IDEALIZE TRACER sms trends
+   USE iom             ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_wri_idtra
+
+CONTAINS
+
+   SUBROUTINE trc_wri_idtra
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_wri_trc  ***
+      !!
+      !! ** Purpose :   output passive tracers fields 
+      !!---------------------------------------------------------------------
+      CHARACTER (len=20)   :: cltra
+      INTEGER              :: jn
+      !!---------------------------------------------------------------------
+
+      ! write the tracer concentrations in the file
+      ! ---------------------------------------
+      DO jn = jp_idtra0, jp_idtra1
+         cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
+         CALL iom_put( cltra, trn(:,:,:,jn) )
+      END DO
+      !
+   END SUBROUTINE trc_wri_idtra
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+   PUBLIC trc_wri_idtra
+CONTAINS
+   SUBROUTINE trc_wri_idtra                     ! Empty routine  
+   END SUBROUTINE trc_wri_idtra
+#endif
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id: trcwri_idtra.F90 3160 2011-11-20 14:27:18Z cetlod $ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!======================================================================
+END MODULE trcwri_idtra
+
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/par_medusa.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/par_medusa.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/par_medusa.F90	(revision 5707)
@@ -0,0 +1,78 @@
+MODULE par_medusa
+   !!======================================================================
+   !!                        ***  par_medusa  ***
+   !! TOP :   set the MEDUSA parameters
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!              -   !  2011-04  (A. Yool) updated for ROAM project
+   !!		   -   !  2013-03  (A. Yool) updated for v3.5 NEMO
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id: par_my_trc.F90 1253 2009-01-13 09:55:38Z cetlod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+   IMPLICIT NONE
+
+#if defined key_medusa
+   !!---------------------------------------------------------------------
+   !!   'key_medusa'                     user defined tracers (MEDUSA)
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_medusa     = .TRUE.   !: PTS flag 
+# if defined key_roam
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa     =  15      !: number of PTS tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_2d  =  225     !: additional 2d output arrays (used if ln_diatrc=T)
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_3d  =  5       !: additional 3d output arrays (used if ln_diatrc=T)
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_trd =  0       !: number of sms trends for MEDUSA
+# else
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa     =  11      !: number of PTS tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_2d  =  90      !: additional 2d output arrays (used if ln_diatrc=T)
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_3d  =  4       !: additional 3d output arrays (used if ln_diatrc=T)
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_trd =  0       !: number of sms trends for MEDUSA
+# endif
+
+   ! assign an index in trc arrays for each PTS prognostic variables
+   INTEGER, PUBLIC, PARAMETER ::   jpchn  =  1              !: non-diatom chlorophyll concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpchd  =  2              !: diatom     chlorophyll concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpphn  =  3              !: non-diatom concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpphd  =  4              !: diatom     concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpzmi  =  5              !: microzooplankton concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpzme  =  6              !: mesozooplankton  concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpdin  =  7              !: dissolved inorganic nitrogen concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpsil  =  8              !: silicic acid concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpfer  =  9              !: total iron concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpdet  = 10              !: slow-sinking detritus concentration
+   INTEGER, PUBLIC, PARAMETER ::   jppds  = 11              !: diatom silicon concentration
+# if defined key_roam
+   INTEGER, PUBLIC, PARAMETER ::   jpdtc  = 12              !: slow-sinking detritus carbon concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpdic  = 13              !: dissolved inorganic carbon concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpalk  = 14              !: alkalinity
+   INTEGER, PUBLIC, PARAMETER ::   jpoxy  = 15              !: dissolved oxygen concentration
+# endif
+
+#else
+   !!---------------------------------------------------------------------
+   !!   Default                           No user defined tracers (MEDUSA)
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_medusa     = .FALSE.  !: MEDUSA flag 
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa     =  0       !: No MEDUSA tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_2d  =  0       !: No MEDUSA additional 2d output arrays 
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_3d  =  0       !: No MEDUSA additional 3d output arrays 
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_trd =  0       !: number of sms trends for MEDUSA
+#endif
+
+   ! Starting/ending PISCES do-loop indices (N.B. no PISCES : jpl_pcs < jpf_pcs the do-loop are never done)
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa0     = 1              !: First index of MEDUSA passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa1     = jp_medusa      !: Last  index of MEDUSA passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa0_2d  = 1              !: First index of MEDUSA passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa1_2d  = jp_medusa_2d   !: Last  index of MEDUSA passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa0_3d  = 1              !: First index of MEDUSA passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa1_3d  = jp_medusa_3d   !: Last  index of MEDUSA passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa0_trd = 1              !: First index of MEDUSA passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa1_trd = jp_medusa_trd  !: Last  index of MEDUSA passive tracers
+
+   !!======================================================================
+END MODULE par_medusa
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/sms_medusa.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/sms_medusa.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/sms_medusa.F90	(revision 5707)
@@ -0,0 +1,472 @@
+MODULE sms_medusa 
+   !!----------------------------------------------------------------------
+   !!                     ***  sms_medusa.F90  ***  
+   !! TOP :   MEDUSA  Source Minus Sink variables
+   !!----------------------------------------------------------------------
+   !! History :    -   !  1999-09 (M. Levy)  original code
+   !!              -   !  2000-12 (O. Aumont, E. Kestenare)  add sediment 
+   !!             1.0  !  2005-10 (C. Ethe) F90
+   !!             1.0  !  2005-03  (A-S Kremeur) add fphylab, fzoolab, fdetlab, fdbod
+   !!              -   !  2005-06  (A-S Kremeur) add sedpocb, sedpocn, sedpoca
+   !!             2.0  !  2007-04  (C. Deltel, G. Madec)  Free form and modules
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!              -   !  2011-04  (A. Yool) updated for ROAM project
+   !!----------------------------------------------------------------------
+
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'                                         MEDUSA model
+   !!----------------------------------------------------------------------
+   USE par_oce
+   USE par_trc
+
+   IMPLICIT NONE
+   PUBLIC
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id: sms_medusa.F90 1152 2008-06-26 14:11:13Z rblod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+   INTEGER ::   numnatp_ref = -1           !! Logical units for namelist medusa
+   INTEGER ::   numnatp_cfg = -1           !! Logical units for namelist medusa
+   INTEGER ::   numonp      = -1           !! Logical unit for namelist medusa output
+
+!!----------------------------------------------------------------------
+!! Biological parameters
+!!----------------------------------------------------------------------
+!!
+!! Primary production and chl related quantities
+   REAL(wp) ::  xxi       !:  conversion factor from gC to mmolN 
+   REAL(wp) ::  xaln      !:  Chl-a specific initial slope of P-I curve for non-diatoms 
+   REAL(wp) ::  xald      !:  Chl-a specific initial slope of P-I curve for diatoms
+   INTEGER  ::  jphy      !:  phytoplankton T-dependent growth switch
+   REAL(wp) ::  xvpn      !:  maximum growth rate for non-diatoms
+   REAL(wp) ::  xvpd      !:  maximum growth rate for diatoms
+   REAL(wp) ::  xthetam   !:  maximum Chl to C ratio for non-diatoms      
+   REAL(wp) ::  xthetamd  !:  maximum Chl to C ratio for diatoms    
+!!
+!! Diatom silicon parameters
+   REAL(wp) ::  xsin0     !:  minimum diatom Si:N ratio
+   REAL(wp) ::  xnsi0     !:  minimum diatom N:Si ratio
+   REAL(wp) ::  xuif      !:  hypothetical growth ratio at infinite Si:N ratio
+!!
+!! Nutrient limitation
+   INTEGER  ::  jliebig   !:  Liebig nutrient uptake switch
+   REAL(wp) ::  xnln      !:  half-sat constant for DIN uptake by non-diatoms 
+   REAL(wp) ::  xnld      !:  half-sat constant for DIN uptake by diatoms 
+   REAL(wp) ::  xsld      !:  half-sat constant for Si uptake by diatoms 
+   REAL(wp) ::  xfln      !:  half-sat constant for Fe uptake by non-diatoms 
+   REAL(wp) ::  xfld      !:  half-sat constant for Fe uptake by diatoms  
+!!
+!! Grazing
+   REAL(wp) ::  xgmi      !:  microzoo maximum growth rate 
+   REAL(wp) ::  xgme      !:  mesozoo maximum growth rate 
+   REAL(wp) ::  xkmi      !:  microzoo grazing half-sat parameter
+   REAL(wp) ::  xkme      !:  mesozoo grazing half-sat parameter
+   REAL(wp) ::  xphi      !:  micro/mesozoo grazing inefficiency
+   REAL(wp) ::  xbetan    !:  micro/mesozoo N assimilation efficiency
+   REAL(wp) ::  xbetac    !:  micro/mesozoo C assimilation efficiency
+   REAL(wp) ::  xkc       !:  micro/mesozoo net C growth efficiency
+   REAL(wp) ::  xpmipn    !:  grazing preference of microzoo for non-diatoms
+   REAL(wp) ::  xpmid     !:  grazing preference of microzoo for diatoms
+   REAL(wp) ::  xpmepn    !:  grazing preference of mesozoo for non-diatoms 
+   REAL(wp) ::  xpmepd    !:  grazing preference of mesozoo for diatoms
+   REAL(wp) ::  xpmezmi   !:  grazing preference of mesozoo for microzoo
+   REAL(wp) ::  xpmed     !:  grazing preference of mesozoo for detritus
+!!
+!! Metabolic losses
+   REAL(wp) ::  xmetapn   !:  non-diatom metabolic loss rate
+   REAL(wp) ::  xmetapd   !:  diatom     metabolic loss rate
+   REAL(wp) ::  xmetazmi  !:  microzoo   metabolic loss rate
+   REAL(wp) ::  xmetazme  !:  mesozoo    metabolic loss rate
+!!
+!! Mortality losses
+   INTEGER  ::  jmpn      !:  non-diatom mortality functional form
+   REAL(wp) ::  xmpn      !:  non-diatom mortality rate
+   REAL(wp) ::  xkphn     !:  non-diatom mortality half-sat constant
+   INTEGER  ::  jmpd      !:  diatom     mortality functional form
+   REAL(wp) ::  xmpd      !:  diatom     mortality rate
+   REAL(wp) ::  xkphd     !:  diatom     mortality half-sat constant
+   INTEGER  ::  jmzmi     !:  microzoo   mortality functional form
+   REAL(wp) ::  xmzmi     !:  microzoo   mortality rate
+   REAL(wp) ::  xkzmi     !:  microzoo   mortality half-sat constant
+   INTEGER  ::  jmzme     !:  mesozoo    mortality functional form
+   REAL(wp) ::  xmzme     !:  mesozoo    mortality rate
+   REAL(wp) ::  xkzme     !:  mesozoo    mortality half-sat constant
+!!
+!! Remineralisation
+   INTEGER  ::  jmd       !:  detritus T-dependent remineralisation switch
+   INTEGER  ::  jsfd      !:  accelerate seafloor detritus remin. switch
+   REAL(wp) ::  xmd       !:  detrital nitrogen remineralisation rate 
+   REAL(wp) ::  xmdc      !:  detrital carbon remineralisation rate 
+!!
+!! Stochiometric ratios
+   REAL(wp) ::  xthetapn  !:  non-diatom C:N ratio
+   REAL(wp) ::  xthetapd  !:  diatom C:N ratio
+   REAL(wp) ::  xthetazmi !:  microzoo C:N ratio
+   REAL(wp) ::  xthetazme !:  mesozoo C:N ratio
+   REAL(wp) ::  xthetad   !:  detritus C:N ratio
+   REAL(wp) ::  xrfn      !:  phytoplankton Fe:N ratio
+   REAL(wp) ::  xrsn      !:  diatom Si:N ratio (NOT USED HERE; RETAINED FOR LOBSTER)
+!!
+!! Iron parameters
+   INTEGER  ::  jiron     !:  iron scavenging submodel switch
+   REAL(wp) ::  xfe_mass  !:  iron atomic mass
+   REAL(wp) ::  xfe_sol   !:  aeolian iron solubility
+   REAL(wp) ::  xfe_sed   !:  sediment iron input
+   REAL(wp) ::  xLgT      !:  total ligand concentration (umol/m3)
+   REAL(wp) ::  xk_FeL    !:  dissociation constant for (Fe + L)
+   REAL(wp) ::  xk_sc_Fe  !:  scavenging rate of "free" iron
+!!
+!! Gravitational sinking      
+   REAL(wp) ::  vsed      !:  detritus gravitational sinking rate 
+   REAL(wp) ::  xhr       !:  coefficient for Martin et al. (1987) remineralisation
+!!
+!! Fast-sinking detritus parameters
+   INTEGER  ::  jexport   !:  fast detritus remineralisation switch
+   INTEGER  ::  jfdfate   !:  fate of fast detritus at seafloor switch
+   INTEGER  ::  jrratio   !:  rain ratio switch
+   INTEGER  ::  jocalccd  !:  CCD switch
+   REAL(wp) ::  xridg_r0  !:  Ridgwell rain ratio coefficient
+   REAL(wp) ::  xfdfrac1  !:  fast-sinking fraction of diatom nat. mort. losses
+   REAL(wp) ::  xfdfrac2  !:  fast-sinking fraction of mesozooplankton mort. losses
+   REAL(wp) ::  xfdfrac3  !:  fast-sinking fraction of diatom silicon grazing losses
+   REAL(wp) ::  xcaco3a   !:  polar (high latitude) CaCO3 fraction
+   REAL(wp) ::  xcaco3b   !:  equatorial (low latitude) CaCO3 fraction
+   REAL(wp) ::  xmassc    !:  organic C mass:mole ratio, C106 H175 O40 N16 P1
+   REAL(wp) ::  xmassca   !:  calcium carbonate mass:mole ratio, CaCO3
+   REAL(wp) ::  xmasssi   !:  biogenic silicon mass:mole ratio, (H2SiO3)n
+   REAL(wp) ::  xprotca   !:  calcium carbonate protection ratio
+   REAL(wp) ::  xprotsi   !:  biogenic silicon protection ratio
+   REAL(wp) ::  xfastc    !:  organic C remineralisation length scale
+   REAL(wp) ::  xfastca   !:  calcium carbonate dissolution length scale
+   REAL(wp) ::  xfastsi   !:  biogenic silicon dissolution length scale
+!!
+!! Benthos parameters
+   INTEGER  ::  jorgben   !:  does   organic detritus go to the benthos?
+   INTEGER  ::  jinorgben !:  does inorganic detritus go to the benthos?
+!!
+   REAL(wp) ::  xsedn     !:  organic   nitrogen sediment remineralisation rate 
+   REAL(wp) ::  xsedfe    !:  organic   iron     sediment remineralisation rate 
+   REAL(wp) ::  xsedsi    !:  inorganic silicon  sediment dissolution      rate 
+   REAL(wp) ::  xsedc     !:  organic   carbon   sediment remineralisation rate 
+   REAL(wp) ::  xsedca    !:  inorganic carbon   sediment dissolution      rate 
+   REAL(wp) ::  xburial   !:  burial rate of seafloor detritus
+!!
+!! River parameters
+   INTEGER  ::  jriver_n  !:  riverine nitrogen?   0 = no, 1 = conc, 2 = flux
+   INTEGER  ::  jriver_si !:  riverine silicon?    0 = no, 1 = conc, 2 = flux
+   INTEGER  ::  jriver_c  !:  riverine carbon?     0 = no, 1 = conc, 2 = flux
+   INTEGER  ::  jriver_alk!:  riverine alkalinity? 0 = no, 1 = conc, 2 = flux
+   INTEGER  ::  jriver_dep!:  depth river input added to?  1 = surface, >1 possible
+!!
+!! Miscellaneous
+   REAL(wp) ::  xsdiss    !:  diatom frustule dissolution rate
+!!
+!! Additional parameters
+   INTEGER  ::  jpkb      !:  vertical layer for diagnostic of the vertical flux 
+!!
+!! UKESM diagnostics
+   INTEGER  ::  jdms      !:  include DMS diagnostics ? Jpalm (27-08-2014) 
+!!
+!!
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   remdmp   !: depth dependent damping coefficient of passive tracers 
+!!
+!! AXY (27/07/10): add in indices for depth horizons (for sinking flux
+!!                 and seafloor iron inputs)
+   INTEGER  ::    i0100, i0150, i0200, i0500, i1000, i1100
+#if defined key_roam
+!!
+!! ROAM carbon, alkalinity and oxygen cycle parameters
+   REAL(wp) ::  xthetaphy    !:  oxygen evolution/consumption by phytoplankton 
+   REAL(wp) ::  xthetazoo    !:  oxygen consumption by zooplankton 
+   REAL(wp) ::  xthetanit    !:  oxygen consumption by nitrogen remineralisation
+   REAL(wp) ::  xthetarem    !:  oxygen consumption by carbon remineralisation
+   REAL(wp) ::  xo2min       !:  oxygen minimum concentration
+!! 
+!! 3D fields of carbonate system parameters
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: f3_pH       !: 3D pH
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: f3_h2co3    !: 3D carbonic acid
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: f3_hco3     !: 3D bicarbonate
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: f3_co3      !: 3D carbonate
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: f3_omcal    !: 3D omega calcite
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: f3_omarg    !: 3D omega aragonite
+!! 
+!! 2D fields of calcium carbonate compensation depth
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: f2_ccd_cal  !: 2D calcite CCD depth
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: f2_ccd_arg  !: 2D aragonite CCD depth
+!!
+!! 2D fields of organic and inorganic material sedimented on the seafloor
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_sed_n    !: 2D organic nitrogen   (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_sed_n    !: 2D organic nitrogen   (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_sed_n    !: 2D organic nitrogen   (after)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_sed_fe   !: 2D organic iron       (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_sed_fe   !: 2D organic iron       (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_sed_fe   !: 2D organic iron       (after)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_sed_si   !: 2D inorganic silicon  (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_sed_si   !: 2D inorganic silicon  (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_sed_si   !: 2D inorganic silicon  (after)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_sed_c    !: 2D organic carbon     (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_sed_c    !: 2D organic carbon     (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_sed_c    !: 2D organic carbon     (after)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_sed_ca   !: 2D inorganic carbon   (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_sed_ca   !: 2D inorganic carbon   (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_sed_ca   !: 2D inorganic carbon   (after)
+#endif
+
+!!----------------------------------------------------------------------
+!! CCD parameter
+!!----------------------------------------------------------------------
+!!
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ocal_ccd  !: CCD depth
+
+!!----------------------------------------------------------------------
+!! Dust parameters
+!!----------------------------------------------------------------------
+!!
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   dust      !: dust parameter 1
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dustmo    !: dust parameter 2
+
+!!----------------------------------------------------------------------
+!! River parameters
+!!----------------------------------------------------------------------
+!!
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   riv_n      !: riverine N
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   riv_si     !: riverine Si
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   riv_c      !: riverine C
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   riv_alk    !: riverine alkalinity
+   !! AXY (19/07/12): add this to permit river fluxes to be added below top box
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   friver_dep !: where river fluxes added
+
+#if defined key_roam
+!!----------------------------------------------------------------------
+!! Atmospheric pCO2 data (1859 to 2100 inclusive)
+!!----------------------------------------------------------------------
+!!
+   REAL(wp), DIMENSION(242)         ::   hist_pco2 !: pCO2
+
+# if defined key_rcp26
+      !! UKMO, run AJKKH + KAAEC, RCP 2.6, pCO2 time evolution
+      DATA hist_pco2 / 286.0230, 286.1730, 286.3230, 286.4480, 286.5730, &
+      & 286.7230, 286.8480, 286.9480, 287.0480, 287.1730, &
+      & 287.3230, 287.4730, 287.6480, 287.8480, 288.0730, &
+      & 288.3480, 288.6480, 288.9730, 289.3470, 289.7470, &
+      & 290.1730, 290.6470, 291.1470, 291.6220, 292.0720, &
+      & 292.5220, 292.9220, 293.2470, 293.5220, 293.7470, &
+      & 293.9470, 294.1220, 294.2720, 294.4220, 294.5470, &
+      & 294.6470, 294.7470, 294.8470, 294.9710, 295.1710, &
+      & 295.4460, 295.7470, 296.0720, 296.4210, 296.7710, &
+      & 297.1460, 297.5710, 298.0210, 298.4460, 298.8460, &
+      & 299.2460, 299.6450, 300.0210, 300.3710, 300.7200, &
+      & 301.0450, 301.3460, 301.6710, 302.0200, 302.3450, &
+      & 302.6450, 302.9700, 303.3450, 303.7200, 304.0700, &
+      & 304.4700, 304.9200, 305.3440, 305.7700, 306.2450, &
+      & 306.7190, 307.1700, 307.6440, 308.1190, 308.5440, &
+      & 308.9440, 309.3440, 309.6940, 309.9440, 310.1190, &
+      & 310.2440, 310.3190, 310.3190, 310.2440, 310.1440, &
+      & 310.0690, 310.0440, 310.0690, 310.1440, 310.2690, &
+      & 310.4440, 310.6940, 311.0430, 311.4440, 311.8690, &
+      & 312.3680, 312.9430, 313.5430, 314.1680, 314.7900, &
+      & 315.4430, 316.2150, 317.0170, 317.7370, 318.3400, &
+      & 318.8680, 319.5900, 320.5890, 321.5470, 322.5770, &
+      & 323.8440, 324.9260, 325.7960, 327.0810, 328.6180, &
+      & 329.6830, 330.5250, 331.6880, 333.2120, 334.7870, &
+      & 336.4640, 338.2990, 339.6660, 340.7310, 342.1360, &
+      & 343.7200, 345.2200, 346.7350, 348.5820, 350.6740, &
+      & 352.4230, 353.7910, 354.9530, 355.8210, 356.7130, &
+      & 358.0630, 359.7720, 361.3970, 363.0900, 365.2560, &
+      & 367.2810, 368.7980, 370.4000, 372.4550, 374.6920, &
+      & 376.7440, 378.7440, 380.7580, 382.7080, 384.7300, &
+      & 386.9310, 389.2150, 391.4910, 393.7710, 396.0460, &
+      & 398.3240, 400.6080, 402.8950, 405.1780, 407.4550, &
+      & 409.7260, 411.9930, 414.2500, 416.4410, 418.5280, &
+      & 420.5250, 422.4390, 424.2720, 426.0200, 427.6750, &
+      & 429.2360, 430.7050, 432.0850, 433.3580, 434.5140, &
+      & 435.5740, 436.5490, 437.4420, 438.2550, 438.9810, &
+      & 439.6110, 440.1430, 440.5770, 440.9450, 441.2660, &
+      & 441.5410, 441.7840, 442.0050, 442.2040, 442.3780, &
+      & 442.5210, 442.6200, 442.6720, 442.6810, 442.6540, &
+      & 442.5830, 442.4670, 442.3270, 442.1680, 441.9960, &
+      & 441.8060, 441.5930, 441.3440, 441.0540, 440.7230, &
+      & 440.3510, 439.9300, 439.4650, 438.9730, 438.4630, &
+      & 437.9400, 437.4020, 436.8400, 436.2640, 435.6850, &
+      & 435.1030, 434.5160, 433.9170, 433.3060, 432.7010, &
+      & 432.1110, 431.5380, 430.9810, 430.4320, 429.8860, &
+      & 429.3370, 428.7810, 428.2220, 427.6490, 427.0660, &
+      & 426.4890, 425.9270, 425.3840, 424.8610, 424.3540, &
+      & 423.8540, 423.3540, 422.8530, 422.3510, 421.8410, &
+      & 421.3250, 420.8190 /
+# else
+      !! UKMO, run AJKKH + KAAEF, RCP 8.5, pCO2 time evolution
+      DATA hist_pco2 / 286.0230, 286.1730, 286.3230, 286.4480, 286.5730, &
+      & 286.7230, 286.8480, 286.9480, 287.0480, 287.1730, &
+      & 287.3230, 287.4730, 287.6480, 287.8480, 288.0730, &
+      & 288.3480, 288.6480, 288.9730, 289.3470, 289.7470, &
+      & 290.1730, 290.6470, 291.1470, 291.6220, 292.0720, &
+      & 292.5220, 292.9220, 293.2470, 293.5220, 293.7470, &
+      & 293.9470, 294.1220, 294.2720, 294.4220, 294.5470, &
+      & 294.6470, 294.7470, 294.8470, 294.9710, 295.1710, &
+      & 295.4460, 295.7470, 296.0720, 296.4210, 296.7710, &
+      & 297.1460, 297.5710, 298.0210, 298.4460, 298.8460, &
+      & 299.2460, 299.6450, 300.0210, 300.3710, 300.7200, &
+      & 301.0450, 301.3460, 301.6710, 302.0200, 302.3450, &
+      & 302.6450, 302.9700, 303.3450, 303.7200, 304.0700, &
+      & 304.4700, 304.9200, 305.3440, 305.7700, 306.2450, &
+      & 306.7190, 307.1700, 307.6440, 308.1190, 308.5440, &
+      & 308.9440, 309.3440, 309.6940, 309.9440, 310.1190, &
+      & 310.2440, 310.3190, 310.3190, 310.2440, 310.1440, &
+      & 310.0690, 310.0440, 310.0690, 310.1440, 310.2690, &
+      & 310.4440, 310.6940, 311.0430, 311.4440, 311.8690, &
+      & 312.3680, 312.9430, 313.5430, 314.1680, 314.7900, &
+      & 315.4430, 316.2150, 317.0170, 317.7370, 318.3400, &
+      & 318.8680, 319.5900, 320.5890, 321.5470, 322.5770, &
+      & 323.8440, 324.9260, 325.7960, 327.0810, 328.6180, &
+      & 329.6830, 330.5250, 331.6880, 333.2120, 334.7870, &
+      & 336.4640, 338.2990, 339.6660, 340.7310, 342.1360, &
+      & 343.7200, 345.2200, 346.7350, 348.5820, 350.6740, &
+      & 352.4230, 353.7910, 354.9530, 355.8210, 356.7130, &
+      & 358.0630, 359.7720, 361.3970, 363.0900, 365.2560, &
+      & 367.2810, 368.7980, 370.4000, 372.4550, 374.6920, &
+      & 376.7440, 378.7440, 380.7580, 382.7080, 384.7300, &
+      & 386.9420, 389.2540, 391.5670, 393.9370, 396.3920, &
+      & 398.9320, 401.5550, 404.2550, 407.0220, 409.8530, &
+      & 412.7470, 415.7050, 418.7210, 421.7880, 424.9180, &
+      & 428.1200, 431.3970, 434.7470, 438.1650, 441.6410, &
+      & 445.1700, 448.7530, 452.3920, 456.0950, 459.8810, &
+      & 463.7680, 467.7660, 471.8750, 476.0960, 480.4210, &
+      & 484.8390, 489.3470, 493.9430, 498.6400, 503.4380, &
+      & 508.3410, 513.3630, 518.5160, 523.8050, 529.2290, &
+      & 534.7780, 540.4450, 546.2230, 552.1120, 558.1110, &
+      & 564.2110, 570.4130, 576.7390, 583.1990, 589.7980, &
+      & 596.5390, 603.4110, 610.4060, 617.4940, 624.6500, &
+      & 631.8800, 639.1750, 646.5360, 653.9800, 661.5230, &
+      & 669.1840, 676.9570, 684.8290, 692.7790, 700.7690, &
+      & 708.8050, 716.8870, 725.0020, 733.1770, 741.3900, &
+      & 749.6700, 758.0480, 766.5050, 775.0350, 783.6110, &
+      & 792.2200, 800.8740, 809.5680, 818.2760, 827.0090, &
+      & 835.8020, 844.6550, 853.5730, 862.5690, 871.6190, &
+      & 880.7020, 889.8240, 898.9590, 908.1270, 917.3080, &
+      & 926.4960, 935.7040 /
+# endif
+#endif
+
+!!----------------------------------------------------------------------
+!! Optical parameters
+!!----------------------------------------------------------------------
+!!
+   REAL(wp) ::   xkr0       !: water coefficient absorption in red      (NAMELIST)
+   REAL(wp) ::   xkg0       !: water coefficient absorption in green    (NAMELIST)
+   REAL(wp) ::   xkrp       !: pigment coefficient absorption in red    (NAMELIST)
+   REAL(wp) ::   xkgp       !: pigment coefficient absorption in green  (NAMELIST)
+   REAL(wp) ::   xlr        !: exposant for pigment absorption in red   (NAMELIST)
+   REAL(wp) ::   xlg        !: exposant for pigment absorption in green (NAMELIST)
+   REAL(wp) ::   rpig       !: chla/chla+phea ratio                     (NAMELIST)
+                                                        
+   INTEGER , ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   neln    !: number of levels in the euphotic layer
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   xze     !: euphotic layer depth
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   xpar    !: par (photosynthetic available radiation)
+
+!!----------------------------------------------------------------------
+!! Sediment parameters                               
+!! 
+!! AXY (16/01/12): these parameters were originally part of the pre-
+!!                 cursor model on which MEDUSA's code was grounded;
+!!                 they do not relate to the sediment/benthos submodel
+!!                 added as part of the ROAM project; they have only
+!!                 been retained because they are distributed through
+!!                 MEDUSA and require a proper clean-up to purge
+!!----------------------------------------------------------------------
+!!
+   REAL(wp) ::   sedlam       !: time coefficient of POC remineralization in sediments
+   REAL(wp) ::   sedlostpoc   !: ???
+   REAL(wp) ::   areacot      !: ???
+                                                        
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: dminl       !: fraction of sinking POC released in sediments
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: dmin3       !: fraction of sinking POC released at each level
+                                                        
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: sedpocb     !: mass of POC in sediments
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: sedpocn     !: mass of POC in sediments
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: sedpoca     !: mass of POC in sediments
+                                                        
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: fbodf       !: rapid sinking particles
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: fbods       !: rapid sinking particles
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: fbodn       !: rapid sinking particles
+                                                        
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: ffln        !: 
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: fflf        !: 
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: ffls        !: 
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: cmask       !: ???
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id: sms_medusa.F90 3780 2013-02-08 11:13:47Z cetlod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION sms_medusa_alloc()
+      !!----------------------------------------------------------------------
+      !!        *** ROUTINE sms_medusa_alloc ***
+      !!----------------------------------------------------------------------
+      USE lib_mpp , ONLY: ctl_warn
+      INTEGER ::   ierr(6)        ! Local variables
+      !!----------------------------------------------------------------------
+      ierr(:) = 0
+      !
+#if defined key_medusa
+      !* depth-dependent damping coefficient
+      ALLOCATE( remdmp(jpk,jp_medusa),                           STAT=ierr(1) )
+# if defined key_roam
+      !* 2D and 3D fields of carbonate system parameters
+      ALLOCATE( f2_ccd_cal(jpi,jpj)  , f2_ccd_arg(jpi,jpj)  ,       &
+         &      f3_pH(jpi,jpj,jpk)   , f3_h2co3(jpi,jpj,jpk),       &
+         &      f3_hco3(jpi,jpj,jpk) , f3_co3(jpi,jpj,jpk)  ,       &
+         &      f3_omcal(jpi,jpj,jpk), f3_omarg(jpi,jpj,jpk),    STAT=ierr(2) )
+      !* 2D fields of organic and inorganic material sedimented on the seafloor
+      ALLOCATE( zb_sed_n(jpi,jpj)    , zn_sed_n(jpi,jpj)    ,       &
+         &      za_sed_n(jpi,jpj)    ,                              &
+         &      zb_sed_fe(jpi,jpj)   , zn_sed_fe(jpi,jpj)   ,       &
+         &      za_sed_fe(jpi,jpj)   ,                              &
+         &      zb_sed_si(jpi,jpj)   , zn_sed_si(jpi,jpj)   ,       &
+         &      za_sed_si(jpi,jpj)   ,                              &
+         &      zb_sed_c(jpi,jpj)    , zn_sed_c(jpi,jpj)    ,       &
+         &      za_sed_c(jpi,jpj)    ,                              &
+         &      zb_sed_ca(jpi,jpj)   , zn_sed_ca(jpi,jpj)   ,       &
+         &      za_sed_ca(jpi,jpj)   ,                           STAT=ierr(3) )
+# endif
+      !* 2D fields of miscellaneous parameters
+      ALLOCATE( ocal_ccd(jpi,jpj)    , dust(jpi,jpj)        ,       &
+         &      dustmo(jpi,jpj,2)    , riv_n(jpi,jpj)       ,       &
+         &      riv_si(jpi,jpj)      , riv_c(jpi,jpj)       ,       &
+         &      riv_alk(jpi,jpj)     , friver_dep(jpk,jpk)  ,    STAT=ierr(4) )
+      !* 2D and 3D fields of light parameters
+      ALLOCATE( neln(jpi,jpj)        , xze(jpi,jpj)         ,       &
+         &      xpar(jpi,jpj,jpk)    ,                           STAT=ierr(5) )
+      !* 2D and 3D fields of sediment-associated parameters
+      ALLOCATE( dminl(jpi,jpj)       , dmin3(jpi,jpj,jpk)   ,       &
+         &      sedpocb(jpi,jpj)     , sedpocn(jpi,jpj)     ,       &
+         &      sedpoca(jpi,jpj)     , fbodn(jpi,jpj)       ,       &
+         &      fbodf(jpi,jpj)       , fbods(jpi,jpj)       ,       &
+         &      ffln(jpi,jpj,jpk)    , fflf(jpi,jpj,jpk)    ,       &
+         &      ffls(jpi,jpj,jpk)    , cmask(jpi,jpj)       ,    STAT=ierr(6) ) 
+#endif
+      !
+      sms_medusa_alloc = MAXVAL( ierr )
+      !
+      IF( sms_medusa_alloc /= 0 )   CALL ctl_warn('sms_medusa_alloc: failed to allocate arrays')
+      !
+   END FUNCTION sms_medusa_alloc
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Empty module :                                     NO MEDUSA model 
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE sms_medusa
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90	(revision 5707)
@@ -0,0 +1,3600 @@
+MODULE trcbio_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcbio  ***
+   !! TOP :   MEDUSA
+   !!======================================================================
+   !! History :
+   !!  -   !  1999-07  (M. Levy)              original code
+   !!  -   !  2000-12  (E. Kestenare)         assign parameters to name individual tracers
+   !!  -   !  2001-03  (M. Levy)              LNO3 + dia2d 
+   !! 2.0  !  2007-12  (C. Deltel, G. Madec)  F90
+   !!  -   !  2008-08  (K. Popova)            adaptation for MEDUSA
+   !!  -   !  2008-11  (A. Yool)              continuing adaptation for MEDUSA
+   !!  -   !  2010-03  (A. Yool)              updated for branch inclusion
+   !!  -   !  2011-08  (A. Yool)              updated for ROAM (see below)
+   !!  -   !  2013-03  (A. Yool)              updated for iMARNET
+   !!  -   !  2013-05  (A. Yool)              updated for v3.5
+   !!  -   !  2014-08  (A. Yool, J. Palm)     Add DMS module for UKESM1 model
+   !!----------------------------------------------------------------------
+   !!
+#if defined key_roam
+   !!----------------------------------------------------------------------
+   !! Updates for the ROAM project include:
+   !!   - addition of DIC, alkalinity, detrital carbon and oxygen tracers
+   !!   - addition of air-sea fluxes of CO2 and oxygen
+   !!   - periodic (monthly) calculation of full 3D carbonate chemistry 
+   !!   - detrital C:N ratio now free to evolve dynamically
+   !!   - benthic storage pools
+   !! 
+   !! Opportunity also taken to add functionality:
+   !!   - switch for Liebig Law (= most-limiting) nutrient uptake
+   !!   - switch for accelerated seafloor detritus remineralisation
+   !!   - switch for fast -> slow detritus transfer at seafloor
+   !!   - switch for ballast vs. Martin vs. Henson fast detritus remin.
+   !!   - per GMD referee remarks, xfdfrac3 introduced for grazed PDS
+   !!----------------------------------------------------------------------
+#endif
+   !!
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!                                        MEDUSA bio-model
+   !!----------------------------------------------------------------------
+   !!   trc_bio_medusa        :  
+   !!----------------------------------------------------------------------
+      USE oce_trc
+      USE trc
+      USE sms_medusa
+      USE lbclnk
+      USE prtctl_trc      ! Print control for debugging
+      USE trcsed_medusa
+      USE sbc_oce         ! surface forcing
+      USE sbcrnf          ! surface boundary condition: runoff variables
+      USE in_out_manager  ! I/O manager
+# if defined key_iomput
+      USE iom
+# endif
+# if defined key_roam
+      USE trcco2_medusa
+      USE trcoxy_medusa
+      !! Jpalm (08/08/2014)
+      USE trcdms_medusa
+# endif
+      !! AXY (18/01/12): brought in for benthic timestepping
+      USE trcnam_trp      ! AXY (24/05/2013)
+      USE trdmxl_trc
+      USE trdtrc_oce  ! AXY (24/05/2013)
+
+      !! AXY (30/01/14): necessary to find NaNs on HECTOR
+      USE, INTRINSIC :: ieee_arithmetic 
+
+      IMPLICIT NONE
+      PRIVATE
+      
+      PUBLIC   trc_bio_medusa    ! called in ???
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id: trcbio.F90 1146 2008-06-25 11:42:56Z rblod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_bio_medusa( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_bio  ***
+      !!
+      !! ** Purpose :   compute the now trend due to biogeochemical processes
+      !!              and add it to the general trend of passive tracers equations
+      !!
+      !! ** Method  :   each now biological flux is calculated in function of now
+      !!              concentrations of tracers.
+      !!              depending on the tracer, these fluxes are sources or sinks.
+      !!              the total of the sources and sinks for each tracer
+      !!              is added to the general trend.
+      !!        
+      !!                      tra = tra + zf...tra - zftra...
+      !!                                     |         |
+      !!                                     |         |
+      !!                                  source      sink
+      !!        
+      !!              IF 'key_trc_diabio' defined , the biogeochemical trends
+      !!              for passive tracers are saved for futher diagnostics.
+      !!---------------------------------------------------------------------
+      !!
+      !!
+      !!----------------------------------------------------------------------            
+      !! Variable conventions
+      !!----------------------------------------------------------------------
+      !!
+      !! names: z*** - state variable 
+      !!        f*** - function (or temporary variable used in part of a function)
+      !!        x*** - parameter
+      !!        b*** - right-hand part (sources and sinks)
+      !!        i*** - integer variable (usually used in yes/no flags)
+      !!
+      !! time (integer timestep)
+      INTEGER, INTENT( in ) ::    kt
+      !!
+      !! spatial array indices
+      INTEGER  ::    ji,jj,jk,jn
+      !!
+      !! AXY (27/07/10): add in indices for depth horizons (for sinking flux
+      !!                 and seafloor iron inputs)
+      !! INTEGER  ::    i0100, i0200, i0500, i1000, i1100
+      !!
+      !! model state variables
+      REAL(wp) ::    zchn,zchd,zphn,zphd,zpds,zzmi
+      REAL(wp) ::    zzme,zdet,zdtc,zdin,zsil,zfer
+      REAL(wp) ::    zage
+# if defined key_roam
+      REAL(wp) ::    zdic, zalk, zoxy
+      REAL(wp) ::    ztmp, zsal
+# endif
+      !!
+      !! integrated source and sink terms
+      REAL(wp) ::    b0
+      !! AXY (23/08/13): changed from individual variables for each flux to
+      !!                 an array that holds all fluxes
+      REAL(wp), DIMENSION(jp_medusa) ::    btra
+      !!
+      !! primary production and chl related quantities      
+      REAL(wp) ::    fthetan,faln,fchn1,fchn,fjln,fprn,frn
+      REAL(wp) ::    fthetad,fald,fchd1,fchd,fjld,fprd,frd
+      !! AXY (03/02/11): add in Liebig terms
+      REAL(wp) ::    fpnlim, fpdlim
+      !! AXY (16/07/09): add in Eppley curve functionality
+      REAL(wp) ::    loc_T,fun_T,xvpnT,xvpdT
+      INTEGER  ::    ieppley
+      !! AXY (01/03/10): add in mixed layer PP diagnostics
+      REAL(wp) ::    fprn_ml,fprd_ml
+      !!
+      !! nutrient limiting factors
+      REAL(wp) ::    fnln,ffln            !! N and Fe
+      REAL(wp) ::    fnld,ffld,fsld,fsld2 !! N, Fe and Si
+      !!
+      !! silicon cycle
+      REAL(wp) ::    fsin,fnsi,fsin1,fnsi1,fnsi2,fprds,fsdiss
+      !!
+      !! iron cycle; includes parameters for Parekh et al. (2005) iron scheme
+      REAL(wp) ::    ffetop,ffebot,ffescav
+      REAL(wp) ::    xLgF, xFeT, xFeF, xFeL, xFree  !! state variables for iron-ligand system
+      REAL(wp) ::    xb_coef_tmp, xb2M4ac           !! iron-ligand parameters
+      REAL(wp) ::    xmaxFeF,fdeltaFe               !! max Fe' parameters
+      !!
+      !! local parameters for Moore et al. (2004) alternative scavenging scheme
+      REAL(wp) ::    fbase_scav,fscal_sink,fscal_part,fscal_scav
+      !!
+      !! local parameters for Moore et al. (2008) alternative scavenging scheme
+      REAL(wp) ::    fscal_csink,fscal_sisink,fscal_casink
+      !!
+      !! local parameters for Galbraith et al. (2010) alternative scavenging scheme
+      REAL(wp) ::    xCscav1, xCscav2, xk_org, xORGscav  !! organic portion of scavenging
+      REAL(wp) ::    xk_inorg, xINORGscav                !! inorganic portion of scavenging
+      !!
+      !! microzooplankton grazing
+      REAL(wp) ::    fmi1,fmi,fgmipn,fgmid,fgmidc
+      REAL(wp) ::    finmi,ficmi,fstarmi,fmith,fmigrow,fmiexcr,fmiresp
+      !!
+      !! mesozooplankton grazing
+      REAL(wp) ::    fme1,fme,fgmepn,fgmepd,fgmepds,fgmezmi,fgmed,fgmedc
+      REAL(wp) ::    finme,ficme,fstarme,fmeth,fmegrow,fmeexcr,fmeresp
+      !!
+      !! mortality/Remineralisation (defunct parameter "fz" removed)
+      REAL(wp) ::    fdpn,fdpd,fdpds,fdzmi,fdzme,fdd
+# if defined key_roam
+      REAL(wp) ::    fddc
+# endif
+      REAL(wp) ::    fdpn2,fdpd2,fdpds2,fdzmi2,fdzme2
+      REAL(wp) ::    fslown, fslownflux
+      REAL(wp) ::    fslowc, fslowcflux
+      REAL(wp) ::    fregen,fregensi
+      REAL(wp), DIMENSION(jpi,jpj) ::    fregenfast,fregenfastsi
+# if defined key_roam
+      REAL(wp) ::    fregenc
+      REAL(wp), DIMENSION(jpi,jpj) ::    fregenfastc
+# endif
+      !!
+      !! particle flux
+      REAL(WP) ::    fthk,fdep,fdep1,fdep2,flat,fcaco3
+      REAL(WP) ::    ftempn,ftempsi,ftempfe,ftempc,ftempca
+      REAL(wp) ::    freminn,freminsi,freminfe,freminc,freminca
+      REAL(wp), DIMENSION(jpi,jpj) ::    ffastn,ffastsi,ffastfe,ffastc,ffastca
+      REAL(wp) ::    fleftn,fleftsi,fleftfe,fleftc,fleftca
+      REAL(wp) ::    fheren,fheresi,fherefe,fherec,fhereca
+      REAL(wp) ::    fprotf
+      REAL(wp) ::    fsedn,fsedsi,fsedfe,fsedc,fsedca
+      REAL(wp), DIMENSION(jpi,jpj) ::    fccd
+      REAL(wp) ::    fccd_dep
+      !!
+      !! AXY (06/07/11): alternative fast detritus schemes
+      REAL(wp) ::    fb_val, fl_sst
+      !!
+      !! AXY (08/07/11): fate of fast detritus reaching the seafloor
+      REAL(wp) ::    ffast2slown,ffast2slowfe,ffast2slowc
+      !!
+      !! conservation law
+      REAL(wp) ::    fnit0,fsil0,ffer0 
+# if defined key_roam
+      REAL(wp) ::    fcar0,falk0,foxy0 
+# endif      
+      !! 
+      !! temporary variables
+      REAL(wp) ::    fq0,fq1,fq2,fq3,fq4,fq5,fq6,fq7,fq8,fq9
+      !!
+      !! water column nutrient and flux integrals
+      REAL(wp) ::    ftot_n,ftot_si,ftot_fe
+      REAL(wp), DIMENSION(jpi,jpj) ::    fflx_n,fflx_si,fflx_fe
+      REAL(wp), DIMENSION(jpi,jpj) ::    fifd_n,fifd_si,fifd_fe
+      REAL(wp), DIMENSION(jpi,jpj) ::    fofd_n,fofd_si,fofd_fe
+# if defined key_roam
+      REAL(wp) ::    ftot_c,ftot_a,ftot_o2
+      REAL(wp), DIMENSION(jpi,jpj) ::    fflx_c,fflx_a,fflx_o2
+      REAL(wp), DIMENSION(jpi,jpj) ::    fifd_c,fifd_a,fifd_o2
+      REAL(wp), DIMENSION(jpi,jpj) ::    fofd_c,fofd_a,fofd_o2
+# endif
+      !!
+      !! zooplankton grazing integrals
+      REAL(wp), DIMENSION(jpi,jpj) ::    fzmi_i,fzmi_o,fzme_i,fzme_o
+      !!
+      !! limitation term temporary variables
+      REAL(wp), DIMENSION(jpi,jpj) ::    ftot_pn,ftot_pd
+      REAL(wp), DIMENSION(jpi,jpj) ::    ftot_zmi,ftot_zme,ftot_det,ftot_dtc
+      !! use ballast scheme (1) or simple exponential scheme (0; a conservation test)
+      INTEGER  ::    iball
+      !! use biological fluxes (1) or not (0)
+      INTEGER  ::    ibio_switch
+      !!
+      !! diagnose fluxes (should only be used in 1D runs)
+      INTEGER  ::    idf, idfval
+      !!
+      !! nitrogen and silicon production and consumption
+      REAL(wp) ::    fn_prod, fn_cons, fs_prod, fs_cons
+      REAL(wp), DIMENSION(jpi,jpj) ::    fnit_prod, fnit_cons, fsil_prod, fsil_cons
+# if defined key_roam
+      !!
+      !! flags to help with calculating the position of the CCD
+      INTEGER, DIMENSION(jpi,jpj) ::     i2_omcal,i2_omarg
+      !!
+      !! ROAM air-sea flux and diagnostic parameters
+      REAL(wp) ::    f_wind, f_pco2a
+      REAL(wp) ::    f_ph, f_pco2w, f_h2co3, f_hco3, f_co3, f_co2flux
+      REAL(wp) ::    f_TDIC, f_TALK, f_dcf, f_henry
+      REAL(wp) ::    f_uwind, f_vwind, f_pp0
+      REAL(wp) ::    f_kw660, f_o2flux, f_o2sat
+      REAL(wp), DIMENSION(jpi,jpj) ::    f_omcal, f_omarg
+      INTEGER  ::    iters
+      REAL(wp) ::    f_year
+      INTEGER  ::    i_year
+      INTEGER  ::    iyr1, iyr2
+      !!
+      !! carbon, alkalinity production and consumption
+      REAL(wp) ::    fc_prod, fc_cons, fa_prod, fa_cons
+      REAL(wp) ::    fcomm_resp
+      REAL(wp), DIMENSION(jpi,jpj) ::    fcar_prod, fcar_cons
+      !!
+      !! oxygen production and consumption (and non-consumption)
+      REAL(wp) ::    fo2_prod, fo2_cons, fo2_ncons, fo2_ccons
+      REAL(wp), DIMENSION(jpi,jpj) ::    foxy_prod, foxy_cons, foxy_anox
+      !! Jpalm (11-08-2014)
+      !! add DMS in MEDUSA for UKESM1 model
+      REAL(wp) ::    dms_surf
+      !! AXY (13/03/15): add in other DMS calculations
+      REAL(wp) ::    dms_andr, dms_simo, dms_aran, dms_hall
+# endif
+      !! 
+      !! benthic fluxes
+      INTEGER  ::    ibenthic
+      REAL(wp), DIMENSION(jpi,jpj) :: f_sbenin_n, f_sbenin_fe,              f_sbenin_c
+      REAL(wp), DIMENSION(jpi,jpj) :: f_fbenin_n, f_fbenin_fe, f_fbenin_si, f_fbenin_c, f_fbenin_ca
+      REAL(wp), DIMENSION(jpi,jpj) :: f_benout_n, f_benout_fe, f_benout_si, f_benout_c, f_benout_ca
+      REAL(wp) ::    zfact
+      !! 
+      !! benthic fluxes of CaCO3 that shouldn't happen because of lysocline
+      REAL(wp), DIMENSION(jpi,jpj) :: f_benout_lyso_ca
+      !!
+      !! riverine fluxes
+      REAL(wp), DIMENSION(jpi,jpj) :: f_runoff, f_riv_n, f_riv_si, f_riv_c, f_riv_alk
+      !! AXY (19/07/12): variables for local riverine fluxes to handle inputs below surface
+      REAL(wp) ::    f_riv_loc_n, f_riv_loc_si, f_riv_loc_c, f_riv_loc_alk
+      !!
+      !! horizontal grid location
+      REAL(wp) ::    flatx, flonx
+
+      !!---------------------------------------------------------------------
+
+      !! AXY (20/11/14): alter this to report on first MEDUSA call
+      !! IF( kt == nit000 ) THEN
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' trc_bio: MEDUSA bio-model'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+	 IF(lwp) WRITE(numout,*) ' kt =',kt
+      ENDIF
+
+      !! AXY (13/01/12): is benthic model properly interactive? 0 = no, 1 = yes
+      ibenthic = 1
+
+      !! not sure what this is for; it's not used anywhere; commenting out
+      !! fbodn(:,:) = 0.e0   
+
+      !!
+      IF( ln_diatrc ) THEN
+         !! blank 2D diagnostic array
+         trc2d(:,:,:) = 0.e0
+         !!
+         !! blank 3D diagnostic array
+         trc3d(:,:,:,:) = 0.e0
+      ENDIF
+
+      !!----------------------------------------------------------------------
+      !! b0 is present for debugging purposes; using b0 = 0 sets the tendency
+      !! terms of all biological equations to 0.
+      !!----------------------------------------------------------------------
+      !!
+      !! AXY (03/09/14): probably not the smartest move ever, but it'll fit
+      !!                 the bill for now; another item on the things-to-sort-
+      !!		 out-in-the-future list ...
+# if defined key_kill_medusa
+      b0 = 0.
+# else
+      b0 = 1.
+# endif
+      !!----------------------------------------------------------------------
+      !! fast detritus ballast scheme (0 = no; 1 = yes)
+      !! alternative to ballast scheme is same scheme but with no ballast
+      !! protection (not dissimilar to Martin et al., 1987)
+      !!----------------------------------------------------------------------
+      !!
+      iball = 1
+
+      !!----------------------------------------------------------------------
+      !! full flux diagnostics (0 = no; 1 = yes); appear in ocean.output
+      !! these should *only* be used in 1D since they give comprehensive
+      !! output for ecological functions in the model; primarily used in
+      !! debugging
+      !!----------------------------------------------------------------------
+      !!
+      idf    = 0
+      !!
+      !! timer mechanism
+      if (kt/120*120.eq.kt) then
+         idfval = 1
+      else
+         idfval = 0
+      endif
+
+      !!----------------------------------------------------------------------
+      !! blank fast-sinking detritus 2D fields
+      !!----------------------------------------------------------------------
+      !!
+      ffastn(:,:)  = 0.0        !! organic nitrogen
+      ffastsi(:,:) = 0.0        !! biogenic silicon
+      ffastfe(:,:) = 0.0        !! organic iron
+      ffastc(:,:)  = 0.0        !! organic carbon
+      ffastca(:,:) = 0.0        !! biogenic calcium carbonate
+      !!
+      fregenfast(:,:)   = 0.0   !! integrated  N regeneration (fast detritus)
+      fregenfastsi(:,:) = 0.0   !! integrated Si regeneration (fast detritus)
+# if defined key_roam
+      fregenfastc(:,:)  = 0.0   !! integrated  C regeneration (fast detritus)
+# endif
+      !!
+      fccd(:,:)    = 0.0        !! last depth level before CCD
+
+      !!----------------------------------------------------------------------
+      !! blank nutrient/flux inventories
+      !!----------------------------------------------------------------------
+      !!
+      fflx_n(:,:)  = 0.0        !! nitrogen flux total
+      fflx_si(:,:) = 0.0        !! silicon  flux total
+      fflx_fe(:,:) = 0.0        !! iron     flux total
+      fifd_n(:,:)  = 0.0        !! nitrogen fast detritus production
+      fifd_si(:,:) = 0.0        !! silicon  fast detritus production
+      fifd_fe(:,:) = 0.0        !! iron     fast detritus production
+      fofd_n(:,:)  = 0.0        !! nitrogen fast detritus remineralisation
+      fofd_si(:,:) = 0.0        !! silicon  fast detritus remineralisation
+      fofd_fe(:,:) = 0.0        !! iron     fast detritus remineralisation
+# if defined key_roam
+      fflx_c(:,:)  = 0.0        !! carbon     flux total
+      fflx_a(:,:)  = 0.0        !! alkalinity flux total
+      fflx_o2(:,:) = 0.0        !! oxygen     flux total
+      fifd_c(:,:)  = 0.0        !! carbon     fast detritus production
+      fifd_a(:,:)  = 0.0        !! alkalinity fast detritus production
+      fifd_o2(:,:) = 0.0        !! oxygen     fast detritus production
+      fofd_c(:,:)  = 0.0        !! carbon     fast detritus remineralisation
+      fofd_a(:,:)  = 0.0        !! alkalinity fast detritus remineralisation
+      fofd_o2(:,:) = 0.0        !! oxygen     fast detritus remineralisation
+      !!
+      fnit_prod(:,:) = 0.0      !! (organic)   nitrogen production
+      fnit_cons(:,:) = 0.0      !! (organic)   nitrogen consumption
+      fsil_prod(:,:) = 0.0      !! (inorganic) silicon production
+      fsil_cons(:,:) = 0.0      !! (inorganic) silicon consumption
+      fcar_prod(:,:) = 0.0      !! (organic)   carbon production
+      fcar_cons(:,:) = 0.0      !! (organic)   carbon consumption
+      !!
+      foxy_prod(:,:) = 0.0      !! oxygen production
+      foxy_cons(:,:) = 0.0      !! oxygen consumption
+      foxy_anox(:,:) = 0.0      !! unrealised oxygen consumption
+# endif
+      ftot_pn(:,:)  = 0.0       !! integrated non-diatom phytoplankton
+      ftot_pd(:,:)  = 0.0       !! integrated diatom     phytoplankton
+      ftot_zmi(:,:) = 0.0       !! integrated microzooplankton
+      ftot_zme(:,:) = 0.0       !! integrated mesozooplankton
+      ftot_det(:,:) = 0.0       !! integrated slow detritus, nitrogen
+      ftot_dtc(:,:) = 0.0       !! integrated slow detritus, carbon
+      !!
+      fzmi_i(:,:)  = 0.0        !! material grazed by microzooplankton
+      fzmi_o(:,:)  = 0.0        !! ... sum of fate of this material
+      fzme_i(:,:)  = 0.0        !! material grazed by  mesozooplankton
+      fzme_o(:,:)  = 0.0        !! ... sum of fate of this material
+      !!
+      f_sbenin_n(:,:)  = 0.0    !! slow detritus N  -> benthic pool
+      f_sbenin_fe(:,:) = 0.0    !! slow detritus Fe -> benthic pool
+      f_sbenin_c(:,:)  = 0.0    !! slow detritus C  -> benthic pool
+      f_fbenin_n(:,:)  = 0.0    !! fast detritus N  -> benthic pool
+      f_fbenin_fe(:,:) = 0.0    !! fast detritus Fe -> benthic pool
+      f_fbenin_si(:,:) = 0.0    !! fast detritus Si -> benthic pool
+      f_fbenin_c(:,:)  = 0.0    !! fast detritus C  -> benthic pool
+      f_fbenin_ca(:,:) = 0.0    !! fast detritus Ca -> benthic pool
+      !!
+      f_benout_n(:,:)  = 0.0    !! benthic N  pool  -> dissolved
+      f_benout_fe(:,:) = 0.0    !! benthic Fe pool  -> dissolved
+      f_benout_si(:,:) = 0.0    !! benthic Si pool  -> dissolved
+      f_benout_c(:,:)  = 0.0    !! benthic C  pool  -> dissolved
+      f_benout_ca(:,:) = 0.0    !! benthic Ca pool  -> dissolved
+      !!
+      f_benout_lyso_ca(:,:) = 0.0 !! benthic Ca pool  -> dissolved (when it shouldn't!)
+      !!
+      f_runoff(:,:)  = 0.0      !! riverine runoff
+      f_riv_n(:,:)   = 0.0      !! riverine N   input 
+      f_riv_si(:,:)  = 0.0      !! riverine Si  input 
+      f_riv_c(:,:)   = 0.0      !! riverine C   input 
+      f_riv_alk(:,:) = 0.0      !! riverine alk input 
+
+# if defined key_axy_nancheck
+      DO jn = 1,jptra
+         !! fq0 = MINVAL(trn(:,:,:,jn))
+         !! fq1 = MAXVAL(trn(:,:,:,jn))
+         fq2 = SUM(trn(:,:,:,jn))
+         !! if (lwp) write (numout,'(a,2i6,3(1x,1pe15.5))') 'NAN-CHECK', &
+         !! &        kt, jn, fq0, fq1, fq2
+         !! AXY (30/01/14): much to our surprise, the next line doesn't work on HECTOR
+         !!                 and has been replaced here with a specialist routine
+         !! if (fq2 /= fq2 ) then
+         if ( ieee_is_nan( fq2 ) ) then
+            !! there's a NaN here
+            if (lwp) write(numout,*) 'NAN detected in field', jn, 'at time', kt, 'at position:'
+            DO jk = 1,jpk
+               DO jj = 1,jpj
+                  DO ji = 1,jpi
+                     !! AXY (30/01/14): "isnan" problem on HECTOR
+                     !! if (trn(ji,jj,jk,jn) /= trn(ji,jj,jk,jn)) then
+                     if ( ieee_is_nan( trn(ji,jj,jk,jn) ) ) then
+                        if (lwp) write (numout,'(a,1pe12.2,4i6)') 'NAN-CHECK', &
+                        &        tmask(ji,jj,jk), ji, jj, jk, jn
+                     endif
+                  enddo
+               enddo
+            enddo
+	    CALL ctl_stop( 'trcbio_medusa, NAN in incoming tracer field' )
+         endif
+      ENDDO
+      CALL flush(numout)
+# endif
+
+# if defined key_roam
+      !!----------------------------------------------------------------------
+      !! calculate atmospheric pCO2
+      !!----------------------------------------------------------------------
+      !!
+      !! what's atmospheric pCO2 doing? (data start in 1859)
+      iyr1  = nyear - 1859 + 1
+      iyr2  = iyr1 + 1
+      if (iyr1 .le. 1) then
+         !! before 1860
+         f_pco2a = hist_pco2(1)
+      elseif (iyr2 .ge. 242) then
+         !! after 2099
+         f_pco2a = hist_pco2(242)
+      else
+         !! just right
+         fq0 = hist_pco2(iyr1)
+         fq1 = hist_pco2(iyr2)
+         fq2 = real(nsec_day) / (60.0 * 60.0 * 24.0)
+         !! AXY (14/06/12): tweaked to make more sense (and be correct)
+#  if defined key_bs_axy_yrlen
+         fq3 = (real(nday_year) - 1.0 + fq2) / 360.0  !! bugfix: for 360d year with HadGEM2-ES forcing
+#  else
+         fq3 = (real(nday_year) - 1.0 + fq2) / 365.0  !! original use of 365 days (not accounting for leap year or 360d year)
+#  endif
+         fq4 = (fq0 * (1.0 - fq3)) + (fq1 * fq3)
+         f_pco2a = fq4
+      endif
+# if defined key_axy_pi_co2
+      f_pco2a = hist_pco2(1)
+      IF(lwp) WRITE(numout,*) ' MEDUSA atm pCO2  = FIXED'
+# endif
+      !! IF(lwp) WRITE(numout,*) ' MEDUSA nyear     =', nyear
+      !! IF(lwp) WRITE(numout,*) ' MEDUSA nsec_day  =', real(nsec_day)
+      !! IF(lwp) WRITE(numout,*) ' MEDUSA nday_year =', real(nday_year)
+      !! AXY (29/01/14): remove surplus diagnostics
+      !! IF(lwp) WRITE(numout,*) ' MEDUSA fq0       =', fq0
+      !! IF(lwp) WRITE(numout,*) ' MEDUSA fq1       =', fq1
+      !! IF(lwp) WRITE(numout,*) ' MEDUSA fq2       =', fq2
+      !! IF(lwp) WRITE(numout,*) ' MEDUSA fq3       =', fq3
+      IF(lwp) WRITE(numout,*) ' MEDUSA atm pCO2  =', f_pco2a
+# endif
+
+# if defined key_roam
+      !! AXY (20/11/14): alter to call on first MEDUSA timestep
+      !! IF( kt == nit000 .or. mod(kt,1920) == 0 ) THEN
+      IF( kt == nittrc000 .or. mod(kt,1920) == 0 ) THEN
+         !!----------------------------------------------------------------------
+         !! Calculate the carbonate chemistry for the whole ocean on the first
+         !! simulation timestep and every month subsequently; the resulting 3D
+         !! field of omega calcite is used to determine the depth of the CCD
+         !!----------------------------------------------------------------------
+         !!
+         IF(lwp) WRITE(numout,*) ' MEDUSA calculating all carbonate chemistry at kt =', kt
+         !! blank flags
+         i2_omcal(:,:) = 0
+         i2_omarg(:,:) = 0
+         !! loop over 3D space
+         DO jk = 1,jpk
+            DO jj = 2,jpjm1
+               DO ji = 2,jpim1
+                  !! OPEN wet point IF..THEN loop
+                  if (tmask(ji,jj,jk).eq.1) then
+                     !! carbonate chemistry
+                     fdep2 = fsdept(ji,jj,jk)           !! set up level midpoint
+                     !! set up required state variables
+                     zdic = max(0.,trn(ji,jj,jk,jpdic)) !! dissolved inorganic carbon
+                     zalk = max(0.,trn(ji,jj,jk,jpalk)) !! alkalinity
+                     ztmp = tsn(ji,jj,jk,jp_tem)        !! temperature
+                     zsal = tsn(ji,jj,jk,jp_sal)        !! salinity
+		     !!
+		     !! AXY (28/02/14): check input fields
+		     if (ztmp .lt. -3.0 .or. ztmp .gt. 40.0 ) then
+                        IF(lwp) WRITE(numout,*) ' trc_bio_medusa: T WARNING 3D, ', &
+                        tsb(ji,jj,jk,jp_tem), tsn(ji,jj,jk,jp_tem), ' at (',    &
+                        ji, ',', jj, ',', jk, ') at time', kt
+			IF(lwp) WRITE(numout,*) ' trc_bio_medusa: T SWITCHING 3D, ', &
+			tsn(ji,jj,jk,jp_tem), ' -> ', tsb(ji,jj,jk,jp_tem)
+                        ztmp = tsb(ji,jj,jk,jp_tem)     !! temperature
+                     endif
+		     if (zsal .lt. 0.0 .or. zsal .gt. 45.0 ) then
+                        IF(lwp) WRITE(numout,*) ' trc_bio_medusa: S WARNING 3D, ', &
+                        tsb(ji,jj,jk,jp_sal), tsn(ji,jj,jk,jp_sal), ' at (',    &
+                        ji, ',', jj, ',', jk, ') at time', kt
+                     endif
+                     !! calculate carbonate chemistry at grid cell midpoint
+                     CALL trc_co2_medusa( ztmp, zsal, zdic, zalk, fdep2, 5.0, f_pco2a, &    ! inputs
+                     f_ph, f_pco2w, f_h2co3, f_hco3, f_co3, f_omcal(ji,jj),            &    ! outputs
+                     f_omarg(ji,jj), f_co2flux, f_TDIC, f_TALK, f_dcf, f_henry, iters)      ! outputs
+                     !! 
+                     !! AXY (28/02/14): check output fields
+                     if (iters .eq. 25) then
+                        IF(lwp) WRITE(numout,*) ' trc_bio_medusa: 3D ITERS WARNING, ', &
+                        iters, ' AT (', ji, ', ', jj, ', ', jk, ') AT ', kt
+                     endif
+                     !! store 3D outputs
+                     f3_pH(ji,jj,jk)    = f_ph
+                     f3_h2co3(ji,jj,jk) = f_h2co3
+                     f3_hco3(ji,jj,jk)  = f_hco3
+                     f3_co3(ji,jj,jk)   = f_co3
+                     f3_omcal(ji,jj,jk) = f_omcal(ji,jj)
+                     f3_omarg(ji,jj,jk) = f_omarg(ji,jj)
+                     !! CCD calculation: calcite
+                     if (i2_omcal(ji,jj) .eq. 0 .and. f_omcal(ji,jj) .lt. 1.0) then
+                        if (jk .eq. 1) then
+                           f2_ccd_cal(ji,jj) = fdep2
+                        else
+                           fq0 = f3_omcal(ji,jj,jk-1) - f_omcal(ji,jj)
+                           fq1 = f3_omcal(ji,jj,jk-1) - 1.0
+                           fq2 = fq1 / (fq0 + tiny(fq0))
+                           fq3 = fdep2 - fsdept(ji,jj,jk-1)
+                           fq4 = fq2 * fq3
+                           f2_ccd_cal(ji,jj) = fsdept(ji,jj,jk-1) + fq4
+                        endif
+                        i2_omcal(ji,jj)   = 1
+                     endif
+                     if ( i2_omcal(ji,jj) .eq. 0 .and. jk .eq. (mbathy(ji,jj)-1) ) then
+                        !! reached seafloor and still no dissolution; set to seafloor (W-point)
+                        f2_ccd_cal(ji,jj) = fsdepw(ji,jj,jk+1)
+                        i2_omcal(ji,jj)   = 1
+                     endif
+                     !! CCD calculation: aragonite
+                     if (i2_omarg(ji,jj) .eq. 0 .and. f_omarg(ji,jj) .lt. 1.0) then
+                        if (jk .eq. 1) then
+                           f2_ccd_arg(ji,jj) = fdep2
+                        else
+                           fq0 = f3_omarg(ji,jj,jk-1) - f_omarg(ji,jj)
+                           fq1 = f3_omarg(ji,jj,jk-1) - 1.0
+                           fq2 = fq1 / (fq0 + tiny(fq0))
+                           fq3 = fdep2 - fsdept(ji,jj,jk-1)
+                           fq4 = fq2 * fq3
+                           f2_ccd_arg(ji,jj) = fsdept(ji,jj,jk-1) + fq4
+                        endif
+                        i2_omarg(ji,jj)   = 1
+                     endif
+                     if ( i2_omarg(ji,jj) .eq. 0 .and. jk .eq. (mbathy(ji,jj)-1) ) then
+                        !! reached seafloor and still no dissolution; set to seafloor (W-point)
+                        f2_ccd_arg(ji,jj) = fsdepw(ji,jj,jk+1)
+                        i2_omarg(ji,jj)   = 1
+                     endif
+                  endif
+               ENDDO
+            ENDDO
+         ENDDO
+      ENDIF
+# endif
+
+      !!----------------------------------------------------------------------
+      !! MEDUSA has unified equation through the water column
+      !! (Diff. from LOBSTER which has two sets: bio- and non-bio layers) 
+      !! Statement below in LOBSTER is different: DO jk = 1, jpkbm1          
+      !!----------------------------------------------------------------------
+      !!
+      !! NOTE: the ordering of the loops below differs from that of some other
+      !! models; looping over the vertical dimension is the outermost loop and
+      !! this complicates some calculations (e.g. storage of vertical fluxes
+      !! that can otherwise be done via a singular variable require 2D fields
+      !! here); however, these issues are relatively easily resolved, but the
+      !! loops CANNOT be reordered without potentially causing code efficiency
+      !! problems (e.g. array indexing means that reordering the loops would
+      !! require skipping between widely-spaced memory location; potentially
+      !! outside those immediately cached)
+      !!
+      !! OPEN vertical loop
+      DO jk = 1,jpk
+         !! OPEN horizontal loops
+         DO jj = 2,jpjm1
+         DO ji = 2,jpim1
+            !! OPEN wet point IF..THEN loop
+            if (tmask(ji,jj,jk).eq.1) then               
+
+               !!======================================================================
+               !! SETUP LOCAL GRID CELL
+               !!======================================================================
+               !!
+               !!---------------------------------------------------------------------
+               !! Some notes on grid vertical structure
+               !! - fsdepw(ji,jj,jk) is the depth of the upper surface of level jk
+               !! - fsde3w(ji,jj,jk) is *approximately* the midpoint of level jk
+               !! - fse3t(ji,jj,jk)  is the thickness of level jk
+               !!---------------------------------------------------------------------
+               !!
+               !! AXY (11/12/08): set up level thickness
+               fthk  = fse3t(ji,jj,jk)
+               !! AXY (25/02/10): set up level depth (top of level)
+               fdep  = fsdepw(ji,jj,jk)
+               !! AXY (01/03/10): set up level depth (bottom of level)
+               fdep1 = fdep + fthk
+               !! AXY (17/05/13): where am I?
+               flatx = gphit(ji,jj)
+               flonx = glamt(ji,jj)
+               !!
+               !! set up model tracers
+               !! negative values of state variables are not allowed to
+               !! contribute to the calculated fluxes
+               zchn = max(0.,trn(ji,jj,jk,jpchn)) !! non-diatom chlorophyll
+               zchd = max(0.,trn(ji,jj,jk,jpchd)) !! diatom chlorophyll
+               zphn = max(0.,trn(ji,jj,jk,jpphn)) !! non-diatoms
+               zphd = max(0.,trn(ji,jj,jk,jpphd)) !! diatoms
+               zpds = max(0.,trn(ji,jj,jk,jppds)) !! diatom silicon
+               !! AXY (28/01/10): probably need to take account of chl/biomass connection
+               if (zchn.eq.0.) zphn = 0.
+               if (zchd.eq.0.) zphd = 0.
+               if (zphn.eq.0.) zchn = 0.
+               if (zphd.eq.0.) zchd = 0.
+	       !! AXY (23/01/14): duh - why did I forget diatom silicon?
+	       if (zpds.eq.0.) zphd = 0.
+	       if (zphd.eq.0.) zpds = 0.
+               zzmi = max(0.,trn(ji,jj,jk,jpzmi)) !! microzooplankton
+               zzme = max(0.,trn(ji,jj,jk,jpzme)) !! mesozooplankton
+               zdet = max(0.,trn(ji,jj,jk,jpdet)) !! detrital nitrogen
+               zdin = max(0.,trn(ji,jj,jk,jpdin)) !! dissolved inorganic nitrogen
+               zsil = max(0.,trn(ji,jj,jk,jpsil)) !! dissolved silicic acid
+               zfer = max(0.,trn(ji,jj,jk,jpfer)) !! dissolved "iron"
+# if defined key_roam
+               zdtc = max(0.,trn(ji,jj,jk,jpdtc)) !! detrital carbon
+               zdic = max(0.,trn(ji,jj,jk,jpdic)) !! dissolved inorganic carbon
+               zalk = max(0.,trn(ji,jj,jk,jpalk)) !! alkalinity
+               zoxy = max(0.,trn(ji,jj,jk,jpoxy)) !! oxygen
+               !!
+               !! also need physical parameters for gas exchange calculations
+               ztmp = tsn(ji,jj,jk,jp_tem)
+               zsal = tsn(ji,jj,jk,jp_sal)
+               !!
+	       !! AXY (28/02/14): check input fields
+               if (ztmp .lt. -3.0 .or. ztmp .gt. 40.0 ) then
+                  IF(lwp) WRITE(numout,*) ' trc_bio_medusa: T WARNING 2D, ', &
+                  tsb(ji,jj,jk,jp_tem), tsn(ji,jj,jk,jp_tem), ' at (',    &
+                  ji, ',', jj, ',', jk, ') at time', kt
+		  IF(lwp) WRITE(numout,*) ' trc_bio_medusa: T SWITCHING 2D, ', &
+                  tsn(ji,jj,jk,jp_tem), ' -> ', tsb(ji,jj,jk,jp_tem)
+                  ztmp = tsb(ji,jj,jk,jp_tem) !! temperature
+               endif
+               if (zsal .lt. 0.0 .or. zsal .gt. 45.0 ) then
+                  IF(lwp) WRITE(numout,*) ' trc_bio_medusa: S WARNING 2D, ', &
+                  tsb(ji,jj,jk,jp_sal), tsn(ji,jj,jk,jp_sal), ' at (',    &
+                  ji, ',', jj, ',', jk, ') at time', kt
+               endif
+# else
+               zdtc = zdet * xthetad              !! implicit detrital carbon
+# endif
+# if defined key_debug_medusa
+               if (idf.eq.1) then
+               !! AXY (15/01/10)
+                  if (trn(ji,jj,jk,jpdin).lt.0.) then
+                     IF (lwp) write (numout,*) '------------------------------'
+                     IF (lwp) write (numout,*) 'NEGATIVE DIN ERROR =', trn(ji,jj,jk,jpdin)
+                     IF (lwp) write (numout,*) 'NEGATIVE DIN ERROR @', ji, jj, jk, kt
+                  endif
+                  if (trn(ji,jj,jk,jpsil).lt.0.) then
+                     IF (lwp) write (numout,*) '------------------------------'
+                     IF (lwp) write (numout,*) 'NEGATIVE SIL ERROR =', trn(ji,jj,jk,jpsil)
+                     IF (lwp) write (numout,*) 'NEGATIVE SIL ERROR @', ji, jj, jk, kt
+                  endif
+#  if defined key_roam
+                  if (trn(ji,jj,jk,jpdic).lt.0.) then
+                     IF (lwp) write (numout,*) '------------------------------'
+                     IF (lwp) write (numout,*) 'NEGATIVE DIC ERROR =', trn(ji,jj,jk,jpdic)
+                     IF (lwp) write (numout,*) 'NEGATIVE DIC ERROR @', ji, jj, jk, kt
+                  endif
+                  if (trn(ji,jj,jk,jpalk).lt.0.) then
+                     IF (lwp) write (numout,*) '------------------------------'
+                     IF (lwp) write (numout,*) 'NEGATIVE ALK ERROR =', trn(ji,jj,jk,jpalk)
+                     IF (lwp) write (numout,*) 'NEGATIVE ALK ERROR @', ji, jj, jk, kt
+                  endif
+                  if (trn(ji,jj,jk,jpoxy).lt.0.) then
+                     IF (lwp) write (numout,*) '------------------------------'
+                     IF (lwp) write (numout,*) 'NEGATIVE OXY ERROR =', trn(ji,jj,jk,jpoxy)
+                     IF (lwp) write (numout,*) 'NEGATIVE OXY ERROR @', ji, jj, jk, kt
+                  endif
+#  endif
+               endif
+# endif
+# if defined key_debug_medusa
+               !! report state variable values
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fthk(',jk,') = ', fthk
+                  IF (lwp) write (numout,*) 'zphn(',jk,') = ', zphn
+                  IF (lwp) write (numout,*) 'zphd(',jk,') = ', zphd
+                  IF (lwp) write (numout,*) 'zpds(',jk,') = ', zpds
+                  IF (lwp) write (numout,*) 'zzmi(',jk,') = ', zzmi
+                  IF (lwp) write (numout,*) 'zzme(',jk,') = ', zzme
+                  IF (lwp) write (numout,*) 'zdet(',jk,') = ', zdet
+                  IF (lwp) write (numout,*) 'zdin(',jk,') = ', zdin
+                  IF (lwp) write (numout,*) 'zsil(',jk,') = ', zsil
+                  IF (lwp) write (numout,*) 'zfer(',jk,') = ', zfer
+#  if defined key_roam
+                  IF (lwp) write (numout,*) 'zdtc(',jk,') = ', zdtc
+                  IF (lwp) write (numout,*) 'zdic(',jk,') = ', zdic
+                  IF (lwp) write (numout,*) 'zalk(',jk,') = ', zalk
+                  IF (lwp) write (numout,*) 'zoxy(',jk,') = ', zoxy                  
+#  endif
+               endif
+# endif
+
+# if defined key_debug_medusa
+               if (idf.eq.1.AND.idfval.eq.1.AND.jk.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'dustmo(1) = ', dustmo(ji,jj,1)
+                  IF (lwp) write (numout,*) 'dustmo(2) = ', dustmo(ji,jj,2)
+                  IF (lwp) write (numout,*) 'dust      = ', dust(ji,jj)
+               endif
+# endif
+
+               !! sum tracers for inventory checks
+               ftot_n  = fthk * ( zphn + zphd + zzmi + zzme + zdet + zdin )
+               ftot_si = fthk * ( zpds + zsil )
+               ftot_fe = fthk * ( xrfn * ( zphn + zphd + zzmi + zzme + zdet ) + zfer )
+# if defined key_roam
+               ftot_c  = fthk * ( (xthetapn * zphn) + (xthetapd * zphd) + &
+                         (xthetazmi * zzmi) + (xthetazme * zzme) + zdtc + &
+                         zdic )
+               ftot_a  = fthk * ( zalk )
+               ftot_o2 = fthk * ( zoxy )
+# endif
+               CALL flush(numout)
+
+               !!======================================================================
+               !! LOCAL GRID CELL CALCULATIONS
+               !!======================================================================
+               !!
+# if defined key_roam
+               if ( jk .eq. 1 ) then
+                  !!----------------------------------------------------------------------
+                  !! Air-sea gas exchange
+                  !!----------------------------------------------------------------------
+                  !!
+                  !! a bit of set up ...
+                  ! f_uwind = zwnd_i(ji,jj)
+                  ! f_vwind = zwnd_j(ji,jj)
+                  !! AXY (17/07/14): zwind_i and zwind_j do not exist in this
+                  !!                 version of NEMO because it does not include
+                  !!                 the SBC changes that our local version has
+                  !!                 for accessing the HadGEM2 forcing; they 
+                  !!                 could be added, but an alternative approach
+                  !!                 is to make use of wndm from oce_trc.F90
+                  !!                 which is wind speed at 10m (which is what
+                  !!                 is required here; this may need to be
+                  !!                 revisited when MEDUSA properly interacts
+                  !!                 with UKESM1 physics
+                  ! f_uwind = zwind_i(ji,jj)
+                  ! f_vwind = zwind_j(ji,jj)
+                  ! f_wind  = ((f_uwind**2.0) + (f_vwind**2.0))**0.5
+                  f_wind  = wndm(ji,jj)
+                  !! AXY (17/07/14): the current oxygen code takes in separate
+                  !!                 U and V components of the wind; to avoid
+                  !!                 the need to change this, calculate these
+                  !!                 components based on wndm; again, this is
+                  !!                 not ideal, but should suffice as a
+                  !!                 temporary measure; in the long-term all
+                  !!                 of MEDUSA's air-sea gas exchange terms
+                  !!                 will be revisited to ensure that they are
+                  !!                 valid and self-consistent; and the CO2
+                  !!                 code will be wholly replaced with a more
+                  !!                 up-to-date parameterisation
+                  f_uwind = ((f_wind**2.0) / 2.0)**0.5
+                  f_vwind = f_uwind
+                  f_pp0   = 1.0
+                  !! IF(lwp) WRITE(numout,*) ' MEDUSA ztmp    =', ztmp
+                  !! IF(lwp) WRITE(numout,*) ' MEDUSA zwind_i =', zwind_i(ji,jj)
+                  !! IF(lwp) WRITE(numout,*) ' MEDUSA zwind_j =', zwind_j(ji,jj)
+                  !! IF(lwp) WRITE(numout,*) ' MEDUSA f_wind  =', f_wind
+                  !! IF(lwp) WRITE(numout,*) ' MEDUSA fr_i    =', fr_i(ji,jj)
+                  !!
+#  if defined key_axy_carbchem
+                  iters = 0
+                  !!
+                  !! carbon dioxide (CO2); Jerry Blackford code (ostensibly OCMIP-2, but not)
+                  CALL trc_co2_medusa( ztmp, zsal, zdic, zalk, 0.0, f_wind, f_pco2a, &     ! inputs
+                  f_ph, f_pco2w, f_h2co3, f_hco3, f_co3, f_omcal(ji,jj),             &     ! outputs
+                  f_omarg(ji,jj), f_co2flux, f_TDIC, f_TALK, f_dcf, f_henry, iters )       ! outputs
+                  !!
+                  !! AXY (09/01/14): removed iteration and NaN checks; these have
+                  !!                 been moved to trc_co2_medusa together with a
+                  !!                 fudge that amends erroneous values (this is
+                  !!                 intended to be a temporary fudge!); the
+                  !!                 output warnings are retained here so that
+                  !!                 failure position can be determined
+                  if (iters .eq. 25) then
+                     IF(lwp) WRITE(numout,*) ' trc_bio_medusa: ITERS WARNING, ', &
+                     iters, ' AT (', ji, ', ', jj, ', ', jk, ') AT ', kt
+                  endif
+#  else
+                  !! AXY (18/04/13): switch off carbonate chemistry calculations; provide
+                  !!                 quasi-sensible alternatives
+                  f_ph           = 8.1
+                  f_pco2w        = f_pco2a
+                  f_h2co3        = 0.005 * zdic
+                  f_hco3         = 0.865 * zdic
+                  f_co3          = 0.130 * zdic
+                  f_omcal(ji,jj) = 4.
+                  f_omarg(ji,jj) = 2.
+                  f_co2flux      = 0.
+                  f_TDIC         = zdic
+                  f_TALK         = zalk
+                  f_dcf          = 1.
+                  f_henry        = 1.
+#  endif
+                  !!
+                  !! already in right units; correct for sea-ice; divide through by layer thickness
+                  f_co2flux = (1. - fr_i(ji,jj)) * f_co2flux / fthk
+                  !!
+                  !! oxygen (O2); OCMIP-2 code
+                  CALL trc_oxy_medusa( ztmp, zsal, f_uwind, f_vwind, f_pp0, zoxy / 1000., fthk, &  ! inputs
+                  f_kw660, f_o2flux, f_o2sat )                                                     ! outputs
+                  !!
+                  !! mol/m3/s -> mmol/m3/d; correct for sea-ice
+                  f_o2flux  = (1. - fr_i(ji,jj)) * f_o2flux * 1000. * 60. * 60. * 24. 
+                  f_o2sat   = f_o2sat  * 1000.
+                  !!
+                  !! Jpalm (08-2014)
+                  !! DMS surface concentration calculation
+                  !! initialy added for UKESM1 model.
+                  !! using MET-OFFICE subroutine.
+                  !! DMS module only needs Chl concentration and MLD
+                  !! to get an aproximate value of DMS concentration.
+                  !! air-sea fluxes are calculated by atmospheric chemitry model
+                  !! from atm and oc-surface concentrations.
+                  !!
+                  !! AXY (13/03/15): this is amended to calculate all of the DMS
+                  !!                 estimates examined during UKESM1 (see comments
+                  !!                 in trcdms_medusa.F90)
+                  !!
+                  IF (jdms .eq. 1) THEN
+                  !!
+                     !! CALL trc_dms_medusa( zchn, zchd, hmld(ji,jj), &                            !! inputs
+                     !! dms_surf )                                                                 !! outputs
+                     CALL trc_dms_medusa( zchn, zchd, hmld(ji,jj), qsr(ji,jj), zdin, &             !! inputs
+                     dms_surf, dms_andr, dms_simo, dms_aran, dms_hall )                            !! outputs
+                  ENDIF
+                  !! End DMS Loop
+               endif
+               !! End jk = 1 loop within ROAM key 
+# endif
+
+               if ( jk .eq. 1 ) then
+                  !!----------------------------------------------------------------------
+                  !! River inputs
+                  !!----------------------------------------------------------------------
+                  !!
+                  !! runoff comes in as        kg / m2 / s
+                  !! used and written out as   m3 / m2 / d (= m / d)
+                  !! where                     1000 kg / m2 / d = 1 m3 / m2 / d = 1 m / d
+                  !!
+                  !! AXY (17/07/14): the compiler doesn't like this line for some reason;
+                  !!                 as MEDUSA doesn't even use runoff for riverine inputs,
+                  !!                 a temporary solution is to switch off runoff entirely
+                  !!                 here; again, this change is one of several that will 
+                  !!                 need revisiting once MEDUSA has bedded down in UKESM1;
+                  !!                 particularly so if the land scheme provides information
+                  !!                 concerning nutrient fluxes
+                  !!
+                  !! f_runoff(ji,jj) = sf_rnf(1)%fnow(ji,jj,1) / 1000. * 60. * 60. * 24.
+                  f_runoff(ji,jj) = 0.0
+                  !!
+                  !! nutrients are added via rivers to the model in one of two ways:
+                  !!   1. via river concentration; i.e. the average nutrient concentration
+                  !!      of a river water is described by a spatial file, and this is
+                  !!      multiplied by runoff to give a nutrient flux
+                  !!   2. via direct river flux; i.e. the average nutrient flux due to
+                  !!      rivers is described by a spatial file, and this is simply applied
+                  !!      as a direct nutrient flux (i.e. it does not relate or respond to
+                  !!      model runoff)
+                  !! nutrient fields are derived from the GlobalNEWS 2 database; carbon and
+                  !! alkalinity are derived from continent-scale DIC estimates (Huang et al., 
+                  !! 2012) and some Arctic river alkalinity estimates (Katya?)
+                  !!      
+                  !! as of 19/07/12, riverine nutrients can now be spread vertically across 
+                  !! several grid cells rather than just poured into the surface box; this
+                  !! block of code is still executed, however, to set up the total amounts
+                  !! of nutrient entering via rivers
+                  !!
+                  !! nitrogen
+                  if (jriver_n .eq. 1) then
+                     !! river concentration specified; use runoff to calculate input
+                     f_riv_n(ji,jj) = f_runoff(ji,jj) * riv_n(ji,jj)
+                  elseif (jriver_n .eq. 2) then
+                     !! river flux specified; independent of runoff
+                     f_riv_n(ji,jj) = riv_n(ji,jj)
+                  endif
+                  !!
+                  !! silicon
+                  if (jriver_si .eq. 1) then
+                     !! river concentration specified; use runoff to calculate input
+                     f_riv_si(ji,jj) = f_runoff(ji,jj) * riv_si(ji,jj)
+                  elseif (jriver_si .eq. 2) then
+                     !! river flux specified; independent of runoff
+                     f_riv_si(ji,jj) = riv_si(ji,jj)
+                  endif
+                  !!
+                  !! carbon
+                  if (jriver_c .eq. 1) then
+                     !! river concentration specified; use runoff to calculate input
+                     f_riv_c(ji,jj) = f_runoff(ji,jj) * riv_c(ji,jj)
+                  elseif (jriver_c .eq. 2) then
+                     !! river flux specified; independent of runoff
+                     f_riv_c(ji,jj) = riv_c(ji,jj)
+                  endif
+                  !!
+                  !! alkalinity
+                  if (jriver_alk .eq. 1) then
+                     !! river concentration specified; use runoff to calculate input
+                     f_riv_alk(ji,jj) = f_runoff(ji,jj) * riv_alk(ji,jj)
+                  elseif (jriver_alk .eq. 2) then
+                     !! river flux specified; independent of runoff
+                     f_riv_alk(ji,jj) = riv_alk(ji,jj)
+                  endif
+
+               endif
+
+               !!----------------------------------------------------------------------
+               !! Chlorophyll calculations
+               !!----------------------------------------------------------------------
+               !!
+               !! non-diatoms
+	       if (zphn.GT.rsmall) then
+                  fthetan = max(tiny(zchn), (zchn * xxi) / (zphn + tiny(zphn)))
+                  faln    = xaln * fthetan
+               else
+                  fthetan = 0.
+                  faln    = 0.
+               endif
+               !!
+               !! diatoms
+	       if (zphd.GT.rsmall) then
+                  fthetad = max(tiny(zchd), (zchd * xxi) / (zphd + tiny(zphd)))
+                  fald    = xald * fthetad
+               else
+                  fthetad = 0.
+                  fald    = 0.
+               endif
+
+# if defined key_debug_medusa
+               !! report biological calculations
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'faln(',jk,') = ', faln
+                  IF (lwp) write (numout,*) 'fald(',jk,') = ', fald
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Phytoplankton light limitation
+               !!----------------------------------------------------------------------
+               !!
+               !! It is assumed xpar is the depth-averaged (vertical layer) PAR 
+               !! Light limitation (check self-shading) in W/m2
+               !!
+               !! Note that there is no temperature dependence in phytoplankton
+               !! growth rate or any other function. 
+               !! In calculation of Chl/Phy ratio tiny(phyto) is introduced to avoid
+               !! NaNs in case of Phy==0.  
+               !!
+               !! fthetad and fthetan are Chl:C ratio (gChl/gC) in diat and non-diat: 
+               !! for 1:1 Chl:P ratio (mgChl/mmolN) theta=0.012
+               !!
+               !! AXY (16/07/09)
+               !! temperature for new Eppley style phytoplankton growth
+               loc_T   = tsn(ji,jj,jk,jp_tem)
+               fun_T   = 1.066**(1.0 * loc_T)
+               if (jphy.eq.1) then
+                  xvpnT = xvpn * fun_T
+                  xvpdT = xvpd * fun_T
+               else
+                  xvpnT = xvpn
+                  xvpdT = xvpd
+               endif
+               !!
+               !! non-diatoms
+               fchn1   = (xvpnT * xvpnT) + (faln * faln * xpar(ji,jj,jk) * xpar(ji,jj,jk))
+               if (fchn1.GT.rsmall) then
+                  fchn    = xvpnT / (sqrt(fchn1) + tiny(fchn1))
+               else
+                  fchn    = 0.
+               endif
+               fjln    = fchn * faln * xpar(ji,jj,jk) !! non-diatom J term
+               !!
+               !! diatoms
+               fchd1   = (xvpdT * xvpdT) + (fald * fald * xpar(ji,jj,jk) * xpar(ji,jj,jk))
+               if (fchd1.GT.rsmall) then
+                  fchd    = xvpdT / (sqrt(fchd1) + tiny(fchd1))
+               else
+                  fchd    = 0.
+               endif
+               fjld    = fchd * fald * xpar(ji,jj,jk) !! diatom J term
+      
+# if defined key_debug_medusa
+               !! report phytoplankton light limitation
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fchn(',jk,') = ', fchn
+                  IF (lwp) write (numout,*) 'fchd(',jk,') = ', fchd
+                  IF (lwp) write (numout,*) 'fjln(',jk,') = ', fjln
+                  IF (lwp) write (numout,*) 'fjld(',jk,') = ', fjld
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Phytoplankton nutrient limitation
+               !!----------------------------------------------------------------------
+               !!
+               !! non-diatoms (N, Fe)
+               fnln = zdin / (zdin + xnln) !! non-diatom Qn term
+               ffln = zfer / (zfer + xfln) !! non-diatom Qf term
+               !!
+               !! diatoms (N, Si, Fe)
+               fnld = zdin / (zdin + xnld) !! diatom Qn term
+               fsld = zsil / (zsil + xsld) !! diatom Qs term
+               ffld = zfer / (zfer + xfld) !! diatom Qf term
+
+# if defined key_debug_medusa
+               !! report phytoplankton nutrient limitation
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fnln(',jk,') = ', fnln
+                  IF (lwp) write (numout,*) 'fnld(',jk,') = ', fnld
+                  IF (lwp) write (numout,*) 'ffln(',jk,') = ', ffln
+                  IF (lwp) write (numout,*) 'ffld(',jk,') = ', ffld
+                  IF (lwp) write (numout,*) 'fsld(',jk,') = ', fsld
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Primary production (non-diatoms)
+               !! (note: still needs multiplying by phytoplankton concentration)
+               !!----------------------------------------------------------------------
+               !!
+               if (jliebig .eq. 0) then
+                  !! multiplicative nutrient limitation
+                  fpnlim = fnln * ffln
+               elseif (jliebig .eq. 1) then
+                  !! Liebig Law (= most limiting) nutrient limitation
+                  fpnlim = min(fnln, ffln)
+               endif
+               fprn = fjln * fpnlim
+
+               !!----------------------------------------------------------------------
+               !! Primary production (diatoms)
+               !! (note: still needs multiplying by phytoplankton concentration)
+               !!
+               !! production here is split between nitrogen production and that of
+               !! silicon; depending upon the "intracellular" ratio of Si:N, model
+               !! diatoms will uptake nitrogen/silicon differentially; this borrows
+               !! from the diatom model of Mongin et al. (2006)
+               !!----------------------------------------------------------------------
+               !!
+               if (jliebig .eq. 0) then
+                  !! multiplicative nutrient limitation
+                  fpdlim = fnld * ffld
+               elseif (jliebig .eq. 1) then
+                  !! Liebig Law (= most limiting) nutrient limitation
+                  fpdlim = min(fnld, ffld)
+               endif
+               !!
+	       if (zphd.GT.rsmall .AND. zpds.GT.rsmall) then
+                  !! "intracellular" elemental ratios
+                  ! fsin  = zpds / (zphd + tiny(zphd))
+                  ! fnsi  = zphd / (zpds + tiny(zpds))
+                  fsin = 0.0
+                  IF( zphd .GT. rsmall) fsin  = zpds / zphd
+                  fnsi = 0.0
+                  IF( zpds .GT. rsmall) fnsi  = zphd / zpds
+                  !! AXY (23/02/10): these next variables derive from Mongin et al. (2003)
+                  fsin1 = 3.0 * xsin0 !! = 0.6
+                  fnsi1 = 1.0 / fsin1 !! = 1.667
+                  fnsi2 = 1.0 / xsin0 !! = 5.0
+                  !!
+                  !! conditionalities based on ratios
+                  !! nitrogen (and iron and carbon)
+                  if (fsin.le.xsin0) then
+                     fprd  = 0.0
+                     fsld2 = 0.0
+                  elseif (fsin.lt.fsin1) then
+                     fprd  = xuif * ((fsin - xsin0) / (fsin + tiny(fsin))) * (fjld * fpdlim)
+                     fsld2 = xuif * ((fsin - xsin0) / (fsin + tiny(fsin)))
+                  elseif (fsin.ge.fsin1) then
+                     fprd  = (fjld * fpdlim)
+                     fsld2 = 1.0
+                  endif
+                  !!
+                  !! silicon
+                  if (fsin.lt.fnsi1) then
+                     fprds = (fjld * fsld)
+                  elseif (fsin.lt.fnsi2) then
+                     fprds = xuif * ((fnsi - xnsi0) / (fnsi + tiny(fnsi))) * (fjld * fsld)
+                  else
+                     fprds = 0.0
+                  endif     
+               else
+                  fsin  = 0.0
+                  fnsi  = 0.0
+                  fprd  = 0.0
+                  fsld2 = 0.0
+                  fprds = 0.0
+               endif
+
+# if defined key_debug_medusa
+               !! report phytoplankton growth (including diatom silicon submodel)
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fsin(',jk,')   = ', fsin
+                  IF (lwp) write (numout,*) 'fnsi(',jk,')   = ', fnsi
+                  IF (lwp) write (numout,*) 'fsld2(',jk,')  = ', fsld2
+                  IF (lwp) write (numout,*) 'fprn(',jk,')   = ', fprn
+                  IF (lwp) write (numout,*) 'fprd(',jk,')   = ', fprd
+                  IF (lwp) write (numout,*) 'fprds(',jk,')  = ', fprds
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Mixed layer primary production
+               !! this block calculates the amount of primary production that occurs
+               !! within the upper mixed layer; this allows the separate diagnosis
+               !! of "sub-surface" primary production; it does assume that short-
+               !! term variability in mixed layer depth doesn't mess with things
+               !! though
+               !!----------------------------------------------------------------------
+               !!
+               if (fdep1.le.hmld(ji,jj)) then
+                  !! this level is entirely in the mixed layer
+                  fq0 = 1.0
+               elseif (fdep.ge.hmld(ji,jj)) then
+                  !! this level is entirely below the mixed layer
+                  fq0 = 0.0
+               else
+                  !! this level straddles the mixed layer
+                  fq0 = (hmld(ji,jj) - fdep) / fthk
+               endif
+               !!
+               fprn_ml = (fprn * zphn * fthk * fq0)
+               fprd_ml = (fprd * zphd * fthk * fq0)
+
+               !!----------------------------------------------------------------------
+               !! More chlorophyll calculations
+               !!----------------------------------------------------------------------
+               !!
+               !! frn = (xthetam / fthetan) * (fprn / (fthetan * xpar(ji,jj,jk)))
+               !! frd = (xthetam / fthetad) * (fprd / (fthetad * xpar(ji,jj,jk)))
+               frn = (xthetam * fchn * fnln * ffln       ) / (fthetan + tiny(fthetan))
+               !! AXY (12/05/09): there's potentially a problem here; fsld, silicic acid 
+               !!   limitation, is used in the following line to regulate chlorophyll 
+               !!   growth in a manner that is inconsistent with its use in the regulation 
+               !!   of biomass growth; the Mongin term term used in growth is more complex
+               !!   than the simple multiplicative function used below
+               !! frd = (xthetam * fchd * fnld * ffld * fsld) / (fthetad + tiny(fthetad))
+               !! AXY (12/05/09): this replacement line uses the new variable, fsld2, to
+               !!   regulate chlorophyll growth
+               frd = (xthetamd * fchd * fnld * ffld * fsld2) / (fthetad + tiny(fthetad))
+
+# if defined key_debug_medusa
+               !! report chlorophyll calculations
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fthetan(',jk,') = ', fthetan
+                  IF (lwp) write (numout,*) 'fthetad(',jk,') = ', fthetad
+                  IF (lwp) write (numout,*) 'frn(',jk,')     = ', frn
+                  IF (lwp) write (numout,*) 'frd(',jk,')     = ', frd
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Zooplankton Grazing 
+               !! this code supplements the base grazing model with one that
+               !! considers the C:N ratio of grazed food and balances this against
+               !! the requirements of zooplankton growth; this model is derived 
+               !! from that of Anderson & Pondaven (2003)
+               !!
+               !! the current version of the code assumes a fixed C:N ratio for
+               !! detritus (in contrast to Anderson & Pondaven, 2003), though the
+               !! full equations are retained for future extension
+               !!----------------------------------------------------------------------
+               !!
+               !!----------------------------------------------------------------------
+               !! Microzooplankton first
+               !!----------------------------------------------------------------------
+               !!
+               fmi1    = (xkmi * xkmi) + (xpmipn * zphn * zphn) + (xpmid * zdet * zdet)
+               fmi     = xgmi * zzmi / fmi1
+               fgmipn  = fmi * xpmipn * zphn * zphn   !! grazing on non-diatoms
+               fgmid   = fmi * xpmid  * zdet * zdet   !! grazing on detrital nitrogen
+# if defined key_roam
+               fgmidc  = rsmall !acc
+               IF ( zdet .GT. rsmall ) fgmidc  = (zdtc / (zdet + tiny(zdet))) * fgmid  !! grazing on detrital carbon
+# else
+               !! AXY (26/11/08): implicit detrital carbon change
+               fgmidc  = xthetad * fgmid              !! grazing on detrital carbon
+# endif
+               !!
+               !! which translates to these incoming N and C fluxes
+               finmi   = (1.0 - xphi) * (fgmipn + fgmid)
+               ficmi   = (1.0 - xphi) * ((xthetapn * fgmipn) + fgmidc)
+               !!
+               !! the ideal food C:N ratio for microzooplankton
+               !! xbetan = 0.77; xthetaz = 5.625; xbetac = 0.64; xkc = 0.80
+               fstarmi = (xbetan * xthetazmi) / (xbetac * xkc)
+               !!
+               !! process these to determine proportioning of grazed N and C
+               !! (since there is no explicit consideration of respiration,
+               !! only growth and excretion are calculated here)
+               fmith   = (ficmi / (finmi + tiny(finmi)))
+               if (fmith.ge.fstarmi) then
+                  fmigrow = xbetan * finmi
+                  fmiexcr = 0.0
+               else
+                  fmigrow = (xbetac * xkc * ficmi) / xthetazmi
+                  fmiexcr = ficmi * ((xbetan / (fmith + tiny(fmith))) - ((xbetac * xkc) / xthetazmi))
+               endif
+# if defined key_roam
+               fmiresp = (xbetac * ficmi) - (xthetazmi * fmigrow)
+# endif
+
+# if defined key_debug_medusa
+               !! report microzooplankton grazing
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fmi1(',jk,')    = ', fmi1
+                  IF (lwp) write (numout,*) 'fmi(',jk,')     = ', fmi
+                  IF (lwp) write (numout,*) 'fgmipn(',jk,')  = ', fgmipn
+                  IF (lwp) write (numout,*) 'fgmid(',jk,')   = ', fgmid
+                  IF (lwp) write (numout,*) 'fgmidc(',jk,')  = ', fgmidc
+                  IF (lwp) write (numout,*) 'finmi(',jk,')   = ', finmi
+                  IF (lwp) write (numout,*) 'ficmi(',jk,')   = ', ficmi
+                  IF (lwp) write (numout,*) 'fstarmi(',jk,') = ', fstarmi
+                  IF (lwp) write (numout,*) 'fmith(',jk,')   = ', fmith
+                  IF (lwp) write (numout,*) 'fmigrow(',jk,') = ', fmigrow
+                  IF (lwp) write (numout,*) 'fmiexcr(',jk,') = ', fmiexcr
+#  if defined key_roam
+                  IF (lwp) write (numout,*) 'fmiresp(',jk,') = ', fmiresp
+#  endif
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Mesozooplankton second
+               !!----------------------------------------------------------------------
+               !!
+               fme1    = (xkme * xkme) + (xpmepn * zphn * zphn) + (xpmepd * zphd * zphd) + & 
+                         (xpmezmi * zzmi * zzmi) + (xpmed * zdet * zdet)
+               fme     = xgme * zzme / fme1
+               fgmepn  = fme * xpmepn  * zphn * zphn  !! grazing on non-diatoms
+               fgmepd  = fme * xpmepd  * zphd * zphd  !! grazing on diatoms
+               fgmepds = fsin * fgmepd                !! grazing on diatom silicon
+               fgmezmi = fme * xpmezmi * zzmi * zzmi  !! grazing on microzooplankton
+               fgmed   = fme * xpmed   * zdet * zdet  !! grazing on detrital nitrogen
+# if defined key_roam
+               fgmedc  = rsmall !acc
+               IF ( zdet .GT. rsmall ) fgmedc  = (zdtc / (zdet + tiny(zdet))) * fgmed  !! grazing on detrital carbon
+# else
+               !! AXY (26/11/08): implicit detrital carbon change
+               fgmedc  = xthetad * fgmed              !! grazing on detrital carbon
+# endif
+               !!
+               !! which translates to these incoming N and C fluxes
+               finme   = (1.0 - xphi) * (fgmepn + fgmepd + fgmezmi + fgmed)
+               ficme   = (1.0 - xphi) * ((xthetapn * fgmepn) + (xthetapd * fgmepd) + &
+                        (xthetazmi * fgmezmi) + fgmedc)
+               !!
+               !! the ideal food C:N ratio for mesozooplankton
+               !! xbetan = 0.77; xthetaz = 5.625; xbetac = 0.64; xkc = 0.80
+               fstarme = (xbetan * xthetazme) / (xbetac * xkc)
+               !!
+               !! process these to determine proportioning of grazed N and C
+               !! (since there is no explicit consideration of respiration,
+               !! only growth and excretion are calculated here)
+               fmeth   = (ficme / (finme + tiny(finme)))
+               if (fmeth.ge.fstarme) then
+                  fmegrow = xbetan * finme
+                  fmeexcr = 0.0
+               else
+                  fmegrow = (xbetac * xkc * ficme) / xthetazme
+                  fmeexcr = ficme * ((xbetan / (fmeth + tiny(fmeth))) - ((xbetac * xkc) / xthetazme))
+               endif
+# if defined key_roam
+               fmeresp = (xbetac * ficme) - (xthetazme * fmegrow)
+# endif
+
+# if defined key_debug_medusa
+               !! report mesozooplankton grazing
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fme1(',jk,')    = ', fme1
+                  IF (lwp) write (numout,*) 'fme(',jk,')     = ', fme
+                  IF (lwp) write (numout,*) 'fgmepn(',jk,')  = ', fgmepn
+                  IF (lwp) write (numout,*) 'fgmepd(',jk,')  = ', fgmepd
+                  IF (lwp) write (numout,*) 'fgmepds(',jk,') = ', fgmepds
+                  IF (lwp) write (numout,*) 'fgmezmi(',jk,') = ', fgmezmi
+                  IF (lwp) write (numout,*) 'fgmed(',jk,')   = ', fgmed
+                  IF (lwp) write (numout,*) 'fgmedc(',jk,')  = ', fgmedc
+                  IF (lwp) write (numout,*) 'finme(',jk,')   = ', finme
+                  IF (lwp) write (numout,*) 'ficme(',jk,')   = ', ficme
+                  IF (lwp) write (numout,*) 'fstarme(',jk,') = ', fstarme
+                  IF (lwp) write (numout,*) 'fmeth(',jk,')   = ', fmeth
+                  IF (lwp) write (numout,*) 'fmegrow(',jk,') = ', fmegrow
+                  IF (lwp) write (numout,*) 'fmeexcr(',jk,') = ', fmeexcr
+#  if defined key_roam
+                  IF (lwp) write (numout,*) 'fmeresp(',jk,') = ', fmeresp
+#  endif
+               endif
+# endif
+
+               fzmi_i(ji,jj)  = fzmi_i(ji,jj)  + fthk * (  &
+                  fgmipn + fgmid )
+               fzmi_o(ji,jj)  = fzmi_o(ji,jj)  + fthk * (  &
+                  fmigrow + (xphi * (fgmipn + fgmid)) + fmiexcr + ((1.0 - xbetan) * finmi) )
+               fzme_i(ji,jj)  = fzme_i(ji,jj)  + fthk * (  &
+                  fgmepn + fgmepd + fgmezmi + fgmed )
+               fzme_o(ji,jj)  = fzme_o(ji,jj)  + fthk * (  &
+                  fmegrow + (xphi * (fgmepn + fgmepd + fgmezmi + fgmed)) + fmeexcr + ((1.0 - xbetan) * finme) )
+
+               !!----------------------------------------------------------------------
+               !! Plankton metabolic losses
+               !! Linear loss processes assumed to be metabolic in origin
+               !!----------------------------------------------------------------------
+               !!
+               fdpn2  = xmetapn  * zphn
+               fdpd2  = xmetapd  * zphd
+               fdpds2 = xmetapd  * zpds
+               fdzmi2 = xmetazmi * zzmi
+               fdzme2 = xmetazme * zzme
+
+               !!----------------------------------------------------------------------
+               !! Plankton mortality losses
+               !! EKP (26/02/09): phytoplankton hyperbolic mortality term introduced 
+               !! to improve performance in gyres
+               !!----------------------------------------------------------------------
+               !!
+               !! non-diatom phytoplankton
+               if (jmpn.eq.1) fdpn = xmpn * zphn               !! linear
+               if (jmpn.eq.2) fdpn = xmpn * zphn * zphn        !! quadratic
+               if (jmpn.eq.3) fdpn = xmpn * zphn * &           !! hyperbolic
+                  (zphn / (xkphn + zphn))
+               if (jmpn.eq.4) fdpn = xmpn * zphn * &           !! sigmoid
+                  ((zphn * zphn) / (xkphn + (zphn * zphn)))
+               !!
+               !! diatom phytoplankton
+               if (jmpd.eq.1) fdpd = xmpd * zphd               !! linear
+               if (jmpd.eq.2) fdpd = xmpd * zphd * zphd        !! quadratic
+               if (jmpd.eq.3) fdpd = xmpd * zphd * &           !! hyperbolic
+                  (zphd / (xkphd + zphd))
+               if (jmpd.eq.4) fdpd = xmpd * zphd * &           !! sigmoid
+                  ((zphd * zphd) / (xkphd + (zphd * zphd)))
+               fdpds = fdpd * fsin
+               !!
+               !! microzooplankton
+               if (jmzmi.eq.1) fdzmi = xmzmi * zzmi            !! linear
+               if (jmzmi.eq.2) fdzmi = xmzmi * zzmi * zzmi     !! quadratic
+               if (jmzmi.eq.3) fdzmi = xmzmi * zzmi * &        !! hyperbolic
+                  (zzmi / (xkzmi + zzmi))
+               if (jmzmi.eq.4) fdzmi = xmzmi * zzmi * &        !! sigmoid
+                  ((zzmi * zzmi) / (xkzmi + (zzmi * zzmi)))
+               !!
+               !! mesozooplankton
+               if (jmzme.eq.1) fdzme = xmzme * zzme            !! linear
+               if (jmzme.eq.2) fdzme = xmzme * zzme * zzme     !! quadratic
+               if (jmzme.eq.3) fdzme = xmzme * zzme * &        !! hyperbolic
+                  (zzme / (xkzme + zzme))
+               if (jmzme.eq.4) fdzme = xmzme * zzme * &        !! sigmoid
+                  ((zzme * zzme) / (xkzme + (zzme * zzme)))
+
+               !!----------------------------------------------------------------------
+               !! Detritus remineralisation
+               !! Constant or temperature-dependent
+               !!----------------------------------------------------------------------
+               !!
+               if (jmd.eq.1) then
+                  !! temperature-dependent
+                  fdd  = xmd  * fun_T * zdet
+# if defined key_roam
+                  fddc = xmdc * fun_T * zdtc
+# endif
+               else
+                  !! temperature-independent
+                  fdd  = xmd  * zdet
+# if defined key_roam
+                  fddc = xmdc * zdtc
+# endif
+               endif
+               !!
+               !! AXY (22/07/09): accelerate detrital remineralisation in the bottom box
+               if (jk.eq.(mbathy(ji,jj)-1) .and. jsfd.eq.1) then
+                  fdd  = 1.0  * zdet
+# if defined key_roam
+                  fddc = 1.0  * zdtc
+# endif
+               endif
+               
+# if defined key_debug_medusa
+               !! report plankton mortality and remineralisation
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fdpn2(',jk,') = ', fdpn2
+                  IF (lwp) write (numout,*) 'fdpd2(',jk,') = ', fdpd2
+                  IF (lwp) write (numout,*) 'fdpds2(',jk,')= ', fdpds2
+                  IF (lwp) write (numout,*) 'fdzmi2(',jk,')= ', fdzmi2
+                  IF (lwp) write (numout,*) 'fdzme2(',jk,')= ', fdzme2
+                  IF (lwp) write (numout,*) 'fdpn(',jk,')  = ', fdpn
+                  IF (lwp) write (numout,*) 'fdpd(',jk,')  = ', fdpd
+                  IF (lwp) write (numout,*) 'fdpds(',jk,') = ', fdpds
+                  IF (lwp) write (numout,*) 'fdzmi(',jk,') = ', fdzmi
+                  IF (lwp) write (numout,*) 'fdzme(',jk,') = ', fdzme
+                  IF (lwp) write (numout,*) 'fdd(',jk,')   = ', fdd
+#  if defined key_roam
+                  IF (lwp) write (numout,*) 'fddc(',jk,')  = ', fddc
+#  endif
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Detritus addition to benthos
+               !! If activated, slow detritus in the bottom box will enter the
+               !! benthic pool
+               !!----------------------------------------------------------------------
+               !!
+               if (jk.eq.(mbathy(ji,jj)-1) .and. jorgben.eq.1) then
+                  !! this is the BOTTOM OCEAN BOX -> into the benthic pool!
+                  !!
+                  f_sbenin_n(ji,jj)  = (zdet * vsed * 86400.)
+                  f_sbenin_fe(ji,jj) = (zdet * vsed * 86400. * xrfn)
+# if defined key_roam
+                  f_sbenin_c(ji,jj)  = (zdtc * vsed * 86400.)
+# else
+                  f_sbenin_c(ji,jj)  = (zdet * vsed * 86400. * xthetad)
+# endif
+               endif
+
+               !!----------------------------------------------------------------------
+               !! Iron chemistry and fractionation
+               !! following the Parekh et al. (2004) scheme adopted by the Met.
+               !! Office, Medusa models total iron but considers "free" and
+               !! ligand-bound forms for the purposes of scavenging (only "free"
+               !! iron can be scavenged
+               !!----------------------------------------------------------------------
+               !!
+               !! total iron concentration (mmol Fe / m3 -> umol Fe / m3)
+               xFeT        = zfer * 1.e3
+               !!
+               !! calculate fractionation (based on Diat-HadOCC; in turn based on Parekh et al., 2004)
+               xb_coef_tmp = xk_FeL * (xLgT - xFeT) - 1.0
+               xb2M4ac     = max(((xb_coef_tmp * xb_coef_tmp) + (4.0 * xk_FeL * xLgT)), 0.0)
+               !!
+               !! "free" ligand concentration
+               xLgF        = 0.5 * (xb_coef_tmp + (xb2M4ac**0.5)) / xk_FeL
+               !!
+               !! ligand-bound iron concentration
+               xFeL        = xLgT - xLgF
+               !!
+               !! "free" iron concentration (and convert to mmol Fe / m3)
+               xFeF        = (xFeT - xFeL) * 1.e-3
+               xFree       = xFeF / (zfer + tiny(zfer))
+               !!
+               !! scavenging of iron (multiple schemes); I'm only really happy with the 
+               !! first one at the moment - the others involve assumptions (sometimes
+               !! guessed at by me) that are potentially questionable
+               !!
+               if (jiron.eq.1) then
+                  !!----------------------------------------------------------------------
+                  !! Scheme 1: Dutkiewicz et al. (2005)
+                  !! This scheme includes a single scavenging term based solely on a
+                  !! fixed rate and the availablility of "free" iron
+                  !!----------------------------------------------------------------------
+                  !!
+                  ffescav     = xk_sc_Fe * xFeF                     ! = mmol/m3/d
+                  !!
+                  !!----------------------------------------------------------------------
+                  !!
+                  !! Mick's code contains a further (optional) implicit "scavenging" of 
+                  !! iron that sets an upper bound on "free" iron concentration, and 
+                  !! essentially caps the concentration of total iron as xFeL + "free" 
+                  !! iron; since the former is constrained by a fixed total ligand 
+                  !! concentration (= 1.0 umol/m3), and the latter isn't allowed above 
+                  !! this upper bound, total iron is constrained to a maximum of ...
+                  !!
+                  !!    xFeL + min(xFeF, 0.3 umol/m3) = 1.0 + 0.3 = 1.3 umol / m3
+                  !! 
+                  !! In Mick's code, the actual value of total iron is reset to this
+                  !! sum (i.e. TFe = FeL + Fe'; but Fe' <= 0.3 umol/m3); this isn't
+                  !! our favoured approach to tracer updating here (not least because
+                  !! of the leapfrog), so here the amount scavenged is augmented by an
+                  !! additional amount that serves to drag total iron back towards that
+                  !! expected from this limitation on iron concentration ...
+                  !!
+                  xmaxFeF     = min((xFeF * 1.e3), 0.3)             ! = umol/m3
+                  !!
+                  !! Here, the difference between current total Fe and (FeL + Fe') is
+                  !! calculated and added to the scavenging flux already calculated
+                  !! above ...
+                  !!
+                  fdeltaFe    = (xFeT - (xFeL + xmaxFeF)) * 1.e-3   ! = mmol/m3
+                  !!
+                  !! This assumes that the "excess" iron is dissipated with a time-
+                  !! scale of 1 day; seems reasonable to me ... (famous last words)
+                  !!
+                  ffescav     = ffescav + fdeltaFe                  ! = mmol/m3/d
+                  !!
+# if defined key_deep_fe_fix
+                  !! AXY (17/01/13)
+                  !! stop scavenging for iron concentrations below 0.5 umol / m3
+                  !! at depths greater than 1000 m; this aims to end MEDUSA's
+                  !! continual loss of iron at depth without impacting things
+                  !! at the surface too much; the justification for this is that
+                  !! it appears to be what Mick Follows et al. do in their work
+                  !! (as evidenced by the iron initial condition they supplied
+                  !! me with); to be honest, it looks like Follow et al. do this
+                  !! at shallower depths than 1000 m, but I'll stick with this
+                  !! for now; I suspect that this seemingly arbitrary approach
+                  !! effectively "parameterises" the particle-based scavenging
+                  !! rates that other models use (i.e. at depth there are no
+                  !! sinking particles, so scavenging stops); it might be fun
+                  !! justifying this in a paper though!
+                  !!
+                  if ((fdep.gt.1000.) .and. (xFeT.lt.0.5)) then
+                     ffescav = 0.
+                  endif
+# endif
+                  !!
+               elseif (jiron.eq.2) then
+                  !!----------------------------------------------------------------------
+                  !! Scheme 2: Moore et al. (2004)
+                  !! This scheme includes a single scavenging term that accounts for
+                  !! both suspended and sinking particles in the water column; this
+                  !! term scavenges total iron rather than "free" iron
+                  !!----------------------------------------------------------------------
+                  !!
+                  !! total iron concentration (mmol Fe / m3 -> umol Fe / m3)
+                  xFeT        = zfer * 1.e3
+                  !!
+                  !! this has a base scavenging rate (12% / y) which is modified by local
+                  !! particle concentration and sinking flux (and dust - but I'm ignoring
+                  !! that here for now) and which is accelerated when Fe concentration gets
+                  !! 0.6 nM (= 0.6 umol/m3 = 0.0006 mmol/m3), and decreased as concentrations
+                  !! below 0.4 nM (= 0.4 umol/m3 = 0.0004 mmol/m3)
+                  !!
+                  !! base scavenging rate (0.12 / y)
+                  fbase_scav = 0.12 / 365.25
+                  !!
+                  !! calculate sinking particle part of scaling factor
+                  !! this takes local fast sinking carbon (mmol C / m2 / d) and
+                  !! gets it into nmol C / cm3 / s ("rdt" below is the number of seconds in
+                  !! a model timestep)
+                  !!
+                  !! fscal_sink = ffastc(ji,jj) * 1.e2 / (86400.)
+                  !!
+                  !! ... actually, re-reading Moore et al.'s equations, it looks like he uses
+                  !! his sinking flux directly, without scaling it by time-step or anything,
+                  !! so I'll copy this here ...
+                  !!
+                  fscal_sink = ffastc(ji,jj) * 1.e2
+                  !!
+                  !! calculate particle part of scaling factor
+                  !! this totals up the carbon in suspended particles (Pn, Pd, Zmi, Zme, D),
+                  !! which comes out in mmol C / m3 (= nmol C / cm3), and then multiplies it
+                  !! by a magic factor, 0.002, to get it into nmol C / cm2 / s
+                  !!
+                  fscal_part = ((xthetapn * zphn) + (xthetapd * zphd) + (xthetazmi * zzmi) + &
+                  (xthetazme * zzme) + (xthetad * zdet)) * 0.002
+                  !!
+                  !! calculate scaling factor for base scavenging rate
+                  !! this uses the (now correctly scaled) sinking flux and standing
+                  !! particle concentration, divides through by some sort of reference
+                  !! value (= 0.0066 nmol C / cm2 / s) and then uses this, or not if its
+                  !! too high, to rescale the base scavenging rate
+                  !!
+                  fscal_scav = fbase_scav * min(((fscal_sink + fscal_part) / 0.0066), 4.0)
+                  !!
+                  !! the resulting scavenging rate is then scaled further according to the
+                  !! local iron concentration (i.e. diminished in low iron regions; enhanced
+                  !! in high iron regions; less alone in intermediate iron regions)
+                  !!
+                  if (xFeT.lt.0.4) then
+                     !!
+                     !! low iron region
+                     !!
+                     fscal_scav = fscal_scav * (xFeT / 0.4)
+                     !!
+                  elseif (xFeT.gt.0.6) then
+                     !!
+                     !! high iron region
+                     !!
+                     fscal_scav = fscal_scav + ((xFeT / 0.6) * (6.0 / 1.4))
+                     !!
+                  else
+                     !!
+                     !! intermediate iron region: do nothing
+                     !!
+                  endif
+                  !! 
+                  !! apply the calculated scavenging rate ...
+                  !!
+                  ffescav = fscal_scav * zfer
+                  !!
+               elseif (jiron.eq.3) then
+                  !!----------------------------------------------------------------------
+                  !! Scheme 3: Moore et al. (2008)
+                  !! This scheme includes a single scavenging term that accounts for
+                  !! sinking particles in the water column, and includes organic C,
+                  !! biogenic opal, calcium carbonate and dust in this (though the
+                  !! latter is ignored here until I work out what units the incoming
+                  !! "dust" flux is in); this term scavenges total iron rather than 
+                  !! "free" iron
+                  !!----------------------------------------------------------------------
+                  !!
+                  !! total iron concentration (mmol Fe / m3 -> umol Fe / m3)
+                  xFeT        = zfer * 1.e3
+                  !!
+                  !! this has a base scavenging rate which is modified by local
+                  !! particle sinking flux (including dust - but I'm ignoring that 
+                  !! here for now) and which is accelerated when Fe concentration
+                  !! is > 0.6 nM (= 0.6 umol/m3 = 0.0006 mmol/m3), and decreased as 
+                  !! concentrations < 0.5 nM (= 0.5 umol/m3 = 0.0005 mmol/m3)
+                  !!
+                  !! base scavenging rate (Fe_b in paper; units may be wrong there)
+                  fbase_scav = 0.00384 ! (ng)^-1 cm
+                  !!
+                  !! calculate sinking particle part of scaling factor; this converts
+                  !! mmol / m2 / d fluxes of organic carbon, silicon and calcium
+                  !! carbonate into ng / cm2 / s fluxes; it is assumed here that the
+                  !! mass conversions simply consider the mass of the main element
+                  !! (C, Si and Ca) and *not* the mass of the molecules that they are
+                  !! part of; Moore et al. (2008) is unclear on the conversion that
+                  !! should be used
+                  !!
+                  !! milli -> nano; mol -> gram; /m2 -> /cm2; /d -> /s
+                  fscal_csink  = (ffastc(ji,jj)  * 1.e6 * xmassc  * 1.e-4 / 86400.)      ! ng C  / cm2 / s
+                  fscal_sisink = (ffastsi(ji,jj) * 1.e6 * xmasssi * 1.e-4 / 86400.)      ! ng Si / cm2 / s
+                  fscal_casink = (ffastca(ji,jj) * 1.e6 * xmassca * 1.e-4 / 86400.)      ! ng Ca / cm2 / s
+                  !! 
+                  !! sum up these sinking fluxes and convert to ng / cm by dividing
+                  !! through by a sinking rate of 100 m / d = 1.157 cm / s
+                  fscal_sink   = ((fscal_csink * 6.) + fscal_sisink + fscal_casink) / &
+                  (100. * 1.e3 / 86400)                                                  ! ng / cm
+                  !!
+                  !! now calculate the scavenging rate based upon the base rate and
+                  !! this particle flux scaling; according to the published units,
+                  !! the result actually has *no* units, but as it must be expressed
+                  !! per unit time for it to make any sense, I'm assuming a missing
+                  !! "per second"
+                  fscal_scav = fbase_scav * fscal_sink                                   ! / s
+                  !!
+                  !! the resulting scavenging rate is then scaled further according to the
+                  !! local iron concentration (i.e. diminished in low iron regions; enhanced
+                  !! in high iron regions; less alone in intermediate iron regions)
+                  !!
+                  if (xFeT.lt.0.5) then
+                     !!
+                     !! low iron region (0.5 instead of the 0.4 in Moore et al., 2004)
+                     !!
+                     fscal_scav = fscal_scav * (xFeT / 0.5)
+                     !!
+                  elseif (xFeT.gt.0.6) then
+                     !!
+                     !! high iron region (functional form different in Moore et al., 2004)
+                     !!
+                     fscal_scav = fscal_scav + ((xFeT - 0.6) * 0.00904)
+                     !!
+                  else
+                     !!
+                     !! intermediate iron region: do nothing
+                     !!
+                  endif
+                  !! 
+                  !! apply the calculated scavenging rate ...
+                  !!
+                  ffescav = fscal_scav * zfer
+                  !!
+               elseif (jiron.eq.4) then
+                  !!----------------------------------------------------------------------
+                  !! Scheme 4: Galbraith et al. (2010)
+                  !! This scheme includes two scavenging terms, one for organic,
+                  !! particle-based scavenging, and another for inorganic scavenging;
+                  !! both terms scavenge "free" iron only
+                  !!----------------------------------------------------------------------
+                  !!
+                  !! Galbraith et al. (2010) present a more straightforward outline of 
+                  !! the scheme in Parekh et al. (2005) ...
+                  !! 
+                  !! sinking particulate carbon available for scavenging
+                  !! this assumes a sinking rate of 100 m / d (Moore & Braucher, 2008),
+                  xCscav1     = (ffastc(ji,jj) * xmassc) / 100. ! = mg C / m3
+                  !! 
+                  !! scale by Honeyman et al. (1981) exponent coefficient
+                  !! multiply by 1.e-3 to express C flux in g C rather than mg C
+                  xCscav2     = (xCscav1 * 1.e-3)**0.58
+                  !!
+                  !! multiply by Galbraith et al. (2010) scavenging rate
+                  xk_org      = 0.5 ! ((g C m/3)^-1) / d
+                  xORGscav    = xk_org * xCscav2 * xFeF
+                  !!
+                  !! Galbraith et al. (2010) also include an inorganic bit ...
+                  !! 
+                  !! this occurs at a fixed rate, again based on the availability of
+                  !! "free" iron
+                  !!
+                  !! k_inorg  = 1000 d**-1 nmol Fe**-0.5 kg**-0.5
+                  !!
+                  !! to implement this here, scale xFeF by 1026 to put in units of
+                  !! umol/m3 which approximately equal nmol/kg
+                  !!
+                  xk_inorg    = 1000. ! ((nmol Fe / kg)^1.5)
+                  xINORGscav  = (xk_inorg * (xFeF * 1026.)**1.5) * 1.e-3
+                  !!
+                  !! sum these two terms together
+                  ffescav     = xORGscav + xINORGscav
+               else
+                  !!----------------------------------------------------------------------
+                  !! No Scheme: you coward!
+                  !! This scheme puts its head in the sand and eskews any decision about
+                  !! how iron is removed from the ocean; prepare to get deluged in iron
+                  !! you fool!
+                  !!----------------------------------------------------------------------
+                  ffescav     = 0.
+               endif
+
+               !!----------------------------------------------------------------------
+               !! Other iron cycle processes
+               !!----------------------------------------------------------------------
+               !!
+               !! aeolian iron deposition
+               if (jk.eq.1) then
+                  !! dust   is in g Fe / m2 / month
+                  !! ffetop is in mmol / m3 / day
+                  ffetop  = (((dust(ji,jj) * 1.e3 * xfe_sol) / xfe_mass) / fthk) / 30.
+               else
+                  ffetop  = 0.0
+               endif
+               !!
+               !! seafloor iron addition
+               !! AXY (10/07/12): amended to only apply sedimentary flux up to ~500 m down
+               !! if (jk.eq.(mbathy(ji,jj)-1).AND.jk.lt.i1100) then
+               if (jk.eq.(mbathy(ji,jj)-1).AND.jk.le.i0500) then
+                  !! Moore et al. (2004) cite a coastal California value of 5 umol/m2/d, but adopt a
+                  !! global value of 2 umol/m2/d for all areas < 1100 m; here we use this latter value
+                  !! but apply it everywhere
+                  !! AXY (21/07/09): actually, let's just apply it below 1100 m (levels 1-37)
+                  ffebot  = (xfe_sed / fthk)
+               else
+                  ffebot  = 0.0
+               endif
+
+               !! AXY (16/12/09): remove iron addition/removal processes
+               !! For the purposes of the quarter degree run, the iron cycle is being pegged to the
+               !! initial condition supplied by Mick Follows via restoration with a 30 day period;
+               !! iron addition at the seafloor is still permitted with the idea that this extra
+               !! iron will be removed by the restoration away from the source
+               !! ffescav = 0.0
+               !! ffetop  = 0.0
+               !! ffebot  = 0.0
+
+# if defined key_debug_medusa
+               !! report miscellaneous calculations
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'xfe_sol  = ', xfe_sol
+                  IF (lwp) write (numout,*) 'xfe_mass = ', xfe_mass
+                  IF (lwp) write (numout,*) 'ffetop(',jk,')  = ', ffetop
+                  IF (lwp) write (numout,*) 'ffebot(',jk,')  = ', ffebot
+                  IF (lwp) write (numout,*) 'xFree(',jk,')   = ', xFree
+                  IF (lwp) write (numout,*) 'ffescav(',jk,') = ', ffescav
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Miscellaneous
+               !!----------------------------------------------------------------------
+               !!
+               !! diatom frustule dissolution
+               fsdiss  = xsdiss * zpds
+
+# if defined key_debug_medusa
+               !! report miscellaneous calculations
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fsdiss(',jk,')  = ', fsdiss
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Slow detritus creation
+               !!----------------------------------------------------------------------
+               !! this variable integrates the creation of slow sinking detritus
+               !! to allow the split between fast and slow detritus to be 
+               !! diagnosed
+               fslown  = fdpn + fdzmi + ((1.0 - xfdfrac1) * fdpd) + &
+               ((1.0 - xfdfrac2) * fdzme) + ((1.0 - xbetan) * (finmi + finme))
+               !!
+               !! this variable records the slow detrital sinking flux at this
+               !! particular depth; it is used in the output of this flux at
+               !! standard depths in the diagnostic outputs; needs to be
+               !! adjusted from per second to per day because of parameter vsed
+               fslownflux = zdet * vsed * 86400.
+# if defined key_roam
+               !!
+               !! and the same for detrital carbon
+               fslowc  = (xthetapn * fdpn) + (xthetazmi * fdzmi) + &
+               (xthetapd * (1.0 - xfdfrac1) * fdpd) + &
+               (xthetazme * (1.0 - xfdfrac2) * fdzme) + &
+               ((1.0 - xbetac) * (ficmi + ficme))
+               !!
+               !! this variable records the slow detrital sinking flux at this
+               !! particular depth; it is used in the output of this flux at
+               !! standard depths in the diagnostic outputs; needs to be
+               !! adjusted from per second to per day because of parameter vsed
+               fslowcflux = zdtc * vsed * 86400.
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Nutrient regeneration
+               !! this variable integrates total nitrogen regeneration down the
+               !! watercolumn; its value is stored and output as a 2D diagnostic;
+               !! the corresponding dissolution flux of silicon (from sources
+               !! other than fast detritus) is also integrated; note that,
+               !! confusingly, the linear loss terms from plankton compartments
+               !! are labelled as fdX2 when one might have expected fdX or fdX1
+               !!----------------------------------------------------------------------
+               !!
+               !! nitrogen
+               fregen   = (( (xphi * (fgmipn + fgmid)) +                &  ! messy feeding
+               (xphi * (fgmepn + fgmepd + fgmezmi + fgmed)) +           &  ! messy feeding
+               fmiexcr + fmeexcr + fdd +                                &  ! excretion + D remin.
+               fdpn2 + fdpd2 + fdzmi2 + fdzme2) * fthk)                    ! linear mortality
+               !!
+               !! silicon
+               fregensi = (( fsdiss + ((1.0 - xfdfrac1) * fdpds) +      &  ! dissolution + non-lin. mortality
+               ((1.0 - xfdfrac3) * fgmepds) +                           &  ! egestion by zooplankton
+               fdpds2) * fthk)                                             ! linear mortality
+# if defined key_roam
+               !!
+               !! carbon
+               fregenc  = (( (xphi * ((xthetapn * fgmipn) + fgmidc)) +  &  ! messy feeding
+               (xphi * ((xthetapn * fgmepn) + (xthetapd * fgmepd) +     &  ! messy feeding
+               (xthetazmi * fgmezmi) + fgmedc)) +                       &  ! messy feeding
+               fmiresp + fmeresp + fddc +                               &  ! respiration + D remin.
+               (xthetapn * fdpn2) + (xthetapd * fdpd2) +                &  ! linear mortality
+               (xthetazmi * fdzmi2) + (xthetazme * fdzme2)) * fthk)        ! linear mortality
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Fast-sinking detritus terms
+               !! "local" variables declared so that conservation can be checked;
+               !! the calculated terms are added to the fast-sinking flux later on
+               !! only after the flux entering this level has experienced some
+               !! remineralisation
+               !! note: these fluxes need to be scaled by the level thickness
+               !!----------------------------------------------------------------------
+               !!
+               !! nitrogen:   diatom and mesozooplankton mortality
+               ftempn         = b0 * ((xfdfrac1 * fdpd)  + (xfdfrac2 * fdzme))
+               !!
+               !! silicon:    diatom mortality and grazed diatoms
+               ftempsi        = b0 * ((xfdfrac1 * fdpds) + (xfdfrac3 * fgmepds))
+               !!
+               !! iron:       diatom and mesozooplankton mortality
+               ftempfe        = b0 * (((xfdfrac1 * fdpd) + (xfdfrac2 * fdzme)) * xrfn)
+               !!
+               !! carbon:     diatom and mesozooplankton mortality
+               ftempc         = b0 * ((xfdfrac1 * xthetapd * fdpd) + & 
+                                (xfdfrac2 * xthetazme * fdzme))
+               !!
+# if defined key_roam
+               if (jrratio.eq.0) then
+                  !! CaCO3:      latitudinally-based fraction of total primary production
+                  !!               absolute latitude of current grid cell
+                  flat           = abs(gphit(ji,jj))
+                  !!               0.10 at equator; 0.02 at pole
+                  fcaco3         = xcaco3a + ((xcaco3b - xcaco3a) * ((90.0 - flat) / 90.0))
+               elseif (jrratio.eq.1) then
+                  !! CaCO3:      Ridgwell et al. (2007) submodel, version 1
+                  !!             this uses SURFACE omega calcite to regulate rain ratio
+                  if (f_omcal(ji,jj).ge.1.0) then
+                     fq1 = (f_omcal(ji,jj) - 1.0)**0.81
+                  else
+                     fq1 = 0.
+                  endif
+                  fcaco3 = xridg_r0 * fq1
+               elseif (jrratio.eq.2) then
+                  !! CaCO3:      Ridgwell et al. (2007) submodel, version 2
+                  !!             this uses FULL 3D omega calcite to regulate rain ratio
+                  if (f3_omcal(ji,jj,jk).ge.1.0) then
+                     fq1 = (f3_omcal(ji,jj,jk) - 1.0)**0.81
+                  else
+                     fq1 = 0.
+                  endif
+                  fcaco3 = xridg_r0 * fq1
+               endif
+# else
+               !! CaCO3:      latitudinally-based fraction of total primary production
+               !!               absolute latitude of current grid cell
+               flat           = abs(gphit(ji,jj))
+               !!               0.10 at equator; 0.02 at pole
+               fcaco3         = xcaco3a + ((xcaco3b - xcaco3a) * ((90.0 - flat) / 90.0))
+# endif
+               !! AXY (09/03/09): convert CaCO3 production from function of 
+               !! primary production into a function of fast-sinking material; 
+               !! technically, this is what Dunne et al. (2007) do anyway; they 
+               !! convert total primary production estimated from surface 
+               !! chlorophyll to an export flux for which they apply conversion 
+               !! factors to estimate the various elemental fractions (Si, Ca)
+               ftempca        = ftempc * fcaco3
+
+# if defined key_debug_medusa
+               !! integrate total fast detritus production
+               if (idf.eq.1) then
+                  fifd_n(ji,jj)  = fifd_n(ji,jj)  + (ftempn  * fthk)
+                  fifd_si(ji,jj) = fifd_si(ji,jj) + (ftempsi * fthk)
+                  fifd_fe(ji,jj) = fifd_fe(ji,jj) + (ftempfe * fthk)
+#  if defined key_roam
+                  fifd_c(ji,jj)  = fifd_c(ji,jj)  + (ftempc  * fthk)
+#  endif
+               endif
+
+               !! report quantities of fast-sinking detritus for each component
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fdpd(',jk,')    = ', fdpd
+                  IF (lwp) write (numout,*) 'fdzme(',jk,')   = ', fdzme
+                  IF (lwp) write (numout,*) 'ftempn(',jk,')  = ', ftempn
+                  IF (lwp) write (numout,*) 'ftempsi(',jk,') = ', ftempsi
+                  IF (lwp) write (numout,*) 'ftempfe(',jk,') = ', ftempfe
+                  IF (lwp) write (numout,*) 'ftempc(',jk,')  = ', ftempc
+                  IF (lwp) write (numout,*) 'ftempca(',jk,') = ', ftempca
+                  IF (lwp) write (numout,*) 'flat(',jk,')    = ', flat
+                  IF (lwp) write (numout,*) 'fcaco3(',jk,')  = ', fcaco3
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! This version of MEDUSA offers a choice of three methods for
+               !! handling the remineralisation of fast detritus.  All three
+               !! do so in broadly the same way:
+               !!
+               !!   1.  Fast detritus is stored as a 2D array                   [ ffastX  ]
+               !!   2.  Fast detritus is added level-by-level                   [ ftempX  ]
+               !!   3.  Fast detritus is not remineralised in the top box       [ freminX ]
+               !!   4.  Remaining fast detritus is remineralised in the bottom  [ fsedX   ]
+               !!       box
+               !!
+               !! The three remineralisation methods are:
+               !!   
+               !!   1.  Ballast model (i.e. that published in Yool et al., 2011)
+               !!  (1b. Ballast-sans-ballast model)
+               !!   2.  Martin et al. (1987)
+               !!   3.  Henson et al. (2011)
+               !! 
+               !! The first of these couples C, N and Fe remineralisation to
+               !! the remineralisation of particulate Si and CaCO3, but the 
+               !! latter two treat remineralisation of C, N, Fe, Si and CaCO3
+               !! completely separately.  At present a switch within the code
+               !! regulates which submodel is used, but this should be moved
+               !! to the namelist file.
+               !! 
+               !! The ballast-sans-ballast submodel is an original development
+               !! feature of MEDUSA in which the ballast submodel's general
+               !! framework and parameterisation is used, but in which there
+               !! is no protection of organic material afforded by ballasting
+               !! minerals.  While similar, it is not the same as the Martin 
+               !! et al. (1987) submodel.
+               !!
+               !! Since the three submodels behave the same in terms of
+               !! accumulating sinking material and remineralising it all at
+               !! the seafloor, these portions of the code below are common to
+               !! all three.
+               !!----------------------------------------------------------------------
+
+               if (jexport.eq.1) then
+                  !!======================================================================
+                  !! BALLAST SUBMODEL
+                  !!======================================================================
+                  !! 
+                  !!----------------------------------------------------------------------
+                  !! Fast-sinking detritus fluxes, pt. 1: REMINERALISATION
+                  !! aside from explicitly modelled, slow-sinking detritus, the
+                  !! model includes an implicit representation of detrital
+                  !! particles that sink too quickly to be modelled with
+                  !! explicit state variables; this sinking flux is instead
+                  !! instantaneously remineralised down the water column using
+                  !! the version of Armstrong et al. (2002)'s ballast model
+                  !! used by Dunne et al. (2007); the version of this model
+                  !! here considers silicon and calcium carbonate ballast
+                  !! minerals; this section of the code redistributes the fast
+                  !! sinking material generated locally down the water column;
+                  !! this differs from Dunne et al. (2007) in that fast sinking
+                  !! material is distributed at *every* level below that it is
+                  !! generated, rather than at every level below some fixed
+                  !! depth; this scheme is also different in that sinking material 
+                  !! generated in one level is aggregated with that generated by
+                  !! shallower levels; this should make the ballast model more
+                  !! self-consistent (famous last words)
+                  !!----------------------------------------------------------------------
+                  !!
+                  if (jk.eq.1) then
+                     !! this is the SURFACE OCEAN BOX (no remineralisation)
+                     !!
+                     freminc  = 0.0
+                     freminn  = 0.0
+                     freminfe = 0.0
+                     freminsi = 0.0
+                     freminca = 0.0
+                  elseif (jk.lt.(mbathy(ji,jj))) then
+                     !! this is an OCEAN BOX (remineralise some material)
+                     !!
+                     !! set up CCD depth to be used depending on user choice
+                     if (jocalccd.eq.0) then
+                        !! use default CCD field
+                        fccd_dep = ocal_ccd(ji,jj)
+                     elseif (jocalccd.eq.1) then
+                        !! use calculated CCD field
+                        fccd_dep = f2_ccd_cal(ji,jj)
+                     endif
+                     !!
+                     !! === organic carbon ===
+                     fq0      = ffastc(ji,jj)                        !! how much organic C enters this box        (mol)
+                     if (iball.eq.1) then
+                        fq1      = (fq0 * xmassc)                    !! how much it weighs                        (mass)
+                        fq2      = (ffastca(ji,jj) * xmassca)        !! how much CaCO3 enters this box            (mass)
+                        fq3      = (ffastsi(ji,jj) * xmasssi)        !! how much  opal enters this box            (mass)
+                        fq4      = (fq2 * xprotca) + (fq3 * xprotsi) !! total protected organic C                 (mass)
+                        !! this next term is calculated for C but used for N and Fe as well
+                        !! it needs to be protected in case ALL C is protected
+                        if (fq4.lt.fq1) then
+                           fprotf   = (fq4 / (fq1 + tiny(fq1)))      !! protected fraction of total organic C     (non-dim)
+                        else
+                           fprotf   = 1.0                            !! all organic C is protected                (non-dim)
+                        endif
+                        fq5      = (1.0 - fprotf)                    !! unprotected fraction of total organic C   (non-dim)
+                        fq6      = (fq0 * fq5)                       !! how much organic C is unprotected         (mol)
+                        fq7      = (fq6 * exp(-(fthk / xfastc)))     !! how much unprotected C leaves this box    (mol)
+                        fq8      = (fq7 + (fq0 * fprotf))            !! how much total C leaves this box          (mol)
+                        freminc  = (fq0 - fq8) / fthk                !! C remineralisation in this box            (mol)
+                        ffastc(ji,jj) = fq8                          
+# if defined key_debug_medusa
+                        !! report in/out/remin fluxes of carbon for this level
+                           if (idf.eq.1.AND.idfval.eq.1) then
+                              IF (lwp) write (numout,*) '------------------------------'
+                              IF (lwp) write (numout,*) 'totalC(',jk,')  = ', fq1
+                              IF (lwp) write (numout,*) 'prtctC(',jk,')  = ', fq4
+                              IF (lwp) write (numout,*) 'fprotf(',jk,')  = ', fprotf
+                              IF (lwp) write (numout,*) '------------------------------'
+                              IF (lwp) write (numout,*) 'IN   C(',jk,')  = ', fq0
+                              IF (lwp) write (numout,*) 'LOST C(',jk,')  = ', freminc * fthk
+                              IF (lwp) write (numout,*) 'OUT  C(',jk,')  = ', fq8
+                              IF (lwp) write (numout,*) 'NEW  C(',jk,')  = ', ftempc * fthk
+                           endif
+# endif
+                        else
+                        fq1      = fq0 * exp(-(fthk / xfastc))       !! how much organic C leaves this box        (mol)
+                        freminc  = (fq0 - fq1) / fthk                !! C remineralisation in this box            (mol)
+                        ffastc(ji,jj)  = fq1
+                     endif
+                     !!
+                     !! === organic nitrogen ===
+                     fq0      = ffastn(ji,jj)                        !! how much organic N enters this box        (mol)
+                     if (iball.eq.1) then
+                        fq5      = (1.0 - fprotf)                    !! unprotected fraction of total organic N   (non-dim)
+                        fq6      = (fq0 * fq5)                       !! how much organic N is unprotected         (mol)
+                        fq7      = (fq6 * exp(-(fthk / xfastc)))     !! how much unprotected N leaves this box    (mol)
+                        fq8      = (fq7 + (fq0 * fprotf))            !! how much total N leaves this box          (mol)
+                        freminn  = (fq0 - fq8) / fthk                !! N remineralisation in this box            (mol)
+                        ffastn(ji,jj)  = fq8
+# if defined key_debug_medusa
+                        !! report in/out/remin fluxes of carbon for this level
+                        if (idf.eq.1.AND.idfval.eq.1) then
+                           IF (lwp) write (numout,*) '------------------------------'
+                           IF (lwp) write (numout,*) 'totalN(',jk,')  = ', fq1
+                           IF (lwp) write (numout,*) 'prtctN(',jk,')  = ', fq4
+                           IF (lwp) write (numout,*) 'fprotf(',jk,')  = ', fprotf
+                           IF (lwp) write (numout,*) '------------------------------'
+                           if (freminn < 0.0) then
+                              IF (lwp) write (numout,*) '** FREMIN ERROR **'
+                           endif
+                           IF (lwp) write (numout,*) 'IN   N(',jk,')  = ', fq0
+                           IF (lwp) write (numout,*) 'LOST N(',jk,')  = ', freminn * fthk
+                           IF (lwp) write (numout,*) 'OUT  N(',jk,')  = ', fq8
+                           IF (lwp) write (numout,*) 'NEW  N(',jk,')  = ', ftempn * fthk
+                        endif
+# endif
+                     else
+                        fq1      = fq0 * exp(-(fthk / xfastc))       !! how much organic N leaves this box        (mol)
+                        freminn  = (fq0 - fq1) / fthk                !! N remineralisation in this box            (mol)
+                        ffastn(ji,jj)  = fq1
+                     endif
+                     !!
+                     !! === organic iron ===
+                     fq0      = ffastfe(ji,jj)                       !! how much organic Fe enters this box       (mol)
+                     if (iball.eq.1) then
+                        fq5      = (1.0 - fprotf)                    !! unprotected fraction of total organic Fe  (non-dim)
+                        fq6      = (fq0 * fq5)                       !! how much organic Fe is unprotected        (mol)
+                        fq7      = (fq6 * exp(-(fthk / xfastc)))     !! how much unprotected Fe leaves this box   (mol)
+                        fq8      = (fq7 + (fq0 * fprotf))            !! how much total Fe leaves this box         (mol)            
+                        freminfe = (fq0 - fq8) / fthk                !! Fe remineralisation in this box           (mol)
+                        ffastfe(ji,jj) = fq8
+                     else
+                        fq1      = fq0 * exp(-(fthk / xfastc))       !! how much total Fe leaves this box         (mol)      
+                        freminfe = (fq0 - fq1) / fthk                !! Fe remineralisation in this box           (mol)
+                        ffastfe(ji,jj) = fq1
+                     endif
+                     !!
+                     !! === biogenic silicon ===
+                     fq0      = ffastsi(ji,jj)                       !! how much  opal centers this box           (mol) 
+                     fq1      = fq0 * exp(-(fthk / xfastsi))         !! how much  opal leaves this box            (mol)
+                     freminsi = (fq0 - fq1) / fthk                   !! Si remineralisation in this box           (mol)
+                     ffastsi(ji,jj) = fq1
+                     !!
+                     !! === biogenic calcium carbonate ===
+                     fq0      = ffastca(ji,jj)                       !! how much CaCO3 enters this box            (mol)
+                     if (fdep.le.fccd_dep) then
+                        !! whole grid cell above CCD
+                        fq1      = fq0                               !! above lysocline, no Ca dissolves          (mol)
+                        freminca = 0.0                               !! above lysocline, no Ca dissolves          (mol)
+                        fccd(ji,jj) = real(jk)                       !! which is the last level above the CCD?    (#)
+                     elseif (fdep.ge.fccd_dep) then
+                        !! whole grid cell below CCD
+                        fq1      = fq0 * exp(-(fthk / xfastca))      !! how much CaCO3 leaves this box            (mol)
+                        freminca = (fq0 - fq1) / fthk                !! Ca remineralisation in this box           (mol)
+                     else
+                        !! partial grid cell below CCD
+                        fq2      = fdep1 - fccd_dep                  !! amount of grid cell below CCD             (m)
+                        fq1      = fq0 * exp(-(fq2 / xfastca))       !! how much CaCO3 leaves this box            (mol)
+                        freminca = (fq0 - fq1) / fthk                !! Ca remineralisation in this box           (mol)
+                     endif
+                     ffastca(ji,jj) = fq1 
+                  else
+                     !! this is BELOW THE LAST OCEAN BOX (do nothing)
+                     freminc  = 0.0
+                     freminn  = 0.0
+                     freminfe = 0.0
+                     freminsi = 0.0
+                     freminca = 0.0              
+                  endif
+
+               elseif (jexport.eq.2.or.jexport.eq.3) then
+                  if (jexport.eq.2) then
+                     !!======================================================================
+                     !! MARTIN ET AL. (1987) SUBMODEL
+                     !!======================================================================
+                     !! 
+                     !!----------------------------------------------------------------------
+                     !! This submodel uses the classic Martin et al. (1987) curve
+                     !! to determine the attenuation of fast-sinking detritus down
+                     !! the water column.  All three organic elements, C, N and Fe,
+                     !! are handled identically, and their quantities in sinking
+                     !! particles attenuate according to a power relationship
+                     !! governed by parameter "b".  This is assigned a canonical 
+                     !! value of -0.858.  Biogenic opal and calcium carbonate are
+                     !! attentuated using the same function as in the ballast
+                     !! submodel
+                     !!----------------------------------------------------------------------
+                     !!
+                     fb_val = -0.858
+                  elseif (jexport.eq.3) then
+                     !!======================================================================
+                     !! HENSON ET AL. (2011) SUBMODEL
+                     !!======================================================================
+                     !!
+                     !!----------------------------------------------------------------------
+                     !! This submodel reconfigures the Martin et al. (1987) curve by
+                     !! allowing the "b" value to vary geographically.  Its value is
+                     !! set, following Henson et al. (2011), as a function of local
+                     !! sea surface temperature:
+                     !!   b = -1.06 + (0.024 * SST)
+                     !! This means that remineralisation length scales are longer in
+                     !! warm, tropical areas and shorter in cold, polar areas.  This
+                     !! does seem back-to-front (i.e. one would expect GREATER
+                     !! remineralisation in warmer waters), but is an outcome of 
+                     !! analysis of sediment trap data, and it may reflect details
+                     !! of ecosystem structure that pertain to particle production
+                     !! rather than simply Q10.
+                     !!----------------------------------------------------------------------
+                     !!
+                     fl_sst = tsn(ji,jj,1,jp_tem)
+                     fb_val = -1.06 + (0.024 * fl_sst)
+                  endif
+                  !!   
+                  if (jk.eq.1) then
+                     !! this is the SURFACE OCEAN BOX (no remineralisation)
+                     !!
+                     freminc  = 0.0
+                     freminn  = 0.0
+                     freminfe = 0.0
+                     freminsi = 0.0
+                     freminca = 0.0
+                  elseif (jk.lt.(mbathy(ji,jj))) then
+                     !! this is an OCEAN BOX (remineralise some material)
+                     !!
+                     !! === organic carbon ===
+                     fq0      = ffastc(ji,jj)                        !! how much organic C enters this box        (mol)
+                     fq1      = fq0 * ((fdep1/fdep)**fb_val)         !! how much organic C leaves this box        (mol)
+                     freminc  = (fq0 - fq1) / fthk                   !! C remineralisation in this box            (mol)
+                     ffastc(ji,jj)  = fq1
+                     !!
+                     !! === organic nitrogen ===
+                     fq0      = ffastn(ji,jj)                        !! how much organic N enters this box        (mol)
+                     fq1      = fq0 * ((fdep1/fdep)**fb_val)         !! how much organic N leaves this box        (mol)
+                     freminn  = (fq0 - fq1) / fthk                   !! N remineralisation in this box            (mol)
+                     ffastn(ji,jj)  = fq1
+                     !!
+                     !! === organic iron ===
+                     fq0      = ffastfe(ji,jj)                       !! how much organic Fe enters this box       (mol)
+                     fq1      = fq0 * ((fdep1/fdep)**fb_val)         !! how much organic Fe leaves this box       (mol)
+                     freminfe = (fq0 - fq1) / fthk                   !! Fe remineralisation in this box           (mol)
+                     ffastfe(ji,jj) = fq1
+                     !!
+                     !! === biogenic silicon ===
+                     fq0      = ffastsi(ji,jj)                       !! how much  opal centers this box           (mol) 
+                     fq1      = fq0 * exp(-(fthk / xfastsi))         !! how much  opal leaves this box            (mol)
+                     freminsi = (fq0 - fq1) / fthk                   !! Si remineralisation in this box           (mol)
+                     ffastsi(ji,jj) = fq1
+                     !!
+                     !! === biogenic calcium carbonate ===
+                     fq0      = ffastca(ji,jj)                       !! how much CaCO3 enters this box            (mol)
+                     if (fdep.le.ocal_ccd(ji,jj)) then
+                        !! whole grid cell above CCD
+                        fq1      = fq0                               !! above lysocline, no Ca dissolves          (mol)
+                        freminca = 0.0                               !! above lysocline, no Ca dissolves          (mol)
+                        fccd(ji,jj) = real(jk)                       !! which is the last level above the CCD?    (#)
+                     elseif (fdep.ge.ocal_ccd(ji,jj)) then
+                        !! whole grid cell below CCD
+                        fq1      = fq0 * exp(-(fthk / xfastca))      !! how much CaCO3 leaves this box            (mol)
+                        freminca = (fq0 - fq1) / fthk                !! Ca remineralisation in this box           (mol)
+                     else
+                        !! partial grid cell below CCD
+                        fq2      = fdep1 - ocal_ccd(ji,jj)           !! amount of grid cell below CCD             (m)
+                        fq1      = fq0 * exp(-(fq2 / xfastca))       !! how much CaCO3 leaves this box            (mol)
+                        freminca = (fq0 - fq1) / fthk                !! Ca remineralisation in this box           (mol)
+                     endif
+                     ffastca(ji,jj) = fq1 
+                  else
+                     !! this is BELOW THE LAST OCEAN BOX (do nothing)
+                     freminc  = 0.0
+                     freminn  = 0.0
+                     freminfe = 0.0
+                     freminsi = 0.0
+                     freminca = 0.0              
+                  endif
+
+               endif
+
+               !!----------------------------------------------------------------------
+               !! Fast-sinking detritus fluxes, pt. 2: UPDATE FAST FLUXES
+               !! here locally calculated additions to the fast-sinking flux are added
+               !! to the total fast-sinking flux; this is done here such that material
+               !! produced in a particular layer is only remineralised below this
+               !! layer
+               !!----------------------------------------------------------------------
+               !!
+               !! add sinking material generated in this layer to running totals
+               !!
+               !! === organic carbon ===                          (diatom and mesozooplankton mortality)
+               ffastc(ji,jj)  = ffastc(ji,jj)  + (ftempc  * fthk)
+               !!
+               !! === organic nitrogen ===                        (diatom and mesozooplankton mortality)
+               ffastn(ji,jj)  = ffastn(ji,jj)  + (ftempn  * fthk)
+               !!
+               !! === organic iron ===                            (diatom and mesozooplankton mortality)
+               ffastfe(ji,jj) = ffastfe(ji,jj) + (ftempfe * fthk)
+               !!
+               !! === biogenic silicon ===                        (diatom mortality and grazed diatoms)
+               ffastsi(ji,jj) = ffastsi(ji,jj) + (ftempsi * fthk)
+               !!
+               !! === biogenic calcium carbonate ===              (latitudinally-based fraction of total primary production)
+               ffastca(ji,jj) = ffastca(ji,jj) + (ftempca * fthk)
+
+               !!----------------------------------------------------------------------
+               !! Fast-sinking detritus fluxes, pt. 3: SEAFLOOR
+               !! remineralise all remaining fast-sinking detritus to dissolved
+               !! nutrients; the sedimentation fluxes calculated here allow the
+               !! separation of what's remineralised sinking through the final
+               !! ocean box from that which is added to the final box by the
+               !! remineralisation of material that reaches the seafloor (i.e.
+               !! the model assumes that *all* material that hits the seafloor
+               !! is remineralised and that none is permanently buried; hey,
+               !! this is a giant GCM model that can't be run for long enough
+               !! to deal with burial fluxes!)
+               !!
+               !! in a change to this process, in part so that MEDUSA behaves
+               !! a little more like ERSEM et al., fast-sinking detritus (N, Fe
+               !! and C) is converted to slow sinking detritus at the seafloor
+               !! instead of being remineralised; the rationale is that in
+               !! shallower shelf regions (... that are not fully mixed!) this
+               !! allows the detrital material to return slowly to dissolved 
+               !! nutrient rather than instantaneously as now; the alternative
+               !! would be to explicitly handle seafloor organic material - a
+               !! headache I don't wish to experience at this point; note that
+               !! fast-sinking Si and Ca detritus is just remineralised as 
+               !! per usual
+               !! 
+               !! AXY (13/01/12)
+               !! in a further change to this process, again so that MEDUSA is
+               !! a little more like ERSEM et al., material that reaches the
+               !! seafloor can now be added to sediment pools and stored for
+               !! slow release; there are new 2D arrays for organic nitrogen,
+               !! iron and carbon and inorganic silicon and carbon that allow
+               !! fast and slow detritus that reaches the seafloor to be held
+               !! and released back to the water column more slowly; these arrays
+               !! are transferred via the tracer restart files between repeat
+               !! submissions of the model
+               !!----------------------------------------------------------------------
+               !! 
+               ffast2slowc  = 0.0
+               ffast2slown  = 0.0
+               ffast2slowfe = 0.0
+               !!
+               if (jk.eq.(mbathy(ji,jj)-1)) then
+                  !! this is the BOTTOM OCEAN BOX (remineralise everything)
+                  !!
+                  !! AXY (17/01/12): tweaked to include benthos pools
+                  !! 
+                  !! === organic carbon ===
+                  if (jfdfate.eq.0 .and. jorgben.eq.0) then
+                     freminc  = freminc + (ffastc(ji,jj) / fthk)    !! C remineralisation in this box            (mol/m3)
+                  elseif (jfdfate.eq.1 .and. jorgben.eq.0) then
+                     ffast2slowc = ffastc(ji,jj) / fthk             !! fast C -> slow C                          (mol/m3)
+                     fslowc      = fslowc + ffast2slowc
+                  elseif (jfdfate.eq.0 .and. jorgben.eq.1) then
+                     f_fbenin_c(ji,jj)  = ffastc(ji,jj)             !! fast C -> benthic C                       (mol/m2)
+                  endif
+                  fsedc    = ffastc(ji,jj)                          !! record seafloor C                         (mol/m2)
+                  ffastc(ji,jj)  = 0.0
+                  !!
+                  !! === organic nitrogen ===
+                  if (jfdfate.eq.0 .and. jorgben.eq.0) then
+                     freminn  = freminn + (ffastn(ji,jj) / fthk)    !! N remineralisation in this box            (mol/m3)
+                  elseif (jfdfate.eq.1 .and. jorgben.eq.0) then
+                     ffast2slown = ffastn(ji,jj) / fthk             !! fast N -> slow N                          (mol/m3)
+                     fslown      = fslown + ffast2slown
+                  elseif (jfdfate.eq.0 .and. jorgben.eq.1) then
+                     f_fbenin_n(ji,jj)  = ffastn(ji,jj)             !! fast N -> benthic N                       (mol/m2)
+                  endif
+                  fsedn    = ffastn(ji,jj)                          !! record seafloor N                         (mol/m2)
+                  ffastn(ji,jj)  = 0.0
+                  !!
+                  !! === organic iron ===
+                  if (jfdfate.eq.0 .and. jorgben.eq.0) then
+                     freminfe = freminfe + (ffastfe(ji,jj) / fthk)  !! Fe remineralisation in this box           (mol/m3)
+                  elseif (jfdfate.eq.1 .and. jorgben.eq.0) then
+                     ffast2slowfe = ffastn(ji,jj) / fthk            !! fast Fe -> slow Fe                        (mol/m3)
+                  elseif (jfdfate.eq.0 .and. jorgben.eq.1) then
+                     f_fbenin_fe(ji,jj) = ffastfe(ji,jj)            !! fast Fe -> benthic Fe                     (mol/m2)
+                  endif
+                  fsedfe   = ffastfe(ji,jj)                         !! record seafloor Fe                        (mol/m2)
+                  ffastfe(ji,jj) = 0.0
+                  !!
+                  !! === biogenic silicon ===
+                  if (jinorgben.eq.0) then
+                     freminsi = freminsi + (ffastsi(ji,jj) / fthk)  !! Si remineralisation in this box           (mol/m3)
+                  elseif (jinorgben.eq.1) then
+                     f_fbenin_si(ji,jj) = ffastsi(ji,jj)            !! fast Si -> benthic Si                     (mol/m2)
+                  endif
+                  fsedsi   = ffastsi(ji,jj)                         !! record seafloor Si                        (mol/m2)
+                  ffastsi(ji,jj) = 0.0
+                  !!
+                  !! === biogenic calcium carbonate ===
+                  if (jinorgben.eq.0) then
+                     freminca = freminca + (ffastca(ji,jj) / fthk)  !! Ca remineralisation in this box           (mol/m3) 
+                  elseif (jinorgben.eq.1) then
+                     f_fbenin_ca(ji,jj) = ffastca(ji,jj)            !! fast Ca -> benthic Ca                     (mol/m2)
+                  endif
+                  fsedca   = ffastca(ji,jj)                         !! record seafloor Ca                        (mol/m2)
+                  ffastca(ji,jj) = 0.0
+               endif
+
+# if defined key_debug_medusa
+               if (idf.eq.1) then
+                  !!----------------------------------------------------------------------
+                  !! Integrate total fast detritus remineralisation
+                  !!----------------------------------------------------------------------
+                  !!
+                  fofd_n(ji,jj)  = fofd_n(ji,jj)  + (freminn  * fthk)
+                  fofd_si(ji,jj) = fofd_si(ji,jj) + (freminsi * fthk)
+                  fofd_fe(ji,jj) = fofd_fe(ji,jj) + (freminfe * fthk)
+#  if defined key_roam
+                  fofd_c(ji,jj)  = fofd_c(ji,jj)  + (freminc  * fthk)
+#  endif
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Sort out remineralisation tally of fast-sinking detritus
+               !!----------------------------------------------------------------------
+               !!
+               !! update fast-sinking regeneration arrays
+               fregenfast(ji,jj)   = fregenfast(ji,jj)   + (freminn  * fthk)
+               fregenfastsi(ji,jj) = fregenfastsi(ji,jj) + (freminsi * fthk)
+# if defined key_roam
+               fregenfastc(ji,jj)  = fregenfastc(ji,jj)  + (freminc  * fthk)
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Benthic remineralisation fluxes
+               !!----------------------------------------------------------------------
+               !!
+               if (jk.eq.(mbathy(ji,jj)-1)) then
+                  !!
+                  !! organic components
+                  if (jorgben.eq.1) then
+                     f_benout_n(ji,jj)  = xsedn  * zn_sed_n(ji,jj)
+                     f_benout_fe(ji,jj) = xsedfe * zn_sed_fe(ji,jj)
+                     f_benout_c(ji,jj)  = xsedc  * zn_sed_c(ji,jj)
+                  endif
+                  !!
+                  !! inorganic components
+                  if (jinorgben.eq.1) then
+                     f_benout_si(ji,jj) = xsedsi * zn_sed_si(ji,jj)
+                     f_benout_ca(ji,jj) = xsedca * zn_sed_ca(ji,jj)
+                     !!
+                     !! account for CaCO3 that dissolves when it shouldn't
+                     if ( fdep .le. fccd_dep ) then
+                        f_benout_lyso_ca(ji,jj) = xsedca * zn_sed_ca(ji,jj)
+                     endif
+                  endif
+               endif
+               CALL flush(numout)
+
+               !!======================================================================
+               !! LOCAL GRID CELL TRENDS
+               !!======================================================================
+               !!
+               !!----------------------------------------------------------------------
+               !! Determination of trends
+               !!----------------------------------------------------------------------
+               !!
+               !!----------------------------------------------------------------------
+               !! chlorophyll
+               btra(jpchn) = b0 * ( &
+                 + ((frn * fprn * zphn) - fgmipn - fgmepn - fdpn - fdpn2) * (fthetan / xxi) )
+               btra(jpchd) = b0 * ( &
+                 + ((frd * fprd * zphd) - fgmepd - fdpd - fdpd2) * (fthetad / xxi) )
+               !!
+               !!----------------------------------------------------------------------
+               !! phytoplankton
+               btra(jpphn) = b0 * ( &
+                 + (fprn * zphn) - fgmipn - fgmepn - fdpn - fdpn2 )
+               btra(jpphd) = b0 * ( &
+                 + (fprd * zphd) - fgmepd - fdpd - fdpd2 )
+               btra(jppds) = b0 * ( &
+                 + (fprds * zpds) - fgmepds - fdpds - fsdiss - fdpds2 )
+               !!
+               !!----------------------------------------------------------------------
+               !! zooplankton
+               btra(jpzmi) = b0 * ( &
+                 + fmigrow - fgmezmi - fdzmi - fdzmi2 )
+               btra(jpzme) = b0 * ( &
+                 + fmegrow - fdzme - fdzme2 )
+               !!
+               !!----------------------------------------------------------------------
+               !! detritus
+               btra(jpdet) = b0 * ( &
+                 + fdpn + ((1.0 - xfdfrac1) * fdpd)              &  ! mort. losses
+                 + fdzmi + ((1.0 - xfdfrac2) * fdzme)            &  ! mort. losses
+                 + ((1.0 - xbetan) * (finmi + finme))            &  ! assim. inefficiency
+                 - fgmid - fgmed - fdd                           &  ! grazing and remin.
+                 + ffast2slown )                                    ! seafloor fast->slow
+               !!
+               !!----------------------------------------------------------------------
+               !! dissolved inorganic nitrogen nutrient
+               fn_cons = 0.0  &
+                 - (fprn * zphn) - (fprd * zphd)                    ! primary production
+               fn_prod = 0.0  &
+                 + (xphi * (fgmipn + fgmid))                     &  ! messy feeding remin.
+                 + (xphi * (fgmepn + fgmepd + fgmezmi + fgmed))  &  ! messy feeding remin.
+                 + fmiexcr + fmeexcr + fdd + freminn             &  ! excretion and remin.
+                 + fdpn2 + fdpd2 + fdzmi2 + fdzme2                  ! metab. losses
+               !! 
+               !! riverine flux
+               if ( jriver_n .gt. 0 ) then
+                  f_riv_loc_n = f_riv_n(ji,jj) * friver_dep(jk,(mbathy(ji,jj)-1)) / fthk
+                  fn_prod = fn_prod + f_riv_loc_n
+               endif
+               !!  
+               !! benthic remineralisation
+               if (jk.eq.(mbathy(ji,jj)-1) .and. jorgben.eq.1 .and. ibenthic.eq.1) then
+                  fn_prod = fn_prod + (f_benout_n(ji,jj) / fthk)
+               endif
+               !!
+               btra(jpdin) = b0 * ( &
+                 fn_prod + fn_cons )
+               !!
+               fnit_cons(ji,jj) = fnit_cons(ji,jj) + ( fthk * (  &  ! consumption of dissolved nitrogen
+                 fn_cons ) )
+               fnit_prod(ji,jj) = fnit_prod(ji,jj) + ( fthk * (  &  ! production of dissolved nitrogen
+                 fn_prod ) )
+               !!
+               !!----------------------------------------------------------------------
+               !! dissolved silicic acid nutrient
+               fs_cons = 0.0  &
+                 - (fprds * zpds)                                   ! opal production
+               fs_prod = 0.0  &
+                 + fsdiss                                        &  ! opal dissolution
+                 + ((1.0 - xfdfrac1) * fdpds)                    &  ! mort. loss
+                 + ((1.0 - xfdfrac3) * fgmepds)                  &  ! egestion of grazed Si
+                 + freminsi + fdpds2                                ! fast diss. and metab. losses
+               !! 
+               !! riverine flux
+               if ( jriver_si .gt. 0 ) then
+                  f_riv_loc_si = f_riv_si(ji,jj) * friver_dep(jk,(mbathy(ji,jj)-1)) / fthk
+                  fs_prod = fs_prod + f_riv_loc_si
+               endif
+               !!  
+               !! benthic remineralisation
+               if (jk.eq.(mbathy(ji,jj)-1) .and. jinorgben.eq.1 .and. ibenthic.eq.1) then
+                  fs_prod = fs_prod + (f_benout_si(ji,jj) / fthk)
+               endif
+               !!
+               btra(jpsil) = b0 * ( &
+                 fs_prod + fs_cons )
+               !!
+               fsil_cons(ji,jj) = fsil_cons(ji,jj) + ( fthk * (  &  ! consumption of dissolved silicon
+                 fs_cons ) )
+               fsil_prod(ji,jj) = fsil_prod(ji,jj) + ( fthk * (  &  ! production of dissolved silicon
+                 fs_prod ) )
+               !!
+               !!----------------------------------------------------------------------
+               !! dissolved "iron" nutrient
+               btra(jpfer) = b0 * ( &
+               + (xrfn * btra(jpdin)) + ffetop + ffebot - ffescav )
+
+# if defined key_roam
+               !!
+               !!----------------------------------------------------------------------
+               !! AXY (26/11/08): implicit detrital carbon change
+               btra(jpdtc) = b0 * ( &
+                 + (xthetapn * fdpn) + ((1.0 - xfdfrac1) * (xthetapd * fdpd))      &  ! mort. losses
+                 + (xthetazmi * fdzmi) + ((1.0 - xfdfrac2) * (xthetazme * fdzme))  &  ! mort. losses
+                 + ((1.0 - xbetac) * (ficmi + ficme))                              &  ! assim. inefficiency
+                 - fgmidc - fgmedc - fddc                                          &  ! grazing and remin.
+                 + ffast2slowc )                                                      ! seafloor fast->slow
+               !!
+               !!----------------------------------------------------------------------
+               !! dissolved inorganic carbon
+               fc_cons = 0.0  &
+                 - (xthetapn * fprn * zphn) - (xthetapd * fprd * zphd)                ! primary production
+               fc_prod = 0.0  &
+                 + (xthetapn * xphi * fgmipn) + (xphi * fgmidc)                    &  ! messy feeding remin
+                 + (xthetapn * xphi * fgmepn) + (xthetapd * xphi * fgmepd)         &  ! messy feeding remin
+                 + (xthetazmi * xphi * fgmezmi) + (xphi * fgmedc)                  &  ! messy feeding remin
+                 + fmiresp + fmeresp + fddc + freminc + (xthetapn * fdpn2)         &  ! resp., remin., losses
+                 + (xthetapd * fdpd2) + (xthetazmi * fdzmi2)                       &  ! losses
+                 + (xthetazme * fdzme2)                                               ! losses
+               !! 
+               !! riverine flux
+               if ( jriver_c .gt. 0 ) then
+                  f_riv_loc_c = f_riv_c(ji,jj) * friver_dep(jk,(mbathy(ji,jj)-1)) / fthk
+                  fc_prod = fc_prod + f_riv_loc_c
+               endif
+               !!  
+               !! benthic remineralisation
+               if (jk.eq.(mbathy(ji,jj)-1) .and. jorgben.eq.1 .and. ibenthic.eq.1) then
+                  fc_prod = fc_prod + (f_benout_c(ji,jj) / fthk)
+               endif
+               if (jk.eq.(mbathy(ji,jj)-1) .and. jinorgben.eq.1 .and. ibenthic.eq.1) then
+                  fc_prod = fc_prod + (f_benout_ca(ji,jj) / fthk)
+               endif
+               !!
+               !! community respiration (does not include CaCO3 terms - obviously!)
+               fcomm_resp = fc_prod
+               !!
+               !! CaCO3
+               fc_prod = fc_prod - ftempca + freminca
+               !! 
+               !! riverine flux
+               if ( jk .eq. 1 .and. jriver_c .gt. 0 ) then
+                  fc_prod = fc_prod + f_riv_c(ji,jj)
+               endif
+               !!
+               btra(jpdic) = b0 * ( &
+                 fc_prod + fc_cons )
+               !!
+               fcar_cons(ji,jj) = fcar_cons(ji,jj) + ( fthk * (  &  ! consumption of dissolved carbon
+                 fc_cons ) )
+               fcar_prod(ji,jj) = fcar_prod(ji,jj) + ( fthk * (  &  ! production of dissolved carbon
+                 fc_prod ) )
+               !!
+               !!----------------------------------------------------------------------
+               !! alkalinity
+               fa_prod = 0.0  &
+                 + (2.0 * freminca)                                                   ! CaCO3 dissolution
+               fa_cons = 0.0  &
+                 - (2.0 * ftempca)                                                    ! CaCO3 production
+               !! 
+               !! riverine flux
+               if ( jriver_alk .gt. 0 ) then
+                  f_riv_loc_alk = f_riv_alk(ji,jj) * friver_dep(jk,(mbathy(ji,jj)-1)) / fthk
+                  fa_prod = fa_prod + f_riv_loc_alk
+               endif
+               !!  
+               !! benthic remineralisation
+               if (jk.eq.(mbathy(ji,jj)-1) .and. jinorgben.eq.1 .and. ibenthic.eq.1) then
+                  fa_prod = fa_prod + (2.0 * f_benout_ca(ji,jj) / fthk)
+               endif
+               !!
+               btra(jpalk) = b0 * ( &
+                 fa_prod + fa_cons )
+               !!
+               !!----------------------------------------------------------------------
+               !! oxygen (has protection at low O2 concentrations; OCMIP-2 style)
+               fo2_prod = 0.0 &
+                 + (xthetanit * fprn * zphn)                                      & ! Pn primary production, N
+                 + (xthetanit * fprd * zphd)                                      & ! Pd primary production, N
+                 + (xthetarem * xthetapn * fprn * zphn)                           & ! Pn primary production, C
+                 + (xthetarem * xthetapd * fprd * zphd)                             ! Pd primary production, C
+               fo2_ncons = 0.0 &
+                 - (xthetanit * xphi * fgmipn)                                    & ! Pn messy feeding remin., N
+                 - (xthetanit * xphi * fgmid)                                     & ! D  messy feeding remin., N
+                 - (xthetanit * xphi * fgmepn)                                    & ! Pn messy feeding remin., N
+                 - (xthetanit * xphi * fgmepd)                                    & ! Pd messy feeding remin., N
+                 - (xthetanit * xphi * fgmezmi)                                   & ! Zi messy feeding remin., N
+                 - (xthetanit * xphi * fgmed)                                     & ! D  messy feeding remin., N
+                 - (xthetanit * fmiexcr)                                          & ! microzoo excretion, N
+                 - (xthetanit * fmeexcr)                                          & ! mesozoo  excretion, N
+                 - (xthetanit * fdd)                                              & ! slow detritus remin., N 
+                 - (xthetanit * freminn)                                          & ! fast detritus remin., N
+                 - (xthetanit * fdpn2)                                            & ! Pn  losses, N
+                 - (xthetanit * fdpd2)                                            & ! Pd  losses, N
+                 - (xthetanit * fdzmi2)                                           & ! Zmi losses, N
+                 - (xthetanit * fdzme2)                                             ! Zme losses, N
+               !!  
+               !! benthic remineralisation
+               if (jk.eq.(mbathy(ji,jj)-1) .and. jorgben.eq.1 .and. ibenthic.eq.1) then
+                  fo2_ncons = fo2_ncons - (xthetanit * f_benout_n(ji,jj) / fthk)
+               endif
+               fo2_ccons = 0.0 &
+                 - (xthetarem * xthetapn * xphi * fgmipn)                         & ! Pn messy feeding remin., C
+                 - (xthetarem * xphi * fgmidc)                                    & ! D  messy feeding remin., C
+                 - (xthetarem * xthetapn * xphi * fgmepn)                         & ! Pn messy feeding remin., C
+                 - (xthetarem * xthetapd * xphi * fgmepd)                         & ! Pd messy feeding remin., C
+                 - (xthetarem * xthetazmi * xphi * fgmezmi)                       & ! Zi messy feeding remin., C
+                 - (xthetarem * xphi * fgmedc)                                    & ! D  messy feeding remin., C
+                 - (xthetarem * fmiresp)                                          & ! microzoo respiration, C
+                 - (xthetarem * fmeresp)                                          & ! mesozoo  respiration, C
+                 - (xthetarem * fddc)                                             & ! slow detritus remin., C
+                 - (xthetarem * freminc)                                          & ! fast detritus remin., C
+                 - (xthetarem * xthetapn * fdpn2)                                 & ! Pn  losses, C
+                 - (xthetarem * xthetapd * fdpd2)                                 & ! Pd  losses, C
+                 - (xthetarem * xthetazmi * fdzmi2)                               & ! Zmi losses, C
+                 - (xthetarem * xthetazme * fdzme2)                                 ! Zme losses, C
+               !!  
+               !! benthic remineralisation
+               if (jk.eq.(mbathy(ji,jj)-1) .and. jorgben.eq.1 .and. ibenthic.eq.1) then
+                  fo2_ccons = fo2_ccons - (xthetarem * f_benout_c(ji,jj) / fthk)
+               endif
+               fo2_cons = fo2_ncons + fo2_ccons
+               !!
+               !! is this a suboxic zone?
+               if (zoxy.lt.xo2min) then  ! deficient O2; production fluxes only
+                  btra(jpoxy) = b0 * ( &
+                    fo2_prod )
+                  foxy_prod(ji,jj) = foxy_prod(ji,jj) + ( fthk * fo2_prod )
+                  foxy_anox(ji,jj) = foxy_anox(ji,jj) + ( fthk * fo2_cons )
+               else                      ! sufficient O2; production + consumption fluxes
+                  btra(jpoxy) = b0 * ( &
+                    fo2_prod + fo2_cons )
+                  foxy_prod(ji,jj) = foxy_prod(ji,jj) + ( fthk * fo2_prod )
+                  foxy_cons(ji,jj) = foxy_cons(ji,jj) + ( fthk * fo2_cons )
+               endif
+               !!
+               !! air-sea fluxes (if this is the surface box)
+               if (jk.eq.1) then
+                  !!
+                  !! CO2 flux
+                  btra(jpdic) = btra(jpdic) + (b0 * f_co2flux)
+                  !!
+                  !! O2 flux (mol/m3/s -> mmol/m3/d)
+                  btra(jpoxy) = btra(jpoxy) + (b0 * f_o2flux)
+               endif
+# endif
+
+# if defined key_debug_medusa
+               !! report state variable fluxes (not including fast-sinking detritus)
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'btra(jpchn)(',jk,')  = ', btra(jpchn)
+                  IF (lwp) write (numout,*) 'btra(jpchd)(',jk,')  = ', btra(jpchd)
+                  IF (lwp) write (numout,*) 'btra(jpphn)(',jk,')  = ', btra(jpphn)
+                  IF (lwp) write (numout,*) 'btra(jpphd)(',jk,')  = ', btra(jpphd)
+                  IF (lwp) write (numout,*) 'btra(jppds)(',jk,')  = ', btra(jppds)
+                  IF (lwp) write (numout,*) 'btra(jpzmi)(',jk,')  = ', btra(jpzmi)
+                  IF (lwp) write (numout,*) 'btra(jpzme)(',jk,')  = ', btra(jpzme)
+                  IF (lwp) write (numout,*) 'btra(jpdet)(',jk,')  = ', btra(jpdet)
+                  IF (lwp) write (numout,*) 'btra(jpdin)(',jk,')  = ', btra(jpdin)
+                  IF (lwp) write (numout,*) 'btra(jpsil)(',jk,')  = ', btra(jpsil)
+                  IF (lwp) write (numout,*) 'btra(jpfer)(',jk,')  = ', btra(jpfer)
+#  if defined key_roam
+                  IF (lwp) write (numout,*) 'btra(jpdtc)(',jk,')  = ', btra(jpdtc)
+                  IF (lwp) write (numout,*) 'btra(jpdic)(',jk,')  = ', btra(jpdic)
+                  IF (lwp) write (numout,*) 'btra(jpalk)(',jk,')  = ', btra(jpalk)
+                  IF (lwp) write (numout,*) 'btra(jpoxy)(',jk,')  = ', btra(jpoxy)
+#  endif
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Integrate calculated fluxes for mass balance
+               !!----------------------------------------------------------------------
+               !!
+               !! === nitrogen ===
+               fflx_n(ji,jj)  = fflx_n(ji,jj)  + &
+                  fthk * ( btra(jpphn) + btra(jpphd) + btra(jpzmi) + btra(jpzme) + btra(jpdet) + btra(jpdin) )
+               !! === silicon ===
+               fflx_si(ji,jj) = fflx_si(ji,jj) + &
+                  fthk * ( btra(jppds) + btra(jpsil) )
+               !! === iron ===
+               fflx_fe(ji,jj) = fflx_fe(ji,jj) + &
+                  fthk * ( ( xrfn * ( btra(jpphn) + btra(jpphd) + btra(jpzmi) + btra(jpzme) + btra(jpdet)) ) + btra(jpfer) )
+# if defined key_roam
+               !! === carbon ===
+               fflx_c(ji,jj)  = fflx_c(ji,jj)  + &
+                  fthk * ( (xthetapn * btra(jpphn)) + (xthetapd * btra(jpphd)) + &
+                  (xthetazmi * btra(jpzmi)) + (xthetazme * btra(jpzme)) + btra(jpdtc) + btra(jpdic) )
+               !! === alkalinity ===
+               fflx_a(ji,jj)  = fflx_a(ji,jj)  + &
+                  fthk * ( btra(jpalk) )
+               !! === oxygen ===
+               fflx_o2(ji,jj) = fflx_o2(ji,jj) + &
+                  fthk * ( btra(jpoxy) )
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Apply calculated tracer fluxes
+               !!----------------------------------------------------------------------
+               !!
+               !! units: [unit of tracer] per second (fluxes are calculated above per day)
+               !!
+               ibio_switch = 1
+# if defined key_gulf_finland
+               !! AXY (17/05/13): fudge in a Gulf of Finland correction; uses longitude-
+               !!                 latitude range to establish if this is a Gulf of Finland 
+               !!                 grid cell; if so, then BGC fluxes are ignored (though 
+               !!                 still calculated); for reference, this is meant to be a 
+               !!                 temporary fix to see if all of my problems can be done 
+               !!                 away with if I switch off BGC fluxes in the Gulf of 
+               !!                 Finland, which currently appears the source of trouble
+               if ( flonx.gt.24.7 .and. flonx.lt.27.8 .and. &
+                  &   flatx.gt.59.2 .and. flatx.lt.60.2 ) then
+                  ibio_switch = 0
+               endif
+# endif               
+               if (ibio_switch.eq.1) then
+                  tra(ji,jj,jk,jpchn) = tra(ji,jj,jk,jpchn) + (btra(jpchn) / 86400.)
+                  tra(ji,jj,jk,jpchd) = tra(ji,jj,jk,jpchd) + (btra(jpchd) / 86400.)
+                  tra(ji,jj,jk,jpphn) = tra(ji,jj,jk,jpphn) + (btra(jpphn) / 86400.)
+                  tra(ji,jj,jk,jpphd) = tra(ji,jj,jk,jpphd) + (btra(jpphd) / 86400.)
+                  tra(ji,jj,jk,jppds) = tra(ji,jj,jk,jppds) + (btra(jppds) / 86400.)
+                  tra(ji,jj,jk,jpzmi) = tra(ji,jj,jk,jpzmi) + (btra(jpzmi) / 86400.)
+                  tra(ji,jj,jk,jpzme) = tra(ji,jj,jk,jpzme) + (btra(jpzme) / 86400.)
+                  tra(ji,jj,jk,jpdet) = tra(ji,jj,jk,jpdet) + (btra(jpdet) / 86400.)
+                  tra(ji,jj,jk,jpdin) = tra(ji,jj,jk,jpdin) + (btra(jpdin) / 86400.)
+                  tra(ji,jj,jk,jpsil) = tra(ji,jj,jk,jpsil) + (btra(jpsil) / 86400.)
+                  tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + (btra(jpfer) / 86400.)
+# if defined key_roam
+                  tra(ji,jj,jk,jpdtc) = tra(ji,jj,jk,jpdtc) + (btra(jpdtc) / 86400.)
+                  tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) + (btra(jpdic) / 86400.)
+                  tra(ji,jj,jk,jpalk) = tra(ji,jj,jk,jpalk) + (btra(jpalk) / 86400.)
+                  tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) + (btra(jpoxy) / 86400.)
+# endif
+               endif               
+
+# if defined key_axy_nancheck
+               !!----------------------------------------------------------------------
+               !! Check calculated tracer fluxes
+               !!----------------------------------------------------------------------
+               !!
+               DO jn = 1,jptra
+                  fq0 = btra(jn)
+                  !! AXY (30/01/14): "isnan" problem on HECTOR
+                  !! if (fq0 /= fq0 ) then
+                  if ( ieee_is_nan( fq0 ) ) then
+                     !! there's a NaN here
+                     if (lwp) write(numout,*) 'NAN detected in btra(', ji, ',', &
+                     & jj, ',', jk, ',', jn, ') at time', kt
+		     CALL ctl_stop( 'trcbio_medusa, NAN in btra field' )
+                  endif
+               ENDDO
+               DO jn = 1,jptra
+                  fq0 = tra(ji,jj,jk,jn)
+                  !! AXY (30/01/14): "isnan" problem on HECTOR
+                  !! if (fq0 /= fq0 ) then
+                  if ( ieee_is_nan( fq0 ) ) then
+                     !! there's a NaN here
+                     if (lwp) write(numout,*) 'NAN detected in tra(', ji, ',', &
+                     & jj, ',', jk, ',', jn, ') at time', kt
+   		     CALL ctl_stop( 'trcbio_medusa, NAN in tra field' )
+                  endif
+               ENDDO
+               CALL flush(numout)
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Check model conservation
+               !! these terms merely sum up the tendency terms of the relevant
+               !! state variables, which should sum to zero; the iron cycle is
+               !! complicated by fluxes that add (aeolian deposition and seafloor
+               !! remineralisation) and remove (scavenging) dissolved iron from
+               !! the model (i.e. the sum of iron fluxes is unlikely to be zero)
+               !!----------------------------------------------------------------------
+               !!
+               !! fnit0 = btra(jpphn) + btra(jpphd) + btra(jpzmi) + btra(jpzme) + btra(jpdet) + btra(jpdin)  ! + ftempn
+               !! fsil0 = btra(jppds) + btra(jpsil)                              ! + ftempsi
+               !! ffer0 = (xrfn * fnit0) + btra(jpfer)
+# if defined key_roam
+               !! fcar0 = 0.
+               !! falk0 = 0.
+               !! foxy0 = 0.
+# endif
+               !!
+               !! if (kt/240*240.eq.kt) then
+               !!    if (ji.eq.2.and.jj.eq.2.and.jk.eq.1) then
+               !!       IF (lwp) write (*,*) '*******!MEDUSA Conservation!*******',kt
+# if defined key_roam
+               !!       IF (lwp) write (*,*) fnit0,fsil0,ffer0,fcar0,falk0,foxy0
+# else
+               !!       IF (lwp) write (*,*) fnit0,fsil0,ffer0
+# endif
+               !!    endif
+               !! endif     
+
+# if defined key_trc_diabio
+               !!======================================================================
+               !! LOCAL GRID CELL DIAGNOSTICS
+               !!======================================================================
+               !!
+               !!----------------------------------------------------------------------
+               !! Full diagnostics key_trc_diabio:
+               !! LOBSTER and PISCES support full diagnistics option key_trc_diabio    
+               !! which gives an option of FULL output of biological sourses and sinks.
+               !! I cannot see any reason for doing this. If needed, it can be done
+               !! as shown below.
+               !!----------------------------------------------------------------------
+               !!
+               IF(lwp) WRITE(numout,*) ' MEDUSA does not support key_trc_diabio'
+               !!               trbio(ji,jj,jk, 1) = fprn
+# endif
+
+               IF( ln_diatrc ) THEN
+                  !!----------------------------------------------------------------------
+                  !! Prepare 2D diagnostics
+                  !!----------------------------------------------------------------------
+                  !!
+                  !! if ((kt / 240*240).eq.kt) then
+                  !!    IF (lwp) write (*,*) '*******!MEDUSA DIAADD!*******',kt
+                  !! endif     
+                  trc2d(ji,jj,1)  = trc2d(ji,jj,1)  + ftot_n                   !! nitrogen inventory
+                  trc2d(ji,jj,2)  = trc2d(ji,jj,2)  + ftot_si                  !! silicon  inventory
+                  trc2d(ji,jj,3)  = trc2d(ji,jj,3)  + ftot_fe                  !! iron     inventory
+                  trc2d(ji,jj,4)  = trc2d(ji,jj,4)  + (fprn  * zphn * fthk)    !! non-diatom production
+                  trc2d(ji,jj,5)  = trc2d(ji,jj,5)  + (fdpn         * fthk)    !! non-diatom non-grazing losses
+                  trc2d(ji,jj,6)  = trc2d(ji,jj,6)  + (fprd  * zphd * fthk)    !! diatom production
+                  trc2d(ji,jj,7)  = trc2d(ji,jj,7)  + (fdpd         * fthk)    !! diatom non-grazing losses
+                  !! diagnostic field  8 is (ostensibly) supplied by trcsed.F            
+                  trc2d(ji,jj,9)  = trc2d(ji,jj,9)  + (fprds * zpds * fthk)    !! diatom silicon production
+                  trc2d(ji,jj,10) = trc2d(ji,jj,10) + (fsdiss  * fthk)         !! diatom silicon dissolution
+                  trc2d(ji,jj,11) = trc2d(ji,jj,11) + (fgmipn  * fthk)         !! microzoo grazing on non-diatoms
+                  trc2d(ji,jj,12) = trc2d(ji,jj,12) + (fgmid   * fthk)         !! microzoo grazing on detrital nitrogen
+                  trc2d(ji,jj,13) = trc2d(ji,jj,13) + (fdzmi   * fthk)         !! microzoo non-grazing losses
+                  trc2d(ji,jj,14) = trc2d(ji,jj,14) + (fgmepn  * fthk)         !! mesozoo  grazing on non-diatoms
+                  trc2d(ji,jj,15) = trc2d(ji,jj,15) + (fgmepd  * fthk)         !! mesozoo  grazing on diatoms
+                  trc2d(ji,jj,16) = trc2d(ji,jj,16) + (fgmezmi * fthk)         !! mesozoo  grazing on microzoo
+                  trc2d(ji,jj,17) = trc2d(ji,jj,17) + (fgmed   * fthk)         !! mesozoo  grazing on detrital nitrogen
+                  trc2d(ji,jj,18) = trc2d(ji,jj,18) + (fdzme   * fthk)         !! mesozoo  non-grazing losses
+                  !! diagnostic field 19 is (ostensibly) supplied by trcexp.F
+                  trc2d(ji,jj,20) = trc2d(ji,jj,20) + (fslown  * fthk)         !! slow sinking detritus N production
+                  trc2d(ji,jj,21) = trc2d(ji,jj,21) + (fdd     * fthk)         !! detrital remineralisation
+                  trc2d(ji,jj,22) = trc2d(ji,jj,22) + (ffetop  * fthk)         !! aeolian  iron addition
+                  trc2d(ji,jj,23) = trc2d(ji,jj,23) + (ffebot  * fthk)         !! seafloor iron addition
+                  trc2d(ji,jj,24) = trc2d(ji,jj,24) + (ffescav * fthk)         !! "free" iron scavenging
+                  trc2d(ji,jj,25) = trc2d(ji,jj,25) + (fjln  * zphn * fthk)    !! non-diatom J  limitation term 
+                  trc2d(ji,jj,26) = trc2d(ji,jj,26) + (fnln  * zphn * fthk)    !! non-diatom N  limitation term 
+                  trc2d(ji,jj,27) = trc2d(ji,jj,27) + (ffln  * zphn * fthk)    !! non-diatom Fe limitation term 
+                  trc2d(ji,jj,28) = trc2d(ji,jj,28) + (fjld  * zphd * fthk)    !! diatom     J  limitation term 
+                  trc2d(ji,jj,29) = trc2d(ji,jj,29) + (fnld  * zphd * fthk)    !! diatom     N  limitation term 
+                  trc2d(ji,jj,30) = trc2d(ji,jj,30) + (ffld  * zphd * fthk)    !! diatom     Fe limitation term 
+                  trc2d(ji,jj,31) = trc2d(ji,jj,31) + (fsld2 * zphd * fthk)    !! diatom     Si limitation term 
+                  trc2d(ji,jj,32) = trc2d(ji,jj,32) + (fsld  * zphd * fthk)    !! diatom     Si uptake limitation term
+                  if (jk.eq.i0100) trc2d(ji,jj,33) = fslownflux                !! slow detritus flux at  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,34) = fslownflux                !! slow detritus flux at  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,35) = fslownflux                !! slow detritus flux at  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,36) = fslownflux                !! slow detritus flux at 1000 m
+                  trc2d(ji,jj,37) = trc2d(ji,jj,37) + fregen                   !! non-fast N  full column regeneration
+                  trc2d(ji,jj,38) = trc2d(ji,jj,38) + fregensi                 !! non-fast Si full column regeneration
+                  if (jk.eq.i0100) trc2d(ji,jj,39) = trc2d(ji,jj,37)           !! non-fast N  regeneration to  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,40) = trc2d(ji,jj,37)           !! non-fast N  regeneration to  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,41) = trc2d(ji,jj,37)           !! non-fast N  regeneration to  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,42) = trc2d(ji,jj,37)           !! non-fast N  regeneration to 1000 m
+                  trc2d(ji,jj,43) = trc2d(ji,jj,43) + (ftempn  * fthk)         !! fast sinking detritus N production
+                  trc2d(ji,jj,44) = trc2d(ji,jj,44) + (ftempsi * fthk)         !! fast sinking detritus Si production
+                  trc2d(ji,jj,45) = trc2d(ji,jj,45) + (ftempfe * fthk)         !! fast sinking detritus Fe production
+                  trc2d(ji,jj,46) = trc2d(ji,jj,46) + (ftempc  * fthk)         !! fast sinking detritus C production
+                  trc2d(ji,jj,47) = trc2d(ji,jj,47) + (ftempca * fthk)         !! fast sinking detritus CaCO3 production
+                  if (jk.eq.i0100) trc2d(ji,jj,48) = ffastn(ji,jj)             !! fast detritus N  flux at  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,49) = ffastn(ji,jj)             !! fast detritus N  flux at  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,50) = ffastn(ji,jj)             !! fast detritus N  flux at  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,51) = ffastn(ji,jj)             !! fast detritus N  flux at 1000 m
+                  if (jk.eq.i0100) trc2d(ji,jj,52) = fregenfast(ji,jj)         !! N  regeneration to  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,53) = fregenfast(ji,jj)         !! N  regeneration to  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,54) = fregenfast(ji,jj)         !! N  regeneration to  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,55) = fregenfast(ji,jj)         !! N  regeneration to 1000 m
+                  if (jk.eq.i0100) trc2d(ji,jj,56) = ffastsi(ji,jj)            !! fast detritus Si flux at  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,57) = ffastsi(ji,jj)            !! fast detritus Si flux at  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,58) = ffastsi(ji,jj)            !! fast detritus Si flux at  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,59) = ffastsi(ji,jj)            !! fast detritus Si flux at 1000 m
+                  if (jk.eq.i0100) trc2d(ji,jj,60) = fregenfastsi(ji,jj)       !! Si regeneration to  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,61) = fregenfastsi(ji,jj)       !! Si regeneration to  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,62) = fregenfastsi(ji,jj)       !! Si regeneration to  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,63) = fregenfastsi(ji,jj)       !! Si regeneration to 1000 m
+                  trc2d(ji,jj,64) = trc2d(ji,jj,64) + (freminn  * fthk)        !! sum of fast-sinking N  fluxes
+                  trc2d(ji,jj,65) = trc2d(ji,jj,65) + (freminsi * fthk)        !! sum of fast-sinking Si fluxes
+                  trc2d(ji,jj,66) = trc2d(ji,jj,66) + (freminfe * fthk)        !! sum of fast-sinking Fe fluxes
+                  trc2d(ji,jj,67) = trc2d(ji,jj,67) + (freminc  * fthk)        !! sum of fast-sinking C  fluxes
+                  trc2d(ji,jj,68) = trc2d(ji,jj,68) + (freminca * fthk)        !! sum of fast-sinking Ca fluxes
+                  if (jk.eq.(mbathy(ji,jj)-1)) then
+                     trc2d(ji,jj,69) = fsedn                                   !! N  sedimentation flux                                  
+                     trc2d(ji,jj,70) = fsedsi                                  !! Si sedimentation flux
+                     trc2d(ji,jj,71) = fsedfe                                  !! Fe sedimentation flux
+                     trc2d(ji,jj,72) = fsedc                                   !! C  sedimentation flux
+                     trc2d(ji,jj,73) = fsedca                                  !! Ca sedimentation flux
+                  endif
+                  if (jk.eq.1)  trc2d(ji,jj,74) = qsr(ji,jj)
+                  if (jk.eq.1)  trc2d(ji,jj,75) = xpar(ji,jj,jk)
+                  !! if (jk.eq.1)  trc2d(ji,jj,75) = real(iters)
+                  !! diagnostic fields 76 to 80 calculated below
+                  trc2d(ji,jj,81) = trc2d(ji,jj,81) + fprn_ml                  !! mixed layer non-diatom production
+                  trc2d(ji,jj,82) = trc2d(ji,jj,82) + fprd_ml                  !! mixed layer     diatom production
+# if defined key_gulf_finland
+                  if (jk.eq.1)  trc2d(ji,jj,83) = real(ibio_switch)            !! Gulf of Finland check
+# else
+                  trc2d(ji,jj,83) = ocal_ccd(ji,jj)                            !! calcite CCD depth
+# endif
+                  trc2d(ji,jj,84) = fccd(ji,jj)                                !! last model level above calcite CCD depth
+                  if (jk.eq.1)     trc2d(ji,jj,85) = xFree                     !! surface "free" iron
+                  if (jk.eq.i0200) trc2d(ji,jj,86) = xFree                     !! "free" iron at  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,87) = xFree                     !! "free" iron at  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,88) = xFree                     !! "free" iron at  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,89) = xFree                     !! "free" iron at 1000 m
+                  !! AXY (27/06/12): extract "euphotic depth"
+                  if (jk.eq.1)     trc2d(ji,jj,90) = xze(ji,jj)
+                  !! 
+                  ftot_pn(ji,jj)  = ftot_pn(ji,jj)  + (zphn * fthk)            !! vertical integral non-diatom phytoplankton
+                  ftot_pd(ji,jj)  = ftot_pd(ji,jj)  + (zphd * fthk)            !! vertical integral diatom phytoplankton
+                  ftot_zmi(ji,jj) = ftot_zmi(ji,jj) + (zzmi * fthk)            !! vertical integral microzooplankton
+                  ftot_zme(ji,jj) = ftot_zme(ji,jj) + (zzme * fthk)            !! vertical integral mesozooplankton
+                  ftot_det(ji,jj) = ftot_det(ji,jj) + (zdet * fthk)            !! vertical integral slow detritus, nitrogen
+                  ftot_dtc(ji,jj) = ftot_dtc(ji,jj) + (zdtc * fthk)            !! vertical integral slow detritus, carbon
+# if defined key_roam
+                  !! ROAM provisionally has access to a further 20 2D diagnostics
+                  if (jk .eq. 1) then
+                     trc2d(ji,jj,91)  = trc2d(ji,jj,91)  + f_wind              !! surface wind
+                     trc2d(ji,jj,92)  = trc2d(ji,jj,92)  + f_pco2a             !! atmospheric pCO2
+                     trc2d(ji,jj,93)  = trc2d(ji,jj,93)  + f_ph                !! ocean pH
+                     trc2d(ji,jj,94)  = trc2d(ji,jj,94)  + f_pco2w             !! ocean pCO2
+                     trc2d(ji,jj,95)  = trc2d(ji,jj,95)  + f_h2co3             !! ocean H2CO3 conc.
+                     trc2d(ji,jj,96)  = trc2d(ji,jj,96)  + f_hco3              !! ocean HCO3 conc.
+                     trc2d(ji,jj,97)  = trc2d(ji,jj,97)  + f_co3               !! ocean CO3 conc.
+                     trc2d(ji,jj,98)  = trc2d(ji,jj,98)  + f_co2flux           !! air-sea CO2 flux
+                     trc2d(ji,jj,99)  = trc2d(ji,jj,99)  + f_omcal(ji,jj)      !! ocean omega calcite 
+                     trc2d(ji,jj,100) = trc2d(ji,jj,100) + f_omarg(ji,jj)      !! ocean omega aragonite
+                     trc2d(ji,jj,101) = trc2d(ji,jj,101) + f_TDIC              !! ocean TDIC
+                     trc2d(ji,jj,102) = trc2d(ji,jj,102) + f_TALK              !! ocean TALK
+                     trc2d(ji,jj,103) = trc2d(ji,jj,103) + f_kw660             !! surface kw660
+                     trc2d(ji,jj,104) = trc2d(ji,jj,104) + f_pp0               !! surface pressure
+                     trc2d(ji,jj,105) = trc2d(ji,jj,105) + f_o2flux            !! air-sea O2 flux
+                     trc2d(ji,jj,106) = trc2d(ji,jj,106) + f_o2sat             !! ocean O2 saturation
+                     trc2d(ji,jj,107) = f2_ccd_cal(ji,jj)                      !! depth calcite CCD
+                     trc2d(ji,jj,108) = f2_ccd_arg(ji,jj)                      !! depth aragonite CCD
+                  endif
+                  if (jk .eq. (mbathy(ji,jj)-1)) then
+                     trc2d(ji,jj,109) = f3_omcal(ji,jj,jk)                     !! seafloor omega calcite
+                     trc2d(ji,jj,110) = f3_omarg(ji,jj,jk)                     !! seafloor omega aragonite
+                  endif
+                  !! diagnostic fields 111 to 117 calculated below
+                  if (jk.eq.i0100) trc2d(ji,jj,118) = ffastca(ji,jj)/MAX(ffastc(ji,jj), rsmall)  !! rain ratio at  100 m
+                  if (jk.eq.i0500) trc2d(ji,jj,119) = ffastca(ji,jj)/MAX(ffastc(ji,jj), rsmall)  !! rain ratio at  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,120) = ffastca(ji,jj)/MAX(ffastc(ji,jj), rsmall)  !! rain ratio at 1000 m
+                  !! AXY (18/01/12): benthic flux diagnostics
+                  if (jk.eq.(mbathy(ji,jj)-1)) then
+                     trc2d(ji,jj,121) = f_sbenin_n(ji,jj)  + f_fbenin_n(ji,jj)
+                     trc2d(ji,jj,122) = f_sbenin_fe(ji,jj) + f_fbenin_fe(ji,jj)
+                     trc2d(ji,jj,123) = f_sbenin_c(ji,jj)  + f_fbenin_c(ji,jj)
+                     trc2d(ji,jj,124) = f_fbenin_si(ji,jj)
+                     trc2d(ji,jj,125) = f_fbenin_ca(ji,jj)
+                     trc2d(ji,jj,126) = f_benout_n(ji,jj)
+                     trc2d(ji,jj,127) = f_benout_fe(ji,jj)
+                     trc2d(ji,jj,128) = f_benout_c(ji,jj)
+                     trc2d(ji,jj,129) = f_benout_si(ji,jj)
+                     trc2d(ji,jj,130) = f_benout_ca(ji,jj)
+                  endif
+                  !! diagnostics fields 131 to 135 calculated below
+                  trc2d(ji,jj,136) = f_runoff(ji,jj)
+                  !! AXY (19/07/12): amended to allow for riverine nutrient addition below surface
+                  trc2d(ji,jj,137) = trc2d(ji,jj,137) + (f_riv_loc_n * fthk)
+                  trc2d(ji,jj,138) = trc2d(ji,jj,138) + (f_riv_loc_si * fthk)
+                  trc2d(ji,jj,139) = trc2d(ji,jj,139) + (f_riv_loc_c * fthk)
+                  trc2d(ji,jj,140) = trc2d(ji,jj,140) + (f_riv_loc_alk * fthk)
+                  trc2d(ji,jj,141) = trc2d(ji,jj,141) + (fslowc  * fthk)       !! slow sinking detritus C production
+                  if (jk.eq.i0100) trc2d(ji,jj,142) = fslowcflux               !! slow detritus flux at  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,143) = fslowcflux               !! slow detritus flux at  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,144) = fslowcflux               !! slow detritus flux at  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,145) = fslowcflux               !! slow detritus flux at 1000 m
+                  trc2d(ji,jj,146)  = trc2d(ji,jj,146)  + ftot_c               !! carbon     inventory
+                  trc2d(ji,jj,147)  = trc2d(ji,jj,147)  + ftot_a               !! alkalinity inventory
+                  trc2d(ji,jj,148)  = trc2d(ji,jj,148)  + ftot_o2              !! oxygen     inventory
+                  if (jk.eq.(mbathy(ji,jj)-1)) then
+                     trc2d(ji,jj,149) = f_benout_lyso_ca(ji,jj)
+                  endif
+                  trc2d(ji,jj,150) = trc2d(ji,jj,150) + (fcomm_resp * fthk)    !! community respiration
+		  !!
+		  !! AXY (14/02/14): a Valentines Day gift to BASIN - a shedload of new
+                  !!                 diagnostics that they'll most likely never need!
+                  !!                 (actually, as with all such gifts, I'm giving them
+                  !!                 some things I'd like myself!)
+                  !! 
+                  !! ----------------------------------------------------------------------
+                  !! linear losses
+                  !! non-diatom
+                  trc2d(ji,jj,151) = trc2d(ji,jj,151) + (fdpn2  * fthk)
+                  !! diatom
+                  trc2d(ji,jj,152) = trc2d(ji,jj,152) + (fdpd2  * fthk)
+                  !! microzooplankton
+                  trc2d(ji,jj,153) = trc2d(ji,jj,153) + (fdzmi2 * fthk)
+                  !! mesozooplankton
+                  trc2d(ji,jj,154) = trc2d(ji,jj,154) + (fdzme2 * fthk)
+                  !! ----------------------------------------------------------------------
+                  !! microzooplankton grazing
+                  !! microzooplankton messy -> N
+                  trc2d(ji,jj,155) = trc2d(ji,jj,155) + (xphi * (fgmipn + fgmid) * fthk)
+                  !! microzooplankton messy -> D
+                  trc2d(ji,jj,156) = trc2d(ji,jj,156) + ((1. - xbetan) * finmi * fthk)
+                  !! microzooplankton messy -> DIC
+                  trc2d(ji,jj,157) = trc2d(ji,jj,157) + (xphi * ((xthetapn * fgmipn) + fgmidc) * fthk)
+                  !! microzooplankton messy -> Dc
+                  trc2d(ji,jj,158) = trc2d(ji,jj,158) + ((1. - xbetac) * ficmi * fthk)
+                  !! microzooplankton excretion
+                  trc2d(ji,jj,159) = trc2d(ji,jj,159) + (fmiexcr * fthk)
+                  !! microzooplankton respiration
+                  trc2d(ji,jj,160) = trc2d(ji,jj,160) + (fmiresp * fthk)
+                  !! microzooplankton growth
+                  trc2d(ji,jj,161) = trc2d(ji,jj,161) + (fmigrow * fthk)
+                  !! ----------------------------------------------------------------------
+                  !! mesozooplankton grazing
+                  !! mesozooplankton messy -> N
+                  trc2d(ji,jj,162) = trc2d(ji,jj,162) + (xphi * (fgmepn + fgmepd + fgmezmi + fgmed) * fthk)
+                  !! mesozooplankton messy -> D
+                  trc2d(ji,jj,163) = trc2d(ji,jj,163) + ((1. - xbetan) * finme * fthk)
+                  !! mesozooplankton messy -> DIC
+                  trc2d(ji,jj,164) = trc2d(ji,jj,164) + (xphi * ((xthetapn * fgmepn) + (xthetapd * fgmepd) + &
+                  &                  (xthetazmi * fgmezmi) + fgmedc) * fthk)
+                  !! mesozooplankton messy -> Dc
+                  trc2d(ji,jj,165) = trc2d(ji,jj,165) + ((1. - xbetac) * ficme * fthk)
+                  !! mesozooplankton excretion
+                  trc2d(ji,jj,166) = trc2d(ji,jj,166) + (fmeexcr * fthk)
+                  !! mesozooplankton respiration
+                  trc2d(ji,jj,167) = trc2d(ji,jj,167) + (fmeresp * fthk)
+                  !! mesozooplankton growth
+                  trc2d(ji,jj,168) = trc2d(ji,jj,168) + (fmegrow * fthk)
+                  !! ----------------------------------------------------------------------
+                  !! miscellaneous
+                  trc2d(ji,jj,169) = trc2d(ji,jj,169) + (fddc    * fthk) !! detrital C remineralisation
+                  trc2d(ji,jj,170) = trc2d(ji,jj,170) + (fgmidc  * fthk) !! microzoo grazing on detrital carbon
+                  trc2d(ji,jj,171) = trc2d(ji,jj,171) + (fgmedc  * fthk) !! mesozoo  grazing on detrital carbon
+                  !!
+                  !! ----------------------------------------------------------------------
+		  !!
+		  !! AXY (23/10/14): extract primary production related surface fields to
+		  !!                 deal with diel cycle issues; hijacking BASIN 150m
+		  !!                 diagnostics to do so (see commented out diagnostics
+		  !!                 below this section)
+		  !!
+		  !! extract fields at surface
+		  if (jk .eq. 1) then
+                     trc2d(ji,jj,172) = zchn              !! Pn chlorophyll
+                     trc2d(ji,jj,173) = zphn              !! Pn biomass
+                     trc2d(ji,jj,174) = fjln              !! Pn J-term
+                     trc2d(ji,jj,175) = (fprn * zphn)     !! Pn PP
+                     trc2d(ji,jj,176) = zchd              !! Pd chlorophyll
+                     trc2d(ji,jj,177) = zphd              !! Pd biomass
+                     trc2d(ji,jj,178) = fjld              !! Pd J-term
+                     trc2d(ji,jj,179) = xpar(ji,jj,jk)    !! Pd PP
+                     trc2d(ji,jj,180) = loc_T             !! local temperature
+                  endif
+		  !!
+		  !! extract fields at 50m (actually 44-50m)
+		  if (jk .eq. 18) then
+                     trc2d(ji,jj,181) = zchn              !! Pn chlorophyll
+                     trc2d(ji,jj,182) = zphn              !! Pn biomass
+                     trc2d(ji,jj,183) = fjln              !! Pn J-term
+                     trc2d(ji,jj,184) = (fprn * zphn)     !! Pn PP
+                     trc2d(ji,jj,185) = zchd              !! Pd chlorophyll
+                     trc2d(ji,jj,186) = zphd              !! Pd biomass
+                     trc2d(ji,jj,187) = fjld              !! Pd J-term
+                     trc2d(ji,jj,188) = xpar(ji,jj,jk)    !! Pd PP
+                     trc2d(ji,jj,189) = loc_T             !! local temperature
+                  endif
+		  !!
+		  !! extract fields at 100m
+		  if (jk .eq. i0100) then
+                     trc2d(ji,jj,190) = zchn              !! Pn chlorophyll
+                     trc2d(ji,jj,191) = zphn              !! Pn biomass
+                     trc2d(ji,jj,192) = fjln              !! Pn J-term
+                     trc2d(ji,jj,193) = (fprn * zphn)     !! Pn PP
+                     trc2d(ji,jj,194) = zchd              !! Pd chlorophyll
+                     trc2d(ji,jj,195) = zphd              !! Pd biomass
+                     trc2d(ji,jj,196) = fjld              !! Pd J-term
+                     trc2d(ji,jj,197) = xpar(ji,jj,jk)    !! Pd PP
+                     trc2d(ji,jj,198) = loc_T             !! local temperature
+                  endif
+                  !! extract relevant BASIN fields at 150m
+                  if (jk .eq. i0150) then
+                     !! trc2d(ji,jj,172) = trc2d(ji,jj,4)    !! Pn PP
+                     !! trc2d(ji,jj,173) = trc2d(ji,jj,151)  !! Pn linear loss
+                     !! trc2d(ji,jj,174) = trc2d(ji,jj,5)    !! Pn non-linear loss
+                     !! trc2d(ji,jj,175) = trc2d(ji,jj,11)   !! Pn grazing to Zmi
+                     !! trc2d(ji,jj,176) = trc2d(ji,jj,14)   !! Pn grazing to Zme
+                     !! trc2d(ji,jj,177) = trc2d(ji,jj,6)    !! Pd PP
+                     !! trc2d(ji,jj,178) = trc2d(ji,jj,152)  !! Pd linear loss
+                     !! trc2d(ji,jj,179) = trc2d(ji,jj,7)    !! Pd non-linear loss
+                     !! trc2d(ji,jj,180) = trc2d(ji,jj,15)   !! Pd grazing to Zme
+                     !! trc2d(ji,jj,181) = trc2d(ji,jj,12)   !! Zmi grazing on D
+                     !! trc2d(ji,jj,182) = trc2d(ji,jj,170)  !! Zmi grazing on Dc
+                     !! trc2d(ji,jj,183) = trc2d(ji,jj,155)  !! Zmi messy feeding loss to N
+                     !! trc2d(ji,jj,184) = trc2d(ji,jj,156)  !! Zmi messy feeding loss to D
+                     !! trc2d(ji,jj,185) = trc2d(ji,jj,157)  !! Zmi messy feeding loss to DIC
+                     !! trc2d(ji,jj,186) = trc2d(ji,jj,158)  !! Zmi messy feeding loss to Dc
+                     !! trc2d(ji,jj,187) = trc2d(ji,jj,159)  !! Zmi excretion
+                     !! trc2d(ji,jj,188) = trc2d(ji,jj,160)  !! Zmi respiration
+                     !! trc2d(ji,jj,189) = trc2d(ji,jj,161)  !! Zmi growth
+                     !! trc2d(ji,jj,190) = trc2d(ji,jj,153)  !! Zmi linear loss
+                     !! trc2d(ji,jj,191) = trc2d(ji,jj,13)   !! Zmi non-linear loss
+                     !! trc2d(ji,jj,192) = trc2d(ji,jj,16)   !! Zmi grazing to Zme
+                     !! trc2d(ji,jj,193) = trc2d(ji,jj,17)   !! Zme grazing on D
+                     !! trc2d(ji,jj,194) = trc2d(ji,jj,171)  !! Zme grazing on Dc
+                     !! trc2d(ji,jj,195) = trc2d(ji,jj,162)  !! Zme messy feeding loss to N
+                     !! trc2d(ji,jj,196) = trc2d(ji,jj,163)  !! Zme messy feeding loss to D
+                     !! trc2d(ji,jj,197) = trc2d(ji,jj,164)  !! Zme messy feeding loss to DIC
+                     !! trc2d(ji,jj,198) = trc2d(ji,jj,165)  !! Zme messy feeding loss to Dc
+                     trc2d(ji,jj,199) = trc2d(ji,jj,166)  !! Zme excretion
+                     trc2d(ji,jj,200) = trc2d(ji,jj,167)  !! Zme respiration
+                     trc2d(ji,jj,201) = trc2d(ji,jj,168)  !! Zme growth
+                     trc2d(ji,jj,202) = trc2d(ji,jj,154)  !! Zme linear loss
+                     trc2d(ji,jj,203) = trc2d(ji,jj,18)   !! Zme non-linear loss
+                     trc2d(ji,jj,204) = trc2d(ji,jj,20)   !! Slow detritus production, N
+                     trc2d(ji,jj,205) = trc2d(ji,jj,21)   !! Slow detritus remineralisation, N
+                     trc2d(ji,jj,206) = trc2d(ji,jj,141)  !! Slow detritus production, C
+                     trc2d(ji,jj,207) = trc2d(ji,jj,169)  !! Slow detritus remineralisation, C
+                     trc2d(ji,jj,208) = trc2d(ji,jj,43)   !! Fast detritus production, N
+                     trc2d(ji,jj,209) = trc2d(ji,jj,21)   !! Fast detritus remineralisation, N
+                     trc2d(ji,jj,210) = trc2d(ji,jj,64)   !! Fast detritus production, C
+                     trc2d(ji,jj,211) = trc2d(ji,jj,67)   !! Fast detritus remineralisation, C
+                     trc2d(ji,jj,212) = trc2d(ji,jj,150)  !! Community respiration
+                     trc2d(ji,jj,213) = fslownflux        !! Slow detritus N flux at 150 m
+                     trc2d(ji,jj,214) = fslowcflux        !! Slow detritus C flux at 150 m
+                     trc2d(ji,jj,215) = ffastn(ji,jj)     !! Fast detritus N flux at 150 m
+                     trc2d(ji,jj,216) = ffastc(ji,jj)     !! Fast detritus C flux at 150 m
+                  endif
+                  !! 
+                  !! Jpalm (11-08-2014)
+                  !! Add UKESM1 diagnoatics 
+                  !!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+                  if ((jk .eq. 1) .and.( jdms.eq.1)) then
+                     trc2d(ji,jj,221) = dms_surf          !! DMS surface concentration 
+                     !! AXY (13/03/15): add in other DMS estimates
+                     trc2d(ji,jj,222) = dms_andr          !! DMS surface concentration 
+                     trc2d(ji,jj,223) = dms_simo          !! DMS surface concentration 
+                     trc2d(ji,jj,224) = dms_aran          !! DMS surface concentration 
+                     trc2d(ji,jj,225) = dms_hall          !! DMS surface concentration 
+                  endif
+# endif
+                  !! other possible future diagnostics include:
+                  !!   - integrated tracer values (esp. biological)
+                  !!   - mixed layer tracer values
+                  !!   - sub-surface chlorophyll maxima (plus depth)
+                  !!   - different mixed layer depth criteria (T, sigma, var. sigma)
+
+                  !!----------------------------------------------------------------------
+                  !! Prepare 3D diagnostics
+                  !!----------------------------------------------------------------------
+                  !!
+                  trc3d(ji,jj,jk,1)  = ((fprn + fprd) * zphn)     !! primary production  
+                  trc3d(ji,jj,jk,2)  = fslownflux + ffastn(ji,jj) !! detrital flux
+                  trc3d(ji,jj,jk,3)  = fregen + (freminn * fthk)  !! remineralisation
+# if defined key_roam
+                  trc3d(ji,jj,jk,4)  = f3_pH(ji,jj,jk)            !! pH
+                  trc3d(ji,jj,jk,5)  = f3_omcal(ji,jj,jk)         !! omega calcite
+# else
+                  trc3d(ji,jj,jk,4)  = ffastsi(ji,jj)             !! fast Si flux
+# endif
+             ENDIF   ! end of ln_diatrc option
+             !! CLOSE wet point IF..THEN loop
+            endif
+         !! CLOSE horizontal loops
+         END DO
+         END DO
+      !! CLOSE vertical loop
+      END DO
+
+      !!----------------------------------------------------------------------
+      !! Process benthic in/out fluxes
+      !! These can be handled outside of the 3D calculations since the
+      !! benthic pools (and fluxes) are 2D in nature; this code is
+      !! (shamelessly) borrowed from corresponding code in the LOBSTER
+      !! model
+      !!----------------------------------------------------------------------
+      !!
+      !! IF(lwp) WRITE(numout,*) 'AXY: rdt = ', rdt
+      if (jorgben.eq.1) then
+         za_sed_n(:,:)  = zn_sed_n(:,:)  + & 
+         &                ( f_sbenin_n(:,:)  + f_fbenin_n(:,:)  - f_benout_n(:,:)  ) * (rdt / 86400.)
+         zn_sed_n(:,:)  = za_sed_n(:,:)
+         !!
+         za_sed_fe(:,:) = zn_sed_fe(:,:) + &
+         &                ( f_sbenin_fe(:,:) + f_fbenin_fe(:,:) - f_benout_fe(:,:) ) * (rdt / 86400.)
+         zn_sed_fe(:,:) = za_sed_fe(:,:)
+         !!
+         za_sed_c(:,:)  = zn_sed_c(:,:)  + &
+         &                ( f_sbenin_c(:,:)  + f_fbenin_c(:,:)  - f_benout_c(:,:)  ) * (rdt / 86400.)
+         zn_sed_c(:,:)  = za_sed_c(:,:)
+      endif
+      if (jinorgben.eq.1) then
+         za_sed_si(:,:) = zn_sed_si(:,:) + & 
+         &                ( f_fbenin_si(:,:) - f_benout_si(:,:) ) * (rdt / 86400.)
+         zn_sed_si(:,:) = za_sed_si(:,:)
+         !!
+         za_sed_ca(:,:) = zn_sed_ca(:,:) + &
+         &                ( f_fbenin_ca(:,:) - f_benout_ca(:,:) ) * (rdt / 86400.)
+         zn_sed_ca(:,:) = za_sed_ca(:,:)
+      endif
+      DO jj = 2,jpjm1
+         DO ji = 2,jpim1
+            trc2d(ji,jj,131) = za_sed_n(ji,jj)
+            trc2d(ji,jj,132) = za_sed_fe(ji,jj)
+            trc2d(ji,jj,133) = za_sed_c(ji,jj)
+            trc2d(ji,jj,134) = za_sed_si(ji,jj)
+            trc2d(ji,jj,135) = za_sed_ca(ji,jj)
+         ENDDO
+      ENDDO
+
+      if (ibenthic.eq.2) then
+         !! The code below (in this if ... then ... endif loop) is
+         !! effectively commented out because it does not work as 
+         !! anticipated; it can be deleted at a later date
+      if (jorgben.eq.1) then
+         za_sed_n(:,:)  = ( f_sbenin_n(:,:)  + f_fbenin_n(:,:)  - f_benout_n(:,:)  ) * rdt
+         za_sed_fe(:,:) = ( f_sbenin_fe(:,:) + f_fbenin_fe(:,:) - f_benout_fe(:,:) ) * rdt
+         za_sed_c(:,:)  = ( f_sbenin_c(:,:)  + f_fbenin_c(:,:)  - f_benout_c(:,:)  ) * rdt
+      endif
+      if (jinorgben.eq.1) then
+         za_sed_si(:,:) = ( f_fbenin_si(:,:) - f_benout_si(:,:) ) * rdt
+         za_sed_ca(:,:) = ( f_fbenin_ca(:,:) - f_benout_ca(:,:) ) * rdt
+      endif
+      !!
+      !! Leap-frog scheme - only in explicit case, otherwise the time stepping
+      !! is already being done in trczdf
+      !! IF( l_trczdf_exp .AND. (ln_trcadv_cen2 .OR. ln_trcadv_tvd) ) THEN
+      !!    zfact = 2. * rdttra(jk) * FLOAT( ndttrc )
+      !!    IF( neuler == 0 .AND. kt == nittrc000 )   zfact = rdttra(jk) * FLOAT(ndttrc)
+      !!    if (jorgben.eq.1) then
+      !!       za_sed_n(:,:)  = zb_sed_n(:,:)  + ( zfact * za_sed_n(:,:)  )
+      !!      za_sed_fe(:,:) = zb_sed_fe(:,:) + ( zfact * za_sed_fe(:,:) )
+      !!       za_sed_c(:,:)  = zb_sed_c(:,:)  + ( zfact * za_sed_c(:,:)  )
+      !!    endif
+      !!    if (jinorgben.eq.1) then
+      !!       za_sed_si(:,:) = zb_sed_si(:,:) + ( zfact * za_sed_si(:,:) )
+      !!       za_sed_ca(:,:) = zb_sed_ca(:,:) + ( zfact * za_sed_ca(:,:) )
+      !!    endif
+      !! ENDIF
+      !! 
+      !! Time filter and swap of arrays
+      IF( ln_trcadv_cen2 .OR. ln_trcadv_tvd  ) THEN         ! centred or tvd scheme
+         IF( neuler == 0 .AND. kt == nittrc000 ) THEN
+            if (jorgben.eq.1) then
+               zb_sed_n(:,:)  = zn_sed_n(:,:)
+               zn_sed_n(:,:)  = za_sed_n(:,:)
+               za_sed_n(:,:)  = 0.0
+               !!
+               zb_sed_fe(:,:) = zn_sed_fe(:,:)
+               zn_sed_fe(:,:) = za_sed_fe(:,:)
+               za_sed_fe(:,:) = 0.0
+               !!
+               zb_sed_c(:,:)  = zn_sed_c(:,:)
+               zn_sed_c(:,:)  = za_sed_c(:,:)
+               za_sed_c(:,:)  = 0.0
+            endif
+            if (jinorgben.eq.1) then
+               zb_sed_si(:,:) = zn_sed_si(:,:)
+               zn_sed_si(:,:) = za_sed_si(:,:)
+               za_sed_si(:,:) = 0.0
+               !!
+               zb_sed_ca(:,:) = zn_sed_ca(:,:)
+               zn_sed_ca(:,:) = za_sed_ca(:,:)
+               za_sed_ca(:,:) = 0.0
+            endif
+         ELSE
+            if (jorgben.eq.1) then
+               zb_sed_n(:,:)  = (atfp  * ( zb_sed_n(:,:)  + za_sed_n(:,:)  )) + (atfp1 * zn_sed_n(:,:) )
+               zn_sed_n(:,:)  = za_sed_n(:,:)
+               za_sed_n(:,:)  = 0.0
+               !!
+               zb_sed_fe(:,:) = (atfp  * ( zb_sed_fe(:,:) + za_sed_fe(:,:) )) + (atfp1 * zn_sed_fe(:,:))
+               zn_sed_fe(:,:) = za_sed_fe(:,:)
+               za_sed_fe(:,:) = 0.0
+               !!
+               zb_sed_c(:,:)  = (atfp  * ( zb_sed_c(:,:)  + za_sed_c(:,:)  )) + (atfp1 * zn_sed_c(:,:) )
+               zn_sed_c(:,:)  = za_sed_c(:,:)
+               za_sed_c(:,:)  = 0.0
+            endif
+            if (jinorgben.eq.1) then
+               zb_sed_si(:,:) = (atfp  * ( zb_sed_si(:,:) + za_sed_si(:,:) )) + (atfp1 * zn_sed_si(:,:))
+               zn_sed_si(:,:) = za_sed_si(:,:)
+               za_sed_si(:,:) = 0.0
+               !!
+               zb_sed_ca(:,:) = (atfp  * ( zb_sed_ca(:,:) + za_sed_ca(:,:) )) + (atfp1 * zn_sed_ca(:,:))
+               zn_sed_ca(:,:) = za_sed_ca(:,:)
+               za_sed_ca(:,:) = 0.0
+            endif
+         ENDIF
+      ELSE                                                   !  case of smolar scheme or muscl
+         if (jorgben.eq.1) then
+            zb_sed_n(:,:)  = za_sed_n(:,:)
+            zn_sed_n(:,:)  = za_sed_n(:,:)
+            za_sed_n(:,:)  = 0.0
+            !!
+            zb_sed_fe(:,:) = za_sed_fe(:,:)
+            zn_sed_fe(:,:) = za_sed_fe(:,:)
+            za_sed_fe(:,:) = 0.0
+            !!
+            zb_sed_c(:,:)  = za_sed_c(:,:)
+            zn_sed_c(:,:)  = za_sed_c(:,:)
+            za_sed_c(:,:)  = 0.0
+         endif
+         if (jinorgben.eq.1) then
+            zb_sed_si(:,:) = za_sed_si(:,:)
+            zn_sed_si(:,:) = za_sed_si(:,:)
+            za_sed_si(:,:) = 0.0
+            !!
+            zb_sed_ca(:,:) = za_sed_ca(:,:)
+            zn_sed_ca(:,:) = za_sed_ca(:,:)
+            za_sed_ca(:,:) = 0.0
+         endif
+      ENDIF
+      endif
+
+      IF( ln_diatrc ) THEN
+         !!----------------------------------------------------------------------
+         !! Output several accumulated diagnostics
+         !!   - biomass-average phytoplankton limitation terms
+         !!   - integrated tendency terms
+         !!----------------------------------------------------------------------
+         !! 
+         DO jj = 2,jpjm1
+            DO ji = 2,jpim1
+               !! non-diatom phytoplankton limitations
+               trc2d(ji,jj,25)  = trc2d(ji,jj,25) / MAX(ftot_pn(ji,jj), rsmall)
+               trc2d(ji,jj,26)  = trc2d(ji,jj,26) / MAX(ftot_pn(ji,jj), rsmall)
+               trc2d(ji,jj,27)  = trc2d(ji,jj,27) / MAX(ftot_pn(ji,jj), rsmall)
+               !! diatom phytoplankton limitations
+               trc2d(ji,jj,28)  = trc2d(ji,jj,28) / MAX(ftot_pd(ji,jj), rsmall)
+               trc2d(ji,jj,29)  = trc2d(ji,jj,29) / MAX(ftot_pd(ji,jj), rsmall)
+               trc2d(ji,jj,30)  = trc2d(ji,jj,30) / MAX(ftot_pd(ji,jj), rsmall)
+               trc2d(ji,jj,31)  = trc2d(ji,jj,31) / MAX(ftot_pd(ji,jj), rsmall)
+               trc2d(ji,jj,32)  = trc2d(ji,jj,32) / MAX(ftot_pd(ji,jj), rsmall)
+               !! tendency terms
+               trc2d(ji,jj,76)  = fflx_n(ji,jj)
+               trc2d(ji,jj,77)  = fflx_si(ji,jj)
+               trc2d(ji,jj,78)  = fflx_fe(ji,jj)
+               !! integrated biomass
+               trc2d(ji,jj,79)  = ftot_pn(ji,jj)       !! integrated non-diatom phytoplankton
+               trc2d(ji,jj,80)  = ftot_pd(ji,jj)       !! integrated diatom phytoplankton
+               trc2d(ji,jj,217) = ftot_zmi(ji,jj)      !! Integrated microzooplankton
+               trc2d(ji,jj,218) = ftot_zme(ji,jj)      !! Integrated mesozooplankton
+               trc2d(ji,jj,219) = ftot_det(ji,jj)      !! Integrated slow detritus, nitrogen
+               trc2d(ji,jj,220) = ftot_dtc(ji,jj)      !! Integrated slow detritus, carbon
+# if defined key_roam
+               !! the balance of nitrogen production/consumption
+               trc2d(ji,jj,111) = fnit_prod(ji,jj)  !! integrated nitrogen production
+               trc2d(ji,jj,112) = fnit_cons(ji,jj)  !! integrated nitrogen consumption
+               !! the balance of carbon production/consumption
+               trc2d(ji,jj,113) = fcar_prod(ji,jj)  !! integrated carbon production
+               trc2d(ji,jj,114) = fcar_cons(ji,jj)  !! integrated carbon consumption
+               !! the balance of oxygen production/consumption
+               trc2d(ji,jj,115) = foxy_prod(ji,jj)  !! integrated oxygen production
+               trc2d(ji,jj,116) = foxy_cons(ji,jj)  !! integrated oxygen consumption
+               trc2d(ji,jj,117) = foxy_anox(ji,jj)  !! integrated unrealised oxygen consumption
+# endif
+            END DO
+         END DO
+
+# if defined key_roam
+#  if defined key_axy_nancheck
+         !!----------------------------------------------------------------------
+         !! Check for NaNs in diagnostic outputs
+         !!----------------------------------------------------------------------
+         !! 
+         !! 2D diagnostics
+         DO jn = 1,150
+            fq0 = SUM(trc2d(:,:,jn))
+            !! AXY (30/01/14): "isnan" problem on HECTOR
+            !! if (fq0 /= fq0 ) then
+            if ( ieee_is_nan( fq0 ) ) then
+               !! there's a NaN here
+               if (lwp) write(numout,*) 'NAN detected in 2D diagnostic field', jn, 'at time', kt, 'at position:'
+               DO jj = 1,jpj
+                  DO ji = 1,jpi
+                     if ( ieee_is_nan( trc2d(ji,jj,jn) ) ) then
+                        if (lwp) write (numout,'(a,3i6)') 'NAN-CHECK', &
+                        &        ji, jj, jn
+                     endif
+                  enddo
+               enddo
+	       CALL ctl_stop( 'trcbio_medusa, NAN in 2D diagnostic field' )
+            endif
+         ENDDO
+         !!
+         !! 3D diagnostics
+         DO jn = 1,5
+            fq0 = SUM(trc3d(:,:,:,jn))
+            !! AXY (30/01/14): "isnan" problem on HECTOR
+            !! if (fq0 /= fq0 ) then
+            if ( ieee_is_nan( fq0 ) ) then
+               !! there's a NaN here
+               if (lwp) write(numout,*) 'NAN detected in 3D diagnostic field', jn, 'at time', kt, 'at position:'
+               DO jk = 1,jpk
+                  DO jj = 1,jpj
+                     DO ji = 1,jpi
+                        if ( ieee_is_nan( trc3d(ji,jj,jk,jn) ) ) then
+                           if (lwp) write (numout,'(a,4i6)') 'NAN-CHECK', &
+                           &        ji, jj, jk, jn
+                        endif
+                     enddo
+                  enddo
+               enddo
+	       CALL ctl_stop( 'trcbio_medusa, NAN in 3D diagnostic field' )
+            endif
+         ENDDO
+	 CALL flush(numout)
+#  endif
+# endif
+
+         !!----------------------------------------------------------------------
+         !! Don't know what this does; belongs to someone else ...
+         !!----------------------------------------------------------------------
+         !! 
+         !! Lateral boundary conditions on trc2d
+         DO jn=1,jp_medusa_2d
+             CALL lbc_lnk(trc2d(:,:,jn),'T',1. )
+         END DO 
+
+         !! Lateral boundary conditions on trc3d
+         DO jn=1,jp_medusa_3d
+             CALL lbc_lnk(trc3d(:,:,1,jn),'T',1. )
+         END DO 
+
+# if defined key_axy_nodiag
+         !!----------------------------------------------------------------------
+         !! Blank diagnostics as a NaN-trap
+         !!----------------------------------------------------------------------
+         !! 
+         !! blank 2D diagnostic array
+         trc2d(:,:,:) = 0.e0
+         !!
+         !! blank 3D diagnostic array
+         trc3d(:,:,:,:) = 0.e0
+# endif
+
+# if defined key_iomput
+         !!----------------------------------------------------------------------
+         !! Add in XML diagnostics stuff
+         !!----------------------------------------------------------------------
+         !!
+         !! ** 2D diagnostics
+         DO jn=1,jp_medusa_2d
+            CALL iom_put(TRIM(ctrc2d(jn)), trc2d(:,:,jn))
+         END DO
+!! AXY (17/02/14): don't think I need this if I modify the above for all diagnostics
+!! #  if defined key_roam
+!!          DO jn=91,jp_medusa_2d
+!!             CALL iom_put(TRIM(ctrc2d(jn)), trc2d(:,:,jn))
+!!          END DO      
+!! #  endif
+         !!
+         !! ** 3D diagnostics
+         DO jn=1,jp_medusa_3d
+            CALL iom_put(TRIM(ctrc3d(jn)), trc3d(:,:,:,jn))
+         END DO
+!! AXY (17/02/14): don't think I need this if I modify the above for all diagnostics
+!! #  if defined key_roam
+!!          CALL iom_put(TRIM(ctrc3d(5)), trc3d(:,:,:,5))
+!! #  endif
+# endif
+      ENDIF ! end of ln_diatrc option
+
+# if defined key_trc_diabio
+      !! Lateral boundary conditions on trcbio
+      DO jn=1,jp_medusa_trd
+          CALL lbc_lnk(trbio(:,:,1,jn),'T',1. )
+      END DO 
+# endif
+
+# if defined key_debug_medusa
+      IF(lwp) WRITE(numout,*) ' MEDUSA exiting trc_bio_medusa at kt =', kt
+      CALL flush(numout)
+# endif
+
+   END SUBROUTINE trc_bio_medusa
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No MEDUSA bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE trc_bio_medusa( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'trc_bio_medusa: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_bio_medusa
+#endif 
+
+   !!======================================================================
+END MODULE  trcbio_medusa
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcco2_medusa.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcco2_medusa.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcco2_medusa.F90	(revision 5707)
@@ -0,0 +1,1128 @@
+MODULE trcco2_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcco2_medusa  ***
+   !! TOP :   MEDUSA
+   !!======================================================================
+   !! History :
+   !!  -   !  2010-12  (A. Yool)             added for ROAM project
+   !!----------------------------------------------------------------------
+#if defined key_medusa && defined key_roam
+   !!----------------------------------------------------------------------
+   !!                                        MEDUSA carbonate chemistry
+   !!----------------------------------------------------------------------
+   !!   trc_co2_medusa        :  
+   !!----------------------------------------------------------------------
+      USE oce_trc
+      USE trc
+      USE sms_medusa
+      USE lbclnk
+      USE prtctl_trc      ! Print control for debugging
+      USE in_out_manager  ! I/O manager
+
+      IMPLICIT NONE
+      PRIVATE
+      
+      PUBLIC   trc_co2_medusa    ! called in trc_bio_medusa
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id: trcbio.F90 1146 2008-06-25 11:42:56Z rblod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+! The following is a map of the subroutines contained within this module
+! - trc_co2_medusa
+!      - CALLS CO2_dynamics
+!           - CALLS CO2DYN
+!		 - CALLS POLYCO
+!		      - CALLS CO2SET
+!		      - CALLS CO2CLC
+!           - CALLS CaCO3_Saturation
+!      - CALLS Air_sea_exchange
+
+CONTAINS
+
+!=======================================================================
+!
+      SUBROUTINE trc_co2_medusa( Temp, Sal, DIC, ALK, Depth, Wnd, pCO2a, &
+      pH, pCO2w, h2co3, hco3, co3, om_cal, om_arg, co2flux, TDIC, TALK,  &
+      dcf, henry, iters )
+!      
+!=======================================================================
+!  
+! This file contains a set of FORTRAN subroutines that calculate the carbonate system 
+! at any given point in marine space time, given values for 
+! temperature, salinity, DIC, depth (pressure). 
+! This is essentially an implimentation of the Haltafall speciation code
+! (Ingri et al 1967, Talanta 14, 1261 - if it ain't broke don't fix it)
+! Another routine calulates the air sea exchange of CO2 given wind speed and atmospheric pCO2.
+! Code developed by Jerry blackford and others at PML, based on pre-existing code.
+! We accept no liability for errors or inaccuracies.
+! See Zeebe & Wolf-Gladrow, 2001. CO2 in seawater: equilibrium, kinetics and isotopes. 
+! Elsevier Oceanography Series 65, 346. for a reasonable overview. 
+! Many other packages exist, replicating the same functionality in different languages.
+! See http://cdiac.ornl.gov/oceans/co2rprt.html (CO2sys)
+! or  http://neon.otago.ac.nz/research/mfc/people/keith_hunter/software/swco2/
+! reference for prior usage of this code: Blackford & Gilbert, 2007. J Mar Sys 64, 229-241.
+! 
+! Modifications
+! 17/02/2010. Added conversion factor from per m3 to per kg (line 108-133)
+! 17/02/2010. Update calculation of K1, K2, Kb to make consistant with the OCMIP protocols.
+! 29/07/2011. Merged into MEDUSA with a raft of changes to this subroutine; less elsewhere
+!
+! Changes for MEDUSA include: 
+!     - making the program a module
+!     - passing in input variables (obvious given the last point)
+!     - making alkalinity a state variable (rather than a function of salinity)
+!
+      IMPLICIT NONE
+
+      REAL(wp), INTENT( in )    :: Temp       ! degrees C
+      REAL(wp), INTENT( in )    :: Sal        ! PSU
+      REAL(wp), INTENT( in )    :: DIC        ! mmol / m3
+      REAL(wp), INTENT( in )    :: ALK        ! meq  / m3
+      REAL(wp), INTENT( in )    :: Depth      ! m
+      REAL(wp), INTENT( in )    :: Wnd        ! m / s
+      REAL(wp), INTENT( in )    :: pCO2a      ! uatm
+!----------------------------------------------------------------------
+      REAL(wp), INTENT( inout ) :: pH         ! "normal" pH units
+      REAL(wp), INTENT( inout ) :: pCO2w      ! uatm
+      REAL(wp), INTENT( inout ) :: h2co3      ! mmol / m3
+      REAL(wp), INTENT( inout ) :: hco3       ! mmol / m3
+      REAL(wp), INTENT( inout ) :: co3        ! mmol / m3
+      REAL(wp), INTENT( inout ) :: om_cal     ! normalised
+      REAL(wp), INTENT( inout ) :: om_arg     ! normalised
+      REAL(wp), INTENT( inout ) :: co2flux    ! mmol / m2 / d
+      REAL(wp), INTENT( inout ) :: TDIC       ! umol / kg
+      REAL(wp), INTENT( inout ) :: TALK       ! ueq  / kg
+      REAL(wp), INTENT( inout ) :: dcf        ! m3 / kg
+      REAL(wp), INTENT( inout ) :: henry      ! ?
+      INTEGER,  INTENT( inout ) :: iters      ! # iterations to convergence
+!----------------------------------------------------------------------
+!     REAL(wp) :: cco2,bicarb,carb,henry
+      REAL(wp) :: cco2,bicarb,carb
+! ======================================================================
+
+! write inputs to screen
+!  WRITE(*,*) " "
+!  WRITE(*,'(A28)')       "    .........Inputs........."
+!  WRITE(*,'(A24,F10.3)') "    Temperature   (C) = ", Temp
+!  WRITE(*,'(A24,F10.3)') "    Salinity    (psu) = ", Sal
+!  WRITE(*,'(A24,F10.3)') "    Depth         (m) = ", Depth
+!  WRITE(*,'(A24,F10.3)') "    DIC     (mmol/m3) = ", DIC
+!  WRITE(*,'(A24,F10.3)') "    ALK      (ueq/m3) = ", ALK
+!  WRITE(*,'(A24,F10.3)') "    Wind speed  (m/s) = ", Wnd
+!  WRITE(*,'(A24,F10.3)') "    pCO2 atmos (uatm) = ", pCO2a
+
+! AXY (07/05/13) ==================================================
+! set total number of iterations to zero
+      iters = 0
+! AXY (07/05/13) ==================================================
+  
+   call CO2_dynamics( Temp, Sal, Depth, DIC, ALK, pCO2a, &                  ! inputs
+      pco2w, ph, h2co3, hco3, co3, henry, om_cal, om_arg, TDIC, TALK, &     ! outputs
+      dcf, iters)                                                           ! outputs
+
+   ! AXY (18/08/11): only do air-sea exchange calculation if depth = 0 
+   !                 (i.e. surface calculations being performed)
+   if (Depth .eq. 0.0) then
+      call Air_sea_exchange( Temp, Wnd, pCO2w, pCO2a, henry, dcf, &         ! inputs
+         co2flux )                                                          ! output
+   else
+      co2flux = 0.0
+   endif      
+
+! AXY (09/01/14) ==================================================
+! check for non-convergence and NaNs
+   !!
+   if (iters .eq. 25) then
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: ITERS WARNING, ', &
+      iters, ' AT depth =', Depth
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: ztmp    =', Temp
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: zsal    =', Sal
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: zdic    =', DIC
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: zalk    =', ALK
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: f_wind  =', Wnd
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: f_ph    =', ph
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: f_pco2w =', pCO2w
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: f_h2co3 =', h2co3
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: f_hco3  =', hco3
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: f_co3   =', co3
+   endif
+   !!
+   !! AXY (29/10/13): NaN checks
+   if (co2flux /= co2flux) then
+      !! if (lwp) write (numout,'(a,1pe10.2,4i6)') 'CO2FLUX-NAN', &
+      !! &        tmask(ji,jj,jk), kt, ji, jj, jk
+      if (lwp) write (numout,'(a,a,f10.3,a,f10.3)') 'CO2FLUX-NAN', &
+      &        ' TMP', Temp, ' SAL', Sal
+      if (lwp) write (numout,'(a,a,f10.3,a,f10.3)') 'CO2FLUX-NAN', &
+      &        ' DIC', DIC, ' ALK', ALK
+      if (lwp) write (numout,'(a,a,f10.3,a,f10.3)') 'CO2FLUX-NAN', &
+      &        ' WND', Wnd, ' PH ', ph
+      if (lwp) write (numout,'(a,a,i6)') 'CO2FLUX-NAN', &
+      &        ' ITERS', iters
+   endif
+   !!
+   !! AXY (09/01/14): NaN fudges
+   if (co2flux /= co2flux) then
+      ph      = 8.1
+      pCO2w   = pCO2a
+      h2co3   = 0.005 * DIC
+      hco3    = 0.865 * DIC
+      co3     = 0.130 * DIC
+      om_cal  = 4.
+      om_arg  = 2.
+      co2flux = 0.
+      TDIC    = DIC
+      TALK    = ALK
+      dcf     = 1.
+      henry   = 1.
+   endif
+! AXY (09/01/14) ==================================================
+
+! write outputs to screen
+!  WRITE(*,*) " "
+!  WRITE(*,'(A32,F10.3)') "    ..........Outputs..........."
+!  WRITE(*,'(A27,F10.3)') "    pH                 (pH) = ", pH
+!  WRITE(*,'(A27,F10.3)') "    DIC           (umol/kg) = ", TDIC
+!  WRITE(*,'(A27,F10.3)') "    TALK           (ueq/kg) = ", TALK
+!  WRITE(*,'(A27,F10.3)') "    pco2w            (uatm) = ", pco2w
+!  WRITE(*,'(A27,F10.3)') "    carbonic acid (mmol/m3) = ", h2co3
+!  WRITE(*,'(A27,F10.3)') "    bicarbonate   (mmol/m3) = ", bicarb
+!  WRITE(*,'(A27,F10.3)') "    carbonate     (mmol/m3) = ", carb
+!  WRITE(*,'(A27,F10.3)') "    Omega calcite       (~) = ", om_cal
+!  WRITE(*,'(A27,F10.3)') "    Omega aragonite     (~) = ", om_arg
+!  WRITE(*,'(A27,F10.3)') "    air sea flux(mmol/m2/d) = ", flux
+!  WRITE(*,*) " "
+
+   END SUBROUTINE trc_co2_medusa
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+      subroutine CO2_dynamics( T, S, Z, DIC, TALK, pco2a, &
+      pco2w, ph, h2co3, bicarb, carb, henry, om_cal, om_arg, TCO2, TA, &
+      dcf, iters )
+!      
+!=======================================================================
+!  
+   IMPLICIT NONE
+
+      REAL(wp), INTENT( in )    :: T          ! temperature (C)
+      REAL(wp), INTENT( in )    :: S          ! salinity (psu)
+      REAL(wp), INTENT( in )    :: Z          ! depth (metres)
+      REAL(wp), INTENT( in )    :: DIC        ! total dissolved inorganic carbon (mmol.m-3)
+      REAL(wp), INTENT( in )    :: TALK       ! total alkalinity (meq.m-3)
+      REAL(wp), INTENT( in )    :: pco2a      ! atmospheric pCO2
+!----------------------------------------------------------------------
+      REAL(wp), INTENT( inout ) :: pco2w      ! seawater pCO2
+      REAL(wp), INTENT( inout ) :: ph         ! seawater pH
+      REAL(wp), INTENT( inout ) :: h2co3      ! seawater carbonic acid (H2CO3)
+      REAL(wp), INTENT( inout ) :: bicarb     ! seawater bicarbonate ion (HCO3)
+      REAL(wp), INTENT( inout ) :: carb       ! seawater carbonate ion (CO3)
+      REAL(wp), INTENT( inout ) :: henry      ! Henry constant
+      REAL(wp), INTENT( inout ) :: om_cal     ! Omega calcite
+      REAL(wp), INTENT( inout ) :: om_arg     ! Omega aragonite
+      REAL(wp), INTENT( inout ) :: TCO2       ! total dissolved inorganic carbon (mol.kg-1)
+      REAL(wp), INTENT( inout ) :: TA         ! total alkalinity (eq.kg-1)
+      REAL(wp), INTENT( inout ) :: dcf        ! density conversion factor
+      INTEGER,  INTENT( inout ) :: iters      ! # iterations to convergence
+!----------------------------------------------------------------------
+      REAL(wp) :: a, b, c
+      REAL(wp) :: ca, bc, cb
+      REAL(wp) :: pco2water, fairco2
+
+! ======================================================================
+
+! Adjust to correct units.
+! Haltafall uses mol/kg rather than umol/kg necessitating a scaling factor of /1.0D6
+! DIC (mmol/m3) needs to be converted to umol/kg via the calculation of water density at prevailing T&S
+! sea-water density (Millero & Poisson, Deep-Sea Research, 1981, also known as UNESCO, 1981)
+! with T: Temperature in degree Celsius; S: Salinity in practical units, density in kg/m3
+! valid for 0<T<40 and 0.5<S<43. Density Conversion factor (dcf) = * density * 1.0D3
+
+          a   =  8.24493d-1 - 4.0899d-3*T +  7.6438d-5*T**2 - 8.2467d-7*T**3 + 5.3875d-9*T**4
+          b   = -5.72466d-3 + 1.0227d-4*T - 1.6546d-6*T**2 
+          c   = 4.8314d-4
+          dcf = (999.842594 + 6.793952d-2*T- 9.095290d-3*T**2 + 1.001685d-4*T**3 &
+                - 1.120083d-6*T**4 + 6.536332d-9*T**5+a*S+b*S**1.5+c*S**2)/1.0D3
+
+          TA    = TALK / (1.0D6*dcf)
+          TCO2  = DIC  / (1.0D6*dcf)
+
+! Call the parent routine for the carbonate system
+          CALL CO2DYN ( TCO2, TA, T, S, pco2a, &     ! inputs
+          pco2water, pH, HENRY, ca, bc, cb, iters )  ! outputs
+
+! Adjust outputs back to units used in the parent model code (e.g. mmol/m3) if appropriate
+
+          pco2w  = pco2water * (1.0D6) 	! partial pressure of co2 in water 
+          TA     = TA * (1.0D6)         ! total alkalinity (umol/kg)
+          h2co3  = ca * (1.0D6*dcf)     ! carbonic acid concentration (mmol/m3)
+          bicarb = bc * (1.0D6*dcf)     ! bicarbonate ion concentration (mmol/m3)
+          carb   = cb * (1.0D6*dcf)     ! carbonate ion concentration (mmol/m3)
+          TCO2   = TCO2 * (1.0D6)       ! total C or DIC in units of umol/kg
+
+! Call carbonate saturation state subroutine to calculate calcite and aragonite calcification states
+
+          CALL CaCO3_Saturation ( T, S, Z, cb, &  ! inputs
+          om_cal, om_arg )                        ! outputs
+
+   RETURN
+
+   END SUBROUTINE CO2_dynamics
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+      SUBROUTINE Air_sea_exchange( T, Wnd, pco2w, pco2a, henry, dcf, &
+      flux )
+!      
+!=======================================================================
+!  
+!  This routine should be called for the surface box only (like, duh)
+!  Uses the Nightingale and Liss parameterisation (GBC 14, 373-388 (2000).
+!  SC is the Schmidt number from Wanninkhof (1992, JGR 97,7373-7382), the Nightingale et al (2000)
+!  transfer velocity being for Sc=600 and the dependence of tranfer velocity on Sc coming 
+!  from Jahne et al (1987, J. Geophys Res 92, 1937-1949).
+
+!  Inputs
+!  pCO2w    partial pressure of CO2 in the water (from carbonate system subroutine call)
+!  pCO2a    partial pressure of CO2 in the atmosphere (usually external forcing).
+!  T        temperature (C)
+!  Wnd      wind speed, metres
+!  Henry    henry's constant
+!  density  the density of water for conversion between mmol/m3 and umol/kg
+
+!  Outputs are
+!  flux     flux of CO2 in mmol C /m2/d 
+!           +ve is in-gassing (air to sea), -ve is outgassing (sea to air).
+
+   IMPLICIT NONE
+
+      REAL(wp), INTENT( in )    :: T, wnd, pco2w, pco2a, henry, dcf ! INPUT PARAMETERS:
+!-----------------------------------------------------------------------
+      REAL(wp), INTENT( inout ) :: flux                             ! OUTPUT Variables
+!-----------------------------------------------------------------------
+      REAL(wp)                  :: sc, fwind                        ! LOCAL VARIABLES:
+
+! calculate the Schmidt number and unit conversions
+          sc    = 2073.1-125.62*T+3.6276*T**2.0-0.0432190*T**3.0
+          fwind = (0.222d0 * wnd**2d0 + 0.333d0 * wnd)*(sc/660.d0)**(-0.5)
+          fwind = fwind*24.d0/100.d0   ! convert to m/day
+
+! flux depends on the difference in partial pressures, wind and henry
+! here it is rescaled to mmol/m2/d
+          flux = fwind * henry * ( pco2a - pco2w ) * dcf
+
+  RETURN 
+
+  END SUBROUTINE Air_sea_exchange
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+      SUBROUTINE CO2dyn ( TCO2, TA, T, S, PCO2A, PCO2, PH, HENRY, ca, bc, cb, iters )
+!      
+!=======================================================================
+!
+!     This subroutine acts as an interface to the Haltafall iteration, setting options etc.
+
+      REAL(wp), INTENT( in )    :: TCO2, TA, T, S, PCO2A
+!-----------------------------------------------------------------------
+      REAL(wp), INTENT( inout ) :: PCO2, PH, HENRY, ca, bc, cb
+      INTEGER,  INTENT( inout ) :: iters
+!-----------------------------------------------------------------------
+      REAL(wp) :: PRSS
+      INTEGER  :: MCONC, MKVAL, ICONST, ICALC
+
+      PARAMETER ( MCONC = 9,MKVAL = 4 )
+
+      REAL(wp), DIMENSION(MKVAL) :: AKVAL
+      REAL(wp), DIMENSION(MCONC) :: CONCS
+
+      ICONST = 6
+      PRSS = 1.0D0
+      CONCS(1) = TCO2
+      CONCS(2) = TA
+      ICALC = 1
+      
+      CALL POLYCO(PRSS,T,S,CONCS,MCONC,AKVAL,MKVAL,ICALC,ICONST,iters)
+
+      if(iters.eq.25) then
+         ! AXY (13/05/13): this location has failed to converge; use
+         !                 some standard values to plug the hole
+         CONCS(3) = PCO2A * 1E-06 ! atmospheric value
+         CONCS(4) = 8.1           ! global average pH
+         CONCS(5) = TCO2 * 0.005  ! some "standard" values plucked
+         CONCS(6) = TCO2 * 0.865  ! from pages 5-6 of Zeebe & Wolf-
+         CONCS(7) = TCO2 * 0.130  ! Gladow (2001)
+         AKVAL(1) = 0.5E-01       ! trial-and-error value
+         IF(lwp) THEN
+            WRITE(numout,*) ' CO2DYN : reset failed outputs'
+         ENDIF
+      endif
+
+      PCO2  = CONCS(3)
+      PH    = CONCS(4)
+      ca    = CONCS(5)
+      bc    = CONCS(6)
+      cb    = CONCS(7)
+      HENRY = AKVAL(1)
+    
+      RETURN
+
+      END SUBROUTINE
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+      SUBROUTINE POLYCO(PD,TD,SD,CONCS,NCONC,AKVAL,NKVAL,ICALC,ICONST,iters)
+!      
+!=======================================================================
+!
+! MASTER SUBROUTINE FOR CALCULATION OF THE CO2 SYSTEM THERMODYNAMICS
+!
+! EXPLANATION OF POLYCO PARAMETERS
+!       AXY (16/08/11): Yuri change for non-surface carbonate chemistry 
+!       P - PRESSURE IN ATMOSPHERES (P<>1 CODED only for ICONST=3 and ICONST=6)
+!       T - TEMPERATURE IN DEG.C
+!       S - SALINITY IN PPT
+!      CONCS(1) - TOTAL C (MOL/KG)
+!      CONCS(2) - TOTAL ALKALINITY (MOL/KG)
+!      CONCS(3) - PCO2 (ATM)
+!      CONCS(4) - PH
+!      CONCS(5) - {H2CO3} (MOL/KG)
+!      CONCS(6) - {HCO3} (MOL/KG)
+!      CONCS(7) - {CO3} (MOL/KG)
+!        CONCS(8) - CARBONATE ALKALINITY  ) FOR ICONST = 4,5,6
+!        CONCS(9) - BORATE ALKALINITY     )       ONLY
+!         NCONC - SIZE OF CONCS ARRAY (7 FOR ICONST=1,2,3; 9 FOR ICONST
+!     AKVAL(1) - KP (HENRY'S LAW CONSTANT) (MOL/KG/ATM)
+!     AKVAL(2) - K1C (H2CO3 DISSOCIATION) (MOL/KG)
+!       AKVAL(3) - K2C (HCO3 DISSOCIATION) (MOL/KG)
+!       AKVAL(4) - KB (B(OH)3 DISSOCIATION) (MOL/KG)  FOR ICONST=4,5,6
+!        NKVAL - SIZE OF AKVAL ARRAY (3 FOR ICONST=1,2,3; 4 FOR ICONST=
+!        ICALC - SELECTION OF THE TWO INPUT PARAMETERS:
+!       ICALC = 1  TOTAL C AND ALKALINITY
+!       ICALC = 2  TOTAL C AND PCO2
+!       ICALC = 3  TOTAL C AND PH
+!       ICALC = 4  ALKALINITY AND PCO2
+!       ICALC = 5  ALKALINITY AND PH
+!       ICALC = 6  PCO2 AND PH
+!       ICALC = 7  CALCULATE CONSTANTS AKVAL ONLY
+!       ICONST - SELECTION OF PH SCALE AND COMPONENTS:
+!       ICONST = 1  NBS PH SCALE
+!       ICONST = 2  HANSSON'S SCALE (SWS WITHOUT FLUORIDE)
+!       ICONST = 3  SWS PH SCALE
+!       ICONST = 4  AS 1 BUT INCLUDING BORATE IN THE CALCULATION
+!       ICONST = 5  AS 2 BUT INCLUDING BORATE IN THE CALCULATION
+!       ICONST = 6  AS 3 BUT INCLUDING BORATE IN THE CALCULATION
+
+!  NOTE: FOR ICONST=1,2,3 CONCS(2) REPRESENTS CARBONATE ALKALINITY SINC
+!        BORATE IS NOT INCLUDED IN THE CALCULATION. FOR ICONST=4,5,6 CO
+!        REPRESENTS TOTAL ALKALINITY (CARBONATE + BORATE), THE COMPONEN
+!        WHICH ARE GIVEN IN CONCS(8) AND CONCS(9)
+
+      REAL(wp) :: PMIN, PMAX, SMIN, SMAX, TMIN, TMAX, & 
+     &     PD, TD, SD, P, T, S, BTOT
+      INTEGER  :: MINJC, MAXJC, MINJK, MAXJK, MINCAL, MAXCAL, MINCON,  &
+     &     MAXCON, NCONC, NKVAL, ICALC, ICONST, IC, iters
+      LOGICAL  :: BORON
+
+      PARAMETER(MINJC=7,MAXJC=9,MINJK=3,MAXJK=4)
+      PARAMETER(MINCAL=1,MAXCAL=7,MINCON=1,MAXCON=6)
+      !! AXY (11/08/11): TMIN changed to -2 to stop error messages in polar regions
+      !! AXY (09/01/14): TMIN changed to -3 to stop error messages in polar regions
+      !! AXY (03/03/14): SMAX changed to 42 to stop error messages in salty regions (the Great Answer ...)
+      !! AXY (05/03/14): SMAX changed to 45 to stop error messages in salty regions
+      PARAMETER(PMIN=0.99999D0,PMAX=1.00001D0,SMIN=0.0D0,  &
+     &  SMAX=45.0D0,TMIN=-3.0D0,TMAX=40.0D0)
+      REAL(wp), DIMENSION(NKVAL) :: AKVAL
+      REAL(wp), DIMENSION(NCONC) :: CONCS
+
+      P = PD
+      S = SD
+      T = TD
+      
+      !! AXY (09/08/11): STOP statements commented out and WARNING messages added
+      IF(lwp) THEN
+         IF(T.LT.TMIN.OR.T.GT.TMAX) WRITE(numout,*) ' trc_co2_medusa: T WARNING, ', T, TMIN, TMAX, S, P
+         IF(S.LT.SMIN.OR.S.GT.SMAX) WRITE(numout,*) ' trc_co2_medusa: S WARNING, ', S, SMIN, SMAX, T, P
+         IF(P.LT.PMIN.OR.P.GT.PMAX) WRITE(numout,*) ' trc_co2_medusa: P WARNING, ', P, PMIN, PMAX, T, S
+      ENDIF
+      ! IF(T.LT.TMIN.OR.T.GT.TMAX)WRITE (*,*) P, S, T, TMIN, TMAX
+      ! IF(P.LT.PMIN.OR.P.GT.PMAX) STOP'POLYCO - PRESSURE OUT OF RANGE'
+      ! IF(S.LT.SMIN.OR.S.GT.SMAX) STOP'POLYCO - SALINITY OUT OF RANGE'
+      ! IF(T.LT.TMIN.OR.T.GT.TMAX) STOP'POLYCO - TEMP. OUT OF RANGE'
+
+      !! AXY (17/04/13): iMARNET climate change simulation appears to be compromised
+      !!                 by excessive Caspian Sea salinity (> 45 PSU); this may be
+      !!                 a runoff glitch that doesn't manifest on local instance of
+      !!                 NEMO; fudging this here by replacing excessively high
+      !!                 salinity values with maximum salinity value for the purpose
+      !!                 of carbonate chemistry calculations; if this works, a more
+      !!                 sensible solution might be to kill Caspian, etc.
+      IF(lwp) THEN
+         IF(S.LT.SMIN) THEN
+            WRITE(numout,*) ' trc_co2_medusa: S RESET, ', S, '->', SMIN
+            S = SMIN
+         ENDIF
+         IF(S.GT.SMAX) THEN
+            WRITE(numout,*) ' trc_co2_medusa: S RESET, ', S, '->', SMAX
+            S = SMAX
+         ENDIF
+      ENDIF
+      
+      !! AXY (28/02/13): as above, but for T; this has been done for 1/4-degree
+      !!                 simulations to provide a temporary fix to a strange
+      !!                 glitch in ocean temperature; basically, T has been found
+      !!                 to spike upwards arbitrarily (e.g. 24C -> 53C); this 
+      !!                 causes the carbonate chemistry calculations to fail;
+      !!                 this fix aims to stop the problem so that we can estimate
+      !!                 how frequent a problem this is; it's suggestive of a
+      !!                 memory leak
+      IF(lwp) THEN
+         IF(T.LT.TMIN) THEN
+            WRITE(numout,*) ' trc_co2_medusa: T RESET, ', T, '->', TMIN
+            T = TMIN
+         ENDIF
+         IF(T.GT.TMAX) THEN
+            WRITE(numout,*) ' trc_co2_medusa: T RESET, ', T, '->', TMAX
+            T = TMAX
+         ENDIF
+      ENDIF
+     
+      IF(ICALC.LT.MINCAL.OR.ICALC.GT.MAXCAL) STOP 'POLYCO - ICALC OUT OR RANGE'
+      IF(ICONST.LT.MINCON.OR.ICONST.GT.MAXCON) STOP 'POLYCO - ICONST OUT OF RANGE'
+      BORON=(ICONST.GT.3)
+      IF(BORON) THEN
+        IC=ICONST-3
+        BTOT=0.0004128D0*S/35.0D0
+        IF(NCONC.NE.MAXJC) STOP 'POLYCO - WRONG NCONC VALUE'
+        IF(NKVAL.NE.MAXJK) STOP 'POLYCO - WRONG NKVAL VALUE'
+      ELSE
+        IC=ICONST
+        IF(NCONC.NE.MINJC) STOP 'POLYCO - WRONG NCONC VALUE'
+        IF(NKVAL.NE.MINJK) STOP 'POLYCO - WRONG NKVAL VALUE'
+      ENDIF
+
+      CALL CO2SET(P,T,S,AKVAL,NKVAL,IC)
+
+      IF(ICALC.LT.MAXCAL)  &
+     & CALL CO2CLC(CONCS,NCONC,AKVAL,NKVAL,ICALC,BORON,BTOT,iters)
+
+      RETURN
+
+      END SUBROUTINE
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+      SUBROUTINE CO2SET(P,T,S,AKVAL,NKVAL,IC)
+!      
+!=======================================================================
+!
+! Routine to calculate CO2 system constants under the conditions set by
+! P,S,T     (NOTE: PRESSURE <> 1ATM IS NOT YET CODED)
+
+! I. Calculate constants at P=1 and S=0 using
+
+!      ln K0  =  A + B/TK + C ln TK
+!                                   (where TK is in Kelvin)
+
+! II. Calculate constants at P=1 and salinity S using
+
+!    ln K  =  ln K0 + (a0 + a1/TK + a2 ln TK) S**1/2
+!                 + (b0 + b1TK + b2TK**2) S
+
+! The sources of the coefficients are as follows:
+
+!  IC=                  1                    2                  3
+!               (NBS pH scale)        (SWS pH scale       (SWS pH scale
+!                                       with no F)
+
+!  KP            WEISS (1974)           WEISS(1974)          WEISS(1974
+
+!  K1C )      MEHRBACH ACC. TO       HANSSON ACC. TO    HANSSON AND MEH
+!  K2C )       MILLERO (1979)         MILLERO (1979)      ACC. TO DICKS
+!   KB )                                                 AND MILLERO (1
+!                                                         (K1C AND K2C
+!                                                           HANSSON ACC
+!                                                            MILLERO (1
+!                                                              (KB ONLY
+
+! ***
+!      IMPLICIT real*8 (A-H,O-Z)
+
+!     Modified by jcb 17/02/10 to use OCMIP calculations of K1, K2, Kb. 
+!     Differences are subtle rather than significant
+
+      INTEGER             :: MAXK, MAXCON, NKVAL, ICON, IC, IK
+! ***
+      PARAMETER(MAXK=4,MAXCON=3)
+      REAL(wp), DIMENSION(MAXK)        :: A, B, C
+      REAL(wp), DIMENSION(MAXK,MAXCON) :: A0, A1, A2
+      REAL(wp), DIMENSION(MAXK,MAXCON) :: B0, B1, B2
+      REAL(wp), DIMENSION(NKVAL)       :: AKVAL
+!     AXY (16/08/11): Yuri change for non-surface carbonate chemistry 
+!     REAL(wp)            :: P,T,S,VAL,TK
+      REAL(wp)            :: P,T,S,VAL,TK, delta, kappa, Rgas
+      REAL(wp)            :: dlogTK, S2, sqrtS, S15, k1, k2, kb
+! ***
+!     AXY (16/08/11): Yuri change for non-surface carbonate chemistry 
+      DATA Rgas/83.131/
+
+      DATA A/-167.8108D0, 290.9097D0, 207.6548D0, 148.0248D0/
+      DATA B/9345.17D0, -14554.21D0, -11843.79D0, -8966.9D0/
+      DATA C/23.3585D0, -45.0575D0, -33.6485D0, -24.4344D0/
+      DATA (A0(1,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (A0(2,ICON),ICON=1,MAXCON) /0.0221D0, 0.5709D0, -45.8076D0/
+      DATA (A0(3,ICON),ICON=1,MAXCON) /0.9805D0, 1.4853D0, -39.5492D0/
+      DATA (A0(4,ICON),ICON=1,MAXCON) /0.0473D0, 0.5998D0, 0.5998D0/
+      DATA (A1(1,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (A1(2,ICON),ICON=1,MAXCON) /34.02D0, -84.25D0, 1935.07D0/
+      DATA (A1(3,ICON),ICON=1,MAXCON) /-92.65D0, -192.69D0, 1590.14D0/
+      DATA (A1(4,ICON),ICON=1,MAXCON) /49.10D0, -75.25D0, -75.25D0/
+      DATA (A2(1,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (A2(2,ICON),ICON=1,MAXCON) /2*0.0D0,6.9513D0/
+      DATA (A2(3,ICON),ICON=1,MAXCON) /2*0.0D0,6.1523D0/
+      DATA (A2(4,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (B0(1,ICON),ICON=1,MAXCON) /3*0.023517D0/
+      DATA (B0(2,ICON),ICON=1,MAXCON) /0.0D0,-0.01632D0,-0.01566D0/
+      DATA (B0(3,ICON),ICON=1,MAXCON) /-0.03294D0,-0.05058D0,-0.04997D0/
+      DATA (B0(4,ICON),ICON=1,MAXCON) /0.0D0, -0.01767D0, -0.01767D0/
+      DATA (B1(1,ICON),ICON=1,MAXCON) /3*-2.3656D-4/
+      DATA (B1(2,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (B1(3,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (B1(4,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (B2(1,ICON),ICON=1,MAXCON) /3*4.7036D-7/
+      DATA (B2(2,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (B2(3,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (B2(4,ICON),ICON=1,MAXCON) /3*0.0D0/
+
+      TK=T+273.15D0
+      DO 100 IK=1,NKVAL
+        VAL=A(IK) + B(IK)/TK + C(IK)*LOG(TK)
+        VAL=VAL + (A0(IK,IC) + A1(IK,IC)/TK + A2(IK,IC)*LOG(TK))*SQRT(S)
+        VAL=VAL + (B0(IK,IC) + B1(IK,IC)*TK + B2(IK,IC)*TK*TK)*S
+        AKVAL(IK)=EXP(VAL)
+100    CONTINUE
+
+      IF (IC .EQ. 3) THEN
+!  Calculation of constants as used in the OCMIP process for ICONST = 3 or 6
+!  see http://www.ipsl.jussieu.fr/OCMIP/
+!  added jcb 17/02/10
+
+!  Derive simple terms used more than once
+	dlogTK = log(TK)
+	S2 = S*S
+	sqrtS = sqrt(S)
+	S15 = S**1.5
+! k1 = [H][HCO3]/[H2CO3]
+! k2 = [H][CO3]/[HCO3]
+! Millero p.664 (1995) using Mehrbach et al. data on seawater scale 
+	k1=10**(-1*(3670.7/TK - 62.008 + 9.7944*dlogTK - &
+     &		0.0118 * S + 0.000116*S2))
+	k2=10**(-1*(1394.7/TK + 4.777 - &
+     &		0.0184*S + 0.000118*S2))
+! AXY (16/08/11): Yuri change for non-surface carbonate chemistry 
+! Correction for high pressure (from Millero 1995)
+! added YA 04/10/2010
+        delta=-25.5+0.1271*T
+        kappa=(-3.08+0.0877*T)/1000.0
+        k1=k1*exp((-delta+0.5*kappa*P)*P/(Rgas*TK))
+        delta=-15.82-0.0219*T
+        kappa=(1.13-0.1475*T)/1000.0
+        k2=k2*exp((-delta+0.5*kappa*P)*P/(Rgas*TK))
+
+! kb = [H][BO2]/[HBO2]
+! Millero p.669 (1995) using data from Dickson (1990)
+	kb=exp((-8966.90 - 2890.53*sqrtS - 77.942*S + &
+     &		1.728*S15 - 0.0996*S2)/TK + &
+     &		(148.0248 + 137.1942*sqrtS + 1.62142*S) + &
+     &		(-24.4344 - 25.085*sqrtS - 0.2474*S) * &
+     &		dlogTK + 0.053105*sqrtS*TK)
+! AXY (16/08/11): Yuri change for non-surface carbonate chemistry 
+! Correction for high pressure (from Millero, 1995)
+! added YA 04/10/2010
+        delta=-29.48+0.1622*T-0.002608*T**2.0
+        kappa=-2.84/1000.0
+        kb=kb*exp((-delta+0.5*kappa*P)*P/(Rgas*TK))
+! Correction for high pressure of Kw (from Millero 1995)
+! added YA 04/10/2010
+        delta=-25.60+0.2324*T-0.0036246*T**2
+        kappa=(-5.13+0.0794*T)/1000.0
+        AKVAL(1)=AKVAL(1)*exp((-delta+0.5*kappa*P)*P/(Rgas*TK))
+
+! replace haltafall calculations with OCMIP calculations
+      AKVAL(2) = k1
+      AKVAL(3) = k2
+      AKVAL(4) = kb
+      END IF ! section implimenting OCMIP coefficients
+
+      RETURN
+      END SUBROUTINE
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+      SUBROUTINE CO2CLC(CONCS,NCONC,AKVAL,NKVAL,ICALC,BORON,BTOT,iters)
+!      
+!=======================================================================
+! 
+! ROUTINE TO CARRY OUT CO2 CALCULATIONS WITH 2 FIXED PARAMETERS ACCORDI
+! THE EQUATIONS GIVEN BY PARKS(1969) AND SKIRROW (1975)
+! WITH ADDITIONS FOR INCLUDING BORON IF BORON=.TRUE.
+
+
+!      IMPLICIT real*8 (A-H,O-Z)
+      INTEGER             :: NCONC, NKVAL, ICALC, II, KARL, LQ, iters
+! AXY (07/05/13) ==================================================
+! put counter in to check duration in convergence loop
+      INTEGER             :: COUNTER,C_CHECK,C_SW,III
+! AXY (07/05/13) ==================================================
+      REAL(wp)            :: CTOT,ALK,PCO2,PH,H2CO3,HCO3,CO3,ALKC
+      REAL(wp)            :: ALKB,AKP,AK1C,AK2C,AKB,BTOT
+      REAL(wp)            :: AKR,AHPLUS
+      REAL(wp)            :: PROD,tol1,tol2,tol3,tol4,steg,fak
+      REAL(wp)            :: STEGBY,Y,X,W,X1,Y1,X2,Y2,FACTOR,TERM,Z
+      REAL(wp), DIMENSION(NCONC) :: CONCS
+      REAL(wp), DIMENSION(NKVAL) :: AKVAL
+      REAL(wp), DIMENSION(9)     :: CONCS2
+      REAL(wp), DIMENSION(4)     :: AKVAL2
+
+! AXY (07/05/13) ==================================================
+! setup array to store old values of concs
+      real(wp),DIMENSION(:) :: old_CONCS(NCONC)
+! AXY (07/05/13) ==================================================
+
+      EQUIVALENCE (CTOT  , CONCS2(1)), (ALK   , CONCS2(2)),  &
+     &            (PCO2  , CONCS2(3)), (PH    , CONCS2(4)),  &
+     &            (H2CO3 , CONCS2(5)), (HCO3  , CONCS2(6)),  &
+     &            (CO3   , CONCS2(7)), (ALKC  , CONCS2(8)),  &
+     &            (ALKB  , CONCS2(9)),                       &
+     &            (AKP   , AKVAL2(1)), (AK1C  , AKVAL2(2)),  &
+     &            (AK2C  , AKVAL2(3)), (AKB   , AKVAL2(4))
+      LOGICAL             :: BORON,DONE
+
+! AXY (07/05/13) ==================================================
+!  DERIVING PH REQUIRES FOLLOWING LOOP TO CONVERGE.
+!  THIS SUBROUTINE RELIES ON CONVERGENCE.  IF THE ENVIRONMENTAL
+!  CONDITIONS DO NOT ALLOW FOR CONVERGENCE (IN 3D MODEL THIS IS
+!  LIKELY TO OCCUR NEAR LOW SALINITY REGIONS) THE MODEL WILL 
+!  BE STUCK IN THE LOOP.  TO AVOID THIS A CONVERGENCE CONDITION
+!  IS PUT IN PLACE TO SET A FLAGG OF -99 IN THE PH VAR FOR NON CONVEGENCE. 
+!  THE MODEL IS THEN ALLOWED TO CONTINUE. 'COUNTER, C_SW,C_CHECK' ARE 
+!  THE LOCAL VARS USED.
+! C_SW = condition of convergence 0=yes, 1= no
+! COUNTER = number of iterations
+! C_CHECK = maximum number of iterations
+
+! SET COUNTER AND SWITCH TO ZERO AND OFF
+      COUNTER=0
+      C_SW=0
+! FROM EXPERIENCE IF THE ITERATIONS IN THE FOLLOWING DO LOOP
+! EXCEEDS 15 CONVERGENCE WILL NOT OCCUR.  THE OVERHEAD OF 25 ITERATIONS 
+! IS OK FOR SMALL DOMAINS WITH 1/10 AND 1/15 DEG RESOLUTION.
+! I RECOMMEND A LOWER VALUE OF 15 FOR HIGHER RESOLUTION OR LARGER DOMAINS.
+      C_CHECK=25
+! AXY (07/05/13) ==================================================
+
+      DO 100 II=1,NCONC
+        CONCS2(II)=CONCS(II)
+
+! AXY (07/05/13) ==================================================
+! IF CONVERGENCE IS NOT ACHIEVED THE LOCAL ARRAY CONCS MUST BE STORED TO 
+! ALLOW THE MODEL TO CONTINUE. THEREFORE ....
+! UPDATE OLD_CONCS
+        old_CONCS(II)=CONCS(II)
+! AXY (07/05/13) ==================================================
+
+100    CONTINUE
+      DO 110 II=1,NKVAL
+        AKVAL2(II)=AKVAL(II)
+110    CONTINUE
+      AKR = AK1C/AK2C
+      AHPLUS=10.0D0**(-PH)
+      PROD=AKR*AKP*PCO2
+     
+      IF(BORON) THEN
+
+        IF(ICALC.EQ.1.OR.ICALC.EQ.4) THEN
+!         *** ALK, BTOT AND CTOT OR PCO2 FIXED ***
+!         *** ITERATIVE CALCULATION NECESSARY HERE
+
+!         SET INITIAL GUESSES AND TOLERANCE
+          H2CO3=PCO2*AKP
+          CO3=ALK/10.0D0
+          AHPLUS=1.0D-8
+          ALKB=BTOT
+          TOL1=ALK/1.0D5
+          TOL2=H2CO3/1.0D5
+          TOL3=CTOT/1.0D5
+          TOL4=BTOT/1.0D5
+
+!         HALTAFALL iteration to determine CO3, ALKB, AHPLUS
+          KARL=1
+          STEG=2.0D0
+          FAK=1.0D0
+          STEGBY=0.4D0
+10        DONE=.TRUE.
+
+! AXY (07/05/13) ==================================================
+! SET COUNTER UPDATE. FLAG 10 IS THE POINT OF RETURN FOR 
+! THE CONVERGENCE CONDITION
+          COUNTER=COUNTER+1
+	  iters  = COUNTER
+! CHECK IF CONVERGENCE HAS OCCURED IN THE NUMBER OF 
+! ACCEPTABLE ITTERATIONS.  SET C_SW TO LET MODEL KNOW
+! WHAT TO DO AT THE END OF THE SUBROUTINE
+          if(counter.ge.c_check)then
+             IF(lwp) THEN
+                WRITE(numout,*) ' CO2CLC : ITERS WARNING, ', iters
+             ENDIF
+             c_sw=1
+             GOTO 123
+          endif
+! AXY (07/05/13) ==================================================
+
+          IF(ICALC.EQ.4) THEN
+!         *** PCO2 IS FIXED ***
+            Y=AHPLUS*AHPLUS*CO3/(AK1C*AK2C)
+            IF(ABS(Y-H2CO3).GT.TOL2) THEN
+              CO3=CO3*H2CO3/Y
+              DONE=.FALSE.
+            ENDIF
+          ELSEIF(ICALC.EQ.1) THEN
+!           *** CTOT IS FIXED ***
+            Y=CO3*(1.0D0+AHPLUS/AK2C+AHPLUS*AHPLUS/(AK1C*AK2C))
+            IF(ABS(Y-CTOT).GT.TOL3) THEN
+              CO3=CO3*CTOT/Y
+              DONE=.FALSE.
+            ENDIF
+          ENDIF
+          Y=ALKB*(1.0D0+AHPLUS/AKB)
+          IF(ABS(Y-BTOT).GT.TOL4) THEN
+            ALKB=ALKB*BTOT/Y
+            DONE=.FALSE.
+          ENDIF
+
+! Alkalinity is equivalent to -(total H+), so the sign of W is opposite
+! to that normally used
+
+          Y=CO3*(2.0D0+AHPLUS/AK2C)+ALKB
+          IF(ABS(Y-ALK).GT.TOL1) THEN
+            DONE=.FALSE.
+            X=LOG(AHPLUS)
+!           W=SIGN(1.0D0,Y-ALK)
+            IF ( Y-ALK .GE. 0.0D0 ) THEN
+            W=1.0D0
+            ELSE
+            W=-1.0D0
+            ENDIF
+            IF(W.GE.0.0D0) THEN
+              X1=X
+              Y1=Y
+            ELSE
+              X2=X
+              Y2=Y
+            ENDIF
+            LQ=KARL
+            IF(LQ.EQ.1) THEN
+              KARL=2*NINT(W)
+            ELSEIF(IABS(LQ).EQ.2.AND.(LQ*W).LT.0.) THEN
+              FAK=0.5D0
+              KARL=3
+            ENDIF
+            IF(KARL.EQ.3.AND.STEG.LT.STEGBY) THEN
+              W=(X2-X1)/(Y2-Y1)
+              X=X1+W*(ALK-Y1)
+            ELSE
+              STEG=STEG*FAK
+              X=X+STEG*W
+            ENDIF
+            AHPLUS=EXP(X)  
+          ENDIF
+          IF(.NOT.DONE) GOTO 10
+          
+          HCO3=CO3*AHPLUS/AK2C
+          IF(ICALC.EQ.4) THEN
+            CTOT=H2CO3+HCO3+CO3
+          ELSEIF(ICALC.EQ.1) THEN
+            H2CO3=HCO3*AHPLUS/AK1C
+            PCO2=H2CO3/AKP
+          ENDIF
+          PH=-LOG10(AHPLUS)
+          ALKC=ALK-ALKB
+        ELSEIF(ICALC.EQ.2) THEN
+!         *** CTOT, PCO2, AND BTOT FIXED ***
+          Y=SQRT(PROD*(PROD-4.0D0*AKP*PCO2+4.0D0*CTOT))
+          H2CO3=PCO2*AKP
+          HCO3=(Y-PROD)/2.0D0
+          CO3=CTOT-H2CO3-HCO3
+          ALKC=HCO3+2.0D0*CO3
+          AHPLUS=AK1C*H2CO3/HCO3
+          PH=-LOG10(AHPLUS)
+          ALKB=BTOT/(1.0D0+AHPLUS/AKB)
+          ALK=ALKC+ALKB
+        ELSEIF(ICALC.EQ.3) THEN
+!         *** CTOT, PH AND BTOT FIXED ***
+          FACTOR=CTOT/(AHPLUS*AHPLUS+AK1C*AHPLUS+AK1C*AK2C)
+          CO3=FACTOR*AK1C*AK2C
+          HCO3=FACTOR*AK1C*AHPLUS
+          H2CO3=FACTOR*AHPLUS*AHPLUS
+          PCO2=H2CO3/AKP
+          ALKC=HCO3+2.0D0*CO3
+          ALKB=BTOT/(1.0D0+AHPLUS/AKB)
+          ALK=ALKC+ALKB
+        ELSEIF(ICALC.EQ.5) THEN
+!         *** ALK, PH AND BTOT FIXED ***
+          ALKB=BTOT/(1.0D0+AHPLUS/AKB)
+          ALKC=ALK-ALKB
+          HCO3=ALKC/(1.0D0+2.0D0*AK2C/AHPLUS)
+          CO3=HCO3*AK2C/AHPLUS
+          H2CO3=HCO3*AHPLUS/AK1C
+          PCO2=H2CO3/AKP
+          CTOT=H2CO3+HCO3+CO3
+        ELSEIF(ICALC.EQ.6) THEN
+!         *** PCO2, PH AND BTOT FIXED ***
+          ALKB=BTOT/(1.0D0+AHPLUS/AKB)
+          H2CO3=PCO2*AKP
+          HCO3=H2CO3*AK1C/AHPLUS
+          CO3=HCO3*AK2C/AHPLUS
+          CTOT=H2CO3+HCO3+CO3
+          ALKC=HCO3+2.0D0*CO3
+          ALK=ALKC+ALKB
+        ENDIF
+      ELSE
+        IF(ICALC.EQ.1) THEN
+!         *** CTOT AND ALK FIXED ***
+          TERM=4.0D0*ALK+CTOT*AKR-ALK*AKR
+          Z=SQRT(TERM*TERM+4.0D0*(AKR-4.0D0)*ALK*ALK)
+          CO3=(ALK*AKR-CTOT*AKR-4.0D0*ALK+Z)/(2.0D0*(AKR-4.0D0))
+          HCO3=(CTOT*AKR-Z)/(AKR-4.0D0)
+          H2CO3=CTOT-ALK+CO3
+          PCO2=H2CO3/AKP
+          PH=-LOG10(AK1C*H2CO3/HCO3)
+        ELSEIF(ICALC.EQ.2) THEN
+!         *** CTOT AND PCO2 FIXED ***
+          Y=SQRT(PROD*(PROD-4.0D0*AKP*PCO2+4.0D0*CTOT))
+          H2CO3=PCO2*AKP
+          HCO3=(Y-PROD)/2.0D0
+          CO3=CTOT-H2CO3-HCO3
+          ALK=HCO3+2.0D0*CO3
+          PH=-LOG10(AK1C*H2CO3/HCO3)
+        ELSEIF(ICALC.EQ.3) THEN
+!         *** CTOT AND PH FIXED ***
+          FACTOR=CTOT/(AHPLUS*AHPLUS+AK1C*AHPLUS+AK1C*AK2C)
+          CO3=FACTOR*AK1C*AK2C
+          HCO3=FACTOR*AK1C*AHPLUS
+          H2CO3=FACTOR*AHPLUS*AHPLUS
+          PCO2=H2CO3/AKP
+          ALK=HCO3+2.0D0*CO3
+        ELSEIF(ICALC.EQ.4) THEN
+!         *** ALK AND PCO2 FIXED ***
+          TERM=SQRT((8.0D0*ALK+PROD)*PROD)
+          CO3=ALK/2.0D0+PROD/8.0D0-TERM/8.0D0
+          HCO3=-PROD/4.0D0+TERM/4.0D0
+          H2CO3=PCO2*AKP
+          CTOT=CO3+HCO3+H2CO3
+          PH=-LOG10(AK1C*H2CO3/HCO3)
+        ELSEIF(ICALC.EQ.5) THEN
+!         *** ALK AND PH FIXED ***
+          HCO3=ALK/(1.0D0+2.0D0*AK2C/AHPLUS)
+          CO3=HCO3*AK2C/AHPLUS
+          H2CO3=HCO3*AHPLUS/AK1C
+          PCO2=H2CO3/AKP
+          CTOT=H2CO3+HCO3+CO3
+        ELSEIF(ICALC.EQ.6) THEN
+!         *** PCO2 AND PH FIXED ***
+          H2CO3=PCO2*AKP
+          HCO3=H2CO3*AK1C/AHPLUS
+          CO3=HCO3*AK2C/AHPLUS
+          CTOT=H2CO3+HCO3+CO3
+          ALK=HCO3+2.0D0*CO3
+        ENDIF
+      ENDIF
+
+      DO 120 II=1,NCONC
+        CONCS(II)=CONCS2(II)
+120    CONTINUE
+
+! AXY (07/05/13) ==================================================
+! C_SW IS SET AT 0 TO START
+! THEN IF NON CONVERGENCE C_SW SET TO 1
+123   IF(C_SW.EQ.1)THEN
+! IF NON CONVERGENCE, THE MODEL REQUIRES CONCS TO CONTAIN USABLE VALUES.
+! BEST OFFER BEING THE OLD CONCS VALUES WHEN CONVERGENCE HAS BEEN 
+! ACHIEVED
+        DO II=1,NCONC
+           CONCS(II)=OLD_CONCS(II)
+        END DO
+
+! SPECIFIC CARBONATE VALUES TO PUSH CODE ON THROUGH THE
+! NON CONVERGENCE CONDITIONS
+! PCO2W = 0 SO CO2 UPTAKE WILL BE ENCOURAGED
+!       CONCS(3)=O3C(III)*0.005_fp8/1.e6_fp8
+! -99 IS A FLAG TO SHOW WHEN AND WHERE NON CONVERGENCE OCCURED
+! CONCS(4)=PH, OUTPUT OF -99 MEANS NON-CONVERGENCE
+!       CONCS(4)=-99._fp8
+! 
+! AXY (10/05/13): remove this -99 flag; this is handled instead up in
+!                 trcbio_medusa.F90 where the iters variable is both 
+!                 output and may be used to trigger action
+!
+! RESET SWITCH FOR NEXT CALL TO THIS SUBROUTINE
+        C_SW=0
+      ENDIF
+! AXY (07/05/13) ==================================================
+
+
+      RETURN
+
+      END SUBROUTINE
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+      SUBROUTINE CaCO3_Saturation (Tc, S, D, CO3, &
+      Om_cal, Om_arg)
+!      
+!=======================================================================
+!
+! Routine to calculate the saturation state of calcite and aragonite    
+! Inputs:                                                               
+!               Tc      Temperature (C)                                 
+!               S       Salinity                                        
+!               D       Depth (m)                                       
+!               CO3     Carbonate ion concentration (mol.kg-1 ie /1D6)
+!                                                                       
+! Outputs                                                               
+!               Om_cal  Calite saturation                               
+!               Om_arg  Aragonite saturation                            
+!                                                                       
+! Intermediates                                                         
+!               K_cal   Stoichiometric solubility product for calcite   
+!               K_arg   Stoichiometric solubility product for aragonite 
+!               Ca      Calcium 2+ concentration (mol.kg-1) 
+!               P       Pressure (bars)
+!                                                                       
+! Source                                                                
+!       Zeebe & Wolf-Gladrow 2001 following Mucci (1983)                
+!       with pressure corrections from Millero (1995)                   
+!       Code tested against reference values given in Z & W-G
+!       Built Jerry Blackford, 2008
+!=======================================================================
+
+        IMPLICIT None
+        REAL(wp), INTENT( in )    :: Tc, S, D, CO3
+        REAL(wp), INTENT( inout ) :: Om_cal, Om_arg
+        REAL(wp) :: Tk, Kelvin, Ca
+        REAL(wp) :: logKspc, Kspc
+        REAL(wp) :: logKspa, Kspa
+        REAL(wp) :: tmp1, tmp2, tmp3
+        REAL(wp) :: dV, dK, P, R
+               
+! setup
+        Kelvin = 273.15
+        Tk = Tc + Kelvin 
+        Ca = 0.01028    ! Currently oceanic mean value at S=25, needs refining)
+        Ca = 0.010279 * (S / 35.0)  ! Ca varies with salinity (cf. Feeley et al., 2004; Yool et al., 2010)
+        R = 83.131      !(cm3.bar.mol-1.K-1)
+        P = D / 10.0    !pressure in bars
+
+! calculate K for calcite
+        tmp1 = -171.9065 - (0.077993*Tk) + (2839.319/Tk) + 71.595*log10(Tk) 
+        tmp2 = + (-0.77712 + (0.0028426*Tk) + (178.34/Tk))*SQRT(S) 
+        tmp3 = - (0.07711*S) + (0.0041249*(S**1.5))
+        logKspc = tmp1 + tmp2 + tmp3
+        Kspc = 10.0**logKspc
+      
+! correction for pressure for calcite
+        IF ( D .GT. 0) THEN
+          dV = -48.76 + 0.5304*Tc
+          dK = -11.76/1.0D3 + (0.3692/1.0D3) * Tc
+          tmp1 = -(dV/(R*Tk))*P + (0.5*dK/(R*Tk))*P*P
+          Kspc = Kspc*exp(tmp1)
+          logKspc = log10(Kspc)
+        END IF
+        
+! calculate K for aragonite
+        tmp1 = -171.945 - 0.077993*Tk + 2903.293 / Tk + 71.595* log10(Tk)
+        tmp2 = + (-0.068393 + 0.0017276*Tk + 88.135/Tk)*SQRT(S)    
+        tmp3 = - 0.10018*S + 0.0059415*S**1.5
+        logKspa = tmp1 + tmp2 + tmp3
+        Kspa = 10.0**logKspa
+     
+! correction for pressure for aragonite
+        IF ( D .GT. 0) THEN
+          dV = -46.00 + 0.5304*Tc
+          dK = -11.76/1.0D3 + (0.3692/1.0D3) * Tc
+          tmp1 = -(dV/(R*Tk))*P + (0.5*dK/(R*Tk))*P*P
+          Kspa = Kspa*exp(tmp1)
+          logKspa = log10(Kspa)
+        END IF
+        
+! calculate saturation states
+        Om_cal = (CO3 * Ca) / Kspc
+        Om_arg = (CO3 * Ca) / Kspa
+      
+      RETURN
+
+      END SUBROUTINE
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+#  else
+   !!======================================================================
+   !!  Dummy module :                         No MEDUSA carbonate chemistry
+   !!======================================================================
+
+CONTAINS
+
+   SUBROUTINE trc_co2_medusa( kt )                   ! Empty routine
+
+      INTEGER, INTENT( in ) ::   kt
+
+      WRITE(*,*) 'trc_co2_medusa: You should not have seen this print! error?', kt
+
+   END SUBROUTINE trc_co2_medusa
+#endif 
+
+   !!======================================================================
+END MODULE  trcco2_medusa
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcctl_medusa.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcctl_medusa.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcctl_medusa.F90	(revision 5707)
@@ -0,0 +1,83 @@
+MODULE trcctl_medusa
+   !!======================================================================
+   !!                         ***  trcctl_medusa.F90  ***
+   !! TOP :                Control of MEDUSA_TRC biogeochemical model
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !! History :   1.0  !  2000-12 (C. Ethe) assign a parameter to name individual tracers
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!----------------------------------------------------------------------
+
+#if defined key_medusa
+
+   USE oce_trc
+   USE trc
+   USE in_out_manager
+   USE par_medusa
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_ctl_medusa     ! called by ???
+
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id: trcctl_medusa.F90 1162 2008-07-02 09:33:33Z cetlod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_ctl_medusa
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_ctl_medusa  ***
+      !!
+      !! ** Purpose :   control the cpp options, namelist and files 
+      !!----------------------------------------------------------------------
+
+!      IF(lwp) WRITE(numout,*)
+!      IF(lwp) WRITE(numout,*) 'use MEDUSA biological model  '
+
+! Check number of tracers
+! -----------------------
+# if defined key_roam
+      IF (jp_medusa /= 15) THEN 
+          IF (lwp) THEN 
+              WRITE (numout,*) ' ===>>>> : W A R N I N G '
+              WRITE (numout,*) ' =======   ============= '
+              WRITE (numout,*)                             &
+              &   ' STOP, change jp_medusa to 15 in '      &
+              &  ,' par_medusa.F90 '  
+          END IF 
+          STOP 'TRC_CTL'
+      END IF 
+# else
+      IF (jp_medusa /= 11) THEN 
+          IF (lwp) THEN 
+              WRITE (numout,*) ' ===>>>> : W A R N I N G '
+              WRITE (numout,*) ' =======   ============= '
+              WRITE (numout,*)                             &
+              &   ' STOP, change jp_medusa to 11 in '      &
+              &  ,' par_medusa.F90 '  
+          END IF 
+          STOP 'TRC_CTL'
+      END IF 
+# endif
+
+   END SUBROUTINE trc_ctl_medusa
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Empty module :                                            No MEDUSA
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ctl_medusa               ! Dummy routine
+   END SUBROUTINE trc_ctl_medusa
+#endif
+
+   !!======================================================================
+END MODULE trcctl_medusa
+      
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcdms_medusa.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcdms_medusa.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcdms_medusa.F90	(revision 5707)
@@ -0,0 +1,248 @@
+MODULE trcdms_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcdms_medusa  ***
+   !! TOP :   MEDUSA
+   !!======================================================================
+   !! History :
+   !!  -   !  2014-08  (J. Palmiéri - A. Yool)    added for UKESM1 project
+   !!----------------------------------------------------------------------
+#if defined key_medusa && defined key_roam
+   !!----------------------------------------------------------------------
+   !!                                        MEDUSA DMS surface concentration
+   !!----------------------------------------------------------------------
+   !!   trc_dms_medusa        :  
+   !!----------------------------------------------------------------------
+      USE oce_trc
+      USE trc
+      USE sms_medusa
+      USE lbclnk
+      USE prtctl_trc      ! Print control for debugging
+      USE in_out_manager  ! I/O manager
+
+      IMPLICIT NONE
+      PRIVATE
+
+      PUBLIC   trc_dms_medusa    ! called in trc_bio_medusa
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id: trcbio.F90 1146 2008-06-25 11:42:56Z rblod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+
+CONTAINS
+
+!=======================================================================
+!
+   SUBROUTINE trc_dms_medusa( chn, chd, mld, xqsr, xdin,   &  !! inputs
+     &  dms_surf, dms_andr, dms_simo, dms_aran, dms_hall )    !! outputs
+!      
+!=======================================================================
+      !!
+      !! Title  : Calculates DMS ocean surface concentration
+      !! Author : Julien Palmiéri and Andrew Yool
+      !! Date   : 08/08/14 
+      !!
+      !! DMS module is called in trc_bio's huge jk,jj,ji loop
+      !! --> DMS concentration is calculated in a specific cell 
+      !! (no need of ji,jj,jk)
+      !!
+      !! AXY (13/03/15): amend to include all four schemes tested
+      !!                 during winter/spring 2015; these are:
+      !!
+      !!                 1. Anderson et al. (2001); this uses fields
+      !!                    of surface chl, irradiance and nutrients
+      !!                    to empirically estimate DMS via a broken
+      !!                    stick approach
+      !!
+      !!                 2. Simo & Dachs (2002); this uses fields of
+      !!                    surface chl and mixed layer depth
+      !!
+      !!                 3. Aranami & Tsunogai (2004); this is an
+      !!                    embellishment of Simo & Dachs
+      !!
+      !!                 4. Halloran et al. (2010); this is an
+      !!                    alternative embellishment of Sim & Dachs
+      !!                    and is included because it is formally
+      !!                    published (and different from the above)
+      !!
+!=======================================================================
+
+      IMPLICIT NONE
+!
+      REAL(wp), INTENT( in )    :: chn                  !! non-diatom chlorophyll    (mg/m3)
+      REAL(wp), INTENT( in )    :: chd                  !! diatom chlorophyll        (mg/m3)
+      REAL(wp), INTENT( in )    :: mld                  !! mix layer depth           (m)
+      REAL(wp), INTENT( in )    :: xqsr                 !! surface irradiance        (W/m2)
+      REAL(wp), INTENT( in )    :: xdin                 !! surface DIN               (mmol N/m3)
+      REAL(wp), INTENT( inout ) :: dms_surf             !! DMS surface concentration (mol/m3) 
+      REAL(wp), INTENT( inout ) :: dms_andr             !! DMS surface concentration (mol/m3) 
+      REAL(wp), INTENT( inout ) :: dms_simo             !! DMS surface concentration (mol/m3) 
+      REAL(wp), INTENT( inout ) :: dms_aran             !! DMS surface concentration (mol/m3) 
+      REAL(wp), INTENT( inout ) :: dms_hall             !! DMS surface concentration (mol/m3) 
+!
+      REAL(wp) :: CHL, cmr, sw_dms
+      REAL(wp) :: Jterm, Qterm
+      !! temporary variables
+      REAL(wp) ::    fq1,fq2,fq3
+!
+!! IJT (30/03/13): DMS calc needs this
+!! Julien : in Simo & Dachs, GBC, 2002, DMS is derived from 
+!!          CHL/MLD ratio in mg/m4 (i.e. CHL is in mg/m3
+!!          MLD in m).
+!!          In MEDUSA, we already have CHL in mg/m3 for both
+!!          Diatoms and non-diatoms (zchn,zchd); and mld from
+!!          NEMO (hmld) in m.
+      CHL = 0.0
+!!
+!!            CHL = mask * TT(I,J,1,PHYTO_TRACER) &
+!!     &       * c2n_p * mw_carbon / CCHL_P(I,J,1,1)
+      CHL = chn+chd                                 !! mg/m3 
+!!
+!! ------------------------------------------------
+!!  Calculate the DMS concentration in nM (nanomol/litre)
+!!   from Simo & Dachs, GBC, 2002, modified to be positive-definite
+!!   for MLD>182.536m, using DMS=90./MLD (Aranami & Tsunogai, JGR, 2004)
+!!   Multiply by 1.0E-6 to convert nM to (mol/m3)
+!!       cmr = fm(i,1)*chl/mld(i)
+!!       IF (cmr .lt. 0.02) THEN
+!!         IF (mld(i) .le. 182.536) THEN
+!!           csurf(i,astf_dms) = 1.0e-6*fm(i,1)*(-LOG(mld(i)) + 5.7)
+!!         ELSE
+!!           csurf(i,astf_dms) = 1.0e-6*fm(i,1)*(90./mld(i))
+!!         ENDIF
+!!       ELSE
+!!         csurf(i,astf_dms) = 1.0e-6*fm(i,1)*(55.8*cmr + 0.6)
+!!       ENDIF
+!!
+        cmr      = CHL / mld
+!       sw_dms   = 0.5 + SIGN( 0.5, cmr - 0.02 )
+!! Jpalm (11-08-2014)
+!! Explanation about the SIGN function :
+!! not easy to read, but maybe "more elegant and efficient")
+!! here for example: 
+!! sw_dms = 1 if cmr is greater than 0.02,
+!!          0 if cmr lower than 0.02
+!! then 
+!! if cmr < 0.02
+!!  dms_surf =  1.0e-6 * 90.0 / mld 
+!!       or  =  1.0e-6 * 5.7 - LOG(mld)
+!! and if cmr > 0.02
+!!  dms_surf = 1.0e-6 * ( 55.8 * cmr + 0.6 )
+!! what is equivalent to the IF loops formulations.
+!! difference is on the stresholds between mld = 182.536m
+!! (strange value...)
+!! and the Max function... that stay uncertain.
+!!
+!        dms_surf = 1.0e-6 * ( sw_dms *             &
+!     &  ( 55.8 * cmr + 0.6 ) + ( 1.0 - sw_dms ) *  &
+!     &  ( MAX( 90.0 / mld, 5.7 - LOG(mld) ) ) )
+!
+! AXY (12/01/15): the DMS equation donated by the UKMO does not match
+!                 that reported in Halloran et al. (2010); amend the
+!                 equations appropriately
+!
+        if (cmr .lt. 0.02) then
+           dms_surf = (-1.0 * log(mld)) + 5.7
+        else
+           dms_surf = (55.8 * cmr) + 0.6
+        endif
+!    
+        if (mld > 182.5) then
+           dms_surf = (90.0 / mld)
+        endif
+!     
+        dms_surf = 1.0e-6 * dms_surf
+
+! 
+!=======================================================================
+!
+! AXY (13/03/15): per remarks above, the following calculations estimate
+!                 DMS using all of the schemes examined for UKESM1
+!
+! AXY (13/03/15): Anderson et al. (2001)
+        Jterm = xqsr + 1.0e-6
+        !! this next line makes a hard-coded assumption about the 
+        !! half-saturation constant of MEDUSA (which should be
+        !! done properly; perhaps even scaled with the proportion
+        !! of diatoms and non-diatoms)
+        Qterm = xdin / (xdin + 0.5)
+        fq1 = log10(CHL * Jterm * Qterm)
+        if (fq1 > 1.72) then
+           dms_andr = (8.24 * (fq1 - 1.72)) + 2.29
+        else
+           dms_andr = 2.29
+        endif
+        dms_andr = 1.0e-6 * dms_andr
+!
+! AXY (13/03/15): Simo & Dachs (2002)
+        cmr = CHL / mld
+        fq1 = (-1 * log(mld)) + 5.7
+        fq2 = (55.8 * cmr) + 0.6
+        if (cmr < 0.02) then
+           dms_simo = fq1
+        else
+           dms_simo = fq2
+        endif
+        dms_simo = 1.0e-6 * dms_simo
+!           
+! AXY (13/03/15): Aranami & Tsunogai (2004)
+        cmr = CHL / mld
+        fq1 = 60.0 / mld
+        fq2 = (55.8 * cmr) + 0.6
+        if (cmr < 0.02) then
+           dms_aran = fq1
+        else
+           dms_aran = fq2
+        endif
+        dms_aran = 1.0e-6 * dms_aran
+!        
+! AXY (13/03/15): Halloran et al. (2010)
+        cmr = CHL / mld
+        fq1 = (-1 * log(mld)) + 5.7
+        fq2 = (55.8 * cmr) + 0.6
+        fq3 = (90.0 / mld)
+        if (cmr < 0.02) then
+           dms_hall = fq1
+        else
+           dms_hall = fq2
+        endif
+        if (mld > 182.5) then
+           dms_hall = fq3
+        endif
+        dms_hall = 1.0e-6 * dms_hall
+
+  END SUBROUTINE trc_dms_medusa
+
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No MEDUSA bio-model
+   !!======================================================================
+
+CONTAINS
+
+!=======================================================================
+!
+   SUBROUTINE trc_dms_medusa( kt )                                        !! EMPTY Routine
+!      
+!
+      INTEGER, INTENT( in ) ::   kt
+!
+
+      WRITE(*,*) 'trc_dms_medusa: You should not have seen this print! error?'
+
+   END SUBROUTINE trc_dms_medusa
+#endif
+
+   !!======================================================================
+END MODULE  trcdms_medusa
+
+
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcini_medusa.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcini_medusa.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcini_medusa.F90	(revision 5707)
@@ -0,0 +1,432 @@
+MODULE trcini_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcini_medusa  ***
+   !! TOP :   initialisation of the MEDUSA tracers
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) Original code
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!              -   !  2011-04  (A. Yool) updated for ROAM project
+   !!----------------------------------------------------------------------
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'                                         MEDUSA tracers
+   !!----------------------------------------------------------------------
+   !! trc_ini_medusa   : MEDUSA model initialisation
+   !!----------------------------------------------------------------------
+   USE par_trc         ! TOP parameters
+   USE oce_trc
+   USE trc
+   USE in_out_manager
+   !! AXY (04/11/13): add this in for initialisation stuff
+   USE iom
+   USE par_medusa
+   !! AXY (13/01/12): add this in for sediment variables
+   USE sms_medusa
+   !! AXY (04/11/13): add this in for initialisation stuff
+   USE trcsed_medusa
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_ini_medusa   ! called by trcini.F90 module
+
+   !! AXY (25/02/10)
+   LOGICAL, PUBLIC ::                  &
+      bocalccd = .TRUE.
+   INTEGER ::                          &
+      numccd
+
+   !! AXY (25/02/10)
+   INTEGER ::                          &
+      numriv
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id: trcini_medusa.F90 1162 2008-07-02 09:33:33Z cetlod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_ini_medusa
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_ini_medusa  ***  
+      !!
+      !! ** Purpose :   initialization for MEDUSA model
+      !!
+      !! ** Method  : - Read the namcfc namelist and check the parameter values
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+
+      !! vertical array index
+      INTEGER  ::    jk, ierr
+      !! AXY (19/07/12): added jk2 to set up friver_dep array
+      INTEGER            :: jk2
+      !! AXY (19/07/12): added tfthk to set up friver_dep array
+      REAL(wp)           :: fthk, tfthk
+      !! AXY (04/11/13): add in temporary variables for checks
+      REAL(wp)           :: fq0, fq1, fq2
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: initialisation of MEDUSA model'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+      IF(lwp) WRITE(numout,*) ' second Test with Julien'
+# if defined key_debug_medusa
+            CALL flush(numout)
+# endif
+
+                                           ! Allocate MEDUSA arrays
+      ierr =         sms_medusa_alloc()
+# if defined key_debug_medusa
+            IF (lwp) write (numout,*) '------------------------------'
+            IF (lwp) write (numout,*) 'Jpalm - debug'
+            IF (lwp) write (numout,*) 'in trc_ini_medusa, just after array allocate'
+            IF (lwp) write (numout,*) ' '
+            CALL flush(numout)
+# endif
+
+!!
+!! AXY (19/07/12): setup array to control distribution of river nutrients
+      friver_dep(:,:) = 0.
+      DO jk = 1,jpk
+         tfthk = 0.
+         DO jk2 = 1,jriver_dep
+            fthk  = e3t_1d(jk2)
+            if (jk2 .le. jk) then
+               tfthk = tfthk + fthk
+               friver_dep(jk2,jk) = fthk
+            endif
+         ENDDO
+         DO jk2 = 1,jriver_dep
+            friver_dep(jk2,jk) = friver_dep(jk2,jk) / tfthk
+         ENDDO
+      ENDDO
+!!
+!! Have a look at the result of this for a single depth (jriver_dep + 1)
+      IF(lwp) THEN
+          WRITE(numout,*) '=== River nutrient fraction by depth (for a water column of jpk depth)'
+          DO jk = 1,jpk
+             WRITE(numout,*)     &
+             &   ' cell = ', jk, ', friver_dep value = ', friver_dep(jk,jpk)
+          ENDDO
+          IF(lwp) CALL flush(numout)
+       ENDIF
+
+#if defined key_roam
+!! ROAM 3D and 2D carbonate system fields (calculated on first time
+!! step, then monthly)
+      f3_pH(:,:,:)    = 0.
+      f3_h2co3(:,:,:) = 0.
+      f3_hco3(:,:,:)  = 0.
+      f3_co3(:,:,:)   = 0.
+      f3_omcal(:,:,:) = 0.
+      f3_omarg(:,:,:) = 0.
+!!
+      f2_ccd_cal(:,:) = 0.
+      f2_ccd_arg(:,:) = 0.
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: carbonate fields initialised to zero'
+#endif
+      IF(lwp) CALL flush(numout)
+
+      !!----------------------------------------------------------------------
+      !! State variable initial conditions (all mmol / m3)
+      !!----------------------------------------------------------------------
+      !!     
+      !! biological and detrital components are initialised to nominal
+      !! values above 100 m depth and zero below; the latter condition
+      !! is applied since non-linear loss processes allow significant
+      !! concentrations of these components to persist at depth
+      !!
+      trn(:,:,:,jpchn) = 0.
+      trn(:,:,:,jpchd) = 0.
+      trn(:,:,:,jpphn) = 0.
+      trn(:,:,:,jpphd) = 0.
+      trn(:,:,:,jppds) = 0.
+      trn(:,:,:,jpzmi) = 0.
+      trn(:,:,:,jpzme) = 0.
+      trn(:,:,:,jpdet) = 0.
+      !!
+      DO jk = 1,13
+         !! non-diatom chlorophyll         (nominal)
+         trn(:,:,jk,jpchn) = 0.01
+         !!
+         !! diatom chlorophyll             (nominal)
+         trn(:,:,jk,jpchd) = 0.01
+         !!
+         !! non-diatom                     (nominal)
+         trn(:,:,jk,jpphn) = 0.01
+         !!
+         !! diatom                         (nominal)
+         trn(:,:,jk,jpphd) = 0.01
+         !!
+         !! diatom silicon                 (nominal)
+         trn(:,:,jk,jppds) = 0.01
+         !!
+         !! microzooplankton               (nominal)
+         trn(:,:,jk,jpzmi) = 0.01
+         !!
+         !! mesozooplankton                (nominal)
+         trn(:,:,jk,jpzme) = 0.01
+         !!
+         !! detrital nitrogen              (nominal)
+         trn(:,:,jk,jpdet) = 0.01
+      ENDDO
+      !!
+      !! dissolved inorganic nitrogen     (nominal average value; typically initialised from climatology)
+      trn(:,:,:,jpdin) = 30.
+      !!
+      !! dissolved silicic acid           (nominal average value; typically initialised from climatology)
+      trn(:,:,:,jpsil) = 90.
+      !!
+      !! dissolved "total" iron           (nominal; typically initialised from model-derived climatology)
+      trn(:,:,:,jpfer) = 1.0e-4           !! = 0.1 umol Fe / m3
+      !!
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: MEDUSA-1 fields initialised to defaults'
+# if defined key_roam
+      !!
+      !! detrital carbon                  (nominal)
+      trn(:,:,:,jpdtc) = 0.
+      DO jk = 1,13
+         trn(:,:,jk,jpdtc) = 0.06625
+      ENDDO
+      !!
+      !! dissolved inorganic carbon (DIC) (nominal average value; typically initialised from climatology)
+      trn(:,:,:,jpdic) = 2330.
+      !!
+      !! total alkalinity                 (nominal average value; typically initialised from climatology)
+      trn(:,:,:,jpalk) = 2450.
+      !!
+      !! dissolved oxygen                 (nominal average value; typically initialised from climatology)
+      trn(:,:,:,jpoxy) = 175.
+      !!
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: MEDUSA-2 fields initialised to defaults'
+# endif
+      IF(lwp) CALL flush(numout)
+
+      !!----------------------------------------------------------------------
+      !! Sediment pools initial conditions (all mmol / m2)
+      !!----------------------------------------------------------------------
+      !!     
+      !! these pools store biogenic material that has sunk to the seabed,
+      !! and act as a temporary reservoir
+      zb_sed_n(:,:)  = 0.0  !! organic N
+      zn_sed_n(:,:)  = 0.0
+      za_sed_n(:,:)  = 0.0
+      zb_sed_fe(:,:) = 0.0  !! organic Fe
+      zn_sed_fe(:,:) = 0.0
+      za_sed_fe(:,:) = 0.0
+      zb_sed_si(:,:) = 0.0  !! inorganic Si
+      zn_sed_si(:,:) = 0.0
+      za_sed_si(:,:) = 0.0
+      zb_sed_c(:,:)  = 0.0  !! organic C
+      zn_sed_c(:,:)  = 0.0
+      za_sed_c(:,:)  = 0.0
+      zb_sed_ca(:,:) = 0.0  !! inorganic C
+      zn_sed_ca(:,:) = 0.0
+      za_sed_ca(:,:) = 0.0
+      !!
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: benthic fields initialised to zero'
+      IF(lwp) CALL flush(numout)
+     
+      !!----------------------------------------------------------------------
+      !! AXY (04/11/13): initialise fields previously done by trc_sed_medusa
+      !!----------------------------------------------------------------------
+      !!     
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: initialising dust deposition fields'
+      CALL trc_sed_medusa_sbc( nit000 )
+      !!
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: initialising ocean CCD array'
+      CALL trc_ini_medusa_ccd( nit000 )
+      fq0 = MINVAL(ocal_ccd(:,:))
+      fq1 = MAXVAL(ocal_ccd(:,:))
+      if (lwp) write (numout,'(a,f10.3,a,f10.3)') & 
+         & 'CCD: min ', fq0, ' max ', fq1
+      !!
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: initialising riverine nutrient arrays'
+      riv_n(:,:)   = 0.0
+      riv_si(:,:)  = 0.0
+      riv_c(:,:)   = 0.0
+      riv_alk(:,:) = 0.0 
+      !!
+      CALL trc_ini_medusa_river( nit000 )
+      fq0 = MINVAL(riv_n(:,:))
+      fq1 = MAXVAL(riv_n(:,:))
+      if (lwp) write (numout,'(a,f10.3,a,f10.3)') & 
+         & 'RIV_N:   min ', fq0, ' max ', fq1
+      fq0 = MINVAL(riv_si(:,:))
+      fq1 = MAXVAL(riv_si(:,:))
+      if (lwp) write (numout,'(a,f10.3,a,f10.3)') & 
+         & 'RIV_SI:  min ', fq0, ' max ', fq1
+      fq0 = MINVAL(riv_c(:,:))
+      fq1 = MAXVAL(riv_c(:,:))
+      if (lwp) write (numout,'(a,f10.3,a,f10.3)') & 
+         & 'RIV_C:   min ', fq0, ' max ', fq1
+      fq0 = MINVAL(riv_alk(:,:))
+      fq1 = MAXVAL(riv_alk(:,:))
+      if (lwp) write (numout,'(a,f10.3,a,f10.3)') & 
+         & 'RIV_ALK: min ', fq0, ' max ', fq1
+      IF(lwp) CALL flush(numout)
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: MEDUSA initialised'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+      IF(lwp) CALL flush(numout)
+
+   END SUBROUTINE trc_ini_medusa
+
+   !! ======================================================================
+   !! ======================================================================
+   !! ======================================================================
+
+   !! AXY (25/02/10)
+   SUBROUTINE trc_ini_medusa_ccd(kt)
+
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_ini_medusa_ccd  ***
+      !!
+      !! ** Purpose :   Read CCD field
+      !!
+      !! ** Method  :   Read the file
+      !!
+      !! ** input   :   external netcdf files
+      !!
+      !!----------------------------------------------------------------------
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !!---------------------------------------------------------------------
+
+      !! Open the file
+      !! -------------
+      !!
+      IF(lwp) WRITE(numout,*) ' '
+      IF(lwp) WRITE(numout,*) ' **** Routine trc_ini_medusa_ccd'
+      CALL iom_open ( 'ccd_ocal_nemo.nc', numccd )
+      IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_ccd: ccd_ocal_nemo.nc opened'
+
+      !! Read the data
+      !! -------------
+      !!
+      CALL iom_get ( numccd, jpdom_data, 'OCAL_CCD', ocal_ccd )
+      IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_ccd: data read'
+
+      !! Close the file
+      !! --------------
+      !!
+      CALL iom_close ( numccd )
+      IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_ccd: ccd_ocal_nemo.nc closed'
+      IF(lwp) CALL flush(numout)
+      
+   END SUBROUTINE trc_ini_medusa_ccd
+
+   !! ======================================================================
+   !! ======================================================================
+   !! ======================================================================
+
+   !! AXY (26/01/12)
+   SUBROUTINE trc_ini_medusa_river(kt)
+
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_ini_medusa_river  ***
+      !!
+      !! ** Purpose :   Read riverine nutrient fields
+      !!
+      !! ** Method  :   Read the file
+      !!
+      !! ** input   :   external netcdf files
+      !!
+      !!----------------------------------------------------------------------
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !!---------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' **** Routine trc_ini_medusa_river'
+         WRITE(numout,*) ' '
+      ENDIF
+
+      !! Open and read the files
+      !! -----------------------
+      !!
+      if (jriver_n.gt.0) then
+         if (jriver_n.eq.1) CALL iom_open ( 'river_N_conc_orca100.nc', numriv )
+         if (jriver_n.eq.2) CALL iom_open ( 'river_N_flux_orca100.nc', numriv )
+         CALL iom_get  ( numriv, jpdom_data, 'RIV_N', riv_n )
+         IF(lwp) THEN
+            if (jriver_n.eq.1) WRITE(numout,*) ' **** trc_ini_medusa_river: N CONC data read'
+            if (jriver_n.eq.2) WRITE(numout,*) ' **** trc_ini_medusa_river: N FLUX data read'
+         ENDIF
+         CALL iom_close ( numriv )
+         IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_river: river N file closed'
+      else
+         IF(lwp) THEN
+            WRITE(numout,*) ' **** trc_ini_medusa_river: N data NOT read'
+         ENDIF
+      endif
+      !!
+      if (jriver_si.gt.0) then
+         if (jriver_si.eq.1) CALL iom_open ( 'river_Si_conc_orca100.nc', numriv )
+         if (jriver_si.eq.2) CALL iom_open ( 'river_Si_flux_orca100.nc', numriv )
+         CALL iom_get  ( numriv, jpdom_data, 'RIV_SI', riv_si )
+         IF(lwp) THEN
+            if (jriver_si.eq.1) WRITE(numout,*) ' **** trc_ini_medusa_river: Si CONC data read'
+            if (jriver_si.eq.2) WRITE(numout,*) ' **** trc_ini_medusa_river: Si FLUX data read'
+         ENDIF
+         CALL iom_close ( numriv )
+         IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_river: river Si file closed'
+      else
+         IF(lwp) THEN
+            WRITE(numout,*) ' **** trc_ini_medusa_river: Si data NOT read'
+         ENDIF
+      endif
+      !!
+      if (jriver_c.gt.0) then
+         if (jriver_c.eq.1) CALL iom_open ( 'river_C_conc_orca100.nc', numriv )
+         if (jriver_c.eq.2) CALL iom_open ( 'river_C_flux_orca100.nc', numriv )
+         CALL iom_get  ( numriv, jpdom_data, 'RIV_C', riv_c )
+         IF(lwp) THEN
+            if (jriver_c.eq.1) WRITE(numout,*) ' **** trc_ini_medusa_river: C CONC data read'
+            if (jriver_c.eq.2) WRITE(numout,*) ' **** trc_ini_medusa_river: C FLUX data read'
+         ENDIF
+         CALL iom_close ( numriv )
+         IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_river: river C file closed'
+      else
+         IF(lwp) THEN
+            WRITE(numout,*) ' **** trc_ini_medusa_river: C data NOT read'
+         ENDIF
+      endif
+      !!
+      if (jriver_alk.gt.0) then
+         if (jriver_alk.eq.1) CALL iom_open ( 'river_alk_conc_orca100.nc', numriv )
+         if (jriver_alk.eq.2) CALL iom_open ( 'river_alk_flux_orca100.nc', numriv )
+         CALL iom_get  ( numriv, jpdom_data, 'RIV_ALK', riv_alk )
+         IF(lwp) THEN
+            if (jriver_alk.eq.1) WRITE(numout,*) ' **** trc_ini_medusa_river: alkalinity CONC data read'
+            if (jriver_alk.eq.2) WRITE(numout,*) ' **** trc_ini_medusa_river: alkalinity FLUX data read'
+         ENDIF
+         CALL iom_close ( numriv )
+         IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_river: river alkalinity file closed'
+      else
+         IF(lwp) THEN
+            WRITE(numout,*) ' **** trc_ini_medusa_river: alkalinity data NOT read'
+         ENDIF
+      endif
+      IF(lwp) CALL flush(numout)
+
+   END SUBROUTINE trc_ini_medusa_river
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                        No MEDUSA model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ini_medusa             ! Empty routine
+   END SUBROUTINE trc_ini_medusa
+#endif
+
+   !!======================================================================
+END MODULE trcini_medusa
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90	(revision 5707)
@@ -0,0 +1,1138 @@
+MODULE trcnam_medusa
+   !!======================================================================
+   !!                      ***  MODULE trcnam_medusa  ***
+   !! TOP :   initialisation of some run parameters for MEDUSA bio-model
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) Original code
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!              -   !  2011-04  (A. Yool) updated for ROAM project
+   !!              -   !  2013-05  (A. Yool) renamed (from trclsm) for v3.5
+   !!----------------------------------------------------------------------
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'   :                                       MEDUSA model
+   !!----------------------------------------------------------------------
+   !! trc_nam_medusa      : MEDUSA model initialisation
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! TOP variables
+   USE sms_medusa      ! sms trends
+   USE iom             ! I/O manager
+
+   !! AXY (04/02/14): necessary to find NaNs on HECTOR
+   USE, INTRINSIC :: ieee_arithmetic 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_nam_medusa   ! called by trcnam.F90 module
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id: trcnam_medusa.F90 1162 2008-07-02 09:33:33Z cetlod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_nam_medusa
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_nam_medusa  ***  
+      !!
+      !! ** Purpose :   read MEDUSA namelist
+      !!
+      !! ** input   :   file 'namelist.trc.sms' containing the following
+      !!             namelist: natbio, natopt, and natdbi ("key_trc_diabio")
+      !!
+      !! ekp: namelist nabio contains ALL parameters of the ecosystem 
+      !!      point sourses and sinks PLUS sediment exchange
+      !!      dia_bio - used by Lobster to output all point terms 
+      !!                (sourses and sinks of bio)
+      !!      dia_add - additional diagnostics for biology such as 
+      !!                primary production (2d depth integrated field or 3d)
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER            :: ji,jj,jk
+      REAL(wp)           :: fthk, fdep, fdep1
+      REAL(wp)           :: q1, q2, q3
+      !
+      NAMELIST/natbio/ xxi,xaln,xald,jphy,xvpn,xvpd,          &
+      &    xsin0,xnsi0,xuif,jliebig,                          &
+      &    xthetam,xthetamd,xnln,xnld,xsld,xfln,xfld,         &
+      &  xgmi,xgme,xkmi,xkme,xphi,xbetan,xbetac,xkc,          &
+      &    xpmipn,xpmid,xpmepn,xpmepd,xpmezmi,xpmed,          &
+      &  xmetapn,xmetapd,xmetazmi,xmetazme,                   &
+      &  jmpn,xmpn,xkphn,jmpd,xmpd,xkphd,jmzmi,xmzmi,xkzmi,   &
+      &    jmzme,xmzme,xkzme,jmd,jsfd,xmd,xmdc,               &
+      &  xthetapn,xthetapd,xthetazmi,xthetazme,xthetad,       &
+      &    xrfn,xrsn,vsed,xhr,                                &
+      &  jiron,xfe_mass,xfe_sol,xfe_sed,xLgT,xk_FeL,xk_sc_Fe, &
+      &  jexport,jfdfate,jrratio,jocalccd,xridg_r0,           &
+      &    xfdfrac1,xfdfrac2,xfdfrac3,                        &
+      &    xcaco3a,xcaco3b,xmassc,xmassca,xmasssi,xprotca,    &
+      &    xprotsi,xfastc,xfastca,xfastsi,                    &
+      &  jorgben,jinorgben,xsedn,xsedfe,xsedsi,xsedc,xsedca,  &
+      &    xburial,                                           &
+      &  jriver_n,jriver_si,jriver_c,jriver_alk,jriver_dep,   &
+      &    friver_dep,                                        &
+      &  xsdiss,                                              &
+      &  vsed,xhr,                                            &
+      &  sedlam,sedlostpoc,jpkb,jdms
+#if defined key_roam
+      NAMELIST/natroam/ xthetaphy,xthetazoo,xthetanit,        &
+      &    xthetarem,xo2min,                                  &
+      &    f3_pH,f3_h2co3,f3_hco3,f3_co3,f3_omcal,f3_omarg,   &
+      &    f2_ccd_cal,f2_ccd_arg
+#endif
+      NAMELIST/natopt/xkg0,xkr0,xkgp,xkrp,xlg,xlr,rpig
+      INTEGER :: jl, jn
+      INTEGER :: ios                 ! Local integer output status for namelist read
+      TYPE(DIAG), DIMENSION(jp_medusa_2d)  :: meddia2d
+      TYPE(DIAG), DIMENSION(jp_medusa_3d)  :: meddia3d
+      TYPE(DIAG), DIMENSION(jp_medusa_trd) :: meddiabio
+      CHARACTER(LEN=32)   ::   clname
+      !!
+      NAMELIST/nammeddia/ meddia3d, meddia2d     ! additional diagnostics
+
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      clname = 'namelist_medusa'
+      IF(lwp) WRITE(numout,*) ' trc_nam_medusa: read MEDUSA namelist'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+# if defined key_debug_medusa
+      CALL flush(numout)
+# endif
+
+
+      CALL ctl_opn( numnatp_ref, TRIM( clname )//'_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+      CALL ctl_opn( numnatp_cfg, TRIM( clname )//'_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+      IF(lwm) CALL ctl_opn( numonp     , 'output.namelist.pis' , 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'open namelist_medusa -- OK'
+      IF (lwp) write (numout,*) 'Now, read namilists inside :'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+# endif
+      !
+# if defined key_debug_medusa
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'Just before reading namelist_medusa :: nammeddia'
+      IF (lwp) write (numout,*) ' '
+      CALL flush(numout)
+# endif
+
+     IF( ( .NOT.lk_iomput .AND. ln_diatrc ) .OR. ( ln_diatrc .AND. lk_medusa ) ) THEN
+         !
+         ! Namelist nampisdia
+         ! -------------------
+         REWIND( numnatp_ref )              ! Namelist nampisdia in reference namelist : Pisces diagnostics
+         READ  ( numnatp_ref, nammeddia, IOSTAT = ios, ERR = 901)
+901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in reference namelist', lwp )
+
+         REWIND( numnatp_cfg )              ! Namelist nampisdia in configuration namelist : Pisces diagnostics
+         READ  ( numnatp_cfg, nammeddia, IOSTAT = ios, ERR = 902 )
+902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in configuration namelist', lwp )
+         IF(lwm) WRITE ( numonp, nammeddia )
+
+# if defined key_debug_medusa
+         IF (lwp) write (numout,*) '------------------------------'
+         IF (lwp) write (numout,*) 'Jpalm - debug'
+         IF (lwp) write (numout,*) 'reading namelist_medusa :: nammeddia OK'
+         IF (lwp) write (numout,*) 'Check number of variable in nammeddia:'
+         IF (lwp) write (numout,*) 'jp_medusa_2d: ',jp_medusa_2d ,'jp_medusa_3d: ',jp_medusa_3d
+         IF (lwp) write (numout,*) ' '
+         CALL flush(numout)
+# endif
+         DO jl = 1, jp_medusa_2d
+            jn = jp_msa0_2d + jl - 1
+# if defined key_debug_medusa
+            IF (lwp) write (numout,*) 'Check what is readden in nammeddia: -- 2D'
+            IF (lwp) write (numout,*) jl,'meddia2d-sname: ',meddia2d(jl)%sname 
+            IF (lwp) write (numout,*) jl,'meddia2d-lname: ',meddia2d(jl)%lname 
+            IF (lwp) write (numout,*) jl,'meddia2d-units: ',meddia2d(jl)%units 
+            CALL flush(numout)
+# endif
+            ctrc2d(jn) = meddia2d(jl)%sname
+            ctrc2l(jn) = meddia2d(jl)%lname
+            ctrc2u(jn) = meddia2d(jl)%units
+         END DO
+
+         DO jl = 1, jp_medusa_3d
+            jn = jp_msa0_3d + jl - 1
+# if defined key_debug_medusa
+            IF (lwp) write (numout,*) 'Check what is readden in nammeddia: -- 3D'
+            IF (lwp) write (numout,*) jl,'meddia3d-sname: ',meddia3d(jl)%sname 
+            IF (lwp) write (numout,*) jl,'meddia3d-lname: ',meddia3d(jl)%lname
+            IF (lwp) write (numout,*) jl,'meddia3d-units: ',meddia3d(jl)%units
+            CALL flush(numout)
+# endif
+            ctrc3d(jn) = meddia3d(jl)%sname
+            ctrc3l(jn) = meddia3d(jl)%lname
+            ctrc3u(jn) = meddia3d(jl)%units
+         END DO
+
+         IF(lwp) THEN                   ! control print
+# if defined key_debug_medusa
+            IF (lwp) write (numout,*) '------------------------------'
+            IF (lwp) write (numout,*) 'Jpalm - debug'
+            IF (lwp) write (numout,*) 'Var name assignation OK'
+            IF (lwp) write (numout,*) 'next check var names'
+            IF (lwp) write (numout,*) ' '
+            CALL flush(numout)
+# endif
+            WRITE(numout,*)
+            WRITE(numout,*) ' Namelist : natadd'
+            DO jl = 1, jp_medusa_3d
+               jn = jp_msa0_3d + jl - 1
+               WRITE(numout,*) '  3d diag nb : ', jn, '    short name : ', ctrc3d(jn), &
+                 &             '  long name  : ', ctrc3l(jn), '   unit : ', ctrc3u(jn)
+            END DO
+            WRITE(numout,*) ' '
+
+            DO jl = 1, jp_medusa_2d
+               jn = jp_msa0_2d + jl - 1
+               WRITE(numout,*) '  2d diag nb : ', jn, '    short name : ', ctrc2d(jn), &
+                 &             '  long name  : ', ctrc2l(jn), '   unit : ', ctrc2u(jn)
+            END DO
+            WRITE(numout,*) ' '
+         ENDIF
+         !
+      ENDIF   
+         !
+# if defined key_debug_medusa
+            CALL flush(numout)
+# endif
+
+      ! 1.4 namelist natbio : biological parameters
+      ! -------------------------------------------
+      
+      xxi         = 0.
+      xaln        = 0.
+      xald        = 0.
+      jphy        = 0
+      xvpn        = 0.
+      xvpd        = 0.
+      xthetam     = 0.
+      xthetamd    = 0.
+!!
+      xsin0       = 0.
+      xnsi0       = 0.
+      xuif        = 0.
+!!
+      jliebig     = 0
+      xnln        = 0.
+      xnld        = 0.
+      xsld        = 0.
+      xfln        = 0.
+      xfld        = 0.
+!!
+      xgmi        = 0.
+      xgme        = 0.
+      xkmi        = 0.
+      xkme        = 0.
+      xphi	  = 0.
+      xbetan      = 0.
+      xbetac      = 0.
+      xkc         = 0.
+      xpmipn      = 0.
+      xpmid       = 0.
+      xpmepn      = 0.
+      xpmepd      = 0.
+      xpmezmi     = 0.
+      xpmed       = 0.
+!!
+      xmetapn     = 0.
+      xmetapd     = 0.
+      xmetazmi    = 0.
+      xmetazme    = 0.
+!!
+      jmpn        = 0
+      xmpn        = 0.
+      xkphn       = 0.
+      jmpd        = 0
+      xmpd        = 0.
+      xkphd       = 0.
+      jmzmi       = 0
+      xmzmi       = 0.
+      xkzmi       = 0.
+      jmzme       = 0
+      xmzme       = 0.
+      xkzme       = 0.
+!!
+      jmd         = 0
+      jsfd        = 0
+      xmd         = 0.
+      xmdc        = 0.
+!!
+      xthetapn    = 0.
+      xthetapd    = 0.
+      xthetazmi   = 0.
+      xthetazme   = 0.
+      xthetad     = 0.
+      xrfn        = 0.
+      xrsn        = 0.  !: (NOT USED HERE; RETAINED FOR LOBSTER)
+!!
+      jiron       = 0
+      xfe_mass    = 0.
+      xfe_sol     = 0.
+      xfe_sed     = 0.
+      xLgT        = 0.
+      xk_FeL	  = 0.
+      xk_sc_Fe    = 0.
+!!
+      jexport     = 0
+      jfdfate     = 0
+      jrratio     = 0
+      jocalccd    = 0
+      xridg_r0    = 0.
+      xfdfrac1	  = 0.
+      xfdfrac2	  = 0.
+      xfdfrac3	  = 0.
+      xcaco3a	  = 0.
+      xcaco3b	  = 0.
+      xmassc	  = 0.
+      xmassca	  = 0.
+      xmasssi	  = 0.
+      xprotca	  = 0.
+      xprotsi	  = 0.
+      xfastc	  = 0.
+      xfastca	  = 0.
+      xfastsi	  = 0.
+!!
+      jorgben     = 0
+      jinorgben   = 0
+      xsedn       = 0.
+      xsedfe      = 0.
+      xsedsi      = 0.
+      xsedc       = 0.
+      xsedca      = 0.
+      xburial     = 0.
+!!
+      jriver_n    = 0
+      jriver_si   = 0
+      jriver_c    = 0
+      jriver_alk  = 0
+      jriver_dep  = 1
+!!
+      xsdiss	  = 0.
+!!
+      vsed        = 0.
+      xhr         = 0.
+!!
+      sedlam	  = 0.
+      sedlostpoc  = 0.
+      jpkb	  = 0.
+      jdms        = 0
+            
+      !REWIND(numnatm)
+      !READ(numnatm,natbio)
+         ! Namelist natbio
+         ! -------------------
+         REWIND( numnatp_ref )              ! Namelist nampisdia in reference namelist : Pisces diagnostics
+         READ  ( numnatp_ref, natbio, IOSTAT = ios, ERR = 901)
+901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in reference namelist', lwp )
+
+         REWIND( numnatp_cfg )              ! Namelist nampisdia in configuration namelist : Pisces diagnostics
+         READ  ( numnatp_cfg, natbio, IOSTAT = ios, ERR = 902 )
+902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in configuration namelist', lwp )
+         IF(lwm) WRITE ( numonp, natbio )
+
+!! Primary production and chl related quantities
+!!       xxi         :  conversion factor from gC to mmolN 
+!!       xaln        :  Chl-a specific initial slope of P-I curve for non-diatoms 
+!!       xald        :  Chl-a specific initial slope of P-I curve for diatoms
+!!       jphy        :  phytoplankton T-dependent growth switch
+!!       xvpn        :  maximum growth rate for non-diatoms
+!!       xvpd        :  maximum growth rate for diatoms
+!!       xthetam     :  maximum Chl to C ratio for non-diatoms      
+!!       xthetamd    :  maximum Chl to C ratio for diatoms      
+!!
+!! Diatom silicon parameters
+!!       xsin0       :  minimum diatom Si:N ratio
+!!       xnsi0       :  minimum diatom N:Si ratio
+!!       xuif        :  hypothetical growth ratio at infinite Si:N ratio
+!!
+!! Nutrient limitation
+!!       jliebig     :  Liebig nutrient uptake switch
+!!       xnln        :  half-sat constant for DIN uptake by non-diatoms 
+!!       xnld        :  half-sat constant for DIN uptake by diatoms 
+!!       xsl         :  half-sat constant for Si uptake by diatoms 
+!!       xfld        :  half-sat constant for Fe uptake by diatoms  
+!!       xfln        :  half-sat constant for Fe uptake by non-datoms 
+!!
+!! Grazing
+!!       xgmi        :  microzoo maximum growth rate 
+!!       xgme        :  mesozoo maximum growth rate 
+!!       xkmi        :  microzoo grazing half-sat parameter
+!!       xkme        :  mesozoo grazing half-sat parameter
+!!       xphi        :  micro/mesozoo grazing inefficiency
+!!       xbetan      :  micro/mesozoo N assimilation efficiency
+!!       xbetac      :  micro/mesozoo C assimilation efficiency
+!!       xkc         :  micro/mesozoo net C growth efficiency
+!!       xpmipn      :  grazing preference of microzoo for non-diatoms
+!!       xpmid       :  grazing preference of microzoo for diatoms
+!!       xpmepn      :  grazing preference of mesozoo for non-diatoms 
+!!       xpmepd      :  grazing preference of mesozoo for diatoms
+!!       xpmezmi     :  grazing preference of mesozoo for microzoo
+!!       xpmed       :  grazing preference of mesozoo for detritus
+!!
+!! Metabolic losses
+!!       xmetapn     :  non-diatom metabolic loss rate
+!!       xmetapd     :  diatom     metabolic loss rate
+!!       xmetazmi    :  microzoo   metabolic loss rate
+!!       xmetazme    :  mesozoo    metabolic loss rate
+!!
+!! Mortality/Remineralisation
+!!       jmpn        :  non-diatom mortality functional form
+!!       xmpn        :  non-diatom mortality rate
+!!       xkphn       :  non-diatom mortality half-sat constant
+!!       jmpd        :  diatom     mortality functional form
+!!       xmpd        :  diatom mortality rate
+!!       xkphd       :  diatom mortality half-sat constant
+!!       jmzmi       :  microzoo   mortality functional form
+!!       xmzmi       :  microzoo mortality rate
+!!       xkzmi       :  microzoo mortality half-sat constant
+!!       jmzme       :  mesozoo    mortality functional form
+!!       xmzme       :  mesozoo mortality rate
+!!       xkzme       :  mesozoo mortality half-sat constant
+!!
+!! Remineralisation
+!!       jmd         :  detritus T-dependent remineralisation switch
+!!       jsfd        :  accelerate seafloor detritus remin. switch
+!!       xmd         :  detrital nitrogen remineralisation rate 
+!!       xmdc        :  detrital carbon remineralisation rate 
+!!
+!! Stochiometric ratios
+!!       xthetapn    :  non-diatom C:N ratio
+!!       xthetapd    :  diatom C:N ratio
+!!       xthetazmi   :  microzoo C:N ratio
+!!       xthetazme   :  mesozoo C:N ratio
+!!       xthetad     :  detritus C:N ratio
+!!       xrfn        :  phytoplankton Fe:N ratio
+!!	 xrsn        :  diatom Si:N ratio (*NOT* used)
+!!
+!! Iron parameters
+!!       jiron       :  iron scavenging submodel switch
+!!       xfe_mass    :  iron atomic mass
+!!	 xfe_sol     :  aeolian iron solubility
+!!	 xfe_sed     :  sediment iron input
+!!	 xLgT	     :  total ligand concentration (umol/m3)
+!!	 xk_FeL	     :  dissociation constant for (Fe + L)
+!!	 xk_sc_Fe    :  scavenging rate of "free" iron
+!!	 
+!! Fast-sinking detritus parameters
+!!       jexport     :  fast detritus remineralisation switch
+!!       jfdfate     :  fate of fast detritus at seafloor switch
+!!       jrratio     :  rain ratio switch
+!!       jocalccd    :  CCD switch
+!!       xridg_r0    :  Ridgwell rain ratio coefficient
+!!       xfdfrac1    :  fast-sinking fraction of diatom nat. mort. losses
+!!       xfdfrac2    :  fast-sinking fraction of meszooplankton mort. losses
+!!       xfdfrac3    :  fast-sinking fraction of diatom silicon grazing losses
+!!       xcaco3a     :  polar (high latitude) CaCO3 fraction
+!!       xcaco3b     :  equatorial (low latitude) CaCO3 fraction
+!!       xmassc      :  organic C mass:mole ratio, C106 H175 O40 N16 P1
+!!       xmassca     :  calcium carbonate mass:mole ratio, CaCO3
+!!       xmasssi     :  biogenic silicon mass:mole ratio, (H2SiO3)n
+!!       xprotca     :  calcium carbonate protection ratio
+!!       xprotsi     :  biogenic silicon protection ratio
+!!       xfastc      :  organic C remineralisation length scale
+!!       xfastca     :  calcium carbonate dissolution length scale
+!!       xfastsi     :  biogenic silicon dissolution length scale
+!!
+!! Benthic 
+!!       jorgben     :  does   organic detritus go to the benthos?
+!!       jinorgben   :  does inorganic detritus go to the benthos?
+!!       xsedn       :  organic   nitrogen sediment remineralisation rate 
+!!       xsedfe      :  organic   iron     sediment remineralisation rate 
+!!       xsedsi      :  inorganic silicon  sediment dissolution      rate 
+!!       xsedc       :  organic   carbon   sediment remineralisation rate 
+!!       xsedca      :  inorganic carbon   sediment dissolution      rate 
+!!       xburial     :  burial rate of seafloor detritus
+!!
+!! Riverine inputs
+!!       jriver_n    :  riverine N          input?
+!!       jriver_si   :  riverine Si         input?
+!!       jriver_c    :  riverine C          input?
+!!       jriver_alk  :  riverine alkalinity input?
+!!       jriver_dep  :  depth of riverine   input?
+!!
+!! Miscellaneous
+!!       xsdiss      :  diatom frustule dissolution rate
+!!
+!! Gravitational sinking      
+!!       vsed        :  detritus gravitational sinking rate 
+!!       xhr         :  coeff for Martin's remineralisation profile
+!!
+!! Additional parameters
+!!       sedlam      :  time coeff of POC in sediments
+!!      sedlostpoc   :  sediment geol loss for POC
+!!       jpkb        :  vertical layer for diagnostic of the vertical flux 
+!!                      NOTE that in LOBSTER it is a first vertical layers where 
+!!                      biology is active  
+!!
+!! UKESM1 - new diagnostics  !! Jpalm
+!!       jdms        :  include dms diagnostics
+!!
+!!
+!!
+
+      IF(lwp) THEN
+!!
+!! AXY (08/11/13): compilation key notification
+         WRITE(numout,*) '=== Compilation keys'
+#if defined key_roam
+         WRITE(numout,*)     &
+         &   ' key_roam                                                               = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_roam                                                               = INACTIVE'
+#endif        
+#if defined key_axy_carbchem
+         WRITE(numout,*)     &
+         &   ' key_axy_carbchem                                                       = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_axy_carbchem                                                       = INACTIVE'
+#endif        
+#if defined key_bs_axy_zforce
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_zforce                                                      = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_zforce                                                      = INACTIVE'
+#endif        
+#if defined key_bs_axy_yrlen
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_yrlen                                                       = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_yrlen                                                       = INACTIVE'
+#endif        
+#if defined key_deep_fe_fix
+         WRITE(numout,*)     &
+         &   ' key_deep_fe_fix                                                        = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_deep_fe_fix                                                        = INACTIVE'
+#endif        
+#if defined key_axy_nancheck
+         WRITE(numout,*)     &
+         &   ' key_axy_nancheck                                                       = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_axy_nancheck                                                       = INACTIVE'
+#endif        
+# if defined key_axy_pi_co2
+         WRITE(numout,*)     &
+         &   ' key_axy_pi_co2                                                         = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_axy_pi_co2                                                         = INACTIVE'
+# endif
+         WRITE(numout,*) ' '
+
+         WRITE(numout,*) 'natbio'
+         WRITE(numout,*) ' '
+!!
+!! Primary production and chl related quantities
+         WRITE(numout,*) '=== Primary production'
+         WRITE(numout,*)     &
+         &   ' conversion factor from gC to mmolN,                        xxi         =', xxi
+         WRITE(numout,*)     &
+         &   ' Chl-a specific initial slope of P-I curve for non-diatoms, xaln        = ', xaln
+         WRITE(numout,*)     &
+         &   ' Chl-a specific initial slope of P-I curve for diatoms,     xald        = ', xald
+         if (jphy.eq.1) then
+            WRITE(numout,*) &
+            &   ' phytoplankton growth is *temperature-dependent*            jphy        = ', jphy
+         elseif (jphy.eq.0) then
+            WRITE(numout,*) &
+            &   ' phytoplankton growth is *temperature-independent*          jphy        = ', jphy
+         endif
+         WRITE(numout,*)     &
+         &   ' maximum growth rate for non-diatoms,                       xvpn        = ', xvpn
+         WRITE(numout,*)     &
+         &   ' maximum growth rate for diatoms,                           xvpn        = ', xvpd
+         WRITE(numout,*)     &
+         &   ' maximum Chl to C ratio for non-diatoms,                    xthetam     = ', xthetam
+         WRITE(numout,*)     &
+         &   ' maximum Chl to C ratio for diatoms,                        xthetamd    = ', xthetamd
+!!
+!! Diatom silicon parameters
+         WRITE(numout,*) '=== Diatom silicon parameters'
+         WRITE(numout,*)     &
+         &   ' minimum diatom Si:N ratio,                                 xsin0       = ', xsin0
+         WRITE(numout,*)     &
+         &   ' minimum diatom N:Si ratio,                                 xnsi0       = ', xnsi0
+         WRITE(numout,*)     &
+         &   ' hypothetical growth ratio at infinite Si:N ratio,          xuif        = ', xuif
+!!
+!! Nutrient limitation
+         WRITE(numout,*) '=== Nutrient limitation'
+         if (jliebig.eq.1) then
+            WRITE(numout,*) &
+            &   ' nutrient uptake is a Liebig Law (= most limiting) function jliebig     = ', jliebig
+         elseif (jliebig.eq.0) then
+            WRITE(numout,*) &
+            &   ' nutrient uptake is a multiplicative function               jliebig     = ', jliebig
+         endif
+         WRITE(numout,*)     &
+         &   ' half-sat constant for DIN uptake by non-diatoms,           xnln        = ', xnln
+         WRITE(numout,*)     &
+         &   ' half-sat constant for DIN uptake by diatoms,               xnld        = ', xnld
+         WRITE(numout,*)     &
+         &   ' half-sat constant for Si uptake by diatoms,                xsld        = ', xsld
+         WRITE(numout,*)     &
+         &   ' half-sat constant for Fe uptake by non-diatoms,            xfln        = ', xfln
+         WRITE(numout,*)     &
+         &   ' half-sat constant for Fe uptake by diatoms,                xfld        = ', xfld
+!!
+!! Grazing
+         WRITE(numout,*) '=== Zooplankton grazing'
+         WRITE(numout,*)     &
+         &   ' microzoo maximum growth rate,                              xgmi        = ', xgmi
+         WRITE(numout,*)     &
+         &   ' mesozoo maximum growth rate,                               xgme        = ', xgme
+         WRITE(numout,*)     &
+         &   ' microzoo grazing half-sat parameter,                       xkmi        = ', xkmi
+         WRITE(numout,*)     &
+         &   ' mesozoo grazing half-sat parameter,                        xkme        = ', xkme
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo grazing inefficiency,                        xphi        = ', xphi
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo N assimilation efficiency,                   xbetan      = ', xbetan
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo C assimilation efficiency,                   xbetac      = ', xbetan
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo net C growth efficiency,                     xkc         = ', xkc
+         WRITE(numout,*)     &
+         &   ' grazing preference of microzoo for non-diatoms,            xpmipn      = ', xpmipn
+         WRITE(numout,*)     &
+         &   ' grazing preference of microzoo for detritus,               xpmid       = ', xpmid
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for non-diatoms,             xpmepn      = ', xpmepn
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for diatoms,                 xpmepd      = ', xpmepd
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for microzoo,                xpmezmi     = ', xpmezmi
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for detritus,                xpmed       = ', xpmed
+!!
+!! Metabolic losses
+         WRITE(numout,*) '=== Metabolic losses'
+         WRITE(numout,*)     &
+         &   ' non-diatom metabolic loss rate,                            xmetapn     = ', xmetapn
+         WRITE(numout,*)     &
+         &   ' diatom     metabolic loss rate,                            xmetapd     = ', xmetapd
+         WRITE(numout,*)     &
+         &   ' microzoo   metabolic loss rate,                            xmetazmi    = ', xmetazmi
+         WRITE(numout,*)     &
+         &   ' mesozoo    metabolic loss rate,                            xmetazme    = ', xmetazme
+!!
+!! Mortality losses
+         WRITE(numout,*) '=== Mortality losses'
+         if (jmpn.eq.1) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,            LINEAR    jmpn        = ', jmpn
+         elseif (jmpn.eq.2) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,         QUADRATIC    jmpn        = ', jmpn
+         elseif (jmpn.eq.3) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,        HYPERBOLIC    jmpn        = ', jmpn
+         elseif (jmpn.eq.4) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,           SIGMOID    jmpn        = ', jmpn
+         endif
+         WRITE(numout,*)     &
+         &   ' non-diatom mortality rate,                                 xmpn        = ', xmpn
+         WRITE(numout,*)     &
+         &   ' non-diatom mortality half-sat constant                     xkphn       = ', xkphn
+         if (jmpd.eq.1) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,                LINEAR    jmpd        = ', jmpd
+         elseif (jmpd.eq.2) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,             QUADRATIC    jmpd        = ', jmpd
+         elseif (jmpd.eq.3) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,            HYPERBOLIC    jmpd        = ', jmpd
+         elseif (jmpd.eq.4) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,               SIGMOID    jmpd        = ', jmpd
+         endif
+         WRITE(numout,*)     &
+         &   ' diatom mortality rate,                                     xmpd        = ', xmpd
+         WRITE(numout,*)     &
+         &   ' diatom mortality half-sat constant                         xkphd       = ', xkphd
+         if (jmzmi.eq.1) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,              LINEAR    jmzmi       = ', jmzmi
+         elseif (jmzmi.eq.2) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,           QUADRATIC    jmzmi       = ', jmzmi
+         elseif (jmzmi.eq.3) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,          HYPERBOLIC    jmzmi       = ', jmzmi
+         elseif (jmzmi.eq.4) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,             SIGMOID    jmzmi       = ', jmzmi
+         endif
+         WRITE(numout,*)     &
+         &   ' microzoo mortality rate,                                   xmzmi       = ', xmzmi
+         WRITE(numout,*)     &
+         &   ' mesozoo mortality half-sat constant,                       xkzmi       = ', xkzmi
+         if (jmzme.eq.1) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,               LINEAR    jmzme       = ', jmzme
+         elseif (jmzme.eq.2) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,            QUADRATIC    jmzme       = ', jmzme
+         elseif (jmzme.eq.3) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,           HYPERBOLIC    jmzme       = ', jmzme
+         elseif (jmzme.eq.4) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,              SIGMOID    jmzme       = ', jmzme
+         endif
+         WRITE(numout,*)     &
+         &   ' mesozoo mortality rate,                                    xmzme       = ', xmzme
+         WRITE(numout,*)     &
+         &   ' mesozoo mortality half-sat constant,                       xkzme       = ', xkzme
+!!
+!! Remineralisation
+         WRITE(numout,*) '=== Remineralisation'
+         if (jmd.eq.1) then
+            WRITE(numout,*) &
+            &   ' detritus remineralisation is *temperature-dependent*       jmd         = ', jmd
+         elseif (jmd.eq.0) then
+            WRITE(numout,*) &
+            &   ' detritus remineralisation is *temperature-independent*     jmd         = ', jmd
+         endif
+         if (jsfd.eq.1) then
+            WRITE(numout,*) &
+            &   ' detritus seafloor remineralisation is *accelerated*        jsfd        = ', jsfd
+         else
+            WRITE(numout,*) &
+            &   ' detritus seafloor remineralisation occurs at same rate     jsfd        = ', jsfd
+         endif
+         WRITE(numout,*)     &
+         &   ' detrital nitrogen remineralisation rate,                   xmd         = ', xmd
+         WRITE(numout,*)     &
+         &   ' detrital carbon remineralisation rate,                     xmdc        = ', xmdc
+!!
+!! Stochiometric ratios
+         WRITE(numout,*) '=== Stoichiometric ratios'
+         WRITE(numout,*)     &
+         &   ' non-diatom C:N ratio,                                      xthetapn    = ', xthetapn
+         WRITE(numout,*)     &
+         &   ' diatom C:N ratio,                                          xthetapd    = ', xthetapd
+         WRITE(numout,*)     &
+         &   ' microzoo C:N ratio,                                        xthetazmi   = ', xthetazmi
+         WRITE(numout,*)     &
+         &   ' mesozoo C:N ratio,                                         xthetazme   = ', xthetazme
+         WRITE(numout,*)     &
+         &   ' detritus C:N ratio,                                        xthetad     = ', xthetad
+         WRITE(numout,*)     &
+         &   ' phytoplankton Fe:N ratio,                                  xrfn        = ', xrfn
+         WRITE(numout,*)     &
+         &   ' diatom Si:N ratio,                                         xrsn        = ', xrsn
+!!	  
+!! Iron parameters
+         WRITE(numout,*) '=== Iron parameters'
+         if (jiron.eq.1) then
+            WRITE(numout,*)     &
+            &   ' Dutkiewicz et al. (2005) iron scavenging                   jiron       = ', jiron
+         elseif (jiron.eq.2) then
+            WRITE(numout,*)     &
+            &   ' Moore et al. (2004) iron scavenging                        jiron       = ', jiron
+         elseif (jiron.eq.3) then
+            WRITE(numout,*)     &
+            &   ' Moore et al. (2008) iron scavenging                        jiron       = ', jiron
+         elseif (jiron.eq.4) then
+            WRITE(numout,*)     &
+            &   ' Galbraith et al. (2010) iron scavenging                    jiron       = ', jiron
+         else
+            WRITE(numout,*)     &
+            &   ' There is **no** iron scavenging                            jiron       = ', jiron
+         endif
+         WRITE(numout,*)     &
+         &   ' iron atomic mass,                                          xfe_mass    = ', xfe_mass
+         WRITE(numout,*)     &
+         &   ' aeolian iron solubility,                                   xfe_sol     = ', xfe_sol
+         WRITE(numout,*)     &
+         &   ' sediment iron input,                                       xfe_sed     = ', xfe_sed
+         WRITE(numout,*)     &
+         &   ' total ligand concentration (umol/m3),                      xLgT        = ', xLgT
+         WRITE(numout,*)     &
+         &   ' dissociation constant for (Fe + L),                        xk_FeL      = ', xk_FeL
+         WRITE(numout,*)     &
+         &   ' scavenging rate for free iron,                             xk_sc_Fe    = ', xk_sc_Fe
+!!
+!! Fast-sinking detritus parameters
+         WRITE(numout,*) '=== Fast-sinking detritus'
+         if (jexport.eq.1) then
+            WRITE(numout,*) &
+            &   ' fast-detritus remin. uses Dunne et al. (2007; ballast)     jexport     = ', jexport
+         elseif (jexport.eq.2) then
+            WRITE(numout,*) &
+            &   ' fast-detritus remin. uses Martin et al. (1987)             jexport     = ', jexport
+         elseif (jexport.eq.2) then
+            WRITE(numout,*) &
+            &   ' fast-detritus remin. uses Henson et al. (2011)             jexport     = ', jexport
+         endif
+         if (jfdfate.eq.1) then
+            WRITE(numout,*) &
+            &   ' fast-detritus reaching seafloor becomes slow-detritus      jfdfate     = ', jfdfate
+         elseif (jfdfate.eq.0) then
+            WRITE(numout,*) &
+            &   ' fast-detritus reaching seafloor instantly remineralised    jfdfate     = ', jfdfate
+         endif
+#if defined key_roam
+         if (jrratio.eq.0) then
+            WRITE(numout,*) &
+            &   ' Dunne et al. (2005) rain ratio submodel                    jrratio     = ', jrratio
+         elseif (jrratio.eq.1) then
+            WRITE(numout,*) &
+            &   ' Ridgwell et al. (2007) rain ratio submodel (surface omega) jrratio     = ', jrratio
+         elseif (jrratio.eq.2) then
+            WRITE(numout,*) &
+            &   ' Ridgwell et al. (2007) rain ratio submodel (3D omega)      jrratio     = ', jrratio
+         endif
+#else          
+         jrratio = 0
+         WRITE(numout,*) &
+         &   ' Dunne et al. (2005) rain ratio submodel                    jrratio     = ', jrratio
+#endif          
+#if defined key_roam
+         if (jocalccd.eq.0) then
+            WRITE(numout,*) &
+            &   ' Default, fixed CCD used                                    jocalccd    = ', jocalccd
+         elseif (jocalccd.eq.1) then
+            WRITE(numout,*) &
+            &   ' Calculated, dynamic CCD used                               jocalccd    = ', jocalccd
+         endif
+#else          
+         jocalccd = 0
+         WRITE(numout,*) &
+         &   ' Default, fixed CCD used                                    jocalccd    = ', jocalccd
+#endif
+         WRITE(numout,*)     &
+         &   ' Ridgwell rain ratio coefficient,                           xridg_r0    = ', xridg_r0
+         WRITE(numout,*)     &
+         &   ' fast-sinking fraction of diatom nat. mort. losses,         xfdfrac1    = ', xfdfrac1
+         WRITE(numout,*)     &
+         &   ' fast-sinking fraction of mesozooplankton mort. losses,     xfdfrac2    = ', xfdfrac2
+         WRITE(numout,*)     &
+         &   ' fast-sinking fraction of diatom silicon grazing losses,    xfdfrac3    = ', xfdfrac3
+         WRITE(numout,*)     &
+         &   ' polar (high latitude) CaCO3 fraction,                      xcaco3a     = ', xcaco3a
+         WRITE(numout,*)     &
+         &   ' equatorial (low latitude) CaCO3 fraction,                  xcaco3b     = ', xcaco3b
+         WRITE(numout,*)     &
+         &   ' organic C mass:mole ratio, C106 H175 O40 N16 P1,           xmassc      = ', xmassc
+         WRITE(numout,*)     &
+         &   ' calcium carbonate mass:mole ratio, CaCO3,                  xmassca     = ', xmassca
+         WRITE(numout,*)     &
+         &   ' biogenic silicon mass:mole ratio, (H2SiO3)n,               xmasssi     = ', xmasssi
+         WRITE(numout,*)     &
+         &   ' calcium carbonate protection ratio,                        xprotca     = ', xprotca
+         WRITE(numout,*)     &
+         &   ' biogenic silicon protection ratio,                         xprotsi     = ', xprotsi
+         WRITE(numout,*)     &
+         &   ' organic C remineralisation length scale,                   xfastc      = ', xfastc
+         WRITE(numout,*)     &
+         &   ' calcium carbonate dissolution length scale,                xfastca     = ', xfastca
+         WRITE(numout,*)     &
+         &   ' biogenic silicon dissolution length scale,                 xfastsi     = ', xfastsi
+!!
+!! Benthos parameters
+         WRITE(numout,*) '=== Benthos parameters'
+         WRITE(numout,*)     &
+         &   ' does   organic detritus go to the benthos?,                jorgben     = ', jorgben
+         WRITE(numout,*)     &
+         &   ' does inorganic detritus go to the benthos?,                jinorgben   = ', jinorgben
+!!
+!! Some checks on parameters related to benthos parameters
+         if (jorgben.eq.1 .and. jsfd.eq.1) then
+            !! slow detritus going to benthos at an accelerated rate
+            WRITE(numout,*) '  === WARNING! ==='
+            WRITE(numout,*) '  jsfd *and* jorgben are active - please check that you wish this'
+            WRITE(numout,*) '  === WARNING! ==='
+         endif
+         if (jorgben.eq.1 .and. jfdfate.eq.1) then
+            !! fast detritus going to benthos but via slow detritus
+            WRITE(numout,*) '  === WARNING! ==='
+            WRITE(numout,*) '  jfdfate *and* jorgben are active - please check that you wish this'
+            WRITE(numout,*) '  === WARNING! ==='
+         endif
+         if (jorgben.eq.0 .and. jinorgben.eq.1) then
+            !! inorganic fast detritus going to benthos but organic fast detritus is not
+            WRITE(numout,*) '  === WARNING! ==='
+            WRITE(numout,*) '  jinorgben is active but jorgben is not - please check that you wish this'
+            WRITE(numout,*) '  === WARNING! ==='
+         endif
+         WRITE(numout,*)     &
+         &   ' organic   nitrogen sediment remineralisation rate,         xsedn       = ', xsedn
+         WRITE(numout,*)     &
+         &   ' organic   iron     sediment remineralisation rate,         xsedfe      = ', xsedfe
+         WRITE(numout,*)     &
+         &   ' inorganic silicon  sediment remineralisation rate,         xsedsi      = ', xsedsi
+         WRITE(numout,*)     &
+         &   ' organic   carbon   sediment remineralisation rate,         xsedc       = ', xsedc
+         WRITE(numout,*)     &
+         &   ' inorganic carbon   sediment remineralisation rate,         xsedca      = ', xsedca
+         WRITE(numout,*)     &
+         &   ' burial rate of seafloor detritus,                          xburial     = ', xburial
+!!
+!! Riverine inputs
+         WRITE(numout,*) '=== Riverine inputs'
+         if (jriver_n.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine N input,                                     jriver_n    = ', jriver_n
+         elseif (jriver_n.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine N concentrations specified,                       jriver_n    = ', jriver_n
+         elseif (jriver_n.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine N inputs specified,                               jriver_n    = ', jriver_n
+         endif
+         if (jriver_si.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine Si input,                                    jriver_si   = ', jriver_si
+         elseif (jriver_si.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine Si concentrations specified,                      jriver_si   = ', jriver_si
+         elseif (jriver_si.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine Si inputs specified,                              jriver_si   = ', jriver_si
+         endif
+         if (jriver_c.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine C input,                                     jriver_c    = ', jriver_c
+         elseif (jriver_c.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine C concentrations specified,                       jriver_c    = ', jriver_c
+         elseif (jriver_c.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine C inputs specified,                               jriver_c    = ', jriver_c
+         endif
+         if (jriver_alk.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine alkalinity input,                            jriver_alk  = ', jriver_alk
+         elseif (jriver_alk.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine alkalinity concentrations specified,              jriver_alk  = ', jriver_alk
+         elseif (jriver_alk.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine alkalinity inputs specified,                      jriver_alk  = ', jriver_alk
+         endif
+         !! AXY (19/07/12): prevent (gross) stupidity on part of user
+         if (jriver_dep.lt.1.or.jriver_dep.ge.jpk) then
+            jriver_dep = 1
+         endif
+         WRITE(numout,*)     &
+         &   ' riverine input applied to down to depth k = ...            jriver_dep  = ', jriver_dep
+!!
+!! Miscellaneous
+         WRITE(numout,*) '=== Miscellaneous'
+         WRITE(numout,*)     &
+         &   ' diatom frustule dissolution rate,                          xsdiss      = ', xsdiss
+!!
+!! Gravitational sinking      
+         WRITE(numout,*) '=== Gravitational sinking'
+         WRITE(numout,*)     &
+         &   ' detritus gravitational sinking rate,                       vsed        = ', vsed
+         WRITE(numout,*)     & 
+         &   ' coefficient for Martin et al. (1987) remineralisation,     xhr         = ', xhr
+!!
+!! Non-Medusa parameters
+         WRITE(numout,*) '=== Non-Medusa parameters'
+         WRITE(numout,*)     & 
+         &   ' time coeff of POC in sediments,                            sedlam      = ', sedlam
+         WRITE(numout,*)     &
+         &   ' Sediment geol loss for POC,                                sedlostpoc  = ', sedlostpoc
+         WRITE(numout,*)     &
+         &   ' Vert layer for diagnostic of vertical flux,                jpkp        = ', jpkb
+!!
+!! UKESM1 - new diagnostics  !! Jpalm
+         WRITE(numout,*) '=== UKESM1-related parameters'
+         WRITE(numout,*)     &
+         &   ' include DMS diagnostic?,                                   jdms        = ', jdms
+!!
+      ENDIF
+!!
+!! Key depth positions (with thanks to Andrew Coward for bug-fixing this bit)
+      DO jk = 1,jpk
+         !! level thickness
+         fthk  = e3t_1d(jk)
+         !! level depth (top of level)
+         fdep  = gdepw_1d(jk)
+         !! level depth (bottom of level)
+         fdep1 = fdep + fthk
+         !!
+         if (fdep.lt.100.0.AND.fdep1.gt.100.0) then        !  100 m
+            i0100 = jk
+         elseif (fdep.lt.150.0.AND.fdep1.gt.150.0) then    !  150 m (for BASIN)
+            i0150 = jk
+         elseif (fdep.lt.200.0.AND.fdep1.gt.200.0) then    !  200 m
+            i0200 = jk
+         elseif (fdep.lt.500.0.AND.fdep1.gt.500.0) then    !  500 m
+            i0500 = jk
+         elseif (fdep.lt.1000.0.AND.fdep1.gt.1000.0) then  ! 1000 m
+            i1000 = jk
+         elseif (fdep1.lt.1100.0) then                     ! 1100 m (for Moore et al. sedimentary iron)
+            i1100 = jk
+         endif
+      enddo
+      !!
+      IF(lwp) THEN
+          WRITE(numout,*) '=== Position of key depths'
+          WRITE(numout,*)     & 
+          &   ' jk position of  100 m horizon                              i0100       = ', i0100
+          WRITE(numout,*)     &
+          &   ' jk position of  150 m horizon                              i0150       = ', i0150
+          WRITE(numout,*)     & 
+          &   ' jk position of  200 m horizon                              i0200       = ', i0200
+          WRITE(numout,*)     & 
+          &   ' jk position of  500 m horizon                              i0500       = ', i0500
+          WRITE(numout,*)     & 
+          &   ' jk position of 1000 m horizon                              i1000       = ', i1000
+          WRITE(numout,*)     & 
+          &   ' jk position of 1100 m horizon [*]                          i1100       = ', i1100
+          WRITE(numout,*) 'Got here ' , SIZE(friver_dep)
+          CALL flush(numout)
+      ENDIF
+
+#if defined key_roam
+
+      ! 1.4b namelist natroam : ROAM parameters
+      ! ---------------------------------------
+      
+      xthetaphy = 0.
+      xthetazoo = 0.
+      xthetanit = 0.
+      xthetarem = 0.
+      xo2min    = 0.
+
+      !READ(numnatm,natroam)
+         ! Namelist natbio
+         ! -------------------
+         REWIND( numnatp_ref )              ! Namelist nampisdia in reference namelist : Pisces diagnostics
+         READ  ( numnatp_ref, natbio, IOSTAT = ios, ERR = 901)
+901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in reference namelist', lwp )
+
+         REWIND( numnatp_cfg )              ! Namelist nampisdia in configuration namelist : Pisces diagnostics
+         READ  ( numnatp_cfg, natbio, IOSTAT = ios, ERR = 902 )
+902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in configuration namelist', lwp )
+         IF(lwm) WRITE ( numonp, natbio )
+
+!! ROAM carbon, alkalinity and oxygen cycle parameters
+!!       xthetaphy :  oxygen evolution/consumption by phytoplankton
+!!       xthetazoo :  oxygen consumption by zooplankton
+!!       xthetanit :  oxygen consumption by nitrogen remineralisation
+!!       xthetarem :  oxygen consumption by carbon remineralisation
+!!       xo2min    :  oxygen minimum concentration
+
+      IF(lwp) THEN
+          WRITE(numout,*) 'natroam'
+          WRITE(numout,*) ' '
+!!
+!! ROAM carbon, alkalinity and oxygen cycle parameters
+          WRITE(numout,*) '=== ROAM carbon, alkalinity and oxygen cycle parameters'
+          WRITE(numout,*)     &
+          &   ' oxygen evolution/consumption by phytoplankton              xthetaphy   = ', xthetaphy
+          WRITE(numout,*)     &
+          &   ' oxygen consumption by zooplankton                          xthetazoo   = ', xthetazoo
+          WRITE(numout,*)     &
+          &   ' oxygen consumption by nitrogen remineralisation            xthetanit   = ', xthetanit
+          WRITE(numout,*)     &
+          &   ' oxygen consumption by carbon remineralisation              xthetarem   = ', xthetarem
+          WRITE(numout,*)     &
+          &   ' oxygen minimum concentration                               xo2min      = ', xo2min
+       ENDIF
+
+#endif
+
+      CALL flush(numout)
+
+      ! 1.5 namelist natopt : parameters for optic
+      ! ------------------------------------------
+
+      xkg0  = 0.
+      xkr0  = 0.
+      xkgp  = 0.
+      xkrp  = 0.
+      xlg   = 0.
+      xlr   = 0.
+      rpig  = 0.
+
+      !READ(numnatm,natopt)
+         ! Namelist natopt
+         ! -------------------
+         REWIND( numnatp_ref )              ! Namelist nampisdia in reference namelist : Pisces diagnostics
+         READ  ( numnatp_ref, natopt, IOSTAT = ios, ERR = 901)
+901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in reference namelist', lwp )
+
+         REWIND( numnatp_cfg )              ! Namelist nampisdia in configuration namelist : Pisces diagnostics
+         READ  ( numnatp_cfg, natopt, IOSTAT = ios, ERR = 902 )
+902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in configuration namelist', lwp )
+         IF(lwm) WRITE ( numonp, natopt )
+
+      IF(lwp) THEN
+         WRITE(numout,*) 'natopt'
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' green   water absorption coeff  xkg0  = ',xkg0
+         WRITE(numout,*) ' red water absorption coeff      xkr0  = ',xkr0
+         WRITE(numout,*) ' pigment red absorption coeff    xkrp  = ',xkrp
+         WRITE(numout,*) ' pigment green absorption coeff  xkgp  = ',xkgp
+         WRITE(numout,*) ' green chl exposant              xlg   = ',xlg
+         WRITE(numout,*) ' red   chl exposant              xlr   = ',xlr
+         WRITE(numout,*) ' chla/chla+phea ratio            rpig  = ',rpig
+         WRITE(numout,*) ' '
+
+      ENDIF
+
+      IF(lwp) THEN
+         WRITE(numout,*) 'NaN check'
+         WRITE(numout,*) ' '
+         q1 = -1.
+         q2 = 0.
+         q3 = log(q1)
+         write (numout,*) 'q3 = ', q3
+         if ( ieee_is_nan( q3 ) ) then
+            write (numout,*) 'NaN detected'
+         else
+            write (numout,*) 'NaN not detected'
+         endif
+         WRITE(numout,*) ' '
+       ENDIF
+
+   END SUBROUTINE trc_nam_medusa
+   
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                             No MEDUSA
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_nam_medusa                      ! Empty routine
+   END  SUBROUTINE  trc_nam_medusa
+#endif  
+
+   !!======================================================================
+END MODULE trcnam_medusa
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90_save
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90_save	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90_save	(revision 5707)
@@ -0,0 +1,1096 @@
+MODULE trcnam_medusa
+   !!======================================================================
+   !!                      ***  MODULE trcnam_medusa  ***
+   !! TOP :   initialisation of some run parameters for MEDUSA bio-model
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) Original code
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!              -   !  2011-04  (A. Yool) updated for ROAM project
+   !!              -   !  2013-05  (A. Yool) renamed (from trclsm) for v3.5
+   !!----------------------------------------------------------------------
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'   :                                       MEDUSA model
+   !!----------------------------------------------------------------------
+   !! trc_nam_medusa      : MEDUSA model initialisation
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! TOP variables
+   USE sms_medusa      ! sms trends
+   USE iom             ! I/O manager
+
+   !! AXY (04/02/14): necessary to find NaNs on HECTOR
+   USE, INTRINSIC :: ieee_arithmetic 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_nam_medusa   ! called by trcnam.F90 module
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id: trcnam_medusa.F90 1162 2008-07-02 09:33:33Z cetlod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_nam_medusa
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_nam_medusa  ***  
+      !!
+      !! ** Purpose :   read MEDUSA namelist
+      !!
+      !! ** input   :   file 'namelist.trc.sms' containing the following
+      !!             namelist: natbio, natopt, and natdbi ("key_trc_diabio")
+      !!
+      !! ekp: namelist nabio contains ALL parameters of the ecosystem 
+      !!      point sourses and sinks PLUS sediment exchange
+      !!      dia_bio - used by Lobster to output all point terms 
+      !!                (sourses and sinks of bio)
+      !!      dia_add - additional diagnostics for biology such as 
+      !!                primary production (2d depth integrated field or 3d)
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER            :: ji,jj,jk
+      REAL(wp)           :: fthk, fdep, fdep1
+      REAL(wp)           :: q1, q2, q3
+      !
+      NAMELIST/natbio/ xxi,xaln,xald,jphy,xvpn,xvpd,          &
+      &    xsin0,xnsi0,xuif,jliebig,                          &
+      &    xthetam,xthetamd,xnln,xnld,xsld,xfln,xfld,         &
+      &  xgmi,xgme,xkmi,xkme,xphi,xbetan,xbetac,xkc,          &
+      &    xpmipn,xpmid,xpmepn,xpmepd,xpmezmi,xpmed,          &
+      &  xmetapn,xmetapd,xmetazmi,xmetazme,                   &
+      &  jmpn,xmpn,xkphn,jmpd,xmpd,xkphd,jmzmi,xmzmi,xkzmi,   &
+      &    jmzme,xmzme,xkzme,jmd,jsfd,xmd,xmdc,               &
+      &  xthetapn,xthetapd,xthetazmi,xthetazme,xthetad,       &
+      &    xrfn,xrsn,vsed,xhr,                                &
+      &  jiron,xfe_mass,xfe_sol,xfe_sed,xLgT,xk_FeL,xk_sc_Fe, &
+      &  jexport,jfdfate,jrratio,jocalccd,xridg_r0,           &
+      &    xfdfrac1,xfdfrac2,xfdfrac3,                        &
+      &    xcaco3a,xcaco3b,xmassc,xmassca,xmasssi,xprotca,    &
+      &    xprotsi,xfastc,xfastca,xfastsi,                    &
+      &  jorgben,jinorgben,xsedn,xsedfe,xsedsi,xsedc,xsedca,  &
+      &    xburial,                                           &
+      &  jriver_n,jriver_si,jriver_c,jriver_alk,jriver_dep,   &
+      &    friver_dep,                                        &
+      &  xsdiss,                                              &
+      &  vsed,xhr,                                            &
+      &  sedlam,sedlostpoc,jpkb,jdms
+#if defined key_roam
+      NAMELIST/natroam/ xthetaphy,xthetazoo,xthetanit,        &
+      &    xthetarem,xo2min,                                  &
+      &    f3_pH,f3_h2co3,f3_hco3,f3_co3,f3_omcal,f3_omarg,   &
+      &    f2_ccd_cal,f2_ccd_arg
+#endif
+      NAMELIST/natopt/xkg0,xkr0,xkgp,xkrp,xlg,xlr,rpig
+      INTEGER :: jl, jn
+      TYPE(DIAG), DIMENSION(jp_medusa_2d)  :: meddia2d
+      TYPE(DIAG), DIMENSION(jp_medusa_3d)  :: meddia3d
+      TYPE(DIAG), DIMENSION(jp_medusa_trd) :: meddiabio
+      CHARACTER(LEN=32)   ::   clname
+      !!
+      NAMELIST/nammeddia/ meddia3d, meddia2d     ! additional diagnostics
+
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      clname = 'namelist_medusa'
+      IF(lwp) WRITE(numout,*) ' trc_nam_medusa: read MEDUSA namelist'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+# if defined key_debug_medusa
+      CALL flush(numout)
+# endif
+
+
+      CALL ctl_opn( numnatm, TRIM( clname ), 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'open namelist_medusa -- OK'
+      IF (lwp) write (numout,*) 'Now, read namilists inside :'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
+!     IF( .NOT.lk_iomput .AND. ln_diatrc ) THEN
+! should be done via iom_put exclusively but there are a lot of them; this is the easy first attempt !
+         !
+         ! Namelist nammeddia
+         ! -------------------
+         DO jl = 1, jp_medusa_2d
+            WRITE(meddia2d(jl)%sname,'("2D_",I1)') jl                      ! short name
+            WRITE(meddia2d(jl)%lname,'("2D DIAGNOSTIC NUMBER ",I2)') jl    ! long name
+            meddia2d(jl)%units = ' '                                       ! units
+         END DO
+# if defined key_debug_medusa
+      CALL flush(numout)
+# endif
+         !                                 ! 3D output arrays
+         DO jl = 1, jp_medusa_3d
+            WRITE(meddia3d(jl)%sname,'("3D_",I1)') jl                      ! short name
+            WRITE(meddia3d(jl)%lname,'("3D DIAGNOSTIC NUMBER ",I2)') jl    ! long name
+            meddia3d(jl)%units = ' '                                       ! units
+         END DO
+# if defined key_debug_medusa
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'Just before reading namelist_medusa :: nammeddia'
+      IF (lwp) write (numout,*) ' '
+      CALL flush(numout)
+# endif
+
+         REWIND( numnatm )               !
+         READ  ( numnatm, nammeddia )
+
+# if defined key_debug_medusa
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'reading namelist_medusa :: nammeddia OK'
+      IF (lwp) write (numout,*) 'Check number of variable in nammeddia:'
+      IF (lwp) write (numout,*) 'jp_medusa_2d: ',jp_medusa_2d ,'jp_medusa_3d: ',jp_medusa_3d
+      IF (lwp) write (numout,*) ' '
+      CALL flush(numout)
+# endif
+         DO jl = 1, jp_medusa_2d
+            jn = jp_msa0_2d + jl - 1
+            ctrc2d(jn) = meddia2d(jl)%sname
+            ctrc2l(jn) = meddia2d(jl)%lname
+            ctrc2u(jn) = meddia2d(jl)%units
+         END DO
+
+         DO jl = 1, jp_medusa_3d
+            jn = jp_msa0_3d + jl - 1
+            ctrc3d(jn) = meddia3d(jl)%sname
+            ctrc3l(jn) = meddia3d(jl)%lname
+            ctrc3u(jn) = meddia3d(jl)%units
+         END DO
+
+         IF(lwp) THEN                   ! control print
+# if defined key_debug_medusa
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'Var name assignation OK'
+      IF (lwp) write (numout,*) 'next check var names'
+      IF (lwp) write (numout,*) ' '
+            CALL flush(numout)
+# endif
+            WRITE(numout,*)
+            WRITE(numout,*) ' Namelist : natadd'
+            DO jl = 1, jp_medusa_3d
+               jn = jp_msa0_3d + jl - 1
+               WRITE(numout,*) '  3d diag nb : ', jn, '    short name : ', ctrc3d(jn), &
+                 &             '  long name  : ', ctrc3l(jn), '   unit : ', ctrc3u(jn)
+            END DO
+            WRITE(numout,*) ' '
+
+            DO jl = 1, jp_medusa_2d
+               jn = jp_msa0_2d + jl - 1
+               WRITE(numout,*) '  2d diag nb : ', jn, '    short name : ', ctrc2d(jn), &
+                 &             '  long name  : ', ctrc2l(jn), '   unit : ', ctrc2u(jn)
+            END DO
+            WRITE(numout,*) ' '
+         ENDIF
+         !
+# if defined key_debug_medusa
+            CALL flush(numout)
+# endif
+
+!     ENDIF
+
+      ! 1.4 namelist natbio : biological parameters
+      ! -------------------------------------------
+      
+      xxi         = 0.
+      xaln        = 0.
+      xald        = 0.
+      jphy        = 0
+      xvpn        = 0.
+      xvpd        = 0.
+      xthetam     = 0.
+      xthetamd    = 0.
+!!
+      xsin0       = 0.
+      xnsi0       = 0.
+      xuif        = 0.
+!!
+      jliebig     = 0
+      xnln        = 0.
+      xnld        = 0.
+      xsld        = 0.
+      xfln        = 0.
+      xfld        = 0.
+!!
+      xgmi        = 0.
+      xgme        = 0.
+      xkmi        = 0.
+      xkme        = 0.
+      xphi	  = 0.
+      xbetan      = 0.
+      xbetac      = 0.
+      xkc         = 0.
+      xpmipn      = 0.
+      xpmid       = 0.
+      xpmepn      = 0.
+      xpmepd      = 0.
+      xpmezmi     = 0.
+      xpmed       = 0.
+!!
+      xmetapn     = 0.
+      xmetapd     = 0.
+      xmetazmi    = 0.
+      xmetazme    = 0.
+!!
+      jmpn        = 0
+      xmpn        = 0.
+      xkphn       = 0.
+      jmpd        = 0
+      xmpd        = 0.
+      xkphd       = 0.
+      jmzmi       = 0
+      xmzmi       = 0.
+      xkzmi       = 0.
+      jmzme       = 0
+      xmzme       = 0.
+      xkzme       = 0.
+!!
+      jmd         = 0
+      jsfd        = 0
+      xmd         = 0.
+      xmdc        = 0.
+!!
+      xthetapn    = 0.
+      xthetapd    = 0.
+      xthetazmi   = 0.
+      xthetazme   = 0.
+      xthetad     = 0.
+      xrfn        = 0.
+      xrsn        = 0.  !: (NOT USED HERE; RETAINED FOR LOBSTER)
+!!
+      jiron       = 0
+      xfe_mass    = 0.
+      xfe_sol     = 0.
+      xfe_sed     = 0.
+      xLgT        = 0.
+      xk_FeL	  = 0.
+      xk_sc_Fe    = 0.
+!!
+      jexport     = 0
+      jfdfate     = 0
+      jrratio     = 0
+      jocalccd    = 0
+      xridg_r0    = 0.
+      xfdfrac1	  = 0.
+      xfdfrac2	  = 0.
+      xfdfrac3	  = 0.
+      xcaco3a	  = 0.
+      xcaco3b	  = 0.
+      xmassc	  = 0.
+      xmassca	  = 0.
+      xmasssi	  = 0.
+      xprotca	  = 0.
+      xprotsi	  = 0.
+      xfastc	  = 0.
+      xfastca	  = 0.
+      xfastsi	  = 0.
+!!
+      jorgben     = 0
+      jinorgben   = 0
+      xsedn       = 0.
+      xsedfe      = 0.
+      xsedsi      = 0.
+      xsedc       = 0.
+      xsedca      = 0.
+      xburial     = 0.
+!!
+      jriver_n    = 0
+      jriver_si   = 0
+      jriver_c    = 0
+      jriver_alk  = 0
+      jriver_dep  = 1
+!!
+      xsdiss	  = 0.
+!!
+      vsed        = 0.
+      xhr         = 0.
+!!
+      sedlam	  = 0.
+      sedlostpoc  = 0.
+      jpkb	  = 0.
+      jdms        = 0
+            
+      REWIND(numnatm)
+      READ(numnatm,natbio)
+
+!! Primary production and chl related quantities
+!!       xxi         :  conversion factor from gC to mmolN 
+!!       xaln        :  Chl-a specific initial slope of P-I curve for non-diatoms 
+!!       xald        :  Chl-a specific initial slope of P-I curve for diatoms
+!!       jphy        :  phytoplankton T-dependent growth switch
+!!       xvpn        :  maximum growth rate for non-diatoms
+!!       xvpd        :  maximum growth rate for diatoms
+!!       xthetam     :  maximum Chl to C ratio for non-diatoms      
+!!       xthetamd    :  maximum Chl to C ratio for diatoms      
+!!
+!! Diatom silicon parameters
+!!       xsin0       :  minimum diatom Si:N ratio
+!!       xnsi0       :  minimum diatom N:Si ratio
+!!       xuif        :  hypothetical growth ratio at infinite Si:N ratio
+!!
+!! Nutrient limitation
+!!       jliebig     :  Liebig nutrient uptake switch
+!!       xnln        :  half-sat constant for DIN uptake by non-diatoms 
+!!       xnld        :  half-sat constant for DIN uptake by diatoms 
+!!       xsl         :  half-sat constant for Si uptake by diatoms 
+!!       xfld        :  half-sat constant for Fe uptake by diatoms  
+!!       xfln        :  half-sat constant for Fe uptake by non-datoms 
+!!
+!! Grazing
+!!       xgmi        :  microzoo maximum growth rate 
+!!       xgme        :  mesozoo maximum growth rate 
+!!       xkmi        :  microzoo grazing half-sat parameter
+!!       xkme        :  mesozoo grazing half-sat parameter
+!!       xphi        :  micro/mesozoo grazing inefficiency
+!!       xbetan      :  micro/mesozoo N assimilation efficiency
+!!       xbetac      :  micro/mesozoo C assimilation efficiency
+!!       xkc         :  micro/mesozoo net C growth efficiency
+!!       xpmipn      :  grazing preference of microzoo for non-diatoms
+!!       xpmid       :  grazing preference of microzoo for diatoms
+!!       xpmepn      :  grazing preference of mesozoo for non-diatoms 
+!!       xpmepd      :  grazing preference of mesozoo for diatoms
+!!       xpmezmi     :  grazing preference of mesozoo for microzoo
+!!       xpmed       :  grazing preference of mesozoo for detritus
+!!
+!! Metabolic losses
+!!       xmetapn     :  non-diatom metabolic loss rate
+!!       xmetapd     :  diatom     metabolic loss rate
+!!       xmetazmi    :  microzoo   metabolic loss rate
+!!       xmetazme    :  mesozoo    metabolic loss rate
+!!
+!! Mortality/Remineralisation
+!!       jmpn        :  non-diatom mortality functional form
+!!       xmpn        :  non-diatom mortality rate
+!!       xkphn       :  non-diatom mortality half-sat constant
+!!       jmpd        :  diatom     mortality functional form
+!!       xmpd        :  diatom mortality rate
+!!       xkphd       :  diatom mortality half-sat constant
+!!       jmzmi       :  microzoo   mortality functional form
+!!       xmzmi       :  microzoo mortality rate
+!!       xkzmi       :  microzoo mortality half-sat constant
+!!       jmzme       :  mesozoo    mortality functional form
+!!       xmzme       :  mesozoo mortality rate
+!!       xkzme       :  mesozoo mortality half-sat constant
+!!
+!! Remineralisation
+!!       jmd         :  detritus T-dependent remineralisation switch
+!!       jsfd        :  accelerate seafloor detritus remin. switch
+!!       xmd         :  detrital nitrogen remineralisation rate 
+!!       xmdc        :  detrital carbon remineralisation rate 
+!!
+!! Stochiometric ratios
+!!       xthetapn    :  non-diatom C:N ratio
+!!       xthetapd    :  diatom C:N ratio
+!!       xthetazmi   :  microzoo C:N ratio
+!!       xthetazme   :  mesozoo C:N ratio
+!!       xthetad     :  detritus C:N ratio
+!!       xrfn        :  phytoplankton Fe:N ratio
+!!	 xrsn        :  diatom Si:N ratio (*NOT* used)
+!!
+!! Iron parameters
+!!       jiron       :  iron scavenging submodel switch
+!!       xfe_mass    :  iron atomic mass
+!!	 xfe_sol     :  aeolian iron solubility
+!!	 xfe_sed     :  sediment iron input
+!!	 xLgT	     :  total ligand concentration (umol/m3)
+!!	 xk_FeL	     :  dissociation constant for (Fe + L)
+!!	 xk_sc_Fe    :  scavenging rate of "free" iron
+!!	 
+!! Fast-sinking detritus parameters
+!!       jexport     :  fast detritus remineralisation switch
+!!       jfdfate     :  fate of fast detritus at seafloor switch
+!!       jrratio     :  rain ratio switch
+!!       jocalccd    :  CCD switch
+!!       xridg_r0    :  Ridgwell rain ratio coefficient
+!!       xfdfrac1    :  fast-sinking fraction of diatom nat. mort. losses
+!!       xfdfrac2    :  fast-sinking fraction of meszooplankton mort. losses
+!!       xfdfrac3    :  fast-sinking fraction of diatom silicon grazing losses
+!!       xcaco3a     :  polar (high latitude) CaCO3 fraction
+!!       xcaco3b     :  equatorial (low latitude) CaCO3 fraction
+!!       xmassc      :  organic C mass:mole ratio, C106 H175 O40 N16 P1
+!!       xmassca     :  calcium carbonate mass:mole ratio, CaCO3
+!!       xmasssi     :  biogenic silicon mass:mole ratio, (H2SiO3)n
+!!       xprotca     :  calcium carbonate protection ratio
+!!       xprotsi     :  biogenic silicon protection ratio
+!!       xfastc      :  organic C remineralisation length scale
+!!       xfastca     :  calcium carbonate dissolution length scale
+!!       xfastsi     :  biogenic silicon dissolution length scale
+!!
+!! Benthic 
+!!       jorgben     :  does   organic detritus go to the benthos?
+!!       jinorgben   :  does inorganic detritus go to the benthos?
+!!       xsedn       :  organic   nitrogen sediment remineralisation rate 
+!!       xsedfe      :  organic   iron     sediment remineralisation rate 
+!!       xsedsi      :  inorganic silicon  sediment dissolution      rate 
+!!       xsedc       :  organic   carbon   sediment remineralisation rate 
+!!       xsedca      :  inorganic carbon   sediment dissolution      rate 
+!!       xburial     :  burial rate of seafloor detritus
+!!
+!! Riverine inputs
+!!       jriver_n    :  riverine N          input?
+!!       jriver_si   :  riverine Si         input?
+!!       jriver_c    :  riverine C          input?
+!!       jriver_alk  :  riverine alkalinity input?
+!!       jriver_dep  :  depth of riverine   input?
+!!
+!! Miscellaneous
+!!       xsdiss      :  diatom frustule dissolution rate
+!!
+!! Gravitational sinking      
+!!       vsed        :  detritus gravitational sinking rate 
+!!       xhr         :  coeff for Martin's remineralisation profile
+!!
+!! Additional parameters
+!!       sedlam      :  time coeff of POC in sediments
+!!      sedlostpoc   :  sediment geol loss for POC
+!!       jpkb        :  vertical layer for diagnostic of the vertical flux 
+!!                      NOTE that in LOBSTER it is a first vertical layers where 
+!!                      biology is active  
+!!
+!! UKESM1 - new diagnostics  !! Jpalm
+!!       jdms        :  include dms diagnostics
+!!
+!!
+!!
+
+      IF(lwp) THEN
+!!
+!! AXY (08/11/13): compilation key notification
+         WRITE(numout,*) '=== Compilation keys'
+#if defined key_roam
+         WRITE(numout,*)     &
+         &   ' key_roam                                                               = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_roam                                                               = INACTIVE'
+#endif        
+#if defined key_axy_carbchem
+         WRITE(numout,*)     &
+         &   ' key_axy_carbchem                                                       = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_axy_carbchem                                                       = INACTIVE'
+#endif        
+#if defined key_bs_axy_zforce
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_zforce                                                      = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_zforce                                                      = INACTIVE'
+#endif        
+#if defined key_bs_axy_yrlen
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_yrlen                                                       = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_yrlen                                                       = INACTIVE'
+#endif        
+#if defined key_deep_fe_fix
+         WRITE(numout,*)     &
+         &   ' key_deep_fe_fix                                                        = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_deep_fe_fix                                                        = INACTIVE'
+#endif        
+#if defined key_axy_nancheck
+         WRITE(numout,*)     &
+         &   ' key_axy_nancheck                                                       = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_axy_nancheck                                                       = INACTIVE'
+#endif        
+# if defined key_axy_pi_co2
+         WRITE(numout,*)     &
+         &   ' key_axy_pi_co2                                                         = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_axy_pi_co2                                                         = INACTIVE'
+# endif
+         WRITE(numout,*) ' '
+
+         WRITE(numout,*) 'natbio'
+         WRITE(numout,*) ' '
+!!
+!! Primary production and chl related quantities
+         WRITE(numout,*) '=== Primary production'
+         WRITE(numout,*)     &
+         &   ' conversion factor from gC to mmolN,                        xxi         =', xxi
+         WRITE(numout,*)     &
+         &   ' Chl-a specific initial slope of P-I curve for non-diatoms, xaln        = ', xaln
+         WRITE(numout,*)     &
+         &   ' Chl-a specific initial slope of P-I curve for diatoms,     xald        = ', xald
+         if (jphy.eq.1) then
+            WRITE(numout,*) &
+            &   ' phytoplankton growth is *temperature-dependent*            jphy        = ', jphy
+         elseif (jphy.eq.0) then
+            WRITE(numout,*) &
+            &   ' phytoplankton growth is *temperature-independent*          jphy        = ', jphy
+         endif
+         WRITE(numout,*)     &
+         &   ' maximum growth rate for non-diatoms,                       xvpn        = ', xvpn
+         WRITE(numout,*)     &
+         &   ' maximum growth rate for diatoms,                           xvpn        = ', xvpd
+         WRITE(numout,*)     &
+         &   ' maximum Chl to C ratio for non-diatoms,                    xthetam     = ', xthetam
+         WRITE(numout,*)     &
+         &   ' maximum Chl to C ratio for diatoms,                        xthetamd    = ', xthetamd
+!!
+!! Diatom silicon parameters
+         WRITE(numout,*) '=== Diatom silicon parameters'
+         WRITE(numout,*)     &
+         &   ' minimum diatom Si:N ratio,                                 xsin0       = ', xsin0
+         WRITE(numout,*)     &
+         &   ' minimum diatom N:Si ratio,                                 xnsi0       = ', xnsi0
+         WRITE(numout,*)     &
+         &   ' hypothetical growth ratio at infinite Si:N ratio,          xuif        = ', xuif
+!!
+!! Nutrient limitation
+         WRITE(numout,*) '=== Nutrient limitation'
+         if (jliebig.eq.1) then
+            WRITE(numout,*) &
+            &   ' nutrient uptake is a Liebig Law (= most limiting) function jliebig     = ', jliebig
+         elseif (jliebig.eq.0) then
+            WRITE(numout,*) &
+            &   ' nutrient uptake is a multiplicative function               jliebig     = ', jliebig
+         endif
+         WRITE(numout,*)     &
+         &   ' half-sat constant for DIN uptake by non-diatoms,           xnln        = ', xnln
+         WRITE(numout,*)     &
+         &   ' half-sat constant for DIN uptake by diatoms,               xnld        = ', xnld
+         WRITE(numout,*)     &
+         &   ' half-sat constant for Si uptake by diatoms,                xsld        = ', xsld
+         WRITE(numout,*)     &
+         &   ' half-sat constant for Fe uptake by non-diatoms,            xfln        = ', xfln
+         WRITE(numout,*)     &
+         &   ' half-sat constant for Fe uptake by diatoms,                xfld        = ', xfld
+!!
+!! Grazing
+         WRITE(numout,*) '=== Zooplankton grazing'
+         WRITE(numout,*)     &
+         &   ' microzoo maximum growth rate,                              xgmi        = ', xgmi
+         WRITE(numout,*)     &
+         &   ' mesozoo maximum growth rate,                               xgme        = ', xgme
+         WRITE(numout,*)     &
+         &   ' microzoo grazing half-sat parameter,                       xkmi        = ', xkmi
+         WRITE(numout,*)     &
+         &   ' mesozoo grazing half-sat parameter,                        xkme        = ', xkme
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo grazing inefficiency,                        xphi        = ', xphi
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo N assimilation efficiency,                   xbetan      = ', xbetan
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo C assimilation efficiency,                   xbetac      = ', xbetan
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo net C growth efficiency,                     xkc         = ', xkc
+         WRITE(numout,*)     &
+         &   ' grazing preference of microzoo for non-diatoms,            xpmipn      = ', xpmipn
+         WRITE(numout,*)     &
+         &   ' grazing preference of microzoo for detritus,               xpmid       = ', xpmid
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for non-diatoms,             xpmepn      = ', xpmepn
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for diatoms,                 xpmepd      = ', xpmepd
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for microzoo,                xpmezmi     = ', xpmezmi
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for detritus,                xpmed       = ', xpmed
+!!
+!! Metabolic losses
+         WRITE(numout,*) '=== Metabolic losses'
+         WRITE(numout,*)     &
+         &   ' non-diatom metabolic loss rate,                            xmetapn     = ', xmetapn
+         WRITE(numout,*)     &
+         &   ' diatom     metabolic loss rate,                            xmetapd     = ', xmetapd
+         WRITE(numout,*)     &
+         &   ' microzoo   metabolic loss rate,                            xmetazmi    = ', xmetazmi
+         WRITE(numout,*)     &
+         &   ' mesozoo    metabolic loss rate,                            xmetazme    = ', xmetazme
+!!
+!! Mortality losses
+         WRITE(numout,*) '=== Mortality losses'
+         if (jmpn.eq.1) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,            LINEAR    jmpn        = ', jmpn
+         elseif (jmpn.eq.2) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,         QUADRATIC    jmpn        = ', jmpn
+         elseif (jmpn.eq.3) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,        HYPERBOLIC    jmpn        = ', jmpn
+         elseif (jmpn.eq.4) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,           SIGMOID    jmpn        = ', jmpn
+         endif
+         WRITE(numout,*)     &
+         &   ' non-diatom mortality rate,                                 xmpn        = ', xmpn
+         WRITE(numout,*)     &
+         &   ' non-diatom mortality half-sat constant                     xkphn       = ', xkphn
+         if (jmpd.eq.1) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,                LINEAR    jmpd        = ', jmpd
+         elseif (jmpd.eq.2) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,             QUADRATIC    jmpd        = ', jmpd
+         elseif (jmpd.eq.3) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,            HYPERBOLIC    jmpd        = ', jmpd
+         elseif (jmpd.eq.4) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,               SIGMOID    jmpd        = ', jmpd
+         endif
+         WRITE(numout,*)     &
+         &   ' diatom mortality rate,                                     xmpd        = ', xmpd
+         WRITE(numout,*)     &
+         &   ' diatom mortality half-sat constant                         xkphd       = ', xkphd
+         if (jmzmi.eq.1) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,              LINEAR    jmzmi       = ', jmzmi
+         elseif (jmzmi.eq.2) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,           QUADRATIC    jmzmi       = ', jmzmi
+         elseif (jmzmi.eq.3) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,          HYPERBOLIC    jmzmi       = ', jmzmi
+         elseif (jmzmi.eq.4) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,             SIGMOID    jmzmi       = ', jmzmi
+         endif
+         WRITE(numout,*)     &
+         &   ' microzoo mortality rate,                                   xmzmi       = ', xmzmi
+         WRITE(numout,*)     &
+         &   ' mesozoo mortality half-sat constant,                       xkzmi       = ', xkzmi
+         if (jmzme.eq.1) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,               LINEAR    jmzme       = ', jmzme
+         elseif (jmzme.eq.2) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,            QUADRATIC    jmzme       = ', jmzme
+         elseif (jmzme.eq.3) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,           HYPERBOLIC    jmzme       = ', jmzme
+         elseif (jmzme.eq.4) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,              SIGMOID    jmzme       = ', jmzme
+         endif
+         WRITE(numout,*)     &
+         &   ' mesozoo mortality rate,                                    xmzme       = ', xmzme
+         WRITE(numout,*)     &
+         &   ' mesozoo mortality half-sat constant,                       xkzme       = ', xkzme
+!!
+!! Remineralisation
+         WRITE(numout,*) '=== Remineralisation'
+         if (jmd.eq.1) then
+            WRITE(numout,*) &
+            &   ' detritus remineralisation is *temperature-dependent*       jmd         = ', jmd
+         elseif (jmd.eq.0) then
+            WRITE(numout,*) &
+            &   ' detritus remineralisation is *temperature-independent*     jmd         = ', jmd
+         endif
+         if (jsfd.eq.1) then
+            WRITE(numout,*) &
+            &   ' detritus seafloor remineralisation is *accelerated*        jsfd        = ', jsfd
+         else
+            WRITE(numout,*) &
+            &   ' detritus seafloor remineralisation occurs at same rate     jsfd        = ', jsfd
+         endif
+         WRITE(numout,*)     &
+         &   ' detrital nitrogen remineralisation rate,                   xmd         = ', xmd
+         WRITE(numout,*)     &
+         &   ' detrital carbon remineralisation rate,                     xmdc        = ', xmdc
+!!
+!! Stochiometric ratios
+         WRITE(numout,*) '=== Stoichiometric ratios'
+         WRITE(numout,*)     &
+         &   ' non-diatom C:N ratio,                                      xthetapn    = ', xthetapn
+         WRITE(numout,*)     &
+         &   ' diatom C:N ratio,                                          xthetapd    = ', xthetapd
+         WRITE(numout,*)     &
+         &   ' microzoo C:N ratio,                                        xthetazmi   = ', xthetazmi
+         WRITE(numout,*)     &
+         &   ' mesozoo C:N ratio,                                         xthetazme   = ', xthetazme
+         WRITE(numout,*)     &
+         &   ' detritus C:N ratio,                                        xthetad     = ', xthetad
+         WRITE(numout,*)     &
+         &   ' phytoplankton Fe:N ratio,                                  xrfn        = ', xrfn
+         WRITE(numout,*)     &
+         &   ' diatom Si:N ratio,                                         xrsn        = ', xrsn
+!!	  
+!! Iron parameters
+         WRITE(numout,*) '=== Iron parameters'
+         if (jiron.eq.1) then
+            WRITE(numout,*)     &
+            &   ' Dutkiewicz et al. (2005) iron scavenging                   jiron       = ', jiron
+         elseif (jiron.eq.2) then
+            WRITE(numout,*)     &
+            &   ' Moore et al. (2004) iron scavenging                        jiron       = ', jiron
+         elseif (jiron.eq.3) then
+            WRITE(numout,*)     &
+            &   ' Moore et al. (2008) iron scavenging                        jiron       = ', jiron
+         elseif (jiron.eq.4) then
+            WRITE(numout,*)     &
+            &   ' Galbraith et al. (2010) iron scavenging                    jiron       = ', jiron
+         else
+            WRITE(numout,*)     &
+            &   ' There is **no** iron scavenging                            jiron       = ', jiron
+         endif
+         WRITE(numout,*)     &
+         &   ' iron atomic mass,                                          xfe_mass    = ', xfe_mass
+         WRITE(numout,*)     &
+         &   ' aeolian iron solubility,                                   xfe_sol     = ', xfe_sol
+         WRITE(numout,*)     &
+         &   ' sediment iron input,                                       xfe_sed     = ', xfe_sed
+         WRITE(numout,*)     &
+         &   ' total ligand concentration (umol/m3),                      xLgT        = ', xLgT
+         WRITE(numout,*)     &
+         &   ' dissociation constant for (Fe + L),                        xk_FeL      = ', xk_FeL
+         WRITE(numout,*)     &
+         &   ' scavenging rate for free iron,                             xk_sc_Fe    = ', xk_sc_Fe
+!!
+!! Fast-sinking detritus parameters
+         WRITE(numout,*) '=== Fast-sinking detritus'
+         if (jexport.eq.1) then
+            WRITE(numout,*) &
+            &   ' fast-detritus remin. uses Dunne et al. (2007; ballast)     jexport     = ', jexport
+         elseif (jexport.eq.2) then
+            WRITE(numout,*) &
+            &   ' fast-detritus remin. uses Martin et al. (1987)             jexport     = ', jexport
+         elseif (jexport.eq.2) then
+            WRITE(numout,*) &
+            &   ' fast-detritus remin. uses Henson et al. (2011)             jexport     = ', jexport
+         endif
+         if (jfdfate.eq.1) then
+            WRITE(numout,*) &
+            &   ' fast-detritus reaching seafloor becomes slow-detritus      jfdfate     = ', jfdfate
+         elseif (jfdfate.eq.0) then
+            WRITE(numout,*) &
+            &   ' fast-detritus reaching seafloor instantly remineralised    jfdfate     = ', jfdfate
+         endif
+#if defined key_roam
+         if (jrratio.eq.0) then
+            WRITE(numout,*) &
+            &   ' Dunne et al. (2005) rain ratio submodel                    jrratio     = ', jrratio
+         elseif (jrratio.eq.1) then
+            WRITE(numout,*) &
+            &   ' Ridgwell et al. (2007) rain ratio submodel (surface omega) jrratio     = ', jrratio
+         elseif (jrratio.eq.2) then
+            WRITE(numout,*) &
+            &   ' Ridgwell et al. (2007) rain ratio submodel (3D omega)      jrratio     = ', jrratio
+         endif
+#else          
+         jrratio = 0
+         WRITE(numout,*) &
+         &   ' Dunne et al. (2005) rain ratio submodel                    jrratio     = ', jrratio
+#endif          
+#if defined key_roam
+         if (jocalccd.eq.0) then
+            WRITE(numout,*) &
+            &   ' Default, fixed CCD used                                    jocalccd    = ', jocalccd
+         elseif (jocalccd.eq.1) then
+            WRITE(numout,*) &
+            &   ' Calculated, dynamic CCD used                               jocalccd    = ', jocalccd
+         endif
+#else          
+         jocalccd = 0
+         WRITE(numout,*) &
+         &   ' Default, fixed CCD used                                    jocalccd    = ', jocalccd
+#endif
+         WRITE(numout,*)     &
+         &   ' Ridgwell rain ratio coefficient,                           xridg_r0    = ', xridg_r0
+         WRITE(numout,*)     &
+         &   ' fast-sinking fraction of diatom nat. mort. losses,         xfdfrac1    = ', xfdfrac1
+         WRITE(numout,*)     &
+         &   ' fast-sinking fraction of mesozooplankton mort. losses,     xfdfrac2    = ', xfdfrac2
+         WRITE(numout,*)     &
+         &   ' fast-sinking fraction of diatom silicon grazing losses,    xfdfrac3    = ', xfdfrac3
+         WRITE(numout,*)     &
+         &   ' polar (high latitude) CaCO3 fraction,                      xcaco3a     = ', xcaco3a
+         WRITE(numout,*)     &
+         &   ' equatorial (low latitude) CaCO3 fraction,                  xcaco3b     = ', xcaco3b
+         WRITE(numout,*)     &
+         &   ' organic C mass:mole ratio, C106 H175 O40 N16 P1,           xmassc      = ', xmassc
+         WRITE(numout,*)     &
+         &   ' calcium carbonate mass:mole ratio, CaCO3,                  xmassca     = ', xmassca
+         WRITE(numout,*)     &
+         &   ' biogenic silicon mass:mole ratio, (H2SiO3)n,               xmasssi     = ', xmasssi
+         WRITE(numout,*)     &
+         &   ' calcium carbonate protection ratio,                        xprotca     = ', xprotca
+         WRITE(numout,*)     &
+         &   ' biogenic silicon protection ratio,                         xprotsi     = ', xprotsi
+         WRITE(numout,*)     &
+         &   ' organic C remineralisation length scale,                   xfastc      = ', xfastc
+         WRITE(numout,*)     &
+         &   ' calcium carbonate dissolution length scale,                xfastca     = ', xfastca
+         WRITE(numout,*)     &
+         &   ' biogenic silicon dissolution length scale,                 xfastsi     = ', xfastsi
+!!
+!! Benthos parameters
+         WRITE(numout,*) '=== Benthos parameters'
+         WRITE(numout,*)     &
+         &   ' does   organic detritus go to the benthos?,                jorgben     = ', jorgben
+         WRITE(numout,*)     &
+         &   ' does inorganic detritus go to the benthos?,                jinorgben   = ', jinorgben
+!!
+!! Some checks on parameters related to benthos parameters
+         if (jorgben.eq.1 .and. jsfd.eq.1) then
+            !! slow detritus going to benthos at an accelerated rate
+            WRITE(numout,*) '  === WARNING! ==='
+            WRITE(numout,*) '  jsfd *and* jorgben are active - please check that you wish this'
+            WRITE(numout,*) '  === WARNING! ==='
+         endif
+         if (jorgben.eq.1 .and. jfdfate.eq.1) then
+            !! fast detritus going to benthos but via slow detritus
+            WRITE(numout,*) '  === WARNING! ==='
+            WRITE(numout,*) '  jfdfate *and* jorgben are active - please check that you wish this'
+            WRITE(numout,*) '  === WARNING! ==='
+         endif
+         if (jorgben.eq.0 .and. jinorgben.eq.1) then
+            !! inorganic fast detritus going to benthos but organic fast detritus is not
+            WRITE(numout,*) '  === WARNING! ==='
+            WRITE(numout,*) '  jinorgben is active but jorgben is not - please check that you wish this'
+            WRITE(numout,*) '  === WARNING! ==='
+         endif
+         WRITE(numout,*)     &
+         &   ' organic   nitrogen sediment remineralisation rate,         xsedn       = ', xsedn
+         WRITE(numout,*)     &
+         &   ' organic   iron     sediment remineralisation rate,         xsedfe      = ', xsedfe
+         WRITE(numout,*)     &
+         &   ' inorganic silicon  sediment remineralisation rate,         xsedsi      = ', xsedsi
+         WRITE(numout,*)     &
+         &   ' organic   carbon   sediment remineralisation rate,         xsedc       = ', xsedc
+         WRITE(numout,*)     &
+         &   ' inorganic carbon   sediment remineralisation rate,         xsedca      = ', xsedca
+         WRITE(numout,*)     &
+         &   ' burial rate of seafloor detritus,                          xburial     = ', xburial
+!!
+!! Riverine inputs
+         WRITE(numout,*) '=== Riverine inputs'
+         if (jriver_n.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine N input,                                     jriver_n    = ', jriver_n
+         elseif (jriver_n.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine N concentrations specified,                       jriver_n    = ', jriver_n
+         elseif (jriver_n.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine N inputs specified,                               jriver_n    = ', jriver_n
+         endif
+         if (jriver_si.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine Si input,                                    jriver_si   = ', jriver_si
+         elseif (jriver_si.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine Si concentrations specified,                      jriver_si   = ', jriver_si
+         elseif (jriver_si.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine Si inputs specified,                              jriver_si   = ', jriver_si
+         endif
+         if (jriver_c.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine C input,                                     jriver_c    = ', jriver_c
+         elseif (jriver_c.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine C concentrations specified,                       jriver_c    = ', jriver_c
+         elseif (jriver_c.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine C inputs specified,                               jriver_c    = ', jriver_c
+         endif
+         if (jriver_alk.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine alkalinity input,                            jriver_alk  = ', jriver_alk
+         elseif (jriver_alk.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine alkalinity concentrations specified,              jriver_alk  = ', jriver_alk
+         elseif (jriver_alk.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine alkalinity inputs specified,                      jriver_alk  = ', jriver_alk
+         endif
+         !! AXY (19/07/12): prevent (gross) stupidity on part of user
+         if (jriver_dep.lt.1.or.jriver_dep.ge.jpk) then
+            jriver_dep = 1
+         endif
+         WRITE(numout,*)     &
+         &   ' riverine input applied to down to depth k = ...            jriver_dep  = ', jriver_dep
+!!
+!! Miscellaneous
+         WRITE(numout,*) '=== Miscellaneous'
+         WRITE(numout,*)     &
+         &   ' diatom frustule dissolution rate,                          xsdiss      = ', xsdiss
+!!
+!! Gravitational sinking      
+         WRITE(numout,*) '=== Gravitational sinking'
+         WRITE(numout,*)     &
+         &   ' detritus gravitational sinking rate,                       vsed        = ', vsed
+         WRITE(numout,*)     & 
+         &   ' coefficient for Martin et al. (1987) remineralisation,     xhr         = ', xhr
+!!
+!! Non-Medusa parameters
+         WRITE(numout,*) '=== Non-Medusa parameters'
+         WRITE(numout,*)     & 
+         &   ' time coeff of POC in sediments,                            sedlam      = ', sedlam
+         WRITE(numout,*)     &
+         &   ' Sediment geol loss for POC,                                sedlostpoc  = ', sedlostpoc
+         WRITE(numout,*)     &
+         &   ' Vert layer for diagnostic of vertical flux,                jpkp        = ', jpkb
+!!
+!! UKESM1 - new diagnostics  !! Jpalm
+         WRITE(numout,*) '=== UKESM1-related parameters'
+         WRITE(numout,*)     &
+         &   ' include DMS diagnostic?,                                   jdms        = ', jdms
+!!
+      ENDIF
+!!
+!! Key depth positions (with thanks to Andrew Coward for bug-fixing this bit)
+      DO jk = 1,jpk
+         !! level thickness
+         fthk  = e3t_1d(jk)
+         !! level depth (top of level)
+         fdep  = gdepw_1d(jk)
+         !! level depth (bottom of level)
+         fdep1 = fdep + fthk
+         !!
+         if (fdep.lt.100.0.AND.fdep1.gt.100.0) then        !  100 m
+            i0100 = jk
+         elseif (fdep.lt.150.0.AND.fdep1.gt.150.0) then    !  150 m (for BASIN)
+            i0150 = jk
+         elseif (fdep.lt.200.0.AND.fdep1.gt.200.0) then    !  200 m
+            i0200 = jk
+         elseif (fdep.lt.500.0.AND.fdep1.gt.500.0) then    !  500 m
+            i0500 = jk
+         elseif (fdep.lt.1000.0.AND.fdep1.gt.1000.0) then  ! 1000 m
+            i1000 = jk
+         elseif (fdep1.lt.1100.0) then                     ! 1100 m (for Moore et al. sedimentary iron)
+            i1100 = jk
+         endif
+      enddo
+      !!
+      IF(lwp) THEN
+          WRITE(numout,*) '=== Position of key depths'
+          WRITE(numout,*)     & 
+          &   ' jk position of  100 m horizon                              i0100       = ', i0100
+          WRITE(numout,*)     &
+          &   ' jk position of  150 m horizon                              i0150       = ', i0150
+          WRITE(numout,*)     & 
+          &   ' jk position of  200 m horizon                              i0200       = ', i0200
+          WRITE(numout,*)     & 
+          &   ' jk position of  500 m horizon                              i0500       = ', i0500
+          WRITE(numout,*)     & 
+          &   ' jk position of 1000 m horizon                              i1000       = ', i1000
+          WRITE(numout,*)     & 
+          &   ' jk position of 1100 m horizon [*]                          i1100       = ', i1100
+          WRITE(numout,*) 'Got here ' , SIZE(friver_dep)
+          CALL flush(numout)
+      ENDIF
+
+#if defined key_roam
+
+      ! 1.4b namelist natroam : ROAM parameters
+      ! ---------------------------------------
+      
+      xthetaphy = 0.
+      xthetazoo = 0.
+      xthetanit = 0.
+      xthetarem = 0.
+      xo2min    = 0.
+
+      READ(numnatm,natroam)
+
+!! ROAM carbon, alkalinity and oxygen cycle parameters
+!!       xthetaphy :  oxygen evolution/consumption by phytoplankton
+!!       xthetazoo :  oxygen consumption by zooplankton
+!!       xthetanit :  oxygen consumption by nitrogen remineralisation
+!!       xthetarem :  oxygen consumption by carbon remineralisation
+!!       xo2min    :  oxygen minimum concentration
+
+      IF(lwp) THEN
+          WRITE(numout,*) 'natroam'
+          WRITE(numout,*) ' '
+!!
+!! ROAM carbon, alkalinity and oxygen cycle parameters
+          WRITE(numout,*) '=== ROAM carbon, alkalinity and oxygen cycle parameters'
+          WRITE(numout,*)     &
+          &   ' oxygen evolution/consumption by phytoplankton              xthetaphy   = ', xthetaphy
+          WRITE(numout,*)     &
+          &   ' oxygen consumption by zooplankton                          xthetazoo   = ', xthetazoo
+          WRITE(numout,*)     &
+          &   ' oxygen consumption by nitrogen remineralisation            xthetanit   = ', xthetanit
+          WRITE(numout,*)     &
+          &   ' oxygen consumption by carbon remineralisation              xthetarem   = ', xthetarem
+          WRITE(numout,*)     &
+          &   ' oxygen minimum concentration                               xo2min      = ', xo2min
+       ENDIF
+
+#endif
+
+      CALL flush(numout)
+
+      ! 1.5 namelist natopt : parameters for optic
+      ! ------------------------------------------
+
+      xkg0  = 0.
+      xkr0  = 0.
+      xkgp  = 0.
+      xkrp  = 0.
+      xlg   = 0.
+      xlr   = 0.
+      rpig  = 0.
+
+      READ(numnatm,natopt)
+
+      IF(lwp) THEN
+         WRITE(numout,*) 'natopt'
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' green   water absorption coeff  xkg0  = ',xkg0
+         WRITE(numout,*) ' red water absorption coeff      xkr0  = ',xkr0
+         WRITE(numout,*) ' pigment red absorption coeff    xkrp  = ',xkrp
+         WRITE(numout,*) ' pigment green absorption coeff  xkgp  = ',xkgp
+         WRITE(numout,*) ' green chl exposant              xlg   = ',xlg
+         WRITE(numout,*) ' red   chl exposant              xlr   = ',xlr
+         WRITE(numout,*) ' chla/chla+phea ratio            rpig  = ',rpig
+         WRITE(numout,*) ' '
+
+      ENDIF
+
+      IF(lwp) THEN
+         WRITE(numout,*) 'NaN check'
+         WRITE(numout,*) ' '
+         q1 = -1.
+         q2 = 0.
+         q3 = log(q1)
+         write (numout,*) 'q3 = ', q3
+         if ( ieee_is_nan( q3 ) ) then
+            write (numout,*) 'NaN detected'
+         else
+            write (numout,*) 'NaN not detected'
+         endif
+         WRITE(numout,*) ' '
+       ENDIF
+
+   END SUBROUTINE trc_nam_medusa
+   
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                             No MEDUSA
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_nam_medusa                      ! Empty routine
+   END  SUBROUTINE  trc_nam_medusa
+#endif  
+
+   !!======================================================================
+END MODULE trcnam_medusa
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcopt_medusa.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcopt_medusa.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcopt_medusa.F90	(revision 5707)
@@ -0,0 +1,169 @@
+MODULE trcopt_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcopt_medusa  ***
+   !! TOP :   MEDUSA Compute the light availability in the water column
+   !!======================================================================
+   !! History :    -   !  1995-05  (M. Levy) Original code
+   !!              -   !  1999-09  (J.-M. Andre, M. Levy) 
+   !!              -   !  1999-11  (C. Menkes, M.-A. Foujols) itabe initial
+   !!              -   !  2000-02  (M.A. Foujols) change x**y par exp(y*log(x))
+   !!             2.0  !  2007-12  (C. Deltel, G. Madec)  F90
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!----------------------------------------------------------------------
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'                                      MEDUSA bio-model
+   !!----------------------------------------------------------------------
+   !!   trc_opt_medusa        :   Compute the light availability in the water column
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trc
+   USE prtctl_trc      ! Print control for debbuging
+   USE sms_medusa
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_opt_medusa   ! called in trcprg.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id: trcopt_medusa.F90 1146 2008-06-25 11:42:56Z rblod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_opt_medusa( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_opt_medusa  ***
+      !!
+      !! ** Purpose :   computes the light propagation in the water column
+      !!              and the euphotic layer depth
+      !!
+      !! ** Method  :   local par is computed in w layers using light propagation
+      !!              mean par in t layers are computed by integration
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! index of the time stepping
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   zpig                                    ! total pigment
+      REAL(wp) ::   zkr                                     ! total absorption coefficient in red
+      REAL(wp) ::   zkg                                     ! total absorption coefficient in green
+      REAL(wp) ::   totchl                                  ! total Chl concentreation
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zpar100         ! irradiance at euphotic layer depth
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zpar0m          ! irradiance just below the surface
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zparr, zparg    ! red and green compound of par
+
+      CHARACTER (len=25) :: charout
+      !!---------------------------------------------------------------------
+
+      !! AXY (20/11/14): alter this to report on first MEDUSA call
+      !! IF( kt == nit000 ) THEN
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' trc_opt_medusa: MEDUSA optic-model'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+	 IF(lwp) WRITE(numout,*) ' kt =',kt
+      ENDIF
+
+      ! determination of surface irradiance
+      ! -----------------------------------
+      zpar0m (:,:)   = qsr   (:,:) * 0.43
+      ! AXY (22/08/14): when zpar0m = 0, zpar100 is also zero and calculating 
+      !                 euphotic depth is not possible (cf. the Arctic Octopus); 
+      !                 a "solution" to this is to set zpar0m to some minimal
+      !                 value such that zpar100 also has a non-zero value and
+      !                 euphotic depth can be calculated properly; note that,
+      !                 in older, non-diurnal versions of NEMO, this was much
+      !                 less of a problem; note also that, if pushed, I will
+      !                 claim that my minimal value of zpar0m refers to light
+      !                 from stars
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( zpar0m(ji,jj) <= 0.0 ) zpar0m(ji,jj) = 0.001  ! = 1 mW/m2
+         ENDDO
+      ENDDO
+      zpar100(:,:)   = zpar0m(:,:) * 0.01
+      xpar   (:,:,1) = zpar0m(:,:)
+      zparr  (:,:,1) = 0.5 * zpar0m(:,:)
+      zparg  (:,:,1) = 0.5 * zpar0m(:,:)
+
+
+      ! determination of xpar
+      ! ---------------------
+
+      DO jk = 2, jpk                     ! determination of local par in w levels
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               totchl =trn(ji,jj,jk-1,jpchn)+trn(ji,jj,jk-1,jpchd)
+               zpig = MAX( TINY(0.), totchl/rpig) 
+               zkr  = xkr0 + xkrp * EXP( xlr * LOG( zpig ) )
+               zkg  = xkg0 + xkgp * EXP( xlg * LOG( zpig ) )
+               zparr(ji,jj,jk) = zparr(ji,jj,jk-1) * EXP( -zkr * fse3t(ji,jj,jk-1) )
+               zparg(ji,jj,jk) = zparg(ji,jj,jk-1) * EXP( -zkg * fse3t(ji,jj,jk-1) )
+            END DO
+        END DO
+      END DO
+
+      DO jk = 1, jpkm1                   ! mean par in t levels
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               totchl =trn(ji,jj,jk  ,jpchn)+trn(ji,jj,jk  ,jpchd)
+               zpig = MAX( TINY(0.), totchl/rpig) 
+               zkr  = xkr0 + xkrp * EXP( xlr * LOG( zpig ) )
+               zkg  = xkg0 + xkgp * EXP( xlg * LOG( zpig ) )
+               zparr(ji,jj,jk)    = zparr(ji,jj,jk) / zkr / fse3t(ji,jj,jk) * ( 1 - EXP( -zkr*fse3t(ji,jj,jk) ) )
+               zparg(ji,jj,jk)    = zparg(ji,jj,jk) / zkg / fse3t(ji,jj,jk) * ( 1 - EXP( -zkg*fse3t(ji,jj,jk) ) )
+               xpar (ji,jj,jk) = MAX( zparr(ji,jj,jk) + zparg(ji,jj,jk), 1.e-15 )
+            END DO
+         END DO
+      END DO
+
+      ! 3. Determination of euphotic layer depth
+      ! ----------------------------------------
+
+      ! Euphotic layer bottom level
+      neln(:,:) = 1                                           ! initialisation of EL level
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+           DO ji = 1, jpi
+              IF( xpar(ji,jj,jk) >= zpar100(ji,jj) )   neln(ji,jj) = jk+1 ! 1rst T-level strictly below EL bottom
+              !                                                  ! nb. this is to ensure compatibility with
+              !                                                  ! nmld_trc definition in trd_mld_trc_zint
+           END DO
+         END DO
+      ENDDO
+
+      ! Euphotic layer depth
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            xze(ji,jj) = fsdepw( ji, jj, neln(ji,jj) )            ! exact EL depth
+         END DO
+      ENDDO 
+
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('opt')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
+      ENDIF
+
+   END SUBROUTINE trc_opt_medusa
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No MEDUSA bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE trc_opt_medusa( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'trc_opt_medusa: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_opt_medusa
+#endif 
+
+   !!======================================================================
+END MODULE  trcopt_medusa
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcoxy_medusa.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcoxy_medusa.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcoxy_medusa.F90	(revision 5707)
@@ -0,0 +1,342 @@
+MODULE trcoxy_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcoxy_medusa  ***
+   !! TOP :   MEDUSA
+   !!======================================================================
+   !! History :
+   !!  -   !  2011-07  (A. Yool)             added for ROAM project
+   !!----------------------------------------------------------------------
+#if defined key_medusa && defined key_roam
+   !!----------------------------------------------------------------------
+   !!                                        MEDUSA oxygen cycle
+   !!----------------------------------------------------------------------
+   !!   trc_oxy_medusa        :  
+   !!----------------------------------------------------------------------
+      USE oce_trc
+      USE trc
+      USE sms_medusa
+      USE lbclnk
+      USE prtctl_trc      ! Print control for debugging
+
+      IMPLICIT NONE
+      PRIVATE
+      
+      PUBLIC   trc_oxy_medusa    ! called in trc_bio_medusa
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id: trcbio.F90 1146 2008-06-25 11:42:56Z rblod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+! The following is a map of the subroutines contained within this module
+! - trc_oxy_medusa
+!      - CALLS gas_transfer
+!      - CALLS oxy_schmidt
+!      - CALLS oxy_sato
+
+CONTAINS
+
+!=======================================================================
+!
+   SUBROUTINE trc_oxy_medusa( pt, ps, uwind, vwind, pp0, o2, dz, &  !! inputs
+      kw660, o2flux, o2sat )                                        !! outputs
+!      
+!=======================================================================
+      !!
+      !! Title  : Calculates O2 change due to air-sea gas exchange
+      !! Author : Andrew Yool
+      !! Date   : 15/10/04 (revised 08/07/11)
+      !!
+      !! This subroutine calculates oxygen air-sea gas exchange in the
+      !! surface layer of the ocean.  The formulation is taken from one 
+      !! written by Ray Najjar for the OCMIP-2 project.  The routine
+      !! calls two other subroutines, oxy_schmidt.f (calculates Schmidt 
+      !! number of oxygen) and oxy_sato.f (calculates oxygen saturation 
+      !! concentration at 1 atm).
+      !! 
+      !! Function inputs are (in order) : 
+      !!     pt      temperature                     (degrees C)
+      !!     ps      salinity                        (PSU)
+      !!     uwind   u-wind velocity                 (m/s)
+      !!     vwind   v-wind velocity                 (m/s)
+      !!     pp0     surface pressure                (divided by 1 atm)
+      !!     o2      surface O2 concentration        (mol/m3)
+      !!     dz      surface layer thickness         (m)
+      !! (*) kw660   gas transfer velocity           (m/s)
+      !! (*) o2flux  exchange rate of oxygen         (mol/m3/s)
+      !! (+) o2sat   oxygen saturation concentration (mol/m3)
+      !! 
+      !! Where (*) is the function output (note its units).  
+      !!
+!=======================================================================
+
+      implicit none
+!
+      REAL(wp), INTENT( in )    :: pt
+      REAL(wp), INTENT( in )    :: ps
+      REAL(wp), INTENT( in )    :: uwind
+      REAL(wp), INTENT( in )    :: vwind
+      REAL(wp), INTENT( in )    :: pp0
+      REAL(wp), INTENT( in )    :: o2
+      REAL(wp), INTENT( in )    :: dz
+      REAL(wp), INTENT( inout ) :: kw660, o2flux, o2sat
+!
+      REAL(wp) :: scl_wind, kwo2, o2schmidt, o2sato
+!
+! Calculate gas transfer
+! 
+      call gas_transfer(uwind, vwind, scl_wind, kw660)
+!
+! Calculate oxygen Schmidt number
+! 
+      call oxy_schmidt(pt, o2schmidt)
+!
+! Calculate the transfer velocity for O2 (m/s)
+!
+      kwo2 = kw660 * (660 / o2schmidt)**0.5
+!
+! Calculate the saturation concentration for oxygen (mol/m3)
+!
+      call oxy_sato(pt, ps, o2sato)
+      o2sat = o2sato * pp0
+!
+! Calculate time rate of change of O2 due to gas exchange (mol/m3/s)
+!
+      o2flux = kwo2 * (o2sat - o2) / dz
+!
+      END SUBROUTINE trc_oxy_medusa
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+   SUBROUTINE oxy_schmidt( pt, &  !! input
+      o2_schmidt )                !! output
+!      
+!=======================================================================
+      !!
+      !! Title  : Calculates Schmidt number for ocean uptake of O2
+      !! Author : Andrew Yool
+      !! Date   : 14/10/04 (revised 08/07/11)
+      !! 
+      !! This subroutine calculates the Schmidt number for O2 using sea 
+      !! surface temperature.  The code is based upon that developed as 
+      !! part of the OCMIP-2 project (1998-2000).  The coefficients used 
+      !! are taken from Keeling et al. (1998, GBC, 12, 141-163).
+      !! 
+      !! Function inputs are (in order) : 
+      !!     t           temperature (degrees C)
+      !! (*) o2_schmidt  oxygen Schmidt number
+      !! 
+      !! Where (*) is the function output.
+      !!
+!=======================================================================
+
+      implicit none
+!
+      REAL(wp) :: pt, o2_schmidt
+      REAL(wp) :: a0, a1, a2, a3
+!
+      data a0 /    1638.0 /
+      data a1 /    -81.83 /
+      data a2 /     1.483 /
+      data a3 / -0.008004 /
+!
+      o2_schmidt = a0 + pt*(a1 + pt*(a2 + pt*a3))
+!
+      END SUBROUTINE oxy_schmidt
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+   SUBROUTINE oxy_sato( pt, ps, &  !! inputs 
+      o2_sato )                    !! output
+!      
+!=======================================================================
+      !!
+      !! Title  : Calculates O2 saturation at 1 atm pressure
+      !! Author : Andrew Yool
+      !! Date   : 14/10/04 (revised 08/07/11)
+      !! 
+      !! This subroutine calculates the oxygen saturation concentration
+      !! at 1 atmosphere pressure in mol/m3 given ambient temperature
+      !! and salinity.  This formulation is (ostensibly) taken from 
+      !! Garcia & Gordon (1992, L&O, 1307-1312).  The function works
+      !! in the range -1.9 <= T <= 40, 0 <= S <= 42.
+      !!
+      !! Function inputs are (in order) : 
+      !!     pt       temperature (degrees C)
+      !!     ps       salinity (PSU)
+      !! (*) o2_sato  oxygen saturation (mol/m3)
+      !!
+      !! Where (*) is the function output (note its units).  
+      !!
+      !! Check value : T = 10, S = 35, oxy_sato = 0.282015 mol/m3
+      !!
+!=======================================================================
+
+      implicit none
+!
+      REAL(wp) :: pt, ps, o2_sato
+!
+      REAL(wp) :: a0, a1, a2, a3, a4, a5
+      REAL(wp) :: b0, b1, b2, b3
+      REAL(wp) :: c0
+!
+      REAL(wp) :: tt, tk, ts, ts2, ts3, ts4, ts5
+      REAL(wp) :: ans1, ans2
+!
+      data a0 /  2.00907    /
+      data a1 /  3.22014    /
+      data a2 /  4.05010    /
+      data a3 /  4.94457    /
+      data a4 / -2.56847E-1 /
+      data a5 /  3.88767    /
+!
+      data b0 / -6.24523E-3 /
+      data b1 / -7.37614E-3 /
+      data b2 / -1.03410E-2 /
+      data b3 / -8.17083E-3 /
+!
+      data c0 / -4.88682E-7 /
+!     
+      tt   = 298.15 - pt
+      tk   = 273.15 + pt
+      ts   = log(tt / tk)
+      ts2  = ts**2
+      ts3  = ts**3
+      ts4  = ts**4
+      ts5  = ts**5
+      ans1 = a0 + a1*ts + a2*ts2 + a3*ts3 + a4*ts4 + a5*ts5  &
+           + ps*(b0 + b1*ts + b2*ts2 + b3*ts3)               &
+           + c0*(ps*ps)
+      ans2 = exp(ans1)
+!
+!  Convert from ml/l to mol/m3
+!
+      o2_sato = (ans2 / 22391.6) * 1000.0
+!
+      END SUBROUTINE oxy_sato
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+   SUBROUTINE gas_transfer( uwind, vwind, &  !! input 
+      scl_wind, k )                          !! output
+!      
+!=======================================================================
+      !!
+      !! Title  : Calculates gas transfer velocity
+      !! Author : Andrew Yool
+      !! Date   : 15/10/04 (revised 04/08/2011)
+      !! 
+      !! This subroutine uses near-surface wind speed to calculate gas
+      !! transfer velocity for use in CO2 and O2 exchange calculations.
+      !! 
+      !! Note that the parameterisation of Wanninkhof quoted here is a
+      !! truncation of the original equation.  It excludes a chemical
+      !! enhancement function (based on temperature), although such
+      !! temperature dependence is reported negligible by Etcheto &
+      !! Merlivat (1988).
+      !! 
+      !! Note also that in calculating scalar wind, the variance of the
+      !! wind over the period of a timestep is ignored.  Some authors,
+      !! for instance OCMIP-2, favour including some reference to the
+      !! variability of wind.  However, their wind fields are averaged
+      !! over relatively long time periods, and so this issue may be
+      !! safely (!) ignored here.
+      !! 
+      !! Subroutine inputs are (in order) :
+      !!     uwind     wind u velocity at 10 m (m/s)
+      !!     vwind     wind v velocity at 10 m (m/s)
+      !! (+) scl_wind  scalar wind velocity at 10 m (m/s)
+      !! (*) k         gas transfer velocity (m/s)
+      !! Where (*) is the function output and (+) is a diagnostic output.
+      !!
+!=======================================================================
+
+      implicit none
+!
+! Input variables
+      REAL(wp) :: uwind, vwind
+!
+! Output variables
+      REAL(wp) :: scl_wind, k, tmp_k
+!
+! Choice of parameterisation
+      INTEGER  :: eqn
+!
+! Coefficients for various parameterisations
+      REAL(wp), DIMENSION(6) :: a
+      REAL(wp), DIMENSION(6) :: b
+!
+! Values of coefficients
+      data a(1) / 0.166 /  ! Liss & Merlivat (1986)    [approximated]
+      data a(2) / 0.3   /  ! Wanninkhof (1992)         [sans enhancement]
+      data a(3) / 0.23  /  ! Nightingale et al. (2000) [good]
+      data a(4) / 0.23  /  ! Nightingale et al. (2000) [better]
+      data a(5) / 0.222 /  ! Nightingale et al. (2000) [best]
+      data a(6) / 0.337 /  ! OCMIP-2                   [sans variability]
+!
+      data b(1) / 0.133 /
+      data b(2) / 0.0   /
+      data b(3) / 0.0   /
+      data b(4) / 0.1   /
+      data b(5) / 0.333 /
+      data b(6) / 0.0   /
+!
+! Which parameterisation is to be used?
+      eqn = 2
+!
+! Calculate scalar wind (m/s)
+      scl_wind = (uwind**2 + vwind**2)**0.5
+!
+! Calculate gas transfer velocity (cm/h)
+      tmp_k = (a(eqn) * scl_wind**2) + (b(eqn) * scl_wind)
+!
+! Convert tmp_k from cm/h to m/s
+      k = tmp_k / (100. * 3600.)
+!
+      END SUBROUTINE gas_transfer
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No MEDUSA bio-model
+   !!======================================================================
+
+CONTAINS
+
+   SUBROUTINE trc_oxy_medusa( pt, ps, uwind, vwind, pp0, o2, dz, &  !! inputs
+      kw660, o2flux, o2sat )                                        !! outputs
+      USE par_kind
+
+      REAL(wp), INTENT( in )    :: pt
+      REAL(wp), INTENT( in )    :: ps
+      REAL(wp), INTENT( in )    :: pp0
+      REAL(wp), INTENT( in )    :: o2
+      REAL(wp), INTENT( in )    :: dz
+      REAL(wp), INTENT( inout ) :: kw660, o2flux, o2sat
+
+      WRITE(*,*) 'trc_oxy_medusa: You should not have seen this print! error?', kt
+
+   END SUBROUTINE trc_oxy_medusa
+#endif
+
+   !!======================================================================
+END MODULE  trcoxy_medusa
+  
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsed_medusa.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsed_medusa.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsed_medusa.F90	(revision 5707)
@@ -0,0 +1,352 @@
+MODULE trcsed_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcsed_medusa  ***
+   !! TOP :   MEDUSA Compute loss of organic matter in the sediments
+   !!======================================================================
+   !! History :    -   !  1995-06 (M. Levy)  original code
+   !!              -   !  2000-12 (E. Kestenare)  clean up
+   !!             2.0  !  2007-12  (C. Deltel, G. Madec)  F90 + simplifications
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!              -   !  2011-04  (A. Yool) updated for ROAM project
+   !!----------------------------------------------------------------------
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'                                      MEDUSA bio-model
+   !!----------------------------------------------------------------------
+   !!   trc_sed_medusa        :  Compute loss of organic matter in the sediments
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trc
+   USE sms_medusa
+   !! AXY (10/02/09)
+   USE iom
+
+   USE lbclnk
+   USE prtctl_trc      ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_sed_medusa     ! called in ???
+   PUBLIC   trc_sed_medusa_sbc      
+
+   !! * Module variables
+   INTEGER ::                   &
+     ryyss,                     &  !: number of seconds per year
+     rmtss                         !: number of seconds per month
+
+   !! AXY (10/02/09)
+   LOGICAL, PUBLIC ::                  &
+      bdustfer = .TRUE.
+   REAL(wp), PUBLIC ::                 &
+      sedfeinput = 1.e-9_wp  ,         &
+      dustsolub  = 0.014_wp
+   INTEGER ::                          &
+      numdust,                         &
+      nflx1,  nflx2,                   &
+      nflx11, nflx12
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id: trcsed_medusa.F90 1146 2008-06-25 11:42:56Z rblod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_sed_medusa( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_sed_medusa  ***
+      !!
+      !! ** Purpose :   compute the now trend due to the vertical sedimentation of
+      !!              detritus and add it to the general trend of detritus equations
+      !!
+      !! ** Method  :   this ROUTINE compute not exactly the advection but the
+      !!              transport term, i.e.  dz(wt) and dz(ws)., dz(wtr)
+      !!              using an upstream scheme
+      !!              the now vertical advection of tracers is given by:
+      !!                      dz(trn wn) = 1/bt dk+1( e1t e2t vsed (trn) )
+      !!              add this trend now to the general trend of tracer (ta,sa,tra):
+      !!                             tra = tra + dz(trn wn)
+      !!        
+      !!              IF 'key_trc_diabio' is defined, the now vertical advection
+      !!              trend of passive tracers is saved for futher diagnostics.
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      !! AXY (10/02/09)
+      INTEGER  ::   jnt
+      !!
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   ztra
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwork
+
+      !! AXY (10/02/09)
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zsidep    !! Si deposition
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zirondep  !! Fe deposition
+      REAL(wp) ::   rfact2
+
+      CHARACTER (len=25) :: charout
+      !!---------------------------------------------------------------------
+
+      !! AXY (10/02/09)
+      jnt = 1
+      rfact2 = 1.0
+
+      ! Number of seconds per year and per month
+      ryyss = nyear_len(1) * rday
+      rmtss = ryyss / raamo
+
+      !! AXY (20/11/14): alter this to report on first MEDUSA call
+      !! IF( kt == nit000 ) THEN
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' trc_sed_medusa: MEDUSA sedimentation'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+	 IF(lwp) WRITE(numout,*) ' kt =',kt
+      ENDIF
+
+      !! AXY (04/11/13): replace this with a call in trc_ini_medusa
+      !! AXY (25/02/10)
+      !! call routine for populating CCD array if this is the first time-step
+      !! IF( kt == nittrc000 ) CALL medusa_ccd( kt )
+
+      !! AXY (04/11/13): replace this with a call in trc_ini_medusa
+      !! AXY (26/01/12)
+      !! call routine for populating river arrays if this is the first time-step
+      !! IF( kt == nittrc000 ) CALL medusa_river( kt )
+
+      !! AXY (10/02/09)
+      IF( (jnt == 1) .and. (bdustfer) )  CALL trc_sed_medusa_sbc( kt )
+      !!
+      zirondep(:,:,:) = 0.e0     !! Initialisation of deposition variables
+      zsidep  (:,:)   = 0.e0
+      !!
+      !! Iron and Si deposition at the surface
+      !! -------------------------------------
+      !!
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zirondep(ji,jj,1) = (dustsolub * dust(ji,jj) / (55.85 * rmtss) + 3.e-10 / ryyss) &
+            & * rfact2 / fse3t(ji,jj,1)
+            zsidep  (ji,jj)   = 8.8 * 0.075 * dust(ji,jj) * rfact2 / &
+            & (fse3t(ji,jj,1) * 28.1 * rmtss)
+         END DO
+      END DO
+
+      ! sedimentation of detrital nitrogen : upstream scheme
+      ! ----------------------------------------------------
+      !
+      zwork(:,:,:) = 0.e0        ! initialisation of sinking variable
+      ! for detrital nitrogen sedimentation only - jpdet
+      zwork(:,:,1  ) = 0.e0      ! surface value set to zero
+      zwork(:,:,jpk) = 0.e0      ! bottom value  set to zero
+      !
+      ! tracer flux at w-point: we use -vsed (downward flux)  with simplification : no e1*e2
+      DO jk = 2, jpk
+         ! AXY (17/07/14): change "0.d0" to "0."
+         ! zwork(:,:,jk) = -vsed * max(trn(:,:,jk-1,jpdet),0.d0) * tmask(:,:,jk-1)
+         zwork(:,:,jk) = -vsed * max(trn(:,:,jk-1,jpdet),0.) * tmask(:,:,jk-1)
+         !
+         ! AXY (16/01/14): stop sinking in upper 10m to reduce model instability 
+         !                 in shallower grid cells
+         ! if ( jk .lt. 9 ) zwork(:,:,jk) = 0.e0
+      END DO
+      !
+      ! tracer flux divergence at t-point added to the general trend
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1,jpi
+               ztra  = - ( zwork(ji,jj,jk) - zwork(ji,jj,jk+1) ) / fse3t(ji,jj,jk)
+               tra(ji,jj,jk,jpdet) = tra(ji,jj,jk,jpdet) + ztra
+# if defined key_trc_diabio
+               trbio(ji,jj,jk,8) = ztra
+# endif
+               IF( ln_diatrc ) &
+                  &  trc2d(ji,jj,8) = trc2d(ji,jj,8) + ztra * fse3t(ji,jj,jk) * 86400.
+            END DO
+         END DO
+      END DO
+      !
+# if defined key_trc_diabio
+      CALL lbc_lnk (trbio(:,:,1,8), 'T', 1. )                    ! Lateral boundary conditions on trcbio
+# endif
+      IF( ln_diatrc ) CALL lbc_lnk( trc2d(:,:,8), 'T', 1. )      ! Lateral boundary conditions on trc2d
+# if defined key_iomput
+      CALL iom_put( "DSED",trc2d(:,:,8) )
+# endif
+
+# if defined key_roam
+
+      ! sedimentation of detrital carbon : upstream scheme
+      ! --------------------------------------------------
+      !
+      zwork(:,:,:) = 0.e0        ! initialisation of sinking variable
+      ! for detrital carbon sedimentation only - jpdtc
+      zwork(:,:,1  ) = 0.e0      ! surface value set to zero
+      zwork(:,:,jpk) = 0.e0      ! bottom value  set to zero
+      !
+      ! tracer flux at w-point: we use -vsed (downward flux)  with simplification : no e1*e2
+      DO jk = 2, jpk
+         ! AXY (17/07/14): change "0.d0" to "0."
+         ! zwork(:,:,jk) = -vsed * max(trn(:,:,jk-1,jpdtc),0.d0) * tmask(:,:,jk-1)
+         zwork(:,:,jk) = -vsed * max(trn(:,:,jk-1,jpdtc),0.) * tmask(:,:,jk-1)
+         !
+         ! AXY (16/01/14): stop sinking in upper 10m to reduce model instability 
+         !                 in shallower grid cells
+         ! if ( jk .lt. 9 ) zwork(:,:,jk) = 0.e0
+      END DO
+      !
+      ! tracer flux divergence at t-point added to the general trend
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1,jpi
+               ztra  = - ( zwork(ji,jj,jk) - zwork(ji,jj,jk+1) ) / fse3t(ji,jj,jk)
+               tra(ji,jj,jk,jpdtc) = tra(ji,jj,jk,jpdtc) + ztra
+!! #  if defined key_trc_diabio
+!!                trbio(ji,jj,jk,8) = ztra
+!! #  endif
+!!             IF( ln_diatrc ) &
+!!                &  trc2d(ji,jj,8) = trc2d(ji,jj,8) + ztra * fse3t(ji,jj,jk) * 86400.
+            END DO
+         END DO
+      END DO
+      !
+!! #  if defined key_trc_diabio
+!!       CALL lbc_lnk (trbio(:,:,1,8), 'T', 1. )                    ! Lateral boundary conditions on trcbio
+!! #  endif
+!!       IF( ln_diatrc ) CALL lbc_lnk( trc2d(:,:,8), 'T', 1. )      ! Lateral boundary conditions on trc2d
+!! #  if defined key_iomput
+!!       CALL iom_put( "DSED",trc2d(:,:,8) )
+!! #  endif
+
+# endif
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('sed')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+      ENDIF
+
+   END SUBROUTINE trc_sed_medusa
+
+   !! ======================================================================
+   !! ======================================================================
+   !! ======================================================================
+
+   !! AXY (10/02/09)
+   SUBROUTINE trc_sed_medusa_sbc(kt)
+
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_sed_medusa_sbc  ***
+      !!
+      !! ** Purpose :   Read and interpolate the external sources of 
+      !!                nutrients
+      !!
+      !! ** Method  :   Read the files and interpolate the appropriate variables
+      !!
+      !! ** input   :   external netcdf files
+      !!
+      !!----------------------------------------------------------------------
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !! * Local declarations
+      INTEGER ::   &
+         imois, imois2,       &  ! temporary integers
+         i15  , iman             !    "          "
+      REAL(wp) ::   &
+         zxy                     !    "         "
+
+      !!---------------------------------------------------------------------
+
+      !! Initialization
+      !! --------------
+      !!
+      i15 = nday / 16
+      iman  = INT( raamo )
+      imois = nmonth + i15 - 1
+      IF( imois == 0 ) imois = iman
+      imois2 = nmonth
+
+      !! 1. first call kt=nittrc000
+      !! -----------------------
+      !!
+      IF( kt == nittrc000 ) THEN
+         ! initializations
+         nflx1  = 0
+         nflx11 = 0
+         ! open the file
+         IF(lwp) THEN
+            WRITE(numout,*) ' '
+            WRITE(numout,*) ' **** Routine trc_sed_medusa_sbc'
+         ENDIF
+         CALL iom_open ( 'dust.orca.nc', numdust )
+	 IF(lwp) WRITE(numout,*) 'trc_sed_medusa_sbc: dust.orca.nc opened'
+      ENDIF
+
+      !! Read monthly file
+      !! ----------------
+      !!
+      IF( kt == nittrc000 .OR. imois /= nflx1 ) THEN
+
+         !! Calendar computation
+         !!
+         !! nflx1 number of the first file record used in the simulation
+         !! nflx2 number of the last  file record
+         !!
+         nflx1 = imois
+         nflx2 = nflx1+1
+         nflx1 = MOD( nflx1, iman )
+         nflx2 = MOD( nflx2, iman )
+         IF( nflx1 == 0 )   nflx1 = iman
+         IF( nflx2 == 0 )   nflx2 = iman
+         IF(lwp) WRITE(numout,*) 'trc_sed_medusa_sbc: first record file used nflx1 ',nflx1
+         IF(lwp) WRITE(numout,*) 'trc_sed_medusa_sbc: last  record file used nflx2 ',nflx2
+
+         !! Read monthly fluxes data
+         !!
+         !! humidity
+         !!
+         CALL iom_get ( numdust, jpdom_data, 'dust', dustmo(:,:,1), nflx1 )
+         CALL iom_get ( numdust, jpdom_data, 'dust', dustmo(:,:,2), nflx2 )
+
+         IF(lwp .AND. nitend-nit000 <= 100 ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) ' read clio flx ok'
+            WRITE(numout,*)
+            WRITE(numout,*)
+            WRITE(numout,*) 'Clio month: ',nflx1,'  field: dust'
+            CALL prihre( dustmo(:,:,1),jpi,jpj,1,jpi,20,1,jpj,10,1e9,numout )
+         ENDIF
+
+      ENDIF
+
+      !! 3. at every time step interpolation of fluxes
+      !! ---------------------------------------------
+      !!
+      zxy = FLOAT( nday + 15 - 30 * i15 ) / 30
+      dust(:,:) = ( (1.-zxy) * dustmo(:,:,1) + zxy * dustmo(:,:,2) )
+
+      IF( kt == nitend ) THEN
+         CALL iom_close (numdust)
+         IF(lwp) WRITE(numout,*) 'trc_sed_medusa_sbc: dust.orca.nc closed'
+      ENDIF
+
+   END SUBROUTINE trc_sed_medusa_sbc
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No MEDUSA bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE trc_sed_medusa( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'trc_sed_medusa: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_sed_medusa
+#endif 
+
+   !!======================================================================
+END MODULE  trcsed_medusa
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsms_medusa.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsms_medusa.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsms_medusa.F90	(revision 5707)
@@ -0,0 +1,80 @@
+MODULE trcsms_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcsms_medusa  ***
+   !! TOP :   Main module of the MEDUSA tracers
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) Original code
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!----------------------------------------------------------------------
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'                                       bio tracers
+   !!----------------------------------------------------------------------
+   !! trc_sms_medusa   : MEDUSA_TRC model main routine 
+   !!----------------------------------------------------------------------
+   USE par_trc         ! TOP parameters
+   USE oce_trc
+   USE trc
+   USE trcbio_medusa
+   USE trcopt_medusa
+   USE trcsed_medusa
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_sms_medusa   ! called by trcsms.F90 module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id: trcsms_medusa.F90 1162 2008-07-02 09:33:33Z cetlod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_sms_medusa( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_sms_medusa  ***  
+      !!
+      !! ** Purpose :   main routine of MEDUSA_TRC model
+      !!
+      !! ** Method  : - 
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) :: kt   ! ocean time-step index
+
+      IF( kt == nittrc000 ) THEN
+       IF(lwp) WRITE(numout,*)
+       IF(lwp) WRITE(numout,*) ' trc_sms_medusa:  MEDUSA model'
+       IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+      ENDIF
+
+      CALL trc_opt_medusa( kt )   ! optical model
+
+# if defined key_kill_medusa
+      !! MEDUSA skipped
+      IF(lwp) WRITE(numout,*) ' MEDUSA killed at kt =', kt
+      CALL flush(numout)
+# else
+      CALL trc_bio_medusa( kt )   ! biological model
+
+      CALL trc_sed_medusa( kt )   ! sedimentation model
+# endif
+
+   END SUBROUTINE trc_sms_medusa
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                        No MEDUSA model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_sms_medusa( kt )             ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'trc_sms_medusa: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_sms_medusa
+#endif
+
+   !!======================================================================
+END MODULE trcsms_medusa
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcwri_medusa.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcwri_medusa.F90	(revision 5707)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcwri_medusa.F90	(revision 5707)
@@ -0,0 +1,60 @@
+MODULE trcwri_medusa
+   !!======================================================================
+   !!                       *** MODULE trcwri ***
+   !!    MEDUSA :   Output of MEDUSA tracers
+   !!======================================================================
+   !! History :   1.0  !  2009-05 (C. Ethe)  Original code
+   !!             1.1  !  2013-05 (A. Yool)  converted for MEDUSA
+   !!----------------------------------------------------------------------
+#if defined key_top && defined key_iomput && defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'                                           MEDUSA model
+   !!----------------------------------------------------------------------
+   !! trc_wri_medusa   :  outputs of concentration fields
+   !!----------------------------------------------------------------------
+   USE trc         ! passive tracers common variables 
+   USE sms_medusa  ! MEDUSA variables
+   USE iom         ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_wri_medusa 
+
+CONTAINS
+
+   SUBROUTINE trc_wri_medusa
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_wri_trc  ***
+      !!
+      !! ** Purpose :   output passive tracers fields 
+      !!---------------------------------------------------------------------
+      CHARACTER (len=20)   :: cltra
+      INTEGER              :: jn
+      !!---------------------------------------------------------------------
+ 
+      ! write the tracer concentrations in the file
+      ! ---------------------------------------
+      DO jn = jp_msa0, jp_msa1
+         cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
+         CALL iom_put( cltra, trn(:,:,:,jn) )
+      END DO
+      !
+   END SUBROUTINE trc_wri_medusa
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+   PUBLIC trc_wri_medusa
+CONTAINS
+   SUBROUTINE trc_wri_medusa                     ! Empty routine  
+   END SUBROUTINE trc_wri_medusa
+#endif
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id: trcwri_medusa.F90 3160 2011-11-20 14:27:18Z cetlod $ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!======================================================================
+END MODULE trcwri_medusa
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/par_trc.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/par_trc.F90	(revision 5706)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/par_trc.F90	(revision 5707)
@@ -15,4 +15,6 @@
    USE par_cfc       ! CFC 11 and 12 tracers
    USE par_my_trc    ! user defined passive tracers
+   USE par_medusa    ! MEDUSA model
+   USE par_idtra     ! Idealize tracer
 
    IMPLICIT NONE
@@ -24,9 +26,9 @@
    ! Passive tracers : Total size
    ! ---------------               ! total number of passive tracers, of 2d and 3d output and trend arrays
-   INTEGER, PUBLIC,  PARAMETER ::   jptra    =  jp_pisces     + jp_cfc     + jp_c14b    + jp_my_trc
-   INTEGER, PUBLIC,  PARAMETER ::   jpdia2d  =  jp_pisces_2d  + jp_cfc_2d  + jp_c14b_2d + jp_my_trc_2d
-   INTEGER, PUBLIC,  PARAMETER ::   jpdia3d  =  jp_pisces_3d  + jp_cfc_3d  + jp_c14b_3d + jp_my_trc_3d
+   INTEGER, PUBLIC,  PARAMETER ::   jptra    =  jp_pisces     + jp_cfc     + jp_c14b    + jp_my_trc    + jp_medusa    + jp_idtra
+   INTEGER, PUBLIC,  PARAMETER ::   jpdia2d  =  jp_pisces_2d  + jp_cfc_2d  + jp_c14b_2d + jp_my_trc_2d + jp_medusa_2d + jp_idtra_2d
+   INTEGER, PUBLIC,  PARAMETER ::   jpdia3d  =  jp_pisces_3d  + jp_cfc_3d  + jp_c14b_3d + jp_my_trc_3d + jp_medusa_3d + jp_idtra_3d
    !                     ! total number of sms diagnostic arrays
-   INTEGER, PUBLIC,  PARAMETER ::   jpdiabio =  jp_pisces_trd + jp_cfc_trd + jp_c14b_trd + jp_my_trc_trd
+   INTEGER, PUBLIC,  PARAMETER ::   jpdiabio =  jp_pisces_trd + jp_cfc_trd + jp_c14b_trd + jp_my_trc_trd + jp_medusa_trd + jp_idtra_trd
    
    !  1D configuration ("key_c1d")
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcini.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 5706)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 5707)
@@ -8,4 +8,5 @@
    !!            2.0  ! 2005-10 (C. Ethe, G. Madec) revised architecture
    !!            4.0  ! 2011-01 (A. R. Porter, STFC Daresbury) dynamical allocation
+   !!             -   ! 2014-06 (A. Yool, J. Palmieri) adding MEDUSA-2
    !!----------------------------------------------------------------------
 #if defined key_top
@@ -24,4 +25,6 @@
    USE trcini_c14b     ! C14 bomb initialisation
    USE trcini_my_trc   ! MY_TRC   initialisation
+   USE trcini_medusa   ! MEDUSA   initialisation
+   USE trcini_idtra    ! idealize tracer initialisation
    USE trcdta          ! initialisation from files
    USE daymod          ! calendar manager
@@ -31,4 +34,6 @@
    USE lib_mpp         ! distribued memory computing library
    USE sbc_oce
+   USE lib_fortran     ! glob_sum
+
  
    IMPLICIT NONE
@@ -61,4 +66,10 @@
       CHARACTER (len=25) :: charout
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrcdta   ! 4D  workspace
+# if defined key_debug_medusa
+      !!INTEGER  ::  globmask                             ! glob_sum tests for debug
+      REAL(wp) ::  globtr, globvl, globtrvol, globmask  ! glob_sum tests for debug 
+# endif
+
+
       !!---------------------------------------------------------------------
       !
@@ -75,4 +86,7 @@
 #endif
 
+    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+    !!!!! CHECK For MEDUSA
+    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       IF( ltrcdm2dc )CALL ctl_warn( ' Diurnal cycle on physics but not in PISCES or LOBSTER ' )
 
@@ -100,4 +114,16 @@
       IF( lk_c14b    )       CALL trc_ini_c14b         ! C14 bomb  tracer
       IF( lk_my_trc  )       CALL trc_ini_my_trc       ! MY_TRC  tracers
+      IF( lk_medusa  )       CALL trc_ini_medusa       ! MEDUSA  tracers
+      IF( lk_idtra   )       CALL trc_ini_idtra        ! Idealize tracers
+
+# if defined key_debug_medusa
+         IF (lwp) write (numout,*) '------------------------------'
+         IF (lwp) write (numout,*) 'Jpalm - debug'
+         IF (lwp) write (numout,*) ' in trc_init'
+         IF (lwp) write (numout,*) ' sms init OK'
+         IF (lwp) write (numout,*) ' next: open tracer.stat'
+         IF (lwp) write (numout,*) ' '
+         CALL flush(numout)
+# endif
 
       IF( lwp ) THEN
@@ -107,9 +133,28 @@
       ENDIF
 
-      IF( ln_trcdta )      CALL trc_dta_init(jptra)
-
+# if defined key_debug_medusa
+         IF (lwp) write (numout,*) '------------------------------'
+         IF (lwp) write (numout,*) 'Jpalm - debug'
+         IF (lwp) write (numout,*) ' in trc_init'
+         IF (lwp) write (numout,*) 'open tracer.stat -- OK'
+         IF (lwp) write (numout,*) ' '
+         CALL flush(numout)
+# endif
+
+
+      IF( ln_trcdta ) THEN
+#if defined key_medusa
+         IF(lwp) WRITE(numout,*) 'AXY: calling trc_dta_init'
+         IF(lwp) CALL flush(numout)
+#endif
+         CALL trc_dta_init(jptra)
+      ENDIF
 
       IF( ln_rsttr ) THEN
         !
+#if defined key_medusa
+        IF(lwp) WRITE(numout,*) 'AXY: calling trc_rst_read'
+        IF(lwp) CALL flush(numout)
+#endif
         CALL trc_rst_read              ! restart from a file
         !
@@ -118,6 +163,14 @@
         IF( ln_trcdta .AND. nb_trcdta > 0 ) THEN  ! Initialisation of tracer from a file that may also be used for damping
             !
+#if defined key_medusa
+            IF(lwp) WRITE(numout,*) 'AXY: calling wrk_alloc'
+            IF(lwp) CALL flush(numout)
+#endif
             CALL wrk_alloc( jpi, jpj, jpk, ztrcdta )    ! Memory allocation
             !
+#if defined key_medusa
+            IF(lwp) WRITE(numout,*) 'AXY: calling trc_dta'
+            IF(lwp) CALL flush(numout)
+#endif
             DO jn = 1, jptra
                IF( ln_trc_ini(jn) ) THEN      ! update passive tracers arrays with input data read from file
@@ -126,5 +179,5 @@
                   ztrcdta(:,:,:) = sf_trcdta(jl)%fnow(:,:,:)
                   trn(:,:,:,jn) = ztrcdta(:,:,:) * tmask(:,:,:)  
-                  IF( .NOT.ln_trcdmp .AND. .NOT.ln_trcdmp_clo ) THEN      !== deallocate data structure   ==!
+                  IF( .NOT.ln_trcdmp .AND. .NOT. ln_trcdmp_clo ) THEN      !== deallocate data structure   ==!
                      !                                                    (data used only for initialisation)
                      IF(lwp) WRITE(numout,*) 'trc_dta: deallocate data arrays as they are only used to initialize the run'
@@ -135,8 +188,30 @@
                ENDIF
             ENDDO
+#if defined key_medusa
+            IF(lwp) WRITE(numout,*) 'AXY: calling wrk_dealloc'
+            IF(lwp) CALL flush(numout)
+#endif
             CALL wrk_dealloc( jpi, jpj, jpk, ztrcdta )
         ENDIF
         !
+# if defined key_debug_medusa
+         IF (lwp) write (numout,*) '------------------------------'
+         IF (lwp) write (numout,*) 'Jpalm - debug'
+         IF (lwp) write (numout,*) ' in trc_init'
+         IF (lwp) write (numout,*) ' before trb = trn'
+         IF (lwp) write (numout,*) ' '
+         CALL flush(numout)
+# endif
+        !
         trb(:,:,:,:) = trn(:,:,:,:)
+        ! 
+# if defined key_debug_medusa
+         IF (lwp) write (numout,*) '------------------------------'
+         IF (lwp) write (numout,*) 'Jpalm - debug'
+         IF (lwp) write (numout,*) ' in trc_init'
+         IF (lwp) write (numout,*) ' trb = trn -- OK'
+         IF (lwp) write (numout,*) ' '
+         CALL flush(numout)
+# endif
         ! 
       ENDIF
@@ -145,11 +220,52 @@
       IF( ln_zps .AND. .NOT. lk_c1d )   &              ! Partial steps: before horizontal gradient of passive
         &    CALL zps_hde( nit000, jptra, trn, pgtu=gtru, pgtv=gtrv, sgtu=gtrui, sgtv=gtrvi )       ! tracers at the bottom ocean level
-
+      !
+# if defined key_debug_medusa
+         IF (lwp) write (numout,*) '------------------------------'
+         IF (lwp) write (numout,*) 'Jpalm - debug'
+         IF (lwp) write (numout,*) ' in trc_init'
+         IF (lwp) write (numout,*) ' partial step -- OK'
+         IF (lwp) write (numout,*) ' '
+         CALL flush(numout)
+# endif
       !
       IF( nn_dttrc /= 1 )        CALL trc_sub_ini      ! Initialize variables for substepping passive tracers
       !
-
+# if defined key_debug_medusa
+         IF (lwp) write (numout,*) '------------------------------'
+         IF (lwp) write (numout,*) 'Jpalm - debug'
+         IF (lwp) write (numout,*) ' in trc_init'
+         IF (lwp) write (numout,*) ' before initiate tracer contents'
+         IF (lwp) write (numout,*) ' '
+         CALL flush(numout)
+# endif
+      !
+# if defined key_debug_medusa
+         write (*,*) narea,' TRCINI ','Jpalm - debug'
+         write (*,*) narea,' TRCINI ','LN_CTL = TRUE '
+         write (*,*) narea,' TRCINI ','---------------------------------'
+      CALL flush(numout)
+      globmask  = glob_sum( tmask(:,:,:))
+      IF (lwp) write (numout,*) 'glob_sum test, sum tmask : ',globmask  
+# endif
+      !
       trai(:) = 0._wp                                                   ! initial content of all tracers
       DO jn = 1, jptra
+# if defined key_debug_medusa
+         globtr    = glob_sum( trn(:,:,:,jn))
+         globvl    = glob_sum( cvol(:,:,:))
+         globtrvol = glob_sum( trn(:,:,:,jn) * cvol(:,:,:)) 
+         !
+         IF (lwp) write (numout,*) 'var number : ',jn
+         CALL flush(numout)
+         IF (lwp) write (numout,*) 'trai(jn) before - should be 0 - ',trai(jn)
+         CALL flush(numout)
+         IF (lwp) write (numout,*) 'global Ocean volume  :          ',globvl
+         CALL flush(numout)
+         IF (lwp) write (numout,*) 'global sum of tracer :          ',globtr
+         CALL flush(numout)
+         IF (lwp) write (numout,*) 'global weighted tracer  :       ',globtrvol
+         CALL flush(numout)
+# endif
          trai(jn) = trai(jn) + glob_sum( trn(:,:,:,jn) * cvol(:,:,:)   )
       END DO
@@ -162,4 +278,12 @@
          WRITE(numout,*) '          *** Total inital content of all tracers '
          WRITE(numout,*)
+# if defined key_debug_medusa
+         CALL flush(numout)
+# endif
+         !
+# if defined key_debug_medusa
+         WRITE(numout,*) ' litle check :  ', ctrcnm(1)
+         CALL flush(numout)
+# endif
          DO jn = 1, jptra
             WRITE(numout,9000) jn, TRIM( ctrcnm(jn) ), trai(jn)
@@ -174,4 +298,10 @@
          CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
       ENDIF
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'trc_init : passive tracer set up completed'
+      IF(lwp) WRITE(numout,*) '~~~~~~~'
+      IF(lwp) CALL flush(numout)
+
 9000  FORMAT(' tracer nb : ',i2,'      name :',a10,'      initial content :',e18.10)
       !
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcnam.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcnam.F90	(revision 5706)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcnam.F90	(revision 5707)
@@ -25,4 +25,6 @@
    USE trcnam_c14b       ! C14 SMS namelist
    USE trcnam_my_trc     ! MY_TRC SMS namelist
+   USE trcnam_medusa     ! MEDUSA namelist
+   USE trcnam_idtra      ! Idealise tracer namelist
    USE trd_oce       
    USE trdtrc_oce
@@ -56,16 +58,54 @@
       !!                ( (PISCES, CFC, MY_TRC )
       !!---------------------------------------------------------------------
-      INTEGER  ::   jn                  ! dummy loop indice
+      INTEGER  ::   jn, jk                     ! dummy loop indice
       !                                        !   Parameters of the run 
       IF( .NOT. lk_offline ) CALL trc_nam_run
       
       !                                        !  passive tracer informations
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_trc'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
       CALL trc_nam_trc
       
       !                                        !   Parameters of additional diagnostics
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_trc -- OK'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_dia'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
+
       CALL trc_nam_dia
 
       !                                        !   namelist of transport
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_dia -- OK'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_trp'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
       CALL trc_nam_trp
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_trp -- OK'
+      IF (lwp) write (numout,*) 'continue trc_nam '
+      IF (lwp) write (numout,*) ' '
+      CALL flush(numout)
+# endif
+      !
 
 
@@ -89,4 +129,7 @@
          END DO
          WRITE(numout,*) ' '
+# if defined key_debug_medusa
+      CALL flush(numout)
+# endif
       ENDIF
 
@@ -107,6 +150,15 @@
             WRITE(numout,*)
          ENDIF
-      ENDIF
-
+# if defined key_debug_medusa
+      CALL flush(numout)
+# endif
+      ENDIF
+
+# if defined key_debug_medusa
+       DO jk = 1, jpk
+          WRITE(numout,*) '  level number: ', jk, 'rdttrc: ',rdttrc(jk),'rdttra: ', rdttra(jk),'nn_dttrc: ', nn_dttrc
+       END DO
+      CALL flush(numout)
+# endif
       
       rdttrc(:) = rdttra(:) * FLOAT( nn_dttrc )   ! vertical profile of passive tracer time-step
@@ -116,4 +168,7 @@
         WRITE(numout,*) '    Passive Tracer  time step    rdttrc  = ', rdttrc(1)
         WRITE(numout,*) 
+# if defined key_debug_medusa
+      CALL flush(numout)
+# endif
       ENDIF
 
@@ -143,7 +198,17 @@
                IF( ln_trdtrc(jn) ) WRITE(numout,*) '    compute ML trends for tracer number :', jn
             END DO
+         WRITE(numout,*) ' '
+         CALL flush(numout)
          ENDIF
 #endif
 
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'Will now read SMS namelists : '
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
 
       ! namelist of SMS
@@ -152,9 +217,53 @@
       ELSE                    ;   IF(lwp) WRITE(numout,*) '          PISCES not used'
       ENDIF
-
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_pisces -- OK'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_medusa'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
+      IF( lk_medusa  ) THEN   ;   CALL trc_nam_medusa      ! MEDUSA  tracers
+      ELSE                    ;   IF(lwp) WRITE(numout,*) '          MEDUSA not used'
+      ENDIF
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_medusa -- OK'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_idtra'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
+      IF( lk_idtra   ) THEN   ;   CALL trc_nam_idtra       ! Idealize tracers
+      ELSE                    ;   IF(lwp) WRITE(numout,*) '          Idealize tracers not used'
+      ENDIF
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_idtra -- OK'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_cfc'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
       IF( lk_cfc     ) THEN   ;   CALL trc_nam_cfc         ! CFC     tracers
       ELSE                    ;   IF(lwp) WRITE(numout,*) '          CFC not used'
       ENDIF
-
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_cfc -- OK'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_c14b'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
       IF( lk_c14b     ) THEN   ;   CALL trc_nam_c14b         ! C14 bomb     tracers
       ELSE                    ;   IF(lwp) WRITE(numout,*) '          C14 not used'
@@ -165,4 +274,5 @@
       ENDIF
       !
+      IF(lwp)   CALL flush(numout)
    END SUBROUTINE trc_nam
 
@@ -211,4 +321,5 @@
          WRITE(numout,*) '   Use euler integration for TRC (y/n)          ln_top_euler  = ', ln_top_euler
          WRITE(numout,*) ' '
+        CALL flush(numout)
       ENDIF
       !
@@ -251,5 +362,6 @@
          ln_trc_wri(jn) =       sn_tracer(jn)%llsave
       END DO
-      
+      IF(lwp)  CALL flush(numout)      
+
     END SUBROUTINE trc_nam_trc
 
@@ -302,7 +414,16 @@
          WRITE(numout,*) '    frequency of outputs for biological trends  nn_writebio = ', nn_writebio
          WRITE(numout,*) ' '
-      ENDIF
-
-      IF( ln_diatrc .AND. .NOT. lk_iomput ) THEN 
+         CALL flush(numout)
+      ENDIF
+!!
+!! JPALM -- 17-07-2015 --
+!! MEDUSA is not yet up-to-date with the iom server.
+!! we use it for the main tracer, but not fully with diagnostics.
+!! will have to adapt it properly when visiting Christian Ethee
+!! for now, we change 
+!! IF( ln_diatrc .AND. .NOT. lk_iomput ) THEN
+!! to :
+!!
+      IF( ( ln_diatrc .AND. .NOT. lk_iomput ) .OR. ( ln_diatrc .AND. lk_medusa ) ) THEN 
          ALLOCATE( trc2d(jpi,jpj,jpdia2d), trc3d(jpi,jpj,jpk,jpdia3d),  &
            &       ctrc2d(jpdia2d), ctrc2l(jpdia2d), ctrc2u(jpdia2d) ,  & 
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcrst.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 5706)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 5707)
@@ -28,4 +28,8 @@
    USE iom
    USE daymod
+   !! AXY (05/11/13): need these for MEDUSA to input/output benthic reservoirs
+   USE sms_medusa
+   USE trcsms_medusa
+   !!
    IMPLICIT NONE
    PRIVATE
@@ -88,9 +92,11 @@
    SUBROUTINE trc_rst_read
       !!----------------------------------------------------------------------
-      !!                    ***  trc_rst_opn  ***
+      !!                    ***  trc_read_opn  ***
       !!
       !! ** purpose  :   read passive tracer fields in restart files
       !!----------------------------------------------------------------------
       INTEGER  ::  jn     
+      !! AXY (05/11/13): temporary variables
+      REAL(wp) ::    fq0,fq1,fq2
 
       !!----------------------------------------------------------------------
@@ -108,4 +114,75 @@
          CALL iom_get( numrtr, jpdom_autoglo, 'TRB'//ctrcnm(jn), trb(:,:,:,jn) )
       END DO
+
+      !! AXY (09/06/14): the ARCHER version of MEDUSA-2 does not include an equivalent
+      !!                 call to MEDUSA-2 at this point; this suggests that the FCM
+      !!                 version of NEMO date significantly earlier than the current
+      !!                 version
+
+#if defined key_medusa
+      !! AXY (13/01/12): check if the restart contains sediment fields;
+      !!                 this is only relevant for simulations that include
+      !!                 biogeochemistry and are restarted from earlier runs
+      !!                 in which there was no sediment component
+      !!
+      IF( iom_varid( numrtr, 'B_SED_N', ldstop = .FALSE. ) > 0 ) THEN
+         !! YES; in which case read them
+         !!
+         IF(lwp) WRITE(numout,*) ' MEDUSA sediment fields present - reading in ...'
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_SED_N',  zb_sed_n(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_SED_N',  zn_sed_n(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_SED_FE', zb_sed_fe(:,:) )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_SED_FE', zn_sed_fe(:,:) )
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_SED_SI', zb_sed_si(:,:) )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_SED_SI', zn_sed_si(:,:) )
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_SED_C',  zb_sed_c(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_SED_C',  zn_sed_c(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_SED_CA', zb_sed_ca(:,:) )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_SED_CA', zn_sed_ca(:,:) )
+      ELSE
+         !! NO; in which case set them to zero
+         !!
+         IF(lwp) WRITE(numout,*) ' MEDUSA sediment fields absent - setting to zero ...'
+         zb_sed_n(:,:)  = 0.0   !! organic N
+         zn_sed_n(:,:)  = 0.0
+         zb_sed_fe(:,:) = 0.0   !! organic Fe
+         zn_sed_fe(:,:) = 0.0
+         zb_sed_si(:,:) = 0.0   !! inorganic Si
+         zn_sed_si(:,:) = 0.0
+         zb_sed_c(:,:)  = 0.0   !! organic C
+         zn_sed_c(:,:)  = 0.0
+         zb_sed_ca(:,:) = 0.0   !! inorganic C
+         zn_sed_ca(:,:) = 0.0
+      ENDIF
+      !!
+      !! calculate stats on these fields
+      IF(lwp) WRITE(numout,*) ' MEDUSA sediment field stats (min, max, sum) ...'
+      fq0 = MINVAL(zn_sed_n(:,:))
+      fq1 = MAXVAL(zn_sed_n(:,:))
+      fq2 = SUM(zn_sed_n(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment  N ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_fe(:,:))
+      fq1 = MAXVAL(zn_sed_fe(:,:))
+      fq2 = SUM(zn_sed_fe(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment Fe ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_si(:,:))
+      fq1 = MAXVAL(zn_sed_si(:,:))
+      fq2 = SUM(zn_sed_si(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment Si ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_c(:,:))
+      fq1 = MAXVAL(zn_sed_c(:,:))
+      fq2 = SUM(zn_sed_c(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment  C ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_ca(:,:))
+      fq1 = MAXVAL(zn_sed_ca(:,:))
+      fq2 = SUM(zn_sed_ca(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment Ca ', &
+         &        fq0, fq1, fq2
+#endif
+ 
       !
    END SUBROUTINE trc_rst_read
@@ -121,4 +198,6 @@
       INTEGER  :: jn
       REAL(wp) :: zarak0
+      !! AXY (05/11/13): temporary variables
+      REAL(wp) ::    fq0,fq1,fq2
       !!----------------------------------------------------------------------
       !
@@ -133,4 +212,58 @@
          CALL iom_rstput( kt, nitrst, numrtw, 'TRB'//ctrcnm(jn), trb(:,:,:,jn) )
       END DO
+
+      !! AXY (09/06/14): the ARCHER version of MEDUSA-2 does not include an equivalent
+      !!                 call to MEDUSA-2 at this point; this suggests that the FCM
+      !!                 version of NEMO date significantly earlier than the current
+      !!                 version
+
+#if defined key_medusa
+      !! AXY (13/01/12): write out "before" and "now" state of seafloor
+      !!                 sediment pools into restart; this happens
+      !!                 whether or not the pools are to be used by
+      !!                 MEDUSA (which is controlled by a switch in the
+      !!                 namelist_top file)
+      !!
+      IF(lwp) WRITE(numout,*) ' MEDUSA sediment fields - writing out ...'
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_SED_N',  zb_sed_n(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_SED_N',  zn_sed_n(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_SED_FE', zb_sed_fe(:,:) )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_SED_FE', zn_sed_fe(:,:) )
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_SED_SI', zb_sed_si(:,:) )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_SED_SI', zn_sed_si(:,:) )
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_SED_C',  zb_sed_c(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_SED_C',  zn_sed_c(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_SED_CA', zb_sed_ca(:,:) )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_SED_CA', zn_sed_ca(:,:) )
+      !!
+      !! calculate stats on these fields
+      IF(lwp) WRITE(numout,*) ' MEDUSA sediment field stats (min, max, sum) ...'
+      fq0 = MINVAL(zn_sed_n(:,:))
+      fq1 = MAXVAL(zn_sed_n(:,:))
+      fq2 = SUM(zn_sed_n(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment  N ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_fe(:,:))
+      fq1 = MAXVAL(zn_sed_fe(:,:))
+      fq2 = SUM(zn_sed_fe(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment Fe ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_si(:,:))
+      fq1 = MAXVAL(zn_sed_si(:,:))
+      fq2 = SUM(zn_sed_si(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment Si ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_c(:,:))
+      fq1 = MAXVAL(zn_sed_c(:,:))
+      fq2 = SUM(zn_sed_c(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment  C ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_ca(:,:))
+      fq1 = MAXVAL(zn_sed_ca(:,:))
+      fq2 = SUM(zn_sed_ca(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment Ca ', &
+         &        fq0, fq1, fq2
+#endif
+
       !
       IF( kt == nitrst ) THEN
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcsms.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcsms.F90	(revision 5706)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcsms.F90	(revision 5707)
@@ -16,4 +16,6 @@
    USE trc                !
    USE trcsms_pisces      ! PISCES biogeo-model
+   USE trcsms_medusa      ! MEDUSA tracers
+   USE trcsms_idtra       ! Idealize Tracer
    USE trcsms_cfc         ! CFC 11 & 12
    USE trcsms_c14b        ! C14b tracer 
@@ -49,4 +51,6 @@
       !
       IF( lk_pisces  )   CALL trc_sms_pisces ( kt )    ! main program of PISCES 
+      IF( lk_medusa  )   CALL trc_sms_medusa ( kt )    ! MEDUSA  tracers
+      IF( lk_idtra   )   CALL trc_sms_idtra  ( kt )    ! radioactive decay of Id. tracer
       IF( lk_cfc     )   CALL trc_sms_cfc    ( kt )    ! surface fluxes of CFC
       IF( lk_c14b    )   CALL trc_sms_c14b   ( kt )    ! surface fluxes of C14
Index: branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcstp.F90
===================================================================
--- branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcstp.F90	(revision 5706)
+++ branches/NERC/dev_r5107_NOC_MEDUSA/NEMOGCM/NEMO/TOP_SRC/trcstp.F90	(revision 5707)
@@ -88,4 +88,8 @@
          tra(:,:,:,:) = 0.e0
          !
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA trc_stp begins at kt =', kt
+         CALL flush(numout)
+# endif
                                    CALL trc_rst_opn  ( kt )       ! Open tracer restart file 
          IF( lrst_trc )            CALL trc_rst_cal  ( kt, 'WRITE' )   ! calendar
@@ -94,5 +98,13 @@
          ENDIF
                                    CALL trc_sms      ( kt )       ! tracers: sinks and sources
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA trc_stp SMS complete at kt =', kt
+         CALL flush(numout)
+# endif
                                    CALL trc_trp      ( kt )       ! transport of passive tracers
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA trc_stp transport complete at kt =', kt
+         CALL flush(numout)
+# endif
          IF( kt == nittrc000 ) THEN
             CALL iom_close( numrtr )       ! close input tracer restart file
@@ -103,4 +115,8 @@
          !
          IF( nn_dttrc /= 1   )     CALL trc_sub_reset( kt )       ! resetting physical variables when sub-stepping
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA trc_stp ends at kt =', kt
+         CALL flush(numout)
+# endif
          !
       ENDIF
