Index: trunk/NEMO/TOP_SRC/trcrst.F90
===================================================================
--- trunk/NEMO/TOP_SRC/trcrst.F90	(revision 1099)
+++ trunk/NEMO/TOP_SRC/trcrst.F90	(revision 1100)
@@ -63,10 +63,12 @@
       !!----------------------------------------------------------------------
       !
-      IF( kt == nit000 )  THEN
-         lrst_trc = .FALSE.
+      IF( kt == nit000 ) lrst_trc = .FALSE. 
 # if defined key_off_tra
-         nitrst = nitend  ! in online version, already done in rst_opn routine defined in restart.F90 module
-# endif
+      IF( MOD( kt - 1, nstock ) == 0 ) THEN
+         ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
+         nitrst = kt + nstock - 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
+#endif
       
       IF( kt == nitrst - ndttrc .OR. nitend - nit000 + 1 < 2 * ndttrc ) THEN
@@ -308,92 +310,85 @@
       !!----------------------------------------------------------------------
 
-      IF( MOD( kt, nstock ) == 0 .OR. kt == nitend ) THEN
-
-         ! 0. initialisations
-         ! ------------------
+      IF(  kt == nitrst ) THEN
          IF(lwp) WRITE(numout,*)
          IF(lwp) WRITE(numout,*) 'trc_wri : write the TOP restart file (NetCDF) at it= ', kt, ' date= ', ndastp
          IF(lwp) WRITE(numout,*) '~~~~~~~'
-
-
-         CALL iom_rstput( kt, nitrst, numrtw, 'kt'   ,  REAL( kt, wp )  )
-
-         IF( ln_trcadv_cen2 .OR. ln_trcadv_tvd ) THEN
-            CALL iom_rstput( kt, nitrst, numrtw, 'arak0', 1. )
-         ELSE
-            CALL iom_rstput( kt, nitrst, numrtw, 'arak0', 0. )
-         ENDIF
+      ENDIF
+
+      CALL iom_rstput( kt, nitrst, numrtw, 'kt'   ,  REAL( kt, wp )  )
+      IF( ln_trcadv_cen2 .OR. ln_trcadv_tvd ) THEN
+         CALL iom_rstput( kt, nitrst, numrtw, 'arak0', 1. )
+      ELSE
+         CALL iom_rstput( kt, nitrst, numrtw, 'arak0', 0. )
+      ENDIF
 
 
          ! 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) )
-         END DO
+      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) )
+      END DO
 
 #if defined key_lobster
-         CALL iom_rstput( kt, nitrst, numrtw, 'SEDB'//ctrcnm(jpdet), sedpocb(:,:) )
-         CALL iom_rstput( kt, nitrst, numrtw, 'SEDN'//ctrcnm(jpdet), sedpocn(:,:) )
+      CALL iom_rstput( kt, nitrst, numrtw, 'SEDB'//ctrcnm(jpdet), sedpocb(:,:) )
+      CALL iom_rstput( kt, nitrst, numrtw, 'SEDN'//ctrcnm(jpdet), sedpocn(:,:) )
 #endif
 
 #if defined key_pisces
-         CALL iom_rstput( kt, nitrst, numrtw, 'Silicalim', xksi(:,:) )
-         CALL iom_rstput( kt, nitrst, numrtw, 'Silicamax', xksimax(:,:) )
+      CALL iom_rstput( kt, nitrst, numrtw, 'Silicalim', xksi(:,:) )
+      CALL iom_rstput( kt, nitrst, numrtw, 'Silicamax', xksimax(:,:) )
 #endif
 
 #if defined key_cfc
-         DO jn = jp_cfc0, jp_cfc1
-            CALL iom_rstput( kt, nitrst, numrtw, 'qint'//ctrcnm(jn), qint(:,:,jn) )
-            CALL iom_rstput( kt, nitrst, numrtw, 'qtr'//ctrcnm(jn) , qtr (:,:,jn) )
-         END DO
-#endif
-
-
-         IF(lwp) WRITE(numout,*) '----TRACER STAT----'
-
-         zdiag_tot = 0.e0
-         DO jn = 1, jptra
-            zdiag_var    = 0.e0
-            zdiag_varmin = 0.e0
-            zdiag_varmax = 0.e0
-            DO ji = 1, jpi
-               DO jj = 1, jpj
-                  DO jk = 1,jpk
-                     zdiag_var = zdiag_var + trn(ji,jj,jk,jn) * tmask(ji,jj,jk) * tmask_i(ji,jj)   &
+      DO jn = jp_cfc0, jp_cfc1
+         CALL iom_rstput( kt, nitrst, numrtw, 'qint'//ctrcnm(jn), qint(:,:,jn) )
+         CALL iom_rstput( kt, nitrst, numrtw, 'qtr'//ctrcnm(jn) , qtr (:,:,jn) )
+      END DO
+#endif
+
+       IF( kt == nitrst ) THEN
+          IF(lwp) WRITE(numout,*) '----TRACER STAT----'
+
+          zdiag_tot = 0.e0
+          DO jn = 1, jptra
+             zdiag_var    = 0.e0
+             zdiag_varmin = 0.e0
+             zdiag_varmax = 0.e0
+             DO ji = 1, jpi
+                DO jj = 1, jpj
+                   DO jk = 1,jpk
+                      zdiag_var = zdiag_var + trn(ji,jj,jk,jn) * tmask(ji,jj,jk) * tmask_i(ji,jj)   &
 #if defined key_off_degrad
-                        &   * facvol(ji,jj,jk)   &
-#endif
-                        &   * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
-                  END DO
-               END DO
-            END DO
-
-            zdiag_varmin = MINVAL( trn(:,:,:,jn), mask= ((tmask*SPREAD(tmask_i,DIM=3,NCOPIES=jpk).NE.0.)) )
-            zdiag_varmax = MAXVAL( trn(:,:,:,jn), mask= ((tmask*SPREAD(tmask_i,DIM=3,NCOPIES=jpk).NE.0.)) )
-
-            IF( lk_mpp ) THEN
-               CALL mpp_min( zdiag_varmin )      ! min over the global domain
-               CALL mpp_max( zdiag_varmax )      ! max over the global domain
-               CALL mpp_sum( zdiag_var    )      ! sum over the global domain
-            END IF
-
-            zdiag_tot = zdiag_tot + zdiag_var
-            zdiag_var = zdiag_var / areatot
-
-            IF(lwp) WRITE(numout,*) '   MEAN NO ', jn, ctrcnm(jn), ' = ', zdiag_var,   &
-               &                    ' MIN = ', zdiag_varmin, ' MAX = ', zdiag_varmax
-         END DO
-
-         zder = ( ( zdiag_tot - trai ) / ( trai + 1.e-12 )  ) * 100._wp
-         IF(lwp) WRITE(numout,*) '   Integral of all tracers over the full domain  = ', zdiag_tot
-         IF(lwp) WRITE(numout,*) '   Drift of the sum of all tracers =', zder, ' %'
-
-         CALL iom_close(numrtw)
-         !
-      ENDIF
+                         &   * facvol(ji,jj,jk)   &
+#endif
+                         &   * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk)
+                   END DO
+                END DO
+             END DO
+             
+             zdiag_varmin = MINVAL( trn(:,:,:,jn), mask= ((tmask*SPREAD(tmask_i,DIM=3,NCOPIES=jpk).NE.0.)) )
+             zdiag_varmax = MAXVAL( trn(:,:,:,jn), mask= ((tmask*SPREAD(tmask_i,DIM=3,NCOPIES=jpk).NE.0.)) )
+             IF( lk_mpp ) THEN
+                CALL mpp_min( zdiag_varmin )      ! min over the global domain
+                CALL mpp_max( zdiag_varmax )      ! max over the global domain
+                CALL mpp_sum( zdiag_var    )      ! sum over the global domain
+             END IF
+             zdiag_tot = zdiag_tot + zdiag_var
+             zdiag_var = zdiag_var / areatot
+             IF(lwp) WRITE(numout,*) '   MEAN NO ', jn, ctrcnm(jn), ' = ', zdiag_var,   &
+                &                    ' MIN = ', zdiag_varmin, ' MAX = ', zdiag_varmax
+          END DO
+          
+          zder = ( ( zdiag_tot - trai ) / ( trai + 1.e-12 )  ) * 100._wp
+          IF(lwp) WRITE(numout,*) '   Integral of all tracers over the full domain  = ', zdiag_tot
+          IF(lwp) WRITE(numout,*) '   Drift of the sum of all tracers =', zder, ' %'
+          
+          CALL iom_close( numrtw )     ! close the restart file (only at last time step)
+          lrst_trc = .FALSE.
+       ENDIF
       !
    END SUBROUTINE trc_rst_wri
