Index: trunk/NEMO/OPA_SRC/DYN/dynkeg.F90
===================================================================
--- trunk/NEMO/OPA_SRC/DYN/dynkeg.F90	(revision 258)
+++ 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
 
