Index: NEMO/branches/2021/dev_r14318_RK3_stage1/src/OCE/stprk3_stg.F90
===================================================================
--- NEMO/branches/2021/dev_r14318_RK3_stage1/src/OCE/stprk3_stg.F90	(revision 15191)
+++ NEMO/branches/2021/dev_r14318_RK3_stage1/src/OCE/stprk3_stg.F90	(revision 15192)
@@ -22,7 +22,15 @@
    USE dynspg_ts, ONLY:   un_adv , vn_adv   ! advective transport from N to N+1
    USE bdydyn         ! ocean open boundary conditions (define bdy_dyn)
-#if defined key_agrif
+# if defined key_top
+   USE trc            ! ocean passive tracers variables
+   USE trcadv         ! advection                           (trc_adv routine)
+   USE trcsms         ! source and sink
+   USE trctrp         ! transport
+   USE trcbdy
+   USE trcstp_rk3
+# endif
+# if defined key_agrif
    USE agrif_oce_interp
-#endif
+# endif
    
    !
@@ -71,5 +79,5 @@
       INTEGER, INTENT(in) ::   kstp, Kbb, Kmm, Krhs, Kaa   ! ocean time-step and time-level indices
       !
-      INTEGER  ::   ji, jj, jk, jtile                      ! dummy loop indices
+      INTEGER  ::   ji, jj, jk, jn, jtile                  ! dummy loop indices
       REAL(wp) ::   ze3Tb, ze3Sb, z1_e3t     ! local scalars
       REAL(wp) ::   ze3Tr, ze3Sr             !   -      -
@@ -194,19 +202,67 @@
       ! RHS of tracers : ADV only using (zaU,zaV,ww)
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-#if defined key_top
+
+# if defined key_top
       !                       !==  Passive Tracer  ==!
-!===>>>>>> create a specific trc_RK3_adv routine with Advective velocity 
-!                                                and with Kstg as input argument
-!                         CALL trc_stp    ( kstp, Kbb, Kmm, Krhs, Kaa )            ! time-stepping
-#endif
+      !
+      IF( kstg == 1 ) THEN
+         CALL trc_stp_start( kstp, Kbb, Kmm, Krhs, Kaa )
+      ENDIF
+      !
+      DO jn = 1, jptra
+         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+            tr(ji,jj,jk,jn,Krhs) = 0._wp                              ! set tracer trends to zero
+         END_3D
+      END DO
+      !                                         !==  advection of passive tracers  ==!
+      rDt_trc = rDt
+      CALL trc_adv( kstp, Kbb, Kmm, tr, Krhs, zaU, zaV, ww )      ! horizontal & vertical advection
+      !
+      !
+      SELECT CASE( kstg )
+      !                    !-------------------!
+      CASE ( 1 , 2 )       !==  Stage 1 & 2  ==!   stg1:  Kbb = N  ;  Kaa = N+1/3
+         !                 !-------------------!   stg2:  Kbb = N  ;  Kmm = N+1/3  ;  Kaa = N+1/2
+         !
+         !                                      !==  time integration  ==!   ∆t = rn_Dt/3 (stg1) or rn_Dt/2 (stg2)
+         DO jn = 1, jptra
+            DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+               ze3Tb = e3t(ji,jj,jk,Kbb) * tr(ji,jj,jk,jn,Kbb )
+               ze3Tr = e3t(ji,jj,jk,Kmm) * tr(ji,jj,jk,jn,Krhs)
+               z1_e3t= 1._wp / e3t(ji,jj,jk, Kaa)
+               tr(ji,jj,jk,jn,Kaa) = ( ze3Tb + rDt * ze3Tr*tmask(ji,jj,jk) ) * z1_e3t
+            END_3D
+         END DO
+         !                 !---------------!
+      CASE ( 3 )           !==  Stage 3  ==!   add all RHS terms but advection (=> Kbb only)
+         !                 !---------------!
+         CALL trc_sms( kstp, Kbb, Kbb, Krhs      )       ! tracers: sinks and sources
+         CALL trc_trp( kstp, Kbb, Kbb, Krhs, Kaa )       ! transport of passive tracers (without advection)
+         !
+!!st a mettre dans trp 
+!!st# if defined key_agrif
+!!st         CALL Agrif_trc( kstp )                ! AGRIF zoom boundaries
+!!st# endif
+!!st         ! Update after tracer on domain lateral boundaries
+!!st         CALL lbc_lnk( 'stprk3_stg', tr(:,:,:,:,Kaa), 'T', 1._wp )   
+!!st         !
+!!st         IF( ln_bdy )  CALL trc_bdy( kstp, Kbb, Kmm, Kaa )
+         !
+         CALL trc_stp_end( kstp, Kbb, Kmm, Kaa )
+         !
+      END SELECT
+# endif
 
       !                       !==  T-S Tracers  ==!
 
 !===>>>>>> Modify tra_adv_...  routines so that Krhs to zero useless
-      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-         ts(ji,jj,jk,:,Krhs) = 0._wp                                    ! set tracer trends to zero
-      END_3D
-
-!===>>> CAUTION here sans GM velocity  but with stokes drift ! 
+      DO jn = 1, jpts
+         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+            ts(ji,jj,jk,jn,Krhs) = 0._wp                                    ! set tracer trends to zero
+         END_3D
+      END DO
+
+!===>>> CAUTION here may be without GM velocity but stokes drift required ! 0 barotropic divergence for GM  != 0 barotropic divergence for SD 
+!!st consistence 2D / 3D - flux de masse 
       CALL tra_adv( kstp, Kbb, Kmm, ts, Krhs, zaU, zaV, ww )       ! hor. + vert. advection	==> RHS
 
@@ -268,5 +324,4 @@
             &                                  tab3d_2=ts(:,:,:,jp_sal,Kaa), clinfo2=           ' Sa: ', mask2=tmask, clinfo3='tra' )
          !
-         !
          !                 !---------------!
       CASE ( 3 )           !==  Stage 3  ==!   add all remaining RHS terms
@@ -284,18 +339,11 @@
          ENDIF
 
-#if defined key_agrif
+# if defined key_agrif
          IF(.NOT. Agrif_Root() ) THEN     ! AGRIF:   sponge ==> momentum and tracer RHS
             CALL Agrif_Sponge_dyn
             CALL Agrif_Sponge_tra
          ENDIF
-#endif
+# endif
          !                                      !==  complete the tracers RHS  ==!   except ZDF (implicit)
-#if defined key_top
-         !                                            !*  Passive Tracer  *!
-
-!===>>>>>> create a specific trc_RK3_NOadv routine with other trend than ADV 
-!                                                and with Kstg as input argument
-!                         CALL trc_stp    ( kstp, Kbb, Kmm, Krhs, Kaa )            ! time-stepping
-#endif
          !                                            !*  T-S Tracer  *!
          !
@@ -324,8 +372,4 @@
          !
          IF( ln_zdfnpc  )   CALL tra_npc( kstp,      Kmm, Krhs, ts    , Kaa  )  ! update after fields by non-penetrative convection
-
-
-!==>>>>>   Missing obc CALL....
-
          !         
       END SELECT      
Index: NEMO/branches/2021/dev_r14318_RK3_stage1/src/TOP/trcstp_rk3.F90
===================================================================
--- NEMO/branches/2021/dev_r14318_RK3_stage1/src/TOP/trcstp_rk3.F90	(revision 15192)
+++ NEMO/branches/2021/dev_r14318_RK3_stage1/src/TOP/trcstp_rk3.F90	(revision 15192)
@@ -0,0 +1,370 @@
+MODULE trcstp_rk3
+   !!======================================================================
+   !!                       ***  MODULE trcstp_rk3  ***
+   !! Time-stepping    : time loop of opa for passive tracer
+   !!======================================================================
+   !! 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
+   !!----------------------------------------------------------------------
+   !!   trc_stp       : passive tracer system time-stepping
+   !!----------------------------------------------------------------------
+   USE par_trc        ! need jptra, number of passive tracers
+   USE oce_trc        ! ocean dynamics and active tracers variables
+   USE sbc_oce
+   USE trc
+   USE trctrp         ! passive tracers transport
+   USE trcsms         ! passive tracers sources and sinks
+   USE trcwri
+   USE trcrst
+   USE trdtrc_oce
+   USE trdmxl_trc
+   USE sms_pisces,  ONLY : ln_check_mass
+   !
+   USE prtctl         ! Print control for debbuging
+   USE iom            !
+   USE in_out_manager !
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_stp_start   ! called by stprk3_stg
+   PUBLIC   trc_stp_end     ! called by stprk3_stg
+
+   LOGICAL  ::   llnew                   ! ???
+   LOGICAL  ::   l_trcstat               ! flag for tracer statistics
+   REAL(wp) ::   rdt_sampl               ! ???
+   INTEGER  ::   nb_rec_per_day, ktdcy   ! ???
+   REAL(wp) ::   rsecfst, rseclast       ! ???
+   REAL(wp), DIMENSION(:,:,:), SAVE, ALLOCATABLE ::   qsr_arr   ! save qsr during TOP time-step
+
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
+   !! $Id: trcstp.F90 14086 2020-12-04 11:37:14Z cetlod $ 
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+  
+   SUBROUTINE trc_stp_start( kt, Kbb, Kmm, Krhs, Kaa )
+      !!-------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_stp_start  ***
+      !!                      
+      !! ** Purpose :   Time loop of opa for passive tracer
+      !! 
+      !! ** Method  :   Compute the passive tracers trends 
+      !!                Update the passive tracers
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT( in ) :: kt                  ! ocean time-step index
+      INTEGER, INTENT( in ) :: Kbb, Kmm, Krhs, Kaa ! time level indices
+      !
+      INTEGER ::   jk, jn   ! dummy loop indices
+      CHARACTER (len=25) ::   charout   !
+      !!-------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('trc_stp_start')
+      !
+      l_trcstat  = ( sn_cfctl%l_trcstat ) .AND. &
+           &       ( ( MOD( kt, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend ) )
+!!st should be in init of top
+      IF( kt == nittrc000 )                      CALL trc_stp_ctl   ! control 
+      IF( kt == nittrc000 .AND. lk_trdmxl_trc )  CALL trd_mxl_trc_init    ! trends: Mixed-layer
+!!st-gm
+!!st-gm a faire uniquement au stage 3
+!!st      !
+      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)
+         END DO
+         IF( l_trcstat .OR. kt == nitrst .OR. ( ln_check_mass .AND. kt == nitend ) )   &
+            &     areatot = glob_sum( 'trcstp', cvol(:,:,:) )
+      ENDIF
+      !
+      IF( l_trcdm2dc )   CALL trc_mean_qsr( kt )
+      !    
+      !
+      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
+      !
+!!st      tr(:,:,:,:,Krhs) = 0._wp
+      !
+      CALL trc_rst_opn  ( kt )                            ! Open tracer restart file 
+      IF( lrst_trc )  CALL trc_rst_cal  ( kt, 'WRITE' )   ! calendar
+!!st cf. stage 3      CALL trc_wri      ( kt,      Kmm            )       ! output of passive tracers with iom I/O manager
+      !
+      IF( ln_timing )   CALL timing_stop('trc_stp_start')
+      !
+   END SUBROUTINE trc_stp_start
+
+
+   SUBROUTINE trc_stp( kt, Kbb, Kmm, Krhs, Kaa )
+      !!-------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_stp  ***
+      !!                      
+      !! ** Purpose :   Time loop of opa for passive tracer
+      !! 
+      !! ** Method  :   Compute the passive tracers trends 
+      !!                Update the passive tracers
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT( in ) :: kt                  ! ocean time-step index
+      INTEGER, INTENT( in ) :: Kbb, Kmm, Krhs, Kaa ! time level indices
+      !
+      INTEGER ::   jk, jn   ! dummy loop indices
+      REAL(wp)::   ztrai    ! local scalar
+      CHARACTER (len=25) ::   charout   !
+      !!-------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('trc_stp')
+      !
+      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
+      !
+      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)
+         END DO
+!!st         IF ( l_trcstat .OR. kt == nitrst .OR. ( ln_check_mass .AND. kt == nitend )   &
+!!st            & .OR. iom_use( "pno3tot" ) .OR. iom_use( "ppo4tot" ) .OR. iom_use( "psiltot" )   &
+!!st            & .OR. iom_use( "palktot" ) .OR. iom_use( "pfertot" ) )                           &
+!!st            &     areatot = glob_sum( 'trcstp', cvol(:,:,:) )
+      ENDIF
+      !
+      tr(:,:,:,:,Krhs) = 0._wp
+      !
+      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(lrxios) CALL iom_context_finalize(      cr_toprst_cxt          )
+         IF(lwm) CALL FLUSH( numont )                     ! flush namelist output
+      ENDIF
+      IF( lrst_trc )            CALL trc_rst_wri  ( kt, Kbb, Kmm, Kaa  )       ! 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
+      !
+      IF (l_trcstat) THEN
+         ztrai = 0._wp                                                   !  content of all tracers
+         DO jn = 1, jptra
+            ztrai = ztrai + glob_sum( 'trcstp', tr(:,:,:,jn,Kaa) * cvol(:,:,:)   )
+         END DO
+         IF( lwm ) WRITE(numstr,9300) kt,  ztrai / areatot
+      ENDIF
+9300  FORMAT(i10,D23.16)
+      !
+      IF( ln_timing )   CALL timing_stop('trc_stp')
+      !
+   END SUBROUTINE trc_stp
+
+
+   SUBROUTINE trc_stp_end( kt, Kbb, Kmm, Kaa )
+      !!-------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_stp_end  ***
+      !!                      
+      !! ** Purpose :   Time loop of opa for passive tracer
+      !! 
+      !! ** Method  :   Compute the passive tracers trends 
+      !!                Update the passive tracers
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT( in ) :: kt                  ! ocean time-step index
+      INTEGER, INTENT( in ) :: Kbb, Kmm, Kaa ! time level indices
+      !
+      INTEGER ::   jk, jn   ! dummy loop indices
+      REAL(wp)::   ztrai    ! local scalar
+      CHARACTER (len=25) ::   charout   !
+      !!-------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('trc_stp_end')
+      !
+            !
+           ! 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(lrxios) CALL iom_context_finalize(      cr_toprst_cxt          )
+         IF(lwm) CALL FLUSH( numont )                     ! flush namelist output
+      ENDIF
+      IF( lrst_trc )            CALL trc_rst_wri  ( kt, Kbb, Kmm, Kaa )       ! write tracer restart file
+      IF( lk_trdmxl_trc  )      CALL trd_mxl_trc  ( kt,           Kaa )       ! trends: Mixed-layer
+      !
+      IF (l_trcstat) THEN
+         ztrai = 0._wp                                                   !  content of all tracers
+         DO jn = 1, jptra
+            ztrai = ztrai + glob_sum( 'trcstp_rk3', tr(:,:,:,jn,Kaa) * cvol(:,:,:)   ) !!st cvol@Kmm weird !!
+         END DO
+         IF( lwm ) WRITE(numstr,9300) kt,  ztrai / areatot
+      ENDIF
+      !
+9300  FORMAT(i10,D23.16)
+      !
+      CALL trc_wri      ( kt,      Kaa            )       ! output of passive tracers with iom I/O manager (!!st Kbb car après le swap des indices !!st-correction FAUX on est avant : le swap a lieu après le CALL à stp_RK3_stg(3) )
+      !
+      IF( ln_timing )   CALL timing_stop('trc_stp_end')
+      !
+   END SUBROUTINE trc_stp_end
+
+
+   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
+
+
+   SUBROUTINE trc_mean_qsr( kt )
+      !!----------------------------------------------------------------------
+      !!             ***  ROUTINE trc_mean_qsr  ***
+      !!
+      !! ** Purpose :  Compute daily mean qsr for biogeochemical model in case
+      !!               of diurnal cycle
+      !!
+      !! ** Method  : store in TOP the qsr every hour ( or every time-step if the latter 
+      !!              is greater than 1 hour ) and then, compute the  mean with 
+      !!              a moving average over 24 hours. 
+      !!              In coupled mode, the sampling is done at every coupling frequency 
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !
+      INTEGER  ::   jn   ! dummy loop indices
+      REAL(wp) ::   zkt, zrec     ! local scalars
+      CHARACTER(len=1) ::   cl1   ! 1 character
+      CHARACTER(len=2) ::   cl2   ! 2 characters
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('trc_mean_qsr')
+      !
+      IF( kt == nittrc000 ) THEN
+         IF( ln_cpl )  THEN  
+            rdt_sampl = rday / ncpl_qsr_freq
+            nb_rec_per_day = ncpl_qsr_freq
+         ELSE  
+            rdt_sampl = MAX( 3600., rn_Dt )
+            nb_rec_per_day = INT( rday / rdt_sampl )
+         ENDIF
+         !
+         IF(lwp) THEN
+            WRITE(numout,*) 
+            WRITE(numout,*) ' Sampling frequency dt = ', rdt_sampl, 's','   Number of sampling per day  nrec = ', nb_rec_per_day
+            WRITE(numout,*) 
+         ENDIF
+         !
+         ALLOCATE( qsr_arr(jpi,jpj,nb_rec_per_day ) )
+         !
+         !                                            !* Restart: read in restart file
+         IF( ln_rsttr .AND. nn_rsttr /= 0 .AND. iom_varid( numrtr, 'qsr_mean' , ldstop = .FALSE. ) > 0  &
+           &                              .AND. iom_varid( numrtr, 'qsr_arr_1', ldstop = .FALSE. ) > 0  &
+           &                              .AND. iom_varid( numrtr, 'ktdcy'    , ldstop = .FALSE. ) > 0  &
+           &                              .AND. iom_varid( numrtr, 'nrdcy'    , ldstop = .FALSE. ) > 0  ) THEN
+            CALL iom_get( numrtr, 'ktdcy', zkt )  
+            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_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
+               DO jn = 1, nb_rec_per_day 
+                  IF( jn <= 9 )  THEN
+                    WRITE(cl1,'(i1)') jn
+                    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_auto, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) )   !  A mean of qsr
+                  ENDIF
+              END DO
+            ELSE
+               DO jn = 1, nb_rec_per_day
+                  qsr_arr(:,:,jn) = qsr_mean(:,:)
+               END DO
+            ENDIF
+         ELSE                                         !* no restart: set from nit000 values
+            IF(lwp) WRITE(numout,*) 'trc_qsr_mean:   qsr_mean set to nit000 values'
+            rsecfst  = kt * rn_Dt
+            !
+            qsr_mean(:,:) = qsr(:,:)
+            DO jn = 1, nb_rec_per_day
+               qsr_arr(:,:,jn) = qsr_mean(:,:)
+            END DO
+         ENDIF
+         !
+      ENDIF
+      !
+      rseclast = kt * rn_Dt
+      !
+      llnew   = ( rseclast - rsecfst ) >=  rdt_sampl    !   new shortwave to store
+      IF( llnew ) THEN
+          ktdcy = kt
+          IF( lwp .AND. kt < nittrc000 + 100 ) WRITE(numout,*) ' New shortwave to sample for TOP at time kt = ', ktdcy, &
+             &                      ' time = ', rseclast/3600.,'hours '
+          rsecfst = rseclast
+          DO jn = 1, nb_rec_per_day - 1
+             qsr_arr(:,:,jn) = qsr_arr(:,:,jn+1)
+          END DO
+          qsr_arr (:,:,nb_rec_per_day) = qsr(:,:)
+          qsr_mean(:,:                ) = SUM( qsr_arr(:,:,:), 3 ) / nb_rec_per_day
+      ENDIF
+      !
+      IF( lrst_trc ) THEN    !* Write the mean of qsr in restart file 
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc_mean_qsr : write qsr_mean in restart file  kt =', kt
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+         zkt  = REAL( ktdcy, wp )
+         zrec = REAL( nb_rec_per_day, wp )
+         CALL iom_rstput( kt, nitrst, numrtw, 'ktdcy', zkt  )
+         CALL iom_rstput( kt, nitrst, numrtw, 'nrdcy', zrec )
+          DO jn = 1, nb_rec_per_day 
+             IF( jn <= 9 )  THEN
+               WRITE(cl1,'(i1)') jn
+               CALL iom_rstput( kt, nitrst, numrtw, 'qsr_arr_'//cl1, qsr_arr(:,:,jn) )
+             ELSE
+               WRITE(cl2,'(i2.2)') jn
+               CALL iom_rstput( kt, nitrst, numrtw, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) )
+             ENDIF
+         END DO
+         CALL iom_rstput( kt, nitrst, numrtw, 'qsr_mean', qsr_mean(:,:) )
+      ENDIF
+      !
+      IF( ln_timing )   CALL timing_stop('trc_mean_qsr')
+      !
+   END SUBROUTINE trc_mean_qsr
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default key                                     NO passive tracers
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_stp( kt )        ! Empty routine
+      WRITE(*,*) 'trc_stp: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_stp
+#endif
+
+   !!======================================================================
+END MODULE trcstp_rk3
