Index: /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/OCE/nemogcm.F90
===================================================================
--- /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/OCE/nemogcm.F90	(revision 11426)
+++ /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/OCE/nemogcm.F90	(revision 11427)
@@ -473,5 +473,5 @@
 #if defined key_top
       !                                      ! Passive tracers
-                           CALL     trc_init( Nbb, Nnn, Naa )
+                           CALL     trc_init
 #endif
       IF( l_ldfslp     )   CALL ldf_slp_init    ! slope of lateral mixing
Index: /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/OFF/dtadyn.F90
===================================================================
--- /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/OFF/dtadyn.F90	(revision 11426)
+++ /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/OFF/dtadyn.F90	(revision 11427)
@@ -46,9 +46,10 @@
    PRIVATE
 
-   PUBLIC   dta_dyn_init       ! called by opa.F90
-   PUBLIC   dta_dyn            ! called by step.F90
-   PUBLIC   dta_dyn_sed_init   ! called by opa.F90
-   PUBLIC   dta_dyn_sed        ! called by step.F90
-   PUBLIC   dta_dyn_swp        ! called by step.F90
+   PUBLIC   dta_dyn_init       ! called by nemo_init
+   PUBLIC   dta_dyn            ! called by nemo_gcm
+   PUBLIC   dta_dyn_sed_init   ! called by nemo_init
+   PUBLIC   dta_dyn_sed        ! called by nemo_gcm
+   PUBLIC   dta_dyn_atf        ! called by nemo_gcm
+   PUBLIC   dta_dyn_sf_interp  ! called by nemo_gcm
 
    CHARACTER(len=100) ::   cn_dir          !: Root directory for location of ssr files
@@ -535,31 +536,40 @@
    END SUBROUTINE dta_dyn_sed_init
 
-   SUBROUTINE dta_dyn_swp( kt, Kbb, Kmm, Kaa )
+   SUBROUTINE dta_dyn_atf( kt, Kbb, Kmm, Kaa )
      !!---------------------------------------------------------------------
       !!                    ***  ROUTINE dta_dyn_swp  ***
       !!
-      !! ** Purpose :   Swap and the data and compute the vertical scale factor 
-      !!              at U/V/W pointand the depht
+      !! ** Purpose :   Asselin time filter of now SSH
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) :: kt             ! time step
       INTEGER, INTENT(in) :: Kbb, Kmm, Kaa  ! ocean time level indices
       !
+      !!---------------------------------------------------------------------
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dta_dyn_atf : Asselin time filter of sea surface height'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+
+      ssh(:,:,Kmm) = ssh(:,:,Kmm) + atfp * ( ssh(:,:,Kbb) - 2 * ssh(:,:,Kmm) + ssh(:,:,Kaa))  
+
+      !! Do we also need to time filter e3t??
+      !
+   END SUBROUTINE dta_dyn_atf
+   
+   SUBROUTINE dta_dyn_sf_interp( kt, Kmm )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE dta_dyn_sf_interp  ***
+      !!
+      !! ** Purpose :   Calculate scale factors at U/V/W points and depths
+      !!                given the after e3t field
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) :: kt   ! time step
+      INTEGER, INTENT(in) :: Kmm  ! ocean time level indices
+      !
       INTEGER             :: ji, jj, jk
       REAL(wp)            :: zcoef
       !!---------------------------------------------------------------------
-
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'ssh_swp : Asselin time filter and swap of sea surface height'
-         IF(lwp) WRITE(numout,*) '~~~~~~~ '
-      ENDIF
-
-      ssh(:,:,Kbb) = ssh(:,:,Kmm) + atfp * ( ssh(:,:,Kbb) - 2 * ssh(:,:,Kmm) + ssh(:,:,Kaa))  ! before <-- now filtered
-      ssh(:,:,Kmm) = ssh(:,:,Kaa)
-
-      e3t(:,:,:,Kmm) = e3t(:,:,:,Kaa)
-
-      ! Reconstruction of all vertical scale factors at now and before time steps
-      ! =============================================================================
 
       ! Horizontal scale factor interpolations
@@ -571,8 +581,4 @@
       ! ------------------------------------
       CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3w (:,:,:,Kmm), 'W' )
-
-      e3t(:,:,:,Kbb)  = e3t(:,:,:,Kmm)
-      e3u(:,:,:,Kbb)  = e3u(:,:,:,Kmm)
-      e3v(:,:,:,Kbb)  = e3v(:,:,:,Kmm)
 
       ! t- and w- points depth
@@ -592,9 +598,5 @@
       END DO
       !
-      gdept(:,:,:,Kbb) = gdept(:,:,:,Kmm)
-      gdepw(:,:,:,Kbb) = gdepw(:,:,:,Kmm)
-      !
-   END SUBROUTINE dta_dyn_swp
-   
+   END SUBROUTINE dta_dyn_sf_interp
 
    SUBROUTINE dta_dyn_ssh( kt, phdivtr, psshb,  pemp, pssha, pe3ta )
Index: /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/OFF/nemogcm.F90
===================================================================
--- /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/OFF/nemogcm.F90	(revision 11426)
+++ /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/OFF/nemogcm.F90	(revision 11427)
@@ -119,7 +119,18 @@
 #else
                                 CALL dta_dyn    ( istp, Nbb, Nnn, Naa )       ! Interpolation of the dynamical fields
-         IF( .NOT.ln_linssh )   CALL dta_dyn_swp( istp, Nbb, Nnn, Naa )       ! swap of sea  surface height and vertical scale factors
 #endif
                                 CALL trc_stp    ( istp, Nbb, Nnn, Nrhs, Naa ) ! time-stepping
+#if ! defined key_sed_off
+         IF( .NOT.ln_linssh )   CALL dta_dyn_atf( istp, Nbb, Nnn, Naa )       ! time filter of sea  surface height and vertical scale factors
+#endif
+         ! Swap time levels
+         Nrhs = Nbb
+         Nbb = Nnn
+         Nnn = Naa
+         Naa = Nrhs
+         !
+#if ! defined key_sed_off
+         IF( .NOT.ln_linssh )   CALL dta_dyn_sf_interp( istp, Nnn )  ! calculate now grid parameters
+#endif
                                 CALL stp_ctl    ( istp, indic )  ! Time loop: control and print
          istp = istp + 1
@@ -333,5 +344,5 @@
 #endif
 
-                           CALL     trc_init( Nbb, Nnn, Naa )   ! Passive tracers initialization
+                           CALL     trc_init                         ! Passive tracers initialization
                            CALL dia_ptr_init   ! Poleward TRansports initialization
                            
Index: /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/TRP/trcatf.F90
===================================================================
--- /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/TRP/trcatf.F90	(revision 11426)
+++ /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/TRP/trcatf.F90	(revision 11427)
@@ -162,5 +162,5 @@
          ENDIF
          !
-         CALL lbc_lnk_multi( 'trcatf', ptr(:,:,:,:,Kbb), 'T', 1._wp, ptr(:,:,:,:,Kmm), 'T', 1._wp, ptr(:,:,:,:,Kaa), 'T', 1._wp )
+         CALL lbc_lnk_multi( 'trcatf', ptr(:,:,:,:,Kmm), 'T', 1._wp, ptr(:,:,:,:,Kaa), 'T', 1._wp, ptr(:,:,:,:,Kaa), 'T', 1._wp )
       ENDIF
       !
Index: /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/TRP/trctrp.F90
===================================================================
--- /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/TRP/trctrp.F90	(revision 11426)
+++ /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/TRP/trctrp.F90	(revision 11427)
@@ -36,4 +36,6 @@
    PUBLIC   trc_trp    ! called by trc_stp
 
+   INTEGER, SAVE :: N_save  !  Save value of time index for time swapping for ln_top_euler=.true.
+
    !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
@@ -53,9 +55,11 @@
       !!              - Update the passive tracers
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) :: kt                  ! ocean time-step index
-      INTEGER, INTENT( in ) :: Kbb, Kmm, Krhs, Kaa ! time level indices
+      INTEGER, INTENT( in    ) :: kt                  ! ocean time-step index
+      INTEGER, INTENT( inout ) :: Kbb, Kmm, Krhs, Kaa ! TOP time level indices (swapped in this routine)
       !! ---------------------------------------------------------------------
       !
       IF( ln_timing )   CALL timing_start('trc_trp')
+      !
+      IF ( kt == nit000 ) N_save = Kbb
       !
       IF( .NOT. lk_c1d ) THEN
@@ -79,6 +83,21 @@
                                 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    
-         IF( ln_trcrad )        CALL trc_rad    ( kt, Kbb, Kmm, Krhs, tr       )  ! Correct artificial negative concentrations
-         IF( ln_trcdmp_clo )    CALL trc_dmp_clo( kt, Kbb, Kmm )                  ! internal damping trends on closed seas only
+         !
+         ! Swap TOP time levels (= Nrhs_trc, Nbb_trc etc)
+         IF( ln_top_euler ) THEN
+            ! For Euler timestepping we need the "before" and "now" fields to be the same.
+            ! Use N_save to ensure that the indices stay in sync with the (leapfrogging) OCE time indices for nn_dttrc=1.
+            Krhs = N_save
+            N_save = Kmm
+            Kbb = Kaa
+         ELSE
+            Krhs = Kbb
+            Kbb = Kmm
+         ENDIF
+         Kmm = Kaa
+         Kaa = Krhs
+         !
+         IF( ln_trcrad )        CALL trc_rad    ( kt, Kbb, Kmm, Krhs, tr   )    ! Correct artificial negative concentrations
+         IF( ln_trcdmp_clo )    CALL trc_dmp_clo( kt, Kbb, Kmm )                ! internal damping trends on closed seas only
 
          !
@@ -88,5 +107,12 @@
                                 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
-          IF( ln_trcrad )       CALL trc_rad( kt, Kbb, Kmm, Krhs, tr       )  ! Correct artificial negative concentrations
+         !
+         ! Swap TOP time levels (= Nrhs_trc, Nbb_trc etc)
+         Krhs = Kbb
+         Kbb = Kmm
+         Kmm = Kaa
+         Kaa = Krhs
+         !
+         IF( ln_trcrad )       CALL trc_rad( kt, Kbb, Kmm, Krhs, tr       )  ! Correct artificial negative concentrations
          !
       END IF
Index: /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/trcini.F90
===================================================================
--- /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/trcini.F90	(revision 11426)
+++ /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/trcini.F90	(revision 11427)
@@ -40,5 +40,5 @@
 CONTAINS
    
-   SUBROUTINE trc_init( Kbb, Kmm, Kaa )
+   SUBROUTINE trc_init
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE trc_init  ***
@@ -52,5 +52,4 @@
       !!                or read data or analytical formulation
       !!---------------------------------------------------------------------
-      INTEGER, INTENT( in ) :: Kbb, Kmm, Kaa ! time level indices
       !
       IF( ln_timing )   CALL timing_start('trc_init')
@@ -59,4 +58,7 @@
       IF(lwp) WRITE(numout,*) 'trc_init : initial set up of the passive tracers'
       IF(lwp) WRITE(numout,*) '~~~~~~~~'
+      !
+      ! Initialise time level indices
+      Nbb_trc = 1; Nnn_trc = 2; Naa_trc = 3; Nrhs_trc = Naa_trc
       !
       CALL trc_ini_ctl   ! control 
@@ -71,5 +73,5 @@
       IF(lwp) WRITE(numout,*)
       !
-      CALL trc_ini_sms( Kmm )   ! SMS
+      CALL trc_ini_sms( Nnn_trc )   ! SMS
       CALL trc_ini_trp          ! passive tracers transport
       CALL trc_ice_ini          ! Tracers in sea ice
@@ -79,9 +81,9 @@
       ENDIF
       !
-      CALL trc_ini_state( Kbb, Kmm, Kaa )  !  passive tracers initialisation : from a restart or from clim
+      CALL trc_ini_state( Nbb_trc, Nnn_trc, Naa_trc )  !  passive tracers initialisation : from a restart or from clim
       IF( nn_dttrc /= 1 ) &
-      CALL trc_sub_ini( Kmm )    ! Initialize variables for substepping passive tracers
-      !
-      CALL trc_ini_inv( Kmm )    ! Inventories
+      CALL trc_sub_ini( Nnn_trc )    ! Initialize variables for substepping passive tracers
+      !
+      CALL trc_ini_inv( Nnn_trc )    ! Inventories
       !
       IF( ln_timing )   CALL timing_stop('trc_init')
Index: /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/trcstp.F90
===================================================================
--- /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/trcstp.F90	(revision 11426)
+++ /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/trcstp.F90	(revision 11427)
@@ -38,4 +38,9 @@
 
    !!----------------------------------------------------------------------
+   !! time level indices
+   !!----------------------------------------------------------------------
+   INTEGER, PUBLIC :: Nbb_trc, Nnn_trc, Naa_trc, Nrhs_trc      !! used by trc_init
+
+   !!----------------------------------------------------------------------
    !! NEMO/TOP 4.0 , NEMO Consortium (2018)
    !! $Id$ 
@@ -44,5 +49,5 @@
 CONTAINS
 
-   SUBROUTINE trc_stp( kt, Kbb, Kmm, Krhs, Kaa )
+   SUBROUTINE trc_stp( kt, Kbb_oce, Kmm_oce, Krhs_oce, Kaa_oce )
       !!-------------------------------------------------------------------
       !!                     ***  ROUTINE trc_stp  ***
@@ -54,5 +59,5 @@
       !!-------------------------------------------------------------------
       INTEGER, INTENT( in ) :: kt                  ! ocean time-step index
-      INTEGER, INTENT( in ) :: Kbb, Kmm, Krhs, Kaa ! time level indices
+      INTEGER, INTENT( in ) :: Kbb_oce, Kmm_oce, Krhs_oce, Kaa_oce ! time level indices
       !
       INTEGER ::   jk, jn   ! dummy loop indices
@@ -76,5 +81,5 @@
       IF( .NOT.ln_linssh ) THEN                                           ! update ocean volume due to ssh temporal evolution
          DO jk = 1, jpk
-            cvol(:,:,jk) = e1e2t(:,:) * e3t(:,:,jk,Kmm) * tmask(:,:,jk)
+            cvol(:,:,jk) = e1e2t(:,:) * e3t(:,:,jk,Kmm_oce) * tmask(:,:,jk)
          END DO
          IF ( ln_ctl .OR. kt == nitrst .OR. ( ln_check_mass .AND. kt == nitend )              &
@@ -86,5 +91,17 @@
       IF( l_trcdm2dc )   CALL trc_mean_qsr( kt )
       !    
-      IF( nn_dttrc /= 1 )   CALL trc_sub_stp( kt, Kbb, Kmm, Krhs )  ! averaging physical variables for sub-stepping
+      IF( nn_dttrc == 1 )  THEN
+         IF(lwp) WRITE(numout,*) "Kbb_oce, Kmm_oce, Kaa_oce, Krhs_oce : ",Kbb_oce, Kmm_oce, Kaa_oce, Krhs_oce
+         IF(lwp) WRITE(numout,*) "Nbb_trc, Nnn_trc, Naa_trc, Nrhs_trc : ",Nbb_trc, Nnn_trc, Naa_trc, Nrhs_trc
+         IF(lwp) CALL FLUSH(numout)
+         CALL mppsync()      
+         IF( Kmm_oce /= Nnn_trc .OR. Kaa_oce /= Naa_trc .OR. Krhs_oce /= Nrhs_trc ) THEN
+            ! The nn_dttrc == 1 case depends on the OCE and TRC time indices being the same always. 
+            ! If this is not the case then something has gone wrong.
+            CALL ctl_stop( 'trc_stp : nn_dttrc = 1 but OCE and TRC time indices are different! Something has gone wrong.' )
+         ENDIF
+      ELSE
+         CALL trc_sub_stp( kt, Nbb_trc, Nnn_trc, Nrhs_trc )  ! averaging physical variables for sub-stepping
+      ENDIF
       !    
       IF( MOD( kt , nn_dttrc ) == 0 ) THEN      ! only every nn_dttrc time step
@@ -95,19 +112,19 @@
          ENDIF
          !
-         tr(:,:,:,:,Krhs) = 0.e0
+         tr(:,:,:,:,Nrhs_trc) = 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,      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
+                                   CALL trc_wri      ( kt,          Nnn_trc                    )  ! output of passive tracers with iom I/O manager
+                                   CALL trc_sms      ( kt, Nbb_trc, Nnn_trc, Nrhs_trc          )  ! tracers: sinks and sources
+                                   CALL trc_trp      ( kt, Nbb_trc, Nnn_trc, Nrhs_trc, Naa_trc )  ! 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, Kbb, Kmm, Krhs )       ! write tracer restart file
-         IF( lk_trdmxl_trc  )      CALL trd_mxl_trc  ( kt,      Kmm       )       ! trends: Mixed-layer
-         !
-         IF( nn_dttrc /= 1   )     CALL trc_sub_reset( kt, Kbb, Kmm, Krhs )       ! resetting physical variables when sub-stepping
+         IF( lrst_trc )            CALL trc_rst_wri  ( kt, Nbb_trc, Nnn_trc, Nrhs_trc )       ! write tracer restart file
+         IF( lk_trdmxl_trc  )      CALL trd_mxl_trc  ( kt,          Nnn_trc           )       ! trends: Mixed-layer
+         !
+         IF( nn_dttrc /= 1   )     CALL trc_sub_reset( kt, Nbb_trc, Nnn_trc, Nrhs_trc )       ! resetting physical variables when sub-stepping
          !
       ENDIF
@@ -116,5 +133,5 @@
          ztrai = 0._wp                                                   !  content of all tracers
          DO jn = 1, jptra
-            ztrai = ztrai + glob_sum( 'trcstp', tr(:,:,:,jn,Kmm) * cvol(:,:,:)   )
+            ztrai = ztrai + glob_sum( 'trcstp', tr(:,:,:,jn,Nnn_trc) * cvol(:,:,:)   )
          END DO
          IF( lwm ) WRITE(numstr,9300) kt,  ztrai / areatot
Index: /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/trcsub.F90
===================================================================
--- /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/trcsub.F90	(revision 11426)
+++ /NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps_rewrite_time_filterswap/src/TOP/trcsub.F90	(revision 11427)
@@ -92,5 +92,5 @@
       !!-------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt              ! ocean time-step index
-      INTEGER, INTENT( in ) ::   Kbb, Kmm, Krhs  ! ocean time-level index
+      INTEGER, INTENT( in ) ::   Kbb, Kmm, Krhs  !       time-level index
       !
       INTEGER ::   ji, jj, jk   ! dummy loop indices
