Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/1_namelist
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/1_namelist	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/1_namelist	(revision 3318)
@@ -748,5 +748,5 @@
 !!======================================================================
 !!   namnc4       netcdf4 chunking and compression settings             ("key_netcdf4")
-!!   namtrd       dynamics and/or tracer trends                         ("key_trddyn","key_trdtra","key_trdmld")
+!!   namtrd       dynamics and/or tracer trends                         
 !!   namflo       float parameters                                      ("key_float")
 !!   namptr       Poleward Transport Diagnostics
@@ -769,4 +769,12 @@
 !              !       or mixed-layer trends or barotropic vorticity    ("key_trdmld" or     "key_trdvor")
 !-----------------------------------------------------------------------
+   ln_glo_trd  = .FALSE.   ! (T) global domain averaged diag for T, T^2, KE, and PE
+   ln_dyn_trd  = .FALSE.   ! (T) 3D momentum trend output
+   ln_dyn_mld  = .FALSE.   ! (T) 2D momentum trends averaged over the mixed layer 
+   ln_vor_trd  = .FALSE.   ! (T) 2D barotropic vorticity trends 
+   ln_KE_trd   = .FALSE.   ! (T) 3D Kinetic   Energy     trends
+   ln_PE_trd   = .FALSE.   ! (T) 3D Potential Energy     trends
+   ln_tra_trd  = .FALSE.   ! (T) 3D tracer trend output
+   ln_tra_mld  = .FALSE.   ! (T) 2D tracer trends averaged over the mixed layer 
    nn_trd      = 365       !  time step frequency dynamics and tracers trends
    nn_ctls     =   0       !  control surface type in mixed-layer trends (0,1 or n<jpk)
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/namelist
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/namelist	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/namelist	(revision 3318)
@@ -537,5 +537,5 @@
    ln_traldf_hor    =  .false.  !  horizontal (geopotential)   (needs "key_ldfslp" when ln_sco=T)
    ln_traldf_iso    =  .true.   !  iso-neutral                 (needs "key_ldfslp")
-   !		       	   !  Griffies parameters              (all need "key_ldfslp")
+   !		       	         !  Griffies parameters              (all need "key_ldfslp")
    ln_traldf_grif   =  .false.  !  use griffies triads
    ln_traldf_gdia   =  .false.  !  output griffies eddy velocities
@@ -793,5 +793,5 @@
 !!======================================================================
 !!   namnc4       netcdf4 chunking and compression settings             ("key_netcdf4")
-!!   namtrd       dynamics and/or tracer trends                         ("key_trddyn","key_trdtra","key_trdmld")
+!!   namtrd       dynamics and/or tracer trends                         
 !!   namflo       float parameters                                      ("key_float")
 !!   namptr       Poleward Transport Diagnostics
@@ -811,15 +811,15 @@
 /
 !-----------------------------------------------------------------------
-&namtrd        !   diagnostics on dynamics and/or tracer trends         ("key_trddyn" and/or "key_trdtra")
-!              !       or mixed-layer trends or barotropic vorticity    ("key_trdmld" or     "key_trdvor")
-!-----------------------------------------------------------------------
-   ln_3D_trd_d = .FALSE.   ! (T) 3D momentum             trends or (F) not
-   ln_3D_trd_t = .FALSE.   ! (T) 3D tracer               trends or (F) not
-   ln_ML_trd_d = .FALSE.   ! (T) 2D tracer   trends averaged over the mixed layer 
-   ln_ML_trd_t = .FALSE.   ! (T) 2D momentum trends averaged over the mixed layer 
-   ln_PE_trd   = .FALSE.   ! (T) 3D Potential Energy     trends or (F) not
-   ln_KE_trd   = .FALSE.   ! (T) 3D Kinetic   Energy     trends or (F) not
-   ln_vor_trd  = .FALSE.   ! (T) 3D barotropic vorticity trends or (F) not
+&namtrd        !   diagnostics on dynamics and/or tracer trends         
+!              !       or mixed-layer trends or barotropic vorticity    
+!-----------------------------------------------------------------------
    ln_glo_trd  = .FALSE.   ! (T) global domain averaged diag for T, T^2, KE, and PE
+   ln_dyn_trd  = .FALSE.   ! (T) 3D momentum trend output
+   ln_dyn_mld  = .FALSE.   ! (T) 2D momentum trends averaged over the mixed layer 
+   ln_vor_trd  = .FALSE.   ! (T) 2D barotropic vorticity trends 
+   ln_KE_trd   = .FALSE.   ! (T) 3D Kinetic   Energy     trends
+   ln_PE_trd   = .FALSE.   ! (T) 3D Potential Energy     trends
+   ln_tra_trd  = .FALSE.   ! (T) 3D tracer trend output
+   ln_tra_mld  = .FALSE.   ! (T) 2D tracer trends averaged over the mixed layer 
    nn_trd      = 365       !  print frequency (ln_glo_trd=T) (unit=time step)
    nn_ctls     =   0       !  control surface type in mixed-layer trends (0,1 or n<jpk)
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90	(revision 3318)
@@ -15,6 +15,6 @@
    USE oce            ! ocean dynamics and tracers
    USE dom_oce        ! ocean space and time domain
-   USE trdmod_oce     ! ocean variables trends
-   USE trdmod         ! ocean dynamics trends
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! MPP library
@@ -103,5 +103,5 @@
          zfu_uw(:,:,:) = ua(:,:,:) - zfu_uw(:,:,:)
          zfv_vw(:,:,:) = va(:,:,:) - zfv_vw(:,:,:)
-         CALL trd_mod( zfu_uw, zfv_vw, jpdyn_trd_keg, 'DYN', kt )
+         CALL trd_dyn( zfu_uw, zfv_vw, jpdyn_keg, kt )
          zfu_t(:,:,:) = ua(:,:,:)
          zfv_t(:,:,:) = va(:,:,:)
@@ -153,5 +153,5 @@
          zfu_t(:,:,:) = ua(:,:,:) - zfu_t(:,:,:)
          zfv_t(:,:,:) = va(:,:,:) - zfv_t(:,:,:)
-         CALL trd_mod( zfu_t, zfv_t, jpdyn_trd_zad, 'DYN', kt )
+         CALL trd_dyn( zfu_t, zfv_t, jpdyn_zad, kt )
       ENDIF
       !                                            ! Control print
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90	(revision 3318)
@@ -16,6 +16,6 @@
    USE oce            ! ocean dynamics and tracers
    USE dom_oce        ! ocean space and time domain
-   USE trdmod         ! ocean dynamics trends
-   USE trdmod_oce     ! ocean variables trends
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
    USE in_out_manager ! I/O manager
    USE prtctl         ! Print control
@@ -196,5 +196,5 @@
          zfu_uw(:,:,:) = ua(:,:,:) - zfu_uw(:,:,:)
          zfv_vw(:,:,:) = va(:,:,:) - zfv_vw(:,:,:)
-         CALL trd_mod( zfu_uw, zfv_vw, jpdyn_trd_keg, 'DYN', kt )
+         CALL trd_dyn( zfu_uw, zfv_vw, jpdyn_keg, kt )
          zfu_t(:,:,:) = ua(:,:,:)
          zfv_t(:,:,:) = va(:,:,:)
@@ -245,5 +245,5 @@
          zfu_t(:,:,:) = ua(:,:,:) - zfu_t(:,:,:)
          zfv_t(:,:,:) = va(:,:,:) - zfv_t(:,:,:)
-         CALL trd_mod( zfu_t, zfv_t, jpdyn_trd_zad, 'DYN', kt )
+         CALL trd_dyn( zfu_t, zfv_t, jpdyn_zad, kt )
       ENDIF
       !                                            ! Control print
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynbfr.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynbfr.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynbfr.F90	(revision 3318)
@@ -12,19 +12,19 @@
    !!   dyn_bfr      : Update the momentum trend with the bottom friction contribution
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables 
-   USE zdf_oce         ! ocean vertical physics variables
-   USE zdfbfr          ! ocean bottom friction variables
-   USE trdmod          ! ocean active dynamics and tracers trends 
-   USE trdmod_oce      ! ocean variables trends
-   USE in_out_manager  ! I/O manager
-   USE prtctl          ! Print control
-   USE timing          ! Timing
-   USE wrk_nemo        ! Memory Allocation
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables 
+   USE zdf_oce        ! ocean vertical physics variables
+   USE zdfbfr         ! ocean bottom friction variables
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
+   USE in_out_manager ! I/O manager
+   USE prtctl         ! Print control
+   USE timing         ! Timing
+   USE wrk_nemo       ! Memory Allocation
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   dyn_bfr    !  routine called by step.F90
+   PUBLIC   dyn_bfr   !  routine called by step.F90
 
    !! * Substitutions
@@ -92,5 +92,5 @@
            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-           CALL trd_mod( ztrdu(:,:,:), ztrdv(:,:,:), jpdyn_trd_bfr, 'DYN', kt )
+           CALL trd_dyn( ztrdu(:,:,:), ztrdv(:,:,:), jpdyn_bfr, kt )
            CALL wrk_dealloc( jpi,jpj,jpk, ztrdu, ztrdv )
         ENDIF
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 3318)
@@ -31,6 +31,6 @@
    USE dom_oce         ! ocean space and time domain
    USE phycst          ! physical constants
-   USE trdmod          ! ocean dynamics trends 
-   USE trdmod_oce      ! ocean variables trends
+   USE trd_oce         ! trends: ocean variables
+   USE trddyn          ! trend manager: dynamics
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
@@ -74,5 +74,5 @@
       !!   
       !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
-      !!             - Save the trend (l_trddyn=T)
+      !!             - send trends to trd_dyn for futher diagnostics (l_trddyn=T)
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
@@ -99,5 +99,5 @@
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_hpg, 'DYN', kt )
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_hpg, kt )
          CALL wrk_dealloc( jpi,jpj,jpk, ztrdu, ztrdv )
       ENDIF          
@@ -427,4 +427,5 @@
    END SUBROUTINE hpg_sco
 
+
    SUBROUTINE hpg_djc( kt )
       !!---------------------------------------------------------------------
@@ -664,6 +665,4 @@
       !!
       !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
-      !!             - Save the trend (l_trddyn=T)
-      !!
       !!----------------------------------------------------------------------
       INTEGER, PARAMETER  :: polynomial_type = 1    ! 1: cubic spline, 2: linear
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynkeg.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynkeg.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynkeg.F90	(revision 3318)
@@ -14,6 +14,6 @@
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
-   USE trdmod          ! ocean dynamics trends 
-   USE trdmod_oce      ! ocean variables trends
+   USE trd_oce         ! trends: ocean variables
+   USE trddyn          ! trend manager: dynamics
    USE in_out_manager  ! I/O manager
    USE lib_mpp         ! MPP library
@@ -52,5 +52,5 @@
       !!
       !! ** Action : - Update the (ua, va) with the hor. ke gradient trend
-      !!             - save this trends (l_trddyn=T) for post-processing
+      !!             - send this trends to trd_dyn (l_trddyn=T) for post-processing
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
@@ -131,5 +131,5 @@
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_keg, 'DYN', kt )
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_keg, kt )
          CALL wrk_dealloc( jpi,jpj,jpk, ztrdu, ztrdv )
       ENDIF
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf.F90	(revision 3318)
@@ -20,6 +20,6 @@
    USE dynldf_iso     ! lateral mixing            (dyn_ldf_iso    routine)
    USE dynldf_lap     ! lateral mixing            (dyn_ldf_lap    routine)
-   USE trdmod         ! ocean dynamics and tracer trends
-   USE trdmod_oce     ! ocean variables trends
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
    USE prtctl         ! Print control
    USE in_out_manager ! I/O manager
@@ -54,5 +54,4 @@
       !! ** Purpose :   compute the lateral ocean dynamics physics.
       !!----------------------------------------------------------------------
-      !
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !
@@ -106,5 +105,5 @@
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_ldf, 'DYN', kt )
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_ldf, kt )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv )
       ENDIF
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_bilap.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_bilap.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_bilap.F90	(revision 3318)
@@ -20,6 +20,4 @@
    USE ldfdyn_oce      ! ocean dynamics: lateral physics
    USE in_out_manager  ! I/O manager
-   USE trdmod          ! ocean dynamics trends 
-   USE trdmod_oce      ! ocean variables trends
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE wrk_nemo        ! Memory Allocation
@@ -70,6 +68,4 @@
       !!      Add this before trend to the general trend (ua,va):
       !!            (ua,va) = (ua,va) + (diffu,diffv)
-      !!      'key_trddyn' defined: the two components of the horizontal
-      !!                               diffusion trend are saved.
       !!
       !! ** Action : - Update (ua,va) with the before iso-level biharmonic
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_bilapg.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_bilapg.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_bilapg.F90	(revision 3318)
@@ -20,6 +20,4 @@
    USE ldfdyn_oce      ! ocean dynamics lateral physics
    USE zdf_oce         ! ocean vertical physics
-   USE trdmod          ! ocean dynamics trends 
-   USE trdmod_oce      ! ocean variables trends
    USE ldfslp          ! iso-neutral slopes available
    USE in_out_manager  ! I/O manager
@@ -81,9 +79,7 @@
       !!         -3- Add this trend to the general trend (ta,sa):
       !!            (ua,va) = (ua,va) + (zwk3,zwk4)
-      !!      'key_trddyn' defined: the trend is saved for diagnostics.
       !!
       !! ** Action  : - Update (ua,va) arrays with the before geopotential
       !!                biharmonic mixing trend.
-      !!              - save the trend in (zwk3,zwk4) ('key_trddyn')
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt           ! ocean time-step index
@@ -176,5 +172,4 @@
       !!                          pu and pv (all the components except
       !!                          second order vertical derivative term)
-      !!      'key_trddyn' defined: the trend is saved for diagnostics.
       !!----------------------------------------------------------------------
       !!
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_iso.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_iso.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_iso.F90	(revision 3318)
@@ -22,6 +22,4 @@
    USE ldftra_oce      ! ocean tracer   lateral physics
    USE zdf_oce         ! ocean vertical physics
-   USE trdmod          ! ocean dynamics trends 
-   USE trdmod_oce      ! ocean variables trends
    USE ldfslp          ! iso-neutral slopes 
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_lap.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_lap.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_lap.F90	(revision 3318)
@@ -19,8 +19,6 @@
    USE ldfdyn_oce      ! ocean dynamics: lateral physics
    USE zdf_oce         ! ocean vertical physics
+   USE ldfslp          ! iso-neutral slopes 
    USE in_out_manager  ! I/O manager
-   USE trdmod          ! ocean dynamics trends 
-   USE trdmod_oce      ! ocean variables trends
-   USE ldfslp          ! iso-neutral slopes 
    USE timing          ! Timing
 
@@ -57,6 +55,4 @@
       !!      Add this before trend to the general trend (ua,va):
       !!            (ua,va) = (ua,va) + (diffu,diffv)
-      !!      'key_trddyn' activated: the two components of the horizontal
-      !!                                 diffusion trend are saved.
       !!
       !! ** Action : - Update (ua,va) with the before iso-level harmonic 
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynnept.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynnept.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynnept.F90	(revision 3318)
@@ -5,13 +5,15 @@
    !!                 recoded version of simplest case (u*, v* only)
    !!======================================================================
-   !! History :  1.0  !  2007-06  (Michael Dunphy)  Modular form: - new namelist parameters
-   !!                                                             - horizontal diffusion for Neptune
-   !!                                                             - vertical diffusion for gm in momentum eqns
-   !!                                                             - option to use Neptune in Coriolis eqn
+   !! History :  1.0  !  2007-06  (Zeliang Wang, Michael Dunphy, BIO)  Original code
+   !!                             Modular form: - new namelist parameters
+   !!                                           - horizontal diffusion for Neptune
+   !!                                           - vertical diffusion for gm in momentum eqns
+   !!                                           - option to use Neptune in Coriolis eqn
    !!                    2011-08  (Jeff Blundell, NOCS) Simplified form for temporally invariant u*, v*
-   !!                                               Horizontal and vertical diffusivity formulations removed
-   !!                                               Dynamic allocation of storage added
-   !!                                               Option of ramping Neptune vel. down
-   !!                                               to zero added in shallow depths added
+   !!                             Horizontal and vertical diffusivity formulations removed
+   !!                             Dynamic allocation of storage added
+   !!                             Option of ramping Neptune vel. down to zero added in shallow depths added
+   !!----------------------------------------------------------------------
+
    !!----------------------------------------------------------------------
    !! dynnept_alloc        :
@@ -30,23 +32,17 @@
    USE phycst
    USE lbclnk
-   USE wrk_nemo        ! Memory Allocation
+   USE wrk_nemo         ! Memory Allocation
 
    IMPLICIT NONE
    PRIVATE
 
-   !! * Routine accessibility
-   PUBLIC dyn_nept_init      ! routine called by nemogcm.F90
-   PUBLIC dyn_nept_cor       ! routine called by step.F90
-   !! dynnept_alloc()         is called only by dyn_nept_init, within this module
-   !! dyn_nept_div_cur_init   is called only by dyn_nept_init, within this module
-   !! dyn_nept_vel            is called only by dyn_nept_cor,  within this module
-
-   !! * Shared module variables
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)    :: zunep, zvnep  ! Neptune u and v
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  :: zhdivnep      ! hor. div for Neptune vel.
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  :: zmrotnep      ! curl for Neptune vel.
-
-
-   !! * Namelist namdyn_nept variables
+   PUBLIC   dyn_nept_init   ! routine called by nemogcm.F90
+   PUBLIC   dyn_nept_cor    ! routine called by step.F90
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zunep, zvnep   ! Neptune u and v
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: zhdivnep       ! hor. div for Neptune vel.
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: zmrotnep       ! curl for Neptune vel.
+
+   !                                                 !!* Namelist namdyn_nept variables
    LOGICAL, PUBLIC  ::  ln_neptsimp        = .FALSE.  ! yes/no simplified neptune
 
@@ -60,14 +56,12 @@
    REAL(wp)         ::  rn_htrmax          =  200.0   ! max. depth of transition range
 
-   !! * Module variables
-
-
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
 #  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
-   !!   OPA 9.0 , implemented by Bedford Institute of Oceanography
-   !!----------------------------------------------------------------------
-
+   !! NEMO/OPA 3.3 , NEMO Consortium (2011)
+   !! $Id: dynadv_cen2.F90 3316 2012-02-21 16:00:02Z gm $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
  CONTAINS
 
@@ -90,16 +84,10 @@
       !!                and compute the arrays zunep and zvnep
       !!
-      !! ** Method  :   zunep =
-      !!                zvnep =
-      !!
-      !! ** History :  1.0  !   07-05  (Zeliang Wang)   Original code for zunep, zvnep
-      !!               1.1  !   07-06  (Michael Dunphy) namelist and  initialisation
-      !!               2.0  ! 2011-07  (Jeff Blundell, NOCS)
-      !!                    ! Simplified form for temporally invariant u*, v*
-      !!                    ! Horizontal and vertical diffusivity formulations removed
-      !!                    ! Includes optional tapering-off in shallow depths
+      !! ** Method  :   Simplified form for temporally invariant u*, v*
+      !!                Horizontal and vertical diffusivity formulations removed
+      !!                Includes optional tapering-off in shallow depths
       !!----------------------------------------------------------------------
       USE iom
-      !!
+      !
       INTEGER  ::   ji, jj, jk    ! dummy loop indices
       REAL(wp) :: unemin,unemax,vnemin,vnemax   ! extrema of (u*, v*) fields
@@ -122,10 +110,6 @@
       ! ==========================================
 
-!!    WRITE(numout,*) ' start dynnept namelist'
-!!    CALL FLUSH(numout)
       REWIND( numnam )                  ! Read Namelist namdyn_nept:  Simplified Neptune
       READ  ( numnam, namdyn_nept )
-!!    WRITE(numout,*) ' dynnept namelist done'
-!!    CALL FLUSH(numout)
 
       IF(lwp) THEN                      ! Control print
@@ -172,6 +156,6 @@
 
       IF( .not. ln_rstart ) THEN      ! If restarting, these arrays are read from the restart file
-         zhdivnep(:,:,:) = 0.0_wp
-         zmrotnep(:,:,:) = 0.0_wp
+         zhdivnep(:,:,:) = 0._wp
+         zmrotnep(:,:,:) = 0._wp
       END IF
 
@@ -361,19 +345,4 @@
       !! ** Action  : - compute zhdivnep, the hor. divergence of (u*, v*)
       !!              - compute zmrotnep, the rel. vorticity  of (u*, v*)
-      !!
-      !! History :  OPA  ! 1987-06  (P. Andrich, D. L Hostis)  Original code
-      !!            4.0  ! 1991-11  (G. Madec)
-      !!            6.0  ! 1993-03  (M. Guyon)  symetrical conditions
-      !!            7.0  ! 1996-01  (G. Madec)  s-coordinates
-      !!            8.0  ! 1997-06  (G. Madec)  lateral boundary cond., lbc
-      !!            8.1  ! 1997-08  (J.M. Molines)  Open boundaries
-      !!            8.2  ! 2000-03  (G. Madec)  no slip accurate
-      !!  NEMO      1.0  ! 2002-09  (G. Madec, E. Durand)  Free form, F90
-      !!             -   ! 2005-01  (J. Chanut) Unstructured open boundaries
-      !!             -   ! 2003-08  (G. Madec)  merged of cur and div, free form, F90
-      !!             -   ! 2005-01  (J. Chanut, A. Sellar) unstructured open boundaries
-      !!            3.3  ! 2010-09  (D.Storkey and E.O'Dea) bug fixes for BDY module
-      !!                 ! 2011-06  (Jeff Blundell, NOCS) Adapt code from divcur.F90
-      !!                 !           to compute Neptune effect fields only
       !!----------------------------------------------------------------------
       !
@@ -517,5 +486,4 @@
 
    SUBROUTINE dyn_nept_smooth_vel( htold, htnew, ld_option )
-
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE dyn_nept_smooth_vel  ***
@@ -607,3 +575,4 @@
    END SUBROUTINE dyn_nept_smooth_vel
 
+   !!==============================================================================
 END MODULE dynnept
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 3318)
@@ -26,11 +26,10 @@
    USE dom_oce         ! ocean space and time domain
    USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE trdmod_oce      ! ocean trends
    USE phycst          ! physical constants
    USE dynspg_oce      ! type of surface pressure gradient
    USE dynadv          ! dynamics: vector invariant versus flux form
    USE domvvl          ! variable volume
-   USE trdmod         ! ocean dynamics trends 
-   USE trdmod_oce     ! ocean variables trends
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
    USE obc_oce         ! ocean open boundary conditions
    USE obcdyn          ! open boundary condition for momentum (obc_dyn routine)
@@ -192,13 +191,15 @@
 #endif
 
-      IF( ln_3D_trd_d ) THEN             ! 3D output: total momentum trends a prepare the atf trend computation
-         z1_2dt = 1._wp / (2. * rdt)            ! Euler or leap-frog time step 
-         IF( neuler == 0 .AND. kt == nit000 )  z1_2dt = 1._wp / rdt
-         zua(:,:,:) = ( ua(:,:,:) - ub(:,:,:) ) * z1_2dt
-         zva(:,:,:) = ( va(:,:,:) - vb(:,:,:) ) * z1_2dt
-         CALL iom_put( "utrd_tot", zua )        ! total momentum trends (but the asselin time filter)
-         CALL iom_put( "vtrd_tot", zva )
-         zua(:,:,:) = un(:,:,:)                 ! save the before velocity before the asselin filter
-         zva(:,:,:) = vn(:,:,:)                 ! (caution: there is a shift by 1 timestep in the
+       IF( l_trddyn ) THEN             ! prepare the atf trend computation
+         IF( ln_dyn_trd ) THEN                 ! 3D output: total momentum trends
+            z1_2dt = 1._wp / (2. * rdt)            ! Euler or leap-frog time step 
+            IF( neuler == 0 .AND. kt == nit000 )  z1_2dt = 1._wp / rdt
+            zua(:,:,:) = ( ua(:,:,:) - ub(:,:,:) ) * z1_2dt
+            zva(:,:,:) = ( va(:,:,:) - vb(:,:,:) ) * z1_2dt
+            CALL iom_put( "utrd_tot", zua )        ! total momentum trends (but the asselin time filter)
+            CALL iom_put( "vtrd_tot", zva )
+         ENDIF
+         zua(:,:,:) = un(:,:,:)                 ! save the now velocity before the asselin filter
+         zva(:,:,:) = vn(:,:,:)                 ! (caution: there will be a shift by 1 timestep in the
          !                                      !  computation of the asselin filter trends)
       ENDIF
@@ -293,8 +294,8 @@
       ENDIF
 
-      IF( ln_3D_trd_d ) THEN             ! 3D output: asselin filter trends on momentum
+      IF( l_trddyn ) THEN                ! 3D output: asselin filter trends on momentum
          zua(:,:,:) = ( ub(:,:,:) - zua(:,:,:) ) * z1_2dt
          zva(:,:,:) = ( vb(:,:,:) - zva(:,:,:) ) * z1_2dt
-         CALL trd_mod( zua, zva, jpdyn_trd_atf, 'DYN', kt )
+         CALL trd_dyn( zua, zva, jpdyn_atf, kt )
       ENDIF
 
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 3318)
@@ -22,12 +22,12 @@
    USE dynspg_flt     ! surface pressure gradient     (dyn_spg_flt routine)
    USE dynadv         ! dynamics: vector invariant versus flux form
-   USE trdmod         ! ocean dynamics trends
-   USE trdmod_oce     ! ocean variables trends
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
    USE prtctl         ! Print control                     (prt_ctl routine)
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! MPP library
-   USE solver          ! solver initialization
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   USE solver         ! solver initialization
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
 
@@ -145,9 +145,9 @@
          CASE( 2 )
             z2dt = 2. * rdt
-            IF( neuler == 0 .AND. kt == nit000 ) z2dt = rdt
+            IF( neuler == 0 .AND. kt == nit000 )   z2dt = rdt
             ztrdu(:,:,:) = ( ua(:,:,:) - ub(:,:,:) ) / z2dt - ztrdu(:,:,:)
             ztrdv(:,:,:) = ( va(:,:,:) - vb(:,:,:) ) / z2dt - ztrdv(:,:,:)
          END SELECT
-         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_spg, 'DYN', kt )
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_spg, kt )
          !
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 3318)
@@ -15,5 +15,5 @@
    !!            3.2  ! 2009-04  (R. Benshila)  vvl: correction of een scheme
    !!            3.3  ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
-	!!            3.5  ! 2012-02  (G. Madec) suppress jpdyn_trd_dat vorticity trend simplification
+	!!            3.5  ! 2012-02  (G. Madec) trend simplification: suppress jpdyn_trd_dat vorticity 
    !!----------------------------------------------------------------------
 
@@ -30,6 +30,6 @@
    USE dommsk         ! ocean mask
    USE dynadv         ! momentum advection (use ln_dynadv_vec value)
-   USE trdmod         ! ocean dynamics trends 
-   USE trdmod_oce     ! ocean variables trends
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
    USE prtctl         ! Print control
@@ -74,5 +74,5 @@
       !! ** Action : - Update (ua,va) with the now vorticity term trend
       !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
-      !!               and planetary vorticity trends) ('key_trddyn')
+      !!               and planetary vorticity trends) (l_trddyn=T)
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
@@ -109,5 +109,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_rvo, kt )
             ztrdu(:,:,:) = ua(:,:,:)
             ztrdv(:,:,:) = va(:,:,:)
@@ -115,5 +115,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_pvo, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_pvo, kt )
          ELSE
             CALL vor_ene( kt, ntot, ua, va )                ! total vorticity
@@ -127,5 +127,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_rvo, kt )
             ztrdu(:,:,:) = ua(:,:,:)
             ztrdv(:,:,:) = va(:,:,:)
@@ -133,5 +133,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_pvo, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_pvo, kt )
          ELSE
             CALL vor_ens( kt, ntot, ua, va )                ! total vorticity
@@ -145,5 +145,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_rvo, kt )
             ztrdu(:,:,:) = ua(:,:,:)
             ztrdv(:,:,:) = va(:,:,:)
@@ -151,5 +151,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_pvo, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_pvo, kt )
          ELSE
             CALL vor_mix( kt )                               ! total vorticity (mix=ens-ene)
@@ -163,5 +163,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_rvo, kt )
             ztrdu(:,:,:) = ua(:,:,:)
             ztrdv(:,:,:) = va(:,:,:)
@@ -169,5 +169,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_pvo, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_pvo, kt )
          ELSE
             CALL vor_een( kt, ntot, ua, va )                ! total vorticity
@@ -208,6 +208,4 @@
       !!
       !! ** Action : - Update (ua,va) with the now vorticity term trend
-      !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
-      !!               and planetary vorticity trends) ('key_trddyn')
       !!
       !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
@@ -325,6 +323,4 @@
       !!
       !! ** Action : - Update (ua,va) arrays with the now vorticity term trend
-      !!             - Save the trends in (ztrdu,ztrdv) in 2 parts (relative
-      !!               and planetary vorticity trends) ('key_trddyn')
       !!
       !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
@@ -441,6 +437,4 @@
       !!
       !! ** Action : - Update (ua,va) arrays with the now vorticity term trend
-      !!             - Save the trends in (ztrdu,ztrdv) in 2 parts (relative 
-      !!               and planetary vorticity trends) ('key_trddyn')
       !!
       !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
@@ -554,6 +548,4 @@
       !!
       !! ** Action : - Update (ua,va) with the now vorticity term trend
-      !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
-      !!               and planetary vorticity trends) ('key_trddyn')
       !!
       !! References : Arakawa and Lamb 1980, Mon. Wea. Rev., 109, 18-36
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynzad.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynzad.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynzad.F90	(revision 3318)
@@ -16,11 +16,11 @@
    USE dom_oce        ! ocean space and time domain
    USE sbc_oce        ! surface boundary condition: ocean
-   USE trdmod_oce     ! ocean variables trends
-   USE trdmod         ! ocean dynamics trends 
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
    USE in_out_manager ! I/O manager
-   USE lib_mpp         ! MPP library
+   USE lib_mpp        ! MPP library
    USE prtctl         ! Print control
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -53,5 +53,5 @@
       !!
       !! ** Action  : - Update (ua,va) with the vert. momentum adv. trends
-      !!              - Save the trends in (ztrdu,ztrdv) ('key_trddyn')
+      !!              - Send the trends to trddyn for diagnostics (l_trddyn=T)
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step inedx
@@ -118,5 +118,5 @@
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_mod(ztrdu, ztrdv, jpdyn_trd_zad, 'DYN', kt)
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_zad, kt )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
       ENDIF
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf.F90	(revision 3318)
@@ -20,6 +20,6 @@
 
    USE ldfdyn_oce      ! ocean dynamics: lateral physics
-   USE trdmod          ! ocean active dynamics and tracers trends 
-   USE trdmod_oce      ! ocean variables trends
+   USE trd_oce         ! trends: ocean variables
+   USE trddyn          ! trend manager: dynamics
    USE in_out_manager  ! I/O manager
    USE lib_mpp         ! MPP library
@@ -91,5 +91,5 @@
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_zdf, 'DYN', kt )
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_zdf, kt )
          !
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 3318)
@@ -18,4 +18,5 @@
    USE oce             ! ocean dynamics and tracers 
    USE dom_oce         ! ocean space and time domain
+   USE trd_oce         ! ocean trend diagnostics
    USE phycst          ! physical constants
    USE in_out_manager  ! I/O manager
@@ -136,5 +137,5 @@
       IF( kt == nitrst ) THEN
          CALL iom_close( numrow )     ! close the restart file (only at last time step)
-         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
+         IF( .NOT. ln_tra_mld )   lrst_oce = .FALSE.
       ENDIF
       !
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_cen2.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_cen2.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_cen2.F90	(revision 3318)
@@ -4,7 +4,7 @@
    !! Ocean  tracers:  horizontal & vertical advective trend
    !!======================================================================
-   !! History :  8.2  ! 2001-08  (G. Madec, E. Durand)  trahad+trazad=traadv 
-   !!            1.0  ! 2002-06  (G. Madec)  F90: Free form and module
-   !!            9.0  ! 2004-08  (C. Talandier) New trends organization
+   !! History :  OPA  ! 2001-08  (G. Madec, E. Durand) v8.2 trahad+trazad=traadv 
+   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
+   !!             -   ! 2004-08  (C. Talandier) New trends organization
    !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
    !!            2.0  ! 2006-04  (R. Benshila, G. Madec) Step reorganization
@@ -21,6 +21,6 @@
    USE dom_oce         ! ocean space and time domain
    USE eosbn2          ! equation of state
-   USE trdmod_oce      ! tracers trends
-   USE trdtra          ! tracers trends
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
    USE closea          ! closed sea
    USE sbcrnf          ! river runoffs
@@ -38,6 +38,6 @@
    PRIVATE
 
-   PUBLIC   tra_adv_cen2       ! routine called by step.F90
-   PUBLIC   ups_orca_set       ! routine used by traadv_cen2_jki.F90
+   PUBLIC   tra_adv_cen2   ! routine called by step.F90
+   PUBLIC   ups_orca_set   ! routine used by traadv_cen2_jki.F90
 
    LOGICAL  :: l_trd       ! flag to compute trends
@@ -56,5 +56,5 @@
 
    SUBROUTINE tra_adv_cen2( kt, kit000, cdtype, pun, pvn, pwn,     &
-      &                                 ptb, ptn, pta, kjpt   ) 
+      &                                         ptb, ptn, pta, kjpt   ) 
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE tra_adv_cen2  ***
@@ -86,8 +86,7 @@
       !!       * Add this trend now to the general trend of tracer (ta,sa):
       !!               pta = pta + ztra
-      !!       * trend diagnostic ('key_trdtra' defined): the trend is
+      !!       * trend diagnostic (l_trdtra=T or l_trctra=T): the trend is
       !!      saved for diagnostics. The trends saved is expressed as
-      !!      Uh.gradh(T), i.e.
-      !!                     save trend = ztra + ptn divn
+      !!      Uh.gradh(T), i.e.  save trend = ztra + ptn divn
       !!
       !!         Part II : vertical advection
@@ -105,5 +104,5 @@
       !!         Add this trend now to the general trend of tracer (ta,sa):
       !!             pta = pta + ztra
-      !!         Trend diagnostic ('key_trdtra' defined): the trend is
+      !!         Trend diagnostic (l_trdtra=T or l_trctra=T): the trend is
       !!      saved for diagnostics. The trends saved is expressed as :
       !!             save trend =  w.gradz(T) = ztra - ptn divn.
@@ -261,9 +260,9 @@
          END DO
 
-         !                                 ! trend diagnostics (contribution of upstream fluxes)
+         !                                 ! trend diagnostics
          IF( l_trd ) THEN
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_xad, zwx, pun, ptn(:,:,:,jn) )
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_yad, zwy, pvn, ptn(:,:,:,jn) )
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_zad, zwz, pwn, ptn(:,:,:,jn) )
+            CALL trd_tra( kt, cdtype, jn, jptra_xad, zwx, pun, ptn(:,:,:,jn) )
+            CALL trd_tra( kt, cdtype, jn, jptra_yad, zwy, pvn, ptn(:,:,:,jn) )
+            CALL trd_tra( kt, cdtype, jn, jptra_zad, zwz, pwn, ptn(:,:,:,jn) )
          END IF
          !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
@@ -273,5 +272,5 @@
          ENDIF
          !
-      ENDDO
+      END DO
 
       ! ---------------------------  required in restart file to ensure restartability)
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_muscl.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_muscl.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_muscl.F90	(revision 3318)
@@ -16,9 +16,8 @@
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
-   USE trdmod_oce      ! tracers trends 
-   USE trdtra      ! tracers trends 
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
    USE in_out_manager  ! I/O manager
    USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
-   USE trabbl          ! tracers: bottom boundary layer
    USE lib_mpp         ! distribued memory computing
    USE lbclnk          ! ocean lateral boundary condition (or mpp link) 
@@ -179,6 +178,6 @@
          !                                 ! trend diagnostics (contribution of upstream fluxes)
          IF( l_trd )  THEN
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_xad, zwx, pun, ptb(:,:,:,jn) )
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_yad, zwy, pvn, ptb(:,:,:,jn) )
+            CALL trd_tra( kt, cdtype, jn, jptra_xad, zwx, pun, ptb(:,:,:,jn) )
+            CALL trd_tra( kt, cdtype, jn, jptra_yad, zwy, pvn, ptb(:,:,:,jn) )
          END IF
          !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
@@ -250,5 +249,5 @@
          END DO
          !                                 ! Save the vertical advective trends for diagnostic
-         IF( l_trd ) CALL trd_tra( kt, cdtype, jn, jptra_trd_zad, zwx, pwn, ptb(:,:,:,jn) )
+         IF( l_trd ) CALL trd_tra( kt, cdtype, jn, jptra_zad, zwx, pwn, ptb(:,:,:,jn) )
          !
       ENDDO
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_muscl2.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_muscl2.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_muscl2.F90	(revision 3318)
@@ -14,9 +14,8 @@
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
-   USE trdmod_oce      ! tracers trends 
-   USE trdtra          ! tracers trends 
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
    USE in_out_manager  ! I/O manager
    USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
-   USE trabbl          ! tracers: bottom boundary layer
    USE lib_mpp         ! distribued memory computing
    USE lbclnk          ! ocean lateral boundary condition (or mpp link) 
@@ -201,6 +200,6 @@
          !                                 ! trend diagnostics (contribution of upstream fluxes)
          IF( l_trd ) THEN
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_xad, zwx, pun, ptb(:,:,:,jn) )
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_yad, zwy, pvn, ptb(:,:,:,jn) )
+            CALL trd_tra( kt, cdtype, jn, jptra_xad, zwx, pun, ptb(:,:,:,jn) )
+            CALL trd_tra( kt, cdtype, jn, jptra_yad, zwy, pvn, ptb(:,:,:,jn) )
          END IF
 
@@ -284,5 +283,5 @@
          END DO
          !                       ! trend diagnostics (contribution of upstream fluxes)
-         IF( l_trd )  CALL trd_tra( kt, cdtype, jn, jptra_trd_zad, zwx, pwn, ptb(:,:,:,jn) )
+         IF( l_trd )  CALL trd_tra( kt, cdtype, jn, jptra_zad, zwx, pwn, ptb(:,:,:,jn) )
          !
       END DO
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_qck.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_qck.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_qck.F90	(revision 3318)
@@ -17,7 +17,6 @@
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
-   USE trdmod_oce      ! ocean space and time domain
-   USE trdtra          ! ocean tracers trends 
-   USE trabbl          ! advective term in the BBL
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
    USE lib_mpp         ! distribued memory computing
    USE lbclnk          ! ocean lateral boundary condition (or mpp link)
@@ -232,5 +231,5 @@
          END DO
          !                                 ! trend diagnostics (contribution of upstream fluxes)
-         IF( l_trd )  CALL trd_tra( kt, cdtype, jn, jptra_trd_xad, zwx, pun, ptn(:,:,:,jn) )
+         IF( l_trd )  CALL trd_tra( kt, cdtype, jn, jptra_xad, zwx, pun, ptn(:,:,:,jn) )
          !
       END DO
@@ -358,5 +357,5 @@
          END DO
          !                                 ! trend diagnostics (contribution of upstream fluxes)
-         IF( l_trd )  CALL trd_tra( kt, cdtype, jn, jptra_trd_yad, zwy, pvn, ptn(:,:,:,jn) )
+         IF( l_trd )  CALL trd_tra( kt, cdtype, jn, jptra_yad, zwy, pvn, ptn(:,:,:,jn) )
          !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
          IF( cdtype == 'TRA' .AND. ln_diaptr .AND. ( MOD( kt, nn_fptr ) == 0 ) ) THEN  
@@ -421,5 +420,5 @@
          END DO
          !                                 ! Save the vertical advective trends for diagnostic
-         IF( l_trd )  CALL trd_tra( kt, cdtype, jn, jptra_trd_zad, zwz, pwn, ptn(:,:,:,jn) )
+         IF( l_trd )  CALL trd_tra( kt, cdtype, jn, jptra_zad, zwz, pwn, ptn(:,:,:,jn) )
          !
       END DO
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_tvd.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_tvd.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_tvd.F90	(revision 3318)
@@ -24,6 +24,6 @@
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
-   USE trdmod_oce      ! tracers trends
-   USE trdtra          ! tracers trends
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
    USE in_out_manager  ! I/O manager
    USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
@@ -229,7 +229,7 @@
             ztrdz(:,:,:) = ztrdz(:,:,:) + zwz(:,:,:)  ! <<< Add to previously computed
             
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_xad, ztrdx, pun, ptn(:,:,:,jn) )   
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_yad, ztrdy, pvn, ptn(:,:,:,jn) )  
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_zad, ztrdz, pwn, ptn(:,:,:,jn) ) 
+            CALL trd_tra( kt, cdtype, jn, jptra_xad, ztrdx, pun, ptn(:,:,:,jn) )   
+            CALL trd_tra( kt, cdtype, jn, jptra_yad, ztrdy, pvn, ptn(:,:,:,jn) )  
+            CALL trd_tra( kt, cdtype, jn, jptra_zad, ztrdz, pwn, ptn(:,:,:,jn) ) 
          END IF
          !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_ubs.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_ubs.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_ubs.F90	(revision 3318)
@@ -14,12 +14,12 @@
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
-   USE trdmod_oce         ! ocean space and time domain
-   USE trdtra
-   USE lib_mpp
+   USE trc_oce         ! share passive tracers/Ocean variables
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
+   USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! I/O library
    USE lbclnk          ! ocean lateral boundary condition (or mpp link)
-   USE in_out_manager  ! I/O manager
    USE diaptr          ! poleward transport diagnostics
-   USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
-   USE trc_oce         ! share passive tracers/Ocean variables
    USE wrk_nemo        ! Memory Allocation
    USE timing          ! Timing
@@ -181,6 +181,6 @@
          !                                 ! trend diagnostics (contribution of upstream fluxes)
          IF( l_trd ) THEN
-             CALL trd_tra( kt, cdtype, jn, jptra_trd_xad, zwx, pun, ptn(:,:,:,jn) )
-             CALL trd_tra( kt, cdtype, jn, jptra_trd_yad, zwy, pvn, ptn(:,:,:,jn) )
+             CALL trd_tra( kt, cdtype, jn, jptra_xad, zwx, pun, ptn(:,:,:,jn) )
+             CALL trd_tra( kt, cdtype, jn, jptra_yad, zwy, pvn, ptn(:,:,:,jn) )
          END IF
          !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
@@ -264,5 +264,5 @@
                END DO
             END DO
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_zad, zltv )
+            CALL trd_tra( kt, cdtype, jn, jptra_zad, zltv )
          ENDIF
          !
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 3318)
@@ -18,6 +18,6 @@
    USE dom_oce         ! domain: ocean
    USE phycst          ! physical constants
-   USE trdmod_oce      ! trends: ocean variables 
-   USE trdtra          ! trends: active tracers 
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
@@ -99,5 +99,5 @@
       IF( l_trdtra ) THEN        ! Save the geothermal heat flux trend for diagnostics
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_bbc, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_bbc, ztrdt )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt )
       ENDIF
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 3318)
@@ -28,6 +28,6 @@
    USE phycst         ! physical constant
    USE eosbn2         ! equation of state
-   USE trdmod_oce     ! trends: ocean variables
-   USE trdtra         ! trends: active tracers
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! trends manager: tracers 
    USE iom            ! IOM server               
    USE in_out_manager ! I/O manager
@@ -148,6 +148,6 @@
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
          ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_bbl, ztrdt )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_bbl, ztrds )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_bbl, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_bbl, ztrds )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds ) 
       ENDIF
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 3318)
@@ -27,6 +27,6 @@
    USE oce            ! ocean: variables
    USE dom_oce        ! ocean: domain variables
-   USE trdmod_oce     ! ocean: trend variables
-   USE trdtra         ! active tracers: trends
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
    USE zdf_oce        ! ocean: vertical physics
    USE phycst         ! physical constants
@@ -172,6 +172,6 @@
       !
       IF( l_trdtra )   THEN       ! trend diagnostic
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_dmp, ttrdmp )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_dmp, strdmp )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_dmp, ttrdmp )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_dmp, strdmp )
       ENDIF
       !                           ! Control print
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traldf.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traldf.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traldf.F90	(revision 3318)
@@ -23,6 +23,6 @@
    USE traldf_iso_grif ! lateral mixing          (tra_ldf_iso_grif routine)
    USE traldf_lap      ! lateral mixing               (tra_ldf_lap routine)
-   USE trdmod_oce      ! ocean space and time domain
-   USE trdtra          ! ocean active tracers trends
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
    USE prtctl          ! Print control
    USE in_out_manager  ! I/O manager
@@ -112,6 +112,6 @@
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
          ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_ldf, ztrdt )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_ldf, ztrds )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_ldf, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_ldf, ztrds )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds ) 
       ENDIF
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/tranpc.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/tranpc.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/tranpc.F90	(revision 3318)
@@ -17,6 +17,6 @@
    USE dom_oce         ! ocean space and time domain
    USE zdf_oce         ! ocean vertical physics
-   USE trdmod_oce      ! ocean active tracer trends
-   USE trdtra          ! ocean active tracer trends
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
    USE eosbn2          ! equation of state (eos routine) 
    USE lbclnk          ! lateral boundary conditions (or mpp link)
@@ -51,8 +51,7 @@
       !!      iterations. instabilities are treated when the vertical density
       !!      gradient is less than 1.e-5.
-      !!      l_trdtra=T: the trend associated with this algorithm is saved.
       !!
       !! ** Action  : - (ta,sa) after the application od the npc scheme
-      !!              - save the associated trends (ttrd,strd) ('key_trdtra')
+      !!              - save the associated trends (l_trdtra=T)
       !!
       !! References : Madec, et al., 1991, JPO, 21, 9, 1349-1371.
@@ -196,19 +195,17 @@
          !                                                ! ===============
          ! 
+      
+         ! Lateral boundary conditions on ( ta, sa )   ( Unchanged sign)
+         CALL lbc_lnk( tsa(:,:,:,jp_tem), 'T', 1. )   ;   CALL lbc_lnk( tsa(:,:,:,jp_sal), 'T', 1. )
+
          IF( l_trdtra )   THEN         ! save the Non penetrative mixing trends for diagnostic
             ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
             ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
-            CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_npc, ztrdt )
-            CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_npc, ztrds )
+            CALL trd_tra( kt, 'TRA', jp_tem, jptra_npc, ztrdt )
+            CALL trd_tra( kt, 'TRA', jp_sal, jptra_npc, ztrds )
             CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
          ENDIF
       
-         ! Lateral boundary conditions on ( ta, sa )   ( Unchanged sign)
-         ! ------------------------------============
-         CALL lbc_lnk( tsa(:,:,:,jp_tem), 'T', 1. )   ;   CALL lbc_lnk( tsa(:,:,:,jp_sal), 'T', 1. )
-      
-
-         !  2. non penetrative convective scheme statistics
-         !  -----------------------------------------------
+         ! non penetrative convective scheme statistics
          IF( nn_npcp /= 0 .AND. MOD( kt, nn_npcp ) == 0 ) THEN
             IF(lwp) WRITE(numout,*)' kt=',kt, ' number of statically instable',   &
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 3318)
@@ -29,11 +29,12 @@
    USE zdf_oce         ! ???
    USE domvvl          ! variable volume
+   USE phycst          ! physical constant
    USE ldftra_oce      ! ocean active tracers lateral physics
    USE dynspg_oce      ! surface     pressure gradient variables
    USE dynhpg          ! hydrostatic pressure gradient 
-   USE trdmod_oce      ! ocean space and time domain variables 
-   USE trdtra          ! ocean active tracers trends 
-   USE phycst
-   USE obc_oce
+   USE traqsr          ! penetrative solar radiation (needed for nksr)
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
+   USE obc_oce         ! open boundary condition variable
    USE obctra          ! open boundary condition (obc_tra routine)
    USE bdy_oce
@@ -42,5 +43,4 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE prtctl          ! Print control
-   USE traqsr          ! penetrative solar radiation (needed for nksr)
 #if defined key_agrif
    USE agrif_opa_update
@@ -134,6 +134,6 @@
          ztrds(:,:,:) = tsn(:,:,:,jp_sal)
          IF( ln_traldf_iso ) THEN              ! diagnose the "pure" Kz diffusive trend 
-            CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_zdfp, ztrdt )
-            CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_zdfp, ztrds )
+            CALL trd_tra( kt, 'TRA', jp_tem, jptra_zdfp, ztrdt )
+            CALL trd_tra( kt, 'TRA', jp_sal, jptra_zdfp, ztrds )
          ENDIF
       ENDIF
@@ -164,6 +164,6 @@
             ztrds(:,:,jk) = ( tsb(:,:,jk,jp_sal) - ztrds(:,:,jk) ) * zfact
          END DO
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_atf, ztrdt )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_atf, ztrds )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_atf, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_atf, ztrds )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
       END IF
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 3318)
@@ -20,8 +20,8 @@
    USE sbc_oce         ! surface boundary condition: ocean
    USE trc_oce         ! share SMS/Ocean variables
-   USE trdmod_oce      ! ocean variables trends
-   USE trdtra          ! ocean active tracers trends 
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
+   USE phycst          ! physical constants
    USE in_out_manager  ! I/O manager
-   USE phycst          ! physical constants
    USE prtctl          ! Print control
    USE iom             ! I/O manager
@@ -31,5 +31,4 @@
    USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
-
 
    IMPLICIT NONE
@@ -88,5 +87,5 @@
       !!
       !! ** Action  : - update ta with the penetrative solar radiation trend
-      !!              - save the trend in ttrd ('key_trdtra')
+      !!              - send the trend to trdtra (l_trdtra=T)
       !!
       !! Reference  : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
@@ -284,5 +283,5 @@
       IF( l_trdtra ) THEN     ! qsr tracers trends saved for diagnostics
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_qsr, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_qsr, ztrdt )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt ) 
       ENDIF
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 3318)
@@ -18,13 +18,13 @@
    USE dom_oce         ! ocean space domain variables
    USE phycst          ! physical constant
+   USE sbcrnf          ! River runoff  
+   USE sbcmod          ! ln_rnf  
    USE traqsr          ! solar radiation penetration
-   USE trdmod_oce      ! ocean trends 
-   USE trdtra          ! ocean trends
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
    USE restart         ! ocean restart
-   USE sbcrnf          ! River runoff  
-   USE sbcmod          ! ln_rnf  
-   USE iom
+   USE iom             ! I/O library
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE wrk_nemo        ! Memory Allocation
@@ -228,9 +228,9 @@
 !!gm : end of useless
 
-      IF( l_trdtra )   THEN                      ! save the horizontal diffusive trends for further diagnostics
+      IF( l_trdtra )   THEN                      ! save the trends for further diagnostics
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
          ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_nsr, ztrdt )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_nsr, ztrds )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_nsr, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_nsr, ztrds )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds ) 
       ENDIF
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90	(revision 3318)
@@ -22,8 +22,7 @@
    USE trazdf_exp      ! vertical diffusion: explicit (tra_zdf_exp     routine)
    USE trazdf_imp      ! vertical diffusion: implicit (tra_zdf_imp     routine)
-
    USE ldftra_oce      ! ocean active tracers: lateral physics
-   USE trdmod_oce      ! ocean active tracers: lateral physics
-   USE trdtra      ! ocean tracers trends 
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
@@ -96,6 +95,6 @@
             ztrds(:,:,jk) = ( ( tsa(:,:,jk,jp_sal) - tsb(:,:,jk,jp_sal) ) / r2dtra(jk) ) - ztrds(:,:,jk)
          END DO
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_zdf, ztrdt )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_zdf, ztrds )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_zdf, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_zdf, ztrds )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
       ENDIF
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trd_oce.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trd_oce.F90	(revision 3318)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trd_oce.F90	(revision 3318)
@@ -0,0 +1,84 @@
+MODULE trd_oce
+   !!======================================================================
+   !!                   ***  MODULE trd_oce  ***
+   !! Ocean trends :   set tracer and momentum trend variables
+   !!======================================================================
+   !! History :  1.0  !  2004-08  (C. Talandier) Original code
+   !!----------------------------------------------------------------------
+   USE par_oce                 ! ocean parameters
+   USE trdmld_oce              ! ocean active mixed layer tracers trends variables
+   USE trdvor_oce              ! ocean vorticity trends variables
+
+   IMPLICIT NONE
+   PUBLIC
+
+   !                                                   !!* Namelist namtrd:  diagnostics on dynamics/tracer trends *
+   LOGICAL , PUBLIC  ::   ln_dyn_trd   = .FALSE.        !: (T) 3D momentum             trends or (F) not
+   LOGICAL , PUBLIC  ::   ln_tra_trd   = .FALSE.        !: (T) 3D tracer               trends or (F) not
+   LOGICAL , PUBLIC  ::   ln_KE_trd    = .FALSE.        !: (T) 3D Kinetic   Energy     trends or (F) not
+   LOGICAL , PUBLIC  ::   ln_PE_trd    = .FALSE.        !: (T) 3D Potential Energy     trends or (F) not
+   LOGICAL , PUBLIC  ::   ln_vor_trd   = .FALSE.        !: (T) 3D barotropic vorticity trends or (F) not
+   LOGICAL , PUBLIC  ::   ln_glo_trd   = .FALSE.        !: (T) global domain averaged diag for T, T^2, KE, and PE
+   LOGICAL , PUBLIC  ::   ln_dyn_mld   = .FALSE.        !: (T) 2D tracer   trends averaged over the mixed layer 
+   LOGICAL , PUBLIC  ::   ln_tra_mld   = .FALSE.        !: (T) 2D momentum trends averaged over the mixed layer 
+   INTEGER , PUBLIC  ::   nn_trd  = 10                  !: time step frequency for ln_glo_trd
+   INTEGER , PUBLIC  ::   nn_ctls =  0                  !: control surface type for trends vertical integration
+   REAL(wp), PUBLIC  ::   rn_ucf   = 1.                 !: unit conversion factor (for netCDF trends outputs)
+                                                        !: =1. (=86400.) for degC/s (degC/day) and psu/s (psu/day)
+   CHARACTER(len=32) ::   cn_trdrst_in  = "restart_mld" !: suffix of ocean restart name (input)
+   CHARACTER(len=32) ::   cn_trdrst_out = "restart_mld" !: suffix of ocean restart name (output)
+   LOGICAL , PUBLIC  ::   ln_trdmld_instant = .FALSE.   !: flag to diagnose inst./mean ML T/S trends
+   LOGICAL , PUBLIC  ::   ln_trdmld_restart = .FALSE.   !: flag to restart mixed-layer diagnostics
+
+   LOGICAL , PUBLIC ::   l_trdtra        !: tracers  trend flag (set from namelist in trdini)
+   LOGICAL , PUBLIC ::   l_trddyn        !: momentum trend flag (set from namelist in trdini)
+   
+# if ( defined key_trdtrc && defined key_iomput )  ||  defined key_trdmld_trc
+   LOGICAL , PUBLIC ::   l_trdtrc = .TRUE.        !: tracers  trend flag
+# else
+   LOGICAL , PUBLIC ::   l_trdtrc = .FALSE.       !: tracers  trend flag
+# endif
+   !                                                  !!!* Active tracers trends indexes
+   INTEGER, PUBLIC, PARAMETER ::   jptot_tra  = 14     !: Total trend nb: change it when adding/removing one indice below
+   !                               ===============     !  
+   INTEGER, PUBLIC, PARAMETER ::   jptra_xad  =  1     !: x- horizontal advection
+   INTEGER, PUBLIC, PARAMETER ::   jptra_yad  =  2     !: y- horizontal advection
+   INTEGER, PUBLIC, PARAMETER ::   jptra_zad  =  3     !: z- vertical   advection
+   INTEGER, PUBLIC, PARAMETER ::   jptra_sad  =  4     !: z- vertical   advection
+   INTEGER, PUBLIC, PARAMETER ::   jptra_ldf  =  5     !: lateral       diffusion
+   INTEGER, PUBLIC, PARAMETER ::   jptra_zdf  =  6     !: vertical      diffusion
+   INTEGER, PUBLIC, PARAMETER ::   jptra_zdfp =  7     !: "PURE" vert.  diffusion (ln_traldf_iso=T)
+   INTEGER, PUBLIC, PARAMETER ::   jptra_bbc  =  8     !: Bottom Boundary Condition (geoth. heating) 
+   INTEGER, PUBLIC, PARAMETER ::   jptra_bbl  =  9     !: Bottom Boundary Layer (diffusive and/or advective)
+   INTEGER, PUBLIC, PARAMETER ::   jptra_npc  = 10     !: non-penetrative convection treatment
+   INTEGER, PUBLIC, PARAMETER ::   jptra_dmp  = 11     !: internal restoring (damping)
+   INTEGER, PUBLIC, PARAMETER ::   jptra_qsr  = 12     !: penetrative solar radiation
+   INTEGER, PUBLIC, PARAMETER ::   jptra_nsr  = 13     !: non solar radiation / C/D on salinity  (+runoff if ln_rnf=T)
+   INTEGER, PUBLIC, PARAMETER ::   jptra_atf  = 14     !: Asselin time filter
+   !
+   !                                                  !!!* Passive tracers trends indices (use if "key_top" defined)
+   INTEGER, PUBLIC, PARAMETER ::   jptra_sms  = 15     !: sources m. sinks
+   INTEGER, PUBLIC, PARAMETER ::   jptra_radn = 16     !: corr. trn<0 in trcrad
+   INTEGER, PUBLIC, PARAMETER ::   jptra_radb = 17     !: corr. trb<0 in trcrad (like atf)
+   !
+   !                                                  !!!* Momentum trends indices
+   INTEGER, PUBLIC, PARAMETER ::   jptot_dyn  = 11     !: Total trend nb: change it when adding/removing one indice below
+   !                               ===============     !  
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_hpg  =  1     !: hydrostatic pressure gradient 
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_spg  =  2     !: surface     pressure gradient
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_keg  =  3     !: kinetic energy gradient  or horizontal advection
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_rvo  =  4     !: relative  vorticity      or metric term
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_pvo  =  5     !: planetary vorticity
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_zad  =  6     !: vertical advection
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_ldf  =  7     !: horizontal diffusion   
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_zdf  =  8     !: vertical   diffusion
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_tau  =  9     !: surface stress
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_bfr  = 10     !: bottom  stress 
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_atf  = 11     !: Asselin time filter
+   !
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!======================================================================
+END MODULE trd_oce
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trddyn.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trddyn.F90	(revision 3318)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trddyn.F90	(revision 3318)
@@ -0,0 +1,188 @@
+MODULE trddyn
+   !!======================================================================
+   !!                       ***  MODULE  trddyn  ***
+   !! Ocean diagnostics:  ocean dynamic trends
+   !!=====================================================================
+   !! History :  3.5  !  2012-02  (G. Madec) creation from trdmod: split DYN and TRA trends
+   !!                           and manage  3D trends output for U, V, and KE
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   trd_dyn       : manage the type of momentum trend diagnostics (3D I/O, domain averaged, KE)
+   !!   trd_dyn_iom   : output 3D momentum and/or tracer trends using IOM
+   !!   trd_dyn_init  : initialization step
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables
+   USE zdf_oce        ! ocean vertical physics variables
+   USE trd_oce        ! trends: ocean variables
+   USE zdfbfr         ! bottom friction
+   USE ldftra_oce     ! ocean active tracers lateral physics
+   USE sbc_oce        ! surface boundary condition: ocean
+   USE phycst         ! physical constants
+   USE trdvor         ! ocean vorticity trends 
+   USE trdglo         ! trends:global domain averaged
+   USE trdmld         ! ocean active mixed layer tracers trends 
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory allocation
+
+   IMPLICIT NONE
+   PRIVATE
+
+   REAL(wp) ::   r2dt    ! time-step, = 2 rdttra except at nit000 (=rdttra) if neuler=0
+
+   PUBLIC trd_dyn        ! called by all dynXX modules
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trd_dyn( putrd, pvtrd, ktrd, kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mod  ***
+      !! 
+      !! ** Purpose :   Dispatch momentum trend computation, e.g. 3D output, 
+      !!              integral constraints, barotropic vorticity, kinetic enrgy, 
+      !!              and/or mixed layer budget.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   putrd, pvtrd   ! U and V trends 
+      INTEGER                   , INTENT(in   ) ::   ktrd           ! trend index
+      INTEGER                   , INTENT(in   ) ::   kt             ! time step
+      !!
+      INTEGER ::   ji, jj   ! dummy loop indices
+      REAL(wp), POINTER, DIMENSION(:,:) ::   ztswu, ztswv    ! 2D workspace 
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, ztswu, ztswv )
+
+      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdtra (restart with Euler time stepping)
+      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdttra (leapfrog)
+      ENDIF
+
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !   3D output of momentum and/or tracers trends using IOM interface
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF( ln_dyn_trd )   CALL trd_dyn_iom( putrd, pvtrd, ktrd, kt )
+         
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !  Integral Constraints Properties for momentum and/or tracers trends
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF( ln_glo_trd  )   CALL trd_glo( putrd, pvtrd, ktrd, 'DYN', kt )
+
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !  Kinetic Energy trends
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!!gm      IF( ln_KE_trd  )   CALL trd_KE( putrd, pvtrd, ktrd, kt )
+
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !  Vorticity trends
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      IF( ln_vor_trd  )   CALL trd_vor( putrd, pvtrd, ktrd, kt )
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      !  Mixed layer trends for active tracers
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+!!gm      IF( ln_dyn_mld )   CALL trd_mld_dyn   
+      !
+      CALL wrk_dealloc( jpi, jpj, ztswu, ztswv )
+      !
+   END SUBROUTINE trd_dyn
+
+
+   SUBROUTINE trd_dyn_iom( putrd, pvtrd, ktrd, kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_dyn_iom  ***
+      !! 
+      !! ** Purpose :   output 3D trends using IOM
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   putrd, pvtrd   ! U and V trends
+      INTEGER                   , INTENT(in   ) ::   ktrd           ! trend index
+      INTEGER                   , INTENT(in   ) ::   kt             ! time step
+      !
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
+      INTEGER ::   ikbu, ikbv   ! local integers
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   z2dx, z2dy, ztswu, ztswv   ! 2D workspace 
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   z3dx, z3dy                 ! 3D workspace 
+      !!----------------------------------------------------------------------
+      !
+      putrd(:,:,:) = putrd(:,:,:) * umask(:,:,:)                       ! mask the trends
+      pvtrd(:,:,:) = pvtrd(:,:,:) * vmask(:,:,:)
+
+!!gm NB : here a lbc_lnk should probably be added
+
+      !
+      SELECT CASE( ktrd )
+      CASE( jpdyn_hpg )   ;   CALL iom_put( "utrd_hpg", putrd )    ! hydrostatic pressure gradient
+                              CALL iom_put( "vtrd_hpg", pvtrd )
+      CASE( jpdyn_spg )   ;   CALL iom_put( "utrd_spg", putrd )    ! surface pressure gradient
+                              CALL iom_put( "vtrd_spg", pvtrd )
+      CASE( jpdyn_pvo )   ;   CALL iom_put( "utrd_pvo", putrd )    ! planetary vorticity
+                              CALL iom_put( "vtrd_pvo", pvtrd )
+      CASE( jpdyn_rvo )   ;   CALL iom_put( "utrd_rvo", putrd )    ! relative  vorticity     (or metric term)
+                              CALL iom_put( "vtrd_rvo", pvtrd )
+      CASE( jpdyn_keg )   ;   CALL iom_put( "utrd_keg", putrd )    ! Kinetic Energy gradient (or had)
+                              CALL iom_put( "vtrd_keg", pvtrd )
+         z3dx(:,:,:) = 0._wp                                           ! U.dxU & V.dyV (approximation)
+         z3dy(:,:,:) = 0._wp
+         DO jk = 1, jpkm1														         ! no mask as un,vn are masked
+            DO jj = 2, jpjm1
+                DO ji = 2, jpim1
+                  z3dx(ji,jj,jk) = un(ji,jj,jk) * ( un(ji+1,jj,jk) - un(ji-1,jj,jk) ) / ( 2._wp * e1u(ji,jj) )
+                  z3dy(ji,jj,jk) = vn(ji,jj,jk) * ( vn(ji,jj+1,jk) - vn(ji,jj-1,jk) ) / ( 2._wp * e2v(ji,jj) )
+               END DO
+            END DO
+         END DO
+         CALL lbc_lnk( z3dx, 'U', -1. )   ;    CALL lbc_lnk( z3dy, 'V', -1. )
+                              CALL iom_put( "utrd_udx", z3dx  ) 
+                              CALL iom_put( "vtrd_vdy", z3dy  )
+      CASE( jpdyn_zad )   ;   CALL iom_put( "utrd_zad", putrd )    ! vertical   advection
+                              CALL iom_put( "vtrd_zad", pvtrd )
+      CASE( jpdyn_ldf )   ;   CALL iom_put( "utrd_ldf", putrd )    ! lateral diffusion
+                              CALL iom_put( "vtrd_ldf", pvtrd )
+      CASE( jpdyn_zdf )   ;   CALL iom_put( "utrd_zdf", putrd )    ! vertical diffusion 
+                              CALL iom_put( "vtrd_zdf", pvtrd )
+                              !                                    ! wind stress trends
+                              z2dx(:,:) = ( utau_b(ji,jj) + utau(ji,jj) ) / ( fse3u(:,:,1) * rau0 )
+                              z2dy(:,:) = ( vtau_b(ji,jj) + vtau(ji,jj) ) / ( fse3v(:,:,1) * rau0 )
+                              CALL iom_put( "utrd_tau", z2dx )
+                              CALL iom_put( "vtrd_tau", z2dy )
+      CASE( jpdyn_bfr )
+         IF( .NOT.ln_bfrimp )     CALL iom_put( "utrd_bfr", putrd )    ! bottom friction (explicit case)
+         IF( .NOT.ln_bfrimp )     CALL iom_put( "vtrd_bfr", pvtrd )
+!!gm only valid if ln_bfrimp=T otherwise the bottom stress as to be recomputed at the end of the compuation....
+
+      CASE( jpdyn_atf )   ;   CALL iom_put( "utrd_atf", putrd )    ! asselin filter trends 
+                              CALL iom_put( "vtrd_atf", pvtrd )
+         IF( ln_bfrimp ) THEN                                          ! bottom friction (implicit case)
+				z3dx(:,:,:) = 0._wp   ;   z3dy(:,:,:) = 0._wp                 ! after velocity known (now filed at this stage)
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+                  DO ji = 2, jpim1
+                     ikbu = mbku(ji,jj)          ! deepest ocean u- & v-levels
+                     ikbv = mbkv(ji,jj)
+                     z3dx(ji,jj,jk) = bfrua(ji,jj) * un(ji,jj,ikbu) / fse3u(ji,jj,ikbu)
+                     z3dy(ji,jj,jk) = bfrva(ji,jj) * vn(ji,jj,ikbv) / fse3v(ji,jj,ikbv)
+                  END DO
+               END DO
+            END DO
+                              CALL iom_put( "utrd_bfr", z3dx )    ! bottom friction (implicit)
+                              CALL iom_put( "vtrd_bfr", z3dy )
+         ENDIF
+         !
+      END SELECT
+      !
+      CALL wrk_dealloc( jpi, jpj     , z2dx, z2dy, ztswu, ztswv )
+      CALL wrk_dealloc( jpi, jpj, jpk, z3dx, z3dy )
+      !
+   END SUBROUTINE trd_dyn_iom
+
+   !!======================================================================
+END MODULE trddyn
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdglo.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdglo.F90	(revision 3318)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdglo.F90	(revision 3318)
@@ -0,0 +1,559 @@
+MODULE trdglo
+   !!======================================================================
+   !!                       ***  MODULE  trdglo  ***
+   !! Ocean diagnostics:  global domain averaged tracer and momentum trends
+   !!=====================================================================
+   !! History :  1.0  !  2004-08 (C. Talandier) New trends organization
+   !!            3.5  !  2012-02 (G. Madec)  add 3D tracer zdf trend output using iom
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   trd_glo      : domain averaged budget of trends (including kinetic energy and T^2 trends)
+   !!   glo_dyn_wri  : print dynamic trends in ocean.output file
+   !!   glo_tra_wri  : print global T & T^2 trends in ocean.output file
+   !!   trd_glo_init : initialization step
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE sbc_oce         ! surface boundary condition: ocean
+   USE trd_oce         ! trends: ocean variables
+   USE phycst          ! physical constants
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE ldfdyn_oce      ! ocean dynamics: lateral physics
+   USE zdf_oce         ! ocean vertical physics
+   USE zdfbfr          ! bottom friction
+   USE zdfddm          ! ocean vertical physics: double diffusion
+   USE eosbn2          ! equation of state
+   USE phycst          ! physical constants
+   USE lib_mpp         ! distibuted memory computing library
+   USE in_out_manager  ! I/O manager
+   USE iom             ! I/O manager library
+   USE wrk_nemo        ! Memory allocation
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trd_glo       ! called by trdtra and trddyn modules
+   PUBLIC   trd_glo_init  ! called by trdini module
+
+   !                     !!! Variables used for diagnostics
+   REAL(wp) ::   tvolt    ! volume of the whole ocean computed at t-points
+   REAL(wp) ::   tvolu    ! volume of the whole ocean computed at u-points
+   REAL(wp) ::   tvolv    ! volume of the whole ocean computed at v-points
+   REAL(wp) ::   rpktrd   ! potential to kinetic energy conversion
+   REAL(wp) ::   peke     ! conversion potential energy - kinetic energy trend
+
+   !                     !!! domain averaged trends
+   REAL(wp), DIMENSION(jptot_tra) ::   tmo, smo   ! temperature and salinity trends 
+   REAL(wp), DIMENSION(jptot_tra) ::   t2 , s2    ! T^2 and S^2 trends 
+   REAL(wp), DIMENSION(jptot_dyn) ::   umo, vmo   ! momentum trends 
+   REAL(wp), DIMENSION(jptot_dyn) ::   hke        ! kinetic energy trends (u^2+v^2) 
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+#  include "zdfddm_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trd_glo( ptrdx, ptrdy, ktrd, ctype, kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_glo  ***
+      !! 
+      !! ** Purpose :   compute and print global domain averaged trends for 
+      !!              T, T^2, momentum, KE, and KE<->PE
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend 
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
+      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
+      CHARACTER(len=3)          , INTENT(in   ) ::   ctype   ! momentum or tracers trends type (='DYN'/'TRA')
+      INTEGER                   , INTENT(in   ) ::   kt      ! time step
+      !!
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+      INTEGER ::   ikbu, ikbv      ! local integers
+      REAL(wp)::   zvm, zvt, zvs, z1_2rau0   ! local scalars
+      REAL(wp), POINTER, DIMENSION(:,:)  :: ztswu, ztswv, z2dx, z2dy   ! 2D workspace 
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, ztswu, ztswv, z2dx, z2dy )
+
+      IF( MOD(kt,nn_trd) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
+         !
+      	SELECT CASE( ctype )
+      	!
+      	CASE( 'TRA' )          !==  Tracers (T & S)  ==!
+      	   DO jk = 1, jpkm1       ! global sum of mask volume trend and trend*T (including interior mask)
+      	      DO jj = 1, jpj
+      	         DO ji = 1, jpi        
+      	            zvm = e1e2t(ji,jj) * fse3t(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+      	            zvt = ptrdx(ji,jj,jk) * zvm
+      	            zvs = ptrdy(ji,jj,jk) * zvm
+         	         tmo(ktrd) = tmo(ktrd) + zvt   
+         	         smo(ktrd) = smo(ktrd) + zvs
+         	         t2 (ktrd) = t2(ktrd)  + zvt * tsn(ji,jj,jk,jp_tem)
+         	         s2 (ktrd) = s2(ktrd)  + zvs * tsn(ji,jj,jk,jp_sal)
+                  END DO
+               END DO
+            END DO
+            !                       ! linear free surface: diagnose advective flux trough the fixed k=1 w-surface
+            IF( .NOT.lk_vvl .AND. ktrd == jptra_zad ) THEN  
+               tmo(jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_tem) * e1e2t(:,:) )
+               smo(jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_sal) * e1e2t(:,:)  )
+               t2 (jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_tem) * tsn(:,:,1,jp_tem) * e1e2t(:,:)  )
+               s2 (jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_sal) * tsn(:,:,1,jp_sal) * e1e2t(:,:)  )
+            ENDIF
+            !
+            IF( ktrd == jptra_atf ) THEN     ! last trend (asselin time filter)
+               ! 
+               CALL glo_tra_wri( kt )             ! print the results in ocean.output
+               !                
+	            tmo(:) = 0._wp                     ! prepare the next time step (domain averaged array reset to zero)
+   	         smo(:) = 0._wp
+               t2 (:) = 0._wp
+               s2 (:) = 0._wp
+               !
+            ENDIF
+            !
+         CASE( 'DYN' )          !==  Momentum and KE  ==!        
+            DO jk = 1, jpkm1
+               DO jj = 1, jpjm1
+                  DO ji = 1, jpim1
+                     zvt = ptrdx(ji,jj,jk) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)   &
+                        &                  * e1u    (ji  ,jj  ) * e2u    (ji,jj) * fse3u(ji,jj,jk)
+                     zvs = ptrdy(ji,jj,jk) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)   &
+                        &                  * e1v    (ji  ,jj  ) * e2v    (ji,jj) * fse3u(ji,jj,jk)
+                     umo(ktrd) = umo(ktrd) + zvt
+                     vmo(ktrd) = vmo(ktrd) + zvs
+                     hke(ktrd) = hke(ktrd) + un(ji,jj,jk) * zvt + vn(ji,jj,jk) * zvs
+                  END DO
+               END DO
+            END DO
+            !                 
+            IF( ktrd == jpdyn_zdf ) THEN      ! zdf trend: compute separately the surface forcing trend
+               z1_2rau0 = 0.5_wp / rau0
+               DO jj = 1, jpjm1
+                  DO ji = 1, jpim1
+                     zvt = ( utau_b(ji,jj) + utau(ji,jj) ) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)   &
+                        &                       * z1_2rau0 * e1u    (ji  ,jj  ) * e2u    (ji,jj)
+                     zvs = ( vtau_b(ji,jj) + vtau(ji,jj) ) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)   &
+                        &                       * z1_2rau0 * e1v    (ji  ,jj  ) * e2v    (ji,jj) * fse3u(ji,jj,jk)
+                     umo(jpdyn_tau) = umo(jpdyn_tau) + zvt
+                     vmo(jpdyn_tau) = vmo(jpdyn_tau) + zvs
+                     hke(jpdyn_tau) = hke(jpdyn_tau) + un(ji,jj,1) * zvt + vn(ji,jj,1) * zvs
+                  END DO
+               END DO
+            ENDIF
+            !                       
+            IF( ktrd == jpdyn_atf ) THEN     ! last trend (asselin time filter)
+               !
+               IF( ln_bfrimp ) THEN                   ! implicit bfr case: compute separately the bottom friction 
+                  z1_2rau0 = 0.5_wp / rau0
+                  DO jj = 1, jpjm1
+                     DO ji = 1, jpim1
+                        ikbu = mbku(ji,jj)                  ! deepest ocean u- & v-levels
+                        ikbv = mbkv(ji,jj)
+                        zvt = bfrua(ji,jj) * un(ji,jj,ikbu) * e1u(ji,jj) * e2v(ji,jj)
+                        zvs = bfrva(ji,jj) * vn(ji,jj,ikbv) * e1v(ji,jj) * e2v(ji,jj)
+                        umo(jpdyn_bfr) = umo(jpdyn_bfr) + zvt
+                        vmo(jpdyn_bfr) = vmo(jpdyn_bfr) + zvs
+                        hke(jpdyn_bfr) = hke(jpdyn_bfr) + un(ji,jj,ikbu) * zvt + vn(ji,jj,ikbv) * zvs
+                     END DO
+                  END DO
+               ENDIF
+               ! 
+               CALL glo_dyn_wri( kt )                 ! print the results in ocean.output
+               !                
+               umo(:) = 0._wp                         ! reset for the next time step
+               vmo(:) = 0._wp
+               hke(:) = 0._wp
+               !
+            ENDIF
+            !
+         END SELECT
+         !
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi, jpj, ztswu, ztswv, z2dx, z2dy )
+      !
+   END SUBROUTINE trd_glo
+
+
+   SUBROUTINE trd_glo_init
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_glo_init  ***
+      !! 
+      !! ** Purpose :   Read the namtrd namelist
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trd_glo_init : integral constraints properties trends'
+         WRITE(numout,*) '~~~~~~~~~~~~~'
+      ENDIF
+
+      ! Total volume at t-points:
+      tvolt = 0._wp
+      DO jk = 1, jpkm1
+         tvolt = SUM( e1e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:) )
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( tvolt )   ! sum over the global domain
+
+      IF(lwp) WRITE(numout,*) '                total ocean volume at T-point   tvolt = ',tvolt
+
+      ! Initialization of potential to kinetic energy conversion
+      rpktrd = 0._wp
+
+      ! Total volume at u-, v- points:
+      tvolu = 0._wp
+      tvolv = 0._wp
+
+      DO jk = 1, jpk
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               tvolu = tvolu + e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)
+               tvolv = tvolv + e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( tvolu )   ! sums over the global domain
+      IF( lk_mpp )   CALL mpp_sum( tvolv )
+
+      IF(lwp) THEN
+         WRITE(numout,*) '                total ocean volume at U-point   tvolu = ',tvolu
+         WRITE(numout,*) '                total ocean volume at V-point   tvolv = ',tvolv
+      ENDIF
+      !
+   END SUBROUTINE trd_glo_init
+
+
+   SUBROUTINE glo_dyn_wri( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE glo_dyn_wri  ***
+      !! 
+      !! ** Purpose :  write global averaged U, KE, PE<->KE trends in ocean.output 
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zcof         ! local scalar
+      REAL(wp), POINTER, DIMENSION(:,:,:)  ::  zkx, zky, zkz, zkepe  
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, jpk, zkx, zky, zkz, zkepe )
+
+      ! I. Momentum trends
+      ! -------------------
+
+      IF( MOD( kt, nn_trd ) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
+
+         ! I.1 Conversion potential energy - kinetic energy
+         ! --------------------------------------------------
+         ! c a u t i o n here, trends are computed at kt+1 (now , but after the swap)
+         zkx  (:,:,:) = 0._wp
+         zky  (:,:,:) = 0._wp
+         zkz  (:,:,:) = 0._wp
+         zkepe(:,:,:) = 0._wp
+   
+         CALL eos( tsn, rhd, rhop )       ! now potential and in situ densities
+
+         zcof = 0.5_wp / rau0             ! Density flux at w-point
+         zkz(:,:,1) = 0._wp
+         DO jk = 2, jpk
+            zkz(:,:,jk) = e1e2t(:,:) * wn(:,:,jk) * ( rhop(:,:,jk) + rhop(:,:,jk-1) ) * tmask_i(:,:)
+         END DO
+         
+         zcof   = 0.5_wp / rau0           ! Density flux at u and v-points
+         DO jk = 1, jpkm1
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1
+                  zkx(ji,jj,jk) = zcof * e2u(ji,jj) * fse3u(ji,jj,jk) * un(ji,jj,jk) * ( rhop(ji,jj,jk) + rhop(ji+1,jj,jk) )
+                  zky(ji,jj,jk) = zcof * e1v(ji,jj) * fse3v(ji,jj,jk) * vn(ji,jj,jk) * ( rhop(ji,jj,jk) + rhop(ji,jj+1,jk) )
+               END DO
+            END DO
+         END DO
+         
+         DO jk = 1, jpkm1                 ! Density flux divergence at t-point
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  zkepe(ji,jj,jk) = - (  zkz(ji,jj,jk) - zkz(ji  ,jj  ,jk+1)               &
+                     &                 + zkx(ji,jj,jk) - zkx(ji-1,jj  ,jk  )               &
+                     &                 + zky(ji,jj,jk) - zky(ji  ,jj-1,jk  )   )           &
+                     &              / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) ) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+               END DO
+            END DO
+         END DO
+
+         ! I.2 Basin averaged kinetic energy trend
+         ! ----------------------------------------
+         peke = 0._wp
+         DO jk = 1, jpkm1
+            peke = peke + SUM( zkepe(:,:,jk) * fsdept(:,:,jk) * e1e2t(:,:) * fse3t(:,:,jk) )
+         END DO
+         peke = grav * peke
+
+         ! I.3 Sums over the global domain
+         ! ---------------------------------
+         IF( lk_mpp ) THEN
+            CALL mpp_sum( peke )
+            CALL mpp_sum( umo , jptot_dyn )
+            CALL mpp_sum( vmo , jptot_dyn )
+            CALL mpp_sum( hke , jptot_dyn )
+         ENDIF
+
+         ! I.2 Print dynamic trends in the ocean.output file
+         ! --------------------------------------------------
+
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9500) kt
+            WRITE (numout,9501) umo(jpdyn_hpg) / tvolu, vmo(jpdyn_hpg) / tvolv
+            WRITE (numout,9509) umo(jpdyn_spg) / tvolu, vmo(jpdyn_spg) / tvolv
+            WRITE (numout,9502) umo(jpdyn_keg) / tvolu, vmo(jpdyn_keg) / tvolv
+            WRITE (numout,9503) umo(jpdyn_rvo) / tvolu, vmo(jpdyn_rvo) / tvolv
+            WRITE (numout,9504) umo(jpdyn_pvo) / tvolu, vmo(jpdyn_pvo) / tvolv
+            WRITE (numout,9507) umo(jpdyn_zad) / tvolu, vmo(jpdyn_zad) / tvolv
+            WRITE (numout,9505) umo(jpdyn_ldf) / tvolu, vmo(jpdyn_ldf) / tvolv
+            WRITE (numout,9508) umo(jpdyn_zdf) / tvolu, vmo(jpdyn_zdf) / tvolv
+            WRITE (numout,9510) umo(jpdyn_tau) / tvolu, vmo(jpdyn_tau) / tvolv
+            WRITE (numout,9511) umo(jpdyn_bfr) / tvolu, vmo(jpdyn_bfr) / tvolv
+            WRITE (numout,9512) umo(jpdyn_atf) / tvolu, vmo(jpdyn_atf) / tvolv
+            WRITE (numout,9513)
+            WRITE (numout,9514)                                                 &
+            &     (  umo(jpdyn_hpg) + umo(jpdyn_spg) + umo(jpdyn_keg) + umo(jpdyn_rvo)   &
+            &      + umo(jpdyn_pvo) + umo(jpdyn_zad) + umo(jpdyn_ldf) + umo(jpdyn_zdf)   &
+            &      + umo(jpdyn_tau) + umo(jpdyn_bfr) + umo(jpdyn_atf) ) / tvolu,   &
+            &     (  vmo(jpdyn_hpg) + vmo(jpdyn_spg) + vmo(jpdyn_keg) + vmo(jpdyn_rvo)   &
+            &      + vmo(jpdyn_pvo) + vmo(jpdyn_zad) + vmo(jpdyn_ldf) + vmo(jpdyn_zdf)   &
+            &      + vmo(jpdyn_tau) + vmo(jpdyn_bfr) + vmo(jpdyn_atf) ) / tvolv
+         ENDIF
+
+ 9500    FORMAT(' momentum trend at it= ', i6, ' :', /' ==============================')
+ 9501    FORMAT(' pressure gradient          u= ', e20.13, '    v= ', e20.13)
+ 9502    FORMAT(' ke gradient                u= ', e20.13, '    v= ', e20.13)
+ 9503    FORMAT(' relative vorticity term    u= ', e20.13, '    v= ', e20.13)
+ 9504    FORMAT(' coriolis term              u= ', e20.13, '    v= ', e20.13)
+ 9505    FORMAT(' horizontal diffusion       u= ', e20.13, '    v= ', e20.13)
+ 9507    FORMAT(' vertical advection         u= ', e20.13, '    v= ', e20.13)
+ 9508    FORMAT(' vertical diffusion         u= ', e20.13, '    v= ', e20.13)
+ 9509    FORMAT(' surface pressure gradient  u= ', e20.13, '    v= ', e20.13)
+ 9510    FORMAT(' surface wind stress        u= ', e20.13, '    v= ', e20.13)
+ 9511    FORMAT(' bottom friction            u= ', e20.13, '    v= ', e20.13)
+ 9512    FORMAT(' Asselin time filter        u= ', e20.13, '    v= ', e20.13)
+ 9513    FORMAT(' -----------------------------------------------------------------------------')
+ 9514    FORMAT(' total trend                u= ', e20.13, '    v= ', e20.13)
+
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9520) kt
+            WRITE (numout,9521) hke(jpdyn_hpg) / tvolt
+            WRITE (numout,9529) hke(jpdyn_spg) / tvolt
+            WRITE (numout,9522) hke(jpdyn_keg) / tvolt
+            WRITE (numout,9523) hke(jpdyn_rvo) / tvolt
+            WRITE (numout,9524) hke(jpdyn_pvo) / tvolt
+            WRITE (numout,9527) hke(jpdyn_zad) / tvolt
+            WRITE (numout,9525) hke(jpdyn_ldf) / tvolt
+            WRITE (numout,9528) hke(jpdyn_zdf) / tvolt
+            WRITE (numout,9530) hke(jpdyn_tau) / tvolt
+            WRITE (numout,9531) hke(jpdyn_bfr) / tvolt
+            WRITE (numout,9532) hke(jpdyn_atf) / tvolt
+            WRITE (numout,9533)
+            WRITE (numout,9534)   &
+            &     (  hke(jpdyn_hpg) + hke(jpdyn_spg) + hke(jpdyn_keg) + hke(jpdyn_rvo)   &
+            &      + hke(jpdyn_pvo) + hke(jpdyn_zad) + hke(jpdyn_ldf) + hke(jpdyn_zdf)   &
+            &      + hke(jpdyn_tau) + hke(jpdyn_bfr) + hke(jpdyn_atf)  ) / tvolt
+         ENDIF
+
+ 9520    FORMAT(' kinetic energy trend at it= ', i6, ' :', /' ====================================')
+ 9521    FORMAT(' pressure gradient         u2= ', e20.13)
+ 9529    FORMAT(' surface pressure gradient u2= ', e20.13)
+ 9522    FORMAT(' ke gradient               u2= ', e20.13)
+ 9523    FORMAT(' relative vorticity term   u2= ', e20.13)
+ 9524    FORMAT(' coriolis term             u2= ', e20.13)
+ 9527    FORMAT(' vertical advection        u2= ', e20.13)
+ 9525    FORMAT(' horizontal diffusion      u2= ', e20.13)
+ 9528    FORMAT(' vertical diffusion        u2= ', e20.13)
+ 9530    FORMAT(' surface wind stress       u2= ', e20.13)
+ 9531    FORMAT(' bottom friction           u2= ', e20.13)
+ 9532    FORMAT(' Asselin time filter       u2= ', e20.13)
+ 9533    FORMAT(' --------------------------------------------------')
+ 9534    FORMAT(' total trend               u2= ', e20.13)
+
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9540) kt
+            WRITE (numout,9541) ( hke(jpdyn_keg) + hke(jpdyn_rvo) + hke(jpdyn_zad) ) / tvolt
+            WRITE (numout,9542) ( hke(jpdyn_keg) + hke(jpdyn_zad) ) / tvolt
+            WRITE (numout,9543) ( hke(jpdyn_pvo) ) / tvolt
+            WRITE (numout,9544) ( hke(jpdyn_rvo) ) / tvolt
+            WRITE (numout,9545) ( hke(jpdyn_spg) ) / tvolt
+            WRITE (numout,9546) ( hke(jpdyn_ldf) ) / tvolt
+            WRITE (numout,9547) ( hke(jpdyn_zdf) ) / tvolt
+            WRITE (numout,9548) ( hke(jpdyn_hpg) ) / tvolt, rpktrd / tvolt
+            WRITE (numout,*)
+            WRITE (numout,*)
+         ENDIF
+
+ 9540    FORMAT(' energetic consistency at it= ', i6, ' :', /' =========================================')
+ 9541    FORMAT(' 0 = non linear term (true if KE conserved)                : ', e20.13)
+ 9542    FORMAT(' 0 = ke gradient + vertical advection                      : ', e20.13)
+ 9543    FORMAT(' 0 = coriolis term  (true if KE conserving scheme)         : ', e20.13)
+ 9544    FORMAT(' 0 = vorticity term (true if KE conserving scheme)         : ', e20.13)
+ 9545    FORMAT(' 0 = surface pressure gradient  ???                        : ', e20.13)
+ 9546    FORMAT(' 0 < horizontal diffusion                                  : ', e20.13)
+ 9547    FORMAT(' 0 < vertical diffusion                                    : ', e20.13)
+ 9548    FORMAT(' pressure gradient u2 = - 1/rau0 u.dz(rhop)                : ', e20.13, '  u.dz(rhop) =', e20.13)
+         !
+         ! Save potential to kinetic energy conversion for next time step
+         rpktrd = peke
+         !
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi, jpj, jpk, zkx, zky, zkz, zkepe )
+      !
+   END SUBROUTINE glo_dyn_wri
+
+
+   SUBROUTINE glo_tra_wri( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE glo_tra_wri  ***
+      !! 
+      !! ** Purpose :  write global domain averaged of T and T^2 trends in ocean.output 
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      INTEGER  ::   jk   ! loop indices
+      !!----------------------------------------------------------------------
+
+      ! I. Tracers trends
+      ! -----------------
+
+      IF( MOD(kt,nn_trd) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
+
+         ! I.1 Sums over the global domain
+         ! -------------------------------
+         IF( lk_mpp ) THEN
+            CALL mpp_sum( tmo, jptot_tra )   
+            CALL mpp_sum( smo, jptot_tra )
+            CALL mpp_sum( t2 , jptot_tra )
+            CALL mpp_sum( s2 , jptot_tra )
+         ENDIF
+
+         ! I.2 Print tracers trends in the ocean.output file
+         ! --------------------------------------------------
+         
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9400) kt
+            WRITE (numout,9401)  tmo(jptra_xad) / tvolt, smo(jptra_xad) / tvolt
+            WRITE (numout,9411)  tmo(jptra_yad) / tvolt, smo(jptra_yad) / tvolt
+            WRITE (numout,9402)  tmo(jptra_zad) / tvolt, smo(jptra_zad) / tvolt
+            WRITE (numout,9403)  tmo(jptra_ldf) / tvolt, smo(jptra_ldf) / tvolt
+            WRITE (numout,9404)  tmo(jptra_zdf) / tvolt, smo(jptra_zdf) / tvolt
+            WRITE (numout,9405)  tmo(jptra_npc) / tvolt, smo(jptra_npc) / tvolt
+            WRITE (numout,9406)  tmo(jptra_dmp) / tvolt, smo(jptra_dmp) / tvolt
+            WRITE (numout,9407)  tmo(jptra_qsr) / tvolt
+            WRITE (numout,9408)  tmo(jptra_nsr) / tvolt, smo(jptra_nsr) / tvolt
+            WRITE (numout,9409) 
+            WRITE (numout,9410) (  tmo(jptra_xad) + tmo(jptra_yad) + tmo(jptra_zad) + tmo(jptra_ldf) + tmo(jptra_zdf)   &
+            &                    + tmo(jptra_npc) + tmo(jptra_dmp) + tmo(jptra_qsr) + tmo(jptra_nsr) ) / tvolt,   &
+            &                   (  smo(jptra_xad) + smo(jptra_yad) + smo(jptra_zad) + smo(jptra_ldf) + smo(jptra_zdf)   &
+            &                    + smo(jptra_npc) + smo(jptra_dmp)                   + smo(jptra_nsr) ) / tvolt
+         ENDIF
+
+9400     FORMAT(' tracer trend at it= ',i6,' :     temperature',   &
+              '              salinity',/' ============================')
+9401     FORMAT(' zonal      advection        ',e20.13,'     ',e20.13)
+9411     FORMAT(' meridional advection        ',e20.13,'     ',e20.13)
+9402     FORMAT(' vertical advection          ',e20.13,'     ',e20.13)
+9403     FORMAT(' horizontal diffusion        ',e20.13,'     ',e20.13)
+9404     FORMAT(' vertical diffusion          ',e20.13,'     ',e20.13)
+9405     FORMAT(' static instability mixing   ',e20.13,'     ',e20.13)
+9406     FORMAT(' damping term                ',e20.13,'     ',e20.13)
+9407     FORMAT(' penetrative qsr             ',e20.13)
+9408     FORMAT(' non solar radiation         ',e20.13,'     ',e20.13)
+9409     FORMAT(' -------------------------------------------------------------------------')
+9410     FORMAT(' total trend                 ',e20.13,'     ',e20.13)
+
+
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9420) kt
+            WRITE (numout,9421)   t2(jptra_xad) / tvolt, s2(jptra_xad) / tvolt
+            WRITE (numout,9431)   t2(jptra_yad) / tvolt, s2(jptra_yad) / tvolt
+            WRITE (numout,9422)   t2(jptra_zad) / tvolt, s2(jptra_zad) / tvolt
+            WRITE (numout,9423)   t2(jptra_ldf) / tvolt, s2(jptra_ldf) / tvolt
+            WRITE (numout,9424)   t2(jptra_zdf) / tvolt, s2(jptra_zdf) / tvolt
+            WRITE (numout,9425)   t2(jptra_npc) / tvolt, s2(jptra_npc) / tvolt
+            WRITE (numout,9426)   t2(jptra_dmp) / tvolt, s2(jptra_dmp) / tvolt
+            WRITE (numout,9427)   t2(jptra_qsr) / tvolt
+            WRITE (numout,9428)   t2(jptra_nsr) / tvolt, s2(jptra_nsr) / tvolt
+            WRITE (numout,9429)
+            WRITE (numout,9430) (  t2(jptra_xad) + t2(jptra_yad) + t2(jptra_zad) + t2(jptra_ldf) + t2(jptra_zdf)   &
+            &                    + t2(jptra_npc) + t2(jptra_dmp) + t2(jptra_qsr) + t2(jptra_nsr) ) / tvolt,   &
+            &                   (  s2(jptra_xad) + s2(jptra_yad) + s2(jptra_zad) + s2(jptra_ldf) + s2(jptra_zdf)   &
+            &                    + s2(jptra_npc) + s2(jptra_dmp)                  + s2(jptra_nsr) ) / tvolt
+         ENDIF
+
+9420     FORMAT(' tracer**2 trend at it= ', i6, ' :      temperature',   &
+            '               salinity', /, ' ===============================')
+9421     FORMAT(' zonal      advection      * t   ', e20.13, '     ', e20.13)
+9431     FORMAT(' meridional advection      * t   ', e20.13, '     ', e20.13)
+9422     FORMAT(' vertical advection        * t   ', e20.13, '     ', e20.13)
+9423     FORMAT(' horizontal diffusion      * t   ', e20.13, '     ', e20.13)
+9424     FORMAT(' vertical diffusion        * t   ', e20.13, '     ', e20.13)
+9425     FORMAT(' static instability mixing * t   ', e20.13, '     ', e20.13)
+9426     FORMAT(' damping term              * t   ', e20.13, '     ', e20.13)
+9427     FORMAT(' penetrative qsr           * t   ', e20.13)
+9428     FORMAT(' non solar radiation       * t   ', e20.13, '     ', e20.13)
+9429     FORMAT(' -----------------------------------------------------------------------------')
+9430     FORMAT(' total trend                *t = ', e20.13, '  *s = ', e20.13)
+
+
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9440) kt
+            WRITE (numout,9441) ( tmo(jptra_xad)+tmo(jptra_yad)+tmo(jptra_zad) )/tvolt,   &
+            &                   ( smo(jptra_xad)+smo(jptra_yad)+smo(jptra_zad) )/tvolt
+            WRITE (numout,9442)   tmo(jptra_sad)/tvolt,  smo(jptra_sad)/tvolt
+            WRITE (numout,9443)   tmo(jptra_ldf)/tvolt,  smo(jptra_ldf)/tvolt
+            WRITE (numout,9444)   tmo(jptra_zdf)/tvolt,  smo(jptra_zdf)/tvolt
+            WRITE (numout,9445)   tmo(jptra_npc)/tvolt,  smo(jptra_npc)/tvolt
+            WRITE (numout,9446) ( t2(jptra_xad)+t2(jptra_yad)+t2(jptra_zad) )/tvolt,    &
+            &                   ( s2(jptra_xad)+s2(jptra_yad)+s2(jptra_zad) )/tvolt
+            WRITE (numout,9447)   t2(jptra_ldf)/tvolt,   s2(jptra_ldf)/tvolt
+            WRITE (numout,9448)   t2(jptra_zdf)/tvolt,   s2(jptra_zdf)/tvolt
+            WRITE (numout,9449)   t2(jptra_npc)/tvolt,   s2(jptra_npc)/tvolt
+         ENDIF
+
+9440     FORMAT(' tracer consistency at it= ',i6,   &
+            ' :         temperature','                salinity',/,   &
+            ' ==================================')
+9441     FORMAT(' 0 = horizontal+vertical advection +    ',e20.13,'       ',e20.13)
+9442     FORMAT('     1st lev vertical advection         ',e20.13,'       ',e20.13)
+9443     FORMAT(' 0 = horizontal diffusion               ',e20.13,'       ',e20.13)
+9444     FORMAT(' 0 = vertical diffusion                 ',e20.13,'       ',e20.13)
+9445     FORMAT(' 0 = static instability mixing          ',e20.13,'       ',e20.13)
+9446     FORMAT(' 0 = horizontal+vertical advection * t  ',e20.13,'       ',e20.13)
+9447     FORMAT(' 0 > horizontal diffusion          * t  ',e20.13,'       ',e20.13)
+9448     FORMAT(' 0 > vertical diffusion            * t  ',e20.13,'       ',e20.13)
+9449     FORMAT(' 0 > static instability mixing     * t  ',e20.13,'       ',e20.13)
+         !
+      ENDIF
+      !
+   END SUBROUTINE glo_tra_wri
+
+   !!======================================================================
+END MODULE trdglo
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdicp.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdicp.F90	(revision 3317)
+++ 	(revision )
@@ -1,563 +1,0 @@
-MODULE trdicp
-   !!======================================================================
-   !!                       ***  MODULE  trdicp  ***
-   !! Ocean diagnostics:  ocean tracers and dynamic trends
-   !!=====================================================================
-   !! History :  1.0  !  2004-08 (C. Talandier) New trends organization
-   !!            3.5  !  2012-02 (G. Madec)  add 3D tracer zdf trend output using iom
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   trd_budget     : domain averaged budget of trends (including kinetic energy and T^2 trends)
-   !!   trd_icp        : compute the basin averaged properties for tra/dyn 
-   !!   trd_dwr        : print dynmaic trends in ocean.output file
-   !!   trd_twr        : print tracers trends in ocean.output file
-   !!   trd_icp_init   : initialization step
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables
-   USE sbc_oce         ! surface boundary condition: ocean
-   USE phycst          ! physical constants
-   USE trdmod_oce      ! ocean variables trends
-   USE ldftra_oce      ! ocean active tracers: lateral physics
-   USE ldfdyn_oce      ! ocean dynamics: lateral physics
-   USE zdf_oce         ! ocean vertical physics
-   USE zdfbfr          ! bottom friction
-   USE zdfddm          ! ocean vertical physics: double diffusion
-   USE eosbn2          ! equation of state
-   USE phycst          ! physical constants
-   USE lib_mpp         ! distibuted memory computing library
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O manager library
-   USE wrk_nemo        ! Memory allocation
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   trd_budget    ! called by trdmod.F90
-   PUBLIC   trd_dwr       ! called by step.F90
-   PUBLIC   trd_twr       ! called by step.F90
-   PUBLIC   trd_icp_init  ! called by opa.F90
-
-   !                     !!! Variables used for diagnostics
-   REAL(wp) ::   tvolt    ! volume of the whole ocean computed at t-points
-   REAL(wp) ::   tvolu    ! volume of the whole ocean computed at u-points
-   REAL(wp) ::   tvolv    ! volume of the whole ocean computed at v-points
-   REAL(wp) ::   rpktrd   ! potential to kinetic energy conversion
-   REAL(wp) ::   peke     ! conversion potential energy - kinetic energy trend
-
-   !                     !!! domain averaged trends
-   REAL(wp), DIMENSION(jptot_tra) ::   tmo, smo   ! temperature and salinity trends 
-   REAL(wp), DIMENSION(jptot_tra) ::   t2 , s2    ! T^2 and S^2 trends 
-   REAL(wp), DIMENSION(jptot_dyn) ::   umo, vmo   ! momentum trends 
-   REAL(wp), DIMENSION(jptot_dyn) ::   hke        ! kinetic energy trends (u^2+v^2) 
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-#  include "zdfddm_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE trd_budget( ptrdx, ptrdy, ktrd, ctype, kt )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_budget  ***
-      !! 
-      !! ** Purpose : integral constraint diagnostics for momentum and/or tracer trends
-      !!              
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend 
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
-      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
-      CHARACTER(len=3)          , INTENT(in   ) ::   ctype   ! momentum or tracers trends type 'DYN'/'TRA'
-      INTEGER                   , INTENT(in   ) ::   kt      ! time step
-      !!
-      INTEGER ::   ji, jj, jk      ! dummy loop indices
-      INTEGER ::   ikbu, ikbv      ! local integers
-      REAL(wp)::   zvm, zvt, zvs, z1_2rau0   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:)  :: ztswu, ztswv, z2dx, z2dy   ! 2D workspace 
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, ztswu, ztswv, z2dx, z2dy )
-
-      IF( MOD(kt,nn_trd) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
-         !
-      	SELECT CASE( ctype )
-      	!
-      	CASE( 'TRA' )          !==  Tracers (T & S)  ==!
-      	   DO jk = 1, jpkm1       ! global sum of mask volume trend and trend*T (including interior mask)
-      	      DO jj = 1, jpj
-      	         DO ji = 1, jpi        
-      	            zvm = e1e2t(ji,jj) * fse3t(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
-      	            zvt = ptrdx(ji,jj,jk) * zvm
-      	            zvs = ptrdy(ji,jj,jk) * zvm
-         	         tmo(ktrd) = tmo(ktrd) + zvt   
-         	         smo(ktrd) = smo(ktrd) + zvs
-         	         t2 (ktrd) = t2(ktrd)  + zvt * tsn(ji,jj,jk,jp_tem)
-         	         s2 (ktrd) = s2(ktrd)  + zvs * tsn(ji,jj,jk,jp_sal)
-                  END DO
-               END DO
-            END DO
-            !                       ! linear free surface: diagnose advective flux trough the fixed k=1 w-surface
-            IF( .NOT.lk_vvl .AND. ktrd == jptra_trd_zad ) THEN  
-               tmo(jptra_trd_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_tem) * e1e2t(:,:) )
-               smo(jptra_trd_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_sal) * e1e2t(:,:)  )
-               t2 (jptra_trd_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_tem) * tsn(:,:,1,jp_tem) * e1e2t(:,:)  )
-               s2 (jptra_trd_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_sal) * tsn(:,:,1,jp_sal) * e1e2t(:,:)  )
-            ENDIF
-            !
-            IF( ktrd == jptra_trd_atf ) THEN     ! last trend (asselin time filter)
-               ! 
-               CALL trd_twr( kt )   ! print the results in ocean.output
-               !                
-	            tmo(:) = 0._wp       ! prepare the next time step (domain averaged array reset to zero)
-   	         smo(:) = 0._wp
-               t2 (:) = 0._wp
-               s2 (:) = 0._wp
-               !
-            ENDIF
-            !
-         CASE( 'DYN' )          !==  Momentum and KE  ==!        
-            DO jk = 1, jpkm1
-               DO jj = 1, jpjm1
-                  DO ji = 1, jpim1
-                     zvt = ptrdx(ji,jj,jk) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)   &
-                        &                  * e1u    (ji  ,jj  ) * e2u    (ji,jj) * fse3u(ji,jj,jk)
-                     zvs = ptrdy(ji,jj,jk) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)   &
-                        &                  * e1v    (ji  ,jj  ) * e2v    (ji,jj) * fse3u(ji,jj,jk)
-                     umo(ktrd) = umo(ktrd) + zvt
-                     vmo(ktrd) = vmo(ktrd) + zvs
-                     hke(ktrd) = hke(ktrd) + un(ji,jj,jk) * zvt + vn(ji,jj,jk) * zvs
-                  END DO
-               END DO
-            END DO
-            !                 
-            IF( ktrd == jpdyn_trd_zdf ) THEN      ! zdf trend: compute separately the surface forcing trend
-               z1_2rau0 = 0.5_wp / rau0
-               DO jj = 1, jpjm1
-                  DO ji = 1, jpim1
-                     zvt = ( utau_b(ji,jj) + utau(ji,jj) ) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)   &
-                        &                       * z1_2rau0 * e1u    (ji  ,jj  ) * e2u    (ji,jj)
-                     zvs = ( vtau_b(ji,jj) + vtau(ji,jj) ) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)   &
-                        &                       * z1_2rau0 * e1v    (ji  ,jj  ) * e2v    (ji,jj) * fse3u(ji,jj,jk)
-                     umo(jpdyn_trd_tau) = umo(jpdyn_trd_tau) + zvt
-                     vmo(jpdyn_trd_tau) = vmo(jpdyn_trd_tau) + zvs
-                     hke(jpdyn_trd_tau) = hke(jpdyn_trd_tau) + un(ji,jj,1) * zvt + vn(ji,jj,1) * zvs
-                  END DO
-               END DO
-            ENDIF
-            !                       
-            IF( ktrd == jpdyn_trd_atf ) THEN     ! last trend (asselin time filter)
-               !
-               IF( ln_bfrimp ) THEN                   ! implicit bfr case: compute separately the bottom friction 
-                  z1_2rau0 = 0.5_wp / rau0
-                  DO jj = 1, jpjm1
-                     DO ji = 1, jpim1
-                        ikbu = mbku(ji,jj)                  ! deepest ocean u- & v-levels
-                        ikbv = mbkv(ji,jj)
-                        zvt = bfrua(ji,jj) * un(ji,jj,ikbu) * e1u(ji,jj) * e2v(ji,jj)
-                        zvs = bfrva(ji,jj) * vn(ji,jj,ikbv) * e1v(ji,jj) * e2v(ji,jj)
-                        umo(jpdyn_trd_bfr) = umo(jpdyn_trd_bfr) + zvt
-                        vmo(jpdyn_trd_bfr) = vmo(jpdyn_trd_bfr) + zvs
-                        hke(jpdyn_trd_bfr) = hke(jpdyn_trd_bfr) + un(ji,jj,ikbu) * zvt + vn(ji,jj,ikbv) * zvs
-                     END DO
-                  END DO
-               ENDIF
-               ! 
-               CALL trd_dwr( kt )                     ! print the results in ocean.output
-               !                
-               umo(:) = 0._wp                         ! reset for the next time step
-               vmo(:) = 0._wp
-               hke(:) = 0._wp
-               !
-            ENDIF
-            !
-         END SELECT
-         !
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, ztswu, ztswv, z2dx, z2dy )
-      !
-   END SUBROUTINE trd_budget
-
-
-   SUBROUTINE trd_icp_init
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_icp_init  ***
-      !! 
-      !! ** Purpose :   Read the namtrd namelist
-      !!----------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      !!----------------------------------------------------------------------
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'trd_icp_init : integral constraints properties trends'
-         WRITE(numout,*) '~~~~~~~~~~~~~'
-      ENDIF
-
-      ! Total volume at t-points:
-      tvolt = 0._wp
-      DO jk = 1, jpkm1
-         tvolt = SUM( e1e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:) )
-      END DO
-      IF( lk_mpp )   CALL mpp_sum( tvolt )   ! sum over the global domain
-
-      IF(lwp) WRITE(numout,*) '                total ocean volume at T-point   tvolt = ',tvolt
-
-#if  defined key_trddyn
-      ! Initialization of potential to kinetic energy conversion
-      rpktrd = 0._wp
-
-      ! Total volume at u-, v- points:
-      tvolu = 0._wp
-      tvolv = 0._wp
-
-      DO jk = 1, jpk
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               tvolu = tvolu + e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)
-               tvolv = tvolv + e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-      IF( lk_mpp )   CALL mpp_sum( tvolu )   ! sums over the global domain
-      IF( lk_mpp )   CALL mpp_sum( tvolv )
-
-      IF(lwp) THEN
-         WRITE(numout,*) '                total ocean volume at U-point   tvolu = ',tvolu
-         WRITE(numout,*) '                total ocean volume at V-point   tvolv = ',tvolv
-      ENDIF
-#endif
-      !
-   END SUBROUTINE trd_icp_init
-
-
-   SUBROUTINE trd_dwr( kt )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_dwr  ***
-      !! 
-      !! ** Purpose :  write dynamic trends in ocean.output 
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zcof         ! local scalar
-      REAL(wp), POINTER, DIMENSION(:,:,:)  ::  zkx, zky, zkz, zkepe  
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, jpk, zkx, zky, zkz, zkepe )
-
-      ! I. Momentum trends
-      ! -------------------
-
-      IF( MOD( kt, nn_trd ) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
-
-         ! I.1 Conversion potential energy - kinetic energy
-         ! --------------------------------------------------
-         ! c a u t i o n here, trends are computed at kt+1 (now , but after the swap)
-         zkx  (:,:,:) = 0._wp
-         zky  (:,:,:) = 0._wp
-         zkz  (:,:,:) = 0._wp
-         zkepe(:,:,:) = 0._wp
-   
-         CALL eos( tsn, rhd, rhop )       ! now potential and in situ densities
-
-         zcof = 0.5_wp / rau0             ! Density flux at w-point
-         zkz(:,:,1) = 0._wp
-         DO jk = 2, jpk
-            zkz(:,:,jk) = e1e2t(:,:) * wn(:,:,jk) * ( rhop(:,:,jk) + rhop(:,:,jk-1) ) * tmask_i(:,:)
-         END DO
-         
-         zcof   = 0.5_wp / rau0           ! Density flux at u and v-points
-         DO jk = 1, jpkm1
-            DO jj = 1, jpjm1
-               DO ji = 1, jpim1
-                  zkx(ji,jj,jk) = zcof * e2u(ji,jj) * fse3u(ji,jj,jk) * un(ji,jj,jk) * ( rhop(ji,jj,jk) + rhop(ji+1,jj,jk) )
-                  zky(ji,jj,jk) = zcof * e1v(ji,jj) * fse3v(ji,jj,jk) * vn(ji,jj,jk) * ( rhop(ji,jj,jk) + rhop(ji,jj+1,jk) )
-               END DO
-            END DO
-         END DO
-         
-         DO jk = 1, jpkm1                 ! Density flux divergence at t-point
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
-                  zkepe(ji,jj,jk) = - (  zkz(ji,jj,jk) - zkz(ji  ,jj  ,jk+1)               &
-                     &                 + zkx(ji,jj,jk) - zkx(ji-1,jj  ,jk  )               &
-                     &                 + zky(ji,jj,jk) - zky(ji  ,jj-1,jk  )   )           &
-                     &              / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) ) * tmask(ji,jj,jk) * tmask_i(ji,jj)
-               END DO
-            END DO
-         END DO
-
-         ! I.2 Basin averaged kinetic energy trend
-         ! ----------------------------------------
-         peke = 0._wp
-         DO jk = 1, jpkm1
-            peke = peke + SUM( zkepe(:,:,jk) * fsdept(:,:,jk) * e1e2t(:,:) * fse3t(:,:,jk) )
-         END DO
-         peke = grav * peke
-
-         ! I.3 Sums over the global domain
-         ! ---------------------------------
-         IF( lk_mpp ) THEN
-            CALL mpp_sum( peke )
-            CALL mpp_sum( umo , jptot_dyn )
-            CALL mpp_sum( vmo , jptot_dyn )
-            CALL mpp_sum( hke , jptot_dyn )
-         ENDIF
-
-         ! I.2 Print dynamic trends in the ocean.output file
-         ! --------------------------------------------------
-
-         IF(lwp) THEN
-            WRITE (numout,*)
-            WRITE (numout,*)
-            WRITE (numout,9500) kt
-            WRITE (numout,9501) umo(jpdyn_trd_hpg) / tvolu, vmo(jpdyn_trd_hpg) / tvolv
-            WRITE (numout,9509) umo(jpdyn_trd_spg) / tvolu, vmo(jpdyn_trd_spg) / tvolv
-            WRITE (numout,9502) umo(jpdyn_trd_keg) / tvolu, vmo(jpdyn_trd_keg) / tvolv
-            WRITE (numout,9503) umo(jpdyn_trd_rvo) / tvolu, vmo(jpdyn_trd_rvo) / tvolv
-            WRITE (numout,9504) umo(jpdyn_trd_pvo) / tvolu, vmo(jpdyn_trd_pvo) / tvolv
-            WRITE (numout,9507) umo(jpdyn_trd_zad) / tvolu, vmo(jpdyn_trd_zad) / tvolv
-            WRITE (numout,9505) umo(jpdyn_trd_ldf) / tvolu, vmo(jpdyn_trd_ldf) / tvolv
-            WRITE (numout,9508) umo(jpdyn_trd_zdf) / tvolu, vmo(jpdyn_trd_zdf) / tvolv
-            WRITE (numout,9510) umo(jpdyn_trd_tau) / tvolu, vmo(jpdyn_trd_tau) / tvolv
-            WRITE (numout,9511) umo(jpdyn_trd_bfr) / tvolu, vmo(jpdyn_trd_bfr) / tvolv
-            WRITE (numout,9512) umo(jpdyn_trd_atf) / tvolu, vmo(jpdyn_trd_atf) / tvolv
-            WRITE (numout,9513)
-            WRITE (numout,9514)                                                 &
-            &     (  umo(jpdyn_trd_hpg) + umo(jpdyn_trd_spg) + umo(jpdyn_trd_keg) + umo(jpdyn_trd_rvo)   &
-            &      + umo(jpdyn_trd_pvo) + umo(jpdyn_trd_zad) + umo(jpdyn_trd_ldf) + umo(jpdyn_trd_zdf)   &
-            &      + umo(jpdyn_trd_tau) + umo(jpdyn_trd_bfr) + umo(jpdyn_trd_atf) ) / tvolu,   &
-            &     (  vmo(jpdyn_trd_hpg) + vmo(jpdyn_trd_spg) + vmo(jpdyn_trd_keg) + vmo(jpdyn_trd_rvo)   &
-            &      + vmo(jpdyn_trd_pvo) + vmo(jpdyn_trd_zad) + vmo(jpdyn_trd_ldf) + vmo(jpdyn_trd_zdf)   &
-            &      + vmo(jpdyn_trd_tau) + vmo(jpdyn_trd_bfr) + vmo(jpdyn_trd_atf) ) / tvolv
-         ENDIF
-
- 9500    FORMAT(' momentum trend at it= ', i6, ' :', /' ==============================')
- 9501    FORMAT(' pressure gradient          u= ', e20.13, '    v= ', e20.13)
- 9502    FORMAT(' ke gradient                u= ', e20.13, '    v= ', e20.13)
- 9503    FORMAT(' relative vorticity term    u= ', e20.13, '    v= ', e20.13)
- 9504    FORMAT(' coriolis term              u= ', e20.13, '    v= ', e20.13)
- 9505    FORMAT(' horizontal diffusion       u= ', e20.13, '    v= ', e20.13)
- 9507    FORMAT(' vertical advection         u= ', e20.13, '    v= ', e20.13)
- 9508    FORMAT(' vertical diffusion         u= ', e20.13, '    v= ', e20.13)
- 9509    FORMAT(' surface pressure gradient  u= ', e20.13, '    v= ', e20.13)
- 9510    FORMAT(' surface wind stress        u= ', e20.13, '    v= ', e20.13)
- 9511    FORMAT(' bottom friction            u= ', e20.13, '    v= ', e20.13)
- 9512    FORMAT(' Asselin time filter        u= ', e20.13, '    v= ', e20.13)
- 9513    FORMAT(' -----------------------------------------------------------------------------')
- 9514    FORMAT(' total trend                u= ', e20.13, '    v= ', e20.13)
-
-         IF(lwp) THEN
-            WRITE (numout,*)
-            WRITE (numout,*)
-            WRITE (numout,9520) kt
-            WRITE (numout,9521) hke(jpdyn_trd_hpg) / tvolt
-            WRITE (numout,9529) hke(jpdyn_trd_spg) / tvolt
-            WRITE (numout,9522) hke(jpdyn_trd_keg) / tvolt
-            WRITE (numout,9523) hke(jpdyn_trd_rvo) / tvolt
-            WRITE (numout,9524) hke(jpdyn_trd_pvo) / tvolt
-            WRITE (numout,9527) hke(jpdyn_trd_zad) / tvolt
-            WRITE (numout,9525) hke(jpdyn_trd_ldf) / tvolt
-            WRITE (numout,9528) hke(jpdyn_trd_zdf) / tvolt
-            WRITE (numout,9530) hke(jpdyn_trd_tau) / tvolt
-            WRITE (numout,9531) hke(jpdyn_trd_bfr) / tvolt
-            WRITE (numout,9532) hke(jpdyn_trd_atf) / tvolt
-            WRITE (numout,9533)
-            WRITE (numout,9534)   &
-            &     (  hke(jpdyn_trd_hpg) + hke(jpdyn_trd_spg) + hke(jpdyn_trd_keg) + hke(jpdyn_trd_rvo)   &
-            &      + hke(jpdyn_trd_pvo) + hke(jpdyn_trd_zad) + hke(jpdyn_trd_ldf) + hke(jpdyn_trd_zdf)   &
-            &      + hke(jpdyn_trd_tau) + hke(jpdyn_trd_bfr) + hke(jpdyn_trd_atf)  ) / tvolt
-         ENDIF
-
- 9520    FORMAT(' kinetic energy trend at it= ', i6, ' :', /' ====================================')
- 9521    FORMAT(' pressure gradient         u2= ', e20.13)
- 9529    FORMAT(' surface pressure gradient u2= ', e20.13)
- 9522    FORMAT(' ke gradient               u2= ', e20.13)
- 9523    FORMAT(' relative vorticity term   u2= ', e20.13)
- 9524    FORMAT(' coriolis term             u2= ', e20.13)
- 9527    FORMAT(' vertical advection        u2= ', e20.13)
- 9525    FORMAT(' horizontal diffusion      u2= ', e20.13)
- 9528    FORMAT(' vertical diffusion        u2= ', e20.13)
- 9530    FORMAT(' surface wind stress       u2= ', e20.13)
- 9531    FORMAT(' bottom friction           u2= ', e20.13)
- 9532    FORMAT(' Asselin time filter       u2= ', e20.13)
- 9533    FORMAT(' --------------------------------------------------')
- 9534    FORMAT(' total trend               u2= ', e20.13)
-
-         IF(lwp) THEN
-            WRITE (numout,*)
-            WRITE (numout,*)
-            WRITE (numout,9540) kt
-            WRITE (numout,9541) ( hke(jpdyn_trd_keg) + hke(jpdyn_trd_rvo) + hke(jpdyn_trd_zad) ) / tvolt
-            WRITE (numout,9542) ( hke(jpdyn_trd_keg) + hke(jpdyn_trd_zad) ) / tvolt
-            WRITE (numout,9543) ( hke(jpdyn_trd_pvo) ) / tvolt
-            WRITE (numout,9544) ( hke(jpdyn_trd_rvo) ) / tvolt
-            WRITE (numout,9545) ( hke(jpdyn_trd_spg) ) / tvolt
-            WRITE (numout,9546) ( hke(jpdyn_trd_ldf) ) / tvolt
-            WRITE (numout,9547) ( hke(jpdyn_trd_zdf) ) / tvolt
-            WRITE (numout,9548) ( hke(jpdyn_trd_hpg) ) / tvolt, rpktrd / tvolt
-            WRITE (numout,*)
-            WRITE (numout,*)
-         ENDIF
-
- 9540    FORMAT(' energetic consistency at it= ', i6, ' :', /' =========================================')
- 9541    FORMAT(' 0 = non linear term (true if KE conserved)                : ', e20.13)
- 9542    FORMAT(' 0 = ke gradient + vertical advection                      : ', e20.13)
- 9543    FORMAT(' 0 = coriolis term  (true if KE conserving scheme)         : ', e20.13)
- 9544    FORMAT(' 0 = vorticity term (true if KE conserving scheme)         : ', e20.13)
- 9545    FORMAT(' 0 = surface pressure gradient  ???                        : ', e20.13)
- 9546    FORMAT(' 0 < horizontal diffusion                                  : ', e20.13)
- 9547    FORMAT(' 0 < vertical diffusion                                    : ', e20.13)
- 9548    FORMAT(' pressure gradient u2 = - 1/rau0 u.dz(rhop)                : ', e20.13, '  u.dz(rhop) =', e20.13)
-         !
-         ! Save potential to kinetic energy conversion for next time step
-         rpktrd = peke
-         !
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, jpk, zkx, zky, zkz, zkepe )
-      !
-   END SUBROUTINE trd_dwr
-
-
-   SUBROUTINE trd_twr( kt )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_twr  ***
-      !! 
-      !! ** Purpose :  write active tracers trends in ocean.output 
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
-      !
-      INTEGER  ::   jk   ! loop indices
-      !!----------------------------------------------------------------------
-
-      ! I. Tracers trends
-      ! -----------------
-
-      IF( MOD(kt,nn_trd) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
-
-         ! I.1 Sums over the global domain
-         ! -------------------------------
-         IF( lk_mpp ) THEN
-            CALL mpp_sum( tmo, jptot_tra )   
-            CALL mpp_sum( smo, jptot_tra )
-            CALL mpp_sum( t2 , jptot_tra )
-            CALL mpp_sum( s2 , jptot_tra )
-         ENDIF
-
-         ! I.2 Print tracers trends in the ocean.output file
-         ! --------------------------------------------------
-         
-         IF(lwp) THEN
-            WRITE (numout,*)
-            WRITE (numout,*)
-            WRITE (numout,9400) kt
-            WRITE (numout,9401)  tmo(jptra_trd_xad) / tvolt, smo(jptra_trd_xad) / tvolt
-            WRITE (numout,9411)  tmo(jptra_trd_yad) / tvolt, smo(jptra_trd_yad) / tvolt
-            WRITE (numout,9402)  tmo(jptra_trd_zad) / tvolt, smo(jptra_trd_zad) / tvolt
-            WRITE (numout,9403)  tmo(jptra_trd_ldf) / tvolt, smo(jptra_trd_ldf) / tvolt
-            WRITE (numout,9404)  tmo(jptra_trd_zdf) / tvolt, smo(jptra_trd_zdf) / tvolt
-            WRITE (numout,9405)  tmo(jptra_trd_npc) / tvolt, smo(jptra_trd_npc) / tvolt
-            WRITE (numout,9406)  tmo(jptra_trd_dmp) / tvolt, smo(jptra_trd_dmp) / tvolt
-            WRITE (numout,9407)  tmo(jptra_trd_qsr) / tvolt
-            WRITE (numout,9408)  tmo(jptra_trd_nsr) / tvolt, smo(jptra_trd_nsr) / tvolt
-            WRITE (numout,9409) 
-            WRITE (numout,9410) (  tmo(jptra_trd_xad) + tmo(jptra_trd_yad) + tmo(jptra_trd_zad) + tmo(jptra_trd_ldf) + tmo(jptra_trd_zdf)   &
-            &                    + tmo(jptra_trd_npc) + tmo(jptra_trd_dmp) + tmo(jptra_trd_qsr) + tmo(jptra_trd_nsr) ) / tvolt,   &
-            &                   (  smo(jptra_trd_xad) + smo(jptra_trd_yad) + smo(jptra_trd_zad) + smo(jptra_trd_ldf) + smo(jptra_trd_zdf)   &
-            &                    + smo(jptra_trd_npc) + smo(jptra_trd_dmp)                   + smo(jptra_trd_nsr) ) / tvolt
-         ENDIF
-
-9400     FORMAT(' tracer trend at it= ',i6,' :     temperature',   &
-              '              salinity',/' ============================')
-9401     FORMAT(' zonal      advection        ',e20.13,'     ',e20.13)
-9411     FORMAT(' meridional advection        ',e20.13,'     ',e20.13)
-9402     FORMAT(' vertical advection          ',e20.13,'     ',e20.13)
-9403     FORMAT(' horizontal diffusion        ',e20.13,'     ',e20.13)
-9404     FORMAT(' vertical diffusion          ',e20.13,'     ',e20.13)
-9405     FORMAT(' static instability mixing   ',e20.13,'     ',e20.13)
-9406     FORMAT(' damping term                ',e20.13,'     ',e20.13)
-9407     FORMAT(' penetrative qsr             ',e20.13)
-9408     FORMAT(' non solar radiation         ',e20.13,'     ',e20.13)
-9409     FORMAT(' -------------------------------------------------------------------------')
-9410     FORMAT(' total trend                 ',e20.13,'     ',e20.13)
-
-
-         IF(lwp) THEN
-            WRITE (numout,*)
-            WRITE (numout,*)
-            WRITE (numout,9420) kt
-            WRITE (numout,9421)   t2(jptra_trd_xad) / tvolt, s2(jptra_trd_xad) / tvolt
-            WRITE (numout,9431)   t2(jptra_trd_yad) / tvolt, s2(jptra_trd_yad) / tvolt
-            WRITE (numout,9422)   t2(jptra_trd_zad) / tvolt, s2(jptra_trd_zad) / tvolt
-            WRITE (numout,9423)   t2(jptra_trd_ldf) / tvolt, s2(jptra_trd_ldf) / tvolt
-            WRITE (numout,9424)   t2(jptra_trd_zdf) / tvolt, s2(jptra_trd_zdf) / tvolt
-            WRITE (numout,9425)   t2(jptra_trd_npc) / tvolt, s2(jptra_trd_npc) / tvolt
-            WRITE (numout,9426)   t2(jptra_trd_dmp) / tvolt, s2(jptra_trd_dmp) / tvolt
-            WRITE (numout,9427)   t2(jptra_trd_qsr) / tvolt
-            WRITE (numout,9428)   t2(jptra_trd_nsr) / tvolt, s2(jptra_trd_nsr) / tvolt
-            WRITE (numout,9429)
-            WRITE (numout,9430) (  t2(jptra_trd_xad) + t2(jptra_trd_yad) + t2(jptra_trd_zad) + t2(jptra_trd_ldf) + t2(jptra_trd_zdf)   &
-            &                    + t2(jptra_trd_npc) + t2(jptra_trd_dmp) + t2(jptra_trd_qsr) + t2(jptra_trd_nsr) ) / tvolt,   &
-            &                   (  s2(jptra_trd_xad) + s2(jptra_trd_yad) + s2(jptra_trd_zad) + s2(jptra_trd_ldf) + s2(jptra_trd_zdf)   &
-            &                    + s2(jptra_trd_npc) + s2(jptra_trd_dmp)                  + s2(jptra_trd_nsr) ) / tvolt
-         ENDIF
-
-9420     FORMAT(' tracer**2 trend at it= ', i6, ' :      temperature',   &
-            '               salinity', /, ' ===============================')
-9421     FORMAT(' zonal      advection      * t   ', e20.13, '     ', e20.13)
-9431     FORMAT(' meridional advection      * t   ', e20.13, '     ', e20.13)
-9422     FORMAT(' vertical advection        * t   ', e20.13, '     ', e20.13)
-9423     FORMAT(' horizontal diffusion      * t   ', e20.13, '     ', e20.13)
-9424     FORMAT(' vertical diffusion        * t   ', e20.13, '     ', e20.13)
-9425     FORMAT(' static instability mixing * t   ', e20.13, '     ', e20.13)
-9426     FORMAT(' damping term              * t   ', e20.13, '     ', e20.13)
-9427     FORMAT(' penetrative qsr           * t   ', e20.13)
-9428     FORMAT(' non solar radiation       * t   ', e20.13, '     ', e20.13)
-9429     FORMAT(' -----------------------------------------------------------------------------')
-9430     FORMAT(' total trend                *t = ', e20.13, '  *s = ', e20.13)
-
-
-         IF(lwp) THEN
-            WRITE (numout,*)
-            WRITE (numout,*)
-            WRITE (numout,9440) kt
-            WRITE (numout,9441) ( tmo(jptra_trd_xad)+tmo(jptra_trd_yad)+tmo(jptra_trd_zad) )/tvolt,   &
-            &                   ( smo(jptra_trd_xad)+smo(jptra_trd_yad)+smo(jptra_trd_zad) )/tvolt
-            WRITE (numout,9442)   tmo(jptra_trd_sad)/tvolt,  smo(jptra_trd_sad)/tvolt
-            WRITE (numout,9443)   tmo(jptra_trd_ldf)/tvolt,  smo(jptra_trd_ldf)/tvolt
-            WRITE (numout,9444)   tmo(jptra_trd_zdf)/tvolt,  smo(jptra_trd_zdf)/tvolt
-            WRITE (numout,9445)   tmo(jptra_trd_npc)/tvolt,  smo(jptra_trd_npc)/tvolt
-            WRITE (numout,9446) ( t2(jptra_trd_xad)+t2(jptra_trd_yad)+t2(jptra_trd_zad) )/tvolt,    &
-            &                   ( s2(jptra_trd_xad)+s2(jptra_trd_yad)+s2(jptra_trd_zad) )/tvolt
-            WRITE (numout,9447)   t2(jptra_trd_ldf)/tvolt,   s2(jptra_trd_ldf)/tvolt
-            WRITE (numout,9448)   t2(jptra_trd_zdf)/tvolt,   s2(jptra_trd_zdf)/tvolt
-            WRITE (numout,9449)   t2(jptra_trd_npc)/tvolt,   s2(jptra_trd_npc)/tvolt
-         ENDIF
-
-9440     FORMAT(' tracer consistency at it= ',i6,   &
-            ' :         temperature','                salinity',/,   &
-            ' ==================================')
-9441     FORMAT(' 0 = horizontal+vertical advection +    ',e20.13,'       ',e20.13)
-9442     FORMAT('     1st lev vertical advection         ',e20.13,'       ',e20.13)
-9443     FORMAT(' 0 = horizontal diffusion               ',e20.13,'       ',e20.13)
-9444     FORMAT(' 0 = vertical diffusion                 ',e20.13,'       ',e20.13)
-9445     FORMAT(' 0 = static instability mixing          ',e20.13,'       ',e20.13)
-9446     FORMAT(' 0 = horizontal+vertical advection * t  ',e20.13,'       ',e20.13)
-9447     FORMAT(' 0 > horizontal diffusion          * t  ',e20.13,'       ',e20.13)
-9448     FORMAT(' 0 > vertical diffusion            * t  ',e20.13,'       ',e20.13)
-9449     FORMAT(' 0 > static instability mixing     * t  ',e20.13,'       ',e20.13)
-         !
-      ENDIF
-      !
-   END SUBROUTINE trd_twr
-
-   !!======================================================================
-END MODULE trdicp
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdini.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdini.F90	(revision 3318)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdini.F90	(revision 3318)
@@ -0,0 +1,96 @@
+MODULE trdini
+   !!======================================================================
+   !!                       ***  MODULE  trdini  ***
+   !! Ocean diagnostics:  ocean tracers and dynamic trends
+   !!=====================================================================
+   !! History :   3.5  !  2012-02  (G. Madec) add 3D trends output for T, S, U, V, PE and KE
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   trd_init      : initialization step
+   !!----------------------------------------------------------------------
+   USE trd_oce        ! trends: ocean variables
+!   USE ldftra_oce     ! ocean active tracers lateral physics
+   USE trdglo         ! ocean bassin integral constraints properties
+   USE trdmld         ! ocean active mixed layer tracers trends 
+   USE trdvor         ! ocean vorticity trends 
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trd_init   ! called by nemogcm.F90 module
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trd_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_init  ***
+      !! 
+      !! ** Purpose :   Initialization of trend diagnostics
+      !!----------------------------------------------------------------------
+      NAMELIST/namtrd/ ln_dyn_trd, ln_KE_trd, ln_vor_trd, ln_dyn_mld,   &
+         &             ln_tra_trd, ln_PE_trd, ln_glo_trd, ln_tra_mld,   &
+         &             nn_trd , cn_trdrst_in , ln_trdmld_restart,       &
+         &             nn_ctls, cn_trdrst_out, ln_trdmld_instant, rn_ucf
+      !!----------------------------------------------------------------------
+
+      REWIND( numnam )
+      READ  ( numnam, namtrd )      ! namelist namtrd : trends diagnostic
+
+      IF(lwp) THEN                  ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) ' trd_init : Momentum/Tracers trends'
+         WRITE(numout,*) ' ~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namtrd : set trends parameters'
+         WRITE(numout,*) '      global domain averaged dyn & tra trends        ln_glo_trd  = ', ln_glo_trd
+         WRITE(numout,*) '      U & V trends: 3D output                        ln_dyn_trd  = ', ln_dyn_trd
+         WRITE(numout,*) '      U & V trends: Mixed Layer averaged             ln_dyn_mld  = ', ln_dyn_mld
+         WRITE(numout,*) '      T & S trends: 3D output                        ln_tra_trd  = ', ln_tra_trd
+         WRITE(numout,*) '      T & S trends: Mixed Layer averaged             ln_tra_mld  = ', ln_tra_mld
+         WRITE(numout,*) '      Kinetic   Energy trends                        ln_KE_trd   = ', ln_KE_trd
+         WRITE(numout,*) '      Potential Energy trends                        ln_PE_trd   = ', ln_PE_trd
+         WRITE(numout,*) '      Barotropic vorticity trends                    ln_vor_trd  = ', ln_vor_trd
+         !
+         WRITE(numout,*) '      frequency of trends diagnostics (glo)   nn_trd             = ', nn_trd
+         WRITE(numout,*) '      control surface type            (mld)   nn_ctls            = ', nn_ctls
+         WRITE(numout,*) '      restart for ML diagnostics              ln_trdmld_restart  = ', ln_trdmld_restart
+         WRITE(numout,*) '      instantaneous or mean ML T/S            ln_trdmld_instant  = ', ln_trdmld_instant
+         WRITE(numout,*) '      unit conversion factor                  rn_ucf             = ', rn_ucf
+      ENDIF
+      !
+      !                             ! trend extraction flags  
+      l_trdtra = .FALSE.                                                       ! tracers  
+      IF ( ln_tra_trd .OR. ln_PE_trd .OR. ln_tra_mld .OR.   &
+         & ln_glo_trd                                       )   l_trdtra = .TRUE. 
+      !
+      l_trddyn = .FALSE.                                                       ! momentum
+      IF ( ln_dyn_trd .OR. ln_KE_trd .OR. ln_dyn_mld .OR.   &
+         & ln_vor_trd .OR. ln_glo_trd                       )   l_trddyn = .TRUE.
+      !
+      
+      IF( ln_KE_trd .OR. ln_PE_trd .OR. ln_dyn_mld )   &
+         CALL ctl_stop( 'KE, PE, aur ML on momentum are not yet coded we stop' )
+
+      !
+      IF( ln_glo_trd )    CALL trd_glo_init       ! integral constraints trends
+      IF( ln_tra_mld )    CALL trd_mld_init       ! mixed-layer trends (active  tracers)  
+      IF( ln_vor_trd )    CALL trd_vor_init       ! vorticity trends        
+      !
+!!gm  : Potential BUG : 3D output only for vector invariant form!  add a ctl_stop or code the flux form case
+!!gm  : bug/pb for vertical advection of tracer in vvl case: add T.dt[eta] in the output... 
+      !
+      !
+   END SUBROUTINE trd_init
+
+   !!======================================================================
+END MODULE trdini
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld.F90	(revision 3318)
@@ -11,7 +11,5 @@
    !!                 !  05-05  (C. Deltel)     Diagnose trends of time averaged ML T & S
    !!----------------------------------------------------------------------
-#if   defined key_trdmld   ||   defined key_esopa
-   !!----------------------------------------------------------------------
-   !!   'key_trdmld'                          mixed layer trend diagnostics
+
    !!----------------------------------------------------------------------
    !!   trd_mld          : T and S cumulated trends averaged over the mixed layer
@@ -21,5 +19,5 @@
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain variables
-   USE trdmod_oce      ! ocean variables trends
+   USE trd_oce         ! trends: ocean variables
    USE trdmld_oce      ! ocean variables trends
    USE ldftra_oce      ! ocean active tracers lateral physics
@@ -94,5 +92,4 @@
       !!            surface and the control surface is called "mixed-layer"
       !!----------------------------------------------------------------------
-      !
       INTEGER                         , INTENT( in ) ::   ktrd       ! ocean trend index
       CHARACTER(len=2)                , INTENT( in ) ::   ctype      ! 2D surface/bottom or 3D interior physics
@@ -112,12 +109,12 @@
       IF( icount == 1 ) THEN        
          !
-         tmltrd(:,:,:) = 0.e0    ;    smltrd(:,:,:) = 0.e0    ! <<< reset trend arrays to zero
+         tmltrd(:,:,:) = 0._wp    ;    smltrd(:,:,:) = 0._wp    ! <<< reset trend arrays to zero
          
          ! ... Set nmld(ji,jj) = index of first T point below control surf. or outside mixed-layer
          IF( nn_ctls == 0 ) THEN       ! * control surface = mixed-layer with density criterion 
             nmld(:,:) = nmln(:,:)    ! array nmln computed in zdfmxl.F90
-         ELSE IF( nn_ctls == 1 ) THEN  ! * control surface = read index from file 
+         ELSEIF( nn_ctls == 1 ) THEN   ! * control surface = read index from file 
             nmld(:,:) = nbol(:,:)
-         ELSE IF( nn_ctls >= 2 ) THEN  ! * control surface = model level
+         ELSEIF( nn_ctls >= 2 ) THEN   ! * control surface = model level
             nn_ctls = MIN( nn_ctls, jpktrd - 1 )
             nmld(:,:) = nn_ctls + 1
@@ -129,5 +126,5 @@
             ! Check of validity : nmld(ji,jj) <= jpktrd
             isum        = 0
-            zvlmsk(:,:) = 0.e0
+            zvlmsk(:,:) = 0._wp
 
             IF( jpktrd < jpk ) THEN 
@@ -138,5 +135,5 @@
                      ELSE
                         isum = isum + 1
-                        zvlmsk(ji,jj) = 0.
+                        zvlmsk(ji,jj) = 0._wp
                      ENDIF
                   END DO
@@ -157,5 +154,5 @@
          
          ! ... Weights for vertical averaging
-         wkx(:,:,:) = 0.e0
+         wkx(:,:,:) = 0._wp
          DO jk = 1, jpktrd             ! initialize wkx with vertical scale factor in mixed-layer
             DO jj = 1,jpj
@@ -166,5 +163,5 @@
          END DO
          
-         rmld(:,:) = 0.e0                ! compute mixed-layer depth : rmld
+         rmld(:,:) = 0._wp               ! compute mixed-layer depth : rmld
          DO jk = 1, jpktrd
             rmld(:,:) = rmld(:,:) + wkx(:,:,jk)
@@ -172,5 +169,5 @@
          
          DO jk = 1, jpktrd             ! compute integration weights
-            wkx(:,:,jk) = wkx(:,:,jk) / MAX( 1., rmld(:,:) )
+            wkx(:,:,jk) = wkx(:,:,jk) / MAX( 1._wp, rmld(:,:) )
          END DO
 
@@ -241,9 +238,6 @@
       !!       In IV), the appropriate trends are written in the trends NetCDF file.
       !!
-      !! References :
-      !!       - Vialard & al.
-      !!       - See NEMO documentation (in preparation)
-      !!----------------------------------------------------------------------
-      !
+      !! References :  Vialard et al.,2001, JPO.
+      !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
       !
@@ -761,5 +755,5 @@
       ! -------------------------------------------------
 
-      IF( ( lk_trdmld ) .AND. ( MOD( nitend, nn_trd ) /= 0 ) ) THEN
+      IF( MOD( nitend, nn_trd ) /= 0 ) THEN
          WRITE(numout,cform_err)
          WRITE(numout,*) '                Your nitend parameter, nitend = ', nitend
@@ -774,10 +768,6 @@
       END IF
 
-      IF( ( lk_trdmld ) .AND. ( nn_cla == 1 ) ) THEN
-         WRITE(numout,cform_war)
-         WRITE(numout,*) '                You set n_cla = 1. Note that the Mixed-Layer diagnostics  '
-         WRITE(numout,*) '                are not exact along the corresponding straits.            '
-         nwarn = nwarn + 1
-      END IF
+      IF( nn_cla == 1 )   CALL ctl_warn( '      You set n_cla = 1. Note that the Mixed-Layer diagnostics  ',   &
+         &                               '      are not exact along the corresponding straits.            ')
 
       !                                   ! allocate trdmld arrays
@@ -951,30 +941,4 @@
    END SUBROUTINE trd_mld_init
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                       Empty module
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE trd_mld( kt )             ! Empty routine
-      INTEGER, INTENT( in) ::   kt
-      WRITE(*,*) 'trd_mld: You should not have seen this print! error?', kt
-   END SUBROUTINE trd_mld
-   SUBROUTINE trd_mld_zint( pttrdmld, pstrdmld, ktrd, ctype )
-      REAL, DIMENSION(:,:,:), INTENT( in ) ::   &
-         pttrdmld, pstrdmld                   ! Temperature and Salinity trends
-      INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
-      CHARACTER(len=2), INTENT( in ) ::   &  
-         ctype                                ! surface/bottom (2D arrays) or
-         !                                    ! interior (3D arrays) physics
-      WRITE(*,*) 'trd_mld_zint: You should not have seen this print! error?', pttrdmld(1,1,1)
-      WRITE(*,*) '  "      "  : You should not have seen this print! error?', pstrdmld(1,1,1)
-      WRITE(*,*) '  "      "  : You should not have seen this print! error?', ctype
-      WRITE(*,*) '  "      "  : You should not have seen this print! error?', ktrd
-   END SUBROUTINE trd_mld_zint
-   SUBROUTINE trd_mld_init              ! Empty routine
-      WRITE(*,*) 'trd_mld_init: You should not have seen this print! error?'
-   END SUBROUTINE trd_mld_init
-#endif
-
    !!======================================================================
 END MODULE trdmld
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld_oce.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld_oce.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld_oce.F90	(revision 3318)
@@ -5,4 +5,5 @@
    !!======================================================================
    !! History :  1.0  ! 2004-08  (C. Talandier)  New trends organization
+   !!            3.5  ! 2012-02  (G. Madec) suppress the trend keys
    !!----------------------------------------------------------------------
    USE par_oce        ! ocean parameters
@@ -13,11 +14,6 @@
    PUBLIC   trdmld_oce_alloc    ! Called in trdmld.F90
 
-#if defined key_trdmld
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trdmld = .TRUE.    !: ML trend flag
-#else
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trdmld = .FALSE.   !: ML trend flag
-#endif
-   !!* mixed layer trends indices
-   INTEGER, PARAMETER, PUBLIC ::   jpltrd = 11      !: number of mixed-layer trends arrays
+   !                                                !* mixed layer trend indices
+   INTEGER, PUBLIC, PARAMETER ::   jpltrd = 11      !: number of mixed-layer trends arrays
    INTEGER, PUBLIC            ::   jpktrd           !: max level for mixed-layer trends diag.
    !
@@ -35,8 +31,4 @@
    INTEGER, PUBLIC, PARAMETER ::   jpmld_atf = 11   !:  asselin trend (**MUST BE THE LAST ONE**)
 
-#if   defined  key_trdmld   ||   defined key_esopa
-   !!----------------------------------------------------------------------
-   !!   'key_trdmld'                         mixed layer trends diagnostics
-   !!----------------------------------------------------------------------
 
    !! Arrays used for diagnosing mixed-layer trends 
@@ -79,5 +71,5 @@
       smltrd_csum_ln,               & !:    ( idem for salinity )
       smltrd_csum_ub                  !: 
-#endif
+
    !!----------------------------------------------------------------------
    !! NEMO/OPA 4.0 , NEMO Consortium (2011)
@@ -101,5 +93,4 @@
      ierr(:) = 0
 
-#if   defined  key_trdmld   ||   defined key_esopa
      ALLOCATE( nmld(jpi,jpj), nbol(jpi,jpj),       &
         &      wkx(jpi,jpj,jpk), rmld(jpi,jpj),    & 
@@ -125,5 +116,4 @@
         &      tmltrd_csum_ub(jpi,jpj,jpltrd), smltrd_sum(jpi,jpj,jpltrd),     &
         &      smltrd_csum_ln(jpi,jpj,jpltrd), smltrd_csum_ub(jpi,jpj,jpltrd), STAT=ierr(5) )
-#endif
       !
       trdmld_oce_alloc = MAXVAL( ierr )
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld_rst.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld_rst.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld_rst.F90	(revision 3318)
@@ -4,10 +4,13 @@
    !! Ocean dynamic :  Input/Output files for restart on mixed-layer diagnostics
    !!=================================================================================
-   !! History :  9.0  ! 05-05 (C. Deltel) Original code
+   !! History :  1.0  ! 2005-05 (C. Deltel)  Original code
    !!---------------------------------------------------------------------------------
-#if defined key_trdmld
+
+   !!---------------------------------------------------------------------------------
+   !!  trd_mld_rst_write : write mixed layer trend restart
+   !!  trd_mld_rst_read  : read  mixed layer trend restart
    !!---------------------------------------------------------------------------------
    USE dom_oce         ! ocean space and time domain
-   USE trdmod_oce      ! ocean variables for trend diagnostics (i.e. icp/mixed-layer/vorticity)
+   USE trd_oce         ! trends: ocean variables
    USE in_out_manager  ! I/O manager
    USE iom             ! I/O module
@@ -27,5 +30,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!---------------------------------------------------------------------------------
-  
 CONTAINS
   
@@ -92,6 +94,6 @@
          CALL iom_rstput( kt, nitrst, nummldw, 'tml_sumb'        , tml_sumb        )
          DO jk = 1, jpltrd
-            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I1)") jk
-            ELSE                 ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I2)") jk
+            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I1)")   jk
+            ELSE                 ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I2)")   jk
             ENDIF
             CALL iom_rstput( kt, nitrst, nummldw, charout,  tmltrd_csum_ub(:,:,jk) )
@@ -103,6 +105,6 @@
          CALL iom_rstput( kt, nitrst, nummldw, 'sml_sumb'        , sml_sumb        )
          DO jk = 1, jpltrd
-            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('smltrd_csum_ub_', I1)") jk
-            ELSE                 ;   WRITE(charout,FMT="('smltrd_csum_ub_', I2)") jk
+            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('smltrd_csum_ub_', I1)")   jk
+            ELSE                 ;   WRITE(charout,FMT="('smltrd_csum_ub_', I2)")   jk
             ENDIF
             CALL iom_rstput( kt, nitrst, nummldw, charout , smltrd_csum_ub(:,:,jk) )
@@ -116,93 +118,77 @@
       ENDIF
       ! 
-      !    
    END SUBROUTINE trd_mld_rst_write
 
 
    SUBROUTINE trd_mld_rst_read
-    !!----------------------------------------------------------------------------
-    !!                   ***  SUBROUTINE trd_mld_rst_lec  ***
-    !!                   
-    !! ** Purpose :   Read file for mixed-layer diagnostics restart.
-    !!----------------------------------------------------------------------------
-    INTEGER  ::  inum       ! temporary logical unit
-    !
-    CHARACTER (len=35) :: charout
-    INTEGER ::   jk         ! loop indice
-    INTEGER ::   jlibalt = jprstlib
-    LOGICAL ::   llok
-    !!-----------------------------------------------------------------------------
+      !!----------------------------------------------------------------------------
+      !!                   ***  SUBROUTINE trd_mld_rst_lec  ***
+      !!                   
+      !! ** Purpose :   Read file for mixed-layer diagnostics restart.
+      !!----------------------------------------------------------------------------
+      INTEGER  ::  inum       ! temporary logical unit
+      !
+      CHARACTER (len=35) :: charout
+      INTEGER ::   jk         ! loop indice
+      INTEGER ::   jlibalt = jprstlib
+      LOGICAL ::   llok
+      !!-----------------------------------------------------------------------------
 
-    IF(lwp)  THEN
-       WRITE(numout,*)
-       WRITE(numout,*) ' trd_mld_rst_read : read the NetCDF MLD restart file'
-       WRITE(numout,*) ' ~~~~~~~~~~~~~~~~'
-    ENDIF
-    IF ( jprstlib == jprstdimg ) THEN
-       ! eventually read netcdf file (monobloc)  for restarting on different number of processors
-       ! if {cn_trdrst_in}.nc exists, then set jlibalt to jpnf90
-       INQUIRE( FILE = TRIM(cn_trdrst_in)//'.nc', EXIST = llok )
-       IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
-    ENDIF
+      IF(lwp)  THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' trd_mld_rst_read : read the NetCDF MLD restart file'
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~'
+      ENDIF
+      IF ( jprstlib == jprstdimg ) THEN
+         ! eventually read netcdf file (monobloc)  for restarting on different number of processors
+         ! if {cn_trdrst_in}.nc exists, then set jlibalt to jpnf90
+         INQUIRE( FILE = TRIM(cn_trdrst_in)//'.nc', EXIST = llok )
+         IF ( llok ) THEN   ;   jlibalt = jpnf90   
+         ELSE               ;   jlibalt = jprstlib   
+         ENDIF
+      ENDIF
 
-    CALL iom_open( cn_trdrst_in, inum, kiolib = jlibalt ) 
+      CALL iom_open( cn_trdrst_in, inum, kiolib = jlibalt ) 
 
-    IF( ln_trdmld_instant ) THEN 
-       !-- Temperature
-       CALL iom_get( inum, jpdom_autoglo, 'tmlbb'           , tmlbb          )
-       CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn          )
-       CALL iom_get( inum, jpdom_autoglo, 'tmlatfb'         , tmlatfb        )
-
-       !-- Salinity
-       CALL iom_get( inum, jpdom_autoglo, 'smlbb'           , smlbb          )
-       CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn          )
-       CALL iom_get( inum, jpdom_autoglo, 'smlatfb'         , smlatfb        )
-    ELSE
-       CALL iom_get( inum, jpdom_autoglo, 'rmldbn'          , rmldbn         ) ! needed for rmld_sum
-
-       !-- Temperature
-       CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn          ) ! needed for tml_sum
-       CALL iom_get( inum, jpdom_autoglo, 'tml_sumb'        , tml_sumb       )
-       DO jk = 1, jpltrd
-          IF( jk < 10 )   THEN
-             WRITE(charout,FMT="('tmltrd_csum_ub_', I1)") jk
-          ELSE
-             WRITE(charout,FMT="('tmltrd_csum_ub_', I2)") jk
-          ENDIF
-          CALL iom_get( inum, jpdom_autoglo, charout, tmltrd_csum_ub(:,:,jk) )
-       ENDDO
-       CALL iom_get( inum, jpdom_autoglo, 'tmltrd_atf_sumb' , tmltrd_atf_sumb)
-
-       !-- Salinity
-       CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn          ) ! needed for sml_sum
-       CALL iom_get( inum, jpdom_autoglo, 'sml_sumb'        , sml_sumb       )
-       DO jk = 1, jpltrd
-          IF( jk < 10 )   THEN
-             WRITE(charout,FMT="('smltrd_csum_ub_', I1)") jk
-          ELSE
-             WRITE(charout,FMT="('smltrd_csum_ub_', I2)") jk
-          ENDIF
-          CALL iom_get( inum, jpdom_autoglo, charout, smltrd_csum_ub(:,:,jk) )
-       ENDDO
-       CALL iom_get( inum, jpdom_autoglo, 'smltrd_atf_sumb' , smltrd_atf_sumb)
-
-       CALL iom_close( inum )
-    ENDIF
-
-  END SUBROUTINE trd_mld_rst_read
+      IF( ln_trdmld_instant ) THEN 
+         !-- Temperature
+         CALL iom_get( inum, jpdom_autoglo, 'tmlbb'           , tmlbb          )
+         CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn          )
+         CALL iom_get( inum, jpdom_autoglo, 'tmlatfb'         , tmlatfb        )
+         !
+         !-- Salinity
+         CALL iom_get( inum, jpdom_autoglo, 'smlbb'           , smlbb          )
+         CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn          )
+         CALL iom_get( inum, jpdom_autoglo, 'smlatfb'         , smlatfb        )
+      ELSE
+         CALL iom_get( inum, jpdom_autoglo, 'rmldbn'          , rmldbn         ) ! needed for rmld_sum
+         !
+         !-- Temperature
+         CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn          ) ! needed for tml_sum
+         CALL iom_get( inum, jpdom_autoglo, 'tml_sumb'        , tml_sumb       )
+         DO jk = 1, jpltrd
+            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I1)")   jk
+            ELSE                 ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I2)")   jk
+            ENDIF
+            CALL iom_get( inum, jpdom_autoglo, charout, tmltrd_csum_ub(:,:,jk) )
+         END DO
+         CALL iom_get( inum, jpdom_autoglo, 'tmltrd_atf_sumb' , tmltrd_atf_sumb)
+         !
+         !-- Salinity
+         CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn          ) ! needed for sml_sum
+         CALL iom_get( inum, jpdom_autoglo, 'sml_sumb'        , sml_sumb       )
+         DO jk = 1, jpltrd
+            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('smltrd_csum_ub_', I1)")   jk
+            ELSE                 ;   WRITE(charout,FMT="('smltrd_csum_ub_', I2)")   jk
+            ENDIF
+            CALL iom_get( inum, jpdom_autoglo, charout, smltrd_csum_ub(:,:,jk) )
+         END DO
+         CALL iom_get( inum, jpdom_autoglo, 'smltrd_atf_sumb' , smltrd_atf_sumb)
+         !
+         CALL iom_close( inum )
+      ENDIF
+      !
+   END SUBROUTINE trd_mld_rst_read
   
-#else
-  !!=================================================================================
-  !!                       ***  MODULE  trdmld_rst  ***
-  !! Ocean dynamic :  Input/Output files for restart on mixed-layer diagnostics
-  !!=================================================================================
-CONTAINS
-  SUBROUTINE trd_mld_rst_write( kt )           !  No ML diags ==> empty routine
-    WRITE(*,*) 'trd_mld_rst_wri: You should not have seen this print! error?', kt
-  END SUBROUTINE trd_mld_rst_write
-  SUBROUTINE trd_mld_rst_read                  !  No ML Diags ==> empty routine
-  END SUBROUTINE trd_mld_rst_read
-#endif
-
   !!=================================================================================
 END MODULE trdmld_rst
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod.F90	(revision 3317)
+++ 	(revision )
@@ -1,355 +1,0 @@
-MODULE trdmod
-   !!======================================================================
-   !!                       ***  MODULE  trdmod  ***
-   !! Ocean diagnostics:  ocean tracers and dynamic trends
-   !!=====================================================================
-   !! History :  1.0  !  2004-08  (C. Talandier) Original code
-   !!             -   !  2005-04  (C. Deltel)    Add Asselin trend in the ML budget
-   !!            3.3  !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
-   !!            3.5  !  2012-02  (G. Madec) add 3D trends output for T, S, U, V, PE and KE
-   !!----------------------------------------------------------------------
-#if  defined key_trdtra || defined key_trddyn || defined key_trdmld || defined key_trdvor || defined key_esopa
-   !!----------------------------------------------------------------------
-   !!   trd_mod       : manage the type of trend diagnostics
-   !!   trd_3Diom     : output 3D momentum and/or tracer trends using IOM
-   !!   trd_mod_init  : Initialization step
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers variables
-   USE dom_oce        ! ocean space and time domain variables
-   USE zdf_oce        ! ocean vertical physics variables
-   USE trdmod_oce     ! ocean variables trends
-   USE zdfbfr         ! bottom friction
-   USE ldftra_oce     ! ocean active tracers lateral physics
-   USE sbc_oce        ! surface boundary condition: ocean
-   USE phycst         ! physical constants
-   USE trdvor         ! ocean vorticity trends 
-   USE trdicp         ! ocean bassin integral constraints properties
-   USE trdmld         ! ocean active mixed layer tracers trends 
-   USE in_out_manager ! I/O manager
-   USE iom            ! I/O manager library
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory allocation
-
-   IMPLICIT NONE
-   PRIVATE
-
-   REAL(wp) ::   r2dt          ! time-step, = 2 rdttra except at nit000 (=rdttra) if neuler=0
-
-   PUBLIC trd_mod              ! called by all dynXX or traXX modules
-   PUBLIC trd_mod_init         ! called by opa.F90 module
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE trd_mod( ptrdx, ptrdy, ktrd, ctype, kt )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mod  ***
-      !! 
-      !! ** Purpose :   Dispatch all trends computation, e.g. 3D output, integral
-      !!                constraints, barotropic vorticity, kinetic enrgy, 
-      !!                potential energy, and/or mixed layer budget.
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend 
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
-      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
-      CHARACTER(len=3)          , INTENT(in   ) ::   ctype   ! momentum or tracers trends type 'DYN'/'TRA'
-      INTEGER                   , INTENT(in   ) ::   kt      ! time step
-      !!
-      INTEGER ::   ji, jj   ! dummy loop indices
-      REAL(wp), POINTER, DIMENSION(:,:) ::   ztswu, ztswv    ! 2D workspace 
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, ztswu, ztswv )
-
-      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdtra (restart with Euler time stepping)
-      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdttra (leapfrog)
-      ENDIF
-
-      !                                            !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_3D_trd_d .OR. ln_3D_trd_t ) THEN      !   3D output of momentum and/or tracers trends using IOM interface
-         !                                         !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-         CALL trd_3Diom ( ptrdx, ptrdy, ktrd, ctype, kt )
-         !
-      ENDIF
-         !                                         !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_glo_trd ) THEN                        ! I. Integral Constraints Properties for momentum and/or tracers trends
-         !                                         !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-         CALL trd_budget( ptrdx, ptrdy, ktrd, ctype, kt )
-         !
-      ENDIF
-
-      !                                            !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( lk_trdvor .AND. ctype == 'DYN' ) THEN    ! II. Vorticity trends
-         !                                         !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-         SELECT CASE( ktrd ) 
-         CASE( jpdyn_trd_hpg )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_prg )   ! Hydrostatique Pressure Gradient 
-         CASE( jpdyn_trd_keg )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_keg )   ! KE Gradient 
-         CASE( jpdyn_trd_rvo )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_rvo )   ! Relative Vorticity 
-         CASE( jpdyn_trd_pvo )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_pvo )   ! Planetary Vorticity Term 
-         CASE( jpdyn_trd_ldf )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_ldf )   ! Horizontal Diffusion 
-         CASE( jpdyn_trd_zad )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_zad )   ! Vertical Advection 
-         CASE( jpdyn_trd_spg )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_spg )   ! Surface Pressure Grad. 
-         CASE( jpdyn_trd_zdf )                                                      ! Vertical Diffusion 
-            ztswu(:,:) = 0.e0   ;   ztswv(:,:) = 0.e0
-            DO jj = 2, jpjm1                                                             ! wind stress trends
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  ztswu(ji,jj) = 0.5 * ( utau_b(ji,jj) + utau(ji,jj) ) / ( fse3u(ji,jj,1) * rau0 )
-                  ztswv(ji,jj) = 0.5 * ( vtau_b(ji,jj) + vtau(ji,jj) ) / ( fse3v(ji,jj,1) * rau0 )
-               END DO
-            END DO
-            !
-            CALL trd_vor_zint( ptrdx, ptrdy, jpvor_zdf )                             ! zdf trend including surf./bot. stresses 
-            CALL trd_vor_zint( ztswu, ztswv, jpvor_swf )                             ! surface wind stress 
-         CASE ( jpdyn_trd_bfr )
-            CALL trd_vor_zint( ptrdx, ptrdy, jpvor_bfr )                             ! Bottom stress
-         END SELECT
-         !
-      ENDIF
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! III. Mixed layer trends for active tracers
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-      IF( lk_trdmld .AND. ctype == 'TRA' )   THEN   
-         !-----------------------------------------------------------------------------------------------
-         ! W.A.R.N.I.N.G :
-         ! jptra_trd_ldf : called by traldf.F90
-         !                 at this stage we store:
-         !                  - the lateral geopotential diffusion (here, lateral = horizontal)
-         !                  - and the iso-neutral diffusion if activated 
-         ! jptra_trd_zdf : called by trazdf.F90
-         !                 * in case of iso-neutral diffusion we store the vertical diffusion component in the 
-         !                   lateral trend including the K_z contrib, which will be removed later (see trd_mld)
-         !-----------------------------------------------------------------------------------------------
-
-         SELECT CASE ( ktrd )
-         CASE ( jptra_trd_xad )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_xad, '3D' )   ! zonal    advection
-         CASE ( jptra_trd_yad )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_yad, '3D' )   ! merid.   advection
-         CASE ( jptra_trd_zad )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_zad, '3D' )   ! vertical advection
-         CASE ( jptra_trd_ldf )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_ldf, '3D' )   ! lateral  diffusion
-         CASE ( jptra_trd_bbl )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_bbl, '3D' )   ! bottom boundary layer
-         CASE ( jptra_trd_zdf )
-            IF( ln_traldf_iso ) THEN   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_ldf, '3D' )   ! lateral  diffusion (K_z)
-            ELSE                       ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_zdf, '3D' )   ! vertical diffusion (K_z)
-            ENDIF
-         CASE ( jptra_trd_dmp )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_dmp, '3D' )   ! internal 3D restoring (tradmp)
-         CASE ( jptra_trd_qsr )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_for, '3D' )   ! air-sea : penetrative sol radiat
-         CASE ( jptra_trd_nsr )
-            ptrdx(:,:,2:jpk) = 0._wp   ;   ptrdy(:,:,2:jpk) = 0._wp
-            CALL trd_mld_zint( ptrdx, ptrdy, jpmld_for, '2D' )                                  ! air-sea : non penetr sol radiat
-         CASE ( jptra_trd_bbc )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_bbc, '3D' )   ! bottom bound cond (geoth flux)
-         CASE ( jptra_trd_atf )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_atf, '3D' )   ! asselin numerical
-         CASE ( jptra_trd_npc )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_npc, '3D' )   ! non penetr convect adjustment
-         END SELECT
-         !
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, ztswu, ztswv )
-      !
-   END SUBROUTINE trd_mod
-
-
-   SUBROUTINE trd_3Diom( ptrdx, ptrdy, ktrd, ctype, kt )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_3Diom  ***
-      !! 
-      !! ** Purpose :   output 3D trends using IOM
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend 
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
-      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
-      CHARACTER(len=3)          , INTENT(in   ) ::   ctype   ! momentum or tracers trends type 'DYN'/'TRA'
-      INTEGER                   , INTENT(in   ) ::   kt      ! time step
-      !!
-      INTEGER ::   ji, jj, jk   ! dummy loop indices
-      INTEGER ::   ikbu, ikbv   ! local integers
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   z2dx, z2dy, ztswu, ztswv   ! 2D workspace 
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   z3dx, z3dy                 ! 3D workspace 
-      !!----------------------------------------------------------------------
-
-       IF( lk_trdtra .AND. ctype == 'TRA' ) THEN       ! active tracer trends
-         !
-!!gm Rq: mask the trends already masked in trd_tra, but lbc_lnk should probably be added
-         !
-         SELECT CASE( ktrd )
-         CASE( jptra_trd_xad  )   ;   CALL iom_put( "ttrd_xad" , ptrdx )        ! x- horizontal advection
-                                      CALL iom_put( "strd_xad" , ptrdy )
-         CASE( jptra_trd_yad  )   ;   CALL iom_put( "ttrd_yad" , ptrdx )        ! y- horizontal advection
-                                      CALL iom_put( "strd_yad" , ptrdy )
-         CASE( jptra_trd_zad  )   ;   CALL iom_put( "ttrd_zad" , ptrdx )        ! z- vertical   advection
-                                      CALL iom_put( "strd_zad" , ptrdy )
-                                      IF( .NOT.lk_vvl ) THEN                   ! cst volume : adv flux through z=0 surface
-                                         z2dx(:,:) = wn(:,:,1) * tsn(:,:,1,jp_tem) / fse3t(:,:,1)
-                                         z2dy(:,:) = wn(:,:,1) * tsn(:,:,1,jp_sal) / fse3t(:,:,1)
-                                         CALL iom_put( "ttrd_sad", z2dx )
-                                         CALL iom_put( "strd_sad", z2dy )
-                                      ENDIF
-         CASE( jptra_trd_ldf  )   ;   CALL iom_put( "ttrd_ldf" , ptrdx )        ! lateral diffusion
-                                      CALL iom_put( "strd_ldf" , ptrdy )
-         CASE( jptra_trd_zdf  )   ;   CALL iom_put( "ttrd_zdf" , ptrdx )        ! vertical diffusion (including Kz contribution)
-                                      CALL iom_put( "strd_zdf" , ptrdy )
-         CASE( jptra_trd_zdfp )   ;   CALL iom_put( "ttrd_zdfp", ptrdx )        ! PURE vertical diffusion (no isoneutral contribution)
-                                      CALL iom_put( "strd_zdfp", ptrdy )
-         CASE( jptra_trd_dmp  )   ;   CALL iom_put( "ttrd_dmp" , ptrdx )        ! internal restoring (damping)
-                                      CALL iom_put( "strd_dmp" , ptrdy )
-         CASE( jptra_trd_bbl  )   ;   CALL iom_put( "ttrd_bbl" , ptrdx )        ! bottom boundary layer
-                                      CALL iom_put( "strd_bbl" , ptrdy )
-         CASE( jptra_trd_npc  )   ;   CALL iom_put( "ttrd_npc" , ptrdx )        ! static instability mixing
-                                      CALL iom_put( "strd_npc" , ptrdy )
-         CASE( jptra_trd_nsr  )   ;   CALL iom_put( "ttrd_qns" , ptrdx )        ! surface forcing + runoff (ln_rnf=T)
-                                      CALL iom_put( "strd_cdt" , ptrdy )
-         CASE( jptra_trd_qsr  )   ;   CALL iom_put( "ttrd_qsr" , ptrdx )        ! penetrative solar radiat. (only on temperature)
-         CASE( jptra_trd_bbc  )   ;   CALL iom_put( "ttrd_bbc" , ptrdx )        ! geothermal heating   (only on temperature)
-         CASE( jptra_trd_atf  )   ;   CALL iom_put( "ttrd_atf" , ptrdx )        ! asselin time Filter
-                                      CALL iom_put( "strd_atf" , ptrdy )
-
-         END SELECT
-      ENDIF
-
-      IF( lk_trddyn .AND. ctype == 'DYN' ) THEN       ! momentum trends 
-            !
-         ptrdx(:,:,:) = ptrdx(:,:,:) * umask(:,:,:)                       ! mask the trends
-         ptrdy(:,:,:) = ptrdy(:,:,:) * vmask(:,:,:)
-!!gm NB : here a lbc_lnk should probably be added
-         !
-         SELECT CASE( ktrd )
-         CASE( jpdyn_trd_hpg )   ;   CALL iom_put( "utrd_hpg", ptrdx )    ! hydrostatic pressure gradient
-                                     CALL iom_put( "vtrd_hpg", ptrdy )
-         CASE( jpdyn_trd_spg )   ;   CALL iom_put( "utrd_spg", ptrdx )    ! surface pressure gradient
-                                     CALL iom_put( "vtrd_spg", ptrdy )
-         CASE( jpdyn_trd_pvo )   ;   CALL iom_put( "utrd_pvo", ptrdx )    ! planetary vorticity
-                                     CALL iom_put( "vtrd_pvo", ptrdy )
-         CASE( jpdyn_trd_rvo )   ;   CALL iom_put( "utrd_rvo", ptrdx )    ! relative  vorticity     (or metric term)
-                                     CALL iom_put( "vtrd_rvo", ptrdy )
-         CASE( jpdyn_trd_keg )   ;   CALL iom_put( "utrd_keg", ptrdx )    ! Kinetic Energy gradient (or had)
-                                     CALL iom_put( "vtrd_keg", ptrdy )
-            z3dx(:,:,:) = 0._wp                                           ! U.dxU & V.dyV (approximation)
-            z3dy(:,:,:) = 0._wp
-            DO jk = 1, jpkm1														         ! no mask as un,vn are masked
-               DO jj = 2, jpjm1
-                  DO ji = 2, jpim1
-                     z3dx(ji,jj,jk) = un(ji,jj,jk) * ( un(ji+1,jj,jk) - un(ji-1,jj,jk) ) / ( 2._wp * e1u(ji,jj) )
-                     z3dy(ji,jj,jk) = vn(ji,jj,jk) * ( vn(ji,jj+1,jk) - vn(ji,jj-1,jk) ) / ( 2._wp * e2v(ji,jj) )
-                  END DO
-               END DO
-            END DO
-            CALL lbc_lnk( z3dx, 'U', -1. )   ;    CALL lbc_lnk( z3dy, 'V', -1. )
-                                     CALL iom_put( "utrd_udx", z3dx  ) 
-                                     CALL iom_put( "vtrd_vdy", z3dy  )
-         CASE( jpdyn_trd_zad )   ;   CALL iom_put( "utrd_zad", ptrdx )    ! vertical   advection
-                                     CALL iom_put( "vtrd_zad", ptrdy )
-         CASE( jpdyn_trd_ldf )   ;   CALL iom_put( "utrd_ldf", ptrdx )    ! lateral diffusion
-                                     CALL iom_put( "vtrd_ldf", ptrdy )
-         CASE( jpdyn_trd_zdf )   ;   CALL iom_put( "utrd_zdf", ptrdx )    ! vertical diffusion 
-                                     CALL iom_put( "vtrd_zdf", ptrdy )
-                                     !                                    ! wind stress trends
-                                     z2dx(:,:) = ( utau_b(ji,jj) + utau(ji,jj) ) / ( fse3u(:,:,1) * rau0 )
-                                     z2dy(:,:) = ( vtau_b(ji,jj) + vtau(ji,jj) ) / ( fse3v(:,:,1) * rau0 )
-                                     CALL iom_put( "utrd_tau", z2dx )
-                                     CALL iom_put( "vtrd_tau", z2dy )
-         CASE( jpdyn_trd_bfr )
-            IF( .NOT.ln_bfrimp )     CALL iom_put( "utrd_bfr", ptrdx )    ! bottom friction (explicit case)
-            IF( .NOT.ln_bfrimp )     CALL iom_put( "vtrd_bfr", ptrdy )
-!!gm only valid if ln_bfrimp=T otherwise the bottom stress as to be recomputed....
-
-         CASE( jpdyn_trd_atf )   ;   CALL iom_put( "utrd_atf", ptrdx )    ! asselin filter trends 
-                                     CALL iom_put( "vtrd_atf", ptrdy )
-            IF( ln_bfrimp ) THEN                                          ! bottom friction (implicit case)
-					z3dx(:,:,:) = 0._wp   ;   z3dy(:,:,:) = 0._wp                 ! after velocity known (now filed at this stage)
-               DO jk = 1, jpkm1
-                  DO jj = 2, jpjm1
-                     DO ji = 2, jpim1
-                        ikbu = mbku(ji,jj)          ! deepest ocean u- & v-levels
-                        ikbv = mbkv(ji,jj)
-                        z3dx(ji,jj,jk) = bfrua(ji,jj) * un(ji,jj,ikbu) / fse3u(ji,jj,ikbu)
-                        z3dy(ji,jj,jk) = bfrva(ji,jj) * vn(ji,jj,ikbv) / fse3v(ji,jj,ikbv)
-                     END DO
-                  END DO
-               END DO
-                                     CALL iom_put( "utrd_bfr", z3dx )    ! bottom friction (implicit)
-                                     CALL iom_put( "vtrd_bfr", z3dy )
-            ENDIF
-            !
-         END SELECT
-         !
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj     , z2dx, z2dy, ztswu, ztswv )
-      CALL wrk_dealloc( jpi, jpj, jpk, z3dx, z3dy )
-      !
-   END SUBROUTINE trd_3Diom
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default case :           Empty module          No trend diagnostics
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE trd_mod( ptrdx, ptrdy, ktrd, ctype, kt )   ! Empty routine
-      REAL ::   ptrdx(:,:,:), ptrdy(:,:,:)
-      INTEGER  ::   ktrd, kt                            
-      CHARACTER(len=3) ::  ctype                  
-      WRITE(*,*) 'trd_mod: You should not have seen this print! error ?',   &
-         &       ptrdx(1,1,1), ptrdy(1,1,1), ktrd, ctype, kt
-   END SUBROUTINE trd_mod
-#endif
-
-   SUBROUTINE trd_mod_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mod_init  ***
-      !! 
-      !! ** Purpose :   Initialization of activated trends
-      !!----------------------------------------------------------------------
-      USE in_out_manager          ! I/O manager
-
-      NAMELIST/namtrd/ ln_3D_trd_d, ln_KE_trd, ln_vor_trd, ln_ML_trd_d,   &
-         &             ln_3D_trd_t, ln_PE_trd, ln_glo_trd, ln_ML_trd_t,   &
-         &             nn_trd , cn_trdrst_in , ln_trdmld_restart,         &
-         &             nn_ctls, cn_trdrst_out, ln_trdmld_instant, rn_ucf
-      !!----------------------------------------------------------------------
-
-      IF( l_trdtra .OR. l_trddyn )   THEN
-         REWIND( numnam )
-         READ  ( numnam, namtrd )      ! namelist namtrd : trends diagnostic
-
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) ' trd_mod_init : Momentum/Tracers trends'
-            WRITE(numout,*) ' ~~~~~~~~~~~~~'
-            WRITE(numout,*) '   Namelist namtrd : set trends parameters'
-            WRITE(numout,*) '      U & V trends: 3D output                 ln_3D_trd_d        = ', ln_3D_trd_d
-            WRITE(numout,*) '      T & S trends: 3D output                 ln_3D_trd_t        = ', ln_3D_trd_t
-            WRITE(numout,*) '      Kinetic   Energy trends                 ln_KE_trd          = ', ln_KE_trd
-            WRITE(numout,*) '      Potential Energy trends                 ln_PE_trd          = ', ln_PE_trd
-            WRITE(numout,*) '      Barotropic vorticity trends             ln_vor_trd         = ', ln_vor_trd
-            WRITE(numout,*) '      check domain averaged dyn & tra trends  ln_glo_trd         = ', ln_glo_trd
-            WRITE(numout,*) '      U & V trends: Mixed Layer averaged      ln_ML_trd_d        = ', ln_3D_trd_d
-            WRITE(numout,*) '      T & S trends: Mixed Layer averaged      ln_ML_trd_t        = ', ln_3D_trd_t
-     !
-            WRITE(numout,*) '      frequency of trends diagnostics (glo)   nn_trd             = ', nn_trd
-            WRITE(numout,*) '      control surface type            (mld)   nn_ctls            = ', nn_ctls
-            WRITE(numout,*) '      restart for ML diagnostics              ln_trdmld_restart  = ', ln_trdmld_restart
-            WRITE(numout,*) '      instantaneous or mean ML T/S            ln_trdmld_instant  = ', ln_trdmld_instant
-            WRITE(numout,*) '      unit conversion factor                  rn_ucf             = ', rn_ucf
-        ENDIF
-      ENDIF
-      !
-      IF( ln_KE_trd .OR. ln_PE_trd .OR. ln_ML_trd_d )   &
-         CALL ctl_stop( 'KE, PE, aur ML on momentum are not yet coded we stop' )
-!!gm  : Potential BUG : 3D output only for vector invariant form!  add a ctl_stop or code the flux form case
-!!gm  : bug/pb for vertical advection of tracer in vvl case: add T.dt[eta] in the output... 
-      !
-      IF( lk_trddyn .OR. lk_trdtra )    CALL trd_icp_init       ! integral constraints trends
-      IF( lk_trdmld                )    CALL trd_mld_init       ! mixed-layer trends (active  tracers)  
-      IF( lk_trdvor                )    CALL trd_vor_init       ! vorticity trends        
-      !
-   END SUBROUTINE trd_mod_init
-
-   !!======================================================================
-END MODULE trdmod
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod_oce.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod_oce.F90	(revision 3317)
+++ 	(revision )
@@ -1,105 +1,0 @@
-MODULE trdmod_oce
-   !!======================================================================
-   !!                   ***  MODULE trdmod_oce  ***
-   !! Ocean trends :   set tracer and momentum trend variables
-   !!======================================================================
-   !! History :  1.0  !  2004-08  (C. Talandier) Original code
-   !!----------------------------------------------------------------------
-   USE par_oce                 ! ocean parameters
-   USE trdmld_oce              ! ocean active mixed layer tracers trends variables
-   USE trdvor_oce              ! ocean vorticity trends variables
-
-   IMPLICIT NONE
-   PUBLIC
-
-#if  defined key_trdtra   &&   defined key_trddyn    ||   defined key_esopa
-   LOGICAL, PARAMETER ::   lk_trdtra = .TRUE.    !: tracers  trend flag
-   LOGICAL, PARAMETER ::   lk_trddyn = .TRUE.    !: momentum trend flag
-#elif  defined key_trdtra
-   LOGICAL, PARAMETER ::   lk_trdtra = .TRUE.    !: tracers  trend flag
-   LOGICAL, PARAMETER ::   lk_trddyn = .FALSE.   !: momentum trend flag
-#elif  defined key_trddyn
-   LOGICAL, PARAMETER ::   lk_trdtra = .FALSE.   !: tracers  trend flag
-   LOGICAL, PARAMETER ::   lk_trddyn = .TRUE.    !: momentum trend flag
-#else
-   LOGICAL, PARAMETER ::   lk_trdtra = .FALSE.   !: tracers  trend flag
-   LOGICAL, PARAMETER ::   lk_trddyn = .FALSE.   !: momentum trend flag
-#endif
-
-   !                                                     !!* Namelist namtrd:  diagnostics on dynamics/tracer trends *
-   LOGICAL , PUBLIC  ::   ln_3D_trd_d   = .FALSE.         !: (T) 3D momentum              trends or (F) not
-   LOGICAL , PUBLIC  ::   ln_3D_trd_t   = .FALSE.         !: (T) 3D tracer               trends or (F) not
-   LOGICAL , PUBLIC  ::   ln_PE_trd     = .FALSE.         !: (T) 3D Potential Energy     trends or (F) not
-   LOGICAL , PUBLIC  ::   ln_KE_trd     = .FALSE.         !: (T) 3D Kinetic   Energy     trends or (F) not
-   LOGICAL , PUBLIC  ::   ln_vor_trd    = .FALSE.         !: (T) 3D barotropic vorticity trends or (F) not
-   LOGICAL , PUBLIC  ::   ln_glo_trd    = .FALSE.         !: (T) global domain averaged diag for T, T^2, KE, and PE
-   LOGICAL , PUBLIC  ::   ln_ML_trd_t   = .FALSE.         !: (T) 2D tracer   trends averaged over the mixed layer 
-   LOGICAL , PUBLIC  ::   ln_ML_trd_d   = .FALSE.         !: (T) 2D momentum trends averaged over the mixed layer 
-   INTEGER , PUBLIC  ::   nn_trd  = 10                    !: time step frequency for ln_glo_trd
-   INTEGER , PUBLIC  ::   nn_ctls =  0                    !: control surface type for trends vertical integration
-   REAL(wp), PUBLIC  ::   rn_ucf   = 1.                   !: unit conversion factor (for netCDF trends outputs)
-                                                          !: =1. (=86400.) for degC/s (degC/day) and psu/s (psu/day)
-   CHARACTER(len=32) ::   cn_trdrst_in  = "restart_mld"   !: suffix of ocean restart name (input)
-   CHARACTER(len=32) ::   cn_trdrst_out = "restart_mld"   !: suffix of ocean restart name (output)
-   LOGICAL , PUBLIC  ::   ln_trdmld_instant = .FALSE.     !: flag to diagnose inst./mean ML T/S trends
-   LOGICAL , PUBLIC  ::   ln_trdmld_restart = .FALSE.     !: flag to restart mixed-layer diagnostics
-
-# if defined key_trdtra   ||   defined key_trdmld
-   LOGICAL , PUBLIC ::   l_trdtra = .TRUE.                !: tracers  trend flag
-# else
-   LOGICAL , PUBLIC ::   l_trdtra = .FALSE.               !: tracers  trend flag
-# endif
-# if defined key_trddyn   ||   defined key_trdvor
-   LOGICAL , PUBLIC ::   l_trddyn = .TRUE.                !: momentum trend flag
-# else
-   LOGICAL , PUBLIC ::   l_trddyn = .FALSE.               !: momentum trend flag
-# endif
-# if ( defined key_trdtrc && defined key_iomput )  ||  defined key_trdmld_trc
-   LOGICAL , PUBLIC ::   l_trdtrc = .TRUE.                !: tracers  trend flag
-# else
-   LOGICAL , PUBLIC ::   l_trdtrc = .FALSE.               !: tracers  trend flag
-# endif
-   !                                                      !!!* Active tracers trends indexes
-   INTEGER, PUBLIC, PARAMETER ::   jptot_tra      = 14     !: Total trend nb: change it when adding/removing one indice below
-   !                               ===================     !  
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_xad  =  1     !: x- horizontal advection
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_yad  =  2     !: y- horizontal advection
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_zad  =  3     !: z- vertical   advection
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_sad  =  4     !: z- vertical   advection
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_ldf  =  5     !: lateral       diffusion
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_zdf  =  6     !: vertical      diffusion
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_zdfp =  7     !: "PURE" vert.  diffusion (ln_traldf_iso=T)
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_bbc  =  8     !: Bottom Boundary Condition (geoth. heating) 
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_bbl  =  9     !: Bottom Boundary Layer (diffusive and/or advective)
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_npc  = 10     !: non-penetrative convection treatment
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_dmp  = 11     !: internal restoring (damping)
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_qsr  = 12     !: penetrative solar radiation
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_nsr  = 13     !: non solar radiation / C/D on salinity  (+runoff if ln_rnf=T)
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_atf  = 14     !: Asselin time filter
-   !
-   !                                                      !!!* Passive tracers trends indices (use if "key_top" defined)
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_sms  = 13     !: sources m. sinks
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_radn = 14     !: corr. trn<0 in trcrad
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_radb = 15     !: corr. trb<0 in trcrad (like atf)
-   !
-   !                                                      !!!* Momentum trends indices
-   INTEGER, PUBLIC, PARAMETER ::   jptot_dyn      = 11     !: Total trend nb: change it when adding/removing one indice below
-   !                               ===================     !  
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_hpg  =  1     !: hydrostatic pressure gradient 
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_spg  =  2     !: surface     pressure gradient
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_keg  =  3     !: kinetic energy gradient  or horizontal advection
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_rvo  =  4     !: relative  vorticity      or metric term
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_pvo  =  5     !: planetary vorticity
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_zad  =  6     !: vertical advection
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_ldf  =  7     !: horizontal diffusion   
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_zdf  =  8     !: vertical   diffusion
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_tau  =  9     !: surface stress
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_bfr  = 10     !: bottom  stress 
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_atf  = 11     !: Asselin time filter
-   !
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!======================================================================
-END MODULE trdmod_oce
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90	(revision 3318)
@@ -7,18 +7,24 @@
    !!            3.5  !  2012-02  (G. Madec) update the comments 
    !!----------------------------------------------------------------------
-#if  defined key_trdtra || defined key_trdmld || defined key_trdmld_trc 
-   !!----------------------------------------------------------------------
-   !!   trd_tra       : pre-process the tracer trends and calll trd_mod(_trc)
+
+   !!----------------------------------------------------------------------
+   !!   trd_tra       : pre-process the tracer trends
    !!   trd_tra_adv   : transform a div(U.T) trend into a U.grad(T) trend
+   !!   trd_tra_mng   : tracer trend manager: dispatch to the diagnostic modules
+   !!   trd_tra_iom   : output 3D tracer trends using IOM
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and tracers variables
    USE dom_oce        ! ocean domain 
+   USE sbc_oce        ! surface boundary condition: ocean
    USE zdf_oce        ! ocean vertical physics
+   USE trd_oce        ! trends: ocean variables
+   USE trdmod_trc     ! ocean passive mixed layer tracers trends 
+   USE trdglo         ! trends:global domain averaged
+   USE trdmld         ! ocean active mixed layer tracers trends 
+   USE ldftra_oce     ! ocean active tracers lateral physics
    USE zdfddm         ! vertical physics: double diffusion
-   USE trdmod_oce     ! ocean active mixed layer tracers trends 
-   USE trdmod         ! ocean active mixed layer tracers trends 
-   USE trdmod_trc     ! ocean passive mixed layer tracers trends 
-   USE ldftra_oce     ! ocean active tracers lateral physics
+   USE phycst         ! physical constants
    USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
    USE lib_mpp        ! MPP library
    USE wrk_nemo       ! Memory allocation
@@ -28,5 +34,7 @@
 
    PUBLIC   trd_tra   ! called by all tra_... modules
- 
+
+   REAL(wp) ::   r2dt   ! time-step, = 2 rdttra except at nit000 (=rdttra) if neuler=0
+
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   trdtx, trdty, trdt   ! use to store the temperature trends
 
@@ -64,5 +72,5 @@
       !!              call to trd_tra_adv
       !!              - 'TRA' case : regroup T & S trends
-      !!              - send the trends to trd_mod(_trc) for further processing
+      !!              - send the trends to trd_tra_mng (trdmod_trc) for further processing
       !!----------------------------------------------------------------------
       INTEGER                         , INTENT(in)           ::   kt      ! time step
@@ -88,13 +96,13 @@
          IF( PRESENT( ptra ) ) THEN                       ! advection: transform flux into trend
             SELECT CASE( ktrd )     
-            CASE( jptra_trd_xad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'X', trdtx ) 
-            CASE( jptra_trd_yad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'Y', trdty ) 
-            CASE( jptra_trd_zad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'Z', trdt  ) 
+            CASE( jptra_xad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'X', trdtx ) 
+            CASE( jptra_yad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'Y', trdty ) 
+            CASE( jptra_zad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'Z', trdt  ) 
             END SELECT
          ELSE                                             ! other trends:
-            trdt(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)                      ! mask & store
-            IF( ktrd == jptra_trd_bbc .OR. ktrd == jptra_trd_qsr ) THEN   ! qsr, bbc: on temperature only
+            trdt(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)              ! mask & store
+            IF( ktrd == jptra_bbc .OR. ktrd == jptra_qsr ) THEN   ! qsr, bbc: on temperature only
                ztrds(:,:,:) = 0._wp
-               CALL trd_mod( trdt, ztrds, ktrd, ctype, kt )                  ! send to trd_mod
+               CALL trd_tra_mng( trdt, ztrds, ktrd, kt )               ! send to trd_tra_mng
             ENDIF
          ENDIF
@@ -105,20 +113,20 @@
          !
          IF( PRESENT( ptra ) ) THEN      ! advection: transform the advective flux into a trend
-            SELECT CASE( ktrd )          !            and send T & S trends to trd_mod
-            CASE( jptra_trd_xad )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'X'  , ztrds ) 
-                                        CALL trd_mod    ( trdtx, ztrds, ktrd, ctype, kt    )
-            CASE( jptra_trd_yad )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'Y'  , ztrds ) 
-                                    ;   CALL trd_mod    ( trdty, ztrds, ktrd, ctype, kt    )
-            CASE( jptra_trd_zad )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'Z'  , ztrds ) 
-                                        CALL trd_mod    ( trdt , ztrds, ktrd, ctype, kt    )
+            SELECT CASE( ktrd )          !            and send T & S trends to trd_tra_mng
+            CASE( jptra_xad )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'X'  , ztrds ) 
+                                    CALL trd_tra_mng( trdtx, ztrds, ktrd, kt   )
+            CASE( jptra_yad )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'Y'  , ztrds ) 
+                                ;   CALL trd_tra_mng( trdty, ztrds, ktrd, kt   )
+            CASE( jptra_zad )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'Z'  , ztrds ) 
+                                    CALL trd_tra_mng( trdt , ztrds, ktrd, kt   )
             END SELECT
-         ELSE                            ! other trends: mask and send T & S trends to trd_mod
+         ELSE                            ! other trends: mask and send T & S trends to trd_tra_mng
             ztrds(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)
-            CALL trd_mod( trdt, ztrds, ktrd, ctype, kt )  
+            CALL trd_tra_mng( trdt, ztrds, ktrd, kt )  
          ENDIF
          !
-         IF( ktrd == jptra_trd_zdfp ) THEN     ! diagnose the "PURE" Kz trend (here: just before the swap)
+         IF( ktrd == jptra_zdfp ) THEN     ! diagnose the "PURE" Kz trend (here: just before the swap)
             !
-            IF( ln_traldf_iso ) THEN      ! iso-neutral diffusion only otherwise jptra_trd_zdf is "PURE"
+            IF( ln_traldf_iso ) THEN      ! iso-neutral diffusion only otherwise jptra_zdf is "PURE"
                !
                CALL wrk_alloc( jpi, jpj, jpk, zwt, zws, ztrdt )
@@ -136,5 +144,5 @@
                   ztrds(:,:,jk) = ( zws(:,:,jk) - zws(:,:,jk+1) ) / fse3t(:,:,jk) 
                END DO
-               CALL trd_mod( ztrdt, ztrds, jptra_trd_zdfp, ctype, kt )  
+               CALL trd_tra_mng( ztrdt, ztrds, jptra_zdfp, kt )  
                !
                CALL wrk_dealloc( jpi, jpj, jpk, zwt, zws, ztrdt )
@@ -147,11 +155,11 @@
       IF( ctype == 'TRC' ) THEN                           !==  passive tracer trend  ==!
          !
-         IF( PRESENT( ptra ) ) THEN                          ! advection: transform flux into a trend
+         IF( PRESENT( ptra ) ) THEN                          ! advection: transform flux into a masked trend
             SELECT CASE( ktrd )
-            CASE( jptra_trd_xad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'X', ztrds ) 
-            CASE( jptra_trd_yad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'Y', ztrds ) 
-            CASE( jptra_trd_zad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'Z', ztrds ) 
+            CASE( jptra_xad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'X', ztrds ) 
+            CASE( jptra_yad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'Y', ztrds ) 
+            CASE( jptra_zad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'Z', ztrds ) 
             END SELECT
-         ELSE                                                ! other trends: mask
+         ELSE                                                ! other trends: masked trend
             ztrds(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)
          END IF
@@ -211,20 +219,124 @@
    END SUBROUTINE trd_tra_adv
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Default case :          Dummy module           No trend diagnostics
-   !!----------------------------------------------------------------------
-   USE par_oce      ! ocean variables trends
-CONTAINS
-   SUBROUTINE trd_tra( kt, ctype, ktra, ktrd, ptrd, pu, ptra )
-      !!----------------------------------------------------------------------
-      CHARACTER(len=3)                , INTENT(in)           ::  ctype   
-      INTEGER                         , INTENT(in)           ::  kt, ktra, ktrd
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in)           ::  ptrd    
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::  pu, ptra    ! Tracer variable 
-      WRITE(*,*) 'trd_tra: You should not have seen this print! error ?',   &
-         &   ptrd(1,1,1), ptra(1,1,1), pu(1,1,1), ktrd, ktra, ctype, kt
-   END SUBROUTINE trd_tra
-#endif
+
+   SUBROUTINE trd_tra_mng( ptrdx, ptrdy, ktrd, kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_tra_mng  ***
+      !! 
+      !! ** Purpose :   Dispatch all trends computation, e.g. 3D output, integral
+      !!                constraints, barotropic vorticity, kinetic enrgy, 
+      !!                potential energy, and/or mixed layer budget.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend 
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
+      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
+      INTEGER                   , INTENT(in   ) ::   kt      ! time step
+      !!----------------------------------------------------------------------
+
+      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdtra (restart with Euler time stepping)
+      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdttra (leapfrog)
+      ENDIF
+
+      !                   ! 3D output of tracers trends using IOM interface
+      IF( ln_tra_trd )   CALL trd_tra_iom ( ptrdx, ptrdy, ktrd, kt )
+
+      !                   ! Integral Constraints Properties for tracers trends                                       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF( ln_glo_trd )   CALL trd_glo( ptrdx, ptrdy, ktrd, 'TRA', kt )
+
+      !                   ! Mixed layer trends for active tracers
+      IF( ln_tra_mld )   THEN   
+         !-----------------------------------------------------------------------------------------------
+         ! W.A.R.N.I.N.G :
+         ! jptra_ldf : called by traldf.F90
+         !                 at this stage we store:
+         !                  - the lateral geopotential diffusion (here, lateral = horizontal)
+         !                  - and the iso-neutral diffusion if activated 
+         ! jptra_zdf : called by trazdf.F90
+         !                 * in case of iso-neutral diffusion we store the vertical diffusion component in the 
+         !                   lateral trend including the K_z contrib, which will be removed later (see trd_mld)
+         !-----------------------------------------------------------------------------------------------
+
+         SELECT CASE ( ktrd )
+         CASE ( jptra_xad )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_xad, '3D' )   ! zonal    advection
+         CASE ( jptra_yad )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_yad, '3D' )   ! merid.   advection
+         CASE ( jptra_zad )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_zad, '3D' )   ! vertical advection
+         CASE ( jptra_ldf )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_ldf, '3D' )   ! lateral  diffusion
+         CASE ( jptra_bbl )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_bbl, '3D' )   ! bottom boundary layer
+         CASE ( jptra_zdf )
+            IF( ln_traldf_iso ) THEN ; CALL trd_mld_zint( ptrdx, ptrdy, jpmld_ldf, '3D' )   ! lateral  diffusion (K_z)
+            ELSE                   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_zdf, '3D' )   ! vertical diffusion (K_z)
+            ENDIF
+         CASE ( jptra_dmp )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_dmp, '3D' )   ! internal 3D restoring (tradmp)
+         CASE ( jptra_qsr )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_for, '3D' )   ! air-sea : penetrative sol radiat
+         CASE ( jptra_nsr )        ;   ptrdx(:,:,2:jpk) = 0._wp   ;   ptrdy(:,:,2:jpk) = 0._wp
+                                   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_for, '2D' )   ! air-sea : non penetr sol radiation
+         CASE ( jptra_bbc )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_bbc, '3D' )   ! bottom bound cond (geoth flux)
+         CASE ( jptra_npc )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_npc, '3D' )   ! non penetr convect adjustment
+         CASE ( jptra_atf )        ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_atf, '3D' )   ! asselin time filter (last trend)
+                                   !
+                                       CALL trd_mld( kt )                                   ! trends: Mixed-layer (output)
+         END SELECT
+         !
+      ENDIF
+      !
+   END SUBROUTINE trd_tra_mng
+
+
+   SUBROUTINE trd_tra_iom( ptrdx, ptrdy, ktrd, kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_tra_iom  ***
+      !! 
+      !! ** Purpose :   output 3D tracer trends using IOM
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend 
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
+      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
+      INTEGER                   , INTENT(in   ) ::   kt      ! time step
+      !!
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
+      INTEGER ::   ikbu, ikbv   ! local integers
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   z2dx, z2dy   ! 2D workspace 
+      !!----------------------------------------------------------------------
+      !
+      CALL wrk_alloc( jpi, jpj, z2dx, z2dy )
+      !
+!!gm Rq: mask the trends already masked in trd_tra, but lbc_lnk should probably be added
+      !
+      SELECT CASE( ktrd )
+      CASE( jptra_xad  )   ;   CALL iom_put( "ttrd_xad" , ptrdx )        ! x- horizontal advection
+                                   CALL iom_put( "strd_xad" , ptrdy )
+      CASE( jptra_yad  )   ;   CALL iom_put( "ttrd_yad" , ptrdx )        ! y- horizontal advection
+                                   CALL iom_put( "strd_yad" , ptrdy )
+      CASE( jptra_zad  )   ;   CALL iom_put( "ttrd_zad" , ptrdx )        ! z- vertical   advection
+                               CALL iom_put( "strd_zad" , ptrdy )
+                               IF( .NOT.lk_vvl ) THEN                   ! cst volume : adv flux through z=0 surface
+                                  z2dx(:,:) = wn(:,:,1) * tsn(:,:,1,jp_tem) / fse3t(:,:,1)
+                                  z2dy(:,:) = wn(:,:,1) * tsn(:,:,1,jp_sal) / fse3t(:,:,1)
+                                  CALL iom_put( "ttrd_sad", z2dx )
+                                  CALL iom_put( "strd_sad", z2dy )
+                               ENDIF
+      CASE( jptra_ldf  )   ;   CALL iom_put( "ttrd_ldf" , ptrdx )        ! lateral diffusion
+                               CALL iom_put( "strd_ldf" , ptrdy )
+      CASE( jptra_zdf  )   ;   CALL iom_put( "ttrd_zdf" , ptrdx )        ! vertical diffusion (including Kz contribution)
+                               CALL iom_put( "strd_zdf" , ptrdy )
+      CASE( jptra_zdfp )   ;   CALL iom_put( "ttrd_zdfp", ptrdx )        ! PURE vertical diffusion (no isoneutral contribution)
+                               CALL iom_put( "strd_zdfp", ptrdy )
+      CASE( jptra_dmp  )   ;   CALL iom_put( "ttrd_dmp" , ptrdx )        ! internal restoring (damping)
+                               CALL iom_put( "strd_dmp" , ptrdy )
+      CASE( jptra_bbl  )   ;   CALL iom_put( "ttrd_bbl" , ptrdx )        ! bottom boundary layer
+                               CALL iom_put( "strd_bbl" , ptrdy )
+      CASE( jptra_npc  )   ;   CALL iom_put( "ttrd_npc" , ptrdx )        ! static instability mixing
+                               CALL iom_put( "strd_npc" , ptrdy )
+      CASE( jptra_nsr  )   ;   CALL iom_put( "ttrd_qns" , ptrdx )        ! surface forcing + runoff (ln_rnf=T)
+                               CALL iom_put( "strd_cdt" , ptrdy )
+      CASE( jptra_qsr  )   ;   CALL iom_put( "ttrd_qsr" , ptrdx )        ! penetrative solar radiat. (only on temperature)
+      CASE( jptra_bbc  )   ;   CALL iom_put( "ttrd_bbc" , ptrdx )        ! geothermal heating   (only on temperature)
+      CASE( jptra_atf  )   ;   CALL iom_put( "ttrd_atf" , ptrdx )        ! asselin time Filter
+                               CALL iom_put( "strd_atf" , ptrdy )
+      END SELECT
+      !
+      CALL wrk_dealloc( jpi, jpj, z2dx, z2dy )
+      !
+   END SUBROUTINE trd_tra_iom
 
    !!======================================================================
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90	(revision 3318)
@@ -8,7 +8,5 @@
    !!            3.5  !  2012-02  (G. Madec) regroup beta.V computation with pvo trend
    !!----------------------------------------------------------------------
-#if defined key_trdvor   ||   defined key_esopa
-   !!----------------------------------------------------------------------
-   !!   'key_trdvor'   : momentum trend diagnostics
+
    !!----------------------------------------------------------------------
    !!   trd_vor      : momentum trends averaged over the depth
@@ -18,16 +16,16 @@
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain variables
-   USE trdmod_oce      ! ocean variables trends
+   USE trd_oce         ! trends: ocean variables
    USE zdf_oce         ! ocean vertical physics
-   USE in_out_manager  ! I/O manager
+   USE sbc_oce         ! surface boundary condition: ocean
    USE phycst          ! Define parameters for the routines
    USE ldfdyn_oce      ! ocean active tracers: lateral physics
    USE dianam          ! build the name of file (routine)
    USE zdfmxl          ! mixed layer depth
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  ! I/O manager
    USE ioipsl          ! NetCDF library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp         ! MPP library
    USE wrk_nemo        ! Memory allocation
-
 
    IMPLICIT NONE
@@ -38,6 +36,5 @@
    END INTERFACE
 
-   PUBLIC   trd_vor        ! routine called by step.F90
-   PUBLIC   trd_vor_zint   ! routine called by dynamics routines
+   PUBLIC   trd_vor        ! routine called by trddyn.F90
    PUBLIC   trd_vor_init   ! routine called by opa.F90
    PUBLIC   trd_vor_alloc  ! routine called by nemogcm.F90
@@ -81,4 +78,52 @@
       IF( trd_vor_alloc /= 0 )   CALL ctl_warn('trd_vor_alloc: failed to allocate arrays')
    END FUNCTION trd_vor_alloc
+
+
+   SUBROUTINE trd_vor( putrd, pvtrd, ktrd, kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_vor  ***
+      !! 
+      !! ** Purpose :  computation of cumulated trends over analysis period
+      !!               and make outputs (NetCDF or DIMG format)
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   putrd, pvtrd   ! U and V trends 
+      INTEGER                   , INTENT(in   ) ::   ktrd           ! trend index
+      INTEGER                   , INTENT(in   ) ::   kt             ! time step
+      !
+      INTEGER ::   ji, jj   ! dummy loop indices
+      REAL(wp), POINTER, DIMENSION(:,:) ::   ztswu, ztswv    ! 2D workspace 
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, ztswu, ztswv )
+
+      SELECT CASE( ktrd ) 
+      CASE( jpdyn_hpg )   ;   CALL trd_vor_zint( putrd, pvtrd, jpvor_prg )   ! Hydrostatique Pressure Gradient 
+      CASE( jpdyn_keg )   ;   CALL trd_vor_zint( putrd, pvtrd, jpvor_keg )   ! KE Gradient 
+      CASE( jpdyn_rvo )   ;   CALL trd_vor_zint( putrd, pvtrd, jpvor_rvo )   ! Relative Vorticity 
+      CASE( jpdyn_pvo )   ;   CALL trd_vor_zint( putrd, pvtrd, jpvor_pvo )   ! Planetary Vorticity Term 
+      CASE( jpdyn_ldf )   ;   CALL trd_vor_zint( putrd, pvtrd, jpvor_ldf )   ! Horizontal Diffusion 
+      CASE( jpdyn_zad )   ;   CALL trd_vor_zint( putrd, pvtrd, jpvor_zad )   ! Vertical Advection 
+      CASE( jpdyn_spg )   ;   CALL trd_vor_zint( putrd, pvtrd, jpvor_spg )   ! Surface Pressure Grad. 
+      CASE( jpdyn_zdf )                                                      ! Vertical Diffusion 
+         ztswu(:,:) = 0.e0   ;   ztswv(:,:) = 0.e0
+         DO jj = 2, jpjm1                                                             ! wind stress trends
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ztswu(ji,jj) = 0.5 * ( utau_b(ji,jj) + utau(ji,jj) ) / ( fse3u(ji,jj,1) * rau0 )
+               ztswv(ji,jj) = 0.5 * ( vtau_b(ji,jj) + vtau(ji,jj) ) / ( fse3v(ji,jj,1) * rau0 )
+            END DO
+         END DO
+         !
+         CALL trd_vor_zint( putrd, pvtrd, jpvor_zdf )                             ! zdf trend including surf./bot. stresses 
+         CALL trd_vor_zint( ztswu, ztswv, jpvor_swf )                             ! surface wind stress 
+      CASE ( jpdyn_bfr )
+         CALL trd_vor_zint( putrd, pvtrd, jpvor_bfr )                             ! Bottom stress
+         !
+      CASE( jpdyn_atf )       ! last trends: perform the output of 2D vorticity trends
+         CALL trd_vor_iom( kt )
+      END SELECT
+      !
+      CALL wrk_dealloc( jpi, jpj, ztswu, ztswv )
+      !
+   END SUBROUTINE trd_vor
 
 
@@ -268,5 +313,5 @@
 
 
-   SUBROUTINE trd_vor( kt )
+   SUBROUTINE trd_vor_iom( kt )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE trd_vor  ***
@@ -275,6 +320,5 @@
       !!               and make outputs (NetCDF or DIMG format)
       !!----------------------------------------------------------------------
-      !
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      INTEGER                   , INTENT(in   ) ::   kt             ! time step
       !
       INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
@@ -453,5 +497,5 @@
       CALL wrk_dealloc( jpi, jpj, zun, zvn )                                   
       !
-   END SUBROUTINE trd_vor
+   END SUBROUTINE trd_vor_iom
 
 
@@ -577,29 +621,4 @@
    END SUBROUTINE trd_vor_init
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                       Empty module
-   !!----------------------------------------------------------------------
-   INTERFACE trd_vor_zint
-      MODULE PROCEDURE trd_vor_zint_2d, trd_vor_zint_3d
-   END INTERFACE
-CONTAINS
-   SUBROUTINE trd_vor( kt )        ! Empty routine
-      WRITE(*,*) 'trd_vor: You should not have seen this print! error?', kt
-   END SUBROUTINE trd_vor
-   SUBROUTINE trd_vor_zint_2d( putrdvor, pvtrdvor, ktrd )
-      REAL, DIMENSION(:,:), INTENT( inout ) ::   putrdvor, pvtrdvor
-      INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
-      WRITE(*,*) 'trd_vor_zint_2d: You should not have seen this print! error?', putrdvor(1,1), pvtrdvor(1,1), ktrd
-   END SUBROUTINE trd_vor_zint_2d
-   SUBROUTINE trd_vor_zint_3d( putrdvor, pvtrdvor, ktrd )
-      REAL, DIMENSION(:,:,:), INTENT( inout ) ::   putrdvor, pvtrdvor
-      INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
-      WRITE(*,*) 'trd_vor_zint_3d: You should not have seen this print! error?', putrdvor(1,1,1), pvtrdvor(1,1,1), ktrd
-   END SUBROUTINE trd_vor_zint_3d
-   SUBROUTINE trd_vor_init              ! Empty routine
-      WRITE(*,*) 'trd_vor_init: You should not have seen this print! error?'
-   END SUBROUTINE trd_vor_init
-#endif
    !!======================================================================
 END MODULE trdvor
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor_oce.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor_oce.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor_oce.F90	(revision 3318)
@@ -13,9 +13,4 @@
    PRIVATE
 
-#if defined key_trdvor
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trdvor = .TRUE.    !: momentum trend flag
-#else
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trdvor = .FALSE.   !: momentum trend flag
-#endif
    !                                               !!* vorticity trends index
    INTEGER, PUBLIC, PARAMETER ::   jpltot_vor = 11  !: Number of vorticity trend terms
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfkpp.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfkpp.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfkpp.F90	(revision 3318)
@@ -27,4 +27,6 @@
    USE eosbn2          ! equation of state
    USE zdfddm          ! double diffusion mixing
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers
    USE in_out_manager  ! I/O manager
    USE lib_mpp         ! MPP library
@@ -32,6 +34,4 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE prtctl          ! Print control
-   USE trdmod_oce      ! ocean trends definition
-   USE trdtra          ! tracers trends
    USE timing          ! Timing
 
@@ -1266,5 +1266,6 @@
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
          ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
-!!bug gm jpttdzdf ==> jpttkpp
+!!bug gm : cannot add a trend to a same index (here jptra_trd_zdf as in trazdf.F90 !
+!!         solution: add another index in TRD: jptra_trd_kpp
          CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_zdf, ztrdt )
          CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_zdf, ztrds )
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 3318)
@@ -55,5 +55,5 @@
    USE zdfini          ! vertical physics setting          (zdf_init routine)
    USE phycst          ! physical constant                  (par_cst routine)
-   USE trdmod          ! momentum/tracers trends       (trd_mod_init routine)
+   USE trdini          ! dyn/tra trends initialization     (trd_init routine)
    USE asmtrj          ! writing out state trajectory
    USE diaptr          ! poleward transports           (dia_ptr_init routine)
@@ -309,5 +309,5 @@
                             CALL     dom_init   ! Domain
 
-      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
+      IF( ln_nnogather  )   CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
 
       IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
@@ -315,10 +315,6 @@
       IF( lk_obc        )   CALL     obc_init   ! Open boundaries 
       IF( lk_bdy        )   CALL     bdy_init       ! Open boundaries initialisation
-      IF( lk_bdy        )   CALL     bdy_dta_init   ! Open boundaries initialisation of external data arrays
-      IF( lk_bdy        )   CALL     tide_init      ! Open boundaries initialisation of tidal harmonic forcing
-
-                            CALL flush(numout)
-                            CALL dyn_nept_init  ! simplified form of Neptune effect
-                            CALL flush(numout)
+      IF( lk_bdy        )   CALL bdy_dta_init       ! Open boundaries initialisation of external data arrays
+      IF( lk_bdy        )   CALL    tide_init       ! Open boundaries initialisation of tidal harmonic forcing
 
                             CALL  istate_init   ! ocean initial state (Dynamics and tracers)
@@ -357,7 +353,8 @@
                             CALL dyn_zdf_init   ! vertical diffusion
                             CALL dyn_spg_init   ! surface pressure gradient
+                            CALL dyn_nept_init  ! Neptune effect (simplified form)
                             
       !                                     ! Misc. options
-      IF( nn_cla == 1   )   CALL cla_init       ! Cross Land Advection
+      IF( nn_cla == 1   )   CALL     cla_init   ! Cross Land Advection
       
 #if defined key_top
@@ -369,8 +366,8 @@
                             CALL     iom_init   ! iom_put initialization
       IF( lk_diaar5     )   CALL dia_ar5_init   ! ar5 diag
-                            CALL dia_ptr_init   ! Poleward TRansports initialization
+                            CALL dia_ptr_init   ! Poleward TRansports
       IF( lk_diadct     )   CALL dia_dct_init   ! Sections tranports
                             CALL dia_hsb_init   ! heat content, salt content and volume budgets
-                            CALL trd_mod_init   ! Mixed-layer/Vorticity/Integral constraints trends
+                            CALL     trd_init   ! momentum/tracer trends
       IF( lk_diaobs     ) THEN                  ! Observation & model comparison
                             CALL dia_obs_init            ! Initialize observational data
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/step.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 3318)
@@ -250,14 +250,4 @@
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Trends                              (ua, va, tsa used as workspace)
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( nstop == 0 ) THEN                         
-         IF( lk_trddyn     )   CALL trd_dwr( kstp )         ! trends: dynamics 
-         IF( lk_trdtra     )   CALL trd_twr( kstp )         ! trends: active tracers
-         IF( lk_trdmld     )   CALL trd_mld( kstp )         ! trends: Mixed-layer 
-         IF( lk_trdvor     )   CALL trd_vor( kstp )         ! trends: vorticity budget
-      ENDIF
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! Coupled mode
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/step_oce.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 3318)
@@ -75,10 +75,4 @@
 
    USE diawri           ! Standard run outputs             (dia_wri routine)
-   USE trdicp           ! Ocean momentum/tracers trends    (trd_wri routine)
-   USE trdmld           ! mixed-layer trends               (trd_mld routine)
-   USE trdmld_rst       ! restart for mixed-layer trends
-   USE trdmod_oce       ! ocean momentum/tracers trends
-   USE trdmod           ! momentum/tracers trends   
-   USE trdvor           ! vorticity budget                 (trd_vor routine)
    USE diaptr           ! poleward transports              (dia_ptr routine)
    USE diadct           ! sections transports              (dia_dct routine)
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/C14b/trcsms_c14b.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/C14b/trcsms_c14b.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/C14b/trcsms_c14b.F90	(revision 3318)
@@ -18,6 +18,6 @@
    USE par_trc       ! TOP parameters
    USE trc           ! TOP variables
-   USE trdmod_oce
-   USE trdmod_trc
+   USE trd_oce       ! trends: ocean variables
+   USE trdmod_trc    ! trends: passive tracer variables
    USE iom           ! I/O library
 
@@ -283,5 +283,5 @@
       ENDIF
 
-      IF( l_trdtrc )  CALL trd_mod_trc( tra(:,:,:,jpc14), jpc14, jptra_trd_sms, kt )   ! save trends
+      IF( l_trdtrc )  CALL trd_mod_trc( tra(:,:,:,jpc14), jpc14, jptra_sms, kt )   ! save trends
 
       CALL wrk_dealloc( jpi, jpj,      zatmbc14 )
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90	(revision 3318)
@@ -18,6 +18,6 @@
    USE par_trc       ! TOP parameters
    USE trc           ! TOP variables
-   USE trdmod_oce
-   USE trdmod_trc
+   USE trd_oce       ! trends: ocean variables
+   USE trdmod_trc    ! trends: passive tracer variables
    USE iom           ! I/O library
 
@@ -191,5 +191,5 @@
       IF( l_trdtrc ) THEN
           DO jn = jp_cfc0, jp_cfc1
-            CALL trd_mod_trc( tra(:,:,:,jn), jn, jptra_trd_sms, kt )   ! save trends
+            CALL trd_mod_trc( tra(:,:,:,jn), jn, jptra_sms, kt )   ! save trends
           END DO
       END IF
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/LOBSTER/trcbio.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/LOBSTER/trcbio.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/LOBSTER/trcbio.F90	(revision 3318)
@@ -2,10 +2,10 @@
    !!======================================================================
    !!                         ***  MODULE trcbio  ***
-   !! TOP :   LOBSTER
+   !! TOP :   LOBSTER bio model
    !!======================================================================
-   !! History :    -   !  1999-07  (M. Levy) Original code
-   !!              -   !  2000-12  (E. Kestenare) assign a parameter to name individual tracers
-   !!              -   !  2001-03  (M. Levy)  LNO3 + dia2d 
-   !!             2.0  !  2007-12  (C. Deltel, G. Madec)  F90
+   !! History :  OPA  !  1999-07  (M. Levy) Original code
+   !!             -   !  2000-12  (E. Kestenare) assign a parameter to name individual tracers
+   !!             -   !  2001-03  (M. Levy)  LNO3 + dia2d 
+   !!   NEMO     2.0  !  2007-12  (C. Deltel, G. Madec)  F90
    !!----------------------------------------------------------------------
 #if defined key_lobster
@@ -13,13 +13,13 @@
    !!   'key_lobster'                                     LOBSTER bio-model
    !!----------------------------------------------------------------------
-   !!   trc_bio        :  
-   !!----------------------------------------------------------------------
-   USE oce_trc         !
-   USE trc             ! 
-   USE sms_lobster     ! 
-   USE lbclnk          ! 
-   USE prtctl_trc      ! Print control for debbuging
-   USE trdmod_oce
-   USE trdmod_trc
+   !!   trc_bio       :  
+   !!----------------------------------------------------------------------
+   USE oce_trc        !
+   USE trc            ! 
+   USE sms_lobster    ! 
+   USE lbclnk         ! 
+   USE prtctl_trc     ! Print control for debbuging
+   USE trd_oce        ! trends: ocean variables
+   USE trdmod_trc     ! trends: passive tracer variables
    USE iom
    
@@ -27,5 +27,5 @@
    PRIVATE
 
-   PUBLIC   trc_bio    ! called in ???
+   PUBLIC   trc_bio   ! called in ???
 
    !!* Substitution
@@ -36,5 +36,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -60,7 +59,6 @@
       !!              for passive tracers are saved for futher diagnostics.
       !!---------------------------------------------------------------------
-      !!
       INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
-      !!
+      !
       INTEGER  ::   ji, jj, jk, jl
       REAL(wp) ::   zdet, zzoo, zphy, zno3, znh4, zdom      ! now concentrations
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/LOBSTER/trcexp.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/LOBSTER/trcexp.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/LOBSTER/trcexp.F90	(revision 3318)
@@ -4,7 +4,7 @@
    !! TOP :   PISCES Compute loss of organic matter in the sediments
    !!======================================================================
-   !! History :    -   !  1999    (O. Aumont, C. Le Quere)  original code
+   !! History :   OPA  !  1999    (O. Aumont, C. Le Quere)  original code
    !!              -   !  2001-05 (O. Aumont, E. Kestenare) add sediment computations
-   !!             1.0  !  2005-06 (A.-S. Kremeur) new temporal integration for sedpoc
+   !!   NEMO      1.0  !  2005-06 (A.-S. Kremeur) new temporal integration for sedpoc
    !!             2.0  !  2007-12  (C. Deltel, G. Madec)  F90
    !!----------------------------------------------------------------------
@@ -21,6 +21,6 @@
    USE trcnam_trp
    USE prtctl_trc      ! Print control for debbuging
-   USE trdmod_oce
-   USE trdmod_trc
+   USE trd_oce         ! trends: ocean variables
+   USE trdmod_trc      ! trends: passive tracer variables
    USE iom
 
@@ -37,5 +37,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -53,7 +52,6 @@
       !!              COLUMN BELOW THE SURFACE LAYER.
       !!---------------------------------------------------------------------
-      !!
       INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
-      !!
+      !
       INTEGER  ::   ji, jj, jk, jl, ikt, ierr
       REAL(wp) ::   zgeolpoc, zfact, zwork, ze3t, zsedpocd
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/LOBSTER/trcsed.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/LOBSTER/trcsed.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/LOBSTER/trcsed.F90	(revision 3318)
@@ -18,6 +18,6 @@
    USE sms_lobster
    USE lbclnk
-   USE trdmod_oce
-   USE trdmod_trc
+   USE trd_oce         ! trends: ocean variables
+   USE trdmod_trc      ! trends: passive tracer variables
    USE iom
    USE prtctl_trc      ! Print control for debbuging
@@ -35,5 +35,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -56,11 +55,10 @@
       !!              trend of passive tracers is saved for futher diagnostics.
       !!---------------------------------------------------------------------
-      !!
       INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
-      !!
+      !
       INTEGER  ::   ji, jj, jk, jl, ierr
       CHARACTER (len=25) :: charout
-      REAL(wp), POINTER, DIMENSION(:,:  ) :: zw2d
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwork, ztra, ztrbio
+      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zw2d
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zwork, ztra, ztrbio
       !!---------------------------------------------------------------------
       !
@@ -76,7 +74,5 @@
       CALL wrk_alloc( jpi, jpj, jpk, zwork, ztra )
 
-      IF( ln_diatrc )  THEN
-         CALL wrk_alloc( jpi, jpj, zw2d )
-      ENDIF
+      IF( ln_diatrc )   CALL wrk_alloc( jpi, jpj, zw2d )
 
       IF( l_trdtrc ) THEN
@@ -109,19 +105,13 @@
       IF( ln_diatrc ) THEN 
          DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zw2d(ji,jj) = zw2d(ji,jj) + ztra(ji,jj,jk) * fse3t(ji,jj,jk) * 86400.
-               END DO
-            END DO
+            zw2d(:,:) = zw2d(:,:) + ztra(:,:,jk) * fse3t(:,:,jk) * 86400._wp
          END DO
-         IF( lk_iomput )  THEN
-           CALL iom_put( "TDETSED", zw2d )
-         ELSE
-           trc2d(:,:,jp_lob0_2d + 7) = zw2d(:,:)
+         IF( lk_iomput ) THEN   ;   CALL iom_put( "TDETSED", zw2d )
+         ELSE                   ;   trc2d(:,:,jp_lob0_2d + 7) = zw2d(:,:)
          ENDIF
          CALL wrk_dealloc( jpi, jpj, zw2d )
       ENDIF
       !
-      IF( ln_diabio )  trbio(:,:,:,jp_lob0_trd + 7) = ztra(:,:,:)
+      IF( ln_diabio )   trbio(:,:,:,jp_lob0_trd + 7) = ztra(:,:,:)
       CALL wrk_dealloc( jpi, jpj, jpk, zwork, ztra )
       !
@@ -133,5 +123,5 @@
       ENDIF
 
-      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+      IF(ln_ctl) THEN      ! print mean trends (used for debugging)
          WRITE(charout, FMT="('sed')")
          CALL prt_ctl_trc_info(charout)
@@ -139,5 +129,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )  CALL timing_stop('trc_sed')
+      IF( nn_timing == 1 )   CALL timing_stop('trc_sed')
       !
    END SUBROUTINE trc_sed
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/LOBSTER/trcsms_lobster.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/LOBSTER/trcsms_lobster.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/LOBSTER/trcsms_lobster.F90	(revision 3318)
@@ -4,5 +4,5 @@
    !! TOP :   Time loop of LOBSTER model
    !!======================================================================
-   !! History :   1.0  !            M. Levy
+   !! History :   1.0  !  2004-02  (M. Levy)  original code
    !!             2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
    !!----------------------------------------------------------------------
@@ -13,5 +13,5 @@
    !!   trcsms_lobster        :  Time loop of passive tracers sms
    !!----------------------------------------------------------------------
-   USE oce_trc          !
+   USE oce_trc       !
    USE trc
    USE trcbio
@@ -19,6 +19,6 @@
    USE trcsed
    USE trcexp
-   USE trdmod_oce
-   USE trdmod_trc_oce
+   USE trd_oce       ! trends: ocean variables
+   USE trdmod_trc    ! trends: passive tracer variables
    USE trdmod_trc
    USE trdmld_trc
@@ -60,5 +60,5 @@
       IF( l_trdtrc ) THEN
          DO jn = jp_lob0, jp_lob1
-           CALL trd_mod_trc( tra(:,:,:,jn), jn, jptra_trd_sms, kt )   ! save trends
+           CALL trd_mod_trc( tra(:,:,:,jn), jn, jptra_sms, kt )   ! save trends
          END DO
       END IF
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcsms_my_trc.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcsms_my_trc.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcsms_my_trc.F90	(revision 3318)
@@ -13,9 +13,9 @@
    !! trc_sms_my_trc_alloc : allocate arrays specific to MY_TRC sms
    !!----------------------------------------------------------------------
-   USE par_trc         ! TOP parameters
-   USE oce_trc         ! Ocean variables
-   USE trc             ! TOP variables
-   USE trdmod_oce
-   USE trdmod_trc
+   USE par_trc       ! TOP parameters
+   USE oce_trc       ! Ocean variables
+   USE trc           ! TOP variables
+   USE trd_oce       ! trends: ocean variables
+   USE trdmod_trc    ! trends: passive tracer variables
 
    IMPLICIT NONE
@@ -42,9 +42,9 @@
       !! ** Method  : -
       !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       INTEGER ::   jn   ! dummy loop index
       REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrmyt
-!!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('trc_sms_my_trc')
@@ -71,5 +71,5 @@
           DO jn = jp_myt0, jp_myt1
             ztrmyt(:,:,:) = tra(:,:,:,jn)
-            CALL trd_mod_trc( ztrmyt, jn, jptra_trd_sms, kt )   ! save trends
+            CALL trd_mod_trc( ztrmyt, jn, jptra_sms, kt )   ! save trends
           END DO
           CALL wrk_dealloc( jpi, jpj, jpk, ztrmyt )
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/PISCES/trcsms_pisces.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/PISCES/trcsms_pisces.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/PISCES/trcsms_pisces.F90	(revision 3318)
@@ -4,6 +4,6 @@
    !! TOP :   PISCES Source Minus Sink manager
    !!======================================================================
-   !! History :   1.0  !  2004-03 (O. Aumont) Original code
-   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !! History :  1.0  !  2004-03 (O. Aumont) Original code
+   !!            2.0  !  2007-12  (C. Ethe, G. Madec)  F90
    !!----------------------------------------------------------------------
 #if defined key_pisces
@@ -11,30 +11,30 @@
    !!   'key_pisces'                                       PISCES bio-model
    !!----------------------------------------------------------------------
-   !!   trcsms_pisces        :  Time loop of passive tracers sms
-   !!----------------------------------------------------------------------
-   USE oce_trc         !  shared variables between ocean and passive tracers
-   USE trc             !  passive tracers common variables 
-   USE sms_pisces      !  PISCES Source Minus Sink variables
-   USE p4zbio          !  Biological model
-   USE p4zche          !  Chemical model
-   USE p4zlys          !  Calcite saturation
-   USE p4zflx          !  Gas exchange
-   USE p4zsed          !  Sedimentation
-   USE p4zint          !  time interpolation
-   USE trdmod_oce      !  Ocean trends variables
-   USE trdmod_trc      !  TOP trends variables
-   USE sedmodel        !  Sediment model
-   USE prtctl_trc      !  print control for debugging
+   !!   trcsms_pisces :  Time loop of passive tracers sms
+   !!----------------------------------------------------------------------
+   USE oce_trc        !  shared variables between ocean and passive tracers
+   USE trc            !  passive tracers common variables 
+   USE sms_pisces     !  PISCES Source Minus Sink variables
+   USE p4zbio         !  Biological model
+   USE p4zche         !  Chemical model
+   USE p4zlys         !  Calcite saturation
+   USE p4zflx         !  Gas exchange
+   USE p4zsed         !  Sedimentation
+   USE p4zint         !  time interpolation
+   USE trd_oce        ! trends: ocean variables
+   USE trdmod_trc     !  TOP trends variables
+   USE sedmodel       !  Sediment model
+   USE prtctl_trc     !  print control for debugging
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   trc_sms_pisces    ! called in trcsms.F90
-
-   LOGICAL ::  ln_check_mass = .false.       !: Flag to check mass conservation 
-
-   INTEGER ::  numno3  !: logical unit for NO3 budget
-   INTEGER ::  numalk  !: logical unit for talk budget
-   INTEGER ::  numsil  !: logical unit for Si budget
+   PUBLIC   trc_sms_pisces   ! called in trcsms.F90
+
+   LOGICAL ::   ln_check_mass = .false.   ! Flag to check mass conservation 
+
+   INTEGER ::   numno3   ! logical unit for NO3 budget
+   INTEGER ::   numalk   ! logical unit for talk budget
+   INTEGER ::   numsil   ! logical unit for Si budget
 
    !!----------------------------------------------------------------------
@@ -43,5 +43,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -57,12 +56,11 @@
       !!              - ...
       !!---------------------------------------------------------------------
-      !
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
-      !!
-      INTEGER ::   jnt, jn
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index      
+      !
+      INTEGER ::   jnt, jn   ! dummy loop indices
       CHARACTER (len=25) :: charout
       !!---------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('trc_sms_pisces')
+      IF( nn_timing == 1 )   CALL timing_start('trc_sms_pisces')
       !
       IF( ln_pisdmp .AND. MOD( kt - nn_dttrc, nn_pisdmp ) == 0 )   CALL trc_sms_pisces_dmp( kt )  ! Relaxation of some tracers
@@ -102,5 +100,5 @@
       IF( l_trdtrc ) THEN
           DO jn = jp_pcs0, jp_pcs1
-            CALL trd_mod_trc( tra(:,:,:,jn), jn, jptra_trd_sms, kt )   ! save trends
+            CALL trd_mod_trc( tra(:,:,:,jn), jn, jptra_sms, kt )   ! save trends
           END DO
       END IF
@@ -120,4 +118,5 @@
    END SUBROUTINE trc_sms_pisces
 
+
    SUBROUTINE trc_sms_pisces_dmp( kt )
       !!----------------------------------------------------------------------
@@ -126,15 +125,13 @@
       !! ** purpose  : Relaxation of some tracers
       !!----------------------------------------------------------------------
-      !
       INTEGER, INTENT( in )  ::     kt ! time step
       !
-      REAL(wp) ::  alkmean = 2426.     ! mean value of alkalinity ( Glodap ; for Goyet 2391. )
-      REAL(wp) ::  po4mean = 2.165     ! mean value of phosphates
-      REAL(wp) ::  no3mean = 30.90     ! mean value of nitrate
-      REAL(wp) ::  silmean = 91.51     ! mean value of silicate
-      !
-      REAL(wp) :: zarea, zalksum, zpo4sum, zno3sum, zsilsum
-      !!---------------------------------------------------------------------
-
+      REAL(wp) ::   alkmean = 2426.   ! mean value of alkalinity ( Glodap ; for Goyet 2391. )
+      REAL(wp) ::   po4mean = 2.165   ! mean value of phosphates
+      REAL(wp) ::   no3mean = 30.90   ! mean value of nitrate
+      REAL(wp) ::   silmean = 91.51   ! mean value of silicate
+      !
+      REAL(wp) ::   zarea, zalksum, zpo4sum, zno3sum, zsilsum   ! local scalars
+      !!---------------------------------------------------------------------
 
       IF(lwp)  WRITE(numout,*)
@@ -165,6 +162,7 @@
          !
       ENDIF
-
+      !
    END SUBROUTINE trc_sms_pisces_dmp
+
 
    SUBROUTINE trc_sms_pisces_mass_conserv ( kt )
@@ -173,14 +171,12 @@
       !!
       !! ** Purpose :  Mass conservation check 
-      !!
-      !!---------------------------------------------------------------------
-      !
+      !!---------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
-      !!
+      !
       REAL(wp) :: zalkbudget, zno3budget, zsilbudget
       !
       NAMELIST/nampismass/ ln_check_mass
       !!---------------------------------------------------------------------
-
+      !
       IF( kt == nittrc000 ) THEN 
          REWIND( numnatp )       
@@ -199,5 +195,5 @@
          ENDIF
       ENDIF
-
+      !
       IF( ln_check_mass ) THEN      !   Compute the budget of NO3, ALK, Si
          zno3budget = glob_sum( (   trn(:,:,:,jpno3) + trn(:,:,:,jpnh4)  &
@@ -206,12 +202,12 @@
             &                     + trn(:,:,:,jppoc) + trn(:,:,:,jpgoc)  &
             &                     + trn(:,:,:,jpdoc)                     ) * cvol(:,:,:)  ) 
-         ! 
+            ! 
          zsilbudget = glob_sum( (   trn(:,:,:,jpsil) + trn(:,:,:,jpgsi)  &
             &                     + trn(:,:,:,jpdsi)                     ) * cvol(:,:,:)  )
-         ! 
+            ! 
          zalkbudget = glob_sum( (   trn(:,:,:,jpno3) * rno3              &
             &                     + trn(:,:,:,jptal)                     &
             &                     + trn(:,:,:,jpcal) * 2.                ) * cvol(:,:,:)  )
-
+            !
          IF( lwp ) THEN
             WRITE(numno3,9500) kt,  zno3budget / areatot
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90	(revision 3318)
@@ -49,11 +49,8 @@
    INTEGER FUNCTION trc_adv_alloc()
       !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trc_adv_alloc  ***
-      !!----------------------------------------------------------------------
-
+      !!                  ***  FUNDCTION trc_adv_alloc  ***
+      !!----------------------------------------------------------------------
       ALLOCATE( r2dt(jpk), STAT=trc_adv_alloc )
-
       IF( trc_adv_alloc /= 0 ) CALL ctl_warn('trc_adv_alloc : failed to allocate array.')
-
    END FUNCTION trc_adv_alloc
 
@@ -67,10 +64,9 @@
       !! ** Method  : - Update the tracer with the advection term following nadv
       !!----------------------------------------------------------------------
-      !!
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !
       INTEGER ::   jk 
       CHARACTER (len=22) ::   charout
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zun, zvn, zwn  ! effective velocity
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zun, zvn, zwn  ! effective velocity
       !!----------------------------------------------------------------------
       !
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcbbl.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcbbl.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcbbl.F90	(revision 3318)
@@ -5,5 +5,4 @@
    !!                                  layer scheme
    !!======================================================================
-   !!==============================================================================
    !! History :  OPA  !  1996-06  (L. Mortier)  Original code
    !!            8.0  !  1997-11  (G. Madec)    Optimization
@@ -18,16 +17,15 @@
    !!   'key_trabbl                      diffusive or/and adevective bottom boundary layer
    !!----------------------------------------------------------------------
-   !!    trc_bbl       : update the tracer trends due to the bottom boundary layer (advective and/or diffusive)
+   !!    trc_bbl : update the tracer trends due to the bottom boundary layer (advective and/or diffusive)
    !!----------------------------------------------------------------------
-   USE oce_trc             ! ocean dynamics and active tracers variables
-   USE trc                 ! ocean passive tracers variables
+   USE oce_trc         ! ocean dynamics and active tracers variables
+   USE trc             ! ocean passive tracers variables
    USE trcnam_trp      ! passive tracers transport namelist variables
-   USE trabbl              ! 
-   USE prtctl_trc          ! Print control for debbuging
-   USE trdmod_oce
-   USE trdtra
+   USE trabbl          ! tracers: bottom boundary layer
+   USE prtctl_trc      ! Print control for debbuging
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends: tracer manager
 
-   PUBLIC   trc_bbl       !  routine called by step.F90
-
+   PUBLIC   trc_bbl    !  routine called by step.F90
 
    !! * Substitutions
@@ -38,7 +36,5 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
-
 
    SUBROUTINE trc_bbl( kt )
@@ -93,5 +89,5 @@
         DO jn = 1, jptra
            ztrtrd(:,:,:,jn) = tra(:,:,:,jn) - ztrtrd(:,:,:,jn)
-           CALL trd_tra( kt, 'TRC', jn, jptra_trd_ldf, ztrtrd(:,:,:,jn) )
+           CALL trd_tra( kt, 'TRC', jn, jptra_ldf, ztrtrd(:,:,:,jn) )
         END DO
         CALL wrk_dealloc( jpi, jpj, jpk, jptra, ztrtrd ) ! temporary save of trends
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcdmp.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcdmp.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcdmp.F90	(revision 3318)
@@ -153,5 +153,5 @@
          IF( l_trdtrc ) THEN
             ztrtrd(:,:,:) = tra(:,:,:,jn) -  ztrtrd(:,:,:)
-            CALL trd_tra( kt, 'TRC', jn, jptra_trd_dmp, ztrtrd )
+            CALL trd_tra( kt, 'TRC', jn, jptra_dmp, ztrtrd )
          END IF
          !                                                       ! ===========
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcldf.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcldf.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcldf.F90	(revision 3318)
@@ -4,11 +4,10 @@
    !! Ocean Passive tracers : lateral diffusive trends
    !!=====================================================================
-   !! History :  9.0  ! 2005-11 (G. Madec)  Original code
-   !!       NEMO 3.0  ! 2008-01  (C. Ethe, G. Madec)  merge TRC-TRA
+   !! History :  1.0  ! 2005-11  (G. Madec)  Original code
+   !!            3.0  ! 2008-01  (C. Ethe, G. Madec)  merge TRC-TRA
    !!----------------------------------------------------------------------
 #if defined key_top
    !!----------------------------------------------------------------------
    !!   'key_top'                                                TOP models
-   !!----------------------------------------------------------------------
    !!----------------------------------------------------------------------
    !!   trc_ldf     : update the tracer trend with the lateral diffusion
@@ -25,6 +24,6 @@
    USE traldf_iso_grif ! lateral mixing          (tra_ldf_iso_grif routine)
    USE traldf_lap      ! lateral mixing            (tra_ldf_lap routine)
-   USE trdmod_oce
-   USE trdtra
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends: tracer manager
    USE prtctl_trc      ! Print control
 
@@ -36,4 +35,5 @@
    REAL(wp) ::  rldf_rat    ! ratio between active and passive tracers diffusive coefficient
    INTEGER  ::  nldf = 0   ! type of lateral diffusion used defined from ln_trcldf_... namlist logicals)
+
    !! * Substitutions
 #  include "domzgr_substitute.h90"
@@ -44,5 +44,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -105,5 +104,5 @@
         DO jn = 1, jptra
            ztrtrd(:,:,:,jn) = tra(:,:,:,jn) - ztrtrd(:,:,:,jn)
-           CALL trd_tra( kt, 'TRC', jn, jptra_trd_ldf, ztrtrd(:,:,:,jn) )
+           CALL trd_tra( kt, 'TRC', jn, jptra_ldf, ztrtrd(:,:,:,jn) )
         END DO
         CALL wrk_dealloc( jpi, jpj, jpk, jptra, ztrtrd )
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 3318)
@@ -30,7 +30,7 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE prtctl_trc      ! Print control for debbuging
-   USE trdmod_oce
-   USE trdtra
-   USE tranxt
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends: tracer manager
+   USE tranxt          ! 
 # if defined key_agrif
    USE agrif_top_update
@@ -157,5 +157,5 @@
                zfact = 1.e0 / r2dt(jk)  
                ztrdt(:,:,jk,jn) = ( trb(:,:,jk,jn) - ztrdt(:,:,jk,jn) ) * zfact 
-               CALL trd_tra( kt, 'TRC', jn, jptra_trd_atf, ztrdt )
+               CALL trd_tra( kt, 'TRC', jn, jptra_atf, ztrdt )
             END DO
          END DO
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcrad.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcrad.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcrad.F90	(revision 3318)
@@ -4,6 +4,6 @@
    !! Ocean passive tracers:  correction of negative concentrations
    !!======================================================================
-   !! History :   -   !  01-01  (O. Aumont & E. Kestenare)  Original code
-   !!            1.0  !  04-03  (C. Ethe)  free form F90
+   !! History :  OPA  !  2001-01  (O. Aumont & E. Kestenare)  Original code
+   !!   NEMO     1.0  !  2004-03  (C. Ethe)  free form F90
    !!----------------------------------------------------------------------
 #if defined key_top
@@ -11,16 +11,16 @@
    !!   'key_top'                                                TOP models
    !!----------------------------------------------------------------------
-   !!   trc_rad    : correction of negative concentrations
-   !!----------------------------------------------------------------------
-   USE oce_trc             ! ocean dynamics and tracers variables
-   USE trc                 ! ocean passive tracers variables
-   USE trdmod_oce
-   USE trdtra
-   USE prtctl_trc          ! Print control for debbuging
+   !!   trc_rad       : correction of negative concentrations
+   !!----------------------------------------------------------------------
+   USE oce_trc        ! ocean dynamics and tracers variables
+   USE trc            ! ocean passive tracers variables
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! trends: tracer manager
+   USE prtctl_trc     ! Print control for debbuging
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC trc_rad         ! routine called by trcstp.F90
+   PUBLIC   trc_rad   ! routine called by trcstp.F90
 
    !! * Substitutions
@@ -31,5 +31,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-   
 CONTAINS
 
@@ -49,5 +48,6 @@
       !!                (the total CFC content is not strictly preserved)
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index      
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !
       CHARACTER (len=22) :: charout
       !!----------------------------------------------------------------------
@@ -77,4 +77,5 @@
       !
    END SUBROUTINE trc_rad
+
 
    SUBROUTINE trc_rad_sms( kt, ptrb, ptrn, jp_sms0, jp_sms1, cpreserv )
@@ -94,35 +95,26 @@
       !!                  (the total content of concentration is not strictly preserved)
       !!--------------------------------------------------------------------------------
-      !! Arguments
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
-      INTEGER  , INTENT( in ) ::  &
-         jp_sms0, &       !: First index of the passive tracer model
-         jp_sms1          !: Last  index of  the passive tracer model
-
-      REAL(wp), DIMENSION (jpi,jpj,jpk,jptra), INTENT( inout )  :: &
-         ptrb, ptrn       !: before and now traceur concentration
-
-      CHARACTER( len = 1) , INTENT(in), OPTIONAL  :: &
-         cpreserv          !: flag to preserve content or not
-      
-      ! Local declarations
-      INTEGER  :: ji, jj, jk, jn     ! dummy loop indices
-      REAL(wp) :: ztrcorb, ztrmasb   ! temporary scalars
-      REAL(wp) :: zcoef, ztrcorn, ztrmasn   !    "         "
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrtrdb, ztrtrdn   ! workspace arrays
-      REAL(wp) :: zs2rdt
-      LOGICAL ::   lldebug = .FALSE.
-      !!----------------------------------------------------------------------
-
+      INTEGER                                , INTENT(in   ) ::   kt                 ! ocean time-step index
+      INTEGER                                , INTENT(in   ) ::   jp_sms0, jp_sms1   ! first/last index of the passive tracer model
+      REAL(wp), DIMENSION (jpi,jpj,jpk,jptra), INTENT(inout) ::   ptrb, ptrn         ! before/now traceur concentration
+      CHARACTER( len = 1),      OPTIONAL     , INTENT(in   ) ::   cpreserv           ! flag to preserve content or not
+      !
+      INTEGER  ::   ji, jj, jk, jn             ! dummy loop indices
+      REAL(wp) ::   ztrcorb, ztrmasb, zs2rdt   ! local scalars
+      REAL(wp) ::   zcoef, ztrcorn, ztrmasn    !   -      -
+      LOGICAL  ::   lldebug = .FALSE.
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrtrdb, ztrtrdn   ! 3D workspace
+      !!----------------------------------------------------------------------
  
       IF( l_trdtrc )  CALL wrk_alloc( jpi, jpj, jpk, ztrtrdb, ztrtrdn )
       
       IF( PRESENT( cpreserv )  ) THEN   !  total tracer concentration is preserved 
-      
+         !                                                           ! ===========
+
          DO jn = jp_sms0, jp_sms1
-            !                                                        ! ===========
-            ztrcorb = 0.e0   ;   ztrmasb = 0.e0
-            ztrcorn = 0.e0   ;   ztrmasn = 0.e0
-
+            !
+            ztrcorb = 0._wp   ;   ztrmasb = 0._wp
+            ztrcorn = 0._wp   ;   ztrmasn = 0._wp
+            !
             IF( l_trdtrc ) THEN
                ztrtrdb(:,:,:) = ptrb(:,:,:,jn)                        ! save input trb for trend computation
@@ -132,8 +124,7 @@
             ztrcorb = glob_sum( MIN( 0., ptrb(:,:,:,jn) ) * cvol(:,:,:) )
             ztrcorn = glob_sum( MIN( 0., ptrn(:,:,:,jn) ) * cvol(:,:,:) )
-
             ztrmasb = glob_sum( MAX( 0., ptrb(:,:,:,jn) ) * cvol(:,:,:) )
             ztrmasn = glob_sum( MAX( 0., ptrn(:,:,:,jn) ) * cvol(:,:,:) )
-
+            !
             IF( ztrcorb /= 0 ) THEN
                zcoef = 1. + ztrcorb / ztrmasb
@@ -143,5 +134,5 @@
                END DO
             ENDIF
-
+            !
             IF( ztrcorn /= 0 ) THEN
                zcoef = 1. + ztrcorn / ztrmasn
@@ -157,21 +148,21 @@
                ztrtrdb(:,:,:) = ( ptrb(:,:,:,jn) - ztrtrdb(:,:,:) ) * zs2rdt
                ztrtrdn(:,:,:) = ( ptrn(:,:,:,jn) - ztrtrdn(:,:,:) ) * zs2rdt 
-               CALL trd_tra( kt, 'TRC', jn, jptra_trd_radb, ztrtrdb )       ! Asselin-like trend handling
-               CALL trd_tra( kt, 'TRC', jn, jptra_trd_radn, ztrtrdn )       ! standard     trend handling
+               CALL trd_tra( kt, 'TRC', jn, jptra_radb, ztrtrdb )       ! Asselin-like trend handling
+               CALL trd_tra( kt, 'TRC', jn, jptra_radn, ztrtrdn )       ! standard     trend handling
               !
             ENDIF
-
+            !
          END DO
          !
          !
       ELSE  ! total CFC content is not strictly preserved
-
+         !
          DO jn = jp_sms0, jp_sms1  
-
-           IF( l_trdtrc ) THEN
-              ztrtrdb(:,:,:) = ptrb(:,:,:,jn)                        ! save input trb for trend computation
-              ztrtrdn(:,:,:) = ptrn(:,:,:,jn)                        ! save input trn for trend computation
-           ENDIF
-
+            !
+            IF( l_trdtrc ) THEN
+               ztrtrdb(:,:,:) = ptrb(:,:,:,jn)                        ! save input trb for trend computation
+               ztrtrdn(:,:,:) = ptrn(:,:,:,jn)                        ! save input trn for trend computation
+            ENDIF
+            !
             DO jk = 1, jpkm1
                DO jj = 1, jpj
@@ -182,22 +173,21 @@
                END DO
             END DO
-         
-            IF( l_trdtrc ) THEN
-               !
+            !
+            IF( l_trdtrc ) THEN
                zs2rdt = 1. / ( 2. * rdt * FLOAT( nn_dttrc ) )
                ztrtrdb(:,:,:) = ( ptrb(:,:,:,jn) - ztrtrdb(:,:,:) ) * zs2rdt
                ztrtrdn(:,:,:) = ( ptrn(:,:,:,jn) - ztrtrdn(:,:,:) ) * zs2rdt 
-               CALL trd_tra( kt, 'TRC', jn, jptra_trd_radb, ztrtrdb )       ! Asselin-like trend handling
-               CALL trd_tra( kt, 'TRC', jn, jptra_trd_radn, ztrtrdn )       ! standard     trend handling
-              !
-            ENDIF
-            !
-         ENDDO
-
+               CALL trd_tra( kt, 'TRC', jn, jptra_radb, ztrtrdb )       ! Asselin-like trend handling
+               CALL trd_tra( kt, 'TRC', jn, jptra_radn, ztrtrdn )       ! standard     trend handling
+            ENDIF
+            !
+         END DO
+         !
       ENDIF
-
+      !
       IF( l_trdtrc )  CALL wrk_dealloc( jpi, jpj, jpk, ztrtrdb, ztrtrdn )
-
+      !
    END SUBROUTINE trc_rad_sms
+
 #else
    !!----------------------------------------------------------------------
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 3318)
@@ -4,9 +4,6 @@
    !! Ocean passive tracers:  surface boundary condition
    !!======================================================================
-   !! History :  8.2  !  1998-10  (G. Madec, G. Roullet, M. Imbard)  Original code
-   !!            8.2  !  2001-02  (D. Ludicone)  sea ice and free surface
-   !!            8.5  !  2002-06  (G. Madec)  F90: Free form and module
-   !!            9.0  !  2004-03  (C. Ethe)  adapted for passive tracers
-   !!                 !  2006-08  (C. Deltel) Diagnose ML trends for passive tracers
+   !! History :  1.0  !  2004-03  (C. Ethe)  adapt trasbc to passive tracers
+   !!            2.0  !  2006-08  (C. Deltel) Diagnose ML trends for passive tracers
    !!==============================================================================
 #if defined key_top
@@ -19,6 +16,6 @@
    USE trc             ! ocean  passive tracers variables
    USE prtctl_trc      ! Print control for debbuging
-   USE trdmod_oce
-   USE trdtra
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends: tracer manager
 
    IMPLICIT NONE
@@ -44,6 +41,5 @@
       !!       trend of tracer equations.
       !!
-      !! ** Method :
-      !!      * concentration/dilution effect:
+      !! ** Method :    concentration/dilution effect:
       !!            The surface freshwater flux modify the ocean volume
       !!         and thus the concentration of a tracer as :
@@ -55,14 +51,12 @@
       !! ** Action  : - Update the 1st level of tra with the trend associated
       !!                with the tracer surface boundary condition 
-      !!
       !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
       !
-      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
-      !
-      INTEGER  ::   ji, jj, jn           ! dummy loop indices
+      INTEGER  ::   ji, jj, jn     ! dummy loop indices
       REAL(wp) ::   zsrau, zse3t   ! temporary scalars
-      CHARACTER (len=22) :: charout
-      REAL(wp), POINTER, DIMENSION(:,:  ) :: zemps
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrtrd
+      CHARACTER (len=22) ::   charout
+      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zemps    ! 2D workspace
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrtrd   ! 3D workspace
       !!---------------------------------------------------------------------
       !
@@ -108,5 +102,5 @@
          IF( l_trdtrc ) THEN
             ztrtrd(:,:,:) = tra(:,:,:,jn) - ztrtrd(:,:,:)
-            CALL trd_tra( kt, 'TRC', jn, jptra_trd_nsr, ztrtrd )
+            CALL trd_tra( kt, 'TRC', jn, jptra_nsr, ztrtrd )
          END IF
          !                                                       ! ===========
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 3318)
@@ -44,5 +44,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -56,5 +55,5 @@
       !!              - Update the passive tracers
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::  kstp  ! ocean time-step index
+      INTEGER, INTENT( in ) ::   kstp   ! ocean time-step index
       !! ---------------------------------------------------------------------
       !
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90	(revision 3318)
@@ -4,6 +4,6 @@
    !! Ocean Passive tracers : vertical diffusive trends 
    !!=====================================================================
-   !! History :  9.0  ! 2005-11 (G. Madec)  Original code
-   !!       NEMO 3.0  ! 2008-01  (C. Ethe, G. Madec)  merge TRC-TRA 
+   !! History :  1.0  ! 2005-11  (G. Madec)  Original code
+   !!            3.0  ! 2008-01  (C. Ethe, G. Madec)  merge TRC-TRA 
    !!----------------------------------------------------------------------
 #if defined key_top
@@ -14,18 +14,18 @@
    !!       ldf_ctl : initialization, namelist read, and parameters control
    !!----------------------------------------------------------------------
-   USE oce_trc         ! ocean dynamics and active tracers
-   USE trc             ! ocean passive tracers variables
-   USE trcnam_trp      ! passive tracers transport namelist variables
-   USE trazdf_exp      ! vertical diffusion: explicit (tra_zdf_exp     routine)
-   USE trazdf_imp      ! vertical diffusion: implicit (tra_zdf_imp     routine)
-   USE trdmod_oce
-   USE trdtra
-   USE prtctl_trc      ! Print control
+   USE oce_trc       ! ocean dynamics and active tracers
+   USE trc           ! ocean passive tracers variables
+   USE trcnam_trp    ! passive tracers transport namelist variables
+   USE trazdf_exp    ! vertical diffusion: explicit (tra_zdf_exp     routine)
+   USE trazdf_imp    ! vertical diffusion: implicit (tra_zdf_imp     routine)
+   USE trd_oce       ! trends: ocean variables
+   USE trdtra        ! trends: tracer manager
+   USE prtctl_trc    ! Print control
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   trc_zdf          ! called by step.F90 
-   PUBLIC   trc_zdf_alloc    ! called by nemogcm.F90 
+   PUBLIC   trc_zdf         ! called by step.F90 
+   PUBLIC   trc_zdf_alloc   ! called by nemogcm.F90 
 
    INTEGER ::   nzdf = 0               ! type vertical diffusion algorithm used
@@ -50,7 +50,5 @@
       !!----------------------------------------------------------------------
       ALLOCATE( r2dt(jpk) , STAT=trc_zdf_alloc )
-      !
       IF( trc_zdf_alloc /= 0 )   CALL ctl_warn('trc_zdf_alloc : failed to allocate array.')
-      !
    END FUNCTION trc_zdf_alloc
 
@@ -62,8 +60,8 @@
       !! ** Purpose :   compute the vertical ocean tracer physics.
       !!---------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::  kt      ! ocean time-step index
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
       !
-      INTEGER               ::  jk, jn
-      CHARACTER (len=22)    :: charout
+      INTEGER            ::  jk, jn
+      CHARACTER (len=22) :: charout
       REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   ztrtrd   ! 4D workspace
       !!---------------------------------------------------------------------
@@ -106,5 +104,5 @@
                ztrtrd(:,:,jk,jn) = ( ( tra(:,:,jk,jn) - trb(:,:,jk,jn) ) / r2dt(jk) ) - ztrtrd(:,:,jk,jn)
             END DO
-            CALL trd_tra( kt, 'TRC', jn, jptra_trd_zdf, ztrtrd(:,:,:,jn) )
+            CALL trd_tra( kt, 'TRC', jn, jptra_zdf, ztrtrd(:,:,:,jn) )
          END DO
          CALL wrk_dealloc( jpi, jpj, jpk, jptra, ztrtrd )
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trdmld_trc.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trdmld_trc.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trdmld_trc.F90	(revision 3318)
@@ -4,7 +4,7 @@
    !! Ocean diagnostics:  mixed layer passive tracer trends 
    !!======================================================================
-   !! History :  9.0  !  06-08  (C. Deltel)  Original code (from trdmld.F90)
-   !!                 !  07-04  (C. Deltel)  Bug fix : add trcrad trends
-   !!                 !  07-06  (C. Deltel)  key_gyre : do not call lbc_lnk
+   !! History :  1.0  !  2006-08  (C. Deltel)  Original code (from trdmld.F90)
+   !!             -   !  2007-04  (C. Deltel)  Bug fix : add trcrad trends
+   !!             -   !  2007-06  (C. Deltel)  key_gyre : do not call lbc_lnk
    !!----------------------------------------------------------------------
 #if   defined key_top && ( defined key_trdmld_trc   ||   defined key_esopa )
@@ -23,17 +23,18 @@
    USE zdfddm  , ONLY : avs  !: salinity vertical diffusivity coeff. at w-point
 # endif
+   USE trdmld_trc_rst    ! restart for diagnosing the ML trends
    USE trcnam_trp        ! passive tracers transport namelist variables
    USE trdmod_trc_oce    ! definition of main arrays used for trends computations
-   USE in_out_manager    ! I/O manager
    USE dianam            ! build the name of file (routine)
    USE ldfslp            ! iso-neutral slopes 
+   USE in_out_manager    ! I/O manager
    USE ioipsl            ! NetCDF library
    USE lbclnk            ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp           ! MPP library
-   USE trdmld_trc_rst    ! restart for diagnosing the ML trends
    USE prtctl            ! print control
    USE sms_pisces        ! PISCES bio-model
    USE sms_lobster       ! LOBSTER bio-model
-
+   USE wrk_nemo          ! Memory Allocation
+   
    IMPLICIT NONE
    PRIVATE
@@ -46,6 +47,6 @@
    PUBLIC trd_mld_bio_zint
 
-   CHARACTER (LEN=40) ::  clhstnam                                ! name of the trends NetCDF file
-   INTEGER ::   nmoymltrd
+   CHARACTER (LEN=40) ::   clhstnam                                ! name of the trends NetCDF file
+   INTEGER            ::   nmoymltrd
    INTEGER, ALLOCATABLE, SAVE, DIMENSION(:) ::   ndextrd1
    INTEGER, DIMENSION(jptra) ::   nidtrd, nh_t
@@ -61,10 +62,9 @@
 
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  ztmltrd2   !
-#if defined key_lobster
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  ztmltrdbio2  ! only needed for mean diagnostics in trd_mld_bio()
-#endif
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  ztmltrdbio2  ! only needed for mean diagnostics in trd_mld_bio()
 
    !! * Substitutions
 #  include "top_substitute.h90"
+#  include "zdfddm_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -367,28 +367,26 @@
       !!       In IV), the appropriate trends are written in the trends NetCDF file.
       !!
-      !! References :
-      !!       - Vialard & al.
-      !!       - See NEMO documentation (in preparation)
-      !!----------------------------------------------------------------------
-      !
+      !! References: Vialard et al., 2001, JPO.
+      !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !
-      INTEGER ::   ji, jj, jk, jl, ik, it, itmod, jn
-      REAL(wp) ::   zavt, zfn, zfn2
-      !
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltot             ! d(trc)/dt over the anlysis window (incl. Asselin)
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlres             ! residual = dh/dt entrainment term
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlatf             ! for storage only
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlrad             ! for storage only (for trb<0 corr in trcrad)
-      !
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltot2            ! -+
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlres2            !  | working arrays to diagnose the trends
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltrdm2           !  | associated with the time meaned ML
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlatf2            !  | passive tracers
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlrad2            !  | (-> for trb<0 corr in trcrad)
+      INTEGER ::   ji, jj, jk, jl      ! dummy loop indices
+      INTEGER ::   ik, it, itmod, jn   ! local integers
+      REAL(wp)::   zavt, zfn, zfn2    ! local scalars
+      !
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltot   ! d(trc)/dt over the anlysis window (incl. Asselin)
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlres   ! residual = dh/dt entrainment term
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlatf   ! for storage only
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlrad   ! for storage only (for trb<0 corr in trcrad)
+      !
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltot2   ! -+
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlres2   !  | working arrays to diagnose the trends
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltrdm2  !  | associated with the time meaned ML
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlatf2   !  | passive tracers
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlrad2   !  | (-> for trb<0 corr in trcrad)
       !
       CHARACTER (LEN= 5) ::   clvar
 #if defined key_dimgout
-      INTEGER ::   iyear,imon,iday
+      INTEGER ::   iyear, imon, iday
       CHARACTER(LEN=80) ::   cltext, clmode
 #endif
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trdmod_trc.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trdmod_trc.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trdmod_trc.F90	(revision 3318)
@@ -11,12 +11,12 @@
    !!   'key_trdtrc'                      3D trend diagnostics
    !!----------------------------------------------------------------------
-   !!   trd_mod_trc      : passive tracer trends 
+   !!   trd_mod_trc   : passive tracer trends 
    !!----------------------------------------------------------------------
-   USE trc               ! tracer definitions (trn, trb, tra, etc.)
-   USE trcnam_trp
-   USE trdmod_oce
-   USE trdmod_trc_oce    ! definition of main arrays used for trends computations
-   USE trdmld_trc        ! Mixed layer trends diag.
-   USE iom               ! I/O library
+   USE trc            ! passive tracer variables
+   USE trcnam_trp     ! 
+   USE trd_oce        ! trends: ocean variables
+   USE trdmod_trc_oce ! definition of main arrays used for trends computations
+   USE trdmld_trc     ! Mixed layer trends diag.
+   USE iom            ! I/O library
 
    IMPLICIT NONE
@@ -24,8 +24,8 @@
 
    INTERFACE trd_mod_trc
-      MODULE PROCEDURE trd_mod_trc_trp, trd_mod_trc_bio
+      MODULE PROCEDURE   trd_mod_trc_trp, trd_mod_trc_bio
    END INTERFACE
 
-   PUBLIC trd_mod_trc
+   PUBLIC   trd_mod_trc   !
 
    !! * Substitutions
@@ -36,5 +36,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -43,8 +42,9 @@
       !!                  ***  ROUTINE trd_mod_trc  ***
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in )  ::   kt                                  ! time step
-      INTEGER, INTENT( in )  ::   kjn                                 ! tracer index
-      INTEGER, INTENT( in )  ::   ktrd                                ! tracer trend index
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout )  ::   ptrtrd  ! Temperature or U trend
+      INTEGER                         , INTENT(in   ) ::   kt       ! time step
+      INTEGER                         , INTENT(in   ) ::   kjn      ! tracer index
+      INTEGER                         , INTENT(in   ) ::   ktrd     ! tracer trend index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptrtrd   ! Temperature or U trend
+      !
       CHARACTER (len=20) :: cltra
       !!----------------------------------------------------------------------
@@ -62,21 +62,19 @@
          !
          SELECT CASE ( ktrd )
-         CASE ( jptra_trd_xad     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_xad, '3D', kjn )
-         CASE ( jptra_trd_yad     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_yad, '3D', kjn )
-         CASE ( jptra_trd_zad     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_zad, '3D', kjn )
-         CASE ( jptra_trd_ldf     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_ldf, '3D', kjn )
-         CASE ( jptra_trd_bbl     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_bbl, '3D', kjn )
-         CASE ( jptra_trd_zdf     )
-            IF( ln_trcldf_iso ) THEN
-               CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_ldf, '3D', kjn )
-            ELSE
-               CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_zdf, '3D', kjn )
+         CASE ( jptra_xad  )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_xad, '3D', kjn )
+         CASE ( jptra_yad  )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_yad, '3D', kjn )
+         CASE ( jptra_zad  )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_zad, '3D', kjn )
+         CASE ( jptra_ldf  )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_ldf, '3D', kjn )
+         CASE ( jptra_bbl  )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_bbl, '3D', kjn )
+         CASE ( jptra_zdf  )
+            IF( ln_trcldf_iso ) THEN   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_ldf, '3D', kjn )
+            ELSE                       ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_zdf, '3D', kjn )
             ENDIF
-         CASE ( jptra_trd_dmp     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_dmp , '3D', kjn )
-         CASE ( jptra_trd_nsr     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_sbc , '2D', kjn )
-         CASE ( jptra_trd_sms     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_sms , '3D', kjn )
-         CASE ( jptra_trd_radb    )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_radb, '3D', kjn )
-         CASE ( jptra_trd_radn    )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_radn, '3D', kjn )
-         CASE ( jptra_trd_atf     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_atf , '3D', kjn )
+         CASE ( jptra_dmp  )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_dmp , '3D', kjn )
+         CASE ( jptra_nsr  )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_sbc , '2D', kjn )
+         CASE ( jptra_sms  )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_sms , '3D', kjn )
+         CASE ( jptra_radb )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_radb, '3D', kjn )
+         CASE ( jptra_radn )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_radn, '3D', kjn )
+         CASE ( jptra_atf  )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_atf , '3D', kjn )
          END SELECT
          !
@@ -86,14 +84,15 @@
          !
          SELECT CASE( ktrd )
-         CASE( jptra_trd_xad )       ;    WRITE (cltra,'("XAD_",16a)')   ctrcnm(kjn)
-         CASE( jptra_trd_yad )       ;    WRITE (cltra,'("YAD_",16a)')   ctrcnm(kjn)
-         CASE( jptra_trd_zad )       ;    WRITE (cltra,'("ZAD_",16a)')   ctrcnm(kjn)
-         CASE( jptra_trd_ldf )       ;    WRITE (cltra,'("LDF_",16a)')   ctrcnm(kjn)
-         CASE( jptra_trd_bbl )       ;    WRITE (cltra,'("BBL_",16a)')   ctrcnm(kjn)
-         CASE( jptra_trd_zdf )       ;    WRITE (cltra,'("ZDF_",16a)')   ctrcnm(kjn)
-         CASE( jptra_trd_dmp )       ;    WRITE (cltra,'("DMP_",16a)')   ctrcnm(kjn)
-         CASE( jptra_trd_nsr )       ;    WRITE (cltra,'("FOR_",16a)')   ctrcnm(kjn)
+         CASE( jptra_xad  )   ;    WRITE (cltra,'("XAD_",16a)')   ctrcnm(kjn)
+         CASE( jptra_yad  )   ;    WRITE (cltra,'("YAD_",16a)')   ctrcnm(kjn)
+         CASE( jptra_zad  )   ;    WRITE (cltra,'("ZAD_",16a)')   ctrcnm(kjn)
+         CASE( jptra_ldf  )   ;    WRITE (cltra,'("LDF_",16a)')   ctrcnm(kjn)
+         CASE( jptra_bbl  )   ;    WRITE (cltra,'("BBL_",16a)')   ctrcnm(kjn)
+         CASE( jptra_zdf  )   ;    WRITE (cltra,'("ZDF_",16a)')   ctrcnm(kjn)
+         CASE( jptra_dmp  )   ;    WRITE (cltra,'("DMP_",16a)')   ctrcnm(kjn)
+         CASE( jptra_nsr  )   ;    WRITE (cltra,'("FOR_",16a)')   ctrcnm(kjn)
          END SELECT
-                                          CALL iom_put( cltra,  ptrtrd(:,:,:) )
+         !
+         CALL iom_put( cltra,  ptrtrd(:,:,:) )
          !
       END IF
@@ -101,28 +100,26 @@
    END SUBROUTINE trd_mod_trc_trp
 
+
    SUBROUTINE trd_mod_trc_bio( ptrbio, ktrd, kt )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE trd_mod_bio  ***
       !!----------------------------------------------------------------------
-
-      INTEGER, INTENT( in )  ::   kt                                  ! time step
-      INTEGER, INTENT( in )  ::   ktrd                                ! bio trend index
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout )  ::   ptrbio  ! Bio trend
+      INTEGER                         , INTENT(in   )  ::   kt       ! time step
+      INTEGER                         , INTENT(in   )  ::   ktrd     ! bio trend index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout)  ::   ptrbio   ! Bio trend
       !!----------------------------------------------------------------------
-
-      CALL trd_mld_bio_zint( ptrbio, ktrd ) ! Verticaly integrated biological trends
-
+      !
+      CALL trd_mld_bio_zint( ptrbio, ktrd )       ! Verticaly integrated biological trends
+      !
    END SUBROUTINE trd_mod_trc_bio
+   
 #else
    !!----------------------------------------------------------------------
    !!   Default option :                                       Empty module
    !!----------------------------------------------------------------------
-
    INTERFACE trd_mod_trc
       MODULE PROCEDURE trd_mod_trc_trp, trd_mod_trc_bio
    END INTERFACE
-
 CONTAINS
-
    SUBROUTINE trd_mod_trc_trp( ptrtrd, kjn, ktrd, kt )
       INTEGER               , INTENT( in )     ::   kt      ! time step
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trdmod_trc_oce.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trdmod_trc_oce.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/TRP/trdmod_trc_oce.F90	(revision 3318)
@@ -38,17 +38,17 @@
 
    INTEGER, PARAMETER ::            & !: mixed layer trends indices
-        jpmld_trc_xad     =  1,     & !:     zonal      \
-        jpmld_trc_yad     =  2,     & !:     meridonal   > advection
-        jpmld_trc_zad     =  3,     & !:     vertical   /
-        jpmld_trc_ldf     =  4,     & !:     lateral diffusion (geopot. or iso-neutral)
-        jpmld_trc_zdf     =  5,     & !:     vertical diffusion (TKE)
-        jpmld_trc_bbl     =  6,     & !:     bottom boundary layer (advective/diffusive)
-        jpmld_trc_dmp     =  7,     & !:     internal restoring trend
-        jpmld_trc_sbc     =  8,     & !:     forcing 
-        jpmld_trc_sms     =  9,     & !:     sources minus sinks trend
-  !     jpmld_trc_xxx     = xx,     & !:     add here any additional trend    (** AND UPDATE JPLTRD_TRC BELOW **)
-        jpmld_trc_radn    = 10,     & !:     corr. trn<0 in trcrad
-        jpmld_trc_radb    = 11,     & !:     corr. trb<0 in trcrad (like atf) (** MUST BE BEFORE THE LAST ONE **)
-        jpmld_trc_atf     = 12        !:     asselin trend                    (** MUST BE    THE      LAST ONE**)
+        jpmld_trc_xad     =  1,     & !: zonal     advection
+        jpmld_trc_yad     =  2,     & !: meridonal advection
+        jpmld_trc_zad     =  3,     & !: vertical  advection
+        jpmld_trc_ldf     =  4,     & !: lateral diffusion (geopot. or iso-neutral)
+        jpmld_trc_zdf     =  5,     & !: vertical diffusion (TKE)
+        jpmld_trc_bbl     =  6,     & !: bottom boundary layer (advective/diffusive)
+        jpmld_trc_dmp     =  7,     & !: internal restoring trend
+        jpmld_trc_sbc     =  8,     & !: forcing 
+        jpmld_trc_sms     =  9,     & !: sources minus sinks trend
+  !     jpmld_trc_xxx     = xx,     & !: add here any additional trend    (** AND UPDATE JPLTRD_TRC BELOW **)
+        jpmld_trc_radn    = 10,     & !: corr. trn<0 in trcrad
+        jpmld_trc_radb    = 11,     & !: corr. trb<0 in trcrad (like atf) (** MUST BE BEFORE THE LAST ONE **)
+        jpmld_trc_atf     = 12        !: asselin trend                    (** MUST BE    THE      LAST ONE**)
 
    !! Trends diagnostics parameters
@@ -73,8 +73,8 @@
 
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  &
-      tml_trc    ,                        &      !: \ "now" mixed layer temperature/salinity
-      tmlb_trc   ,                        &      !: /  and associated "before" fields
-      tmlbb_trc  ,                        &      !: \  idem, but valid at the 1rst time step of the
-      tmlbn_trc  ,                        &      !: /  current analysis window
+      tml_trc    ,                        &      !: "now" mixed layer temperature/salinity
+      tmlb_trc   ,                        &      !:  and associated "before" fields
+      tmlbb_trc  ,                        &      !:  idem, but valid at the 1rst time step of the
+      tmlbn_trc  ,                        &      !:  current analysis window
       tml_sum_trc,                        &      !: mixed layer T, summed over the current analysis period
       tml_sumb_trc,                       &      !: idem, but from the previous analysis period
@@ -93,6 +93,6 @@
 
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  &
-      tmltrd_trc,                         &      !: \ physical contributions to the total trend (for T/S),
-                                                 !: / cumulated over the current analysis window
+      tmltrd_trc,                         &      !: physical contributions to the total trend (for T/S),
+                                                 !: cumulated over the current analysis window
       tmltrd_sum_trc,                     &      !: sum of these trends over the analysis period
       tmltrd_csum_ln_trc,                 &      !: now cumulated sum of trends over the "lower triangle"
@@ -109,6 +109,6 @@
    CHARACTER(LEN=80) :: clname_bio, ctrd_bio(jpdiabio,2)
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  &
-      tmltrd_bio,                         &      !: \ biological contributions to the total trend ,
-                                                 !: / cumulated over the current analysis window
+      tmltrd_bio,                         &      !: biological contributions to the total trend ,
+                                                 !: cumulated over the current analysis window
       tmltrd_sum_bio,                     &      !: sum of these trends over the analysis period
       tmltrd_csum_ln_bio,                 &      !: now cumulated sum of trends over the "lower triangle"
Index: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/trcnam.F90
===================================================================
--- branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/trcnam.F90	(revision 3317)
+++ branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/TOP_SRC/trcnam.F90	(revision 3318)
@@ -26,5 +26,5 @@
    USE trcnam_c14b       ! C14 SMS namelist
    USE trcnam_my_trc     ! MY_TRC SMS namelist
-   USE trdmod_oce       
+   USE trd_oce           ! trends: ocean variables
    USE trdmod_trc_oce
    USE iom               ! I/O manager
