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
