Index: branches/UKMO/dev_r5518_GO6_package_FOAMv14/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_update.F90
===================================================================
--- branches/UKMO/dev_r5518_GO6_package_FOAMv14/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_update.F90	(revision 9287)
+++ branches/UKMO/dev_r5518_GO6_package_FOAMv14/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_update.F90	(revision 10302)
@@ -6,4 +6,6 @@
    !! History :
    !!   -   ! 2017-04 (M. Stringer)        Code taken from trcbio_medusa.F90
+   !!   -   ! 2017-08 (A. Yool)            Amend slow-detritus bug
+   !!   -   ! 2017-08 (A. Yool)            Reformatting for clarity
    !!----------------------------------------------------------------------
 #if defined key_medusa
@@ -60,5 +62,8 @@
                                    fsil_cons, fsil_prod, fsdiss,             &
                                    ftempca, fthetad, fthetan,                &
+                                   fslowsink, fslowgain, fslowloss,          & ! AXY (22/08/17)
+                                   f_sbenin_n, f_sbenin_c,                   &
 # if defined key_roam
+                                   fslowsinkc, fslowgainc, fslowlossc,       & ! AXY (22/08/17)
                                    fcar_cons, fcar_prod, fcomm_resp,         &
                                    fddc, fflx_a, fflx_c, fflx_o2, zoxy,      &
@@ -66,9 +71,12 @@
 # endif
                                    zpds, zphd, zphn
-      USE dom_oce,           ONLY: e3t_0, e3t_n, gphit, mbathy, tmask
+      USE dom_oce,           ONLY: e3t_0, gphit, mbathy, tmask
+# if defined key_vvl
+      USE dom_oce,           ONLY: e3t_n
+# endif
       USE in_out_manager,    ONLY: lwp, numout
       USE lib_mpp,           ONLY: ctl_stop
       USE par_kind,          ONLY: wp
-      USE par_medusa,        ONLY: jp_medusa,                                &
+      USE par_medusa,        ONLY: jp_medusa, jp_msa0, jp_msa1,              &
                                    jpalk, jpchd, jpchn, jpdet, jpdic,        &
                                    jpdin, jpdtc, jpfer, jpoxy, jppds,        &
@@ -78,5 +86,5 @@
                                    jpoxy_lc, jppds_lc, jpphd_lc, jpphn_lc,   &
                                    jpsil_lc, jpzme_lc, jpzmi_lc
-      USE par_oce,           ONLY: jpi, jpim1, jpj, jpjm1
+      USE par_oce,           ONLY: jpi, jpim1, jpj, jpjm1, jpk
       USE par_trc,           ONLY: jptra
       USE sms_medusa,        ONLY: friver_dep,                               &
@@ -181,25 +189,21 @@
       ENDDO
 
-      DO jj = 2,jpjm1
-         DO ji = 2,jpim1
-            if (tmask(ji,jj,jk) == 1) then
-               !!
-               !!----------------------------------------------------------
-               !! detritus
-               btra(ji,jj,jpdet_lc) = b0 *                                      &
-                                          ! mort. losses 
-                                   (fdpn(ji,jj) + ((1.0 - xfdfrac1) *        &
-                                                   fdpd(ji,jj)) +            &
-                                    fdzmi(ji,jj) +                           &
-                                    ((1.0 - xfdfrac2) * fdzme(ji,jj)) +      &
-                                          ! assim. inefficiency
-                                    ((1.0 - xbetan) * (finmi(ji,jj) +        &
-                                                       finme(ji,jj))) -      &
-                                          ! grazing and remin.
-                                    fgmid(ji,jj) - fgmed(ji,jj) -            &
-                                    fdd(ji,jj) +                             &
-                                          ! seafloor fast->slow
-                                    ffast2slown(ji,jj))
-               !!
+      !!----------------------------------------------------------
+      !! detritus
+      DO jj = 2,jpjm1
+         DO ji = 2,jpim1
+            if (tmask(ji,jj,jk) == 1) then
+               !!
+               btra(ji,jj,jpdet_lc) = b0 * (                           &
+                   fdpn(ji,jj)                                         & ! mort. losses 
+                 + ((1.0 - xfdfrac1) * fdpd(ji,jj))                    & ! mort. losses 
+                 + fdzmi(ji,jj)                                        & ! mort. losses
+                 + ((1.0 - xfdfrac2) * fdzme(ji,jj))                   & ! mort. losses
+                 + ((1.0 - xbetan) * (finmi(ji,jj) + finme(ji,jj)))    & ! assim. inefficiency
+                 - fgmid(ji,jj) - fgmed(ji,jj)                         & ! grazing
+                 - fdd(ji,jj)                                          & ! remin.
+                 + fslowgain(ji,jj) - fslowloss(ji,jj)                 & ! slow-sinking
+                 - (f_sbenin_n(ji,jj) / fse3t(ji,jj,jk))               & ! slow-sinking loss to seafloor
+                 + ffast2slown(ji,jj) )                                  ! seafloor fast->slow 
             ENDIF
          ENDDO
@@ -266,5 +270,5 @@
                              ! mort. loss
                          ((1.0 - xfdfrac1) * fdpds(ji,jj)) +                 &
-                             &  ! egestion of grazed Si
+                             ! egestion of grazed Si
                          ((1.0 - xfdfrac3) * fgmepds(ji,jj)) +               &
                              ! fast diss. and metab. losses
@@ -305,24 +309,26 @@
                                           ffetop(ji,jj) + ffebot(ji,jj) -    &
                                           ffescav(ji,jj) )
+            ENDIF
+         ENDDO
+      ENDDO
+
 # if defined key_roam
-               !!
-               !!----------------------------------------------------------
-               !! AXY (26/11/08): implicit detrital carbon change
-               btra(ji,jj,jpdtc_lc) = b0 * (                                    &
-                                            ! mort. losses
-                                         (xthetapn * fdpn(ji,jj)) +          &
-                                         ((1.0 - xfdfrac1) *                 &
-                                          (xthetapd * fdpd(ji,jj))) +        &
-                                         (xthetazmi * fdzmi(ji,jj)) +        &
-                                         ((1.0 - xfdfrac2) *                 &
-                                          (xthetazme * fdzme(ji,jj))) +      &
-                                             ! assim. inefficiency
-                                         ((1.0 - xbetac) *                   &
-                                          (ficmi(ji,jj) + ficme(ji,jj))) -   &
-                                             ! grazing and remin.
-                                         fgmidc(ji,jj) - fgmedc(ji,jj) -     &
-                                         fddc(ji,jj) +                       &
-                                             ! seafloor fast->slow
-                                         ffast2slowc(ji,jj) )
+      !!----------------------------------------------------------
+      !! AXY (26/11/08): implicit detrital carbon change
+      DO jj = 2,jpjm1
+         DO ji = 2,jpim1
+            if (tmask(ji,jj,jk) == 1) then 
+               !!
+               btra(ji,jj,jpdtc_lc) = b0 * (                           &
+                   (xthetapn * fdpn(ji,jj))                            & ! mort. losses 
+                 + ((1.0 - xfdfrac1) * (xthetapd * fdpd(ji,jj)))       & ! mort. losses 
+                 + (xthetazmi * fdzmi(ji,jj))                          & ! mort. losses 
+                 + ((1.0 - xfdfrac2) * (xthetazme * fdzme(ji,jj)))     & ! mort. losses 
+                 + ((1.0 - xbetac) * (ficmi(ji,jj) + ficme(ji,jj)))    & ! assim. inefficiency
+                 - fgmidc(ji,jj) - fgmedc(ji,jj)                       & ! grazing
+                 - fddc(ji,jj)                                         & ! remin.
+                 + fslowgainc(ji,jj) - fslowlossc(ji,jj)               & ! slow-sinking
+                 - (f_sbenin_c(ji,jj) / fse3t(ji,jj,jk))               & ! slow-sinking loss to seafloor
+                 + ffast2slowc(ji,jj) )                                  ! seafloor fast->slow
             ENDIF
          ENDDO
@@ -575,8 +581,8 @@
                                                            f_o2flux(ji,jj))
                endif
+            ENDIF
+         ENDDO
+      ENDDO
 # endif
-            ENDIF
-         ENDDO
-      ENDDO
 
 # if defined key_debug_medusa
