Index: trunk/NEMO/OPA_SRC/DYN/dynhpg.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 503)
@@ -4,4 +4,14 @@
    !! Ocean dynamics:  hydrostatic pressure gradient trend
    !!======================================================================
+   !! History :  1.0  !  87-09  (P. Andrich, M.-A. Foujols)  hpg_zco: Original code
+   !!            5.0  !  91-11  (G. Madec)
+   !!            7.0  !  96-01  (G. Madec)  hpg_sco: Original code for s-coordinates
+   !!            8.0  !  97-05  (G. Madec)  split dynber into dynkeg and dynhpg
+   !!            8.5  !  02-07  (G. Madec)  F90: Free form and module
+   !!            8.5  !  02-08  (A. Bozec)  hpg_zps: Original code
+   !!            9.0  !  05-10  (A. Beckmann, B.W. An)  various s-coordinate options
+   !!                           Original code for hpg_ctl, hpg_hel hpg_wdj, hpg_djc, hpg_rot 
+   !!            9.0  !  05-11  (G. Madec) style & small optimisation
+   !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
@@ -18,5 +28,4 @@
    !!       hpg_rot  : s-coordinate (ROTated axes scheme)
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
@@ -32,6 +41,5 @@
    PRIVATE
 
-   !! * Accessibility
-   PUBLIC dyn_hpg                ! routine called by step.F90
+   PUBLIC   dyn_hpg    ! routine called by step module
 
 #if defined key_mpp_omp
@@ -49,20 +57,18 @@
 #endif
 
-   !! * Share module variables
-   LOGICAL  ::               & !!! ** nam_dynhpg **   hpg flags
-      ln_hpg_zco = .TRUE. ,  &  ! z-coordinate - full steps
-      ln_hpg_zps = .FALSE.,  &  ! z-coordinate - partial steps (interpolation)
-      ln_hpg_sco = .FALSE.,  &  ! s-coordinate (standard jacobian formulation)
-      ln_hpg_hel = .FALSE.,  &  ! s-coordinate (helsinki modification)
-      ln_hpg_wdj = .FALSE.,  &  ! s-coordinate (weighted density jacobian)
-      ln_hpg_djc = .FALSE.,  &  ! s-coordinate (Density Jacobian with Cubic polynomial)
-      ln_hpg_rot = .FALSE.      ! s-coordinate (ROTated axes scheme)
-
-   REAL(wp) ::               & !!! ** nam_dynhpg ** 
-      gamm = 0.e0               ! weighting coefficient
-
-   INTEGER  ::               &  ! 
-      nhpg  =  0                 ! = 0 to 6, type of pressure gradient scheme used
-      !                         ! (deduced from ln_hpg_... flags)
+   !!* Namelist nam_dynhpg : Choice of horizontal pressure gradient computation
+   LOGICAL  ::   ln_hpg_zco = .TRUE.    ! z-coordinate - full steps
+   LOGICAL  ::   ln_hpg_zps = .FALSE.   ! z-coordinate - partial steps (interpolation)
+   LOGICAL  ::   ln_hpg_sco = .FALSE.   ! s-coordinate (standard jacobian formulation)
+   LOGICAL  ::   ln_hpg_hel = .FALSE.   ! s-coordinate (helsinki modification)
+   LOGICAL  ::   ln_hpg_wdj = .FALSE.   ! s-coordinate (weighted density jacobian)
+   LOGICAL  ::   ln_hpg_djc = .FALSE.   ! s-coordinate (Density Jacobian with Cubic polynomial)
+   LOGICAL  ::   ln_hpg_rot = .FALSE.   ! s-coordinate (ROTated axes scheme)
+   REAL(wp) ::   gamm       = 0.e0      ! weighting coefficient
+   NAMELIST/nam_dynhpg/ ln_hpg_zco, ln_hpg_zps, ln_hpg_sco, ln_hpg_hel,   &
+      &                 ln_hpg_wdj, ln_hpg_djc, ln_hpg_rot, gamm
+
+   INTEGER  ::   nhpg  =  0             ! = 0 to 6, type of pressure gradient scheme used
+      !                                 ! (deduced from ln_hpg_... flags)
 
    !! * Substitutions
@@ -72,5 +78,5 @@
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -82,25 +88,17 @@
       !!
       !! ** Method  :   Call the hydrostatic pressure gradient routine 
-      !!      using the scheme defined in the namelist (nhpg parameter)
+      !!              using the scheme defined in the namelist
       !!   
       !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
       !!             - Save the trend (l_trddyn=T)
-      !!             - Control print  (ln_ctl)
-      !!
-      !! History :
-      !!   9.0  !  05-10  (A. Beckmann, G. Madec) various s-coordinate options
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-
-      !! * local declarations
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         ztrdu, ztrdv                         ! 3D temporary workspace
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !!
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdu, ztrdv   ! 3D temporary workspace
       !!----------------------------------------------------------------------
    
       IF( kt == nit000 )   CALL hpg_ctl      ! initialisation & control of options
 
-      ! Temporary saving of ua and va trends (l_trddyn)
-      IF( l_trddyn )   THEN
+      IF( l_trddyn ) THEN                    ! Temporary saving of ua and va trends (l_trddyn)
          ztrdu(:,:,:) = ua(:,:,:)  
          ztrdv(:,:,:) = va(:,:,:) 
@@ -108,38 +106,25 @@
 
       SELECT CASE ( nhpg )      ! Hydrastatic pressure gradient computation
-      CASE ( 0 )                  ! z-coordinate 
-         CALL hpg_zco( kt )
-      CASE ( 1 )                  ! z-coordinate plus partial steps (interpolation)
-         CALL hpg_zps( kt )
-      CASE ( 2 )                  ! s-coordinate (standard jacobian formulation)
-         CALL hpg_sco( kt )
-      CASE ( 3 )                  ! s-coordinate (helsinki modification)
-         CALL hpg_hel( kt )
-      CASE ( 4 )                  ! s-coordinate (weighted density jacobian)
-         CALL hpg_wdj( kt )
-      CASE ( 5 )                  ! s-coordinate (Density Jacobian with Cubic polynomial)
-         CALL hpg_djc( kt )
-      CASE ( 6 )                  ! s-coordinate (ROTated axes scheme)
-         CALL hpg_rot( kt )
-      CASE ( 10 )                  ! z-coordinate
-         CALL hpg_zco_jki( kt )
-      CASE ( 11 )                  ! z-coordinate plus partial steps (interpolation)
-         CALL hpg_zps_jki( kt )
-      CASE ( 12 )                  ! s-coordinate (standard jacobian formulation)
-         CALL hpg_sco_jki( kt )
+      CASE (  0 )   ;   CALL hpg_zco    ( kt )      ! z-coordinate
+      CASE (  1 )   ;   CALL hpg_zps    ( kt )      ! z-coordinate plus partial steps (interpolation)
+      CASE (  2 )   ;   CALL hpg_sco    ( kt )      ! s-coordinate (standard jacobian formulation)
+      CASE (  3 )   ;   CALL hpg_hel    ( kt )      ! s-coordinate (helsinki modification)
+      CASE (  4 )   ;   CALL hpg_wdj    ( kt )      ! s-coordinate (weighted density jacobian)
+      CASE (  5 )   ;   CALL hpg_djc    ( kt )      ! s-coordinate (Density Jacobian with Cubic polynomial)
+      CASE (  6 )   ;   CALL hpg_rot    ( kt )      ! s-coordinate (ROTated axes scheme)
+      CASE ( 10 )   ;   CALL hpg_zco_jki( kt )      ! z-coordinate (k-j-i)
+      CASE ( 11 )   ;   CALL hpg_zps_jki( kt )      ! z-coordinate plus partial steps (interpolation) (k-j-i)
+      CASE ( 12 )   ;   CALL hpg_sco_jki( kt )      ! s-coordinate (standard jacobian formulation) (k-j-i)
       END SELECT
 
-      ! save the hydrostatic pressure gradient trends for momentum trend diagnostics
-      IF( l_trddyn )   THEN
+      IF( l_trddyn ) THEN      ! save the hydrostatic pressure gradient trends for momentum trend diagnostics
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_mod( ztrdu, ztrdv, jpdtdhpg, 'DYN', kt )
+         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_hpg, 'DYN', kt )
       ENDIF          
-      
-      IF(ln_ctl) THEN         ! print sum trends (used for debugging)
-         CALL prt_ctl( tab3d_1=ua, clinfo1=' hpg  - Ua: ', mask1=umask, &
-            &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-      ENDIF
-      
+      !
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' hpg  - Ua: ', mask1=umask,   &
+         &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
    END SUBROUTINE dyn_hpg
 
@@ -154,21 +139,12 @@
       !! ** Action  :   Read the namelist namdynhpg and check the consistency
       !!      with the type of vertical coordinate used (zco, zps, sco)
-      !!
-      !! History :
-      !!   9.0  !  05-10  (A. Beckmann)  Original code
       !!----------------------------------------------------------------------
       INTEGER ::   ioptio = 0      ! temporary integer
-
-      NAMELIST/nam_dynhpg/ ln_hpg_zco, ln_hpg_zps, ln_hpg_sco,               &
-         &                 ln_hpg_hel, ln_hpg_wdj, ln_hpg_djc, ln_hpg_rot,   &
-         &                 gamm
-      !!----------------------------------------------------------------------
-
-      ! Read Namelist nam_dynhpg : pressure gradient calculation options
-      REWIND ( numnam )
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )               ! Read Namelist nam_dynhpg : pressure gradient calculation options
       READ   ( numnam, nam_dynhpg )
 
-      ! Control print
-      IF(lwp) THEN
+      IF(lwp) THEN                    ! Control print
          WRITE(numout,*)
          WRITE(numout,*) 'dyn:hpg_ctl : hydrostatic pressure gradient control'
@@ -185,5 +161,5 @@
       ENDIF
 
-      ! set nhpg from ln_hpg_... flags
+      !                               ! Set nhpg from ln_hpg_... flags
       IF( ln_hpg_zco )   nhpg = 0
       IF( ln_hpg_zps )   nhpg = 1
@@ -194,5 +170,5 @@
       IF( ln_hpg_rot )   nhpg = 6
 
-      ! Consitency check
+      !                               ! Consitency check
       ioptio = 0 
       IF( ln_hpg_zco )   ioptio = ioptio + 1
@@ -203,6 +179,5 @@
       IF( ln_hpg_djc )   ioptio = ioptio + 1
       IF( ln_hpg_rot )   ioptio = ioptio + 1
-      IF ( ioptio > 1 )   &
-           &   CALL ctl_stop( ' several hydrostatic pressure gradient options used' )
+      IF ( ioptio /= 1 )   CALL ctl_stop( ' NO or several hydrostatic pressure gradient options used' )
 
       IF( lk_dynhpg_jki ) THEN
@@ -211,5 +186,5 @@
          IF(lwp) WRITE(numout,*) '          Autotasking or OPENMP: use j-k-i loops (i.e. _jki routines)'
       ENDIF
-
+      !
    END SUBROUTINE hpg_ctl
 
@@ -230,23 +205,12 @@
       !! 
       !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
-      !!
-      !! History :
-      !!   1.0  !  87-09  (P. Andrich, M.-A. Foujols)  Original code
-      !!   5.0  !  91-11  (G. Madec)
-      !!   7.0  !  96-01  (G. Madec)
-      !!   8.0  !  97-05  (G. Madec)  split dynber into dynkeg and dynhpg
-      !!   8.5  !  02-07  (G. Madec)  F90: Free form and module
-      !!----------------------------------------------------------------------
-      !! * modules used
-      USE oce, ONLY :   zhpi => ta,  &  ! use ta as 3D workspace
-         &              zhpj => sa      ! use sa as 3D workspace
-      
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-      
-      !! * local declarations
-      INTEGER ::   ji, jj, jk           ! dummy loop indices
-      REAL(wp) ::   &   
-         zcoef0, zcoef1                 ! temporary scalars
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk       ! dummy loop indices
+      REAL(wp) ::   zcoef0, zcoef1   ! temporary scalars
       !!----------------------------------------------------------------------
       
@@ -257,11 +221,8 @@
       ENDIF
       
-      
       ! Local constant initialization 
-      ! -----------------------------
       zcoef0 = - grav * 0.5
 
       ! Surface value
-      ! -------------
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -275,7 +236,6 @@
          END DO
       END DO
-
+      !
       ! interior value (2=<jk=<jpkm1)
-      ! --------------
       DO jk = 2, jpkm1
          DO jj = 2, jpjm1
@@ -296,5 +256,5 @@
          END DO
       END DO
-
+      !
    END SUBROUTINE hpg_zco
 
@@ -307,22 +267,13 @@
       !! 
       !! ** Action  : - Update (ua,va) with the now hydrastatic pressure trend
-      !!    
-      !! History :
-      !!   8.5  !  02-08  (A. Bozec)  Original code
-      !!   9.0  !  04-08  (G. Madec)  F90
       !!---------------------------------------------------------------------- 
-      !! * modules used                                 
-      USE oce, ONLY :   zhpi => ta,  &  ! use ta as 3D workspace
-         &              zhpj => sa      ! use sa as 3D workspace
-               
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-
-      !! * local declarations
-      INTEGER ::   ji, jj, jk           ! dummy loop indices
-      INTEGER ::   iku, ikv             ! temporary integers
-      REAL(wp) ::   &
-         zcoef0, zcoef1,             &  ! temporary scalars
-         zcoef2, zcoef3                 !    "         "
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk                       ! dummy loop indices
+      INTEGER  ::   iku, ikv                         ! temporary integers
+      REAL(wp) ::   zcoef0, zcoef1, zcoef2, zcoef3   ! temporary scalars
       !!----------------------------------------------------------------------
 
@@ -330,15 +281,11 @@
          IF(lwp) WRITE(numout,*)
          IF(lwp) WRITE(numout,*) 'dyn:hpg_zps : hydrostatic pressure gradient trend'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   z-coordinate with partial steps'
-         IF(lwp) WRITE(numout,*) '              vector optimization'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   z-coordinate with partial steps - vector optimization'
       ENDIF
 
-
-      ! 0. Local constant initialization
-      ! --------------------------------
+      ! Local constant initialization
       zcoef0 = - grav * 0.5
 
-      ! 1. Surface value
-      ! ----------------
+      !  Surface value
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -353,6 +300,5 @@
       END DO
 
-      ! 2. interior value (2=<jk=<jpkm1)
-      ! -----------------
+      ! interior value (2=<jk=<jpkm1)
       DO jk = 2, jpkm1
          DO jj = 2, jpjm1
@@ -410,5 +356,5 @@
 # endif
       END DO
-
+      !
    END SUBROUTINE hpg_zps
 
@@ -431,23 +377,12 @@
       !!
       !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
-      !!
-      !! History :
-      !!   7.0  !  96-01  (G. Madec)  s-coordinates
-      !!        !  97-05  (G. Madec)  split dynber into dynkeg and dynhpg
-      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module, vector opt.
-      !!   9.0  !  04-08  (C. Talandier) New trends organization
-      !!   9.0  !  05-10  (A. Beckmann) various s-coordinate options
-      !!----------------------------------------------------------------------
-      !! * modules used
-      USE oce, ONLY :   zhpi => ta,  &  ! use ta as 3D workspace
-         &              zhpj => sa      ! use sa as 3D workspace
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk           ! dummy loop indices
-      REAL(wp) ::   &
-         zcoef0, zuap, zvap             ! temporary scalars
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk           ! dummy loop indices
+      REAL(wp) ::   zcoef0, zuap, zvap   ! temporary scalars
       !!----------------------------------------------------------------------
 
@@ -458,12 +393,8 @@
       ENDIF
 
-
-      ! 0. Local constant initialization
-      ! --------------------------------
+      ! Local constant initialization
       zcoef0 = - grav * 0.5
 
-
-      ! 1. Surface value
-      ! ----------------                          
+      ! Surface value
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vector opt.   
@@ -484,7 +415,5 @@
       END DO   
             
-               
-      ! 2. interior value (2=<jk=<jpkm1)
-      ! -----------------     
+      ! interior value (2=<jk=<jpkm1)
       DO jk = 2, jpkm1                                  
          DO jj = 2, jpjm1     
@@ -508,5 +437,5 @@
          END DO
       END DO
-
+      !
    END SUBROUTINE hpg_sco
 
@@ -530,19 +459,12 @@
       !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
       !!             - Save the trend (l_trddyn=T)
-      !!
-      !! History :
-      !!   9.0  !  05-10  (A. Beckmann)  Original code
-      !!----------------------------------------------------------------------
-      !! * modules used
-      USE oce, ONLY :   zhpi => ta,  &  ! use ta as 3D workspace
-         &              zhpj => sa      ! use sa as 3D workspace
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-      
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk           ! dummy loop indices
-      REAL(wp) ::   &
-         zcoef0, zuap, zvap             ! temporary scalars
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk           ! dummy loop indices
+      REAL(wp) ::   zcoef0, zuap, zvap   ! temporary scalars
       !!----------------------------------------------------------------------
 
@@ -553,12 +475,8 @@
       ENDIF
 
-
-      ! 0. Local constant initialization
-      ! --------------------------------
+      ! Local constant initialization
       zcoef0 = - grav * 0.5
-
  
-      ! 1. Surface value
-      ! ----------------
+      ! Surface value
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -578,7 +496,6 @@
          END DO
       END DO
-
-      ! 2. interior value (2=<jk=<jpkm1)
-      ! -----------------
+      !
+      ! interior value (2=<jk=<jpkm1)
       DO jk = 2, jpkm1
          DO jj = 2, jpjm1
@@ -606,5 +523,5 @@
          END DO
       END DO
-
+      !
    END SUBROUTINE hpg_hel
 
@@ -619,21 +536,13 @@
       !!
       !! Reference : Song, Mon. Wea. Rev., 126, 3213-3230, 1998.
-      !!
-      !! History :
-      !!   9.0  !  05-05  (B.W. An)  Original code
-      !!        !  05-10  (G. Madec) style & small optimisation
-      !!----------------------------------------------------------------------
-      !! * modules used
-      USE oce, ONLY :   zhpi => ta,  &  ! use ta as 3D workspace
-         &              zhpj => sa      ! use sa as 3D workspace
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk           ! dummy loop indices
-      REAL(wp) ::   &
-         zcoef0, zuap, zvap,         &  ! temporary scalars
-         zalph , zbeta                  !    "         "
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk           ! dummy loop indices
+      REAL(wp) ::   zcoef0, zuap, zvap   ! temporary scalars
+      REAL(wp) ::   zalph , zbeta        !    "         "
       !!----------------------------------------------------------------------
 
@@ -644,7 +553,5 @@
       ENDIF
 
-
       ! Local constant initialization
-      ! -----------------------------
       zcoef0 = - grav * 0.5
       zalph  = 0.5 - gamm        ! weighting coefficients (alpha=0.5-gamm)
@@ -652,5 +559,4 @@
 
       ! Surface value (no ponderation)
-      ! -------------
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -672,5 +578,4 @@
 
       ! Interior value (2=<jk=<jpkm1) (weighted with zalph & zbeta)
-      ! --------------
       DO jk = 2, jpkm1
          DO jj = 2, jpjm1
@@ -700,5 +605,5 @@
          END DO
       END DO
-
+      !
    END SUBROUTINE hpg_wdj
 
@@ -710,26 +615,18 @@
       !! ** Method  :   Density Jacobian with Cubic polynomial scheme
       !! 
-      !! Reference: Shchepetkin, A.F. & J.C. McWilliams, J. Geophys. Res.,
-      !!            108(C3), 3090, 2003
-      !! History :
-      !!   9.0  !  05-05  (B.W. An)  Original code
-      !!----------------------------------------------------------------------
-      !! * modules used
-      USE oce, ONLY :   zhpi => ta,  &  ! use ta as 3D workspace
-         &              zhpj => sa      ! use sa as 3D workspace
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-      
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk           ! dummy loop indices
-      REAL(wp) ::   &
-         zcoef0, z1_10, cffu, cffx,  &  ! temporary scalars
-                 z1_12, cffv, cffy,  &  !    "         "
-         zep   , cffw                   !    "         "
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &  ! 3D workspace
-         drhox, dzx, drhou, dzu, rho_i,     &
-         drhoy, dzy, drhov, dzv, rho_j,     &
-         drhoz, dzz, drhow, dzw, rho_k
+      !! Reference: Shchepetkin and McWilliams, J. Geophys. Res., 108(C3), 3090, 2003
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk          ! dummy loop indices
+      REAL(wp) ::   zcoef0, zep, cffw   ! temporary scalars
+      REAL(wp) ::   z1_10, cffu, cffx   !    "         "
+      REAL(wp) ::   z1_12, cffv, cffy   !    "         "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   drhox, dzx, drhou, dzu, rho_i   ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   drhoy, dzy, drhov, dzv, rho_j   !  "      "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   drhoz, dzz, drhow, dzw, rho_k   !  "      "
       !!----------------------------------------------------------------------
 
@@ -741,6 +638,5 @@
 
 
-      ! 0. Local constant initialization
-      ! --------------------------------
+      ! Local constant initialization
       zcoef0 = - grav * 0.5
       z1_10  = 1.0 / 10.0
@@ -771,6 +667,6 @@
       zep = 1.e-15
 
-      !!bug  gm  drhoz not defined at level 1 and used (jk-1 with jk=2)
-      !!bug  gm  idem for drhox, drhoy et ji=jpi and jj=jpj
+!!bug  gm  drhoz not defined at level 1 and used (jk-1 with jk=2)
+!!bug  gm  idem for drhox, drhoy et ji=jpi and jj=jpj
 
       DO jk = 2, jpkm1
@@ -930,5 +826,5 @@
          END DO
       END DO
-
+      !
    END SUBROUTINE hpg_djc
 
@@ -941,25 +837,16 @@
       !!
       !! Reference: Thiem & Berntsen, Ocean Modelling, In press, 2005.
-      !! History :
-      !!   9.0  !  05-07 (B.W. An)
-      !!   9.0  !  05-10 (A. Beckmann) adapted to non-equidistant and masked grids
-      !!----------------------------------------------------------------------
-      !! * modules used
-      USE oce, ONLY :   zhpi => ta,         &  ! use ta as 3D workspace
-         &              zhpj => sa             ! use sa as 3D workspace
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt            ! ocean time-step index
-      
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk                  ! dummy loop indices
-      REAL(wp) ::   &
-         zforg, zcoef0, zuap, zmskd1, zmskd1m,                             &
-         zfrot        , zvap, zmskd2, zmskd2m
-      REAL(wp), DIMENSION(jpi,jpj) ::       &  ! 2D temporary workspace
-         zdistr, zsina, zcosa             
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &  ! 3D temporary workspace
-         zhpiorg, zhpirot, zhpitra, zhpine, & 
-         zhpjorg, zhpjrot, zhpjtra, zhpjne
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk          ! dummy loop indices
+      REAL(wp) ::   zforg, zcoef0, zuap, zmskd1, zmskd1m   ! temporary scalar
+      REAL(wp) ::   zfrot        , zvap, zmskd2, zmskd2m   !    "         "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zdistr, zsina, zcosa                ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhpiorg, zhpirot, zhpitra, zhpine   ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhpjorg, zhpjrot, zhpjtra, zhpjne   !  "      "
       !!----------------------------------------------------------------------
 
@@ -1118,5 +1005,5 @@
          END DO
       END DO
-
+      !
    END SUBROUTINE hpg_rot
 
Index: trunk/NEMO/OPA_SRC/DYN/dynhpg_jki.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DYN/dynhpg_jki.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/DYN/dynhpg_jki.F90	(revision 503)
@@ -4,17 +4,19 @@
    !! Ocean dynamics:  hydrostatic pressure gradient trend
    !!======================================================================
-
-   !!----------------------------------------------------------------------
-   !!   hpg...o_jki : update the momentum trend with the horizontal
-   !!                  gradient of the hydrostatic pressure
-   !!----------------------------------------------------------------------
-   !! * Modules used
+   !! History :  9.0  !  06-09  (G. Madec) From dynhpg module
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   hpg_sco_jki : update the momentum trend with the horizontal
+   !!                 gradient of the hydrostatic pressure (s-coordinate)
+   !!   hpg_zps_jki : update the momentum trend with the horizontal
+   !!                 gradient of the hydrostatic pressure (partial step)
+   !!   hpg_zco_jki : update the momentum trend with the horizontal
+   !!                 gradient of the hydrostatic pressure (z-coordinate)
+   !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
    USE phycst          ! physical constants
    USE in_out_manager  ! I/O manager
-   USE trdmod          ! ocean dynamics trends
-   USE trdmod_oce      ! ocean variables trends
-   USE prtctl          ! Print control
    USE lbclnk          ! lateral boundary condition
 
@@ -22,8 +24,7 @@
    PRIVATE
 
-   !! * Accessibility
-   PUBLIC hpg_sco_jki ! routine called by step.F90
-   PUBLIC hpg_zps_jki ! routine called by step.F90
-   PUBLIC hpg_zco_jki ! routine called by step.F90
+   PUBLIC   hpg_sco_jki   ! routine called by step.F90
+   PUBLIC   hpg_zps_jki   ! routine called by step.F90
+   PUBLIC   hpg_zco_jki   ! routine called by step.F90
 
    !! * Substitutions
@@ -32,4 +33,6 @@
    !!----------------------------------------------------------------------
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -57,25 +60,13 @@
       !!
       !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
-      !!             - Save the trend in (utrd,vtrd) ('key_trddyn')
-      !!
-      !! History :
-      !!   7.0  !  96-01  (G. Madec)  s-coordinates
-      !!        !  97-05  (G. Madec)  split dynber into dynkeg and dynhpg
-      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
-      !!   9.0  !  04-08  (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------
-      !! * modules used
-      USE oce, ONLY :   zhpi => ta,  &  ! use ta as 3D workspace
-         &              zhpj => sa      ! use sa as 3D workspace
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-      
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk           ! dummy loop indices
-      REAL(wp) ::   &
-         zcoef0, zuap, zvap     ! temporary scalars
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         ztdua, ztdva                   ! temporary scalars
+      !!             - Save the trend in (ztrdu,ztrdv) ('key_trddyn')
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk           ! dummy loop indices
+      REAL(wp) ::   zcoef0, zuap, zvap   ! temporary scalars
       !!----------------------------------------------------------------------
 
@@ -86,12 +77,5 @@
       ENDIF
 
-      ! Save ua and va trends
-      IF( l_trddyn )   THEN
-         ztdua(:,:,:) = ua(:,:,:) 
-         ztdva(:,:,:) = va(:,:,:) 
-      ENDIF
-
-      ! 0. Local constant initialization
-      ! --------------------------------
+      ! Local constant initialization
       zcoef0 = - grav * 0.5
       zuap   = 0.e0
@@ -101,7 +85,5 @@
       DO jj = 2, jpjm1                                 !  Vertical slab
          !                                             ! ===============
-         ! 1. Surface value
-         ! ----------------
-         DO ji = 2, jpim1
+         DO ji = 2, jpim1         !  Surface value
             ! hydrostatic pressure gradient along s-surfaces
             zhpi(ji,jj,1) = zcoef0 / e1u(ji,jj)   &
@@ -118,8 +100,6 @@
             va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1) + zvap
          END DO  
-
-         ! 2. interior value (2=<jk=<jpkm1)
-         ! -----------------
-         DO jk = 2, jpkm1
+         !
+         DO jk = 2, jpkm1         ! interior value (2=<jk=<jpkm1)
             DO ji = 2, jpim1
                ! hydrostatic pressure gradient along s-surfaces
@@ -143,18 +123,4 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-
-      ! save the hydrostatic pressure gradient trends for diagnostic
-      ! momentum trends
-      IF( l_trddyn )   THEN
-         zhpi(:,:,:) = ua(:,:,:) - ztdua(:,:,:)
-         zhpj(:,:,:) = va(:,:,:) - ztdva(:,:,:)
-         CALL trd_mod(zhpi, zhpj, jpdtdhpg, 'DYN', kt)
-      ENDIF
-
-      IF(ln_ctl) THEN         ! print sum trends (used for debugging)
-         CALL prt_ctl(tab3d_1=ua, clinfo1=' hpg  - Ua: ', mask1=umask, &
-            &         tab3d_2=va, clinfo2=' Va: ', mask2=vmask, clinfo3='dyn')
-      ENDIF
-
    END SUBROUTINE hpg_sco_jki
 
@@ -178,24 +144,15 @@
       !!
       !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
-      !!             - Save the trend in (utrd,vtrd) ('key_trddyn')
-      !!
-      !! History :
-      !!   8.5  !  02-08  (A. Bozec)  Original code
-      !!----------------------------------------------------------------------
-      !! * modules used
-      USE oce, ONLY :   zhpi => ta,  &  ! use ta as 3D workspace
-         &              zhpj => sa      ! use sa as 3D workspace
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-
-      !! * local declarations
-      INTEGER ::   ji, jj, jk           ! dummy loop indices
-      INTEGER ::   iku, ikv             ! temporary integers
-      REAL(wp) ::   &
-         zcoef0, zcoef1, zuap,       &  ! temporary scalars
-         zcoef2, zcoef3, zvap           !    "         "
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         ztdua, ztdva                   ! temporary scalars
+      !!             - Save the trend in (ztrdu,ztrdv) ('key_trddyn')
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk             ! dummy loop indices
+      INTEGER  ::   iku, ikv               ! temporary integers
+      REAL(wp) ::   zcoef0, zcoef1, zuap   ! temporary scalars
+      REAL(wp) ::   zcoef2, zcoef3, zvap   !    "         "
       !!----------------------------------------------------------------------
 
@@ -206,12 +163,5 @@
       ENDIF
 
-      ! Save ua and va trends
-      IF( l_trddyn )   THEN
-         ztdua(:,:,:) = ua(:,:,:) 
-         ztdva(:,:,:) = va(:,:,:) 
-      ENDIF
-
-      ! 0. Local constant initialization
-      ! --------------------------------
+      ! Local constant initialization
       zcoef0 = - grav * 0.5
       zuap   = 0.e0
@@ -220,7 +170,5 @@
       DO jj = 2, jpjm1                                 !  Vertical slab
          !                                             ! ===============
-         ! 1. Surface value
-         ! ----------------
-         DO ji = 2, jpim1
+         DO ji = 2, jpim1         ! Surface value
             zcoef1 = zcoef0 * fse3w(ji,jj,1)
             ! hydrostatic pressure gradient
@@ -231,8 +179,6 @@
             va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1)
          END DO
-
-         ! 2. interior value (2=<jk=<jpkm1)
-         ! -----------------
-         DO jk = 2, jpkm1
+         !
+         DO jk = 2, jpkm1         ! interior value (2=<jk=<jpkm1)
             DO ji = 2, jpim1
                zcoef1 = zcoef0 * fse3w(ji,jj,jk)
@@ -250,5 +196,5 @@
             END DO 
          END DO
-
+         !
          ! partial steps correction at the last level  (new gradient with  intgrd.F)
          DO ji = 2, jpim1
@@ -281,18 +227,4 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-
-      ! save the hydrostatic pressure gradient trends for diagnostic
-      ! momentum trends
-      IF( l_trddyn )   THEN
-         zhpi(:,:,:) = ua(:,:,:) - ztdua(:,:,:)
-         zhpj(:,:,:) = va(:,:,:) - ztdva(:,:,:)
-         CALL trd_mod(zhpi, zhpj, jpdtdhpg, 'DYN', kt)
-      ENDIF
-
-      IF(ln_ctl) THEN         ! print sum trends (used for debugging)
-         CALL prt_ctl(tab3d_1=ua, clinfo1=' hpg  - Ua: ', mask1=umask, &
-            &         tab3d_2=va, clinfo2=' Va: ', mask2=vmask, clinfo3='dyn')
-      ENDIF   
-
    END SUBROUTINE hpg_zps_jki
 
@@ -317,26 +249,13 @@
       !!
       !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
-      !!             - Save the trend in (utrd,vtrd) ('key_trddyn')
-      !!
-      !! History :
-      !!   1.0  !  87-09  (P. Andrich, m.-a. Foujols)  Original code
-      !!        !  91-11  (G. Madec)
-      !!        !  96-01  (G. Madec)  s-coordinates
-      !!        !  97-05  (G. Madec)  split dynber into dynkeg and dynhpg
-      !!   8.5  !  02-07  (G. Madec)  F90: Free form and module
-      !!----------------------------------------------------------------------
-      !! * modules used
-      USE oce, ONLY :   zhpi => ta,  &  ! use ta as 3D workspace
-         &              zhpj => sa      ! use sa as 3D workspace
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-
-      !! * local declarations
-      INTEGER ::   ji, jj, jk           ! dummy loop indices
-      REAL(wp) ::   &
-         zcoef0, zcoef1, zuap, zvap     ! temporary scalars
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         ztdua, ztdva                   ! temporary scalars
+      !!             - Save the trend in (ztrdu,ztrdv) ('key_trddyn')
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zhpi => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   zhpj => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk                   ! dummy loop indices
+      REAL(wp) ::   zcoef0, zcoef1, zuap, zvap   ! temporary scalars
       !!----------------------------------------------------------------------
 
@@ -347,12 +266,5 @@
       ENDIF
 
-      ! Save ua and va trends
-      IF( l_trddyn )   THEN
-         ztdua(:,:,:) = ua(:,:,:) 
-         ztdva(:,:,:) = va(:,:,:) 
-      ENDIF
-
-      ! 0. Local constant initialization
-      ! --------------------------------
+      ! Local constant initialization
       zcoef0 = - grav * 0.5
       zuap   = 0.e0
@@ -362,9 +274,5 @@
       DO jj = 2, jpjm1                                 !  Vertical slab
          !                                             ! ===============
-         ! 1. Surface value
-         ! ----------------
-         
-
-         DO ji = 2, jpim1
+         DO ji = 2, jpim1         ! Surface value
             zcoef1 = zcoef0 * fse3w(ji,jj,1)
             ! hydrostatic pressure gradient
@@ -375,8 +283,6 @@
             va(ji,jj,1) = va(ji,jj,1) + zhpj(ji,jj,1)
          END DO
-
-         ! 2. interior value (2=<jk=<jpkm1)
-         ! -----------------
-         DO jk = 2, jpkm1
+         !
+         DO jk = 2, jpkm1         ! interior value (2=<jk=<jpkm1)
             DO ji = 2, jpim1
                zcoef1 = zcoef0 * fse3w(ji,jj,jk)
@@ -397,19 +303,4 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-
-      ! save the hydrostatic pressure gradient trends for diagnostic
-      ! momentum trends
-      IF( l_trddyn )   THEN
-         zhpi(:,:,:) = ua(:,:,:) - ztdua(:,:,:)
-         zhpj(:,:,:) = va(:,:,:) - ztdva(:,:,:)
-
-         CALL trd_mod(zhpi, zhpj, jpdtdhpg, 'DYN', kt)
-      ENDIF
-
-      IF(ln_ctl) THEN         ! print sum trends (used for debugging)
-         CALL prt_ctl(tab3d_1=ua, clinfo1=' hpg  - Ua: ', mask1=umask, &
-            &         tab3d_2=va, clinfo2=' Va: ', mask2=vmask, clinfo3='dyn')
-      ENDIF
-
    END SUBROUTINE hpg_zco_jki
 
Index: trunk/NEMO/OPA_SRC/DYN/dynkeg.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DYN/dynkeg.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/DYN/dynkeg.F90	(revision 503)
@@ -4,9 +4,12 @@
    !! Ocean dynamics:  kinetic energy gradient trend
    !!======================================================================
+   !! History :  1.0  !  87-09  (P. Andrich, m.-a. Foujols)  Original code
+   !!            7.0  !  97-05  (G. Madec)  Split dynber into dynkeg and dynhpg
+   !!            9.0  !  02-07  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
    
    !!----------------------------------------------------------------------
    !!   dyn_keg      : update the momentum trend with the horizontal tke
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
@@ -19,14 +22,13 @@
    PRIVATE
 
-   !! * Accessibility
-   PUBLIC dyn_keg                ! routine called by step.F90
+   PUBLIC   dyn_keg    ! routine called by step module
    
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
-   !!---------------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
-   !!---------------------------------------------------------------------------------
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 
 CONTAINS
@@ -40,5 +42,5 @@
       !!      general momentum trend.
       !!
-      !! ** Method  :   Compute the now horizontal kinetic energy:
+      !! ** Method  :   Compute the now horizontal kinetic energy 
       !!         zhke = 1/2 [ mi-1( un^2 ) + mj-1( vn^2 ) ]
       !!      Take its horizontal gradient and add it to the general momentum
@@ -48,24 +50,14 @@
       !!
       !! ** Action : - Update the (ua, va) with the hor. ke gradient trend
-      !!             - Save the trends in (utrd,vtrd) ('key_trddyn')
+      !!             - save this trends (l_trddyn=T) for post-processing
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   ztrdu => ta   ! use ta as 3D workspace   
+      USE oce, ONLY :   ztrdv => sa   ! use sa as 3D workspace   
       !!
-      !! History :
-      !!   1.0  !  87-09  (P. Andrich, m.-a. Foujols)  Original code
-      !!   7.0  !  97-05  (G. Madec)  Split dynber into dynkeg and dynhpg
-      !!   9.0  !  02-07  (G. Madec)  F90: Free form and module
-      !!    "   !  04-08  (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------
-      !! * Modules used     
-      USE oce, ONLY :    ztdua => ta,   & ! use ta as 3D workspace   
-                         ztdva => sa      ! use sa as 3D workspace   
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-
-      !! * Local declarations
-      INTEGER  ::   ji, jj, jk          ! dummy loop indices
-      REAL(wp) ::   zua, zva, zu, zv    ! temporary scalars
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         zhke                           ! temporary workspace
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zu, zv       ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhke   ! temporary 3D workspace
       !!----------------------------------------------------------------------
 
@@ -76,8 +68,7 @@
       ENDIF
 
-      ! Save ua and va trends
-      IF( l_trddyn )   THEN
-         ztdua(:,:,:) = ua(:,:,:) 
-         ztdva(:,:,:) = va(:,:,:) 
+      IF( l_trddyn ) THEN           ! Save ua and va trends
+         ztrdu(:,:,:) = ua(:,:,:) 
+         ztrdv(:,:,:) = va(:,:,:) 
       ENDIF
       
@@ -85,24 +76,17 @@
       DO jk = 1, jpkm1                                 ! Horizontal slab
          !                                             ! ===============
-         ! Horizontal kinetic energy at T-point
-         DO jj = 2, jpj
+         DO jj = 2, jpj         ! Horizontal kinetic energy at T-point
             DO ji = fs_2, jpi   ! vector opt.
+               zu = 0.25 * (  un(ji-1,jj  ,jk) * un(ji-1,jj  ,jk)   &
+                  &         + un(ji  ,jj  ,jk) * un(ji  ,jj  ,jk)  )
                zv = 0.25 * (  vn(ji  ,jj-1,jk) * vn(ji  ,jj-1,jk)   &
-                            + vn(ji  ,jj  ,jk) * vn(ji  ,jj  ,jk)  )
-               zu = 0.25 * (  un(ji-1,jj  ,jk) * un(ji-1,jj  ,jk)   &
-                            + un(ji  ,jj  ,jk) * un(ji  ,jj  ,jk)  )
+                  &         + vn(ji  ,jj  ,jk) * vn(ji  ,jj  ,jk)  )
                zhke(ji,jj,jk) = zv + zu
             END DO  
          END DO  
-         
-         ! Horizontal gradient of Horizontal kinetic energy
-         DO jj = 2, jpjm1
+         DO jj = 2, jpjm1       ! add the gradient of kinetic energy to the general momentum trends
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               ! gradient of kinetic energy
-               zua = -( zhke(ji+1,jj  ,jk) - zhke(ji,jj,jk) ) / e1u(ji,jj)
-               zva = -( zhke(ji  ,jj+1,jk) - zhke(ji,jj,jk) ) / e2v(ji,jj)
-               ! add to the general momentum trends
-               ua(ji,jj,jk) = ua(ji,jj,jk) + zua
-               va(ji,jj,jk) = va(ji,jj,jk) + zva
+               ua(ji,jj,jk) = ua(ji,jj,jk) - ( zhke(ji+1,jj  ,jk) - zhke(ji,jj,jk) ) / e1u(ji,jj)
+               va(ji,jj,jk) = va(ji,jj,jk) - ( zhke(ji  ,jj+1,jk) - zhke(ji,jj,jk) ) / e2v(ji,jj)
             END DO 
          END DO
@@ -111,18 +95,13 @@
       !                                                ! ===============
 
-      ! save the Kinetic Energy trends for diagnostic
-      ! momentum trends
-      IF( l_trddyn )   THEN
-         ztdua(:,:,:) = ua(:,:,:) - ztdua(:,:,:)
-         ztdva(:,:,:) = va(:,:,:) - ztdva(:,:,:)
-
-         CALL trd_mod(ztdua, ztdva, jpdtdkeg, 'DYN', kt)
+      IF( l_trddyn ) THEN      ! save the Kinetic Energy trends for diagnostic
+         ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+         ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_keg, 'DYN', kt )
       ENDIF
-
-      IF(ln_ctl) THEN         ! print sum trends (used for debugging)
-         CALL prt_ctl(tab3d_1=ua, clinfo1=' keg  - Ua: ', mask1=umask, &
-            &         tab3d_2=va, clinfo2=' Va: ', mask2=vmask, clinfo3='dyn')
-      ENDIF
-
+      !
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' keg  - Ua: ', mask1=umask,   &
+         &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
    END SUBROUTINE dyn_keg
 
Index: trunk/NEMO/OPA_SRC/DYN/dynldf.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DYN/dynldf.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/DYN/dynldf.F90	(revision 503)
@@ -4,4 +4,6 @@
    !! Ocean physics:  lateral diffusivity trends 
    !!=====================================================================
+   !! History :  9.0  !  05-11  (G. Madec)  Original code (new step architecture)
+   !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
@@ -9,31 +11,26 @@
    !!   dyn_ldf_ctl : initialization, namelist read, and parameters control
    !!----------------------------------------------------------------------
-   !! * Modules used
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE ldfdyn_oce      ! ocean dynamics lateral physics
-   USE ldfslp          ! ???
-   USE dynldf_bilapg   ! lateral mixing            (dyn_ldf_bilapg routine)
-   USE dynldf_bilap    ! lateral mixing             (dyn_ldf_bilap routine)
-   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 prtctl          ! Print control
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! distribued memory computing library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE ldfdyn_oce     ! ocean dynamics lateral physics
+   USE ldfslp         ! lateral mixing: slopes of mixing orientation
+   USE dynldf_bilapg  ! lateral mixing            (dyn_ldf_bilapg routine)
+   USE dynldf_bilap   ! lateral mixing            (dyn_ldf_bilap  routine)
+   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 prtctl         ! Print control
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! distribued memory computing library
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
 
    IMPLICIT NONE
    PRIVATE
 
-   !! *  Routine accessibility
-   PUBLIC dyn_ldf      ! called by step.F90 
+   PUBLIC   dyn_ldf   ! called by step module 
 
-   !! * module variables
-   INTEGER ::                        & 
-      nldf = 0                         ! type of lateral diffusion used
-      !                                ! defined from ln_dynldf_... namlist logicals)
+   INTEGER ::   nldf = 0   ! type of lateral diffusion used defined from ln_dynldf_... namlist logicals)
 
    !! * Substitutions
@@ -42,5 +39,7 @@
    !!---------------------------------------------------------------------------------
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
-   !!---------------------------------------------------------------------------------
+   !! $Header$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 
 CONTAINS
@@ -51,12 +50,8 @@
       !! 
       !! ** Purpose :   compute the lateral ocean dynamics physics.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !!
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-
-      !! * local declarations
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         ztrdu, ztrdv                         ! 3D temporary workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdu, ztrdv   ! 3D workspace
       !!----------------------------------------------------------------------
 
@@ -69,48 +64,34 @@
 
       SELECT CASE ( nldf )                       ! compute lateral mixing trend and add it to the general trend
+      !
+      CASE ( 0 )    ;   CALL dyn_ldf_lap    ( kt )      ! iso-level laplacian
+      CASE ( 1 )    ;   CALL dyn_ldf_iso    ( kt )      ! rotated laplacian (except dk[ dk[.] ] part)
+      CASE ( 2 )    ;   CALL dyn_ldf_bilap  ( kt )      ! iso-level bilaplacian
+      CASE ( 3 )    ;   CALL dyn_ldf_bilapg ( kt )      ! s-coord. horizontal bilaplacian
+      !
       CASE ( -1 )                                       ! esopa: test all possibility with control print
-         CALL dyn_ldf_lap    ( kt )
-         IF(ln_ctl) THEN         ! print sum trends (used for debugging)
-            CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf0 - Ua: ', mask1=umask, &
-               &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-         ENDIF
-         CALL dyn_ldf_iso    ( kt )
-         IF(ln_ctl) THEN         ! print sum trends (used for debugging)
-            CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf1 - Ua: ', mask1=umask, &
-               &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-         ENDIF
-         CALL dyn_ldf_bilap  ( kt )
-         IF(ln_ctl) THEN         ! print sum trends (used for debugging)
-            CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf2 - Ua: ', mask1=umask, &
-               &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-         ENDIF
-         CALL dyn_ldf_bilapg ( kt )
-         IF(ln_ctl) THEN         ! print sum trends (used for debugging)
-            CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf3 - Ua: ', mask1=umask, &
-               &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-         ENDIF
-
-      CASE ( 0 )                                       ! iso-level laplacian
-         CALL dyn_ldf_lap    ( kt )
-      CASE ( 1 )                                       ! rotated laplacian (except dk[ dk[.] ] part)
-         CALL dyn_ldf_iso    ( kt )
-      CASE ( 2 )                                       ! iso-level bilaplacian
-         CALL dyn_ldf_bilap  ( kt )
-      CASE ( 3 )                                       ! s-coord. horizontal bilaplacian
-         CALL dyn_ldf_bilapg ( kt )
+         ;              CALL dyn_ldf_lap    ( kt )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf0 - Ua: ', mask1=umask,   &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;              CALL dyn_ldf_iso    ( kt )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf1 - Ua: ', mask1=umask,   &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;              CALL dyn_ldf_bilap  ( kt )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf2 - Ua: ', mask1=umask,   &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;              CALL dyn_ldf_bilapg ( kt )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf3 - Ua: ', mask1=umask,   &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
       END SELECT
 
-      !                                          ! save the horizontal diffusive trends for further diagnostics
-      IF( l_trddyn )   THEN
+      IF( l_trddyn ) THEN                        ! save the horizontal diffusive trends for further diagnostics
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_mod( ztrdu, ztrdv, jpdtdldf, 'DYN', kt )
+         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_ldf, 'DYN', kt )
       ENDIF
-
-      IF(ln_ctl) THEN                            ! print mean trends (used for debugging)
-         CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf  - Ua: ', mask1=umask, &
-            &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-      ENDIF
-
+      !                                          ! print sum trends (used for debugging)
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' ldf  - Ua: ', mask1=umask,   &
+         &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
    END SUBROUTINE dyn_ldf
 
@@ -121,32 +102,23 @@
       !! 
       !! ** Purpose :   initializations of the horizontal ocean dynamics physics
-      !!
-      !! ** Method :
-      !!
-      !! History :
-      !!   9.0  !  05-11  (G. Madec)  Original code
       !!----------------------------------------------------------------------
-      !! * Local declarations
       INTEGER ::   ioptio, ierr         ! temporary integers 
       !!----------------------------------------------------------------------
+    
+      !                                   ! Namelist nam_dynldf: already read in ldfdyn module
 
-      !  Define the lateral dynamics physics parameters
-      ! =============================================
-    
-      ! Namelist nam_dynldf already read in ldfdyn module
-
-      IF(lwp) THEN
+      IF(lwp) THEN                        ! Namelist print
          WRITE(numout,*)
-         WRITE(numout,*) 'dyn:ldf_ctl : Choice of the lateral diffusive operator on dynamics'
+         WRITE(numout,*) 'dyn_ldf_ctl : Choice of the lateral diffusive operator on dynamics'
          WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*) '          Namelist nam_dynldf : set lateral mixing parameters (type, direction, coefficients)'
-         WRITE(numout,*) '             laplacian operator          ln_dynldf_lap   = ', ln_dynldf_lap
-         WRITE(numout,*) '             bilaplacian operator        ln_dynldf_bilap = ', ln_dynldf_bilap
-         WRITE(numout,*) '             iso-level                   ln_dynldf_level = ', ln_dynldf_level
-         WRITE(numout,*) '             horizontal (geopotential)   ln_dynldf_hor   = ', ln_dynldf_hor
-         WRITE(numout,*) '             iso-neutral                 ln_dynldf_iso   = ', ln_dynldf_iso
+         WRITE(numout,*) '       Namelist nam_dynldf : set lateral mixing parameters (type, direction, coefficients)'
+         WRITE(numout,*) '          laplacian operator          ln_dynldf_lap   = ', ln_dynldf_lap
+         WRITE(numout,*) '          bilaplacian operator        ln_dynldf_bilap = ', ln_dynldf_bilap
+         WRITE(numout,*) '          iso-level                   ln_dynldf_level = ', ln_dynldf_level
+         WRITE(numout,*) '          horizontal (geopotential)   ln_dynldf_hor   = ', ln_dynldf_hor
+         WRITE(numout,*) '          iso-neutral                 ln_dynldf_iso   = ', ln_dynldf_iso
       ENDIF
 
-      ! control the consistency
+      !                                   ! control the consistency
       ioptio = 0
       IF( ln_dynldf_lap   )   ioptio = ioptio + 1
@@ -159,5 +131,5 @@
       IF( ioptio /= 1 ) CALL ctl_stop( '          use only ONE direction (level/hor/iso)' )
 
-      ! defined the type of lateral diffusion from ln_dynldf_... logicals
+      !                                   ! Set nldf, the type of lateral diffusion, from ln_dynldf_... logicals
       ierr = 0
       IF ( ln_dynldf_lap ) THEN      ! laplacian operator
@@ -196,17 +168,11 @@
          ENDIF
       ENDIF
+      
+      IF( lk_esopa )                 nldf = -1     ! esopa test
 
-      IF( ierr == 1 )   &
-           &   CALL ctl_stop( ' iso-level in z-coordinate - partial step, not allowed' )
-      IF( ierr == 2 )   &
-           &   CALL ctl_stop( ' isoneutral bilaplacian operator does not exist' )
+      IF( ierr == 1 )   CALL ctl_stop( 'iso-level in z-coordinate - partial step, not allowed' )
+      IF( ierr == 2 )   CALL ctl_stop( 'isoneutral bilaplacian operator does not exist' )
       IF( nldf == 1 .OR. nldf == 3 ) THEN      ! rotation
-         IF( .NOT.lk_ldfslp )   &
-           &   CALL ctl_stop(  '          the rotation of the diffusive tensor require key_ldfslp' )
-      ENDIF
-
-      IF( lk_esopa ) THEN
-         IF(lwp ) WRITE(numout,*) '          esopa test: use all lateral physics options'
-         nldf = -1
+         IF( .NOT.lk_ldfslp )   CALL ctl_stop( 'the rotation of the diffusive tensor require key_ldfslp' )
       ENDIF
 
@@ -219,5 +185,5 @@
          IF( nldf ==  3 )   WRITE(numout,*) '              Rotated bilaplacian'
       ENDIF
-
+      !
    END SUBROUTINE dyn_ldf_ctl
 
Index: trunk/NEMO/OPA_SRC/DYN/dynspg.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 503)
@@ -4,4 +4,7 @@
    !! Ocean dynamics:  surface pressure gradient control
    !!======================================================================
+   !! History :  9.0  !  05-12  (C. Talandier, G. Madec)  Original code
+   !!            9.0  !  05-12  (V. Garnier)  dyn_spg_ctl: Original code
+   !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
@@ -9,5 +12,4 @@
    !!   dyn_spg_ctl : initialization, namelist read, and parameters control
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce            ! ocean dynamics and tracers variables
    USE dom_oce        ! ocean space and time domain variables
@@ -29,11 +31,8 @@
    PRIVATE
 
-   !! * Accessibility
    PUBLIC dyn_spg         ! routine called by step module
 
    !! * module variables
-   INTEGER ::                        &
-      nspg = 0                         ! type of surface pressure gradient scheme
-      !                                ! defined from lk_dynspg_... 
+   INTEGER ::   nspg = 0   ! type of surface pressure gradient scheme defined from lk_dynspg_... 
 
    !! * Substitutions
@@ -43,5 +42,5 @@
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -53,16 +52,10 @@
       !!
       !! ** Purpose :   compute the lateral ocean dynamics physics.
-      !!
-      !! History :
-      !!   9.0  !  05-12  (C. Talandier, G. Madec)  Original code
-      !!----------------------------------------------------------------------
-      !! * Arguments
+      !!----------------------------------------------------------------------
       INTEGER, INTENT( in  ) ::   kt     ! ocean time-step index
       INTEGER, INTENT( out ) ::   kindic ! solver flag
-
-      !! * local declarations
+      !!
       REAL(wp) ::   z2dt                      ! temporary scalar
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         ztrdu, ztrdv                         ! 3D temporary workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdu, ztrdv   ! 3D workspace
       !!----------------------------------------------------------------------
 
@@ -75,42 +68,36 @@
 
       SELECT CASE ( nspg )                       ! compute surf. pressure gradient trend and add it to the general trend
+      !                                                      ! k-j-i loops
+      CASE (  0 )   ;   CALL dyn_spg_exp    ( kt )              ! explicit
+      CASE (  1 )   ;   CALL dyn_spg_ts     ( kt )              ! time-splitting
+      CASE (  2 )   ;   CALL dyn_spg_flt    ( kt, kindic )      ! filtered
+      CASE (  3 )   ;   CALL dyn_spg_rl     ( kt, kindic )      ! rigid lid
+      !                                                      ! j-k-i loops
+      CASE ( 10 )   ;   CALL dyn_spg_exp_jki( kt )              ! explicit with j-k-i loop
+      CASE ( 11 )   ;   CALL dyn_spg_ts_jki ( kt )              ! time-splitting with j-k-i loop
+      CASE ( 12 )   ;   CALL dyn_spg_flt_jki( kt, kindic )      ! filtered with j-k-i loop
+      !
       CASE ( -1 )                                       ! esopa: test all possibility with control print
-         CALL dyn_spg_exp    ( kt )
-         IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' spg0 - Ua: ', mask1=umask, &
-               &                    tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-         CALL dyn_spg_ts     ( kt )
-         IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' spg1 - Ua: ', mask1=umask, &
-               &                    tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-         CALL dyn_spg_flt  ( kt, kindic )
-         IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' spg2 - Ua: ', mask1=umask, &
-               &                    tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-         CALL dyn_spg_exp_jki( kt )
-         IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' spg10- Ua: ', mask1=umask, &
-               &                    tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-         CALL dyn_spg_ts_jki ( kt )
-         IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' spg12- Ua: ', mask1=umask, &
-               &                    tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-         CALL dyn_spg_flt_jki( kt, kindic )
-         IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' spg13- Ua: ', mask1=umask, &
-               &                    tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-      CASE (  0 )                                       ! explicit
-         CALL dyn_spg_exp    ( kt )
-      CASE (  1 )                                       ! time-splitting
-         CALL dyn_spg_ts     ( kt )
-      CASE (  2 )                                       ! filtered
-         CALL dyn_spg_flt    ( kt, kindic )
-      CASE (  3 )                                       ! rigid lid
-         CALL dyn_spg_rl     ( kt, kindic )
-
-      CASE ( 10 )                                       ! explicit with j-k-i loop
-         CALL dyn_spg_exp_jki( kt )
-      CASE ( 11 )                                       ! time-splitting with j-k-i loop
-         CALL dyn_spg_ts_jki ( kt )
-      CASE ( 12 )                                       ! filtered with j-k-i loop
-         CALL dyn_spg_flt_jki( kt, kindic )
+         ;              CALL dyn_spg_exp    ( kt )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' spg0 - Ua: ', mask1=umask, &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;              CALL dyn_spg_ts     ( kt )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' spg1 - Ua: ', mask1=umask, &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;              CALL dyn_spg_flt  ( kt, kindic )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' spg2 - Ua: ', mask1=umask, &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;              CALL dyn_spg_exp_jki( kt )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' spg10- Ua: ', mask1=umask, &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;              CALL dyn_spg_ts_jki ( kt )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' spg12- Ua: ', mask1=umask, &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;              CALL dyn_spg_flt_jki( kt, kindic )
+         ;              CALL prt_ctl( tab3d_1=ua, clinfo1=' spg13- Ua: ', mask1=umask, &
+            &                         tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
       END SELECT
-
-      !                                          ! save the horizontal diffusive trends for further diagnostics
-      IF( l_trddyn )   THEN
+      !                    
+      IF( l_trddyn )   THEN                      ! save the horizontal diffusive trends for further diagnostics
          SELECT CASE ( nspg )
          CASE ( 0, 1, 3, 10, 11 )
@@ -123,11 +110,10 @@
             ztrdv(:,:,:) = ( va(:,:,:) - vb(:,:,:) ) / z2dt - ztrdv(:,:,:)
          END SELECT
-         CALL trd_mod( ztrdu, ztrdv, jpdtdspg, 'DYN', kt )
-      ENDIF
-
+         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_spg, 'DYN', kt )
+      ENDIF
       !                                          ! print mean trends (used for debugging)
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' spg  - Ua: ', mask1=umask, &
          &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-
+      !
    END SUBROUTINE dyn_spg
 
@@ -139,7 +125,4 @@
       !! ** Purpose :   Control the consistency between cpp options for 
       !!      surface pressure gradient schemes
-      !!
-      !! History :
-      !!   9.0  !  05-10  (V. Garnier)  Original code : spg re-organization
       !!----------------------------------------------------------------------
       !! * Local declarations
Index: trunk/NEMO/OPA_SRC/DYN/dynspg_flt_jki.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DYN/dynspg_flt_jki.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/DYN/dynspg_flt_jki.F90	(revision 503)
@@ -9,13 +9,9 @@
    !!   'key_mpp_omp'                              j-k-i loop (vector opt.)
    !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !!   dyn_spg_flt_jki : Update the momentum trend with the surface pressure
    !!                     gradient for the free surf. constant volume case
    !!                     with auto-tasking (j-slab) (no vectior opt.)
    !!----------------------------------------------------------------------
-   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
-   !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
-   !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and tracers 
    USE dom_oce         ! ocean space and time domain
@@ -51,5 +47,5 @@
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -100,21 +96,9 @@
       !! ** Action : - Update (ua,va) with the surf. pressure gradient trend
       !!
-      !! References :
-      !!      Roullet and Madec 1999, JGR.
-      !!
-      !! History :
-      !!        !  98-05 (G. Roullet)  Original code
-      !!        !  98-10 (G. Madec, M. Imbard)  release 8.2
-      !!   8.5  !  02-08 (G. Madec)  F90: Free form and module
-      !!        !  02-11 (C. Talandier, A-M Treguier) Open boundaries
-      !!   9.0  !  04-08 (C. Talandier) New trends organization
-      !!    "   !  05-11  (V. Garnier) Surface pressure gradient organization
+      !! References : Roullet and Madec 1999, JGR.
       !!---------------------------------------------------------------------
-      !! * Arguments
       INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
-      INTEGER, INTENT( out ) ::   kindic     ! solver convergence flag
-                                             ! if the solver doesn t converge
-                                             ! the flag is < 0
-      !! * Local declarations
+      INTEGER, INTENT( out ) ::   kindic     ! solver convergence flag, <0 if the solver doesn t converge
+      !!
       INTEGER  ::   ji, jj, jk               ! dummy loop indices
       REAL(wp) ::   &              ! temporary scalars
@@ -154,5 +138,4 @@
             spgv(ji,jj) = - grav * ( sshn(ji  ,jj+1) - sshn(ji,jj) ) / e2v(ji,jj)
          END DO 
-
          !  Add the surface pressure trend to the general trend
          DO jk = 1, jpkm1
@@ -162,5 +145,4 @@
             END DO
          END DO
-
          ! Evaluate the masked next velocity (effect of the additional force not included)
          DO jk = 1, jpkm1
@@ -170,5 +152,4 @@
             END DO
          END DO
-
          !                                             ! ===============
       END DO                                           !   End of slab
@@ -202,5 +183,4 @@
             spgv(ji,jj) = 0.e0
          END DO
-
          ! vertical sum
          DO jk = 1, jpk
@@ -210,5 +190,4 @@
             END DO
          END DO
-
          ! transport: multiplied by the horizontal scale factor
          DO ji = 2, jpim1
@@ -216,5 +195,4 @@
             spgv(ji,jj) = spgv(ji,jj) * e1v(ji,jj)
          END DO
-
          !                                             ! ===============
       END DO                                           !   End of slab
@@ -302,10 +280,9 @@
             WRITE(ctmp1,*) ' ~~~~~~~~~~~~~~~~                not = ', nsolv
             CALL ctl_stop( ' dyn_spg_flt_jki : e r r o r, nsolv = 1, 2, 3 or 4', ctmp1 )
-      ENDIF
-
-      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
-
-!CDIR PARALLEL DO
-!$OMP PARALLEL DO
+         ENDIF
+      ENDIF
+
+      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+
       !                                                ! ===============
       DO jj = 2, jpjm1                                 !  Vertical slab
@@ -353,6 +330,5 @@
          ! 8. Sea surface elevation time stepping
          ! --------------------------------------
-         ! Euler (forward) time stepping, no time filter
-         IF( neuler == 0 .AND. kt == nit000 ) THEN
+         IF( neuler == 0 .AND. kt == nit000 ) THEN         ! Euler (forward) time stepping, no time filter
             DO ji = 1, jpi
                ! after free surface elevation
@@ -362,6 +338,5 @@
                sshn(ji,jj) = zssha
             END DO
-         ELSE
-            ! Leap-frog time stepping and time filter
+         ELSE                                              ! Leap-frog time stepping and time filter
             DO ji = 1, jpi
                ! after free surface elevation
@@ -384,6 +359,5 @@
          CALL prt_ctl( tab2d_1=sshn, clinfo1=' spg  - ssh: ', mask1=tmask)
       ENDIF
-
-
+      !
    END SUBROUTINE dyn_spg_flt_jki
 
Index: trunk/NEMO/OPA_SRC/DYN/dynvor.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 503)
@@ -5,4 +5,12 @@
    !!                 planetary vorticity trends
    !!======================================================================
+   !! History :  1.0  !  89-12  (P. Andrich)  vor_ens: Original code
+   !!            5.0  !  91-11  (G. Madec) vor_ene, vor_mix: Original code
+   !!            6.0  !  96-01  (G. Madec)  s-coord, suppress work arrays
+   !!            8.5  !  02-08  (G. Madec)  F90: Free form and module
+   !!            8.5  !  04-02  (G. Madec)  vor_een: Original code
+   !!            9.0  !  03-08  (G. Madec)  vor_ctl: Original code
+   !!            9.0  !  05-11  (G. Madec)  dyn_vor: Original code (new step architecture)
+   !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
@@ -14,28 +22,25 @@
    !!       vor_ctl : control of the different vorticity option
    !!----------------------------------------------------------------------
-   !! * Modules used
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   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 prtctl          ! Print control
+   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 lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl         ! Print control
+   USE in_out_manager ! I/O manager
 
    IMPLICIT NONE
    PRIVATE
 
-   !! * Routine accessibility
-   PUBLIC dyn_vor      ! routine called by step.F90
-
-   !! * Shared module variables
+   PUBLIC   dyn_vor   ! routine called by step.F90
+
+   !!* Namelist nam_dynvor: vorticity term
    LOGICAL, PUBLIC ::   ln_dynvor_ene = .FALSE.   !: energy conserving scheme
    LOGICAL, PUBLIC ::   ln_dynvor_ens = .TRUE.    !: enstrophy conserving scheme
    LOGICAL, PUBLIC ::   ln_dynvor_mix = .FALSE.   !: mixed scheme
-   LOGICAL, PUBLIC ::   ln_dynvor_een = .FALSE.    !: energy and enstrophy conserving scheme
-
-   !! * module variables
-   INTEGER ::                        &
-      nvor = 0                         ! type of vorticity trend used
+   LOGICAL, PUBLIC ::   ln_dynvor_een = .FALSE.   !: energy and enstrophy conserving scheme
+   NAMELIST/nam_dynvor/ ln_dynvor_ens, ln_dynvor_ene, ln_dynvor_mix, ln_dynvor_een
+
+   INTEGER ::   nvor = 0   ! type of vorticity trend used
 
    !! * Substitutions
@@ -43,5 +48,7 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -54,15 +61,11 @@
       !!
       !! ** Action : - Update (ua,va) with the now vorticity term trend
-      !!             - save the trends in (utrd,vtrd) in 2 parts (relative
+      !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
       !!               and planetary vorticity trends) ('key_trddyn')
-      !!
-      !! History :
-      !!   9.0  !  05-11  (G. Madec)  Original code
-      !!----------------------------------------------------------------------
-      USE oce, ONLY :    ztrdu => ta,     & ! use ta as 3D workspace
-                         ztrdv => sa        ! use sa as 3D workspace
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   ztrdu => ta   ! use ta as 3D workspace
+      USE oce, ONLY :   ztrdv => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
       !!----------------------------------------------------------------------
 
@@ -74,15 +77,15 @@
       CASE ( -1 )                                      ! esopa: test all possibility with control print
          CALL vor_ene( kt, 'TOT', ua, va )
-         IF(ln_ctl) CALL prt_ctl( tab3d_1=ua, clinfo1=' vor0 - Ua: ', mask1=umask, &
-            &                     tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         CALL prt_ctl( tab3d_1=ua, clinfo1=' vor0 - Ua: ', mask1=umask, &
+            &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
          CALL vor_ens( kt, 'TOT', ua, va )
-         IF(ln_ctl) CALL prt_ctl( tab3d_1=ua, clinfo1=' vor1 - Ua: ', mask1=umask, &
-            &                     tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         CALL prt_ctl( tab3d_1=ua, clinfo1=' vor1 - Ua: ', mask1=umask, &
+            &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
          CALL vor_mix( kt )
-         IF(ln_ctl) CALL prt_ctl( tab3d_1=ua, clinfo1=' vor2 - Ua: ', mask1=umask, &
-            &                     tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         CALL prt_ctl( tab3d_1=ua, clinfo1=' vor2 - Ua: ', mask1=umask, &
+            &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
          CALL vor_een( kt, 'TOT', ua, va )
-         IF(ln_ctl) CALL prt_ctl( tab3d_1=ua, clinfo1=' vor3 - Ua: ', mask1=umask, &
-            &                     tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         CALL prt_ctl( tab3d_1=ua, clinfo1=' vor3 - Ua: ', mask1=umask, &
+            &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
 
       CASE ( 0 )                                       ! energy conserving scheme
@@ -93,5 +96,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdtdrvo, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
             ztrdu(:,:,:) = ua(:,:,:)
             ztrdv(:,:,:) = va(:,:,:)
@@ -99,6 +102,6 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdu, jpdtdpvo, 'DYN', kt )
-            CALL trd_mod( ztrdu, ztrdv, jpdtddat, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdu, jpdyn_trd_pvo, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_dat, 'DYN', kt )
          ELSE
             CALL vor_ene( kt, 'TOT', ua, va )                ! total vorticity
@@ -112,5 +115,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdtdrvo, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
             ztrdu(:,:,:) = ua(:,:,:)
             ztrdv(:,:,:) = va(:,:,:)
@@ -118,6 +121,6 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdu, jpdtdpvo, 'DYN', kt )
-            CALL trd_mod( ztrdu, ztrdv, jpdtddat, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdu, jpdyn_trd_pvo, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_dat, 'DYN', kt )
          ELSE
             CALL vor_ens( kt, 'TOT', ua, va )                ! total vorticity
@@ -131,5 +134,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdtdrvo, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
             ztrdu(:,:,:) = ua(:,:,:)
             ztrdv(:,:,:) = va(:,:,:)
@@ -137,6 +140,6 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdu, jpdtdpvo, 'DYN', kt )
-            CALL trd_mod( ztrdu, ztrdv, jpdtddat, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdu, jpdyn_trd_pvo, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_dat, 'DYN', kt )
          ELSE
             CALL vor_mix( kt )                               ! total vorticity (mix=ens-ene)
@@ -150,5 +153,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdtdrvo, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
             ztrdu(:,:,:) = ua(:,:,:)
             ztrdv(:,:,:) = va(:,:,:)
@@ -156,6 +159,6 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdu, jpdtdpvo, 'DYN', kt )
-            CALL trd_mod( ztrdu, ztrdv, jpdtddat, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdu, jpdyn_trd_pvo, 'DYN', kt )
+            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_dat, 'DYN', kt )
          ELSE
             CALL vor_een( kt, 'TOT', ua, va )                ! total vorticity
@@ -192,30 +195,19 @@
       !!
       !! ** Action : - Update (ua,va) with the now vorticity term trend
-      !!             - save the trends in (utrd,vtrd) in 2 parts (relative
+      !!             - 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.
-      !! History :
-      !!   5.0  !  91-11  (G. Madec)  Original code
-      !!   6.0  !  96-01  (G. Madec)  s-coord, suppress work arrays
-      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
-      !!   9.0  !  04-08  (C. Talandier)  New trends organization
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
-      CHARACTER(len=3) , INTENT( in ) ::   &
-         cd_vor        ! define the vorticity considered
-         !             ! ='COR' (planetary) ; ='VOR' (relative) ; ='TOT' (total)
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
-         pua, pva                      ! ????
-
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk               ! dummy loop indices
-      REAL(wp) ::   &
-         zfact2,                         &  ! temporary scalars
-         zx1, zx2, zy1, zy2                 !    "         "
-      REAL(wp), DIMENSION(jpi,jpj) ::   &
-         zwx, zwy, zwz                      ! temporary workspace
+      !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
+      !!----------------------------------------------------------------------
+      INTEGER          , INTENT(in   )                         ::   kt       ! ocean time-step index
+      CHARACTER(len=3) , INTENT(in   )                         ::   cd_vor   ! ='COR' (planetary) ; ='VOR' (relative)
+         !                                                                   ! ='TOT' (total)
+      REAL(wp)         , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pua      ! total u-trend
+      REAL(wp)         , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pva      ! total v-trend
+      !!
+      INTEGER  ::   ji, jj, jk         ! dummy loop indices
+      REAL(wp) ::   zx1, zy1, zfact2   ! temporary scalars
+      REAL(wp) ::   zx2, zy2           !    "         "
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz   ! temporary 2D workspace
       !!----------------------------------------------------------------------
 
@@ -234,14 +226,10 @@
       DO jk = 1, jpkm1                                 ! Horizontal slab
          !                                             ! ===============
-         
          ! Potential vorticity and horizontal fluxes
          ! -----------------------------------------
          SELECT CASE( cd_vor )      ! vorticity considered
-         CASE ( 'COR' )                   ! planetary vorticcity (Coriolis)
-            zwz(:,:) = ff(:,:)
-         CASE ( 'VOR' )                   ! relative  vorticity
-            zwz(:,:) = rotn(:,:,jk)
-         CASE ( 'TOT' )                   ! total     vorticity (planetary + relative)
-            zwz(:,:) = rotn(:,:,jk) + ff(:,:)
+         CASE ( 'COR' )   ;   zwz(:,:) =                  ff(:,:)      ! planetary vorticity (Coriolis)
+         CASE ( 'VOR' )   ;   zwz(:,:) =   rotn(:,:,jk)                ! relative  vorticity
+         CASE ( 'TOT' )   ;   zwz(:,:) = ( rotn(:,:,jk) + ff(:,:) )    ! total     vorticity 
          END SELECT
 
@@ -270,5 +258,4 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-
    END SUBROUTINE vor_ene
 
@@ -300,25 +287,15 @@
       !!
       !! ** Action : - Update (ua,va) arrays with the now vorticity term trend
-      !!             - Save the trends in (utrd,vtrd) in 2 parts (relative
+      !!             - 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.
-      !! History :
-      !!   5.0  !  91-11  (G. Madec) Original code, enstrophy-energy-combined schemes
-      !!   6.0  !  96-01  (G. Madec) s-coord, suppress work arrays
-      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
-      !!   9.0  !  04-08  (C. Talandier)  New trends organization
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt         ! ocean timestep index
-
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk               ! dummy loop indices
-      REAL(wp) ::   &
-         zfact1, zfact2, zua, zva,       &  ! temporary scalars
-         zcua, zcva, zx1, zx2, zy1, zy2
-      REAL(wp), DIMENSION(jpi,jpj) ::   &
-         zwx, zwy, zwz, zww                 ! temporary workspace
+      !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean timestep index
+      !!
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zfact1, zua, zcua, zx1, zy1   ! temporary scalars
+      REAL(wp) ::   zfact2, zva, zcva, zx2, zy2   !    "         "
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz, zww   ! temporary 3D workspace
       !!----------------------------------------------------------------------
 
@@ -367,5 +344,5 @@
                zcua = zfact2 * ( zwz(ji  ,jj-1) * zy1 + zwz(ji,jj) * zy2 )
                zcva =-zfact2 * ( zwz(ji-1,jj  ) * zx1 + zwz(ji,jj) * zx2 )
-
+               ! mixed vorticity trend added to the momentum trends
                ua(ji,jj,jk) = ua(ji,jj,jk) + zcua + zua
                va(ji,jj,jk) = va(ji,jj,jk) + zcva + zva
@@ -375,5 +352,4 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-
    END SUBROUTINE vor_mix
 
@@ -400,29 +376,18 @@
       !!
       !! ** Action : - Update (ua,va) arrays with the now vorticity term trend
-      !!             - Save the trends in (utrd,vtrd) in 2 parts (relative 
+      !!             - 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.
-      !! History :
-      !!   5.0  !  91-11  (G. Madec)  Original code
-      !!   6.0  !  96-01  (G. Madec)  s-coord, suppress work arrays
-      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
-      !!   9.0  !  04-08  (C. Talandier)  New trends organization
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt    ! ocean timestep
-      CHARACTER(len=3) , INTENT( in ) ::   &
-         cd_vor        ! define the vorticity considered
-         !             ! ='COR' (planetary) ; ='VOR' (relative) ; ='TOT' (total)
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
-         pua, pva                      ! ????
-
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk          ! dummy loop indices
-      REAL(wp) ::   &
-         zfact1, zuav, zvau            ! temporary scalars
-      REAL(wp), DIMENSION(jpi,jpj) ::   &
-         zwx, zwy, zwz                 ! temporary workspace
+      !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
+      !!----------------------------------------------------------------------
+      INTEGER          , INTENT(in   )                         ::   kt       ! ocean time-step index
+      CHARACTER(len=3) , INTENT(in   )                         ::   cd_vor   ! ='COR' (planetary) ; ='VOR' (relative)
+         !                                                                   ! ='TOT' (total)
+      REAL(wp)         , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pua      ! total u-trend
+      REAL(wp)         , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pva      ! total v-trend
+      !!
+      INTEGER  ::   ji, jj, jk           ! dummy loop indices
+      REAL(wp) ::   zfact1, zuav, zvau   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz   ! temporary 3D workspace
       !!----------------------------------------------------------------------
       
@@ -441,14 +406,10 @@
       DO jk = 1, jpkm1                                 ! Horizontal slab
          !                                             ! ===============
-
          ! Potential vorticity and horizontal fluxes
          ! -----------------------------------------
          SELECT CASE( cd_vor )      ! vorticity considered
-         CASE ( 'COR' )                   ! planetary vorticcity (Coriolis)
-            zwz(:,:) = ff(:,:)
-         CASE ( 'VOR' )                   ! relative  vorticity
-            zwz(:,:) = rotn(:,:,jk)
-         CASE ( 'TOT' )                   ! total     vorticity (planetary + relative)
-            zwz(:,:) = rotn(:,:,jk) + ff(:,:)
+         CASE ( 'COR' )   ;   zwz(:,:) =                  ff(:,:)      ! planetary vorticity (Coriolis)
+         CASE ( 'VOR' )   ;   zwz(:,:) =   rotn(:,:,jk)                ! relative  vorticity
+         CASE ( 'TOT' )   ;   zwz(:,:) = ( rotn(:,:,jk) + ff(:,:) )    ! total     vorticity 
          END SELECT
 
@@ -470,5 +431,4 @@
          ENDIF
 
-
          ! Compute and add the vorticity term trend
          ! ----------------------------------------
@@ -476,8 +436,7 @@
             DO ji = fs_2, fs_jpim1   ! vector opt.
                zuav = zfact1 / e1u(ji,jj) * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1)   &
-                                            + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) )
+                  &                         + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) )
                zvau =-zfact1 / e2v(ji,jj) * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1)   &
-                                            + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) )
-
+                  &                         + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) )
                pua(ji,jj,jk) = pua(ji,jj,jk) + zuav * ( zwz(ji  ,jj-1) + zwz(ji,jj) )
                pva(ji,jj,jk) = pva(ji,jj,jk) + zvau * ( zwz(ji-1,jj  ) + zwz(ji,jj) )
@@ -487,5 +446,4 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-
    END SUBROUTINE vor_ens
 
@@ -509,33 +467,20 @@
       !!
       !! ** Action : - Update (ua,va) with the now vorticity term trend
-      !!             - save the trends in (utrd,vtrd) in 2 parts (relative
+      !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
       !!               and planetary vorticity trends) ('key_trddyn')
       !!
-      !! References :
-      !!      Arakawa and Lamb 1980, A potential enstrophy and energy conserving
-      !!                             scheme for the Shallow water equations, 
-      !!                             Monthly Weather Review, vol. 109, p 18-36
-      !!
-      !! History :
-      !!   8.5  !  04-02  (G. Madec)  Original code
-      !!   9.0  !  04-08  (C. Talandier)  New trends organization
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt        ! ocean time-step index
-      CHARACTER(len=3) , INTENT( in ) ::   &
-         cd_vor        ! define the vorticity considered
-         !             ! ='COR' (planetary) ; ='VOR' (relative) ; ='TOT' (total)
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
-         pua, pva                      ! ????
-
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk              ! dummy loop indices
-      REAL(wp) ::   &
-         zfac12, zua, zva                  ! temporary scalars
-      REAL(wp), DIMENSION(jpi,jpj) ::   &
-         zwx, zwy, zwz,                 &  ! temporary workspace
-         ztnw, ztne, ztsw, ztse            !    "           "
-      REAL(wp), DIMENSION(jpi,jpj,jpk), SAVE ::   &
-         ze3f
+      !! References : Arakawa and Lamb 1980, Mon. Wea. Rev., 109, 18-36
+      !!----------------------------------------------------------------------
+      INTEGER          , INTENT(in   )                         ::   kt       ! ocean time-step index
+      CHARACTER(len=3) , INTENT(in   )                         ::   cd_vor   ! ='COR' (planetary) ; ='VOR' (relative)
+         !                                                                   ! ='TOT' (total)
+      REAL(wp)         , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pua      ! total u-trend
+      REAL(wp)         , INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pva      ! total v-trend
+      !!
+      INTEGER ::   ji, jj, jk          ! dummy loop indices
+      REAL(wp) ::   zfac12, zua, zva   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz            ! temporary 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztnw, ztne, ztsw, ztse   ! temporary 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk), SAVE ::   ze3f
       !!----------------------------------------------------------------------
 
@@ -570,10 +515,7 @@
          ! -----------------------------------------
          SELECT CASE( cd_vor )      ! vorticity considered
-         CASE ( 'COR' )                   ! planetary vorticcity (Coriolis)
-            zwz(:,:) = ff(:,:) * ze3f(:,:,jk)
-         CASE ( 'VOR' )                   ! relative  vorticity
-            zwz(:,:) = rotn(:,:,jk) * ze3f(:,:,jk)
-         CASE ( 'TOT' )                   ! total     vorticity (planetary + relative)
-            zwz(:,:) = ( rotn(:,:,jk) + ff(:,:) ) * ze3f(:,:,jk)
+         CASE ( 'COR' )   ;   zwz(:,:) =                  ff(:,:)   * ze3f(:,:,jk)   ! planetary vorticity (Coriolis)
+         CASE ( 'VOR' )   ;   zwz(:,:) =   rotn(:,:,jk)             * ze3f(:,:,jk)   ! relative  vorticity
+         CASE ( 'TOT' )   ;   zwz(:,:) = ( rotn(:,:,jk) + ff(:,:) ) * ze3f(:,:,jk)   ! total     vorticity 
          END SELECT
 
@@ -599,5 +541,4 @@
             END DO
          END DO
-         
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -613,5 +554,4 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-
    END SUBROUTINE vor_een
 
@@ -623,67 +563,49 @@
       !! ** Purpose :   Control the consistency between cpp options for
       !!      tracer advection schemes
-      !!
-      !! History :
-      !!   9.0  !  03-08  (G. Madec)  Original code
-      !!----------------------------------------------------------------------
-      !! * Local declarations
+      !!----------------------------------------------------------------------
       INTEGER ::   ioptio          ! temporary integer
-
-      NAMELIST/nam_dynvor/ ln_dynvor_ens, ln_dynvor_ene, ln_dynvor_mix, ln_dynvor_een
-      !!----------------------------------------------------------------------
-
-      ! Read Namelist nam_dynvor : Vorticity scheme options
-      ! ------------------------
-      REWIND ( numnam )
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )               ! Read Namelist nam_dynvor : Vorticity scheme options
       READ   ( numnam, nam_dynvor )
 
-      ! Control of vorticity scheme options
-      ! -----------------------------------
-      ! Control print
-      IF(lwp) THEN
+      IF(lwp) THEN                    ! Namelist print
          WRITE(numout,*)
          WRITE(numout,*) 'dyn:vor_ctl : vorticity term : read namelist and control the consistency'
          WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*) '              Namelist nam_dynvor : oice of the vorticity term scheme'
-         WRITE(numout,*) '                 energy    conserving scheme                ln_dynvor_ene = ', ln_dynvor_ene
-         WRITE(numout,*) '                 enstrophy conserving scheme                ln_dynvor_ens = ', ln_dynvor_ens
-         WRITE(numout,*) '                 mixed enstrophy/energy conserving scheme   ln_dynvor_mix = ', ln_dynvor_mix
-         WRITE(numout,*) '                 enstrophy and energy conserving scheme     ln_dynvor_een = ', ln_dynvor_een
+         WRITE(numout,*) '        Namelist nam_dynvor : oice of the vorticity term scheme'
+         WRITE(numout,*) '           energy    conserving scheme                ln_dynvor_ene = ', ln_dynvor_ene
+         WRITE(numout,*) '           enstrophy conserving scheme                ln_dynvor_ens = ', ln_dynvor_ens
+         WRITE(numout,*) '           mixed enstrophy/energy conserving scheme   ln_dynvor_mix = ', ln_dynvor_mix
+         WRITE(numout,*) '           enstrophy and energy conserving scheme     ln_dynvor_een = ', ln_dynvor_een
       ENDIF
 
-      ioptio = 0
-      IF( ln_dynvor_ene ) THEN
-         nvor = 0
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) '              vorticity term : energy conserving scheme'
-         ioptio = ioptio + 1
+      ioptio = 0                     ! Control of vorticity scheme options
+      IF( ln_dynvor_ene )   ioptio = ioptio + 1
+      IF( ln_dynvor_ens )   ioptio = ioptio + 1
+      IF( ln_dynvor_mix )   ioptio = ioptio + 1
+      IF( ln_dynvor_een )   ioptio = ioptio + 1
+      IF( lk_esopa      )   ioptio =          1
+
+      IF( ioptio /= 1 ) CALL ctl_stop( ' use ONE and ONLY one vorticity scheme' )
+
+      !                              ! Set nvor
+      IF( ln_dynvor_ene )   nvor =  0
+      IF( ln_dynvor_ens )   nvor =  1
+      IF( ln_dynvor_mix )   nvor =  2
+      IF( ln_dynvor_een )   nvor =  3
+      IF( lk_esopa      )   nvor = -1
+      
+      IF(lwp) THEN                   ! Print the choice
+         WRITE(numout,*)
+         IF( nvor ==  0 )   WRITE(numout,*) '         vorticity term used : energy conserving scheme'
+         IF( nvor ==  1 )   WRITE(numout,*) '         vorticity term used : enstrophy conserving scheme'
+         IF( nvor ==  2 )   WRITE(numout,*) '         vorticity term used : mixed enstrophy/energy conserving scheme'
+         IF( nvor ==  3 )   WRITE(numout,*) '         vorticity term used : energy and enstrophy conserving scheme'
+         IF( nvor == -1 )   WRITE(numout,*) '         esopa test: use all lateral physics options'
       ENDIF
-      IF( ln_dynvor_ens ) THEN
-         nvor = 1
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) '              vorticity term : enstrophy conserving scheme'
-         ioptio = ioptio + 1
-      ENDIF
-      IF( ln_dynvor_mix ) THEN
-         nvor = 2
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) '              vorticity term : mixed enstrophy/energy conserving scheme'
-         ioptio = ioptio + 1
-      ENDIF
-      IF( ln_dynvor_een ) THEN
-         nvor = 3
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) '              vorticity term : energy and enstrophy conserving scheme'
-         ioptio = ioptio + 1
-      ENDIF
-      IF( ioptio /= 1 .AND. .NOT. lk_esopa ) CALL ctl_stop( ' use ONE and ONLY one vorticity scheme' )
-      IF( lk_esopa ) THEN
-         nvor = -1
-         IF(lwp ) WRITE(numout,*) '          esopa test: use all lateral physics options'
-      ENDIF
-      IF(lwp) WRITE(numout,*) '             choice of vor_...                nvor   = ', nvor
-
+      !
    END SUBROUTINE vor_ctl
 
-!!==============================================================================
+   !!==============================================================================
 END MODULE dynvor
Index: trunk/NEMO/OPA_SRC/DYN/dynzad.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DYN/dynzad.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/DYN/dynzad.F90	(revision 503)
@@ -4,22 +4,26 @@
    !! Ocean dynamics : vertical advection trend
    !!======================================================================
+   !! History :  6.0  !  91-01  (G. Madec) Original code
+   !!            7.0  !  91-11  (G. Madec)
+   !!            7.5  !  96-01  (G. Madec) statement function for e3
+   !!            8.5  !  02-07  (G. Madec) j-k-i case: Original code
+   !!            8.5  !  02-07  (G. Madec) Free form, F90
+   !!----------------------------------------------------------------------
    
    !!----------------------------------------------------------------------
-   !!   dyn_zad      : vertical advection momentum trend
-   !!----------------------------------------------------------------------
-   !! * Modules used
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE in_out_manager  ! I/O manager
-   USE trdmod          ! ocean dynamics trends 
-   USE trdmod_oce      ! ocean variables trends
-   USE flxrnf          ! ocean runoffs
-   USE prtctl          ! Print control
+   !!   dyn_zad       : vertical advection momentum trend
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE in_out_manager ! I/O manager
+   USE trdmod         ! ocean dynamics trends 
+   USE trdmod_oce     ! ocean variables trends
+   USE flxrnf         ! ocean runoffs
+   USE prtctl         ! Print control
 
    IMPLICIT NONE
    PRIVATE
    
-   !! * Accessibility
-   PUBLIC dyn_zad                ! routine called by step.F90
+   PUBLIC   dyn_zad   ! routine called by step.F90
 
    !! * Substitutions
@@ -29,5 +33,5 @@
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -54,27 +58,15 @@
       !!
       !! ** Action  : - Update (ua,va) with the vert. momentum advection trends
-      !!              - Save the trends in (utrd,vtrd) ('key_trddyn')
-      !!
-      !! History :
-      !!   6.0  !  91-01  (G. Madec) Original code
-      !!   7.0  !  91-11  (G. Madec)
-      !!   7.5  !  96-01  (G. Madec) statement function for e3
-      !!   8.5  !  02-07  (G. Madec) Free form, F90
-      !!   9.0  !  04-08  (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------
-      !! * modules used
-      USE oce, ONLY:   zwuw => ta,   & ! use ta as 3D workspace
-                       zwvw => sa      ! use sa as 3D workspace
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt    ! ocean time-step inedx
-      
-      !! * Local declarations
-      INTEGER  ::   ji, jj, jk         ! dummy loop indices
-      REAL(wp) ::   zvn, zua, zva      ! temporary scalars
-      REAL(wp), DIMENSION(jpi) ::   &
-         zww                           ! temporary workspace
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         ztdua, ztdva                  ! temporary workspace
+      !!              - Save the trends in (ztrdu,ztrdv) ('key_trddyn')
+      !!----------------------------------------------------------------------
+      USE oce, ONLY:   zwuw => ta   ! use ta as 3D workspace
+      USE oce, ONLY:   zwvw => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step inedx
+      !!
+      INTEGER  ::   ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   zvn, zua, zva   ! temporary scalars
+      REAL(wp), DIMENSION(jpi)         ::   zww            ! 1D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdu, ztrdv   ! 3D workspace
       !!----------------------------------------------------------------------
       
@@ -85,8 +77,7 @@
       ENDIF
 
-      ! Save ua and va trends
-      IF( l_trddyn )   THEN
-         ztdua(:,:,:) = ua(:,:,:) 
-         ztdva(:,:,:) = va(:,:,:) 
+      IF( l_trddyn )   THEN         ! Save ua and va trends
+         ztrdu(:,:,:) = ua(:,:,:) 
+         ztrdv(:,:,:) = va(:,:,:) 
       ENDIF
 
@@ -94,14 +85,9 @@
       DO jj = 2, jpjm1                                 !  Vertical slab
          !                                             ! ===============
-
-         ! Vertical momentum advection at level w and u- and v- vertical
-         ! ----------------------------------------------------------------
-         DO jk = 2, jpkm1
-            ! vertical fluxes 
-            DO ji = 2, jpi
+         DO jk = 2, jpkm1         ! Vertical momentum advection at uw and vw-pts
+            DO ji = 2, jpi              ! vertical fluxes 
                zww(ji) = 0.25 * e1t(ji,jj) * e2t(ji,jj) * wn(ji,jj,jk)
             END DO
-            ! vertical momentum advection at w-point
-            DO ji = 2, jpim1
+            DO ji = 2, jpim1            ! vertical momentum advection at w-point
                zvn = 0.25 * e1t(ji,jj+1) * e2t(ji,jj+1) * wn(ji,jj+1,jk)
                zwuw(ji,jj,jk) = ( zww(ji+1) + zww(ji) ) * ( un(ji,jj,jk-1)-un(ji,jj,jk) )
@@ -109,7 +95,5 @@
             END DO  
          END DO   
-
-         ! Surface and bottom values set to zero
-         DO ji = 2, jpim1
+         DO ji = 2, jpim1               ! Surface and bottom values set to zero
             zwuw(ji,jj, 1 ) = 0.e0
             zwvw(ji,jj, 1 ) = 0.e0
@@ -117,13 +101,11 @@
             zwvw(ji,jj,jpk) = 0.e0
          END DO  
-
-         ! Vertical momentum advection at u- and v-points
-         ! ----------------------------------------------
-         DO jk = 1, jpkm1
+         !
+         DO jk = 1, jpkm1         ! Vertical momentum advection at u- and v-points
             DO ji = 2, jpim1
-               ! vertical momentum advective trends
+               !                        ! vertical momentum advective trends
                zua = - ( zwuw(ji,jj,jk) + zwuw(ji,jj,jk+1) ) / ( e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) )
                zva = - ( zwvw(ji,jj,jk) + zwvw(ji,jj,jk+1) ) / ( e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) )
-               ! add the trends to the general momentum trends
+               !                        ! add the trends to the general momentum trends
                ua(ji,jj,jk) = ua(ji,jj,jk) + zua
                va(ji,jj,jk) = va(ji,jj,jk) + zva
@@ -133,19 +115,14 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-
-      ! save the vertical advection trends for diagnostic
-      ! momentum trends
-      IF( l_trddyn )   THEN
-         ztdua(:,:,:) = ua(:,:,:) - ztdua(:,:,:)
-         ztdva(:,:,:) = va(:,:,:) - ztdva(:,:,:)
-
-         CALL trd_mod(ztdua, ztdva, jpdtdzad, 'DYN', kt)
-      ENDIF
-
-      IF(ln_ctl) THEN         ! print sum trends (used for debugging)
-         CALL prt_ctl(tab3d_1=ua, clinfo1=' zad  - Ua: ', mask1=umask, &
-            &         tab3d_2=va, clinfo2=' Va: ', mask2=vmask, clinfo3='dyn')
-      ENDIF
-
+      !
+      IF( l_trddyn ) THEN         ! save the vertical advection trends for diagnostic
+         ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+         ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_zad, 'DYN', kt )
+      ENDIF
+      !                           ! Control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' zad  - Ua: ', mask1=umask,   &
+         &                       tab3d_2=va, clinfo2=' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
    END SUBROUTINE dyn_zad
 
@@ -169,22 +146,15 @@
       !!
       !! ** Action  : - Update (ua,va) with the vert. momentum adv. trends
-      !!              - Save the trends in (utrd,vtrd) ('key_trddyn')
-      !!
-      !! History :
-      !!   8.5  !  02-07  (G. Madec)  Original code
-      !!----------------------------------------------------------------------
-      !! * modules used
-      USE oce, ONLY:   zwuw => ta,   & ! use ta as 3D workspace
-                       zwvw => sa      ! use sa as 3D workspace
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt    ! ocean time-step inedx
-      
-      !! * Local declarations
-      INTEGER  ::   ji, jj, jk         ! dummy loop indices
-      REAL(wp) ::   zua, zva           ! temporary scalars
-      REAL(wp), DIMENSION(jpi,jpj) ::   &
-         zww                           ! temporary  workspace
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         ztdua, ztdva                  ! temporary workspace
+      !!              - Save the trends in (ztrdu,ztrdv) ('key_trddyn')
+     !!----------------------------------------------------------------------
+      USE oce, ONLY:   zwuw => ta   ! use ta as 3D workspace
+      USE oce, ONLY:   zwvw => sa   ! use sa as 3D workspace
+      !!
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step inedx
+      !!
+      INTEGER  ::   ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   zua, zva        ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zww            ! 2D  workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdu, ztrdv   ! 3D workspace
       !!----------------------------------------------------------------------
       
@@ -195,22 +165,17 @@
       ENDIF
 
-      ! Save ua and va trends
-      IF( l_trddyn )   THEN
-         ztdua(:,:,:) = ua(:,:,:) 
-         ztdva(:,:,:) = va(:,:,:) 
+      IF( l_trddyn )   THEN         ! Save ua and va trends
+         ztrdu(:,:,:) = ua(:,:,:) 
+         ztrdv(:,:,:) = va(:,:,:) 
       ENDIF
       
-      ! Vertical momentum advection at level w and u- and v- vertical
-      ! -------------------------------------------------------------
-      DO jk = 2, jpkm1
-         ! vertical fluxes 
-         DO jj = 2, jpj
-            DO ji = fs_2, jpi   ! vector opt.
+      DO jk = 2, jpkm1              ! Vertical momentum advection at level w and u- and v- vertical
+         DO jj = 2, jpj                   ! vertical fluxes 
+            DO ji = fs_2, jpi             ! vector opt.
                zww(ji,jj) = 0.25 * e1t(ji,jj) * e2t(ji,jj) * wn(ji,jj,jk)
             END DO
          END DO
-         ! vertical momentum advection at w-point
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
+         DO jj = 2, jpjm1                 ! vertical momentum advection at w-point
+            DO ji = fs_2, fs_jpim1        ! vector opt.
                zwuw(ji,jj,jk) = ( zww(ji+1,jj  ) + zww(ji,jj) ) * ( un(ji,jj,jk-1)-un(ji,jj,jk) )
                zwvw(ji,jj,jk) = ( zww(ji  ,jj+1) + zww(ji,jj) ) * ( vn(ji,jj,jk-1)-vn(ji,jj,jk) )
@@ -218,8 +183,6 @@
          END DO   
       END DO
-
-      ! Surface and bottom values set to zero
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1   ! vector opt.
+      DO jj = 2, jpjm1              ! Surface and bottom values set to zero
+         DO ji = fs_2, fs_jpim1           ! vector opt.
             zwuw(ji,jj, 1 ) = 0.e0
             zwvw(ji,jj, 1 ) = 0.e0
@@ -229,14 +192,11 @@
       END DO
 
-
-      ! Vertical momentum advection at u- and v-points
-      ! ----------------------------------------------
-      DO jk = 1, jpkm1
+      DO jk = 1, jpkm1              ! Vertical momentum advection at u- and v-points
          DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ! vertical momentum advective trends
+            DO ji = fs_2, fs_jpim1       ! vector opt.
+               !                         ! vertical momentum advective trends
                zua = - ( zwuw(ji,jj,jk) + zwuw(ji,jj,jk+1) ) / ( e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) )
                zva = - ( zwvw(ji,jj,jk) + zwvw(ji,jj,jk+1) ) / ( e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) )
-               ! add the trends to the general momentum trends
+               !                         ! add the trends to the general momentum trends
                ua(ji,jj,jk) = ua(ji,jj,jk) + zua
                va(ji,jj,jk) = va(ji,jj,jk) + zva
@@ -245,21 +205,16 @@
       END DO
 
-      ! save the vertical advection trends for diagnostic
-      ! momentum trends
-      IF( l_trddyn )   THEN
-         ztdua(:,:,:) = ua(:,:,:) - ztdua(:,:,:)
-         ztdva(:,:,:) = va(:,:,:) - ztdva(:,:,:)
-
-         CALL trd_mod(ztdua, ztdva, jpdtdzad, 'DYN', kt)
-      ENDIF
-
-      IF(ln_ctl) THEN         ! print sum trends (used for debugging)
-         CALL prt_ctl(tab3d_1=ua, clinfo1=' zad  - Ua: ', mask1=umask, &
-            &         tab3d_2=va, clinfo2=' Va: ', mask2=vmask, clinfo3='dyn')
-      ENDIF
-
+      IF( l_trddyn ) THEN           ! save the vertical advection trends for diagnostic
+         ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+         ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+         CALL trd_mod(ztrdu, ztrdv, jpdyn_trd_zad, 'DYN', kt)
+      ENDIF
+      !                             ! Control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' zad  - Ua: ', mask1=umask,   &
+         &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
    END SUBROUTINE dyn_zad
 #endif
 
-!!======================================================================
+   !!======================================================================
 END MODULE dynzad
Index: trunk/NEMO/OPA_SRC/DYN/dynzdf.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DYN/dynzdf.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/DYN/dynzdf.F90	(revision 503)
@@ -4,9 +4,11 @@
    !! Ocean dynamics :  vertical component of the momentum mixing trend
    !!==============================================================================
+   !! History :  9.0  !  05-11  (G. Madec)  Original code
+   !!----------------------------------------------------------------------
+
    !!----------------------------------------------------------------------
    !!   dyn_zdf      : Update the momentum trend with the vertical diffusion
-   !!       zdf_ctl  : ???
+   !!       zdf_ctl  : initializations of the vertical diffusion scheme
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain variables 
@@ -26,15 +28,11 @@
    PRIVATE
 
-   !! * Routine accessibility
-   PUBLIC dyn_zdf   !  routine called by step.F90
+   PUBLIC   dyn_zdf    !  routine called by step.F90
 
-   !! * module variables
-   INTEGER ::                        &
-      nzdf = 0                         ! type vertical diffusion algorithm used
+   INTEGER  ::   nzdf = 0              ! type vertical diffusion algorithm used 
       !                                ! defined from ln_zdf...  namlist logicals)
 
-   !! * Module variables
-   REAL(wp) ::   &
-      r2dt                          ! time-step, = 2 rdttra except at nit000 (=rdttra) if neuler=0
+   REAL(wp) ::   r2dt                  ! time-step, = 2 rdttra
+      !                                ! except at nit000 (=rdttra) if neuler=0
 
    !! * Substitutions
@@ -44,4 +42,6 @@
    !!----------------------------------------------------------------------
    !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -53,16 +53,8 @@
       !!
       !! ** Purpose :   compute the vertical ocean dynamics physics.
-      !! ** Method  :
-      !! ** Action  :
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
       !!
-      !! History :
-      !!   9.0  !  05-11  (G. Madec)  Original code
-      !!---------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-
-      !! * local declarations
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         ztrdu, ztrdv                    ! 3D temporary workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdu, ztrdv   ! 3D workspace
       !!---------------------------------------------------------------------
 
@@ -70,10 +62,7 @@
 
       !                                          ! set time step
-      IF( neuler == 0 .AND. kt == nit000 ) THEN     ! at nit000
-         r2dt =  rdt                                    ! = rdtra (restarting with Euler time stepping)
-      ELSEIF( kt <= nit000 + 1) THEN                ! at nit000 or nit000+1
-         r2dt = 2. * rdt                                ! = 2 rdttra (leapfrog)
+      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdtra (restarting with Euler time stepping)
+      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdttra (leapfrog)
       ENDIF
-
 
       IF( l_trddyn )   THEN                      ! temporary save of ta and sa trends
@@ -83,36 +72,30 @@
 
       SELECT CASE ( nzdf )                       ! compute lateral mixing trend and add it to the general trend
-      CASE ( -1 )                                       ! esopa: test all possibility with control print
-         CALL dyn_zdf_exp    ( kt )
-         CALL prt_ctl( tab3d_1=ua, clinfo1=' zdf0 - Ua: ', mask1=umask,               &
-            &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-         CALL dyn_zdf_imp    ( kt )
-         CALL prt_ctl( tab3d_1=ua, clinfo1=' zdf1 - Ua: ', mask1=umask,               &
-            &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-         CALL dyn_zdf_imp_jki( kt )
-         CALL prt_ctl( tab3d_1=ua, clinfo1=' zdf2 - Ua: ', mask1=umask,               &
-            &          tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-
-      CASE ( 0 )                                       ! explicit scheme
-         CALL dyn_zdf_exp    ( kt )
-
-      CASE ( 1 )                                       ! implicit scheme (k-j-i loop)
-         CALL dyn_zdf_imp    ( kt )
-
-      CASE ( 2 )                                       ! implicit scheme (j-k-i loop)
-         CALL dyn_zdf_imp_jki( kt )
-
+      !
+      CASE ( 0 )   ;   CALL dyn_zdf_exp    ( kt, r2dt )      ! explicit scheme
+      CASE ( 1 )   ;   CALL dyn_zdf_imp    ( kt, r2dt )      ! implicit scheme (k-j-i loop)
+      CASE ( 2 )   ;   CALL dyn_zdf_imp_jki( kt, r2dt )      ! implicit scheme (j-k-i loop)
+      !
+      CASE ( -1 )                                      ! esopa: test all possibility with control print
+         ;             CALL dyn_zdf_exp    ( kt, r2dt )
+         ;             CALL prt_ctl( tab3d_1=ua, clinfo1=' zdf0 - Ua: ', mask1=umask,               &
+            &                        tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;             CALL dyn_zdf_imp    ( kt, r2dt )
+         ;             CALL prt_ctl( tab3d_1=ua, clinfo1=' zdf1 - Ua: ', mask1=umask,               &
+            &                        tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+         ;             CALL dyn_zdf_imp_jki( kt, r2dt )
+         ;             CALL prt_ctl( tab3d_1=ua, clinfo1=' zdf2 - Ua: ', mask1=umask,               &
+            &                        tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
       END SELECT
 
-      IF( l_trddyn )   THEN                         ! save the vertical diffusive trends for further diagnostics
+      IF( l_trddyn )   THEN                      ! save the vertical diffusive trends for further diagnostics
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_mod( ztrdu, ztrdv, jpttdzdf, 'DYN', kt )
+         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_zdf, 'DYN', kt )
       ENDIF
-
       !                                          ! print mean trends (used for debugging)
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' zdf  - Ua: ', mask1=umask,               &
             &                    tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-
+      !
    END SUBROUTINE dyn_zdf
 
@@ -122,46 +105,32 @@
       !!                 ***  ROUTINE zdf_ctl  ***
       !!
-      !! ** Purpose :   initializations of the vertical ocean dynamics physics
+      !! ** Purpose :   initializations of the vertical diffusion scheme
       !!
       !! ** Method  :   implicit (euler backward) scheme (default)
       !!                explicit (time-splitting) scheme if ln_zdfexp=T
       !!                OpenMP / NEC autotasking: use j-k-i loops
-      !!
-      !! History :
-      !!   9.0  !  05-11  (G. Madec)  Original code
       !!----------------------------------------------------------------------
-      !! * Module used
       USE zdftke
       USE zdfkpp
       !!----------------------------------------------------------------------
 
-      !  Define the vertical dynamics physics scheme
-      ! ==========================================
-
       ! Choice from ln_zdfexp read in namelist in zdfini
-      IF( ln_zdfexp ) THEN               ! use explicit scheme
-         nzdf = 0
-      ELSE                               ! use implicit scheme
-         nzdf = 1
+      IF( ln_zdfexp ) THEN   ;   nzdf = 0           ! use explicit scheme
+      ELSE                   ;   nzdf = 1           ! use implicit scheme
       ENDIF
 
       ! Force implicit schemes
-      IF( lk_zdftke .OR. lk_zdfkpp   )   nzdf = 1      ! TKE or KPP physics
-      IF( ln_dynldf_iso              )   nzdf = 1      ! iso-neutral lateral physics
-      IF( ln_dynldf_hor .AND. ln_sco )   nzdf = 1      ! horizontal lateral physics in s-coordinate
+      IF( lk_zdftke .OR. lk_zdfkpp   )   nzdf = 1   ! TKE or KPP physics
+      IF( ln_dynldf_iso              )   nzdf = 1   ! iso-neutral lateral physics
+      IF( ln_dynldf_hor .AND. ln_sco )   nzdf = 1   ! horizontal lateral physics in s-coordinate
 
       ! OpenMP / NEC autotasking
 #if defined key_mpp_omp
-      IF( nzdf == 1 )   nzdf = 2                       ! j-k-i loop
+      IF( nzdf == 1 )   nzdf = 2                    ! j-k-i loop
 #endif
 
-!!bug
-!     IF( ln_dynldf_iso              )   nzdf = 3      ! iso-neutral lateral physics
-!     IF( ln_dynldf_hor .AND. ln_sco )   nzdf = 3      ! horizontal lateral physics in s-coordinate
-!!bug
-      ! Test: esopa
-      IF( lk_esopa )    nzdf = -1                      ! All schemes used
+      IF( lk_esopa )    nzdf = -1                   ! Esopa key: All schemes used
 
-      IF(lwp) THEN
+      IF(lwp) THEN                                  ! Print the choice
          WRITE(numout,*)
          WRITE(numout,*) 'dyn:zdf_ctl : vertical dynamics physics scheme'
@@ -172,5 +141,5 @@
          IF( nzdf ==  2 )   WRITE(numout,*) '              Implicit (euler backward) scheme with j-k-i loops'
       ENDIF
-
+      !
    END SUBROUTINE zdf_ctl
 
Index: trunk/NEMO/OPA_SRC/DYN/dynzdf_exp.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DYN/dynzdf_exp.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/DYN/dynzdf_exp.F90	(revision 503)
@@ -4,4 +4,8 @@
    !! Ocean dynamics:  vertical component(s) of the momentum mixing trend
    !!==============================================================================
+   !! History :      !  90-10  (B. Blanke)  Original code
+   !!                !  97-05  (G. Madec)  vertical component of isopycnal
+   !!           8.5  !  02-08  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
@@ -16,5 +20,4 @@
    USE in_out_manager  ! I/O manager
    USE taumod          ! surface ocean stress
-   USE prtctl          ! Print control
 
    IMPLICIT NONE
@@ -30,10 +33,10 @@
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
 CONTAINS
 
-   SUBROUTINE dyn_zdf_exp( kt )
+   SUBROUTINE dyn_zdf_exp( kt, p2dt )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE dyn_zdf_exp  ***
@@ -50,25 +53,13 @@
       !!
       !! ** Action : - Update (ua,va) with the vertical diffusive trend
-      !!             - Save the trends in (ztdua,ztdva) ('key_trddyn')
-      !!
-      !! History :
-      !!        !  90-10  (B. Blanke)  Original code
-      !!        !  97-05  (G. Madec)  vertical component of isopycnal
-      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
-      !!   9.0  !  04-08  (C. Talandier)  New trends organization
       !!---------------------------------------------------------------------
-      !! * Modules used     
-      USE oce, ONLY :    ztdua => ta,    & ! use ta as 3D workspace   
-                         ztdva => sa       ! use sa as 3D workspace   
       !! * Arguments
-      INTEGER, INTENT( in ) ::   kt        ! ocean time-step index
+      INTEGER , INTENT( in ) ::   kt                           ! ocean time-step index
+      REAL(wp), INTENT( in ) ::   p2dt                         ! time-step 
 
       !! * Local declarations
-      INTEGER ::   &
-         ji, jj, jk, jl                    ! dummy loop indices
-      REAL(wp) ::   &
-         zrau0r, zlavmr, z2dt, zua, zva    ! temporary scalars
-      REAL(wp), DIMENSION(jpi,jpk) ::    &
-         zwx, zwy, zwz, zww                ! temporary workspace arrays
+      INTEGER ::   ji, jj, jk, jl                              ! dummy loop indices
+      REAL(wp) ::   zrau0r, zlavmr, zua, zva                   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpk) ::   zwx, zwy, zwz, zww     ! temporary workspace arrays
       !!----------------------------------------------------------------------
 
@@ -83,7 +74,4 @@
       zrau0r = 1. / rau0                                   ! inverse of the reference density
       zlavmr = 1. / float( n_zdfexp )                      ! inverse of the number of sub time step
-      z2dt = 2. * rdt                                      ! Leap-frog environnement
-
-      IF( neuler == 0 .AND. kt == nit000 )   z2dt = rdt    ! Euler time stepping when starting from rest
 
       !                                                ! ===============
@@ -124,6 +112,6 @@
                   va(ji,jj,jk) = va(ji,jj,jk) + zva
 
-                  zwx(ji,jk) = zwx(ji,jk) + z2dt*zua*umask(ji,jj,jk)
-                  zwz(ji,jk) = zwz(ji,jk) + z2dt*zva*vmask(ji,jj,jk)
+                  zwx(ji,jk) = zwx(ji,jk) + p2dt*zua*umask(ji,jj,jk)
+                  zwz(ji,jk) = zwz(ji,jk) + p2dt*zva*vmask(ji,jj,jk)
                END DO  
             END DO  
Index: trunk/NEMO/OPA_SRC/DYN/dynzdf_imp.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DYN/dynzdf_imp.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/DYN/dynzdf_imp.F90	(revision 503)
@@ -4,4 +4,8 @@
    !! Ocean dynamics:  vertical component(s) of the momentum mixing trend
    !!==============================================================================
+   !! History :      !  90-10  (B. Blanke)  Original code
+   !!                !  97-05  (G. Madec)  vertical component of isopycnal
+   !!           8.5  !  02-08  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
@@ -11,5 +15,5 @@
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
    !! * Modules used
@@ -20,5 +24,4 @@
    USE in_out_manager  ! I/O manager
    USE taumod          ! surface ocean stress
-   USE prtctl          ! Print control
 
    IMPLICIT NONE
@@ -40,5 +43,5 @@
 
 
-   SUBROUTINE dyn_zdf_imp( kt )
+   SUBROUTINE dyn_zdf_imp( kt, p2dt )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE dyn_zdf_imp  ***
@@ -58,25 +61,17 @@
       !! ** Action : - Update (ua,va) arrays with the after vertical diffusive
       !!               mixing trend.
-      !!
-      !! History :
-      !!        !  90-10  (B. Blanke)  Original code
-      !!        !  97-05  (G. Madec)  vertical component of isopycnal
-      !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
-      !!   9.0  !  04-08  (C. Talandier)  New trends organization
       !!---------------------------------------------------------------------
       !! * Modules used
-      USE oce, ONLY :  zwd   => ta,   &  ! use ta as workspace
-                       zws   => sa       ! use sa as workspace
+      USE oce, ONLY :  zwd   => ta,   &                ! use ta as workspace
+                       zws   => sa                     ! use sa as workspace
 
       !! * Arguments
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      INTEGER , INTENT( in ) ::   kt                   ! ocean time-step index
+      REAL(wp), INTENT( in ) ::  p2dt                  ! vertical profile of tracer time-step
 
       !! * Local declarations
-      INTEGER ::   ji, jj, jk            ! dummy loop indices
-      REAL(wp) ::   &
-         zrau0r, z2dt,                &  ! temporary scalars
-         z2dtf, zcoef, zzws, zrhs        !    "         "
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         zwi                             ! temporary workspace arrays
+      INTEGER ::   ji, jj, jk                          ! dummy loop indices
+      REAL(wp) ::   zrau0r, z2dtf, zcoef, zzws, zrhs   ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwi        ! temporary workspace arrays
       !!----------------------------------------------------------------------
 
@@ -90,8 +85,4 @@
       ! --------------------------------
       zrau0r = 1. / rau0      ! inverse of the reference density
-      z2dt   = 2. * rdt       ! Leap-frog environnement
-
-      ! Euler time stepping when starting from rest
-      IF( neuler == 0 .AND. kt == nit000 )   z2dt = rdt
 
       ! 1. Vertical diffusion on u
@@ -104,5 +95,5 @@
          DO jj = 2, jpjm1 
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zcoef = - z2dt / fse3u(ji,jj,jk)
+               zcoef = - p2dt / fse3u(ji,jj,jk)
                zwi(ji,jj,jk) = zcoef * avmu(ji,jj,jk  ) / fse3uw(ji,jj,jk  )
                zzws          = zcoef * avmu(ji,jj,jk+1) / fse3uw(ji,jj,jk+1)
@@ -150,14 +141,14 @@
 !!! change les resultats (derniers digit, pas significativement + rapide 1* de moins)
 !!!         ua(ji,jj,1) = ub(ji,jj,1)  &
-!!!                      + z2dt * ( ua(ji,jj,1) + taux(ji,jj) / ( fse3u(ji,jj,1)*rau0 ) )
-            z2dtf = z2dt / ( fse3u(ji,jj,1)*rau0 )
+!!!                      + p2dt * ( ua(ji,jj,1) + taux(ji,jj) / ( fse3u(ji,jj,1)*rau0 ) )
+            z2dtf = p2dt / ( fse3u(ji,jj,1)*rau0 )
             ua(ji,jj,1) = ub(ji,jj,1)  &
-                         + z2dt *  ua(ji,jj,1) + z2dtf * taux(ji,jj)
-         END DO
-      END DO
-      DO jk = 2, jpkm1
-         DO jj = 2, jpjm1   
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zrhs = ub(ji,jj,jk) + z2dt * ua(ji,jj,jk)   ! zrhs=right hand side
+                         + p2dt *  ua(ji,jj,1) + z2dtf * taux(ji,jj)
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zrhs = ub(ji,jj,jk) + p2dt * ua(ji,jj,jk)   ! zrhs=right hand side
                ua(ji,jj,jk) = zrhs - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * ua(ji,jj,jk-1)
             END DO
@@ -183,5 +174,5 @@
          DO jj = 2, jpjm1   
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               ua(ji,jj,jk) = ( ua(ji,jj,jk) - ub(ji,jj,jk) ) / z2dt
+               ua(ji,jj,jk) = ( ua(ji,jj,jk) - ub(ji,jj,jk) ) / p2dt
             END DO
          END DO
@@ -198,5 +189,5 @@
          DO jj = 2, jpjm1   
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zcoef = -z2dt / fse3v(ji,jj,jk)
+               zcoef = -p2dt / fse3v(ji,jj,jk)
                zwi(ji,jj,jk) = zcoef * avmv(ji,jj,jk  ) / fse3vw(ji,jj,jk  )
                zzws       = zcoef * avmv(ji,jj,jk+1) / fse3vw(ji,jj,jk+1)
@@ -245,8 +236,8 @@
 !!! change les resultats (derniers digit, pas significativement + rapide 1* de moins)
 !!!         va(ji,jj,1) = vb(ji,jj,1)  &
-!!!                      + z2dt * ( va(ji,jj,1) + tauy(ji,jj) / ( fse3v(ji,jj,1)*rau0 ) )
-            z2dtf = z2dt / ( fse3v(ji,jj,1)*rau0 )
+!!!                      + p2dt * ( va(ji,jj,1) + tauy(ji,jj) / ( fse3v(ji,jj,1)*rau0 ) )
+            z2dtf = p2dt / ( fse3v(ji,jj,1)*rau0 )
             va(ji,jj,1) = vb(ji,jj,1)  &
-                         + z2dt * va(ji,jj,1) + z2dtf * tauy(ji,jj)
+                         + p2dt * va(ji,jj,1) + z2dtf * tauy(ji,jj)
          END DO
       END DO
@@ -254,5 +245,5 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zrhs = vb(ji,jj,jk) + z2dt * va(ji,jj,jk)   ! zrhs=right hand side
+               zrhs = vb(ji,jj,jk) + p2dt * va(ji,jj,jk)   ! zrhs=right hand side
                va(ji,jj,jk) = zrhs - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * va(ji,jj,jk-1)
             END DO
@@ -274,31 +265,9 @@
       END DO
 
-! flux de surface doit etre calcule dans trdmod et boootom stress
-! deduit par integration verticale dans trmod pour jpdtdzdf
-!RB      IF( l_trddyn )  THEN 
-!         ! diagnose surface and bottom momentum fluxes
-!         DO jj = 2, jpjm1   
-!            DO ji = fs_2, fs_jpim1   ! vector opt.
-!               ! save the surface forcing momentum fluxes
-!               ztsy(ji,jj) = tauy(ji,jj) / ( fse3v(ji,jj,1)*rau0 )
-!               ztsx(ji,jj) = taux(ji,jj) / ( fse3u(ji,jj,1)*rau0 )
-!               ! save bottom friction momentum fluxes
-!               ikbv   = MIN( mbathy(ji,jj+1), mbathy(ji,jj) )
-!               ikbvm1 = MAX( ikbv-1, 1 )
-!               ztby(ji,jj) = - avmv(ji,jj,ikbv) * va(ji,jj,ikbvm1)   &
-!                  / ( fse3v(ji,jj,ikbvm1)*fse3vw(ji,jj,ikbv) )
-!               ! subtract surface forcing and bottom friction trend from vertical
-!               ! diffusive momentum trend
-!               ztdva(ji,jj,1     ) = ztdva(ji,jj,1     ) - ztsy(ji,jj)
-!               ztdva(ji,jj,ikbvm1) = ztdva(ji,jj,ikbvm1) - ztby(ji,jj)
-!            END DO
-!         END DO
-!      ENDIF
-
       ! Normalization to obtain the general momentum trend va
       DO jk = 1, jpkm1
          DO jj = 2, jpjm1   
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               va(ji,jj,jk) = ( va(ji,jj,jk) - vb(ji,jj,jk) ) / z2dt
+               va(ji,jj,jk) = ( va(ji,jj,jk) - vb(ji,jj,jk) ) / p2dt
             END DO
          END DO
Index: trunk/NEMO/OPA_SRC/DYN/dynzdf_imp_jki.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DYN/dynzdf_imp_jki.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/DYN/dynzdf_imp_jki.F90	(revision 503)
@@ -4,4 +4,6 @@
    !! Ocean dynamics:  vertical component(s) of the momentum mixing trend
    !!==============================================================================
+   !! History : 8.5  !  02-08  (G. Madec)  auto-tasking option
+   !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
@@ -17,5 +19,4 @@
    USE in_out_manager  ! I/O manager
    USE taumod          ! surface ocean stress
-   USE prtctl          ! Print control
 
    IMPLICIT NONE
@@ -30,9 +31,11 @@
    !!----------------------------------------------------------------------
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
 CONTAINS
 
-   SUBROUTINE dyn_zdf_imp_jki( kt )
+   SUBROUTINE dyn_zdf_imp_jki( kt, p2dt )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE dyn_zdf_imp_jki  ***
@@ -52,24 +55,15 @@
       !! ** Action : - Update (ua,va) arrays with the after vertical diffusive
       !!               mixing trend.
-      !!
-      !! History :
-      !!   8.5  !  02-08  (G. Madec)  auto-tasking option
-      !!   9.0  !  04-08  (C. Talandier)  New trends organization
       !!---------------------------------------------------------------------
-      !! * Modules used     
-      USE oce, ONLY :    ztdua => ta,  & ! use ta as 3D workspace   
-                         ztdva => sa     ! use sa as 3D workspace   
-
       !! * Arguments
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      INTEGER , INTENT( in ) ::   kt                          ! ocean time-step index
+      REAL(wp), INTENT( in ) ::   p2dt                        ! ocean time-step index
 
       !! * Local declarations
-      INTEGER ::   ji, jj, jk            ! dummy loop indices
-      INTEGER ::   ikst, ikenm2, ikstp1  ! temporary integers
-      REAL(wp) ::  zrau0r, z2dt,       & !temporary scalars
-         &         z2dtf, zcoef, zzws
-      REAL(wp), DIMENSION(jpi,jpk) ::  &
-         zwx, zwy, zwz,                & ! workspace
-         zwd, zws, zwi, zwt
+      INTEGER ::   ji, jj, jk                                 ! dummy loop indices
+      INTEGER ::   ikst, ikenm2, ikstp1                       ! temporary integers
+      REAL(wp) ::  zrau0r, z2dtf, zcoef, zzws                 ! temporary scalars
+      REAL(wp), DIMENSION(jpi,jpk) ::  zwx, zwy, zwz,       & ! workspace
+         &                             zwd, zws, zwi, zwt
       !!----------------------------------------------------------------------
 
@@ -84,8 +78,4 @@
       ! --------------------------------
       zrau0r = 1. / rau0      ! inverse of the reference density
-      z2dt   = 2. * rdt       ! Leap-frog environnement
-
-      ! Euler time stepping when starting from rest
-      IF( neuler == 0 .AND. kt == nit000 )   z2dt = rdt
 
       !                                                ! ===============
@@ -101,10 +91,10 @@
          DO jk = 1, jpkm1
             DO ji = 2, jpim1
-               zcoef = - z2dt / fse3u(ji,jj,jk)
+               zcoef = - p2dt / fse3u(ji,jj,jk)
                zwi(ji,jk) = zcoef * avmu(ji,jj,jk  ) / fse3uw(ji,jj,jk  )
                zzws       = zcoef * avmu(ji,jj,jk+1) / fse3uw(ji,jj,jk+1)
                zws(ji,jk) = zzws * umask(ji,jj,jk+1)
                zwd(ji,jk) = 1. - zwi(ji,jk) - zzws
-               zwy(ji,jk) = ub(ji,jj,jk) + z2dt * ua(ji,jj,jk)
+               zwy(ji,jk) = ub(ji,jj,jk) + p2dt * ua(ji,jj,jk)
             END DO
          END DO
@@ -112,5 +102,5 @@
          ! Surface boudary conditions
          DO ji = 2, jpim1
-            z2dtf = z2dt / ( fse3u(ji,jj,1)*rau0 )
+            z2dtf = p2dt / ( fse3u(ji,jj,1)*rau0 )
             zwi(ji,1) = 0.
             zwd(ji,1) = 1. - zws(ji,1)
@@ -175,5 +165,5 @@
          DO jk = 1, jpkm1
             DO ji = 2, jpim1
-               ua(ji,jj,jk) = ( zwx(ji,jk) - ub(ji,jj,jk) ) / z2dt
+               ua(ji,jj,jk) = ( zwx(ji,jk) - ub(ji,jj,jk) ) / p2dt
             END DO
          END DO
@@ -188,10 +178,10 @@
          DO jk = 1, jpkm1
             DO ji = 2, jpim1
-               zcoef = -z2dt/fse3v(ji,jj,jk)
+               zcoef = -p2dt/fse3v(ji,jj,jk)
                zwi(ji,jk) = zcoef * avmv(ji,jj,jk  ) / fse3vw(ji,jj,jk  )
                zzws       = zcoef * avmv(ji,jj,jk+1) / fse3vw(ji,jj,jk+1)
                zws(ji,jk) =  zzws * vmask(ji,jj,jk+1)
                zwd(ji,jk) = 1. - zwi(ji,jk) - zzws
-               zwy(ji,jk) = vb(ji,jj,jk) + z2dt * va(ji,jj,jk)
+               zwy(ji,jk) = vb(ji,jj,jk) + p2dt * va(ji,jj,jk)
             END DO
          END DO
@@ -199,5 +189,5 @@
          ! Surface boudary conditions
          DO ji = 2, jpim1
-            z2dtf = z2dt / ( fse3v(ji,jj,1)*rau0 )
+            z2dtf = p2dt / ( fse3v(ji,jj,1)*rau0 )
             zwi(ji,1) = 0.e0
             zwd(ji,1) = 1. - zws(ji,1)
@@ -262,5 +252,5 @@
          DO jk = 1, jpkm1
             DO ji = 2, jpim1
-               va(ji,jj,jk) = ( zwx(ji,jk) - vb(ji,jj,jk) ) / z2dt
+               va(ji,jj,jk) = ( zwx(ji,jk) - vb(ji,jj,jk) ) / p2dt
             END DO
          END DO
Index: trunk/NEMO/OPA_SRC/TRA/traadv.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/traadv.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/traadv.F90	(revision 503)
@@ -4,21 +4,22 @@
    !! Ocean active tracers:  advection trend 
    !!==============================================================================
-   !! History :
-   !!   9.0  !  05-11  (G. Madec)  Original code
+   !! History :  9.0  !  05-11  (G. Madec)  Original code
+   !!----------------------------------------------------------------------
+
    !!----------------------------------------------------------------------
    !!   tra_adv      : compute ocean tracer advection trend
    !!   tra_adv_ctl  : control the different options of advection scheme
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
-   USE traadv_cen2     ! 2nd order centered scheme   (tra_adv_cen2 routine)
-   USE traadv_cen2_jki ! 2nd order centered scheme   (tra_adv_cen2 routine)
-   USE traadv_tvd      ! TVD scheme                (tra_adv_tvd    routine)
-   USE traadv_muscl    ! MUSCL scheme              (tra_adv_muscl  routine)
+   USE traadv_cen2     ! 2nd order centered scheme (tra_adv_cen2   routine)
+   USE traadv_cen2_jki ! 2nd order centered scheme (tra_adv_cen2   routine)
+   USE traadv_tvd      ! TVD    scheme             (tra_adv_tvd    routine)
+   USE traadv_muscl    ! MUSCL  scheme             (tra_adv_muscl  routine)
    USE traadv_muscl2   ! MUSCL2 scheme             (tra_adv_muscl2 routine)
+   USE traadv_ubs      ! UBS    scheme             (tra_adv_ubs    routine)
    USE traadv_eiv      ! eddy induced velocity     (tra_adv_eiv    routine)
-   USE trabbl          ! ???
-   USE ldftra_oce      ! ???
+   USE trabbl          ! tracers: bottom boundary layer
+   USE ldftra_oce      ! lateral diffusion coefficient on tracers
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
@@ -27,23 +28,24 @@
    PRIVATE
 
-   !! * Accessibility
-   PUBLIC tra_adv         ! routine called by step module
+   PUBLIC   tra_adv    ! routine called by step module
  
-   !! * Share module variables
-   LOGICAL, PUBLIC ::   &
-      ln_traadv_cen2   = .TRUE.  ,   &  ! 2nd order centered scheme flag
-      ln_traadv_tvd    = .FALSE. ,   &  ! TVD scheme flag
-      ln_traadv_muscl  = .FALSE. ,   &  ! MUSCL scheme flag
-      ln_traadv_muscl2 = .FALSE.        ! MUSCL2 scheme flag
+   !!* Namelist nam_traadv
+   LOGICAL, PUBLIC ::   ln_traadv_cen2   = .TRUE.       ! 2nd order centered scheme flag
+   LOGICAL, PUBLIC ::   ln_traadv_tvd    = .FALSE.      ! TVD scheme flag
+   LOGICAL, PUBLIC ::   ln_traadv_muscl  = .FALSE.      ! MUSCL scheme flag
+   LOGICAL, PUBLIC ::   ln_traadv_muscl2 = .FALSE.      ! MUSCL2 scheme flag
+   LOGICAL, PUBLIC ::   ln_traadv_ubs    = .FALSE.      ! UBS scheme flag
+   NAMELIST/nam_traadv/ ln_traadv_cen2 , ln_traadv_tvd,   &
+      &                 ln_traadv_muscl, ln_traadv_muscl2, ln_traadv_ubs
 
-   !! * Module variables
-   INTEGER ::   &
-      nadv                              ! choice of the type of advection scheme
+   INTEGER ::   nadv   ! choice of the type of advection scheme
 
    !! * Substitutions
-#   include "domzgr_substitute.h90"
-#   include "vectopt_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -56,28 +58,25 @@
       !! ** Purpose :   compute the ocean tracer advection trend.
       !!
+      !! ** Method  : - Update (ua,va) with the advection term following nadv
       !!----------------------------------------------------------------------
 #if ( defined key_trabbl_adv || defined key_traldf_eiv )
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  &  ! temporary arrays
-         &         zun, zvn, zwn
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zun, zvn, zwn   ! effective velocity
 #else
-      USE oce                , zun => un,  &  ! When no advective bbl, zun == un
-         &                     zvn => vn,  &  !      "        "      , zvn == vn
-         &                     zwn => wn      !      "        "      , zwn == wn
+      USE oce, ONLY :                       zun => un       ! the effective velocity is the
+      USE oce, ONLY :                       zvn => vn       ! Eulerian velocity
+      USE oce, ONLY :                       zwn => wn       ! 
 #endif
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
       !!----------------------------------------------------------------------
 
-      IF( kt == nit000 )   CALL tra_adv_ctl                  ! initialisation & control of options
+      IF( kt == nit000 )   CALL tra_adv_ctl          ! initialisation & control of options
 
 #if defined key_trabbl_adv
-      ! Advective bottom boundary layer                      ! add the bbl velocity
-      ! -------------------------------
-      zun(:,:,:) = un(:,:,:) - u_bbl(:,:,:)
+      zun(:,:,:) = un(:,:,:) - u_bbl(:,:,:)          ! add the bbl velocity
       zvn(:,:,:) = vn(:,:,:) - v_bbl(:,:,:)
       zwn(:,:,:) = wn(:,:,:) + w_bbl(:,:,:)
 #endif
-      IF( lk_traldf_eiv ) THEN                               ! add the eiv velocity
+      IF( lk_traldf_eiv ) THEN                       ! commpute and add the eiv velocity
          IF( .NOT. lk_trabbl_adv ) THEN 
             zun(:,:,:) = un(:,:,:)
@@ -85,41 +84,39 @@
             zwn(:,:,:) = wn(:,:,:)
          ENDIF
-         CALL tra_adv_eiv( kt, zun, zvn, zwn )                  ! compute and add the eiv velocity 
+         CALL tra_adv_eiv( kt, zun, zvn, zwn ) 
       ENDIF
 
-      SELECT CASE ( nadv )                       ! compute advection trend and add it to general trend
-      CASE ( -1 )                                       ! esopa: test all possibility with control print
-         CALL tra_adv_cen2    ( kt, zun, zvn, zwn )
-         CALL prt_ctl( tab3d_1=ta, clinfo1=' ldf0 - Ta: ', mask1=tmask,               &
-            &          tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
-         CALL tra_adv_cen2_jki( kt, zun, zvn, zwn )
-         CALL prt_ctl( tab3d_1=ta, clinfo1=' ldf1 - Ta: ', mask1=tmask,               &
-            &          tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
-         CALL tra_adv_tvd     ( kt, zun, zvn, zwn )
-         CALL prt_ctl( tab3d_1=ta, clinfo1=' ldf2 - Ta: ', mask1=tmask,               &
-            &          tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
-         CALL tra_adv_muscl   ( kt, zun, zvn, zwn )
-         CALL prt_ctl( tab3d_1=ta, clinfo1=' ldf3 - Ta: ', mask1=tmask,               &
-            &          tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
-         CALL tra_adv_muscl2  ( kt, zun, zvn, zwn )
-         CALL prt_ctl( tab3d_1=ta, clinfo1=' ldf4 - Ta: ', mask1=tmask,               &
-            &          tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
-
-      CASE ( 0 )                                       ! 2nd order centered scheme k-j-i loops
-         CALL tra_adv_cen2    ( kt, zun, zvn, zwn )
-      CASE ( 1 )                                       ! 2nd order centered scheme
-         CALL tra_adv_cen2_jki( kt, zun, zvn, zwn )
-      CASE ( 2 )                                       ! TVD scheme
-         CALL tra_adv_tvd    ( kt, zun, zvn, zwn )
-      CASE ( 3 )                                       ! MUSCL  scheme
-         CALL tra_adv_muscl  ( kt, zun, zvn, zwn )
-      CASE ( 4 )                                       ! MUSCL2 scheme
-         CALL tra_adv_muscl2 ( kt, zun, zvn, zwn )
+      SELECT CASE ( nadv )                           ! compute advection trend and add it to general trend
+      CASE ( 0 )   ;   CALL tra_adv_cen2    ( kt, zun, zvn, zwn )    ! 2nd order centered scheme k-j-i loops
+      CASE ( 1 )   ;   CALL tra_adv_cen2_jki( kt, zun, zvn, zwn )    ! 2nd order centered scheme
+      CASE ( 2 )   ;   CALL tra_adv_tvd     ( kt, zun, zvn, zwn )    ! TVD    scheme
+      CASE ( 3 )   ;   CALL tra_adv_muscl   ( kt, zun, zvn, zwn )    ! MUSCL  scheme
+      CASE ( 4 )   ;   CALL tra_adv_muscl2  ( kt, zun, zvn, zwn )    ! MUSCL2 scheme
+      CASE ( 5 )   ;   CALL tra_adv_ubs     ( kt, zun, zvn, zwn )    ! UBS    scheme
+      !
+      CASE (-1 )                                                     ! esopa: test all possibility with control print
+         ;             CALL tra_adv_cen2    ( kt, zun, zvn, zwn )
+         ;             CALL prt_ctl( tab3d_1=ta, clinfo1=' ldf0 - Ta: ', mask1=tmask,               &
+            &                        tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+         ;             CALL tra_adv_cen2_jki( kt, zun, zvn, zwn )
+         ;             CALL prt_ctl( tab3d_1=ta, clinfo1=' ldf1 - Ta: ', mask1=tmask,               &
+            &                        tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+         ;             CALL tra_adv_tvd     ( kt, zun, zvn, zwn )
+         ;             CALL prt_ctl( tab3d_1=ta, clinfo1=' ldf2 - Ta: ', mask1=tmask,               &
+            &                        tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+         ;             CALL tra_adv_muscl   ( kt, zun, zvn, zwn )
+         ;             CALL prt_ctl( tab3d_1=ta, clinfo1=' ldf3 - Ta: ', mask1=tmask,               &
+            &                        tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+         ;             CALL tra_adv_muscl2  ( kt, zun, zvn, zwn )
+         ;             CALL prt_ctl( tab3d_1=ta, clinfo1=' ldf4 - Ta: ', mask1=tmask,               &
+            &                        tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+         ;             CALL tra_adv_ubs     ( kt, zun, zvn, zwn )
+         ;             CALL prt_ctl( tab3d_1=ta, clinfo1=' adv5 - Ta: ', mask1=tmask,               &
+            &                        tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
       END SELECT
-
-      !                                                ! print mean trends (used for debugging)
-!      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' adv  - Ta: ', mask1=tmask,               &
-!         &                       tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
-
+      !                                              ! print mean trends (used for debugging)
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' adv  - Ta: ', mask1=tmask,               &
+         &                       tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+      !
    END SUBROUTINE tra_adv
 
@@ -129,63 +126,60 @@
       !!                  ***  ROUTINE tra_adv_ctl  ***
       !!                
-      !! ** Purpose :   Control the consistency between cpp options for 
-      !!      tracer advection schemes
-      !!
+      !! ** Purpose :   Control the consistency between namelist options for 
+      !!              tracer advection schemes and set nadv
       !!----------------------------------------------------------------------
       INTEGER ::   ioptio
-      NAMELIST/nam_traadv/ ln_traadv_cen2 , ln_traadv_tvd,   &
-         &                 ln_traadv_muscl, ln_traadv_muscl2
       !!----------------------------------------------------------------------
 
-      ! Read Namelist nam_traadv : tracer advection scheme
-      ! -------------------------
-      REWIND ( numnam )
+      REWIND ( numnam )               ! Read Namelist nam_traadv : tracer advection scheme
       READ   ( numnam, nam_traadv )
 
-      ! Parameter control and print
-      ! ---------------------------
-      ! Control print
-      IF(lwp) THEN
+      IF(lwp) THEN                    ! Namelist print
          WRITE(numout,*)
          WRITE(numout,*) 'tra_adv_ctl : choice/control of the tracer advection scheme'
          WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*) '          Namelist nam_tra_adv : chose a advection scheme for tracers'
-         WRITE(numout,*)
-         WRITE(numout,*) '             2nd order advection scheme     ln_traadv_cen2   = ', ln_traadv_cen2
-         WRITE(numout,*) '             TVD advection scheme           ln_traadv_tvd    = ', ln_traadv_tvd
-         WRITE(numout,*) '             MUSCL  advection scheme        ln_traadv_muscl  = ', ln_traadv_muscl
-         WRITE(numout,*) '             MUSCL2 advection scheme        ln_traadv_muscl2 = ', ln_traadv_muscl2
+         WRITE(numout,*) '       Namelist nam_traadv : chose a advection scheme for tracers'
+         WRITE(numout,*) '          2nd order advection scheme     ln_traadv_cen2   = ', ln_traadv_cen2
+         WRITE(numout,*) '          TVD advection scheme           ln_traadv_tvd    = ', ln_traadv_tvd
+         WRITE(numout,*) '          MUSCL  advection scheme        ln_traadv_muscl  = ', ln_traadv_muscl
+         WRITE(numout,*) '          MUSCL2 advection scheme        ln_traadv_muscl2 = ', ln_traadv_muscl2
+         WRITE(numout,*) '          UBS    advection scheme        ln_traadv_ubs    = ', ln_traadv_ubs
       ENDIF
 
-      ! Control of Advection scheme options
-      ! -----------------------------------
-      ioptio = 0
+      ioptio = 0                      ! Parameter control
       IF( ln_traadv_cen2   )   ioptio = ioptio + 1
       IF( ln_traadv_tvd    )   ioptio = ioptio + 1
       IF( ln_traadv_muscl  )   ioptio = ioptio + 1
       IF( ln_traadv_muscl2 )   ioptio = ioptio + 1
+      IF( ln_traadv_ubs    )   ioptio = ioptio + 1
+      IF( lk_esopa         )   ioptio =          1
 
-      IF( .NOT.lk_esopa .AND. ( ioptio > 1 .OR. ioptio == 0 ) ) &
-           &   CALL ctl_stop( ' Choose ONE advection scheme in namelist nam_traadv' )
+      IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE advection scheme in namelist nam_traadv' )
 
-      IF( n_cla == 1 .AND. .NOT. ln_traadv_cen2 ) &
-           &   CALL ctl_stop( '     cross-land advection only with 2nd order advection scheme' )
+      IF( n_cla == 1 .AND. .NOT. ln_traadv_cen2 )   &
+         &                CALL ctl_stop( 'cross-land advection only with 2nd order advection scheme' )
 
-      ! Set nadv
-      ! --------
-      IF( ln_traadv_cen2   )   nadv = 0
+      !                              ! Set nadv
+      IF( ln_traadv_cen2   )   nadv =  0
 #if defined key_mpp_omp
-      IF( ln_traadv_cen2   )   nadv = 1
+      IF( ln_traadv_cen2   )   nadv =  1
 #endif
-      IF( ln_traadv_tvd    )   nadv = 2
-      IF( ln_traadv_muscl  )   nadv = 3
-      IF( ln_traadv_muscl2 )   nadv = 4
+      IF( ln_traadv_tvd    )   nadv =  2
+      IF( ln_traadv_muscl  )   nadv =  3
+      IF( ln_traadv_muscl2 )   nadv =  4
+      IF( ln_traadv_ubs    )   nadv =  5
+      IF( lk_esopa         )   nadv = -1
 
-      IF( lk_esopa ) THEN
-         IF(lwp) WRITE(numout,*) '          esopa control: use all lateral physics options'
-         nadv = -1
+      IF(lwp) THEN                   ! Print the choice
+         WRITE(numout,*)
+         IF( nadv ==  0 )   WRITE(numout,*) '         2nd order scheme is used'
+         IF( nadv ==  1 )   WRITE(numout,*) '         2nd order scheme is usedi, k-j-i case'
+         IF( nadv ==  2 )   WRITE(numout,*) '         TVD       scheme is used'
+         IF( nadv ==  3 )   WRITE(numout,*) '         MUSCL     scheme is used'
+         IF( nadv ==  4 )   WRITE(numout,*) '         MUSCL2    scheme is used'
+         IF( nadv ==  5 )   WRITE(numout,*) '         UBS       scheme is used'
+         IF( nadv == -1 )   WRITE(numout,*) '         esopa test: use all advection scheme'
       ENDIF
-      IF(lwp) WRITE(numout,*) '             choice of tra_adv_...                nadv   = ', nadv
-
+      !
    END SUBROUTINE tra_adv_ctl
 
Index: trunk/NEMO/OPA_SRC/TRA/traadv_cen2.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/traadv_cen2.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/traadv_cen2.F90	(revision 503)
@@ -4,10 +4,10 @@
    !! Ocean active tracers:  horizontal & vertical advective trend
    !!==============================================================================
-   !! History :
-   !!   8.2  !  01-08  (G. Madec, E. Durand)  trahad+trazad = traadv 
-   !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
-   !!   9.0  !  04-08  (C. Talandier) New trends organization
-   !!    "   !  05-11  (V. Garnier) Surface pressure gradient organization
-   !!    "   !  06-04  (R. Benshila, G. Madec) Step reorganization
+   !! History :  8.2  !  01-08  (G. Madec, E. Durand)  trahad+trazad = traadv 
+   !!            8.5  !  02-06  (G. Madec)  F90: Free form and module
+   !!            9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+   !!            " "  !  06-04  (R. Benshila, G. Madec) Step reorganization
+   !!----------------------------------------------------------------------
+
    !!----------------------------------------------------------------------
    !!   tra_adv_cen2 : update the tracer trend with the horizontal and
@@ -15,5 +15,4 @@
    !!                  centered scheme. (k-j-i loops)
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
@@ -33,6 +32,7 @@
    PRIVATE
 
-   !! * Accessibility
-   PUBLIC tra_adv_cen2    ! routine called by step.F90
+   PUBLIC   tra_adv_cen2   ! routine called by step.F90
+
+   REAL(wp), DIMENSION(jpi,jpj) ::   btr2   ! inverse of T-point surface [1/(e1t*e2t)]
 
    !! * Substitutions
@@ -42,5 +42,5 @@
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -86,6 +86,4 @@
       !!         zta+tn*divn=1/(e1t*e2t*e3t) { mi-1( e2u*e3u  un  di[tn] )
       !!                                      +mj-1( e1v*e3v  vn  mj[tn] )  }
-      !!         C A U T I O N : the trend saved is the centered trend only.
-      !!      It doesn't take into account the upstream part of the scheme.
       !!         NB:in z-coordinate - full step (ln_zco=T) e3u=e3v=e3t, so
       !!      they vanish from the expression of the flux and divergence.
@@ -110,22 +108,15 @@
       !!
       !! ** Action :  - update (ta,sa) with the now advective tracer trends
-      !!              - save trends in (ttrdh,ttrd,strdhi,strd) ('key_trdtra')
-      !!
+      !!              - save trends in (ztrdt,ztrds) ('key_trdtra')
       !!----------------------------------------------------------------------
-      !! * Modules used
-      USE oce                , zwx => ua,  &  ! use ua as workspace
-         &                     zwy => va      ! use va as workspace
-
-      !! * Arguments
-      INTEGER , INTENT( in ) ::   kt          ! ocean time-step index
-      REAL(wp), INTENT( in ), DIMENSION(jpi,jpj,jpk) ::   &
-         pun, pvn, pwn                        ! now ocean velocity fields
- 
-      !! * Local save
-      REAL(wp), DIMENSION(jpi,jpj), SAVE ::   &
-         zbtr2
- 
-      !! * Local declarations
-      INTEGER  ::   ji, jj, jk                 ! dummy loop indices
+      USE oce, ONLY :   zwx => ua   ! use ua as workspace
+      USE oce, ONLY :   zwy => va   ! use va as workspace
+      !!
+      INTEGER , INTENT(in)                         ::   kt    ! ocean time-step index
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pun   ! ocean velocity u-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pvn   ! ocean velocity v-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pwn   ! ocean velocity w-component
+      !!
+      INTEGER  ::   ji, jj, jk                           ! dummy loop indices
       REAL(wp) ::                           &
          zbtr, zta, zsa, zfui, zfvj,        &  ! temporary scalars
@@ -135,8 +126,8 @@
          zcofk, zupst, zupss, zcent,        &  !    "         "
          zcens, zfp_w, zfm_w,               &  !    "         "
-         zcenut, zcenvt, zcenus, zcenvs        !    "         "
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         zwz, zww, zind,                    &  ! temporary workspace arrays
-         ztdta, ztdsa                          !    "         "
+         zcenut, zcenvt, zcenus, zcenvs,    &  !    "         "
+         z_hdivn_x, z_hdivn_y, z_hdivn
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwz, ztrdt, zind   ! 3D workspace 
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zww, ztrds         !  "      "
       !!----------------------------------------------------------------------
 
@@ -146,18 +137,10 @@
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~   Vector optimization case'
          IF(lwp) WRITE(numout,*)
-   
-         zbtr2(:,:) = 1. / ( e1t(:,:) * e2t(:,:) )
-      ENDIF
-
-      ! Save ta and sa trends
-      IF( l_trdtra )   THEN
-         ztdta(:,:,:) = ta(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) 
-         l_adv = 'ce2'
+         ! 
+         btr2(:,:) = 1. / ( e1t(:,:) * e2t(:,:) )
       ENDIF
 
       ! Upstream / centered scheme indicator
       ! ------------------------------------
- 
       DO jk = 1, jpk
          DO jj = 1, jpj
@@ -176,10 +159,6 @@
 
 
-      ! I. Horizontal advective fluxes
-      ! ------------------------------
-
-      ! 1. Second order centered tracer flux at u and v-points
-      ! -------------------------------------------------------
-
+      !  Horizontal advective fluxes
+      ! -----------------------------
       !                                                ! ===============
       DO jk = 1, jpkm1                                 ! Horizontal slab
@@ -220,13 +199,12 @@
          END DO
 
-         ! 2. Tracer flux divergence at t-point added to the general trend
-         ! ---------------------------------------------------------------
-
+         !  Tracer flux divergence at t-point added to the general trend
+         ! --------------------------------------------------------------
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
 #if defined key_zco
-               zbtr = zbtr2(ji,jj)
-#else
-               zbtr = zbtr2(ji,jj) / fse3t(ji,jj,jk)
+               zbtr = btr2(ji,jj)
+#else
+               zbtr = btr2(ji,jj) / fse3t(ji,jj,jk)
 #endif
                ! horizontal advective trends
@@ -244,20 +222,56 @@
       !                                                ! ===============
 
-      ! 3. Save the horizontal advective trends for diagnostic
-      ! ------------------------------------------------------
-      IF( l_trdtra )   THEN
-         ! Recompute the hoizontal advection zta & zsa trends computed 
-         ! at the step 2. above in making the difference between the new 
-         ! trends and the previous one ta()/sa - ztdta()/ztdsa() and add
-         ! the term tn()/sn()*hdivn() to recover the Uh gradh(T/S) trends
-         ztdta(:,:,:) = ta(:,:,:) - ztdta(:,:,:) + tn(:,:,:) * hdivn(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) - ztdsa(:,:,:) + sn(:,:,:) * hdivn(:,:,:)
-
-         CALL trd_mod(ztdta, ztdsa, jpttdlad, 'TRA', kt)
-
-         ! Save the new ta and sa trends
-         ztdta(:,:,:) = ta(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) 
-
+      !  Save the horizontal advective trends for diagnostic
+      ! -----------------------------------------------------
+      IF( l_trdtra ) THEN
+         ! T/S ZONAL advection trends
+         ztrdt(:,:,:) = 0.e0   ;   ztrds(:,:,:) = 0.e0
+         !
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  !-- Compute zonal divergence by splitting hdivn (see divcur.F90)
+                  !   N.B. This computation is not valid along OBCs (if any)
+#if defined key_zco
+                  zbtr      = btr2(ji,jj) 
+                  z_hdivn_x = (  e2u(ji  ,jj) * pun(ji  ,jj,jk)                              &
+                     &         - e2u(ji-1,jj) * pun(ji-1,jj,jk) ) * zbtr
+#else
+                  zbtr      = btr2(ji,jj) / fse3t(ji,jj,jk)
+                  z_hdivn_x = (  e2u(ji  ,jj) * fse3u(ji  ,jj,jk) * pun(ji  ,jj,jk)          &
+                     &         - e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * pun(ji-1,jj,jk) ) * zbtr
+#endif
+                  ztrdt(ji,jj,jk) = - zbtr * ( zwx(ji,jj,jk) - zwx(ji-1,jj,jk) ) + tn(ji,jj,jk) * z_hdivn_x
+                  ztrds(ji,jj,jk) = - zbtr * ( zww(ji,jj,jk) - zww(ji-1,jj,jk) ) + sn(ji,jj,jk) * z_hdivn_x
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_xad, 'TRA', kt)
+         !
+         ! T/S MERIDIONAL advection trends
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  !-- Compute merid. divergence by splitting hdivn (see divcur.F90)
+                  !   N.B. This computation is not valid along OBCs (if any)
+#if defined key_zco
+                  zbtr      = btr2(ji,jj) 
+                  z_hdivn_y = (  e1v(ji,jj  ) * pvn(ji,jj  ,jk)                              &
+                     &         - e1v(ji,jj-1) * pvn(ji,jj-1,jk) ) * zbtr
+#else
+                  zbtr      = btr2(ji,jj) / fse3t(ji,jj,jk)
+                  z_hdivn_y = (  e1v(ji,  jj) * fse3v(ji,jj  ,jk) * pvn(ji,jj  ,jk)          &
+                     &         - e1v(ji,jj-1) * fse3v(ji,jj-1,jk) * pvn(ji,jj-1,jk) ) * zbtr
+#endif
+                  ztrdt(ji,jj,jk) = - zbtr * ( zwy(ji,jj,jk) - zwy(ji,jj-1,jk) ) + tn(ji,jj,jk) * z_hdivn_y          
+                  ztrds(ji,jj,jk) = - zbtr * ( zwz(ji,jj,jk) - zwz(ji,jj-1,jk) ) + sn(ji,jj,jk) * z_hdivn_y
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_yad, 'TRA', kt)
+         !
+         ! Save the horizontal up-to-date ta/sa trends
+         ztrdt(:,:,:) = ta(:,:,:) 
+         ztrds(:,:,:) = sa(:,:,:)
       ENDIF
 
@@ -265,5 +279,7 @@
          &                       tab3d_2=sa, clinfo2=            ' Sa: ', mask2=tmask, clinfo3='tra' )
 
-      ! "zonal" mean advective heat and salt transport
+      ! 4. "zonal" mean advective heat and salt transport 
+      ! -------------------------------------------------
+
       IF( ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
          IF( lk_zco ) THEN
@@ -299,7 +315,5 @@
       ! 1. Vertical advective fluxes
       ! ----------------------------
-
       ! Second order centered tracer flux at w-point
-
       DO jk = 2, jpk
          DO jj = 2, jpjm1
@@ -324,8 +338,6 @@
       END DO
 
-
       ! 2. Tracer flux divergence at t-point added to the general trend
       ! -------------------------
-  
       DO jk = 1, jpkm1
          DO jj = 2, jpjm1
@@ -347,16 +359,31 @@
          ! Recompute the vertical advection zta & zsa trends computed 
          ! at the step 2. above in making the difference between the new 
-         ! trends and the previous one: ta()/sa - ztdta()/ztdsa() and substract
+         ! trends and the previous one: ta()/sa - ztrdt()/ztrds() and substract
          ! the term tn()/sn()*hdivn() to recover the W gradz(T/S) trends
-         ztdta(:,:,:) = ta(:,:,:) - ztdta(:,:,:) - tn(:,:,:) * hdivn(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) - ztdsa(:,:,:) - sn(:,:,:) * hdivn(:,:,:)
-
-         CALL trd_mod(ztdta, ztdsa, jpttdzad, 'TRA', kt)
+
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+#if defined key_zco
+                  zbtr      = btr2(ji,jj) 
+                  z_hdivn_x = e2u(ji,jj)*pun(ji,jj,jk) - e2u(ji-1,jj)*pun(ji-1,jj,jk)
+                  z_hdivn_y = e1v(ji,jj)*pvn(ji,jj,jk) - e1v(ji,jj-1)*pvn(ji,jj-1,jk)
+#else
+                  zbtr      = btr2(ji,jj) / fse3t(ji,jj,jk)
+                  z_hdivn_x = e2u(ji,jj)*fse3u(ji,jj,jk)*pun(ji,jj,jk) - e2u(ji-1,jj)*fse3u(ji-1,jj,jk)*pun(ji-1,jj,jk)
+                  z_hdivn_y = e1v(ji,jj)*fse3v(ji,jj,jk)*pvn(ji,jj,jk) - e1v(ji,jj-1)*fse3v(ji,jj-1,jk)*pvn(ji,jj-1,jk)
+#endif
+                  z_hdivn   = (z_hdivn_x + z_hdivn_y) * zbtr
+                  ztrdt(ji,jj,jk) = ta(ji,jj,jk) - ztrdt(ji,jj,jk) - tn(ji,jj,jk) * z_hdivn 
+                  ztrds(ji,jj,jk) = sa(ji,jj,jk) - ztrds(ji,jj,jk) - sn(ji,jj,jk) * z_hdivn
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_zad, 'TRA', kt)
       ENDIF
 
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' cen2 zad  - Ta: ', mask1=tmask, &
          &                       tab3d_2=sa, clinfo2=            ' Sa: ', mask2=tmask, clinfo3='tra' )
-
-
+      !
    END SUBROUTINE tra_adv_cen2
 
Index: trunk/NEMO/OPA_SRC/TRA/traadv_cen2_jki.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/traadv_cen2_jki.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/traadv_cen2_jki.F90	(revision 503)
@@ -4,10 +4,10 @@
    !! Ocean active tracers:  horizontal & vertical advective trend
    !!==============================================================================
-   !! History :
-   !!   8.2  !  01-08  (G. Madec, E. Durand)  trahad+trazad = traadv
-   !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
-   !!   9.0  !  04-08  (C. Talandier) New trends organization
-   !!    "   !  05-11  (V. Garnier) Surface pressure gradient organization
-   !!    "   !  06-04  (R. Benshila, G. Madec) Step reorganization
+   !! History :  8.2  !  01-08  (G. Madec, E. Durand)  trahad+trazad = traadv
+   !!            8.5  !  02-06  (G. Madec)  F90: Free form and module
+   !!            9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+   !!            " "  !  06-04  (R. Benshila, G. Madec) Step reorganization
+   !!----------------------------------------------------------------------
+
    !!----------------------------------------------------------------------
    !!   tra_adv_cen2_jki : update the tracer trend with the horizontal and
@@ -16,5 +16,4 @@
    !!                  hor. adv., j-slab for vert. adv. (j-k-i loops)
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
@@ -34,6 +33,7 @@
    PRIVATE
 
-   !! * Accessibility
-   PUBLIC tra_adv_cen2_jki    ! routine called by step.F90
+   PUBLIC   tra_adv_cen2_jki   ! routine called by step.F90
+
+   REAL(wp), DIMENSION(jpi,jpj) ::   btr2   ! inverse of T-point surface [1/(e1t*e2t)]
 
    !! * Substitutions
@@ -42,11 +42,9 @@
    !!----------------------------------------------------------------------
    !!   OPA 9.0 , LOCEAN-IPSL (2005)
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
 CONTAINS
-
-   !!----------------------------------------------------------------------
-   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
-   !!----------------------------------------------------------------------
 
    SUBROUTINE tra_adv_cen2_jki( kt, pun, pvn, pwn )
@@ -89,6 +87,4 @@
       !!         zta+tn*divn=1/(e1t*e2t*e3t) { mi-1( e2u*e3u  un  di[tn] )
       !!                                      +mj-1( e1v*e3v  vn  mj[tn] )  }
-      !!         C A U T I O N : the trend saved is the centered trend only.
-      !!      It doesn't take into account the upstream part of the scheme.
       !!         NB:in z-coordinate - full step (ln_zco=T) e3u=e3v=e3t, so 
       !!      they vanish from the expression of the flux and divergence.
@@ -113,22 +109,15 @@
       !!
       !! ** Action :  - update (ta,sa) with the now advective tracer trends
-      !!              - save trends in (ttrdh,ttrd,strdhi,strd) ('key_trdtra')
-      !!
+      !!              - save trends in (ztrdt,ztrds) ('key_trdtra')
       !!----------------------------------------------------------------------
-      !! * Modules used
-      USE oce              , zwx => ua,    &  ! use ua as workspace
-         &                   zwy => va        ! use va as workspace
-
-      !! * Arguments
-      INTEGER , INTENT( in ) ::   kt          ! ocean time-step index
-      REAL(wp), INTENT( in ), DIMENSION(jpi,jpj,jpk) ::   &
-         pun, pvn, pwn                        ! now ocean velocity fields
-
-      !! * Local save
-      REAL(wp), DIMENSION(jpi,jpj), SAVE ::   &
-         zbtr2
-
-      !! * Local declarations
-      INTEGER  ::   ji, jj, jk                 ! dummy loop indices
+      USE oce, ONLY :   zwx => ua   ! use ua as workspace
+      USE oce, ONLY :   zwy => va   ! use va as workspace
+      !!
+      INTEGER , INTENT(in)                         ::   kt    ! ocean time-step index
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pun   ! ocean velocity u-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pvn   ! ocean velocity v-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pwn   ! ocean velocity w-component
+      !!
+      INTEGER  ::   ji, jj, jk                           ! dummy loop indices
       REAL(wp) ::                           &
          zbtr, zta, zsa, zfui, zfvj,        &  ! temporary scalars
@@ -138,8 +127,8 @@
          zcofk, zupst, zupss, zcent,        &  !    "         "
          zcens, zfp_w, zfm_w,               &  !    "         "
-         zcenut, zcenvt, zcenus, zcenvs        !    "         "
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         zwz, zww, zind,                    &  ! temporary workspace arrays
-         ztdta, ztdsa                          !    "         "
+         zcenut, zcenvt, zcenus, zcenvs,    &  !    "         "
+         z_hdivn_x, z_hdivn_y, z_hdivn
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwz, ztrdt, zind   ! 3D workspace 
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zww, ztrds         !  "      "
       !!----------------------------------------------------------------------
 
@@ -149,13 +138,6 @@
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~   Auto-tasking case'
          IF(lwp) WRITE(numout,*)
-         
-         zbtr2(:,:) = 1. / ( e1t(:,:) * e2t(:,:) )
-      ENDIF
-
-      ! Save ta and sa trends
-      IF( l_trdtra )   THEN
-         ztdta(:,:,:) = ta(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) 
-         l_adv = 'ce2'
+         !
+         btr2(:,:) = 1. / ( e1t(:,:) * e2t(:,:) )
       ENDIF
 
@@ -165,7 +147,6 @@
       DO jk = 1, jpkm1                                 ! Horizontal slab
          !                                             ! ===============
-
-         ! 0. Upstream / centered scheme indicator
-         ! ---------------------------------------
+         !  Upstream / centered scheme indicator
+         ! --------------------------------------
          DO jj = 1, jpj
             DO ji = 1, jpi
@@ -181,7 +162,6 @@
          END DO
 
-
-         ! I. Horizontal advective fluxes
-         ! ------------------------------
+         !  Horizontal advective fluxes
+         ! -----------------------------
          ! Second order centered tracer flux at u and v-points
          DO jj = 1, jpjm1
@@ -220,13 +200,11 @@
          END DO
 
-         ! 2. Tracer flux divergence at t-point added to the general trend
-         ! ---------------------------------------------------------------
-
+         ! Tracer flux divergence at t-point added to the general trend
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
 #if defined key_zco
-               zbtr = zbtr2(ji,jj) 
-#else
-               zbtr = zbtr2(ji,jj) / fse3t(ji,jj,jk)
+               zbtr = btr2(ji,jj) 
+#else
+               zbtr = btr2(ji,jj) / fse3t(ji,jj,jk)
 #endif
                ! horizontal advective trends
@@ -244,20 +222,59 @@
       !                                                ! ===============
 
-      ! 3. Save the horizontal advective trends for diagnostic
-      ! ------------------------------------------------------
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' cen2 had  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=            ' Sa: ', mask2=tmask, clinfo3='tra' )
+
+      ! Save the horizontal advective trends for diagnostics
       IF( l_trdtra )   THEN
-         ! Recompute the hoizontal advection zta & zsa trends computed 
-         ! at the step 2. above in making the difference between the new 
-         ! trends and the previous one ta()/sa - ztdta()/ztdsa() and add
-         ! the term tn()/sn()*hdivn() to recover the Uh gradh(T/S) trends
-         ztdta(:,:,:) = ta(:,:,:) - ztdta(:,:,:) + tn(:,:,:) * hdivn(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) - ztdsa(:,:,:) + sn(:,:,:) * hdivn(:,:,:)
-
-         CALL trd_mod(ztdta, ztdsa, jpttdlad, 'TRA', kt)
-
-         ! Save the new ta and sa trends
-         ztdta(:,:,:) = ta(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) 
-
+         ztrdt(:,:,:) = 0.e0   ;   ztrds(:,:,:) = 0.e0
+         !
+         ! T/S ZONAL advection trends
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  !-- Compute zonal divergence by splitting hdivn (see divcur.F90)
+                  !   N.B. This computation is not valid along OBCs (if any)
+#if defined key_zco
+                  zbtr      = btr2(ji,jj) 
+                  z_hdivn_x = (  e2u(ji  ,jj) * pun(ji  ,jj,jk)                              &
+                     &         - e2u(ji-1,jj) * pun(ji-1,jj,jk) ) * zbtr
+#else
+                  zbtr      = btr2(ji,jj) / fse3t(ji,jj,jk)
+                  z_hdivn_x = (  e2u(ji  ,jj) * fse3u(ji  ,jj,jk) * pun(ji  ,jj,jk)          &
+                     &         - e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * pun(ji-1,jj,jk) ) * zbtr
+#endif
+                  ztrdt(ji,jj,jk) = - zbtr * ( zwx(ji,jj,jk) - zwx(ji-1,jj,jk) ) + tn(ji,jj,jk) * z_hdivn_x
+                  ztrds(ji,jj,jk) = - zbtr * ( zww(ji,jj,jk) - zww(ji-1,jj,jk) ) + sn(ji,jj,jk) * z_hdivn_x
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_xad, 'TRA', kt)
+         !
+         ! T/S MERIDIONAL advection trends
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  !-- Compute merid. divergence by splitting hdivn (see divcur.F90)
+                  !   N.B. This computation is not valid along OBCs (if any)
+#if defined key_zco
+                  zbtr      = btr2(ji,jj) 
+                  z_hdivn_y = (  e1v(ji,jj  ) * pvn(ji,jj  ,jk)                              &
+                     &         - e1v(ji,jj-1) * pvn(ji,jj-1,jk) ) * zbtr
+#else
+                  zbtr      = btr2(ji,jj) / fse3t(ji,jj,jk)
+                  z_hdivn_y = (  e1v(ji,  jj) * fse3v(ji,jj  ,jk) * pvn(ji,jj  ,jk)          &
+                     &         - e1v(ji,jj-1) * fse3v(ji,jj-1,jk) * pvn(ji,jj-1,jk) ) * zbtr
+#endif
+                  ztrdt(ji,jj,jk) = - zbtr * ( zwy(ji,jj,jk) - zwy(ji,jj-1,jk) ) + tn(ji,jj,jk) * z_hdivn_y          
+                  ztrds(ji,jj,jk) = - zbtr * ( zwz(ji,jj,jk) - zwz(ji,jj-1,jk) ) + sn(ji,jj,jk) * z_hdivn_y
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_yad, 'TRA', kt)
+         !
+         ! Save the up-to-date ta and sa trends
+         ztrdt(:,:,:) = ta(:,:,:) 
+         ztrds(:,:,:) = sa(:,:,:)
+         !
       ENDIF
 
@@ -281,6 +298,6 @@
       ENDIF
 
-      ! II. Vertical advection
-      ! ----------------------
+      !  Vertical advection
+      ! --------------------
 !CDIR PARALLEL DO
 !$OMP PARALLEL DO
@@ -300,7 +317,5 @@
          ENDIF
          
-         ! 1. Vertical advective fluxes
-         ! ----------------------------
-         ! Second order centered tracer flux at w-point
+         ! Vertical advective fluxes at w-point
          DO jk = 2, jpk
             DO ji = 2, jpim1
@@ -323,6 +338,5 @@
          END DO
 
-         ! 2. Tracer flux divergence at t-point added to the general trend
-         ! -------------------------
+         ! Tracer flux divergence at t-point added to the general trend
          DO jk = 1, jpkm1
             DO ji = 2, jpim1
@@ -340,20 +354,36 @@
       !                                                ! ===============
 
-      ! 3. Save the vertical advective trends for diagnostic
-      ! ----------------------------------------------------
+      ! Save the vertical advective trends for diagnostic
       IF( l_trdtra )   THEN
          ! Recompute the vertical advection zta & zsa trends computed 
          ! at the step 2. above in making the difference between the new 
-         ! trends and the previous one: ta()/sa - ztdta()/ztdsa() and substract
+         ! trends and the previous one: ta()/sa - ztrdt()/ztrds() and substract
          ! the term tn()/sn()*hdivn() to recover the W gradz(T/S) trends
-         ztdta(:,:,:) = ta(:,:,:) - ztdta(:,:,:) - tn(:,:,:) * hdivn(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) - ztdsa(:,:,:) - sn(:,:,:) * hdivn(:,:,:)
-
-         CALL trd_mod(ztdta, ztdsa, jpttdzad, 'TRA', kt)
+         !
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+#if defined key_zco
+                  zbtr      = btr2(ji,jj) 
+                  z_hdivn_x = e2u(ji,jj)*pun(ji,jj,jk) - e2u(ji-1,jj)*pun(ji-1,jj,jk)
+                  z_hdivn_y = e1v(ji,jj)*pvn(ji,jj,jk) - e1v(ji,jj-1)*pvn(ji,jj-1,jk)
+#else
+                  zbtr      = btr2(ji,jj) / fse3t(ji,jj,jk)
+                  z_hdivn_x = e2u(ji,jj)*fse3u(ji,jj,jk)*pun(ji,jj,jk) - e2u(ji-1,jj)*fse3u(ji-1,jj,jk)*pun(ji-1,jj,jk)
+                  z_hdivn_y = e1v(ji,jj)*fse3v(ji,jj,jk)*pvn(ji,jj,jk) - e1v(ji,jj-1)*fse3v(ji,jj-1,jk)*pvn(ji,jj-1,jk)
+#endif
+                  z_hdivn   = (z_hdivn_x + z_hdivn_y) * zbtr
+                  ztrdt(ji,jj,jk) = ta(ji,jj,jk) - ztrdt(ji,jj,jk) - tn(ji,jj,jk) * z_hdivn 
+                  ztrds(ji,jj,jk) = sa(ji,jj,jk) - ztrds(ji,jj,jk) - sn(ji,jj,jk) * z_hdivn
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_zad, 'TRA', kt)
+         !
       ENDIF
 
-      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' cen2 zad  - Ta: ', mask1=tmask, &
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' cen2 zad  - Ta: ', mask1=tmask,   &
          &                       tab3d_2=sa, clinfo2=            ' Sa: ', mask2=tmask, clinfo3='tra' )
-
+      !
    END SUBROUTINE tra_adv_cen2_jki
 
Index: trunk/NEMO/OPA_SRC/TRA/traadv_eiv.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/traadv_eiv.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/traadv_eiv.F90	(revision 503)
@@ -1,9 +1,8 @@
 MODULE traadv_eiv
-   !!==============================================================================
+   !!======================================================================
    !!                    ***  MODULE  traadv_eiv  ***
    !! Ocean active tracers:  advection trend - eddy induced velocity
-   !!==============================================================================
-   !! History :
-   !!   9.0  !  05-11  (G. Madec)  Original code from traldf & zdf _iso
+   !!======================================================================
+   !! History :  9.0  !  05-11  (G. Madec)  Original code, from traldf and zdf _iso
    !!----------------------------------------------------------------------
 #if defined key_traldf_eiv   ||   defined key_esopa
@@ -11,9 +10,9 @@
    !!   'key_traldf_eiv'                  rotation of the lateral mixing tensor
    !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !!   tra_ldf_iso : update the tracer trend with the horizontal component
    !!                 of iso neutral laplacian operator or horizontal 
    !!                 laplacian operator in s-coordinate
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain variables
@@ -25,7 +24,5 @@
    PRIVATE
 
-   !! * Routine accessibility
-   PUBLIC tra_adv_eiv  ! routine called by step.F90
-
+   PUBLIC   tra_adv_eiv   ! routine called by step.F90
 
    !! * Substitutions
@@ -35,5 +32,7 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!  OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -57,18 +56,14 @@
       !!
       !! ** Action  : - add to p.n the eiv component
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   kt    ! ocean time-step index
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pun   ! in : 3 ocean velocity components 
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pvn   ! out: 3 ocean velocity components
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pwn   !      increased by the eiv
       !!
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER , INTENT( in ) ::   kt       ! ocean time-step index
-      REAL(wp), INTENT( inout ), DIMENSION(jpi,jpj,jpk) ::   &
-         pun, pvn, pwn                     ! in : now ocean velocity fields 
-         !                                 ! out: fields increased by the eiv components
-
-      !! * Local declarations
-      INTEGER  ::   ji, jj, jk             ! dummy loop indices
-      REAL(wp) ::                       &
-         zuwk, zuwk1, zuwi, zuwi1,      &  ! temporary scalar
-         zvwk, zvwk1, zvwj, zvwj1,      &  !
-         zu_eiv, zv_eiv, zw_eiv            !
+      INTEGER  ::   ji, jj, jk                 ! dummy loop indices
+      REAL(wp) ::   zuwk, zuwk1, zuwi, zuwi1   ! temporary scalar
+      REAL(wp) ::   zvwk, zvwk1, zvwj, zvwj1   !    "         "
+      REAL(wp) ::   zu_eiv, zv_eiv, zw_eiv     !    "         "
       !!----------------------------------------------------------------------
 
@@ -83,9 +78,7 @@
 # endif
       ENDIF
-
       !                                             ! =================
       DO jk = 1, jpkm1                              !  Horizontal slab
          !                                          ! =================
-
          DO jj = 1, jpjm1
             DO ji = 1, fs_jpim1   ! vector opt.
@@ -95,10 +88,9 @@
                zvwk1= ( wslpj(ji,jj,jk+1) + wslpj(ji,jj+1,jk+1) ) * fsaeiv(ji,jj,jk+1) * vmask(ji,jj,jk+1)
 
-               zu_eiv =  0.5 * umask(ji,jj,jk) * ( zuwk - zuwk1 ) / fse3u(ji,jj,jk)
-               zv_eiv =  0.5 * vmask(ji,jj,jk) * ( zvwk - zvwk1 ) / fse3v(ji,jj,jk)
+               zu_eiv = 0.5 * umask(ji,jj,jk) * ( zuwk - zuwk1 ) / fse3u(ji,jj,jk)
+               zv_eiv = 0.5 * vmask(ji,jj,jk) * ( zvwk - zvwk1 ) / fse3v(ji,jj,jk)
    
                pun(ji,jj,jk) = pun(ji,jj,jk) + zu_eiv
                pvn(ji,jj,jk) = pvn(ji,jj,jk) + zv_eiv
-
 # if defined key_diaeiv
                u_eiv(ji,jj,jk) = zu_eiv
@@ -118,10 +110,10 @@
                   zw_eiv = - 0.5 * tmask(ji,jj,jk) * ( zuwi1 - zuwi + zvwj1 - zvwj ) / ( e1t(ji,jj)*e2t(ji,jj) )
 # else
-                  zuwki = ( wslpi(ji,jj,jk) + wslpi(ji-1,jj,jk) ) * e2u(ji-1,jj) * umask(ji-1,jj,jk)
-                  zuwk  = ( wslpi(ji,jj,jk) + wslpi(ji+1,jj,jk) ) * e2u(ji  ,jj) * umask(ji  ,jj,jk)
-                  zvwki = ( wslpj(ji,jj,jk) + wslpj(ji,jj-1,jk) ) * e1v(ji,jj-1) * vmask(ji,jj-1,jk)
-                  zvwk  = ( wslpj(ji,jj,jk) + wslpj(ji,jj+1,jk) ) * e1v(ji  ,jj) * vmask(ji  ,jj,jk)
+                  zuwi  = ( wslpi(ji,jj,jk) + wslpi(ji-1,jj,jk) ) * e2u(ji-1,jj) * umask(ji-1,jj,jk)
+                  zuwi1 = ( wslpi(ji,jj,jk) + wslpi(ji+1,jj,jk) ) * e2u(ji  ,jj) * umask(ji  ,jj,jk)
+                  zvwj  = ( wslpj(ji,jj,jk) + wslpj(ji,jj-1,jk) ) * e1v(ji,jj-1) * vmask(ji,jj-1,jk)
+                  zvwj1 = ( wslpj(ji,jj,jk) + wslpj(ji,jj+1,jk) ) * e1v(ji  ,jj) * vmask(ji  ,jj,jk)
 
-                  zw_eiv = - 0.5 * tmask(ji,jj,jk) * fsaeiw(ji,jj,jk) * ( zuwk - zuwki + zvwk - zvwki )
+                  zw_eiv = - 0.5 * tmask(ji,jj,jk) * fsaeiw(ji,jj,jk) * ( zuwi1 - zuwi + zvwj1 - zvwj )  &
                      &                                                / ( e1t(ji,jj)*e2t(ji,jj) )
 # endif
@@ -137,5 +129,4 @@
       END DO                                        !    End of slab  
       !                                             ! =================
-
    END SUBROUTINE tra_adv_eiv
 
@@ -146,8 +137,6 @@
 CONTAINS
    SUBROUTINE tra_adv_eiv( kt, pun, pvn, pwn )              ! Empty routine
-      INTEGER ::   kt 
       REAL, DIMENSION(:,:,:) ::   pun, pvn, pwn
-      WRITE(*,*) 'tra_adv_eiv: You should not have seen this print! error?',   &
-         &       kt, pun(1,1,1), pvn(1,1,1), pwn(1,1,1)
+      WRITE(*,*) 'tra_adv_eiv: You should not have seen this print! error?', kt, pun(1,1,1), pvn(1,1,1), pwn(1,1,1)
    END SUBROUTINE tra_adv_eiv
 #endif
Index: trunk/NEMO/OPA_SRC/TRA/traadv_muscl.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/traadv_muscl.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/traadv_muscl.F90	(revision 503)
@@ -1,7 +1,11 @@
 MODULE traadv_muscl
-   !!==============================================================================
+   !!======================================================================
    !!                       ***  MODULE  traadv_muscl  ***
    !! Ocean active tracers:  horizontal & vertical advective trend
-   !!==============================================================================
+   !!======================================================================
+   !! History :       !  06-00  (A.Estublier)  for passive tracers
+   !!                 !  01-08  (E.Durand, G.Madec)  adapted for T & S
+   !!            8.5  !  02-06  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
@@ -9,5 +13,4 @@
    !!                   and vertical advection trends using MUSCL scheme
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
@@ -25,6 +28,5 @@
    PRIVATE
 
-   !! * Accessibility
-   PUBLIC tra_adv_muscl  ! routine called by step.F90
+   PUBLIC   tra_adv_muscl  ! routine called by step.F90
 
    !! * Substitutions
@@ -32,7 +34,7 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -50,23 +52,18 @@
       !!
       !! ** Action  : - update (ta,sa) with the now advective tracer trends
-      !!              - save trends in (ztdta,ztdsa) ('key_trdtra')
-      !!
-      !! References :                
-      !!      Estubier, A., and M. Levy, Notes Techn. Pole de Modelisation
-      !!	IPSL, Sept. 2000 (http://www.lodyc.jussieu.fr/opa)
-      !!
-      !! History :
-      !!        !  06-00  (A.Estublier)  for passive tracers
-      !!        !  01-08  (E.Durand G.Madec)  adapted for T & S
-      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
-      !!   9.0  !  04-08  (C. Talandier) New trends organization
+      !!              - save trends in (ztrdt,ztrds) ('key_trdtra')
+      !!
+      !! References : Estubier, A., and M. Levy, Notes Techn. Pole de Modelisation
+      !!              IPSL, Sept. 2000 (http://www.lodyc.jussieu.fr/opa)
       !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER , INTENT( in ) ::   kt          ! ocean time-step index
-      REAL(wp), INTENT( in ), DIMENSION(jpi,jpj,jpk) ::   &
-         pun, pvn, pwn                        ! now ocean velocity fields
-
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk               ! dummy loop indices
+      USE oce, ONLY :   ztrdt => ua   ! use ua as workspace
+      USE oce, ONLY :   ztrds => va   ! use va as workspace
+      !!
+      INTEGER , INTENT(in)                         ::   kt    ! ocean time-step index
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pun   ! ocean velocity u-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pvn   ! ocean velocity v-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pwn   ! ocean velocity w-component
+      !!
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
       REAL(wp) ::   &
          zu, zv, zw, zeu, zev,           &  
@@ -75,9 +72,8 @@
          zzt1, zzt2, zalpha,             &
          zzs1, zzs2, z2,                 &
-         zta, zsa                          
-      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   &
-         zt1, zt2, ztp1, ztp2,               &
-         zs1, zs2, zsp1, zsp2,               &
-         ztdta, ztdsa
+         zta, zsa,                       &
+        z_hdivn_x, z_hdivn_y, z_hdivn
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zt1, zt2, ztp1, ztp2   ! 3D workspace
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zs1, zs2, zsp1, zsp2   !  "      "
       !!----------------------------------------------------------------------
 
@@ -88,21 +84,10 @@
       ENDIF
 
-      IF( neuler == 0 .AND. kt == nit000 ) THEN
-          z2=1.
-      ELSE
-          z2=2.
-      ENDIF
-
-      ! Save ta and sa trends
-      IF( l_trdtra )   THEN
-         ztdta(:,:,:) = ta(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) 
-         l_adv = 'mus'
-      ENDIF
-
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;    z2 = 1.
+      ELSE                                        ;    z2 = 2.
+      ENDIF
 
       ! I. Horizontal advective fluxes
       ! ------------------------------
-
       ! first guess of the slopes
       ! interior values
@@ -193,5 +178,5 @@
                zt1(ji,jj,jk) = zeu * ( zalpha * zzt1 + (1.-zalpha) * zzt2 )
                zs1(ji,jj,jk) = zeu * ( zalpha * zzs1 + (1.-zalpha) * zzs2 )
-
+               !
                z0v = SIGN( 0.5, pvn(ji,jj,jk) )            
                zalpha = 0.5 - z0v
@@ -211,17 +196,5 @@
       CALL lbc_lnk( zt2, 'V', -1. )   ;   CALL lbc_lnk( zs2, 'V', -1. )
 
-      ! Save MUSCL fluxes to compute i- & j- horizontal 
-      ! advection trends in the MLD
-      IF( l_trdtra )   THEN
-         ! save i- terms
-         tladi(:,:,:) = zt1(:,:,:) 
-         sladi(:,:,:) = zs1(:,:,:) 
-         ! save j- terms
-         tladj(:,:,:) = zt2(:,:,:) 
-         sladj(:,:,:) = zs2(:,:,:) 
-      ENDIF
-
-      ! Compute & add the horizontal advective trend
-
+      ! Tracer flux divergence at t-point added to the general trend
       DO jk = 1, jpkm1
          DO jj = 2, jpjm1      
@@ -244,25 +217,59 @@
       END DO        
 
-      ! Save the horizontal advective trends for diagnostic
-
-      IF( l_trdtra )   THEN
-         ! Recompute the horizontal advection zta & zsa trends computed 
-         ! at the step 2. above in making the difference between the new 
-         ! trends and the previous one ta()/sa - ztdta()/ztdsa() and add
-         ! the term tn()/sn()*hdivn() to recover the Uh gradh(T/S) trends
-         ztdta(:,:,:) = ta(:,:,:) - ztdta(:,:,:) + tn(:,:,:) * hdivn(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) - ztdsa(:,:,:) + sn(:,:,:) * hdivn(:,:,:)
-
-         CALL trd_mod(ztdta, ztdsa, jpttdlad, 'TRA', kt)
-
-         ! Save the new ta and sa trends
-         ztdta(:,:,:) = ta(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) 
-
-      ENDIF
-
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab3d_1=ta, clinfo1=' muscl had  - Ta: ', mask1=tmask ,  &
-            &         tab3d_2=sa, clinfo2=' Sa: ', mask2=tmask, clinfo3='tra' )
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' muscl had  - Ta: ', mask1=tmask ,  &
+         &                       tab3d_2=sa, clinfo2=             ' Sa: ', mask2=tmask, clinfo3='tra' )
+
+      ! Save the horizontal advective trends for diagnostics
+      IF( l_trdtra ) THEN
+         ztrdt(:,:,:) = 0.e0   ;   ztrds(:,:,:) = 0.e0
+         !
+         ! T/S ZONAL advection trends
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  !-- Compute zonal divergence by splitting hdivn (see divcur.F90)
+                  !   N.B. This computation is not valid along OBCs (if any)
+#if defined key_zco
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) )
+                  z_hdivn_x = (  e2u(ji  ,jj) * pun(ji  ,jj,jk)                              &
+                     &         - e2u(ji-1,jj) * pun(ji-1,jj,jk) ) * zbtr
+#else
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  z_hdivn_x = (  e2u(ji  ,jj) * fse3u(ji  ,jj,jk) * pun(ji  ,jj,jk)          &
+                     &         - e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * pun(ji-1,jj,jk) ) * zbtr
+#endif
+                  ztrdt(ji,jj,jk) = - zbtr * ( zt1(ji,jj,jk) - zt1(ji-1,jj,jk) ) + tn(ji,jj,jk) * z_hdivn_x
+                  ztrds(ji,jj,jk) = - zbtr * ( zs1(ji,jj,jk) - zs1(ji-1,jj,jk) ) + sn(ji,jj,jk) * z_hdivn_x
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_xad, 'TRA', kt)
+
+         ! T/S MERIDIONAL advection trends
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  !-- Compute merid. divergence by splitting hdivn (see divcur.F90)
+                  !   N.B. This computation is not valid along OBCs (if any)
+#if defined key_zco
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) )
+                  z_hdivn_y = (  e1v(ji,jj  ) * pvn(ji,jj  ,jk)                              &
+                     &         - e1v(ji,jj-1) * pvn(ji,jj-1,jk) ) * zbtr
+#else
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  z_hdivn_y = (  e1v(ji,  jj) * fse3v(ji,jj  ,jk) * pvn(ji,jj  ,jk)          &
+                     &         - e1v(ji,jj-1) * fse3v(ji,jj-1,jk) * pvn(ji,jj-1,jk) ) * zbtr
+#endif
+                  ztrdt(ji,jj,jk) = - zbtr * ( zt2(ji,jj,jk) - zt2(ji,jj-1,jk) ) + tn(ji,jj,jk) * z_hdivn_y          
+                  ztrds(ji,jj,jk) = - zbtr * ( zs2(ji,jj,jk) - zs2(ji,jj-1,jk) ) + sn(ji,jj,jk) * z_hdivn_y
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_yad, 'TRA', kt)
+
+         ! Save the up-to-date ta and sa trends
+         ztrdt(:,:,:) = ta(:,:,:) 
+         ztrds(:,:,:) = sa(:,:,:) 
+         !
       ENDIF
 
@@ -378,21 +385,36 @@
 
       ! Save the vertical advective trends for diagnostic
-
+      ! -------------------------------------------------
       IF( l_trdtra )   THEN
          ! Recompute the vertical advection zta & zsa trends computed 
          ! at the step 2. above in making the difference between the new 
-         ! trends and the previous one: ta()/sa - ztdta()/ztdsa() and substract
+         ! trends and the previous one: ta()/sa - ztrdt()/ztrds() and substract
          ! the term tn()/sn()*hdivn() to recover the W gradz(T/S) trends
-         ztdta(:,:,:) = ta(:,:,:) - ztdta(:,:,:) - tn(:,:,:) * hdivn(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) - ztdsa(:,:,:) - sn(:,:,:) * hdivn(:,:,:)
-
-         CALL trd_mod(ztdta, ztdsa, jpttdzad, 'TRA', kt)
-      ENDIF
-
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab3d_1=ta, clinfo1=' muscl zad  - Ta: ', mask1=tmask ,  &
-            &         tab3d_2=sa, clinfo2=' Sa: ', mask2=tmask, clinfo3='tra')
-      ENDIF
-
+
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+#if defined key_zco
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) )
+                  z_hdivn_x = e2u(ji,jj)*pun(ji,jj,jk) - e2u(ji-1,jj)*pun(ji-1,jj,jk)
+                  z_hdivn_y = e1v(ji,jj)*pvn(ji,jj,jk) - e1v(ji,jj-1)*pvn(ji,jj-1,jk)
+#else
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  z_hdivn_x = e2u(ji,jj)*fse3u(ji,jj,jk)*pun(ji,jj,jk) - e2u(ji-1,jj)*fse3u(ji-1,jj,jk)*pun(ji-1,jj,jk)
+                  z_hdivn_y = e1v(ji,jj)*fse3v(ji,jj,jk)*pvn(ji,jj,jk) - e1v(ji,jj-1)*fse3v(ji,jj-1,jk)*pvn(ji,jj-1,jk)
+#endif
+                  z_hdivn   = (z_hdivn_x + z_hdivn_y) * zbtr
+                  ztrdt(ji,jj,jk) = ta(ji,jj,jk) - ztrdt(ji,jj,jk) - tn(ji,jj,jk) * z_hdivn 
+                  ztrds(ji,jj,jk) = sa(ji,jj,jk) - ztrds(ji,jj,jk) - sn(ji,jj,jk) * z_hdivn
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_zad, 'TRA', kt)
+         !
+      ENDIF
+
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' muscl zad  - Ta: ', mask1=tmask ,   &
+         &                       tab3d_2=sa, clinfo2=             ' Sa: ', mask2=tmask, clinfo3='tra' )
+      !
    END SUBROUTINE tra_adv_muscl
 
Index: trunk/NEMO/OPA_SRC/TRA/traadv_muscl2.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/traadv_muscl2.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/traadv_muscl2.F90	(revision 503)
@@ -4,4 +4,6 @@
    !! Ocean active tracers:  horizontal & vertical advective trend
    !!==============================================================================
+   !! History :  9.0  !  02-06  (G. Madec) from traadv_muscl
+   !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
@@ -9,5 +11,4 @@
    !!                    and vertical advection trends using MUSCL2 scheme
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
@@ -32,7 +33,7 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -50,24 +51,18 @@
       !!
       !! ** Action  : - update (ta,sa) with the now advective tracer trends
-      !!              - save trends in (ztdta,ztdsa) ('key_trdtra')
-      !!
-      !! References :                
-      !!      Estubier, A., and M. Levy, Notes Techn. Pole de Modelisation
-      !!	IPSL, Sept. 2000 (http://www.lodyc.jussieu.fr/opa)
-      !!
-      !! History :
-      !!        !  06-00  (A.Estublier)  for passive tracers
-      !!        !  01-08  (E.Durand G.Madec)  adapted for T & S
-      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
-      !!   9.0  !  04-08  (C. Talandier) New trends organization
+      !!              - save trends in (ztrdt,ztrds) ('key_trdtra')
+      !!
+      !! References : Estubier, A., and M. Levy, Notes Techn. Pole de Modelisation
+      !!              IPSL, Sept. 2000 (http://www.lodyc.jussieu.fr/opa)
       !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER , INTENT( in ) ::   kt          ! ocean time-step index
-      REAL(wp), INTENT( in ), DIMENSION(jpi,jpj,jpk) ::   &
-         pun, pvn, pwn                        ! now ocean velocity fields
-
-
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk               ! dummy loop indices
+      USE oce              , ztrdt => ua   ! use ua as workspace
+      USE oce              , ztrds => va   ! use va as workspace
+      !!
+      INTEGER , INTENT(in)                         ::   kt    ! ocean time-step index
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pun   ! ocean velocity u-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pvn   ! ocean velocity v-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pwn   ! ocean velocity w-component
+      !!
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
       REAL(wp) ::   &
          zu, zv, zw, zeu, zev,           &  
@@ -76,9 +71,8 @@
          zzt1, zzt2, zalpha,             &
          zzs1, zzs2, z2,                 &
-         zta, zsa
-      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   &
-         zt1, zt2, ztp1, ztp2,   &
-         zs1, zs2, zsp1, zsp2,   &
-         ztdta, ztdsa
+         zta, zsa,                       &
+         z_hdivn_x, z_hdivn_y, z_hdivn
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zt1, zt2, ztp1, ztp2   ! 3D workspace
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zs1, zs2, zsp1, zsp2   !  "      "
       !!----------------------------------------------------------------------
 
@@ -89,17 +83,7 @@
       ENDIF
 
-      IF( neuler == 0 .AND. kt == nit000 ) THEN
-          z2=1.
-      ELSE
-          z2=2.
-      ENDIF
-
-      ! Save ta and sa trends
-      IF( l_trdtra )   THEN
-         ztdta(:,:,:) = ta(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) 
-         l_adv = 'mu2'
-      ENDIF
-
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;   z2 = 1.
+      ELSE                                        ;   z2 = 2.
+      ENDIF
 
       ! I. Horizontal advective fluxes
@@ -194,5 +178,5 @@
                zt1(ji,jj,jk) = zeu * ( zalpha * zzt1 + (1.-zalpha) * zzt2 )
                zs1(ji,jj,jk) = zeu * ( zalpha * zzs1 + (1.-zalpha) * zzs2 )
-
+               !
                z0v = SIGN( 0.5, pvn(ji,jj,jk) )            
                zalpha = 0.5 - z0v
@@ -271,15 +255,4 @@
       CALL lbc_lnk( zt2, 'V', -1. )   ;   CALL lbc_lnk( zs2, 'V', -1. )
 
-      ! Save MUSCL fluxes to compute i- & j- horizontal 
-      ! advection trends in the MLD
-      IF( l_trdtra )   THEN
-         ! save i- terms
-         tladi(:,:,:) = zt1(:,:,:) 
-         sladi(:,:,:) = zs1(:,:,:) 
-         ! save j- terms
-         tladj(:,:,:) = zt2(:,:,:) 
-         sladj(:,:,:) = zs2(:,:,:) 
-      ENDIF
-
       ! Compute & add the horizontal advective trend
 
@@ -305,25 +278,59 @@
 
       ! Save the horizontal advective trends for diagnostic
-
-      IF( l_trdtra )   THEN
-         ! Recompute the horizontal advection zta & zsa trends computed 
-         ! at the step 2. above in making the difference between the new 
-         ! trends and the previous one ta()/sa - ztdta()/ztdsa() and add
-         ! the term tn()/sn()*hdivn() to recover the Uh gradh(T/S) trends
-         ztdta(:,:,:) = ta(:,:,:) - ztdta(:,:,:) + tn(:,:,:) * hdivn(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) - ztdsa(:,:,:) + sn(:,:,:) * hdivn(:,:,:)
-
-         CALL trd_mod(ztdta, ztdsa, jpttdlad, 'TRA', kt)
-
-         ! Save the new ta and sa trends
-         ztdta(:,:,:) = ta(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) 
-
-      ENDIF
-
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab3d_1=ta, clinfo1=' muscl2 had  - Ta: ', mask1=tmask, &
-            &         tab3d_2=sa, clinfo2=' Sa: ', mask2=tmask, clinfo3='tra')
-      ENDIF
+      IF( l_trdtra ) THEN
+         ztrdt(:,:,:) = 0.e0   ;   ztrds(:,:,:) = 0.e0
+         !
+         ! T/S ZONAL advection trends
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  !-- Compute zonal divergence by splitting hdivn (see divcur.F90)
+                  !   N.B. This computation is not valid along OBCs (if any)
+#if defined key_zco
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) )
+                  z_hdivn_x = (  e2u(ji  ,jj) * pun(ji  ,jj,jk)                              &
+                     &         - e2u(ji-1,jj) * pun(ji-1,jj,jk) ) * zbtr
+#else
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  z_hdivn_x = (  e2u(ji  ,jj) * fse3u(ji  ,jj,jk) * pun(ji  ,jj,jk)          &
+                     &         - e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * pun(ji-1,jj,jk) ) * zbtr
+#endif
+                  ztrdt(ji,jj,jk) = - zbtr * ( zt1(ji,jj,jk) - zt1(ji-1,jj,jk) ) + tn(ji,jj,jk) * z_hdivn_x
+                  ztrds(ji,jj,jk) = - zbtr * ( zs1(ji,jj,jk) - zs1(ji-1,jj,jk) ) + sn(ji,jj,jk) * z_hdivn_x
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_xad, 'TRA', kt)
+
+         ! T/S MERIDIONAL advection trends
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  !-- Compute merid. divergence by splitting hdivn (see divcur.F90)
+                  !   N.B. This computation is not valid along OBCs (if any)
+#if defined key_zco
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) )
+                  z_hdivn_y = (  e1v(ji,jj  ) * pvn(ji,jj  ,jk)                              &
+                     &         - e1v(ji,jj-1) * pvn(ji,jj-1,jk) ) * zbtr
+#else
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  z_hdivn_y = (  e1v(ji,  jj) * fse3v(ji,jj  ,jk) * pvn(ji,jj  ,jk)          &
+                     &         - e1v(ji,jj-1) * fse3v(ji,jj-1,jk) * pvn(ji,jj-1,jk) ) * zbtr
+#endif
+                  ztrdt(ji,jj,jk) = - zbtr * ( zt2(ji,jj,jk) - zt2(ji,jj-1,jk) ) + tn(ji,jj,jk) * z_hdivn_y          
+                  ztrds(ji,jj,jk) = - zbtr * ( zs2(ji,jj,jk) - zs2(ji,jj-1,jk) ) + sn(ji,jj,jk) * z_hdivn_y
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_yad, 'TRA', kt)
+
+         ! Save the up-to-date ta and sa trends
+         ztrdt(:,:,:) = ta(:,:,:) 
+         ztrds(:,:,:) = sa(:,:,:) 
+         !
+      ENDIF
+
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' muscl2 had  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=              ' Sa: ', mask2=tmask, clinfo3='tra')
 
       ! "zonal" mean advective heat and salt transport
@@ -451,22 +458,35 @@
 
       ! Save the vertical advective trends for diagnostic
-
       IF( l_trdtra )   THEN
          ! Recompute the vertical advection zta & zsa trends computed 
          ! at the step 2. above in making the difference between the new 
-         ! trends and the previous one: ta()/sa - ztdta()/ztdsa() and substract
+         ! trends and the previous one: ta()/sa - ztrdt()/ztrds() and substract
          ! the term tn()/sn()*hdivn() to recover the W gradz(T/S) trends
-         ztdta(:,:,:) = ta(:,:,:) - ztdta(:,:,:) - tn(:,:,:) * hdivn(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) - ztdsa(:,:,:) - sn(:,:,:) * hdivn(:,:,:)
-
-         CALL trd_mod(ztdta, ztdsa, jpttdzad, 'TRA', kt)
-      ENDIF
-
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab3d_1=ta, clinfo1=' muscl2 zad  - Ta: ', mask1=tmask, &
-            &         tab3d_2=sa, clinfo2=' Sa: ', mask2=tmask, clinfo3='tra')
-
-      ENDIF
-
+
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+#if defined key_zco
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) )
+                  z_hdivn_x = e2u(ji,jj)*pun(ji,jj,jk) - e2u(ji-1,jj)*pun(ji-1,jj,jk)
+                  z_hdivn_y = e1v(ji,jj)*pvn(ji,jj,jk) - e1v(ji,jj-1)*pvn(ji,jj-1,jk)
+#else
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  z_hdivn_x = e2u(ji,jj)*fse3u(ji,jj,jk)*pun(ji,jj,jk) - e2u(ji-1,jj)*fse3u(ji-1,jj,jk)*pun(ji-1,jj,jk)
+                  z_hdivn_y = e1v(ji,jj)*fse3v(ji,jj,jk)*pvn(ji,jj,jk) - e1v(ji,jj-1)*fse3v(ji,jj-1,jk)*pvn(ji,jj-1,jk)
+#endif
+                  z_hdivn   = (z_hdivn_x + z_hdivn_y) * zbtr
+                  ztrdt(ji,jj,jk) = ta(ji,jj,jk) - ztrdt(ji,jj,jk) - tn(ji,jj,jk) * z_hdivn 
+                  ztrds(ji,jj,jk) = sa(ji,jj,jk) - ztrds(ji,jj,jk) - sn(ji,jj,jk) * z_hdivn
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_zad, 'TRA', kt)
+         !
+      ENDIF
+
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' muscl2 zad  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=              ' Sa: ', mask2=tmask, clinfo3='tra' )
+      !
    END SUBROUTINE tra_adv_muscl2
 
Index: trunk/NEMO/OPA_SRC/TRA/traadv_tvd.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/traadv_tvd.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/traadv_tvd.F90	(revision 503)
@@ -4,4 +4,15 @@
    !! Ocean active tracers:  horizontal & vertical advective trend
    !!==============================================================================
+   !! History :       !  95-12  (L. Mortier)  Original code
+   !!                 !  00-01  (H. Loukos)  adapted to ORCA 
+   !!                 !  00-10  (MA Foujols E.Kestenare)  include file not routine
+   !!                 !  00-12  (E. Kestenare M. Levy)  fix bug in trtrd indexes
+   !!                 !  01-07  (E. Durand G. Madec)  adaptation to ORCA config
+   !!            8.5  !  02-06  (G. Madec)  F90: Free form and module
+   !!            9.0  !  04-01  (A. de Miranda, G. Madec, J.M. Molines ): advective bbl
+   !!            9.0  !  08-04  (S. Cravatte) add the i-, j- & k- trends computation
+   !!            " "  !  05-11  (V. Garnier) Surface pressure gradient organization
+   !!----------------------------------------------------------------------
+
 
    !!----------------------------------------------------------------------
@@ -11,5 +22,4 @@
    !!                  algorithm 
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
@@ -28,6 +38,5 @@
    PRIVATE
 
-   !! * Accessibility
-   PUBLIC tra_adv_tvd    ! routine called by step.F90
+   PUBLIC   tra_adv_tvd    ! routine called by step.F90
 
    !! * Substitutions
@@ -35,7 +44,7 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
-   !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -54,41 +63,26 @@
       !!
       !! ** Action : - update (ta,sa) with the now advective tracer trends
-      !!             - save the trends in (ttrdh,strdh) ('key_trdtra')
+      !!             - save the trends in (ztrdt,ztrds) ('key_trdtra')
+      !!----------------------------------------------------------------------
+      USE oce              , ztrdt => ua   ! use ua as workspace
+      USE oce              , ztrds => va   ! use va as workspace
       !!
-      !! History :
-      !!        !  95-12  (L. Mortier)  Original code
-      !!        !  00-01  (H. Loukos)  adapted to ORCA 
-      !!        !  00-10  (MA Foujols E.Kestenare)  include file not routine
-      !!        !  00-12  (E. Kestenare M. Levy)  fix bug in trtrd indexes
-      !!        !  01-07  (E. Durand G. Madec)  adaptation to ORCA config
-      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
-      !!   9.0  !  04-01  (A. de Miranda, G. Madec, J.M. Molines ): advective bbl
-      !!   9.0  !  08-04  (S. Cravatte) add the i-, j- & k- trends computation
-      !!    "   !  05-11  (V. Garnier) Surface pressure gradient organization
-      !!----------------------------------------------------------------------
-      !! * Modules used
-      USE trdmod_oce         , ztay => tladj,  &  ! use tladj latter
-         &                     zsay => sladj,  &  ! use sladj latter
-         &                     ztaz => tladi,  &  ! use ua as workspace
-         &                     zsaz => sladi      ! use ua as workspace
-
-      !! * Arguments
-      INTEGER , INTENT( in ) ::   kt          ! ocean time-step index
-      REAL(wp), INTENT( in ), DIMENSION(jpi,jpj,jpk) ::   &
-         pun, pvn, pwn                        ! now ocean velocity fields
-
-      !! * Local declarations
+      INTEGER , INTENT(in)                         ::   kt    ! ocean time-step index
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pun   ! ocean velocity u-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pvn   ! ocean velocity v-component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pwn   ! ocean velocity w-component
+      !!
       INTEGER  ::   ji, jj, jk              ! dummy loop indices
       REAL(wp) ::                        &  ! temporary scalar
          ztai, ztaj, ztak,               &  !    "         "   
-         zsai, zsaj, zsak                   !    "         "   
-      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   &
-         zti, ztu, ztv, ztw,             &  ! temporary workspace
-         zsi, zsu, zsv, zsw,             &  !    "           "
-         ztdta, ztdsa                       !    "           "
+         zsai, zsaj, zsak,               &  !    "         "   
+         z_hdivn_x, z_hdivn_y, z_hdivn
       REAL(wp) ::   &
-         z2dtt, zbtr, zeu, zev, zew, z2, &  ! temporary scalar
+         z2dtt, zbtr, zeu, zev,          &  ! temporary scalar
+         zew, z2, zbtr1,                 &  ! temporary scalar
          zfp_ui, zfp_vj, zfp_wk,         &  !    "         "
          zfm_ui, zfm_vj, zfm_wk             !    "         "
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zti, ztu, ztv, ztw   ! temporary workspace
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zsi, zsu, zsv, zsw   !    "           "
       !!----------------------------------------------------------------------
 
@@ -101,17 +95,7 @@
       ENDIF
 
-      IF( neuler == 0 .AND. kt == nit000 ) THEN
-         z2=1.
-      ELSE
-         z2=2.
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;    z2 = 1.
+      ELSE                                        ;    z2 = 2.
       ENDIF
-
-      ! Save ta and sa trends
-      IF( l_trdtra )   THEN
-         ztdta(:,:,:) = ta(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) 
-         l_adv = 'tvd'
-      ENDIF
-
 
       ! 1. Bottom value : flux set to zero
@@ -177,5 +161,4 @@
             DO ji = fs_2, fs_jpim1   ! vector opt.
                zbtr = 1./ ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
-
                ! i- j- horizontal & k- vertical advective trends
                ztai = - ( ztu(ji,jj,jk) - ztu(ji-1,jj  ,jk  ) ) * zbtr
@@ -185,5 +168,4 @@
                zsaj = - ( zsv(ji,jj,jk) - zsv(ji  ,jj-1,jk  ) ) * zbtr
                zsak = - ( zsw(ji,jj,jk) - zsw(ji  ,jj  ,jk+1) ) * zbtr
-
                ! total intermediate advective trends
                zti(ji,jj,jk) = ztai + ztaj + ztak
@@ -193,17 +175,50 @@
       END DO
 
-     ! Save the intermediate vertical & j- horizontal advection trends
-     IF( l_trdtra )   THEN
+
+      ! Save the intermediate i / j / k advective trends for diagnostics
+      ! -------------------------------------------------------------------
+      ! Warning : We should use zun instead of un in the computations below, but we
+      ! also use hdivn which is computed with un, vn (check ???). So we use un, vn
+      ! for consistency. Results are therefore approximate with key_trabbl_adv.
+
+      IF( l_trdtra ) THEN
+         ztrdt(:,:,:) = 0.e0   ;   ztrds(:,:,:) = 0.e0
+         ! 
+         ! T/S ZONAL advection trends
          DO jk = 1, jpkm1
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zbtr = 1./ ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
-                  ztay(ji,jj,jk) = - ( ztv(ji,jj,jk) - ztv(ji  ,jj-1,jk  ) ) * zbtr
-                  zsay(ji,jj,jk) = - ( zsv(ji,jj,jk) - zsv(ji  ,jj-1,jk  ) ) * zbtr
-                  ztaz(ji,jj,jk) = - ( ztw(ji,jj,jk) - ztw(ji  ,jj  ,jk+1) ) * zbtr
-                  zsaz(ji,jj,jk) = - ( zsw(ji,jj,jk) - zsw(ji  ,jj  ,jk+1) ) * zbtr
+                  zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  ztrdt(ji,jj,jk) = - ( ztu(ji,jj,jk) - ztu(ji-1,jj,jk) ) * zbtr
+                  ztrds(ji,jj,jk) = - ( zsu(ji,jj,jk) - zsu(ji-1,jj,jk) ) * zbtr
                END DO
             END DO
          END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_xad, 'TRA', kt)    ! save the trends
+         !
+         ! T/S MERIDIONAL advection trends
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  ztrdt(ji,jj,jk) = - ( ztv(ji,jj,jk) - ztv(ji,jj-1,jk) ) * zbtr
+                  ztrds(ji,jj,jk) = - ( zsv(ji,jj,jk) - zsv(ji,jj-1,jk) ) * zbtr
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_yad, 'TRA', kt)     ! save the trends
+         !
+         ! T/S VERTICAL advection trends
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.         
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  ztrdt(ji,jj,jk) = - ( ztw(ji,jj,jk) - ztw(ji,jj,jk+1) ) * zbtr
+                  ztrds(ji,jj,jk) = - ( zsw(ji,jj,jk) - zsw(ji,jj,jk+1) ) * zbtr
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_zad, 'TRA', kt)     ! save the trends
+         !
       ENDIF
 
@@ -244,6 +259,6 @@
       ! antidiffusive flux on k
       ! Surface value
-      ztw(:,:,1) = 0.
-      zsw(:,:,1) = 0.
+      ztw(:,:,1) = 0.e0
+      zsw(:,:,1) = 0.e0
 
       ! Interior value
@@ -290,50 +305,72 @@
       END DO
 
-      ! save the advective trends for diagnostic
-      ! tracers trends
-      IF( l_trdtra )   THEN
-         ! Compute the final vertical & j- horizontal advection trends
+
+      ! Save the advective trends for diagnostics
+      ! --------------------------------------------
+
+      IF( l_trdtra ) THEN
+         ztrdt(:,:,:) = 0.e0   ;   ztrds(:,:,:) = 0.e0
+         !
+         ! T/S ZONAL advection trends
          DO jk = 1, jpkm1
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zbtr = 1./ ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
-                  ztay(ji,jj,jk) = - ( ztv(ji,jj,jk) - ztv(ji  ,jj-1,jk  ) ) * zbtr   &
-                     &             + ztay(ji,jj,jk) 
-                  zsay(ji,jj,jk) = - ( zsv(ji,jj,jk) - zsv(ji  ,jj-1,jk  ) ) * zbtr   &
-                     &             + zsay(ji,jj,jk) 
-                  ztaz(ji,jj,jk) = - ( ztw(ji,jj,jk) - ztw(ji  ,jj  ,jk+1) ) * zbtr   &
-                     &             + ztaz(ji,jj,jk) 
-                  zsaz(ji,jj,jk) = - ( zsw(ji,jj,jk) - zsw(ji  ,jj  ,jk+1) ) * zbtr   &
-                     &             + zsaz(ji,jj,jk) 
+                  !-- Compute zonal divergence by splitting hdivn (see divcur.F90)
+                  !   N.B. This computation is not valid along OBCs (if any)
+                  zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  z_hdivn_x = (  e2u(ji  ,jj) * fse3u(ji  ,jj,jk) * pun(ji  ,jj,jk)          &
+                     &         - e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * pun(ji-1,jj,jk) ) * zbtr
+                  !-- Compute T/S zonal advection trends
+                  ztrdt(ji,jj,jk) = - ( ztu(ji,jj,jk) - ztu(ji-1,jj,jk) ) * zbtr + tn(ji,jj,jk) * z_hdivn_x
+                  ztrds(ji,jj,jk) = - ( zsu(ji,jj,jk) - zsu(ji-1,jj,jk) ) * zbtr + sn(ji,jj,jk) * z_hdivn_x
                END DO
             END DO
          END DO
-
-         ! horizontal advection: 
-         ! make the difference between the new trends ta()/sa() and the 
-         ! previous one ztdta()/ztdsa() to have the total advection trends 
-         ! to which we substract the vertical trends ztaz()/zsaz()
-         ztdta(:,:,:) = ta(:,:,:) - ztdta(:,:,:) - ztaz(:,:,:)
-         ztdsa(:,:,:) = sa(:,:,:) - ztdsa(:,:,:) - zsaz(:,:,:)
-
-         ! Add the term tn()/sn()*hdivn() to recover the Uh gradh(T/S) trends
-         ztdta(:,:,:) = ztdta(:,:,:) + tn(:,:,:) * hdivn(:,:,:)
-         ztdsa(:,:,:) = ztdsa(:,:,:) + sn(:,:,:) * hdivn(:,:,:)
-
-         CALL trd_mod(ztdta, ztdsa, jpttdlad, 'TRA', kt)
-
-         ! vertical advection: 
-         ! Substract the term tn()/sn()*hdivn() to recover the W gradz(T/S) trends
-         ztaz(:,:,:) = ztaz(:,:,:) - tn(:,:,:) * hdivn(:,:,:)
-         zsaz(:,:,:) = zsaz(:,:,:) - sn(:,:,:) * hdivn(:,:,:)
-
-         CALL trd_mod(ztaz, zsaz, jpttdzad, 'TRA', kt)
-
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_xad, 'TRA', kt, cnbpas='bis')   ! <<< ADD TO PREVIOUSLY COMPUTED
+         !
+         ! T/S MERIDIONAL advection trends
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  !-- Compute merid. divergence by splitting hdivn (see divcur.F90)
+                  !   N.B. This computation is not valid along OBCs (if any)
+                  zbtr      = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  z_hdivn_y = (  e1v(ji,  jj) * fse3v(ji,jj  ,jk) * pvn(ji,jj  ,jk)          &
+                     &         - e1v(ji,jj-1) * fse3v(ji,jj-1,jk) * pvn(ji,jj-1,jk) ) * zbtr
+                  !-- Compute T/S meridional advection trends
+                  ztrdt(ji,jj,jk) = - ( ztv(ji,jj,jk) - ztv(ji,jj-1,jk) ) * zbtr + tn(ji,jj,jk) * z_hdivn_y          
+                  ztrds(ji,jj,jk) = - ( zsv(ji,jj,jk) - zsv(ji,jj-1,jk) ) * zbtr + sn(ji,jj,jk) * z_hdivn_y          
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_yad, 'TRA', kt, cnbpas='bis')   ! <<< ADD TO PREVIOUSLY COMPUTED
+         !
+         ! T/S VERTICAL advection trends
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zbtr1     = 1. / ( e1t(ji,jj) * e2t(ji,jj) )
+#if defined key_zco
+                  zbtr      = zbtr1
+                  z_hdivn_x = e2u(ji,jj)*pun(ji,jj,jk) - e2u(ji-1,jj)*pun(ji-1,jj,jk)
+                  z_hdivn_y = e1v(ji,jj)*pvn(ji,jj,jk) - e1v(ji,jj-1)*pvn(ji,jj-1,jk)
+#else
+                  zbtr      = zbtr1 / fse3t(ji,jj,jk)
+                  z_hdivn_x = e2u(ji,jj)*fse3u(ji,jj,jk)*pun(ji,jj,jk) - e2u(ji-1,jj)*fse3u(ji-1,jj,jk)*pun(ji-1,jj,jk)
+                  z_hdivn_y = e1v(ji,jj)*fse3v(ji,jj,jk)*pvn(ji,jj,jk) - e1v(ji,jj-1)*fse3v(ji,jj-1,jk)*pvn(ji,jj-1,jk)
+#endif
+                  z_hdivn   = (z_hdivn_x + z_hdivn_y) * zbtr
+                  zbtr      = zbtr1 / fse3t(ji,jj,jk)
+                  ztrdt(ji,jj,jk) = - ( ztw(ji,jj,jk) - ztw(ji,jj,jk+1) ) * zbtr - tn(ji,jj,jk) * z_hdivn
+                  ztrds(ji,jj,jk) = - ( zsw(ji,jj,jk) - zsw(ji,jj,jk+1) ) * zbtr - sn(ji,jj,jk) * z_hdivn
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_zad, 'TRA', kt, cnbpas='bis')   ! <<< ADD TO PREVIOUSLY COMPUTED
+         !
       ENDIF
 
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab3d_1=ta, clinfo1=' tvd adv  - Ta: ', mask1=tmask, &
-            &         tab3d_2=sa, clinfo2=' Sa: ', mask2=tmask, clinfo3='tra')
-      ENDIF
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' tvd adv  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=           ' Sa: ', mask2=tmask, clinfo3='tra' )
 
       ! "zonal" mean advective heat and salt transport
@@ -342,5 +379,5 @@
          pst_adv(:) = ptr_vj( zsv(:,:,:) )
       ENDIF
-
+      !
    END SUBROUTINE tra_adv_tvd
 
@@ -358,16 +395,6 @@
       !!       drange (1995) multi-dimensional forward-in-time and upstream-
       !!       in-space based differencing for fluid
-      !!
-      !! History :
-      !!        !  97-04  (L. Mortier) Original code
-      !!        !  00-02  (H. Loukos)  rewritting for opa8
-      !!        !  00-10  (M.A Foujols, E. Kestenare)  lateral b.c.
-      !!        !  01-03  (E. Kestenare)  add key_passivetrc
-      !!        !  01-07  (E. Durand G. Madec)  adapted for T & S
-      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
       !!----------------------------------------------------------------------
-      !! * Arguments
-      REAL(wp), INTENT( in ) ::   &
-         prdt                               ! ???
+      REAL(wp), INTENT( in ) ::   prdt                               ! ???
       REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT( inout ) ::   &
          pbef,                            & ! before field
@@ -376,6 +403,5 @@
          pbb,                             & ! monotonic flux in the j direction
          pcc                                ! monotonic flux in the k direction
-
-      !! * Local declarations
+      !!
       INTEGER ::   ji, jj, jk               ! dummy loop indices
       INTEGER ::   ikm1
@@ -496,5 +522,5 @@
       CALL lbc_lnk( pbb, 'V', -1. )      ! changed sign
       CALL lbc_lnk( pcc, 'W',  1. )      ! NO changed sign
-
+      !
    END SUBROUTINE nonosc
 
Index: trunk/NEMO/OPA_SRC/TRA/traadv_ubs.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/traadv_ubs.F90	(revision 503)
+++ trunk/NEMO/OPA_SRC/TRA/traadv_ubs.F90	(revision 503)
@@ -0,0 +1,541 @@
+MODULE traadv_ubs
+   !!==============================================================================
+   !!                       ***  MODULE  traadv_ubs  ***
+   !! Ocean active tracers:  horizontal & vertical advective trend
+   !!==============================================================================
+   !! History :  9.0  !  06-08  (L. Debreu, R. Benshila)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_adv_ubs : update the tracer trend with the horizontal
+   !!                 advection trends using a third order biaised scheme  
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and active tracers
+   USE dom_oce         ! ocean space and time domain
+   USE trdmod
+   USE trdmod_oce
+   USE lib_mpp
+   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 prtctl
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_adv_ubs   ! routine called by traadv module
+
+   REAL(wp), DIMENSION(jpi,jpj) ::   e1e2tr   ! = 1/(e1t * e2t)
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006)  
+   !! $Header$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE tra_adv_ubs( kt, pun, pvn, pwn )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_ubs  ***
+      !!                 
+      !! ** Purpose :   Compute the now trend due to the advection of tracers
+      !!      and add it to the general trend of passive tracer equations.
+      !!
+      !! ** Method  :   ???
+      !!
+      !! ** Action : - update (ta,sa) with the now advective tracer trends
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   zwx => ua   ! use ua as workspace
+      USE oce, ONLY :   zwy => va   ! use va as workspace
+      !!
+      INTEGER , INTENT(in)                         ::   kt             ! ocean time-step index
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::  pun   ! effective ocean velocity, u_component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::  pvn   ! effective ocean velocity, v_component
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::  pwn   ! effective ocean velocity, w_component
+      !!
+      INTEGER  ::   ji, jj, jk                 ! dummy loop indices
+      REAL(wp) ::   zta, zsa, zbtr, zcoef                  ! temporary scalars
+      REAL(wp) ::   zfui, zfp_ui, zfm_ui, zcenut, zcenus   !    "         "
+      REAL(wp) ::   zfvj, zfp_vj, zfm_vj, zcenvt, zcenvs   !    "         "
+      REAL(wp) ::   z_hdivn_x, z_hdivn_y, z_hdivn          !    "         "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zeeu, zeev     ! temporary 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwz , zww                        ! temporary 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztu , ztv , zltu , zltv, ztrdt   !    "              "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zsu , zsv , zlsu , zlsv, ztrds   !    "              "
+      !!----------------------------------------------------------------------
+
+      zltu(:,:,:) = 0.e0
+      zltv(:,:,:) = 0.e0
+      zlsu(:,:,:) = 0.e0
+      zlsv(:,:,:) = 0.e0
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_adv_ubs :  horizontal UBS advection scheme'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
+         !
+         e1e2tr(:,:) = 1. / ( e1t(:,:) * e2t(:,:) )
+      ENDIF
+
+      ! Save ta and sa trends
+      ztrdt(:,:,:) = ta(:,:,:)
+      ztrds(:,:,:) = sa(:,:,:)
+
+      zcoef = 1./6.
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+
+         !  Initialization of metric arrays (for z- or s-coordinates)
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+#if defined key_zco
+               ! z-coordinates, no vertical scale factors
+               zeeu(ji,jj) = e2u(ji,jj) / e1u(ji,jj) * umask(ji,jj,jk)
+               zeev(ji,jj) = e1v(ji,jj) / e2v(ji,jj) * vmask(ji,jj,jk)
+#else
+               ! s-coordinates, vertical scale factor are used
+               zeeu(ji,jj) = e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj) * umask(ji,jj,jk)
+               zeev(ji,jj) = e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj) * vmask(ji,jj,jk)
+#endif
+            END DO
+         END DO
+
+         !  Laplacian
+         ! First derivative (gradient)
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               ztu(ji,jj,jk) = zeeu(ji,jj) * ( tb(ji+1,jj  ,jk) - tb(ji,jj,jk) )
+               zsu(ji,jj,jk) = zeeu(ji,jj) * ( sb(ji+1,jj  ,jk) - sb(ji,jj,jk) )
+               ztv(ji,jj,jk) = zeev(ji,jj) * ( tb(ji  ,jj+1,jk) - tb(ji,jj,jk) )
+               zsv(ji,jj,jk) = zeev(ji,jj) * ( sb(ji  ,jj+1,jk) - sb(ji,jj,jk) )
+            END DO
+         END DO
+         ! Second derivative (divergence)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+#if ! defined key_zco
+               zcoef = 1. / ( 6. * fse3t(ji,jj,jk) )
+#endif         
+               zltu(ji,jj,jk) = (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk)  ) * zcoef
+               zlsu(ji,jj,jk) = (  zsu(ji,jj,jk) - zsu(ji-1,jj,jk)  ) * zcoef
+               zltv(ji,jj,jk) = (  ztv(ji,jj,jk) - ztv(ji,jj-1,jk)  ) * zcoef
+               zlsv(ji,jj,jk) = (  zsv(ji,jj,jk) - zsv(ji,jj-1,jk)  ) * zcoef
+            END DO
+         END DO
+         !                                             ! =================
+      END DO                                           !    End of slab
+      !                                                ! =================
+
+      ! Lateral boundary conditions on the laplacian (zlt,zls)   (unchanged sgn)
+      CALL lbc_lnk( zltu, 'T', 1. )   ;    CALL lbc_lnk( zlsu, 'T', 1. )
+      CALL lbc_lnk( zltv, 'T', 1. )   ;    CALL lbc_lnk( zlsv, 'T', 1. )
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+         !  Horizontal advective fluxes
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               ! volume fluxes * 1/2
+#if defined key_zco
+               zfui = 0.5 * e2u(ji,jj) * pun(ji,jj,jk)
+               zfvj = 0.5 * e1v(ji,jj) * pvn(ji,jj,jk)
+#else
+               zfui = 0.5 * e2u(ji,jj) * fse3u(ji,jj,jk) * pun(ji,jj,jk)
+               zfvj = 0.5 * e1v(ji,jj) * fse3v(ji,jj,jk) * pvn(ji,jj,jk)
+#endif
+               ! upstream scheme
+               zfp_ui = zfui + ABS( zfui )
+               zfp_vj = zfvj + ABS( zfvj )
+               zfm_ui = zfui - ABS( zfui )
+               zfm_vj = zfvj - ABS( zfvj )
+               ! centered scheme
+               zcenut = zfui * ( tn(ji,jj,jk) + tn(ji+1,jj  ,jk) )
+               zcenvt = zfvj * ( tn(ji,jj,jk) + tn(ji  ,jj+1,jk) )
+               zcenus = zfui * ( sn(ji,jj,jk) + sn(ji+1,jj  ,jk) )
+               zcenvs = zfvj * ( sn(ji,jj,jk) + sn(ji  ,jj+1,jk) )
+               ! mixed centered / upstream scheme
+               zwx(ji,jj,jk) = zcenut - zfp_ui * zltu(ji,jj,jk) -zfm_ui * zltu(ji+1,jj,jk)
+               zwy(ji,jj,jk) = zcenvt - zfp_vj * zltv(ji,jj,jk) -zfm_vj * zltv(ji,jj+1,jk)
+               zww(ji,jj,jk) = zcenus - zfp_ui * zlsu(ji,jj,jk) -zfm_ui * zlsu(ji+1,jj,jk)
+               zwz(ji,jj,jk) = zcenvs - zfp_vj * zlsv(ji,jj,jk) -zfm_vj * zlsv(ji,jj+1,jk)
+            END DO
+         END DO
+
+         !  Tracer flux divergence at t-point added to the general trend
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! horizontal advective trends
+#if defined key_zco
+               zbtr = e1e2tr(ji,jj)
+#else
+               zbtr = e1e2tr(ji,jj) / fse3t(ji,jj,jk)
+#endif
+               zta = - zbtr * (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk)   &
+                  &            + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk)  )
+               zsa = - zbtr * (  zww(ji,jj,jk) - zww(ji-1,jj  ,jk)   &
+                  &            + zwz(ji,jj,jk) - zwz(ji  ,jj-1,jk)  )
+               ! add it to the general tracer trends
+               ta(ji,jj,jk) = ta(ji,jj,jk) + zta
+               sa(ji,jj,jk) = sa(ji,jj,jk) + zsa
+            END DO
+         END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      ! Horizontal trend used in tra_adv_ztvd subroutine
+      zltu(:,:,:) = ta(:,:,:) - ztrdt(:,:,:) 
+      zlsu(:,:,:) = sa(:,:,:) - ztrds(:,:,:) 
+
+      ! 3. Save the horizontal advective trends for diagnostic
+      ! ------------------------------------------------------
+      IF( l_trdtra )   THEN
+         ! Recompute the hoizontal advection zta & zsa trends computed 
+         ! at the step 2. above in making the difference between the new 
+         ! trends and the previous one ta()/sa - ztrdt()/ztrds() and add
+         ! the term tn()/sn()*hdivn() to recover the Uh gradh(T/S) trends
+         ztrdt(:,:,:) = 0.e0   ;   ztrds(:,:,:) = 0.e0
+         !
+         ! T/S ZONAL advection trends
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  !-- Compute zonal divergence by splitting hdivn (see divcur.F90)
+#if defined key_zco
+                  zbtr = e1e2tr(ji,jj)
+                  z_hdivn_x = (  e2u(ji  ,jj) * pun(ji  ,jj,jk)          &
+                     &         - e2u(ji-1,jj) * pun(ji-1,jj,jk) ) * zbtr
+#else
+                  zbtr = e1e2tr(ji,jj) / fse3t(ji,jj,jk)
+                  z_hdivn_x = (  e2u(ji  ,jj) * fse3u(ji  ,jj,jk) * pun(ji  ,jj,jk)          &
+                     &         - e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * pun(ji-1,jj,jk) ) * zbtr
+#endif
+                  ztrdt(ji,jj,jk) = - ( zwx(ji,jj,jk) - zwx(ji-1,jj,jk) ) * zbtr + tn(ji,jj,jk) * z_hdivn_x
+                  ztrds(ji,jj,jk) = - ( zww(ji,jj,jk) - zww(ji-1,jj,jk) ) * zbtr + sn(ji,jj,jk) * z_hdivn_x
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_xad, 'TRA', kt)    ! save the trends
+         !
+         ! T/S MERIDIONAL advection trends
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  !-- Compute merid. divergence by splitting hdivn (see divcur.F90)
+#if defined key_zco
+                  zbtr      = e1e2tr(ji,jj)
+                  z_hdivn_y = (  e1v(ji,  jj) * pvn(ji,jj  ,jk)          &
+                     &         - e1v(ji,jj-1) * pvn(ji,jj-1,jk) ) * zbtr
+#else
+                  zbtr      = e1e2tr(ji,jj) / fse3t(ji,jj,jk)
+                  z_hdivn_y = (  e1v(ji,  jj) * fse3v(ji,jj  ,jk) * pvn(ji,jj  ,jk)          &
+                     &         - e1v(ji,jj-1) * fse3v(ji,jj-1,jk) * pvn(ji,jj-1,jk) ) * zbtr
+#endif
+                  ztrdt(ji,jj,jk) = - ( zwy(ji,jj,jk) - zwy(ji,jj-1,jk) ) * zbtr + tn(ji,jj,jk) * z_hdivn_y          
+                  ztrds(ji,jj,jk) = - ( zwz(ji,jj,jk) - zwz(ji,jj-1,jk) ) * zbtr + sn(ji,jj,jk) * z_hdivn_y
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_yad, 'TRA', kt)     ! save the trends
+         !
+      ENDIF
+
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' ubs had  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=           ' Sa: ', mask2=tmask, clinfo3='tra' )
+
+      ! "zonal" mean advective heat and salt transport 
+      IF( ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
+         IF( lk_zco ) THEN
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+                     zwy(ji,jj,jk) = zwy(ji,jj,jk) * fse3v(ji,jj,jk)
+                     zwz(ji,jj,jk) = zwz(ji,jj,jk) * fse3v(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+         ENDIF
+         pht_adv(:) = ptr_vj( zwy(:,:,:) )
+         pst_adv(:) = ptr_vj( zwz(:,:,:) )
+      ENDIF
+
+      ! II. Vertical advection
+      ! ----------------------
+      IF( l_trdtra ) THEN          ! Save ta and sa trends
+         ztrdt(:,:,:) = ta(:,:,:)
+         ztrds(:,:,:) = sa(:,:,:)
+      ENDIF
+    
+      ! TVD scheme the vertical direction  
+      CALL tra_adv_ztvd(kt, pwn, zltu, zlsu)
+
+      IF( l_trdtra )   THEN         !  Save the final vertical advective trends
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+#if defined key_zco
+                  zbtr      = e1e2tr(ji,jj)
+                  z_hdivn_x = e2u(ji,jj)*pun(ji,jj,jk) - e2u(ji-1,jj)*pun(ji-1,jj,jk)
+                  z_hdivn_y = e1v(ji,jj)*pvn(ji,jj,jk) - e1v(ji,jj-1)*pvn(ji,jj-1,jk)
+#else
+                  zbtr      = e1e2tr(ji,jj) / fse3t(ji,jj,jk)
+                  z_hdivn_x = e2u(ji,jj)*fse3u(ji,jj,jk)*pun(ji,jj,jk) - e2u(ji-1,jj)*fse3u(ji-1,jj,jk)*pun(ji-1,jj,jk)
+                  z_hdivn_y = e1v(ji,jj)*fse3v(ji,jj,jk)*pvn(ji,jj,jk) - e1v(ji,jj-1)*fse3v(ji,jj-1,jk)*pvn(ji,jj-1,jk)
+#endif
+                  z_hdivn   = (z_hdivn_x + z_hdivn_y) * zbtr
+                  zbtr      = e1e2tr(ji,jj) / fse3t(ji,jj,jk)
+                  ztrdt(ji,jj,jk) = ta(ji,jj,jk) - ztrdt(ji,jj,jk) - tn(ji,jj,jk) * z_hdivn
+                  ztrds(ji,jj,jk) = sa(ji,jj,jk) - ztrds(ji,jj,jk) - sn(ji,jj,jk) * z_hdivn
+               END DO
+            END DO
+         END DO
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_zad, 'TRA', kt)   ! <<< ADD TO PREVIOUSLY COMPUTED
+         !
+      ENDIF
+
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' ubs zad  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=           ' Sa: ', mask2=tmask, clinfo3='tra')
+      !
+   END SUBROUTINE tra_adv_ubs
+
+
+   SUBROUTINE tra_adv_ztvd( kt, pwn, zttrd, zstrd )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_ztvd  ***
+      !! 
+      !! **  Purpose :   Compute the now trend due to total advection of 
+      !!       tracers and add it to the general trend of tracer equations
+      !!
+      !! **  Method  :   TVD scheme, i.e. 2nd order centered scheme with
+      !!       corrected flux (monotonic correction)
+      !!       note: - this advection scheme needs a leap-frog time scheme
+      !!
+      !! ** Action : - update (ta,sa) with the now advective tracer trends
+      !!             - save the trends in (ztrdt,ztrds) ('key_trdtra')
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in)                         ::   kt             ! ocean time-step
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   pwn            ! verical effective velocity
+      REAL(wp), INTENT(in), DIMENSION(jpi,jpj,jpk) ::   zttrd, zstrd   ! lateral advective trends on T & S 
+      !!
+      INTEGER  ::   ji, jj, jk              ! dummy loop indices
+      REAL(wp) ::   z2dtt, zbtr, zew, z2    ! temporary scalar  
+      REAL(wp) ::   ztak, zfp_wk            !    "         "
+      REAL(wp) ::   zsak, zfm_wk            !    "         "
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zti, ztw   ! temporary 3D workspace
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zsi, zsw   !    "              "
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_adv_ztvd : vertical TVD advection scheme'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+      ENDIF
+
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;    z2 = 1.
+      ELSE                                        ;    z2 = 2.
+      ENDIF
+
+      !  Bottom value : flux set to zero
+      ! --------------
+      ztw(:,:,jpk) = 0.e0   ;   zsw(:,:,jpk) = 0.e0
+      zti  (:,:,:) = 0.e0   ;   zsi  (:,:,:) = 0.e0
+
+
+      !  upstream advection with initial mass fluxes & intermediate update
+      ! -------------------------------------------------------------------
+      ! Surface value
+      IF( lk_dynspg_rl ) THEN                           ! rigid lid : flux set to zero
+         ztw(:,:,1) = 0.e0
+         zsw(:,:,1) = 0.e0
+      ELSE                                              ! free surface
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zew = e1t(ji,jj) * e2t(ji,jj) * pwn(ji,jj,1)
+               ztw(ji,jj,1) = zew * tb(ji,jj,1)
+               zsw(ji,jj,1) = zew * sb(ji,jj,1)
+            END DO
+         END DO
+      ENDIF
+
+      ! Interior value
+      DO jk = 2, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zew = 0.5 * e1t(ji,jj) * e2t(ji,jj) * pwn(ji,jj,jk)
+               zfp_wk = zew + ABS( zew )
+               zfm_wk = zew - ABS( zew )
+               ztw(ji,jj,jk) = zfp_wk * tb(ji,jj,jk) + zfm_wk * tb(ji,jj,jk-1)
+               zsw(ji,jj,jk) = zfp_wk * sb(ji,jj,jk) + zfm_wk * sb(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+
+      ! update and guess with monotonic sheme
+      DO jk = 1, jpkm1
+         z2dtt = z2 * rdttra(jk)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbtr = 1./ ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+               ztak = - ( ztw(ji,jj,jk) - ztw(ji,jj,jk+1) ) * zbtr
+               zsak = - ( zsw(ji,jj,jk) - zsw(ji,jj,jk+1) ) * zbtr
+               ta(ji,jj,jk) =  ta(ji,jj,jk) + ztak
+               sa(ji,jj,jk) =  sa(ji,jj,jk) + zsak 
+               zti (ji,jj,jk) = ( tb(ji,jj,jk) + z2dtt * ( ztak + zttrd(ji,jj,jk) ) ) * tmask(ji,jj,jk)
+               zsi (ji,jj,jk) = ( sb(ji,jj,jk) + z2dtt * ( zsak + zstrd(ji,jj,jk) ) ) * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! Lateral boundary conditions on zti, zsi   (unchanged sign)
+      CALL lbc_lnk( zti, 'T', 1. )
+      CALL lbc_lnk( zsi, 'T', 1. )
+
+
+      !  antidiffusive flux : high order minus low order
+      ! -------------------------------------------------      
+      ! Surface value
+      ztw(:,:,1) = 0.e0   ;   zsw(:,:,1) = 0.e0
+
+      ! Interior value
+      DO jk = 2, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zew = 0.5 * e1t(ji,jj) * e2t(ji,jj) * pwn(ji,jj,jk)
+               ztw(ji,jj,jk) = zew * ( tn(ji,jj,jk) + tn(ji,jj,jk-1) ) - ztw(ji,jj,jk)
+               zsw(ji,jj,jk) = zew * ( sn(ji,jj,jk) + sn(ji,jj,jk-1) ) - zsw(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      !  monotonicity algorithm
+      ! ------------------------
+      CALL nonosc_z( tb, ztw, zti, z2 )
+      CALL nonosc_z( sb, zsw, zsi, z2 )
+
+
+      !  final trend with corrected fluxes
+      ! -----------------------------------
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.  
+               zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+               ! k- vertical advective trends
+               ztak = - ( ztw(ji,jj,jk) - ztw(ji,jj,jk+1) ) * zbtr
+               zsak = - ( zsw(ji,jj,jk) - zsw(ji,jj,jk+1) ) * zbtr
+               ! add them to the general tracer trends
+               ta(ji,jj,jk) = ta(ji,jj,jk) + ztak
+               sa(ji,jj,jk) = sa(ji,jj,jk) + zsak
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE tra_adv_ztvd
+
+
+   SUBROUTINE nonosc_z( pbef, pcc, paft, prdt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE nonosc_z  ***
+      !!     
+      !! **  Purpose :   compute monotonic tracer fluxes from the upstream 
+      !!       scheme and the before field by a nonoscillatory algorithm 
+      !!
+      !! **  Method  :   ... ???
+      !!       warning : pbef and paft must be masked, but the boundaries
+      !!       conditions on the fluxes are not necessary zalezak (1979)
+      !!       drange (1995) multi-dimensional forward-in-time and upstream-
+      !!       in-space based differencing for fluid
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in   )                          ::   prdt   ! ???
+      REAL(wp), INTENT(inout), DIMENSION (jpi,jpj,jpk) ::   pbef   ! before field
+      REAL(wp), INTENT(inout), DIMENSION (jpi,jpj,jpk) ::   paft   ! after field
+      REAL(wp), INTENT(inout), DIMENSION (jpi,jpj,jpk) ::   pcc    ! monotonic flux in the k direction
+      !!
+      INTEGER  ::   ji, jj, jk               ! dummy loop indices
+      INTEGER  ::   ikm1
+      REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zrtrn, z2dtt
+      REAL(wp), DIMENSION (jpi,jpj,jpk) ::   zbetup, zbetdo
+      !!----------------------------------------------------------------------
+
+      zbig = 1.e+40
+      zrtrn = 1.e-15
+      zbetup(:,:,:) = 0.e0   ;   zbetdo(:,:,:) = 0.e0
+
+      ! Search local extrema
+      ! --------------------
+      ! large negative value (-zbig) inside land
+      pbef(:,:,:) = pbef(:,:,:) * tmask(:,:,:) - zbig * ( 1.e0 - tmask(:,:,:) )
+      paft(:,:,:) = paft(:,:,:) * tmask(:,:,:) - zbig * ( 1.e0 - tmask(:,:,:) )
+      ! search maximum in neighbourhood
+      DO jk = 1, jpkm1
+         ikm1 = MAX(jk-1,1)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbetup(ji,jj,jk) = MAX(  pbef(ji  ,jj  ,jk  ), paft(ji  ,jj  ,jk  ),   &
+                  &                     pbef(ji  ,jj  ,ikm1), pbef(ji  ,jj  ,jk+1),   &
+                  &                     paft(ji  ,jj  ,ikm1), paft(ji  ,jj  ,jk+1)  )
+            END DO
+         END DO
+      END DO
+      ! large positive value (+zbig) inside land
+      pbef(:,:,:) = pbef(:,:,:) * tmask(:,:,:) + zbig * ( 1.e0 - tmask(:,:,:) )
+      paft(:,:,:) = paft(:,:,:) * tmask(:,:,:) + zbig * ( 1.e0 - tmask(:,:,:) )
+      ! search minimum in neighbourhood
+      DO jk = 1, jpkm1
+         ikm1 = MAX(jk-1,1)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zbetdo(ji,jj,jk) = MIN(  pbef(ji  ,jj  ,jk  ), paft(ji  ,jj  ,jk  ),   &
+                  &                     pbef(ji  ,jj  ,ikm1), pbef(ji  ,jj  ,jk+1),   &
+                  &                     paft(ji  ,jj  ,ikm1), paft(ji  ,jj  ,jk+1)  )
+            END DO
+         END DO
+      END DO
+
+      ! restore masked values to zero
+      pbef(:,:,:) = pbef(:,:,:) * tmask(:,:,:)
+      paft(:,:,:) = paft(:,:,:) * tmask(:,:,:)
+ 
+
+      ! 2. Positive and negative part of fluxes and beta terms
+      ! ------------------------------------------------------
+
+      DO jk = 1, jpkm1
+         z2dtt = prdt * rdttra(jk)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! positive & negative part of the flux
+               zpos = MAX( 0., pcc(ji  ,jj  ,jk+1) ) - MIN( 0., pcc(ji  ,jj  ,jk  ) )
+               zneg = MAX( 0., pcc(ji  ,jj  ,jk  ) ) - MIN( 0., pcc(ji  ,jj  ,jk+1) )
+               ! up & down beta terms
+               zbt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) / z2dtt
+               zbetup(ji,jj,jk) = ( zbetup(ji,jj,jk) - paft(ji,jj,jk) ) / (zpos+zrtrn) * zbt
+               zbetdo(ji,jj,jk) = ( paft(ji,jj,jk) - zbetdo(ji,jj,jk) ) / (zneg+zrtrn) * zbt
+            END DO
+         END DO
+      END DO
+
+      ! monotonic flux in the k direction, i.e. pcc
+      ! -------------------------------------------
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+
+               za = MIN( 1., zbetdo(ji,jj,jk), zbetup(ji,jj,jk-1) )
+               zb = MIN( 1., zbetup(ji,jj,jk), zbetdo(ji,jj,jk-1) )
+               zc = 0.5 * ( 1.e0 + SIGN( 1.e0, pcc(ji,jj,jk) ) )
+               pcc(ji,jj,jk) = pcc(ji,jj,jk) * ( zc * za + ( 1.e0 - zc) * zb )
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE nonosc_z
+
+   !!======================================================================
+END MODULE traadv_ubs
Index: trunk/NEMO/OPA_SRC/TRA/trabbc.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 503)
@@ -4,4 +4,8 @@
    !! Ocean active tracers:  bottom boundary condition
    !!==============================================================================
+   !! History :  8.1  ! 99-10 (G. Madec)  original code
+   !!            8.5  ! 02-08 (G. Madec)  free form + modules
+   !!            8.5  ! 02-11 (A. Bozec)  tra_bbc_init: original code
+   !!----------------------------------------------------------------------
 #if   defined key_trabbc   ||   defined key_esopa
    !!----------------------------------------------------------------------
@@ -15,4 +19,6 @@
    USE dom_oce         ! ocean space and time domain
    USE phycst          ! physical constants
+   USE trdmod          ! ocean trends 
+   USE trdmod_oce      ! ocean variables trends
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
@@ -21,5 +27,4 @@
    PRIVATE
 
-   !! * Accessibility
    PUBLIC tra_bbc          ! routine called by step.F90
 
@@ -27,22 +32,18 @@
    LOGICAL, PUBLIC, PARAMETER ::   lk_trabbc = .TRUE.   !: bbc flag
 
-   !! * Module variables
-   INTEGER ::                       & !!! ** bbc namelist (nambbc) **
-      ngeo_flux = 1                    ! Geothermal flux (0:no flux, 1:constant flux,
-      !                                !                  2:read in file )
-   REAL(wp) ::                      & !!! ** bbc namlist **
-      ngeo_flux_const = 86.4e-3        ! Constant value of geothermal heat flux
-
-   INTEGER, DIMENSION(jpi,jpj) ::   &
-      nbotlevt                         ! ocean bottom level index at T-pt
-   REAL(wp), DIMENSION(jpi,jpj) ::  &
-      qgh_trd                          ! geothermal heating trend
+   !!* Namelist nambbc: bottom boundary condition
+   INTEGER  ::   ngeo_flux       = 1            ! Geothermal flux (0:no flux, 1:constant flux, 2:read in file )
+   REAL(wp) ::   ngeo_flux_const = 86.4e-3      ! Constant value of geothermal heat flux
+   NAMELIST/nambbc/ngeo_flux, ngeo_flux_const 
+
+   INTEGER , DIMENSION(jpi,jpj) ::   nbotlevt   ! ocean bottom level index at T-pt
+   REAL(wp), DIMENSION(jpi,jpj) ::   qgh_trd    ! geothermal heating trend
  
    !! * Substitutions
 #  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
-   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!  OPA 9.0 , LOCEAN-IPSL (2006) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -68,31 +69,30 @@
       !!                the ocean bottom boundary condition
       !!
-      !! References :
-      !!      Stein, C. A., and S. Stein, 1992, Nature, 359, 123-129.
-      !!
-      !! History :
-      !!   8.1  !  99-10  (G. Madec)  original code
-      !!   8.5  !  02-08  (G. Madec)  free form + modules
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt    ! ocean time-step index
-
-      !! * Local declarations
+      !! References : Stein, C. A., and S. Stein, 1992, Nature, 359, 123-129.
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   ztrdt => ua   ! use ua as 3D workspace   
+      USE oce, ONLY :   ztrds => va   ! use va as 3D workspace   
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
 #if defined key_vectopt_loop   &&   ! defined key_mpp_omp
-      INTEGER ::   ji                  ! dummy loop indices
-#else
-      INTEGER ::   ji, jj              ! dummy loop indices
-#endif
-      !!----------------------------------------------------------------------
-
-      ! 0. Initialization
-      IF( kt == nit000 )   CALL tra_bbc_init
-
-      ! 1. Add the geothermal heat flux trend on temperature
+      INTEGER ::   ji       ! dummy loop indices
+#else
+      INTEGER ::   ji, jj   ! dummy loop indices
+#endif
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL tra_bbc_init      ! Initialization
+
+      IF( l_trdtra )   THEN         ! Save ta and sa trends
+         ztrdt(:,:,:) = ta(:,:,:) 
+         ztrds(:,:,:) = 0.e0
+      ENDIF
+
+      ! Add the geothermal heat flux trend on temperature
 
       SELECT CASE ( ngeo_flux )
-
+      !
       CASE ( 1:2 )                !  geothermal heat flux
-
 #if defined key_vectopt_loop   &&   ! defined key_mpp_omp
          DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
@@ -106,11 +106,13 @@
          END DO
 #endif
-
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab3d_1=ta, clinfo1=' bbc  - Ta: ', mask1=tmask, clinfo3='tra-ta')
+      END SELECT
+
+      IF( l_trdtra ) THEN        ! Save the geothermal heat flux trend for diagnostics
+         ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
+         CALL trd_mod( ztrdt, ztrds, jptra_trd_bbc, 'TRA', kt )
       ENDIF
-
-      END SELECT
-
+      !
+      IF(ln_ctl)   CALL prt_ctl(tab3d_1=ta, clinfo1=' bbc  - Ta: ', mask1=tmask, clinfo3='tra-ta')
+      !
    END SUBROUTINE tra_bbc
 
@@ -132,23 +134,15 @@
       !! ** Action  : - compute the heat geothermal trend qgh_trd
       !!              - compute the bottom ocean level nbotlevt
-      !!
-      !! history :
-      !!  8.5  ! 02-11 (A. Bozec) original code
-      !!----------------------------------------------------------------------
-      !! * Modules used
+      !!----------------------------------------------------------------------
       USE iom
-
-      !! * local declarations
+      !!
       INTEGER  ::   ji, jj              ! dummy loop indices
       INTEGER  ::   inum                ! temporary logical unit
-
-      NAMELIST/nambbc/ngeo_flux, ngeo_flux_const 
-      !!----------------------------------------------------------------------
-
-      ! Read Namelist nambbc : bottom momentum boundary condition
-      REWIND ( numnam )
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )              ! Read Namelist nambbc : bottom momentum boundary condition
       READ   ( numnam, nambbc )
 
-      ! Control print
+      !                              ! Control print
       IF(lwp) WRITE(numout,*)
       IF(lwp) WRITE(numout,*) 'tra_bbc : tempearture Bottom Boundary Condition (bbc)'
@@ -160,6 +154,5 @@
       IF(lwp) WRITE(numout,*)
 
-      ! level of the ocean bottom at T-point
-
+      !                              ! level of the ocean bottom at T-point
       DO jj = 1, jpj
          DO ji = 1, jpi
@@ -168,29 +161,29 @@
       END DO
 
-      ! initialization of geothermal heat flux
-
-      SELECT CASE ( ngeo_flux )
-
+
+      SELECT CASE ( ngeo_flux )      ! initialization of geothermal heat flux
+      !
       CASE ( 0 )                ! no geothermal heat flux
          IF(lwp) WRITE(numout,*)
          IF(lwp) WRITE(numout,*) '             *** no geothermal heat flux'
-
+         !
       CASE ( 1 )                ! constant flux
          IF(lwp) WRITE(numout,*) '             *** constant heat flux  =   ', ngeo_flux_const
          qgh_trd(:,:) = ngeo_flux_const
-
+         !
       CASE ( 2 )                ! variable geothermal heat flux
          ! read the geothermal fluxes in mW/m2
-
+         !
          IF(lwp) WRITE(numout,*) '             *** variable geothermal heat flux'
          CALL iom_open ( 'geothermal_heating.nc', inum )
          CALL iom_get ( inum, jpdom_data, 'heatflow', qgh_trd )
          CALL iom_close (inum)
-
+         !
          qgh_trd(:,:) = qgh_trd(:,:) * 1.e-3 ! conversion in W/m2
-
+         !
       CASE DEFAULT
          WRITE(ctmp1,*) '     bad flag value for ngeo_flux = ', ngeo_flux
          CALL ctl_stop( ctmp1 )
+         !
       END SELECT
 
@@ -198,7 +191,6 @@
 
       SELECT CASE ( ngeo_flux )
-
+      !
       CASE ( 1:2 )                !  geothermal heat flux
-
 #if defined key_vectopt_loop   &&   ! defined key_mpp_omp
          DO ji = 1, jpij   ! vector opt. (forced unrolling)
@@ -212,7 +204,6 @@
          END DO
 #endif
-
       END SELECT
-
+      !
    END SUBROUTINE tra_bbc_init
 
Index: trunk/NEMO/OPA_SRC/TRA/trabbl.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 503)
@@ -4,8 +4,13 @@
    !! Ocean physics :  advective and/or diffusive bottom boundary layer scheme
    !!==============================================================================
+   !! History :  8.0  !  96-06  (L. Mortier)  Original code
+   !!            8.0  !  97-11  (G. Madec)  Optimization
+   !!            8.5  !  02-08  (G. Madec)  free form + modules
+   !!----------------------------------------------------------------------
 #if   defined key_trabbl_dif   ||   defined key_trabbl_adv   || defined key_esopa
    !!----------------------------------------------------------------------
    !!   'key_trabbl_dif'   or            diffusive bottom boundary layer
    !!   'key_trabbl_adv'                 advective bottom boundary layer
+   !!----------------------------------------------------------------------
    !!----------------------------------------------------------------------
    !!   tra_bbl_dif  : update the active tracer trends due to the bottom
@@ -15,47 +20,39 @@
    !!   tra_bbl_init : initialization, namlist read, parameters control
    !!----------------------------------------------------------------------
-   !! * Modules used
-   USE oce                  ! ocean dynamics and active tracers
-   USE dom_oce              ! ocean space and time domain
-   USE trdmod_oce           ! ocean variables trends
-   USE in_out_manager       ! I/O manager
-   USE lbclnk               ! ocean lateral boundary conditions
-   USE prtctl               ! Print control
+   USE oce                ! ocean dynamics and active tracers
+   USE dom_oce            ! ocean space and time domain
+   USE trdmod             ! ocean active tracers trends
+   USE trdmod_oce         ! ocean variables trends
+   USE in_out_manager     ! I/O manager
+   USE lbclnk             ! ocean lateral boundary conditions
+   USE prtctl             ! Print control
 
    IMPLICIT NONE
    PRIVATE
 
-   !! * Routine accessibility
    PUBLIC tra_bbl_dif    ! routine called by step.F90
    PUBLIC tra_bbl_adv    ! routine called by step.F90
 
-   !! * Shared module variables
-   REAL(wp), PUBLIC ::            &  !!: * bbl namelist *
-      atrbbl = 1.e+3                  !: lateral coeff. for bottom boundary 
-      !                               !  layer scheme (m2/s) 
+   !!* Namelist nambbl: bottom boundary layer
+   REAL(wp), PUBLIC ::   atrbbl = 1.e+3   !: lateral coeff. for bottom boundary layer scheme (m2/s)
+   NAMELIST/nambbl/ atrbbl
+
 # if defined key_trabbl_dif
-   LOGICAL, PUBLIC, PARAMETER ::   &  !:
-      lk_trabbl_dif = .TRUE.          !: diffusive bottom boundary layer flag
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trabbl_dif = .TRUE.          !: diffusive bottom boundary layer flag
 # else
-   LOGICAL, PUBLIC, PARAMETER ::   &  !:
-      lk_trabbl_dif = .FALSE.         !: diffusive bottom boundary layer flag
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trabbl_dif = .FALSE.         !: diffusive bottom boundary layer flag
 # endif
 
 # if defined key_trabbl_adv
-   LOGICAL, PUBLIC, PARAMETER ::    &  !:
-      lk_trabbl_adv = .TRUE.   !: advective bottom boundary layer flag
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &  !:
-       u_bbl, v_bbl,  &  !: velocity involved in exhanges in the advective BBL
-       w_bbl             !: vertical increment of velocity due to advective BBL
-       !                 !  only affect tracer vertical advection
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trabbl_adv = .TRUE.   !: advective bottom boundary layer flag
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   u_bbl      !: 3 components of the velocity
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   v_bbl      !: associated with advective BBL
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   w_bbl      !: (only affect tracer)
 # else
-   LOGICAL, PUBLIC, PARAMETER ::    &  !:
-      lk_trabbl_adv = .FALSE.  !: advective bottom boundary layer flag
+   LOGICAL, PUBLIC, PARAMETER ::   lk_trabbl_adv = .FALSE.  !: advective bottom boundary layer flag
 # endif
 
-   !! * Module variables
-   INTEGER, DIMENSION(jpi,jpj) ::   &  !:
-      mbkt,           &   ! vertical index of the bottom ocean T-level
-      mbku, mbkv          ! vertical index of the bottom ocean U/V-level
+   INTEGER, DIMENSION(jpi,jpj) ::   mbkt          ! vertical index of the bottom ocean T-level
+   INTEGER, DIMENSION(jpi,jpj) ::   mbku, mbkv    ! vertical index of the bottom ocean U/V-level
 
    !! * Substitutions
@@ -63,7 +60,7 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -102,39 +99,28 @@
       !! ** Action  : - update (ta,sa) at the bottom level with the bottom
       !!                boundary layer trend
-      !!              - save the trends in tldfbbl/sldfbbl ('key_trdtra')
-      !!
-      !! References :
-      !!     Beckmann, A., and R. Doscher, 1997, J. Phys.Oceanogr., 581-591.
-      !!
-      !! History :
-      !!   8.0  !  96-06  (L. Mortier)  Original code
-      !!   8.0  !  97-11  (G. Madec)  Optimization
-      !!   8.5  !  02-08  (G. Madec)  free form + modules
-      !!   9.0  !  04-08  (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------
-      !! * Modules used     
-      USE oce, ONLY :    ztdta => ua,     & ! use ua as 3D workspace   
-                         ztdsa => va        ! use va as 3D workspace   
-      USE eosbn2                            ! equation of state
-
-      !! * Arguments 
-      INTEGER, INTENT( in ) ::   kt         ! ocean time-step
-
-      !! * Local declarations
-      INTEGER ::   ji, jj                   ! dummy loop indices
-      INTEGER ::   ik
-      INTEGER ::   ii0, ii1, ij0, ij1       ! temporary integers
+      !!              - save the trends in ztrdt/ztrds ('key_trdtra')
+      !!
+      !! References : Beckmann, A., and R. Doscher, 1997, J. Phys.Oceanogr., 581-591.
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   ztrdt => ua   ! use ua as 3D workspace   
+      USE oce, ONLY :   ztrds => va   ! use va as 3D workspace   
+      USE eosbn2                      ! equation of state
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step
+      !!
+      INTEGER  ::   ji, jj                   ! dummy loop indices
+      INTEGER  ::   ik
+      INTEGER  ::   ii0, ii1, ij0, ij1       ! temporary integers
       INTEGER  ::   iku1, iku2, ikv1,ikv2   ! temporary intergers
       REAL(wp) ::   ze3u, ze3v              ! temporary scalars
-      INTEGER ::   iku, ikv
+      INTEGER  ::   iku, ikv
       REAL(wp) ::   &
          zsign, zt, zs, zh, zalbet,      &  ! temporary scalars
          zgdrho, zbtr, zta, zsa
       REAL(wp), DIMENSION(jpi,jpj) ::    &
-        zki, zkj, zkw, zkx, zky, zkz,    &  ! temporary workspace arrays
+        zki, zkj, zkw, zkx, zky, zkz,    &  ! 2D workspace arrays
         ztnb, zsnb, zdep,                &
         ztbb, zsbb, zahu, zahv
-      REAL(wp) ::   &
-         fsalbt, pft, pfs, pfh              ! statement function
+      REAL(wp) ::    fsalbt, pft, pfs, pfh   ! statement function
       !!----------------------------------------------------------------------
       ! ratio alpha/beta
@@ -161,8 +147,7 @@
       IF( kt == nit000 )   CALL tra_bbl_init
 
-      ! Save ta and sa trends
-      IF( l_trdtra )   THEN
-         ztdta(:,:,:) = ta(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) 
+      IF( l_trdtra )   THEN         ! Save ta and sa trends
+         ztrdt(:,:,:) = ta(:,:,:) 
+         ztrds(:,:,:) = sa(:,:,:) 
       ENDIF
 
@@ -170,5 +155,4 @@
       ! -----------------------------------------------------------------
       ! mbathy= number of w-level, minimum value=1 (cf dommsk.F)
-
 #  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
       jj = 1
@@ -387,5 +371,5 @@
 
       IF( cp_cfg == "orca" ) THEN
-
+         !
          SELECT CASE ( jp_cfg )
          !                                           ! =======================
@@ -397,5 +381,5 @@
             zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 4.e0 * zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
             zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 4.e0 * zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
-
+            !
             ! Red Sea enhancement of BBL
             ij0 =  88   ;   ij1 =  88
@@ -403,5 +387,5 @@
             zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 10.e0 * zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
             zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 10.e0 * zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
-
+            !
             !                                        ! =======================
          CASE ( 4 )                                  !  ORCA_R4 configuration
@@ -412,7 +396,7 @@
             zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 4.e0 * zkx( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
             zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) = 4.e0 * zky( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) )
-
+            !
          END SELECT
-
+      !
       ENDIF
 
@@ -439,29 +423,13 @@
       END DO
 
-      ! save the trends for diagnostic
-      ! BBL lateral diffusion tracers trends
-      IF( l_trdtra )   THEN
-#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
-         jj = 1
-         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
-#  else
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-#  endif
-            ik = max( mbathy(ji,jj)-1, 1 )
-            tldfbbl(ji,jj) = ta(ji,jj,ik) - ztdta(ji,jj,ik)
-            sldfbbl(ji,jj) = sa(ji,jj,ik) - ztdsa(ji,jj,ik)
-#  if ! defined key_vectopt_loop   ||   defined key_mpp_omp
-            END DO
-#  endif
-         END DO
-
+      IF( l_trdtra ) THEN      ! save the BBL lateral diffusion trends for diagnostic
+         ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
+         ztrds(:,:,:) = sa(:,:,:) - ztrds(:,:,:)
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_bbl, 'TRA', kt)
       ENDIF
 
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab3d_1=ta, clinfo1=' bbl  - Ta: ', mask1=tmask, &
-            &         tab3d_2=sa, clinfo2=' Sa: ', mask2=tmask, clinfo3='tra')
-      ENDIF
-
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' bbl  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+      !
    END SUBROUTINE tra_bbl_dif
 
@@ -489,37 +457,20 @@
       !! ** Method  :   Read the nambbl namelist and check the parameters
       !!      called by tra_bbl at the first timestep (nit000)
-      !!
-      !! History :
-      !!    8.5  !  02-08  (G. Madec)  Original code
-      !!----------------------------------------------------------------------
-      !! * Local declarations
+      !!----------------------------------------------------------------------
       INTEGER ::   ji, jj      ! dummy loop indices
       REAL(wp),  DIMENSION(jpi,jpj) :: zmbk  
-
-      NAMELIST/nambbl/ atrbbl
-      !!----------------------------------------------------------------------
-
-      ! Read Namelist nambbl : bottom boundary layer scheme
-      ! --------------------
-      REWIND ( numnam )
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )              ! Read Namelist nambbl : bottom boundary layer scheme
       READ   ( numnam, nambbl )
 
-
-      ! Parameter control and print
-      ! ---------------------------
-      IF(lwp) THEN
+      IF(lwp) THEN                   ! Parameter control and print
          WRITE(numout,*)
          WRITE(numout,*) 'tra_bbl_init : '
          WRITE(numout,*) '~~~~~~~~~~~~'
-         IF (lk_trabbl_dif ) THEN
-            WRITE(numout,*) '               * Diffusive Bottom Boundary Layer'
-         ENDIF 
-         IF( lk_trabbl_adv ) THEN
-            WRITE(numout,*) '               * Advective Bottom Boundary Layer'
-         ENDIF
-         WRITE(numout,*) '          Namelist nambbl : set bbl parameters'
-         WRITE(numout,*)
+         IF (lk_trabbl_dif )   WRITE(numout,*) '               * Diffusive Bottom Boundary Layer'
+         IF( lk_trabbl_adv )   WRITE(numout,*) '               * Advective Bottom Boundary Layer'
+         WRITE(numout,*) '       Namelist nambbl : set bbl parameters'
          WRITE(numout,*) '          bottom boundary layer coef.    atrbbl = ', atrbbl
-         WRITE(numout,*)
       ENDIF
  
@@ -545,8 +496,7 @@
 
 # if defined key_trabbl_adv
-      ! initialisation of w_bbl to zero
-      w_bbl(:,:,:) = 0.e0    
+      w_bbl(:,:,:) = 0.e0          ! initialisation of w_bbl to zero
 # endif
-
+      !
    END SUBROUTINE tra_bbl_init
 
@@ -558,10 +508,8 @@
    LOGICAL, PUBLIC, PARAMETER ::   lk_trabbl_adv = .FALSE.   !: adv  bbl flag
 CONTAINS
-   SUBROUTINE tra_bbl_dif (kt )              ! Empty routine
-      INTEGER, INTENT(in) :: kt
+   SUBROUTINE tra_bbl_dif( kt )              ! Empty routine
       WRITE(*,*) 'tra_bbl_dif: You should not have seen this print! error?', kt
    END SUBROUTINE tra_bbl_dif
-   SUBROUTINE tra_bbl_adv (kt )              ! Empty routine
-      INTEGER, INTENT(in) :: kt
+   SUBROUTINE tra_bbl_adv( kt )              ! Empty routine
       WRITE(*,*) 'tra_bbl_adv: You should not have seen this print! error?', kt
    END SUBROUTINE tra_bbl_adv
Index: trunk/NEMO/OPA_SRC/TRA/trabbl_adv.h90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/trabbl_adv.h90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/trabbl_adv.h90	(revision 503)
@@ -2,9 +2,12 @@
    !!                     ***  trabbl_adv.h90  ***
    !!----------------------------------------------------------------------
+   !! History :  8.5  !  02-12  (A. de Miranda, G. Madec)  Original Code 
+   !!            9.0  !  04-01  (A. de Miranda, G. Madec, J.M. Molines )
+   !!----------------------------------------------------------------------     
 
    !!----------------------------------------------------------------------
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -43,44 +46,29 @@
       !! ** Action  : - update (ta,sa) at the bottom level with the bottom
       !!                boundary layer trend
-      !!              - save the lateral diffusion trends in tldfbbl/sldfbbl ('key_trdtra')
-      !!              - save the horizontal advection trends in tladbbl/sladbbl ('key_trdtra')
       !!
-      !! References :
-      !!     Beckmann, A., and R. Doscher, 1997, J. Phys.Oceanogr., 581-591.
+      !! References : Beckmann, A., and R. Doscher, 1997, J. Phys.Oceanogr., 581-591.
+      !!----------------------------------------------------------------------     
+      USE eosbn2                      ! equation of state
+      USE oce, ONLY :   ztrdt => ua   ! use ua as 3D workspace   
+      USE oce, ONLY :   ztrds => va   ! use va as 3D workspace   
       !!
-      !! History :
-      !!   8.5  !  02-12  (A. de Miranda, G. Madec)  Original Code 
-      !!   9.0  !  04-01  (A. de Miranda, G. Madec, J.M. Molines )
-      !!   9.0  !  04-08  (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------     
-      !! * Modules used
-      USE eosbn2                           ! equation of state
-      USE oce, ONLY :    ztdta => ua,    & ! use ua as 3D workspace   
-                         ztdsa => va       ! use va as 3D workspace   
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt        ! ocean time-step 
-      
-      !! * Local declarations
-      INTEGER :: ji, jj, jk                ! dummy loop indices
-      INTEGER :: ik, iku, ikv              ! temporary integers
-
-      REAL(wp) ::   &
-         zsign, zt, zs, zh, zalbet,     &  ! temporary scalars
-         zgdrho, zbtr, zta, zsa            !    "         " 
-      REAL(wp), DIMENSION(jpi,jpj) ::   &
-         ztnb, zsnb, zdep, ztbb, zsbb
-      REAL(wp), DIMENSION(jpi,jpj) ::   &  ! temporary workspace arrays
-         zalphax, zwu, zunb,            &  !    "                  "
-         zalphay, zwv, zvnb,            &  !    "                  "
-         zwx, zwy, zww, zwz                !    "                  "
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         zhdivn                            ! temporary workspace arrays
-      REAL(wp) ::   &
-         zfui, zfvj, zbt, zsigna,       &  ! temporary scalars
-         iku1, iku2, ikv1, ikv2,        &  ! temporary scalars
-         ze3u,ze3v
-      REAL(wp) ::   &
-         fsalbt, pft, pfs, pfh             ! statement function
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step 
+      !!
+      INTEGER  ::   ji, jj, jk        ! dummy loop indices
+      INTEGER  ::   ik                ! temporary integers
+      INTEGER  ::   iku, iku1, iku2   !    "          "
+      INTEGER  ::   ikv, ikv1, ikv2   !    "          "
+      REAL(wp) ::   zsign, zh, zalbet     ! temporary scalars
+      REAL(wp) ::   zgdrho, zbtr          !    "         " 
+      REAL(wp) ::   zbt, zsigna           !    "         "
+      REAL(wp) ::   zfui, ze3u, zt, zta   !    "         "
+      REAL(wp) ::   zfvj, ze3v, zs, zsa   !    "         "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zalphax, zwu, zunb   ! temporary 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zalphay, zwv, zvnb   !    "             "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zwx, zwy, zww, zwz   !    "             "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   ztbb, zsbb           !    "             "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   ztnb, zsnb, zdep     !    "             "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhdivn               ! temporary 3D workspace
+      REAL(wp) ::   fsalbt, pft, pfs, pfh   ! statement function
       !!----------------------------------------------------------------------
       ! ratio alpha/beta
@@ -108,8 +96,7 @@
       IF( kt == nit000 )   CALL tra_bbl_init    ! initialization at first time-step
 
-      ! Save ta and sa trends
-      IF( l_trdtra )   THEN
-         ztdta(:,:,:) = ta(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) 
+      IF( l_trdtra )   THEN      ! Save ta and sa trends
+         ztrdt(:,:,:) = ta(:,:,:) 
+         ztrds(:,:,:) = sa(:,:,:) 
       ENDIF
 
@@ -146,48 +133,47 @@
 
       SELECT CASE ( neos )
-
+      !
       CASE ( 0 )               ! Jackett and McDougall (1994) formulation
-
+      !
       DO jj = 1, jpjm1
-        DO ji = 1, fs_jpim1   ! vector opt.
-      !   ... temperature, salinity anomalie and depth
-          zt = 0.5 * ( ztnb(ji,jj) + ztnb(ji+1,jj) )
-          zs = 0.5 * ( zsnb(ji,jj) + zsnb(ji+1,jj) ) - 35.0
-          zh = 0.5 * ( zdep(ji,jj) + zdep(ji+1,jj) )
-      !   ... masked ratio alpha/beta
-          zalbet = fsalbt( zt, zs, zh ) * umask(ji,jj,1)
-      !   ... local density gradient along i-bathymetric slope
-          zgdrho = zalbet * ( ztnb(ji+1,jj) - ztnb(ji,jj) )   &
-             &       -      ( zsnb(ji+1,jj) - zsnb(ji,jj) )
-          zgdrho = zgdrho * umask(ji,jj,1)
-      !   ... sign of local i-gradient of density multiplied by the i-slope
-          zsign = SIGN( 0.5, -zgdrho     * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
-          zsigna= SIGN( 0.5, zunb(ji,jj) * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
-          zalphax(ji,jj)=( 0.5 + zsigna ) * ( 0.5 - zsign ) * umask(ji,jj,1)
-        END DO
-      END DO
-
+         DO ji = 1, fs_jpim1   ! vector opt.
+            !   ... temperature, salinity anomalie and depth
+            zt = 0.5 * ( ztnb(ji,jj) + ztnb(ji+1,jj) )
+            zs = 0.5 * ( zsnb(ji,jj) + zsnb(ji+1,jj) ) - 35.0
+            zh = 0.5 * ( zdep(ji,jj) + zdep(ji+1,jj) )
+            !   ... masked ratio alpha/beta
+            zalbet = fsalbt( zt, zs, zh ) * umask(ji,jj,1)
+            !   ... local density gradient along i-bathymetric slope
+            zgdrho = zalbet * ( ztnb(ji+1,jj) - ztnb(ji,jj) )   &
+               &       -      ( zsnb(ji+1,jj) - zsnb(ji,jj) )
+            zgdrho = zgdrho * umask(ji,jj,1)
+            !   ... sign of local i-gradient of density multiplied by the i-slope
+            zsign = SIGN( 0.5, -zgdrho     * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+            zsigna= SIGN( 0.5, zunb(ji,jj) * ( zdep(ji+1,jj) - zdep(ji,jj) ) )
+            zalphax(ji,jj)=( 0.5 + zsigna ) * ( 0.5 - zsign ) * umask(ji,jj,1)
+         END DO
+      END DO
+      !
       DO jj = 1, jpjm1
-        DO ji = 1, fs_jpim1   ! vector opt.
-      !   ... temperature, salinity anomalie and depth
-          zt = 0.5 * ( ztnb(ji,jj+1) + ztnb(ji,jj) )
-          zs = 0.5 * ( zsnb(ji,jj+1) + zsnb(ji,jj) ) - 35.0
-          zh = 0.5 * ( zdep(ji,jj+1) + zdep(ji,jj) )
-      !   ... masked ratio alpha/beta
-          zalbet = fsalbt( zt, zs, zh ) * vmask(ji,jj,1)
-      !   ... local density gradient along j-bathymetric slope
-          zgdrho = zalbet * ( ztnb(ji,jj+1) - ztnb(ji,jj) )   &
-             &       -      ( zsnb(ji,jj+1) - zsnb(ji,jj) )
-          zgdrho = zgdrho*vmask(ji,jj,1)
-      !   ... sign of local j-gradient of density multiplied by the j-slope
-          zsign = SIGN( 0.5, -zgdrho     * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
-          zsigna= SIGN( 0.5, zvnb(ji,jj) * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
-          zalphay(ji,jj)=( 0.5 + zsigna ) * ( 0.5 - zsign ) * vmask(ji,jj,1)
-        END DO
-      END DO
-
-
+         DO ji = 1, fs_jpim1   ! vector opt.
+            !   ... temperature, salinity anomalie and depth
+            zt = 0.5 * ( ztnb(ji,jj+1) + ztnb(ji,jj) )
+            zs = 0.5 * ( zsnb(ji,jj+1) + zsnb(ji,jj) ) - 35.0
+            zh = 0.5 * ( zdep(ji,jj+1) + zdep(ji,jj) )
+            !   ... masked ratio alpha/beta
+            zalbet = fsalbt( zt, zs, zh ) * vmask(ji,jj,1)
+            !   ... local density gradient along j-bathymetric slope
+            zgdrho = zalbet * ( ztnb(ji,jj+1) - ztnb(ji,jj) )   &
+               &       -      ( zsnb(ji,jj+1) - zsnb(ji,jj) )
+            zgdrho = zgdrho*vmask(ji,jj,1)
+            !   ... sign of local j-gradient of density multiplied by the j-slope
+            zsign = SIGN( 0.5, -zgdrho     * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zsigna= SIGN( 0.5, zvnb(ji,jj) * ( zdep(ji,jj+1) - zdep(ji,jj) ) )
+            zalphay(ji,jj)=( 0.5 + zsigna ) * ( 0.5 - zsign ) * vmask(ji,jj,1)
+         END DO
+      END DO
+      !
       CASE ( 1 )               ! Linear formulation function of temperature only
-                               !
+      !
       DO jj = 1, jpjm1
          DO ji = 1, fs_jpim1   ! vector opt.
@@ -207,6 +193,7 @@
          END DO
       END DO
-
+      !
       CASE ( 2 )               ! Linear formulation function of temperature and salinity
+      !
       DO jj = 1, jpjm1
          DO ji = 1, fs_jpim1   ! vector opt.            
@@ -228,10 +215,9 @@
          END DO
       END DO
-
+      !
       CASE DEFAULT
-
          WRITE(ctmp1,*) '          bad flag value for neos = ', neos
          CALL ctl_stop( ctmp1 )
-
+         !
       END SELECT
 
@@ -359,26 +345,11 @@
       ! BBL lateral advection tracers trends
       IF( l_trdtra )   THEN
-#  if defined key_vectopt_loop   &&   ! defined key_mpp_omp
-         jj = 1
-         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
-#  else
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-#  endif
-            ik = mbkt(ji,jj)
-            tladbbl(ji,jj) = ta(ji,jj,ik) - ztdta(ji,jj,ik)
-            sladbbl(ji,jj) = sa(ji,jj,ik) - ztdsa(ji,jj,ik)
-#  if ! defined key_vectopt_loop   ||   defined key_mpp_omp
-            END DO
-#  endif
-         END DO
-
+         ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
+         ztrds(:,:,:) = sa(:,:,:) - ztrds(:,:,:)
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_bbl, 'TRA', kt)
       ENDIF
 
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab3d_1=ta, clinfo1=' bbl  - Ta: ', mask1=tmask, &
-            &         tab3d_2=sa, clinfo2=' Sa: ', mask2=tmask, clinfo3='tra')
-      ENDIF
-
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' bbl  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
 
       ! 6. Vertical advection velocities
@@ -475,5 +446,4 @@
       ! 7. compute additional vertical velocity to be used in t boxes
       ! -------------------------------------------------------------
-
       ! ... Computation from the bottom
       ! Note that w_bbl(:,:,jpk) has been set to 0 in tra_bbl_init
@@ -488,4 +458,4 @@
       ! Boundary condition on w_bbl   (unchanged sign)
       CALL lbc_lnk( w_bbl, 'W', 1. )
-
+      !
    END SUBROUTINE tra_bbl_adv
Index: trunk/NEMO/OPA_SRC/TRA/tradmp.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 503)
@@ -4,7 +4,17 @@
    !! Ocean physics: internal restoring trend on active tracers (T and S)
    !!======================================================================
+   !! History :  5.0  !  91-03  (O. Marti, G. Madec)  Original code
+   !!                 !  92-06  (M. Imbard)  doctor norme
+   !!                 !  96-01  (G. Madec)  statement function for e3
+   !!                 !  97-05  (G. Madec)  macro-tasked on jk-slab
+   !!                 !  98-07  (M. Imbard, G. Madec) ORCA version
+   !!            7.0  !  01-02  (M. Imbard)  cofdis, Original code
+   !!            8.1  !  01-02  (G. Madec, E. Durand)  cleaning
+   !!            8.5  !  02-08  (G. Madec, E. Durand)  free form + modules
+   !!----------------------------------------------------------------------
 #if   defined key_tradmp   ||   defined key_esopa
    !!----------------------------------------------------------------------
    !!   key_tradmp                                         internal damping
+   !!----------------------------------------------------------------------
    !!----------------------------------------------------------------------
    !!   tra_dmp      : update the tracer trend with the internal damping
@@ -14,5 +24,4 @@
    !!   cofdis       : compute the distance to the coastline
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain variables
@@ -31,27 +40,22 @@
    PRIVATE
 
-   !! * Routine accessibility
-   PUBLIC tra_dmp   ! routine called by step.F90
-
-   !! * Shared module variables
-   LOGICAL , PUBLIC &
+   PUBLIC tra_dmp      ! routine called by step.F90
+
 #if ! defined key_agrif
-   , PARAMETER  &
+   LOGICAL, PUBLIC, PARAMETER ::   lk_tradmp = .TRUE.     !: internal damping flag
+#else
+   LOGICAL, PUBLIC            ::   lk_tradmp = .TRUE.     !: internal damping flag
 #endif
-   ::   lk_tradmp = .TRUE.    !: internal damping flag
-
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &
-      strdmp,              &  ! damping salinity trend (psu/s)
-      resto                   ! restoring coeff. on T and S (s-1)
-
-   !! * Module variables
-   INTEGER  ::             & !!! * newtonian damping namelist (mandmp) *
-      ndmp   =   -1 ,      &  ! = 0/-1/'latitude' for damping over T and S
-      ndmpf  =    2 ,      &  ! = 1 create a damping.coeff NetCDF file 
-      nmldmp =    0           ! = 0/1/2 flag for damping in the mixed layer
-   REAL(wp) ::             & !!!  * newtonian damping namelist *
-      sdmp   =   50.,      &  ! surface time scale for internal damping (days)
-      bdmp   =  360.,      &  ! bottom time scale for internal damping (days)
-      hdmp   =  800.          ! depth of transition between sdmp and bdmp (meters)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   strdmp   !: damping salinity trend (psu/s)
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   resto    !: restoring coeff. on T and S (s-1)
+   
+   !!* newtonian damping namelist (mandmp) 
+   INTEGER  ::   ndmp   =   -1    ! = 0/-1/'latitude' for damping over T and S
+   INTEGER  ::   ndmpf  =    2    ! = 1 create a damping.coeff NetCDF file 
+   INTEGER  ::   nmldmp =    0    ! = 0/1/2 flag for damping in the mixed layer
+   REAL(wp) ::   sdmp   =   50.   ! surface time scale for internal damping (days)
+   REAL(wp) ::   bdmp   =  360.   ! bottom time scale for internal damping (days)
+   REAL(wp) ::   hdmp   =  800.   ! depth of transition between sdmp and bdmp (meters)
+   NAMELIST/namtdp/ ndmp, ndmpf, nmldmp, sdmp, bdmp, hdmp
 
    !! * Substitutions
@@ -59,7 +63,7 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -85,32 +89,19 @@
       !!                damping trends.
       !!              - save the trends in (ttrd,strd) ('key_trdtra')
-      !!
-      !! History :
-      !!   7.0  !         (G. Madec)  Original code
-      !!        !  96-01  (G. Madec) 
-      !!        !  97-05  (G. Madec)  macro-tasked on jk-slab
-      !!   8.5  !  02-08  (G. Madec)  free form + modules
-      !!   9.0  !  04-08  (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------
-      !! * Modules used     
-      USE oce, ONLY :    ztdta => ua,   & ! use ua as 3D workspace   
-                         ztdsa => va      ! use va as 3D workspace   
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
-
-      !! * Local declarations
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   ztrdt => ua   ! use ua as 3D workspace   
+      USE oce, ONLY :   ztrds => va   ! use va as 3D workspace   
+      !!
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
       INTEGER  ::   ji, jj, jk            ! dummy loop indices
       REAL(wp) ::   ztest, zta, zsa       ! temporary scalars
       !!----------------------------------------------------------------------
 
-      ! 0. Initialization (first time-step only)
-      !    --------------
-      IF( kt == nit000 ) CALL tra_dmp_init
-
-      ! Save ta and sa trends
-      IF( l_trdtra )   THEN
-         ztdta(:,:,:) = ta(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) 
+      IF( kt == nit000 )   CALL tra_dmp_init      ! Initialization
+
+      IF( l_trdtra )   THEN                       ! Save ta and sa trends
+         ztrdt(:,:,:) = ta(:,:,:) 
+         ztrds(:,:,:) = sa(:,:,:) 
       ENDIF
 
@@ -120,5 +111,5 @@
 
       SELECT CASE ( nmldmp )
-
+      !
       CASE( 0 )                ! newtonian damping throughout the water column
          DO jk = 1, jpkm1
@@ -135,5 +126,5 @@
             END DO
          END DO
-
+         !
       CASE ( 1 )                ! no damping in the turbocline (avt > 5 cm2/s)
          DO jk = 1, jpkm1
@@ -156,5 +147,5 @@
             END DO
          END DO
-
+         !
       CASE ( 2 )                ! no damping in the mixed layer 
          DO jk = 1, jpkm1
@@ -176,21 +167,16 @@
             END DO
          END DO
-
+         !
       END SELECT
 
-      ! save the trends for diagnostic
-      ! damping salinity trends
-      IF( l_trdtra )   THEN
-         ztdta(:,:,:) = ta(:,:,:) - ztdta(:,:,:)
-         ztdsa(:,:,:) = sa(:,:,:) - ztdsa(:,:,:)
-         CALL trd_mod(ztdta, ztdsa, jpttddoe, 'TRA', kt)
+      IF( l_trdtra )   THEN          ! save the damping tracer trends for diagnostic
+         ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
+         ztrds(:,:,:) = sa(:,:,:) - ztrds(:,:,:)
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_dmp, 'TRA', kt)
       ENDIF
-
-      IF(ln_ctl) THEN         ! print mean trends (used for debugging)
-         CALL prt_ctl(tab3d_1=ta, clinfo1=' dmp  - Ta: ', mask1=tmask, &
-            &         tab3d_2=sa, clinfo2=' Sa: ', mask2=tmask, clinfo3='tra')
-      ENDIF
-
-
+      !                              ! Control print
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' dmp  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+      !
    END SUBROUTINE tra_dmp
 
@@ -204,82 +190,50 @@
       !! ** Method  :   read the nammbf namelist and check the parameters
       !!      called by tra_dmp at the first timestep (nit000)
-      !!
-      !! History :
-      !!   8.5  !  02-08  (G. Madec)  Original code
-      !!----------------------------------------------------------------------
-      !! * Local declarations
-      NAMELIST/namtdp/ ndmp, ndmpf, nmldmp, sdmp, bdmp, hdmp
-      !!----------------------------------------------------------------------
-
-      ! Read Namelist namtdp : temperature and salinity damping term
-      ! --------------------
-      REWIND ( numnam )
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )                  ! Read Namelist namtdp : temperature and salinity damping term
       READ   ( numnam, namtdp )
       IF( lzoom )   nmldmp = 0           ! restoring to climatology at closed north or south boundaries
 
-      ! Parameter control and print
-      ! ---------------------------
-      IF(lwp) THEN
+      IF(lwp) THEN                       ! Namelist print
          WRITE(numout,*)
          WRITE(numout,*) 'tra_dmp : T and S newtonian damping'
          WRITE(numout,*) '~~~~~~~'
-         WRITE(numout,*) '          Namelist namtdp : set damping parameter'
-         WRITE(numout,*)
-         WRITE(numout,*) '             T and S damping option         ndmp   = ', ndmp
-         WRITE(numout,*) '             create a damping.coeff file    ndmpf  = ', ndmpf
-         WRITE(numout,*) '             mixed layer damping option     nmldmp = ', nmldmp, '(zoom: forced to 0)'
-         WRITE(numout,*) '             surface time scale (days)      sdmp   = ', sdmp
-         WRITE(numout,*) '             bottom time scale (days)       bdmp   = ', bdmp
-         WRITE(numout,*) '             depth of transition (meters)   hdmp   = ', hdmp
-         WRITE(numout,*)
+         WRITE(numout,*) '       Namelist namtdp : set damping parameter'
+         WRITE(numout,*) '          T and S damping option         ndmp   = ', ndmp
+         WRITE(numout,*) '          create a damping.coeff file    ndmpf  = ', ndmpf
+         WRITE(numout,*) '          mixed layer damping option     nmldmp = ', nmldmp, '(zoom: forced to 0)'
+         WRITE(numout,*) '          surface time scale (days)      sdmp   = ', sdmp
+         WRITE(numout,*) '          bottom time scale (days)       bdmp   = ', bdmp
+         WRITE(numout,*) '          depth of transition (meters)   hdmp   = ', hdmp
       ENDIF
 
       SELECT CASE ( ndmp )
-
-      CASE ( -1 )               ! ORCA: damping in Red & Med Seas only
-         IF(lwp) WRITE(numout,*) '          tracer damping in the Med & Red seas only'
-
-      CASE ( 1:90 )             ! Damping poleward of 'ndmp' degrees
-         IF(lwp) WRITE(numout,*) '          tracer damping poleward of', ndmp, ' degrees'
-
+      CASE (  -1  )   ;   IF(lwp) WRITE(numout,*) '          tracer damping in the Med & Red seas only'
+      CASE ( 1:90 )   ;   IF(lwp) WRITE(numout,*) '          tracer damping poleward of', ndmp, ' degrees'
       CASE DEFAULT
          WRITE(ctmp1,*) '          bad flag value for ndmp = ', ndmp
          CALL ctl_stop(ctmp1)
-
       END SELECT
 
-
       SELECT CASE ( nmldmp )
-
-      CASE ( 0 )                ! newtonian damping throughout the water column
-         IF(lwp) WRITE(numout,*) '          tracer damping throughout the water column'
-
-      CASE ( 1 )                ! no damping in the turbocline (avt > 5 cm2/s)
-         IF(lwp) WRITE(numout,*) '          no tracer damping in the turbocline'
-
-      CASE ( 2 )                ! no damping in the mixed layer 
-         IF(lwp) WRITE(numout,*) '          no tracer damping in the mixed layer'
-
+      CASE ( 0 )   ;   IF(lwp) WRITE(numout,*) '          tracer damping throughout the water column'
+      CASE ( 1 )   ;   IF(lwp) WRITE(numout,*) '          no tracer damping in the turbocline (avt > 5 cm2/s)'
+      CASE ( 2 )   ;   IF(lwp) WRITE(numout,*) '          no tracer damping in the mixed layer'
       CASE DEFAULT
          WRITE(ctmp1,*) '          bad flag value for nmldmp = ', nmldmp
          CALL ctl_stop(ctmp1)
-
       END SELECT
 
-      IF( .NOT.lk_dtasal .OR. .NOT.lk_dtatem ) &
-           &   CALL ctl_stop( '          no temperature and/or salinity data ', &
-           &                  '          define key_dtatem and key_dtasal' )
+      IF( .NOT.lk_dtasal .OR. .NOT.lk_dtatem )   &
+         &   CALL ctl_stop( 'no temperature and/or salinity data define key_dtatem and key_dtasal' )
 
       strdmp(:,:,:) = 0.e0       ! internal damping salinity trend (used in ocesbc)
 
-      ! Damping coefficients initialization
-      ! -----------------------------------
-
-      IF( lzoom ) THEN
-         CALL dtacof_zoom
-      ELSE
-         CALL dtacof
+      !                          ! Damping coefficients initialization
+      IF( lzoom ) THEN   ;   CALL dtacof_zoom
+      ELSE               ;   CALL dtacof
       ENDIF
-
+      !
    END SUBROUTINE tra_dmp_init
 
@@ -297,14 +251,8 @@
       !!
       !! ** Action  : - resto, the damping coeff. for T and S
-      !!
-      !! History :
-      !!   9.0  !  03-09  (G. Madec)  Original code
-      !!----------------------------------------------------------------------
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk, jn      ! dummy loop indices
-      REAL(wp) ::   &
-         zlat, zlat0, zlat1, zlat2     ! temporary scalar
-      REAL(wp), DIMENSION(6)  ::   &
-         zfact                         ! temporary workspace
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk, jn              ! dummy loop indices
+      REAL(wp) ::   zlat, zlat0, zlat1, zlat2   ! temporary scalar
+      REAL(wp), DIMENSION(6)  ::   zfact        ! temporary workspace
       !!----------------------------------------------------------------------
 
@@ -321,15 +269,13 @@
       ! damping along the forced closed boundary over 6 grid-points
       DO jn = 1, 6
-         IF( lzoom_w )   resto( mi0(jn+jpizoom):mi1(jn+jpizoom), : , : ) = zfact(jn) ! west  closed
-         IF( lzoom_s )   resto( : , mj0(jn+jpjzoom):mj1(jn+jpjzoom), : ) = zfact(jn) ! south closed 
-         IF( lzoom_e )   resto( mi0(jpiglo+jpizoom-1-jn):mi1(jpiglo+jpizoom-1-jn) , : , : ) &
-                       &              = zfact(jn)                                 ! east  closed 
-         IF( lzoom_n )   resto( : , mj0(jpjglo+jpjzoom-1-jn):mj1(jpjglo+jpjzoom-1-jn) , : ) &
-                       &              = zfact(jn)                                 ! north closed
+         IF( lzoom_w )   resto( mi0(jn+jpizoom):mi1(jn+jpizoom), : , : )                    = zfact(jn)   ! west  closed
+         IF( lzoom_s )   resto( : , mj0(jn+jpjzoom):mj1(jn+jpjzoom), : )                    = zfact(jn)   ! south closed 
+         IF( lzoom_e )   resto( mi0(jpiglo+jpizoom-1-jn):mi1(jpiglo+jpizoom-1-jn) , : , : ) = zfact(jn)   ! east  closed 
+         IF( lzoom_n )   resto( : , mj0(jpjglo+jpjzoom-1-jn):mj1(jpjglo+jpjzoom-1-jn) , : ) = zfact(jn)   ! north closed
       END DO
 
 
       IF( lzoom_arct .AND. lzoom_anta ) THEN
-
+         !
          ! ====================================================
          !  ORCA configuration : arctic zoom or antarctic zoom
@@ -364,11 +310,12 @@
             END DO
          END DO
-
+         !
       ENDIF
 
       ! ... Mask resto array
       resto(:,:,:) = resto(:,:,:) * tmask(:,:,:)
-
+      !
    END SUBROUTINE dtacof_zoom
+
 
    SUBROUTINE dtacof
@@ -383,34 +330,20 @@
       !!
       !! ** Action  : - resto, the damping coeff. for T and S
-      !!
-      !! History :
-      !!   5.0  !  91-03  (O. Marti, G. Madec)  Original code
-      !!        !  92-06  (M. Imbard)  doctor norme
-      !!        !  96-01  (G. Madec) statement function for e3
-      !!        !  98-07  (M. Imbard, G. Madec) ORCA version
-      !!        !  00-08  (G. Madec, D. Ludicone) 
-      !!----------------------------------------------------------------------
-      !! * Modules used
+      !!----------------------------------------------------------------------
       USE iom
       USE ioipsl
-
-      !! * Local declarations
+      !!
       INTEGER ::   ji, jj, jk     ! dummy loop indices
       INTEGER ::   itime
       INTEGER ::   ii0, ii1, ij0, ij1  !    "          "
-      INTEGER ::   &
-         idmp,     &  ! logical unit for file restoring damping term
-         icot         ! logical unit for file distance to the coast
+      INTEGER ::   idmp         ! logical unit for file restoring damping term
+      INTEGER ::   icot         ! logical unit for file distance to the coast
       CHARACTER (len=32) :: clname3
-      REAL(wp) ::   &
-         zdate0, zinfl, zlon,         & ! temporary scalars
-         zlat, zlat0, zlat1, zlat2,   & !    "         "
-         zsdmp, zbdmp                   !    "         "
-      REAL(wp), DIMENSION(jpk) ::   &
-         zhfac
-      REAL(wp), DIMENSION(jpi,jpj) ::   &
-         zmrs
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         zdct
+      REAL(wp) ::   zdate0, zinfl, zlon         ! temporary scalars
+      REAL(wp) ::   zlat, zlat0, zlat1, zlat2   !    "         "
+      REAL(wp) ::   zsdmp, zbdmp                !    "         "
+      REAL(wp), DIMENSION(jpk)         ::   zhfac
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zmrs
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdct
       !!----------------------------------------------------------------------
 
@@ -494,16 +427,12 @@
                DO ji = 1, jpi
                   zdct(ji,jj,jk) = MIN( zinfl, zdct(ji,jj,jk) )
-
                   !   ... Decrease the value in the vicinity of the coast
-                  resto(ji,jj,jk) = resto(ji,jj,1)*0.5   &
-                     &            * ( 1. - COS( rpi*zdct(ji,jj,jk)/zinfl) )
-
+                  resto(ji,jj,jk) = resto(ji,jj,1) * 0.5 * ( 1. - COS( rpi*zdct(ji,jj,jk)/zinfl) )
                   !   ... Vertical variation from zsdmp (sea surface) to zbdmp (bottom)
-                  resto(ji,jj,jk) = resto(ji,jj,jk)   &
-                     &            * ( zbdmp + (zsdmp-zbdmp)*EXP(-fsdept(ji,jj,jk)/hdmp) )
+                  resto(ji,jj,jk) = resto(ji,jj,jk)      * ( zbdmp + (zsdmp-zbdmp)*EXP(-fsdept(ji,jj,jk)/hdmp) )
                END DO
             END DO
          END DO
-
+         !
       ENDIF
 
@@ -524,5 +453,4 @@
          CASE ( 4 )                                  !  ORCA_R4 configuration 
             !                                        ! =======================
-
             ! Mediterranean Sea
             ij0 =  50   ;   ij1 =  56
@@ -539,9 +467,7 @@
                zhfac (jk) = 1./rday
             END DO
-
             !                                        ! =======================
          CASE ( 2 )                                  !  ORCA_R2 configuration 
             !                                        ! =======================
-
             ! Mediterranean Sea
             ij0 =  96   ;   ij1 = 110
@@ -576,9 +502,7 @@
                zhfac (jk) = 1./rday
             END DO
-
             !                                        ! =======================
          CASE ( 05 )                                 !  ORCA_R05 configuration
             !                                        ! =======================
-
             ! Mediterranean Sea
             ii0 = 568   ;   ii1 = 574 
@@ -608,10 +532,9 @@
                zhfac (jk) = ( zbdmp + (zsdmp-zbdmp) * EXP(-fsdept(1,1,jk)/hdmp) )
             END DO
-
             !                                       ! ========================
          CASE ( 025 )                               !  ORCA_R025 configuration 
             !                                       ! ========================
             CALL ctl_stop( ' Not yet implemented in ORCA_R025' )
-
+            !
          END SELECT
 
@@ -644,11 +567,11 @@
          CALL ymds2ju( 0     , 1      , 1      , 0.e0 , zdate0 )
          CALL restini( 'NONE', jpi    , jpj    , glamt, gphit,    &
-                       jpk   , gdept_0, clname3, itime, zdate0,   &
-                       rdt   , idmp, domain_id=nidom )
+            &          jpk   , gdept_0, clname3, itime, zdate0,   &
+            &          rdt   , idmp, domain_id=nidom )
          CALL restput( idmp, 'Resto', jpi, jpj, jpk,   &
-                       0   , resto  )
+            &          0   , resto  )
          CALL restclo( idmp )
       ENDIF
-
+      !
    END SUBROUTINE dtacof
 
@@ -673,32 +596,18 @@
       !! ** Action  : - pdct, distance to the coastline (argument)
       !!              - NetCDF file 'dist.coast.nc' 
-      !!        
-      !! History :
-      !!   7.0  !  01-02  (M. Imbard)  Original code
-      !!   8.1  !  01-02  (G. Madec, E. Durand)
-      !!   8.5  !  02-08  (G. Madec, E. Durand)  Free form, F90
-      !!----------------------------------------------------------------------
-      !! * Modules used
-      USE ioipsl
-
-      !! * Arguments
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out ) ::   &
-         pdct                     ! distance to the coastline
-
-      !! * local declarations
-      INTEGER :: ji, jj, jk, jl      ! dummy loop indices
-      INTEGER :: iju, ijt            ! temporary integers
-      INTEGER :: icoast, itime
-      INTEGER ::   &
-         icot         ! logical unit for file distance to the coast
-      LOGICAL, DIMENSION(jpi,jpj) ::   &
-         llcotu, llcotv, llcotf   ! ???
+      !!----------------------------------------------------------------------
+      USE ioipsl      ! IOipsl librairy
+      !!
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( out ) ::   pdct   ! distance to the coastline
+      !!
+      INTEGER ::   ji, jj, jk, jl      ! dummy loop indices
+      INTEGER ::   iju, ijt            ! temporary integers
+      INTEGER ::   icoast, itime
+      INTEGER ::   icot         ! logical unit for file distance to the coast
+      LOGICAL, DIMENSION(jpi,jpj) ::   llcotu, llcotv, llcotf   ! ???
       CHARACTER (len=32) ::   clname
       REAL(wp) ::   zdate0
-      REAL(wp), DIMENSION(jpi,jpj) ::   &
-         zxt, zyt, zzt,                 &  ! cartesian coordinates for T-points
-         zmask                             
-      REAL(wp), DIMENSION(3*jpi*jpj) ::   &
-         zxc, zyc, zzc, zdis      ! temporary workspace
+      REAL(wp), DIMENSION(jpi,jpj)   ::   zxt, zyt, zzt, zmask   ! cartesian coordinates for T-points
+      REAL(wp), DIMENSION(3*jpi*jpj) ::   zxc, zyc, zzc, zdis    ! temporary workspace
       !!----------------------------------------------------------------------
 
@@ -832,6 +741,6 @@
                   DO jl = 1, icoast
                      zdis(jl) = ( zxt(ji,jj) - zxc(jl) )**2   &
-                              + ( zyt(ji,jj) - zyc(jl) )**2   &
-                              + ( zzt(ji,jj) - zzc(jl) )**2
+                        &     + ( zyt(ji,jj) - zyc(jl) )**2   &
+                        &     + ( zzt(ji,jj) - zzc(jl) )**2
                   END DO
                   pdct(ji,jj,jk) = ra * SQRT( MINVAL( zdis(1:icoast) ) )
@@ -850,6 +759,6 @@
       CALL ymds2ju( 0     , 1      , 1     , 0.e0 , zdate0 )
       CALL restini( 'NONE', jpi    , jpj   , glamt, gphit ,   &
-                    jpk   , gdept_0, clname, itime, zdate0,   &
-                    rdt   , icot                         )
+         &          jpk   , gdept_0, clname, itime, zdate0,   &
+         &          rdt   , icot                         )
       CALL restput( icot, 'Tcoast', jpi, jpj, jpk, 0, pdct )
       CALL restclo( icot )
Index: trunk/NEMO/OPA_SRC/TRA/traldf.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/traldf.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/traldf.F90	(revision 503)
@@ -4,6 +4,7 @@
    !! Ocean Active tracers : lateral diffusive trends 
    !!=====================================================================
-   !! History :
-   !!   9.0  !  05-11  (G. Madec)  Original code
+   !! History :  9.0  ! 05-11 (G. Madec)  Original code
+   !!----------------------------------------------------------------------
+
    !!----------------------------------------------------------------------
    !!   tra_ldf     : update the tracer trend with the lateral diffusion
@@ -11,5 +12,4 @@
    !!       ldf_ano : compute lateral diffusion for constant T-S profiles
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
@@ -31,15 +31,10 @@
    PRIVATE
 
-   !! *  Routine accessibility
-   PUBLIC tra_ldf      ! called by step.F90 
-
-   !! * module variables
-   INTEGER ::                        & 
-      nldf = 0                         ! type of lateral diffusion used
-      !                                ! defined from ln_traldf_... namlist logicals)
+   PUBLIC   tra_ldf    ! called by step.F90 
+
+   INTEGER ::   nldf = 0   ! type of lateral diffusion used defined from ln_traldf_... namlist logicals)
 #if defined key_traldf_ano
-   REAL, DIMENSION(jpi,jpj,jpk) ::   &  
-      t0_ldf, s0_ldf                    ! lateral diffusion trends of T & S
-      !                                 ! for a constant vertical profile
+   REAL, DIMENSION(jpi,jpj,jpk) ::   t0_ldf, s0_ldf   ! lateral diffusion trends of T & S
+      !                                               ! for a constant vertical profile
 #endif
 
@@ -47,7 +42,9 @@
 #  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
-   !!---------------------------------------------------------------------------------
-   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
-   !!---------------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 
 CONTAINS
@@ -60,13 +57,10 @@
       !!
       !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-
-      !! * local declarations
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         ztrdt, ztrds                         ! 3D temporary workspace
-      !!----------------------------------------------------------------------
-
-      IF( kt == nit000 )   CALL ldf_ctl      ! initialisation & control of options
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdt, ztrds   ! 3D temporary workspace
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000 )   CALL ldf_ctl          ! initialisation & control of options
 
       IF( l_trdtra )   THEN                      ! temporary save of ta and sa trends
@@ -76,5 +70,10 @@
 
       SELECT CASE ( nldf )                       ! compute lateral mixing trend and add it to the general trend
-      CASE ( -1 )                                       ! esopa: test all possibility with control print
+      CASE ( 0 )   ;   CALL tra_ldf_lap   ( kt )      ! iso-level laplacian
+      CASE ( 1 )   ;   CALL tra_ldf_iso   ( kt )      ! rotated laplacian (except dk[ dk[.] ] part)
+      CASE ( 2 )   ;   CALL tra_ldf_bilap ( kt )      ! iso-level bilaplacian
+      CASE ( 3 )   ;   CALL tra_ldf_bilapg( kt )      ! s-coord. horizontal bilaplacian
+         !
+      CASE ( -1 )                                     ! esopa: test all possibility with control print
          CALL tra_ldf_lap    ( kt )
          CALL prt_ctl( tab3d_1=ta, clinfo1=' ldf0 - Ta: ', mask1=tmask,               &
@@ -89,32 +88,19 @@
          CALL prt_ctl( tab3d_1=ta, clinfo1=' ldf3 - Ta: ', mask1=tmask,               &
             &          tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
-
-      CASE ( 0 )                                       ! iso-level laplacian
-         CALL tra_ldf_lap    ( kt )
-      CASE ( 1 )                                       ! rotated laplacian (except dk[ dk[.] ] part)
-         CALL tra_ldf_iso    ( kt )
-      CASE ( 2 )                                       ! iso-level bilaplacian
-         CALL tra_ldf_bilap  ( kt )
-      CASE ( 3 )                                       ! s-coord. horizontal bilaplacian
-         CALL tra_ldf_bilapg ( kt )
       END SELECT
 
 #if defined key_traldf_ano
-      !                                          ! anomaly: substract the reference diffusivity
-      ta(:,:,:) = ta(:,:,:) - t0_ldf(:,:,:)
+      ta(:,:,:) = ta(:,:,:) - t0_ldf(:,:,:)      ! anomaly: substract the reference diffusivity
       sa(:,:,:) = sa(:,:,:) - s0_ldf(:,:,:)
 #endif
-
-      !                                          ! save the horizontal diffusive trends for further diagnostics
-      IF( l_trdtra )   THEN
+      IF( l_trdtra )   THEN                      ! save the horizontal diffusive trends for further diagnostics
          ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
          ztrds(:,:,:) = sa(:,:,:) - ztrds(:,:,:)
-         CALL trd_mod( ztrdt, ztrds, jpttdldf, 'TRA', kt )
-      ENDIF
-
+         CALL trd_mod( ztrdt, ztrds, jptra_trd_ldf, 'TRA', kt )
+      ENDIF
       !                                          ! print mean trends (used for debugging)
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' ldf  - Ta: ', mask1=tmask,               &
          &                       tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
-
+      !
    END SUBROUTINE tra_ldf
 
@@ -132,7 +118,5 @@
       !!      nldf ==  2   bilaplacian operator
       !!      nldf ==  3   Rotated bilaplacian
-      !!
-      !!----------------------------------------------------------------------
-      !! * Local declarations
+      !!----------------------------------------------------------------------
       INTEGER ::   ioptio, ierr         ! temporary integers 
 !      
@@ -150,28 +134,26 @@
 !     READ  ( numnam, nam_traldf )
 
-      IF(lwp) THEN
+      IF(lwp) THEN                    ! Namelist print
          WRITE(numout,*)
          WRITE(numout,*) 'tra:ldf_ctl : lateral tracer diffusive operator'
          WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*) '          Namelist nam_traldf : set lateral mixing parameters (type, direction, coefficients)'
-         WRITE(numout,*) '             laplacian operator          ln_traldf_lap   = ', ln_traldf_lap
-         WRITE(numout,*) '             bilaplacian operator        ln_traldf_bilap = ', ln_traldf_bilap
-         WRITE(numout,*) '             iso-level                   ln_traldf_level = ', ln_traldf_level
-         WRITE(numout,*) '             horizontal (geopotential)   ln_traldf_hor   = ', ln_traldf_hor
-         WRITE(numout,*) '             iso-neutral                 ln_traldf_iso   = ', ln_traldf_iso
-      ENDIF
-
-      ! Parameter control
-
-      ! control the input
+         WRITE(numout,*) '       Namelist nam_traldf : set lateral mixing parameters (type, direction, coefficients)'
+         WRITE(numout,*) '          laplacian operator          ln_traldf_lap   = ', ln_traldf_lap
+         WRITE(numout,*) '          bilaplacian operator        ln_traldf_bilap = ', ln_traldf_bilap
+         WRITE(numout,*) '          iso-level                   ln_traldf_level = ', ln_traldf_level
+         WRITE(numout,*) '          horizontal (geopotential)   ln_traldf_hor   = ', ln_traldf_hor
+         WRITE(numout,*) '          iso-neutral                 ln_traldf_iso   = ', ln_traldf_iso
+      ENDIF
+
+      !                               ! control the input
       ioptio = 0
       IF( ln_traldf_lap   )   ioptio = ioptio + 1
       IF( ln_traldf_bilap )   ioptio = ioptio + 1
-      IF( ioptio /= 1 ) CALL ctl_stop( '          use ONE of the 2 lap/bilap operator type on tracer' )
+      IF( ioptio /= 1 )   CALL ctl_stop( '          use ONE of the 2 lap/bilap operator type on tracer' )
       ioptio = 0
       IF( ln_traldf_level )   ioptio = ioptio + 1
       IF( ln_traldf_hor   )   ioptio = ioptio + 1
       IF( ln_traldf_iso   )   ioptio = ioptio + 1
-      IF( ioptio /= 1 ) CALL ctl_stop( '          use only ONE direction (level/hor/iso)' )
+      IF( ioptio /= 1 )   CALL ctl_stop( '          use only ONE direction (level/hor/iso)' )
 
       ! defined the type of lateral diffusion from ln_traldf_... logicals
@@ -213,11 +195,11 @@
       ENDIF
 
-      IF( ierr == 1 ) CALL ctl_stop( ' iso-level in z-coordinate - partial step, not allowed' )
-      IF( ierr == 2 ) CALL ctl_stop( ' isoneutral bilaplacian operator does not exist' )
-      IF( lk_traldf_eiv .AND. .NOT.ln_traldf_iso ) &
-           & CALL ctl_stop( '          eddy induced velocity on tracers', &
-           &                ' the eddy induced velocity on tracers requires isopycnal laplacian diffusion' )
+      IF( ierr == 1 )   CALL ctl_stop( ' iso-level in z-coordinate - partial step, not allowed' )
+      IF( ierr == 2 )   CALL ctl_stop( ' isoneutral bilaplacian operator does not exist' )
+      IF( lk_traldf_eiv .AND. .NOT.ln_traldf_iso )   &
+           CALL ctl_stop( '          eddy induced velocity on tracers',   &
+           &              ' the eddy induced velocity on tracers requires isopycnal laplacian diffusion' )
       IF( nldf == 1 .OR. nldf == 3 ) THEN      ! rotation
-         IF( .NOT.lk_ldfslp ) CALL ctl_stop( '          the rotation of the diffusive tensor require key_ldfslp' )
+         IF( .NOT.lk_ldfslp )   CALL ctl_stop( '          the rotation of the diffusive tensor require key_ldfslp' )
       ENDIF
 
@@ -236,10 +218,8 @@
       ENDIF
 
-
       ! Reference T & S diffusivity (if necessary)
       ! ===========================
-
       CALL ldf_ano
-
+      !
    END SUBROUTINE ldf_ctl
 
@@ -254,18 +234,14 @@
       !!
       !! ** Purpose :   initializations of 
-      !!
-      !!----------------------------------------------------------------------
-      !! * Modules used
+      !!----------------------------------------------------------------------
       USE zdf_oce         ! vertical mixing
       USE trazdf          ! vertical mixing: double diffusion
       USE zdfddm          ! vertical mixing: double diffusion
-
-      !! * local declarations
-      INTEGER  ::   jk                         ! Dummy loop indice
-      LOGICAL  ::   llsave                     !
-      REAL(wp) ::   zt0, zs0, z12              ! temporary scalar
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         zt_ref, ztb, zavt,                 &  ! 3D temporary workspace
-         zs_ref, zsb                           ! 3D temporary workspace
+      !!
+      INTEGER  ::   jk              ! Dummy loop indice
+      LOGICAL  ::   llsave          !
+      REAL(wp) ::   zt0, zs0, z12   ! temporary scalar
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zt_ref, ztb, zavt   ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zs_ref, zsb         ! 3D workspace
       !!----------------------------------------------------------------------
 
@@ -329,5 +305,5 @@
       sa    (:,:,:) = va  (:,:,:)
       avt   (:,:,:) = zavt(:,:,:)
-
+      !
    END SUBROUTINE ldf_ano
 
Index: trunk/NEMO/OPA_SRC/TRA/traldf_iso.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/traldf_iso.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/traldf_iso.F90	(revision 503)
@@ -1,10 +1,16 @@
 MODULE traldf_iso
-   !!==============================================================================
+   !!======================================================================
    !!                   ***  MODULE  traldf_iso  ***
    !! Ocean active tracers:  horizontal component of the lateral tracer mixing trend
-   !!==============================================================================
+   !!======================================================================
+   !! History :        !  94-08  (G. Madec, M. Imbard)
+   !!                  !  97-05  (G. Madec)  split into traldf and trazdf
+   !!             8.5  !  02-08  (G. Madec)  Free form, F90
+   !!             9.0  !  05-11  (G. Madec)  merge traldf and trazdf :-)
+   !!----------------------------------------------------------------------
 #if   defined key_ldfslp   ||   defined key_esopa
    !!----------------------------------------------------------------------
    !!   'key_ldfslp'               slope of the lateral diffusive direction
+   !!----------------------------------------------------------------------
    !!----------------------------------------------------------------------
    !!   tra_ldf_iso  : update the tracer trend with the horizontal 
@@ -14,5 +20,4 @@
    !!                  vector optimization, use k-j-i loops.
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
@@ -26,10 +31,8 @@
    USE prtctl          ! Print control
 
-
    IMPLICIT NONE
    PRIVATE
 
-   !! * Accessibility
-   PUBLIC tra_ldf_iso   ! routine called by step.F90
+   PUBLIC   tra_ldf_iso   ! routine called by step.F90
 
    !! * Substitutions
@@ -39,4 +42,6 @@
    !!----------------------------------------------------------------------
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -81,36 +86,21 @@
       !!         ta = ta + difft
       !!
-      !! ** Action :
-      !!         Update (ta,sa) arrays with the before rotated diffusion trend
-      !!            (except the dk[ dk[.] ] term)
-      !!
-      !! History :
-      !!        !  94-08  (G. Madec, M. Imbard)
-      !!        !  97-05  (G. Madec)  split into traldf and trazdf
-      !!   8.5  !  02-08  (G. Madec)  Free form, F90
-      !!   9.0  !  04-08  (C. Talandier) New trends organization
-      !!        !  05-11  (G. Madec)  merge traldf and trazdf :-)
-      !!----------------------------------------------------------------------
-      !! * Modules used
-      USE oce           , zftv => ua,   &  ! use ua as workspace
-         &                zfsv => va       ! use va as workspace
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt        ! ocean time-step index
-
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk              ! dummy loop indices
-      INTEGER ::   iku, ikv                ! temporary integer
-      REAL(wp) ::   &
-         zabe1, zabe2, zcof1, zcof2,    &  ! temporary scalars
-         zmsku, zta,                    &  !    "           "
-         zmskv, zsa, zbtr,              &  !    "           "
-         zcoef0, zcoef3, zcoef4            !    "         "
-      REAL(wp), DIMENSION(jpi,jpj) ::   &  ! temporary workspace
-         zdkt , zdk1t, zftu,            &  !    "           "
-         zdks , zdk1s, zfsu                !    "           "
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   & 
-         zdit, zdjt, ztfw,              &  ! temporary workspace
-         zdis, zdjs, zsfw                  !    "           "
+      !! ** Action :   Update (ta,sa) arrays with the before rotated diffusion
+      !!            trend (except the dk[ dk[.] ] term)
+      !!----------------------------------------------------------------------
+      USE oce           , zftv => ua   ! use ua as workspace
+      USE oce           , zfsv => va   ! use va as workspace
+      !!
+      INTEGER, INTENT( in ) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   iku, ikv     ! temporary integer
+      REAL(wp) ::   zmsku, zabe1, zcof1, zcoef3, zta   ! temporary scalars
+      REAL(wp) ::   zmskv, zabe2, zcof2, zcoef4, zsa   !    "         "
+      REAL(wp) ::   zcoef0, zbtr                       !    "         "
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zdkt , zdk1t, zftu   ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zdks , zdk1s, zfsu   !    "           "
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdit, zdjt, ztfw     ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdis, zdjs, zsfw     !  "      "
       !!----------------------------------------------------------------------
 
@@ -130,5 +120,4 @@
       zdjs (1,:,:) = 0.e0     ;     zdjs (jpi,:,:) = 0.e0
 !!end
-
 
       ! Horizontal temperature and salinity gradient 
@@ -217,5 +206,4 @@
          ! II.4 Second derivative (divergence) and add to the general trend
          ! ----------------------------------------------------------------
-
          DO jj = 2 , jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -231,6 +219,5 @@
       !                                             ! ===============
 
-      IF( ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN
-         ! "zonal" mean lateral diffusive heat and salt transports
+      IF( ln_diaptr .AND. ( MOD( kt, nf_ptr ) == 0 ) ) THEN   ! Poleward diffusive heat and salt transports
          pht_ldf(:) = ptr_vj( zftv(:,:,:) )
          pst_ldf(:) = ptr_vj( zfsv(:,:,:) )
@@ -297,5 +284,5 @@
          END DO
       END DO
-
+      !
    END SUBROUTINE tra_ldf_iso
 
@@ -306,5 +293,4 @@
 CONTAINS
    SUBROUTINE tra_ldf_iso( kt )               ! Empty routine
-      INTEGER :: kt
       WRITE(*,*) 'tra_ldf_iso: You should not have seen this print! error?', kt
    END SUBROUTINE tra_ldf_iso
Index: trunk/NEMO/OPA_SRC/TRA/tranpc.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/tranpc.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/tranpc.F90	(revision 503)
@@ -4,4 +4,12 @@
    !! Ocean active tracers:  non penetrative convection scheme
    !!==============================================================================
+   !! History :  1.0  !  90-09  (G. Madec)  Original code
+   !!                 !  91-11  (G. Madec)
+   !!                 !  92-06  (M. Imbard)  periodic conditions on t and s
+   !!                 !  93-03  (M. Guyon)  symetrical conditions 
+   !!                 !  96-01  (G. Madec)  statement function for e3
+   !!                                       suppression of common work arrays
+   !!            8.5  !  02-06  (G. Madec)  free form F90
+   !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
@@ -9,5 +17,4 @@
    !!   tra_npc_init : initialization and control of the scheme
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and active tracers 
    USE dom_oce         ! ocean space and time domain
@@ -21,11 +28,10 @@
    PRIVATE
 
-   !! * Routine accessibility
-   PUBLIC tra_npc      ! routine called by step.F90
-
-   !! * Module variable
-   INTEGER ::       &
-      nnpc1 =   1,  &  ! nnpc1   non penetrative convective scheme frequency
-      nnpc2 =  15      ! nnpc2   non penetrative convective scheme print frequency
+   PUBLIC   tra_npc    ! routine called by step.F90
+
+   !!* Namelist namnpc: non penetrative convection algorithm
+   INTEGER ::   nnpc1 =   1   ! nnpc1   non penetrative convective scheme frequency
+   INTEGER ::   nnpc2 =  15   ! nnpc2   non penetrative convective scheme print frequency
+   NAMELIST/namnpc/ nnpc1, nnpc2
 
    !! * Substitutions
@@ -34,5 +40,5 @@
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -50,50 +56,27 @@
       !!      iterations. instabilities are treated when the vertical density
       !!      gradient is less than 1.e-5.
-      !!
-      !!      'key_trdtra' defined: the trend associated with this
-      !!                               algorithm is saved.
-      !!
-      !!      macro-tasked on vertical slab (jj-loop)
+      !!      l_trdtra=T: the trend associated with this algorithm is saved.
       !!
       !! ** Action  : - (tn,sn) after the application od the npc scheme
       !!              - save the associated trends (ttrd,strd) ('key_trdtra')
       !!
-      !! References :
-      !!      Madec, et al., 1991, JPO, 21, 9, 1349-1371.
-      !!
-      !! History :
-      !!   1.0  !  90-09  (G. Madec)  Original code
-      !!        !  91-11  (G. Madec)
-      !!        !  92-06  (M. Imbard)  periodic conditions on t and s
-      !!        !  93-03  (M. Guyon)  symetrical conditions 
-      !!        !  96-01  (G. Madec)  statement function for e3
-      !!                                  suppression of common work arrays
-      !!   8.5  !  02-06  (G. Madec)  free form F90
-      !!   9.0  !  04-08  (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------
-      !! * Modules used     
-      USE oce, ONLY :    ztdta => ua,   & ! use ua as 3D workspace   
-                         ztdsa => va      ! use va as 3D workspace   
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt       ! ocean time-step index
-
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk             ! dummy loop indices
-      INTEGER ::   &
-         inpcc ,                        & ! number of statically instable water column
-         inpci ,                        & ! number of iteration for npc scheme
-         jiter, jkdown, jkp,            & ! ???
-         ikbot, ik, ikup, ikdown          ! ???
-      REAL(wp) ::   &                     ! temporary arrays
-         ze3tot, zta, zsa, zraua, ze3dwn
-      REAL(wp), DIMENSION(jpi,jpk) ::   &
-         zwx, zwy, zwz                    ! temporary arrays
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         zrhop                            ! temporary arrays
-      !!----------------------------------------------------------------------
-
-      IF( kt == nit000  )   CALL tra_npc_init
-
+      !! References : Madec, et al., 1991, JPO, 21, 9, 1349-1371.
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :    ztrdt => ua   ! use ua as 3D workspace   
+      USE oce, ONLY :    ztrds => va   ! use va as 3D workspace   
+      !! 
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   inpcc        ! number of statically instable water column
+      INTEGER  ::   inpci        ! number of iteration for npc scheme
+      INTEGER  ::   jiter, jkdown, jkp        ! ???
+      INTEGER  ::   ikbot, ik, ikup, ikdown   ! ???
+      REAL(wp) ::   ze3tot, zta, zsa, zraua, ze3dwn
+      REAL(wp), DIMENSION(jpi,jpk)     ::   zwx, zwy, zwz   ! 2D arrays
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zrhop           ! 3D arrays
+      !!----------------------------------------------------------------------
+
+      IF( kt == nit000  )   CALL tra_npc_init   ! Initialisation
 
       IF( MOD( kt, nnpc1 ) == 0 ) THEN
@@ -102,13 +85,10 @@
          inpci = 0
 
-         ! 0. Potential density
-         ! --------------------
-
-         CALL eos( tn, sn, rhd, zrhop )
-
-         ! Save tn and sn trends
-         IF( l_trdtra )   THEN
-            ztdta(:,:,:) = tn(:,:,:) 
-            ztdsa(:,:,:) = sn(:,:,:) 
+         CALL eos( tn, sn, rhd, zrhop )         ! Potential density
+
+
+         IF( l_trdtra )   THEN                  ! Save tn and sn trends
+            ztrdt(:,:,:) = tn(:,:,:) 
+            ztrds(:,:,:) = sn(:,:,:) 
          ENDIF
 
@@ -116,8 +96,6 @@
          DO jj = 1, jpj                                   !  Vertical slab
             !                                             ! ===============
-
-            ! 1. Static instability pointer 
-            ! -----------------------------
-
+            !  Static instability pointer 
+            ! ----------------------------
             DO jk = 1, jpkm1
                DO ji = 1, jpi
@@ -134,14 +112,14 @@
             END DO
             ! even if south-symmetric b. c. used, do not considere jj=1
-            IF( jj == 1 ) zwx(:,:) = 0.e0
+            IF( jj == 1 )   zwx(:,:) = 0.e0
 
             DO jk = 1, jpkm1
                DO ji = 1, jpi
                   zwx(ji,jk) = 1.
-                  IF( zwx(ji,jk) < 1.e-5 ) zwx(ji,jk)=0.
-               END DO
-            END DO
-
-            zwy(:,1) = 0.
+                  IF( zwx(ji,jk) < 1.e-5 ) zwx(ji,jk) = 0.e0
+               END DO
+            END DO
+
+            zwy(:,1) = 0.e0
             DO ji = 1, jpi
                DO jk = 1, jpkm1
@@ -150,5 +128,5 @@
             END DO
 
-            zwz(1,1) = 0.
+            zwz(1,1) = 0.e0
             DO ji = 1, jpi
                zwz(1,1) = zwz(1,1) + zwy(ji,1)
@@ -161,21 +139,14 @@
             ! ------------------------------------------------------------------
 
-            IF (zwz(1,1) /= 0.) THEN
-
-               ! -->> the density profil is statically instable :
-
+            IF( zwz(1,1) /= 0.e0 ) THEN         ! -->> the density profil is statically instable :
                DO ji = 1, jpi
-                  IF( zwy(ji,1) /= 0. ) THEN
-
-                     ! ikbot: ocean bottom level
-
-                     ikbot = mbathy(ji,jj)
-
-                     ! vertical iteration
-
-                     DO jiter = 1, jpk
-
+                  IF( zwy(ji,1) /= 0.e0 ) THEN
+                     !
+                     ikbot = mbathy(ji,jj)      ! ikbot: ocean bottom level
+                     !
+                     DO jiter = 1, jpk          ! vertical iteration
+                        !
                         ! search of ikup : the first static instability from the sea surface
-
+                        !
                         ik = 0
 220                     CONTINUE
@@ -183,17 +154,15 @@
                         IF( ik >= ikbot-1 ) GO TO 200
                         zwx(ji,ik) = zrhop(ji,jj,ik) - zrhop(ji,jj,ik+1)
-                        IF( zwx(ji,ik) <= 0. ) GO TO 220
+                        IF( zwx(ji,ik) <= 0.e0 ) GO TO 220
                         ikup = ik
                         ! the density profil is instable below ikup
-   
                         ! ikdown : bottom of the instable portion of the density profil
-
                         ! search of ikdown and vertical mixing from ikup to ikdown
-
+                        !
                         ze3tot= fse3t(ji,jj,ikup)
                         zta   = tn   (ji,jj,ikup)
                         zsa   = sn   (ji,jj,ikup)
                         zraua = zrhop(ji,jj,ikup)
-
+                        !
                         DO jkdown = ikup+1, ikbot-1
                            IF( zraua <= zrhop(ji,jj,jkdown) ) THEN
@@ -210,5 +179,5 @@
                         ikdown = ikbot-1
 240                     CONTINUE
-
+                        !
                         DO jkp = ikup, ikdown-1
                            tn(ji,jj,jkp) = zta
@@ -221,25 +190,18 @@
                            zrhop(ji,jj,ikdown) = zraua
                         ENDIF
-
                      END DO
                   ENDIF
 200               CONTINUE
                END DO
-
                ! <<-- no more static instability on slab jj
-
             ENDIF
             !                                             ! ===============
          END DO                                           !   End of slab
          !                                                ! ===============
-
-
-         ! save the trends for diagnostic
-         ! Non penetrative mixing trends
-         IF( l_trdtra )   THEN
-            ztdta(:,:,:) = tn(:,:,:) - ztdta(:,:,:)
-            ztdsa(:,:,:) = sn(:,:,:) - ztdsa(:,:,:)
-
-            CALL trd_mod(ztdta, ztdsa, jpttdnpc, 'TRA', kt)
+         ! 
+         IF( l_trdtra )   THEN         ! save the Non penetrative mixing trends for diagnostic
+            ztrdt(:,:,:) = tn(:,:,:) - ztrdt(:,:,:)
+            ztrds(:,:,:) = sn(:,:,:) - ztrds(:,:,:)
+            CALL trd_mod(ztrdt, ztrds, jptra_trd_npc, 'TRA', kt)
          ENDIF
       
@@ -252,12 +214,11 @@
          !  2. non penetrative convective scheme statistics
          !  -----------------------------------------------
-
          IF( nnpc2 /= 0 .AND. MOD( kt, nnpc2 ) == 0 ) THEN
             IF(lwp) WRITE(numout,*)' kt=',kt, ' number of statically instable',   &
-               ' water column : ',inpcc, ' number of iteration : ',inpci
+               &                   ' water column : ',inpcc, ' number of iteration : ',inpci
          ENDIF
-
+         !
       ENDIF
-      
+      !
    END SUBROUTINE tra_npc
 
@@ -268,33 +229,19 @@
       !!                   
       !! ** Purpose :   initializations of the non-penetrative adjustment scheme
-      !!
-      !! History :
-      !!   8.5  !  02-12  (G. Madec)  F90 : free form
-      !!----------------------------------------------------------------------
-      !! * Namelist
-      NAMELIST/namnpc/ nnpc1, nnpc2
-      !!----------------------------------------------------------------------
-
-      ! Namelist namzdf : vertical diffusion
-      REWIND( numnam )
+      !!----------------------------------------------------------------------
+      !
+      REWIND( numnam )           ! Namelist namzdf : vertical diffusion
       READ  ( numnam, namnpc )
-
-      ! Parameter print
-      ! ---------------
-      IF(lwp) THEN
+      !
+      IF(lwp) THEN               ! Namelist print
          WRITE(numout,*)
          WRITE(numout,*) 'tra_npc_init : Non Penetrative Convection (npc) scheme'
          WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '          Namelist namnpc : set npc scheme parameters'
-         WRITE(numout,*)
-         WRITE(numout,*) '             npc scheme frequency           nnpc1  = ', nnpc1
-         WRITE(numout,*) '             npc scheme print frequency     nnpc2  = ', nnpc2
-         WRITE(numout,*)
+         WRITE(numout,*) '       Namelist namnpc : set npc scheme parameters'
+         WRITE(numout,*) '          npc scheme frequency           nnpc1  = ', nnpc1
+         WRITE(numout,*) '          npc scheme print frequency     nnpc2  = ', nnpc2
       ENDIF
-
-
-      ! Parameter controls
-      ! ------------------
-      IF ( nnpc1 == 0 ) THEN
+      !
+      IF ( nnpc1 == 0 ) THEN      ! Parameter controls
           IF(lwp) WRITE(numout,cform_war)
           IF(lwp) WRITE(numout,*) '             nnpc1 = ', nnpc1, ' is forced to 1'
@@ -302,5 +249,5 @@
           nwarn = nwarn + 1
       ENDIF
-      
+      !
    END SUBROUTINE tra_npc_init
 
Index: trunk/NEMO/OPA_SRC/TRA/tranxt.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 503)
@@ -4,17 +4,18 @@
    !! Ocean active tracers:  time stepping on temperature and salinity
    !!======================================================================
-   !! History :
-   !!   7.0  !  91-11  (G. Madec)  Original code
-   !!        !  93-03  (M. Guyon)  symetrical conditions
-   !!        !  96-02  (G. Madec & M. Imbard)  opa release 8.0
-   !!   8.0  !  96-04  (A. Weaver)  Euler forward step
-   !!   8.2  !  99-02  (G. Madec, N. Grima)  semi-implicit pressure grad.
-   !!   8.5  !  02-08  (G. Madec)  F90: Free form and module
-   !!        !  02-11  (C. Talandier, A-M Treguier) Open boundaries
-   !!   9.0  !  06-02  (L. Debreu, C. Mazauric) Agrif implementation
+   !! History :  7.0  !  91-11  (G. Madec)  Original code
+   !!                 !  93-03  (M. Guyon)  symetrical conditions
+   !!                 !  96-02  (G. Madec & M. Imbard)  opa release 8.0
+   !!            8.0  !  96-04  (A. Weaver)  Euler forward step
+   !!            8.2  !  99-02  (G. Madec, N. Grima)  semi-implicit pressure grad.
+   !!            8.5  !  02-08  (G. Madec)  F90: Free form and module
+   !!                 !  02-11  (C. Talandier, A-M Treguier) Open boundaries
+   !!                 !  05-04  (C. Deltel) Add Asselin trend in the ML budget
+   !!            9.0  !  06-02  (L. Debreu, C. Mazauric) Agrif implementation
+   !!----------------------------------------------------------------------
+
    !!----------------------------------------------------------------------
    !!   tra_nxt     : time stepping on temperature and salinity
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain variables 
@@ -23,4 +24,6 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE obctra          ! open boundary condition (obc_tra routine)
+   USE trdmod          ! ocean active tracers trends 
+   USE trdmod_oce      ! ocean variables trends
    USE prtctl          ! Print control
    USE agrif_opa_update
@@ -31,9 +34,9 @@
 
    !! * Routine accessibility
-   PUBLIC tra_nxt          ! routine called by step.F90
-   !!----------------------------------------------------------------------
-   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   PUBLIC   tra_nxt   ! routine called by step.F90
+   !!----------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2006) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -67,16 +70,19 @@
       !! ** Action  : - update (tb,sb) and (tn,sn) 
       !!              - (ta,sa) time averaged (t,s)      (ln_dynhpg_imp = T)
-      !!
       !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
-
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zt, zs      ! temporary scalars
-      REAL(wp) ::   zfact       ! temporary scalar
+      USE oce, ONLY :    ztrdt => ua   ! use ua as 3D workspace   
+      USE oce, ONLY :    ztrds => va   ! use va as 3D workspace   
+      !!
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zt, zs       ! temporary scalars
+      REAL(wp) ::   zfact        ! temporary scalar
       !!----------------------------------------------------------------------
 
-
+      IF( l_trdtra ) THEN
+         ztrdt(:,:,jpk) = 0.e0
+         ztrds(:,:,jpk) = 0.e0
+      ENDIF
       ! 0. Lateral boundary conditions on ( ta, sa )   (T-point, unchanged sign)
       ! ---------------------------------============
@@ -84,5 +90,4 @@
       CALL lbc_lnk( sa, 'T', 1. )
 
-
       !                                                ! ===============
       DO jk = 1, jpkm1                                 ! Horizontal slab
@@ -93,7 +98,8 @@
          IF( ln_zdfexp ) THEN
             zfact = 2. * rdttra(jk)
-            IF( neuler == 0 .AND. kt == nit000 ) zfact = rdttra(jk)
+            IF( neuler == 0 .AND. kt == nit000 )   zfact = rdttra(jk)
             ta(:,:,jk) = ( tb(:,:,jk) + zfact * ta(:,:,jk) ) * tmask(:,:,jk)
             sa(:,:,jk) = ( sb(:,:,jk) + zfact * sa(:,:,jk) ) * tmask(:,:,jk)
+            IF(l_trdtra)   CALL ctl_stop( 'tranxt: Asselin ML trend not yet accounted for.' )
          ENDIF
 
@@ -102,8 +108,6 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-
       ! Update tracers on open boundaries.
       CALL obc_tra( kt )
-
       !                                                ! ===============
       DO jk = 1, jpkm1                                 ! Horizontal slab
@@ -114,14 +118,10 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-
       ! Update tracers on open boundaries.
       CALL Agrif_tra( kt )
-
       !                                                ! ===============
       DO jk = 1, jpkm1                                 ! Horizontal slab
          !                                             ! ===============
 #endif
-
-
          ! 2. Time filter and swap of arrays
          ! ---------------------------------
@@ -141,4 +141,8 @@
                   END DO
                END DO
+               IF( l_trdtra ) THEN
+                  ztrdt(:,:,jk) = 0.e0
+                  ztrds(:,:,jk) = 0.e0
+               END IF
             ELSE
                DO jj = 1, jpj
@@ -148,4 +152,8 @@
                      tb(ji,jj,jk) = atfp  * ( tb(ji,jj,jk) + ta(ji,jj,jk) ) + atfp1 * tn(ji,jj,jk)
                      sb(ji,jj,jk) = atfp  * ( sb(ji,jj,jk) + sa(ji,jj,jk) ) + atfp1 * sn(ji,jj,jk)
+                     IF( l_trdtra ) THEN ! ChD ceci est a optimiser, mais ca marche
+                        ztrdt(ji,jj,jk) = tb(ji,jj,jk) - tn(ji,jj,jk)
+                        ztrds(ji,jj,jk) = sb(ji,jj,jk) - sn(ji,jj,jk)
+                     END IF
                      tn(ji,jj,jk) = ta(ji,jj,jk)
                      sn(ji,jj,jk) = sa(ji,jj,jk)
@@ -165,5 +173,17 @@
                   END DO
                END DO
+               IF( l_trdtra ) THEN
+                  ztrdt(:,:,jk) = 0.e0
+                  ztrds(:,:,jk) = 0.e0
+               END IF
             ELSE
+               IF( l_trdtra ) THEN
+                  DO jj = 1, jpj
+                     DO ji = 1, jpi
+                        ztrdt(ji,jj,jk) = atfp * ( tb(ji,jj,jk) - 2*tn(ji,jj,jk) + ta(ji,jj,jk) )
+                        ztrds(ji,jj,jk) = atfp * ( sb(ji,jj,jk) - 2*sn(ji,jj,jk) + sa(ji,jj,jk) )
+                     END DO
+                  END DO
+               END IF
                DO jj = 1, jpj
                   DO ji = 1, jpi
@@ -180,13 +200,16 @@
       !                                                ! ===============
 
-      IF(ln_ctl) THEN         ! print mean field (used for debugging)
-         CALL prt_ctl(tab3d_1=tn, clinfo1=' nxt  - Tn: ', mask1=tmask, &
-            &         tab3d_2=sn, clinfo2=' Sn: ', mask2=tmask)
-      ENDIF
-      
+      IF( l_trdtra )   THEN      ! Take the Asselin trend into account 
+         ztrdt(:,:,:) = ztrdt(:,:,:) / ( 2.*rdt )
+         ztrds(:,:,:) = ztrds(:,:,:) / ( 2.*rdt )         
+         CALL trd_mod( ztrdt, ztrds, jptra_trd_atf, 'TRA', kt )
+      END IF
+
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=tn, clinfo1=' nxt  - Tn: ', mask1=tmask,   &
+         &                       tab3d_2=sn, clinfo2=       ' Sn: ', mask2=tmask )
 #if defined key_agrif
       IF (.NOT.Agrif_Root())    CALL Agrif_Update_Tra( kt )
 #endif      
-
+      !
    END SUBROUTINE tra_nxt
 
Index: trunk/NEMO/OPA_SRC/TRA/traqsr.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 503)
@@ -4,16 +4,15 @@
    !! Ocean physics: solar radiation penetration in the top ocean levels
    !!======================================================================
-   !! History :
-   !!   6.0  !  90-10  (B. Blanke)  Original code
-   !!   7.0  !  91-11  (G. Madec)
-   !!        !  96-01  (G. Madec)  s-coordinates
-   !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
-   !!   9.0  !  04-08  (C. Talandier) New trends organization
-   !!   9.0  !  05-11  (G. Madec) zco, zps, sco coordinate
+   !! History :  6.0  !  90-10  (B. Blanke)  Original code
+   !!            7.0  !  91-11  (G. Madec)
+   !!                 !  96-01  (G. Madec)  s-coordinates
+   !!            8.5  !  02-06  (G. Madec)  F90: Free form and module
+   !!            9.0  !  05-11  (G. Madec) zco, zps, sco coordinate
+   !!----------------------------------------------------------------------
+
    !!----------------------------------------------------------------------
    !!   tra_qsr      : trend due to the solar radiation penetration
    !!   tra_qsr_init : solar radiation penetration initialization
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
@@ -29,25 +28,17 @@
    PRIVATE
 
-   !! * Routine accessibility
-   PUBLIC tra_qsr      ! routine called by step.F90 (ln_traqsr=T)
-   PUBLIC tra_qsr_init ! routine called by opa.F90
-
-   !! * Shared module variables
-   LOGICAL, PUBLIC ::   ln_traqsr = .TRUE.   !: qsr flag (Default=T)
-
-   !! * Module variables
-   REAL(wp), PUBLIC ::  & !!! * penetrative solar radiation namelist *
-      rabs = 0.58_wp,   &  ! fraction associated with xsi1
-      xsi1 = 0.35_wp,   &  ! first depth of extinction 
-      xsi2 = 23.0_wp       ! second depth of extinction 
-      !                    ! (default values: water type Ib)
-   LOGICAL ::           & 
-      ln_qsr_sms = .false. ! flag to use or not the biological 
-      !                    ! fluxes for light 
+   PUBLIC   tra_qsr      ! routine called by step.F90 (ln_traqsr=T)
+   PUBLIC   tra_qsr_init ! routine called by opa.F90
+
+   !!* Namelist namqsr: penetrative solar radiation
+   LOGICAL , PUBLIC ::   ln_traqsr = .TRUE.   !: qsr flag (Default=T)
+   REAL(wp), PUBLIC ::   rabs = 0.58_wp       ! fraction associated with xsi1
+   REAL(wp), PUBLIC ::   xsi1 = 0.35_wp       ! first depth of extinction 
+   REAL(wp), PUBLIC ::   xsi2 = 23.0_wp       ! second depth of extinction (default values: water type Ib)
+   LOGICAL , PUBLIC ::   ln_qsr_sms = .false. ! flag to use or not the biological fluxes for light 
+   NAMELIST/namqsr/ ln_traqsr, rabs, xsi1, xsi2, ln_qsr_sms
    
-   INTEGER ::    &
-      nksr                 ! number of levels
-   REAL(wp), DIMENSION(jpk) ::   &
-      gdsr                 ! profile of the solar flux penetration
+   INTEGER ::   nksr   ! number of levels
+   REAL(wp), DIMENSION(jpk) ::   gdsr   ! profile of the solar flux penetration
 
    !! * Substitutions
@@ -57,5 +48,5 @@
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -86,27 +77,22 @@
       !! ** Action  : - update ta with the penetrative solar radiation trend
       !!              - save the trend in ttrd ('key_trdtra')
-      !!
-      !!----------------------------------------------------------------------
-      !! * Modules used     
-      USE oce, ONLY :    ztrdt => ua,   & ! use ua as 3D workspace   
-                         ztrds => va      ! use va as 3D workspace   
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt       ! ocean time-step
-
-      !! * Local declarations
-      INTEGER ::    ji, jj, jk            ! dummy loop indexes
-      REAL(wp) ::   zc0 , zta             ! temporary scalars
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   ztrdt => ua   ! use ua as 3D workspace   
+      USE oce, ONLY :   ztrds => va   ! use va as 3D workspace   
+      !!
+      INTEGER, INTENT(in) ::   kt     ! ocean time-step
+      !!
+      INTEGER  ::    ji, jj, jk       ! dummy loop indexes
+      REAL(wp) ::   zc0 , zta         ! temporary scalars
       !!----------------------------------------------------------------------
 
       IF( kt == nit000 ) THEN
-         IF ( lwp )  WRITE(numout,*)
-         IF ( lwp )  WRITE(numout,*) 'tra_qsr : penetration of the surface solar radiation'
-         IF ( lwp )  WRITE(numout,*) '~~~~~~~'
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_qsr : penetration of the surface solar radiation'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
          CALL tra_qsr_init
       ENDIF
 
-      ! Save ta and sa trends
-      IF( l_trdtra )   THEN
+      IF( l_trdtra ) THEN      ! Save ta and sa trends
          ztrdt(:,:,:) = ta(:,:,:) 
          ztrds(:,:,:) = 0.e0
@@ -122,11 +108,8 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  
                   zc0 = ro0cpr  / fse3t(ji,jj,jk)         ! compute the qsr trend
                   zta = zc0 * ( etot3(ji,jj,jk  ) * tmask(ji,jj,jk)     &
                      &        - etot3(ji,jj,jk+1) * tmask(ji,jj,jk+1) )
-                  
                   ta(ji,jj,jk) = ta(ji,jj,jk) + zta       ! add qsr trend to the temperature trend
-                  
                END DO
             END DO
@@ -179,13 +162,11 @@
       ENDIF
 
-      ! qsr tracers trends saved the trends for diagnostics
-      IF( l_trdtra )   THEN
+      IF( l_trdtra ) THEN     ! qsr tracers trends saved for diagnostics
          ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
-         CALL trd_mod( ztrdt, ztrds, jpttdqsr, 'TRA', kt )
-      ENDIF
-
+         CALL trd_mod( ztrdt, ztrds, jptra_trd_qsr, 'TRA', kt )
+      ENDIF
       !                       ! print mean trends (used for debugging)
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' qsr  - Ta: ', mask1=tmask, clinfo3='tra-ta' )
-
+      !
    END SUBROUTINE tra_qsr
 
@@ -206,23 +187,16 @@
       !! ** Action  : - initialize xsr1, xsr2 and rabs
       !!
-      !! Reference :
-      !!   Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
-      !!----------------------------------------------------------------------
-      INTEGER ::    ji,jj,jk, &  ! dummy loop index
-                    indic        ! temporary integer
-      REAL(wp) ::   zc0 , zc1 , zc2 ,   & ! temporary scalars
-         &          zcst, zdp1, zdp2      !    "         "
-
-      NAMELIST/namqsr/ ln_traqsr, rabs, xsi1, xsi2, ln_qsr_sms
-      !!----------------------------------------------------------------------
-
-      ! Read Namelist namqsr : ratio and length of penetration
-      ! --------------------
-      REWIND ( numnam )
+      !! Reference : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk   ! dummy loop index
+      INTEGER  ::   indic        ! temporary integer
+      REAL(wp) ::   zc0 , zc1 , zc2    ! temporary scalars
+      REAL(wp) ::   zcst, zdp1, zdp2   !    "         "
+      !!----------------------------------------------------------------------
+
+      REWIND ( numnam )           ! Read Namelist namqsr : ratio and length of penetration
       READ   ( numnam, namqsr )
 
-      ! Parameter control and print
-      ! ---------------------------
-      IF( ln_traqsr  ) THEN
+      IF( ln_traqsr  ) THEN       ! Parameter control and print
          IF(lwp) THEN
             WRITE(numout,*)
@@ -248,8 +222,7 @@
          CALL ctl_stop( '             0<rabs<1, 0<xsi1, or 0<xsi2 not satisfied' )
 
-      ! Initialization of gdsr
-      ! ----------------------
+      !                           ! Initialization of gdsr
       IF( ln_zco .OR. ln_zps ) THEN
-
+         !
          ! z-coordinate with or without partial step : same w-level everywhere inside the ocean
          gdsr(:) = 0.e0
@@ -283,5 +256,5 @@
             END DO
          ENDIF
-
+         !
       ENDIF
 
@@ -302,6 +275,6 @@
             END DO
          END DO 
-       ENDIF
-
+      ENDIF
+      !
    END SUBROUTINE tra_qsr_init
 
Index: trunk/NEMO/OPA_SRC/TRA/trasbc.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 503)
@@ -4,13 +4,12 @@
    !! Ocean active tracers:  surface boundary condition
    !!==============================================================================
-   !! History :
-   !!   8.2  !  98-10  (G. Madec, G. Roullet, M. Imbard)  Original code
-   !!   8.2  !  01-02  (D. Ludicone)  sea ice and free surface
-   !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
-   !!   9.0  !  04-08  (C. Talandier) New trends organization
+   !! History :  8.2  !  98-10  (G. Madec, G. Roullet, M. Imbard)  Original code
+   !!            8.2  !  01-02  (D. Ludicone)  sea ice and free surface
+   !!            8.5  !  02-06  (G. Madec)  F90: Free form and module
+   !!----------------------------------------------------------------------
+
    !!----------------------------------------------------------------------
    !!   tra_sbc      : update the tracer trend at ocean surface
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space domain variables
@@ -26,6 +25,5 @@
    PRIVATE
 
-   !! * Routine accessibility
-   PUBLIC tra_sbc              ! routine called by step.F90
+   PUBLIC   tra_sbc    ! routine called by step.F90
 
    !! * Substitutions
@@ -35,5 +33,5 @@
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -78,14 +76,10 @@
       !!                with the tracer surface boundary condition 
       !!              - save the trend it in ttrd ('key_trdtra')
+      !!----------------------------------------------------------------------
+      USE oce, ONLY :   ztrdt => ua   ! use ua as 3D workspace   
+      USE oce, ONLY :   ztrds => va   ! use va as 3D workspace   
       !!
-      !!----------------------------------------------------------------------
-      !! * Modules used     
-      USE oce, ONLY :    ztdta => ua,      & ! use ua as 3D workspace   
-                         ztdsa => va         ! use va as 3D workspace   
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
-
-      !! * Local declarations
+      INTEGER, INTENT(in) ::   kt     ! ocean time-step index
+      !!
       INTEGER  ::   ji, jj                   ! dummy loop indices
       REAL(wp) ::   zta, zsa, zsrau, zse3t   ! temporary scalars
@@ -98,19 +92,17 @@
       ENDIF
 
-      ! 0. initialization
-      zsrau = 1. / rauw
+      zsrau = 1. / rauw             ! initialization
 #if defined key_zco
       zse3t = 1. / e3t_0(1)
 #endif
 
-      ! Save ta and sa trends
-      IF( l_trdtra )   THEN
-         ztdta(:,:,:) = ta(:,:,:) 
-         ztdsa(:,:,:) = sa(:,:,:) 
+      IF( l_trdtra ) THEN           ! Save ta and sa trends
+         ztrdt(:,:,:) = ta(:,:,:) 
+         ztrds(:,:,:) = sa(:,:,:) 
       ENDIF
 
       IF( .NOT.ln_traqsr )   qsr(:,:) = 0.e0   ! no solar radiation penetration
 
-      ! 1. Concentration dillution effect on (t,s)
+      ! Concentration dillution effect on (t,s)
       DO jj = 2, jpj
          DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -118,29 +110,20 @@
             zse3t = 1. / fse3t(ji,jj,1)
 #endif
-            ! temperature : heat flux
-            zta = ro0cpr * ( qt(ji,jj) - qsr(ji,jj) ) * zse3t
-
-            ! salinity :  concent./dilut. effect
-            zsa = emps(ji,jj) * zsrau * sn(ji,jj,1) * zse3t
-            
-            ! add the trend to the general tracer trend
-            ta(ji,jj,1) = ta(ji,jj,1) + zta
+            zta = ro0cpr * ( qt(ji,jj) - qsr(ji,jj) ) * zse3t      ! temperature : heat flux
+            zsa = emps(ji,jj) * zsrau * sn(ji,jj,1)   * zse3t      ! salinity :  concent./dilut. effect
+            ta(ji,jj,1) = ta(ji,jj,1) + zta                        ! add the trend to the general tracer trend
             sa(ji,jj,1) = sa(ji,jj,1) + zsa
          END DO
       END DO
 
-      ! save the trends for diagnostic
-      ! sea surface boundary condition tracers trends
-      IF( l_trdtra )   THEN
-         ztdta(:,:,:) = ta(:,:,:) - ztdta(:,:,:)
-         ztdsa(:,:,:) = sa(:,:,:) - ztdsa(:,:,:)
-         CALL trd_mod(ztdta, ztdsa, jpttdnsr, 'TRA', kt)
+      IF( l_trdtra ) THEN      ! save the sbc trends for diagnostic
+         ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
+         ztrds(:,:,:) = sa(:,:,:) - ztrds(:,:,:)
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_nsr, 'TRA', kt)
       ENDIF
-      
-      IF(ln_ctl) THEN         ! print mean trends (used for debugging)
-         CALL prt_ctl(tab3d_1=ta, clinfo1=' sbc  - Ta: ', mask1=tmask, &
-            &         tab3d_2=sa, clinfo2=' Sa: ', mask2=tmask, clinfo3='tra')
-      ENDIF
-
+      !
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' sbc  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+      !
    END SUBROUTINE tra_sbc
 
Index: trunk/NEMO/OPA_SRC/TRA/trazdf.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/trazdf.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/trazdf.F90	(revision 503)
@@ -4,11 +4,11 @@
    !! Ocean active tracers:  vertical component of the tracer mixing trend
    !!==============================================================================
-   !! History :
-   !!   9.0  !  05-11  (G. Madec)  Original code
+   !! History :  9.0  !  05-11  (G. Madec)  Original code
+   !!----------------------------------------------------------------------
+
    !!----------------------------------------------------------------------
    !!   tra_zdf      : Update the tracer trend with the vertical diffusion
    !!       zdf_ctl  : ???
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain variables 
@@ -28,16 +28,11 @@
    PRIVATE
 
-   !! * Routine accessibility
    PUBLIC tra_zdf   !  routine called by step.F90
 
-   !! * module variables
-   INTEGER ::                        &
-      nzdf = 0                         ! type vertical diffusion algorithm used
+   INTEGER ::   nzdf = 0               ! type vertical diffusion algorithm used
       !                                ! defined from ln_zdf...  namlist logicals)
 
-   !! * Module variables
-   REAL(wp), DIMENSION(jpk) ::  &
-      r2dt                          ! vertical profile time-step, = 2 rdttra
-      !                             ! except at nit000 (=rdttra) if neuler=0
+   REAL(wp), DIMENSION(jpk) ::   r2dt  ! vertical profile time-step, = 2 rdttra
+      !                                ! except at nit000 (=rdttra) if neuler=0
 
    !! * Substitutions
@@ -47,4 +42,6 @@
    !!----------------------------------------------------------------------
    !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
@@ -56,15 +53,9 @@
       !!
       !! ** Purpose :   compute the vertical ocean tracer physics.
-      !! ** Method  :
-      !! ** Action  :
-      !!
       !!---------------------------------------------------------------------
-      !! * Arguments
       INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
 
-      !! * local declarations
       INTEGER  ::   jk                   ! Dummy loop indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         ztrdt, ztrds                         ! 3D temporary workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztrdt, ztrds   ! 3D workspace
       !!---------------------------------------------------------------------
 
@@ -77,5 +68,4 @@
          r2dt(:) = 2. * rdttra(:)                      ! = 2 rdttra (leapfrog)
       ENDIF
-
 
       IF( l_trdtra )   THEN                      ! temporary save of ta and sa trends
@@ -101,5 +91,5 @@
             ztrdt(:,:,:) = ta(:,:,:) - ztrdt(:,:,:)
             ztrds(:,:,:) = sa(:,:,:) - ztrds(:,:,:)
-            CALL trd_mod( ztrdt, ztrds, jpttdzdf, 'TRA', kt )
+            CALL trd_mod( ztrdt, ztrds, jptra_trd_zdf, 'TRA', kt )
          ENDIF
 
@@ -111,5 +101,5 @@
                ztrds(:,:,jk) = ( ( sa(:,:,jk) - sb(:,:,jk) ) / r2dt(jk) ) - ztrds(:,:,jk)
             END DO
-            CALL trd_mod( ztrdt, ztrds, jpttdzdf, 'TRA', kt )
+            CALL trd_mod( ztrdt, ztrds, jptra_trd_zdf, 'TRA', kt )
          ENDIF
 
@@ -121,5 +111,5 @@
                ztrds(:,:,jk) = ( ( sa(:,:,jk) - sb(:,:,jk) ) / r2dt(jk) ) - ztrds(:,:,jk)
             END DO
-            CALL trd_mod( ztrdt, ztrds, jpttdzdf, 'TRA', kt )
+            CALL trd_mod( ztrdt, ztrds, jptra_trd_zdf, 'TRA', kt )
          ENDIF
 
@@ -146,7 +136,5 @@
       !!      NB: rotation of lateral mixing operator or TKE or KPP scheme,
       !!      the implicit scheme is required.
-      !!
       !!----------------------------------------------------------------------
-      !! * Module used
       USE zdftke
       USE zdfkpp
Index: trunk/NEMO/OPA_SRC/TRA/trazdf_imp.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRA/trazdf_imp.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRA/trazdf_imp.F90	(revision 503)
@@ -13,6 +13,5 @@
    !!        !  00-08 (G. Madec) double diffusive mixing
    !!   8.5  !  02-08 (G. Madec)  F90: Free form and module
-   !!   9.0  !  04-08 (C. Talandier) New trends organization
-   !!   " "  !  06-11 (G. Madec)  New step reorganisation
+   !!   9.0  !  06-11 (G. Madec)  New step reorganisation
    !!----------------------------------------------------------------------
    !!   tra_zdf_imp : Update the tracer trend with the diagonal vertical  
@@ -61,5 +60,5 @@
       !!
       !! ** Method  :   The vertical component of the lateral diffusive trends
-      !!      is provided by a 2nd order operator rotated along neural or geo-
+      !!      is provided by a 2nd order operator rotated along neutral or geo-
       !!      potential surfaces to which an eddy induced advection can be 
       !!      added. It is computed using before fields (forward in time) and 
Index: trunk/NEMO/OPA_SRC/TRD/trdicp.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRD/trdicp.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRD/trdicp.F90	(revision 503)
@@ -4,4 +4,10 @@
    !! Ocean diagnostics:  ocean tracers and dynamic trends
    !!=====================================================================
+   !! History :       !  91-12 (G. Madec)
+   !!                 !  92-06 (M. Imbard) add time step frequency
+   !!                 !  96-01 (G. Madec)  terrain following coordinates
+   !!            8.5  !  02-06 (G. Madec)  F90: Free form and module
+   !!            9.0  !  04-08 (C. Talandier) New trends organization
+   !!----------------------------------------------------------------------
 #if  defined key_trdtra   ||   defined key_trddyn   ||   defined key_esopa
    !!----------------------------------------------------------------------
@@ -9,12 +15,10 @@
    !!   'key_trddyn'                            momentum trends diagnostics
    !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   trd              : verify the basin averaged properties for tra/dyn 
+   !!----------------------------------------------------------------------
+   !!   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
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain variables
@@ -31,26 +35,12 @@
    PRIVATE
 
-   !! * Interfaces
-   INTERFACE trd
+   INTERFACE trd_icp
       MODULE PROCEDURE trd_2d, trd_3d
    END INTERFACE
 
-   !! * Routine accessibility
-   PUBLIC trd                   ! called by step.F90
-   PUBLIC trd_dwr               ! called by step.F90
-   PUBLIC trd_twr               ! called by step.F90
-   PUBLIC trd_icp_init          ! called by opa.F90
-
-   !! * Shared module variables
-#if  defined key_trdtra   &&   defined key_trddyn    ||   defined key_esopa
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trdtra = .TRUE.    !: tracers  trend flag
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trddyn = .TRUE.    !: momentum trend flag
-#elif  defined key_trdtra
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trdtra = .TRUE.    !: tracers  trend flag
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trddyn = .FALSE.   !: momentum trend flag
-#elif  defined key_trddyn
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trdtra = .FALSE.   !: tracers  trend flag
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trddyn = .TRUE.    !: momentum trend flag
-#endif
+   PUBLIC   trd_icp       ! 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
 
    !! * Substitutions
@@ -60,10 +50,10 @@
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
 CONTAINS
 
-   SUBROUTINE trd_2d(ptrd2dx, ptrd2dy, ktrd , ctype)
+   SUBROUTINE trd_2d( ptrd2dx, ptrd2dy, ktrd , ctype, clpas )
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE trd_2d  ***
@@ -71,39 +61,27 @@
       !! ** Purpose : verify the basin averaged properties of tracers and/or
       !!              momentum equations at every time step frequency ntrd.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ptrd2dx             ! Temperature or U trend 
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ptrd2dy             ! Salinity    or V trend
+      INTEGER                     , INTENT(in   ) ::   ktrd                ! tracer trend index
+      CHARACTER(len=3)            , INTENT(in   ) ::   ctype               ! momentum ('DYN') or tracers ('TRA') trends
+      CHARACTER(len=3)            , INTENT(in   ), OPTIONAL ::   clpas     ! number of passage
       !!
-      !! ** Method :
-      !!
-      !! History :
-      !!        !  91-12 (G. Madec)
-      !!        !  92-06 (M. Imbard) add time step frequency
-      !!        !  96-01 (G. Madec)  terrain following coordinates
-      !!   8.5  !  02-06 (G. Madec)  F90: Free form and module
-      !!   9.0  !  04-08 (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
-         ptrd2dx,                      &   ! Temperature or U trend 
-         ptrd2dy                           ! Salinity    or V trend
-
-      INTEGER, INTENT( in ) ::   ktrd      ! tracer trend index
-
-      CHARACTER(len=3), INTENT( in ) ::   &
-         ctype                             ! momentum or tracers trends type
-         !                                 ! 'DYN' or 'TRA'
-
-      !! * Local declarations
-      INTEGER ::   ji, jj        ! loop indices
-      REAL(wp) ::   &
-         zbt, zbtu, zbtv,     &  ! temporary scalars
-         zmsku, zmskv            !    "         "
-      !!----------------------------------------------------------------------
-
-      ! 1. Advective trends and forcing trend
-      ! -------------------------------------
-
-      ! 1.1 Mask the forcing trend and substract it from the vertical diffusion trend
-      SELECT CASE (ctype)
-
-      CASE ('DYN')              ! Momentum
+      INTEGER  ::   ji, jj                                                 ! loop indices
+      CHARACTER(len=3) ::   cpas                                           ! number of passage
+      REAL(wp) ::   zmsku, zbtu, zbt                                       ! temporary scalars
+      REAL(wp) ::   zmskv, zbtv                                            !    "         "
+      !!----------------------------------------------------------------------
+
+      ! Control of optional arguments
+      cpas = 'fst'
+      IF( PRESENT(clpas) )  cpas = clpas
+
+      ! 1. Mask trends
+      ! --------------
+
+      SELECT CASE( ctype )
+      !
+      CASE( 'DYN' )              ! Momentum
          DO jj = 1, jpjm1
             DO ji = 1, jpim1
@@ -116,23 +94,23 @@
          ptrd2dx(jpi, : ) = 0.e0      ;      ptrd2dy(jpi, : ) = 0.e0
          ptrd2dx( : ,jpj) = 0.e0      ;      ptrd2dy( : ,jpj) = 0.e0
-
-      CASE ('TRA')              ! Tracers
+         !
+      CASE( 'TRA' )              ! Tracers
          ptrd2dx(:,:) = ptrd2dx(:,:) * tmask_i(:,:)
          ptrd2dy(:,:) = ptrd2dy(:,:) * tmask_i(:,:)
-
+         !
       END SELECT
       
-      ! 2. Basin averaged tracer trend
-      ! ------------------------------
-
-      SELECT CASE (ctype)
-
-      CASE ('DYN')              ! Momentum
+      ! 2. Basin averaged tracer/momentum trends
+      ! ----------------------------------------
+
+      SELECT CASE( ctype )
+      !
+      CASE( 'DYN' )              ! Momentum
          umo(ktrd) = 0.e0
          vmo(ktrd) = 0.e0
-
-         SELECT CASE (ktrd)
-
-         CASE (jpdtdswf)         ! surface forcing
+         !
+         SELECT CASE( ktrd )
+         !
+         CASE( jpdyn_trd_swf )         ! surface forcing
             DO jj = 1, jpj
                DO ji = 1, jpi
@@ -141,6 +119,6 @@
                END DO
             END DO
-
-         CASE (jpdtdbfr)         ! bottom friction fluxes
+            !
+         CASE( jpdyn_trd_bfr )         ! bottom friction fluxes
             DO jj = 1, jpj
                DO ji = 1, jpi
@@ -149,10 +127,12 @@
                END DO
             END DO
-
+            !
          END SELECT
-
-      CASE ('TRA')              ! Tracers
-         tmo(ktrd) = 0.e0
-         smo(ktrd) = 0.e0
+         !
+      CASE( 'TRA' )              ! Tracers
+         IF( cpas == 'fst' )   THEN
+            tmo(ktrd) = 0.e0
+            smo(ktrd) = 0.e0
+         ENDIF
          DO jj = 1, jpj
             DO ji = 1, jpi
@@ -162,14 +142,14 @@
             END DO
          END DO
-
+         !
       END SELECT
       
-      ! 3. Basin averaged tracer square trend
-      ! -------------------------------------
+      ! 3. Basin averaged tracer/momentum square trends
+      ! ----------------------------------------------
       ! c a u t i o n: field now
       
-      SELECT CASE (ctype)
-
-      CASE ('DYN')              ! Momentum
+      SELECT CASE( ctype )
+      !
+      CASE( 'DYN' )              ! Momentum
          hke(ktrd) = 0.e0
          DO jj = 1, jpj
@@ -182,8 +162,10 @@
             END DO
          END DO
-
-      CASE ('TRA')              ! Tracers
-         t2(ktrd) = 0.e0
-         s2(ktrd) = 0.e0
+         !
+      CASE( 'TRA' )              ! Tracers
+         IF( cpas == 'fst' )   THEN
+            t2(ktrd) = 0.e0
+            s2(ktrd) = 0.e0
+         ENDIF
          DO jj = 1, jpj
             DO ji = 1, jpi
@@ -193,12 +175,11 @@
             END DO
          END DO
-      
+         !      
       END SELECT
-
+      !
    END SUBROUTINE trd_2d
 
 
-
-   SUBROUTINE trd_3d(ptrd3dx, ptrd3dy, ktrd, ctype)
+   SUBROUTINE trd_3d( ptrd3dx, ptrd3dy, ktrd, ctype, clpas )
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE trd_3d  ***
@@ -206,39 +187,26 @@
       !! ** Purpose : verify the basin averaged properties of tracers and/or
       !!              momentum equations at every time step frequency ntrd.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptrd3dx            ! Temperature or U trend 
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptrd3dy            ! Salinity    or V trend
+      INTEGER,                          INTENT(in   ) ::   ktrd               ! momentum or tracer trend index
+      CHARACTER(len=3),                 INTENT(in   ) ::   ctype              ! momentum ('DYN') or tracers ('TRA') trends
+      CHARACTER(len=3),                 INTENT(in   ), OPTIONAL ::   clpas    ! number of passage
       !!
-      !! ** Method :
-      !!
-      !! History :
-      !!        !  91-12 (G. Madec)
-      !!        !  92-06 (M. Imbard) add time step frequency
-      !!        !  96-01 (G. Madec)  terrain following coordinates
-      !!   8.5  !  02-06 (G. Madec)  F90: Free form and module
-      !!   9.0  !  04-08 (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
-          ptrd3dx,                     &   ! Temperature or U trend 
-          ptrd3dy                          ! Salinity    or V trend
-
-      INTEGER, INTENT( in ) ::   ktrd      ! momentum or tracer trend index
-
-      CHARACTER(len=3), INTENT( in ) ::   &
-         ctype                             ! momentum or tracers trends type
-         !                                 ! 'DYN' or 'TRA'
-
-      !! * Local declarations
       INTEGER ::   ji, jj, jk
-      REAL(wp) ::   &
-         zbt, zbtu, zbtv,               &  ! temporary scalars
-         zmsku, zmskv
-      !!----------------------------------------------------------------------
-
-      ! 1. Advective trends and forcing trend
-      ! -------------------------------------
-
-      ! Mask the trends
-      SELECT CASE (ctype)
-
-      CASE ('DYN')              ! Momentum        
+      CHARACTER(len=3) ::   cpas                                              ! number of passage
+      REAL(wp) ::   zbt, zbtu, zbtv, zmsku, zmskv                             ! temporary scalars
+      !!----------------------------------------------------------------------
+
+      ! Control of optional arguments
+      cpas = 'fst'
+      IF( PRESENT(clpas) )  cpas = clpas
+
+      ! 1. Mask the trends
+      ! ------------------
+
+      SELECT CASE( ctype )
+      !
+      CASE( 'DYN' )              ! Momentum        
          DO jk = 1, jpk
             DO jj = 1, jpjm1
@@ -248,25 +216,24 @@
                   ptrd3dx(ji,jj,jk) = ptrd3dx(ji,jj,jk) * zmsku
                   ptrd3dy(ji,jj,jk) = ptrd3dy(ji,jj,jk) * zmskv
-               ENDDO
-            ENDDO
-         ENDDO
-
+               END DO
+            END DO
+         END DO
          ptrd3dx(jpi, : ,:) = 0.e0      ;      ptrd3dy(jpi, : ,:) = 0.e0
          ptrd3dx( : ,jpj,:) = 0.e0      ;      ptrd3dy( : ,jpj,:) = 0.e0
-
-      CASE ('TRA')              ! Tracers
+         !
+      CASE( 'TRA' )              ! Tracers
          DO jk = 1, jpk
             ptrd3dx(:,:,jk) = ptrd3dx(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:)
             ptrd3dy(:,:,jk) = ptrd3dy(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:)
-         ENDDO
-
+         END DO
+         !
       END SELECT   
 
-      ! 2. Basin averaged tracer/momentum trend
-      ! ---------------------------------------
+      ! 2. Basin averaged tracer/momentum trends
+      ! ----------------------------------------
       
-      SELECT CASE (ctype)
-
-      CASE ('DYN')              ! Momentum
+      SELECT CASE( ctype )
+      !
+      CASE( 'DYN' )              ! Momentum
          umo(ktrd) = 0.e0
          vmo(ktrd) = 0.e0
@@ -281,8 +248,10 @@
             END DO
          END DO
-
-      CASE ('TRA')              ! Tracers
-         tmo(ktrd) = 0.e0
-         smo(ktrd) = 0.e0
+         !
+      CASE( 'TRA' )              ! Tracers
+         IF( cpas == 'fst' )   THEN
+            tmo(ktrd) = 0.e0
+            smo(ktrd) = 0.e0
+         ENDIF
          DO jk = 1, jpkm1
             DO jj = 1, jpj
@@ -294,14 +263,14 @@
             END DO
          END DO
-
+         !
       END SELECT
 
-      ! 3. Basin averaged tracer/momentum square trend
-      ! ----------------------------------------------
+      ! 3. Basin averaged tracer/momentum square trends
+      ! -----------------------------------------------
       ! c a u t i o n: field now
       
-      SELECT CASE (ctype)
-
-      CASE ('DYN')              ! Momentum
+      SELECT CASE( ctype )
+      !
+      CASE( 'DYN' )              ! Momentum
          hke(ktrd) = 0.e0
          DO jk = 1, jpk
@@ -316,8 +285,10 @@
             END DO
          END DO
-
-      CASE ('TRA')              ! Tracers
-         t2(ktrd) = 0.e0
-         s2(ktrd) = 0.e0
+         !
+      CASE( 'TRA' )              ! Tracers
+         IF( cpas == 'fst' )   THEN
+            t2(ktrd) = 0.e0
+            s2(ktrd) = 0.e0
+         ENDIF
          DO jk = 1, jpk
             DO jj = 1, jpj
@@ -329,7 +300,7 @@
             END DO
          END DO
-
+         !
       END SELECT
-
+      !
    END SUBROUTINE trd_3d
 
@@ -340,26 +311,12 @@
       !!                  ***  ROUTINE trd_icp_init  ***
       !! 
-      !! ** Purpose :   
-      !!
-      !! ** Method  :
-      !!
-      !! History :
-      !!   9.0  !  03-09 (G. Madec)  Original code
-      !!        !  04-08 (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------
-      !! * Local declarations
-      INTEGER :: ji, jj, jk
-
+      !! ** Purpose :   Read the namtrd namelist
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk
       REAL(wp) ::   zmskt
 #if  defined key_trddyn
-      REAL(wp) ::   zmsku,zmskv
+      REAL(wp) ::   zmsku, zmskv
 #endif
-
-      NAMELIST/namtrd/ ntrd, nctls
-      !!----------------------------------------------------------------------
-
-      ! namelist namtrd : trend diagnostic
-      REWIND( numnam )
-      READ  ( numnam, namtrd )
+      !!----------------------------------------------------------------------
 
       IF(lwp) THEN
@@ -367,16 +324,5 @@
          WRITE(numout,*) 'trd_icp_init : integral constraints properties trends'
          WRITE(numout,*) '~~~~~~~~~~~~~'
-         WRITE(numout,*) ' '
-         WRITE(numout,*) '          Namelist namtrd : '
-         WRITE(numout,*) '             time step frequency trend       ntrd  = ', ntrd
       ENDIF
-
-      ! initialisation of BBL tracers lateral diffusion to zero
-      tldfbbl(:,:) = 0.e0   ;   sldfbbl(:,:) = 0.e0  
-      ! initialisation of BBL tracers lateral advection to zero
-      tladbbl(:,:) = 0.e0   ;   sladbbl(:,:) = 0.e0  
-      ! initialisation of workspace
-      tladi(:,:,:) = 0.e0  ;  tladj(:,:,:) = 0.e0
-      sladi(:,:,:) = 0.e0  ;  sladj(:,:,:) = 0.e0
 
       ! Total volume at t-points:
@@ -392,8 +338,5 @@
       IF( lk_mpp )   CALL mpp_sum( tvolt )   ! sum over the global domain
 
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) '          total ocean volume at T-point   tvolt = ',tvolt
-      ENDIF
+      IF(lwp) WRITE(numout,*) '                total ocean volume at T-point   tvolt = ',tvolt
 
 #if  defined key_trddyn
@@ -419,12 +362,10 @@
 
       IF(lwp) THEN
-         WRITE(numout,*) '          total ocean volume at U-point   tvolu = ',tvolu
-         WRITE(numout,*) '          total ocean volume at V-point   tvolv = ',tvolv
-         WRITE(numout,*) ' '
+         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
-
 
 
@@ -434,21 +375,10 @@
       !! 
       !! ** Purpose :  write dynamic trends in ocean.output 
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt                                  ! ocean time-step index
       !!
-      !! ** Method  :
-      !!
-      !! History :
-      !!   9.0  !  03-09  (G. Madec)  Original code
-      !!        !  04-08  (C. Talandier)  New trends organization
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-      INTEGER ::   ji, jj, jk
-      REAL(wp) ::   &
-         ze1e2w,zcof,        &  !    "         "
-         zbe1ru, zbe2rv,     &  !    "         "
-         zbtr, ztz, zth 
-
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-               zkepe, zkx, zky, zkz              ! temporary arrays
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   ze1e2w, zcof, zbe1ru, zbe2rv, zbtr, ztz, zth   !    "      scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zkepe, zkx, zky, zkz   ! temporary arrays
       !!----------------------------------------------------------------------
 
@@ -462,12 +392,12 @@
          ! c a u t i o n here, trends are computed at kt+1 (now , but after the swap)
 
-         zkx(:,:,:) = 0.e0
-         zky(:,:,:) = 0.e0
-         zkz(:,:,:) = 0.e0
+         zkx(:,:,:)   = 0.e0
+         zky(:,:,:)   = 0.e0
+         zkz(:,:,:)   = 0.e0
          zkepe(:,:,:) = 0.e0
    
          CALL eos( tn, sn, rhd, rhop )       ! now potential and in situ densities
 
-         ! 4.1 Density flux at w-point
+         ! Density flux at w-point
          DO jk = 2, jpk
             DO jj = 1, jpj
@@ -478,5 +408,5 @@
             END DO
          END DO
-         zkz  (:,:, 1 ) = 0.e0
+         zkz(:,:,1) = 0.e0
          
          ! Density flux at u and v-points
@@ -524,9 +454,9 @@
          ! ---------------------------------
          IF( lk_mpp ) THEN
-               CALL mpp_sum( peke )
-               CALL mpp_sum( umo , 11 )
-               CALL mpp_sum( vmo , 11 )
-               CALL mpp_sum( hke , 10 )
-         END IF
+            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
@@ -537,21 +467,23 @@
             WRITE (numout,*)
             WRITE (numout,9500) kt
-            WRITE (numout,9501) umo( 1) / tvolu, vmo( 1) / tvolv
-            WRITE (numout,9502) umo( 2) / tvolu, vmo( 2) / tvolv
-            WRITE (numout,9503) umo( 3) / tvolu, vmo( 3) / tvolv
-            WRITE (numout,9504) umo( 4) / tvolu, vmo( 4) / tvolv
-            WRITE (numout,9505) umo( 5) / tvolu, vmo( 5) / tvolv
-            WRITE (numout,9506) umo( 6) / tvolu, vmo( 6) / tvolv
-            WRITE (numout,9507) umo( 7) / tvolu, vmo( 7) / tvolv
-            WRITE (numout,9508) umo( 8) / tvolu, vmo( 8) / tvolv
-            WRITE (numout,9509) umo(10) / tvolu, vmo(10) / tvolv
-            WRITE (numout,9510) umo( 9) / tvolu, vmo( 9) / tvolv
-            WRITE (numout,9511) umo(11) / tvolu, vmo(11) / tvolv
+            WRITE (numout,9501) umo(jpicpd_hpg) / tvolu, vmo(jpicpd_hpg) / tvolv
+            WRITE (numout,9502) umo(jpicpd_keg) / tvolu, vmo(jpicpd_keg) / tvolv
+            WRITE (numout,9503) umo(jpicpd_rvo) / tvolu, vmo(jpicpd_rvo) / tvolv
+            WRITE (numout,9504) umo(jpicpd_pvo) / tvolu, vmo(jpicpd_pvo) / tvolv
+            WRITE (numout,9505) umo(jpicpd_ldf) / tvolu, vmo(jpicpd_ldf) / tvolv
+            WRITE (numout,9506) umo(jpicpd_zad) / tvolu, vmo(jpicpd_zad) / tvolv
+            WRITE (numout,9507) umo(jpicpd_zdf) / tvolu, vmo(jpicpd_zdf) / tvolv
+            WRITE (numout,9508) umo(jpicpd_spg) / tvolu, vmo(jpicpd_spg) / tvolv
+            WRITE (numout,9509) umo(jpicpd_swf) / tvolu, vmo(jpicpd_swf) / tvolv
+            WRITE (numout,9510) umo(jpicpd_dat) / tvolu, vmo(jpicpd_dat) / tvolv
+            WRITE (numout,9511) umo(jpicpd_bfr) / tvolu, vmo(jpicpd_bfr) / tvolv
             WRITE (numout,9512)
             WRITE (numout,9513)                                                 &
-            &     (  umo(1) + umo(2) + umo(3) + umo( 4) + umo( 5) + umo(6)    &
-            &      + umo(7) + umo(8) + umo(9) + umo(10) + umo(11) ) / tvolu,   &
-            &     (  vmo(1) + vmo(2) + vmo(3) + vmo( 4) + vmo( 5) + vmo(6)    &
-            &      + vmo(7) + vmo(8) + vmo(9) + vmo(10) + vmo(11) ) / tvolv
+            &     (  umo(jpicpd_hpg) + umo(jpicpd_keg) + umo(jpicpd_rvo) + umo(jpicpd_pvo) + umo(jpicpd_ldf)   &
+            &      + umo(jpicpd_zad) + umo(jpicpd_zdf) + umo(jpicpd_spg) + umo(jpicpd_dat) + umo(jpicpd_swf)   &
+            &      + umo(jpicpd_bfr) ) / tvolu,   &
+            &     (  vmo(jpicpd_hpg) + vmo(jpicpd_keg) + vmo(jpicpd_rvo) + vmo(jpicpd_pvo) + vmo(jpicpd_ldf)   &
+            &      + vmo(jpicpd_zad) + vmo(jpicpd_zdf) + vmo(jpicpd_spg) + vmo(jpicpd_dat) + vmo(jpicpd_swf)   &
+            &      + vmo(jpicpd_bfr) ) / tvolv
          ENDIF
 
@@ -565,5 +497,5 @@
  9507    FORMAT(' vertical diffusion         u= ', e20.13, '    v= ', e20.13)
  9508    FORMAT(' surface pressure gradient  u= ', e20.13, '    v= ', e20.13)
- 9509    FORMAT(' forcing term               u= ', e20.13, '    v= ', e20.13)
+ 9509    FORMAT(' surface wind forcing       u= ', e20.13, '    v= ', e20.13)
  9510    FORMAT(' dampimg term               u= ', e20.13, '    v= ', e20.13)
  9511    FORMAT(' bottom flux                u= ', e20.13, '    v= ', e20.13)
@@ -575,18 +507,18 @@
             WRITE (numout,*)
             WRITE (numout,9520) kt
-            WRITE (numout,9521) hke( 1) / tvolt
-            WRITE (numout,9522) hke( 2) / tvolt
-            WRITE (numout,9523) hke( 3) / tvolt
-            WRITE (numout,9524) hke( 4) / tvolt
-            WRITE (numout,9525) hke( 5) / tvolt
-            WRITE (numout,9526) hke( 6) / tvolt
-            WRITE (numout,9527) hke( 7) / tvolt
-            WRITE (numout,9528) hke( 8) / tvolt
-            WRITE (numout,9529) hke(10) / tvolt
-            WRITE (numout,9530) hke( 9) / tvolt
+            WRITE (numout,9521) hke(jpicpd_hpg) / tvolt
+            WRITE (numout,9522) hke(jpicpd_keg) / tvolt
+            WRITE (numout,9523) hke(jpicpd_rvo) / tvolt
+            WRITE (numout,9524) hke(jpicpd_pvo) / tvolt
+            WRITE (numout,9525) hke(jpicpd_ldf) / tvolt
+            WRITE (numout,9526) hke(jpicpd_zad) / tvolt
+            WRITE (numout,9527) hke(jpicpd_zdf) / tvolt
+            WRITE (numout,9528) hke(jpicpd_spg) / tvolt
+            WRITE (numout,9529) hke(jpicpd_swf) / tvolt
+            WRITE (numout,9530) hke(jpicpd_dat) / tvolt
             WRITE (numout,9531)
             WRITE (numout,9532)   &
-            &     (  hke(1) + hke(2) + hke(3) + hke(4) + hke(5) + hke(6)   &
-            &      + hke(7) + hke(8) + hke(9) + hke(10) ) / tvolt
+            &     (  hke(jpicpd_hpg) + hke(jpicpd_keg) + hke(jpicpd_rvo) + hke(jpicpd_pvo) + hke(jpicpd_ldf)   &
+            &      + hke(jpicpd_zad) + hke(jpicpd_zdf) + hke(jpicpd_spg) + hke(jpicpd_dat) + hke(jpicpd_swf) ) / tvolt
          ENDIF
 
@@ -600,5 +532,5 @@
  9527    FORMAT(' vertical diffusion        u2= ', e20.13)
  9528    FORMAT(' surface pressure gradient u2= ', e20.13)
- 9529    FORMAT(' forcing term              u2= ', e20.13)
+ 9529    FORMAT(' surface wind forcing      u2= ', e20.13)
  9530    FORMAT(' dampimg term              u2= ', e20.13)
  9531    FORMAT(' --------------------------------------------------')
@@ -609,32 +541,32 @@
             WRITE (numout,*)
             WRITE (numout,9540) kt
-            WRITE (numout,9541) ( hke(2) + hke(3) + hke(6) ) / tvolt
-            WRITE (numout,9542) ( hke(2) + hke(6) ) / tvolt
-            WRITE (numout,9543) ( hke(4) ) / tvolt
-            WRITE (numout,9544) ( hke(3) ) / tvolt
-            WRITE (numout,9545) ( hke(8) ) / tvolt
-            WRITE (numout,9546) ( hke(5) ) / tvolt
-            WRITE (numout,9547) ( hke(7) ) / tvolt
-            WRITE (numout,9548) ( hke(1) ) / tvolt, rpktrd / tvolt
+            WRITE (numout,9541) ( hke(jpicpd_keg) + hke(jpicpd_rvo) + hke(jpicpd_zad) ) / tvolt
+            WRITE (numout,9542) ( hke(jpicpd_keg) + hke(jpicpd_zad) ) / tvolt
+            WRITE (numout,9543) ( hke(jpicpd_pvo) ) / tvolt
+            WRITE (numout,9544) ( hke(jpicpd_rvo) ) / tvolt
+            WRITE (numout,9545) ( hke(jpicpd_spg) ) / tvolt
+            WRITE (numout,9546) ( hke(jpicpd_ldf) ) / tvolt
+            WRITE (numout,9547) ( hke(jpicpd_zdf) ) / tvolt
+            WRITE (numout,9548) ( hke(jpicpd_hpg) ) / tvolt, rpktrd / tvolt
+            WRITE (numout,*)
+            WRITE (numout,*)
          ENDIF
 
  9540    FORMAT(' energetic consistency at it= ', i6, ' :', /' =========================================')
  9541    FORMAT(' 0 = non linear term(true if key_vorenergy or key_combined): ', e20.13)
- 9542    FORMAT(' 0 = ke gradient + vertical advection              : ', e20.13)
+ 9542    FORMAT(' 0 = ke gradient + vertical advection                      : ', e20.13)
  9543    FORMAT(' 0 = coriolis term  (true if key_vorenergy or key_combined): ', e20.13)
- 9544    FORMAT(' 0 = uh.( rot(u) x uh ) (true if enstrophy conser.)    : ', 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)
-
+ 9544    FORMAT(' 0 = uh.( rot(u) x uh ) (true if enstrophy conser.)        : ', 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
-
+      !
    END SUBROUTINE trd_dwr
-
-
 
 
@@ -644,14 +576,6 @@
       !! 
       !! ** Purpose :  write active tracers trends in ocean.output 
-      !!
-      !! ** Method  :
-      !!
-      !! History :
-      !!   9.0  !  03-09  (G. Madec)  Original code
-      !!        !  04-08  (C. Talandier)  New trends organization
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !!----------------------------------------------------------------------
 
@@ -664,8 +588,8 @@
          ! -------------------------------
          IF( lk_mpp ) THEN
-            CALL mpp_sum( tmo, 10 )   
-            CALL mpp_sum( smo, 10 )
-            CALL mpp_sum( t2 , 10 )
-            CALL mpp_sum( s2 , 10 )
+            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
 
@@ -677,17 +601,17 @@
             WRITE (numout,*)
             WRITE (numout,9400) kt
-            WRITE (numout,9401) tmo(1) / tvolt, smo(1) / tvolt
-            WRITE (numout,9402) tmo(2) / tvolt, smo(2) / tvolt
-            WRITE (numout,9403) tmo(3) / tvolt, smo(3) / tvolt
-            WRITE (numout,9404) tmo(4) / tvolt, smo(4) / tvolt
-            WRITE (numout,9405) tmo(5) / tvolt, smo(5) / tvolt
-            WRITE (numout,9406) tmo(6) / tvolt, smo(6) / tvolt
-            WRITE (numout,9407) tmo(7) / tvolt
-            WRITE (numout,9408) tmo(8) / tvolt, smo(8) / tvolt
-            WRITE (numout,9409)
-            WRITE (numout,9410) (  tmo(1) + tmo(2) + tmo(3) + tmo(4)              &
-            &                    + tmo(5) + tmo(6) + tmo(7) + tmo(8) ) / tvolt,   &
-            &                   (  smo(1) + smo(2) + smo(3) + smo(4)              &
-            &                    + smo(5) + smo(6)           + smo(8) ) / tvolt
+            WRITE (numout,9401) (tmo(jpicpt_xad)+tmo(jpicpt_yad))/ tvolt, (smo(jpicpt_xad)+smo(jpicpt_yad))/ tvolt
+            WRITE (numout,9402)  tmo(jpicpt_zad) / tvolt, smo(jpicpt_zad) / tvolt
+            WRITE (numout,9403)  tmo(jpicpt_ldf) / tvolt, smo(jpicpt_ldf) / tvolt
+            WRITE (numout,9404)  tmo(jpicpt_zdf) / tvolt, smo(jpicpt_zdf) / tvolt
+            WRITE (numout,9405)  tmo(jpicpt_npc) / tvolt, smo(jpicpt_npc) / tvolt
+            WRITE (numout,9406)  tmo(jpicpt_dmp) / tvolt, smo(jpicpt_dmp) / tvolt
+            WRITE (numout,9407)  tmo(jpicpt_qsr) / tvolt
+            WRITE (numout,9408)  tmo(jpicpt_nsr) / tvolt, smo(jpicpt_nsr) / tvolt
+            WRITE (numout,9409) 
+            WRITE (numout,9410) (  tmo(jpicpt_xad) + tmo(jpicpt_yad) + tmo(jpicpt_zad) + tmo(jpicpt_ldf) + tmo(jpicpt_zdf)   &
+            &                    + tmo(jpicpt_npc) + tmo(jpicpt_dmp) + tmo(jpicpt_qsr) + tmo(jpicpt_nsr) ) / tvolt,   &
+            &                   (  smo(jpicpt_xad) + smo(jpicpt_yad) + smo(jpicpt_zad) + smo(jpicpt_ldf) + smo(jpicpt_zdf)   &
+            &                    + smo(jpicpt_npc) + smo(jpicpt_dmp)                   + smo(jpicpt_nsr) ) / tvolt
          ENDIF
 
@@ -698,8 +622,8 @@
 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)
+9405     FORMAT(' static instability mixing   ',e20.13,'     ',e20.13)
 9406     FORMAT(' damping term                ',e20.13,'     ',e20.13)
-9407     FORMAT(' penetrative qsr             ',e20.13,'     ',e20.13)
-9408     FORMAT(' forcing 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)
@@ -710,17 +634,17 @@
             WRITE (numout,*)
             WRITE (numout,9420) kt
-            WRITE (numout,9421) t2(1) / tvolt, s2(1) / tvolt
-            WRITE (numout,9422) t2(2) / tvolt, s2(2) / tvolt
-            WRITE (numout,9423) t2(3) / tvolt, s2(3) / tvolt
-            WRITE (numout,9424) t2(4) / tvolt, s2(4) / tvolt
-            WRITE (numout,9425) t2(5) / tvolt, s2(5) / tvolt
-            WRITE (numout,9426) t2(6) / tvolt, s2(6) / tvolt
-            WRITE (numout,9427) t2(7) / tvolt
-            WRITE (numout,9428) t2(8) / tvolt, s2(8) / tvolt
+            WRITE (numout,9421) ( t2(jpicpt_xad)+t2(jpicpt_yad) )/ tvolt, ( s2(jpicpt_xad)+s2(jpicpt_yad) )/ tvolt
+            WRITE (numout,9422)   t2(jpicpt_zad) / tvolt, s2(jpicpt_zad) / tvolt
+            WRITE (numout,9423)   t2(jpicpt_ldf) / tvolt, s2(jpicpt_ldf) / tvolt
+            WRITE (numout,9424)   t2(jpicpt_zdf) / tvolt, s2(jpicpt_zdf) / tvolt
+            WRITE (numout,9425)   t2(jpicpt_npc) / tvolt, s2(jpicpt_npc) / tvolt
+            WRITE (numout,9426)   t2(jpicpt_dmp) / tvolt, s2(jpicpt_dmp) / tvolt
+            WRITE (numout,9427)   t2(jpicpt_qsr) / tvolt
+            WRITE (numout,9428)   t2(jpicpt_nsr) / tvolt, s2(jpicpt_nsr) / tvolt
             WRITE (numout,9429)
-            WRITE (numout,9430) (  t2(1) + t2(2) + t2(3) + t2(4)              &
-            &                    + t2(5) + t2(6) + t2(7) + t2(8) ) / tvolt,   &
-            &                   (  s2(1) + s2(2) + s2(3) + s2(4)              &
-            &                    + s2(5) + s2(6)          + s2(8) ) / tvolt
+            WRITE (numout,9430) (  t2(jpicpt_xad) + t2(jpicpt_yad) + t2(jpicpt_zad) + t2(jpicpt_ldf) + t2(jpicpt_zdf)   &
+            &                    + t2(jpicpt_npc) + t2(jpicpt_dmp) + t2(jpicpt_qsr) + t2(jpicpt_nsr) ) / tvolt,   &
+            &                   (  s2(jpicpt_xad) + s2(jpicpt_yad) + s2(jpicpt_zad) + s2(jpicpt_ldf) + s2(jpicpt_zdf)   &
+            &                    + s2(jpicpt_npc) + s2(jpicpt_dmp)                  + s2(jpicpt_nsr) ) / tvolt
          ENDIF
 
@@ -731,8 +655,8 @@
 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)
+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, '     ', e20.13)
-9428     FORMAT(' forcing 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)
@@ -743,12 +667,15 @@
             WRITE (numout,*)
             WRITE (numout,9440) kt
-            WRITE (numout,9441) ( tmo(1)+tmo(2) )/tvolt, ( smo(1)+smo(2) )/tvolt
-            WRITE (numout,9442)   tmo(3)/tvolt,  smo(3)/tvolt
-            WRITE (numout,9443)   tmo(4)/tvolt,  smo(4)/tvolt
-            WRITE (numout,9444)   tmo(5)/tvolt,  smo(5)/tvolt
-            WRITE (numout,9445) ( t2(1)+t2(2) )/tvolt, ( s2(1)+s2(2) )/tvolt
-            WRITE (numout,9446)   t2(3)/tvolt,   s2(3)/tvolt
-            WRITE (numout,9447)   t2(4)/tvolt,   s2(4)/tvolt
-            WRITE (numout,9448)   t2(5)/tvolt,   s2(5)/tvolt
+            WRITE (numout,9441) ( tmo(jpicpt_xad)+tmo(jpicpt_yad)+tmo(jpicpt_zad) )/tvolt,   &
+            &                   ( smo(jpicpt_xad)+smo(jpicpt_yad)+smo(jpicpt_zad) )/tvolt
+            WRITE (numout,9442)   tmo(jpicpt_zl1)/tvolt,  smo(jpicpt_zl1)/tvolt
+            WRITE (numout,9443)   tmo(jpicpt_ldf)/tvolt,  smo(jpicpt_ldf)/tvolt
+            WRITE (numout,9444)   tmo(jpicpt_zdf)/tvolt,  smo(jpicpt_zdf)/tvolt
+            WRITE (numout,9445)   tmo(jpicpt_npc)/tvolt,  smo(jpicpt_npc)/tvolt
+            WRITE (numout,9446) ( t2(jpicpt_xad)+t2(jpicpt_yad)+t2(jpicpt_zad) )/tvolt,    &
+            &                   ( s2(jpicpt_xad)+s2(jpicpt_yad)+s2(jpicpt_zad) )/tvolt
+            WRITE (numout,9447)   t2(jpicpt_ldf)/tvolt,   s2(jpicpt_ldf)/tvolt
+            WRITE (numout,9448)   t2(jpicpt_zdf)/tvolt,   s2(jpicpt_zdf)/tvolt
+            WRITE (numout,9449)   t2(jpicpt_npc)/tvolt,   s2(jpicpt_npc)/tvolt
          ENDIF
 
@@ -756,15 +683,16 @@
             ' :         temperature','                salinity',/,   &
             ' ==================================')
-9441     FORMAT(' 0 = horizontal+vertical advection      ',e20.13,'       ',e20.13)
-9442     FORMAT(' 0 = horizontal diffusion               ',e20.13,'       ',e20.13)
-9443     FORMAT(' 0 = vertical diffusion                 ',e20.13,'       ',e20.13)
-9444     FORMAT(' 0 = static instability mixing          ',e20.13,'       ',e20.13)
-9445     FORMAT(' 0 = horizontal+vertical advection * t  ',e20.13,'       ',e20.13)
-9446     FORMAT(' 0 > horizontal diffusion          * t  ',e20.13,'       ',e20.13)
-9447     FORMAT(' 0 > vertical diffusion            * t  ',e20.13,'       ',e20.13)
-9448     FORMAT(' 0 > static instability mixing     * t  ',e20.13,'       ',e20.13)
-
+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
 
@@ -773,39 +701,19 @@
    !!   Default case :                                         Empty module
    !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trdtra = .FALSE.   !: tracers  trend flag
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trddyn = .FALSE.   !: momentum trend flag
 CONTAINS
-   SUBROUTINE trd_2d(ptrd2dx, ptrd2dy, ktrd , ctype)       ! Empty routine
-      REAL, DIMENSION(:,:,:), INTENT( inout ) ::   &
-          ptrd2dx,                     &   ! Temperature or U trend 
-          ptrd2dy                          ! Salinity    or V trend
-      INTEGER, INTENT( in ) ::   ktrd      ! momentum or tracer trend index
-      CHARACTER(len=3), INTENT( in ) ::   &
-         ctype                             ! momentum or tracers trends type
-      WRITE(*,*) 'trd_2d: You should not have seen this print! error ?', ptrd2dx(1,1,1)
-      WRITE(*,*) ' "   ": You should not have seen this print! error ?', ptrd2dy(1,1,1)
-      WRITE(*,*) ' "   ": You should not have seen this print! error ?', ktrd
-      WRITE(*,*) ' "   ": You should not have seen this print! error ?', ctype
+   SUBROUTINE trd_2d( ptrd2dx, ptrd2dy, ktrd , ctype )       ! Empty routine
+      REAL, DIMENSION(:,:) ::   ptrd2dx, ptrd2dy
+      WRITE(*,*) 'trd_2d: You should not have seen this print! error ?', ptrd2dx(1,1), ptrd2dy(1,1), ktrd, ctype
    END SUBROUTINE trd_2d
-   SUBROUTINE trd_3d(ptrd3dx, ptrd3dy, ktrd , ctype)       ! Empty routine
-      REAL, DIMENSION(:,:,:), INTENT( inout ) ::   &
-          ptrd3dx,                     &   ! Temperature or U trend 
-          ptrd3dy                          ! Salinity    or V trend
-      INTEGER, INTENT( in ) ::   ktrd      ! momentum or tracer trend index
-      CHARACTER(len=3), INTENT( in ) ::   &
-         ctype                             ! momentum or tracers trends type
-      WRITE(*,*) 'trd_3d: You should not have seen this print! error ?', ptrd3dx(1,1,1)
-      WRITE(*,*) ' "   ": You should not have seen this print! error ?', ptrd3dy(1,1,1)
-      WRITE(*,*) ' "   ": You should not have seen this print! error ?', ktrd
-      WRITE(*,*) ' "   ": You should not have seen this print! error ?', ctype
+   SUBROUTINE trd_3d( ptrd3dx, ptrd3dy, ktrd , ctype )       ! Empty routine
+      REAL, DIMENSION(:,:,:) ::   ptrd3dx, ptrd3dy
+      WRITE(*,*) 'trd_3d: You should not have seen this print! error ?', ptrd3dx(1,1,1), ptrd3dy(1,1,1), ktrd, ctype
    END SUBROUTINE trd_3d
    SUBROUTINE trd_icp_init               ! Empty routine
    END SUBROUTINE trd_icp_init
    SUBROUTINE trd_dwr( kt )          ! Empty routine
-      INTEGER, INTENT(in) :: kt
       WRITE(*,*) 'trd_dwr: You should not have seen this print! error ?', kt
    END SUBROUTINE trd_dwr
    SUBROUTINE trd_twr( kt )          ! Empty routine
-      INTEGER, INTENT(in) :: kt
       WRITE(*,*) 'trd_twr: You should not have seen this print! error ?', kt
    END SUBROUTINE trd_twr
Index: trunk/NEMO/OPA_SRC/TRD/trdicp_oce.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRD/trdicp_oce.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRD/trdicp_oce.F90	(revision 503)
@@ -6,13 +6,7 @@
 
    !!----------------------------------------------------------------------
-   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
-   !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
    !!   'key_trdtra'   or                         tracer trends diagnostics
    !!   'key_trddyn'                            momentum trends diagnostics
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE par_oce                 ! ocean parameters
 
@@ -20,107 +14,81 @@
    PUBLIC
 
-   !! Namelist parameters
-   !!----------------------------------------------------------------------
-   INTEGER  ::      & !!: namdia :  diagnostics on dynamics and/or tracer trends
-      ntrd  = 10 ,  &  !: time step frequency dynamics and tracers trends
-      nctls =  0       !: control surface type for trends vertical integration
+   !! * Shared module variables
+#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
 
    !! Tracers trends diagnostics parameters
    !!---------------------------------------------------------------------
-   INTEGER, PARAMETER ::            &  !: trends index
-      jpttdlad = 1,   &  !: tracer horizontal advection
-      jpttdzad = 2,   &  !: tracer vertical advection
-      jpttdldf = 3,   &  !: tracer horizontal diffusion
-      jpttdzdf = 4,   &  !: tracer vertical diffusion
-      jpttdnpc = 5,   &  !: tracer non penetrative convection
-      jpttddoe = 6,   &  !: tracer D.amping O.r vertical E.iv
-      jpttdqsr = 7,   &  !: tracer penetrative solar radiation
-      jpttdnsr = 8       !: tracer non solar radiation
+   INTEGER, PARAMETER ::   &  !: => tracer trends indexes <=
+        jpicpt_xad =  1,   &  !: x- horizontal advection
+        jpicpt_yad =  2,   &  !: y- horizontal advection
+        jpicpt_zad =  3,   &  !: z- vertical   advection
+        jpicpt_ldf =  4,   &  !: lateral       diffusion
+        jpicpt_zdf =  5,   &  !: vertical diffusion (Kz)
+        jpicpt_bbc =  6,   &  !: Bottom Boundary Condition (geoth. flux) 
+        jpicpt_bbl =  7,   &  !: Bottom Boundary Layer (diffusive/convective)
+        jpicpt_npc =  8,   &  !: static instability mixing
+        jpicpt_dmp =  9,   &  !: damping
+        jpicpt_qsr = 10,   &  !: penetrative solar radiation
+        jpicpt_nsr = 11,   &  !: non solar radiation
+        jpicpt_zl1 = 12       !: first level vertical flux
 
+   INTEGER, PARAMETER ::   &  !: => Total tracer trends indexes <=
+        jptot_tra = 12        !: change it when adding/removing one indice above
+   
    !! Momentum trends diagnostics parameters
    !!---------------------------------------------------------------------
-   INTEGER, PARAMETER ::            &  !: trends index
-      jpdtdhpg =  1,   &  !: dynamic hydrostatic pressure gradient 
-      jpdtdkeg =  2,   &  !: dynamic kinetic energy gradient
-      jpdtdrvo =  3,   &  !: dynamic relative vorticity
-      jpdtdpvo =  4,   &  !: dynamic planetary vorticity
-      jpdtdldf =  5,   &  !: dynamic lateral diffusion
-      jpdtdzad =  6,   &  !: dynamic vertical advection
-      jpdtdzdf =  7,   &  !: dynamic vertical diffusion
-      jpdtdspg =  8,   &  !: dynamic surface pressure gradient
-      jpdtddat =  9,   &  !: dynamic damping term
-      jpdtdswf = 10,   &  !: dynamic surface wind forcing
-      jpdtdbfr = 11       !: dynamic bottom friction 
+   INTEGER, PARAMETER ::   &  !: => dynamic trends indexes <=
+        jpicpd_hpg =  1,   &  !: hydrostatic pressure gradient 
+        jpicpd_keg =  2,   &  !: kinetic energy gradient
+        jpicpd_rvo =  3,   &  !: relative vorticity
+        jpicpd_pvo =  4,   &  !: planetary vorticity
+        jpicpd_ldf =  5,   &  !: lateral diffusion
+        jpicpd_zad =  6,   &  !: vertical advection
+        jpicpd_zdf =  7,   &  !: vertical diffusion
+        jpicpd_spg =  8,   &  !: surface pressure gradient
+        jpicpd_dat =  9,   &  !: damping term
+        jpicpd_swf = 10,   &  !: surface wind forcing
+        jpicpd_bfr = 11       !: bottom friction 
 
-   REAL, DIMENSION(jpi,jpj) ::   &  !:
-      tldfbbl, sldfbbl,          &  ! Temperature/salinity lateral diffusion trends
-      !                             ! in the BBL  
-      tladbbl, sladbbl              ! Temperature/salinity lateral advection trends 
-      !                             ! in the BBL
-
-   REAL, DIMENSION(jpi,jpj,jpk) ::   &  !:
-      tladi, sladi,                  &  ! Temp./sal. MUSCL OR TVD advection fluxes 
-      !                                 ! terms along i- 
-      tladj, sladj                      ! Temp./sal. MUSCL OR TVD advection fluxes 
-      !                                 ! terms along j- 
-#if defined key_ldfslp
-   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &  !:
-      uldftrd, vldftrd     !: lateral diffusion trend in isopycnal case
-#endif
+   INTEGER, PARAMETER ::   &  !: => Total dynamic trends indexes <=
+        jptot_dyn = 11        !: change it when adding/removing one indice above
+   
 #if   defined key_trdtra   ||   defined key_trddyn   ||   defined key_esopa
 
    !! Variables used for diagnostics
    !!---------------------------------------------------------------------
-   REAL(wp) ::   &  !:
-      tvolt,     &  !: volume of the whole ocean computed at t-points
-      tvolu,     &  !: volume of the whole ocean computed at u-points
-      tvolv         !: volume of the whole ocean computed at v-points
+   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
 
    !! Tracers trends diagnostics variables
    !!---------------------------------------------------------------------
-   REAL(wp), DIMENSION(10) ::   &  !:
-      tmo, smo         !: tracers trends average 
-      !                !  tmo(1) : horizontal advection
-      !                !  tmo(2) : vertical advection
-      !                !  tmo(3) : horizontal diffusion
-      !                !  tmo(4) : vertical diffusion
-      !                !  tmo(5) : static instability
-      !                !  tmo(6) : damping OR vertical EIV
-      !                !  tmo(7) : penetrative solar radiation (T only)
-   REAL(wp), DIMENSION(10) ::   &  !:
-      t2, s2           !: tracers square trends average 
-      !                !  t2(1) : horizontal advection
-      !                !  t2(2) : vertical advection
-      !                !  t2(3) : horizontal diffusion
-      !                !  t2(4) : vertical diffusion
-      !                !  t2(5) : static instability
-      !                !  t2(6) : damping OR vertical EIV
-      !                !  t2(7) : penetrative solar radiation (T only)
+   REAL(wp), DIMENSION(jptot_tra) ::   tmo, smo         !: tracers trends average 
+   REAL(wp), DIMENSION(jptot_tra) ::   t2, s2           !: tracers square trends average 
    
    !! Momentum trends diagnostics variables
    !!---------------------------------------------------------------------
-   REAL(wp), DIMENSION(11) ::   &  !:
-      umo, vmo         !: momentum trends average 
-      !                !  umo(1) : hydrostatic pressure gradient
-      !                !  umo(2) : kinetic energy
-      !                !  umo(3) : lateral diffusion geo-pot
-      !                !  umo(4) : 
-      !                !  umo(5) : lateral diffusion
-      !                !  umo(6) : vertical advection
-      !                !  umo(7) : vertical diffusion
-      !                !  umo(8) : surface pressure gradient
-      !                !  umo(9) : 
-
-   REAL(wp), DIMENSION(10) ::   &  !:
-      hke              !: momentum square trends average 
-      !                !  hke(1) : horizontal advection
-      !                !  hke(2) : vertical advection
-
-   REAL(wp) ::   &  !:
-      rpktrd,    &  !: potential to kinetic energy conversion
-      peke          !: conversion potential energy - kinetic energy trend
+   REAL(wp), DIMENSION(jptot_dyn) ::   umo, vmo         !: momentum trends average 
+   REAL(wp), DIMENSION(jptot_dyn) ::   hke              !: momentum square trends average 
+   REAL(wp) ::   rpktrd   !: potential to kinetic energy conversion
+   REAL(wp) ::   peke     !: conversion potential energy - kinetic energy trend
 
 #endif
-
-  !!======================================================================
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!======================================================================
 END MODULE trdicp_oce
Index: trunk/NEMO/OPA_SRC/TRD/trdmld.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRD/trdmld.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRD/trdmld.F90	(revision 503)
@@ -4,7 +4,15 @@
    !! Ocean diagnostics:  mixed layer T-S trends 
    !!=====================================================================
+   !! History :       !  95-04  (J. Vialard)    Original code
+   !!                 !  97-02  (E. Guilyardi)  Adaptation global + base cmo
+   !!                 !  99-09  (E. Guilyardi)  Re-writing + netCDF output
+   !!            8.5  !  02-06  (G. Madec)      F90: Free form and module
+   !!            9.0  !  04-08  (C. Talandier)  New trends organization
+   !!                 !  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
@@ -12,5 +20,4 @@
    !!   trd_mld_init     : initialization step
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain variables
@@ -28,46 +35,19 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE diadimg         ! dimg direct access file format output
+   USE trdmld_rst , ONLY : trd_mld_rst_read  ! restart for diagnosing the ML trends
+   USE prtctl          ! Print control
 
    IMPLICIT NONE
    PRIVATE
 
-   !! * Accessibility
-   PUBLIC trd_mld        ! routine called by step.F90
-   PUBLIC trd_mld_init   ! routine called by opa.F90
-   PUBLIC trd_mld_zint   ! routine called by tracers routines
-
-   !! * Shared module variables
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trdmld = .TRUE.    !: momentum trend flag
-
-   !! * Module variables
-   INTEGER ::   &
-      nh_t, nmoymltrd,             &  ! ???
-      nidtrd,                      &
-      ndextrd1(jpi*jpj),           &
-      ndimtrd1
-   INTEGER, SAVE ::   &
-      ionce, icount,               &
-      idebug                          ! (0/1) set it to 1 in case of problem to have more print
-
-   INTEGER, DIMENSION(jpi,jpj) ::   &
-      nmld,                         & ! mixed layer depth
-      nbol                
-
-   REAL(wp), DIMENSION(jpi,jpj) ::   &
-      rmld   ,          &  ! mld depth (m) corresponding to nmld
-      tml    , sml  ,   &  ! average T and S over mixed layer
-      tmlb   , smlb ,   &  ! before tml and sml (kt-1)
-      tmlbb  , smlbb,   &  ! tml and sml at begining of the nwrite-1 
-      !                    ! timestep averaging period
-      tmlbn  , smlbn,   &  ! after tml and sml at time step after the
-      !                    ! begining of the NWRITE-1 timesteps
-      tmltrdm, smltrdm     !
-
-   REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-      tmltrd ,          &  ! total cumulative trends of temperature and 
-      smltrd ,          &  ! salinity over nwrite-1 time steps
-      wkx
-
-   CHARACTER(LEN=80) :: clname
+   PUBLIC   trd_mld        ! routine called by step.F90
+   PUBLIC   trd_mld_init   ! routine called by opa.F90
+   PUBLIC   trd_mld_zint   ! routine called by tracers routines
+
+   CHARACTER (LEN=40) ::  clhstnam         ! name of the trends NetCDF file
+   INTEGER ::   nh_t, nmoymltrd
+   INTEGER ::   nidtrd, ndextrd1(jpi*jpj)
+   INTEGER ::   ndimtrd1                        
+   INTEGER, SAVE ::  ionce, icount                   
 
    !! * Substitutions
@@ -83,114 +63,55 @@
 CONTAINS
 
-SUBROUTINE trd_mld_zint( pttrdmld, pstrdmld, ktrd, ctype )
+   SUBROUTINE trd_mld_zint( pttrdmld, pstrdmld, ktrd, ctype )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE trd_mld_zint  ***
       !! 
-      !! ** Purpose :   computation of vertically integrated T and S budgets
-      !!                from ocean surface down to control surface 
+      !! ** Purpose :   Compute the vertical average of the 3D fields given as arguments 
+      !!                to the subroutine. This vertical average is performed from ocean
+      !!                surface down to a chosen control surface.
       !!
       !! ** Method/usage :
-      !!      integration done over nwrite-1 time steps 
-      !!      Control surface can be either a mixed layer depth (time varying)
+      !!      The control surface can be either a mixed layer depth (time varying)
       !!      or a fixed surface (jk level or bowl). 
-      !!      Choose control surface with nctls in namelist NAMDIA.
-      !!      nctls = 0  : use mixed layer with density criterion 
-      !!      nctls = 1  : read index from file 'ctlsurf_idx'
-      !!      nctls > 1  : use fixed level surface jk = nctls
+      !!      Choose control surface with nctls in namelist NAMTRD :
+      !!        nctls = 0  : use mixed layer with density criterion 
+      !!        nctls = 1  : read index from file 'ctlsurf_idx'
+      !!        nctls > 1  : use fixed level surface jk = nctls
       !!      Note: in the remainder of the routine, the volume between the 
       !!            surface and the control surface is called "mixed-layer"
-      !!      Method check : if the control surface is fixed, the residual dh/dt
-      !!                     entrainment should be zero
-      !!
-      !! ** Action :
-      !!            /commld/   : rmld         mld depth corresponding to nmld
-      !!                         tml          average T over mixed layer
-      !!                         tmlb         tml at kt-1
-      !!                         tmlbb        tml at begining of the NWRITE-1 
-      !!                                      time steps averaging period
-      !!                         tmlbn        tml at time step after the 
-      !!                                      begining of the NWRITE-1 time
-      !!                                      steps averaging period
-      !!
-      !!                  mixed layer trends :
-      !!
-      !!                  tmltrd (,,1) = zonal advection
-      !!                  tmltrd (,,2) = meridional advection
-      !!                  tmltrd (,,3) = vertical advection
-      !!                  tmltrd (,,4) = lateral diffusion (horiz. component+Beckman)
-      !!                  tmltrd (,,5) = forcing
-      !!                  tmltrd (,,6) = entrainment due to vertical diffusion (TKE)
-      !!          if iso  tmltrd (,,7) = lateral diffusion (vertical component)
-      !!                  tmltrd (,,8) = eddy induced zonal advection
-      !!                  tmltrd (,,9) = eddy induced meridional advection
-      !!                  tmltrd (,,10) = eddy induced vertical advection
-      !!
-      !!                  tmltrdm(,) : total cumulative trends over nwrite-1 time steps
-      !!                  ztmltot(,) : dT/dt over the NWRITE-1 time steps 
-      !!                               averaging period (including Asselin 
-      !!                               terms)
-      !!                  ztmlres(,) : residual = dh/dt entrainment
-      !!
-      !!      trends output in netCDF format using ioipsl
-      !!
-      !! History :
-      !!        !  95-04  (J. Vialard)  Original code
-      !!        !  97-02  (E. Guilyardi)  Adaptation global + base cmo
-      !!        !  99-09  (E. Guilyardi)  Re-writing + netCDF output
-      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
-      !!   9.0  !  04-08  (C. Talandier) New trends organization
       !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
-
-      CHARACTER(len=2), INTENT( in ) ::   &
-         ctype                                ! surface/bottom (2D arrays) or
-                                              ! interior (3D arrays) physics
-
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   &
-         pttrdmld,                         &  ! Temperature trend 
-         pstrdmld                             ! Salinity    trend
-
-      !! * Local declarations
+      INTEGER, INTENT( in ) ::   ktrd                             ! ocean trend index
+      CHARACTER(len=2), INTENT( in ) :: ctype                     ! surface/bottom (2D arrays) or
+      !                                                           ! interior (3D arrays) physics
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::  pttrdmld ! temperature trend 
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::  pstrdmld ! salinity trend 
       INTEGER ::   ji, jj, jk, isum
-# if defined key_trabbl_dif
-      INTEGER ::   ikb
-# endif
-
-      REAL(wp), DIMENSION(jpi,jpj) ::   &
-         zvlmsk
+      REAL(wp), DIMENSION(jpi,jpj) ::  zvlmsk
       !!----------------------------------------------------------------------
 
+      ! I. Definition of control surface and associated fields
+      ! ------------------------------------------------------
+      !            ==> only once per time step <== 
+
       IF( icount == 1 ) THEN        
-
-         zvlmsk(:,:)   = 0.e0
-         tmltrd(:,:,:) = 0.e0
-         smltrd(:,:,:) = 0.e0
-         
-         ! This computation should be done only once per time step
-
-         !  ========================================================
-         !   I. definition of control surface and associated fields
-         !  ========================================================
-
-         !    I.1 set nmld(ji,jj) = index of first T point below control surface
-         !    -------------------                       or outside mixed-layer
-
-         IF( nctls == 0 ) THEN
-            ! control surface = mixed-layer with density criterion 
-            ! (array nmln computed in zdfmxl.F90)
-            nmld(:,:) = nmln(:,:)
-         ELSE IF( nctls == 1 ) THEN
-            ! control surface = read index from file 
+         !
+         tmltrd(:,:,:) = 0.e0    ;    smltrd(:,:,:) = 0.e0    ! <<< reset trend arrays to zero
+         
+         ! ... Set nmld(ji,jj) = index of first T point below control surf. or outside mixed-layer
+         IF( nctls == 0 ) THEN       ! * control surface = mixed-layer with density criterion 
+            nmld(:,:) = nmln(:,:)    ! array nmln computed in zdfmxl.F90
+         ELSE IF( nctls == 1 ) THEN  ! * control surface = read index from file 
             nmld(:,:) = nbol(:,:)
-         ELSE IF( nctls >= 2 ) THEN
-            ! control surface = model level
+         ELSE IF( nctls >= 2 ) THEN  ! * control surface = model level
             nctls = MIN( nctls, jpktrd - 1 )
             nmld(:,:) = nctls + 1
          ENDIF
 
-         IF( ionce == 1 ) THEN  ! compute ndextrd1 and ndimtrd1 only once
-            ! Check of validity : nmld(ji,jj) =< jpktrd
-            isum = 0
+         ! ... Compute ndextrd1 and ndimtrd1 only once
+         IF( ionce == 1 ) THEN
+            !
+            ! Check of validity : nmld(ji,jj) <= jpktrd
+            isum        = 0
+            zvlmsk(:,:) = 0.e0
 
             IF( jpktrd < jpk ) THEN 
@@ -215,118 +136,47 @@
             ENDIF                                
 
-            ! no more pass here
-            ionce = 0
-
-         ENDIF
-         
-         IF( idebug /= 0 ) THEN
-            ! CALL prihre (zvlmsk,jpi,jpj,1,jpi,2,1,jpj,2,3,numout)
-            WRITE(numout,*) ' debuging trd_mld_zint: I.1 done '  
-            CALL FLUSH(numout)
-         ENDIF
-
-
-         ! I.2 probability density function of presence in mixed-layer
-         ! --------------------------------
-         ! (i.e. weight of each grid point in vertical integration : wkx(ji,jj,jk)
-
-
-         ! initialize wkx with vertical scale factor in mixed-layer
-
+            ionce = 0                ! no more pass here
+            !
+         END IF
+         
+         ! ... Weights for vertical averaging
          wkx(:,:,:) = 0.e0
-         DO jk = 1, jpktrd
+         DO jk = 1, jpktrd             ! initialize wkx with vertical scale factor in mixed-layer
             DO jj = 1,jpj
                DO ji = 1,jpi
-                  IF( jk - nmld(ji,jj) < 0. )   wkx(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
+                  IF( jk - nmld(ji,jj) < 0.e0 )   wkx(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
                END DO
             END DO
          END DO
          
-         ! compute mixed-layer depth : rmld
-         
-         rmld(:,:) = 0.
+         rmld(:,:) = 0.e0                ! compute mixed-layer depth : rmld
          DO jk = 1, jpktrd
             rmld(:,:) = rmld(:,:) + wkx(:,:,jk)
          END DO
          
-         ! compute PDF
-
+         DO jk = 1, jpktrd             ! compute integration weights
+            wkx(:,:,jk) = wkx(:,:,jk) / MAX( 1., rmld(:,:) )
+         END DO
+
+         icount = 0                    ! <<< flag = off : control surface & integr. weights
+         !                             !     computed only once per time step
+      END IF
+
+      ! II. Vertical integration of trends in the mixed-layer
+      ! -----------------------------------------------------
+
+      SELECT CASE (ctype)
+      CASE ( '3D' )   ! mean T/S trends in the mixed-layer
          DO jk = 1, jpktrd
-            wkx(:,:,jk) = wkx(:,:,jk) / MAX( 1., rmld(:,:) )
-         END DO
-
-         IF( idebug /= 0 ) THEN
-            WRITE(numout,*) ' debuging trd_mld_zint: I.2 done '  
-            CALL FLUSH(numout)
-         ENDIF
-
-         ! Set counter icount to 0 to avoid this part at each time step
-         icount = 0
-
-      ENDIF
-
-
-      !  ====================================================
-      !   II. vertical integration of trends in mixed-layer
-      !  ====================================================
-
-      ! II.1 vertical integration of 3D and 2D trends
-      ! ---------------------------------------------
-
-      SELECT CASE (ctype)
-
-      CASE ('3D')       ! 3D treatment
-
-         ! trends terms in the mixed-layer
-         DO jk = 1, jpktrd
-            ! Temperature
-            tmltrd(:,:,ktrd) = tmltrd(:,:,ktrd) + pttrdmld(:,:,jk) * wkx(:,:,jk)   
-
-            ! Salinity
-            smltrd(:,:,ktrd) = smltrd(:,:,ktrd) + pstrdmld(:,:,jk) * wkx(:,:,jk)   
-         ENDDO
-
-      CASE ('2D')       ! 2D treatment
-
-         SELECT CASE (ktrd) 
-
-         CASE (jpmldldf)
-
-# if defined key_trabbl_dif
-               ! trends terms from Beckman over-flow parameterization
-               DO jj = 1,jpj
-                  DO ji = 1,jpi
-                     ikb = MAX( mbathy(ji,jj)-1, 1 )
-                     ! beckmann component -> horiz. part of lateral diffusion
-                     tmltrd(ji,jj,ktrd) = tmltrd(ji,jj,ktrd) + pttrdmld(ji,jj,1) * wkx(ji,jj,ikb)
-                     smltrd(ji,jj,ktrd) = smltrd(ji,jj,ktrd) + pstrdmld(ji,jj,1) * wkx(ji,jj,ikb)
-                  END DO
-               END DO
-# endif
-
-         CASE DEFAULT
-
-            ! trends terms at upper boundary of mixed-layer
-
-            ! forcing term (non penetrative)
-            ! Temperature
-            tmltrd(:,:,ktrd) = tmltrd(:,:,ktrd) + pttrdmld(:,:,1) * wkx(:,:,1)   
-
-            ! forcing term
-            ! Salinity
-            smltrd(:,:,ktrd) = smltrd(:,:,ktrd) + pstrdmld(:,:,1) * wkx(:,:,1)   
-
-         END SELECT
-
+            tmltrd(:,:,ktrd) = tmltrd(:,:,ktrd) + pttrdmld(:,:,jk) * wkx(:,:,jk)   ! temperature
+            smltrd(:,:,ktrd) = smltrd(:,:,ktrd) + pstrdmld(:,:,jk) * wkx(:,:,jk)   ! salinity
+         END DO
+      CASE ( '2D' )   ! forcing at upper boundary of the mixed-layer
+         tmltrd(:,:,ktrd) = tmltrd(:,:,ktrd) + pttrdmld(:,:,1) * wkx(:,:,1)        ! non penetrative
+         smltrd(:,:,ktrd) = smltrd(:,:,ktrd) + pstrdmld(:,:,1) * wkx(:,:,1)            
       END SELECT
-
-      IF( idebug /= 0 ) THEN
-         IF(lwp) WRITE(numout,*) ' debuging trd_mld_zint: II.1 done'  
-         CALL FLUSH(numout)
-      ENDIF
-
+      !
    END SUBROUTINE trd_mld_zint
-
-
+    
 
    SUBROUTINE trd_mld( kt )
@@ -334,25 +184,61 @@
       !!                  ***  ROUTINE trd_mld  ***
       !! 
-      !! ** Purpose :  computation of cumulated trends over analysis period
-      !!               and make outputs (NetCDF or DIMG format)
+      !! ** Purpose :  Compute and cumulate the mixed layer trends over an analysis
+      !!               period, and write NetCDF (or dimg) outputs.
       !!
       !! ** Method/usage :
+      !!          The stored trends can be chosen twofold (according to the ln_trdmld_instant 
+      !!          logical namelist variable) :
+      !!          1) to explain the difference between initial and final 
+      !!             mixed-layer T & S (where initial and final relate to the
+      !!             current analysis window, defined by ntrd in the namelist)
+      !!          2) to explain the difference between the current and previous 
+      !!             TIME-AVERAGED mixed-layer T & S (where time-averaging is
+      !!             performed over each analysis window).
       !!
-      !! History :
-      !!   9.0  !  04-08  (C. Talandier) New trends organization
+      !! ** Consistency check : 
+      !!        If the control surface is fixed ( nctls > 1 ), the residual term (dh/dt
+      !!        entrainment) should be zero, at machine accuracy. Note that in the case
+      !!        of time-averaged mixed-layer fields, this residual WILL NOT BE ZERO
+      !!        over the first two analysis windows (except if restart).
+      !!        N.B. For ORCA2_LIM, use e.g. ntrd=5, ucf=1., nctls=8
+      !!             for checking residuals.
+      !!             On a NEC-SX5 computer, this typically leads to:
+      !!                   O(1.e-20) temp. residuals (tml_res) when ln_trdmld_instant=.false.
+      !!                   O(1.e-21) temp. residuals (tml_res) when ln_trdmld_instant=.true.
+      !!
+      !! ** Action :
+      !!       At each time step, mixed-layer averaged trends are stored in the 
+      !!       tmltrd(:,:,jpmld_xxx) array (see trdmld_oce.F90 for definitions of jpmld_xxx).
+      !!       This array is known when trd_mld is called, at the end of the stp subroutine, 
+      !!       except for the purely vertical K_z diffusion term, which is embedded in the
+      !!       lateral diffusion trend.
+      !!
+      !!       In I), this K_z term is diagnosed and stored, thus its contribution is removed
+      !!       from the lateral diffusion trend.
+      !!       In II), the instantaneous mixed-layer T & S are computed, and misc. cumulative
+      !!       arrays are updated.
+      !!       In III), called only once per analysis window, we compute the total trends,
+      !!       along with the residuals and the Asselin correction terms.
+      !!       In IV), the appropriate trends are written in the trends NetCDF file.
+      !!
+      !! References :
+      !!       - Vialard & al.
+      !!       - See NEMO documentation (in preparation)
       !!----------------------------------------------------------------------
-      !! * Arguments
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
-
-      !! * Local declarations
+      !!
       INTEGER :: ji, jj, jk, jl, ik, it
-
-      REAL(wp) :: zmean, zavt
-
-      REAL(wp) ,DIMENSION(jpi,jpj) ::   &
-         ztmltot, ztmlres,              &
-         zsmltot, zsmlres,              & 
-         z2d
-
+      LOGICAL :: lldebug = .TRUE.
+      REAL(wp) :: zavt, zfn, zfn2
+      REAL(wp) ,DIMENSION(jpi,jpj) ::     &
+           ztmltot,  zsmltot,             & ! dT/dt over the anlysis window (including Asselin)
+           ztmlres,  zsmlres,             & ! residual = dh/dt entrainment term
+           ztmlatf,  zsmlatf,             & ! needed for storage only
+           ztmltot2, ztmlres2, ztmltrdm2, & ! \  working arrays to diagnose the trends
+           zsmltot2, zsmlres2, zsmltrdm2, & !  > associated with the time meaned ML T & S
+           ztmlatf2, zsmlatf2               ! /
+      REAL(wp), DIMENSION(jpi,jpj,jpltrd) ::  &
+           ztmltrd2, zsmltrd2               ! only needed for mean diagnostics
 #if defined key_dimgout
       INTEGER ::  iyear,imon,iday
@@ -361,65 +247,56 @@
       !!----------------------------------------------------------------------
 
-      ! I. trends terms at lower boundary of mixed-layer
-      ! ------------------------------------------------
-
+      ! ======================================================================
+      ! I. Diagnose the purely vertical (K_z) diffusion trend
+      ! ======================================================================
+
+      ! ... These terms can be estimated by flux computation at the lower boundary of the ML 
+      !     (we compute (-1/h) * K_z * d_z( T ) and (-1/h) * K_z * d_z( S ))
       DO jj = 1,jpj
          DO ji = 1,jpi
-            
             ik = nmld(ji,jj)
-            
-            ! Temperature
-            ! entrainment due to vertical diffusion
-            !       - due to vertical mixing scheme (TKE)
             zavt = avt(ji,jj,ik)
-            tmltrd(ji,jj,jpmldevd) = - 1. * zavt / fse3w(ji,jj,ik) * tmask(ji,jj,ik)   &
-               &                   * ( tn(ji,jj,ik-1) - tn(ji,jj,ik) )   &
-               &                   / MAX( 1., rmld(ji,jj) ) * tmask(ji,jj,1)
-            ! Salinity
-            ! entrainment due to vertical diffusion
-            !       - due to vertical mixing scheme (TKE)
+            tmltrd(ji,jj,jpmld_zdf) = - zavt / fse3w(ji,jj,ik) * tmask(ji,jj,ik)  &
+               &                      * ( tn(ji,jj,ik-1) - tn(ji,jj,ik) )         &
+               &                      / MAX( 1., rmld(ji,jj) ) * tmask(ji,jj,1)
             zavt = fsavs(ji,jj,ik)
-            smltrd(ji,jj,jpmldevd) = -1. * zavt / fse3w(ji,jj,ik) * tmask(ji,jj,ik)   &
-               &                  * ( sn(ji,jj,ik-1) - sn(ji,jj,ik) )   &
-               &                  / MAX( 1., rmld(ji,jj) ) * tmask(ji,jj,1)
+            smltrd(ji,jj,jpmld_zdf) = - zavt / fse3w(ji,jj,ik) * tmask(ji,jj,ik)  &
+               &                      * ( sn(ji,jj,ik-1) - sn(ji,jj,ik) )         &
+               &                      / MAX( 1., rmld(ji,jj) ) * tmask(ji,jj,1)
          END DO
       END DO
 
+      ! ... Remove this K_z trend from the iso-neutral diffusion term (if any)
       IF( ln_traldf_iso ) THEN
-         ! We substract to the TOTAL vertical diffusion tmltrd(:,:,jpmldzdf) 
-         ! computed in subroutines trazdf_iso.F90 or trazdf_imp.F90
-         ! the vertical part du to the Kz in order to keep only the vertical
-         ! isopycnal diffusion (i.e the isopycnal diffusion componant on the vertical):
-         tmltrd(:,:,jpmldzdf) = tmltrd(:,:,jpmldzdf) - tmltrd(:,:,jpmldevd)   ! - due to isopycnal mixing scheme (implicit part)
-         smltrd(:,:,jpmldzdf) = smltrd(:,:,jpmldzdf) - smltrd(:,:,jpmldevd)   ! - due to isopycnal mixing scheme (implicit part)
-      ENDIF
-
-      ! Boundary conditions
-      CALL lbc_lnk( tmltrd, 'T', 1. )
-      CALL lbc_lnk( smltrd, 'T', 1. )
-
-      IF( idebug /= 0 ) THEN
-         WRITE(numout,*) ' debuging trd_mld: I. done'  
-         CALL FLUSH(numout)
-      ENDIF
-
-      !  =================================
-      !   II. Cumulated trends
-      !  =================================
-
-      ! II.1 set before values of vertically average T and S 
-      ! ---------------------------------------------------
-
+         tmltrd(:,:,jpmld_ldf) = tmltrd(:,:,jpmld_ldf) - tmltrd(:,:,jpmld_zdf)
+         smltrd(:,:,jpmld_ldf) = smltrd(:,:,jpmld_ldf) - smltrd(:,:,jpmld_zdf)
+      END IF
+
+      ! ... Lateral boundary conditions
+      DO jl = 1, jpltrd
+         CALL lbc_lnk( tmltrd(:,:,jl), 'T', 1. )
+         CALL lbc_lnk( smltrd(:,:,jl), 'T', 1. )
+      END DO
+
+      ! ======================================================================
+      ! II. Cumulate the trends over the analysis window
+      ! ======================================================================
+
+      ztmltrd2(:,:,:) = 0.e0   ;    zsmltrd2(:,:,:) = 0.e0  ! <<< reset arrays to zero
+      ztmltot2(:,:)   = 0.e0   ;    zsmltot2(:,:)   = 0.e0
+      ztmlres2(:,:)   = 0.e0   ;    zsmlres2(:,:)   = 0.e0
+      ztmlatf2(:,:)   = 0.e0   ;    zsmlatf2(:,:)   = 0.e0
+
+      ! II.1 Set before values of vertically average T and S 
+      ! ----------------------------------------------------
       IF( kt > nit000 ) THEN
-         tmlb(:,:) = tml(:,:)
-         smlb(:,:) = sml(:,:)
-      ENDIF
-
-      ! II.2 vertically integrated T and S
-      ! ---------------------------------
-
-      tml(:,:) = 0.
-      sml(:,:) = 0.
-
+         !   ... temperature ...                    ... salinity ...
+         tmlb   (:,:) = tml   (:,:)           ; smlb   (:,:) = sml   (:,:)
+         tmlatfn(:,:) = tmltrd(:,:,jpmld_atf) ; smlatfn(:,:) = smltrd(:,:,jpmld_atf)
+      END IF
+
+      ! II.2 Vertically averaged T and S
+      ! --------------------------------
+      tml(:,:) = 0.e0   ;   sml(:,:) = 0.e0
       DO jk = 1, jpktrd - 1
          tml(:,:) = tml(:,:) + wkx(:,:,jk) * tn(:,:,jk)
@@ -427,207 +304,397 @@
       END DO
 
-      IF(idebug /= 0) THEN
-         WRITE(numout,*) ' debuging trd_mld: II.2 done'  
-         CALL FLUSH(numout)
-      ENDIF
-
-      ! II.3 set `before' mixed layer values for kt = nit000+1
-      ! --------------------------------------------------------
-
-      IF( kt == nit000+1 ) THEN
-         tmlbb(:,:) = tmlb(:,:)
-         tmlbn(:,:) = tml (:,:)
-         smlbb(:,:) = smlb(:,:)
-         smlbn(:,:) = sml (:,:)
-      ENDIF
-
-      IF( idebug /= 0 ) THEN
-         WRITE(numout,*) ' debuging trd_mld: II.3 done'  
-         CALL FLUSH(numout)
-      ENDIF
-
-      ! II.4 cumulated trends over analysis period (kt=2 to nwrite)
-      ! -----------------------------------------------------------
-
-      ! trends cumulated over nwrite-2 time steps
-
-      IF( kt >= nit000+2 ) THEN
+      ! II.3 Initialize mixed-layer "before" arrays for the 1rst analysis window    
+      ! ------------------------------------------------------------------------
+      IF( kt == 2 ) THEN  !  i.e. ( .NOT. ln_rstart ).AND.( kt == nit000 + 1)
+         !
+         !   ... temperature ...                ... salinity ...
+         tmlbb  (:,:) = tmlb   (:,:)   ;   smlbb  (:,:) = smlb   (:,:)
+         tmlbn  (:,:) = tml    (:,:)   ;   smlbn  (:,:) = sml    (:,:)
+         tmlatfb(:,:) = tmlatfn(:,:)   ;   smlatfb(:,:) = smlatfn(:,:)
+         
+         tmltrd_csum_ub (:,:,:) = 0.e0  ;   smltrd_csum_ub (:,:,:) = 0.e0
+         tmltrd_atf_sumb(:,:)   = 0.e0  ;   smltrd_atf_sumb(:,:)   = 0.e0
+
+         rmldbn(:,:) = rmld(:,:)
+
+         IF( ln_ctl ) THEN
+            WRITE(numout,*) '             we reach kt == nit000 + 1 = ', nit000+1
+            CALL prt_ctl(tab2d_1=tmlbb   , clinfo1=' tmlbb   -   : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=tmlbn   , clinfo1=' tmlbn   -   : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=tmlatfb , clinfo1=' tmlatfb -   : ', mask1=tmask, ovlap=1)
+         END IF
+         !
+      END IF
+
+      IF( ( ln_rstart ) .AND. ( kt == nit000 ) .AND. ( ln_ctl ) ) THEN
+         IF( ln_trdmld_instant ) THEN
+            WRITE(numout,*) '             restart from kt == nit000 = ', nit000
+            CALL prt_ctl(tab2d_1=tmlbb   , clinfo1=' tmlbb   -   : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=tmlbn   , clinfo1=' tmlbn   -   : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=tmlatfb , clinfo1=' tmlatfb -   : ', mask1=tmask, ovlap=1)
+         ELSE
+            WRITE(numout,*) '             restart from kt == nit000 = ', nit000
+            CALL prt_ctl(tab2d_1=tmlbn          , clinfo1=' tmlbn           -  : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=rmldbn         , clinfo1=' rmldbn          -  : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=tml_sumb       , clinfo1=' tml_sumb        -  : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab2d_1=tmltrd_atf_sumb, clinfo1=' tmltrd_atf_sumb -  : ', mask1=tmask, ovlap=1)
+            CALL prt_ctl(tab3d_1=tmltrd_csum_ub , clinfo1=' tmltrd_csum_ub  -  : ', mask1=tmask, ovlap=1, kdim=1)
+         END IF
+      END IF
+
+      ! II.4 Cumulated trends over the analysis period
+      ! ----------------------------------------------
+      !
+      !         [  1rst analysis window ] [     2nd analysis window     ]                       
+      !
+      !     o---[--o-----o-----o-----o--]-[--o-----o-----o-----o-----o--]---o-----o--> time steps
+      !                            ntrd                             2*ntrd       etc.
+      !     1      2     3     4    =5 e.g.                          =10
+      !
+      IF( ( kt >= 2 ).OR.( ln_rstart ) ) THEN
+         !
          nmoymltrd = nmoymltrd + 1
+         
+         ! ... Cumulate over BOTH physical contributions AND over time steps
          DO jl = 1, jpltrd
             tmltrdm(:,:) = tmltrdm(:,:) + tmltrd(:,:,jl)
             smltrdm(:,:) = smltrdm(:,:) + smltrd(:,:,jl)
          END DO
-      ENDIF
-
-      IF( idebug /= 0 ) THEN
-         WRITE(numout,*) ' debuging trd_mld: II.4 done'  
-         CALL FLUSH(numout)
-      ENDIF
-
-      !  =============================================
-      !   III. Output in netCDF + residual computation
-      !  =============================================
-
-      ztmltot(:,:) = 0.
-      zsmltot(:,:) = 0.
-      ztmlres(:,:) = 0.
-      zsmlres(:,:) = 0.
-
-      IF( MOD( kt - nit000+1, nwrite ) == 0 ) THEN
-
-         ! III.1 compute total trend 
-         ! ------------------------
-
-         zmean = float(nmoymltrd)
-         
-         ztmltot(:,:) = ( tml(:,:) - tmlbn(:,:) + tmlb(:,:) - tmlbb(:,:) ) /  (zmean * 2. * rdt)
-         zsmltot(:,:) = ( sml(:,:) - smlbn(:,:) + smlb(:,:) - smlbb(:,:) ) /  (zmean * 2. * rdt)
-
-         IF(idebug /= 0) THEN
-            WRITE(numout,*) ' zmean = ',zmean  
-            WRITE(numout,*) ' debuging trd_mld: III.1 done'  
-            CALL FLUSH(numout)
-         ENDIF
-          
-
-         ! III.2 compute residual 
-         ! ---------------------
-
-         ztmlres(:,:) = ztmltot(:,:) - tmltrdm(:,:) / zmean
-         zsmlres(:,:) = zsmltot(:,:) - smltrdm(:,:) / zmean
-
-
-         ! Boundary conditions
-
-         CALL lbc_lnk( ztmltot, 'T', 1. )
-         CALL lbc_lnk( ztmlres, 'T', 1. )
-         CALL lbc_lnk( zsmltot, 'T', 1. )
-         CALL lbc_lnk( zsmlres, 'T', 1. )
-
-         IF( idebug /= 0 ) THEN
-            WRITE(numout,*) ' debuging trd_mld: III.2 done'  
-            CALL FLUSH(numout)
-         ENDIF
-
-
-         ! III.3 time evolution array swap
-         ! ------------------------------
-
-         tmlbb(:,:) = tmlb(:,:)
-         tmlbn(:,:) = tml (:,:)
-         smlbb(:,:) = smlb(:,:)
-         smlbn(:,:) = sml (:,:)
-
-         IF( idebug /= 0 ) THEN
-            WRITE(numout,*) ' debuging trd_mld: III.3 done'  
-            CALL FLUSH(numout)
-         ENDIF
-
-
-         ! III.4 zero cumulative array
-         ! ---------------------------
-
-          nmoymltrd = 0
-
-          tmltrdm(:,:) = 0.
-          smltrdm(:,:) = 0.
-
-          IF(idebug /= 0) THEN
-              WRITE(numout,*) ' debuging trd_mld: III.4 done'  
-              CALL FLUSH(numout)
-          ENDIF
-          
-      ENDIF
-
-      ! III.5 write trends to output
-      ! ---------------------------
+
+         ! ... Special handling of the Asselin trend 
+         tmlatfm(:,:) = tmlatfm(:,:) + tmlatfn(:,:)
+         smlatfm(:,:) = smlatfm(:,:) + smlatfn(:,:)
+
+         ! ... Trends associated with the time mean of the ML T/S
+         tmltrd_sum    (:,:,:) = tmltrd_sum    (:,:,:) + tmltrd    (:,:,:) ! tem
+         tmltrd_csum_ln(:,:,:) = tmltrd_csum_ln(:,:,:) + tmltrd_sum(:,:,:)
+         tml_sum       (:,:)   = tml_sum       (:,:)   + tml       (:,:)
+         smltrd_sum    (:,:,:) = smltrd_sum    (:,:,:) + smltrd    (:,:,:) ! sal
+         smltrd_csum_ln(:,:,:) = smltrd_csum_ln(:,:,:) + smltrd_sum(:,:,:)
+         sml_sum       (:,:)   = sml_sum       (:,:)   + sml       (:,:)
+         rmld_sum      (:,:)   = rmld_sum      (:,:)   + rmld      (:,:)   ! rmld
+         !
+      END IF
+
+      ! ======================================================================
+      ! III. Prepare fields for output (get here ONCE PER ANALYSIS PERIOD)
+      ! ======================================================================
+
+      ! Convert to appropriate physical units
+      ! N.B. It may be useful to check IOIPSL time averaging with :
+      !      tmltrd (:,:,:) = 1. ; smltrd (:,:,:) = 1.
+      tmltrd(:,:,:) = tmltrd(:,:,:) * ucf   ! (actually needed for 1:jpltrd-1, but trdmld(:,:,jpltrd)
+      smltrd(:,:,:) = smltrd(:,:,:) * ucf   !  is no longer used, and is reset to 0. at next time step)
+      
+      MODULO_NTRD : IF( MOD( kt, ntrd ) == 0 ) THEN        ! nitend MUST be multiple of ntrd
+         !
+         ztmltot (:,:) = 0.e0   ;   zsmltot (:,:) = 0.e0   ! reset arrays to zero
+         ztmlres (:,:) = 0.e0   ;   zsmlres (:,:) = 0.e0
+         ztmltot2(:,:) = 0.e0   ;   zsmltot2(:,:) = 0.e0
+         ztmlres2(:,:) = 0.e0   ;   zsmlres2(:,:) = 0.e0
+      
+         zfn  = float(nmoymltrd)    ;    zfn2 = zfn * zfn
+         
+         ! III.1 Prepare fields for output ("instantaneous" diagnostics) 
+         ! -------------------------------------------------------------
+         
+         !-- Compute total trends
+         ztmltot(:,:) = ( tml(:,:) - tmlbn(:,:) + tmlb(:,:) - tmlbb(:,:) ) / ( 2.*rdt )
+         zsmltot(:,:) = ( sml(:,:) - smlbn(:,:) + smlb(:,:) - smlbb(:,:) ) / ( 2.*rdt )
+         
+         !-- Compute residuals
+         ztmlres(:,:) = ztmltot(:,:) - ( tmltrdm(:,:) - tmlatfn(:,:) + tmlatfb(:,:) )
+         zsmlres(:,:) = zsmltot(:,:) - ( smltrdm(:,:) - smlatfn(:,:) + smlatfb(:,:) )
+      
+         !-- Diagnose Asselin trend over the analysis window 
+         ztmlatf(:,:) = tmlatfm(:,:) - tmlatfn(:,:) + tmlatfb(:,:)
+         zsmlatf(:,:) = smlatfm(:,:) - smlatfn(:,:) + smlatfb(:,:)
+         
+         !-- Lateral boundary conditions
+         !         ... temperature ...                    ... salinity ...
+         CALL lbc_lnk( ztmltot , 'T', 1. )  ;   CALL lbc_lnk( zsmltot , 'T', 1. )
+         CALL lbc_lnk( ztmlres , 'T', 1. )  ;   CALL lbc_lnk( zsmlres , 'T', 1. )
+         CALL lbc_lnk( ztmlatf , 'T', 1. )  ;   CALL lbc_lnk( zsmlatf , 'T', 1. )
+
+#if defined key_diainstant
+         CALL ctl_stop( 'tml_trd : key_diainstant was never checked within trdmld. Comment this to proceed.')
+#endif
+         ! III.2 Prepare fields for output ("mean" diagnostics) 
+         ! ----------------------------------------------------
+         
+         !-- Update the ML depth time sum (to build the Leap-Frog time mean)
+         rmld_sum(:,:) = rmldbn(:,:) + 2 * ( rmld_sum(:,:) - rmld(:,:) ) + rmld(:,:)
+
+         !-- Compute temperature total trends
+         tml_sum (:,:) = tmlbn(:,:) + 2 * ( tml_sum(:,:) - tml(:,:) ) + tml(:,:)
+         ztmltot2(:,:) = ( tml_sum(:,:) - tml_sumb(:,:) ) /  ( 2.*rdt )    ! now in degC/s
+         
+         !-- Compute salinity total trends
+         sml_sum (:,:) = smlbn(:,:) + 2 * ( sml_sum(:,:) - sml(:,:) ) + sml(:,:)
+         zsmltot2(:,:) = ( sml_sum(:,:) - sml_sumb(:,:) ) /  ( 2.*rdt )    ! now in psu/s
+         
+         !-- Compute temperature residuals
+         DO jl = 1, jpltrd
+            ztmltrd2(:,:,jl) = tmltrd_csum_ub(:,:,jl) + tmltrd_csum_ln(:,:,jl)
+         END DO
+
+         ztmltrdm2(:,:) = 0.e0
+         DO jl = 1, jpltrd
+            ztmltrdm2(:,:) = ztmltrdm2(:,:) + ztmltrd2(:,:,jl)
+         END DO
+
+         ztmlres2(:,:) =  ztmltot2(:,:)  -       &
+              ( ztmltrdm2(:,:) - tmltrd_sum(:,:,jpmld_atf) + tmltrd_atf_sumb(:,:) )
+         
+         !-- Compute salinity residuals
+         DO jl = 1, jpltrd
+            zsmltrd2(:,:,jl) = smltrd_csum_ub(:,:,jl) + smltrd_csum_ln(:,:,jl)
+         END DO
+
+         zsmltrdm2(:,:) = 0.
+         DO jl = 1, jpltrd
+            zsmltrdm2(:,:) = zsmltrdm2(:,:) + zsmltrd2(:,:,jl)
+         END DO
+
+         zsmlres2(:,:) =  zsmltot2(:,:)  -       &
+              ( zsmltrdm2(:,:) - smltrd_sum(:,:,jpmld_atf) + smltrd_atf_sumb(:,:) )
+         
+         !-- Diagnose Asselin trend over the analysis window
+         ztmlatf2(:,:) = ztmltrd2(:,:,jpmld_atf) - tmltrd_sum(:,:,jpmld_atf) + tmltrd_atf_sumb(:,:)
+         zsmlatf2(:,:) = zsmltrd2(:,:,jpmld_atf) - smltrd_sum(:,:,jpmld_atf) + smltrd_atf_sumb(:,:)
+
+         !-- Lateral boundary conditions
+         !         ... temperature ...                    ... salinity ...
+         CALL lbc_lnk( ztmltot2, 'T', 1. )  ;   CALL lbc_lnk( zsmltot2, 'T', 1. )
+         CALL lbc_lnk( ztmlres2, 'T', 1. )  ;   CALL lbc_lnk( zsmlres2, 'T', 1. )
+         DO jl = 1, jpltrd
+            CALL lbc_lnk( ztmltrd2(:,:,jl), 'T', 1. ) ! \  these will be output
+            CALL lbc_lnk( zsmltrd2(:,:,jl), 'T', 1. ) ! /  in the NetCDF trends file
+         END DO
+         
+         ! III.3 Time evolution array swap
+         ! -------------------------------
+         
+         ! For T/S instantaneous diagnostics 
+         !   ... temperature ...               ... salinity ...
+         tmlbb  (:,:) = tmlb   (:,:)  ;   smlbb  (:,:) = smlb   (:,:)
+         tmlbn  (:,:) = tml    (:,:)  ;   smlbn  (:,:) = sml    (:,:)
+         tmlatfb(:,:) = tmlatfn(:,:)  ;   smlatfb(:,:) = smlatfn(:,:)
+
+         ! For T mean diagnostics 
+         tmltrd_csum_ub (:,:,:) = zfn * tmltrd_sum(:,:,:) - tmltrd_csum_ln(:,:,:)
+         tml_sumb       (:,:)   = tml_sum(:,:)
+         tmltrd_atf_sumb(:,:)   = tmltrd_sum(:,:,jpmld_atf)
+         
+         ! For S mean diagnostics 
+         smltrd_csum_ub (:,:,:) = zfn * smltrd_sum(:,:,:) - smltrd_csum_ln(:,:,:)
+         sml_sumb       (:,:)   = sml_sum(:,:)
+         smltrd_atf_sumb(:,:)   = smltrd_sum(:,:,jpmld_atf)
+         
+         ! ML depth
+         rmldbn         (:,:)   = rmld    (:,:)
+         
+         IF( ln_ctl ) THEN
+            IF( ln_trdmld_instant ) THEN
+               CALL prt_ctl(tab2d_1=tmlbb   , clinfo1=' tmlbb   -   : ', mask1=tmask, ovlap=1)
+               CALL prt_ctl(tab2d_1=tmlbn   , clinfo1=' tmlbn   -   : ', mask1=tmask, ovlap=1)
+               CALL prt_ctl(tab2d_1=tmlatfb , clinfo1=' tmlatfb -   : ', mask1=tmask, ovlap=1)
+            ELSE
+               CALL prt_ctl(tab2d_1=tmlbn          , clinfo1=' tmlbn           -  : ', mask1=tmask, ovlap=1)
+               CALL prt_ctl(tab2d_1=rmldbn         , clinfo1=' rmldbn          -  : ', mask1=tmask, ovlap=1)
+               CALL prt_ctl(tab2d_1=tml_sumb       , clinfo1=' tml_sumb        -  : ', mask1=tmask, ovlap=1)
+               CALL prt_ctl(tab2d_1=tmltrd_atf_sumb, clinfo1=' tmltrd_atf_sumb -  : ', mask1=tmask, ovlap=1)
+               CALL prt_ctl(tab3d_1=tmltrd_csum_ub , clinfo1=' tmltrd_csum_ub  -  : ', mask1=tmask, ovlap=1, kdim=1)
+            END IF
+         END IF
+
+         ! III.4 Convert to appropriate physical units
+         ! -------------------------------------------
+
+         !    ... temperature ...                         ... salinity ...
+         ztmltot (:,:)   = ztmltot(:,:)   * ucf/zfn  ; zsmltot (:,:)   = zsmltot(:,:)   * ucf/zfn
+         ztmlres (:,:)   = ztmlres(:,:)   * ucf/zfn  ; zsmlres (:,:)   = zsmlres(:,:)   * ucf/zfn
+         ztmlatf (:,:)   = ztmlatf(:,:)   * ucf/zfn  ; zsmlatf (:,:)   = zsmlatf(:,:)   * ucf/zfn
+
+         tml_sum (:,:)   = tml_sum (:,:)  /  (2*zfn) ; sml_sum (:,:)   = sml_sum (:,:)  /  (2*zfn)
+         ztmltot2(:,:)   = ztmltot2(:,:)  * ucf/zfn2 ; zsmltot2(:,:)   = zsmltot2(:,:)  * ucf/zfn2
+         ztmltrd2(:,:,:) = ztmltrd2(:,:,:)* ucf/zfn2 ; zsmltrd2(:,:,:) = zsmltrd2(:,:,:)* ucf/zfn2
+         ztmlatf2(:,:)   = ztmlatf2(:,:)  * ucf/zfn2 ; zsmlatf2(:,:)   = zsmlatf2(:,:)  * ucf/zfn2
+         ztmlres2(:,:)   = ztmlres2(:,:)  * ucf/zfn2 ; zsmlres2(:,:)   = zsmlres2(:,:)  * ucf/zfn2
+
+         rmld_sum(:,:)   = rmld_sum(:,:)  /  (2*zfn)  ! similar to tml_sum and sml_sum
+
+         ! * Debugging information *
+         IF( lldebug ) THEN
+            !
+            WRITE(numout,*)
+            WRITE(numout,*) 'trd_mld : write trends in the Mixed Layer for debugging process:'
+            WRITE(numout,*) '~~~~~~~  '
+            WRITE(numout,*) '          TRA kt = ', kt, 'nmoymltrd = ', nmoymltrd
+            WRITE(numout,*)
+            WRITE(numout,*) '          >>>>>>>>>>>>>>>>>>  TRA TEMPERATURE <<<<<<<<<<<<<<<<<<'
+            WRITE(numout,*) '          TRA ztmlres    : ', SUM(ztmlres(:,:))
+            WRITE(numout,*) '          TRA ztmltot    : ', SUM(ztmltot(:,:))
+            WRITE(numout,*) '          TRA tmltrdm    : ', SUM(tmltrdm(:,:))
+            WRITE(numout,*) '          TRA tmlatfb    : ', SUM(tmlatfb(:,:))
+            WRITE(numout,*) '          TRA tmlatfn    : ', SUM(tmlatfn(:,:))
+            DO jl = 1, jpltrd
+               WRITE(numout,*) '          * TRA TREND INDEX jpmld_xxx = jl = ', jl, &
+                    & ' tmltrd : ', SUM(tmltrd(:,:,jl))
+            END DO
+            WRITE(numout,*) '          TRA ztmlres (jpi/2,jpj/2) : ', ztmlres (jpi/2,jpj/2)
+            WRITE(numout,*) '          TRA ztmlres2(jpi/2,jpj/2) : ', ztmlres2(jpi/2,jpj/2)
+            WRITE(numout,*)
+            WRITE(numout,*) '          >>>>>>>>>>>>>>>>>>  TRA SALINITY <<<<<<<<<<<<<<<<<<'
+            WRITE(numout,*) '          TRA zsmlres    : ', SUM(zsmlres(:,:))
+            WRITE(numout,*) '          TRA zsmltot    : ', SUM(zsmltot(:,:))
+            WRITE(numout,*) '          TRA smltrdm    : ', SUM(smltrdm(:,:))
+            WRITE(numout,*) '          TRA smlatfb    : ', SUM(smlatfb(:,:))
+            WRITE(numout,*) '          TRA smlatfn    : ', SUM(smlatfn(:,:))
+            DO jl = 1, jpltrd
+               WRITE(numout,*) '          * TRA TREND INDEX jpmld_xxx = jl = ', jl, &
+                    & ' smltrd : ', SUM(smltrd(:,:,jl))
+            END DO
+            WRITE(numout,*) '          TRA zsmlres (jpi/2,jpj/2) : ', zsmlres (jpi/2,jpj/2)
+            WRITE(numout,*) '          TRA zsmlres2(jpi/2,jpj/2) : ', zsmlres2(jpi/2,jpj/2)
+            !
+         END IF
+         !
+      END IF MODULO_NTRD
+
+      ! ======================================================================
+      ! IV. Write trends in the NetCDF file
+      ! ======================================================================
+
+      ! IV.1 Code for dimg mpp output
+      ! -----------------------------
 
 #if defined key_dimgout
-! code for dimg mpp output
-      IF ( MOD(kt,nwrite) == 0 ) THEN
-         WRITE(clmode,'(f5.1,a)' ) nwrite*rdt/86400.,' days average'
-         iyear = ndastp/10000
-         imon = (ndastp-iyear*10000)/100
-         iday = ndastp - imon*100 - iyear*10000
+
+      IF( MOD( kt, ntrd ) == 0 ) THEN
+         iyear =  ndastp/10000
+         imon  = (ndastp-iyear*10000)/100
+         iday  =  ndastp - imon*100 - iyear*10000
          WRITE(clname,9000) TRIM(cexper),'MLDiags',iyear,imon,iday
-         cltext=TRIM(cexper)//' mld diags'//TRIM(clmode)
+         WRITE(clmode,'(f5.1,a)') ntrd*rdt/86400.,' days average'
+         cltext = TRIM(cexper)//' mld diags'//TRIM(clmode)
          CALL dia_wri_dimg (clname, cltext, smltrd, jpltrd, '2')
-  9000   FORMAT(a,"_",a,"_y",i4.4,"m",i2.2,"d",i2.2,".dimgproc")
-       END IF
+      END IF
+
+9000  FORMAT(a,"_",a,"_y",i4.4,"m",i2.2,"d",i2.2,".dimgproc")
 
 #else
-      IF( kt >=  nit000+1 ) THEN
-
-         ! define time axis
-         it= kt-nit000+1
-         IF( lwp .AND. MOD( kt, nwrite ) == 0 ) THEN
-            WRITE(numout,*) '     trd_mld : write NetCDF fields'
-         ENDIF
-         
-         CALL histwrite( nidtrd,"somlttml",it,rmld          ,ndimtrd1,ndextrd1) ! Mixed-layer depth
-         
-         ! Temperature trends
-         ! ------------------
-         CALL histwrite( nidtrd,"somltemp",it,tml           ,ndimtrd1,ndextrd1) ! Mixed-layer temperature
-         CALL histwrite( nidtrd,"somlttto",it,ztmltot       ,ndimtrd1,ndextrd1) ! total 
-         CALL histwrite( nidtrd,"somlttax",it,tmltrd(:,:, 1),ndimtrd1,ndextrd1) ! i- adv.
-         CALL histwrite( nidtrd,"somlttay",it,tmltrd(:,:, 2),ndimtrd1,ndextrd1) ! j- adv.
-         CALL histwrite( nidtrd,"somlttaz",it,tmltrd(:,:, 3),ndimtrd1,ndextrd1) ! vertical adv.
-         CALL histwrite( nidtrd,"somlttdh",it,tmltrd(:,:, 4),ndimtrd1,ndextrd1) ! hor. lateral diff.
-         CALL histwrite( nidtrd,"somlttfo",it,tmltrd(:,:, 5),ndimtrd1,ndextrd1) ! forcing
-
-         CALL histwrite( nidtrd,"somlbtdz",it,tmltrd(:,:, 6),ndimtrd1,ndextrd1) ! vert. diffusion 
-         CALL histwrite( nidtrd,"somlbtdt",it,ztmlres       ,ndimtrd1,ndextrd1) ! dh/dt entrainment (residual)
-         IF( ln_traldf_iso ) THEN
-            CALL histwrite( nidtrd,"somlbtdv",it,tmltrd(:,:, 7),ndimtrd1,ndextrd1) ! vert. lateral diff.
-         ENDIF
-#if defined key_traldf_eiv
-         CALL histwrite( nidtrd,"somlgtax",it,tmltrd(:,:, 8),ndimtrd1,ndextrd1) ! i- adv. (eiv)
-         CALL histwrite( nidtrd,"somlgtay",it,tmltrd(:,:, 9),ndimtrd1,ndextrd1) ! j- adv. (eiv)
-         CALL histwrite( nidtrd,"somlgtaz",it,tmltrd(:,:,10),ndimtrd1,ndextrd1) ! vert. adv. (eiv)
-         z2d(:,:) = tmltrd(:,:,8) + tmltrd(:,:,9) + tmltrd(:,:,10)
-         CALL histwrite( nidtrd,"somlgtat",it,z2d           ,ndimtrd1,ndextrd1) ! total adv. (eiv)
-#endif   
-
-         ! Salinity trends
-         ! ---------------
-         CALL histwrite( nidtrd,"somlsalt",it,sml           ,ndimtrd1,ndextrd1) ! Mixed-layer salinity
-         CALL histwrite( nidtrd,"somltsto",it,zsmltot       ,ndimtrd1,ndextrd1) ! total 
-         CALL histwrite( nidtrd,"somltsax",it,smltrd(:,:, 1),ndimtrd1,ndextrd1) ! i- adv.
-         CALL histwrite( nidtrd,"somltsay",it,smltrd(:,:, 2),ndimtrd1,ndextrd1) ! j- adv.
-         CALL histwrite( nidtrd,"somltsaz",it,smltrd(:,:, 3),ndimtrd1,ndextrd1) ! vert. adv.
-         CALL histwrite( nidtrd,"somltsdh",it,smltrd(:,:, 4),ndimtrd1,ndextrd1) ! hor. lateral diff.
-         CALL histwrite( nidtrd,"somltsfo",it,smltrd(:,:, 5),ndimtrd1,ndextrd1) ! forcing
-         CALL histwrite( nidtrd,"somlbsdz",it,smltrd(:,:, 6),ndimtrd1,ndextrd1) ! vert. diff.
-         CALL histwrite( nidtrd,"somlbsdt",it,zsmlres       ,ndimtrd1,ndextrd1) ! dh/dt entrainment (residual)
-         IF( ln_traldf_iso ) THEN
-            CALL histwrite( nidtrd,"somlbsdv",it,smltrd(:,:, 7),ndimtrd1,ndextrd1) ! vert. lateral diff;
-         ENDIF
-#if defined key_traldf_eiv
-         CALL histwrite( nidtrd,"somlgsax",it,smltrd(:,:, 8),ndimtrd1,ndextrd1) ! i-adv. (eiv)
-         CALL histwrite( nidtrd,"somlgsay",it,smltrd(:,:, 9),ndimtrd1,ndextrd1) ! j-adv. (eiv)
-         CALL histwrite( nidtrd,"somlgsaz",it,smltrd(:,:,10),ndimtrd1,ndextrd1) ! vert. adv. (eiv)
-         z2d(:,:) = smltrd(:,:,8) + smltrd(:,:,9) + smltrd(:,:,10)
-         CALL histwrite( nidtrd,"somlgsat",it,z2d           ,ndimtrd1,ndextrd1) ! total adv. (eiv)
+      
+      ! IV.2 Code for IOIPSL/NetCDF output
+      ! ----------------------------------
+
+      IF( lwp .AND. MOD( kt , ntrd ) == 0 ) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) 'trd_mld : write trends in the NetCDF file :'
+         WRITE(numout,*) '~~~~~~~  '
+         WRITE(numout,*) '          ', TRIM(clhstnam), ' at kt = ', kt
+         WRITE(numout,*) '          N.B. nmoymltrd = ', nmoymltrd
+         WRITE(numout,*) ' '
+      END IF
+         
+      it = kt - nit000 + 1
+
+      !-- Write the trends for T/S instantaneous diagnostics 
+      IF( ln_trdmld_instant ) THEN           
+
+         CALL histwrite( nidtrd, "mxl_depth", it, rmld(:,:), ndimtrd1, ndextrd1 )
+         
+         !................................. ( ML temperature ) ...................................
+         
+         !-- Output the fields
+         CALL histwrite( nidtrd, "tml"     , it, tml    (:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "tml_tot" , it, ztmltot(:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "tml_res" , it, ztmlres(:,:), ndimtrd1, ndextrd1 ) 
+         
+         DO jl = 1, jpltrd - 1
+            CALL histwrite( nidtrd, trim("tml"//ctrd(jl,2)),            &
+                 &          it, tmltrd (:,:,jl), ndimtrd1, ndextrd1 )
+         END DO
+         
+         CALL histwrite( nidtrd, trim("tml"//ctrd(jpmld_atf,2)),        &
+              &          it, ztmlatf(:,:), ndimtrd1, ndextrd1 )
+         
+         !.................................. ( ML salinity ) .....................................
+         
+         !-- Output the fields
+         CALL histwrite( nidtrd, "sml"     , it, sml    (:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "sml_tot" , it, zsmltot(:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "sml_res" , it, zsmlres(:,:), ndimtrd1, ndextrd1 ) 
+         
+         DO jl = 1, jpltrd - 1
+            CALL histwrite( nidtrd, trim("sml"//ctrd(jl,2)),            &
+                 &          it, smltrd(:,:,jl), ndimtrd1, ndextrd1 )
+         END DO
+         
+         CALL histwrite( nidtrd, trim("sml"//ctrd(jpmld_atf,2)),        &
+              &          it, zsmlatf(:,:), ndimtrd1, ndextrd1 )
+         
+         IF( kt == nitend )   CALL histclo( nidtrd )
+
+      !-- Write the trends for T/S mean diagnostics 
+      ELSE
+         
+         CALL histwrite( nidtrd, "mxl_depth", it, rmld_sum(:,:), ndimtrd1, ndextrd1 ) 
+         
+         !................................. ( ML temperature ) ...................................
+         
+         !-- Output the fields
+         CALL histwrite( nidtrd, "tml"     , it, tml_sum (:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "tml_tot" , it, ztmltot2(:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "tml_res" , it, ztmlres2(:,:), ndimtrd1, ndextrd1 ) 
+         
+         DO jl = 1, jpltrd - 1
+            CALL histwrite( nidtrd, trim("tml"//ctrd(jl,2)),            &
+                 &          it, ztmltrd2(:,:,jl), ndimtrd1, ndextrd1 )
+         END DO
+         
+         CALL histwrite( nidtrd, trim("tml"//ctrd(jpmld_atf,2)),        &
+              &          it, ztmlatf2(:,:), ndimtrd1, ndextrd1 )
+         
+         !.................................. ( ML salinity ) .....................................
+                     
+         !-- Output the fields
+         CALL histwrite( nidtrd, "sml"     , it, sml_sum (:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "sml_tot" , it, zsmltot2(:,:), ndimtrd1, ndextrd1 ) 
+         CALL histwrite( nidtrd, "sml_res" , it, zsmlres2(:,:), ndimtrd1, ndextrd1 ) 
+         
+         DO jl = 1, jpltrd - 1
+            CALL histwrite( nidtrd, trim("sml"//ctrd(jl,2)),            &
+                 &          it, zsmltrd2(:,:,jl), ndimtrd1, ndextrd1 )
+         END DO
+         
+         CALL histwrite( nidtrd, trim("sml"//ctrd(jpmld_atf,2)),        &
+              &          it, zsmlatf2(:,:), ndimtrd1, ndextrd1 )
+         
+         IF( kt == nitend )   CALL histclo( nidtrd )
+
+      END IF
+      
+      ! Compute the control surface (for next time step) : flag = on
+      icount = 1
+      !
 #endif
 
-         IF( idebug /= 0 ) THEN
-            WRITE(numout,*) ' debuging trd_mld: III.5 done'  
-            CALL FLUSH(numout)
-         ENDIF
-
-         ! set counter icount to one to allow the calculation
-         ! of the surface control in the next time step in the trd_mld_zint subroutine
-         icount = 1
-
-      ENDIF
-
-      ! At the end of the 1st time step, set icount to 1 to be
-      ! able to compute the surface control at the beginning of
-      ! the second time step
-      IF( kt == nit000 )   icount = 1
-
-      IF( kt == nitend )   CALL histclo( nidtrd )
-#endif
+      IF( MOD( kt , ntrd ) == 0 ) THEN
+         !
+         ! III.5 Reset cumulative arrays to zero
+         ! -------------------------------------
+         nmoymltrd = 0
+         
+         !   ... temperature ...               ... salinity ...
+         tmltrdm        (:,:)   = 0.e0   ;   smltrdm        (:,:)   = 0.e0
+         tmlatfm        (:,:)   = 0.e0   ;   smlatfm        (:,:)   = 0.e0
+         tml_sum        (:,:)   = 0.e0   ;   sml_sum        (:,:)   = 0.e0
+         tmltrd_csum_ln (:,:,:) = 0.e0   ;   smltrd_csum_ln (:,:,:) = 0.e0
+         tmltrd_sum     (:,:,:) = 0.e0   ;   smltrd_sum     (:,:,:) = 0.e0
+
+         rmld_sum       (:,:)   = 0.e0
+         !
+      END IF
 
    END SUBROUTINE trd_mld
@@ -642,213 +709,218 @@
       !!      from ocean surface down to control surface (NetCDF output)
       !!
-      !! ** Method/usage :
-      !!
-      !! History :
-      !!        !  95-04  (J. Vialard)  Original code
-      !!        !  97-02  (E. Guilyardi)  Adaptation global + base cmo
-      !!        !  99-09  (E. Guilyardi)  Re-writing + netCDF output
-      !!   8.5  !  02-06  (G. Madec)  F90: Free form and module
-      !!   9.0  !  04-08  (C. Talandier) New trends organization
       !!----------------------------------------------------------------------
       !! * Local declarations
-      INTEGER :: ilseq
+      INTEGER :: ilseq, jl
 
       REAL(wp) ::   zjulian, zsto, zout
 
-      CHARACTER (LEN=21) ::   &
+      CHARACTER (LEN=21) ::    &
          clold ='OLD'        , & ! open specifier (direct access files)
          clunf ='UNFORMATTED', & ! open specifier (direct access files)
          clseq ='SEQUENTIAL'     ! open specifier (direct access files)
-      CHARACTER (LEN=40) ::   clhstnam
       CHARACTER (LEN=40) ::   clop
-      CHARACTER (LEN=12) ::   clmxl
-
-      NAMELIST/namtrd/ ntrd, nctls
+      CHARACTER (LEN=12) ::   clmxl, cltu, clsu
+
       !!----------------------------------------------------------------------
 
-      !  ===================
-      !   I. initialization
-      !  ===================
-
-      ! Open specifier
-      ilseq  = 1
-      idebug = 0      ! set it to 1 in case of problem to have more print
-      icount = 1      
-      ionce  = 1
-
-      ! namelist namtrd : trend diagnostic
-      REWIND( numnam )
-      READ  ( numnam, namtrd )
+      ! ======================================================================
+      ! I. initialization
+      ! ======================================================================
 
       IF(lwp) THEN
-         WRITE(numout,*) ' '
-         WRITE(numout,*) 'trd_mld_init: mixed layer heat & freshwater budget trends'
-         WRITE(numout,*) '~~~~~~~~~~~~~'
-         WRITE(numout,*) ' '
-         WRITE(numout,*) '          Namelist namtrd : '
-         WRITE(numout,*) '             control surface for trends      nctls = ',nctls
-         WRITE(numout,*) ' '
-      ENDIF
-
-      ! cumulated trends array init
+         WRITE(numout,*)
+         WRITE(numout,*) ' trd_mld_init : Mixed-layer trends'
+         WRITE(numout,*) ' ~~~~~~~~~~~~~'
+         WRITE(numout,*) '                namelist namtrd read in trd_mod_init                        '
+         WRITE(numout,*)
+      END IF
+
+      ! I.1 Check consistency of user defined preferences
+      ! -------------------------------------------------
+
+      IF( ( lk_trdmld ) .AND. ( MOD( nitend, ntrd ) /= 0 ) ) THEN
+         WRITE(numout,cform_err)
+         WRITE(numout,*) '                Your nitend parameter, nitend = ', nitend
+         WRITE(numout,*) '                is no multiple of the trends diagnostics frequency        '
+         WRITE(numout,*) '                          you defined, ntrd   = ', ntrd
+         WRITE(numout,*) '                This will not allow you to restart from this simulation.  '
+         WRITE(numout,*) '                You should reconsider this choice.                        ' 
+         WRITE(numout,*) 
+         WRITE(numout,*) '                N.B. the nitend parameter is also constrained to be a     '
+         WRITE(numout,*) '                multiple of the sea-ice frequency parameter (typically 5) '
+         nstop = nstop + 1
+      END IF
+
+      IF( ( lk_trdmld ) .AND. ( n_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
+
+      ! I.2 Initialize arrays to zero or read a restart file
+      ! ----------------------------------------------------
+
       nmoymltrd = 0
-      tmltrdm(:,:) = 0.e0
-      smltrdm(:,:) = 0.e0
-
-      !  read control surface from file ctlsurf_idx
-
+
+      !     ... temperature ...                  ... salinity ...
+      tml            (:,:)   = 0.e0    ;    sml            (:,:)   = 0.e0     ! inst.
+      tmltrdm        (:,:)   = 0.e0    ;    smltrdm        (:,:)   = 0.e0
+      tmlatfm        (:,:)   = 0.e0    ;    smlatfm        (:,:)   = 0.e0
+      tml_sum        (:,:)   = 0.e0    ;    sml_sum        (:,:)   = 0.e0     ! mean
+      tmltrd_sum     (:,:,:) = 0.e0    ;    smltrd_sum     (:,:,:) = 0.e0
+      tmltrd_csum_ln (:,:,:) = 0.e0    ;    smltrd_csum_ln (:,:,:) = 0.e0
+
+      rmld           (:,:)   = 0.e0            
+      rmld_sum       (:,:)   = 0.e0
+
+      IF( ln_rstart .AND. ln_trdmld_restart ) THEN
+         CALL trd_mld_rst_read
+      ELSE
+         !     ... temperature ...                  ... salinity ...
+         tmlb           (:,:)   = 0.e0    ;    smlb           (:,:)   = 0.e0  ! inst.
+         tmlbb          (:,:)   = 0.e0    ;    smlbb          (:,:)   = 0.e0  
+         tmlbn          (:,:)   = 0.e0    ;    smlbn          (:,:)   = 0.e0  
+         tml_sumb       (:,:)   = 0.e0    ;    sml_sumb       (:,:)   = 0.e0  ! mean
+         tmltrd_csum_ub (:,:,:) = 0.e0    ;    smltrd_csum_ub (:,:,:) = 0.e0
+         tmltrd_atf_sumb(:,:)   = 0.e0    ;    smltrd_atf_sumb(:,:)   = 0.e0  
+      END IF
+
+      ilseq  = 1   ;   icount = 1   ;   ionce  = 1                            ! open specifier
+
+      ! I.3 Read control surface from file ctlsurf_idx
+      ! ----------------------------------------------
+ 
       IF( nctls == 1 ) THEN
-         clname ='ctlsurf_idx'
-         CALL ctlopn(numbol,clname,clold,clunf,clseq,   &
-              ilseq,numout,lwp,1)
-         REWIND (numbol)
-         READ(numbol) nbol
-      ENDIF
-
-
-      IF( idebug /= 0 ) THEN
-         WRITE(numout,*) ' debuging trd_mld_init: 0. done '  
-         CALL FLUSH(numout)
-      ENDIF
-
-      !  ===================================
-      !   II. netCDF output initialization
-      !  ===================================
+         clname = 'ctlsurf_idx'
+         CALL ctlopn( numbol, clname, clold, clunf, clseq, ilseq, numout, lwp, 1 )
+         REWIND( numbol )
+         READ  ( numbol ) nbol
+      END IF
+
+      ! ======================================================================
+      ! II. netCDF output initialization
+      ! ======================================================================
 
 #if defined key_dimgout 
-
+      ???
 #else
-      !     clmxl = legend root for netCDF output
-      IF( nctls == 0 ) THEN
-         ! control surface = mixed-layer with density criterion 
-         ! (array nmln computed in zdfmxl.F90)
-         clmxl = 'Mixed Layer '
-      ELSE IF( nctls == 1 ) THEN
-         ! control surface = read index from file 
+      ! clmxl = legend root for netCDF output
+      IF( nctls == 0 ) THEN      ! control surface = mixed-layer with density criterion
+         clmxl = 'Mixed Layer '  !                   (array nmln computed in zdfmxl.F90)
+      ELSE IF( nctls == 1 ) THEN ! control surface = read index from file 
          clmxl = '      Bowl '
-      ELSE IF( nctls >= 2 ) THEN
-         ! control surface = model level
-         WRITE(clmxl,'(A9,I2,1X)') 'Levels 1-', nctls
-      ENDIF
-
-      !-----------------------------------------
+      ELSE IF( nctls >= 2 ) THEN ! control surface = model level
+         WRITE(clmxl,'(A10,I2,1X)') 'Levels 1 -', nctls
+      END IF
+
       ! II.1 Define frequency of output and means
       ! -----------------------------------------
-
-#if defined key_diainstant
-      zsto = nwrite*rdt
-      clop ="inst(x)"
-#else
-      zsto = rdt
-      clop ="ave(x)"
-#endif
-      zout = nwrite*rdt
-
-      IF(lwp) WRITE (numout,*) ' trdmld_ncinit: netCDF initialization'
+#  if defined key_diainstant
+      IF( .NOT. ln_trdmld_instant ) THEN
+         CALL ctl_stop( 'trd_mld : this was never checked. Comment this line to proceed...' )
+      END IF
+      zsto = ntrd * rdt
+      clop ="inst(only(x))"
+#  else
+      IF( ln_trdmld_instant ) THEN
+         zsto = rdt                 ! inst. diags : we use IOIPSL time averaging
+      ELSE
+         zsto = ntrd * rdt          ! mean  diags : we DO NOT use any IOIPSL time averaging
+      END IF
+      clop ="ave(only(x))"
+#  endif
+      zout = ntrd * rdt
+
+      IF(lwp) WRITE (numout,*) '                netCDF initialization'
 
       ! II.2 Compute julian date from starting date of the run
-      ! ------------------------
-
+      ! ------------------------------------------------------
       CALL ymds2ju( nyear, nmonth, nday, 0.e0, zjulian )
-      IF (lwp) WRITE(numout,*)' '  
-      IF (lwp) WRITE(numout,*)' Date 0 used :',nit000   &
-           ,' YEAR ', nyear,' MONTH ', nmonth,' DAY ', nday   &
-           ,'Julian day : ', zjulian
+      IF(lwp) WRITE(numout,*)' '  
+      IF(lwp) WRITE(numout,*)'                Date 0 used :',nit000,    &
+         &                   ' YEAR ', nyear,' MONTH '      , nmonth,   &
+         &                   ' DAY ' , nday, 'Julian day : ', zjulian
 
 
       ! II.3 Define the T grid trend file (nidtrd)
-      ! ---------------------------------
-
-      CALL dia_nam( clhstnam, nwrite, 'trends' )                  ! filename
+      ! ------------------------------------------
+      !-- Define long and short names for the NetCDF output variables
+      !       ==> choose them according to trdmld_oce.F90 <==
+
+      ctrd(jpmld_xad,1) = " Zonal advection"                  ;   ctrd(jpmld_xad,2) = "_xad"
+      ctrd(jpmld_yad,1) = " Meridional advection"             ;   ctrd(jpmld_yad,2) = "_yad"
+      ctrd(jpmld_zad,1) = " Vertical advection"               ;   ctrd(jpmld_zad,2) = "_zad"
+      ctrd(jpmld_ldf,1) = " Lateral diffusion"                ;   ctrd(jpmld_ldf,2) = "_ldf"
+      ctrd(jpmld_for,1) = " Forcing"                          ;   ctrd(jpmld_for,2) = "_for"
+      ctrd(jpmld_zdf,1) = " Vertical diff. (Kz)"              ;   ctrd(jpmld_zdf,2) = "_zdf"
+      ctrd(jpmld_bbc,1) = " Geothermal flux"                  ;   ctrd(jpmld_bbc,2) = "_bbc"
+      ctrd(jpmld_bbl,1) = " Adv/diff. Bottom boundary layer"  ;   ctrd(jpmld_bbl,2) = "_bbl"
+      ctrd(jpmld_dmp,1) = " Tracer damping"                   ;   ctrd(jpmld_dmp,2) = "_dmp"
+      ctrd(jpmld_npc,1) = " Non penetrative convec. adjust."  ;   ctrd(jpmld_npc,2) = "_npc"
+      ctrd(jpmld_atf,1) = " Asselin time filter"              ;   ctrd(jpmld_atf,2) = "_atf"
+                                                                  
+      !-- Create a NetCDF file and enter the define mode 
+      CALL dia_nam( clhstnam, ntrd, 'trends' )
       IF(lwp) WRITE(numout,*) ' Name of NETCDF file ', clhstnam
-      CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,1, jpi,   &  ! Horizontal grid : glamt and gphit
-         &          1, jpj, 0, zjulian, rdt, nh_t, nidtrd, domain_id=nidom )
-
-      ! Declare output fields as netCDF variables
-
-      ! Mixed layer Depth
-      CALL histdef( nidtrd, "somlttml", clmxl//"Depth"              , "m"   ,   &  ! hmlp
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-
-      ! Temperature
-      CALL histdef( nidtrd, "somltemp", clmxl//"Temperature"        , "C"   ,   &  ! ???
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      ! Temperature trends
-      CALL histdef( nidtrd, "somlttto", clmxl//"T Total"             , "C/s",   &  ! total
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zout, zout )
-      CALL histdef( nidtrd, "somlttax", clmxl//"T Zonal Advection", "C/s",       & ! i-adv.
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somlttay", clmxl//"T Meridional Advection", "C/s",   & ! j-adv.
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somlttaz", clmxl//"T Vertical Advection", "C/s",   & ! vert. adv.
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somlttdh", clmxl//"T Horizontal Diffusion ", "C/s",   & ! hor. lateral diff.
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somlttfo", clmxl//"T Forcing", "C/s",   & ! forcing
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somlbtdz", clmxl//"T Vertical Diffusion", "C/s",   & ! vert. diff.
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somlbtdt", clmxl//"T dh/dt Entrainment (Residual)", "C/s",   & ! T * dh/dt 
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zout, zout )
-      IF( ln_traldf_iso ) THEN
-      CALL histdef( nidtrd, "somlbtdv", clmxl//"T Vert. lateral Diffusion","C/s",   & ! vertical diffusion entrainment (ISO)
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      ENDIF
-#if defined key_traldf_eiv
-      CALL histdef( nidtrd, "somlgtax", clmxl//"T Zonal EIV Advection", "C/s",   & ! i-adv. (eiv)
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somlgtay", clmxl//"T Meridional EIV Advection", "C/s",   & ! j-adv. (eiv)
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somlgtaz", clmxl//"T Vertical EIV Advection", "C/s",   & ! vert. adv. (eiv)
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somlgtat", clmxl//"T Total EIV Advection", "C/s",   & ! total advection (eiv)
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-#endif
-      ! Salinity
-      CALL histdef( nidtrd, "somlsalt", clmxl//"Salinity", "PSU",   & ! Mixed-layer salinity
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      ! Salinity trends
-      CALL histdef( nidtrd, "somltsto", clmxl//"S Total", "PSU/s",   & ! total 
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somltsax", clmxl//"S Zonal Advection", "PSU/s",   & ! i-advection
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somltsay", clmxl//"S Meridional Advection", "PSU/s",   & ! j-advection
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somltsaz", clmxl//"S Vertical Advection", "PSU/s",   & ! vertical advection
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somltsdh", clmxl//"S Horizontal Diffusion ", "PSU/s",   & ! hor. lat. diff.
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somltsfo", clmxl//"S Forcing", "PSU/s",   & ! forcing
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-
-      CALL histdef( nidtrd, "somlbsdz", clmxl//"S Vertical Diffusion", "PSU/s",   & ! vert. diff.
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somlbsdt", clmxl//"S dh/dt Entrainment (Residual)", "PSU/s",   & ! S * dh/dt 
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      IF( ln_traldf_iso ) THEN
-      ! vertical diffusion entrainment (ISO)
-      CALL histdef( nidtrd, "somlbsdv", clmxl//"S Vertical lateral Diffusion", "PSU/s",   & ! vert. lat. diff.
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      ENDIF
-#if defined key_traldf_eiv
-      CALL histdef( nidtrd, "somlgsax", clmxl//"S Zonal EIV Advection", "PSU/s",   & ! i-advection (eiv)
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somlgsay", clmxl//"S Meridional EIV Advection", "PSU/s",   & ! j-advection (eiv)
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somlgsaz", clmxl//"S Vertical EIV Advection", "PSU/s",   & ! vert. adv. (eiv)
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-      CALL histdef( nidtrd, "somlgsat", clmxl//"S Total EIV Advection", "PSU/s",   & ! total adv. (eiv)
-         &          jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-#endif
+      CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,                                            &
+      &             1, jpi, 1, jpj, 0, zjulian, rdt, nh_t, nidtrd, domain_id=nidom )
+
+      !-- Define the ML depth variable
+      CALL histdef(nidtrd, "mxl_depth", clmxl//"  Mixed Layer Depth"              , "m",         &
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+
+      !-- Define physical units
+      IF( ucf == 1. ) THEN
+         cltu = "degC/s"     ;   clsu = "p.s.u./s"
+      ELSEIF ( ucf == 3600.*24.) THEN
+         cltu = "degC/day"   ;   clsu = "p.s.u./day"
+      ELSE
+         cltu = "unknown?"   ;   clsu = "unknown?"
+      END IF
+
+      !-- Define miscellaneous T and S mixed-layer variables 
+
+      IF( jpltrd /= jpmld_atf ) CALL ctl_stop( 'Error : jpltrd /= jpmld_atf' ) ! see below
+
+      !................................. ( ML temperature ) ...................................
+
+      CALL histdef(nidtrd, "tml"      , clmxl//" T Mixed Layer Temperature"       ,  "C",        &
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )           
+      CALL histdef(nidtrd, "tml_tot",   clmxl//" T Total trend"                   , cltu,        & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zout, zout )              
+      CALL histdef(nidtrd, "tml_res",   clmxl//" T dh/dt Entrainment (Resid.)"    , cltu,        & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zout, zout )                   
+      
+      DO jl = 1, jpltrd - 1      ! <== only true if jpltrd == jpmld_atf
+         CALL histdef(nidtrd, trim("tml"//ctrd(jl,2)), clmxl//" T"//ctrd(jl,1), cltu,            & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout ) ! IOIPSL: time mean
+      END DO                                                                 ! if zsto=rdt above
+      
+      CALL histdef(nidtrd, trim("tml"//ctrd(jpmld_atf,2)), clmxl//" T"//ctrd(jpmld_atf,1), cltu, & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zout, zout ) ! IOIPSL: NO time mean
+      
+      !.................................. ( ML salinity ) .....................................
+     
+      CALL histdef(nidtrd, "sml"      , clmxl//" S Mixed Layer Salinity"          , "p.s.u.",       &
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout )           
+      CALL histdef(nidtrd, "sml_tot",   clmxl//" S Total trend"                   , clsu,        & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zout, zout )              
+      CALL histdef(nidtrd, "sml_res",   clmxl//" S dh/dt Entrainment (Resid.)"    , clsu,        & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zout, zout )                   
+      
+      DO jl = 1, jpltrd - 1      ! <== only true if jpltrd == jpmld_atf
+         CALL histdef(nidtrd, trim("sml"//ctrd(jl,2)), clmxl//" S"//ctrd(jl,1), clsu,            & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zsto, zout ) ! IOIPSL: time mean
+      END DO                                                                 ! if zsto=rdt above
+      
+      CALL histdef(nidtrd, trim("sml"//ctrd(jpmld_atf,2)), clmxl//" S"//ctrd(jpmld_atf,1), clsu, & 
+                   jpi, jpj, nh_t, 1  , 1, 1  , -99 , 32, clop, zout, zout ) ! IOIPSL: NO time mean
+
+      !-- Leave IOIPSL/NetCDF define mode
       CALL histend( nidtrd )
-#endif
-
-      IF( idebug /= 0 ) THEN
-         WRITE(numout,*) ' debuging trd_mld_init: II. done'  
-         CALL FLUSH(numout)
-      ENDIF
-
-
-      END SUBROUTINE trd_mld_init
+
+#endif        /* key_dimgout */
+   END SUBROUTINE trd_mld_init
 
 #else
@@ -856,5 +928,4 @@
    !!   Default option :                                       Empty module
    !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trdmld = .FALSE.   !: momentum trend flag
 CONTAINS
    SUBROUTINE trd_mld( kt )             ! Empty routine
Index: trunk/NEMO/OPA_SRC/TRD/trdmld_oce.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRD/trdmld_oce.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRD/trdmld_oce.F90	(revision 503)
@@ -4,27 +4,32 @@
    !! Ocean trends :   set tracer and momentum trend variables
    !!======================================================================
+   !! History :  9.0  !  04-08  (C. Talandier)  New trends organization
    !!----------------------------------------------------------------------
-   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
-   !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !! * Modules used
    USE par_oce         ! ocean parameters
 
    IMPLICIT NONE
-   PUBLIC
+   PRIVATE
 
-   INTEGER, PARAMETER ::            &  !: mixed layer trends index
-      jpmldxad = 1,   &  !: zonal advection
-      jpmldyad = 2,   &  !: meridionnal advection
-      jpmldzad = 3,   &  !: vertical advection
-      jpmldldf = 4,   &  !: lateral diffusion (horiz. component+Beckman)
-      jpmldfor = 5,   &  !: forcing 
-      jpmldevd = 6,   &  !: entrainment due to vertical diffusion (TKE)
-      jpmldzdf = 7,   &  !: explicit vertical part if isopycnal diffusion
-      jpmldxei = 8,   &  !: eddy induced zonal advection
-      jpmldyei = 9,   &  !: eddy induced meridional advection
-      jpmldzei =10       !: eddy induced vertical advection
+#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
+   INTEGER, PARAMETER, PUBLIC ::   jpktrd = jpk   !: max level for mixed-layer trends diag.
+   !
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_xad =  1   !:  zonal      \
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_yad =  2   !:  meridonal   > advection
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_zad =  3   !:  vertical   /
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_ldf =  4   !:  lateral diffusion (geopot. or iso-neutral)
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_for =  5   !:  forcing 
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_zdf =  6   !:  vertical diffusion (TKE)
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_bbc =  7   !:  geothermal flux
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_bbl =  8   !:  bottom boundary layer (advective/diffusive)
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_dmp =  9   !:  internal restoring trend
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_npc = 10   !:  non penetrative convective adjustment
+   INTEGER, PUBLIC, PARAMETER ::   jpmld_atf = 11   !:  asselin trend
+!! INTEGER, PUBLIC, PARAMETER ::   jpmld_xxx = xx   !:  add here any additional trend (add change jpltrd)
 
 #if   defined  key_trdmld   ||   defined key_esopa
@@ -33,16 +38,48 @@
    !!----------------------------------------------------------------------
 
-   !! Trends diagnostics parameters
+   !! Arrays used for diagnosing mixed-layer trends 
    !!---------------------------------------------------------------------
-   INTEGER, PARAMETER ::            &  !:
-# if defined key_traldf_eiv
-      jpltrd = 10,  &  !: number of mixed-layer trends arrays
-      jpktrd = jpk     !: max level for mixed-layer trends diag.
-# else
-      jpltrd = 7,   &  !: number of mixed-layer trends arrays
-      jpktrd = jpk     !: max level for mixed-layer trends diag.
-# endif
+   CHARACTER(LEN=80) , PUBLIC :: clname, ctrd(jpltrd+1,2)
 
+   INTEGER , PUBLIC, DIMENSION(jpi,jpj)     ::   nmld   !: mixed layer depth indexes 
+   INTEGER , PUBLIC, DIMENSION(jpi,jpj)     ::   nbol   !: mixed-layer depth indexes when read from file
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   wkx    !:
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::  &
+      rmld   ,                      & !: mld depth (m) corresponding to nmld
+      tml    , sml  ,               & !: \ "now" mixed layer temperature/salinity
+      tmlb   , smlb ,               & !: /  and associated "before" fields
+      tmlbb  , smlbb,               & !: \  idem, but valid at the 1rst time step of the
+      tmlbn  , smlbn,               & !: /  current analysis window
+      tmltrdm, smltrdm,             & !: total cumulative trends over the analysis window
+      tml_sum,                      & !: mixed layer T, summed over the current analysis period
+      tml_sumb,                     & !: idem, but from the previous analysis period
+      tmltrd_atf_sumb,              & !: Asselin trends, summed over the previous analysis period
+      sml_sum,                      & !: 
+      sml_sumb,                     & !:    ( idem for salinity )
+      smltrd_atf_sumb,              & !: 
+      rmld_sum, rmldbn                !: needed to compute the leap-frog time mean of the ML depth
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::  &
+      tmlatfb, tmlatfn ,            & !: "before" Asselin contribution at begining of the averaging
+      smlatfb, smlatfn,             & !: period (i.e. last contrib. from previous such period) and 
+                                      !: "now" Asselin contribution to the ML temp. & salinity trends
+      tmlatfm, smlatfm                !: accumulator for Asselin trends (needed for storage only)
+
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpltrd) ::  &
+      tmltrd,                       & !: \ physical contributions to the total trend (for T/S),
+      smltrd,                       & !: / cumulated over the current analysis window
+      tmltrd_sum,                   & !: sum of these trends over the analysis period
+      tmltrd_csum_ln,               & !: now cumulated sum of the trends over the "lower triangle"
+      tmltrd_csum_ub,               & !: before (prev. analysis period) cumulated sum over the upper triangle
+      smltrd_sum,                   & !: 
+      smltrd_csum_ln,               & !:    ( idem for salinity )
+      smltrd_csum_ub                  !: 
 #endif
-  !!======================================================================
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!======================================================================
 END MODULE trdmld_oce
Index: trunk/NEMO/OPA_SRC/TRD/trdmld_rst.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRD/trdmld_rst.F90	(revision 503)
+++ trunk/NEMO/OPA_SRC/TRD/trdmld_rst.F90	(revision 503)
@@ -0,0 +1,195 @@
+MODULE trdmld_rst
+   !!=================================================================================
+   !!                       ***  MODULE  trdmld_rst  ***
+   !! Ocean dynamic :  Input/Output files for restart on mixed-layer diagnostics
+   !!=================================================================================
+   !! History :  9.0  ! 05-05 (C. Deltel) Original code
+   !!---------------------------------------------------------------------------------
+#if defined key_trdmld
+   !!---------------------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE trdmod_oce      ! ocean variables for trend diagnostics (i.e. icp/mixed-layer/vorticity)
+   USE in_out_manager  ! I/O manager
+   USE daymod          ! calendar
+   USE ioipsl          !
+
+   IMPLICIT NONE
+   PRIVATE
+  
+   PUBLIC   trd_mld_rst_read    ! routine called by trd_mld_init
+   PUBLIC   trd_mld_rst_write   ! routine called by step.F90
+  
+   CHARACTER (len=48) ::   crestart = 'initial.nc'   ! restart file name
+   !!---------------------------------------------------------------------------------
+   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !!---------------------------------------------------------------------------------
+  
+CONTAINS
+  
+   SUBROUTINE trd_mld_rst_write( kt )
+      !!--------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE trd_mld_rst_wri  ***
+      !!                
+      !! ** Purpose :   Write mixed-layer diagnostics restart fields.
+      !!-----------------------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !!    
+      LOGICAL ::   llbon
+      CHARACTER (len=50) ::   clname, cln
+      REAL(wp) ::   zdate0
+      REAL(wp), DIMENSION(1) :: zdept
+      INTEGER ::   ic, jc, itime, inumwrs_mld
+      !!-----------------------------------------------------------------------------
+    
+      IF( ( mod( kt, nstock ) == 0 ) .OR. ( kt == nitend ) ) THEN
+             
+         inumwrs_mld = 47
+         !-- Delete the restart file if it exists 
+         INQUIRE( FILE=crestart, EXIST=llbon )
+         IF(llbon) THEN
+            OPEN( UNIT=inumwrs_mld, FILE=crestart, STATUS='old' )
+            CLOSE( inumwrs_mld, STATUS='delete' )
+         ENDIF
+
+         !-- Name of the new restart file
+         ic = 1
+         DO jc = 1, 16
+            IF( cexper(jc:jc) /= ' ' )   ic = jc
+         END DO
+         WRITE(cln,'("_",i4.4,i2.2,i2.2,"_restart_mld")') nyear, nmonth, nday
+         clname = cexper(1:ic)//cln
+         ic = 1
+         DO jc = 1, 48
+            IF( clname(jc:jc) /= ' ' ) ic = jc
+         END DO
+         crestart = clname(1:ic)//".nc"
+         itime = 0
+         CALL ymds2ju( nyear, nmonth, nday, 0.e0, zdate0 )
+
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'trdmld_rst: output for ML diags. restart, with trd_mld_rst_write routine'
+            WRITE(numout,*) '~~~~~~~~~~'
+            WRITE(numout,*) '            in file : ', TRIM(crestart), ' at it= ', kt, ' date= ', ndastp
+            WRITE(numout,*)
+         ENDIF
+
+         !-- Create the NetCDF restart file and write tje appropriate fields
+         !   N.B. In this section, 3rd dimension in arrays is NOT depth 
+         zdept(1) = 1.
+         CALL restini( 'NONE', jpi, jpj, glamt, gphit, 1, zdept, clname,   &
+            &          itime, zdate0, rdt*nstock ,inumwrs_mld, domain_id=nidom )
+       
+         IF( ln_trdmld_instant ) THEN 
+            CALL restput( inumwrs_mld, 'tmlbb'           , jpi, jpj,      1, 0, tmlbb           )
+            CALL restput( inumwrs_mld, 'tmlbn'           , jpi, jpj,      1, 0, tmlbn           )
+            CALL restput( inumwrs_mld, 'tmlatfb'         , jpi, jpj,      1, 0, tmlatfb         )
+
+            CALL restput( inumwrs_mld, 'smlbb'           , jpi, jpj,      1, 0, smlbb           )
+            CALL restput( inumwrs_mld, 'smlbn'           , jpi, jpj,      1, 0, smlbn           )
+            CALL restput( inumwrs_mld, 'smlatfb'         , jpi, jpj,      1, 0, smlatfb         )
+         ELSE
+            CALL restput( inumwrs_mld, 'rmldbn'          , jpi, jpj,      1, 0, rmldbn          )
+
+            !-- Temperature
+            CALL restput( inumwrs_mld, 'tmlbn'           , jpi, jpj,      1, 0, tmlbn           )
+            CALL restput( inumwrs_mld, 'tml_sumb'        , jpi, jpj,      1, 0, tml_sumb        )
+            CALL restput( inumwrs_mld, 'tmltrd_csum_ub'  , jpi, jpj, jpltrd, 0, tmltrd_csum_ub  )
+            CALL restput( inumwrs_mld, 'tmltrd_atf_sumb' , jpi, jpj,      1, 0, tmltrd_atf_sumb )
+
+            !-- Salinity
+            CALL restput( inumwrs_mld, 'smlbn'           , jpi, jpj,      1, 0, smlbn           )
+            CALL restput( inumwrs_mld, 'sml_sumb'        , jpi, jpj,      1, 0, sml_sumb        )
+            CALL restput( inumwrs_mld, 'smltrd_csum_ub'  , jpi, jpj, jpltrd, 0, smltrd_csum_ub  )
+            CALL restput( inumwrs_mld, 'smltrd_atf_sumb' , jpi, jpj,      1, 0, smltrd_atf_sumb )
+         ENDIF
+         !
+         CALL restclo( inumwrs_mld )
+         ! 
+      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.
+    !!----------------------------------------------------------------------------
+    LOGICAL ::   llog
+    REAL(wp) ::  zlamt(jpi,jpj), zphit(jpi,jpj)
+    CHARACTER (len=8 ) ::   clvnames(30)
+    CHARACTER (len=32) ::   clname = 'restart_mld'
+    INTEGER  ::  itime, ibvar, &  
+                 inum  ! temporary logical unit
+    REAL(wp) ::   zdate0, zdt
+    REAL(wp), DIMENSION(1) :: zdept
+    !!-----------------------------------------------------------------------------
+
+    IF(lwp)  THEN
+       WRITE(numout,*)
+       WRITE(numout,*) ' trd_mld_rst_read : read the NetCDF MLD restart file'
+       WRITE(numout,*) ' ~~~~~~~~~~~~~~~~'
+    ENDIF
+
+    itime = 0
+    llog  = .FALSE.
+    zlamt(:,:) = 0.e0   ;   zphit(:,:) = 0.e0   ;   zdept(1)   = 0.e0
+    CALL restini( clname, jpi, jpj, zlamt, zphit, 1, zdept, 'NONE',   &
+       &          itime, zdate0, zdt, inum, domain_id=nidom )
+  
+    CALL ioget_vname( inum, ibvar, clvnames)
+
+    IF(lwp) THEN
+       WRITE(numout,*) 
+       WRITE(numout,*) '                    Info on the MLD restart file read : '
+       WRITE(numout,*) '                      File name           : ', clname
+       WRITE(numout,*) '                      number of variables : ', ibvar
+       WRITE(numout,*) '                      NetCDF variables    : ', clvnames
+       WRITE(numout,*)
+    ENDIF
+
+    IF( ln_trdmld_instant ) THEN 
+       CALL restget( inum, 'tmlbb'           , jpi, jpj,      1, 0, llog, tmlbb          )
+       CALL restget( inum, 'tmlbn'           , jpi, jpj,      1, 0, llog, tmlbn          )
+       CALL restget( inum, 'tmlatfb'         , jpi, jpj,      1, 0, llog, tmlatfb        )
+
+       CALL restget( inum, 'smlbb'           , jpi, jpj,      1, 0, llog, smlbb          )
+       CALL restget( inum, 'smlbn'           , jpi, jpj,      1, 0, llog, smlbn          )
+       CALL restget( inum, 'smlatfb'         , jpi, jpj,      1, 0, llog, smlatfb        )
+    ELSE
+       CALL restget( inum, 'rmldbn'          , jpi, jpj,      1, 0, llog, rmldbn         ) ! needed for rmld_sum
+
+       !-- Temperature
+       CALL restget( inum, 'tmlbn'           , jpi, jpj,      1, 0, llog, tmlbn          ) ! needed for tml_sum
+       CALL restget( inum, 'tml_sumb'        , jpi, jpj,      1, 0, llog, tml_sumb       )
+       CALL restget( inum, 'tmltrd_csum_ub'  , jpi, jpj, jpltrd, 0, llog, tmltrd_csum_ub )
+       CALL restget( inum, 'tmltrd_atf_sumb' , jpi, jpj,      1, 0, llog, tmltrd_atf_sumb)
+
+       !-- Salinity
+       CALL restget( inum, 'smlbn'           , jpi, jpj,      1, 0, llog, smlbn          ) ! needed for sml_sum
+       CALL restget( inum, 'sml_sumb'        , jpi, jpj,      1, 0, llog, sml_sumb       )
+       CALL restget( inum, 'smltrd_csum_ub'  , jpi, jpj, jpltrd, 0, llog, smltrd_csum_ub )
+       CALL restget( inum, 'smltrd_atf_sumb' , jpi, jpj,      1, 0, llog, smltrd_atf_sumb)
+
+       CALL restclo( 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: trunk/NEMO/OPA_SRC/TRD/trdmod.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRD/trdmod.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRD/trdmod.F90	(revision 503)
@@ -4,23 +4,31 @@
    !! Ocean diagnostics:  ocean tracers and dynamic trends
    !!=====================================================================
+   !! History :  9.0  !  04-08  (C. Talandier) Original code
+   !!                 !  05-04  (C. Deltel)    Add Asselin trend in the ML budget
+   !!----------------------------------------------------------------------
 #if  defined key_trdtra || defined key_trddyn || defined key_trdmld || defined key_trdvor || defined key_esopa
    !!----------------------------------------------------------------------
    !!   trd_mod          : Call the trend to be computed
-   !!----------------------------------------------------------------------
-   !! * Modules used
+   !!   trd_mod_init     : Initialization step
+   !!----------------------------------------------------------------------
+   USE phycst                  ! physical constants
    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 ldftra_oce              ! ocean active tracers lateral physics
    USE trdvor                  ! ocean vorticity trends 
    USE trdicp                  ! ocean bassin integral constraints properties
    USE trdmld                  ! ocean active mixed layer tracers trends 
-   USE trabbl                  ! bottom boundary layer variables
    USE in_out_manager          ! I/O manager
+   USE taumod                  ! surface ocean stress
 
    IMPLICIT NONE
    PRIVATE
 
-   !! * Routine accessibility
-   PUBLIC trd_mod        ! called by all dynXX or traXX modules
+   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
@@ -30,104 +38,117 @@
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
 CONTAINS
 
-   SUBROUTINE trd_mod(ptrdx, ptrdy, ktrd, ctype, kt)
+   SUBROUTINE trd_mod( ptrdx, ptrdy, ktrd, ctype, kt, cnbpas )
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE trd_mod  ***
       !! 
       !! ** Purpose : Dispatch all trends computation, e.g. vorticity, mld or 
-      !!              integral constrains
+      !!              integral constraints
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt                                ! time step
+      INTEGER, INTENT( in ) ::   ktrd                              ! tracer trend index
+      CHARACTER(len=3), INTENT( in ) ::   ctype                    ! momentum or tracers trends type 'DYN'/'TRA'
+      CHARACTER(len=3), INTENT( in ), OPTIONAL ::   cnbpas         ! number of passage
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   ptrdx ! Temperature or U trend 
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   ptrdy ! Salinity    or V trend
       !!
-      !! ** Method :
-      !!
-      !! History :
-      !!   9.0  !  04-08  (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------
-      !! * Modules used
-#if defined key_trabbl_adv
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  &  ! temporary arrays
-         &         zun, zvn
-#else
-      USE oce                , zun => un,  &  ! When no bbl, zun == un
-         &                     zvn => vn      ! When no bbl, zvn == vn
-#endif
-
-      !! * Arguments
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
-         ptrdx,                      &   ! Temperature or U trend 
-         ptrdy                           ! Salinity    or V trend
-
-      INTEGER, INTENT( in ) ::   &
-         kt  ,                   & ! time step
-         ktrd                      ! tracer trend index
-
-      CHARACTER(len=3), INTENT( in ) ::   &
-         ctype                             ! momentum or tracers trends type
-         !                                 ! 'DYN' or 'TRA'
-
-      !! * Local save
-      REAL(wp), DIMENSION(jpi,jpj), SAVE ::   &
-         zbtr2
-
-      !! * Local declarations
-      INTEGER ::   ji, jj, jk    ! loop indices
-      REAL(wp) ::   &
-         zbtr,            &  ! temporary scalars
-         zfui, zfvj,           &  !    "         "
-         zfui1, zfvj1             !    "         "
-      REAL(wp), DIMENSION(jpi,jpj) ::   &
-         z2dx, z2dy                        ! workspace arrays
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   &
-         z3dx, z3dy                            ! workspace arrays
-      !!----------------------------------------------------------------------
-
-      ! Initialization of workspace arrays
-      z3dx(:,:,:) = 0.e0
-      z3dy(:,:,:) = 0.e0
-      z2dx(:,:) = 0.e0
-      z2dy(:,:) = 0.e0
+      INTEGER ::   ji, ikbu, ikbum1
+      INTEGER ::   jj, ikbv, ikbvm1
+      CHARACTER(len=3) ::   clpas                                  ! number of passage
+      REAL(wp) ::   zua, zva                                       ! scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztswu, ztswv               ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztbfu, ztbfv               ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   z2dx, z2dy                 ! workspace arrays
+      !!----------------------------------------------------------------------
+
+      z2dx(:,:)   = 0.e0   ;   z2dy(:,:)   = 0.e0                  ! initialization of workspace arrays
+
+      ! Control of optional arguments
+      clpas = 'fst'
+      IF( PRESENT(cnbpas) )  clpas = cnbpas
+
+      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdtra (restarting with Euler time stepping)
+      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdttra (leapfrog)
+      ENDIF
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! I. Bassin averaged properties for momentum and/or tracers trends
+      ! I. Integral Constraints Properties for momentum and/or tracers trends
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
       IF( ( mod(kt,ntrd) == 0 .OR. kt == nit000 .OR. kt == nitend) )   THEN
-
-         ! Active tracers trends 
-         IF( lk_trdtra .AND. ctype == 'TRA' )   THEN
-
-            IF( ktrd == jpttdnsr )   THEN
-               ! 2D array tracers surface forcing
-               z2dx(:,:) = ptrdx(:,:,1)
-               z2dy(:,:) = ptrdy(:,:,1)
-
-               CALL trd(z2dx, z2dy, ktrd, ctype)
-            ELSE
-               ! 3D array
-               CALL trd(ptrdx, ptrdy, ktrd, ctype)
-            ENDIF
-
-         ENDIF
-
-         ! Momentum trends 
-         IF( lk_trddyn .AND. ctype == 'DYN' )   THEN
-
-            IF( ktrd == jpdtdswf .OR. ktrd == jpdtdbfr )   THEN
-               ! momentum surface forcing/bottom friction  2D array
-               z2dx(:,:) = ptrdx(:,:,1)
-               z2dy(:,:) = ptrdy(:,:,1)
-
-               CALL trd(z2dx, z2dy, ktrd, ctype)
-            ELSE
-               ! 3D array
-               CALL trd(ptrdx, ptrdy, ktrd, ctype)
-            ENDIF
-
-         ENDIF
-
-      ENDIF
+         !
+         IF( lk_trdtra .AND. ctype == 'TRA' )   THEN       ! active tracer trends
+            SELECT CASE ( ktrd )
+            CASE ( jptra_trd_ldf )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_ldf, ctype )   ! lateral diff
+            CASE ( jptra_trd_zdf )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_zdf, ctype )   ! vertical diff (Kz)
+            CASE ( jptra_trd_bbc )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_bbc, ctype )   ! bottom boundary cond
+            CASE ( jptra_trd_bbl )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_bbl, ctype )   ! bottom boundary layer
+            CASE ( jptra_trd_npc )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_npc, ctype )   ! static instability mixing
+            CASE ( jptra_trd_dmp )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_dmp, ctype )   ! damping
+            CASE ( jptra_trd_qsr )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_qsr, ctype )   ! penetrative solar radiat.
+            CASE ( jptra_trd_nsr )   
+               z2dx(:,:) = ptrdx(:,:,1)   ;   z2dy(:,:) = ptrdy(:,:,1)
+               CALL trd_icp( z2dx, z2dy, jpicpt_nsr, ctype )                               ! non solar radiation
+            CASE ( jptra_trd_xad )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_xad, ctype )   ! x- horiz adv
+            CASE ( jptra_trd_yad )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_yad, ctype )   ! y- horiz adv
+            CASE ( jptra_trd_zad )                                                         ! z- vertical adv 
+               CALL trd_icp( ptrdx, ptrdy, jpicpt_zad, ctype, clpas )   
+               ! compute the surface flux condition wn(:,:,1)*tn(:,:,1)                                                                   
+               z2dx(:,:) = wn(:,:,1)*tn(:,:,1)/fse3t(:,:,1)   
+               z2dy(:,:) = wn(:,:,1)*sn(:,:,1)/fse3t(:,:,1)
+               CALL trd_icp( z2dx , z2dy , jpicpt_zl1, ctype )                             ! 1st z- vertical adv 
+            END SELECT
+         END IF
+
+         IF( lk_trddyn .AND. ctype == 'DYN' )   THEN       ! momentum trends 
+            !
+            SELECT CASE ( ktrd )
+            CASE ( jpdyn_trd_hpg )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_hpg, ctype )   ! hydrost. pressure grad
+            CASE ( jpdyn_trd_keg )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_keg, ctype )   ! KE gradient 
+            CASE ( jpdyn_trd_rvo )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_rvo, ctype )   ! relative vorticity 
+            CASE ( jpdyn_trd_pvo )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_pvo, ctype )   ! planetary vorticity
+            CASE ( jpdyn_trd_ldf )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_ldf, ctype )   ! lateral diffusion 
+            CASE ( jpdyn_trd_zad )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_zad, ctype )   ! vertical advection 
+            CASE ( jpdyn_trd_spg )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_spg, ctype )   ! surface pressure grad.
+            CASE ( jpdyn_trd_dat )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_dat, ctype )   ! damping term
+            CASE ( jpdyn_trd_zdf )                                                         ! vertical diffusion 
+               ! subtract surface forcing/bottom friction trends 
+               ! from vertical diffusive momentum trends
+               ztswu(:,:) = 0.e0   ;   ztswv(:,:) = 0.e0
+               ztbfu(:,:) = 0.e0   ;   ztbfv(:,:) = 0.e0  
+               DO jj = 2, jpjm1   
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+                     ! save the surface forcing momentum fluxes
+                     ztswu(ji,jj) = taux(ji,jj) / ( fse3u(ji,jj,1)*rau0 )
+                     ztswv(ji,jj) = tauy(ji,jj) / ( fse3v(ji,jj,1)*rau0 )
+                     ! save bottom friction momentum fluxes
+                     ikbu   = MIN( mbathy(ji+1,jj  ), mbathy(ji,jj) )
+                     ikbv   = MIN( mbathy(ji  ,jj+1), mbathy(ji,jj) )
+                     ikbum1 = MAX( ikbu-1, 1 )
+                     ikbvm1 = MAX( ikbv-1, 1 )
+                     zua = ua(ji,jj,ikbum1) * r2dt + ub(ji,jj,ikbum1)
+                     zva = va(ji,jj,ikbvm1) * r2dt + vb(ji,jj,ikbvm1)
+                     ztbfu(ji,jj) = - avmu(ji,jj,ikbu) * zua / ( fse3u(ji,jj,ikbum1)*fse3uw(ji,jj,ikbu) )
+                     ztbfv(ji,jj) = - avmv(ji,jj,ikbv) * zva / ( fse3v(ji,jj,ikbvm1)*fse3vw(ji,jj,ikbv) )
+                     !
+                     ptrdx(ji,jj,1     ) = ptrdx(ji,jj,1     ) - ztswu(ji,jj)
+                     ptrdy(ji,jj,1     ) = ptrdy(ji,jj,1     ) - ztswv(ji,jj)
+                     ptrdx(ji,jj,ikbum1) = ptrdx(ji,jj,ikbum1) - ztbfu(ji,jj)
+                     ptrdy(ji,jj,ikbvm1) = ptrdy(ji,jj,ikbvm1) - ztbfv(ji,jj)
+                  END DO
+               END DO
+               !
+               CALL trd_icp( ptrdx, ptrdy, jpicpd_zdf, ctype )   
+               CALL trd_icp( ztswu, ztswv, jpicpd_swf, ctype )                               ! wind stress forcing term
+               CALL trd_icp( ztbfu, ztbfv, jpicpd_bfr, ctype )                               ! bottom friction term
+            END SELECT
+            !
+         END IF
+         !
+      END IF
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -136,276 +157,87 @@
 
       IF( lk_trdvor .AND. ctype == 'DYN' )   THEN
-
-         SELECT CASE ( ktrd )
-
-         ! Pressure Gradient trend
-         CASE ( jpdtdhpg )      
-            CALL trd_vor_zint(ptrdx, ptrdy, jpvorprg)
-
-         ! KE Gradient trend
-         CASE ( jpdtdkeg )      
-            CALL trd_vor_zint(ptrdx, ptrdy, jpvorkeg)
-
-         ! Relative Vorticity trend
-         CASE ( jpdtdrvo )      
-            CALL trd_vor_zint(ptrdx, ptrdy, jpvorrvo)
-
-         ! Planetary Vorticity Term trend
-         CASE ( jpdtdpvo )      
-            CALL trd_vor_zint(ptrdx, ptrdy, jpvorpvo)
-
-         ! Horizontal Diffusion trend
-         CASE ( jpdtdldf )      
-            CALL trd_vor_zint(ptrdx, ptrdy, jpvorldf)
-
-         ! Vertical Advection trend
-         CASE ( jpdtdzad )      
-            CALL trd_vor_zint(ptrdx, ptrdy, jpvorzad)
-
-         ! Vertical Diffusion trend
-         CASE ( jpdtdzdf )      
-            CALL trd_vor_zint(ptrdx, ptrdy, jpvorzdf)
-
-         ! Surface Pressure Grad. trend
-         CASE ( jpdtdspg )      
-            CALL trd_vor_zint(ptrdx, ptrdy, jpvorspg)
-
-         ! Beta V trend 
-         CASE ( jpdtddat )      
-            CALL trd_vor_zint(ptrdx, ptrdy, jpvorbev)
-
-         ! Wind stress forcing term
-         CASE ( jpdtdswf )      
-            z2dx(:,:) = ptrdx(:,:,1)
-            z2dy(:,:) = ptrdy(:,:,1)
-
-            CALL trd_vor_zint(z2dx, z2dy, jpvorswf)
-
-         ! Bottom friction term
-         CASE ( jpdtdbfr )      
-            z2dx(:,:) = ptrdx(:,:,1)
-            z2dy(:,:) = ptrdy(:,:,1)
-
-            CALL trd_vor_zint(z2dx, z2dy, jpvorbfr)
-
+         !
+         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_dat )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_bev )   ! Beta V  
+         CASE ( jpdyn_trd_zdf )                                                      ! Vertical Diffusion 
+            ! subtract surface forcing/bottom friction trends 
+            ! from vertical diffusive momentum trends
+            ztswu(:,:) = 0.e0   ;   ztswv(:,:) = 0.e0
+            ztbfu(:,:) = 0.e0   ;   ztbfv(:,:) = 0.e0  
+            DO jj = 2, jpjm1   
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! save the surface forcing momentum fluxes
+                  ztswu(ji,jj) = taux(ji,jj) / ( fse3u(ji,jj,1)*rau0 )
+                  ztswv(ji,jj) = tauy(ji,jj) / ( fse3v(ji,jj,1)*rau0 )
+                  ! save bottom friction momentum fluxes
+                  ikbu   = MIN( mbathy(ji+1,jj  ), mbathy(ji,jj) )
+                  ikbv   = MIN( mbathy(ji  ,jj+1), mbathy(ji,jj) )
+                  ikbum1 = MAX( ikbu-1, 1 )
+                  ikbvm1 = MAX( ikbv-1, 1 )
+                  zua = ua(ji,jj,ikbum1) * r2dt + ub(ji,jj,ikbum1)
+                  zva = va(ji,jj,ikbvm1) * r2dt + vb(ji,jj,ikbvm1)
+                  ztbfu(ji,jj) = - avmu(ji,jj,ikbu) * zua / ( fse3u(ji,jj,ikbum1)*fse3uw(ji,jj,ikbu) )
+                  ztbfv(ji,jj) = - avmv(ji,jj,ikbv) * zva / ( fse3v(ji,jj,ikbvm1)*fse3vw(ji,jj,ikbv) )
+                  !
+                  ptrdx(ji,jj,1     ) = ptrdx(ji,jj,1     ) - ztswu(ji,jj)
+                  ptrdx(ji,jj,ikbum1) = ptrdx(ji,jj,ikbum1) - ztbfu(ji,jj)
+                  ptrdy(ji,jj,1     ) = ptrdy(ji,jj,1     ) - ztswv(ji,jj)
+                  ptrdy(ji,jj,ikbvm1) = ptrdy(ji,jj,ikbvm1) - ztbfv(ji,jj)
+               END DO
+            END DO
+            !
+            CALL trd_vor_zint( ptrdx, ptrdy, jpvor_zdf )   
+            CALL trd_vor_zint( ztswu, ztswv, jpvor_swf )                               ! Wind stress forcing term
+            CALL trd_vor_zint( ztbfu, ztbfv, jpvor_bfr )                               ! Bottom friction term
          END SELECT
-
+         !
       ENDIF
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! III. Mixed layer trends
+      ! 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 purely vertical diffusion (and not iso-neutral),
+         !                   we do not need to store the corresponding trend here, since it
+         !                   is recomputed later (at the basis of the ML, see trd_mld)
+         !                 * else (iso-neutral case) 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 )
-
-         ! horizontal advection trends
-         CASE ( jpttdlad )      
-
-#if defined key_trabbl_adv
-            ! Advective bottom boundary layer 
-            ! -------------------------------
-            zun(:,:,:) = un(:,:,:) - u_bbl(:,:,:)
-            zvn(:,:,:) = vn(:,:,:) - v_bbl(:,:,:)
-#endif
-            IF( kt == nit000 )   zbtr2(:,:) = 1. / ( e1t(:,:) * e2t(:,:) )
-
-            SELECT CASE ( l_adv )
-
-            CASE ( 'ce2' )
-
-               ! Split horizontal trends into i- and j- compnents for trdmld case 
-               ! ----------------------------------------------------------------
-
-               ! i- advective trend computed as Uh gradh(T)
-               DO jk = 1, jpkm1
-                  DO jj = 2, jpjm1
-                     DO ji = fs_2, fs_jpim1   ! vector opt.
-# if defined key_zco
-                        zbtr = zbtr2(ji,jj)
-                        zfui = 0.5 * e2u(ji  ,jj) * zun(ji,  jj,jk)
-                        zfui1= 0.5 * e2u(ji-1,jj) * zun(ji-1,jj,jk)
-# else         
-                        zbtr = zbtr2(ji,jj) / fse3t(ji,jj,jk)
-                        zfui = 0.5 * e2u(ji  ,jj) * fse3u(ji,  jj,jk) * zun(ji,  jj,jk)
-                        zfui1= 0.5 * e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zun(ji-1,jj,jk)
-# endif
-                        ! save i- advective trend 
-                        z3dx(ji,jj,jk) = - zbtr * ( zfui  * ( tn(ji+1,jj,jk) - tn(ji  ,jj,jk) )    &
-                            &                     + zfui1 * ( tn(ji  ,jj,jk) - tn(ji-1,jj,jk) ) )
-                        z3dy(ji,jj,jk) = - zbtr * ( zfui  * ( sn(ji+1,jj,jk) - sn(ji  ,jj,jk) )    &
-                            &                     + zfui1 * ( sn(ji  ,jj,jk) - sn(ji-1,jj,jk) ) )
-                     END DO
-                  END DO
-               END DO
-
-               ! save the i- horizontal trends for diagnostic
-               CALL trd_mld_zint(z3dx, z3dy, jpmldxad, '3D')
-
-               ! j- advective trend computed as Uh gradh(T)
-               DO jk = 1, jpkm1
-                  DO jj = 2, jpjm1
-                     DO ji = fs_2, fs_jpim1   ! vector opt.
-# if defined key_zco
-                        zbtr = zbtr2(ji,jj)
-                        zfvj = 0.5 * e1v(ji,jj  ) * zvn(ji,jj  ,jk)
-                        zfvj1= 0.5 * e1v(ji,jj-1) * zvn(ji,jj-1,jk)
-# else         
-                        zbtr = zbtr2(ji,jj) / fse3t(ji,jj,jk)
-                        zfvj = 0.5 * e1v(ji,jj  ) * fse3v(ji,jj  ,jk) * zvn(ji,jj  ,jk)
-                        zfvj1= 0.5 * e1v(ji,jj-1) * fse3v(ji,jj-1,jk) * zvn(ji,jj-1,jk)
-# endif
-                        ! save j- advective trend 
-                        z3dx(ji,jj,jk) = - zbtr * ( zfvj  * ( tn(ji,jj+1,jk) - tn(ji,jj  ,jk) )   &
-                            &                     + zfvj1 * ( tn(ji,jj  ,jk) - tn(ji,jj-1,jk) ) )
-                        z3dy(ji,jj,jk) = - zbtr * ( zfvj  * ( sn(ji,jj+1,jk) - sn(ji,jj  ,jk) )   &
-                            &                     + zfvj1 * ( sn(ji,jj  ,jk) - sn(ji,jj-1,jk) ) )
-                     END DO
-                  END DO
-               END DO
-
-               ! save the j- horizontal trend for diagnostic
-               CALL trd_mld_zint(z3dx, z3dy, jpmldyad, '3D')
-
-            CASE ( 'tvd' )
-
-               ! Recompute the horizontal advection term Div(Uh.T) term 
-               z3dx(:,:,:) = ptrdx(:,:,:) - tn(:,:,:) * hdivn(:,:,:)
-               z3dy(:,:,:) = ptrdy(:,:,:) - sn(:,:,:) * hdivn(:,:,:)
-
-               ! Deduce the i- horizontal advection in substracting the j- one.
-               ! tladj()/sladj() are computed in traadv_tvd.F90 module
-               z3dx(:,:,:) = z3dx(:,:,:) - tladj(:,:,:)
-               z3dy(:,:,:) = z3dy(:,:,:) - sladj(:,:,:)
-
-               DO jk = 1, jpkm1
-                  DO jj = 2, jpjm1
-                     DO ji = fs_2, fs_jpim1
-                        zbtr = zbtr2(ji,jj) / fse3t(ji,jj,jk)
-
-                        ! Compute the zonal et meridional divergence
-                        zfui = e2u(ji  ,jj) * fse3u(ji  ,jj,jk) * zun(ji  ,jj,jk)  &
-                             - e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zun(ji-1,jj,jk)
-                        zfvj = e1v(ji,jj  ) * fse3v(ji,jj  ,jk) * zvn(ji,jj  ,jk)  &
-                             - e1v(ji,jj-1) * fse3v(ji,jj-1,jk) * zvn(ji,jj-1,jk)
-
-                        ! i- advective trend computed as U gradx(T/S)
-                        z3dx(ji,jj,jk) = z3dx(ji,jj,jk) + tn(ji,jj,jk) * zfui * zbtr
-                        z3dy(ji,jj,jk) = z3dy(ji,jj,jk) + sn(ji,jj,jk) * zfui * zbtr
-
-                        ! j- advective trend computed as V grady(T/S)
-                        tladj(ji,jj,jk) = tladj(ji,jj,jk) + tn(ji,jj,jk) * zfvj * zbtr
-                        sladj(ji,jj,jk) = sladj(ji,jj,jk) + sn(ji,jj,jk) * zfvj * zbtr
-
-                     END DO
-                  END DO
-               END DO
-
-               ! save the i- horizontal trend for diagnostic
-               CALL trd_mld_zint(z3dx, z3dy, jpmldxad, '3D')
-
-               ! save the j- horizontal trend for diagnostic
-               CALL trd_mld_zint(tladj, sladi, jpmldyad, '3D')
-
-            CASE ( 'mus', 'mu2' )
-
-               !  Split horizontal trends in i- and j- direction for trdmld case 
-               ! ----------------------------------------------------------------
-
-               ! i- advective trend computed as U gradx(T/S)
-               DO jk = 1, jpkm1
-                  DO jj = 2, jpjm1      
-                     DO ji = fs_2, fs_jpim1   ! vector opt.
-# if defined key_zco
-                        zbtr = zbtr2(ji,jj)
-                        zfui = e2u(ji  ,jj) * zun(ji,  jj,jk)   &
-                           & - e2u(ji-1,jj) * zun(ji-1,jj,jk)
-# else      
-                        zbtr = zbtr2(ji,jj) / fse3t(ji,jj,jk)
-                        zfui =  e2u(ji  ,jj) * fse3u(ji,  jj,jk) * zun(ji,  jj,jk)   &
-                           & -  e2u(ji-1,jj) * fse3u(ji-1,jj,jk) * zun(ji-1,jj,jk)
-# endif
-                        ! save i- advective trend 
-                        z3dx(ji,jj,jk) = - zbtr * ( tladi(ji,jj,jk) - tladi(ji-1,jj,jk) )   &
-                            &                      + tn(ji,jj,jk) * zfui * zbtr
-                        z3dy(ji,jj,jk) = - zbtr * ( sladi(ji,jj,jk) - sladi(ji-1,jj,jk) )  &
-                            &                      + sn(ji,jj,jk) * zfui * zbtr
-                     END DO
-                  END DO
-               END DO        
-
-               ! save the i- horizontal trends for diagnostic
-               CALL trd_mld_zint(z3dx, z3dy, jpmldxad, '3D')
-
-               ! j- advective trend computed as V grady(T/S)
-               DO jk = 1, jpkm1
-                  DO jj = 2, jpjm1      
-                     DO ji = fs_2, fs_jpim1   ! vector opt.
-# if defined key_zco
-                        zbtr = zbtr2(ji,jj)
-                        zfvj = e1v(ji,jj  ) * zvn(ji,jj  ,jk)   &
-                           & - e1v(ji,jj-1) * zvn(ji,jj-1,jk)
-# else      
-                        zbtr = zbtr2(ji,jj) / fse3t(ji,jj,jk)
-                        zfvj =  e1v(ji,jj  ) * fse3v(ji,jj  ,jk) * zvn(ji,jj  ,jk)   &
-                           & -  e1v(ji,jj-1) * fse3v(ji,jj-1,jk) * zvn(ji,jj-1,jk)
-# endif
-                        ! save j- advective trend 
-                        z3dx(ji,jj,jk) =  - zbtr * ( tladj(ji,jj,jk) - tladj(ji,jj-1,jk) )   &
-                            &                       + tn(ji,jj,jk) * zfvj * zbtr
-                        z3dy(ji,jj,jk) =  - zbtr * ( sladj(ji,jj,jk) - sladj(ji,jj-1,jk) )   &
-                            &                       + sn(ji,jj,jk) * zfvj * zbtr
-                     END DO
-                  END DO
-               END DO        
-
-               ! save the j- horizontal trends for diagnostic
-               CALL trd_mld_zint(z3dx, z3dy, jpmldyad, '3D')
-
-            END SELECT
-
-         ! vertical advection trends
-         CASE ( jpttdzad )      
-            CALL trd_mld_zint(ptrdx, ptrdy, jpmldzad, '3D')
-
-         ! lateral diffusion trends
-         CASE ( jpttdldf )      
-            CALL trd_mld_zint(ptrdx, ptrdy, jpmldldf, '3D')
-# if defined key_traldf_eiv
-            ! Save the i- and j- eddy induce velocity trends
-            CALL trd_mld_zint(tladi, sladi, jpmldxei, '3D')
-            CALL trd_mld_zint(tladj, sladj, jpmldyei, '3D')
-# endif
-            IF( lk_trabbl_dif )   THEN
-               z3dx(:,:,:) = 0.e0
-               z3dy(:,:,:) = 0.e0
-               z3dx(:,:,1) = tldfbbl(:,:)
-               z3dy(:,:,1) = sldfbbl(:,:)
-               CALL trd_mld_zint(z3dx, z3dy, jpmldldf, '2D')
-            ENDIF
-
-         ! vertical diffusion trends
-         CASE ( jpttdzdf )      
-            CALL trd_mld_zint(ptrdx, ptrdy, jpmldzdf, '3D')
-
-         ! vertical diffusion trends
-         CASE ( jpttddoe )      
-            CALL trd_mld_zint(ptrdx, ptrdy, jpmldzei, '3D')
-
-         ! penetrative solar radiation trends
-         CASE ( jpttdqsr )      
-            CALL trd_mld_zint(ptrdx, ptrdy, jpmldfor, '3D')
-
-         ! non penetrative solar radiation trends
-         CASE ( jpttdnsr )
-            ptrdx(:,:,2:jpk) = 0.e0
-            ptrdy(:,:,2:jpk) = 0.e0
-            CALL trd_mld_zint(ptrdx, ptrdy, jpmldfor, '2D')
-
-         END SELECT   
+         CASE ( jptra_trd_xad )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_xad, '3D' )   ! merid. advection
+         CASE ( jptra_trd_yad )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_yad, '3D' )   ! zonal  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 diffusive
+         CASE ( jptra_trd_bbl )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_bbl, '3D' )   ! bottom boundary layer
+         CASE ( jptra_trd_zdf )
+            IF( ln_traldf_iso )       CALL trd_mld_zint( ptrdx, ptrdy, jpmld_ldf, '3D' )   ! vertical diffusion (K_z)
+         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.e0   ;   ptrdy(:,:,2:jpk) = 0.e0
+            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
-
 
    END SUBROUTINE trd_mod
@@ -434,4 +266,38 @@
 #   endif
 
+   SUBROUTINE trd_mod_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mod_init  ***
+      !! 
+      !! ** Purpose :   Initialization of activated trends
+      !!----------------------------------------------------------------------
+      USE in_out_manager          ! I/O manager
+
+      NAMELIST/namtrd/ ntrd, nctls, ln_trdmld_restart, ucf, ln_trdmld_instant
+      !!----------------------------------------------------------------------
+
+      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,*) '           * frequency of trends diagnostics   ntrd               = ', ntrd
+            WRITE(numout,*) '           * control surface type              nctls              = ', nctls
+            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            ucf                = ', ucf
+        ENDIF
+      ENDIF
+      !
+      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: trunk/NEMO/OPA_SRC/TRD/trdmod_oce.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRD/trdmod_oce.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRD/trdmod_oce.F90	(revision 503)
@@ -4,19 +4,64 @@
    !! Ocean trends :   set tracer and momentum trend variables
    !!======================================================================
+   !! History :  9.0  !  04-08  (C. Talandier) Original code
    !!----------------------------------------------------------------------
-   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
-   !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
-   !!----------------------------------------------------------------------
-   !! * Modules used
    USE trdicp_oce              ! ocean momentum/tracers bassin properties trends variables
    USE trdmld_oce              ! ocean active mixed layer tracers trends variables
    USE trdvor_oce              ! ocean vorticity trends variables
 
-   !! Control parameters
+   IMPLICIT NONE
+   PUBLIC
+
+   !!* Namelist namtrd:  diagnostics on dynamics/tracer trends
+   INTEGER , PUBLIC ::    ntrd  = 10                    !: time step frequency dynamics and tracers trends
+   INTEGER , PUBLIC ::    nctls =  0                    !: control surface type for trends vertical integration
+   REAL(wp), PUBLIC ::    ucf   = 1.                    !: unit conversion factor (for netCDF trends outputs)
+                                                        !: =1. (=86400.) for degC/s (degC/day) and psu/s (psu/day)
+   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
+
+   !!* Control parameters
+# 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
+
+   !!* Active tracers trends indexes
+   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_ldf =  4   !: lateral       diffusion
+   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_zdf =  5   !: vertical diffusion (Kz)
+   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_bbc =  6   !: Bottom Boundary Condition (geoth. flux) 
+   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_bbl =  7   !: Bottom Boundary Layer (diffusive/convective)
+   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_npc =  8   !: static instability mixing
+   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_dmp =  9   !: damping
+   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_qsr = 10   !: penetrative solar radiation
+   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_nsr = 11   !: non solar radiation
+   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_atf = 12   !: Asselin correction
+   
+   !!* Momentum trends indexes
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_hpg =  1   !: hydrostatic pressure gradient 
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_keg =  2   !: kinetic energy gradient
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_rvo =  3   !: relative vorticity
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_pvo =  4   !: planetary vorticity
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_ldf =  5   !: lateral diffusion
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_zad =  6   !: vertical advection
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_zdf =  7   !: vertical diffusion
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_spg =  8   !: surface pressure gradient
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_dat =  9   !: damping term
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_swf = 10   !: surface wind forcing
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_bfr = 11   !: bottom friction 
+
    !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC ::   l_trdtra = .FALSE.    !: tracers  trend flag
-   LOGICAL, PUBLIC ::   l_trddyn = .FALSE.    !: momentum trend flag
-
-  !!======================================================================
+   !!  OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Header$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!======================================================================
 END MODULE trdmod_oce
Index: trunk/NEMO/OPA_SRC/TRD/trdvor.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRD/trdvor.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRD/trdvor.F90	(revision 503)
@@ -4,8 +4,11 @@
    !! Ocean diagnostics:  momentum trends
    !!=====================================================================
-   
+   !! History :  9.0  !  04-06  (L. Brunier, A-M. Treguier) Original code 
+   !!                 !  04-08  (C. Talandier) New trends organization
+   !!----------------------------------------------------------------------
 #if defined key_trdvor   ||   defined key_esopa
    !!----------------------------------------------------------------------
    !!   'key_trdvor'   : momentum trend diagnostics
+   !!----------------------------------------------------------------------
    !!----------------------------------------------------------------------
    !!   trd_vor      : momentum trends averaged over the depth
@@ -13,5 +16,4 @@
    !!   trd_vor_init : initialization step
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain variables
@@ -27,22 +29,15 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
 
-
    IMPLICIT NONE
    PRIVATE
 
-   !! * Interfaces
    INTERFACE trd_vor_zint
       MODULE PROCEDURE trd_vor_zint_2d, trd_vor_zint_3d
    END INTERFACE
 
-   !! * Accessibility
-   PUBLIC trd_vor        ! routine called by step.F90
-   PUBLIC trd_vor_zint   ! routine called by dynamics routines
-   PUBLIC trd_vor_init   ! routine called by opa.F90
-
-   !! * Shared module variables
-   LOGICAL, PUBLIC ::   lk_trdvor = .TRUE.   ! momentum trend flag
-
-   !! * Module variables
+   PUBLIC   trd_vor        ! routine called by step.F90
+   PUBLIC   trd_vor_zint   ! routine called by dynamics routines
+   PUBLIC   trd_vor_init   ! routine called by opa.F90
+
    INTEGER ::                &
       nh_t, nmoydpvor  ,     &
@@ -61,7 +56,6 @@
      vor_avrres
 
-   REAL(wp), DIMENSION(jpi,jpj,jplvor)::   &  !: curl of trends
-      vortrd   
-
+   REAL(wp), DIMENSION(jpi,jpj,jpltot_vor)::   vortrd  !: curl of trends
+         
    CHARACTER(len=12) ::   cvort
 
@@ -70,9 +64,8 @@
 #  include "ldfdyn_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
-
    !!----------------------------------------------------------------------
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
   
@@ -80,4 +73,113 @@
 
    SUBROUTINE trd_vor_zint_2d( putrdvor, pvtrdvor, ktrd )
+      !!----------------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_vor_zint  ***
+      !!
+      !! ** Purpose :   computation of vertically integrated vorticity budgets
+      !!      from ocean surface down to control surface (NetCDF output)
+      !!
+      !! ** Method/usage :
+      !!      integration done over nwrite-1 time steps
+      !!
+      !!
+      !! ** Action :
+      !!            /comvor/   :
+      !!                         vor_avr          average
+      !!                         vor_avrb         vorticity at kt-1
+      !!                         vor_avrbb        vorticity at begining of the NWRITE-1
+      !!                                          time steps averaging period
+      !!                         vor_avrbn         vorticity at time step after the
+      !!                                          begining of the NWRITE-1 time
+      !!                                          steps averaging period
+      !!
+      !!                 trends :
+      !!
+      !!                  vortrd (,, 1) = Pressure Gradient Trend
+      !!                  vortrd (,, 2) = KE Gradient Trend
+      !!                  vortrd (,, 3) = Relative Vorticity Trend
+      !!                  vortrd (,, 4) = Coriolis Term Trend
+      !!                  vortrd (,, 5) = Horizontal Diffusion Trend
+      !!                  vortrd (,, 6) = Vertical Advection Trend
+      !!                  vortrd (,, 7) = Vertical Diffusion Trend
+      !!                  vortrd (,, 8) = Surface Pressure Grad. Trend
+      !!                  vortrd (,, 9) = Beta V
+      !!                  vortrd (,,10) = forcing term
+      !!		  vortrd (,,11) = bottom friction term
+      !!                  rotot(,) : total cumulative trends over nwrite-1 time steps
+      !!                  vor_avrtot(,) : first membre of vrticity equation
+      !!                  vor_avrres(,) : residual = dh/dt entrainment
+      !!
+      !!      trends output in netCDF format using ioipsl
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
+         putrdvor,                         &  ! u vorticity trend 
+         pvtrdvor                             ! v vorticity trend
+      !!
+      INTEGER ::   ji, jj
+      INTEGER ::   ikbu, ikbum1, ikbv, ikbvm1
+      REAL(wp), DIMENSION(jpi,jpj) ::   zudpvor, zvdpvor   ! total cmulative trends
+      !!----------------------------------------------------------------------
+
+      ! Initialization
+      zudpvor(:,:) = 0.e0
+      zvdpvor(:,:) = 0.e0
+
+      CALL lbc_lnk( putrdvor,  'U' , -1. )
+      CALL lbc_lnk( pvtrdvor,  'V' , -1. )
+
+      !  =====================================
+      !  I vertical integration of 2D trends
+      !  =====================================
+
+      SELECT CASE (ktrd) 
+
+      CASE (jpvor_bfr)        ! bottom friction
+
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1 
+               ikbu   = min( mbathy(ji+1,jj), mbathy(ji,jj) )
+               ikbum1 = max( ikbu-1, 1 )
+               ikbv   = min( mbathy(ji,jj+1), mbathy(ji,jj) )
+               ikbvm1 = max( ikbv-1, 1 )
+            
+               zudpvor(ji,jj) = putrdvor(ji,jj) * fse3u(ji,jj,ikbum1) * e1u(ji,jj) * umask(ji,jj,ikbum1)
+               zvdpvor(ji,jj) = pvtrdvor(ji,jj) * fse3v(ji,jj,ikbvm1) * e2v(ji,jj) * vmask(ji,jj,ikbvm1)
+            END DO
+         END DO
+
+      CASE (jpvor_swf)        ! wind stress
+
+         zudpvor(:,:) = putrdvor(:,:) * fse3u(:,:,1) * e1u(:,:) * umask(:,:,1)
+         zvdpvor(:,:) = pvtrdvor(:,:) * fse3v(:,:,1) * e2v(:,:) * vmask(:,:,1)
+
+      END SELECT
+
+      ! Average except for Beta.V
+      zudpvor(:,:) = zudpvor(:,:) * hur(:,:)
+      zvdpvor(:,:) = zvdpvor(:,:) * hvr(:,:)
+   
+      ! Curl
+      DO ji=1,jpim1
+         DO jj=1,jpjm1
+            vortrd(ji,jj,ktrd) = ( zvdpvor(ji+1,jj) - zvdpvor(ji,jj)        &
+                 &                - ( zudpvor(ji,jj+1) - zudpvor(ji,jj) ) ) &
+                 &               / ( e1f(ji,jj) * e2f(ji,jj) )
+         END DO
+      END DO
+
+      ! Surface mask
+      vortrd(:,:,ktrd) = vortrd(:,:,ktrd) * fmask(:,:,1)
+
+      IF( idebug /= 0 ) THEN
+         IF(lwp) WRITE(numout,*) ' debuging trd_vor_zint: I done'
+         CALL FLUSH(numout)
+      ENDIF
+      !
+   END SUBROUTINE trd_vor_zint_2d
+
+
+   SUBROUTINE trd_vor_zint_3d( putrdvor, pvtrdvor, ktrd )
       !!----------------------------------------------------------------------------
       !!                  ***  ROUTINE trd_vor_zint  ***
@@ -119,136 +221,11 @@
       !!      trends output in netCDF format using ioipsl
       !!
-      !! History :
-      !!   9.0  !  04-06  (L. Brunier, A-M. Treguier) Original code 
-      !!        !  04-08  (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------
-      !! * Arguments
+      !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
-
-      REAL(wp), DIMENSION(jpi,jpj), INTENT( inout ) ::   &
-         putrdvor,                         &  ! u vorticity trend 
-         pvtrdvor                             ! v vorticity trend
-
-      !! * Local declarations
-      INTEGER ::   ji, jj
-      INTEGER ::   ikbu, ikbum1, ikbv, ikbvm1
-      REAL(wp), DIMENSION(jpi,jpj) ::   &
-         zudpvor,                       &  ! total cmulative trends
-         zvdpvor                           !   "      "        "
-      !!----------------------------------------------------------------------
-
-      ! Initialization
-      zudpvor(:,:) = 0.e0
-      zvdpvor(:,:) = 0.e0
-
-      CALL lbc_lnk( putrdvor,  'U' , -1. )
-      CALL lbc_lnk( pvtrdvor,  'V' , -1. )
-
-      !  =====================================
-      !  I vertical integration of 2D trends
-      !  =====================================
-
-      SELECT CASE (ktrd) 
-
-      CASE (jpvorbfr)        ! bottom friction
-
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1 
-               ikbu   = min( mbathy(ji+1,jj), mbathy(ji,jj) )
-               ikbum1 = max( ikbu-1, 1 )
-               ikbv   = min( mbathy(ji,jj+1), mbathy(ji,jj) )
-               ikbvm1 = max( ikbv-1, 1 )
-            
-               zudpvor(ji,jj) = putrdvor(ji,jj) * fse3u(ji,jj,ikbum1) * e1u(ji,jj) * umask(ji,jj,ikbum1)
-               zvdpvor(ji,jj) = pvtrdvor(ji,jj) * fse3v(ji,jj,ikbvm1) * e2v(ji,jj) * vmask(ji,jj,ikbvm1)
-            END DO
-         END DO
-
-      CASE (jpvorswf)        ! wind stress
-
-         zudpvor(:,:) = putrdvor(:,:) * fse3u(:,:,1) * e1u(:,:) * umask(:,:,1)
-         zvdpvor(:,:) = pvtrdvor(:,:) * fse3v(:,:,1) * e2v(:,:) * vmask(:,:,1)
-
-      END SELECT
-
-      ! Average except for Beta.V
-      zudpvor(:,:) = zudpvor(:,:) * hur(:,:)
-      zvdpvor(:,:) = zvdpvor(:,:) * hvr(:,:)
-   
-      ! Curl
-      DO ji=1,jpim1
-         DO jj=1,jpjm1
-            vortrd(ji,jj,ktrd) = ( zvdpvor(ji+1,jj) - zvdpvor(ji,jj)        &
-                 &                - ( zudpvor(ji,jj+1) - zudpvor(ji,jj) ) ) &
-                 &               / ( e1f(ji,jj) * e2f(ji,jj) )
-         END DO
-      END DO
-
-      ! Surface mask
-      vortrd(:,:,ktrd) = vortrd(:,:,ktrd) * fmask(:,:,1)
-
-      IF( idebug /= 0 ) THEN
-         IF(lwp) WRITE(numout,*) ' debuging trd_vor_zint: I done'
-         CALL FLUSH(numout)
-      ENDIF
-
-   END SUBROUTINE trd_vor_zint_2d
-
-
-
-   SUBROUTINE trd_vor_zint_3d( putrdvor, pvtrdvor, ktrd )
-      !!----------------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_vor_zint  ***
-      !!
-      !! ** Purpose :   computation of vertically integrated vorticity budgets
-      !!      from ocean surface down to control surface (NetCDF output)
-      !!
-      !! ** Method/usage :
-      !!      integration done over nwrite-1 time steps
-      !!
-      !!
-      !! ** Action :
-      !!            /comvor/   :
-      !!                         vor_avr          average
-      !!                         vor_avrb         vorticity at kt-1
-      !!                         vor_avrbb        vorticity at begining of the NWRITE-1
-      !!                                          time steps averaging period
-      !!                         vor_avrbn         vorticity at time step after the
-      !!                                          begining of the NWRITE-1 time
-      !!                                          steps averaging period
-      !!
-      !!                 trends :
-      !!
-      !!                  vortrd (,,1) = Pressure Gradient Trend
-      !!                  vortrd (,,2) = KE Gradient Trend
-      !!                  vortrd (,,3) = Relative Vorticity Trend
-      !!                  vortrd (,,4) = Coriolis Term Trend
-      !!                  vortrd (,,5) = Horizontal Diffusion Trend
-      !!                  vortrd (,,6) = Vertical Advection Trend
-      !!                  vortrd (,,7) = Vertical Diffusion Trend
-      !!                  vortrd (,,8) = Surface Pressure Grad. Trend
-      !!                  vortrd (,,9) = Beta V
-      !!                  vortrd (,,10) = forcing term
-      !!		  vortrd (,,11) = bottom friction term
-      !!                  rotot(,) : total cumulative trends over nwrite-1 time steps
-      !!                  vor_avrtot(,) : first membre of vrticity equation
-      !!                  vor_avrres(,) : residual = dh/dt entrainment
-      !!
-      !!      trends output in netCDF format using ioipsl
-      !!
-      !! History :
-      !!   9.0  !  04-06  (L. Brunier, A-M. Treguier) Original code 
-      !!        !  04-08  (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
-
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::   &
          putrdvor,                         &  ! u vorticity trend 
          pvtrdvor                             ! v vorticity trend
-
-      !! * Local declarations
+      !!
       INTEGER ::   ji, jj, jk
-
       REAL(wp), DIMENSION(jpi,jpj) ::   &
          zubet,                         &  ! u Beta.V case
@@ -279,5 +256,5 @@
       ! Save Beta.V term to avoid average before Curl
       ! Beta.V : intergration, no average
-      IF( ktrd == jpvorbev ) THEN 
+      IF( ktrd == jpvor_bev ) THEN 
          zubet(:,:) = zudpvor(:,:)
          zvbet(:,:) = zvdpvor(:,:)
@@ -302,8 +279,8 @@
       ! Special treatement for the Beta.V term
       ! Compute the Curl of the Beta.V term which is not averaged
-      IF( ktrd == jpvorbev ) THEN
+      IF( ktrd == jpvor_bev ) THEN
          DO ji=1,jpim1
             DO jj=1,jpjm1
-               vortrd(ji,jj,jpvorbev) = (  zvbet(ji+1,jj) - zvbet(ji,jj) -   &
+               vortrd(ji,jj,jpvor_bev) = (  zvbet(ji+1,jj) - zvbet(ji,jj) -   &
                     &                    ( zubet(ji,jj+1) - zubet(ji,jj) ) ) &
                     &                   / ( e1f(ji,jj) * e2f(ji,jj) )
@@ -312,8 +289,8 @@
 
          ! Average on the Curl
-         vortrd(:,:,jpvorbev) = vortrd(:,:,jpvorbev) * hur(:,:)
+         vortrd(:,:,jpvor_bev) = vortrd(:,:,jpvor_bev) * hur(:,:)
 
          ! Surface mask
-         vortrd(:,:,jpvorbev) = vortrd(:,:,jpvorbev) * fmask(:,:,1)
+         vortrd(:,:,jpvor_bev) = vortrd(:,:,jpvor_bev) * fmask(:,:,1)
       ENDIF
    
@@ -322,7 +299,6 @@
          CALL FLUSH(numout)
       ENDIF
-
+      !
    END SUBROUTINE trd_vor_zint_3d
-
 
 
@@ -333,21 +309,10 @@
       !! ** Purpose :  computation of cumulated trends over analysis period
       !!               and make outputs (NetCDF or DIMG format)
-      !!
-      !! ** Method/usage :
-      !!
-      !! History :
-      !!   9.0  !  04-06  (L. Brunier, A-M. Treguier) Original code 
-      !!        !  04-08  (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------
-      !! * Arguments
+      !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
-
-      !! * Local declarations
-      INTEGER :: ji, jj, jk, jl, it
-
-      REAL(wp) :: zmean
-
-      REAL(wp) ,DIMENSION(jpi,jpj) ::   &
-         zun, zvn
+      !!
+      INTEGER  ::   ji, jj, jk, jl, it
+      REAL(wp) ::   zmean
+      REAL(wp), DIMENSION(jpi,jpj) ::   zun, zvn
       !!----------------------------------------------------------------------
 
@@ -424,5 +389,5 @@
       IF( kt >= nit000+2 ) THEN
          nmoydpvor = nmoydpvor + 1
-         DO jl = 1, jplvor
+         DO jl = 1, jpltot_vor
             IF( jl /= 9 ) THEN
                rotot(:,:) = rotot(:,:) + vortrd(:,:,jl)
@@ -490,34 +455,35 @@
          it= kt-nit000+1
          IF( lwp .AND. MOD( kt, ntrd ) == 0 ) THEN
-            WRITE(numout,*) '     trdvor_ncwrite : write NetCDF fields'
+            WRITE(numout,*) ''
+            WRITE(numout,*) 'trd_vor : write trends in the NetCDF file at kt = ', kt
+            WRITE(numout,*) '~~~~~~~  '
          ENDIF
  
-         CALL histwrite( nidvor,"sovortPh",it,vortrd(:,:,1),ndimvor1,ndexvor1)  ! grad Ph
-         CALL histwrite( nidvor,"sovortEk",it,vortrd(:,:,2),ndimvor1,ndexvor1)  ! Energy
-         CALL histwrite( nidvor,"sovozeta",it,vortrd(:,:,3),ndimvor1,ndexvor1)  ! rel vorticity
-         CALL histwrite( nidvor,"sovortif",it,vortrd(:,:,4),ndimvor1,ndexvor1)  ! coriolis
-         CALL histwrite( nidvor,"sovodifl",it,vortrd(:,:,5),ndimvor1,ndexvor1)  ! lat diff
-         CALL histwrite( nidvor,"sovoadvv",it,vortrd(:,:,6),ndimvor1,ndexvor1)  ! vert adv
-         CALL histwrite( nidvor,"sovodifv",it,vortrd(:,:,7),ndimvor1,ndexvor1)  ! vert diff
-         CALL histwrite( nidvor,"sovortPs",it,vortrd(:,:,8),ndimvor1,ndexvor1)  ! grad Ps
-         CALL histwrite( nidvor,"sovortbv",it,vortrd(:,:,9),ndimvor1,ndexvor1)  ! beta.V
-         CALL histwrite( nidvor,"sovowind",it,vortrd(:,:,10),ndimvor1,ndexvor1) ! wind stress
-         CALL histwrite( nidvor,"sovobfri",it,vortrd(:,:,11),ndimvor1,ndexvor1) ! bottom friction
+         CALL histwrite( nidvor,"sovortPh",it,vortrd(:,:,jpvor_prg),ndimvor1,ndexvor1)  ! grad Ph
+         CALL histwrite( nidvor,"sovortEk",it,vortrd(:,:,jpvor_keg),ndimvor1,ndexvor1)  ! Energy
+         CALL histwrite( nidvor,"sovozeta",it,vortrd(:,:,jpvor_rvo),ndimvor1,ndexvor1)  ! rel vorticity
+         CALL histwrite( nidvor,"sovortif",it,vortrd(:,:,jpvor_pvo),ndimvor1,ndexvor1)  ! coriolis
+         CALL histwrite( nidvor,"sovodifl",it,vortrd(:,:,jpvor_ldf),ndimvor1,ndexvor1)  ! lat diff
+         CALL histwrite( nidvor,"sovoadvv",it,vortrd(:,:,jpvor_zad),ndimvor1,ndexvor1)  ! vert adv
+         CALL histwrite( nidvor,"sovodifv",it,vortrd(:,:,jpvor_zdf),ndimvor1,ndexvor1)  ! vert diff
+         CALL histwrite( nidvor,"sovortPs",it,vortrd(:,:,jpvor_spg),ndimvor1,ndexvor1)  ! grad Ps
+         CALL histwrite( nidvor,"sovortbv",it,vortrd(:,:,jpvor_bev),ndimvor1,ndexvor1)  ! beta.V
+         CALL histwrite( nidvor,"sovowind",it,vortrd(:,:,jpvor_swf),ndimvor1,ndexvor1) ! wind stress
+         CALL histwrite( nidvor,"sovobfri",it,vortrd(:,:,jpvor_bfr),ndimvor1,ndexvor1) ! bottom friction
          CALL histwrite( nidvor,"1st_mbre",it,vor_avrtot    ,ndimvor1,ndexvor1) ! First membre
          CALL histwrite( nidvor,"sovorgap",it,vor_avrres    ,ndimvor1,ndexvor1) ! gap between 1st and 2 nd mbre
-
+         !
          IF( idebug /= 0 ) THEN
             WRITE(numout,*) ' debuging trd_vor: III.4 done'
             CALL FLUSH(numout)
          ENDIF
-
-      ENDIF
-
+         !
+      ENDIF
+      !
       IF( MOD( kt - nit000+1, ntrd ) == 0 ) rotot(:,:)=0
-
+      !
       IF( kt == nitend )   CALL histclo( nidvor )
-
+      !
    END SUBROUTINE trd_vor
-
 
 
@@ -528,18 +494,8 @@
       !! ** Purpose :   computation of vertically integrated T and S budgets
       !!      from ocean surface down to control surface (NetCDF output)
-      !!
-      !! ** Method/usage :
-      !!
-      !! History :
-      !!   9.0  !  04-06  (L. Brunier, A-M. Treguier) Original code 
-      !!        !  04-08  (C. Talandier) New trends organization
-      !!----------------------------------------------------------------------
-      !! * Local declarations
-      REAL(wp) :: zjulian, zsto, zout
-
+      !!----------------------------------------------------------------------
+      REAL(wp) ::   zjulian, zsto, zout
       CHARACTER (len=40) ::   clhstnam
       CHARACTER (len=40) ::   clop
-
-      NAMELIST/namtrd/ ntrd,nctls
       !!----------------------------------------------------------------------
 
@@ -553,20 +509,13 @@
       idebug = 0      ! set it to 1 in case of problem to have more Print
 
-      ! namelist namtrd : trend diagnostic
-      REWIND( numnam )
-      READ  ( numnam, namtrd )
-
       IF(lwp) THEN
          WRITE(numout,*) ' '
-         WRITE(numout,*) 'trd_vor_init: vorticity trends'
-         WRITE(numout,*) '~~~~~~~~~~~~~'
+         WRITE(numout,*) ' trd_vor_init: vorticity trends'
+         WRITE(numout,*) ' ~~~~~~~~~~~~'
          WRITE(numout,*) ' '
-         WRITE(numout,*) '          Namelist namtrd : '
-         WRITE(numout,*) '             time step frequency trend       ntrd  = ',ntrd
-         WRITE(numout,*) ' '
-         WRITE(numout,*) '##########################################################################'
-         WRITE(numout,*) ' CAUTION: The interpretation of the vorticity trends is'
-         WRITE(numout,*) ' not obvious, please contact Anne-Marie TREGUIER at: treguier@ifremer.fr '
-         WRITE(numout,*) '##########################################################################'
+         WRITE(numout,*) '               ##########################################################################'
+         WRITE(numout,*) '                CAUTION: The interpretation of the vorticity trends is'
+         WRITE(numout,*) '                not obvious, please contact Anne-Marie TREGUIER at: treguier@ifremer.fr '
+         WRITE(numout,*) '               ##########################################################################'
          WRITE(numout,*) ' '
       ENDIF
@@ -599,13 +548,13 @@
       zout = ntrd*rdt
 
-      IF(lwp) WRITE (numout,*) ' trdvor_ncinit: netCDF initialization'
+      IF(lwp) WRITE(numout,*) '               netCDF initialization'
 
       ! II.2 Compute julian date from starting date of the run
       ! ------------------------
       CALL ymds2ju( nyear, nmonth, nday, 0.e0, zjulian )
-      IF (lwp) WRITE(numout,*)' '  
-      IF (lwp) WRITE(numout,*)' Date 0 used :',nit000         &
-           ,' YEAR ', nyear,' MONTH ', nmonth,' DAY ', nday   &
-           ,'Julian day : ', zjulian
+      IF(lwp) WRITE(numout,*)' '  
+      IF(lwp) WRITE(numout,*)'               Date 0 used :',nit000,    &
+         &                   ' YEAR ', nyear,' MONTH '      , nmonth,   &
+         &                   ' DAY ' , nday, 'Julian day : ', zjulian
 
       ! II.3 Define the T grid trend file (nidvor)
@@ -650,5 +599,5 @@
          CALL FLUSH(numout)
       ENDIF
-
+      !
    END SUBROUTINE trd_vor_init
 
@@ -657,11 +606,7 @@
    !!   Default option :                                       Empty module
    !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC ::   lk_trdvor = .FALSE.   ! momentum trend flag
-
-   !! * Interfaces
    INTERFACE trd_vor_zint
       MODULE PROCEDURE trd_vor_zint_2d, trd_vor_zint_3d
    END INTERFACE
-
 CONTAINS
    SUBROUTINE trd_vor( kt )        ! Empty routine
@@ -669,6 +614,5 @@
    END SUBROUTINE trd_vor
    SUBROUTINE trd_vor_zint_2d( putrdvor, pvtrdvor, ktrd )
-      REAL, DIMENSION(:,:), INTENT( inout ) ::   &
-         putrdvor, pvtrdvor                  ! U and V momentum trends
+      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)
@@ -677,6 +621,5 @@
    END SUBROUTINE trd_vor_zint_2d
    SUBROUTINE trd_vor_zint_3d( putrdvor, pvtrdvor, ktrd )
-      REAL, DIMENSION(:,:,:), INTENT( inout ) ::   &
-         putrdvor, pvtrdvor                  ! U and V momentum trends
+      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)
Index: trunk/NEMO/OPA_SRC/TRD/trdvor_oce.F90
===================================================================
--- trunk/NEMO/OPA_SRC/TRD/trdvor_oce.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/TRD/trdvor_oce.F90	(revision 503)
@@ -4,31 +4,37 @@
    !! Ocean trends :   set vorticity trend variables
    !!======================================================================
+   !! History :  9.0  ! ???
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   USE par_oce      ! ocean parameters
+
+   IMPLICIT NONE
+   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
+   !
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_prg =  1   !: Pressure Gradient Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_keg =  2   !: KE Gradient Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_rvo =  3   !: Relative Vorticity Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_pvo =  4   !: Planetary Vorticity Term Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_ldf =  5   !: Horizontal Diffusion Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_zad =  6   !: Vertical Advection Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_zdf =  7   !: Vertical Diffusion Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_spg =  8   !: Surface Pressure Grad. Trend
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_bev =  9   !: Beta V
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_swf = 10   !: wind stress forcing term
+   INTEGER, PUBLIC, PARAMETER ::   jpvor_bfr = 11   !: bottom friction term
+
    !!----------------------------------------------------------------------
    !!  OPA 9.0 , LOCEAN-IPSL (2005) 
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
-   !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
-   !! * Modules used
-   USE par_oce      ! ocean parameters
-
-   IMPLICIT NONE
-   PUBLIC
-
-   INTEGER,PARAMETER :: jplvor = 11     ! Number of vorticity trend terms
-
-   INTEGER, PARAMETER ::            &  !: vorticity trends index
-      jpvorprg = 1,   &  !: Pressure Gradient Trend
-      jpvorkeg = 2,   &  !: KE Gradient Trend
-      jpvorrvo = 3,   &  !: Relative Vorticity Trend
-      jpvorpvo = 4,   &  !: Planetary Vorticity Term Trend
-      jpvorldf = 5,   &  !: Horizontal Diffusion Trend
-      jpvorzad = 6,   &  !: Vertical Advection Trend
-      jpvorzdf = 7,   &  !: Vertical Diffusion Trend
-      jpvorspg = 8,   &  !: Surface Pressure Grad. Trend
-      jpvorbev = 9,   &  !: Beta V
-      jpvorswf =10,   &  !: wind stress forcing term
-      jpvorbfr =11       !: bottom friction term
-
-  !!======================================================================
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!======================================================================
 END MODULE trdvor_oce
Index: trunk/NEMO/OPA_SRC/ZDF/zdfkpp.F90
===================================================================
--- trunk/NEMO/OPA_SRC/ZDF/zdfkpp.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/ZDF/zdfkpp.F90	(revision 503)
@@ -5,12 +5,17 @@
    !!                 turbulent closure parameterization
    !!=====================================================================
+   !! History :  8.1  ! 00-03 (W.G. Large, J. Chanut) Original code
+   !!            8.1  ! 02-06 (J.M. Molines) for real case CLIPPER  
+   !!            8.2  ! 03-10 (Chanut J.) re-writting
+   !!            9.0  ! 05-01 (C. Ethe) Free form, F90
+   !!----------------------------------------------------------------------
 #if defined key_zdfkpp   ||   defined key_esopa
    !!----------------------------------------------------------------------
    !!   'key_zdfkpp'                                             KPP scheme
    !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !!   zdf_kpp      : update momentum and tracer Kz from a kpp scheme
    !!   zdf_kpp_init : initialization, namelist read, and parameters control
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE oce             ! ocean dynamics and active tracers 
    USE dom_oce         ! ocean space and time domain
@@ -28,18 +33,14 @@
    PRIVATE
 
-   !! * Routine accessibility
-   PUBLIC zdf_kpp   ! routine called by step.F90
-   PUBLIC tra_kpp   ! routine called by step.F90
-
-   !! * Share Module variables
-   LOGICAL, PUBLIC, PARAMETER ::  &
-      lk_zdfkpp = .TRUE.          !: KPP vertical mixing flag
-   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   & 
-      ghats                       ! non-local scalar mixing term (gamma/<ws>o)
+   PUBLIC   zdf_kpp   ! routine called by step.F90
+   PUBLIC   tra_kpp   ! routine called by step.F90
+
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfkpp = .TRUE.    !: KPP vertical mixing flag
+   REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   ghats   !: non-local scalar mixing term (gamma/<ws>o)
    REAL(wp), PUBLIC, DIMENSION(jpi,jpj) ::   & 
-      wt0                   ,  &  ! surface temperature flux for non local flux
-      ws0                   ,  &  ! surface salinity flux for non local flux
-      hkpp                        ! boundary layer depht
-   !! * Module variables
+      wt0                   ,  &  !: surface temperature flux for non local flux
+      ws0                   ,  &  !: surface salinity flux for non local flux
+      hkpp                        !: boundary layer depht
+
    INTEGER ::                  & !!! ** kpp namelist (namkpp) **
       nave  =  1            ,  &  ! = 0/1 flag for horizontal average on avt, avmu, avmv
@@ -148,9 +149,8 @@
    !!   OPA 9.0 , LOCEAN-IPSL   (2005)
    !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
 CONTAINS
-
 
    SUBROUTINE zdf_kpp ( kt )
@@ -184,23 +184,9 @@
       !!                update avt, avmu, avmv (before vertical eddy coef.)
       !!
-      !!   References :       
-      !!         Large W.G., Mc Williams J.C. and Doney S.C.              
+      !! References : Large W.G., Mc Williams J.C. and Doney S.C.              
       !!         Reviews of Geophysics, 32, 4, November 1994
       !!         Comments in the code refer to this paper, particularly 
       !!         the equation number. (LMD94, here after)
-      !!
-      !!   Modifications :
-      !!   --------------
-      !!     original  :  00-03 (LARGE W.G.)
-      !!     additions :  00-04 (CHANUT J.)
-      !!               :  02-06 (MOLINES J.M. for real case CLIPPER)
-      !!               :  03-10 (CHANUT J.)
-      !!
-      !! History :
-      !!   8.1  !  00-03  (J. Chanut)  Original code
-      !!   8.1  !  00-04  (J.M. Molines) for real case CLIPPER  
-      !!   9.0  !  05-01  (C. Ethe) Free form, F90
       !!----------------------------------------------------------------------
-      !! * Modules used
 #if defined  key_zdfddm
       USE oce     , zviscos => ua,      &  ! temp. array for viscosities use ua as workspace
@@ -211,15 +197,9 @@
          &          zdiffut => ta          ! temp. array for diffusivities use sa as workspace
 #endif
-
-
-      !! * arguments
-      INTEGER, INTENT( in  ) ::         &
-         kt                                ! ocean time step
-
-      !! * local declarations
-      INTEGER ::                        &
-         ji, jj, jk                        ! dummy loop indices
-      INTEGER ::                        &  !
-         ikbot, jkmax, jkm1, jkp2          !
+      !!
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+      !!
+      INTEGER ::   ji, jj, jk              ! dummy loop indices
+      INTEGER ::   ikbot, jkmax, jkm1, jkp2   !
 
       REAL(wp), DIMENSION(jpi,jpj) ::   & !!! Surface buoyancy forcing, friction velocity
@@ -1251,11 +1231,9 @@
          IF(ln_ctl) THEN
 #if defined key_zdfddm
-            CALL prt_ctl(tab3d_1=avt  , clinfo1=' kpp  - t: ', tab3d_2=avs , clinfo2=' s: ', &
-               &         ovlap=1, kdim=jpk)
+            CALL prt_ctl(tab3d_1=avt , clinfo1=' kpp  - t: ', tab3d_2=avs , clinfo2=' s: ', ovlap=1, kdim=jpk)
 #else
-            CALL prt_ctl(tab3d_1=avt  , clinfo1=' kpp  - t: ', ovlap=1, kdim=jpk)
-#endif
-            CALL prt_ctl(tab3d_1=avmu  , clinfo1='       u: ', tab3d_2=avmv , clinfo2=' v: ', &
-               &         ovlap=1, kdim=jpk)
+            CALL prt_ctl(tab3d_1=avt , clinfo1=' kpp  - t: ', ovlap=1, kdim=jpk)
+#endif
+            CALL prt_ctl(tab3d_1=avmu, clinfo1='       u: ', tab3d_2=avmv , clinfo2=' v: ', ovlap=1, kdim=jpk)
          ENDIF
 
@@ -1312,10 +1290,9 @@
          ztrds(:,:,:) = sa(:,:,:) - ztrds(:,:,:)
 !!bug gm jpttdzdf ==> jpttkpp
-         CALL trd_mod(ztrdt, ztrds, jpttdzdf, 'TRA', kt)
+         CALL trd_mod(ztrdt, ztrds, jptra_trd_zdf, 'TRA', kt)
       ENDIF
 
-      IF(ln_ctl) THEN         ! print mean trends (used for debugging)
-         CALL prt_ctl(tab3d_1=ta, clinfo1=' kpp  - Ta: ', mask1=tmask, &
-            &         tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra')
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ta, clinfo1=' kpp  - Ta: ', mask1=tmask,   &
+         &                       tab3d_2=sa, clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
       ENDIF
 
@@ -1594,5 +1571,4 @@
       END DO
 #endif
-
    END SUBROUTINE zdf_kpp_init
 
Index: trunk/NEMO/OPA_SRC/opa.F90
===================================================================
--- trunk/NEMO/OPA_SRC/opa.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/opa.F90	(revision 503)
@@ -62,7 +62,5 @@
    USE cpl             ! coupled ocean/atmos.              (cpl_init routine)
    USE ocfzpt          ! ocean freezing point              (oc_fz_pt routine)
-   USE trdicp          ! momentum/tracers trends       (trd_icp_init routine)
-   USE trdvor          ! vorticity trends              (trd_vor_init routine)
-   USE trdmld          ! tracer mixed layer trends     (trd_mld_init routine)
+   USE trdmod          ! momentum/tracers trends       (trd_mod_init routine)
    USE flxfwb          ! freshwater budget correction  (flx_fwb_init routine)
    USE flxmod          ! thermohaline forcing of the ocean (flx_init routine)
@@ -280,15 +278,6 @@
       CALL zdf_init                             ! Vertical ocean physics
 
-      !                                     ! Ocean trends
-      ! Control parameters 
-      IF( lk_trdtra .OR. lk_trdmld )   l_trdtra = .TRUE.
-      IF( lk_trddyn .OR. lk_trdvor )   l_trddyn = .TRUE.
-
-      IF( lk_trddyn .OR. lk_trdtra )   &
-         &            CALL trd_icp_init         ! active tracers and/or momentum
-
-      IF( lk_trdmld ) CALL trd_mld_init         ! mixed layer
-
-      IF( lk_trdvor ) CALL trd_vor_init         ! vorticity
+      CALL trd_mod_init                         ! Mixed-layer/Vorticity/Integral constraints trends
+
 
 #if defined key_passivetrc
Index: trunk/NEMO/OPA_SRC/step.F90
===================================================================
--- trunk/NEMO/OPA_SRC/step.F90	(revision 485)
+++ trunk/NEMO/OPA_SRC/step.F90	(revision 503)
@@ -102,4 +102,6 @@
    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 trdvor          ! vorticity budget                 (trd_vor routine)
    USE diagap          ! hor. mean model-data gap         (dia_gap routine)
@@ -424,4 +426,5 @@
                             CALL rst_write  ( kstp )             ! ocean model: restart file output
          IF( lk_obc     )   CALL obc_rst_wri( kstp )             ! ocean model: open boundary restart file output
+         IF( lk_trdmld  )   CALL trd_mld_rst_write( kstp )       ! ocean model: restart file output for trends diagnostics
                             CALL dia_wri    ( kstp, indic )      ! ocean model: outputs
 
