Index: /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 8466)
+++ /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 8467)
@@ -28,5 +28,5 @@
    USE zpshde          ! partial step: hor. derivative       (zps_hde routine)
 # if defined key_debug_medusa
-   USE trcrst
+   USE trcstat
 # endif
 
Index: /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc.F90	(revision 8466)
+++ /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc.F90	(revision 8467)
@@ -19,4 +19,7 @@
    USE trdmxl_trc        ! Mixed layer trends diag.
    USE iom               ! I/O library
+# if defined key_debug_medusa
+   USE trcstat,          ONLY: trc_rst_dia_stat     
+# endif
 
    IMPLICIT NONE
@@ -100,5 +103,5 @@
          CASE( jptra_tot  )       ;    WRITE (cltra,'("TOT_",4a)')
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          END SELECT
          !
@@ -107,41 +110,41 @@
          CASE( jptra_xad  )       ;    WRITE (cltra,'("XAD_",4a)')
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_yad  )       ;    WRITE (cltra,'("YAD_",4a)')
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_zad  )       ;    WRITE (cltra,'("ZAD_",4a)')      !! care vvl case
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_totad  )     ;    WRITE (cltra,'("TAD_",4a)')      !! total adv
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_ldf  )       ;    WRITE (cltra,'("LDF_",4a)')
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_bbl  )       ;    WRITE (cltra,'("BBL_",4a)')
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_nsr  )       ;    WRITE (cltra,'("FOR_",4a)')
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_zdf  )       ;    WRITE (cltra,'("ZDF_",4a)')
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_zdfp )       ;    WRITE (cltra,'("ZDP_",4a)')
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_dmp  )       ;    WRITE (cltra,'("DMP_",4a)')
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_sms  )       ;    WRITE (cltra,'("SMS_",4a)')
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_radb )       ;    WRITE (cltra,'("RDB_",4a)')
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          CASE( jptra_radn )       ;    WRITE (cltra,'("RDN_",4a)')
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          END SELECT
        ELSE IF( MOD( kt, 2 ) == 1 ) THEN
@@ -149,5 +152,5 @@
          CASE( jptra_atf  )       ;    WRITE (cltra,'("ATF_",4a)')
                            cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                           IF  (iom_use(cltra))  CALL iom_put( cltra,  ptrtrd(:,:,:) )
+                           CALL trd_trc_iomput( cltra, ptrtrd, kjn, kt )
          END SELECT
        END IF
@@ -172,4 +175,33 @@
 
    END SUBROUTINE trd_trc_bio
+
+   SUBROUTINE trd_trc_iomput( cltra, ptrtrd, kjn, kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_trc_iomput  ***
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in )  ::   kt                                  ! timestep
+      INTEGER, INTENT( in )  ::   kjn                                 ! biotrend index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout )  ::   ptrtrd  ! var trend
+      CHARACTER (len=*),INTENT( in ) :: cltra                         ! trend name
+      !!----------------------------------------------------------------------
+
+
+                           IF  (iom_use(cltra)) THEN
+# if defined key_debug_medusa
+                              IF(lwp) WRITE(numout,*) ' TREND stats (min, max,sum) kt = ',kt ,' jn = ',kjn
+                              CALL trc_rst_dia_stat( ptrtrd(:,:,1), cltra)
+# endif
+                              CALL iom_put( cltra,  ptrtrd(:,:,:) )
+# if defined key_debug_medusa
+                           ELSE
+                              IF(lwp) WRITE(numout,*) &
+                              ' TREND -- No output asked for ',cltra,' kt = ',kt,' jn = ',kjn
+                              CALL trc_rst_dia_stat( ptrtrd(:,:,1), cltra)
+# endif
+                           ENDIF
+
+   END SUBROUTINE trd_trc_iomput
+
+
 #else
    !!----------------------------------------------------------------------
Index: /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/trcrst.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 8466)
+++ /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 8467)
@@ -43,4 +43,5 @@
    USE sbc_oce, ONLY: lk_oasis 
    USE oce,     ONLY: CO2Flux_out_cpl, DMS_out_cpl, chloro_out_cpl  !! Coupling variable
+   USE trcstat
 
    IMPLICIT NONE
@@ -52,6 +53,4 @@
    PUBLIC   trc_rst_cal
    PUBLIC   trc_rst_stat
-   PUBLIC   trc_rst_dia_stat
-   PUBLIC   trc_rst_tra_stat
 
    !! * Substitutions
@@ -697,90 +696,4 @@
 
 
-   SUBROUTINE trc_rst_tra_stat
-      !!----------------------------------------------------------------------
-      !!                    ***  trc_rst_tra_stat  ***
-      !!
-      !! ** purpose  :   Compute tracers statistics - check where crazy values appears
-      !!----------------------------------------------------------------------
-      INTEGER  :: jk, jn
-      REAL(wp) :: ztraf, zmin, zmax, zmean, zdrift, areasf
-      REAL(wp), DIMENSION(jpi,jpj) :: zvol
-      !!----------------------------------------------------------------------
-
-      IF( lwp ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) '           ----SURFACE TRA STAT----             '
-         WRITE(numout,*)
-      ENDIF
-      !
-      zvol(:,:) = e1e2t(:,:) * fse3t_a(:,:,1) * tmask(:,:,1)
-      areasf = glob_sum(zvol(:,:))
-      DO jn = 1, jptra
-         ztraf = glob_sum( tra(:,:,1,jn) * zvol(:,:) )
-         zmin  = MINVAL( tra(:,:,1,jn), mask= ((tmask(:,:,1).NE.0.)) )
-         zmax  = MAXVAL( tra(:,:,1,jn), mask= ((tmask(:,:,1).NE.0.)) )
-         IF( lk_mpp ) THEN
-            CALL mpp_min( zmin )      ! min over the global domain
-            CALL mpp_max( zmax )      ! max over the global domain
-         END IF
-         zmean  = ztraf / areasf
-         IF(lwp) WRITE(numout,9001) jn, TRIM( ctrcnm(jn) ), zmean, zmin, zmax
-      END DO
-      IF(lwp) WRITE(numout,*)
-9001  FORMAT(' tracer nb :',i2,'    name :',a10,'    mean :',e18.10,'    min :',e18.10, &
-      &      '    max :',e18.10)
-      !
-   END SUBROUTINE trc_rst_tra_stat
-
-
-
-   SUBROUTINE trc_rst_dia_stat( dgtr, names)
-      !!----------------------------------------------------------------------
-      !!                    ***  trc_rst_dia_stat  ***
-      !!
-      !! ** purpose  :   Compute tracers statistics
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj) , INTENT(in) ::   dgtr      ! 2D diag var
-      CHARACTER(len=*)             , INTENT(in) ::   names     ! 2D diag name
-      !!---------------------------------------------------------------------
-      INTEGER  :: jk, jn
-      CHARACTER (LEN=18) :: text_zmean
-      REAL(wp) :: ztraf, zmin, zmax, zmean, areasf
-      REAL(wp), DIMENSION(jpi,jpj) :: zvol
-      !!----------------------------------------------------------------------
-
-      IF( lwp )  WRITE(numout,*) 'STAT- ', names
-      
-      ! fse3t_a will be undefined at the start of a run, but this routine
-      ! may be called at any stage! Hence we MUST make sure it is 
-      ! initialised to zero when allocated to enable us to test for 
-      ! zero content here and avoid potentially dangerous and non-portable 
-      ! operations (e.g. divide by zero, global sums of junk values etc.)   
-      zvol(:,:) = e1e2t(:,:) * fse3t_a(:,:,1) * tmask(:,:,1)
-      ztraf = glob_sum( dgtr(:,:) * zvol(:,:) )
-      !! areasf = glob_sum(e1e2t(:,:) * tmask(:,:,1) )
-      areasf = glob_sum(zvol(:,:))
-      zmin  = MINVAL( dgtr(:,:), mask= ((tmask(:,:,1).NE.0.)) )
-      zmax  = MAXVAL( dgtr(:,:), mask= ((tmask(:,:,1).NE.0.)) )
-      IF( lk_mpp ) THEN
-         CALL mpp_min( zmin )      ! min over the global domain
-         CALL mpp_max( zmax )      ! max over the global domain
-      END IF
-
-      text_zmean = "N/A"
-      ! Avoid divide by zero. areasf must be positive.
-      IF  (areasf > 0.0) THEN 
-         zmean = ztraf / areasf
-         WRITE(text_zmean,'(e18.10)') zmean
-      ENDIF
-
-      IF(lwp) WRITE(numout,9002) TRIM( names ), text_zmean, zmin, zmax
-
-  9002  FORMAT(' tracer name :',A,'    mean :',A,'    min :',e18.10, &
-      &      '    max :',e18.10 )
-      !
-   END SUBROUTINE trc_rst_dia_stat
-
-
 #else
    !!----------------------------------------------------------------------
Index: /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/trcstat.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/trcstat.F90	(revision 8467)
+++ /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/trcstat.F90	(revision 8467)
@@ -0,0 +1,154 @@
+MODULE trcstat
+   !!======================================================================
+   !!                         ***  MODULE trcrst  ***
+   !! TOP :   Manage the passive tracer restart
+   !!======================================================================
+   !! History :    -   !  1991-03  ()  original code
+   !!             1.0  !  2005-03 (O. Aumont, A. El Moussaoui) F90
+   !!              -   !  2005-10 (C. Ethe) print control
+   !!             2.0  !  2005-10 (C. Ethe, G. Madec) revised architecture
+   !!----------------------------------------------------------------------
+#if defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   trc_rst :   Restart for passive tracer
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   !!   trc_rst_opn    : open  restart file
+   !!   trc_rst_read   : read  restart file
+   !!   trc_rst_wri    : write restart file
+   !!----------------------------------------------------------------------
+   USE trc,               ONLY: tra, ctrcnm
+   USE par_kind,          ONLY: wp
+   USE in_out_manager,    ONLY: lwp, numout
+   USE par_oce,           ONLY: jpi, jpj
+   USE par_trc,           ONLY: jptra
+   USE dom_oce,           ONLY: e3t_0, e3t_a, e3t_n, gdepw_0, gdepw_n,     &
+                          tmask, e1e2t
+   !* MPP library                         
+   USE lib_mpp
+   !* Fortran utilities                         
+   USE lib_fortran
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_rst_dia_stat
+   PUBLIC   trc_rst_tra_stat
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   
+CONTAINS
+   
+   SUBROUTINE trc_rst_tra_stat
+      !!----------------------------------------------------------------------
+      !!                    ***  trc_rst_tra_stat  ***
+      !!
+      !! ** purpose  :   Compute tracers statistics - check where crazy values appears
+      !!----------------------------------------------------------------------
+      INTEGER  :: jk, jn
+      REAL(wp) :: ztraf, zmin, zmax, zmean, zdrift, areasf
+      REAL(wp), DIMENSION(jpi,jpj) :: zvol
+      !!----------------------------------------------------------------------
+
+      IF( lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '           ----SURFACE TRA STAT----             '
+         WRITE(numout,*)
+      ENDIF
+      !
+      zvol(:,:) = e1e2t(:,:) * fse3t_a(:,:,1) * tmask(:,:,1)
+      areasf = glob_sum(zvol(:,:))
+      DO jn = 1, jptra
+         ztraf = glob_sum( tra(:,:,1,jn) * zvol(:,:) )
+         zmin  = MINVAL( tra(:,:,1,jn), mask= ((tmask(:,:,1).NE.0.)) )
+         zmax  = MAXVAL( tra(:,:,1,jn), mask= ((tmask(:,:,1).NE.0.)) )
+         IF( lk_mpp ) THEN
+            CALL mpp_min( zmin )      ! min over the global domain
+            CALL mpp_max( zmax )      ! max over the global domain
+         END IF
+         zmean  = ztraf / areasf
+         IF(lwp) WRITE(numout,9001) jn, TRIM( ctrcnm(jn) ), zmean, zmin, zmax
+      END DO
+      IF(lwp) WRITE(numout,*)
+9001  FORMAT(' tracer nb :',i2,'    name :',a10,'    mean :',e18.10,'    min :',e18.10, &
+      &      '    max :',e18.10)
+      !
+   END SUBROUTINE trc_rst_tra_stat
+
+
+
+   SUBROUTINE trc_rst_dia_stat( dgtr, names)
+      !!----------------------------------------------------------------------
+      !!                    ***  trc_rst_dia_stat  ***
+      !!
+      !! ** purpose  :   Compute tracers statistics
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj) , INTENT(in) ::   dgtr      ! 2D diag var
+      CHARACTER(len=*)             , INTENT(in) ::   names     ! 2D diag name
+      !!---------------------------------------------------------------------
+      INTEGER  :: jk, jn
+      CHARACTER (LEN=18) :: text_zmean
+      REAL(wp) :: ztraf, zmin, zmax, zmean, areasf
+      REAL(wp), DIMENSION(jpi,jpj) :: zvol
+      !!----------------------------------------------------------------------
+
+      IF( lwp )  WRITE(numout,*) 'STAT- ', names
+      
+      ! fse3t_a will be undefined at the start of a run, but this routine
+      ! may be called at any stage! Hence we MUST make sure it is 
+      ! initialised to zero when allocated to enable us to test for 
+      ! zero content here and avoid potentially dangerous and non-portable 
+      ! operations (e.g. divide by zero, global sums of junk values etc.)   
+      zvol(:,:) = e1e2t(:,:) * fse3t_a(:,:,1) * tmask(:,:,1)
+      ztraf = glob_sum( dgtr(:,:) * zvol(:,:) )
+      !! areasf = glob_sum(e1e2t(:,:) * tmask(:,:,1) )
+      areasf = glob_sum(zvol(:,:))
+      zmin  = MINVAL( dgtr(:,:), mask= ((tmask(:,:,1).NE.0.)) )
+      zmax  = MAXVAL( dgtr(:,:), mask= ((tmask(:,:,1).NE.0.)) )
+      IF( lk_mpp ) THEN
+         CALL mpp_min( zmin )      ! min over the global domain
+         CALL mpp_max( zmax )      ! max over the global domain
+      END IF
+
+      text_zmean = "N/A"
+      ! Avoid divide by zero. areasf must be positive.
+      IF  (areasf > 0.0) THEN 
+         zmean = ztraf / areasf
+         WRITE(text_zmean,'(e18.10)') zmean
+      ENDIF
+
+      IF(lwp) WRITE(numout,9002) TRIM( names ), text_zmean, zmin, zmax
+
+  9002  FORMAT(' tracer name :',A,'    mean :',A,'    min :',e18.10, &
+      &      '    max :',e18.10 )
+      !
+   END SUBROUTINE trc_rst_dia_stat
+
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_rst_dia_stat                      ! Empty routines
+      WRITE(*,*) 'trc_rst_wri: You should not have seen this print! error?'
+   END SUBROUTINE trc_rst_dia_stat
+   SUBROUTINE trc_rst_dia_stat( dgtr, names)
+      REAL(wp), DIMENSION(jpi,jpj) , INTENT(in) ::   dgtr      ! 2D diag var
+      CHARACTER(len=*)             , INTENT(in) ::   names     ! 2D diag name
+      WRITE(*,*) 'trc_rst_wri: You should not have seen this print! error?'
+   END SUBROUTINE trc_rst_dia_stat  
+#endif
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!======================================================================
+END MODULE trcstat
Index: /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/trcstp.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/trcstp.F90	(revision 8466)
+++ /branches/NERC/dev_r5518_GO6_package_trdtrc/NEMOGCM/NEMO/TOP_SRC/trcstp.F90	(revision 8467)
@@ -19,4 +19,5 @@
    USE trcwri
    USE trcrst
+   USE trcstat
    USE trdtrc_oce
    USE trdmxl_trc
