Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/AGE/trcini_age.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/AGE/trcini_age.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/AGE/trcini_age.F90	(revision 13463)
@@ -25,5 +25,5 @@
 CONTAINS
 
-   SUBROUTINE trc_ini_age
+   SUBROUTINE trc_ini_age( Kmm )
       !!----------------------------------------------------------------------
       !!                     ***  trc_ini_age  ***  
@@ -32,4 +32,5 @@
       !!
       !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kmm ! time level indices
       INTEGER    ::  jn
       CHARACTER(len = 20)  ::  cltra
@@ -57,5 +58,5 @@
 
       
-      IF( .NOT. ln_rsttr ) trn(:,:,:,jp_age) = 0.
+      IF( .NOT. ln_rsttr ) tr(:,:,:,jp_age,Kmm) = 0.
       !
    END SUBROUTINE trc_ini_age
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/AGE/trcnam_age.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/AGE/trcnam_age.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/AGE/trcnam_age.F90	(revision 13463)
@@ -54,10 +54,8 @@
       ln_trc_obc(jp_age) = .false.
       !
-      REWIND( numnat_ref )              ! Namelist namagedate in reference namelist : AGE parameters
       READ  ( numnat_ref, namage, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namage in reference namelist', lwp )
-      REWIND( numnat_cfg )              ! Namelist namagedate in configuration namelist : AGE parameters
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namage in reference namelist' )
       READ  ( numnat_cfg, namage, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namage in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namage in configuration namelist' )
       IF(lwm) WRITE ( numont, namage )
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/AGE/trcsms_age.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/AGE/trcsms_age.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/AGE/trcsms_age.F90	(revision 13463)
@@ -37,5 +37,5 @@
 CONTAINS
 
-   SUBROUTINE trc_sms_age( kt )
+   SUBROUTINE trc_sms_age( kt, Kbb, Kmm, Krhs )
       !!----------------------------------------------------------------------
       !!                     ***  trc_sms_age  ***
@@ -45,5 +45,6 @@
       !! ** Method  : -
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      INTEGER, INTENT(in) ::   kt              ! ocean time-step index
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Krhs  ! ocean time level
       INTEGER ::   jn, jk   ! dummy loop index
       !!----------------------------------------------------------------------
@@ -57,15 +58,15 @@
 
       DO jk = 1, nla_age
-         tra(:,:,jk,jp_age) = rn_age_kill_rate * trb(:,:,jk,jp_age)
+         tr(:,:,jk,jp_age,Krhs) = rn_age_kill_rate * tr(:,:,jk,jp_age,Kbb)
       END DO
       !
-      tra(:,:,nl_age,jp_age) = frac_kill_age * rn_age_kill_rate * trb(:,:,nl_age,jp_age)  &
+      tr(:,:,nl_age,jp_age,Krhs) = frac_kill_age * rn_age_kill_rate * tr(:,:,nl_age,jp_age,Kbb)  &
           &                   + frac_add_age  * rryear * tmask(:,:,nl_age)
       !
       DO jk = nlb_age, jpk
-         tra(:,:,jk,jp_age) = tmask(:,:,jk) * rryear
+         tr(:,:,jk,jp_age,Krhs) = tmask(:,:,jk) * rryear
       END DO
       !
-      IF( l_trdtrc ) CALL trd_trc( tra(:,:,:,jp_age), jn, jptra_sms, kt )   ! save trends
+      IF( l_trdtrc ) CALL trd_trc( tr(:,:,:,jp_age,Krhs), jn, jptra_sms, kt, Kmm )   ! save trends
       !
       IF( ln_timing )   CALL timing_stop('trc_sms_age')
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/AGE/trcwri_age.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/AGE/trcwri_age.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/AGE/trcwri_age.F90	(revision 13463)
@@ -21,5 +21,5 @@
 CONTAINS
 
-   SUBROUTINE trc_wri_age
+   SUBROUTINE trc_wri_age( Kmm )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE trc_wri_trc  ***
@@ -27,4 +27,5 @@
       !! ** Purpose :   output passive tracers fields 
       !!---------------------------------------------------------------------
+      INTEGER, INTENT(in)  :: Kmm  ! time level indices
       CHARACTER (len=20)   :: cltra
       INTEGER              :: jn
@@ -34,5 +35,5 @@
 
       cltra = TRIM( ctrcnm(jp_age) )                  ! short title for tracer
-      CALL iom_put( cltra, trn(:,:,:,jp_age) )
+      CALL iom_put( cltra, tr(:,:,:,jp_age,Kmm) )
 
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcatm_c14.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcatm_c14.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcatm_c14.F90	(revision 13463)
@@ -21,4 +21,6 @@
    PUBLIC   trc_atm_c14_ini     ! called in trcini_c14.F90
    !
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -118,29 +120,27 @@
             IF( ierr3 /= 0 )   CALL ctl_stop( 'STOP', 'trc_atm_c14_ini: unable to allocate fareaz' )
       !
-            DO jj = 1 , jpj                       ! from C14b package
-              DO ji = 1 , jpi
-                 IF( gphit(ji,jj) >= yn40 ) THEN
-                    fareaz(ji,jj,1) = 0.
-                    fareaz(ji,jj,2) = 0.
-                    fareaz(ji,jj,3) = 1.
-                 ELSE IF( gphit(ji,jj ) <= ys40) THEN
-                    fareaz(ji,jj,1) = 1.
-                    fareaz(ji,jj,2) = 0.
-                    fareaz(ji,jj,3) = 0.
-                 ELSE IF( gphit(ji,jj) >= yn20 ) THEN
-                    fareaz(ji,jj,1) = 0.
-                    fareaz(ji,jj,2) = 2. * ( 1. - gphit(ji,jj) / yn40 )
-                    fareaz(ji,jj,3) = 2. * gphit(ji,jj) / yn40 - 1.
-                 ELSE IF( gphit(ji,jj) <= ys20 ) THEN
-                    fareaz(ji,jj,1) = 2. * gphit(ji,jj) / ys40 - 1.
-                    fareaz(ji,jj,2) = 2. * ( 1. - gphit(ji,jj) / ys40 )
-                    fareaz(ji,jj,3) = 0.
-                 ELSE
-                    fareaz(ji,jj,1) = 0.
-                    fareaz(ji,jj,2) = 1.
-                    fareaz(ji,jj,3) = 0.
-                 ENDIF
-              END DO
-           END DO
+            DO_2D( 1, 1, 1, 1 )
+              IF( gphit(ji,jj) >= yn40 ) THEN
+                 fareaz(ji,jj,1) = 0.
+                 fareaz(ji,jj,2) = 0.
+                 fareaz(ji,jj,3) = 1.
+              ELSE IF( gphit(ji,jj ) <= ys40) THEN
+                 fareaz(ji,jj,1) = 1.
+                 fareaz(ji,jj,2) = 0.
+                 fareaz(ji,jj,3) = 0.
+              ELSE IF( gphit(ji,jj) >= yn20 ) THEN
+                 fareaz(ji,jj,1) = 0.
+                 fareaz(ji,jj,2) = 2. * ( 1. - gphit(ji,jj) / yn40 )
+                 fareaz(ji,jj,3) = 2. * gphit(ji,jj) / yn40 - 1.
+              ELSE IF( gphit(ji,jj) <= ys20 ) THEN
+                 fareaz(ji,jj,1) = 2. * gphit(ji,jj) / ys40 - 1.
+                 fareaz(ji,jj,2) = 2. * ( 1. - gphit(ji,jj) / ys40 )
+                 fareaz(ji,jj,3) = 0.
+              ELSE
+                 fareaz(ji,jj,1) = 0.
+                 fareaz(ji,jj,2) = 1.
+                 fareaz(ji,jj,3) = 0.
+              ENDIF
+            END_2D
       !
          ENDIF
@@ -223,5 +223,5 @@
       IF(kc14typ >= 1) THEN  ! Transient C14 & CO2
       !
-         tyrc14_now = tyrc14_now + ( rdt / ( rday * nyear_len(1)) )    !  current time step in yr relative to tyrc14_beg
+         tyrc14_now = tyrc14_now + ( rn_Dt / ( rday * nyear_len(1)) )    !  current time step in yr relative to tyrc14_beg
       !
       ! CO2 --------------------------------------------------------
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcini_c14.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcini_c14.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcini_c14.F90	(revision 13463)
@@ -31,5 +31,5 @@
 CONTAINS
 
-   SUBROUTINE trc_ini_c14
+   SUBROUTINE trc_ini_c14( Kmm )
       !!----------------------------------------------------------------------
       !!                     ***  trc_ini_c14  ***  
@@ -40,4 +40,5 @@
       !!----------------------------------------------------------------------
       !
+      INTEGER, INTENT(in)  ::  Kmm  ! time level indices
       REAL(wp) :: ztrai
       INTEGER  :: jn
@@ -57,5 +58,5 @@
          IF(lwp) WRITE(numout,*) '                      ==>    Ocean C14/C :', rc14init 
          !
-         trn(:,:,:,jp_c14) = rc14init * tmask(:,:,:)
+         tr(:,:,:,jp_c14,Kmm) = rc14init * tmask(:,:,:)
          !
          qtr_c14(:,:) = 0._wp           ! Init of air-sea BC
@@ -68,8 +69,8 @@
         ! 
         CALL iom_get( numrtr, 'co2sbc', co2sbc ) 
-        CALL iom_get( numrtr, jpdom_autoglo, 'c14sbc', c14sbc ) 
-        CALL iom_get( numrtr, jpdom_autoglo, 'exch_co2', exch_co2 ) 
-        CALL iom_get( numrtr, jpdom_autoglo, 'exch_c14', exch_c14 ) 
-        CALL iom_get( numrtr, jpdom_autoglo, 'qtr_c14', qtr_c14 )
+        CALL iom_get( numrtr, jpdom_auto, 'c14sbc', c14sbc ) 
+        CALL iom_get( numrtr, jpdom_auto, 'exch_co2', exch_co2 ) 
+        CALL iom_get( numrtr, jpdom_auto, 'exch_c14', exch_c14 ) 
+        CALL iom_get( numrtr, jpdom_auto, 'qtr_c14', qtr_c14 )
         !
       END IF
@@ -84,5 +85,5 @@
       ELSE
         !
-        CALL iom_get( numrtr, jpdom_autoglo, 'qint_c14', qint_c14 ) 
+        CALL iom_get( numrtr, jpdom_auto, 'qint_c14', qint_c14 ) 
         !
       ENDIF
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcnam_c14.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcnam_c14.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcnam_c14.F90	(revision 13463)
@@ -61,10 +61,8 @@
       ln_trc_obc(jp_c14) = .false.
       !
-      REWIND( numtrc_ref )              ! Namelist namc14_typ in reference namelist :
       READ  ( numtrc_ref, namc14_typ, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc14_typ in reference namelist', lwp )
-      REWIND( numtrc_cfg )              ! Namelist namcfcdate in configuration namelist 
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc14_typ in reference namelist' )
       READ  ( numtrc_cfg, namc14_typ, IOSTAT = ios, ERR = 902)
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc14_typ in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc14_typ in configuration namelist' )
       IF(lwm) WRITE ( numonr, namc14_typ )
       !
@@ -78,10 +76,8 @@
       ENDIF
 
-      REWIND( numtrc_ref )              ! Namelist namc14_typ in reference namelist :
       READ  ( numtrc_ref, namc14_sbc, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc14_sbc in reference namelist', lwp )
-      REWIND( numtrc_cfg )              ! Namelist namcfcdate in configuration namelist 
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc14_sbc in reference namelist' )
       READ  ( numtrc_cfg, namc14_sbc, IOSTAT = ios, ERR = 904)
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc14_sbc in configuration namelist', lwp )
+904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc14_sbc in configuration namelist' )
       IF(lwm) WRITE( numonr, namc14_sbc )
       !
@@ -94,10 +90,8 @@
       ENDIF
 
-      REWIND( numtrc_ref )              ! Namelist namc14_typ in reference namelist :
       READ  ( numtrc_ref, namc14_fcg, IOSTAT = ios, ERR = 905)
-905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc14_fcg in reference namelist', lwp )
-      REWIND( numtrc_cfg )              ! Namelist namcfcdate in configuration namelist 
+905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namc14_fcg in reference namelist' )
       READ  ( numtrc_cfg, namc14_fcg, IOSTAT = ios, ERR = 906)
-906   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc14_fcg in configuration namelist', lwp )
+906   IF( ios >  0 )   CALL ctl_nam ( ios , 'namc14_fcg in configuration namelist' )
       IF(lwm) WRITE ( numonr, namc14_fcg )
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcsms_c14.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcsms_c14.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcsms_c14.F90	(revision 13463)
@@ -26,4 +26,7 @@
    PUBLIC   trc_sms_c14       ! called in trcsms.F90
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -33,5 +36,5 @@
 CONTAINS
 
-   SUBROUTINE trc_sms_c14( kt )
+   SUBROUTINE trc_sms_c14( kt, Kbb, Kmm, Krhs )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE trc_sms_c14  ***
@@ -46,11 +49,12 @@
       !            freshwater fluxes which should not impact the C14/C ratio
       !
-      !        =>   Delta-C14= ( trn(...jp_c14) -1)*1000.
+      !        =>   Delta-C14= ( tr(...jp_c14,Kmm) -1)*1000.
       !!
       !!----------------------------------------------------------------------
       !
-      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      INTEGER, INTENT(in) ::   kt               ! ocean time-step index
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Krhs   ! ocean time level
       !
-      INTEGER  :: ji, jj, jk         ! dummy loop indices 
+      INTEGER  :: ji, jj, jk        ! dummy loop indices 
       REAL(wp) :: zt, ztp, zsk      ! dummy variables
       REAL(wp) :: zsol              ! solubility
@@ -77,40 +81,38 @@
       ! -------------------------------------------------------------------
 
-      DO jj = 1, jpj
-         DO ji = 1, jpi  
-            IF( tmask(ji,jj,1) >  0. ) THEN
-               !
-               zt   = MIN( 40. , tsn(ji,jj,1,jp_tem) )
-               !
-               !  Computation of solubility zsol in [mol/(L * atm)]
-               !   after Wanninkhof (2014) referencing Weiss (1974)
-               ztp  = ( zt + 273.16 ) * 0.01
-               zsk  = 0.027766 + ztp * ( -0.025888 + 0.0050578 * ztp )   ! [mol/(L * atm)]
-               zsol = EXP( -58.0931 + 90.5069 / ztp  + 22.2940 * LOG( ztp ) + zsk * tsn(ji,jj,1,jp_sal) )
-               ! convert solubilities [mol/(L * atm)] -> [mol/(m^3 * ppm)]
-               zsol = zsol * 1.e-03
+      DO_2D( 1, 1, 1, 1 )
+         IF( tmask(ji,jj,1) >  0. ) THEN
+            !
+            zt   = MIN( 40. , ts(ji,jj,1,jp_tem,Kmm) )
+            !
+            !  Computation of solubility zsol in [mol/(L * atm)]
+            !   after Wanninkhof (2014) referencing Weiss (1974)
+            ztp  = ( zt + 273.16 ) * 0.01
+            zsk  = 0.027766 + ztp * ( -0.025888 + 0.0050578 * ztp )   ! [mol/(L * atm)]
+            zsol = EXP( -58.0931 + 90.5069 / ztp  + 22.2940 * LOG( ztp ) + zsk * ts(ji,jj,1,jp_sal,Kmm) )
+            ! convert solubilities [mol/(L * atm)] -> [mol/(m^3 * ppm)]
+            zsol = zsol * 1.e-03
 
-               ! Computes the Schmidt number of CO2 in seawater
-               !               Wanninkhof-2014
-               zsch = 2116.8 + zt * ( -136.25 + zt * (4.7353 + zt * (-0.092307 + 0.0007555 * zt ) ) )
+            ! Computes the Schmidt number of CO2 in seawater
+            !               Wanninkhof-2014
+            zsch = 2116.8 + zt * ( -136.25 + zt * (4.7353 + zt * (-0.092307 + 0.0007555 * zt ) ) )
 
-               ! Wanninkhof Piston velocity: zpv in units [m/s]
-               zv2 = xkwind * (wndm(ji,jj) * wndm(ji,jj))              ! wind speed module at T points
-               ! chemical enhancement (Wanninkhof & Knox, 1996)
-               IF( ln_chemh ) zv2 = zv2 + 2.5 * ( 0.5246 + zt * (0.016256 + 0.00049946  * zt ) )
-               zv2 = zv2/360000._wp                                    ! conversion cm/h -> m/s
-               !
-               zpv  = ( zv2 * SQRT( 660./ zsch ) ) * ( 1. - fr_i(ji,jj) ) * tmask(ji,jj,1)
+            ! Wanninkhof Piston velocity: zpv in units [m/s]
+            zv2 = xkwind * (wndm(ji,jj) * wndm(ji,jj))              ! wind speed module at T points
+            ! chemical enhancement (Wanninkhof & Knox, 1996)
+            IF( ln_chemh ) zv2 = zv2 + 2.5 * ( 0.5246 + zt * (0.016256 + 0.00049946  * zt ) )
+            zv2 = zv2/360000._wp                                    ! conversion cm/h -> m/s
+            !
+            zpv  = ( zv2 * SQRT( 660./ zsch ) ) * ( 1. - fr_i(ji,jj) ) * tmask(ji,jj,1)
 
-               ! CO2 piston velocity (m/s)
-               exch_co2(ji,jj)= zpv
-               ! CO2 invasion rate (mol/ppm/m2/s) = 1st part of 14C/C exchange velocity
-               exch_c14(ji,jj)= zpv * zsol
-            ELSE
-               exch_co2(ji,jj) = 0._wp
-               exch_c14(ji,jj) = 0._wp
-            ENDIF
-         END DO
-      END DO
+            ! CO2 piston velocity (m/s)
+            exch_co2(ji,jj)= zpv
+            ! CO2 invasion rate (mol/ppm/m2/s) = 1st part of 14C/C exchange velocity
+            exch_c14(ji,jj)= zpv * zsol
+         ELSE
+            exch_co2(ji,jj) = 0._wp
+            exch_c14(ji,jj) = 0._wp
+         ENDIF
+      END_2D
 
       ! Exchange velocity for 14C/C ratio (m/s)
@@ -120,26 +122,20 @@
       ! Flux of C-14 from air-to-sea; units: (C14/C ratio) x m/s
       !                               already masked
-      qtr_c14(:,:) = exch_c14(:,:) * ( c14sbc(:,:) - trb(:,:,1,jp_c14) )
+      qtr_c14(:,:) = exch_c14(:,:) * ( c14sbc(:,:) - tr(:,:,1,jp_c14,Kbb) )
             
       ! cumulation of air-to-sea flux at each time step
-      qint_c14(:,:) = qint_c14(:,:) + qtr_c14(:,:) * rdttrc
+      qint_c14(:,:) = qint_c14(:,:) + qtr_c14(:,:) * rn_Dt
       !
       ! Add the surface flux to the trend of jp_c14
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            tra(ji,jj,1,jp_c14) = tra(ji,jj,1,jp_c14) + qtr_c14(ji,jj) / e3t_n(ji,jj,1) 
-         END DO
-      END DO
+      DO_2D( 1, 1, 1, 1 )
+         tr(ji,jj,1,jp_c14,Krhs) = tr(ji,jj,1,jp_c14,Krhs) + qtr_c14(ji,jj) / e3t(ji,jj,1,Kmm) 
+      END_2D
       !
       ! Computation of decay effects on jp_c14
-      DO jk = 1, jpk
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               !
-               tra(ji,jj,jk,jp_c14) = tra(ji,jj,jk,jp_c14) - rlam14 * trb(ji,jj,jk,jp_c14) * tmask(ji,jj,jk) 
-               !
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpk )
+         !
+         tr(ji,jj,jk,jp_c14,Krhs) = tr(ji,jj,jk,jp_c14,Krhs) - rlam14 * tr(ji,jj,jk,jp_c14,Kbb) * tmask(ji,jj,jk) 
+         !
+      END_3D
       !
       IF( lrst_trc ) THEN
@@ -157,5 +153,5 @@
       ENDIF
 
-      IF( l_trdtrc )  CALL trd_trc( tra(:,:,:,jp_c14), 1, jptra_sms, kt )   ! save trends
+      IF( l_trdtrc )  CALL trd_trc( tr(:,:,:,jp_c14,Krhs), 1, jptra_sms, kt, Kmm )   ! save trends
       !
       IF( ln_timing )   CALL timing_stop('trc_sms_c14')
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcwri_c14.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcwri_c14.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/C14/trcwri_c14.F90	(revision 13463)
@@ -23,9 +23,11 @@
    !   Standard ratio: 1.176E-12 ; Avogadro's nbr = 6.022E+23 at/mol ; bomb C14 traditionally reported as 1.E+26 atoms
    REAL(wp), PARAMETER  :: atomc14 = 1.176 * 6.022E-15   ! conversion factor 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
 
 
 CONTAINS
 
-   SUBROUTINE trc_wri_c14
+   SUBROUTINE trc_wri_c14( Kmm )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE trc_wri_c14  ***
@@ -33,4 +35,5 @@
       !! ** Purpose :   output additional C14 tracers fields 
       !!---------------------------------------------------------------------
+      INTEGER, INTENT(in)  :: Kmm           ! time level indices
       CHARACTER (len=20)   :: cltra         ! short title for tracer
       INTEGER              :: ji,jj,jk,jn   ! dummy loop indexes
@@ -43,5 +46,5 @@
       ! ---------------------------------------
       cltra = TRIM( ctrcnm(jp_c14) )                  ! short title for tracer
-      CALL iom_put( cltra, trn(:,:,:,jp_c14) )
+      CALL iom_put( cltra, tr(:,:,:,jp_c14,Kmm) )
 
       ! compute and write the tracer diagnostic in the file
@@ -57,14 +60,10 @@
          zz3d(:,:,:) = 0._wp
          !
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  IF( tmask(ji,jj,jk) > 0._wp) THEN
-                     z3d (ji,jj,jk) = trn(ji,jj,jk,jp_c14)
-                     zz3d(ji,jj,jk) = LOG( z3d(ji,jj,jk) )
-                  ENDIF
-               ENDDO
-            ENDDO
-         ENDDO
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+            IF( tmask(ji,jj,jk) > 0._wp) THEN
+               z3d (ji,jj,jk) = tr(ji,jj,jk,jp_c14,Kmm)
+               zz3d(ji,jj,jk) = LOG( z3d(ji,jj,jk) )
+            ENDIF
+         END_3D
          zres(:,:) = z3d(:,:,1)
 
@@ -72,10 +71,8 @@
          z2d(:,:) =0._wp
          jk = 1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ztemp = zres(ji,jj) / c14sbc(ji,jj)
-               IF( ztemp > 0._wp .AND. tmask(ji,jj,jk) > 0._wp ) z2d(ji,jj) = LOG( ztemp )
-            ENDDO
-         ENDDO
+         DO_2D( 1, 1, 1, 1 )
+            ztemp = zres(ji,jj) / c14sbc(ji,jj)
+            IF( ztemp > 0._wp .AND. tmask(ji,jj,jk) > 0._wp ) z2d(ji,jj) = LOG( ztemp )
+         END_2D
          !
          z3d(:,:,:) = 1.d03 * ( z3d(:,:,:) - 1._wp )
@@ -113,5 +110,5 @@
       ENDIF
       IF( iom_use("C14Inv") ) THEN
-         ztemp = glob_sum( 'trcwri_c14', trn(:,:,:,jp_c14) * cvol(:,:,:) )
+         ztemp = glob_sum( 'trcwri_c14', tr(:,:,:,jp_c14,Kmm) * cvol(:,:,:) )
          ztemp = atomc14 * xdicsur * ztemp
          CALL iom_put( "C14Inv", ztemp )  !  Radiocarbon ocean inventory [10^26 atoms]
@@ -130,4 +127,6 @@
 #endif
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/CFC/trcini_cfc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/CFC/trcini_cfc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/CFC/trcini_cfc.F90	(revision 13463)
@@ -24,4 +24,6 @@
    REAL(wp) ::   ylatn =  10.           ! 10 degrees north
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -31,5 +33,5 @@
 CONTAINS
 
-   SUBROUTINE trc_ini_cfc
+   SUBROUTINE trc_ini_cfc( Kmm )
       !!----------------------------------------------------------------------
       !!                     ***  trc_ini_cfc  ***  
@@ -39,6 +41,7 @@
       !! ** Method  : - Read the namcfc namelist and check the parameter values
       !!----------------------------------------------------------------------
+      INTEGER, INTENT(in)  ::  Kmm  ! time level indices
       INTEGER  ::  ji, jj, jn, jl, jm, js, io, ierr
-      INTEGER  ::  iskip = 6   ! number of 1st descriptor lines
+      INTEGER  ::  iskip = 6        ! number of 1st descriptor lines
       REAL(wp) ::  zyy, zyd
       CHARACTER(len = 20)  ::  cltra
@@ -90,5 +93,5 @@
          DO jl = 1, jp_cfc
             jn = jp_cfc0 + jl - 1
-            trn(:,:,:,jn) = 0._wp
+            tr(:,:,:,jn,Kmm) = 0._wp
          END DO
       ENDIF
@@ -129,12 +132,10 @@
       !---------------------------------------------------------------------------------------
       zyd = ylatn - ylats      
-      DO jj = 1 , jpj
-         DO ji = 1 , jpi
-            IF(     gphit(ji,jj) >= ylatn ) THEN   ;   xphem(ji,jj) = 1.e0
-            ELSEIF( gphit(ji,jj) <= ylats ) THEN   ;   xphem(ji,jj) = 0.e0
-            ELSE                                   ;   xphem(ji,jj) = ( gphit(ji,jj) - ylats) / zyd
-            ENDIF
-         END DO
-      END DO
+      DO_2D( 1, 1, 1, 1 )
+         IF(     gphit(ji,jj) >= ylatn ) THEN   ;   xphem(ji,jj) = 1.e0
+         ELSEIF( gphit(ji,jj) <= ylats ) THEN   ;   xphem(ji,jj) = 0.e0
+         ELSE                                   ;   xphem(ji,jj) = ( gphit(ji,jj) - ylats) / zyd
+         ENDIF
+      END_2D
       !
       IF(lwp) WRITE(numout,*) 'Initialization of CFC tracers done'
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/CFC/trcnam_cfc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/CFC/trcnam_cfc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/CFC/trcnam_cfc.F90	(revision 13463)
@@ -51,10 +51,8 @@
       ENDIF
       !
-      REWIND( numtrc_ref )              ! Namelist namcfcdate in reference namelist : CFC parameters
       READ  ( numtrc_ref, namcfc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfc in reference namelist', lwp )
-      REWIND( numtrc_cfg )              ! Namelist namcfcdate in configuration namelist : CFC parameters
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfc in reference namelist' )
       READ  ( numtrc_cfg, namcfc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfc in configuration namelist' )
       IF(lwm) WRITE( numonr, namcfc )
       IF(lwm) CALL FLUSH ( numonr )     ! flush output namelist CFC
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/CFC/trcsms_cfc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/CFC/trcsms_cfc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/CFC/trcsms_cfc.F90	(revision 13463)
@@ -47,4 +47,7 @@
    REAL(wp) ::   xconv4 = 1.0e-12      ! conversion from mol/m3/atm to mol/m3/pptv 
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -54,5 +57,5 @@
 CONTAINS
 
-   SUBROUTINE trc_sms_cfc( kt )
+   SUBROUTINE trc_sms_cfc( kt, Kbb, Kmm, Krhs )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE trc_sms_cfc  ***
@@ -70,5 +73,6 @@
       !!                CFC concentration in pico-mol/m3
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      INTEGER, INTENT(in) ::   kt               ! ocean time-step index
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Krhs   ! ocean time level
       !
       INTEGER  ::   ji, jj, jn, jl, jm
@@ -105,4 +109,8 @@
          im2       =      nmonth - 7
       ENDIF
+      ! Avoid bad interpolation if starting date is =< 1900
+      IF( iyear_beg .LE. 0      )  iyear_beg = 1
+      IF( iyear_beg .GE. jpyear )  iyear_beg = jpyear - 1
+      !
       iyear_end = iyear_beg + 1
 
@@ -118,51 +126,48 @@
          
          !                                                         !------------!
-         DO jj = 1, jpj                                            !  i-j loop  !
-            DO ji = 1, jpi                                         !------------!
+         DO_2D( 1, 1, 1, 1 )
  
-               ! space interpolation
-               zpp_cfc  =       xphem(ji,jj)   * zpatm(1,jl)   &
-                  &     + ( 1.- xphem(ji,jj) ) * zpatm(2,jl)
-
-               ! Computation of concentration at equilibrium : in picomol/l
-               ! coefficient for solubility for CFC-11/12 in  mol/l/atm
-               IF( tmask(ji,jj,1) .GE. 0.5 ) THEN
-                  ztap  = ( tsn(ji,jj,1,jp_tem) + 273.16 ) * 0.01
-                  zdtap = sob(1,jl) + ztap * ( sob(2,jl) + ztap * sob(3,jl) ) 
-                  zsol  =  EXP( soa(1,jl) + soa(2,jl) / ztap + soa(3,jl) * LOG( ztap )   &
-                     &                    + soa(4,jl) * ztap * ztap + tsn(ji,jj,1,jp_sal) * zdtap ) 
-               ELSE
-                  zsol  = 0.e0
-               ENDIF
-               ! conversion from mol/l/atm to mol/m3/atm and from mol/m3/atm to mol/m3/pptv    
-               zsol = xconv4 * xconv3 * zsol * tmask(ji,jj,1)  
-               ! concentration at equilibrium
-               zca_cfc = xconv1 * zpp_cfc * zsol * tmask(ji,jj,1)             
-  
-               ! Computation of speed transfert
-               !    Schmidt number revised in Wanninkhof (2014)
-               zt1  = tsn(ji,jj,1,jp_tem)
-               zt2  = zt1 * zt1 
-               zt3  = zt1 * zt2
-               zt4  = zt2 * zt2
-               zsch = sca(1,jl) + sca(2,jl) * zt1 + sca(3,jl) * zt2 + sca(4,jl) * zt3 + sca(5,jl) * zt4
-
-               !    speed transfert : formulae revised in Wanninkhof (2014)
-               zv2     = wndm(ji,jj) * wndm(ji,jj)
-               zsch    = zsch / 660.
-               zak_cfc = ( 0.251 * xconv2 * zv2 / SQRT(zsch) ) * tmask(ji,jj,1)
-
-               ! Input function  : speed *( conc. at equil - concen at surface )
-               ! trn in pico-mol/l idem qtr; ak in en m/a
-               qtr_cfc(ji,jj,jl) = -zak_cfc * ( trb(ji,jj,1,jn) - zca_cfc )   &
-                  &                         * tmask(ji,jj,1) * ( 1. - fr_i(ji,jj) )
-               ! Add the surface flux to the trend
-               tra(ji,jj,1,jn) = tra(ji,jj,1,jn) + qtr_cfc(ji,jj,jl) / e3t_n(ji,jj,1) 
-
-               ! cumulation of surface flux at each time step
-               qint_cfc(ji,jj,jl) = qint_cfc(ji,jj,jl) + qtr_cfc(ji,jj,jl) * rdt
-               !                                               !----------------!
-            END DO                                             !  end i-j loop  !
-         END DO                                                !----------------!
+            ! space interpolation
+            zpp_cfc  =       xphem(ji,jj)   * zpatm(1,jl)   &
+               &     + ( 1.- xphem(ji,jj) ) * zpatm(2,jl)
+
+            ! Computation of concentration at equilibrium : in picomol/l
+            ! coefficient for solubility for CFC-11/12 in  mol/l/atm
+            IF( tmask(ji,jj,1) .GE. 0.5 ) THEN
+               ztap  = ( ts(ji,jj,1,jp_tem,Kmm) + 273.16 ) * 0.01
+               zdtap = sob(1,jl) + ztap * ( sob(2,jl) + ztap * sob(3,jl) ) 
+               zsol  =  EXP( soa(1,jl) + soa(2,jl) / ztap + soa(3,jl) * LOG( ztap )   &
+                  &                    + soa(4,jl) * ztap * ztap + ts(ji,jj,1,jp_sal,Kmm) * zdtap ) 
+            ELSE
+               zsol  = 0.e0
+            ENDIF
+            ! conversion from mol/l/atm to mol/m3/atm and from mol/m3/atm to mol/m3/pptv    
+            zsol = xconv4 * xconv3 * zsol * tmask(ji,jj,1)  
+            ! concentration at equilibrium
+            zca_cfc = xconv1 * zpp_cfc * zsol * tmask(ji,jj,1)             
+            ! Computation of speed transfert
+            !    Schmidt number revised in Wanninkhof (2014)
+            zt1  = ts(ji,jj,1,jp_tem,Kmm)
+            zt2  = zt1 * zt1 
+            zt3  = zt1 * zt2
+            zt4  = zt2 * zt2
+            zsch = sca(1,jl) + sca(2,jl) * zt1 + sca(3,jl) * zt2 + sca(4,jl) * zt3 + sca(5,jl) * zt4
+
+            !    speed transfert : formulae revised in Wanninkhof (2014)
+            zv2     = wndm(ji,jj) * wndm(ji,jj)
+            zsch    = zsch / 660.
+            zak_cfc = ( 0.251 * xconv2 * zv2 / SQRT(zsch) ) * tmask(ji,jj,1)
+
+            ! Input function  : speed *( conc. at equil - concen at surface )
+            ! tr(:,:,:,:,Kmm) in pico-mol/l idem qtr; ak in en m/a
+            qtr_cfc(ji,jj,jl) = -zak_cfc * ( tr(ji,jj,1,jn,Kbb) - zca_cfc )   &
+               &                         * tmask(ji,jj,1) * ( 1. - fr_i(ji,jj) )
+            ! Add the surface flux to the trend
+            tr(ji,jj,1,jn,Krhs) = tr(ji,jj,1,jn,Krhs) + qtr_cfc(ji,jj,jl) / e3t(ji,jj,1,Kmm) 
+
+            ! cumulation of surface flux at each time step
+            qint_cfc(ji,jj,jl) = qint_cfc(ji,jj,jl) + qtr_cfc(ji,jj,jl) * rn_Dt
+            !                                               !----------------!
+         END_2D
          !                                                  !----------------!
       END DO                                                !  end CFC loop  !
@@ -191,5 +196,5 @@
       IF( l_trdtrc ) THEN
           DO jn = jp_cfc0, jp_cfc1
-            CALL trd_trc( tra(:,:,:,jn), jn, jptra_sms, kt )   ! save trends
+            CALL trd_trc( tr(:,:,:,jn,Krhs), jn, jptra_sms, kt, Kmm )   ! save trends
           END DO
       END IF
@@ -293,5 +298,5 @@
          DO jn = jp_cfc0, jp_cfc1
             jl = jl + 1
-            CALL iom_get( numrtr, jpdom_autoglo, 'qint_'//ctrcnm(jn), qint_cfc(:,:,jl) ) 
+            CALL iom_get( numrtr, jpdom_auto, 'qint_'//ctrcnm(jn), qint_cfc(:,:,jl) ) 
          END DO
       ENDIF
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/CFC/trcwri_cfc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/CFC/trcwri_cfc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/CFC/trcwri_cfc.F90	(revision 13463)
@@ -20,5 +20,5 @@
 CONTAINS
 
-   SUBROUTINE trc_wri_cfc
+   SUBROUTINE trc_wri_cfc( Kmm )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE trc_wri_trc  ***
@@ -26,4 +26,5 @@
       !! ** Purpose :   output passive tracers fields 
       !!---------------------------------------------------------------------
+      INTEGER, INTENT(in)  :: Kmm   ! time level indices
       CHARACTER (len=20)   :: cltra
       INTEGER              :: jn
@@ -34,5 +35,5 @@
       DO jn = jp_cfc0, jp_cfc1
          cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
-         CALL iom_put( cltra, trn(:,:,:,jn) )
+         CALL iom_put( cltra, tr(:,:,:,jn,Kmm) )
       END DO
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/MY_TRC/trcini_my_trc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/MY_TRC/trcini_my_trc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/MY_TRC/trcini_my_trc.F90	(revision 13463)
@@ -28,5 +28,5 @@
 CONTAINS
 
-   SUBROUTINE trc_ini_my_trc
+   SUBROUTINE trc_ini_my_trc( Kmm )
       !!----------------------------------------------------------------------
       !!                     ***  trc_ini_my_trc  ***  
@@ -36,4 +36,5 @@
       !! ** Method  : - Read the namcfc namelist and check the parameter values
       !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kmm  ! time level indices
       !
       CALL trc_nam_my_trc
@@ -50,5 +51,5 @@
       IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
       
-      IF( .NOT. ln_rsttr ) trn(:,:,:,jp_myt0:jp_myt1) = 1.
+      IF( .NOT. ln_rsttr ) tr(:,:,:,jp_myt0:jp_myt1,Kmm) = 1.
       !
    END SUBROUTINE trc_ini_my_trc
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/MY_TRC/trcsms_my_trc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/MY_TRC/trcsms_my_trc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/MY_TRC/trcsms_my_trc.F90	(revision 13463)
@@ -15,5 +15,4 @@
    USE trd_oce
    USE trdtrc
-   USE trcbc, only : trc_bc
 
    IMPLICIT NONE
@@ -32,5 +31,5 @@
 CONTAINS
 
-   SUBROUTINE trc_sms_my_trc( kt )
+   SUBROUTINE trc_sms_my_trc( kt, Kbb, Kmm, Krhs )
       !!----------------------------------------------------------------------
       !!                     ***  trc_sms_my_trc  ***
@@ -42,4 +41,5 @@
       !
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Krhs  ! time level indices
       INTEGER ::   jn   ! dummy loop index
       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: ztrmyt
@@ -54,6 +54,4 @@
       IF( l_trdtrc )  ALLOCATE( ztrmyt(jpi,jpj,jpk) )
 
-      CALL trc_bc ( kt )       ! tracers: surface and lateral Boundary Conditions
-
       ! add here the call to BGC model
 
@@ -61,6 +59,6 @@
       IF( l_trdtrc ) THEN
           DO jn = jp_myt0, jp_myt1
-            ztrmyt(:,:,:) = tra(:,:,:,jn)
-            CALL trd_trc( ztrmyt, jn, jptra_sms, kt )   ! save trends
+            ztrmyt(:,:,:) = tr(:,:,:,jn,Krhs)
+            CALL trd_trc( ztrmyt, jn, jptra_sms, kt, Kmm )   ! save trends
           END DO
           DEALLOCATE( ztrmyt )
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/MY_TRC/trcwri_my_trc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/MY_TRC/trcwri_my_trc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/MY_TRC/trcwri_my_trc.F90	(revision 13463)
@@ -25,5 +25,5 @@
 CONTAINS
 
-   SUBROUTINE trc_wri_my_trc
+   SUBROUTINE trc_wri_my_trc( Kmm )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE trc_wri_trc  ***
@@ -31,4 +31,5 @@
       !! ** Purpose :   output passive tracers fields 
       !!---------------------------------------------------------------------
+      INTEGER, INTENT(in)  :: Kmm   ! time level indices
       CHARACTER (len=20)   :: cltra
       INTEGER              :: jn
@@ -39,5 +40,5 @@
       DO jn = jp_myt0, jp_myt1
          cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
-         CALL iom_put( cltra, trn(:,:,:,jn) )
+         CALL iom_put( cltra, tr(:,:,:,jn,Kmm) )
       END DO
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zbio.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zbio.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zbio.F90	(revision 13463)
@@ -19,5 +19,5 @@
    !
    USE lbclnk          ! 
-   USE prtctl_trc      ! Print control for debbuging
+   USE prtctl          ! Print control for debbuging
    USE iom             !
    
@@ -57,5 +57,6 @@
 
    !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -65,5 +66,5 @@
 CONTAINS
 
-   SUBROUTINE p2z_bio( kt )
+   SUBROUTINE p2z_bio( kt, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p2z_bio  ***
@@ -78,5 +79,5 @@
       !!              is added to the general trend.
       !!        
-      !!                      tra = tra + zf...tra - zftra...
+      !!                      tr(Krhs) = tr(Krhs) + zf...tr(Krhs) - zftra...
       !!                                     |         |
       !!                                     |         |
@@ -84,5 +85,6 @@
       !!        
       !!---------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   kt             ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   Kmm, Krhs      ! time level indices
       !
       INTEGER  ::   ji, jj, jk, jl
@@ -120,121 +122,119 @@
       DO jk = 1, jpkbm1                      !  Upper ocean (bio-layers)  !
          !                                   ! -------------------------- !
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1 
-               ! trophic variables( det, zoo, phy, no3, nh4, dom)
-               ! ------------------------------------------------
-
-               ! negative trophic variables DO not contribute to the fluxes
-               zdet = MAX( 0.e0, trn(ji,jj,jk,jpdet) )
-               zzoo = MAX( 0.e0, trn(ji,jj,jk,jpzoo) )
-               zphy = MAX( 0.e0, trn(ji,jj,jk,jpphy) )
-               zno3 = MAX( 0.e0, trn(ji,jj,jk,jpno3) )
-               znh4 = MAX( 0.e0, trn(ji,jj,jk,jpnh4) )
-               zdom = MAX( 0.e0, trn(ji,jj,jk,jpdom) )
-
-               ! Limitations
-               zlt   = 1.
-               zle   = 1. - EXP( -etot(ji,jj,jk) / aki / zlt )
-               ! psinut,akno3,aknh4 added by asklod AS Kremeur 2005-03
-               zlno3 = zno3 * EXP( -psinut * znh4 ) / ( akno3 + zno3 )
-               zlnh4 = znh4 / (znh4+aknh4)  
-
-               ! sinks and sources
-               !    phytoplankton production and exsudation
-               zno3phy = tmumax * zle * zlt * zlno3 * zphy
-               znh4phy = tmumax * zle * zlt * zlnh4 * zphy
-
-               !    fphylab added by asklod AS Kremeur 2005-03
-               zphydom = rgamma * (1 - fphylab) * (zno3phy + znh4phy)
-               zphynh4 = rgamma * fphylab * (zno3phy + znh4phy)
-               ! zooplankton production
-               !    preferences
-               zppz = rppz
-               zpdz = 1. - rppz
-               zpppz = ( zppz * zphy ) / ( ( zppz * zphy + zpdz * zdet ) + 1.e-13 )
-               zppdz = ( zpdz * zdet ) / ( ( zppz * zphy + zpdz * zdet ) + 1.e-13 )
-               zfood = zpppz * zphy + zppdz * zdet
-               !    filtration 
-               zfilpz = taus * zpppz / (aks + zfood)
-               zfildz = taus * zppdz / (aks + zfood)
-               !    grazing
-               zphyzoo = zfilpz * zphy * zzoo
-               zdetzoo = zfildz * zdet * zzoo
-
-               ! fecal pellets production
-               zzoodet = rpnaz * zphyzoo + rdnaz * zdetzoo
-
-               ! zooplankton liquide excretion
-               zzoonh4 = tauzn * fzoolab * zzoo  
-               zzoodom = tauzn * (1 - fzoolab) * zzoo
-
-               ! mortality
-               !    phytoplankton mortality
-               zphydet = tmminp * zphy
-
-               !    zooplankton mortality
-               !    closure : flux grazing is redistributed below level jpkbio
-               zzoobod = tmminz * zzoo * zzoo
-               xksi(ji,jj) = xksi(ji,jj) + (1-fdbod) * zzoobod * e3t_n(ji,jj,jk)
-               zboddet = fdbod * zzoobod
-
-               ! detritus and dom breakdown
-               zdetnh4 = taudn * fdetlab * zdet
-               zdetdom = taudn * (1 - fdetlab) * zdet
-
-               zdomnh4 = taudomn * zdom
-
-               ! flux added to express how the excess of nitrogen from 
-               ! PHY, ZOO and DET to DOM goes directly to NH4 (flux of ajustment)
-               zdomaju = (1 - redf/reddom) * (zphydom + zzoodom + zdetdom)
-
-               ! Nitrification 
-               znh4no3 = taunn * znh4
-
-               ! determination of trends
-               !    total trend for each biological tracer
-               zphya =   zno3phy + znh4phy - zphynh4 - zphydom - zphyzoo - zphydet
-               zzooa =   zphyzoo + zdetzoo - zzoodet - zzoodom - zzoonh4 - zzoobod
-               zno3a = - zno3phy + znh4no3
-               znh4a = - znh4phy - znh4no3 + zphynh4 + zzoonh4 + zdomnh4 + zdetnh4 + zdomaju
-               zdeta =   zphydet + zzoodet - zdetzoo - zdetnh4 - zdetdom + zboddet
-               zdoma =   zphydom + zzoodom + zdetdom - zdomnh4 - zdomaju
-
-               ! tracer flux at totox-point added to the general trend
-               tra(ji,jj,jk,jpdet) = tra(ji,jj,jk,jpdet) + zdeta
-               tra(ji,jj,jk,jpzoo) = tra(ji,jj,jk,jpzoo) + zzooa
-               tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) + zphya
-               tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) + zno3a
-               tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + znh4a
-               tra(ji,jj,jk,jpdom) = tra(ji,jj,jk,jpdom) + zdoma
-
-                IF( lk_iomput ) THEN
-                  ! convert fluxes in per day
-                  ze3t = e3t_n(ji,jj,jk) * 86400._wp
-                  zw2d(ji,jj,1)  = zw2d(ji,jj,1)  + zno3phy * ze3t
-                  zw2d(ji,jj,2)  = zw2d(ji,jj,2)  + znh4phy * ze3t
-                  zw2d(ji,jj,3)  = zw2d(ji,jj,3)  + zphydom * ze3t
-                  zw2d(ji,jj,4)  = zw2d(ji,jj,4)  + zphynh4 * ze3t
-                  zw2d(ji,jj,5)  = zw2d(ji,jj,5)  + zphyzoo * ze3t
-                  zw2d(ji,jj,6)  = zw2d(ji,jj,6)  + zphydet * ze3t
-                  zw2d(ji,jj,7)  = zw2d(ji,jj,7)  + zdetzoo * ze3t
-                  zw2d(ji,jj,8)  = zw2d(ji,jj,8)  + zzoodet * ze3t
-                  zw2d(ji,jj,9)  = zw2d(ji,jj,9)  + zzoobod * ze3t
-                  zw2d(ji,jj,10) = zw2d(ji,jj,10) + zzoonh4 * ze3t
-                  zw2d(ji,jj,11) = zw2d(ji,jj,11) + zzoodom * ze3t
-                  zw2d(ji,jj,12) = zw2d(ji,jj,12) + znh4no3 * ze3t
-                  zw2d(ji,jj,13) = zw2d(ji,jj,13) + zdomnh4 * ze3t
-                  zw2d(ji,jj,14) = zw2d(ji,jj,14) + zdetnh4 * ze3t
-                  zw2d(ji,jj,15) = zw2d(ji,jj,15) + ( zno3phy + znh4phy - zphynh4 - zphydom - zphyzoo - zphydet ) * ze3t
-                  zw2d(ji,jj,16) = zw2d(ji,jj,16) + ( zphyzoo + zdetzoo - zzoodet - zzoobod - zzoonh4 - zzoodom ) * ze3t
-                  zw2d(ji,jj,17) = zw2d(ji,jj,17) + zdetdom * ze3t
-                  !   
-                  zw3d(ji,jj,jk,1) = zno3phy * 86400
-                  zw3d(ji,jj,jk,2) = znh4phy * 86400     
-                  zw3d(ji,jj,jk,3) = znh4no3 * 86400   
-                   ! 
-                ENDIF
-            END DO
-         END DO
+         DO_2D( 0, 0, 0, 0 )
+            ! trophic variables( det, zoo, phy, no3, nh4, dom)
+            ! ------------------------------------------------
+
+            ! negative trophic variables DO not contribute to the fluxes
+            zdet = MAX( 0.e0, tr(ji,jj,jk,jpdet,Kmm) )
+            zzoo = MAX( 0.e0, tr(ji,jj,jk,jpzoo,Kmm) )
+            zphy = MAX( 0.e0, tr(ji,jj,jk,jpphy,Kmm) )
+            zno3 = MAX( 0.e0, tr(ji,jj,jk,jpno3,Kmm) )
+            znh4 = MAX( 0.e0, tr(ji,jj,jk,jpnh4,Kmm) )
+            zdom = MAX( 0.e0, tr(ji,jj,jk,jpdom,Kmm) )
+
+            ! Limitations
+            zlt   = 1.
+            zle   = 1. - EXP( -etot(ji,jj,jk) / aki / zlt )
+            ! psinut,akno3,aknh4 added by asklod AS Kremeur 2005-03
+            zlno3 = zno3 * EXP( -psinut * znh4 ) / ( akno3 + zno3 )
+            zlnh4 = znh4 / (znh4+aknh4)  
+
+            ! sinks and sources
+            !    phytoplankton production and exsudation
+            zno3phy = tmumax * zle * zlt * zlno3 * zphy
+            znh4phy = tmumax * zle * zlt * zlnh4 * zphy
+
+            !    fphylab added by asklod AS Kremeur 2005-03
+            zphydom = rgamma * (1 - fphylab) * (zno3phy + znh4phy)
+            zphynh4 = rgamma * fphylab * (zno3phy + znh4phy)
+            ! zooplankton production
+            !    preferences
+            zppz = rppz
+            zpdz = 1. - rppz
+            zpppz = ( zppz * zphy ) / ( ( zppz * zphy + zpdz * zdet ) + 1.e-13 )
+            zppdz = ( zpdz * zdet ) / ( ( zppz * zphy + zpdz * zdet ) + 1.e-13 )
+            zfood = zpppz * zphy + zppdz * zdet
+            !    filtration 
+            zfilpz = taus * zpppz / (aks + zfood)
+            zfildz = taus * zppdz / (aks + zfood)
+            !    grazing
+            zphyzoo = zfilpz * zphy * zzoo
+            zdetzoo = zfildz * zdet * zzoo
+
+            ! fecal pellets production
+            zzoodet = rpnaz * zphyzoo + rdnaz * zdetzoo
+
+            ! zooplankton liquide excretion
+            zzoonh4 = tauzn * fzoolab * zzoo  
+            zzoodom = tauzn * (1 - fzoolab) * zzoo
+
+            ! mortality
+            !    phytoplankton mortality
+            zphydet = tmminp * zphy
+
+            !    zooplankton mortality
+            !    closure : flux grazing is redistributed below level jpkbio
+            zzoobod = tmminz * zzoo * zzoo
+            xksi(ji,jj) = xksi(ji,jj) + (1-fdbod) * zzoobod * e3t(ji,jj,jk,Kmm)
+            zboddet = fdbod * zzoobod
+
+            ! detritus and dom breakdown
+            zdetnh4 = taudn * fdetlab * zdet
+            zdetdom = taudn * (1 - fdetlab) * zdet
+
+            zdomnh4 = taudomn * zdom
+
+            ! flux added to express how the excess of nitrogen from 
+            ! PHY, ZOO and DET to DOM goes directly to NH4 (flux of ajustment)
+            zdomaju = (1 - redf/reddom) * (zphydom + zzoodom + zdetdom)
+
+            ! Nitrification 
+            znh4no3 = taunn * znh4
+
+            ! determination of trends
+            !    total trend for each biological tracer
+            zphya =   zno3phy + znh4phy - zphynh4 - zphydom - zphyzoo - zphydet
+            zzooa =   zphyzoo + zdetzoo - zzoodet - zzoodom - zzoonh4 - zzoobod
+            zno3a = - zno3phy + znh4no3
+            znh4a = - znh4phy - znh4no3 + zphynh4 + zzoonh4 + zdomnh4 + zdetnh4 + zdomaju
+            zdeta =   zphydet + zzoodet - zdetzoo - zdetnh4 - zdetdom + zboddet
+            zdoma =   zphydom + zzoodom + zdetdom - zdomnh4 - zdomaju
+
+            ! tracer flux at totox-point added to the general trend
+            tr(ji,jj,jk,jpdet,Krhs) = tr(ji,jj,jk,jpdet,Krhs) + zdeta
+            tr(ji,jj,jk,jpzoo,Krhs) = tr(ji,jj,jk,jpzoo,Krhs) + zzooa
+            tr(ji,jj,jk,jpphy,Krhs) = tr(ji,jj,jk,jpphy,Krhs) + zphya
+            tr(ji,jj,jk,jpno3,Krhs) = tr(ji,jj,jk,jpno3,Krhs) + zno3a
+            tr(ji,jj,jk,jpnh4,Krhs) = tr(ji,jj,jk,jpnh4,Krhs) + znh4a
+            tr(ji,jj,jk,jpdom,Krhs) = tr(ji,jj,jk,jpdom,Krhs) + zdoma
+
+             IF( lk_iomput ) THEN
+               ! convert fluxes in per day
+               ze3t = e3t(ji,jj,jk,Kmm) * 86400._wp
+               zw2d(ji,jj,1)  = zw2d(ji,jj,1)  + zno3phy * ze3t
+               zw2d(ji,jj,2)  = zw2d(ji,jj,2)  + znh4phy * ze3t
+               zw2d(ji,jj,3)  = zw2d(ji,jj,3)  + zphydom * ze3t
+               zw2d(ji,jj,4)  = zw2d(ji,jj,4)  + zphynh4 * ze3t
+               zw2d(ji,jj,5)  = zw2d(ji,jj,5)  + zphyzoo * ze3t
+               zw2d(ji,jj,6)  = zw2d(ji,jj,6)  + zphydet * ze3t
+               zw2d(ji,jj,7)  = zw2d(ji,jj,7)  + zdetzoo * ze3t
+               zw2d(ji,jj,8)  = zw2d(ji,jj,8)  + zzoodet * ze3t
+               zw2d(ji,jj,9)  = zw2d(ji,jj,9)  + zzoobod * ze3t
+               zw2d(ji,jj,10) = zw2d(ji,jj,10) + zzoonh4 * ze3t
+               zw2d(ji,jj,11) = zw2d(ji,jj,11) + zzoodom * ze3t
+               zw2d(ji,jj,12) = zw2d(ji,jj,12) + znh4no3 * ze3t
+               zw2d(ji,jj,13) = zw2d(ji,jj,13) + zdomnh4 * ze3t
+               zw2d(ji,jj,14) = zw2d(ji,jj,14) + zdetnh4 * ze3t
+               zw2d(ji,jj,15) = zw2d(ji,jj,15) + ( zno3phy + znh4phy - zphynh4 - zphydom - zphyzoo - zphydet ) * ze3t
+               zw2d(ji,jj,16) = zw2d(ji,jj,16) + ( zphyzoo + zdetzoo - zzoodet - zzoobod - zzoonh4 - zzoodom ) * ze3t
+               zw2d(ji,jj,17) = zw2d(ji,jj,17) + zdetdom * ze3t
+               !   
+               zw3d(ji,jj,jk,1) = zno3phy * 86400
+               zw3d(ji,jj,jk,2) = znh4phy * 86400     
+               zw3d(ji,jj,jk,3) = znh4no3 * 86400   
+                ! 
+             ENDIF
+         END_2D
       END DO
 
@@ -242,105 +242,103 @@
       DO jk = jpkb, jpkm1                    !  Upper ocean (bio-layers)  !
          !                                   ! -------------------------- !
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1 
-               ! remineralisation of all quantities towards nitrate 
-
-               !    trophic variables( det, zoo, phy, no3, nh4, dom)
-               !       negative trophic variables DO not contribute to the fluxes
-               zdet = MAX( 0.e0, trn(ji,jj,jk,jpdet) )
-               zzoo = MAX( 0.e0, trn(ji,jj,jk,jpzoo) )
-               zphy = MAX( 0.e0, trn(ji,jj,jk,jpphy) )
-               zno3 = MAX( 0.e0, trn(ji,jj,jk,jpno3) )
-               znh4 = MAX( 0.e0, trn(ji,jj,jk,jpnh4) )
-               zdom = MAX( 0.e0, trn(ji,jj,jk,jpdom) )
-
-               !    Limitations
-               zlt   = 0.e0
-               zle   = 0.e0
-               zlno3 = 0.e0
-               zlnh4 = 0.e0
-
-               !    sinks and sources
-               !       phytoplankton production and exsudation
-               zno3phy = 0.e0
-               znh4phy = 0.e0
-               zphydom = 0.e0
-               zphynh4 = 0.e0
-
-               !    zooplankton production
-               zphyzoo = 0.e0      ! grazing
-               zdetzoo = 0.e0
-
-               zzoodet = 0.e0      ! fecal pellets production
-
-               zzoonh4 = tauzn * fzoolab * zzoo         ! zooplankton liquide excretion
-               zzoodom = tauzn * (1 - fzoolab) * zzoo
-
-               !    mortality
-               zphydet = tmminp * zphy      ! phytoplankton mortality
-
-               zzoobod = 0.e0               ! zooplankton mortality
-               zboddet = 0.e0               ! closure : flux fbod is redistributed below level jpkbio
-
-               !    detritus and dom breakdown
-               zdetnh4 = taudn * fdetlab * zdet
-               zdetdom = taudn * (1 - fdetlab) * zdet
-
-               zdomnh4 = taudomn * zdom
-               zdomaju = (1 - redf/reddom) * (zphydom + zzoodom + zdetdom)
-
-               !    Nitrification
-               znh4no3 = taunn * znh4
-
-
-               ! determination of trends
-               !     total trend for each biological tracer
-               zphya =   zno3phy + znh4phy - zphynh4 - zphydom - zphyzoo - zphydet
-               zzooa =   zphyzoo + zdetzoo - zzoodet - zzoodom - zzoonh4 - zzoobod
-               zno3a = - zno3phy + znh4no3 
-               znh4a = - znh4phy - znh4no3 + zphynh4 + zzoonh4 + zdomnh4 + zdetnh4 + zdomaju
-               zdeta = zphydet + zzoodet  - zdetzoo - zdetnh4 - zdetdom + zboddet
-               zdoma = zphydom + zzoodom + zdetdom - zdomnh4 - zdomaju
-
-               ! tracer flux at totox-point added to the general trend
-               tra(ji,jj,jk,jpdet) = tra(ji,jj,jk,jpdet) + zdeta
-               tra(ji,jj,jk,jpzoo) = tra(ji,jj,jk,jpzoo) + zzooa
-               tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) + zphya
-               tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) + zno3a
-               tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + znh4a
-               tra(ji,jj,jk,jpdom) = tra(ji,jj,jk,jpdom) + zdoma
+         DO_2D( 0, 0, 0, 0 )
+            ! remineralisation of all quantities towards nitrate 
+
+            !    trophic variables( det, zoo, phy, no3, nh4, dom)
+            !       negative trophic variables DO not contribute to the fluxes
+            zdet = MAX( 0.e0, tr(ji,jj,jk,jpdet,Kmm) )
+            zzoo = MAX( 0.e0, tr(ji,jj,jk,jpzoo,Kmm) )
+            zphy = MAX( 0.e0, tr(ji,jj,jk,jpphy,Kmm) )
+            zno3 = MAX( 0.e0, tr(ji,jj,jk,jpno3,Kmm) )
+            znh4 = MAX( 0.e0, tr(ji,jj,jk,jpnh4,Kmm) )
+            zdom = MAX( 0.e0, tr(ji,jj,jk,jpdom,Kmm) )
+
+            !    Limitations
+            zlt   = 0.e0
+            zle   = 0.e0
+            zlno3 = 0.e0
+            zlnh4 = 0.e0
+
+            !    sinks and sources
+            !       phytoplankton production and exsudation
+            zno3phy = 0.e0
+            znh4phy = 0.e0
+            zphydom = 0.e0
+            zphynh4 = 0.e0
+
+            !    zooplankton production
+            zphyzoo = 0.e0      ! grazing
+            zdetzoo = 0.e0
+
+            zzoodet = 0.e0      ! fecal pellets production
+
+            zzoonh4 = tauzn * fzoolab * zzoo         ! zooplankton liquide excretion
+            zzoodom = tauzn * (1 - fzoolab) * zzoo
+
+            !    mortality
+            zphydet = tmminp * zphy      ! phytoplankton mortality
+
+            zzoobod = 0.e0               ! zooplankton mortality
+            zboddet = 0.e0               ! closure : flux fbod is redistributed below level jpkbio
+
+            !    detritus and dom breakdown
+            zdetnh4 = taudn * fdetlab * zdet
+            zdetdom = taudn * (1 - fdetlab) * zdet
+
+            zdomnh4 = taudomn * zdom
+            zdomaju = (1 - redf/reddom) * (zphydom + zzoodom + zdetdom)
+
+            !    Nitrification
+            znh4no3 = taunn * znh4
+
+
+            ! determination of trends
+            !     total trend for each biological tracer
+            zphya =   zno3phy + znh4phy - zphynh4 - zphydom - zphyzoo - zphydet
+            zzooa =   zphyzoo + zdetzoo - zzoodet - zzoodom - zzoonh4 - zzoobod
+            zno3a = - zno3phy + znh4no3 
+            znh4a = - znh4phy - znh4no3 + zphynh4 + zzoonh4 + zdomnh4 + zdetnh4 + zdomaju
+            zdeta = zphydet + zzoodet  - zdetzoo - zdetnh4 - zdetdom + zboddet
+            zdoma = zphydom + zzoodom + zdetdom - zdomnh4 - zdomaju
+
+            ! tracer flux at totox-point added to the general trend
+            tr(ji,jj,jk,jpdet,Krhs) = tr(ji,jj,jk,jpdet,Krhs) + zdeta
+            tr(ji,jj,jk,jpzoo,Krhs) = tr(ji,jj,jk,jpzoo,Krhs) + zzooa
+            tr(ji,jj,jk,jpphy,Krhs) = tr(ji,jj,jk,jpphy,Krhs) + zphya
+            tr(ji,jj,jk,jpno3,Krhs) = tr(ji,jj,jk,jpno3,Krhs) + zno3a
+            tr(ji,jj,jk,jpnh4,Krhs) = tr(ji,jj,jk,jpnh4,Krhs) + znh4a
+            tr(ji,jj,jk,jpdom,Krhs) = tr(ji,jj,jk,jpdom,Krhs) + zdoma
+            !
+             IF( lk_iomput ) THEN                  ! convert fluxes in per day
+               ze3t = e3t(ji,jj,jk,Kmm) * 86400._wp
+               zw2d(ji,jj,1)  = zw2d(ji,jj,1)  + zno3phy * ze3t
+               zw2d(ji,jj,2)  = zw2d(ji,jj,2)  + znh4phy * ze3t
+               zw2d(ji,jj,3)  = zw2d(ji,jj,3)  + zphydom * ze3t
+               zw2d(ji,jj,4)  = zw2d(ji,jj,4)  + zphynh4 * ze3t
+               zw2d(ji,jj,5)  = zw2d(ji,jj,5)  + zphyzoo * ze3t
+               zw2d(ji,jj,6)  = zw2d(ji,jj,6)  + zphydet * ze3t
+               zw2d(ji,jj,7)  = zw2d(ji,jj,7)  + zdetzoo * ze3t
+               zw2d(ji,jj,8)  = zw2d(ji,jj,8)  + zzoodet * ze3t
+               zw2d(ji,jj,9)  = zw2d(ji,jj,9)  + zzoobod * ze3t
+               zw2d(ji,jj,10) = zw2d(ji,jj,10) + zzoonh4 * ze3t
+               zw2d(ji,jj,11) = zw2d(ji,jj,11) + zzoodom * ze3t
+               zw2d(ji,jj,12) = zw2d(ji,jj,12) + znh4no3 * ze3t
+               zw2d(ji,jj,13) = zw2d(ji,jj,13) + zdomnh4 * ze3t
+               zw2d(ji,jj,14) = zw2d(ji,jj,14) + zdetnh4 * ze3t
+               zw2d(ji,jj,15) = zw2d(ji,jj,15) + ( zno3phy + znh4phy - zphynh4 - zphydom - zphyzoo - zphydet ) * ze3t
+               zw2d(ji,jj,16) = zw2d(ji,jj,16) + ( zphyzoo + zdetzoo - zzoodet - zzoobod - zzoonh4 - zzoodom ) * ze3t
+               zw2d(ji,jj,17) = zw2d(ji,jj,17) + zdetdom * ze3t
+               !   
+               zw3d(ji,jj,jk,1) = zno3phy * 86400._wp
+               zw3d(ji,jj,jk,2) = znh4phy * 86400._wp
+               zw3d(ji,jj,jk,3) = znh4no3 * 86400._wp
                !
-                IF( lk_iomput ) THEN                  ! convert fluxes in per day
-                  ze3t = e3t_n(ji,jj,jk) * 86400._wp
-                  zw2d(ji,jj,1)  = zw2d(ji,jj,1)  + zno3phy * ze3t
-                  zw2d(ji,jj,2)  = zw2d(ji,jj,2)  + znh4phy * ze3t
-                  zw2d(ji,jj,3)  = zw2d(ji,jj,3)  + zphydom * ze3t
-                  zw2d(ji,jj,4)  = zw2d(ji,jj,4)  + zphynh4 * ze3t
-                  zw2d(ji,jj,5)  = zw2d(ji,jj,5)  + zphyzoo * ze3t
-                  zw2d(ji,jj,6)  = zw2d(ji,jj,6)  + zphydet * ze3t
-                  zw2d(ji,jj,7)  = zw2d(ji,jj,7)  + zdetzoo * ze3t
-                  zw2d(ji,jj,8)  = zw2d(ji,jj,8)  + zzoodet * ze3t
-                  zw2d(ji,jj,9)  = zw2d(ji,jj,9)  + zzoobod * ze3t
-                  zw2d(ji,jj,10) = zw2d(ji,jj,10) + zzoonh4 * ze3t
-                  zw2d(ji,jj,11) = zw2d(ji,jj,11) + zzoodom * ze3t
-                  zw2d(ji,jj,12) = zw2d(ji,jj,12) + znh4no3 * ze3t
-                  zw2d(ji,jj,13) = zw2d(ji,jj,13) + zdomnh4 * ze3t
-                  zw2d(ji,jj,14) = zw2d(ji,jj,14) + zdetnh4 * ze3t
-                  zw2d(ji,jj,15) = zw2d(ji,jj,15) + ( zno3phy + znh4phy - zphynh4 - zphydom - zphyzoo - zphydet ) * ze3t
-                  zw2d(ji,jj,16) = zw2d(ji,jj,16) + ( zphyzoo + zdetzoo - zzoodet - zzoobod - zzoonh4 - zzoodom ) * ze3t
-                  zw2d(ji,jj,17) = zw2d(ji,jj,17) + zdetdom * ze3t
-                  !   
-                  zw3d(ji,jj,jk,1) = zno3phy * 86400._wp
-                  zw3d(ji,jj,jk,2) = znh4phy * 86400._wp
-                  zw3d(ji,jj,jk,3) = znh4no3 * 86400._wp
-                  !
-               ENDIF
-            END DO
-         END DO
+            ENDIF
+         END_2D
       END DO
       !
       IF( lk_iomput ) THEN
-         CALL lbc_lnk( 'p2zbio', zw2d(:,:,:),'T', 1. )
-         CALL lbc_lnk_multi( 'p2zbio', zw3d(:,:,:,1),'T', 1., zw3d(:,:,:,2),'T', 1., zw3d(:,:,:,3),'T', 1. )
+         CALL lbc_lnk( 'p2zbio', zw2d(:,:,:),'T', 1.0_wp )
+         CALL lbc_lnk_multi( 'p2zbio', zw3d(:,:,:,1),'T', 1.0_wp, zw3d(:,:,:,2),'T', 1.0_wp, zw3d(:,:,:,3),'T', 1.0_wp )
          ! Save diagnostics
          CALL iom_put( "TNO3PHY", zw2d(:,:,1) )
@@ -367,8 +365,8 @@
       ENDIF
 
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('bio')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -402,10 +400,8 @@
       IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~'
       !
-      REWIND( numnatp_ref )              ! Namelist namlobphy in reference namelist : Lobster biological parameters
       READ  ( numnatp_ref, namlobphy, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobphy in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist namlobphy in configuration namelist : Lobster biological parameters
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobphy in reference namelist' )
       READ  ( numnatp_cfg, namlobphy, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobphy in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobphy in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobphy )
       !
@@ -419,10 +415,8 @@
       ENDIF
 
-      REWIND( numnatp_ref )              ! Namelist namlobnut in reference namelist : Lobster nutriments parameters
       READ  ( numnatp_ref, namlobnut, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobnut in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist namlobnut in configuration namelist : Lobster nutriments parameters
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobnut in reference namelist' )
       READ  ( numnatp_cfg, namlobnut, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobnut in configuration namelist', lwp )
+904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobnut in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobnut )
 
@@ -436,10 +430,8 @@
       ENDIF
 
-      REWIND( numnatp_ref )              ! Namelist namlobzoo in reference namelist : Lobster zooplankton parameters
       READ  ( numnatp_ref, namlobzoo, IOSTAT = ios, ERR = 905)
-905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobzoo in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist namlobzoo in configuration namelist : Lobster zooplankton parameters
+905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobzoo in reference namelist' )
       READ  ( numnatp_cfg, namlobzoo, IOSTAT = ios, ERR = 906 )
-906   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobzoo in configuration namelist', lwp )
+906   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobzoo in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobzoo )
 
@@ -458,10 +450,8 @@
       ENDIF
 
-      REWIND( numnatp_ref )              ! Namelist namlobdet in reference namelist : Lobster detritus parameters
       READ  ( numnatp_ref, namlobdet, IOSTAT = ios, ERR = 907)
-907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobdet in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist namlobdet in configuration namelist : Lobster detritus parameters
+907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobdet in reference namelist' )
       READ  ( numnatp_cfg, namlobdet, IOSTAT = ios, ERR = 908 )
-908   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobdet in configuration namelist', lwp )
+908   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobdet in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobdet )
 
@@ -473,10 +463,8 @@
       ENDIF
 
-      REWIND( numnatp_ref )              ! Namelist namlobdom in reference namelist : Lobster DOM breakdown rate
       READ  ( numnatp_ref, namlobdom, IOSTAT = ios, ERR = 909)
-909   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobdom in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist namlobdom in configuration namelist : Lobster DOM breakdown rate
+909   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlobdom in reference namelist' )
       READ  ( numnatp_cfg, namlobdom, IOSTAT = ios, ERR = 910 )
-910   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobdom in configuration namelist', lwp )
+910   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobdom in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobdom )
 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zexp.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zexp.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zexp.F90	(revision 13463)
@@ -17,5 +17,5 @@
    USE p2zsed
    USE lbclnk
-   USE prtctl_trc      ! Print control for debbuging
+   USE prtctl          ! Print control for debbuging
    USE trd_oce
    USE trdtrc
@@ -38,5 +38,6 @@
 
    !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -46,5 +47,5 @@
 CONTAINS
 
-   SUBROUTINE p2z_exp( kt )
+   SUBROUTINE p2z_exp( kt, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p2z_exp  ***
@@ -60,5 +61,6 @@
       !!---------------------------------------------------------------------
       !!
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   kt             ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   Kmm, Krhs      ! time level indices
       !!
       INTEGER  ::   ji, jj, jk, jl, ikt
@@ -70,5 +72,5 @@
       IF( ln_timing )   CALL timing_start('p2z_exp')
       !
-      IF( kt == nittrc000 )   CALL p2z_exp_init
+      IF( kt == nittrc000 )   CALL p2z_exp_init( Kmm )
 
       zsedpoca(:,:) = 0.
@@ -80,12 +82,8 @@
       ! LAYERS IS DETERMINED BY DMIN3 DEFINED IN sms_p2z.F90
       ! ----------------------------------------------------------------------
-      DO jk = 1, jpkm1
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-               ze3t = 1. / e3t_n(ji,jj,jk)
-               tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) + ze3t * dmin3(ji,jj,jk) * xksi(ji,jj)
-            END DO
-         END DO
-      END DO
+      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+         ze3t = 1. / e3t(ji,jj,jk,Kmm)
+         tr(ji,jj,jk,jpno3,Krhs) = tr(ji,jj,jk,jpno3,Krhs) + ze3t * dmin3(ji,jj,jk) * xksi(ji,jj)
+      END_3D
 
       ! Find the last level of the water column
@@ -95,23 +93,19 @@
       zgeolpoc = 0.e0         !     Initialization
       ! Release of nutrients from the "simple" sediment
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1
-            ikt = mbkt(ji,jj) 
-            tra(ji,jj,ikt,jpno3) = tra(ji,jj,ikt,jpno3) + sedlam * sedpocn(ji,jj) / e3t_n(ji,jj,ikt) 
-            ! Deposition of organic matter in the sediment
-            zwork = vsed * trn(ji,jj,ikt,jpdet)
-            zsedpoca(ji,jj) = ( zwork + dminl(ji,jj) * xksi(ji,jj)   &
-               &           - sedlam * sedpocn(ji,jj) - sedlostpoc * sedpocn(ji,jj) ) * rdt
-            zgeolpoc = zgeolpoc + sedlostpoc * sedpocn(ji,jj) * e1e2t(ji,jj)
-         END DO
-      END DO
-
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1
-            tra(ji,jj,1,jpno3) = tra(ji,jj,1,jpno3) + zgeolpoc * cmask(ji,jj) / areacot / e3t_n(ji,jj,1)
-         END DO
-      END DO
-
-      CALL lbc_lnk( 'p2zexp', sedpocn, 'T', 1. )
+      DO_2D( 0, 0, 0, 0 )
+         ikt = mbkt(ji,jj) 
+         tr(ji,jj,ikt,jpno3,Krhs) = tr(ji,jj,ikt,jpno3,Krhs) + sedlam * sedpocn(ji,jj) / e3t(ji,jj,ikt,Kmm) 
+         ! Deposition of organic matter in the sediment
+         zwork = vsed * tr(ji,jj,ikt,jpdet,Kmm)
+         zsedpoca(ji,jj) = ( zwork + dminl(ji,jj) * xksi(ji,jj)   &
+            &           - sedlam * sedpocn(ji,jj) - sedlostpoc * sedpocn(ji,jj) ) * rn_Dt
+         zgeolpoc = zgeolpoc + sedlostpoc * sedpocn(ji,jj) * e1e2t(ji,jj)
+      END_2D
+
+      DO_2D( 0, 0, 0, 0 )
+         tr(ji,jj,1,jpno3,Krhs) = tr(ji,jj,1,jpno3,Krhs) + zgeolpoc * cmask(ji,jj) / areacot / e3t(ji,jj,1,Kmm)
+      END_2D
+
+      CALL lbc_lnk( 'p2zexp', sedpocn, 'T', 1.0_wp )
  
       ! Oa & Ek: diagnostics depending on jpdia2d !          left as example
@@ -121,17 +115,15 @@
       ! Time filter and swap of arrays
       ! ------------------------------
-      IF( neuler == 0 .AND. kt == nittrc000 ) THEN        ! Euler time-stepping at first time-step
-        !                                             ! (only swap)
+      IF( l_1st_euler ) THEN        ! Euler time-stepping at first time-step
+        !                           ! (only swap)
         sedpocn(:,:) = zsedpoca(:,:)
         !                                              
       ELSE
         !
-        DO jj = 1, jpj
-           DO ji = 1, jpi
-              zsedpocd = zsedpoca(ji,jj) - 2. * sedpocn(ji,jj) + sedpocb(ji,jj)      ! time laplacian on tracers
-              sedpocb(ji,jj) = sedpocn(ji,jj) + atfp * zsedpocd                     ! sedpocb <-- filtered sedpocn
-              sedpocn(ji,jj) = zsedpoca(ji,jj)                                       ! sedpocn <-- sedpoca
-           END DO
-        END DO
+        DO_2D( 1, 1, 1, 1 )
+           zsedpocd = zsedpoca(ji,jj) - 2. * sedpocn(ji,jj) + sedpocb(ji,jj)      ! time laplacian on tracers
+           sedpocb(ji,jj) = sedpocn(ji,jj) + rn_atfp * zsedpocd                     ! sedpocb <-- filtered sedpocn
+           sedpocn(ji,jj) = zsedpoca(ji,jj)                                       ! sedpocn <-- sedpoca
+        END_2D
         ! 
       ENDIF
@@ -146,8 +138,8 @@
       ENDIF
       !
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('exp')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -157,9 +149,10 @@
 
 
-   SUBROUTINE p2z_exp_init
+   SUBROUTINE p2z_exp_init( Kmm )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE p4z_exp_init  ***
       !! ** purpose :   specific initialisation for export
       !!----------------------------------------------------------------------
+      INTEGER, INTENT(in)  ::  Kmm      ! time level index
       INTEGER  ::   ji, jj, jk
       REAL(wp) ::   zmaskt, zfluo, zfluu
@@ -181,16 +174,12 @@
       zdm0 = 0._wp
       zrro = 1._wp
-      DO jk = jpkb, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zfluo = ( gdepw_n(ji,jj,jk  ) / gdepw_n(ji,jj,jpkb) )**xhr
-               zfluu = ( gdepw_n(ji,jj,jk+1) / gdepw_n(ji,jj,jpkb) )**xhr
-               IF( zfluo.GT.1. )   zfluo = 1._wp
-               zdm0(ji,jj,jk) = zfluo - zfluu
-               IF( jk <= jpkb-1 )   zdm0(ji,jj,jk) = 0._wp
-               zrro(ji,jj) = zrro(ji,jj) - zdm0(ji,jj,jk)
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, jpkb, jpkm1 )
+         zfluo = ( gdepw(ji,jj,jk  ,Kmm) / gdepw(ji,jj,jpkb,Kmm) )**xhr
+         zfluu = ( gdepw(ji,jj,jk+1,Kmm) / gdepw(ji,jj,jpkb,Kmm) )**xhr
+         IF( zfluo.GT.1. )   zfluo = 1._wp
+         zdm0(ji,jj,jk) = zfluo - zfluu
+         IF( jk <= jpkb-1 )   zdm0(ji,jj,jk) = 0._wp
+         zrro(ji,jj) = zrro(ji,jj) - zdm0(ji,jj,jk)
+      END_3D
       !
       zdm0(:,:,jpk) = zrro(:,:)
@@ -202,37 +191,29 @@
       dminl(:,:)   = 0._wp
       dmin3(:,:,:) = zdm0
-      DO jk = 1, jpk
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( tmask(ji,jj,jk) == 0._wp ) THEN
-                  dminl(ji,jj) = dminl(ji,jj) + dmin3(ji,jj,jk)
-                  dmin3(ji,jj,jk) = 0._wp
-               ENDIF
-            END DO
-         END DO
-      END DO
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( tmask(ji,jj,1) == 0 )   dmin3(ji,jj,1) = 0._wp
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpk )
+         IF( tmask(ji,jj,jk) == 0._wp ) THEN
+            dminl(ji,jj) = dminl(ji,jj) + dmin3(ji,jj,jk)
+            dmin3(ji,jj,jk) = 0._wp
+         ENDIF
+      END_3D
+
+      DO_2D( 1, 1, 1, 1 )
+         IF( tmask(ji,jj,1) == 0 )   dmin3(ji,jj,1) = 0._wp
+      END_2D
 
       ! Coastal mask 
       cmask(:,:) = 0._wp
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1
-            IF( tmask(ji,jj,1) /= 0. ) THEN
-               zmaskt = tmask(ji+1,jj,1) * tmask(ji-1,jj,1) * tmask(ji,jj+1,1) * tmask(ji,jj-1,1) 
-               IF( zmaskt == 0. )   cmask(ji,jj) = 1._wp
-            END IF
-         END DO
-      END DO
-      CALL lbc_lnk( 'p2zexp', cmask , 'T', 1. )      ! lateral boundary conditions on cmask   (sign unchanged)
+      DO_2D( 0, 0, 0, 0 )
+         IF( tmask(ji,jj,1) /= 0. ) THEN
+            zmaskt = tmask(ji+1,jj,1) * tmask(ji-1,jj,1) * tmask(ji,jj+1,1) * tmask(ji,jj-1,1) 
+            IF( zmaskt == 0. )   cmask(ji,jj) = 1._wp
+         END IF
+      END_2D
+      CALL lbc_lnk( 'p2zexp', cmask , 'T', 1.0_wp )      ! lateral boundary conditions on cmask   (sign unchanged)
       areacot = glob_sum( 'p2zexp', e1e2t(:,:) * cmask(:,:) )
       !
       IF( ln_rsttr ) THEN
-         CALL iom_get( numrtr, jpdom_autoglo, 'SEDB'//ctrcnm(jpdet), sedpocb(:,:) )
-         CALL iom_get( numrtr, jpdom_autoglo, 'SEDN'//ctrcnm(jpdet), sedpocn(:,:) )
+         CALL iom_get( numrtr, jpdom_auto, 'SEDB'//ctrcnm(jpdet), sedpocb(:,:) )
+         CALL iom_get( numrtr, jpdom_auto, 'SEDN'//ctrcnm(jpdet), sedpocn(:,:) )
       ELSE
          sedpocb(:,:) = 0._wp
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zopt.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zopt.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zopt.F90	(revision 13463)
@@ -18,5 +18,5 @@
    USE trc
    USE sms_pisces
-   USE prtctl_trc      ! Print control for debbuging
+   USE prtctl          ! Print control for debbuging
 
    IMPLICIT NONE
@@ -38,4 +38,7 @@
    REAL(wp), PUBLIC ::  reddom    ! redfield ratio (C:N) for DOM
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -45,5 +48,5 @@
 CONTAINS
 
-   SUBROUTINE p2z_opt( kt )
+   SUBROUTINE p2z_opt( kt, Kmm )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p2z_opt  ***
@@ -61,4 +64,5 @@
       !!
       INTEGER, INTENT( in ) ::   kt   ! index of the time stepping
+      INTEGER, INTENT( in ) ::   Kmm  ! time level index
       !!
       INTEGER  ::   ji, jj, jk          ! dummy loop indices
@@ -91,50 +95,36 @@
       !                                          ! Photosynthetically Available Radiation (PAR)
       zcoef = 12 * redf / rcchl / rpig           ! --------------------------------------
-      DO jk = 2, jpk                                  ! local par at w-levels
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zpig = LOG(  MAX( TINY(0.), trn(ji,jj,jk-1,jpphy) ) * zcoef  )
-               zkr  = xkr0 + xkrp * EXP( xlr * zpig )
-               zkg  = xkg0 + xkgp * EXP( xlg * zpig )
-               zparr(ji,jj,jk) = zparr(ji,jj,jk-1) * EXP( -zkr * e3t_n(ji,jj,jk-1) )
-               zparg(ji,jj,jk) = zparg(ji,jj,jk-1) * EXP( -zkg * e3t_n(ji,jj,jk-1) )
-            END DO
-        END DO
-      END DO
-      DO jk = 1, jpkm1                                ! mean par at t-levels
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zpig = LOG(  MAX( TINY(0.), trn(ji,jj,jk,jpphy) ) * zcoef  )
-               zkr  = xkr0 + xkrp * EXP( xlr * zpig )
-               zkg  = xkg0 + xkgp * EXP( xlg * zpig )
-               zparr(ji,jj,jk) = zparr(ji,jj,jk) / ( zkr * e3t_n(ji,jj,jk) ) * ( 1 - EXP( -zkr * e3t_n(ji,jj,jk) ) )
-               zparg(ji,jj,jk) = zparg(ji,jj,jk) / ( zkg * e3t_n(ji,jj,jk) ) * ( 1 - EXP( -zkg * e3t_n(ji,jj,jk) ) )
-               etot (ji,jj,jk) = MAX( zparr(ji,jj,jk) + zparg(ji,jj,jk), 1.e-15 )
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 2, jpk )
+         zpig = LOG(  MAX( TINY(0.), tr(ji,jj,jk-1,jpphy,Kmm) ) * zcoef  )
+         zkr  = xkr0 + xkrp * EXP( xlr * zpig )
+         zkg  = xkg0 + xkgp * EXP( xlg * zpig )
+         zparr(ji,jj,jk) = zparr(ji,jj,jk-1) * EXP( -zkr * e3t(ji,jj,jk-1,Kmm) )
+         zparg(ji,jj,jk) = zparg(ji,jj,jk-1) * EXP( -zkg * e3t(ji,jj,jk-1,Kmm) )
+      END_3D
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zpig = LOG(  MAX( TINY(0.), tr(ji,jj,jk,jpphy,Kmm) ) * zcoef  )
+         zkr  = xkr0 + xkrp * EXP( xlr * zpig )
+         zkg  = xkg0 + xkgp * EXP( xlg * zpig )
+         zparr(ji,jj,jk) = zparr(ji,jj,jk) / ( zkr * e3t(ji,jj,jk,Kmm) ) * ( 1 - EXP( -zkr * e3t(ji,jj,jk,Kmm) ) )
+         zparg(ji,jj,jk) = zparg(ji,jj,jk) / ( zkg * e3t(ji,jj,jk,Kmm) ) * ( 1 - EXP( -zkg * e3t(ji,jj,jk,Kmm) ) )
+         etot (ji,jj,jk) = MAX( zparr(ji,jj,jk) + zparg(ji,jj,jk), 1.e-15 )
+      END_3D
 
       !                                          ! Euphotic layer
       !                                          ! --------------
       neln(:,:) = 1                                   ! euphotic layer level
-      DO jk = 1, jpkm1                                ! (i.e. 1rst T-level strictly below EL bottom)
-         DO jj = 1, jpj
-           DO ji = 1, jpi
-              IF( etot(ji,jj,jk) >= zpar100(ji,jj) )   neln(ji,jj) = jk + 1 
-           END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+        IF( etot(ji,jj,jk) >= zpar100(ji,jj) )   neln(ji,jj) = jk + 1 
+      END_3D
       !                                               ! Euphotic layer depth
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            heup(ji,jj) = gdepw_n(ji,jj,neln(ji,jj))
-         END DO
-      END DO 
+      DO_2D( 1, 1, 1, 1 )
+         heup(ji,jj) = gdepw(ji,jj,neln(ji,jj),Kmm)
+      END_2D
 
 
-      IF(ln_ctl) THEN      ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc) 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 )
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl( tab4d_1=tr(:,:,:,:,Kmm), mask1=tmask, clinfo=ctrcnm )
       ENDIF
       !
@@ -159,11 +149,9 @@
       !!----------------------------------------------------------------------
 
-      REWIND( numnatp_ref )              ! Namelist namlobopt in reference namelist : Lobster options
       READ  ( numnatp_ref, namlobopt, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namlobopt in reference namelist', lwp )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namlobopt in reference namelist' )
 
-      REWIND( numnatp_cfg )              ! Namelist namlobopt in configuration namelist : Lobster options
       READ  ( numnatp_cfg, namlobopt, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namlobopt in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namlobopt in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobopt )
 
@@ -181,11 +169,9 @@
       ENDIF
       !
-      REWIND( numnatp_ref )              ! Namelist namlobrat in reference namelist : Lobster ratios
       READ  ( numnatp_ref, namlobrat, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namlobrat in reference namelist', lwp )
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namlobrat in reference namelist' )
 
-      REWIND( numnatp_cfg )              ! Namelist namlobrat in configuration namelist : Lobster ratios
       READ  ( numnatp_cfg, namlobrat, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 ) CALL ctl_nam ( ios , 'namlobrat in configuration namelist', lwp )
+904   IF( ios >  0 ) CALL ctl_nam ( ios , 'namlobrat in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobrat )
 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zsed.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zsed.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zsed.F90	(revision 13463)
@@ -18,5 +18,5 @@
    USE lbclnk          !
    USE iom             !
-   USE prtctl_trc      ! Print control for debbuging
+   USE prtctl          ! Print control for debbuging
 
    IMPLICIT NONE
@@ -31,4 +31,7 @@
    REAL(wp), PUBLIC ::   xhr         !: coeff for martin''s remineralisation profile
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -38,5 +41,5 @@
 CONTAINS
 
-   SUBROUTINE p2z_sed( kt )
+   SUBROUTINE p2z_sed( kt, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p2z_sed  ***
@@ -49,12 +52,13 @@
       !!              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)
+      !!                      dz(tr(:,:,:,:,Kmm) ww) = 1/bt dk+1( e1t e2t vsed (tr(:,:,:,:,Kmm)) )
+      !!              add this trend now to the general trend of tracer (ta,sa,tr(:,:,:,:,Krhs)):
+      !!                             tr(:,:,:,:,Krhs) = tr(:,:,:,:,Krhs) + dz(tr(:,:,:,:,Kmm) ww)
       !!        
       !!              IF 'key_diabio' is defined, the now vertical advection
       !!              trend of passive tracers is saved for futher diagnostics.
       !!---------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   Kmm, Krhs  ! time level indices
       !
       INTEGER  ::   ji, jj, jk, jl, ierr
@@ -81,23 +85,19 @@
       ! tracer flux at w-point: we use -vsed (downward flux)  with simplification : no e1*e2
       DO jk = 2, jpkm1
-         zwork(:,:,jk) = -vsed * trn(:,:,jk-1,jpdet)
+         zwork(:,:,jk) = -vsed * tr(:,:,jk-1,jpdet,Kmm)
       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(ji,jj,jk)  = - ( zwork(ji,jj,jk) - zwork(ji,jj,jk+1) ) / e3t_n(ji,jj,jk)
-               tra(ji,jj,jk,jpdet) = tra(ji,jj,jk,jpdet) + ztra(ji,jj,jk) 
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         ztra(ji,jj,jk)  = - ( zwork(ji,jj,jk) - zwork(ji,jj,jk+1) ) / e3t(ji,jj,jk,Kmm)
+         tr(ji,jj,jk,jpdet,Krhs) = tr(ji,jj,jk,jpdet,Krhs) + ztra(ji,jj,jk) 
+      END_3D
 
       IF( lk_iomput )  THEN
          IF( iom_use( "TDETSED" ) ) THEN
             ALLOCATE( zw2d(jpi,jpj) )
-            zw2d(:,:) =  ztra(:,:,1) * e3t_n(:,:,1) * 86400._wp
+            zw2d(:,:) =  ztra(:,:,1) * e3t(:,:,1,Kmm) * 86400._wp
             DO jk = 2, jpkm1
-               zw2d(:,:) = zw2d(:,:) + ztra(:,:,jk) * e3t_n(:,:,jk) * 86400._wp
+               zw2d(:,:) = zw2d(:,:) + ztra(:,:,jk) * e3t(:,:,jk,Kmm) * 86400._wp
             END DO
             CALL iom_put( "TDETSED", zw2d )
@@ -107,8 +107,8 @@
       !
 
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc)   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)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -132,10 +132,8 @@
       !!----------------------------------------------------------------------
       !
-      REWIND( numnatp_ref )              ! Namelist namlobsed in reference namelist : Lobster sediments
       READ  ( numnatp_ref, namlobsed, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlosed in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist namlobsed in configuration namelist : Lobster sediments
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlosed in reference namelist' )
       READ  ( numnatp_cfg, namlobsed, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobsed in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlobsed in configuration namelist' )
       IF(lwm) WRITE ( numonp, namlobsed )
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zsms.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zsms.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P2Z/p2zsms.F90	(revision 13463)
@@ -35,5 +35,5 @@
 CONTAINS
 
-   SUBROUTINE p2z_sms( kt )
+   SUBROUTINE p2z_sms( kt, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p2z_sms  ***
@@ -44,5 +44,6 @@
       !! ** Method  : - ???
       !! --------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   kt            ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   Kmm, Krhs     ! ocean time level index      
       !
       INTEGER ::   jn   ! dummy loop index
@@ -51,12 +52,12 @@
       IF( ln_timing )   CALL timing_start('p2z_sms')
       !
-      CALL p2z_opt( kt )      ! optical model
-      CALL p2z_bio( kt )      ! biological model
-      CALL p2z_sed( kt )      ! sedimentation model
-      CALL p2z_exp( kt )      ! export
+      CALL p2z_opt( kt, Kmm       )      ! optical model
+      CALL p2z_bio( kt, Kmm, Krhs )      ! biological model
+      CALL p2z_sed( kt, Kmm, Krhs )      ! sedimentation model
+      CALL p2z_exp( kt, Kmm, Krhs )      ! export
       !
       IF( l_trdtrc ) THEN
          DO jn = jp_pcs0, jp_pcs1
-           CALL trd_trc( tra(:,:,:,jn), jn, jptra_sms, kt )   ! save trends
+           CALL trd_trc( tr(:,:,:,jn,Krhs), jn, jptra_sms, kt, Kmm )   ! save trends
          END DO
       END IF
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zagg.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zagg.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zagg.F90	(revision 13463)
@@ -17,5 +17,5 @@
    USE trc             !  passive tracers common variables 
    USE sms_pisces      !  PISCES Source Minus Sink variables
-   USE prtctl_trc      !  print control for debugging
+   USE prtctl          !  print control for debugging
 
    IMPLICIT NONE
@@ -24,4 +24,6 @@
    PUBLIC   p4z_agg         ! called in p4zbio.F90
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -31,5 +33,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_agg ( kt, knt )
+   SUBROUTINE p4z_agg ( kt, knt, Kbb, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_agg  ***
@@ -40,4 +42,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt, knt   !
+      INTEGER, INTENT(in) ::   Kbb, Krhs ! time level indices
       !
       INTEGER  ::   ji, jj, jk
@@ -57,124 +60,116 @@
       IF( ln_p4z ) THEN
          !
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  !
-                  zfact = xstep * xdiss(ji,jj,jk)
-                  !  Part I : Coagulation dependent on turbulence
-                  zagg1 = 25.9  * zfact * trb(ji,jj,jk,jppoc) * trb(ji,jj,jk,jppoc)
-                  zagg2 = 4452. * zfact * trb(ji,jj,jk,jppoc) * trb(ji,jj,jk,jpgoc)
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+            !
+            zfact = xstep * xdiss(ji,jj,jk)
+            !  Part I : Coagulation dependent on turbulence
+            zagg1 = 25.9  * zfact * tr(ji,jj,jk,jppoc,Kbb) * tr(ji,jj,jk,jppoc,Kbb)
+            zagg2 = 4452. * zfact * tr(ji,jj,jk,jppoc,Kbb) * tr(ji,jj,jk,jpgoc,Kbb)
 
-                  ! Part II : Differential settling
+            ! Part II : Differential settling
 
-                  !  Aggregation of small into large particles
-                  zagg3 =  47.1 * xstep * trb(ji,jj,jk,jppoc) * trb(ji,jj,jk,jpgoc)
-                  zagg4 =  3.3  * xstep * trb(ji,jj,jk,jppoc) * trb(ji,jj,jk,jppoc)
+            !  Aggregation of small into large particles
+            zagg3 =  47.1 * xstep * tr(ji,jj,jk,jppoc,Kbb) * tr(ji,jj,jk,jpgoc,Kbb)
+            zagg4 =  3.3  * xstep * tr(ji,jj,jk,jppoc,Kbb) * tr(ji,jj,jk,jppoc,Kbb)
 
-                  zagg   = zagg1 + zagg2 + zagg3 + zagg4
-                  zaggfe = zagg * trb(ji,jj,jk,jpsfe) / ( trb(ji,jj,jk,jppoc) + rtrn )
+            zagg   = zagg1 + zagg2 + zagg3 + zagg4
+            zaggfe = zagg * tr(ji,jj,jk,jpsfe,Kbb) / ( tr(ji,jj,jk,jppoc,Kbb) + rtrn )
 
-                  ! Aggregation of DOC to POC : 
-                  ! 1st term is shear aggregation of DOC-DOC
-                  ! 2nd term is shear aggregation of DOC-POC
-                  ! 3rd term is differential settling of DOC-POC
-                  zaggdoc  = ( ( 0.369 * 0.3 * trb(ji,jj,jk,jpdoc) + 102.4 * trb(ji,jj,jk,jppoc) ) * zfact       &
-                  &            + 2.4 * xstep * trb(ji,jj,jk,jppoc) ) * 0.3 * trb(ji,jj,jk,jpdoc)
-                  ! transfer of DOC to GOC : 
-                  ! 1st term is shear aggregation
-                  ! 2nd term is differential settling 
-                  zaggdoc2 = ( 3.53E3 * zfact + 0.1 * xstep ) * trb(ji,jj,jk,jpgoc) * 0.3 * trb(ji,jj,jk,jpdoc)
-                  ! tranfer of DOC to POC due to brownian motion
-                  zaggdoc3 =  114. * 0.3 * trb(ji,jj,jk,jpdoc) *xstep * 0.3 * trb(ji,jj,jk,jpdoc)
+            ! Aggregation of DOC to POC : 
+            ! 1st term is shear aggregation of DOC-DOC
+            ! 2nd term is shear aggregation of DOC-POC
+            ! 3rd term is differential settling of DOC-POC
+            zaggdoc  = ( ( 0.369 * 0.3 * tr(ji,jj,jk,jpdoc,Kbb) + 102.4 * tr(ji,jj,jk,jppoc,Kbb) ) * zfact       &
+            &            + 2.4 * xstep * tr(ji,jj,jk,jppoc,Kbb) ) * 0.3 * tr(ji,jj,jk,jpdoc,Kbb)
+            ! transfer of DOC to GOC : 
+            ! 1st term is shear aggregation
+            ! 2nd term is differential settling 
+            zaggdoc2 = ( 3.53E3 * zfact + 0.1 * xstep ) * tr(ji,jj,jk,jpgoc,Kbb) * 0.3 * tr(ji,jj,jk,jpdoc,Kbb)
+            ! tranfer of DOC to POC due to brownian motion
+            zaggdoc3 =  114. * 0.3 * tr(ji,jj,jk,jpdoc,Kbb) *xstep * 0.3 * tr(ji,jj,jk,jpdoc,Kbb)
 
-                  !  Update the trends
-                  tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) - zagg + zaggdoc + zaggdoc3
-                  tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) + zagg + zaggdoc2
-                  tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) - zaggfe
-                  tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + zaggfe
-                  tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) - zaggdoc - zaggdoc2 - zaggdoc3
-                  !
-                  conspoc(ji,jj,jk) = conspoc(ji,jj,jk) - zagg + zaggdoc + zaggdoc3
-                  prodgoc(ji,jj,jk) = prodgoc(ji,jj,jk) + zagg + zaggdoc2
-                  !
-               END DO
-            END DO
-         END DO
+            !  Update the trends
+            tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) - zagg + zaggdoc + zaggdoc3
+            tr(ji,jj,jk,jpgoc,Krhs) = tr(ji,jj,jk,jpgoc,Krhs) + zagg + zaggdoc2
+            tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) - zaggfe
+            tr(ji,jj,jk,jpbfe,Krhs) = tr(ji,jj,jk,jpbfe,Krhs) + zaggfe
+            tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) - zaggdoc - zaggdoc2 - zaggdoc3
+            !
+            conspoc(ji,jj,jk) = conspoc(ji,jj,jk) - zagg + zaggdoc + zaggdoc3
+            prodgoc(ji,jj,jk) = prodgoc(ji,jj,jk) + zagg + zaggdoc2
+            !
+         END_3D
       ELSE    ! ln_p5z
         !
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  !
-                  zfact = xstep * xdiss(ji,jj,jk)
-                  !  Part I : Coagulation dependent on turbulence
-                  zaggtmp = 25.9  * zfact * trb(ji,jj,jk,jppoc)
-                  zaggpoc1 = zaggtmp * trb(ji,jj,jk,jppoc)
-                  zaggtmp = 4452. * zfact * trb(ji,jj,jk,jpgoc)
-                  zaggpoc2 = zaggtmp * trb(ji,jj,jk,jppoc)
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+            !
+            zfact = xstep * xdiss(ji,jj,jk)
+            !  Part I : Coagulation dependent on turbulence
+            zaggtmp = 25.9  * zfact * tr(ji,jj,jk,jppoc,Kbb)
+            zaggpoc1 = zaggtmp * tr(ji,jj,jk,jppoc,Kbb)
+            zaggtmp = 4452. * zfact * tr(ji,jj,jk,jpgoc,Kbb)
+            zaggpoc2 = zaggtmp * tr(ji,jj,jk,jppoc,Kbb)
 
-                  ! Part II : Differential settling
-   
-                  !  Aggregation of small into large particles
-                  zaggtmp =  47.1 * xstep * trb(ji,jj,jk,jpgoc)
-                  zaggpoc3 = zaggtmp * trb(ji,jj,jk,jppoc)
-                  zaggtmp =  3.3  * xstep * trb(ji,jj,jk,jppoc)
-                  zaggpoc4 = zaggtmp * trb(ji,jj,jk,jppoc)
+            ! Part II : Differential settling
 
-                  zaggpoc   = zaggpoc1 + zaggpoc2 + zaggpoc3 + zaggpoc4
-                  zaggpon = zaggpoc * trb(ji,jj,jk,jppon) / ( trb(ji,jj,jk,jppoc) + rtrn)
-                  zaggpop = zaggpoc * trb(ji,jj,jk,jppop) / ( trb(ji,jj,jk,jppoc) + rtrn)
-                  zaggfe = zaggpoc * trb(ji,jj,jk,jpsfe) / ( trb(ji,jj,jk,jppoc)  + rtrn )
+            !  Aggregation of small into large particles
+            zaggtmp =  47.1 * xstep * tr(ji,jj,jk,jpgoc,Kbb)
+            zaggpoc3 = zaggtmp * tr(ji,jj,jk,jppoc,Kbb)
+            zaggtmp =  3.3  * xstep * tr(ji,jj,jk,jppoc,Kbb)
+            zaggpoc4 = zaggtmp * tr(ji,jj,jk,jppoc,Kbb)
 
-                  ! Aggregation of DOC to POC : 
-                  ! 1st term is shear aggregation of DOC-DOC
-                  ! 2nd term is shear aggregation of DOC-POC
-                  ! 3rd term is differential settling of DOC-POC
-                  zaggtmp = ( ( 0.369 * 0.3 * trb(ji,jj,jk,jpdoc) + 102.4 * trb(ji,jj,jk,jppoc) ) * zfact       &
-                  &            + 2.4 * xstep * trb(ji,jj,jk,jppoc) )
-                  zaggdoc  = zaggtmp * 0.3 * trb(ji,jj,jk,jpdoc)
-                  zaggdon  = zaggtmp * 0.3 * trb(ji,jj,jk,jpdon)
-                  zaggdop  = zaggtmp * 0.3 * trb(ji,jj,jk,jpdop)
+            zaggpoc   = zaggpoc1 + zaggpoc2 + zaggpoc3 + zaggpoc4
+            zaggpon = zaggpoc * tr(ji,jj,jk,jppon,Kbb) / ( tr(ji,jj,jk,jppoc,Kbb) + rtrn)
+            zaggpop = zaggpoc * tr(ji,jj,jk,jppop,Kbb) / ( tr(ji,jj,jk,jppoc,Kbb) + rtrn)
+            zaggfe = zaggpoc * tr(ji,jj,jk,jpsfe,Kbb) / ( tr(ji,jj,jk,jppoc,Kbb)  + rtrn )
 
-                  ! transfer of DOC to GOC : 
-                  ! 1st term is shear aggregation
-                  ! 2nd term is differential settling 
-                  zaggtmp = ( 3.53E3 * zfact + 0.1 * xstep ) * trb(ji,jj,jk,jpgoc)
-                  zaggdoc2 = zaggtmp * 0.3 * trb(ji,jj,jk,jpdoc)
-                  zaggdon2 = zaggtmp * 0.3 * trb(ji,jj,jk,jpdon)
-                  zaggdop2 = zaggtmp * 0.3 * trb(ji,jj,jk,jpdop)
+            ! Aggregation of DOC to POC : 
+            ! 1st term is shear aggregation of DOC-DOC
+            ! 2nd term is shear aggregation of DOC-POC
+            ! 3rd term is differential settling of DOC-POC
+            zaggtmp = ( ( 0.369 * 0.3 * tr(ji,jj,jk,jpdoc,Kbb) + 102.4 * tr(ji,jj,jk,jppoc,Kbb) ) * zfact       &
+            &            + 2.4 * xstep * tr(ji,jj,jk,jppoc,Kbb) )
+            zaggdoc  = zaggtmp * 0.3 * tr(ji,jj,jk,jpdoc,Kbb)
+            zaggdon  = zaggtmp * 0.3 * tr(ji,jj,jk,jpdon,Kbb)
+            zaggdop  = zaggtmp * 0.3 * tr(ji,jj,jk,jpdop,Kbb)
 
-                  ! tranfer of DOC to POC due to brownian motion
-                  zaggtmp = ( 114. * 0.3 * trb(ji,jj,jk,jpdoc) ) * xstep
-                  zaggdoc3 =  zaggtmp * 0.3 * trb(ji,jj,jk,jpdoc)
-                  zaggdon3 =  zaggtmp * 0.3 * trb(ji,jj,jk,jpdon)
-                  zaggdop3 =  zaggtmp * 0.3 * trb(ji,jj,jk,jpdop)
+            ! transfer of DOC to GOC : 
+            ! 1st term is shear aggregation
+            ! 2nd term is differential settling 
+            zaggtmp = ( 3.53E3 * zfact + 0.1 * xstep ) * tr(ji,jj,jk,jpgoc,Kbb)
+            zaggdoc2 = zaggtmp * 0.3 * tr(ji,jj,jk,jpdoc,Kbb)
+            zaggdon2 = zaggtmp * 0.3 * tr(ji,jj,jk,jpdon,Kbb)
+            zaggdop2 = zaggtmp * 0.3 * tr(ji,jj,jk,jpdop,Kbb)
 
-                  !  Update the trends
-                  tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) - zaggpoc + zaggdoc + zaggdoc3
-                  tra(ji,jj,jk,jppon) = tra(ji,jj,jk,jppon) - zaggpon + zaggdon + zaggdon3
-                  tra(ji,jj,jk,jppop) = tra(ji,jj,jk,jppop) - zaggpop + zaggdop + zaggdop3
-                  tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) + zaggpoc + zaggdoc2
-                  tra(ji,jj,jk,jpgon) = tra(ji,jj,jk,jpgon) + zaggpon + zaggdon2
-                  tra(ji,jj,jk,jpgop) = tra(ji,jj,jk,jpgop) + zaggpop + zaggdop2
-                  tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) - zaggfe
-                  tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + zaggfe
-                  tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) - zaggdoc - zaggdoc2 - zaggdoc3
-                  tra(ji,jj,jk,jpdon) = tra(ji,jj,jk,jpdon) - zaggdon - zaggdon2 - zaggdon3
-                  tra(ji,jj,jk,jpdop) = tra(ji,jj,jk,jpdop) - zaggdop - zaggdop2 - zaggdop3
-                  !
-                  conspoc(ji,jj,jk) = conspoc(ji,jj,jk) - zaggpoc + zaggdoc + zaggdoc3
-                  prodgoc(ji,jj,jk) = prodgoc(ji,jj,jk) + zaggpoc + zaggdoc2
-                  !
-               END DO
-            END DO
-         END DO
+            ! tranfer of DOC to POC due to brownian motion
+            zaggtmp = ( 114. * 0.3 * tr(ji,jj,jk,jpdoc,Kbb) ) * xstep
+            zaggdoc3 =  zaggtmp * 0.3 * tr(ji,jj,jk,jpdoc,Kbb)
+            zaggdon3 =  zaggtmp * 0.3 * tr(ji,jj,jk,jpdon,Kbb)
+            zaggdop3 =  zaggtmp * 0.3 * tr(ji,jj,jk,jpdop,Kbb)
+
+            !  Update the trends
+            tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) - zaggpoc + zaggdoc + zaggdoc3
+            tr(ji,jj,jk,jppon,Krhs) = tr(ji,jj,jk,jppon,Krhs) - zaggpon + zaggdon + zaggdon3
+            tr(ji,jj,jk,jppop,Krhs) = tr(ji,jj,jk,jppop,Krhs) - zaggpop + zaggdop + zaggdop3
+            tr(ji,jj,jk,jpgoc,Krhs) = tr(ji,jj,jk,jpgoc,Krhs) + zaggpoc + zaggdoc2
+            tr(ji,jj,jk,jpgon,Krhs) = tr(ji,jj,jk,jpgon,Krhs) + zaggpon + zaggdon2
+            tr(ji,jj,jk,jpgop,Krhs) = tr(ji,jj,jk,jpgop,Krhs) + zaggpop + zaggdop2
+            tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) - zaggfe
+            tr(ji,jj,jk,jpbfe,Krhs) = tr(ji,jj,jk,jpbfe,Krhs) + zaggfe
+            tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) - zaggdoc - zaggdoc2 - zaggdoc3
+            tr(ji,jj,jk,jpdon,Krhs) = tr(ji,jj,jk,jpdon,Krhs) - zaggdon - zaggdon2 - zaggdon3
+            tr(ji,jj,jk,jpdop,Krhs) = tr(ji,jj,jk,jpdop,Krhs) - zaggdop - zaggdop2 - zaggdop3
+            !
+            conspoc(ji,jj,jk) = conspoc(ji,jj,jk) - zaggpoc + zaggdoc + zaggdoc3
+            prodgoc(ji,jj,jk) = prodgoc(ji,jj,jk) + zaggpoc + zaggdoc2
+            !
+         END_3D
          !
       ENDIF
       !
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('agg')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zbc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zbc.F90	(revision 13463)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zbc.F90	(revision 13463)
@@ -0,0 +1,350 @@
+MODULE p4zbc
+   !!======================================================================
+   !!                         ***  MODULE p4sbc  ***
+   !! TOP :   PISCES surface boundary conditions of external inputs of nutrients
+   !!======================================================================
+   !! History :   3.5  !  2012-07 (O. Aumont, C. Ethe) Original code
+   !!----------------------------------------------------------------------
+   !!   p4z_bc        :  Read and interpolate time-varying nutrients fluxes
+   !!   p4z_bc_init   :  Initialization of p4z_bc
+   !!----------------------------------------------------------------------
+   USE oce_trc         !  shared variables between ocean and passive tracers
+   USE trc             !  passive tracers common variables 
+   USE sms_pisces      !  PISCES Source Minus Sink variables
+   USE iom             !  I/O manager
+   USE fldread         !  time interpolation
+   USE trcbc
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_bc
+   PUBLIC   p4z_bc_init   
+
+   LOGICAL , PUBLIC ::   ln_ironsed   !: boolean for Fe input from sediments
+   LOGICAL , PUBLIC ::   ln_hydrofe   !: boolean for Fe input from hydrothermal vents
+   REAL(wp), PUBLIC ::   sedfeinput   !: Coastal release of Iron
+   REAL(wp), PUBLIC ::   icefeinput   !: Iron concentration in sea ice
+   REAL(wp), PUBLIC ::   wdust        !: Sinking speed of the dust 
+   REAL(wp), PUBLIC ::   mfrac        !: Mineral Content of the dust
+   REAL(wp)         ::   hratio       !: Fe:3He ratio assumed for vent iron supply
+   REAL(wp)         ::   distcoast    !: Distance off the coast for Iron from sediments
+   REAL(wp), PUBLIC ::   lgw_rath     !: Weak ligand ratio from hydro sources
+
+   LOGICAL , PUBLIC ::   ll_bc
+   LOGICAL , PUBLIC ::   ll_dust      !: boolean for dust input from the atmosphere
+   LOGICAL , PUBLIC ::   ll_river     !: boolean for river input of nutrients
+   LOGICAL , PUBLIC ::   ll_ndepo     !: boolean for atmospheric deposition of N
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_dust      ! structure of input dust
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_ironsed   ! structure of input iron from sediment
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_hydrofe   ! structure of input iron from sediment
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   dust    !: dust fields
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ironsed          !: Coastal supply of iron
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hydrofe          !: Hydrothermal vent supply of iron
+
+   REAL(wp), PUBLIC :: sedsilfrac, sedcalfrac
+
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
+   !! $Id: p4zbc.F90 10869 2019-04-15 10:34:03Z cetlod $ 
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE p4z_bc( kt, Kbb, Kmm, Krhs )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine p4z_bc  ***
+      !!
+      !! ** purpose :   read and interpolate the external sources of nutrients
+      !!
+      !! ** method  :   read the files and interpolate the appropriate variables
+      !!
+      !! ** input   :   external netcdf files
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt              ! ocean time step
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Krhs  ! time level index
+      !
+      INTEGER  ::  ji, jj, jk, jl 
+      REAL(wp) ::  zcoef, zyyss
+      REAL(wp) ::  zdep, ztrfer, zwdust, zwflux, zrivdin
+      !
+      CHARACTER (len=25) :: charout
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: zirondep
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:  ) :: zironice, zndep
+      !!---------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('p4z_bc')
+      !
+      IF( ll_dust )  THEN
+         ALLOCATE(  zirondep(jpi,jpj,jpk) )
+         !
+         CALL fld_read( kt, 1, sf_dust )
+         dust(:,:) = MAX( rtrn, sf_dust(1)%fnow(:,:,1) )
+         !
+         jl = n_trc_indsbc(jpfer)
+         zirondep(:,:,1) = rf_trsfac(jl) * sf_trcsbc(jl)%fnow(:,:,1) / e3t(:,:,1,Kmm) / rn_sbc_time
+         !                                              ! Iron solubilization of particles in the water column
+         !                                              ! dust in kg/m2/s ---> 1/55.85 to put in mol/Fe ;  wdust in m/j
+         zwdust = 0.03 / ( wdust / rday ) / ( 270. * rday )
+         DO jk = 2, jpkm1
+            zirondep(:,:,jk) = ( mfrac * dust(:,:) * zwdust / mMass_Fe ) * rfact * EXP( -gdept(:,:,jk,Kmm) / 540. )
+            tr(:,:,jk,jpfer,Krhs) = tr(:,:,jk,jpfer,Krhs) + zirondep(:,:,jk)
+            tr(:,:,jk,jppo4,Krhs) = tr(:,:,jk,jppo4,Krhs) + zirondep(:,:,jk) * 0.023
+         ENDDO
+         !
+         IF( lk_iomput ) THEN
+             CALL iom_put( "Irondep", zirondep(:,:,1) * 1.e+3 * rfactr * e3t(:,:,1,Kmm) * tmask(:,:,1) ) ! surface downward dust depo of iron
+             CALL iom_put( "pdust"  , dust(:,:) / ( wdust * rday ) * tmask(:,:,1) ) ! dust concentration at surface
+         ENDIF
+         DEALLOCATE( zirondep )
+      ENDIF
+
+      ! N/P and Si releases due to coastal rivers
+      ! Compute river at nit000 or only if there is more than 1 time record in river file
+      ! -----------------------------------------
+            ! Add the external input of nutrients from river
+      ! ----------------------------------------------------------
+      IF( ll_river ) THEN
+          jl = n_trc_indcbc(jpno3)
+          DO_2D( 1, 1, 1, 1 )
+             DO jk = 1, nk_rnf(ji,jj)
+                zcoef = rn_rfact / ( e1e2t(ji,jj) * h_rnf(ji,jj) * rn_cbc_time ) * tmask(ji,jj,1)
+                zrivdin = rf_trcfac(jl) * sf_trccbc(jl)%fnow(ji,jj,1) * zcoef
+                tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) - rno3 * zrivdin * rfact
+            ENDDO
+          END_2D
+      ENDIF
+      
+      ! Add the external input of nutrients from nitrogen deposition
+      ! ----------------------------------------------------------
+      IF( ll_ndepo ) THEN
+         ALLOCATE( zndep(jpi,jpj) )
+         IF( ln_trc_sbc(jpno3) ) THEN
+            jl = n_trc_indsbc(jpno3)
+            zndep(:,:) = rf_trsfac(jl) * sf_trcsbc(jl)%fnow(:,:,1) / e3t(:,:,1,Kmm) / rn_sbc_time
+            tr(:,:,1,jptal,Krhs) = tr(:,:,1,jptal,Krhs) - rno3 * zndep(:,:) * rfact
+         ENDIF
+         IF( ln_trc_sbc(jpnh4) ) THEN
+            jl = n_trc_indsbc(jpnh4)
+            zndep(:,:) = rf_trsfac(jl) * sf_trcsbc(jl)%fnow(:,:,1) / e3t(:,:,1,Kmm) / rn_sbc_time
+            tr(:,:,1,jptal,Krhs) = tr(:,:,1,jptal,Krhs) - rno3 * zndep(:,:) * rfact
+         ENDIF
+         DEALLOCATE( zndep )
+      ENDIF
+      !
+      ! Iron input/uptake due to sea ice : Crude parameterization based on
+      ! Lancelot et al.
+      ! ----------------------------------------------------
+      IF( ln_ironice ) THEN
+         !
+         ALLOCATE( zironice(jpi,jpj) )
+         !
+         DO_2D( 1, 1, 1, 1 )
+            zdep    = rfact / e3t(ji,jj,1,Kmm)
+            zwflux  = fmmflx(ji,jj) / 1000._wp
+            zironice(ji,jj) =  MAX( -0.99 * tr(ji,jj,1,jpfer,Kbb), -zwflux * icefeinput * zdep )
+         END_2D
+         !
+         tr(:,:,1,jpfer,Krhs) = tr(:,:,1,jpfer,Krhs) + zironice(:,:)
+         !
+         IF( lk_iomput )  CALL iom_put( "Ironice", zironice(:,:) * 1.e+3 * rfactr * e3t(:,:,1,Kmm) * tmask(:,:,1) ) ! iron flux from ice
+         !
+         DEALLOCATE( zironice )
+         !
+      ENDIF
+
+      ! Add the external input of iron from sediment mobilization
+      ! ------------------------------------------------------
+      IF( ln_ironsed .AND. .NOT.lk_sed ) THEN
+          tr(:,:,:,jpfer,Krhs) = tr(:,:,:,jpfer,Krhs) + ironsed(:,:,:) * rfact
+          !
+          IF( lk_iomput )  CALL iom_put( "Ironsed", ironsed(:,:,:) * 1.e+3 * tmask(:,:,:) ) 
+      ENDIF
+
+      ! Add the external input of iron from hydrothermal vents
+      ! ------------------------------------------------------
+      IF( ln_hydrofe ) THEN
+         CALL fld_read( kt, 1, sf_hydrofe )
+         DO jk = 1, jpk
+            hydrofe(:,:,jk) = ( MAX( rtrn, sf_hydrofe(1)%fnow(:,:,jk) ) * hratio ) &
+              &              / ( e1e2t(:,:) * e3t(:,:,jk,Kmm) * ryyss + rtrn ) / 1000._wp &
+              &              * tmask(:,:,jk)
+         ENDDO
+                         tr(:,:,:,jpfer,Krhs) = tr(:,:,:,jpfer,Krhs) + hydrofe(:,:,:) * rfact
+         IF( ln_ligand ) tr(:,:,:,jplgw,Krhs) = tr(:,:,:,jplgw,Krhs) + ( hydrofe(:,:,:) * lgw_rath ) * rfact
+         !
+         IF( lk_iomput ) CALL iom_put( "HYDR", hydrofe(:,:,:) * 1.e+3 * tmask(:,:,:) ) ! hydrothermal iron input
+      ENDIF
+      IF( ln_timing )  CALL timing_stop('p4z_bc')
+      !
+   END SUBROUTINE p4z_bc
+
+
+   SUBROUTINE p4z_bc_init( Kmm ) 
+      !!----------------------------------------------------------------------
+      !!                  ***  routine p4z_bc_init  ***
+      !!
+      !! ** purpose :   initialization of the external sources of nutrients
+      !!
+      !! ** method  :   read the files and compute the budget
+      !!                called at the first timestep (nittrc000)
+      !!
+      !! ** input   :   external netcdf files
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   Kmm  ! time level index
+      INTEGER  :: ji, jj, jk, jm
+      INTEGER  :: ii0, ii1, ij0, ij1
+      INTEGER  :: numiron
+      INTEGER  :: ierr, ierr1, ierr2, ierr3
+      INTEGER  :: ios                 ! Local integer output status for namelist read
+      INTEGER  :: ik50                !  last level where depth less than 50 m
+      REAL(wp) :: zexpide, zdenitide, zmaskt, zsurfc, zsurfp,ze3t, ze3t2, zcslp
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zriver, zcmask
+      !
+      CHARACTER(len=100) ::  cn_dir          ! Root directory for location of ssr files
+      TYPE(FLD_N) ::   sn_dust, sn_ironsed, sn_hydrofe   ! informations about the fields to be read
+      !!
+      NAMELIST/nampisbc/cn_dir, sn_dust, sn_ironsed, sn_hydrofe, &
+        &                ln_ironsed, ln_ironice, ln_hydrofe,    &
+        &                sedfeinput, distcoast, icefeinput, wdust, mfrac,  &
+        &                hratio, lgw_rath
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'p4z_bc_init : initialization of the external sources of nutrients '
+         WRITE(numout,*) '~~~~~~~~~~~~ '
+      ENDIF
+      !                            !* set file information
+      READ  ( numnatp_ref, nampisbc, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisbc in reference namelist' )
+      READ  ( numnatp_cfg, nampisbc, IOSTAT = ios, ERR = 902 )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisbc in configuration namelist' )
+      IF(lwm) WRITE ( numonp, nampisbc )
+
+
+      IF(lwp) THEN
+         WRITE(numout,*) '   Namelist : nampissbc '
+         WRITE(numout,*) '      Fe input from sediments                  ln_ironsed  = ', ln_ironsed
+         WRITE(numout,*) '      Fe input from seaice                     ln_ironice  = ', ln_ironice
+         WRITE(numout,*) '      fe input from hydrothermal vents         ln_hydrofe  = ', ln_hydrofe
+         IF( ln_ironsed ) THEN
+            WRITE(numout,*) '      coastal release of iron                  sedfeinput  = ', sedfeinput
+            WRITE(numout,*) '      distance off the coast                   distcoast   = ', distcoast
+         ENDIF
+         IF( ln_ligand ) THEN
+            WRITE(numout,*) '      Weak ligand ratio from sed hydro sources  lgw_rath   = ', lgw_rath
+         ENDIF
+         IF( ln_ironice ) THEN
+            WRITE(numout,*) '      Iron concentration in sea ice            icefeinput  = ', icefeinput
+         ENDIF
+         IF( ln_trc_sbc(jpfer) ) THEN
+            WRITE(numout,*) '      Mineral Fe content of the dust           mfrac       = ', mfrac
+            WRITE(numout,*) '      sinking speed of the dust                wdust       = ', wdust
+         ENDIF
+         IF( ln_hydrofe ) THEN
+            WRITE(numout,*) '      Fe to 3He ratio assumed for vent iron supply hratio  = ', hratio
+         ENDIF
+      END IF
+
+      ll_bc    = ( ln_trcbc .AND. lltrcbc )  .OR. ln_hydrofe .OR. ln_ironsed .OR. ln_ironice
+      ll_dust  =  ln_trc_sbc(jpfer)   
+      ll_ndepo =  ln_trc_sbc(jpno3) .OR. ln_trc_sbc(jpnh4)   
+      ll_river =  ln_trc_cbc(jpno3)  
+
+      ! dust input from the atmosphere
+      ! ------------------------------
+      IF( ll_dust ) THEN
+         !
+         IF(lwp) WRITE(numout,*) '    initialize dust input from atmosphere '
+         IF(lwp) WRITE(numout,*) '    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+         !
+         ALLOCATE( dust(jpi,jpj) ) 
+         !
+         ALLOCATE( sf_dust(1), STAT=ierr )           !* allocate and fill sf_sst (forcing structure) with sn_sst
+         IF( ierr > 0 )   CALL ctl_stop( 'STOP', 'p4z_sed_init: unable to allocate sf_dust structure' )
+         !
+         CALL fld_fill( sf_dust, (/ sn_dust /), cn_dir, 'p4z_sed_init', 'Atmospheric dust deposition', 'nampissed' )
+                                   ALLOCATE( sf_dust(1)%fnow(jpi,jpj,1)   )
+         IF( sn_dust%ln_tint )     ALLOCATE( sf_dust(1)%fdta(jpi,jpj,1,2) )
+         !
+      END IF
+
+      ! coastal and island masks
+      ! ------------------------
+      IF( ln_ironsed ) THEN     
+         !
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '   ==>>>   ln_ironsed=T , computation of an island mask to enhance coastal supply of iron'
+         !
+         ALLOCATE( ironsed(jpi,jpj,jpk) )    ! allocation
+         !
+         CALL iom_open ( TRIM( sn_ironsed%clname ), numiron )
+         ALLOCATE( zcmask(jpi,jpj,jpk) )
+         CALL iom_get  ( numiron, jpdom_global, TRIM( sn_ironsed%clvar ), zcmask(:,:,:), 1 )
+         CALL iom_close( numiron )
+         !
+         ik50 = 5        !  last level where depth less than 50 m
+         DO jk = jpkm1, 1, -1
+            IF( gdept_1d(jk) > 50. )   ik50 = jk - 1
+         END DO
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' Level corresponding to 50m depth ',  ik50,' ', gdept_1d(ik50+1)
+         DO_3D( 0, 0, 0, 0, 1, ik50 )
+            ze3t   = e3t_0(ji,jj,jk)
+            zsurfc =  e1u(ji,jj) * ( 1. - umask(ji  ,jj  ,jk) )   &
+                    + e1u(ji,jj) * ( 1. - umask(ji-1,jj  ,jk) )   &
+                    + e2v(ji,jj) * ( 1. - vmask(ji  ,jj  ,jk) )   &
+                    + e2v(ji,jj) * ( 1. - vmask(ji  ,jj-1,jk) )
+            zsurfp = zsurfc * ze3t / e1e2t(ji,jj)
+            ! estimation of the coastal slope : 5 km off the coast
+            ze3t2 = ze3t * ze3t
+            zcslp = SQRT( ( distcoast*distcoast + ze3t2 ) / ze3t2 )
+            !
+            zcmask(ji,jj,jk) = zcmask(ji,jj,jk) + zcslp * zsurfp
+         END_3D
+         !
+         CALL lbc_lnk( 'p4zbc', zcmask , 'T', 1.0_wp )      ! lateral boundary conditions on cmask   (sign unchanged)
+         !
+         DO_3D( 1, 1, 1, 1, 1, jpk )
+            zexpide   = MIN( 8.,( gdept(ji,jj,jk,Kmm) / 500. )**(-1.5) )
+            zdenitide = -0.9543 + 0.7662 * LOG( zexpide ) - 0.235 * LOG( zexpide )**2
+            zcmask(ji,jj,jk) = zcmask(ji,jj,jk) * MIN( 1., EXP( zdenitide ) / 0.5 )
+         END_3D
+         ! Coastal supply of iron
+         ! -------------------------
+         ironsed(:,:,jpk) = 0._wp
+         DO jk = 1, jpkm1
+            ironsed(:,:,jk) = sedfeinput * zcmask(:,:,jk) / ( e3t_0(:,:,jk) * rday )
+         END DO
+         DEALLOCATE( zcmask)
+      ENDIF
+      !
+      ! Iron from Hydrothermal vents
+      ! ------------------------
+      IF( ln_hydrofe ) THEN
+         !
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '   ==>>>   ln_hydrofe=T , Input of iron from hydrothermal vents'
+         !
+         ALLOCATE( hydrofe(jpi,jpj,jpk) )    ! allocation
+         !
+         ALLOCATE( sf_hydrofe(1), STAT=ierr )           !* allocate and fill sf_sst (forcing structure) with sn_sst
+         IF( ierr > 0 )   CALL ctl_stop( 'STOP', 'p4z_sed_init: unable to allocate sf_hydro structure' )
+         !
+         CALL fld_fill( sf_hydrofe, (/ sn_hydrofe /), cn_dir, 'p4z_sed_init', 'Input of iron from hydrothermal vents', 'nampisbc' )
+                                   ALLOCATE( sf_hydrofe(1)%fnow(jpi,jpj,jpk)   )
+         IF( sn_hydrofe%ln_tint )    ALLOCATE( sf_hydrofe(1)%fdta(jpi,jpj,jpk,2) )
+         !
+      ENDIF
+      !
+   END SUBROUTINE p4z_bc_init
+
+   !!======================================================================
+END MODULE p4zbc
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zbio.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zbio.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zbio.F90	(revision 13463)
@@ -30,5 +30,5 @@
    USE p4zfechem
    USE p4zligand       !  Prognostic ligand model
-   USE prtctl_trc      !  print control for debugging
+   USE prtctl          !  print control for debugging
    USE iom             !  I/O manager
   
@@ -38,4 +38,7 @@
    PUBLIC  p4z_bio    
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -45,5 +48,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_bio ( kt, knt )
+   SUBROUTINE p4z_bio ( kt, knt, Kbb, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_bio  ***
@@ -56,4 +59,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) :: kt, knt
+      INTEGER, INTENT(in) :: Kbb, Kmm, Krhs  ! time level indices
       !
       INTEGER             :: ji, jj, jk, jn
@@ -68,46 +72,42 @@
       xdiss(:,:,:) = 1.
 !!gm the use of nmld should be better here?
-      DO jk = 2, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
+      DO_3D( 1, 1, 1, 1, 2, jpkm1 )
 !!gm  :  use nmln  and test on jk ...  less memory acces
-               IF( gdepw_n(ji,jj,jk+1) > hmld(ji,jj) )   xdiss(ji,jj,jk) = 0.01
-            END DO 
-         END DO
-      END DO
+         IF( gdepw(ji,jj,jk+1,Kmm) > hmld(ji,jj) )   xdiss(ji,jj,jk) = 0.01
+      END_3D
 
-      CALL p4z_opt     ( kt, knt )     ! Optic: PAR in the water column
-      CALL p4z_sink    ( kt, knt )     ! vertical flux of particulate organic matter
-      CALL p4z_fechem  ( kt, knt )     ! Iron chemistry/scavenging
+      CALL p4z_opt     ( kt, knt, Kbb, Kmm       )     ! Optic: PAR in the water column
+      CALL p4z_sink    ( kt, knt, Kbb, Kmm, Krhs )     ! vertical flux of particulate organic matter
+      CALL p4z_fechem  ( kt, knt, Kbb, Kmm, Krhs )     ! Iron chemistry/scavenging
       !
       IF( ln_p4z ) THEN
-         CALL p4z_lim  ( kt, knt )     ! co-limitations by the various nutrients
-         CALL p4z_prod ( kt, knt )     ! phytoplankton growth rate over the global ocean. 
-         !                             ! (for each element : C, Si, Fe, Chl )
-         CALL p4z_mort ( kt      )     ! phytoplankton mortality
-         !                             ! zooplankton sources/sinks routines 
-         CALL p4z_micro( kt, knt )           ! microzooplankton
-         CALL p4z_meso ( kt, knt )           ! mesozooplankton
+         CALL p4z_lim  ( kt, knt, Kbb, Kmm       )     ! co-limitations by the various nutrients
+         CALL p4z_prod ( kt, knt, Kbb, Kmm, Krhs )     ! phytoplankton growth rate over the global ocean. 
+         !                                          ! (for each element : C, Si, Fe, Chl )
+         CALL p4z_mort ( kt,      Kbb,      Krhs )     ! phytoplankton mortality
+         !                                          ! zooplankton sources/sinks routines 
+         CALL p4z_micro( kt, knt, Kbb,      Krhs )     ! microzooplankton
+         CALL p4z_meso ( kt, knt, Kbb,      Krhs )     ! mesozooplankton
       ELSE
-         CALL p5z_lim  ( kt, knt )     ! co-limitations by the various nutrients
-         CALL p5z_prod ( kt, knt )     ! phytoplankton growth rate over the global ocean. 
-         !                             ! (for each element : C, Si, Fe, Chl )
-         CALL p5z_mort ( kt      )     ! phytoplankton mortality
-         !                             ! zooplankton sources/sinks routines 
-         CALL p5z_micro( kt, knt )           ! microzooplankton
-         CALL p5z_meso ( kt, knt )           ! mesozooplankton
+         CALL p5z_lim  ( kt, knt, Kbb, Kmm       )     ! co-limitations by the various nutrients
+         CALL p5z_prod ( kt, knt, Kbb, Kmm, Krhs )     ! phytoplankton growth rate over the global ocean. 
+         !                                          ! (for each element : C, Si, Fe, Chl )
+         CALL p5z_mort ( kt,      Kbb,      Krhs      )     ! phytoplankton mortality
+         !                                          ! zooplankton sources/sinks routines 
+         CALL p5z_micro( kt, knt, Kbb,      Krhs )           ! microzooplankton
+         CALL p5z_meso ( kt, knt, Kbb,      Krhs )           ! mesozooplankton
       ENDIF
       !
-      CALL p4z_agg     ( kt, knt )     ! Aggregation of particles
-      CALL p4z_rem     ( kt, knt )     ! remineralization terms of organic matter+scavenging of Fe
-      CALL p4z_poc     ( kt, knt )     ! Remineralization of organic particles
+      CALL p4z_agg     ( kt, knt, Kbb,      Krhs )     ! Aggregation of particles
+      CALL p4z_rem     ( kt, knt, Kbb, Kmm, Krhs )     ! remineralization terms of organic matter+scavenging of Fe
+      CALL p4z_poc     ( kt, knt, Kbb, Kmm, Krhs )     ! Remineralization of organic particles
       !
       IF( ln_ligand )  &
-      & CALL p4z_ligand( kt, knt )
+      & CALL p4z_ligand( kt, knt, Kbb,      Krhs )
       !                                                             !
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('bio ')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zche.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zche.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zche.F90	(revision 13463)
@@ -130,4 +130,7 @@
    INTEGER :: niter_atgen    = jp_maxniter_atgen
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -137,5 +140,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_che
+   SUBROUTINE p4z_che( Kbb, Kmm )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_che  ***
@@ -145,4 +148,5 @@
       !! ** Method  : - ...
       !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kbb, Kmm  ! time level indices
       INTEGER  ::   ji, jj, jk
       REAL(wp) ::   ztkel, ztkel1, zt , zsal  , zsal2 , zbuf1 , zbuf2
@@ -164,7 +168,7 @@
       ! -------------------------------------------------------------
       IF (neos == -1) THEN
-         salinprac(:,:,:) = tsn(:,:,:,jp_sal) * 35.0 / 35.16504
+         salinprac(:,:,:) = ts(:,:,:,jp_sal,Kmm) * 35.0 / 35.16504
       ELSE
-         salinprac(:,:,:) = tsn(:,:,:,jp_sal)
+         salinprac(:,:,:) = ts(:,:,:,jp_sal,Kmm)
       ENDIF
 
@@ -175,14 +179,10 @@
       ! 0.04°C relative to an exact computation
       ! ---------------------------------------------------------------------
-      DO jk = 1, jpk
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zpres = gdept_n(ji,jj,jk) / 1000.
-               za1 = 0.04 * ( 1.0 + 0.185 * tsn(ji,jj,jk,jp_tem) + 0.035 * (salinprac(ji,jj,jk) - 35.0) )
-               za2 = 0.0075 * ( 1.0 - tsn(ji,jj,jk,jp_tem) / 30.0 )
-               tempis(ji,jj,jk) = tsn(ji,jj,jk,jp_tem) - za1 * zpres + za2 * zpres**2
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpk )
+         zpres = gdept(ji,jj,jk,Kmm) / 1000.
+         za1 = 0.04 * ( 1.0 + 0.185 * ts(ji,jj,jk,jp_tem,Kmm) + 0.035 * (salinprac(ji,jj,jk) - 35.0) )
+         za2 = 0.0075 * ( 1.0 - ts(ji,jj,jk,jp_tem,Kmm) / 30.0 )
+         tempis(ji,jj,jk) = ts(ji,jj,jk,jp_tem,Kmm) - za1 * zpres + za2 * zpres**2
+      END_3D
       !
       ! CHEMICAL CONSTANTS - SURFACE LAYER
@@ -245,5 +245,5 @@
                zplat   = SIN ( ABS(gphit(ji,jj)*3.141592654/180.) )
                zc1 = 5.92E-3 + zplat**2 * 5.25E-3
-               zpres = ((1-zc1)-SQRT(((1-zc1)**2)-(8.84E-6*gdept_n(ji,jj,jk)))) / 4.42E-6
+               zpres = ((1-zc1)-SQRT(((1-zc1)**2)-(8.84E-6*gdept(ji,jj,jk,Kmm)))) / 4.42E-6
                zpres = zpres / 10.0
 
@@ -448,5 +448,5 @@
    END SUBROUTINE p4z_che
 
-   SUBROUTINE ahini_for_at(p_hini)
+   SUBROUTINE ahini_for_at(p_hini, Kbb )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE ahini_for_at  ***
@@ -462,4 +462,5 @@
       !!---------------------------------------------------------------------
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(OUT)  ::  p_hini
+      INTEGER,                          INTENT(in)   ::  Kbb      ! time level indices
       INTEGER  ::   ji, jj, jk
       REAL(wp)  ::  zca1, zba1
@@ -471,42 +472,38 @@
       IF( ln_timing )  CALL timing_start('ahini_for_at')
       !
-      DO jk = 1, jpk
-        DO jj = 1, jpj
-          DO ji = 1, jpi
-            p_alkcb  = trb(ji,jj,jk,jptal) * 1000. / (rhop(ji,jj,jk) + rtrn)
-            p_dictot = trb(ji,jj,jk,jpdic) * 1000. / (rhop(ji,jj,jk) + rtrn)
-            p_bortot = borat(ji,jj,jk)
-            IF (p_alkcb <= 0.) THEN
-                p_hini(ji,jj,jk) = 1.e-3
-            ELSEIF (p_alkcb >= (2.*p_dictot + p_bortot)) THEN
-                p_hini(ji,jj,jk) = 1.e-10_wp
+      DO_3D( 1, 1, 1, 1, 1, jpk )
+      p_alkcb  = tr(ji,jj,jk,jptal,Kbb) * 1000. / (rhop(ji,jj,jk) + rtrn)
+      p_dictot = tr(ji,jj,jk,jpdic,Kbb) * 1000. / (rhop(ji,jj,jk) + rtrn)
+      p_bortot = borat(ji,jj,jk)
+      IF (p_alkcb <= 0.) THEN
+          p_hini(ji,jj,jk) = 1.e-3
+      ELSEIF (p_alkcb >= (2.*p_dictot + p_bortot)) THEN
+          p_hini(ji,jj,jk) = 1.e-10_wp
+      ELSE
+          zca1 = p_dictot/( p_alkcb + rtrn )
+          zba1 = p_bortot/ (p_alkcb + rtrn )
+     ! Coefficients of the cubic polynomial
+          za2 = aKb3(ji,jj,jk)*(1. - zba1) + ak13(ji,jj,jk)*(1.-zca1)
+          za1 = ak13(ji,jj,jk)*akb3(ji,jj,jk)*(1. - zba1 - zca1)    &
+          &     + ak13(ji,jj,jk)*ak23(ji,jj,jk)*(1. - (zca1+zca1))
+          za0 = ak13(ji,jj,jk)*ak23(ji,jj,jk)*akb3(ji,jj,jk)*(1. - zba1 - (zca1+zca1))
+                                  ! Taylor expansion around the minimum
+          zd = za2*za2 - 3.*za1   ! Discriminant of the quadratic equation
+                                  ! for the minimum close to the root
+
+          IF(zd > 0.) THEN        ! If the discriminant is positive
+            zsqrtd = SQRT(zd)
+            IF(za2 < 0) THEN
+              zhmin = (-za2 + zsqrtd)/3.
             ELSE
-                zca1 = p_dictot/( p_alkcb + rtrn )
-                zba1 = p_bortot/ (p_alkcb + rtrn )
-           ! Coefficients of the cubic polynomial
-                za2 = aKb3(ji,jj,jk)*(1. - zba1) + ak13(ji,jj,jk)*(1.-zca1)
-                za1 = ak13(ji,jj,jk)*akb3(ji,jj,jk)*(1. - zba1 - zca1)    &
-                &     + ak13(ji,jj,jk)*ak23(ji,jj,jk)*(1. - (zca1+zca1))
-                za0 = ak13(ji,jj,jk)*ak23(ji,jj,jk)*akb3(ji,jj,jk)*(1. - zba1 - (zca1+zca1))
-                                        ! Taylor expansion around the minimum
-                zd = za2*za2 - 3.*za1   ! Discriminant of the quadratic equation
-                                        ! for the minimum close to the root
-
-                IF(zd > 0.) THEN        ! If the discriminant is positive
-                  zsqrtd = SQRT(zd)
-                  IF(za2 < 0) THEN
-                    zhmin = (-za2 + zsqrtd)/3.
-                  ELSE
-                    zhmin = -za1/(za2 + zsqrtd)
-                  ENDIF
-                  p_hini(ji,jj,jk) = zhmin + SQRT(-(za0 + zhmin*(za1 + zhmin*(za2 + zhmin)))/zsqrtd)
-                ELSE
-                  p_hini(ji,jj,jk) = 1.e-7
-                ENDIF
-             !
-             ENDIF
-          END DO
-        END DO
-      END DO
+              zhmin = -za1/(za2 + zsqrtd)
+            ENDIF
+            p_hini(ji,jj,jk) = zhmin + SQRT(-(za0 + zhmin*(za1 + zhmin*(za2 + zhmin)))/zsqrtd)
+          ELSE
+            p_hini(ji,jj,jk) = 1.e-7
+          ENDIF
+       !
+       ENDIF
+      END_3D
       !
       IF( ln_timing )  CALL timing_stop('ahini_for_at')
@@ -516,5 +513,5 @@
    !===============================================================================
 
-   SUBROUTINE anw_infsup( p_alknw_inf, p_alknw_sup )
+   SUBROUTINE anw_infsup( p_alknw_inf, p_alknw_sup, Kbb )
 
    ! Subroutine returns the lower and upper bounds of "non-water-selfionization"
@@ -525,8 +522,9 @@
    REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(OUT) :: p_alknw_inf
    REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(OUT) :: p_alknw_sup
-
-   p_alknw_inf(:,:,:) =  -trb(:,:,:,jppo4) * 1000. / (rhop(:,:,:) + rtrn) - sulfat(:,:,:)  &
+   INTEGER,                          INTENT(in)  ::  Kbb      ! time level indices
+
+   p_alknw_inf(:,:,:) =  -tr(:,:,:,jppo4,Kbb) * 1000. / (rhop(:,:,:) + rtrn) - sulfat(:,:,:)  &
    &              - fluorid(:,:,:)
-   p_alknw_sup(:,:,:) =   (2. * trb(:,:,:,jpdic) + 2. * trb(:,:,:,jppo4) + trb(:,:,:,jpsil) )    &
+   p_alknw_sup(:,:,:) =   (2. * tr(:,:,:,jpdic,Kbb) + 2. * tr(:,:,:,jppo4,Kbb) + tr(:,:,:,jpsil,Kbb) )    &
    &               * 1000. / (rhop(:,:,:) + rtrn) + borat(:,:,:) 
 
@@ -534,5 +532,5 @@
 
 
-   SUBROUTINE solve_at_general( p_hini, zhi )
+   SUBROUTINE solve_at_general( p_hini, zhi, Kbb )
 
    ! Universal pH solver that converges from any given initial value,
@@ -543,4 +541,5 @@
    REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(IN)   :: p_hini
    REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(OUT)  :: zhi
+   INTEGER,                          INTENT(in)   :: Kbb  ! time level indices
 
    ! Local variables
@@ -565,5 +564,5 @@
    IF( ln_timing )  CALL timing_start('solve_at_general')
 
-   CALL anw_infsup( zalknw_inf, zalknw_sup )
+   CALL anw_infsup( zalknw_inf, zalknw_sup, Kbb )
 
    rmask(:,:,:) = tmask(:,:,:)
@@ -571,224 +570,216 @@
 
    ! TOTAL H+ scale: conversion factor for Htot = aphscale * Hfree
-   DO jk = 1, jpk
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF (rmask(ji,jj,jk) == 1.) THEN
-               p_alktot = trb(ji,jj,jk,jptal) * 1000. / (rhop(ji,jj,jk) + rtrn)
-               aphscale = 1. + sulfat(ji,jj,jk)/aks3(ji,jj,jk)
-               zh_ini = p_hini(ji,jj,jk)
-
-               zdelta = (p_alktot-zalknw_inf(ji,jj,jk))**2 + 4.*akw3(ji,jj,jk)/aphscale
-
-               IF(p_alktot >= zalknw_inf(ji,jj,jk)) THEN
-                 zh_min(ji,jj,jk) = 2.*akw3(ji,jj,jk) /( p_alktot-zalknw_inf(ji,jj,jk) + SQRT(zdelta) )
-               ELSE
-                 zh_min(ji,jj,jk) = aphscale*(-(p_alktot-zalknw_inf(ji,jj,jk)) + SQRT(zdelta) ) / 2.
-               ENDIF
-
-               zdelta = (p_alktot-zalknw_sup(ji,jj,jk))**2 + 4.*akw3(ji,jj,jk)/aphscale
-
-               IF(p_alktot <= zalknw_sup(ji,jj,jk)) THEN
-                 zh_max(ji,jj,jk) = aphscale*(-(p_alktot-zalknw_sup(ji,jj,jk)) + SQRT(zdelta) ) / 2.
-               ELSE
-                 zh_max(ji,jj,jk) = 2.*akw3(ji,jj,jk) /( p_alktot-zalknw_sup(ji,jj,jk) + SQRT(zdelta) )
-               ENDIF
-
-               zhi(ji,jj,jk) = MAX(MIN(zh_max(ji,jj,jk), zh_ini), zh_min(ji,jj,jk))
+   DO_3D( 1, 1, 1, 1, 1, jpk )
+      IF (rmask(ji,jj,jk) == 1.) THEN
+         p_alktot = tr(ji,jj,jk,jptal,Kbb) * 1000. / (rhop(ji,jj,jk) + rtrn)
+         aphscale = 1. + sulfat(ji,jj,jk)/aks3(ji,jj,jk)
+         zh_ini = p_hini(ji,jj,jk)
+
+         zdelta = (p_alktot-zalknw_inf(ji,jj,jk))**2 + 4.*akw3(ji,jj,jk)/aphscale
+
+         IF(p_alktot >= zalknw_inf(ji,jj,jk)) THEN
+           zh_min(ji,jj,jk) = 2.*akw3(ji,jj,jk) /( p_alktot-zalknw_inf(ji,jj,jk) + SQRT(zdelta) )
+         ELSE
+           zh_min(ji,jj,jk) = aphscale*(-(p_alktot-zalknw_inf(ji,jj,jk)) + SQRT(zdelta) ) / 2.
+         ENDIF
+
+         zdelta = (p_alktot-zalknw_sup(ji,jj,jk))**2 + 4.*akw3(ji,jj,jk)/aphscale
+
+         IF(p_alktot <= zalknw_sup(ji,jj,jk)) THEN
+           zh_max(ji,jj,jk) = aphscale*(-(p_alktot-zalknw_sup(ji,jj,jk)) + SQRT(zdelta) ) / 2.
+         ELSE
+           zh_max(ji,jj,jk) = 2.*akw3(ji,jj,jk) /( p_alktot-zalknw_sup(ji,jj,jk) + SQRT(zdelta) )
+         ENDIF
+
+         zhi(ji,jj,jk) = MAX(MIN(zh_max(ji,jj,jk), zh_ini), zh_min(ji,jj,jk))
+      ENDIF
+   END_3D
+
+   zeqn_absmin(:,:,:) = HUGE(1._wp)
+
+   DO jn = 1, jp_maxniter_atgen 
+   DO_3D( 1, 1, 1, 1, 1, jpk )
+      IF (rmask(ji,jj,jk) == 1.) THEN
+         zfact = rhop(ji,jj,jk) / 1000. + rtrn
+         p_alktot = tr(ji,jj,jk,jptal,Kbb) / zfact
+         zdic  = tr(ji,jj,jk,jpdic,Kbb) / zfact
+         zbot  = borat(ji,jj,jk)
+         zpt = tr(ji,jj,jk,jppo4,Kbb) / zfact * po4r
+         zsit = tr(ji,jj,jk,jpsil,Kbb) / zfact
+         zst = sulfat (ji,jj,jk)
+         zft = fluorid(ji,jj,jk)
+         aphscale = 1. + sulfat(ji,jj,jk)/aks3(ji,jj,jk)
+         zh = zhi(ji,jj,jk)
+         zh_prev = zh
+
+         ! H2CO3 - HCO3 - CO3 : n=2, m=0
+         znumer_dic = 2.*ak13(ji,jj,jk)*ak23(ji,jj,jk) + zh*ak13(ji,jj,jk)
+         zdenom_dic = ak13(ji,jj,jk)*ak23(ji,jj,jk) + zh*(ak13(ji,jj,jk) + zh)
+         zalk_dic   = zdic * (znumer_dic/zdenom_dic)
+         zdnumer_dic = ak13(ji,jj,jk)*ak13(ji,jj,jk)*ak23(ji,jj,jk) + zh     &
+                       *(4.*ak13(ji,jj,jk)*ak23(ji,jj,jk) + zh*ak13(ji,jj,jk))
+         zdalk_dic   = -zdic*(zdnumer_dic/zdenom_dic**2)
+
+
+         ! B(OH)3 - B(OH)4 : n=1, m=0
+         znumer_bor = akb3(ji,jj,jk)
+         zdenom_bor = akb3(ji,jj,jk) + zh
+         zalk_bor   = zbot * (znumer_bor/zdenom_bor)
+         zdnumer_bor = akb3(ji,jj,jk)
+         zdalk_bor   = -zbot*(zdnumer_bor/zdenom_bor**2)
+
+
+         ! H3PO4 - H2PO4 - HPO4 - PO4 : n=3, m=1
+         znumer_po4 = 3.*ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk)*ak3p3(ji,jj,jk)  &
+         &            + zh*(2.*ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk) + zh* ak1p3(ji,jj,jk))
+         zdenom_po4 = ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk)*ak3p3(ji,jj,jk)     &
+         &            + zh*( ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk) + zh*(ak1p3(ji,jj,jk) + zh))
+         zalk_po4   = zpt * (znumer_po4/zdenom_po4 - 1.) ! Zero level of H3PO4 = 1
+         zdnumer_po4 = ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk)*ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk)*ak3p3(ji,jj,jk)  &
+         &             + zh*(4.*ak1p3(ji,jj,jk)*ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk)*ak3p3(ji,jj,jk)         &
+         &             + zh*(9.*ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk)*ak3p3(ji,jj,jk)                         &
+         &             + ak1p3(ji,jj,jk)*ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk)                                &
+         &             + zh*(4.*ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk) + zh * ak1p3(ji,jj,jk) ) ) )
+         zdalk_po4   = -zpt * (zdnumer_po4/zdenom_po4**2)
+
+         ! H4SiO4 - H3SiO4 : n=1, m=0
+         znumer_sil = aksi3(ji,jj,jk)
+         zdenom_sil = aksi3(ji,jj,jk) + zh
+         zalk_sil   = zsit * (znumer_sil/zdenom_sil)
+         zdnumer_sil = aksi3(ji,jj,jk)
+         zdalk_sil   = -zsit * (zdnumer_sil/zdenom_sil**2)
+
+         ! HSO4 - SO4 : n=1, m=1
+         aphscale = 1.0 + zst/aks3(ji,jj,jk)
+         znumer_so4 = aks3(ji,jj,jk) * aphscale
+         zdenom_so4 = aks3(ji,jj,jk) * aphscale + zh
+         zalk_so4   = zst * (znumer_so4/zdenom_so4 - 1.)
+         zdnumer_so4 = aks3(ji,jj,jk)
+         zdalk_so4   = -zst * (zdnumer_so4/zdenom_so4**2)
+
+         ! HF - F : n=1, m=1
+         znumer_flu =  akf3(ji,jj,jk)
+         zdenom_flu =  akf3(ji,jj,jk) + zh
+         zalk_flu   =  zft * (znumer_flu/zdenom_flu - 1.)
+         zdnumer_flu = akf3(ji,jj,jk)
+         zdalk_flu   = -zft * (zdnumer_flu/zdenom_flu**2)
+
+         ! H2O - OH
+         aphscale = 1.0 + zst/aks3(ji,jj,jk)
+         zalk_wat   = akw3(ji,jj,jk)/zh - zh/aphscale
+         zdalk_wat  = -akw3(ji,jj,jk)/zh**2 - 1./aphscale
+
+         ! CALCULATE [ALK]([CO3--], [HCO3-])
+         zeqn = zalk_dic + zalk_bor + zalk_po4 + zalk_sil   &
+         &      + zalk_so4 + zalk_flu                       &
+         &      + zalk_wat - p_alktot
+
+         zalka = p_alktot - (zalk_bor + zalk_po4 + zalk_sil   &
+         &       + zalk_so4 + zalk_flu + zalk_wat)
+
+         zdeqndh = zdalk_dic + zdalk_bor + zdalk_po4 + zdalk_sil &
+         &         + zdalk_so4 + zdalk_flu + zdalk_wat
+
+         ! Adapt bracketing interval
+         IF(zeqn > 0._wp) THEN
+           zh_min(ji,jj,jk) = zh_prev
+         ELSEIF(zeqn < 0._wp) THEN
+           zh_max(ji,jj,jk) = zh_prev
+         ENDIF
+
+         IF(ABS(zeqn) >= 0.5_wp*zeqn_absmin(ji,jj,jk)) THEN
+         ! if the function evaluation at the current point is
+         ! not decreasing faster than with a bisection step (at least linearly)
+         ! in absolute value take one bisection step on [ph_min, ph_max]
+         ! ph_new = (ph_min + ph_max)/2d0
+         !
+         ! In terms of [H]_new:
+         ! [H]_new = 10**(-ph_new)
+         !         = 10**(-(ph_min + ph_max)/2d0)
+         !         = SQRT(10**(-(ph_min + phmax)))
+         !         = SQRT(zh_max * zh_min)
+            zh = SQRT(zh_max(ji,jj,jk) * zh_min(ji,jj,jk))
+            zh_lnfactor = (zh - zh_prev)/zh_prev ! Required to test convergence below
+         ELSE
+         ! dzeqn/dpH = dzeqn/d[H] * d[H]/dpH
+         !           = -zdeqndh * LOG(10) * [H]
+         ! \Delta pH = -zeqn/(zdeqndh*d[H]/dpH) = zeqn/(zdeqndh*[H]*LOG(10))
+         !
+         ! pH_new = pH_old + \deltapH
+         !
+         ! [H]_new = 10**(-pH_new)
+         !         = 10**(-pH_old - \Delta pH)
+         !         = [H]_old * 10**(-zeqn/(zdeqndh*[H]_old*LOG(10)))
+         !         = [H]_old * EXP(-LOG(10)*zeqn/(zdeqndh*[H]_old*LOG(10)))
+         !         = [H]_old * EXP(-zeqn/(zdeqndh*[H]_old))
+
+            zh_lnfactor = -zeqn/(zdeqndh*zh_prev)
+
+            IF(ABS(zh_lnfactor) > pz_exp_threshold) THEN
+               zh          = zh_prev*EXP(zh_lnfactor)
+            ELSE
+               zh_delta    = zh_lnfactor*zh_prev
+               zh          = zh_prev + zh_delta
             ENDIF
-         END DO
-      END DO
-   END DO
-
-   zeqn_absmin(:,:,:) = HUGE(1._wp)
-
-   DO jn = 1, jp_maxniter_atgen 
-   DO jk = 1, jpk
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF (rmask(ji,jj,jk) == 1.) THEN
-               zfact = rhop(ji,jj,jk) / 1000. + rtrn
-               p_alktot = trb(ji,jj,jk,jptal) / zfact
-               zdic  = trb(ji,jj,jk,jpdic) / zfact
-               zbot  = borat(ji,jj,jk)
-               zpt = trb(ji,jj,jk,jppo4) / zfact * po4r
-               zsit = trb(ji,jj,jk,jpsil) / zfact
-               zst = sulfat (ji,jj,jk)
-               zft = fluorid(ji,jj,jk)
-               aphscale = 1. + sulfat(ji,jj,jk)/aks3(ji,jj,jk)
-               zh = zhi(ji,jj,jk)
-               zh_prev = zh
-
-               ! H2CO3 - HCO3 - CO3 : n=2, m=0
-               znumer_dic = 2.*ak13(ji,jj,jk)*ak23(ji,jj,jk) + zh*ak13(ji,jj,jk)
-               zdenom_dic = ak13(ji,jj,jk)*ak23(ji,jj,jk) + zh*(ak13(ji,jj,jk) + zh)
-               zalk_dic   = zdic * (znumer_dic/zdenom_dic)
-               zdnumer_dic = ak13(ji,jj,jk)*ak13(ji,jj,jk)*ak23(ji,jj,jk) + zh     &
-                             *(4.*ak13(ji,jj,jk)*ak23(ji,jj,jk) + zh*ak13(ji,jj,jk))
-               zdalk_dic   = -zdic*(zdnumer_dic/zdenom_dic**2)
-
-
-               ! B(OH)3 - B(OH)4 : n=1, m=0
-               znumer_bor = akb3(ji,jj,jk)
-               zdenom_bor = akb3(ji,jj,jk) + zh
-               zalk_bor   = zbot * (znumer_bor/zdenom_bor)
-               zdnumer_bor = akb3(ji,jj,jk)
-               zdalk_bor   = -zbot*(zdnumer_bor/zdenom_bor**2)
-
-
-               ! H3PO4 - H2PO4 - HPO4 - PO4 : n=3, m=1
-               znumer_po4 = 3.*ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk)*ak3p3(ji,jj,jk)  &
-               &            + zh*(2.*ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk) + zh* ak1p3(ji,jj,jk))
-               zdenom_po4 = ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk)*ak3p3(ji,jj,jk)     &
-               &            + zh*( ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk) + zh*(ak1p3(ji,jj,jk) + zh))
-               zalk_po4   = zpt * (znumer_po4/zdenom_po4 - 1.) ! Zero level of H3PO4 = 1
-               zdnumer_po4 = ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk)*ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk)*ak3p3(ji,jj,jk)  &
-               &             + zh*(4.*ak1p3(ji,jj,jk)*ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk)*ak3p3(ji,jj,jk)         &
-               &             + zh*(9.*ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk)*ak3p3(ji,jj,jk)                         &
-               &             + ak1p3(ji,jj,jk)*ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk)                                &
-               &             + zh*(4.*ak1p3(ji,jj,jk)*ak2p3(ji,jj,jk) + zh * ak1p3(ji,jj,jk) ) ) )
-               zdalk_po4   = -zpt * (zdnumer_po4/zdenom_po4**2)
-
-               ! H4SiO4 - H3SiO4 : n=1, m=0
-               znumer_sil = aksi3(ji,jj,jk)
-               zdenom_sil = aksi3(ji,jj,jk) + zh
-               zalk_sil   = zsit * (znumer_sil/zdenom_sil)
-               zdnumer_sil = aksi3(ji,jj,jk)
-               zdalk_sil   = -zsit * (zdnumer_sil/zdenom_sil**2)
-
-               ! HSO4 - SO4 : n=1, m=1
-               aphscale = 1.0 + zst/aks3(ji,jj,jk)
-               znumer_so4 = aks3(ji,jj,jk) * aphscale
-               zdenom_so4 = aks3(ji,jj,jk) * aphscale + zh
-               zalk_so4   = zst * (znumer_so4/zdenom_so4 - 1.)
-               zdnumer_so4 = aks3(ji,jj,jk)
-               zdalk_so4   = -zst * (zdnumer_so4/zdenom_so4**2)
-
-               ! HF - F : n=1, m=1
-               znumer_flu =  akf3(ji,jj,jk)
-               zdenom_flu =  akf3(ji,jj,jk) + zh
-               zalk_flu   =  zft * (znumer_flu/zdenom_flu - 1.)
-               zdnumer_flu = akf3(ji,jj,jk)
-               zdalk_flu   = -zft * (zdnumer_flu/zdenom_flu**2)
-
-               ! H2O - OH
-               aphscale = 1.0 + zst/aks3(ji,jj,jk)
-               zalk_wat   = akw3(ji,jj,jk)/zh - zh/aphscale
-               zdalk_wat  = -akw3(ji,jj,jk)/zh**2 - 1./aphscale
-
-               ! CALCULATE [ALK]([CO3--], [HCO3-])
-               zeqn = zalk_dic + zalk_bor + zalk_po4 + zalk_sil   &
-               &      + zalk_so4 + zalk_flu                       &
-               &      + zalk_wat - p_alktot
-
-               zalka = p_alktot - (zalk_bor + zalk_po4 + zalk_sil   &
-               &       + zalk_so4 + zalk_flu + zalk_wat)
-
-               zdeqndh = zdalk_dic + zdalk_bor + zdalk_po4 + zdalk_sil &
-               &         + zdalk_so4 + zdalk_flu + zdalk_wat
-
-               ! Adapt bracketing interval
-               IF(zeqn > 0._wp) THEN
-                 zh_min(ji,jj,jk) = zh_prev
-               ELSEIF(zeqn < 0._wp) THEN
-                 zh_max(ji,jj,jk) = zh_prev
-               ENDIF
-
-               IF(ABS(zeqn) >= 0.5_wp*zeqn_absmin(ji,jj,jk)) THEN
-               ! if the function evaluation at the current point is
-               ! not decreasing faster than with a bisection step (at least linearly)
-               ! in absolute value take one bisection step on [ph_min, ph_max]
-               ! ph_new = (ph_min + ph_max)/2d0
-               !
+
+            IF( zh < zh_min(ji,jj,jk) ) THEN
+               ! if [H]_new < [H]_min
+               ! i.e., if ph_new > ph_max then
+               ! take one bisection step on [ph_prev, ph_max]
+               ! ph_new = (ph_prev + ph_max)/2d0
                ! In terms of [H]_new:
                ! [H]_new = 10**(-ph_new)
-               !         = 10**(-(ph_min + ph_max)/2d0)
-               !         = SQRT(10**(-(ph_min + phmax)))
-               !         = SQRT(zh_max * zh_min)
-                  zh = SQRT(zh_max(ji,jj,jk) * zh_min(ji,jj,jk))
-                  zh_lnfactor = (zh - zh_prev)/zh_prev ! Required to test convergence below
-               ELSE
-               ! dzeqn/dpH = dzeqn/d[H] * d[H]/dpH
-               !           = -zdeqndh * LOG(10) * [H]
-               ! \Delta pH = -zeqn/(zdeqndh*d[H]/dpH) = zeqn/(zdeqndh*[H]*LOG(10))
-               !
-               ! pH_new = pH_old + \deltapH
-               !
-               ! [H]_new = 10**(-pH_new)
-               !         = 10**(-pH_old - \Delta pH)
-               !         = [H]_old * 10**(-zeqn/(zdeqndh*[H]_old*LOG(10)))
-               !         = [H]_old * EXP(-LOG(10)*zeqn/(zdeqndh*[H]_old*LOG(10)))
-               !         = [H]_old * EXP(-zeqn/(zdeqndh*[H]_old))
-
-                  zh_lnfactor = -zeqn/(zdeqndh*zh_prev)
-
-                  IF(ABS(zh_lnfactor) > pz_exp_threshold) THEN
-                     zh          = zh_prev*EXP(zh_lnfactor)
-                  ELSE
-                     zh_delta    = zh_lnfactor*zh_prev
-                     zh          = zh_prev + zh_delta
-                  ENDIF
-
-                  IF( zh < zh_min(ji,jj,jk) ) THEN
-                     ! if [H]_new < [H]_min
-                     ! i.e., if ph_new > ph_max then
-                     ! take one bisection step on [ph_prev, ph_max]
-                     ! ph_new = (ph_prev + ph_max)/2d0
-                     ! In terms of [H]_new:
-                     ! [H]_new = 10**(-ph_new)
-                     !         = 10**(-(ph_prev + ph_max)/2d0)
-                     !         = SQRT(10**(-(ph_prev + phmax)))
-                     !         = SQRT([H]_old*10**(-ph_max))
-                     !         = SQRT([H]_old * zh_min)
-                     zh                = SQRT(zh_prev * zh_min(ji,jj,jk))
-                     zh_lnfactor       = (zh - zh_prev)/zh_prev ! Required to test convergence below
-                  ENDIF
-
-                  IF( zh > zh_max(ji,jj,jk) ) THEN
-                     ! if [H]_new > [H]_max
-                     ! i.e., if ph_new < ph_min, then
-                     ! take one bisection step on [ph_min, ph_prev]
-                     ! ph_new = (ph_prev + ph_min)/2d0
-                     ! In terms of [H]_new:
-                     ! [H]_new = 10**(-ph_new)
-                     !         = 10**(-(ph_prev + ph_min)/2d0)
-                     !         = SQRT(10**(-(ph_prev + ph_min)))
-                     !         = SQRT([H]_old*10**(-ph_min))
-                     !         = SQRT([H]_old * zhmax)
-                     zh                = SQRT(zh_prev * zh_max(ji,jj,jk))
-                     zh_lnfactor       = (zh - zh_prev)/zh_prev ! Required to test convergence below
-                  ENDIF
-               ENDIF
-
-               zeqn_absmin(ji,jj,jk) = MIN( ABS(zeqn), zeqn_absmin(ji,jj,jk))
-
-               ! Stop iterations once |\delta{[H]}/[H]| < rdel
-               ! <=> |(zh - zh_prev)/zh_prev| = |EXP(-zeqn/(zdeqndh*zh_prev)) -1| < rdel
-               ! |EXP(-zeqn/(zdeqndh*zh_prev)) -1| ~ |zeqn/(zdeqndh*zh_prev)|
-
-               ! Alternatively:
-               ! |\Delta pH| = |zeqn/(zdeqndh*zh_prev*LOG(10))|
-               !             ~ 1/LOG(10) * |\Delta [H]|/[H]
-               !             < 1/LOG(10) * rdel
-
-               ! Hence |zeqn/(zdeqndh*zh)| < rdel
-
-               ! rdel <-- pp_rdel_ah_target
-               l_exitnow = (ABS(zh_lnfactor) < pp_rdel_ah_target)
-
-               IF(l_exitnow) THEN 
-                  rmask(ji,jj,jk) = 0.
-               ENDIF
-
-               zhi(ji,jj,jk) =  zh
-
-               IF(jn >= jp_maxniter_atgen) THEN
-                  zhi(ji,jj,jk) = -1._wp
-               ENDIF
-
+               !         = 10**(-(ph_prev + ph_max)/2d0)
+               !         = SQRT(10**(-(ph_prev + phmax)))
+               !         = SQRT([H]_old*10**(-ph_max))
+               !         = SQRT([H]_old * zh_min)
+               zh                = SQRT(zh_prev * zh_min(ji,jj,jk))
+               zh_lnfactor       = (zh - zh_prev)/zh_prev ! Required to test convergence below
             ENDIF
-         END DO
-      END DO
-   END DO
+
+            IF( zh > zh_max(ji,jj,jk) ) THEN
+               ! if [H]_new > [H]_max
+               ! i.e., if ph_new < ph_min, then
+               ! take one bisection step on [ph_min, ph_prev]
+               ! ph_new = (ph_prev + ph_min)/2d0
+               ! In terms of [H]_new:
+               ! [H]_new = 10**(-ph_new)
+               !         = 10**(-(ph_prev + ph_min)/2d0)
+               !         = SQRT(10**(-(ph_prev + ph_min)))
+               !         = SQRT([H]_old*10**(-ph_min))
+               !         = SQRT([H]_old * zhmax)
+               zh                = SQRT(zh_prev * zh_max(ji,jj,jk))
+               zh_lnfactor       = (zh - zh_prev)/zh_prev ! Required to test convergence below
+            ENDIF
+         ENDIF
+
+         zeqn_absmin(ji,jj,jk) = MIN( ABS(zeqn), zeqn_absmin(ji,jj,jk))
+
+         ! Stop iterations once |\delta{[H]}/[H]| < rdel
+         ! <=> |(zh - zh_prev)/zh_prev| = |EXP(-zeqn/(zdeqndh*zh_prev)) -1| < rdel
+         ! |EXP(-zeqn/(zdeqndh*zh_prev)) -1| ~ |zeqn/(zdeqndh*zh_prev)|
+
+         ! Alternatively:
+         ! |\Delta pH| = |zeqn/(zdeqndh*zh_prev*LOG(10))|
+         !             ~ 1/LOG(10) * |\Delta [H]|/[H]
+         !             < 1/LOG(10) * rdel
+
+         ! Hence |zeqn/(zdeqndh*zh)| < rdel
+
+         ! rdel <-- pp_rdel_ah_target
+         l_exitnow = (ABS(zh_lnfactor) < pp_rdel_ah_target)
+
+         IF(l_exitnow) THEN 
+            rmask(ji,jj,jk) = 0.
+         ENDIF
+
+         zhi(ji,jj,jk) =  zh
+
+         IF(jn >= jp_maxniter_atgen) THEN
+            zhi(ji,jj,jk) = -1._wp
+         ENDIF
+
+      ENDIF
+   END_3D
    END DO
    !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zfechem.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zfechem.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zfechem.F90	(revision 13463)
@@ -15,6 +15,6 @@
    USE sms_pisces      ! PISCES Source Minus Sink variables
    USE p4zche          ! chemical model
-   USE p4zsbc          ! Boundary conditions from sediments
-   USE prtctl_trc      ! print control for debugging
+   USE p4zbc           ! Boundary conditions from sediments
+   USE prtctl          ! print control for debugging
    USE iom             ! I/O manager
 
@@ -31,4 +31,7 @@
    REAL(wp), PUBLIC ::   kfep         !: rate constant for nanoparticle formation
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -38,5 +41,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_fechem( kt, knt )
+   SUBROUTINE p4z_fechem( kt, knt, Kbb, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_fechem  ***
@@ -48,4 +51,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt, knt   ! ocean time step
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Krhs  ! time level indices
       !
       INTEGER  ::   ji, jj, jk, jic, jn
@@ -71,16 +75,12 @@
       IF( ln_timing )   CALL timing_start('p4z_fechem')
       !
-      zFe3 (:,:,:) = 0.
-      zFeL1(:,:,:) = 0.
-      zTL1 (:,:,:) = 0.
-
       ! Total ligand concentration : Ligands can be chosen to be constant or variable
       ! Parameterization from Tagliabue and Voelker (2011)
       ! -------------------------------------------------
       IF( ln_ligvar ) THEN
-         ztotlig(:,:,:) =  0.09 * trb(:,:,:,jpdoc) * 1E6 + ligand * 1E9
+         ztotlig(:,:,:) =  0.09 * tr(:,:,:,jpdoc,Kbb) * 1E6 + ligand * 1E9
          ztotlig(:,:,:) =  MIN( ztotlig(:,:,:), 10. )
       ELSE
-        IF( ln_ligand ) THEN  ;   ztotlig(:,:,:) = trb(:,:,:,jplgw) * 1E9
+        IF( ln_ligand ) THEN  ;   ztotlig(:,:,:) = tr(:,:,:,jplgw,Kbb) * 1E9
         ELSE                  ;   ztotlig(:,:,:) = ligand * 1E9
         ENDIF
@@ -92,114 +92,102 @@
       ! Chemistry is supposed to be fast enough to be at equilibrium
       ! ------------------------------------------------------------
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zTL1(ji,jj,jk)  = ztotlig(ji,jj,jk)
-               zkeq            = fekeq(ji,jj,jk)
-               zfesatur        = zTL1(ji,jj,jk) * 1E-9
-               ztfe            = trb(ji,jj,jk,jpfer) 
-               ! Fe' is the root of a 2nd order polynom
-               zFe3 (ji,jj,jk) = ( -( 1. + zfesatur * zkeq - zkeq * ztfe )               &
-                  &              + SQRT( ( 1. + zfesatur * zkeq - zkeq * ztfe )**2       &
-                  &              + 4. * ztfe * zkeq) ) / ( 2. * zkeq )
-               zFe3 (ji,jj,jk) = zFe3(ji,jj,jk) * 1E9
-               zFeL1(ji,jj,jk) = MAX( 0., trb(ji,jj,jk,jpfer) * 1E9 - zFe3(ji,jj,jk) )
-           END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zTL1(ji,jj,jk)  = ztotlig(ji,jj,jk)
+         zkeq            = fekeq(ji,jj,jk)
+         zfesatur        = zTL1(ji,jj,jk) * 1E-9
+         ztfe            = tr(ji,jj,jk,jpfer,Kbb) 
+         ! Fe' is the root of a 2nd order polynom
+         zFe3 (ji,jj,jk) = ( -( 1. + zfesatur * zkeq - zkeq * ztfe )               &
+            &              + SQRT( ( 1. + zfesatur * zkeq - zkeq * ztfe )**2       &
+            &              + 4. * ztfe * zkeq) ) / ( 2. * zkeq )
+         zFe3 (ji,jj,jk) = zFe3(ji,jj,jk) * 1E9
+         zFeL1(ji,jj,jk) = MAX( 0., tr(ji,jj,jk,jpfer,Kbb) * 1E9 - zFe3(ji,jj,jk) )
+      END_3D
          !
 
       zdust = 0.         ! if no dust available
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! Scavenging rate of iron. This scavenging rate depends on the load of particles of sea water. 
-               ! This parameterization assumes a simple second order kinetics (k[Particles][Fe]).
-               ! Scavenging onto dust is also included as evidenced from the DUNE experiments.
-               ! --------------------------------------------------------------------------------------
-               zhplus  = max( rtrn, hi(ji,jj,jk) )
-               fe3sol  = fesol(ji,jj,jk,1) * ( zhplus**3 + fesol(ji,jj,jk,2) * zhplus**2  &
-               &         + fesol(ji,jj,jk,3) * zhplus + fesol(ji,jj,jk,4)     &
-               &         + fesol(ji,jj,jk,5) / zhplus )
-               !
-               zfeequi = zFe3(ji,jj,jk) * 1E-9
-               zhplus  = max( rtrn, hi(ji,jj,jk) )
-               fe3sol  = fesol(ji,jj,jk,1) * ( zhplus**3 + fesol(ji,jj,jk,2) * zhplus**2  &
-                  &         + fesol(ji,jj,jk,3) * zhplus + fesol(ji,jj,jk,4)     &
-                  &         + fesol(ji,jj,jk,5) / zhplus )
-               zfecoll = 0.5 * zFeL1(ji,jj,jk) * 1E-9
-               ! precipitation of Fe3+, creation of nanoparticles
-               precip(ji,jj,jk) = MAX( 0., ( zFe3(ji,jj,jk) * 1E-9 - fe3sol ) ) * kfep * xstep
-               !
-               ztrc   = ( trb(ji,jj,jk,jppoc) + trb(ji,jj,jk,jpgoc) + trb(ji,jj,jk,jpcal) + trb(ji,jj,jk,jpgsi) ) * 1.e6 
-               IF( ln_dust )  zdust  = dust(ji,jj) / ( wdust / rday ) * tmask(ji,jj,jk) &
-               &  * EXP( -gdept_n(ji,jj,jk) / 540. )
-               IF (ln_ligand) THEN
-                  zxlam  = xlam1 * MAX( 1.E-3, EXP(-2 * etot(ji,jj,jk) / 10. ) * (1. - EXP(-2 * trb(ji,jj,jk,jpoxy) / 100.E-6 ) ))
-               ELSE
-                  zxlam  = xlam1 * 1.0
-               ENDIF
-               zlam1b = 3.e-5 + xlamdust * zdust + zxlam * ztrc
-               zscave = zfeequi * zlam1b * xstep
-
-               ! Compute the different ratios for scavenging of iron
-               ! to later allocate scavenged iron to the different organic pools
-               ! ---------------------------------------------------------
-               zdenom1 = zxlam * trb(ji,jj,jk,jppoc) / zlam1b
-               zdenom2 = zxlam * trb(ji,jj,jk,jpgoc) / zlam1b
-
-               !  Increased scavenging for very high iron concentrations found near the coasts 
-               !  due to increased lithogenic particles and let say it is unknown processes (precipitation, ...)
-               !  -----------------------------------------------------------
-               zlamfac = MAX( 0.e0, ( gphit(ji,jj) + 55.) / 30. )
-               zlamfac = MIN( 1.  , zlamfac )
-               zdep    = MIN( 1., 1000. / gdept_n(ji,jj,jk) )
-               zcoag   = 1E-4 * ( 1. - zlamfac ) * zdep * xstep * trb(ji,jj,jk,jpfer)
-
-               !  Compute the coagulation of colloidal iron. This parameterization 
-               !  could be thought as an equivalent of colloidal pumping.
-               !  It requires certainly some more work as it is very poorly constrained.
-               !  ----------------------------------------------------------------
-               zlam1a   = ( 0.369  * 0.3 * trb(ji,jj,jk,jpdoc) + 102.4  * trb(ji,jj,jk,jppoc) ) * xdiss(ji,jj,jk)    &
-                   &      + ( 114.   * 0.3 * trb(ji,jj,jk,jpdoc) )
-               zaggdfea = zlam1a * xstep * zfecoll
-               !
-               zlam1b   = 3.53E3 * trb(ji,jj,jk,jpgoc) * xdiss(ji,jj,jk)
-               zaggdfeb = zlam1b * xstep * zfecoll
-               !
-               tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) - zscave - zaggdfea - zaggdfeb &
-               &                     - zcoag - precip(ji,jj,jk)
-               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + zscave * zdenom1 + zaggdfea
-               tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + zscave * zdenom2 + zaggdfeb
-               zscav3d(ji,jj,jk)   = zscave
-               zcoll3d(ji,jj,jk)   = zaggdfea + zaggdfeb
-               !
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         ! Scavenging rate of iron. This scavenging rate depends on the load of particles of sea water. 
+         ! This parameterization assumes a simple second order kinetics (k[Particles][Fe]).
+         ! Scavenging onto dust is also included as evidenced from the DUNE experiments.
+         ! --------------------------------------------------------------------------------------
+         zhplus  = max( rtrn, hi(ji,jj,jk) )
+         fe3sol  = fesol(ji,jj,jk,1) * ( zhplus**3 + fesol(ji,jj,jk,2) * zhplus**2  &
+         &         + fesol(ji,jj,jk,3) * zhplus + fesol(ji,jj,jk,4)     &
+         &         + fesol(ji,jj,jk,5) / zhplus )
+         !
+         zfeequi = zFe3(ji,jj,jk) * 1E-9
+         zhplus  = max( rtrn, hi(ji,jj,jk) )
+         fe3sol  = fesol(ji,jj,jk,1) * ( zhplus**3 + fesol(ji,jj,jk,2) * zhplus**2  &
+            &         + fesol(ji,jj,jk,3) * zhplus + fesol(ji,jj,jk,4)     &
+            &         + fesol(ji,jj,jk,5) / zhplus )
+         zfecoll = 0.5 * zFeL1(ji,jj,jk) * 1E-9
+         ! precipitation of Fe3+, creation of nanoparticles
+         precip(ji,jj,jk) = MAX( 0., ( zFe3(ji,jj,jk) * 1E-9 - fe3sol ) ) * kfep * xstep
+         !
+         ztrc   = ( tr(ji,jj,jk,jppoc,Kbb) + tr(ji,jj,jk,jpgoc,Kbb) + tr(ji,jj,jk,jpcal,Kbb) + tr(ji,jj,jk,jpgsi,Kbb) ) * 1.e6 
+         IF( ll_dust )  zdust  = dust(ji,jj) / ( wdust / rday ) * tmask(ji,jj,jk) &
+         &  * EXP( -gdept(ji,jj,jk,Kmm) / 540. )
+         IF (ln_ligand) THEN
+            zxlam  = xlam1 * MAX( 1.E-3, EXP(-2 * etot(ji,jj,jk) / 10. ) * (1. - EXP(-2 * tr(ji,jj,jk,jpoxy,Kbb) / 100.E-6 ) ))
+         ELSE
+            zxlam  = xlam1 * 1.0
+         ENDIF
+         zlam1b = 3.e-5 + xlamdust * zdust + zxlam * ztrc
+         zscave = zfeequi * zlam1b * xstep
+
+         ! Compute the different ratios for scavenging of iron
+         ! to later allocate scavenged iron to the different organic pools
+         ! ---------------------------------------------------------
+         zdenom1 = zxlam * tr(ji,jj,jk,jppoc,Kbb) / zlam1b
+         zdenom2 = zxlam * tr(ji,jj,jk,jpgoc,Kbb) / zlam1b
+
+         !  Increased scavenging for very high iron concentrations found near the coasts 
+         !  due to increased lithogenic particles and let say it is unknown processes (precipitation, ...)
+         !  -----------------------------------------------------------
+         zlamfac = MAX( 0.e0, ( gphit(ji,jj) + 55.) / 30. )
+         zlamfac = MIN( 1.  , zlamfac )
+         zdep    = MIN( 1., 1000. / gdept(ji,jj,jk,Kmm) )
+         zcoag   = 1E-4 * ( 1. - zlamfac ) * zdep * xstep * tr(ji,jj,jk,jpfer,Kbb)
+
+         !  Compute the coagulation of colloidal iron. This parameterization 
+         !  could be thought as an equivalent of colloidal pumping.
+         !  It requires certainly some more work as it is very poorly constrained.
+         !  ----------------------------------------------------------------
+         zlam1a   = ( 0.369  * 0.3 * tr(ji,jj,jk,jpdoc,Kbb) + 102.4  * tr(ji,jj,jk,jppoc,Kbb) ) * xdiss(ji,jj,jk)    &
+             &      + ( 114.   * 0.3 * tr(ji,jj,jk,jpdoc,Kbb) )
+         zaggdfea = zlam1a * xstep * zfecoll
+         !
+         zlam1b   = 3.53E3 * tr(ji,jj,jk,jpgoc,Kbb) * xdiss(ji,jj,jk)
+         zaggdfeb = zlam1b * xstep * zfecoll
+         !
+         tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) - zscave - zaggdfea - zaggdfeb &
+         &                     - zcoag - precip(ji,jj,jk)
+         tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) + zscave * zdenom1 + zaggdfea
+         tr(ji,jj,jk,jpbfe,Krhs) = tr(ji,jj,jk,jpbfe,Krhs) + zscave * zdenom2 + zaggdfeb
+         zscav3d(ji,jj,jk)   = zscave
+         zcoll3d(ji,jj,jk)   = zaggdfea + zaggdfeb
+         !
+      END_3D
       !
       !  Define the bioavailable fraction of iron
       !  ----------------------------------------
-      biron(:,:,:) = trb(:,:,:,jpfer) 
+      biron(:,:,:) = tr(:,:,:,jpfer,Kbb) 
       !
       IF( ln_ligand ) THEN
          !
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zlam1a   = ( 0.369  * 0.3 * trb(ji,jj,jk,jpdoc) + 102.4  * trb(ji,jj,jk,jppoc) ) * xdiss(ji,jj,jk)    &
-                      &    + ( 114.   * 0.3 * trb(ji,jj,jk,jpdoc) )
-                  !
-                  zlam1b   = 3.53E3 *   trb(ji,jj,jk,jpgoc) * xdiss(ji,jj,jk)
-                  zligco   = 0.5 * trn(ji,jj,jk,jplgw)
-                  zaggliga = zlam1a * xstep * zligco
-                  zaggligb = zlam1b * xstep * zligco
-                  tra(ji,jj,jk,jplgw) = tra(ji,jj,jk,jplgw) - zaggliga - zaggligb
-                  zlcoll3d(ji,jj,jk)  = zaggliga + zaggligb
-               END DO
-            END DO
-         END DO
-         !
-         plig(:,:,:) =  MAX( 0., ( ( zFeL1(:,:,:) * 1E-9 ) / ( trb(:,:,:,jpfer) +rtrn ) ) )
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+            zlam1a   = ( 0.369  * 0.3 * tr(ji,jj,jk,jpdoc,Kbb) + 102.4  * tr(ji,jj,jk,jppoc,Kbb) ) * xdiss(ji,jj,jk)    &
+                &    + ( 114.   * 0.3 * tr(ji,jj,jk,jpdoc,Kbb) )
+            !
+            zlam1b   = 3.53E3 *   tr(ji,jj,jk,jpgoc,Kbb) * xdiss(ji,jj,jk)
+            zligco   = 0.5 * tr(ji,jj,jk,jplgw,Kmm)
+            zaggliga = zlam1a * xstep * zligco
+            zaggligb = zlam1b * xstep * zligco
+            tr(ji,jj,jk,jplgw,Krhs) = tr(ji,jj,jk,jplgw,Krhs) - zaggliga - zaggligb
+            zlcoll3d(ji,jj,jk)  = zaggliga + zaggligb
+         END_3D
+         !
+         plig(:,:,:) =  MAX( 0., ( ( zFeL1(:,:,:) * 1E-9 ) / ( tr(:,:,:,jpfer,Kbb) +rtrn ) ) )
          !
       ENDIF
@@ -209,19 +197,31 @@
          IF( knt == nrdttrc ) THEN
             zrfact2 = 1.e3 * rfact2r  ! conversion from mol/L/timestep into mol/m3/s
-            IF( iom_use("Fe3")    )  CALL iom_put("Fe3"    , zFe3   (:,:,:)       * tmask(:,:,:) )   ! Fe3+
-            IF( iom_use("FeL1")   )  CALL iom_put("FeL1"   , zFeL1  (:,:,:)       * tmask(:,:,:) )   ! FeL1
-            IF( iom_use("TL1")    )  CALL iom_put("TL1"    , zTL1   (:,:,:)       * tmask(:,:,:) )   ! TL1
+            IF( iom_use("Fe3")  )  THEN
+               zFe3(:,:,jpk) = 0.  ;  CALL iom_put("Fe3" , zFe3(:,:,:) * tmask(:,:,:) )   ! Fe3+
+            ENDIF
+            IF( iom_use("FeL1") )  THEN
+              zFeL1(:,:,jpk) = 0.  ;  CALL iom_put("FeL1", zFeL1(:,:,:) * tmask(:,:,:) )   ! FeL1
+            ENDIF
+            IF( iom_use("TL1")  )  THEN
+              zTL1(:,:,jpk) = 0.   ;  CALL iom_put("TL1" , zTL1(:,:,:) * tmask(:,:,:) )   ! TL1
+            ENDIF
             IF( iom_use("Totlig") )  CALL iom_put("Totlig" , ztotlig(:,:,:)       * tmask(:,:,:) )   ! TL
             IF( iom_use("Biron")  )  CALL iom_put("Biron"  , biron  (:,:,:)  * 1e9 * tmask(:,:,:) )   ! biron
-            IF( iom_use("FESCAV") )  CALL iom_put("FESCAV" , zscav3d(:,:,:)  * 1e9 * tmask(:,:,:) * zrfact2 )
-            IF( iom_use("FECOLL") )  CALL iom_put("FECOLL" , zcoll3d(:,:,:)  * 1e9 * tmask(:,:,:) * zrfact2 )
-            IF( iom_use("LGWCOLL"))  CALL iom_put("LGWCOLL", zlcoll3d(:,:,:) * 1e9 * tmask(:,:,:) * zrfact2 )
-         ENDIF
-      ENDIF
-
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+            IF( iom_use("FESCAV") )  THEN
+               zscav3d (:,:,jpk) = 0.  ;  CALL iom_put("FESCAV" , zscav3d(:,:,:)  * 1e9 * tmask(:,:,:) * zrfact2 )
+            ENDIF
+            IF( iom_use("FECOLL") ) THEN
+               zcoll3d (:,:,jpk) = 0.  ;   CALL iom_put("FECOLL" , zcoll3d(:,:,:)  * 1e9 * tmask(:,:,:) * zrfact2 )
+            ENDIF
+            IF( iom_use("LGWCOLL")) THEN
+               zlcoll3d(:,:,jpk) = 0.  ;  CALL iom_put("LGWCOLL", zlcoll3d(:,:,:) * 1e9 * tmask(:,:,:) * zrfact2 )
+            ENDIF
+          ENDIF
+      ENDIF
+
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('fechem')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -254,10 +254,8 @@
       ENDIF
       !
-      REWIND( numnatp_ref )            ! Namelist nampisfer in reference namelist : Pisces iron chemistry
       READ  ( numnatp_ref, nampisfer, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisfer in reference namelist', lwp )
-      REWIND( numnatp_cfg )            ! Namelist nampisfer in configuration namelist : Pisces iron chemistry
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisfer in reference namelist' )
       READ  ( numnatp_cfg, nampisfer, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisfer in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisfer in configuration namelist' )
       IF(lwm) WRITE( numonp, nampisfer )
 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zflx.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zflx.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zflx.F90	(revision 13463)
@@ -19,5 +19,5 @@
    USE sms_pisces     !  PISCES Source Minus Sink variables
    USE p4zche         !  Chemical model
-   USE prtctl_trc     !  print control for debugging
+   USE prtctl         !  print control for debugging
    USE iom            !  I/O manager
    USE fldread        !  read input fields
@@ -52,4 +52,7 @@
    REAL(wp) ::   xconv  = 0.01_wp / 3600._wp   !: coefficients for conversion 
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -59,5 +62,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_flx ( kt, knt )
+   SUBROUTINE p4z_flx ( kt, knt, Kbb, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_flx  ***
@@ -71,4 +74,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt, knt   !
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Krhs      ! time level indices
       !
       INTEGER  ::   ji, jj, jm, iind, iindm1
@@ -80,5 +84,4 @@
       CHARACTER (len=25) ::   charout
       REAL(wp), DIMENSION(jpi,jpj) ::   zkgco2, zkgo2, zh2co3, zoflx,  zpco2atm  
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zw2d
       !!---------------------------------------------------------------------
       !
@@ -107,14 +110,12 @@
       IF( l_co2cpl )   satmco2(:,:) = atm_co2(:,:)
 
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            ! DUMMY VARIABLES FOR DIC, H+, AND BORATE
-            zfact = rhop(ji,jj,1) / 1000. + rtrn
-            zdic  = trb(ji,jj,1,jpdic)
-            zph   = MAX( hi(ji,jj,1), 1.e-10 ) / zfact
-            ! CALCULATE [H2CO3]
-            zh2co3(ji,jj) = zdic/(1. + ak13(ji,jj,1)/zph + ak13(ji,jj,1)*ak23(ji,jj,1)/zph**2)
-         END DO
-      END DO
+      DO_2D( 1, 1, 1, 1 )
+         ! DUMMY VARIABLES FOR DIC, H+, AND BORATE
+         zfact = rhop(ji,jj,1) / 1000. + rtrn
+         zdic  = tr(ji,jj,1,jpdic,Kbb)
+         zph   = MAX( hi(ji,jj,1), 1.e-10 ) / zfact
+         ! CALCULATE [H2CO3]
+         zh2co3(ji,jj) = zdic/(1. + ak13(ji,jj,1)/zph + ak13(ji,jj,1)*ak23(ji,jj,1)/zph**2)
+      END_2D
 
       ! --------------
@@ -125,90 +126,70 @@
       ! -------------------------------------------
 
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            ztc  = MIN( 35., tsn(ji,jj,1,jp_tem) )
-            ztc2 = ztc * ztc
-            ztc3 = ztc * ztc2 
-            ztc4 = ztc2 * ztc2 
-            ! Compute the schmidt Number both O2 and CO2
-            zsch_co2 = 2116.8 - 136.25 * ztc + 4.7353 * ztc2 - 0.092307 * ztc3 + 0.0007555 * ztc4
-            zsch_o2  = 1920.4 - 135.6  * ztc + 5.2122 * ztc2 - 0.109390 * ztc3 + 0.0009377 * ztc4
-            !  wind speed 
-            zws  = wndm(ji,jj) * wndm(ji,jj)
-            ! Compute the piston velocity for O2 and CO2
-            zkgwan = 0.251 * zws
-            zkgwan = zkgwan * xconv * ( 1.- fr_i(ji,jj) ) * tmask(ji,jj,1)
-            ! compute gas exchange for CO2 and O2
-            zkgco2(ji,jj) = zkgwan * SQRT( 660./ zsch_co2 )
-            zkgo2 (ji,jj) = zkgwan * SQRT( 660./ zsch_o2 )
-         END DO
-      END DO
-
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            ztkel = tempis(ji,jj,1) + 273.15
-            zsal  = salinprac(ji,jj,1) + ( 1.- tmask(ji,jj,1) ) * 35.
-            zvapsw    = EXP(24.4543 - 67.4509*(100.0/ztkel) - 4.8489*LOG(ztkel/100) - 0.000544*zsal)
-            zpco2atm(ji,jj) = satmco2(ji,jj) * ( patm(ji,jj) - zvapsw )
-            zxc2      = ( 1.0 - zpco2atm(ji,jj) * 1E-6 )**2
-            zfugcoeff = EXP( patm(ji,jj) * (chemc(ji,jj,2) + 2.0 * zxc2 * chemc(ji,jj,3) )   &
-            &           / ( 82.05736 * ztkel ))
-            zfco2 = zpco2atm(ji,jj) * zfugcoeff
-
-            ! Compute CO2 flux for the sea and air
-            zfld = zfco2 * chemc(ji,jj,1) * zkgco2(ji,jj)  ! (mol/L) * (m/s)
-            zflu = zh2co3(ji,jj) * zkgco2(ji,jj)                                   ! (mol/L) (m/s) ?
-            oce_co2(ji,jj) = ( zfld - zflu ) * rfact2 * e1e2t(ji,jj) * tmask(ji,jj,1) * 1000.
-            ! compute the trend
-            tra(ji,jj,1,jpdic) = tra(ji,jj,1,jpdic) + ( zfld - zflu ) * rfact2 / e3t_n(ji,jj,1) * tmask(ji,jj,1)
-
-            ! Compute O2 flux 
-            zfld16 = patm(ji,jj) * chemo2(ji,jj,1) * zkgo2(ji,jj)          ! (mol/L) * (m/s)
-            zflu16 = trb(ji,jj,1,jpoxy) * zkgo2(ji,jj)
-            zoflx(ji,jj) = ( zfld16 - zflu16 ) * tmask(ji,jj,1)
-            tra(ji,jj,1,jpoxy) = tra(ji,jj,1,jpoxy) + zoflx(ji,jj) * rfact2 / e3t_n(ji,jj,1)
-         END DO
-      END DO
+      DO_2D( 1, 1, 1, 1 )
+         ztc  = MIN( 35., ts(ji,jj,1,jp_tem,Kmm) )
+         ztc2 = ztc * ztc
+         ztc3 = ztc * ztc2 
+         ztc4 = ztc2 * ztc2 
+         ! Compute the schmidt Number both O2 and CO2
+         zsch_co2 = 2116.8 - 136.25 * ztc + 4.7353 * ztc2 - 0.092307 * ztc3 + 0.0007555 * ztc4
+         zsch_o2  = 1920.4 - 135.6  * ztc + 5.2122 * ztc2 - 0.109390 * ztc3 + 0.0009377 * ztc4
+         !  wind speed 
+         zws  = wndm(ji,jj) * wndm(ji,jj)
+         ! Compute the piston velocity for O2 and CO2
+         zkgwan = 0.251 * zws
+         zkgwan = zkgwan * xconv * ( 1.- fr_i(ji,jj) ) * tmask(ji,jj,1)
+         ! compute gas exchange for CO2 and O2
+         zkgco2(ji,jj) = zkgwan * SQRT( 660./ zsch_co2 )
+         zkgo2 (ji,jj) = zkgwan * SQRT( 660./ zsch_o2 )
+      END_2D
+
+
+      DO_2D( 1, 1, 1, 1 )
+         ztkel = tempis(ji,jj,1) + 273.15
+         zsal  = salinprac(ji,jj,1) + ( 1.- tmask(ji,jj,1) ) * 35.
+         zvapsw    = EXP(24.4543 - 67.4509*(100.0/ztkel) - 4.8489*LOG(ztkel/100) - 0.000544*zsal)
+         zpco2atm(ji,jj) = satmco2(ji,jj) * ( patm(ji,jj) - zvapsw )
+         zxc2      = ( 1.0 - zpco2atm(ji,jj) * 1E-6 )**2
+         zfugcoeff = EXP( patm(ji,jj) * (chemc(ji,jj,2) + 2.0 * zxc2 * chemc(ji,jj,3) )   &
+         &           / ( 82.05736 * ztkel ))
+         zfco2 = zpco2atm(ji,jj) * zfugcoeff
+
+         ! Compute CO2 flux for the sea and air
+         zfld = zfco2 * chemc(ji,jj,1) * zkgco2(ji,jj)  ! (mol/L) * (m/s)
+         zflu = zh2co3(ji,jj) * zkgco2(ji,jj)                                   ! (mol/L) (m/s) ?
+         oce_co2(ji,jj) = ( zfld - zflu ) * tmask(ji,jj,1) 
+         ! compute the trend
+         tr(ji,jj,1,jpdic,Krhs) = tr(ji,jj,1,jpdic,Krhs) + oce_co2(ji,jj) * rfact2 / e3t(ji,jj,1,Kmm)
+
+         ! Compute O2 flux 
+         zfld16 = patm(ji,jj) * chemo2(ji,jj,1) * zkgo2(ji,jj)          ! (mol/L) * (m/s)
+         zflu16 = tr(ji,jj,1,jpoxy,Kbb) * zkgo2(ji,jj)
+         zoflx(ji,jj) = ( zfld16 - zflu16 ) * tmask(ji,jj,1)
+         tr(ji,jj,1,jpoxy,Krhs) = tr(ji,jj,1,jpoxy,Krhs) + zoflx(ji,jj) * rfact2 / e3t(ji,jj,1,Kmm)
+      END_2D
 
       IF( iom_use("tcflx") .OR. iom_use("tcflxcum") .OR. kt == nitrst   &
          &                 .OR. (ln_check_mass .AND. kt == nitend) )    &
-         t_oce_co2_flx  = glob_sum( 'p4zflx', oce_co2(:,:) )                    !  Total Flux of Carbon
+         t_oce_co2_flx  = glob_sum( 'p4zflx', oce_co2(:,:) * e1e2t(:,:) * 1000. )                    !  Total Flux of Carbon
       t_oce_co2_flx_cum = t_oce_co2_flx_cum + t_oce_co2_flx       !  Cumulative Total Flux of Carbon
 !      t_atm_co2_flx     = glob_sum( 'p4zflx', satmco2(:,:) * e1e2t(:,:) )       ! Total atmospheric pCO2
       t_atm_co2_flx     =  atcco2      ! Total atmospheric pCO2
  
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('flx ')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
 
       IF( lk_iomput .AND. knt == nrdttrc ) THEN
-         ALLOCATE( zw2d(jpi,jpj) )  
-         IF( iom_use( "Cflx"  ) )  THEN
-            zw2d(:,:) = oce_co2(:,:) / e1e2t(:,:) * rfact2r
-            CALL iom_put( "Cflx"     , zw2d ) 
-         ENDIF
-         IF( iom_use( "Oflx"  ) )  THEN
-            zw2d(:,:) =  zoflx(:,:) * 1000 * tmask(:,:,1)
-            CALL iom_put( "Oflx" , zw2d )
-         ENDIF
-         IF( iom_use( "Kg"    ) )  THEN
-            zw2d(:,:) =  zkgco2(:,:) * tmask(:,:,1)
-            CALL iom_put( "Kg"   , zw2d )
-         ENDIF
-         IF( iom_use( "Dpco2" ) ) THEN
-           zw2d(:,:) = ( zpco2atm(:,:) - zh2co3(:,:) / ( chemc(:,:,1) + rtrn ) ) * tmask(:,:,1)
-           CALL iom_put( "Dpco2" ,  zw2d )
-         ENDIF
-         IF( iom_use( "Dpo2" ) )  THEN
-           zw2d(:,:) = ( atcox * patm(:,:) - atcox * trb(:,:,1,jpoxy) / ( chemo2(:,:,1) + rtrn ) ) * tmask(:,:,1)
-           CALL iom_put( "Dpo2"  , zw2d )
-         ENDIF
-         CALL iom_put( "tcflx"    , t_oce_co2_flx * rfact2r )   ! molC/s
-         CALL iom_put( "tcflxcum" , t_oce_co2_flx_cum       )   ! molC
-         !
-         DEALLOCATE( zw2d )
+         CALL iom_put( "AtmCo2"  , satmco2(:,:) * tmask(:,:,1) )   ! Atmospheric CO2 concentration
+         CALL iom_put( "Cflx"    , oce_co2(:,:) * 1000. ) 
+         CALL iom_put( "Oflx"    , zoflx(:,:) * 1000.  )
+         CALL iom_put( "Kg"      , zkgco2(:,:) * tmask(:,:,1)  )
+         CALL iom_put( "Dpco2"   , ( zpco2atm(:,:) - zh2co3(:,:) / ( chemc(:,:,1) + rtrn ) ) * tmask(:,:,1) )
+         CALL iom_put( "pCO2sea" , ( zh2co3(:,:) / ( chemc(:,:,1) + rtrn ) ) * tmask(:,:,1) )
+         CALL iom_put( "Dpo2"    , ( atcox * patm(:,:) - atcox * tr(:,:,1,jpoxy,Kbb) / ( chemo2(:,:,1) + rtrn ) ) * tmask(:,:,1) )
+         CALL iom_put( "tcflx"   , t_oce_co2_flx     )   ! molC/s
+         CALL iom_put( "tcflxcum", t_oce_co2_flx_cum )   ! molC
       ENDIF
       !
@@ -239,10 +220,8 @@
       ENDIF
       !
-      REWIND( numnatp_ref )              ! Namelist nampisext in reference namelist : Pisces atm. conditions
       READ  ( numnatp_ref, nampisext, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisext in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampisext in configuration namelist : Pisces atm. conditions
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisext in reference namelist' )
       READ  ( numnatp_cfg, nampisext, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisext in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisext in configuration namelist' )
       IF(lwm) WRITE ( numonp, nampisext )
       !
@@ -320,10 +299,8 @@
          ENDIF
          !
-         REWIND( numnatp_ref )              ! Namelist nampisatm in reference namelist : Pisces atm. sea level pressure file
          READ  ( numnatp_ref, nampisatm, IOSTAT = ios, ERR = 901)
-901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampisatm in reference namelist', lwp )
-         REWIND( numnatp_cfg )              ! Namelist nampisatm in configuration namelist : Pisces atm. sea level pressure file 
+901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampisatm in reference namelist' )
          READ  ( numnatp_cfg, nampisatm, IOSTAT = ios, ERR = 902 )
-902      IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisatm in configuration namelist', lwp )
+902      IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisatm in configuration namelist' )
          IF(lwm) WRITE ( numonp, nampisatm )
          !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zint.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zint.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zint.F90	(revision 13463)
@@ -26,5 +26,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_int( kt )
+   SUBROUTINE p4z_int( kt, Kbb, Kmm )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_int  ***
@@ -33,5 +33,6 @@
       !!
       !!---------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
+      INTEGER, INTENT( in ) ::   Kbb, Kmm ! time level indices
       !
       INTEGER  :: ji, jj                 ! dummy loop indices
@@ -43,6 +44,6 @@
       ! Computation of phyto and zoo metabolic rate
       ! -------------------------------------------
-      tgfunc (:,:,:) = EXP( 0.063913 * tsn(:,:,:,jp_tem) )
-      tgfunc2(:,:,:) = EXP( 0.07608  * tsn(:,:,:,jp_tem) )
+      tgfunc (:,:,:) = EXP( 0.063913 * ts(:,:,:,jp_tem,Kmm) )
+      tgfunc2(:,:,:) = EXP( 0.07608  * ts(:,:,:,jp_tem,Kmm) )
 
       ! Computation of the silicon dependant half saturation  constant for silica uptake
@@ -50,5 +51,5 @@
       DO ji = 1, jpi
          DO jj = 1, jpj
-            zvar = trb(ji,jj,1,jpsil) * trb(ji,jj,1,jpsil)
+            zvar = tr(ji,jj,1,jpsil,Kbb) * tr(ji,jj,1,jpsil,Kbb)
             xksimax(ji,jj) = MAX( xksimax(ji,jj), ( 1.+ 7.* zvar / ( xksilim * xksilim + zvar ) ) * 1e-6 )
          END DO
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zligand.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zligand.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zligand.F90	(revision 13463)
@@ -12,5 +12,5 @@
    USE trc             ! passive tracers common variables 
    USE sms_pisces      ! PISCES Source Minus Sink variables
-   USE prtctl_trc      ! print control for debugging
+   USE prtctl          ! print control for debugging
    USE iom             !  I/O manager
 
@@ -26,4 +26,6 @@
    REAL(wp), PUBLIC ::  prlgw    !: Photochemical of weak ligand
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -33,5 +35,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_ligand( kt, knt )
+   SUBROUTINE p4z_ligand( kt, knt, Kbb, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_ligand  ***
@@ -39,10 +41,10 @@
       !! ** Purpose :   Compute remineralization/scavenging of organic ligands
       !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt, knt ! ocean time step
+      INTEGER, INTENT(in) ::   kt, knt   ! ocean time step
+      INTEGER, INTENT(in)  ::  Kbb, Krhs ! time level indices
       !
       INTEGER  ::   ji, jj, jk
       REAL(wp) ::   zlgwp, zlgwpr, zlgwr, zlablgw
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zligrem, zligpr, zrligprod
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   zw3d
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zligrem, zligpr, zligprod
       CHARACTER (len=25) ::   charout
       !!---------------------------------------------------------------------
@@ -50,52 +52,43 @@
       IF( ln_timing )   CALL timing_start('p4z_ligand')
       !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               !
-               ! ------------------------------------------------------------------
-               ! Remineralization of iron ligands
-               ! ------------------------------------------------------------------
-               ! production from remineralisation of organic matter
-               zlgwp = orem(ji,jj,jk) * rlig
-               ! decay of weak ligand
-               ! This is based on the idea that as LGW is lower
-               ! there is a larger fraction of refractory OM
-               zlgwr = max( rlgs , rlgw * exp( -2 * (trb(ji,jj,jk,jplgw)*1e9) ) ) ! years
-               zlgwr = 1. / zlgwr * tgfunc(ji,jj,jk) * ( xstep / nyear_len(1) ) * blim(ji,jj,jk) * trb(ji,jj,jk,jplgw)
-               ! photochem loss of weak ligand
-               zlgwpr = prlgw * xstep * etot(ji,jj,jk) * trb(ji,jj,jk,jplgw) * (1. - fr_i(ji,jj))
-               tra(ji,jj,jk,jplgw) = tra(ji,jj,jk,jplgw) + zlgwp - zlgwr - zlgwpr
-               zligrem(ji,jj,jk)   = zlgwr
-               zligpr(ji,jj,jk)    = zlgwpr
-               zrligprod(ji,jj,jk) = zlgwp
-               !
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         !
+         ! ------------------------------------------------------------------
+         ! Remineralization of iron ligands
+         ! ------------------------------------------------------------------
+         ! production from remineralisation of organic matter
+         zlgwp = orem(ji,jj,jk) * rlig
+         ! decay of weak ligand
+         ! This is based on the idea that as LGW is lower
+         ! there is a larger fraction of refractory OM
+         zlgwr = max( rlgs , rlgw * exp( -2 * (tr(ji,jj,jk,jplgw,Kbb)*1e9) ) ) ! years
+         zlgwr = 1. / zlgwr * tgfunc(ji,jj,jk) * ( xstep / nyear_len(1) ) * blim(ji,jj,jk) * tr(ji,jj,jk,jplgw,Kbb)
+         ! photochem loss of weak ligand
+         zlgwpr = prlgw * xstep * etot(ji,jj,jk) * tr(ji,jj,jk,jplgw,Kbb) * (1. - fr_i(ji,jj))
+         tr(ji,jj,jk,jplgw,Krhs) = tr(ji,jj,jk,jplgw,Krhs) + zlgwp - zlgwr - zlgwpr
+         zligrem(ji,jj,jk)   = zlgwr
+         zligpr(ji,jj,jk)    = zlgwpr
+         zligprod(ji,jj,jk) = zlgwp
+         !
+      END_3D
       !
       !  Output of some diagnostics variables
       !     ---------------------------------
       IF( lk_iomput .AND. knt == nrdttrc ) THEN
-         ALLOCATE( zw3d(jpi,jpj,jpk) )
          IF( iom_use( "LIGREM" ) ) THEN
-            zw3d(:,:,:) = zligrem(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:)
-            CALL iom_put( "LIGREM", zw3d )
+           zligrem(:,:,jpk) = 0.  ; CALL iom_put( "LIGREM", zligrem(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:) )
          ENDIF
          IF( iom_use( "LIGPR" ) ) THEN
-            zw3d(:,:,:) = zligpr(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:) 
-            CALL iom_put( "LIGPR", zw3d )
+           zligpr(:,:,jpk) = 0.   ; CALL iom_put( "LIGPR" , zligpr(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:) )
          ENDIF
          IF( iom_use( "LPRODR" ) ) THEN
-            zw3d(:,:,:) = zrligprod(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:) 
-            CALL iom_put( "LPRODR", zw3d )
+           zligprod(:,:,jpk) = 0. ; CALL iom_put( "LPRODR", zligprod(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:) )
          ENDIF
-         DEALLOCATE( zw3d )
       ENDIF
       !
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('ligand1')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -125,10 +118,8 @@
          WRITE(numout,*) '~~~~~~~~~~~~~~~'
       ENDIF
-      REWIND( numnatp_ref )              ! Namelist nampislig in reference namelist : Pisces remineralization
       READ  ( numnatp_ref, nampislig, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampislig in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampislig in configuration namelist : Pisces remineralization
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampislig in reference namelist' )
       READ  ( numnatp_cfg, nampislig, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampislig in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampislig in configuration namelist' )
       IF(lwm) WRITE ( numonp, nampislig )
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zlim.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zlim.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zlim.F90	(revision 13463)
@@ -67,4 +67,6 @@
    REAL(wp) ::  xcoef3   = 1.15E-4 * 14. / 55.85 / 7.625 * 0.5 
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -74,5 +76,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_lim( kt, knt )
+   SUBROUTINE p4z_lim( kt, knt, Kbb, Kmm )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_lim  ***
@@ -84,4 +86,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in)  :: kt, knt
+      INTEGER, INTENT(in)  :: Kbb, Kmm      ! time level indices
       !
       INTEGER  ::   ji, jj, jk
@@ -95,129 +98,117 @@
       IF( ln_timing )   CALL timing_start('p4z_lim')
       !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               
-               ! Tuning of the iron concentration to a minimum level that is set to the detection limit
-               !-------------------------------------
-               zno3    = trb(ji,jj,jk,jpno3) / 40.e-6
-               zferlim = MAX( 3e-11 * zno3 * zno3, 5e-12 )
-               zferlim = MIN( zferlim, 7e-11 )
-               trb(ji,jj,jk,jpfer) = MAX( trb(ji,jj,jk,jpfer), zferlim )
-
-               ! Computation of a variable Ks for iron on diatoms taking into account
-               ! that increasing biomass is made of generally bigger cells
-               !------------------------------------------------
-               zconcd   = MAX( 0.e0 , trb(ji,jj,jk,jpdia) - xsizedia )
-               zconcd2  = trb(ji,jj,jk,jpdia) - zconcd
-               zconcn   = MAX( 0.e0 , trb(ji,jj,jk,jpphy) - xsizephy )
-               zconcn2  = trb(ji,jj,jk,jpphy) - zconcn
-               z1_trbphy   = 1. / ( trb(ji,jj,jk,jpphy) + rtrn )
-               z1_trbdia   = 1. / ( trb(ji,jj,jk,jpdia) + rtrn )
-
-               concdfe(ji,jj,jk) = MAX( concdfer, ( zconcd2 * concdfer + concdfer * xsizerd * zconcd ) * z1_trbdia )
-               zconc1d           = MAX( concdno3, ( zconcd2 * concdno3 + concdno3 * xsizerd * zconcd ) * z1_trbdia )
-               zconc1dnh4        = MAX( concdnh4, ( zconcd2 * concdnh4 + concdnh4 * xsizerd * zconcd ) * z1_trbdia )
-
-               concnfe(ji,jj,jk) = MAX( concnfer, ( zconcn2 * concnfer + concnfer * xsizern * zconcn ) * z1_trbphy )
-               zconc0n           = MAX( concnno3, ( zconcn2 * concnno3 + concnno3 * xsizern * zconcn ) * z1_trbphy )
-               zconc0nnh4        = MAX( concnnh4, ( zconcn2 * concnnh4 + concnnh4 * xsizern * zconcn ) * z1_trbphy )
-
-               ! Michaelis-Menten Limitation term for nutrients Small bacteria
-               ! -------------------------------------------------------------
-               zdenom = 1. /  ( concbno3 * concbnh4 + concbnh4 * trb(ji,jj,jk,jpno3) + concbno3 * trb(ji,jj,jk,jpnh4) )
-               xnanono3(ji,jj,jk) = trb(ji,jj,jk,jpno3) * concbnh4 * zdenom
-               xnanonh4(ji,jj,jk) = trb(ji,jj,jk,jpnh4) * concbno3 * zdenom
-               !
-               zlim1    = xnanono3(ji,jj,jk) + xnanonh4(ji,jj,jk)
-               zlim2    = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + concbnh4 )
-               zlim3    = trb(ji,jj,jk,jpfer) / ( concbfe + trb(ji,jj,jk,jpfer) )
-               zlim4    = trb(ji,jj,jk,jpdoc) / ( xkdoc   + trb(ji,jj,jk,jpdoc) )
-               xlimbacl(ji,jj,jk) = MIN( zlim1, zlim2, zlim3 )
-               xlimbac (ji,jj,jk) = MIN( zlim1, zlim2, zlim3 ) * zlim4
-
-               ! Michaelis-Menten Limitation term for nutrients Small flagellates
-               ! -----------------------------------------------
-               zdenom = 1. /  ( zconc0n * zconc0nnh4 + zconc0nnh4 * trb(ji,jj,jk,jpno3) + zconc0n * trb(ji,jj,jk,jpnh4) )
-               xnanono3(ji,jj,jk) = trb(ji,jj,jk,jpno3) * zconc0nnh4 * zdenom
-               xnanonh4(ji,jj,jk) = trb(ji,jj,jk,jpnh4) * zconc0n    * zdenom
-               !
-               zlim1    = xnanono3(ji,jj,jk) + xnanonh4(ji,jj,jk)
-               zlim2    = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zconc0nnh4 )
-               zratio   = trb(ji,jj,jk,jpnfe) * z1_trbphy 
-               zironmin = xcoef1 * trb(ji,jj,jk,jpnch) * z1_trbphy + xcoef2 * zlim1 + xcoef3 * xnanono3(ji,jj,jk)
-               zlim3    = MAX( 0.,( zratio - zironmin ) / qnfelim )
-               xnanopo4(ji,jj,jk) = zlim2
-               xlimnfe (ji,jj,jk) = MIN( 1., zlim3 )
-               xlimphy (ji,jj,jk) = MIN( zlim1, zlim2, zlim3 )
-               !
-               !   Michaelis-Menten Limitation term for nutrients Diatoms
-               !   ----------------------------------------------
-               zdenom   = 1. / ( zconc1d * zconc1dnh4 + zconc1dnh4 * trb(ji,jj,jk,jpno3) + zconc1d * trb(ji,jj,jk,jpnh4) )
-               xdiatno3(ji,jj,jk) = trb(ji,jj,jk,jpno3) * zconc1dnh4 * zdenom
-               xdiatnh4(ji,jj,jk) = trb(ji,jj,jk,jpnh4) * zconc1d    * zdenom
-               !
-               zlim1    = xdiatno3(ji,jj,jk) + xdiatnh4(ji,jj,jk)
-               zlim2    = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zconc1dnh4  )
-               zlim3    = trb(ji,jj,jk,jpsil) / ( trb(ji,jj,jk,jpsil) + xksi(ji,jj) )
-               zratio   = trb(ji,jj,jk,jpdfe) * z1_trbdia
-               zironmin = xcoef1 * trb(ji,jj,jk,jpdch) * z1_trbdia + xcoef2 * zlim1 + xcoef3 * xdiatno3(ji,jj,jk)
-               zlim4    = MAX( 0., ( zratio - zironmin ) / qdfelim )
-               xdiatpo4(ji,jj,jk) = zlim2
-               xlimdfe (ji,jj,jk) = MIN( 1., zlim4 )
-               xlimdia (ji,jj,jk) = MIN( zlim1, zlim2, zlim3, zlim4 )
-               xlimsi  (ji,jj,jk) = MIN( zlim1, zlim2, zlim4 )
-           END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         
+         ! Tuning of the iron concentration to a minimum level that is set to the detection limit
+         !-------------------------------------
+         zno3    = tr(ji,jj,jk,jpno3,Kbb) / 40.e-6
+         zferlim = MAX( 3e-11 * zno3 * zno3, 5e-12 )
+         zferlim = MIN( zferlim, 7e-11 )
+         tr(ji,jj,jk,jpfer,Kbb) = MAX( tr(ji,jj,jk,jpfer,Kbb), zferlim )
+
+         ! Computation of a variable Ks for iron on diatoms taking into account
+         ! that increasing biomass is made of generally bigger cells
+         !------------------------------------------------
+         zconcd   = MAX( 0.e0 , tr(ji,jj,jk,jpdia,Kbb) - xsizedia )
+         zconcd2  = tr(ji,jj,jk,jpdia,Kbb) - zconcd
+         zconcn   = MAX( 0.e0 , tr(ji,jj,jk,jpphy,Kbb) - xsizephy )
+         zconcn2  = tr(ji,jj,jk,jpphy,Kbb) - zconcn
+         z1_trbphy   = 1. / ( tr(ji,jj,jk,jpphy,Kbb) + rtrn )
+         z1_trbdia   = 1. / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+
+         concdfe(ji,jj,jk) = MAX( concdfer, ( zconcd2 * concdfer + concdfer * xsizerd * zconcd ) * z1_trbdia )
+         zconc1d           = MAX( concdno3, ( zconcd2 * concdno3 + concdno3 * xsizerd * zconcd ) * z1_trbdia )
+         zconc1dnh4        = MAX( concdnh4, ( zconcd2 * concdnh4 + concdnh4 * xsizerd * zconcd ) * z1_trbdia )
+
+         concnfe(ji,jj,jk) = MAX( concnfer, ( zconcn2 * concnfer + concnfer * xsizern * zconcn ) * z1_trbphy )
+         zconc0n           = MAX( concnno3, ( zconcn2 * concnno3 + concnno3 * xsizern * zconcn ) * z1_trbphy )
+         zconc0nnh4        = MAX( concnnh4, ( zconcn2 * concnnh4 + concnnh4 * xsizern * zconcn ) * z1_trbphy )
+
+         ! Michaelis-Menten Limitation term for nutrients Small bacteria
+         ! -------------------------------------------------------------
+         zdenom = 1. /  ( concbno3 * concbnh4 + concbnh4 * tr(ji,jj,jk,jpno3,Kbb) + concbno3 * tr(ji,jj,jk,jpnh4,Kbb) )
+         xnanono3(ji,jj,jk) = tr(ji,jj,jk,jpno3,Kbb) * concbnh4 * zdenom
+         xnanonh4(ji,jj,jk) = tr(ji,jj,jk,jpnh4,Kbb) * concbno3 * zdenom
+         !
+         zlim1    = xnanono3(ji,jj,jk) + xnanonh4(ji,jj,jk)
+         zlim2    = tr(ji,jj,jk,jppo4,Kbb) / ( tr(ji,jj,jk,jppo4,Kbb) + concbnh4 )
+         zlim3    = tr(ji,jj,jk,jpfer,Kbb) / ( concbfe + tr(ji,jj,jk,jpfer,Kbb) )
+         zlim4    = tr(ji,jj,jk,jpdoc,Kbb) / ( xkdoc   + tr(ji,jj,jk,jpdoc,Kbb) )
+         xlimbacl(ji,jj,jk) = MIN( zlim1, zlim2, zlim3 )
+         xlimbac (ji,jj,jk) = MIN( zlim1, zlim2, zlim3 ) * zlim4
+
+         ! Michaelis-Menten Limitation term for nutrients Small flagellates
+         ! -----------------------------------------------
+         zdenom = 1. /  ( zconc0n * zconc0nnh4 + zconc0nnh4 * tr(ji,jj,jk,jpno3,Kbb) + zconc0n * tr(ji,jj,jk,jpnh4,Kbb) )
+         xnanono3(ji,jj,jk) = tr(ji,jj,jk,jpno3,Kbb) * zconc0nnh4 * zdenom
+         xnanonh4(ji,jj,jk) = tr(ji,jj,jk,jpnh4,Kbb) * zconc0n    * zdenom
+         !
+         zlim1    = xnanono3(ji,jj,jk) + xnanonh4(ji,jj,jk)
+         zlim2    = tr(ji,jj,jk,jppo4,Kbb) / ( tr(ji,jj,jk,jppo4,Kbb) + zconc0nnh4 )
+         zratio   = tr(ji,jj,jk,jpnfe,Kbb) * z1_trbphy 
+         zironmin = xcoef1 * tr(ji,jj,jk,jpnch,Kbb) * z1_trbphy + xcoef2 * zlim1 + xcoef3 * xnanono3(ji,jj,jk)
+         zlim3    = MAX( 0.,( zratio - zironmin ) / qnfelim )
+         xnanopo4(ji,jj,jk) = zlim2
+         xlimnfe (ji,jj,jk) = MIN( 1., zlim3 )
+         xlimphy (ji,jj,jk) = MIN( zlim1, zlim2, zlim3 )
+         !
+         !   Michaelis-Menten Limitation term for nutrients Diatoms
+         !   ----------------------------------------------
+         zdenom   = 1. / ( zconc1d * zconc1dnh4 + zconc1dnh4 * tr(ji,jj,jk,jpno3,Kbb) + zconc1d * tr(ji,jj,jk,jpnh4,Kbb) )
+         xdiatno3(ji,jj,jk) = tr(ji,jj,jk,jpno3,Kbb) * zconc1dnh4 * zdenom
+         xdiatnh4(ji,jj,jk) = tr(ji,jj,jk,jpnh4,Kbb) * zconc1d    * zdenom
+         !
+         zlim1    = xdiatno3(ji,jj,jk) + xdiatnh4(ji,jj,jk)
+         zlim2    = tr(ji,jj,jk,jppo4,Kbb) / ( tr(ji,jj,jk,jppo4,Kbb) + zconc1dnh4  )
+         zlim3    = tr(ji,jj,jk,jpsil,Kbb) / ( tr(ji,jj,jk,jpsil,Kbb) + xksi(ji,jj) + rtrn )
+         zratio   = tr(ji,jj,jk,jpdfe,Kbb) * z1_trbdia
+         zironmin = xcoef1 * tr(ji,jj,jk,jpdch,Kbb) * z1_trbdia + xcoef2 * zlim1 + xcoef3 * xdiatno3(ji,jj,jk)
+         zlim4    = MAX( 0., ( zratio - zironmin ) / qdfelim )
+         xdiatpo4(ji,jj,jk) = zlim2
+         xlimdfe (ji,jj,jk) = MIN( 1., zlim4 )
+         xlimdia (ji,jj,jk) = MIN( zlim1, zlim2, zlim3, zlim4 )
+         xlimsi  (ji,jj,jk) = MIN( zlim1, zlim2, zlim4 )
+      END_3D
 
       ! Compute the fraction of nanophytoplankton that is made of calcifiers
       ! --------------------------------------------------------------------
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zlim1 =  ( trb(ji,jj,jk,jpno3) * concnnh4 + trb(ji,jj,jk,jpnh4) * concnno3 )    &
-                  &   / ( concnno3 * concnnh4 + concnnh4 * trb(ji,jj,jk,jpno3) + concnno3 * trb(ji,jj,jk,jpnh4) ) 
-               zlim2  = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + concnnh4 )
-               zlim3  = trb(ji,jj,jk,jpfer) / ( trb(ji,jj,jk,jpfer) +  5.E-11   )
-               ztem1  = MAX( 0., tsn(ji,jj,jk,jp_tem) )
-               ztem2  = tsn(ji,jj,jk,jp_tem) - 10.
-               zetot1 = MAX( 0., etot_ndcy(ji,jj,jk) - 1.) / ( 4. + etot_ndcy(ji,jj,jk) ) 
-               zetot2 = 30. / ( 30. + etot_ndcy(ji,jj,jk) ) 
-
-               xfracal(ji,jj,jk) = caco3r * MIN( zlim1, zlim2, zlim3 )                  &
-                  &                       * ztem1 / ( 0.1 + ztem1 )                     &
-                  &                       * MAX( 1., trb(ji,jj,jk,jpphy) * 1.e6 / 2. )  &
-                  &                       * zetot1 * zetot2               &
-                  &                       * ( 1. + EXP(-ztem2 * ztem2 / 25. ) )         &
-                  &                       * MIN( 1., 50. / ( hmld(ji,jj) + rtrn ) )
-               xfracal(ji,jj,jk) = MIN( 0.8 , xfracal(ji,jj,jk) )
-               xfracal(ji,jj,jk) = MAX( 0.02, xfracal(ji,jj,jk) )
-            END DO
-         END DO
-      END DO
-      !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! denitrification factor computed from O2 levels
-               nitrfac(ji,jj,jk) = MAX(  0.e0, 0.4 * ( 6.e-6  - trb(ji,jj,jk,jpoxy) )    &
-                  &                                / ( oxymin + trb(ji,jj,jk,jpoxy) )  )
-               nitrfac(ji,jj,jk) = MIN( 1., nitrfac(ji,jj,jk) )
-               !
-               ! denitrification factor computed from NO3 levels
-               nitrfac2(ji,jj,jk) = MAX( 0.e0,       ( 1.E-6 - trb(ji,jj,jk,jpno3) )  &
-                  &                                / ( 1.E-6 + trb(ji,jj,jk,jpno3) ) )
-               nitrfac2(ji,jj,jk) = MIN( 1., nitrfac2(ji,jj,jk) )
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zlim1 =  ( tr(ji,jj,jk,jpno3,Kbb) * concnnh4 + tr(ji,jj,jk,jpnh4,Kbb) * concnno3 )    &
+            &   / ( concnno3 * concnnh4 + concnnh4 * tr(ji,jj,jk,jpno3,Kbb) + concnno3 * tr(ji,jj,jk,jpnh4,Kbb) ) 
+         zlim2  = tr(ji,jj,jk,jppo4,Kbb) / ( tr(ji,jj,jk,jppo4,Kbb) + concnnh4 )
+         zlim3  = tr(ji,jj,jk,jpfer,Kbb) / ( tr(ji,jj,jk,jpfer,Kbb) +  5.E-11   )
+         ztem1  = MAX( 0., ts(ji,jj,jk,jp_tem,Kmm) )
+         ztem2  = ts(ji,jj,jk,jp_tem,Kmm) - 10.
+         zetot1 = MAX( 0., etot_ndcy(ji,jj,jk) - 1.) / ( 4. + etot_ndcy(ji,jj,jk) ) 
+         zetot2 = 30. / ( 30. + etot_ndcy(ji,jj,jk) ) 
+
+         xfracal(ji,jj,jk) = caco3r * MIN( zlim1, zlim2, zlim3 )                  &
+            &                       * ztem1 / ( 0.1 + ztem1 )                     &
+            &                       * MAX( 1., tr(ji,jj,jk,jpphy,Kbb) * 1.e6 / 2. )  &
+            &                       * zetot1 * zetot2               &
+            &                       * ( 1. + EXP(-ztem2 * ztem2 / 25. ) )         &
+            &                       * MIN( 1., 50. / ( hmld(ji,jj) + rtrn ) )
+         xfracal(ji,jj,jk) = MIN( 0.8 , xfracal(ji,jj,jk) )
+         xfracal(ji,jj,jk) = MAX( 0.02, xfracal(ji,jj,jk) )
+      END_3D
+      !
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         ! denitrification factor computed from O2 levels
+         nitrfac(ji,jj,jk) = MAX(  0.e0, 0.4 * ( 6.e-6  - tr(ji,jj,jk,jpoxy,Kbb) )    &
+            &                                / ( oxymin + tr(ji,jj,jk,jpoxy,Kbb) )  )
+         nitrfac(ji,jj,jk) = MIN( 1., nitrfac(ji,jj,jk) )
+         !
+         ! denitrification factor computed from NO3 levels
+         nitrfac2(ji,jj,jk) = MAX( 0.e0,       ( 1.E-6 - tr(ji,jj,jk,jpno3,Kbb) )  &
+            &                                / ( 1.E-6 + tr(ji,jj,jk,jpno3,Kbb) ) )
+         nitrfac2(ji,jj,jk) = MIN( 1., nitrfac2(ji,jj,jk) )
+      END_3D
       !
       IF( lk_iomput .AND. knt == nrdttrc ) THEN        ! save output diagnostics
-        IF( iom_use( "xfracal" ) )   CALL iom_put( "xfracal", xfracal(:,:,:) * tmask(:,:,:) )  ! euphotic layer deptht
-        IF( iom_use( "LNnut"   ) )   CALL iom_put( "LNnut"  , xlimphy(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
-        IF( iom_use( "LDnut"   ) )   CALL iom_put( "LDnut"  , xlimdia(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
-        IF( iom_use( "LNFe"    ) )   CALL iom_put( "LNFe"   , xlimnfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
-        IF( iom_use( "LDFe"    ) )   CALL iom_put( "LDFe"   , xlimdfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+        CALL iom_put( "xfracal", xfracal(:,:,:) * tmask(:,:,:) )  ! euphotic layer deptht
+        CALL iom_put( "LNnut"  , xlimphy(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
+        CALL iom_put( "LDnut"  , xlimdia(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
+        CALL iom_put( "LNFe"   , xlimnfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+        CALL iom_put( "LDFe"   , xlimdfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
       ENDIF
       !
@@ -252,10 +243,8 @@
       ENDIF
       !
-      REWIND( numnatp_ref )              ! Namelist nampislim in reference namelist : Pisces nutrient limitation parameters
       READ  ( numnatp_ref, namp4zlim, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zlim in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampislim in configuration namelist : Pisces nutrient limitation parameters 
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zlim in reference namelist' )
       READ  ( numnatp_cfg, namp4zlim, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zlim in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zlim in configuration namelist' )
       IF(lwm) WRITE( numonp, namp4zlim )
       !
@@ -284,5 +273,11 @@
       ENDIF
       !
-      nitrfac (:,:,:) = 0._wp
+      nitrfac (:,:,jpk) = 0._wp
+      nitrfac2(:,:,jpk) = 0._wp
+      xfracal (:,:,jpk) = 0._wp
+      xlimphy (:,:,jpk) = 0._wp
+      xlimdia (:,:,jpk) = 0._wp
+      xlimnfe (:,:,jpk) = 0._wp
+      xlimdfe (:,:,jpk) = 0._wp
       !
    END SUBROUTINE p4z_lim_init
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zlys.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zlys.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zlys.F90	(revision 13463)
@@ -20,5 +20,5 @@
    USE sms_pisces      !  PISCES Source Minus Sink variables
    USE p4zche          !  Chemical model
-   USE prtctl_trc      !  print control for debugging
+   USE prtctl          !  print control for debugging
    USE iom             !  I/O manager
 
@@ -35,4 +35,6 @@
    REAL(wp) ::   calcon = 1.03E-2   ! mean calcite concentration [Ca2+] in sea water [mole/kg solution]
  
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -43,5 +45,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_lys( kt, knt )
+   SUBROUTINE p4z_lys( kt, knt, Kbb, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_lys  ***
@@ -54,4 +56,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt, knt   ! ocean time step and ???
+      INTEGER, INTENT(in)  ::  Kbb, Krhs ! time level indices
       !
       INTEGER  ::   ji, jj, jk, jn
@@ -64,6 +67,4 @@
       IF( ln_timing )  CALL timing_start('p4z_lys')
       !
-      zco3    (:,:,:) = 0.
-      zcaldiss(:,:,:) = 0.
       zhinit  (:,:,:) = hi(:,:,:) * 1000. / ( rhop(:,:,:) + rtrn )
       !
@@ -72,15 +73,11 @@
       !     -------------------------------------------
 
-      CALL solve_at_general( zhinit, zhi )
+      CALL solve_at_general( zhinit, zhi, Kbb )
 
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zco3(ji,jj,jk) = trb(ji,jj,jk,jpdic) * ak13(ji,jj,jk) * ak23(ji,jj,jk) / (zhi(ji,jj,jk)**2   &
-                  &             + ak13(ji,jj,jk) * zhi(ji,jj,jk) + ak13(ji,jj,jk) * ak23(ji,jj,jk) + rtrn )
-               hi  (ji,jj,jk) = zhi(ji,jj,jk) * rhop(ji,jj,jk) / 1000.
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zco3(ji,jj,jk) = tr(ji,jj,jk,jpdic,Kbb) * ak13(ji,jj,jk) * ak23(ji,jj,jk) / (zhi(ji,jj,jk)**2   &
+            &             + ak13(ji,jj,jk) * zhi(ji,jj,jk) + ak13(ji,jj,jk) * ak23(ji,jj,jk) + rtrn )
+         hi  (ji,jj,jk) = zhi(ji,jj,jk) * rhop(ji,jj,jk) / 1000.
+      END_3D
 
       !     ---------------------------------------------------------
@@ -90,47 +87,49 @@
       !     ---------------------------------------------------------
 
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
 
-               ! DEVIATION OF [CO3--] FROM SATURATION VALUE
-               ! Salinity dependance in zomegaca and divide by rhop/1000 to have good units
-               zcalcon  = calcon * ( salinprac(ji,jj,jk) / 35._wp )
-               zfact    = rhop(ji,jj,jk) / 1000._wp
-               zomegaca = ( zcalcon * zco3(ji,jj,jk) ) / ( aksp(ji,jj,jk) * zfact + rtrn )
-               zco3sat(ji,jj,jk) = aksp(ji,jj,jk) * zfact / ( zcalcon + rtrn )
+         ! DEVIATION OF [CO3--] FROM SATURATION VALUE
+         ! Salinity dependance in zomegaca and divide by rhop/1000 to have good units
+         zcalcon  = calcon * ( salinprac(ji,jj,jk) / 35._wp )
+         zfact    = rhop(ji,jj,jk) / 1000._wp
+         zomegaca = ( zcalcon * zco3(ji,jj,jk) ) / ( aksp(ji,jj,jk) * zfact + rtrn )
+         zco3sat(ji,jj,jk) = aksp(ji,jj,jk) * zfact / ( zcalcon + rtrn )
 
-               ! SET DEGREE OF UNDER-/SUPERSATURATION
-               excess(ji,jj,jk) = 1._wp - zomegaca
-               zexcess0 = MAX( 0., excess(ji,jj,jk) )
-               zexcess  = zexcess0**nca
+         ! SET DEGREE OF UNDER-/SUPERSATURATION
+         excess(ji,jj,jk) = 1._wp - zomegaca
+         zexcess0 = MAX( 0., excess(ji,jj,jk) )
+         zexcess  = zexcess0**nca
 
-               ! AMOUNT CACO3 (12C) THAT RE-ENTERS SOLUTION
-               !       (ACCORDING TO THIS FORMULATION ALSO SOME PARTICULATE
-               !       CACO3 GETS DISSOLVED EVEN IN THE CASE OF OVERSATURATION)
-               zdispot = kdca * zexcess * trb(ji,jj,jk,jpcal)
-              !  CHANGE OF [CO3--] , [ALK], PARTICULATE [CACO3],
-              !       AND [SUM(CO2)] DUE TO CACO3 DISSOLUTION/PRECIPITATION
-              zcaldiss(ji,jj,jk)  = zdispot * rfact2 / rmtss ! calcite dissolution
-              !
-              tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) + 2. * zcaldiss(ji,jj,jk)
-              tra(ji,jj,jk,jpcal) = tra(ji,jj,jk,jpcal) -      zcaldiss(ji,jj,jk)
-              tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) +      zcaldiss(ji,jj,jk)
-            END DO
-         END DO
-      END DO
+         ! AMOUNT CACO3 (12C) THAT RE-ENTERS SOLUTION
+         !       (ACCORDING TO THIS FORMULATION ALSO SOME PARTICULATE
+         !       CACO3 GETS DISSOLVED EVEN IN THE CASE OF OVERSATURATION)
+         zdispot = kdca * zexcess * tr(ji,jj,jk,jpcal,Kbb)
+        !  CHANGE OF [CO3--] , [ALK], PARTICULATE [CACO3],
+        !       AND [SUM(CO2)] DUE TO CACO3 DISSOLUTION/PRECIPITATION
+        zcaldiss(ji,jj,jk)  = zdispot * rfact2 / rmtss ! calcite dissolution
+        !
+        tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) + 2. * zcaldiss(ji,jj,jk)
+        tr(ji,jj,jk,jpcal,Krhs) = tr(ji,jj,jk,jpcal,Krhs) -      zcaldiss(ji,jj,jk)
+        tr(ji,jj,jk,jpdic,Krhs) = tr(ji,jj,jk,jpdic,Krhs) +      zcaldiss(ji,jj,jk)
+      END_3D
       !
 
       IF( lk_iomput .AND. knt == nrdttrc ) THEN
-         IF( iom_use( "PH"     ) ) CALL iom_put( "PH"    , -1. * LOG10( MAX( hi(:,:,:), rtrn ) ) * tmask(:,:,:) )
-         IF( iom_use( "CO3"    ) ) CALL iom_put( "CO3"   , zco3(:,:,:)     * 1.e+3               * tmask(:,:,:) )
-         IF( iom_use( "CO3sat" ) ) CALL iom_put( "CO3sat", zco3sat(:,:,:)  * 1.e+3               * tmask(:,:,:) )
-         IF( iom_use( "DCAL"   ) ) CALL iom_put( "DCAL"  , zcaldiss(:,:,:) * 1.e+3 * rfact2r     * tmask(:,:,:) )
+         CALL iom_put( "PH" , -1. * LOG10( MAX( hi(:,:,:), rtrn ) ) * tmask(:,:,:) )
+         IF( iom_use( "CO3" ) ) THEN
+            zco3(:,:,jpk) = 0.    ; CALL iom_put( "CO3"   , zco3(:,:,:)     * 1.e+3           * tmask(:,:,:) )
+         ENDIF
+         IF( iom_use( "CO3sat" ) ) THEN
+           zco3sat(:,:,jpk) = 0.  ; CALL iom_put( "CO3sat", zco3sat(:,:,:)  * 1.e+3           * tmask(:,:,:) )
+         ENDIF
+         IF( iom_use( "DCAL" ) ) THEN
+           zcaldiss(:,:,jpk) = 0. ; CALL iom_put( "DCAL"  , zcaldiss(:,:,:) * 1.e+3 * rfact2r * tmask(:,:,:) )
+         ENDIF              
       ENDIF
       !
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
         WRITE(charout, FMT="('lys ')")
-        CALL prt_ctl_trc_info(charout)
-        CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+        CALL prt_ctl_info( charout, cdcomp = 'top' )
+        CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -162,10 +161,8 @@
       ENDIF
       !
-      REWIND( numnatp_ref )              ! Namelist nampiscal in reference namelist : Pisces CaCO3 dissolution
       READ  ( numnatp_ref, nampiscal, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampiscal in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampiscal in configuration namelist : Pisces CaCO3 dissolution
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampiscal in reference namelist' )
       READ  ( numnatp_cfg, nampiscal, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampiscal in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampiscal in configuration namelist' )
       IF(lwm) WRITE( numonp, nampiscal )
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zmeso.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zmeso.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zmeso.F90	(revision 13463)
@@ -15,5 +15,5 @@
    USE sms_pisces      ! PISCES Source Minus Sink variables
    USE p4zprod         ! production
-   USE prtctl_trc      ! print control for debugging
+   USE prtctl          ! print control for debugging
    USE iom             ! I/O manager
 
@@ -44,4 +44,6 @@
    REAL(wp), PUBLIC ::  grazflux     !: mesozoo flux feeding rate
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -51,5 +53,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_meso( kt, knt )
+   SUBROUTINE p4z_meso( kt, knt, Kbb, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_meso  ***
@@ -60,4 +62,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt, knt   ! ocean time step and ???
+      INTEGER, INTENT(in)  ::  Kbb, Krhs ! time level indices
       !
       INTEGER  :: ji, jj, jk
@@ -66,197 +69,183 @@
       REAL(wp) :: zfact   , zfood, zfoodlim, zproport, zbeta
       REAL(wp) :: zmortzgoc, zfrac, zfracfe, zratio, zratio2, zfracal, zgrazcal
-      REAL(wp) :: zepsherf, zepshert, zepsherv, zgrarsig, zgraztotc, zgraztotn, zgraztotf
+      REAL(wp) :: zepsherf, zepshert, zepsherv, zepsherq 
+      REAL(wp) :: zgrarsig, zgraztotc, zgraztotn, zgraztotf
       REAL(wp) :: zgrarem2, zgrafer2, zgrapoc2, zprcaca, zmortz, zgrasrat, zgrasratn
       REAL(wp) :: zrespz, ztortz, zgrazd, zgrazz, zgrazpof
       REAL(wp) :: zgrazn, zgrazpoc, zgraznf, zgrazf
       REAL(wp) :: zgrazfffp, zgrazfffg, zgrazffep, zgrazffeg
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zgrazing2, zfezoo2, zz2ligprod
       CHARACTER (len=25) :: charout
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zgrazing, zfezoo2
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   zw3d, zz2ligprod
       !!---------------------------------------------------------------------
       !
       IF( ln_timing )   CALL timing_start('p4z_meso')
       !
-      zgrazing(:,:,:) = 0._wp
-      zfezoo2 (:,:,:) = 0._wp
-      !
-      IF (ln_ligand) THEN
-         ALLOCATE( zz2ligprod(jpi,jpj,jpk) )
-         zz2ligprod(:,:,:) = 0._wp
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zcompam   = MAX( ( tr(ji,jj,jk,jpmes,Kbb) - 1.e-9 ), 0.e0 )
+         zfact     = xstep * tgfunc2(ji,jj,jk) * zcompam
+
+         !  Respiration rates of both zooplankton
+         !  -------------------------------------
+         zrespz    = resrat2 * zfact * ( tr(ji,jj,jk,jpmes,Kbb) / ( xkmort + tr(ji,jj,jk,jpmes,Kbb) )  &
+         &           + 3. * nitrfac(ji,jj,jk) )
+
+         !  Zooplankton mortality. A square function has been selected with
+         !  no real reason except that it seems to be more stable and may mimic predation
+         !  ---------------------------------------------------------------
+         ztortz    = mzrat2 * 1.e6 * zfact * tr(ji,jj,jk,jpmes,Kbb)  * (1. - nitrfac(ji,jj,jk) )
+         !
+         zcompadi  = MAX( ( tr(ji,jj,jk,jpdia,Kbb) - xthresh2dia ), 0.e0 )
+         zcompaz   = MAX( ( tr(ji,jj,jk,jpzoo,Kbb) - xthresh2zoo ), 0.e0 )
+         zcompapoc = MAX( ( tr(ji,jj,jk,jppoc,Kbb) - xthresh2poc ), 0.e0 )
+         ! Size effect of nanophytoplankton on grazing : the smaller it is, the less prone
+         ! it is to predation by mesozooplankton
+         ! -------------------------------------------------------------------------------
+         zcompaph  = MAX( ( tr(ji,jj,jk,jpphy,Kbb) - xthresh2phy ), 0.e0 ) &
+            &      * MIN(1., MAX( 0., ( quotan(ji,jj,jk) - 0.2) / 0.3 ) )
+
+         !   Mesozooplankton grazing
+         !   ------------------------
+         zfood     = xpref2d * zcompadi + xpref2z * zcompaz + xpref2n * zcompaph + xpref2c * zcompapoc 
+         zfoodlim  = MAX( 0., zfood - MIN( 0.5 * zfood, xthresh2 ) )
+         zdenom    = zfoodlim / ( xkgraz2 + zfoodlim )
+         zdenom2   = zdenom / ( zfood + rtrn )
+         zgraze2   = grazrat2 * xstep * tgfunc2(ji,jj,jk) * tr(ji,jj,jk,jpmes,Kbb) * (1. - nitrfac(ji,jj,jk)) 
+
+         zgrazd    = zgraze2  * xpref2d  * zcompadi  * zdenom2 
+         zgrazz    = zgraze2  * xpref2z  * zcompaz   * zdenom2 
+         zgrazn    = zgraze2  * xpref2n  * zcompaph  * zdenom2 
+         zgrazpoc  = zgraze2  * xpref2c  * zcompapoc * zdenom2 
+
+         zgraznf   = zgrazn   * tr(ji,jj,jk,jpnfe,Kbb) / ( tr(ji,jj,jk,jpphy,Kbb) + rtrn)
+         zgrazf    = zgrazd   * tr(ji,jj,jk,jpdfe,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn)
+         zgrazpof  = zgrazpoc * tr(ji,jj,jk,jpsfe,Kbb) / ( tr(ji,jj,jk,jppoc,Kbb) + rtrn)
+
+         !  Mesozooplankton flux feeding on GOC
+         !  ----------------------------------
+         zgrazffeg = grazflux  * xstep * wsbio4(ji,jj,jk)      &
+         &           * tgfunc2(ji,jj,jk) * tr(ji,jj,jk,jpgoc,Kbb) * tr(ji,jj,jk,jpmes,Kbb) &
+         &           * (1. - nitrfac(ji,jj,jk))
+         zgrazfffg = zgrazffeg * tr(ji,jj,jk,jpbfe,Kbb) / (tr(ji,jj,jk,jpgoc,Kbb) + rtrn)
+         zgrazffep = grazflux  * xstep *  wsbio3(ji,jj,jk)     &
+         &           * tgfunc2(ji,jj,jk) * tr(ji,jj,jk,jppoc,Kbb) * tr(ji,jj,jk,jpmes,Kbb) &
+         &           * (1. - nitrfac(ji,jj,jk))
+         zgrazfffp = zgrazffep * tr(ji,jj,jk,jpsfe,Kbb) / (tr(ji,jj,jk,jppoc,Kbb) + rtrn)
+         !
+         zgraztotc = zgrazd + zgrazz + zgrazn + zgrazpoc + zgrazffep + zgrazffeg
+         ! Compute the proportion of filter feeders
+         zproport  = (zgrazffep + zgrazffeg)/(rtrn + zgraztotc)
+         ! Compute fractionation of aggregates. It is assumed that 
+         ! diatoms based aggregates are more prone to fractionation
+         ! since they are more porous (marine snow instead of fecal pellets)
+         zratio    = tr(ji,jj,jk,jpgsi,Kbb) / ( tr(ji,jj,jk,jpgoc,Kbb) + rtrn )
+         zratio2   = zratio * zratio
+         zfrac     = zproport * grazflux  * xstep * wsbio4(ji,jj,jk)      &
+         &          * tr(ji,jj,jk,jpgoc,Kbb) * tr(ji,jj,jk,jpmes,Kbb)          &
+         &          * ( 0.2 + 3.8 * zratio2 / ( 1.**2 + zratio2 ) )
+         zfracfe   = zfrac * tr(ji,jj,jk,jpbfe,Kbb) / (tr(ji,jj,jk,jpgoc,Kbb) + rtrn)
+
+         zgrazffep = zproport * zgrazffep
+         zgrazffeg = zproport * zgrazffeg
+         zgrazfffp = zproport * zgrazfffp
+         zgrazfffg = zproport * zgrazfffg
+         zgraztotc = zgrazd + zgrazz + zgrazn + zgrazpoc + zgrazffep + zgrazffeg
+         zgraztotn = zgrazd * quotad(ji,jj,jk) + zgrazz + zgrazn * quotan(ji,jj,jk)   &
+         &   + zgrazpoc + zgrazffep + zgrazffeg
+         zgraztotf = zgrazf + zgraznf + zgrazz * ferat3 + zgrazpof + zgrazfffp + zgrazfffg
+
+         ! Total grazing ( grazing by microzoo is already computed in p4zmicro )
+         zgrazing2(ji,jj,jk) = zgraztotc
+
+         ! Mesozooplankton efficiency. 
+         ! We adopt a formulation proposed by Mitra et al. (2007)
+         ! The gross growth efficiency is controled by the most limiting nutrient.
+         ! Growth is also further decreased when the food quality is poor. This is currently
+         ! hard coded : it can be decreased by up to 50% (zepsherq)
+         ! GGE can also be decreased when food quantity is high, zepsherf (Montagnes and 
+         ! Fulton, 2012)
+         ! -----------------------------------------------------------------------------------
+         zgrasrat  =  ( zgraztotf + rtrn )/ ( zgraztotc + rtrn )
+         zgrasratn =  ( zgraztotn + rtrn )/ ( zgraztotc + rtrn )
+         zepshert  = MIN( 1., zgrasratn, zgrasrat / ferat3)
+         zbeta     = MAX(0., (epsher2 - epsher2min) )
+         zepsherf  = epsher2min + zbeta / ( 1.0 + 0.04E6 * 12. * zfood * zbeta ) 
+         zepsherq  = 0.5 + (1.0 - 0.5) * zepshert * ( 1.0 + 1.0 ) / ( zepshert + 1.0 )
+         zepsherv  = zepsherf * zepshert * zepsherq 
+
+         zgrarem2  = zgraztotc * ( 1. - zepsherv - unass2 ) &
+         &         + ( 1. - epsher2 - unass2 ) / ( 1. - epsher2 ) * ztortz
+         zgrafer2  = zgraztotc * MAX( 0. , ( 1. - unass2 ) * zgrasrat - ferat3 * zepsherv )    &
+         &         + ferat3 * ( ( 1. - epsher2 - unass2 ) /( 1. - epsher2 ) * ztortz )
+         zgrapoc2  = zgraztotc * unass2
+
+
+         !   Update the arrays TRA which contain the biological sources and sinks
+         zgrarsig  = zgrarem2 * sigma2
+         tr(ji,jj,jk,jppo4,Krhs) = tr(ji,jj,jk,jppo4,Krhs) + zgrarsig
+         tr(ji,jj,jk,jpnh4,Krhs) = tr(ji,jj,jk,jpnh4,Krhs) + zgrarsig
+         tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) + zgrarem2 - zgrarsig
+         !
+         IF( ln_ligand ) THEN 
+            tr(ji,jj,jk,jplgw,Krhs) = tr(ji,jj,jk,jplgw,Krhs) + (zgrarem2 - zgrarsig) * ldocz
+            zz2ligprod(ji,jj,jk) = (zgrarem2 - zgrarsig) * ldocz
+         ENDIF
+         !
+         tr(ji,jj,jk,jpoxy,Krhs) = tr(ji,jj,jk,jpoxy,Krhs) - o2ut * zgrarsig
+         tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) + zgrafer2
+         zfezoo2(ji,jj,jk)   = zgrafer2
+         tr(ji,jj,jk,jpdic,Krhs) = tr(ji,jj,jk,jpdic,Krhs) + zgrarsig
+         tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) + rno3 * zgrarsig              
+
+         zmortz = ztortz + zrespz
+         zmortzgoc = unass2 / ( 1. - epsher2 ) * ztortz + zrespz
+         tr(ji,jj,jk,jpmes,Krhs) = tr(ji,jj,jk,jpmes,Krhs) - zmortz + zepsherv * zgraztotc 
+         tr(ji,jj,jk,jpdia,Krhs) = tr(ji,jj,jk,jpdia,Krhs) - zgrazd
+         tr(ji,jj,jk,jpzoo,Krhs) = tr(ji,jj,jk,jpzoo,Krhs) - zgrazz
+         tr(ji,jj,jk,jpphy,Krhs) = tr(ji,jj,jk,jpphy,Krhs) - zgrazn
+         tr(ji,jj,jk,jpnch,Krhs) = tr(ji,jj,jk,jpnch,Krhs) - zgrazn * tr(ji,jj,jk,jpnch,Kbb) / ( tr(ji,jj,jk,jpphy,Kbb) + rtrn )
+         tr(ji,jj,jk,jpdch,Krhs) = tr(ji,jj,jk,jpdch,Krhs) - zgrazd * tr(ji,jj,jk,jpdch,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+         tr(ji,jj,jk,jpdsi,Krhs) = tr(ji,jj,jk,jpdsi,Krhs) - zgrazd * tr(ji,jj,jk,jpdsi,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+         tr(ji,jj,jk,jpgsi,Krhs) = tr(ji,jj,jk,jpgsi,Krhs) + zgrazd * tr(ji,jj,jk,jpdsi,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+         tr(ji,jj,jk,jpnfe,Krhs) = tr(ji,jj,jk,jpnfe,Krhs) - zgraznf
+         tr(ji,jj,jk,jpdfe,Krhs) = tr(ji,jj,jk,jpdfe,Krhs) - zgrazf
+
+         tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) - zgrazpoc - zgrazffep + zfrac
+         prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + zfrac
+         conspoc(ji,jj,jk) = conspoc(ji,jj,jk) - zgrazpoc - zgrazffep
+         tr(ji,jj,jk,jpgoc,Krhs) = tr(ji,jj,jk,jpgoc,Krhs) + zmortzgoc - zgrazffeg + zgrapoc2 - zfrac
+         prodgoc(ji,jj,jk) = prodgoc(ji,jj,jk) + zmortzgoc + zgrapoc2
+         consgoc(ji,jj,jk) = consgoc(ji,jj,jk) - zgrazffeg - zfrac
+         tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) - zgrazpof - zgrazfffp + zfracfe
+         tr(ji,jj,jk,jpbfe,Krhs) = tr(ji,jj,jk,jpbfe,Krhs) + ferat3 * zmortzgoc - zgrazfffg     &
+           &                + zgraztotf * unass2 - zfracfe
+         zfracal = tr(ji,jj,jk,jpcal,Kbb) / (tr(ji,jj,jk,jppoc,Kbb) + tr(ji,jj,jk,jpgoc,Kbb) + rtrn )
+         zgrazcal = (zgrazffeg + zgrazpoc) * (1. - part2) * zfracal
+         ! calcite production
+         zprcaca = xfracal(ji,jj,jk) * zgrazn
+         prodcal(ji,jj,jk) = prodcal(ji,jj,jk) + zprcaca  ! prodcal=prodcal(nanophy)+prodcal(microzoo)+prodcal(mesozoo)
+         !
+         zprcaca = part2 * zprcaca
+         tr(ji,jj,jk,jpdic,Krhs) = tr(ji,jj,jk,jpdic,Krhs) + zgrazcal - zprcaca
+         tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) - 2. * ( zgrazcal + zprcaca )
+         tr(ji,jj,jk,jpcal,Krhs) = tr(ji,jj,jk,jpcal,Krhs) - zgrazcal + zprcaca
+      END_3D
+      !
+      IF( lk_iomput .AND. knt == nrdttrc ) THEN
+        CALL iom_put( "PCAL"  , prodcal(:,:,:) * 1.e+3  * rfact2r * tmask(:,:,:) )  !  Calcite production 
+        IF( iom_use("GRAZ2") ) THEN  !   Total grazing of phyto by zooplankton
+           zgrazing2(:,:,jpk) = 0._wp ;  CALL iom_put( "GRAZ2" , zgrazing2(:,:,:) * 1.e+3  * rfact2r * tmask(:,:,:) ) 
+         ENDIF
+         IF( iom_use("FEZOO2") ) THEN  
+           zfezoo2 (:,:,jpk) = 0._wp ; CALL iom_put( "FEZOO2", zfezoo2(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:) )
+         ENDIF
+         IF( ln_ligand ) THEN
+            zz2ligprod(:,:,jpk) = 0._wp ; CALL iom_put( "LPRODZ2", zz2ligprod(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:)  )
+         ENDIF
       ENDIF
       !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zcompam   = MAX( ( trb(ji,jj,jk,jpmes) - 1.e-9 ), 0.e0 )
-               zfact     = xstep * tgfunc2(ji,jj,jk) * zcompam
-
-               !  Respiration rates of both zooplankton
-               !  -------------------------------------
-               zrespz    = resrat2 * zfact * ( trb(ji,jj,jk,jpmes) / ( xkmort + trb(ji,jj,jk,jpmes) )  &
-               &           + 3. * nitrfac(ji,jj,jk) )
-
-               !  Zooplankton mortality. A square function has been selected with
-               !  no real reason except that it seems to be more stable and may mimic predation
-               !  ---------------------------------------------------------------
-               ztortz    = mzrat2 * 1.e6 * zfact * trb(ji,jj,jk,jpmes)  * (1. - nitrfac(ji,jj,jk) )
-               !
-               zcompadi  = MAX( ( trb(ji,jj,jk,jpdia) - xthresh2dia ), 0.e0 )
-               zcompaz   = MAX( ( trb(ji,jj,jk,jpzoo) - xthresh2zoo ), 0.e0 )
-               zcompapoc = MAX( ( trb(ji,jj,jk,jppoc) - xthresh2poc ), 0.e0 )
-               ! Size effect of nanophytoplankton on grazing : the smaller it is, the less prone
-               ! it is to predation by mesozooplankton
-               ! -------------------------------------------------------------------------------
-               zcompaph  = MAX( ( trb(ji,jj,jk,jpphy) - xthresh2phy ), 0.e0 ) &
-                  &      * MIN(1., MAX( 0., ( quotan(ji,jj,jk) - 0.2) / 0.3 ) )
-
-               !   Mesozooplankton grazing
-               !   ------------------------
-               zfood     = xpref2d * zcompadi + xpref2z * zcompaz + xpref2n * zcompaph + xpref2c * zcompapoc 
-               zfoodlim  = MAX( 0., zfood - MIN( 0.5 * zfood, xthresh2 ) )
-               zdenom    = zfoodlim / ( xkgraz2 + zfoodlim )
-               zdenom2   = zdenom / ( zfood + rtrn )
-               zgraze2   = grazrat2 * xstep * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jpmes) * (1. - nitrfac(ji,jj,jk)) 
-
-               zgrazd    = zgraze2  * xpref2d  * zcompadi  * zdenom2 
-               zgrazz    = zgraze2  * xpref2z  * zcompaz   * zdenom2 
-               zgrazn    = zgraze2  * xpref2n  * zcompaph  * zdenom2 
-               zgrazpoc  = zgraze2  * xpref2c  * zcompapoc * zdenom2 
-
-               zgraznf   = zgrazn   * trb(ji,jj,jk,jpnfe) / ( trb(ji,jj,jk,jpphy) + rtrn)
-               zgrazf    = zgrazd   * trb(ji,jj,jk,jpdfe) / ( trb(ji,jj,jk,jpdia) + rtrn)
-               zgrazpof  = zgrazpoc * trb(ji,jj,jk,jpsfe) / ( trb(ji,jj,jk,jppoc) + rtrn)
-
-               !  Mesozooplankton flux feeding on GOC
-               !  ----------------------------------
-               zgrazffeg = grazflux  * xstep * wsbio4(ji,jj,jk)      &
-               &           * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jpgoc) * trb(ji,jj,jk,jpmes) &
-               &           * (1. - nitrfac(ji,jj,jk))
-               zgrazfffg = zgrazffeg * trb(ji,jj,jk,jpbfe) / (trb(ji,jj,jk,jpgoc) + rtrn)
-               zgrazffep = grazflux  * xstep *  wsbio3(ji,jj,jk)     &
-               &           * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jppoc) * trb(ji,jj,jk,jpmes) &
-               &           * (1. - nitrfac(ji,jj,jk))
-               zgrazfffp = zgrazffep * trb(ji,jj,jk,jpsfe) / (trb(ji,jj,jk,jppoc) + rtrn)
-               !
-               zgraztotc = zgrazd + zgrazz + zgrazn + zgrazpoc + zgrazffep + zgrazffeg
-               ! Compute the proportion of filter feeders
-               zproport  = (zgrazffep + zgrazffeg)/(rtrn + zgraztotc)
-               ! Compute fractionation of aggregates. It is assumed that 
-               ! diatoms based aggregates are more prone to fractionation
-               ! since they are more porous (marine snow instead of fecal pellets)
-               zratio    = trb(ji,jj,jk,jpgsi) / ( trb(ji,jj,jk,jpgoc) + rtrn )
-               zratio2   = zratio * zratio
-               zfrac     = zproport * grazflux  * xstep * wsbio4(ji,jj,jk)      &
-               &          * trb(ji,jj,jk,jpgoc) * trb(ji,jj,jk,jpmes)          &
-               &          * ( 0.2 + 3.8 * zratio2 / ( 1.**2 + zratio2 ) )
-               zfracfe   = zfrac * trb(ji,jj,jk,jpbfe) / (trb(ji,jj,jk,jpgoc) + rtrn)
-
-               zgrazffep = zproport * zgrazffep
-               zgrazffeg = zproport * zgrazffeg
-               zgrazfffp = zproport * zgrazfffp
-               zgrazfffg = zproport * zgrazfffg
-               zgraztotc = zgrazd + zgrazz + zgrazn + zgrazpoc + zgrazffep + zgrazffeg
-               zgraztotn = zgrazd * quotad(ji,jj,jk) + zgrazz + zgrazn * quotan(ji,jj,jk)   &
-               &   + zgrazpoc + zgrazffep + zgrazffeg
-               zgraztotf = zgrazf + zgraznf + zgrazz * ferat3 + zgrazpof + zgrazfffp + zgrazfffg
-
-               ! Total grazing ( grazing by microzoo is already computed in p4zmicro )
-               zgrazing(ji,jj,jk) = zgraztotc
-
-               !    Mesozooplankton efficiency
-               !    --------------------------
-               zgrasrat  =  ( zgraztotf + rtrn )/ ( zgraztotc + rtrn )
-               zgrasratn =  ( zgraztotn + rtrn )/ ( zgraztotc + rtrn )
-               zepshert  = MIN( 1., zgrasratn, zgrasrat / ferat3)
-               zbeta     = MAX(0., (epsher2 - epsher2min) )
-               zepsherf  = epsher2min + zbeta / ( 1.0 + 0.04E6 * 12. * zfood * zbeta ) 
-               zepsherv  = zepsherf * zepshert 
-
-               zgrarem2  = zgraztotc * ( 1. - zepsherv - unass2 ) &
-               &         + ( 1. - epsher2 - unass2 ) / ( 1. - epsher2 ) * ztortz
-               zgrafer2  = zgraztotc * MAX( 0. , ( 1. - unass2 ) * zgrasrat - ferat3 * zepsherv )    &
-               &         + ferat3 * ( ( 1. - epsher2 - unass2 ) /( 1. - epsher2 ) * ztortz )
-               zgrapoc2  = zgraztotc * unass2
-
-               !   Update the arrays TRA which contain the biological sources and sinks
-               zgrarsig  = zgrarem2 * sigma2
-               tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) + zgrarsig
-               tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + zgrarsig
-               tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + zgrarem2 - zgrarsig
-               !
-               IF( ln_ligand ) THEN 
-                  tra(ji,jj,jk,jplgw) = tra(ji,jj,jk,jplgw) + (zgrarem2 - zgrarsig) * ldocz
-                  zz2ligprod(ji,jj,jk) = (zgrarem2 - zgrarsig) * ldocz
-               ENDIF
-               !
-               tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) - o2ut * zgrarsig
-               tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + zgrafer2
-               zfezoo2(ji,jj,jk)   = zgrafer2
-               tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) + zgrarsig
-               tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) + rno3 * zgrarsig              
-
-               zmortz = ztortz + zrespz
-               zmortzgoc = unass2 / ( 1. - epsher2 ) * ztortz + zrespz
-               tra(ji,jj,jk,jpmes) = tra(ji,jj,jk,jpmes) - zmortz + zepsherv * zgraztotc 
-               tra(ji,jj,jk,jpdia) = tra(ji,jj,jk,jpdia) - zgrazd
-               tra(ji,jj,jk,jpzoo) = tra(ji,jj,jk,jpzoo) - zgrazz
-               tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) - zgrazn
-               tra(ji,jj,jk,jpnch) = tra(ji,jj,jk,jpnch) - zgrazn * trb(ji,jj,jk,jpnch) / ( trb(ji,jj,jk,jpphy) + rtrn )
-               tra(ji,jj,jk,jpdch) = tra(ji,jj,jk,jpdch) - zgrazd * trb(ji,jj,jk,jpdch) / ( trb(ji,jj,jk,jpdia) + rtrn )
-               tra(ji,jj,jk,jpdsi) = tra(ji,jj,jk,jpdsi) - zgrazd * trb(ji,jj,jk,jpdsi) / ( trb(ji,jj,jk,jpdia) + rtrn )
-               tra(ji,jj,jk,jpgsi) = tra(ji,jj,jk,jpgsi) + zgrazd * trb(ji,jj,jk,jpdsi) / ( trb(ji,jj,jk,jpdia) + rtrn )
-               tra(ji,jj,jk,jpnfe) = tra(ji,jj,jk,jpnfe) - zgraznf
-               tra(ji,jj,jk,jpdfe) = tra(ji,jj,jk,jpdfe) - zgrazf
-
-               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) - zgrazpoc - zgrazffep + zfrac
-               prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + zfrac
-               conspoc(ji,jj,jk) = conspoc(ji,jj,jk) - zgrazpoc - zgrazffep
-               tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) + zmortzgoc - zgrazffeg + zgrapoc2 - zfrac
-               prodgoc(ji,jj,jk) = prodgoc(ji,jj,jk) + zmortzgoc + zgrapoc2
-               consgoc(ji,jj,jk) = consgoc(ji,jj,jk) - zgrazffeg - zfrac
-               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) - zgrazpof - zgrazfffp + zfracfe
-               tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + ferat3 * zmortzgoc - zgrazfffg     &
-                 &                + zgraztotf * unass2 - zfracfe
-               zfracal = trb(ji,jj,jk,jpcal) / (trb(ji,jj,jk,jppoc) + trb(ji,jj,jk,jpgoc) + rtrn )
-               zgrazcal = (zgrazffeg + zgrazpoc) * (1. - part2) * zfracal
-               ! calcite production
-               zprcaca = xfracal(ji,jj,jk) * zgrazn
-               prodcal(ji,jj,jk) = prodcal(ji,jj,jk) + zprcaca  ! prodcal=prodcal(nanophy)+prodcal(microzoo)+prodcal(mesozoo)
-               !
-               zprcaca = part2 * zprcaca
-               tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) + zgrazcal - zprcaca
-               tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) - 2. * ( zgrazcal + zprcaca )
-               tra(ji,jj,jk,jpcal) = tra(ji,jj,jk,jpcal) - zgrazcal + zprcaca
-            END DO
-         END DO
-      END DO
-      !
-      IF( lk_iomput .AND. knt == nrdttrc ) THEN
-         ALLOCATE( zw3d(jpi,jpj,jpk) )
-         IF( iom_use( "GRAZ2" ) ) THEN
-            zw3d(:,:,:) = zgrazing(:,:,:) * 1.e+3 * rfact2r * tmask(:,:,:)  !   Total grazing of phyto by zooplankton
-            CALL iom_put( "GRAZ2", zw3d )
-         ENDIF
-         IF( iom_use( "PCAL" ) ) THEN
-            zw3d(:,:,:) = prodcal(:,:,:) * 1.e+3 * rfact2r * tmask(:,:,:)   !  Calcite production
-            CALL iom_put( "PCAL", zw3d )  
-         ENDIF
-         IF( iom_use( "FEZOO2" ) ) THEN
-            zw3d(:,:,:) = zfezoo2(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:)   !
-            CALL iom_put( "FEZOO2", zw3d )
-         ENDIF
-         IF( iom_use( "LPRODZ2" ) .AND. ln_ligand )  THEN
-            zw3d(:,:,:) = zz2ligprod(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:)
-            CALL iom_put( "LPRODZ2"  , zw3d )
-         ENDIF
-         DEALLOCATE( zw3d )
-      ENDIF
-      !
-      IF (ln_ligand)  DEALLOCATE( zz2ligprod )
-      !
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
         WRITE(charout, FMT="('meso')")
-        CALL prt_ctl_trc_info(charout)
-        CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+        CALL prt_ctl_info( charout, cdcomp = 'top' )
+        CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -290,10 +279,8 @@
       ENDIF
       !
-      REWIND( numnatp_ref )              ! Namelist nampismes in reference namelist : Pisces mesozooplankton
       READ  ( numnatp_ref, namp4zmes, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zmes in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampismes in configuration namelist : Pisces mesozooplankton
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zmes in reference namelist' )
       READ  ( numnatp_cfg, namp4zmes, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zmes in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zmes in configuration namelist' )
       IF(lwm) WRITE( numonp, namp4zmes )
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zmicro.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zmicro.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zmicro.F90	(revision 13463)
@@ -17,5 +17,5 @@
    USE p4zprod         ! production
    USE iom             ! I/O manager
-   USE prtctl_trc      ! print control for debugging
+   USE prtctl          ! print control for debugging
 
    IMPLICIT NONE
@@ -42,4 +42,6 @@
    REAL(wp), PUBLIC ::   epshermin   !: minimum growth efficiency for grazing 1
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -49,5 +51,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_micro( kt, knt )
+   SUBROUTINE p4z_micro( kt, knt, Kbb, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_micro  ***
@@ -59,4 +61,5 @@
       INTEGER, INTENT(in) ::   kt    ! ocean time step
       INTEGER, INTENT(in) ::   knt   ! ??? 
+      INTEGER, INTENT(in) ::   Kbb, Krhs  ! time level indices
       !
       INTEGER  :: ji, jj, jk
@@ -64,11 +67,11 @@
       REAL(wp) :: zgraze  , zdenom, zdenom2
       REAL(wp) :: zfact   , zfood, zfoodlim, zbeta
-      REAL(wp) :: zepsherf, zepshert, zepsherv, zgrarsig, zgraztotc, zgraztotn, zgraztotf
+      REAL(wp) :: zepsherf, zepshert, zepsherv, zepsherq
+      REAL(wp) :: zgrarsig, zgraztotc, zgraztotn, zgraztotf
       REAL(wp) :: zgrarem, zgrafer, zgrapoc, zprcaca, zmortz
       REAL(wp) :: zrespz, ztortz, zgrasrat, zgrasratn
       REAL(wp) :: zgrazp, zgrazm, zgrazsd
       REAL(wp) :: zgrazmf, zgrazsf, zgrazpf
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zgrazing, zfezoo
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zw3d, zzligprod
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zgrazing, zfezoo, zzligprod
       CHARACTER (len=25) :: charout
       !!---------------------------------------------------------------------
@@ -76,139 +79,129 @@
       IF( ln_timing )   CALL timing_start('p4z_micro')
       !
-      IF (ln_ligand) THEN
-         ALLOCATE( zzligprod(jpi,jpj,jpk) )
-         zzligprod(:,:,:) = 0._wp
-      ENDIF
-      !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zcompaz = MAX( ( trb(ji,jj,jk,jpzoo) - 1.e-9 ), 0.e0 )
-               zfact   = xstep * tgfunc2(ji,jj,jk) * zcompaz
-
-               !  Respiration rates of both zooplankton
-               !  -------------------------------------
-               zrespz = resrat * zfact * trb(ji,jj,jk,jpzoo) / ( xkmort + trb(ji,jj,jk,jpzoo) )  &
-                  &   + resrat * zfact * 3. * nitrfac(ji,jj,jk)
-
-               !  Zooplankton mortality. A square function has been selected with
-               !  no real reason except that it seems to be more stable and may mimic predation.
-               !  ---------------------------------------------------------------
-               ztortz = mzrat * 1.e6 * zfact * trb(ji,jj,jk,jpzoo) * (1. - nitrfac(ji,jj,jk))
-
-               zcompadi  = MIN( MAX( ( trb(ji,jj,jk,jpdia) - xthreshdia ), 0.e0 ), xsizedia )
-               zcompaph  = MAX( ( trb(ji,jj,jk,jpphy) - xthreshphy ), 0.e0 )
-               zcompapoc = MAX( ( trb(ji,jj,jk,jppoc) - xthreshpoc ), 0.e0 )
-               
-               !     Microzooplankton grazing
-               !     ------------------------
-               zfood     = xprefn * zcompaph + xprefc * zcompapoc + xprefd * zcompadi
-               zfoodlim  = MAX( 0. , zfood - min(xthresh,0.5*zfood) )
-               zdenom    = zfoodlim / ( xkgraz + zfoodlim )
-               zdenom2   = zdenom / ( zfood + rtrn )
-               zgraze    = grazrat * xstep * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jpzoo) * (1. - nitrfac(ji,jj,jk))
-
-               zgrazp    = zgraze  * xprefn * zcompaph  * zdenom2 
-               zgrazm    = zgraze  * xprefc * zcompapoc * zdenom2 
-               zgrazsd   = zgraze  * xprefd * zcompadi  * zdenom2 
-
-               zgrazpf   = zgrazp  * trb(ji,jj,jk,jpnfe) / (trb(ji,jj,jk,jpphy) + rtrn)
-               zgrazmf   = zgrazm  * trb(ji,jj,jk,jpsfe) / (trb(ji,jj,jk,jppoc) + rtrn)
-               zgrazsf   = zgrazsd * trb(ji,jj,jk,jpdfe) / (trb(ji,jj,jk,jpdia) + rtrn)
-               !
-               zgraztotc = zgrazp  + zgrazm  + zgrazsd 
-               zgraztotf = zgrazpf + zgrazsf + zgrazmf 
-               zgraztotn = zgrazp * quotan(ji,jj,jk) + zgrazm + zgrazsd * quotad(ji,jj,jk)
-
-               ! Grazing by microzooplankton
-               zgrazing(ji,jj,jk) = zgraztotc
-
-               !    Various remineralization and excretion terms
-               !    --------------------------------------------
-               zgrasrat  = ( zgraztotf + rtrn ) / ( zgraztotc + rtrn )
-               zgrasratn = ( zgraztotn + rtrn ) / ( zgraztotc + rtrn )
-               zepshert  =  MIN( 1., zgrasratn, zgrasrat / ferat3)
-               zbeta     = MAX(0., (epsher - epshermin) )
-               zepsherf  = epshermin + zbeta / ( 1.0 + 0.04E6 * 12. * zfood * zbeta )
-               zepsherv  = zepsherf * zepshert 
-
-               zgrafer   = zgraztotc * MAX( 0. , ( 1. - unass ) * zgrasrat - ferat3 * zepsherv ) 
-               zgrarem   = zgraztotc * ( 1. - zepsherv - unass )
-               zgrapoc   = zgraztotc * unass
-
-               !  Update of the TRA arrays
-               !  ------------------------
-               zgrarsig  = zgrarem * sigma1
-               tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) + zgrarsig
-               tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + zgrarsig
-               tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + zgrarem - zgrarsig
-               !
-               IF( ln_ligand ) THEN
-                  tra(ji,jj,jk,jplgw) = tra(ji,jj,jk,jplgw) + (zgrarem - zgrarsig) * ldocz
-                  zzligprod(ji,jj,jk) = (zgrarem - zgrarsig) * ldocz
-               ENDIF
-               !
-               tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) - o2ut * zgrarsig
-               tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + zgrafer
-               zfezoo(ji,jj,jk)    = zgrafer
-               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zgrapoc
-               prodpoc(ji,jj,jk)   = prodpoc(ji,jj,jk) + zgrapoc
-               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + zgraztotf * unass
-               tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) + zgrarsig
-               tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) + rno3 * zgrarsig
-               !   Update the arrays TRA which contain the biological sources and sinks
-               !   --------------------------------------------------------------------
-               zmortz = ztortz + zrespz
-               tra(ji,jj,jk,jpzoo) = tra(ji,jj,jk,jpzoo) - zmortz + zepsherv * zgraztotc 
-               tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) - zgrazp
-               tra(ji,jj,jk,jpdia) = tra(ji,jj,jk,jpdia) - zgrazsd
-               tra(ji,jj,jk,jpnch) = tra(ji,jj,jk,jpnch) - zgrazp  * trb(ji,jj,jk,jpnch)/(trb(ji,jj,jk,jpphy)+rtrn)
-               tra(ji,jj,jk,jpdch) = tra(ji,jj,jk,jpdch) - zgrazsd * trb(ji,jj,jk,jpdch)/(trb(ji,jj,jk,jpdia)+rtrn)
-               tra(ji,jj,jk,jpdsi) = tra(ji,jj,jk,jpdsi) - zgrazsd * trb(ji,jj,jk,jpdsi)/(trb(ji,jj,jk,jpdia)+rtrn)
-               tra(ji,jj,jk,jpgsi) = tra(ji,jj,jk,jpgsi) + zgrazsd * trb(ji,jj,jk,jpdsi)/(trb(ji,jj,jk,jpdia)+rtrn)
-               tra(ji,jj,jk,jpnfe) = tra(ji,jj,jk,jpnfe) - zgrazpf
-               tra(ji,jj,jk,jpdfe) = tra(ji,jj,jk,jpdfe) - zgrazsf
-               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zmortz - zgrazm
-               prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + zmortz
-               conspoc(ji,jj,jk) = conspoc(ji,jj,jk) - zgrazm
-               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + ferat3 * zmortz - zgrazmf
-               !
-               ! calcite production
-               zprcaca = xfracal(ji,jj,jk) * zgrazp
-               prodcal(ji,jj,jk) = prodcal(ji,jj,jk) + zprcaca  ! prodcal=prodcal(nanophy)+prodcal(microzoo)+prodcal(mesozoo)
-               !
-               zprcaca = part * zprcaca
-               tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) - zprcaca
-               tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) - 2. * zprcaca
-               tra(ji,jj,jk,jpcal) = tra(ji,jj,jk,jpcal) + zprcaca
-            END DO
-         END DO
-      END DO
-      !
-      IF( lk_iomput ) THEN
-         IF( knt == nrdttrc ) THEN
-           ALLOCATE( zw3d(jpi,jpj,jpk) )
-           IF( iom_use( "GRAZ1" ) ) THEN
-              zw3d(:,:,:) = zgrazing(:,:,:) * 1.e+3 * rfact2r * tmask(:,:,:)  !  Total grazing of phyto by zooplankton
-              CALL iom_put( "GRAZ1", zw3d )
-           ENDIF
-           IF( iom_use( "FEZOO" ) ) THEN
-              zw3d(:,:,:) = zfezoo(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:)   !
-              CALL iom_put( "FEZOO", zw3d )
-           ENDIF
-           IF( iom_use( "LPRODZ" ) .AND. ln_ligand )  THEN
-              zw3d(:,:,:) = zzligprod(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:)
-              CALL iom_put( "LPRODZ"  , zw3d )
-           ENDIF
-           DEALLOCATE( zw3d )
-         ENDIF
-      ENDIF
-      !
-      IF (ln_ligand)  DEALLOCATE( zzligprod )
-      !
-      IF(ln_ctl) THEN      ! print mean trends (used for debugging)
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zcompaz = MAX( ( tr(ji,jj,jk,jpzoo,Kbb) - 1.e-9 ), 0.e0 )
+         zfact   = xstep * tgfunc2(ji,jj,jk) * zcompaz
+
+         !  Respiration rates of both zooplankton
+         !  -------------------------------------
+         zrespz = resrat * zfact * tr(ji,jj,jk,jpzoo,Kbb) / ( xkmort + tr(ji,jj,jk,jpzoo,Kbb) )  &
+            &   + resrat * zfact * 3. * nitrfac(ji,jj,jk)
+
+         !  Zooplankton mortality. A square function has been selected with
+         !  no real reason except that it seems to be more stable and may mimic predation.
+         !  ---------------------------------------------------------------
+         ztortz = mzrat * 1.e6 * zfact * tr(ji,jj,jk,jpzoo,Kbb) * (1. - nitrfac(ji,jj,jk))
+
+         zcompadi  = MIN( MAX( ( tr(ji,jj,jk,jpdia,Kbb) - xthreshdia ), 0.e0 ), xsizedia )
+         zcompaph  = MAX( ( tr(ji,jj,jk,jpphy,Kbb) - xthreshphy ), 0.e0 )
+         zcompapoc = MAX( ( tr(ji,jj,jk,jppoc,Kbb) - xthreshpoc ), 0.e0 )
+         
+         !     Microzooplankton grazing
+         !     ------------------------
+         zfood     = xprefn * zcompaph + xprefc * zcompapoc + xprefd * zcompadi
+         zfoodlim  = MAX( 0. , zfood - min(xthresh,0.5*zfood) )
+         zdenom    = zfoodlim / ( xkgraz + zfoodlim )
+         zdenom2   = zdenom / ( zfood + rtrn )
+         zgraze    = grazrat * xstep * tgfunc2(ji,jj,jk) * tr(ji,jj,jk,jpzoo,Kbb) * (1. - nitrfac(ji,jj,jk))
+
+         zgrazp    = zgraze  * xprefn * zcompaph  * zdenom2 
+         zgrazm    = zgraze  * xprefc * zcompapoc * zdenom2 
+         zgrazsd   = zgraze  * xprefd * zcompadi  * zdenom2 
+
+         zgrazpf   = zgrazp  * tr(ji,jj,jk,jpnfe,Kbb) / (tr(ji,jj,jk,jpphy,Kbb) + rtrn)
+         zgrazmf   = zgrazm  * tr(ji,jj,jk,jpsfe,Kbb) / (tr(ji,jj,jk,jppoc,Kbb) + rtrn)
+         zgrazsf   = zgrazsd * tr(ji,jj,jk,jpdfe,Kbb) / (tr(ji,jj,jk,jpdia,Kbb) + rtrn)
+         !
+         zgraztotc = zgrazp  + zgrazm  + zgrazsd 
+         zgraztotf = zgrazpf + zgrazsf + zgrazmf 
+         zgraztotn = zgrazp * quotan(ji,jj,jk) + zgrazm + zgrazsd * quotad(ji,jj,jk)
+
+         ! Grazing by microzooplankton
+         zgrazing(ji,jj,jk) = zgraztotc
+
+
+         ! Microzooplankton efficiency. 
+         ! We adopt a formulation proposed by Mitra et al. (2007)
+         ! The gross growth efficiency is controled by the most limiting nutrient.
+         ! Growth is also further decreased when the food quality is poor. This is currently
+         ! hard coded : it can be decreased by up to 50% (zepsherq)
+         ! GGE can also be decreased when food quantity is high, zepsherf (Montagnes and 
+         ! Fulton, 2012)
+         ! -----------------------------------------------------------------------------
+         zgrasrat  = ( zgraztotf + rtrn ) / ( zgraztotc + rtrn )
+         zgrasratn = ( zgraztotn + rtrn ) / ( zgraztotc + rtrn )
+         zepshert  =  MIN( 1., zgrasratn, zgrasrat / ferat3)
+         zbeta     = MAX(0., (epsher - epshermin) )
+         zepsherf  = epshermin + zbeta / ( 1.0 + 0.04E6 * 12. * zfood * zbeta )
+         zepsherq  = 0.5 + (1.0 - 0.5) * zepshert * ( 1.0 + 1.0 ) / ( zepshert + 1.0 )
+         zepsherv  = zepsherf * zepshert * zepsherq 
+
+         zgrafer   = zgraztotc * MAX( 0. , ( 1. - unass ) * zgrasrat - ferat3 * zepsherv ) 
+         zgrarem   = zgraztotc * ( 1. - zepsherv - unass )
+         zgrapoc   = zgraztotc * unass
+
+         !  Update of the TRA arrays
+         !  ------------------------
+         zgrarsig  = zgrarem * sigma1
+         tr(ji,jj,jk,jppo4,Krhs) = tr(ji,jj,jk,jppo4,Krhs) + zgrarsig
+         tr(ji,jj,jk,jpnh4,Krhs) = tr(ji,jj,jk,jpnh4,Krhs) + zgrarsig
+         tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) + zgrarem - zgrarsig
+         !
+         IF( ln_ligand ) THEN
+            tr(ji,jj,jk,jplgw,Krhs) = tr(ji,jj,jk,jplgw,Krhs) + (zgrarem - zgrarsig) * ldocz
+            zzligprod(ji,jj,jk) = (zgrarem - zgrarsig) * ldocz
+         ENDIF
+         !
+         tr(ji,jj,jk,jpoxy,Krhs) = tr(ji,jj,jk,jpoxy,Krhs) - o2ut * zgrarsig
+         tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) + zgrafer
+         zfezoo(ji,jj,jk)    = zgrafer
+         tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) + zgrapoc
+         prodpoc(ji,jj,jk)   = prodpoc(ji,jj,jk) + zgrapoc
+         tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) + zgraztotf * unass
+         tr(ji,jj,jk,jpdic,Krhs) = tr(ji,jj,jk,jpdic,Krhs) + zgrarsig
+         tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) + rno3 * zgrarsig
+         !   Update the arrays TRA which contain the biological sources and sinks
+         !   --------------------------------------------------------------------
+         zmortz = ztortz + zrespz
+         tr(ji,jj,jk,jpzoo,Krhs) = tr(ji,jj,jk,jpzoo,Krhs) - zmortz + zepsherv * zgraztotc 
+         tr(ji,jj,jk,jpphy,Krhs) = tr(ji,jj,jk,jpphy,Krhs) - zgrazp
+         tr(ji,jj,jk,jpdia,Krhs) = tr(ji,jj,jk,jpdia,Krhs) - zgrazsd
+         tr(ji,jj,jk,jpnch,Krhs) = tr(ji,jj,jk,jpnch,Krhs) - zgrazp  * tr(ji,jj,jk,jpnch,Kbb)/(tr(ji,jj,jk,jpphy,Kbb)+rtrn)
+         tr(ji,jj,jk,jpdch,Krhs) = tr(ji,jj,jk,jpdch,Krhs) - zgrazsd * tr(ji,jj,jk,jpdch,Kbb)/(tr(ji,jj,jk,jpdia,Kbb)+rtrn)
+         tr(ji,jj,jk,jpdsi,Krhs) = tr(ji,jj,jk,jpdsi,Krhs) - zgrazsd * tr(ji,jj,jk,jpdsi,Kbb)/(tr(ji,jj,jk,jpdia,Kbb)+rtrn)
+         tr(ji,jj,jk,jpgsi,Krhs) = tr(ji,jj,jk,jpgsi,Krhs) + zgrazsd * tr(ji,jj,jk,jpdsi,Kbb)/(tr(ji,jj,jk,jpdia,Kbb)+rtrn)
+         tr(ji,jj,jk,jpnfe,Krhs) = tr(ji,jj,jk,jpnfe,Krhs) - zgrazpf
+         tr(ji,jj,jk,jpdfe,Krhs) = tr(ji,jj,jk,jpdfe,Krhs) - zgrazsf
+         tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) + zmortz - zgrazm
+         prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + zmortz
+         conspoc(ji,jj,jk) = conspoc(ji,jj,jk) - zgrazm
+         tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) + ferat3 * zmortz - zgrazmf
+         !
+         ! calcite production
+         zprcaca = xfracal(ji,jj,jk) * zgrazp
+         prodcal(ji,jj,jk) = prodcal(ji,jj,jk) + zprcaca  ! prodcal=prodcal(nanophy)+prodcal(microzoo)+prodcal(mesozoo)
+         !
+         zprcaca = part * zprcaca
+         tr(ji,jj,jk,jpdic,Krhs) = tr(ji,jj,jk,jpdic,Krhs) - zprcaca
+         tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) - 2. * zprcaca
+         tr(ji,jj,jk,jpcal,Krhs) = tr(ji,jj,jk,jpcal,Krhs) + zprcaca
+      END_3D
+      !
+      IF( lk_iomput .AND. knt == nrdttrc ) THEN
+        IF( iom_use("GRAZ1") ) THEN  !   Total grazing of phyto by zooplankton
+           zgrazing(:,:,jpk) = 0._wp   ; CALL iom_put( "GRAZ1" , zgrazing(:,:,:) * 1.e+3  * rfact2r * tmask(:,:,:) ) 
+         ENDIF
+         IF( iom_use("FEZOO") ) THEN  
+           zfezoo (:,:,jpk) = 0._wp    ; CALL iom_put( "FEZOO", zfezoo(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:) )
+         ENDIF
+         IF( ln_ligand ) THEN
+            zzligprod(:,:,jpk) = 0._wp ; CALL iom_put( "LPRODZ", zzligprod(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:))
+         ENDIF
+      ENDIF
+      !
+      IF(sn_cfctl%l_prttrc) THEN      ! print mean trends (used for debugging)
          WRITE(charout, FMT="('micro')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -243,10 +236,8 @@
       ENDIF
       !
-      REWIND( numnatp_ref )              ! Namelist nampiszoo in reference namelist : Pisces microzooplankton
       READ  ( numnatp_ref, namp4zzoo, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zzoo in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampiszoo in configuration namelist : Pisces microzooplankton
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zzoo in reference namelist' )
       READ  ( numnatp_cfg, namp4zzoo, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zzoo in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zzoo in configuration namelist' )
       IF(lwm) WRITE( numonp, namp4zzoo )
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zmort.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zmort.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zmort.F90	(revision 13463)
@@ -15,5 +15,5 @@
    USE p4zprod         ! Primary productivity 
    USE p4zlim          ! Phytoplankton limitation terms
-   USE prtctl_trc      ! print control for debugging
+   USE prtctl          ! print control for debugging
 
    IMPLICIT NONE
@@ -29,4 +29,6 @@
    REAL(wp), PUBLIC ::   mprat2   !:
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -36,5 +38,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_mort( kt )
+   SUBROUTINE p4z_mort( kt, Kbb, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_mort  ***
@@ -46,14 +48,15 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt ! ocean time step
-      !!---------------------------------------------------------------------
-      !
-      CALL p4z_nano            ! nanophytoplankton
-      !
-      CALL p4z_diat            ! diatoms
+      INTEGER, INTENT(in) ::   Kbb, Krhs  ! time level indices
+      !!---------------------------------------------------------------------
+      !
+      CALL p4z_nano( Kbb, Krhs )            ! nanophytoplankton
+      !
+      CALL p4z_diat( Kbb, Krhs )            ! diatoms
       !
    END SUBROUTINE p4z_mort
 
 
-   SUBROUTINE p4z_nano
+   SUBROUTINE p4z_nano( Kbb, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_nano  ***
@@ -63,4 +66,5 @@
       !! ** Method  : - ???
       !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kbb, Krhs  ! time level indices
       INTEGER  ::   ji, jj, jk
       REAL(wp) ::   zsizerat, zcompaph
@@ -73,53 +77,49 @@
       !
       prodcal(:,:,:) = 0._wp   ! calcite production variable set to zero
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zcompaph = MAX( ( trb(ji,jj,jk,jpphy) - 1e-8 ), 0.e0 )
-               !     When highly limited by macronutrients, very small cells 
-               !     dominate the community. As a consequence, aggregation
-               !     due to turbulence is negligible. Mortality is also set
-               !     to 0
-               zsizerat = MIN(1., MAX( 0., (quotan(ji,jj,jk) - 0.2) / 0.3) ) * trb(ji,jj,jk,jpphy)
-               !     Squared mortality of Phyto similar to a sedimentation term during
-               !     blooms (Doney et al. 1996)
-               zrespp = wchl * 1.e6 * xstep * xdiss(ji,jj,jk) * zcompaph * zsizerat 
-
-               !     Phytoplankton mortality. This mortality loss is slightly
-               !     increased when nutrients are limiting phytoplankton growth
-               !     as observed for instance in case of iron limitation.
-               ztortp = mprat * xstep * zcompaph / ( xkmort + trb(ji,jj,jk,jpphy) ) * zsizerat
-
-               zmortp = zrespp + ztortp
-
-               !   Update the arrays TRA which contains the biological sources and sinks
-
-               zfactfe = trb(ji,jj,jk,jpnfe)/(trb(ji,jj,jk,jpphy)+rtrn)
-               zfactch = trb(ji,jj,jk,jpnch)/(trb(ji,jj,jk,jpphy)+rtrn)
-               tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) - zmortp
-               tra(ji,jj,jk,jpnch) = tra(ji,jj,jk,jpnch) - zmortp * zfactch
-               tra(ji,jj,jk,jpnfe) = tra(ji,jj,jk,jpnfe) - zmortp * zfactfe
-               zprcaca = xfracal(ji,jj,jk) * zmortp
-               !
-               prodcal(ji,jj,jk) = prodcal(ji,jj,jk) + zprcaca  ! prodcal=prodcal(nanophy)+prodcal(microzoo)+prodcal(mesozoo)
-               !
-               zfracal = 0.5 * xfracal(ji,jj,jk)
-               tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) - zprcaca
-               tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) - 2. * zprcaca
-               tra(ji,jj,jk,jpcal) = tra(ji,jj,jk,jpcal) + zprcaca
-               tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) + zfracal * zmortp
-               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + ( 1. - zfracal ) * zmortp
-               prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + ( 1. - zfracal ) * zmortp
-               prodgoc(ji,jj,jk) = prodgoc(ji,jj,jk) + zfracal * zmortp
-               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + ( 1. - zfracal ) * zmortp * zfactfe
-               tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + zfracal * zmortp * zfactfe
-            END DO
-         END DO
-      END DO
-      !
-       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zcompaph = MAX( ( tr(ji,jj,jk,jpphy,Kbb) - 1e-8 ), 0.e0 )
+         !     When highly limited by macronutrients, very small cells 
+         !     dominate the community. As a consequence, aggregation
+         !     due to turbulence is negligible. Mortality is also set
+         !     to 0
+         zsizerat = MIN(1., MAX( 0., (quotan(ji,jj,jk) - 0.2) / 0.3) ) * tr(ji,jj,jk,jpphy,Kbb)
+         !     Squared mortality of Phyto similar to a sedimentation term during
+         !     blooms (Doney et al. 1996)
+         zrespp = wchl * 1.e6 * xstep * xdiss(ji,jj,jk) * zcompaph * zsizerat 
+
+         !     Phytoplankton mortality. This mortality loss is slightly
+         !     increased when nutrients are limiting phytoplankton growth
+         !     as observed for instance in case of iron limitation.
+         ztortp = mprat * xstep * zcompaph / ( xkmort + tr(ji,jj,jk,jpphy,Kbb) ) * zsizerat
+
+         zmortp = zrespp + ztortp
+
+         !   Update the arrays TRA which contains the biological sources and sinks
+
+         zfactfe = tr(ji,jj,jk,jpnfe,Kbb)/(tr(ji,jj,jk,jpphy,Kbb)+rtrn)
+         zfactch = tr(ji,jj,jk,jpnch,Kbb)/(tr(ji,jj,jk,jpphy,Kbb)+rtrn)
+         tr(ji,jj,jk,jpphy,Krhs) = tr(ji,jj,jk,jpphy,Krhs) - zmortp
+         tr(ji,jj,jk,jpnch,Krhs) = tr(ji,jj,jk,jpnch,Krhs) - zmortp * zfactch
+         tr(ji,jj,jk,jpnfe,Krhs) = tr(ji,jj,jk,jpnfe,Krhs) - zmortp * zfactfe
+         zprcaca = xfracal(ji,jj,jk) * zmortp
+         !
+         prodcal(ji,jj,jk) = prodcal(ji,jj,jk) + zprcaca  ! prodcal=prodcal(nanophy)+prodcal(microzoo)+prodcal(mesozoo)
+         !
+         zfracal = 0.5 * xfracal(ji,jj,jk)
+         tr(ji,jj,jk,jpdic,Krhs) = tr(ji,jj,jk,jpdic,Krhs) - zprcaca
+         tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) - 2. * zprcaca
+         tr(ji,jj,jk,jpcal,Krhs) = tr(ji,jj,jk,jpcal,Krhs) + zprcaca
+         tr(ji,jj,jk,jpgoc,Krhs) = tr(ji,jj,jk,jpgoc,Krhs) + zfracal * zmortp
+         tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) + ( 1. - zfracal ) * zmortp
+         prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + ( 1. - zfracal ) * zmortp
+         prodgoc(ji,jj,jk) = prodgoc(ji,jj,jk) + zfracal * zmortp
+         tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) + ( 1. - zfracal ) * zmortp * zfactfe
+         tr(ji,jj,jk,jpbfe,Krhs) = tr(ji,jj,jk,jpbfe,Krhs) + zfracal * zmortp * zfactfe
+      END_3D
+      !
+       IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('nano')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
        ENDIF
       !
@@ -129,5 +129,5 @@
 
 
-   SUBROUTINE p4z_diat
+   SUBROUTINE p4z_diat( Kbb, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_diat  ***
@@ -137,4 +137,5 @@
       !! ** Method  : - ???
       !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kbb, Krhs  ! time level indices
       INTEGER  ::   ji, jj, jk
       REAL(wp) ::   zfactfe,zfactsi,zfactch, zcompadi
@@ -151,50 +152,46 @@
       !     ------------------------------------------------------------
 
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-
-               zcompadi = MAX( ( trb(ji,jj,jk,jpdia) - 1e-9), 0. )
-
-               !    Aggregation term for diatoms is increased in case of nutrient
-               !    stress as observed in reality. The stressed cells become more
-               !    sticky and coagulate to sink quickly out of the euphotic zone
-               !     ------------------------------------------------------------
-               !  Phytoplankton respiration 
-               !     ------------------------
-               zlim2   = xlimdia(ji,jj,jk) * xlimdia(ji,jj,jk)
-               zlim1   = 0.25 * ( 1. - zlim2 ) / ( 0.25 + zlim2 ) 
-               zrespp2 = 1.e6 * xstep * (  wchld + wchldm * zlim1 ) * xdiss(ji,jj,jk) * zcompadi * trb(ji,jj,jk,jpdia)
-
-               !     Phytoplankton mortality. 
-               !     ------------------------
-               ztortp2 = mprat2 * xstep * trb(ji,jj,jk,jpdia)  / ( xkmort + trb(ji,jj,jk,jpdia) ) * zcompadi 
-
-               zmortp2 = zrespp2 + ztortp2
-
-               !   Update the arrays tra which contains the biological sources and sinks
-               !   ---------------------------------------------------------------------
-               zfactch = trb(ji,jj,jk,jpdch) / ( trb(ji,jj,jk,jpdia) + rtrn )
-               zfactfe = trb(ji,jj,jk,jpdfe) / ( trb(ji,jj,jk,jpdia) + rtrn )
-               zfactsi = trb(ji,jj,jk,jpdsi) / ( trb(ji,jj,jk,jpdia) + rtrn )
-               tra(ji,jj,jk,jpdia) = tra(ji,jj,jk,jpdia) - zmortp2 
-               tra(ji,jj,jk,jpdch) = tra(ji,jj,jk,jpdch) - zmortp2 * zfactch
-               tra(ji,jj,jk,jpdfe) = tra(ji,jj,jk,jpdfe) - zmortp2 * zfactfe
-               tra(ji,jj,jk,jpdsi) = tra(ji,jj,jk,jpdsi) - zmortp2 * zfactsi
-               tra(ji,jj,jk,jpgsi) = tra(ji,jj,jk,jpgsi) + zmortp2 * zfactsi
-               tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) + zrespp2 + 0.5 * ztortp2
-               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + 0.5 * ztortp2
-               prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + 0.5 * ztortp2
-               prodgoc(ji,jj,jk) = prodgoc(ji,jj,jk) + zrespp2 + 0.5 * ztortp2
-               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + 0.5 * ztortp2 * zfactfe
-               tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + ( zrespp2 + 0.5 * ztortp2 ) * zfactfe
-            END DO
-         END DO
-      END DO
-      !
-      IF(ln_ctl) THEN      ! print mean trends (used for debugging)
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+
+         zcompadi = MAX( ( tr(ji,jj,jk,jpdia,Kbb) - 1e-9), 0. )
+
+         !    Aggregation term for diatoms is increased in case of nutrient
+         !    stress as observed in reality. The stressed cells become more
+         !    sticky and coagulate to sink quickly out of the euphotic zone
+         !     ------------------------------------------------------------
+         !  Phytoplankton respiration 
+         !     ------------------------
+         zlim2   = xlimdia(ji,jj,jk) * xlimdia(ji,jj,jk)
+         zlim1   = 0.25 * ( 1. - zlim2 ) / ( 0.25 + zlim2 ) 
+         zrespp2 = 1.e6 * xstep * (  wchld + wchldm * zlim1 ) * xdiss(ji,jj,jk) * zcompadi * tr(ji,jj,jk,jpdia,Kbb)
+
+         !     Phytoplankton mortality. 
+         !     ------------------------
+         ztortp2 = mprat2 * xstep * tr(ji,jj,jk,jpdia,Kbb)  / ( xkmort + tr(ji,jj,jk,jpdia,Kbb) ) * zcompadi 
+
+         zmortp2 = zrespp2 + ztortp2
+
+         !   Update the arrays tr(:,:,:,:,Krhs) which contains the biological sources and sinks
+         !   ---------------------------------------------------------------------
+         zfactch = tr(ji,jj,jk,jpdch,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+         zfactfe = tr(ji,jj,jk,jpdfe,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+         zfactsi = tr(ji,jj,jk,jpdsi,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+         tr(ji,jj,jk,jpdia,Krhs) = tr(ji,jj,jk,jpdia,Krhs) - zmortp2 
+         tr(ji,jj,jk,jpdch,Krhs) = tr(ji,jj,jk,jpdch,Krhs) - zmortp2 * zfactch
+         tr(ji,jj,jk,jpdfe,Krhs) = tr(ji,jj,jk,jpdfe,Krhs) - zmortp2 * zfactfe
+         tr(ji,jj,jk,jpdsi,Krhs) = tr(ji,jj,jk,jpdsi,Krhs) - zmortp2 * zfactsi
+         tr(ji,jj,jk,jpgsi,Krhs) = tr(ji,jj,jk,jpgsi,Krhs) + zmortp2 * zfactsi
+         tr(ji,jj,jk,jpgoc,Krhs) = tr(ji,jj,jk,jpgoc,Krhs) + zrespp2 + 0.5 * ztortp2
+         tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) + 0.5 * ztortp2
+         prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + 0.5 * ztortp2
+         prodgoc(ji,jj,jk) = prodgoc(ji,jj,jk) + zrespp2 + 0.5 * ztortp2
+         tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) + 0.5 * ztortp2 * zfactfe
+         tr(ji,jj,jk,jpbfe,Krhs) = tr(ji,jj,jk,jpbfe,Krhs) + ( zrespp2 + 0.5 * ztortp2 ) * zfactfe
+      END_3D
+      !
+      IF(sn_cfctl%l_prttrc) THEN      ! print mean trends (used for debugging)
          WRITE(charout, FMT="('diat')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -227,10 +224,8 @@
       ENDIF
       !
-      REWIND( numnatp_ref )              ! Namelist nampismort in reference namelist : Pisces phytoplankton
       READ  ( numnatp_ref, namp4zmort, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zmort in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampismort in configuration namelist : Pisces phytoplankton
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zmort in reference namelist' )
       READ  ( numnatp_cfg, namp4zmort, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zmort in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zmort in configuration namelist' )
       IF(lwm) WRITE( numonp, namp4zmort )
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zopt.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zopt.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zopt.F90	(revision 13463)
@@ -16,5 +16,5 @@
    USE iom            ! I/O manager
    USE fldread        !  time interpolation
-   USE prtctl_trc     !  print control for debugging
+   USE prtctl         !  print control for debugging
 
    IMPLICIT NONE
@@ -37,9 +37,8 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   par_varsw      ! PAR fraction of shortwave
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ekb, ekg, ekr  ! wavelength (Red-Green-Blue)
-
-   INTEGER  ::   nksrp   ! levels below which the light cannot penetrate ( depth larger than 391 m)
-
-   REAL(wp), DIMENSION(3,61) ::   xkrgb   ! tabulated attenuation coefficients for RGB absorption
    
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -49,5 +48,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_opt( kt, knt )
+   SUBROUTINE p4z_opt( kt, knt, Kbb, Kmm )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_opt  ***
@@ -59,4 +58,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt, knt   ! ocean time step
+      INTEGER, INTENT(in) ::   Kbb, Kmm  ! time level indices
       !
       INTEGER  ::   ji, jj, jk
@@ -71,5 +71,4 @@
       !
       IF( ln_timing )   CALL timing_start('p4z_opt')
-      IF( ln_p5z    )   ALLOCATE( zetmp5(jpi,jpj) )
 
       IF( knt == 1 .AND. ln_varpar )   CALL p4z_opt_sbc( kt )
@@ -83,20 +82,16 @@
       !                                        !* attenuation coef. function of Chlorophyll and wavelength (Red-Green-Blue)
       !                                        !  --------------------------------------------------------
-                     zchl3d(:,:,:) = trb(:,:,:,jpnch) + trb(:,:,:,jpdch)
-      IF( ln_p5z )   zchl3d(:,:,:) = zchl3d(:,:,:)    + trb(:,:,:,jppch)
-      !
-      DO jk = 1, jpkm1   
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zchl = ( zchl3d(ji,jj,jk) + rtrn ) * 1.e6
-               zchl = MIN(  10. , MAX( 0.05, zchl )  )
-               irgb = NINT( 41 + 20.* LOG10( zchl ) + rtrn )
-               !                                                         
-               ekb(ji,jj,jk) = xkrgb(1,irgb) * e3t_n(ji,jj,jk)
-               ekg(ji,jj,jk) = xkrgb(2,irgb) * e3t_n(ji,jj,jk)
-               ekr(ji,jj,jk) = xkrgb(3,irgb) * e3t_n(ji,jj,jk)
-            END DO
-         END DO
-      END DO
+                     zchl3d(:,:,:) = tr(:,:,:,jpnch,Kbb) + tr(:,:,:,jpdch,Kbb)
+      IF( ln_p5z )   zchl3d(:,:,:) = zchl3d(:,:,:)    + tr(:,:,:,jppch,Kbb)
+      !
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zchl = ( zchl3d(ji,jj,jk) + rtrn ) * 1.e6
+         zchl = MIN(  10. , MAX( 0.05, zchl )  )
+         irgb = NINT( 41 + 20.* LOG10( zchl ) + rtrn )
+         !                                                         
+         ekb(ji,jj,jk) = rkrgb(1,irgb) * e3t(ji,jj,jk,Kmm)
+         ekg(ji,jj,jk) = rkrgb(2,irgb) * e3t(ji,jj,jk,Kmm)
+         ekr(ji,jj,jk) = rkrgb(3,irgb) * e3t(ji,jj,jk,Kmm)
+      END_3D
       !                                        !* Photosynthetically Available Radiation (PAR)
       !                                        !  --------------------------------------
@@ -105,7 +100,7 @@
          zqsr_corr(:,:) = qsr_mean(:,:) / ( 1.-fr_i(:,:) + rtrn )
          !
-         CALL p4z_opt_par( kt, zqsr_corr, ze1, ze2, ze3, pqsr100 = zqsr100 ) 
-         !
-         DO jk = 1, nksrp      
+         CALL p4z_opt_par( kt, Kmm, zqsr_corr, ze1, ze2, ze3, pqsr100 = zqsr100 ) 
+         !
+         DO jk = 1, nksr      
             etot_ndcy(:,:,jk) =        ze1(:,:,jk) +        ze2(:,:,jk) +       ze3(:,:,jk)
             enano    (:,:,jk) =  1.85 * ze1(:,:,jk) + 0.69 * ze2(:,:,jk) + 0.46 * ze3(:,:,jk)
@@ -113,5 +108,5 @@
          END DO
          IF( ln_p5z ) THEN
-            DO jk = 1, nksrp      
+            DO jk = 1, nksr      
               epico  (:,:,jk) =  1.94 * ze1(:,:,jk) + 0.66 * ze2(:,:,jk) + 0.4 * ze3(:,:,jk)
             END DO
@@ -120,7 +115,7 @@
          zqsr_corr(:,:) = qsr(:,:) / ( 1.-fr_i(:,:) + rtrn )
          !
-         CALL p4z_opt_par( kt, zqsr_corr, ze1, ze2, ze3 ) 
-         !
-         DO jk = 1, nksrp      
+         CALL p4z_opt_par( kt, Kmm, zqsr_corr, ze1, ze2, ze3 ) 
+         !
+         DO jk = 1, nksr      
             etot(:,:,jk) =  ze1(:,:,jk) + ze2(:,:,jk) + ze3(:,:,jk)
          END DO
@@ -130,7 +125,7 @@
          zqsr_corr(:,:) = qsr(:,:) / ( 1.-fr_i(:,:) + rtrn )
          !
-         CALL p4z_opt_par( kt, zqsr_corr, ze1, ze2, ze3, pqsr100 = zqsr100  ) 
-         !
-         DO jk = 1, nksrp      
+         CALL p4z_opt_par( kt, Kmm, zqsr_corr, ze1, ze2, ze3, pqsr100 = zqsr100  ) 
+         !
+         DO jk = 1, nksr      
             etot (:,:,jk) =        ze1(:,:,jk) +        ze2(:,:,jk) +       ze3(:,:,jk)
             enano(:,:,jk) =  1.85 * ze1(:,:,jk) + 0.69 * ze2(:,:,jk) + 0.46 * ze3(:,:,jk)
@@ -138,5 +133,5 @@
          END DO
          IF( ln_p5z ) THEN
-            DO jk = 1, nksrp      
+            DO jk = 1, nksr      
               epico(:,:,jk) =  1.94 * ze1(:,:,jk) + 0.66 * ze2(:,:,jk) + 0.4 * ze3(:,:,jk)
             END DO
@@ -148,8 +143,8 @@
       IF( ln_qsr_bio ) THEN                    !* heat flux accros w-level (used in the dynamics)
          !                                     !  ------------------------
-         CALL p4z_opt_par( kt, qsr, ze1, ze2, ze3, pe0=ze0 )
+         CALL p4z_opt_par( kt, Kmm, qsr, ze1, ze2, ze3, pe0=ze0 )
          !
          etot3(:,:,1) =  qsr(:,:) * tmask(:,:,1)
-         DO jk = 2, nksrp + 1
+         DO jk = 2, nksr + 1
             etot3(:,:,jk) =  ( ze0(:,:,jk) + ze1(:,:,jk) + ze2(:,:,jk) + ze3(:,:,jk) ) * tmask(:,:,jk)
          END DO
@@ -158,21 +153,17 @@
       !                                        !* Euphotic depth and level
       neln   (:,:) = 1                            !  ------------------------
-      heup   (:,:) = gdepw_n(:,:,2)
-      heup_01(:,:) = gdepw_n(:,:,2)
-
-      DO jk = 2, nksrp
-         DO jj = 1, jpj
-           DO ji = 1, jpi
-              IF( etot_ndcy(ji,jj,jk) * tmask(ji,jj,jk) >=  zqsr100(ji,jj) )  THEN
-                 neln(ji,jj) = jk+1                    ! Euphotic level : 1rst T-level strictly below Euphotic layer
-                 !                                     ! nb: ensure the compatibility with nmld_trc definition in trd_mld_trc_zint
-                 heup(ji,jj) = gdepw_n(ji,jj,jk+1)     ! Euphotic layer depth
-              ENDIF
-              IF( etot_ndcy(ji,jj,jk) * tmask(ji,jj,jk) >= 0.50 )  THEN
-                 heup_01(ji,jj) = gdepw_n(ji,jj,jk+1)  ! Euphotic layer depth (light level definition)
-              ENDIF
-           END DO
-        END DO
-      END DO
+      heup   (:,:) = gdepw(:,:,2,Kmm)
+      heup_01(:,:) = gdepw(:,:,2,Kmm)
+
+      DO_3D( 1, 1, 1, 1, 2, nksr )
+        IF( etot_ndcy(ji,jj,jk) * tmask(ji,jj,jk) >=  zqsr100(ji,jj) )  THEN
+           neln(ji,jj) = jk+1                    ! Euphotic level : 1rst T-level strictly below Euphotic layer
+           !                                     ! nb: ensure the compatibility with nmld_trc definition in trd_mld_trc_zint
+           heup(ji,jj) = gdepw(ji,jj,jk+1,Kmm)     ! Euphotic layer depth
+        ENDIF
+        IF( etot_ndcy(ji,jj,jk) * tmask(ji,jj,jk) >= 0.50 )  THEN
+           heup_01(ji,jj) = gdepw(ji,jj,jk+1,Kmm)  ! Euphotic layer depth (light level definition)
+        ENDIF
+      END_3D
       !
       heup   (:,:) = MIN( 300., heup   (:,:) )
@@ -183,30 +174,22 @@
       zetmp2 (:,:)   = 0.e0
 
-      DO jk = 1, nksrp
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( gdepw_n(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
-                  zetmp1 (ji,jj) = zetmp1 (ji,jj) + etot     (ji,jj,jk) * e3t_n(ji,jj,jk) ! remineralisation
-                  zetmp2 (ji,jj) = zetmp2 (ji,jj) + etot_ndcy(ji,jj,jk) * e3t_n(ji,jj,jk) ! production
-                  zdepmoy(ji,jj) = zdepmoy(ji,jj) +                       e3t_n(ji,jj,jk)
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, nksr )
+         IF( gdepw(ji,jj,jk+1,Kmm) <= hmld(ji,jj) ) THEN
+            zetmp1 (ji,jj) = zetmp1 (ji,jj) + etot     (ji,jj,jk) * e3t(ji,jj,jk,Kmm) ! remineralisation
+            zetmp2 (ji,jj) = zetmp2 (ji,jj) + etot_ndcy(ji,jj,jk) * e3t(ji,jj,jk,Kmm) ! production
+            zdepmoy(ji,jj) = zdepmoy(ji,jj) +                       e3t(ji,jj,jk,Kmm)
+         ENDIF
+      END_3D
       !
       emoy(:,:,:) = etot(:,:,:)       ! remineralisation
       zpar(:,:,:) = etot_ndcy(:,:,:)  ! diagnostic : PAR with no diurnal cycle 
       !
-      DO jk = 1, nksrp
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( gdepw_n(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
-                  z1_dep = 1. / ( zdepmoy(ji,jj) + rtrn )
-                  emoy (ji,jj,jk) = zetmp1(ji,jj) * z1_dep
-                  zpar (ji,jj,jk) = zetmp2(ji,jj) * z1_dep
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, nksr )
+         IF( gdepw(ji,jj,jk+1,Kmm) <= hmld(ji,jj) ) THEN
+            z1_dep = 1. / ( zdepmoy(ji,jj) + rtrn )
+            emoy (ji,jj,jk) = zetmp1(ji,jj) * z1_dep
+            zpar (ji,jj,jk) = zetmp2(ji,jj) * z1_dep
+         ENDIF
+      END_3D
       !
       zdepmoy(:,:)   = 0.e0
@@ -214,64 +197,47 @@
       zetmp4 (:,:)   = 0.e0
       !
-      DO jk = 1, nksrp
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( gdepw_n(ji,jj,jk+1) <= MIN(hmld(ji,jj), heup_01(ji,jj)) ) THEN
-                  zetmp3 (ji,jj) = zetmp3 (ji,jj) + enano    (ji,jj,jk) * e3t_n(ji,jj,jk) ! production
-                  zetmp4 (ji,jj) = zetmp4 (ji,jj) + ediat    (ji,jj,jk) * e3t_n(ji,jj,jk) ! production
-                  zdepmoy(ji,jj) = zdepmoy(ji,jj) +                       e3t_n(ji,jj,jk)
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, nksr )
+         IF( gdepw(ji,jj,jk+1,Kmm) <= MIN(hmld(ji,jj), heup_01(ji,jj)) ) THEN
+            zetmp3 (ji,jj) = zetmp3 (ji,jj) + enano    (ji,jj,jk) * e3t(ji,jj,jk,Kmm) ! production
+            zetmp4 (ji,jj) = zetmp4 (ji,jj) + ediat    (ji,jj,jk) * e3t(ji,jj,jk,Kmm) ! production
+            zdepmoy(ji,jj) = zdepmoy(ji,jj) +                       e3t(ji,jj,jk,Kmm)
+         ENDIF
+      END_3D
       enanom(:,:,:) = enano(:,:,:)
       ediatm(:,:,:) = ediat(:,:,:)
       !
-      DO jk = 1, nksrp
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( gdepw_n(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
-                  z1_dep = 1. / ( zdepmoy(ji,jj) + rtrn )
-                  enanom(ji,jj,jk) = zetmp3(ji,jj) * z1_dep
-                  ediatm(ji,jj,jk) = zetmp4(ji,jj) * z1_dep
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, nksr )
+         IF( gdepw(ji,jj,jk+1,Kmm) <= hmld(ji,jj) ) THEN
+            z1_dep = 1. / ( zdepmoy(ji,jj) + rtrn )
+            enanom(ji,jj,jk) = zetmp3(ji,jj) * z1_dep
+            ediatm(ji,jj,jk) = zetmp4(ji,jj) * z1_dep
+         ENDIF
+      END_3D
       !
       IF( ln_p5z ) THEN
-         zetmp5 (:,:) = 0.e0
-         DO jk = 1, nksrp
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  IF( gdepw_n(ji,jj,jk+1) <= MIN(hmld(ji,jj), heup_01(ji,jj)) ) THEN
-                     zetmp5(ji,jj)  = zetmp5 (ji,jj) + epico(ji,jj,jk) * e3t_n(ji,jj,jk) ! production
-                  ENDIF
-               END DO
-            END DO
-         END DO
+         ALLOCATE( zetmp5(jpi,jpj) )  ;   zetmp5 (:,:) = 0.e0
+         DO_3D( 1, 1, 1, 1, 1, nksr )
+            IF( gdepw(ji,jj,jk+1,Kmm) <= MIN(hmld(ji,jj), heup_01(ji,jj)) ) THEN
+               zetmp5(ji,jj)  = zetmp5 (ji,jj) + epico(ji,jj,jk) * e3t(ji,jj,jk,Kmm) ! production
+            ENDIF
+         END_3D
          !
          epicom(:,:,:) = epico(:,:,:)
          !
-         DO jk = 1, nksrp
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  IF( gdepw_n(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
-                     z1_dep = 1. / ( zdepmoy(ji,jj) + rtrn )
-                     epicom(ji,jj,jk) = zetmp5(ji,jj) * z1_dep
-                  ENDIF
-               END DO
-            END DO
-         END DO
-      ENDIF
-      IF( lk_iomput ) THEN
-        IF( knt == nrdttrc ) THEN
-           IF( iom_use( "Heup"  ) ) CALL iom_put( "Heup" , heup(:,:  ) * tmask(:,:,1) )  ! euphotic layer deptht
-           IF( iom_use( "PARDM" ) ) CALL iom_put( "PARDM", zpar(:,:,:) * tmask(:,:,:) )  ! Photosynthetically Available Radiation
-           IF( iom_use( "PAR"   ) ) CALL iom_put( "PAR"  , emoy(:,:,:) * tmask(:,:,:) )  ! Photosynthetically Available Radiation
-        ENDIF
-      ENDIF
-      !
-      IF( ln_p5z    )   DEALLOCATE( zetmp5 )
+         DO_3D( 1, 1, 1, 1, 1, nksr )
+            IF( gdepw(ji,jj,jk+1,Kmm) <= hmld(ji,jj) ) THEN
+               z1_dep = 1. / ( zdepmoy(ji,jj) + rtrn )
+               epicom(ji,jj,jk) = zetmp5(ji,jj) * z1_dep
+            ENDIF
+         END_3D
+         DEALLOCATE( zetmp5 )
+      ENDIF
+      !
+      IF( lk_iomput .AND.  knt == nrdttrc ) THEN
+         CALL iom_put( "Heup" , heup(:,:  ) * tmask(:,:,1) )  ! euphotic layer deptht
+         CALL iom_put( "PARDM", zpar(:,:,:) * tmask(:,:,:) )  ! Photosynthetically Available Radiation
+         CALL iom_put( "PAR"  , emoy(:,:,:) * tmask(:,:,:) )  ! Photosynthetically Available Radiation
+      ENDIF
+      !
       IF( ln_timing )   CALL timing_stop('p4z_opt')
       !
@@ -279,5 +245,5 @@
 
 
-   SUBROUTINE p4z_opt_par( kt, pqsr, pe1, pe2, pe3, pe0, pqsr100 ) 
+   SUBROUTINE p4z_opt_par( kt, Kmm, pqsr, pe1, pe2, pe3, pe0, pqsr100 ) 
       !!----------------------------------------------------------------------
       !!                  ***  routine p4z_opt_par  ***
@@ -288,4 +254,5 @@
       !!----------------------------------------------------------------------
       INTEGER                         , INTENT(in)              ::   kt                ! ocean time-step
+      INTEGER                         , INTENT(in)              ::   Kmm               ! ocean time-index
       REAL(wp), DIMENSION(jpi,jpj)    , INTENT(in   )           ::   pqsr              ! shortwave
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout)           ::   pe1 , pe2 , pe3   ! PAR ( R-G-B)
@@ -312,8 +279,8 @@
          pe3(:,:,1) = zqsr(:,:)
          !
-         DO jk = 2, nksrp + 1
+         DO jk = 2, nksr + 1
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  pe0(ji,jj,jk) = pe0(ji,jj,jk-1) * EXP( -e3t_n(ji,jj,jk-1) * xsi0r )
+                  pe0(ji,jj,jk) = pe0(ji,jj,jk-1) * EXP( -e3t(ji,jj,jk-1,Kmm) * xsi0r )
                   pe1(ji,jj,jk) = pe1(ji,jj,jk-1) * EXP( -ekb  (ji,jj,jk-1 )        )
                   pe2(ji,jj,jk) = pe2(ji,jj,jk-1) * EXP( -ekg  (ji,jj,jk-1 )        )
@@ -331,13 +298,9 @@
         pe3(:,:,1) = zqsr(:,:) * EXP( -0.5 * ekr(:,:,1) )
         !
-        DO jk = 2, nksrp      
-           DO jj = 1, jpj
-              DO ji = 1, jpi
-                 pe1(ji,jj,jk) = pe1(ji,jj,jk-1) * EXP( -0.5 * ( ekb(ji,jj,jk-1) + ekb(ji,jj,jk) ) )
-                 pe2(ji,jj,jk) = pe2(ji,jj,jk-1) * EXP( -0.5 * ( ekg(ji,jj,jk-1) + ekg(ji,jj,jk) ) )
-                 pe3(ji,jj,jk) = pe3(ji,jj,jk-1) * EXP( -0.5 * ( ekr(ji,jj,jk-1) + ekr(ji,jj,jk) ) )
-              END DO
-           END DO
-        END DO    
+        DO_3D( 1, 1, 1, 1, 2, nksr )
+           pe1(ji,jj,jk) = pe1(ji,jj,jk-1) * EXP( -0.5 * ( ekb(ji,jj,jk-1) + ekb(ji,jj,jk) ) )
+           pe2(ji,jj,jk) = pe2(ji,jj,jk-1) * EXP( -0.5 * ( ekg(ji,jj,jk-1) + ekg(ji,jj,jk) ) )
+           pe3(ji,jj,jk) = pe3(ji,jj,jk-1) * EXP( -0.5 * ( ekr(ji,jj,jk-1) + ekr(ji,jj,jk) ) )
+        END_3D
         !
       ENDIF
@@ -400,10 +363,8 @@
          WRITE(numout,*) '~~~~~~~~~~~~ '
       ENDIF
-      REWIND( numnatp_ref )              ! Namelist nampisopt in reference namelist : Pisces attenuation coef. and PAR
       READ  ( numnatp_ref, nampisopt, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisopt in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampisopt in configuration namelist : Pisces attenuation coef. and PAR
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisopt in reference namelist' )
       READ  ( numnatp_cfg, nampisopt, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisopt in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisopt in configuration namelist' )
       IF(lwm) WRITE ( numonp, nampisopt )
 
@@ -435,9 +396,4 @@
          ntimes_par = iom_getszuld( numpar )   ! get number of record in file
       ENDIF
-      !
-      CALL trc_oce_rgb( xkrgb )                  ! tabulated attenuation coefficients
-      nksrp = trc_oce_ext_lev( r_si2, 0.33e2 )     ! max level of light extinction (Blue Chl=0.01)
-      !
-      IF(lwp) WRITE(numout,*) '        level of light extinction = ', nksrp, ' ref depth = ', gdepw_1d(nksrp+1), ' m'
       !
                          ekr      (:,:,:) = 0._wp
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zpoc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zpoc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zpoc.F90	(revision 13463)
@@ -15,5 +15,5 @@
    USE trc             !  passive tracers common variables 
    USE sms_pisces      !  PISCES Source Minus Sink variables
-   USE prtctl_trc      !  print control for debugging
+   USE prtctl          !  print control for debugging
    USE iom             !  I/O manager
 
@@ -37,4 +37,7 @@
 
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -44,5 +47,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_poc( kt, knt )
+   SUBROUTINE p4z_poc( kt, knt, Kbb, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_poc  ***
@@ -52,5 +55,6 @@
       !! ** Method  : - ???
       !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt, knt   ! ocean time step and ???
+      INTEGER, INTENT(in) ::   kt, knt         ! ocean time step and ???
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Krhs  ! time level indices
       !
       INTEGER  ::   ji, jj, jk, jn
@@ -103,87 +107,83 @@
      ! -----------------------------------------------------------------------
      ztremint(:,:,:) = zremigoc(:,:,:)
-     DO jk = 2, jpkm1
-        DO jj = 1, jpj
-           DO ji = 1, jpi
-              IF (tmask(ji,jj,jk) == 1.) THEN
-                zdep = hmld(ji,jj)
-                !
-                ! In the case of GOC, lability is constant in the mixed layer 
-                ! It is computed only below the mixed layer depth
-                ! ------------------------------------------------------------
-                !
-                IF( gdept_n(ji,jj,jk) > zdep ) THEN
-                  alphat = 0.
-                  remint = 0.
-                  !
-                  zsizek1  = e3t_n(ji,jj,jk-1) / 2. / (wsbio4(ji,jj,jk-1) + rtrn) * tgfunc(ji,jj,jk-1)
-                  zsizek = e3t_n(ji,jj,jk) / 2. / (wsbio4(ji,jj,jk) + rtrn) * tgfunc(ji,jj,jk)
-                  !
-                  IF ( gdept_n(ji,jj,jk-1) <= zdep ) THEN
-                    ! 
-                    ! The first level just below the mixed layer needs a 
-                    ! specific treatment because lability is supposed constant
-                    ! everywhere within the mixed layer. This means that 
-                    ! change in lability in the bottom part of the previous cell
-                    ! should not be computed
-                    ! ----------------------------------------------------------
-                    !
-                    ! POC concentration is computed using the lagrangian 
-                    ! framework. It is only used for the lability param
-                    zpoc = trb(ji,jj,jk-1,jpgoc) + consgoc(ji,jj,jk) * rday / rfact2               &
-                    &   * e3t_n(ji,jj,jk) / 2. / (wsbio4(ji,jj,jk) + rtrn)
-                    zpoc = MAX(0., zpoc)
-                    !
-                    DO jn = 1, jcpoc
-                       !
-                       ! Lagrangian based algorithm. The fraction of each 
-                       ! lability class is computed starting from the previous
-                       ! level
-                       ! -----------------------------------------------------
-                       !
-                       ! the concentration of each lability class is calculated
-                       ! as the sum of the different sources and sinks
-                       ! Please note that production of new GOC experiences
-                       ! degradation 
-                       alphag(ji,jj,jk,jn) = alphag(ji,jj,jk-1,jn) * exp( -reminp(jn) * zsizek ) * zpoc &
-                       &   + prodgoc(ji,jj,jk) * alphan(jn) / tgfunc(ji,jj,jk) / reminp(jn)             &
-                       &   * ( 1. - exp( -reminp(jn) * zsizek ) ) * rday / rfact2 
-                       alphat = alphat + alphag(ji,jj,jk,jn)
-                       remint = remint + alphag(ji,jj,jk,jn) * reminp(jn)
-                    END DO
-                  ELSE
-                    !
-                    ! standard algorithm in the rest of the water column
-                    ! See the comments in the previous block.
-                    ! ---------------------------------------------------
-                    !
-                    zpoc = trb(ji,jj,jk-1,jpgoc) + consgoc(ji,jj,jk-1) * rday / rfact2               &
-                    &   * e3t_n(ji,jj,jk-1) / 2. / (wsbio4(ji,jj,jk-1) + rtrn) + consgoc(ji,jj,jk)   &
-                    &   * rday / rfact2 * e3t_n(ji,jj,jk) / 2. / (wsbio4(ji,jj,jk) + rtrn)
-                    zpoc = max(0., zpoc)
-                    !
-                    DO jn = 1, jcpoc
-                       alphag(ji,jj,jk,jn) = alphag(ji,jj,jk-1,jn) * exp( -reminp(jn) * ( zsizek              &
-                       &   + zsizek1 ) ) * zpoc + ( prodgoc(ji,jj,jk-1) / tgfunc(ji,jj,jk-1) * ( 1.           &
-                       &   - exp( -reminp(jn) * zsizek1 ) ) * exp( -reminp(jn) * zsizek ) + prodgoc(ji,jj,jk) &
-                       &   / tgfunc(ji,jj,jk) * ( 1. - exp( -reminp(jn) * zsizek ) ) ) * rday / rfact2 / reminp(jn) * alphan(jn) 
-                       alphat = alphat + alphag(ji,jj,jk,jn)
-                       remint = remint + alphag(ji,jj,jk,jn) * reminp(jn)
-                    END DO
-                  ENDIF
-                  !
-                  DO jn = 1, jcpoc
-                     ! The contribution of each lability class at the current
-                     ! level is computed
-                     alphag(ji,jj,jk,jn) = alphag(ji,jj,jk,jn) / ( alphat + rtrn)
-                  END DO
-                  ! Computation of the mean remineralisation rate
-                  ztremint(ji,jj,jk) =  MAX(0., remint / ( alphat + rtrn) )
-                  !
-                ENDIF
-              ENDIF
+     DO_3D( 1, 1, 1, 1, 2, jpkm1 )
+        IF (tmask(ji,jj,jk) == 1.) THEN
+          zdep = hmld(ji,jj)
+          !
+          ! In the case of GOC, lability is constant in the mixed layer 
+          ! It is computed only below the mixed layer depth
+          ! ------------------------------------------------------------
+          !
+          IF( gdept(ji,jj,jk,Kmm) > zdep ) THEN
+            alphat = 0.
+            remint = 0.
+            !
+            zsizek1  = e3t(ji,jj,jk-1,Kmm) / 2. / (wsbio4(ji,jj,jk-1) + rtrn) * tgfunc(ji,jj,jk-1)
+            zsizek = e3t(ji,jj,jk,Kmm) / 2. / (wsbio4(ji,jj,jk) + rtrn) * tgfunc(ji,jj,jk)
+            !
+            IF ( gdept(ji,jj,jk-1,Kmm) <= zdep ) THEN
+              ! 
+              ! The first level just below the mixed layer needs a 
+              ! specific treatment because lability is supposed constant
+              ! everywhere within the mixed layer. This means that 
+              ! change in lability in the bottom part of the previous cell
+              ! should not be computed
+              ! ----------------------------------------------------------
+              !
+              ! POC concentration is computed using the lagrangian 
+              ! framework. It is only used for the lability param
+              zpoc = tr(ji,jj,jk-1,jpgoc,Kbb) + consgoc(ji,jj,jk) * rday / rfact2               &
+              &   * e3t(ji,jj,jk,Kmm) / 2. / (wsbio4(ji,jj,jk) + rtrn)
+              zpoc = MAX(0., zpoc)
+              !
+              DO jn = 1, jcpoc
+                 !
+                 ! Lagrangian based algorithm. The fraction of each 
+                 ! lability class is computed starting from the previous
+                 ! level
+                 ! -----------------------------------------------------
+                 !
+                 ! the concentration of each lability class is calculated
+                 ! as the sum of the different sources and sinks
+                 ! Please note that production of new GOC experiences
+                 ! degradation 
+                 alphag(ji,jj,jk,jn) = alphag(ji,jj,jk-1,jn) * exp( -reminp(jn) * zsizek ) * zpoc &
+                 &   + prodgoc(ji,jj,jk) * alphan(jn) / tgfunc(ji,jj,jk) / reminp(jn)             &
+                 &   * ( 1. - exp( -reminp(jn) * zsizek ) ) * rday / rfact2 
+                 alphat = alphat + alphag(ji,jj,jk,jn)
+                 remint = remint + alphag(ji,jj,jk,jn) * reminp(jn)
+              END DO
+            ELSE
+              !
+              ! standard algorithm in the rest of the water column
+              ! See the comments in the previous block.
+              ! ---------------------------------------------------
+              !
+              zpoc = tr(ji,jj,jk-1,jpgoc,Kbb) + consgoc(ji,jj,jk-1) * rday / rfact2               &
+              &   * e3t(ji,jj,jk-1,Kmm) / 2. / (wsbio4(ji,jj,jk-1) + rtrn) + consgoc(ji,jj,jk)   &
+              &   * rday / rfact2 * e3t(ji,jj,jk,Kmm) / 2. / (wsbio4(ji,jj,jk) + rtrn)
+              zpoc = max(0., zpoc)
+              !
+              DO jn = 1, jcpoc
+                 alphag(ji,jj,jk,jn) = alphag(ji,jj,jk-1,jn) * exp( -reminp(jn) * ( zsizek              &
+                 &   + zsizek1 ) ) * zpoc + ( prodgoc(ji,jj,jk-1) / tgfunc(ji,jj,jk-1) * ( 1.           &
+                 &   - exp( -reminp(jn) * zsizek1 ) ) * exp( -reminp(jn) * zsizek ) + prodgoc(ji,jj,jk) &
+                 &   / tgfunc(ji,jj,jk) * ( 1. - exp( -reminp(jn) * zsizek ) ) ) * rday / rfact2 / reminp(jn) * alphan(jn) 
+                 alphat = alphat + alphag(ji,jj,jk,jn)
+                 remint = remint + alphag(ji,jj,jk,jn) * reminp(jn)
+              END DO
+            ENDIF
+            !
+            DO jn = 1, jcpoc
+               ! The contribution of each lability class at the current
+               ! level is computed
+               alphag(ji,jj,jk,jn) = alphag(ji,jj,jk,jn) / ( alphat + rtrn)
             END DO
-         END DO
-      END DO
+            ! Computation of the mean remineralisation rate
+            ztremint(ji,jj,jk) =  MAX(0., remint / ( alphat + rtrn) )
+            !
+          ENDIF
+        ENDIF
+     END_3D
 
       IF( ln_p4z ) THEN   ;   zremigoc(:,:,:) = MIN( xremip , ztremint(:,:,:) )
@@ -192,64 +192,56 @@
 
       IF( ln_p4z ) THEN
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ! POC disaggregation by turbulence and bacterial activity. 
-                  ! --------------------------------------------------------
-                  zremig = zremigoc(ji,jj,jk) * xstep * tgfunc(ji,jj,jk)
-                  zorem2  = zremig * trb(ji,jj,jk,jpgoc)
-                  orem(ji,jj,jk)      = zorem2
-                  zorem3(ji,jj,jk) = zremig * solgoc * trb(ji,jj,jk,jpgoc)
-                  zofer2 = zremig * trb(ji,jj,jk,jpbfe)
-                  zofer3 = zremig * solgoc * trb(ji,jj,jk,jpbfe)
-
-                  ! -------------------------------------
-                  tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zorem3(ji,jj,jk)
-                  tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) - zorem2 - zorem3(ji,jj,jk)
-                  tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + zofer3
-                  tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) - zofer2 - zofer3
-                  tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + zorem2
-                  tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + zofer2
-                  zfolimi(ji,jj,jk)   = zofer2
-               END DO
-            END DO
-         END DO
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+            ! POC disaggregation by turbulence and bacterial activity. 
+            ! --------------------------------------------------------
+            zremig = zremigoc(ji,jj,jk) * xstep * tgfunc(ji,jj,jk)
+            zorem2  = zremig * tr(ji,jj,jk,jpgoc,Kbb)
+            orem(ji,jj,jk)      = zorem2
+            zorem3(ji,jj,jk) = zremig * solgoc * tr(ji,jj,jk,jpgoc,Kbb)
+            zofer2 = zremig * tr(ji,jj,jk,jpbfe,Kbb)
+            zofer3 = zremig * solgoc * tr(ji,jj,jk,jpbfe,Kbb)
+
+            ! -------------------------------------
+            tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) + zorem3(ji,jj,jk)
+            tr(ji,jj,jk,jpgoc,Krhs) = tr(ji,jj,jk,jpgoc,Krhs) - zorem2 - zorem3(ji,jj,jk)
+            tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) + zofer3
+            tr(ji,jj,jk,jpbfe,Krhs) = tr(ji,jj,jk,jpbfe,Krhs) - zofer2 - zofer3
+            tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) + zorem2
+            tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) + zofer2
+            zfolimi(ji,jj,jk)   = zofer2
+         END_3D
       ELSE
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                   ! POC disaggregation by turbulence and bacterial activity. 
-                  ! --------------------------------------------------------
-                  zremig = zremigoc(ji,jj,jk) * xstep * tgfunc(ji,jj,jk)
-                  zopoc2 = zremig  * trb(ji,jj,jk,jpgoc)
-                  orem(ji,jj,jk) = zopoc2
-                  zorem3(ji,jj,jk) = zremig * solgoc * trb(ji,jj,jk,jpgoc)
-                  zopon2 = xremipn / xremipc * zremig * trb(ji,jj,jk,jpgon)
-                  zopop2 = xremipp / xremipc * zremig * trb(ji,jj,jk,jpgop)
-                  zofer2 = xremipn / xremipc * zremig * trb(ji,jj,jk,jpbfe)
-
-                  ! -------------------------------------
-                  tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zorem3(ji,jj,jk)
-                  tra(ji,jj,jk,jppon) = tra(ji,jj,jk,jppon) + solgoc * zopon2 
-                  tra(ji,jj,jk,jppop) = tra(ji,jj,jk,jppop) + solgoc * zopop2
-                  tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + solgoc * zofer2
-                  tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + zopoc2
-                  tra(ji,jj,jk,jpdon) = tra(ji,jj,jk,jpdon) + zopon2
-                  tra(ji,jj,jk,jpdop) = tra(ji,jj,jk,jpdop) + zopop2
-                  tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + zofer2
-                  tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) - zopoc2 - zorem3(ji,jj,jk)
-                  tra(ji,jj,jk,jpgon) = tra(ji,jj,jk,jpgon) - zopon2 * (1. + solgoc)
-                  tra(ji,jj,jk,jpgop) = tra(ji,jj,jk,jpgop) - zopop2 * (1. + solgoc)
-                  tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) - zofer2 * (1. + solgoc)
-                  zfolimi(ji,jj,jk)   = zofer2
-               END DO
-            END DO
-         END DO
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+             ! POC disaggregation by turbulence and bacterial activity. 
+            ! --------------------------------------------------------
+            zremig = zremigoc(ji,jj,jk) * xstep * tgfunc(ji,jj,jk)
+            zopoc2 = zremig  * tr(ji,jj,jk,jpgoc,Kbb)
+            orem(ji,jj,jk) = zopoc2
+            zorem3(ji,jj,jk) = zremig * solgoc * tr(ji,jj,jk,jpgoc,Kbb)
+            zopon2 = xremipn / xremipc * zremig * tr(ji,jj,jk,jpgon,Kbb)
+            zopop2 = xremipp / xremipc * zremig * tr(ji,jj,jk,jpgop,Kbb)
+            zofer2 = xremipn / xremipc * zremig * tr(ji,jj,jk,jpbfe,Kbb)
+
+            ! -------------------------------------
+            tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) + zorem3(ji,jj,jk)
+            tr(ji,jj,jk,jppon,Krhs) = tr(ji,jj,jk,jppon,Krhs) + solgoc * zopon2 
+            tr(ji,jj,jk,jppop,Krhs) = tr(ji,jj,jk,jppop,Krhs) + solgoc * zopop2
+            tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) + solgoc * zofer2
+            tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) + zopoc2
+            tr(ji,jj,jk,jpdon,Krhs) = tr(ji,jj,jk,jpdon,Krhs) + zopon2
+            tr(ji,jj,jk,jpdop,Krhs) = tr(ji,jj,jk,jpdop,Krhs) + zopop2
+            tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) + zofer2
+            tr(ji,jj,jk,jpgoc,Krhs) = tr(ji,jj,jk,jpgoc,Krhs) - zopoc2 - zorem3(ji,jj,jk)
+            tr(ji,jj,jk,jpgon,Krhs) = tr(ji,jj,jk,jpgon,Krhs) - zopon2 * (1. + solgoc)
+            tr(ji,jj,jk,jpgop,Krhs) = tr(ji,jj,jk,jpgop,Krhs) - zopop2 * (1. + solgoc)
+            tr(ji,jj,jk,jpbfe,Krhs) = tr(ji,jj,jk,jpbfe,Krhs) - zofer2 * (1. + solgoc)
+            zfolimi(ji,jj,jk)   = zofer2
+         END_3D
       ENDIF
 
-     IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+     IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
         WRITE(charout, FMT="('poc1')")
-        CALL prt_ctl_trc_info(charout)
-        CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+        CALL prt_ctl_info( charout, cdcomp = 'top' )
+        CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
      ENDIF
 
@@ -268,18 +260,14 @@
      ! ----------------------------------------------------------------
      ! 
-     DO jk = 1, jpkm1
-        DO jj = 1, jpj
-           DO ji = 1, jpi
-              zdep = hmld(ji,jj)
-              IF (tmask(ji,jj,jk) == 1. .AND. gdept_n(ji,jj,jk) <= zdep ) THEN
-                totprod(ji,jj) = totprod(ji,jj) + prodpoc(ji,jj,jk) * e3t_n(ji,jj,jk) * rday/ rfact2
-                ! The temperature effect is included here
-                totthick(ji,jj) = totthick(ji,jj) + e3t_n(ji,jj,jk)* tgfunc(ji,jj,jk)
-                totcons(ji,jj) = totcons(ji,jj) - conspoc(ji,jj,jk) * e3t_n(ji,jj,jk) * rday/ rfact2    &
-                &                / ( trb(ji,jj,jk,jppoc) + rtrn )
-              ENDIF
-           END DO
-        END DO
-     END DO
+     DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+        zdep = hmld(ji,jj)
+        IF (tmask(ji,jj,jk) == 1. .AND. gdept(ji,jj,jk,Kmm) <= zdep ) THEN
+          totprod(ji,jj) = totprod(ji,jj) + prodpoc(ji,jj,jk) * e3t(ji,jj,jk,Kmm) * rday/ rfact2
+          ! The temperature effect is included here
+          totthick(ji,jj) = totthick(ji,jj) + e3t(ji,jj,jk,Kmm)* tgfunc(ji,jj,jk)
+          totcons(ji,jj) = totcons(ji,jj) - conspoc(ji,jj,jk) * e3t(ji,jj,jk,Kmm) * rday/ rfact2    &
+          &                / ( tr(ji,jj,jk,jppoc,Kbb) + rtrn )
+        ENDIF
+     END_3D
 
      ! Computation of the lability spectrum in the mixed layer. In the mixed 
@@ -287,30 +275,26 @@
      ! ---------------------------------------------------------------------
      ztremint(:,:,:) = zremipoc(:,:,:)
-     DO jk = 1, jpkm1
-        DO jj = 1, jpj
-           DO ji = 1, jpi
-              IF (tmask(ji,jj,jk) == 1.) THEN
-                zdep = hmld(ji,jj)
-                alphat = 0.0
-                remint = 0.0
-                IF( gdept_n(ji,jj,jk) <= zdep ) THEN
-                   DO jn = 1, jcpoc
-                      ! For each lability class, the system is supposed to be 
-                      ! at equilibrium: Prod - Sink - w alphap = 0.
-                      alphap(ji,jj,jk,jn) = totprod(ji,jj) * alphan(jn) / ( reminp(jn)    &
-                      &                     * totthick(ji,jj) + totcons(ji,jj) + wsbio + rtrn )
-                      alphat = alphat + alphap(ji,jj,jk,jn)
-                   END DO
-                   DO jn = 1, jcpoc
-                      alphap(ji,jj,jk,jn) = alphap(ji,jj,jk,jn) / ( alphat + rtrn)
-                      remint = remint + alphap(ji,jj,jk,jn) * reminp(jn)
-                   END DO
-                   ! Mean remineralization rate in the mixed layer
-                   ztremint(ji,jj,jk) =  MAX( 0., remint )
-                ENDIF
-              ENDIF
-           END DO
-        END DO
-     END DO
+     DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+        IF (tmask(ji,jj,jk) == 1.) THEN
+          zdep = hmld(ji,jj)
+          alphat = 0.0
+          remint = 0.0
+          IF( gdept(ji,jj,jk,Kmm) <= zdep ) THEN
+             DO jn = 1, jcpoc
+                ! For each lability class, the system is supposed to be 
+                ! at equilibrium: Prod - Sink - w alphap = 0.
+                alphap(ji,jj,jk,jn) = totprod(ji,jj) * alphan(jn) / ( reminp(jn)    &
+                &                     * totthick(ji,jj) + totcons(ji,jj) + wsbio + rtrn )
+                alphat = alphat + alphap(ji,jj,jk,jn)
+             END DO
+             DO jn = 1, jcpoc
+                alphap(ji,jj,jk,jn) = alphap(ji,jj,jk,jn) / ( alphat + rtrn)
+                remint = remint + alphap(ji,jj,jk,jn) * reminp(jn)
+             END DO
+             ! Mean remineralization rate in the mixed layer
+             ztremint(ji,jj,jk) =  MAX( 0., remint )
+          ENDIF
+        ENDIF
+     END_3D
      !
      IF( ln_p4z ) THEN   ;  zremipoc(:,:,:) = MIN( xremip , ztremint(:,:,:) )
@@ -326,76 +310,72 @@
      ! -----------------------------------------------------------------------
      !
-     DO jk = 2, jpkm1
-        DO jj = 1, jpj
-           DO ji = 1, jpi
-              IF (tmask(ji,jj,jk) == 1.) THEN
-                zdep = hmld(ji,jj)
-                IF( gdept_n(ji,jj,jk) > zdep ) THEN
-                  alphat = 0.
-                  remint = 0.
-                  !
-                  ! the scale factors are corrected with temperature
-                  zsizek1  = e3t_n(ji,jj,jk-1) / 2. / (wsbio3(ji,jj,jk-1) + rtrn) * tgfunc(ji,jj,jk-1)
-                  zsizek = e3t_n(ji,jj,jk) / 2. / (wsbio3(ji,jj,jk) + rtrn) * tgfunc(ji,jj,jk)
-                  !
-                  ! Special treatment of the level just below the MXL
-                  ! See the comments in the GOC section
-                  ! ---------------------------------------------------
-                  !
-                  IF ( gdept_n(ji,jj,jk-1) <= zdep ) THEN
-                    !
-                    ! Computation of the POC concentration using the 
-                    ! lagrangian algorithm
-                    zpoc = trb(ji,jj,jk-1,jppoc) + conspoc(ji,jj,jk) * rday / rfact2               &
-                    &   * e3t_n(ji,jj,jk) / 2. / (wsbio3(ji,jj,jk) + rtrn)
-                    zpoc = max(0., zpoc)
-                    ! 
-                    DO jn = 1, jcpoc
-                       ! computation of the lability spectrum applying the 
-                       ! different sources and sinks
-                       alphap(ji,jj,jk,jn) = alphap(ji,jj,jk-1,jn) * exp( -reminp(jn) * zsizek ) * zpoc  &
-                       &   + ( prodpoc(ji,jj,jk) * alphan(jn) + zorem3(ji,jj,jk) * alphag(ji,jj,jk,jn) ) &
-                       &   / tgfunc(ji,jj,jk) / reminp(jn) * rday / rfact2 * ( 1. - exp( -reminp(jn)     &
-                       &   * zsizek ) )
-                       alphap(ji,jj,jk,jn) = MAX( 0., alphap(ji,jj,jk,jn) )
-                       alphat = alphat + alphap(ji,jj,jk,jn)
-                    END DO
-                  ELSE
-                    !
-                    ! Lability parameterization for the interior of the ocean
-                    ! This is very similar to what is done in the previous 
-                    ! block
-                    ! --------------------------------------------------------
-                    !
-                    zpoc = trb(ji,jj,jk-1,jppoc) + conspoc(ji,jj,jk-1) * rday / rfact2               &
-                    &   * e3t_n(ji,jj,jk-1) / 2. / (wsbio3(ji,jj,jk-1) + rtrn) + conspoc(ji,jj,jk)   &
-                    &   * rday / rfact2 * e3t_n(ji,jj,jk) / 2. / (wsbio3(ji,jj,jk) + rtrn)
-                    zpoc = max(0., zpoc)
-                    !
-                    DO jn = 1, jcpoc
-                       alphap(ji,jj,jk,jn) = alphap(ji,jj,jk-1,jn) * exp( -reminp(jn)                       &
-                       &   * ( zsizek + zsizek1 ) ) * zpoc + ( prodpoc(ji,jj,jk-1) * alphan(jn)             & 
-                       &   + zorem3(ji,jj,jk-1) * alphag(ji,jj,jk-1,jn) ) * rday / rfact2 / reminp(jn)      &
-                       &   / tgfunc(ji,jj,jk-1) * ( 1. - exp( -reminp(jn) * zsizek1 ) ) * exp( -reminp(jn)  &
-                       &   * zsizek ) + ( prodpoc(ji,jj,jk) * alphan(jn) + zorem3(ji,jj,jk)                 &
-                       &   * alphag(ji,jj,jk,jn) ) * rday / rfact2 / reminp(jn) / tgfunc(ji,jj,jk) * ( 1.   &
-                       &   - exp( -reminp(jn) * zsizek ) )
-                       alphap(ji,jj,jk,jn) = max(0., alphap(ji,jj,jk,jn) )
-                       alphat = alphat + alphap(ji,jj,jk,jn)
-                    END DO
-                  ENDIF
-                  ! Normalization of the lability spectrum so that the 
-                  ! integral is equal to 1
-                  DO jn = 1, jcpoc
-                     alphap(ji,jj,jk,jn) = alphap(ji,jj,jk,jn) / ( alphat + rtrn)
-                     remint = remint + alphap(ji,jj,jk,jn) * reminp(jn)
-                  END DO
-                  ! Mean remineralization rate in the water column
-                  ztremint(ji,jj,jk) =  MAX( 0., remint )
-                ENDIF
-              ENDIF
+     DO_3D( 1, 1, 1, 1, 2, jpkm1 )
+        IF (tmask(ji,jj,jk) == 1.) THEN
+          zdep = hmld(ji,jj)
+          IF( gdept(ji,jj,jk,Kmm) > zdep ) THEN
+            alphat = 0.
+            remint = 0.
+            !
+            ! the scale factors are corrected with temperature
+            zsizek1  = e3t(ji,jj,jk-1,Kmm) / 2. / (wsbio3(ji,jj,jk-1) + rtrn) * tgfunc(ji,jj,jk-1)
+            zsizek = e3t(ji,jj,jk,Kmm) / 2. / (wsbio3(ji,jj,jk) + rtrn) * tgfunc(ji,jj,jk)
+            !
+            ! Special treatment of the level just below the MXL
+            ! See the comments in the GOC section
+            ! ---------------------------------------------------
+            !
+            IF ( gdept(ji,jj,jk-1,Kmm) <= zdep ) THEN
+              !
+              ! Computation of the POC concentration using the 
+              ! lagrangian algorithm
+              zpoc = tr(ji,jj,jk-1,jppoc,Kbb) + conspoc(ji,jj,jk) * rday / rfact2               &
+              &   * e3t(ji,jj,jk,Kmm) / 2. / (wsbio3(ji,jj,jk) + rtrn)
+              zpoc = max(0., zpoc)
+              ! 
+              DO jn = 1, jcpoc
+                 ! computation of the lability spectrum applying the 
+                 ! different sources and sinks
+                 alphap(ji,jj,jk,jn) = alphap(ji,jj,jk-1,jn) * exp( -reminp(jn) * zsizek ) * zpoc  &
+                 &   + ( prodpoc(ji,jj,jk) * alphan(jn) + zorem3(ji,jj,jk) * alphag(ji,jj,jk,jn) ) &
+                 &   / tgfunc(ji,jj,jk) / reminp(jn) * rday / rfact2 * ( 1. - exp( -reminp(jn)     &
+                 &   * zsizek ) )
+                 alphap(ji,jj,jk,jn) = MAX( 0., alphap(ji,jj,jk,jn) )
+                 alphat = alphat + alphap(ji,jj,jk,jn)
+              END DO
+            ELSE
+              !
+              ! Lability parameterization for the interior of the ocean
+              ! This is very similar to what is done in the previous 
+              ! block
+              ! --------------------------------------------------------
+              !
+              zpoc = tr(ji,jj,jk-1,jppoc,Kbb) + conspoc(ji,jj,jk-1) * rday / rfact2               &
+              &   * e3t(ji,jj,jk-1,Kmm) / 2. / (wsbio3(ji,jj,jk-1) + rtrn) + conspoc(ji,jj,jk)   &
+              &   * rday / rfact2 * e3t(ji,jj,jk,Kmm) / 2. / (wsbio3(ji,jj,jk) + rtrn)
+              zpoc = max(0., zpoc)
+              !
+              DO jn = 1, jcpoc
+                 alphap(ji,jj,jk,jn) = alphap(ji,jj,jk-1,jn) * exp( -reminp(jn)                       &
+                 &   * ( zsizek + zsizek1 ) ) * zpoc + ( prodpoc(ji,jj,jk-1) * alphan(jn)             & 
+                 &   + zorem3(ji,jj,jk-1) * alphag(ji,jj,jk-1,jn) ) * rday / rfact2 / reminp(jn)      &
+                 &   / tgfunc(ji,jj,jk-1) * ( 1. - exp( -reminp(jn) * zsizek1 ) ) * exp( -reminp(jn)  &
+                 &   * zsizek ) + ( prodpoc(ji,jj,jk) * alphan(jn) + zorem3(ji,jj,jk)                 &
+                 &   * alphag(ji,jj,jk,jn) ) * rday / rfact2 / reminp(jn) / tgfunc(ji,jj,jk) * ( 1.   &
+                 &   - exp( -reminp(jn) * zsizek ) )
+                 alphap(ji,jj,jk,jn) = max(0., alphap(ji,jj,jk,jn) )
+                 alphat = alphat + alphap(ji,jj,jk,jn)
+              END DO
+            ENDIF
+            ! Normalization of the lability spectrum so that the 
+            ! integral is equal to 1
+            DO jn = 1, jcpoc
+               alphap(ji,jj,jk,jn) = alphap(ji,jj,jk,jn) / ( alphat + rtrn)
+               remint = remint + alphap(ji,jj,jk,jn) * reminp(jn)
             END DO
-         END DO
-      END DO
+            ! Mean remineralization rate in the water column
+            ztremint(ji,jj,jk) =  MAX( 0., remint )
+          ENDIF
+        ENDIF
+     END_3D
 
      IF( ln_p4z ) THEN   ;   zremipoc(:,:,:) = MIN( xremip , ztremint(:,:,:) )
@@ -404,49 +384,41 @@
 
      IF( ln_p4z ) THEN
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  IF (tmask(ji,jj,jk) == 1.) THEN
-                    ! POC disaggregation by turbulence and bacterial activity. 
-                    ! --------------------------------------------------------
-                    zremip          = zremipoc(ji,jj,jk) * xstep * tgfunc(ji,jj,jk)
-                    zorem           = zremip * trb(ji,jj,jk,jppoc)
-                    zofer           = zremip * trb(ji,jj,jk,jpsfe)
-
-                    tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + zorem
-                    orem(ji,jj,jk)      = orem(ji,jj,jk) + zorem
-                    tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + zofer
-                    tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) - zorem
-                    tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) - zofer
-                    zfolimi(ji,jj,jk)   = zfolimi(ji,jj,jk) + zofer
-                  ENDIF
-               END DO
-            END DO
-         END DO
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+            IF (tmask(ji,jj,jk) == 1.) THEN
+              ! POC disaggregation by turbulence and bacterial activity. 
+              ! --------------------------------------------------------
+              zremip          = zremipoc(ji,jj,jk) * xstep * tgfunc(ji,jj,jk)
+              zorem           = zremip * tr(ji,jj,jk,jppoc,Kbb)
+              zofer           = zremip * tr(ji,jj,jk,jpsfe,Kbb)
+
+              tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) + zorem
+              orem(ji,jj,jk)      = orem(ji,jj,jk) + zorem
+              tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) + zofer
+              tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) - zorem
+              tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) - zofer
+              zfolimi(ji,jj,jk)   = zfolimi(ji,jj,jk) + zofer
+            ENDIF
+         END_3D
      ELSE
-       DO jk = 1, jpkm1
-          DO jj = 1, jpj
-             DO ji = 1, jpi
-                ! POC disaggregation by turbulence and bacterial activity. 
-                ! --------------------------------------------------------
-                zremip = zremipoc(ji,jj,jk) * xstep * tgfunc(ji,jj,jk)
-                zopoc  = zremip * trb(ji,jj,jk,jppoc)
-                orem(ji,jj,jk)  = orem(ji,jj,jk) + zopoc
-                zopon  = xremipn / xremipc * zremip * trb(ji,jj,jk,jppon)
-                zopop  = xremipp / xremipc * zremip * trb(ji,jj,jk,jppop)
-                zofer  = xremipn / xremipc * zremip * trb(ji,jj,jk,jpsfe)
-
-                tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) - zopoc
-                tra(ji,jj,jk,jppon) = tra(ji,jj,jk,jppon) - zopon
-                tra(ji,jj,jk,jppop) = tra(ji,jj,jk,jppop) - zopop
-                tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) - zofer
-                tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + zopoc
-                tra(ji,jj,jk,jpdon) = tra(ji,jj,jk,jpdon) + zopon 
-                tra(ji,jj,jk,jpdop) = tra(ji,jj,jk,jpdop) + zopop 
-                tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + zofer 
-                zfolimi(ji,jj,jk)   = zfolimi(ji,jj,jk) + zofer
-             END DO
-           END DO
-        END DO
+       DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+          ! POC disaggregation by turbulence and bacterial activity. 
+          ! --------------------------------------------------------
+          zremip = zremipoc(ji,jj,jk) * xstep * tgfunc(ji,jj,jk)
+          zopoc  = zremip * tr(ji,jj,jk,jppoc,Kbb)
+          orem(ji,jj,jk)  = orem(ji,jj,jk) + zopoc
+          zopon  = xremipn / xremipc * zremip * tr(ji,jj,jk,jppon,Kbb)
+          zopop  = xremipp / xremipc * zremip * tr(ji,jj,jk,jppop,Kbb)
+          zofer  = xremipn / xremipc * zremip * tr(ji,jj,jk,jpsfe,Kbb)
+
+          tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) - zopoc
+          tr(ji,jj,jk,jppon,Krhs) = tr(ji,jj,jk,jppon,Krhs) - zopon
+          tr(ji,jj,jk,jppop,Krhs) = tr(ji,jj,jk,jppop,Krhs) - zopop
+          tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) - zofer
+          tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) + zopoc
+          tr(ji,jj,jk,jpdon,Krhs) = tr(ji,jj,jk,jpdon,Krhs) + zopon 
+          tr(ji,jj,jk,jpdop,Krhs) = tr(ji,jj,jk,jpdop,Krhs) + zopop 
+          tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) + zofer 
+          zfolimi(ji,jj,jk)   = zfolimi(ji,jj,jk) + zofer
+       END_3D
      ENDIF
 
@@ -460,8 +432,8 @@
      ENDIF
 
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('poc2')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -497,10 +469,8 @@
       ENDIF
       !
-      REWIND( numnatp_ref )              ! Namelist nampisrem in reference namelist : Pisces remineralization
       READ  ( numnatp_ref, nampispoc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampispoc in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampisrem in configuration namelist : Pisces remineralization
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampispoc in reference namelist' )
       READ  ( numnatp_cfg, nampispoc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampispoc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampispoc in configuration namelist' )
       IF(lwm) WRITE( numonp, nampispoc )
 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zprod.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zprod.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zprod.F90	(revision 13463)
@@ -16,5 +16,5 @@
    USE sms_pisces      ! PISCES Source Minus Sink variables
    USE p4zlim          ! Co-limitations of differents nutrients
-   USE prtctl_trc      ! print control for debugging
+   USE prtctl          ! print control for debugging
    USE iom             ! I/O manager
 
@@ -46,4 +46,7 @@
    REAL(wp) ::   texcretd   ! 1 - excretd        
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -53,5 +56,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_prod( kt , knt )
+   SUBROUTINE p4z_prod( kt , knt, Kbb, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_prod  ***
@@ -63,4 +66,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt, knt   !
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Krhs  ! time level indices
       !
       INTEGER  ::   ji, jj, jk
@@ -89,9 +93,10 @@
       !  Allocate temporary workspace
       !
-      zprorcan(:,:,:) = 0._wp ; zprorcad(:,:,:) = 0._wp ; zprofed (:,:,:) = 0._wp
-      zprofen (:,:,:) = 0._wp ; zysopt  (:,:,:) = 0._wp
-      zpronewn(:,:,:) = 0._wp ; zpronewd(:,:,:) = 0._wp ; zprdia  (:,:,:) = 0._wp
-      zprbio  (:,:,:) = 0._wp ; zprdch  (:,:,:) = 0._wp ; zprnch  (:,:,:) = 0._wp 
-      zmxl_fac(:,:,:) = 0._wp ; zmxl_chl(:,:,:) = 0._wp 
+      zprorcan  (:,:,:) = 0._wp ; zprorcad  (:,:,:) = 0._wp ; zprofed (:,:,:) = 0._wp
+      zprofen   (:,:,:) = 0._wp ; zysopt    (:,:,:) = 0._wp
+      zpronewn  (:,:,:) = 0._wp ; zpronewd  (:,:,:) = 0._wp ; zprdia  (:,:,:) = 0._wp
+      zprbio    (:,:,:) = 0._wp ; zprdch    (:,:,:) = 0._wp ; zprnch  (:,:,:) = 0._wp 
+      zmxl_fac  (:,:,:) = 0._wp ; zmxl_chl  (:,:,:) = 0._wp 
+      zpligprod1(:,:,:) = 0._wp ; zpligprod2(:,:,:) = 0._wp 
 
       ! Computation of the optimal production
@@ -105,27 +110,21 @@
       ! day length in hours
       zstrn(:,:) = 0.
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zargu = TAN( zcodel ) * TAN( gphit(ji,jj) * rad )
-            zargu = MAX( -1., MIN(  1., zargu ) )
-            zstrn(ji,jj) = MAX( 0.0, 24. - 2. * ACOS( zargu ) / rad / 15. )
-         END DO
-      END DO
+      DO_2D( 1, 1, 1, 1 )
+         zargu = TAN( zcodel ) * TAN( gphit(ji,jj) * rad )
+         zargu = MAX( -1., MIN(  1., zargu ) )
+         zstrn(ji,jj) = MAX( 0.0, 24. - 2. * ACOS( zargu ) / rad / 15. )
+      END_2D
 
       ! Impact of the day duration and light intermittency on phytoplankton growth
-      DO jk = 1, jpkm1
-         DO jj = 1 ,jpj
-            DO ji = 1, jpi
-               IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                  zval = MAX( 1., zstrn(ji,jj) )
-                  IF( gdept_n(ji,jj,jk) <= hmld(ji,jj) ) THEN
-                     zval = zval * MIN(1., heup_01(ji,jj) / ( hmld(ji,jj) + rtrn ))
-                  ENDIF
-                  zmxl_chl(ji,jj,jk) = zval / 24.
-                  zmxl_fac(ji,jj,jk) = 1.5 * zval / ( 12. + zval )
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+            zval = MAX( 1., zstrn(ji,jj) )
+            IF( gdept(ji,jj,jk,Kmm) <= hmld(ji,jj) ) THEN
+               zval = zval * MIN(1., heup_01(ji,jj) / ( hmld(ji,jj) + rtrn ))
+            ENDIF
+            zmxl_chl(ji,jj,jk) = zval / 24.
+            zmxl_fac(ji,jj,jk) = 1.5 * zval / ( 12. + zval )
+         ENDIF
+      END_3D
 
       zprbio(:,:,:) = zprmaxn(:,:,:) * zmxl_fac(:,:,:)
@@ -136,202 +135,166 @@
 
       ! Computation of the P-I slope for nanos and diatoms
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                  ztn         = MAX( 0., tsn(ji,jj,jk,jp_tem) - 15. )
-                  zadap       = xadap * ztn / ( 2.+ ztn )
-                  zconctemp   = MAX( 0.e0 , trb(ji,jj,jk,jpdia) - xsizedia )
-                  zconctemp2  = trb(ji,jj,jk,jpdia) - zconctemp
-                  !
-                  zpislopeadn(ji,jj,jk) = pislopen * ( 1.+ zadap  * EXP( -0.25 * enano(ji,jj,jk) ) )  &
-                  &                   * trb(ji,jj,jk,jpnch) /( trb(ji,jj,jk,jpphy) * 12. + rtrn)
-                  !
-                  zpislopeadd(ji,jj,jk) = (pislopen * zconctemp2 + pisloped * zconctemp) / ( trb(ji,jj,jk,jpdia) + rtrn )   &
-                  &                   * trb(ji,jj,jk,jpdch) /( trb(ji,jj,jk,jpdia) * 12. + rtrn)
-               ENDIF
-            END DO
-         END DO
-      END DO
-
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                   ! Computation of production function for Carbon
-                   !  ---------------------------------------------
-                   zpislopen = zpislopeadn(ji,jj,jk) / ( ( r1_rday + bresp * r1_rday ) &
-                   &            * zmxl_fac(ji,jj,jk) * rday + rtrn)
-                   zpisloped = zpislopeadd(ji,jj,jk) / ( ( r1_rday + bresp * r1_rday ) &
-                   &            * zmxl_fac(ji,jj,jk) * rday + rtrn)
-                   zprbio(ji,jj,jk) = zprbio(ji,jj,jk) * ( 1.- EXP( -zpislopen * enano(ji,jj,jk) )  )
-                   zprdia(ji,jj,jk) = zprdia(ji,jj,jk) * ( 1.- EXP( -zpisloped * ediat(ji,jj,jk) )  )
-                   !  Computation of production function for Chlorophyll
-                   !--------------------------------------------------
-                   zpislopen = zpislopeadn(ji,jj,jk) / ( zprmaxn(ji,jj,jk) * zmxl_chl(ji,jj,jk) * rday + rtrn )
-                   zpisloped = zpislopeadd(ji,jj,jk) / ( zprmaxd(ji,jj,jk) * zmxl_chl(ji,jj,jk) * rday + rtrn )
-                   zprnch(ji,jj,jk) = zprmaxn(ji,jj,jk) * ( 1.- EXP( -zpislopen * enanom(ji,jj,jk) ) )
-                   zprdch(ji,jj,jk) = zprmaxd(ji,jj,jk) * ( 1.- EXP( -zpisloped * ediatm(ji,jj,jk) ) )
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+            ztn         = MAX( 0., ts(ji,jj,jk,jp_tem,Kmm) - 15. )
+            zadap       = xadap * ztn / ( 2.+ ztn )
+            zconctemp   = MAX( 0.e0 , tr(ji,jj,jk,jpdia,Kbb) - xsizedia )
+            zconctemp2  = tr(ji,jj,jk,jpdia,Kbb) - zconctemp
+            !
+            zpislopeadn(ji,jj,jk) = pislopen * ( 1.+ zadap  * EXP( -0.25 * enano(ji,jj,jk) ) )  &
+            &                   * tr(ji,jj,jk,jpnch,Kbb) /( tr(ji,jj,jk,jpphy,Kbb) * 12. + rtrn)
+            !
+            zpislopeadd(ji,jj,jk) = (pislopen * zconctemp2 + pisloped * zconctemp) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )   &
+            &                   * tr(ji,jj,jk,jpdch,Kbb) /( tr(ji,jj,jk,jpdia,Kbb) * 12. + rtrn)
+         ENDIF
+      END_3D
+
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+             ! Computation of production function for Carbon
+             !  ---------------------------------------------
+             zpislopen = zpislopeadn(ji,jj,jk) / ( ( r1_rday + bresp * r1_rday ) &
+             &            * zmxl_fac(ji,jj,jk) * rday + rtrn)
+             zpisloped = zpislopeadd(ji,jj,jk) / ( ( r1_rday + bresp * r1_rday ) &
+             &            * zmxl_fac(ji,jj,jk) * rday + rtrn)
+             zprbio(ji,jj,jk) = zprbio(ji,jj,jk) * ( 1.- EXP( -zpislopen * enano(ji,jj,jk) )  )
+             zprdia(ji,jj,jk) = zprdia(ji,jj,jk) * ( 1.- EXP( -zpisloped * ediat(ji,jj,jk) )  )
+             !  Computation of production function for Chlorophyll
+             !--------------------------------------------------
+             zpislopen = zpislopeadn(ji,jj,jk) / ( zprmaxn(ji,jj,jk) * zmxl_chl(ji,jj,jk) * rday + rtrn )
+             zpisloped = zpislopeadd(ji,jj,jk) / ( zprmaxd(ji,jj,jk) * zmxl_chl(ji,jj,jk) * rday + rtrn )
+             zprnch(ji,jj,jk) = zprmaxn(ji,jj,jk) * ( 1.- EXP( -zpislopen * enanom(ji,jj,jk) ) )
+             zprdch(ji,jj,jk) = zprmaxd(ji,jj,jk) * ( 1.- EXP( -zpisloped * ediatm(ji,jj,jk) ) )
+         ENDIF
+      END_3D
 
       !  Computation of a proxy of the N/C ratio
       !  ---------------------------------------
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-                zval = MIN( xnanopo4(ji,jj,jk), ( xnanonh4(ji,jj,jk) + xnanono3(ji,jj,jk) ) )   &
-                &      * zprmaxn(ji,jj,jk) / ( zprbio(ji,jj,jk) + rtrn )
-                quotan(ji,jj,jk) = MIN( 1., 0.2 + 0.8 * zval )
-                zval = MIN( xdiatpo4(ji,jj,jk), ( xdiatnh4(ji,jj,jk) + xdiatno3(ji,jj,jk) ) )   &
-                &      * zprmaxd(ji,jj,jk) / ( zprdia(ji,jj,jk) + rtrn )
-                quotad(ji,jj,jk) = MIN( 1., 0.2 + 0.8 * zval )
-            END DO
-         END DO
-      END DO
-
-
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-
-                IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                   !    Si/C of diatoms
-                   !    ------------------------
-                   !    Si/C increases with iron stress and silicate availability
-                   !    Si/C is arbitrariliy increased for very high Si concentrations
-                   !    to mimic the very high ratios observed in the Southern Ocean (silpot2)
-                  zlim  = trb(ji,jj,jk,jpsil) / ( trb(ji,jj,jk,jpsil) + xksi1 )
-                  zsilim = MIN( zprdia(ji,jj,jk) / ( zprmaxd(ji,jj,jk) + rtrn ), xlimsi(ji,jj,jk) )
-                  zsilfac = 4.4 * EXP( -4.23 * zsilim ) * MAX( 0.e0, MIN( 1., 2.2 * ( zlim - 0.5 ) )  ) + 1.e0
-                  zsiborn = trb(ji,jj,jk,jpsil) * trb(ji,jj,jk,jpsil) * trb(ji,jj,jk,jpsil)
-                  IF (gphit(ji,jj) < -30 ) THEN
-                    zsilfac2 = 1. + 2. * zsiborn / ( zsiborn + xksi2**3 )
-                  ELSE
-                    zsilfac2 = 1. +      zsiborn / ( zsiborn + xksi2**3 )
-                  ENDIF
-                  zysopt(ji,jj,jk) = grosip * zlim * zsilfac * zsilfac2
-              ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+          zval = MIN( xnanopo4(ji,jj,jk), ( xnanonh4(ji,jj,jk) + xnanono3(ji,jj,jk) ) )   &
+          &      * zprmaxn(ji,jj,jk) / ( zprbio(ji,jj,jk) + rtrn )
+          quotan(ji,jj,jk) = MIN( 1., 0.2 + 0.8 * zval )
+          zval = MIN( xdiatpo4(ji,jj,jk), ( xdiatnh4(ji,jj,jk) + xdiatno3(ji,jj,jk) ) )   &
+          &      * zprmaxd(ji,jj,jk) / ( zprdia(ji,jj,jk) + rtrn )
+          quotad(ji,jj,jk) = MIN( 1., 0.2 + 0.8 * zval )
+      END_3D
+
+
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+
+          IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+             !    Si/C of diatoms
+             !    ------------------------
+             !    Si/C increases with iron stress and silicate availability
+             !    Si/C is arbitrariliy increased for very high Si concentrations
+             !    to mimic the very high ratios observed in the Southern Ocean (silpot2)
+            zlim  = tr(ji,jj,jk,jpsil,Kbb) / ( tr(ji,jj,jk,jpsil,Kbb) + xksi1 )
+            zsilim = MIN( zprdia(ji,jj,jk) / ( zprmaxd(ji,jj,jk) + rtrn ), xlimsi(ji,jj,jk) )
+            zsilfac = 4.4 * EXP( -4.23 * zsilim ) * MAX( 0.e0, MIN( 1., 2.2 * ( zlim - 0.5 ) )  ) + 1.e0
+            zsiborn = tr(ji,jj,jk,jpsil,Kbb) * tr(ji,jj,jk,jpsil,Kbb) * tr(ji,jj,jk,jpsil,Kbb)
+            IF (gphit(ji,jj) < -30 ) THEN
+              zsilfac2 = 1. + 2. * zsiborn / ( zsiborn + xksi2**3 )
+            ELSE
+              zsilfac2 = 1. +      zsiborn / ( zsiborn + xksi2**3 )
+            ENDIF
+            zysopt(ji,jj,jk) = grosip * zlim * zsilfac * zsilfac2
+        ENDIF
+      END_3D
 
       !  Mixed-layer effect on production 
       !  Sea-ice effect on production
 
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zprbio(ji,jj,jk) = zprbio(ji,jj,jk) * ( 1. - fr_i(ji,jj) )
-               zprdia(ji,jj,jk) = zprdia(ji,jj,jk) * ( 1. - fr_i(ji,jj) )
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zprbio(ji,jj,jk) = zprbio(ji,jj,jk) * ( 1. - fr_i(ji,jj) )
+         zprdia(ji,jj,jk) = zprdia(ji,jj,jk) * ( 1. - fr_i(ji,jj) )
+      END_3D
 
       ! Computation of the various production terms 
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                  !  production terms for nanophyto. (C)
-                  zprorcan(ji,jj,jk) = zprbio(ji,jj,jk)  * xlimphy(ji,jj,jk) * trb(ji,jj,jk,jpphy) * rfact2
-                  zpronewn(ji,jj,jk)  = zprorcan(ji,jj,jk)* xnanono3(ji,jj,jk) / ( xnanono3(ji,jj,jk) + xnanonh4(ji,jj,jk) + rtrn )
-                  !
-                  zratio = trb(ji,jj,jk,jpnfe) / ( trb(ji,jj,jk,jpphy) * fecnm + rtrn )
-                  zmax   = MAX( 0., ( 1. - zratio ) / ABS( 1.05 - zratio ) ) 
-                  zprofen(ji,jj,jk) = fecnm * zprmaxn(ji,jj,jk) * ( 1.0 - fr_i(ji,jj) )  &
-                  &             * ( 4. - 4.5 * xlimnfe(ji,jj,jk) / ( xlimnfe(ji,jj,jk) + 0.5 ) )    &
-                  &             * biron(ji,jj,jk) / ( biron(ji,jj,jk) + concnfe(ji,jj,jk) )  &
-                  &             * zmax * trb(ji,jj,jk,jpphy) * rfact2
-                  !  production terms for diatoms (C)
-                  zprorcad(ji,jj,jk) = zprdia(ji,jj,jk) * xlimdia(ji,jj,jk) * trb(ji,jj,jk,jpdia) * rfact2
-                  zpronewd(ji,jj,jk) = zprorcad(ji,jj,jk) * xdiatno3(ji,jj,jk) / ( xdiatno3(ji,jj,jk) + xdiatnh4(ji,jj,jk) + rtrn )
-                  !
-                  zratio = trb(ji,jj,jk,jpdfe) / ( trb(ji,jj,jk,jpdia) * fecdm + rtrn )
-                  zmax   = MAX( 0., ( 1. - zratio ) / ABS( 1.05 - zratio ) ) 
-                  zprofed(ji,jj,jk) = fecdm * zprmaxd(ji,jj,jk) * ( 1.0 - fr_i(ji,jj) )  &
-                  &             * ( 4. - 4.5 * xlimdfe(ji,jj,jk) / ( xlimdfe(ji,jj,jk) + 0.5 ) )    &
-                  &             * biron(ji,jj,jk) / ( biron(ji,jj,jk) + concdfe(ji,jj,jk) )  &
-                  &             * zmax * trb(ji,jj,jk,jpdia) * rfact2
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+            !  production terms for nanophyto. (C)
+            zprorcan(ji,jj,jk) = zprbio(ji,jj,jk)  * xlimphy(ji,jj,jk) * tr(ji,jj,jk,jpphy,Kbb) * rfact2
+            zpronewn(ji,jj,jk)  = zprorcan(ji,jj,jk)* xnanono3(ji,jj,jk) / ( xnanono3(ji,jj,jk) + xnanonh4(ji,jj,jk) + rtrn )
+            !
+            zratio = tr(ji,jj,jk,jpnfe,Kbb) / ( tr(ji,jj,jk,jpphy,Kbb) * fecnm + rtrn )
+            zmax   = MAX( 0., ( 1. - zratio ) / ABS( 1.05 - zratio ) ) 
+            zprofen(ji,jj,jk) = fecnm * zprmaxn(ji,jj,jk) * ( 1.0 - fr_i(ji,jj) )  &
+            &             * ( 4. - 4.5 * xlimnfe(ji,jj,jk) / ( xlimnfe(ji,jj,jk) + 0.5 ) )    &
+            &             * biron(ji,jj,jk) / ( biron(ji,jj,jk) + concnfe(ji,jj,jk) )  &
+            &             * zmax * tr(ji,jj,jk,jpphy,Kbb) * rfact2
+            !  production terms for diatoms (C)
+            zprorcad(ji,jj,jk) = zprdia(ji,jj,jk) * xlimdia(ji,jj,jk) * tr(ji,jj,jk,jpdia,Kbb) * rfact2
+            zpronewd(ji,jj,jk) = zprorcad(ji,jj,jk) * xdiatno3(ji,jj,jk) / ( xdiatno3(ji,jj,jk) + xdiatnh4(ji,jj,jk) + rtrn )
+            !
+            zratio = tr(ji,jj,jk,jpdfe,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) * fecdm + rtrn )
+            zmax   = MAX( 0., ( 1. - zratio ) / ABS( 1.05 - zratio ) ) 
+            zprofed(ji,jj,jk) = fecdm * zprmaxd(ji,jj,jk) * ( 1.0 - fr_i(ji,jj) )  &
+            &             * ( 4. - 4.5 * xlimdfe(ji,jj,jk) / ( xlimdfe(ji,jj,jk) + 0.5 ) )    &
+            &             * biron(ji,jj,jk) / ( biron(ji,jj,jk) + concdfe(ji,jj,jk) )  &
+            &             * zmax * tr(ji,jj,jk,jpdia,Kbb) * rfact2
+         ENDIF
+      END_3D
 
       ! Computation of the chlorophyll production terms
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                  !  production terms for nanophyto. ( chlorophyll )
-                  znanotot = enanom(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
-                  zprod    = rday * zprorcan(ji,jj,jk) * zprnch(ji,jj,jk) * xlimphy(ji,jj,jk)
-                  zprochln = chlcmin * 12. * zprorcan (ji,jj,jk)
-                  chlcnm_n   = MIN ( chlcnm, ( chlcnm / (1. - 1.14 / 43.4 *tsn(ji,jj,jk,jp_tem))) * (1. - 1.14 / 43.4 * 20.))
-                  zprochln = zprochln + (chlcnm_n-chlcmin) * 12. * zprod / &
-                                        & (  zpislopeadn(ji,jj,jk) * znanotot +rtrn)
-                  !  production terms for diatoms ( chlorophyll )
-                  zdiattot = ediatm(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
-                  zprod    = rday * zprorcad(ji,jj,jk) * zprdch(ji,jj,jk) * xlimdia(ji,jj,jk)
-                  zprochld = chlcmin * 12. * zprorcad(ji,jj,jk)
-                  chlcdm_n   = MIN ( chlcdm, ( chlcdm / (1. - 1.14 / 43.4 * tsn(ji,jj,jk,jp_tem))) * (1. - 1.14 / 43.4 * 20.))
-                  zprochld = zprochld + (chlcdm_n-chlcmin) * 12. * zprod / &
-                                        & ( zpislopeadd(ji,jj,jk) * zdiattot +rtrn )
-                  !   Update the arrays TRA which contain the Chla sources and sinks
-                  tra(ji,jj,jk,jpnch) = tra(ji,jj,jk,jpnch) + zprochln * texcretn
-                  tra(ji,jj,jk,jpdch) = tra(ji,jj,jk,jpdch) + zprochld * texcretd
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+            !  production terms for nanophyto. ( chlorophyll )
+            znanotot = enanom(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
+            zprod    = rday * zprorcan(ji,jj,jk) * zprnch(ji,jj,jk) * xlimphy(ji,jj,jk)
+            zprochln = chlcmin * 12. * zprorcan (ji,jj,jk)
+            chlcnm_n   = MIN ( chlcnm, ( chlcnm / (1. - 1.14 / 43.4 *ts(ji,jj,jk,jp_tem,Kmm))) * (1. - 1.14 / 43.4 * 20.))
+            zprochln = zprochln + (chlcnm_n-chlcmin) * 12. * zprod / &
+                                  & (  zpislopeadn(ji,jj,jk) * znanotot +rtrn)
+            !  production terms for diatoms ( chlorophyll )
+            zdiattot = ediatm(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
+            zprod    = rday * zprorcad(ji,jj,jk) * zprdch(ji,jj,jk) * xlimdia(ji,jj,jk)
+            zprochld = chlcmin * 12. * zprorcad(ji,jj,jk)
+            chlcdm_n   = MIN ( chlcdm, ( chlcdm / (1. - 1.14 / 43.4 * ts(ji,jj,jk,jp_tem,Kmm))) * (1. - 1.14 / 43.4 * 20.))
+            zprochld = zprochld + (chlcdm_n-chlcmin) * 12. * zprod / &
+                                  & ( zpislopeadd(ji,jj,jk) * zdiattot +rtrn )
+            !   Update the arrays TRA which contain the Chla sources and sinks
+            tr(ji,jj,jk,jpnch,Krhs) = tr(ji,jj,jk,jpnch,Krhs) + zprochln * texcretn
+            tr(ji,jj,jk,jpdch,Krhs) = tr(ji,jj,jk,jpdch,Krhs) + zprochld * texcretd
+         ENDIF
+      END_3D
 
       !   Update the arrays TRA which contain the biological sources and sinks
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-           DO ji =1 ,jpi
-              IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                 zproreg  = zprorcan(ji,jj,jk) - zpronewn(ji,jj,jk)
-                 zproreg2 = zprorcad(ji,jj,jk) - zpronewd(ji,jj,jk)
-                 zdocprod = excretd * zprorcad(ji,jj,jk) + excretn * zprorcan(ji,jj,jk)
-                 tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) - zprorcan(ji,jj,jk) - zprorcad(ji,jj,jk)
-                 tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) - zpronewn(ji,jj,jk) - zpronewd(ji,jj,jk)
-                 tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) - zproreg - zproreg2
-                 tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) + zprorcan(ji,jj,jk) * texcretn
-                 tra(ji,jj,jk,jpnfe) = tra(ji,jj,jk,jpnfe) + zprofen(ji,jj,jk) * texcretn
-                 tra(ji,jj,jk,jpdia) = tra(ji,jj,jk,jpdia) + zprorcad(ji,jj,jk) * texcretd
-                 tra(ji,jj,jk,jpdfe) = tra(ji,jj,jk,jpdfe) + zprofed(ji,jj,jk) * texcretd
-                 tra(ji,jj,jk,jpdsi) = tra(ji,jj,jk,jpdsi) + zprorcad(ji,jj,jk) * zysopt(ji,jj,jk) * texcretd
-                 tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + zdocprod
-                 tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) + o2ut * ( zproreg + zproreg2) &
-                 &                   + ( o2ut + o2nit ) * ( zpronewn(ji,jj,jk) + zpronewd(ji,jj,jk) )
-                 !
-                 zfeup = texcretn * zprofen(ji,jj,jk) + texcretd * zprofed(ji,jj,jk)
-                 tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) - zfeup
-                 tra(ji,jj,jk,jpsil) = tra(ji,jj,jk,jpsil) - texcretd * zprorcad(ji,jj,jk) * zysopt(ji,jj,jk)
-                 tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) - zprorcan(ji,jj,jk) - zprorcad(ji,jj,jk)
-                 tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) + rno3 * ( zpronewn(ji,jj,jk) + zpronewd(ji,jj,jk) ) &
-                 &                                         - rno3 * ( zproreg + zproreg2 )
-              ENDIF
-           END DO
-        END DO
-     END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+        IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+           zproreg  = zprorcan(ji,jj,jk) - zpronewn(ji,jj,jk)
+           zproreg2 = zprorcad(ji,jj,jk) - zpronewd(ji,jj,jk)
+           zdocprod = excretd * zprorcad(ji,jj,jk) + excretn * zprorcan(ji,jj,jk)
+           tr(ji,jj,jk,jppo4,Krhs) = tr(ji,jj,jk,jppo4,Krhs) - zprorcan(ji,jj,jk) - zprorcad(ji,jj,jk)
+           tr(ji,jj,jk,jpno3,Krhs) = tr(ji,jj,jk,jpno3,Krhs) - zpronewn(ji,jj,jk) - zpronewd(ji,jj,jk)
+           tr(ji,jj,jk,jpnh4,Krhs) = tr(ji,jj,jk,jpnh4,Krhs) - zproreg - zproreg2
+           tr(ji,jj,jk,jpphy,Krhs) = tr(ji,jj,jk,jpphy,Krhs) + zprorcan(ji,jj,jk) * texcretn
+           tr(ji,jj,jk,jpnfe,Krhs) = tr(ji,jj,jk,jpnfe,Krhs) + zprofen(ji,jj,jk) * texcretn
+           tr(ji,jj,jk,jpdia,Krhs) = tr(ji,jj,jk,jpdia,Krhs) + zprorcad(ji,jj,jk) * texcretd
+           tr(ji,jj,jk,jpdfe,Krhs) = tr(ji,jj,jk,jpdfe,Krhs) + zprofed(ji,jj,jk) * texcretd
+           tr(ji,jj,jk,jpdsi,Krhs) = tr(ji,jj,jk,jpdsi,Krhs) + zprorcad(ji,jj,jk) * zysopt(ji,jj,jk) * texcretd
+           tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) + zdocprod
+           tr(ji,jj,jk,jpoxy,Krhs) = tr(ji,jj,jk,jpoxy,Krhs) + o2ut * ( zproreg + zproreg2) &
+           &                   + ( o2ut + o2nit ) * ( zpronewn(ji,jj,jk) + zpronewd(ji,jj,jk) )
+           !
+           zfeup = texcretn * zprofen(ji,jj,jk) + texcretd * zprofed(ji,jj,jk)
+           tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) - zfeup
+           tr(ji,jj,jk,jpsil,Krhs) = tr(ji,jj,jk,jpsil,Krhs) - texcretd * zprorcad(ji,jj,jk) * zysopt(ji,jj,jk)
+           tr(ji,jj,jk,jpdic,Krhs) = tr(ji,jj,jk,jpdic,Krhs) - zprorcan(ji,jj,jk) - zprorcad(ji,jj,jk)
+           tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) + rno3 * ( zpronewn(ji,jj,jk) + zpronewd(ji,jj,jk) ) &
+           &                                         - rno3 * ( zproreg + zproreg2 )
+        ENDIF
+      END_3D
      !
      IF( ln_ligand ) THEN
          zpligprod1(:,:,:) = 0._wp    ;    zpligprod2(:,:,:) = 0._wp
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-              DO ji =1 ,jpi
-                 IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                    zdocprod = excretd * zprorcad(ji,jj,jk) + excretn * zprorcan(ji,jj,jk)
-                    zfeup    = texcretn * zprofen(ji,jj,jk) + texcretd * zprofed(ji,jj,jk)
-                    tra(ji,jj,jk,jplgw) = tra(ji,jj,jk,jplgw) + zdocprod * ldocp - zfeup * plig(ji,jj,jk) * lthet
-                    zpligprod1(ji,jj,jk) = zdocprod * ldocp
-                    zpligprod2(ji,jj,jk) = zfeup * plig(ji,jj,jk) * lthet
-                 ENDIF
-              END DO
-           END DO
-        END DO
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+           IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+              zdocprod = excretd * zprorcad(ji,jj,jk) + excretn * zprorcan(ji,jj,jk)
+              zfeup    = texcretn * zprofen(ji,jj,jk) + texcretd * zprofed(ji,jj,jk)
+              tr(ji,jj,jk,jplgw,Krhs) = tr(ji,jj,jk,jplgw,Krhs) + zdocprod * ldocp - zfeup * plig(ji,jj,jk) * lthet
+              zpligprod1(ji,jj,jk) = zdocprod * ldocp
+              zpligprod2(ji,jj,jk) = zfeup * plig(ji,jj,jk) * lthet
+           ENDIF
+         END_3D
      ENDIF
 
@@ -341,123 +304,33 @@
          & tpp = glob_sum( 'p4zprod', ( zprorcan(:,:,:) + zprorcad(:,:,:) ) * cvol(:,:,:) )
 
-    IF( lk_iomput ) THEN
-       IF( knt == nrdttrc ) THEN
-          ALLOCATE( zw2d(jpi,jpj), zw3d(jpi,jpj,jpk) )
-          zfact = 1.e+3 * rfact2r  !  conversion from mol/l/kt to  mol/m3/s
-          !
-          IF( iom_use( "PPPHYN" ) .OR. iom_use( "PPPHYD" ) )  THEN
-              zw3d(:,:,:) = zprorcan(:,:,:) * zfact * tmask(:,:,:)  ! primary production by nanophyto
-              CALL iom_put( "PPPHYN"  , zw3d )
-              !
-              zw3d(:,:,:) = zprorcad(:,:,:) * zfact * tmask(:,:,:)  ! primary production by diatomes
-              CALL iom_put( "PPPHYD"  , zw3d )
-          ENDIF
-          IF( iom_use( "PPNEWN" ) .OR. iom_use( "PPNEWD" ) )  THEN
-              zw3d(:,:,:) = zpronewn(:,:,:) * zfact * tmask(:,:,:)  ! new primary production by nanophyto
-              CALL iom_put( "PPNEWN"  , zw3d )
-              !
-              zw3d(:,:,:) = zpronewd(:,:,:) * zfact * tmask(:,:,:)  ! new primary production by diatomes
-              CALL iom_put( "PPNEWD"  , zw3d )
-          ENDIF
-          IF( iom_use( "PBSi" ) )  THEN
-              zw3d(:,:,:) = zprorcad(:,:,:) * zfact * tmask(:,:,:) * zysopt(:,:,:) ! biogenic silica production
-              CALL iom_put( "PBSi"  , zw3d )
-          ENDIF
-          IF( iom_use( "PFeN" ) .OR. iom_use( "PFeD" ) )  THEN
-              zw3d(:,:,:) = zprofen(:,:,:) * zfact * tmask(:,:,:)  ! biogenic iron production by nanophyto
-              CALL iom_put( "PFeN"  , zw3d )
-              !
-              zw3d(:,:,:) = zprofed(:,:,:) * zfact * tmask(:,:,:)  ! biogenic iron production by  diatomes
-              CALL iom_put( "PFeD"  , zw3d )
-          ENDIF
-          IF( iom_use( "LPRODP" ) )  THEN
-              zw3d(:,:,:) = zpligprod1(:,:,:) * 1e9 * zfact * tmask(:,:,:)
-              CALL iom_put( "LPRODP"  , zw3d )
-          ENDIF
-          IF( iom_use( "LDETP" ) )  THEN
-              zw3d(:,:,:) = zpligprod2(:,:,:) * 1e9 * zfact * tmask(:,:,:)
-              CALL iom_put( "LDETP"  , zw3d )
-          ENDIF
-          IF( iom_use( "Mumax" ) )  THEN
-              zw3d(:,:,:) = zprmaxn(:,:,:) * tmask(:,:,:)   ! Maximum growth rate
-              CALL iom_put( "Mumax"  , zw3d )
-          ENDIF
-          IF( iom_use( "MuN" ) .OR. iom_use( "MuD" ) )  THEN
-              zw3d(:,:,:) = zprbio(:,:,:) * xlimphy(:,:,:) * tmask(:,:,:)  ! Realized growth rate for nanophyto
-              CALL iom_put( "MuN"  , zw3d )
-              !
-              zw3d(:,:,:) =  zprdia(:,:,:) * xlimdia(:,:,:) * tmask(:,:,:)  ! Realized growth rate for diatoms
-              CALL iom_put( "MuD"  , zw3d )
-          ENDIF
-          IF( iom_use( "LNlight" ) .OR. iom_use( "LDlight" ) )  THEN
-              zw3d(:,:,:) = zprbio (:,:,:) / (zprmaxn(:,:,:) + rtrn) * tmask(:,:,:) ! light limitation term
-              CALL iom_put( "LNlight"  , zw3d )
-              !
-              zw3d(:,:,:) = zprdia (:,:,:) / (zprmaxd(:,:,:) + rtrn) * tmask(:,:,:)  ! light limitation term
-              CALL iom_put( "LDlight"  , zw3d )
-          ENDIF
-          IF( iom_use( "TPP" ) )  THEN
-              zw3d(:,:,:) = ( zprorcan(:,:,:) + zprorcad(:,:,:) ) * zfact * tmask(:,:,:)  ! total primary production
-              CALL iom_put( "TPP"  , zw3d )
-          ENDIF
-          IF( iom_use( "TPNEW" ) )  THEN
-              zw3d(:,:,:) = ( zpronewn(:,:,:) + zpronewd(:,:,:) ) * zfact * tmask(:,:,:)  ! total new production
-              CALL iom_put( "TPNEW"  , zw3d )
-          ENDIF
-          IF( iom_use( "TPBFE" ) )  THEN
-              zw3d(:,:,:) = ( zprofen(:,:,:) + zprofed(:,:,:) ) * zfact * tmask(:,:,:)  ! total biogenic iron production
-              CALL iom_put( "TPBFE"  , zw3d )
-          ENDIF
-          IF( iom_use( "INTPPPHYN" ) .OR. iom_use( "INTPPPHYD" ) ) THEN  
-             zw2d(:,:) = 0.
-             DO jk = 1, jpkm1
-               zw2d(:,:) = zw2d(:,:) + zprorcan(:,:,jk) * e3t_n(:,:,jk) * zfact * tmask(:,:,jk)  ! vert. integrated  primary produc. by nano
-             ENDDO
-             CALL iom_put( "INTPPPHYN" , zw2d )
-             !
-             zw2d(:,:) = 0.
-             DO jk = 1, jpkm1
-                zw2d(:,:) = zw2d(:,:) + zprorcad(:,:,jk) * e3t_n(:,:,jk) * zfact * tmask(:,:,jk) ! vert. integrated  primary produc. by diatom
-             ENDDO
-             CALL iom_put( "INTPPPHYD" , zw2d )
-          ENDIF
-          IF( iom_use( "INTPP" ) ) THEN   
-             zw2d(:,:) = 0.
-             DO jk = 1, jpkm1
-                zw2d(:,:) = zw2d(:,:) + ( zprorcan(:,:,jk) + zprorcad(:,:,jk) ) * e3t_n(:,:,jk) * zfact * tmask(:,:,jk) ! vert. integrated pp
-             ENDDO
-             CALL iom_put( "INTPP" , zw2d )
-          ENDIF
-          IF( iom_use( "INTPNEW" ) ) THEN    
-             zw2d(:,:) = 0.
-             DO jk = 1, jpkm1
-                zw2d(:,:) = zw2d(:,:) + ( zpronewn(:,:,jk) + zpronewd(:,:,jk) ) * e3t_n(:,:,jk) * zfact * tmask(:,:,jk)  ! vert. integrated new prod
-             ENDDO
-             CALL iom_put( "INTPNEW" , zw2d )
-          ENDIF
-          IF( iom_use( "INTPBFE" ) ) THEN           !   total biogenic iron production  ( vertically integrated )
-             zw2d(:,:) = 0.
-             DO jk = 1, jpkm1
-                zw2d(:,:) = zw2d(:,:) + ( zprofen(:,:,jk) + zprofed(:,:,jk) ) * e3t_n(:,:,jk) * zfact * tmask(:,:,jk) ! vert integr. bfe prod
-             ENDDO
-            CALL iom_put( "INTPBFE" , zw2d )
-          ENDIF
-          IF( iom_use( "INTPBSI" ) ) THEN           !   total biogenic silica production  ( vertically integrated )
-             zw2d(:,:) = 0.
-             DO jk = 1, jpkm1
-                zw2d(:,:) = zw2d(:,:) + zprorcad(:,:,jk) * zysopt(:,:,jk) * e3t_n(:,:,jk) * zfact * tmask(:,:,jk)  ! vert integr. bsi prod
-             ENDDO
-             CALL iom_put( "INTPBSI" , zw2d )
-          ENDIF
-          IF( iom_use( "tintpp" ) )  CALL iom_put( "tintpp" , tpp * zfact )  !  global total integrated primary production molC/s
-          !
-          DEALLOCATE( zw2d, zw3d )
+    IF( lk_iomput .AND.  knt == nrdttrc ) THEN
+       zfact = 1.e+3 * rfact2r  !  conversion from mol/l/kt to  mol/m3/s
+       !
+       CALL iom_put( "PPPHYN"  , zprorcan(:,:,:) * zfact * tmask(:,:,:) )  ! primary production by nanophyto
+       CALL iom_put( "PPPHYD"  , zprorcad(:,:,:) * zfact * tmask(:,:,:)   ) ! primary production by diatomes
+       CALL iom_put( "PPNEWN"  , zpronewn(:,:,:) * zfact * tmask(:,:,:)    ) ! new primary production by nanophyto
+       CALL iom_put( "PPNEWD"  , zpronewd(:,:,:) * zfact * tmask(:,:,:)   ) ! new primary production by diatomes
+       CALL iom_put( "PBSi"    , zprorcad(:,:,:) * zfact * tmask(:,:,:) * zysopt(:,:,:)  ) ! biogenic silica production
+       CALL iom_put( "PFeN"    , zprofen(:,:,:) * zfact * tmask(:,:,:)  ) ! biogenic iron production by nanophyto
+       CALL iom_put( "PFeD"    , zprofed(:,:,:) * zfact * tmask(:,:,:)  ) ! biogenic iron production by  diatomes
+       IF( ln_ligand ) THEN
+         CALL iom_put( "LPRODP"  , zpligprod1(:,:,:) * 1e9 * zfact * tmask(:,:,:) )
+         CALL iom_put( "LDETP"   , zpligprod2(:,:,:) * 1e9 * zfact * tmask(:,:,:) )
        ENDIF
+       CALL iom_put( "Mumax"   , zprmaxn(:,:,:) * tmask(:,:,:)  ) ! Maximum growth rate
+       CALL iom_put( "MuN"     , zprbio(:,:,:) * xlimphy(:,:,:) * tmask(:,:,:) ) ! Realized growth rate for nanophyto
+       CALL iom_put( "MuD"     , zprdia(:,:,:) * xlimdia(:,:,:) * tmask(:,:,:) ) ! Realized growth rate for diatoms
+       CALL iom_put( "LNlight" , zprbio (:,:,:) / (zprmaxn(:,:,:) + rtrn) * tmask(:,:,:)  )  ! light limitation term
+       CALL iom_put( "LDlight" , zprdia (:,:,:) / (zprmaxd(:,:,:) + rtrn) * tmask(:,:,:)   )
+       CALL iom_put( "TPP"     , ( zprorcan(:,:,:) + zprorcad(:,:,:) ) * zfact * tmask(:,:,:)  )  ! total primary production
+       CALL iom_put( "TPNEW"   , ( zpronewn(:,:,:) + zpronewd(:,:,:) ) * zfact * tmask(:,:,:)  ) ! total new production
+       CALL iom_put( "TPBFE"   , ( zprofen(:,:,:) + zprofed(:,:,:) ) * zfact * tmask(:,:,:)  )  ! total biogenic iron production
+       CALL iom_put( "tintpp"  , tpp * zfact )  !  global total integrated primary production molC/s
      ENDIF
 
-     IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+     IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('prod')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
      ENDIF
       !
@@ -490,10 +363,8 @@
       ENDIF
       !
-      REWIND( numnatp_ref )              ! Namelist nampisprod in reference namelist : Pisces phytoplankton production
       READ  ( numnatp_ref, namp4zprod, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zprod in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampisprod in configuration namelist : Pisces phytoplankton production
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namp4zprod in reference namelist' )
       READ  ( numnatp_cfg, namp4zprod, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zprod in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namp4zprod in configuration namelist' )
       IF(lwm) WRITE( numonp, namp4zprod )
 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zrem.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zrem.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zrem.F90	(revision 13463)
@@ -18,5 +18,5 @@
    USE p4zprod         !  Growth rate of the 2 phyto groups
    USE p4zlim
-   USE prtctl_trc      !  print control for debugging
+   USE prtctl          !  print control for debugging
    USE iom             !  I/O manager
 
@@ -42,4 +42,7 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   denitr   !: denitrification array
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -49,5 +52,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_rem( kt, knt )
+   SUBROUTINE p4z_rem( kt, knt, Kbb, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_rem  ***
@@ -57,5 +60,6 @@
       !! ** Method  : - ???
       !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt, knt ! ocean time step
+      INTEGER, INTENT(in) ::   kt, knt         ! ocean time step
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Krhs  ! time level indices
       !
       INTEGER  ::   ji, jj, jk
@@ -68,5 +72,4 @@
       REAL(wp), DIMENSION(jpi,jpj    ) :: ztempbac
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdepbac, zolimi, zdepprod, zfacsi, zfacsib, zdepeff, zfebact
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: zw3d
       !!---------------------------------------------------------------------
       !
@@ -86,155 +89,135 @@
       ! that was modeling explicitely bacteria
       ! -------------------------------------------------------
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zdep = MAX( hmld(ji,jj), heup(ji,jj) )
-               IF( gdept_n(ji,jj,jk) < zdep ) THEN
-                  zdepbac(ji,jj,jk) = MIN( 0.7 * ( trb(ji,jj,jk,jpzoo) + 2.* trb(ji,jj,jk,jpmes) ), 4.e-6 )
-                  ztempbac(ji,jj)   = zdepbac(ji,jj,jk)
-               ELSE
-                  zdepmin = MIN( 1., zdep / gdept_n(ji,jj,jk) )
-                  zdepbac (ji,jj,jk) = zdepmin**0.683 * ztempbac(ji,jj)
-                  zdepprod(ji,jj,jk) = zdepmin**0.273
-                  zdepeff (ji,jj,jk) = zdepeff(ji,jj,jk) * zdepmin**0.3
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zdep = MAX( hmld(ji,jj), heup(ji,jj) )
+         IF( gdept(ji,jj,jk,Kmm) < zdep ) THEN
+            zdepbac(ji,jj,jk) = MIN( 0.7 * ( tr(ji,jj,jk,jpzoo,Kbb) + 2.* tr(ji,jj,jk,jpmes,Kbb) ), 4.e-6 )
+            ztempbac(ji,jj)   = zdepbac(ji,jj,jk)
+         ELSE
+            zdepmin = MIN( 1., zdep / gdept(ji,jj,jk,Kmm) )
+            zdepbac (ji,jj,jk) = zdepmin**0.683 * ztempbac(ji,jj)
+            zdepprod(ji,jj,jk) = zdepmin**0.273
+            zdepeff (ji,jj,jk) = zdepeff(ji,jj,jk) * zdepmin**0.3
+         ENDIF
+      END_3D
 
       IF( ln_p4z ) THEN
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ! DOC ammonification. Depends on depth, phytoplankton biomass
-                  ! and a limitation term which is supposed to be a parameterization of the bacterial activity. 
-                  zremik = xremik * xstep / 1.e-6 * xlimbac(ji,jj,jk) * zdepbac(ji,jj,jk) 
-                  zremik = MAX( zremik, 2.74e-4 * xstep )
-                  ! Ammonification in oxic waters with oxygen consumption
-                  ! -----------------------------------------------------
-                  zolimit = zremik * ( 1.- nitrfac(ji,jj,jk) ) * trb(ji,jj,jk,jpdoc) 
-                  zolimi(ji,jj,jk) = MIN( ( trb(ji,jj,jk,jpoxy) - rtrn ) / o2ut, zolimit ) 
-                  ! Ammonification in suboxic waters with denitrification
-                  ! -------------------------------------------------------
-                  zammonic = zremik * nitrfac(ji,jj,jk) * trb(ji,jj,jk,jpdoc)
-                  denitr(ji,jj,jk)  = zammonic * ( 1. - nitrfac2(ji,jj,jk) )
-                  denitr(ji,jj,jk)  = MIN( ( trb(ji,jj,jk,jpno3) - rtrn ) / rdenit, denitr(ji,jj,jk) )
-                  zoxyremc          = zammonic - denitr(ji,jj,jk)
-                  !
-                  zolimi (ji,jj,jk) = MAX( 0.e0, zolimi (ji,jj,jk) )
-                  denitr (ji,jj,jk) = MAX( 0.e0, denitr (ji,jj,jk) )
-                  zoxyremc          = MAX( 0.e0, zoxyremc )
-
-                  !
-                  tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) + zolimi (ji,jj,jk) + denitr(ji,jj,jk) + zoxyremc
-                  tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + zolimi (ji,jj,jk) + denitr(ji,jj,jk) + zoxyremc
-                  tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) - denitr (ji,jj,jk) * rdenit
-                  tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) - zolimi (ji,jj,jk) - denitr(ji,jj,jk) - zoxyremc
-                  tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) - zolimi (ji,jj,jk) * o2ut
-                  tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) + zolimi (ji,jj,jk) + denitr(ji,jj,jk) + zoxyremc
-                  tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) + rno3 * ( zolimi(ji,jj,jk) + zoxyremc    &
-                  &                     + ( rdenit + 1.) * denitr(ji,jj,jk) )
-               END DO
-            END DO
-         END DO
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+            ! DOC ammonification. Depends on depth, phytoplankton biomass
+            ! and a limitation term which is supposed to be a parameterization of the bacterial activity. 
+            zremik = xremik * xstep / 1.e-6 * xlimbac(ji,jj,jk) * zdepbac(ji,jj,jk) 
+            zremik = MAX( zremik, 2.74e-4 * xstep )
+            ! Ammonification in oxic waters with oxygen consumption
+            ! -----------------------------------------------------
+            zolimit = zremik * ( 1.- nitrfac(ji,jj,jk) ) * tr(ji,jj,jk,jpdoc,Kbb) 
+            zolimi(ji,jj,jk) = MIN( ( tr(ji,jj,jk,jpoxy,Kbb) - rtrn ) / o2ut, zolimit ) 
+            ! Ammonification in suboxic waters with denitrification
+            ! -------------------------------------------------------
+            zammonic = zremik * nitrfac(ji,jj,jk) * tr(ji,jj,jk,jpdoc,Kbb)
+            denitr(ji,jj,jk)  = zammonic * ( 1. - nitrfac2(ji,jj,jk) )
+            denitr(ji,jj,jk)  = MIN( ( tr(ji,jj,jk,jpno3,Kbb) - rtrn ) / rdenit, denitr(ji,jj,jk) )
+            zoxyremc          = zammonic - denitr(ji,jj,jk)
+            !
+            zolimi (ji,jj,jk) = MAX( 0.e0, zolimi (ji,jj,jk) )
+            denitr (ji,jj,jk) = MAX( 0.e0, denitr (ji,jj,jk) )
+            zoxyremc          = MAX( 0.e0, zoxyremc )
+
+            !
+            tr(ji,jj,jk,jppo4,Krhs) = tr(ji,jj,jk,jppo4,Krhs) + zolimi (ji,jj,jk) + denitr(ji,jj,jk) + zoxyremc
+            tr(ji,jj,jk,jpnh4,Krhs) = tr(ji,jj,jk,jpnh4,Krhs) + zolimi (ji,jj,jk) + denitr(ji,jj,jk) + zoxyremc
+            tr(ji,jj,jk,jpno3,Krhs) = tr(ji,jj,jk,jpno3,Krhs) - denitr (ji,jj,jk) * rdenit
+            tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) - zolimi (ji,jj,jk) - denitr(ji,jj,jk) - zoxyremc
+            tr(ji,jj,jk,jpoxy,Krhs) = tr(ji,jj,jk,jpoxy,Krhs) - zolimi (ji,jj,jk) * o2ut
+            tr(ji,jj,jk,jpdic,Krhs) = tr(ji,jj,jk,jpdic,Krhs) + zolimi (ji,jj,jk) + denitr(ji,jj,jk) + zoxyremc
+            tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) + rno3 * ( zolimi(ji,jj,jk) + zoxyremc    &
+            &                     + ( rdenit + 1.) * denitr(ji,jj,jk) )
+         END_3D
       ELSE
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ! DOC ammonification. Depends on depth, phytoplankton biomass
-                  ! and a limitation term which is supposed to be a parameterization of the bacterial activity. 
-                  ! -----------------------------------------------------------------
-                  zremik = xstep / 1.e-6 * MAX(0.01, xlimbac(ji,jj,jk)) * zdepbac(ji,jj,jk) 
-                  zremik = MAX( zremik, 2.74e-4 * xstep / xremikc )
-
-                  zremikc = xremikc * zremik
-                  zremikn = xremikn / xremikc
-                  zremikp = xremikp / xremikc
-
-                  ! Ammonification in oxic waters with oxygen consumption
-                  ! -----------------------------------------------------
-                  zolimit = zremikc * ( 1.- nitrfac(ji,jj,jk) ) * trb(ji,jj,jk,jpdoc) 
-                  zolimic = MAX( 0.e0, MIN( ( trb(ji,jj,jk,jpoxy) - rtrn ) / o2ut, zolimit ) ) 
-                  zolimi(ji,jj,jk) = zolimic
-                  zolimin = zremikn * zolimic * trb(ji,jj,jk,jpdon) / ( trb(ji,jj,jk,jpdoc) + rtrn )
-                  zolimip = zremikp * zolimic * trb(ji,jj,jk,jpdop) / ( trb(ji,jj,jk,jpdoc) + rtrn ) 
-
-                  ! Ammonification in suboxic waters with denitrification
-                  ! -------------------------------------------------------
-                  zammonic = zremikc * nitrfac(ji,jj,jk) * trb(ji,jj,jk,jpdoc)
-                  denitr(ji,jj,jk)  = zammonic * ( 1. - nitrfac2(ji,jj,jk) )
-                  denitr(ji,jj,jk)  = MAX(0., MIN(  ( trb(ji,jj,jk,jpno3) - rtrn ) / rdenit, denitr(ji,jj,jk) ) )
-                  zoxyremc          = MAX(0., zammonic - denitr(ji,jj,jk))
-                  zdenitrn  = zremikn * denitr(ji,jj,jk) * trb(ji,jj,jk,jpdon) / ( trb(ji,jj,jk,jpdoc) + rtrn )
-                  zdenitrp  = zremikp * denitr(ji,jj,jk) * trb(ji,jj,jk,jpdop) / ( trb(ji,jj,jk,jpdoc) + rtrn )
-                  zoxyremn  = zremikn * zoxyremc * trb(ji,jj,jk,jpdon) / ( trb(ji,jj,jk,jpdoc) + rtrn )
-                  zoxyremp  = zremikp * zoxyremc * trb(ji,jj,jk,jpdop) / ( trb(ji,jj,jk,jpdoc) + rtrn )
-
-                  tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) + zolimip + zdenitrp + zoxyremp
-                  tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + zolimin + zdenitrn + zoxyremn
-                  tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) - denitr(ji,jj,jk) * rdenit
-                  tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) - zolimic - denitr(ji,jj,jk) - zoxyremc
-                  tra(ji,jj,jk,jpdon) = tra(ji,jj,jk,jpdon) - zolimin - zdenitrn - zoxyremn
-                  tra(ji,jj,jk,jpdop) = tra(ji,jj,jk,jpdop) - zolimip - zdenitrp - zoxyremp
-                  tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) - zolimic * o2ut
-                  tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) + zolimic + denitr(ji,jj,jk) + zoxyremc
-                  tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) + rno3 * ( zolimin + zoxyremn + ( rdenit + 1.) * zdenitrn )
-               END DO
-            END DO
-         END DO
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+            ! DOC ammonification. Depends on depth, phytoplankton biomass
+            ! and a limitation term which is supposed to be a parameterization of the bacterial activity. 
+            ! -----------------------------------------------------------------
+            zremik = xstep / 1.e-6 * MAX(0.01, xlimbac(ji,jj,jk)) * zdepbac(ji,jj,jk) 
+            zremik = MAX( zremik, 2.74e-4 * xstep / xremikc )
+
+            zremikc = xremikc * zremik
+            zremikn = xremikn / xremikc
+            zremikp = xremikp / xremikc
+
+            ! Ammonification in oxic waters with oxygen consumption
+            ! -----------------------------------------------------
+            zolimit = zremikc * ( 1.- nitrfac(ji,jj,jk) ) * tr(ji,jj,jk,jpdoc,Kbb) 
+            zolimic = MAX( 0.e0, MIN( ( tr(ji,jj,jk,jpoxy,Kbb) - rtrn ) / o2ut, zolimit ) ) 
+            zolimi(ji,jj,jk) = zolimic
+            zolimin = zremikn * zolimic * tr(ji,jj,jk,jpdon,Kbb) / ( tr(ji,jj,jk,jpdoc,Kbb) + rtrn )
+            zolimip = zremikp * zolimic * tr(ji,jj,jk,jpdop,Kbb) / ( tr(ji,jj,jk,jpdoc,Kbb) + rtrn ) 
+
+            ! Ammonification in suboxic waters with denitrification
+            ! -------------------------------------------------------
+            zammonic = zremikc * nitrfac(ji,jj,jk) * tr(ji,jj,jk,jpdoc,Kbb)
+            denitr(ji,jj,jk)  = zammonic * ( 1. - nitrfac2(ji,jj,jk) )
+            denitr(ji,jj,jk)  = MAX(0., MIN(  ( tr(ji,jj,jk,jpno3,Kbb) - rtrn ) / rdenit, denitr(ji,jj,jk) ) )
+            zoxyremc          = MAX(0., zammonic - denitr(ji,jj,jk))
+            zdenitrn  = zremikn * denitr(ji,jj,jk) * tr(ji,jj,jk,jpdon,Kbb) / ( tr(ji,jj,jk,jpdoc,Kbb) + rtrn )
+            zdenitrp  = zremikp * denitr(ji,jj,jk) * tr(ji,jj,jk,jpdop,Kbb) / ( tr(ji,jj,jk,jpdoc,Kbb) + rtrn )
+            zoxyremn  = zremikn * zoxyremc * tr(ji,jj,jk,jpdon,Kbb) / ( tr(ji,jj,jk,jpdoc,Kbb) + rtrn )
+            zoxyremp  = zremikp * zoxyremc * tr(ji,jj,jk,jpdop,Kbb) / ( tr(ji,jj,jk,jpdoc,Kbb) + rtrn )
+
+            tr(ji,jj,jk,jppo4,Krhs) = tr(ji,jj,jk,jppo4,Krhs) + zolimip + zdenitrp + zoxyremp
+            tr(ji,jj,jk,jpnh4,Krhs) = tr(ji,jj,jk,jpnh4,Krhs) + zolimin + zdenitrn + zoxyremn
+            tr(ji,jj,jk,jpno3,Krhs) = tr(ji,jj,jk,jpno3,Krhs) - denitr(ji,jj,jk) * rdenit
+            tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) - zolimic - denitr(ji,jj,jk) - zoxyremc
+            tr(ji,jj,jk,jpdon,Krhs) = tr(ji,jj,jk,jpdon,Krhs) - zolimin - zdenitrn - zoxyremn
+            tr(ji,jj,jk,jpdop,Krhs) = tr(ji,jj,jk,jpdop,Krhs) - zolimip - zdenitrp - zoxyremp
+            tr(ji,jj,jk,jpoxy,Krhs) = tr(ji,jj,jk,jpoxy,Krhs) - zolimic * o2ut
+            tr(ji,jj,jk,jpdic,Krhs) = tr(ji,jj,jk,jpdic,Krhs) + zolimic + denitr(ji,jj,jk) + zoxyremc
+            tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) + rno3 * ( zolimin + zoxyremn + ( rdenit + 1.) * zdenitrn )
+         END_3D
          !
       ENDIF
 
 
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! NH4 nitrification to NO3. Ceased for oxygen concentrations
-               ! below 2 umol/L. Inhibited at strong light 
-               ! ----------------------------------------------------------
-               zonitr  = nitrif * xstep * trb(ji,jj,jk,jpnh4) * ( 1.- nitrfac(ji,jj,jk) )  &
-               &         / ( 1.+ emoy(ji,jj,jk) ) * ( 1. + fr_i(ji,jj) * emoy(ji,jj,jk) ) 
-               zdenitnh4 = nitrif * xstep * trb(ji,jj,jk,jpnh4) * nitrfac(ji,jj,jk)
-               zdenitnh4 = MIN(  ( trb(ji,jj,jk,jpno3) - rtrn ) / rdenita, zdenitnh4 ) 
-               ! Update of the tracers trends
-               ! ----------------------------
-               tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) - zonitr - zdenitnh4
-               tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) + zonitr - rdenita * zdenitnh4
-               tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) - o2nit * zonitr
-               tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) - 2 * rno3 * zonitr + rno3 * ( rdenita - 1. ) * zdenitnh4
-            END DO
-         END DO
-      END DO
-
-       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         ! NH4 nitrification to NO3. Ceased for oxygen concentrations
+         ! below 2 umol/L. Inhibited at strong light 
+         ! ----------------------------------------------------------
+         zonitr  = nitrif * xstep * tr(ji,jj,jk,jpnh4,Kbb) * ( 1.- nitrfac(ji,jj,jk) )  &
+         &         / ( 1.+ emoy(ji,jj,jk) ) * ( 1. + fr_i(ji,jj) * emoy(ji,jj,jk) ) 
+         zdenitnh4 = nitrif * xstep * tr(ji,jj,jk,jpnh4,Kbb) * nitrfac(ji,jj,jk)
+         zdenitnh4 = MIN(  ( tr(ji,jj,jk,jpno3,Kbb) - rtrn ) / rdenita, zdenitnh4 ) 
+         ! Update of the tracers trends
+         ! ----------------------------
+         tr(ji,jj,jk,jpnh4,Krhs) = tr(ji,jj,jk,jpnh4,Krhs) - zonitr - zdenitnh4
+         tr(ji,jj,jk,jpno3,Krhs) = tr(ji,jj,jk,jpno3,Krhs) + zonitr - rdenita * zdenitnh4
+         tr(ji,jj,jk,jpoxy,Krhs) = tr(ji,jj,jk,jpoxy,Krhs) - o2nit * zonitr
+         tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) - 2 * rno3 * zonitr + rno3 * ( rdenita - 1. ) * zdenitnh4
+      END_3D
+
+       IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('rem1')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
        ENDIF
 
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-
-               ! Bacterial uptake of iron. No iron is available in DOC. So
-               ! Bacteries are obliged to take up iron from the water. Some
-               ! studies (especially at Papa) have shown this uptake to be significant
-               ! ----------------------------------------------------------
-               zbactfer = feratb *  rfact2 * 0.6_wp / rday * tgfunc(ji,jj,jk) * xlimbacl(ji,jj,jk)     &
-                  &              * trb(ji,jj,jk,jpfer) / ( xkferb + trb(ji,jj,jk,jpfer) )    &
-                  &              * zdepprod(ji,jj,jk) * zdepeff(ji,jj,jk) * zdepbac(ji,jj,jk)
-               tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) - zbactfer*0.33
-               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + zbactfer*0.25
-               tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + zbactfer*0.08
-               zfebact(ji,jj,jk)   = zbactfer * 0.33
-               blim(ji,jj,jk)      = xlimbacl(ji,jj,jk)  * zdepbac(ji,jj,jk) / 1.e-6 * zdepprod(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-
-       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+
+         ! Bacterial uptake of iron. No iron is available in DOC. So
+         ! Bacteries are obliged to take up iron from the water. Some
+         ! studies (especially at Papa) have shown this uptake to be significant
+         ! ----------------------------------------------------------
+         zbactfer = feratb *  rfact2 * 0.6_wp / rday * tgfunc(ji,jj,jk) * xlimbacl(ji,jj,jk)     &
+            &              * tr(ji,jj,jk,jpfer,Kbb) / ( xkferb + tr(ji,jj,jk,jpfer,Kbb) )    &
+            &              * zdepprod(ji,jj,jk) * zdepeff(ji,jj,jk) * zdepbac(ji,jj,jk)
+         tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) - zbactfer*0.33
+         tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) + zbactfer*0.25
+         tr(ji,jj,jk,jpbfe,Krhs) = tr(ji,jj,jk,jpbfe,Krhs) + zbactfer*0.08
+         zfebact(ji,jj,jk)   = zbactfer * 0.33
+         blim(ji,jj,jk)      = xlimbacl(ji,jj,jk)  * zdepbac(ji,jj,jk) / 1.e-6 * zdepprod(ji,jj,jk)
+      END_3D
+
+       IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('rem2')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
        ENDIF
 
@@ -243,58 +226,42 @@
       ! ---------------------------------------------------------------
 
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zdep     = MAX( hmld(ji,jj), heup_01(ji,jj) )
-               zsatur   = MAX( rtrn, ( sio3eq(ji,jj,jk) - trb(ji,jj,jk,jpsil) ) / ( sio3eq(ji,jj,jk) + rtrn ) )
-               zsatur2  = ( 1. + tsn(ji,jj,jk,jp_tem) / 400.)**37
-               znusil   = 0.225  * ( 1. + tsn(ji,jj,jk,jp_tem) / 15.) * zsatur + 0.775 * zsatur2 * zsatur**9.25
-               ! Remineralization rate of BSi depedant on T and saturation
-               ! ---------------------------------------------------------
-               IF ( gdept_n(ji,jj,jk) > zdep ) THEN
-                  zfacsib(ji,jj,jk) = zfacsib(ji,jj,jk-1) * EXP( -0.5 * ( xsiremlab - xsirem )  &
-                  &                   * znusil * e3t_n(ji,jj,jk) / wsbio4(ji,jj,jk) )
-                  zfacsi(ji,jj,jk)  = zfacsib(ji,jj,jk) / ( 1.0 + zfacsib(ji,jj,jk) )
-                  zfacsib(ji,jj,jk) = zfacsib(ji,jj,jk) * EXP( -0.5 * ( xsiremlab - xsirem )    &
-                  &                   * znusil * e3t_n(ji,jj,jk) / wsbio4(ji,jj,jk) )
-               ENDIF
-               zsiremin = ( xsiremlab * zfacsi(ji,jj,jk) + xsirem * ( 1. - zfacsi(ji,jj,jk) ) ) * xstep * znusil
-               zosil    = zsiremin * trb(ji,jj,jk,jpgsi)
-               !
-               tra(ji,jj,jk,jpgsi) = tra(ji,jj,jk,jpgsi) - zosil
-               tra(ji,jj,jk,jpsil) = tra(ji,jj,jk,jpsil) + zosil
-            END DO
-         END DO
-      END DO
-
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zdep     = MAX( hmld(ji,jj), heup_01(ji,jj) )
+         zsatur   = MAX( rtrn, ( sio3eq(ji,jj,jk) - tr(ji,jj,jk,jpsil,Kbb) ) / ( sio3eq(ji,jj,jk) + rtrn ) )
+         zsatur2  = ( 1. + ts(ji,jj,jk,jp_tem,Kmm) / 400.)**37
+         znusil   = 0.225  * ( 1. + ts(ji,jj,jk,jp_tem,Kmm) / 15.) * zsatur + 0.775 * zsatur2 * zsatur**9.25
+         ! Remineralization rate of BSi depedant on T and saturation
+         ! ---------------------------------------------------------
+         IF ( gdept(ji,jj,jk,Kmm) > zdep ) THEN
+            zfacsib(ji,jj,jk) = zfacsib(ji,jj,jk-1) * EXP( -0.5 * ( xsiremlab - xsirem )  &
+            &                   * znusil * e3t(ji,jj,jk,Kmm) / wsbio4(ji,jj,jk) )
+            zfacsi(ji,jj,jk)  = zfacsib(ji,jj,jk) / ( 1.0 + zfacsib(ji,jj,jk) )
+            zfacsib(ji,jj,jk) = zfacsib(ji,jj,jk) * EXP( -0.5 * ( xsiremlab - xsirem )    &
+            &                   * znusil * e3t(ji,jj,jk,Kmm) / wsbio4(ji,jj,jk) )
+         ENDIF
+         zsiremin = ( xsiremlab * zfacsi(ji,jj,jk) + xsirem * ( 1. - zfacsi(ji,jj,jk) ) ) * xstep * znusil
+         zosil    = zsiremin * tr(ji,jj,jk,jpgsi,Kbb)
+         !
+         tr(ji,jj,jk,jpgsi,Krhs) = tr(ji,jj,jk,jpgsi,Krhs) - zosil
+         tr(ji,jj,jk,jpsil,Krhs) = tr(ji,jj,jk,jpsil,Krhs) + zosil
+      END_3D
+
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('rem3')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
        ENDIF
 
       IF( knt == nrdttrc ) THEN
-          zrfact2 = 1.e3 * rfact2r
-          ALLOCATE( zw3d(jpi,jpj,jpk) )
-          zfact = 1.e+3 * rfact2r  !  conversion from mol/l/kt to  mol/m3/s
+          zrfact2 = 1.e+3 * rfact2r  !  conversion from mol/l/kt to  mol/m3/s
           !
-          IF( iom_use( "REMIN" ) )  THEN
-              zw3d(:,:,:) = zolimi(:,:,:) * tmask(:,:,:) * zfact !  Remineralisation rate
-              CALL iom_put( "REMIN"  , zw3d )
+          IF( iom_use( "REMIN" ) )  THEN !  Remineralisation rate
+             zolimi(:,:,jpk) = 0. ; CALL iom_put( "REMIN"  , zolimi(:,:,:) * tmask(:,:,:) * zrfact2  )
           ENDIF
-          IF( iom_use( "DENIT" ) )  THEN
-              zw3d(:,:,:) = denitr(:,:,:) * rdenit * rno3 * tmask(:,:,:) * zfact ! Denitrification
-              CALL iom_put( "DENIT"  , zw3d )
+          CALL iom_put( "DENIT"  , denitr(:,:,:) * rdenit * rno3 * tmask(:,:,:) * zrfact2 ) ! Denitrification 
+          IF( iom_use( "BACT" ) )  THEN ! Bacterial biomass
+             zdepbac(:,:,jpk) = 0.  ;   CALL iom_put( "BACT", zdepbac(:,:,:) * 1.E6 * tmask(:,:,:) )
           ENDIF
-          IF( iom_use( "BACT" ) )  THEN
-               zw3d(:,:,:) = zdepbac(:,:,:) * 1.E6 * tmask(:,:,:)  ! Bacterial biomass
-               CALL iom_put( "BACT", zw3d )
-          ENDIF
-          IF( iom_use( "FEBACT" ) )  THEN
-               zw3d(:,:,:) = zfebact(:,:,:) * 1E9 * tmask(:,:,:) * zrfact2   ! Bacterial iron consumption
-               CALL iom_put( "FEBACT" , zw3d )
-          ENDIF
-          !
-          DEALLOCATE( zw3d )
+          CALL iom_put( "FEBACT" , zfebact(:,:,:) * 1E9 * tmask(:,:,:) * zrfact2  )
        ENDIF
       !
@@ -327,10 +294,8 @@
       ENDIF
       !
-      REWIND( numnatp_ref )              ! Namelist nampisrem in reference namelist : Pisces remineralization
       READ  ( numnatp_ref, nampisrem, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisrem in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampisrem in configuration namelist : Pisces remineralization
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisrem in reference namelist' )
       READ  ( numnatp_cfg, nampisrem, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisrem in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisrem in configuration namelist' )
       IF(lwm) WRITE( numonp, nampisrem )
 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zsbc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zsbc.F90	(revision 11396)
+++ 	(revision )
@@ -1,497 +1,0 @@
-MODULE p4zsbc
-   !!======================================================================
-   !!                         ***  MODULE p4sbc  ***
-   !! TOP :   PISCES surface boundary conditions of external inputs of nutrients
-   !!======================================================================
-   !! History :   3.5  !  2012-07 (O. Aumont, C. Ethe) Original code
-   !!----------------------------------------------------------------------
-   !!   p4z_sbc        :  Read and interpolate time-varying nutrients fluxes
-   !!   p4z_sbc_init   :  Initialization of p4z_sbc
-   !!----------------------------------------------------------------------
-   USE oce_trc         !  shared variables between ocean and passive tracers
-   USE trc             !  passive tracers common variables 
-   USE sms_pisces      !  PISCES Source Minus Sink variables
-   USE iom             !  I/O manager
-   USE fldread         !  time interpolation
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   p4z_sbc
-   PUBLIC   p4z_sbc_init   
-
-   LOGICAL , PUBLIC ::   ln_dust      !: boolean for dust input from the atmosphere
-   LOGICAL , PUBLIC ::   ln_solub     !: boolean for variable solubility of atmospheric iron
-   LOGICAL , PUBLIC ::   ln_river     !: boolean for river input of nutrients
-   LOGICAL , PUBLIC ::   ln_ndepo     !: boolean for atmospheric deposition of N
-   LOGICAL , PUBLIC ::   ln_ironsed   !: boolean for Fe input from sediments
-   LOGICAL , PUBLIC ::   ln_hydrofe   !: boolean for Fe input from hydrothermal vents
-   REAL(wp), PUBLIC ::   sedfeinput   !: Coastal release of Iron
-   REAL(wp), PUBLIC ::   dustsolub    !: Solubility of the dust
-   REAL(wp), PUBLIC ::   mfrac        !: Mineral Content of the dust
-   REAL(wp), PUBLIC ::   icefeinput   !: Iron concentration in sea ice
-   REAL(wp), PUBLIC ::   wdust        !: Sinking speed of the dust 
-   REAL(wp), PUBLIC ::   nitrfix      !: Nitrogen fixation rate   
-   REAL(wp), PUBLIC ::   diazolight   !: Nitrogen fixation sensitivty to light 
-   REAL(wp), PUBLIC ::   concfediaz   !: Fe half-saturation Cste for diazotrophs 
-   REAL(wp)         ::   hratio       !: Fe:3He ratio assumed for vent iron supply
-   REAL(wp)         ::   distcoast    !: Distance off the coast for Iron from sediments
-   REAL(wp), PUBLIC ::   lgw_rath     !: Weak ligand ratio from hydro sources
-
-   LOGICAL , PUBLIC ::   ll_sbc
-   LOGICAL          ::   ll_solub
-
-   INTEGER , PARAMETER  :: jpriv  = 7   !: Maximum number of river input fields
-   INTEGER , PARAMETER  :: jr_dic = 1   !: index of dissolved inorganic carbon
-   INTEGER , PARAMETER  :: jr_doc = 2   !: index of dissolved organic carbon
-   INTEGER , PARAMETER  :: jr_din = 3   !: index of dissolved inorganic nitrogen
-   INTEGER , PARAMETER  :: jr_don = 4   !: index of dissolved organic nitrogen
-   INTEGER , PARAMETER  :: jr_dip = 5   !: index of dissolved inorganic phosporus
-   INTEGER , PARAMETER  :: jr_dop = 6   !: index of dissolved organic phosphorus
-   INTEGER , PARAMETER  :: jr_dsi = 7   !: index of dissolved silicate
-
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_dust      ! structure of input dust
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_solub     ! structure of input dust
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_river     ! structure of input riverdic
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_ndepo     ! structure of input nitrogen deposition
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_ironsed   ! structure of input iron from sediment
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_hydrofe   ! structure of input iron from hydrothermal vents
-
-   INTEGER , PARAMETER ::   nbtimes = 365                          ! maximum number of times record in a file
-   INTEGER             ::   ntimes_dust, ntimes_riv, ntimes_ndep   ! number of time steps in a file
-   INTEGER             ::   ntimes_solub, ntimes_hydro             ! number of time steps in a file
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   dust  , solub    !: dust fields
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   rivdic, rivalk   !: river input fields
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   rivdin, rivdip   !: river input fields
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   rivdon, rivdop   !: river input fields
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   rivdoc           !: river input fields
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   rivdsi           !: river input fields
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   nitdep           !: atmospheric N deposition 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ironsed          !: Coastal supply of iron
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hydrofe          !: Hydrothermal vent supply of iron
-
-   REAL(wp), PUBLIC :: sedsilfrac, sedcalfrac
-   REAL(wp), PUBLIC :: rivalkinput, rivdicinput
-   REAL(wp), PUBLIC :: rivdininput, rivdipinput, rivdsiinput
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
-   !! $Id$ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE p4z_sbc( kt )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine p4z_sbc  ***
-      !!
-      !! ** purpose :   read and interpolate the external sources of nutrients
-      !!
-      !! ** method  :   read the files and interpolate the appropriate variables
-      !!
-      !! ** input   :   external netcdf files
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time step
-      !
-      INTEGER  ::   ji, jj 
-      REAL(wp) ::   zcoef, zyyss
-      !!---------------------------------------------------------------------
-      !
-      IF( ln_timing )   CALL timing_start('p4z_sbc')
-      !
-      ! Compute dust at nit000 or only if there is more than 1 time record in dust file
-      IF( ln_dust ) THEN
-         IF( kt == nit000 .OR. ( kt /= nit000 .AND. ntimes_dust > 1 ) ) THEN
-            CALL fld_read( kt, 1, sf_dust )
-            dust(:,:) = MAX( rtrn, sf_dust(1)%fnow(:,:,1) ) * ( 1.0 - fr_i(:,:) )
-         ENDIF
-      ENDIF
-      !
-      IF( ll_solub ) THEN
-         IF( kt == nit000 .OR. ( kt /= nit000 .AND. ntimes_solub > 1 ) ) THEN
-            CALL fld_read( kt, 1, sf_solub )
-            solub(:,:) = sf_solub(1)%fnow(:,:,1)
-         ENDIF
-      ENDIF
-
-      ! N/P and Si releases due to coastal rivers
-      ! Compute river at nit000 or only if there is more than 1 time record in river file
-      ! -----------------------------------------
-      IF( ln_river ) THEN
-         IF( kt == nit000 .OR. ( kt /= nit000 .AND. ntimes_riv > 1 ) ) THEN
-            CALL fld_read( kt, 1, sf_river )
-            IF( ln_p4z ) THEN
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     zcoef = ryyss * e1e2t(ji,jj) * h_rnf(ji,jj) 
-                     rivalk(ji,jj) =   sf_river(jr_dic)%fnow(ji,jj,1)  &
-                        &              * 1.E3        / ( 12. * zcoef + rtrn )
-                     rivdic(ji,jj) =   sf_river(jr_dic)%fnow(ji,jj,1)  &
-                        &              * 1.E3         / ( 12. * zcoef + rtrn )
-                     rivdin(ji,jj) =   sf_river(jr_din)%fnow(ji,jj,1)  &
-                        &              * 1.E3 / rno3 / ( 14. * zcoef + rtrn )
-                     rivdip(ji,jj) =   sf_river(jr_dip)%fnow(ji,jj,1)  &
-                        &              * 1.E3 / po4r / ( 31. * zcoef + rtrn )
-                     rivdsi(ji,jj) =   sf_river(jr_dsi)%fnow(ji,jj,1)  &
-                        &              * 1.E3        / ( 28.1 * zcoef + rtrn )
-                     rivdoc(ji,jj) =   sf_river(jr_doc)%fnow(ji,jj,1)  &
-                        &              * 1.E3        / ( 12. * zcoef + rtrn ) 
-                  END DO
-               END DO
-            ELSE    !  ln_p5z
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     zcoef = ryyss * e1e2t(ji,jj) * h_rnf(ji,jj) 
-                     rivalk(ji,jj) =   sf_river(jr_dic)%fnow(ji,jj,1)                                    &
-                        &              * 1.E3        / ( 12. * zcoef + rtrn )
-                     rivdic(ji,jj) = ( sf_river(jr_dic)%fnow(ji,jj,1) ) &
-                        &              * 1.E3 / ( 12. * zcoef + rtrn ) * tmask(ji,jj,1)
-                     rivdin(ji,jj) = ( sf_river(jr_din)%fnow(ji,jj,1) ) &
-                        &              * 1.E3 / rno3 / ( 14. * zcoef + rtrn ) * tmask(ji,jj,1)
-                     rivdip(ji,jj) = ( sf_river(jr_dip)%fnow(ji,jj,1) ) &
-                        &              * 1.E3 / po4r / ( 31. * zcoef + rtrn ) * tmask(ji,jj,1)
-                     rivdon(ji,jj) = ( sf_river(jr_don)%fnow(ji,jj,1) ) &
-                        &              * 1.E3 / rno3 / ( 14. * zcoef + rtrn ) * tmask(ji,jj,1)
-                     rivdop(ji,jj) = ( sf_river(jr_dop)%fnow(ji,jj,1) ) &
-                        &              * 1.E3 / po4r / ( 31. * zcoef + rtrn ) * tmask(ji,jj,1)
-                     rivdsi(ji,jj) =   sf_river(jr_dsi)%fnow(ji,jj,1)  &
-                        &              * 1.E3        / ( 28.1 * zcoef + rtrn )
-                     rivdoc(ji,jj) =   sf_river(jr_doc)%fnow(ji,jj,1)  &
-                        &              * 1.E3        / ( 12. * zcoef + rtrn )
-                  END DO
-               END DO
-            ENDIF
-         ENDIF
-      ENDIF
-
-      ! Compute N deposition at nit000 or only if there is more than 1 time record in N deposition file
-      IF( ln_ndepo ) THEN
-         IF( kt == nit000 .OR. ( kt /= nit000 .AND. ntimes_ndep > 1 ) ) THEN
-             zcoef = 14. * rno3
-             CALL fld_read( kt, 1, sf_ndepo )
-             nitdep(:,:) = MAX( rtrn, sf_ndepo(1)%fnow(:,:,1) / zcoef / e3t_n(:,:,1) )
-         ENDIF
-         IF( .NOT.ln_linssh ) THEN
-            zcoef = 14. * rno3
-            nitdep(:,:) = MAX( rtrn, sf_ndepo(1)%fnow(:,:,1) / zcoef / e3t_n(:,:,1) )
-         ENDIF
-      ENDIF
-      !
-      IF( ln_timing )  CALL timing_stop('p4z_sbc')
-      !
-   END SUBROUTINE p4z_sbc
-
-
-   SUBROUTINE p4z_sbc_init
-      !!----------------------------------------------------------------------
-      !!                  ***  routine p4z_sbc_init  ***
-      !!
-      !! ** purpose :   initialization of the external sources of nutrients
-      !!
-      !! ** method  :   read the files and compute the budget
-      !!                called at the first timestep (nittrc000)
-      !!
-      !! ** input   :   external netcdf files
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER  :: ji, jj, jk, jm, ifpr
-      INTEGER  :: ii0, ii1, ij0, ij1
-      INTEGER  :: numdust, numsolub, numriv, numiron, numdepo, numhydro
-      INTEGER  :: ierr, ierr1, ierr2, ierr3
-      INTEGER  :: ios                 ! Local integer output status for namelist read
-      INTEGER  :: ik50                !  last level where depth less than 50 m
-      INTEGER  :: isrow             ! index for ORCA1 starting row
-      REAL(wp) :: zexpide, zdenitide, zmaskt, zsurfc, zsurfp,ze3t, ze3t2, zcslp
-      REAL(wp) :: ztimes_dust, ztimes_riv, ztimes_ndep 
-      REAL(wp), DIMENSION(:), ALLOCATABLE :: rivinput
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zriver, zcmask
-      !
-      CHARACTER(len=100) ::  cn_dir          ! Root directory for location of ssr files
-      TYPE(FLD_N), DIMENSION(jpriv) ::  slf_river    ! array of namelist informations on the fields to read
-      TYPE(FLD_N) ::   sn_dust, sn_solub, sn_ndepo, sn_ironsed, sn_hydrofe   ! informations about the fields to be read
-      TYPE(FLD_N) ::   sn_riverdoc, sn_riverdic, sn_riverdsi   ! informations about the fields to be read
-      TYPE(FLD_N) ::   sn_riverdin, sn_riverdon, sn_riverdip, sn_riverdop
-      !!
-      NAMELIST/nampissbc/cn_dir, sn_dust, sn_solub, sn_riverdic, sn_riverdoc, sn_riverdin, sn_riverdon,     &
-        &                sn_riverdip, sn_riverdop, sn_riverdsi, sn_ndepo, sn_ironsed, sn_hydrofe, &
-        &                ln_dust, ln_solub, ln_river, ln_ndepo, ln_ironsed, ln_ironice, ln_hydrofe,    &
-        &                sedfeinput, distcoast, dustsolub, icefeinput, wdust, mfrac, nitrfix, diazolight, concfediaz, &
-        &                hratio, lgw_rath
-      !!----------------------------------------------------------------------
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'p4z_sbc_init : initialization of the external sources of nutrients '
-         WRITE(numout,*) '~~~~~~~~~~~~ '
-      ENDIF
-      !                            !* set file information
-      REWIND( numnatp_ref )              ! Namelist nampissbc in reference namelist : Pisces external sources of nutrients
-      READ  ( numnatp_ref, nampissbc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampissbc in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampissbc in configuration namelist : Pisces external sources of nutrients
-      READ  ( numnatp_cfg, nampissbc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampissbc in configuration namelist', lwp )
-      IF(lwm) WRITE ( numonp, nampissbc )
-
-      IF(lwp) THEN
-         WRITE(numout,*) '   Namelist : nampissbc '
-         WRITE(numout,*) '      dust input from the atmosphere           ln_dust     = ', ln_dust
-         WRITE(numout,*) '      Variable solubility of iron input        ln_solub    = ', ln_solub
-         WRITE(numout,*) '      river input of nutrients                 ln_river    = ', ln_river
-         WRITE(numout,*) '      atmospheric deposition of n              ln_ndepo    = ', ln_ndepo
-         WRITE(numout,*) '      Fe input from sediments                  ln_ironsed  = ', ln_ironsed
-         WRITE(numout,*) '      Fe input from seaice                     ln_ironice  = ', ln_ironice
-         WRITE(numout,*) '      fe input from hydrothermal vents         ln_hydrofe  = ', ln_hydrofe
-         WRITE(numout,*) '      coastal release of iron                  sedfeinput  = ', sedfeinput
-         WRITE(numout,*) '      distance off the coast                   distcoast   = ', distcoast
-         WRITE(numout,*) '      solubility of the dust                   dustsolub   = ', dustsolub
-         WRITE(numout,*) '      Mineral Fe content of the dust           mfrac       = ', mfrac
-         WRITE(numout,*) '      Iron concentration in sea ice            icefeinput  = ', icefeinput
-         WRITE(numout,*) '      sinking speed of the dust                wdust       = ', wdust
-         WRITE(numout,*) '      nitrogen fixation rate                   nitrfix     = ', nitrfix
-         WRITE(numout,*) '      nitrogen fixation sensitivty to light    diazolight  = ', diazolight
-         WRITE(numout,*) '      Fe half-saturation cste for diazotrophs  concfediaz  = ', concfediaz
-         WRITE(numout,*) '      Fe to 3He ratio assumed for vent iron supply hratio  = ', hratio
-         IF( ln_ligand ) THEN
-            WRITE(numout,*) '      Weak ligand ratio from sed hydro sources  lgw_rath   = ', lgw_rath
-         ENDIF
-      END IF
-
-      IF( ln_dust .OR. ln_river .OR. ln_ndepo ) THEN   ;   ll_sbc = .TRUE.
-      ELSE                                             ;   ll_sbc = .FALSE.
-      ENDIF
-
-      IF( ln_dust .AND. ln_solub ) THEN                ;   ll_solub = .TRUE.
-      ELSE                                             ;   ll_solub = .FALSE.
-      ENDIF
-
-      ! set the number of level over which river runoffs are applied 
-      ! online configuration : computed in sbcrnf
-      IF( l_offline ) THEN
-        nk_rnf(:,:) = 1
-        h_rnf (:,:) = gdept_n(:,:,1)
-      ENDIF
-
-      ! dust input from the atmosphere
-      ! ------------------------------
-      IF( ln_dust ) THEN 
-         !
-         IF(lwp) WRITE(numout,*) '    initialize dust input from atmosphere '
-         IF(lwp) WRITE(numout,*) '    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
-         !
-         ALLOCATE( dust(jpi,jpj) )    ! allocation
-         !
-         ALLOCATE( sf_dust(1), STAT=ierr )           !* allocate and fill sf_sst (forcing structure) with sn_sst
-         IF( ierr > 0 )   CALL ctl_stop( 'STOP', 'p4z_sed_init: unable to allocate sf_dust structure' )
-         !
-         CALL fld_fill( sf_dust, (/ sn_dust /), cn_dir, 'p4z_sed_init', 'Atmospheric dust deposition', 'nampissed' )
-                                   ALLOCATE( sf_dust(1)%fnow(jpi,jpj,1)   )
-         IF( sn_dust%ln_tint )     ALLOCATE( sf_dust(1)%fdta(jpi,jpj,1,2) )
-         !
-         IF( Agrif_Root() ) THEN   !  Only on the master grid
-            ! Get total input dust ; need to compute total atmospheric supply of Si in a year
-            CALL iom_open (  TRIM( sn_dust%clname ) , numdust )
-            ntimes_dust = iom_getszuld( numdust )   ! get number of record in file
-         END IF
-      END IF
-
-      ! Solubility of dust deposition of iron
-      ! Only if ln_dust and ln_solubility set to true (ll_solub = .true.)
-      ! -----------------------------------------------------------------
-      IF( ll_solub ) THEN
-         !
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) '   ==>>>   ll_solub=T , initialize variable solubility of Fe '
-         !
-         ALLOCATE( solub(jpi,jpj) )    ! allocation
-         !
-         ALLOCATE( sf_solub(1), STAT=ierr )           !* allocate and fill sf_sst (forcing structure) with sn_sst
-         IF( ierr > 0 )   CALL ctl_stop( 'STOP', 'p4z_sed_init: unable to allocate sf_solub structure' )
-         !
-         CALL fld_fill( sf_solub, (/ sn_solub /), cn_dir, 'p4z_sed_init', 'Solubility of atm. iron ', 'nampissed' )
-                                   ALLOCATE( sf_solub(1)%fnow(jpi,jpj,1)   )
-         IF( sn_solub%ln_tint )    ALLOCATE( sf_solub(1)%fdta(jpi,jpj,1,2) )
-         ! get number of record in file
-         CALL iom_open (  TRIM( sn_solub%clname ) , numsolub )
-         ntimes_solub = iom_getszuld( numsolub )   ! get number of record in file
-         CALL iom_close( numsolub )
-      ENDIF
-
-      ! nutrient input from rivers
-      ! --------------------------
-      IF( ln_river ) THEN
-         !
-         slf_river(jr_dic) = sn_riverdic   ;   slf_river(jr_doc) = sn_riverdoc   ;   slf_river(jr_din) = sn_riverdin 
-         slf_river(jr_don) = sn_riverdon   ;   slf_river(jr_dip) = sn_riverdip   ;   slf_river(jr_dop) = sn_riverdop
-         slf_river(jr_dsi) = sn_riverdsi  
-         !
-         ALLOCATE( rivdic(jpi,jpj), rivalk(jpi,jpj), rivdin(jpi,jpj), rivdip(jpi,jpj), rivdsi(jpi,jpj), rivdoc(jpi,jpj) ) 
-         IF( ln_p5z )  ALLOCATE( rivdon(jpi,jpj), rivdop(jpi,jpj) )
-         !
-         ALLOCATE( sf_river(jpriv), rivinput(jpriv), STAT=ierr1 )    !* allocate and fill sf_river (forcing structure) with sn_river_
-         rivinput(:) = 0._wp
-
-         IF( ierr1 > 0 )   CALL ctl_stop( 'STOP', 'p4z_sed_init: unable to allocate sf_irver structure' )
-         !
-         CALL fld_fill( sf_river, slf_river, cn_dir, 'p4z_sed_init', 'Input from river ', 'nampissed' )
-         DO ifpr = 1, jpriv
-                                          ALLOCATE( sf_river(ifpr)%fnow(jpi,jpj,1  ) )
-            IF( slf_river(ifpr)%ln_tint ) ALLOCATE( sf_river(ifpr)%fdta(jpi,jpj,1,2) )
-         END DO
-         IF( Agrif_Root() ) THEN   !  Only on the master grid
-            ! Get total input rivers ; need to compute total river supply in a year
-            DO ifpr = 1, jpriv
-               CALL iom_open ( TRIM( slf_river(ifpr)%clname ), numriv )
-               ntimes_riv = iom_getszuld( numriv )
-               ALLOCATE( zriver(jpi,jpj,ntimes_riv) )
-               DO jm = 1, ntimes_riv
-                  CALL iom_get( numriv, jpdom_data, TRIM( slf_river(ifpr)%clvar ), zriver(:,:,jm), jm )
-               END DO
-               CALL iom_close( numriv )
-               ztimes_riv = 1._wp / REAL(ntimes_riv, wp) 
-               DO jm = 1, ntimes_riv
-                  rivinput(ifpr) = rivinput(ifpr) + glob_sum( 'p4zsbc', zriver(:,:,jm) * tmask(:,:,1) * ztimes_riv ) 
-               END DO
-               DEALLOCATE( zriver)
-            END DO
-            ! N/P and Si releases due to coastal rivers
-            ! -----------------------------------------
-            rivdicinput = (rivinput(jr_dic) + rivinput(jr_doc) ) * 1E3 / 12._wp
-            rivdininput = (rivinput(jr_din) + rivinput(jr_don) ) * 1E3 / rno3 / 14._wp
-            rivdipinput = (rivinput(jr_dip) + rivinput(jr_dop) ) * 1E3 / po4r / 31._wp
-            rivdsiinput = rivinput(jr_dsi) * 1E3 / 28.1_wp
-            rivalkinput = rivinput(jr_dic) * 1E3 / 12._wp
-            !
-         ENDIF
-      ELSE
-         rivdicinput = 0._wp
-         rivdininput = 0._wp
-         rivdipinput = 0._wp
-         rivdsiinput = 0._wp
-         rivalkinput = 0._wp
-      END IF 
-      ! nutrient input from dust
-      ! ------------------------
-      IF( ln_ndepo ) THEN
-         !
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) '   ==>>>   ln_ndepo=T , initialize the nutrient input by dust from NetCDF file'
-         !
-         ALLOCATE( nitdep(jpi,jpj) )    ! allocation
-         !
-         ALLOCATE( sf_ndepo(1), STAT=ierr3 )           !* allocate and fill sf_sst (forcing structure) with sn_sst
-         IF( ierr3 > 0 )   CALL ctl_stop( 'STOP', 'p4z_sed_init: unable to allocate sf_ndepo structure' )
-         !
-         CALL fld_fill( sf_ndepo, (/ sn_ndepo /), cn_dir, 'p4z_sed_init', 'Nutrient atmospheric depositon ', 'nampissed' )
-                                   ALLOCATE( sf_ndepo(1)%fnow(jpi,jpj,1)   )
-         IF( sn_ndepo%ln_tint )    ALLOCATE( sf_ndepo(1)%fdta(jpi,jpj,1,2) )
-         !
-         IF( Agrif_Root() ) THEN   !  Only on the master grid
-            ! Get total input dust ; need to compute total atmospheric supply of N in a year
-            CALL iom_open ( TRIM( sn_ndepo%clname ), numdepo )
-            ntimes_ndep = iom_getszuld( numdepo )
-         ENDIF
-      ENDIF
-
-      ! coastal and island masks
-      ! ------------------------
-      IF( ln_ironsed ) THEN     
-         !
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) '   ==>>>   ln_ironsed=T , computation of an island mask to enhance coastal supply of iron'
-         !
-         ALLOCATE( ironsed(jpi,jpj,jpk) )    ! allocation
-         !
-         CALL iom_open ( TRIM( sn_ironsed%clname ), numiron )
-         ALLOCATE( zcmask(jpi,jpj,jpk) )
-         CALL iom_get  ( numiron, jpdom_data, TRIM( sn_ironsed%clvar ), zcmask(:,:,:), 1 )
-         CALL iom_close( numiron )
-         !
-         ik50 = 5        !  last level where depth less than 50 m
-         DO jk = jpkm1, 1, -1
-            IF( gdept_1d(jk) > 50. )   ik50 = jk - 1
-         END DO
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) ' Level corresponding to 50m depth ',  ik50,' ', gdept_1d(ik50+1)
-         DO jk = 1, ik50
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1
-                  ze3t   = e3t_0(ji,jj,jk)
-                  zsurfc =  e1u(ji,jj) * ( 1. - umask(ji  ,jj  ,jk) )   &
-                          + e1u(ji,jj) * ( 1. - umask(ji-1,jj  ,jk) )   &
-                          + e2v(ji,jj) * ( 1. - vmask(ji  ,jj  ,jk) )   &
-                          + e2v(ji,jj) * ( 1. - vmask(ji  ,jj-1,jk) )
-                  zsurfp = zsurfc * ze3t / e1e2t(ji,jj)
-                  ! estimation of the coastal slope : 5 km off the coast
-                  ze3t2 = ze3t * ze3t
-                  zcslp = SQRT( ( distcoast*distcoast + ze3t2 ) / ze3t2 )
-                  !
-                  zcmask(ji,jj,jk) = zcmask(ji,jj,jk) + zcslp * zsurfp
-               END DO
-            END DO
-         END DO
-         !
-         CALL lbc_lnk( 'p4zsbc', zcmask , 'T', 1. )      ! lateral boundary conditions on cmask   (sign unchanged)
-         !
-         DO jk = 1, jpk
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zexpide   = MIN( 8.,( gdept_n(ji,jj,jk) / 500. )**(-1.5) )
-                  zdenitide = -0.9543 + 0.7662 * LOG( zexpide ) - 0.235 * LOG( zexpide )**2
-                  zcmask(ji,jj,jk) = zcmask(ji,jj,jk) * MIN( 1., EXP( zdenitide ) / 0.5 )
-               END DO
-            END DO
-         END DO
-         ! Coastal supply of iron
-         ! -------------------------
-         ironsed(:,:,jpk) = 0._wp
-         DO jk = 1, jpkm1
-            ironsed(:,:,jk) = sedfeinput * zcmask(:,:,jk) / ( e3t_0(:,:,jk) * rday )
-         END DO
-         DEALLOCATE( zcmask)
-      ENDIF
-      !
-      ! Iron from Hydrothermal vents
-      ! ------------------------
-      IF( ln_hydrofe ) THEN
-         !
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) '   ==>>>   ln_hydrofe=T , Input of iron from hydrothermal vents'
-         !
-         ALLOCATE( hydrofe(jpi,jpj,jpk) )    ! allocation
-         !
-         CALL iom_open ( TRIM( sn_hydrofe%clname ), numhydro )
-         CALL iom_get  ( numhydro, jpdom_data, TRIM( sn_hydrofe%clvar ), hydrofe(:,:,:), 1 )
-         CALL iom_close( numhydro )
-         !
-         DO jk = 1, jpk
-            hydrofe(:,:,jk) = ( hydrofe(:,:,jk) * hratio ) / ( e1e2t(:,:) * e3t_0(:,:,jk) * ryyss + rtrn ) / 1000._wp
-         ENDDO
-         !
-      ENDIF
-      ! 
-      IF( ll_sbc ) CALL p4z_sbc( nit000 ) 
-      !
-      IF(lwp) THEN 
-         WRITE(numout,*)
-         WRITE(numout,*) '    Total input of elements from river supply'
-         WRITE(numout,*) '    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
-         WRITE(numout,*) '    N Supply   : ', rivdininput*rno3*1E3/1E12*14.,' TgN/yr'
-         WRITE(numout,*) '    Si Supply  : ', rivdsiinput*1E3/1E12*28.1    ,' TgSi/yr'
-         WRITE(numout,*) '    P Supply   : ', rivdipinput*1E3*po4r/1E12*31.,' TgP/yr'
-         WRITE(numout,*) '    Alk Supply : ', rivalkinput*1E3/1E12         ,' Teq/yr'
-         WRITE(numout,*) '    DIC Supply : ', rivdicinput*1E3*12./1E12     ,' TgC/yr'
-         WRITE(numout,*) 
-      ENDIF
-      !
-      sedsilfrac = 0.03     ! percentage of silica loss in the sediments
-      sedcalfrac = 0.6      ! percentage of calcite loss in the sediments
-      !
-   END SUBROUTINE p4z_sbc_init
-
-   !!======================================================================
-END MODULE p4zsbc
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zsed.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zsed.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zsed.F90	(revision 13463)
@@ -15,9 +15,8 @@
    USE sms_pisces      !  PISCES Source Minus Sink variables
    USE p4zlim          !  Co-limitations of differents nutrients
-   USE p4zsbc          !  External source of nutrients 
    USE p4zint          !  interpolation and computation of various fields
    USE sed             !  Sediment module
    USE iom             !  I/O manager
-   USE prtctl_trc      !  print control for debugging
+   USE prtctl          !  print control for debugging
 
    IMPLICIT NONE
@@ -25,11 +24,20 @@
 
    PUBLIC   p4z_sed  
+   PUBLIC   p4z_sed_init
    PUBLIC   p4z_sed_alloc
  
+   REAL(wp), PUBLIC ::   nitrfix      !: Nitrogen fixation rate
+   REAL(wp), PUBLIC ::   diazolight   !: Nitrogen fixation sensitivty to light
+   REAL(wp), PUBLIC ::   concfediaz   !: Fe half-saturation Cste for diazotrophs
+
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: nitrpot    !: Nitrogen fixation 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:  ) :: sdenit     !: Nitrate reduction in the sediments
-   REAL(wp) :: r1_rday                  !: inverse of rday
-   LOGICAL, SAVE :: lk_sed
-
+   !
+   REAL(wp), SAVE :: r1_rday          
+   REAL(wp), SAVE :: sedsilfrac, sedcalfrac
+
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -39,5 +47,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_sed( kt, knt )
+   SUBROUTINE p4z_sed( kt, knt, Kbb, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_sed  ***
@@ -51,7 +59,8 @@
       !
       INTEGER, INTENT(in) ::   kt, knt ! ocean time step
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Krhs  ! time level indices
       INTEGER  ::  ji, jj, jk, ikt
       REAL(wp) ::  zrivalk, zrivsil, zrivno3
-      REAL(wp) ::  zwflux, zlim, zfact, zfactcal
+      REAL(wp) ::  zlim, zfact, zfactcal
       REAL(wp) ::  zo2, zno3, zflx, zpdenit, z1pdenit, zolimit
       REAL(wp) ::  zsiloss, zcaloss, zws3, zws4, zwsc, zdep
@@ -66,20 +75,9 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: zsoufer, zlight
       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: ztrpo4, ztrdop, zirondep, zpdep
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:  ) :: zsidep, zironice
       !!---------------------------------------------------------------------
       !
       IF( ln_timing )  CALL timing_start('p4z_sed')
       !
-      IF( kt == nittrc000 .AND. knt == 1 )   THEN
-          r1_rday  = 1. / rday
-          IF (ln_sediment .AND. ln_sed_2way) THEN
-             lk_sed = .TRUE.
-          ELSE
-             lk_sed = .FALSE.
-          ENDIF
-      ENDIF
-      !
-      IF( kt == nittrc000 .AND. knt == 1 )   r1_rday  = 1. / rday
-      !
+
       ! Allocate temporary workspace
       ALLOCATE( ztrpo4(jpi,jpj,jpk) )
@@ -93,167 +91,35 @@
       zsedc   (:,:) = 0.e0
 
-      ! Iron input/uptake due to sea ice : Crude parameterization based on Lancelot et al.
-      ! ----------------------------------------------------
-      IF( ln_ironice ) THEN  
-         !                                              
-         ALLOCATE( zironice(jpi,jpj) )
-         !                                              
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zdep    = rfact2 / e3t_n(ji,jj,1)
-               zwflux  = fmmflx(ji,jj) / 1000._wp
-               zironice(ji,jj) =  MAX( -0.99 * trb(ji,jj,1,jpfer), -zwflux * icefeinput * zdep )
-            END DO
-         END DO
-         !
-         tra(:,:,1,jpfer) = tra(:,:,1,jpfer) + zironice(:,:) 
-         ! 
-         IF( lk_iomput .AND. knt == nrdttrc .AND. iom_use( "Ironice" ) )   &
-            &   CALL iom_put( "Ironice", zironice(:,:) * 1.e+3 * rfact2r * e3t_n(:,:,1) * tmask(:,:,1) ) ! iron flux from ice
-         !
-         DEALLOCATE( zironice )
-         !                                              
-      ENDIF
-
-      ! Add the external input of nutrients from dust deposition
-      ! ----------------------------------------------------------
-      IF( ln_dust ) THEN
-         !                                              
-         ALLOCATE( zsidep(jpi,jpj), zpdep(jpi,jpj,jpk), zirondep(jpi,jpj,jpk) )
-         !                                              ! Iron and Si deposition at the surface
-         IF( ln_solub ) THEN
-            zirondep(:,:,1) = solub(:,:) * dust(:,:) * mfrac * rfact2 / e3t_n(:,:,1) / 55.85 + 3.e-10 * r1_ryyss 
-         ELSE
-            zirondep(:,:,1) = dustsolub  * dust(:,:) * mfrac * rfact2 / e3t_n(:,:,1) / 55.85 + 3.e-10 * r1_ryyss 
-         ENDIF
-         zsidep(:,:)   = 8.8 * 0.075 * dust(:,:) * mfrac * rfact2 / e3t_n(:,:,1) / 28.1 
-         zpdep (:,:,1) = 0.1 * 0.021 * dust(:,:) * mfrac * rfact2 / e3t_n(:,:,1) / 31. / po4r 
-         !                                              ! Iron solubilization of particles in the water column
-         !                                              ! dust in kg/m2/s ---> 1/55.85 to put in mol/Fe ;  wdust in m/j
-         zwdust = 0.03 * rday / ( wdust * 55.85 ) / ( 270. * rday )
-         DO jk = 2, jpkm1
-            zirondep(:,:,jk) = dust(:,:) * mfrac * zwdust * rfact2 * EXP( -gdept_n(:,:,jk) / 540. )
-            zpdep   (:,:,jk) = zirondep(:,:,jk) * 0.023
-         END DO
-         !                                              ! Iron solubilization of particles in the water column
-         tra(:,:,1,jpsil) = tra(:,:,1,jpsil) + zsidep  (:,:)
-         DO jk = 1, jpkm1
-            tra(:,:,jk,jppo4) = tra(:,:,jk,jppo4) + zpdep   (:,:,jk)
-            tra(:,:,jk,jpfer) = tra(:,:,jk,jpfer) + zirondep(:,:,jk) 
-         ENDDO
-         ! 
-         IF( lk_iomput ) THEN
-            IF( knt == nrdttrc ) THEN
-                IF( iom_use( "Irondep" ) )   &
-                &  CALL iom_put( "Irondep", zirondep(:,:,1) * 1.e+3 * rfact2r * e3t_n(:,:,1) * tmask(:,:,1) ) ! surface downward dust depo of iron
-                IF( iom_use( "pdust" ) )   &
-                &  CALL iom_put( "pdust"  , dust(:,:) / ( wdust * rday )  * tmask(:,:,1) ) ! dust concentration at surface
-            ENDIF
-         ENDIF
-         DEALLOCATE( zsidep, zpdep, zirondep )
-         !                                              
-      ENDIF
-     
-      ! Add the external input of nutrients from river
-      ! ----------------------------------------------------------
-      IF( ln_river ) THEN
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               DO jk = 1, nk_rnf(ji,jj)
-                  tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) +  rivdip(ji,jj) * rfact2
-                  tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) +  rivdin(ji,jj) * rfact2
-                  tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) +  rivdic(ji,jj) * 5.e-5 * rfact2
-                  tra(ji,jj,jk,jpsil) = tra(ji,jj,jk,jpsil) +  rivdsi(ji,jj) * rfact2
-                  tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) +  rivdic(ji,jj) * rfact2
-                  tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) +  ( rivalk(ji,jj) - rno3 * rivdin(ji,jj) ) * rfact2
-                  tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) +  rivdoc(ji,jj) * rfact2
-               ENDDO
-            ENDDO
-         ENDDO
-         IF (ln_ligand) THEN
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  DO jk = 1, nk_rnf(ji,jj)
-                     tra(ji,jj,jk,jplgw) = tra(ji,jj,jk,jplgw) +  rivdic(ji,jj) * 5.e-5 * rfact2
-                  ENDDO
-               ENDDO
-            ENDDO
-         ENDIF
-         IF( ln_p5z ) THEN
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  DO jk = 1, nk_rnf(ji,jj)
-                     tra(ji,jj,jk,jpdop) = tra(ji,jj,jk,jpdop) + rivdop(ji,jj) * rfact2
-                     tra(ji,jj,jk,jpdon) = tra(ji,jj,jk,jpdon) + rivdon(ji,jj) * rfact2
-                  ENDDO
-               ENDDO
-            ENDDO
-         ENDIF
-      ENDIF
-      
-      ! Add the external input of nutrients from nitrogen deposition
-      ! ----------------------------------------------------------
-      IF( ln_ndepo ) THEN
-         tra(:,:,1,jpno3) = tra(:,:,1,jpno3) + nitdep(:,:) * rfact2
-         tra(:,:,1,jptal) = tra(:,:,1,jptal) - rno3 * nitdep(:,:) * rfact2
-      ENDIF
-
-      ! Add the external input of iron from hydrothermal vents
-      ! ------------------------------------------------------
-      IF( ln_hydrofe ) THEN
-            tra(:,:,:,jpfer) = tra(:,:,:,jpfer) + hydrofe(:,:,:) * rfact2
-         IF( ln_ligand ) THEN
-            tra(:,:,:,jplgw) = tra(:,:,:,jplgw) + ( hydrofe(:,:,:) * lgw_rath ) * rfact2
-         ENDIF
-         !
-         IF( lk_iomput .AND. knt == nrdttrc .AND. iom_use( "HYDR" ) )   &
-            &   CALL iom_put( "HYDR", hydrofe(:,:,:) * 1.e+3 * tmask(:,:,:) ) ! hydrothermal iron input
-      ENDIF
-
-      ! OA: Warning, the following part is necessary to avoid CFL problems above the sediments
-      ! --------------------------------------------------------------------
-      DO jj = 1, jpj
-         DO ji = 1, jpi
+      IF( .NOT.lk_sed ) THEN
+         ! OA: Warning, the following part is necessary to avoid CFL problems above the sediments
+         ! --------------------------------------------------------------------
+         DO_2D( 1, 1, 1, 1 )
             ikt  = mbkt(ji,jj)
-            zdep = e3t_n(ji,jj,ikt) / xstep
+            zdep = e3t(ji,jj,ikt,Kmm) / xstep
             zwsbio4(ji,jj) = MIN( 0.99 * zdep, wsbio4(ji,jj,ikt) )
             zwsbio3(ji,jj) = MIN( 0.99 * zdep, wsbio3(ji,jj,ikt) )
-         END DO
-      END DO
-      !
-      IF( .NOT.lk_sed ) THEN
-!
-         ! Add the external input of iron from sediment mobilization
-         ! ------------------------------------------------------
-         IF( ln_ironsed ) THEN
-                            tra(:,:,:,jpfer) = tra(:,:,:,jpfer) + ironsed(:,:,:) * rfact2
-            !
-            IF( lk_iomput .AND. knt == nrdttrc .AND. iom_use( "Ironsed" ) )   &
-               &   CALL iom_put( "Ironsed", ironsed(:,:,:) * 1.e+3 * tmask(:,:,:) ) ! iron inputs from sediments
-         ENDIF
+         END_2D
 
          ! Computation of the sediment denitrification proportion: The metamodel from midlleburg (2006) is being used
          ! Computation of the fraction of organic matter that is permanently buried from Dunne's model
          ! -------------------------------------------------------
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-              IF( tmask(ji,jj,1) == 1 ) THEN
-                 ikt = mbkt(ji,jj)
-                 zflx = (  trb(ji,jj,ikt,jpgoc) * zwsbio4(ji,jj)   &
-                   &     + trb(ji,jj,ikt,jppoc) * zwsbio3(ji,jj) )  * 1E3 * 1E6 / 1E4
-                 zflx  = LOG10( MAX( 1E-3, zflx ) )
-                 zo2   = LOG10( MAX( 10. , trb(ji,jj,ikt,jpoxy) * 1E6 ) )
-                 zno3  = LOG10( MAX( 1.  , trb(ji,jj,ikt,jpno3) * 1E6 * rno3 ) )
-                 zdep  = LOG10( gdepw_n(ji,jj,ikt+1) )
-                 zdenit2d(ji,jj) = -2.2567 - 1.185 * zflx - 0.221 * zflx**2 - 0.3995 * zno3 * zo2 + 1.25 * zno3    &
-                   &                + 0.4721 * zo2 - 0.0996 * zdep + 0.4256 * zflx * zo2
-                 zdenit2d(ji,jj) = 10.0**( zdenit2d(ji,jj) )
-                   !
-                 zflx = (  trb(ji,jj,ikt,jpgoc) * zwsbio4(ji,jj)   &
-                   &     + trb(ji,jj,ikt,jppoc) * zwsbio3(ji,jj) ) * 1E6
-                 zbureff(ji,jj) = 0.013 + 0.53 * zflx**2 / ( 7.0 + zflx )**2
-              ENDIF
-            END DO
-         END DO 
+         DO_2D( 1, 1, 1, 1 )
+           IF( tmask(ji,jj,1) == 1 ) THEN
+              ikt = mbkt(ji,jj)
+              zflx = (  tr(ji,jj,ikt,jpgoc,Kbb) * zwsbio4(ji,jj)   &
+                &     + tr(ji,jj,ikt,jppoc,Kbb) * zwsbio3(ji,jj) )  * 1E3 * 1E6 / 1E4
+              zflx  = LOG10( MAX( 1E-3, zflx ) )
+              zo2   = LOG10( MAX( 10. , tr(ji,jj,ikt,jpoxy,Kbb) * 1E6 ) )
+              zno3  = LOG10( MAX( 1.  , tr(ji,jj,ikt,jpno3,Kbb) * 1E6 * rno3 ) )
+              zdep  = LOG10( gdepw(ji,jj,ikt+1,Kmm) )
+              zdenit2d(ji,jj) = -2.2567 - 1.185 * zflx - 0.221 * zflx**2 - 0.3995 * zno3 * zo2 + 1.25 * zno3    &
+                &                + 0.4721 * zo2 - 0.0996 * zdep + 0.4256 * zflx * zo2
+              zdenit2d(ji,jj) = 10.0**( zdenit2d(ji,jj) )
+                !
+              zflx = (  tr(ji,jj,ikt,jpgoc,Kbb) * zwsbio4(ji,jj)   &
+                &     + tr(ji,jj,ikt,jppoc,Kbb) * zwsbio3(ji,jj) ) * 1E6
+              zbureff(ji,jj) = 0.013 + 0.53 * zflx**2 / ( 7.0 + zflx )**2
+           ENDIF
+         END_2D
          !
       ENDIF
@@ -264,64 +130,56 @@
       IF( .NOT.lk_sed )  zrivsil = 1._wp - sedsilfrac
 
-      DO jj = 1, jpj
-         DO ji = 1, jpi
+      DO_2D( 1, 1, 1, 1 )
+         ikt  = mbkt(ji,jj)
+         zdep = xstep / e3t(ji,jj,ikt,Kmm) 
+         zwsc = zwsbio4(ji,jj) * zdep
+         zsiloss = tr(ji,jj,ikt,jpgsi,Kbb) * zwsc
+         zcaloss = tr(ji,jj,ikt,jpcal,Kbb) * zwsc
+         !
+         tr(ji,jj,ikt,jpgsi,Krhs) = tr(ji,jj,ikt,jpgsi,Krhs) - zsiloss
+         tr(ji,jj,ikt,jpcal,Krhs) = tr(ji,jj,ikt,jpcal,Krhs) - zcaloss
+      END_2D
+      !
+      IF( .NOT.lk_sed ) THEN
+         DO_2D( 1, 1, 1, 1 )
             ikt  = mbkt(ji,jj)
-            zdep = xstep / e3t_n(ji,jj,ikt) 
+            zdep = xstep / e3t(ji,jj,ikt,Kmm) 
             zwsc = zwsbio4(ji,jj) * zdep
-            zsiloss = trb(ji,jj,ikt,jpgsi) * zwsc
-            zcaloss = trb(ji,jj,ikt,jpcal) * zwsc
+            zsiloss = tr(ji,jj,ikt,jpgsi,Kbb) * zwsc
+            zcaloss = tr(ji,jj,ikt,jpcal,Kbb) * zwsc
+            tr(ji,jj,ikt,jpsil,Krhs) = tr(ji,jj,ikt,jpsil,Krhs) + zsiloss * zrivsil 
             !
-            tra(ji,jj,ikt,jpgsi) = tra(ji,jj,ikt,jpgsi) - zsiloss
-            tra(ji,jj,ikt,jpcal) = tra(ji,jj,ikt,jpcal) - zcaloss
-         END DO
-      END DO
-      !
-      IF( .NOT.lk_sed ) THEN
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ikt  = mbkt(ji,jj)
-               zdep = xstep / e3t_n(ji,jj,ikt) 
-               zwsc = zwsbio4(ji,jj) * zdep
-               zsiloss = trb(ji,jj,ikt,jpgsi) * zwsc
-               zcaloss = trb(ji,jj,ikt,jpcal) * zwsc
-               tra(ji,jj,ikt,jpsil) = tra(ji,jj,ikt,jpsil) + zsiloss * zrivsil 
-               !
-               zfactcal = MIN( excess(ji,jj,ikt), 0.2 )
-               zfactcal = MIN( 1., 1.3 * ( 0.2 - zfactcal ) / ( 0.4 - zfactcal ) )
-               zrivalk  = sedcalfrac * zfactcal
-               tra(ji,jj,ikt,jptal) =  tra(ji,jj,ikt,jptal) + zcaloss * zrivalk * 2.0
-               tra(ji,jj,ikt,jpdic) =  tra(ji,jj,ikt,jpdic) + zcaloss * zrivalk
-               zsedcal(ji,jj) = (1.0 - zrivalk) * zcaloss * e3t_n(ji,jj,ikt) 
-               zsedsi (ji,jj) = (1.0 - zrivsil) * zsiloss * e3t_n(ji,jj,ikt) 
-            END DO
-         END DO
-      ENDIF
-      !
-      DO jj = 1, jpj
-         DO ji = 1, jpi
+            zfactcal = MIN( excess(ji,jj,ikt), 0.2 )
+            zfactcal = MIN( 1., 1.3 * ( 0.2 - zfactcal ) / ( 0.4 - zfactcal ) )
+            zrivalk  = sedcalfrac * zfactcal
+            tr(ji,jj,ikt,jptal,Krhs) =  tr(ji,jj,ikt,jptal,Krhs) + zcaloss * zrivalk * 2.0
+            tr(ji,jj,ikt,jpdic,Krhs) =  tr(ji,jj,ikt,jpdic,Krhs) + zcaloss * zrivalk
+            zsedcal(ji,jj) = (1.0 - zrivalk) * zcaloss * e3t(ji,jj,ikt,Kmm) 
+            zsedsi (ji,jj) = (1.0 - zrivsil) * zsiloss * e3t(ji,jj,ikt,Kmm) 
+         END_2D
+      ENDIF
+      !
+      DO_2D( 1, 1, 1, 1 )
+         ikt  = mbkt(ji,jj)
+         zdep = xstep / e3t(ji,jj,ikt,Kmm) 
+         zws4 = zwsbio4(ji,jj) * zdep
+         zws3 = zwsbio3(ji,jj) * zdep
+         tr(ji,jj,ikt,jpgoc,Krhs) = tr(ji,jj,ikt,jpgoc,Krhs) - tr(ji,jj,ikt,jpgoc,Kbb) * zws4 
+         tr(ji,jj,ikt,jppoc,Krhs) = tr(ji,jj,ikt,jppoc,Krhs) - tr(ji,jj,ikt,jppoc,Kbb) * zws3
+         tr(ji,jj,ikt,jpbfe,Krhs) = tr(ji,jj,ikt,jpbfe,Krhs) - tr(ji,jj,ikt,jpbfe,Kbb) * zws4
+         tr(ji,jj,ikt,jpsfe,Krhs) = tr(ji,jj,ikt,jpsfe,Krhs) - tr(ji,jj,ikt,jpsfe,Kbb) * zws3
+      END_2D
+      !
+      IF( ln_p5z ) THEN
+         DO_2D( 1, 1, 1, 1 )
             ikt  = mbkt(ji,jj)
-            zdep = xstep / e3t_n(ji,jj,ikt) 
+            zdep = xstep / e3t(ji,jj,ikt,Kmm) 
             zws4 = zwsbio4(ji,jj) * zdep
             zws3 = zwsbio3(ji,jj) * zdep
-            tra(ji,jj,ikt,jpgoc) = tra(ji,jj,ikt,jpgoc) - trb(ji,jj,ikt,jpgoc) * zws4 
-            tra(ji,jj,ikt,jppoc) = tra(ji,jj,ikt,jppoc) - trb(ji,jj,ikt,jppoc) * zws3
-            tra(ji,jj,ikt,jpbfe) = tra(ji,jj,ikt,jpbfe) - trb(ji,jj,ikt,jpbfe) * zws4
-            tra(ji,jj,ikt,jpsfe) = tra(ji,jj,ikt,jpsfe) - trb(ji,jj,ikt,jpsfe) * zws3
-         END DO
-      END DO
-      !
-      IF( ln_p5z ) THEN
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ikt  = mbkt(ji,jj)
-               zdep = xstep / e3t_n(ji,jj,ikt) 
-               zws4 = zwsbio4(ji,jj) * zdep
-               zws3 = zwsbio3(ji,jj) * zdep
-               tra(ji,jj,ikt,jpgon) = tra(ji,jj,ikt,jpgon) - trb(ji,jj,ikt,jpgon) * zws4
-               tra(ji,jj,ikt,jppon) = tra(ji,jj,ikt,jppon) - trb(ji,jj,ikt,jppon) * zws3
-               tra(ji,jj,ikt,jpgop) = tra(ji,jj,ikt,jpgop) - trb(ji,jj,ikt,jpgop) * zws4
-               tra(ji,jj,ikt,jppop) = tra(ji,jj,ikt,jppop) - trb(ji,jj,ikt,jppop) * zws3
-            END DO
-         END DO
+            tr(ji,jj,ikt,jpgon,Krhs) = tr(ji,jj,ikt,jpgon,Krhs) - tr(ji,jj,ikt,jpgon,Kbb) * zws4
+            tr(ji,jj,ikt,jppon,Krhs) = tr(ji,jj,ikt,jppon,Krhs) - tr(ji,jj,ikt,jppon,Kbb) * zws3
+            tr(ji,jj,ikt,jpgop,Krhs) = tr(ji,jj,ikt,jpgop,Krhs) - tr(ji,jj,ikt,jpgop,Kbb) * zws4
+            tr(ji,jj,ikt,jppop,Krhs) = tr(ji,jj,ikt,jppop,Krhs) - tr(ji,jj,ikt,jppop,Kbb) * zws3
+         END_2D
       ENDIF
 
@@ -329,32 +187,30 @@
          ! The 0.5 factor in zpdenit is to avoid negative NO3 concentration after
          ! denitrification in the sediments. Not very clever, but simpliest option.
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ikt  = mbkt(ji,jj)
-               zdep = xstep / e3t_n(ji,jj,ikt) 
-               zws4 = zwsbio4(ji,jj) * zdep
-               zws3 = zwsbio3(ji,jj) * zdep
-               zrivno3 = 1. - zbureff(ji,jj)
-               zwstpoc = trb(ji,jj,ikt,jpgoc) * zws4 + trb(ji,jj,ikt,jppoc) * zws3
-               zpdenit  = MIN( 0.5 * ( trb(ji,jj,ikt,jpno3) - rtrn ) / rdenit, zdenit2d(ji,jj) * zwstpoc * zrivno3 )
-               z1pdenit = zwstpoc * zrivno3 - zpdenit
-               zolimit = MIN( ( trb(ji,jj,ikt,jpoxy) - rtrn ) / o2ut, z1pdenit * ( 1.- nitrfac(ji,jj,ikt) ) )
-               tra(ji,jj,ikt,jpdoc) = tra(ji,jj,ikt,jpdoc) + z1pdenit - zolimit
-               tra(ji,jj,ikt,jppo4) = tra(ji,jj,ikt,jppo4) + zpdenit + zolimit
-               tra(ji,jj,ikt,jpnh4) = tra(ji,jj,ikt,jpnh4) + zpdenit + zolimit
-               tra(ji,jj,ikt,jpno3) = tra(ji,jj,ikt,jpno3) - rdenit * zpdenit
-               tra(ji,jj,ikt,jpoxy) = tra(ji,jj,ikt,jpoxy) - zolimit * o2ut
-               tra(ji,jj,ikt,jptal) = tra(ji,jj,ikt,jptal) + rno3 * (zolimit + (1.+rdenit) * zpdenit )
-               tra(ji,jj,ikt,jpdic) = tra(ji,jj,ikt,jpdic) + zpdenit + zolimit 
-               sdenit(ji,jj) = rdenit * zpdenit * e3t_n(ji,jj,ikt)
-               zsedc(ji,jj)   = (1. - zrivno3) * zwstpoc * e3t_n(ji,jj,ikt)
-               IF( ln_p5z ) THEN
-                  zwstpop              = trb(ji,jj,ikt,jpgop) * zws4 + trb(ji,jj,ikt,jppop) * zws3
-                  zwstpon              = trb(ji,jj,ikt,jpgon) * zws4 + trb(ji,jj,ikt,jppon) * zws3
-                  tra(ji,jj,ikt,jpdon) = tra(ji,jj,ikt,jpdon) + ( z1pdenit - zolimit ) * zwstpon / (zwstpoc + rtrn)
-                  tra(ji,jj,ikt,jpdop) = tra(ji,jj,ikt,jpdop) + ( z1pdenit - zolimit ) * zwstpop / (zwstpoc + rtrn)
-               ENDIF
-            END DO
-         END DO
+         DO_2D( 1, 1, 1, 1 )
+            ikt  = mbkt(ji,jj)
+            zdep = xstep / e3t(ji,jj,ikt,Kmm) 
+            zws4 = zwsbio4(ji,jj) * zdep
+            zws3 = zwsbio3(ji,jj) * zdep
+            zrivno3 = 1. - zbureff(ji,jj)
+            zwstpoc = tr(ji,jj,ikt,jpgoc,Kbb) * zws4 + tr(ji,jj,ikt,jppoc,Kbb) * zws3
+            zpdenit  = MIN( 0.5 * ( tr(ji,jj,ikt,jpno3,Kbb) - rtrn ) / rdenit, zdenit2d(ji,jj) * zwstpoc * zrivno3 )
+            z1pdenit = zwstpoc * zrivno3 - zpdenit
+            zolimit = MIN( ( tr(ji,jj,ikt,jpoxy,Kbb) - rtrn ) / o2ut, z1pdenit * ( 1.- nitrfac(ji,jj,ikt) ) )
+            tr(ji,jj,ikt,jpdoc,Krhs) = tr(ji,jj,ikt,jpdoc,Krhs) + z1pdenit - zolimit
+            tr(ji,jj,ikt,jppo4,Krhs) = tr(ji,jj,ikt,jppo4,Krhs) + zpdenit + zolimit
+            tr(ji,jj,ikt,jpnh4,Krhs) = tr(ji,jj,ikt,jpnh4,Krhs) + zpdenit + zolimit
+            tr(ji,jj,ikt,jpno3,Krhs) = tr(ji,jj,ikt,jpno3,Krhs) - rdenit * zpdenit
+            tr(ji,jj,ikt,jpoxy,Krhs) = tr(ji,jj,ikt,jpoxy,Krhs) - zolimit * o2ut
+            tr(ji,jj,ikt,jptal,Krhs) = tr(ji,jj,ikt,jptal,Krhs) + rno3 * (zolimit + (1.+rdenit) * zpdenit )
+            tr(ji,jj,ikt,jpdic,Krhs) = tr(ji,jj,ikt,jpdic,Krhs) + zpdenit + zolimit 
+            sdenit(ji,jj) = rdenit * zpdenit * e3t(ji,jj,ikt,Kmm)
+            zsedc(ji,jj)   = (1. - zrivno3) * zwstpoc * e3t(ji,jj,ikt,Kmm)
+            IF( ln_p5z ) THEN
+               zwstpop              = tr(ji,jj,ikt,jpgop,Kbb) * zws4 + tr(ji,jj,ikt,jppop,Kbb) * zws3
+               zwstpon              = tr(ji,jj,ikt,jpgon,Kbb) * zws4 + tr(ji,jj,ikt,jppon,Kbb) * zws3
+               tr(ji,jj,ikt,jpdon,Krhs) = tr(ji,jj,ikt,jpdon,Krhs) + ( z1pdenit - zolimit ) * zwstpon / (zwstpoc + rtrn)
+               tr(ji,jj,ikt,jpdop,Krhs) = tr(ji,jj,ikt,jpdop,Krhs) + ( z1pdenit - zolimit ) * zwstpop / (zwstpoc + rtrn)
+            ENDIF
+         END_2D
        ENDIF
 
@@ -368,44 +224,36 @@
       ENDDO
       IF( ln_p4z ) THEN
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  !                      ! Potential nitrogen fixation dependant on temperature and iron
-                  ztemp = tsn(ji,jj,jk,jp_tem)
-                  zmudia = MAX( 0.,-0.001096*ztemp**2 + 0.057*ztemp -0.637 ) * 7.625
-                  !       Potential nitrogen fixation dependant on temperature and iron
-                  xdianh4 = trb(ji,jj,jk,jpnh4) / ( concnnh4 + trb(ji,jj,jk,jpnh4) )
-                  xdiano3 = trb(ji,jj,jk,jpno3) / ( concnno3 + trb(ji,jj,jk,jpno3) ) * (1. - xdianh4)
-                  zlim = ( 1.- xdiano3 - xdianh4 )
-                  IF( zlim <= 0.1 )   zlim = 0.01
-                  zfact = zlim * rfact2
-                  ztrfer = biron(ji,jj,jk) / ( concfediaz + biron(ji,jj,jk) )
-                  ztrpo4(ji,jj,jk) = trb(ji,jj,jk,jppo4) / ( 1E-6 + trb(ji,jj,jk,jppo4) )
-                  ztrdp = ztrpo4(ji,jj,jk)
-                  nitrpot(ji,jj,jk) =  zmudia * r1_rday * zfact * MIN( ztrfer, ztrdp ) * zlight(ji,jj,jk)
-               END DO
-            END DO
-         END DO
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+            !                      ! Potential nitrogen fixation dependant on temperature and iron
+            ztemp = ts(ji,jj,jk,jp_tem,Kmm)
+            zmudia = MAX( 0.,-0.001096*ztemp**2 + 0.057*ztemp -0.637 ) * 7.625
+            !       Potential nitrogen fixation dependant on temperature and iron
+            xdianh4 = tr(ji,jj,jk,jpnh4,Kbb) / ( concnnh4 + tr(ji,jj,jk,jpnh4,Kbb) )
+            xdiano3 = tr(ji,jj,jk,jpno3,Kbb) / ( concnno3 + tr(ji,jj,jk,jpno3,Kbb) ) * (1. - xdianh4)
+            zlim = ( 1.- xdiano3 - xdianh4 )
+            IF( zlim <= 0.1 )   zlim = 0.01
+            zfact = zlim * rfact2
+            ztrfer = biron(ji,jj,jk) / ( concfediaz + biron(ji,jj,jk) )
+            ztrpo4(ji,jj,jk) = tr(ji,jj,jk,jppo4,Kbb) / ( 1E-6 + tr(ji,jj,jk,jppo4,Kbb) )
+            ztrdp = ztrpo4(ji,jj,jk)
+            nitrpot(ji,jj,jk) =  zmudia * r1_rday * zfact * MIN( ztrfer, ztrdp ) * zlight(ji,jj,jk)
+         END_3D
       ELSE       ! p5z
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  !                      ! Potential nitrogen fixation dependant on temperature and iron
-                  ztemp = tsn(ji,jj,jk,jp_tem)
-                  zmudia = MAX( 0.,-0.001096*ztemp**2 + 0.057*ztemp -0.637 ) * 7.625
-                  !       Potential nitrogen fixation dependant on temperature and iron
-                  xdianh4 = trb(ji,jj,jk,jpnh4) / ( concnnh4 + trb(ji,jj,jk,jpnh4) )
-                  xdiano3 = trb(ji,jj,jk,jpno3) / ( concnno3 + trb(ji,jj,jk,jpno3) ) * (1. - xdianh4)
-                  zlim = ( 1.- xdiano3 - xdianh4 )
-                  IF( zlim <= 0.1 )   zlim = 0.01
-                  zfact = zlim * rfact2
-                  ztrfer = biron(ji,jj,jk) / ( concfediaz + biron(ji,jj,jk) )
-                  ztrpo4(ji,jj,jk) = trb(ji,jj,jk,jppo4) / ( 1E-6 + trb(ji,jj,jk,jppo4) )
-                  ztrdop(ji,jj,jk) = trb(ji,jj,jk,jpdop) / ( 1E-6 + trb(ji,jj,jk,jpdop) ) * (1. - ztrpo4(ji,jj,jk))
-                  ztrdp = ztrpo4(ji,jj,jk) + ztrdop(ji,jj,jk)
-                  nitrpot(ji,jj,jk) =  zmudia * r1_rday * zfact * MIN( ztrfer, ztrdp ) * zlight(ji,jj,jk)
-               END DO
-            END DO
-         END DO
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+            !                      ! Potential nitrogen fixation dependant on temperature and iron
+            ztemp = ts(ji,jj,jk,jp_tem,Kmm)
+            zmudia = MAX( 0.,-0.001096*ztemp**2 + 0.057*ztemp -0.637 ) * 7.625
+            !       Potential nitrogen fixation dependant on temperature and iron
+            xdianh4 = tr(ji,jj,jk,jpnh4,Kbb) / ( concnnh4 + tr(ji,jj,jk,jpnh4,Kbb) )
+            xdiano3 = tr(ji,jj,jk,jpno3,Kbb) / ( concnno3 + tr(ji,jj,jk,jpno3,Kbb) ) * (1. - xdianh4)
+            zlim = ( 1.- xdiano3 - xdianh4 )
+            IF( zlim <= 0.1 )   zlim = 0.01
+            zfact = zlim * rfact2
+            ztrfer = biron(ji,jj,jk) / ( concfediaz + biron(ji,jj,jk) )
+            ztrpo4(ji,jj,jk) = tr(ji,jj,jk,jppo4,Kbb) / ( 1E-6 + tr(ji,jj,jk,jppo4,Kbb) )
+            ztrdop(ji,jj,jk) = tr(ji,jj,jk,jpdop,Kbb) / ( 1E-6 + tr(ji,jj,jk,jpdop,Kbb) ) * (1. - ztrpo4(ji,jj,jk))
+            ztrdp = ztrpo4(ji,jj,jk) + ztrdop(ji,jj,jk)
+            nitrpot(ji,jj,jk) =  zmudia * r1_rday * zfact * MIN( ztrfer, ztrdp ) * zlight(ji,jj,jk)
+         END_3D
       ENDIF
 
@@ -413,77 +261,60 @@
       ! ----------------------------------------
       IF( ln_p4z ) THEN
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zfact = nitrpot(ji,jj,jk) * nitrfix
-                  tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + zfact / 3.0
-                  tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) + rno3 * zfact / 3.0
-                  tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) - zfact * 2.0 / 3.0
-                  tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + zfact * 1.0 / 3.0
-                  tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zfact * 1.0 / 3.0 * 2.0 / 3.0
-                  tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) + zfact * 1.0 / 3.0 * 1.0 / 3.0
-                  tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) + ( o2ut + o2nit ) * zfact * 2.0 / 3.0 + o2nit * zfact / 3.0
-                  tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) - 30E-6 * zfact * 1.0 / 3.0
-                  tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + 30E-6 * zfact * 1.0 / 3.0 * 2.0 / 3.0
-                  tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + 30E-6 * zfact * 1.0 / 3.0 * 1.0 / 3.0
-                  tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + 0.002 * 4E-10 * zsoufer(ji,jj,jk) * rfact2 / rday
-                  tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) + concdnh4 / ( concdnh4 + trb(ji,jj,jk,jppo4) ) &
-                  &                     * 0.001 * trb(ji,jj,jk,jpdoc) * xstep
-              END DO
-            END DO 
-         END DO
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+            zfact = nitrpot(ji,jj,jk) * nitrfix
+            tr(ji,jj,jk,jpnh4,Krhs) = tr(ji,jj,jk,jpnh4,Krhs) + zfact / 3.0
+            tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) + rno3 * zfact / 3.0
+            tr(ji,jj,jk,jppo4,Krhs) = tr(ji,jj,jk,jppo4,Krhs) - zfact * 2.0 / 3.0
+            tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) + zfact * 1.0 / 3.0
+            tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) + zfact * 1.0 / 3.0 * 2.0 / 3.0
+            tr(ji,jj,jk,jpgoc,Krhs) = tr(ji,jj,jk,jpgoc,Krhs) + zfact * 1.0 / 3.0 * 1.0 / 3.0
+            tr(ji,jj,jk,jpoxy,Krhs) = tr(ji,jj,jk,jpoxy,Krhs) + ( o2ut + o2nit ) * zfact * 2.0 / 3.0 + o2nit * zfact / 3.0
+            tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) - 30E-6 * zfact * 1.0 / 3.0
+            tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) + 30E-6 * zfact * 1.0 / 3.0 * 2.0 / 3.0
+            tr(ji,jj,jk,jpbfe,Krhs) = tr(ji,jj,jk,jpbfe,Krhs) + 30E-6 * zfact * 1.0 / 3.0 * 1.0 / 3.0
+            tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) + 0.002 * 4E-10 * zsoufer(ji,jj,jk) * rfact2 / rday
+            tr(ji,jj,jk,jppo4,Krhs) = tr(ji,jj,jk,jppo4,Krhs) + concdnh4 / ( concdnh4 + tr(ji,jj,jk,jppo4,Kbb) ) &
+            &                     * 0.001 * tr(ji,jj,jk,jpdoc,Kbb) * xstep
+         END_3D
       ELSE    ! p5z
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zfact = nitrpot(ji,jj,jk) * nitrfix
-                  tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + zfact / 3.0
-                  tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) + rno3 * zfact / 3.0
-                  tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) - 16.0 / 46.0 * zfact * ( 1.0 - 1.0 / 3.0 ) &
-                  &                     * ztrpo4(ji,jj,jk) / (ztrpo4(ji,jj,jk) + ztrdop(ji,jj,jk) + rtrn)
-                  tra(ji,jj,jk,jpdon) = tra(ji,jj,jk,jpdon) + zfact * 1.0 / 3.0
-                  tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + zfact * 1.0 / 3.0
-                  tra(ji,jj,jk,jpdop) = tra(ji,jj,jk,jpdop) + 16.0 / 46.0 * zfact / 3.0  &
-                  &                     - 16.0 / 46.0 * zfact * ztrdop(ji,jj,jk)   &
-                  &                     / (ztrpo4(ji,jj,jk) + ztrdop(ji,jj,jk) + rtrn)
-                  tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zfact * 1.0 / 3.0 * 2.0 / 3.0
-                  tra(ji,jj,jk,jppon) = tra(ji,jj,jk,jppon) + zfact * 1.0 / 3.0 * 2.0 /3.0
-                  tra(ji,jj,jk,jppop) = tra(ji,jj,jk,jppop) + 16.0 / 46.0 * zfact * 1.0 / 3.0 * 2.0 /3.0
-                  tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) + zfact * 1.0 / 3.0 * 1.0 / 3.0
-                  tra(ji,jj,jk,jpgon) = tra(ji,jj,jk,jpgon) + zfact * 1.0 / 3.0 * 1.0 /3.0
-                  tra(ji,jj,jk,jpgop) = tra(ji,jj,jk,jpgop) + 16.0 / 46.0 * zfact * 1.0 / 3.0 * 1.0 /3.0
-                  tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) + ( o2ut + o2nit ) * zfact * 2.0 / 3.0 + o2nit * zfact / 3.0
-                  tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) - 30E-6 * zfact * 1.0 / 3.0 
-                  tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + 30E-6 * zfact * 1.0 / 3.0 * 2.0 / 3.0
-                  tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + 30E-6 * zfact * 1.0 / 3.0 * 1.0 / 3.0
-                  tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + 0.002 * 4E-10 * zsoufer(ji,jj,jk) * rfact2 / rday
-              END DO
-            END DO 
-         END DO
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+            zfact = nitrpot(ji,jj,jk) * nitrfix
+            tr(ji,jj,jk,jpnh4,Krhs) = tr(ji,jj,jk,jpnh4,Krhs) + zfact / 3.0
+            tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) + rno3 * zfact / 3.0
+            tr(ji,jj,jk,jppo4,Krhs) = tr(ji,jj,jk,jppo4,Krhs) - 16.0 / 46.0 * zfact * ( 1.0 - 1.0 / 3.0 ) &
+            &                     * ztrpo4(ji,jj,jk) / (ztrpo4(ji,jj,jk) + ztrdop(ji,jj,jk) + rtrn)
+            tr(ji,jj,jk,jpdon,Krhs) = tr(ji,jj,jk,jpdon,Krhs) + zfact * 1.0 / 3.0
+            tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) + zfact * 1.0 / 3.0
+            tr(ji,jj,jk,jpdop,Krhs) = tr(ji,jj,jk,jpdop,Krhs) + 16.0 / 46.0 * zfact / 3.0  &
+            &                     - 16.0 / 46.0 * zfact * ztrdop(ji,jj,jk)   &
+            &                     / (ztrpo4(ji,jj,jk) + ztrdop(ji,jj,jk) + rtrn)
+            tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) + zfact * 1.0 / 3.0 * 2.0 / 3.0
+            tr(ji,jj,jk,jppon,Krhs) = tr(ji,jj,jk,jppon,Krhs) + zfact * 1.0 / 3.0 * 2.0 /3.0
+            tr(ji,jj,jk,jppop,Krhs) = tr(ji,jj,jk,jppop,Krhs) + 16.0 / 46.0 * zfact * 1.0 / 3.0 * 2.0 /3.0
+            tr(ji,jj,jk,jpgoc,Krhs) = tr(ji,jj,jk,jpgoc,Krhs) + zfact * 1.0 / 3.0 * 1.0 / 3.0
+            tr(ji,jj,jk,jpgon,Krhs) = tr(ji,jj,jk,jpgon,Krhs) + zfact * 1.0 / 3.0 * 1.0 /3.0
+            tr(ji,jj,jk,jpgop,Krhs) = tr(ji,jj,jk,jpgop,Krhs) + 16.0 / 46.0 * zfact * 1.0 / 3.0 * 1.0 /3.0
+            tr(ji,jj,jk,jpoxy,Krhs) = tr(ji,jj,jk,jpoxy,Krhs) + ( o2ut + o2nit ) * zfact * 2.0 / 3.0 + o2nit * zfact / 3.0
+            tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) - 30E-6 * zfact * 1.0 / 3.0 
+            tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) + 30E-6 * zfact * 1.0 / 3.0 * 2.0 / 3.0
+            tr(ji,jj,jk,jpbfe,Krhs) = tr(ji,jj,jk,jpbfe,Krhs) + 30E-6 * zfact * 1.0 / 3.0 * 1.0 / 3.0
+            tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) + 0.002 * 4E-10 * zsoufer(ji,jj,jk) * rfact2 / rday
+         END_3D
          !
       ENDIF
 
-      IF( lk_iomput ) THEN
-         IF( knt == nrdttrc ) THEN
-            zfact = 1.e+3 * rfact2r !  conversion from molC/l/kt  to molN/m3/s
-            IF( iom_use("Nfix"   ) ) CALL iom_put( "Nfix", nitrpot(:,:,:) * nitrfix * rno3 * zfact * tmask(:,:,:) )  ! nitrogen fixation 
-            IF( iom_use("INTNFIX") ) THEN   ! nitrogen fixation rate in ocean ( vertically integrated )
-               zwork(:,:) = 0.
-               DO jk = 1, jpkm1
-                 zwork(:,:) = zwork(:,:) + nitrpot(:,:,jk) * nitrfix * rno3 * zfact * e3t_n(:,:,jk) * tmask(:,:,jk)
-               ENDDO
-               CALL iom_put( "INTNFIX" , zwork ) 
-            ENDIF
-            IF( iom_use("SedCal" ) ) CALL iom_put( "SedCal", zsedcal(:,:) * zfact )
-            IF( iom_use("SedSi" ) )  CALL iom_put( "SedSi",  zsedsi (:,:) * zfact )
-            IF( iom_use("SedC" ) )   CALL iom_put( "SedC",   zsedc  (:,:) * zfact )
-            IF( iom_use("Sdenit" ) ) CALL iom_put( "Sdenit", sdenit (:,:) * zfact * rno3 )
-         ENDIF
-      ENDIF
-      !
-      IF(ln_ctl) THEN  ! print mean trends (USEd for debugging)
+      IF( lk_iomput .AND. knt == nrdttrc ) THEN
+         zfact = 1.e+3 * rfact2r !  conversion from molC/l/kt  to molN/m3/s
+         CALL iom_put( "Nfix", nitrpot(:,:,:) * nitrfix * rno3 * zfact * tmask(:,:,:) )  ! nitrogen fixation 
+         CALL iom_put( "SedCal", zsedcal(:,:) * zfact )
+         CALL iom_put( "SedSi" , zsedsi (:,:) * zfact )
+         CALL iom_put( "SedC"  , zsedc  (:,:) * zfact )
+         CALL iom_put( "Sdenit", sdenit (:,:) * zfact * rno3 )
+      ENDIF
+      !
+      IF(sn_cfctl%l_prttrc) 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)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -494,4 +325,46 @@
    END SUBROUTINE p4z_sed
 
+   SUBROUTINE p4z_sed_init
+      !!----------------------------------------------------------------------
+      !!                  ***  routine p4z_sed_init  ***
+      !!
+      !! ** purpose :   initialization of some parameters
+      !!
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      INTEGER  :: ji, jj, jk, jm
+      INTEGER  :: ios                 ! Local integer output status for namelist read
+      !
+      !!
+      NAMELIST/nampissed/ nitrfix, diazolight, concfediaz
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'p4z_sed_init : initialization of sediment mobilisation '
+         WRITE(numout,*) '~~~~~~~~~~~~ '
+      ENDIF
+      !                            !* set file information
+      READ  ( numnatp_ref, nampissed, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampissed in reference namelist' )
+      READ  ( numnatp_cfg, nampissed, IOSTAT = ios, ERR = 902 )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampissed in configuration namelist' )
+      IF(lwm) WRITE ( numonp, nampissed )
+
+      IF(lwp) THEN
+         WRITE(numout,*) '   Namelist : nampissed '
+         WRITE(numout,*) '      nitrogen fixation rate                       nitrfix = ', nitrfix
+         WRITE(numout,*) '      nitrogen fixation sensitivty to light    diazolight  = ', diazolight
+         WRITE(numout,*) '      Fe half-saturation cste for diazotrophs  concfediaz  = ', concfediaz
+      ENDIF
+      !
+      r1_rday  = 1. / rday
+      !
+      sedsilfrac = 0.03     ! percentage of silica loss in the sediments
+      sedcalfrac = 0.6      ! percentage of calcite loss in the sediments
+      !
+      lk_sed = ln_sediment .AND. ln_sed_2way 
+      !
+   END SUBROUTINE p4z_sed_init
 
    INTEGER FUNCTION p4z_sed_alloc()
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zsink.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zsink.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zsink.F90	(revision 13463)
@@ -17,5 +17,5 @@
    USE sms_pisces      !  PISCES Source Minus Sink variables
    USE trcsink         !  General routine to compute sedimentation
-   USE prtctl_trc      !  print control for debugging
+   USE prtctl          !  print control for debugging
    USE iom             !  I/O manager
    USE lib_mpp
@@ -38,4 +38,7 @@
    INTEGER  :: ik100
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -49,5 +52,5 @@
    !!----------------------------------------------------------------------
 
-   SUBROUTINE p4z_sink ( kt, knt )
+   SUBROUTINE p4z_sink ( kt, knt, Kbb, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_sink  ***
@@ -59,9 +62,8 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) :: kt, knt
+      INTEGER, INTENT(in) :: Kbb, Kmm, Krhs  ! time level indices
       INTEGER  ::   ji, jj, jk
       CHARACTER (len=25) :: charout
       REAL(wp) :: zmax, zfact
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: zw3d
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:  ) :: zw2d
       !!---------------------------------------------------------------------
       !
@@ -79,13 +81,9 @@
       !    by data and from the coagulation theory
       !    -----------------------------------------------------------
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1,jpi
-               zmax  = MAX( heup_01(ji,jj), hmld(ji,jj) )
-               zfact = MAX( 0., gdepw_n(ji,jj,jk+1) - zmax ) / wsbio2scale
-               wsbio4(ji,jj,jk) = wsbio2 + MAX(0., ( wsbio2max - wsbio2 )) * zfact
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zmax  = MAX( heup_01(ji,jj), hmld(ji,jj) )
+         zfact = MAX( 0., gdepw(ji,jj,jk+1,Kmm) - zmax ) / wsbio2scale
+         wsbio4(ji,jj,jk) = wsbio2 + MAX(0., ( wsbio2max - wsbio2 )) * zfact
+      END_3D
 
       ! limit the values of the sinking speeds to avoid numerical instabilities  
@@ -104,10 +102,10 @@
       !   Compute the sedimentation term using p4zsink2 for all the sinking particles
       !   -----------------------------------------------------
-      CALL trc_sink( kt, wsbio3, sinking , jppoc, rfact2 )
-      CALL trc_sink( kt, wsbio3, sinkfer , jpsfe, rfact2 )
-      CALL trc_sink( kt, wsbio4, sinking2, jpgoc, rfact2 )
-      CALL trc_sink( kt, wsbio4, sinkfer2, jpbfe, rfact2 )
-      CALL trc_sink( kt, wsbio4, sinksil , jpgsi, rfact2 )
-      CALL trc_sink( kt, wsbio4, sinkcal , jpcal, rfact2 )
+      CALL trc_sink( kt, Kbb, Kmm, wsbio3, sinking , jppoc, rfact2 )
+      CALL trc_sink( kt, Kbb, Kmm, wsbio3, sinkfer , jpsfe, rfact2 )
+      CALL trc_sink( kt, Kbb, Kmm, wsbio4, sinking2, jpgoc, rfact2 )
+      CALL trc_sink( kt, Kbb, Kmm, wsbio4, sinkfer2, jpbfe, rfact2 )
+      CALL trc_sink( kt, Kbb, Kmm, wsbio4, sinksil , jpgsi, rfact2 )
+      CALL trc_sink( kt, Kbb, Kmm, wsbio4, sinkcal , jpcal, rfact2 )
 
       IF( ln_p5z ) THEN
@@ -119,8 +117,8 @@
          !   Compute the sedimentation term using p4zsink2 for all the sinking particles
          !   -----------------------------------------------------
-         CALL trc_sink( kt, wsbio3, sinkingn , jppon, rfact2 )
-         CALL trc_sink( kt, wsbio3, sinkingp , jppop, rfact2 )
-         CALL trc_sink( kt, wsbio4, sinking2n, jpgon, rfact2 )
-         CALL trc_sink( kt, wsbio4, sinking2p, jpgop, rfact2 )
+         CALL trc_sink( kt, Kbb, Kmm, wsbio3, sinkingn , jppon, rfact2 )
+         CALL trc_sink( kt, Kbb, Kmm, wsbio3, sinkingp , jppop, rfact2 )
+         CALL trc_sink( kt, Kbb, Kmm, wsbio4, sinking2n, jpgon, rfact2 )
+         CALL trc_sink( kt, Kbb, Kmm, wsbio4, sinking2p, jpgop, rfact2 )
       ENDIF
 
@@ -129,51 +127,23 @@
         &   t_oce_co2_exp = glob_sum( 'p4zsink', ( sinking(:,:,ik100) + sinking2(:,:,ik100) ) * e1e2t(:,:) * tmask(:,:,1) )
      !
-     IF( lk_iomput ) THEN
-       IF( knt == nrdttrc ) THEN
-          ALLOCATE( zw2d(jpi,jpj), zw3d(jpi,jpj,jpk) )
-          zfact = 1.e+3 * rfact2r  !  conversion from mol/l/kt to  mol/m3/s
-          !
-          IF( iom_use( "EPC100" ) )  THEN
-              zw2d(:,:) = ( sinking(:,:,ik100) + sinking2(:,:,ik100) ) * zfact * tmask(:,:,1) ! Export of carbon at 100m
-              CALL iom_put( "EPC100"  , zw2d )
-          ENDIF
-          IF( iom_use( "EPFE100" ) )  THEN
-              zw2d(:,:) = ( sinkfer(:,:,ik100) + sinkfer2(:,:,ik100) ) * zfact * tmask(:,:,1) ! Export of iron at 100m
-              CALL iom_put( "EPFE100"  , zw2d )
-          ENDIF
-          IF( iom_use( "EPCAL100" ) )  THEN
-              zw2d(:,:) = sinkcal(:,:,ik100) * zfact * tmask(:,:,1) ! Export of calcite at 100m
-              CALL iom_put( "EPCAL100"  , zw2d )
-          ENDIF
-          IF( iom_use( "EPSI100" ) )  THEN
-              zw2d(:,:) =  sinksil(:,:,ik100) * zfact * tmask(:,:,1) ! Export of bigenic silica at 100m
-              CALL iom_put( "EPSI100"  , zw2d )
-          ENDIF
-          IF( iom_use( "EXPC" ) )  THEN
-              zw3d(:,:,:) = ( sinking(:,:,:) + sinking2(:,:,:) ) * zfact * tmask(:,:,:) ! Export of carbon in the water column
-              CALL iom_put( "EXPC"  , zw3d )
-          ENDIF
-          IF( iom_use( "EXPFE" ) )  THEN
-              zw3d(:,:,:) = ( sinkfer(:,:,:) + sinkfer2(:,:,:) ) * zfact * tmask(:,:,:) ! Export of iron 
-              CALL iom_put( "EXPFE"  , zw3d )
-          ENDIF
-          IF( iom_use( "EXPCAL" ) )  THEN
-              zw3d(:,:,:) = sinkcal(:,:,:) * zfact * tmask(:,:,:) ! Export of calcite 
-              CALL iom_put( "EXPCAL"  , zw3d )
-          ENDIF
-          IF( iom_use( "EXPSI" ) )  THEN
-              zw3d(:,:,:) = sinksil(:,:,:) * zfact * tmask(:,:,:) ! Export of bigenic silica
-              CALL iom_put( "EXPSI"  , zw3d )
-          ENDIF
-          IF( iom_use( "tcexp" ) )  CALL iom_put( "tcexp" , t_oce_co2_exp * zfact )   ! molC/s
-          ! 
-          DEALLOCATE( zw2d, zw3d )
-        ENDIF
+     IF( lk_iomput .AND.  knt == nrdttrc ) THEN
+       zfact = 1.e+3 * rfact2r  !  conversion from mol/l/kt to  mol/m3/s
+       !
+       CALL iom_put( "EPC100"  , ( sinking(:,:,ik100) + sinking2(:,:,ik100) ) * zfact * tmask(:,:,1) ) ! Export of carbon at 100m 
+       CALL iom_put( "EPFE100" , ( sinkfer(:,:,ik100) + sinkfer2(:,:,ik100) ) * zfact * tmask(:,:,1) ) ! Export of iron at 100m 
+       CALL iom_put( "EPCAL100", sinkcal(:,:,ik100) * zfact * tmask(:,:,1) )      ! Export of calcite at 100m 
+       CALL iom_put( "EPSI100" , sinksil(:,:,ik100) * zfact * tmask(:,:,1) )          ! Export of bigenic silica at 100m 
+       CALL iom_put( "EXPC"    , ( sinking(:,:,:) + sinking2(:,:,:) ) * zfact * tmask(:,:,:) ) ! Export of carbon in the water column 
+       CALL iom_put( "EXPFE"   , ( sinkfer(:,:,:) + sinkfer2(:,:,:) ) * zfact * tmask(:,:,:) ) ! Export of iron  
+       CALL iom_put( "EXPCAL"  , sinkcal(:,:,:) * zfact * tmask(:,:,:) )      ! Export of calcite 
+       CALL iom_put( "EXPSI"   , sinksil(:,:,:) * zfact * tmask(:,:,:) )      ! Export of bigenic silica
+       CALL iom_put( "tcexp"   , t_oce_co2_exp * zfact )   ! molC/s
+       ! 
       ENDIF
       !
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('sink')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zsms.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zsms.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p4zsms.F90	(revision 13463)
@@ -17,5 +17,5 @@
    USE p4zlys          ! Calcite saturation
    USE p4zflx          ! Gas exchange
-   USE p4zsbc          ! External source of nutrients
+   USE p4zbc           ! External source of nutrients
    USE p4zsed          ! Sedimentation
    USE p4zint          ! time interpolation
@@ -25,5 +25,5 @@
    USE trdtrc          ! TOP trends variables
    USE sedmodel        ! Sediment model
-   USE prtctl_trc      ! print control for debugging
+   USE prtctl          ! print control for debugging
 
    IMPLICIT NONE
@@ -35,8 +35,11 @@
    INTEGER ::    numco2, numnut, numnit      ! logical unit for co2 budget
    REAL(wp) ::   alkbudget, no3budget, silbudget, ferbudget, po4budget
-   REAL(wp) ::   xfact1, xfact2, xfact3
+   REAL(wp) ::   xfact, xfact1, xfact2, xfact3
 
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   xnegtr     ! Array used to indicate negative tracer values
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -46,5 +49,5 @@
 CONTAINS
 
-   SUBROUTINE p4z_sms( kt )
+   SUBROUTINE p4z_sms( kt, Kbb, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p4z_sms  ***
@@ -58,9 +61,14 @@
       !!---------------------------------------------------------------------
       !
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   kt              ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   Kbb, Kmm, Krhs  ! time level index
       !!
       INTEGER ::   ji, jj, jk, jnt, jn, jl
       REAL(wp) ::  ztra
       CHARACTER (len=25) :: charout
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:    ) :: zw2d
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:  ) :: zw3d
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::   ztrdt   ! 4D workspace
+
       !!---------------------------------------------------------------------
       !
@@ -72,82 +80,135 @@
         !
         IF( .NOT. ln_rsttr ) THEN
-            CALL p4z_che                              ! initialize the chemical constants
-            CALL ahini_for_at(hi)   !  set PH at kt=nit000
+            CALL p4z_che( Kbb, Kmm )                  ! initialize the chemical constants
+            CALL ahini_for_at( hi, Kbb )              !  set PH at kt=nit000
             t_oce_co2_flx_cum = 0._wp
         ELSE
-            CALL p4z_rst( nittrc000, 'READ' )  !* read or initialize all required fields
+            CALL p4z_rst( nittrc000, Kbb, Kmm,  'READ' )  !* read or initialize all required fields
         ENDIF
         !
       ENDIF
       !
-      IF( ln_pisdmp .AND. MOD( kt - nn_dttrc, nn_pisdmp ) == 0 )   CALL p4z_dmp( kt )      ! Relaxation of some tracers
-      !
-      rfact = r2dttrc
-      !
-      IF( ( ln_top_euler .AND. kt == nittrc000 )  .OR. ( .NOT.ln_top_euler .AND. kt <= nittrc000 + nn_dttrc ) ) THEN
+      IF( ln_pisdmp .AND. MOD( kt - 1, nn_pisdmp ) == 0 )   CALL p4z_dmp( kt, Kbb, Kmm )      ! Relaxation of some tracers
+      !
+      rfact = rDt_trc
+      !
+      ! trends computation initialisation
+      IF( l_trdtrc )  THEN
+         ALLOCATE( ztrdt(jpi,jpj,jpk,jp_pisces) )  !* store now fields before applying the Asselin filter
+         ztrdt(:,:,:,:)  = tr(:,:,:,:,Kmm)
+      ENDIF
+      !
+
+      IF( ( ln_top_euler .AND. kt == nittrc000 )  .OR. ( .NOT.ln_top_euler .AND. kt <= nittrc000 + 1 ) ) THEN
          rfactr  = 1. / rfact
          rfact2  = rfact / REAL( nrdttrc, wp )
          rfact2r = 1. / rfact2
          xstep = rfact2 / rday         ! Time step duration for biology
+         xfact = 1.e+3 * rfact2r
          IF(lwp) WRITE(numout,*) 
-         IF(lwp) WRITE(numout,*) '    Passive Tracer  time step    rfact  = ', rfact, ' rdt = ', rdt
+         IF(lwp) WRITE(numout,*) '    Passive Tracer  time step    rfact  = ', rfact, ' rn_Dt = ', rn_Dt
          IF(lwp) write(numout,*) '    PISCES  Biology time step    rfact2 = ', rfact2
          IF(lwp) WRITE(numout,*)
       ENDIF
 
-      IF( ( neuler == 0 .AND. kt == nittrc000 ) .OR. ln_top_euler ) THEN
+      IF( l_1st_euler .OR. ln_top_euler ) THEN
          DO jn = jp_pcs0, jp_pcs1              !   SMS on tracer without Asselin time-filter
-            trb(:,:,:,jn) = trn(:,:,:,jn)
+            tr(:,:,:,jn,Kbb) = tr(:,:,:,jn,Kmm)
          END DO
       ENDIF
       !
-      IF( ll_sbc ) CALL p4z_sbc( kt )   ! external sources of nutrients 
+      IF( ll_bc )    CALL p4z_bc( kt, Kbb, Kmm, Krhs )   ! external sources of nutrients 
       !
 #if ! defined key_sed_off
-      CALL p4z_che              ! computation of chemical constants
-      CALL p4z_int( kt )        ! computation of various rates for biogeochemistry
+      CALL p4z_che(     Kbb, Kmm       ) ! computation of chemical constants
+      CALL p4z_int( kt, Kbb, Kmm       ) ! computation of various rates for biogeochemistry
       !
       DO jnt = 1, nrdttrc          ! Potential time splitting if requested
          !
-         CALL p4z_bio( kt, jnt )   ! Biology
-         CALL p4z_lys( kt, jnt )   ! Compute CaCO3 saturation
-         CALL p4z_sed( kt, jnt )   ! Surface and Bottom boundary conditions
-         CALL p4z_flx( kt, jnt )   ! Compute surface fluxes
+         CALL p4z_bio( kt, jnt, Kbb, Kmm, Krhs )   ! Biology
+         CALL p4z_lys( kt, jnt, Kbb,      Krhs )   ! Compute CaCO3 saturation
+         CALL p4z_sed( kt, jnt, Kbb, Kmm, Krhs )   ! Surface and Bottom boundary conditions
+         CALL p4z_flx( kt, jnt, Kbb, Kmm, Krhs )   ! Compute surface fluxes
          !
          xnegtr(:,:,:) = 1.e0
          DO jn = jp_pcs0, jp_pcs1
-            DO jk = 1, jpk
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     IF( ( trb(ji,jj,jk,jn) + tra(ji,jj,jk,jn) ) < 0.e0 ) THEN
-                        ztra             = ABS( trb(ji,jj,jk,jn) ) / ( ABS( tra(ji,jj,jk,jn) ) + rtrn )
-                        xnegtr(ji,jj,jk) = MIN( xnegtr(ji,jj,jk),  ztra )
-                     ENDIF
-                 END DO
-               END DO
-            END DO
+            DO_3D( 1, 1, 1, 1, 1, jpk )
+               IF( ( tr(ji,jj,jk,jn,Kbb) + tr(ji,jj,jk,jn,Krhs) ) < 0.e0 ) THEN
+                  ztra             = ABS( tr(ji,jj,jk,jn,Kbb) ) / ( ABS( tr(ji,jj,jk,jn,Krhs) ) + rtrn )
+                  xnegtr(ji,jj,jk) = MIN( xnegtr(ji,jj,jk),  ztra )
+               ENDIF
+            END_3D
          END DO
          !                                ! where at least 1 tracer concentration becomes negative
          !                                ! 
          DO jn = jp_pcs0, jp_pcs1
-           trb(:,:,:,jn) = trb(:,:,:,jn) + xnegtr(:,:,:) * tra(:,:,:,jn)
+           tr(:,:,:,jn,Kbb) = tr(:,:,:,jn,Kbb) + xnegtr(:,:,:) * tr(:,:,:,jn,Krhs)
          END DO
         !
+        IF(  iom_use( 'INTdtAlk' ) .OR. iom_use( 'INTdtDIC' ) .OR. iom_use( 'INTdtFer' ) .OR.  &
+          &  iom_use( 'INTdtDIN' ) .OR. iom_use( 'INTdtDIP' ) .OR. iom_use( 'INTdtSil' ) )  THEN
+          !
+          ALLOCATE( zw3d(jpi,jpj,jpk), zw2d(jpi,jpj) )
+          zw3d(:,:,jpk) = 0.
+          DO jk = 1, jpkm1
+              zw3d(:,:,jk) = xnegtr(:,:,jk) * xfact * e3t(:,:,jk,Kmm) * tmask(:,:,jk)
+          ENDDO
+          !
+          zw2d(:,:) = 0.
+          DO jk = 1, jpkm1
+             zw2d(:,:) = zw2d(:,:) + zw3d(:,:,jk) * tr(:,:,jk,jptal,Krhs)
+          ENDDO
+          CALL iom_put( 'INTdtAlk', zw2d )
+          !
+          zw2d(:,:) = 0.
+          DO jk = 1, jpkm1
+             zw2d(:,:) = zw2d(:,:) + zw3d(:,:,jk) * tr(:,:,jk,jpdic,Krhs)
+          ENDDO
+          CALL iom_put( 'INTdtDIC', zw2d )
+          !
+          zw2d(:,:) = 0.
+          DO jk = 1, jpkm1
+             zw2d(:,:) = zw2d(:,:) + zw3d(:,:,jk) * rno3 * ( tr(:,:,jk,jpno3,Krhs) + tr(:,:,jk,jpnh4,Krhs) )
+          ENDDO
+          CALL iom_put( 'INTdtDIN', zw2d )
+          !
+          zw2d(:,:) = 0.
+          DO jk = 1, jpkm1
+             zw2d(:,:) = zw2d(:,:) + zw3d(:,:,jk) * po4r * tr(:,:,jk,jppo4,Krhs)
+          ENDDO
+          CALL iom_put( 'INTdtDIP', zw2d )
+          !
+          zw2d(:,:) = 0.
+          DO jk = 1, jpkm1
+             zw2d(:,:) = zw2d(:,:) + zw3d(:,:,jk) * tr(:,:,jk,jpfer,Krhs)
+          ENDDO
+          CALL iom_put( 'INTdtFer', zw2d )
+          !
+          zw2d(:,:) = 0.
+          DO jk = 1, jpkm1
+             zw2d(:,:) = zw2d(:,:) + zw3d(:,:,jk) * tr(:,:,jk,jpsil,Krhs)
+          ENDDO
+          CALL iom_put( 'INTdtSil', zw2d )
+          !
+          DEALLOCATE( zw3d, zw2d )
+        ENDIF
+        !
          DO jn = jp_pcs0, jp_pcs1
-            tra(:,:,:,jn) = 0._wp
+            tr(:,:,:,jn,Krhs) = 0._wp
          END DO
          !
          IF( ln_top_euler ) THEN
             DO jn = jp_pcs0, jp_pcs1
-               trn(:,:,:,jn) = trb(:,:,:,jn)
+               tr(:,:,:,jn,Kmm) = tr(:,:,:,jn,Kbb)
             END DO
          ENDIF
       END DO
-
       !
       IF( l_trdtrc ) THEN
          DO jn = jp_pcs0, jp_pcs1
-           CALL trd_trc( tra(:,:,:,jn), jn, jptra_sms, kt )   ! save trends
+           ztrdt(:,:,:,jn) = ( tr(:,:,:,jn,Kbb) - ztrdt(:,:,:,jn) ) * rfactr 
+           CALL trd_trc( tr(:,:,:,jn,Krhs), jn, jptra_sms, kt, Kmm )   ! save trends
          END DO
+         DEALLOCATE( ztrdt ) 
       END IF
 #endif
@@ -155,9 +216,9 @@
       IF( ln_sediment ) THEN 
          !
-         CALL sed_model( kt )     !  Main program of Sediment model
+         CALL sed_model( kt, Kbb, Kmm, Krhs )     !  Main program of Sediment model
          !
          IF( ln_top_euler ) THEN
             DO jn = jp_pcs0, jp_pcs1
-               trn(:,:,:,jn) = trb(:,:,:,jn)
+               tr(:,:,:,jn,Kmm) = tr(:,:,:,jn,Kbb)
             END DO
          ENDIF
@@ -165,10 +226,10 @@
       ENDIF
       !
-      IF( lrst_trc )  CALL p4z_rst( kt, 'WRITE' )  !* Write PISCES informations in restart file 
-      !
-
-      IF( lk_iomput .OR. ln_check_mass )  CALL p4z_chk_mass( kt )    ! Mass conservation checking
-
-      IF( lwm .AND. kt == nittrc000    )  CALL FLUSH( numonp )       ! flush output namelist PISCES
+      IF( lrst_trc )  CALL p4z_rst( kt, Kbb, Kmm,  'WRITE' )           !* Write PISCES informations in restart file 
+      !
+
+      IF( lk_iomput .OR. ln_check_mass )  CALL p4z_chk_mass( kt, Kmm ) ! Mass conservation checking
+
+      IF( lwm .AND. kt == nittrc000    )  CALL FLUSH( numonp )         ! flush output namelist PISCES
       !
       IF( ln_timing )  CALL timing_stop('p4z_sms')
@@ -201,10 +262,8 @@
       ENDIF
 
-      REWIND( numnatp_ref )              ! Namelist nampisbio in reference namelist : Pisces variables
       READ  ( numnatp_ref, nampisbio, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisbio in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampisbio in configuration namelist : Pisces variables
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisbio in reference namelist' )
       READ  ( numnatp_cfg, nampisbio, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisbio in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisbio in configuration namelist' )
       IF(lwm) WRITE( numonp, nampisbio )
       !
@@ -232,10 +291,8 @@
 
 
-      REWIND( numnatp_ref )              ! Namelist nampisdmp in reference namelist : Pisces damping
       READ  ( numnatp_ref, nampisdmp, IOSTAT = ios, ERR = 905)
-905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisdmp in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampisdmp in configuration namelist : Pisces damping
+905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampisdmp in reference namelist' )
       READ  ( numnatp_cfg, nampisdmp, IOSTAT = ios, ERR = 906 )
-906   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisdmp in configuration namelist', lwp )
+906   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampisdmp in configuration namelist' )
       IF(lwm) WRITE( numonp, nampisdmp )
       !
@@ -247,10 +304,8 @@
       ENDIF
 
-      REWIND( numnatp_ref )              ! Namelist nampismass in reference namelist : Pisces mass conservation check
       READ  ( numnatp_ref, nampismass, IOSTAT = ios, ERR = 907)
-907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampismass in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampismass in configuration namelist : Pisces mass conservation check 
+907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampismass in reference namelist' )
       READ  ( numnatp_cfg, nampismass, IOSTAT = ios, ERR = 908 )
-908   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampismass in configuration namelist', lwp )
+908   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampismass in configuration namelist' )
       IF(lwm) WRITE( numonp, nampismass )
 
@@ -264,5 +319,5 @@
 
 
-   SUBROUTINE p4z_rst( kt, cdrw )
+   SUBROUTINE p4z_rst( kt, Kbb, Kmm, cdrw )
       !!---------------------------------------------------------------------
       !!                   ***  ROUTINE p4z_rst  ***
@@ -275,4 +330,5 @@
       !!---------------------------------------------------------------------
       INTEGER         , INTENT(in) ::   kt         ! ocean time-step
+      INTEGER         , INTENT(in) ::   Kbb, Kmm   ! time level indices
       CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
       !!---------------------------------------------------------------------
@@ -285,12 +341,12 @@
          ! 
          IF( iom_varid( numrtr, 'PH', ldstop = .FALSE. ) > 0 ) THEN
-            CALL iom_get( numrtr, jpdom_autoglo, 'PH' , hi(:,:,:)  )
+            CALL iom_get( numrtr, jpdom_auto, 'PH' , hi(:,:,:)  )
          ELSE
-            CALL p4z_che                              ! initialize the chemical constants
-            CALL ahini_for_at(hi)
-         ENDIF
-         CALL iom_get( numrtr, jpdom_autoglo, 'Silicalim', xksi(:,:) )
+            CALL p4z_che( Kbb, Kmm )                  ! initialize the chemical constants
+            CALL ahini_for_at( hi, Kbb )
+         ENDIF
+         CALL iom_get( numrtr, jpdom_auto, 'Silicalim', xksi(:,:) )
          IF( iom_varid( numrtr, 'Silicamax', ldstop = .FALSE. ) > 0 ) THEN
-            CALL iom_get( numrtr, jpdom_autoglo, 'Silicamax' , xksimax(:,:)  )
+            CALL iom_get( numrtr, jpdom_auto, 'Silicamax' , xksimax(:,:)  )
          ELSE
             xksimax(:,:) = xksi(:,:)
@@ -305,7 +361,7 @@
          IF( ln_p5z ) THEN
             IF( iom_varid( numrtr, 'sized', ldstop = .FALSE. ) > 0 ) THEN
-               CALL iom_get( numrtr, jpdom_autoglo, 'sizep' , sizep(:,:,:)  )
-               CALL iom_get( numrtr, jpdom_autoglo, 'sizen' , sizen(:,:,:)  )
-               CALL iom_get( numrtr, jpdom_autoglo, 'sized' , sized(:,:,:)  )
+               CALL iom_get( numrtr, jpdom_auto, 'sizep' , sizep(:,:,:)  )
+               CALL iom_get( numrtr, jpdom_auto, 'sizen' , sizen(:,:,:)  )
+               CALL iom_get( numrtr, jpdom_auto, 'sized' , sized(:,:,:)  )
             ELSE
                sizep(:,:,:) = 1.
@@ -335,5 +391,5 @@
 
 
-   SUBROUTINE p4z_dmp( kt )
+   SUBROUTINE p4z_dmp( kt, Kbb, Kmm )
       !!----------------------------------------------------------------------
       !!                    ***  p4z_dmp  ***
@@ -342,5 +398,6 @@
       !!----------------------------------------------------------------------
       !
-      INTEGER, INTENT( in )  ::     kt ! time step
+      INTEGER, INTENT( in )  ::     kt            ! time step
+      INTEGER, INTENT( in )  ::     Kbb, Kmm      ! time level indices
       !
       REAL(wp) ::  alkmean = 2426.     ! mean value of alkalinity ( Glodap ; for Goyet 2391. )
@@ -363,40 +420,40 @@
             zarea          = 1._wp / glob_sum( 'p4zsms', cvol(:,:,:) ) * 1e6              
 
-            zalksumn = glob_sum( 'p4zsms', trn(:,:,:,jptal) * cvol(:,:,:)  ) * zarea
-            zpo4sumn = glob_sum( 'p4zsms', trn(:,:,:,jppo4) * cvol(:,:,:)  ) * zarea * po4r
-            zno3sumn = glob_sum( 'p4zsms', trn(:,:,:,jpno3) * cvol(:,:,:)  ) * zarea * rno3
-            zsilsumn = glob_sum( 'p4zsms', trn(:,:,:,jpsil) * cvol(:,:,:)  ) * zarea
+            zalksumn = glob_sum( 'p4zsms', tr(:,:,:,jptal,Kmm) * cvol(:,:,:)  ) * zarea
+            zpo4sumn = glob_sum( 'p4zsms', tr(:,:,:,jppo4,Kmm) * cvol(:,:,:)  ) * zarea * po4r
+            zno3sumn = glob_sum( 'p4zsms', tr(:,:,:,jpno3,Kmm) * cvol(:,:,:)  ) * zarea * rno3
+            zsilsumn = glob_sum( 'p4zsms', tr(:,:,:,jpsil,Kmm) * cvol(:,:,:)  ) * zarea
  
             IF(lwp) WRITE(numout,*) '       TALKN mean : ', zalksumn
-            trn(:,:,:,jptal) = trn(:,:,:,jptal) * alkmean / zalksumn
+            tr(:,:,:,jptal,Kmm) = tr(:,:,:,jptal,Kmm) * alkmean / zalksumn
 
             IF(lwp) WRITE(numout,*) '       PO4N  mean : ', zpo4sumn
-            trn(:,:,:,jppo4) = trn(:,:,:,jppo4) * po4mean / zpo4sumn
+            tr(:,:,:,jppo4,Kmm) = tr(:,:,:,jppo4,Kmm) * po4mean / zpo4sumn
 
             IF(lwp) WRITE(numout,*) '       NO3N  mean : ', zno3sumn
-            trn(:,:,:,jpno3) = trn(:,:,:,jpno3) * no3mean / zno3sumn
+            tr(:,:,:,jpno3,Kmm) = tr(:,:,:,jpno3,Kmm) * no3mean / zno3sumn
 
             IF(lwp) WRITE(numout,*) '       SiO3N mean : ', zsilsumn
-            trn(:,:,:,jpsil) = MIN( 400.e-6,trn(:,:,:,jpsil) * silmean / zsilsumn )
+            tr(:,:,:,jpsil,Kmm) = MIN( 400.e-6,tr(:,:,:,jpsil,Kmm) * silmean / zsilsumn )
             !
             !
             IF( .NOT. ln_top_euler ) THEN
-               zalksumb = glob_sum( 'p4zsms', trb(:,:,:,jptal) * cvol(:,:,:)  ) * zarea
-               zpo4sumb = glob_sum( 'p4zsms', trb(:,:,:,jppo4) * cvol(:,:,:)  ) * zarea * po4r
-               zno3sumb = glob_sum( 'p4zsms', trb(:,:,:,jpno3) * cvol(:,:,:)  ) * zarea * rno3
-               zsilsumb = glob_sum( 'p4zsms', trb(:,:,:,jpsil) * cvol(:,:,:)  ) * zarea
+               zalksumb = glob_sum( 'p4zsms', tr(:,:,:,jptal,Kbb) * cvol(:,:,:)  ) * zarea
+               zpo4sumb = glob_sum( 'p4zsms', tr(:,:,:,jppo4,Kbb) * cvol(:,:,:)  ) * zarea * po4r
+               zno3sumb = glob_sum( 'p4zsms', tr(:,:,:,jpno3,Kbb) * cvol(:,:,:)  ) * zarea * rno3
+               zsilsumb = glob_sum( 'p4zsms', tr(:,:,:,jpsil,Kbb) * cvol(:,:,:)  ) * zarea
  
                IF(lwp) WRITE(numout,*) ' '
                IF(lwp) WRITE(numout,*) '       TALKB mean : ', zalksumb
-               trb(:,:,:,jptal) = trb(:,:,:,jptal) * alkmean / zalksumb
+               tr(:,:,:,jptal,Kbb) = tr(:,:,:,jptal,Kbb) * alkmean / zalksumb
 
                IF(lwp) WRITE(numout,*) '       PO4B  mean : ', zpo4sumb
-               trb(:,:,:,jppo4) = trb(:,:,:,jppo4) * po4mean / zpo4sumb
+               tr(:,:,:,jppo4,Kbb) = tr(:,:,:,jppo4,Kbb) * po4mean / zpo4sumb
 
                IF(lwp) WRITE(numout,*) '       NO3B  mean : ', zno3sumb
-               trb(:,:,:,jpno3) = trb(:,:,:,jpno3) * no3mean / zno3sumb
+               tr(:,:,:,jpno3,Kbb) = tr(:,:,:,jpno3,Kbb) * no3mean / zno3sumb
 
                IF(lwp) WRITE(numout,*) '       SiO3B mean : ', zsilsumb
-               trb(:,:,:,jpsil) = MIN( 400.e-6,trb(:,:,:,jpsil) * silmean / zsilsumb )
+               tr(:,:,:,jpsil,Kbb) = MIN( 400.e-6,tr(:,:,:,jpsil,Kbb) * silmean / zsilsumb )
            ENDIF
         ENDIF
@@ -407,5 +464,5 @@
 
 
-   SUBROUTINE p4z_chk_mass( kt )
+   SUBROUTINE p4z_chk_mass( kt, Kmm )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE p4z_chk_mass  ***
@@ -415,4 +472,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   Kmm     ! time level indices
       REAL(wp)             ::  zrdenittot, zsdenittot, znitrpottot
       CHARACTER(LEN=100)   ::   cltxt
@@ -438,13 +496,13 @@
          !   Compute the budget of NO3, ALK, Si, Fer
          IF( ln_p4z ) THEN
-            zwork(:,:,:) =    trn(:,:,:,jpno3) + trn(:,:,:,jpnh4)                      &
-               &          +   trn(:,:,:,jpphy) + trn(:,:,:,jpdia)                      &
-               &          +   trn(:,:,:,jppoc) + trn(:,:,:,jpgoc)  + trn(:,:,:,jpdoc)  &        
-               &          +   trn(:,:,:,jpzoo) + trn(:,:,:,jpmes) 
+            zwork(:,:,:) =    tr(:,:,:,jpno3,Kmm) + tr(:,:,:,jpnh4,Kmm)                      &
+               &          +   tr(:,:,:,jpphy,Kmm) + tr(:,:,:,jpdia,Kmm)                      &
+               &          +   tr(:,:,:,jppoc,Kmm) + tr(:,:,:,jpgoc,Kmm)  + tr(:,:,:,jpdoc,Kmm)  &        
+               &          +   tr(:,:,:,jpzoo,Kmm) + tr(:,:,:,jpmes,Kmm) 
         ELSE
-            zwork(:,:,:) =    trn(:,:,:,jpno3) + trn(:,:,:,jpnh4) + trn(:,:,:,jpnph)   &
-               &          +   trn(:,:,:,jpndi) + trn(:,:,:,jpnpi)                      & 
-               &          +   trn(:,:,:,jppon) + trn(:,:,:,jpgon) + trn(:,:,:,jpdon)   &
-               &          + ( trn(:,:,:,jpzoo) + trn(:,:,:,jpmes) ) * no3rat3 
+            zwork(:,:,:) =    tr(:,:,:,jpno3,Kmm) + tr(:,:,:,jpnh4,Kmm) + tr(:,:,:,jpnph,Kmm)   &
+               &          +   tr(:,:,:,jpndi,Kmm) + tr(:,:,:,jpnpi,Kmm)                      & 
+               &          +   tr(:,:,:,jppon,Kmm) + tr(:,:,:,jpgon,Kmm) + tr(:,:,:,jpdon,Kmm)   &
+               &          + ( tr(:,:,:,jpzoo,Kmm) + tr(:,:,:,jpmes,Kmm) ) * no3rat3 
         ENDIF
         !
@@ -456,13 +514,13 @@
       IF( iom_use( "ppo4tot" ) .OR. ( ln_check_mass .AND. kt == nitend )  ) THEN
          IF( ln_p4z ) THEN
-            zwork(:,:,:) =    trn(:,:,:,jppo4)                                         &
-               &          +   trn(:,:,:,jpphy) + trn(:,:,:,jpdia)                      &
-               &          +   trn(:,:,:,jppoc) + trn(:,:,:,jpgoc)  + trn(:,:,:,jpdoc)  &        
-               &          +   trn(:,:,:,jpzoo) + trn(:,:,:,jpmes) 
+            zwork(:,:,:) =    tr(:,:,:,jppo4,Kmm)                                         &
+               &          +   tr(:,:,:,jpphy,Kmm) + tr(:,:,:,jpdia,Kmm)                      &
+               &          +   tr(:,:,:,jppoc,Kmm) + tr(:,:,:,jpgoc,Kmm)  + tr(:,:,:,jpdoc,Kmm)  &        
+               &          +   tr(:,:,:,jpzoo,Kmm) + tr(:,:,:,jpmes,Kmm) 
         ELSE
-            zwork(:,:,:) =    trn(:,:,:,jppo4) + trn(:,:,:,jppph)                      &
-               &          +   trn(:,:,:,jppdi) + trn(:,:,:,jpppi)                      & 
-               &          +   trn(:,:,:,jppop) + trn(:,:,:,jpgop) + trn(:,:,:,jpdop)   &
-               &          + ( trn(:,:,:,jpzoo) + trn(:,:,:,jpmes) ) * po4rat3 
+            zwork(:,:,:) =    tr(:,:,:,jppo4,Kmm) + tr(:,:,:,jppph,Kmm)                      &
+               &          +   tr(:,:,:,jppdi,Kmm) + tr(:,:,:,jpppi,Kmm)                      & 
+               &          +   tr(:,:,:,jppop,Kmm) + tr(:,:,:,jpgop,Kmm) + tr(:,:,:,jpdop,Kmm)   &
+               &          + ( tr(:,:,:,jpzoo,Kmm) + tr(:,:,:,jpmes,Kmm) ) * po4rat3 
         ENDIF
         !
@@ -473,5 +531,5 @@
       !
       IF( iom_use( "psiltot" ) .OR. ( ln_check_mass .AND. kt == nitend )  ) THEN
-         zwork(:,:,:) =  trn(:,:,:,jpsil) + trn(:,:,:,jpgsi) + trn(:,:,:,jpdsi) 
+         zwork(:,:,:) =  tr(:,:,:,jpsil,Kmm) + tr(:,:,:,jpgsi,Kmm) + tr(:,:,:,jpdsi,Kmm) 
          !
          silbudget = glob_sum( 'p4zsms', zwork(:,:,:) * cvol(:,:,:)  )  
@@ -481,5 +539,5 @@
       !
       IF( iom_use( "palktot" ) .OR. ( ln_check_mass .AND. kt == nitend )  ) THEN
-         zwork(:,:,:) =  trn(:,:,:,jpno3) * rno3 + trn(:,:,:,jptal) + trn(:,:,:,jpcal) * 2.              
+         zwork(:,:,:) =  tr(:,:,:,jpno3,Kmm) * rno3 + tr(:,:,:,jptal,Kmm) + tr(:,:,:,jpcal,Kmm) * 2.              
          !
          alkbudget = glob_sum( 'p4zsms', zwork(:,:,:) * cvol(:,:,:)  )         !
@@ -489,7 +547,7 @@
       !
       IF( iom_use( "pfertot" ) .OR. ( ln_check_mass .AND. kt == nitend )  ) THEN
-         zwork(:,:,:) =   trn(:,:,:,jpfer) + trn(:,:,:,jpnfe) + trn(:,:,:,jpdfe)   &
-            &         +   trn(:,:,:,jpbfe) + trn(:,:,:,jpsfe)                      &
-            &         + ( trn(:,:,:,jpzoo) + trn(:,:,:,jpmes) )  * ferat3    
+         zwork(:,:,:) =   tr(:,:,:,jpfer,Kmm) + tr(:,:,:,jpnfe,Kmm) + tr(:,:,:,jpdfe,Kmm)   &
+            &         +   tr(:,:,:,jpbfe,Kmm) + tr(:,:,:,jpsfe,Kmm)                      &
+            &         + ( tr(:,:,:,jpzoo,Kmm) + tr(:,:,:,jpmes,Kmm) )  * ferat3    
          !
          ferbudget = glob_sum( 'p4zsms', zwork(:,:,:) * cvol(:,:,:)  )  
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zlim.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zlim.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zlim.F90	(revision 13463)
@@ -91,4 +91,6 @@
    REAL(wp) ::  xcoef2   = 1.21E-5 * 14. / 55.85 / 7.625 * 0.5 * 1.5
    REAL(wp) ::  xcoef3   = 1.15E-4 * 14. / 55.85 / 7.625 * 0.5 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -99,5 +101,5 @@
 CONTAINS
 
-   SUBROUTINE p5z_lim( kt, knt )
+   SUBROUTINE p5z_lim( kt, knt, Kbb, Kmm )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p5z_lim  ***
@@ -110,4 +112,5 @@
       !
       INTEGER, INTENT(in)  :: kt, knt
+      INTEGER, INTENT(in)  :: Kbb, Kmm  ! time level indices
       !
       INTEGER  ::   ji, jj, jk
@@ -128,189 +131,185 @@
       zratchl = 6.0
       !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! 
-               ! Tuning of the iron concentration to a minimum level that is set to the detection limit
-               !-------------------------------------
-               zno3    = trb(ji,jj,jk,jpno3) / 40.e-6
-               zferlim = MAX( 3e-11 * zno3 * zno3, 5e-12 )
-               zferlim = MIN( zferlim, 7e-11 )
-               trb(ji,jj,jk,jpfer) = MAX( trb(ji,jj,jk,jpfer), zferlim )
-
-               ! Computation of the mean relative size of each community
-               ! -------------------------------------------------------
-               z1_trnphy   = 1. / ( trb(ji,jj,jk,jpphy) + rtrn )
-               z1_trnpic   = 1. / ( trb(ji,jj,jk,jppic) + rtrn )
-               z1_trndia   = 1. / ( trb(ji,jj,jk,jpdia) + rtrn )
-               znanochl = trb(ji,jj,jk,jpnch) * z1_trnphy
-               zpicochl = trb(ji,jj,jk,jppch) * z1_trnpic
-               zdiatchl = trb(ji,jj,jk,jpdch) * z1_trndia
-
-               ! Computation of a variable Ks for iron on diatoms taking into account
-               ! that increasing biomass is made of generally bigger cells
-               !------------------------------------------------
-               zsized            = sized(ji,jj,jk)**0.81
-               zconcdfe          = concdfer * zsized
-               zconc1d           = concdno3 * zsized
-               zconc1dnh4        = concdnh4 * zsized
-               zconc0dpo4        = concdpo4 * zsized
-
-               zsizep            = 1.
-               zconcpfe          = concpfer * zsizep
-               zconc0p           = concpno3 * zsizep
-               zconc0pnh4        = concpnh4 * zsizep
-               zconc0ppo4        = concppo4 * zsizep
-
-               zsizen            = 1.
-               zconcnfe          = concnfer * zsizen
-               zconc0n           = concnno3 * zsizen
-               zconc0nnh4        = concnnh4 * zsizen
-               zconc0npo4        = concnpo4 * zsizen
-
-               ! Allometric variations of the minimum and maximum quotas
-               ! From Talmy et al. (2014) and Maranon et al. (2013)
-               ! -------------------------------------------------------
-               xqnnmin(ji,jj,jk) = qnnmin
-               xqnnmax(ji,jj,jk) = qnnmax
-               xqndmin(ji,jj,jk) = qndmin * sized(ji,jj,jk)**(-0.27) 
-               xqndmax(ji,jj,jk) = qndmax
-               xqnpmin(ji,jj,jk) = qnpmin
-               xqnpmax(ji,jj,jk) = qnpmax
-
-               ! Computation of the optimal allocation parameters
-               ! Based on the different papers by Pahlow et al., and Smith et al.
-               ! -----------------------------------------------------------------
-               znutlim = MAX( trb(ji,jj,jk,jpnh4) / zconc0nnh4,    &
-                 &         trb(ji,jj,jk,jpno3) / zconc0n)
-               fanano = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = trb(ji,jj,jk,jppo4) / zconc0npo4
-               fananop = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = biron(ji,jj,jk) / zconcnfe
-               fananof = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = MAX( trb(ji,jj,jk,jpnh4) / zconc0pnh4,    &
-                 &         trb(ji,jj,jk,jpno3) / zconc0p)
-               fapico = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = trb(ji,jj,jk,jppo4) / zconc0ppo4
-               fapicop = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = biron(ji,jj,jk) / zconcpfe
-               fapicof = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = MAX( trb(ji,jj,jk,jpnh4) / zconc1dnh4,    &
-                 &         trb(ji,jj,jk,jpno3) / zconc1d )
-               fadiat = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = trb(ji,jj,jk,jppo4) / zconc0dpo4
-               fadiatp = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               znutlim = biron(ji,jj,jk) / zconcdfe
-               fadiatf = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
-               !
-               ! Michaelis-Menten Limitation term for nutrients Small bacteria
-               ! -------------------------------------------------------------
-               zbactnh4 = trb(ji,jj,jk,jpnh4) / ( concbnh4 + trb(ji,jj,jk,jpnh4) )
-               zbactno3 = trb(ji,jj,jk,jpno3) / ( concbno3 + trb(ji,jj,jk,jpno3) ) * (1. - zbactnh4)
-               !
-               zlim1    = zbactno3 + zbactnh4
-               zlim2    = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + concbpo4)
-               zlim3    = biron(ji,jj,jk) / ( concbfe + biron(ji,jj,jk) )
-               zlim4    = trb(ji,jj,jk,jpdoc) / ( xkdoc   + trb(ji,jj,jk,jpdoc) )
-               xlimbacl(ji,jj,jk) = MIN( zlim1, zlim2, zlim3 )
-               xlimbac (ji,jj,jk) = xlimbacl(ji,jj,jk) * zlim4
-               !
-               ! Michaelis-Menten Limitation term for nutrients Small flagellates
-               ! -----------------------------------------------
-               zfalim = (1.-fanano) / fanano
-               xnanonh4(ji,jj,jk) = (1. - fanano) * trb(ji,jj,jk,jpnh4) / ( zfalim * zconc0nnh4 + trb(ji,jj,jk,jpnh4) )
-               xnanono3(ji,jj,jk) = (1. - fanano) * trb(ji,jj,jk,jpno3) / ( zfalim * zconc0n + trb(ji,jj,jk,jpno3) )  &
-               &                    * (1. - xnanonh4(ji,jj,jk))
-               !
-               zfalim = (1.-fananop) / fananop
-               xnanopo4(ji,jj,jk) = (1. - fananop) * trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zfalim * zconc0npo4 )
-               xnanodop(ji,jj,jk) = trb(ji,jj,jk,jpdop) / ( trb(ji,jj,jk,jpdop) + xkdoc )   &
-               &                    * ( 1.0 - xnanopo4(ji,jj,jk) )
-               xnanodop(ji,jj,jk) = 0.
-               !
-               zfalim = (1.-fananof) / fananof
-               xnanofer(ji,jj,jk) = (1. - fananof) * biron(ji,jj,jk) / ( biron(ji,jj,jk) + zfalim * zconcnfe )
-               !
-               zratiof   = trb(ji,jj,jk,jpnfe) * z1_trnphy
-               zqfemn = xcoef1 * znanochl + xcoef2 + xcoef3 * xnanono3(ji,jj,jk)
-               !
-               zration = trb(ji,jj,jk,jpnph) * z1_trnphy
-               zration = MIN(xqnnmax(ji,jj,jk), MAX( 2. * xqnnmin(ji,jj,jk), zration ))
-               fvnuptk(ji,jj,jk) = 1. / zpsiuptk * rno3 * 2. * xqnnmin(ji,jj,jk) / (zration + rtrn)  &
-               &                   * MAX(0., (1. - zratchl * znanochl / 12. ) )
-               !
-               zlim1    = max(0., (zration - 2. * xqnnmin(ji,jj,jk) )  &
-               &          / (xqnnmax(ji,jj,jk) - 2. * xqnnmin(ji,jj,jk) ) ) * xqnnmax(ji,jj,jk)  &
-               &          / (zration + rtrn)
-               zlim3    = MAX( 0.,( zratiof - zqfemn ) / qfnopt ) 
-               xlimnfe(ji,jj,jk) = MIN( 1., zlim3 )
-               xlimphy(ji,jj,jk) = MIN( 1., zlim1, zlim3 )
-               !
-               ! Michaelis-Menten Limitation term for nutrients picophytoplankton
-               ! ----------------------------------------------------------------
-               zfalim = (1.-fapico) / fapico 
-               xpiconh4(ji,jj,jk) = (1. - fapico) * trb(ji,jj,jk,jpnh4) / ( zfalim * zconc0pnh4 + trb(ji,jj,jk,jpnh4) )
-               xpicono3(ji,jj,jk) = (1. - fapico) * trb(ji,jj,jk,jpno3) / ( zfalim * zconc0p + trb(ji,jj,jk,jpno3) )  &
-               &                    * (1. - xpiconh4(ji,jj,jk))
-               !
-               zfalim = (1.-fapicop) / fapicop 
-               xpicopo4(ji,jj,jk) = (1. - fapicop) * trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zfalim * zconc0ppo4 )
-               xpicodop(ji,jj,jk) = trb(ji,jj,jk,jpdop) / ( trb(ji,jj,jk,jpdop) + xkdoc )   &
-               &                    * ( 1.0 - xpicopo4(ji,jj,jk) )
-               xpicodop(ji,jj,jk) = 0.
-               !
-               zfalim = (1.-fapicof) / fapicof
-               xpicofer(ji,jj,jk) = (1. - fapicof) * biron(ji,jj,jk) / ( biron(ji,jj,jk) + zfalim * zconcpfe )
-               !
-               zratiof   = trb(ji,jj,jk,jppfe) * z1_trnpic
-               zqfemp = xcoef1 * zpicochl + xcoef2 + xcoef3 * xpicono3(ji,jj,jk)
-               !
-               zration   = trb(ji,jj,jk,jpnpi) * z1_trnpic
-               zration = MIN(xqnpmax(ji,jj,jk), MAX( 2. * xqnpmin(ji,jj,jk), zration ))
-               fvpuptk(ji,jj,jk) = 1. / zpsiuptk * rno3 * 2. * xqnpmin(ji,jj,jk) / (zration + rtrn)  &
-               &                   * MAX(0., (1. - zratchl * zpicochl / 12. ) ) 
-               !
-               zlim1    = max(0., (zration - 2. * xqnpmin(ji,jj,jk) )  &
-               &          / (xqnpmax(ji,jj,jk) - 2. * xqnpmin(ji,jj,jk) ) ) * xqnpmax(ji,jj,jk)  &
-               &          / (zration + rtrn)
-               zlim3    = MAX( 0.,( zratiof - zqfemp ) / qfpopt )
-               xlimpfe(ji,jj,jk) = MIN( 1., zlim3 )
-               xlimpic(ji,jj,jk) = MIN( 1., zlim1, zlim3 )
-               !
-               !   Michaelis-Menten Limitation term for nutrients Diatoms
-               !   ------------------------------------------------------
-               zfalim = (1.-fadiat) / fadiat 
-               xdiatnh4(ji,jj,jk) = (1. - fadiat) * trb(ji,jj,jk,jpnh4) / ( zfalim * zconc1dnh4 + trb(ji,jj,jk,jpnh4) )
-               xdiatno3(ji,jj,jk) = (1. - fadiat) * trb(ji,jj,jk,jpno3) / ( zfalim * zconc1d + trb(ji,jj,jk,jpno3) )  &
-               &                    * (1. - xdiatnh4(ji,jj,jk))
-               !
-               zfalim = (1.-fadiatp) / fadiatp
-               xdiatpo4(ji,jj,jk) = (1. - fadiatp) * trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + zfalim * zconc0dpo4 )
-               xdiatdop(ji,jj,jk) = trb(ji,jj,jk,jpdop) / ( trb(ji,jj,jk,jpdop) + xkdoc )  &
-               &                    * ( 1.0 - xdiatpo4(ji,jj,jk) )
-               xdiatdop(ji,jj,jk) = 0.
-               !
-               zfalim = (1.-fadiatf) / fadiatf
-               xdiatfer(ji,jj,jk) = (1. - fadiatf) * biron(ji,jj,jk) / ( biron(ji,jj,jk) + zfalim * zconcdfe )
-               !
-               zratiof   = trb(ji,jj,jk,jpdfe) * z1_trndia
-               zqfemd = xcoef1 * zdiatchl + xcoef2 + xcoef3 * xdiatno3(ji,jj,jk)
-               !
-               zration   = trb(ji,jj,jk,jpndi) * z1_trndia
-               zration = MIN(xqndmax(ji,jj,jk), MAX( 2. * xqndmin(ji,jj,jk), zration ))
-               fvduptk(ji,jj,jk) = 1. / zpsiuptk * rno3 * 2. * xqndmin(ji,jj,jk) / (zration + rtrn)   &
-               &                   * MAX(0., (1. - zratchl * zdiatchl / 12. ) ) 
-               !
-               zlim1    = max(0., (zration - 2. * xqndmin(ji,jj,jk) )    &
-               &          / (xqndmax(ji,jj,jk) - 2. * xqndmin(ji,jj,jk) ) )   &
-               &          * xqndmax(ji,jj,jk) / (zration + rtrn)
-               zlim3    = trb(ji,jj,jk,jpsil) / ( trb(ji,jj,jk,jpsil) + xksi(ji,jj) )
-               zlim4    = MAX( 0., ( zratiof - zqfemd ) / qfdopt )
-               xlimdfe(ji,jj,jk) = MIN( 1., zlim4 )
-               xlimdia(ji,jj,jk) = MIN( 1., zlim1, zlim3, zlim4 )
-               xlimsi(ji,jj,jk)  = MIN( zlim1, zlim4 )
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         ! 
+         ! Tuning of the iron concentration to a minimum level that is set to the detection limit
+         !-------------------------------------
+         zno3    = tr(ji,jj,jk,jpno3,Kbb) / 40.e-6
+         zferlim = MAX( 3e-11 * zno3 * zno3, 5e-12 )
+         zferlim = MIN( zferlim, 7e-11 )
+         tr(ji,jj,jk,jpfer,Kbb) = MAX( tr(ji,jj,jk,jpfer,Kbb), zferlim )
+
+         ! Computation of the mean relative size of each community
+         ! -------------------------------------------------------
+         z1_trnphy   = 1. / ( tr(ji,jj,jk,jpphy,Kbb) + rtrn )
+         z1_trnpic   = 1. / ( tr(ji,jj,jk,jppic,Kbb) + rtrn )
+         z1_trndia   = 1. / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+         znanochl = tr(ji,jj,jk,jpnch,Kbb) * z1_trnphy
+         zpicochl = tr(ji,jj,jk,jppch,Kbb) * z1_trnpic
+         zdiatchl = tr(ji,jj,jk,jpdch,Kbb) * z1_trndia
+
+         ! Computation of a variable Ks for iron on diatoms taking into account
+         ! that increasing biomass is made of generally bigger cells
+         !------------------------------------------------
+         zsized            = sized(ji,jj,jk)**0.81
+         zconcdfe          = concdfer * zsized
+         zconc1d           = concdno3 * zsized
+         zconc1dnh4        = concdnh4 * zsized
+         zconc0dpo4        = concdpo4 * zsized
+
+         zsizep            = 1.
+         zconcpfe          = concpfer * zsizep
+         zconc0p           = concpno3 * zsizep
+         zconc0pnh4        = concpnh4 * zsizep
+         zconc0ppo4        = concppo4 * zsizep
+
+         zsizen            = 1.
+         zconcnfe          = concnfer * zsizen
+         zconc0n           = concnno3 * zsizen
+         zconc0nnh4        = concnnh4 * zsizen
+         zconc0npo4        = concnpo4 * zsizen
+
+         ! Allometric variations of the minimum and maximum quotas
+         ! From Talmy et al. (2014) and Maranon et al. (2013)
+         ! -------------------------------------------------------
+         xqnnmin(ji,jj,jk) = qnnmin
+         xqnnmax(ji,jj,jk) = qnnmax
+         xqndmin(ji,jj,jk) = qndmin * sized(ji,jj,jk)**(-0.27) 
+         xqndmax(ji,jj,jk) = qndmax
+         xqnpmin(ji,jj,jk) = qnpmin
+         xqnpmax(ji,jj,jk) = qnpmax
+
+         ! Computation of the optimal allocation parameters
+         ! Based on the different papers by Pahlow et al., and Smith et al.
+         ! -----------------------------------------------------------------
+         znutlim = MAX( tr(ji,jj,jk,jpnh4,Kbb) / zconc0nnh4,    &
+           &         tr(ji,jj,jk,jpno3,Kbb) / zconc0n)
+         fanano = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+         znutlim = tr(ji,jj,jk,jppo4,Kbb) / zconc0npo4
+         fananop = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+         znutlim = biron(ji,jj,jk) / zconcnfe
+         fananof = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+         znutlim = MAX( tr(ji,jj,jk,jpnh4,Kbb) / zconc0pnh4,    &
+           &         tr(ji,jj,jk,jpno3,Kbb) / zconc0p)
+         fapico = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+         znutlim = tr(ji,jj,jk,jppo4,Kbb) / zconc0ppo4
+         fapicop = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+         znutlim = biron(ji,jj,jk) / zconcpfe
+         fapicof = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+         znutlim = MAX( tr(ji,jj,jk,jpnh4,Kbb) / zconc1dnh4,    &
+           &         tr(ji,jj,jk,jpno3,Kbb) / zconc1d )
+         fadiat = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+         znutlim = tr(ji,jj,jk,jppo4,Kbb) / zconc0dpo4
+         fadiatp = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+         znutlim = biron(ji,jj,jk) / zconcdfe
+         fadiatf = MAX(0.01, MIN(0.99, 1. / ( SQRT(znutlim) + 1.) ) )
+         !
+         ! Michaelis-Menten Limitation term for nutrients Small bacteria
+         ! -------------------------------------------------------------
+         zbactnh4 = tr(ji,jj,jk,jpnh4,Kbb) / ( concbnh4 + tr(ji,jj,jk,jpnh4,Kbb) )
+         zbactno3 = tr(ji,jj,jk,jpno3,Kbb) / ( concbno3 + tr(ji,jj,jk,jpno3,Kbb) ) * (1. - zbactnh4)
+         !
+         zlim1    = zbactno3 + zbactnh4
+         zlim2    = tr(ji,jj,jk,jppo4,Kbb) / ( tr(ji,jj,jk,jppo4,Kbb) + concbpo4)
+         zlim3    = biron(ji,jj,jk) / ( concbfe + biron(ji,jj,jk) )
+         zlim4    = tr(ji,jj,jk,jpdoc,Kbb) / ( xkdoc   + tr(ji,jj,jk,jpdoc,Kbb) )
+         xlimbacl(ji,jj,jk) = MIN( zlim1, zlim2, zlim3 )
+         xlimbac (ji,jj,jk) = xlimbacl(ji,jj,jk) * zlim4
+         !
+         ! Michaelis-Menten Limitation term for nutrients Small flagellates
+         ! -----------------------------------------------
+         zfalim = (1.-fanano) / fanano
+         xnanonh4(ji,jj,jk) = (1. - fanano) * tr(ji,jj,jk,jpnh4,Kbb) / ( zfalim * zconc0nnh4 + tr(ji,jj,jk,jpnh4,Kbb) )
+         xnanono3(ji,jj,jk) = (1. - fanano) * tr(ji,jj,jk,jpno3,Kbb) / ( zfalim * zconc0n + tr(ji,jj,jk,jpno3,Kbb) )  &
+         &                    * (1. - xnanonh4(ji,jj,jk))
+         !
+         zfalim = (1.-fananop) / fananop
+         xnanopo4(ji,jj,jk) = (1. - fananop) * tr(ji,jj,jk,jppo4,Kbb) / ( tr(ji,jj,jk,jppo4,Kbb) + zfalim * zconc0npo4 )
+         xnanodop(ji,jj,jk) = tr(ji,jj,jk,jpdop,Kbb) / ( tr(ji,jj,jk,jpdop,Kbb) + xkdoc )   &
+         &                    * ( 1.0 - xnanopo4(ji,jj,jk) )
+         xnanodop(ji,jj,jk) = 0.
+         !
+         zfalim = (1.-fananof) / fananof
+         xnanofer(ji,jj,jk) = (1. - fananof) * biron(ji,jj,jk) / ( biron(ji,jj,jk) + zfalim * zconcnfe )
+         !
+         zratiof   = tr(ji,jj,jk,jpnfe,Kbb) * z1_trnphy
+         zqfemn = xcoef1 * znanochl + xcoef2 + xcoef3 * xnanono3(ji,jj,jk)
+         !
+         zration = tr(ji,jj,jk,jpnph,Kbb) * z1_trnphy
+         zration = MIN(xqnnmax(ji,jj,jk), MAX( 2. * xqnnmin(ji,jj,jk), zration ))
+         fvnuptk(ji,jj,jk) = 1. / zpsiuptk * rno3 * 2. * xqnnmin(ji,jj,jk) / (zration + rtrn)  &
+         &                   * MAX(0., (1. - zratchl * znanochl / 12. ) )
+         !
+         zlim1    = max(0., (zration - 2. * xqnnmin(ji,jj,jk) )  &
+         &          / (xqnnmax(ji,jj,jk) - 2. * xqnnmin(ji,jj,jk) ) ) * xqnnmax(ji,jj,jk)  &
+         &          / (zration + rtrn)
+         zlim3    = MAX( 0.,( zratiof - zqfemn ) / qfnopt ) 
+         xlimnfe(ji,jj,jk) = MIN( 1., zlim3 )
+         xlimphy(ji,jj,jk) = MIN( 1., zlim1, zlim3 )
+         !
+         ! Michaelis-Menten Limitation term for nutrients picophytoplankton
+         ! ----------------------------------------------------------------
+         zfalim = (1.-fapico) / fapico 
+         xpiconh4(ji,jj,jk) = (1. - fapico) * tr(ji,jj,jk,jpnh4,Kbb) / ( zfalim * zconc0pnh4 + tr(ji,jj,jk,jpnh4,Kbb) )
+         xpicono3(ji,jj,jk) = (1. - fapico) * tr(ji,jj,jk,jpno3,Kbb) / ( zfalim * zconc0p + tr(ji,jj,jk,jpno3,Kbb) )  &
+         &                    * (1. - xpiconh4(ji,jj,jk))
+         !
+         zfalim = (1.-fapicop) / fapicop 
+         xpicopo4(ji,jj,jk) = (1. - fapicop) * tr(ji,jj,jk,jppo4,Kbb) / ( tr(ji,jj,jk,jppo4,Kbb) + zfalim * zconc0ppo4 )
+         xpicodop(ji,jj,jk) = tr(ji,jj,jk,jpdop,Kbb) / ( tr(ji,jj,jk,jpdop,Kbb) + xkdoc )   &
+         &                    * ( 1.0 - xpicopo4(ji,jj,jk) )
+         xpicodop(ji,jj,jk) = 0.
+         !
+         zfalim = (1.-fapicof) / fapicof
+         xpicofer(ji,jj,jk) = (1. - fapicof) * biron(ji,jj,jk) / ( biron(ji,jj,jk) + zfalim * zconcpfe )
+         !
+         zratiof   = tr(ji,jj,jk,jppfe,Kbb) * z1_trnpic
+         zqfemp = xcoef1 * zpicochl + xcoef2 + xcoef3 * xpicono3(ji,jj,jk)
+         !
+         zration   = tr(ji,jj,jk,jpnpi,Kbb) * z1_trnpic
+         zration = MIN(xqnpmax(ji,jj,jk), MAX( 2. * xqnpmin(ji,jj,jk), zration ))
+         fvpuptk(ji,jj,jk) = 1. / zpsiuptk * rno3 * 2. * xqnpmin(ji,jj,jk) / (zration + rtrn)  &
+         &                   * MAX(0., (1. - zratchl * zpicochl / 12. ) ) 
+         !
+         zlim1    = max(0., (zration - 2. * xqnpmin(ji,jj,jk) )  &
+         &          / (xqnpmax(ji,jj,jk) - 2. * xqnpmin(ji,jj,jk) ) ) * xqnpmax(ji,jj,jk)  &
+         &          / (zration + rtrn)
+         zlim3    = MAX( 0.,( zratiof - zqfemp ) / qfpopt )
+         xlimpfe(ji,jj,jk) = MIN( 1., zlim3 )
+         xlimpic(ji,jj,jk) = MIN( 1., zlim1, zlim3 )
+         !
+         !   Michaelis-Menten Limitation term for nutrients Diatoms
+         !   ------------------------------------------------------
+         zfalim = (1.-fadiat) / fadiat 
+         xdiatnh4(ji,jj,jk) = (1. - fadiat) * tr(ji,jj,jk,jpnh4,Kbb) / ( zfalim * zconc1dnh4 + tr(ji,jj,jk,jpnh4,Kbb) )
+         xdiatno3(ji,jj,jk) = (1. - fadiat) * tr(ji,jj,jk,jpno3,Kbb) / ( zfalim * zconc1d + tr(ji,jj,jk,jpno3,Kbb) )  &
+         &                    * (1. - xdiatnh4(ji,jj,jk))
+         !
+         zfalim = (1.-fadiatp) / fadiatp
+         xdiatpo4(ji,jj,jk) = (1. - fadiatp) * tr(ji,jj,jk,jppo4,Kbb) / ( tr(ji,jj,jk,jppo4,Kbb) + zfalim * zconc0dpo4 )
+         xdiatdop(ji,jj,jk) = tr(ji,jj,jk,jpdop,Kbb) / ( tr(ji,jj,jk,jpdop,Kbb) + xkdoc )  &
+         &                    * ( 1.0 - xdiatpo4(ji,jj,jk) )
+         xdiatdop(ji,jj,jk) = 0.
+         !
+         zfalim = (1.-fadiatf) / fadiatf
+         xdiatfer(ji,jj,jk) = (1. - fadiatf) * biron(ji,jj,jk) / ( biron(ji,jj,jk) + zfalim * zconcdfe )
+         !
+         zratiof   = tr(ji,jj,jk,jpdfe,Kbb) * z1_trndia
+         zqfemd = xcoef1 * zdiatchl + xcoef2 + xcoef3 * xdiatno3(ji,jj,jk)
+         !
+         zration   = tr(ji,jj,jk,jpndi,Kbb) * z1_trndia
+         zration = MIN(xqndmax(ji,jj,jk), MAX( 2. * xqndmin(ji,jj,jk), zration ))
+         fvduptk(ji,jj,jk) = 1. / zpsiuptk * rno3 * 2. * xqndmin(ji,jj,jk) / (zration + rtrn)   &
+         &                   * MAX(0., (1. - zratchl * zdiatchl / 12. ) ) 
+         !
+         zlim1    = max(0., (zration - 2. * xqndmin(ji,jj,jk) )    &
+         &          / (xqndmax(ji,jj,jk) - 2. * xqndmin(ji,jj,jk) ) )   &
+         &          * xqndmax(ji,jj,jk) / (zration + rtrn)
+         zlim3    = tr(ji,jj,jk,jpsil,Kbb) / ( tr(ji,jj,jk,jpsil,Kbb) + xksi(ji,jj) + rtrn )
+         zlim4    = MAX( 0., ( zratiof - zqfemd ) / qfdopt )
+         xlimdfe(ji,jj,jk) = MIN( 1., zlim4 )
+         xlimdia(ji,jj,jk) = MIN( 1., zlim1, zlim3, zlim4 )
+         xlimsi(ji,jj,jk)  = MIN( zlim1, zlim4 )
+      END_3D
       !
       ! Compute the phosphorus quota values. It is based on Litchmann et al., 2004 and Daines et al, 2013.
@@ -319,101 +318,89 @@
       ! phytoplankton (see Daines et al., 2013). 
       ! --------------------------------------------------------------------------------------------------
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! Size estimation of nanophytoplankton
-               ! ------------------------------------
-               zfvn = 2. * fvnuptk(ji,jj,jk)
-               sizen(ji,jj,jk) = MAX(1., MIN(xsizern, 1.0 / ( MAX(rtrn, zfvn) ) ) )
-
-               ! N/P ratio of nanophytoplankton
-               ! ------------------------------
-               zfuptk = 0.23 * zfvn
-               zrpho = 2.24 * trb(ji,jj,jk,jpnch) / ( trb(ji,jj,jk,jpnph) * rno3 * 15. + rtrn )
-               zrass = 1. - 0.2 - zrpho - zfuptk
-               xqpnmax(ji,jj,jk) = ( zfuptk + zrpho ) * 0.0128 * 16. + zrass * 1./ 7.2 * 16.
-               xqpnmax(ji,jj,jk) = xqpnmax(ji,jj,jk) * trb(ji,jj,jk,jpnph) / ( trb(ji,jj,jk,jpphy) + rtrn ) + 0.13
-               xqpnmin(ji,jj,jk) = 0.13 + 0.23 * 0.0128 * 16.
-
-               ! Size estimation of picophytoplankton
-               ! ------------------------------------
-               zfvn = 2. * fvpuptk(ji,jj,jk)
-               sizep(ji,jj,jk) = MAX(1., MIN(xsizerp, 1.0 / ( MAX(rtrn, zfvn) ) ) )
-
-               ! N/P ratio of picophytoplankton
-               ! ------------------------------
-               zfuptk = 0.35 * zfvn
-               zrpho = 2.24 * trb(ji,jj,jk,jppch) / ( trb(ji,jj,jk,jpnpi) * rno3 * 15. + rtrn )
-               zrass = 1. - 0.4 - zrpho - zfuptk
-               xqppmax(ji,jj,jk) =  (zrpho + zfuptk) * 0.0128 * 16. + zrass * 1./ 9. * 16.
-               xqppmax(ji,jj,jk) = xqppmax(ji,jj,jk) * trb(ji,jj,jk,jpnpi) / ( trb(ji,jj,jk,jppic) + rtrn ) + 0.13
-               xqppmin(ji,jj,jk) = 0.13
-
-               ! Size estimation of diatoms
-               ! --------------------------
-               zfvn = 2. * fvduptk(ji,jj,jk)
-               sized(ji,jj,jk) = MAX(1., MIN(xsizerd, 1.0 / ( MAX(rtrn, zfvn) ) ) )
-               zcoef = trb(ji,jj,jk,jpdia) - MIN(xsizedia, trb(ji,jj,jk,jpdia) )
-               sized(ji,jj,jk) = 1. + xsizerd * zcoef *1E6 / ( 1. + zcoef * 1E6 )
-
-               ! N/P ratio of diatoms
-               ! --------------------
-               zfuptk = 0.2 * zfvn
-               zrpho = 2.24 * trb(ji,jj,jk,jpdch) / ( trb(ji,jj,jk,jpndi) * rno3 * 15. + rtrn )
-               zrass = 1. - 0.2 - zrpho - zfuptk
-               xqpdmax(ji,jj,jk) = ( zfuptk + zrpho ) * 0.0128 * 16. + zrass * 1./ 7.2 * 16.
-               xqpdmax(ji,jj,jk) = xqpdmax(ji,jj,jk) * trb(ji,jj,jk,jpndi) / ( trb(ji,jj,jk,jpdia) + rtrn ) + 0.13
-               xqpdmin(ji,jj,jk) = 0.13 + 0.2 * 0.0128 * 16.
-
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         ! Size estimation of nanophytoplankton
+         ! ------------------------------------
+         zfvn = 2. * fvnuptk(ji,jj,jk)
+         sizen(ji,jj,jk) = MAX(1., MIN(xsizern, 1.0 / ( MAX(rtrn, zfvn) ) ) )
+
+         ! N/P ratio of nanophytoplankton
+         ! ------------------------------
+         zfuptk = 0.23 * zfvn
+         zrpho = 2.24 * tr(ji,jj,jk,jpnch,Kbb) / ( tr(ji,jj,jk,jpnph,Kbb) * rno3 * 15. + rtrn )
+         zrass = 1. - 0.2 - zrpho - zfuptk
+         xqpnmax(ji,jj,jk) = ( zfuptk + zrpho ) * 0.0128 * 16. + zrass * 1./ 7.2 * 16.
+         xqpnmax(ji,jj,jk) = xqpnmax(ji,jj,jk) * tr(ji,jj,jk,jpnph,Kbb) / ( tr(ji,jj,jk,jpphy,Kbb) + rtrn ) + 0.13
+         xqpnmin(ji,jj,jk) = 0.13 + 0.23 * 0.0128 * 16.
+
+         ! Size estimation of picophytoplankton
+         ! ------------------------------------
+         zfvn = 2. * fvpuptk(ji,jj,jk)
+         sizep(ji,jj,jk) = MAX(1., MIN(xsizerp, 1.0 / ( MAX(rtrn, zfvn) ) ) )
+
+         ! N/P ratio of picophytoplankton
+         ! ------------------------------
+         zfuptk = 0.35 * zfvn
+         zrpho = 2.24 * tr(ji,jj,jk,jppch,Kbb) / ( tr(ji,jj,jk,jpnpi,Kbb) * rno3 * 15. + rtrn )
+         zrass = 1. - 0.4 - zrpho - zfuptk
+         xqppmax(ji,jj,jk) =  (zrpho + zfuptk) * 0.0128 * 16. + zrass * 1./ 9. * 16.
+         xqppmax(ji,jj,jk) = xqppmax(ji,jj,jk) * tr(ji,jj,jk,jpnpi,Kbb) / ( tr(ji,jj,jk,jppic,Kbb) + rtrn ) + 0.13
+         xqppmin(ji,jj,jk) = 0.13
+
+         ! Size estimation of diatoms
+         ! --------------------------
+         zfvn = 2. * fvduptk(ji,jj,jk)
+         sized(ji,jj,jk) = MAX(1., MIN(xsizerd, 1.0 / ( MAX(rtrn, zfvn) ) ) )
+         zcoef = tr(ji,jj,jk,jpdia,Kbb) - MIN(xsizedia, tr(ji,jj,jk,jpdia,Kbb) )
+         sized(ji,jj,jk) = 1. + xsizerd * zcoef *1E6 / ( 1. + zcoef * 1E6 )
+
+         ! N/P ratio of diatoms
+         ! --------------------
+         zfuptk = 0.2 * zfvn
+         zrpho = 2.24 * tr(ji,jj,jk,jpdch,Kbb) / ( tr(ji,jj,jk,jpndi,Kbb) * rno3 * 15. + rtrn )
+         zrass = 1. - 0.2 - zrpho - zfuptk
+         xqpdmax(ji,jj,jk) = ( zfuptk + zrpho ) * 0.0128 * 16. + zrass * 1./ 7.2 * 16.
+         xqpdmax(ji,jj,jk) = xqpdmax(ji,jj,jk) * tr(ji,jj,jk,jpndi,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn ) + 0.13
+         xqpdmin(ji,jj,jk) = 0.13 + 0.2 * 0.0128 * 16.
+
+      END_3D
 
       ! Compute the fraction of nanophytoplankton that is made of calcifiers
       ! --------------------------------------------------------------------
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zlim1 =  trb(ji,jj,jk,jpnh4) / ( trb(ji,jj,jk,jpnh4) + concnnh4 ) + trb(ji,jj,jk,jpno3)    &
-               &        / ( trb(ji,jj,jk,jpno3) + concnno3 ) * ( 1.0 - trb(ji,jj,jk,jpnh4)   &
-               &        / ( trb(ji,jj,jk,jpnh4) + concnnh4 ) )
-               zlim2  = trb(ji,jj,jk,jppo4) / ( trb(ji,jj,jk,jppo4) + concnpo4 )
-               zlim3  = trb(ji,jj,jk,jpfer) / ( trb(ji,jj,jk,jpfer) +  5.E-11 ) 
-               ztem1  = MAX( 0., tsn(ji,jj,jk,jp_tem) )
-               ztem2  = tsn(ji,jj,jk,jp_tem) - 10.
-               zetot1 = MAX( 0., etot(ji,jj,jk) - 1.) / ( 4. + etot(ji,jj,jk) ) * 20. / ( 20. + etot(ji,jj,jk) ) 
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zlim1 =  tr(ji,jj,jk,jpnh4,Kbb) / ( tr(ji,jj,jk,jpnh4,Kbb) + concnnh4 ) + tr(ji,jj,jk,jpno3,Kbb)    &
+         &        / ( tr(ji,jj,jk,jpno3,Kbb) + concnno3 ) * ( 1.0 - tr(ji,jj,jk,jpnh4,Kbb)   &
+         &        / ( tr(ji,jj,jk,jpnh4,Kbb) + concnnh4 ) )
+         zlim2  = tr(ji,jj,jk,jppo4,Kbb) / ( tr(ji,jj,jk,jppo4,Kbb) + concnpo4 )
+         zlim3  = tr(ji,jj,jk,jpfer,Kbb) / ( tr(ji,jj,jk,jpfer,Kbb) +  5.E-11 ) 
+         ztem1  = MAX( 0., ts(ji,jj,jk,jp_tem,Kmm) )
+         ztem2  = ts(ji,jj,jk,jp_tem,Kmm) - 10.
+         zetot1 = MAX( 0., etot(ji,jj,jk) - 1.) / ( 4. + etot(ji,jj,jk) ) * 20. / ( 20. + etot(ji,jj,jk) ) 
 
 !               xfracal(ji,jj,jk) = caco3r * MIN( zlim1, zlim2, zlim3 )                  &
-               xfracal(ji,jj,jk) = caco3r                 &
-               &                   * ztem1 / ( 1. + ztem1 ) * MAX( 1., trb(ji,jj,jk,jpphy)*1E6 )   &
-                  &                * ( 1. + EXP(-ztem2 * ztem2 / 25. ) )         &
-                  &                * zetot1 * MIN( 1., 50. / ( hmld(ji,jj) + rtrn ) )
-               xfracal(ji,jj,jk) = MAX( 0.02, MIN( 0.8 , xfracal(ji,jj,jk) ) )
-            END DO
-         END DO
-      END DO
-      !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! denitrification factor computed from O2 levels
-               nitrfac(ji,jj,jk) = MAX(  0.e0, 0.4 * ( 6.e-6  - trb(ji,jj,jk,jpoxy) )    &
-                  &                                / ( oxymin + trb(ji,jj,jk,jpoxy) )  )
-               nitrfac(ji,jj,jk) = MIN( 1., nitrfac(ji,jj,jk) )
-            END DO
-         END DO
-      END DO
+         xfracal(ji,jj,jk) = caco3r                 &
+         &                   * ztem1 / ( 1. + ztem1 ) * MAX( 1., tr(ji,jj,jk,jpphy,Kbb)*1E6 )   &
+            &                * ( 1. + EXP(-ztem2 * ztem2 / 25. ) )         &
+            &                * zetot1 * MIN( 1., 50. / ( hmld(ji,jj) + rtrn ) )
+         xfracal(ji,jj,jk) = MAX( 0.02, MIN( 0.8 , xfracal(ji,jj,jk) ) )
+      END_3D
+      !
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         ! denitrification factor computed from O2 levels
+         nitrfac(ji,jj,jk) = MAX(  0.e0, 0.4 * ( 6.e-6  - tr(ji,jj,jk,jpoxy,Kbb) )    &
+            &                                / ( oxymin + tr(ji,jj,jk,jpoxy,Kbb) )  )
+         nitrfac(ji,jj,jk) = MIN( 1., nitrfac(ji,jj,jk) )
+      END_3D
       !
       IF( lk_iomput .AND. knt == nrdttrc ) THEN        ! save output diagnostics
-        IF( iom_use( "xfracal" ) ) CALL iom_put( "xfracal", xfracal(:,:,:) * tmask(:,:,:) )  ! euphotic layer deptht
-        IF( iom_use( "LNnut"   ) ) CALL iom_put( "LNnut"  , xlimphy(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
-        IF( iom_use( "LPnut"   ) ) CALL iom_put( "LPnut"  , xlimpic(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
-        IF( iom_use( "LDnut"   ) ) CALL iom_put( "LDnut"  , xlimdia(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
-        IF( iom_use( "LNFe"    ) ) CALL iom_put( "LNFe"   , xlimnfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
-        IF( iom_use( "LPFe"    ) ) CALL iom_put( "LPFe"   , xlimpfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
-        IF( iom_use( "LDFe"    ) ) CALL iom_put( "LDFe"   , xlimdfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
-        IF( iom_use( "SIZEN"   ) ) CALL iom_put( "SIZEN"  , sizen(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
-        IF( iom_use( "SIZEP"   ) ) CALL iom_put( "SIZEP"  , sizep(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
-        IF( iom_use( "SIZED"   ) ) CALL iom_put( "SIZED"  , sized(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+        CALL iom_put( "xfracal", xfracal(:,:,:) * tmask(:,:,:) )  ! euphotic layer deptht
+        CALL iom_put( "LNnut"  , xlimphy(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
+        CALL iom_put( "LPnut"  , xlimpic(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
+        CALL iom_put( "LDnut"  , xlimdia(:,:,:) * tmask(:,:,:) )  ! Nutrient limitation term
+        CALL iom_put( "LNFe"   , xlimnfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+        CALL iom_put( "LPFe"   , xlimpfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+        CALL iom_put( "LDFe"   , xlimdfe(:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+        CALL iom_put( "SIZEN"  , sizen  (:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+        CALL iom_put( "SIZEP"  , sizep  (:,:,:) * tmask(:,:,:) )  ! Iron limitation term
+        CALL iom_put( "SIZED"  , sized  (:,:,:) * tmask(:,:,:) )  ! Iron limitation term
       ENDIF
       !
@@ -448,11 +435,9 @@
       !!----------------------------------------------------------------------
       !
-      REWIND( numnatp_ref )              ! Namelist nampislim in reference namelist : Pisces nutrient limitation parameters
       READ  ( numnatp_ref, namp5zlim, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampislim in reference namelist', lwp )
-      !
-      REWIND( numnatp_cfg )              ! Namelist nampislim in configuration namelist : Pisces nutrient limitation parameters 
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampislim in reference namelist' )
+      !
       READ  ( numnatp_cfg, namp5zlim, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampislim in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampislim in configuration namelist' )
       IF(lwm) WRITE ( numonp, namp5zlim )
       !
@@ -489,11 +474,9 @@
       ENDIF
 
-      REWIND( numnatp_ref )              ! Namelist nampislim in reference namelist : Pisces nutrient limitation parameters
       READ  ( numnatp_ref, namp5zquota, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampisquota in reference namelist', lwp )
-      !
-      REWIND( numnatp_cfg )              ! Namelist nampislim in configuration namelist : Pisces nutrient limitation parameters 
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampisquota in reference namelist' )
+      !
       READ  ( numnatp_cfg, namp5zquota, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampisquota in configuration namelist', lwp )
+904   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampisquota in configuration namelist' )
       IF(lwm) WRITE ( numonp, namp5zquota )
       !
@@ -526,5 +509,15 @@
       zpsiuptk = 2.3 * rno3
       !
-      nitrfac (:,:,:) = 0._wp
+      nitrfac(:,:,jpk) = 0._wp
+      xfracal(:,:,jpk) = 0._wp
+      xlimphy(:,:,jpk) = 0._wp
+      xlimpic(:,:,jpk) = 0._wp
+      xlimdia(:,:,jpk) = 0._wp
+      xlimnfe(:,:,jpk) = 0._wp
+      xlimpfe(:,:,jpk) = 0._wp
+      xlimdfe(:,:,jpk) = 0._wp
+      sizen  (:,:,jpk) = 0._wp
+      sizep  (:,:,jpk) = 0._wp
+      sized  (:,:,jpk) = 0._wp
       !
    END SUBROUTINE p5z_lim_init
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zmeso.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zmeso.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zmeso.F90	(revision 13463)
@@ -15,5 +15,5 @@
    USE trc             !  passive tracers common variables 
    USE sms_pisces      !  PISCES Source Minus Sink variables
-   USE prtctl_trc      !  print control for debugging
+   USE prtctl          !  print control for debugging
    USE iom             !  I/O manager
 
@@ -51,4 +51,6 @@
    LOGICAL,  PUBLIC ::  bmetexc2     !: Use of excess carbon for respiration
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -59,5 +61,5 @@
 CONTAINS
 
-   SUBROUTINE p5z_meso( kt, knt )
+   SUBROUTINE p5z_meso( kt, knt, Kbb, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p5z_meso  ***
@@ -67,5 +69,6 @@
       !! ** Method  : - ???
       !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt, knt ! ocean time step
+      INTEGER, INTENT(in) ::   kt, knt    ! ocean time step
+      INTEGER, INTENT(in)  ::  Kbb, Krhs  ! time level indices
       INTEGER  :: ji, jj, jk
       REAL(wp) :: zcompadi, zcompaph, zcompapoc, zcompaz, zcompam, zcompames
@@ -86,6 +89,5 @@
       CHARACTER (len=25) :: charout
       REAL(wp) :: zrfact2, zmetexcess
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zgrazing, zfezoo2
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: zw3d, zz2ligprod
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zgrazing, zfezoo2,  zz2ligprod
 
       !!---------------------------------------------------------------------
@@ -93,291 +95,270 @@
       IF( ln_timing )   CALL timing_start('p5z_meso')
       !
-
-      zgrazing(:,:,:) = 0._wp
-      zfezoo2 (:,:,:) = 0._wp
-      !
-      IF (ln_ligand) THEN
-         ALLOCATE( zz2ligprod(jpi,jpj,jpk) )
-         zz2ligprod(:,:,:) = 0._wp
-      ENDIF
-
       zmetexcess = 0.0
       IF ( bmetexc2 ) zmetexcess = 1.0
 
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zcompam   = MAX( ( trb(ji,jj,jk,jpmes) - 1.e-9 ), 0.e0 )
-               zfact     = xstep * tgfunc2(ji,jj,jk) * zcompam
-
-               !   Michaelis-Menten mortality rates of mesozooplankton
-               !   ---------------------------------------------------
-               zrespz   = resrat2 * zfact * ( trb(ji,jj,jk,jpmes) / ( xkmort + trb(ji,jj,jk,jpmes) )  &
-               &          + 3. * nitrfac(ji,jj,jk) )
-
-               !   Zooplankton mortality. A square function has been selected with
-               !   no real reason except that it seems to be more stable and may mimic predation
-               !   ---------------------------------------------------------------
-               ztortz   = mzrat2 * 1.e6 * zfact * trb(ji,jj,jk,jpmes) * (1. - nitrfac(ji,jj,jk))
-
-               !   Computation of the abundance of the preys
-               !   A threshold can be specified in the namelist
-               !   --------------------------------------------
-               zcompadi  = MAX( ( trb(ji,jj,jk,jpdia) - xthresh2dia ), 0.e0 )
-               zcompaz   = MAX( ( trb(ji,jj,jk,jpzoo) - xthresh2zoo ), 0.e0 )
-               zcompaph  = MAX( ( trb(ji,jj,jk,jpphy) - xthresh2phy ), 0.e0 )
-               zcompapoc = MAX( ( trb(ji,jj,jk,jppoc) - xthresh2poc ), 0.e0 )
-               zcompames = MAX( ( trb(ji,jj,jk,jpmes) - xthresh2mes ), 0.e0 )
-
-               !   Mesozooplankton grazing
-               !   ------------------------
-               zfood     = xpref2d * zcompadi + xpref2z * zcompaz + xpref2n * zcompaph + xpref2c * zcompapoc   &
-               &           + xpref2m * zcompames 
-               zfoodlim  = MAX( 0., zfood - MIN( 0.5 * zfood, xthresh2 ) )
-               zdenom    = zfoodlim / ( xkgraz2 + zfoodlim )
-               zgraze2   = grazrat2 * xstep * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jpmes) * (1. - nitrfac(ji,jj,jk)) 
-
-               !   An active switching parameterization is used here.
-               !   We don't use the KTW parameterization proposed by 
-               !   Vallina et al. because it tends to produce to steady biomass
-               !   composition and the variance of Chl is too low as it grazes
-               !   too strongly on winning organisms. Thus, instead of a square
-               !   a 1.5 power value is used which decreases the pressure on the
-               !   most abundant species
-               !   ------------------------------------------------------------  
-               ztmp1 = xpref2n * zcompaph**1.5
-               ztmp2 = xpref2m * zcompames**1.5
-               ztmp3 = xpref2c * zcompapoc**1.5
-               ztmp4 = xpref2d * zcompadi**1.5
-               ztmp5 = xpref2z * zcompaz**1.5
-               ztmptot = ztmp1 + ztmp2 + ztmp3 + ztmp4 + ztmp5 + rtrn
-               ztmp1 = ztmp1 / ztmptot
-               ztmp2 = ztmp2 / ztmptot
-               ztmp3 = ztmp3 / ztmptot
-               ztmp4 = ztmp4 / ztmptot
-               ztmp5 = ztmp5 / ztmptot
-
-               !   Mesozooplankton regular grazing on the different preys
-               !   ------------------------------------------------------
-               zgrazdc   = zgraze2 * ztmp4 * zdenom
-               zgrazdn   = zgrazdc * trb(ji,jj,jk,jpndi) / ( trb(ji,jj,jk,jpdia) + rtrn)
-               zgrazdp   = zgrazdc * trb(ji,jj,jk,jppdi) / ( trb(ji,jj,jk,jpdia) + rtrn)
-               zgrazdf   = zgrazdc * trb(ji,jj,jk,jpdfe) / ( trb(ji,jj,jk,jpdia) + rtrn)
-               zgrazz    = zgraze2 * ztmp5 * zdenom
-               zgrazm    = zgraze2 * ztmp2 * zdenom
-               zgraznc   = zgraze2 * ztmp1 * zdenom
-               zgraznn   = zgraznc * trb(ji,jj,jk,jpnph) / ( trb(ji,jj,jk,jpphy) + rtrn)
-               zgraznp   = zgraznc * trb(ji,jj,jk,jppph) / ( trb(ji,jj,jk,jpphy) + rtrn)
-               zgraznf   = zgraznc * trb(ji,jj,jk,jpnfe) / ( trb(ji,jj,jk,jpphy) + rtrn)
-               zgrazpoc  = zgraze2 * ztmp3 * zdenom
-               zgrazpon  = zgrazpoc * trb(ji,jj,jk,jppon) / ( trb(ji,jj,jk,jppoc) + rtrn)
-               zgrazpop  = zgrazpoc * trb(ji,jj,jk,jppop) / ( trb(ji,jj,jk,jppoc) + rtrn)
-               zgrazpof  = zgrazpoc * trb(ji,jj,jk,jpsfe) / ( trb(ji,jj,jk,jppoc) + rtrn)
-
-               !   Mesozooplankton flux feeding on GOC
-               !   ----------------------------------
-               zgrazffeg = grazflux  * xstep * wsbio4(ji,jj,jk)      &
-               &           * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jpgoc) * trb(ji,jj,jk,jpmes)  &
-               &           * (1. - nitrfac(ji,jj,jk))
-               zgrazfffg = zgrazffeg * trb(ji,jj,jk,jpbfe) / (trb(ji,jj,jk,jpgoc) + rtrn)
-               zgrazffng = zgrazffeg * trb(ji,jj,jk,jpgon) / (trb(ji,jj,jk,jpgoc) + rtrn)
-               zgrazffpg = zgrazffeg * trb(ji,jj,jk,jpgop) / (trb(ji,jj,jk,jpgoc) + rtrn)
-               zgrazffep = grazflux  * xstep *  wsbio3(ji,jj,jk)     &
-               &           * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jppoc) * trb(ji,jj,jk,jpmes)   &
-               &           * (1. - nitrfac(ji,jj,jk))
-               zgrazfffp = zgrazffep * trb(ji,jj,jk,jpsfe) / (trb(ji,jj,jk,jppoc) + rtrn)
-               zgrazffnp = zgrazffep * trb(ji,jj,jk,jppon) / (trb(ji,jj,jk,jppoc) + rtrn)
-               zgrazffpp = zgrazffep * trb(ji,jj,jk,jppop) / (trb(ji,jj,jk,jppoc) + rtrn)
-               !
-               zgraztotc  = zgrazdc + zgrazz + zgraznc + zgrazm + zgrazpoc + zgrazffep + zgrazffeg
-
-               !   Compute the proportion of filter feeders
-               !   ----------------------------------------  
-               zproport  = (zgrazffep + zgrazffeg)/(rtrn + zgraztotc)
-
-               !   Compute fractionation of aggregates. It is assumed that 
-               !   diatoms based aggregates are more prone to fractionation
-               !   since they are more porous (marine snow instead of fecal pellets)
-               !   ----------------------------------------------------------------
-               zratio    = trb(ji,jj,jk,jpgsi) / ( trb(ji,jj,jk,jpgoc) + rtrn )
-               zratio2   = zratio * zratio
-               zfracc    = zproport * grazflux  * xstep * wsbio4(ji,jj,jk)      &
-               &          * trb(ji,jj,jk,jpgoc) * trb(ji,jj,jk,jpmes)          &
-               &          * ( 0.2 + 3.8 * zratio2 / ( 1.**2 + zratio2 ) )
-               zfracfe   = zfracc * trb(ji,jj,jk,jpbfe) / (trb(ji,jj,jk,jpgoc) + rtrn)
-               zfracn    = zfracc * trb(ji,jj,jk,jpgon) / (trb(ji,jj,jk,jpgoc) + rtrn)
-               zfracp    = zfracc * trb(ji,jj,jk,jpgop) / (trb(ji,jj,jk,jpgoc) + rtrn)
-
-               zgrazffep = zproport * zgrazffep   ;   zgrazffeg = zproport * zgrazffeg
-               zgrazfffp = zproport * zgrazfffp   ;   zgrazfffg = zproport * zgrazfffg
-               zgrazffnp = zproport * zgrazffnp   ;   zgrazffng = zproport * zgrazffng
-               zgrazffpp = zproport * zgrazffpp   ;   zgrazffpg = zproport * zgrazffpg
-
-               zgraztotc  = zgrazdc + zgrazz + zgraznc + zgrazm + zgrazpoc + zgrazffep + zgrazffeg
-               zgraztotf  = zgrazdf + zgraznf + ( zgrazz + zgrazm ) * ferat3 + zgrazpof &
-               &            + zgrazfffp + zgrazfffg
-               zgraztotn  = zgrazdn + (zgrazm + zgrazz) * no3rat3 + zgraznn + zgrazpon  &
-               &            + zgrazffnp + zgrazffng
-               zgraztotp  = zgrazdp + (zgrazz + zgrazm) * po4rat3 + zgraznp + zgrazpop  &
-               &            + zgrazffpp + zgrazffpg
-
-
-               ! Total grazing ( grazing by microzoo is already computed in p5zmicro )
-               zgrazing(ji,jj,jk) = zgraztotc
-
-               !   Stoichiometruc ratios of the food ingested by zooplanton 
-               !   --------------------------------------------------------
-               zgrasratf  =  (zgraztotf + rtrn) / ( zgraztotc + rtrn )
-               zgrasratn  =  (zgraztotn + rtrn) / ( zgraztotc + rtrn )
-               zgrasratp  =  (zgraztotp + rtrn) / ( zgraztotc + rtrn )
-
-               !   Growth efficiency is made a function of the quality 
-               !   and the quantity of the preys
-               !   ---------------------------------------------------
-               zepshert  = MIN( 1., zgrasratn/ no3rat3, zgrasratp/ po4rat3, zgrasratf / ferat3)
-               zbeta     = MAX(0., (epsher2 - epsher2min) )
-               zepsherf  = epsher2min + zbeta / ( 1.0 + 0.04E6 * 12. * zfood * zbeta )
-               zepsherv  = zepsherf * zepshert
-
-               !   Respiration of mesozooplankton
-               !   Excess carbon in the food is used preferentially
-               !   ----------------  ------------------------------
-               zexcess  = zgraztotc * zepsherf * (1.0 - zepshert) * zmetexcess 
-               zbasresb = MAX(0., zrespz - zexcess)
-               zbasresi = zexcess + MIN(0., zrespz - zexcess)
-               zrespirc = srespir2 * zepsherv * zgraztotc + zbasresb
-
-               !   When excess carbon is used, the other elements in excess
-               !   are also used proportionally to their abundance
-               !   --------------------------------------------------------
-               zexcess  = ( zgrasratn/ no3rat3 - zepshert ) / ( 1.0 - zepshert + rtrn)
-               zbasresn = zbasresi * zexcess * zgrasratn
-               zexcess  = ( zgrasratp/ po4rat3 - zepshert ) / ( 1.0 - zepshert + rtrn)
-               zbasresp = zbasresi * zexcess * zgrasratp
-               zexcess  = ( zgrasratf/ ferat3 - zepshert ) / ( 1.0 - zepshert + rtrn)
-               zbasresf = zbasresi * zexcess * zgrasratf
-
-               !   Voiding of the excessive elements as organic matter
-               !   --------------------------------------------------------
-               zgradoct = (1. - unass2c - zepsherv) * zgraztotc - zbasresi
-               zgradont = (1. - unass2n) * zgraztotn - zepsherv * no3rat3 * zgraztotc - zbasresn
-               zgradopt = (1. - unass2p) * zgraztotp - zepsherv * po4rat3 * zgraztotc - zbasresp
-               zgrareft = (1. - unass2c) * zgraztotf - zepsherv * ferat3 * zgraztotc - zbasresf
-               ztmp1   = ( 1. - epsher2 - unass2c ) /( 1. - 0.8 * epsher2 ) * ztortz
-               zgradoc = (zgradoct + ztmp1) * ssigma2
-               zgradon = (zgradont + no3rat3 * ztmp1) * ssigma2
-               zgradop = (zgradopt + po4rat3 * ztmp1) * ssigma2
-               zgratmp = 0.2 * epsher2 /( 1. - 0.8 * epsher2 ) * ztortz
-
-               !  Since only semilabile DOM is represented in PISCES
-               !  part of DOM is in fact labile and is then released
-               !  as dissolved inorganic compounds (ssigma2)
-               !  --------------------------------------------------
-               zgrarem = zgratmp + ( zgradoct + ztmp1 ) * (1.0 - ssigma2)
-               zgraren = no3rat3 * zgratmp + ( zgradont + no3rat3 * ztmp1 ) * (1.0 - ssigma2)
-               zgrarep = po4rat3 * zgratmp + ( zgradopt + po4rat3 * ztmp1 ) * (1.0 - ssigma2)
-               zgraref = zgrareft + ferat3 * ( ztmp1 + zgratmp )
-
-               !   Defecation as a result of non assimilated products
-               !   --------------------------------------------------
-               zgrapoc  = zgraztotc * unass2c + unass2c / ( 1. - 0.8 * epsher2 ) * ztortz
-               zgrapon  = zgraztotn * unass2n + no3rat3 * unass2n / ( 1. - 0.8 * epsher2 ) * ztortz
-               zgrapop  = zgraztotp * unass2p + po4rat3 * unass2p / ( 1. - 0.8 * epsher2 ) * ztortz
-               zgrapof  = zgraztotf * unass2c + ferat3  * unass2c / ( 1. - 0.8 * epsher2 ) * ztortz
-
-               !  Addition of respiration to the release of inorganic nutrients
-               !  -------------------------------------------------------------
-               zgrarem = zgrarem + zbasresi + zrespirc
-               zgraren = zgraren + zbasresn + zrespirc * no3rat3
-               zgrarep = zgrarep + zbasresp + zrespirc * po4rat3
-               zgraref = zgraref + zbasresf + zrespirc * ferat3
-
-               !   Update the arrays TRA which contain the biological sources and
-               !   sinks
-               !   --------------------------------------------------------------
-               tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) + zgrarep 
-               tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + zgraren
-               tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + zgradoc
-               !
-               IF( ln_ligand ) THEN
-                  tra(ji,jj,jk,jplgw)  = tra(ji,jj,jk,jplgw) + zgradoc * ldocz
-                  zz2ligprod(ji,jj,jk) = zgradoc * ldocz
-               ENDIF
-               !
-               tra(ji,jj,jk,jpdon) = tra(ji,jj,jk,jpdon) + zgradon
-               tra(ji,jj,jk,jpdop) = tra(ji,jj,jk,jpdop) + zgradop
-               tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) - o2ut * zgrarem
-               tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + zgraref
-               zfezoo2(ji,jj,jk)   = zgraref
-               tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) + zgrarem
-               tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) + rno3 * zgraren
-               tra(ji,jj,jk,jpmes) = tra(ji,jj,jk,jpmes) + zepsherv * zgraztotc - zrespirc   &
-               &                     - ztortz - zgrazm
-               tra(ji,jj,jk,jpdia) = tra(ji,jj,jk,jpdia) - zgrazdc
-               tra(ji,jj,jk,jpndi) = tra(ji,jj,jk,jpndi) - zgrazdn
-               tra(ji,jj,jk,jppdi) = tra(ji,jj,jk,jppdi) - zgrazdp
-               tra(ji,jj,jk,jpdfe) = tra(ji,jj,jk,jpdfe) - zgrazdf
-               tra(ji,jj,jk,jpzoo) = tra(ji,jj,jk,jpzoo) - zgrazz
-               tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) - zgraznc
-               tra(ji,jj,jk,jpnph) = tra(ji,jj,jk,jpnph) - zgraznn
-               tra(ji,jj,jk,jppph) = tra(ji,jj,jk,jppph) - zgraznp
-               tra(ji,jj,jk,jpnfe) = tra(ji,jj,jk,jpnfe) - zgraznf
-               tra(ji,jj,jk,jpnch) = tra(ji,jj,jk,jpnch) - zgraznc * trb(ji,jj,jk,jpnch) / ( trb(ji,jj,jk,jpphy) + rtrn )
-               tra(ji,jj,jk,jpdch) = tra(ji,jj,jk,jpdch) - zgrazdc * trb(ji,jj,jk,jpdch) / ( trb(ji,jj,jk,jpdia) + rtrn )
-               tra(ji,jj,jk,jpdsi) = tra(ji,jj,jk,jpdsi) - zgrazdc * trb(ji,jj,jk,jpdsi) / ( trb(ji,jj,jk,jpdia) + rtrn )
-               tra(ji,jj,jk,jpgsi) = tra(ji,jj,jk,jpgsi) + zgrazdc * trb(ji,jj,jk,jpdsi) / ( trb(ji,jj,jk,jpdia) + rtrn )
-
-               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) - zgrazpoc - zgrazffep + zfracc
-               prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + zfracc
-               conspoc(ji,jj,jk) = conspoc(ji,jj,jk) - zgrazpoc - zgrazffep
-               tra(ji,jj,jk,jppon) = tra(ji,jj,jk,jppon) - zgrazpon - zgrazffnp + zfracn
-               tra(ji,jj,jk,jppop) = tra(ji,jj,jk,jppop) - zgrazpop - zgrazffpp + zfracp
-               tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) - zgrazffeg + zgrapoc - zfracc
-               prodgoc(ji,jj,jk) = prodgoc(ji,jj,jk) + zgrapoc
-               consgoc(ji,jj,jk) = consgoc(ji,jj,jk) - zgrazffeg - zfracc
-               tra(ji,jj,jk,jpgon) = tra(ji,jj,jk,jpgon) - zgrazffng + zgrapon - zfracn
-               tra(ji,jj,jk,jpgop) = tra(ji,jj,jk,jpgop) - zgrazffpg + zgrapop - zfracp
-               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) - zgrazpof - zgrazfffp + zfracfe
-               tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) - zgrazfffg + zgrapof - zfracfe
-               zfracal = trb(ji,jj,jk,jpcal) / ( trb(ji,jj,jk,jpgoc) + rtrn )
-               zgrazcal = zgrazffeg * (1. - part2) * zfracal
-
-               !  calcite production
-               !  ------------------
-               zprcaca = xfracal(ji,jj,jk) * zgraznc
-               prodcal(ji,jj,jk) = prodcal(ji,jj,jk) + zprcaca  ! prodcal=prodcal(nanophy)+prodcal(microzoo)+prodcal(mesozoo)
-               zprcaca = part2 * zprcaca
-               tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) + zgrazcal - zprcaca
-               tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) + 2. * ( zgrazcal - zprcaca )
-               tra(ji,jj,jk,jpcal) = tra(ji,jj,jk,jpcal) - zgrazcal + zprcaca
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zcompam   = MAX( ( tr(ji,jj,jk,jpmes,Kbb) - 1.e-9 ), 0.e0 )
+         zfact     = xstep * tgfunc2(ji,jj,jk) * zcompam
+
+         !   Michaelis-Menten mortality rates of mesozooplankton
+         !   ---------------------------------------------------
+         zrespz   = resrat2 * zfact * ( tr(ji,jj,jk,jpmes,Kbb) / ( xkmort + tr(ji,jj,jk,jpmes,Kbb) )  &
+         &          + 3. * nitrfac(ji,jj,jk) )
+
+         !   Zooplankton mortality. A square function has been selected with
+         !   no real reason except that it seems to be more stable and may mimic predation
+         !   ---------------------------------------------------------------
+         ztortz   = mzrat2 * 1.e6 * zfact * tr(ji,jj,jk,jpmes,Kbb) * (1. - nitrfac(ji,jj,jk))
+
+         !   Computation of the abundance of the preys
+         !   A threshold can be specified in the namelist
+         !   --------------------------------------------
+         zcompadi  = MAX( ( tr(ji,jj,jk,jpdia,Kbb) - xthresh2dia ), 0.e0 )
+         zcompaz   = MAX( ( tr(ji,jj,jk,jpzoo,Kbb) - xthresh2zoo ), 0.e0 )
+         zcompaph  = MAX( ( tr(ji,jj,jk,jpphy,Kbb) - xthresh2phy ), 0.e0 )
+         zcompapoc = MAX( ( tr(ji,jj,jk,jppoc,Kbb) - xthresh2poc ), 0.e0 )
+         zcompames = MAX( ( tr(ji,jj,jk,jpmes,Kbb) - xthresh2mes ), 0.e0 )
+
+         !   Mesozooplankton grazing
+         !   ------------------------
+         zfood     = xpref2d * zcompadi + xpref2z * zcompaz + xpref2n * zcompaph + xpref2c * zcompapoc   &
+         &           + xpref2m * zcompames 
+         zfoodlim  = MAX( 0., zfood - MIN( 0.5 * zfood, xthresh2 ) )
+         zdenom    = zfoodlim / ( xkgraz2 + zfoodlim )
+         zgraze2   = grazrat2 * xstep * tgfunc2(ji,jj,jk) * tr(ji,jj,jk,jpmes,Kbb) * (1. - nitrfac(ji,jj,jk)) 
+
+         !   An active switching parameterization is used here.
+         !   We don't use the KTW parameterization proposed by 
+         !   Vallina et al. because it tends to produce to steady biomass
+         !   composition and the variance of Chl is too low as it grazes
+         !   too strongly on winning organisms. Thus, instead of a square
+         !   a 1.5 power value is used which decreases the pressure on the
+         !   most abundant species
+         !   ------------------------------------------------------------  
+         ztmp1 = xpref2n * zcompaph**1.5
+         ztmp2 = xpref2m * zcompames**1.5
+         ztmp3 = xpref2c * zcompapoc**1.5
+         ztmp4 = xpref2d * zcompadi**1.5
+         ztmp5 = xpref2z * zcompaz**1.5
+         ztmptot = ztmp1 + ztmp2 + ztmp3 + ztmp4 + ztmp5 + rtrn
+         ztmp1 = ztmp1 / ztmptot
+         ztmp2 = ztmp2 / ztmptot
+         ztmp3 = ztmp3 / ztmptot
+         ztmp4 = ztmp4 / ztmptot
+         ztmp5 = ztmp5 / ztmptot
+
+         !   Mesozooplankton regular grazing on the different preys
+         !   ------------------------------------------------------
+         zgrazdc   = zgraze2 * ztmp4 * zdenom
+         zgrazdn   = zgrazdc * tr(ji,jj,jk,jpndi,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn)
+         zgrazdp   = zgrazdc * tr(ji,jj,jk,jppdi,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn)
+         zgrazdf   = zgrazdc * tr(ji,jj,jk,jpdfe,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn)
+         zgrazz    = zgraze2 * ztmp5 * zdenom
+         zgrazm    = zgraze2 * ztmp2 * zdenom
+         zgraznc   = zgraze2 * ztmp1 * zdenom
+         zgraznn   = zgraznc * tr(ji,jj,jk,jpnph,Kbb) / ( tr(ji,jj,jk,jpphy,Kbb) + rtrn)
+         zgraznp   = zgraznc * tr(ji,jj,jk,jppph,Kbb) / ( tr(ji,jj,jk,jpphy,Kbb) + rtrn)
+         zgraznf   = zgraznc * tr(ji,jj,jk,jpnfe,Kbb) / ( tr(ji,jj,jk,jpphy,Kbb) + rtrn)
+         zgrazpoc  = zgraze2 * ztmp3 * zdenom
+         zgrazpon  = zgrazpoc * tr(ji,jj,jk,jppon,Kbb) / ( tr(ji,jj,jk,jppoc,Kbb) + rtrn)
+         zgrazpop  = zgrazpoc * tr(ji,jj,jk,jppop,Kbb) / ( tr(ji,jj,jk,jppoc,Kbb) + rtrn)
+         zgrazpof  = zgrazpoc * tr(ji,jj,jk,jpsfe,Kbb) / ( tr(ji,jj,jk,jppoc,Kbb) + rtrn)
+
+         !   Mesozooplankton flux feeding on GOC
+         !   ----------------------------------
+         zgrazffeg = grazflux  * xstep * wsbio4(ji,jj,jk)      &
+         &           * tgfunc2(ji,jj,jk) * tr(ji,jj,jk,jpgoc,Kbb) * tr(ji,jj,jk,jpmes,Kbb)  &
+         &           * (1. - nitrfac(ji,jj,jk))
+         zgrazfffg = zgrazffeg * tr(ji,jj,jk,jpbfe,Kbb) / (tr(ji,jj,jk,jpgoc,Kbb) + rtrn)
+         zgrazffng = zgrazffeg * tr(ji,jj,jk,jpgon,Kbb) / (tr(ji,jj,jk,jpgoc,Kbb) + rtrn)
+         zgrazffpg = zgrazffeg * tr(ji,jj,jk,jpgop,Kbb) / (tr(ji,jj,jk,jpgoc,Kbb) + rtrn)
+         zgrazffep = grazflux  * xstep *  wsbio3(ji,jj,jk)     &
+         &           * tgfunc2(ji,jj,jk) * tr(ji,jj,jk,jppoc,Kbb) * tr(ji,jj,jk,jpmes,Kbb)   &
+         &           * (1. - nitrfac(ji,jj,jk))
+         zgrazfffp = zgrazffep * tr(ji,jj,jk,jpsfe,Kbb) / (tr(ji,jj,jk,jppoc,Kbb) + rtrn)
+         zgrazffnp = zgrazffep * tr(ji,jj,jk,jppon,Kbb) / (tr(ji,jj,jk,jppoc,Kbb) + rtrn)
+         zgrazffpp = zgrazffep * tr(ji,jj,jk,jppop,Kbb) / (tr(ji,jj,jk,jppoc,Kbb) + rtrn)
+         !
+         zgraztotc  = zgrazdc + zgrazz + zgraznc + zgrazm + zgrazpoc + zgrazffep + zgrazffeg
+
+         !   Compute the proportion of filter feeders
+         !   ----------------------------------------  
+         zproport  = (zgrazffep + zgrazffeg)/(rtrn + zgraztotc)
+
+         !   Compute fractionation of aggregates. It is assumed that 
+         !   diatoms based aggregates are more prone to fractionation
+         !   since they are more porous (marine snow instead of fecal pellets)
+         !   ----------------------------------------------------------------
+         zratio    = tr(ji,jj,jk,jpgsi,Kbb) / ( tr(ji,jj,jk,jpgoc,Kbb) + rtrn )
+         zratio2   = zratio * zratio
+         zfracc    = zproport * grazflux  * xstep * wsbio4(ji,jj,jk)      &
+         &          * tr(ji,jj,jk,jpgoc,Kbb) * tr(ji,jj,jk,jpmes,Kbb)          &
+         &          * ( 0.2 + 3.8 * zratio2 / ( 1.**2 + zratio2 ) )
+         zfracfe   = zfracc * tr(ji,jj,jk,jpbfe,Kbb) / (tr(ji,jj,jk,jpgoc,Kbb) + rtrn)
+         zfracn    = zfracc * tr(ji,jj,jk,jpgon,Kbb) / (tr(ji,jj,jk,jpgoc,Kbb) + rtrn)
+         zfracp    = zfracc * tr(ji,jj,jk,jpgop,Kbb) / (tr(ji,jj,jk,jpgoc,Kbb) + rtrn)
+
+         zgrazffep = zproport * zgrazffep   ;   zgrazffeg = zproport * zgrazffeg
+         zgrazfffp = zproport * zgrazfffp   ;   zgrazfffg = zproport * zgrazfffg
+         zgrazffnp = zproport * zgrazffnp   ;   zgrazffng = zproport * zgrazffng
+         zgrazffpp = zproport * zgrazffpp   ;   zgrazffpg = zproport * zgrazffpg
+
+         zgraztotc  = zgrazdc + zgrazz + zgraznc + zgrazm + zgrazpoc + zgrazffep + zgrazffeg
+         zgraztotf  = zgrazdf + zgraznf + ( zgrazz + zgrazm ) * ferat3 + zgrazpof &
+         &            + zgrazfffp + zgrazfffg
+         zgraztotn  = zgrazdn + (zgrazm + zgrazz) * no3rat3 + zgraznn + zgrazpon  &
+         &            + zgrazffnp + zgrazffng
+         zgraztotp  = zgrazdp + (zgrazz + zgrazm) * po4rat3 + zgraznp + zgrazpop  &
+         &            + zgrazffpp + zgrazffpg
+
+
+         ! Total grazing ( grazing by microzoo is already computed in p5zmicro )
+         zgrazing(ji,jj,jk) = zgraztotc
+
+         !   Stoichiometruc ratios of the food ingested by zooplanton 
+         !   --------------------------------------------------------
+         zgrasratf  =  (zgraztotf + rtrn) / ( zgraztotc + rtrn )
+         zgrasratn  =  (zgraztotn + rtrn) / ( zgraztotc + rtrn )
+         zgrasratp  =  (zgraztotp + rtrn) / ( zgraztotc + rtrn )
+
+         !   Growth efficiency is made a function of the quality 
+         !   and the quantity of the preys
+         !   ---------------------------------------------------
+         zepshert  = MIN( 1., zgrasratn/ no3rat3, zgrasratp/ po4rat3, zgrasratf / ferat3)
+         zbeta     = MAX(0., (epsher2 - epsher2min) )
+         zepsherf  = epsher2min + zbeta / ( 1.0 + 0.04E6 * 12. * zfood * zbeta )
+         zepsherv  = zepsherf * zepshert
+
+         !   Respiration of mesozooplankton
+         !   Excess carbon in the food is used preferentially
+         !   ----------------  ------------------------------
+         zexcess  = zgraztotc * zepsherf * (1.0 - zepshert) * zmetexcess 
+         zbasresb = MAX(0., zrespz - zexcess)
+         zbasresi = zexcess + MIN(0., zrespz - zexcess)
+         zrespirc = srespir2 * zepsherv * zgraztotc + zbasresb
+
+         !   When excess carbon is used, the other elements in excess
+         !   are also used proportionally to their abundance
+         !   --------------------------------------------------------
+         zexcess  = ( zgrasratn/ no3rat3 - zepshert ) / ( 1.0 - zepshert + rtrn)
+         zbasresn = zbasresi * zexcess * zgrasratn
+         zexcess  = ( zgrasratp/ po4rat3 - zepshert ) / ( 1.0 - zepshert + rtrn)
+         zbasresp = zbasresi * zexcess * zgrasratp
+         zexcess  = ( zgrasratf/ ferat3 - zepshert ) / ( 1.0 - zepshert + rtrn)
+         zbasresf = zbasresi * zexcess * zgrasratf
+
+         !   Voiding of the excessive elements as organic matter
+         !   --------------------------------------------------------
+         zgradoct = (1. - unass2c - zepsherv) * zgraztotc - zbasresi
+         zgradont = (1. - unass2n) * zgraztotn - zepsherv * no3rat3 * zgraztotc - zbasresn
+         zgradopt = (1. - unass2p) * zgraztotp - zepsherv * po4rat3 * zgraztotc - zbasresp
+         zgrareft = (1. - unass2c) * zgraztotf - zepsherv * ferat3 * zgraztotc - zbasresf
+         ztmp1   = ( 1. - epsher2 - unass2c ) /( 1. - 0.8 * epsher2 ) * ztortz
+         zgradoc = (zgradoct + ztmp1) * ssigma2
+         zgradon = (zgradont + no3rat3 * ztmp1) * ssigma2
+         zgradop = (zgradopt + po4rat3 * ztmp1) * ssigma2
+         zgratmp = 0.2 * epsher2 /( 1. - 0.8 * epsher2 ) * ztortz
+
+         !  Since only semilabile DOM is represented in PISCES
+         !  part of DOM is in fact labile and is then released
+         !  as dissolved inorganic compounds (ssigma2)
+         !  --------------------------------------------------
+         zgrarem = zgratmp + ( zgradoct + ztmp1 ) * (1.0 - ssigma2)
+         zgraren = no3rat3 * zgratmp + ( zgradont + no3rat3 * ztmp1 ) * (1.0 - ssigma2)
+         zgrarep = po4rat3 * zgratmp + ( zgradopt + po4rat3 * ztmp1 ) * (1.0 - ssigma2)
+         zgraref = zgrareft + ferat3 * ( ztmp1 + zgratmp )
+
+         !   Defecation as a result of non assimilated products
+         !   --------------------------------------------------
+         zgrapoc  = zgraztotc * unass2c + unass2c / ( 1. - 0.8 * epsher2 ) * ztortz
+         zgrapon  = zgraztotn * unass2n + no3rat3 * unass2n / ( 1. - 0.8 * epsher2 ) * ztortz
+         zgrapop  = zgraztotp * unass2p + po4rat3 * unass2p / ( 1. - 0.8 * epsher2 ) * ztortz
+         zgrapof  = zgraztotf * unass2c + ferat3  * unass2c / ( 1. - 0.8 * epsher2 ) * ztortz
+
+         !  Addition of respiration to the release of inorganic nutrients
+         !  -------------------------------------------------------------
+         zgrarem = zgrarem + zbasresi + zrespirc
+         zgraren = zgraren + zbasresn + zrespirc * no3rat3
+         zgrarep = zgrarep + zbasresp + zrespirc * po4rat3
+         zgraref = zgraref + zbasresf + zrespirc * ferat3
+
+         !   Update the arrays TRA which contain the biological sources and
+         !   sinks
+         !   --------------------------------------------------------------
+         tr(ji,jj,jk,jppo4,Krhs) = tr(ji,jj,jk,jppo4,Krhs) + zgrarep 
+         tr(ji,jj,jk,jpnh4,Krhs) = tr(ji,jj,jk,jpnh4,Krhs) + zgraren
+         tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) + zgradoc
+         !
+         IF( ln_ligand ) THEN
+            tr(ji,jj,jk,jplgw,Krhs)  = tr(ji,jj,jk,jplgw,Krhs) + zgradoc * ldocz
+            zz2ligprod(ji,jj,jk) = zgradoc * ldocz
+         ENDIF
+         !
+         tr(ji,jj,jk,jpdon,Krhs) = tr(ji,jj,jk,jpdon,Krhs) + zgradon
+         tr(ji,jj,jk,jpdop,Krhs) = tr(ji,jj,jk,jpdop,Krhs) + zgradop
+         tr(ji,jj,jk,jpoxy,Krhs) = tr(ji,jj,jk,jpoxy,Krhs) - o2ut * zgrarem
+         tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) + zgraref
+         zfezoo2(ji,jj,jk)   = zgraref
+         tr(ji,jj,jk,jpdic,Krhs) = tr(ji,jj,jk,jpdic,Krhs) + zgrarem
+         tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) + rno3 * zgraren
+         tr(ji,jj,jk,jpmes,Krhs) = tr(ji,jj,jk,jpmes,Krhs) + zepsherv * zgraztotc - zrespirc   &
+         &                     - ztortz - zgrazm
+         tr(ji,jj,jk,jpdia,Krhs) = tr(ji,jj,jk,jpdia,Krhs) - zgrazdc
+         tr(ji,jj,jk,jpndi,Krhs) = tr(ji,jj,jk,jpndi,Krhs) - zgrazdn
+         tr(ji,jj,jk,jppdi,Krhs) = tr(ji,jj,jk,jppdi,Krhs) - zgrazdp
+         tr(ji,jj,jk,jpdfe,Krhs) = tr(ji,jj,jk,jpdfe,Krhs) - zgrazdf
+         tr(ji,jj,jk,jpzoo,Krhs) = tr(ji,jj,jk,jpzoo,Krhs) - zgrazz
+         tr(ji,jj,jk,jpphy,Krhs) = tr(ji,jj,jk,jpphy,Krhs) - zgraznc
+         tr(ji,jj,jk,jpnph,Krhs) = tr(ji,jj,jk,jpnph,Krhs) - zgraznn
+         tr(ji,jj,jk,jppph,Krhs) = tr(ji,jj,jk,jppph,Krhs) - zgraznp
+         tr(ji,jj,jk,jpnfe,Krhs) = tr(ji,jj,jk,jpnfe,Krhs) - zgraznf
+         tr(ji,jj,jk,jpnch,Krhs) = tr(ji,jj,jk,jpnch,Krhs) - zgraznc * tr(ji,jj,jk,jpnch,Kbb) / ( tr(ji,jj,jk,jpphy,Kbb) + rtrn )
+         tr(ji,jj,jk,jpdch,Krhs) = tr(ji,jj,jk,jpdch,Krhs) - zgrazdc * tr(ji,jj,jk,jpdch,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+         tr(ji,jj,jk,jpdsi,Krhs) = tr(ji,jj,jk,jpdsi,Krhs) - zgrazdc * tr(ji,jj,jk,jpdsi,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+         tr(ji,jj,jk,jpgsi,Krhs) = tr(ji,jj,jk,jpgsi,Krhs) + zgrazdc * tr(ji,jj,jk,jpdsi,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+
+         tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) - zgrazpoc - zgrazffep + zfracc
+         prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + zfracc
+         conspoc(ji,jj,jk) = conspoc(ji,jj,jk) - zgrazpoc - zgrazffep
+         tr(ji,jj,jk,jppon,Krhs) = tr(ji,jj,jk,jppon,Krhs) - zgrazpon - zgrazffnp + zfracn
+         tr(ji,jj,jk,jppop,Krhs) = tr(ji,jj,jk,jppop,Krhs) - zgrazpop - zgrazffpp + zfracp
+         tr(ji,jj,jk,jpgoc,Krhs) = tr(ji,jj,jk,jpgoc,Krhs) - zgrazffeg + zgrapoc - zfracc
+         prodgoc(ji,jj,jk) = prodgoc(ji,jj,jk) + zgrapoc
+         consgoc(ji,jj,jk) = consgoc(ji,jj,jk) - zgrazffeg - zfracc
+         tr(ji,jj,jk,jpgon,Krhs) = tr(ji,jj,jk,jpgon,Krhs) - zgrazffng + zgrapon - zfracn
+         tr(ji,jj,jk,jpgop,Krhs) = tr(ji,jj,jk,jpgop,Krhs) - zgrazffpg + zgrapop - zfracp
+         tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) - zgrazpof - zgrazfffp + zfracfe
+         tr(ji,jj,jk,jpbfe,Krhs) = tr(ji,jj,jk,jpbfe,Krhs) - zgrazfffg + zgrapof - zfracfe
+         zfracal = tr(ji,jj,jk,jpcal,Kbb) / ( tr(ji,jj,jk,jpgoc,Kbb) + rtrn )
+         zgrazcal = zgrazffeg * (1. - part2) * zfracal
+
+         !  calcite production
+         !  ------------------
+         zprcaca = xfracal(ji,jj,jk) * zgraznc
+         prodcal(ji,jj,jk) = prodcal(ji,jj,jk) + zprcaca  ! prodcal=prodcal(nanophy)+prodcal(microzoo)+prodcal(mesozoo)
+         zprcaca = part2 * zprcaca
+         tr(ji,jj,jk,jpdic,Krhs) = tr(ji,jj,jk,jpdic,Krhs) + zgrazcal - zprcaca
+         tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) + 2. * ( zgrazcal - zprcaca )
+         tr(ji,jj,jk,jpcal,Krhs) = tr(ji,jj,jk,jpcal,Krhs) - zgrazcal + zprcaca
+      END_3D
       !
       IF( lk_iomput .AND. knt == nrdttrc ) THEN
-         ALLOCATE( zw3d(jpi,jpj,jpk) )
-         IF( iom_use( "GRAZ2" ) ) THEN
-            zw3d(:,:,:) = zgrazing(:,:,:) * 1.e+3 * rfact2r * tmask(:,:,:)  !   Total grazing of phyto by zooplankton
-            CALL iom_put( "GRAZ2", zw3d )
+        CALL iom_put( "PCAL"  , prodcal(:,:,:) * 1.e+3  * rfact2r * tmask(:,:,:) )  !  Calcite production 
+        IF( iom_use("GRAZ2") ) THEN  !   Total grazing of phyto by zooplankton
+           zgrazing(:,:,jpk) = 0._wp ;  CALL iom_put( "GRAZ2" , zgrazing(:,:,:) * 1.e+3  * rfact2r * tmask(:,:,:) ) 
          ENDIF
-         IF( iom_use( "PCAL" ) ) THEN
-            zw3d(:,:,:) = prodcal(:,:,:) * 1.e+3 * rfact2r * tmask(:,:,:)   !  Calcite production
-            CALL iom_put( "PCAL", zw3d )
+         IF( iom_use("FEZOO2") ) THEN  
+           zfezoo2 (:,:,jpk) = 0._wp ; CALL iom_put( "FEZOO2", zfezoo2(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:) )
          ENDIF
-         IF( iom_use( "FEZOO2" ) ) THEN
-            zw3d(:,:,:) = zfezoo2(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:)   !
-            CALL iom_put( "FEZOO2", zw3d )
+         IF( ln_ligand ) THEN
+            zz2ligprod(:,:,jpk) = 0._wp ; CALL iom_put( "LPRODZ2", zz2ligprod(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:)  )
          ENDIF
-         IF( iom_use( "LPRODZ2" ) .AND. ln_ligand )  THEN
-            zw3d(:,:,:) = zz2ligprod(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:)
-            CALL iom_put( "LPRODZ2"  , zw3d )
-         ENDIF
-         DEALLOCATE( zw3d )
       ENDIF
       !
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
         WRITE(charout, FMT="('meso')")
-        CALL prt_ctl_trc_info(charout)
-        CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+        CALL prt_ctl_info( charout, cdcomp = 'top' )
+        CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -407,11 +388,9 @@
       !!----------------------------------------------------------------------
       !
-      REWIND( numnatp_ref )              ! Namelist nampismes in reference namelist : Pisces mesozooplankton
       READ  ( numnatp_ref, namp5zmes, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampismes in reference namelist', lwp )
-      !
-      REWIND( numnatp_cfg )              ! Namelist nampismes in configuration namelist : Pisces mesozooplankton
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampismes in reference namelist' )
+      !
       READ  ( numnatp_cfg, namp5zmes, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampismes in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nampismes in configuration namelist' )
       IF(lwm) WRITE ( numonp, namp5zmes )
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zmicro.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zmicro.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zmicro.F90	(revision 13463)
@@ -18,5 +18,5 @@
    USE p5zlim          !  Phytoplankton limitation terms
    USE iom             !  I/O manager
-   USE prtctl_trc      !  print control for debugging
+   USE prtctl          !  print control for debugging
 
    IMPLICIT NONE
@@ -52,4 +52,6 @@
    LOGICAL,  PUBLIC ::  bmetexc     !: Use of excess carbon for respiration
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -60,5 +62,5 @@
 CONTAINS
 
-   SUBROUTINE p5z_micro( kt, knt )
+   SUBROUTINE p5z_micro( kt, knt, Kbb, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p5z_micro  ***
@@ -70,4 +72,5 @@
       INTEGER, INTENT(in) ::  kt  ! ocean time step
       INTEGER, INTENT(in) ::  knt 
+      INTEGER, INTENT(in) ::  Kbb, Krhs      ! time level indices
       !
       INTEGER  :: ji, jj, jk
@@ -84,6 +87,5 @@
       REAL(wp) :: zgrazdc, zgrazdn, zgrazdp, zgrazdf, zgraznf, zgrazz
       REAL(wp) :: zgrazpc, zgrazpn, zgrazpp, zgrazpf, zbeta, zrfact2, zmetexcess
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zgrazing, zfezoo
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: zw3d, zzligprod
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zgrazing, zfezoo, zzligprod
       CHARACTER (len=25) :: charout
       !!---------------------------------------------------------------------
@@ -91,235 +93,219 @@
       IF( ln_timing )   CALL timing_start('p5z_micro')
       !
-      IF (ln_ligand) THEN
-         ALLOCATE( zzligprod(jpi,jpj,jpk) )
-         zzligprod(:,:,:) = 0._wp
-      ENDIF
-      !
       zmetexcess = 0.0
       IF ( bmetexc ) zmetexcess = 1.0
       !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zcompaz = MAX( ( trb(ji,jj,jk,jpzoo) - 1.e-9 ), 0.e0 )
-               zfact   = xstep * tgfunc2(ji,jj,jk) * zcompaz
-
-               !   Michaelis-Menten mortality rates of microzooplankton
-               !   -----------------------------------------------------
-               zrespz = resrat * zfact * ( trb(ji,jj,jk,jpzoo) / ( xkmort + trb(ji,jj,jk,jpzoo) )  &
-               &        + 3. * nitrfac(ji,jj,jk) )
-
-               !   Zooplankton mortality. A square function has been selected with
-               !   no real reason except that it seems to be more stable and may mimic predation.
-               !   ------------------------------------------------------------------------------
-               ztortz = mzrat * 1.e6 * zfact * trb(ji,jj,jk,jpzoo) * (1. - nitrfac(ji,jj,jk))
-
-               !   Computation of the abundance of the preys
-               !   A threshold can be specified in the namelist
-               !   --------------------------------------------
-               zcompadi  = MIN( MAX( ( trb(ji,jj,jk,jpdia) - xthreshdia ), 0.e0 ), xsizedia )
-               zcompaph  = MAX( ( trb(ji,jj,jk,jpphy) - xthreshphy ), 0.e0 )
-               zcompaz   = MAX( ( trb(ji,jj,jk,jpzoo) - xthreshzoo ), 0.e0 )
-               zcompapi  = MAX( ( trb(ji,jj,jk,jppic) - xthreshpic ), 0.e0 )
-               zcompapoc = MAX( ( trb(ji,jj,jk,jppoc) - xthreshpoc ), 0.e0 )
-               
-               !   Microzooplankton grazing
-               !   ------------------------
-               zfood     = xprefn * zcompaph + xprefc * zcompapoc + xprefd * zcompadi   &
-               &           + xprefz * zcompaz + xprefp * zcompapi
-               zfoodlim  = MAX( 0. , zfood - min(xthresh,0.5*zfood) )
-               zdenom    = zfoodlim / ( xkgraz + zfoodlim )
-               zgraze    = grazrat * xstep * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jpzoo) * (1. - nitrfac(ji,jj,jk)) 
-
-               !   An active switching parameterization is used here.
-               !   We don't use the KTW parameterization proposed by 
-               !   Vallina et al. because it tends to produce to steady biomass
-               !   composition and the variance of Chl is too low as it grazes
-               !   too strongly on winning organisms. Thus, instead of a square
-               !   a 1.5 power value is used which decreases the pressure on the
-               !   most abundant species
-               !   ------------------------------------------------------------  
-               ztmp1 = xprefn * zcompaph**1.5
-               ztmp2 = xprefp * zcompapi**1.5
-               ztmp3 = xprefc * zcompapoc**1.5
-               ztmp4 = xprefd * zcompadi**1.5
-               ztmp5 = xprefz * zcompaz**1.5
-               ztmptot = ztmp1 + ztmp2 + ztmp3 + ztmp4 + ztmp5 + rtrn
-               ztmp1 = ztmp1 / ztmptot
-               ztmp2 = ztmp2 / ztmptot
-               ztmp3 = ztmp3 / ztmptot
-               ztmp4 = ztmp4 / ztmptot
-               ztmp5 = ztmp5 / ztmptot
-
-               !   Microzooplankton regular grazing on the different preys
-               !   -------------------------------------------------------
-               zgraznc   = zgraze  * ztmp1  * zdenom
-               zgraznn   = zgraznc * trb(ji,jj,jk,jpnph) / (trb(ji,jj,jk,jpphy) + rtrn)
-               zgraznp   = zgraznc * trb(ji,jj,jk,jppph) / (trb(ji,jj,jk,jpphy) + rtrn)
-               zgraznf   = zgraznc * trb(ji,jj,jk,jpnfe) / (trb(ji,jj,jk,jpphy) + rtrn)
-               zgrazpc   = zgraze  * ztmp2  * zdenom
-               zgrazpn   = zgrazpc * trb(ji,jj,jk,jpnpi) / (trb(ji,jj,jk,jppic) + rtrn)
-               zgrazpp   = zgrazpc * trb(ji,jj,jk,jpppi) / (trb(ji,jj,jk,jppic) + rtrn)
-               zgrazpf   = zgrazpc * trb(ji,jj,jk,jppfe) / (trb(ji,jj,jk,jppic) + rtrn)
-               zgrazz    = zgraze  * ztmp5   * zdenom
-               zgrazpoc  = zgraze  * ztmp3   * zdenom
-               zgrazpon  = zgrazpoc * trb(ji,jj,jk,jppon) / ( trb(ji,jj,jk,jppoc) + rtrn )
-               zgrazpop  = zgrazpoc * trb(ji,jj,jk,jppop) / ( trb(ji,jj,jk,jppoc) + rtrn )
-               zgrazpof  = zgrazpoc* trb(ji,jj,jk,jpsfe) / (trb(ji,jj,jk,jppoc) + rtrn)
-               zgrazdc   = zgraze  * ztmp4  * zdenom
-               zgrazdn   = zgrazdc * trb(ji,jj,jk,jpndi) / (trb(ji,jj,jk,jpdia) + rtrn)
-               zgrazdp   = zgrazdc * trb(ji,jj,jk,jppdi) / (trb(ji,jj,jk,jpdia) + rtrn)
-               zgrazdf   = zgrazdc * trb(ji,jj,jk,jpdfe) / (trb(ji,jj,jk,jpdia) + rtrn)
-               !
-               zgraztotc = zgraznc + zgrazpoc + zgrazdc + zgrazz + zgrazpc
-               zgraztotn = zgraznn + zgrazpn + zgrazpon + zgrazdn + zgrazz * no3rat3
-               zgraztotp = zgraznp + zgrazpp + zgrazpop + zgrazdp + zgrazz * po4rat3
-               zgraztotf = zgraznf + zgrazpf + zgrazpof + zgrazdf + zgrazz * ferat3
-               !
-               ! Grazing by microzooplankton
-               zgrazing(ji,jj,jk) = zgraztotc
-
-               !   Stoichiometruc ratios of the food ingested by zooplanton 
-               !   --------------------------------------------------------
-               zgrasratf =  (zgraztotf + rtrn) / ( zgraztotc + rtrn )
-               zgrasratn =  (zgraztotn + rtrn) / ( zgraztotc + rtrn )
-               zgrasratp =  (zgraztotp + rtrn) / ( zgraztotc + rtrn )
-
-               !   Growth efficiency is made a function of the quality 
-               !   and the quantity of the preys
-               !   ---------------------------------------------------
-               zepshert  = MIN( 1., zgrasratn/ no3rat3, zgrasratp/ po4rat3, zgrasratf / ferat3)
-               zbeta     = MAX( 0., (epsher - epshermin) )
-               zepsherf  = epshermin + zbeta / ( 1.0 + 0.04E6 * 12. * zfood * zbeta )
-               zepsherv  = zepsherf * zepshert
-
-               !   Respiration of microzooplankton
-               !   Excess carbon in the food is used preferentially
-               !   ------------------------------------------------
-               zexcess  = zgraztotc * zepsherf * (1.0 - zepshert) * zmetexcess
-               zbasresb = MAX(0., zrespz - zexcess)
-               zbasresi = zexcess + MIN(0., zrespz - zexcess)  
-               zrespirc = srespir * zepsherv * zgraztotc + zbasresb
-               
-               !   When excess carbon is used, the other elements in excess
-               !   are also used proportionally to their abundance
-               !   --------------------------------------------------------
-               zexcess  = ( zgrasratn/ no3rat3 - zepshert ) / ( 1.0 - zepshert + rtrn)
-               zbasresn = zbasresi * zexcess * zgrasratn 
-               zexcess  = ( zgrasratp/ po4rat3 - zepshert ) / ( 1.0 - zepshert + rtrn)
-               zbasresp = zbasresi * zexcess * zgrasratp
-               zexcess  = ( zgrasratf/ ferat3 - zepshert ) / ( 1.0 - zepshert + rtrn)
-               zbasresf = zbasresi * zexcess * zgrasratf
-
-               !   Voiding of the excessive elements as DOM
-               !   ----------------------------------------
-               zgradoct   = (1. - unassc - zepsherv) * zgraztotc - zbasresi  
-               zgradont   = (1. - unassn) * zgraztotn - zepsherv * no3rat3 * zgraztotc - zbasresn
-               zgradopt   = (1. - unassp) * zgraztotp - zepsherv * po4rat3 * zgraztotc - zbasresp
-               zgrareft   = (1. - unassc) * zgraztotf - zepsherv * ferat3 * zgraztotc - zbasresf
-
-               !  Since only semilabile DOM is represented in PISCES
-               !  part of DOM is in fact labile and is then released
-               !  as dissolved inorganic compounds (ssigma)
-               !  --------------------------------------------------
-               zgradoc =  zgradoct * ssigma
-               zgradon =  zgradont * ssigma
-               zgradop =  zgradopt * ssigma
-               zgrarem = (1.0 - ssigma) * zgradoct
-               zgraren = (1.0 - ssigma) * zgradont
-               zgrarep = (1.0 - ssigma) * zgradopt
-               zgraref = zgrareft
-
-               !   Defecation as a result of non assimilated products
-               !   --------------------------------------------------
-               zgrapoc   = zgraztotc * unassc
-               zgrapon   = zgraztotn * unassn
-               zgrapop   = zgraztotp * unassp
-               zgrapof   = zgraztotf * unassc
-
-               !  Addition of respiration to the release of inorganic nutrients
-               !  -------------------------------------------------------------
-               zgrarem = zgrarem + zbasresi + zrespirc
-               zgraren = zgraren + zbasresn + zrespirc * no3rat3
-               zgrarep = zgrarep + zbasresp + zrespirc * po4rat3
-               zgraref = zgraref + zbasresf + zrespirc * ferat3
-
-               !   Update of the TRA arrays
-               !   ------------------------
-               tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) + zgrarep
-               tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + zgraren
-               tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + zgradoc
-               !
-               IF( ln_ligand ) THEN 
-                  tra(ji,jj,jk,jplgw) = tra(ji,jj,jk,jplgw) + zgradoc * ldocz
-                  zzligprod(ji,jj,jk) = zgradoc * ldocz
-               ENDIF
-               !
-               tra(ji,jj,jk,jpdon) = tra(ji,jj,jk,jpdon) + zgradon
-               tra(ji,jj,jk,jpdop) = tra(ji,jj,jk,jpdop) + zgradop
-               tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) - o2ut * zgrarem 
-               tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + zgraref
-               zfezoo(ji,jj,jk)    = zgraref
-               tra(ji,jj,jk,jpzoo) = tra(ji,jj,jk,jpzoo) + zepsherv * zgraztotc - zrespirc - ztortz - zgrazz
-               tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) - zgraznc
-               tra(ji,jj,jk,jpnph) = tra(ji,jj,jk,jpnph) - zgraznn
-               tra(ji,jj,jk,jppph) = tra(ji,jj,jk,jppph) - zgraznp
-               tra(ji,jj,jk,jppic) = tra(ji,jj,jk,jppic) - zgrazpc
-               tra(ji,jj,jk,jpnpi) = tra(ji,jj,jk,jpnpi) - zgrazpn
-               tra(ji,jj,jk,jpppi) = tra(ji,jj,jk,jpppi) - zgrazpp
-               tra(ji,jj,jk,jpdia) = tra(ji,jj,jk,jpdia) - zgrazdc
-               tra(ji,jj,jk,jpndi) = tra(ji,jj,jk,jpndi) - zgrazdn
-               tra(ji,jj,jk,jppdi) = tra(ji,jj,jk,jppdi) - zgrazdp
-               tra(ji,jj,jk,jpnch) = tra(ji,jj,jk,jpnch) - zgraznc * trb(ji,jj,jk,jpnch)/(trb(ji,jj,jk,jpphy)+rtrn)
-               tra(ji,jj,jk,jppch) = tra(ji,jj,jk,jppch) - zgrazpc * trb(ji,jj,jk,jppch)/(trb(ji,jj,jk,jppic)+rtrn)
-               tra(ji,jj,jk,jpdch) = tra(ji,jj,jk,jpdch) - zgrazdc * trb(ji,jj,jk,jpdch)/(trb(ji,jj,jk,jpdia)+rtrn)
-               tra(ji,jj,jk,jpdsi) = tra(ji,jj,jk,jpdsi) - zgrazdc * trb(ji,jj,jk,jpdsi)/(trb(ji,jj,jk,jpdia)+rtrn)
-               tra(ji,jj,jk,jpgsi) = tra(ji,jj,jk,jpgsi) + zgrazdc * trb(ji,jj,jk,jpdsi)/(trb(ji,jj,jk,jpdia)+rtrn)
-               tra(ji,jj,jk,jpnfe) = tra(ji,jj,jk,jpnfe) - zgraznf
-               tra(ji,jj,jk,jppfe) = tra(ji,jj,jk,jppfe) - zgrazpf
-               tra(ji,jj,jk,jpdfe) = tra(ji,jj,jk,jpdfe) - zgrazdf
-               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + ztortz + zgrapoc - zgrazpoc 
-               prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + ztortz + zgrapoc
-               conspoc(ji,jj,jk) = conspoc(ji,jj,jk) - zgrazpoc
-               tra(ji,jj,jk,jppon) = tra(ji,jj,jk,jppon) + no3rat3 * ztortz + zgrapon - zgrazpon
-               tra(ji,jj,jk,jppop) = tra(ji,jj,jk,jppop) + po4rat3 * ztortz + zgrapop - zgrazpop
-               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + ferat3 * ztortz  + zgrapof - zgrazpof
-               !
-               ! calcite production
-               zprcaca = xfracal(ji,jj,jk) * zgraznc
-               prodcal(ji,jj,jk) = prodcal(ji,jj,jk) + zprcaca  ! prodcal=prodcal(nanophy)+prodcal(microzoo)+prodcal(mesozoo)
-               !
-               zprcaca = part * zprcaca
-               tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) + zgrarem - zprcaca
-               tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) - 2. * zprcaca     &
-               &                     + rno3 * zgraren
-               tra(ji,jj,jk,jpcal) = tra(ji,jj,jk,jpcal) + zprcaca
-            END DO
-         END DO
-      END DO
-      !
-      IF( lk_iomput ) THEN
-         IF( knt == nrdttrc ) THEN
-            ALLOCATE( zw3d(jpi,jpj,jpk) )
-            IF( iom_use( "GRAZ1" ) ) THEN
-               zw3d(:,:,:) = zgrazing(:,:,:) * 1.e+3 * rfact2r * tmask(:,:,:)  !  Total grazing of phyto by zooplankton
-               CALL iom_put( "GRAZ1", zw3d )
-            ENDIF
-            IF( iom_use( "FEZOO" ) ) THEN
-               zw3d(:,:,:) = zfezoo(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:)   !
-               CALL iom_put( "FEZOO", zw3d )
-            ENDIF
-            IF( iom_use( "LPRODZ" ) .AND. ln_ligand )  THEN
-               zw3d(:,:,:) = zzligprod(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:)
-               CALL iom_put( "LPRODZ"  , zw3d )
-            ENDIF
-            DEALLOCATE( zw3d )
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zcompaz = MAX( ( tr(ji,jj,jk,jpzoo,Kbb) - 1.e-9 ), 0.e0 )
+         zfact   = xstep * tgfunc2(ji,jj,jk) * zcompaz
+
+         !   Michaelis-Menten mortality rates of microzooplankton
+         !   -----------------------------------------------------
+         zrespz = resrat * zfact * ( tr(ji,jj,jk,jpzoo,Kbb) / ( xkmort + tr(ji,jj,jk,jpzoo,Kbb) )  &
+         &        + 3. * nitrfac(ji,jj,jk) )
+
+         !   Zooplankton mortality. A square function has been selected with
+         !   no real reason except that it seems to be more stable and may mimic predation.
+         !   ------------------------------------------------------------------------------
+         ztortz = mzrat * 1.e6 * zfact * tr(ji,jj,jk,jpzoo,Kbb) * (1. - nitrfac(ji,jj,jk))
+
+         !   Computation of the abundance of the preys
+         !   A threshold can be specified in the namelist
+         !   --------------------------------------------
+         zcompadi  = MIN( MAX( ( tr(ji,jj,jk,jpdia,Kbb) - xthreshdia ), 0.e0 ), xsizedia )
+         zcompaph  = MAX( ( tr(ji,jj,jk,jpphy,Kbb) - xthreshphy ), 0.e0 )
+         zcompaz   = MAX( ( tr(ji,jj,jk,jpzoo,Kbb) - xthreshzoo ), 0.e0 )
+         zcompapi  = MAX( ( tr(ji,jj,jk,jppic,Kbb) - xthreshpic ), 0.e0 )
+         zcompapoc = MAX( ( tr(ji,jj,jk,jppoc,Kbb) - xthreshpoc ), 0.e0 )
+         
+         !   Microzooplankton grazing
+         !   ------------------------
+         zfood     = xprefn * zcompaph + xprefc * zcompapoc + xprefd * zcompadi   &
+         &           + xprefz * zcompaz + xprefp * zcompapi
+         zfoodlim  = MAX( 0. , zfood - min(xthresh,0.5*zfood) )
+         zdenom    = zfoodlim / ( xkgraz + zfoodlim )
+         zgraze    = grazrat * xstep * tgfunc2(ji,jj,jk) * tr(ji,jj,jk,jpzoo,Kbb) * (1. - nitrfac(ji,jj,jk)) 
+
+         !   An active switching parameterization is used here.
+         !   We don't use the KTW parameterization proposed by 
+         !   Vallina et al. because it tends to produce to steady biomass
+         !   composition and the variance of Chl is too low as it grazes
+         !   too strongly on winning organisms. Thus, instead of a square
+         !   a 1.5 power value is used which decreases the pressure on the
+         !   most abundant species
+         !   ------------------------------------------------------------  
+         ztmp1 = xprefn * zcompaph**1.5
+         ztmp2 = xprefp * zcompapi**1.5
+         ztmp3 = xprefc * zcompapoc**1.5
+         ztmp4 = xprefd * zcompadi**1.5
+         ztmp5 = xprefz * zcompaz**1.5
+         ztmptot = ztmp1 + ztmp2 + ztmp3 + ztmp4 + ztmp5 + rtrn
+         ztmp1 = ztmp1 / ztmptot
+         ztmp2 = ztmp2 / ztmptot
+         ztmp3 = ztmp3 / ztmptot
+         ztmp4 = ztmp4 / ztmptot
+         ztmp5 = ztmp5 / ztmptot
+
+         !   Microzooplankton regular grazing on the different preys
+         !   -------------------------------------------------------
+         zgraznc   = zgraze  * ztmp1  * zdenom
+         zgraznn   = zgraznc * tr(ji,jj,jk,jpnph,Kbb) / (tr(ji,jj,jk,jpphy,Kbb) + rtrn)
+         zgraznp   = zgraznc * tr(ji,jj,jk,jppph,Kbb) / (tr(ji,jj,jk,jpphy,Kbb) + rtrn)
+         zgraznf   = zgraznc * tr(ji,jj,jk,jpnfe,Kbb) / (tr(ji,jj,jk,jpphy,Kbb) + rtrn)
+         zgrazpc   = zgraze  * ztmp2  * zdenom
+         zgrazpn   = zgrazpc * tr(ji,jj,jk,jpnpi,Kbb) / (tr(ji,jj,jk,jppic,Kbb) + rtrn)
+         zgrazpp   = zgrazpc * tr(ji,jj,jk,jpppi,Kbb) / (tr(ji,jj,jk,jppic,Kbb) + rtrn)
+         zgrazpf   = zgrazpc * tr(ji,jj,jk,jppfe,Kbb) / (tr(ji,jj,jk,jppic,Kbb) + rtrn)
+         zgrazz    = zgraze  * ztmp5   * zdenom
+         zgrazpoc  = zgraze  * ztmp3   * zdenom
+         zgrazpon  = zgrazpoc * tr(ji,jj,jk,jppon,Kbb) / ( tr(ji,jj,jk,jppoc,Kbb) + rtrn )
+         zgrazpop  = zgrazpoc * tr(ji,jj,jk,jppop,Kbb) / ( tr(ji,jj,jk,jppoc,Kbb) + rtrn )
+         zgrazpof  = zgrazpoc* tr(ji,jj,jk,jpsfe,Kbb) / (tr(ji,jj,jk,jppoc,Kbb) + rtrn)
+         zgrazdc   = zgraze  * ztmp4  * zdenom
+         zgrazdn   = zgrazdc * tr(ji,jj,jk,jpndi,Kbb) / (tr(ji,jj,jk,jpdia,Kbb) + rtrn)
+         zgrazdp   = zgrazdc * tr(ji,jj,jk,jppdi,Kbb) / (tr(ji,jj,jk,jpdia,Kbb) + rtrn)
+         zgrazdf   = zgrazdc * tr(ji,jj,jk,jpdfe,Kbb) / (tr(ji,jj,jk,jpdia,Kbb) + rtrn)
+         !
+         zgraztotc = zgraznc + zgrazpoc + zgrazdc + zgrazz + zgrazpc
+         zgraztotn = zgraznn + zgrazpn + zgrazpon + zgrazdn + zgrazz * no3rat3
+         zgraztotp = zgraznp + zgrazpp + zgrazpop + zgrazdp + zgrazz * po4rat3
+         zgraztotf = zgraznf + zgrazpf + zgrazpof + zgrazdf + zgrazz * ferat3
+         !
+         ! Grazing by microzooplankton
+         zgrazing(ji,jj,jk) = zgraztotc
+
+         !   Stoichiometruc ratios of the food ingested by zooplanton 
+         !   --------------------------------------------------------
+         zgrasratf =  (zgraztotf + rtrn) / ( zgraztotc + rtrn )
+         zgrasratn =  (zgraztotn + rtrn) / ( zgraztotc + rtrn )
+         zgrasratp =  (zgraztotp + rtrn) / ( zgraztotc + rtrn )
+
+         !   Growth efficiency is made a function of the quality 
+         !   and the quantity of the preys
+         !   ---------------------------------------------------
+         zepshert  = MIN( 1., zgrasratn/ no3rat3, zgrasratp/ po4rat3, zgrasratf / ferat3)
+         zbeta     = MAX( 0., (epsher - epshermin) )
+         zepsherf  = epshermin + zbeta / ( 1.0 + 0.04E6 * 12. * zfood * zbeta )
+         zepsherv  = zepsherf * zepshert
+
+         !   Respiration of microzooplankton
+         !   Excess carbon in the food is used preferentially
+         !   ------------------------------------------------
+         zexcess  = zgraztotc * zepsherf * (1.0 - zepshert) * zmetexcess
+         zbasresb = MAX(0., zrespz - zexcess)
+         zbasresi = zexcess + MIN(0., zrespz - zexcess)  
+         zrespirc = srespir * zepsherv * zgraztotc + zbasresb
+         
+         !   When excess carbon is used, the other elements in excess
+         !   are also used proportionally to their abundance
+         !   --------------------------------------------------------
+         zexcess  = ( zgrasratn/ no3rat3 - zepshert ) / ( 1.0 - zepshert + rtrn)
+         zbasresn = zbasresi * zexcess * zgrasratn 
+         zexcess  = ( zgrasratp/ po4rat3 - zepshert ) / ( 1.0 - zepshert + rtrn)
+         zbasresp = zbasresi * zexcess * zgrasratp
+         zexcess  = ( zgrasratf/ ferat3 - zepshert ) / ( 1.0 - zepshert + rtrn)
+         zbasresf = zbasresi * zexcess * zgrasratf
+
+         !   Voiding of the excessive elements as DOM
+         !   ----------------------------------------
+         zgradoct   = (1. - unassc - zepsherv) * zgraztotc - zbasresi  
+         zgradont   = (1. - unassn) * zgraztotn - zepsherv * no3rat3 * zgraztotc - zbasresn
+         zgradopt   = (1. - unassp) * zgraztotp - zepsherv * po4rat3 * zgraztotc - zbasresp
+         zgrareft   = (1. - unassc) * zgraztotf - zepsherv * ferat3 * zgraztotc - zbasresf
+
+         !  Since only semilabile DOM is represented in PISCES
+         !  part of DOM is in fact labile and is then released
+         !  as dissolved inorganic compounds (ssigma)
+         !  --------------------------------------------------
+         zgradoc =  zgradoct * ssigma
+         zgradon =  zgradont * ssigma
+         zgradop =  zgradopt * ssigma
+         zgrarem = (1.0 - ssigma) * zgradoct
+         zgraren = (1.0 - ssigma) * zgradont
+         zgrarep = (1.0 - ssigma) * zgradopt
+         zgraref = zgrareft
+
+         !   Defecation as a result of non assimilated products
+         !   --------------------------------------------------
+         zgrapoc   = zgraztotc * unassc
+         zgrapon   = zgraztotn * unassn
+         zgrapop   = zgraztotp * unassp
+         zgrapof   = zgraztotf * unassc
+
+         !  Addition of respiration to the release of inorganic nutrients
+         !  -------------------------------------------------------------
+         zgrarem = zgrarem + zbasresi + zrespirc
+         zgraren = zgraren + zbasresn + zrespirc * no3rat3
+         zgrarep = zgrarep + zbasresp + zrespirc * po4rat3
+         zgraref = zgraref + zbasresf + zrespirc * ferat3
+
+         !   Update of the TRA arrays
+         !   ------------------------
+         tr(ji,jj,jk,jppo4,Krhs) = tr(ji,jj,jk,jppo4,Krhs) + zgrarep
+         tr(ji,jj,jk,jpnh4,Krhs) = tr(ji,jj,jk,jpnh4,Krhs) + zgraren
+         tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) + zgradoc
+         !
+         IF( ln_ligand ) THEN 
+            tr(ji,jj,jk,jplgw,Krhs) = tr(ji,jj,jk,jplgw,Krhs) + zgradoc * ldocz
+            zzligprod(ji,jj,jk) = zgradoc * ldocz
+         ENDIF
+         !
+         tr(ji,jj,jk,jpdon,Krhs) = tr(ji,jj,jk,jpdon,Krhs) + zgradon
+         tr(ji,jj,jk,jpdop,Krhs) = tr(ji,jj,jk,jpdop,Krhs) + zgradop
+         tr(ji,jj,jk,jpoxy,Krhs) = tr(ji,jj,jk,jpoxy,Krhs) - o2ut * zgrarem 
+         tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) + zgraref
+         zfezoo(ji,jj,jk)    = zgraref
+         tr(ji,jj,jk,jpzoo,Krhs) = tr(ji,jj,jk,jpzoo,Krhs) + zepsherv * zgraztotc - zrespirc - ztortz - zgrazz
+         tr(ji,jj,jk,jpphy,Krhs) = tr(ji,jj,jk,jpphy,Krhs) - zgraznc
+         tr(ji,jj,jk,jpnph,Krhs) = tr(ji,jj,jk,jpnph,Krhs) - zgraznn
+         tr(ji,jj,jk,jppph,Krhs) = tr(ji,jj,jk,jppph,Krhs) - zgraznp
+         tr(ji,jj,jk,jppic,Krhs) = tr(ji,jj,jk,jppic,Krhs) - zgrazpc
+         tr(ji,jj,jk,jpnpi,Krhs) = tr(ji,jj,jk,jpnpi,Krhs) - zgrazpn
+         tr(ji,jj,jk,jpppi,Krhs) = tr(ji,jj,jk,jpppi,Krhs) - zgrazpp
+         tr(ji,jj,jk,jpdia,Krhs) = tr(ji,jj,jk,jpdia,Krhs) - zgrazdc
+         tr(ji,jj,jk,jpndi,Krhs) = tr(ji,jj,jk,jpndi,Krhs) - zgrazdn
+         tr(ji,jj,jk,jppdi,Krhs) = tr(ji,jj,jk,jppdi,Krhs) - zgrazdp
+         tr(ji,jj,jk,jpnch,Krhs) = tr(ji,jj,jk,jpnch,Krhs) - zgraznc * tr(ji,jj,jk,jpnch,Kbb)/(tr(ji,jj,jk,jpphy,Kbb)+rtrn)
+         tr(ji,jj,jk,jppch,Krhs) = tr(ji,jj,jk,jppch,Krhs) - zgrazpc * tr(ji,jj,jk,jppch,Kbb)/(tr(ji,jj,jk,jppic,Kbb)+rtrn)
+         tr(ji,jj,jk,jpdch,Krhs) = tr(ji,jj,jk,jpdch,Krhs) - zgrazdc * tr(ji,jj,jk,jpdch,Kbb)/(tr(ji,jj,jk,jpdia,Kbb)+rtrn)
+         tr(ji,jj,jk,jpdsi,Krhs) = tr(ji,jj,jk,jpdsi,Krhs) - zgrazdc * tr(ji,jj,jk,jpdsi,Kbb)/(tr(ji,jj,jk,jpdia,Kbb)+rtrn)
+         tr(ji,jj,jk,jpgsi,Krhs) = tr(ji,jj,jk,jpgsi,Krhs) + zgrazdc * tr(ji,jj,jk,jpdsi,Kbb)/(tr(ji,jj,jk,jpdia,Kbb)+rtrn)
+         tr(ji,jj,jk,jpnfe,Krhs) = tr(ji,jj,jk,jpnfe,Krhs) - zgraznf
+         tr(ji,jj,jk,jppfe,Krhs) = tr(ji,jj,jk,jppfe,Krhs) - zgrazpf
+         tr(ji,jj,jk,jpdfe,Krhs) = tr(ji,jj,jk,jpdfe,Krhs) - zgrazdf
+         tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) + ztortz + zgrapoc - zgrazpoc 
+         prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + ztortz + zgrapoc
+         conspoc(ji,jj,jk) = conspoc(ji,jj,jk) - zgrazpoc
+         tr(ji,jj,jk,jppon,Krhs) = tr(ji,jj,jk,jppon,Krhs) + no3rat3 * ztortz + zgrapon - zgrazpon
+         tr(ji,jj,jk,jppop,Krhs) = tr(ji,jj,jk,jppop,Krhs) + po4rat3 * ztortz + zgrapop - zgrazpop
+         tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) + ferat3 * ztortz  + zgrapof - zgrazpof
+         !
+         ! calcite production
+         zprcaca = xfracal(ji,jj,jk) * zgraznc
+         prodcal(ji,jj,jk) = prodcal(ji,jj,jk) + zprcaca  ! prodcal=prodcal(nanophy)+prodcal(microzoo)+prodcal(mesozoo)
+         !
+         zprcaca = part * zprcaca
+         tr(ji,jj,jk,jpdic,Krhs) = tr(ji,jj,jk,jpdic,Krhs) + zgrarem - zprcaca
+         tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) - 2. * zprcaca     &
+         &                     + rno3 * zgraren
+         tr(ji,jj,jk,jpcal,Krhs) = tr(ji,jj,jk,jpcal,Krhs) + zprcaca
+      END_3D
+      !
+      IF( lk_iomput .AND. knt == nrdttrc ) THEN
+       IF( iom_use("GRAZ1") ) THEN  !   Total grazing of phyto by zooplankton
+           zgrazing(:,:,jpk) = 0._wp   ; CALL iom_put( "GRAZ1" , zgrazing(:,:,:) * 1.e+3  * rfact2r * tmask(:,:,:) ) 
+         ENDIF
+         IF( iom_use("FEZOO") ) THEN  
+           zfezoo (:,:,jpk) = 0._wp    ; CALL iom_put( "FEZOO" , zfezoo(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:) )
+         ENDIF
+         IF( ln_ligand ) THEN
+            zzligprod(:,:,jpk) = 0._wp ; CALL iom_put( "LPRODZ", zzligprod(:,:,:) * 1e9 * 1.e+3 * rfact2r * tmask(:,:,:))
          ENDIF
       ENDIF
       !
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('micro')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -349,11 +335,9 @@
       !!----------------------------------------------------------------------
       !
-      REWIND( numnatp_ref )              ! Namelist nampiszoo in reference namelist : Pisces microzooplankton
       READ  ( numnatp_ref, namp5zzoo, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namp5zzoo in reference namelist', lwp )
-      !
-      REWIND( numnatp_cfg )              ! Namelist nampiszoo in configuration namelist : Pisces microzooplankton
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namp5zzoo in reference namelist' )
+      !
       READ  ( numnatp_cfg, namp5zzoo, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namp5zzoo in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namp5zzoo in configuration namelist' )
       IF(lwm) WRITE ( numonp, namp5zzoo )
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zmort.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zmort.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zmort.F90	(revision 13463)
@@ -16,5 +16,5 @@
    USE p4zlim
    USE p5zlim          !  Phytoplankton limitation terms
-   USE prtctl_trc      !  print control for debugging
+   USE prtctl          !  print control for debugging
 
    IMPLICIT NONE
@@ -33,4 +33,6 @@
    REAL(wp), PUBLIC :: mpratd  !:
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -41,5 +43,5 @@
 CONTAINS
 
-   SUBROUTINE p5z_mort( kt )
+   SUBROUTINE p5z_mort( kt, Kbb, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p5z_mort  ***
@@ -51,14 +53,15 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt ! ocean time step
-      !!---------------------------------------------------------------------
-
-      CALL p5z_nano            ! nanophytoplankton
-      CALL p5z_pico            ! picophytoplankton
-      CALL p5z_diat            ! diatoms
+      INTEGER, INTENT(in) ::   Kbb, Krhs  ! time level indices
+      !!---------------------------------------------------------------------
+
+      CALL p5z_nano( Kbb, Krhs )            ! nanophytoplankton
+      CALL p5z_pico( Kbb, Krhs )            ! picophytoplankton
+      CALL p5z_diat( Kbb, Krhs )            ! diatoms
 
    END SUBROUTINE p5z_mort
 
 
-   SUBROUTINE p5z_nano
+   SUBROUTINE p5z_nano( Kbb, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p5z_nano  ***
@@ -68,4 +71,5 @@
       !! ** Method  : - ???
       !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kbb, Krhs  ! time level indices
       INTEGER  :: ji, jj, jk
       REAL(wp) :: zcompaph
@@ -78,49 +82,45 @@
       !
       prodcal(:,:,:) = 0.  !: calcite production variable set to zero
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zcompaph = MAX( ( trb(ji,jj,jk,jpphy) - 1e-9 ), 0.e0 )
-               !   Squared mortality of Phyto similar to a sedimentation term during
-               !   blooms (Doney et al. 1996)
-               !   -----------------------------------------------------------------
-               zrespp = wchln * 1.e6 * xstep * xdiss(ji,jj,jk) * zcompaph * trb(ji,jj,jk,jpphy)
-
-               !   Phytoplankton linear mortality
-               !   ------------------------------
-               ztortp = mpratn * xstep  * zcompaph
-               zmortp = zrespp + ztortp
-
-               !   Update the arrays TRA which contains the biological sources and sinks
-
-               zfactn  = trb(ji,jj,jk,jpnph)/(trb(ji,jj,jk,jpphy)+rtrn)
-               zfactp  = trb(ji,jj,jk,jppph)/(trb(ji,jj,jk,jpphy)+rtrn)
-               zfactfe = trb(ji,jj,jk,jpnfe)/(trb(ji,jj,jk,jpphy)+rtrn)
-               zfactch = trb(ji,jj,jk,jpnch)/(trb(ji,jj,jk,jpphy)+rtrn)
-               tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) - zmortp
-               tra(ji,jj,jk,jpnph) = tra(ji,jj,jk,jpnph) - zmortp * zfactn
-               tra(ji,jj,jk,jppph) = tra(ji,jj,jk,jppph) - zmortp * zfactp
-               tra(ji,jj,jk,jpnch) = tra(ji,jj,jk,jpnch) - zmortp * zfactch
-               tra(ji,jj,jk,jpnfe) = tra(ji,jj,jk,jpnfe) - zmortp * zfactfe
-               zprcaca = xfracal(ji,jj,jk) * zmortp
-               !
-               prodcal(ji,jj,jk) = prodcal(ji,jj,jk) + zprcaca  ! prodcal=prodcal(nanophy)+prodcal(microzoo)+prodcal(mesozoo)
-               !
-               tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) - zprcaca
-               tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) - 2. * zprcaca
-               tra(ji,jj,jk,jpcal) = tra(ji,jj,jk,jpcal) + zprcaca
-               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zmortp
-               tra(ji,jj,jk,jppon) = tra(ji,jj,jk,jppon) + zmortp * zfactn
-               tra(ji,jj,jk,jppop) = tra(ji,jj,jk,jppop) + zmortp * zfactp
-               prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + zmortp
-               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + zmortp * zfactfe
-            END DO
-         END DO
-      END DO
-      !
-       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zcompaph = MAX( ( tr(ji,jj,jk,jpphy,Kbb) - 1e-9 ), 0.e0 )
+         !   Squared mortality of Phyto similar to a sedimentation term during
+         !   blooms (Doney et al. 1996)
+         !   -----------------------------------------------------------------
+         zrespp = wchln * 1.e6 * xstep * xdiss(ji,jj,jk) * zcompaph * tr(ji,jj,jk,jpphy,Kbb)
+
+         !   Phytoplankton linear mortality
+         !   ------------------------------
+         ztortp = mpratn * xstep  * zcompaph
+         zmortp = zrespp + ztortp
+
+         !   Update the arrays TRA which contains the biological sources and sinks
+
+         zfactn  = tr(ji,jj,jk,jpnph,Kbb)/(tr(ji,jj,jk,jpphy,Kbb)+rtrn)
+         zfactp  = tr(ji,jj,jk,jppph,Kbb)/(tr(ji,jj,jk,jpphy,Kbb)+rtrn)
+         zfactfe = tr(ji,jj,jk,jpnfe,Kbb)/(tr(ji,jj,jk,jpphy,Kbb)+rtrn)
+         zfactch = tr(ji,jj,jk,jpnch,Kbb)/(tr(ji,jj,jk,jpphy,Kbb)+rtrn)
+         tr(ji,jj,jk,jpphy,Krhs) = tr(ji,jj,jk,jpphy,Krhs) - zmortp
+         tr(ji,jj,jk,jpnph,Krhs) = tr(ji,jj,jk,jpnph,Krhs) - zmortp * zfactn
+         tr(ji,jj,jk,jppph,Krhs) = tr(ji,jj,jk,jppph,Krhs) - zmortp * zfactp
+         tr(ji,jj,jk,jpnch,Krhs) = tr(ji,jj,jk,jpnch,Krhs) - zmortp * zfactch
+         tr(ji,jj,jk,jpnfe,Krhs) = tr(ji,jj,jk,jpnfe,Krhs) - zmortp * zfactfe
+         zprcaca = xfracal(ji,jj,jk) * zmortp
+         !
+         prodcal(ji,jj,jk) = prodcal(ji,jj,jk) + zprcaca  ! prodcal=prodcal(nanophy)+prodcal(microzoo)+prodcal(mesozoo)
+         !
+         tr(ji,jj,jk,jpdic,Krhs) = tr(ji,jj,jk,jpdic,Krhs) - zprcaca
+         tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) - 2. * zprcaca
+         tr(ji,jj,jk,jpcal,Krhs) = tr(ji,jj,jk,jpcal,Krhs) + zprcaca
+         tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) + zmortp
+         tr(ji,jj,jk,jppon,Krhs) = tr(ji,jj,jk,jppon,Krhs) + zmortp * zfactn
+         tr(ji,jj,jk,jppop,Krhs) = tr(ji,jj,jk,jppop,Krhs) + zmortp * zfactp
+         prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + zmortp
+         tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) + zmortp * zfactfe
+      END_3D
+      !
+       IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('nano')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
        ENDIF
       !
@@ -130,5 +130,5 @@
 
 
-   SUBROUTINE p5z_pico
+   SUBROUTINE p5z_pico( Kbb, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p5z_pico  ***
@@ -138,4 +138,5 @@
       !! ** Method  : - ???
       !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kbb, Krhs  ! time level indices
       INTEGER  :: ji, jj, jk
       REAL(wp) :: zcompaph
@@ -147,41 +148,37 @@
       IF( ln_timing )   CALL timing_start('p5z_pico')
       !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zcompaph = MAX( ( trb(ji,jj,jk,jppic) - 1e-9 ), 0.e0 )
-               !  Squared mortality of Phyto similar to a sedimentation term during
-               !  blooms (Doney et al. 1996)
-               !  -----------------------------------------------------------------
-               zrespp = wchlp * 1.e6 * xstep * xdiss(ji,jj,jk) * zcompaph * trb(ji,jj,jk,jppic)
-
-               !     Phytoplankton mortality 
-               ztortp = mpratp * xstep  * zcompaph
-               zmortp = zrespp + ztortp
-
-               !   Update the arrays TRA which contains the biological sources and sinks
-
-               zfactn = trb(ji,jj,jk,jpnpi)/(trb(ji,jj,jk,jppic)+rtrn)
-               zfactp = trb(ji,jj,jk,jpppi)/(trb(ji,jj,jk,jppic)+rtrn)
-               zfactfe = trb(ji,jj,jk,jppfe)/(trb(ji,jj,jk,jppic)+rtrn)
-               zfactch = trb(ji,jj,jk,jppch)/(trb(ji,jj,jk,jppic)+rtrn)
-               tra(ji,jj,jk,jppic) = tra(ji,jj,jk,jppic) - zmortp
-               tra(ji,jj,jk,jpnpi) = tra(ji,jj,jk,jpnpi) - zmortp * zfactn
-               tra(ji,jj,jk,jpppi) = tra(ji,jj,jk,jpppi) - zmortp * zfactp
-               tra(ji,jj,jk,jppch) = tra(ji,jj,jk,jppch) - zmortp * zfactch
-               tra(ji,jj,jk,jppfe) = tra(ji,jj,jk,jppfe) - zmortp * zfactfe
-               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + zmortp
-               tra(ji,jj,jk,jppon) = tra(ji,jj,jk,jppon) + zmortp * zfactn
-               tra(ji,jj,jk,jppop) = tra(ji,jj,jk,jppop) + zmortp * zfactp
-               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + zmortp * zfactfe
-               prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + zmortp
-            END DO
-         END DO
-      END DO
-      !
-       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zcompaph = MAX( ( tr(ji,jj,jk,jppic,Kbb) - 1e-9 ), 0.e0 )
+         !  Squared mortality of Phyto similar to a sedimentation term during
+         !  blooms (Doney et al. 1996)
+         !  -----------------------------------------------------------------
+         zrespp = wchlp * 1.e6 * xstep * xdiss(ji,jj,jk) * zcompaph * tr(ji,jj,jk,jppic,Kbb)
+
+         !     Phytoplankton mortality 
+         ztortp = mpratp * xstep  * zcompaph
+         zmortp = zrespp + ztortp
+
+         !   Update the arrays TRA which contains the biological sources and sinks
+
+         zfactn = tr(ji,jj,jk,jpnpi,Kbb)/(tr(ji,jj,jk,jppic,Kbb)+rtrn)
+         zfactp = tr(ji,jj,jk,jpppi,Kbb)/(tr(ji,jj,jk,jppic,Kbb)+rtrn)
+         zfactfe = tr(ji,jj,jk,jppfe,Kbb)/(tr(ji,jj,jk,jppic,Kbb)+rtrn)
+         zfactch = tr(ji,jj,jk,jppch,Kbb)/(tr(ji,jj,jk,jppic,Kbb)+rtrn)
+         tr(ji,jj,jk,jppic,Krhs) = tr(ji,jj,jk,jppic,Krhs) - zmortp
+         tr(ji,jj,jk,jpnpi,Krhs) = tr(ji,jj,jk,jpnpi,Krhs) - zmortp * zfactn
+         tr(ji,jj,jk,jpppi,Krhs) = tr(ji,jj,jk,jpppi,Krhs) - zmortp * zfactp
+         tr(ji,jj,jk,jppch,Krhs) = tr(ji,jj,jk,jppch,Krhs) - zmortp * zfactch
+         tr(ji,jj,jk,jppfe,Krhs) = tr(ji,jj,jk,jppfe,Krhs) - zmortp * zfactfe
+         tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) + zmortp
+         tr(ji,jj,jk,jppon,Krhs) = tr(ji,jj,jk,jppon,Krhs) + zmortp * zfactn
+         tr(ji,jj,jk,jppop,Krhs) = tr(ji,jj,jk,jppop,Krhs) + zmortp * zfactp
+         tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) + zmortp * zfactfe
+         prodpoc(ji,jj,jk) = prodpoc(ji,jj,jk) + zmortp
+      END_3D
+      !
+       IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('pico')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
        ENDIF
       !
@@ -191,5 +188,5 @@
 
 
-   SUBROUTINE p5z_diat
+   SUBROUTINE p5z_diat( Kbb, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p5z_diat  ***
@@ -199,4 +196,5 @@
       !! ** Method  : - ???
       !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kbb, Krhs  ! time level indices
       INTEGER  ::  ji, jj, jk
       REAL(wp) ::  zfactfe,zfactsi,zfactch, zfactn, zfactp, zcompadi
@@ -209,57 +207,53 @@
       !
 
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-
-               zcompadi = MAX( ( trb(ji,jj,jk,jpdia) - 1E-9), 0. )
-
-               !   Aggregation term for diatoms is increased in case of nutrient
-               !   stress as observed in reality. The stressed cells become more
-               !   sticky and coagulate to sink quickly out of the euphotic zone
-               !   -------------------------------------------------------------
-               !  Phytoplankton squared mortality
-               !  -------------------------------
-               zlim2   = xlimdia(ji,jj,jk) * xlimdia(ji,jj,jk)
-               zlim1   = 0.25 * ( 1. - zlim2 ) / ( 0.25 + zlim2 ) 
-               zrespp2 = 1.e6 * xstep * (  wchld + wchldm * zlim1 ) * xdiss(ji,jj,jk) * zcompadi * trb(ji,jj,jk,jpdia)
-
-               !  Phytoplankton linear mortality 
-               !  ------------------------------
-               ztortp2 = mpratd * xstep  * zcompadi
-               zmortp2 = zrespp2 + ztortp2
-
-               !   Update the arrays tra which contains the biological sources and sinks
-               !   ---------------------------------------------------------------------
-               zfactn  = trb(ji,jj,jk,jpndi) / ( trb(ji,jj,jk,jpdia) + rtrn )
-               zfactp  = trb(ji,jj,jk,jppdi) / ( trb(ji,jj,jk,jpdia) + rtrn )
-               zfactch = trb(ji,jj,jk,jpdch) / ( trb(ji,jj,jk,jpdia) + rtrn )
-               zfactfe = trb(ji,jj,jk,jpdfe) / ( trb(ji,jj,jk,jpdia) + rtrn )
-               zfactsi = trb(ji,jj,jk,jpdsi) / ( trb(ji,jj,jk,jpdia) + rtrn )
-               tra(ji,jj,jk,jpdia) = tra(ji,jj,jk,jpdia) - zmortp2 
-               tra(ji,jj,jk,jpndi) = tra(ji,jj,jk,jpndi) - zmortp2 * zfactn
-               tra(ji,jj,jk,jppdi) = tra(ji,jj,jk,jppdi) - zmortp2 * zfactp
-               tra(ji,jj,jk,jpdch) = tra(ji,jj,jk,jpdch) - zmortp2 * zfactch
-               tra(ji,jj,jk,jpdfe) = tra(ji,jj,jk,jpdfe) - zmortp2 * zfactfe
-               tra(ji,jj,jk,jpdsi) = tra(ji,jj,jk,jpdsi) - zmortp2 * zfactsi
-               tra(ji,jj,jk,jpgsi) = tra(ji,jj,jk,jpgsi) + zmortp2 * zfactsi
-               tra(ji,jj,jk,jpgoc) = tra(ji,jj,jk,jpgoc) + zrespp2 
-               tra(ji,jj,jk,jpgon) = tra(ji,jj,jk,jpgon) + zrespp2 * zfactn
-               tra(ji,jj,jk,jpgop) = tra(ji,jj,jk,jpgop) + zrespp2 * zfactp
-               tra(ji,jj,jk,jpbfe) = tra(ji,jj,jk,jpbfe) + zrespp2 * zfactfe
-               tra(ji,jj,jk,jppoc) = tra(ji,jj,jk,jppoc) + ztortp2
-               tra(ji,jj,jk,jppon) = tra(ji,jj,jk,jppon) + ztortp2 * zfactn
-               tra(ji,jj,jk,jppop) = tra(ji,jj,jk,jppop) + ztortp2 * zfactp
-               tra(ji,jj,jk,jpsfe) = tra(ji,jj,jk,jpsfe) + ztortp2 * zfactfe
-               prodpoc(ji,jj,jk)   = prodpoc(ji,jj,jk) + ztortp2
-               prodgoc(ji,jj,jk)   = prodgoc(ji,jj,jk) + zrespp2
-            END DO
-         END DO
-      END DO
-      !
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+
+         zcompadi = MAX( ( tr(ji,jj,jk,jpdia,Kbb) - 1E-9), 0. )
+
+         !   Aggregation term for diatoms is increased in case of nutrient
+         !   stress as observed in reality. The stressed cells become more
+         !   sticky and coagulate to sink quickly out of the euphotic zone
+         !   -------------------------------------------------------------
+         !  Phytoplankton squared mortality
+         !  -------------------------------
+         zlim2   = xlimdia(ji,jj,jk) * xlimdia(ji,jj,jk)
+         zlim1   = 0.25 * ( 1. - zlim2 ) / ( 0.25 + zlim2 ) 
+         zrespp2 = 1.e6 * xstep * (  wchld + wchldm * zlim1 ) * xdiss(ji,jj,jk) * zcompadi * tr(ji,jj,jk,jpdia,Kbb)
+
+         !  Phytoplankton linear mortality 
+         !  ------------------------------
+         ztortp2 = mpratd * xstep  * zcompadi
+         zmortp2 = zrespp2 + ztortp2
+
+         !   Update the arrays tr(:,:,:,:,Krhs) which contains the biological sources and sinks
+         !   ---------------------------------------------------------------------
+         zfactn  = tr(ji,jj,jk,jpndi,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+         zfactp  = tr(ji,jj,jk,jppdi,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+         zfactch = tr(ji,jj,jk,jpdch,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+         zfactfe = tr(ji,jj,jk,jpdfe,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+         zfactsi = tr(ji,jj,jk,jpdsi,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+         tr(ji,jj,jk,jpdia,Krhs) = tr(ji,jj,jk,jpdia,Krhs) - zmortp2 
+         tr(ji,jj,jk,jpndi,Krhs) = tr(ji,jj,jk,jpndi,Krhs) - zmortp2 * zfactn
+         tr(ji,jj,jk,jppdi,Krhs) = tr(ji,jj,jk,jppdi,Krhs) - zmortp2 * zfactp
+         tr(ji,jj,jk,jpdch,Krhs) = tr(ji,jj,jk,jpdch,Krhs) - zmortp2 * zfactch
+         tr(ji,jj,jk,jpdfe,Krhs) = tr(ji,jj,jk,jpdfe,Krhs) - zmortp2 * zfactfe
+         tr(ji,jj,jk,jpdsi,Krhs) = tr(ji,jj,jk,jpdsi,Krhs) - zmortp2 * zfactsi
+         tr(ji,jj,jk,jpgsi,Krhs) = tr(ji,jj,jk,jpgsi,Krhs) + zmortp2 * zfactsi
+         tr(ji,jj,jk,jpgoc,Krhs) = tr(ji,jj,jk,jpgoc,Krhs) + zrespp2 
+         tr(ji,jj,jk,jpgon,Krhs) = tr(ji,jj,jk,jpgon,Krhs) + zrespp2 * zfactn
+         tr(ji,jj,jk,jpgop,Krhs) = tr(ji,jj,jk,jpgop,Krhs) + zrespp2 * zfactp
+         tr(ji,jj,jk,jpbfe,Krhs) = tr(ji,jj,jk,jpbfe,Krhs) + zrespp2 * zfactfe
+         tr(ji,jj,jk,jppoc,Krhs) = tr(ji,jj,jk,jppoc,Krhs) + ztortp2
+         tr(ji,jj,jk,jppon,Krhs) = tr(ji,jj,jk,jppon,Krhs) + ztortp2 * zfactn
+         tr(ji,jj,jk,jppop,Krhs) = tr(ji,jj,jk,jppop,Krhs) + ztortp2 * zfactp
+         tr(ji,jj,jk,jpsfe,Krhs) = tr(ji,jj,jk,jpsfe,Krhs) + ztortp2 * zfactfe
+         prodpoc(ji,jj,jk)   = prodpoc(ji,jj,jk) + ztortp2
+         prodgoc(ji,jj,jk)   = prodgoc(ji,jj,jk) + zrespp2
+      END_3D
+      !
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('diat')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -286,11 +280,9 @@
       !!----------------------------------------------------------------------
 
-      REWIND( numnatp_ref )              ! Namelist nampismort in reference namelist : Pisces phytoplankton
       READ  ( numnatp_ref, namp5zmort, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namp5zmort in reference namelist', lwp )
-
-      REWIND( numnatp_cfg )              ! Namelist nampismort in configuration namelist : Pisces phytoplankton
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namp5zmort in reference namelist' )
+
       READ  ( numnatp_cfg, namp5zmort, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namp5zmort in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namp5zmort in configuration namelist' )
       IF(lwm) WRITE ( numonp, namp5zmort )
 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zprod.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zprod.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/P4Z/p5zprod.F90	(revision 13463)
@@ -18,5 +18,5 @@
    USE p4zlim
    USE p5zlim          !  Co-limitations of differents nutrients
-   USE prtctl_trc      !  print control for debugging
+   USE prtctl          !  print control for debugging
    USE iom             !  I/O manager
 
@@ -50,4 +50,7 @@
    REAL(wp) :: texcretd               !: 1 - excret2        
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -57,5 +60,5 @@
 CONTAINS
 
-   SUBROUTINE p5z_prod( kt , knt )
+   SUBROUTINE p5z_prod( kt , knt, Kbb, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE p5z_prod  ***
@@ -68,4 +71,5 @@
       !
       INTEGER, INTENT(in) :: kt, knt
+      INTEGER, INTENT(in) :: Kbb, Kmm, Krhs      ! time level indices
       !
       INTEGER  ::   ji, jj, jk
@@ -94,6 +98,4 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: zmxl_fac, zmxl_chl
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: zpligprod1, zpligprod2
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: zw3d
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:  ) :: zw2d
       !!---------------------------------------------------------------------
       !
@@ -101,4 +103,5 @@
       !
       zprorcan(:,:,:) = 0._wp ; zprorcap(:,:,:) = 0._wp ; zprorcad(:,:,:) = 0._wp
+      zcroissn(:,:,:) = 0._wp ; zcroissp(:,:,:) = 0._wp ; zcroissd(:,:,:) = 0._wp
       zprofed (:,:,:) = 0._wp ; zprofep (:,:,:) = 0._wp ; zprofen (:,:,:) = 0._wp
       zpronewn(:,:,:) = 0._wp ; zpronewp(:,:,:) = 0._wp ; zpronewd(:,:,:) = 0._wp
@@ -107,5 +110,5 @@
       zprdia  (:,:,:) = 0._wp ; zprpic  (:,:,:) = 0._wp ; zprbio  (:,:,:) = 0._wp
       zprodopn(:,:,:) = 0._wp ; zprodopp(:,:,:) = 0._wp ; zprodopd(:,:,:) = 0._wp
-      zysopt  (:,:,:) = 0._wp
+      zysopt  (:,:,:) = 0._wp 
       zrespn  (:,:,:) = 0._wp ; zrespp  (:,:,:) = 0._wp ; zrespd  (:,:,:) = 0._wp 
 
@@ -122,27 +125,21 @@
       ! day length in hours
       zstrn(:,:) = 0.
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zargu = TAN( zcodel ) * TAN( gphit(ji,jj) * rad )
-            zargu = MAX( -1., MIN(  1., zargu ) )
-            zstrn(ji,jj) = MAX( 0.0, 24. - 2. * ACOS( zargu ) / rad / 15. )
-         END DO
-      END DO
+      DO_2D( 1, 1, 1, 1 )
+         zargu = TAN( zcodel ) * TAN( gphit(ji,jj) * rad )
+         zargu = MAX( -1., MIN(  1., zargu ) )
+         zstrn(ji,jj) = MAX( 0.0, 24. - 2. * ACOS( zargu ) / rad / 15. )
+      END_2D
 
          ! Impact of the day duration on phytoplankton growth
-      DO jk = 1, jpkm1
-         DO jj = 1 ,jpj
-            DO ji = 1, jpi
-               IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                  zval = MAX( 1., zstrn(ji,jj) )
-                  IF( gdepw_n(ji,jj,jk+1) <= hmld(ji,jj) ) THEN
-                     zval = zval * MIN(1., heup_01(ji,jj) / ( hmld(ji,jj) + rtrn ))
-                  ENDIF
-                  zmxl_chl(ji,jj,jk) = zval / 24.
-                  zmxl_fac(ji,jj,jk) = 1.5 * zval / ( 12. + zval )
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+            zval = MAX( 1., zstrn(ji,jj) )
+            IF( gdepw(ji,jj,jk+1,Kmm) <= hmld(ji,jj) ) THEN
+               zval = zval * MIN(1., heup_01(ji,jj) / ( hmld(ji,jj) + rtrn ))
+            ENDIF
+            zmxl_chl(ji,jj,jk) = zval / 24.
+            zmxl_fac(ji,jj,jk) = 1.5 * zval / ( 12. + zval )
+         ENDIF
+      END_3D
 
       zprbio(:,:,:) = zprmaxn(:,:,:) * zmxl_fac(:,:,:)
@@ -155,305 +152,269 @@
       WHERE( zstrn(:,:) < 1.e0 ) zstrn(:,:) = 24.
 
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                  ! Computation of the P-I slope for nanos and diatoms
-                  ztn         = MAX( 0., tsn(ji,jj,jk,jp_tem) - 15. )
-                  zadap       = xadap * ztn / ( 2.+ ztn )
-                  !
-                  zpislopeadn(ji,jj,jk) = pislopen * trb(ji,jj,jk,jpnch)    &
-                  &                       /( trb(ji,jj,jk,jpphy) * 12. + rtrn)
-                  zpislopeadp(ji,jj,jk) = pislopep * ( 1. + zadap * EXP( -0.25 * epico(ji,jj,jk) ) )   &
-                  &                       * trb(ji,jj,jk,jppch) /( trb(ji,jj,jk,jppic) * 12. + rtrn)
-                  zpislopeadd(ji,jj,jk) = pisloped * trb(ji,jj,jk,jpdch)    &
-                     &                    /( trb(ji,jj,jk,jpdia) * 12. + rtrn)
-                  !
-                  zpislopen = zpislopeadn(ji,jj,jk) / ( zprbio(ji,jj,jk) * rday * xlimphy(ji,jj,jk) + rtrn )
-                  zpislopep = zpislopeadp(ji,jj,jk) / ( zprpic(ji,jj,jk) * rday * xlimpic(ji,jj,jk) + rtrn )
-                  zpisloped = zpislopeadd(ji,jj,jk) / ( zprdia(ji,jj,jk) * rday * xlimdia(ji,jj,jk) + rtrn )
-
-                  ! Computation of production function for Carbon
-                  !  ---------------------------------------------
-                  zprbio(ji,jj,jk) = zprbio(ji,jj,jk) * ( 1.- EXP( -zpislopen * enano(ji,jj,jk) )  )
-                  zprpic(ji,jj,jk) = zprpic(ji,jj,jk) * ( 1.- EXP( -zpislopep * epico(ji,jj,jk) )  )
-                  zprdia(ji,jj,jk) = zprdia(ji,jj,jk) * ( 1.- EXP( -zpisloped * ediat(ji,jj,jk) )  )
-
-                  ! Computation of production function for Chlorophyll
-                  !  -------------------------------------------------
-                  zpislopen = zpislopen * zmxl_fac(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
-                  zpisloped = zpisloped * zmxl_fac(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
-                  zpislopep = zpislopep * zmxl_fac(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
-                  zprchln(ji,jj,jk) = zprmaxn(ji,jj,jk) * ( 1.- EXP( -zpislopen * enanom(ji,jj,jk) )  )
-                  zprchlp(ji,jj,jk) = zprmaxp(ji,jj,jk) * ( 1.- EXP( -zpislopep * epicom(ji,jj,jk) )  )
-                  zprchld(ji,jj,jk) = zprmaxd(ji,jj,jk) * ( 1.- EXP( -zpisloped * ediatm(ji,jj,jk) )  )
-               ENDIF
-            END DO
-         END DO
-      END DO
-
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-
-                IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                  !    Si/C of diatoms
-                  !    ------------------------
-                  !    Si/C increases with iron stress and silicate availability
-                  !    Si/C is arbitrariliy increased for very high Si concentrations
-                  !    to mimic the very high ratios observed in the Southern Ocean (silpot2)
-                  zlim  = trb(ji,jj,jk,jpsil) / ( trb(ji,jj,jk,jpsil) + xksi1 )
-                  zsilim = MIN( zprdia(ji,jj,jk) / ( zprmaxd(ji,jj,jk) + rtrn ), xlimsi(ji,jj,jk) )
-                  zsilfac = 3.4 * EXP( -4.23 * zsilim ) * MAX( 0.e0, MIN( 1., 2.2 * ( zlim - 0.5 ) )  ) + 1.e0
-                  zsiborn = trb(ji,jj,jk,jpsil) * trb(ji,jj,jk,jpsil) * trb(ji,jj,jk,jpsil)
-                  IF (gphit(ji,jj) < -30 ) THEN
-                    zsilfac2 = 1. + 2. * zsiborn / ( zsiborn + xksi2**3 )
-                  ELSE
-                    zsilfac2 = 1. +      zsiborn / ( zsiborn + xksi2**3 )
-                  ENDIF
-                  zysopt(ji,jj,jk) = grosip * zlim * zsilfac * zsilfac2
-              ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+            ! Computation of the P-I slope for nanos and diatoms
+            ztn         = MAX( 0., ts(ji,jj,jk,jp_tem,Kmm) - 15. )
+            zadap       = xadap * ztn / ( 2.+ ztn )
+            !
+            zpislopeadn(ji,jj,jk) = pislopen * tr(ji,jj,jk,jpnch,Kbb)    &
+            &                       /( tr(ji,jj,jk,jpphy,Kbb) * 12. + rtrn)
+            zpislopeadp(ji,jj,jk) = pislopep * ( 1. + zadap * EXP( -0.25 * epico(ji,jj,jk) ) )   &
+            &                       * tr(ji,jj,jk,jppch,Kbb) /( tr(ji,jj,jk,jppic,Kbb) * 12. + rtrn)
+            zpislopeadd(ji,jj,jk) = pisloped * tr(ji,jj,jk,jpdch,Kbb)    &
+               &                    /( tr(ji,jj,jk,jpdia,Kbb) * 12. + rtrn)
+            !
+            zpislopen = zpislopeadn(ji,jj,jk) / ( zprbio(ji,jj,jk) * rday * xlimphy(ji,jj,jk) + rtrn )
+            zpislopep = zpislopeadp(ji,jj,jk) / ( zprpic(ji,jj,jk) * rday * xlimpic(ji,jj,jk) + rtrn )
+            zpisloped = zpislopeadd(ji,jj,jk) / ( zprdia(ji,jj,jk) * rday * xlimdia(ji,jj,jk) + rtrn )
+
+            ! Computation of production function for Carbon
+            !  ---------------------------------------------
+            zprbio(ji,jj,jk) = zprbio(ji,jj,jk) * ( 1.- EXP( -zpislopen * enano(ji,jj,jk) )  )
+            zprpic(ji,jj,jk) = zprpic(ji,jj,jk) * ( 1.- EXP( -zpislopep * epico(ji,jj,jk) )  )
+            zprdia(ji,jj,jk) = zprdia(ji,jj,jk) * ( 1.- EXP( -zpisloped * ediat(ji,jj,jk) )  )
+
+            ! Computation of production function for Chlorophyll
+            !  -------------------------------------------------
+            zpislopen = zpislopen * zmxl_fac(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
+            zpisloped = zpisloped * zmxl_fac(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
+            zpislopep = zpislopep * zmxl_fac(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
+            zprchln(ji,jj,jk) = zprmaxn(ji,jj,jk) * ( 1.- EXP( -zpislopen * enanom(ji,jj,jk) )  )
+            zprchlp(ji,jj,jk) = zprmaxp(ji,jj,jk) * ( 1.- EXP( -zpislopep * epicom(ji,jj,jk) )  )
+            zprchld(ji,jj,jk) = zprmaxd(ji,jj,jk) * ( 1.- EXP( -zpisloped * ediatm(ji,jj,jk) )  )
+         ENDIF
+      END_3D
+
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+
+          IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+            !    Si/C of diatoms
+            !    ------------------------
+            !    Si/C increases with iron stress and silicate availability
+            !    Si/C is arbitrariliy increased for very high Si concentrations
+            !    to mimic the very high ratios observed in the Southern Ocean (silpot2)
+            zlim  = tr(ji,jj,jk,jpsil,Kbb) / ( tr(ji,jj,jk,jpsil,Kbb) + xksi1 )
+            zsilim = MIN( zprdia(ji,jj,jk) / ( zprmaxd(ji,jj,jk) + rtrn ), xlimsi(ji,jj,jk) )
+            zsilfac = 3.4 * EXP( -4.23 * zsilim ) * MAX( 0.e0, MIN( 1., 2.2 * ( zlim - 0.5 ) )  ) + 1.e0
+            zsiborn = tr(ji,jj,jk,jpsil,Kbb) * tr(ji,jj,jk,jpsil,Kbb) * tr(ji,jj,jk,jpsil,Kbb)
+            IF (gphit(ji,jj) < -30 ) THEN
+              zsilfac2 = 1. + 2. * zsiborn / ( zsiborn + xksi2**3 )
+            ELSE
+              zsilfac2 = 1. +      zsiborn / ( zsiborn + xksi2**3 )
+            ENDIF
+            zysopt(ji,jj,jk) = grosip * zlim * zsilfac * zsilfac2
+        ENDIF
+      END_3D
 
       !  Sea-ice effect on production                                                                               
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zprbio(ji,jj,jk)  = zprbio(ji,jj,jk) * ( 1. - fr_i(ji,jj) )
-               zprpic(ji,jj,jk)  = zprpic(ji,jj,jk) * ( 1. - fr_i(ji,jj) ) 
-               zprdia(ji,jj,jk)  = zprdia(ji,jj,jk) * ( 1. - fr_i(ji,jj) ) 
-               zprnut(ji,jj,jk)  = zprnut(ji,jj,jk) * ( 1. - fr_i(ji,jj) )
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         zprbio(ji,jj,jk)  = zprbio(ji,jj,jk) * ( 1. - fr_i(ji,jj) )
+         zprpic(ji,jj,jk)  = zprpic(ji,jj,jk) * ( 1. - fr_i(ji,jj) ) 
+         zprdia(ji,jj,jk)  = zprdia(ji,jj,jk) * ( 1. - fr_i(ji,jj) ) 
+         zprnut(ji,jj,jk)  = zprnut(ji,jj,jk) * ( 1. - fr_i(ji,jj) )
+      END_3D
 
       ! Computation of the various production terms of nanophytoplankton 
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                  !  production terms for nanophyto.
-                  zprorcan(ji,jj,jk) = zprbio(ji,jj,jk)  * xlimphy(ji,jj,jk) * trb(ji,jj,jk,jpphy) * rfact2
-                  !
-                  zration = trb(ji,jj,jk,jpnph) / ( trb(ji,jj,jk,jpphy) + rtrn )
-                  zratiop = trb(ji,jj,jk,jppph) / ( trb(ji,jj,jk,jpphy) + rtrn )
-                  zratiof = trb(ji,jj,jk,jpnfe) / ( trb(ji,jj,jk,jpphy) + rtrn )
-                  zprnutmax = zprnut(ji,jj,jk) * fvnuptk(ji,jj,jk) / rno3 * trb(ji,jj,jk,jpphy) * rfact2
-                  ! Uptake of nitrogen
-                  zrat = MIN( 1., zration / (xqnnmax(ji,jj,jk) + rtrn) ) 
-                  zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05))
-                  zpronmax = zprnutmax * zmax * MAX(0., MIN(1., ( zratiop - xqpnmin(ji,jj,jk) )   &
-                  &          / ( xqpnmax(ji,jj,jk) - xqpnmin(ji,jj,jk) + rtrn ), xlimnfe(ji,jj,jk) ) )
-                  zpronewn(ji,jj,jk) = zpronmax * zdaylen(ji,jj) * xnanono3(ji,jj,jk)
-                  zproregn(ji,jj,jk) = zpronmax * xnanonh4(ji,jj,jk)
-                  ! Uptake of phosphorus
-                  zrat = MIN( 1., zratiop / (xqpnmax(ji,jj,jk) + rtrn) )
-                  zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05))
-                  zpropmax = zprnutmax * zmax * xlimnfe(ji,jj,jk)
-                  zpropo4n(ji,jj,jk) = zpropmax * xnanopo4(ji,jj,jk)
-                  zprodopn(ji,jj,jk) = zpropmax * xnanodop(ji,jj,jk)
-                  ! Uptake of iron
-                  zrat = MIN( 1., zratiof / qfnmax )
-                  zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05))
-                  zprofmax = zprnutmax * qfnmax * zmax
-                  zprofen(ji,jj,jk) = zprofmax * xnanofer(ji,jj,jk) * ( 3. - 2.4 * xlimnfe(ji,jj,jk)    &
-                  &          / ( xlimnfe(ji,jj,jk) + 0.2 ) ) * (1. + 0.8 * xnanono3(ji,jj,jk) / ( rtrn  &
-                  &          + xnanono3(ji,jj,jk) + xnanonh4(ji,jj,jk) ) * (1. - xnanofer(ji,jj,jk) ) )
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+            !  production terms for nanophyto.
+            zprorcan(ji,jj,jk) = zprbio(ji,jj,jk)  * xlimphy(ji,jj,jk) * tr(ji,jj,jk,jpphy,Kbb) * rfact2
+            !
+            zration = tr(ji,jj,jk,jpnph,Kbb) / ( tr(ji,jj,jk,jpphy,Kbb) + rtrn )
+            zratiop = tr(ji,jj,jk,jppph,Kbb) / ( tr(ji,jj,jk,jpphy,Kbb) + rtrn )
+            zratiof = tr(ji,jj,jk,jpnfe,Kbb) / ( tr(ji,jj,jk,jpphy,Kbb) + rtrn )
+            zprnutmax = zprnut(ji,jj,jk) * fvnuptk(ji,jj,jk) / rno3 * tr(ji,jj,jk,jpphy,Kbb) * rfact2
+            ! Uptake of nitrogen
+            zrat = MIN( 1., zration / (xqnnmax(ji,jj,jk) + rtrn) ) 
+            zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05))
+            zpronmax = zprnutmax * zmax * MAX(0., MIN(1., ( zratiop - xqpnmin(ji,jj,jk) )   &
+            &          / ( xqpnmax(ji,jj,jk) - xqpnmin(ji,jj,jk) + rtrn ), xlimnfe(ji,jj,jk) ) )
+            zpronewn(ji,jj,jk) = zpronmax * zdaylen(ji,jj) * xnanono3(ji,jj,jk)
+            zproregn(ji,jj,jk) = zpronmax * xnanonh4(ji,jj,jk)
+            ! Uptake of phosphorus
+            zrat = MIN( 1., zratiop / (xqpnmax(ji,jj,jk) + rtrn) )
+            zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05))
+            zpropmax = zprnutmax * zmax * xlimnfe(ji,jj,jk)
+            zpropo4n(ji,jj,jk) = zpropmax * xnanopo4(ji,jj,jk)
+            zprodopn(ji,jj,jk) = zpropmax * xnanodop(ji,jj,jk)
+            ! Uptake of iron
+            zrat = MIN( 1., zratiof / qfnmax )
+            zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05))
+            zprofmax = zprnutmax * qfnmax * zmax
+            zprofen(ji,jj,jk) = zprofmax * xnanofer(ji,jj,jk) * ( 3. - 2.4 * xlimnfe(ji,jj,jk)    &
+            &          / ( xlimnfe(ji,jj,jk) + 0.2 ) ) * (1. + 0.8 * xnanono3(ji,jj,jk) / ( rtrn  &
+            &          + xnanono3(ji,jj,jk) + xnanonh4(ji,jj,jk) ) * (1. - xnanofer(ji,jj,jk) ) )
+         ENDIF
+      END_3D
 
       ! Computation of the various production terms of picophytoplankton 
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                  !  production terms for picophyto.
-                  zprorcap(ji,jj,jk) = zprpic(ji,jj,jk)  * xlimpic(ji,jj,jk) * trb(ji,jj,jk,jppic) * rfact2
-                  !
-                  zration = trb(ji,jj,jk,jpnpi) / ( trb(ji,jj,jk,jppic) + rtrn )
-                  zratiop = trb(ji,jj,jk,jpppi) / ( trb(ji,jj,jk,jppic) + rtrn )
-                  zratiof = trb(ji,jj,jk,jppfe) / ( trb(ji,jj,jk,jppic) + rtrn )
-                  zprnutmax = zprnut(ji,jj,jk) * fvpuptk(ji,jj,jk) / rno3 * trb(ji,jj,jk,jppic) * rfact2
-                  ! Uptake of nitrogen
-                  zrat = MIN( 1., zration / (xqnpmax(ji,jj,jk) + rtrn) )
-                  zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05))
-                  zpronmax = zprnutmax * zmax * MAX(0., MIN(1., ( zratiop - xqppmin(ji,jj,jk) )   &
-                  &          / ( xqppmax(ji,jj,jk) - xqppmin(ji,jj,jk) + rtrn ), xlimpfe(ji,jj,jk) ) )
-                  zpronewp(ji,jj,jk) = zpronmax * zdaylen(ji,jj) * xpicono3(ji,jj,jk) 
-                  zproregp(ji,jj,jk) = zpronmax * xpiconh4(ji,jj,jk)
-                  ! Uptake of phosphorus
-                  zrat = MIN( 1., zratiop / (xqppmax(ji,jj,jk) + rtrn) )
-                  zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05))
-                  zpropmax = zprnutmax * zmax * xlimpfe(ji,jj,jk)
-                  zpropo4p(ji,jj,jk) = zpropmax * xpicopo4(ji,jj,jk)
-                  zprodopp(ji,jj,jk) = zpropmax * xpicodop(ji,jj,jk)
-                  ! Uptake of iron
-                  zrat = MIN( 1., zratiof / qfpmax )
-                  zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05))
-                  zprofmax = zprnutmax * qfpmax * zmax
-                  zprofep(ji,jj,jk) = zprofmax * xpicofer(ji,jj,jk) * ( 3. - 2.4 * xlimpfe(ji,jj,jk)   &
-                  &          / ( xlimpfe(ji,jj,jk) + 0.2 ) ) * (1. + 0.8 * xpicono3(ji,jj,jk) / ( rtrn   &
-                  &          + xpicono3(ji,jj,jk) + xpiconh4(ji,jj,jk) ) * (1. - xpicofer(ji,jj,jk) ) )
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+            !  production terms for picophyto.
+            zprorcap(ji,jj,jk) = zprpic(ji,jj,jk)  * xlimpic(ji,jj,jk) * tr(ji,jj,jk,jppic,Kbb) * rfact2
+            !
+            zration = tr(ji,jj,jk,jpnpi,Kbb) / ( tr(ji,jj,jk,jppic,Kbb) + rtrn )
+            zratiop = tr(ji,jj,jk,jpppi,Kbb) / ( tr(ji,jj,jk,jppic,Kbb) + rtrn )
+            zratiof = tr(ji,jj,jk,jppfe,Kbb) / ( tr(ji,jj,jk,jppic,Kbb) + rtrn )
+            zprnutmax = zprnut(ji,jj,jk) * fvpuptk(ji,jj,jk) / rno3 * tr(ji,jj,jk,jppic,Kbb) * rfact2
+            ! Uptake of nitrogen
+            zrat = MIN( 1., zration / (xqnpmax(ji,jj,jk) + rtrn) )
+            zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05))
+            zpronmax = zprnutmax * zmax * MAX(0., MIN(1., ( zratiop - xqppmin(ji,jj,jk) )   &
+            &          / ( xqppmax(ji,jj,jk) - xqppmin(ji,jj,jk) + rtrn ), xlimpfe(ji,jj,jk) ) )
+            zpronewp(ji,jj,jk) = zpronmax * zdaylen(ji,jj) * xpicono3(ji,jj,jk) 
+            zproregp(ji,jj,jk) = zpronmax * xpiconh4(ji,jj,jk)
+            ! Uptake of phosphorus
+            zrat = MIN( 1., zratiop / (xqppmax(ji,jj,jk) + rtrn) )
+            zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05))
+            zpropmax = zprnutmax * zmax * xlimpfe(ji,jj,jk)
+            zpropo4p(ji,jj,jk) = zpropmax * xpicopo4(ji,jj,jk)
+            zprodopp(ji,jj,jk) = zpropmax * xpicodop(ji,jj,jk)
+            ! Uptake of iron
+            zrat = MIN( 1., zratiof / qfpmax )
+            zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05))
+            zprofmax = zprnutmax * qfpmax * zmax
+            zprofep(ji,jj,jk) = zprofmax * xpicofer(ji,jj,jk) * ( 3. - 2.4 * xlimpfe(ji,jj,jk)   &
+            &          / ( xlimpfe(ji,jj,jk) + 0.2 ) ) * (1. + 0.8 * xpicono3(ji,jj,jk) / ( rtrn   &
+            &          + xpicono3(ji,jj,jk) + xpiconh4(ji,jj,jk) ) * (1. - xpicofer(ji,jj,jk) ) )
+         ENDIF
+      END_3D
 
       ! Computation of the various production terms of diatoms
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                  !  production terms for diatomees
-                  zprorcad(ji,jj,jk) = zprdia(ji,jj,jk) * xlimdia(ji,jj,jk) * trb(ji,jj,jk,jpdia) * rfact2
-                  ! Computation of the respiration term according to pahlow 
-                  ! & oschlies (2013)
-                  !
-                  zration = trb(ji,jj,jk,jpndi) / ( trb(ji,jj,jk,jpdia) + rtrn )
-                  zratiop = trb(ji,jj,jk,jppdi) / ( trb(ji,jj,jk,jpdia) + rtrn )
-                  zratiof = trb(ji,jj,jk,jpdfe) / ( trb(ji,jj,jk,jpdia) + rtrn )
-                  zprnutmax = zprnut(ji,jj,jk) * fvduptk(ji,jj,jk) / rno3 * trb(ji,jj,jk,jpdia) * rfact2
-                  ! Uptake of nitrogen
-                  zrat = MIN( 1., zration / (xqndmax(ji,jj,jk) + rtrn) )
-                  zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05)) 
-                  zpronmax = zprnutmax * zmax * MAX(0., MIN(1., ( zratiop - xqpdmin(ji,jj,jk) )   &
-                  &          / ( xqpdmax(ji,jj,jk) - xqpdmin(ji,jj,jk) + rtrn ), xlimdfe(ji,jj,jk) ) )
-                  zpronewd(ji,jj,jk) = zpronmax * zdaylen(ji,jj) * xdiatno3(ji,jj,jk)
-                  zproregd(ji,jj,jk) = zpronmax * xdiatnh4(ji,jj,jk)
-                  ! Uptake of phosphorus
-                  zrat = MIN( 1., zratiop / (xqpdmax(ji,jj,jk) + rtrn) )
-                  zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05)) 
-                  zpropmax = zprnutmax * zmax * xlimdfe(ji,jj,jk)
-                  zpropo4d(ji,jj,jk) = zpropmax * xdiatpo4(ji,jj,jk)
-                  zprodopd(ji,jj,jk) = zpropmax * xdiatdop(ji,jj,jk)
-                  ! Uptake of iron
-                  zrat = MIN( 1., zratiof / qfdmax )
-                  zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05))
-                  zprofmax = zprnutmax * qfdmax * zmax
-                  zprofed(ji,jj,jk) = zprofmax * xdiatfer(ji,jj,jk) * ( 3. - 2.4 * xlimdfe(ji,jj,jk)     &
-                  &          / ( xlimdfe(ji,jj,jk) + 0.2 ) ) * (1. + 0.8 * xdiatno3(ji,jj,jk) / ( rtrn   &
-                  &          + xdiatno3(ji,jj,jk) + xdiatnh4(ji,jj,jk) ) * (1. - xdiatfer(ji,jj,jk) ) )
-               ENDIF
-            END DO
-         END DO
-      END DO
-
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
-                     !  production terms for nanophyto. ( chlorophyll )
-                  znanotot = enanom(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
-                  zprod = rday * (zpronewn(ji,jj,jk) + zproregn(ji,jj,jk)) * zprchln(ji,jj,jk) * xlimphy(ji,jj,jk)
-                  thetannm_n   = MIN ( thetannm, ( thetannm / (1. - 1.14 / 43.4 *tsn(ji,jj,jk,jp_tem)))   &
-                  &               * (1. - 1.14 / 43.4 * 20.))
-                  zprochln = thetannm_n * zprod / ( zpislopeadn(ji,jj,jk) * znanotot + rtrn )
-                  zprochln = MAX(zprochln, chlcmin * 12. * zprorcan (ji,jj,jk) )
-                     !  production terms for picophyto. ( chlorophyll )
-                  zpicotot = epicom(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
-                  zprod = rday * (zpronewp(ji,jj,jk) + zproregp(ji,jj,jk)) * zprchlp(ji,jj,jk) * xlimpic(ji,jj,jk)
-                  thetanpm_n   = MIN ( thetanpm, ( thetanpm / (1. - 1.14 / 43.4 *tsn(ji,jj,jk,jp_tem)))   &
-                  &               * (1. - 1.14 / 43.4 * 20.))
-                  zprochlp = thetanpm_n * zprod / ( zpislopeadp(ji,jj,jk) * zpicotot + rtrn )
-                  zprochlp = MAX(zprochlp, chlcmin * 12. * zprorcap(ji,jj,jk) )
-                  !  production terms for diatomees ( chlorophyll )
-                  zdiattot = ediatm(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
-                  zprod = rday * (zpronewd(ji,jj,jk) + zproregd(ji,jj,jk)) * zprchld(ji,jj,jk) * xlimdia(ji,jj,jk)
-                  thetandm_n   = MIN ( thetandm, ( thetandm / (1. - 1.14 / 43.4 *tsn(ji,jj,jk,jp_tem)))   &
-                  &               * (1. - 1.14 / 43.4 * 20.))
-                  zprochld = thetandm_n * zprod / ( zpislopeadd(ji,jj,jk) * zdiattot + rtrn )
-                  zprochld = MAX(zprochld, chlcmin * 12. * zprorcad(ji,jj,jk) )
-                  !   Update the arrays TRA which contain the Chla sources and sinks
-                  tra(ji,jj,jk,jpnch) = tra(ji,jj,jk,jpnch) + zprochln * texcretn
-                  tra(ji,jj,jk,jpdch) = tra(ji,jj,jk,jpdch) + zprochld * texcretd
-                  tra(ji,jj,jk,jppch) = tra(ji,jj,jk,jppch) + zprochlp * texcretp
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+            !  production terms for diatomees
+            zprorcad(ji,jj,jk) = zprdia(ji,jj,jk) * xlimdia(ji,jj,jk) * tr(ji,jj,jk,jpdia,Kbb) * rfact2
+            ! Computation of the respiration term according to pahlow 
+            ! & oschlies (2013)
+            !
+            zration = tr(ji,jj,jk,jpndi,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+            zratiop = tr(ji,jj,jk,jppdi,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+            zratiof = tr(ji,jj,jk,jpdfe,Kbb) / ( tr(ji,jj,jk,jpdia,Kbb) + rtrn )
+            zprnutmax = zprnut(ji,jj,jk) * fvduptk(ji,jj,jk) / rno3 * tr(ji,jj,jk,jpdia,Kbb) * rfact2
+            ! Uptake of nitrogen
+            zrat = MIN( 1., zration / (xqndmax(ji,jj,jk) + rtrn) )
+            zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05)) 
+            zpronmax = zprnutmax * zmax * MAX(0., MIN(1., ( zratiop - xqpdmin(ji,jj,jk) )   &
+            &          / ( xqpdmax(ji,jj,jk) - xqpdmin(ji,jj,jk) + rtrn ), xlimdfe(ji,jj,jk) ) )
+            zpronewd(ji,jj,jk) = zpronmax * zdaylen(ji,jj) * xdiatno3(ji,jj,jk)
+            zproregd(ji,jj,jk) = zpronmax * xdiatnh4(ji,jj,jk)
+            ! Uptake of phosphorus
+            zrat = MIN( 1., zratiop / (xqpdmax(ji,jj,jk) + rtrn) )
+            zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05)) 
+            zpropmax = zprnutmax * zmax * xlimdfe(ji,jj,jk)
+            zpropo4d(ji,jj,jk) = zpropmax * xdiatpo4(ji,jj,jk)
+            zprodopd(ji,jj,jk) = zpropmax * xdiatdop(ji,jj,jk)
+            ! Uptake of iron
+            zrat = MIN( 1., zratiof / qfdmax )
+            zmax = MAX(0., MIN(1., (1. - zrat)/ (1.05 - zrat) * 1.05))
+            zprofmax = zprnutmax * qfdmax * zmax
+            zprofed(ji,jj,jk) = zprofmax * xdiatfer(ji,jj,jk) * ( 3. - 2.4 * xlimdfe(ji,jj,jk)     &
+            &          / ( xlimdfe(ji,jj,jk) + 0.2 ) ) * (1. + 0.8 * xdiatno3(ji,jj,jk) / ( rtrn   &
+            &          + xdiatno3(ji,jj,jk) + xdiatnh4(ji,jj,jk) ) * (1. - xdiatfer(ji,jj,jk) ) )
+         ENDIF
+      END_3D
+
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         IF( etot_ndcy(ji,jj,jk) > 1.E-3 ) THEN
+               !  production terms for nanophyto. ( chlorophyll )
+            znanotot = enanom(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
+            zprod = rday * (zpronewn(ji,jj,jk) + zproregn(ji,jj,jk)) * zprchln(ji,jj,jk) * xlimphy(ji,jj,jk)
+            thetannm_n   = MIN ( thetannm, ( thetannm / (1. - 1.14 / 43.4 *ts(ji,jj,jk,jp_tem,Kmm)))   &
+            &               * (1. - 1.14 / 43.4 * 20.))
+            zprochln = thetannm_n * zprod / ( zpislopeadn(ji,jj,jk) * znanotot + rtrn )
+            zprochln = MAX(zprochln, chlcmin * 12. * zprorcan (ji,jj,jk) )
+               !  production terms for picophyto. ( chlorophyll )
+            zpicotot = epicom(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
+            zprod = rday * (zpronewp(ji,jj,jk) + zproregp(ji,jj,jk)) * zprchlp(ji,jj,jk) * xlimpic(ji,jj,jk)
+            thetanpm_n   = MIN ( thetanpm, ( thetanpm / (1. - 1.14 / 43.4 *ts(ji,jj,jk,jp_tem,Kmm)))   &
+            &               * (1. - 1.14 / 43.4 * 20.))
+            zprochlp = thetanpm_n * zprod / ( zpislopeadp(ji,jj,jk) * zpicotot + rtrn )
+            zprochlp = MAX(zprochlp, chlcmin * 12. * zprorcap(ji,jj,jk) )
+            !  production terms for diatomees ( chlorophyll )
+            zdiattot = ediatm(ji,jj,jk) / ( zmxl_chl(ji,jj,jk) + rtrn )
+            zprod = rday * (zpronewd(ji,jj,jk) + zproregd(ji,jj,jk)) * zprchld(ji,jj,jk) * xlimdia(ji,jj,jk)
+            thetandm_n   = MIN ( thetandm, ( thetandm / (1. - 1.14 / 43.4 *ts(ji,jj,jk,jp_tem,Kmm)))   &
+            &               * (1. - 1.14 / 43.4 * 20.))
+            zprochld = thetandm_n * zprod / ( zpislopeadd(ji,jj,jk) * zdiattot + rtrn )
+            zprochld = MAX(zprochld, chlcmin * 12. * zprorcad(ji,jj,jk) )
+            !   Update the arrays TRA which contain the Chla sources and sinks
+            tr(ji,jj,jk,jpnch,Krhs) = tr(ji,jj,jk,jpnch,Krhs) + zprochln * texcretn
+            tr(ji,jj,jk,jpdch,Krhs) = tr(ji,jj,jk,jpdch,Krhs) + zprochld * texcretd
+            tr(ji,jj,jk,jppch,Krhs) = tr(ji,jj,jk,jppch,Krhs) + zprochlp * texcretp
+         ENDIF
+      END_3D
 
       !   Update the arrays TRA which contain the biological sources and sinks
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-           DO ji =1 ,jpi
-              zprontot = zpronewn(ji,jj,jk) + zproregn(ji,jj,jk)
-              zproptot = zpronewp(ji,jj,jk) + zproregp(ji,jj,jk)
-              zprodtot = zpronewd(ji,jj,jk) + zproregd(ji,jj,jk)
-              zdocprod = excretd * zprorcad(ji,jj,jk) + excretn * zprorcan(ji,jj,jk)  &
-              &          + excretp * zprorcap(ji,jj,jk)
-              tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) - zpropo4n(ji,jj,jk) - zpropo4d(ji,jj,jk)  &
-              &                     - zpropo4p(ji,jj,jk)
-              tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) - zpronewn(ji,jj,jk) - zpronewd(ji,jj,jk)  &
-              &                     - zpronewp(ji,jj,jk)
-              tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) - zproregn(ji,jj,jk) - zproregd(ji,jj,jk)  &
-              &                     - zproregp(ji,jj,jk)
-              tra(ji,jj,jk,jpphy) = tra(ji,jj,jk,jpphy) + zprorcan(ji,jj,jk) * texcretn    &
-                 &                  - zpsino3 * zpronewn(ji,jj,jk) - zpsinh4 * zproregn(ji,jj,jk)   &
-                 &                  - zrespn(ji,jj,jk) 
-              zcroissn(ji,jj,jk) = tra(ji,jj,jk,jpphy) / rfact2/ (trb(ji,jj,jk,jpphy) + rtrn)
-              tra(ji,jj,jk,jpnph) = tra(ji,jj,jk,jpnph) + zprontot * texcretn
-              tra(ji,jj,jk,jppph) = tra(ji,jj,jk,jppph) + zpropo4n(ji,jj,jk) * texcretn   &
-              &                     + zprodopn(ji,jj,jk) * texcretn
-              tra(ji,jj,jk,jpnfe) = tra(ji,jj,jk,jpnfe) + zprofen(ji,jj,jk) * texcretn
-              tra(ji,jj,jk,jppic) = tra(ji,jj,jk,jppic) + zprorcap(ji,jj,jk) * texcretp     &
-                 &                  - zpsino3 * zpronewp(ji,jj,jk) - zpsinh4 * zproregp(ji,jj,jk)   &
-                 &                  - zrespp(ji,jj,jk) 
-              zcroissp(ji,jj,jk) = tra(ji,jj,jk,jppic) / rfact2/ (trb(ji,jj,jk,jppic) + rtrn)
-              tra(ji,jj,jk,jpnpi) = tra(ji,jj,jk,jpnpi) + zproptot * texcretp
-              tra(ji,jj,jk,jpppi) = tra(ji,jj,jk,jpppi) + zpropo4p(ji,jj,jk) * texcretp   &
-              &                     + zprodopp(ji,jj,jk) * texcretp
-              tra(ji,jj,jk,jppfe) = tra(ji,jj,jk,jppfe) + zprofep(ji,jj,jk) * texcretp
-              tra(ji,jj,jk,jpdia) = tra(ji,jj,jk,jpdia) + zprorcad(ji,jj,jk) * texcretd   &
-                 &                  - zpsino3 * zpronewd(ji,jj,jk) - zpsinh4 * zproregd(ji,jj,jk)   &
-                 &                  - zrespd(ji,jj,jk) 
-              zcroissd(ji,jj,jk) = tra(ji,jj,jk,jpdia) / rfact2 / (trb(ji,jj,jk,jpdia) + rtrn)
-              tra(ji,jj,jk,jpndi) = tra(ji,jj,jk,jpndi) + zprodtot * texcretd
-              tra(ji,jj,jk,jppdi) = tra(ji,jj,jk,jppdi) + zpropo4d(ji,jj,jk) * texcretd   &
-              &                     + zprodopd(ji,jj,jk) * texcretd
-              tra(ji,jj,jk,jpdfe) = tra(ji,jj,jk,jpdfe) + zprofed(ji,jj,jk) * texcretd
-              tra(ji,jj,jk,jpdsi) = tra(ji,jj,jk,jpdsi) + zprorcad(ji,jj,jk) * zysopt(ji,jj,jk) * texcretd
-              tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) + excretd * zprorcad(ji,jj,jk) + excretn * zprorcan(ji,jj,jk)  &
-              &                     + excretp * zprorcap(ji,jj,jk)
-              tra(ji,jj,jk,jpdon) = tra(ji,jj,jk,jpdon) + excretd * zprodtot + excretn * zprontot   &
-              &                     + excretp * zproptot
-              tra(ji,jj,jk,jpdop) = tra(ji,jj,jk,jpdop) + excretd * zpropo4d(ji,jj,jk) + excretn * zpropo4n(ji,jj,jk)   &
-              &    - texcretn * zprodopn(ji,jj,jk) - texcretd * zprodopd(ji,jj,jk) + excretp * zpropo4p(ji,jj,jk)     &
-              &    - texcretp * zprodopp(ji,jj,jk)
-              tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) + o2ut * ( zproregn(ji,jj,jk) + zproregd(ji,jj,jk)   &
-                 &                + zproregp(ji,jj,jk) ) + ( o2ut + o2nit ) * ( zpronewn(ji,jj,jk)           &
-                 &                + zpronewd(ji,jj,jk) + zpronewp(ji,jj,jk) )   &
-                 &                - o2ut * ( zrespn(ji,jj,jk) + zrespp(ji,jj,jk) + zrespd(ji,jj,jk) )
-              zfeup = texcretn * zprofen(ji,jj,jk) + texcretd * zprofed(ji,jj,jk) + texcretp * zprofep(ji,jj,jk)
-              tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) - zfeup
-              tra(ji,jj,jk,jpsil) = tra(ji,jj,jk,jpsil) - texcretd * zprorcad(ji,jj,jk) * zysopt(ji,jj,jk)
-              tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) - zprorcan(ji,jj,jk) - zprorcad(ji,jj,jk) - zprorcap(ji,jj,jk)  &
-              &                     + zpsino3 * zpronewn(ji,jj,jk) + zpsinh4 * zproregn(ji,jj,jk)   &
-              &                     + zpsino3 * zpronewp(ji,jj,jk) + zpsinh4 * zproregp(ji,jj,jk)   &
-              &                     + zpsino3 * zpronewd(ji,jj,jk) + zpsinh4 * zproregd(ji,jj,jk)  &
-              &                     + zrespn(ji,jj,jk) + zrespd(ji,jj,jk) + zrespp(ji,jj,jk) 
-              tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) + rno3 * ( zpronewn(ji,jj,jk) + zpronewd(ji,jj,jk)  &
-              &                     + zpronewp(ji,jj,jk) ) - rno3 * ( zproregn(ji,jj,jk) + zproregd(ji,jj,jk)     &
-              &                     + zproregp(ji,jj,jk) ) 
-          END DO
-        END DO
-     END DO
+      DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+        zprontot = zpronewn(ji,jj,jk) + zproregn(ji,jj,jk)
+        zproptot = zpronewp(ji,jj,jk) + zproregp(ji,jj,jk)
+        zprodtot = zpronewd(ji,jj,jk) + zproregd(ji,jj,jk)
+        zdocprod = excretd * zprorcad(ji,jj,jk) + excretn * zprorcan(ji,jj,jk)  &
+        &          + excretp * zprorcap(ji,jj,jk)
+        tr(ji,jj,jk,jppo4,Krhs) = tr(ji,jj,jk,jppo4,Krhs) - zpropo4n(ji,jj,jk) - zpropo4d(ji,jj,jk)  &
+        &                     - zpropo4p(ji,jj,jk)
+        tr(ji,jj,jk,jpno3,Krhs) = tr(ji,jj,jk,jpno3,Krhs) - zpronewn(ji,jj,jk) - zpronewd(ji,jj,jk)  &
+        &                     - zpronewp(ji,jj,jk)
+        tr(ji,jj,jk,jpnh4,Krhs) = tr(ji,jj,jk,jpnh4,Krhs) - zproregn(ji,jj,jk) - zproregd(ji,jj,jk)  &
+        &                     - zproregp(ji,jj,jk)
+        tr(ji,jj,jk,jpphy,Krhs) = tr(ji,jj,jk,jpphy,Krhs) + zprorcan(ji,jj,jk) * texcretn    &
+           &                  - zpsino3 * zpronewn(ji,jj,jk) - zpsinh4 * zproregn(ji,jj,jk)   &
+           &                  - zrespn(ji,jj,jk) 
+        zcroissn(ji,jj,jk) = tr(ji,jj,jk,jpphy,Krhs) / rfact2/ (tr(ji,jj,jk,jpphy,Kbb) + rtrn)
+        tr(ji,jj,jk,jpnph,Krhs) = tr(ji,jj,jk,jpnph,Krhs) + zprontot * texcretn
+        tr(ji,jj,jk,jppph,Krhs) = tr(ji,jj,jk,jppph,Krhs) + zpropo4n(ji,jj,jk) * texcretn   &
+        &                     + zprodopn(ji,jj,jk) * texcretn
+        tr(ji,jj,jk,jpnfe,Krhs) = tr(ji,jj,jk,jpnfe,Krhs) + zprofen(ji,jj,jk) * texcretn
+        tr(ji,jj,jk,jppic,Krhs) = tr(ji,jj,jk,jppic,Krhs) + zprorcap(ji,jj,jk) * texcretp     &
+           &                  - zpsino3 * zpronewp(ji,jj,jk) - zpsinh4 * zproregp(ji,jj,jk)   &
+           &                  - zrespp(ji,jj,jk) 
+        zcroissp(ji,jj,jk) = tr(ji,jj,jk,jppic,Krhs) / rfact2/ (tr(ji,jj,jk,jppic,Kbb) + rtrn)
+        tr(ji,jj,jk,jpnpi,Krhs) = tr(ji,jj,jk,jpnpi,Krhs) + zproptot * texcretp
+        tr(ji,jj,jk,jpppi,Krhs) = tr(ji,jj,jk,jpppi,Krhs) + zpropo4p(ji,jj,jk) * texcretp   &
+        &                     + zprodopp(ji,jj,jk) * texcretp
+        tr(ji,jj,jk,jppfe,Krhs) = tr(ji,jj,jk,jppfe,Krhs) + zprofep(ji,jj,jk) * texcretp
+        tr(ji,jj,jk,jpdia,Krhs) = tr(ji,jj,jk,jpdia,Krhs) + zprorcad(ji,jj,jk) * texcretd   &
+           &                  - zpsino3 * zpronewd(ji,jj,jk) - zpsinh4 * zproregd(ji,jj,jk)   &
+           &                  - zrespd(ji,jj,jk) 
+        zcroissd(ji,jj,jk) = tr(ji,jj,jk,jpdia,Krhs) / rfact2 / (tr(ji,jj,jk,jpdia,Kbb) + rtrn)
+        tr(ji,jj,jk,jpndi,Krhs) = tr(ji,jj,jk,jpndi,Krhs) + zprodtot * texcretd
+        tr(ji,jj,jk,jppdi,Krhs) = tr(ji,jj,jk,jppdi,Krhs) + zpropo4d(ji,jj,jk) * texcretd   &
+        &                     + zprodopd(ji,jj,jk) * texcretd
+        tr(ji,jj,jk,jpdfe,Krhs) = tr(ji,jj,jk,jpdfe,Krhs) + zprofed(ji,jj,jk) * texcretd
+        tr(ji,jj,jk,jpdsi,Krhs) = tr(ji,jj,jk,jpdsi,Krhs) + zprorcad(ji,jj,jk) * zysopt(ji,jj,jk) * texcretd
+        tr(ji,jj,jk,jpdoc,Krhs) = tr(ji,jj,jk,jpdoc,Krhs) + excretd * zprorcad(ji,jj,jk) + excretn * zprorcan(ji,jj,jk)  &
+        &                     + excretp * zprorcap(ji,jj,jk)
+        tr(ji,jj,jk,jpdon,Krhs) = tr(ji,jj,jk,jpdon,Krhs) + excretd * zprodtot + excretn * zprontot   &
+        &                     + excretp * zproptot
+        tr(ji,jj,jk,jpdop,Krhs) = tr(ji,jj,jk,jpdop,Krhs) + excretd * zpropo4d(ji,jj,jk) + excretn * zpropo4n(ji,jj,jk)   &
+        &    - texcretn * zprodopn(ji,jj,jk) - texcretd * zprodopd(ji,jj,jk) + excretp * zpropo4p(ji,jj,jk)     &
+        &    - texcretp * zprodopp(ji,jj,jk)
+        tr(ji,jj,jk,jpoxy,Krhs) = tr(ji,jj,jk,jpoxy,Krhs) + o2ut * ( zproregn(ji,jj,jk) + zproregd(ji,jj,jk)   &
+           &                + zproregp(ji,jj,jk) ) + ( o2ut + o2nit ) * ( zpronewn(ji,jj,jk)           &
+           &                + zpronewd(ji,jj,jk) + zpronewp(ji,jj,jk) )   &
+           &                - o2ut * ( zrespn(ji,jj,jk) + zrespp(ji,jj,jk) + zrespd(ji,jj,jk) )
+        zfeup = texcretn * zprofen(ji,jj,jk) + texcretd * zprofed(ji,jj,jk) + texcretp * zprofep(ji,jj,jk)
+        tr(ji,jj,jk,jpfer,Krhs) = tr(ji,jj,jk,jpfer,Krhs) - zfeup
+        tr(ji,jj,jk,jpsil,Krhs) = tr(ji,jj,jk,jpsil,Krhs) - texcretd * zprorcad(ji,jj,jk) * zysopt(ji,jj,jk)
+        tr(ji,jj,jk,jpdic,Krhs) = tr(ji,jj,jk,jpdic,Krhs) - zprorcan(ji,jj,jk) - zprorcad(ji,jj,jk) - zprorcap(ji,jj,jk)  &
+        &                     + zpsino3 * zpronewn(ji,jj,jk) + zpsinh4 * zproregn(ji,jj,jk)   &
+        &                     + zpsino3 * zpronewp(ji,jj,jk) + zpsinh4 * zproregp(ji,jj,jk)   &
+        &                     + zpsino3 * zpronewd(ji,jj,jk) + zpsinh4 * zproregd(ji,jj,jk)  &
+        &                     + zrespn(ji,jj,jk) + zrespd(ji,jj,jk) + zrespp(ji,jj,jk) 
+        tr(ji,jj,jk,jptal,Krhs) = tr(ji,jj,jk,jptal,Krhs) + rno3 * ( zpronewn(ji,jj,jk) + zpronewd(ji,jj,jk)  &
+        &                     + zpronewp(ji,jj,jk) ) - rno3 * ( zproregn(ji,jj,jk) + zproregd(ji,jj,jk)     &
+        &                     + zproregp(ji,jj,jk) ) 
+      END_3D
      !
      IF( ln_ligand ) THEN
-         zpligprod1(:,:,:) = 0._wp    ;    zpligprod2(:,:,:) = 0._wp
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-              DO ji =1 ,jpi
-                 zdocprod = excretd * zprorcad(ji,jj,jk) + excretn * zprorcan(ji,jj,jk) + excretp * zprorcap(ji,jj,jk)
-                 zfeup    = texcretn * zprofen(ji,jj,jk) + texcretd * zprofed(ji,jj,jk) + texcretp * zprofep(ji,jj,jk)
-                 tra(ji,jj,jk,jplgw) = tra(ji,jj,jk,jplgw) + zdocprod * ldocp - zfeup * plig(ji,jj,jk) * lthet
-                 zpligprod1(ji,jj,jk) = zdocprod * ldocp
-                 zpligprod2(ji,jj,jk) = zfeup * plig(ji,jj,jk) * lthet
-              END DO
-           END DO
-        END DO
+         zpligprod1(:,:,:) = 0._wp    ;    zpligprod2(:,:,:) = 0._wp             
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+           zdocprod = excretd * zprorcad(ji,jj,jk) + excretn * zprorcan(ji,jj,jk) + excretp * zprorcap(ji,jj,jk)
+           zfeup    = texcretn * zprofen(ji,jj,jk) + texcretd * zprofed(ji,jj,jk) + texcretp * zprofep(ji,jj,jk)
+           tr(ji,jj,jk,jplgw,Krhs) = tr(ji,jj,jk,jplgw,Krhs) + zdocprod * ldocp - zfeup * plig(ji,jj,jk) * lthet
+           zpligprod1(ji,jj,jk) = zdocprod * ldocp
+           zpligprod2(ji,jj,jk) = zfeup * plig(ji,jj,jk) * lthet
+         END_3D
      ENDIF
 
@@ -465,97 +426,41 @@
       & tpp = glob_sum( 'p5zprod', ( zprorcan(:,:,:) + zprorcad(:,:,:) + zprorcap(:,:,:) ) * cvol(:,:,:) )
 
-    IF( lk_iomput ) THEN
-       IF( knt == nrdttrc ) THEN
-          ALLOCATE( zw2d(jpi,jpj), zw3d(jpi,jpj,jpk) )
-          zfact = 1.e+3 * rfact2r  !  conversion from mol/l/kt to  mol/m3/s
-          !
-          IF( iom_use( "PPPHYN" ) .OR. iom_use( "PPPHYD" ) .OR. iom_use( "PPPHYP" ) )  THEN
-              zw3d(:,:,:) = zprorcan(:,:,:) * zfact * tmask(:,:,:)  ! primary production by nanophyto
-              CALL iom_put( "PPPHYN"  , zw3d )
-              !
-              zw3d(:,:,:) = zprorcap(:,:,:) * zfact * tmask(:,:,:)  ! primary production by picophyto
-              CALL iom_put( "PPPHYP"  , zw3d )
-              !
-              zw3d(:,:,:) = zprorcad(:,:,:) * zfact * tmask(:,:,:)  ! primary production by diatomes
-              CALL iom_put( "PPPHYD"  , zw3d )
-          ENDIF
-          IF( iom_use( "PPNEWN" ) .OR. iom_use( "PPNEWD" ) .OR. iom_use( "PPNEWP" ) )  THEN
-              zw3d(:,:,:) = zpronewn(:,:,:) * zfact * tmask(:,:,:)  ! new primary production by nanophyto
-              CALL iom_put( "PPNEWN"  , zw3d )
-              !
-              zw3d(:,:,:) = zpronewp(:,:,:) * zfact * tmask(:,:,:)  ! new primary production by picophyto
-              CALL iom_put( "PPNEWP"  , zw3d )
-              !
-              zw3d(:,:,:) = zpronewd(:,:,:) * zfact * tmask(:,:,:)  ! new primary production by diatomes
-              CALL iom_put( "PPNEWD"  , zw3d )
-          ENDIF
-          IF( iom_use( "PBSi" ) )  THEN
-              zw3d(:,:,:) = zprorcad(:,:,:) * zfact * tmask(:,:,:) * zysopt(:,:,:) ! biogenic silica production
-              CALL iom_put( "PBSi"  , zw3d )
-          ENDIF
-          IF( iom_use( "PFeN" ) .OR. iom_use( "PFeD" ) .OR. iom_use( "PFeP" ) )  THEN
-              zw3d(:,:,:) = zprofen(:,:,:) * zfact * tmask(:,:,:)  ! biogenic iron production by nanophyto
-              CALL iom_put( "PFeN"  , zw3d )
-              !
-              zw3d(:,:,:) = zprofep(:,:,:) * zfact * tmask(:,:,:)  ! biogenic iron production by picophyto
-              CALL iom_put( "PFeP"  , zw3d )
-              !
-              zw3d(:,:,:) = zprofed(:,:,:) * zfact * tmask(:,:,:)  ! biogenic iron production by  diatomes
-              CALL iom_put( "PFeD"  , zw3d )
-          ENDIF
-          IF( iom_use( "LPRODP" ) )  THEN
-              zw3d(:,:,:) = zpligprod1(:,:,:) * 1e9 * zfact * tmask(:,:,:)
-              CALL iom_put( "LPRODP"  , zw3d )
-          ENDIF
-          IF( iom_use( "LDETP" ) )  THEN
-              zw3d(:,:,:) = zpligprod2(:,:,:) * 1e9 * zfact * tmask(:,:,:)
-              CALL iom_put( "LDETP"  , zw3d )
-          ENDIF
-          IF( iom_use( "Mumax" ) )  THEN
-              zw3d(:,:,:) = zprmaxn(:,:,:) * tmask(:,:,:)   ! Maximum growth rate
-              CALL iom_put( "Mumax"  , zw3d )
-          ENDIF
-          IF( iom_use( "MuN" ) .OR. iom_use( "MuD" ) .OR. iom_use( "MuP" ) )  THEN
-              zw3d(:,:,:) = zprbio(:,:,:) * xlimphy(:,:,:) * tmask(:,:,:)  ! Realized growth rate for nanophyto
-              CALL iom_put( "MuN"  , zw3d )
-              !
-              zw3d(:,:,:) = zprpic(:,:,:) * xlimpic(:,:,:) * tmask(:,:,:)  ! Realized growth rate for picophyto
-              CALL iom_put( "MuP"  , zw3d )
-              !
-              zw3d(:,:,:) =  zprdia(:,:,:) * xlimdia(:,:,:) * tmask(:,:,:)  ! Realized growth rate for diatoms
-              CALL iom_put( "MuD"  , zw3d )
-          ENDIF
-          IF( iom_use( "LNlight" ) .OR. iom_use( "LDlight" ) .OR. iom_use( "LPlight" ) )  THEN
-              zw3d(:,:,:) = zprbio (:,:,:) / (zprmaxn(:,:,:) + rtrn) * tmask(:,:,:) ! light limitation term
-              CALL iom_put( "LNlight"  , zw3d )
-              !
-              zw3d(:,:,:) = zprpic (:,:,:) / (zprmaxp(:,:,:) + rtrn) * tmask(:,:,:) ! light limitation term
-              CALL iom_put( "LPlight"  , zw3d )
-              !
-              zw3d(:,:,:) =  zprdia (:,:,:) / (zprmaxd(:,:,:) + rtrn) * tmask(:,:,:)  ! light limitation term
-              CALL iom_put( "LDlight"  , zw3d )
-          ENDIF
-          IF( iom_use( "MunetN" ) .OR. iom_use( "MunetD" ) .OR. iom_use( "MunetP" ) )  THEN
-              zw3d(:,:,:) = zcroissn(:,:,:) * tmask(:,:,:) ! ! Realized growth rate for nanophyto
-              CALL iom_put( "MunetN"  , zw3d )
-              !
-              zw3d(:,:,:) = zcroissp(:,:,:) * tmask(:,:,:) ! ! Realized growth rate for picophyto
-              CALL iom_put( "MunetP"  , zw3d )
-              !
-              zw3d(:,:,:) = zcroissd(:,:,:) * tmask(:,:,:) ! ! Realized growth rate for diatomes
-              CALL iom_put( "MunetD"  , zw3d )
-              !
-          ENDIF
-
-          IF( iom_use( "tintpp" ) )  CALL iom_put( "tintpp" , tpp * zfact )  !  global total integrated primary production molC/s
-          !
-          DEALLOCATE( zw2d, zw3d )
+    IF( lk_iomput .AND.  knt == nrdttrc ) THEN
+       zfact = 1.e+3 * rfact2r  !  conversion from mol/l/kt to  mol/m3/s
+       !
+       CALL iom_put( "PPPHYP"  , zprorcap(:,:,:) * zfact * tmask(:,:,:)   ) ! primary production by picophyto
+       CALL iom_put( "PPPHYN"  , zprorcan(:,:,:) * zfact * tmask(:,:,:) )  ! primary production by nanophyto
+       CALL iom_put( "PPPHYD"  , zprorcad(:,:,:) * zfact * tmask(:,:,:)   ) ! primary production by diatomes
+       CALL iom_put( "PPNEWN"  , zpronewp(:,:,:) * zfact * tmask(:,:,:)    ) ! new primary production by picophyto
+       CALL iom_put( "PPNEWN"  , zpronewn(:,:,:) * zfact * tmask(:,:,:)    ) ! new primary production by nanophyto
+       CALL iom_put( "PPNEWD"  , zpronewd(:,:,:) * zfact * tmask(:,:,:)   ) ! new primary production by diatomes
+       CALL iom_put( "PBSi"    , zprorcad(:,:,:) * zfact * tmask(:,:,:) * zysopt(:,:,:)  ) ! biogenic silica production
+       CALL iom_put( "PFeP"    , zprofep(:,:,:) * zfact * tmask(:,:,:)  ) ! biogenic iron production by picophyto
+       CALL iom_put( "PFeN"    , zprofen(:,:,:) * zfact * tmask(:,:,:)  ) ! biogenic iron production by nanophyto
+       CALL iom_put( "PFeD"    , zprofed(:,:,:) * zfact * tmask(:,:,:)  ) ! biogenic iron production by  diatomes
+       IF( ln_ligand ) THEN
+         CALL iom_put( "LPRODP"  , zpligprod1(:,:,:) * 1e9 * zfact * tmask(:,:,:) )
+         CALL iom_put( "LDETP"   , zpligprod2(:,:,:) * 1e9 * zfact * tmask(:,:,:) )
        ENDIF
+       CALL iom_put( "Mumax"   , zprmaxn(:,:,:) * tmask(:,:,:)  ) ! Maximum growth rate
+       CALL iom_put( "MuP"     , zprpic(:,:,:) * xlimpic(:,:,:) * tmask(:,:,:) ) ! Realized growth rate for picophyto
+       CALL iom_put( "MuN"     , zprbio(:,:,:) * xlimphy(:,:,:) * tmask(:,:,:) ) ! Realized growth rate for nanophyto
+       CALL iom_put( "MuD"     , zprdia(:,:,:) * xlimdia(:,:,:) * tmask(:,:,:) ) ! Realized growth rate for diatoms
+       CALL iom_put( "LPlight" , zprpic(:,:,:) / (zprmaxp(:,:,:) + rtrn) * tmask(:,:,:)  )  ! light limitation term
+       CALL iom_put( "LNlight" , zprbio(:,:,:) / (zprmaxn(:,:,:) + rtrn) * tmask(:,:,:)  )  ! light limitation term
+       CALL iom_put( "LDlight" , zprdia(:,:,:) / (zprmaxd(:,:,:) + rtrn) * tmask(:,:,:)   )
+       CALL iom_put( "MunetP"  , zcroissp(:,:,:) * tmask(:,:,:) ) ! Realized growth rate for picophyto
+       CALL iom_put( "MunetN"  , zcroissn(:,:,:) * tmask(:,:,:) ) ! Realized growth rate for nanophyto
+       CALL iom_put( "MunetD"  , zcroissd(:,:,:) * tmask(:,:,:) ) ! Realized growth rate for diatoms
+       CALL iom_put( "TPP"     , ( zprorcap(:,:,:) + zprorcan(:,:,:) + zprorcad(:,:,:) ) * zfact * tmask(:,:,:)  )  ! total primary production
+       CALL iom_put( "TPNEW"   , ( zpronewp(:,:,:) + zpronewn(:,:,:) + zpronewd(:,:,:) ) * zfact * tmask(:,:,:)  ) ! total new production
+       CALL iom_put( "TPBFE"   , ( zprofep (:,:,:) + zprofen (:,:,:) + zprofed (:,:,:) ) * zfact * tmask(:,:,:)  )  ! total biogenic iron production
+       CALL iom_put( "tintpp"  , tpp * zfact )  !  global total integrated primary production molC/s
      ENDIF
 
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('prod')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm)
       ENDIF
       !
@@ -582,11 +487,9 @@
       !!----------------------------------------------------------------------
 
-      REWIND( numnatp_ref )              ! Namelist nampisprod in reference namelist : Pisces phytoplankton production
       READ  ( numnatp_ref, namp5zprod, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namp5zprod in reference namelist', lwp )
-
-      REWIND( numnatp_cfg )              ! Namelist nampisprod in configuration namelist : Pisces phytoplankton production
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namp5zprod in reference namelist' )
+
       READ  ( numnatp_cfg, namp5zprod, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namp5zprod in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namp5zprod in configuration namelist' )
       IF(lwm) WRITE ( numonp, namp5zprod )
 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/oce_sed.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/oce_sed.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/oce_sed.F90	(revision 13463)
@@ -13,10 +13,13 @@
    USE dom_oce , ONLY :   glamt     =>   glamt          !: longitude of t-point (degre)
    USE dom_oce , ONLY :   gphit     =>   gphit          !: latitude  of t-point (degre)
-   USE dom_oce , ONLY :   e3t_n     =>   e3t_n          !: latitude  of t-point (degre)
+!!st 
+#if ! defined key_qco
+   USE dom_oce , ONLY :   e3t       =>   e3t            !: latitude  of t-point (degre)
+#endif
    USE dom_oce , ONLY :   e3t_1d    =>   e3t_1d         !: reference depth of t-points (m)
    USE dom_oce , ONLY :   gdepw_0   =>   gdepw_0        !: reference depth of t-points (m)
    USE dom_oce , ONLY :   mbkt      =>   mbkt           !: vertical index of the bottom last T- ocean level
    USE dom_oce , ONLY :   tmask     =>   tmask          !: land/ocean mask at t-points
-   USE dom_oce , ONLY :   rdt       =>   rdt            !: time step for the dynamics
+   USE dom_oce , ONLY :   rn_Dt     =>   rn_Dt          !: time step for the dynamics
    USE dom_oce , ONLY :   nyear     =>   nyear          !: Current year
    USE dom_oce , ONLY :   ndastp    =>   ndastp         !: time step date in year/month/day aammjj
@@ -26,10 +29,10 @@
    !                                !: that may have been run with different time steps.
 
-   USE oce     , ONLY :  tsn        =>   tsn             !: pot. temperature (celsius) and salinity (psu)
-   USE trc     , ONLY :  trb        =>   trb             !: pot. temperature (celsius) and salinity (psu)
+   USE oce     , ONLY :   ts        =>   ts              !: pot. temperature (celsius) and salinity (psu)
+   USE trc     , ONLY :   tr        =>   tr              !: pot. temperature (celsius) and salinity (psu)
 
    USE sms_pisces, ONLY : wsbio4    =>   wsbio4          !: sinking flux for POC
    USE sms_pisces, ONLY : wsbio3    =>   wsbio3          !: sinking flux for GOC
-   USE sms_pisces, ONLY : wsbio2    =>   wsbio2           !: sinking flux for calcite
+   USE sms_pisces, ONLY : wsbio2    =>   wsbio2          !: sinking flux for calcite
    USE sms_pisces, ONLY : wsbio     =>   wsbio           !: sinking flux for calcite
    USE sms_pisces, ONLY : ln_p5z    =>   ln_p5z          !: PISCES-QUOTA flag
@@ -49,8 +52,6 @@
    USE p4zche, ONLY     : sulfat    =>   sulfat          !: Chemical constants  
    USE p4zche, ONLY     : sio3eq    =>   sio3eq          !: Chemical constants  
-   USE p4zsbc, ONLY     : dust      =>   dust
-   USE trc       , ONLY : r2dttrc   =>   r2dttrc
+   USE p4zbc, ONLY     : dust      =>   dust
+   USE trc  , ONLY : rDt_trc   =>   rDt_trc
 
 END MODULE oce_sed
-
-
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedchem.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedchem.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedchem.F90	(revision 13463)
@@ -23,4 +23,6 @@
    REAL(wp), PARAMETER :: pp_rdel_ah_target = 1.E-4_wp
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !! * Module variables
    REAL(wp) :: &
@@ -136,26 +138,24 @@
          CALL sed_chem_cst
       ELSE
-         DO jj = 1,jpj
-            DO ji = 1, jpi
-               ikt = mbkt(ji,jj) 
-               IF ( tmask(ji,jj,ikt) == 1 ) THEN
-                  zchem_data(ji,jj,1) = ak13  (ji,jj,ikt)
-                  zchem_data(ji,jj,2) = ak23  (ji,jj,ikt)
-                  zchem_data(ji,jj,3) = akb3  (ji,jj,ikt)
-                  zchem_data(ji,jj,4) = akw3  (ji,jj,ikt)
-                  zchem_data(ji,jj,5) = aksp  (ji,jj,ikt)
-                  zchem_data(ji,jj,6) = borat (ji,jj,ikt)
-                  zchem_data(ji,jj,7) = ak1p3 (ji,jj,ikt)
-                  zchem_data(ji,jj,8) = ak2p3 (ji,jj,ikt)
-                  zchem_data(ji,jj,9) = ak3p3 (ji,jj,ikt)
-                  zchem_data(ji,jj,10)= aksi3 (ji,jj,ikt)
-                  zchem_data(ji,jj,11)= sio3eq(ji,jj,ikt)
-                  zchem_data(ji,jj,12)= aks3  (ji,jj,ikt)
-                  zchem_data(ji,jj,13)= akf3  (ji,jj,ikt)
-                  zchem_data(ji,jj,14)= sulfat(ji,jj,ikt)
-                  zchem_data(ji,jj,15)= fluorid(ji,jj,ikt)
-               ENDIF
-            ENDDO
-         ENDDO
+         DO_2D( 1, 1, 1, 1 )
+            ikt = mbkt(ji,jj) 
+            IF ( tmask(ji,jj,ikt) == 1 ) THEN
+               zchem_data(ji,jj,1) = ak13  (ji,jj,ikt)
+               zchem_data(ji,jj,2) = ak23  (ji,jj,ikt)
+               zchem_data(ji,jj,3) = akb3  (ji,jj,ikt)
+               zchem_data(ji,jj,4) = akw3  (ji,jj,ikt)
+               zchem_data(ji,jj,5) = aksp  (ji,jj,ikt)
+               zchem_data(ji,jj,6) = borat (ji,jj,ikt)
+               zchem_data(ji,jj,7) = ak1p3 (ji,jj,ikt)
+               zchem_data(ji,jj,8) = ak2p3 (ji,jj,ikt)
+               zchem_data(ji,jj,9) = ak3p3 (ji,jj,ikt)
+               zchem_data(ji,jj,10)= aksi3 (ji,jj,ikt)
+               zchem_data(ji,jj,11)= sio3eq(ji,jj,ikt)
+               zchem_data(ji,jj,12)= aks3  (ji,jj,ikt)
+               zchem_data(ji,jj,13)= akf3  (ji,jj,ikt)
+               zchem_data(ji,jj,14)= sulfat(ji,jj,ikt)
+               zchem_data(ji,jj,15)= fluorid(ji,jj,ikt)
+            ENDIF
+         END_2D
 
          CALL pack_arr ( jpoce, ak1s  (1:jpoce), zchem_data(1:jpi,1:jpj,1) , iarroce(1:jpoce) )
@@ -577,5 +577,5 @@
          saltprac(:) = salt(:) * 35.0 / 35.16504
       ELSE
-         saltprac(:) = temp(:)
+         saltprac(:) = salt(:)
       ENDIF
 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/seddta.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/seddta.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/seddta.F90	(revision 13463)
@@ -22,4 +22,7 @@
    REAL(wp) ::  conv2    ! [kg/m2/month]-->[g/cm2/s] ( 1 month has 30 days )
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !! $Id$
 CONTAINS
@@ -29,5 +32,5 @@
    !!---------------------------------------------------------------------------
 
-   SUBROUTINE sed_dta( kt )
+   SUBROUTINE sed_dta( kt, Kbb, Kmm )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE sed_dta  ***
@@ -43,5 +46,6 @@
 
       !! Arguments
-      INTEGER, INTENT(in) ::  kt    ! time-step
+      INTEGER, INTENT(in) ::  kt         ! time-step
+      INTEGER, INTENT(in) ::  Kbb, Kmm   ! time level indices
 
       !! * Local declarations
@@ -72,5 +76,5 @@
       IF( kt == nitsed000 ) THEN
          IF (lwp) WRITE(numsed,*) ' sed_dta : Sediment fields'
-         dtsed = r2dttrc
+         dtsed = rDt_trc
          rsecday = 60.* 60. * 24.
 !         conv2   = 1.0e+3 / ( 1.0e+4 * rsecday * 30. )
@@ -92,49 +96,43 @@
       !    -----------------------------------------------------------
       IF (ln_sediment_offline) THEN
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ikt = mbkt(ji,jj)
-               zwsbio4(ji,jj) = wsbio2 / rday
-               zwsbio3(ji,jj) = wsbio  / rday
-            END DO
-         END DO
+         DO_2D( 1, 1, 1, 1 )
+            ikt = mbkt(ji,jj)
+            zwsbio4(ji,jj) = wsbio2 / rday
+            zwsbio3(ji,jj) = wsbio  / rday
+         END_2D
       ELSE
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ikt = mbkt(ji,jj)
-               zdep = e3t_n(ji,jj,ikt) / r2dttrc
-               zwsbio4(ji,jj) = MIN( 0.99 * zdep, wsbio4(ji,jj,ikt) / rday )
-               zwsbio3(ji,jj) = MIN( 0.99 * zdep, wsbio3(ji,jj,ikt) / rday )
-            END DO
-         END DO
+         DO_2D( 1, 1, 1, 1 )
+            ikt = mbkt(ji,jj)
+            zdep = e3t(ji,jj,ikt,Kmm) / rDt_trc
+            zwsbio4(ji,jj) = MIN( 0.99 * zdep, wsbio4(ji,jj,ikt) / rday )
+            zwsbio3(ji,jj) = MIN( 0.99 * zdep, wsbio3(ji,jj,ikt) / rday )
+         END_2D
       ENDIF
 
       trc_data(:,:,:) = 0.
-      DO jj = 1,jpj
-         DO ji = 1, jpi
-            ikt = mbkt(ji,jj)
-            IF ( tmask(ji,jj,ikt) == 1 ) THEN
-               trc_data(ji,jj,1)   = trb(ji,jj,ikt,jpsil)
-               trc_data(ji,jj,2)   = trb(ji,jj,ikt,jpoxy)
-               trc_data(ji,jj,3)   = trb(ji,jj,ikt,jpdic)
-               trc_data(ji,jj,4)   = trb(ji,jj,ikt,jpno3) / 7.625
-               trc_data(ji,jj,5)   = trb(ji,jj,ikt,jppo4) / 122.
-               trc_data(ji,jj,6)   = trb(ji,jj,ikt,jptal)
-               trc_data(ji,jj,7)   = trb(ji,jj,ikt,jpnh4) / 7.625
-               trc_data(ji,jj,8)   = 0.0
-               trc_data(ji,jj,9)   = 28.0E-3
-               trc_data(ji,jj,10)  = trb(ji,jj,ikt,jpfer)
-               trc_data(ji,jj,11 ) = MIN(trb(ji,jj,ikt,jpgsi), 1E-4) * zwsbio4(ji,jj) * 1E3
-               trc_data(ji,jj,12 ) = MIN(trb(ji,jj,ikt,jppoc), 1E-4) * zwsbio3(ji,jj) * 1E3
-               trc_data(ji,jj,13 ) = MIN(trb(ji,jj,ikt,jpgoc), 1E-4) * zwsbio4(ji,jj) * 1E3
-               trc_data(ji,jj,14)  = MIN(trb(ji,jj,ikt,jpcal), 1E-4) * zwsbio4(ji,jj) * 1E3
-               trc_data(ji,jj,15)  = tsn(ji,jj,ikt,jp_tem)
-               trc_data(ji,jj,16)  = tsn(ji,jj,ikt,jp_sal)
-               trc_data(ji,jj,17 ) = ( trb(ji,jj,ikt,jpsfe) * zwsbio3(ji,jj) + trb(ji,jj,ikt,jpbfe)  &
-               &                     * zwsbio4(ji,jj)  ) * 1E3 / ( trc_data(ji,jj,12 ) + trc_data(ji,jj,13 ) + rtrn )
-               trc_data(ji,jj,17 ) = MIN(1E-3, trc_data(ji,jj,17 ) )
-            ENDIF
-         ENDDO
-      ENDDO
+      DO_2D( 1, 1, 1, 1 )
+         ikt = mbkt(ji,jj)
+         IF ( tmask(ji,jj,ikt) == 1 ) THEN
+            trc_data(ji,jj,1)   = tr(ji,jj,ikt,jpsil,Kbb)
+            trc_data(ji,jj,2)   = tr(ji,jj,ikt,jpoxy,Kbb)
+            trc_data(ji,jj,3)   = tr(ji,jj,ikt,jpdic,Kbb)
+            trc_data(ji,jj,4)   = tr(ji,jj,ikt,jpno3,Kbb) / 7.625
+            trc_data(ji,jj,5)   = tr(ji,jj,ikt,jppo4,Kbb) / 122.
+            trc_data(ji,jj,6)   = tr(ji,jj,ikt,jptal,Kbb)
+            trc_data(ji,jj,7)   = tr(ji,jj,ikt,jpnh4,Kbb) / 7.625
+            trc_data(ji,jj,8)   = 0.0
+            trc_data(ji,jj,9)   = 28.0E-3
+            trc_data(ji,jj,10)  = tr(ji,jj,ikt,jpfer,Kbb)
+            trc_data(ji,jj,11 ) = MIN(tr(ji,jj,ikt,jpgsi,Kbb), 1E-4) * zwsbio4(ji,jj) * 1E3
+            trc_data(ji,jj,12 ) = MIN(tr(ji,jj,ikt,jppoc,Kbb), 1E-4) * zwsbio3(ji,jj) * 1E3
+            trc_data(ji,jj,13 ) = MIN(tr(ji,jj,ikt,jpgoc,Kbb), 1E-4) * zwsbio4(ji,jj) * 1E3
+            trc_data(ji,jj,14)  = MIN(tr(ji,jj,ikt,jpcal,Kbb), 1E-4) * zwsbio4(ji,jj) * 1E3
+            trc_data(ji,jj,15)  = ts(ji,jj,ikt,jp_tem,Kmm)
+            trc_data(ji,jj,16)  = ts(ji,jj,ikt,jp_sal,Kmm)
+            trc_data(ji,jj,17 ) = ( tr(ji,jj,ikt,jpsfe,Kbb) * zwsbio3(ji,jj) + tr(ji,jj,ikt,jpbfe,Kbb)  &
+            &                     * zwsbio4(ji,jj)  ) * 1E3 / ( trc_data(ji,jj,12 ) + trc_data(ji,jj,13 ) + rtrn )
+            trc_data(ji,jj,17 ) = MIN(1E-3, trc_data(ji,jj,17 ) )
+         ENDIF
+      END_2D
 
       ! Pore water initial concentration [mol/l] in  k=1
@@ -167,5 +165,5 @@
       CALL pack_arr ( jpoce,  rainrm_dta(1:jpoce,jscal), trc_data(1:jpi,1:jpj,14), iarroce(1:jpoce) )
       rainrm_dta(1:jpoce,jscal) = rainrm_dta(1:jpoce,jscal) * 1e-4
-      ! vector temperature [°C] and salinity 
+      ! vector temperature [�C] and salinity 
       CALL pack_arr ( jpoce,  temp(1:jpoce), trc_data(1:jpi,1:jpj,15), iarroce(1:jpoce) )
       CALL pack_arr ( jpoce,  salt(1:jpoce), trc_data(1:jpi,1:jpj,16), iarroce(1:jpoce) )
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedini.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedini.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedini.F90	(revision 13463)
@@ -13,5 +13,4 @@
    USE sedarr
    USE sedadv
-   USE trc_oce, ONLY : nn_dttrc
    USE trcdmp_sed
    USE trcdta
@@ -23,4 +22,6 @@
    PRIVATE
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !! Module variables
    REAL(wp)    ::  &
@@ -134,11 +135,9 @@
       ! Determination of sediments number of points and allocate global variables
       epkbot(:,:) = 0.
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            ikt = mbkt(ji,jj) 
-            IF( tmask(ji,jj,ikt) == 1 ) epkbot(ji,jj) = e3t_1d(ikt)
-            gdepbot(ji,jj) = gdepw_0(ji,jj,ikt)
-         ENDDO
-      ENDDO
+      DO_2D( 1, 1, 1, 1 )
+         ikt = mbkt(ji,jj) 
+         IF( tmask(ji,jj,ikt) == 1 ) epkbot(ji,jj) = e3t_1d(ikt)
+         gdepbot(ji,jj) = gdepw_0(ji,jj,ikt)
+      END_2D
 
       ! computation of total number of ocean points
@@ -248,12 +247,10 @@
       ! Computation of 1D array of sediments points
       indoce = 0
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF (  epkbot(ji,jj) > 0. ) THEN
-               indoce          = indoce + 1
-               iarroce(indoce) = (jj - 1) * jpi + ji
-            ENDIF
-         END DO
-      END DO
+      DO_2D( 1, 1, 1, 1 )
+         IF (  epkbot(ji,jj) > 0. ) THEN
+            indoce          = indoce + 1
+            iarroce(indoce) = (jj - 1) * jpi + ji
+         ENDIF
+      END_2D
 
       IF ( indoce .EQ. 0 ) THEN
@@ -406,6 +403,6 @@
       !!----------------------------------------------------------------------
 
-      INTEGER ::   numnamsed_ref = -1           !! Logical units for namelist sediment
-      INTEGER ::   numnamsed_cfg = -1           !! Logical units for namelist sediment
+      CHARACTER(:), ALLOCATABLE ::   numnamsed_ref           !! Character buffer for reference namelist sediment
+      CHARACTER(:), ALLOCATABLE ::   numnamsed_cfg           !! Character buffer for configuration namelist sediment
       INTEGER :: ios                 ! Local integer output status for namelist read
       CHARACTER(LEN=20)   ::   clname
@@ -452,17 +449,15 @@
       IF(lwp) WRITE(numsed,*) ' sed_init_nam : read SEDIMENT namelist'
       IF(lwp) WRITE(numsed,*) ' ~~~~~~~~~~~~~~'
-      CALL ctl_opn( numnamsed_ref, TRIM( clname )//'_ref', 'OLD'    , 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
-      CALL ctl_opn( numnamsed_cfg, TRIM( clname )//'_cfg', 'OLD'    , 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+      CALL load_nml( numnamsed_ref, TRIM( clname )//'_ref', numout, lwm )
+      CALL load_nml( numnamsed_cfg, TRIM( clname )//'_cfg', numout, lwm )
 
       nitsed000 = nittrc000
       nitsedend = nitend
       ! Namelist nam_run
-      REWIND( numnamsed_ref )              ! Namelist nam_run in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_run, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_run in reference namelist', lwp )
-
-      REWIND( numnamsed_cfg )              ! Namelist nam_run in reference namelist : Pisces variables
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_run in reference namelist' )
+
       READ  ( numnamsed_cfg, nam_run, IOSTAT = ios, ERR = 902)
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_run in configuration namelist', lwp )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_run in configuration namelist' )
 
       IF (lwp) THEN
@@ -474,11 +469,9 @@
       IF ( ln_p5z .AND. ln_sed_2way ) CALL ctl_stop( '2 ways coupling with sediment cannot be activated with PISCES-QUOTA' )
 
-      REWIND( numnamsed_ref )              ! Namelist nam_geom in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_geom, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_geom in reference namelist', lwp )
-
-      REWIND( numnamsed_cfg )              ! Namelist nam_geom in reference namelist : Pisces variables
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_geom in reference namelist' )
+
       READ  ( numnamsed_cfg, nam_geom, IOSTAT = ios, ERR = 904)
-904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_geom in configuration namelist', lwp )
+904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_geom in configuration namelist' )
 
       IF (lwp) THEN 
@@ -495,13 +488,11 @@
 
       jpksedm1  = jpksed - 1
-      dtsed = r2dttrc
-
-      REWIND( numnamsed_ref )              ! Namelist nam_trased in reference namelist : Pisces variables
+      dtsed = rDt_trc
+
       READ  ( numnamsed_ref, nam_trased, IOSTAT = ios, ERR = 905)
-905   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_trased in reference namelist', lwp )
-
-      REWIND( numnamsed_cfg )              ! Namelist nam_trased in reference namelist : Pisces variables
+905   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_trased in reference namelist' )
+
       READ  ( numnamsed_cfg, nam_trased, IOSTAT = ios, ERR = 906)
-906   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_trased in configuration namelist', lwp )
+906   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_trased in configuration namelist' )
 
       DO jn = 1, jpsol
@@ -530,11 +521,9 @@
       ENDIF
 
-      REWIND( numnamsed_ref )              ! Namelist nam_diased in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_diased, IOSTAT = ios, ERR = 907)
-907   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diased in reference namelist', lwp )
-
-      REWIND( numnamsed_cfg )              ! Namelist nam_diased in reference namelist : Pisces variables
+907   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diased in reference namelist' )
+
       READ  ( numnamsed_cfg, nam_diased, IOSTAT = ios, ERR = 908)
-908   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diased in configuration namelist', lwp )
+908   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_diased in configuration namelist' )
       
       DO jn = 1, jpdia3dsed
@@ -572,11 +561,9 @@
       ! Inorganic chemistry parameters
       !----------------------------------
-      REWIND( numnamsed_ref )              ! Namelist nam_inorg in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_inorg, IOSTAT = ios, ERR = 909)
-909   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_inorg in reference namelist', lwp )
-
-      REWIND( numnamsed_cfg )              ! Namelist nam_inorg in reference namelist : Pisces variables
+909   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_inorg in reference namelist' )
+
       READ  ( numnamsed_cfg, nam_inorg, IOSTAT = ios, ERR = 910)
-910   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_inorg in configuration namelist', lwp )
+910   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_inorg in configuration namelist' )
 
       IF (lwp) THEN
@@ -598,11 +585,9 @@
       ! Additional parameter linked to POC/O2/No3/Po4
       !----------------------------------------------
-      REWIND( numnamsed_ref )              ! Namelist nam_poc in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_poc, IOSTAT = ios, ERR = 911)
-911   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_poc in reference namelist', lwp )
-
-      REWIND( numnamsed_cfg )              ! Namelist nam_poc in reference namelist : Pisces variables
+911   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_poc in reference namelist' )
+
       READ  ( numnamsed_cfg, nam_poc, IOSTAT = ios, ERR = 912)
-912   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_poc in configuration namelist', lwp )
+912   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_poc in configuration namelist' )
 
       IF (lwp) THEN
@@ -650,11 +635,9 @@
       ! Bioturbation parameter
       !------------------------
-      REWIND( numnamsed_ref )              ! Namelist nam_btb in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_btb, IOSTAT = ios, ERR = 913)
-913   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_btb in reference namelist', lwp )
-
-      REWIND( numnamsed_cfg )              ! Namelist nam_btb in reference namelist : Pisces variables
+913   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_btb in reference namelist' )
+
       READ  ( numnamsed_cfg, nam_btb, IOSTAT = ios, ERR = 914)
-914   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_btb in configuration namelist', lwp )
+914   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_btb in configuration namelist' )
 
       IF (lwp) THEN
@@ -671,11 +654,9 @@
       ! Initial value (t=0) for sediment pore water and solid components
       !----------------------------------------------------------------
-      REWIND( numnamsed_ref )              ! Namelist nam_rst in reference namelist : Pisces variables
       READ  ( numnamsed_ref, nam_rst, IOSTAT = ios, ERR = 915)
-915   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_rst in reference namelist', lwp )
-
-      REWIND( numnamsed_cfg )              ! Namelist nam_rst in reference namelist : Pisces variables
+915   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_rst in reference namelist' )
+
       READ  ( numnamsed_cfg, nam_rst, IOSTAT = ios, ERR = 916)
-916   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_rst in configuration namelist', lwp )
+916   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_rst in configuration namelist' )
 
       IF (lwp) THEN
@@ -684,8 +665,6 @@
          WRITE(numsed,*) ' '
       ENDIF
-      nn_dtsed = nn_dttrc
-
-      CLOSE( numnamsed_cfg )
-      CLOSE( numnamsed_ref )
+      nn_dtsed = 1
+
 
    END SUBROUTINE sed_init_nam
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedinitrc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedinitrc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedinitrc.F90	(revision 13463)
@@ -33,5 +33,5 @@
 
 
-   SUBROUTINE sed_initrc
+   SUBROUTINE sed_initrc( Kbb, Kmm )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE sed_init  ***
@@ -50,4 +50,5 @@
       !!        !  06-07  (C. Ethe)  Re-organization
       !!----------------------------------------------------------------------
+      INTEGER, INTENT(in)  ::  Kbb, Kmm      ! time level indices
       INTEGER :: ji, jj, ikt
       !!----------------------------------------------------------------------
@@ -65,5 +66,5 @@
       ! ( only clay or reading restart file )
       !---------------------------------------
-      CALL sed_init_data
+      CALL sed_init_data( Kbb, Kmm )
 
 
@@ -74,5 +75,5 @@
 
 
-   SUBROUTINE sed_init_data
+   SUBROUTINE sed_init_data( Kbb, Kmm )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE sed_init_data  ***
@@ -85,4 +86,5 @@
       !!        !  06-07  (C. Ethe)  original
       !!----------------------------------------------------------------------
+      INTEGER, INTENT(in)  ::  Kbb, Kmm      ! time level indices
  
       ! local variables
@@ -128,5 +130,5 @@
 
       ! Load initial Pisces Data for bot. wat. Chem and fluxes
-      CALL sed_dta ( nitsed000 ) 
+      CALL sed_dta ( nitsed000, Kbb, Kmm ) 
 
       ! Initialization of chemical constants
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedinorg.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedinorg.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedinorg.F90	(revision 13463)
@@ -89,4 +89,5 @@
             zsolcpcl = zsolcpcl + solcp(ji,jk,jsclay) * dz(jk)
          END DO
+         zsolcpsi = MAX( zsolcpsi, rtrn )
          zsieq(ji) = sieqs(ji) * MAX(0.25, 1.0 - (0.045 * zsolcpcl / zsolcpsi )**0.58 )
          zsieq(ji) = MAX( rtrn, sieqs(ji) )
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedmodel.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedmodel.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedmodel.F90	(revision 13463)
@@ -16,5 +16,5 @@
 CONTAINS
 
-   SUBROUTINE sed_model ( kt )
+   SUBROUTINE sed_model ( kt, Kbb, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE sed_model  ***
@@ -29,11 +29,12 @@
       !!        !  07-02 (C. Ethe)  Original
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt       ! number of iteration
+      INTEGER, INTENT(in) ::   kt               ! number of iteration
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Krhs   ! time level indices
 
 
       IF( ln_timing )  CALL timing_start('sed_model')
 
-      IF( kt == nittrc000 ) CALL sed_initrc       ! Initialization of sediment model
-                            CALL sed_stp( kt )  ! Time stepping of Sediment model
+      IF( kt == nittrc000 ) CALL sed_initrc( Kbb, Kmm )         ! Initialization of sediment model
+                            CALL sed_stp( kt, Kbb, Kmm, Krhs )  ! Time stepping of Sediment model
 
       IF( ln_timing )  CALL timing_stop('sed_model')
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedrst.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedrst.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedrst.F90	(revision 13463)
@@ -10,5 +10,5 @@
    USE sed
    USE sedarr
-   USE trc_oce, ONLY : l_offline, nn_dttrc
+   USE trc_oce, ONLY : l_offline
    USE phycst , ONLY : rday
    USE iom
@@ -49,12 +49,12 @@
             IF( ln_rst_list ) THEN
                nrst_lst = 1
-               nitrst = nstocklist( nrst_lst )
+               nitrst = nn_stocklist( nrst_lst )
             ELSE
                nitrst = nitend
             ENDIF
          ENDIF
-         IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nstock ) == 0 ) THEN
+         IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nn_stock ) == 0 ) THEN
             ! we use kt - 1 and not kt - nittrc000 to keep the same periodicity from the beginning of the experiment
-            nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
+            nitrst = kt + nn_stock - 1                  ! define the next value of nitrst for restart writing
             IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
          ENDIF
@@ -63,8 +63,10 @@
       ENDIF
 
+      IF( .NOT. ln_rst_list .AND. nn_stock == -1 )   RETURN   ! we will never do any restart
+
       ! to get better performances with NetCDF format:
-      ! we open and define the tracer restart file one tracer time step before writing the data (-> at nitrst - 2*nn_dttrc + 1)
-      ! except if we write tracer restart files every tracer time step or if a tracer restart file was writen at nitend - 2*nn_dttrc + 1
-      IF( kt == nitrst - 2*nn_dtsed .OR. nstock == nn_dtsed .OR. ( kt == nitend - nn_dtsed .AND. .NOT. lrst_sed ) ) THEN
+      ! we open and define the tracer restart file one tracer time step before writing the data (-> at nitrst - 1)
+      ! except if we write tracer restart files every tracer time step or if a tracer restart file was writen at nitend - 1
+      IF( kt == nitrst - 2*nn_dtsed .OR. nn_stock == nn_dtsed .OR. ( kt == nitend - nn_dtsed .AND. .NOT. lrst_sed ) ) THEN
          ! beware of the format used to write kt (default is i8.8, that should be large enough)
          IF( nitrst > 1.0e9 ) THEN   ;   WRITE(clkt,*       ) nitrst
@@ -78,5 +80,5 @@
          IF(lwp) WRITE(numsed,*) &
              '             open sed restart.output NetCDF file: ',TRIM(clpath)//clname
-         CALL iom_open( TRIM(clpath)//TRIM(clname), numrsw, ldwrt = .TRUE., kdlev = jpksed )
+         CALL iom_open( TRIM(clpath)//TRIM(clname), numrsw, ldwrt = .TRUE., kdlev = jpksed, cdcomp = 'SED' )
          lrst_sed = .TRUE.
       ENDIF
@@ -121,5 +123,5 @@
          cltra = TRIM(sedtrcd(jn))
          IF( iom_varid( numrsr, TRIM(cltra) , ldstop = .FALSE. ) > 0 ) THEN
-            CALL iom_get( numrsr, jpdom_autoglo, TRIM(cltra), zdta(:,:,:,jn) )
+            CALL iom_get( numrsr, jpdom_auto, TRIM(cltra), zdta(:,:,:,jn) )
          ELSE
             zdta(:,:,:,jn) = 0.0
@@ -140,5 +142,5 @@
          cltra = TRIM(seddia3d(jn))
          IF( iom_varid( numrsr, TRIM(cltra) , ldstop = .FALSE. ) > 0 ) THEN
-            CALL iom_get( numrsr, jpdom_autoglo, TRIM(cltra), zdta1(:,:,:,jn) )
+            CALL iom_get( numrsr, jpdom_auto, TRIM(cltra), zdta1(:,:,:,jn) )
          ELSE
             zdta1(:,:,:,jn) = 0.0
@@ -167,5 +169,5 @@
       cltra = "dbioturb"
       IF( iom_varid( numrsr, TRIM(cltra) , ldstop = .FALSE. ) > 0 ) THEN
-         CALL iom_get( numrsr, jpdom_autoglo, TRIM(cltra), zdta2(:,:,:) )
+         CALL iom_get( numrsr, jpdom_auto, TRIM(cltra), zdta2(:,:,:) )
       ELSE
          zdta2(:,:,:) = 0.0
@@ -177,5 +179,5 @@
       cltra = "irrig"
       IF( iom_varid( numrsr, TRIM(cltra) , ldstop = .FALSE. ) > 0 ) THEN
-         CALL iom_get( numrsr, jpdom_autoglo, TRIM(cltra), zdta2(:,:,:) )
+         CALL iom_get( numrsr, jpdom_auto, TRIM(cltra), zdta2(:,:,:) )
       ELSE
          zdta2(:,:,:) = 0.0
@@ -187,5 +189,5 @@
       cltra = "sedligand"
       IF( iom_varid( numrsr, TRIM(cltra) , ldstop = .FALSE. ) > 0 ) THEN
-         CALL iom_get( numrsr, jpdom_autoglo, TRIM(cltra), zdta2(:,:,:) )
+         CALL iom_get( numrsr, jpdom_auto, TRIM(cltra), zdta2(:,:,:) )
       ELSE
          zdta2(:,:,:) = 0.0
@@ -300,5 +302,5 @@
           IF( l_offline .AND. ln_rst_list ) THEN
              nrst_lst = nrst_lst + 1
-             nitrst = nstocklist( nrst_lst )
+             nitrst = nn_stocklist( nrst_lst )
           ENDIF
       ENDIF
@@ -328,5 +330,5 @@
       !!       In both those options, the  exact duration of the experiment
       !!       since the beginning (cumulated duration of all previous restart runs)
-      !!       is not stored in the restart and is assumed to be (nittrc000-1)*rdt.
+      !!       is not stored in the restart and is assumed to be (nittrc000-1)*rn_Dt.
       !!       This is valid is the time step has remained constant.
       !!
@@ -379,5 +381,5 @@
              ELSE
                ndastp = ndate0 - 1     ! ndate0 read in the namelist in dom_nam
-               adatrj = ( REAL( nittrc000-1, wp ) * rdt ) / rday
+               adatrj = ( REAL( nittrc000-1, wp ) * rn_Dt ) / rday
                ! note this is wrong if time step has changed during run
             ENDIF
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedsfc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedsfc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedsfc.F90	(revision 13463)
@@ -11,8 +11,10 @@
    PUBLIC sed_sfc
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !! $Id$
 CONTAINS
 
-   SUBROUTINE sed_sfc( kt )
+   SUBROUTINE sed_sfc( kt, Kbb )
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE sed_sfc ***
@@ -26,4 +28,5 @@
       !!* Arguments
       INTEGER, INTENT(in) ::  kt              ! time step
+      INTEGER, INTENT(in) ::  Kbb             ! time index
 
       ! * local variables
@@ -45,19 +48,17 @@
 
 
-      DO jj = 1,jpj
-         DO ji = 1, jpi
-            ikt = mbkt(ji,jj)
-            IF ( tmask(ji,jj,ikt) == 1 ) THEN
-               trb(ji,jj,ikt,jptal) = trc_data(ji,jj,1)
-               trb(ji,jj,ikt,jpdic) = trc_data(ji,jj,2)
-               trb(ji,jj,ikt,jpno3) = trc_data(ji,jj,3) * 7.625
-               trb(ji,jj,ikt,jppo4) = trc_data(ji,jj,4) * 122.
-               trb(ji,jj,ikt,jpoxy) = trc_data(ji,jj,5)
-               trb(ji,jj,ikt,jpsil) = trc_data(ji,jj,6)
-               trb(ji,jj,ikt,jpnh4) = trc_data(ji,jj,7) * 7.625
-               trb(ji,jj,ikt,jpfer) = trc_data(ji,jj,8)
-            ENDIF
-         ENDDO
-      ENDDO
+      DO_2D( 1, 1, 1, 1 )
+         ikt = mbkt(ji,jj)
+         IF ( tmask(ji,jj,ikt) == 1 ) THEN
+            tr(ji,jj,ikt,jptal,Kbb) = trc_data(ji,jj,1)
+            tr(ji,jj,ikt,jpdic,Kbb) = trc_data(ji,jj,2)
+            tr(ji,jj,ikt,jpno3,Kbb) = trc_data(ji,jj,3) * 7.625
+            tr(ji,jj,ikt,jppo4,Kbb) = trc_data(ji,jj,4) * 122.
+            tr(ji,jj,ikt,jpoxy,Kbb) = trc_data(ji,jj,5)
+            tr(ji,jj,ikt,jpsil,Kbb) = trc_data(ji,jj,6)
+            tr(ji,jj,ikt,jpnh4,Kbb) = trc_data(ji,jj,7) * 7.625
+            tr(ji,jj,ikt,jpfer,Kbb) = trc_data(ji,jj,8)
+         ENDIF
+      END_2D
 
       IF( ln_timing )  CALL timing_stop('sed_sfc')
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedstp.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedstp.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedstp.F90	(revision 13463)
@@ -29,5 +29,5 @@
 CONTAINS
 
-   SUBROUTINE sed_stp ( kt )
+   SUBROUTINE sed_stp ( kt, Kbb, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE sed_stp  ***
@@ -44,5 +44,6 @@
       !!        !  06-04 (C. Ethe)  Re-organization
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt       ! number of iteration
+      INTEGER, INTENT(in) ::   kt                ! number of iteration
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Krhs    ! time level indices
       INTEGER :: ji,jk,js,jn,jw
       !!----------------------------------------------------------------------
@@ -52,10 +53,10 @@
       IF( lrst_sed )            CALL sed_rst_cal  ( kt, 'WRITE' )   ! calenda
 
-      IF(ln_sediment_offline)   CALL trc_dmp_sed  ( kt )
+      IF(ln_sediment_offline)   CALL trc_dmp_sed  ( kt, Kbb, Kmm, Krhs )
 
-      dtsed  = r2dttrc
+      dtsed  = rDt_trc
 !      dtsed2 = dtsed
       IF (kt /= nitsed000) THEN
-         CALL sed_dta( kt )       ! Load  Data for bot. wat. Chem and fluxes
+         CALL sed_dta( kt, Kbb, Kmm )       ! Load  Data for bot. wat. Chem and fluxes
       ENDIF
 
@@ -80,5 +81,5 @@
          CALL sed_mbc( kt )         ! cumulation for mass balance calculation
 
-         IF (ln_sed_2way) CALL sed_sfc( kt )         ! Give back new bottom wat chem to tracer model
+         IF (ln_sed_2way) CALL sed_sfc( kt, Kbb )         ! Give back new bottom wat chem to tracer model
       ENDIF
       CALL sed_wri( kt )         ! outputs
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedwri.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedwri.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/sedwri.F90	(revision 13463)
@@ -94,5 +94,5 @@
          DO ji = 1, jpoce
             zflx(ji,jw) = ( pwcp(ji,1,jw) - pwcp_dta(ji,jw) ) &
-               &         * 1.e3 / 1.e2 * dzkbot(ji) / r2dttrc
+               &         * 1.e3 / 1.e2 * dzkbot(ji) / rDt_trc
          ENDDO
       ENDDO
@@ -100,5 +100,5 @@
       ! Calculation of accumulation rate per dt
       DO js = 1, jpsol
-         zrate =  1.0 / ( denssol * por1(jpksed) ) / r2dttrc
+         zrate =  1.0 / ( denssol * por1(jpksed) ) / rDt_trc
          DO ji = 1, jpoce
             zflx(ji,jpwatp1) = zflx(ji,jpwatp1) + ( tosed(ji,js) - fromsed(ji,js) ) * zrate
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/trcdmp_sed.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/trcdmp_sed.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/SED/trcdmp_sed.F90	(revision 13463)
@@ -21,5 +21,5 @@
    USE trc             ! ocean passive tracers variables
    USE trcdta
-   USE prtctl_trc      ! Print control for debbuging
+   USE prtctl          ! Print control for debbuging
    USE iom
 
@@ -35,5 +35,5 @@
 
    !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -54,5 +54,5 @@
 
 
-   SUBROUTINE trc_dmp_sed( kt )
+   SUBROUTINE trc_dmp_sed( kt, Kbb, Kmm, Krhs )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE trc_dmp_sed  ***
@@ -64,14 +64,15 @@
       !! ** Method  :   Newtonian damping towards trdta computed 
       !!      and add to the general tracer trends:
-      !!                     trn = tra + restotr * (trdta - trb)
+      !!                     tr(Kmm) = tr(Krhs) + restotr * (trdta - tr(Kbb))
       !!         The trend is computed either throughout the water column
       !!      (nlmdmptr=0) or in area of weak vertical mixing (nlmdmptr=1) or
       !!      below the well mixed layer (nlmdmptr=2)
       !!
-      !! ** Action  : - update the tracer trends tra with the newtonian 
+      !! ** Action  : - update the tracer trends tr(Krhs) with the newtonian 
       !!                damping trends.
       !!              - save the trends ('key_trdmxl_trc')
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      INTEGER, INTENT(in) ::   kt              ! ocean time-step index
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Krhs  ! time level index
       !
       INTEGER ::   ji, jj, jk, jn, jl, ikt   ! dummy loop indices
@@ -90,13 +91,11 @@
                !
                jl = n_trc_index(jn) 
-               CALL trc_dta( kt, sf_trcdta(jl), rf_trfac(jl), ztrcdta )   ! read tracer data at nit000
+               CALL trc_dta( kt, Kmm, sf_trcdta(jl), rf_trfac(jl), ztrcdta )   ! read tracer data at nit000
                !
-               DO jj = 1, jpj
-                  DO ji = 1, jpi   ! vector opt.
-                     ikt = mbkt(ji,jj)
-                     trb(ji,jj,ikt,jn) = ztrcdta(ji,jj,ikt) + ( trb(ji,jj,ikt,jn) -  ztrcdta(ji,jj,ikt) )     &
-                     &                  * exp( -restosed(ji,jj,ikt) * dtsed )
-                  END DO
-               END DO
+               DO_2D( 1, 1, 1, 1 )
+                  ikt = mbkt(ji,jj)
+                  tr(ji,jj,ikt,jn,Kbb) = ztrcdta(ji,jj,ikt) + ( tr(ji,jj,ikt,jn,Kbb) -  ztrcdta(ji,jj,ikt) )     &
+                  &                  * exp( -restosed(ji,jj,ikt) * dtsed )
+               END_2D
                ! 
             ENDIF
@@ -106,8 +105,8 @@
       !
       !                                          ! print mean trends (used for debugging)
-      IF( ln_ctl ) THEN
+      IF( sn_cfctl%l_prttrc ) THEN
          WRITE(charout, FMT="('dmp ')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl( tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm, clinfo3='trd' )
       ENDIF
       !
@@ -148,6 +147,7 @@
    !!----------------------------------------------------------------------
 CONTAINS
-   SUBROUTINE trc_dmp_sed( kt )        ! Empty routine
+   SUBROUTINE trc_dmp_sed( kt, Kbb, Kmm, Krhs )   ! Empty routine
       INTEGER, INTENT(in) :: kt
+      INTEGER, INTENT(in) :: Kbb, Kmm, Krhs
       WRITE(*,*) 'trc_dmp_sed: You should not have seen this print! error?', kt
    END SUBROUTINE trc_dmp_sed
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/par_pisces.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/par_pisces.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/par_pisces.F90	(revision 13463)
@@ -6,4 +6,5 @@
    !! History :   2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
    !!----------------------------------------------------------------------
+   USE par_kind
 
    IMPLICIT NONE
@@ -60,6 +61,12 @@
    !!   Default                                   No CFC geochemical model
    ! Starting/ending PISCES do-loop indices (N.B. no PISCES : jpl_pcs < jpf_pcs the do-loop are never done)
-   INTEGER, PUBLIC  ::   jp_pcs0  !: First index of PISCES tracers
-   INTEGER, PUBLIC  ::   jp_pcs1  !: Last  index of PISCES tracers
+   INTEGER, PUBLIC  ::  jp_pcs0  !: First index of PISCES tracers
+   INTEGER, PUBLIC  ::  jp_pcs1  !: Last  index of PISCES tracers
+
+   REAL(wp), PUBLIC ::  mMass_C  = 12.00      ! Molar mass of carbon
+   REAL(wp), PUBLIC ::  mMass_N  = 14.00      ! Molar mass of nitrogen
+   REAL(wp), PUBLIC ::  mMass_P  = 31.00      ! Molar mass of phosphorus
+   REAL(wp), PUBLIC ::  mMass_Fe = 55.85      ! Molar mass of iron
+   REAL(wp), PUBLIC ::  mMass_Si = 28.00      ! Molar mass of silver
 
    !!----------------------------------------------------------------------
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/sms_pisces.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/sms_pisces.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/sms_pisces.F90	(revision 13463)
@@ -13,7 +13,7 @@
    PUBLIC
 
-   INTEGER ::   numnatp_ref = -1           !! Logical units for namelist pisces
-   INTEGER ::   numnatp_cfg = -1           !! Logical units for namelist pisces
-   INTEGER ::   numonp      = -1           !! Logical unit for namelist pisces output
+   CHARACTER(:), ALLOCATABLE ::   numnatp_ref   !! Character buffer for reference namelist pisces
+   CHARACTER(:), ALLOCATABLE ::   numnatp_cfg   !! Character buffer for configuration namelist pisces
+   INTEGER ::   numonp      = -1                !! Logical unit for namelist pisces output
 
    !                                                       !:  PISCES  : silicon dependant half saturation
@@ -121,4 +121,6 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tgfunc2   !: Temp. dependancy of mesozooplankton rates
 
+   LOGICAL, SAVE :: lk_sed
+
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/trcini_pisces.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/trcini_pisces.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/trcini_pisces.F90	(revision 13463)
@@ -32,5 +32,5 @@
 CONTAINS
 
-   SUBROUTINE trc_ini_pisces
+   SUBROUTINE trc_ini_pisces( Kmm )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE trc_ini_pisces ***
@@ -38,9 +38,10 @@
       !! ** Purpose :   Initialisation of the PISCES biochemical model
       !!----------------------------------------------------------------------
+      INTEGER, INTENT(in)  ::  Kmm      ! time level indices
       !
       CALL trc_nam_pisces
       !
-      IF( ln_p4z .OR. ln_p5z ) THEN  ;   CALL p4z_ini   !  PISCES
-      ELSE                           ;   CALL p2z_ini   !  LOBSTER
+      IF( ln_p4z .OR. ln_p5z ) THEN  ;   CALL p4z_ini( Kmm )   !  PISCES
+      ELSE                           ;   CALL p2z_ini( Kmm )   !  LOBSTER
       ENDIF
 
@@ -48,5 +49,5 @@
 
 
-   SUBROUTINE p4z_ini
+   SUBROUTINE p4z_ini( Kmm )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE p4z_ini ***
@@ -58,5 +59,5 @@
       USE p4zsink         !  vertical flux of particulate matter due to sinking
       USE p4zopt          !  optical model
-      USE p4zsbc          !  Boundary conditions
+      USE p4zbc          !  Boundary conditions
       USE p4zfechem       !  Iron chemistry
       USE p4zrem          !  Remineralisation of organic matter
@@ -77,4 +78,5 @@
       USE p5zmort         !  Mortality terms for phytoplankton
       !
+      INTEGER, INTENT(in)  ::  Kmm      ! time level indices
       REAL(wp), SAVE ::   sco2   =  2.312e-3_wp
       REAL(wp), SAVE ::   alka0  =  2.426e-3_wp
@@ -189,47 +191,47 @@
       !--------------------------------------------------------------
       IF( .NOT.ln_rsttr ) THEN  
-         trn(:,:,:,jpdic) = sco2
-         trn(:,:,:,jpdoc) = bioma0
-         trn(:,:,:,jptal) = alka0
-         trn(:,:,:,jpoxy) = oxyg0
-         trn(:,:,:,jpcal) = bioma0
-         trn(:,:,:,jppo4) = po4 / po4r
-         trn(:,:,:,jppoc) = bioma0
-         trn(:,:,:,jpgoc) = bioma0
-         trn(:,:,:,jpbfe) = bioma0 * 5.e-6
-         trn(:,:,:,jpsil) = silic1
-         trn(:,:,:,jpdsi) = bioma0 * 0.15
-         trn(:,:,:,jpgsi) = bioma0 * 5.e-6
-         trn(:,:,:,jpphy) = bioma0
-         trn(:,:,:,jpdia) = bioma0
-         trn(:,:,:,jpzoo) = bioma0
-         trn(:,:,:,jpmes) = bioma0
-         trn(:,:,:,jpfer) = 0.6E-9
-         trn(:,:,:,jpsfe) = bioma0 * 5.e-6
-         trn(:,:,:,jpdfe) = bioma0 * 5.e-6
-         trn(:,:,:,jpnfe) = bioma0 * 5.e-6
-         trn(:,:,:,jpnch) = bioma0 * 12. / 55.
-         trn(:,:,:,jpdch) = bioma0 * 12. / 55.
-         trn(:,:,:,jpno3) = no3
-         trn(:,:,:,jpnh4) = bioma0
+         tr(:,:,:,jpdic,Kmm) = sco2
+         tr(:,:,:,jpdoc,Kmm) = bioma0
+         tr(:,:,:,jptal,Kmm) = alka0
+         tr(:,:,:,jpoxy,Kmm) = oxyg0
+         tr(:,:,:,jpcal,Kmm) = bioma0
+         tr(:,:,:,jppo4,Kmm) = po4 / po4r
+         tr(:,:,:,jppoc,Kmm) = bioma0
+         tr(:,:,:,jpgoc,Kmm) = bioma0
+         tr(:,:,:,jpbfe,Kmm) = bioma0 * 5.e-6
+         tr(:,:,:,jpsil,Kmm) = silic1
+         tr(:,:,:,jpdsi,Kmm) = bioma0 * 0.15
+         tr(:,:,:,jpgsi,Kmm) = bioma0 * 5.e-6
+         tr(:,:,:,jpphy,Kmm) = bioma0
+         tr(:,:,:,jpdia,Kmm) = bioma0
+         tr(:,:,:,jpzoo,Kmm) = bioma0
+         tr(:,:,:,jpmes,Kmm) = bioma0
+         tr(:,:,:,jpfer,Kmm) = 0.6E-9
+         tr(:,:,:,jpsfe,Kmm) = bioma0 * 5.e-6
+         tr(:,:,:,jpdfe,Kmm) = bioma0 * 5.e-6
+         tr(:,:,:,jpnfe,Kmm) = bioma0 * 5.e-6
+         tr(:,:,:,jpnch,Kmm) = bioma0 * 12. / 55.
+         tr(:,:,:,jpdch,Kmm) = bioma0 * 12. / 55.
+         tr(:,:,:,jpno3,Kmm) = no3
+         tr(:,:,:,jpnh4,Kmm) = bioma0
          IF( ln_ligand) THEN
-            trn(:,:,:,jplgw) = 0.6E-9
+            tr(:,:,:,jplgw,Kmm) = 0.6E-9
          ENDIF
          IF( ln_p5z ) THEN
-            trn(:,:,:,jpdon) = bioma0
-            trn(:,:,:,jpdop) = bioma0
-            trn(:,:,:,jppon) = bioma0
-            trn(:,:,:,jppop) = bioma0
-            trn(:,:,:,jpgon) = bioma0
-            trn(:,:,:,jpgop) = bioma0
-            trn(:,:,:,jpnph) = bioma0
-            trn(:,:,:,jppph) = bioma0
-            trn(:,:,:,jppic) = bioma0
-            trn(:,:,:,jpnpi) = bioma0
-            trn(:,:,:,jpppi) = bioma0
-            trn(:,:,:,jpndi) = bioma0
-            trn(:,:,:,jppdi) = bioma0
-            trn(:,:,:,jppfe) = bioma0 * 5.e-6
-            trn(:,:,:,jppch) = bioma0 * 12. / 55.
+            tr(:,:,:,jpdon,Kmm) = bioma0
+            tr(:,:,:,jpdop,Kmm) = bioma0
+            tr(:,:,:,jppon,Kmm) = bioma0
+            tr(:,:,:,jppop,Kmm) = bioma0
+            tr(:,:,:,jpgon,Kmm) = bioma0
+            tr(:,:,:,jpgop,Kmm) = bioma0
+            tr(:,:,:,jpnph,Kmm) = bioma0
+            tr(:,:,:,jppph,Kmm) = bioma0
+            tr(:,:,:,jppic,Kmm) = bioma0
+            tr(:,:,:,jpnpi,Kmm) = bioma0
+            tr(:,:,:,jpppi,Kmm) = bioma0
+            tr(:,:,:,jpndi,Kmm) = bioma0
+            tr(:,:,:,jppdi,Kmm) = bioma0
+            tr(:,:,:,jppfe,Kmm) = bioma0 * 5.e-6
+            tr(:,:,:,jppch,Kmm) = bioma0 * 12. / 55.
          ENDIF
          ! initialize the half saturation constant for silicate
@@ -254,5 +256,5 @@
          CALL p5z_prod_init      !  phytoplankton growth rate over the global ocean.
       ENDIF
-      CALL p4z_sbc_init          !  boundary conditions
+      CALL p4z_bc_init( Kmm )    !  boundary conditions
       CALL p4z_fechem_init       !  Iron chemistry
       CALL p4z_rem_init          !  remineralisation
@@ -275,5 +277,8 @@
 
       ! Initialization of the sediment model
-      IF( ln_sediment)   CALL sed_init
+      IF( ln_sediment)   &
+        & CALL sed_init ! Initialization of the sediment model 
+
+      CALL p4z_sed_init          ! loss of organic matter in the sediments 
 
       IF(lwp) WRITE(numout,*) 
@@ -284,5 +289,5 @@
 
 
-   SUBROUTINE p2z_ini
+   SUBROUTINE p2z_ini( Kmm )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE p2z_ini ***
@@ -296,4 +301,5 @@
       USE p2zsed
       !
+      INTEGER, INTENT(in)  ::  Kmm      ! time level indices
       INTEGER  ::  ji, jj, jk, jn, ierr
       CHARACTER(len = 10)  ::  cltra
@@ -334,18 +340,18 @@
       ! ----------------------
       IF( .NOT. ln_rsttr ) THEN             ! in case of  no restart 
-         trn(:,:,:,jpdet) = 0.1 * tmask(:,:,:)
-         trn(:,:,:,jpzoo) = 0.1 * tmask(:,:,:)
-         trn(:,:,:,jpnh4) = 0.1 * tmask(:,:,:)
-         trn(:,:,:,jpphy) = 0.1 * tmask(:,:,:)
-         trn(:,:,:,jpdom) = 1.0 * tmask(:,:,:)
-         WHERE( rhd(:,:,:) <= 24.5e-3 )  ;  trn(:,:,:,jpno3) = 2._wp * tmask(:,:,:)
-         ELSE WHERE                      ;  trn(:,:,:,jpno3) = ( 15.55 * ( rhd(:,:,:) * 1000. ) - 380.11 ) * tmask(:,:,:)
+         tr(:,:,:,jpdet,Kmm) = 0.1 * tmask(:,:,:)
+         tr(:,:,:,jpzoo,Kmm) = 0.1 * tmask(:,:,:)
+         tr(:,:,:,jpnh4,Kmm) = 0.1 * tmask(:,:,:)
+         tr(:,:,:,jpphy,Kmm) = 0.1 * tmask(:,:,:)
+         tr(:,:,:,jpdom,Kmm) = 1.0 * tmask(:,:,:)
+         WHERE( rhd(:,:,:) <= 24.5e-3 )  ;  tr(:,:,:,jpno3,Kmm) = 2._wp * tmask(:,:,:)
+         ELSE WHERE                      ;  tr(:,:,:,jpno3,Kmm) = ( 15.55 * ( rhd(:,:,:) * 1000. ) - 380.11 ) * tmask(:,:,:)
          END WHERE                       
       ENDIF
-      !                       !  Namelist read
-      CALL p2z_opt_init       !  Optics parameters
-      CALL p2z_sed_init       !  sedimentation
-      CALL p2z_bio_init       !  biology
-      CALL p2z_exp_init       !  export 
+      !                        !  Namelist read
+      CALL p2z_opt_init        !  Optics parameters
+      CALL p2z_sed_init        !  sedimentation
+      CALL p2z_bio_init        !  biology
+      CALL p2z_exp_init( Kmm ) !  export 
       !
       IF(lwp) WRITE(numout,*) 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/trcnam_pisces.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/trcnam_pisces.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/trcnam_pisces.F90	(revision 13463)
@@ -51,14 +51,12 @@
       IF(lwp) WRITE(numout,*) 'trc_nam_pisces : read PISCES namelist'
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'
-      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. )
+      CALL load_nml( numnatp_ref, TRIM( clname )//'_ref', numout, lwm )
+      CALL load_nml( numnatp_cfg, TRIM( clname )//'_cfg', numout, lwm )
       IF(lwm) CALL ctl_opn( numonp     , 'output.namelist.pis' , 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
       !
-      REWIND( numnatp_ref )              ! Namelist nampisbio in reference namelist : Pisces variables
       READ  ( numnatp_ref, nampismod, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampismod in reference namelist', lwp )
-      REWIND( numnatp_cfg )              ! Namelist nampisbio in configuration namelist : Pisces variables
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nampismod in reference namelist' )
       READ  ( numnatp_cfg, nampismod, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampismod in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nampismod in configuration namelist' )
       IF(lwm) WRITE( numonp, nampismod )
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/trcsms_pisces.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/trcsms_pisces.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/trcsms_pisces.F90	(revision 13463)
@@ -25,5 +25,5 @@
 CONTAINS
 
-   SUBROUTINE trc_sms_pisces( kt )
+   SUBROUTINE trc_sms_pisces( kt, Kbb, Kmm, Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE trc_sms_pisces  ***
@@ -34,9 +34,10 @@
       !!---------------------------------------------------------------------
       !
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   kt               ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   Kbb, Kmm, Krhs   ! time level index
       !!---------------------------------------------------------------------
       !
-      IF( ln_p4z .OR. ln_p5z ) THEN  ;   CALL p4z_sms( kt )   !  PISCES
-      ELSE                           ;   CALL p2z_sms( kt )   !  LOBSTER
+      IF( ln_p4z .OR. ln_p5z ) THEN  ;   CALL p4z_sms( kt, Kbb, Kmm, Krhs )   !  PISCES
+      ELSE                           ;   CALL p2z_sms( kt,      Kmm, Krhs )   !  LOBSTER
       ENDIF
 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/trcwri_pisces.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/trcwri_pisces.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/PISCES/trcwri_pisces.F90	(revision 13463)
@@ -19,4 +19,7 @@
    PUBLIC trc_wri_pisces 
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -26,5 +29,5 @@
 CONTAINS
 
-   SUBROUTINE trc_wri_pisces
+   SUBROUTINE trc_wri_pisces( Kmm )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE trc_wri_trc  ***
@@ -32,4 +35,5 @@
       !! ** Purpose :   output passive tracers fields 
       !!---------------------------------------------------------------------
+      INTEGER, INTENT(in)          :: Kmm      ! time level indices
       CHARACTER (len=20)           :: cltra
       REAL(wp)                     :: zfact
@@ -43,5 +47,5 @@
          DO jn = jp_pcs0, jp_pcs1
             cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
-            CALL iom_put( cltra, trn(:,:,:,jn) )
+            CALL iom_put( cltra, tr(:,:,:,jn,Kmm) )
          END DO
       ELSE
@@ -51,5 +55,5 @@
             IF( jn == jppo4  )                 zfact = po4r * 1.0e+6
             cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
-            IF( iom_use( cltra ) )  CALL iom_put( cltra, trn(:,:,:,jn) * zfact )
+            IF( iom_use( cltra ) )  CALL iom_put( cltra, tr(:,:,:,jn,Kmm) * zfact )
          END DO
 
@@ -57,5 +61,5 @@
             zdic(:,:) = 0.
             DO jk = 1, jpkm1
-               zdic(:,:) = zdic(:,:) + trn(:,:,jk,jpdic) * e3t_n(:,:,jk) * tmask(:,:,jk) * 12.
+               zdic(:,:) = zdic(:,:) + tr(:,:,jk,jpdic,Kmm) * e3t(:,:,jk,Kmm) * tmask(:,:,jk) * 12.
             ENDDO
             CALL iom_put( 'INTDIC', zdic )     
@@ -63,18 +67,14 @@
          !
          IF( iom_use( "O2MIN" ) .OR. iom_use ( "ZO2MIN" ) ) THEN  ! Oxygen minimum concentration and depth 
-            zo2min   (:,:) = trn(:,:,1,jpoxy) * tmask(:,:,1)
-            zdepo2min(:,:) = gdepw_n(:,:,1)   * tmask(:,:,1)
-            DO jk = 2, jpkm1
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     IF( tmask(ji,jj,jk) == 1 ) then
-                        IF( trn(ji,jj,jk,jpoxy) < zo2min(ji,jj) ) then
-                           zo2min   (ji,jj) = trn(ji,jj,jk,jpoxy)
-                           zdepo2min(ji,jj) = gdepw_n(ji,jj,jk)
-                        ENDIF
-                     ENDIF
-                  END DO
-               END DO
-            END DO
+            zo2min   (:,:) = tr(:,:,1,jpoxy,Kmm) * tmask(:,:,1)
+            zdepo2min(:,:) = gdepw(:,:,1,Kmm)   * tmask(:,:,1)
+            DO_3D( 1, 1, 1, 1, 2, jpkm1 )
+               IF( tmask(ji,jj,jk) == 1 ) then
+                  IF( tr(ji,jj,jk,jpoxy,Kmm) < zo2min(ji,jj) ) then
+                     zo2min   (ji,jj) = tr(ji,jj,jk,jpoxy,Kmm)
+                     zdepo2min(ji,jj) = gdepw(ji,jj,jk,Kmm)
+                  ENDIF
+               ENDIF
+            END_3D
             !
             CALL iom_put('O2MIN' , zo2min     )                              ! oxygen minimum concentration
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/README.rst
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/README.rst	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/README.rst	(revision 13463)
@@ -3,46 +3,51 @@
 ***************
 
+.. todo::
+
+
+
 .. contents::
-	:local:
-
-TOP (Tracers in the Ocean Paradigm) is the NEMO hardwired interface toward biogeochemical models and
-provide the physical constraints/boundaries for oceanic tracers.
-It consists of a modular framework to handle multiple ocean tracers, including also a variety of built-in modules.
+   :local:
+
+TOP (Tracers in the Ocean Paradigm) is the NEMO hardwired interface toward
+biogeochemical models and provide the physical constraints/boundaries for oceanic tracers.
+It consists of a modular framework to handle multiple ocean tracers,
+including also a variety of built-in modules.
 
 This component of the NEMO framework allows one to exploit available modules (see below) and
 further develop a range of applications, spanning from the implementation of a dye passive tracer to
 evaluate dispersion processes (by means of MY_TRC), track water masses age (AGE module),
-assess the ocean interior penetration of persistent chemical compounds (e.g., gases like CFC or even PCBs),
-up to the full set of equations involving marine biogeochemical cycles.
+assess the ocean interior penetration of persistent chemical compounds
+(e.g., gases like CFC or even PCBs), up to the full set of equations involving
+marine biogeochemical cycles.
 
 Structure
 =========
 
-TOP interface has the following location in the source code ``./src/MBG/`` and
+TOP interface has the following location in the source code :file:`./src/TOP` and
 the following modules are available:
 
-``TRP``
-	Interface to NEMO physical core for computing tracers transport
-
-``CFC``
-	Inert carbon tracers (CFC11,CFC12,SF6)
-
-``C14``
-	Radiocarbon passive tracer
-
-``AGE``
-	Water age tracking
-
-``MY_TRC``
-	Template for creation of new modules and external BGC models coupling
-
-``PISCES``
-	Built in BGC model.
-	See [https://www.geosci-model-dev.net/8/2465/2015/gmd-8-2465-2015-discussion.html Aumont et al. (2015)] for
-	a throughout description. |
-
-The usage of TOP is activated i) by including in the configuration definition  the component ``MBG`` and
-ii) by adding the macro ``key_top`` in the configuration CPP file
-(see for more details [http://forge.ipsl.jussieu.fr/nemo/wiki/Users "Learn more about the model"]).
+:file:`TRP`
+   Interface to NEMO physical core for computing tracers transport
+
+:file:`CFC`
+   Inert carbon tracers (CFC11,CFC12,SF6)
+
+:file:`C14`
+   Radiocarbon passive tracer
+
+:file:`AGE`
+   Water age tracking
+
+:file:`MY_TRC`
+   Template for creation of new modules and external BGC models coupling
+
+:file:`PISCES`
+   Built in BGC model. See :cite:`gmd-8-2465-2015` for a throughout description.
+
+The usage of TOP is activated
+*i)* by including in the configuration definition the component ``TOP`` and
+*ii)* by adding the macro ``key_top`` in the configuration CPP file
+(see for more details :forge:`"Learn more about the model" <wiki/Users>`).
 
 As an example, the user can refer to already available configurations in the code,
@@ -51,5 +56,6 @@
 (see also Section 4) .
 
-Note that, since version 4.0, TOP interface core functionalities are activated by means of logical keys and
+Note that, since version 4.0,
+TOP interface core functionalities are activated by means of logical keys and
 all submodules preprocessing macros from previous versions were removed.
 
@@ -57,118 +63,131 @@
 
 ``key_iomput``
-	use XIOS I/O
+   use XIOS I/O
 
 ``key_agrif``
-	enable AGRIF coupling
+   enable AGRIF coupling
 
 ``key_trdtrc`` & ``key_trdmxl_trc``
-	trend computation for tracers
+   trend computation for tracers
 
 Synthetic Workflow
 ==================
 
-A synthetic description of the TOP interface workflow is given below to summarize the steps involved in
-the computation of biogeochemical and physical trends and their time integration and outputs,
+A synthetic description of the TOP interface workflow is given below to
+summarize the steps involved in the computation of biogeochemical and physical trends and
+their time integration and outputs,
 by reporting also the principal Fortran subroutine herein involved.
 
-**Model initialization (OPA_SRC/nemogcm.F90)**
-
-call to trc_init (trcini.F90)
-
-  ↳ call trc_nam (trcnam.F90) to initialize TOP tracers and run setting
-
-  ↳ call trc_ini_sms, to initialize each submodule
-
-  ↳ call trc_ini_trp, to initialize transport for tracers
-
-  ↳ call trc_ice_ini, to initialize tracers in seaice
-
-  ↳ call trc_ini_state, read passive tracers from a restart or input data
-
-  ↳ call trc_sub_ini, setup substepping if {{{nn_dttrc /= 1}}}
-
-**Time marching procedure (OPA_SRC/stp.F90)**
-
-call to trc_stp.F90 (trcstp.F90)
-
-  ↳ call trc_sub_stp, averaging physical variables for sub-stepping
-
-  ↳ call trc_wri, call XIOS for output of data
-
-  ↳ call trc_sms, compute BGC trends for each submodule
-
-    ↳ call trc_sms_my_trc, includes also surface and coastal BCs trends
-
-  ↳ call trc_trp (TRP/trctrp.F90), compute physical trends
-
-    ↳ call trc_sbc, get trend due to surface concentration/dilution
-
-    ↳ call trc_adv, compute tracers advection
-
-    ↳ call to trc_ldf, compute tracers lateral diffusion
-
-    ↳ call to trc_zdf, vertical mixing and after tracer fields
-
-    ↳ call to trc_nxt, tracer fields at next time step. Lateral Boundary Conditions are solved in here.
-
-    ↳ call to trc_rad, Correct artificial negative concentrations
-
-  ↳ call trc_rst_wri, output tracers restart files
+Model initialization (:file:`./src/OCE/nemogcm.F90`)
+----------------------------------------------------
+
+Call to ``trc_init`` subroutine (:file:`./src/TOP/trcini.F90`) to initialize TOP.
+
+.. literalinclude:: ../../../src/TOP/trcini.F90
+   :language:        fortran
+   :lines:           41-86
+   :emphasize-lines: 21,30-32,38-40
+   :caption:         ``trc_init`` subroutine
+
+Time marching procedure (:file:`./src/OCE/step.F90`)
+----------------------------------------------------
+
+Call to ``trc_stp`` subroutine (:file:`./src/TOP/trcstp.F90`) to compute/update passive tracers.
+
+.. literalinclude:: ../../../src/TOP/trcstp.F90
+   :language:        fortran
+   :lines:           46-125
+   :emphasize-lines: 42,55-57
+   :caption:         ``trc_stp`` subroutine
+
+BGC trends computation for each submodule (:file:`./src/TOP/trcsms.F90`)
+------------------------------------------------------------------------
+
+.. literalinclude:: ../../../src/TOP/trcsms.F90
+   :language:        fortran
+   :lines:           21
+   :caption:         :file:`trcsms` snippet
+
+Physical trends computation (:file:`./src/TOP/TRP/trctrp.F90`)
+--------------------------------------------------------------
+
+.. literalinclude:: ../../../src/TOP/TRP/trctrp.F90
+   :language:        fortran
+   :lines:           46-95
+   :emphasize-lines: 17,21,29,33-35
+   :caption:         ``trc_trp`` subroutine
 
 Namelists walkthrough
 =====================
 
-namelist_top
-------------
-
-Here below are listed the features/options of the TOP interface accessible through the namelist_top_ref and
-modifiable by means of namelist_top_cfg (as for NEMO physical ones).
-
-Note that ## is used to refer to a number in an array field.
+:file:`namelist_top`
+--------------------
+
+Here below are listed the features/options of the TOP interface accessible through
+the :file:`namelist_top_ref` and modifiable by means of :file:`namelist_top_cfg`
+(as for NEMO physical ones).
+
+Note that ``##`` is used to refer to a number in an array field.
 
 .. literalinclude:: ../../namelists/namtrc_run
+   :language: fortran
 
 .. literalinclude:: ../../namelists/namtrc
+   :language: fortran
 
 .. literalinclude:: ../../namelists/namtrc_dta
+   :language: fortran
 
 .. literalinclude:: ../../namelists/namtrc_adv
+   :language: fortran
 
 .. literalinclude:: ../../namelists/namtrc_ldf
+   :language: fortran
 
 .. literalinclude:: ../../namelists/namtrc_rad
+   :language: fortran
 
 .. literalinclude:: ../../namelists/namtrc_snk
+   :language: fortran
 
 .. literalinclude:: ../../namelists/namtrc_dmp
+   :language: fortran
 
 .. literalinclude:: ../../namelists/namtrc_ice
+   :language: fortran
 
 .. literalinclude:: ../../namelists/namtrc_trd
+   :language: fortran
 
 .. literalinclude:: ../../namelists/namtrc_bc
+   :language: fortran
 
 .. literalinclude:: ../../namelists/namtrc_bdy
+   :language: fortran
 
 .. literalinclude:: ../../namelists/namage
-
-Two main types of data structure are used within TOP interface to initialize tracer properties (1) and
+   :language: fortran
+
+Two main types of data structure are used within TOP interface
+to initialize tracer properties (1) and
 to provide related initial and boundary conditions (2).
 
-**1. TOP tracers initialization**: sn_tracer (namtrc)
+1. TOP tracers initialization: ``sn_tracer`` (``&namtrc``)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 Beside providing name and metadata for tracers,
-here are also defined the use of initial ({{{sn_tracer%llinit}}}) and
-boundary ({{{sn_tracer%llsbc, sn_tracer%llcbc, sn_tracer%llobc}}}) conditions.
-
-In the following, an example of the full structure definition is given for two idealized tracers both with
-initial conditions given, while the first has only surface boundary forcing and
+here are also defined the use of initial (``sn_tracer%llinit``) and
+boundary (``sn_tracer%llsbc, sn_tracer%llcbc, sn_tracer%llobc``) conditions.
+
+In the following, an example of the full structure definition is given for
+two idealized tracers both with initial conditions given,
+while the first has only surface boundary forcing and
 the second both surface and coastal forcings:
 
 .. code-block:: fortran
 
-	!             !    name   !           title of the field            !   units    ! initial data ! sbc   !   cbc  !   obc  !
-	sn_tracer(1)  = 'TRC1'    , 'Tracer 1 Concentration                ',   ' - '    ,  .true.      , .true., .false., .true.
-	sn_tracer(2)  = 'TRC2 '   , 'Tracer 2 Concentration                ',   ' - '    ,  .true.      , .true., .true. , .false.
+   !             !    name   !           title of the field            !   units    ! initial data ! sbc   !   cbc  !   obc  !
+   sn_tracer(1)  = 'TRC1'    , 'Tracer 1 Concentration                ',   ' - '    ,  .true.      , .true., .false., .true.
+   sn_tracer(2)  = 'TRC2 '   , 'Tracer 2 Concentration                ',   ' - '    ,  .true.      , .true., .true. , .false.
 
 As tracers in BGC models are increasingly growing,
@@ -177,94 +196,101 @@
 .. code-block:: fortran
 
-	!             !    name   !           title of the field            !   units    ! initial data !
-	sn_tracer(1)  = 'TRC1'    , 'Tracer 1 Concentration                ',   ' - '    ,   .true.
-	sn_tracer(2)  = 'TRC2 '   , 'Tracer 2 Concentration                ',   ' - '    ,   .true.
-	! sbc
-	sn_tracer(1)%llsbc = .true.
-	sn_tracer(2)%llsbc = .true.
-	! cbc
-	sn_tracer(2)%llcbc = .true.
+   !             !    name   !           title of the field            !   units    ! initial data !
+   sn_tracer(1)  = 'TRC1'    , 'Tracer 1 Concentration                ',   ' - '    ,   .true.
+   sn_tracer(2)  = 'TRC2 '   , 'Tracer 2 Concentration                ',   ' - '    ,   .true.
+   ! sbc
+   sn_tracer(1)%llsbc = .true.
+   sn_tracer(2)%llsbc = .true.
+   ! cbc
+   sn_tracer(2)%llcbc = .true.
 
 The data structure is internally initialized by code with dummy names and
-all initialization/forcing logical fields set to .false. .
-
-**2. Structures to read input initial and boundary conditions**: namtrc_dta (sn_trcdta), namtrc_bc (sn_trcsbc/sn_trccbc/sn_trcobc)
+all initialization/forcing logical fields set to ``.false.`` .
+
+2. Structures to read input initial and boundary conditions: ``&namtrc_dta`` (``sn_trcdta``), ``&namtrc_bc`` (``sn_trcsbc`` / ``sn_trccbc`` / ``sn_trcobc``)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 The overall data structure (Fortran type) is based on the general one defined for NEMO core in the SBC component
-(see details in User Manual SBC Chapter on Input Data specification).
-
-Input fields are prescribed within namtrc_dta (with sn_trcdta structure),
-while Boundary Conditions are applied to the model by means of namtrc_bc,
-with dedicated structure fields for surface (sn_trcsbc), riverine (sn_trccbc), and
-lateral open (sn_trcobc) boundaries.
+(see details in ``SBC`` Chapter of :doc:`Reference Manual <cite>` on Input Data specification).
+
+Input fields are prescribed within ``&namtrc_dta`` (with ``sn_trcdta`` structure),
+while Boundary Conditions are applied to the model by means of ``&namtrc_bc``,
+with dedicated structure fields for surface (``sn_trcsbc``), riverine (``sn_trccbc``), and
+lateral open (``sn_trcobc``) boundaries.
 
 The following example illustrates the data structure in the case of initial condition for
-a single tracer contained in the file named tracer_1_data.nc (.nc is implicitly assumed in namelist filename),
-with a doubled initial value, and located in the usr/work/model/inputdata/ folder:
+a single tracer contained in the file named :file:`tracer_1_data.nc`
+(``.nc`` is implicitly assumed in namelist filename),
+with a doubled initial value, and located in the :file:`usr/work/model/inputdata` folder:
 
 .. code-block:: fortran
 
-	!               !  file name             ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
-	!               !                        !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
-	  sn_trcdta(1)  = 'tracer_1_data'        ,        -12        ,  'TRC1'   ,    .false.   , .true. , 'yearly'  , ''       , ''       , ''
-	  rf_trfac(1) = 2.0
-	  cn_dir = “usr/work/model/inputdata/”
-
-Note that, the Lateral Open Boundaries conditions are applied on the segments defined for the physical core of NEMO
-(see BDY description in the User Manual).
-
-namelist_trc
-------------
-
-Here below the description of namelist_trc_ref used to handle Carbon tracers modules, namely CFC and C14.
-
-|||| &'''namcfc'''     !   CFC ||
-
-|||| &'''namc14_typ'''     !  C14 - type of C14 tracer, default values of C14/C and pco2 ||
-
-|||| &'''namc14_sbc'''     !  C14 - surface BC ||
-
-|||| &'''namc14_fcg'''     !  files & dates ||
+   !               !  file name             ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+   !               !                        !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+     sn_trcdta(1)  = 'tracer_1_data'        ,        -12        ,  'TRC1'   ,    .false.   , .true. , 'yearly'  , ''       , ''       , ''
+     rf_trfac(1) = 2.0
+     cn_dir = 'usr/work/model/inputdata/'
+
+Note that, the Lateral Open Boundaries conditions are applied on
+the segments defined for the physical core of NEMO
+(see ``BDY`` description in the :doc:`Reference Manual <cite>`).
+
+:file:`namelist_trc`
+--------------------
+
+Here below the description of :file:`namelist_trc_ref` used to handle Carbon tracers modules,
+namely CFC and C14.
+
+.. literalinclude:: ../../../cfgs/SHARED/namelist_trc_ref
+   :language: fortran
+   :lines: 7,17,26,34
+   :caption: :file:`namelist_trc_ref` snippet
 
 ``MY_TRC`` interface for coupling external BGC models
 =====================================================
 
-The generalized interface is pivoted on MY_TRC module that contains template files to build the coupling between
+The generalized interface is pivoted on MY_TRC module that contains template files to
+build the coupling between
 NEMO and any external BGC model.
 
-The call to MY_TRC is activated by setting ``ln_my_trc = .true.`` (in namtrc)
+The call to MY_TRC is activated by setting ``ln_my_trc = .true.`` (in ``&namtrc``)
 
 The following 6 fortran files are available in MY_TRC with the specific purposes here described.
 
-``par_my_trc.F90``
-	This module allows to define additional arrays and public variables to be used within the MY_TRC interface
-
-``trcini_my_trc.F90``
-	Here are initialized user defined namelists and the call to the external BGC model initialization procedures to
-	populate general tracer array (trn and trb). Here are also likely to be defined suport arrays related to
-	system metrics that could be needed by the BGC model.
-
-``trcnam_my_trc.F90``
-	This routine is called at the beginning of trcini_my_trc and should contain the initialization of
-	additional namelists for the BGC model or user-defined code.
-
-``trcsms_my_trc.F90``
-	The routine performs the call to Boundary Conditions and its main purpose is to
-	contain the Source-Minus-Sinks terms due to the biogeochemical processes of the external model.
-	Be aware that lateral boundary conditions are applied in trcnxt routine.
-	IMPORTANT: the routines to compute the light penetration along the water column and
-	the tracer vertical sinking should be defined/called in here, as generalized modules are still missing in
-	the code.
-
-``trcice_my_trc.F90``
-	Here it is possible to prescribe the tracers concentrations in the seaice that will be used as
-	boundary conditions when ice melting occurs (nn_ice_tr =1 in namtrc_ice).
-	See e.g. the correspondent PISCES subroutine.
-
-``trcwri_my_trc.F90``
-	This routine performs the output of the model tracers (only those defined in namtrc) using IOM module
-	(see Manual Chapter “Output and Diagnostics”).
-	It is possible to place here the output of additional variables produced by the model,
-	if not done elsewhere in the code, using the call to iom_put.
+:file:`par_my_trc.F90`
+   This module allows to define additional arrays and public variables to
+   be used within the MY_TRC interface
+
+:file:`trcini_my_trc.F90`
+   Here are initialized user defined namelists and
+   the call to the external BGC model initialization procedures to populate general tracer array
+   (``trn`` and ``trb``).
+   Here are also likely to be defined support arrays related to system metrics that
+   could be needed by the BGC model.
+
+:file:`trcnam_my_trc.F90`
+   This routine is called at the beginning of ``trcini_my_trc`` and
+   should contain the initialization of additional namelists for the BGC model or user-defined code.
+
+:file:`trcsms_my_trc.F90`
+   The routine performs the call to Boundary Conditions and its main purpose is to
+   contain the Source-Minus-Sinks terms due to the biogeochemical processes of the external model.
+   Be aware that lateral boundary conditions are applied in trcnxt routine.
+
+   .. warning::
+      The routines to compute the light penetration along the water column and
+      the tracer vertical sinking should be defined/called in here,
+      as generalized modules are still missing in the code.
+
+:file:`trcice_my_trc.F90`
+   Here it is possible to prescribe the tracers concentrations in the sea-ice that
+   will be used as boundary conditions when ice melting occurs (``nn_ice_tr = 1`` in ``&namtrc_ice``).
+   See e.g. the correspondent PISCES subroutine.
+
+:file:`trcwri_my_trc.F90`
+   This routine performs the output of the model tracers (only those defined in ``&namtrc``) using
+   IOM module (see chapter “Output and Diagnostics” in the :doc:`Reference Manual <cite>`).
+   It is possible to place here the output of additional variables produced by the model,
+   if not done elsewhere in the code, using the call to ``iom_put``.
 
 Coupling an external BGC model using NEMO framework
@@ -273,18 +299,20 @@
 The coupling with an external BGC model through the NEMO compilation framework can be achieved in
 different ways according to the degree of coding complexity of the Biogeochemical model, like e.g.,
-the whole code is made only by one file or it has multiple modules and interfaces spread across several subfolders.
-
-Beside the 6 core files of MY_TRC module, let’s assume an external BGC model named *MYBGC* and constituted by
-a rather essential coding structure, likely few Fortran files.
+the whole code is made only by one file or
+it has multiple modules and interfaces spread across several subfolders.
+
+Beside the 6 core files of MY_TRC module, let’s assume an external BGC model named *MYBGC* and
+constituted by a rather essential coding structure, likely few Fortran files.
 The new coupled configuration name is *NEMO_MYBGC*.
 
-The best solution is to have all files (the modified ``MY_TRC`` routines and the BGC model ones) placed in
-a unique folder with root ``MYBGCPATH`` and to use the makenemo external readdressing of ``MY_SRC`` folder.
-
-The coupled configuration listed in ``work_cfgs.txt`` will look like
+The best solution is to have all files (the modified ``MY_TRC`` routines and the BGC model ones)
+placed in a unique folder with root ``MYBGCPATH`` and
+to use the makenemo external readdressing of ``MY_SRC`` folder.
+
+The coupled configuration listed in :file:`work_cfgs.txt` will look like
 
 ::
 
-	NEMO_MYBGC OPA_SRC TOP_SRC
+   NEMO_MYBGC OCE TOP
 
 and the related ``cpp_MYBGC.fcm`` content will be
@@ -292,46 +320,46 @@
 .. code-block:: perl
 
-	bld::tool::fppkeys  key_iomput key_mpp_mpi key_top
-
-the compilation with ``makenemo`` will be executed through the following syntax
+   bld::tool::fppkeys key_iomput key_mpp_mpi key_top
+
+the compilation with :file:`makenemo` will be executed through the following syntax
 
 .. code-block:: console
 
-	$ makenemo -n 'NEMO_MYBGC' -m '<arch_my_machine>' -j 8 -e '<MYBGCPATH>'
-
-The makenemo feature “-e” was introduced to readdress at compilation time the standard MY_SRC folder
-(usually found in NEMO configurations) with a user defined external one.
-
-The compilation of more articulated BGC model code & infrastructure, like in the case of BFM
-([http://www.bfm-community.eu/publications/bfmnemomanual_r1.0_201508.pdf BFM-NEMO coupling manual]),
-requires some additional features.
+   $ makenemo -n 'NEMO_MYBGC' -m '<arch_my_machine>' -j 8 -e '<MYBGCPATH>'
+
+The makenemo feature ``-e`` was introduced to
+readdress at compilation time the standard MY_SRC folder (usually found in NEMO configurations) with
+a user defined external one.
+
+The compilation of more articulated BGC model code & infrastructure,
+like in the case of BFM (|BFM man|_), requires some additional features.
 
 As before, let’s assume a coupled configuration name *NEMO_MYBGC*,
-but in this case MYBGC model root becomes ``<MYBGCPATH>`` that contains 4 different subfolders for
-biogeochemistry, named ``initialization``, ``pelagic``, and ``benthic``, and
-a separate one named ``nemo_coupling`` including the modified ``MY_SRC`` routines.
+but in this case MYBGC model root becomes :file:`MYBGC` path that
+contains 4 different subfolders for biogeochemistry,
+named :file:`initialization`, :file:`pelagic`, and :file:`benthic`,
+and a separate one named :file:`nemo_coupling` including the modified `MY_SRC` routines.
 The latter folder containing the modified NEMO coupling interface will be still linked using
-the makenemo “-e” option.
+the makenemo ``-e`` option.
 
 In order to include the BGC model subfolders in the compilation of NEMO code,
-it will be necessary to extend the configuration ``cpp_NEMO_MYBGC.fcm`` file to include the specific paths of
-``MYBGC`` folders, as in the following example
+it will be necessary to extend the configuration :file:`cpp_NEMO_MYBGC.fcm` file to include the specific paths of :file:`MYBGC` folders, as in the following example
 
 .. code-block:: perl
 
-	bld::tool::fppkeys  key_iomput key_mpp_mpi key_top
-	
-	src::MYBGC::initialization         <MYBGCPATH>/initialization
-	src::MYBGC::pelagic                <MYBGCPATH>/pelagic
-	src::MYBGC::benthic                <MYBGCPATH>/benthic
-	
-	bld::pp::MYBGC      1
-	bld::tool::fppflags::MYBGC   %FPPFLAGS
-	bld::tool::fppkeys           %bld::tool::fppkeys MYBGC_MACROS
+   bld::tool::fppkeys  key_iomput key_mpp_mpi key_top
+
+   src::MYBGC::initialization         <MYBGCPATH>/initialization
+   src::MYBGC::pelagic                <MYBGCPATH>/pelagic
+   src::MYBGC::benthic                <MYBGCPATH>/benthic
+
+   bld::pp::MYBGC      1
+   bld::tool::fppflags::MYBGC   %FPPFLAGS
+   bld::tool::fppkeys           %bld::tool::fppkeys MYBGC_MACROS
 
 where *MYBGC_MACROS* is the space delimited list of macros used in *MYBGC* model for
 selecting/excluding specific parts of the code.
-The BGC model code will be preprocessed in the configuration ``BLD`` folder as for NEMO,
-but with an independent path, like ``NEMO_MYBGC/BLD/MYBGC/<subforlders>``.
+The BGC model code will be preprocessed in the configuration :file:`BLD` folder as for NEMO,
+but with an independent path, like :file:`NEMO_MYBGC/BLD/MYBGC/<subforlders>`.
 
 The compilation will be performed similarly to in the previous case with the following
@@ -339,20 +367,26 @@
 .. code-block:: console
 
-	$ makenemo -n 'NEMO_MYBGC' -m '<arch_my_machine>' -j 8 -e '<MYBGCPATH>/nemo_coupling'
-
-Note that, the additional lines specific for the BGC model source and build paths can be written into
-a separate file, e.g. named ``MYBGC.fcm``, and then simply included in the ``cpp_NEMO_MYBGC.fcm`` as follow
-
-.. code-block:: perl
-
-	bld::tool::fppkeys  key_zdftke key_dynspg_ts key_iomput key_mpp_mpi key_top
-	inc <MYBGCPATH>/MYBGC.fcm
-
-This will enable a more portable compilation structure for all MYBGC related configurations.
-
-**Important**: the coupling interface contained in nemo_coupling cannot be added using the FCM syntax,
-as the same files already exists in NEMO and they are overridden only with the readdressing of MY_SRC contents to
-avoid compilation conflicts due to duplicate routines.
-
-All modifications illustrated above, can be easily implemented using shell or python scripting to
-edit the NEMO configuration CPP.fcm file and to create the BGC model specific FCM compilation file with code paths.
+   $ makenemo -n 'NEMO_MYBGC' -m '<arch_my_machine>' -j 8 -e '<MYBGCPATH>/nemo_coupling'
+
+.. note::
+   The additional lines specific for the BGC model source and build paths can be written into
+   a separate file, e.g. named :file:`MYBGC.fcm`,
+   and then simply included in the :file:`cpp_NEMO_MYBGC.fcm` as follow
+
+   .. code-block:: perl
+
+      bld::tool::fppkeys  key_zdftke key_dynspg_ts key_iomput key_mpp_mpi key_top
+      inc <MYBGCPATH>/MYBGC.fcm
+
+   This will enable a more portable compilation structure for all MYBGC related configurations.
+
+.. warning::
+   The coupling interface contained in :file:`nemo_coupling` cannot be added using the FCM syntax,
+   as the same files already exists in NEMO and they are overridden only with
+   the readdressing of MY_SRC contents to avoid compilation conflicts due to duplicate routines.
+
+All modifications illustrated above, can be easily implemented using shell or python scripting
+to edit the NEMO configuration :file:`CPP.fcm` file and
+to create the BGC model specific FCM compilation file with code paths.
+
+.. |BFM man| replace:: BFM-NEMO coupling manual
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcadv.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcadv.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcadv.F90	(revision 13463)
@@ -29,5 +29,5 @@
    USE ldfslp         ! Lateral diffusion: slopes of neutral surfaces
    !
-   USE prtctl_trc     ! control print
+   USE prtctl         ! control print
    USE timing         ! Timing
 
@@ -59,6 +59,5 @@
    INTEGER, PARAMETER ::   np_QCK     = 5   ! QUICK scheme
    
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -68,5 +67,5 @@
 CONTAINS
 
-   SUBROUTINE trc_adv( kt )
+   SUBROUTINE trc_adv( kt, Kbb, Kmm, ptr, Krhs  )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE trc_adv  ***
@@ -74,11 +73,13 @@
       !! ** Purpose :   compute the ocean tracer advection trend.
       !!
-      !! ** Method  : - Update after tracers (tra) with the advection term following nadv
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !! ** Method  : - Update after tracers (tr(Krhs)) with the advection term following nadv
+      !!----------------------------------------------------------------------
+      INTEGER                                   , INTENT(in)    :: kt   ! ocean time-step index
+      INTEGER                                   , INTENT(in)    :: Kbb, Kmm, Krhs ! time level indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) :: ptr            ! passive tracers and RHS of tracer equation
       !
       INTEGER ::   jk   ! dummy loop index
       CHARACTER (len=22) ::   charout
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zun, zvn, zwn  ! effective velocity
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zuu, zvv, zww  ! effective velocity
       !!----------------------------------------------------------------------
       !
@@ -87,34 +88,34 @@
       !                                         !==  effective transport  ==!
       IF( l_offline ) THEN
-         zun(:,:,:) = un(:,:,:)                    ! already in (un,vn,wn)
-         zvn(:,:,:) = vn(:,:,:)
-         zwn(:,:,:) = wn(:,:,:)
+         zuu(:,:,:) = uu(:,:,:,Kmm)                ! already in (uu(Kmm),vv(Kmm),ww)
+         zvv(:,:,:) = vv(:,:,:,Kmm)
+         zww(:,:,:) = ww(:,:,:)
       ELSE                                         ! build the effective transport
-         zun(:,:,jpk) = 0._wp
-         zvn(:,:,jpk) = 0._wp
-         zwn(:,:,jpk) = 0._wp
+         zuu(:,:,jpk) = 0._wp
+         zvv(:,:,jpk) = 0._wp
+         zww(:,:,jpk) = 0._wp
          IF( ln_wave .AND. ln_sdw )  THEN
             DO jk = 1, jpkm1                                                       ! eulerian transport + Stokes Drift
-               zun(:,:,jk) = e2u  (:,:) * e3u_n(:,:,jk) * ( un(:,:,jk) + usd(:,:,jk) )
-               zvn(:,:,jk) = e1v  (:,:) * e3v_n(:,:,jk) * ( vn(:,:,jk) + vsd(:,:,jk) )
-               zwn(:,:,jk) = e1e2t(:,:)                 * ( wn(:,:,jk) + wsd(:,:,jk) )
+               zuu(:,:,jk) = e2u  (:,:) * e3u(:,:,jk,Kmm) * ( uu(:,:,jk,Kmm) + usd(:,:,jk) )
+               zvv(:,:,jk) = e1v  (:,:) * e3v(:,:,jk,Kmm) * ( vv(:,:,jk,Kmm) + vsd(:,:,jk) )
+               zww(:,:,jk) = e1e2t(:,:)                   * ( ww(:,:,jk) + wsd(:,:,jk) )
             END DO
          ELSE
             DO jk = 1, jpkm1
-               zun(:,:,jk) = e2u  (:,:) * e3u_n(:,:,jk) * un(:,:,jk)                   ! eulerian transport
-               zvn(:,:,jk) = e1v  (:,:) * e3v_n(:,:,jk) * vn(:,:,jk)
-               zwn(:,:,jk) = e1e2t(:,:)                 * wn(:,:,jk)
+               zuu(:,:,jk) = e2u  (:,:) * e3u(:,:,jk,Kmm) * uu(:,:,jk,Kmm)                   ! eulerian transport
+               zvv(:,:,jk) = e1v  (:,:) * e3v(:,:,jk,Kmm) * vv(:,:,jk,Kmm)
+               zww(:,:,jk) = e1e2t(:,:)                   * ww(:,:,jk)
             END DO
          ENDIF
          !
          IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN                                 ! add z-tilde and/or vvl corrections
-            zun(:,:,:) = zun(:,:,:) + un_td(:,:,:)
-            zvn(:,:,:) = zvn(:,:,:) + vn_td(:,:,:)
+            zuu(:,:,:) = zuu(:,:,:) + un_td(:,:,:)
+            zvv(:,:,:) = zvv(:,:,:) + vn_td(:,:,:)
          ENDIF
          !
          IF( ln_ldfeiv .AND. .NOT. ln_traldf_triad )   & 
-            &              CALL ldf_eiv_trp( kt, nittrc000, zun, zvn, zwn, 'TRC' )  ! add the eiv transport
-         !
-         IF( ln_mle    )   CALL tra_mle_trp( kt, nittrc000, zun, zvn, zwn, 'TRC' )  ! add the mle transport
+            &              CALL ldf_eiv_trp( kt, nittrc000, zuu, zvv, zww, 'TRC', Kmm, Krhs )  ! add the eiv transport
+         !
+         IF( ln_mle    )   CALL tra_mle_trp( kt, nittrc000, zuu, zvv, zww, 'TRC', Kmm       )  ! add the mle transport
          !
       ENDIF
@@ -123,20 +124,20 @@
       !
       CASE ( np_CEN )                                 ! Centered : 2nd / 4th order
-         CALL tra_adv_cen( kt, nittrc000,'TRC',          zun, zvn, zwn     , trn, tra, jptra, nn_cen_h, nn_cen_v )
+         CALL tra_adv_cen( kt, nittrc000,'TRC',          zuu, zvv, zww,      Kmm, ptr, jptra, Krhs, nn_cen_h, nn_cen_v )
       CASE ( np_FCT )                                 ! FCT      : 2nd / 4th order
-         CALL tra_adv_fct( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb, trn, tra, jptra, nn_fct_h, nn_fct_v )
+         CALL tra_adv_fct( kt, nittrc000,'TRC', rDt_trc, zuu, zvv, zww, Kbb, Kmm, ptr, jptra, Krhs, nn_fct_h, nn_fct_v )
       CASE ( np_MUS )                                 ! MUSCL
-         CALL tra_adv_mus( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb,      tra, jptra        , ln_mus_ups ) 
+         CALL tra_adv_mus( kt, nittrc000,'TRC', rDt_trc, zuu, zvv, zww, Kbb, Kmm, ptr, jptra, Krhs, ln_mus_ups         ) 
       CASE ( np_UBS )                                 ! UBS
-         CALL tra_adv_ubs( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb, trn, tra, jptra          , nn_ubs_v )
+         CALL tra_adv_ubs( kt, nittrc000,'TRC', rDt_trc, zuu, zvv, zww, Kbb, Kmm, ptr, jptra, Krhs, nn_ubs_v           )
       CASE ( np_QCK )                                 ! QUICKEST
-         CALL tra_adv_qck( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb, trn, tra, jptra                     )
+         CALL tra_adv_qck( kt, nittrc000,'TRC', rDt_trc, zuu, zvv, zww, Kbb, Kmm, ptr, jptra, Krhs                     )
       !
       END SELECT
       !                  
-      IF( ln_ctl ) THEN                         !== print mean trends (used for debugging)
+      IF( sn_cfctl%l_prttrc ) THEN        !== print mean trends (used for debugging)
          WRITE(charout, FMT="('adv ')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl( tab4d_1=tr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm, clinfo3='trd' )
       END IF
       !
@@ -164,10 +165,8 @@
       !
       !                                !==  Namelist  ==!
-      REWIND( numnat_ref )                   !  namtrc_adv in reference namelist 
       READ  ( numnat_ref, namtrc_adv, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_adv in reference namelist', lwp )
-      REWIND( numnat_cfg )                   ! namtrc_adv in configuration namelist
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_adv in reference namelist' )
       READ  ( numnat_cfg, namtrc_adv, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_adv in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_adv in configuration namelist' )
       IF(lwm) WRITE ( numont, namtrc_adv )
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcatf.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcatf.F90	(revision 13463)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcatf.F90	(revision 13463)
@@ -0,0 +1,359 @@
+MODULE trcatf
+   !!======================================================================
+   !!                       ***  MODULE  trcatf  ***
+   !! Ocean passive tracers:  time stepping on passives tracers
+   !!======================================================================
+   !! History :  7.0  !  1991-11  (G. Madec)  Original code
+   !!                 !  1993-03  (M. Guyon)  symetrical conditions
+   !!                 !  1995-02  (M. Levy)   passive tracers
+   !!                 !  1996-02  (G. Madec & M. Imbard)  opa release 8.0
+   !!            8.0  !  1996-04  (A. Weaver)  Euler forward step
+   !!            8.2  !  1999-02  (G. Madec, N. Grima)  semi-implicit pressure grad.
+   !!  NEMO      1.0  !  2002-08  (G. Madec)  F90: Free form and module
+   !!                 !  2002-08  (G. Madec)  F90: Free form and module
+   !!                 !  2002-11  (C. Talandier, A-M Treguier) Open boundaries
+   !!                 !  2004-03  (C. Ethe) passive tracers
+   !!                 !  2007-02  (C. Deltel) Diagnose ML trends for passive tracers
+   !!            2.0  !  2006-02  (L. Debreu, C. Mazauric) Agrif implementation
+   !!            3.0  !  2008-06  (G. Madec)  time stepping always done in trazdf
+   !!            3.1  !  2009-02  (G. Madec, R. Benshila)  re-introduce the vvl option
+   !!            3.3  !  2010-06  (C. Ethe, G. Madec) Merge TRA-TRC
+   !!            4.1  !  2019-08  (A. Coward, D. Storkey) rename trcnxt.F90 -> trcatf.F90. Now only does time filtering.
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_atf     : time stepping on passive tracers
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! ocean dynamics and tracers variables
+   USE trc             ! ocean passive tracers variables
+   USE trd_oce
+   USE trdtra
+# if defined key_qco
+   USE traatfqco
+# else
+   USE traatf
+# endif
+   USE bdy_oce   , ONLY: ln_bdy
+   USE trcbdy          ! BDY open boundaries
+# if defined key_agrif
+   USE agrif_top_interp
+# endif
+   !
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl          ! Print control for debbuging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_atf   ! routine called by step.F90
+
+   REAL(wp) ::   rfact1, rfact2
+
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
+   !! $Id$ 
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trc_atf( kt, Kbb, Kmm, Kaa, ptr )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE trcatf  ***
+      !!
+      !! ** Purpose :   Apply the boundary condition on the after passive tracers fields and
+      !!      apply Asselin time filter to the now passive tracer fields if using leapfrog timestep
+      !! 
+      !! ** Method  :   Apply lateral boundary conditions on (uu(Kaa),vv(Kaa)) through 
+      !!      call to lbc_lnk routine
+      !!
+      !!   For Arakawa or TVD Scheme : 
+      !!      A Asselin time filter applied on now tracers tr(Kmm) to avoid
+      !!      the divergence of two consecutive time-steps and tr arrays
+      !!      to prepare the next time_step:
+      !!         (tr(Kmm)) = (tr(Kmm)) + rn_atfp [ (tr(Kbb)) + (tr(Kaa)) - 2 (tr(Kmm)) ]
+      !!
+      !!
+      !! ** Action  : - update tr(Kmm), tr(Kaa)
+      !!----------------------------------------------------------------------
+      INTEGER                                   , INTENT( in )  :: kt             ! ocean time-step index
+      INTEGER                                   , INTENT( in )  :: Kbb, Kmm, Kaa ! time level indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) :: ptr            ! passive tracers
+      !
+      INTEGER  ::   jk, jn   ! dummy loop indices
+      REAL(wp) ::   zfact            ! temporary scalar
+      CHARACTER (len=22) :: charout
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::   ztrdt    ! 4D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('trc_atf')
+      !
+      IF( kt == nittrc000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trc_atf : Asselin time filtering on passive tracers'
+      ENDIF
+      !
+#if defined key_agrif
+      CALL Agrif_trc                   ! AGRIF zoom boundaries
+#endif
+      ! Update after tracer on domain lateral boundaries
+      CALL lbc_lnk( 'trcatf', ptr(:,:,:,:,Kaa), 'T', 1. )   
+
+      IF( ln_bdy )  CALL trc_bdy( kt, Kbb, Kmm, Kaa )
+
+      IF( l_trdtrc )  THEN             ! trends: store now fields before the Asselin filter application
+         ALLOCATE( ztrdt(jpi,jpj,jpk,jptra) )
+         ztrdt(:,:,:,:)  = 0._wp
+         IF( ln_traldf_iso ) THEN                       ! diagnose the "pure" Kz diffusive trend 
+            DO jn = 1, jptra
+               CALL trd_tra( kt, Kmm, Kaa, 'TRC', jn, jptra_zdfp, ztrdt(:,:,:,jn) )
+            ENDDO
+         ENDIF
+
+         ! total trend for the non-time-filtered variables. 
+         zfact = 1.0 / rn_Dt
+         ! G Nurser 23 Mar 2017. Recalculate trend as Delta(e3ta*Ta)/e3tn; e3tn cancel from ts(Kmm) terms
+         IF( ln_linssh ) THEN       ! linear sea surface height only
+            DO jn = 1, jptra
+               DO jk = 1, jpkm1
+                  ztrdt(:,:,jk,jn) = ( ptr(:,:,jk,jn,Kaa)*e3t(:,:,jk,Kaa) / e3t(:,:,jk,Kmm) - ptr(:,:,jk,jn,Kmm)) * zfact
+               END DO
+            END DO
+         ELSE
+            DO jn = 1, jptra
+               DO jk = 1, jpkm1
+                  ztrdt(:,:,jk,jn) = ( ptr(:,:,jk,jn,Kaa) - ptr(:,:,jk,jn,Kmm) ) * zfact
+               END DO
+            END DO
+         ENDIF
+         !
+         DO jn = 1, jptra
+            CALL trd_tra( kt, Kmm, Kaa, 'TRC', jn, jptra_tot, ztrdt(:,:,:,jn) )
+         ENDDO
+         !
+         IF( ln_linssh ) THEN       ! linear sea surface height only
+            ! Store now fields before applying the Asselin filter 
+            ! in order to calculate Asselin filter trend later.
+            ztrdt(:,:,:,:) = ptr(:,:,:,:,Kmm) 
+         ENDIF
+
+      ENDIF
+      !                                ! Leap-Frog + Asselin filter time stepping
+      IF( l_1st_euler .OR. ln_top_euler ) THEN    ! Euler time-stepping 
+         !
+         IF (l_trdtrc .AND. .NOT. ln_linssh ) THEN   ! Zero Asselin filter contribution must be explicitly written out since for vvl
+            !                                        ! Asselin filter is output by tra_nxt_vvl that is not called on this time step
+            ztrdt(:,:,:,:) = 0._wp            
+            DO jn = 1, jptra
+               CALL trd_tra( kt, Kmm, Kaa, 'TRC', jn, jptra_atf, ztrdt(:,:,:,jn) )
+            ENDDO
+         END IF
+         !
+      ELSE     
+         IF( .NOT. l_offline ) THEN ! Leap-Frog + Asselin filter time stepping
+# if defined key_qco
+            IF( ln_linssh ) THEN   ;   CALL tra_atf_fix_lf( kt, Kbb, Kmm, Kaa, nittrc000,        'TRC', ptr, jptra )                     !     linear ssh
+            ELSE                   ;   CALL tra_atf_qco_lf( kt, Kbb, Kmm, Kaa, nittrc000, rn_Dt, 'TRC', ptr, sbc_trc, sbc_trc_b, jptra ) ! non-linear ssh
+# else
+            IF( ln_linssh ) THEN   ;   CALL tra_atf_fix( kt, Kbb, Kmm, Kaa, nittrc000,         'TRC', ptr, jptra )                     !     linear ssh
+            ELSE                   ;   CALL tra_atf_vvl( kt, Kbb, Kmm, Kaa, nittrc000, rn_Dt, 'TRC', ptr, sbc_trc, sbc_trc_b, jptra ) ! non-linear ssh
+# endif
+            ENDIF
+         ELSE
+                                       CALL trc_atf_off( kt, Kbb, Kmm, Kaa, ptr )       ! offline 
+         ENDIF
+         !
+         CALL lbc_lnk_multi( 'trcatf', ptr(:,:,:,:,Kmm), 'T', 1._wp, ptr(:,:,:,:,Kaa), 'T', 1._wp, ptr(:,:,:,:,Kaa), 'T', 1._wp )
+      ENDIF
+      !
+      IF( l_trdtrc .AND. ln_linssh ) THEN      ! trend of the Asselin filter (tb filtered - tb)/dt )
+         DO jn = 1, jptra
+            DO jk = 1, jpkm1
+               zfact = 1._wp / rDt_trc  
+               ztrdt(:,:,jk,jn) = ( ptr(:,:,jk,jn,Kbb) - ztrdt(:,:,jk,jn) ) * zfact 
+            END DO
+            CALL trd_tra( kt, Kmm, Kaa, 'TRC', jn, jptra_atf, ztrdt(:,:,:,jn) )
+         END DO
+      END IF
+      IF( l_trdtrc ) DEALLOCATE( ztrdt ) 
+      !
+      IF(sn_cfctl%l_prttrc)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('nxt')")
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl(tab4d_1=ptr(:,:,:,:,Kmm), mask1=tmask, clinfo=ctrcnm)
+      ENDIF
+      !
+      IF( ln_timing )   CALL timing_stop('trc_atf')
+      !
+   END SUBROUTINE trc_atf
+
+# if ! defined key_qco
+   SUBROUTINE trc_atf_off( kt, Kbb, Kmm, Kaa, ptr )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tra_atf_off  ***
+      !!
+      !!          !!!!!!!!!!!!!!!!! REWRITE HEADER COMMENTS !!!!!!!!!!!!!!
+      !!
+      !! ** Purpose :   Time varying volume: apply the Asselin time filter  
+      !! 
+      !! ** Method  : - Apply a thickness weighted Asselin time filter on now fields.
+      !!              - save in (ta,sa) a thickness weighted average over the three 
+      !!             time levels which will be used to compute rdn and thus the semi-
+      !!             implicit hydrostatic pressure gradient (ln_dynhpg_imp = T)
+      !!              - swap tracer fields to prepare the next time_step.
+      !!                This can be summurized for tempearture as:
+      !!             ztm = ( e3t_n*tn + rbcp*[ e3t_b*tb - 2 e3t_n*tn + e3t_a*ta ] )   ln_dynhpg_imp = T
+      !!                  /( e3t(:,:,jk,Kmm)    + rbcp*[ e3t(:,:,jk,Kbb)    - 2 e3t(:,:,jk,Kmm)    + e3t(:,:,jk,Kaa)    ] )   
+      !!             ztm = 0                                                       otherwise
+      !!             tb  = ( e3t_n*tn + rn_atfp*[ e3t_b*tb - 2 e3t_n*tn + e3t_a*ta ] )
+      !!                  /( e3t(:,:,jk,Kmm)    + rn_atfp*[ e3t(:,:,jk,Kbb)    - 2 e3t(:,:,jk,Kmm)    + e3t(:,:,jk,Kaa)    ] )
+      !!             tn  = ta 
+      !!             ta  = zt        (NB: reset to 0 after eos_bn2 call)
+      !!
+      !! ** Action  : - (tb,sb) and (tn,sn) ready for the next time step
+      !!              - (ta,sa) time averaged (t,s)   (ln_dynhpg_imp = T)
+      !!----------------------------------------------------------------------
+      INTEGER                                   , INTENT(in   ) ::  kt            ! ocean time-step index
+      INTEGER                                   , INTENT(in   ) ::  Kbb, Kmm, Kaa ! time level indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) ::  ptr           ! passive tracers
+      !!     
+      INTEGER  ::   ji, jj, jk, jn              ! dummy loop indices
+      REAL(wp) ::   ztc_a , ztc_n , ztc_b , ztc_f , ztc_d    ! local scalar
+      REAL(wp) ::   ze3t_b, ze3t_n, ze3t_a, ze3t_f, ze3t_d   !   -      -
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nittrc000 )  THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc_atf_off : Asselin time filtering'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+         IF( .NOT. ln_linssh ) THEN
+            rfact1 = rn_atfp * rn_Dt
+            rfact2 = rfact1 / rho0
+         ENDIF
+        !  
+      ENDIF
+      !
+      DO jn = 1, jptra      
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+            ze3t_b = e3t(ji,jj,jk,Kbb)
+            ze3t_n = e3t(ji,jj,jk,Kmm)
+            ze3t_a = e3t(ji,jj,jk,Kaa)
+            !                                         ! tracer content at Before, now and after
+            ztc_b  = ptr(ji,jj,jk,jn,Kbb)  * ze3t_b
+            ztc_n  = ptr(ji,jj,jk,jn,Kmm)  * ze3t_n
+            ztc_a  = ptr(ji,jj,jk,jn,Kaa) * ze3t_a
+            !
+            ze3t_d = ze3t_a - 2. * ze3t_n + ze3t_b
+            ztc_d  = ztc_a  - 2. * ztc_n  + ztc_b
+            !
+            ze3t_f = ze3t_n + rn_atfp * ze3t_d
+            ztc_f  = ztc_n  + rn_atfp * ztc_d
+            !
+            IF( .NOT. ln_linssh .AND. jk == mikt(ji,jj) ) THEN           ! first level 
+               ze3t_f = ze3t_f - rfact2 * ( emp_b(ji,jj)      - emp(ji,jj)   ) 
+               ztc_f  = ztc_f  - rfact1 * ( sbc_trc(ji,jj,jn) - sbc_trc_b(ji,jj,jn) )
+            ENDIF
+
+            ze3t_f = 1.e0 / ze3t_f
+            ptr(ji,jj,jk,jn,Kmm) = ztc_f * ze3t_f     ! time filtered "now" field
+            !
+         END_3D
+         ! 
+      END DO
+      !
+   END SUBROUTINE trc_atf_off
+# else
+   SUBROUTINE trc_atf_off( kt, Kbb, Kmm, Kaa, ptr )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tra_atf_off  ***
+      !!
+      !!          !!!!!!!!!!!!!!!!! REWRITE HEADER COMMENTS !!!!!!!!!!!!!!
+      !!
+      !! ** Purpose :   Time varying volume: apply the Asselin time filter  
+      !! 
+      !! ** Method  : - Apply a thickness weighted Asselin time filter on now fields.
+      !!              - save in (ta,sa) a thickness weighted average over the three 
+      !!             time levels which will be used to compute rdn and thus the semi-
+      !!             implicit hydrostatic pressure gradient (ln_dynhpg_imp = T)
+      !!              - swap tracer fields to prepare the next time_step.
+      !!                This can be summurized for tempearture as:
+      !!             ztm = ( e3t_n*tn + rbcp*[ e3t_b*tb - 2 e3t_n*tn + e3t_a*ta ] )   ln_dynhpg_imp = T
+      !!                  /( e3t(:,:,jk,Kmm)    + rbcp*[ e3t(:,:,jk,Kbb)    - 2 e3t(:,:,jk,Kmm)    + e3t(:,:,jk,Kaa)    ] )   
+      !!             ztm = 0                                                       otherwise
+      !!             tb  = ( e3t_n*tn + rn_atfp*[ e3t_b*tb - 2 e3t_n*tn + e3t_a*ta ] )
+      !!                  /( e3t(:,:,jk,Kmm)    + rn_atfp*[ e3t(:,:,jk,Kbb)    - 2 e3t(:,:,jk,Kmm)    + e3t(:,:,jk,Kaa)    ] )
+      !!             tn  = ta 
+      !!             ta  = zt        (NB: reset to 0 after eos_bn2 call)
+      !!
+      !! ** Action  : - (tb,sb) and (tn,sn) ready for the next time step
+      !!              - (ta,sa) time averaged (t,s)   (ln_dynhpg_imp = T)
+      !!----------------------------------------------------------------------
+      INTEGER                                   , INTENT(in   ) ::  kt            ! ocean time-step index
+      INTEGER                                   , INTENT(in   ) ::  Kbb, Kmm, Kaa ! time level indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) ::  ptr           ! passive tracers
+      !!     
+      INTEGER  ::   ji, jj, jk, jn              ! dummy loop indices
+      REAL(wp) ::   ztc_a , ztc_n , ztc_b , ztc_f , ztc_d    ! local scalar
+      REAL(wp) ::   ze3t_b, ze3t_n, ze3t_a, ze3t_f           !   -      -
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nittrc000 )  THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc_atf_off : Asselin time filtering'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+         IF( .NOT. ln_linssh ) THEN
+            rfact1 = rn_atfp * rn_Dt
+            rfact2 = rfact1 / rho0
+         ENDIF
+        !  
+      ENDIF
+      !
+      DO jn = 1, jptra      
+         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+            ze3t_b = 1._wp + r3t(ji,jj,Kbb) * tmask(ji,jj,jk)
+            ze3t_n = 1._wp + r3t(ji,jj,Kmm) * tmask(ji,jj,jk)
+            ze3t_a = 1._wp + r3t(ji,jj,Kaa) * tmask(ji,jj,jk)
+            !                                         ! tracer content at Before, now and after
+            ztc_b  = ptr(ji,jj,jk,jn,Kbb) * ze3t_b
+            ztc_n  = ptr(ji,jj,jk,jn,Kmm) * ze3t_n
+            ztc_a  = ptr(ji,jj,jk,jn,Kaa) * ze3t_a
+            !
+            ztc_d  = ztc_a  - 2. * ztc_n  + ztc_b
+            !
+            ze3t_f = 1._wp + r3t_f(ji,jj)*tmask(ji,jj,jk)
+            ztc_f  = ztc_n  + rn_atfp * ztc_d
+            !
+            IF( .NOT. ln_linssh .AND. jk == mikt(ji,jj) ) THEN           ! first level 
+               ztc_f  = ztc_f  - rfact1 * ( sbc_trc(ji,jj,jn) - sbc_trc_b(ji,jj,jn) )
+            ENDIF
+
+            ze3t_f = 1.e0 / ze3t_f
+            ptr(ji,jj,jk,jn,Kmm) = ztc_f * ze3t_f     ! time filtered "now" field
+            !
+         END_3D
+         ! 
+      END DO
+      !
+   END SUBROUTINE trc_atf_off
+# endif
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Empty module
+   !!----------------------------------------------------------------------
+   USE par_oce
+   USE par_trc
+CONTAINS
+   SUBROUTINE trc_atf( kt, Kbb, Kmm, Kaa, ptr )  
+      INTEGER                                   , INTENT(in)    :: kt
+      INTEGER,                                    INTENT(in   ) :: Kbb, Kmm, Kaa ! time level indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) :: ptr           ! passive tracers and RHS of tracer equation
+      WRITE(*,*) 'trc_atf: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_atf
+#endif
+   !!======================================================================
+END MODULE trcatf
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcbbl.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcbbl.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcbbl.F90	(revision 13463)
@@ -20,10 +20,10 @@
    !!    trc_bbl      : update the tracer trends due to the bottom boundary layer (advective and/or diffusive)
    !!----------------------------------------------------------------------
-   USE oce_trc        ! ocean dynamics and active tracers variables
+   USE oce_trc        ! ocean dynamics and passive tracers variables
    USE trc            ! ocean passive tracers variables
    USE trd_oce        ! trends: ocean variables
    USE trdtra         ! tracer trends
    USE trabbl         ! bottom boundary layer 
-   USE prtctl_trc     ! Print control for debbuging
+   USE prtctl         ! Print control for debbuging
 
    PUBLIC   trc_bbl   !  routine called by trctrp.F90
@@ -36,5 +36,5 @@
 CONTAINS
 
-   SUBROUTINE trc_bbl( kt )
+   SUBROUTINE trc_bbl( kt, Kbb, Kmm, ptr, Krhs )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE bbl  ***
@@ -45,5 +45,7 @@
       !!
       !!----------------------------------------------------------------------  
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step 
+      INTEGER,                                    INTENT( in  ) :: kt              ! ocean time-step 
+      INTEGER,                                    INTENT( in  ) :: Kbb, Kmm, Krhs  ! time level indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) :: ptr             ! passive tracers and RHS of tracer equation
       INTEGER :: jn                   ! loop index
       CHARACTER (len=22) :: charout
@@ -53,12 +55,12 @@
       IF( ln_timing )   CALL timing_start('trc_bbl')
       !
-      IF( .NOT. l_offline .AND. nn_dttrc == 1 ) THEN
-         CALL bbl( kt, nittrc000, 'TRC' )      ! Online coupling with dynamics  : Computation of bbl coef and bbl transport
-         l_bbl = .FALSE.                       ! Offline coupling with dynamics : Read bbl coef and bbl transport from input files
+      IF( .NOT. l_offline ) THEN
+         CALL bbl( kt, nittrc000, 'TRC', Kbb, Kmm )  ! Online coupling with dynamics  : Computation of bbl coef and bbl transport
+         l_bbl = .FALSE.                             ! Offline coupling with dynamics : Read bbl coef and bbl transport from input files
       ENDIF
 
       IF( l_trdtrc )  THEN
          ALLOCATE( ztrtrd(jpi,jpj,jpk,jptra) ) ! temporary save of trends
-         ztrtrd(:,:,:,:)  = tra(:,:,:,:)
+         ztrtrd(:,:,:,:)  = ptr(:,:,:,:,Krhs)
       ENDIF
 
@@ -66,8 +68,8 @@
       IF( nn_bbl_ldf == 1 ) THEN
          !
-         CALL tra_bbl_dif( trb, tra, jptra )  
-         IF( ln_ctl )   THEN
-            WRITE(charout, FMT="(' bbl_dif')")  ;  CALL prt_ctl_trc_info(charout)
-            CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
+         CALL tra_bbl_dif( ptr(:,:,:,:,Kbb), ptr(:,:,:,:,Krhs), jptra, Kmm )  
+         IF( sn_cfctl%l_prttrc )   THEN
+            WRITE(charout, FMT="(' bbl_dif')")  ;  CALL prt_ctl_info( charout, cdcomp = 'top' )
+            CALL prt_ctl( tab4d_1=ptr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm, clinfo3='trd' )
          ENDIF
          !
@@ -77,8 +79,8 @@
       IF( nn_bbl_adv /= 0 ) THEN
          !
-         CALL tra_bbl_adv( trb, tra, jptra )  
-         IF( ln_ctl )   THEN
-            WRITE(charout, FMT="(' bbl_adv')")  ;  CALL prt_ctl_trc_info(charout)
-            CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
+         CALL tra_bbl_adv( ptr(:,:,:,:,Kbb), ptr(:,:,:,:,Krhs), jptra, Kmm )  
+         IF( sn_cfctl%l_prttrc )   THEN
+            WRITE(charout, FMT="(' bbl_adv')")  ;  CALL prt_ctl_info( charout, cdcomp = 'top' )
+            CALL prt_ctl( tab4d_1=ptr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm, clinfo3='trd' )
          ENDIF
          !
@@ -87,6 +89,6 @@
       IF( l_trdtrc )   THEN                      ! save the horizontal diffusive trends for further diagnostics
         DO jn = 1, jptra
-           ztrtrd(:,:,:,jn) = tra(:,:,:,jn) - ztrtrd(:,:,:,jn)
-           CALL trd_tra( kt, 'TRC', jn, jptra_bbl, ztrtrd(:,:,:,jn) )
+           ztrtrd(:,:,:,jn) = ptr(:,:,:,jn,Krhs) - ztrtrd(:,:,:,jn)
+           CALL trd_tra( kt, Kmm, Krhs, 'TRC', jn, jptra_bbl, ztrtrd(:,:,:,jn) )
         END DO
         DEALLOCATE( ztrtrd ) ! temporary save of trends
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcdmp.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcdmp.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcdmp.F90	(revision 13463)
@@ -24,5 +24,5 @@
    !
    USE iom
-   USE prtctl_trc      ! Print control for debbuging
+   USE prtctl          ! Print control for debbuging
 
    IMPLICIT NONE
@@ -44,5 +44,6 @@
 
    !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -63,5 +64,5 @@
 
 
-   SUBROUTINE trc_dmp( kt )
+   SUBROUTINE trc_dmp( kt, Kbb, Kmm, ptr, Krhs )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE trc_dmp  ***
@@ -73,14 +74,16 @@
       !! ** Method  :   Newtonian damping towards trdta computed 
       !!      and add to the general tracer trends:
-      !!                     trn = tra + restotr * (trdta - trb)
+      !!                     tr(Kmm) = tr(Krhs) + restotr * (trdta - tr(Kbb))
       !!         The trend is computed either throughout the water column
       !!      (nlmdmptr=0) or in area of weak vertical mixing (nlmdmptr=1) or
       !!      below the well mixed layer (nlmdmptr=2)
       !!
-      !! ** Action  : - update the tracer trends tra with the newtonian 
+      !! ** Action  : - update the tracer trends tr(:,:,:,:,Krhs) with the newtonian 
       !!                damping trends.
       !!              - save the trends ('key_trdmxl_trc')
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      INTEGER,                                    INTENT(in   ) :: kt              ! ocean time-step index
+      INTEGER,                                    INTENT(in   ) :: Kbb, Kmm, Krhs  ! time level indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) :: ptr             ! passive tracers and RHS of tracer equation
       !
       INTEGER ::   ji, jj, jk, jn, jl   ! dummy loop indices
@@ -100,43 +103,31 @@
          DO jn = 1, jptra                                           ! tracer loop
             !                                                       ! ===========
-            IF( l_trdtrc ) ztrtrd(:,:,:) = tra(:,:,:,jn)    ! save trends 
+            IF( l_trdtrc ) ztrtrd(:,:,:) = ptr(:,:,:,jn,Krhs)    ! save trends 
             !
             IF( ln_trc_ini(jn) ) THEN      ! update passive tracers arrays with input data read from file
                !
                jl = n_trc_index(jn) 
-               CALL trc_dta( kt, sf_trcdta(jl), rf_trfac(jl), ztrcdta )   ! read tracer data at nit000
+               CALL trc_dta( kt, Kmm, sf_trcdta(jl), rf_trfac(jl), ztrcdta )   ! read tracer data at nit000
                !
                SELECT CASE ( nn_zdmp_tr )
                !
                CASE( 0 )                !==  newtonian damping throughout the water column  ==!
-                  DO jk = 1, jpkm1
-                     DO jj = 2, jpjm1
-                        DO ji = fs_2, fs_jpim1   ! vector opt.
-                           tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + restotr(ji,jj,jk) * ( ztrcdta(ji,jj,jk) - trb(ji,jj,jk,jn) )
-                        END DO
-                     END DO
-                  END DO
+                  DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+                     ptr(ji,jj,jk,jn,Krhs) = ptr(ji,jj,jk,jn,Krhs) + restotr(ji,jj,jk) * ( ztrcdta(ji,jj,jk) - ptr(ji,jj,jk,jn,Kbb) )
+                  END_3D
                   !
                CASE ( 1 )                !==  no damping in the turbocline (avt > 5 cm2/s)  ==!
-                  DO jk = 1, jpkm1
-                     DO jj = 2, jpjm1
-                        DO ji = fs_2, fs_jpim1   ! vector opt.
-                           IF( avt(ji,jj,jk) <= avt_c )  THEN 
-                              tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + restotr(ji,jj,jk) * ( ztrcdta(ji,jj,jk) - trb(ji,jj,jk,jn) )
-                           ENDIF
-                        END DO
-                     END DO
-                  END DO
+                  DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+                     IF( avt(ji,jj,jk) <= avt_c )  THEN 
+                        ptr(ji,jj,jk,jn,Krhs) = ptr(ji,jj,jk,jn,Krhs) + restotr(ji,jj,jk) * ( ztrcdta(ji,jj,jk) - ptr(ji,jj,jk,jn,Kbb) )
+                     ENDIF
+                  END_3D
                   !
                CASE ( 2 )               !==  no damping in the mixed layer   ==! 
-                  DO jk = 1, jpkm1
-                     DO jj = 2, jpjm1
-                        DO ji = fs_2, fs_jpim1   ! vector opt.
-                           IF( gdept_n(ji,jj,jk) >= hmlp (ji,jj) ) THEN
-                              tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + restotr(ji,jj,jk) * ( ztrcdta(ji,jj,jk) - trb(ji,jj,jk,jn) )
-                           END IF
-                        END DO
-                     END DO
-                  END DO
+                  DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+                     IF( gdept(ji,jj,jk,Kmm) >= hmlp (ji,jj) ) THEN
+                        ptr(ji,jj,jk,jn,Krhs) = ptr(ji,jj,jk,jn,Krhs) + restotr(ji,jj,jk) * ( ztrcdta(ji,jj,jk) - ptr(ji,jj,jk,jn,Kbb) )
+                     END IF
+                  END_3D
                   !  
                END SELECT
@@ -145,6 +136,6 @@
             !
             IF( l_trdtrc ) THEN
-               ztrtrd(:,:,:) = tra(:,:,:,jn) -  ztrtrd(:,:,:)
-               CALL trd_tra( kt, 'TRC', jn, jptra_dmp, ztrtrd )
+               ztrtrd(:,:,:) = ptr(:,:,:,jn,Krhs) -  ztrtrd(:,:,:)
+               CALL trd_tra( kt, Kmm, Krhs, 'TRC', jn, jptra_dmp, ztrtrd )
             END IF
             !                                                       ! ===========
@@ -156,8 +147,8 @@
       IF( l_trdtrc )  DEALLOCATE( ztrtrd )
       !                                          ! print mean trends (used for debugging)
-      IF( ln_ctl ) THEN
+      IF( sn_cfctl%l_prttrc ) THEN
          WRITE(charout, FMT="('dmp ')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl( tab4d_1=ptr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm, clinfo3='trd' )
       ENDIF
       !
@@ -181,10 +172,8 @@
       !!----------------------------------------------------------------------
       !
-      REWIND( numnat_ref )              ! Namelist namtrc_dmp in reference namelist : Passive tracers newtonian damping
       READ  ( numnat_ref, namtrc_dmp, IOSTAT = ios, ERR = 909)
-909   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_dmp in reference namelist', lwp )
-      REWIND( numnat_cfg )              ! Namelist namtrc_dmp in configuration namelist : Passive tracers newtonian damping
+909   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_dmp in reference namelist' )
       READ  ( numnat_cfg, namtrc_dmp, IOSTAT = ios, ERR = 910)
-910   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_dmp in configuration namelist', lwp )
+910   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_dmp in configuration namelist' )
       IF(lwm) WRITE ( numont, namtrc_dmp )
 
@@ -216,5 +205,5 @@
          !Read in mask from file
          CALL iom_open ( cn_resto_tr, imask)
-         CALL iom_get  ( imask, jpdom_autoglo, 'resto', restotr)
+         CALL iom_get  ( imask, jpdom_auto, 'resto', restotr)
          CALL iom_close( imask )
          !
@@ -224,5 +213,5 @@
 
 
-   SUBROUTINE trc_dmp_clo( kt )
+   SUBROUTINE trc_dmp_clo( kt, Kbb, Kmm )
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE trc_dmp_clo  ***
@@ -236,5 +225,6 @@
       !!                nctsi2(), nctsj2() : north-east Closed sea limits (i,j)
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      INTEGER, INTENT( in ) ::   kt           ! ocean time-step index
+      INTEGER, INTENT( in ) ::   Kbb, Kmm     ! time level indices
       !
       INTEGER :: ji , jj, jk, jn, jl, jc                    ! dummy loop indicesa
@@ -256,32 +246,33 @@
             !                                           ! =======================
             CASE ( 1 )                                  ! eORCA_R1 configuration
-            !                                           ! =======================
-            isrow = 332 - jpjglo
-            !
-            nctsi1(1)   = 333  ; nctsj1(1)   = 243 - isrow   ! Caspian Sea
-            nctsi2(1)   = 342  ; nctsj2(1)   = 274 - isrow
-            !                                        
-            nctsi1(2)   = 198  ; nctsj1(2)   = 258 - isrow   ! Lake Superior
-            nctsi2(2)   = 204  ; nctsj2(2)   = 262 - isrow
-            !                                         
-            nctsi1(3)   = 201  ; nctsj1(3)   = 250 - isrow   ! Lake Michigan
-            nctsi2(3)   = 203  ; nctsj2(3)   = 256 - isrow
-            !                                        
-            nctsi1(4)   = 204  ; nctsj1(4)   = 252 - isrow   ! Lake Huron
-            nctsi2(4)   = 209  ; nctsj2(4)   = 256 - isrow
-            !                                        
-            nctsi1(5)   = 206  ; nctsj1(5)   = 249 - isrow   ! Lake Erie
-            nctsi2(5)   = 209  ; nctsj2(5)   = 251 - isrow
-            !                                        
-            nctsi1(6)   = 210  ; nctsj1(6)   = 252 - isrow   ! Lake Ontario
-            nctsi2(6)   = 212  ; nctsj2(6)   = 252 - isrow
-            !                                        
-            nctsi1(7)   = 321  ; nctsj1(7)   = 180 - isrow   ! Victoria Lake
-            nctsi2(7)   = 322  ; nctsj2(7)   = 189 - isrow
-            !                                        
-            nctsi1(8)   = 297  ; nctsj1(8)   = 270 - isrow   ! Baltic Sea
-            nctsi2(8)   = 308  ; nctsj2(8)   = 293 - isrow
-            !                                        
-            !                                           ! =======================
+               !                                        ! =======================
+               !
+               isrow = 332 - (Nj0glo + 1)   ! was 332 - jpjglo -> jpjglo_old_version = Nj0glo + 1
+               !
+               nctsi1(1)   = 333  ; nctsj1(1)   = 243 - isrow   ! Caspian Sea
+               nctsi2(1)   = 342  ; nctsj2(1)   = 274 - isrow
+               !                                        
+               nctsi1(2)   = 198  ; nctsj1(2)   = 258 - isrow   ! Lake Superior
+               nctsi2(2)   = 204  ; nctsj2(2)   = 262 - isrow
+               !                                         
+               nctsi1(3)   = 201  ; nctsj1(3)   = 250 - isrow   ! Lake Michigan
+               nctsi2(3)   = 203  ; nctsj2(3)   = 256 - isrow
+               !                                        
+               nctsi1(4)   = 204  ; nctsj1(4)   = 252 - isrow   ! Lake Huron
+               nctsi2(4)   = 209  ; nctsj2(4)   = 256 - isrow
+               !                                        
+               nctsi1(5)   = 206  ; nctsj1(5)   = 249 - isrow   ! Lake Erie
+               nctsi2(5)   = 209  ; nctsj2(5)   = 251 - isrow
+               !                                        
+               nctsi1(6)   = 210  ; nctsj1(6)   = 252 - isrow   ! Lake Ontario
+               nctsi2(6)   = 212  ; nctsj2(6)   = 252 - isrow
+               !                                        
+               nctsi1(7)   = 321  ; nctsj1(7)   = 180 - isrow   ! Victoria Lake
+               nctsi2(7)   = 322  ; nctsj2(7)   = 189 - isrow
+               !                                        
+               nctsi1(8)   = 297  ; nctsj1(8)   = 270 - isrow   ! Baltic Sea
+               nctsi2(8)   = 308  ; nctsj2(8)   = 293 - isrow
+               !
+               !                                        ! =======================
             CASE ( 2 )                                  !  ORCA_R2 configuration
                !                                        ! =======================
@@ -296,9 +287,10 @@
                nctsi2(3)   = 181  ;  nctsj2(3)   = 112
               !                                      
-               nctsi1(4)   =   2  ;  nctsj1(4)   = 107      ! Black Sea 2 : est part of the Black Sea
+               nctsi1(4)   =   2  ;  nctsj1(4)   = 107       ! Black Sea 2 : est part of the Black Sea
                nctsi2(4)   =   6  ;  nctsj2(4)   = 112
                !                                     
                nctsi1(5)   =  145 ;  nctsj1(5)   = 116       ! Baltic Sea
                nctsi2(5)   =  150 ;  nctsj2(5)   = 126
+               !
                !                                        ! =======================
             CASE ( 4 )                                  !  ORCA_R4 configuration
@@ -316,4 +308,5 @@
                nctsi1(4)   = 75  ;  nctsj1(4)   = 59         ! Baltic Sea
                nctsi2(4)   = 76  ;  nctsj2(4)   = 61
+               !
                !                                        ! =======================
             CASE ( 025 )                                ! ORCA_R025 configuration
@@ -330,4 +323,7 @@
          ENDIF
          !
+         nctsi1(:) = nctsi1(:) + nn_hls - 1   ;   nctsi2(:) = nctsi2(:) + nn_hls - 1   ! -1 as x-perio included in old input files
+         nctsj1(:) = nctsj1(:) + nn_hls       ;   nctsj2(:) = nctsj2(:) + nn_hls
+         !
          ! convert the position in local domain indices
          ! --------------------------------------------
@@ -354,11 +350,11 @@
             IF( ln_trc_ini(jn) ) THEN      ! update passive tracers arrays with input data read from file
                 jl = n_trc_index(jn)
-                CALL trc_dta( kt, sf_trcdta(jl), rf_trfac(jl), ztrcdta )   ! read tracer data at nit000
+                CALL trc_dta( kt, Kmm, sf_trcdta(jl), rf_trfac(jl), ztrcdta )   ! read tracer data at nit000
                 DO jc = 1, npncts
                    DO jk = 1, jpkm1
                       DO jj = nctsj1(jc), nctsj2(jc)
                          DO ji = nctsi1(jc), nctsi2(jc)
-                            trn(ji,jj,jk,jn) = ztrcdta(ji,jj,jk)
-                            trb(ji,jj,jk,jn) = trn(ji,jj,jk,jn)
+                            tr(ji,jj,jk,jn,Kmm) = ztrcdta(ji,jj,jk)
+                            tr(ji,jj,jk,jn,Kbb) = tr(ji,jj,jk,jn,Kmm)
                          END DO
                       END DO
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcldf.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcldf.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcldf.F90	(revision 13463)
@@ -25,5 +25,5 @@
    USE trdtra         ! trends manager: tracers
    !
-   USE prtctl_trc     ! Print control
+   USE prtctl         ! Print control
 
    IMPLICIT NONE
@@ -43,5 +43,6 @@
    
    !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -51,5 +52,5 @@
 CONTAINS
 
-   SUBROUTINE trc_ldf( kt )
+   SUBROUTINE trc_ldf( kt, Kbb, Kmm, ptr, Krhs )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE tra_ldf  ***
@@ -58,11 +59,13 @@
       !!
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      INTEGER,                                    INTENT(in   ) :: kt              ! ocean time-step index
+      INTEGER,                                    INTENT(in   ) :: Kbb, Kmm, Krhs  ! ocean time-level index
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) :: ptr             ! passive tracers and RHS of tracer equation
       !
       INTEGER            :: ji, jj, jk, jn
       REAL(wp)           :: zdep
       CHARACTER (len=22) :: charout
-      REAL(wp), DIMENSION(jpi,jpj,jpk)   ::   zahu, zahv
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   ztrtrd
+      REAL(wp),          DIMENSION(jpi,jpj,jpk) ::   zahu, zahv
+      REAL(wp), POINTER, DIMENSION(:,:,:,:)     ::   ztrtrd
       !!----------------------------------------------------------------------
       !
@@ -73,5 +76,5 @@
       IF( l_trdtrc )  THEN
          ALLOCATE( ztrtrd(jpi,jpj,jpk,jptra) )
-         ztrtrd(:,:,:,:)  = tra(:,:,:,:)
+         ztrtrd(:,:,:,:)  = ptr(:,:,:,:,Krhs)
       ENDIF
       !                                  !* set the lateral diffusivity coef. for passive tracer      
@@ -79,39 +82,39 @@
       zahv(:,:,:) = rldf * ahtv(:,:,:)
       !                                  !* Enhanced zonal diffusivity coefficent in the equatorial domain
-      DO jk= 1, jpk
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( gdept_n(ji,jj,jk) > 200. .AND. gphit(ji,jj) < 5. .AND. gphit(ji,jj) > -5. ) THEN
-                  zdep = MAX( gdept_n(ji,jj,jk) - 1000., 0. ) / 1000.
-                  zahu(ji,jj,jk) = zahu(ji,jj,jk) * MAX( 1., rn_fact_lap * EXP( -zdep ) )
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1, jpk )
+         IF( gdept(ji,jj,jk,Kmm) > 200. .AND. gphit(ji,jj) < 5. .AND. gphit(ji,jj) > -5. ) THEN
+            zdep = MAX( gdept(ji,jj,jk,Kmm) - 1000., 0. ) / 1000.
+            zahu(ji,jj,jk) = zahu(ji,jj,jk) * MAX( 1., rn_fact_lap * EXP( -zdep ) )
+         ENDIF
+      END_3D
       !
       SELECT CASE ( nldf_trc )                 !* compute lateral mixing trend and add it to the general trend
       !
-      CASE ( np_lap   )                               ! iso-level laplacian
-         CALL tra_ldf_lap  ( kt, nittrc000,'TRC', zahu, zahv, gtru, gtrv, gtrui, gtrvi, trb,      tra, jptra,    1     )
-      CASE ( np_lap_i )                               ! laplacian : standard iso-neutral operator (Madec)
-         CALL tra_ldf_iso  ( kt, nittrc000,'TRC', zahu, zahv, gtru, gtrv, gtrui, gtrvi, trb, trb, tra, jptra,    1     )
-      CASE ( np_lap_it )                              ! laplacian : triad iso-neutral operator (griffies)
-         CALL tra_ldf_triad( kt, nittrc000,'TRC', zahu, zahv, gtru, gtrv, gtrui, gtrvi, trb, trb, tra, jptra,    1     )
-      CASE ( np_blp , np_blp_i , np_blp_it )          ! bilaplacian: all operator (iso-level, -neutral)
-         CALL tra_ldf_blp  ( kt, nittrc000,'TRC', zahu, zahv, gtru, gtrv, gtrui, gtrvi, trb     , tra, jptra, nldf_trc )
+      CASE ( np_lap   )                                                                                    ! iso-level laplacian
+         CALL tra_ldf_lap  ( kt, Kmm, nittrc000,'TRC', zahu, zahv, gtru, gtrv, gtrui, gtrvi,            &
+           &                     ptr(:,:,:,:,Kbb), ptr(:,:,:,:,Krhs),                   jptra, 1 )
+      CASE ( np_lap_i )                                                                                    ! laplacian : standard iso-neutral operator (Madec)
+         CALL tra_ldf_iso  ( kt, Kmm, nittrc000,'TRC', zahu, zahv, gtru, gtrv, gtrui, gtrvi,            &
+           &                     ptr(:,:,:,:,Kbb), ptr(:,:,:,:,Kbb), ptr(:,:,:,:,Krhs), jptra, 1 )
+      CASE ( np_lap_it )                                                                                   ! laplacian : triad iso-neutral operator (griffies)
+         CALL tra_ldf_triad( kt, Kmm, nittrc000,'TRC', zahu, zahv, gtru, gtrv, gtrui, gtrvi,            &
+           &                     ptr(:,:,:,:,Kbb), ptr(:,:,:,:,Kbb), ptr(:,:,:,:,Krhs), jptra, 1 )
+      CASE ( np_blp , np_blp_i , np_blp_it )                                                               ! bilaplacian: all operator (iso-level, -neutral)
+         CALL tra_ldf_blp  ( kt, Kmm, nittrc000,'TRC', zahu, zahv, gtru, gtrv, gtrui, gtrvi,            &
+           &                     ptr(:,:,:,:,Kbb) , ptr(:,:,:,:,Krhs),                 jptra, nldf_trc )
       END SELECT
       !
       IF( l_trdtrc )   THEN                    ! send the trends for further diagnostics
         DO jn = 1, jptra
-           ztrtrd(:,:,:,jn) = tra(:,:,:,jn) - ztrtrd(:,:,:,jn)
-           CALL trd_tra( kt, 'TRC', jn, jptra_ldf, ztrtrd(:,:,:,jn) )
+           ztrtrd(:,:,:,jn) = ptr(:,:,:,jn,Krhs) - ztrtrd(:,:,:,jn)
+           CALL trd_tra( kt, Kmm, Krhs, 'TRC', jn, jptra_ldf, ztrtrd(:,:,:,jn) )
         END DO
         DEALLOCATE( ztrtrd )
       ENDIF
       !                
-      IF( ln_ctl ) THEN                        ! print mean trends (used for debugging)
+      IF( sn_cfctl%l_prttrc ) THEN ! print mean trends (used for debugging)
          WRITE(charout, FMT="('ldf ')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl( tab4d_1=ptr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm, clinfo3='trd' )
       ENDIF
       !
@@ -143,11 +146,9 @@
       ENDIF
       !
-      REWIND( numnat_ref )             !  namtrc_ldf in reference namelist 
       READ  ( numnat_ref, namtrc_ldf, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_ldf in reference namelist', lwp )
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_ldf in reference namelist' )
       !
-      REWIND( numnat_cfg )             !  namtrc_ldf in configuration namelist 
       READ  ( numnat_cfg, namtrc_ldf, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_ldf in configuration namelist', lwp )
+904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_ldf in configuration namelist' )
       IF(lwm) WRITE ( numont, namtrc_ldf )
       !
@@ -167,5 +168,5 @@
       IF( ln_trcldf_OFF  ) THEN   ;   nldf_trc = np_no_ldf   ;   ioptio = ioptio + 1   ;   ENDIF
       IF( ln_trcldf_tra  ) THEN   ;   nldf_trc = nldf_tra    ;   ioptio = ioptio + 1   ;   ENDIF
-      IF( ioptio /=  1   )   CALL ctl_stop( 'trc_ldf_ini: use ONE of the 2 operator options (NONE/tra)' )
+      IF( ioptio /=  1   )   CALL ctl_stop( 'trc_ldf_ini: use ONE of the 2 operator options (OFF/tra)' )
       
       !                                ! multiplier : passive/active tracers ration
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcnxt.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcnxt.F90	(revision 11396)
+++ 	(revision )
@@ -1,279 +1,0 @@
-MODULE trcnxt
-   !!======================================================================
-   !!                       ***  MODULE  trcnxt  ***
-   !! Ocean passive tracers:  time stepping on passives tracers
-   !!======================================================================
-   !! History :  7.0  !  1991-11  (G. Madec)  Original code
-   !!                 !  1993-03  (M. Guyon)  symetrical conditions
-   !!                 !  1995-02  (M. Levy)   passive tracers
-   !!                 !  1996-02  (G. Madec & M. Imbard)  opa release 8.0
-   !!            8.0  !  1996-04  (A. Weaver)  Euler forward step
-   !!            8.2  !  1999-02  (G. Madec, N. Grima)  semi-implicit pressure grad.
-   !!  NEMO      1.0  !  2002-08  (G. Madec)  F90: Free form and module
-   !!                 !  2002-08  (G. Madec)  F90: Free form and module
-   !!                 !  2002-11  (C. Talandier, A-M Treguier) Open boundaries
-   !!                 !  2004-03  (C. Ethe) passive tracers
-   !!                 !  2007-02  (C. Deltel) Diagnose ML trends for passive tracers
-   !!            2.0  !  2006-02  (L. Debreu, C. Mazauric) Agrif implementation
-   !!            3.0  !  2008-06  (G. Madec)  time stepping always done in trazdf
-   !!            3.1  !  2009-02  (G. Madec, R. Benshila)  re-introduce the vvl option
-   !!            3.3  !  2010-06  (C. Ethe, G. Madec) Merge TRA-TRC
-   !!----------------------------------------------------------------------
-#if defined key_top
-   !!----------------------------------------------------------------------
-   !!   'key_top'                                                TOP models
-   !!----------------------------------------------------------------------
-   !!   trc_nxt     : time stepping on passive tracers
-   !!----------------------------------------------------------------------
-   USE oce_trc         ! ocean dynamics and tracers variables
-   USE trc             ! ocean passive tracers variables
-   USE trd_oce
-   USE trdtra
-   USE tranxt
-   USE bdy_oce   , ONLY: ln_bdy
-   USE trcbdy          ! BDY open boundaries
-# if defined key_agrif
-   USE agrif_top_interp
-# endif
-   !
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE prtctl_trc      ! Print control for debbuging
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   trc_nxt   ! routine called by step.F90
-
-   REAL(wp) ::   rfact1, rfact2
-
-   !!----------------------------------------------------------------------
-   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
-   !! $Id$ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE trc_nxt( kt )
-      !!----------------------------------------------------------------------
-      !!                   ***  ROUTINE trcnxt  ***
-      !!
-      !! ** Purpose :   Compute the passive tracers fields at the 
-      !!      next time-step from their temporal trends and swap the fields.
-      !! 
-      !! ** Method  :   Apply lateral boundary conditions on (ua,va) through 
-      !!      call to lbc_lnk routine
-      !!   default:
-      !!      arrays swap
-      !!         (trn) = (tra) ; (tra) = (0,0)
-      !!         (trb) = (trn) 
-      !!
-      !!   For Arakawa or TVD Scheme : 
-      !!      A Asselin time filter applied on now tracers (trn) to avoid
-      !!      the divergence of two consecutive time-steps and tr arrays
-      !!      to prepare the next time_step:
-      !!         (trb) = (trn) + atfp [ (trb) + (tra) - 2 (trn) ]
-      !!         (trn) = (tra) ; (tra) = (0,0)
-      !!
-      !!
-      !! ** Action  : - update trb, trn
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-      !
-      INTEGER  ::   jk, jn   ! dummy loop indices
-      REAL(wp) ::   zfact            ! temporary scalar
-      CHARACTER (len=22) :: charout
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::   ztrdt    ! 4D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_timing )   CALL timing_start('trc_nxt')
-      !
-      IF( kt == nittrc000 .AND. lwp ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'trc_nxt : time stepping on passive tracers'
-      ENDIF
-      !
-#if defined key_agrif
-      CALL Agrif_trc                   ! AGRIF zoom boundaries
-#endif
-      ! Update after tracer on domain lateral boundaries
-      CALL lbc_lnk( 'trcnxt', tra(:,:,:,:), 'T', 1. )   
-
-      IF( ln_bdy )  CALL trc_bdy( kt )
-
-      IF( l_trdtrc )  THEN             ! trends: store now fields before the Asselin filter application
-         ALLOCATE( ztrdt(jpi,jpj,jpk,jptra) )
-         ztrdt(:,:,:,:)  = 0._wp
-         IF( ln_traldf_iso ) THEN                       ! diagnose the "pure" Kz diffusive trend 
-            DO jn = 1, jptra
-               CALL trd_tra( kt, 'TRC', jn, jptra_zdfp, ztrdt(:,:,:,jn) )
-            ENDDO
-         ENDIF
-
-         ! total trend for the non-time-filtered variables. 
-         zfact = 1.0 / rdttrc
-         ! G Nurser 23 Mar 2017. Recalculate trend as Delta(e3t*T)/e3tn; e3tn cancel from tsn terms
-         IF( ln_linssh ) THEN       ! linear sea surface height only
-            DO jn = 1, jptra
-               DO jk = 1, jpkm1
-                  ztrdt(:,:,jk,jn) = ( tra(:,:,jk,jn)*e3t_a(:,:,jk) / e3t_n(:,:,jk) - trn(:,:,jk,jn)) * zfact
-               END DO
-            END DO
-         ELSE
-            DO jn = 1, jptra
-               DO jk = 1, jpkm1
-                  ztrdt(:,:,jk,jn) = ( tra(:,:,jk,jn) - trn(:,:,jk,jn) ) * zfact
-               END DO
-            END DO
-         ENDIF
-         !
-         DO jn = 1, jptra
-            CALL trd_tra( kt, 'TRC', jn, jptra_tot, ztrdt(:,:,:,jn) )
-         ENDDO
-         !
-         IF( ln_linssh ) THEN       ! linear sea surface height only
-            ! Store now fields before applying the Asselin filter 
-            ! in order to calculate Asselin filter trend later.
-            ztrdt(:,:,:,:) = trn(:,:,:,:) 
-         ENDIF
-
-      ENDIF
-      !                                ! Leap-Frog + Asselin filter time stepping
-      IF( (neuler == 0 .AND. kt == nittrc000) .OR. ln_top_euler ) THEN    ! Euler time-stepping (only swap)
-         DO jn = 1, jptra
-            DO jk = 1, jpkm1
-               trn(:,:,jk,jn) = tra(:,:,jk,jn)
-               trb(:,:,jk,jn) = trn(:,:,jk,jn)  
-            END DO
-         END DO
-         IF (l_trdtrc .AND. .NOT. ln_linssh ) THEN   ! Zero Asselin filter contribution must be explicitly written out since for vvl
-            !                                        ! Asselin filter is output by tra_nxt_vvl that is not called on this time step
-            ztrdt(:,:,:,:) = 0._wp            
-            DO jn = 1, jptra
-               CALL trd_tra( kt, 'TRC', jn, jptra_atf, ztrdt(:,:,:,jn) )
-            ENDDO
-         END IF
-         !
-      ELSE     
-         IF( .NOT. l_offline ) THEN ! Leap-Frog + Asselin filter time stepping
-            IF( ln_linssh ) THEN   ;   CALL tra_nxt_fix( kt, nittrc000,         'TRC', trb, trn, tra, jptra )  !     linear ssh
-            ELSE                   ;   CALL tra_nxt_vvl( kt, nittrc000, rdttrc, 'TRC', trb, trn, tra,      &
-              &                                                                   sbc_trc, sbc_trc_b, jptra )  ! non-linear ssh
-            ENDIF
-         ELSE
-                                       CALL trc_nxt_off( kt )       ! offline 
-         ENDIF
-         !
-         CALL lbc_lnk_multi( 'trcnxt', trb(:,:,:,:), 'T', 1._wp, trn(:,:,:,:), 'T', 1._wp, tra(:,:,:,:), 'T', 1._wp )
-      ENDIF
-      !
-      IF( l_trdtrc .AND. ln_linssh ) THEN      ! trend of the Asselin filter (tb filtered - tb)/dt )
-         DO jn = 1, jptra
-            DO jk = 1, jpkm1
-               zfact = 1._wp / r2dttrc  
-               ztrdt(:,:,jk,jn) = ( trb(:,:,jk,jn) - ztrdt(:,:,jk,jn) ) * zfact 
-            END DO
-            CALL trd_tra( kt, 'TRC', jn, jptra_atf, ztrdt(:,:,:,jn) )
-         END DO
-      END IF
-      IF( l_trdtrc ) DEALLOCATE( ztrdt ) 
-      !
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
-         WRITE(charout, FMT="('nxt')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc(tab4d=trn, mask=tmask, clinfo=ctrcnm)
-      ENDIF
-      !
-      IF( ln_timing )   CALL timing_stop('trc_nxt')
-      !
-   END SUBROUTINE trc_nxt
-
-
-   SUBROUTINE trc_nxt_off( kt )
-      !!----------------------------------------------------------------------
-      !!                   ***  ROUTINE tra_nxt_vvl  ***
-      !!
-      !! ** Purpose :   Time varying volume: apply the Asselin time filter  
-      !!                and swap the tracer fields.
-      !! 
-      !! ** Method  : - Apply a thickness weighted Asselin time filter on now fields.
-      !!              - save in (ta,sa) a thickness weighted average over the three 
-      !!             time levels which will be used to compute rdn and thus the semi-
-      !!             implicit hydrostatic pressure gradient (ln_dynhpg_imp = T)
-      !!              - swap tracer fields to prepare the next time_step.
-      !!                This can be summurized for tempearture as:
-      !!             ztm = ( e3t_n*tn + rbcp*[ e3t_b*tb - 2 e3t_n*tn + e3t_a*ta ] )   ln_dynhpg_imp = T
-      !!                  /( e3t_n    + rbcp*[ e3t_b    - 2 e3t_n    + e3t_a    ] )   
-      !!             ztm = 0                                                       otherwise
-      !!             tb  = ( e3t_n*tn + atfp*[ e3t_b*tb - 2 e3t_n*tn + e3t_a*ta ] )
-      !!                  /( e3t_n    + atfp*[ e3t_b    - 2 e3t_n    + e3t_a    ] )
-      !!             tn  = ta 
-      !!             ta  = zt        (NB: reset to 0 after eos_bn2 call)
-      !!
-      !! ** Action  : - (tb,sb) and (tn,sn) ready for the next time step
-      !!              - (ta,sa) time averaged (t,s)   (ln_dynhpg_imp = T)
-      !!----------------------------------------------------------------------
-      INTEGER , INTENT(in   )   ::  kt       ! ocean time-step index
-      !!     
-      INTEGER  ::   ji, jj, jk, jn              ! dummy loop indices
-      REAL(wp) ::   ztc_a , ztc_n , ztc_b , ztc_f , ztc_d    ! local scalar
-      REAL(wp) ::   ze3t_b, ze3t_n, ze3t_a, ze3t_f, ze3t_d   !   -      -
-      !!----------------------------------------------------------------------
-      !
-      IF( kt == nittrc000 )  THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'trc_nxt_off : time stepping'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
-         IF( .NOT. ln_linssh ) THEN
-            rfact1 = atfp * rdttrc
-            rfact2 = rfact1 / rau0
-         ENDIF
-        !  
-      ENDIF
-      !
-      DO jn = 1, jptra      
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ze3t_b = e3t_b(ji,jj,jk)
-                  ze3t_n = e3t_n(ji,jj,jk)
-                  ze3t_a = e3t_a(ji,jj,jk)
-                  !                                         ! tracer content at Before, now and after
-                  ztc_b  = trb(ji,jj,jk,jn) * ze3t_b
-                  ztc_n  = trn(ji,jj,jk,jn) * ze3t_n
-                  ztc_a  = tra(ji,jj,jk,jn) * ze3t_a
-                  !
-                  ze3t_d = ze3t_a - 2. * ze3t_n + ze3t_b
-                  ztc_d  = ztc_a  - 2. * ztc_n  + ztc_b
-                  !
-                  ze3t_f = ze3t_n + atfp * ze3t_d
-                  ztc_f  = ztc_n  + atfp * ztc_d
-                  !
-                  IF( .NOT. ln_linssh .AND. jk == mikt(ji,jj) ) THEN           ! first level 
-                     ze3t_f = ze3t_f - rfact2 * ( emp_b(ji,jj)      - emp(ji,jj)   ) 
-                     ztc_f  = ztc_f  - rfact1 * ( sbc_trc(ji,jj,jn) - sbc_trc_b(ji,jj,jn) )
-                  ENDIF
-
-                  ze3t_f = 1.e0 / ze3t_f
-                  trb(ji,jj,jk,jn) = ztc_f * ze3t_f       ! ptb <-- ptn filtered
-                  trn(ji,jj,jk,jn) = tra(ji,jj,jk,jn)     ! ptn <-- pta
-                  !
-               END DO
-            END DO
-         END DO
-         ! 
-      END DO
-      !
-   END SUBROUTINE trc_nxt_off
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                                         Empty module
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE trc_nxt( kt )  
-      INTEGER, INTENT(in) :: kt
-      WRITE(*,*) 'trc_nxt: You should not have seen this print! error?', kt
-   END SUBROUTINE trc_nxt
-#endif
-   !!======================================================================
-END MODULE trcnxt
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcrad.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcrad.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcrad.F90	(revision 13463)
@@ -6,4 +6,5 @@
    !! History :   -   !  01-01  (O. Aumont & E. Kestenare)  Original code
    !!            1.0  !  04-03  (C. Ethe)  free form F90
+   !!            4.1  !  08-19  (A. Coward, D. Storkey) tidy up using new time-level indices
    !!----------------------------------------------------------------------
 #if defined key_top
@@ -18,5 +19,5 @@
    USE trd_oce
    USE trdtra
-   USE prtctl_trc          ! Print control for debbuging
+   USE prtctl              ! Print control for debbuging
    USE lib_fortran
 
@@ -30,4 +31,6 @@
    REAL(wp), DIMENSION(:,:), ALLOCATABLE::   gainmass
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -37,5 +40,5 @@
 CONTAINS
 
-   SUBROUTINE trc_rad( kt )
+   SUBROUTINE trc_rad( kt, Kbb, Kmm, ptr )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE trc_rad  ***
@@ -52,5 +55,7 @@
       !!                (the total CFC content is not strictly preserved)
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      INTEGER,                                    INTENT(in   ) :: kt         ! ocean time-step index
+      INTEGER,                                    INTENT(in   ) :: Kbb, Kmm   ! time level indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) :: ptr        ! passive tracers and RHS of tracer equation
       !
       CHARACTER (len=22) :: charout
@@ -59,14 +64,14 @@
       IF( ln_timing )   CALL timing_start('trc_rad')
       !
-      IF( ln_age     )   CALL trc_rad_sms( kt, trb, trn, jp_age , jp_age                )  !  AGE
-      IF( ll_cfc     )   CALL trc_rad_sms( kt, trb, trn, jp_cfc0, jp_cfc1               )  !  CFC model
-      IF( ln_c14     )   CALL trc_rad_sms( kt, trb, trn, jp_c14 , jp_c14                )  !  C14
-      IF( ln_pisces  )   CALL trc_rad_sms( kt, trb, trn, jp_pcs0, jp_pcs1, cpreserv='Y' )  !  PISCES model
-      IF( ln_my_trc  )   CALL trc_rad_sms( kt, trb, trn, jp_myt0, jp_myt1               )  !  MY_TRC model
-      !
-      IF(ln_ctl) THEN      ! print mean trends (used for debugging)
+      IF( ln_age     )   CALL trc_rad_sms( kt, Kbb, Kmm, ptr, jp_age , jp_age                )  !  AGE
+      IF( ll_cfc     )   CALL trc_rad_sms( kt, Kbb, Kmm, ptr, jp_cfc0, jp_cfc1               )  !  CFC model
+      IF( ln_c14     )   CALL trc_rad_sms( kt, Kbb, Kmm, ptr, jp_c14 , jp_c14                )  !  C14
+      IF( ln_pisces  )   CALL trc_rad_sms( kt, Kbb, Kmm, ptr, jp_pcs0, jp_pcs1, cpreserv='Y' )  !  PISCES model
+      IF( ln_my_trc  )   CALL trc_rad_sms( kt, Kbb, Kmm, ptr, jp_myt0, jp_myt1               )  !  MY_TRC model
+      !
+      IF(sn_cfctl%l_prttrc) THEN      ! print mean trends (used for debugging)
          WRITE(charout, FMT="('rad')")
-         CALL prt_ctl_trc_info( charout )
-         CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl( tab4d_1=ptr(:,:,:,:,Kbb), mask1=tmask, clinfo=ctrcnm )
       ENDIF
       !
@@ -87,10 +92,8 @@
       !!----------------------------------------------------------------------
       !
-      REWIND( numnat_ref )              ! namtrc_rad in reference namelist 
       READ  ( numnat_ref, namtrc_rad, IOSTAT = ios, ERR = 907)
-907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_rad in reference namelist', lwp )
-      REWIND( numnat_cfg )              ! namtrc_rad in configuration namelist 
+907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_rad in reference namelist' )
       READ  ( numnat_cfg, namtrc_rad, IOSTAT = ios, ERR = 908 )
-908   IF( ios > 0 )   CALL ctl_nam ( ios , 'namtrc_rad in configuration namelist', lwp )
+908   IF( ios > 0 )   CALL ctl_nam ( ios , 'namtrc_rad in configuration namelist' )
       IF(lwm) WRITE( numont, namtrc_rad )
 
@@ -113,167 +116,111 @@
 
 
-   SUBROUTINE trc_rad_sms( kt, ptrb, ptrn, jp_sms0, jp_sms1, cpreserv )
-      !!-----------------------------------------------------------------------------
-      !!                  ***  ROUTINE trc_rad_sms  ***
-      !!
-      !! ** Purpose :   "crappy" routine to correct artificial negative
-      !!              concentrations due to isopycnal scheme
-      !!
-      !! ** Method  : 2 cases :
-      !!                - Set negative concentrations to zero while computing
-      !!                  the corresponding tracer content that is added to the
-      !!                  tracers. Then, adjust the tracer concentration using
-      !!                  a multiplicative factor so that the total tracer 
-      !!                  concentration is preserved.
-      !!                - simply set to zero the negative CFC concentration
-      !!                  (the total content of concentration is not strictly preserved)
-      !!--------------------------------------------------------------------------------
-      INTEGER                                , INTENT(in   ) ::   kt                 ! ocean time-step index
-      INTEGER                                , INTENT(in   ) ::   jp_sms0, jp_sms1   ! First & last index of the passive tracer model
-      REAL(wp), DIMENSION (jpi,jpj,jpk,jptra), INTENT(inout) ::   ptrb    , ptrn     ! before and now traceur concentration
-      CHARACTER( len = 1), OPTIONAL          , INTENT(in   ) ::   cpreserv           ! flag to preserve content or not
-      !
-      INTEGER ::   ji, ji2, jj, jj2, jk, jn     ! dummy loop indices
-      INTEGER ::   icnt
-      LOGICAL ::   lldebug = .FALSE.            ! local logical
-      REAL(wp)::   zcoef, zs2rdt, ztotmass
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrneg, ztrpos
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrtrd   ! workspace arrays
-      !!----------------------------------------------------------------------
-      !
-      IF( l_trdtrc )   ALLOCATE( ztrtrd(jpi,jpj,jpk) )
-      zs2rdt = 1. / ( 2. * rdt * REAL( nn_dttrc, wp ) )
-      !
-      IF( PRESENT( cpreserv )  ) THEN     !==  total tracer concentration is preserved  ==!
-         !
-         ALLOCATE( ztrneg(1:jpi,1:jpj,jp_sms0:jp_sms1), ztrpos(1:jpi,1:jpj,jp_sms0:jp_sms1) )
-
-         DO jn = jp_sms0, jp_sms1
-            ztrneg(:,:,jn) = SUM( MIN( 0., ptrb(:,:,:,jn) ) * cvol(:,:,:), dim = 3 )   ! sum of the negative values
-            ztrpos(:,:,jn) = SUM( MAX( 0., ptrb(:,:,:,jn) ) * cvol(:,:,:), dim = 3 )   ! sum of the positive values
-         END DO
-         CALL sum3x3( ztrneg )
-         CALL sum3x3( ztrpos )
-         
-         DO jn = jp_sms0, jp_sms1
-            !
-            IF( l_trdtrc )   ztrtrd(:,:,:) = ptrb(:,:,:,jn)                            ! save input trb for trend computation           
-            !
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     IF( ztrneg(ji,jj,jn) /= 0. ) THEN                                 ! if negative values over the 3x3 box
-                        !
-                        ptrb(ji,jj,jk,jn) = ptrb(ji,jj,jk,jn) * tmask(ji,jj,jk)   ! really needed?
-                        IF( ptrb(ji,jj,jk,jn) < 0. ) ptrb(ji,jj,jk,jn) = 0.       ! supress negative values
-                        IF( ptrb(ji,jj,jk,jn) > 0. ) THEN                         ! use positive values to compensate mass gain
-                           zcoef = 1. + ztrneg(ji,jj,jn) / ztrpos(ji,jj,jn)       ! ztrpos > 0 as ptrb > 0
-                           ptrb(ji,jj,jk,jn) = ptrb(ji,jj,jk,jn) * zcoef
-                           IF( zcoef < 0. ) THEN                                  ! if the compensation exceed the positive value
-                              gainmass(jn,1) = gainmass(jn,1) - ptrb(ji,jj,jk,jn) * cvol(ji,jj,jk)   ! we are adding mass...
-                              ptrb(ji,jj,jk,jn) = 0.                              ! limit the compensation to keep positive value
-                           ENDIF
-                        ENDIF
-                        !
-                     ENDIF
-                  END DO
-               END DO
-            END DO
-            !
-            IF( l_trdtrc ) THEN
-               ztrtrd(:,:,:) = ( ptrb(:,:,:,jn) - ztrtrd(:,:,:) ) * zs2rdt
-               CALL trd_tra( kt, 'TRC', jn, jptra_radb, ztrtrd )       ! Asselin-like trend handling
-            ENDIF
-            !
-         END DO
- 
-         IF( kt == nitend ) THEN
-            CALL mpp_sum( 'trcrad', gainmass(:,1) )
-            DO jn = jp_sms0, jp_sms1
-               IF( gainmass(jn,1) > 0. ) THEN
-                  ztotmass = glob_sum( 'trcrad', ptrb(:,:,:,jn) * cvol(:,:,:) )
-                  IF(lwp) WRITE(numout, '(a, i2, a, D23.16, a, D23.16)') 'trcrad ptrb, traceur ', jn  &
-                     &        , ' total mass : ', ztotmass, ', mass gain : ',  gainmass(jn,1)
-               END IF
-            END DO
-         ENDIF
-
-         DO jn = jp_sms0, jp_sms1
-            ztrneg(:,:,jn) = SUM( MIN( 0., ptrn(:,:,:,jn) ) * cvol(:,:,:), dim = 3 )   ! sum of the negative values
-            ztrpos(:,:,jn) = SUM( MAX( 0., ptrn(:,:,:,jn) ) * cvol(:,:,:), dim = 3 )   ! sum of the positive values
-         END DO
-         CALL sum3x3( ztrneg )
-         CALL sum3x3( ztrpos )
-         
-         DO jn = jp_sms0, jp_sms1
-            !
-            IF( l_trdtrc )   ztrtrd(:,:,:) = ptrn(:,:,:,jn)                            ! save input trb for trend computation
-            !
-            DO jk = 1, jpkm1
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     IF( ztrneg(ji,jj,jn) /= 0. ) THEN                                 ! if negative values over the 3x3 box
-                        !
-                        ptrn(ji,jj,jk,jn) = ptrn(ji,jj,jk,jn) * tmask(ji,jj,jk)   ! really needed?
-                        IF( ptrn(ji,jj,jk,jn) < 0. ) ptrn(ji,jj,jk,jn) = 0.       ! supress negative values
-                        IF( ptrn(ji,jj,jk,jn) > 0. ) THEN                         ! use positive values to compensate mass gain
-                           zcoef = 1. + ztrneg(ji,jj,jn) / ztrpos(ji,jj,jn)       ! ztrpos > 0 as ptrb > 0
-                           ptrn(ji,jj,jk,jn) = ptrn(ji,jj,jk,jn) * zcoef
-                           IF( zcoef < 0. ) THEN                                  ! if the compensation exceed the positive value
-                              gainmass(jn,2) = gainmass(jn,2) - ptrn(ji,jj,jk,jn) * cvol(ji,jj,jk)   ! we are adding mass...
-                              ptrn(ji,jj,jk,jn) = 0.                              ! limit the compensation to keep positive value
-                           ENDIF
-                        ENDIF
-                        !
-                     ENDIF
-                  END DO
-               END DO
-            END DO
-            !
-            IF( l_trdtrc ) THEN
-               ztrtrd(:,:,:) = ( ptrn(:,:,:,jn) - ztrtrd(:,:,:) ) * zs2rdt
-               CALL trd_tra( kt, 'TRC', jn, jptra_radn, ztrtrd )       ! standard     trend handling
-            ENDIF
-            !
-         END DO
- 
-         IF( kt == nitend ) THEN
-            CALL mpp_sum( 'trcrad', gainmass(:,2) )
-            DO jn = jp_sms0, jp_sms1
-               IF( gainmass(jn,2) > 0. ) THEN
-                  ztotmass = glob_sum( 'trcrad', ptrn(:,:,:,jn) * cvol(:,:,:) )
-                  WRITE(numout, '(a, i2, a, D23.16, a, D23.16)') 'trcrad ptrn, traceur ', jn  &
-                     &        , ' total mass : ', ztotmass, ', mass gain : ',  gainmass(jn,1)
-               END IF
-            END DO
-         ENDIF
-
-         DEALLOCATE( ztrneg, ztrpos )
-         !
-      ELSE                                !==  total CFC content is NOT strictly preserved  ==!
-         !
-         DO jn = jp_sms0, jp_sms1  
-            !
-            IF( l_trdtrc )   ztrtrd(:,:,:) = ptrb(:,:,:,jn)                        ! save input trb for trend computation
-            !
-            WHERE( ptrb(:,:,:,jn) < 0. )   ptrb(:,:,:,jn) = 0.
-            !
-            IF( l_trdtrc ) THEN
-               ztrtrd(:,:,:) = ( ptrb(:,:,:,jn) - ztrtrd(:,:,:) ) * zs2rdt
-               CALL trd_tra( kt, 'TRC', jn, jptra_radb, ztrtrd )       ! Asselin-like trend handling
-            ENDIF
-            !
-            IF( l_trdtrc )   ztrtrd(:,:,:) = ptrn(:,:,:,jn)                        ! save input trn for trend computation
-            !
-            WHERE( ptrn(:,:,:,jn) < 0. )   ptrn(:,:,:,jn) = 0.
-            !
-            IF( l_trdtrc ) THEN
-               ztrtrd(:,:,:) = ( ptrn(:,:,:,jn) - ztrtrd(:,:,:) ) * zs2rdt
-               CALL trd_tra( kt, 'TRC', jn, jptra_radn, ztrtrd )       ! standard     trend handling
-            ENDIF
-            !
-         END DO
-         !
-      ENDIF
+   SUBROUTINE trc_rad_sms( kt, Kbb, Kmm, ptr, jp_sms0, jp_sms1, cpreserv )
+     !!-----------------------------------------------------------------------------
+     !!                  ***  ROUTINE trc_rad_sms  ***
+     !!
+     !! ** Purpose :   "crappy" routine to correct artificial negative
+     !!              concentrations due to isopycnal scheme
+     !!
+     !! ** Method  : 2 cases :
+     !!                - Set negative concentrations to zero while computing
+     !!                  the corresponding tracer content that is added to the
+     !!                  tracers. Then, adjust the tracer concentration using
+     !!                  a multiplicative factor so that the total tracer 
+     !!                  concentration is preserved.
+     !!                - simply set to zero the negative CFC concentration
+     !!                  (the total content of concentration is not strictly preserved)
+     !!--------------------------------------------------------------------------------
+     INTEGER                                    , INTENT(in   ) ::   kt                 ! ocean time-step index
+     INTEGER                                    , INTENT(in   ) ::   Kbb, Kmm           ! time level indices
+     INTEGER                                    , INTENT(in   ) ::   jp_sms0, jp_sms1   ! First & last index of the passive tracer model
+     REAL(wp), DIMENSION (jpi,jpj,jpk,jptra,jpt), INTENT(inout) ::   ptr                ! before and now traceur concentration
+     CHARACTER( len = 1), OPTIONAL              , INTENT(in   ) ::   cpreserv           ! flag to preserve content or not
+     !
+     INTEGER ::   ji, ji2, jj, jj2, jk, jn, jt ! dummy loop indices
+     INTEGER ::   icnt, itime
+     LOGICAL ::   lldebug = .FALSE.            ! local logical
+     REAL(wp)::   zcoef, zs2rdt, ztotmass
+     REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrneg, ztrpos
+     REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrtrd   ! workspace arrays
+     !!----------------------------------------------------------------------
+     !
+     IF( l_trdtrc )   ALLOCATE( ztrtrd(jpi,jpj,jpk) )
+     zs2rdt = 1. / ( 2. * rn_Dt )
+     !
+     DO jt = 1,2  ! Loop over time indices since exactly the same fix is applied to "now" and "after" fields
+        IF( jt == 1 ) itime = Kbb
+        IF( jt == 2 ) itime = Kmm
+
+        IF( PRESENT( cpreserv )  ) THEN     !==  total tracer concentration is preserved  ==!
+           !
+           ALLOCATE( ztrneg(1:jpi,1:jpj,jp_sms0:jp_sms1), ztrpos(1:jpi,1:jpj,jp_sms0:jp_sms1) )
+
+           DO jn = jp_sms0, jp_sms1
+              ztrneg(:,:,jn) = SUM( MIN( 0., ptr(:,:,:,jn,itime) ) * cvol(:,:,:), dim = 3 )   ! sum of the negative values
+              ztrpos(:,:,jn) = SUM( MAX( 0., ptr(:,:,:,jn,itime) ) * cvol(:,:,:), dim = 3 )   ! sum of the positive values
+           END DO
+           CALL sum3x3( ztrneg )
+           CALL sum3x3( ztrpos )
+
+           DO jn = jp_sms0, jp_sms1
+              !
+              IF( l_trdtrc )   ztrtrd(:,:,:) = ptr(:,:,:,jn,itime)                       ! save input tr(:,:,:,:,Kbb) for trend computation           
+              !
+              DO_3D( nn_hls, nn_hls, nn_hls, nn_hls, 1, jpkm1 )
+                 IF( ztrneg(ji,jj,jn) /= 0. ) THEN                                 ! if negative values over the 3x3 box
+                    !
+                    ptr(ji,jj,jk,jn,itime) = ptr(ji,jj,jk,jn,itime) * tmask(ji,jj,jk)   ! really needed?
+                    IF( ptr(ji,jj,jk,jn,itime) < 0. ) ptr(ji,jj,jk,jn,itime) = 0.       ! suppress negative values
+                    IF( ptr(ji,jj,jk,jn,itime) > 0. ) THEN                    ! use positive values to compensate mass gain
+                       zcoef = 1. + ztrneg(ji,jj,jn) / ztrpos(ji,jj,jn)       ! ztrpos > 0 as ptr > 0
+                       ptr(ji,jj,jk,jn,itime) = ptr(ji,jj,jk,jn,itime) * zcoef
+                       IF( zcoef < 0. ) THEN                                  ! if the compensation exceed the positive value
+                          gainmass(jn,1) = gainmass(jn,1) - ptr(ji,jj,jk,jn,itime) * cvol(ji,jj,jk)   ! we are adding mass...
+                          ptr(ji,jj,jk,jn,itime) = 0.                         ! limit the compensation to keep positive value
+                       ENDIF
+                    ENDIF
+                    !
+                 ENDIF
+              END_3D
+              !
+              IF( l_trdtrc ) THEN
+                 ztrtrd(:,:,:) = ( ptr(:,:,:,jn,itime) - ztrtrd(:,:,:) ) * zs2rdt
+                 CALL trd_tra( kt, Kbb, Kmm, 'TRC', jn, jptra_radb, ztrtrd )       ! Asselin-like trend handling
+              ENDIF
+              !
+           END DO
+
+           IF( kt == nitend ) THEN
+              CALL mpp_sum( 'trcrad', gainmass(:,1) )
+              DO jn = jp_sms0, jp_sms1
+                 IF( gainmass(jn,1) > 0. ) THEN
+                    ztotmass = glob_sum( 'trcrad', ptr(:,:,:,jn,itime) * cvol(:,:,:) )
+                    IF(lwp) WRITE(numout, '(a, i2, a, D23.16, a, D23.16)') 'trcrad ptrb, traceur ', jn  &
+                         &        , ' total mass : ', ztotmass, ', mass gain : ',  gainmass(jn,1)
+                 END IF
+              END DO
+           ENDIF
+
+           DEALLOCATE( ztrneg, ztrpos )
+           !
+        ELSE                                !==  total CFC content is NOT strictly preserved  ==!
+           !
+           DO jn = jp_sms0, jp_sms1  
+              !
+              IF( l_trdtrc )   ztrtrd(:,:,:) = ptr(:,:,:,jn,itime)                 ! save input tr for trend computation
+              !
+              WHERE( ptr(:,:,:,jn,itime) < 0. )   ptr(:,:,:,jn,itime) = 0.
+              !
+              IF( l_trdtrc ) THEN
+                 ztrtrd(:,:,:) = ( ptr(:,:,:,jn,itime) - ztrtrd(:,:,:) ) * zs2rdt
+                 CALL trd_tra( kt, Kbb, Kmm, 'TRC', jn, jptra_radb, ztrtrd )       ! Asselin-like trend handling
+              ENDIF
+              !
+           END DO
+           !
+        ENDIF
+        !
+      END DO
       !
       IF( l_trdtrc )  DEALLOCATE( ztrtrd )
@@ -286,6 +233,7 @@
    !!----------------------------------------------------------------------
 CONTAINS
-   SUBROUTINE trc_rad( kt )              ! Empty routine
+   SUBROUTINE trc_rad( kt, Kbb, Kmm )              ! Empty routine
       INTEGER, INTENT(in) ::   kt
+      INTEGER, INTENT(in) ::   Kbb, Kmm  ! time level indices
       WRITE(*,*) 'trc_rad: You should not have seen this print! error?', kt
    END SUBROUTINE trc_rad
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcsbc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcsbc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcsbc.F90	(revision 13463)
@@ -18,5 +18,5 @@
    USE oce_trc         ! ocean dynamics and active tracers variables
    USE trc             ! ocean  passive tracers variables
-   USE prtctl_trc      ! Print control for debbuging
+   USE prtctl          ! Print control for debbuging
    USE iom
    USE trd_oce
@@ -29,5 +29,6 @@
 
    !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -37,5 +38,5 @@
 CONTAINS
 
-   SUBROUTINE trc_sbc ( kt )
+   SUBROUTINE trc_sbc ( kt, Kmm, ptr, Krhs )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE trc_sbc  ***
@@ -49,14 +50,16 @@
       !!            The surface freshwater flux modify the ocean volume
       !!         and thus the concentration of a tracer as :
-      !!            tra = tra + emp * trn / e3t   for k=1
+      !!            tr(Krhs) = tr(Krhs) + emp * tr(Kmm) / e3t_   for k=1
       !!         where emp, the surface freshwater budget (evaporation minus
       !!         precipitation ) given in kg/m2/s is divided
       !!         by 1035 kg/m3 (density of ocean water) to obtain m/s.
       !!
-      !! ** Action  : - Update the 1st level of tra with the trend associated
+      !! ** Action  : - Update the 1st level of tr(:,:,:,:,Krhs) with the trend associated
       !!                with the tracer surface boundary condition 
       !!
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      INTEGER,                                    INTENT(in   ) :: kt        ! ocean time-step index
+      INTEGER,                                    INTENT(in   ) :: Kmm, Krhs ! time level indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) :: ptr       ! passive tracers and RHS of tracer equation
       !
       INTEGER  ::   ji, jj, jn                      ! dummy loop indices
@@ -82,8 +85,8 @@
          IF( ln_rsttr .AND. .NOT.ln_top_euler .AND.   &                     ! Restart: read in restart  file
             iom_varid( numrtr, 'sbc_'//TRIM(ctrcnm(1))//'_b', ldstop = .FALSE. ) > 0 ) THEN
-            IF(lwp) WRITE(numout,*) '          nittrc000-nn_dttrc surface tracer content forcing fields red in the restart file'
+            IF(lwp) WRITE(numout,*) '          nittrc000-1 surface tracer content forcing fields read in the restart file'
             zfact = 0.5_wp
             DO jn = 1, jptra
-               CALL iom_get( numrtr, jpdom_autoglo, 'sbc_'//TRIM(ctrcnm(jn))//'_b', sbc_trc_b(:,:,jn) )   ! before tracer content sbc
+               CALL iom_get( numrtr, jpdom_auto, 'sbc_'//TRIM(ctrcnm(jn))//'_b', sbc_trc_b(:,:,jn) )   ! before tracer content sbc
             END DO
          ELSE                                         ! No restart or restart not found: Euler forward time stepping
@@ -102,5 +105,5 @@
       ENDIF
 
-      ! Coupling online : river runoff is added to the horizontal divergence (hdivn) in the subroutine sbc_rnf_div 
+      ! Coupling online : river runoff is added to the horizontal divergence (hdiv) in the subroutine sbc_rnf_div 
       ! one only consider the concentration/dilution effect due to evaporation minus precipitation + freezing/melting of sea-ice
       ! Coupling offline : runoff are in emp which contains E-P-R
@@ -118,9 +121,7 @@
          !
          DO jn = 1, jptra
-            DO jj = 2, jpj
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  sbc_trc(ji,jj,jn) = zsfx(ji,jj) * r1_rau0 * trn(ji,jj,1,jn)
-               END DO
-            END DO
+            DO_2D( 0, 1, 0, 0 )
+               sbc_trc(ji,jj,jn) = zsfx(ji,jj) * r1_rho0 * ptr(ji,jj,1,jn,Kmm)
+            END_2D
          END DO
          !
@@ -128,9 +129,7 @@
          !
          DO jn = 1, jptra
-            DO jj = 2, jpj
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  sbc_trc(ji,jj,jn) = ( zsfx(ji,jj) + fmmflx(ji,jj) ) * r1_rau0 * trn(ji,jj,1,jn)
-               END DO
-            END DO
+            DO_2D( 0, 1, 0, 0 )
+               sbc_trc(ji,jj,jn) = ( zsfx(ji,jj) + fmmflx(ji,jj) ) * r1_rho0 * ptr(ji,jj,1,jn,Kmm)
+            END_2D
          END DO
          !
@@ -138,40 +137,36 @@
          !
          DO jn = 1, jptra
-            DO jj = 2, jpj
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zse3t = 1. / e3t_n(ji,jj,1)
-                  ! tracer flux at the ice/ocean interface (tracer/m2/s)
-                  zftra = - trc_i(ji,jj,jn) * fmmflx(ji,jj) ! uptake of tracer in the sea ice
-                  !                                         ! only used in the levitating sea ice case
-                  ! tracer flux only       : add concentration dilution term in net tracer flux, no F-M in volume flux
-                  ! tracer and mass fluxes : no concentration dilution term in net tracer flux, F-M term in volume flux
-                  ztfx  = zftra                        ! net tracer flux
-                  !
-                  zdtra = r1_rau0 * ( ztfx + ( zsfx(ji,jj) + fmmflx(ji,jj) ) * trn(ji,jj,1,jn) ) 
-                  IF ( zdtra < 0. ) THEN
-                     zdtra  = MAX(zdtra, -trn(ji,jj,1,jn) * e3t_n(ji,jj,1) / r2dttrc )   ! avoid negative concentrations to arise
-                  ENDIF
-                  sbc_trc(ji,jj,jn) =  zdtra 
-               END DO
-            END DO
+            DO_2D( 0, 1, 0, 0 )
+               zse3t = 1. / e3t(ji,jj,1,Kmm)
+               ! tracer flux at the ice/ocean interface (tracer/m2/s)
+               zftra = - trc_i(ji,jj,jn) * fmmflx(ji,jj) ! uptake of tracer in the sea ice
+               !                                         ! only used in the levitating sea ice case
+               ! tracer flux only       : add concentration dilution term in net tracer flux, no F-M in volume flux
+               ! tracer and mass fluxes : no concentration dilution term in net tracer flux, F-M term in volume flux
+               ztfx  = zftra                        ! net tracer flux
+               !
+               zdtra = r1_rho0 * ( ztfx + ( zsfx(ji,jj) + fmmflx(ji,jj) ) * ptr(ji,jj,1,jn,Kmm) ) 
+               IF ( zdtra < 0. ) THEN
+                  zdtra  = MAX(zdtra, -ptr(ji,jj,1,jn,Kmm) * e3t(ji,jj,1,Kmm) / rDt_trc )   ! avoid negative concentrations to arise
+               ENDIF
+               sbc_trc(ji,jj,jn) =  zdtra 
+            END_2D
          END DO
       END SELECT
       !
-      CALL lbc_lnk( 'trcsbc', sbc_trc(:,:,:), 'T', 1. )
+      CALL lbc_lnk( 'trcsbc', sbc_trc(:,:,:), 'T', 1.0_wp )
       !                                       Concentration dilution effect on tracers due to evaporation & precipitation 
       DO jn = 1, jptra
          !
-         IF( l_trdtrc )   ztrtrd(:,:,:) = tra(:,:,:,jn)  ! save trends
-         !
-         DO jj = 2, jpj
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zse3t = zfact / e3t_n(ji,jj,1)
-               tra(ji,jj,1,jn) = tra(ji,jj,1,jn) + ( sbc_trc_b(ji,jj,jn) + sbc_trc(ji,jj,jn) ) * zse3t
-            END DO
-         END DO
+         IF( l_trdtrc )   ztrtrd(:,:,:) = ptr(:,:,:,jn,Krhs)  ! save trends
+         !
+         DO_2D( 0, 1, 0, 0 )
+            zse3t = zfact / e3t(ji,jj,1,Kmm)
+            ptr(ji,jj,1,jn,Krhs) = ptr(ji,jj,1,jn,Krhs) + ( sbc_trc_b(ji,jj,jn) + sbc_trc(ji,jj,jn) ) * zse3t
+         END_2D
          !
          IF( l_trdtrc ) THEN
-            ztrtrd(:,:,:) = tra(:,:,:,jn) - ztrtrd(:,:,:)
-            CALL trd_tra( kt, 'TRC', jn, jptra_nsr, ztrtrd )
+            ztrtrd(:,:,:) = ptr(:,:,:,jn,Krhs) - ztrtrd(:,:,:)
+            CALL trd_tra( kt, Kmm, Krhs, 'TRC', jn, jptra_nsr, ztrtrd )
          END IF
          !                                                       ! ===========
@@ -191,7 +186,7 @@
       ENDIF
       !
-      IF( ln_ctl )   THEN
-         WRITE(charout, FMT="('sbc ')") ;  CALL prt_ctl_trc_info(charout)
-                                           CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
+      IF( sn_cfctl%l_prttrc )   THEN
+         WRITE(charout, FMT="('sbc ')") ;  CALL prt_ctl_info( charout, cdcomp = 'top' )
+                                           CALL prt_ctl( tab4d_1=ptr(:,:,:,:,Krhs), mask1=tmask, clinfo=ctrcnm, clinfo3='trd' )
       ENDIF
       IF( l_trdtrc )  DEALLOCATE( ztrtrd )
@@ -205,7 +200,11 @@
    !!   Dummy module :                      NO passive tracer
    !!----------------------------------------------------------------------
+   USE par_oce
+   USE par_trc
 CONTAINS
-   SUBROUTINE trc_sbc (kt)              ! Empty routine
-      INTEGER, INTENT(in) :: kt
+   SUBROUTINE trc_sbc ( kt, Kmm, ptr, Krhs )      ! Empty routine
+      INTEGER,                                    INTENT(in   ) :: kt        ! ocean time-step index
+      INTEGER,                                    INTENT(in   ) :: Kmm, Krhs ! time level indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) :: ptr       ! passive tracers and RHS of tracer equation
       WRITE(*,*) 'trc_sbc: You should not have seen this print! error?', kt
    END SUBROUTINE trc_sbc
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcsink.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcsink.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trcsink.F90	(revision 13463)
@@ -24,4 +24,7 @@
    INTEGER, PUBLIC :: nitermax      !: Maximum number of iterations for sinking
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -35,5 +38,5 @@
    !!----------------------------------------------------------------------
 
-   SUBROUTINE trc_sink ( kt, pwsink, psinkflx, jp_tra, rsfact )
+   SUBROUTINE trc_sink ( kt, Kbb, Kmm, pwsink, psinkflx, jp_tra, rsfact )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE trc_sink  ***
@@ -45,4 +48,5 @@
       !!---------------------------------------------------------------------
       INTEGER , INTENT(in)  :: kt
+      INTEGER , INTENT(in)  :: Kbb, Kmm
       INTEGER , INTENT(in)  :: jp_tra    ! tracer index index      
       REAL(wp), INTENT(in)  :: rsfact    ! time step duration
@@ -70,28 +74,25 @@
          iiter(:,:) = 1
       ELSE
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               iiter(ji,jj) = 1
-               DO jk = 1, jpkm1
-                  IF( tmask(ji,jj,jk) == 1.0 ) THEN
-                      zwsmax =  0.5 * e3t_n(ji,jj,jk) * rday / rsfact
-                      iiter(ji,jj) =  MAX( iiter(ji,jj), INT( pwsink(ji,jj,jk) / zwsmax ) )
-                  ENDIF
-               END DO
-            END DO
-         END DO
+         DO_2D( 1, 1, 1, 1 )
+            iiter(ji,jj) = 1
+            DO jk = 1, jpkm1
+               IF( tmask(ji,jj,jk) == 1.0 ) THEN
+                   zwsmax =  0.5 * e3t(ji,jj,jk,Kmm) * rday / rsfact
+                   iiter(ji,jj) =  MAX( iiter(ji,jj), INT( pwsink(ji,jj,jk) / zwsmax ) )
+               ENDIF
+            END DO
+         END_2D
          iiter(:,:) = MIN( iiter(:,:), nitermax )
       ENDIF
 
-      DO jk = 1,jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( tmask(ji,jj,jk) == 1 ) THEN
-                 zwsmax = 0.5 * e3t_n(ji,jj,jk) * rday / rsfact
-                 zwsink(ji,jj,jk) = MIN( pwsink(ji,jj,jk), zwsmax * REAL( iiter(ji,jj), wp ) )
-               ENDIF
-            END DO
-         END DO
-      END DO
+      DO_3D( 1, 1, 1, 1, 1,jpkm1 )
+         IF( tmask(ji,jj,jk) == 1.0 ) THEN
+           zwsmax = 0.5 * e3t(ji,jj,jk,Kmm) * rday / rsfact
+           zwsink(ji,jj,jk) = MIN( pwsink(ji,jj,jk), zwsmax * REAL( iiter(ji,jj), wp ) )
+         ELSE
+           ! provide a default value so there is no use of undefinite value in trc_sink2 for zwsink2 initialization
+           zwsink(ji,jj,jk) = 0.
+         ENDIF
+      END_3D
 
       !  Initializa to zero all the sinking arrays 
@@ -101,5 +102,5 @@
       !   Compute the sedimentation term using trc_sink2 for the considered sinking particle
       !   -----------------------------------------------------
-      CALL trc_sink2( zwsink, psinkflx, jp_tra, iiter, rsfact )
+      CALL trc_sink2( Kbb, Kmm, zwsink, psinkflx, jp_tra, iiter, rsfact )
       !
       IF( ln_timing )   CALL timing_stop('trc_sink')
@@ -107,5 +108,5 @@
    END SUBROUTINE trc_sink
 
-   SUBROUTINE trc_sink2( pwsink, psinkflx, jp_tra, kiter, rsfact )
+   SUBROUTINE trc_sink2( Kbb, Kmm, pwsink, psinkflx, jp_tra, kiter, rsfact )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE trc_sink2  ***
@@ -118,4 +119,5 @@
       !!      transport term, i.e.  div(u*tra).
       !!---------------------------------------------------------------------
+      INTEGER,  INTENT(in   )                         ::   Kbb, Kmm  ! time level indices
       INTEGER,  INTENT(in   )                         ::   jp_tra    ! tracer index index      
       REAL(wp), INTENT(in   )                         ::   rsfact    ! duration of time step
@@ -133,5 +135,5 @@
       ztraz(:,:,:) = 0.e0
       zakz (:,:,:) = 0.e0
-      ztrb (:,:,:) = trb(:,:,:,jp_tra)
+      ztrb (:,:,:) = tr(:,:,:,jp_tra,Kbb)
 
       DO jk = 1, jpkm1
@@ -144,56 +146,50 @@
       DO jn = 1, 2
          !  first guess of the slopes interior values
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               !
-               zstep = rsfact / REAL( kiter(ji,jj), wp ) / 2.
-               !              
-               DO jk = 2, jpkm1
-                  ztraz(ji,jj,jk) = ( trb(ji,jj,jk-1,jp_tra) - trb(ji,jj,jk,jp_tra) ) * tmask(ji,jj,jk)
-               END DO
-               ztraz(ji,jj,1  ) = 0.0
-               ztraz(ji,jj,jpk) = 0.0
-
-               ! slopes
-               DO jk = 2, jpkm1
-                  zign = 0.25 + SIGN( 0.25, ztraz(ji,jj,jk) * ztraz(ji,jj,jk+1) )
-                  zakz(ji,jj,jk) = ( ztraz(ji,jj,jk) + ztraz(ji,jj,jk+1) ) * zign
-               END DO
-         
-               ! Slopes limitation
-               DO jk = 2, jpkm1
-                  zakz(ji,jj,jk) = SIGN( 1., zakz(ji,jj,jk) ) *        &
-                     &             MIN( ABS( zakz(ji,jj,jk) ), 2. * ABS(ztraz(ji,jj,jk+1)), 2. * ABS(ztraz(ji,jj,jk) ) )
-               END DO
-         
-               ! vertical advective flux
-               DO jk = 1, jpkm1
-                  zigma = zwsink2(ji,jj,jk+1) * zstep / e3w_n(ji,jj,jk+1)
-                  zew   = zwsink2(ji,jj,jk+1)
-                  psinkflx(ji,jj,jk+1) = -zew * ( trb(ji,jj,jk,jp_tra) - 0.5 * ( 1 + zigma ) * zakz(ji,jj,jk) ) * zstep
-               END DO
-               !
-               ! Boundary conditions
-               psinkflx(ji,jj,1  ) = 0.e0
-               psinkflx(ji,jj,jpk) = 0.e0
-         
-               DO jk=1,jpkm1
-                  zflx = ( psinkflx(ji,jj,jk) - psinkflx(ji,jj,jk+1) ) / e3t_n(ji,jj,jk)
-                  trb(ji,jj,jk,jp_tra) = trb(ji,jj,jk,jp_tra) + zflx
-               END DO
-            END DO
-         END DO
+         DO_2D( 1, 1, 1, 1 )
+            !
+            zstep = rsfact / REAL( kiter(ji,jj), wp ) / 2.
+            !              
+            DO jk = 2, jpkm1
+               ztraz(ji,jj,jk) = ( tr(ji,jj,jk-1,jp_tra,Kbb) - tr(ji,jj,jk,jp_tra,Kbb) ) * tmask(ji,jj,jk)
+            END DO
+            ztraz(ji,jj,1  ) = 0.0
+            ztraz(ji,jj,jpk) = 0.0
+
+            ! slopes
+            DO jk = 2, jpkm1
+               zign = 0.25 + SIGN( 0.25_wp, ztraz(ji,jj,jk) * ztraz(ji,jj,jk+1) )
+               zakz(ji,jj,jk) = ( ztraz(ji,jj,jk) + ztraz(ji,jj,jk+1) ) * zign
+            END DO
+      
+            ! Slopes limitation
+            DO jk = 2, jpkm1
+               zakz(ji,jj,jk) = SIGN( 1.0_wp, zakz(ji,jj,jk) ) *        &
+                  &             MIN( ABS( zakz(ji,jj,jk) ), 2. * ABS(ztraz(ji,jj,jk+1)), 2. * ABS(ztraz(ji,jj,jk) ) )
+            END DO
+      
+            ! vertical advective flux
+            DO jk = 1, jpkm1
+               zigma = zwsink2(ji,jj,jk+1) * zstep / e3w(ji,jj,jk+1,Kmm)
+               zew   = zwsink2(ji,jj,jk+1)
+               psinkflx(ji,jj,jk+1) = -zew * ( tr(ji,jj,jk,jp_tra,Kbb) - 0.5 * ( 1 + zigma ) * zakz(ji,jj,jk) ) * zstep
+            END DO
+            !
+            ! Boundary conditions
+            psinkflx(ji,jj,1  ) = 0.e0
+            psinkflx(ji,jj,jpk) = 0.e0
+      
+            DO jk=1,jpkm1
+               zflx = ( psinkflx(ji,jj,jk) - psinkflx(ji,jj,jk+1) ) / e3t(ji,jj,jk,Kmm)
+               tr(ji,jj,jk,jp_tra,Kbb) = tr(ji,jj,jk,jp_tra,Kbb) + zflx
+            END DO
+         END_2D
       END DO
 
-      DO jk = 1,jpkm1
-         DO jj = 1,jpj
-            DO ji = 1, jpi
-               zflx = ( psinkflx(ji,jj,jk) - psinkflx(ji,jj,jk+1) ) / e3t_n(ji,jj,jk)
-               ztrb(ji,jj,jk) = ztrb(ji,jj,jk) + 2. * zflx
-            END DO
-         END DO
-      END DO
-
-      trb(:,:,:,jp_tra) = ztrb(:,:,:)
+      DO_3D( 1, 1, 1, 1, 1,jpkm1 )
+         zflx = ( psinkflx(ji,jj,jk) - psinkflx(ji,jj,jk+1) ) / e3t(ji,jj,jk,Kmm)
+         ztrb(ji,jj,jk) = ztrb(ji,jj,jk) + 2. * zflx
+      END_3D
+
+      tr(:,:,:,jp_tra,Kbb) = ztrb(:,:,:)
       psinkflx(:,:,:)   = 2. * psinkflx(:,:,:)
       !
@@ -213,10 +209,8 @@
       !!----------------------------------------------------------------------
       !
-      REWIND( numnat_ref )              ! namtrc_rad in reference namelist 
       READ  ( numnat_ref, namtrc_snk, IOSTAT = ios, ERR = 907)
-907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_snk in reference namelist', lwp )
-      REWIND( numnat_cfg )              ! namtrc_rad in configuration namelist 
+907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_snk in reference namelist' )
       READ  ( numnat_cfg, namtrc_snk, IOSTAT = ios, ERR = 908 )
-908   IF( ios > 0 )   CALL ctl_nam ( ios , 'namtrc_snk in configuration namelist', lwp )
+908   IF( ios > 0 )   CALL ctl_nam ( ios , 'namtrc_snk in configuration namelist' )
       IF(lwm) WRITE( numont, namtrc_snk )
 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trctrp.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trctrp.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trctrp.F90	(revision 13463)
@@ -20,7 +20,8 @@
    USE trcadv          ! advection                           (trc_adv routine)
    USE trczdf          ! vertical diffusion                  (trc_zdf routine)
-   USE trcnxt          ! time-stepping                       (trc_nxt routine)
+   USE trcatf          ! time filtering                      (trc_atf routine)
    USE trcrad          ! positivity                          (trc_rad routine)
    USE trcsbc          ! surface boundary condition          (trc_sbc routine)
+   USE trcbc           ! Tracers boundary condtions          ( trc_bc routine)
    USE zpshde          ! partial step: hor. derivative       (zps_hde routine)
    USE bdy_oce   , ONLY: ln_bdy
@@ -44,5 +45,5 @@
 CONTAINS
 
-   SUBROUTINE trc_trp( kt )
+   SUBROUTINE trc_trp( kt, Kbb, Kmm, Krhs, Kaa )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE trc_trp  ***
@@ -53,5 +54,6 @@
       !!              - Update the passive tracers
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::  kt  ! ocean time-step index
+      INTEGER, INTENT( in ) :: kt                  ! ocean time-step index
+      INTEGER, INTENT( in ) :: Kbb, Kmm, Krhs, Kaa ! time level indices (not swapped in this routine)
       !! ---------------------------------------------------------------------
       !
@@ -60,32 +62,42 @@
       IF( .NOT. lk_c1d ) THEN
          !
-                                CALL trc_sbc    ( kt )      ! surface boundary condition
-         IF( ln_trabbl )        CALL trc_bbl    ( kt )      ! advective (and/or diffusive) bottom boundary layer scheme
-         IF( ln_trcdmp )        CALL trc_dmp    ( kt )      ! internal damping trends
-         IF( ln_bdy )           CALL trc_bdy_dmp( kt )      ! BDY damping trends
-                                CALL trc_adv    ( kt )      ! horizontal & vertical advection 
+                                CALL trc_sbc    ( kt,      Kmm, tr, Krhs )      ! surface boundary condition
+         IF( ln_trcbc .AND. lltrcbc .AND. kt /= nit000 )  &
+                                CALL trc_bc     ( kt,      Kmm, tr, Krhs )      ! tracers: surface and lateral Boundary Conditions 
+         IF( ln_trabbl )        CALL trc_bbl    ( kt, Kbb, Kmm, tr, Krhs )      ! advective (and/or diffusive) bottom boundary layer scheme
+         IF( ln_trcdmp )        CALL trc_dmp    ( kt, Kbb, Kmm, tr, Krhs )      ! internal damping trends
+         IF( ln_bdy )           CALL trc_bdy_dmp( kt, Kbb,      Krhs )      ! BDY damping trends
+                                CALL trc_adv    ( kt, Kbb, Kmm, tr, Krhs )      ! horizontal & vertical advection 
          !                                                         ! Partial top/bottom cell: GRADh( trb )  
          IF( ln_zps ) THEN
-           IF( ln_isfcav ) THEN ; CALL zps_hde_isf( kt, jptra, trb, pgtu=gtru, pgtv=gtrv, pgtui=gtrui, pgtvi=gtrvi )  ! both top & bottom
-           ELSE                 ; CALL zps_hde    ( kt, jptra, trb, gtru, gtrv )                                      !  only bottom
+           IF( ln_isfcav ) THEN ; CALL zps_hde_isf( kt, Kmm, jptra, tr(:,:,:,:,Kbb), pgtu=gtru, pgtv=gtrv, pgtui=gtrui, pgtvi=gtrvi )  ! both top & bottom
+           ELSE                 ; CALL zps_hde    ( kt, Kmm, jptra, tr(:,:,:,:,Kbb), gtru, gtrv )                                      !  only bottom
            ENDIF
          ENDIF
          !                                                      
-                                CALL trc_ldf    ( kt )      ! lateral mixing
+                                CALL trc_ldf    ( kt, Kbb, Kmm,       tr, Krhs )  ! lateral mixing
 #if defined key_agrif
          IF(.NOT. Agrif_Root()) CALL Agrif_Sponge_trc       ! tracers sponge
 #endif
-                                CALL trc_zdf    ( kt )      ! vertical mixing and after tracer fields
-                                CALL trc_nxt    ( kt )      ! tracer fields at next time step     
-         IF( ln_trcrad )        CALL trc_rad    ( kt )      ! Correct artificial negative concentrations
-         IF( ln_trcdmp_clo )    CALL trc_dmp_clo( kt )      ! internal damping trends on closed seas only
+                                CALL trc_zdf    ( kt, Kbb, Kmm, Krhs, tr, Kaa  )  ! vert. mixing & after tracer	==> after
+                                CALL trc_atf    ( kt, Kbb, Kmm, Kaa , tr )        ! time filtering of "now" tracer fields    
+         !
+         ! Subsequent calls use the filtered values: Kmm and Kaa 
+         ! These are used explicitly here since time levels will not be swapped until after tra_atf/dyn_atf/ssh_atf in stp
+         !
+         IF( ln_trcrad )        CALL trc_rad    ( kt, Kmm, Kaa, tr       )    ! Correct artificial negative concentrations
+         IF( ln_trcdmp_clo )    CALL trc_dmp_clo( kt, Kmm, Kaa )              ! internal damping trends on closed seas only
 
          !
       ELSE                                               ! 1D vertical configuration
-                                CALL trc_sbc( kt )            ! surface boundary condition
-         IF( ln_trcdmp )        CALL trc_dmp( kt )            ! internal damping trends
-                                CALL trc_zdf( kt )            ! vertical mixing and after tracer fields
-                                CALL trc_nxt( kt )            ! tracer fields at next time step     
-          IF( ln_trcrad )       CALL trc_rad( kt )            ! Correct artificial negative concentrations
+                                CALL trc_sbc( kt,      Kmm,       tr, Krhs )  ! surface boundary condition
+         IF( ln_trcdmp )        CALL trc_dmp( kt, Kbb, Kmm,       tr, Krhs )  ! internal damping trends
+                                CALL trc_zdf( kt, Kbb, Kmm, Krhs, tr, Kaa  )  ! vert. mixing & after tracer	==> after
+                                CALL trc_atf( kt, Kbb, Kmm, Kaa , tr )        ! time filtering of "now" tracer fields
+         !
+         ! Subsequent calls use the filtered values: Kmm and Kaa 
+         ! These are used explicitly here since time levels will not be swapped until after tra_atf/dyn_atf/ssh_atf in stp
+         !
+         IF( ln_trcrad )       CALL trc_rad( kt, Kmm, Kaa, tr       )  ! Correct artificial negative concentrations
          !
       END IF
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trczdf.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trczdf.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trczdf.F90	(revision 13463)
@@ -22,5 +22,5 @@
 !!gm
    USE trdtra        ! trends manager: tracers 
-   USE prtctl_trc    ! Print control
+   USE prtctl        ! Print control
 
    IMPLICIT NONE
@@ -36,5 +36,5 @@
 CONTAINS
 
-   SUBROUTINE trc_zdf( kt )
+   SUBROUTINE trc_zdf( kt, Kbb, Kmm, Krhs, ptr, Kaa )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE trc_zdf  ***
@@ -43,5 +43,7 @@
       !!              an implicit time-stepping scheme.
       !!---------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::  kt      ! ocean time-step index
+      INTEGER                                   , INTENT(in   ) ::   kt                   ! ocean time-step index
+      INTEGER                                   , INTENT(in   ) ::   Kbb, Kmm, Krhs, Kaa  ! ocean time level indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) ::   ptr                  ! passive tracers and RHS of tracer equation
       !
       INTEGER               ::  jk, jn
@@ -52,21 +54,21 @@
       IF( ln_timing )   CALL timing_start('trc_zdf')
       !
-      IF( l_trdtrc )   ztrtrd(:,:,:,:)  = tra(:,:,:,:)
+      IF( l_trdtrc )   ztrtrd(:,:,:,:)  = ptr(:,:,:,:,Krhs)
       !
-      CALL tra_zdf_imp( kt, nittrc000, 'TRC', r2dttrc, trb, tra, jptra )    !   implicit scheme          
+      CALL tra_zdf_imp( kt, nittrc000, 'TRC', rDt_trc, Kbb, Kmm, Krhs, ptr, Kaa, jptra )    !   implicit scheme          
       !
       IF( l_trdtrc )   THEN                      ! save the vertical diffusive trends for further diagnostics
          DO jn = 1, jptra
             DO jk = 1, jpkm1
-               ztrtrd(:,:,jk,jn) = ( ( tra(:,:,jk,jn) - trb(:,:,jk,jn) ) / r2dttrc ) - ztrtrd(:,:,jk,jn)
+               ztrtrd(:,:,jk,jn) = ( ( ptr(:,:,jk,jn,Kaa) - ptr(:,:,jk,jn,Kbb) ) / rDt_trc ) - ztrtrd(:,:,jk,jn)
             END DO
-            CALL trd_tra( kt, 'TRC', jn, jptra_zdf, ztrtrd(:,:,:,jn) )
+            CALL trd_tra( kt, Kmm, Krhs, 'TRC', jn, jptra_zdf, ztrtrd(:,:,:,jn) )
          END DO
       ENDIF
       !                                          ! print mean trends (used for debugging)
-      IF( ln_ctl )   THEN
+      IF( sn_cfctl%l_prttrc )   THEN
          WRITE(charout, FMT="('zdf ')")
-         CALL prt_ctl_trc_info(charout)
-         CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl( tab4d_1=tr(:,:,:,:,Kaa), mask1=tmask, clinfo=ctrcnm, clinfo3='trd' )
       END IF
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trdmxl_trc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trdmxl_trc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trdmxl_trc.F90	(revision 13463)
@@ -16,6 +16,5 @@
    !!   trd_mxl_trc_init : initialization step
    !!----------------------------------------------------------------------
-   USE trc               ! tracer definitions (trn, trb, tra, etc.)
-   USE trc_oce, ONLY :   nn_dttrc  ! frequency of step on passive tracers
+   USE trc               ! tracer definitions (tr etc.)
    USE dom_oce           ! domain definition
    USE zdfmxl  , ONLY : nmln ! number of level in the mixed layer
@@ -50,4 +49,7 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  ztmltrd2   !
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -70,5 +72,5 @@
 
 
-   SUBROUTINE trd_mxl_trc_zint( ptrc_trdmxl, ktrd, ctype, kjn )
+   SUBROUTINE trd_mxl_trc_zint( ptrc_trdmxl, ktrd, ctype, kjn, Kmm )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE trd_mxl_trc_zint  ***
@@ -92,4 +94,5 @@
       !!
       INTEGER, INTENT( in ) ::   ktrd, kjn                        ! ocean trend index and passive tracer rank
+      INTEGER, INTENT( in ) ::   Kmm                              ! time level index
       CHARACTER(len=2), INTENT( in ) ::  ctype                    ! surface/bottom (2D) or interior (3D) physics
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::  ptrc_trdmxl ! passive tracer trend
@@ -108,5 +111,5 @@
          ! ... Set nmld(ji,jj) = index of first T point below control surf. or outside mixed-layer
          SELECT CASE ( nn_ctls_trc )                                ! choice of the control surface
-            CASE ( -2  )   ;   STOP 'trdmxl_trc : not ready '     !     -> isopycnal surface (see ???)
+            CASE ( -2  )   ;   CALL ctl_stop( 'STOP', 'trdmxl_trc : not ready ' )     !     -> isopycnal surface (see ???)
             CASE ( -1  )   ;   nmld_trc(:,:) = neln(:,:)          !     -> euphotic layer with light criterion
             CASE (  0  )   ;   nmld_trc(:,:) = nmln(:,:)          !     -> ML with density criterion (see zdfmxl)
@@ -122,14 +125,12 @@
 
             IF( jpktrd_trc < jpk ) THEN                           ! description ???
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     IF( nmld_trc(ji,jj) <= jpktrd_trc ) THEN
-                        zvlmsk(ji,jj) = tmask(ji,jj,1)
-                     ELSE
-                        isum = isum + 1
-                        zvlmsk(ji,jj) = 0.e0
-                     ENDIF
-                  END DO
-               END DO
+               DO_2D( 1, 1, 1, 1 )
+                  IF( nmld_trc(ji,jj) <= jpktrd_trc ) THEN
+                     zvlmsk(ji,jj) = tmask(ji,jj,1)
+                  ELSE
+                     isum = isum + 1
+                     zvlmsk(ji,jj) = 0.e0
+                  ENDIF
+               END_2D
             ENDIF
 
@@ -147,11 +148,7 @@
          ! ... Weights for vertical averaging
          wkx_trc(:,:,:) = 0.e0
-         DO jk = 1, jpktrd_trc                                    ! initialize wkx_trc with vertical scale factor in mixed-layer
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  IF( jk - nmld_trc(ji,jj) < 0 )   wkx_trc(ji,jj,jk) = e3t_n(ji,jj,jk) * tmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
+         DO_3D( 1, 1, 1, 1, 1, jpktrd_trc )
+            IF( jk - nmld_trc(ji,jj) < 0 )   wkx_trc(ji,jj,jk) = e3t(ji,jj,jk,Kmm) * tmask(ji,jj,jk)
+         END_3D
          
          rmld_trc(:,:) = 0.e0
@@ -183,5 +180,5 @@
 
 
-   SUBROUTINE trd_mxl_trc( kt )
+   SUBROUTINE trd_mxl_trc( kt, Kmm )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE trd_mxl_trc  ***
@@ -232,4 +229,5 @@
       !
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      INTEGER, INTENT(in) ::   Kmm                              ! time level index
       !
       INTEGER ::   ji, jj, jk, jl, ik, it, itmod, jn
@@ -251,6 +249,4 @@
 
 
-      IF( nn_dttrc  /= 1  )   CALL ctl_stop( " Be careful, trends diags never validated " )
-
       ! ======================================================================
       ! I. Diagnose the purely vertical (K_z) diffusion trend
@@ -263,13 +259,11 @@
          !
          DO jn = 1, jptra
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ik = nmld_trc(ji,jj)
-                  IF( ln_trdtrc(jn) )    &
-                  tmltrd_trc(ji,jj,jpmxl_trc_zdf,jn) = - avs(ji,jj,ik) / e3w_n(ji,jj,ik) * tmask(ji,jj,ik)  &
-                       &                    * ( trn(ji,jj,ik-1,jn) - trn(ji,jj,ik,jn) )            &
-                       &                    / MAX( 1., rmld_trc(ji,jj) ) * tmask(ji,jj,1)
-               END DO
-            END DO
+            DO_2D( 1, 1, 1, 1 )
+               ik = nmld_trc(ji,jj)
+               IF( ln_trdtrc(jn) )    &
+               tmltrd_trc(ji,jj,jpmxl_trc_zdf,jn) = - avs(ji,jj,ik) / e3w(ji,jj,ik,Kmm) * tmask(ji,jj,ik)  &
+                    &                    * ( tr(ji,jj,ik-1,jn,Kmm) - tr(ji,jj,ik,jn,Kmm) )            &
+                    &                    / MAX( 1., rmld_trc(ji,jj) ) * tmask(ji,jj,1)
+            END_2D
          END DO
 
@@ -322,5 +316,5 @@
          DO jn = 1, jptra
             IF( ln_trdtrc(jn) ) &
-               tml_trc(:,:,jn) = tml_trc(:,:,jn) + wkx_trc(:,:,jk) * trn(:,:,jk,jn)
+               tml_trc(:,:,jn) = tml_trc(:,:,jn) + wkx_trc(:,:,jk) * tr(:,:,jk,jn,Kmm)
          END DO
       END DO
@@ -328,5 +322,5 @@
       ! II.3 Initialize mixed-layer "before" arrays for the 1rst analysis window    
       ! ------------------------------------------------------------------------
-      IF( kt == nittrc000 + nn_dttrc ) THEN  !  i.e. ( .NOT. ln_rstart ).AND.( kt == nit000 + 1)    ???
+      IF( kt == nittrc000 + 1 ) THEN  !  i.e. ( .NOT. ln_rstart ).AND.( kt == nit000 + 1)    ???
          !
          DO jn = 1, jptra
@@ -408,9 +402,9 @@
          DO jn = 1, jptra
             IF( ln_trdtrc(jn) ) THEN
-               !-- Compute total trends    (use rdttrc instead of rdt ???)
+               !-- Compute total trends 
                IF ( ln_trcadv_muscl .OR. ln_trcadv_muscl2 ) THEN  ! EULER-FORWARD schemes
-                  ztmltot(:,:,jn) =  ( tml_trc(:,:,jn) - tmlbn_trc(:,:,jn) )/rdt
+                  ztmltot(:,:,jn) =  ( tml_trc(:,:,jn) - tmlbn_trc(:,:,jn) )/rn_Dt
                ELSE                                                                     ! LEAP-FROG schemes
-                  ztmltot(:,:,jn) =  ( tml_trc(:,:,jn) - tmlbn_trc(:,:,jn) + tmlb_trc(:,:,jn) - tmlbb_trc(:,:,jn))/(2.*rdt)
+                  ztmltot(:,:,jn) =  ( tml_trc(:,:,jn) - tmlbn_trc(:,:,jn) + tmlb_trc(:,:,jn) - tmlbb_trc(:,:,jn))/(2.*rn_Dt)
                ENDIF
                
@@ -431,5 +425,5 @@
 
 #if defined key_diainstant
-               STOP 'tmltrd_trc : key_diainstant was never checked within trdmxl. Comment this to proceed.'
+               CALL ctl_stop( 'STOP', 'tmltrd_trc : key_diainstant was never checked within trdmxl. Comment this to proceed.' )
 #endif
             ENDIF
@@ -446,5 +440,5 @@
             IF( ln_trdtrc(jn) ) THEN
                tml_sum_trc(:,:,jn) = tmlbn_trc(:,:,jn) + 2 * ( tml_sum_trc(:,:,jn) - tml_trc(:,:,jn) ) + tml_trc(:,:,jn)
-               ztmltot2   (:,:,jn) = ( tml_sum_trc(:,:,jn) - tml_sumb_trc(:,:,jn) ) /  ( 2.*rdt )    ! now tracer unit is /sec
+               ztmltot2   (:,:,jn) = ( tml_sum_trc(:,:,jn) - tml_sumb_trc(:,:,jn) ) /  ( 2.*rn_Dt )    ! now tracer unit is /sec
             ENDIF
          END DO
@@ -857,18 +851,18 @@
 #  if defined key_diainstant
       IF( .NOT. ln_trdmxl_trc_instant ) THEN
-         STOP 'trd_mxl_trc : this was never checked. Comment this line to proceed...'
-      ENDIF
-      zsto = nn_trd_trc * rdt
+         CALL ctl_stop( 'STOP', 'trd_mxl_trc : this was never checked. Comment this line to proceed...' )
+      ENDIF
+      zsto = nn_trd_trc * rn_Dt
       clop = "inst("//TRIM(clop)//")"
 #  else
       IF( ln_trdmxl_trc_instant ) THEN
-         zsto = rdt                                               ! inst. diags : we use IOIPSL time averaging
+         zsto = rn_Dt                                               ! inst. diags : we use IOIPSL time averaging
       ELSE
-         zsto = nn_trd_trc * rdt                                    ! mean  diags : we DO NOT use any IOIPSL time averaging
+         zsto = nn_trd_trc * rn_Dt                                    ! mean  diags : we DO NOT use any IOIPSL time averaging
       ENDIF
       clop = "ave("//TRIM(clop)//")"
 #  endif
-      zout = nn_trd_trc * rdt
-      iiter = ( nittrc000 - 1 ) / nn_dttrc
+      zout = nn_trd_trc * rn_Dt
+      iiter = nittrc000 - 1
 
       IF(lwp) WRITE (numout,*) '                netCDF initialization'
@@ -876,5 +870,5 @@
       ! II.2 Compute julian date from starting date of the run
       ! ------------------------------------------------------
-      CALL ymds2ju( nyear, nmonth, nday, rdt, zjulian )
+      CALL ymds2ju( nyear, nmonth, nday, rn_Dt, zjulian )
       zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
       IF(lwp) WRITE(numout,*)' '  
@@ -908,5 +902,5 @@
             CALL dia_nam( clhstnam, nn_trd_trc, csuff )
             CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,                                            &
-               &        1, jpi, 1, jpj, iiter, zjulian, rdt, nh_t(jn), nidtrd(jn), domain_id=nidom, snc4chunks=snc4set )
+               &        1, jpi, 1, jpj, iiter, zjulian, rn_Dt, nh_t(jn), nidtrd(jn), domain_id=nidom, snc4chunks=snc4set )
       
             !-- Define the ML depth variable
@@ -928,5 +922,5 @@
       !-- Define miscellaneous passive tracer mixed-layer variables 
       IF( jpltrd_trc /= jpmxl_trc_atf .OR.  jpltrd_trc - 1 /= jpmxl_trc_radb ) THEN
-         STOP 'Error : jpltrd_trc /= jpmxl_trc_atf .OR.  jpltrd_trc - 1 /= jpmxl_trc_radb'  ! see below
+         CALL ctl_stop( 'STOP', 'Error : jpltrd_trc /= jpmxl_trc_atf .OR.  jpltrd_trc - 1 /= jpmxl_trc_radb' ) ! see below
       ENDIF
 
@@ -945,5 +939,5 @@
                CALL histdef(nidtrd(jn), trim(clvar)//trim(ctrd_trc(jl,2)), clmxl//" "//clvar//ctrd_trc(jl,1),                      & 
                  &    cltrcu, jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zsto, zout ) ! IOIPSL: time mean
-            END DO                                                                         ! if zsto=rdt above
+            END DO                                                                         ! if zsto=rn_Dt above
          
             CALL histdef(nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmxl_trc_radb,2)), clmxl//" "//clvar//ctrd_trc(jpmxl_trc_radb,1), & 
@@ -970,10 +964,12 @@
    !!----------------------------------------------------------------------
 CONTAINS
-   SUBROUTINE trd_mxl_trc( kt )                                   ! Empty routine
+   SUBROUTINE trd_mxl_trc( kt, Kmm )                                   ! Empty routine
       INTEGER, INTENT( in) ::   kt
+      INTEGER, INTENT( in) ::   Kmm            ! time level index
       WRITE(*,*) 'trd_mxl_trc: You should not have seen this print! error?', kt
    END SUBROUTINE trd_mxl_trc
-   SUBROUTINE trd_mxl_trc_zint( ptrc_trdmxl, ktrd, ctype, kjn )
+   SUBROUTINE trd_mxl_trc_zint( ptrc_trdmxl, ktrd, ctype, kjn, Kmm )
       INTEGER               , INTENT( in ) ::  ktrd, kjn              ! ocean trend index and passive tracer rank
+      INTEGER               , INTENT( in ) ::  Kmm                    ! time level index
       CHARACTER(len=2)      , INTENT( in ) ::  ctype                  ! surface/bottom (2D) or interior (3D) physics
       REAL, DIMENSION(:,:,:), INTENT( in ) ::  ptrc_trdmxl            ! passive trc trend
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trdmxl_trc_rst.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trdmxl_trc_rst.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trdmxl_trc_rst.F90	(revision 13463)
@@ -11,5 +11,5 @@
    USE in_out_manager  ! I/O manager
    USE iom             ! I/O module
-   USE trc             ! for nn_dttrc ctrcnm
+   USE trc             ! for ctrcnm
    USE trdmxl_trc_oce  ! for lk_trdmxl_trc
 
@@ -44,5 +44,5 @@
       !!--------------------------------------------------------------------------------
 
-      IF( kt == nitrst - nn_dttrc .OR. nitend - nit000 + 1 < 2 * nn_dttrc ) THEN ! idem trcrst.F90
+      IF( kt == nitrst - 1 .OR. nitend - nit000 + 1 < 2 ) THEN ! idem trcrst.F90
          IF( nitrst > 1.0e9 ) THEN
             WRITE(clkt,*) nitrst
@@ -144,22 +144,22 @@
          
          DO jn = 1, jptra
-            CALL iom_get( inum, jpdom_autoglo, 'tmlbb_trc_'  //ctrcnm(jn), tmlbb_trc  (:,:,jn) )
-            CALL iom_get( inum, jpdom_autoglo, 'tmlbn_trc_'  //ctrcnm(jn), tmlbn_trc  (:,:,jn) )
-            CALL iom_get( inum, jpdom_autoglo, 'tmlatfb_trc_'//ctrcnm(jn), tmlatfb_trc(:,:,jn) )
-            CALL iom_get( inum, jpdom_autoglo, 'tmlradb_trc_'//ctrcnm(jn), tmlradb_trc(:,:,jn) )
+            CALL iom_get( inum, jpdom_auto, 'tmlbb_trc_'  //ctrcnm(jn), tmlbb_trc  (:,:,jn) )
+            CALL iom_get( inum, jpdom_auto, 'tmlbn_trc_'  //ctrcnm(jn), tmlbn_trc  (:,:,jn) )
+            CALL iom_get( inum, jpdom_auto, 'tmlatfb_trc_'//ctrcnm(jn), tmlatfb_trc(:,:,jn) )
+            CALL iom_get( inum, jpdom_auto, 'tmlradb_trc_'//ctrcnm(jn), tmlradb_trc(:,:,jn) )
          END DO
          
       ELSE
-         CALL iom_get( inum, jpdom_autoglo, 'rmldbn_trc', rmldbn_trc ) ! needed for rmld_sum
+         CALL iom_get( inum, jpdom_auto, 'rmldbn_trc', rmldbn_trc ) ! needed for rmld_sum
          
          !                                                          ! ===========
          DO jn = 1, jptra                                           ! tracer loop
             !                                                       ! ===========
-            CALL iom_get( inum, jpdom_autoglo, 'tmlatfb_trc_' //ctrcnm(jn), tmlatfb_trc(:,:,jn) )
-            CALL iom_get( inum, jpdom_autoglo, 'tmlbb_trc_'   //ctrcnm(jn), tmlbb_trc  (:,:,jn) )
-            CALL iom_get( inum, jpdom_autoglo, 'tmlradb_trc_' //ctrcnm(jn), tmlradb_trc(:,:,jn) )
-
-            CALL iom_get( inum, jpdom_autoglo, 'tmlbn_trc_'   //ctrcnm(jn), tmlbn_trc   (:,:,jn) ) ! needed for tml_sum
-            CALL iom_get( inum, jpdom_autoglo, 'tml_sumb_trc_'//ctrcnm(jn), tml_sumb_trc(:,:,jn) )
+            CALL iom_get( inum, jpdom_auto, 'tmlatfb_trc_' //ctrcnm(jn), tmlatfb_trc(:,:,jn) )
+            CALL iom_get( inum, jpdom_auto, 'tmlbb_trc_'   //ctrcnm(jn), tmlbb_trc  (:,:,jn) )
+            CALL iom_get( inum, jpdom_auto, 'tmlradb_trc_' //ctrcnm(jn), tmlradb_trc(:,:,jn) )
+
+            CALL iom_get( inum, jpdom_auto, 'tmlbn_trc_'   //ctrcnm(jn), tmlbn_trc   (:,:,jn) ) ! needed for tml_sum
+            CALL iom_get( inum, jpdom_auto, 'tml_sumb_trc_'//ctrcnm(jn), tml_sumb_trc(:,:,jn) )
             
             DO jk = 1, jpltrd_trc
@@ -169,11 +169,11 @@
                   WRITE(charout,FMT="('tmltrd_csum_ub_trc_', A3, '_', I2)") ctrcnm(jn), jk
                ENDIF
-               CALL iom_get( inum, jpdom_autoglo, charout, tmltrd_csum_ub_trc(:,:,jk,jn) )
+               CALL iom_get( inum, jpdom_auto, charout, tmltrd_csum_ub_trc(:,:,jk,jn) )
             END DO
             
-            CALL iom_get( inum, jpdom_autoglo, 'tmltrd_atf_sumb_trc_'//ctrcnm(jn) , &
+            CALL iom_get( inum, jpdom_auto, 'tmltrd_atf_sumb_trc_'//ctrcnm(jn) , &
                  &        tmltrd_atf_sumb_trc(:,:,jn) )
 
-            CALL iom_get( inum, jpdom_autoglo, 'tmltrd_rad_sumb_trc_'//ctrcnm(jn) , &
+            CALL iom_get( inum, jpdom_auto, 'tmltrd_rad_sumb_trc_'//ctrcnm(jn) , &
                  &        tmltrd_rad_sumb_trc(:,:,jn) )
             !                                                       ! ===========
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trdtrc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trdtrc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/TRP/trdtrc.F90	(revision 13463)
@@ -13,9 +13,10 @@
    !!   trdtrc      : passive tracer trends 
    !!----------------------------------------------------------------------
-   USE trc               ! tracer definitions (trn, trb, tra, etc.)
+   USE trc               ! tracer definitions (tr(:,:,:,:,Kmm), tr(:,:,:,:,Kbb), tr(:,:,:,:,Krhs), etc.)
    USE trd_oce
    USE trdtrc_oce       ! definition of main arrays used for trends computations
    USE trdmxl_trc        ! Mixed layer trends diag.
    USE iom               ! I/O library
+   USE par_kind
 
    IMPLICIT NONE
@@ -32,9 +33,10 @@
 CONTAINS
 
-   SUBROUTINE trd_trc( ptrtrd, kjn, ktrd, kt )
+   SUBROUTINE trd_trc( ptrtrd, kjn, ktrd, kt, Kmm )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE trd_trc  ***
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in )  ::   kt                                  ! time step
+      INTEGER, INTENT( in )  ::   Kmm                                 ! time level index
       INTEGER, INTENT( in )  ::   kjn                                 ! tracer index
       INTEGER, INTENT( in )  ::   ktrd                                ! tracer trend index
@@ -56,21 +58,21 @@
          !
          SELECT CASE ( ktrd )
-         CASE ( jptra_xad     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_xad, '3D', kjn )
-         CASE ( jptra_yad     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_yad, '3D', kjn )
-         CASE ( jptra_zad     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_zad, '3D', kjn )
-         CASE ( jptra_ldf     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_ldf, '3D', kjn )
-         CASE ( jptra_bbl     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_bbl, '3D', kjn )
+         CASE ( jptra_xad     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_xad, '3D', kjn, Kmm )
+         CASE ( jptra_yad     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_yad, '3D', kjn, Kmm )
+         CASE ( jptra_zad     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_zad, '3D', kjn, Kmm )
+         CASE ( jptra_ldf     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_ldf, '3D', kjn, Kmm )
+         CASE ( jptra_bbl     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_bbl, '3D', kjn, Kmm )
          CASE ( jptra_zdf     )
             IF( ln_trcldf_iso ) THEN
-               CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_ldf, '3D', kjn )
+               CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_ldf, '3D', kjn, Kmm )
             ELSE
-               CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_zdf, '3D', kjn )
+               CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_zdf, '3D', kjn, Kmm )
             ENDIF
-         CASE ( jptra_dmp     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_dmp , '3D', kjn )
-         CASE ( jptra_nsr     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_sbc , '2D', kjn )
-         CASE ( jptra_sms     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_sms , '3D', kjn )
-         CASE ( jptra_radb    )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_radb, '3D', kjn )
-         CASE ( jptra_radn    )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_radn, '3D', kjn )
-         CASE ( jptra_atf     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_atf , '3D', kjn )
+         CASE ( jptra_dmp     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_dmp , '3D', kjn, Kmm )
+         CASE ( jptra_nsr     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_sbc , '2D', kjn, Kmm )
+         CASE ( jptra_sms     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_sms , '3D', kjn, Kmm )
+         CASE ( jptra_radb    )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_radb, '3D', kjn, Kmm )
+         CASE ( jptra_radn    )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_radn, '3D', kjn, Kmm )
+         CASE ( jptra_atf     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_atf , '3D', kjn, Kmm )
          END SELECT
          !
@@ -106,13 +108,16 @@
    !!----------------------------------------------------------------------
 
+   USE par_kind
+
    PUBLIC trd_trc
 
 CONTAINS
 
-   SUBROUTINE trd_trc( ptrtrd, kjn, ktrd, kt )
+   SUBROUTINE trd_trc( ptrtrd, kjn, ktrd, kt, Kmm )
       INTEGER               , INTENT( in )     ::   kt      ! time step
+      INTEGER               , INTENT( in )     ::   Kmm     ! time level index
       INTEGER               , INTENT( in )     ::   kjn     ! tracer index
       INTEGER               , INTENT( in )     ::   ktrd    ! tracer trend index
-      REAL, DIMENSION(:,:,:), INTENT( inout )  ::   ptrtrd  ! Temperature or U trend
+      REAL(wp), DIMENSION(:,:,:), INTENT( inout )  ::   ptrtrd  ! Temperature or U trend
       WRITE(*,*) 'trd_trc : You should not have seen this print! error?', ptrtrd(1,1,1)
       WRITE(*,*) '  "      "      : You should not have seen this print! error?', kjn
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/oce_trc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/oce_trc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/oce_trc.F90	(revision 13463)
@@ -8,4 +8,5 @@
    !!----------------------------------------------------------------------
    !                                            !* Domain size *
+   USE par_oce , ONLY :   jpt      =>   jpt        !: time dimension
    USE par_oce , ONLY :   jpi      =>   jpi        !: first  dimension of grid --> i 
    USE par_oce , ONLY :   jpj      =>   jpj        !: second dimension of grid --> j  
@@ -17,4 +18,27 @@
    USE par_oce , ONLY :   jp_tem   =>   jp_tem     !: indice for temperature
    USE par_oce , ONLY :   jp_sal   =>   jp_sal     !: indice for salinity
+   USE par_oce , ONLY :   nn_hls   =>   nn_hls     !: 
+   USE par_oce , ONLY :   Nis0    =>   Nis0      !: 
+   USE par_oce , ONLY :   Njs0    =>   Njs0      !: 
+   USE par_oce , ONLY :   Nie0    =>   Nie0      !: 
+   USE par_oce , ONLY :   Nje0    =>   Nje0      !: 
+   USE par_oce , ONLY :   Nis1    =>   Nis1      !: 
+   USE par_oce , ONLY :   Njs1    =>   Njs1      !: 
+   USE par_oce , ONLY :   Nie1    =>   Nie1      !: 
+   USE par_oce , ONLY :   Nje1    =>   Nje1      !: 
+   USE par_oce , ONLY :   Nis1nxt2    =>   Nis1nxt2      !: 
+   USE par_oce , ONLY :   Njs1nxt2    =>   Njs1nxt2      !: 
+   USE par_oce , ONLY :   Nie1nxt2    =>   Nie1nxt2      !: 
+   USE par_oce , ONLY :   Nje1nxt2    =>   Nje1nxt2      !: 
+   USE par_oce , ONLY :   Nis2    =>   Nis2      !: 
+   USE par_oce , ONLY :   Njs2    =>   Njs2      !: 
+   USE par_oce , ONLY :   Nie2    =>   Nie2      !: 
+   USE par_oce , ONLY :   Nje2    =>   Nje2      !: 
+   USE par_oce , ONLY :   Ni_0    =>   Ni_0      !: 
+   USE par_oce , ONLY :   Nj_0    =>   Nj_0      !: 
+   USE par_oce , ONLY :   Ni_1    =>   Ni_1      !: 
+   USE par_oce , ONLY :   Nj_1    =>   Nj_1      !: 
+   USE par_oce , ONLY :   Ni_2    =>   Ni_2      !: 
+   USE par_oce , ONLY :   Nj_2    =>   Nj_2      !: 
 
    USE in_out_manager                           !* IO manager *
@@ -33,17 +57,13 @@
 
    !* ocean fields: here now and after fields *
-   USE oce , ONLY :   un      =>    un      !: i-horizontal velocity (m s-1) 
-   USE oce , ONLY :   vn      =>    vn      !: j-horizontal velocity (m s-1)
-   USE oce , ONLY :   wn      =>    wn      !: vertical velocity (m s-1)  
-   USE oce , ONLY :   tsn     =>    tsn     !: 4D array contaning ( tn, sn )
-   USE oce , ONLY :   tsb     =>    tsb     !: 4D array contaning ( tb, sb )
-   USE oce , ONLY :   tsa     =>    tsa     !: 4D array contaning ( ta, sa )
-   USE oce , ONLY :   rhop    =>    rhop    !: potential volumic mass (kg m-3) 
-   USE oce , ONLY :   rhd     =>    rhd     !: in situ density anomalie rhd=(rho-rau0)/rau0 (no units)
-   USE oce , ONLY :   hdivn   =>    hdivn   !: horizontal divergence (1/s)
-   USE oce , ONLY :   sshn    =>    sshn    !: sea surface height at t-point [m]   
-   USE oce , ONLY :   sshb    =>    sshb    !: sea surface height at t-point [m]   
-   USE oce , ONLY :   ssha    =>    ssha    !: sea surface height at t-point [m]   
-   USE oce , ONLY :   rab_n   =>    rab_n   !: local thermal/haline expension ratio at T-points
+   USE oce , ONLY :   uu     =>    uu     !: i-horizontal velocity (m s-1) 
+   USE oce , ONLY :   vv     =>    vv     !: j-horizontal velocity (m s-1)
+   USE oce , ONLY :   ww     =>    ww     !: vertical velocity (m s-1)  
+   USE oce , ONLY :   ts     =>    ts     !: 4D array contaning ( tn, sn )
+   USE oce , ONLY :   rhop   =>    rhop   !: potential volumic mass (kg m-3) 
+   USE oce , ONLY :   rhd    =>    rhd    !: in situ density anomalie rhd=(rho-rho0)/rho0 (no units)
+   USE oce , ONLY :   hdiv   =>    hdiv   !: horizontal divergence (1/s)
+   USE oce , ONLY :   ssh    =>    ssh    !: sea surface height at t-point [m]   
+   USE oce , ONLY :   rab_n  =>    rab_n  !: local thermal/haline expension ratio at T-points
 
    !* surface fluxes *
@@ -65,4 +85,6 @@
    USE traqsr  , ONLY :   rn_abs     =>    rn_abs     !: fraction absorbed in the very near surface
    USE traqsr  , ONLY :   rn_si0     =>    rn_si0     !: very near surface depth of extinction
+   USE traqsr  , ONLY :   nksr       =>    nksr       !: levels below which the light cannot penetrate (depth larger than 391 m)
+   USE traqsr  , ONLY :   rkrgb      =>    rkrgb      !: tabulated attenuation coefficients for RGB absorption
    USE traqsr  , ONLY :   ln_qsr_bio =>    ln_qsr_bio !: flag to use or not the biological fluxes for light
    USE sbcrnf  , ONLY :   rnfmsk     =>    rnfmsk     !: mixed adv scheme in runoffs vicinity (hori.) 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/prtctl_trc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/prtctl_trc.F90	(revision 11396)
+++ 	(revision )
@@ -1,295 +1,0 @@
-MODULE prtctl_trc
-   !!======================================================================
-   !!                         ***  MODULE prtctl_trc  ***
-   !! TOP :   print all SUM trends for each processor domain
-   !!======================================================================
-   !! History :    -   !  2005-07  (C. Talandier) original code for OPA
-   !!             1.0  !  2005-10  (C. Ethe     ) adapted to passive tracer
-   !!----------------------------------------------------------------------
-   !!   prt_ctl_trc      :   control print in mpp for passive tracers
-   !!   prt_ctl_trc_info :   ???
-   !!   prt_ctl_trc_init :   ???
-   !!----------------------------------------------------------------------
-   USE par_trc          ! TOP parameters
-   USE oce_trc          ! ocean space and time domain variables
-   USE prtctl           ! print control for OPA
-
-   IMPLICIT NONE
-   PRIVATE
-
-   INTEGER , DIMENSION(:), ALLOCATABLE ::   numid_trc          !: logical unit 
-   INTEGER , DIMENSION(:), ALLOCATABLE ::   nlditl , nldjtl    !: first, last indoor index for each i-domain
-   INTEGER , DIMENSION(:), ALLOCATABLE ::   nleitl , nlejtl    !: first, last indoor index for each j-domain
-   INTEGER , DIMENSION(:), ALLOCATABLE ::   nimpptl, njmpptl   !: i-, j-indexes for each processor
-   INTEGER , DIMENSION(:), ALLOCATABLE ::   nlcitl , nlcjtl    !: dimensions of every subdomain
-   INTEGER , DIMENSION(:), ALLOCATABLE ::   ibonitl, ibonjtl
-
-   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   tra_ctl         !: previous trend values
-
-   PUBLIC prt_ctl_trc         ! called by all subroutines
-   PUBLIC prt_ctl_trc_info    !
-   PUBLIC prt_ctl_trc_init    ! called by opa.F90
-
-CONTAINS
-
-   SUBROUTINE prt_ctl_trc( tab4d, mask, clinfo, ovlap, kdim, clinfo2 )
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE prt_ctl  ***
-      !!
-      !! ** Purpose : - print sum control 3D arrays over the same area 
-      !!                in mono and mpp case. This way can be usefull when
-      !!                debugging a new parametrization in mono or mpp. 
-      !!
-      !! ** Method  : 2 possibilities exist when setting the ln_ctl parameter to
-      !!                .true. in the ocean namelist:
-      !!              - to debug a MPI run .vs. a mono-processor one; 
-      !!                the control print will be done over each sub-domain.
-      !!                The nictl[se] and njctl[se] parameters in the namelist must 
-      !!                be set to zero and [ij]splt to the corresponding splitted
-      !!                domain in MPI along respectively i-, j- directions.
-      !!              - to debug a mono-processor run over the whole domain/a specific area; 
-      !!                in the first case the nictl[se] and njctl[se] parameters must be set
-      !!                to zero else to the indices of the area to be controled. In both cases
-      !!                isplt and jsplt must be set to 1.
-      !!              - All arguments of the above calling sequence are optional so their
-      !!                name must be explicitly typed if used. For instance if the mask
-      !!                array tmask(:,:,:) must be passed through the prt_ctl subroutine, 
-      !!                it must looks like: CALL prt_ctl( mask=tmask ).
-      !!----------------------------------------------------------------------
-      REAL(wp)         , DIMENSION(:,:,:,:), INTENT(in), OPTIONAL ::   tab4d     ! 4D array
-      REAL(wp)         , DIMENSION(:,:,:)  , INTENT(in), OPTIONAL ::   mask      ! 3D mask to apply to the tab4d array
-      CHARACTER (len=*), DIMENSION(:)      , INTENT(in), OPTIONAL ::   clinfo    ! information about the tab3d array
-      CHARACTER (len=*)                    , INTENT(in), OPTIONAL ::   clinfo2   ! ???
-      INTEGER                              , INTENT(in), OPTIONAL ::   ovlap     ! overlap value
-      INTEGER                              , INTENT(in), OPTIONAL ::   kdim      ! k- direction for 4D arrays
-      !!
-      INTEGER  ::   overlap, jn, js, sind, eind, kdir, j_id
-      REAL(wp) ::   zsum, zvctl
-      CHARACTER (len=20), ALLOCATABLE, DIMENSION(:) ::   cl
-      CHARACTER (len=10) ::   cl2
-      REAL(wp), DIMENSION(jpi,jpj,jpk)  :: zmask, ztab3d 
-      !!----------------------------------------------------------------------
-
-      ALLOCATE( cl(jptra) )
-      !                                      ! Arrays, scalars initialization 
-      overlap       = 0
-      kdir          = jpkm1
-      zsum          = 0.e0
-      zvctl         = 0.e0
-      cl(:)         = ''
-      cl2           = ''
-      ztab3d(:,:,:) = 0.e0
-      zmask (:,:,:) = 1.e0
-
-      !                                      ! Control of optional arguments
-      IF( PRESENT(ovlap)   )   overlap       = ovlap
-      IF( PRESENT(kdim)    )   kdir          = kdim
-      IF( PRESENT(clinfo ) )   cl(:)         = clinfo(:)
-      IF( PRESENT(clinfo2) )   cl2           = clinfo2
-      IF( PRESENT(mask)    )   zmask (:,:,:) = mask(:,:,:)
-
-      IF( lk_mpp )   THEN      ! processor number
-         sind = narea
-         eind = narea
-      ELSE                     ! processors total number
-         sind = 1
-         eind = ijsplt
-      ENDIF
-
-      ! Loop over each sub-domain, i.e. the total number of processors ijsplt
-      DO js = sind, eind
-         !
-         ! Set logical unit
-         j_id = numid_trc( js - narea + 1 )
-         ! Set indices for the SUM control
-         IF( .NOT. lsp_area ) THEN
-            IF (lk_mpp )   THEN
-               nictls = MAX( 1, nlditl(js) - overlap )
-               nictle = nleitl(js) + overlap * MIN( 1, nlcitl(js) - nleitl(js)) 
-               njctls = MAX( 1, nldjtl(js) - overlap )
-               njctle = nlejtl(js) + overlap * MIN( 1, nlcjtl(js) - nlejtl(js))
-               ! Do not take into account the bound of the domain
-               IF( ibonitl(js) == -1 .OR. ibonitl(js) == 2 )   nictls = MAX( 2, nictls )
-               IF( ibonitl(js) ==  1 .OR. ibonitl(js) == 2 )   nictle = MIN( nictle, nleitl(js) - 1 )
-               IF( ibonjtl(js) == -1 .OR. ibonjtl(js) == 2 )   njctls = MAX( 2, njctls )
-               IF( ibonjtl(js) ==  1 .OR. ibonjtl(js) == 2 )   njctle = MIN( njctle, nlejtl(js) - 1 )
-            ELSE
-               nictls = MAX( 1, nimpptl(js) + nlditl(js) - 1 - overlap )
-               nictle = nimpptl(js) + nleitl(js) - 1 + overlap * MIN( 1, nlcitl(js) - nleitl(js) ) 
-               njctls = MAX( 1, njmpptl(js) + nldjtl(js) - 1 - overlap )
-               njctle = njmpptl(js) + nlejtl(js) - 1 + overlap * MIN( 1, nlcjtl(js) - nlejtl(js) ) 
-               ! Do not take into account the bound of the domain
-               IF( ibonitl(js) == -1 .OR. ibonitl(js) == 2 )   nictls = MAX( 2, nictls )
-               IF( ibonjtl(js) == -1 .OR. ibonjtl(js) == 2 )   njctls = MAX( 2, njctls )
-               IF( ibonitl(js) ==  1 .OR. ibonitl(js) == 2 )   nictle = MIN( nictle, nimpptl(js) + nleitl(js) - 2 )
-               IF( ibonjtl(js) ==  1 .OR. ibonjtl(js) == 2 )   njctle = MIN( njctle, njmpptl(js) + nlejtl(js) - 2 )
-            ENDIF
-         ENDIF
-         !
-         IF( PRESENT(clinfo2) ) THEN
-            DO jn = 1, jptra
-               zvctl  = tra_ctl(jn,js)
-               ztab3d(:,:,:) = tab4d(:,:,:,jn)
-               zsum          = SUM( ztab3d(nictls:nictle,njctls:njctle,1:kdir)   &
-                  &                * zmask(nictls:nictle,njctls:njctle,1:kdir) )
-               WRITE(j_id,FMT="(3x,a,' : ',D23.16)") cl(jn), zsum-zvctl
-               tra_ctl(jn,js) = zsum
-            END DO
-         ELSE
-            DO jn = 1, jptra
-               ztab3d(:,:,:) = tab4d(:,:,:,jn)
-               zsum          = SUM( ztab3d(nictls:nictle,njctls:njctle,1:kdir)   &
-                  &               *  zmask(nictls:nictle,njctls:njctle,1:kdir) )
-               WRITE(j_id,FMT="(3x,a,' : ',D23.16)") cl(jn), zsum
-            END DO
-         ENDIF
-         !
-      END DO
-      !
-      DEALLOCATE( cl )
-      !
-   END SUBROUTINE prt_ctl_trc
-
-
-   SUBROUTINE prt_ctl_trc_info( clinfo )
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE prt_ctl_trc_info  ***
-      !!
-      !! ** Purpose : - print information without any computation
-      !!----------------------------------------------------------------------
-      CHARACTER (len=*), INTENT(in) ::   clinfo      ! information to print
-      !! 
-      INTEGER ::   js, sind, eind, j_id
-      !!----------------------------------------------------------------------
-
-      IF( lk_mpp ) THEN      ! processor number
-         sind = narea
-         eind = narea
-      ELSE                   ! total number of processors
-         sind = 1
-         eind = ijsplt
-      ENDIF
-
-      ! Loop over each sub-domain, i.e. number of processors ijsplt
-      DO js = sind, eind
-         j_id = numid_trc(js - narea + 1)
-         WRITE(j_id,*) clinfo
-      END DO
-      !
-   END SUBROUTINE prt_ctl_trc_info
-
-
-   SUBROUTINE prt_ctl_trc_init
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE prt_ctl_trc_init  ***
-      !!
-      !! ** Purpose :   open ASCII files & compute indices
-      !!----------------------------------------------------------------------
-      INTEGER            ::   js, sind, eind, j_id
-      CHARACTER (len=31) :: clfile_out
-      CHARACTER (len=27) :: clb_name
-      CHARACTER (len=19) :: cl_run
-      !!----------------------------------------------------------------------
-
-      !                             ! Allocate arrays
-      ALLOCATE( nlditl (ijsplt) )
-      ALLOCATE( nldjtl (ijsplt) )
-      ALLOCATE( nleitl (ijsplt) )
-      ALLOCATE( nlejtl (ijsplt) )
-      ALLOCATE( nimpptl(ijsplt) )
-      ALLOCATE( njmpptl(ijsplt) )
-      ALLOCATE( nlcitl (ijsplt) )
-      ALLOCATE( nlcjtl (ijsplt) )
-      ALLOCATE( tra_ctl(jptra,ijsplt) )
-      ALLOCATE( ibonitl(ijsplt) )
-      ALLOCATE( ibonjtl(ijsplt) )
-
-      tra_ctl(:,:) = 0.e0           ! Initialization to zero
-
-      IF( lk_mpp ) THEN
-         sind = narea
-         eind = narea
-         clb_name = "('mpp.top.output_',I4.4)"
-         cl_run = 'MULTI processor run'
-         ! use indices for each area computed by mpp_init subroutine
-         nlditl(1:jpnij) = nldit(:) 
-         nleitl(1:jpnij) = nleit(:) 
-         nldjtl(1:jpnij) = nldjt(:) 
-         nlejtl(1:jpnij) = nlejt(:) 
-         !
-         nimpptl(1:jpnij) = nimppt(:)
-         njmpptl(1:jpnij) = njmppt(:)
-         !
-         nlcitl(1:jpnij) = nlcit(:)
-         nlcjtl(1:jpnij) = nlcjt(:)
-         !
-         ibonitl(1:jpnij) = ibonit(:)
-         ibonjtl(1:jpnij) = ibonjt(:)
-      ELSE
-         sind = 1
-         eind = ijsplt
-         clb_name = "('mono.top.output_',I4.4)"
-         cl_run   = 'MONO processor run '
-         ! compute indices for each area as done in mpp_init subroutine
-         CALL sub_dom
-      ENDIF
-
-      ALLOCATE( numid_trc(eind-sind+1) )
-
-      DO js = sind, eind
-         WRITE(clfile_out,FMT=clb_name) js-1
-         CALL ctl_opn( numid_trc(js -narea + 1), clfile_out, 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
-         j_id = numid_trc(js -narea + 1)
-         WRITE(j_id,*)
-         WRITE(j_id,*) '                 L O D Y C - I P S L'
-         WRITE(j_id,*) '                       N E M 0 '
-         WRITE(j_id,*) '            Ocean General Circulation Model'
-         WRITE(j_id,*) '               version TOP 1.0  (2005) '
-         WRITE(j_id,*)
-         WRITE(j_id,*) '                   PROC number: ', js
-         WRITE(j_id,*)
-         WRITE(j_id,FMT="(19x,a20)") cl_run
-
-         ! Print the SUM control indices
-         IF( .NOT. lsp_area )   THEN
-            IF ( lk_mpp )   THEN
-               nictls = nlditl(js) 
-               nictle = nleitl(js)
-               njctls = nldjtl(js)
-               njctle = nlejtl(js)
-            ELSE
-               nictls = nimpptl(js) + nlditl(js) - 1
-               nictle = nimpptl(js) + nleitl(js) - 1
-               njctls = njmpptl(js) + nldjtl(js) - 1
-               njctle = njmpptl(js) + nlejtl(js) - 1
-            ENDIF
-         ENDIF
-         WRITE(j_id,*) 
-         WRITE(j_id,*) 'prt_tra_ctl :  Sum control indices'
-         WRITE(j_id,*) '~~~~~~~'
-         WRITE(j_id,*)
-         WRITE(j_id,9000)'                                nlej   = ', nlejtl(js), '              '
-         WRITE(j_id,9000)'                  ------------- njctle = ', njctle, ' -------------'
-         WRITE(j_id,9001)'                  |                                       |'
-         WRITE(j_id,9001)'                  |                                       |'
-         WRITE(j_id,9001)'                  |                                       |'
-         WRITE(j_id,9002)'           nictls = ', nictls,  '                           nictle = ', nictle
-         WRITE(j_id,9002)'           nldi   = ', nlditl(js),  '                           nlei   = ', nleitl(js)
-         WRITE(j_id,9001)'                  |                                       |'
-         WRITE(j_id,9001)'                  |                                       |'
-         WRITE(j_id,9001)'                  |                                       |'
-         WRITE(j_id,9004)'  njmpp  = ',njmpptl(js),'   ------------- njctls = ', njctls, ' -------------'
-         WRITE(j_id,9003)'           nimpp  = ', nimpptl(js), '        nldj   = ', nldjtl(js), '              '
-         WRITE(j_id,*)
-         WRITE(j_id,*)
-
-9000     FORMAT(a41,i4.4,a14)
-9001     FORMAT(a59)
-9002     FORMAT(a20,i4.4,a36,i3.3)
-9003     FORMAT(a20,i4.4,a17,i4.4)
-9004     FORMAT(a11,i4.4,a26,i4.4,a14)
-      END DO
-      !
-   END SUBROUTINE prt_ctl_trc_init
-
-END MODULE prtctl_trc
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trc.F90	(revision 13463)
@@ -18,13 +18,13 @@
 
    !                                     !!- logical units of passive tracers
-   INTEGER, PUBLIC ::   numnat_ref = -1   !: reference passive tracer namelist_top_ref
-   INTEGER, PUBLIC ::   numnat_cfg = -1   !: reference passive tracer namelist_top_cfg
    INTEGER, PUBLIC ::   numont     = -1   !: reference passive tracer namelist output output.namelist.top
-   INTEGER, PUBLIC ::   numtrc_ref = -1   !: reference passive tracer namelist_top_ref
-   INTEGER, PUBLIC ::   numtrc_cfg = -1   !: reference passive tracer namelist_top_cfg
    INTEGER, PUBLIC ::   numonr     = -1   !: reference passive tracer namelist output output.namelist.top
    INTEGER, PUBLIC ::   numstr            !: tracer statistics
    INTEGER, PUBLIC ::   numrtr            !: trc restart (read )
    INTEGER, PUBLIC ::   numrtw            !: trc restart ( write )
+   CHARACTER(:), ALLOCATABLE, PUBLIC ::   numnat_ref   !: character buffer for reference passive tracer namelist_top_ref
+   CHARACTER(:), ALLOCATABLE, PUBLIC ::   numnat_cfg   !: character buffer for configuration specific passive tracer namelist_top_cfg
+   CHARACTER(:), ALLOCATABLE, PUBLIC ::   numtrc_ref   !: character buffer for reference passive tracer namelist_trc_ref
+   CHARACTER(:), ALLOCATABLE, PUBLIC ::   numtrc_cfg   !: character buffer for configuration specific passive tracer namelist_trc_cfg
 
    !! passive tracers fields (before,now,after)
@@ -33,7 +33,5 @@
    REAL(wp), PUBLIC                                        ::  areatot        !: total volume 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:  ) ::  cvol           !: volume correction -degrad option- 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  trn            !: tracer concentration for now time step
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  tra            !: tracer concentration for next time step
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  trb            !: tracer concentration for before time step
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:,:) ::  tr           !: tracer concentration 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:  ) ::  sbc_trc_b      !: Before sbc fluxes for tracers
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:  ) ::  sbc_trc        !: Now sbc fluxes for tracers
@@ -63,8 +61,8 @@
    CHARACTER(len = 80) , PUBLIC ::   cn_trcrst_out      !: suffix of pass. tracer restart name (output)
    CHARACTER(len = 256), PUBLIC ::   cn_trcrst_outdir   !: restart output directory
-   REAL(wp)            , PUBLIC ::   rdttrc             !: passive tracer time step
-   REAL(wp)            , PUBLIC ::   r2dttrc            !: = 2*rdttrc except at nit000 (=rdttrc) if neuler=0
+   REAL(wp)            , PUBLIC ::   rDt_trc            !: = 2*rn_Dt except at nit000 (=rn_Dt) if l_1st_euler=.true.
    LOGICAL             , PUBLIC ::   ln_top_euler       !: boolean term for euler integration 
    LOGICAL             , PUBLIC ::   ln_trcdta          !: Read inputs data from files
+   LOGICAL             , PUBLIC ::   ln_trcbc           !: Enable surface, lateral or open boundaries conditions
    LOGICAL             , PUBLIC ::   ln_trcdmp          !: internal damping flag
    LOGICAL             , PUBLIC ::   ln_trcdmp_clo      !: internal damping flag on closed seas
@@ -117,5 +115,7 @@
    LOGICAL , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ln_trc_cbc    !: Use coastal boundary condition data
    LOGICAL , PUBLIC                                  ::   ln_rnf_ctl    !: remove runoff dilution on tracers
-   REAL(wp), PUBLIC                                  ::   rn_bc_time    !: Time scaling factor for SBC and CBC data (seconds in a day)
+   REAL(wp), PUBLIC                                  ::   rn_sbc_time   !: Time scaling factor for SBC data (seconds in a day)
+   REAL(wp), PUBLIC                                  ::   rn_cbc_time   !: Time scaling factor for CBC data (seconds in a day)
+   LOGICAL , PUBLIC                                  ::   lltrcbc       !: Applying one of the boundary conditions 
    !
    CHARACTER(len=20), PUBLIC, DIMENSION(jp_bdy) :: cn_trc_dflt   ! Default OBC condition for all tracers
@@ -130,4 +130,6 @@
 !$AGRIF_END_DO_NOT_TREAT
    !
+   !! Substitutions
+#include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -147,5 +149,5 @@
       ierr(:) = 0
       !
-      ALLOCATE( trn(jpi,jpj,jpk,jptra), trb(jpi,jpj,jpk,jptra), tra(jpi,jpj,jpk,jptra),       &  
+      ALLOCATE( tr(jpi,jpj,jpk,jptra,jpt)                                             ,       &  
          &      trc_i(jpi,jpj,jptra)  , trc_o(jpi,jpj,jptra)                          ,       &
          &      gtru (jpi,jpj,jptra)  , gtrv (jpi,jpj,jptra)                          ,       &
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcbc.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcbc.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcbc.F90	(revision 13463)
@@ -7,8 +7,4 @@
    !!            3.6 !  2015 (T . Lovato) Revision and BDY support
    !!            4.0 !  2016 (T . Lovato) Include application of sbc and cbc
-   !!----------------------------------------------------------------------
-#if defined key_top
-   !!----------------------------------------------------------------------
-   !!   'key_top'                                                TOP model 
    !!----------------------------------------------------------------------
    !!   trc_bc       :  Apply tracer Boundary Conditions
@@ -44,8 +40,13 @@
    TYPE(FLD), SAVE, PUBLIC, ALLOCATABLE, DIMENSION(:), TARGET  :: sf_trcobc
 #endif
-   TYPE(MAP_POINTER), ALLOCATABLE, DIMENSION(:) :: nbmap_ptr   ! array of pointers to nbmap
+
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP model 
+   !!----------------------------------------------------------------------
 
    !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -55,5 +56,5 @@
 CONTAINS
 
-   SUBROUTINE trc_bc_ini( ntrc )
+   SUBROUTINE trc_bc_ini( ntrc, Kmm )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE trc_bc_ini  ***
@@ -64,5 +65,6 @@
       !!              - allocates passive tracer BC data structure 
       !!----------------------------------------------------------------------
-      INTEGER,INTENT(in) :: ntrc                           ! number of tracers
+      INTEGER, INTENT(in) :: ntrc                          ! number of tracers
+      INTEGER, INTENT(in) ::   Kmm                         ! time level index
       !
       INTEGER            :: jl, jn , ib, ibd, ii, ij, ik   ! dummy loop indices
@@ -82,5 +84,5 @@
       !!
       NAMELIST/namtrc_bc/ cn_dir_obc, sn_trcobc, rn_trofac, cn_dir_sbc, sn_trcsbc, rn_trsfac, & 
-                        & cn_dir_cbc, sn_trccbc, rn_trcfac, ln_rnf_ctl, rn_bc_time
+                        & cn_dir_cbc, sn_trccbc, rn_trcfac, ln_rnf_ctl, rn_sbc_time, rn_cbc_time
       NAMELIST/namtrc_bdy/ cn_trc_dflt, cn_trc, nn_trcdmp_bdy
       !!----------------------------------------------------------------------
@@ -121,20 +123,18 @@
       !
       ! Read Boundary Conditions Namelists
-      REWIND( numnat_ref )              ! Namelist namtrc_bc in reference namelist : Passive tracer data structure
       READ  ( numnat_ref, namtrc_bc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_bc in reference namelist', lwp )
-      REWIND( numnat_cfg )              ! Namelist namtrc_bc in configuration namelist : Passive tracer data structure
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_bc in reference namelist' )
       READ  ( numnat_cfg, namtrc_bc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_bc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_bc in configuration namelist' )
       IF(lwm) WRITE ( numont, namtrc_bc )
 
       IF ( ln_bdy ) THEN
-         REWIND( numnat_ref )              ! Namelist namtrc_bdy in reference namelist : Passive tracer data structure
          READ  ( numnat_ref, namtrc_bdy, IOSTAT = ios, ERR = 903)
-903      IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_bdy in reference namelist', lwp )
-
-         REWIND( numnat_cfg )              ! Namelist namtrc_bdy in configuration namelist : Passive tracer data structure
+903      IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_bdy in reference namelist' )
+         ! make sur that all elements of the namelist variables have a default definition from namelist_ref
+         cn_trc     (2:jp_bdy) = cn_trc     (1)
+         cn_trc_dflt(2:jp_bdy) = cn_trc_dflt(1)
          READ  ( numnat_cfg, namtrc_bdy, IOSTAT = ios, ERR = 904 )
-904      IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_bdy in configuration namelist', lwp )
+904      IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_bdy in configuration namelist' )
          IF(lwm) WRITE ( numont, namtrc_bdy )
       
@@ -152,5 +152,5 @@
                IF(trcdta_bdy(jn,ib)%cn_obc == 'frs' .AND. nn_trcdmp_bdy(ib) /= 0 )  &
                    & CALL ctl_stop( 'trc_bc_ini: Use FRS OR relaxation' )
-               IF(  .NOT.( 0 < nn_trcdmp_bdy(ib)  .AND.  nn_trcdmp_bdy(ib) <= 2 )  )   &
+               IF(  .NOT.( 0 <= nn_trcdmp_bdy(ib)  .AND.  nn_trcdmp_bdy(ib) <= 2 )  )   &
                    & CALL ctl_stop( 'trc_bc_ini: Not a valid option for nn_trcdmp_bdy. Allowed: 0,1,2.' )
             END DO
@@ -234,5 +234,5 @@
       ! OPEN Lateral boundary conditions
       IF( ln_bdy .AND. nb_trcobc > 0 ) THEN 
-         ALLOCATE ( sf_trcobc(nb_trcobc), rf_trofac(nb_trcobc), nbmap_ptr(nb_trcobc), STAT=ierr1 )
+         ALLOCATE ( sf_trcobc(nb_trcobc), rf_trofac(nb_trcobc), STAT=ierr1 )
          IF( ierr1 > 0 ) THEN
             CALL ctl_stop( 'trc_bc_ini: unable to allocate sf_trcobc structure' )   ;   RETURN
@@ -257,8 +257,4 @@
                   trcdta_bdy(jn,ib)%trc => sf_trcobc(jl)%fnow(:,1,:)
                   trcdta_bdy(jn,ib)%rn_fac = rf_trofac(jl)
-                  ! create OBC mapping array
-                  nbmap_ptr(jl)%ptr => idx_bdy(ib)%nbmap(:,igrd)
-                  nbmap_ptr(jl)%ll_unstruc = ln_coords_file(igrd)
-                  !
                ELSE                          !* Initialise obc arrays from initial conditions *!
                   ALLOCATE ( trcdta_bdy(jn,ib)%trc(nblen,jpk) )
@@ -267,5 +263,5 @@
                         ii = idx_bdy(ib)%nbi(ibd,igrd)
                         ij = idx_bdy(ib)%nbj(ibd,igrd)
-                        trcdta_bdy(jn,ib)%trc(ibd,ik) = trn(ii,ij,ik,jn) * tmask(ii,ij,ik)
+                        trcdta_bdy(jn,ib)%trc(ibd,ik) = tr(ii,ij,ik,jn,Kmm) * tmask(ii,ij,ik)
                      END DO
                   END DO
@@ -276,4 +272,13 @@
          !
          CALL fld_fill( sf_trcobc, slf_i, cn_dir_obc, 'trc_bc_ini', 'Passive tracer OBC data', 'namtrc_bc' )
+         DO jn = 1, ntrc   ! define imap pointer, must be done after the call to fld_fill
+            DO ib = 1, nb_bdy
+               IF( ln_trc_obc(jn) ) THEN     !* Initialise from external data *!
+                  jl = n_trc_indobc(jn)
+                  sf_trcobc(jl)%imap => idx_bdy(ib)%nbmap(1:idx_bdy(ib)%nblen(igrd),igrd)
+               ENDIF
+            END DO
+         END DO
+         !
       ENDIF
 
@@ -333,5 +338,5 @@
 
 
-   SUBROUTINE trc_bc(kt, jit)
+   SUBROUTINE trc_bc(kt, Kmm, ptr, Krhs, jit)
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE trc_bc  ***
@@ -344,6 +349,8 @@
       USE fldread
       !!      
-      INTEGER, INTENT(in)           ::   kt    ! ocean time-step index
-      INTEGER, INTENT(in), OPTIONAL ::   jit   ! subcycle time-step index (for timesplitting option)
+      INTEGER                                   , INTENT(in)           ::   kt        ! ocean time-step index
+      INTEGER                                   , INTENT(in)           ::   Kmm, Krhs ! time level indices
+      INTEGER                                   , INTENT(in), OPTIONAL ::   jit       ! subcycle time-step index (for timesplitting option)
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) :: ptr            ! passive tracers and RHS of tracer equation
       !!
       INTEGER  :: ji, jj, jk, jn, jl             ! Loop index
@@ -362,8 +369,8 @@
       IF( PRESENT(jit) ) THEN 
          !
-         ! OPEN boundary conditions (use time_offset=+1 as they are applied at the end of the step)
+         ! BDY: use pt_offset=0.5 as applied at the end of the step and fldread is referenced at the middle of the step
          IF( nb_trcobc > 0 ) THEN
            if (lwp) write(numout,'(a,i5,a,i10)') '   reading OBC data for ', nb_trcobc ,' variable(s) at step ', kt
-           CALL fld_read( kt=kt, kn_fsbc=1, sd=sf_trcobc, map=nbmap_ptr, kit=jit, kt_offset=+1)
+           CALL fld_read( kt=kt, kn_fsbc=1, sd=sf_trcobc, kit=jit, pt_offset = 0.5_wp )
          ENDIF
          !
@@ -382,8 +389,8 @@
       ELSE
          !
-         ! OPEN boundary conditions (use time_offset=+1 as they are applied at the end of the step)
+         ! BDY: use pt_offset=0.5 as applied at the end of the step and fldread is referenced at the middle of the step
          IF( nb_trcobc > 0 ) THEN
            if (lwp) write(numout,'(a,i5,a,i10)') '   reading OBC data for ', nb_trcobc ,' variable(s) at step ', kt
-           CALL fld_read( kt=kt, kn_fsbc=1, sd=sf_trcobc, map=nbmap_ptr, kt_offset=+1)
+           CALL fld_read( kt=kt, kn_fsbc=1, sd=sf_trcobc, pt_offset = 0.5_wp )
          ENDIF
          !
@@ -408,12 +415,10 @@
          ! Remove river dilution for tracers with absent river load
          IF( ln_rnf_ctl .AND. .NOT.ln_trc_cbc(jn) ) THEN
-            DO jj = 2, jpj
-               DO ji = fs_2, fs_jpim1
-                  DO jk = 1, nk_rnf(ji,jj)
-                     zrnf = (rnf(ji,jj) + rnf_b(ji,jj)) * 0.5_wp * r1_rau0 / h_rnf(ji,jj)
-                     tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn)  + (trn(ji,jj,jk,jn) * zrnf)
-                  END DO
+            DO_2D( 0, 1, 0, 0 )
+               DO jk = 1, nk_rnf(ji,jj)
+                  zrnf = (rnf(ji,jj) + rnf_b(ji,jj)) * 0.5_wp * r1_rho0 / h_rnf(ji,jj)
+                  ptr(ji,jj,jk,jn,Krhs) = ptr(ji,jj,jk,jn,Krhs)  + (ptr(ji,jj,jk,jn,Kmm) * zrnf)
                END DO
-            END DO
+            END_2D
          ENDIF
          !
@@ -423,23 +428,21 @@
          IF( ln_trc_sbc(jn) ) THEN
             jl = n_trc_indsbc(jn)
-            DO jj = 2, jpj
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zfact = 1. / ( e3t_n(ji,jj,1) * rn_bc_time )
-                  tra(ji,jj,1,jn) = tra(ji,jj,1,jn) + rf_trsfac(jl) * sf_trcsbc(jl)%fnow(ji,jj,1) * zfact
+            sf_trcsbc(jl)%fnow(:,:,1) = MAX( rtrn, sf_trcsbc(jl)%fnow(:,:,1) ) ! avoid nedgative value due to interpolation
+            DO_2D( 0, 1, 0, 0 )
+               zfact = 1. / ( e3t(ji,jj,1,Kmm) * rn_sbc_time )
+               ptr(ji,jj,1,jn,Krhs) = ptr(ji,jj,1,jn,Krhs) + rf_trsfac(jl) * sf_trcsbc(jl)%fnow(ji,jj,1) * zfact
+            END_2D
+         ENDIF
+         !
+         ! COASTAL boundary conditions
+         IF( ( ln_rnf .OR. l_offline ) .AND. ln_trc_cbc(jn) ) THEN
+            IF( l_offline )   rn_rfact = 1._wp
+            jl = n_trc_indcbc(jn)
+            DO_2D( 0, 1, 0, 0 )
+               DO jk = 1, nk_rnf(ji,jj)
+                  zfact = rn_rfact / ( e1e2t(ji,jj) * h_rnf(ji,jj) * rn_cbc_time ) * tmask(ji,jj,1)
+                  ptr(ji,jj,jk,jn,Krhs) = ptr(ji,jj,jk,jn,Krhs) + rf_trcfac(jl) * sf_trccbc(jl)%fnow(ji,jj,1) * zfact
                END DO
-            END DO
-         ENDIF
-         !
-         ! COASTAL boundary conditions
-         IF( ln_rnf .AND. ln_trc_cbc(jn) ) THEN
-            jl = n_trc_indcbc(jn)
-            DO jj = 2, jpj
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  DO jk = 1, nk_rnf(ji,jj)
-                     zfact = rn_rfact / ( e1e2t(ji,jj) * h_rnf(ji,jj) * rn_bc_time ) 
-                     tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + rf_trcfac(jl) * sf_trccbc(jl)%fnow(ji,jj,1) * zfact
-                  END DO
-               END DO
-            END DO
+            END_2D
          ENDIF
          !                                                       ! ===========
@@ -455,10 +458,12 @@
    !!----------------------------------------------------------------------
 CONTAINS
-   SUBROUTINE trc_bc_ini( ntrc )        ! Empty routine
-      INTEGER,INTENT(IN) :: ntrc                           ! number of tracers
-      WRITE(*,*) 'trc_bc_ini: You should not have seen this print! error?', kt
+   SUBROUTINE trc_bc_ini( ntrc, Kmm )        ! Empty routine
+      INTEGER, INTENT(IN) :: ntrc                           ! number of tracers
+      INTEGER, INTENT(in) :: Kmm                            ! time level index
+      WRITE(*,*) 'trc_bc_ini: You should not have seen this print! error?', ntrc, Kmm
    END SUBROUTINE trc_bc_ini
-   SUBROUTINE trc_bc( kt )        ! Empty routine
-      WRITE(*,*) 'trc_bc: You should not have seen this print! error?', kt
+   SUBROUTINE trc_bc( kt, Kmm, Krhs )        ! Empty routine
+      INTEGER, INTENT(in) :: kt, Kmm, Krhs ! time level indices
+      WRITE(*,*) 'trc_bc: You should not have seen this print! error?', kt, Kmm, Krhs 
    END SUBROUTINE trc_bc
 #endif
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcbdy.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcbdy.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcbdy.F90	(revision 13463)
@@ -22,5 +22,5 @@
    USE lbclnk                       ! ocean lateral boundary conditions (or mpp link)
    USE in_out_manager               ! I/O manager
-   USE bdy_oce, only: idx_bdy       ! ocean open boundary conditions
+   USE bdy_oce                      ! ocean open boundary conditions
 
    IMPLICIT NONE
@@ -37,5 +37,5 @@
 CONTAINS
 
-   SUBROUTINE trc_bdy( kt )
+   SUBROUTINE trc_bdy( kt, Kbb, Kmm, Krhs )
       !!----------------------------------------------------------------------
       !!                  ***  SUBROUTINE trc_bdy  ***
@@ -44,9 +44,12 @@
       !!
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) :: kt     ! Main time step counter
+      INTEGER, INTENT( in ) :: kt              ! Main time step counter
+      INTEGER, INTENT( in ) :: Kbb, Kmm, Krhs  ! time level indices
       !!
-      INTEGER                           :: ib_bdy ,jn ,igrd ! Loop indeces
+      INTEGER                           :: ib_bdy ,ir, jn ,igrd ! Loop indices
       REAL(wp), POINTER, DIMENSION(:,:) ::  ztrc
       REAL(wp), POINTER                 ::  zfac
+      LOGICAL                           :: llrim0               ! indicate if rim 0 is treated
+      LOGICAL, DIMENSION(4)             :: llsend1, llrecv1     ! indicate how communications are to be carried out
       !!----------------------------------------------------------------------
       !
@@ -54,32 +57,54 @@
       !
       igrd = 1 
-      !
-      DO ib_bdy=1, nb_bdy
-         DO jn = 1, jptra
-            !
-            ztrc => trcdta_bdy(jn,ib_bdy)%trc 
-            zfac => trcdta_bdy(jn,ib_bdy)%rn_fac
-            !
-            SELECT CASE( TRIM(trcdta_bdy(jn,ib_bdy)%cn_obc) )
-            CASE('none'        )   ;   CYCLE
-            CASE('frs'         )   ;   CALL bdy_frs( idx_bdy(ib_bdy),                tra(:,:,:,jn), ztrc*zfac )
-            CASE('specified'   )   ;   CALL bdy_spe( idx_bdy(ib_bdy),                tra(:,:,:,jn), ztrc*zfac )
-            CASE('neumann'     )   ;   CALL bdy_nmn( idx_bdy(ib_bdy), igrd         , tra(:,:,:,jn) )
-            CASE('orlanski'    )   ;   CALL bdy_orl( idx_bdy(ib_bdy), trb(:,:,:,jn), tra(:,:,:,jn), ztrc*zfac, ll_npo=.false. )
-            CASE('orlanski_npo')   ;   CALL bdy_orl( idx_bdy(ib_bdy), trb(:,:,:,jn), tra(:,:,:,jn), ztrc*zfac, ll_npo=.true. )
-            CASE DEFAULT           ;   CALL ctl_stop( 'trc_bdy : unrecognised option for open boundaries for passive tracers' )
+      llsend1(:) = .false.  ;   llrecv1(:) = .false.
+      DO ir = 1, 0, -1   ! treat rim 1 before rim 0
+         IF( ir == 0 ) THEN   ;   llrim0 = .TRUE.
+         ELSE                 ;   llrim0 = .FALSE.
+         END IF
+         DO ib_bdy=1, nb_bdy
+            DO jn = 1, jptra
+               !
+               ztrc => trcdta_bdy(jn,ib_bdy)%trc 
+               zfac => trcdta_bdy(jn,ib_bdy)%rn_fac
+               !
+               SELECT CASE( TRIM(trcdta_bdy(jn,ib_bdy)%cn_obc) )
+               CASE('none'        )   ;   CYCLE
+               CASE('frs'         )   ! treat the whole boundary at once
+                  IF( ir == 0 ) CALL bdy_frs( idx_bdy(ib_bdy),                tr(:,:,:,jn,Krhs), ztrc*zfac )
+               CASE('specified'   )   ! treat the whole rim      at once
+                  IF( ir == 0 ) CALL bdy_spe( idx_bdy(ib_bdy),                tr(:,:,:,jn,Krhs), ztrc*zfac )
+               CASE('neumann'     )   ;   CALL bdy_nmn( idx_bdy(ib_bdy), igrd         , tr(:,:,:,jn,Krhs) )   ! tra masked
+               CASE('orlanski'    )   ;   CALL bdy_orl( idx_bdy(ib_bdy), tr(:,:,:,jn,Kbb), tr(:,:,:,jn,Krhs), ztrc*zfac, ll_npo=.false. )
+               CASE('orlanski_npo')   ;   CALL bdy_orl( idx_bdy(ib_bdy), tr(:,:,:,jn,Kbb), tr(:,:,:,jn,Krhs), ztrc*zfac, ll_npo=.true. )
+               CASE DEFAULT           ;   CALL ctl_stop( 'trc_bdy : unrecognised option for open boundaries for passive tracers' )
+               END SELECT
+               !
+            END DO
+         END DO
+         !
+         IF( nn_hls > 1 .AND. ir == 1 ) CYCLE   ! at least 2 halos will be corrected -> no need to correct rim 1 before rim 0
+         IF( nn_hls == 1 ) THEN   ;   llsend1(:) = .false.   ;   llrecv1(:) = .false.   ;   END IF
+         DO ib_bdy=1, nb_bdy
+            SELECT CASE( TRIM(cn_tra(ib_bdy)) )
+            CASE('neumann')
+               llsend1(:) = llsend1(:) .OR. lsend_bdyint(ib_bdy,1,:,ir)   ! possibly every direction, T points
+               llrecv1(:) = llrecv1(:) .OR. lrecv_bdyint(ib_bdy,1,:,ir)   ! possibly every direction, T points
+            CASE('orlanski','orlanski_npo')
+               llsend1(:) = llsend1(:) .OR. lsend_bdy(ib_bdy,1,:,ir)   ! possibly every direction, T points
+               llrecv1(:) = llrecv1(:) .OR. lrecv_bdy(ib_bdy,1,:,ir)   ! possibly every direction, T points
             END SELECT
-            ! Boundary points should be updated
-            CALL lbc_bdy_lnk( 'trcbdy', tra(:,:,:,jn), 'T', 1., ib_bdy )
-            !
          END DO
-      END DO
+         IF( ANY(llsend1) .OR. ANY(llrecv1) ) THEN   ! if need to send/recv in at least one direction
+            CALL lbc_lnk( 'trcbdy', tr(:,:,:,:,Krhs), 'T',  1.0_wp, kfillmode=jpfillnothing ,lsend=llsend1, lrecv=llrecv1 )
+         END IF
+         !
+      END DO   ! ir
       !
       IF( ln_timing )   CALL timing_stop('trc_bdy')
-
+      !
    END SUBROUTINE trc_bdy
 
 
-   SUBROUTINE trc_bdy_dmp( kt )
+   SUBROUTINE trc_bdy_dmp( kt, Kbb, Krhs )
       !!----------------------------------------------------------------------
       !!                 ***  SUBROUTINE trc_bdy_dmp  ***
@@ -90,4 +115,5 @@
       !!----------------------------------------------------------------------
       INTEGER,         INTENT(in) ::   kt
+      INTEGER,         INTENT(in) ::   Kbb, Krhs  ! time level indices
       !! 
       INTEGER  ::   jn             ! Tracer index
@@ -110,6 +136,6 @@
                   zwgt = idx_bdy(ib_bdy)%nbd(ib,igrd)
                   DO ik = 1, jpkm1
-                     zta = zwgt * ( trcdta_bdy(jn, ib_bdy)%trc(ib,ik) - trb(ii,ij,ik,jn) ) * tmask(ii,ij,ik)
-                     tra(ii,ij,ik,jn) = tra(ii,ij,ik,jn) + zta
+                     zta = zwgt * ( trcdta_bdy(jn, ib_bdy)%trc(ib,ik) - tr(ii,ij,ik,jn,Kbb) ) * tmask(ii,ij,ik)
+                     tr(ii,ij,ik,jn,Krhs) = tr(ii,ij,ik,jn,Krhs) + zta
                   END DO
                END DO
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcdta.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcdta.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcdta.F90	(revision 13463)
@@ -39,4 +39,7 @@
 !$AGRIF_END_DO_NOT_TREAT
 
+   !! Substitutions
+#include "do_loop_substitute.h90"
+#include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -98,10 +101,8 @@
       ENDIF
       !
-      REWIND( numnat_ref )              ! Namelist namtrc_dta in reference namelist : Passive tracer input data
       READ  ( numnat_ref, namtrc_dta, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_dta_ini in reference namelist', lwp )
-      REWIND( numnat_cfg )              ! Namelist namtrc_dta in configuration namelist : Passive tracer input data
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_dta_ini in reference namelist' )
       READ  ( numnat_cfg, namtrc_dta, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_dta_ini in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_dta_ini in configuration namelist' )
       IF(lwm) WRITE ( numont, namtrc_dta )
 
@@ -154,5 +155,5 @@
 
 
-   SUBROUTINE trc_dta( kt, sf_trcdta, ptrcfac, ptrcdta)
+   SUBROUTINE trc_dta( kt, Kmm, sf_trcdta, ptrcfac, ptrcdta)
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE trc_dta  ***
@@ -167,4 +168,5 @@
       !!----------------------------------------------------------------------
       INTEGER                          , INTENT(in   )   ::   kt         ! ocean time-step
+      INTEGER                          , INTENT(in   )   ::   Kmm        ! time level index
       TYPE(FLD), DIMENSION(1)          , INTENT(inout)   ::   sf_trcdta  ! array of information on the field to read
       REAL(wp)                         , INTENT(in   )   ::   ptrcfac    ! multiplication factor
@@ -178,4 +180,10 @@
       !
       IF( ln_timing )   CALL timing_start('trc_dta')
+      !
+      IF( kt == nit000 .AND. lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trc_dta : passive tracers data for IC'
+         WRITE(numout,*) '~~~~~~~ '
+      ENDIF
       !
       IF( nb_trcdta > 0 ) THEN
@@ -191,27 +199,25 @@
                WRITE(numout,*) 'trc_dta: interpolates passive tracer data onto the s- or mixed s-z-coordinate mesh'
             ENDIF
-            DO jj = 1, jpj                         ! vertical interpolation of T & S
-               DO ji = 1, jpi
-                  DO jk = 1, jpk                        ! determines the intepolated T-S profiles at each (i,j) points
-                     zl = gdept_n(ji,jj,jk)
-                     IF(     zl < gdept_1d(1  ) ) THEN         ! above the first level of data
-                        ztp(jk) = ptrcdta(ji,jj,1)
-                     ELSEIF( zl > gdept_1d(jpk) ) THEN         ! below the last level of data
-                        ztp(jk) = ptrcdta(ji,jj,jpkm1)
-                     ELSE                                      ! inbetween : vertical interpolation between jkk & jkk+1
-                        DO jkk = 1, jpkm1                                  ! when  gdept(jkk) < zl < gdept(jkk+1)
-                           IF( (zl-gdept_1d(jkk)) * (zl-gdept_1d(jkk+1)) <= 0._wp ) THEN
-                              zi = ( zl - gdept_1d(jkk) ) / (gdept_1d(jkk+1)-gdept_1d(jkk))
-                              ztp(jk) = ptrcdta(ji,jj,jkk) + ( ptrcdta(ji,jj,jkk+1) - ptrcdta(ji,jj,jkk) ) * zi
-                           ENDIF
-                        END DO
-                     ENDIF
-                  END DO
-                  DO jk = 1, jpkm1
-                     ptrcdta(ji,jj,jk) = ztp(jk) * tmask(ji,jj,jk)     ! mask required for mixed zps-s-coord
-                  END DO
-                  ptrcdta(ji,jj,jpk) = 0._wp
-                END DO
-            END DO
+            DO_2D( 1, 1, 1, 1 )
+               DO jk = 1, jpk                        ! determines the intepolated T-S profiles at each (i,j) points
+                  zl = gdept(ji,jj,jk,Kmm)
+                  IF(     zl < gdept_1d(1  ) ) THEN         ! above the first level of data
+                     ztp(jk) = ptrcdta(ji,jj,1)
+                  ELSEIF( zl > gdept_1d(jpk) ) THEN         ! below the last level of data
+                     ztp(jk) = ptrcdta(ji,jj,jpkm1)
+                  ELSE                                      ! inbetween : vertical interpolation between jkk & jkk+1
+                     DO jkk = 1, jpkm1                                  ! when  gdept_1d(jkk) < zl < gdept_1d(jkk+1)
+                        IF( (zl-gdept_1d(jkk)) * (zl-gdept_1d(jkk+1)) <= 0._wp ) THEN
+                           zi = ( zl - gdept_1d(jkk) ) / (gdept_1d(jkk+1)-gdept_1d(jkk))
+                           ztp(jk) = ptrcdta(ji,jj,jkk) + ( ptrcdta(ji,jj,jkk+1) - ptrcdta(ji,jj,jkk) ) * zi
+                        ENDIF
+                     END DO
+                  ENDIF
+               END DO
+               DO jk = 1, jpkm1
+                  ptrcdta(ji,jj,jk) = ztp(jk) * tmask(ji,jj,jk)     ! mask required for mixed zps-s-coord
+               END DO
+               ptrcdta(ji,jj,jpk) = 0._wp
+            END_2D
             ! 
          ELSE                                !==   z- or zps- coordinate   ==!
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcice.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcice.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcice.F90	(revision 13463)
@@ -85,10 +85,8 @@
       ENDIF
       !
-      REWIND( numnat_ref )              ! Namelist namtrc_ice in reference namelist : Passive tracer input data
       READ  ( numnat_ref, namtrc_ice, IOSTAT = ios, ERR = 901)
- 901  IF( ios /= 0 )   CALL ctl_nam ( ios , ' namtrc_ice in reference namelist ', lwp )
-      REWIND( numnat_cfg )              ! Namelist namtrc_ice in configuration namelist : Pisces external sources of nutrients
+ 901  IF( ios /= 0 )   CALL ctl_nam ( ios , ' namtrc_ice in reference namelist ' )
       READ  ( numnat_cfg, namtrc_ice, IOSTAT = ios, ERR = 902 )
- 902  IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_ice in configuration namelist', lwp )
+ 902  IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_ice in configuration namelist' )
 
       IF( lwp ) THEN
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcini.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcini.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcini.F90	(revision 13463)
@@ -20,10 +20,9 @@
    USE trcnam          ! Namelist read
    USE daymod          ! calendar manager
-   USE prtctl_trc      ! Print control passive tracers (prt_ctl_trc_init routine)
-   USE trcsub          ! variables to substep passive tracers
+   USE prtctl          ! Print control passive tracers (prt_ctl_init routine)
    USE trcrst
    USE lib_mpp         ! distribued memory computing library
    USE trcice          ! tracers in sea ice
-   USE trcbc,   only : trc_bc_ini ! generalized Boundary Conditions
+   USE trcbc           ! generalized Boundary Conditions
  
    IMPLICIT NONE
@@ -32,4 +31,5 @@
    PUBLIC   trc_init   ! called by opa
 
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -39,5 +39,5 @@
 CONTAINS
    
-   SUBROUTINE trc_init
+   SUBROUTINE trc_init( Kbb, Kmm, Kaa )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE trc_init  ***
@@ -51,4 +51,5 @@
       !!                or read data or analytical formulation
       !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa   ! time level indices
       !
       IF( ln_timing )   CALL timing_start('trc_init')
@@ -58,7 +59,7 @@
       IF(lwp) WRITE(numout,*) '~~~~~~~~'
       !
-      CALL trc_ini_ctl   ! control 
       CALL trc_nam       ! read passive tracers namelists
       CALL top_alloc()   ! allocate TOP arrays
+
       !
       IF(.NOT.ln_trcdta )   ln_trc_ini(:) = .FALSE.
@@ -68,7 +69,7 @@
       IF(lwp) WRITE(numout,*)
       !
-      CALL trc_ini_sms   ! SMS
-      CALL trc_ini_trp   ! passive tracers transport
-      CALL trc_ice_ini   ! Tracers in sea ice
+      CALL trc_ini_sms( Kmm )   ! SMS
+      CALL trc_ini_trp          ! passive tracers transport
+      CALL trc_ice_ini          ! Tracers in sea ice
       !
       IF( lwm .AND. sn_cfctl%l_trcstat ) THEN
@@ -76,9 +77,7 @@
       ENDIF
       !
-      CALL trc_ini_state  !  passive tracers initialisation : from a restart or from clim
-      IF( nn_dttrc /= 1 ) &
-      CALL trc_sub_ini    ! Initialize variables for substepping passive tracers
-      !
-      CALL trc_ini_inv   ! Inventories
+      CALL trc_ini_state( Kbb, Kmm, Kaa )  !  passive tracers initialisation : from a restart or from clim
+      !
+      CALL trc_ini_inv( Kmm )              ! Inventories
       !
       IF( ln_timing )   CALL timing_stop('trc_init')
@@ -87,27 +86,14 @@
 
 
-   SUBROUTINE trc_ini_ctl
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE trc_ini_ctl  ***
-      !! ** Purpose :        Control  + ocean volume
-      !!----------------------------------------------------------------------
-      INTEGER ::   jk    ! dummy loop indices
-      !
-      ! Define logical parameter ton control dirunal cycle in TOP
-      l_trcdm2dc = ln_dm2dc .OR. ( ln_cpl .AND. ncpl_qsr_freq /= 1 )
-      l_trcdm2dc = l_trcdm2dc  .AND. .NOT. l_offline
-      IF( l_trcdm2dc .AND. lwp )   CALL ctl_warn( 'Coupling with passive tracers and used of diurnal cycle.',   &
-         &                           'Computation of a daily mean shortwave for some biogeochemical models ' )
-      !
-   END SUBROUTINE trc_ini_ctl
-
-
-   SUBROUTINE trc_ini_inv
+   SUBROUTINE trc_ini_inv( Kmm )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE trc_ini_stat  ***
       !! ** Purpose :      passive tracers inventories at initialsation phase
       !!----------------------------------------------------------------------
-      INTEGER ::  jk, jn    ! dummy loop indices
+      INTEGER, INTENT(in) ::   Kmm    ! time level index
+      INTEGER             ::  jk, jn  ! dummy loop indices
       CHARACTER (len=25) :: charout
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra) :: zzmsk
+      CHARACTER (len=25), DIMENSION(jptra) :: clseb  
       !!----------------------------------------------------------------------
       !
@@ -118,5 +104,5 @@
       !                          ! masked grid volume
       DO jk = 1, jpk
-         cvol(:,:,jk) = e1e2t(:,:) * e3t_n(:,:,jk) * tmask(:,:,jk)
+         cvol(:,:,jk) = e1e2t(:,:) * e3t(:,:,jk,Kmm) * tmask(:,:,jk)
       END DO
       !                          ! total volume of the ocean 
@@ -125,5 +111,5 @@
       trai(:) = 0._wp            ! initial content of all tracers
       DO jn = 1, jptra
-         trai(jn) = trai(jn) + glob_sum( 'trcini', trn(:,:,:,jn) * cvol(:,:,:)   )
+         trai(jn) = trai(jn) + glob_sum( 'trcini', tr(:,:,:,jn,Kmm) * cvol(:,:,:)   )
       END DO
 
@@ -140,9 +126,14 @@
       ENDIF
       IF(lwp) WRITE(numout,*)
-      IF(ln_ctl) THEN            ! print mean trends (used for debugging)
-         CALL prt_ctl_trc_init
+      IF(sn_cfctl%l_prttrc) THEN            ! print mean trends (used for debugging)
+         CALL prt_ctl_init( 'top', jptra )
          WRITE(charout, FMT="('ini ')")
-         CALL prt_ctl_trc_info( charout )
-         CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl( tab4d_1=tr(:,:,:,:,Kmm), mask1=tmask, clinfo=ctrcnm )
+         DO jn = 1, jptra
+            zzmsk(:,:,:,jn) = tmask(:,:,:)
+            WRITE(clseb(jn),'(a,i2.2)') 'seb ', jn
+         END DO
+         CALL prt_ctl( tab4d_1=zzmsk, mask1=tmask, clinfo=clseb )
       ENDIF
 9000  FORMAT('      tracer nb : ',i2,'      name :',a10,'      initial content :',e18.10)
@@ -151,5 +142,5 @@
 
 
-   SUBROUTINE trc_ini_sms
+   SUBROUTINE trc_ini_sms( Kmm )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE trc_ini_sms  ***
@@ -162,4 +153,5 @@
       USE trcini_my_trc  ! MY_TRC   initialisation
       !
+      INTEGER, INTENT(in) ::   Kmm ! time level indices
       INTEGER :: jn
       !!----------------------------------------------------------------------
@@ -175,10 +167,20 @@
          ln_trc_obc(jn) =       sn_tracer(jn)%llobc
       END DO
+      !
+      IF( .NOT.ln_trcbc ) THEN
+         DO jn = 1, jp_bgc
+            ln_trc_sbc(jn) = .FALSE.
+            ln_trc_cbc(jn) = .FALSE.
+            ln_trc_obc(jn) = .FALSE.
+         END DO
+      ENDIF
+     
+      lltrcbc = ( COUNT(ln_trc_sbc) + COUNT(ln_trc_obc) + COUNT(ln_trc_cbc) ) > 0 
       !    
-      IF( ln_pisces      )   CALL trc_ini_pisces     !  PISCES model
-      IF( ln_my_trc      )   CALL trc_ini_my_trc     !  MY_TRC model
-      IF( ll_cfc         )   CALL trc_ini_cfc        !  CFC's
-      IF( ln_c14         )   CALL trc_ini_c14        !  C14 model
-      IF( ln_age         )   CALL trc_ini_age        !  AGE
+      IF( ln_pisces      )   CALL trc_ini_pisces( Kmm )     !  PISCES model
+      IF( ln_my_trc      )   CALL trc_ini_my_trc( Kmm )     !  MY_TRC model
+      IF( ll_cfc         )   CALL trc_ini_cfc   ( Kmm )     !  CFC's
+      IF( ln_c14         )   CALL trc_ini_c14   ( Kmm )     !  C14 model
+      IF( ln_age         )   CALL trc_ini_age   ( Kmm )     !  AGE
       !
       IF(lwp) THEN                   ! control print
@@ -191,4 +193,9 @@
          END DO
       ENDIF
+      IF( lwp .AND. ln_trcbc .AND. lltrcbc ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' Applying tracer boundary conditions '
+      ENDIF
+     
 9001  FORMAT(3x,i3,1x,a10,3x,l2,3x,l2,3x,l2,3x,l2)
       !
@@ -221,5 +228,5 @@
 
 
-   SUBROUTINE trc_ini_state
+   SUBROUTINE trc_ini_state( Kbb, Kmm, Kaa )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE trc_ini_state ***
@@ -230,15 +237,19 @@
       USE trcdta          ! initialisation from files
       !
-      INTEGER :: jn, jl   ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_trcdta )   CALL trc_dta_ini( jptra )      ! set initial tracers values
-      !
-      IF( ln_my_trc )   CALL trc_bc_ini ( jptra )      ! set tracers Boundary Conditions
+      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa   ! time level index
+      INTEGER             :: jn, jl          ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_trcdta )   CALL trc_dta_ini( jptra )           ! set initial tracers values
+      !
+      IF( ln_trcbc .AND. lltrcbc )  THEN 
+        CALL trc_bc_ini ( jptra, Kmm  )            ! set tracers Boundary Conditions
+        CALL trc_bc     ( nit000, Kmm, tr, Kaa )   ! tracers: surface and lateral Boundary Conditions
+      ENDIF
       !
       !
       IF( ln_rsttr ) THEN              ! restart from a file
         !
-        CALL trc_rst_read
+        CALL trc_rst_read( Kbb, Kmm )
         !
       ELSE                             ! Initialisation of tracer from a file that may also be used for damping
@@ -249,5 +260,5 @@
                IF( ln_trc_ini(jn) ) THEN
                   jl = n_trc_index(jn) 
-                  CALL trc_dta( nit000, sf_trcdta(jl), rf_trfac(jl), trn(:,:,:,jn) )
+                  CALL trc_dta( nit000, Kmm, sf_trcdta(jl), rf_trfac(jl), tr(:,:,:,jn,Kmm) )
                   !
                   ! deallocate data structure if data are not used for damping
@@ -263,10 +274,10 @@
         ENDIF
         !
-        trb(:,:,:,:) = trn(:,:,:,:)
+        tr(:,:,:,:,Kbb) = tr(:,:,:,:,Kmm)
         ! 
       ENDIF
       !
-      tra(:,:,:,:) = 0._wp
-      !                                                         ! Partial top/bottom cell: GRADh(trn)
+      tr(:,:,:,:,Kaa) = 0._wp
+      !                                                         ! Partial top/bottom cell: GRADh(tr(Kmm))
    END SUBROUTINE trc_ini_state
 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcnam.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcnam.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcnam.F90	(revision 13463)
@@ -23,7 +23,4 @@
    USE trdtrc_oce  !
    USE iom         ! I/O manager
-#if defined key_mpp_mpi
-   USE lib_mpp, ONLY: ncom_dttrc
-#endif
 
    IMPLICIT NONE
@@ -79,9 +76,7 @@
       ENDIF
       !
-      rdttrc = rdt * FLOAT( nn_dttrc )          ! passive tracer time-step      
-      ! 
       IF(lwp) THEN                              ! control print
         WRITE(numout,*) 
-        WRITE(numout,*) '   ==>>>   Passive Tracer  time step    rdttrc = nn_dttrc*rdt = ', rdttrc
+        WRITE(numout,*) '   ==>>>   Passive Tracer time step = rn_Dt = ', rn_Dt
       ENDIF
       !
@@ -100,5 +95,5 @@
       INTEGER  ::   ios   ! Local integer
       !!
-      NAMELIST/namtrc_run/ nn_dttrc, ln_rsttr, nn_rsttr, ln_top_euler, &
+      NAMELIST/namtrc_run/ ln_rsttr, nn_rsttr, ln_top_euler, &
         &                  cn_trcrst_indir, cn_trcrst_outdir, cn_trcrst_in, cn_trcrst_out
       !!---------------------------------------------------------------------
@@ -108,21 +103,18 @@
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
       !
-      CALL ctl_opn( numnat_ref, 'namelist_top_ref'   , 'OLD'    , 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
-      CALL ctl_opn( numnat_cfg, 'namelist_top_cfg'   , 'OLD'    , 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+      CALL load_nml( numnat_ref, 'namelist_top_ref' , numout, lwm )
+      CALL load_nml( numnat_cfg, 'namelist_top_cfg' , numout, lwm )
       IF(lwm) CALL ctl_opn( numont, 'output.namelist.top', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE., 1 )
       !
-      REWIND( numnat_ref )              ! Namelist namtrc in reference namelist : Passive tracer variables
       READ  ( numnat_ref, namtrc_run, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc in reference namelist', lwp )
-      REWIND( numnat_cfg )              ! Namelist namtrc in configuration namelist : Passive tracer variables
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc in reference namelist' )
       READ  ( numnat_cfg, namtrc_run, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc in configuration namelist' )
       IF(lwm) WRITE( numont, namtrc_run )
 
-      nittrc000 = nit000 + nn_dttrc - 1      ! first time step of tracer model
+      nittrc000 = nit000             ! first time step of tracer model
 
       IF(lwp) THEN                   ! control print
          WRITE(numout,*) '   Namelist : namtrc_run'
-         WRITE(numout,*) '      time step freq. for passive tracer           nn_dttrc      = ', nn_dttrc
          WRITE(numout,*) '      restart  for passive tracer                  ln_rsttr      = ', ln_rsttr
          WRITE(numout,*) '      control of time step for passive tracer      nn_rsttr      = ', nn_rsttr
@@ -131,8 +123,4 @@
       ENDIF
       !
-#if defined key_mpp_mpi
-      ncom_dttrc = nn_dttrc    ! make nn_fsbc available for lib_mpp
-#endif
-      !
    END SUBROUTINE trc_nam_run
 
@@ -148,5 +136,5 @@
       !!
       NAMELIST/namtrc/jp_bgc, ln_pisces, ln_my_trc, ln_age, ln_cfc11, ln_cfc12, ln_sf6, ln_c14, &
-         &            sn_tracer, ln_trcdta, ln_trcdmp, ln_trcdmp_clo, jp_dia3d, jp_dia2d
+         &            sn_tracer, ln_trcdta, ln_trcbc, ln_trcdmp, ln_trcdmp_clo, jp_dia3d, jp_dia2d
       !!---------------------------------------------------------------------
       ! Dummy settings to fill tracers data structure
@@ -158,10 +146,8 @@
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
 
-      REWIND( numnat_ref )              ! Namelist namtrc in reference namelist : Passive tracer variables
       READ  ( numnat_ref, namtrc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc in reference namelist', lwp )
-      REWIND( numnat_cfg )              ! Namelist namtrc in configuration namelist : Passive tracer variables
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc in reference namelist' )
       READ  ( numnat_cfg, namtrc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc in configuration namelist', lwp )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc in configuration namelist' )
       IF(lwm) WRITE( numont, namtrc )
 
@@ -222,4 +208,5 @@
          WRITE(numout,*) '      Simulating C14   passive tracer              ln_c14        = ', ln_c14
          WRITE(numout,*) '      Read inputs data from file (y/n)             ln_trcdta     = ', ln_trcdta
+         WRITE(numout,*) '      Enable surface, lateral or open boundaries conditions (y/n)  ln_trcbc  = ', ln_trcbc
          WRITE(numout,*) '      Damping of passive tracer (y/n)              ln_trcdmp     = ', ln_trcdmp
          WRITE(numout,*) '      Restoring of tracer on closed seas           ln_trcdmp_clo = ', ln_trcdmp_clo
@@ -228,6 +215,6 @@
       IF( ll_cfc .OR. ln_c14 ) THEN
         !                             ! Open namelist files
-        CALL ctl_opn( numtrc_ref, 'namelist_trc_ref'   ,     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
-        CALL ctl_opn( numtrc_cfg, 'namelist_trc_cfg'   ,     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+        CALL load_nml( numtrc_ref, 'namelist_trc_ref' , numout, lwm )
+        CALL load_nml( numtrc_cfg, 'namelist_trc_cfg' , numout, lwm )
         IF(lwm) CALL ctl_opn( numonr, 'output.namelist.trc', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
         !
@@ -261,10 +248,8 @@
       ALLOCATE( ln_trdtrc(jptra) ) 
       !
-      REWIND( numnat_ref )              ! Namelist namtrc_trd in reference namelist : Passive tracer trends
       READ  ( numnat_ref, namtrc_trd, IOSTAT = ios, ERR = 905)
-905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_trd in reference namelist', lwp )
-      REWIND( numnat_cfg )              ! Namelist namtrc_trd in configuration namelist : Passive tracer trends
+905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_trd in reference namelist' )
       READ  ( numnat_cfg, namtrc_trd, IOSTAT = ios, ERR = 906 )
-906   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_trd in configuration namelist', lwp )
+906   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_trd in configuration namelist' )
       IF(lwm) WRITE( numont, namtrc_trd )
 
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcrst.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcrst.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcrst.F90	(revision 13463)
@@ -33,4 +33,5 @@
    PUBLIC   trc_rst_cal
 
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -58,5 +59,5 @@
             IF( ln_rst_list ) THEN
                nrst_lst = 1
-               nitrst = nstocklist( nrst_lst )
+               nitrst = nn_stocklist( nrst_lst )
             ELSE
                nitrst = nitend
@@ -64,7 +65,7 @@
          ENDIF
 
-         IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nstock ) == 0 ) THEN
+         IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nn_stock ) == 0 ) THEN
             ! we use kt - 1 and not kt - nittrc000 to keep the same periodicity from the beginning of the experiment
-            nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
+            nitrst = kt + nn_stock - 1                  ! define the next value of nitrst for restart writing
             IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
          ENDIF
@@ -73,8 +74,10 @@
       ENDIF
 
+      IF( .NOT. ln_rst_list .AND. nn_stock == -1 )   RETURN   ! we will never do any restart
+
       ! to get better performances with NetCDF format:
-      ! we open and define the tracer restart file one tracer time step before writing the data (-> at nitrst - 2*nn_dttrc + 1)
-      ! except if we write tracer restart files every tracer time step or if a tracer restart file was writen at nitend - 2*nn_dttrc + 1
-      IF( kt == nitrst - 2*nn_dttrc .OR. nstock == nn_dttrc .OR. ( kt == nitend - nn_dttrc .AND. .NOT. lrst_trc ) ) THEN
+      ! we open and define the tracer restart file one tracer time step before writing the data (-> at nitrst - 1)
+      ! except if we write tracer restart files every tracer time step or if a tracer restart file was writen at nitend - 1
+      IF( kt == nitrst - 1 .OR. nn_stock == 1 .OR. ( kt == nitend - 1 .AND. .NOT. lrst_trc ) ) THEN
          ! beware of the format used to write kt (default is i8.8, that should be large enough)
          IF( nitrst > 1.0e9 ) THEN   ;   WRITE(clkt,*       ) nitrst
@@ -94,5 +97,5 @@
    END SUBROUTINE trc_rst_opn
 
-   SUBROUTINE trc_rst_read
+   SUBROUTINE trc_rst_read( Kbb, Kmm )
       !!----------------------------------------------------------------------
       !!                    ***  trc_rst_opn  ***
@@ -100,4 +103,5 @@
       !! ** purpose  :   read passive tracer fields in restart files
       !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   Kbb, Kmm  ! time level indices
       INTEGER  ::  jn     
 
@@ -110,9 +114,9 @@
       ! READ prognostic variables and computes diagnostic variable
       DO jn = 1, jptra
-         CALL iom_get( numrtr, jpdom_autoglo, 'TRN'//ctrcnm(jn), trn(:,:,:,jn) )
-      END DO
-
-      DO jn = 1, jptra
-         CALL iom_get( numrtr, jpdom_autoglo, 'TRB'//ctrcnm(jn), trb(:,:,:,jn) )
+         CALL iom_get( numrtr, jpdom_auto, 'TRN'//ctrcnm(jn), tr(:,:,:,jn,Kmm) )
+      END DO
+
+      DO jn = 1, jptra
+         CALL iom_get( numrtr, jpdom_auto, 'TRB'//ctrcnm(jn), tr(:,:,:,jn,Kbb) )
       END DO
       !
@@ -121,5 +125,5 @@
    END SUBROUTINE trc_rst_read
 
-   SUBROUTINE trc_rst_wri( kt )
+   SUBROUTINE trc_rst_wri( kt, Kbb, Kmm, Krhs )
       !!----------------------------------------------------------------------
       !!                    ***  trc_rst_wri  ***
@@ -127,18 +131,19 @@
       !! ** purpose  :   write passive tracer fields in restart files
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt    ! ocean time-step index
+      INTEGER, INTENT( in ) ::   kt              ! ocean time-step index
+      INTEGER, INTENT( in ) ::   Kbb, Kmm, Krhs  ! time level indices
       !!
       INTEGER  :: jn
       !!----------------------------------------------------------------------
       !
-      CALL iom_rstput( kt, nitrst, numrtw, 'rdttrc1', rdttrc )   ! passive tracer time step
+      CALL iom_rstput( kt, nitrst, numrtw, 'rdttrc1', rn_Dt )   ! passive tracer time step (= ocean time step)
       ! prognostic variables 
       ! -------------------- 
       DO jn = 1, jptra
-         CALL iom_rstput( kt, nitrst, numrtw, 'TRN'//ctrcnm(jn), trn(:,:,:,jn) )
-      END DO
-
-      DO jn = 1, jptra
-         CALL iom_rstput( kt, nitrst, numrtw, 'TRB'//ctrcnm(jn), trb(:,:,:,jn) )
+         CALL iom_rstput( kt, nitrst, numrtw, 'TRN'//ctrcnm(jn), tr(:,:,:,jn,Kmm) )
+      END DO
+
+      DO jn = 1, jptra
+         CALL iom_rstput( kt, nitrst, numrtw, 'TRB'//ctrcnm(jn), tr(:,:,:,jn,Kbb) )
       END DO
       !
@@ -146,5 +151,5 @@
     
       IF( kt == nitrst ) THEN
-          CALL trc_rst_stat            ! statistics
+          CALL trc_rst_stat( Kmm, Krhs )             ! statistics
           CALL iom_close( numrtw )     ! close the restart file (only at last time step)
 #if ! defined key_trdmxl_trc
@@ -153,5 +158,5 @@
           IF( l_offline .AND. ln_rst_list ) THEN
              nrst_lst = nrst_lst + 1
-             nitrst = nstocklist( nrst_lst )
+             nitrst = nn_stocklist( nrst_lst )
           ENDIF
       ENDIF
@@ -179,5 +184,5 @@
       !!       In both those options, the  exact duration of the experiment
       !!       since the beginning (cumulated duration of all previous restart runs)
-      !!       is not stored in the restart and is assumed to be (nittrc000-1)*rdt.
+      !!       is not stored in the restart and is assumed to be (nittrc000-1)*rn_Dt.
       !!       This is valid is the time step has remained constant.
       !!
@@ -217,5 +222,5 @@
             ENDIF
             ! Control of date 
-            IF( nittrc000  - NINT( zkt ) /= nn_dttrc .AND.  nn_rsttr /= 0 )                                  &
+            IF( nittrc000  - NINT( zkt ) /= 1 .AND.  nn_rsttr /= 0 )                                  &
                &   CALL ctl_stop( ' ===>>>> : problem with nittrc000 for the restart',                 &
                &                  ' verify the restart file or rerun with nn_rsttr = 0 (namelist)' )
@@ -259,5 +264,5 @@
                nminute = ( nn_time0 - nhour * 100 )
                IF( nhour*3600+nminute*60-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0)
-               adatrj = ( REAL( nit000-1, wp ) * rdt ) / rday
+               adatrj = ( REAL( nit000-1, wp ) * rn_Dt ) / rday
                ! note this is wrong if time step has changed during run
             ENDIF
@@ -272,6 +277,6 @@
             ENDIF
             !
-            IF( ln_rsttr )  THEN   ;    neuler = 1
-            ELSE                   ;    neuler = 0
+            IF( ln_rsttr )  THEN   ;    l_1st_euler = .false.
+            ELSE                   ;    l_1st_euler = .true.
             ENDIF
             !
@@ -297,5 +302,5 @@
 
 
-   SUBROUTINE trc_rst_stat
+   SUBROUTINE trc_rst_stat( Kmm, Krhs )
       !!----------------------------------------------------------------------
       !!                    ***  trc_rst_stat  ***
@@ -303,4 +308,5 @@
       !! ** purpose  :   Compute tracers statistics
       !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   Kmm, Krhs  ! time level indices
       INTEGER  :: jk, jn
       REAL(wp) :: ztraf, zmin, zmax, zmean, zdrift
@@ -315,11 +321,11 @@
       !
       DO jk = 1, jpk
-         zvol(:,:,jk) = e1e2t(:,:) * e3t_a(:,:,jk) * tmask(:,:,jk)
-      END DO
-      !
-      DO jn = 1, jptra
-         ztraf = glob_sum( 'trcrst', trn(:,:,:,jn) * zvol(:,:,:) )
-         zmin  = MINVAL( trn(:,:,:,jn), mask= ((tmask*SPREAD(tmask_i,DIM=3,NCOPIES=jpk).NE.0.)) )
-         zmax  = MAXVAL( trn(:,:,:,jn), mask= ((tmask*SPREAD(tmask_i,DIM=3,NCOPIES=jpk).NE.0.)) )
+         zvol(:,:,jk) = e1e2t(:,:) * e3t(:,:,jk,Krhs) * tmask(:,:,jk)
+      END DO
+      !
+      DO jn = 1, jptra
+         ztraf = glob_sum( 'trcrst', tr(:,:,:,jn,Kmm) * zvol(:,:,:) )
+         zmin  = MINVAL( tr(:,:,:,jn,Kmm), mask= ((tmask*SPREAD(tmask_i,DIM=3,NCOPIES=jpk).NE.0.)) )
+         zmax  = MAXVAL( tr(:,:,:,jn,Kmm), mask= ((tmask*SPREAD(tmask_i,DIM=3,NCOPIES=jpk).NE.0.)) )
          IF( lk_mpp ) THEN
             CALL mpp_min( 'trcrst', zmin )      ! min over the global domain
@@ -341,8 +347,10 @@
    !!----------------------------------------------------------------------
 CONTAINS
-   SUBROUTINE trc_rst_read                      ! Empty routines
+   SUBROUTINE trc_rst_read( Kbb, Kmm)                      ! Empty routines
+      INTEGER, INTENT( in ) :: Kbb, Kmm  ! time level indices
    END SUBROUTINE trc_rst_read
-   SUBROUTINE trc_rst_wri( kt )
-      INTEGER, INTENT ( in ) :: kt
+   SUBROUTINE trc_rst_wri( kt, Kbb, Kmm, Krhs )
+      INTEGER, INTENT( in ) :: kt
+      INTEGER, INTENT( in ) :: Kbb, Kmm, Krhs  ! time level indices
       WRITE(*,*) 'trc_rst_wri: You should not have seen this print! error?', kt
    END SUBROUTINE trc_rst_wri   
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcsms.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcsms.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcsms.F90	(revision 13463)
@@ -20,5 +20,5 @@
    USE trcsms_age         ! AGE
    USE trcsms_my_trc      ! MY_TRC  tracers
-   USE prtctl_trc         ! Print control for debbuging
+   USE prtctl             ! Print control for debbuging
 
    IMPLICIT NONE
@@ -34,5 +34,5 @@
 CONTAINS
 
-   SUBROUTINE trc_sms( kt )
+   SUBROUTINE trc_sms( kt, Kbb, Kmm , Krhs )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE trc_sms  ***
@@ -42,5 +42,6 @@
       !! ** Method  : -  call the main routine of of each defined tracer model
       !! -------------------------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   kt        ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   Kbb, Kmm, Krhs ! time level indices
       !!
       CHARACTER (len=25) :: charout
@@ -49,14 +50,14 @@
       IF( ln_timing )   CALL timing_start('trc_sms')
       !
-      IF( ln_pisces  )   CALL trc_sms_pisces ( kt )    ! main program of PISCES 
-      IF( ll_cfc     )   CALL trc_sms_cfc    ( kt )    ! surface fluxes of CFC
-      IF( ln_c14     )   CALL trc_sms_c14    ( kt )    ! surface fluxes of C14
-      IF( ln_age     )   CALL trc_sms_age    ( kt )    ! Age tracer
-      IF( ln_my_trc  )   CALL trc_sms_my_trc ( kt )    ! MY_TRC  tracers
+      IF( ln_pisces  )   CALL trc_sms_pisces ( kt, Kbb, Kmm, Krhs )    ! main program of PISCES 
+      IF( ll_cfc     )   CALL trc_sms_cfc    ( kt, Kbb, Kmm, Krhs )    ! surface fluxes of CFC
+      IF( ln_c14     )   CALL trc_sms_c14    ( kt, Kbb, Kmm, Krhs )    ! surface fluxes of C14
+      IF( ln_age     )   CALL trc_sms_age    ( kt, Kbb, Kmm, Krhs )    ! Age tracer
+      IF( ln_my_trc  )   CALL trc_sms_my_trc ( kt, Kbb, Kmm, Krhs )    ! MY_TRC  tracers
 
-      IF(ln_ctl) THEN      ! print mean trends (used for debugging)
+      IF(sn_cfctl%l_prttrc) THEN                       ! print mean trends (used for debugging)
          WRITE(charout, FMT="('sms ')")
-         CALL prt_ctl_trc_info( charout )
-         CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+         CALL prt_ctl( tab4d_1=tr(:,:,:,:,Kmm), mask1=tmask, clinfo=ctrcnm )
       ENDIF
       !
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcstp.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcstp.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcstp.F90	(revision 13463)
@@ -5,4 +5,5 @@
    !!======================================================================
    !! History :  1.0  !  2004-03  (C. Ethe)  Original
+   !!            4.1  !  2019-08  (A. Coward, D. Storkey) rewrite in preparation for new timestepping scheme
    !!----------------------------------------------------------------------
 #if defined key_top
@@ -17,10 +18,9 @@
    USE trcwri
    USE trcrst
-   USE trcsub         !
    USE trdtrc_oce
    USE trdmxl_trc
    USE sms_pisces,  ONLY : ln_check_mass
    !
-   USE prtctl_trc     ! Print control for debbuging
+   USE prtctl         ! Print control for debbuging
    USE iom            !
    USE in_out_manager !
@@ -37,4 +37,5 @@
    REAL(wp), DIMENSION(:,:,:), SAVE, ALLOCATABLE ::   qsr_arr   ! save qsr during TOP time-step
 
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -44,5 +45,5 @@
 CONTAINS
 
-   SUBROUTINE trc_stp( kt )
+   SUBROUTINE trc_stp( kt, Kbb, Kmm, Krhs, Kaa )
       !!-------------------------------------------------------------------
       !!                     ***  ROUTINE trc_stp  ***
@@ -53,5 +54,6 @@
       !!                Update the passive tracers
       !!-------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      INTEGER, INTENT( in ) :: kt                  ! ocean time-step index
+      INTEGER, INTENT( in ) :: Kbb, Kmm, Krhs, Kaa ! time level indices
       !
       INTEGER ::   jk, jn   ! dummy loop indices
@@ -63,19 +65,21 @@
       IF( ln_timing )   CALL timing_start('trc_stp')
       !
-      IF( ( neuler == 0 .AND. kt == nittrc000 ) .OR. ln_top_euler ) THEN     ! at nittrc000
-         r2dttrc =  rdttrc           ! = rdttrc (use or restarting with Euler time stepping)
-      ELSEIF( kt <= nittrc000 + nn_dttrc ) THEN          ! at nittrc000 or nittrc000+1
-         r2dttrc = 2. * rdttrc       ! = 2 rdttrc (leapfrog)
-      ENDIF
-      !
-      ll_trcstat  = ( ln_ctl .OR. sn_cfctl%l_trcstat ) .AND. &
+      IF( l_1st_euler .OR. ln_top_euler ) THEN     ! at nittrc000
+         rDt_trc =  rn_Dt           ! = rn_Dt (use or restarting with Euler time stepping)
+      ELSEIF( kt <= nittrc000 + 1 ) THEN                                     ! at nittrc000 or nittrc000+1 
+         rDt_trc = 2. * rn_Dt       ! = 2 rn_Dt (leapfrog) 
+      ENDIF
+      !
+      ll_trcstat  = ( sn_cfctl%l_trcstat ) .AND. &
      &              ( ( MOD( kt, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend ) )
+
+      IF( kt == nittrc000 )                      CALL trc_stp_ctl   ! control 
       IF( kt == nittrc000 .AND. lk_trdmxl_trc )  CALL trd_mxl_trc_init    ! trends: Mixed-layer
       !
       IF( .NOT.ln_linssh ) THEN                                           ! update ocean volume due to ssh temporal evolution
          DO jk = 1, jpk
-            cvol(:,:,jk) = e1e2t(:,:) * e3t_n(:,:,jk) * tmask(:,:,jk)
+            cvol(:,:,jk) = e1e2t(:,:) * e3t(:,:,jk,Kmm) * tmask(:,:,jk)
          END DO
-         IF ( ln_ctl .OR. kt == nitrst .OR. ( ln_check_mass .AND. kt == nitend )              &
+         IF ( ll_trcstat .OR. kt == nitrst .OR. ( ln_check_mass .AND. kt == nitend )   &
             & .OR. iom_use( "pno3tot" ) .OR. iom_use( "ppo4tot" ) .OR. iom_use( "psiltot" )   &
             & .OR. iom_use( "palktot" ) .OR. iom_use( "pfertot" ) )                           &
@@ -85,29 +89,35 @@
       IF( l_trcdm2dc )   CALL trc_mean_qsr( kt )
       !    
-      IF( nn_dttrc /= 1 )   CALL trc_sub_stp( kt )  ! averaging physical variables for sub-stepping
-      !    
-      IF( MOD( kt , nn_dttrc ) == 0 ) THEN      ! only every nn_dttrc time step
-         !
-         IF(ln_ctl) THEN
-            WRITE(charout,FMT="('kt =', I4,'  d/m/y =',I2,I2,I4)") kt, nday, nmonth, nyear
-            CALL prt_ctl_trc_info(charout)
-         ENDIF
-         !
-         tra(:,:,:,:) = 0.e0
-         !
-                                   CALL trc_rst_opn  ( kt )       ! Open tracer restart file 
-         IF( lrst_trc )            CALL trc_rst_cal  ( kt, 'WRITE' )   ! calendar
-                                   CALL trc_wri      ( kt )       ! output of passive tracers with iom I/O manager
-                                   CALL trc_sms      ( kt )       ! tracers: sinks and sources
-                                   CALL trc_trp      ( kt )       ! transport of passive tracers
-         IF( kt == nittrc000 ) THEN
-            CALL iom_close( numrtr )       ! close input tracer restart file
-            IF(lwm) CALL FLUSH( numont )   ! flush namelist output
-         ENDIF
-         IF( lrst_trc )            CALL trc_rst_wri  ( kt )       ! write tracer restart file
-         IF( lk_trdmxl_trc  )      CALL trd_mxl_trc  ( kt )       ! trends: Mixed-layer
-         !
-         IF( nn_dttrc /= 1   )     CALL trc_sub_reset( kt )       ! resetting physical variables when sub-stepping
-         !
+      !
+      IF(sn_cfctl%l_prttrc) THEN
+         WRITE(charout,FMT="('kt =', I4,'  d/m/y =',I2,I2,I4)") kt, nday, nmonth, nyear
+         CALL prt_ctl_info( charout, cdcomp = 'top' )
+      ENDIF
+      !
+      tr(:,:,:,:,Krhs) = 0._wp
+      !
+      CALL trc_rst_opn  ( kt )                            ! Open tracer restart file 
+      IF( lrst_trc )  CALL trc_rst_cal  ( kt, 'WRITE' )   ! calendar
+      CALL trc_wri      ( kt,      Kmm            )       ! output of passive tracers with iom I/O manager
+      CALL trc_sms      ( kt, Kbb, Kmm, Krhs      )       ! tracers: sinks and sources
+      CALL trc_trp      ( kt, Kbb, Kmm, Krhs, Kaa )       ! transport of passive tracers
+           !
+           ! Note passive tracers have been time-filtered in trc_trp but the time level
+           ! indices will not be swapped until after tra_atf/dyn_atf/ssh_atf in stp. Subsequent calls here
+           ! anticipate this update which will be: Nrhs= Nbb ; Nbb = Nnn ; Nnn = Naa ; Naa = Nrhs
+           ! and use the filtered levels explicitly.
+           !
+      IF( kt == nittrc000 ) THEN
+         CALL iom_close( numrtr )                         ! close input tracer restart file
+         IF(lwm) CALL FLUSH( numont )                     ! flush namelist output
+      ENDIF
+      IF( lrst_trc )            CALL trc_rst_wri  ( kt, Kmm, Kaa, Kbb  )       ! write tracer restart file
+      IF( lk_trdmxl_trc  )      CALL trd_mxl_trc  ( kt,      Kaa       )       ! trends: Mixed-layer
+      !
+      IF( ln_top_euler ) THEN 
+         ! For Euler timestepping for TOP we need to copy the "after" to the "now" fields 
+         ! here then after the (leapfrog) swapping of the time-level indices in OCE/step.F90 we have 
+         ! "before" fields = "now" fields.
+         tr(:,:,:,:,Kmm) = tr(:,:,:,:,Kaa)
       ENDIF
       !
@@ -115,5 +125,5 @@
          ztrai = 0._wp                                                   !  content of all tracers
          DO jn = 1, jptra
-            ztrai = ztrai + glob_sum( 'trcstp', trn(:,:,:,jn) * cvol(:,:,:)   )
+            ztrai = ztrai + glob_sum( 'trcstp', tr(:,:,:,jn,Kaa) * cvol(:,:,:)   )
          END DO
          IF( lwm ) WRITE(numstr,9300) kt,  ztrai / areatot
@@ -124,4 +134,20 @@
       !
    END SUBROUTINE trc_stp
+
+
+   SUBROUTINE trc_stp_ctl
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_stp_ctl  ***
+      !! ** Purpose :        Control  + ocean volume
+      !!----------------------------------------------------------------------
+      !
+      ! Define logical parameter ton control dirunal cycle in TOP
+      l_trcdm2dc = ln_dm2dc .OR. ( ln_cpl .AND. ncpl_qsr_freq /= 1 .AND. ncpl_qsr_freq /= 0 )
+      l_trcdm2dc = l_trcdm2dc .AND. .NOT. l_offline
+      !
+      IF( l_trcdm2dc .AND. lwp )   CALL ctl_warn( 'Coupling with passive tracers and used of diurnal cycle.',   &
+         &                           'Computation of a daily mean shortwave for some biogeochemical models ' )
+      !
+   END SUBROUTINE trc_stp_ctl
 
 
@@ -153,5 +179,5 @@
             nb_rec_per_day = ncpl_qsr_freq
          ELSE  
-            rdt_sampl = MAX( 3600., rdttrc )
+            rdt_sampl = MAX( 3600., rn_Dt )
             nb_rec_per_day = INT( rday / rdt_sampl )
          ENDIF
@@ -172,7 +198,7 @@
 
             CALL iom_get( numrtr, 'ktdcy', zkt )  
-            rsecfst = INT( zkt ) * rdttrc
+            rsecfst = INT( zkt ) * rn_Dt
             IF(lwp) WRITE(numout,*) 'trc_qsr_mean:   qsr_mean read in the restart file at time-step rsecfst =', rsecfst, ' s '
-            CALL iom_get( numrtr, jpdom_autoglo, 'qsr_mean', qsr_mean )   !  A mean of qsr
+            CALL iom_get( numrtr, jpdom_auto, 'qsr_mean', qsr_mean )   !  A mean of qsr
             CALL iom_get( numrtr, 'nrdcy', zrec )   !  Number of record per days
             IF( INT( zrec ) == nb_rec_per_day ) THEN
@@ -180,8 +206,8 @@
                   IF( jn <= 9 )  THEN
                     WRITE(cl1,'(i1)') jn
-                    CALL iom_get( numrtr, jpdom_autoglo, 'qsr_arr_'//cl1, qsr_arr(:,:,jn) )   !  A mean of qsr
+                    CALL iom_get( numrtr, jpdom_auto, 'qsr_arr_'//cl1, qsr_arr(:,:,jn) )   !  A mean of qsr
                   ELSE
                     WRITE(cl2,'(i2.2)') jn
-                    CALL iom_get( numrtr, jpdom_autoglo, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) )   !  A mean of qsr
+                    CALL iom_get( numrtr, jpdom_auto, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) )   !  A mean of qsr
                   ENDIF
               END DO
@@ -193,5 +219,5 @@
          ELSE                                         !* no restart: set from nit000 values
             IF(lwp) WRITE(numout,*) 'trc_qsr_mean:   qsr_mean set to nit000 values'
-            rsecfst  = kt * rdttrc
+            rsecfst  = kt * rn_Dt
             !
             qsr_mean(:,:) = qsr(:,:)
@@ -203,5 +229,5 @@
       ENDIF
       !
-      rseclast = kt * rdttrc
+      rseclast = kt * rn_Dt
       !
       llnew   = ( rseclast - rsecfst ) .ge.  rdt_sampl    !   new shortwave to store
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcsub.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcsub.F90	(revision 11396)
+++ 	(revision )
@@ -1,597 +1,0 @@
-MODULE trcsub
-   !!======================================================================
-   !!                       ***  MODULE trcsubstp  ***
-   !!   TOP :   Averages physics variables for TOP substepping. 
-   !!======================================================================
-   !! History :  1.0  !  2011-10  (K. Edwards)  Original
-   !!----------------------------------------------------------------------
-#if defined key_top
-   !!----------------------------------------------------------------------
-   !!   trc_sub       : passive tracer system sub-stepping 
-   !!----------------------------------------------------------------------
-   USE oce_trc        ! ocean dynamics and active tracers variables
-   USE trc
-   USE trabbl         ! bottom boundary layer
-   USE zdf_oce
-   USE domvvl
-   USE divhor         ! horizontal divergence
-   USE sbcrnf   , ONLY: h_rnf, nk_rnf    ! River runoff
-   USE bdy_oce  , ONLY: ln_bdy, bdytmask ! BDY
-   !
-   USE prtctl_trc     ! Print control for debbuging
-   USE in_out_manager ! 
-   USE iom
-   USE lbclnk
-#if defined key_agrif
-   USE agrif_oce_update
-   USE agrif_oce_interp
-#endif
-
-   IMPLICIT NONE
-
-   PUBLIC   trc_sub_stp     ! called by trc_stp
-   PUBLIC   trc_sub_ini     ! called by trc_ini to initialize substepping arrays.
-   PUBLIC   trc_sub_reset   ! called by trc_stp to reset physics variables
-   PUBLIC   trc_sub_ssh     ! called by trc_stp to reset physics variables
-
-   REAL(wp) :: r1_ndttrc     ! = 1 /  nn_dttrc 
-   REAL(wp) :: r1_ndttrcp1   ! = 1 / (nn_dttrc+1) 
-
-
-   !! averaged and temporary saved variables  (needed when a larger passive tracer time-step is used)
-   !! ----------------------------------------------------------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::    un_tm ,   un_temp   !: i-horizontal velocity average     [m/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::    vn_tm ,   vn_temp   !: j-horizontal velocity average     [m/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::              wn_temp   !: hold current values of avt, un, vn, wn
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   tsn_tm ,  tsn_temp   !: t/s average     [m/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   avs_tm ,  avs_temp   !: vertical diffusivity coeff. at  w-point   [m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  rhop_tm , rhop_temp   !: 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  sshn_tm , sshn_temp   !: average ssh for the now step [m]
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::    rnf_tm ,    rnf_temp   !: river runoff
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  h_rnf_tm ,  h_rnf_temp   !: depth in metres to the bottom of the relevant grid box
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   hmld_tm ,   hmld_temp   !: mixed layer depth average [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   fr_i_tm ,   fr_i_temp   !: average ice fraction     [m/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::    emp_tm ,    emp_temp   !: freshwater budget: volume flux [Kg/m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     :: fmmflx_tm , fmmflx_temp   !: freshwater budget: freezing/melting [Kg/m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     :: emp_b_hold,  emp_b_temp   !: hold emp from the beginning of each sub-stepping[m]  
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::    qsr_tm ,    qsr_temp   !: solar radiation average [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   wndm_tm ,   wndm_temp   !: 10m wind average [m]
-   !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  sshb_hold   !:hold sshb from the beginning of each sub-stepping[m]  
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   sshb_temp, ssha_temp
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  hdivn_temp, rotn_temp
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  hdivb_temp, rotb_temp
-   !
-   !                                                    !!- bottom boundary layer param (ln_trabbl=T)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  ahu_bbl_tm, ahu_bbl_temp  ! BBL diffusive i-coef.
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  ahv_bbl_tm, ahv_bbl_temp  ! BBL diffusive j-coef.
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  utr_bbl_tm, utr_bbl_temp  ! BBL u-advection
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  vtr_bbl_tm, vtr_bbl_temp  ! BBL v-advection
-
-   !                                                      !!- iso-neutral slopes (if l_ldfslp=T)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   uslp_temp, vslp_temp, wslpi_temp, wslpj_temp   !: hold current values 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   uslp_tm  , vslp_tm  , wslpi_tm  , wslpj_tm     !: time mean 
-
-
-   !!----------------------------------------------------------------------
-   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
-   !! $Id$ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE trc_sub_stp( kt )
-      !!-------------------------------------------------------------------
-      !!                     ***  ROUTINE trc_stp  ***
-      !!                      
-      !! ** Purpose : Average variables needed for sub-stepping passive tracers
-      !! 
-      !! ** Method  : Called every timestep to increment _tm (time mean) variables
-      !!              on TOP steps, calculate averages.
-      !!-------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
-      !
-      INTEGER ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp)::   z1_ne3t, z1_ne3u, z1_ne3v, z1_ne3w   ! local scalars
-      !!-------------------------------------------------------------------
-      !
-      IF( ln_timing )   CALL timing_start('trc_sub_stp')
-      !
-      IF( kt == nit000 ) THEN
-           IF(lwp) WRITE(numout,*)
-           IF(lwp) WRITE(numout,*) 'trc_sub_stp : substepping of the passive tracers'
-           IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
-           !
-           sshb_hold  (:,:) = sshn  (:,:)
-           emp_b_hold (:,:) = emp_b (:,:)
-           !
-           r1_ndttrc        = 1._wp / REAL( nn_dttrc    , wp ) 
-           r1_ndttrcp1      = 1._wp / REAL( nn_dttrc + 1, wp )
-      ENDIF  
-
-      IF( MOD( kt , nn_dttrc ) /= 0 ) THEN
-         !
-         un_tm   (:,:,:)        = un_tm   (:,:,:)        + un   (:,:,:)        * e3u_n(:,:,:) 
-         vn_tm   (:,:,:)        = vn_tm   (:,:,:)        + vn   (:,:,:)        * e3v_n(:,:,:) 
-         tsn_tm  (:,:,:,jp_tem) = tsn_tm  (:,:,:,jp_tem) + tsn  (:,:,:,jp_tem) * e3t_n(:,:,:)  
-         tsn_tm  (:,:,:,jp_sal) = tsn_tm  (:,:,:,jp_sal) + tsn  (:,:,:,jp_sal) * e3t_n(:,:,:)  
-         rhop_tm (:,:,:)        = rhop_tm (:,:,:)        + rhop (:,:,:)        * e3t_n(:,:,:)  
-         avs_tm  (:,:,:)        = avs_tm  (:,:,:)        + avs  (:,:,:)        * e3w_n(:,:,:)  
-         IF( l_ldfslp ) THEN
-            uslp_tm (:,:,:)      = uslp_tm (:,:,:)        + uslp (:,:,:)
-            vslp_tm (:,:,:)      = vslp_tm (:,:,:)        + vslp (:,:,:)
-            wslpi_tm(:,:,:)      = wslpi_tm(:,:,:)        + wslpi(:,:,:)
-            wslpj_tm(:,:,:)      = wslpj_tm(:,:,:)        + wslpj(:,:,:)
-         ENDIF
-         IF( ln_trabbl ) THEN
-            IF( nn_bbl_ldf == 1 ) THEN
-               ahu_bbl_tm(:,:)     = ahu_bbl_tm(:,:)        + ahu_bbl(:,:) 
-               ahv_bbl_tm(:,:)     = ahv_bbl_tm(:,:)        + ahv_bbl(:,:) 
-            ENDIF
-            IF( nn_bbl_adv == 1 ) THEN
-               utr_bbl_tm(:,:)     = utr_bbl_tm(:,:)        + utr_bbl(:,:) 
-               vtr_bbl_tm(:,:)     = vtr_bbl_tm(:,:)        + vtr_bbl(:,:) 
-            ENDIF
-         ENDIF 
-         !
-         sshn_tm  (:,:)         = sshn_tm  (:,:)         + sshn  (:,:) 
-         rnf_tm   (:,:)         = rnf_tm   (:,:)         + rnf   (:,:) 
-         h_rnf_tm (:,:)         = h_rnf_tm (:,:)         + h_rnf (:,:) 
-         hmld_tm  (:,:)         = hmld_tm  (:,:)         + hmld  (:,:)
-         fr_i_tm  (:,:)         = fr_i_tm  (:,:)         + fr_i  (:,:)
-         emp_tm   (:,:)         = emp_tm   (:,:)         + emp   (:,:) 
-         fmmflx_tm(:,:)         = fmmflx_tm(:,:)         + fmmflx(:,:)
-         qsr_tm   (:,:)         = qsr_tm   (:,:)         + qsr   (:,:)
-         wndm_tm  (:,:)         = wndm_tm  (:,:)         + wndm  (:,:)
-         !
-      ELSE                           !  It is time to substep 
-         !   1. set temporary arrays to hold physics/dynamical variables
-         un_temp    (:,:,:)      = un    (:,:,:)
-         vn_temp    (:,:,:)      = vn    (:,:,:)
-         wn_temp    (:,:,:)      = wn    (:,:,:)
-         tsn_temp   (:,:,:,:)    = tsn   (:,:,:,:)
-         rhop_temp  (:,:,:)      = rhop  (:,:,:)    
-         avs_temp   (:,:,:)      = avs   (:,:,:)
-         IF( l_ldfslp ) THEN
-            uslp_temp  (:,:,:)   = uslp  (:,:,:)   ;   wslpi_temp (:,:,:)   = wslpi (:,:,:)
-            vslp_temp  (:,:,:)   = vslp  (:,:,:)   ;   wslpj_temp (:,:,:)   = wslpj (:,:,:)
-         ENDIF
-         IF( ln_trabbl ) THEN
-            IF( nn_bbl_ldf == 1 ) THEN
-               ahu_bbl_temp(:,:)   = ahu_bbl(:,:)  
-               ahv_bbl_temp(:,:)   = ahv_bbl(:,:) 
-            ENDIF
-            IF( nn_bbl_adv == 1 ) THEN
-               utr_bbl_temp(:,:)   = utr_bbl(:,:) 
-               vtr_bbl_temp(:,:)   = vtr_bbl(:,:) 
-            ENDIF
-         ENDIF 
-         sshn_temp  (:,:)        = sshn  (:,:)
-         sshb_temp  (:,:)        = sshb  (:,:)
-         ssha_temp  (:,:)        = ssha  (:,:)
-         rnf_temp   (:,:)        = rnf   (:,:)
-         h_rnf_temp (:,:)        = h_rnf (:,:)
-         hmld_temp  (:,:)        = hmld  (:,:)
-         fr_i_temp  (:,:)        = fr_i  (:,:)
-         emp_temp   (:,:)        = emp   (:,:)
-         emp_b_temp (:,:)        = emp_b (:,:)
-         fmmflx_temp(:,:)        = fmmflx(:,:)
-         qsr_temp   (:,:)        = qsr   (:,:)
-         wndm_temp  (:,:)        = wndm  (:,:)
-         !                                    !  Variables reset in trc_sub_ssh
-         hdivn_temp (:,:,:)      = hdivn (:,:,:)
-         !
-         ! 2. Create averages and reassign variables
-         un_tm    (:,:,:)        = un_tm   (:,:,:)        + un   (:,:,:)        * e3u_n(:,:,:) 
-         vn_tm    (:,:,:)        = vn_tm   (:,:,:)        + vn   (:,:,:)        * e3v_n(:,:,:) 
-         tsn_tm   (:,:,:,jp_tem) = tsn_tm  (:,:,:,jp_tem) + tsn  (:,:,:,jp_tem) * e3t_n(:,:,:)  
-         tsn_tm   (:,:,:,jp_sal) = tsn_tm  (:,:,:,jp_sal) + tsn  (:,:,:,jp_sal) * e3t_n(:,:,:)  
-         rhop_tm (:,:,:)         = rhop_tm (:,:,:)        + rhop (:,:,:)        * e3t_n(:,:,:)  
-         avs_tm   (:,:,:)        = avs_tm  (:,:,:)        + avs  (:,:,:)        * e3w_n(:,:,:)  
-         IF( l_ldfslp ) THEN
-            uslp_tm  (:,:,:)     = uslp_tm (:,:,:)        + uslp (:,:,:) 
-            vslp_tm  (:,:,:)     = vslp_tm (:,:,:)        + vslp (:,:,:)
-            wslpi_tm (:,:,:)     = wslpi_tm(:,:,:)        + wslpi(:,:,:) 
-            wslpj_tm (:,:,:)     = wslpj_tm(:,:,:)        + wslpj(:,:,:) 
-         ENDIF
-         IF( ln_trabbl ) THEN
-            IF( nn_bbl_ldf == 1 ) THEN
-               ahu_bbl_tm(:,:)     = ahu_bbl_tm(:,:)        + ahu_bbl(:,:) 
-               ahv_bbl_tm(:,:)     = ahv_bbl_tm(:,:)        + ahv_bbl(:,:) 
-            ENDIF
-            IF( nn_bbl_adv == 1 ) THEN
-               utr_bbl_tm(:,:)     = utr_bbl_tm(:,:)        + utr_bbl(:,:) 
-               vtr_bbl_tm(:,:)     = vtr_bbl_tm(:,:)        + vtr_bbl(:,:) 
-            ENDIF
-         ENDIF 
-         sshn_tm  (:,:)          = sshn_tm    (:,:)       + sshn  (:,:) 
-         rnf_tm   (:,:)          = rnf_tm     (:,:)       + rnf   (:,:) 
-         h_rnf_tm (:,:)          = h_rnf_tm   (:,:)       + h_rnf (:,:) 
-         hmld_tm  (:,:)          = hmld_tm    (:,:)       + hmld  (:,:)
-         fr_i_tm  (:,:)          = fr_i_tm    (:,:)       + fr_i  (:,:)
-         emp_tm   (:,:)          = emp_tm     (:,:)       + emp   (:,:) 
-         fmmflx_tm(:,:)          = fmmflx_tm  (:,:)       + fmmflx(:,:)
-         qsr_tm   (:,:)          = qsr_tm     (:,:)       + qsr   (:,:)
-         wndm_tm  (:,:)          = wndm_tm    (:,:)       + wndm  (:,:)
-         !
-         sshn     (:,:)          = sshn_tm    (:,:) * r1_ndttrcp1 
-         sshb     (:,:)          = sshb_hold  (:,:)
-         rnf      (:,:)          = rnf_tm     (:,:) * r1_ndttrcp1 
-         h_rnf    (:,:)          = h_rnf_tm   (:,:) * r1_ndttrcp1 
-         hmld     (:,:)          = hmld_tm    (:,:) * r1_ndttrcp1 
-         !  variables that are initialized after averages
-         emp_b    (:,:) = emp_b_hold (:,:)
-         IF( kt == nittrc000 ) THEN
-            wndm  (:,:)          = wndm_tm    (:,:) * r1_ndttrc 
-            qsr   (:,:)          = qsr_tm     (:,:) * r1_ndttrc 
-            emp   (:,:)          = emp_tm     (:,:) * r1_ndttrc 
-            fmmflx(:,:)          = fmmflx_tm  (:,:) * r1_ndttrc 
-            fr_i  (:,:)          = fr_i_tm    (:,:) * r1_ndttrc
-            IF( ln_trabbl ) THEN
-               IF( nn_bbl_ldf == 1 ) THEN
-                  ahu_bbl(:,:)      = ahu_bbl_tm (:,:) * r1_ndttrc  
-                  ahv_bbl(:,:)      = ahv_bbl_tm (:,:) * r1_ndttrc 
-               ENDIF
-               IF( nn_bbl_adv == 1 ) THEN
-                  utr_bbl(:,:)      = utr_bbl_tm (:,:) * r1_ndttrc  
-                  vtr_bbl(:,:)      = vtr_bbl_tm (:,:) * r1_ndttrc 
-               ENDIF
-            ENDIF
-         ELSE
-            wndm  (:,:)          = wndm_tm    (:,:) * r1_ndttrcp1 
-            qsr   (:,:)          = qsr_tm     (:,:) * r1_ndttrcp1 
-            emp   (:,:)          = emp_tm     (:,:) * r1_ndttrcp1 
-            fmmflx(:,:)          = fmmflx_tm  (:,:) * r1_ndttrcp1 
-            fr_i  (:,:)          = fr_i_tm    (:,:) * r1_ndttrcp1 
-            IF( ln_trabbl ) THEN
-               IF( nn_bbl_ldf == 1 ) THEN
-                  ahu_bbl(:,:)      = ahu_bbl_tm (:,:) * r1_ndttrcp1  
-                  ahv_bbl(:,:)      = ahv_bbl_tm (:,:) * r1_ndttrcp1 
-               ENDIF
-               IF( nn_bbl_adv == 1 ) THEN
-                  utr_bbl(:,:)      = utr_bbl_tm (:,:) * r1_ndttrcp1  
-                  vtr_bbl(:,:)      = vtr_bbl_tm (:,:) * r1_ndttrcp1 
-               ENDIF
-            ENDIF
-         ENDIF
-         !
-         DO jk = 1, jpk
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  z1_ne3t = r1_ndttrcp1  / e3t_n(ji,jj,jk)
-                  z1_ne3u = r1_ndttrcp1  / e3u_n(ji,jj,jk)
-                  z1_ne3v = r1_ndttrcp1  / e3v_n(ji,jj,jk)
-                  z1_ne3w = r1_ndttrcp1  / e3w_n(ji,jj,jk)
-                  !
-                  un   (ji,jj,jk)        = un_tm   (ji,jj,jk)        * z1_ne3u
-                  vn   (ji,jj,jk)        = vn_tm   (ji,jj,jk)        * z1_ne3v
-                  tsn  (ji,jj,jk,jp_tem) = tsn_tm  (ji,jj,jk,jp_tem) * z1_ne3t
-                  tsn  (ji,jj,jk,jp_sal) = tsn_tm  (ji,jj,jk,jp_sal) * z1_ne3t
-                  rhop (ji,jj,jk)        = rhop_tm (ji,jj,jk)        * z1_ne3t
-!!gm : BUG ==>> for avs I don't understand the division by e3w
-                  avs  (ji,jj,jk)        = avs_tm  (ji,jj,jk)        * z1_ne3w
-               END DO
-            END DO
-         END DO
-         IF( l_ldfslp ) THEN
-            wslpi(:,:,:)        = wslpi_tm(:,:,:) 
-            wslpj(:,:,:)        = wslpj_tm(:,:,:)
-            uslp (:,:,:)        = uslp_tm (:,:,:)
-            vslp (:,:,:)        = vslp_tm (:,:,:)
-         ENDIF
-         !
-         CALL trc_sub_ssh( kt )         ! after ssh & vertical velocity
-         !
-      ENDIF
-      !
-      IF( ln_timing )   CALL timing_stop('trc_sub_stp')
-      !
-   END SUBROUTINE trc_sub_stp
-
-
-   SUBROUTINE trc_sub_ini
-      !!-------------------------------------------------------------------
-      !!                     ***  ROUTINE trc_sub_ini  ***
-      !!                      
-      !! ** Purpose : Initialize variables needed for sub-stepping passive tracers
-      !! 
-      !! ** Method  : 
-      !!              Compute the averages for sub-stepping
-      !!-------------------------------------------------------------------
-      INTEGER ::   ierr
-      !!-------------------------------------------------------------------
-      !
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'trc_sub_ini : initial set up of the passive tracers substepping'
-      IF(lwp) WRITE(numout,*) '~~~~~~~'
-
-      ierr =  trc_sub_alloc    ()
-      CALL mpp_sum( 'trcsub', ierr )
-      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'top_sub_alloc : unable to allocate standard ocean arrays' )
-
-      un_tm   (:,:,:)        = un   (:,:,:)        * e3u_n(:,:,:) 
-      vn_tm   (:,:,:)        = vn   (:,:,:)        * e3v_n(:,:,:) 
-      tsn_tm  (:,:,:,jp_tem) = tsn  (:,:,:,jp_tem) * e3t_n(:,:,:)  
-      tsn_tm  (:,:,:,jp_sal) = tsn  (:,:,:,jp_sal) * e3t_n(:,:,:)  
-      rhop_tm (:,:,:)        = rhop (:,:,:)        * e3t_n(:,:,:)  
-!!gm : BUG? ==>> for avt & avs I don't understand the division by e3w
-      avs_tm  (:,:,:)        = avs  (:,:,:)        * e3w_n(:,:,:)  
-      IF( l_ldfslp ) THEN
-         wslpi_tm(:,:,:)     = wslpi(:,:,:)
-         wslpj_tm(:,:,:)     = wslpj(:,:,:)
-         uslp_tm (:,:,:)     = uslp (:,:,:)
-         vslp_tm (:,:,:)     = vslp (:,:,:)
-      ENDIF
-      sshn_tm  (:,:) = sshn  (:,:) 
-      rnf_tm   (:,:) = rnf   (:,:) 
-      h_rnf_tm (:,:) = h_rnf (:,:) 
-      hmld_tm  (:,:) = hmld  (:,:)
-
-      ! Physics variables that are set after initialization:
-      fr_i_tm  (:,:) = 0._wp
-      emp_tm   (:,:) = 0._wp
-      fmmflx_tm(:,:)  = 0._wp
-      qsr_tm   (:,:) = 0._wp
-      wndm_tm  (:,:) = 0._wp
-      IF( ln_trabbl ) THEN
-         IF( nn_bbl_ldf == 1 ) THEN
-            ahu_bbl_tm(:,:) = 0._wp
-            ahv_bbl_tm(:,:) = 0._wp
-         ENDIF
-         IF( nn_bbl_adv == 1 ) THEN
-            utr_bbl_tm(:,:) = 0._wp
-            vtr_bbl_tm(:,:) = 0._wp
-         ENDIF
-      ENDIF
-      !
-   END SUBROUTINE trc_sub_ini
-
-
-   SUBROUTINE trc_sub_reset( kt )
-      !!-------------------------------------------------------------------
-      !!                     ***  ROUTINE trc_sub_reset  ***
-      !!                      
-      !! ** Purpose : Reset physics variables averaged for substepping
-      !! 
-      !! ** Method  : 
-      !!              Compute the averages for sub-stepping
-      !!-------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::  kt  ! ocean time-step index
-      INTEGER :: jk                 ! dummy loop indices
-      !!-------------------------------------------------------------------
-      !
-      IF( ln_timing )   CALL timing_start('trc_sub_reset')
-      !
-      !   restore physics variables
-      un    (:,:,:)   =  un_temp    (:,:,:)
-      vn    (:,:,:)   =  vn_temp    (:,:,:)
-      wn    (:,:,:)   =  wn_temp    (:,:,:)
-      tsn   (:,:,:,:) =  tsn_temp   (:,:,:,:)
-      rhop  (:,:,:)   =  rhop_temp  (:,:,:)
-      avs   (:,:,:)   =  avs_temp   (:,:,:)
-      IF( l_ldfslp ) THEN
-         wslpi (:,:,:)=  wslpi_temp (:,:,:)
-         wslpj (:,:,:)=  wslpj_temp (:,:,:)
-         uslp  (:,:,:)=  uslp_temp  (:,:,:)
-         vslp  (:,:,:)=  vslp_temp  (:,:,:)
-      ENDIF
-      sshn  (:,:)     =  sshn_temp  (:,:)
-      sshb  (:,:)     =  sshb_temp  (:,:)
-      ssha  (:,:)     =  ssha_temp  (:,:)
-      rnf   (:,:)     =  rnf_temp   (:,:)
-      h_rnf (:,:)     =  h_rnf_temp (:,:)
-      !
-      hmld  (:,:)     =  hmld_temp  (:,:)
-      fr_i  (:,:)     =  fr_i_temp  (:,:)
-      emp   (:,:)     =  emp_temp   (:,:)
-      fmmflx(:,:)     =  fmmflx_temp(:,:)
-      emp_b (:,:)     =  emp_b_temp (:,:)
-      qsr   (:,:)     =  qsr_temp   (:,:)
-      wndm  (:,:)     =  wndm_temp  (:,:)
-      IF( ln_trabbl ) THEN
-         IF( nn_bbl_ldf == 1 ) THEN
-            ahu_bbl(:,:) = ahu_bbl_temp(:,:) 
-            ahv_bbl(:,:) = ahv_bbl_temp(:,:) 
-         ENDIF
-         IF( nn_bbl_adv == 1 ) THEN
-            utr_bbl(:,:) = utr_bbl_temp(:,:) 
-            vtr_bbl(:,:) = vtr_bbl_temp(:,:) 
-         ENDIF
-      ENDIF
-      !
-      hdivn (:,:,:)   =  hdivn_temp (:,:,:)
-      !                                      
-      ! Start new averages
-         un_tm   (:,:,:)        = un   (:,:,:)        * e3u_n(:,:,:) 
-         vn_tm   (:,:,:)        = vn   (:,:,:)        * e3v_n(:,:,:) 
-         tsn_tm  (:,:,:,jp_tem) = tsn  (:,:,:,jp_tem) * e3t_n(:,:,:)  
-         tsn_tm  (:,:,:,jp_sal) = tsn  (:,:,:,jp_sal) * e3t_n(:,:,:)  
-         rhop_tm (:,:,:)        = rhop (:,:,:)        * e3t_n(:,:,:)  
-         avs_tm  (:,:,:)        = avs  (:,:,:)        * e3w_n(:,:,:)  
-      IF( l_ldfslp ) THEN
-         uslp_tm (:,:,:)        = uslp (:,:,:)
-         vslp_tm (:,:,:)        = vslp (:,:,:)
-         wslpi_tm(:,:,:)        = wslpi(:,:,:) 
-         wslpj_tm(:,:,:)        = wslpj(:,:,:)
-      ENDIF
-      !
-      sshb_hold  (:,:) = sshn  (:,:)
-      emp_b_hold (:,:) = emp   (:,:)
-      sshn_tm    (:,:) = sshn  (:,:) 
-      rnf_tm     (:,:) = rnf   (:,:) 
-      h_rnf_tm   (:,:) = h_rnf (:,:) 
-      hmld_tm    (:,:) = hmld  (:,:)
-      fr_i_tm    (:,:) = fr_i  (:,:)
-      emp_tm     (:,:) = emp   (:,:)
-      fmmflx_tm  (:,:) = fmmflx(:,:)
-      qsr_tm     (:,:) = qsr   (:,:)
-      wndm_tm    (:,:) = wndm  (:,:)
-      IF( ln_trabbl ) THEN
-         IF( nn_bbl_ldf == 1 ) THEN
-            ahu_bbl_tm(:,:) = ahu_bbl(:,:) 
-            ahv_bbl_tm(:,:) = ahv_bbl(:,:) 
-         ENDIF
-         IF( nn_bbl_adv == 1 ) THEN
-            utr_bbl_tm(:,:) = utr_bbl(:,:) 
-            vtr_bbl_tm(:,:) = vtr_bbl(:,:) 
-         ENDIF
-      ENDIF
-      !
-      !
-      IF( ln_timing )   CALL timing_stop('trc_sub_reset')
-      !
-   END SUBROUTINE trc_sub_reset
-
-
-   SUBROUTINE trc_sub_ssh( kt ) 
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE trc_sub_ssh  ***
-      !!                   
-      !! ** Purpose :   compute the after ssh (ssha), the now vertical velocity
-      !!              and update the now vertical coordinate (ln_linssh=F).
-      !!
-      !! ** Method  : - Using the incompressibility hypothesis, the vertical 
-      !!      velocity is computed by integrating the horizontal divergence  
-      !!      from the bottom to the surface minus the scale factor evolution.
-      !!        The boundary conditions are w=0 at the bottom (no flux) and.
-      !!
-      !! ** action  :   ssha    : after sea surface height
-      !!                wn      : now vertical velocity
-      !!                sshu_a, sshv_a, sshf_a  : after sea surface height (ln_linssh=F)
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2009, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! time step
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zcoefu, zcoefv, zcoeff, z2dt, z1_2dt, z1_rau0   ! local scalars
-      REAL(wp), DIMENSION(jpi,jpj) :: zhdiv
-      !!---------------------------------------------------------------------
-      !
-      IF( ln_timing )   CALL timing_start('trc_sub_ssh')
-      !
-
-      IF( kt == nittrc000 ) THEN
-         !
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'trc_sub_ssh : after sea surface height and now vertical velocity '
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
-         !
-         wn(:,:,jpk) = 0._wp                  ! bottom boundary condition: w=0 (set once for all)
-         !
-      ENDIF
-      !
-!!gm BUG here !   hdivn will include the runoff divergence at the wrong timestep !!!!
-      CALL div_hor( kt )                              ! Horizontal divergence & Relative vorticity
-      !
-      z2dt = 2._wp * rdt                              ! set time step size (Euler/Leapfrog)
-      IF( neuler == 0 .AND. kt == nittrc000 )   z2dt = rdt
-
-      !                                           !------------------------------!
-      !                                           !   After Sea Surface Height   !
-      !                                           !------------------------------!
-      zhdiv(:,:) = 0._wp
-      DO jk = 1, jpkm1                                 ! Horizontal divergence of barotropic transports
-        zhdiv(:,:) = zhdiv(:,:) + e3t_n(:,:,jk) * hdivn(:,:,jk)
-      END DO
-      !                                                ! Sea surface elevation time stepping
-      ! In forward Euler time stepping case, the same formulation as in the leap-frog case can be used
-      ! because emp_b field is initialized with the vlaues of emp field. Hence, 0.5 * ( emp + emp_b ) = emp
-      z1_rau0 = 0.5 / rau0
-      ssha(:,:) = (  sshb(:,:) - z2dt * ( z1_rau0 * ( emp_b(:,:) + emp(:,:) ) + zhdiv(:,:) )  ) * tmask(:,:,1)
-
-      IF( .NOT.ln_dynspg_ts ) THEN
-      ! These lines are not necessary with time splitting since
-      ! boundary condition on sea level is set during ts loop
-#if defined key_agrif
-      CALL agrif_ssh( kt )
-#endif
-         IF( ln_bdy ) THEN
-            ssha(:,:) = ssha(:,:) * bdytmask(:,:)
-            CALL lbc_lnk( 'trcsub', ssha, 'T', 1. ) 
-         ENDIF
-      ENDIF
-      !
-      !                                           !------------------------------!
-      !                                           !     Now Vertical Velocity    !
-      !                                           !------------------------------!
-      z1_2dt = 1.e0 / z2dt
-      DO jk = jpkm1, 1, -1                             ! integrate from the bottom the hor. divergence
-         ! - ML - need 3 lines here because replacement of e3t by its expression yields too long lines otherwise
-         wn(:,:,jk) = wn(:,:,jk+1) -   e3t_n(:,:,jk) * hdivn(:,:,jk)        &
-            &                      - ( e3t_a(:,:,jk) - e3t_b(:,:,jk) )    &
-            &                         * tmask(:,:,jk) * z1_2dt
-         IF( ln_bdy ) wn(:,:,jk) = wn(:,:,jk) * bdytmask(:,:)
-      END DO
-      !
-      IF( ln_timing )   CALL timing_stop('trc_sub_ssh')
-      !
-   END SUBROUTINE trc_sub_ssh
-
-
-   INTEGER FUNCTION trc_sub_alloc()
-      !!-------------------------------------------------------------------
-      !!                    *** ROUTINE trc_sub_alloc ***
-      !!-------------------------------------------------------------------
-      USE lib_mpp, ONLY: ctl_stop
-      INTEGER ::  ierr(3)
-      !!-------------------------------------------------------------------
-      !
-      ierr(:) = 0
-      !
-      ALLOCATE( un_temp(jpi,jpj,jpk)      ,  vn_temp(jpi,jpj,jpk)   ,     &
-         &      wn_temp(jpi,jpj,jpk)      ,                               &
-         &      rhop_temp(jpi,jpj,jpk)    ,  rhop_tm(jpi,jpj,jpk)   ,     &
-         &      sshn_temp(jpi,jpj)        ,  sshb_temp(jpi,jpj)     ,     &
-         &      ssha_temp(jpi,jpj)        ,                               &
-         &      rnf_temp(jpi,jpj)         ,  h_rnf_temp(jpi,jpj)    ,     &
-         &      tsn_temp(jpi,jpj,jpk,2)   ,  emp_b_temp(jpi,jpj)    ,     &
-         &      emp_temp(jpi,jpj)         ,  fmmflx_temp(jpi,jpj)   ,     &
-         &      hmld_temp(jpi,jpj)        ,  qsr_temp(jpi,jpj)      ,     &
-         &      fr_i_temp(jpi,jpj)        ,  fr_i_tm(jpi,jpj)       ,     &
-         &      wndm_temp(jpi,jpj)        ,  wndm_tm(jpi,jpj)       ,     &
-         &      avs_tm(jpi,jpj,jpk)       ,  avs_temp(jpi,jpj,jpk)  ,     &
-         &      hdivn_temp(jpi,jpj,jpk)   ,  hdivb_temp(jpi,jpj,jpk),     &
-         &      un_tm(jpi,jpj,jpk)        ,  vn_tm(jpi,jpj,jpk)     ,     &
-         &      sshn_tm(jpi,jpj)          ,  sshb_hold(jpi,jpj)     ,     &
-         &      tsn_tm(jpi,jpj,jpk,2)     ,                               &
-         &      emp_tm(jpi,jpj)           ,  fmmflx_tm(jpi,jpj)     ,     &
-         &      emp_b_hold(jpi,jpj)       ,                               &
-         &      hmld_tm(jpi,jpj)          ,  qsr_tm(jpi,jpj)        ,     &
-         &      rnf_tm(jpi,jpj)           ,  h_rnf_tm(jpi,jpj)      , STAT=ierr(1) )  
-      !
-      IF( l_ldfslp ) THEN
-         ALLOCATE( uslp_temp(jpi,jpj,jpk) ,  wslpi_temp(jpi,jpj,jpk),     &
-            &      vslp_temp(jpi,jpj,jpk) ,  wslpj_temp(jpi,jpj,jpk),     &
-            &      uslp_tm  (jpi,jpj,jpk) ,  wslpi_tm  (jpi,jpj,jpk),     &
-            &      vslp_tm  (jpi,jpj,jpk) ,  wslpj_tm  (jpi,jpj,jpk), STAT=ierr(2) )
-      ENDIF
-      IF( ln_trabbl ) THEN
-         ALLOCATE( ahu_bbl_temp(jpi,jpj)  , utr_bbl_temp(jpi,jpj)   ,     &
-            &      ahv_bbl_temp(jpi,jpj)  , vtr_bbl_temp(jpi,jpj)   ,     &
-            &      ahu_bbl_tm  (jpi,jpj)  , utr_bbl_tm  (jpi,jpj)   ,     &
-            &      ahv_bbl_tm  (jpi,jpj)  , vtr_bbl_tm  (jpi,jpj)   , STAT=ierr(3) ) 
-      ENDIF
-      !
-      trc_sub_alloc = MAXVAL( ierr )
-      !
-      IF( trc_sub_alloc /= 0 )   CALL ctl_stop( 'STOP', 'trc_sub_alloc: failed to allocate arrays' )
-      !
-   END FUNCTION trc_sub_alloc
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default key                                     NO passive tracers
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE trc_sub_stp( kt )        ! Empty routine
-      WRITE(*,*) 'trc_sub_stp: You should not have seen this print! error?', kt
-   END SUBROUTINE trc_sub_stp
-   SUBROUTINE trc_sub_ini        ! Empty routine
-      WRITE(*,*) 'trc_sub_ini: You should not have seen this print! error?', kt
-   END SUBROUTINE trc_sub_ini
-#endif
-
-   !!======================================================================
-END MODULE trcsub
Index: NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcwri.F90
===================================================================
--- NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcwri.F90	(revision 11396)
+++ NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/TOP/trcwri.F90	(revision 13463)
@@ -30,5 +30,5 @@
 CONTAINS
 
-   SUBROUTINE trc_wri( kt )
+   SUBROUTINE trc_wri( kt, Kmm )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE trc_wri  ***
@@ -37,4 +37,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT( in )     :: kt
+      INTEGER, INTENT( in )     :: Kmm  ! time level indices
       !
       INTEGER                   :: jn
@@ -46,17 +47,31 @@
       IF( ln_timing )   CALL timing_start('trc_wri')
       !
-      IF( l_offline .AND. kt == nittrc000 .AND. lwp ) THEN    ! WRITE root name in date.file for use by postpro
-         CALL dia_nam( clhstnam, nn_writetrc,' ' )
-         CALL ctl_opn( inum, 'date.file', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
-         WRITE(inum,*) clhstnam
-         CLOSE(inum)
+      IF( l_offline ) THEN    ! WRITE root name in date.file for use by postpro
+         IF(  kt == nittrc000 .AND. lwp ) THEN    ! WRITE root name in date.file for use by postpro
+           CALL dia_nam( clhstnam, nn_writetrc,' ' )
+           CALL ctl_opn( inum, 'date.file', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
+           WRITE(inum,*) clhstnam
+           CLOSE(inum)
+        ENDIF
+
+       ! Output of initial vertical scale factor
+       CALL iom_put( "e3t_0", e3t_0(:,:,:) )
+       CALL iom_put( "e3u_0", e3u_0(:,:,:) )
+       CALL iom_put( "e3v_0", e3v_0(:,:,:) )
+       !
+#if ! defined key_qco
+       CALL iom_put( "e3t" , e3t(:,:,:,Kmm) )
+       CALL iom_put( "e3u" , e3u(:,:,:,Kmm) )
+       CALL iom_put( "e3v" , e3v(:,:,:,Kmm) )
+#endif 
+       !
       ENDIF
       ! write the tracer concentrations in the file
       ! ---------------------------------------
-      IF( ln_pisces  )   CALL trc_wri_pisces     ! PISCES 
-      IF( ll_cfc     )   CALL trc_wri_cfc        ! surface fluxes of CFC
-      IF( ln_c14     )   CALL trc_wri_c14        ! surface fluxes of C14
-      IF( ln_age     )   CALL trc_wri_age        ! AGE tracer
-      IF( ln_my_trc  )   CALL trc_wri_my_trc     ! MY_TRC  tracers
+      IF( ln_pisces  )   CALL trc_wri_pisces( Kmm )     ! PISCES 
+      IF( ll_cfc     )   CALL trc_wri_cfc   ( Kmm )     ! surface fluxes of CFC
+      IF( ln_c14     )   CALL trc_wri_c14   ( Kmm )     ! surface fluxes of C14
+      IF( ln_age     )   CALL trc_wri_age   ( Kmm )     ! AGE tracer
+      IF( ln_my_trc  )   CALL trc_wri_my_trc( Kmm )     ! MY_TRC  tracers
       !
       IF( ln_timing )   CALL timing_stop('trc_wri')
@@ -70,6 +85,7 @@
    PUBLIC trc_wri
 CONTAINS
-   SUBROUTINE trc_wri( kt )                     ! Empty routine   
+   SUBROUTINE trc_wri( kt, Kmm )                     ! Empty routine   
    INTEGER, INTENT(in) :: kt
+   INTEGER, INTENT(in) :: Kmm  ! time level indices
    END SUBROUTINE trc_wri
 #endif
