Index: trunk/NEMOGCM/NEMO/TOP_SRC/trcrst.F90
===================================================================
--- trunk/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 2524)
+++ trunk/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 2528)
@@ -25,6 +25,7 @@
    USE oce_trc
    USE trc
-   USE trctrp_lec
+   USE trcnam_trp
    USE lib_mpp
+   USE lib_fortran
    USE iom
    USE trcrst_cfc      ! CFC      
@@ -33,7 +34,5 @@
    USE trcrst_c14b     ! C14 bomb restart
    USE trcrst_my_trc   ! MY_TRC   restart
-#if defined key_off_tra
-    USE daymod
-#endif
+   USE daymod
    IMPLICIT NONE
    PRIVATE
@@ -47,9 +46,4 @@
    !! * Substitutions
 #  include "top_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
-   !! $Id$ 
-   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
    
 CONTAINS
@@ -67,22 +61,23 @@
       !!----------------------------------------------------------------------
       !
-# if ! defined key_off_tra
-      IF( kt == nit000 ) lrst_trc = .FALSE. 
-# else
-      IF( kt == nit000 ) THEN
-        lrst_trc = .FALSE. 
-        nitrst = nitend  
-      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
-     ! 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*ndttrc + 1)
-     ! except if we write tracer restart files every tracer time step or if a tracer restart file was writen at nitend - 2*ndttrc + 1
-     IF( kt == nitrst - 2*ndttrc + 1 .OR. nstock == ndttrc .OR. ( kt == nitend - ndttrc + 1 .AND. .NOT. lrst_trc ) ) THEN
+      IF( lk_offline ) THEN
+         IF( kt == nit000 ) THEN
+            lrst_trc = .FALSE.
+            nitrst = nitend
+         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
+      ELSE
+         IF( kt == nit000 ) lrst_trc = .FALSE.
+      ENDIF
+
+      ! 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 + 1 .OR. nstock == nn_dttrc .OR. ( kt == nitend - nn_dttrc + 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
@@ -106,6 +101,4 @@
       !!----------------------------------------------------------------------
       INTEGER  ::  jn     
-      INTEGER  ::  iarak0 
-      REAL(wp) ::  zarak0
       INTEGER  ::  jlibalt = jprstlib
       LOGICAL  ::  llok
@@ -128,17 +121,5 @@
       ! Time domain : restart
       ! ---------------------
-      CALL trc_rst_cal( nittrc000, 'READ' )   ! calendar
-
-      IF( ln_trcadv_cen2 .OR. ln_trcadv_tvd ) THEN   ;   iarak0 = 1
-      ELSE                                           ;   iarak0 = 0
-      ENDIF
-      CALL iom_get( numrtr, 'arak0', zarak0 )
-
-      IF( iarak0 /= NINT( zarak0 ) )   &                           ! Control of the scheme
-         & CALL ctl_stop( ' ===>>>> : problem with advection scheme', &
-         & ' it must be the same type for both restart and previous run', &
-         & ' centered or euler '  )
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '    arakawa option      : ', NINT( zarak0 )
+      CALL trc_rst_cal( nit000, 'READ' )   ! calendar
 
       ! READ prognostic variables and computes diagnostic variable
@@ -175,10 +156,5 @@
 
       CALL trc_rst_cal( kt, 'WRITE' )   ! calendar
-
-      IF( ln_trcadv_cen2 .OR. ln_trcadv_tvd ) THEN   ;   zarak0 = 1.
-      ELSE                                           ;   zarak0 = 0.
-      ENDIF
-      CALL iom_rstput( kt, nitrst, numrtw, 'arak0', zarak0 )
-
+      CALL iom_rstput( kt, nitrst, numrtw, 'rdttrc1', rdttrc(1) )   ! surface passive tracer time step
       ! prognostic variables 
       ! -------------------- 
@@ -222,6 +198,6 @@
       !!
       !!   According to namelist parameter nrstdt,
-      !!       nrsttr = 0  no control on the date (nittrc000 is  arbitrary).
-      !!       nrsttr = 1  we verify that nit000 is equal to the last
+      !!       nn_rsttr = 0  no control on the date (nit000 is  arbitrary).
+      !!       nn_rsttr = 1  we verify that nit000 is equal to the last
       !!                   time step of previous run + 1.
       !!       In both those options, the  exact duration of the experiment
@@ -230,5 +206,5 @@
       !!       This is valid is the time step has remained constant.
       !!
-      !!       nrsttr = 2  the duration of the experiment in days (adatrj)
+      !!       nn_rsttr = 2  the duration of the experiment in days (adatrj)
       !!                    has been stored in the restart file.
       !!----------------------------------------------------------------------
@@ -236,8 +212,6 @@
       CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
       !
-      REAL(wp) ::  zkt
-#if defined key_off_tra
+      REAL(wp) ::  zkt, zrdttrc1
       REAL(wp) ::  zndastp
-#endif
 
       ! Time domain : restart
@@ -250,38 +224,43 @@
             WRITE(numout,*) '   previous time-step                               : ', NINT( zkt )
             WRITE(numout,*) ' *** restart option'
-            SELECT CASE ( nrsttr )
-            CASE ( 0 )   ;   WRITE(numout,*) ' nrsttr = 0 : no control of nittrc000'
-            CASE ( 1 )   ;   WRITE(numout,*) ' nrsttr = 1 : no control the date at nit000 (use ndate0 read in the namelist)'
-            CASE ( 2 )   ;   WRITE(numout,*) ' nrsttr = 2 : calendar parameters read in restart'
+            SELECT CASE ( nn_rsttr )
+            CASE ( 0 )   ;   WRITE(numout,*) ' nn_rsttr = 0 : no control of nit000'
+            CASE ( 1 )   ;   WRITE(numout,*) ' nn_rsttr = 1 : no control the date at nit000 (use ndate0 read in the namelist)'
+            CASE ( 2 )   ;   WRITE(numout,*) ' nn_rsttr = 2 : calendar parameters read in restart'
             END SELECT
             WRITE(numout,*)
          ENDIF
          ! Control of date 
-         IF( nittrc000  - NINT( zkt ) /= 1 .AND.  nrsttr /= 0 )                                  &
+         IF( nit000  - NINT( zkt ) /= 1 .AND.  nn_rsttr /= 0 )                                  &
             &   CALL ctl_stop( ' ===>>>> : problem with nit000 for the restart',                 &
-            &                  ' verify the restart file or rerun with nrsttr = 0 (namelist)' )
-#if defined key_off_tra
-         ! define ndastp and adatrj
-         IF ( nrsttr == 2 ) THEN
-            CALL iom_get( numrtr, 'ndastp', zndastp ) 
-            ndastp = NINT( zndastp )
-            CALL iom_get( numrtr, 'adatrj', adatrj  )
-         ELSE
-            ndastp = ndate0 - 1     ! ndate0 read in the namelist in dom_nam
-            adatrj = ( REAL( nittrc000-1, wp ) * rdttra(1) ) / rday
-            ! note this is wrong if time step has changed during run
+            &                  ' verify the restart file or rerun with nn_rsttr = 0 (namelist)' )
+         IF( lk_offline ) THEN      ! set the date in offline mode
+            ! Check dynamics and tracer time-step consistency and force Euler restart if changed
+            IF( iom_varid( numrtr, 'rdttrc1', ldstop = .FALSE. ) > 0 )   THEN
+               CALL iom_get( numrtr, 'rdttrc1', zrdttrc1 )
+               IF( zrdttrc1 /= rdttrc(1) )   neuler = 0
+            ENDIF
+            !                          ! define ndastp and adatrj
+            IF ( nn_rsttr == 2 ) THEN
+               CALL iom_get( numrtr, 'ndastp', zndastp ) 
+               ndastp = NINT( zndastp )
+               CALL iom_get( numrtr, 'adatrj', adatrj  )
+            ELSE
+               ndastp = ndate0 - 1     ! ndate0 read in the namelist in dom_nam
+               adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday
+               ! note this is wrong if time step has changed during run
+            ENDIF
+            !
+            IF(lwp) THEN
+              WRITE(numout,*) ' *** Info used values : '
+              WRITE(numout,*) '   date ndastp                                      : ', ndastp
+              WRITE(numout,*) '   number of elapsed days since the begining of run : ', adatrj
+              WRITE(numout,*)
+            ENDIF
+            !
+            CALL day_init          ! compute calendar
+            !
          ENDIF
          !
-         IF(lwp) THEN
-           WRITE(numout,*) ' *** Info used values : '
-           WRITE(numout,*) '   date ndastp                                      : ', ndastp
-           WRITE(numout,*) '   number of elapsed days since the begining of run : ', adatrj
-           WRITE(numout,*)
-         ENDIF
-         !
-         CALL day_init          ! compute calendar
-         !
-#endif
-
       ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN
          !
@@ -291,5 +270,4 @@
             IF(lwp) WRITE(numout,*) '~~~~~~~'
          ENDIF
-         ! calendar control
          CALL iom_rstput( kt, nitrst, numrtw, 'kt'     , REAL( kt    , wp) )   ! time-step
          CALL iom_rstput( kt, nitrst, numrtw, 'ndastp' , REAL( ndastp, wp) )   ! date
@@ -308,7 +286,7 @@
       !!----------------------------------------------------------------------
 
-      INTEGER  :: ji, jj, jk, jn
+      INTEGER  :: jn
       REAL(wp) :: zdiag_var, zdiag_varmin, zdiag_varmax, zdiag_tot
-      REAL(wp) :: zder, zvol
+      REAL(wp) :: zder
       !!----------------------------------------------------------------------
 
@@ -322,19 +300,9 @@
       zdiag_tot = 0.e0
       DO jn = 1, jptra
-         zdiag_var    = 0.e0
-         zdiag_varmin = 0.e0
-         zdiag_varmax = 0.e0
-         DO jk = 1, jpk
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zvol = cvol(ji,jj,jk)
-#  if defined key_off_degrad
-                  zvol = zvol * facvol(ji,jj,jk)
+#  if defined key_degrad
+         zdiag_var = glob_sum( trn(:,:,:,jn) * cvol(:,:,:) * facvol(:,:,:) )
+#  else
+         zdiag_var = glob_sum( trn(:,:,:,jn) * cvol(:,:,:)  )
 #  endif
-                  zdiag_var = zdiag_var + trn(ji,jj,jk,jn) * zvol
-               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.)) )
@@ -342,5 +310,4 @@
             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
@@ -369,4 +336,8 @@
 #endif
 
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!======================================================================
 END MODULE trcrst
