Index: branches/2012/dev_v3_4_STABLE_2012/NEMOGCM/NEMO/OPATAM_SRC/TRA/trabbl_tam.F90
===================================================================
--- branches/2012/dev_v3_4_STABLE_2012/NEMOGCM/NEMO/OPATAM_SRC/TRA/trabbl_tam.F90	(revision 4590)
+++ branches/2012/dev_v3_4_STABLE_2012/NEMOGCM/NEMO/OPATAM_SRC/TRA/trabbl_tam.F90	(revision 4591)
@@ -56,4 +56,5 @@
    PUBLIC   tra_bbl_adv_adj   !  -          -          -              -
    PUBLIC   bbl_adj           !  routine called by trcbbl.F90 and dtadyn.F90
+   PUBLIC   bbl_adj_tst       !  routine called by tamtst
    PUBLIC   tra_bbl_adj_tst   !  routine called by tamtst
 
@@ -165,5 +166,8 @@
       IF( nn_timing == 1 )  CALL timing_start( 'tra_bbl_tan')
       !
-      IF( l_bbl )  CALL bbl_tan( kt, nit000, 'TRA' )   !* bbl coef. and transport (only if not already done in trcbbl)
+      IF( l_bbl )  THEN 
+         CALL bbl( kt, nit000, 'TRA' )
+         CALL bbl_tan( kt, nit000, 'TRA' )   !* bbl coef. and transport (only if not already done in trcbbl)
+      END IF
 
       IF( nn_bbl_ldf == 1 ) THEN                   !* Diffusive bbl
@@ -247,5 +251,5 @@
                zbtr = r1_e1e2t(ji,jj)  / fse3t(ji,jj,ik)
                pta_tl(ji,jj,ik,jn) = pta_tl(ji,jj,ik,jn)                                                         &
-# if defined control_param
+# if defined key_control_param
                   &               + (   ahu_bbl_tl(ji  ,jj  ) * ( zptb(ji+1,jj  ) - zptb(ji  ,jj  ) )    &
                   &                   - ahu_bbl_tl(ji-1,jj  ) * ( zptb(ji  ,jj  ) - zptb(ji-1,jj  ) )    &
@@ -525,4 +529,7 @@
             zub(ji,jj) = un(ji,jj,mbku(ji,jj))      ! bottom velocity
             zvb(ji,jj) = vn(ji,jj,mbkv(ji,jj))
+
+            zubtl(ji,jj) = un_tl(ji,jj,mbku(ji,jj))      ! bottom velocity
+            zvbtl(ji,jj) = vn_tl(ji,jj,mbkv(ji,jj))
          END DO
       END DO
@@ -699,5 +706,11 @@
       IF( nn_timing == 1 )  CALL timing_start( 'tra_bbl_adj')
       !
-      IF( l_bbl )  CALL bbl_adj( kt, nit000, 'TRA' )   !* bbl coef. and transport (only if not already done in trcbbl)
+      IF( l_bbl )  CALL bbl( kt, nitend, 'TRA' )   !* bbl coef. and transport (only if not already done in trcbbl)
+
+      IF( nn_bbl_adv /= 0 ) THEN                !* Advective bbl
+         !
+         CALL tra_bbl_adv_adj( tsb, tsb_ad, tsa_ad, jpts )
+         !
+      END IF
 
       IF( nn_bbl_ldf == 1 ) THEN                   !* Diffusive bbl
@@ -707,9 +720,5 @@
       END IF
 
-      IF( nn_bbl_adv /= 0 ) THEN                !* Advective bbl
-         !
-         CALL tra_bbl_adv_adj( tsb, tsb_ad, tsa_ad, jpts )
-         !
-      END IF
+      IF( l_bbl )  CALL bbl_adj( kt, nitend, 'TRA' )   !* bbl coef. and transport (only if not already done in trcbbl)
       !
       IF( nn_timing == 1 )  CALL timing_stop( 'tra_bbl_adj')
@@ -757,6 +766,7 @@
       zptbad(:,:) = 0.0_wp
       !
-      DO jn = 1, kjpt                                     ! tracer loop
+      DO jn = kjpt, 1, -1                                 ! tracer loop
          !                                                ! ===========
+#  if defined key_control_param
 #  if defined key_vectopt_loop
          DO jj = 1, 1   ! vector opt. (forced unrolling)
@@ -770,4 +780,5 @@
             END DO
          END DO
+#endif
          !                                                  ! ===========
          !                                             ! Compute the trend
@@ -781,5 +792,5 @@
                ik = mbkt(ji,jj)                            ! bottom T-level index
                zbtr = r1_e1e2t(ji,jj)  / fse3t(ji,jj,ik)
-#  if defined control_param
+#  if defined key_control_param
                ahu_bbl_ad(ji  ,jj  ) = ahu_bbl_ad(ji  ,jj  ) + pta_ad(ji,jj,ik,jn) * ( zptb(ji+1,jj  ) - zptb(ji  ,jj  ) ) * zbtr
                ahu_bbl_ad(ji-1,jj  ) = ahu_bbl_ad(ji-1,jj  ) - pta_ad(ji,jj,ik,jn) * ( zptb(ji  ,jj  ) - zptb(ji-1,jj  ) ) * zbtr
@@ -805,6 +816,6 @@
             DO ji = 1, jpij
 #else
-         DO jj = 1, jpj
-            DO ji = 1, jpi
+         DO jj = jpj, 1, -1
+            DO ji = jpi, 1, -1
 #endif
                ik = mbkt(ji,jj)                        ! bottom T-level index
@@ -909,7 +920,7 @@
                   zu_bblad = zu_bblad + ztraad * ( ptb(iis,jj,ikus,jn) - ptb(iid,jj,ikud,jn) ) * zbtr
                   ptb_ad(iis,jj,ikus,jn) = ptb_ad(iis,jj,ikus,jn) + ztraad * zu_bbl * zbtr
-                  ptb_ad(iid,jj,ikud,jn) = ptb_ad(iid,jj,ikud,jn) + ztraad * zu_bbl * zbtr
-                  !
-                  DO jk = ikus, ikud-1                            ! down-slope upper to down T-point (deep column)
+                  ptb_ad(iid,jj,ikud,jn) = ptb_ad(iid,jj,ikud,jn) - ztraad * zu_bbl * zbtr
+                  !
+                  DO jk = ikud-1, ikus, -1                            ! down-slope upper to down T-point (deep column)
                      zbtr = r1_e1e2t(iid,jj) / fse3t(iid,jj,jk)
                      ztraad = pta_ad(iid,jj,jk,jn)
@@ -1305,4 +1316,9 @@
             ztbad (ji,jj) = 0.0_wp
             zsbad (ji,jj) = 0.0_wp
+
+            un_ad(ji,jj,mbku(ji,jj)) = un_ad(ji,jj,mbku(ji,jj)) + zubad(ji,jj)
+            vn_ad(ji,jj,mbkv(ji,jj)) = vn_ad(ji,jj,mbkv(ji,jj)) + zvbad(ji,jj)
+            zvbad(ji,jj) = 0.0_wp
+            zubad(ji,jj) = 0.0_wp
          END DO
       END DO
@@ -1310,5 +1326,5 @@
       !
       CALL wrk_dealloc( jpi, jpj, zub  , zvb  , ztb  , zsb, zdep, &
-         &                        ztbad, zsbad, ztbad, zsbad      )
+         &                        zubad, zvbad, ztbad, zsbad      )
       !
       IF( nn_timing == 1 )  CALL timing_stop( 'bbl_adj')
@@ -1339,4 +1355,227 @@
       !
    END SUBROUTINE tra_bbl_init_tam
+
+   SUBROUTINE bbl_adj_tst( kumadt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tra_bbl_adj_tst ***
+      !!
+      !! ** Purpose : Test the adjoint routine.
+      !!
+      !! ** Method  : Verify the scalar product
+      !!
+      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
+      !!
+      !!              where  L   = tangent routine
+      !!                     L^T = adjoint routine
+      !!                     W   = diagonal matrix of scale factors
+      !!                     dx  = input perturbation (random field)
+      !!                     dy  = L dx
+      !!
+      !!
+      !! History :
+      !!        ! 08-08 (A. Vidard)
+      !!-----------------------------------------------------------------------
+      !! * Modules used
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & kumadt             ! Output unit
+      !! * Local declarations
+      INTEGER ::  &
+         & ji,    &        ! dummy loop indices
+         & jj,    &
+         & jk,    &
+         & jtst
+      INTEGER ::  &
+         & jsav1, &
+         & jsav2
+      REAL(KIND=wp) :: &
+         & zsp1,         & ! scalar product involving the tangent routine
+         & zsp2            ! scalar product involving the adjoint routine
+      REAL(KIND=wp), POINTER, DIMENSION(:,:,:,:) :: &
+         & ztsb_tlin ,     & ! Tangent input
+         & ztsb_adout,     & ! Adjoint input
+         & zrts            ! 2*3D random field
+      REAL(KIND=wp), POINTER, DIMENSION(:,:,:) :: &
+         & zun_tlin,       &
+         & zvn_tlin,       &
+         & zun_adout,      &
+         & zvn_adout,      &
+         & zr3             ! 3D random field
+      REAL(KIND=wp), POINTER, DIMENSION(:,:) :: &
+         & zahu_tlout,      &
+         & zahv_tlout,      &
+         & zahu_adin ,      &
+         & zahv_adin ,      &
+         & zutr_tlout,      &
+         & zvtr_tlout,      &
+         & zutr_adin,       &
+         & zvtr_adin,       &
+         & zr2
+      CHARACTER(LEN=14) :: &
+         & cl_name
+      ! Allocate memory
+      CALL wrk_alloc( jpi, jpj, jpk, jpts, ztsb_tlin , ztsb_adout, zrts )
+      CALL wrk_alloc( jpi, jpj, jpk, zun_tlin, zvn_tlin, zun_adout, zvn_adout, zr3 )
+      CALL wrk_alloc( jpi, jpj, zahu_tlout, zahv_tlout, zahu_adin, zahv_adin, &
+         &                      zutr_tlout, zvtr_tlout, zutr_adin, zvtr_adin, zr2 )
+
+      CALL grid_random( utr_bbl(:,:), 'U', 0.0_wp, stdu )
+      CALL grid_random( vtr_bbl(:,:), 'V', 0.0_wp, stdv )
+
+      jsav1 = nn_bbl_ldf
+      jsav2 = nn_bbl_adv
+
+      DO jtst = 1, 3
+         !==================================================================
+         ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and
+         !    dy = ( hdivb_tl, hdivn_tl )
+         !==================================================================
+
+         SELECT CASE( jtst)
+         CASE ( 1 )
+            nn_bbl_ldf = 1
+            nn_bbl_adv = 0
+         CASE ( 2 )
+            nn_bbl_ldf = 0
+            nn_bbl_adv = 1
+         CASE ( 3 )
+            nn_bbl_ldf = 0
+            nn_bbl_adv = 2
+         END SELECT
+         !--------------------------------------------------------------------
+         ! Reset the tangent and adjoint variables
+         !--------------------------------------------------------------------
+         ztsb_tlin = 0.0_wp
+         zun_tlin  = 0.0_wp
+         zvn_tlin  = 0.0_wp
+         zahu_adin = 0.0_wp
+         zahv_adin = 0.0_wp
+         zutr_adin = 0.0_wp
+         zvtr_adin = 0.0_wp
+
+         ahu_bbl_tl = 0.0_wp
+         ahv_bbl_tl = 0.0_wp
+         utr_bbl_tl = 0.0_wp
+         vtr_bbl_tl = 0.0_wp
+
+         un_ad  = 0.0_wp
+         vn_ad  = 0.0_wp
+         tsb_ad = 0.0_wp
+
+         !--------------------------------------------------------------------
+         ! Initialize the tangent input with random noise: dx
+         !--------------------------------------------------------------------
+
+         CALL grid_random( zrts(:,:,:,jp_tem), 'T', 0.0_wp, stdt )
+         CALL grid_random( zrts(:,:,:,jp_sal), 'T', 0.0_wp, stds )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  ztsb_tlin(ji,jj,jk,:) = zrts(ji,jj,jk,:)
+               END DO
+            END DO
+         END DO
+
+         CALL grid_random( zr3(:,:,:), 'U', 0.0_wp, stdu )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zun_tlin(ji,jj,jk) = zr3(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         CALL grid_random( zr3(:,:,:), 'V', 0.0_wp, stdv )
+         DO jk = 1, jpk
+            DO jj = nldj, nlej
+               DO ji = nldi, nlei
+                  zvn_tlin(ji,jj,jk) = zr3(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         tsb_tl(:,:,:,:) = ztsb_tlin(:,:,:,:)
+         un_tl(:,:,:)    = zun_tlin(:,:,:)
+         vn_tl(:,:,:)    = zvn_tlin(:,:,:)
+
+         CALL bbl_tan (0, 1, 'TRA')
+
+         zahu_tlout(:,:) = ahu_bbl_tl(:,:)
+         zahv_tlout(:,:) = ahv_bbl_tl(:,:)
+         zutr_tlout(:,:) = utr_bbl_tl(:,:)
+         zvtr_tlout(:,:) = vtr_bbl_tl(:,:)
+         
+         DO jj = nldj, nlej
+            DO ji = nldi, nlei
+               zahu_adin(ji,jj) = zahu_tlout(ji,jj) &
+                  &             * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,1) &
+                  &             * umask(ji,jj,1)
+               zahv_adin(ji,jj) = zahv_tlout(ji,jj) &
+                  &             * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,1) &
+                  &             * vmask(ji,jj,1)
+               zutr_adin(ji,jj) = zutr_tlout(ji,jj) &
+                  &             * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,1) &
+                  &             * umask(ji,jj,1)
+               zvtr_adin(ji,jj) = zvtr_tlout(ji,jj) &
+                  &             * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,1) &
+                  &             * vmask(ji,jj,1)
+            END DO
+         END DO
+         !--------------------------------------------------------------------
+         ! Compute the scalar product: ( L dx )^T W dy
+         !--------------------------------------------------------------------
+
+         zsp1 = DOT_PRODUCT( zahu_tlout, zahu_adin ) &
+            & + DOT_PRODUCT( zutr_tlout, zutr_adin ) &
+            & + DOT_PRODUCT( zahv_tlout, zahv_adin ) &
+            & + DOT_PRODUCT( zvtr_tlout, zvtr_adin )
+
+         !--------------------------------------------------------------------
+         ! Call the adjoint routine: dx^* = L^T dy^*
+         !--------------------------------------------------------------------
+
+         ahu_bbl_ad(:,:) = zahu_adin(:,:)
+         ahv_bbl_ad(:,:) = zahv_adin(:,:)
+         utr_bbl_ad(:,:) = zutr_adin(:,:)
+         vtr_bbl_ad(:,:) = zvtr_adin(:,:)
+
+         CALL bbl_adj (0, 1, 'TRA')
+
+         ztsb_adout = tsb_ad
+         zun_adout  = un_ad
+         zvn_adout  = vn_ad
+
+         zsp2 = DOT_PRODUCT( ztsb_tlin(:,:,:,jp_tem), ztsb_adout(:,:,:,jp_tem) ) &
+            & + DOT_PRODUCT( ztsb_tlin(:,:,:,jp_sal), ztsb_adout(:,:,:,jp_sal) ) &
+            & + DOT_PRODUCT( zun_tlin (:,:,:       ), zun_adout (:,:,:       ) ) &
+            & + DOT_PRODUCT( zvn_tlin (:,:,:       ), zvn_adout (:,:,:       ) ) 
+
+         SELECT CASE ( jtst )
+         CASE ( 1 )
+            ! 14 char:'12345678901234'
+            cl_name = 'bbl_adj_dif   '
+         CASE ( 2 )
+            ! 14 char:'12345678901234'
+            cl_name = 'bbl_adj_adv  1'
+         CASE ( 3 )
+            ! 14 char:'12345678901234'
+            cl_name = 'bbl_adj_adv  2'
+         END SELECT
+         CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
+
+      END DO
+
+      nn_bbl_ldf = jsav1
+      nn_bbl_adv = jsav2
+
+
+      CALL wrk_dealloc( jpi, jpj, jpk, jpts, ztsb_tlin , ztsb_adout, zrts )
+      CALL wrk_dealloc( jpi, jpj, jpk, zun_tlin, zvn_tlin, zun_adout, zvn_adout, zr3 )
+      CALL wrk_dealloc( jpi, jpj, zahu_tlout, zahv_tlout, zahu_adin, zahv_adin, &
+         &                      zutr_tlout, zvtr_tlout, zutr_adin, zvtr_adin, zr2 )
+
+   END SUBROUTINE bbl_adj_tst
 
    SUBROUTINE tra_bbl_adj_tst( kumadt )
@@ -1387,14 +1626,10 @@
          & ztsb_adout,     &
          & zrts            ! 2*3D random field
-      REAL(KIND=wp), POINTER, DIMENSION(:,:) :: &
-         & zutr_tlin ,     &
-         & zutr_tlout,     &
-         & zvtr_tlin ,     &
-         & zvtr_tlout,     &
-         & zutr_adout,     &
-         & zutr_adin ,     &
-         & zvtr_adout,     &
-         & zvtr_adin ,     &
-         & zr2             ! 2D random field
+      REAL(KIND=wp), POINTER, DIMENSION(:,:,:) :: &
+         & zun_tlin,       &
+         & zvn_tlin,       &
+         & zun_adout,      &
+         & zvn_adout,      &
+         & zr3             ! 3D random field
       CHARACTER(LEN=14) :: &
          & cl_name
@@ -1404,7 +1639,5 @@
          &                                  ztsa_adout, ztsa_adin , ztsb_adout, &
          &                                  zrts )
-      CALL wrk_alloc( jpi, jpj, zutr_tlin , zutr_tlout, zvtr_tlin , zvtr_tlout, &
-         &                      zutr_adout, zutr_adin , zvtr_adout, zvtr_adin , &
-         &                      zr2 )
+      CALL wrk_alloc( jpi, jpj, jpk, zun_tlin, zvn_tlin, zun_adout, zvn_adout, zr3 )
 
       CALL grid_random( utr_bbl(:,:), 'U', 0.0_wp, stdu )
@@ -1414,5 +1647,5 @@
       jsav2 = nn_bbl_adv
 
-      DO jtst = 1, 2
+      DO jtst = 1, 3
          !==================================================================
          ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and
@@ -1441,14 +1674,18 @@
          ztsb_adout(:,:,:,:) = 0.0_wp
 
-         zutr_tlin (:,:) = 0.0_wp
-         zutr_tlout(:,:) = 0.0_wp
-         zvtr_tlin (:,:) = 0.0_wp
-         zvtr_tlout(:,:) = 0.0_wp
-         zutr_adout(:,:) = 0.0_wp
-         zutr_adin (:,:) = 0.0_wp
-         zvtr_adout(:,:) = 0.0_wp
-         zvtr_adin (:,:) = 0.0_wp
-
+         zun_tlin (:,:,:) = 0.0_wp
+         zun_adout(:,:,:) = 0.0_wp
+         zvn_tlin (:,:,:) = 0.0_wp
+         zvn_adout(:,:,:) = 0.0_wp
+
+         tsb_tl(:,:,:,:) = 0.0_wp
+         tsa_tl(:,:,:,:) = 0.0_wp
          tsb_ad(:,:,:,:) = 0.0_wp
+         tsa_ad(:,:,:,:) = 0.0_wp
+
+         un_tl(:,:,:) = 0.0_wp
+         vn_tl(:,:,:) = 0.0_wp
+         un_ad(:,:,:) = 0.0_wp
+         vn_ad(:,:,:) = 0.0_wp
          !--------------------------------------------------------------------
          ! Initialize the tangent input with random noise: dx
@@ -1475,26 +1712,29 @@
          END DO
 
-         CALL grid_random( zr2(:,:), 'U', 0.0_wp, stdu )
+         CALL grid_random( zr3(:,:,:), 'U', 0.0_wp, stdu )
+         DO jk = 1, jpk
          DO jj = nldj, nlej
             DO ji = nldi, nlei
-               zutr_tlin(ji,jj) = zr2(ji,jj)
-            END DO
-         END DO
-
-         CALL grid_random( zr2(:,:), 'V', 0.0_wp, stdv )
+                  zun_tlin(ji,jj,jk) = zr3(ji,jj,jk)
+            END DO
+         END DO
+         END DO
+
+         CALL grid_random( zr3(:,:,:), 'V', 0.0_wp, stdv )
+         DO jk = 1, jpk
          DO jj = nldj, nlej
             DO ji = nldi, nlei
-               zvtr_tlin(ji,jj) = zr2(ji,jj)
-            END DO
+                  zvn_tlin(ji,jj,jk) = zr3(ji,jj,jk)
+            END DO
+         END DO
          END DO
 
          tsa_tl(:,:,:,:) = ztsa_tlin(:,:,:,:)
          tsb_tl(:,:,:,:) = ztsb_tlin(:,:,:,:)
-         utr_bbl_tl(:,:) = zutr_tlin(:,:)
-         vtr_bbl_tl(:,:) = zvtr_tlin(:,:)
+         un_tl(:,:,:)    = zun_tlin(:,:,:)
+         vn_tl(:,:,:)    = zvn_tlin(:,:,:)
+
          CALL tra_bbl_tan ( nit000 )
          ztsa_tlout(:,:,:,:) = tsa_tl(:,:,:,:)
-         zutr_tlout(:,:)     = utr_bbl_tl(:,:)
-         zvtr_tlout(:,:)     = vtr_bbl_tl(:,:)
          !--------------------------------------------------------------------
          ! Initialize the adjoint variables: dy^* = W dy
@@ -1513,14 +1753,4 @@
             END DO
          END DO
-         DO jj = nldj, nlej
-            DO ji = nldi, nlei
-               zutr_adin(ji,jj) = zutr_tlout(ji,jj) &
-                  &               * e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,1) &
-                  &               * vmask(ji,jj,jk)
-               zvtr_adin(ji,jj) = zvtr_tlout(ji,jj) &
-                  &               * e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,1) &
-                  &               * vmask(ji,jj,jk)
-            END DO
-         END DO
          !--------------------------------------------------------------------
          ! Compute the scalar product: ( L dx )^T W dy
@@ -1528,6 +1758,5 @@
 
          zsp1 = DOT_PRODUCT( ztsa_tlout(:,:,:,jp_tem), ztsa_adin(:,:,:,jp_tem) ) &
-            & + DOT_PRODUCT( ztsa_tlout(:,:,:,jp_sal), ztsa_adin(:,:,:,jp_sal) ) &
-            & + DOT_PRODUCT( zutr_tlout, zutr_adin ) + DOT_PRODUCT( zvtr_tlout, zvtr_adin )
+            & + DOT_PRODUCT( ztsa_tlout(:,:,:,jp_sal), ztsa_adin(:,:,:,jp_sal) ) 
 
          !--------------------------------------------------------------------
@@ -1536,12 +1765,9 @@
 
          tsa_ad(:,:,:,:) = ztsa_adin(:,:,:,:)
-         utr_bbl_ad(:,:) = zutr_adin(:,:)
-         vtr_bbl_ad(:,:) = zvtr_adin(:,:)
          CALL tra_bbl_adj ( nit000 )
          ztsa_adout(:,:,:,:) = tsa_ad(:,:,:,:)
          ztsb_adout(:,:,:,:) = tsb_ad(:,:,:,:)
-         zutr_adout(:,:)     = utr_bbl_ad(:,:)
-         zvtr_adout(:,:)     = vtr_bbl_ad(:,:)
-
+         zun_adout(:,:,:)    = un_ad (:,:,:)
+         zvn_adout(:,:,:)    = vn_ad (:,:,:)
 
          zsp2 = DOT_PRODUCT( ztsa_tlin(:,:,:,jp_tem), ztsa_adout(:,:,:,jp_tem) ) &
@@ -1549,5 +1775,6 @@
             & + DOT_PRODUCT( ztsb_tlin(:,:,:,jp_tem), ztsb_adout(:,:,:,jp_tem) ) &
             & + DOT_PRODUCT( ztsb_tlin(:,:,:,jp_sal), ztsb_adout(:,:,:,jp_sal) ) &
-            & + DOT_PRODUCT( zutr_tlin, zutr_adout ) + DOT_PRODUCT( zvtr_tlin, zvtr_adout )
+            & + DOT_PRODUCT( zun_tlin (:,:,:       ), zun_adout (:,:,:       ) ) &
+            & + DOT_PRODUCT( zvn_tlin (:,:,:       ), zvn_adout (:,:,:       ) ) 
 
          SELECT CASE ( jtst )
@@ -1569,7 +1796,5 @@
          &                                    ztsa_adout, ztsa_adin , ztsb_adout, &
          &                                    zrts )
-      CALL wrk_dealloc( jpi, jpj, zutr_tlin , zutr_tlout, zvtr_tlin , zvtr_tlout, &
-         &                        zutr_adout, zutr_adin , zvtr_adout, zvtr_adin , &
-         &                        zr2 )
+      CALL wrk_dealloc( jpi, jpj, jpk, zun_tlin, zvn_tlin, zun_adout, zvn_adout, zr3 )
 
       nn_bbl_ldf = jsav1
