Index: /branches/DEV_r2006_merge_TRA_TRC/NEMO/OPA_SRC/TRA/trabbl.F90
===================================================================
--- /branches/DEV_r2006_merge_TRA_TRC/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 2105)
+++ /branches/DEV_r2006_merge_TRA_TRC/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 2106)
@@ -20,5 +20,5 @@
    !!   tra_bbl_adv   : generic routine to compute bbl advective trend
    !!   bbl           : computation of bbl diffu. flux coef. & transport in bottom boundary layer
-   !!   tra_bbl_init  : initialization, namlist read, parameters control
+   !!   tra_bbl_init  : initialization, namelist read, parameters control
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and active tracers
@@ -32,5 +32,4 @@
    USE lbclnk         ! ocean lateral boundary conditions
    USE prtctl         ! Print control
-   USE trc_oce        ! share passive tracers/Ocean variables
 
    IMPLICIT NONE
@@ -49,16 +48,14 @@
 # endif
 
-   LOGICAL, PUBLIC              ::   l_bbl               !: flag to compute bbl diffu. flux coef and transport
-   
    !                                         !!* Namelist nambbl * 
    INTEGER , PUBLIC ::   nn_bbl_ldf = 0       !: =1   : diffusive bbl or not (=0)
    INTEGER , PUBLIC ::   nn_bbl_adv = 0       !: =1/2 : advective bbl or not (=0)
-   !                                          !  =1 : advective bbl using the model velocity
-   !                                          !  =2 :   -        -  using utr_bbl proportional to grad(rho)
+   !                                          !  =1 : advective bbl using the bottom ocean velocity
+   !                                          !  =2 :     -      -  using utr_bbl proportional to grad(rho)
    REAL(wp), PUBLIC ::   rn_ahtbbl  = 1.e+3   !: along slope bbl diffusive coefficient [m2/s]
    REAL(wp), PUBLIC ::   rn_gambbl  = 10.e0   !: lateral coeff. for bottom boundary layer scheme [s]
 
-   REAL(wp), DIMENSION(jpi,jpj), PUBLIC ::   utr_bbl, vtr_bbl   ! u- (v-) transport in the bottom boundary layer
-   
+   REAL(wp), DIMENSION(jpi,jpj), PUBLIC ::   utr_bbl  , vtr_bbl   ! u- (v-) transport in the bottom boundary layer
+
    INTEGER , DIMENSION(jpi,jpj) ::   mbkt                   ! vertical index of the bottom ocean T-level
    INTEGER , DIMENSION(jpi,jpj) ::   mbku     , mbkv        ! vertical index of the (upper) bottom ocean U/V-level
@@ -68,5 +65,6 @@
    REAL(wp), DIMENSION(jpi,jpj) ::   ahu_bbl  , ahv_bbl     ! masked diffusive bbl coefficients at u and v-points
    REAL(wp), DIMENSION(jpi,jpj) ::   e3u_bbl_0, e3v_bbl_0   ! thichness of the bbl (e3) at u and v-points
-   REAL(wp), DIMENSION(jpi,jpj) ::   e1e2t_r                ! thichness of the bbl (e3) at u and v-points
+   REAL(wp), DIMENSION(jpi,jpj) ::   e1e2t_r   ! thichness of the bbl (e3) at u and v-points
+   LOGICAL, PUBLIC              ::   l_bbl                    !: flag to compute bbl diffu. flux coef and transport
 
    !! * Substitutions
@@ -80,4 +78,5 @@
 
 CONTAINS
+
 
    SUBROUTINE tra_bbl( kt )
@@ -89,4 +88,7 @@
       !!     of tracer equations.
       !!
+      !! ** Method  :   Depending on namtra_bbl namelist parameters the bbl
+      !!              diffusive and/or advective contribution to the tracer trend
+      !!              is added to the general tracer trend
       !!----------------------------------------------------------------------  
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step 
@@ -100,9 +102,8 @@
       ENDIF
 
-      !* bbl coef and transport are computed only if not already done in passive tracers routine
-      IF( l_bbl )      CALL bbl( kt, 'TRA' ) 
-
-      !* Diffusive bbl :
-      IF( nn_bbl_ldf == 1 ) THEN
+      IF( l_bbl )   CALL bbl( kt, 'TRA' )       !* bbl coef. and transport (only if not already done trcbbl)
+
+
+      IF( nn_bbl_ldf == 1 ) THEN                !* Diffusive bbl
          CALL tra_bbl_dif( tsb, tsa, jpts )
          IF( ln_ctl )  &
@@ -115,12 +116,11 @@
       END IF
 
-      !* Advective bbl : bbl upstream advective trends added to the tracer trends
-      IF( nn_bbl_adv /= 0 ) THEN
-         CALL tra_bbl_adv( tsb, tsa, jpts )  
+      IF( nn_bbl_adv /= 0 ) THEN                !* Advective bbl
+         CALL tra_bbl_adv( tsb, tsa, jpts )
          IF(ln_ctl)   &
          CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' bbl_adv  - Ta: ', mask1=tmask,   &
          &             tab3d_2=tsa(:,:,:,jp_sal), clinfo2=           ' Sa: ', mask2=tmask, clinfo3='tra' )
          ! lateral boundary conditions ; just need for outputs                          
-         CALL lbc_lnk( utr_bbl, 'U', 1. )     ;   CALL lbc_lnk( vtr_bbl, 'V', 1. )   
+         CALL lbc_lnk( utr_bbl, 'U', 1. )     ;   CALL lbc_lnk( vtr_bbl, 'V', 1. )
          CALL iom_put( "uoce_bbl", utr_bbl )  ! bbl i-transport     
          CALL iom_put( "voce_bbl", vtr_bbl )  ! bbl j-transport
@@ -155,4 +155,6 @@
       !!      convection is satified)
       !!
+      !! ** Action  :   ptraa   increased by the bbl diffusive trend
+      !!
       !! References : Beckmann, A., and R. Doscher, 1997, J. Phys.Oceanogr., 581-591.
       !!              Campin, J.-M., and H. Goosse, 1999, Tellus, 412-430.
@@ -163,7 +165,6 @@
       !!
       INTEGER  ::   ji, jj, jn   ! dummy loop indices
-      INTEGER  ::   ik           ! local integer
-      REAL(wp) ::   zbtr, ztra   ! local scalars 
-      REAL(wp), DIMENSION(jpi,jpj) :: ztrb, zkx, zky   ! 2D workspace
+      INTEGER  ::   ik           ! local integers
+      REAL(wp) ::   zbtr, ztra   ! local scalars
       !!----------------------------------------------------------------------
       !
@@ -171,29 +172,4 @@
       DO jn = 1, kjpt                                     ! tracer loop
          !                                                ! ===========
-#if defined key_vectopt_loop
-         DO jj = 1, 1   ! vector opt. (forced unrolling)
-            DO ji = 1, jpij
-#else
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-#endif
-               ik = mbkt(ji,jj)                        ! bottom T-level index
-               ztrb(ji,jj) = ptrab(ji,jj,ik,jn)              ! bottom before T and S
-            END DO
-         END DO
-         !
-!!gm  forced unrolling should be uuseless in the loop below (no indirect adressing)
-#  if defined key_vectopt_loop
-         DO jj = 1, 1   ! vector opt. (forced unrolling)
-            DO ji = 1, jpij-jpi
-#  else
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-#  endif
-               zkx(ji,jj) = ahu_bbl(ji,jj) * ( ztrb(ji+1,jj  ) - ztrb(ji,jj) )  ! diffusive i-flux
-               zky(ji,jj) = ahv_bbl(ji,jj) * ( ztrb(ji  ,jj+1) - ztrb(ji,jj) )  ! diffusive j-flux
-            END DO
-         END DO
-            !                                        ! Add the diffusive trends
 #  if defined key_vectopt_loop
          DO jj = 1, 1   ! vector opt. (forced unrolling)
@@ -203,13 +179,16 @@
             DO ji = 2, jpim1
 #  endif
-               ik = mbkt(ji,jj)
+               ik = mbkt(ji,jj)                            ! bottom T-level index
                zbtr = e1e2t_r(ji,jj)  / fse3t(ji,jj,ik)
-               ztra = ( zkx(ji,jj) - zkx(ji-1,jj) + zky(ji,jj) - zky(ji,jj-1) ) * zbtr
-               ptraa(ji,jj,ik,jn) = ptraa(ji,jj,ik,jn) + ztra
+               ptraa(ji,jj,ik,jn) = ptraa(ji,jj,ik,jn)                                                         &
+                  &               + (   ahu_bbl(ji,jj) * ( ptrab(ji+1,jj  ,ik,jn) - ptrab(ji  ,jj  ,ik,jn) )   &
+                  &                   - ahu_bbl(ji,jj) * ( ptrab(ji  ,jj  ,ik,jn) - ptrab(ji-1,jj  ,ik,jn) )   &
+                  &                   + ahv_bbl(ji,jj) * ( ptrab(ji  ,jj+1,ik,jn) - ptrab(ji  ,jj  ,ik,jn) )   &
+                  &                   - ahv_bbl(ji,jj) * ( ptrab(ji  ,jj  ,ik,jn) - ptrab(ji  ,jj-1,ik,jn) )   ) * zbtr
             END DO
          END DO
-         !
-      END DO
-      !
+         !                                                  ! ===========
+      END DO                                                ! end tracer
+      !                                                     ! ===========
    END SUBROUTINE tra_bbl_dif
    
@@ -218,15 +197,12 @@
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE trc_bbl  ***
-      !!                   
+      !!
       !! ** Purpose :   Compute the before passive tracer trend associated 
       !!     with the bottom boundary layer and add it to the general trend
       !!     of tracer equations.
-      !!        * advective bbl (nn_bbl_adv=1 or 2) :
-      !!      nn_bbl_adv = 1   use of the ocean velocity as bbl velocity
-      !!      nn_bbl_adv = 2   follow Campin and Goosse (1999) implentation
-      !!        i.e. transport proportional to the along-slope density gradient
-      !!
-      !!      NB: the along slope density gradient is evaluated using the
-      !!      local density (i.e. referenced at a common local depth).
+      !! ** Method  :   advective bbl (nn_bbl_adv = 1 or 2) :
+      !!      nn_bbl_adv = 1   use of the ocean near bottom velocity as bbl velocity
+      !!      nn_bbl_adv = 2   follow Campin and Goosse (1999) implentation i.e. 
+      !!                       transport proportional to the along-slope density gradient                   
       !!
       !!
@@ -303,7 +279,7 @@
             !
          END DO
-            !
-      END DO
-      !
+         !                                                  ! ===========
+      END DO                                                ! end tracer
+      !                                                     ! ===========
    END SUBROUTINE tra_bbl_adv
 
@@ -407,13 +383,6 @@
       IF( nn_bbl_ldf == 1 ) THEN          !   diffusive bbl   !
          !                                !-------------------!
-         !                                        ! bbl diffusive fluxes
-         !                                             ! (criteria for non zero flux: grad(rho).grad(h) < 0 )
-#  if defined key_vectopt_loop
-         DO jj = 1, 1   ! vector opt. (forced unrolling)
-            DO ji = 1, jpij-jpi
-#  else
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-#  endif
+         DO jj = 1, jpjm1                      ! (criteria for non zero flux: grad(rho).grad(h) < 0 )
+            DO ji = 1, jpim1              
                !                                                ! i-direction 
                zt = 0.5 * ( ztb (ji,jj) + ztb (ji+1,jj) )  ! T, S anomalie, and depth
@@ -544,5 +513,7 @@
       REWIND ( numnam )              !* Read Namelist nambbl : bottom boundary layer scheme
       READ   ( numnam, nambbl )
-
+      !
+      l_bbl = .TRUE.                 !* flag to compute bbl coef and transport
+      !
       IF(lwp) THEN                   !* Parameter control and print
          WRITE(numout,*)
@@ -626,6 +597,4 @@
       ENDIF
       !
-      l_bbl = .TRUE.     !: flag to compute bbl coef and transport
-      !
    END SUBROUTINE tra_bbl_init
 
