Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limhdf_2.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limhdf_2.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limhdf_2.F90	(revision 4946)
@@ -86,10 +86,8 @@
       zdiv0(:, 1 ) = 0._wp
       zdiv0(:,jpj) = 0._wp
-      IF( .NOT.lk_vopt_loop ) THEN
-         zflu (jpi,:) = 0._wp   
-         zflv (jpi,:) = 0._wp
-         zdiv0(1,  :) = 0._wp
-         zdiv0(jpi,:) = 0._wp
-      ENDIF
+      zflu (jpi,:) = 0._wp   
+      zflv (jpi,:) = 0._wp
+      zdiv0(1,  :) = 0._wp
+      zdiv0(jpi,:) = 0._wp
 
       zconv = 1._wp           !==  horizontal diffusion using a Crant-Nicholson scheme  ==!
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limistate_2.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limistate_2.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limistate_2.F90	(revision 4946)
@@ -14,5 +14,4 @@
    !!   'key_lim2' :                                  LIM 2.0 sea-ice model
    !!----------------------------------------------------------------------
-   !!----------------------------------------------------------------------
    !!   lim_istate_2      :  Initialisation of diagnostics ice variables
    !!   lim_istate_init_2 :  initialization of ice state and namelist read
@@ -34,6 +33,6 @@
    PUBLIC lim_istate_2      ! routine called by lim_init_2.F90
 
-   !!! **  namelist (namiceini) **
-   LOGICAL  ::   ln_limini   !: Ice initialization state
+   !                        !! **  namelist (namiceini) **
+   LOGICAL  ::   ln_limini   ! Ice initialization state
    REAL(wp) ::   ttest       ! threshold water temperature for initial sea ice
    REAL(wp) ::   hninn       ! initial snow thickness in the north
@@ -51,5 +50,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -71,5 +69,5 @@
       IF( .NOT. ln_limini ) THEN  
          
-         tfu(:,:) = tfreez( tsn(:,:,1,jp_sal) ) * tmask(:,:,1)       ! freezing/melting point of sea water [Celcius]
+         tfu(:,:) = eos_fzp( tsn(:,:,1,jp_sal) ) * tmask(:,:,1)       ! freezing/melting point of sea water [Celcius]
 
          DO jj = 1, jpj
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90	(revision 4946)
@@ -30,5 +30,4 @@
    USE sbc_oce          ! surface boundary condition: ocean
    USE sbccpl
-   USE cpl_oasis3, ONLY : lk_cpl
    USE oce       , ONLY : sshn, sshb, snwice_mass, snwice_mass_b, snwice_fmass 
    USE albedo           ! albedo parameters
@@ -97,9 +96,7 @@
       !!              - emp     : freshwater budget: mass flux 
       !!              - sfx     : freshwater budget: salt flux due to Freezing/Melting
-      !!              - utau    : sea surface i-stress (ocean referential)
-      !!              - vtau    : sea surface j-stress (ocean referential)
       !!              - fr_i    : ice fraction
       !!              - tn_ice  : sea-ice surface temperature
-      !!              - alb_ice : sea-ice alberdo (lk_cpl=T)
+      !!              - alb_ice : sea-ice albedo (lk_cpl=T)
       !!
       !! References : Goosse, H. et al. 1996, Bul. Soc. Roy. Sc. Liege, 65, 87-90.
@@ -183,9 +180,9 @@
 
             !   computation the solar flux at ocean surface
-#if defined key_coupled 
-            zqsr = qsr_tot(ji,jj) + ( fstric(ji,jj) - qsr_ice(ji,jj,1) ) * ( 1.0 - pfrld(ji,jj) )
-#else
-            zqsr = pfrld(ji,jj) * qsr(ji,jj)  + ( 1.  - pfrld(ji,jj) ) * fstric(ji,jj)
-#endif            
+            IF( lk_cpl ) THEN
+               zqsr = qsr_tot(ji,jj) + ( fstric(ji,jj) - qsr_ice(ji,jj,1) ) * ( 1.0 - pfrld(ji,jj) )
+            ELSE
+               zqsr = pfrld(ji,jj) * qsr(ji,jj)  + ( 1.  - pfrld(ji,jj) ) * fstric(ji,jj)
+            ENDIF
             !  computation the non solar heat flux at ocean surface
             zqns    =  - ( 1. - thcm(ji,jj) ) * zqsr                                              &   ! part of the solar energy used in leads
@@ -206,14 +203,14 @@
             !
             ! mass flux at the ocean-atmosphere interface (open ocean fraction = leads area)
-#if defined key_coupled
             !                                                  ! coupled mode: 
-            zemp = + emp_tot(ji,jj)                            &     ! net mass flux over the grid cell (ice+ocean area)
-               &   - emp_ice(ji,jj) * ( 1. - pfrld(ji,jj) )          ! minus the mass flux intercepted by sea-ice
-#else
-            !                                                  ! forced  mode: 
-            zemp = + emp(ji,jj)     *         frld(ji,jj)      &     ! mass flux over open ocean fraction 
-               &   - tprecip(ji,jj) * ( 1. -  frld(ji,jj) )    &     ! liquid precip. over ice reaches directly the ocean
-               &   + sprecip(ji,jj) * ( 1. - pfrld(ji,jj) )          ! snow is intercepted by sea-ice (previous frld)
-#endif            
+            IF( lk_cpl ) THEN
+               zemp = + emp_tot(ji,jj)                            &     ! net mass flux over the grid cell (ice+ocean area)
+                  &   - emp_ice(ji,jj) * ( 1. - pfrld(ji,jj) )          ! minus the mass flux intercepted by sea-ice
+            ELSE
+               !                                                  ! forced  mode: 
+               zemp = + emp(ji,jj)     *         frld(ji,jj)      &     ! mass flux over open ocean fraction 
+                  &   - tprecip(ji,jj) * ( 1. -  frld(ji,jj) )    &     ! liquid precip. over ice reaches directly the ocean
+                  &   + sprecip(ji,jj) * ( 1. - pfrld(ji,jj) )          ! snow is intercepted by sea-ice (previous frld)
+            ENDIF
             !
             ! mass flux at the ocean/ice interface (sea ice fraction)
@@ -259,20 +256,18 @@
       !-----------------------------------------------!
 
-#if defined key_coupled
-      tn_ice(:,:,1) = sist(:,:)          ! sea-ice surface temperature       
-      ht_i(:,:,1) = hicif(:,:)
-      ht_s(:,:,1) = hsnif(:,:)
-      a_i(:,:,1) = fr_i(:,:)
-      !                                  ! Computation of snow/ice and ocean albedo
-      CALL albedo_ice( tn_ice, ht_i, ht_s, zalbp, zalb )
-      alb_ice(:,:,1) =  0.5 * ( zalbp(:,:,1) + zalb (:,:,1) )   ! Ice albedo (mean clear and overcast skys)
-      CALL iom_put( "icealb_cea", alb_ice(:,:,1) * fr_i(:,:) )  ! ice albedo
-#endif
+      IF( lk_cpl) THEN
+         tn_ice(:,:,1) = sist(:,:)          ! sea-ice surface temperature       
+         ht_i(:,:,1) = hicif(:,:)
+         ht_s(:,:,1) = hsnif(:,:)
+         a_i(:,:,1) = fr_i(:,:)
+         !                                  ! Computation of snow/ice and ocean albedo
+         CALL albedo_ice( tn_ice, ht_i, ht_s, zalbp, zalb )
+         alb_ice(:,:,1) =  0.5 * ( zalbp(:,:,1) + zalb (:,:,1) )   ! Ice albedo (mean clear and overcast skys)
+         CALL iom_put( "icealb_cea", alb_ice(:,:,1) * fr_i(:,:) )  ! ice albedo
+      ENDIF
 
       IF(ln_ctl) THEN            ! control print
          CALL prt_ctl(tab2d_1=qsr   , clinfo1=' lim_sbc: qsr    : ', tab2d_2=qns   , clinfo2=' qns     : ')
          CALL prt_ctl(tab2d_1=emp   , clinfo1=' lim_sbc: emp    : ', tab2d_2=sfx   , clinfo2=' sfx     : ')
-         CALL prt_ctl(tab2d_1=utau  , clinfo1=' lim_sbc: utau   : ', mask1=umask,   &
-            &         tab2d_2=vtau  , clinfo2=' vtau    : '        , mask2=vmask )
          CALL prt_ctl(tab2d_1=fr_i  , clinfo1=' lim_sbc: fr_i   : ', tab2d_2=tn_ice(:,:,1), clinfo2=' tn_ice  : ')
       ENDIF 
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90	(revision 4946)
@@ -33,5 +33,4 @@
    USE limtab_2
    USE prtctl           ! Print control
-   USE cpl_oasis3, ONLY :   lk_cpl
    USE diaar5    , ONLY :   lk_diaar5
    USE lib_fortran      ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
@@ -219,15 +218,15 @@
                         
             !  partial computation of the lead energy budget (qldif)
-#if defined key_coupled 
-            qldif(ji,jj)   = tms(ji,jj) * rdt_ice                                                  &
-               &    * (   ( qsr_tot(ji,jj) - qsr_ice(ji,jj,1) * zfricp ) * ( 1.0 - thcm(ji,jj) )   &
-               &        + ( qns_tot(ji,jj) - qns_ice(ji,jj,1) * zfricp )                           &
-               &        + frld(ji,jj) * ( fdtcn(ji,jj) + ( 1.0 - zindb ) * fsbbq(ji,jj) )   )
-#else
-            qldif(ji,jj)   = tms(ji,jj) * rdt_ice * frld(ji,jj)                    &
-               &                        * (  qsr(ji,jj) * ( 1.0 - thcm(ji,jj) )    &
-               &                           + qns(ji,jj)  +  fdtcn(ji,jj)           &
-               &                           + ( 1.0 - zindb ) * fsbbq(ji,jj)      )
-#endif
+            IF( lk_cpl ) THEN 
+               qldif(ji,jj)   = tms(ji,jj) * rdt_ice                                                  &
+                  &    * (   ( qsr_tot(ji,jj) - qsr_ice(ji,jj,1) * zfricp ) * ( 1.0 - thcm(ji,jj) )   &
+                  &        + ( qns_tot(ji,jj) - qns_ice(ji,jj,1) * zfricp )                           &
+                  &        + frld(ji,jj) * ( fdtcn(ji,jj) + ( 1.0 - zindb ) * fsbbq(ji,jj) )   )
+            ELSE
+               qldif(ji,jj)   = tms(ji,jj) * rdt_ice * frld(ji,jj)                    &
+                  &                        * (  qsr(ji,jj) * ( 1.0 - thcm(ji,jj) )    &
+                  &                           + qns(ji,jj)  +  fdtcn(ji,jj)           &
+                  &                           + ( 1.0 - zindb ) * fsbbq(ji,jj)      )
+            ENDIF
             !  parlat : percentage of energy used for lateral ablation (0.0) 
             zfntlat        = 1.0 - MAX( rzero , SIGN( rone ,  - qldif(ji,jj) ) )
@@ -449,4 +448,5 @@
       zztmp = 1.0 / rdt_ice
       CALL iom_put( 'iceprod_cea' , hicifp (:,:) * zztmp     )   ! Ice produced               [m/s]
+      CALL iom_put( 'iiceconc'    , fr_i(:,:)                )   ! Ice concentration          [-]
       IF( lk_diaar5 ) THEN
          CALL iom_put( 'snowmel_cea' , rdm_snw(:,:) * zztmp     )   ! Snow melt                  [kg/m2/s]
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limthd_zdf_2.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limthd_zdf_2.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_2/limthd_zdf_2.F90	(revision 4946)
@@ -18,5 +18,5 @@
    USE ice_2
    USE limistate_2
-   USE cpl_oasis3, ONLY : lk_cpl
+   USE sbc_oce, ONLY : lk_cpl
    USE in_out_manager
    USE lib_mpp          ! MPP library
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limdiahsb.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limdiahsb.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limdiahsb.F90	(revision 4946)
@@ -75,5 +75,5 @@
 
       ! 1/area
-      z1_area = 1.d0 / MAX( glob_sum( area(:,:) * tms(:,:) ), epsi06 )
+      z1_area = 1._wp / MAX( glob_sum( area(:,:) * tms(:,:) ), epsi06 )
 
       zinda = MAX( 0._wp , SIGN( 1._wp , glob_sum( area(:,:) * tms(:,:) ) - epsi06 ) )
@@ -244,7 +244,7 @@
       ! 2 - initial conservation variables !
       ! ---------------------------------- !
-      !frc_vol = 0.d0                                           ! volume       trend due to forcing
-      !frc_sal = 0.d0                                           ! salt content   -    -   -    -         
-      !bg_grme = 0.d0                                           ! ice growth + melt volume trend
+      !frc_vol = 0._wp                                          ! volume       trend due to forcing
+      !frc_sal = 0._wp                                          ! salt content   -    -   -    -         
+      !bg_grme = 0._wp                                          ! ice growth + melt volume trend
       !
       CALL lim_diahsb_rst( nstart, 'READ' )  !* read or initialize all required files
@@ -280,8 +280,8 @@
            IF(lwp) WRITE(numout,*) ' lim_diahsb at initial state '
            IF(lwp) WRITE(numout,*) '~~~~~~~'
-           frc_vol  = 0.d0                                           
-           frc_sal  = 0.d0                                                  
-           bg_grme  = 0.d0                                        
-       ENDIF	
+           frc_vol  = 0._wp                                          
+           frc_sal  = 0._wp                                                 
+           bg_grme  = 0._wp                                       
+       ENDIF
 
      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limhdf.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limhdf.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limhdf.F90	(revision 4946)
@@ -83,10 +83,8 @@
       zdiv0(:, 1 ) = 0._wp
       zdiv0(:,jpj) = 0._wp
-      IF( .NOT.lk_vopt_loop ) THEN
-         zflu (jpi,:) = 0._wp   
-         zflv (jpi,:) = 0._wp
-         zdiv0(1,  :) = 0._wp
-         zdiv0(jpi,:) = 0._wp
-      ENDIF
+      zflu (jpi,:) = 0._wp   
+      zflv (jpi,:) = 0._wp
+      zdiv0(1,  :) = 0._wp
+      zdiv0(jpi,:) = 0._wp
 
       zconv = 1._wp           !==  horizontal diffusion using a Crant-Nicholson scheme  ==!
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 4946)
@@ -6,5 +6,5 @@
    !! History :  2.0  ! 2004-01 (C. Ethe, G. Madec)  Original code
    !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!             -   ! 2012    (C. Rousset) add par_oce (for jp_sal)...bug?
+   !!             -   ! 2014    (C. Rousset) add N/S initializations
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -29,5 +29,4 @@
    USE lib_fortran      ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
    USE wrk_nemo         ! work arrays
-   USE cpl_oasis3, ONLY : lk_cpl
 
    IMPLICIT NONE
@@ -36,5 +35,4 @@
    PUBLIC   lim_istate      ! routine called by lim_init.F90
 
-   !! * Module variables
    !                          !!** init namelist (namiceini) **
    REAL(wp) ::   thres_sst   ! threshold water temperature for initial sea ice
@@ -56,5 +54,4 @@
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -80,5 +77,5 @@
       !!
       !! ** Notes   : o_i, t_su, t_s, t_i, s_i must be filled everywhere, even
-      !!              where there is no ice (clem: I do not know why but it is mandatory) 
+      !!              where there is no ice (clem: I do not know why, is it mandatory?) 
       !!
       !! History :
@@ -116,8 +113,4 @@
       CALL lim_istate_init     !  reading the initials parameters of the ice
 
-# if defined key_coupled
-      albege(:,:)   = 0.8 * tms(:,:)
-# endif
-
       ! surface temperature
       DO jl = 1, jpl ! loop over categories
@@ -125,6 +118,7 @@
          tn_ice(:,:,jl) = rtt * tms(:,:)
       END DO
-      ! Basal temperature is set to the freezing point of seawater in Kelvin
-      t_bo(:,:) = ( tfreez( tsn(:,:,1,jp_sal) ) + rt0 ) * tms(:,:) 
+
+      ! basal temperature (considered at freezing point)
+      t_bo(:,:) = ( eos_fzp( tsn(:,:,1,jp_sal) ) + rt0 ) * tms(:,:) 
 
       IF( ln_limini ) THEN
@@ -133,6 +127,6 @@
       ! 2) Basal temperature, ice mask and hemispheric index
       !--------------------------------------------------------------------
-      ! ice if sst <= t-freez + thres_sst
-      DO jj = 1, jpj                                       
+
+      DO jj = 1, jpj                                       ! ice if sst <= t-freez + ttest
          DO ji = 1, jpi
             IF( ( tsn(ji,jj,1,jp_tem)  - ( t_bo(ji,jj) - rt0 ) ) * tms(ji,jj) >= thres_sst ) THEN 
@@ -146,5 +140,4 @@
 
       ! Hemispheric index
-      ! MV 2011 new initialization
       DO jj = 1, jpj
          DO ji = 1, jpi
@@ -156,5 +149,4 @@
          END DO
       END DO
-      ! END MV 2011 new initialization
 
       !--------------------------------------------------------------------
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90	(revision 4946)
@@ -32,6 +32,5 @@
    USE sbc_oce          ! Surface boundary condition: ocean fields
    USE sbccpl
-   USE cpl_oasis3, ONLY : lk_cpl
-   USE oce       , ONLY : iatte, oatte, sshn, sshb, snwice_mass, snwice_mass_b, snwice_fmass
+   USE oce       , ONLY : fraqsr_1lev, sshn, sshb, snwice_mass, snwice_mass_b, snwice_fmass
    USE albedo           ! albedo parameters
    USE lbclnk           ! ocean lateral boundary condition - MPP exchanges
@@ -98,19 +97,21 @@
       !!              - fr_i    : ice fraction
       !!              - tn_ice  : sea-ice surface temperature
-      !!              - alb_ice : sea-ice alberdo (lk_cpl=T)
+      !!              - alb_ice : sea-ice albedo (lk_cpl=T)
       !!
       !! References : Goosse, H. et al. 1996, Bul. Soc. Roy. Sc. Liege, 65, 87-90.
       !!              Tartinville et al. 2001 Ocean Modelling, 3, 95-108.
+      !!              These refs are now obsolete since everything has been revised
+      !!              The ref should be Rousset et al., 2015?
       !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt    ! number of iteration
-      !
-      INTEGER  ::   ji, jj, jl, jk           ! dummy loop indices
-      REAL(wp) ::   zinda, zemp      ! local scalars
-      REAL(wp) ::   zf_mass         ! Heat flux associated with mass exchange ice->ocean (W.m-2)
-      REAL(wp) ::   zfcm1           ! New solar flux received by the ocean
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zalb, zalbp     ! 2D/3D workspace
+      INTEGER, INTENT(in) ::   kt                                   ! number of iteration
+      !
+      INTEGER  ::   ji, jj, jl, jk                                  ! dummy loop indices
+      !
+      REAL(wp) ::   zinda, zemp                                     !  local scalars
+      REAL(wp) ::   zf_mass                                         ! Heat flux associated with mass exchange ice->ocean (W.m-2)
+      REAL(wp) ::   zfcm1                                           ! New solar flux received by the ocean
+      !
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zalb_cs, zalb_os     ! 2D/3D workspace
       !!---------------------------------------------------------------------
-      
-      IF( lk_cpl )   CALL wrk_alloc( jpi, jpj, jpl, zalb, zalbp )
 
       ! make calls for heat fluxes before it is modified
@@ -134,14 +135,12 @@
             ! Solar heat flux reaching the ocean = zfcm1 (W.m-2) 
             !---------------------------------------------------
-            IF( lk_cpl ) THEN ! be carfeful: not been tested yet
-               ! original line
+            IF( lk_cpl ) THEN 
+               !!! LIM2 version zqsr = qsr_tot(ji,jj) + ( fstric(ji,jj) - qsr_ice(ji,jj,1) ) * ( 1.0 - pfrld(ji,jj) )
                zfcm1 = qsr_tot(ji,jj)
-               !!!zfcm1 = qsr_tot(ji,jj) + ftr_ice(ji,jj) * ( 1._wp - pfrld(ji,jj) ) / ( 1._wp - zinda + zinda * iatte(ji,jj) )
                DO jl = 1, jpl
-                  zfcm1 = zfcm1 - ( qsr_ice(ji,jj,jl) - ftr_ice(ji,jj,jl) ) * a_i_b(ji,jj,jl)
+                  zfcm1 = zfcm1 + ( ftr_ice(ji,jj,jl) - qsr_ice(ji,jj,jl) ) * a_i_b(ji,jj,jl)
                END DO
             ELSE
-               !!!zfcm1   = pfrld(ji,jj) * qsr(ji,jj)  + &
-               !!!     &    ( 1._wp - pfrld(ji,jj) ) * ftr_ice(ji,jj) / ( 1._wp - zinda + zinda * iatte(ji,jj) )
+               !!! LIM2 version zqsr = pfrld(ji,jj) * qsr(ji,jj)  + ( 1.  - pfrld(ji,jj) ) * fstric(ji,jj)
                zfcm1   = pfrld(ji,jj) * qsr(ji,jj)
                DO jl = 1, jpl
@@ -217,9 +216,16 @@
 
       !------------------------------------------------!
-      !    Computation of snow/ice and ocean albedo    !
+      !    Snow/ice albedo (only if sent to coupler)   !
       !------------------------------------------------!
       IF( lk_cpl ) THEN          ! coupled case
-         CALL albedo_ice( t_su, ht_i, ht_s, zalbp, zalb )                  ! snow/ice albedo
-         alb_ice(:,:,:) =  0.5_wp * zalbp(:,:,:) + 0.5_wp * zalb (:,:,:)   ! Ice albedo (mean clear and overcast skys)
+
+            CALL wrk_alloc( jpi, jpj, jpl, zalb_cs, zalb_os )
+
+            CALL albedo_ice( t_su, ht_i, ht_s, zalb_cs, zalb_os )  ! cloud-sky and overcast-sky ice albedos
+
+            alb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
+
+            CALL wrk_dealloc( jpi, jpj, jpl, zalb_cs, zalb_os )
+
       ENDIF
 
@@ -231,7 +237,5 @@
          CALL prt_ctl( tab3d_1=tn_ice, clinfo1=' lim_sbc: tn_ice : ', kdim=jpl )
       ENDIF
-      !
-      IF( lk_cpl )   CALL wrk_dealloc( jpi, jpj, jpl, zalb, zalbp )
-      ! 
+
    END SUBROUTINE lim_sbc_flx
 
@@ -346,6 +350,5 @@
       ! clem modif
       IF( .NOT. ln_rstart ) THEN
-         iatte(:,:) = 1._wp
-         oatte(:,:) = 1._wp
+         fraqsr_1lev(:,:) = 1._wp
       ENDIF
       !
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90	(revision 4946)
@@ -22,5 +22,5 @@
    USE phycst         ! physical constants
    USE dom_oce        ! ocean space and time domain variables
-   USE oce     , ONLY :  iatte, oatte
+   USE oce     , ONLY : fraqsr_1lev 
    USE ice            ! LIM: sea-ice variables
    USE par_ice        ! LIM: sea-ice parameters
@@ -43,5 +43,4 @@
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
    USE timing         ! Timing
-   USE cpl_oasis3, ONLY : lk_cpl
    USE limcons        ! conservation tests
 
@@ -68,5 +67,5 @@
       !!                ***  ROUTINE lim_thd  ***       
       !!  
-      !! ** Purpose : This routine manages the ice thermodynamic.
+      !! ** Purpose : This routine manages ice thermodynamics
       !!         
       !! ** Action : - Initialisation of some variables
@@ -74,11 +73,12 @@
       !!               at the ice base, snow acc.,heat budget of the leads)
       !!             - selection of the icy points and put them in an array
-      !!             - call lim_vert_ther for vert ice thermodynamic
-      !!             - back to the geographic grid
-      !!             - selection of points for lateral accretion
-      !!             - call lim_lat_acc  for the ice accretion
+      !!             - call lim_thd_dif  for vertical heat diffusion
+      !!             - call lim_thd_dh   for vertical ice growth and melt
+      !!             - call lim_thd_ent  for enthalpy remapping
+      !!             - call lim_thd_sal  for ice desalination
+      !!             - call lim_thd_temp to  retrieve temperature from ice enthalpy
       !!             - back to the geographic grid
       !!     
-      !! ** References : H. Goosse et al. 1996, Bul. Soc. Roy. Sc. Liege, 65, 87-90
+      !! ** References : 
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt    ! number of iteration
@@ -93,5 +93,9 @@
       !
       REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
+      !
+      REAL(wp), POINTER, DIMENSION(:,:) ::  zqsr, zqns
       !!-------------------------------------------------------------------
+      CALL wrk_alloc( jpi, jpj, zqsr, zqns )
+
       IF( nn_timing == 1 )  CALL timing_start('limthd')
 
@@ -137,4 +141,24 @@
       !-----------------------------------------------------------------------------!
 
+      !--- Ocean solar and non solar fluxes to be used in zqld
+      IF ( .NOT. lk_cpl ) THEN   ! --- forced case, fluxes to the lead are the same as over the ocean
+         !
+         zqsr(:,:) = qsr(:,:)      ; zqns(:,:) = qns(:,:)
+         !
+      ELSE                       ! --- coupled case, fluxes to the lead are total - intercepted
+         !
+         zqsr(:,:) = qsr_tot(:,:)  ; zqns(:,:) = qns_tot(:,:)
+         !
+         DO jl = 1, jpl
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zqsr(ji,jj) = zqsr(ji,jj) - qsr_ice(ji,jj,jl) * a_i_b(ji,jj,jl)
+                  zqns(ji,jj) = zqns(ji,jj) - qns_ice(ji,jj,jl) * a_i_b(ji,jj,jl)
+               END DO
+            END DO
+         END DO
+         !
+      ENDIF
+
 !CDIR NOVERRCHK
       DO jj = 1, jpj
@@ -149,13 +173,21 @@
             !           !  temperature and turbulent mixing (McPhee, 1992)
             !
+
             ! --- Energy received in the lead, zqld is defined everywhere (J.m-2) --- !
-            zqld =  tms(ji,jj) * rdt_ice *                                       &
-               &  ( pfrld(ji,jj)         * ( qsr(ji,jj) * oatte(ji,jj)           &   ! solar heat + clem modif
-               &                           + qns(ji,jj) )                        &   ! non solar heat
-               ! latent heat of precip (note that precip is included in qns but not in qns_ice)
-               &    + ( pfrld(ji,jj)**betas - pfrld(ji,jj) ) * sprecip(ji,jj)         &
-               &    * ( cpic * ( MIN( tatm_ice(ji,jj), rt0_snow ) - rtt ) - lfus )    &
-               &    + ( 1._wp - pfrld(ji,jj) ) * ( tprecip(ji,jj) - sprecip(ji,jj) )  &
-               &    * rcp * ( tatm_ice(ji,jj) - rtt ) )
+            ! REMARK valid at least in forced mode from clem
+            ! precip is included in qns but not in qns_ice
+            IF ( lk_cpl ) THEN
+               zqld =  tms(ji,jj) * rdt_ice *  &
+                  &    (   zqsr(ji,jj) * fraqsr_1lev(ji,jj) + zqns(ji,jj)               &   ! pfrld already included in coupled mode
+                  &    + ( pfrld(ji,jj)**betas - pfrld(ji,jj) ) * sprecip(ji,jj)  *     &   ! heat content of precip
+                  &      ( cpic * ( MIN( tatm_ice(ji,jj), rt0_snow ) - rtt ) - lfus )   &
+                  &    + ( 1._wp - pfrld(ji,jj) ) * ( tprecip(ji,jj) - sprecip(ji,jj) ) * rcp * ( tatm_ice(ji,jj) - rtt ) )
+            ELSE
+               zqld =  tms(ji,jj) * rdt_ice *  &
+                  &      ( pfrld(ji,jj) * ( zqsr(ji,jj) * fraqsr_1lev(ji,jj) + zqns(ji,jj) )    &
+                  &    + ( pfrld(ji,jj)**betas - pfrld(ji,jj) ) * sprecip(ji,jj)  *             &  ! heat content of precip
+                  &      ( cpic * ( MIN( tatm_ice(ji,jj), rt0_snow ) - rtt ) - lfus )           &
+                  &    + ( 1._wp - pfrld(ji,jj) ) * ( tprecip(ji,jj) - sprecip(ji,jj) ) * rcp * ( tatm_ice(ji,jj) - rtt ) )
+            ENDIF
 
             !-- Energy needed to bring ocean surface layer until its freezing (<0, J.m-2) --- !
@@ -187,5 +219,5 @@
             hfx_in(ji,jj) = hfx_in(ji,jj)                                                                                         & 
                ! heat flux above the ocean
-               &    +             pfrld(ji,jj)   * ( qns(ji,jj) + qsr(ji,jj) )                                                    &
+               &    +             pfrld(ji,jj)   * ( zqns(ji,jj) + zqsr(ji,jj) )                                                  &
                ! latent heat of precip (note that precip is included in qns but not in qns_ice)
                &    +   ( 1._wp - pfrld(ji,jj) ) * sprecip(ji,jj) * ( cpic * ( MIN( tatm_ice(ji,jj), rt0_snow ) - rtt ) - lfus )  &
@@ -198,15 +230,15 @@
             !     Second step in limthd_dh      :  heat remaining if total melt (zq_rema) 
             !     Third  step in limsbc         :  heat from ice-ocean mass exchange (zf_mass) + solar
-            hfx_out(ji,jj) = hfx_out(ji,jj)                                                                                   & 
+            hfx_out(ji,jj) = hfx_out(ji,jj)                                                                                       & 
                ! Non solar heat flux received by the ocean
-               &    +        pfrld(ji,jj) * qns(ji,jj)                                                                        &
+               &    +        pfrld(ji,jj) * qns(ji,jj)                                                                            &
                ! latent heat of precip (note that precip is included in qns but not in qns_ice)
-               &    +      ( pfrld(ji,jj)**betas - pfrld(ji,jj) ) * sprecip(ji,jj)                                            &
-               &    * ( cpic * ( MIN( tatm_ice(ji,jj), rt0_snow ) - rtt ) - lfus )                                            &
-               &    +      ( 1._wp - pfrld(ji,jj) ) * ( tprecip(ji,jj) - sprecip(ji,jj) ) * rcp * ( tatm_ice(ji,jj) - rtt )   &
+               &    +      ( pfrld(ji,jj)**betas - pfrld(ji,jj) ) * sprecip(ji,jj)       &
+               &         * ( cpic * ( MIN( tatm_ice(ji,jj), rt0_snow ) - rtt ) - lfus )  &
+               &    +      ( 1._wp - pfrld(ji,jj) ) * ( tprecip(ji,jj) - sprecip(ji,jj) ) * rcp * ( tatm_ice(ji,jj) - rtt )       &
                ! heat flux taken from the ocean where there is open water ice formation
-               &    -      qlead(ji,jj) * r1_rdtice                                                                           &
+               &    -      qlead(ji,jj) * r1_rdtice                                                                               &
                ! heat flux taken from the ocean during bottom growth/melt (fhld should be 0 while bott growth)
-               &    -      at_i(ji,jj) * fhtur(ji,jj)                                                                         &
+               &    -      at_i(ji,jj) * fhtur(ji,jj)                                                                             &
                &    -      at_i(ji,jj) *  fhld(ji,jj)
 
@@ -309,7 +341,4 @@
             CALL tab_2d_1d( nbpb, sfx_bri_1d (1:nbpb), sfx_bri         , jpi, jpj, npb(1:nbpb) )
             CALL tab_2d_1d( nbpb, sfx_res_1d (1:nbpb), sfx_res         , jpi, jpj, npb(1:nbpb) )
-
-            CALL tab_2d_1d( nbpb, iatte_1d   (1:nbpb), iatte           , jpi, jpj, npb(1:nbpb) ) 
-            CALL tab_2d_1d( nbpb, oatte_1d   (1:nbpb), oatte           , jpi, jpj, npb(1:nbpb) ) 
 
             CALL tab_2d_1d( nbpb, hfx_thd_1d (1:nbpb), hfx_thd         , jpi, jpj, npb(1:nbpb) )
@@ -485,8 +514,13 @@
       ENDIF
       !
+      !
+      CALL wrk_dealloc( jpi, jpj, zqsr, zqns )
+
+      !
       ! conservation test
       IF( ln_limdiahsb ) CALL lim_cons_hsm(1, 'limthd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
       !
       IF( nn_timing == 1 )  CALL timing_stop('limthd')
+
    END SUBROUTINE lim_thd 
 
@@ -555,4 +589,6 @@
 902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicethd in configuration namelist', lwp )
       IF(lwm) WRITE ( numoni, namicethd )
+
+      IF( lk_cpl .AND. parsub /= 0.0 )   CALL ctl_stop( 'In coupled mode, use parsub = 0. or send dqla' )
       !
       IF(lwp) THEN                          ! control print
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90	(revision 4946)
@@ -26,5 +26,4 @@
    USE wrk_nemo       ! work arrays
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE cpl_oasis3, ONLY : lk_cpl
    
    IMPLICIT NONE
@@ -169,6 +168,6 @@
          ztmelts       = zinda * rtt + ( 1._wp - zinda ) * rtt
 
-         zfdum     = qns_ice_1d(ji) + ( 1._wp - i0(ji) ) * qsr_ice_1d(ji) - fc_su(ji) 
-         zf_tt(ji) = fc_bo_i(ji) + fhtur_1d(ji) + fhld_1d(ji) 
+         zfdum      = qns_ice_1d(ji) + ( 1._wp - i0(ji) ) * qsr_ice_1d(ji) - fc_su(ji) 
+         zf_tt(ji)  = fc_bo_i(ji) + fhtur_1d(ji) + fhld_1d(ji) 
 
          zq_su (ji) = MAX( 0._wp, zfdum     * rdt_ice ) * MAX( 0._wp , SIGN( 1._wp, t_su_1d(ji) - ztmelts ) )
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90	(revision 4946)
@@ -25,5 +25,5 @@
    USE wrk_nemo       ! work arrays
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE cpl_oasis3, ONLY : lk_cpl
+   USE sbc_oce, ONLY : lk_cpl
 
    IMPLICIT NONE
@@ -146,6 +146,5 @@
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrid     ! tridiagonal system terms
       ! diag errors on heat
-      REAL(wp), POINTER, DIMENSION(:) :: zdq, zq_ini
-      REAL(wp)                        :: zhfx_err
+      REAL(wp), POINTER, DIMENSION(:) :: zdq, zq_ini, zhfx_err
       !!------------------------------------------------------------------     
       ! 
@@ -158,5 +157,5 @@
       CALL wrk_alloc( jpij, nlay_i+3, 3, ztrid )
 
-      CALL wrk_alloc( jpij, zdq, zq_ini )
+      CALL wrk_alloc( jpij, zdq, zq_ini, zhfx_err )
 
       ! --- diag error on heat diffusion - PART 1 --- !
@@ -272,5 +271,4 @@
 
       DO ji = kideb, kiut           ! Radiation transmitted below the ice
-         !!!ftr_ice_1d(ji) = ftr_ice_1d(ji) + iatte_1d(ji) * zradtr_i(ji,nlay_i) * a_i_1d(ji) / at_i_1d(ji) ! clem modif
          ftr_ice_1d(ji) = zradtr_i(ji,nlay_i) 
       END DO
@@ -408,11 +406,16 @@
          !------------------------------------------------------------------------------|
          !
-         DO ji = kideb , kiut
-            ! update of the non solar flux according to the update in T_su
-            qns_ice_1d(ji) = qns_ice_1d(ji) + dqns_ice_1d(ji) * ( t_su_1d(ji) - ztsubit(ji) )
-
+         IF( .NOT. lk_cpl ) THEN   !--- forced atmosphere case
+            DO ji = kideb , kiut
+               ! update of the non solar flux according to the update in T_su
+               qns_ice_1d(ji) = qns_ice_1d(ji) + dqns_ice_1d(ji) * ( t_su_1d(ji) - ztsubit(ji) )
+            END DO
+         ENDIF
+
+         ! Update incoming flux
+         DO ji = kideb , kiut
             ! update incoming flux
             zf(ji)    =   zfsw(ji)              & ! net absorbed solar radiation
-               + qns_ice_1d(ji)                  ! non solar total flux 
+               + qns_ice_1d(ji)                   ! non solar total flux 
             ! (LWup, LWdw, SH, LH)
          END DO
@@ -740,14 +743,30 @@
       CALL lim_thd_enmelt( kideb, kiut )
 
-      ! --- diag error on heat diffusion - PART 2 --- !
+      ! --- diag conservation imbalance on heat diffusion - PART 2 --- !
       DO ji = kideb, kiut
          zdq(ji)        = - zq_ini(ji) + ( SUM( q_i_1d(ji,1:nlay_i) ) * ht_i_1d(ji) / REAL( nlay_i ) +  &
             &                              SUM( q_s_1d(ji,1:nlay_s) ) * ht_s_1d(ji) / REAL( nlay_s ) )
-         zhfx_err    = ( fc_su(ji) + i0(ji) * qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) + zdq(ji) * r1_rdtice ) 
-         hfx_err_1d(ji) = hfx_err_1d(ji) + zhfx_err * a_i_1d(ji)
-         ! --- correction of qns_ice and surface conduction flux --- !
-         qns_ice_1d(ji) = qns_ice_1d(ji) - zhfx_err 
-         fc_su     (ji) = fc_su     (ji) - zhfx_err 
-         ! --- Heat flux at the ice surface in W.m-2 --- !
+         zhfx_err(ji)   = ( fc_su(ji) + i0(ji) * qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) + zdq(ji) * r1_rdtice ) 
+         hfx_err_1d(ji) = hfx_err_1d(ji) + zhfx_err(ji) * a_i_1d(ji)
+      END DO 
+
+      ! diagnose external surface (forced case) or bottom (forced case) from heat conservation
+      IF( .NOT. lk_cpl ) THEN   ! --- forced case: qns_ice and fc_su are diagnosed
+         !
+         DO ji = kideb, kiut
+            qns_ice_1d(ji) = qns_ice_1d(ji) - zhfx_err(ji)
+            fc_su     (ji) = fc_su(ji)      - zhfx_err(ji)
+         END DO
+         !
+      ELSE                      ! --- coupled case: ocean turbulent heat flux is diagnosed
+         !
+         DO ji = kideb, kiut
+            fhtur_1d  (ji) = fhtur_1d(ji)   - zhfx_err(ji)
+         END DO
+         !
+      ENDIF
+
+      ! --- compute diagnostic net heat flux at the surface of the snow-ice system (W.m2)
+      DO ji = kideb, kiut
          ii = MOD( npb(ji) - 1, jpi ) + 1 ; ij = ( npb(ji) - 1 ) / jpi + 1
          hfx_in (ii,ij) = hfx_in (ii,ij) + a_i_1d(ji) * ( qsr_ice_1d(ji) + qns_ice_1d(ji) )
@@ -763,5 +782,5 @@
       CALL wrk_dealloc( jpij, nlay_i+3, zindterm, zindtbis, zdiagbis )
       CALL wrk_dealloc( jpij, nlay_i+3, 3, ztrid )
-      CALL wrk_dealloc( jpij, zdq, zq_ini )
+      CALL wrk_dealloc( jpij, zdq, zq_ini, zhfx_err )
 
    END SUBROUTINE lim_thd_dif
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90	(revision 4946)
@@ -112,5 +112,5 @@
       REAL(wp), POINTER, DIMENSION(:,:) ::   zsmv_i_1d ! 1-D version of smv_i
 
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ze_i_1d !: 1-D version of e_i
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ze_i_1d   !: 1-D version of e_i
 
       REAL(wp), POINTER, DIMENSION(:,:) ::   zvrel                   ! relative ice / frazil velocity
@@ -133,5 +133,6 @@
                   !Energy of melting q(S,T) [J.m-3]
                   zindb = 1._wp - MAX(  0._wp , SIGN( 1._wp , -v_i(ji,jj,jl) + epsi10 )  )   !0 if no ice and 1 if yes
-                  e_i(ji,jj,jk,jl) = zindb * e_i(ji,jj,jk,jl) / ( area(ji,jj) * MAX( v_i(ji,jj,jl) ,  epsi10 ) ) * REAL( nlay_i, wp )
+                  e_i(ji,jj,jk,jl) = zindb * e_i(ji,jj,jk,jl) &
+                      &   / ( area(ji,jj) * MAX( v_i(ji,jj,jl) ,  epsi10 ) ) * REAL( nlay_i, wp )
                   e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * unit_fac
                END DO
@@ -478,5 +479,4 @@
                qh_i_old(ji,nlay_i+1) = ze_newice(ji) * zv_newfra
             ENDDO
-
             ! --- Ice enthalpy remapping --- !
             CALL lim_thd_ent( 1, nbpac, ze_i_1d(1:nbpac,:,jl) ) 
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/thd_ice.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/thd_ice.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/LIM_SRC_3/thd_ice.F90	(revision 4946)
@@ -114,7 +114,4 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   s_i_new       !: Salinity of new ice at the bottom
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   iatte_1d   !: attenuation coef of the input solar flux (unitless)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   oatte_1d   !: attenuation coef of the input solar flux (unitless)
-
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_s_1d   !: corresponding to the 2D var  t_s
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_i_1d   !: corresponding to the 2D var  t_i
@@ -148,6 +145,6 @@
          &      qsr_ice_1d (jpij) ,     &
          &      fr1_i0_1d(jpij) , fr2_i0_1d(jpij) , qns_ice_1d(jpij) ,     &
-         &      t_bo_1d   (jpij) , iatte_1d  (jpij) , oatte_1d (jpij) ,     &
-         &      hfx_sum_1d(jpij) , hfx_bom_1d(jpij) ,hfx_bog_1d(jpij),     &
+         &      t_bo_1d   (jpij) ,                                          &
+         &      hfx_sum_1d(jpij) , hfx_bom_1d(jpij) ,hfx_bog_1d(jpij) ,     & 
          &      hfx_dif_1d(jpij) ,hfx_opw_1d(jpij) , &
          &      hfx_thd_1d(jpij) , hfx_spr_1d(jpij) , &
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90	(revision 4946)
@@ -535,6 +535,6 @@
       !!---------------------------------------------------------------------
 #if defined key_ldfslp && ! defined key_c1d
-      CALL eos( pts, rhd, rhop, gdept_0(:,:,:) )   ! Time-filtered in situ density 
-      CALL bn2( pts, rn2 )         ! before Brunt-Vaisala frequency
+      CALL eos_rab( pts, rab_n )       ! now local thermal/haline expension ratio at T-points
+      CALL bn2    ( pts, rab_n, rn2  ) ! now    Brunt-Vaisala
       IF( ln_zps )   & ! Partial steps: before Horizontal DErivative
         &    CALL zps_hde( kt, jpts, pts, gtsu, gtsv,  &        ! Partial steps: before horizontal gradient
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OOO_SRC/nemogcm.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OOO_SRC/nemogcm.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OOO_SRC/nemogcm.F90	(revision 4946)
@@ -54,9 +54,5 @@
    USE icbini          ! handle bergs, initialisation
    USE icbstp          ! handle bergs, calving, themodynamics and transport
-#if defined key_oasis3
    USE cpl_oasis3      ! OASIS3 coupling
-#elif defined key_oasis4
-   USE cpl_oasis4      ! OASIS4 coupling (not working)
-#endif
    USE lib_mpp         ! distributed memory computing
 #if defined key_iomput
@@ -166,22 +162,23 @@
 #if defined key_iomput
       IF( Agrif_Root() ) THEN
-# if defined key_oasis3 || defined key_oasis4
-         CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
-         CALL xios_initialize( "oceanx",local_comm=ilocal_comm )
-# else
-         CALL  xios_initialize( "nemo",return_comm=ilocal_comm )
-# endif
+         IF( lk_cpl ) THEN
+            CALL cpl_init( ilocal_comm )                               ! nemo local communicator given by oasis
+            CALL xios_initialize( "oceanx",local_comm=ilocal_comm )    ! send nemo communicator to xios
+         ELSE
+            CALL  xios_initialize( "nemo",return_comm=ilocal_comm )    ! nemo local communicator given by xios
+         ENDIF
+      ENDIF
       ENDIF
       narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection
 #else
-# if defined key_oasis3 || defined key_oasis4
-      IF( Agrif_Root() ) THEN
-         CALL cpl_prism_init( ilocal_comm )                 ! nemo local communicator given by oasis
-      ENDIF
-      narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection (control print return in cltxt)
-# else
-      ilocal_comm = 0
-      narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop )                ! Nodes selection (control print return in cltxt)
-# endif
+      IF( lk_cpl ) THEN
+         IF( Agrif_Root() ) THEN
+            CALL cpl_init( ilocal_comm )                               ! nemo local communicator given by oasis
+         ENDIF
+         narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection (control print return in cltxt)
+      ELSE
+         ilocal_comm = 0
+         narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop )                ! Nodes selection (control print return in cltxt)
+      ENDIF
 #endif
       narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 4946)
@@ -109,8 +109,7 @@
       !! ** Action  : 
       !!----------------------------------------------------------------------
-      INTEGER :: ji, jj, jk
-      INTEGER :: jt
-      INTEGER :: imid
-      INTEGER :: inum
+      INTEGER :: ji, jj, jk, jt  ! dummy loop indices
+      INTEGER :: imid, inum      ! local integers
+      INTEGER :: ios             ! Local integer output status for namelist read
       INTEGER :: iiauper         ! Number of time steps in the IAU period
       INTEGER :: icycper         ! Number of time steps in the cycle
@@ -120,15 +119,13 @@
       INTEGER :: iitiaustr_date  ! Date YYYYMMDD of IAU interval start time step
       INTEGER :: iitiaufin_date  ! Date YYYYMMDD of IAU interval final time step
-      INTEGER :: ios             ! Local integer output status for namelist read
-
+      !
       REAL(wp) :: znorm        ! Normalization factor for IAU weights
-      REAL(wp) :: ztotwgt      ! Value of time-integrated IAU weights 
-                               ! (should be equal to one)
+      REAL(wp) :: ztotwgt      ! Value of time-integrated IAU weights (should be equal to one)
       REAL(wp) :: z_inc_dateb  ! Start date of interval on which increment is valid
       REAL(wp) :: z_inc_datef  ! End date of interval on which increment is valid
       REAL(wp) :: zdate_bkg    ! Date in background state file for DI
       REAL(wp) :: zdate_inc    ! Time axis in increments file
-
-      REAL(wp), POINTER, DIMENSION(:,:) :: hdiv
+      !
+      REAL(wp), POINTER, DIMENSION(:,:) ::   hdiv   ! 2D workspace
       !!
       NAMELIST/nam_asminc/ ln_bkgwri,                                      &
@@ -136,6 +133,5 @@
          &                 ln_asmdin, ln_asmiau,                           &
          &                 nitbkg, nitdin, nitiaustr, nitiaufin, niaufn,   &
-         &                 ln_salfix, salfixmin,                &
-         &                 nn_divdmp
+         &                 ln_salfix, salfixmin, nn_divdmp
       !!----------------------------------------------------------------------
 
@@ -143,5 +139,4 @@
       ! Read Namelist nam_asminc : assimilation increment interface
       !-----------------------------------------------------------------------
-
       ln_seaiceinc = .FALSE.
       ln_temnofreeze = .FALSE.
@@ -186,19 +181,10 @@
       icycper = nitend      - nit000      + 1  ! Cycle interval length
 
-      ! Date of final time step
-      CALL calc_date( nit000, nitend, ndate0, iitend_date )
-
-      ! Background time for Jb referenced to ndate0
-      CALL calc_date( nit000, nitbkg_r, ndate0, iitbkg_date )
-
-      ! Background time for DI referenced to ndate0
-      CALL calc_date( nit000, nitdin_r, ndate0, iitdin_date )
-
-      ! IAU start time referenced to ndate0
-      CALL calc_date( nit000, nitiaustr_r, ndate0, iitiaustr_date )
-
-      ! IAU end time referenced to ndate0
-      CALL calc_date( nit000, nitiaufin_r, ndate0, iitiaufin_date )
-
+      CALL calc_date( nit000, nitend     , ndate0, iitend_date    )     ! Date of final time step
+      CALL calc_date( nit000, nitbkg_r   , ndate0, iitbkg_date    )     ! Background time for Jb referenced to ndate0
+      CALL calc_date( nit000, nitdin_r   , ndate0, iitdin_date    )     ! Background time for DI referenced to ndate0
+      CALL calc_date( nit000, nitiaustr_r, ndate0, iitiaustr_date )     ! IAU start time referenced to ndate0
+      CALL calc_date( nit000, nitiaufin_r, ndate0, iitiaufin_date )     ! IAU end time referenced to ndate0
+      !
       IF(lwp) THEN
          WRITE(numout,*)
@@ -671,7 +657,7 @@
       ! used to prevent the applied increments taking the temperature below the local freezing point 
 
-      DO jk=1, jpkm1
-         fzptnz (:,:,jk) = tfreez( tsn(:,:,jk,jp_sal), fsdept(:,:,jk) )
-      ENDDO
+      DO jk = 1, jpkm1
+         fzptnz(:,:,jk) = eos_fzp( tsn(:,:,jk,jp_sal), fsdept(:,:,jk) )
+      END DO
 
       IF ( ln_asmiau ) THEN
@@ -688,6 +674,5 @@
             IF(lwp) THEN
                WRITE(numout,*) 
-               WRITE(numout,*) 'tra_asm_inc : Tracer IAU at time step = ', &
-                  &  kt,' with IAU weight = ', wgtiau(it)
+               WRITE(numout,*) 'tra_asm_inc : Tracer IAU at time step = ', kt,' with IAU weight = ', wgtiau(it)
                WRITE(numout,*) '~~~~~~~~~~~~'
             ENDIF
@@ -737,6 +722,5 @@
             IF (ln_temnofreeze) THEN
                ! Do not apply negative increments if the temperature will fall below freezing
-               WHERE(t_bkginc(:,:,:) > 0.0_wp .OR. &
-                  &   tsn(:,:,:,jp_tem) + t_bkginc(:,:,:) > fzptnz(:,:,:) ) 
+               WHERE( t_bkginc(:,:,:) > 0.0_wp .OR. tsn(:,:,:,jp_tem) + t_bkginc(:,:,:) > fzptnz(:,:,:) ) 
                   tsn(:,:,:,jp_tem) = t_bkg(:,:,:) + t_bkginc(:,:,:)   
                END WHERE
@@ -747,6 +731,5 @@
                ! Do not apply negative increments if the salinity will fall below a specified
                ! minimum value salfixmin
-               WHERE(s_bkginc(:,:,:) > 0.0_wp .OR. &
-                  &   tsn(:,:,:,jp_sal) + s_bkginc(:,:,:) > salfixmin ) 
+               WHERE( s_bkginc(:,:,:) > 0.0_wp .OR. tsn(:,:,:,jp_sal) + s_bkginc(:,:,:) > salfixmin ) 
                   tsn(:,:,:,jp_sal) = s_bkg(:,:,:) + s_bkginc(:,:,:)   
                END WHERE
@@ -758,5 +741,9 @@
 
             CALL eos( tsb, rhd, rhop, gdept_0(:,:,:) )  ! Before potential and in situ densities
-         
+!!gm  fabien
+!            CALL eos( tsb, rhd, rhop )                ! Before potential and in situ densities
+!!gm
+
+
             IF( ln_zps .AND. .NOT. lk_c1d ) &
                &  CALL zps_hde( nit000, jpts, tsb, gtsu, gtsv,  &        ! Partial steps: before horizontal gradient
@@ -766,4 +753,5 @@
 #if defined key_zdfkpp
             CALL eos( tsn, rhd, fsdept_n(:,:,:) )                      ! Compute rhd
+!!gm fabien            CALL eos( tsn, rhd )                      ! Compute rhd
 #endif
 
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/C1D/dyndmp.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/C1D/dyndmp.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/C1D/dyndmp.F90	(revision 4946)
@@ -15,6 +15,4 @@
    USE dom_oce        ! ocean: domain variables
    USE c1d            ! 1D vertical configuration
-   USE trdmod         ! ocean: trends
-   USE trdmod_oce     ! ocean: trends variables
    USE tradmp         ! ocean: internal damping
    USE zdf_oce        ! ocean: vertical physics
@@ -164,5 +162,4 @@
       !! ** Action  : - (ua,va)   momentum trends updated with the damping trend
       !!----------------------------------------------------------------------
-      !
       INTEGER, INTENT(in) ::   kt                        ! ocean time-step index
       !!
@@ -236,6 +233,6 @@
       END SELECT
       !
-      !                           ! Trend diagnostic
-      IF( l_trddyn )   CALL trd_mod( utrdmp, vtrdmp, jpdyn_trd_dat, 'DYN', kt )
+!!gm      !                           ! Trend diagnostic
+!!gm      IF( l_trddyn )   CALL trd_mod( utrdmp, vtrdmp, jpdyn_trd_dat, 'DYN', kt )
       !
       !                           ! Control print
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90	(revision 4946)
@@ -72,6 +72,6 @@
       ! Ocean physics update                (ua, va, ta, sa used as workspace)
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL bn2( tsb, rn2b )        ! before Brunt-Vaisala frequency
-                         CALL bn2( tsn, rn2  )        ! now    Brunt-Vaisala frequency
+                         CALL bn2( tsb, rab_b, rn2b ) ! before Brunt-Vaisala frequency
+                         CALL bn2( tsn, rab_n, rn2  ) ! now    Brunt-Vaisala frequency
       !  VERTICAL PHYSICS   
                          CALL zdf_bfr( kstp )         ! bottom friction
@@ -115,5 +115,5 @@
       ! Passive Tracer Model
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL trc_stp( kstp )            ! time-stepping
+                        CALL trc_stp( kstp )       ! time-stepping
 #endif
 
@@ -121,32 +121,32 @@
       ! Active tracers                              (ua, va used as workspace)
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                             tsa(:,:,:,:) = 0.e0                ! set tracer trends to zero
+                        tsa(:,:,:,:) = 0._wp       ! set tracer trends to zero
 
-                             CALL tra_sbc    ( kstp )        ! surface boundary condition
-      IF( ln_traqsr      )   CALL tra_qsr    ( kstp )        ! penetrative solar radiation qsr
-      IF( ln_tradmp      )   CALL tra_dmp    ( kstp )        ! internal damping trends- tracers
-      IF( lk_zdfkpp      )   CALL tra_kpp    ( kstp )        ! KPP non-local tracer fluxes
-                             CALL tra_zdf    ( kstp )        ! vertical mixing
-                             CALL tra_nxt    ( kstp )        ! tracer fields at next time step
-      IF( ln_zdfnpc      )   CALL tra_npc    ( kstp )        ! applied non penetrative convective adjustment on (t,s)
-                             CALL eos( tsb, rhd, rhop, gdept_0(:,:,:) )      ! now (swap=before) in situ density for dynhpg module
+                        CALL tra_sbc( kstp )       ! surface boundary condition
+      IF( ln_traqsr )   CALL tra_qsr( kstp )       ! penetrative solar radiation qsr
+      IF( ln_tradmp )   CALL tra_dmp( kstp )       ! internal damping trends- tracers
+      IF( lk_zdfkpp )   CALL tra_kpp( kstp )       ! KPP non-local tracer fluxes
+                        CALL tra_zdf( kstp )       ! vertical mixing
+                        CALL eos( tsn, rhd, rhop, gdept_0(:,:,:) )   ! now potential density for zdfmxl
+      IF( ln_zdfnpc )   CALL tra_npc( kstp )       ! applied non penetrative convective adjustment on (t,s)
+                        CALL tra_nxt( kstp )       ! tracer fields at next time step
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! Dynamics                                    (ta, sa used as workspace)
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                               ua(:,:,:) = 0.e0               ! set dynamics trends to zero
-                               va(:,:,:) = 0.e0
+                        ua(:,:,:) = 0._wp          ! set dynamics trends to zero
+                        va(:,:,:) = 0._wp
 
-      IF( ln_dyndmp      )     CALL dyn_dmp    ( kstp )       ! internal damping trends- momentum
-                               CALL dyn_cor_c1d( kstp )       ! vorticity term including Coriolis
-                               CALL dyn_zdf    ( kstp )       ! vertical diffusion
-                               CALL dyn_nxt_c1d( kstp )       ! lateral velocity at next time step
+      IF( ln_dyndmp )   CALL dyn_dmp    ( kstp )   ! internal damping trends- momentum
+                        CALL dyn_cor_c1d( kstp )   ! vorticity term including Coriolis
+                        CALL dyn_zdf    ( kstp )   ! vertical diffusion
+                        CALL dyn_nxt_c1d( kstp )   ! lateral velocity at next time step
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! Control and restarts
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                                 CALL stp_ctl( kstp, indic )
-      IF( kstp == nit000     )   CALL iom_close( numror )             ! close input  ocean restart file
-      IF( lrst_oce           )   CALL rst_write  ( kstp )             ! write output ocean restart file
+                             CALL stp_ctl( kstp, indic )
+      IF( kstp == nit000 )   CALL iom_close( numror )      ! close input  ocean restart file
+      IF( lrst_oce       )   CALL rst_write( kstp )        ! write output ocean restart file
       !
    END SUBROUTINE stp_c1d
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DIA/diafwb.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DIA/diafwb.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DIA/diafwb.F90	(revision 4946)
@@ -7,7 +7,5 @@
    !!            8.5  !  02-06  (G. Madec)  F90: Free form and module
    !!            9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
-   !!----------------------------------------------------------------------
-#if ! defined key_coupled
- 
+   !!---------------------------------------------------------------------- 
    !!----------------------------------------------------------------------
    !!   Only for ORCA2 ORCA1 and ORCA025
@@ -29,6 +27,4 @@
 
    PUBLIC dia_fwb    ! routine called by step.F90
-
-   LOGICAL, PUBLIC, PARAMETER ::   lk_diafwb = .TRUE.    !: fresh water budget flag
 
    REAL(wp)               ::   a_fwf ,          &
@@ -453,15 +449,4 @@
    END SUBROUTINE dia_fwb
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                       Dummy Module
-   !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER ::   lk_diafwb = .FALSE.    !: fresh water budget flag
-CONTAINS
-   SUBROUTINE dia_fwb( kt )        ! Empty routine
-      WRITE(*,*) 'dia_fwb: : You should not have seen this print! error?', kt
-   END SUBROUTINE dia_fwb
-#endif
-
    !!======================================================================
 END MODULE diafwb
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DIA/diahsb.F90	(revision 4946)
@@ -96,6 +96,7 @@
       ! Add geothermal ice shelf
       IF( nn_isf .GE. 1 )  THEN
-                        z_frc_trd_t = z_frc_trd_t +                      glob_sum( ( risf_tsc(:,:,jp_tem) - rdivisf * fwfisf(:,:) * -1.9 * r1_rau0 ) * surf(:,:) )
-                        z_frc_trd_s = z_frc_trd_s + (1.0_wp - rdivisf) * glob_sum( risf_tsc(:,:,jp_sal) * surf(:,:) )
+          z_frc_trd_t = z_frc_trd_t &
+              &   + glob_sum( ( risf_tsc(:,:,jp_tem) - rdivisf * fwfisf(:,:) * (-1.9) * r1_rau0 ) * surf(:,:) )
+          z_frc_trd_s = z_frc_trd_s + (1.0_wp - rdivisf) * glob_sum( risf_tsc(:,:,jp_sal) * surf(:,:) )
       ENDIF
 
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 4946)
@@ -573,6 +573,6 @@
       !!-------------------------------------------------------------------- 
       !
-      CALL wrk_alloc( jpj      , zphi , zfoo )
-      CALL wrk_alloc( jpj , jpk, z_1 )
+      CALL wrk_alloc( jpj       , zphi , zfoo )
+      CALL wrk_alloc( jpj , jpk , z_1  )
 
       ! define time axis
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 4946)
@@ -88,7 +88,5 @@
       INTEGER, DIMENSION(2) :: ierr
       !!----------------------------------------------------------------------
-      !
       ierr = 0
-      !
       ALLOCATE( ndex_hT(jpi*jpj) , ndex_T(jpi*jpj*jpk) ,     &
          &      ndex_hU(jpi*jpj) , ndex_U(jpi*jpj*jpk) ,     &
@@ -193,5 +191,4 @@
          CALL iom_put( "sss2" , z2d(:,:) * z2d(:,:) ) ! square of sea surface salinity
       END IF
-      ! multiply by umask to prevent not numerical value error in the ioserver sometimes
       IF( lk_vvl .AND. (.NOT. ln_dynadv_vec) ) THEN
          CALL iom_put( "uoce" , umask(:,:,:) * un(:,:,:) * fse3u_n(:,:,:) )    ! i-transport
@@ -580,23 +577,22 @@
          ENDIF
 
-#if ! defined key_coupled 
-         CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sosafldp", "Surface salt flux: damping"         , "Kg/m2/s",   &  ! erp * sn
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-#endif
-
-
-
-#if ( defined key_coupled && ! defined key_lim3 && ! defined key_lim2 ) 
-         CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sosafldp", "Surface salt flux: Damping"         , "Kg/m2/s",   &  ! erp * sn
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-#endif
+         IF( .NOT. lk_cpl ) THEN
+            CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
+               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+            CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
+               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+            CALL histdef( nid_T, "sosafldp", "Surface salt flux: damping"         , "Kg/m2/s",   &  ! erp * sn
+               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         ENDIF
+
+         IF( lk_cpl .AND. nn_ice <= 1 ) THEN
+            CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
+               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+            CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
+               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+            CALL histdef( nid_T, "sosafldp", "Surface salt flux: Damping"         , "Kg/m2/s",   &  ! erp * sn
+               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         ENDIF
+         
          clmx ="l_max(only(x))"    ! max index on a period
          CALL histdef( nid_T, "sobowlin", "Bowl Index"                         , "W-point",   &  ! bowl INDEX 
@@ -613,15 +609,10 @@
 #endif
 
-#if defined key_coupled 
-# if defined key_lim3
-         Must be adapted to LIM3
-# endif 
-# if defined key_lim2
-         CALL histdef( nid_T,"soicetem" , "Ice Surface Temperature"            , "K"      ,   &  ! tn_ice
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T,"soicealb" , "Ice Albedo"                         , "[0,1]"  ,   &  ! alb_ice
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-# endif 
-#endif 
+         IF( lk_cpl .AND. nn_ice == 2 ) THEN
+            CALL histdef( nid_T,"soicetem" , "Ice Surface Temperature"            , "K"      ,   &  ! tn_ice
+               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+            CALL histdef( nid_T,"soicealb" , "Ice Albedo"                         , "[0,1]"  ,   &  ! alb_ice
+               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         ENDIF
 
          CALL histend( nid_T, snc4chunks=snc4set )
@@ -773,16 +764,16 @@
       ENDIF
 
-#if ! defined key_coupled
-!      CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
-!      CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
-!      IF( ln_ssr ) zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
-!      CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
-#endif
-#if ( defined key_coupled && ! defined key_lim3 && ! defined key_lim2 ) 
-      CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
-      CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
+      IF( .NOT. lk_cpl ) THEN
+         CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
+         CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
          IF( ln_ssr ) zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
-      CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
-#endif
+         CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
+      ENDIF
+      IF( lk_cpl .AND. nn_ice <= 1 ) THEN
+         CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
+         CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
+         IF( ln_ssr ) zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
+         CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
+      ENDIF
 !      zw2d(:,:) = FLOAT( nmln(:,:) ) * tmask(:,:,1)
 !      CALL histwrite( nid_T, "sobowlin", it, zw2d          , ndim_hT, ndex_hT )   ! ???
@@ -795,16 +786,9 @@
 #endif
 
-#if defined key_coupled 
-# if defined key_lim3
-      Must be adapted for LIM3
-      CALL histwrite( nid_T, "soicetem", it, tn_ice        , ndim_hT, ndex_hT )   ! surf. ice temperature
-      CALL histwrite( nid_T, "soicealb", it, alb_ice       , ndim_hT, ndex_hT )   ! ice albedo
-# endif
-# if defined key_lim2
-      CALL histwrite( nid_T, "soicetem", it, tn_ice(:,:,1) , ndim_hT, ndex_hT )   ! surf. ice temperature
-      CALL histwrite( nid_T, "soicealb", it, alb_ice(:,:,1), ndim_hT, ndex_hT )   ! ice albedo
-# endif
-#endif
-      ! Write fields on U grid 
+      IF( lk_cpl .AND. nn_ice == 2 ) THEN
+         CALL histwrite( nid_T, "soicetem", it, tn_ice(:,:,1) , ndim_hT, ndex_hT )   ! surf. ice temperature
+         CALL histwrite( nid_T, "soicealb", it, alb_ice(:,:,1), ndim_hT, ndex_hT )   ! ice albedo
+      ENDIF
+
       CALL histwrite( nid_U, "vozocrtx", it, un            , ndim_U , ndex_U )    ! i-current
       IF( ln_traldf_gdia ) THEN
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90	(revision 4946)
@@ -1003,5 +1003,5 @@
 
       IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE vertical coordinate in namelist nam_vvl' )
-      IF( .NOT. ln_vvl_zstar .AND. nn_isf .NE. 0)   CALL ctl_stop( 'vvl_ztilde, vvl_layer, vvl_ztilde_as_zstar, vvl_zstar_at_eqtor not tested with ice shelf cavity (only vvl_zstar was tested)' )
+      IF( .NOT. ln_vvl_zstar .AND. nn_isf .NE. 0) CALL ctl_stop( 'Only vvl_zstar has been tested with ice shelf cavity' )
 
       IF(lwp) THEN                   ! Print the choice
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 4946)
@@ -1082,6 +1082,8 @@
                ! test bathy
                IF (risfdep(ji,jj) .GT. 1) THEN
-               zbathydiff =ABS(bathy(ji,jj)   - (gdepw_1d(mbathy (ji,jj)+1) + MIN( e3zps_min, e3t_1d(mbathy (ji,jj)+1)*e3zps_rat )))
-               zrisfdepdiff=ABS(risfdep(ji,jj) - (gdepw_1d(misfdep(ji,jj)  ) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )))
+               zbathydiff =ABS(bathy(ji,jj)   - (gdepw_1d(mbathy (ji,jj)+1) &
+                 &   + MIN( e3zps_min, e3t_1d(mbathy (ji,jj)+1)*e3zps_rat )))
+               zrisfdepdiff=ABS(risfdep(ji,jj) - (gdepw_1d(misfdep(ji,jj)  ) &
+                 &   - MIN( e3zps_min, e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )))
  
                   IF (bathy(ji,jj) .GT. risfdep(ji,jj) .AND. mbathy(ji,jj) .LT. misfdep(ji,jj)) THEN
@@ -1104,6 +1106,8 @@
                ! test bathy
                IF( misfdep(ji,jj) == mbathy(ji,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff  =ABS(bathy(ji,jj)  - (gdepw_1d(mbathy (ji,jj)+1) + MIN( e3zps_min,e3t_1d(mbathy (ji,jj)+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji,jj) - (gdepw_1d(misfdep(ji,jj)  ) - MIN( e3zps_min,e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )))
+                  zbathydiff  =ABS(bathy(ji,jj)  - (gdepw_1d(mbathy (ji,jj)+1)&
+                    & + MIN( e3zps_min,e3t_1d(mbathy (ji,jj)+1)*e3zps_rat )))
+                  zrisfdepdiff=ABS(risfdep(ji,jj) - (gdepw_1d(misfdep(ji,jj)  )  &
+                    & - MIN( e3zps_min,e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )))
                   IF (zbathydiff .LE. zrisfdepdiff) THEN
                      mbathy(ji,jj) = mbathy(ji,jj) + 1
@@ -1121,12 +1125,16 @@
             DO ji = 1, jpim1
                IF( misfdep(ji,jj+1) == mbathy(ji,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff =ABS(bathy(ji,jj    ) - (gdepw_1d(mbathy (ji,jj)+1) + MIN( e3zps_min, e3t_1d(mbathy (ji,jj  )+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji,jj+1) - (gdepw_1d(misfdep(ji,jj+1)) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj+1)-1)*e3zps_rat )))
+                  zbathydiff =ABS(bathy(ji,jj    ) - (gdepw_1d(mbathy (ji,jj)+1)   &
+                    &   + MIN( e3zps_min, e3t_1d(mbathy (ji,jj  )+1)*e3zps_rat )))
+                  zrisfdepdiff=ABS(risfdep(ji,jj+1) - (gdepw_1d(misfdep(ji,jj+1))  &
+                    &  - MIN( e3zps_min, e3t_1d(misfdep(ji,jj+1)-1)*e3zps_rat )))
                   IF (zbathydiff .LE. zrisfdepdiff) THEN
                      mbathy(ji,jj) = mbathy(ji,jj) + 1
-                     bathy(ji,jj)  = gdepw_1d(mbathy (ji,jj  )) + MIN( e3zps_min, e3t_1d(mbathy(ji,jj   )+1)*e3zps_rat )
+                     bathy(ji,jj)  = gdepw_1d(mbathy (ji,jj  )) &
+                   &    + MIN( e3zps_min, e3t_1d(mbathy(ji,jj   )+1)*e3zps_rat )
                   ELSE
                      misfdep(ji,jj+1)  = misfdep(ji,jj+1) - 1
-                     risfdep (ji,jj+1) = gdepw_1d(misfdep(ji,jj+1)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj+1))*e3zps_rat )
+                     risfdep (ji,jj+1) = gdepw_1d(misfdep(ji,jj+1)+1) &
+                   &   - MIN( e3zps_min, e3t_1d(misfdep(ji,jj+1))*e3zps_rat )
                   END IF
                ENDIF
@@ -1148,6 +1156,8 @@
             DO ji = 1, jpim1
                IF( misfdep(ji,jj) == mbathy(ji,jj+1) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff =ABS(  bathy(ji,jj+1) - (gdepw_1d(mbathy (ji,jj+1)+1) + MIN( e3zps_min, e3t_1d(mbathy (ji,jj+1)+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji,jj  ) - (gdepw_1d(misfdep(ji,jj  )  ) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj  )-1)*e3zps_rat )))
+                  zbathydiff =ABS(  bathy(ji,jj+1) - (gdepw_1d(mbathy (ji,jj+1)+1) &
+                   &   + MIN( e3zps_min, e3t_1d(mbathy (ji,jj+1)+1)*e3zps_rat )))
+                  zrisfdepdiff=ABS(risfdep(ji,jj  ) - (gdepw_1d(misfdep(ji,jj  )  )  &
+                   &   - MIN( e3zps_min, e3t_1d(misfdep(ji,jj  )-1)*e3zps_rat )))
                   IF (zbathydiff .LE. zrisfdepdiff) THEN
                      mbathy (ji,jj+1) = mbathy(ji,jj+1) + 1
@@ -1177,6 +1187,8 @@
             DO ji = 1, jpim1
                IF( misfdep(ji+1,jj) == mbathy(ji,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff =ABS(  bathy(ji  ,jj) - (gdepw_1d(mbathy (ji,jj)+1) + MIN( e3zps_min, e3t_1d(mbathy (ji  ,jj)+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji+1,jj) - (gdepw_1d(misfdep(ji+1,jj)) - MIN( e3zps_min, e3t_1d(misfdep(ji+1,jj)-1)*e3zps_rat )))
+                  zbathydiff =ABS(  bathy(ji  ,jj) - (gdepw_1d(mbathy (ji,jj)+1) &
+                    &   + MIN( e3zps_min, e3t_1d(mbathy (ji  ,jj)+1)*e3zps_rat )))
+                  zrisfdepdiff=ABS(risfdep(ji+1,jj) - (gdepw_1d(misfdep(ji+1,jj)) &
+                    &  - MIN( e3zps_min, e3t_1d(misfdep(ji+1,jj)-1)*e3zps_rat )))
                   IF (zbathydiff .LE. zrisfdepdiff) THEN
                      mbathy(ji,jj) = mbathy(ji,jj) + 1
@@ -1205,12 +1217,16 @@
             DO ji = 1, jpim1
                IF( misfdep(ji,jj) == mbathy(ji+1,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff =ABS(  bathy(ji+1,jj) - (gdepw_1d(mbathy (ji+1,jj)+1) + MIN( e3zps_min, e3t_1d(mbathy (ji+1,jj)+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji  ,jj) - (gdepw_1d(misfdep(ji  ,jj)  ) - MIN( e3zps_min, e3t_1d(misfdep(ji  ,jj)-1)*e3zps_rat )))
+                  zbathydiff =ABS(  bathy(ji+1,jj) - (gdepw_1d(mbathy (ji+1,jj)+1) &
+                      &   + MIN( e3zps_min, e3t_1d(mbathy (ji+1,jj)+1)*e3zps_rat )))
+                  zrisfdepdiff=ABS(risfdep(ji  ,jj) - (gdepw_1d(misfdep(ji  ,jj)  )  &
+                      &  - MIN( e3zps_min, e3t_1d(misfdep(ji  ,jj)-1)*e3zps_rat )))
                   IF (zbathydiff .LE. zrisfdepdiff) THEN
                      mbathy(ji+1,jj)  = mbathy (ji+1,jj) + 1
-                     bathy (ji+1,jj)  = gdepw_1d(mbathy (ji+1,jj)  ) + MIN( e3zps_min, e3t_1d(mbathy (ji+1,jj) +1)*e3zps_rat )
+                     bathy (ji+1,jj)  = gdepw_1d(mbathy (ji+1,jj)  )  &
+                      &   + MIN( e3zps_min, e3t_1d(mbathy (ji+1,jj) +1)*e3zps_rat )
                   ELSE
                      misfdep(ji,jj)   = misfdep(ji  ,jj) - 1
-                     risfdep(ji,jj)   = gdepw_1d(misfdep(ji  ,jj)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji  ,jj)   )*e3zps_rat )
+                     risfdep(ji,jj)   = gdepw_1d(misfdep(ji  ,jj)+1) &
+                      &   - MIN( e3zps_min, e3t_1d(misfdep(ji  ,jj)   )*e3zps_rat )
                   END IF
                ENDIF
@@ -1591,6 +1607,8 @@
          DO jj = 1, jpjm1 
             DO ji = 1, fs_jpim1   ! vector opt. 
-               e3uw_0(ji,jj,jk) = MIN( gdept_0(ji,jj,jk), gdept_0(ji+1,jj  ,jk) ) - MAX( gdept_0(ji,jj,jk-1), gdept_0(ji+1,jj  ,jk-1) )
-               e3vw_0(ji,jj,jk) = MIN( gdept_0(ji,jj,jk), gdept_0(ji  ,jj+1,jk) ) - MAX( gdept_0(ji,jj,jk-1), gdept_0(ji  ,jj+1,jk-1) )
+               e3uw_0(ji,jj,jk) = MIN( gdept_0(ji,jj,jk), gdept_0(ji+1,jj  ,jk) ) &
+                 &   - MAX( gdept_0(ji,jj,jk-1), gdept_0(ji+1,jj  ,jk-1) )
+               e3vw_0(ji,jj,jk) = MIN( gdept_0(ji,jj,jk), gdept_0(ji  ,jj+1,jk) ) &
+                 &   - MAX( gdept_0(ji,jj,jk-1), gdept_0(ji  ,jj+1,jk-1) )
             END DO 
          END DO 
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90	(revision 4946)
@@ -34,6 +34,4 @@
    USE dtatsd          ! data temperature and salinity   (dta_tsd routine)
    USE dtauvd          ! data: U & V current             (dta_uvd routine)
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O library
    USE zpshde          ! partial step: hor. derivative (zps_hde routine)
    USE eosbn2          ! equation of state            (eos bn2 routine)
@@ -42,4 +40,7 @@
    USE dynspg_flt      ! filtered free surface
    USE sol_oce         ! ocean solver variables
+   !
+   USE in_out_manager  ! I/O manager
+   USE iom             ! I/O library
    USE lib_mpp         ! MPP library
    USE restart         ! restart
@@ -56,5 +57,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -73,5 +74,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('istate_init')
+      IF( nn_timing == 1 )   CALL timing_start('istate_init')
       !
 
@@ -83,8 +84,10 @@
       IF( lk_c1d ) CALL dta_uvd_init          ! Initialization of U & V input data
 
-      rhd  (:,:,:  ) = 0.e0
-      rhop (:,:,:  ) = 0.e0
-      rn2  (:,:,:  ) = 0.e0 
-      tsa  (:,:,:,:) = 0.e0    
+      rhd  (:,:,:  ) = 0._wp
+      rhop (:,:,:  ) = 0._wp
+      rn2  (:,:,:  ) = 0._wp
+      tsa  (:,:,:,:) = 0._wp   
+      rab_b(:,:,:,:) = 0._wp
+      rab_n(:,:,:,:) = 0._wp
 
       IF( ln_rstart ) THEN                    ! Restart from a file
@@ -168,11 +171,6 @@
       !
       DO jk = 1, jpkm1
-#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                  
                un_b(ji,jj) = un_b(ji,jj) + fse3u_n(ji,jj,jk) * un(ji,jj,jk) * umask(ji,jj,jk)
                vn_b(ji,jj) = vn_b(ji,jj) + fse3v_n(ji,jj,jk) * vn(ji,jj,jk) * vmask(ji,jj,jk)
@@ -191,7 +189,8 @@
       !
       !
-      IF( nn_timing == 1 )  CALL timing_stop('istate_init')
+      IF( nn_timing == 1 )   CALL timing_stop('istate_init')
       !
    END SUBROUTINE istate_init
+
 
    SUBROUTINE istate_t_s
@@ -225,4 +224,5 @@
    END SUBROUTINE istate_t_s
 
+
    SUBROUTINE istate_eel
       !!----------------------------------------------------------------------
@@ -239,5 +239,5 @@
       USE divcur     ! hor. divergence & rel. vorticity      (div_cur routine)
       USE iom
- 
+      !
       INTEGER  ::   inum              ! temporary logical unit
       INTEGER  ::   ji, jj, jk        ! dummy loop indices
@@ -250,5 +250,5 @@
       REAL(wp), DIMENSION(jpiglo,jpjglo) ::   zssh  ! initial ssh over the global domain
       !!----------------------------------------------------------------------
-
+      !
       SELECT CASE ( jp_cfg ) 
          !                                              ! ====================
@@ -381,12 +381,12 @@
       INTEGER, PARAMETER ::   ntsinit = 0   ! (0/1) (analytical/input data files) T&S initialization
       !!----------------------------------------------------------------------
-
+      !
       SELECT CASE ( ntsinit)
-
+      !
       CASE ( 0 )                  ! analytical T/S profil deduced from LEVITUS
          IF(lwp) WRITE(numout,*)
          IF(lwp) WRITE(numout,*) 'istate_gyre : initial analytical T and S profil deduced from LEVITUS '
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
-
+         !
          DO jk = 1, jpk
             DO jj = 1, jpj
@@ -413,5 +413,5 @@
             END DO
          END DO
-
+         !
       CASE ( 1 )                  ! T/S data fields read in dta_tem.nc/data_sal.nc files
          IF(lwp) WRITE(numout,*)
@@ -437,7 +437,7 @@
          tsn(:,:,:,jp_sal) = tsn(:,:,:,jp_sal) * tmask(:,:,:) 
          tsb(:,:,:,jp_sal) = tsn(:,:,:,jp_sal)
-
+         !
       END SELECT
-
+      !
       IF(lwp) THEN
          WRITE(numout,*)
@@ -446,6 +446,7 @@
          WRITE(numout, "(10x, i4, 3f10.2)" ) ( jk, gdept_1d(jk), tsn(2,2,jk,jp_tem), tsn(2,2,jk,jp_sal), jk = 1, jpk )
       ENDIF
-
+      !
    END SUBROUTINE istate_gyre
+
 
    SUBROUTINE istate_uvg
@@ -463,5 +464,5 @@
       USE divcur          ! hor. divergence & rel. vorticity      (div_cur routine)
       USE lbclnk          ! ocean lateral boundary condition (or mpp link)
-
+      !
       INTEGER ::   ji, jj, jk        ! dummy loop indices
       INTEGER ::   indic             ! ???
@@ -573,3 +574,2 @@
    !!=====================================================================
 END MODULE istate
-
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DOM/phycst.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DOM/phycst.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DOM/phycst.F90	(revision 4946)
@@ -47,13 +47,8 @@
    REAL(wp), PUBLIC ::   rt0_ice  = 273.05_wp        !: melting point of ice          [Kelvin]
 #endif
-#if defined key_cice
-   REAL(wp), PUBLIC ::   rau0     = 1026._wp         !: volumic mass of reference     [kg/m3]
-#else
-   REAL(wp), PUBLIC ::   rau0     = 1035._wp         !: volumic mass of reference     [kg/m3]
-#endif
+   REAL(wp), PUBLIC ::   rau0                        !: volumic mass of reference     [kg/m3]
    REAL(wp), PUBLIC ::   r1_rau0                     !: = 1. / rau0                   [m3/kg]
-   REAL(wp), PUBLIC ::   rauw     = 1000._wp         !: volumic mass of pure water    [m3/kg]
-   REAL(wp), PUBLIC ::   rcp      =    4.e3_wp       !: ocean specific heat           [J/kg/K]
-   REAL(wp), PUBLIC ::   r1_rcp                      !: = 1. / rcp                    [kg.K/J]
+   REAL(wp), PUBLIC ::   rcp                         !: ocean specific heat           [J/Kelvin]
+   REAL(wp), PUBLIC ::   r1_rcp                      !: = 1. / rcp                    [Kelvin/J]
    REAL(wp), PUBLIC ::   r1_rau0_rcp                 !: = 1. / ( rau0 * rcp )
 
@@ -69,10 +64,10 @@
 #if defined key_lim3 || defined key_cice
    REAL(wp), PUBLIC ::   rhoic    =  917._wp         !: volumic mass of sea ice                               [kg/m3]
-   REAL(wp), PUBLIC ::   rcdic    =    2.034396_wp   !: thermal conductivity of fresh ice                     [W/m/K]
-   REAL(wp), PUBLIC ::   rcdsn    =    0.31_wp       !: thermal conductivity of snow                          [W/m/K] 
-   REAL(wp), PUBLIC ::   cpic     = 2067.0_wp        !: specific heat for ice                                 [J/kg/K]
+   REAL(wp), PUBLIC ::   rcdic    =    2.034396_wp   !: thermal conductivity of fresh ice
+   REAL(wp), PUBLIC ::   rcdsn    =    0.31_wp       !: thermal conductivity of snow
+   REAL(wp), PUBLIC ::   cpic     = 2067.0_wp        !: specific heat for ice 
    REAL(wp), PUBLIC ::   lsub     =    2.834e+6_wp   !: pure ice latent heat of sublimation                   [J/kg]
    REAL(wp), PUBLIC ::   lfus     =    0.334e+6_wp   !: latent heat of fusion of fresh ice                    [J/kg]
-   REAL(wp), PUBLIC ::   tmut     =    0.054_wp      !: decrease of seawater meltpoint with salinity          [degC/ppt]
+   REAL(wp), PUBLIC ::   tmut     =    0.054_wp      !: decrease of seawater meltpoint with salinity
    REAL(wp), PUBLIC ::   xlsn                        !: = lfus*rhosn (volumetric latent heat fusion of snow)  [J/m3]
 #else
@@ -163,15 +158,6 @@
       IF(lwp) WRITE(numout,*) '          melting point of ice             rt0_ice  = ', rt0_ice , ' K'
 
-      r1_rau0     = 1._wp / rau0
-      r1_rcp      = 1._wp / rcp
-      r1_rau0_rcp = 1._wp / ( rau0 * rcp )
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '          volumic mass of pure water          rauw  = ', rauw   , ' kg/m^3'
-      IF(lwp) WRITE(numout,*) '          volumic mass of reference           rau0  = ', rau0   , ' kg/m^3'
-      IF(lwp) WRITE(numout,*) '          1. / rau0                        r1_rau0  = ', r1_rau0, ' m^3/kg'
-      IF(lwp) WRITE(numout,*) '          ocean specific heat                 rcp   = ', rcp    , ' J/Kelvin'
-      IF(lwp) WRITE(numout,*) '          1. / ( rau0 * rcp )           r1_rau0_rcp = ', r1_rau0_rcp
-
-
+      IF(lwp) WRITE(numout,*) '          reference density and heat capacity now defined in eosbn2.f90'
+              
 #if defined key_lim3 || defined key_cice
       xlsn = lfus * rhosn        ! volumetric latent heat fusion of snow [J/m3]
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90	(revision 4946)
@@ -15,11 +15,12 @@
    USE oce            ! ocean dynamics and tracers
    USE dom_oce        ! ocean space and time domain
-   USE trdmod_oce     ! ocean variables trends
-   USE trdmod         ! ocean dynamics trends
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
+   !
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! MPP library
    USE prtctl         ! Print control
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -103,5 +104,5 @@
          zfu_uw(:,:,:) = ua(:,:,:) - zfu_uw(:,:,:)
          zfv_vw(:,:,:) = va(:,:,:) - zfv_vw(:,:,:)
-         CALL trd_mod( zfu_uw, zfv_vw, jpdyn_trd_had, 'DYN', kt )
+         CALL trd_dyn( zfu_uw, zfv_vw, jpdyn_keg, kt )
          zfu_t(:,:,:) = ua(:,:,:)
          zfv_t(:,:,:) = va(:,:,:)
@@ -153,5 +154,5 @@
          zfu_t(:,:,:) = ua(:,:,:) - zfu_t(:,:,:)
          zfv_t(:,:,:) = va(:,:,:) - zfv_t(:,:,:)
-         CALL trd_mod( zfu_t, zfv_t, jpdyn_trd_zad, 'DYN', kt )
+         CALL trd_dyn( zfu_t, zfv_t, jpdyn_zad, kt )
       ENDIF
       !                                            ! Control print
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90	(revision 4946)
@@ -16,12 +16,13 @@
    USE oce            ! ocean dynamics and tracers
    USE dom_oce        ! ocean space and time domain
-   USE trdmod         ! ocean dynamics trends
-   USE trdmod_oce     ! ocean variables trends
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
+   !
    USE in_out_manager ! I/O manager
    USE prtctl         ! Print control
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp        ! MPP library
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -196,5 +197,5 @@
          zfu_uw(:,:,:) = ua(:,:,:) - zfu_uw(:,:,:)
          zfv_vw(:,:,:) = va(:,:,:) - zfv_vw(:,:,:)
-         CALL trd_mod( zfu_uw, zfv_vw, jpdyn_trd_had, 'DYN', kt )
+         CALL trd_dyn( zfu_uw, zfv_vw, jpdyn_keg, kt )
          zfu_t(:,:,:) = ua(:,:,:)
          zfv_t(:,:,:) = va(:,:,:)
@@ -245,5 +246,5 @@
          zfu_t(:,:,:) = ua(:,:,:) - zfu_t(:,:,:)
          zfv_t(:,:,:) = va(:,:,:) - zfv_t(:,:,:)
-         CALL trd_mod( zfu_t, zfv_t, jpdyn_trd_zad, 'DYN', kt )
+         CALL trd_dyn( zfu_t, zfv_t, jpdyn_zad, kt )
       ENDIF
       !                                            ! Control print
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynbfr.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynbfr.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynbfr.F90	(revision 4946)
@@ -10,21 +10,21 @@
 
    !!----------------------------------------------------------------------
-   !!   dyn_bfr      : Update the momentum trend with the bottom friction contribution
+   !!   dyn_bfr       : Update the momentum trend with the bottom friction contribution
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables 
-   USE zdf_oce         ! ocean vertical physics variables
-   USE zdfbfr          ! ocean bottom friction variables
-   USE trdmod          ! ocean active dynamics and tracers trends 
-   USE trdmod_oce      ! ocean variables trends
-   USE in_out_manager  ! I/O manager
-   USE prtctl          ! Print control
-   USE timing          ! Timing
-   USE wrk_nemo        ! Memory Allocation
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables 
+   USE zdf_oce        ! ocean vertical physics variables
+   USE zdfbfr         ! ocean bottom friction variables
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
+   USE in_out_manager ! I/O manager
+   USE prtctl         ! Print control
+   USE timing         ! Timing
+   USE wrk_nemo       ! Memory Allocation
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   dyn_bfr    !  routine called by step.F90
+   PUBLIC   dyn_bfr   !  routine called by step.F90
 
    !! * Substitutions
@@ -57,7 +57,10 @@
       IF( nn_timing == 1 )  CALL timing_start('dyn_bfr')
       !
+!!gm issue: better to put the logical in step to control the call of zdf_bfr
+!!          ==> change the logical from ln_bfrimp to ln_bfr_exp !!
       IF( .NOT.ln_bfrimp) THEN     ! only for explicit bottom friction form
                                     ! implicit bfr is implemented in dynzdf_imp
 
+!!gm bug : time step is only rdt (not 2 rdt if euler start !)
         zm1_2dt = - 1._wp / ( 2._wp * rdt )
 
@@ -69,11 +72,6 @@
 
 
-# if defined key_vectopt_loop
-        DO jj = 1, 1
-           DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
-# else
         DO jj = 2, jpjm1
            DO ji = 2, jpim1
-# endif
               ikbu = mbku(ji,jj)          ! deepest ocean u- & v-levels
               ikbv = mbkv(ji,jj)
@@ -101,5 +99,5 @@
            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-           CALL trd_mod( ztrdu(:,:,:), ztrdv(:,:,:), jpdyn_trd_bfr, 'DYN', kt )
+           CALL trd_dyn( ztrdu(:,:,:), ztrdv(:,:,:), jpdyn_bfr, kt )
            CALL wrk_dealloc( jpi,jpj,jpk, ztrdu, ztrdv )
         ENDIF
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 4946)
@@ -32,9 +32,10 @@
    USE dom_oce         ! ocean space and time domain
    USE phycst          ! physical constants
-   USE trdmod          ! ocean dynamics trends
-   USE trdmod_oce      ! ocean variables trends
+   USE trd_oce         ! trends: ocean variables
+   USE trddyn          ! trend manager: dynamics
+   !
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
-   USE lbclnk          ! lateral boundary condition
+   USE lbclnk          ! lateral boundary condition 
    USE lib_mpp         ! MPP library
    USE eosbn2          ! compute density
@@ -76,5 +77,5 @@
       !!
       !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
-      !!             - Save the trend (l_trddyn=T)
+      !!             - send trends to trd_dyn for futher diagnostics (l_trddyn=T)
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
@@ -101,5 +102,5 @@
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_hpg, 'DYN', kt )
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_hpg, kt )
          CALL wrk_dealloc( jpi,jpj,jpk, ztrdu, ztrdv )
       ENDIF
@@ -177,5 +178,6 @@
       IF( ln_hpg_prj )   ioptio = ioptio + 1
       IF( ioptio /= 1 )   CALL ctl_stop( 'NO or several hydrostatic pressure gradient options used' )
-      IF( (ln_hpg_zco .OR. ln_hpg_zps .OR. ln_hpg_djc .OR. ln_hpg_prj ) .AND. nn_isf .NE. 0 )   CALL ctl_stop( 'Only hpg_sco has been corrected to work with ice shelf cavity. Comparison in a GYRE simulation with bump in the middle show similar result than hpg_zps' )
+      IF( (ln_hpg_zco .OR. ln_hpg_zps .OR. ln_hpg_djc .OR. ln_hpg_prj ) .AND. nn_isf .NE. 0 )   &
+          &  CALL ctl_stop( 'Only hpg_sco has been corrected to work with ice shelf cavity.' )
       !
    END SUBROUTINE dyn_hpg_init
@@ -318,11 +320,6 @@
 
       ! partial steps correction at the last level  (use gru & grv computed in zpshde.F90)
-# if defined key_vectopt_loop
-         jj = 1
-         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
-# else
       DO jj = 2, jpjm1
          DO ji = 2, jpim1
-# endif
             iku = mbku(ji,jj)
             ikv = mbkv(ji,jj)
@@ -341,7 +338,5 @@
                va  (ji,jj,ikv) = va(ji,jj,ikv) + zhpj(ji,jj,ikv)         ! add the new one to the general momentum trend
             ENDIF
-# if ! defined key_vectopt_loop
-         END DO
-# endif
+         END DO
       END DO
       !
@@ -617,4 +612,5 @@
    END SUBROUTINE hpg_sco
 
+
    SUBROUTINE hpg_djc( kt )
       !!---------------------------------------------------------------------
@@ -854,6 +850,4 @@
       !!
       !! ** Action : - Update (ua,va) with the now hydrastatic pressure trend
-      !!             - Save the trend (l_trddyn=T)
-      !!
       !!----------------------------------------------------------------------
       INTEGER, PARAMETER  :: polynomial_type = 1    ! 1: cubic spline, 2: linear
@@ -907,13 +901,19 @@
 
       ! Transfer the depth of "T(:,:,:)" to vertical coordinate "zdept(:,:,:)"
-      DO jj = 1, jpj;   DO ji = 1, jpi
-          zdept(ji,jj,1) = 0.5_wp * fse3w(ji,jj,1) - sshn(ji,jj) * znad
-      END DO        ;   END DO
-
-      DO jk = 2, jpk;   DO jj = 1, jpj;   DO ji = 1, jpi
-          zdept(ji,jj,jk) = zdept(ji,jj,jk-1) + fse3w(ji,jj,jk)
-      END DO        ;   END DO        ;   END DO
-
-      fsp(:,:,:) = zrhh(:,:,:)
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zdept(ji,jj,1) = 0.5_wp * fse3w(ji,jj,1) - sshn(ji,jj) * znad
+         END DO
+      END DO
+
+      DO jk = 2, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zdept(ji,jj,jk) = zdept(ji,jj,jk-1) + fse3w(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      fsp(:,:,:) = zrhh (:,:,:)
       xsp(:,:,:) = zdept(:,:,:)
 
@@ -1116,4 +1116,5 @@
    END SUBROUTINE hpg_prj
 
+
    SUBROUTINE cspline(fsp, xsp, asp, bsp, csp, dsp, polynomial_type)
       !!----------------------------------------------------------------------
@@ -1123,6 +1124,6 @@
       !!
       !! ** Method  :   f(x) = asp + bsp*x + csp*x^2 + dsp*x^3
+      !!
       !! Reference: CJC Kruger, Constrained Cubic Spline Interpoltation
-      !!
       !!----------------------------------------------------------------------
       IMPLICIT NONE
@@ -1132,6 +1133,5 @@
       INTEGER, INTENT(in) :: polynomial_type                        ! 1: cubic spline
                                                                     ! 2: Linear
-
-      ! Local Variables
+      !
       INTEGER  ::   ji, jj, jk                 ! dummy loop indices
       INTEGER  ::   jpi, jpj, jpkm1
@@ -1223,5 +1223,4 @@
       ENDIF
 
-
    END SUBROUTINE cspline
 
@@ -1233,8 +1232,6 @@
       !! ** Purpose :   1-d linear interpolation
       !!
-      !! ** Method  :
-      !!                interpolation is straight forward
+      !! ** Method  :   interpolation is straight forward
       !!                extrapolation is also permitted (no value limit)
-      !!
       !!----------------------------------------------------------------------
       IMPLICIT NONE
@@ -1253,4 +1250,5 @@
    END FUNCTION interp1
 
+
    FUNCTION interp2(x, a, b, c, d)  RESULT(f)
       !!----------------------------------------------------------------------
@@ -1316,5 +1314,4 @@
    END FUNCTION integ_spline
 
-
    !!======================================================================
 END MODULE dynhpg
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynkeg.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynkeg.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynkeg.F90	(revision 4946)
@@ -14,6 +14,7 @@
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
-   USE trdmod          ! ocean dynamics trends 
-   USE trdmod_oce      ! ocean variables trends
+   USE trd_oce         ! trends: ocean variables
+   USE trddyn          ! trend manager: dynamics
+   !
    USE in_out_manager  ! I/O manager
    USE lib_mpp         ! MPP library
@@ -52,8 +53,8 @@
       !!
       !! ** Action : - Update the (ua, va) with the hor. ke gradient trend
-      !!             - save this trends (l_trddyn=T) for post-processing
+      !!             - send this trends to trd_dyn (l_trddyn=T) for post-processing
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
-      !!
+      !
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
       REAL(wp) ::   zu, zv       ! temporary scalars
@@ -131,5 +132,5 @@
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_keg, 'DYN', kt )
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_keg, kt )
          CALL wrk_dealloc( jpi,jpj,jpk, ztrdu, ztrdv )
       ENDIF
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf.F90	(revision 4946)
@@ -15,4 +15,5 @@
    USE phycst         ! physical constants
    USE ldfdyn_oce     ! ocean dynamics lateral physics
+   USE ldftra_oce     ! ocean tracers  lateral physics
    USE ldfslp         ! lateral mixing: slopes of mixing orientation
    USE dynldf_bilapg  ! lateral mixing            (dyn_ldf_bilapg routine)
@@ -20,7 +21,7 @@
    USE dynldf_iso     ! lateral mixing            (dyn_ldf_iso    routine)
    USE dynldf_lap     ! lateral mixing            (dyn_ldf_lap    routine)
-   USE ldftra_oce, ONLY: ln_traldf_hor     ! ocean tracers lateral physics
-   USE trdmod         ! ocean dynamics and tracer trends
-   USE trdmod_oce     ! ocean variables trends
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics   (trd_dyn        routine)
+   !
    USE prtctl         ! Print control
    USE in_out_manager ! I/O manager
@@ -30,5 +31,4 @@
    USE timing          ! Timing
 
-
    IMPLICIT NONE
    PRIVATE
@@ -55,5 +55,4 @@
       !! ** Purpose :   compute the lateral ocean dynamics physics.
       !!----------------------------------------------------------------------
-      !
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !
@@ -107,5 +106,5 @@
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_ldf, 'DYN', kt )
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_ldf, kt )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv )
       ENDIF
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_bilap.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_bilap.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_bilap.F90	(revision 4946)
@@ -19,7 +19,6 @@
    USE dom_oce         ! ocean space and time domain
    USE ldfdyn_oce      ! ocean dynamics: lateral physics
+   !
    USE in_out_manager  ! I/O manager
-   USE trdmod          ! ocean dynamics trends 
-   USE trdmod_oce      ! ocean variables trends
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE wrk_nemo        ! Memory Allocation
@@ -70,11 +69,8 @@
       !!      Add this before trend to the general trend (ua,va):
       !!            (ua,va) = (ua,va) + (diffu,diffv)
-      !!      'key_trddyn' defined: the two components of the horizontal
-      !!                               diffusion trend are saved.
       !!
       !! ** Action : - Update (ua,va) with the before iso-level biharmonic
       !!               mixing trend.
       !!----------------------------------------------------------------------
-      !
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_bilapg.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_bilapg.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_bilapg.F90	(revision 4946)
@@ -19,9 +19,8 @@
    USE dom_oce         ! ocean space and time domain
    USE ldfdyn_oce      ! ocean dynamics lateral physics
+   USE zdf_oce         ! ocean vertical physics
+   USE ldfslp          ! iso-neutral slopes available
    USE ldftra_oce, ONLY: ln_traldf_iso
-   USE zdf_oce         ! ocean vertical physics
-   USE trdmod          ! ocean dynamics trends 
-   USE trdmod_oce      ! ocean variables trends
-   USE ldfslp          ! iso-neutral slopes available
+   !
    USE in_out_manager  ! I/O manager
    USE lib_mpp         ! MPP library
@@ -81,9 +80,7 @@
       !!         -3- Add this trend to the general trend (ta,sa):
       !!            (ua,va) = (ua,va) + (zwk3,zwk4)
-      !!      'key_trddyn' defined: the trend is saved for diagnostics.
       !!
       !! ** Action  : - Update (ua,va) arrays with the before geopotential
       !!                biharmonic mixing trend.
-      !!              - save the trend in (zwk3,zwk4) ('key_trddyn')
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt           ! ocean time-step index
@@ -201,7 +198,5 @@
       !!                          pu and pv (all the components except
       !!                          second order vertical derivative term)
-      !!      'key_trddyn' defined: the trend is saved for diagnostics.
-      !!----------------------------------------------------------------------
-      !!
+      !!----------------------------------------------------------------------
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::   pu , pv    ! 1st call: before horizontal velocity 
       !                                                               ! 2nd call: ahm x these fields
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_iso.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_iso.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_iso.F90	(revision 4946)
@@ -22,7 +22,6 @@
    USE ldftra_oce      ! ocean tracer   lateral physics
    USE zdf_oce         ! ocean vertical physics
-   USE trdmod          ! ocean dynamics trends 
-   USE trdmod_oce      ! ocean variables trends
    USE ldfslp          ! iso-neutral slopes 
+   !
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE in_out_manager  ! I/O manager
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_lap.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_lap.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_lap.F90	(revision 4946)
@@ -19,8 +19,6 @@
    USE ldfdyn_oce      ! ocean dynamics: lateral physics
    USE zdf_oce         ! ocean vertical physics
+   !
    USE in_out_manager  ! I/O manager
-   USE trdmod          ! ocean dynamics trends 
-   USE trdmod_oce      ! ocean variables trends
-   USE ldfslp          ! iso-neutral slopes 
    USE timing          ! Timing
 
@@ -57,9 +55,6 @@
       !!      Add this before trend to the general trend (ua,va):
       !!            (ua,va) = (ua,va) + (diffu,diffv)
-      !!      'key_trddyn' activated: the two components of the horizontal
-      !!                                 diffusion trend are saved.
       !!
-      !! ** Action : - Update (ua,va) with the before iso-level harmonic 
-      !!               mixing trend.
+      !! ** Action : - Update (ua,va) with the iso-level harmonic mixing trend
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 4946)
@@ -18,4 +18,5 @@
    !!            3.3  !  2011-03  (P. Oddo) Bug fix for time-splitting+(BDY-OBC) and not VVL
    !!            3.5  !  2013-07  (J. Chanut) Compliant with time splitting changes
+   !!            3.7  !  2014-04  (G. Madec) add the diagnostic of the time filter trends
    !!-------------------------------------------------------------------------
   
@@ -34,14 +35,18 @@
    USE bdydyn          ! ocean open boundary conditions
    USE bdyvol          ! ocean open boundary condition (bdy_vol routines)
+   USE trd_oce         ! trends: ocean variables
+   USE trddyn          ! trend manager: dynamics
+   USE trdken          ! trend manager: kinetic energy
+   !
    USE in_out_manager  ! I/O manager
+   USE iom             ! I/O manager library
    USE lbclnk          ! lateral boundary condition (or mpp link)
    USE lib_mpp         ! MPP library
    USE wrk_nemo        ! Memory Allocation
    USE prtctl          ! Print control
-
+   USE timing          ! Timing
 #if defined key_agrif
    USE agrif_opa_interp
 #endif
-   USE timing          ! Timing
 
    IMPLICIT NONE
@@ -79,5 +84,5 @@
       !!             at the local domain boundaries through lbc_lnk call,
       !!             at the one-way open boundaries (lk_bdy=T),
-      !!             at the AGRIF zoom     boundaries (lk_agrif=T)
+      !!             at the AGRIF zoom   boundaries (lk_agrif=T)
       !!
       !!              * Apply the time filter applied and swap of the dynamics
@@ -99,14 +104,14 @@
       REAL(wp) ::   z2dt         ! temporary scalar
 #endif
-      REAL(wp) ::   zue3a, zue3n, zue3b, zuf, zec   ! local scalars
-      REAL(wp) ::   zve3a, zve3n, zve3b, zvf        !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:)   ::  zua, zva
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ze3u_f, ze3v_f 
+      REAL(wp) ::   zue3a, zue3n, zue3b, zuf, zec      ! local scalars
+      REAL(wp) ::   zve3a, zve3n, zve3b, zvf, z1_2dt   !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:)   ::  zue, zve
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ze3u_f, ze3v_f, zua, zva 
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_nxt')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk, ze3u_f, ze3v_f )
-      IF ( lk_dynspg_ts ) CALL wrk_alloc( jpi,jpj, zua, zva )
+      IF( nn_timing == 1 )   CALL timing_start('dyn_nxt')
+      !
+      CALL wrk_alloc( jpi,jpj,jpk,  ze3u_f, ze3v_f, zua, zva )
+      IF( lk_dynspg_ts )   CALL wrk_alloc( jpi,jpj, zue, zve )
       !
       IF( kt == nit000 ) THEN
@@ -152,15 +157,16 @@
 
 # if defined key_dynspg_ts
+!!gm IF ( lk_dynspg_ts ) THEN ....
       ! Ensure below that barotropic velocities match time splitting estimate
       ! Compute actual transport and replace it with ts estimate at "after" time step
-      zua(:,:) = 0._wp
-      zva(:,:) = 0._wp
-      DO jk = 1, jpkm1
-         zua(:,:) = zua(:,:) + fse3u_a(:,:,jk) * ua(:,:,jk) * umask(:,:,jk)
-         zva(:,:) = zva(:,:) + fse3v_a(:,:,jk) * va(:,:,jk) * vmask(:,:,jk)
+      zue(:,:) = fse3u_a(:,:,1) * ua(:,:,1) * umask(:,:,1)
+      zve(:,:) = fse3v_a(:,:,1) * va(:,:,1) * vmask(:,:,1)
+      DO jk = 2, jpkm1
+         zue(:,:) = zue(:,:) + fse3u_a(:,:,jk) * ua(:,:,jk) * umask(:,:,jk)
+         zve(:,:) = zve(:,:) + fse3v_a(:,:,jk) * va(:,:,jk) * vmask(:,:,jk)
       END DO
       DO jk = 1, jpkm1
-         ua(:,:,jk) = ( ua(:,:,jk) - zua(:,:) * hur_a(:,:) + ua_b(:,:) ) * umask(:,:,jk)
-         va(:,:,jk) = ( va(:,:,jk) - zva(:,:) * hvr_a(:,:) + va_b(:,:) ) * vmask(:,:,jk)
+         ua(:,:,jk) = ( ua(:,:,jk) - zue(:,:) * hur_a(:,:) + ua_b(:,:) ) * umask(:,:,jk)
+         va(:,:,jk) = ( va(:,:,jk) - zve(:,:) * hvr_a(:,:) + va_b(:,:) ) * vmask(:,:,jk)
       END DO
 
@@ -175,4 +181,5 @@
          END DO  
       ENDIF
+!!gm ENDIF
 # endif
 
@@ -195,4 +202,23 @@
 # endif
 #endif
+
+      IF( l_trddyn ) THEN             ! prepare the atf trend computation + some diagnostics
+         z1_2dt = 1._wp / (2. * rdt)        ! Euler or leap-frog time step 
+         IF( neuler == 0 .AND. kt == nit000 )   z1_2dt = 1._wp / rdt
+         !
+         !                                  ! Kinetic energy and Conversion
+         IF( ln_KE_trd  )   CALL trd_dyn( ua, va, jpdyn_ken, kt )
+         !
+         IF( ln_dyn_trd ) THEN              ! 3D output: total momentum trends
+            zua(:,:,:) = ( ua(:,:,:) - ub(:,:,:) ) * z1_2dt
+            zva(:,:,:) = ( va(:,:,:) - vb(:,:,:) ) * z1_2dt
+            CALL iom_put( "utrd_tot", zua )        ! total momentum trends, except the asselin time filter
+            CALL iom_put( "vtrd_tot", zva )
+         ENDIF
+         !
+         zua(:,:,:) = un(:,:,:)             ! save the now velocity before the asselin filter
+         zva(:,:,:) = vn(:,:,:)             ! (caution: there will be a shift by 1 timestep in the
+         !                                  !  computation of the asselin filter trends)
+      ENDIF
 
       ! Time filter and swap of dynamics arrays
@@ -217,6 +243,6 @@
                DO jj = 1, jpj
                   DO ji = 1, jpi    
-                     zuf = un(ji,jj,jk) + atfp * ( ub(ji,jj,jk) - 2.e0_wp * un(ji,jj,jk) + ua(ji,jj,jk) )
-                     zvf = vn(ji,jj,jk) + atfp * ( vb(ji,jj,jk) - 2.e0_wp * vn(ji,jj,jk) + va(ji,jj,jk) )
+                     zuf = un(ji,jj,jk) + atfp * ( ub(ji,jj,jk) - 2._wp * un(ji,jj,jk) + ua(ji,jj,jk) )
+                     zvf = vn(ji,jj,jk) + atfp * ( vb(ji,jj,jk) - 2._wp * vn(ji,jj,jk) + va(ji,jj,jk) )
                      !
                      ub(ji,jj,jk) = zuf                      ! ub <-- filtered velocity
@@ -301,13 +327,13 @@
             ! Revert "before" velocities to time split estimate
             ! Doing it here also means that asselin filter contribution is removed  
-            zua(:,:) = 0._wp
-            zva(:,:) = 0._wp
-            DO jk = 1, jpkm1
-               zua(:,:) = zua(:,:) + fse3u_b(:,:,jk) * ub(:,:,jk) * umask(:,:,jk)
-               zva(:,:) = zva(:,:) + fse3v_b(:,:,jk) * vb(:,:,jk) * vmask(:,:,jk)    
+            zue(:,:) = fse3u_b(:,:,1) * ub(:,:,1) * umask(:,:,1)
+            zve(:,:) = fse3v_b(:,:,1) * vb(:,:,1) * vmask(:,:,1)    
+            DO jk = 2, jpkm1
+               zue(:,:) = zue(:,:) + fse3u_b(:,:,jk) * ub(:,:,jk) * umask(:,:,jk)
+               zve(:,:) = zve(:,:) + fse3v_b(:,:,jk) * vb(:,:,jk) * vmask(:,:,jk)    
             END DO
             DO jk = 1, jpkm1
-               ub(:,:,jk) = ub(:,:,jk) - (zua(:,:) * hur(:,:) - un_b(:,:)) * umask(:,:,jk)
-               vb(:,:,jk) = vb(:,:,jk) - (zva(:,:) * hvr(:,:) - vn_b(:,:)) * vmask(:,:,jk)
+               ub(:,:,jk) = ub(:,:,jk) - (zue(:,:) * hur(:,:) - un_b(:,:)) * umask(:,:,jk)
+               vb(:,:,jk) = vb(:,:,jk) - (zve(:,:) * hvr(:,:) - vn_b(:,:)) * vmask(:,:,jk)
             END DO
          ENDIF
@@ -335,11 +361,6 @@
       !
       DO jk = 1, jpkm1
-#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                  
                un_b(ji,jj) = un_b(ji,jj) + fse3u_a(ji,jj,jk) * un(ji,jj,jk) * umask(ji,jj,jk)
                vn_b(ji,jj) = vn_b(ji,jj) + fse3v_a(ji,jj,jk) * vn(ji,jj,jk) * vmask(ji,jj,jk)
@@ -358,9 +379,16 @@
       !
       !
+
+      IF( l_trddyn ) THEN                ! 3D output: asselin filter trends on momentum
+         zua(:,:,:) = ( ub(:,:,:) - zua(:,:,:) ) * z1_2dt
+         zva(:,:,:) = ( vb(:,:,:) - zva(:,:,:) ) * z1_2dt
+         CALL trd_dyn( zua, zva, jpdyn_atf, kt )
+      ENDIF
+      !
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=un, clinfo1=' nxt  - Un: ', mask1=umask,   &
          &                       tab3d_2=vn, clinfo2=' Vn: '       , mask2=vmask )
       ! 
-      CALL wrk_dealloc( jpi,jpj,jpk, ze3u_f, ze3v_f )
-      IF ( lk_dynspg_ts ) CALL wrk_dealloc( jpi,jpj, zua, zva )
+      CALL wrk_dealloc( jpi,jpj,jpk,  ze3u_f, ze3v_f, zua, zva )
+      IF( lk_dynspg_ts )   CALL wrk_dealloc( jpi,jpj, zue, zve )
       !
       IF( nn_timing == 1 )  CALL timing_stop('dyn_nxt')
@@ -370,3 +398,2 @@
    !!=========================================================================
 END MODULE dynnxt
-
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 4946)
@@ -26,12 +26,13 @@
    USE sbctide
    USE updtide
-   USE trdmod         ! ocean dynamics trends
-   USE trdmod_oce     ! ocean variables trends
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
+   !
    USE prtctl         ! Print control                     (prt_ctl routine)
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! MPP library
-   USE solver          ! solver initialization
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   USE solver         ! solver initialization
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
 
@@ -163,5 +164,8 @@
                END DO
             END DO
-         END DO         
+         END DO    
+         
+!!gm add here a call to dyn_trd for ice pressure gradient, the surf pressure trends ????
+              
       ENDIF
 
@@ -191,9 +195,9 @@
          CASE( 2 )
             z2dt = 2. * rdt
-            IF( neuler == 0 .AND. kt == nit000 ) z2dt = rdt
+            IF( neuler == 0 .AND. kt == nit000 )   z2dt = rdt
             ztrdu(:,:,:) = ( ua(:,:,:) - ub(:,:,:) ) / z2dt - ztrdu(:,:,:)
             ztrdv(:,:,:) = ( va(:,:,:) - vb(:,:,:) ) / z2dt - ztrdv(:,:,:)
          END SELECT
-         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_spg, 'DYN', kt )
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_spg, kt )
          !
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90	(revision 4946)
@@ -19,4 +19,5 @@
    USE sbc_oce         ! surface boundary condition: ocean
    USE phycst          ! physical constants
+   !
    USE in_out_manager  ! I/O manager
    USE lib_mpp         ! distributed memory computing library
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_flt.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_flt.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_flt.F90	(revision 4946)
@@ -13,4 +13,5 @@
    !!             -   !  2006-08  (J.Chanut, A.Sellar) Calls to BDY routines. 
    !!            3.2  !  2009-03  (G. Madec, M. Leclair, R. Benshila) introduce sshwzv module
+   !!            3.7  !  2014-04  (F. Roquet, G. Madec)  add some trends diag
    !!----------------------------------------------------------------------
 #if defined key_dynspg_flt   ||   defined key_esopa  
@@ -36,4 +37,7 @@
    USE bdyvol          ! ocean open boundary condition (bdy_vol routine)
    USE cla             ! cross land advection
+   USE trd_oce         ! trends: ocean variables
+   USE trddyn          ! trend manager: dynamics
+   !
    USE in_out_manager  ! I/O manager
    USE lib_mpp         ! distributed memory computing library
@@ -43,8 +47,8 @@
    USE iom
    USE lib_fortran
+   USE timing          ! Timing
 #if defined key_agrif
    USE agrif_opa_interp
 #endif
-   USE timing          ! Timing
 
    IMPLICIT NONE
@@ -99,15 +103,16 @@
       !! ** Action : - Update (ua,va) with the surf. pressure gradient trend
       !!
-      !! References : Roullet and Madec 1999, JGR.
+      !! References : Roullet and Madec, JGR, 2000.
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
       INTEGER, INTENT(  out) ::   kindic   ! solver convergence flag (<0 if not converge)
-      !!                                   
+      !
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
       REAL(wp) ::   z2dt, z2dtg, zgcb, zbtd, ztdgu, ztdgv   ! local scalars
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdu, ztrdv
+      REAL(wp), POINTER, DIMENSION(:,:)   ::  zpw
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('dyn_spg_flt')
-      !
       !
       IF( kt == nit000 ) THEN
@@ -179,4 +184,17 @@
          END DO
          !
+         IF( l_trddyn )   THEN                      ! temporary save of spg trends
+            CALL wrk_alloc( jpi, jpj, jpk, ztrdu, ztrdv )
+            DO jk = 1, jpkm1              ! unweighted time stepping 
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+                     ztrdu(ji,jj,jk) = spgu(ji,jj) * umask(ji,jj,jk)
+                     ztrdv(ji,jj,jk) = spgv(ji,jj) * vmask(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_spgexp, kt )
+         ENDIF
+         !
       ENDIF
 
@@ -194,31 +212,18 @@
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vector opt.
-            spgu(ji,jj) = 0._wp
-            spgv(ji,jj) = 0._wp
-         END DO
-      END DO
-
-      ! vertical sum
-!CDIR NOLOOPCHG
-      IF( lk_vopt_loop ) THEN          ! vector opt., forced unroll
-         DO jk = 1, jpkm1
-            DO ji = 1, jpij
-               spgu(ji,1) = spgu(ji,1) + fse3u_a(ji,1,jk) * ua(ji,1,jk)
-               spgv(ji,1) = spgv(ji,1) + fse3v_a(ji,1,jk) * va(ji,1,jk)
-            END DO
-         END DO
-      ELSE                        ! No  vector opt.
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
-                  spgu(ji,jj) = spgu(ji,jj) + fse3u_a(ji,jj,jk) * ua(ji,jj,jk)
-                  spgv(ji,jj) = spgv(ji,jj) + fse3v_a(ji,jj,jk) * va(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-      ENDIF
-
-      ! transport: multiplied by the horizontal scale factor
-      DO jj = 2, jpjm1
+            spgu(ji,jj) = fse3u_a(ji,jj,1) * ua(ji,jj,1)
+            spgv(ji,jj) = fse3v_a(ji,jj,1) * va(ji,jj,1)
+         END DO
+      END DO
+      DO jk = 2, jpkm1                     ! vertical sum
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               spgu(ji,jj) = spgu(ji,jj) + fse3u_a(ji,jj,jk) * ua(ji,jj,jk)
+               spgv(ji,jj) = spgv(ji,jj) + fse3v_a(ji,jj,jk) * va(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      DO jj = 2, jpjm1                     ! transport: multiplied by the horizontal scale factor
          DO ji = fs_2, fs_jpim1   ! vector opt.
             spgu(ji,jj) = spgu(ji,jj) * e2u(ji,jj)
@@ -322,4 +327,26 @@
       ENDIF
 #endif      
+
+      IF( l_trddyn )   THEN                     
+         ztrdu(:,:,:) = ua(:,:,:)                 ! save the after velocity before the filtered SPG
+         ztrdv(:,:,:) = va(:,:,:)
+         !
+         CALL wrk_alloc( jpi, jpj, zpw )
+         !
+         zpw(:,:) = - z2dt * gcx(:,:)
+         CALL iom_put( "ssh_flt" , zpw )          ! output equivalent ssh modification due to implicit filter
+         !
+         !                                        ! save surface pressure flux: -pw at z=0
+         zpw(:,:) = - rau0 * grav * sshn(:,:) * wn(:,:,1) * tmask(:,:,1)
+         CALL iom_put( "pw0_exp" , zpw )
+         zpw(:,:) = wn(:,:,1)
+         CALL iom_put( "w0" , zpw )
+         zpw(:,:) =  rau0 * z2dtg * gcx(:,:) * wn(:,:,1) * tmask(:,:,1)
+         CALL iom_put( "pw0_flt" , zpw )
+         !
+         CALL wrk_dealloc( jpi, jpj, zpw ) 
+         !                                   
+      ENDIF
+      
       ! Add the trends multiplied by z2dt to the after velocity
       ! -------------------------------------------------------
@@ -336,10 +363,15 @@
       END DO
 
-      ! write filtered free surface arrays in restart file
-      ! --------------------------------------------------
-      IF( lrst_oce ) CALL flt_rst( kt, 'WRITE' )
-      !
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_spg_flt')
+      IF( l_trddyn )   THEN                      ! save the explicit SPG trends for further diagnostics
+         ztrdu(:,:,:) = ( ua(:,:,:) - ztrdu(:,:,:) ) / z2dt
+         ztrdv(:,:,:) = ( va(:,:,:) - ztrdv(:,:,:) ) / z2dt
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_spgflt, kt )
+         !
+         CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
+      ENDIF
+
+      IF( lrst_oce )   CALL flt_rst( kt, 'WRITE' )      ! write filtered free surface arrays in restart file
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('dyn_spg_flt')
       !
    END SUBROUTINE dyn_spg_flt
@@ -352,6 +384,6 @@
       !! ** Purpose : Read or write filtered free surface arrays in restart file
       !!----------------------------------------------------------------------
-      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
-      CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
+      INTEGER         , INTENT(in) ::   kt     ! ocean time-step
+      CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
       !!----------------------------------------------------------------------
       !
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 4946)
@@ -15,4 +15,5 @@
    !!            3.2  ! 2009-04  (R. Benshila)  vvl: correction of een scheme
    !!            3.3  ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
+   !!            3.7  ! 2014-04  (G. Madec) trend simplification: suppress jpdyn_trd_dat vorticity 
    !!----------------------------------------------------------------------
 
@@ -29,6 +30,6 @@
    USE dommsk         ! ocean mask
    USE dynadv         ! momentum advection (use ln_dynadv_vec value)
-   USE trdmod         ! ocean dynamics trends 
-   USE trdmod_oce     ! ocean variables trends
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
    USE prtctl         ! Print control
@@ -73,5 +74,6 @@
       !! ** Action : - Update (ua,va) with the now vorticity term trend
       !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
-      !!               and planetary vorticity trends) ('key_trddyn')
+      !!               and planetary vorticity trends) and send them to trd_dyn 
+      !!               for futher diagnostics (l_trddyn=T)
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
@@ -108,5 +110,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_rvo, kt )
             ztrdu(:,:,:) = ua(:,:,:)
             ztrdv(:,:,:) = va(:,:,:)
@@ -114,6 +116,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_pvo, 'DYN', kt )
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_dat, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_pvo, kt )
          ELSE
             CALL vor_ene( kt, ntot, ua, va )                ! total vorticity
@@ -127,5 +128,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_rvo, kt )
             ztrdu(:,:,:) = ua(:,:,:)
             ztrdv(:,:,:) = va(:,:,:)
@@ -133,6 +134,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_pvo, 'DYN', kt )
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_dat, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_pvo, kt )
          ELSE
             CALL vor_ens( kt, ntot, ua, va )                ! total vorticity
@@ -146,5 +146,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_rvo, kt )
             ztrdu(:,:,:) = ua(:,:,:)
             ztrdv(:,:,:) = va(:,:,:)
@@ -152,6 +152,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_pvo, 'DYN', kt )
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_dat, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_pvo, kt )
          ELSE
             CALL vor_mix( kt )                               ! total vorticity (mix=ens-ene)
@@ -165,5 +164,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_rvo, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_rvo, kt )
             ztrdu(:,:,:) = ua(:,:,:)
             ztrdv(:,:,:) = va(:,:,:)
@@ -171,6 +170,5 @@
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_pvo, 'DYN', kt )
-            CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_dat, 'DYN', kt )
+            CALL trd_dyn( ztrdu, ztrdv, jpdyn_pvo, kt )
          ELSE
             CALL vor_een( kt, ntot, ua, va )                ! total vorticity
@@ -211,6 +209,4 @@
       !!
       !! ** Action : - Update (ua,va) with the now vorticity term trend
-      !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
-      !!               and planetary vorticity trends) ('key_trddyn')
       !!
       !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
@@ -328,6 +324,4 @@
       !!
       !! ** Action : - Update (ua,va) arrays with the now vorticity term trend
-      !!             - Save the trends in (ztrdu,ztrdv) in 2 parts (relative
-      !!               and planetary vorticity trends) ('key_trddyn')
       !!
       !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
@@ -444,6 +438,4 @@
       !!
       !! ** Action : - Update (ua,va) arrays with the now vorticity term trend
-      !!             - Save the trends in (ztrdu,ztrdv) in 2 parts (relative 
-      !!               and planetary vorticity trends) ('key_trddyn')
       !!
       !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
@@ -557,6 +549,4 @@
       !!
       !! ** Action : - Update (ua,va) with the now vorticity term trend
-      !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
-      !!               and planetary vorticity trends) ('key_trddyn')
       !!
       !! References : Arakawa and Lamb 1980, Mon. Wea. Rev., 109, 18-36
@@ -601,5 +591,5 @@
             IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'dyn:vor_een : unable to allocate arrays' )
          ENDIF
-         ze3f(:,:,:) = 0.d0
+         ze3f(:,:,:) = 0._wp
 #endif
       ENDIF
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynzad.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynzad.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynzad.F90	(revision 4946)
@@ -16,11 +16,12 @@
    USE dom_oce        ! ocean space and time domain
    USE sbc_oce        ! surface boundary condition: ocean
-   USE trdmod_oce     ! ocean variables trends
-   USE trdmod         ! ocean dynamics trends 
+   USE trd_oce        ! trends: ocean variables
+   USE trddyn         ! trend manager: dynamics
+   !
    USE in_out_manager ! I/O manager
-   USE lib_mpp         ! MPP library
+   USE lib_mpp        ! MPP library
    USE prtctl         ! Print control
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -54,5 +55,5 @@
       !!
       !! ** Action  : - Update (ua,va) with the vert. momentum adv. trends
-      !!              - Save the trends in (ztrdu,ztrdv) ('key_trddyn')
+      !!              - Send the trends to trddyn for diagnostics (l_trddyn=T)
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step inedx
@@ -119,5 +120,5 @@
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_mod(ztrdu, ztrdv, jpdyn_trd_zad, 'DYN', kt)
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_zad, kt )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
       ENDIF
@@ -261,5 +262,5 @@
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_mod(ztrdu, ztrdv, jpdyn_trd_zad, 'DYN', kt)
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_zad, kt )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
       ENDIF
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf.F90	(revision 4946)
@@ -20,6 +20,6 @@
 
    USE ldfdyn_oce      ! ocean dynamics: lateral physics
-   USE trdmod          ! ocean active dynamics and tracers trends 
-   USE trdmod_oce      ! ocean variables trends
+   USE trd_oce         ! trends: ocean variables
+   USE trddyn          ! trend manager: dynamics
    USE in_out_manager  ! I/O manager
    USE lib_mpp         ! MPP library
@@ -91,6 +91,5 @@
          ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_mod( ztrdu, ztrdv, jpdyn_trd_zdf, 'DYN', kt )
-         !
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_zdf, kt )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
       ENDIF
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_imp.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_imp.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_imp.F90	(revision 4946)
@@ -70,6 +70,4 @@
       REAL(wp) ::   z1_p2dt, zcoef, zzwi, zzws, zrhs   ! local scalars
       REAL(wp) ::   ze3ua, ze3va
-      !!----------------------------------------------------------------------
-
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  zwi, zwd, zws
       !!----------------------------------------------------------------------
@@ -101,11 +99,6 @@
 
       IF( ln_bfrimp ) THEN
-# if defined key_vectopt_loop
-         DO jj = 1, 1
-            DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
-# else
          DO jj = 2, jpjm1
             DO ji = 2, jpim1
-# endif
                ikbu = mbku(ji,jj)       ! ocean bottom level at u- and v-points 
                ikbv = mbkv(ji,jj)       ! (deepest ocean u- and v-points)
@@ -142,5 +135,5 @@
             ua(:,:,jk) = (ua(:,:,jk) - ua_b(:,:)) * umask(:,:,jk)
             va(:,:,jk) = (va(:,:,jk) - va_b(:,:)) * vmask(:,:,jk)
-         ENDDO
+         END DO
          ! Add bottom/top stress due to barotropic component only:
          DO jj = 2, jpjm1        
@@ -220,6 +213,7 @@
                &                                      / ( ze3ua * rau0 ) 
 #else
-            ua(ji,jj,miku(ji,jj)) = ub(ji,jj,miku(ji,jj)) + p2dt *(ua(ji,jj,miku(ji,jj)) +  0.5_wp * ( utau_b(ji,jj) + utau(ji,jj) )   &
-               &                                                     / ( fse3u(ji,jj,miku(ji,jj)) * rau0     ) ) 
+            ua(ji,jj,miku(ji,jj)) = ub(ji,jj,miku(ji,jj)) &
+               &                   + p2dt *(ua(ji,jj,miku(ji,jj)) +  0.5_wp * ( utau_b(ji,jj) + utau(ji,jj) )   &
+               &                                  / ( fse3u(ji,jj,miku(ji,jj)) * rau0     ) ) 
 #endif
             DO jk = miku(ji,jj)+1, jpkm1
@@ -311,5 +305,6 @@
                &                                      / ( ze3va * rau0 ) 
 #else
-            va(ji,jj,mikv(ji,jj)) = vb(ji,jj,mikv(ji,jj)) + p2dt *(va(ji,jj,mikv(ji,jj)) +  0.5_wp * ( vtau_b(ji,jj) + vtau(ji,jj) )   &
+            va(ji,jj,mikv(ji,jj)) = vb(ji,jj,mikv(ji,jj)) &
+               &                   + p2dt *(va(ji,jj,mikv(ji,jj)) +  0.5_wp * ( vtau_b(ji,jj) + vtau(ji,jj) )   &
                &                                                       / ( fse3v(ji,jj,mikv(ji,jj)) * rau0     )  )
 #endif
@@ -348,11 +343,6 @@
       !! restore bottom layer avmu(v) 
       IF( ln_bfrimp ) THEN
-# if defined key_vectopt_loop
-        DO jj = 1, 1
-           DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
-# else
         DO jj = 2, jpjm1
            DO ji = 2, jpim1
-# endif
               ikbu = mbku(ji,jj)         ! ocean bottom level at u- and v-points 
               ikbv = mbkv(ji,jj)         ! (deepest ocean u- and v-points)
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 4946)
@@ -111,11 +111,12 @@
    INTEGER ::   numstp          =   -1      !: logical unit for time step
    INTEGER ::   numtime         =   -1      !: logical unit for timing
-   INTEGER ::   numout          =    6      !: logical unit for output print
+   INTEGER ::   numout          =    6      !: logical unit for output print; Set to stdout to ensure any early
+                                            !  output can be collected; do not change
    INTEGER ::   numnam_ref      =   -1      !: logical unit for reference namelist
    INTEGER ::   numnam_cfg      =   -1      !: logical unit for configuration specific namelist
-   INTEGER ::   numond          =    7      !: logical unit for Output Namelist Dynamics
+   INTEGER ::   numond          =   -1      !: logical unit for Output Namelist Dynamics
    INTEGER ::   numnam_ice_ref  =   -1      !: logical unit for ice reference namelist
    INTEGER ::   numnam_ice_cfg  =   -1      !: logical unit for ice reference namelist
-   INTEGER ::   numoni          =    8      !: logical unit for Output Namelist Ice
+   INTEGER ::   numoni          =   -1      !: logical unit for Output Namelist Ice
    INTEGER ::   numevo_ice      =   -1      !: logical unit for ice variables (temp. evolution)
    INTEGER ::   numsol          =   -1      !: logical unit for solver statistics
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 4946)
@@ -22,5 +22,5 @@
    USE iom             ! I/O module
    USE eosbn2          ! equation of state            (eos bn2 routine)
-   USE trdmld_oce      ! ocean active mixed layer tracers trends variables
+   USE trdmxl_oce      ! ocean active mixed layer tracers trends variables
    USE divcur          ! hor. divergence and curl      (div & cur routines)
    USE sbc_ice, ONLY : lk_lim3
@@ -140,13 +140,15 @@
 #endif
                   IF( lk_lim3 ) THEN
-                     CALL iom_rstput( kt, nitrst, numrow, 'iatte'  , iatte     ) !clem modif
-                     CALL iom_rstput( kt, nitrst, numrow, 'oatte'  , oatte     ) !clem modif
+                     CALL iom_rstput( kt, nitrst, numrow, 'fraqsr_1lev'  , fraqsr_1lev     ) !clem modif
                   ENDIF
       IF( kt == nitrst ) THEN
          CALL iom_close( numrow )     ! close the restart file (only at last time step)
-         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
+!!gm         IF( .NOT. lk_trdmld )   lrst_oce = .FALSE.
+!!gm  not sure what to do here   ===>>>  ask to Sebastian
+         lrst_oce = .FALSE.
       ENDIF
       !
    END SUBROUTINE rst_write
+
 
    SUBROUTINE rst_read_open
@@ -162,6 +164,6 @@
       LOGICAL  ::   llok
       !!----------------------------------------------------------------------
-
-      IF( numror .LE. 0 ) THEN
+      !
+      IF( numror <= 0 ) THEN
          IF(lwp) THEN                                             ! Contol prints
             WRITE(numout,*)
@@ -269,6 +271,5 @@
       !
       IF( lk_lim3 ) THEN
-         CALL iom_get( numror, jpdom_autoglo, 'iatte' , iatte ) ! clem modif
-         CALL iom_get( numror, jpdom_autoglo, 'oatte' , oatte ) ! clem modif
+         CALL iom_get( numror, jpdom_autoglo, 'fraqsr_1lev' , fraqsr_1lev )
       ENDIF
       !
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/LDF/ldfeiv.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/LDF/ldfeiv.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/LDF/ldfeiv.F90	(revision 4946)
@@ -84,22 +84,5 @@
       IF( ln_traldf_grif ) THEN
          DO jk = 1, jpk
-#  if defined key_vectopt_loop  
-!CDIR NOVERRCHK 
-            DO ji = 1, jpij   ! vector opt.
-               ! Take the max of N^2 and zero then take the vertical sum
-               ! of the square root of the resulting N^2 ( required to compute
-               ! internal Rossby radius Ro = .5 * sum_jpk(N) / f
-               zn2 = MAX( rn2b(ji,1,jk), 0._wp )
-               zn(ji,1) = zn(ji,1) + SQRT( zn2 ) * fse3w(ji,1,jk)
-               ! Compute elements required for the inverse time scale of baroclinic
-               ! eddies using the isopycnal slopes calculated in ldfslp.F :
-               ! T^-1 = sqrt(m_jpk(N^2*(r1^2+r2^2)*e3w))
-               ze3w = fse3w(ji,1,jk) * tmask(ji,1,jk)
-               zah(ji,1) = zah(ji,1) + zn2 * wslp2(ji,1,jk) * ze3w
-               zhw(ji,1) = zhw(ji,1) + ze3w
-            END DO
-#  else
             DO jj = 2, jpjm1
-!CDIR NOVERRCHK 
                DO ji = 2, jpim1
                   ! Take the max of N^2 and zero then take the vertical sum 
@@ -116,27 +99,8 @@
                END DO
             END DO
-#  endif
          END DO
       ELSE
          DO jk = 1, jpk
-#  if defined key_vectopt_loop  
-!CDIR NOVERRCHK 
-            DO ji = 1, jpij   ! vector opt.
-               ! Take the max of N^2 and zero then take the vertical sum
-               ! of the square root of the resulting N^2 ( required to compute
-               ! internal Rossby radius Ro = .5 * sum_jpk(N) / f
-               zn2 = MAX( rn2b(ji,1,jk), 0._wp )
-               zn(ji,1) = zn(ji,1) + SQRT( zn2 ) * fse3w(ji,1,jk)
-               ! Compute elements required for the inverse time scale of baroclinic
-               ! eddies using the isopycnal slopes calculated in ldfslp.F :
-               ! T^-1 = sqrt(m_jpk(N^2*(r1^2+r2^2)*e3w))
-               ze3w = fse3w(ji,1,jk) * tmask(ji,1,jk)
-               zah(ji,1) = zah(ji,1) + zn2 * ( wslpi(ji,1,jk) * wslpi(ji,1,jk)   &
-                  &                          + wslpj(ji,1,jk) * wslpj(ji,1,jk) ) * ze3w
-               zhw(ji,1) = zhw(ji,1) + ze3w
-            END DO
-#  else
             DO jj = 2, jpjm1
-!CDIR NOVERRCHK 
                DO ji = 2, jpim1
                   ! Take the max of N^2 and zero then take the vertical sum 
@@ -154,10 +118,8 @@
                END DO
             END DO
-#  endif
          END DO
       END IF
 
       DO jj = 2, jpjm1
-!CDIR NOVERRCHK 
          DO ji = fs_2, fs_jpim1   ! vector opt.
             zfw = MAX( ABS( 2. * omega * SIN( rad * gphit(ji,jj) ) ) , 1.e-10 )
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/LDF/ldfslp.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/LDF/ldfslp.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/LDF/ldfslp.F90	(revision 4946)
@@ -28,6 +28,7 @@
    USE zdfmxl         ! mixed layer depth
    USE eosbn2         ! equation of states
+   !
+   USE in_out_manager ! I/O manager
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE in_out_manager ! I/O manager
    USE prtctl         ! Print control
    USE wrk_nemo       ! work arrays
@@ -139,11 +140,6 @@
          END DO
          IF( ln_zps ) THEN                           ! partial steps correction at the bottom ocean level
-# if defined key_vectopt_loop
-            DO jj = 1, 1
-               DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
-# else
             DO jj = 1, jpjm1
                DO ji = 1, jpim1
-# endif
 ! IF should be useless check zpshde (PM)
                IF ( mbku(ji,jj) > 1 ) zgru(ji,jj,mbku(ji,jj)) = gru(ji,jj)
@@ -304,6 +300,8 @@
                   zfk = MAX( omlmask(ji,jj,jk), omlmask(ji,jj,jk-1) )    ! zfk=1 in the ML otherwise zfk=0
                   zck = ( fsdepw(ji,jj,jk) - fsdepw(ji,jj,mikt(ji,jj) ) ) / MAX( hmlp(ji,jj), 10._wp )
-                  zwz(ji,jj,jk) = (  zai / ( zbi - zeps ) * ( 1._wp - zfk ) + zck * wslpiml(ji,jj) * zfk  ) * tmask(ji,jj,jk) * tmask(ji,jj,jk-1)
-                  zww(ji,jj,jk) = (  zaj / ( zbj - zeps ) * ( 1._wp - zfk ) + zck * wslpjml(ji,jj) * zfk  ) * tmask(ji,jj,jk) * tmask(ji,jj,jk-1)
+                  zwz(ji,jj,jk) = (  zai / ( zbi - zeps ) * ( 1._wp - zfk ) &
+                     &            + zck * wslpiml(ji,jj) * zfk  ) * tmask(ji,jj,jk) * tmask(ji,jj,jk-1)
+                  zww(ji,jj,jk) = (  zaj / ( zbj - zeps ) * ( 1._wp - zfk ) &
+                     &            + zck * wslpjml(ji,jj) * zfk  ) * tmask(ji,jj,jk) * tmask(ji,jj,jk-1)
 
 !!gm  modif to suppress omlmask....  (as in Griffies operator)
@@ -415,6 +413,8 @@
                   uslp(ji,jj,jk) = -1./e1u(ji,jj) * ( fsdept_b(ji+1,jj,jk) - fsdept_b(ji ,jj ,jk) ) * umask(ji,jj,jk) 
                   vslp(ji,jj,jk) = -1./e2v(ji,jj) * ( fsdept_b(ji,jj+1,jk) - fsdept_b(ji ,jj ,jk) ) * vmask(ji,jj,jk) 
-                  wslpi(ji,jj,jk) = -1./e1t(ji,jj) * ( fsdepw_b(ji+1,jj,jk) - fsdepw_b(ji-1,jj,jk) ) * tmask(ji,jj,jk) * tmask(ji,jj,jk-1) * 0.5 
-                  wslpj(ji,jj,jk) = -1./e2t(ji,jj) * ( fsdepw_b(ji,jj+1,jk) - fsdepw_b(ji,jj-1,jk) ) * tmask(ji,jj,jk) * tmask(ji,jj,jk-1) * 0.5 
+                  wslpi(ji,jj,jk) = -1./e1t(ji,jj) * ( fsdepw_b(ji+1,jj,jk) - fsdepw_b(ji-1,jj,jk) ) &
+                    &                              * tmask(ji,jj,jk) * tmask(ji,jj,jk-1) * 0.5 
+                  wslpj(ji,jj,jk) = -1./e2t(ji,jj) * ( fsdepw_b(ji,jj+1,jk) - fsdepw_b(ji,jj-1,jk) ) &
+                    &                              * tmask(ji,jj,jk) * tmask(ji,jj,jk-1) * 0.5 
                END DO 
             END DO 
@@ -469,7 +469,5 @@
       REAL(wp) ::   zdyrho_raw, ztj_coord, ztj_raw, ztj_lim, ztj_g_raw, ztj_g_lim
       REAL(wp) ::   zdzrho_raw
-      REAL(wp) ::   zbeta0
       REAL(wp), POINTER, DIMENSION(:,:)     ::   z1_mlbw
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zalbet
       REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   zdxrho , zdyrho, zdzrho     ! Horizontal and vertical density gradients
       REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   zti_mlb, ztj_mlb            ! for Griffies operator only
@@ -479,5 +477,4 @@
       !
       CALL wrk_alloc( jpi,jpj, z1_mlbw )
-      CALL wrk_alloc( jpi,jpj,jpk, zalbet )
       CALL wrk_alloc( jpi,jpj,jpk,2, zdxrho , zdyrho, zdzrho,              klstart = 0  )
       CALL wrk_alloc( jpi,jpj,  2,2, zti_mlb, ztj_mlb,        kkstart = 0, klstart = 0  )
@@ -486,6 +483,4 @@
       !  Some preliminary calculation  !
       !--------------------------------!
-      !
-      CALL eos_alpbet( tsb, zalbet, zbeta0 )  !==  before local thermal/haline expension ratio at T-points  ==!
       !
       DO jl = 0, 1                            !==  unmasked before density i- j-, k-gradients  ==!
@@ -499,7 +494,7 @@
                   zdjt = ( tsb(ji,jj+1,jk,jp_tem) - tsb(ji,jj,jk,jp_tem) )    ! j-gradient of T & S at v-point
                   zdjs = ( tsb(ji,jj+1,jk,jp_sal) - tsb(ji,jj,jk,jp_sal) )
-                  zdxrho_raw = ( - zalbet(ji+ip,jj   ,jk) * zdit + zbeta0*zdis ) / e1u(ji,jj)
-                  zdyrho_raw = ( - zalbet(ji   ,jj+jp,jk) * zdjt + zbeta0*zdjs ) / e2v(ji,jj)
-                  zdxrho(ji+ip,jj   ,jk,1-ip) = SIGN( MAX(   repsln, ABS( zdxrho_raw ) ), zdxrho_raw )   ! keep the sign
+                  zdxrho_raw = ( - rab_b(ji+ip,jj   ,jk,jp_tem) * zdit + rab_b(ji+ip,jj   ,jk,jp_sal) * zdis ) / e1u(ji,jj)
+                  zdyrho_raw = ( - rab_b(ji   ,jj+jp,jk,jp_tem) * zdjt + rab_b(ji   ,jj+jp,jk,jp_sal) * zdjs ) / e2v(ji,jj)
+                  zdxrho(ji+ip,jj   ,jk,1-ip) = SIGN( MAX( repsln, ABS( zdxrho_raw ) ), zdxrho_raw )   ! keep the sign
                   zdyrho(ji   ,jj+jp,jk,1-jp) = SIGN( MAX( repsln, ABS( zdyrho_raw ) ), zdyrho_raw )
                END DO
@@ -507,17 +502,12 @@
          END DO
          !
-         IF( ln_zps.and.l_grad_zps ) THEN     ! partial steps: correction of i- & j-grad on bottom
-# if defined key_vectopt_loop
-            DO jj = 1, 1
-               DO ji = 1, jpij-jpi            ! vector opt. (forced unrolling)
-# else
+         IF( ln_zps .AND. l_grad_zps ) THEN     ! partial steps: correction of i- & j-grad on bottom
             DO jj = 1, jpjm1
                DO ji = 1, jpim1
-# endif
                   iku  = mbku(ji,jj)          ;   ikv  = mbkv(ji,jj)             ! last ocean level (u- & v-points)
                   zdit = gtsu(ji,jj,jp_tem)   ;   zdjt = gtsv(ji,jj,jp_tem)      ! i- & j-gradient of Temperature
                   zdis = gtsu(ji,jj,jp_sal)   ;   zdjs = gtsv(ji,jj,jp_sal)      ! i- & j-gradient of Salinity
-                  zdxrho_raw = ( - zalbet(ji+ip,jj   ,iku) * zdit + zbeta0*zdis ) / e1u(ji,jj)
-                  zdyrho_raw = ( - zalbet(ji   ,jj+jp,ikv) * zdjt + zbeta0*zdjs ) / e2v(ji,jj)
+                  zdxrho_raw = ( - rab_b(ji+ip,jj   ,iku,jp_tem) * zdit + rab_b(ji+ip,jj   ,iku,jp_sal) * zdis ) / e1u(ji,jj)
+                  zdyrho_raw = ( - rab_b(ji   ,jj+jp,ikv,jp_tem) * zdjt + rab_b(ji   ,jj+jp,ikv,jp_sal) * zdjs ) / e2v(ji,jj)
                   zdxrho(ji+ip,jj   ,iku,1-ip) = SIGN( MAX( repsln, ABS( zdxrho_raw ) ), zdxrho_raw )   ! keep the sign
                   zdyrho(ji   ,jj+jp,ikv,1-jp) = SIGN( MAX( repsln, ABS( zdyrho_raw ) ), zdyrho_raw )
@@ -539,6 +529,6 @@
                      zdks = 0._wp
                   ENDIF
-                  zdzrho_raw = ( - zalbet(ji   ,jj   ,jk) * zdkt + zbeta0*zdks ) / fse3w(ji,jj,jk+kp)
-                  zdzrho(ji   ,jj   ,jk,  kp) =     - MIN( - repsln,      zdzrho_raw )    ! force zdzrho >= repsln
+                  zdzrho_raw = ( - rab_b(ji,jj,jk,jp_tem) * zdkt + rab_b(ji,jj,jk,jp_sal) * zdks ) / fse3w(ji,jj,jk+kp)
+                  zdzrho(ji,jj,jk,kp) = - MIN( - repsln, zdzrho_raw )    ! force zdzrho >= repsln
                  END DO
             END DO
@@ -684,5 +674,4 @@
       !
       CALL wrk_dealloc( jpi,jpj, z1_mlbw )
-      CALL wrk_dealloc( jpi,jpj,jpk, zalbet )
       CALL wrk_dealloc( jpi,jpj,jpk,2, zdxrho , zdyrho, zdzrho,              klstart = 0  )
       CALL wrk_dealloc( jpi,jpj,  2,2, zti_mlb, ztj_mlb,        kkstart = 0, klstart = 0  )
@@ -735,11 +724,6 @@
       !                                            !==   surface mixed layer mask   !
       DO jk = 1, jpk                               ! =1 inside the mixed layer, =0 otherwise
-# if defined key_vectopt_loop
-         DO jj = 1, 1
-            DO ji = 1, jpij                        ! vector opt. (forced unrolling)
-# else
          DO jj = 1, jpj
             DO ji = 1, jpi
-# endif
                ik = nmln(ji,jj) - 1
                IF( jk <= ik .AND. jk >= mikt(ji,jj) ) THEN   ;   omlmask(ji,jj,jk) = 1._wp
@@ -761,11 +745,6 @@
       !-----------------------------------------------------------------------
       !
-# if defined key_vectopt_loop
-      DO jj = 1, 1
-         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
-# else
       DO jj = 2, jpjm1
          DO ji = 2, jpim1
-# endif
             !                        !==   Slope at u- & v-points just below the Mixed Layer   ==!
             !
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90	(revision 4946)
@@ -2,6 +2,5 @@
    !!======================================================================
    !!                    ***  MODULE cpl_oasis  ***
-   !! Coupled O/A : coupled ocean-atmosphere case using OASIS3 V. prism_2_4
-   !!               special case: NEMO OPA/LIM coupled to ECHAM5
+   !! Coupled O/A : coupled ocean-atmosphere case using OASIS3-MCT
    !!=====================================================================
    !! History :   
@@ -15,19 +14,16 @@
    !!   3.4  !  11-11  (C. Harris) Changes to allow mutiple category fields
    !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   'key_oasis3'                    coupled Ocean/Atmosphere via OASIS3
+   !!----------------------------------------------------------------------
+   !!   cpl_init     : initialization of coupled mode communication
+   !!   cpl_define   : definition of grid and fields
+   !!   cpl_snd     : snd out fields in coupled mode
+   !!   cpl_rcv     : receive fields in coupled mode
+   !!   cpl_finalize : finalize the coupled mode communication
+   !!----------------------------------------------------------------------
 #if defined key_oasis3
-   !!----------------------------------------------------------------------
-   !!   'key_oasis3'                    coupled Ocean/Atmosphere via OASIS3
-   !!----------------------------------------------------------------------
-   !!   cpl_prism_init     : initialization of coupled mode communication
-   !!   cpl_prism_define   : definition of grid and fields
-   !!   cpl_prism_snd     : snd out fields in coupled mode
-   !!   cpl_prism_rcv     : receive fields in coupled mode
-   !!   cpl_prism_finalize : finalize the coupled mode communication
-   !!----------------------------------------------------------------------
-   USE mod_prism_proto              ! OASIS3 prism module
-   USE mod_prism_def_partition_proto! OASIS3 prism module for partitioning
-   USE mod_prism_put_proto          ! OASIS3 prism module for snding
-   USE mod_prism_get_proto          ! OASIS3 prism module for receiving
-   USE mod_comprism_proto           ! OASIS3 prism module to get coupling frequency
+   USE mod_oasis                    ! OASIS3-MCT module
+#endif
    USE par_oce                      ! ocean parameters
    USE dom_oce                      ! ocean space and time domain
@@ -38,18 +34,34 @@
    PRIVATE
 
-   PUBLIC   cpl_prism_init
-   PUBLIC   cpl_prism_define
-   PUBLIC   cpl_prism_snd
-   PUBLIC   cpl_prism_rcv
-   PUBLIC   cpl_prism_freq
-   PUBLIC   cpl_prism_finalize
-
-   LOGICAL, PUBLIC, PARAMETER ::   lk_cpl = .TRUE.   !: coupled flag
+   PUBLIC   cpl_init
+   PUBLIC   cpl_define
+   PUBLIC   cpl_snd
+   PUBLIC   cpl_rcv
+   PUBLIC   cpl_freq
+   PUBLIC   cpl_finalize
+
    INTEGER, PUBLIC            ::   OASIS_Rcv  = 1    !: return code if received field
    INTEGER, PUBLIC            ::   OASIS_idle = 0    !: return code if nothing done by oasis
-   INTEGER                    ::   ncomp_id          ! id returned by prism_init_comp
+   INTEGER                    ::   ncomp_id          ! id returned by oasis_init_comp
    INTEGER                    ::   nerror            ! return error code
-
-   INTEGER, PARAMETER ::   nmaxfld=40    ! Maximum number of coupling fields
+#if ! defined key_oasis3
+   ! OASIS Variables not used. defined only for compilation purpose
+   INTEGER                    ::   OASIS_Out         = -1
+   INTEGER                    ::   OASIS_REAL        = -1
+   INTEGER                    ::   OASIS_Ok          = -1
+   INTEGER                    ::   OASIS_In          = -1
+   INTEGER                    ::   OASIS_Sent        = -1
+   INTEGER                    ::   OASIS_SentOut     = -1
+   INTEGER                    ::   OASIS_ToRest      = -1
+   INTEGER                    ::   OASIS_ToRestOut   = -1
+   INTEGER                    ::   OASIS_Recvd       = -1
+   INTEGER                    ::   OASIS_RecvOut     = -1
+   INTEGER                    ::   OASIS_FromRest    = -1
+   INTEGER                    ::   OASIS_FromRestOut = -1
+#endif
+
+   INTEGER, PUBLIC, PARAMETER ::   nmaxfld=40        ! Maximum number of coupling fields
+   INTEGER, PUBLIC, PARAMETER ::   nmaxcat=5    ! Maximum number of coupling fields
+   INTEGER, PUBLIC, PARAMETER ::   nmaxcpl=5    ! Maximum number of coupling fields
    
    TYPE, PUBLIC ::   FLD_CPL               !: Type for coupling field information
@@ -58,6 +70,7 @@
       CHARACTER(len = 1)    ::   clgrid    ! Grid type  
       REAL(wp)              ::   nsgn      ! Control of the sign change
-      INTEGER, DIMENSION(9) ::   nid       ! Id of the field (no more than 9 categories)
+      INTEGER, DIMENSION(nmaxcat,nmaxcpl) ::   nid   ! Id of the field (no more than 9 categories and 9 extrena models)
       INTEGER               ::   nct       ! Number of categories in field
+      INTEGER               ::   ncplmodel ! Maximum number of models to/from which this variable may be sent/received
    END TYPE FLD_CPL
 
@@ -73,7 +86,7 @@
 CONTAINS
 
-   SUBROUTINE cpl_prism_init( kl_comm )
+   SUBROUTINE cpl_init( kl_comm )
       !!-------------------------------------------------------------------
-      !!             ***  ROUTINE cpl_prism_init  ***
+      !!             ***  ROUTINE cpl_init  ***
       !!
       !! ** Purpose :   Initialize coupled mode communication for ocean
@@ -89,9 +102,9 @@
 
       !------------------------------------------------------------------
-      ! 1st Initialize the PRISM system for the application
+      ! 1st Initialize the OASIS system for the application
       !------------------------------------------------------------------
-      CALL prism_init_comp_proto ( ncomp_id, 'oceanx', nerror )
-      IF ( nerror /= PRISM_Ok ) &
-         CALL prism_abort_proto (ncomp_id, 'cpl_prism_init', 'Failure in prism_init_comp_proto')
+      CALL oasis_init_comp ( ncomp_id, 'oceanx', nerror )
+      IF ( nerror /= OASIS_Ok ) &
+         CALL oasis_abort (ncomp_id, 'cpl_init', 'Failure in oasis_init_comp')
 
       !------------------------------------------------------------------
@@ -99,14 +112,14 @@
       !------------------------------------------------------------------
 
-      CALL prism_get_localcomm_proto ( kl_comm, nerror )
-      IF ( nerror /= PRISM_Ok ) &
-         CALL prism_abort_proto (ncomp_id, 'cpl_prism_init','Failure in prism_get_localcomm_proto' )
-      !
-   END SUBROUTINE cpl_prism_init
-
-
-   SUBROUTINE cpl_prism_define( krcv, ksnd )
+      CALL oasis_get_localcomm ( kl_comm, nerror )
+      IF ( nerror /= OASIS_Ok ) &
+         CALL oasis_abort (ncomp_id, 'cpl_init','Failure in oasis_get_localcomm' )
+      !
+   END SUBROUTINE cpl_init
+
+
+   SUBROUTINE cpl_define( krcv, ksnd, kcplmodel )
       !!-------------------------------------------------------------------
-      !!             ***  ROUTINE cpl_prism_define  ***
+      !!             ***  ROUTINE cpl_define  ***
       !!
       !! ** Purpose :   Define grid and field information for ocean
@@ -116,17 +129,22 @@
       !!--------------------------------------------------------------------
       INTEGER, INTENT(in) ::   krcv, ksnd     ! Number of received and sent coupling fields
+      INTEGER, INTENT(in) ::   kcplmodel      ! Maximum number of models to/from which NEMO is potentialy sending/receiving data
       !
       INTEGER :: id_part
       INTEGER :: paral(5)       ! OASIS3 box partition
       INTEGER :: ishape(2,2)    ! shape of arrays passed to PSMILe
-      INTEGER :: ji,jc          ! local loop indicees
-      CHARACTER(LEN=8) :: zclname
+      INTEGER :: ji,jc,jm       ! local loop indicees
+      CHARACTER(LEN=64) :: zclname
+      CHARACTER(LEN=2) :: cli2
       !!--------------------------------------------------------------------
 
       IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'cpl_prism_define : initialization in coupled ocean/atmosphere case'
+      IF(lwp) WRITE(numout,*) 'cpl_define : initialization in coupled ocean/atmosphere case'
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
       IF(lwp) WRITE(numout,*)
 
+      IF( kcplmodel > nmaxcpl ) THEN
+         CALL oasis_abort ( ncomp_id, 'cpl_define', 'kcplmodel is larger than nmaxcpl, increase nmaxcpl')   ;   RETURN
+      ENDIF
       !
       ! ... Define the shape for the area that excludes the halo
@@ -141,5 +159,5 @@
       ALLOCATE(exfld(nlei-nldi+1, nlej-nldj+1), stat = nerror)
       IF( nerror > 0 ) THEN
-         CALL prism_abort_proto ( ncomp_id, 'cpl_prism_define', 'Failure in allocating exfld')   ;   RETURN
+         CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in allocating exfld')   ;   RETURN
       ENDIF
       !
@@ -161,23 +179,47 @@
       ENDIF
       
-      CALL prism_def_partition_proto ( id_part, paral, nerror )
+      CALL oasis_def_partition ( id_part, paral, nerror )
       !
       ! ... Announce send variables. 
       !
+      ssnd(:)%ncplmodel = kcplmodel
+      !
       DO ji = 1, ksnd
-         IF ( ssnd(ji)%laction ) THEN 
+         IF ( ssnd(ji)%laction ) THEN
+
+            IF( ssnd(ji)%nct > nmaxcat ) THEN
+               CALL oasis_abort ( ncomp_id, 'cpl_define', 'Number of categories of '//   &
+                  &              TRIM(ssnd(ji)%clname)//' is larger than nmaxcat, increase nmaxcat' )
+               RETURN
+            ENDIF
+            
             DO jc = 1, ssnd(ji)%nct
-               IF ( ssnd(ji)%nct .gt. 1 ) THEN
-                  WRITE(zclname,'( a7, i1)') ssnd(ji)%clname,jc
-               ELSE
-                  zclname=ssnd(ji)%clname
-               ENDIF
-               WRITE(numout,*) "Define",ji,jc,zclname," for",PRISM_Out
-               CALL prism_def_var_proto (ssnd(ji)%nid(jc), zclname, id_part, (/ 2, 0/),   &
-                    PRISM_Out, ishape, PRISM_REAL, nerror)
-               IF ( nerror /= PRISM_Ok ) THEN
-                  WRITE(numout,*) 'Failed to define transient ', ji, TRIM(zclname)
-                  CALL prism_abort_proto ( ssnd(ji)%nid(jc), 'cpl_prism_define', 'Failure in prism_def_var')
-               ENDIF
+               DO jm = 1, kcplmodel
+
+                  IF ( ssnd(ji)%nct .GT. 1 ) THEN
+                     WRITE(cli2,'(i2.2)') jc
+                     zclname = TRIM(ssnd(ji)%clname)//'_cat'//cli2
+                  ELSE
+                     zclname = ssnd(ji)%clname
+                  ENDIF
+                  IF ( kcplmodel  > 1 ) THEN
+                     WRITE(cli2,'(i2.2)') jm
+                     zclname = 'model'//cli2//'_'//TRIM(zclname)
+                  ENDIF
+#if defined key_agrif
+                  IF( agrif_fixed() /= 0 ) THEN 
+                     zclname=TRIM(Agrif_CFixed())//'_'//TRIM(zclname)
+                  END IF
+#endif
+                  IF( ln_ctl ) WRITE(numout,*) "Define", ji, jc, jm, " "//TRIM(zclname), " for ", OASIS_Out
+                  CALL oasis_def_var (ssnd(ji)%nid(jc,jm), zclname, id_part   , (/ 2, 0 /),   &
+                     &                OASIS_Out          , ishape , OASIS_REAL, nerror )
+                  IF ( nerror /= OASIS_Ok ) THEN
+                     WRITE(numout,*) 'Failed to define transient ', ji, jc, jm, " "//TRIM(zclname)
+                     CALL oasis_abort ( ssnd(ji)%nid(jc,jm), 'cpl_define', 'Failure in oasis_def_var' )
+                  ENDIF
+                  IF( ln_ctl .AND. ssnd(ji)%nid(jc,jm) /= -1 ) WRITE(numout,*) "variable defined in the namcouple"
+                  IF( ln_ctl .AND. ssnd(ji)%nid(jc,jm) == -1 ) WRITE(numout,*) "variable NOT defined in the namcouple"
+               END DO
             END DO
          ENDIF
@@ -188,17 +230,40 @@
       DO ji = 1, krcv
          IF ( srcv(ji)%laction ) THEN 
+            
+            IF( srcv(ji)%nct > nmaxcat ) THEN
+               CALL oasis_abort ( ncomp_id, 'cpl_define', 'Number of categories of '//   &
+                  &              TRIM(srcv(ji)%clname)//' is larger than nmaxcat, increase nmaxcat' )
+               RETURN
+            ENDIF
+            
             DO jc = 1, srcv(ji)%nct
-               IF ( srcv(ji)%nct .gt. 1 ) THEN
-                  WRITE(zclname,'( a7, i1)') srcv(ji)%clname,jc
-               ELSE
-                  zclname=srcv(ji)%clname
-               ENDIF
-               WRITE(numout,*) "Define",ji,jc,zclname," for",PRISM_In
-               CALL prism_def_var_proto ( srcv(ji)%nid(jc), zclname, id_part, (/ 2, 0/),   &
-                    &                      PRISM_In    , ishape   , PRISM_REAL, nerror)
-               IF ( nerror /= PRISM_Ok ) THEN
-                  WRITE(numout,*) 'Failed to define transient ', ji, TRIM(zclname)
-                  CALL prism_abort_proto ( srcv(ji)%nid(jc), 'cpl_prism_define', 'Failure in prism_def_var')
-               ENDIF
+               DO jm = 1, kcplmodel
+                  
+                  IF ( srcv(ji)%nct .GT. 1 ) THEN
+                     WRITE(cli2,'(i2.2)') jc
+                     zclname = TRIM(srcv(ji)%clname)//'_cat'//cli2
+                  ELSE
+                     zclname = srcv(ji)%clname
+                  ENDIF
+                  IF ( kcplmodel  > 1 ) THEN
+                     WRITE(cli2,'(i2.2)') jm
+                     zclname = 'model'//cli2//'_'//TRIM(zclname)
+                  ENDIF
+#if defined key_agrif
+                  IF( agrif_fixed() /= 0 ) THEN 
+                     zclname=TRIM(Agrif_CFixed())//'_'//TRIM(zclname)
+                  END IF
+#endif
+                  IF( ln_ctl ) WRITE(numout,*) "Define", ji, jc, jm, " "//TRIM(zclname), " for ", OASIS_In
+                  CALL oasis_def_var (srcv(ji)%nid(jc,jm), zclname, id_part   , (/ 2, 0 /),   &
+                     &                OASIS_In           , ishape , OASIS_REAL, nerror )
+                  IF ( nerror /= OASIS_Ok ) THEN
+                     WRITE(numout,*) 'Failed to define transient ', ji, jc, jm, " "//TRIM(zclname)
+                     CALL oasis_abort ( srcv(ji)%nid(jc,jm), 'cpl_define', 'Failure in oasis_def_var' )
+                  ENDIF
+                  IF( ln_ctl .AND. srcv(ji)%nid(jc,jm) /= -1 ) WRITE(numout,*) "variable defined in the namcouple"
+                  IF( ln_ctl .AND. srcv(ji)%nid(jc,jm) == -1 ) WRITE(numout,*) "variable NOT defined in the namcouple"
+
+               END DO
             END DO
          ENDIF
@@ -209,13 +274,13 @@
       !------------------------------------------------------------------
       
-      CALL prism_enddef_proto(nerror)
-      IF( nerror /= PRISM_Ok )   CALL prism_abort_proto ( ncomp_id, 'cpl_prism_define', 'Failure in prism_enddef')
-      !
-   END SUBROUTINE cpl_prism_define
+      CALL oasis_enddef(nerror)
+      IF( nerror /= OASIS_Ok )   CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in oasis_enddef')
+      !
+   END SUBROUTINE cpl_define
    
    
-   SUBROUTINE cpl_prism_snd( kid, kstep, pdata, kinfo )
+   SUBROUTINE cpl_snd( kid, kstep, pdata, kinfo )
       !!---------------------------------------------------------------------
-      !!              ***  ROUTINE cpl_prism_snd  ***
+      !!              ***  ROUTINE cpl_snd  ***
       !!
       !! ** Purpose : - At each coupling time-step,this routine sends fields
@@ -227,5 +292,5 @@
       REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdata
       !!
-      INTEGER                                   ::   jc        ! local loop index
+      INTEGER                                   ::   jc,jm     ! local loop index
       !!--------------------------------------------------------------------
       !
@@ -233,30 +298,35 @@
       !
       DO jc = 1, ssnd(kid)%nct
-
-         CALL prism_put_proto ( ssnd(kid)%nid(jc), kstep, pdata(nldi:nlei, nldj:nlej,jc), kinfo )
-         
-         IF ( ln_ctl ) THEN        
-            IF ( kinfo == PRISM_Sent     .OR. kinfo == PRISM_ToRest .OR.   &
-                 & kinfo == PRISM_SentOut  .OR. kinfo == PRISM_ToRestOut ) THEN
-               WRITE(numout,*) '****************'
-               WRITE(numout,*) 'prism_put_proto: Outgoing ', ssnd(kid)%clname
-               WRITE(numout,*) 'prism_put_proto: ivarid ', ssnd(kid)%nid(jc)
-               WRITE(numout,*) 'prism_put_proto:  kstep ', kstep
-               WRITE(numout,*) 'prism_put_proto:   info ', kinfo
-               WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
-               WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
-               WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
-               WRITE(numout,*) '****************'
+         DO jm = 1, ssnd(kid)%ncplmodel
+        
+            IF( ssnd(kid)%nid(jc,jm) /= -1 ) THEN
+               CALL oasis_put ( ssnd(kid)%nid(jc,jm), kstep, pdata(nldi:nlei, nldj:nlej,jc), kinfo )
+               
+               IF ( ln_ctl ) THEN        
+                  IF ( kinfo == OASIS_Sent     .OR. kinfo == OASIS_ToRest .OR.   &
+                     & kinfo == OASIS_SentOut  .OR. kinfo == OASIS_ToRestOut ) THEN
+                     WRITE(numout,*) '****************'
+                     WRITE(numout,*) 'oasis_put: Outgoing ', ssnd(kid)%clname
+                     WRITE(numout,*) 'oasis_put: ivarid ', ssnd(kid)%nid(jc,jm)
+                     WRITE(numout,*) 'oasis_put:  kstep ', kstep
+                     WRITE(numout,*) 'oasis_put:   info ', kinfo
+                     WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
+                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
+                     WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
+                     WRITE(numout,*) '****************'
+                  ENDIF
+               ENDIF
+               
             ENDIF
-         ENDIF
-
+            
+         ENDDO
       ENDDO
       !
-    END SUBROUTINE cpl_prism_snd
-
-
-   SUBROUTINE cpl_prism_rcv( kid, kstep, pdata, kinfo )
+    END SUBROUTINE cpl_snd
+
+
+   SUBROUTINE cpl_rcv( kid, kstep, pdata, pmask, kinfo )
       !!---------------------------------------------------------------------
-      !!              ***  ROUTINE cpl_prism_rcv  ***
+      !!              ***  ROUTINE cpl_rcv  ***
       !!
       !! ** Purpose : - At each coupling time-step,this routine receives fields
@@ -266,100 +336,174 @@
       INTEGER                   , INTENT(in   ) ::   kstep     ! ocean time-step in seconds
       REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdata     ! IN to keep the value if nothing is done
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pmask     ! coupling mask
       INTEGER                   , INTENT(  out) ::   kinfo     ! OASIS3 info argument
       !!
-      INTEGER                                   ::   jc        ! local loop index
-      LOGICAL                                   ::   llaction
+      INTEGER                                   ::   jc,jm     ! local loop index
+      LOGICAL                                   ::   llaction, llfisrt
       !!--------------------------------------------------------------------
       !
       ! receive local data from OASIS3 on every process
       !
+      kinfo = OASIS_idle
+      !
       DO jc = 1, srcv(kid)%nct
-
-         CALL prism_get_proto ( srcv(kid)%nid(jc), kstep, exfld, kinfo )         
-         
-         llaction = .false.
-         IF( kinfo == PRISM_Recvd   .OR. kinfo == PRISM_FromRest .OR.   &
-              kinfo == PRISM_RecvOut .OR. kinfo == PRISM_FromRestOut )   llaction = .TRUE.
-         
-         IF ( ln_ctl )   WRITE(numout,*) "llaction, kinfo, kstep, ivarid: " , llaction, kinfo, kstep, srcv(kid)%nid(jc)
-         
-         IF ( llaction ) THEN
+         llfisrt = .TRUE.
+
+         DO jm = 1, srcv(kid)%ncplmodel
+
+            IF( srcv(kid)%nid(jc,jm) /= -1 ) THEN
+
+               CALL oasis_get ( srcv(kid)%nid(jc,jm), kstep, exfld, kinfo )         
+               
+               llaction =  kinfo == OASIS_Recvd   .OR. kinfo == OASIS_FromRest .OR.   &
+                  &        kinfo == OASIS_RecvOut .OR. kinfo == OASIS_FromRestOut
+               
+               IF ( ln_ctl )   WRITE(numout,*) "llaction, kinfo, kstep, ivarid: " , llaction, kinfo, kstep, srcv(kid)%nid(jc,jm)
+               
+               IF ( llaction ) THEN
+                  
+                  kinfo = OASIS_Rcv
+                  IF( llfisrt ) THEN 
+                     pdata(nldi:nlei,nldj:nlej,jc) =                                 exfld(:,:) * pmask(nldi:nlei,nldj:nlej,jm)
+                     llfisrt = .FALSE.
+                  ELSE
+                     pdata(nldi:nlei,nldj:nlej,jc) = pdata(nldi:nlei,nldj:nlej,jc) + exfld(:,:) * pmask(nldi:nlei,nldj:nlej,jm)
+                  ENDIF
+                  
+                  IF ( ln_ctl ) THEN        
+                     WRITE(numout,*) '****************'
+                     WRITE(numout,*) 'oasis_get: Incoming ', srcv(kid)%clname
+                     WRITE(numout,*) 'oasis_get: ivarid '  , srcv(kid)%nid(jc,jm)
+                     WRITE(numout,*) 'oasis_get:   kstep', kstep
+                     WRITE(numout,*) 'oasis_get:   info ', kinfo
+                     WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
+                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
+                     WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
+                     WRITE(numout,*) '****************'
+                  ENDIF
+                  
+               ENDIF
+               
+            ENDIF
             
-            pdata(nldi:nlei, nldj:nlej,jc) = exfld(:,:)
-            
-            !--- Fill the overlap areas and extra hallows (mpp)
-            !--- check periodicity conditions (all cases)
-            CALL lbc_lnk( pdata(:,:,jc), srcv(kid)%clgrid, srcv(kid)%nsgn )   
-            
-            IF ( ln_ctl ) THEN        
-               WRITE(numout,*) '****************'
-               WRITE(numout,*) 'prism_get_proto: Incoming ', srcv(kid)%clname
-               WRITE(numout,*) 'prism_get_proto: ivarid '  , srcv(kid)%nid(jc)
-               WRITE(numout,*) 'prism_get_proto:   kstep', kstep
-               WRITE(numout,*) 'prism_get_proto:   info ', kinfo
-               WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
-               WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
-               WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
-               WRITE(numout,*) '****************'
-            ENDIF
-
-            ! Ideally we would not reuse kinfo, but define a separate variable
-            ! for use as the return code from this routine to avoid confusion
-            ! with the return code previously obtained from the coupler.
-            kinfo = OASIS_Rcv
-            
-         ELSE
-            kinfo = OASIS_idle     
-         ENDIF
-         
+         ENDDO
+
+         !--- Fill the overlap areas and extra hallows (mpp)
+         !--- check periodicity conditions (all cases)
+         IF( .not. llfisrt )   CALL lbc_lnk( pdata(:,:,jc), srcv(kid)%clgrid, srcv(kid)%nsgn )   
+ 
       ENDDO
       !
-   END SUBROUTINE cpl_prism_rcv
-
-
-   INTEGER FUNCTION cpl_prism_freq( kid )  
+   END SUBROUTINE cpl_rcv
+
+
+   INTEGER FUNCTION cpl_freq( kid )  
       !!---------------------------------------------------------------------
-      !!              ***  ROUTINE cpl_prism_freq  ***
+      !!              ***  ROUTINE cpl_freq  ***
       !!
       !! ** Purpose : - send back the coupling frequency for a particular field
       !!----------------------------------------------------------------------
-      INTEGER,INTENT(in) ::   kid   ! variable index 
+      INTEGER,INTENT(in) ::   kid   ! variable index
+      !!
+      INTEGER :: info
       !!----------------------------------------------------------------------
-      cpl_prism_freq = ig_def_freq( kid )
-      !
-   END FUNCTION cpl_prism_freq
-
-
-   SUBROUTINE cpl_prism_finalize
+      CALL oasis_get_freqs(kid, 1, cpl_freq, info)
+      !
+   END FUNCTION cpl_freq
+
+
+   SUBROUTINE cpl_finalize
       !!---------------------------------------------------------------------
-      !!              ***  ROUTINE cpl_prism_finalize  ***
+      !!              ***  ROUTINE cpl_finalize  ***
       !!
       !! ** Purpose : - Finalizes the coupling. If MPI_init has not been
-      !!      called explicitly before cpl_prism_init it will also close
+      !!      called explicitly before cpl_init it will also close
       !!      MPI communication.
       !!----------------------------------------------------------------------
       !
       DEALLOCATE( exfld )
-      CALL prism_terminate_proto( nerror )         
-      !
-   END SUBROUTINE cpl_prism_finalize
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default case          Dummy module          Forced Ocean/Atmosphere
-   !!----------------------------------------------------------------------
-   USE in_out_manager               ! I/O manager
-   LOGICAL, PUBLIC, PARAMETER :: lk_cpl = .FALSE.   !: coupled flag
-   PUBLIC cpl_prism_init
-   PUBLIC cpl_prism_finalize
-CONTAINS
-   SUBROUTINE cpl_prism_init (kl_comm) 
-      INTEGER, INTENT(out)   :: kl_comm       ! local communicator of the model
-      kl_comm = -1
-      WRITE(numout,*) 'cpl_prism_init: Error you sould not be there...'
-   END SUBROUTINE cpl_prism_init
-   SUBROUTINE cpl_prism_finalize
-      WRITE(numout,*) 'cpl_prism_finalize: Error you sould not be there...'
-   END SUBROUTINE cpl_prism_finalize
+      IF (nstop == 0) THEN
+         CALL oasis_terminate( nerror )         
+      ELSE
+         CALL oasis_abort( ncomp_id, "cpl_finalize", "NEMO ABORT STOP" )
+      ENDIF       
+      !
+   END SUBROUTINE cpl_finalize
+
+#if ! defined key_oasis3
+
+   !!----------------------------------------------------------------------
+   !!   No OASIS Library          OASIS3 Dummy module...
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE oasis_init_comp(k1,cd1,k2)
+      CHARACTER(*), INTENT(in   ) ::  cd1
+      INTEGER     , INTENT(  out) ::  k1,k2
+      k1 = -1 ; k2 = -1
+      WRITE(numout,*) 'oasis_init_comp: Error you sould not be there...', cd1
+   END SUBROUTINE oasis_init_comp
+
+   SUBROUTINE oasis_abort(k1,cd1,cd2)
+      INTEGER     , INTENT(in   ) ::  k1
+      CHARACTER(*), INTENT(in   ) ::  cd1,cd2
+      WRITE(numout,*) 'oasis_abort: Error you sould not be there...', cd1, cd2
+   END SUBROUTINE oasis_abort
+
+   SUBROUTINE oasis_get_localcomm(k1,k2)
+      INTEGER     , INTENT(  out) ::  k1,k2
+      k1 = -1 ; k2 = -1
+      WRITE(numout,*) 'oasis_get_localcomm: Error you sould not be there...'
+   END SUBROUTINE oasis_get_localcomm
+
+   SUBROUTINE oasis_def_partition(k1,k2,k3)
+      INTEGER     , INTENT(  out) ::  k1,k3
+      INTEGER     , INTENT(in   ) ::  k2(5)
+      k1 = k2(1) ; k3 = k2(5)
+      WRITE(numout,*) 'oasis_def_partition: Error you sould not be there...'
+   END SUBROUTINE oasis_def_partition
+
+   SUBROUTINE oasis_def_var(k1,cd1,k2,k3,k4,k5,k6,k7)
+      CHARACTER(*), INTENT(in   ) ::  cd1
+      INTEGER     , INTENT(in   ) ::  k2,k3(2),k4,k5(2,2),k6
+      INTEGER     , INTENT(  out) ::  k1,k7
+      k1 = -1 ; k7 = -1
+      WRITE(numout,*) 'oasis_def_var: Error you sould not be there...', cd1
+   END SUBROUTINE oasis_def_var
+
+   SUBROUTINE oasis_enddef(k1)
+      INTEGER     , INTENT(  out) ::  k1
+      k1 = -1
+      WRITE(numout,*) 'oasis_enddef: Error you sould not be there...'
+   END SUBROUTINE oasis_enddef
+  
+   SUBROUTINE oasis_put(k1,k2,p1,k3)
+      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::  p1
+      INTEGER                 , INTENT(in   ) ::  k1,k2
+      INTEGER                 , INTENT(  out) ::  k3
+      k3 = -1
+      WRITE(numout,*) 'oasis_put: Error you sould not be there...'
+   END SUBROUTINE oasis_put
+
+   SUBROUTINE oasis_get(k1,k2,p1,k3)
+      REAL(wp), DIMENSION(:,:), INTENT(  out) ::  p1
+      INTEGER                 , INTENT(in   ) ::  k1,k2
+      INTEGER                 , INTENT(  out) ::  k3
+      p1(1,1) = -1. ; k3 = -1
+      WRITE(numout,*) 'oasis_get: Error you sould not be there...'
+   END SUBROUTINE oasis_get
+
+   SUBROUTINE oasis_get_freqs(k1,k2,k3,k4)
+      INTEGER     , INTENT(in   ) ::  k1,k2
+      INTEGER     , INTENT(  out) ::  k3,k4
+      k3 = k1 ; k4 = k2
+      WRITE(numout,*) 'oasis_get_freqs: Error you sould not be there...'
+   END SUBROUTINE oasis_get_freqs
+
+   SUBROUTINE oasis_terminate(k1)
+      INTEGER     , INTENT(  out) ::  k1
+      k1 = -1
+      WRITE(numout,*) 'oasis_terminate: Error you sould not be there...'
+   END SUBROUTINE oasis_terminate
+   
 #endif
 
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis4.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis4.F90	(revision 4944)
+++ 	(revision )
@@ -1,481 +1,0 @@
-MODULE cpl_oasis4
-   !!======================================================================
-   !!                    ***  MODULE cpl_oasis  ***
-   !! Coupled O/A : coupled ocean-atmosphere case using OASIS4
-   !!=====================================================================
-   !! History :   
-   !!   9.0  !  2004-06  (R. Redler, NEC Laboratories Europe, St Augustin, Germany) Original code
-   !!    -   !  2004-11  (R. Redler, NEC Laboratories Europe; N. Keenlyside, W. Park, IFM-GEOMAR, Kiel, Germany) revision
-   !!    -   !  2004-11  (V. Gayler, MPI M&D) Grid writing
-   !!    -   !  2005-08  (R. Redler, W. Park) frld initialization, paral(2) revision
-   !!    -   !  2005-09  (R. Redler) extended to allow for communication over root only
-   !!    -   !  2006-01  (W. Park) modification of physical part
-   !!    -   !  2006-02  (R. Redler, W. Park) buffer array fix for root exchange
-   !!    -   !  2010-10  (E. Maisonnave and S. Masson) complete rewrite
-   !!----------------------------------------------------------------------
-#if defined key_oasis4
-   !!----------------------------------------------------------------------
-   !!   'key_oasis4'                    coupled Ocean/Atmosphere via OASIS4
-   !!----------------------------------------------------------------------
-   !!   cpl_prism_init     : initialization of coupled mode communication
-   !!   cpl_prism_define   : definition of grid and fields
-   !!   cpl_prism_snd      : snd out fields in coupled mode
-   !!   cpl_prism_rcv      : receive fields in coupled mode
-   !!   cpl_prism_update_time : update date sent to Oasis
-   !!   cpl_prism_finalize : finalize the coupled mode communication
-   !!----------------------------------------------------------------------
-   USE prism            ! OASIS4 prism module
-   USE par_oce          ! ocean parameters
-   USE dom_oce          ! ocean space and time domain
-   USE domwri           ! ocean space and time domain
-   USE in_out_manager   ! I/O manager
-   USE lbclnk           ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC cpl_prism_init
-   PUBLIC cpl_prism_define
-   PUBLIC cpl_prism_snd
-   PUBLIC cpl_prism_rcv
-   PUBLIC cpl_prism_update_time
-   PUBLIC cpl_prism_finalize
-   
-!   LOGICAL, PUBLIC, PARAMETER :: lk_cpl = .TRUE.    ! coupled flag
-   INTEGER                    :: ncomp_id           ! id returned by prism_init_comp
-   INTEGER                    :: nerror             ! return error code
-   INTEGER, PUBLIC            :: OASIS_Rcv  = 1     ! return code if received field
-   INTEGER, PUBLIC            :: OASIS_idle = 0     ! return code if nothing done by oasis
-
-   INTEGER, PARAMETER :: nmaxfld=40    ! Maximum number of coupling fields
-   
-   TYPE, PUBLIC ::   FLD_CPL            ! Type for coupling field information
-      LOGICAL            ::   laction   ! To be coupled or not
-      CHARACTER(len = 8) ::   clname    ! Name of the coupling field   
-      CHARACTER(len = 1) ::   clgrid    ! Grid type  
-      REAL(wp)           ::   nsgn      ! Control of the sign change
-      INTEGER            ::   nid       ! Id of the field
-   END TYPE FLD_CPL
-
-   TYPE(FLD_CPL), DIMENSION(nmaxfld), PUBLIC :: srcv, ssnd   ! Coupling fields
-
-   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: exfld  ! Temporary buffer for receiving
-
-   TYPE(PRISM_Time_struct), PUBLIC    :: date            ! date info for send operation
-   TYPE(PRISM_Time_struct), PUBLIC    :: date_bound(2)   ! date info for send operation
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE cpl_prism_init( kl_comm ) 
-      !!-------------------------------------------------------------------
-      !!             ***  ROUTINE cpl_prism_init  ***
-      !!
-      !! ** Purpose :   Initialize coupled mode communication for ocean
-      !!    exchange between AGCM, OGCM and COUPLER. (OASIS4 software)
-      !!
-      !! ** Method  :   OASIS4 MPI communication 
-      !!--------------------------------------------------------------------
-      INTEGER, INTENT(out) ::   kl_comm   ! local communicator of the model
-      !!--------------------------------------------------------------------
-      
-      CALL prism_init( 'nemo', nerror )
-
-      !------------------------------------------------------------------
-      ! 2nd Initialize the PRISM system for the component
-      !------------------------------------------------------------------
-      CALL prism_init_comp( ncomp_id, 'oceanx', nerror )
-      IF( nerror /= PRISM_Success )   CALL prism_abort( ncomp_id, 'cpl_prism_init', 'Failure in prism_init_comp' )
-
-      !------------------------------------------------------------------
-      ! 3rd Get an MPI communicator fr OPA local communication
-      !------------------------------------------------------------------
-      CALL prism_get_localcomm( ncomp_id, kl_comm, nerror )
-      IF( nerror /= PRISM_Success )   CALL prism_abort( ncomp_id, 'cpl_prism_init', 'Failure in prism_get_localcomm' )
-      !
-   END SUBROUTINE cpl_prism_init
-
-
-   SUBROUTINE cpl_prism_define( krcv, ksnd )
-      !!-------------------------------------------------------------------
-      !!             ***  ROUTINE cpl_prism_define  ***
-      !!
-      !! ** Purpose :   Define grid and field information for ocean
-      !!    exchange between AGCM, OGCM and COUPLER. (OASIS4 software)
-      !!
-      !! ** Method  :   OASIS4 MPI communication 
-      !!--------------------------------------------------------------------
-      INTEGER, INTENT(in) :: krcv, ksnd     ! Number of received and sent coupling fields
-      !
-      INTEGER, DIMENSION(4)      :: igrid     ! ids returned by prism_def_grid
-      INTEGER, DIMENSION(4)      :: iptid     ! ids returned by prism_set_points
-      INTEGER, DIMENSION(4)      :: imskid    ! ids returned by prism_set_mask
-      INTEGER, DIMENSION(4)      :: iishift   ! 
-      INTEGER, DIMENSION(4)      :: ijshift   ! 
-      INTEGER, DIMENSION(4)      :: iioff     ! 
-      INTEGER, DIMENSION(4)      :: ijoff     ! 
-      INTEGER, DIMENSION(4)      :: itmp      ! 
-      INTEGER, DIMENSION(1,3)    :: iextent   ! 
-      INTEGER, DIMENSION(1,3)    :: ioffset   ! 
-
-      INTEGER                    :: ishape(2,3)    ! shape of arrays passed to PSMILe
-      INTEGER                    :: data_type      ! data type of transients
-
-      LOGICAL                    :: new_points
-      LOGICAL                    :: new_mask
-      LOGICAL, ALLOCATABLE, SAVE :: llmask(:,:,:) ! jpi,jpj,1
-
-      INTEGER                    :: ji, jj, jg, jc   ! local loop indicees
-      INTEGER                    :: ii, ij           ! index
-      INTEGER, DIMENSION(1)      :: ind              ! index
-
-      CHARACTER(len=32)          :: clpt_name     ! name of the grid points
-      CHARACTER(len=7)           :: cltxt 
-      CHARACTER(len=1), DIMENSION(4) :: clgrd = (/ 'T','U','V','F' /)     ! name of the grid points
-
-      TYPE(PRISM_Time_struct)    :: tmpdate
-      INTEGER                    :: idate_incr      ! date increment
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zlon, zlat
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zclo, zcla
-      !!--------------------------------------------------------------------
-      
-      CALL wrk_alloc( jpi,jpj, zlon, zlat )
-      CALL wrk_alloc( jpi,jpj,jpk, zclo, zcla )
-
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'cpl_prism_define : initialization in coupled ocean/atmosphere case'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
-      IF(lwp) WRITE(numout,*)
-
-      !
-      ! ... Allocate memory for data exchange
-      !
-      ALLOCATE( exfld(nlei-nldi+1, nlej-nldj+1, 1), stat = nerror )
-      IF ( nerror > 0 ) THEN
-         CALL prism_abort( ncomp_id, 'cpl_prism_define', 'Failure in allocating exfld' )
-         RETURN
-      ENDIF
-
-      IF(.not. ALLOCATED(mask))THEN
-         ALLOCATE(llmask(jpi,jpj,1), Stat=ji)
-         IF(ji /= 0)THEN
-            CALL prism_abort( ncomp_id, 'cpl_prism_define', 'Failure in allocating llmask' )
-            RETURN
-         END IF
-      END IF
-
-      ! -----------------------------------------------------------------
-      ! ... Define the shape of the valid region without the halo and overlaps between cpus
-      !     For serial configuration (key_mpp_mpi not being active)
-      !     nl* is set to the global values 1 and jp*glo.
-      ! -----------------------------------------------------------------
-
-      ishape(:,1) = (/ 1, nlei-nldi+1 /)
-      ishape(:,2) = (/ 1, nlej-nldj+1 /)
-      ishape(:,3) = (/ 1,           1 /)
-          
-      DO ji = 1, 4
-         CALL prism_def_grid( igrid(ji), 'orca'//clgrd(ji), ncomp_id, ishape, PRISM_irrlonlat_regvrt, nerror )
-         IF( nerror /= PRISM_Success )   CALL prism_abort (ncomp_id, 'cpl_prism_define',   &
-            &                                                        'Failure in prism_def_grid of '//clgrd(jg)//'-point' )
-      END DO
-      
-      ! -----------------------------------------------------------------
-      ! ... Define the partition 
-      ! -----------------------------------------------------------------
-      
-      iextent(1,:) = (/    nlei-nldi+1,    nlej-nldj+1, 1 /)
-      ioffset(1,:) = (/ nldi-1+nimpp-1, nldj-1+njmpp-1, 0 /)
-      
-      DO ji = 1, 4
-         CALL prism_def_partition( igrid(ji), 1, ioffset, iextent, nerror )
-         IF( nerror /= PRISM_Success )   CALL prism_abort (ncomp_id, 'cpl_prism_define',   &
-            &                                                        'Failure in prism_def_partition of '//clgrd(jg)//'-point' )
-      END DO
-
-      ! -----------------------------------------------------------------
-      ! ... Define the elements, i.e. specify the corner points for each
-      !     volume element. In case OPA runs on level coordinates (regular
-      !     in the vertical) we only need to give the 4 horizontal corners
-      !     for a volume element plus the vertical position of the upper
-      !     and lower face. Nevertheless the volume element has 8 corners.
-      ! -----------------------------------------------------------------
-      
-      iioff(:) = (/0,1,0,1/)
-      ijoff(:) = (/0,0,1,1/) 
-      iishift(:) = (/0,1,1,0/)
-      ijshift(:) = (/0,0,1,1/)
-
-      DO jg = 1, 4    ! ... the t,u,v,f-points
-
-         cltxt = clgrd(jg)//'-point'
-         
-         ! -----------------------------------------------------------------
-         ! ... Convert OPA masks to logicals and define the masks
-         ! -----------------------------------------------------------------
-         SELECT CASE( jg ) 
-         CASE(1)   ;   llmask(:,:,1) = ( tmask(:,:,1)  ) == 1.
-         CASE(2)   ;   llmask(:,:,1) = ( umask(:,:,1)  ) == 1.
-         CASE(3)   ;   llmask(:,:,1) = ( vmask(:,:,1)  ) == 1.
-         CASE(4)   ;   llmask(:,:,1) = ( fmask(:,:,1)  ) == 1.
-!         CASE(1)   ;   llmask(:,:,1) = ( tmask(:,:,1) * dom_uniq('T') ) == 1.
-!         CASE(2)   ;   llmask(:,:,1) = ( umask(:,:,1) * dom_uniq('U') ) == 1.
-!         CASE(3)   ;   llmask(:,:,1) = ( vmask(:,:,1) * dom_uniq('V') ) == 1.
-!         CASE(4)   ;   llmask(:,:,1) = ( fmask(:,:,1) * dom_uniq('F') ) == 1.
-         END SELECT
-         CALL prism_set_mask( imskid(jg), igrid(jg), ishape, llmask(nldi:nlei, nldj:nlej, 1), .TRUE., nerror )
-         IF( nerror /= PRISM_Success )   CALL prism_abort( ncomp_id, 'cpl_prism_define', 'Failure in prism_set_mask for '//cltxt )
-
-         ! -----------------------------------------------------------------
-         ! ... Define the corners
-         ! -----------------------------------------------------------------
-         SELECT CASE( jg ) 
-         CASE(1)   ;   zlon(:,:) = glamf(:,:)   ;   zlat(:,:) = gphif(:,:)
-         CASE(2)   ;   zlon(:,:) = glamv(:,:)   ;   zlat(:,:) = gphiv(:,:)
-         CASE(3)   ;   zlon(:,:) = glamu(:,:)   ;   zlat(:,:) = gphiu(:,:) 
-         CASE(4)   ;   zlon(:,:) = glamt(:,:)   ;   zlat(:,:) = gphit(:,:)
-         END SELECT
-
-         DO jc = 1, 4   ! corner number (anti-clockwise, starting from the bottom left corner)
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1   ! NO vector opt.
-                  ii = ji-1 + iioff(jg) + iishift(jc)
-                  ij = jj-1 + ijoff(jg) + ijshift(jc)
-                  zclo(ji,jj,jc) = zlon(ii,ij)
-                  zcla(ji,jj,jc) = zlat(ii,ij)
-               END DO
-            END DO
-            CALL lbc_lnk( zclo(:,:,jc), clgrd(jg), 1. )   ;   CALL lbc_lnk( zcla(:,:,jc), clgrd(jg), 1. )
-         END DO
-
-         CALL prism_set_corners( igrid(jg), 8, ishape, zclo(nldi:nlei, nldj:nlej,:),   &
-            &                                          zcla(nldi:nlei, nldj:nlej,:), RESHAPE( (/-1.,1./), (/1,2/) ), nerror )
-         IF( nerror /= PRISM_Success )   CALL prism_abort( ncomp_id, 'cpl_prism_define', 'Failure in prism_set_corners of '//cltxt )    
-
-         ! -----------------------------------------------------------------
-         ! ... Define the center points
-         ! -----------------------------------------------------------------
-         SELECT CASE( jg ) 
-         CASE(1)   ;   zlon(:,:) = glamt(:,:)   ;   zlat(:,:) = gphit(:,:)
-         CASE(2)   ;   zlon(:,:) = glamu(:,:)   ;   zlat(:,:) = gphiu(:,:)
-         CASE(3)   ;   zlon(:,:) = glamv(:,:)   ;   zlat(:,:) = gphiv(:,:)
-         CASE(4)   ;   zlon(:,:) = glamf(:,:)   ;   zlat(:,:) = gphif(:,:)
-         END SELECT
-
-         CALL prism_set_points ( iptid(jg), cltxt, igrid(jg), ishape, zlon(nldi:nlei, nldj:nlej),   &
-         &                                                            zlat(nldi:nlei, nldj:nlej), (/0./), .TRUE., nerror )
-         IF( nerror /= PRISM_Success )   CALL prism_abort ( ncomp_id, 'cpl_prism_define', 'Failure in prism_set_points '//cltxt )
-
-      END DO
-
-      ! ... Announce send variables. 
-      !
-      DO ji = 1, ksnd
-         IF ( ssnd(ji)%laction ) THEN 
-            
-            itmp(:) = 0
-            WHERE( clgrd == ssnd(ji)%clgrid  ) itmp = 1
-            ind(:) = maxloc( itmp )
-            WRITE(6,*) ' grid for field ', ind(1), ssnd(ji)%clname
-             ind(1) = 1
-
-            CALL prism_def_var( ssnd(ji)%nid, ssnd(ji)%clname, igrid(ind(1)), iptid(ind(1)),  imskid(ind(1)), (/ 3, 0/),   &
-               &                ishape, PRISM_Double_Precision, nerror )
-            IF ( nerror /= PRISM_Success )   CALL prism_abort( ssnd(ji)%nid, 'cpl_prism_define',   &
-               &                                               'Failure in prism_def_var for '//TRIM(ssnd(ji)%clname))
-
-         ENDIF
-      END DO
-      !
-      ! ... Announce received variables. 
-      !
-      DO ji = 1, krcv
-         IF ( srcv(ji)%laction ) THEN 
-
-            itmp(:) = 0
-            WHERE( clgrd == srcv(ji)%clgrid  ) itmp = 1
-            ind(:) = maxloc( itmp )
-            WRITE(6,*) ' grid for field ', ind(1), srcv(ji)%clname
-             ind(1) = 1
- 
-            CALL prism_def_var( srcv(ji)%nid, srcv(ji)%clname, igrid(ind(1)), iptid(ind(1)), imskid(ind(1)), (/ 3, 0/),   &
-               &                ishape, PRISM_Double_Precision, nerror )
-            IF ( nerror /= PRISM_Success )   CALL prism_abort( srcv(ji)%nid, 'cpl_prism_define',   &
-               &                                               'Failure in prism_def_var for '//TRIM(srcv(ji)%clname))
-
-         ENDIF
-      END DO
-      
-      !------------------------------------------------------------------
-      ! End of definition phase
-      !------------------------------------------------------------------
-      
-      CALL prism_enddef( nerror )
-      IF ( nerror /= PRISM_Success )   CALL prism_abort ( ncomp_id, 'cpl_prism_define', 'Failure in prism_enddef')
-      
-      CALL wrk_dealloc( jpi,jpj, zlon, zlat )
-      CALL wrk_dealloc( jpi,jpj,jpk, zclo, zcla )
-      !
-   END SUBROUTINE cpl_prism_define
-   
-   
-   SUBROUTINE cpl_prism_snd( kid, kstep, pdata, kinfo )
-      !!---------------------------------------------------------------------
-      !!              ***  ROUTINE cpl_prism_snd  ***
-      !!
-      !! ** Purpose : - At each coupling time-step,this routine sends fields
-      !!      like sst or ice cover to the coupler or remote application.
-      !!----------------------------------------------------------------------
-      INTEGER                 , INTENT(in   ) ::   kid     ! variable intex in the array
-      INTEGER                 , INTENT(  out) ::   kinfo   ! OASIS4 info argument
-      INTEGER                 , INTENT(in   ) ::   kstep   ! ocean time-step in seconds
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   pdata
-      !!--------------------------------------------------------------------
-      !
-      ! snd data to OASIS4
-      !
-      exfld(:,:,1) = pdata(nldi:nlei, nldj:nlej)
-      CALL prism_put( ssnd(kid)%nid, date, date_bound, exfld, kinfo, nerror )
-      IF ( nerror /= PRISM_Success )   CALL prism_abort( ssnd(kid)%nid, 'cpl_prism_snd',   &
-         &                                               'Failure in prism_put for '//TRIM(ssnd(kid)%clname) )
-
-      IF( ln_ctl ) THEN        
-         IF ( kinfo >= PRISM_Cpl     .OR. kinfo == PRISM_Rst .OR.   &
-            & kinfo == PRISM_RstTimeop ) THEN
-            WRITE(numout,*) '****************'
-            WRITE(numout,*) 'prism_put: Outgoing ', ssnd(kid)%clname
-            WRITE(numout,*) 'prism_put: ivarid ', ssnd(kid)%nid
-            WRITE(numout,*) 'prism_put:  kstep ', kstep
-            WRITE(numout,*) 'prism_put:   info ', kinfo
-            WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata)
-            WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata)
-            WRITE(numout,*) '     -     Sum value is ', SUM(pdata)
-            WRITE(numout,*) '****************'
-         ENDIF
-      ENDIF
-      !
-   END SUBROUTINE cpl_prism_snd
-
-
-   SUBROUTINE cpl_prism_rcv( kid, kstep, pdata, kinfo )
-      !!---------------------------------------------------------------------
-      !!              ***  ROUTINE cpl_prism_rcv  ***
-      !!
-      !! ** Purpose : - At each coupling time-step,this routine receives fields
-      !!      like stresses and fluxes from the coupler or remote application.
-      !!----------------------------------------------------------------------
-      INTEGER                 , INTENT(in   ) ::   kid     ! variable intex in the array
-      INTEGER                 , INTENT(in   ) ::   kstep   ! ocean time-step in seconds
-      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pdata   ! IN to keep the value if nothing is done
-      INTEGER                 , INTENT(  out) ::   kinfo   ! OASIS4 info argument
-      !
-      LOGICAL                :: llaction
-      !!--------------------------------------------------------------------
-      !
-      ! receive local data from OASIS4 on every process
-      !
-      CALL prism_get( srcv(kid)%nid, date, date_bound, exfld, kinfo, nerror )         
-      IF ( nerror /= PRISM_Success )   CALL prism_abort( srcv(kid)%nid, 'cpl_prism_rcv',   &
-         &                                               'Failure in prism_get for '//TRIM(srcv(kid)%clname) )
-
-      WRITE(numout,*) 'prism_get: Incoming ', srcv(kid)%clname
-      call flush(numout)
-      llaction = .false.
-      IF( kinfo == PRISM_Cpl )  llaction = .TRUE.
-
-      IF ( ln_ctl )   WRITE(numout,*) "llaction, kinfo, kstep, ivarid: " , llaction, kinfo, kstep, srcv(kid)%nid
-
-      IF ( llaction ) THEN
-
-         kinfo = OASIS_Rcv
-         pdata(nldi:nlei, nldj:nlej) = exfld(:,:,1)
-         
-         !--- Fill the overlap areas and extra hallows (mpp)
-         !--- check periodicity conditions (all cases)
-         CALL lbc_lnk( pdata, srcv(kid)%clgrid, srcv(kid)%nsgn )   
-         
-         IF ( ln_ctl ) THEN        
-            WRITE(numout,*) '****************'
-            WRITE(numout,*) 'prism_get: Incoming ', srcv(kid)%clname
-            WRITE(numout,*) 'prism_get: ivarid '  , srcv(kid)%nid
-            WRITE(numout,*) 'prism_get:   kstep', kstep
-            WRITE(numout,*) 'prism_get:   info ', kinfo
-            WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata)
-            WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata)
-            WRITE(numout,*) '     -     Sum value is ', SUM(pdata)
-            WRITE(numout,*) '****************'
-         ENDIF
-
-      ELSE
-         kinfo = OASIS_idle     
-      ENDIF
-      !
-   END SUBROUTINE cpl_prism_rcv
-
-
-   SUBROUTINE cpl_prism_finalize
-      !!---------------------------------------------------------------------
-      !!              ***  ROUTINE cpl_prism_finalize  ***
-      !!
-      !! ** Purpose : - Finalizes the coupling. If MPI_init has not been
-      !!      called explicitly before cpl_prism_init it will also close
-      !!      MPI communication.
-      !!----------------------------------------------------------------------
-      !
-      DEALLOCATE(exfld)
-      CALL prism_terminate ( nerror )         
-      !
-   END SUBROUTINE cpl_prism_finalize
-
-
-   SUBROUTINE cpl_prism_update_time(kt)
-      !!---------------------------------------------------------------------
-      !!              ***  ROUTINE cpl_prism_update_time  ***
-      !!
-      !! ** Purpose : - Increment date with model timestep
-      !!                called explicitly at the end of each timestep
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean model time step index
-
-      TYPE(PRISM_Time_struct) ::   tmpdate
-      INTEGER                 ::   idate_incr   ! date increment
-      !!----------------------------------------------------------------------
-
-      IF( kt == nit000 ) THEN      ! Define the actual date 
-         !
-         ! date is determined by adding days since beginning of the run to the corresponding initial date.
-         ! Note that OPA internal info about the start date of the experiment is bypassed.
-         ! Instead we rely sololy on the info provided by the SCC.xml file.
-         !
-         date = PRISM_Jobstart_date
-         !
-         !
-         ! lower/upper bound is determined by adding half a time step
-         !
-         idate_incr = 0.5 * NINT ( rdttra(1) )
-         tmpdate = date   ;   CALL PRISM_calc_newdate ( tmpdate, -idate_incr, nerror )   ;   date_bound(1) = tmpdate
-         tmpdate = date   ;   CALL PRISM_calc_newdate ( tmpdate,  idate_incr, nerror )   ;   date_bound(2) = tmpdate
-         !
-      ELSE      ! Date update
-         !
-         idate_incr  = rdttra(1)
-         CALL PRISM_calc_newdate( date, idate_incr, nerror )
-         date_bound(1) = date_bound(2)
-         tmpdate = date_bound(2)
-         CALL PRISM_calc_newdate( tmpdate, idate_incr, nerror )
-         date_bound(2) = tmpdate
-         !
-      END IF
-      !
-   END SUBROUTINE cpl_prism_update_time
-
-#endif
-
-   !!=====================================================================
-END MODULE cpl_oasis4
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/oasis4_date.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/oasis4_date.F90	(revision 4944)
+++ 	(revision )
@@ -1,41 +1,0 @@
-MODULE oasis4_date
-   !!======================================================================
-   !!                     ***  MODULE oasis_date  ***  
-   !!   Date and related information required to couple NEMO via OASIS4
-   !!   Made separate from cpl_oasis4 module to allow wider use.
-   !!======================================================================
-   !! History :  2.0  ! 2005-12  (R. Hill, Met. Office) Original code
-   !!----------------------------------------------------------------------
-#if defined key_oasis4
-   !!----------------------------------------------------------------------
-   !!   'key_oasis4'                                   coupled with OASIS-4
-   !!----------------------------------------------------------------------
-   !##################### WARNING coupled mode ###############################
-   !##################### WARNING coupled mode ###############################
-   !   Following line must be enabled if coupling with OASIS
-   !   USE PRISM
-   !##################### WARNING coupled mode ###############################
-   !##################### WARNING coupled mode ###############################
-
-   PRIVATE
-   IMPLICIT NONE
-
-   INTEGER, PUBLIC :: date_err, date_info   !: 
-
-   TYPE(PRISM_Time_struct), PUBLIC ::   dates            !: date info for send operation
-   TYPE(PRISM_Time_struct), PUBLIC ::   dates_bound(2)   !: date info for send operation
-   TYPE(PRISM_Time_struct), PUBLIC ::   dater            !: date info for receive operation
-   TYPE(PRISM_Time_struct), PUBLIC ::   dater_bound(2)   !: date info for receive operation
-   TYPE(PRISM_Time_struct), PUBLIC ::   tmpdate          !:
-   
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option            Dummy module                   NO OASIS-4
-   !!----------------------------------------------------------------------
-#endif
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!======================================================================
-END MODULE oasis4_date
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_ice.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_ice.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_ice.F90	(revision 4946)
@@ -14,4 +14,5 @@
    !!----------------------------------------------------------------------
    USE par_oce          ! ocean parameters
+   USE sbc_oce          ! surface boundary condition: ocean
 # if defined key_lim3
    USE par_ice          ! LIM-3 parameters
@@ -21,5 +22,5 @@
    USE ice_2
 # endif
-# if defined key_cice 
+# if defined key_cice
    USE ice_domain_size, only: ncat 
 #endif
@@ -55,30 +56,26 @@
 # endif
 
-#if defined key_lim3 || defined key_lim2 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qns_ice       !: non solar heat flux over ice                  [W/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qsr_ice       !: solar heat flux over ice                      [W/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qsr_ice_mean  !: dauly mean solar heat flux over ice       [W/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qla_ice       !: latent flux over ice                          [W/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dqla_ice      !: latent sensibility over ice                 [W/m2/K]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dqns_ice      !: non solar heat flux over ice (LW+SEN+LA)    [W/m2/K]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tn_ice        !: ice surface temperature                          [K]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   alb_ice       !: albedo of ice
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qns_ice        !: non solar heat flux over ice                  [W/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qsr_ice        !: solar heat flux over ice                      [W/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qsr_ice_mean   !: daily mean solar heat flux over ice           [W/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qla_ice        !: latent flux over ice                          [W/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dqla_ice       !: latent sensibility over ice                 [W/m2/K]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dqns_ice       !: non solar heat flux over ice (LW+SEN+LA)    [W/m2/K]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tn_ice         !: ice surface temperature                          [K]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   alb_ice        !: ice albedo                                       [-]
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   utau_ice  !: atmos-ice u-stress. VP: I-pt ; EVP: U,V-pts   [N/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   vtau_ice  !: atmos-ice v-stress. VP: I-pt ; EVP: U,V-pts   [N/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   fr1_i0    !: 1st Qsr fraction penetrating inside ice cover    [-]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   fr2_i0    !: 2nd Qsr fraction penetrating inside ice cover    [-]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   emp_ice   !: sublimation-snow budget over ice             [kg/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   utau_ice       !: atmos-ice u-stress. VP: I-pt ; EVP: U,V-pts   [N/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   vtau_ice       !: atmos-ice v-stress. VP: I-pt ; EVP: U,V-pts   [N/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   fr1_i0         !: Solar surface transmission parameter, thick ice  [-]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   fr2_i0         !: Solar surface transmission parameter, thin ice   [-]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   emp_ice        !: sublimation - precip over sea ice            [kg/m2]
 
-# if defined key_lim3
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   tatm_ice  !: air temperature
-# endif
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   topmelt            !: category topmelt
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   botmelt            !: category botmelt
 
-#elif defined key_cice
+#if defined key_cice
    !
    ! for consistency with LIM, these are declared with three dimensions
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qlw_ice            !: incoming long-wave
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qla_ice            !: latent flux over ice           [W/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qsr_ice            !: solar heat flux over ice       [W/m2]
    !
    ! other forcing arrays are two dimensional
@@ -86,5 +83,4 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ss_iov             !: y ice-ocean surface stress at NEMO V point
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   emp_ice            !: sublimation-snow budget over ice    [kg/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   tatm_ice           !: air temperature
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   qatm_ice           !: specific humidity
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   wndi_ice           !: i wind at T point
@@ -93,10 +89,22 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   fr_iu              !: ice fraction at NEMO U point
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   fr_iv              !: ice fraction at NEMO V point
-   !
-   ! finally, arrays corresponding to different ice categories
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   a_i                !: category ice fraction
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   topmelt            !: category topmelt
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   botmelt            !: category botmelt
+   
+   ! variables used in the coupled interface
+   INTEGER , PUBLIC, PARAMETER ::   jpl = ncat
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   u_ice, v_ice          ! jpi, jpj
 #endif
+   
+#if defined key_lim2 || defined key_cice
+   ! already defined in ice.F90 for LIM3
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  a_i
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  ht_i, ht_s
+#endif
+
+#if defined key_lim3 || defined key_cice
+   ! not used with LIM2
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   tatm_ice       !: air temperature [K]
+#endif
+
+   REAL(wp), PUBLIC, SAVE ::   cldf_ice = 0.81    !: cloud fraction over sea ice, summer CLIO value   [-]
 
    !!----------------------------------------------------------------------
@@ -111,34 +119,45 @@
       !!                     ***  FUNCTION sbc_ice_alloc  ***
       !!----------------------------------------------------------------------
-      INTEGER :: ierr(2)
+      INTEGER :: ierr(5)
       !!----------------------------------------------------------------------
       ierr(:) = 0
 
-#if defined key_lim3 || defined key_lim2
-      ALLOCATE( qns_ice (jpi,jpj,jpl) , qsr_ice (jpi,jpj,jpl) ,     &
+      ALLOCATE( qsr_ice (jpi,jpj,jpl)                         ,     &
          &      qla_ice (jpi,jpj,jpl) , dqla_ice(jpi,jpj,jpl) ,     &
-         &      dqns_ice(jpi,jpj,jpl) , tn_ice  (jpi,jpj,jpl) ,     &
-         &      alb_ice (jpi,jpj,jpl) ,                             &
          &      utau_ice(jpi,jpj)     , vtau_ice(jpi,jpj)     ,     &
-         &      fr1_i0  (jpi,jpj)     , fr2_i0  (jpi,jpj)     ,     &
-#if defined key_lim3
-         &      emp_ice(jpi,jpj)      , tatm_ice(jpi,jpj)     , STAT= ierr(1) )
-#else
-         &      emp_ice(jpi,jpj)                              , STAT= ierr(1) )
+#if defined key_lim3 || defined key_cice
+         &      tatm_ice(jpi,jpj)     ,                             &
 #endif
-#elif defined key_cice
-      ALLOCATE( qla_ice(jpi,jpj,1)    , qlw_ice(jpi,jpj,1)    , qsr_ice(jpi,jpj,1)    , &
-                wndi_ice(jpi,jpj)     , tatm_ice(jpi,jpj)     , qatm_ice(jpi,jpj)     , &
+         &      STAT= ierr(1) )
+#if defined key_cice
+      ALLOCATE( qlw_ice(jpi,jpj,1)    , wndi_ice(jpi,jpj)     , qatm_ice(jpi,jpj)     , &
                 wndj_ice(jpi,jpj)     , nfrzmlt(jpi,jpj)      , ss_iou(jpi,jpj)       , &
                 ss_iov(jpi,jpj)       , fr_iu(jpi,jpj)        , fr_iv(jpi,jpj)        , &
-                a_i(jpi,jpj,ncat)     , topmelt(jpi,jpj,ncat) , botmelt(jpi,jpj,ncat), STAT= ierr(1) )
+                a_i(jpi,jpj,ncat)     , topmelt(jpi,jpj,ncat) , botmelt(jpi,jpj,ncat) , &
+                STAT= ierr(1) )
+      IF( lk_cpl )   ALLOCATE( u_ice(jpi,jpj)        , fr1_i0(jpi,jpj)       , tn_ice (jpi,jpj,1)    , &
+         &                     v_ice(jpi,jpj)        , fr2_i0(jpi,jpj)       , alb_ice(jpi,jpj,1)    , &
+         &                     emp_ice(jpi,jpj)      , qns_ice(jpi,jpj,1)    , dqns_ice(jpi,jpj,1)   , &
+         &                     STAT= ierr(2) )
+      
+#else
+      ALLOCATE( fr1_i0(jpi,jpj)       , tn_ice (jpi,jpj,1)    , &
+         &      fr2_i0(jpi,jpj)       , alb_ice(jpi,jpj,1)    , &
+         &      emp_ice(jpi,jpj)      , qns_ice(jpi,jpj,1)    , dqns_ice(jpi,jpj,1)   , &
+         &      STAT= ierr(2) )
 #endif
          !
 #if defined key_lim2
-      IF( ltrcdm2dc_ice )THEN
-         ALLOCATE( qsr_ice_mean (jpi,jpj,jpl), STAT=ierr(2) )
-      ENDIF
+      IF( ltrcdm2dc_ice )   ALLOCATE( qsr_ice_mean (jpi,jpj,jpl), STAT=ierr(3) )
 #endif
          !
+#if defined key_lim2
+      ALLOCATE( a_i(jpi,jpj,1) , STAT=ierr(4) )
+#endif
+
+#if defined key_cice || defined key_lim2
+      IF( lk_cpl )   ALLOCATE( ht_i(jpi,jpj,jpl) , ht_s(jpi,jpj,jpl) , STAT=ierr(5) )
+#endif
+
       sbc_ice_alloc = MAXVAL( ierr )
       IF( lk_mpp            )   CALL mpp_sum ( sbc_ice_alloc )
@@ -150,8 +169,18 @@
    !!   Default option                      NO LIM 2.0 or 3.0 or CICE sea-ice model
    !!----------------------------------------------------------------------
+   USE in_out_manager   ! I/O manager
    LOGICAL         , PUBLIC, PARAMETER ::   lk_lim2    = .FALSE.  !: no LIM-2 ice model
    LOGICAL         , PUBLIC, PARAMETER ::   lk_lim3    = .FALSE.  !: no LIM-3 ice model
    LOGICAL         , PUBLIC, PARAMETER ::   lk_cice    = .FALSE.  !: no CICE  ice model
    CHARACTER(len=1), PUBLIC, PARAMETER ::   cp_ice_msh = '-'      !: no grid ice-velocity
+   REAL            , PUBLIC, PARAMETER ::   cldf_ice = 0.81       !: cloud fraction over sea ice, summer CLIO value   [-]
+   INTEGER         , PUBLIC, PARAMETER ::   jpl = 1 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   u_ice, v_ice,fr1_i0,fr2_i0          ! jpi, jpj
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tn_ice, alb_ice, qns_ice, dqns_ice  ! (jpi,jpj,jpl)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   a_i
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   emp_ice
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qsr_ice
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ht_i, ht_s
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   topmelt, botmelt
 #endif
 
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90	(revision 4946)
@@ -35,5 +35,9 @@
    LOGICAL , PUBLIC ::   ln_blk_core    !: CORE bulk formulation
    LOGICAL , PUBLIC ::   ln_blk_mfs     !: MFS  bulk formulation
-   LOGICAL , PUBLIC ::   ln_cpl         !: coupled   formulation (overwritten by key_sbc_coupled )
+#if defined key_oasis3
+   LOGICAL , PUBLIC ::   lk_cpl = .TRUE.  !: coupled formulation
+#else
+   LOGICAL , PUBLIC ::   lk_cpl = .FALSE. !: coupled formulation
+#endif
    LOGICAL , PUBLIC ::   ln_dm2dc       !: Daily mean to Diurnal Cycle short wave (qsr)
    LOGICAL , PUBLIC ::   ln_rnf         !: runoffs / runoff mouths
@@ -46,4 +50,9 @@
    !                                             !: =1 levitating ice with mass and salt exchange but no presure effect
    !                                             !: =2 embedded sea-ice (full salt and mass exchanges and pressure)
+   INTEGER , PUBLIC :: nn_limflx        !: LIM3 Multi-category heat flux formulation
+   !                                             !: =-1  Use of per-category fluxes
+   !                                             !: = 0  Average per-category fluxes
+   !                                             !: = 1  Average then redistribute per-category fluxes
+   !                                             !: = 2  Redistribute a single flux over categories
    INTEGER , PUBLIC ::   nn_fwb         !: FreshWater Budget: 
    !                                             !:  = 0 unchecked 
@@ -56,9 +65,17 @@
    LOGICAL , PUBLIC ::   ln_icebergs    !: Icebergs
    !
-   CHARACTER (len=8), PUBLIC :: cn_iceflx  !: Flux handling over ice categories
-   LOGICAL, PUBLIC :: ln_iceflx_ave     ! Average heat fluxes over all ice categories
-   LOGICAL, PUBLIC :: ln_iceflx_linear  ! Redistribute mean heat fluxes over all ice categories, using ice temperature and albedo
-   !
-   INTEGER , PUBLIC ::   nn_lsm        !: Number of iteration if seaoverland is applied
+   INTEGER , PUBLIC ::   nn_lsm         !: Number of iteration if seaoverland is applied
+   !!----------------------------------------------------------------------
+   !!           switch definition (improve readability)
+   !!----------------------------------------------------------------------
+   INTEGER , PUBLIC, PARAMETER ::   jp_gyre    = 0        !: GYRE analytical formulation
+   INTEGER , PUBLIC, PARAMETER ::   jp_ana     = 1        !: analytical      formulation
+   INTEGER , PUBLIC, PARAMETER ::   jp_flx     = 2        !: flux            formulation
+   INTEGER , PUBLIC, PARAMETER ::   jp_clio    = 3        !: CLIO bulk       formulation
+   INTEGER , PUBLIC, PARAMETER ::   jp_core    = 4        !: CORE bulk       formulation
+   INTEGER , PUBLIC, PARAMETER ::   jp_cpl     = 5        !: Coupled         formulation
+   INTEGER , PUBLIC, PARAMETER ::   jp_mfs     = 6        !: MFS  bulk       formulation
+   INTEGER , PUBLIC, PARAMETER ::   jp_esopa   = -1       !: esopa test, ALL formulations
+   
    !!----------------------------------------------------------------------
    !!              Ocean Surface Boundary Condition fields
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_clio.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_clio.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_clio.F90	(revision 4946)
@@ -114,5 +114,5 @@
       !!              - utau, vtau  i- and j-component of the wind stress
       !!              - taum        wind stress module at T-point
-      !!              - wndm        10m wind module at T-point
+      !!              - wndm        10m wind module at T-point over free ocean or leads in presence of sea-ice
       !!              - qns         non-solar heat flux including latent heat of solid 
       !!                            precip. melting and emp heat content
@@ -204,5 +204,5 @@
       !!               - utau, vtau  i- and j-component of the wind stress
       !!               - taum        wind stress module at T-point
-      !!               - wndm        10m wind module at T-point
+      !!               - wndm        10m wind module at T-point over free ocean or leads in presence of sea-ice
       !!               - qns         non-solar heat flux including latent heat of solid 
       !!                             precip. melting and emp heat content
@@ -403,5 +403,5 @@
 
 
-   SUBROUTINE blk_ice_clio(  pst   , palb_cs, palb_os ,       &
+   SUBROUTINE blk_ice_clio(  pst   , palb_cs, palb_os, palb,  &
       &                      p_taui, p_tauj, p_qns , p_qsr,   &
       &                      p_qla , p_dqns, p_dqla,          &
@@ -432,6 +432,7 @@
       !!----------------------------------------------------------------------
       REAL(wp), INTENT(in   ), DIMENSION(:,:,:)   ::   pst      ! ice surface temperature                   [Kelvin]
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:)   ::   palb_cs  ! ice albedo (clear    sky) (alb_ice_cs)         [%]
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:)   ::   palb_os  ! ice albedo (overcast sky) (alb_ice_os)         [%]
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:)   ::   palb_cs  ! ice albedo (clear    sky) (alb_ice_cs)         [-]
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:)   ::   palb_os  ! ice albedo (overcast sky) (alb_ice_os)         [-]
+      REAL(wp), INTENT(  out), DIMENSION(:,:,:)   ::   palb     ! ice albedo (actual value)                      [-]
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   p_taui   ! surface ice stress at I-point (i-component) [N/m2]
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   p_tauj   ! surface ice stress at I-point (j-component) [N/m2]
@@ -443,6 +444,6 @@
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   p_tpr    ! total precipitation          (T-point)   [Kg/m2/s]
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   p_spr    ! solid precipitation          (T-point)   [Kg/m2/s]
-      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   p_fr1    ! 1sr fraction of qsr penetration in ice         [%]
-      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   p_fr2    ! 2nd fraction of qsr penetration in ice         [%]
+      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   p_fr1    ! 1sr fraction of qsr penetration in ice         [-]
+      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   p_fr2    ! 2nd fraction of qsr penetration in ice         [-]
       CHARACTER(len=1), INTENT(in   )             ::   cd_grid  ! type of sea-ice grid ("C" or "B" grid)
       INTEGER, INTENT(in   )                      ::   pdim     ! number of ice categories
@@ -547,4 +548,9 @@
       !-----------------------------------------------------------!
       CALL blk_clio_qsr_ice( palb_cs, palb_os, p_qsr )
+      
+      DO jl = 1, ijpl
+         palb(:,:,jl) = ( palb_cs(:,:,jl) * ( 1.e0 - sf(jp_ccov)%fnow(ji,jj,1) )   &
+            &         +   palb_os(:,:,jl) * sf(jp_ccov)%fnow(ji,jj,1) )
+      END DO
 
       !                                     ! ========================== !
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_core.F90	(revision 4946)
@@ -5,22 +5,27 @@
    !!=====================================================================
    !! History :  1.0  !  2004-08  (U. Schweckendiek)  Original code
-   !!            2.0  !  2005-04  (L. Brodeau, A.M. Treguier) additions: 
+   !!            2.0  !  2005-04  (L. Brodeau, A.M. Treguier) additions:
    !!                           -  new bulk routine for efficiency
    !!                           -  WINDS ARE NOW ASSUMED TO BE AT T POINTS in input files !!!!
-   !!                           -  file names and file characteristics in namelist 
-   !!                           -  Implement reading of 6-hourly fields   
-   !!            3.0  !  2006-06  (G. Madec) sbc rewritting   
-   !!             -   !  2006-12  (L. Brodeau) Original code for TURB_CORE_2Z
+   !!                           -  file names and file characteristics in namelist
+   !!                           -  Implement reading of 6-hourly fields
+   !!            3.0  !  2006-06  (G. Madec) sbc rewritting
+   !!             -   !  2006-12  (L. Brodeau) Original code for turb_core_2z
    !!            3.2  !  2009-04  (B. Lemaire)  Introduce iom_put
    !!            3.3  !  2010-10  (S. Masson)  add diurnal cycle
    !!            3.4  !  2011-11  (C. Harris) Fill arrays required by CICE
+   !!            3.7  !  2014-06  (L. Brodeau) simplification and optimization of CORE bulk
    !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
-   !!   sbc_blk_core  : bulk formulation as ocean surface boundary condition
-   !!                   (forced mode, CORE bulk formulea)
-   !!   blk_oce_core  : ocean: computes momentum, heat and freshwater fluxes
-   !!   blk_ice_core  : ice  : computes momentum, heat and freshwater fluxes
-   !!   turb_core     : computes the CORE turbulent transfer coefficients 
+   !!   sbc_blk_core    : bulk formulation as ocean surface boundary condition (forced mode, CORE bulk formulea)
+   !!   blk_oce_core    : computes momentum, heat and freshwater fluxes over ocean
+   !!   blk_ice_core    : computes momentum, heat and freshwater fluxes over ice
+   !!   blk_bio_meanqsr : compute daily mean short wave radiation over the ocean
+   !!   blk_ice_meanqsr : compute daily mean short wave radiation over the ice
+   !!   turb_core_2z    : Computes turbulent transfert coefficients
+   !!   cd_neutral_10m  : Estimate of the neutral drag coefficient at 10m
+   !!   psi_m           : universal profile stability function for momentum
+   !!   psi_h           : universal profile stability function for temperature and humidity
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers
@@ -38,8 +43,6 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE prtctl          ! Print control
-   USE sbcwave,ONLY :  cdn_wave !wave module 
-#if defined key_lim3 || defined key_cice
+   USE sbcwave, ONLY   :  cdn_wave ! wave module
    USE sbc_ice         ! Surface boundary condition: ice fields
-#endif
    USE lib_fortran     ! to use key_nosignedzero
 
@@ -52,5 +55,5 @@
    PUBLIC   turb_core_2z         ! routine calles in sbcblk_mfs module
 
-   INTEGER , PARAMETER ::   jpfld   = 9           ! maximum number of files to read 
+   INTEGER , PARAMETER ::   jpfld   = 9           ! maximum number of files to read
    INTEGER , PARAMETER ::   jp_wndi = 1           ! index of 10m wind velocity (i-component) (m/s)    at T-point
    INTEGER , PARAMETER ::   jp_wndj = 2           ! index of 10m wind velocity (j-component) (m/s)    at T-point
@@ -62,7 +65,7 @@
    INTEGER , PARAMETER ::   jp_snow = 8           ! index of snow (solid prcipitation)       (kg/m2/s)
    INTEGER , PARAMETER ::   jp_tdif = 9           ! index of tau diff associated to HF tau   (N/m2)   at T-point
-   
+
    TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf   ! structure of input fields (file informations, fields read)
-         
+
    !                                             !!! CORE bulk parameters
    REAL(wp), PARAMETER ::   rhoa =    1.22        ! air density
@@ -75,10 +78,8 @@
 
    !                                  !!* Namelist namsbc_core : CORE bulk parameters
-   LOGICAL  ::   ln_2m       ! logical flag for height of air temp. and hum
    LOGICAL  ::   ln_taudif   ! logical flag to use the "mean of stress module - module of mean stress" data
    REAL(wp) ::   rn_pfac     ! multiplication factor for precipitation
    REAL(wp) ::   rn_efac     ! multiplication factor for evaporation (clem)
    REAL(wp) ::   rn_vfac     ! multiplication factor for ice/ocean velocity in the calculation of wind stress (clem)
-   LOGICAL  ::   ln_bulk2z   ! logical flag for case where z(q,t) and z(u) are specified in the namelist
    REAL(wp) ::   rn_zqt      ! z(q,t) : height of humidity and temperature measurements
    REAL(wp) ::   rn_zu       ! z(u)   : height of wind measurements
@@ -88,5 +89,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO-consortium (2010) 
+   !! NEMO/OPA 3.7 , NEMO-consortium (2014)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -97,7 +98,7 @@
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE sbc_blk_core  ***
-      !!                   
+      !!
       !! ** Purpose :   provide at each time step the surface ocean fluxes
-      !!      (momentum, heat, freshwater and runoff) 
+      !!      (momentum, heat, freshwater and runoff)
       !!
       !! ** Method  : (1) READ each fluxes in NetCDF files:
@@ -118,17 +119,21 @@
       !! ** Action  :   defined at each time-step at the air-sea interface
       !!              - utau, vtau  i- and j-component of the wind stress
-      !!              - taum, wndm  wind stress and 10m wind modules at T-point
+      !!              - taum        wind stress module at T-point
+      !!              - wndm        wind speed  module at T-point over free ocean or leads in presence of sea-ice
       !!              - qns, qsr    non-solar and solar heat fluxes
       !!              - emp         upward mass flux (evapo. - precip.)
       !!              - sfx         salt flux due to freezing/melting (non-zero only if ice is present)
       !!                            (set in limsbc(_2).F90)
+      !!
+      !! ** References :   Large & Yeager, 2004 / Large & Yeager, 2008
+      !!                   Brodeau et al. Ocean Modelling 2010
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time step
-      !!
+      !
       INTEGER  ::   ierror   ! return error code
       INTEGER  ::   ifpr     ! dummy loop indice
       INTEGER  ::   jfld     ! dummy loop arguments
       INTEGER  ::   ios      ! Local integer output status for namelist read
-      !!
+      !
       CHARACTER(len=100) ::  cn_dir   !   Root directory for location of core files
       TYPE(FLD_N), DIMENSION(jpfld) ::   slf_i     ! array of namelist informations on the fields to read
@@ -136,10 +141,10 @@
       TYPE(FLD_N) ::   sn_qlw , sn_tair, sn_prec, sn_snow      !   "                                 "
       TYPE(FLD_N) ::   sn_tdif                                 !   "                                 "
-      NAMELIST/namsbc_core/ cn_dir , ln_2m  , ln_taudif, rn_pfac, rn_efac, rn_vfac,  &
+      NAMELIST/namsbc_core/ cn_dir , ln_taudif, rn_pfac, rn_efac, rn_vfac,  &
          &                  sn_wndi, sn_wndj, sn_humi  , sn_qsr ,           &
          &                  sn_qlw , sn_tair, sn_prec  , sn_snow,           &
-         &                  sn_tdif, rn_zqt , ln_bulk2z, rn_zu
-      !!---------------------------------------------------------------------
-
+         &                  sn_tdif, rn_zqt,  rn_zu
+      !!---------------------------------------------------------------------
+      !
       !                                         ! ====================== !
       IF( kt == nit000 ) THEN                   !  First call kt=nit000  !
@@ -149,16 +154,16 @@
          READ  ( numnam_ref, namsbc_core, IOSTAT = ios, ERR = 901)
 901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_core in reference namelist', lwp )
-
+         !
          REWIND( numnam_cfg )              ! Namelist namsbc_core in configuration namelist : CORE bulk parameters
          READ  ( numnam_cfg, namsbc_core, IOSTAT = ios, ERR = 902 )
 902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_core in configuration namelist', lwp )
 
-         IF(lwm) WRITE ( numond, namsbc_core )
+         WRITE ( numond, namsbc_core )
          !                                         ! check: do we plan to use ln_dm2dc with non-daily forcing?
-         IF( ln_dm2dc .AND. sn_qsr%nfreqh /= 24 )   & 
-            &   CALL ctl_stop( 'sbc_blk_core: ln_dm2dc can be activated only with daily short-wave forcing' ) 
+         IF( ln_dm2dc .AND. sn_qsr%nfreqh /= 24 )   &
+            &   CALL ctl_stop( 'sbc_blk_core: ln_dm2dc can be activated only with daily short-wave forcing' )
          IF( ln_dm2dc .AND. sn_qsr%ln_tint ) THEN
             CALL ctl_warn( 'sbc_blk_core: ln_dm2dc is taking care of the temporal interpolation of daily qsr',   &
-                 &         '              ==> We force time interpolation = .false. for qsr' )
+               &         '              ==> We force time interpolation = .false. for qsr' )
             sn_qsr%ln_tint = .false.
          ENDIF
@@ -169,5 +174,5 @@
          slf_i(jp_prec) = sn_prec   ;   slf_i(jp_snow) = sn_snow
          slf_i(jp_tdif) = sn_tdif
-         !                 
+         !
          lhftau = ln_taudif                        ! do we use HF tau information?
          jfld = jpfld - COUNT( (/.NOT. lhftau/) )
@@ -191,5 +196,5 @@
       IF( MOD( kt - 1, nn_fsbc ) == 0 )   CALL blk_oce_core( kt, sf, sst_m, ssu_m, ssv_m )
 
-      ! If diurnal cycle is activated, compute a daily mean short waves flux for biogeochemistery 
+      ! If diurnal cycle is activated, compute a daily mean short waves flux for biogeochemistery
       IF( ltrcdm2dc )   CALL blk_bio_meanqsr
 
@@ -226,5 +231,4 @@
       !!              - qsr     : Solar heat flux over the ocean        (W/m2)
       !!              - qns     : Non Solar heat flux over the ocean    (W/m2)
-      !!              - evap    : Evaporation over the ocean            (kg/m2/s)
       !!              - emp     : evaporation minus precipitation       (kg/m2/s)
       !!
@@ -269,8 +273,5 @@
       zwnd_j(:,:) = 0.e0
 #if defined key_cyclone
-# if defined key_vectopt_loop
-!CDIR COLLAPSE
-# endif
-      CALL wnd_cyc( kt, zwnd_i, zwnd_j )    ! add Manu !
+      CALL wnd_cyc( kt, zwnd_i, zwnd_j )    ! add analytical tropical cyclone (Vincent et al. JGR 2012)
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vect. opt.
@@ -279,7 +280,4 @@
          END DO
       END DO
-#endif
-#if defined key_vectopt_loop
-!CDIR COLLAPSE
 #endif
       DO jj = 2, jpjm1
@@ -292,6 +290,4 @@
       CALL lbc_lnk( zwnd_j(:,:) , 'T', -1. )
       ! ... scalar wind ( = | U10m - U_oce | ) at T-point (masked)
-!CDIR NOVERRCHK
-!CDIR COLLAPSE
       wndm(:,:) = SQRT(  zwnd_i(:,:) * zwnd_i(:,:)   &
          &             + zwnd_j(:,:) * zwnd_j(:,:)  ) * tmask(:,:,1)
@@ -300,5 +296,5 @@
       !      I   Radiative FLUXES                                                     !
       ! ----------------------------------------------------------------------------- !
-    
+
       ! ocean albedo assumed to be constant + modify now Qsr to include the diurnal cycle                    ! Short Wave
       zztmp = 1. - albo
@@ -306,5 +302,4 @@
       ELSE                  ;   qsr(:,:) = zztmp *          sf(jp_qsr)%fnow(:,:,1)   * tmask(:,:,1)
       ENDIF
-!CDIR COLLAPSE
       zqlw(:,:) = (  sf(jp_qlw)%fnow(:,:,1) - Stef * zst(:,:)*zst(:,:)*zst(:,:)*zst(:,:)  ) * tmask(:,:,1)   ! Long  Wave
       ! ----------------------------------------------------------------------------- !
@@ -313,43 +308,10 @@
 
       ! ... specific humidity at SST and IST
-!CDIR NOVERRCHK
-!CDIR COLLAPSE
-      zqsatw(:,:) = zcoef_qsatw * EXP( -5107.4 / zst(:,:) ) 
+      zqsatw(:,:) = zcoef_qsatw * EXP( -5107.4 / zst(:,:) )
 
       ! ... NCAR Bulk formulae, computation of Cd, Ch, Ce at T-point :
-      IF( ln_2m ) THEN
-         !! If air temp. and spec. hum. are given at different height (2m) than wind (10m) :
-         CALL TURB_CORE_2Z(2.,10., zst   , sf(jp_tair)%fnow,         &
-            &                      zqsatw, sf(jp_humi)%fnow, wndm,   &
-            &                      Cd    , Ch              , Ce  ,   &
-            &                      zt_zu , zq_zu                   )
-      ELSE IF( ln_bulk2z ) THEN
-         !! If the height of the air temp./spec. hum. and wind are to be specified by hand :
-         IF( rn_zqt == rn_zu ) THEN
-            !! If air temp. and spec. hum. are at the same height as wind :
-            CALL TURB_CORE_1Z( rn_zu, zst   , sf(jp_tair)%fnow(:,:,1),       &
-               &                      zqsatw, sf(jp_humi)%fnow(:,:,1), wndm, &
-               &                      Cd    , Ch                     , Ce  )
-         ELSE
-            !! If air temp. and spec. hum. are at a different height to wind :
-            CALL TURB_CORE_2Z(rn_zqt, rn_zu , zst   , sf(jp_tair)%fnow,         &
-               &                              zqsatw, sf(jp_humi)%fnow, wndm,   &
-               &                              Cd    , Ch              , Ce  ,   &
-               &                              zt_zu , zq_zu                 )
-         ENDIF
-      ELSE
-         !! If air temp. and spec. hum. are given at same height than wind (10m) :
-!gm bug?  at the compiling phase, add a copy in temporary arrays...  ==> check perf
-!         CALL TURB_CORE_1Z( 10., zst   (:,:), sf(jp_tair)%fnow(:,:),              &
-!            &                    zqsatw(:,:), sf(jp_humi)%fnow(:,:), wndm(:,:),   &
-!            &                    Cd    (:,:),             Ch  (:,:), Ce  (:,:)  )
-!gm bug
-! ARPDBG - this won't compile with gfortran. Fix but check performance
-! as per comment above.
-         CALL TURB_CORE_1Z( 10., zst   , sf(jp_tair)%fnow(:,:,1),       &
-            &                    zqsatw, sf(jp_humi)%fnow(:,:,1), wndm, &
-            &                    Cd    , Ch              , Ce    )
-      ENDIF
-
+      CALL turb_core_2z( rn_zqt, rn_zu, zst, sf(jp_tair)%fnow, zqsatw, sf(jp_humi)%fnow, wndm,   &
+         &               Cd, Ch, Ce, zt_zu, zq_zu )
+    
       ! ... tau module, i and j component
       DO jj = 1, jpj
@@ -363,6 +325,5 @@
 
       ! ... add the HF tau contribution to the wind stress module?
-      IF( lhftau ) THEN 
-!CDIR COLLAPSE
+      IF( lhftau ) THEN
          taum(:,:) = taum(:,:) + sf(jp_tdif)%fnow(:,:,1)
       ENDIF
@@ -383,17 +344,17 @@
       CALL lbc_lnk( vtau(:,:), 'V', -1. )
 
+    
       !  Turbulent fluxes over ocean
       ! -----------------------------
-      IF( ln_2m .OR. ( ln_bulk2z .AND. rn_zqt /= rn_zu ) ) THEN
-         ! Values of temp. and hum. adjusted to height of wind must be used
-         zevap(:,:) = rn_efac * MAX( 0.e0, rhoa    *Ce(:,:)*( zqsatw(:,:) - zq_zu(:,:) ) * wndm(:,:) )   ! Evaporation
-         zqsb (:,:) =                      rhoa*cpa*Ch(:,:)*( zst   (:,:) - zt_zu(:,:) ) * wndm(:,:)     ! Sensible Heat
+      IF( ABS( rn_zu - rn_zqt) < 0.01_wp ) THEN
+         !! q_air and t_air are (or "are almost") given at 10m (wind reference height)
+         zevap(:,:) = rn_efac*MAX( 0._wp,     rhoa*Ce(:,:)*( zqsatw(:,:) - sf(jp_humi)%fnow(:,:,1) )*wndm(:,:) ) ! Evaporation
+         zqsb (:,:) =                     cpa*rhoa*Ch(:,:)*( zst   (:,:) - sf(jp_tair)%fnow(:,:,1) )*wndm(:,:)   ! Sensible Heat
       ELSE
-!CDIR COLLAPSE
-         zevap(:,:) = rn_efac * MAX( 0.e0, rhoa    *Ce(:,:)*( zqsatw(:,:) - sf(jp_humi)%fnow(:,:,1) ) * wndm(:,:) )   ! Evaporation
-!CDIR COLLAPSE
-         zqsb (:,:) =            rhoa*cpa*Ch(:,:)*( zst   (:,:) - sf(jp_tair)%fnow(:,:,1) ) * wndm(:,:)     ! Sensible Heat
+         !! q_air and t_air are not given at 10m (wind reference height)
+         ! Values of temp. and hum. adjusted to height of wind during bulk algorithm iteration must be used!!!
+         zevap(:,:) = rn_efac*MAX( 0._wp,     rhoa*Ce(:,:)*( zqsatw(:,:) - zq_zu(:,:) )*wndm(:,:) )   ! Evaporation
+         zqsb (:,:) =                     cpa*rhoa*Ch(:,:)*( zst   (:,:) - zt_zu(:,:) )*wndm(:,:)     ! Sensible Heat
       ENDIF
-!CDIR COLLAPSE
       zqla (:,:) = Lv * zevap(:,:)                                                              ! Latent Heat
 
@@ -412,14 +373,12 @@
       !     III    Total FLUXES                                                       !
       ! ----------------------------------------------------------------------------- !
-     
-!CDIR COLLAPSE
+      !
       emp (:,:) = (  zevap(:,:)                                          &   ! mass flux (evap. - precip.)
          &         - sf(jp_prec)%fnow(:,:,1) * rn_pfac  ) * tmask(:,:,1)
-!CDIR COLLAPSE
       qns(:,:) = zqlw(:,:) - zqsb(:,:) - zqla(:,:)                                &   ! Downward Non Solar flux
          &     - sf(jp_snow)%fnow(:,:,1) * rn_pfac * lfus                         &   ! remove latent melting heat for solid precip
          &     - zevap(:,:) * pst(:,:) * rcp                                      &   ! remove evap heat content at SST
          &     + ( sf(jp_prec)%fnow(:,:,1) - sf(jp_snow)%fnow(:,:,1) ) * rn_pfac  &   ! add liquid precip heat content at Tair
-         &     * ( sf(jp_tair)%fnow(:,:,1) - rt0 ) * rcp                          &   
+         &     * ( sf(jp_tair)%fnow(:,:,1) - rt0 ) * rcp                          &
          &     + sf(jp_snow)%fnow(:,:,1) * rn_pfac                                &   ! add solid  precip heat content at min(Tair,Tsnow)
          &     * ( MIN( sf(jp_tair)%fnow(:,:,1), rt0_snow ) - rt0 ) * cpic * tmask(:,:,1)
@@ -445,58 +404,4 @@
       !
    END SUBROUTINE blk_oce_core
-  
-   SUBROUTINE blk_bio_meanqsr
-      !!---------------------------------------------------------------------
-      !!                     ***  ROUTINE blk_bio_meanqsr
-      !!                     
-      !! ** Purpose :   provide daily qsr_mean for PISCES when
-      !!                analytic diurnal cycle is applied in physic
-      !!                
-      !! ** Method  :   add part where there is no ice
-      !! 
-      !!---------------------------------------------------------------------
-      IF( nn_timing == 1 )  CALL timing_start('blk_bio_meanqsr')
-
-      qsr_mean(:,:) = (1. - albo ) *  sf(jp_qsr)%fnow(:,:,1)
-
-      IF( nn_timing == 1 )  CALL timing_stop('blk_bio_meanqsr')
-
-   END SUBROUTINE blk_bio_meanqsr
- 
- 
-   SUBROUTINE blk_ice_meanqsr(palb,p_qsr_mean,pdim)
-      !!---------------------------------------------------------------------
-      !!
-      !! ** Purpose :   provide the daily qsr_mean over sea_ice for PISCES when
-      !!                analytic diurnal cycle is applied in physic
-      !!
-      !! ** Method  :   compute qsr
-      !! 
-      !!---------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   palb       ! ice albedo (clear sky) (alb_ice_cs)               [%]
-      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   p_qsr_mean !     solar heat flux over ice (T-point)         [W/m2]
-      INTEGER                   , INTENT(in   ) ::   pdim       ! number of ice categories
-      !!
-      INTEGER  ::   ijpl          ! number of ice categories (size of 3rd dim of input arrays)
-      INTEGER  ::   ji, jj, jl    ! dummy loop indices
-      REAL(wp) ::   zztmp         ! temporary variable
-      !!---------------------------------------------------------------------
-      IF( nn_timing == 1 )  CALL timing_start('blk_ice_meanqsr')
-      !
-      ijpl  = pdim                            ! number of ice categories
-      zztmp = 1. / ( 1. - albo )
-      !                                     ! ========================== !
-      DO jl = 1, ijpl                       !  Loop over ice categories  !
-         !                                  ! ========================== !
-         DO jj = 1 , jpj
-            DO ji = 1, jpi
-                  p_qsr_mean(ji,jj,jl) = zztmp * ( 1. - palb(ji,jj,jl) ) * qsr_mean(ji,jj)
-            END DO
-         END DO
-      END DO
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('blk_ice_meanqsr')
-      !
-   END SUBROUTINE blk_ice_meanqsr  
  
    
@@ -521,5 +426,5 @@
       REAL(wp), DIMENSION(:,:)  , INTENT(in   ) ::   pui      ! ice surface velocity (i- and i- components      [m/s]
       REAL(wp), DIMENSION(:,:)  , INTENT(in   ) ::   pvi      !    at I-point (B-grid) or U & V-point (C-grid)
-      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   palb     ! ice albedo (clear sky) (alb_ice_cs)               [%]
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   palb     ! ice albedo (all skies)                            [%]
       REAL(wp), DIMENSION(:,:)  , INTENT(  out) ::   p_taui   ! i- & j-components of surface ice stress        [N/m2]
       REAL(wp), DIMENSION(:,:)  , INTENT(  out) ::   p_tauj   !   at I-point (B-grid) or U & V-point (C-grid)
@@ -541,5 +446,4 @@
       REAL(wp) ::   zcoef_wnorm, zcoef_wnorm2, zcoef_dqlw, zcoef_dqla, zcoef_dqsb
       REAL(wp) ::   zztmp                                        ! temporary variable
-      REAL(wp) ::   zcoef_frca                                   ! fractional cloud amount
       REAL(wp) ::   zwnorm_f, zwndi_f , zwndj_f                  ! relative wind module and components at F-point
       REAL(wp) ::             zwndi_t , zwndj_t                  ! relative wind components at T-point
@@ -565,7 +469,4 @@
       zcoef_dqla   = -Ls * Cice * 11637800. * (-5897.8)
       zcoef_dqsb   = rhoa * cpa * Cice
-      zcoef_frca   = 1.0  - 0.3
-      ! MV 2014 the proper cloud fraction (mean summer months from the CLIO climato, NH+SH) is 0.19
-      zcoef_frca   = 1.0  - 0.19
 
 !!gm brutal....
@@ -584,5 +485,4 @@
       CASE( 'I' )                  ! B-grid ice dynamics :   I-point (i.e. F-point with sea-ice indexation)
          !                           and scalar wind at T-point ( = | U10m - U_ice | ) (masked)
-!CDIR NOVERRCHK
          DO jj = 2, jpjm1
             DO ji = 2, jpim1   ! B grid : NO vector opt
@@ -609,7 +509,4 @@
          !
       CASE( 'C' )                  ! C-grid ice dynamics :   U & V-points (same as ocean)
-#if defined key_vectopt_loop
-!CDIR COLLAPSE
-#endif
          DO jj = 2, jpj
             DO ji = fs_2, jpi   ! vect. opt.
@@ -619,7 +516,4 @@
             END DO
          END DO
-#if defined key_vectopt_loop
-!CDIR COLLAPSE
-#endif
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vect. opt.
@@ -640,8 +534,5 @@
       DO jl = 1, ijpl                       !  Loop over ice categories  !
          !                                  ! ========================== !
-!CDIR NOVERRCHK
-!CDIR COLLAPSE
          DO jj = 1 , jpj
-!CDIR NOVERRCHK
             DO ji = 1, jpi
                ! ----------------------------!
@@ -668,11 +559,10 @@
                   &                         * (  11637800. * EXP( -5897.8 / pst(ji,jj,jl) ) / rhoa - sf(jp_humi)%fnow(ji,jj,1)  ) )
                ! Latent heat sensitivity for ice (Dqla/Dt)
-               ! MV we also have to cap the sensitivity if the flux is zero
-               IF ( p_qla(ji,jj,jl) .GT. 0.0 ) THEN
+               IF( p_qla(ji,jj,jl) > 0._wp ) THEN
                   p_dqla(ji,jj,jl) = rn_efac * zcoef_dqla * z_wnds_t(ji,jj) / ( zst2 ) * EXP( -5897.8 / pst(ji,jj,jl) )
                ELSE
-                  p_dqla(ji,jj,jl) = 0.0
+                  p_dqla(ji,jj,jl) = 0._wp
                ENDIF
-                             
+
                ! Sensible heat sensitivity (Dqsb_ice/Dtn_ice)
                z_dqsb(ji,jj,jl) = zcoef_dqsb * z_wnds_t(ji,jj)
@@ -682,7 +572,7 @@
                ! ----------------------------!
                ! Downward Non Solar flux
-               p_qns (ji,jj,jl) =     z_qlw (ji,jj,jl) - z_qsb (ji,jj,jl) - p_qla (ji,jj,jl)      
+               p_qns (ji,jj,jl) =     z_qlw (ji,jj,jl) - z_qsb (ji,jj,jl) - p_qla (ji,jj,jl)
                ! Total non solar heat flux sensitivity for ice
-               p_dqns(ji,jj,jl) = - ( z_dqlw(ji,jj,jl) + z_dqsb(ji,jj,jl) + p_dqla(ji,jj,jl) )    
+               p_dqns(ji,jj,jl) = - ( z_dqlw(ji,jj,jl) + z_dqsb(ji,jj,jl) + p_dqla(ji,jj,jl) )
             END DO
             !
@@ -695,16 +585,12 @@
       ! thin surface layer and penetrates inside the ice cover
       ! ( Maykut and Untersteiner, 1971 ; Ebert and Curry, 1993 )
-    
-!CDIR COLLAPSE
-      p_fr1(:,:) = ( 0.18 * ( 1.0 - zcoef_frca ) + 0.35 * zcoef_frca )
-!CDIR COLLAPSE
-      p_fr2(:,:) = ( 0.82 * ( 1.0 - zcoef_frca ) + 0.65 * zcoef_frca )
-       
-!CDIR COLLAPSE
+      !
+      p_fr1(:,:) = ( 0.18 * ( 1.0 - cldf_ice ) + 0.35 * cldf_ice )
+      p_fr2(:,:) = ( 0.82 * ( 1.0 - cldf_ice ) + 0.65 * cldf_ice )
+      !
       p_tpr(:,:) = sf(jp_prec)%fnow(:,:,1) * rn_pfac      ! total precipitation [kg/m2/s]
-!CDIR COLLAPSE
       p_spr(:,:) = sf(jp_snow)%fnow(:,:,1) * rn_pfac      ! solid precipitation [kg/m2/s]
-      CALL iom_put( 'snowpre', p_spr * 86400. )                  ! Snow precipitation 
-      CALL iom_put( 'precip', p_tpr * 86400. )                   ! Total precipitation 
+      CALL iom_put( 'snowpre', p_spr * 86400. )                  ! Snow precipitation
+      CALL iom_put( 'precip' , p_tpr * 86400. )                  ! Total precipitation
       !
       IF(ln_ctl) THEN
@@ -719,163 +605,90 @@
       ENDIF
 
-      CALL wrk_dealloc( jpi,jpj, z_wnds_t )
-      CALL wrk_dealloc( jpi,jpj,pdim, z_qlw, z_qsb, z_dqlw, z_dqsb ) 
+      CALL wrk_dealloc( jpi,jpj,   z_wnds_t )
+      CALL wrk_dealloc( jpi,jpj,   pdim, z_qlw, z_qsb, z_dqlw, z_dqsb )
       !
       IF( nn_timing == 1 )  CALL timing_stop('blk_ice_core')
       !
    END SUBROUTINE blk_ice_core
-  
-
-   SUBROUTINE TURB_CORE_1Z(zu, sst, T_a, q_sat, q_a,   &
-      &                        dU , Cd , Ch   , Ce   )
+
+
+   SUBROUTINE blk_bio_meanqsr
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE blk_bio_meanqsr
+      !!                     
+      !! ** Purpose :   provide daily qsr_mean for PISCES when
+      !!                analytic diurnal cycle is applied in physic
+      !!                
+      !! ** Method  :   add part where there is no ice
+      !! 
+      !!---------------------------------------------------------------------
+      IF( nn_timing == 1 )  CALL timing_start('blk_bio_meanqsr')
+      !
+      qsr_mean(:,:) = (1. - albo ) *  sf(jp_qsr)%fnow(:,:,1)
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('blk_bio_meanqsr')
+      !
+   END SUBROUTINE blk_bio_meanqsr
+ 
+ 
+   SUBROUTINE blk_ice_meanqsr( palb, p_qsr_mean, pdim )
+      !!---------------------------------------------------------------------
+      !!
+      !! ** Purpose :   provide the daily qsr_mean over sea_ice for PISCES when
+      !!                analytic diurnal cycle is applied in physic
+      !!
+      !! ** Method  :   compute qsr
+      !! 
+      !!---------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   palb       ! ice albedo (clear sky) (alb_ice_cs)               [%]
+      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   p_qsr_mean !     solar heat flux over ice (T-point)         [W/m2]
+      INTEGER                   , INTENT(in   ) ::   pdim       ! number of ice categories
+      !
+      INTEGER  ::   ijpl          ! number of ice categories (size of 3rd dim of input arrays)
+      INTEGER  ::   ji, jj, jl    ! dummy loop indices
+      REAL(wp) ::   zztmp         ! temporary variable
+      !!---------------------------------------------------------------------
+      IF( nn_timing == 1 )  CALL timing_start('blk_ice_meanqsr')
+      !
+      ijpl  = pdim                            ! number of ice categories
+      zztmp = 1. / ( 1. - albo )
+      !                                     ! ========================== !
+      DO jl = 1, ijpl                       !  Loop over ice categories  !
+         !                                  ! ========================== !
+         DO jj = 1 , jpj
+            DO ji = 1, jpi
+                  p_qsr_mean(ji,jj,jl) = zztmp * ( 1. - palb(ji,jj,jl) ) * qsr_mean(ji,jj)
+            END DO
+         END DO
+      END DO
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('blk_ice_meanqsr')
+      !
+   END SUBROUTINE blk_ice_meanqsr  
+
+
+   SUBROUTINE turb_core_2z( zt, zu, sst, T_zt, q_sat, q_zt, dU,    &
+      &                      Cd, Ch, Ce , T_zu, q_zu )
       !!----------------------------------------------------------------------
       !!                      ***  ROUTINE  turb_core  ***
       !!
       !! ** Purpose :   Computes turbulent transfert coefficients of surface
-      !!                fluxes according to Large & Yeager (2004)
-      !!
-      !! ** Method  :   I N E R T I A L   D I S S I P A T I O N   M E T H O D
-      !!      Momentum, Latent and sensible heat exchange coefficients
-      !!      Caution: this procedure should only be used in cases when air
-      !!      temperature (T_air), air specific humidity (q_air) and wind (dU)
-      !!      are provided at the same height 'zzu'!
-      !!
-      !! References :   Large & Yeager, 2004 : ???
-      !!----------------------------------------------------------------------
-      REAL(wp)                , INTENT(in   ) ::   zu      ! altitude of wind measurement       [m]
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   sst     ! sea surface temperature         [Kelvin]
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   T_a     ! potential air temperature       [Kelvin]
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   q_sat   ! sea surface specific humidity   [kg/kg]
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   q_a     ! specific air humidity           [kg/kg]
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   dU      ! wind module |U(zu)-U(0)|        [m/s]
-      REAL(wp), DIMENSION(:,:), INTENT(  out) ::   Cd      ! transfert coefficient for momentum       (tau)
-      REAL(wp), DIMENSION(:,:), INTENT(  out) ::   Ch      ! transfert coefficient for temperature (Q_sens)
-      REAL(wp), DIMENSION(:,:), INTENT(  out) ::   Ce      ! transfert coefficient for evaporation  (Q_lat)
-      !!
-      INTEGER :: j_itt
-      INTEGER , PARAMETER ::   nb_itt = 3
-      REAL(wp), PARAMETER ::   grav   = 9.8   ! gravity                       
-      REAL(wp), PARAMETER ::   kappa  = 0.4   ! von Karman s constant
-
-      REAL(wp), DIMENSION(:,:), POINTER  ::   dU10          ! dU                                   [m/s]
-      REAL(wp), DIMENSION(:,:), POINTER  ::   dT            ! air/sea temperature differeence      [K]
-      REAL(wp), DIMENSION(:,:), POINTER  ::   dq            ! air/sea humidity difference          [K]
-      REAL(wp), DIMENSION(:,:), POINTER  ::   Cd_n10        ! 10m neutral drag coefficient
-      REAL(wp), DIMENSION(:,:), POINTER  ::   Ce_n10        ! 10m neutral latent coefficient
-      REAL(wp), DIMENSION(:,:), POINTER  ::   Ch_n10        ! 10m neutral sensible coefficient
-      REAL(wp), DIMENSION(:,:), POINTER  ::   sqrt_Cd_n10   ! root square of Cd_n10
-      REAL(wp), DIMENSION(:,:), POINTER  ::   sqrt_Cd       ! root square of Cd
-      REAL(wp), DIMENSION(:,:), POINTER  ::   T_vpot        ! virtual potential temperature        [K]
-      REAL(wp), DIMENSION(:,:), POINTER  ::   T_star        ! turbulent scale of tem. fluct.
-      REAL(wp), DIMENSION(:,:), POINTER  ::   q_star        ! turbulent humidity of temp. fluct.
-      REAL(wp), DIMENSION(:,:), POINTER  ::   U_star        ! turb. scale of velocity fluct.
-      REAL(wp), DIMENSION(:,:), POINTER  ::   L             ! Monin-Obukov length                  [m]
-      REAL(wp), DIMENSION(:,:), POINTER  ::   zeta          ! stability parameter at height zu
-      REAL(wp), DIMENSION(:,:), POINTER  ::   U_n10         ! neutral wind velocity at 10m         [m]   
-      REAL(wp), DIMENSION(:,:), POINTER  ::   xlogt, xct, zpsi_h, zpsi_m
-      
-      INTEGER , DIMENSION(:,:), POINTER  ::   stab          ! 1st guess stability test integer
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('TURB_CORE_1Z')
-      !
-      CALL wrk_alloc( jpi,jpj, stab )   ! integer
-      CALL wrk_alloc( jpi,jpj, dU10, dT, dq, Cd_n10, Ce_n10, Ch_n10, sqrt_Cd_n10, sqrt_Cd, L )
-      CALL wrk_alloc( jpi,jpj, T_vpot, T_star, q_star, U_star, zeta, U_n10, xlogt, xct, zpsi_h, zpsi_m )
-
-      !! * Start
-      !! Air/sea differences
-      dU10 = max(0.5, dU)     ! we don't want to fall under 0.5 m/s
-      dT = T_a - sst          ! assuming that T_a is allready the potential temp. at zzu
-      dq = q_a - q_sat
-      !!    
-      !! Virtual potential temperature
-      T_vpot = T_a*(1. + 0.608*q_a)
-      !!
-      !! Neutral Drag Coefficient
-      stab    = 0.5 + sign(0.5,dT)    ! stable : stab = 1 ; unstable : stab = 0 
-      IF  ( ln_cdgw ) THEN
-        cdn_wave = cdn_wave - rsmall*(tmask(:,:,1)-1)
-        Cd_n10(:,:) =   cdn_wave
-      ELSE
-        Cd_n10  = 1.e-3 * ( 2.7/dU10 + 0.142 + dU10/13.09 )    !   L & Y eq. (6a)
-      ENDIF
-      sqrt_Cd_n10 = sqrt(Cd_n10)
-      Ce_n10  = 1.e-3 * ( 34.6 * sqrt_Cd_n10 )               !   L & Y eq. (6b)
-      Ch_n10  = 1.e-3*sqrt_Cd_n10*(18.*stab + 32.7*(1.-stab)) !   L & Y eq. (6c), (6d)
-      !!
-      !! Initializing transfert coefficients with their first guess neutral equivalents :
-      Cd = Cd_n10 ;  Ce = Ce_n10 ;  Ch = Ch_n10 ;  sqrt_Cd = sqrt(Cd)
-
-      !! * Now starting iteration loop
-      DO j_itt=1, nb_itt
-         !! Turbulent scales :
-         U_star  = sqrt_Cd*dU10                !   L & Y eq. (7a)
-         T_star  = Ch/sqrt_Cd*dT               !   L & Y eq. (7b)
-         q_star  = Ce/sqrt_Cd*dq               !   L & Y eq. (7c)
-
-         !! Estimate the Monin-Obukov length :
-         L  = (U_star**2)/( kappa*grav*(T_star/T_vpot + q_star/(q_a + 1./0.608)) )
-
-         !! Stability parameters :
-         zeta  = zu/L ;  zeta   = sign( min(abs(zeta),10.0), zeta )
-         zpsi_h  = psi_h(zeta)
-         zpsi_m  = psi_m(zeta)
-
-         IF  ( ln_cdgw ) THEN
-           sqrt_Cd=kappa/((kappa/sqrt_Cd_n10) - zpsi_m) ; Cd=sqrt_Cd*sqrt_Cd;
-         ELSE
-           !! Shifting the wind speed to 10m and neutral stability :  L & Y eq. (9a)
-           !   In very rare low-wind conditions, the old way of estimating the
-           !   neutral wind speed at 10m leads to a negative value that causes the code
-           !   to crash. To prevent this a threshold of 0.25m/s is now imposed.
-           U_n10 = MAX( 0.25 , dU10/(1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m)) )
-
-           !! Updating the neutral 10m transfer coefficients :
-           Cd_n10  = 1.e-3 * (2.7/U_n10 + 0.142 + U_n10/13.09)              !  L & Y eq. (6a)
-           sqrt_Cd_n10 = sqrt(Cd_n10)
-           Ce_n10  = 1.e-3 * (34.6 * sqrt_Cd_n10)                           !  L & Y eq. (6b)
-           stab    = 0.5 + sign(0.5,zeta)
-           Ch_n10  = 1.e-3*sqrt_Cd_n10*(18.*stab + 32.7*(1.-stab))           !  L & Y eq. (6c), (6d)
-
-           !! Shifting the neutral  10m transfer coefficients to ( zu , zeta ) :
-           !!
-           xct = 1. + sqrt_Cd_n10/kappa*(log(zu/10) - zpsi_m)
-           Cd  = Cd_n10/(xct*xct) ;  sqrt_Cd = sqrt(Cd)
-         ENDIF
-         !!
-         xlogt = log(zu/10.) - zpsi_h
-         !!
-         xct = 1. + Ch_n10*xlogt/kappa/sqrt_Cd_n10
-         Ch  = Ch_n10*sqrt_Cd/sqrt_Cd_n10/xct
-         !!
-         xct = 1. + Ce_n10*xlogt/kappa/sqrt_Cd_n10
-         Ce  = Ce_n10*sqrt_Cd/sqrt_Cd_n10/xct
-         !!
-      END DO
-      !!
-      CALL wrk_dealloc( jpi,jpj, stab )   ! integer
-      CALL wrk_dealloc( jpi,jpj, dU10, dT, dq, Cd_n10, Ce_n10, Ch_n10, sqrt_Cd_n10, sqrt_Cd, L )
-      CALL wrk_dealloc( jpi,jpj, T_vpot, T_star, q_star, U_star, zeta, U_n10, xlogt, xct, zpsi_h, zpsi_m )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('TURB_CORE_1Z')
-      !
-    END SUBROUTINE TURB_CORE_1Z
-
-
-    SUBROUTINE TURB_CORE_2Z(zt, zu, sst, T_zt, q_sat, q_zt, dU, Cd, Ch, Ce, T_zu, q_zu)
-      !!----------------------------------------------------------------------
-      !!                      ***  ROUTINE  turb_core  ***
-      !!
-      !! ** Purpose :   Computes turbulent transfert coefficients of surface 
-      !!                fluxes according to Large & Yeager (2004).
-      !!
-      !! ** Method  :   I N E R T I A L   D I S S I P A T I O N   M E T H O D
-      !!      Momentum, Latent and sensible heat exchange coefficients
-      !!      Caution: this procedure should only be used in cases when air
-      !!      temperature (T_air) and air specific humidity (q_air) are at a
-      !!      different height to wind (dU).
-      !!
-      !! References :   Large & Yeager, 2004 : ???
+      !!                fluxes according to Large & Yeager (2004) and Large & Yeager (2008)
+      !!                If relevant (zt /= zu), adjust temperature and humidity from height zt to zu
+      !!
+      !! ** Method : Monin Obukhov Similarity Theory 
+      !!             + Large & Yeager (2004,2008) closure: CD_n10 = f(U_n10)
+      !!
+      !! ** References :   Large & Yeager, 2004 / Large & Yeager, 2008
+      !!
+      !! ** Last update: Laurent Brodeau, June 2014:
+      !!    - handles both cases zt=zu and zt/=zu
+      !!    - optimized: less 2D arrays allocated and less operations
+      !!    - better first guess of stability by checking air-sea difference of virtual temperature
+      !!       rather than temperature difference only...
+      !!    - added function "cd_neutral_10m" that uses the improved parametrization of 
+      !!      Large & Yeager 2008. Drag-coefficient reduction for Cyclone conditions!
+      !!    - using code-wide physical constants defined into "phycst.mod" rather than redifining them
+      !!      => 'vkarmn' and 'grav'
       !!----------------------------------------------------------------------
       REAL(wp), INTENT(in   )                     ::   zt       ! height for T_zt and q_zt                   [m]
@@ -885,5 +698,5 @@
       REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   q_sat    ! sea surface specific humidity         [kg/kg]
       REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   q_zt     ! specific air humidity                 [kg/kg]
-      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   dU       ! relative wind module |U(zu)-U(0)|       [m/s]
+      REAL(wp), INTENT(in   ), DIMENSION(jpi,jpj) ::   dU       ! relative wind module at zu            [m/s]
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   Cd       ! transfer coefficient for momentum         (tau)
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   Ch       ! transfer coefficient for sensible heat (Q_sens)
@@ -891,170 +704,199 @@
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   T_zu     ! air temp. shifted at zu                     [K]
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   q_zu     ! spec. hum.  shifted at zu               [kg/kg]
-
-      INTEGER :: j_itt
-      INTEGER , PARAMETER :: nb_itt = 5              ! number of itterations
-      REAL(wp), PARAMETER ::   grav   = 9.8          ! gravity                       
-      REAL(wp), PARAMETER ::   kappa  = 0.4          ! von Karman's constant
-      
-      REAL(wp), DIMENSION(:,:), POINTER ::   dU10          ! dU                                [m/s]
-      REAL(wp), DIMENSION(:,:), POINTER ::   dT            ! air/sea temperature differeence   [K]
-      REAL(wp), DIMENSION(:,:), POINTER ::   dq            ! air/sea humidity difference       [K]
-      REAL(wp), DIMENSION(:,:), POINTER ::   Cd_n10        ! 10m neutral drag coefficient
+      !
+      INTEGER ::   j_itt
+      INTEGER , PARAMETER ::   nb_itt = 5       ! number of itterations
+      LOGICAL ::   l_zt_equal_zu = .FALSE.      ! if q and t are given at different height than U
+      !
+      REAL(wp), DIMENSION(:,:), POINTER ::   U_zu          ! relative wind at zu                            [m/s]
       REAL(wp), DIMENSION(:,:), POINTER ::   Ce_n10        ! 10m neutral latent coefficient
       REAL(wp), DIMENSION(:,:), POINTER ::   Ch_n10        ! 10m neutral sensible coefficient
       REAL(wp), DIMENSION(:,:), POINTER ::   sqrt_Cd_n10   ! root square of Cd_n10
       REAL(wp), DIMENSION(:,:), POINTER ::   sqrt_Cd       ! root square of Cd
-      REAL(wp), DIMENSION(:,:), POINTER ::   T_vpot        ! virtual potential temperature        [K]
-      REAL(wp), DIMENSION(:,:), POINTER ::   T_star        ! turbulent scale of tem. fluct.
-      REAL(wp), DIMENSION(:,:), POINTER ::   q_star        ! turbulent humidity of temp. fluct.
-      REAL(wp), DIMENSION(:,:), POINTER ::   U_star        ! turb. scale of velocity fluct.
-      REAL(wp), DIMENSION(:,:), POINTER ::   L             ! Monin-Obukov length                  [m]
       REAL(wp), DIMENSION(:,:), POINTER ::   zeta_u        ! stability parameter at height zu
       REAL(wp), DIMENSION(:,:), POINTER ::   zeta_t        ! stability parameter at height zt
-      REAL(wp), DIMENSION(:,:), POINTER ::   U_n10         ! neutral wind velocity at 10m        [m]
-      REAL(wp), DIMENSION(:,:), POINTER ::   xlogt, xct, zpsi_hu, zpsi_ht, zpsi_m
-
-      INTEGER , DIMENSION(:,:), POINTER ::   stab          ! 1st stability test integer
+      REAL(wp), DIMENSION(:,:), POINTER ::   zpsi_h_u, zpsi_m_u
+      REAL(wp), DIMENSION(:,:), POINTER ::   ztmp0, ztmp1, ztmp2
+      REAL(wp), DIMENSION(:,:), POINTER ::   stab          ! 1st stability test integer
       !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('TURB_CORE_2Z')
-      !
-      CALL wrk_alloc( jpi,jpj, dU10, dT, dq, Cd_n10, Ce_n10, Ch_n10, sqrt_Cd_n10, sqrt_Cd, L )
-      CALL wrk_alloc( jpi,jpj, T_vpot, T_star, q_star, U_star, zeta_u, zeta_t, U_n10 )
-      CALL wrk_alloc( jpi,jpj, xlogt, xct, zpsi_hu, zpsi_ht, zpsi_m )
-      CALL wrk_alloc( jpi,jpj, stab )   ! interger
-
-      !! Initial air/sea differences
-      dU10 = max(0.5, dU)      !  we don't want to fall under 0.5 m/s
-      dT = T_zt - sst 
-      dq = q_zt - q_sat
-
-      !! Neutral Drag Coefficient :
-      stab = 0.5 + sign(0.5,dT)                 ! stab = 1  if dT > 0  -> STABLE
-      IF( ln_cdgw ) THEN
-        cdn_wave = cdn_wave - rsmall*(tmask(:,:,1)-1)
-        Cd_n10(:,:) =   cdn_wave
+
+      IF( nn_timing == 1 )  CALL timing_start('turb_core_2z')
+    
+      CALL wrk_alloc( jpi,jpj, U_zu, Ce_n10, Ch_n10, sqrt_Cd_n10, sqrt_Cd )
+      CALL wrk_alloc( jpi,jpj, zeta_u, stab )
+      CALL wrk_alloc( jpi,jpj, zpsi_h_u, zpsi_m_u, ztmp0, ztmp1, ztmp2 )
+
+      l_zt_equal_zu = .FALSE.
+      IF( ABS(zu - zt) < 0.01 ) l_zt_equal_zu = .TRUE.    ! testing "zu == zt" is risky with double precision
+
+      IF( .NOT. l_zt_equal_zu )   CALL wrk_alloc( jpi,jpj, zeta_t )
+
+      U_zu = MAX( 0.5 , dU )   !  relative wind speed at zu (normally 10m), we don't want to fall under 0.5 m/s
+
+      !! First guess of stability: 
+      ztmp0 = T_zt*(1. + 0.608*q_zt) - sst*(1. + 0.608*q_sat) ! air-sea difference of virtual pot. temp. at zt
+      stab  = 0.5 + sign(0.5,ztmp0)                           ! stab = 1 if dTv > 0  => STABLE, 0 if unstable
+
+      !! Neutral coefficients at 10m:
+      IF( ln_cdgw ) THEN      ! wave drag case
+         cdn_wave(:,:) = cdn_wave(:,:) + rsmall * ( 1._wp - tmask(:,:,1) )
+         ztmp0   (:,:) = cdn_wave(:,:)
       ELSE
-        Cd_n10  = 1.e-3*( 2.7/dU10 + 0.142 + dU10/13.09 ) 
+         ztmp0 = cd_neutral_10m( U_zu )
       ENDIF
-      sqrt_Cd_n10 = sqrt(Cd_n10)
+      sqrt_Cd_n10 = SQRT( ztmp0 )
       Ce_n10  = 1.e-3*( 34.6 * sqrt_Cd_n10 )
       Ch_n10  = 1.e-3*sqrt_Cd_n10*(18.*stab + 32.7*(1. - stab))
-
+    
       !! Initializing transf. coeff. with their first guess neutral equivalents :
-      Cd = Cd_n10 ;  Ce = Ce_n10 ;  Ch = Ch_n10 ;  sqrt_Cd = sqrt(Cd)
-
-      !! Initializing z_u values with z_t values :
-      T_zu = T_zt ;  q_zu = q_zt
+      Cd = ztmp0   ;   Ce = Ce_n10   ;   Ch = Ch_n10   ;   sqrt_Cd = sqrt_Cd_n10
+
+      !! Initializing values at z_u with z_t values:
+      T_zu = T_zt   ;   q_zu = q_zt
 
       !!  * Now starting iteration loop
       DO j_itt=1, nb_itt
-         dT = T_zu - sst ;  dq = q_zu - q_sat ! Updating air/sea differences
-         T_vpot = T_zu*(1. + 0.608*q_zu)    ! Updating virtual potential temperature at zu
-         U_star = sqrt_Cd*dU10                ! Updating turbulent scales :   (L & Y eq. (7))
-         T_star  = Ch/sqrt_Cd*dT              !
-         q_star  = Ce/sqrt_Cd*dq              !
-         !!
-         L = (U_star*U_star) &                ! Estimate the Monin-Obukov length at height zu
-              & / (kappa*grav/T_vpot*(T_star*(1.+0.608*q_zu) + 0.608*T_zu*q_star))
+         !
+         ztmp1 = T_zu - sst   ! Updating air/sea differences
+         ztmp2 = q_zu - q_sat 
+
+         ! Updating turbulent scales :   (L&Y 2004 eq. (7))
+         ztmp1  = Ch/sqrt_Cd*ztmp1    ! theta*
+         ztmp2  = Ce/sqrt_Cd*ztmp2    ! q*
+       
+         ztmp0 = T_zu*(1. + 0.608*q_zu) ! virtual potential temperature at zu
+
+         ! Estimate the inverse of Monin-Obukov length (1/L) at height zu:
+         ztmp0 =  (vkarmn*grav/ztmp0*(ztmp1*(1.+0.608*q_zu) + 0.608*T_zu*ztmp2)) / (Cd*U_zu*U_zu) 
+         !                                                                     ( Cd*U_zu*U_zu is U*^2 at zu)
+
          !! Stability parameters :
-         zeta_u  = zu/L  ;  zeta_u = sign( min(abs(zeta_u),10.0), zeta_u )
-         zeta_t  = zt/L  ;  zeta_t = sign( min(abs(zeta_t),10.0), zeta_t )
-         zpsi_hu = psi_h(zeta_u)
-         zpsi_ht = psi_h(zeta_t)
-         zpsi_m  = psi_m(zeta_u)
-         !!
-         !! Shifting the wind speed to 10m and neutral stability : L & Y eq.(9a)
-         !   In very rare low-wind conditions, the old way of estimating the
-         !   neutral wind speed at 10m leads to a negative value that causes the code
-         !   to crash. To prevent this a threshold of 0.25m/s is now imposed.
-         U_n10 = MAX( 0.25 , dU10/(1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m)) )
-         !!
-         !! Shifting temperature and humidity at zu :          (L & Y eq. (9b-9c))
-!        T_zu = T_zt - T_star/kappa*(log(zt/zu) + psi_h(zeta_u) - psi_h(zeta_t))
-         T_zu = T_zt - T_star/kappa*(log(zt/zu) + zpsi_hu - zpsi_ht)
-!        q_zu = q_zt - q_star/kappa*(log(zt/zu) + psi_h(zeta_u) - psi_h(zeta_t))
-         q_zu = q_zt - q_star/kappa*(log(zt/zu) + zpsi_hu - zpsi_ht)
-         !!
-         !! q_zu cannot have a negative value : forcing 0
-         stab = 0.5 + sign(0.5,q_zu) ;  q_zu = stab*q_zu
-         !!
-         IF( ln_cdgw ) THEN
-            sqrt_Cd=kappa/((kappa/sqrt_Cd_n10) - zpsi_m) ; Cd=sqrt_Cd*sqrt_Cd;
+         zeta_u   = zu*ztmp0   ;  zeta_u = sign( min(abs(zeta_u),10.0), zeta_u )
+         zpsi_h_u = psi_h( zeta_u )
+         zpsi_m_u = psi_m( zeta_u )
+       
+         !! Shifting temperature and humidity at zu (L&Y 2004 eq. (9b-9c))
+         IF ( .NOT. l_zt_equal_zu ) THEN
+            zeta_t = zt*ztmp0 ;  zeta_t = sign( min(abs(zeta_t),10.0), zeta_t )
+            stab = LOG(zu/zt) - zpsi_h_u + psi_h(zeta_t)  ! stab just used as temp array!!!
+            T_zu = T_zt + ztmp1/vkarmn*stab    ! ztmp1 is still theta*
+            q_zu = q_zt + ztmp2/vkarmn*stab    ! ztmp2 is still q*
+            q_zu = max(0., q_zu)
+         END IF
+       
+         IF( ln_cdgw ) THEN      ! surface wave case
+            sqrt_Cd = vkarmn / ( vkarmn / sqrt_Cd_n10 - zpsi_m_u ) 
+            Cd      = sqrt_Cd * sqrt_Cd
          ELSE
-           !! Updating the neutral 10m transfer coefficients :
-           Cd_n10  = 1.e-3 * (2.7/U_n10 + 0.142 + U_n10/13.09)    ! L & Y eq. (6a)
-           sqrt_Cd_n10 = sqrt(Cd_n10)
-           Ce_n10  = 1.e-3 * (34.6 * sqrt_Cd_n10)                 ! L & Y eq. (6b)
-           stab    = 0.5 + sign(0.5,zeta_u)
-           Ch_n10  = 1.e-3*sqrt_Cd_n10*(18.*stab + 32.7*(1.-stab)) ! L & Y eq. (6c-6d)
-           !!
-           !!
-           !! Shifting the neutral 10m transfer coefficients to (zu,zeta_u) :
-           xct = 1. + sqrt_Cd_n10/kappa*(log(zu/10.) - zpsi_m)   ! L & Y eq. (10a)
-           Cd = Cd_n10/(xct*xct) ; sqrt_Cd = sqrt(Cd)
+           ! Update neutral wind speed at 10m and neutral Cd at 10m (L&Y 2004 eq. 9a)...
+           !   In very rare low-wind conditions, the old way of estimating the
+           !   neutral wind speed at 10m leads to a negative value that causes the code
+           !   to crash. To prevent this a threshold of 0.25m/s is imposed.
+           ztmp0 = MAX( 0.25 , U_zu/(1. + sqrt_Cd_n10/vkarmn*(LOG(zu/10.) - zpsi_m_u)) ) !  U_n10
+           ztmp0 = cd_neutral_10m(ztmp0)                                                 ! Cd_n10
+           sqrt_Cd_n10 = sqrt(ztmp0)
+       
+           Ce_n10  = 1.e-3 * (34.6 * sqrt_Cd_n10)                     ! L&Y 2004 eq. (6b)
+           stab    = 0.5 + sign(0.5,zeta_u)                           ! update stability
+           Ch_n10  = 1.e-3*sqrt_Cd_n10*(18.*stab + 32.7*(1. - stab))  ! L&Y 2004 eq. (6c-6d)
+
+           !! Update of transfer coefficients:
+           ztmp1 = 1. + sqrt_Cd_n10/vkarmn*(LOG(zu/10.) - zpsi_m_u)   ! L&Y 2004 eq. (10a)
+           Cd      = ztmp0 / ( ztmp1*ztmp1 )   
+           sqrt_Cd = SQRT( Cd )
          ENDIF
-         !!
-         xlogt = log(zu/10.) - zpsi_hu
-         !!
-         xct = 1. + Ch_n10*xlogt/kappa/sqrt_Cd_n10               ! L & Y eq. (10b)
-         Ch  = Ch_n10*sqrt_Cd/sqrt_Cd_n10/xct
-         !!
-         xct = 1. + Ce_n10*xlogt/kappa/sqrt_Cd_n10               ! L & Y eq. (10c)
-         Ce  = Ce_n10*sqrt_Cd/sqrt_Cd_n10/xct
-         !!
-         !!
+         !
+         ztmp0 = (LOG(zu/10.) - zpsi_h_u) / vkarmn / sqrt_Cd_n10
+         ztmp2 = sqrt_Cd / sqrt_Cd_n10
+         ztmp1 = 1. + Ch_n10*ztmp0               
+         Ch  = Ch_n10*ztmp2 / ztmp1  ! L&Y 2004 eq. (10b)
+         !
+         ztmp1 = 1. + Ce_n10*ztmp0               
+         Ce  = Ce_n10*ztmp2 / ztmp1  ! L&Y 2004 eq. (10c)
+         !
       END DO
-      !!
-      CALL wrk_dealloc( jpi,jpj, dU10, dT, dq, Cd_n10, Ce_n10, Ch_n10, sqrt_Cd_n10, sqrt_Cd, L )
-      CALL wrk_dealloc( jpi,jpj, T_vpot, T_star, q_star, U_star, zeta_u, zeta_t, U_n10 )
-      CALL wrk_dealloc( jpi,jpj, xlogt, xct, zpsi_hu, zpsi_ht, zpsi_m )
-      CALL wrk_dealloc( jpi,jpj, stab )   ! interger
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('TURB_CORE_2Z')
-      !
-    END SUBROUTINE TURB_CORE_2Z
-
-
-    FUNCTION psi_m(zta)   !! Psis, L & Y eq. (8c), (8d), (8e)
+
+      CALL wrk_dealloc( jpi,jpj, U_zu, Ce_n10, Ch_n10, sqrt_Cd_n10, sqrt_Cd )
+      CALL wrk_dealloc( jpi,jpj, zeta_u, stab )
+      CALL wrk_dealloc( jpi,jpj, zpsi_h_u, zpsi_m_u, ztmp0, ztmp1, ztmp2 )
+
+      IF( .NOT. l_zt_equal_zu ) CALL wrk_dealloc( jpi,jpj, zeta_t )
+
+      IF( nn_timing == 1 )  CALL timing_stop('turb_core_2z')
+      !
+   END SUBROUTINE turb_core_2z
+
+
+   FUNCTION cd_neutral_10m( zw10 )
+      !!----------------------------------------------------------------------
+      !! Estimate of the neutral drag coefficient at 10m as a function 
+      !! of neutral wind  speed at 10m
+      !!
+      !! Origin: Large & Yeager 2008 eq.(11a) and eq.(11b)
+      !!
+      !! Author: L. Brodeau, june 2014
+      !!----------------------------------------------------------------------    
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   zw10           ! scalar wind speed at 10m (m/s)
+      REAL(wp), DIMENSION(jpi,jpj)             ::   cd_neutral_10m
+      !
+      REAL(wp), DIMENSION(:,:), POINTER ::   rgt33
+      !!----------------------------------------------------------------------    
+      !
+      CALL wrk_alloc( jpi,jpj, rgt33 )
+      !
+      !! When wind speed > 33 m/s => Cyclone conditions => special treatment
+      rgt33 = 0.5_wp + SIGN( 0.5_wp, (zw10 - 33._wp) )   ! If zw10 < 33. => 0, else => 1  
+      cd_neutral_10m = 1.e-3 * ( &
+         &       (rgt33 + 1._wp)*( 2.7_wp/zw10 + 0.142_wp + zw10/13.09_wp - 3.14807E-10*zw10**6) & ! zw10< 33.
+         &      + rgt33         *      2.34   )                                                    ! zw10 >= 33.
+      !
+      CALL wrk_dealloc( jpi,jpj, rgt33)
+      !
+   END FUNCTION cd_neutral_10m
+
+
+   FUNCTION psi_m(pta)   !! Psis, L&Y 2004 eq. (8c), (8d), (8e)
       !-------------------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: zta
-
-      REAL(wp), PARAMETER :: pi = 3.141592653589793_wp
+      ! universal profile stability function for momentum
+      !-------------------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: pta
+      !
       REAL(wp), DIMENSION(jpi,jpj)             :: psi_m
       REAL(wp), DIMENSION(:,:), POINTER        :: X2, X, stabit
       !-------------------------------------------------------------------------------
-
+      !
       CALL wrk_alloc( jpi,jpj, X2, X, stabit )
-
-      X2 = sqrt(abs(1. - 16.*zta))  ;  X2 = max(X2 , 1.0) ;  X  = sqrt(X2)
-      stabit    = 0.5 + sign(0.5,zta)
-      psi_m = -5.*zta*stabit  &                                                          ! Stable
-         &    + (1. - stabit)*(2*log((1. + X)/2) + log((1. + X2)/2) - 2*atan(X) + pi/2)  ! Unstable 
-
+      !
+      X2 = SQRT( ABS( 1. - 16.*pta ) )  ;  X2 = MAX( X2 , 1. )   ;   X = SQRT( X2 )
+      stabit = 0.5 + SIGN( 0.5 , pta )
+      psi_m = -5.*pta*stabit  &                                                          ! Stable
+         &    + (1. - stabit)*(2.*LOG((1. + X)*0.5) + LOG((1. + X2)*0.5) - 2.*ATAN(X) + rpi*0.5)  ! Unstable
+      !
       CALL wrk_dealloc( jpi,jpj, X2, X, stabit )
       !
-    END FUNCTION psi_m
-
-
-    FUNCTION psi_h( zta )    !! Psis, L & Y eq. (8c), (8d), (8e)
+   END FUNCTION psi_m
+
+
+   FUNCTION psi_h( pta )    !! Psis, L&Y 2004 eq. (8c), (8d), (8e)
       !-------------------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   zta
+      ! universal profile stability function for temperature and humidity
+      !-------------------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pta
       !
       REAL(wp), DIMENSION(jpi,jpj)             ::   psi_h
-      REAL(wp), DIMENSION(:,:), POINTER        :: X2, X, stabit
+      REAL(wp), DIMENSION(:,:), POINTER        ::   X2, X, stabit
       !-------------------------------------------------------------------------------
-
+      !
       CALL wrk_alloc( jpi,jpj, X2, X, stabit )
-
-      X2 = sqrt(abs(1. - 16.*zta))  ;  X2 = max(X2 , 1.) ;  X  = sqrt(X2)
-      stabit    = 0.5 + sign(0.5,zta)
-      psi_h = -5.*zta*stabit  &                                       ! Stable
-         &    + (1. - stabit)*(2.*log( (1. + X2)/2. ))                 ! Unstable
-
+      !
+      X2 = SQRT( ABS( 1. - 16.*pta ) )   ;   X2 = MAX( X2 , 1. )   ;   X = SQRT( X2 )
+      stabit = 0.5 + SIGN( 0.5 , pta )
+      psi_h = -5.*pta*stabit   &                                       ! Stable
+         &    + (1. - stabit)*(2.*LOG( (1. + X2)*0.5 ))                ! Unstable
+      !
       CALL wrk_dealloc( jpi,jpj, X2, X, stabit )
       !
-    END FUNCTION psi_h
-  
+   END FUNCTION psi_h
+
    !!======================================================================
 END MODULE sbcblk_core
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_mfs.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_mfs.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_mfs.F90	(revision 4946)
@@ -82,5 +82,5 @@
       !!              - utau, vtau  i- and j-component of the wind stress
       !!              - taum        wind stress module at T-point
-      !!              - wndm        10m wind module at T-point
+      !!              - wndm        10m wind module at T-point over free ocean or leads in presence of sea-ice
       !!              - qns, qsr    non-slor and solar heat flux
       !!              - emp         evaporation minus precipitation
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 4946)
@@ -9,7 +9,4 @@
    !!            3.4  ! 2011_11  (C. Harris) more flexibility + multi-category fields
    !!----------------------------------------------------------------------
-#if defined key_oasis3 || defined key_oasis4
-   !!----------------------------------------------------------------------
-   !!   'key_oasis3' or 'key_oasis4'   Coupled Ocean/Atmosphere formulation
    !!----------------------------------------------------------------------
    !!   namsbc_cpl      : coupled formulation namlist
@@ -34,10 +31,5 @@
    USE ice_2           ! ice variables
 #endif
-#if defined key_oasis3
    USE cpl_oasis3      ! OASIS3 coupling
-#endif
-#if defined key_oasis4
-   USE cpl_oasis4      ! OASIS4 coupling
-#endif
    USE geo2ocean       ! 
    USE oce   , ONLY : tsn, un, vn
@@ -58,5 +50,6 @@
    IMPLICIT NONE
    PRIVATE
-
+!EM XIOS-OASIS-MCT compliance
+   PUBLIC   sbc_cpl_init       ! routine called by sbcmod.F90
    PUBLIC   sbc_cpl_rcv        ! routine called by sbc_ice_lim(_2).F90
    PUBLIC   sbc_cpl_snd        ! routine called by step.F90
@@ -129,4 +122,10 @@
    TYPE(FLD_C) ::   sn_rcv_w10m, sn_rcv_taumod, sn_rcv_tau, sn_rcv_dqnsdt, sn_rcv_qsr, sn_rcv_qns, sn_rcv_emp, sn_rcv_rnf
    TYPE(FLD_C) ::   sn_rcv_cal, sn_rcv_iceflx, sn_rcv_co2                        
+   ! Other namelist parameters                        !
+   INTEGER     ::   nn_cplmodel            ! Maximum number of models to/from which NEMO is potentialy sending/receiving data
+   LOGICAL     ::   ln_usecplmask          !  use a coupling mask file to merge data received from several models
+                                           !   -> file cplmask.nc with the float variable called cplmask (jpi,jpj,nn_cplmodel)
+
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: xcplmask
 
    TYPE ::   DYNARR     
@@ -139,29 +138,4 @@
 
    INTEGER , ALLOCATABLE, SAVE, DIMENSION(    :) ::   nrcvinfo           ! OASIS info argument
-
-#if ! defined key_lim2   &&   ! defined key_lim3
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   u_ice, v_ice,fr1_i0,fr2_i0          ! jpi, jpj
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tn_ice, alb_ice, qns_ice, dqns_ice  ! (jpi,jpj,jpl)
-#endif
-
-#if defined key_cice
-   INTEGER, PARAMETER ::   jpl = ncat
-#elif ! defined key_lim2   &&   ! defined key_lim3
-   INTEGER, PARAMETER ::   jpl = 1 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   emp_ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qsr_ice
-#endif
-
-#if ! defined key_lim3   &&  ! defined key_cice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  a_i
-#endif
-
-#if ! defined key_lim3
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  ht_i, ht_s
-#endif
-
-#if ! defined key_cice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  topmelt, botmelt
-#endif
 
    !! Substitution
@@ -179,24 +153,15 @@
       !!             ***  FUNCTION sbc_cpl_alloc  ***
       !!----------------------------------------------------------------------
-      INTEGER :: ierr(4),jn
+      INTEGER :: ierr(3)
       !!----------------------------------------------------------------------
       ierr(:) = 0
       !
       ALLOCATE( albedo_oce_mix(jpi,jpj), nrcvinfo(jprcv),  STAT=ierr(1) )
-      !
-#if ! defined key_lim2 && ! defined key_lim3
-      ! quick patch to be able to run the coupled model without sea-ice...
-      ALLOCATE( u_ice(jpi,jpj) , fr1_i0(jpi,jpj) , tn_ice (jpi,jpj,1) ,     &
-                v_ice(jpi,jpj) , fr2_i0(jpi,jpj) , alb_ice(jpi,jpj,1),      &
-                emp_ice(jpi,jpj) , qns_ice(jpi,jpj,1) , dqns_ice(jpi,jpj,1) , STAT=ierr(2) )
+      
+#if ! defined key_lim3 && ! defined key_lim2 && ! defined key_cice
+      ALLOCATE( a_i(jpi,jpj,1) , STAT=ierr(2) )  ! used in sbcice_if.F90 (done here as there is no sbc_ice_if_init)
 #endif
-
-#if ! defined key_lim3 && ! defined key_cice
-      ALLOCATE( a_i(jpi,jpj,jpl) , STAT=ierr(3) )
-#endif
-
-#if defined key_cice || defined key_lim2
-      ALLOCATE( ht_i(jpi,jpj,jpl) , ht_s(jpi,jpj,jpl) , STAT=ierr(4) )
-#endif
+      ALLOCATE( xcplmask(jpi,jpj,nn_cplmodel) , STAT=ierr(3) )
+      !
       sbc_cpl_alloc = MAXVAL( ierr )
       IF( lk_mpp            )   CALL mpp_sum ( sbc_cpl_alloc )
@@ -210,5 +175,5 @@
       !!             ***  ROUTINE sbc_cpl_init  ***
       !!
-      !! ** Purpose :   Initialisation of send and recieved information from
+      !! ** Purpose :   Initialisation of send and received information from
       !!                the atmospheric component
       !!
@@ -222,9 +187,11 @@
       INTEGER ::   jn   ! dummy loop index
       INTEGER ::   ios  ! Local integer output status for namelist read
+      INTEGER ::   inum 
       REAL(wp), POINTER, DIMENSION(:,:) ::   zacs, zaos
       !!
-      NAMELIST/namsbc_cpl/  sn_snd_temp, sn_snd_alb   , sn_snd_thick, sn_snd_crt   , sn_snd_co2,   &
-         &                  sn_rcv_w10m, sn_rcv_taumod, sn_rcv_tau  , sn_rcv_dqnsdt, sn_rcv_qsr,   &
-         &                  sn_rcv_qns , sn_rcv_emp   , sn_rcv_rnf  , sn_rcv_cal   , sn_rcv_iceflx  , sn_rcv_co2
+      NAMELIST/namsbc_cpl/  sn_snd_temp, sn_snd_alb   , sn_snd_thick, sn_snd_crt   , sn_snd_co2,      &
+         &                  sn_rcv_w10m, sn_rcv_taumod, sn_rcv_tau  , sn_rcv_dqnsdt, sn_rcv_qsr,      &
+         &                  sn_rcv_qns , sn_rcv_emp   , sn_rcv_rnf  , sn_rcv_cal   , sn_rcv_iceflx,   &
+         &                  sn_rcv_co2 , nn_cplmodel  , ln_usecplmask
       !!---------------------------------------------------------------------
       !
@@ -274,4 +241,6 @@
          WRITE(numout,*)'                      - mesh          = ', sn_snd_crt%clvgrd
          WRITE(numout,*)'      oce co2 flux                    = ', TRIM(sn_snd_co2%cldes   ), ' (', TRIM(sn_snd_co2%clcat   ), ')'
+         WRITE(numout,*)'  nn_cplmodel                         = ', nn_cplmodel
+         WRITE(numout,*)'  ln_usecplmask                       = ', ln_usecplmask
       ENDIF
 
@@ -485,9 +454,9 @@
       END DO
       ! Allocate taum part of frcv which is used even when not received as coupling field
-      IF ( .NOT. srcv(jpr_taum)%laction ) ALLOCATE( frcv(jpr_taum)%z3(jpi,jpj,srcv(jn)%nct) )
+      IF ( .NOT. srcv(jpr_taum)%laction ) ALLOCATE( frcv(jpr_taum)%z3(jpi,jpj,srcv(jpr_taum)%nct) )
       ! Allocate itx1 and ity1 as they are used in sbc_cpl_ice_tau even if srcv(jpr_itx1)%laction = .FALSE.
       IF( k_ice /= 0 ) THEN
-         IF ( .NOT. srcv(jpr_itx1)%laction ) ALLOCATE( frcv(jpr_itx1)%z3(jpi,jpj,srcv(jn)%nct) )
-         IF ( .NOT. srcv(jpr_ity1)%laction ) ALLOCATE( frcv(jpr_ity1)%z3(jpi,jpj,srcv(jn)%nct) )
+         IF ( .NOT. srcv(jpr_itx1)%laction ) ALLOCATE( frcv(jpr_itx1)%z3(jpi,jpj,srcv(jpr_itx1)%nct) )
+         IF ( .NOT. srcv(jpr_ity1)%laction ) ALLOCATE( frcv(jpr_ity1)%z3(jpi,jpj,srcv(jpr_ity1)%nct) )
       END IF
 
@@ -604,7 +573,16 @@
       ! ================================ !
 
-      CALL cpl_prism_define(jprcv, jpsnd)            
-      !
-      IF( ln_dm2dc .AND. ( cpl_prism_freq( jpr_qsroce ) + cpl_prism_freq( jpr_qsrmix ) /= 86400 ) )   &
+      CALL cpl_define(jprcv, jpsnd,nn_cplmodel)            
+      IF (ln_usecplmask) THEN 
+         xcplmask(:,:,:) = 0.
+         CALL iom_open( 'cplmask', inum )
+         CALL iom_get( inum, jpdom_unknown, 'cplmask', xcplmask(1:nlci,1:nlcj,1:nn_cplmodel),   &
+            &          kstart = (/ mig(1),mjg(1),1 /), kcount = (/ nlci,nlcj,nn_cplmodel /) )
+         CALL iom_close( inum )
+      ELSE
+         xcplmask(:,:,:) = 1.
+      ENDIF
+      !
+      IF( ln_dm2dc .AND. ( cpl_freq( jpr_qsroce ) + cpl_freq( jpr_qsrmix ) /= 86400 ) )   &
          &   CALL ctl_stop( 'sbc_cpl_init: diurnal cycle reconstruction (ln_dm2dc) needs daily couping for solar radiation' )
 
@@ -654,5 +632,6 @@
       !!
       !! ** Action  :   update  utau, vtau   ocean stress at U,V grid 
-      !!                        taum, wndm   wind stres and wind speed module at T-point
+      !!                        taum         wind stress module at T-point
+      !!                        wndm         wind speed  module at T-point over free ocean or leads in presence of sea-ice
       !!                        qns          non solar heat fluxes including emp heat content    (ocean only case)
       !!                                     and the latent heat flux of solid precip. melting
@@ -678,11 +657,8 @@
       !
       CALL wrk_alloc( jpi,jpj, ztx, zty )
-
-      IF( kt == nit000 )   CALL sbc_cpl_init( k_ice )          ! initialisation
-
       !                                                 ! Receive all the atmos. fields (including ice information)
       isec = ( kt - nit000 ) * NINT( rdttra(1) )             ! date of exchanges
       DO jn = 1, jprcv                                       ! received fields sent by the atmosphere
-         IF( srcv(jn)%laction )   CALL cpl_prism_rcv( jn, isec, frcv(jn)%z3, nrcvinfo(jn) )
+         IF( srcv(jn)%laction )   CALL cpl_rcv( jn, isec, frcv(jn)%z3, xcplmask, nrcvinfo(jn) )
       END DO
 
@@ -848,8 +824,8 @@
          IF( srcv(jpr_qnsoce)%laction )   qns(:,:) = frcv(jpr_qnsoce)%z3(:,:,1)
          IF( srcv(jpr_qnsmix)%laction )   qns(:,:) = frcv(jpr_qnsmix)%z3(:,:,1)
-         ! add the latent heat of solid precip. melting
-         IF( srcv(jpr_snow  )%laction )   THEN                         ! update qns over the free ocean with:
-              qns(:,:) = qns(:,:) - frcv(jpr_snow)%z3(:,:,1) * lfus  & ! energy for melting solid precipitation over the free ocean
-           &           - emp(:,:) * sst_m(:,:) * rcp                   ! remove heat content due to mass flux (assumed to be at SST)
+         ! update qns over the free ocean with:
+         qns(:,:) =  qns(:,:) - emp(:,:) * sst_m(:,:) * rcp            ! remove heat content due to mass flux (assumed to be at SST)
+         IF( srcv(jpr_snow  )%laction )   THEN
+              qns(:,:) = qns(:,:) - frcv(jpr_snow)%z3(:,:,1) * lfus    ! energy for melting solid precipitation over the free ocean
          ENDIF
 
@@ -914,6 +890,5 @@
       CALL wrk_alloc( jpi,jpj, ztx, zty )
 
-!AC Pour eviter un stress nul sur la glace dans le cas mixed oce-ice
-      IF( srcv(jpr_itx1)%laction .AND. TRIM( sn_rcv_tau%cldes ) == 'oce and ice') THEN   ;   itx =  jpr_itx1   
+      IF( srcv(jpr_itx1)%laction ) THEN   ;   itx =  jpr_itx1   
       ELSE                                ;   itx =  jpr_otx1
       ENDIF
@@ -922,8 +897,7 @@
       IF(  nrcvinfo(itx) == OASIS_Rcv ) THEN
 
-         !                                                                                              ! ======================= !
-!AC Pour eviter un stress nul sur la glace dans le cas mixes oce-ice
-         IF( srcv(jpr_itx1)%laction .AND. TRIM( sn_rcv_tau%cldes ) == 'oce and ice') THEN               !   ice stress received   !
-            !                                                                                           ! ======================= !
+         !                                                      ! ======================= !
+         IF( srcv(jpr_itx1)%laction ) THEN                      !   ice stress received   !
+            !                                                   ! ======================= !
             !  
             IF( TRIM( sn_rcv_tau%clvref ) == 'cartesian' ) THEN            ! 2 components on the sphere
@@ -1125,6 +1099,6 @@
       REAL(wp), INTENT(in   ), DIMENSION(:,:)   ::   p_frld     ! lead fraction                [0 to 1]
       ! optional arguments, used only in 'mixed oce-ice' case
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:), OPTIONAL ::   palbi   ! ice albedo 
-      REAL(wp), INTENT(in   ), DIMENSION(:,:  ), OPTIONAL ::   psst    ! sea surface temperature     [Celcius]
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:), OPTIONAL ::   palbi   ! all skies ice albedo 
+      REAL(wp), INTENT(in   ), DIMENSION(:,:  ), OPTIONAL ::   psst    ! sea surface temperature     [Celsius]
       REAL(wp), INTENT(in   ), DIMENSION(:,:,:), OPTIONAL ::   pist    ! ice surface temperature     [Kelvin]
       !
@@ -1296,5 +1270,7 @@
       ENDIF
 
-      SELECT CASE( TRIM( sn_rcv_dqnsdt%cldes ) )
+      !                                                      ! ========================= !
+      SELECT CASE( TRIM( sn_rcv_dqnsdt%cldes ) )             !          d(qns)/dt        !
+      !                                                      ! ========================= !
       CASE ('coupled')
          IF ( TRIM(sn_rcv_dqnsdt%clcat) == 'yes' ) THEN
@@ -1308,5 +1284,7 @@
       END SELECT
 
-      SELECT CASE( TRIM( sn_rcv_iceflx%cldes ) )
+      !                                                      ! ========================= !
+      SELECT CASE( TRIM( sn_rcv_iceflx%cldes ) )             !    topmelt and botmelt    !
+      !                                                      ! ========================= !
       CASE ('coupled')
          topmelt(:,:,:)=frcv(jpr_topm)%z3(:,:,:)
@@ -1314,12 +1292,10 @@
       END SELECT
 
-      !    Ice Qsr penetration used (only?)in lim2 or lim3 
-      ! fraction of net shortwave radiation which is not absorbed in the thin surface layer 
-      ! and penetrates inside the ice cover ( Maykut and Untersteiner, 1971 ; Elbert anbd Curry, 1993 )
+      ! Surface transimission parameter io (Maykut Untersteiner , 1971 ; Ebert and Curry, 1993 )
+      ! Used for LIM2 and LIM3
       ! Coupled case: since cloud cover is not received from atmosphere 
-      !               ===> defined as constant value -> definition done in sbc_cpl_init
-      fr1_i0(:,:) = 0.18
-      fr2_i0(:,:) = 0.82
-
+      !               ===> used prescribed cloud fraction representative for polar oceans in summer (0.81)
+      fr1_i0(:,:) = ( 0.18 * ( 1.0 - cldf_ice ) + 0.35 * cldf_ice )
+      fr2_i0(:,:) = ( 0.82 * ( 1.0 - cldf_ice ) + 0.65 * cldf_ice )
 
       CALL wrk_dealloc( jpi,jpj, zcptn, ztmp, zicefr )
@@ -1336,5 +1312,5 @@
       !! ** Purpose :   provide the ocean-ice informations to the atmosphere
       !!
-      !! ** Method  :   send to the atmosphere through a call to cpl_prism_snd
+      !! ** Method  :   send to the atmosphere through a call to cpl_snd
       !!              all the needed fields (as defined in sbc_cpl_init)
       !!----------------------------------------------------------------------
@@ -1355,5 +1331,4 @@
 
       zfr_l(:,:) = 1.- fr_i(:,:)
-
       !                                                      ! ------------------------- !
       !                                                      !    Surface temperature    !   in Kelvin
@@ -1380,9 +1355,8 @@
          CASE default                     ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_temp%cldes' )
          END SELECT
-         IF( ssnd(jps_toce)%laction )   CALL cpl_prism_snd( jps_toce, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
-         IF( ssnd(jps_tice)%laction )   CALL cpl_prism_snd( jps_tice, isec, ztmp3, info )
-         IF( ssnd(jps_tmix)%laction )   CALL cpl_prism_snd( jps_tmix, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
-      ENDIF
-      !
+         IF( ssnd(jps_toce)%laction )   CALL cpl_snd( jps_toce, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
+         IF( ssnd(jps_tice)%laction )   CALL cpl_snd( jps_tice, isec, ztmp3, info )
+         IF( ssnd(jps_tmix)%laction )   CALL cpl_snd( jps_tmix, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
+      ENDIF
       !                                                      ! ------------------------- !
       !                                                      !           Albedo          !
@@ -1390,5 +1364,5 @@
       IF( ssnd(jps_albice)%laction ) THEN                         ! ice 
          ztmp3(:,:,1:jpl) = alb_ice(:,:,1:jpl) * a_i(:,:,1:jpl)
-         CALL cpl_prism_snd( jps_albice, isec, ztmp3, info )
+         CALL cpl_snd( jps_albice, isec, ztmp3, info )
       ENDIF
       IF( ssnd(jps_albmix)%laction ) THEN                         ! mixed ice-ocean
@@ -1397,5 +1371,5 @@
             ztmp1(:,:) = ztmp1(:,:) + alb_ice(:,:,jl) * a_i(:,:,jl)
          ENDDO
-         CALL cpl_prism_snd( jps_albmix, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
+         CALL cpl_snd( jps_albmix, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
       ENDIF
       !                                                      ! ------------------------- !
@@ -1409,5 +1383,5 @@
          CASE default    ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_thick%clcat' )
          END SELECT
-         CALL cpl_prism_snd( jps_fice, isec, ztmp3, info )
+         CALL cpl_snd( jps_fice, isec, ztmp3, info )
       ENDIF
 
@@ -1434,6 +1408,6 @@
          CASE default                     ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_thick%cldes' )
          END SELECT
-         IF( ssnd(jps_hice)%laction )   CALL cpl_prism_snd( jps_hice, isec, ztmp3, info )
-         IF( ssnd(jps_hsnw)%laction )   CALL cpl_prism_snd( jps_hsnw, isec, ztmp4, info )
+         IF( ssnd(jps_hice)%laction )   CALL cpl_snd( jps_hice, isec, ztmp3, info )
+         IF( ssnd(jps_hsnw)%laction )   CALL cpl_snd( jps_hsnw, isec, ztmp4, info )
       ENDIF
       !
@@ -1442,5 +1416,5 @@
       !                                                      !  CO2 flux from PISCES     ! 
       !                                                      ! ------------------------- !
-      IF( ssnd(jps_co2)%laction )   CALL cpl_prism_snd( jps_co2, isec, RESHAPE ( oce_co2, (/jpi,jpj,1/) ) , info )
+      IF( ssnd(jps_co2)%laction )   CALL cpl_snd( jps_co2, isec, RESHAPE ( oce_co2, (/jpi,jpj,1/) ) , info )
       !
 #endif
@@ -1565,11 +1539,11 @@
          ENDIF
          !
-         IF( ssnd(jps_ocx1)%laction )   CALL cpl_prism_snd( jps_ocx1, isec, RESHAPE ( zotx1, (/jpi,jpj,1/) ), info )   ! ocean x current 1st grid
-         IF( ssnd(jps_ocy1)%laction )   CALL cpl_prism_snd( jps_ocy1, isec, RESHAPE ( zoty1, (/jpi,jpj,1/) ), info )   ! ocean y current 1st grid
-         IF( ssnd(jps_ocz1)%laction )   CALL cpl_prism_snd( jps_ocz1, isec, RESHAPE ( zotz1, (/jpi,jpj,1/) ), info )   ! ocean z current 1st grid
+         IF( ssnd(jps_ocx1)%laction )   CALL cpl_snd( jps_ocx1, isec, RESHAPE ( zotx1, (/jpi,jpj,1/) ), info )   ! ocean x current 1st grid
+         IF( ssnd(jps_ocy1)%laction )   CALL cpl_snd( jps_ocy1, isec, RESHAPE ( zoty1, (/jpi,jpj,1/) ), info )   ! ocean y current 1st grid
+         IF( ssnd(jps_ocz1)%laction )   CALL cpl_snd( jps_ocz1, isec, RESHAPE ( zotz1, (/jpi,jpj,1/) ), info )   ! ocean z current 1st grid
          !
-         IF( ssnd(jps_ivx1)%laction )   CALL cpl_prism_snd( jps_ivx1, isec, RESHAPE ( zitx1, (/jpi,jpj,1/) ), info )   ! ice   x current 1st grid
-         IF( ssnd(jps_ivy1)%laction )   CALL cpl_prism_snd( jps_ivy1, isec, RESHAPE ( zity1, (/jpi,jpj,1/) ), info )   ! ice   y current 1st grid
-         IF( ssnd(jps_ivz1)%laction )   CALL cpl_prism_snd( jps_ivz1, isec, RESHAPE ( zitz1, (/jpi,jpj,1/) ), info )   ! ice   z current 1st grid
+         IF( ssnd(jps_ivx1)%laction )   CALL cpl_snd( jps_ivx1, isec, RESHAPE ( zitx1, (/jpi,jpj,1/) ), info )   ! ice   x current 1st grid
+         IF( ssnd(jps_ivy1)%laction )   CALL cpl_snd( jps_ivy1, isec, RESHAPE ( zity1, (/jpi,jpj,1/) ), info )   ! ice   y current 1st grid
+         IF( ssnd(jps_ivz1)%laction )   CALL cpl_snd( jps_ivz1, isec, RESHAPE ( zitz1, (/jpi,jpj,1/) ), info )   ! ice   z current 1st grid
          ! 
       ENDIF
@@ -1582,35 +1556,4 @@
    END SUBROUTINE sbc_cpl_snd
    
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module                                            NO coupling
-   !!----------------------------------------------------------------------
-   USE par_kind        ! kind definition
-CONTAINS
-   SUBROUTINE sbc_cpl_snd( kt )
-      WRITE(*,*) 'sbc_cpl_snd: You should not have seen this print! error?', kt
-   END SUBROUTINE sbc_cpl_snd
-   !
-   SUBROUTINE sbc_cpl_rcv( kt, k_fsbc, k_ice )     
-      WRITE(*,*) 'sbc_cpl_snd: You should not have seen this print! error?', kt, k_fsbc, k_ice
-   END SUBROUTINE sbc_cpl_rcv
-   !
-   SUBROUTINE sbc_cpl_ice_tau( p_taui, p_tauj )     
-      REAL(wp), INTENT(out), DIMENSION(:,:) ::   p_taui   ! i- & j-components of atmos-ice stress [N/m2]
-      REAL(wp), INTENT(out), DIMENSION(:,:) ::   p_tauj   ! at I-point (B-grid) or U & V-point (C-grid)
-      p_taui(:,:) = 0.   ;   p_tauj(:,:) = 0. ! stupid definition to avoid warning message when compiling...
-      WRITE(*,*) 'sbc_cpl_snd: You should not have seen this print! error?'
-   END SUBROUTINE sbc_cpl_ice_tau
-   !
-   SUBROUTINE sbc_cpl_ice_flx( p_frld , palbi   , psst    , pist  )
-      REAL(wp), INTENT(in   ), DIMENSION(:,:  ) ::   p_frld     ! lead fraction                [0 to 1]
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:), OPTIONAL ::   palbi   ! ice albedo
-      REAL(wp), INTENT(in   ), DIMENSION(:,:  ), OPTIONAL ::   psst    ! sea surface temperature      [Celcius]
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:), OPTIONAL ::   pist    ! ice surface temperature      [Kelvin]
-      WRITE(*,*) 'sbc_cpl_snd: You should not have seen this print! error?', p_frld(1,1), palbi(1,1,1), psst(1,1), pist(1,1,1) 
-   END SUBROUTINE sbc_cpl_ice_flx
-   
-#endif
-
    !!======================================================================
 END MODULE sbccpl
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90	(revision 4946)
@@ -91,5 +91,5 @@
          area = glob_sum( e1e2t(:,:) )           ! interior global domain surface
          !
-#if ! defined key_lim2 &&  ! defined key_lim3 && ! defined key_cice 
+#if ! defined key_lim2 &&  ! defined key_lim3 && ! defined key_cice
          snwice_mass_b(:,:) = 0.e0               ! no sea-ice model is being used : no snow+ice mass
          snwice_mass  (:,:) = 0.e0
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90	(revision 4946)
@@ -17,4 +17,5 @@
    USE phycst, only : rcp, rau0, r1_rau0, rhosn, rhoic
    USE in_out_manager  ! I/O manager
+   USE iom, only : iom_put              ! I/O manager library !!Joakim edit
    USE lib_mpp         ! distributed memory computing library
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
@@ -23,5 +24,4 @@
    USE daymod          ! calendar
    USE fldread         ! read input fields
-
    USE sbc_oce         ! Surface boundary condition: ocean fields
    USE sbc_ice         ! Surface boundary condition: ice   fields
@@ -38,4 +38,5 @@
    USE ice_calendar, only: dt
    USE ice_state, only: aice,aicen,uvel,vvel,vsno,vsnon,vice,vicen
+# if defined key_cice4
    USE ice_flux, only: strax,stray,strocnx,strocny,frain,fsnow,  &
                 sst,sss,uocn,vocn,ss_tltx,ss_tlty,fsalt_gbm,     &
@@ -44,7 +45,16 @@
                 uatm,vatm,wind,fsw,flw,Tair,potT,Qa,rhoa,zlvl,   &
                 swvdr,swvdf,swidr,swidf
+   USE ice_therm_vertical, only: calc_Tsfc
+#else
+   USE ice_flux, only: strax,stray,strocnx,strocny,frain,fsnow,  &
+                sst,sss,uocn,vocn,ss_tltx,ss_tlty,fsalt_ai,     &
+                fresh_ai,fhocn_ai,fswthru_ai,frzmlt,          &
+                flatn_f,fsurfn_f,fcondtopn_f,                    &
+                uatm,vatm,wind,fsw,flw,Tair,potT,Qa,rhoa,zlvl,   &
+                swvdr,swvdf,swidr,swidf
+   USE ice_therm_shared, only: calc_Tsfc
+#endif
    USE ice_forcing, only: frcvdr,frcvdf,frcidr,frcidf
    USE ice_atmo, only: calc_strair
-   USE ice_therm_vertical, only: calc_Tsfc
 
    USE CICE_InitMod
@@ -95,5 +105,5 @@
    END FUNCTION sbc_ice_cice_alloc
 
-   SUBROUTINE sbc_ice_cice( kt, nsbc )
+   SUBROUTINE sbc_ice_cice( kt, ksbc )
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE sbc_ice_cice  ***
@@ -113,5 +123,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt      ! ocean time step
-      INTEGER, INTENT(in) ::   nsbc    ! surface forcing type
+      INTEGER, INTENT(in) ::   ksbc    ! surface forcing type
       !!----------------------------------------------------------------------
       !
@@ -123,15 +133,15 @@
 
          ! Make sure any fluxes required for CICE are set
-         IF ( nsbc == 2 )  THEN
+         IF      ( ksbc == jp_flx ) THEN
             CALL cice_sbc_force(kt)
-         ELSE IF ( nsbc == 5 ) THEN
+         ELSE IF ( ksbc == jp_cpl ) THEN
             CALL sbc_cpl_ice_flx( 1.0-fr_i  )
          ENDIF
 
-         CALL cice_sbc_in ( kt, nsbc )
+         CALL cice_sbc_in  ( kt, ksbc )
          CALL CICE_Run
-         CALL cice_sbc_out ( kt, nsbc )
-
-         IF ( nsbc == 5 )  CALL cice_sbc_hadgam(kt+1)
+         CALL cice_sbc_out ( kt, ksbc )
+
+         IF ( ksbc == jp_cpl )  CALL cice_sbc_hadgam(kt+1)
 
       ENDIF                                          ! End sea-ice time step only
@@ -141,13 +151,13 @@
    END SUBROUTINE sbc_ice_cice
 
-   SUBROUTINE cice_sbc_init (nsbc)
+   SUBROUTINE cice_sbc_init (ksbc)
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE cice_sbc_init  ***
       !! ** Purpose: Initialise ice related fields for NEMO and coupling
       !!
-      INTEGER, INTENT( in  ) ::   nsbc                ! surface forcing type
+      INTEGER, INTENT( in  ) ::   ksbc                ! surface forcing type
       REAL(wp), DIMENSION(:,:), POINTER :: ztmp1, ztmp2
       REAL(wp) ::   zcoefu, zcoefv, zcoeff            ! local scalar
-      INTEGER  ::   ji, jj, jl                        ! dummy loop indices
+      INTEGER  ::   ji, jj, jl, jk                    ! dummy loop indices
       !!---------------------------------------------------------------------
 
@@ -161,13 +171,22 @@
       jj_off = INT ( (jpjglo - ny_global) / 2 )
 
+#if defined key_nemocice_decomp
+      ! Pass initial SST from NEMO to CICE so ice is initialised correctly if
+      ! there is no restart file.
+      ! Values from a CICE restart file would overwrite this
+      IF ( .NOT. ln_rstart ) THEN    
+         CALL nemo2cice( tsn(:,:,1,jp_tem) , sst , 'T' , 1.) 
+      ENDIF  
+#endif
+
 ! Initialize CICE
       CALL CICE_Initialize
 
 ! Do some CICE consistency checks
-      IF ( (nsbc == 2) .OR. (nsbc == 5) ) THEN
+      IF ( (ksbc == jp_flx) .OR. (ksbc == jp_cpl) ) THEN
          IF ( calc_strair .OR. calc_Tsfc ) THEN
             CALL ctl_stop( 'STOP', 'cice_sbc_init : Forcing option requires calc_strair=F and calc_Tsfc=F in ice_in' )
          ENDIF
-      ELSEIF (nsbc == 4) THEN
+      ELSEIF (ksbc == jp_core) THEN
          IF ( .NOT. (calc_strair .AND. calc_Tsfc) ) THEN
             CALL ctl_stop( 'STOP', 'cice_sbc_init : Forcing option requires calc_strair=T and calc_Tsfc=T in ice_in' )
@@ -190,5 +209,5 @@
 
       CALL cice2nemo(aice,fr_i, 'T', 1. )
-      IF ( (nsbc == 2).OR.(nsbc == 5) ) THEN
+      IF ( (ksbc == jp_flx) .OR. (ksbc == jp_cpl) ) THEN
          DO jl=1,ncat
             CALL cice2nemo(aicen(:,:,jl,:),a_i(:,:,jl), 'T', 1. )
@@ -218,9 +237,44 @@
          snwice_mass_b(:,:) = 0.0_wp         ! no mass exchanges
       ENDIF
-      IF( nn_ice_embd == 2 .AND.          &  ! full embedment (case 2) & no restart : 
-         &   .NOT.ln_rstart ) THEN           ! deplete the initial ssh belew sea-ice area
-         sshn(:,:) = sshn(:,:) - snwice_mass(:,:) * r1_rau0
-         sshb(:,:) = sshb(:,:) - snwice_mass(:,:) * r1_rau0
-         !
+      IF( .NOT. ln_rstart ) THEN
+         IF( nn_ice_embd == 2 ) THEN            ! full embedment (case 2) deplete the initial ssh below sea-ice area
+            sshn(:,:) = sshn(:,:) - snwice_mass(:,:) * r1_rau0
+            sshb(:,:) = sshb(:,:) - snwice_mass(:,:) * r1_rau0
+#if defined key_vvl            
+           ! key_vvl necessary? clem: yes for compilation purpose
+            DO jk = 1,jpkm1                     ! adjust initial vertical scale factors
+               fse3t_n(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshn(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
+               fse3t_b(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshb(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
+            ENDDO
+            fse3t_a(:,:,:) = fse3t_b(:,:,:)
+            ! Reconstruction of all vertical scale factors at now and before time
+            ! steps
+            ! =============================================================================
+            ! Horizontal scale factor interpolations
+            ! --------------------------------------
+            CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3u_b(:,:,:), 'U' )
+            CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3v_b(:,:,:), 'V' )
+            CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3u_n(:,:,:), 'U' )
+            CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3v_n(:,:,:), 'V' )
+            CALL dom_vvl_interpol( fse3u_n(:,:,:), fse3f_n(:,:,:), 'F' )
+            ! Vertical scale factor interpolations
+            ! ------------------------------------
+            CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3w_n (:,:,:), 'W'  )
+            CALL dom_vvl_interpol( fse3u_n(:,:,:), fse3uw_n(:,:,:), 'UW' )
+            CALL dom_vvl_interpol( fse3v_n(:,:,:), fse3vw_n(:,:,:), 'VW' )
+            CALL dom_vvl_interpol( fse3u_b(:,:,:), fse3uw_b(:,:,:), 'UW' )
+            CALL dom_vvl_interpol( fse3v_b(:,:,:), fse3vw_b(:,:,:), 'VW' )
+            ! t- and w- points depth
+            ! ----------------------
+            fsdept_n(:,:,1) = 0.5_wp * fse3w_n(:,:,1)
+            fsdepw_n(:,:,1) = 0.0_wp
+            fsde3w_n(:,:,1) = fsdept_n(:,:,1) - sshn(:,:)
+            DO jk = 2, jpk
+               fsdept_n(:,:,jk) = fsdept_n(:,:,jk-1) + fse3w_n(:,:,jk)
+               fsdepw_n(:,:,jk) = fsdepw_n(:,:,jk-1) + fse3t_n(:,:,jk-1)
+               fsde3w_n(:,:,jk) = fsdept_n(:,:,jk  ) - sshn   (:,:)
+            END DO
+#endif
+         ENDIF
       ENDIF
  
@@ -232,5 +286,5 @@
 
    
-   SUBROUTINE cice_sbc_in (kt, nsbc)
+   SUBROUTINE cice_sbc_in (kt, ksbc)
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE cice_sbc_in  ***
@@ -238,5 +292,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in   ) ::   kt   ! ocean time step
-      INTEGER, INTENT(in   ) ::   nsbc ! surface forcing type
+      INTEGER, INTENT(in   ) ::   ksbc ! surface forcing type
 
       INTEGER  ::   ji, jj, jl                   ! dummy loop indices      
@@ -262,5 +316,5 @@
 ! forced and coupled case 
 
-      IF ( (nsbc == 2).OR.(nsbc == 5) ) THEN
+      IF ( (ksbc == jp_flx).OR.(ksbc == jp_cpl) ) THEN
 
          ztmpn(:,:,:)=0.0
@@ -287,5 +341,5 @@
 
 ! Surface downward latent heat flux (CI_5)
-         IF (nsbc == 2) THEN
+         IF (ksbc == jp_flx) THEN
             DO jl=1,ncat
                ztmpn(:,:,jl)=qla_ice(:,:,1)*a_i(:,:,jl)
@@ -316,5 +370,5 @@
 ! GBM conductive flux through ice (CI_6)
 !  Convert to GBM
-            IF (nsbc == 2) THEN
+            IF (ksbc == jp_flx) THEN
                ztmp(:,:) = botmelt(:,:,jl)*a_i(:,:,jl)
             ELSE
@@ -325,5 +379,5 @@
 ! GBM surface heat flux (CI_7)
 !  Convert to GBM
-            IF (nsbc == 2) THEN
+            IF (ksbc == jp_flx) THEN
                ztmp(:,:) = (topmelt(:,:,jl)+botmelt(:,:,jl))*a_i(:,:,jl) 
             ELSE
@@ -333,5 +387,5 @@
          ENDDO
 
-      ELSE IF (nsbc == 4) THEN
+      ELSE IF (ksbc == jp_core) THEN
 
 ! Pass CORE forcing fields to CICE (which will calculate heat fluxes etc itself)
@@ -375,9 +429,11 @@
 
 ! Snowfall
-! Ensure fsnow is positive (as in CICE routine prepare_forcing)  
+! Ensure fsnow is positive (as in CICE routine prepare_forcing)
+      CALL iom_put('snowpre',MAX( (1.0-fr_i(:,:))*sprecip(:,:) ,0.0)) !!Joakim edit  
       ztmp(:,:)=MAX(fr_i(:,:)*sprecip(:,:),0.0)  
       CALL nemo2cice(ztmp,fsnow,'T', 1. ) 
 
 ! Rainfall
+      CALL iom_put('precip', (1.0-fr_i(:,:))*(tprecip(:,:)-sprecip(:,:)) ) !!Joakim edit
       ztmp(:,:)=fr_i(:,:)*(tprecip(:,:)-sprecip(:,:))
       CALL nemo2cice(ztmp,frain,'T', 1. ) 
@@ -458,5 +514,5 @@
 
 
-   SUBROUTINE cice_sbc_out (kt,nsbc)
+   SUBROUTINE cice_sbc_out (kt,ksbc)
       !!---------------------------------------------------------------------
       !!                    ***  ROUTINE cice_sbc_out  ***
@@ -464,5 +520,5 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT( in  ) ::   kt   ! ocean time step
-      INTEGER, INTENT( in  ) ::   nsbc ! surface forcing type
+      INTEGER, INTENT( in  ) ::   ksbc ! surface forcing type
       
       INTEGER  ::   ji, jj, jl                 ! dummy loop indices
@@ -510,5 +566,5 @@
 ! Freshwater fluxes 
 
-      IF (nsbc == 2) THEN
+      IF (ksbc == jp_flx) THEN
 ! Note that emp from the forcing files is evap*(1-aice)-(tprecip-aice*sprecip)
 ! What we want here is evap*(1-aice)-tprecip*(1-aice) hence manipulation below
@@ -516,7 +572,7 @@
 ! Better to use evap and tprecip? (but for now don't read in evap in this case)
          emp(:,:)  = emp(:,:)+fr_i(:,:)*(tprecip(:,:)-sprecip(:,:))
-      ELSE IF (nsbc == 4) THEN
+      ELSE IF (ksbc == jp_core) THEN
          emp(:,:)  = (1.0-fr_i(:,:))*emp(:,:)        
-      ELSE IF (nsbc ==5) THEN
+      ELSE IF (ksbc == jp_cpl) THEN
 ! emp_tot is set in sbc_cpl_ice_flx (called from cice_sbc_in above) 
 ! This is currently as required with the coupling fields from the UM atmosphere
@@ -524,6 +580,11 @@
       ENDIF
 
+#if defined key_cice4
       CALL cice2nemo(fresh_gbm,ztmp1,'T', 1. )
       CALL cice2nemo(fsalt_gbm,ztmp2,'T', 1. )
+#else
+      CALL cice2nemo(fresh_ai,ztmp1,'T', 1. )
+      CALL cice2nemo(fsalt_ai,ztmp2,'T', 1. )
+#endif
 
 ! Check to avoid unphysical expression when ice is forming (ztmp1 negative)
@@ -535,5 +596,6 @@
       sfx(:,:)=ztmp2(:,:)*1000.0
       emp(:,:)=emp(:,:)-ztmp1(:,:)
- 
+      fmmflx(:,:) = ztmp1(:,:) !!Joakim edit
+      
       CALL lbc_lnk( emp , 'T', 1. )
       CALL lbc_lnk( sfx , 'T', 1. )
@@ -543,10 +605,10 @@
 ! Scale qsr and qns according to ice fraction (bulk formulae only)
 
-      IF (nsbc == 4) THEN
+      IF (ksbc == jp_core) THEN
          qsr(:,:)=qsr(:,:)*(1.0-fr_i(:,:))
          qns(:,:)=qns(:,:)*(1.0-fr_i(:,:))
       ENDIF
 ! Take into account snow melting except for fully coupled when already in qns_tot
-      IF (nsbc == 5) THEN
+      IF (ksbc == jp_cpl) THEN
          qsr(:,:)= qsr_tot(:,:)
          qns(:,:)= qns_tot(:,:)
@@ -557,5 +619,9 @@
 ! Now add in ice / snow related terms
 ! [fswthru will be zero unless running with calc_Tsfc=T in CICE]
+#if defined key_cice4
       CALL cice2nemo(fswthru_gbm,ztmp1,'T', 1. )
+#else
+      CALL cice2nemo(fswthru_ai,ztmp1,'T', 1. )
+#endif
       qsr(:,:)=qsr(:,:)+ztmp1(:,:)
       CALL lbc_lnk( qsr , 'T', 1. )
@@ -567,5 +633,9 @@
       ENDDO
 
+#if defined key_cice4
       CALL cice2nemo(fhocn_gbm,ztmp1,'T', 1. )
+#else
+      CALL cice2nemo(fhocn_ai,ztmp1,'T', 1. )
+#endif
       qns(:,:)=qns(:,:)+nfrzmlt(:,:)+ztmp1(:,:)
 
@@ -575,5 +645,5 @@
 
       CALL cice2nemo(aice,fr_i,'T', 1. )
-      IF ( (nsbc == 2).OR.(nsbc == 5) ) THEN
+      IF ( (ksbc == jp_flx).OR.(ksbc == jp_cpl) ) THEN
          DO jl=1,ncat
             CALL cice2nemo(aicen(:,:,jl,:),a_i(:,:,jl), 'T', 1. )
@@ -611,5 +681,4 @@
 
 
-#if defined key_oasis3 || defined key_oasis4
    SUBROUTINE cice_sbc_hadgam( kt )
       !!---------------------------------------------------------------------
@@ -653,10 +722,4 @@
    END SUBROUTINE cice_sbc_hadgam
 
-#else
-   SUBROUTINE cice_sbc_hadgam( kt )    ! Dummy routine
-      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
-      WRITE(*,*) 'cice_sbc_hadgam: You should not have seen this print! error?'
-   END SUBROUTINE cice_sbc_hadgam
-#endif
 
    SUBROUTINE cice_sbc_final
@@ -713,4 +776,25 @@
       IF( kt == nit000 ) THEN                   !  First call kt=nit000  !
          !                                      ! ====================== !
+         ! namsbc_cice is not yet in the reference namelist
+         ! set file information (default values)
+         cn_dir = './'       ! directory in which the model is executed
+
+         ! (NB: frequency positive => hours, negative => months)
+         !            !    file          ! frequency !  variable    ! time intep !  clim   ! 'yearly' or ! weights  ! rotation   ! landmask
+         !            !    name          !  (hours)  !   name       !   (T/F)    !  (T/F)  !  'monthly'  ! filename ! pairs      ! file
+         sn_snow = FLD_N( 'snowfall_1m'  ,    -1.    ,  'snowfall'  ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    ) 
+         sn_rain = FLD_N( 'rainfall_1m'  ,    -1.    ,  'rainfall'  ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    ) 
+         sn_sblm = FLD_N( 'sublim_1m'    ,    -1.    ,  'sublim'    ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
+         sn_top1 = FLD_N( 'topmeltn1_1m' ,    -1.    ,  'topmeltn1' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
+         sn_top2 = FLD_N( 'topmeltn2_1m' ,    -1.    ,  'topmeltn2' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
+         sn_top3 = FLD_N( 'topmeltn3_1m' ,    -1.    ,  'topmeltn3' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
+         sn_top4 = FLD_N( 'topmeltn4_1m' ,    -1.    ,  'topmeltn4' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
+         sn_top5 = FLD_N( 'topmeltn5_1m' ,    -1.    ,  'topmeltn5' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
+         sn_bot1 = FLD_N( 'botmeltn1_1m' ,    -1.    ,  'botmeltn1' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
+         sn_bot2 = FLD_N( 'botmeltn2_1m' ,    -1.    ,  'botmeltn2' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
+         sn_bot3 = FLD_N( 'botmeltn3_1m' ,    -1.    ,  'botmeltn3' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
+         sn_bot4 = FLD_N( 'botmeltn4_1m' ,    -1.    ,  'botmeltn4' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
+         sn_bot5 = FLD_N( 'botmeltn5_1m' ,    -1.    ,  'botmeltn5' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
+
          REWIND( numnam_ref )              ! Namelist namsbc_cice in reference namelist : 
          READ  ( numnam_ref, namsbc_cice, IOSTAT = ios, ERR = 901)
@@ -1001,9 +1085,9 @@
 CONTAINS
 
-   SUBROUTINE sbc_ice_cice ( kt, nsbc )     ! Dummy routine
+   SUBROUTINE sbc_ice_cice ( kt, ksbc )     ! Dummy routine
       WRITE(*,*) 'sbc_ice_cice: You should not have seen this print! error?', kt
    END SUBROUTINE sbc_ice_cice
 
-   SUBROUTINE cice_sbc_init (nsbc)    ! Dummy routine
+   SUBROUTINE cice_sbc_init (ksbc)    ! Dummy routine
       WRITE(*,*) 'cice_sbc_init: You should not have seen this print! error?'
    END SUBROUTINE cice_sbc_init
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_if.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_if.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_if.F90	(revision 4946)
@@ -16,5 +16,9 @@
    USE eosbn2         ! equation of state
    USE sbc_oce        ! surface boundary condition: ocean fields
-   USE sbccpl
+#if defined key_lim3
+   USE ice    , ONLY :   a_i 
+#else
+   USE sbc_ice, ONLY :   a_i 
+#endif
    USE fldread        ! read input field
    USE iom            ! I/O manager library
@@ -99,13 +103,9 @@
                                  ! ( d rho / dt ) / ( d rho / ds )      ( s = 34, t = -1.8 )
          
-         fr_i(:,:) = tfreez( sss_m ) * tmask(:,:,1)      ! sea surface freezing temperature [Celcius]
+         fr_i(:,:) = eos_fzp( sss_m ) * tmask(:,:,1)      ! sea surface freezing temperature [Celcius]
 
-! OM : probleme. a_i pas defini dans les cas lim3 et cice
-#if defined key_coupled && defined key_lim2
-         a_i(:,:,1) = fr_i(:,:)         
-#endif
+         IF( lk_cpl )   a_i(:,:,1) = fr_i(:,:)         
 
          ! Flux and ice fraction computation
-!CDIR COLLAPSE
          DO jj = 1, jpj
             DO ji = 1, jpi
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 4946)
@@ -12,4 +12,5 @@
    !!            3.4  ! 2011-01  (A Porter)  dynamical allocation
    !!             -   ! 2012-10  (C. Rousset)  add lim_diahsb
+   !!            3.6  ! 2014-07  (M. Vancoppenolle, G. Madec, O. Marti) revise coupled interface
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -59,5 +60,4 @@
    USE prtctl          ! Print control
    USE lib_fortran     ! 
-   USE cpl_oasis3, ONLY : lk_cpl
 
 #if defined key_bdy 
@@ -80,33 +80,4 @@
    !!----------------------------------------------------------------------
 CONTAINS
-
-   FUNCTION fice_cell_ave ( ptab)
-      !!--------------------------------------------------------------------------
-      !! * Compute average over categories, for grid cell (ice covered and free ocean)
-      !!--------------------------------------------------------------------------
-      REAL (wp), DIMENSION (jpi,jpj) :: fice_cell_ave
-      REAL (wp), DIMENSION (jpi,jpj,jpl), INTENT (in) :: ptab
-      INTEGER :: jl ! Dummy loop index
-      
-      fice_cell_ave (:,:) = 0.0_wp
-      
-      DO jl = 1, jpl
-         fice_cell_ave (:,:) = fice_cell_ave (:,:) &
-            &                  + a_i (:,:,jl) * ptab (:,:,jl)
-      END DO
-      
-   END FUNCTION fice_cell_ave
-   
-   FUNCTION fice_ice_ave ( ptab)
-      !!--------------------------------------------------------------------------
-      !! * Compute average over categories, for ice covered part of grid cell
-      !!--------------------------------------------------------------------------
-      REAL (kind=wp), DIMENSION (jpi,jpj) :: fice_ice_ave
-      REAL (kind=wp), DIMENSION (jpi,jpj,jpl), INTENT(in) :: ptab
-
-      fice_ice_ave (:,:) = 0.0_wp
-      WHERE ( at_i (:,:) .GT. 0.0_wp ) fice_ice_ave (:,:) = fice_cell_ave ( ptab (:,:,:)) / at_i (:,:)
-
-   END FUNCTION fice_ice_ave
 
    !!======================================================================
@@ -133,34 +104,13 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt      ! ocean time step
-      INTEGER, INTENT(in) ::   kblk    ! type of bulk (=3 CLIO, =4 CORE)
+      INTEGER, INTENT(in) ::   kblk    ! type of bulk (=3 CLIO, =4 CORE, =5 COUPLED)
       !!
-      INTEGER  ::   ji, jj, jl, jk      ! dummy loop index
+      INTEGER  ::   jl      ! dummy loop index
       REAL(wp) ::   zcoef   ! local scalar
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zalb_ice_os, zalb_ice_cs  ! albedo of the ice under overcast/clear sky
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zalb_ice      ! mean albedo of ice (for coupled)
-
-      REAL(wp), POINTER, DIMENSION(:,:) :: zalb_ice_all    ! Mean albedo over all categories
-      REAL(wp), POINTER, DIMENSION(:,:) :: ztem_ice_all    ! Mean temperature over all categories
-      
-      REAL(wp), POINTER, DIMENSION(:,:) :: z_qsr_ice_all   ! Mean solar heat flux over all categories
-      REAL(wp), POINTER, DIMENSION(:,:) :: z_qns_ice_all   ! Mean non solar heat flux over all categories
-      REAL(wp), POINTER, DIMENSION(:,:) :: z_qla_ice_all   ! Mean latent heat flux over all categories
-      REAL(wp), POINTER, DIMENSION(:,:) :: z_dqns_ice_all  ! Mean d(qns)/dT over all categories
-      REAL(wp), POINTER, DIMENSION(:,:) :: z_dqla_ice_all  ! Mean d(qla)/dT over all categories
-      REAL(wp) ::   ztmelts           ! clem 2014: for HC diags
-      REAL(wp) ::   epsi20 = 1.e-20   !
+      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zalb_os, zalb_cs  ! ice albedo under overcast/clear sky
+      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zalb_ice          ! mean ice albedo (for coupled)
       !!----------------------------------------------------------------------
 
-      !- O.M. : why do we allocate all these arrays even when MOD( kt-1, nn_fsbc ) /= 0 ?????
-
       IF( nn_timing == 1 )  CALL timing_start('sbc_ice_lim')
-
-      CALL wrk_alloc( jpi,jpj,jpl, zalb_ice_os, zalb_ice_cs, zalb_ice )
-
-      IF( lk_cpl ) THEN
-         IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) &
-            &   CALL wrk_alloc( jpi, jpj, ztem_ice_all , zalb_ice_all  , z_qsr_ice_all, z_qns_ice_all,   &
-            &                             z_qla_ice_all, z_dqns_ice_all, z_dqla_ice_all)
-      ENDIF
 
       IF( kt == nit000 ) THEN
@@ -185,26 +135,28 @@
          u_oce(:,:) = ssu_m(:,:) * umask(:,:,1)                     ! mean surface ocean current at ice velocity point
          v_oce(:,:) = ssv_m(:,:) * vmask(:,:,1)                    ! (C-grid dynamics :  U- & V-points as the ocean)
-
-         ! masked sea surface freezing temperature [Kelvin]
-         t_bo(:,:) = ( tfreez( sss_m ) +  rt0 ) * tmask(:,:,1) + rt0 * ( 1. - tmask(:,:,1) )
-
-         CALL albedo_ice( t_su, ht_i, ht_s, zalb_ice_cs, zalb_ice_os )  ! ... ice albedo
-
+         !
+         t_bo(:,:) = ( eos_fzp( sss_m ) +  rt0 ) * tmask(:,:,1) + rt0 * ( 1. - tmask(:,:,1) )  ! masked sea surface freezing temperature [Kelvin]
+         !                                                                                  ! (set to rt0 over land)
+         !                                           ! Ice albedo
+         CALL wrk_alloc( jpi,jpj,jpl, zalb_os, zalb_cs, zalb_ice )      
+
+         CALL albedo_ice( t_su, ht_i, ht_s, zalb_cs, zalb_os )  ! cloud-sky and overcast-sky ice albedos
+
+         SELECT CASE( kblk )
+         CASE( jp_core , jp_cpl )   ! CORE and COUPLED bulk formulations
+
+            ! albedo depends on cloud fraction because of non-linear spectral effects
+            zalb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
+            ! In CLIO the cloud fraction is read in the climatology and the all-sky albedo 
+            ! (zalb_ice) is computed within the bulk routine
+            
+         END SELECT
+         
+         !                                           ! Mask sea ice surface temperature
          DO jl = 1, jpl
             t_su(:,:,jl) = t_su(:,:,jl) +  rt0 * ( 1. - tmask(:,:,1) )
          END DO
-
-         IF ( ln_cpl ) zalb_ice (:,:,:) = 0.5 * ( zalb_ice_cs (:,:,:) +  zalb_ice_os (:,:,:) )
-         
-         IF( lk_cpl ) THEN
-            IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) THEN
-               !
-               ! Compute mean albedo and temperature
-               zalb_ice_all (:,:) = fice_ice_ave ( zalb_ice (:,:,:) ) 
-               ztem_ice_all (:,:) = fice_ice_ave ( tn_ice   (:,:,:) ) 
-               !
-            ENDIF
-         ENDIF
-                                               ! Bulk formulea - provides the following fields:
+     
+         ! Bulk formulae  - provides the following fields:
          ! utau_ice, vtau_ice : surface ice stress                     (U- & V-points)   [N/m2]
          ! qsr_ice , qns_ice  : solar & non solar heat flux over ice   (T-point)         [W/m2]
@@ -215,6 +167,6 @@
          !
          SELECT CASE( kblk )
-         CASE( 3 )                                       ! CLIO bulk formulation
-            CALL blk_ice_clio( t_su , zalb_ice_cs, zalb_ice_os,                           &
+         CASE( jp_clio )                                       ! CLIO bulk formulation
+            CALL blk_ice_clio( t_su , zalb_cs    , zalb_os    , zalb_ice  ,               &
                &                      utau_ice   , vtau_ice   , qns_ice   , qsr_ice   ,   &
                &                      qla_ice    , dqns_ice   , dqla_ice  ,               &
@@ -222,13 +174,8 @@
                &                      fr1_i0     , fr2_i0     , cp_ice_msh, jpl  )
             !         
-         CASE( 4 )                                       ! CORE bulk formulation
-            ! MV 2014
-            ! We must account for cloud fraction in the computation of the albedo
-            ! The present ref just uses the clear sky value
-            ! The overcast sky value is 0.06 higher, and polar skies are mostly overcast
-            ! CORE has no cloud fraction, hence we must prescribe it
-            ! Mean summer cloud fraction computed from CLIO = 0.81
-            zalb_ice(:,:,:) = 0.19 * zalb_ice_cs(:,:,:) + 0.81 * zalb_ice_os(:,:,:)
-            ! Following line, we replace zalb_ice_cs by simply zalb_ice
+            IF( nn_limflx /= 2 )   CALL ice_lim_flx( t_su, zalb_ice, qns_ice, qsr_ice ,   &
+               &                                           dqns_ice, qla_ice, dqla_ice, nn_limflx )
+
+         CASE( jp_core )                                       ! CORE bulk formulation
             CALL blk_ice_core( t_su , u_ice     , v_ice     , zalb_ice   ,               &
                &                      utau_ice  , vtau_ice  , qns_ice    , qsr_ice   ,   &
@@ -236,51 +183,25 @@
                &                      tprecip   , sprecip   ,                            &
                &                      fr1_i0    , fr2_i0    , cp_ice_msh, jpl  )
+               !
+            IF( nn_limflx /= 2 )   CALL ice_lim_flx( t_su, zalb_ice, qns_ice, qsr_ice ,   &
+               &                                           dqns_ice, qla_ice, dqla_ice, nn_limflx )
             !
-         CASE ( 5 )
-            zalb_ice (:,:,:) = 0.5 * ( zalb_ice_cs (:,:,:) +  zalb_ice_os (:,:,:) )
+         CASE ( jp_cpl )
             
             CALL sbc_cpl_ice_tau( utau_ice , vtau_ice )
 
-            CALL sbc_cpl_ice_flx( p_frld=ato_i, palbi=zalb_ice, psst=sst_m, pist=tn_ice    )
-
-            ! Latent heat flux is forced to 0 in coupled :
-            !  it is included in qns (non-solar heat flux)
-            qla_ice  (:,:,:) = 0.0e0_wp
-            dqla_ice (:,:,:) = 0.0e0_wp
+            ! MV -> seb 
+!           CALL sbc_cpl_ice_flx( p_frld=ato_i, palbi=zalb_ice, psst=sst_m, pist=t_su    )
+
+!           IF( nn_limflx == 2 )   CALL ice_lim_flx( t_su, zalb_ice, qns_ice, qsr_ice ,   &
+!              &                                           dqns_ice, qla_ice, dqla_ice, nn_limflx )
+!           ! Latent heat flux is forced to 0 in coupled :
+!           !  it is included in qns (non-solar heat flux)
+!           qla_ice  (:,:,:) = 0._wp
+!           dqla_ice (:,:,:) = 0._wp
+            ! END MV -> seb
             !
          END SELECT
-
-         ! Average over all categories
-         IF( lk_cpl ) THEN
-         IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) THEN
-
-            z_qns_ice_all  (:,:) = fice_ice_ave ( qns_ice  (:,:,:) )
-            z_qsr_ice_all  (:,:) = fice_ice_ave ( qsr_ice  (:,:,:) )
-            z_dqns_ice_all (:,:) = fice_ice_ave ( dqns_ice (:,:,:) )
-            z_qla_ice_all  (:,:) = fice_ice_ave ( qla_ice  (:,:,:) )
-            z_dqla_ice_all (:,:) = fice_ice_ave ( dqla_ice (:,:,:) )
-
-            DO jl = 1, jpl
-               dqns_ice (:,:,jl) = z_dqns_ice_all (:,:)
-               dqla_ice (:,:,jl) = z_dqla_ice_all (:,:)
-            END DO
-            !
-            IF ( ln_iceflx_ave ) THEN
-               DO jl = 1, jpl
-                  qns_ice  (:,:,jl) = z_qns_ice_all  (:,:)
-                  qsr_ice  (:,:,jl) = z_qsr_ice_all  (:,:)
-                  qla_ice  (:,:,jl) = z_qla_ice_all  (:,:)
-               END DO
-            END IF
-            !
-            IF ( ln_iceflx_linear ) THEN
-               DO jl = 1, jpl
-                  qns_ice  (:,:,jl) = z_qns_ice_all(:,:) + z_dqns_ice_all(:,:) * (tn_ice(:,:,jl) - ztem_ice_all(:,:))
-                  qla_ice  (:,:,jl) = z_qla_ice_all(:,:) + z_dqla_ice_all(:,:) * (tn_ice(:,:,jl) - ztem_ice_all(:,:))
-                  qsr_ice  (:,:,jl) = (1.0e0_wp-zalb_ice(:,:,jl)) / (1.0e0_wp-zalb_ice_all(:,:)) * z_qsr_ice_all(:,:)
-               END DO
-            END IF
-         END IF
-         ENDIF
+         
          !                                           !----------------------!
          !                                           ! LIM-3  time-stepping !
@@ -389,4 +310,17 @@
                           pfrld(:,:)   = 1._wp - at_i(:,:)
                           phicif(:,:)  = vt_i(:,:)
+
+                          ! MV -> seb
+                          SELECT CASE( kblk )
+                             CASE ( jp_cpl )
+                             CALL sbc_cpl_ice_flx( p_frld=pfrld, palbi=zalb_ice, psst=sst_m, pist=t_su    )
+                             IF( nn_limflx == 2 )   CALL ice_lim_flx( t_su, zalb_ice, qns_ice, qsr_ice ,   &
+                          &                                           dqns_ice, qla_ice, dqla_ice, nn_limflx )
+                           ! Latent heat flux is forced to 0 in coupled :
+                           !  it is included in qns (non-solar heat flux)
+                             qla_ice  (:,:,:) = 0._wp
+                             dqla_ice (:,:,:) = 0._wp
+                          END SELECT
+                          ! END MV -> seb
                           !
                           CALL lim_var_bv                 ! bulk brine volume (diag)
@@ -420,4 +354,6 @@
          IF( ln_nicep )   CALL lim_ctl( kt )              ! alerts in case of model crash
          !
+         CALL wrk_dealloc( jpi,jpj,jpl, zalb_os, zalb_cs, zalb_ice )
+         !
       ENDIF                                    ! End sea-ice time step only
 
@@ -429,19 +365,92 @@
       !                                                   ! otherwise the atm.-ocean stresses are used everywhere
       IF( ln_limdyn )     CALL lim_sbc_tau( kt, ub(:,:,1), vb(:,:,1) )  ! using before instantaneous surf. currents
-      
 !!gm   remark, the ocean-ice stress is not saved in ice diag call above .....  find a solution!!!
-      CALL wrk_dealloc( jpi,jpj,jpl, zalb_ice_os, zalb_ice_cs, zalb_ice )
-
-      IF( lk_cpl ) THEN
-         IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) &
-            &    CALL wrk_dealloc( jpi, jpj, ztem_ice_all , zalb_ice_all , z_qsr_ice_all, z_qns_ice_all,   &
-            &                                z_qla_ice_all, z_dqns_ice_all, z_dqla_ice_all)
-      ENDIF
+
       !
       IF( nn_timing == 1 )  CALL timing_stop('sbc_ice_lim')
       !
    END SUBROUTINE sbc_ice_lim
-
-
+   
+   
+      SUBROUTINE ice_lim_flx( ptn_ice, palb_ice, pqns_ice, pqsr_ice,   &
+         &                          pdqn_ice, pqla_ice, pdql_ice, k_limflx )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_ice_lim  ***
+      !!                   
+      !! ** Purpose :   update the ice surface boundary condition by averaging and / or
+      !!                redistributing fluxes on ice categories                   
+      !!
+      !! ** Method  :   average then redistribute 
+      !!
+      !! ** Action  :   
+      !!---------------------------------------------------------------------
+      INTEGER                   , INTENT(in   ) ::   k_limflx   ! =-1 do nothing; =0 average ; 
+                                                                ! =1 average and redistribute ; =2 redistribute
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   ptn_ice    ! ice surface temperature 
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   palb_ice   ! ice albedo
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pqns_ice   ! non solar flux
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pqsr_ice   ! net solar flux
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdqn_ice   ! non solar flux sensitivity
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pqla_ice   ! latent heat flux
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdql_ice   ! latent heat flux sensitivity
+      !
+      INTEGER  ::   jl      ! dummy loop index
+      !
+      REAL(wp), POINTER, DIMENSION(:,:) :: zalb_m    ! Mean albedo over all categories
+      REAL(wp), POINTER, DIMENSION(:,:) :: ztem_m    ! Mean temperature over all categories
+      !
+      REAL(wp), POINTER, DIMENSION(:,:) :: z_qsr_m   ! Mean solar heat flux over all categories
+      REAL(wp), POINTER, DIMENSION(:,:) :: z_qns_m   ! Mean non solar heat flux over all categories
+      REAL(wp), POINTER, DIMENSION(:,:) :: z_qla_m   ! Mean latent heat flux over all categories
+      REAL(wp), POINTER, DIMENSION(:,:) :: z_dqn_m   ! Mean d(qns)/dT over all categories
+      REAL(wp), POINTER, DIMENSION(:,:) :: z_dql_m   ! Mean d(qla)/dT over all categories
+      !!----------------------------------------------------------------------
+
+      IF( nn_timing == 1 )  CALL timing_start('ice_lim_flx')
+      !
+      !
+      SELECT CASE( k_limflx )                              !==  averaged on all ice categories  ==!
+      CASE( 0 , 1 )
+         CALL wrk_alloc( jpi,jpj, z_qsr_m, z_qns_m, z_qla_m, z_dqn_m, z_dql_m)
+         !
+         z_qns_m(:,:) = fice_ice_ave ( pqns_ice (:,:,:) )
+         z_qsr_m(:,:) = fice_ice_ave ( pqsr_ice (:,:,:) )
+         z_dqn_m(:,:) = fice_ice_ave ( pdqn_ice (:,:,:) )
+         z_qla_m(:,:) = fice_ice_ave ( pqla_ice (:,:,:) )
+         z_dql_m(:,:) = fice_ice_ave ( pdql_ice (:,:,:) )
+         DO jl = 1, jpl
+            pdqn_ice(:,:,jl) = z_dqn_m(:,:)
+            pdql_ice(:,:,jl) = z_dql_m(:,:)
+         END DO
+         !
+         DO jl = 1, jpl
+            pqns_ice(:,:,jl) = z_qns_m(:,:)
+            pqsr_ice(:,:,jl) = z_qsr_m(:,:)
+            pqla_ice(:,:,jl) = z_qla_m(:,:)
+         END DO
+         !
+         CALL wrk_dealloc( jpi,jpj, z_qsr_m, z_qns_m, z_qla_m, z_dqn_m, z_dql_m)
+      END SELECT
+
+      SELECT CASE( k_limflx )                              !==  redistribution on all ice categories  ==!
+      CASE( 1 , 2 )
+         CALL wrk_alloc( jpi,jpj, zalb_m, ztem_m )
+         !
+         zalb_m(:,:) = fice_ice_ave ( palb_ice (:,:,:) ) 
+         ztem_m(:,:) = fice_ice_ave ( ptn_ice  (:,:,:) ) 
+         DO jl = 1, jpl
+            pqns_ice(:,:,jl) = pqns_ice(:,:,jl) + pdqn_ice(:,:,jl) * (ptn_ice(:,:,jl) - ztem_m(:,:))
+            pqla_ice(:,:,jl) = pqla_ice(:,:,jl) + pdql_ice(:,:,jl) * (ptn_ice(:,:,jl) - ztem_m(:,:))
+            pqsr_ice(:,:,jl) = pqsr_ice(:,:,jl) * ( 1._wp - palb_ice(:,:,jl) ) / ( 1._wp - zalb_m(:,:) ) 
+         END DO
+         !
+         CALL wrk_dealloc( jpi,jpj, zalb_m, ztem_m )
+      END SELECT
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('ice_lim_flx')
+      !
+   END SUBROUTINE ice_lim_flx
+   
+   
    SUBROUTINE lim_ctl( kt )
       !!-----------------------------------------------------------------------
@@ -675,5 +684,5 @@
       !!                n : number of the option
       !!-------------------------------------------------------------------
-      INTEGER         , INTENT(in) ::   kt      ! ocean time step
+      INTEGER         , INTENT(in) ::   kt            ! ocean time step
       INTEGER         , INTENT(in) ::   ki, kj, kn    ! ocean gridpoint indices
       CHARACTER(len=*), INTENT(in) ::   cd1           !
@@ -853,6 +862,38 @@
          END DO
       END DO
-
+      !
    END SUBROUTINE lim_prt_state
+   
+     
+   FUNCTION fice_cell_ave ( ptab )
+      !!--------------------------------------------------------------------------
+      !! * Compute average over categories, for grid cell (ice covered and free ocean)
+      !!--------------------------------------------------------------------------
+      REAL (wp), DIMENSION (jpi,jpj) :: fice_cell_ave
+      REAL (wp), DIMENSION (jpi,jpj,jpl), INTENT (in) :: ptab
+      INTEGER :: jl ! Dummy loop index
+      
+      fice_cell_ave (:,:) = 0.0_wp
+      
+      DO jl = 1, jpl
+         fice_cell_ave (:,:) = fice_cell_ave (:,:) &
+            &                  + a_i (:,:,jl) * ptab (:,:,jl)
+      END DO
+      
+   END FUNCTION fice_cell_ave
+   
+   
+   FUNCTION fice_ice_ave ( ptab )
+      !!--------------------------------------------------------------------------
+      !! * Compute average over categories, for ice covered part of grid cell
+      !!--------------------------------------------------------------------------
+      REAL (kind=wp), DIMENSION (jpi,jpj) :: fice_ice_ave
+      REAL (kind=wp), DIMENSION (jpi,jpj,jpl), INTENT(in) :: ptab
+
+      fice_ice_ave (:,:) = 0.0_wp
+      WHERE ( at_i (:,:) .GT. 0.0_wp ) fice_ice_ave (:,:) = fice_cell_ave ( ptab (:,:,:)) / at_i (:,:)
+
+   END FUNCTION fice_ice_ave
+
 
 #else
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90	(revision 4946)
@@ -97,10 +97,11 @@
       !!
       INTEGER  ::   ji, jj   ! dummy loop indices
-      REAL(wp), DIMENSION(:,:,:), POINTER :: zalb_ice_os   ! albedo of the ice under overcast sky
-      REAL(wp), DIMENSION(:,:,:), POINTER :: zalb_ice_cs   ! albedo of ice under clear sky
-      REAL(wp), DIMENSION(:,:,:), POINTER :: zsist         ! surface ice temperature (K)
+      REAL(wp), DIMENSION(:,:,:), POINTER :: zalb_os   ! ice albedo under overcast sky
+      REAL(wp), DIMENSION(:,:,:), POINTER :: zalb_cs   ! ice albedo under clear sky
+      REAL(wp), DIMENSION(:,:,:), POINTER :: zalb_ice  ! mean ice albedo
+      REAL(wp), DIMENSION(:,:,:), POINTER :: zsist     ! ice surface temperature (K)
       !!----------------------------------------------------------------------
 
-      CALL wrk_alloc( jpi,jpj,1, zalb_ice_os, zalb_ice_cs, zsist )
+      CALL wrk_alloc( jpi,jpj,1, zalb_os, zalb_cs, zalb_ice, zsist )
 
       IF( kt == nit000 ) THEN
@@ -130,6 +131,8 @@
             DO jj = 2, jpj
                DO ji = 2, jpi   ! NO vector opt. possible
-                  u_oce(ji,jj) = 0.5_wp * ( ssu_m(ji-1,jj  ) * umask(ji-1,jj  ,1) + ssu_m(ji-1,jj-1) * umask(ji-1,jj-1,1) ) * tmu(ji,jj)
-                  v_oce(ji,jj) = 0.5_wp * ( ssv_m(ji  ,jj-1) * vmask(ji  ,jj-1,1) + ssv_m(ji-1,jj-1) * vmask(ji-1,jj-1,1) ) * tmu(ji,jj)
+                  u_oce(ji,jj) = 0.5_wp * ( ssu_m(ji-1,jj  ) * umask(ji-1,jj  ,1) &
+                     &           + ssu_m(ji-1,jj-1) * umask(ji-1,jj-1,1) ) * tmu(ji,jj)
+                  v_oce(ji,jj) = 0.5_wp * ( ssv_m(ji  ,jj-1) * vmask(ji  ,jj-1,1) &
+                     &           + ssv_m(ji-1,jj-1) * vmask(ji-1,jj-1,1) ) * tmu(ji,jj)
                END DO
             END DO
@@ -144,12 +147,23 @@
 
          ! ... masked sea surface freezing temperature [Kelvin] (set to rt0 over land)
-         tfu(:,:) = tfreez( sss_m ) +  rt0 
+         tfu(:,:) = eos_fzp( sss_m ) +  rt0 
 
          zsist (:,:,1) = sist (:,:) + rt0 * ( 1. - tmask(:,:,1) )
 
-         ! ... ice albedo (clear sky and overcast sky)
+         ! Ice albedo
+
          CALL albedo_ice( zsist, reshape( hicif, (/jpi,jpj,1/) ), &
                                  reshape( hsnif, (/jpi,jpj,1/) ), &
-                          zalb_ice_cs, zalb_ice_os )
+                          zalb_cs, zalb_os )
+
+         SELECT CASE( ksbc )
+         CASE( jp_core , jp_cpl )   ! CORE and COUPLED bulk formulations
+
+            ! albedo depends on cloud fraction because of non-linear spectral effects
+            zalb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
+            ! In CLIO the cloud fraction is read in the climatology and the all-sky albedo 
+            ! (zalb_ice) is computed within the bulk routine
+
+         END SELECT
 
          ! ... Sea-ice surface boundary conditions output from bulk formulae :
@@ -167,6 +181,6 @@
          !
          SELECT CASE( ksbc )
-         CASE( 3 )           ! CLIO bulk formulation
-            CALL blk_ice_clio( zsist, zalb_ice_cs, zalb_ice_os,                         &
+         CASE( jp_clio )           ! CLIO bulk formulation
+            CALL blk_ice_clio( zsist, zalb_cs    , zalb_os    , zalb_ice   ,            &
                &                      utau_ice   , vtau_ice   , qns_ice    , qsr_ice,   &
                &                      qla_ice    , dqns_ice   , dqla_ice   ,            &
@@ -174,13 +188,13 @@
                &                      fr1_i0     , fr2_i0     , cp_ice_msh , jpl  )
 
-         CASE( 4 )           ! CORE bulk formulation
-            CALL blk_ice_core( zsist, u_ice      , v_ice      , zalb_ice_cs,            &
+         CASE( jp_core )           ! CORE bulk formulation
+            CALL blk_ice_core( zsist, u_ice      , v_ice      , zalb_ice   ,            &
                &                      utau_ice   , vtau_ice   , qns_ice    , qsr_ice,   &
                &                      qla_ice    , dqns_ice   , dqla_ice   ,            &
                &                      tprecip    , sprecip    ,                         &
                &                      fr1_i0     , fr2_i0     , cp_ice_msh , jpl  )
-            IF( ltrcdm2dc_ice )   CALL blk_ice_meanqsr( zalb_ice_cs, qsr_ice_mean, jpl )
-
-         CASE( 5 )           ! Coupled formulation : atmosphere-ice stress only (fluxes provided after ice dynamics)
+            IF( ltrcdm2dc_ice )   CALL blk_ice_meanqsr( zalb_ice, qsr_ice_mean, jpl )
+
+         CASE( jp_cpl )            ! Coupled formulation : atmosphere-ice stress only (fluxes provided after ice dynamics)
             CALL sbc_cpl_ice_tau( utau_ice , vtau_ice )
          END SELECT
@@ -213,14 +227,12 @@
 #endif
          END IF
-#if defined key_coupled
          !                                             ! Ice surface fluxes in coupled mode 
-         IF( ksbc == 5 )   THEN
+         IF( ksbc == jp_cpl )   THEN
             a_i(:,:,1)=fr_i
             CALL sbc_cpl_ice_flx( frld,                                              &
             !                                optional arguments, used only in 'mixed oce-ice' case
-            &                                             palbi = zalb_ice_cs, psst = sst_m, pist = zsist )
+            &                                             palbi = zalb_ice, psst = sst_m, pist = zsist )
             sprecip(:,:) = - emp_ice(:,:)   ! Ugly patch, WARNING, in coupled mode, sublimation included in snow (parsub = 0.)
          ENDIF
-#endif
                            CALL lim_thd_2      ( kt )      ! Ice thermodynamics 
                            CALL lim_sbc_flx_2  ( kt )      ! update surface ocean mass, heat & salt fluxes 
@@ -252,5 +264,5 @@
       IF( ln_limdyn    )   CALL lim_sbc_tau_2( kt, ub(:,:,1), vb(:,:,1) )  ! using before instantaneous surf. currents
       !
-      CALL wrk_dealloc( jpi,jpj,1, zalb_ice_os, zalb_ice_cs, zsist )
+      CALL wrk_dealloc( jpi,jpj,1, zalb_os, zalb_cs, zalb_ice, zsist )
       !
    END SUBROUTINE sbc_ice_lim_2
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90	(revision 4946)
@@ -54,6 +54,12 @@
    REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  risfLeff               !:effective length (Leff) BG03 nn_isf==2
    REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  ttbl, stbl, utbl, vtbl !:top boundary layer variable at T point
-   INTEGER(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  misfkt, misfkb         !:Level of ice shelf base
+#ifdef key_agrif
+   ! AGRIF can not handle these arrays as integers. The reason is a mystery but problems avoided by declaring them as reals
+   REAL(wp),    PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  misfkt, misfkb         !:Level of ice shelf base
                                                                                           !: (first wet level and last level include in the tbl)
+#else
+   INTEGER,    PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  misfkt, misfkb         !:Level of ice shelf base
+#endif
+
 
    REAL(wp), PUBLIC, SAVE ::   rcpi   = 2000.0_wp     ! phycst ?
@@ -303,8 +309,11 @@
       sbc_isf_alloc = 0       ! set to zero if no array to be allocated
       IF( .NOT. ALLOCATED( qisf ) ) THEN
-         ALLOCATE(  risf_tsc(jpi,jpj,jpts), risf_tsc_b(jpi,jpj,jpts), qisf(jpi,jpj), fwfisf(jpi,jpj), &
-               &    fwfisf_b(jpi,jpj), misfkt(jpi,jpj), rhisf_tbl(jpi,jpj), r1_hisf_tbl(jpi,jpj),     &
-               &    rzisf_tbl(jpi,jpj), misfkb(jpi,jpj), ttbl(jpi,jpj), stbl(jpi,jpj), utbl(jpi,jpj), &
-               &    vtbl(jpi, jpj), risfLeff(jpi,jpj), rhisf_tbl_0(jpi,jpj), ralpha(jpi,jpj), STAT= sbc_isf_alloc )
+         ALLOCATE(  risf_tsc(jpi,jpj,jpts), risf_tsc_b(jpi,jpj,jpts)              , &
+               &    qisf(jpi,jpj)     , fwfisf(jpi,jpj)     , fwfisf_b(jpi,jpj)   , &
+               &    rhisf_tbl(jpi,jpj), r1_hisf_tbl(jpi,jpj), rzisf_tbl(jpi,jpj)  , &
+               &    ttbl(jpi,jpj)     , stbl(jpi,jpj)       , utbl(jpi,jpj)       , &
+               &    vtbl(jpi, jpj)    , risfLeff(jpi,jpj)   , rhisf_tbl_0(jpi,jpj), &
+               &    ralpha(jpi,jpj)   , misfkt(jpi,jpj)     , misfkb(jpi,jpj)     , &
+               &    STAT= sbc_isf_alloc )
          !
          IF( lk_mpp                  )   CALL mpp_sum ( sbc_isf_alloc )
@@ -363,5 +372,5 @@
              ! Calculate freezing temperature
                 zpress = grav*rau0*fsdept(ji,jj,ik)*1.e-04 
-                zt_frz = tfreez1D(tsb(ji,jj,ik,jp_sal), zpress) 
+                zt_frz = eos_fzp(tsb(ji,jj,ik,jp_sal), zpress) 
                 zt_sum = zt_sum + (tsn(ji,jj,ik,jp_tem)-zt_frz) * fse3t(ji,jj,ik) * tmask(ji,jj,ik)  ! sum temp
              ENDDO
@@ -445,5 +454,5 @@
       zti(:,:)=tinsitu( ttbl, stbl, zpress )
 ! Calculate freezing temperature
-      zfrz(:,:)=tfreez( sss_m(:,:), zpress )
+      zfrz(:,:)=eos_fzp( sss_m(:,:), zpress )
 
       
@@ -526,5 +535,6 @@
                      nit = nit + 1
                      IF (nit .GE. 51) THEN
-                        WRITE(numout,*) "sbcisf : too many iteration ... ", zhtflx, zhtflx_b, zgammat, zgammas, nn_gammablk, ji, jj, mikt(ji,jj), narea
+                        WRITE(numout,*) "sbcisf : too many iteration ... ", &
+                            &  zhtflx, zhtflx_b, zgammat, zgammas, nn_gammablk, ji, jj, mikt(ji,jj), narea
                         CALL ctl_stop( 'STOP', 'sbc_isf_hol99 : too many iteration ...' )
                      END IF
@@ -584,10 +594,10 @@
       REAL(wp) :: zgmolet, zgmoles, zgturb   ! contribution of modelecular sublayer and turbulence 
       REAL(wp) :: zcoef                      ! temporary coef
-      REAL(wp) :: zrhos, zalbet, zbeta, zthermal, zhalin
-      REAL(wp) :: zt, zs, zh
+      REAL(wp) :: zdep
       REAL(wp), PARAMETER :: zxsiN = 0.052   ! dimensionless constant
       REAL(wp), PARAMETER :: epsln = 1.0e-20 ! a small positive number
       REAL(wp), PARAMETER :: znu   = 1.95e-6 ! kinamatic viscosity of sea water (m2.s-1)
       REAL(wp) ::   rcs      = 1.0e-3_wp        ! conversion: mm/s ==> m/s
+      REAL(wp), DIMENSION(2) :: zts, zab
       !!---------------------------------------------------------------------
       !
@@ -656,44 +666,12 @@
 
       !! compute bouyancy 
-               IF( nn_eos < 1) THEN
-                  zt     = ttbl(ji,jj)
-                  zs     = stbl(ji,jj) - 35.0
-                  zh     = fsdepw(ji,jj,ikt)
-                  !  potential volumic mass
-                  zrhos  = rhop(ji,jj,ikt)
-                  zalbet = ( ( ( - 0.255019e-07 * zt + 0.298357e-05 ) * zt   &   ! ratio alpha/beta
-                     &                               - 0.203814e-03 ) * zt   &
-                     &                               + 0.170907e-01 ) * zt   &
-                     &   + 0.665157e-01                                      &
-                     &   +     ( - 0.678662e-05 * zs                         &
-                     &           - 0.846960e-04 * zt + 0.378110e-02 ) * zs   &
-                     &   +   ( ( - 0.302285e-13 * zh                         &
-                     &           - 0.251520e-11 * zs                         &
-                     &           + 0.512857e-12 * zt * zt           ) * zh   &
-                     &           - 0.164759e-06 * zs                         &
-                     &        +(   0.791325e-08 * zt - 0.933746e-06 ) * zt   &
-                     &                               + 0.380374e-04 ) * zh
-
-                  zbeta  = ( ( -0.415613e-09 * zt + 0.555579e-07 ) * zt      &   ! beta
-                     &                            - 0.301985e-05 ) * zt      &
-                     &   + 0.785567e-03                                      &
-                     &   + (     0.515032e-08 * zs                           &
-                     &         + 0.788212e-08 * zt - 0.356603e-06 ) * zs     &
-                     &   +(  (   0.121551e-17 * zh                           &
-                     &         - 0.602281e-15 * zs                           &
-                     &         - 0.175379e-14 * zt + 0.176621e-12 ) * zh     &
-                     &                             + 0.408195e-10   * zs     &
-                     &     + ( - 0.213127e-11 * zt + 0.192867e-09 ) * zt     &
-                     &                             - 0.121555e-07 ) * zh
-
-                  zthermal = zbeta * zalbet / ( rcp * zrhos + epsln )
-                  zhalin   = zbeta * stbl(ji,jj) * rcs
-               ELSE
-                  zrhos    = rhop(ji,jj,ikt) + rau0 * ( 1. - tmask(ji,jj,ikt) )
-                  zthermal = rn_alpha / ( rcp * zrhos + epsln )
-                  zhalin   = rn_beta * stbl(ji,jj) * rcs
-               ENDIF
+               zts(jp_tem) = ttbl(ji,jj)
+               zts(jp_sal) = stbl(ji,jj)
+               zdep        = fsdepw(ji,jj,ikt)
+               !
+               CALL eos_rab( zts, zdep, zab )
+                  !
       !! compute length scale 
-               zbuofdep = grav * ( zthermal * zqhisf - zhalin * zqwisf )  !!!!!!!!!!!!!!!!!!!!!!!!!!!!
+               zbuofdep = grav * ( zab(jp_tem) * zqhisf - zab(jp_sal) * zqwisf )  !!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
       !! compute Monin Obukov Length
@@ -766,7 +744,10 @@
                ! level partially include in ice shelf boundary layer 
                zhk = SUM( fse3t_n(ji, jj, ikt:ikb - 1)) * r1_hisf_tbl(ji,jj)
-               IF (cptin == 'T') varout(ji,jj) = varout(ji,jj) + varin(ji,jj,ikb) * (1._wp - zhk)
-               IF (cptin == 'U') varout(ji,jj) = varout(ji,jj) + 0.5_wp * (varin(ji,jj,ikb) + varin(ji-1,jj,ikb)) * (1._wp - zhk)
-               IF (cptin == 'V') varout(ji,jj) = varout(ji,jj) + 0.5_wp * (varin(ji,jj,ikb) + varin(ji,jj-1,ikb)) * (1._wp - zhk)
+               IF (cptin == 'T') &
+                   &  varout(ji,jj) = varout(ji,jj) + varin(ji,jj,ikb) * (1._wp - zhk)
+               IF (cptin == 'U') &
+                   &  varout(ji,jj) = varout(ji,jj) + 0.5_wp * (varin(ji,jj,ikb) + varin(ji-1,jj,ikb)) * (1._wp - zhk)
+               IF (cptin == 'V') &
+                   &  varout(ji,jj) = varout(ji,jj) + 0.5_wp * (varin(ji,jj,ikb) + varin(ji,jj-1,ikb)) * (1._wp - zhk)
             END IF
          END DO
@@ -796,7 +777,7 @@
       REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   phdivn   ! horizontal divergence
       !!
-      INTEGER(wp)  ::   ji, jj, jk   ! dummy loop indices
-      INTEGER(wp)  ::   ikt, ikb 
-      INTEGER(wp)  ::   nk_isf
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   ikt, ikb 
+      INTEGER  ::   nk_isf
       REAL(wp)     ::   zhk, z1_hisf_tbl, zhisf_tbl
       REAL(wp)     ::   zfact     ! local scalar
@@ -834,8 +815,10 @@
                ! level fully include in the ice shelf boundary layer
                DO jk = ikt, ikb - 1
-                  phdivn(ji,jj,jk) = phdivn(ji,jj,jk) + ( fwfisf(ji,jj) + fwfisf_b(ji,jj) ) * r1_hisf_tbl(ji,jj) * r1_rau0 * zfact
+                  phdivn(ji,jj,jk) = phdivn(ji,jj,jk) + ( fwfisf(ji,jj) + fwfisf_b(ji,jj) ) &
+                    &               * r1_hisf_tbl(ji,jj) * r1_rau0 * zfact
                END DO
                ! level partially include in ice shelf boundary layer 
-               phdivn(ji,jj,ikb) = phdivn(ji,jj,ikb) + ( fwfisf(ji,jj) + fwfisf_b(ji,jj) ) * r1_hisf_tbl(ji,jj) * r1_rau0 * zfact * ralpha(ji,jj) 
+               phdivn(ji,jj,ikb) = phdivn(ji,jj,ikb) + ( fwfisf(ji,jj) &
+                  &             + fwfisf_b(ji,jj) ) * r1_hisf_tbl(ji,jj) * r1_rau0 * zfact * ralpha(ji,jj) 
             !==   ice shelf melting mass distributed over several levels   ==!
          END DO
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 4946)
@@ -37,5 +37,4 @@
    USE sbcice_cice      ! surface boundary condition: CICE    sea-ice model
    USE sbccpl           ! surface boundary condition: coupled florulation
-   USE cpl_oasis3, ONLY:lk_cpl      ! are we in coupled mode?
    USE sbcssr           ! surface boundary condition: sea surface restoring
    USE sbcrnf           ! surface boundary condition: runoffs
@@ -83,7 +82,7 @@
       INTEGER ::   icpt   ! local integer
       !!
-      NAMELIST/namsbc/ nn_fsbc   , ln_ana    , ln_flx,  ln_blk_clio, ln_blk_core, ln_cpl,   &
+      NAMELIST/namsbc/ nn_fsbc   , ln_ana    , ln_flx,  ln_blk_clio, ln_blk_core,           &
          &             ln_blk_mfs, ln_apr_dyn, nn_ice,  nn_ice_embd, ln_dm2dc   , ln_rnf,   &
-         &             ln_ssr    , nn_isf    , nn_fwb,  ln_cdgw    , ln_wave    , ln_sdw, nn_lsm, cn_iceflx
+         &             ln_ssr    ,  nn_isf , nn_fwb    , ln_cdgw , ln_wave , ln_sdw, nn_lsm, nn_limflx
       INTEGER  ::   ios
       !!----------------------------------------------------------------------
@@ -124,6 +123,6 @@
          WRITE(numout,*) '              CORE bulk  formulation                     ln_blk_core = ', ln_blk_core
          WRITE(numout,*) '              MFS  bulk  formulation                     ln_blk_mfs  = ', ln_blk_mfs
-         WRITE(numout,*) '              coupled    formulation (T if key_sbc_cpl)  ln_cpl      = ', ln_cpl
-         WRITE(numout,*) '              Flux handling over ice categories          cn_iceflx   = ', TRIM (cn_iceflx)
+         WRITE(numout,*) '              coupled    formulation (T if key_oasis3)   lk_cpl      = ', lk_cpl
+         WRITE(numout,*) '              Multicategory heat flux formulation (LIM3) nn_limflx   = ', nn_limflx
          WRITE(numout,*) '           Misc. options of sbc : '
          WRITE(numout,*) '              Patm gradient added in ocean & ice Eqs.    ln_apr_dyn  = ', ln_apr_dyn
@@ -139,20 +138,15 @@
       ENDIF
 
-      !   Flux handling over ice categories
-#if defined key_coupled 
-      SELECT CASE ( TRIM (cn_iceflx))
-      CASE ('ave')
-         ln_iceflx_ave    = .TRUE.
-         ln_iceflx_linear = .FALSE.
-      CASE ('linear')
-         ln_iceflx_ave    = .FALSE.
-         ln_iceflx_linear = .TRUE.
-      CASE default
-         ln_iceflx_ave    = .FALSE.
-         ln_iceflx_linear = .FALSE.
+      ! LIM3 Multi-category heat flux formulation
+      SELECT CASE ( nn_limflx)
+      CASE ( -1 )
+         IF(lwp) WRITE(numout,*) '              Use of per-category fluxes (nn_limflx = -1) '
+      CASE ( 0  )
+         IF(lwp) WRITE(numout,*) '              Average per-category fluxes (nn_limflx = 0) ' 
+      CASE ( 1  )
+         IF(lwp) WRITE(numout,*) '              Average then redistribute per-category fluxes (nn_limflx = 1) '
+      CASE ( 2  )
+         IF(lwp) WRITE(numout,*) '              Redistribute a single flux over categories (nn_limflx = 2) '
       END SELECT
-      IF(lwp) WRITE(numout,*) '              Fluxes averaged over all ice categories         ln_iceflx_ave    = ', ln_iceflx_ave
-      IF(lwp) WRITE(numout,*) '              Fluxes distributed linearly over ice categories ln_iceflx_linear = ', ln_iceflx_linear
-#endif
       !
 #if defined key_top && ! defined key_offline
@@ -214,10 +208,11 @@
       IF( ( nn_ice == 3 .OR. nn_ice == 4 ) .AND. nn_ice_embd == 0 )   &
          &   CALL ctl_stop( 'LIM3 and CICE sea-ice models require nn_ice_embd = 1 or 2' )
-#if defined key_coupled
-      IF( ln_iceflx_ave .AND. ln_iceflx_linear ) &
-         &   CALL ctl_stop( ' ln_iceflx_ave and ln_iceflx_linear options are not compatible' )
-      IF( ( nn_ice ==3 .AND. lk_cpl) .AND. .NOT. ( ln_iceflx_ave .OR. ln_iceflx_linear ) ) &
-         &   CALL ctl_stop( ' With lim3 coupled, either ln_iceflx_ave or ln_iceflx_linear must be set to .TRUE.' )
-#endif      
+      IF( ( nn_ice /= 3 ) .AND. ( nn_limflx >= 0 ) )   &
+         &   WRITE(numout,*) 'The nn_limflx>=0 option has no effect if sea ice model is not LIM3'
+      IF( ( nn_ice == 3 ) .AND. ( lk_cpl ) .AND. ( ( nn_limflx == -1 ) .OR. ( nn_limflx == 1 ) ) )   &
+         &   CALL ctl_stop( 'The chosen nn_limflx for LIM3 in coupled mode must be 0 or 2' )
+      IF( ( nn_ice == 3 ) .AND. ( .NOT. lk_cpl ) .AND. ( nn_limflx == 2 ) )   &
+         &   CALL ctl_stop( 'The chosen nn_limflx for LIM3 in forced mode cannot be 2' )
+
       IF( ln_dm2dc )   nday_qsr = -1   ! initialisation flag
 
@@ -244,12 +239,12 @@
       !                          ! Choice of the Surface Boudary Condition (set nsbc)
       icpt = 0
-      IF( ln_ana          ) THEN   ;   nsbc =  1   ; icpt = icpt + 1   ;   ENDIF       ! analytical      formulation
-      IF( ln_flx          ) THEN   ;   nsbc =  2   ; icpt = icpt + 1   ;   ENDIF       ! flux            formulation
-      IF( ln_blk_clio     ) THEN   ;   nsbc =  3   ; icpt = icpt + 1   ;   ENDIF       ! CLIO bulk       formulation
-      IF( ln_blk_core     ) THEN   ;   nsbc =  4   ; icpt = icpt + 1   ;   ENDIF       ! CORE bulk       formulation
-      IF( ln_blk_mfs      ) THEN   ;   nsbc =  6   ; icpt = icpt + 1   ;   ENDIF       ! MFS  bulk       formulation
-      IF( ln_cpl          ) THEN   ;   nsbc =  5   ; icpt = icpt + 1   ;   ENDIF       ! Coupled         formulation
-      IF( cp_cfg == 'gyre') THEN   ;   nsbc =  0                       ;   ENDIF       ! GYRE analytical formulation
-      IF( lk_esopa        )            nsbc = -1                                       ! esopa test, ALL formulations
+      IF( ln_ana          ) THEN   ;   nsbc = jp_ana    ; icpt = icpt + 1   ;   ENDIF       ! analytical      formulation
+      IF( ln_flx          ) THEN   ;   nsbc = jp_flx    ; icpt = icpt + 1   ;   ENDIF       ! flux            formulation
+      IF( ln_blk_clio     ) THEN   ;   nsbc = jp_clio   ; icpt = icpt + 1   ;   ENDIF       ! CLIO bulk       formulation
+      IF( ln_blk_core     ) THEN   ;   nsbc = jp_core   ; icpt = icpt + 1   ;   ENDIF       ! CORE bulk       formulation
+      IF( ln_blk_mfs      ) THEN   ;   nsbc = jp_mfs    ; icpt = icpt + 1   ;   ENDIF       ! MFS  bulk       formulation
+      IF( lk_cpl          ) THEN   ;   nsbc = jp_cpl    ; icpt = icpt + 1   ;   ENDIF       ! Coupled         formulation
+      IF( cp_cfg == 'gyre') THEN   ;   nsbc = jp_gyre                       ;   ENDIF       ! GYRE analytical formulation
+      IF( lk_esopa        )            nsbc = jp_esopa                                      ! esopa test, ALL formulations
       !
       IF( icpt /= 1 .AND. .NOT.lk_esopa ) THEN
@@ -262,20 +257,22 @@
       IF(lwp) THEN
          WRITE(numout,*)
-         IF( nsbc == -1 )   WRITE(numout,*) '              ESOPA test All surface boundary conditions'
-         IF( nsbc ==  0 )   WRITE(numout,*) '              GYRE analytical formulation'
-         IF( nsbc ==  1 )   WRITE(numout,*) '              analytical formulation'
-         IF( nsbc ==  2 )   WRITE(numout,*) '              flux formulation'
-         IF( nsbc ==  3 )   WRITE(numout,*) '              CLIO bulk formulation'
-         IF( nsbc ==  4 )   WRITE(numout,*) '              CORE bulk formulation'
-         IF( nsbc ==  5 )   WRITE(numout,*) '              coupled formulation'
-         IF( nsbc ==  6 )   WRITE(numout,*) '              MFS Bulk formulation'
-      ENDIF
-      !
-                          CALL sbc_ssm_init               ! Sea-surface mean fields initialisation
-      !
-      IF( ln_ssr      )   CALL sbc_ssr_init               ! Sea-Surface Restoring initialisation
-      !
-      IF( nn_ice == 4 )   CALL cice_sbc_init( nsbc )      ! CICE initialisation
-      !
+         IF( nsbc == jp_esopa )   WRITE(numout,*) '              ESOPA test All surface boundary conditions'
+         IF( nsbc == jp_gyre  )   WRITE(numout,*) '              GYRE analytical formulation'
+         IF( nsbc == jp_ana   )   WRITE(numout,*) '              analytical formulation'
+         IF( nsbc == jp_flx   )   WRITE(numout,*) '              flux formulation'
+         IF( nsbc == jp_clio  )   WRITE(numout,*) '              CLIO bulk formulation'
+         IF( nsbc == jp_core  )   WRITE(numout,*) '              CORE bulk formulation'
+         IF( nsbc == jp_cpl   )   WRITE(numout,*) '              coupled formulation'
+         IF( nsbc == jp_mfs   )   WRITE(numout,*) '              MFS Bulk formulation'
+      ENDIF
+      !
+                               CALL sbc_ssm_init               ! Sea-surface mean fields initialisation
+      !
+      IF( ln_ssr           )   CALL sbc_ssr_init               ! Sea-Surface Restoring initialisation
+      !
+      IF( nn_ice == 4      )   CALL cice_sbc_init( nsbc )      ! CICE initialisation
+      !
+      IF( nsbc   == jp_cpl )   CALL sbc_cpl_init (nn_ice)      ! OASIS initialisation. must be done before first time step
+
    END SUBROUTINE sbc_init
 
@@ -328,18 +325,18 @@
       SELECT CASE( nsbc )                                ! Compute ocean surface boundary condition
       !                                                  ! (i.e. utau,vtau, qns, qsr, emp, sfx)
-      CASE(  0 )   ;   CALL sbc_gyre    ( kt )                    ! analytical formulation : GYRE configuration
-      CASE(  1 )   ;   CALL sbc_ana     ( kt )                    ! analytical formulation : uniform sbc
-      CASE(  2 )   ;   CALL sbc_flx     ( kt )                    ! flux formulation
-      CASE(  3 )   ;   CALL sbc_blk_clio( kt )                    ! bulk formulation : CLIO for the ocean
-      CASE(  4 )   ;   CALL sbc_blk_core( kt )                    ! bulk formulation : CORE for the ocean
-      CASE(  5 )   ;   CALL sbc_cpl_rcv ( kt, nn_fsbc, nn_ice )   ! coupled formulation
-      CASE(  6 )   ;   CALL sbc_blk_mfs ( kt )                    ! bulk formulation : MFS for the ocean
-      CASE( -1 )                                
-                       CALL sbc_ana     ( kt )                    ! ESOPA, test ALL the formulations
-                       CALL sbc_gyre    ( kt )                    !
-                       CALL sbc_flx     ( kt )                    !
-                       CALL sbc_blk_clio( kt )                    !
-                       CALL sbc_blk_core( kt )                    !
-                       CALL sbc_cpl_rcv ( kt, nn_fsbc, nn_ice )   !
+      CASE( jp_gyre  )   ;   CALL sbc_gyre    ( kt )                    ! analytical formulation : GYRE configuration
+      CASE( jp_ana   )   ;   CALL sbc_ana     ( kt )                    ! analytical formulation : uniform sbc
+      CASE( jp_flx   )   ;   CALL sbc_flx     ( kt )                    ! flux formulation
+      CASE( jp_clio  )   ;   CALL sbc_blk_clio( kt )                    ! bulk formulation : CLIO for the ocean
+      CASE( jp_core  )   ;   CALL sbc_blk_core( kt )                    ! bulk formulation : CORE for the ocean
+      CASE( jp_cpl   )   ;   CALL sbc_cpl_rcv ( kt, nn_fsbc, nn_ice )   ! coupled formulation
+      CASE( jp_mfs   )   ;   CALL sbc_blk_mfs ( kt )                    ! bulk formulation : MFS for the ocean
+      CASE( jp_esopa )                                
+                             CALL sbc_ana     ( kt )                    ! ESOPA, test ALL the formulations
+                             CALL sbc_gyre    ( kt )                    !
+                             CALL sbc_flx     ( kt )                    !
+                             CALL sbc_blk_clio( kt )                    !
+                             CALL sbc_blk_core( kt )                    !
+                             CALL sbc_cpl_rcv ( kt, nn_fsbc, nn_ice )   !
       END SELECT
 
@@ -350,5 +347,4 @@
       CASE(  2 )   ;         CALL sbc_ice_lim_2( kt, nsbc )          ! LIM-2 ice model
       CASE(  3 )   ;         CALL sbc_ice_lim  ( kt, nsbc )          ! LIM-3 ice model
-      !is it useful?
       CASE(  4 )   ;         CALL sbc_ice_cice ( kt, nsbc )          ! CICE ice model
       END SELECT                                              
@@ -424,10 +420,10 @@
          CALL iom_put( "qsr"   ,       qsr  )                   ! solar heat flux
          IF( nn_ice > 0 )   CALL iom_put( "ice_cover", fr_i )   ! ice fraction 
+         CALL iom_put( "taum"  , taum       )                   ! wind stress module 
+         CALL iom_put( "wspd"  , wndm       )                   ! wind speed  module over free ocean or leads in presence of sea-ice
       ENDIF
       !
       CALL iom_put( "utau", utau )   ! i-wind stress   (stress can be updated at 
       CALL iom_put( "vtau", vtau )   ! j-wind stress    each time step in sea-ice)
-      CALL iom_put( "taum", taum )   ! wind stress module 
-      CALL iom_put( "wspd", wndm )   ! wind speed  module 
       !
       IF(ln_ctl) THEN         ! print mean trends (used for debugging)
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90	(revision 4946)
@@ -14,10 +14,11 @@
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
-   USE sbc_oce         ! Surface boundary condition: ocean fields
    USE sbc_oce         ! surface boundary condition: ocean fields
    USE sbcapr          ! surface boundary condition: atmospheric pressure
-   USE prtctl          ! Print control                    (prt_ctl routine)
-   USE iom
+   USE eosbn2          ! equation of state and related derivatives
+   !
    USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
+   USE iom             ! IOM library
 
    IMPLICIT NONE
@@ -54,23 +55,42 @@
       INTEGER, INTENT(in) ::   kt   ! ocean time step
       !
-      INTEGER  ::   ji,jj               ! loop index
+      INTEGER  ::   ji, jj               ! loop index
       REAL(wp) ::   zcoef, zf_sbc       ! local scalar
+      REAL(wp), DIMENSION(jpi,jpj,jpts) :: zts
+      REAL(wp), DIMENSION(jpi,jpj)      :: zub, zvb,zdep
       !!---------------------------------------------------------------------
+      
+      !                                        !* first wet T-, U-, V- ocean level (ISF) variables (T, S, depth, velocity)
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zub(ji,jj)        = ub (ji,jj,miku(ji,jj))
+            zvb(ji,jj)        = vb (ji,jj,mikv(ji,jj))
+            zts(ji,jj,jp_tem) = tsn(ji,jj,mikt(ji,jj),jp_tem)
+            zts(ji,jj,jp_sal) = tsn(ji,jj,mikt(ji,jj),jp_sal)
+         END DO
+      END DO
+      !
+      IF( lk_vvl ) THEN
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zdep(ji,jj) = fse3t_n(ji,jj,mikt(ji,jj))
+            END DO
+         END DO
+      ENDIF
       !                                                   ! ---------------------------------------- !
       IF( nn_fsbc == 1 ) THEN                             !   Instantaneous surface fields        !
          !                                                ! ---------------------------------------- !
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ssu_m(ji,jj) = ub(ji,jj,miku(ji,jj))
-               ssv_m(ji,jj) = vb(ji,jj,mikv(ji,jj))
-               sst_m(ji,jj) = tsn(ji,jj,mikt(ji,jj),jp_tem)
-               sss_m(ji,jj) = tsn(ji,jj,mikt(ji,jj),jp_sal)
-               IF( lk_vvl )   fse3t_m(ji,jj) = fse3t_n(ji,jj,mikt(ji,jj))
-            END DO
-         END DO
+         ssu_m(:,:) = zub(:,:)
+         ssv_m(:,:) = zvb(:,:)
+         IF( ln_useCT )  THEN    ;   sst_m(:,:) = eos_pt_from_ct( zts(:,:,jp_tem), zts(:,:,jp_sal) )
+         ELSE                    ;   sst_m(:,:) = zts(:,:,jp_tem)
+         ENDIF
+         sss_m(:,:) = zts(:,:,jp_sal)
          !                          ! removed inverse barometer ssh when Patm forcing is used (for sea-ice dynamics)
          IF( ln_apr_dyn ) THEN   ;   ssh_m(:,:) = sshn(:,:) - 0.5 * ( ssh_ib(:,:) + ssh_ibb(:,:) )
          ELSE                    ;   ssh_m(:,:) = sshn(:,:)
          ENDIF
+         !
+         IF( lk_vvl )   fse3t_m(:,:) = zdep(:,:)
          !
       ELSE
@@ -81,17 +101,16 @@
             IF(lwp) WRITE(numout,*) '~~~~~~~   mean fields initialised to instantaneous values'
             zcoef = REAL( nn_fsbc - 1, wp )
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ssu_m(ji,jj) = zcoef * ub(ji,jj,miku(ji,jj))
-                  ssv_m(ji,jj) = zcoef * vb(ji,jj,mikv(ji,jj))
-                  sst_m(ji,jj) = zcoef * tsn(ji,jj,mikt(ji,jj),jp_tem)
-                  sss_m(ji,jj) = zcoef * tsn(ji,jj,mikt(ji,jj),jp_sal)
-                  IF( lk_vvl )   fse3t_m(ji,jj) = zcoef * fse3t_n(ji,jj,mikt(ji,jj))
-               END DO
-            END DO
-            !                          ! removed inverse barometer ssh when Patm forcing is used 
+            ssu_m(:,:) = zcoef * zub(:,:)
+            ssv_m(:,:) = zcoef * zvb(:,:)
+            IF( ln_useCT )  THEN    ;   sst_m(:,:) = zcoef * eos_pt_from_ct( zts(:,:,jp_tem), zts(:,:,jp_sal) )
+            ELSE                    ;   sst_m(:,:) = zcoef * zts(:,:,jp_tem)
+            ENDIF
+            sss_m(:,:) = zcoef * zts(:,:,jp_sal)
+            !                          ! removed inverse barometer ssh when Patm forcing is used (for sea-ice dynamics)
             IF( ln_apr_dyn ) THEN   ;   ssh_m(:,:) = zcoef * ( sshn(:,:) - 0.5 * ( ssh_ib(:,:) + ssh_ibb(:,:) ) )
-            ELSE                    ;   ssh_m(:,:) = zcoef *   sshn(:,:)
+            ELSE                    ;   ssh_m(:,:) = zcoef * sshn(:,:)
             ENDIF
+            !
+            IF( lk_vvl )   fse3t_m(:,:) = zcoef * zdep(:,:)
             !                                             ! ---------------------------------------- !
          ELSEIF( MOD( kt - 2 , nn_fsbc ) == 0 ) THEN      !   Initialisation: New mean computation   !
@@ -107,17 +126,16 @@
          !                                                !        Cumulate at each time step        !
          !                                                ! ---------------------------------------- !
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ssu_m(ji,jj) = ssu_m(ji,jj) + ub(ji,jj,miku(ji,jj))
-               ssv_m(ji,jj) = ssv_m(ji,jj) + vb(ji,jj,mikv(ji,jj))
-               sst_m(ji,jj) = sst_m(ji,jj) + tsn(ji,jj,mikt(ji,jj),jp_tem)
-               sss_m(ji,jj) = sss_m(ji,jj) + tsn(ji,jj,mikt(ji,jj),jp_sal)
-               IF( lk_vvl )   fse3t_m(ji,jj) = fse3t_m(ji,jj) + fse3t_n(ji,jj,mikt(ji,jj))
-            END DO
-         END DO
-!                                   ! removed inverse barometer ssh when Patm forcing is used (for sea-ice dynamics)
-         IF( ln_apr_dyn ) THEN   ;   ssh_m(:,:) = ssh_m(:,:) + sshn(:,:) - 0.5 *  ( ssh_ib(:,:) + ssh_ibb(:,:) )
+         ssu_m(:,:) = ssu_m(:,:) + zub(:,:)
+         ssv_m(:,:) = ssv_m(:,:) + zvb(:,:)
+         IF( ln_useCT )  THEN    ;   sst_m(:,:) = sst_m(:,:) + eos_pt_from_ct( zts(:,:,jp_tem), zts(:,:,jp_sal) )
+         ELSE                    ;   sst_m(:,:) = sst_m(:,:) + zts(:,:,jp_tem)
+         ENDIF
+         sss_m(:,:) = sss_m(:,:) + zts(:,:,jp_sal)
+         !                          ! removed inverse barometer ssh when Patm forcing is used (for sea-ice dynamics)
+         IF( ln_apr_dyn ) THEN   ;   ssh_m(:,:) = ssh_m(:,:) + sshn(:,:) - 0.5 * ( ssh_ib(:,:) + ssh_ibb(:,:) )
          ELSE                    ;   ssh_m(:,:) = ssh_m(:,:) + sshn(:,:)
          ENDIF
+         !
+         IF( lk_vvl )   fse3t_m(:,:) = fse3t_m(:,:) + zdep(:,:)
 
          !                                                ! ---------------------------------------- !
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssr.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssr.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssr.F90	(revision 4946)
@@ -10,4 +10,5 @@
    !!----------------------------------------------------------------------
    !!   sbc_ssr       : add to sbc a restoring term toward SST/SSS climatology
+   !!   sbc_ssr_init  : initialisation of surface restoring
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and tracers
@@ -16,4 +17,5 @@
    USE phycst         ! physical constants
    USE sbcrnf         ! surface boundary condition : runoffs
+   !
    USE fldread        ! read input fields
    USE iom            ! I/O manager
@@ -93,5 +95,4 @@
             !
             IF( nn_sstr == 1 ) THEN                                   !* Temperature restoring term
-!CDIR COLLAPSE
                DO jj = 1, jpj
                   DO ji = 1, jpi
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/eosbn2.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/eosbn2.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/eosbn2.F90	(revision 4946)
@@ -15,7 +15,11 @@
    !!             -   ! 2002-11  (G. Madec, A. Bozec)  partial step, eos_insitu_2d
    !!             -   ! 2003-08  (G. Madec)  F90, free form
-   !!            3.0  ! 2006-08  (G. Madec)  add tfreez function
+   !!            3.0  ! 2006-08  (G. Madec)  add tfreez function (now eos_fzp function)
    !!            3.3  ! 2010-05  (C. Ethe, G. Madec)  merge TRC-TRA
-   !!             -   ! 2010-10  (G. Nurser, G. Madec)  add eos_alpbet used in ldfslp
+   !!             -   ! 2010-10  (G. Nurser, G. Madec)  add alpha/beta used in ldfslp
+   !!            3.7  ! 2012-03  (F. Roquet, G. Madec)  add primitive of alpha and beta used in PE computation
+   !!             -   ! 2012-05  (F. Roquet)  add Vallis and original JM95 equation of state
+   !!             -   ! 2013-04  (F. Roquet, G. Madec)  add eos_rab, change bn2 computation and reorganize the module
+   !!             -   ! 2014-09  (F. Roquet)  add TEOS-10, S-EOS, and modify EOS-80
    !!----------------------------------------------------------------------
 
@@ -23,19 +27,23 @@
    !!   eos            : generic interface of the equation of state
    !!   eos_insitu     : Compute the in situ density
-   !!   eos_insitu_pot : Compute the insitu and surface referenced potential
-   !!                    volumic mass
+   !!   eos_insitu_pot : Compute the insitu and surface referenced potential volumic mass
    !!   eos_insitu_2d  : Compute the in situ density for 2d fields
-   !!   eos_bn2        : Compute the Brunt-Vaisala frequency
-   !!   eos_alpbet     : calculates the in situ thermal/haline expansion ratio
-   !!   tfreez         : Compute the surface freezing temperature
+   !!   bn2            : Compute the Brunt-Vaisala frequency
+   !!   eos_rab        : generic interface of in situ thermal/haline expansion ratio 
+   !!   eos_rab_3d     : compute in situ thermal/haline expansion ratio
+   !!   eos_rab_2d     : compute in situ thermal/haline expansion ratio for 2d fields
+   !!   eos_fzp_2d     : freezing temperature for 2d fields
+   !!   eos_fzp_0d     : freezing temperature for scalar
    !!   eos_init       : set eos parameters (namelist)
    !!----------------------------------------------------------------------
    USE dom_oce         ! ocean space and time domain
    USE phycst          ! physical constants
-   USE zdfddm          ! vertical physics: double diffusion
+   !
    USE in_out_manager  ! I/O manager
    USE lib_mpp         ! MPP library
+   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
    USE prtctl          ! Print control
    USE wrk_nemo        ! Memory Allocation
+   USE lbclnk         ! ocean lateral boundary conditions
    USE timing          ! Timing
 
@@ -47,21 +55,116 @@
       MODULE PROCEDURE eos_insitu, eos_insitu_pot, eos_insitu_2d
    END INTERFACE
-   INTERFACE bn2
-      MODULE PROCEDURE eos_bn2
+   !
+   INTERFACE eos_rab
+      MODULE PROCEDURE rab_3d, rab_2d, rab_0d
    END INTERFACE
-
-   PUBLIC   eos        ! called by step, istate, tranpc and zpsgrd modules
-   PUBLIC   eos_init   ! called by istate module
-   PUBLIC   bn2        ! called by step module
-   PUBLIC   eos_alpbet ! called by ldfslp module
-   PUBLIC   tfreez     ! called by sbcice_... modules and sbcisf module
-   PUBLIC   tfreez1D   ! called by trasbc modules
-
-   !                                  !!* Namelist (nameos) *
-   INTEGER , PUBLIC ::   nn_eos       !: = 0/1/2 type of eq. of state and Brunt-Vaisala frequ.
-   REAL(wp), PUBLIC ::   rn_alpha     !: thermal expension coeff. (linear equation of state)
-   REAL(wp), PUBLIC ::   rn_beta      !: saline  expension coeff. (linear equation of state)
-
-   REAL(wp), PUBLIC ::   ralpbet              !: alpha / beta ratio
+   !
+   INTERFACE eos_fzp 
+      MODULE PROCEDURE eos_fzp_2d, eos_fzp_0d
+   END INTERFACE
+   !
+   PUBLIC   eos            ! called by step, istate, tranpc and zpsgrd modules
+   PUBLIC   bn2            ! called by step module
+   PUBLIC   eos_rab        ! called by ldfslp, zdfddm, trabbl
+   PUBLIC   eos_pt_from_ct ! called by sbcssm
+   PUBLIC   eos_fzp        ! called by traadv_cen2 and sbcice_... modules
+   PUBLIC   eos_pen        ! used for pe diagnostics in trdpen module
+   PUBLIC   eos_init       ! called by istate module
+
+   !                                          !!* Namelist (nameos) *
+   INTEGER , PUBLIC ::   nn_eos   = 0         !: = 0/1/2 type of eq. of state and Brunt-Vaisala frequ.
+   LOGICAL , PUBLIC ::   ln_useCT  = .FALSE.  ! determine if eos_pt_from_ct is used to compute sst_m
+
+   !                                   !!!  simplified eos coefficients
+   ! default value: Vallis 2006
+   REAL(wp) ::   rn_a0      = 1.6550e-1_wp     ! thermal expansion coeff. 
+   REAL(wp) ::   rn_b0      = 7.6554e-1_wp     ! saline  expansion coeff. 
+   REAL(wp) ::   rn_lambda1 = 5.9520e-2_wp     ! cabbeling coeff. in T^2        
+   REAL(wp) ::   rn_lambda2 = 5.4914e-4_wp     ! cabbeling coeff. in S^2        
+   REAL(wp) ::   rn_mu1     = 1.4970e-4_wp     ! thermobaric coeff. in T  
+   REAL(wp) ::   rn_mu2     = 1.1090e-5_wp     ! thermobaric coeff. in S  
+   REAL(wp) ::   rn_nu      = 2.4341e-3_wp     ! cabbeling coeff. in theta*salt  
+   
+   ! TEOS10/EOS80 parameters
+   REAL(wp) ::   r1_S0, r1_T0, r1_Z0, rdeltaS
+   
+   ! EOS parameters
+   REAL(wp) ::   EOS000 , EOS100 , EOS200 , EOS300 , EOS400 , EOS500 , EOS600
+   REAL(wp) ::   EOS010 , EOS110 , EOS210 , EOS310 , EOS410 , EOS510
+   REAL(wp) ::   EOS020 , EOS120 , EOS220 , EOS320 , EOS420
+   REAL(wp) ::   EOS030 , EOS130 , EOS230 , EOS330
+   REAL(wp) ::   EOS040 , EOS140 , EOS240
+   REAL(wp) ::   EOS050 , EOS150
+   REAL(wp) ::   EOS060
+   REAL(wp) ::   EOS001 , EOS101 , EOS201 , EOS301 , EOS401
+   REAL(wp) ::   EOS011 , EOS111 , EOS211 , EOS311
+   REAL(wp) ::   EOS021 , EOS121 , EOS221
+   REAL(wp) ::   EOS031 , EOS131
+   REAL(wp) ::   EOS041
+   REAL(wp) ::   EOS002 , EOS102 , EOS202
+   REAL(wp) ::   EOS012 , EOS112
+   REAL(wp) ::   EOS022
+   REAL(wp) ::   EOS003 , EOS103
+   REAL(wp) ::   EOS013 
+   
+   ! ALPHA parameters
+   REAL(wp) ::   ALP000 , ALP100 , ALP200 , ALP300 , ALP400 , ALP500
+   REAL(wp) ::   ALP010 , ALP110 , ALP210 , ALP310 , ALP410
+   REAL(wp) ::   ALP020 , ALP120 , ALP220 , ALP320
+   REAL(wp) ::   ALP030 , ALP130 , ALP230
+   REAL(wp) ::   ALP040 , ALP140
+   REAL(wp) ::   ALP050
+   REAL(wp) ::   ALP001 , ALP101 , ALP201 , ALP301
+   REAL(wp) ::   ALP011 , ALP111 , ALP211
+   REAL(wp) ::   ALP021 , ALP121
+   REAL(wp) ::   ALP031
+   REAL(wp) ::   ALP002 , ALP102
+   REAL(wp) ::   ALP012
+   REAL(wp) ::   ALP003
+   
+   ! BETA parameters
+   REAL(wp) ::   BET000 , BET100 , BET200 , BET300 , BET400 , BET500
+   REAL(wp) ::   BET010 , BET110 , BET210 , BET310 , BET410
+   REAL(wp) ::   BET020 , BET120 , BET220 , BET320
+   REAL(wp) ::   BET030 , BET130 , BET230
+   REAL(wp) ::   BET040 , BET140
+   REAL(wp) ::   BET050
+   REAL(wp) ::   BET001 , BET101 , BET201 , BET301
+   REAL(wp) ::   BET011 , BET111 , BET211
+   REAL(wp) ::   BET021 , BET121
+   REAL(wp) ::   BET031
+   REAL(wp) ::   BET002 , BET102
+   REAL(wp) ::   BET012
+   REAL(wp) ::   BET003
+
+   ! PEN parameters
+   REAL(wp) ::   PEN000 , PEN100 , PEN200 , PEN300 , PEN400
+   REAL(wp) ::   PEN010 , PEN110 , PEN210 , PEN310
+   REAL(wp) ::   PEN020 , PEN120 , PEN220
+   REAL(wp) ::   PEN030 , PEN130
+   REAL(wp) ::   PEN040
+   REAL(wp) ::   PEN001 , PEN101 , PEN201
+   REAL(wp) ::   PEN011 , PEN111
+   REAL(wp) ::   PEN021
+   REAL(wp) ::   PEN002 , PEN102
+   REAL(wp) ::   PEN012
+   
+   ! ALPHA_PEN parameters
+   REAL(wp) ::   APE000 , APE100 , APE200 , APE300
+   REAL(wp) ::   APE010 , APE110 , APE210
+   REAL(wp) ::   APE020 , APE120
+   REAL(wp) ::   APE030
+   REAL(wp) ::   APE001 , APE101
+   REAL(wp) ::   APE011
+   REAL(wp) ::   APE002
+
+   ! BETA_PEN parameters
+   REAL(wp) ::   BPE000 , BPE100 , BPE200 , BPE300
+   REAL(wp) ::   BPE010 , BPE110 , BPE210
+   REAL(wp) ::   BPE020 , BPE120
+   REAL(wp) ::   BPE030
+   REAL(wp) ::   BPE001 , BPE101
+   REAL(wp) ::   BPE011
+   REAL(wp) ::   BPE002
 
    !! * Substitutions
@@ -69,5 +172,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -83,117 +186,108 @@
       !!       defined through the namelist parameter nn_eos.
       !!
-      !! ** Method  :   3 cases:
-      !!      nn_eos = 0 : Jackett and McDougall (1994) equation of state.
-      !!         the in situ density is computed directly as a function of
-      !!         potential temperature relative to the surface (the opa t
-      !!         variable), salt and pressure (assuming no pressure variation
-      !!         along geopotential surfaces, i.e. the pressure p in decibars
-      !!         is approximated by the depth in meters.
-      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
-      !!         with pressure                      p        decibars
-      !!              potential temperature         t        deg celsius
-      !!              salinity                      s        psu
-      !!              reference volumic mass        rau0     kg/m**3
-      !!              in situ volumic mass          rho      kg/m**3
-      !!              in situ density anomalie      prd      no units
-      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
-      !!          t = 40 deg celcius, s=40 psu
-      !!      nn_eos = 1 : linear equation of state function of temperature only
-      !!              prd(t) = 0.0285 - rn_alpha * t
-      !!      nn_eos = 2 : linear equation of state function of temperature and
-      !!               salinity
-      !!              prd(t,s) = rn_beta * s - rn_alpha * tn - 1.
-      !!      Note that no boundary condition problem occurs in this routine
-      !!      as pts are defined over the whole domain.
+      !! ** Method  :   prd(t,s,z) = ( rho(t,s,z) - rau0 ) / rau0
+      !!         with   prd    in situ density anomaly      no units
+      !!                t      TEOS10: CT or EOS80: PT      Celsius
+      !!                s      TEOS10: SA or EOS80: SP      TEOS10: g/kg or EOS80: psu
+      !!                z      depth                        meters
+      !!                rho    in situ density              kg/m^3
+      !!                rau0   reference density            kg/m^3
+      !!
+      !!     nn_eos = -1 : polynomial TEOS-10 equation of state is used for rho(t,s,z).
+      !!         Check value: rho = 1028.21993233072 kg/m^3 for z=3000 dbar, ct=3 Celcius, sa=35.5 g/kg
+      !!
+      !!     nn_eos =  0 : polynomial EOS-80 equation of state is used for rho(t,s,z).
+      !!         Check value: rho = 1028.35011066567 kg/m^3 for z=3000 dbar, pt=3 Celcius, sp=35.5 psu
+      !!
+      !!     nn_eos =  1 : simplified equation of state
+      !!              prd(t,s,z) = ( -a0*(1+lambda/2*(T-T0)+mu*z+nu*(S-S0))*(T-T0) + b0*(S-S0) ) / rau0
+      !!              linear case function of T only: rn_alpha<>0, other coefficients = 0
+      !!              linear eos function of T and S: rn_alpha and rn_beta<>0, other coefficients=0
+      !!              Vallis like equation: use default values of coefficients
       !!
       !! ** Action  :   compute prd , the in situ density (no units)
       !!
-      !! References :   Jackett and McDougall, J. Atmos. Ocean. Tech., 1994
-      !!----------------------------------------------------------------------
-      !!
-      REAL(wp), DIMENSION(:,:,:,:), INTENT(in   ) ::   pts   ! 1 : potential temperature  [Celcius]
-      !                                                      ! 2 : salinity               [psu]
-      REAL(wp), DIMENSION(:,:,:)  , INTENT(  out) ::   prd   ! in situ density            [-]
-      REAL(wp), DIMENSION(:,:,:)  , INTENT(in   ) ::   pdep  ! depth                      [m]
-      !!
-      INTEGER  ::   ji, jj, jk           ! dummy loop indices
-      REAL(wp) ::   zt , zs , zh , zsr   ! local scalars
-      REAL(wp) ::   zr1, zr2, zr3, zr4   !   -      -
-      REAL(wp) ::   zrhop, ze, zbw, zb   !   -      -
-      REAL(wp) ::   zd , zc , zaw, za    !   -      -
-      REAL(wp) ::   zb1, za1, zkw, zk0   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zws
-      !!----------------------------------------------------------------------
-
-      !
-      IF( nn_timing == 1 ) CALL timing_start('eos')
-      !
-      CALL wrk_alloc( jpi, jpj, jpk, zws )
+      !! References :   Roquet et al, Ocean Modelling, in preparation (2014)
+      !!                Vallis, Atmospheric and Oceanic Fluid Dynamics, 2006
+      !!                TEOS-10 Manual, 2010
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts), INTENT(in   ) ::   pts   ! 1 : potential temperature  [Celcius]
+      !                                                               ! 2 : salinity               [psu]
+      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(  out) ::   prd   ! in situ density            [-]
+      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pdep  ! depth                      [m]
+      !
+      INTEGER  ::   ji, jj, jk                ! dummy loop indices
+      REAL(wp) ::   zt , zh , zs , ztm        ! local scalars
+      REAL(wp) ::   zn , zn0, zn1, zn2, zn3   !   -      -
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('eos-insitu')
       !
       SELECT CASE( nn_eos )
       !
-      CASE( 0 )                !==  Jackett and McDougall (1994) formulation  ==!
-!CDIR NOVERRCHK
-         zws(:,:,:) = SQRT( ABS( pts(:,:,:,jp_sal) ) )
+      CASE( -1, 0 )                !==  polynomial TEOS-10 / EOS-80 ==!
          !
          DO jk = 1, jpkm1
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  zt = pts   (ji,jj,jk,jp_tem)
-                  zs = pts   (ji,jj,jk,jp_sal)
-                  zh = pdep(ji,jj,jk)        ! depth
-                  zsr= zws   (ji,jj,jk)        ! square root salinity
-                  !
-                  ! compute volumic mass pure water at atm pressure
-                  zr1= ( ( ( ( 6.536332e-9_wp  *zt - 1.120083e-6_wp )*zt + 1.001685e-4_wp )*zt   &
-                     &        -9.095290e-3_wp )*zt + 6.793952e-2_wp )*zt +  999.842594_wp
-                  ! seawater volumic mass atm pressure
-                  zr2= ( ( ( 5.3875e-9_wp*zt-8.2467e-7_wp ) *zt+7.6438e-5_wp ) *zt        &
-                     &                      -4.0899e-3_wp ) *zt+0.824493_wp
-                  zr3= ( -1.6546e-6_wp*zt+1.0227e-4_wp )    *zt-5.72466e-3_wp
-                  zr4= 4.8314e-4_wp
-                  !
-                  ! potential volumic mass (reference to the surface)
-                  zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1
-                  !
-                  ! add the compression terms
-                  ze = ( -3.508914e-8_wp*zt-1.248266e-8_wp ) *zt-2.595994e-6_wp
-                  zbw= (  1.296821e-6_wp*zt-5.782165e-9_wp ) *zt+1.045941e-4_wp
-                  zb = zbw + ze * zs
-                  !
-                  zd = -2.042967e-2_wp
-                  zc =   (-7.267926e-5_wp*zt+2.598241e-3_wp ) *zt+0.1571896_wp
-                  zaw= ( ( 5.939910e-6_wp*zt+2.512549e-3_wp ) *zt-0.1028859_wp ) *zt - 4.721788_wp
-                  za = ( zd*zsr + zc ) *zs + zaw
-                  !
-                  zb1=   (-0.1909078_wp*zt+7.390729_wp )        *zt-55.87545_wp
-                  za1= ( ( 2.326469e-3_wp*zt+1.553190_wp)       *zt-65.00517_wp ) *zt+1044.077_wp
-                  zkw= ( ( (-1.361629e-4_wp*zt-1.852732e-2_wp ) *zt-30.41638_wp ) *zt + 2098.925_wp ) *zt+190925.6_wp
-                  zk0= ( zb1*zsr + za1 )*zs + zkw
-                  !
-                  ! masked in situ density anomaly
-                  prd(ji,jj,jk) = (  zrhop / (  1.0_wp - zh / ( zk0 - zh * ( za - zh * zb ) )  )    &
-                     &             - rau0  ) * r1_rau0 * tmask(ji,jj,jk)
+                  !
+                  zh  = pdep(ji,jj,jk) * r1_Z0                                  ! depth
+                  zt  = pts (ji,jj,jk,jp_tem) * r1_T0                           ! temperature
+                  zs  = SQRT( ABS( pts(ji,jj,jk,jp_sal) + rdeltaS ) * r1_S0 )   ! square root salinity
+                  ztm = tmask(ji,jj,jk)                                         ! tmask
+                  !
+                  zn3 = EOS013*zt   &
+                     &   + EOS103*zs+EOS003
+                     !
+                  zn2 = (EOS022*zt   &
+                     &   + EOS112*zs+EOS012)*zt   &
+                     &   + (EOS202*zs+EOS102)*zs+EOS002
+                     !
+                  zn1 = (((EOS041*zt   &
+                     &   + EOS131*zs+EOS031)*zt   &
+                     &   + (EOS221*zs+EOS121)*zs+EOS021)*zt   &
+                     &   + ((EOS311*zs+EOS211)*zs+EOS111)*zs+EOS011)*zt   &
+                     &   + (((EOS401*zs+EOS301)*zs+EOS201)*zs+EOS101)*zs+EOS001
+                     !
+                  zn0 = (((((EOS060*zt   &
+                     &   + EOS150*zs+EOS050)*zt   &
+                     &   + (EOS240*zs+EOS140)*zs+EOS040)*zt   &
+                     &   + ((EOS330*zs+EOS230)*zs+EOS130)*zs+EOS030)*zt   &
+                     &   + (((EOS420*zs+EOS320)*zs+EOS220)*zs+EOS120)*zs+EOS020)*zt   &
+                     &   + ((((EOS510*zs+EOS410)*zs+EOS310)*zs+EOS210)*zs+EOS110)*zs+EOS010)*zt   &
+                     &   + (((((EOS600*zs+EOS500)*zs+EOS400)*zs+EOS300)*zs+EOS200)*zs+EOS100)*zs+EOS000
+                     !
+                  zn  = ( ( zn3 * zh + zn2 ) * zh + zn1 ) * zh + zn0
+                  !
+                  prd(ji,jj,jk) = (  zn * r1_rau0 - 1._wp  ) * ztm  ! density anomaly (masked)
+                  !
                END DO
             END DO
          END DO
          !
-      CASE( 1 )                !==  Linear formulation function of temperature only  ==!
+      CASE( 1 )                !==  simplified EOS  ==!
+         !
          DO jk = 1, jpkm1
-            prd(:,:,jk) = ( 0.0285_wp - rn_alpha * pts(:,:,jk,jp_tem) ) * tmask(:,:,jk)
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt  = pts  (ji,jj,jk,jp_tem) - 10._wp
+                  zs  = pts  (ji,jj,jk,jp_sal) - 35._wp
+                  zh  = pdep (ji,jj,jk)
+                  ztm = tmask(ji,jj,jk)
+                  !
+                  zn =  - rn_a0 * ( 1._wp + 0.5_wp*rn_lambda1*zt + rn_mu1*zh ) * zt   &
+                     &  + rn_b0 * ( 1._wp - 0.5_wp*rn_lambda2*zs - rn_mu2*zh ) * zs   &
+                     &  - rn_nu * zt * zs
+                     !                                 
+                  prd(ji,jj,jk) = zn * r1_rau0 * ztm                ! density anomaly (masked)
+               END DO
+            END DO
          END DO
          !
-      CASE( 2 )                !==  Linear formulation function of temperature and salinity  ==!
-         DO jk = 1, jpkm1
-            prd(:,:,jk) = ( rn_beta  * pts(:,:,jk,jp_sal) - rn_alpha * pts(:,:,jk,jp_tem) ) * tmask(:,:,jk)
-         END DO
-         !
       END SELECT
       !
-      IF(ln_ctl)   CALL prt_ctl( tab3d_1=prd, clinfo1=' eos  : ', ovlap=1, kdim=jpk )
-      !
-      CALL wrk_dealloc( jpi, jpj, jpk, zws )
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('eos')
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=prd, clinfo1=' eos-insitu  : ', ovlap=1, kdim=jpk )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('eos-insitu')
       !
    END SUBROUTINE eos_insitu
@@ -209,42 +303,8 @@
       !!     namelist parameter nn_eos.
       !!
-      !! ** Method  :
-      !!      nn_eos = 0 : Jackett and McDougall (1994) equation of state.
-      !!         the in situ density is computed directly as a function of
-      !!         potential temperature relative to the surface (the opa t
-      !!         variable), salt and pressure (assuming no pressure variation
-      !!         along geopotential surfaces, i.e. the pressure p in decibars
-      !!         is approximated by the depth in meters.
-      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
-      !!              rhop(t,s)  = rho(t,s,0)
-      !!         with pressure                      p        decibars
-      !!              potential temperature         t        deg celsius
-      !!              salinity                      s        psu
-      !!              reference volumic mass        rau0     kg/m**3
-      !!              in situ volumic mass          rho      kg/m**3
-      !!              in situ density anomalie      prd      no units
-      !!
-      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
-      !!          t = 40 deg celcius, s=40 psu
-      !!
-      !!      nn_eos = 1 : linear equation of state function of temperature only
-      !!              prd(t) = ( rho(t) - rau0 ) / rau0 = 0.028 - rn_alpha * t
-      !!              rhop(t,s)  = rho(t,s)
-      !!
-      !!      nn_eos = 2 : linear equation of state function of temperature and
-      !!               salinity
-      !!              prd(t,s) = ( rho(t,s) - rau0 ) / rau0
-      !!                       = rn_beta * s - rn_alpha * tn - 1.
-      !!              rhop(t,s)  = rho(t,s)
-      !!      Note that no boundary condition problem occurs in this routine
-      !!      as (tn,sn) or (ta,sa) are defined over the whole domain.
-      !!
       !! ** Action  : - prd  , the in situ density (no units)
       !!              - prhop, the potential volumic mass (Kg/m3)
       !!
-      !! References :   Jackett and McDougall, J. Atmos. Ocean. Tech., 1994
-      !!                Brown and Campana, Mon. Weather Rev., 1978
-      !!----------------------------------------------------------------------
-      !!
+      !!----------------------------------------------------------------------
       REAL(wp), DIMENSION(jpi,jpj,jpk,jpts), INTENT(in   ) ::   pts    ! 1 : potential temperature  [Celcius]
       !                                                                ! 2 : salinity               [psu]
@@ -253,84 +313,81 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pdep   ! depth                      [m]
       !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zt, zs, zh, zsr, zr1, zr2, zr3, zr4, zrhop, ze, zbw   ! local scalars
-      REAL(wp) ::   zb, zd, zc, zaw, za, zb1, za1, zkw, zk0               !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zws
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 ) CALL timing_start('eos-p')
-      !
-      CALL wrk_alloc( jpi, jpj, jpk, zws )
+      INTEGER  ::   ji, jj, jk                ! dummy loop indices
+      REAL(wp) ::   zt , zh , zs , ztm        ! local scalars
+      REAL(wp) ::   zn , zn0, zn1, zn2, zn3   !   -      -
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('eos-pot')
       !
       SELECT CASE ( nn_eos )
       !
-      CASE( 0 )                !==  Jackett and McDougall (1994) formulation  ==!
-!CDIR NOVERRCHK
-         zws(:,:,:) = SQRT( ABS( pts(:,:,:,jp_sal) ) )
+      CASE( -1, 0 )                !==  polynomial TEOS-10 / EOS-80 ==!
          !
          DO jk = 1, jpkm1
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  zt = pts   (ji,jj,jk,jp_tem)
-                  zs = pts   (ji,jj,jk,jp_sal)
-                  zh = pdep(ji,jj,jk)        ! depth
-                  zsr= zws   (ji,jj,jk)        ! square root salinity
-                  !
-                  ! compute volumic mass pure water at atm pressure
-                  zr1= ( ( ( ( 6.536332e-9_wp*zt-1.120083e-6_wp )*zt+1.001685e-4_wp )*zt   &
-                     &                          -9.095290e-3_wp )*zt+6.793952e-2_wp )*zt+999.842594_wp
-                  ! seawater volumic mass atm pressure
-                  zr2= ( ( ( 5.3875e-9_wp*zt-8.2467e-7_wp ) *zt+7.6438e-5_wp ) *zt   &
-                     &                                         -4.0899e-3_wp ) *zt+0.824493_wp
-                  zr3= ( -1.6546e-6_wp*zt+1.0227e-4_wp )    *zt-5.72466e-3_wp
-                  zr4= 4.8314e-4_wp
-                  !
-                  ! potential volumic mass (reference to the surface)
-                  zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1
-                  !
-                  ! save potential volumic mass
-                  prhop(ji,jj,jk) = zrhop * tmask(ji,jj,jk)
-                  !
-                  ! add the compression terms
-                  ze = ( -3.508914e-8_wp*zt-1.248266e-8_wp ) *zt-2.595994e-6_wp
-                  zbw= (  1.296821e-6_wp*zt-5.782165e-9_wp ) *zt+1.045941e-4_wp
-                  zb = zbw + ze * zs
-                  !
-                  zd = -2.042967e-2_wp
-                  zc =   (-7.267926e-5_wp*zt+2.598241e-3_wp ) *zt+0.1571896_wp
-                  zaw= ( ( 5.939910e-6_wp*zt+2.512549e-3_wp ) *zt-0.1028859_wp ) *zt - 4.721788_wp
-                  za = ( zd*zsr + zc ) *zs + zaw
-                  !
-                  zb1=   (  -0.1909078_wp  *zt+7.390729_wp    ) *zt-55.87545_wp
-                  za1= ( (   2.326469e-3_wp*zt+1.553190_wp    ) *zt-65.00517_wp ) *zt + 1044.077_wp
-                  zkw= ( ( (-1.361629e-4_wp*zt-1.852732e-2_wp ) *zt-30.41638_wp ) *zt + 2098.925_wp ) *zt+190925.6_wp
-                  zk0= ( zb1*zsr + za1 )*zs + zkw
-                  !
-                  ! masked in situ density anomaly
-                  prd(ji,jj,jk) = (  zrhop / (  1.0_wp - zh / ( zk0 - zh * ( za - zh * zb ) )  )    &
-                     &             - rau0  ) * r1_rau0 * tmask(ji,jj,jk)
+                  !
+                  zh  = pdep(ji,jj,jk) * r1_Z0                                  ! depth
+                  zt  = pts (ji,jj,jk,jp_tem) * r1_T0                           ! temperature
+                  zs  = SQRT( ABS( pts(ji,jj,jk,jp_sal) + rdeltaS ) * r1_S0 )   ! square root salinity
+                  ztm = tmask(ji,jj,jk)                                         ! tmask
+                  !
+                  zn3 = EOS013*zt   &
+                     &   + EOS103*zs+EOS003
+                     !
+                  zn2 = (EOS022*zt   &
+                     &   + EOS112*zs+EOS012)*zt   &
+                     &   + (EOS202*zs+EOS102)*zs+EOS002
+                     !
+                  zn1 = (((EOS041*zt   &
+                     &   + EOS131*zs+EOS031)*zt   &
+                     &   + (EOS221*zs+EOS121)*zs+EOS021)*zt   &
+                     &   + ((EOS311*zs+EOS211)*zs+EOS111)*zs+EOS011)*zt   &
+                     &   + (((EOS401*zs+EOS301)*zs+EOS201)*zs+EOS101)*zs+EOS001
+                     !
+                  zn0 = (((((EOS060*zt   &
+                     &   + EOS150*zs+EOS050)*zt   &
+                     &   + (EOS240*zs+EOS140)*zs+EOS040)*zt   &
+                     &   + ((EOS330*zs+EOS230)*zs+EOS130)*zs+EOS030)*zt   &
+                     &   + (((EOS420*zs+EOS320)*zs+EOS220)*zs+EOS120)*zs+EOS020)*zt   &
+                     &   + ((((EOS510*zs+EOS410)*zs+EOS310)*zs+EOS210)*zs+EOS110)*zs+EOS010)*zt   &
+                     &   + (((((EOS600*zs+EOS500)*zs+EOS400)*zs+EOS300)*zs+EOS200)*zs+EOS100)*zs+EOS000
+                     !
+                  zn  = ( ( zn3 * zh + zn2 ) * zh + zn1 ) * zh + zn0
+                  !
+                  prhop(ji,jj,jk) = zn0 * ztm                           ! potential density referenced at the surface
+                  !
+                  prd(ji,jj,jk) = (  zn * r1_rau0 - 1._wp  ) * ztm      ! density anomaly (masked)
                END DO
             END DO
          END DO
          !
-      CASE( 1 )                !==  Linear formulation = F( temperature )  ==!
+      CASE( 1 )                !==  simplified EOS  ==!
+         !
          DO jk = 1, jpkm1
-            prd  (:,:,jk) = ( 0.0285_wp - rn_alpha * pts(:,:,jk,jp_tem) )        * tmask(:,:,jk)
-            prhop(:,:,jk) = ( 1.e0_wp   +            prd (:,:,jk)       ) * rau0 * tmask(:,:,jk)
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt  = pts  (ji,jj,jk,jp_tem) - 10._wp
+                  zs  = pts  (ji,jj,jk,jp_sal) - 35._wp
+                  zh  = pdep (ji,jj,jk)
+                  ztm = tmask(ji,jj,jk)
+                  !                                                     ! potential density referenced at the surface
+                  zn =  - rn_a0 * ( 1._wp + 0.5_wp*rn_lambda1*zt ) * zt   &
+                     &  + rn_b0 * ( 1._wp - 0.5_wp*rn_lambda2*zs ) * zs   &
+                     &  - rn_nu * zt * zs
+                  prhop(ji,jj,jk) = ( rau0 + zn ) * ztm
+                  !                                                     ! density anomaly (masked)
+                  zn = zn - ( rn_a0 * rn_mu1 * zt + rn_b0 * rn_mu2 * zs ) * zh
+                  prd(ji,jj,jk) = zn * r1_rau0 * ztm
+                  !
+               END DO
+            END DO
          END DO
          !
-      CASE( 2 )                !==  Linear formulation = F( temperature , salinity )  ==!
-         DO jk = 1, jpkm1
-            prd  (:,:,jk) = ( rn_beta  * pts(:,:,jk,jp_sal) - rn_alpha * pts(:,:,jk,jp_tem) )        * tmask(:,:,jk)
-            prhop(:,:,jk) = ( 1.e0_wp  + prd (:,:,jk) )                                       * rau0 * tmask(:,:,jk)
-         END DO
-         !
       END SELECT
       !
-      IF(ln_ctl)   CALL prt_ctl( tab3d_1=prd, clinfo1=' eos-p: ', tab3d_2=prhop, clinfo2=' pot : ', ovlap=1, kdim=jpk )
-      !
-      CALL wrk_dealloc( jpi, jpj, jpk, zws )
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('eos-p')
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=prd, clinfo1=' eos-pot: ', tab3d_2=prhop, clinfo2=' pot : ', ovlap=1, kdim=jpk )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('eos-pot')
       !
    END SUBROUTINE eos_insitu_pot
@@ -345,325 +402,189 @@
       !!      defined through the namelist parameter nn_eos. * 2D field case
       !!
-      !! ** Method :
-      !!      nn_eos = 0 : Jackett and McDougall (1994) equation of state.
-      !!         the in situ density is computed directly as a function of
-      !!         potential temperature relative to the surface (the opa t
-      !!         variable), salt and pressure (assuming no pressure variation
-      !!         along geopotential surfaces, i.e. the pressure p in decibars
-      !!         is approximated by the depth in meters.
-      !!              prd(t,s,p) = ( rho(t,s,p) - rau0 ) / rau0
-      !!         with pressure                      p        decibars
-      !!              potential temperature         t        deg celsius
-      !!              salinity                      s        psu
-      !!              reference volumic mass        rau0     kg/m**3
-      !!              in situ volumic mass          rho      kg/m**3
-      !!              in situ density anomalie      prd      no units
-      !!         Check value: rho = 1060.93298 kg/m**3 for p=10000 dbar,
-      !!          t = 40 deg celcius, s=40 psu
-      !!      nn_eos = 1 : linear equation of state function of temperature only
-      !!              prd(t) = 0.0285 - rn_alpha * t
-      !!      nn_eos = 2 : linear equation of state function of temperature and
-      !!               salinity
-      !!              prd(t,s) = rn_beta * s - rn_alpha * tn - 1.
-      !!      Note that no boundary condition problem occurs in this routine
-      !!      as pts are defined over the whole domain.
-      !!
-      !! ** Action  : - prd , the in situ density (no units)
-      !!
-      !! References :   Jackett and McDougall, J. Atmos. Ocean. Tech., 1994
-      !!----------------------------------------------------------------------
-      !!
+      !! ** Action  : - prd , the in situ density (no units) (unmasked)
+      !!
+      !!----------------------------------------------------------------------
       REAL(wp), DIMENSION(jpi,jpj,jpts), INTENT(in   ) ::   pts   ! 1 : potential temperature  [Celcius]
       !                                                           ! 2 : salinity               [psu]
-      REAL(wp), DIMENSION(jpi,jpj)     , INTENT(in   ) ::   pdep  ! depth                  [m]
+      REAL(wp), DIMENSION(jpi,jpj)     , INTENT(in   ) ::   pdep  ! depth                      [m]
       REAL(wp), DIMENSION(jpi,jpj)     , INTENT(  out) ::   prd   ! in situ density
-      !!
-      INTEGER  ::   ji, jj                    ! dummy loop indices
-      REAL(wp) ::   zt, zs, zh, zsr, zr1, zr2, zr3, zr4, zrhop, ze, zbw   ! temporary scalars
-      REAL(wp) ::   zb, zd, zc, zaw, za, zb1, za1, zkw, zk0, zmask        !    -         -
-      REAL(wp), POINTER, DIMENSION(:,:) :: zws
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 ) CALL timing_start('eos2d')
-      !
-      CALL wrk_alloc( jpi, jpj, zws )
-      !
-
+      !
+      INTEGER  ::   ji, jj, jk                ! dummy loop indices
+      REAL(wp) ::   zt , zh , zs              ! local scalars
+      REAL(wp) ::   zn , zn0, zn1, zn2, zn3   !   -      -
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('eos2d')
+      !
       prd(:,:) = 0._wp
-
+      !
       SELECT CASE( nn_eos )
       !
-      CASE( 0 )                !==  Jackett and McDougall (1994) formulation  ==!
-      !
-!CDIR NOVERRCHK
-         DO jj = 1, jpj
-!CDIR NOVERRCHK
-            DO ji = 1, jpi   ! vector opt.
-               zws(ji,jj) = SQRT( ABS( pts(ji,jj,jp_sal) ) )
+      CASE( -1, 0 )                !==  polynomial TEOS-10 / EOS-80 ==!
+         !
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               !
+               zh  = pdep(ji,jj) * r1_Z0                                  ! depth
+               zt  = pts (ji,jj,jp_tem) * r1_T0                           ! temperature
+               zs  = SQRT( ABS( pts(ji,jj,jp_sal) + rdeltaS ) * r1_S0 )   ! square root salinity
+               !
+               zn3 = EOS013*zt   &
+                  &   + EOS103*zs+EOS003
+                  !
+               zn2 = (EOS022*zt   &
+                  &   + EOS112*zs+EOS012)*zt   &
+                  &   + (EOS202*zs+EOS102)*zs+EOS002
+                  !
+               zn1 = (((EOS041*zt   &
+                  &   + EOS131*zs+EOS031)*zt   &
+                  &   + (EOS221*zs+EOS121)*zs+EOS021)*zt   &
+                  &   + ((EOS311*zs+EOS211)*zs+EOS111)*zs+EOS011)*zt   &
+                  &   + (((EOS401*zs+EOS301)*zs+EOS201)*zs+EOS101)*zs+EOS001
+                  !
+               zn0 = (((((EOS060*zt   &
+                  &   + EOS150*zs+EOS050)*zt   &
+                  &   + (EOS240*zs+EOS140)*zs+EOS040)*zt   &
+                  &   + ((EOS330*zs+EOS230)*zs+EOS130)*zs+EOS030)*zt   &
+                  &   + (((EOS420*zs+EOS320)*zs+EOS220)*zs+EOS120)*zs+EOS020)*zt   &
+                  &   + ((((EOS510*zs+EOS410)*zs+EOS310)*zs+EOS210)*zs+EOS110)*zs+EOS010)*zt   &
+                  &   + (((((EOS600*zs+EOS500)*zs+EOS400)*zs+EOS300)*zs+EOS200)*zs+EOS100)*zs+EOS000
+                  !
+               zn  = ( ( zn3 * zh + zn2 ) * zh + zn1 ) * zh + zn0
+               !
+               prd(ji,jj) = zn * r1_rau0 - 1._wp               ! unmasked in situ density anomaly
+               !
             END DO
          END DO
-         DO jj = 1, jpj
-            DO ji = 1, jpi   ! vector opt.
-               zmask = ssmask(ji,jj)          ! land/sea bottom mask = surf. mask
-               zt    = pts  (ji,jj,jp_tem)            ! interpolated T
-               zs    = pts  (ji,jj,jp_sal)            ! interpolated S
-               zsr   = zws  (ji,jj)            ! square root of interpolated S
-               zh    = pdep (ji,jj)            ! depth at the partial step level
-               !
-               ! compute volumic mass pure water at atm pressure
-               zr1 = ( ( ( ( 6.536332e-9_wp*zt-1.120083e-6_wp )*zt+1.001685e-4_wp )*zt   &
-                  &                        -9.095290e-3_wp )*zt+6.793952e-2_wp )*zt+999.842594_wp
-               ! seawater volumic mass atm pressure
-               zr2 = ( ( ( 5.3875e-9_wp*zt-8.2467e-7_wp )*zt+7.6438e-5_wp ) *zt   &
-                  &                                   -4.0899e-3_wp ) *zt+0.824493_wp
-               zr3 = ( -1.6546e-6_wp*zt+1.0227e-4_wp ) *zt-5.72466e-3_wp
-               zr4 = 4.8314e-4_wp
-               !
-               ! potential volumic mass (reference to the surface)
-               zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1
-               !
-               ! add the compression terms
-               ze = ( -3.508914e-8_wp*zt-1.248266e-8_wp ) *zt-2.595994e-6_wp
-               zbw= (  1.296821e-6_wp*zt-5.782165e-9_wp ) *zt+1.045941e-4_wp
-               zb = zbw + ze * zs
-               !
-               zd =    -2.042967e-2_wp
-               zc =   (-7.267926e-5_wp*zt+2.598241e-3_wp ) *zt+0.1571896_wp
-               zaw= ( ( 5.939910e-6_wp*zt+2.512549e-3_wp ) *zt-0.1028859_wp ) *zt -4.721788_wp
-               za = ( zd*zsr + zc ) *zs + zaw
-               !
-               zb1=     (-0.1909078_wp  *zt+7.390729_wp      ) *zt-55.87545_wp
-               za1=   ( ( 2.326469e-3_wp*zt+1.553190_wp      ) *zt-65.00517_wp ) *zt+1044.077_wp
-               zkw= ( ( (-1.361629e-4_wp*zt-1.852732e-2_wp   ) *zt-30.41638_wp ) *zt   &
-                  &                             +2098.925_wp ) *zt+190925.6_wp
-               zk0= ( zb1*zsr + za1 )*zs + zkw
-               !
-               ! masked in situ density anomaly
-               prd(ji,jj) = ( zrhop / (  1.0_wp - zh / ( zk0 - zh * ( za - zh * zb ) )  ) - rau0 ) / rau0 * zmask
+         !
+         CALL lbc_lnk( prd, 'T', 1. )                    ! Lateral boundary conditions
+         !
+      CASE( 1 )                !==  simplified EOS  ==!
+         !
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               !
+               zt    = pts  (ji,jj,jp_tem)  - 10._wp
+               zs    = pts  (ji,jj,jp_sal)  - 35._wp
+               zh    = pdep (ji,jj)                         ! depth at the partial step level
+               !
+               zn =  - rn_a0 * ( 1._wp + 0.5_wp*rn_lambda1*zt + rn_mu1*zh ) * zt   &
+                  &  + rn_b0 * ( 1._wp - 0.5_wp*rn_lambda2*zs - rn_mu2*zh ) * zs   &
+                  &  - rn_nu * zt * zs
+                  !
+               prd(ji,jj) = zn * r1_rau0               ! unmasked in situ density anomaly
+               !
             END DO
          END DO
          !
-      CASE( 1 )                !==  Linear formulation = F( temperature )  ==!
-         DO jj = 1, jpj
-            DO ji = 1, jpi   ! vector opt.
-               prd(ji,jj) = ( 0.0285_wp - rn_alpha * pts(ji,jj,jp_tem) ) * ssmask(ji,jj)
-            END DO
-         END DO
-         !
-      CASE( 2 )                !==  Linear formulation = F( temperature , salinity )  ==!
-         DO jj = 1, jpj
-            DO ji = 1, jpi   ! vector opt.
-               prd(ji,jj) = ( rn_beta * pts(ji,jj,jp_sal) - rn_alpha * pts(ji,jj,jp_tem) ) * ssmask(ji,jj)
-            END DO
-         END DO
+         CALL lbc_lnk( prd, 'T', 1. )                    ! Lateral boundary conditions
          !
       END SELECT
-
+      !
       IF(ln_ctl)   CALL prt_ctl( tab2d_1=prd, clinfo1=' eos2d: ' )
       !
-      CALL wrk_dealloc( jpi, jpj, zws )
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('eos2d')
+      IF( nn_timing == 1 )   CALL timing_stop('eos2d')
       !
    END SUBROUTINE eos_insitu_2d
 
 
-   SUBROUTINE eos_bn2( pts, pn2 )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE eos_bn2  ***
-      !!
-      !! ** Purpose :   Compute the local Brunt-Vaisala frequency at the time-
-      !!      step of the input arguments
-      !!
-      !! ** Method :
-      !!       * nn_eos = 0  : UNESCO sea water properties
-      !!         The brunt-vaisala frequency is computed using the polynomial
-      !!      polynomial expression of McDougall (1987):
-      !!            N^2 = grav * beta * ( alpha/beta*dk[ t ] - dk[ s ] )/e3w
-      !!      If lk_zdfddm=T, the heat/salt buoyancy flux ratio Rrau is
-      !!      computed and used in zdfddm module :
-      !!              Rrau = alpha/beta * ( dk[ t ] / dk[ s ] )
-      !!       * nn_eos = 1  : linear equation of state (temperature only)
-      !!            N^2 = grav * rn_alpha * dk[ t ]/e3w
-      !!       * nn_eos = 2  : linear equation of state (temperature & salinity)
-      !!            N^2 = grav * (rn_alpha * dk[ t ] - rn_beta * dk[ s ] ) / e3w
-      !!      The use of potential density to compute N^2 introduces e r r o r
-      !!      in the sign of N^2 at great depths. We recommand the use of
-      !!      nn_eos = 0, except for academical studies.
-      !!        Macro-tasked on horizontal slab (jk-loop)
-      !!      N.B. N^2 is set to zero at the first level (JK=1) in inidtr
-      !!      and is never used at this level.
-      !!
-      !! ** Action  : - pn2 : the brunt-vaisala frequency
-      !!
-      !! References :   McDougall, J. Phys. Oceanogr., 17, 1950-1964, 1987.
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts), INTENT(in   ) ::   pts   ! 1 : potential temperature  [Celcius]
-      !                                                               ! 2 : salinity               [psu]
-      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pn2   ! Brunt-Vaisala frequency    [s-1]
-      !!
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zgde3w, zt, zs, zh, zalbet, zbeta   ! local scalars
-#if defined key_zdfddm
-      REAL(wp) ::   zds   ! local scalars
-#endif
-      !!----------------------------------------------------------------------
-
-      !
-      IF( nn_timing == 1 ) CALL timing_start('bn2')
-      !
-      ! pn2 : interior points only (2=< jk =< jpkm1 )
-      ! --------------------------
-      !
-      SELECT CASE( nn_eos )
-      !
-      CASE( 0 )                !==  Jackett and McDougall (1994) formulation  ==!
-         DO jk = 2, jpkm1
+   SUBROUTINE rab_3d( pts, pab )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE rab_3d  ***
+      !!
+      !! ** Purpose :   Calculates thermal/haline expansion ratio at T-points
+      !!
+      !! ** Method  :   calculates alpha / beta at T-points
+      !!
+      !! ** Action  : - pab     : thermal/haline expansion ratio at T-points
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts), INTENT(in   ) ::   pts   ! pot. temperature & salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts), INTENT(  out) ::   pab   ! thermal/haline expansion ratio
+      !
+      INTEGER  ::   ji, jj, jk                ! dummy loop indices
+      REAL(wp) ::   zt , zh , zs , ztm        ! local scalars
+      REAL(wp) ::   zn , zn0, zn1, zn2, zn3   !   -      -
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('rab_3d')
+      !
+      SELECT CASE ( nn_eos )
+      !
+      CASE( -1, 0 )                !==  polynomial TEOS-10 / EOS-80 ==!
+         !
+         DO jk = 1, jpkm1
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  zgde3w = grav / fse3w(ji,jj,jk)
-                  zt = 0.5_wp * ( pts(ji,jj,jk,jp_tem) + pts(ji,jj,jk-1,jp_tem) )            ! potential temperature at w-pt
-                  zs = 0.5_wp * ( pts(ji,jj,jk,jp_sal) + pts(ji,jj,jk-1,jp_sal) ) - 35.0_wp  ! salinity anomaly (s-35) at w-pt
-                  zh = fsdepw(ji,jj,jk)                                                ! depth in meters  at w-point
-                  !
-                  zalbet = ( ( ( - 0.255019e-07_wp * zt + 0.298357e-05_wp ) * zt   &   ! ratio alpha/beta
-                     &                                  - 0.203814e-03_wp ) * zt   &
-                     &                                  + 0.170907e-01_wp ) * zt   &
-                     &   +         0.665157e-01_wp                                 &
-                     &   +     ( - 0.678662e-05_wp * zs                            &
-                     &           - 0.846960e-04_wp * zt + 0.378110e-02_wp ) * zs   &
-                     &   +   ( ( - 0.302285e-13_wp * zh                            &
-                     &           - 0.251520e-11_wp * zs                            &
-                     &           + 0.512857e-12_wp * zt * zt              ) * zh   &
-                     &           - 0.164759e-06_wp * zs                            &
-                     &        +(   0.791325e-08_wp * zt - 0.933746e-06_wp ) * zt   &
-                     &                                  + 0.380374e-04_wp ) * zh
-                     !
-                  zbeta  = ( ( -0.415613e-09_wp * zt + 0.555579e-07_wp ) * zt      &   ! beta
-                     &                               - 0.301985e-05_wp ) * zt      &
-                     &   +       0.785567e-03_wp                                   &
-                     &   + (     0.515032e-08_wp * zs                              &
-                     &         + 0.788212e-08_wp * zt - 0.356603e-06_wp ) * zs     &
-                     &   + ( (   0.121551e-17_wp * zh                              &
-                     &         - 0.602281e-15_wp * zs                              &
-                     &         - 0.175379e-14_wp * zt + 0.176621e-12_wp ) * zh     &
-                     &                                + 0.408195e-10_wp   * zs     &
-                     &     + ( - 0.213127e-11_wp * zt + 0.192867e-09_wp ) * zt     &
-                     &                                - 0.121555e-07_wp ) * zh
-                     !
-                  pn2(ji,jj,jk) = zgde3w * zbeta * tmask(ji,jj,jk) * tmask(ji,jj,jk-1)           &   ! N^2
-                     &          * ( zalbet * ( pts(ji,jj,jk-1,jp_tem) - pts(ji,jj,jk,jp_tem) )   &
-                     &                     - ( pts(ji,jj,jk-1,jp_sal) - pts(ji,jj,jk,jp_sal) ) )
-#if defined key_zdfddm
-                  !                                                         !!bug **** caution a traiter zds=dk[S]= 0 !!!!
-                  zds = ( pts(ji,jj,jk-1,jp_sal) - pts(ji,jj,jk,jp_sal) )                    ! Rrau = (alpha / beta) (dk[t] / dk[s])
-                  IF ( ABS( zds) <= 1.e-20_wp ) zds = 1.e-20_wp
-                  rrau(ji,jj,jk) = zalbet * ( pts(ji,jj,jk-1,jp_tem) - pts(ji,jj,jk,jp_tem) ) / zds
-#endif
+                  !
+                  zh  = fsdept(ji,jj,jk) * r1_Z0                                ! depth
+                  zt  = pts (ji,jj,jk,jp_tem) * r1_T0                           ! temperature
+                  zs  = SQRT( ABS( pts(ji,jj,jk,jp_sal) + rdeltaS ) * r1_S0 )   ! square root salinity
+                  ztm = tmask(ji,jj,jk)                                         ! tmask
+                  !
+                  ! alpha
+                  zn3 = ALP003
+                  !
+                  zn2 = ALP012*zt + ALP102*zs+ALP002
+                  !
+                  zn1 = ((ALP031*zt   &
+                     &   + ALP121*zs+ALP021)*zt   &
+                     &   + (ALP211*zs+ALP111)*zs+ALP011)*zt   &
+                     &   + ((ALP301*zs+ALP201)*zs+ALP101)*zs+ALP001
+                     !
+                  zn0 = ((((ALP050*zt   &
+                     &   + ALP140*zs+ALP040)*zt   &
+                     &   + (ALP230*zs+ALP130)*zs+ALP030)*zt   &
+                     &   + ((ALP320*zs+ALP220)*zs+ALP120)*zs+ALP020)*zt   &
+                     &   + (((ALP410*zs+ALP310)*zs+ALP210)*zs+ALP110)*zs+ALP010)*zt   &
+                     &   + ((((ALP500*zs+ALP400)*zs+ALP300)*zs+ALP200)*zs+ALP100)*zs+ALP000
+                     !
+                  zn  = ( ( zn3 * zh + zn2 ) * zh + zn1 ) * zh + zn0
+                  !
+                  pab(ji,jj,jk,jp_tem) = zn * r1_rau0 * ztm
+                  !
+                  ! beta
+                  zn3 = BET003
+                  !
+                  zn2 = BET012*zt + BET102*zs+BET002
+                  !
+                  zn1 = ((BET031*zt   &
+                     &   + BET121*zs+BET021)*zt   &
+                     &   + (BET211*zs+BET111)*zs+BET011)*zt   &
+                     &   + ((BET301*zs+BET201)*zs+BET101)*zs+BET001
+                     !
+                  zn0 = ((((BET050*zt   &
+                     &   + BET140*zs+BET040)*zt   &
+                     &   + (BET230*zs+BET130)*zs+BET030)*zt   &
+                     &   + ((BET320*zs+BET220)*zs+BET120)*zs+BET020)*zt   &
+                     &   + (((BET410*zs+BET310)*zs+BET210)*zs+BET110)*zs+BET010)*zt   &
+                     &   + ((((BET500*zs+BET400)*zs+BET300)*zs+BET200)*zs+BET100)*zs+BET000
+                     !
+                  zn  = ( ( zn3 * zh + zn2 ) * zh + zn1 ) * zh + zn0
+                  !
+                  pab(ji,jj,jk,jp_sal) = zn / zs * r1_rau0 * ztm
+                  !
                END DO
             END DO
          END DO
          !
-      CASE( 1 )                !==  Linear formulation = F( temperature )  ==!
-         DO jk = 2, jpkm1
-            pn2(:,:,jk) = grav * rn_alpha * ( pts(:,:,jk-1,jp_tem) - pts(:,:,jk,jp_tem) )   &
-               &          / fse3w(:,:,jk) * tmask(:,:,jk) * tmask(:,:,jk-1)
-         END DO
-         !
-      CASE( 2 )                !==  Linear formulation = F( temperature , salinity )  ==!
-         DO jk = 2, jpkm1
-            pn2(:,:,jk) = grav * (  rn_alpha * ( pts(:,:,jk-1,jp_tem) - pts(:,:,jk,jp_tem) )      &
-               &                  - rn_beta  * ( pts(:,:,jk-1,jp_sal) - pts(:,:,jk,jp_sal) )  )   &
-               &               / fse3w(:,:,jk) * tmask(:,:,jk) * tmask(:,:,jk-1)
-         END DO
-#if defined key_zdfddm
-         DO jk = 2, jpkm1                                 ! Rrau = (alpha / beta) (dk[t] / dk[s])
+      CASE( 1 )                  !==  simplified EOS  ==!
+         !
+         DO jk = 1, jpkm1
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  zds = ( pts(ji,jj,jk-1,jp_sal) - pts(ji,jj,jk,jp_sal) )
-                  IF ( ABS( zds ) <= 1.e-20_wp ) zds = 1.e-20_wp
-                  rrau(ji,jj,jk) = ralpbet * ( pts(ji,jj,jk-1,jp_tem) - pts(ji,jj,jk,jp_tem) ) / zds
+                  zt  = pts (ji,jj,jk,jp_tem) - 10._wp   ! pot. temperature anomaly (t-T0)
+                  zs  = pts (ji,jj,jk,jp_sal) - 35._wp   ! abs. salinity anomaly (s-S0)
+                  zh  = fsdept(ji,jj,jk)                 ! depth in meters at t-point
+                  ztm = tmask(ji,jj,jk)                  ! land/sea bottom mask = surf. mask
+                  !
+                  zn  = rn_a0 * ( 1._wp + rn_lambda1*zt + rn_mu1*zh ) + rn_nu*zs
+                  pab(ji,jj,jk,jp_tem) = zn * r1_rau0 * ztm   ! alpha
+                  !
+                  zn  = rn_b0 * ( 1._wp - rn_lambda2*zs - rn_mu2*zh ) - rn_nu*zt
+                  pab(ji,jj,jk,jp_sal) = zn * r1_rau0 * ztm   ! beta
+                  !
                END DO
             END DO
          END DO
-#endif
-      END SELECT
-
-      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pn2, clinfo1=' bn2  : ', ovlap=1, kdim=jpk )
-#if defined key_zdfddm
-      IF(ln_ctl)   CALL prt_ctl( tab3d_1=rrau, clinfo1=' rrau : ', ovlap=1, kdim=jpk )
-#endif
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('bn2')
-      !
-   END SUBROUTINE eos_bn2
-
-
-   SUBROUTINE eos_alpbet( pts, palpbet, beta0 )
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE eos_alpbet  ***
-      !!
-      !! ** Purpose :   Calculates the in situ thermal/haline expansion ratio at T-points
-      !!
-      !! ** Method  :   calculates alpha / beta ratio at T-points
-      !!       * nn_eos = 0  : UNESCO sea water properties
-      !!                       The alpha/beta ratio is returned as 3-D array palpbet using the polynomial
-      !!                       polynomial expression of McDougall (1987).
-      !!                       Scalar beta0 is returned = 1.
-      !!       * nn_eos = 1  : linear equation of state (temperature only)
-      !!                       The ratio is undefined, so we return alpha as palpbet
-      !!                       Scalar beta0 is returned = 0.
-      !!       * nn_eos = 2  : linear equation of state (temperature & salinity)
-      !!                       The alpha/beta ratio is returned as ralpbet
-      !!                       Scalar beta0 is returned = 1.
-      !!
-      !! ** Action  : - palpbet : thermal/haline expansion ratio at T-points
-      !!            :   beta0   : 1. or 0.
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts), INTENT(in   ) ::   pts       ! pot. temperature & salinity
-      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   palpbet   ! thermal/haline expansion ratio
-      REAL(wp),                              INTENT(  out) ::   beta0     ! set = 1 except with case 1 eos, rho=rho(T)
-      !!
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zt, zs, zh   ! local scalars
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 ) CALL timing_start('eos_alpbet')
-      !
-      SELECT CASE ( nn_eos )
-      !
-      CASE ( 0 )               ! Jackett and McDougall (1994) formulation
-         DO jk = 1, jpk
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zt = pts(ji,jj,jk,jp_tem)           ! potential temperature
-                  zs = pts(ji,jj,jk,jp_sal) - 35._wp  ! salinity anomaly (s-35)
-                  zh = fsdept(ji,jj,jk)               ! depth in meters
-                  !
-                  palpbet(ji,jj,jk) =                                              &
-                     &     ( ( ( - 0.255019e-07_wp * zt + 0.298357e-05_wp ) * zt   &
-                     &                                  - 0.203814e-03_wp ) * zt   &
-                     &                                  + 0.170907e-01_wp ) * zt   &
-                     &   + 0.665157e-01_wp                                         &
-                     &   +     ( - 0.678662e-05_wp * zs                            &
-                     &           - 0.846960e-04_wp * zt + 0.378110e-02_wp ) * zs   &
-                     &   +   ( ( - 0.302285e-13_wp * zh                            &
-                     &           - 0.251520e-11_wp * zs                            &
-                     &           + 0.512857e-12_wp * zt * zt              ) * zh   &
-                     &           - 0.164759e-06_wp * zs                            &
-                     &        +(   0.791325e-08_wp * zt - 0.933746e-06_wp ) * zt   &
-                     &                                  + 0.380374e-04_wp ) * zh
-               END DO
-            END DO
-         END DO
-         beta0 = 1._wp
-         !
-      CASE ( 1 )              !==  Linear formulation = F( temperature )  ==!
-         palpbet(:,:,:) = rn_alpha
-         beta0 = 0._wp
-         !
-      CASE ( 2 )              !==  Linear formulation = F( temperature , salinity )  ==!
-         palpbet(:,:,:) = ralpbet
-         beta0 = 1._wp
          !
       CASE DEFAULT
@@ -674,83 +595,582 @@
       END SELECT
       !
-      IF( nn_timing == 1 ) CALL timing_stop('eos_alpbet')
-      !
-   END SUBROUTINE eos_alpbet
-
-
-   FUNCTION tfreez( psal, pdep ) RESULT( ptf )
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pab(:,:,:,jp_tem), clinfo1=' rab_3d_t: ', &
+         &                       tab3d_2=pab(:,:,:,jp_sal), clinfo2=' rab_3d_s : ', ovlap=1, kdim=jpk )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('rab_3d')
+      !
+   END SUBROUTINE rab_3d
+
+   SUBROUTINE rab_2d( pts, pdep, pab )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE rab_2d  ***
+      !!
+      !! ** Purpose :   Calculates thermal/haline expansion ratio for a 2d field (unmasked)
+      !!
+      !! ** Action  : - pab     : thermal/haline expansion ratio at T-points
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpts)    , INTENT(in   ) ::   pts    ! pot. temperature & salinity
+      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(in   ) ::   pdep   ! depth                  [m]
+      REAL(wp), DIMENSION(jpi,jpj,jpts)    , INTENT(  out) ::   pab    ! thermal/haline expansion ratio
+      !
+      INTEGER  ::   ji, jj, jk                ! dummy loop indices
+      REAL(wp) ::   zt , zh , zs              ! local scalars
+      REAL(wp) ::   zn , zn0, zn1, zn2, zn3   !   -      -
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('rab_2d')
+      !
+      pab(:,:,:) = 0._wp
+      !
+      SELECT CASE ( nn_eos )
+      !
+      CASE( -1, 0 )                !==  polynomial TEOS-10 / EOS-80 ==!
+         !
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               !
+               zh  = pdep(ji,jj) * r1_Z0                                  ! depth
+               zt  = pts (ji,jj,jp_tem) * r1_T0                           ! temperature
+               zs  = SQRT( ABS( pts(ji,jj,jp_sal) + rdeltaS ) * r1_S0 )   ! square root salinity
+               !
+               ! alpha
+               zn3 = ALP003
+               !
+               zn2 = ALP012*zt + ALP102*zs+ALP002
+               !
+               zn1 = ((ALP031*zt   &
+                  &   + ALP121*zs+ALP021)*zt   &
+                  &   + (ALP211*zs+ALP111)*zs+ALP011)*zt   &
+                  &   + ((ALP301*zs+ALP201)*zs+ALP101)*zs+ALP001
+                  !
+               zn0 = ((((ALP050*zt   &
+                  &   + ALP140*zs+ALP040)*zt   &
+                  &   + (ALP230*zs+ALP130)*zs+ALP030)*zt   &
+                  &   + ((ALP320*zs+ALP220)*zs+ALP120)*zs+ALP020)*zt   &
+                  &   + (((ALP410*zs+ALP310)*zs+ALP210)*zs+ALP110)*zs+ALP010)*zt   &
+                  &   + ((((ALP500*zs+ALP400)*zs+ALP300)*zs+ALP200)*zs+ALP100)*zs+ALP000
+                  !
+               zn  = ( ( zn3 * zh + zn2 ) * zh + zn1 ) * zh + zn0
+               !
+               pab(ji,jj,jp_tem) = zn * r1_rau0
+               !
+               ! beta
+               zn3 = BET003
+               !
+               zn2 = BET012*zt + BET102*zs+BET002
+               !
+               zn1 = ((BET031*zt   &
+                  &   + BET121*zs+BET021)*zt   &
+                  &   + (BET211*zs+BET111)*zs+BET011)*zt   &
+                  &   + ((BET301*zs+BET201)*zs+BET101)*zs+BET001
+                  !
+               zn0 = ((((BET050*zt   &
+                  &   + BET140*zs+BET040)*zt   &
+                  &   + (BET230*zs+BET130)*zs+BET030)*zt   &
+                  &   + ((BET320*zs+BET220)*zs+BET120)*zs+BET020)*zt   &
+                  &   + (((BET410*zs+BET310)*zs+BET210)*zs+BET110)*zs+BET010)*zt   &
+                  &   + ((((BET500*zs+BET400)*zs+BET300)*zs+BET200)*zs+BET100)*zs+BET000
+                  !
+               zn  = ( ( zn3 * zh + zn2 ) * zh + zn1 ) * zh + zn0
+               !
+               pab(ji,jj,jp_sal) = zn / zs * r1_rau0
+               !
+               !
+            END DO
+         END DO
+         !
+         CALL lbc_lnk( pab(:,:,jp_tem), 'T', 1. )                    ! Lateral boundary conditions
+         CALL lbc_lnk( pab(:,:,jp_sal), 'T', 1. )                    
+         !
+      CASE( 1 )                  !==  simplified EOS  ==!
+         !
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               !
+               zt    = pts  (ji,jj,jp_tem) - 10._wp   ! pot. temperature anomaly (t-T0)
+               zs    = pts  (ji,jj,jp_sal) - 35._wp   ! abs. salinity anomaly (s-S0)
+               zh    = pdep (ji,jj)                   ! depth at the partial step level
+               !
+               zn  = rn_a0 * ( 1._wp + rn_lambda1*zt + rn_mu1*zh ) + rn_nu*zs
+               pab(ji,jj,jp_tem) = zn * r1_rau0   ! alpha
+               !
+               zn  = rn_b0 * ( 1._wp - rn_lambda2*zs - rn_mu2*zh ) - rn_nu*zt
+               pab(ji,jj,jp_sal) = zn * r1_rau0   ! beta
+               !
+            END DO
+         END DO
+         !
+         CALL lbc_lnk( pab(:,:,jp_tem), 'T', 1. )                    ! Lateral boundary conditions
+         CALL lbc_lnk( pab(:,:,jp_sal), 'T', 1. )                    
+         !
+      CASE DEFAULT
+         IF(lwp) WRITE(numout,cform_err)
+         IF(lwp) WRITE(numout,*) '          bad flag value for nn_eos = ', nn_eos
+         nstop = nstop + 1
+         !
+      END SELECT
+      !
+      IF(ln_ctl)   CALL prt_ctl( tab2d_1=pab(:,:,jp_tem), clinfo1=' rab_2d_t: ', &
+         &                       tab2d_2=pab(:,:,jp_sal), clinfo2=' rab_2d_s : ' )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('rab_2d')
+      !
+   END SUBROUTINE rab_2d
+
+
+   SUBROUTINE rab_0d( pts, pdep, pab )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE rab_0d  ***
+      !!
+      !! ** Purpose :   Calculates thermal/haline expansion ratio for a 2d field (unmasked)
+      !!
+      !! ** Action  : - pab     : thermal/haline expansion ratio at T-points
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpts)    , INTENT(in   ) ::   pts    ! pot. temperature & salinity
+      REAL(wp),                      INTENT(in   ) ::   pdep   ! depth                  [m]
+      REAL(wp), DIMENSION(jpts)    , INTENT(  out) ::   pab    ! thermal/haline expansion ratio
+      !
+      REAL(wp) ::   zt , zh , zs              ! local scalars
+      REAL(wp) ::   zn , zn0, zn1, zn2, zn3   !   -      -
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('rab_2d')
+      !
+      pab(:) = 0._wp
+      !
+      SELECT CASE ( nn_eos )
+      !
+      CASE( -1, 0 )                !==  polynomial TEOS-10 / EOS-80 ==!
+         !
+         !
+         zh  = pdep * r1_Z0                                  ! depth
+         zt  = pts (jp_tem) * r1_T0                           ! temperature
+         zs  = SQRT( ABS( pts(jp_sal) + rdeltaS ) * r1_S0 )   ! square root salinity
+         !
+         ! alpha
+         zn3 = ALP003
+         !
+         zn2 = ALP012*zt + ALP102*zs+ALP002
+         !
+         zn1 = ((ALP031*zt   &
+            &   + ALP121*zs+ALP021)*zt   &
+            &   + (ALP211*zs+ALP111)*zs+ALP011)*zt   &
+            &   + ((ALP301*zs+ALP201)*zs+ALP101)*zs+ALP001
+            !
+         zn0 = ((((ALP050*zt   &
+            &   + ALP140*zs+ALP040)*zt   &
+            &   + (ALP230*zs+ALP130)*zs+ALP030)*zt   &
+            &   + ((ALP320*zs+ALP220)*zs+ALP120)*zs+ALP020)*zt   &
+            &   + (((ALP410*zs+ALP310)*zs+ALP210)*zs+ALP110)*zs+ALP010)*zt   &
+            &   + ((((ALP500*zs+ALP400)*zs+ALP300)*zs+ALP200)*zs+ALP100)*zs+ALP000
+            !
+         zn  = ( ( zn3 * zh + zn2 ) * zh + zn1 ) * zh + zn0
+         !
+         pab(jp_tem) = zn * r1_rau0
+         !
+         ! beta
+         zn3 = BET003
+         !
+         zn2 = BET012*zt + BET102*zs+BET002
+         !
+         zn1 = ((BET031*zt   &
+            &   + BET121*zs+BET021)*zt   &
+            &   + (BET211*zs+BET111)*zs+BET011)*zt   &
+            &   + ((BET301*zs+BET201)*zs+BET101)*zs+BET001
+            !
+         zn0 = ((((BET050*zt   &
+            &   + BET140*zs+BET040)*zt   &
+            &   + (BET230*zs+BET130)*zs+BET030)*zt   &
+            &   + ((BET320*zs+BET220)*zs+BET120)*zs+BET020)*zt   &
+            &   + (((BET410*zs+BET310)*zs+BET210)*zs+BET110)*zs+BET010)*zt   &
+            &   + ((((BET500*zs+BET400)*zs+BET300)*zs+BET200)*zs+BET100)*zs+BET000
+            !
+         zn  = ( ( zn3 * zh + zn2 ) * zh + zn1 ) * zh + zn0
+         !
+         pab(jp_sal) = zn / zs * r1_rau0
+         !
+         !
+         !
+      CASE( 1 )                  !==  simplified EOS  ==!
+         !
+         zt    = pts(jp_tem) - 10._wp   ! pot. temperature anomaly (t-T0)
+         zs    = pts(jp_sal) - 35._wp   ! abs. salinity anomaly (s-S0)
+         zh    = pdep                    ! depth at the partial step level
+         !
+         zn  = rn_a0 * ( 1._wp + rn_lambda1*zt + rn_mu1*zh ) + rn_nu*zs
+         pab(jp_tem) = zn * r1_rau0   ! alpha
+         !
+         zn  = rn_b0 * ( 1._wp - rn_lambda2*zs - rn_mu2*zh ) - rn_nu*zt
+         pab(jp_sal) = zn * r1_rau0   ! beta
+         !
+      CASE DEFAULT
+         IF(lwp) WRITE(numout,cform_err)
+         IF(lwp) WRITE(numout,*) '          bad flag value for nn_eos = ', nn_eos
+         nstop = nstop + 1
+         !
+      END SELECT
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('rab_2d')
+      !
+   END SUBROUTINE rab_0d
+
+
+   SUBROUTINE bn2( pts, pab, pn2 )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE bn2  ***
+      !!
+      !! ** Purpose :   Compute the local Brunt-Vaisala frequency at the 
+      !!                time-step of the input arguments
+      !!
+      !! ** Method  :   pn2 = grav * (alpha dk[T] + beta dk[S] ) / e3w
+      !!      where alpha and beta are given in pab, and computed on T-points.
+      !!      N.B. N^2 is set one for all to zero at jk=1 in istate module.
+      !!
+      !! ** Action  :   pn2 : square of the brunt-vaisala frequency at w-point 
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts), INTENT(in   ) ::  pts   ! pot. temperature and salinity   [Celcius,psu]
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts), INTENT(in   ) ::  pab   ! thermal/haline expansion coef.  [Celcius-1,psu-1]
+      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(  out) ::  pn2   ! Brunt-Vaisala frequency squared [1/s^2]
+      !
+      INTEGER  ::   ji, jj, jk      ! dummy loop indices
+      REAL(wp) ::   zaw, zbw, zrw   ! local scalars
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('bn2')
+      !
+      DO jk = 2, jpkm1           ! interior points only (2=< jk =< jpkm1 )
+         DO jj = 1, jpj          ! surface and bottom value set to zero one for all in istate.F90
+            DO ji = 1, jpi
+               zrw =   ( fsdepw(ji,jj,jk  ) - fsdept(ji,jj,jk) )   &
+                  &  / ( fsdept(ji,jj,jk-1) - fsdept(ji,jj,jk) ) 
+                  !
+               zaw = pab(ji,jj,jk,jp_tem) * (1. - zrw) + pab(ji,jj,jk-1,jp_tem) * zrw 
+               zbw = pab(ji,jj,jk,jp_sal) * (1. - zrw) + pab(ji,jj,jk-1,jp_sal) * zrw
+               !
+               pn2(ji,jj,jk) = grav * (  zaw * ( pts(ji,jj,jk-1,jp_tem) - pts(ji,jj,jk,jp_tem) )     &
+                  &                    - zbw * ( pts(ji,jj,jk-1,jp_sal) - pts(ji,jj,jk,jp_sal) )  )  &
+                  &            / fse3w(ji,jj,jk) * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=pn2, clinfo1=' bn2  : ', ovlap=1, kdim=jpk )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('bn2')
+      !
+   END SUBROUTINE bn2
+
+
+   FUNCTION eos_pt_from_ct( ctmp, psal ) RESULT( ptmp )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE eos_pt_from_ct  ***
+      !!
+      !! ** Purpose :   Compute pot.temp. from cons. temp. [Celcius]
+      !!
+      !! ** Method  :   rational approximation (5/3th order) of TEOS-10 algorithm
+      !!       checkvalue: pt=20.02391895 Celsius for sa=35.7g/kg, ct=20degC
+      !!
+      !! Reference  :   TEOS-10, UNESCO
+      !!                Rational approximation to TEOS10 algorithm (rms error on WOA13 values: 4.0e-5 degC)
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   ctmp   ! Cons. Temp [Celcius]
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   psal   ! salinity   [psu]
+      ! Leave result array automatic rather than making explicitly allocated
+      REAL(wp), DIMENSION(jpi,jpj) ::   ptmp   ! potential temperature [Celcius]
+      !
+      INTEGER  ::   ji, jj               ! dummy loop indices
+      REAL(wp) ::   zt , zs , ztm        ! local scalars
+      REAL(wp) ::   zn , zd              ! local scalars
+      REAL(wp) ::   zdeltaS , z1_S0 , z1_T0
+      !!----------------------------------------------------------------------
+      !
+      IF ( nn_timing == 1 )   CALL timing_start('eos_pt_from_ct')
+      !
+      zdeltaS = 5._wp
+      z1_S0   = 0.875_wp/35.16504_wp
+      z1_T0   = 1._wp/40._wp
+      !
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            !
+            zt  = ctmp   (ji,jj) * z1_T0
+            zs  = SQRT( ABS( psal(ji,jj) + zdeltaS ) * r1_S0 )
+            ztm = tmask(ji,jj,1)
+            !
+            zn = ((((-2.1385727895e-01_wp*zt   &
+               &   - 2.7674419971e-01_wp*zs+1.0728094330_wp)*zt   &
+               &   + (2.6366564313_wp*zs+3.3546960647_wp)*zs-7.8012209473_wp)*zt   &
+               &   + ((1.8835586562_wp*zs+7.3949191679_wp)*zs-3.3937395875_wp)*zs-5.6414948432_wp)*zt   &
+               &   + (((3.5737370589_wp*zs-1.5512427389e+01_wp)*zs+2.4625741105e+01_wp)*zs   &
+               &      +1.9912291000e+01_wp)*zs-3.2191146312e+01_wp)*zt   &
+               &   + ((((5.7153204649e-01_wp*zs-3.0943149543_wp)*zs+9.3052495181_wp)*zs   &
+               &      -9.4528934807_wp)*zs+3.1066408996_wp)*zs-4.3504021262e-01_wp
+               !
+            zd = (2.0035003456_wp*zt   &
+               &   -3.4570358592e-01_wp*zs+5.6471810638_wp)*zt   &
+               &   + (1.5393993508_wp*zs-6.9394762624_wp)*zs+1.2750522650e+01_wp
+               !
+            ptmp(ji,jj) = ( zt / z1_T0 + zn / zd ) * ztm
+               !
+         END DO
+      END DO
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('eos_pt_from_ct')
+      !
+   END FUNCTION eos_pt_from_ct
+
+
+   FUNCTION eos_fzp_2d( psal, pdep ) RESULT( ptf )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE eos_fzp  ***
+      !!
+      !! ** Purpose :   Compute the freezing point temperature [Celcius]
+      !!
+      !! ** Method  :   UNESCO freezing point (ptf) in Celcius is given by
+      !!       ptf(t,z) = (-.0575+1.710523e-3*sqrt(abs(s))-2.154996e-4*s)*s - 7.53e-4*z
+      !!       checkvalue: tf=-2.588567 Celsius for s=40psu, z=500m
+      !!
+      !! Reference  :   UNESCO tech. papers in the marine science no. 28. 1978
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   )           ::   psal   ! salinity   [psu]
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ), OPTIONAL ::   pdep   ! depth      [m]
+      REAL(wp), DIMENSION(jpi,jpj)                          ::   ptf   ! freezing temperature [Celcius]
+      !
+      INTEGER  ::   ji, jj   ! dummy loop indices
+      REAL(wp) ::   zt, zs   ! local scalars
+      !!----------------------------------------------------------------------
+      !
+      SELECT CASE ( nn_eos )
+      !
+      CASE ( -1, 1 )                !==  CT,SA (TEOS-10 formulation) ==!
+         !
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zs= SQRT( ABS( psal(ji,jj) ) * r1_S0 )           ! square root salinity
+               ptf(ji,jj) = ((((1.46873e-03_wp*zs-9.64972e-03_wp)*zs+2.28348e-02_wp)*zs &
+                  &          - 3.12775e-02_wp)*zs+2.07679e-02_wp)*zs-5.87701e-02_wp
+            END DO
+         END DO
+         ptf(:,:) = ptf(:,:) * psal(:,:)
+         !
+         IF( PRESENT( pdep ) )   ptf(:,:) = ptf(:,:) - 7.53e-4 * pdep(:,:)
+         !
+      CASE ( 0 )                     !==  PT,SP (UNESCO formulation)  ==!
+         !
+         ptf(:,:) = ( - 0.0575_wp + 1.710523e-3_wp * SQRT( psal(:,:) )   &
+            &                     - 2.154996e-4_wp *       psal(:,:)   ) * psal(:,:)
+            !
+         IF( PRESENT( pdep ) )   ptf(:,:) = ptf(:,:) - 7.53e-4 * pdep(:,:)
+         !
+      CASE DEFAULT
+         IF(lwp) WRITE(numout,cform_err)
+         IF(lwp) WRITE(numout,*) '          bad flag value for nn_eos = ', nn_eos
+         nstop = nstop + 1
+         !
+      END SELECT
+      !
+   END FUNCTION eos_fzp_2d
+
+  FUNCTION eos_fzp_0d( psal, pdep ) RESULT( ptf )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE eos_fzp  ***
+      !!
+      !! ** Purpose :   Compute the freezing point temperature [Celcius]
+      !!
+      !! ** Method  :   UNESCO freezing point (ptf) in Celcius is given by
+      !!       ptf(t,z) = (-.0575+1.710523e-3*sqrt(abs(s))-2.154996e-4*s)*s - 7.53e-4*z
+      !!       checkvalue: tf=-2.588567 Celsius for s=40psu, z=500m
+      !!
+      !! Reference  :   UNESCO tech. papers in the marine science no. 28. 1978
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in)           ::   psal   ! salinity   [psu]
+      REAL(wp), INTENT(in), OPTIONAL ::   pdep   ! depth      [m]
+      REAL(wp)                       ::   ptf   ! freezing temperature [Celcius]
+      !
+      REAL(wp) :: zs   ! local scalars
+      !!----------------------------------------------------------------------
+      !
+      SELECT CASE ( nn_eos )
+      !
+      CASE ( -1, 1 )                !==  CT,SA (TEOS-10 formulation) ==!
+         !
+         zs  = SQRT( ABS( psal ) * r1_S0 )           ! square root salinity
+         ptf = ((((1.46873e-03_wp*zs-9.64972e-03_wp)*zs+2.28348e-02_wp)*zs &
+                  &          - 3.12775e-02_wp)*zs+2.07679e-02_wp)*zs-5.87701e-02_wp
+         ptf = ptf * psal
+         !
+         IF( PRESENT( pdep ) )   ptf = ptf - 7.53e-4 * pdep
+         !
+      CASE ( 0 )                     !==  PT,SP (UNESCO formulation)  ==!
+         !
+         ptf = ( - 0.0575_wp + 1.710523e-3_wp * SQRT( psal )   &
+            &                - 2.154996e-4_wp *       psal   ) * psal
+            !
+         IF( PRESENT( pdep ) )   ptf = ptf - 7.53e-4 * pdep
+         !
+      CASE DEFAULT
+         IF(lwp) WRITE(numout,cform_err)
+         IF(lwp) WRITE(numout,*) '          bad flag value for nn_eos = ', nn_eos
+         nstop = nstop + 1
+         !
+      END SELECT
+      !
+   END FUNCTION eos_fzp_0d
+
+
+   SUBROUTINE eos_pen( pts, pab_pe, ppen )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE eos_pen  ***
+      !!
+      !! ** Purpose :   Calculates nonlinear anomalies of alpha_PE, beta_PE and PE at T-points
+      !!
+      !! ** Method  :   PE is defined analytically as the vertical 
+      !!                   primitive of EOS times -g integrated between 0 and z>0.
+      !!                pen is the nonlinear bsq-PE anomaly: pen = ( PE - rau0 gz ) / rau0 gz - rd
+      !!                                                      = 1/z * /int_0^z rd dz - rd 
+      !!                                where rd is the density anomaly (see eos_rhd function)
+      !!                ab_pe are partial derivatives of PE anomaly with respect to T and S:
+      !!                    ab_pe(1) = - 1/(rau0 gz) * dPE/dT + drd/dT = - d(pen)/dT
+      !!                    ab_pe(2) =   1/(rau0 gz) * dPE/dS + drd/dS =   d(pen)/dS
+      !!
+      !! ** Action  : - pen         : PE anomaly given at T-points
+      !!            : - pab_pe  : given at T-points
+      !!                    pab_pe(:,:,:,jp_tem) is alpha_pe
+      !!                    pab_pe(:,:,:,jp_sal) is beta_pe
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts), INTENT(in   ) ::   pts     ! pot. temperature & salinity
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts), INTENT(  out) ::   pab_pe  ! alpha_pe and beta_pe
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   ppen     ! potential energy anomaly
+      !
+      INTEGER  ::   ji, jj, jk                ! dummy loop indices
+      REAL(wp) ::   zt , zh , zs , ztm        ! local scalars
+      REAL(wp) ::   zn , zn0, zn1, zn2        !   -      -
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('eos_pen')
+      !
+      SELECT CASE ( nn_eos )
+      !
+      CASE( -1, 0 )                !==  polynomial TEOS-10 / EOS-80 ==!
+         !
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  !
+                  zh  = fsdept(ji,jj,jk) * r1_Z0                                ! depth
+                  zt  = pts (ji,jj,jk,jp_tem) * r1_T0                           ! temperature
+                  zs  = SQRT( ABS( pts(ji,jj,jk,jp_sal) + rdeltaS ) * r1_S0 )   ! square root salinity
+                  ztm = tmask(ji,jj,jk)                                         ! tmask
+                  !
+                  ! potential energy non-linear anomaly
+                  zn2 = (PEN012)*zt   &
+                     &   + PEN102*zs+PEN002
+                     !
+                  zn1 = ((PEN021)*zt   &
+                     &   + PEN111*zs+PEN011)*zt   &
+                     &   + (PEN201*zs+PEN101)*zs+PEN001
+                     !
+                  zn0 = ((((PEN040)*zt   &
+                     &   + PEN130*zs+PEN030)*zt   &
+                     &   + (PEN220*zs+PEN120)*zs+PEN020)*zt   &
+                     &   + ((PEN310*zs+PEN210)*zs+PEN110)*zs+PEN010)*zt   &
+                     &   + (((PEN400*zs+PEN300)*zs+PEN200)*zs+PEN100)*zs+PEN000
+                     !
+                  zn  = ( zn2 * zh + zn1 ) * zh + zn0
+                  !
+                  ppen(ji,jj,jk)  = zn * zh * r1_rau0 * ztm
+                  !
+                  ! alphaPE non-linear anomaly
+                  zn2 = APE002
+                  !
+                  zn1 = (APE011)*zt   &
+                     &   + APE101*zs+APE001
+                     !
+                  zn0 = (((APE030)*zt   &
+                     &   + APE120*zs+APE020)*zt   &
+                     &   + (APE210*zs+APE110)*zs+APE010)*zt   &
+                     &   + ((APE300*zs+APE200)*zs+APE100)*zs+APE000
+                     !
+                  zn  = ( zn2 * zh + zn1 ) * zh + zn0
+                  !                              
+                  pab_pe(ji,jj,jk,jp_tem) = zn * zh * r1_rau0 * ztm
+                  !
+                  ! betaPE non-linear anomaly
+                  zn2 = BPE002
+                  !
+                  zn1 = (BPE011)*zt   &
+                     &   + BPE101*zs+BPE001
+                     !
+                  zn0 = (((BPE030)*zt   &
+                     &   + BPE120*zs+BPE020)*zt   &
+                     &   + (BPE210*zs+BPE110)*zs+BPE010)*zt   &
+                     &   + ((BPE300*zs+BPE200)*zs+BPE100)*zs+BPE000
+                     !
+                  zn  = ( zn2 * zh + zn1 ) * zh + zn0
+                  !                              
+                  pab_pe(ji,jj,jk,jp_sal) = zn / zs * zh * r1_rau0 * ztm
+                  !
+               END DO
+            END DO
+         END DO
+         !
+      CASE( 1 )                !==  Vallis (2006) simplified EOS  ==!
+         !
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zt  = pts(ji,jj,jk,jp_tem) - 10._wp  ! temperature anomaly (t-T0)
+                  zs = pts (ji,jj,jk,jp_sal) - 35._wp  ! abs. salinity anomaly (s-S0)
+                  zh  = fsdept(ji,jj,jk)               ! depth in meters  at t-point
+                  ztm = tmask(ji,jj,jk)                ! tmask
+                  zn  = 0.5_wp * zh * r1_rau0 * ztm
+                  !                                    ! Potential Energy
+                  ppen(ji,jj,jk) = ( rn_a0 * rn_mu1 * zt + rn_b0 * rn_mu2 * zs ) * zn
+                  !                                    ! alphaPE
+                  pab_pe(ji,jj,jk,jp_tem) = - rn_a0 * rn_mu1 * zn
+                  pab_pe(ji,jj,jk,jp_sal) =   rn_b0 * rn_mu2 * zn
+                  !
+               END DO
+            END DO
+         END DO
+         !
+      CASE DEFAULT
+         IF(lwp) WRITE(numout,cform_err)
+         IF(lwp) WRITE(numout,*) '          bad flag value for nn_eos = ', nn_eos
+         nstop = nstop + 1
+         !
+      END SELECT
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('eos_pen')
+      !
+   END SUBROUTINE eos_pen
+
+
+   SUBROUTINE eos_init
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE eos_init  ***
       !!
-      !! ** Purpose :   Compute the sea surface freezing temperature [Celcius]
-      !!
-      !! ** Method  :   UNESCO freezing point at the surface (pressure = 0???)
-      !!       freezing point [Celcius]=(-.0575+1.710523e-3*sqrt(abs(s))-2.154996e-4*s)*s-7.53e-4*p
-      !!       checkvalue: tf= -2.588567 Celsius for s=40.0psu, p=500. decibars
-      !!
-      !! Reference  :   UNESCO tech. papers in the marine science no. 28. 1978
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   psal   ! salinity             [psu]
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ), OPTIONAL ::   pdep   ! depth      [decibars]
-      ! Leave result array automatic rather than making explicitly allocated
-      REAL(wp), DIMENSION(jpi,jpj)                ::   ptf    ! freezing temperature [Celcius]
-      !!----------------------------------------------------------------------
-      !
-      ptf(:,:) = ( - 0.0575_wp + 1.710523e-3_wp * SQRT( psal(:,:) )   &
-         &                     - 2.154996e-4_wp *       psal(:,:)   ) * psal(:,:)
-      IF ( PRESENT( pdep ) ) THEN   
-         ptf(:,:) = ptf(:,:) - 7.53e-4_wp * pdep(:,:)
-      ENDIF
-      !
-   END FUNCTION tfreez
-
-   FUNCTION tfreez1D( psal, pdep ) RESULT( ptf )
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE eos_init  ***
-      !!
-      !! ** Purpose :   Compute the sea surface freezing temperature [Celcius]
-      !!
-      !! ** Method  :   UNESCO freezing point at the surface (pressure = 0???)
-      !!       freezing point [Celcius]=(-.0575+1.710523e-3*sqrt(abs(s))-2.154996e-4*s)*s-7.53e-4*p
-      !!       checkvalue: tf= -2.588567 Celsius for s=40.0psu, p=500. decibars
-      !!
-      !! Reference  :   UNESCO tech. papers in the marine science no. 28. 1978
-      !!----------------------------------------------------------------------
-      REAL(wp), INTENT(in   ) ::   psal   ! salinity             [psu]
-      REAL(wp), INTENT(in   ), OPTIONAL ::   pdep   ! pressure             [dBar]
-      ! Leave result array automatic rather than making explicitly allocated
-      REAL(wp)                ::   ptf    ! freezing temperature [Celcius]
-      !!----------------------------------------------------------------------
-      !
-      ptf = ( - 0.0575_wp + 1.710523e-3_wp * SQRT( psal )   &
-         &                     - 2.154996e-4_wp *  psal ) * psal
-      IF ( PRESENT( pdep ) ) THEN   
-         ptf = ptf - 7.53e-4_wp * pdep
-      ENDIF
-      !
-   END FUNCTION tfreez1D
-
-
-
-   SUBROUTINE eos_init
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE eos_init  ***
-      !!
       !! ** Purpose :   initializations for the equation of state
       !!
       !! ** Method  :   Read the namelist nameos and control the parameters
       !!----------------------------------------------------------------------
-      NAMELIST/nameos/ nn_eos, rn_alpha, rn_beta
-      !!----------------------------------------------------------------------
-      INTEGER  ::   ios
+      INTEGER  ::   ios   ! local integer
+      !!
+      NAMELIST/nameos/ nn_eos, ln_useCT, rn_a0, rn_b0, rn_lambda1, rn_mu1,   &
+         &                                             rn_lambda2, rn_mu2, rn_nu
+      !!----------------------------------------------------------------------
       !
       REWIND( numnam_ref )              ! Namelist nameos in reference namelist : equation of state
       READ  ( numnam_ref, nameos, IOSTAT = ios, ERR = 901 )
 901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nameos in reference namelist', lwp )
-
+      !
       REWIND( numnam_cfg )              ! Namelist nameos in configuration namelist : equation of state
       READ  ( numnam_cfg, nameos, IOSTAT = ios, ERR = 902 )
 902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nameos in configuration namelist', lwp )
-      IF(lwm) WRITE( numond, nameos )
+      WRITE( numond, nameos )
+      !
+      rau0        = 1026._wp                 !: volumic mass of reference     [kg/m3]
+      rcp         = 3991.86795711963_wp      !: heat capacity     [J/K]
       !
       IF(lwp) THEN                ! Control print
@@ -760,25 +1180,406 @@
          WRITE(numout,*) '          Namelist nameos : set eos parameters'
          WRITE(numout,*) '             flag for eq. of state and N^2  nn_eos   = ', nn_eos
-         WRITE(numout,*) '             thermal exp. coef. (linear)    rn_alpha = ', rn_alpha
-         WRITE(numout,*) '             saline  exp. coef. (linear)    rn_beta  = ', rn_beta
+         IF( ln_useCT )   THEN
+            WRITE(numout,*) '             model uses Conservative Temperature'
+            WRITE(numout,*) '             Important: model must be initialized with CT and SA fields'
+         ENDIF
       ENDIF
       !
       SELECT CASE( nn_eos )         ! check option
       !
-      CASE( 0 )                        !==  Jackett and McDougall (1994) formulation  ==!
+      CASE( -1 )                       !==  polynomial TEOS-10  ==!
          IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) '          use of Jackett & McDougall (1994) equation of state and'
-         IF(lwp) WRITE(numout,*) '                 McDougall (1987) Brunt-Vaisala frequency'
-         !
-      CASE( 1 )                        !==  Linear formulation = F( temperature )  ==!
+         IF(lwp) WRITE(numout,*) '          use of TEOS-10 equation of state (cons. temp. and abs. salinity)'
+         !
+         rdeltaS = 32._wp
+         r1_S0  = 0.875_wp/35.16504_wp
+         r1_T0  = 1._wp/40._wp
+         r1_Z0  = 1.e-4_wp
+         !
+         EOS000 = 8.0189615746e+02_wp
+         EOS100 = 8.6672408165e+02_wp
+         EOS200 = -1.7864682637e+03_wp
+         EOS300 = 2.0375295546e+03_wp
+         EOS400 = -1.2849161071e+03_wp
+         EOS500 = 4.3227585684e+02_wp
+         EOS600 = -6.0579916612e+01_wp
+         EOS010 = 2.6010145068e+01_wp
+         EOS110 = -6.5281885265e+01_wp
+         EOS210 = 8.1770425108e+01_wp
+         EOS310 = -5.6888046321e+01_wp
+         EOS410 = 1.7681814114e+01_wp
+         EOS510 = -1.9193502195_wp
+         EOS020 = -3.7074170417e+01_wp
+         EOS120 = 6.1548258127e+01_wp
+         EOS220 = -6.0362551501e+01_wp
+         EOS320 = 2.9130021253e+01_wp
+         EOS420 = -5.4723692739_wp
+         EOS030 = 2.1661789529e+01_wp
+         EOS130 = -3.3449108469e+01_wp
+         EOS230 = 1.9717078466e+01_wp
+         EOS330 = -3.1742946532_wp
+         EOS040 = -8.3627885467_wp
+         EOS140 = 1.1311538584e+01_wp
+         EOS240 = -5.3563304045_wp
+         EOS050 = 5.4048723791e-01_wp
+         EOS150 = 4.8169980163e-01_wp
+         EOS060 = -1.9083568888e-01_wp
+         EOS001 = 1.9681925209e+01_wp
+         EOS101 = -4.2549998214e+01_wp
+         EOS201 = 5.0774768218e+01_wp
+         EOS301 = -3.0938076334e+01_wp
+         EOS401 = 6.6051753097_wp
+         EOS011 = -1.3336301113e+01_wp
+         EOS111 = -4.4870114575_wp
+         EOS211 = 5.0042598061_wp
+         EOS311 = -6.5399043664e-01_wp
+         EOS021 = 6.7080479603_wp
+         EOS121 = 3.5063081279_wp
+         EOS221 = -1.8795372996_wp
+         EOS031 = -2.4649669534_wp
+         EOS131 = -5.5077101279e-01_wp
+         EOS041 = 5.5927935970e-01_wp
+         EOS002 = 2.0660924175_wp
+         EOS102 = -4.9527603989_wp
+         EOS202 = 2.5019633244_wp
+         EOS012 = 2.0564311499_wp
+         EOS112 = -2.1311365518e-01_wp
+         EOS022 = -1.2419983026_wp
+         EOS003 = -2.3342758797e-02_wp
+         EOS103 = -1.8507636718e-02_wp
+         EOS013 = 3.7969820455e-01_wp
+         !
+         ALP000 = -6.5025362670e-01_wp
+         ALP100 = 1.6320471316_wp
+         ALP200 = -2.0442606277_wp
+         ALP300 = 1.4222011580_wp
+         ALP400 = -4.4204535284e-01_wp
+         ALP500 = 4.7983755487e-02_wp
+         ALP010 = 1.8537085209_wp
+         ALP110 = -3.0774129064_wp
+         ALP210 = 3.0181275751_wp
+         ALP310 = -1.4565010626_wp
+         ALP410 = 2.7361846370e-01_wp
+         ALP020 = -1.6246342147_wp
+         ALP120 = 2.5086831352_wp
+         ALP220 = -1.4787808849_wp
+         ALP320 = 2.3807209899e-01_wp
+         ALP030 = 8.3627885467e-01_wp
+         ALP130 = -1.1311538584_wp
+         ALP230 = 5.3563304045e-01_wp
+         ALP040 = -6.7560904739e-02_wp
+         ALP140 = -6.0212475204e-02_wp
+         ALP050 = 2.8625353333e-02_wp
+         ALP001 = 3.3340752782e-01_wp
+         ALP101 = 1.1217528644e-01_wp
+         ALP201 = -1.2510649515e-01_wp
+         ALP301 = 1.6349760916e-02_wp
+         ALP011 = -3.3540239802e-01_wp
+         ALP111 = -1.7531540640e-01_wp
+         ALP211 = 9.3976864981e-02_wp
+         ALP021 = 1.8487252150e-01_wp
+         ALP121 = 4.1307825959e-02_wp
+         ALP031 = -5.5927935970e-02_wp
+         ALP002 = -5.1410778748e-02_wp
+         ALP102 = 5.3278413794e-03_wp
+         ALP012 = 6.2099915132e-02_wp
+         ALP003 = -9.4924551138e-03_wp
+         !
+         BET000 = 1.0783203594e+01_wp
+         BET100 = -4.4452095908e+01_wp
+         BET200 = 7.6048755820e+01_wp
+         BET300 = -6.3944280668e+01_wp
+         BET400 = 2.6890441098e+01_wp
+         BET500 = -4.5221697773_wp
+         BET010 = -8.1219372432e-01_wp
+         BET110 = 2.0346663041_wp
+         BET210 = -2.1232895170_wp
+         BET310 = 8.7994140485e-01_wp
+         BET410 = -1.1939638360e-01_wp
+         BET020 = 7.6574242289e-01_wp
+         BET120 = -1.5019813020_wp
+         BET220 = 1.0872489522_wp
+         BET320 = -2.7233429080e-01_wp
+         BET030 = -4.1615152308e-01_wp
+         BET130 = 4.9061350869e-01_wp
+         BET230 = -1.1847737788e-01_wp
+         BET040 = 1.4073062708e-01_wp
+         BET140 = -1.3327978879e-01_wp
+         BET050 = 5.9929880134e-03_wp
+         BET001 = -5.2937873009e-01_wp
+         BET101 = 1.2634116779_wp
+         BET201 = -1.1547328025_wp
+         BET301 = 3.2870876279e-01_wp
+         BET011 = -5.5824407214e-02_wp
+         BET111 = 1.2451933313e-01_wp
+         BET211 = -2.4409539932e-02_wp
+         BET021 = 4.3623149752e-02_wp
+         BET121 = -4.6767901790e-02_wp
+         BET031 = -6.8523260060e-03_wp
+         BET002 = -6.1618945251e-02_wp
+         BET102 = 6.2255521644e-02_wp
+         BET012 = -2.6514181169e-03_wp
+         BET003 = -2.3025968587e-04_wp
+         !
+         PEN000 = -9.8409626043_wp
+         PEN100 = 2.1274999107e+01_wp
+         PEN200 = -2.5387384109e+01_wp
+         PEN300 = 1.5469038167e+01_wp
+         PEN400 = -3.3025876549_wp
+         PEN010 = 6.6681505563_wp
+         PEN110 = 2.2435057288_wp
+         PEN210 = -2.5021299030_wp
+         PEN310 = 3.2699521832e-01_wp
+         PEN020 = -3.3540239802_wp
+         PEN120 = -1.7531540640_wp
+         PEN220 = 9.3976864981e-01_wp
+         PEN030 = 1.2324834767_wp
+         PEN130 = 2.7538550639e-01_wp
+         PEN040 = -2.7963967985e-01_wp
+         PEN001 = -1.3773949450_wp
+         PEN101 = 3.3018402659_wp
+         PEN201 = -1.6679755496_wp
+         PEN011 = -1.3709540999_wp
+         PEN111 = 1.4207577012e-01_wp
+         PEN021 = 8.2799886843e-01_wp
+         PEN002 = 1.7507069098e-02_wp
+         PEN102 = 1.3880727538e-02_wp
+         PEN012 = -2.8477365341e-01_wp
+         !
+         APE000 = -1.6670376391e-01_wp
+         APE100 = -5.6087643219e-02_wp
+         APE200 = 6.2553247576e-02_wp
+         APE300 = -8.1748804580e-03_wp
+         APE010 = 1.6770119901e-01_wp
+         APE110 = 8.7657703198e-02_wp
+         APE210 = -4.6988432490e-02_wp
+         APE020 = -9.2436260751e-02_wp
+         APE120 = -2.0653912979e-02_wp
+         APE030 = 2.7963967985e-02_wp
+         APE001 = 3.4273852498e-02_wp
+         APE101 = -3.5518942529e-03_wp
+         APE011 = -4.1399943421e-02_wp
+         APE002 = 7.1193413354e-03_wp
+         !
+         BPE000 = 2.6468936504e-01_wp
+         BPE100 = -6.3170583896e-01_wp
+         BPE200 = 5.7736640125e-01_wp
+         BPE300 = -1.6435438140e-01_wp
+         BPE010 = 2.7912203607e-02_wp
+         BPE110 = -6.2259666565e-02_wp
+         BPE210 = 1.2204769966e-02_wp
+         BPE020 = -2.1811574876e-02_wp
+         BPE120 = 2.3383950895e-02_wp
+         BPE030 = 3.4261630030e-03_wp
+         BPE001 = 4.1079296834e-02_wp
+         BPE101 = -4.1503681096e-02_wp
+         BPE011 = 1.7676120780e-03_wp
+         BPE002 = 1.7269476440e-04_wp
+         !
+      CASE( 0 )                        !==  polynomial EOS-80 formulation  ==!
+         !
          IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) '          use of linear eos rho(T) = rau0 * ( 1.0285 - rn_alpha * T )'
-         IF( lk_zdfddm ) CALL ctl_stop( '          double diffusive mixing parameterization requires',   &
-              &                         ' that T and S are used as state variables' )
-         !
-      CASE( 2 )                        !==  Linear formulation = F( temperature , salinity )  ==!
-         ralpbet = rn_alpha / rn_beta
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) '          use of linear eos rho(T,S) = rau0 * ( rn_beta * S - rn_alpha * T )'
+         IF(lwp) WRITE(numout,*) '          use of EOS-80 equation of state (pot. temp. and pract. salinity)'
+         !
+         rdeltaS = 20._wp
+         r1_S0  = 1._wp/40._wp
+         r1_T0  = 1._wp/40._wp
+         r1_Z0  = 1.e-4_wp
+         !
+         EOS000 = 9.5356891948e+02_wp
+         EOS100 = 1.7136499189e+02_wp
+         EOS200 = -3.7501039454e+02_wp
+         EOS300 = 5.1856810420e+02_wp
+         EOS400 = -3.7264470465e+02_wp
+         EOS500 = 1.4302533998e+02_wp
+         EOS600 = -2.2856621162e+01_wp
+         EOS010 = 1.0087518651e+01_wp
+         EOS110 = -1.3647741861e+01_wp
+         EOS210 = 8.8478359933_wp
+         EOS310 = -7.2329388377_wp
+         EOS410 = 1.4774410611_wp
+         EOS510 = 2.0036720553e-01_wp
+         EOS020 = -2.5579830599e+01_wp
+         EOS120 = 2.4043512327e+01_wp
+         EOS220 = -1.6807503990e+01_wp
+         EOS320 = 8.3811577084_wp
+         EOS420 = -1.9771060192_wp
+         EOS030 = 1.6846451198e+01_wp
+         EOS130 = -2.1482926901e+01_wp
+         EOS230 = 1.0108954054e+01_wp
+         EOS330 = -6.2675951440e-01_wp
+         EOS040 = -8.0812310102_wp
+         EOS140 = 1.0102374985e+01_wp
+         EOS240 = -4.8340368631_wp
+         EOS050 = 1.2079167803_wp
+         EOS150 = 1.1515380987e-01_wp
+         EOS060 = -2.4520288837e-01_wp
+         EOS001 = 1.0748601068e+01_wp
+         EOS101 = -1.7817043500e+01_wp
+         EOS201 = 2.2181366768e+01_wp
+         EOS301 = -1.6750916338e+01_wp
+         EOS401 = 4.1202230403_wp
+         EOS011 = -1.5852644587e+01_wp
+         EOS111 = -7.6639383522e-01_wp
+         EOS211 = 4.1144627302_wp
+         EOS311 = -6.6955877448e-01_wp
+         EOS021 = 9.9994861860_wp
+         EOS121 = -1.9467067787e-01_wp
+         EOS221 = -1.2177554330_wp
+         EOS031 = -3.4866102017_wp
+         EOS131 = 2.2229155620e-01_wp
+         EOS041 = 5.9503008642e-01_wp
+         EOS002 = 1.0375676547_wp
+         EOS102 = -3.4249470629_wp
+         EOS202 = 2.0542026429_wp
+         EOS012 = 2.1836324814_wp
+         EOS112 = -3.4453674320e-01_wp
+         EOS022 = -1.2548163097_wp
+         EOS003 = 1.8729078427e-02_wp
+         EOS103 = -5.7238495240e-02_wp
+         EOS013 = 3.8306136687e-01_wp
+         !
+         ALP000 = -2.5218796628e-01_wp
+         ALP100 = 3.4119354654e-01_wp
+         ALP200 = -2.2119589983e-01_wp
+         ALP300 = 1.8082347094e-01_wp
+         ALP400 = -3.6936026529e-02_wp
+         ALP500 = -5.0091801383e-03_wp
+         ALP010 = 1.2789915300_wp
+         ALP110 = -1.2021756164_wp
+         ALP210 = 8.4037519952e-01_wp
+         ALP310 = -4.1905788542e-01_wp
+         ALP410 = 9.8855300959e-02_wp
+         ALP020 = -1.2634838399_wp
+         ALP120 = 1.6112195176_wp
+         ALP220 = -7.5817155402e-01_wp
+         ALP320 = 4.7006963580e-02_wp
+         ALP030 = 8.0812310102e-01_wp
+         ALP130 = -1.0102374985_wp
+         ALP230 = 4.8340368631e-01_wp
+         ALP040 = -1.5098959754e-01_wp
+         ALP140 = -1.4394226233e-02_wp
+         ALP050 = 3.6780433255e-02_wp
+         ALP001 = 3.9631611467e-01_wp
+         ALP101 = 1.9159845880e-02_wp
+         ALP201 = -1.0286156825e-01_wp
+         ALP301 = 1.6738969362e-02_wp
+         ALP011 = -4.9997430930e-01_wp
+         ALP111 = 9.7335338937e-03_wp
+         ALP211 = 6.0887771651e-02_wp
+         ALP021 = 2.6149576513e-01_wp
+         ALP121 = -1.6671866715e-02_wp
+         ALP031 = -5.9503008642e-02_wp
+         ALP002 = -5.4590812035e-02_wp
+         ALP102 = 8.6134185799e-03_wp
+         ALP012 = 6.2740815484e-02_wp
+         ALP003 = -9.5765341718e-03_wp
+         !
+         BET000 = 2.1420623987_wp
+         BET100 = -9.3752598635_wp
+         BET200 = 1.9446303907e+01_wp
+         BET300 = -1.8632235232e+01_wp
+         BET400 = 8.9390837485_wp
+         BET500 = -1.7142465871_wp
+         BET010 = -1.7059677327e-01_wp
+         BET110 = 2.2119589983e-01_wp
+         BET210 = -2.7123520642e-01_wp
+         BET310 = 7.3872053057e-02_wp
+         BET410 = 1.2522950346e-02_wp
+         BET020 = 3.0054390409e-01_wp
+         BET120 = -4.2018759976e-01_wp
+         BET220 = 3.1429341406e-01_wp
+         BET320 = -9.8855300959e-02_wp
+         BET030 = -2.6853658626e-01_wp
+         BET130 = 2.5272385134e-01_wp
+         BET230 = -2.3503481790e-02_wp
+         BET040 = 1.2627968731e-01_wp
+         BET140 = -1.2085092158e-01_wp
+         BET050 = 1.4394226233e-03_wp
+         BET001 = -2.2271304375e-01_wp
+         BET101 = 5.5453416919e-01_wp
+         BET201 = -6.2815936268e-01_wp
+         BET301 = 2.0601115202e-01_wp
+         BET011 = -9.5799229402e-03_wp
+         BET111 = 1.0286156825e-01_wp
+         BET211 = -2.5108454043e-02_wp
+         BET021 = -2.4333834734e-03_wp
+         BET121 = -3.0443885826e-02_wp
+         BET031 = 2.7786444526e-03_wp
+         BET002 = -4.2811838287e-02_wp
+         BET102 = 5.1355066072e-02_wp
+         BET012 = -4.3067092900e-03_wp
+         BET003 = -7.1548119050e-04_wp
+         !
+         PEN000 = -5.3743005340_wp
+         PEN100 = 8.9085217499_wp
+         PEN200 = -1.1090683384e+01_wp
+         PEN300 = 8.3754581690_wp
+         PEN400 = -2.0601115202_wp
+         PEN010 = 7.9263222935_wp
+         PEN110 = 3.8319691761e-01_wp
+         PEN210 = -2.0572313651_wp
+         PEN310 = 3.3477938724e-01_wp
+         PEN020 = -4.9997430930_wp
+         PEN120 = 9.7335338937e-02_wp
+         PEN220 = 6.0887771651e-01_wp
+         PEN030 = 1.7433051009_wp
+         PEN130 = -1.1114577810e-01_wp
+         PEN040 = -2.9751504321e-01_wp
+         PEN001 = -6.9171176978e-01_wp
+         PEN101 = 2.2832980419_wp
+         PEN201 = -1.3694684286_wp
+         PEN011 = -1.4557549876_wp
+         PEN111 = 2.2969116213e-01_wp
+         PEN021 = 8.3654420645e-01_wp
+         PEN002 = -1.4046808820e-02_wp
+         PEN102 = 4.2928871430e-02_wp
+         PEN012 = -2.8729602515e-01_wp
+         !
+         APE000 = -1.9815805734e-01_wp
+         APE100 = -9.5799229402e-03_wp
+         APE200 = 5.1430784127e-02_wp
+         APE300 = -8.3694846809e-03_wp
+         APE010 = 2.4998715465e-01_wp
+         APE110 = -4.8667669469e-03_wp
+         APE210 = -3.0443885826e-02_wp
+         APE020 = -1.3074788257e-01_wp
+         APE120 = 8.3359333577e-03_wp
+         APE030 = 2.9751504321e-02_wp
+         APE001 = 3.6393874690e-02_wp
+         APE101 = -5.7422790533e-03_wp
+         APE011 = -4.1827210323e-02_wp
+         APE002 = 7.1824006288e-03_wp
+         !
+         BPE000 = 1.1135652187e-01_wp
+         BPE100 = -2.7726708459e-01_wp
+         BPE200 = 3.1407968134e-01_wp
+         BPE300 = -1.0300557601e-01_wp
+         BPE010 = 4.7899614701e-03_wp
+         BPE110 = -5.1430784127e-02_wp
+         BPE210 = 1.2554227021e-02_wp
+         BPE020 = 1.2166917367e-03_wp
+         BPE120 = 1.5221942913e-02_wp
+         BPE030 = -1.3893222263e-03_wp
+         BPE001 = 2.8541225524e-02_wp
+         BPE101 = -3.4236710714e-02_wp
+         BPE011 = 2.8711395266e-03_wp
+         BPE002 = 5.3661089288e-04_wp
+         !
+      CASE( 1 )                        !==  Simplified EOS     ==!
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) '          use of simplified eos:    rhd(dT=T-10,dS=S-35,Z) = '
+            WRITE(numout,*) '             [-a0*(1+lambda1/2*dT+mu1*Z)*dT + b0*(1+lambda2/2*dT+mu2*Z)*dS - nu*dT*dS]/rau0'
+            WRITE(numout,*)
+            WRITE(numout,*) '             thermal exp. coef.    rn_a0      = ', rn_a0
+            WRITE(numout,*) '             saline  cont. coef.   rn_b0      = ', rn_b0
+            WRITE(numout,*) '             cabbeling coef.       rn_lambda1 = ', rn_lambda1
+            WRITE(numout,*) '             cabbeling coef.       rn_lambda2 = ', rn_lambda2
+            WRITE(numout,*) '             thermobar. coef.      rn_mu1     = ', rn_mu1
+            WRITE(numout,*) '             thermobar. coef.      rn_mu2     = ', rn_mu2
+            WRITE(numout,*) '             2nd cabbel. coef.     rn_nu      = ', rn_nu
+            WRITE(numout,*) '               Caution: rn_beta0=0 incompatible with ddm parameterization '
+         ENDIF
          !
       CASE DEFAULT                     !==  ERROR in nn_eos  ==!
@@ -788,4 +1589,14 @@
       END SELECT
       !
+      r1_rau0     = 1._wp / rau0
+      r1_rcp      = 1._wp / rcp
+      r1_rau0_rcp = 1._wp / ( rau0 * rcp )
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '          volumic mass of reference           rau0  = ', rau0   , ' kg/m^3'
+      IF(lwp) WRITE(numout,*) '          1. / rau0                        r1_rau0  = ', r1_rau0, ' m^3/kg'
+      IF(lwp) WRITE(numout,*) '          ocean specific heat                 rcp   = ', rcp    , ' J/Kelvin'
+      IF(lwp) WRITE(numout,*) '          1. / ( rau0 * rcp )           r1_rau0_rcp = ', r1_rau0_rcp
+      !
    END SUBROUTINE eos_init
 
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_cen2.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_cen2.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_cen2.F90	(revision 4946)
@@ -4,7 +4,7 @@
    !! Ocean  tracers:  horizontal & vertical advective trend
    !!======================================================================
-   !! History :  8.2  ! 2001-08  (G. Madec, E. Durand)  trahad+trazad=traadv 
-   !!            1.0  ! 2002-06  (G. Madec)  F90: Free form and module
-   !!            9.0  ! 2004-08  (C. Talandier) New trends organization
+   !! History :  OPA  ! 2001-08  (G. Madec, E. Durand) v8.2 trahad+trazad=traadv 
+   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
+   !!             -   ! 2004-08  (C. Talandier) New trends organization
    !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
    !!            2.0  ! 2006-04  (R. Benshila, G. Madec) Step reorganization
@@ -21,6 +21,6 @@
    USE dom_oce         ! ocean space and time domain
    USE eosbn2          ! equation of state
-   USE trdmod_oce      ! tracers trends
-   USE trdtra          ! tracers trends
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
    USE closea          ! closed sea
    USE sbcrnf          ! river runoffs
@@ -38,8 +38,5 @@
    PRIVATE
 
-   PUBLIC   tra_adv_cen2       ! routine called by step.F90
-   PUBLIC   ups_orca_set       ! routine used by traadv_cen2_jki.F90
-
-   LOGICAL  :: l_trd       ! flag to compute trends
+   PUBLIC   tra_adv_cen2   ! routine called by traadv.F90
 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: upsmsk !: mixed upstream/centered scheme near some straits 
@@ -56,5 +53,5 @@
 
    SUBROUTINE tra_adv_cen2( kt, kit000, cdtype, pun, pvn, pwn,     &
-      &                                 ptb, ptn, pta, kjpt   ) 
+      &                                         ptb, ptn, pta, kjpt   ) 
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE tra_adv_cen2  ***
@@ -86,8 +83,7 @@
       !!       * Add this trend now to the general trend of tracer (ta,sa):
       !!               pta = pta + ztra
-      !!       * trend diagnostic ('key_trdtra' defined): the trend is
+      !!       * trend diagnostic (l_trdtra=T or l_trctra=T): the trend is
       !!      saved for diagnostics. The trends saved is expressed as
-      !!      Uh.gradh(T), i.e.
-      !!                     save trend = ztra + ptn divn
+      !!      Uh.gradh(T), i.e.  save trend = ztra + ptn divn
       !!
       !!         Part II : vertical advection
@@ -105,5 +101,5 @@
       !!         Add this trend now to the general trend of tracer (ta,sa):
       !!             pta = pta + ztra
-      !!         Trend diagnostic ('key_trdtra' defined): the trend is
+      !!         Trend diagnostic (l_trdtra=T or l_trctra=T): the trend is
       !!      saved for diagnostics. The trends saved is expressed as :
       !!             save trend =  w.gradz(T) = ztra - ptn divn.
@@ -112,6 +108,4 @@
       !!              - save trends if needed
       !!----------------------------------------------------------------------
-      USE oce     , ONLY:   zwx => ua        , zwy  => va          ! (ua,va) used as 3D workspace
-      !
       INTEGER                              , INTENT(in   ) ::   kt              ! ocean time-step index
       INTEGER                              , INTENT(in   ) ::   kit000          ! first time step index
@@ -122,5 +116,5 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta             ! tracer trend 
       !
-      INTEGER  ::   ji, jj, jk, jn, ik   ! dummy loop indices
+      INTEGER  ::   ji, jj, jk, jn, ikt   ! dummy loop indices
       INTEGER  ::   ierr                 ! local integer
       REAL(wp) ::   zbtr, ztra                            ! local scalars
@@ -129,12 +123,13 @@
       REAL(wp) ::   zupsut, zcenut, zupst                 !   -      -
       REAL(wp) ::   zupsvt, zcenvt, zcent, zice           !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:  ) :: ztfreez, zpress 
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwz, zind
+      REAL(wp), POINTER, DIMENSION(:,:)   :: zfzp, zpres   ! 2D workspace
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwx, zwy     ! 3D     -
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwz, zind    !  -     -
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('tra_adv_cen2')
       !
-      CALL wrk_alloc( jpi, jpj, ztfreez, zpress )
-      CALL wrk_alloc( jpi, jpj, jpk, zwz, zind )
+      CALL wrk_alloc( jpi, jpj, zpres, zfzp )
+      CALL wrk_alloc( jpi, jpj, jpk, zwx, zwy, zwz, zind )
       !
 
@@ -145,5 +140,5 @@
          IF(lwp) WRITE(numout,*)
          !
-         IF ( .NOT. ALLOCATED( upsmsk ) )  THEN
+         IF( .NOT. ALLOCATED( upsmsk ) )  THEN
              ALLOCATE( upsmsk(jpi,jpj), STAT=ierr )
              IF( ierr /= 0 )   CALL ctl_stop('STOP', 'tra_adv_cen2: unable to allocate array')
@@ -163,7 +158,4 @@
       ENDIF
       !
-      l_trd = .FALSE.
-      IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) )   l_trd = .TRUE.
-      !
       ! Upstream / centered scheme indicator
       ! ------------------------------------
@@ -173,20 +165,19 @@
       DO jj = 1, jpj 
          DO ji = 1, jpi 
-            ik=mikt(ji,jj) 
-            IF (ik > 1 ) THEN 
-               zpress(ji,jj) = grav*rau0*fsdept(ji,jj,ik)*1.e-04  
+            ikt = mikt(ji,jj) 
+            IF (ikt > 1 ) THEN 
+               zpres(ji,jj) = grav * rau0 * fsdept(ji,jj,ikt) * 1.e-04  
             ELSE 
-               zpress(ji,jj) = 0.0 
+               zpres(ji,jj) = 0.0 
             ENDIF  
          END DO 
       END DO 
-      ztfreez(:,:) = tfreez( tsn(:,:,1, jp_sal), zpress(:,:) )
-      
+      zfzp(:,:) = eos_fzp( tsn(:,:,1,jp_sal), zpres(:,:) )
       DO jk = 1, jpk
          DO jj = 1, jpj
             DO ji = 1, jpi
                !                                        ! below ice covered area (if tn < "freezing"+0.1 )
-               IF( tsn(ji,jj,jk,jp_tem) <= ztfreez(ji,jj) + 0.1 ) THEN   ;   zice = 1.e0
-               ELSE                                                      ;   zice = 0.e0
+               IF( tsn(ji,jj,jk,jp_tem) <= zfzp(ji,jj) + 0.1 ) THEN   ;   zice = 1._wp
+               ELSE                                                   ;   zice = 0._wp
                ENDIF
                zind(ji,jj,jk) = MAX (   &
@@ -240,7 +231,7 @@
             DO jj = 1, jpj   ! vector opt.
                DO ji = 1, jpi   ! vector opt.
-                  ik=mikt(ji,jj)                
-                  zwz(ji,jj,ik ) = pwn(ji,jj,ik) * ptn(ji,jj,ik,jn)   ! linear free surface 
-                  zwz(ji,jj,1:ik-1) = 0.e0
+                  ikt = mikt(ji,jj)                
+                  zwz(ji,jj,ikt ) = pwn(ji,jj,ikt) * ptn(ji,jj,ikt,jn)   ! linear free surface 
+                  zwz(ji,jj,1:ikt-1) = 0.e0
                END DO
             END DO
@@ -280,17 +271,18 @@
          END DO
 
-         !                                 ! trend diagnostics (contribution of upstream fluxes)
-         IF( l_trd ) THEN
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_xad, zwx, pun, ptn(:,:,:,jn) )
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_yad, zwy, pvn, ptn(:,:,:,jn) )
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_zad, zwz, pwn, ptn(:,:,:,jn) )
+         !                                 ! trend diagnostics
+         IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR.    &
+            &( cdtype == 'TRC' .AND. l_trdtrc ) )   THEN
+            CALL trd_tra( kt, cdtype, jn, jptra_xad, zwx, pun, ptn(:,:,:,jn) )
+            CALL trd_tra( kt, cdtype, jn, jptra_yad, zwy, pvn, ptn(:,:,:,jn) )
+            CALL trd_tra( kt, cdtype, jn, jptra_zad, zwz, pwn, ptn(:,:,:,jn) )
          END IF
          !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
          IF( cdtype == 'TRA' .AND. ln_diaptr .AND. ( MOD( kt, nn_fptr ) == 0 ) ) THEN  
-           IF( jn == jp_tem )  htr_adv(:) = ptr_vj( zwy(:,:,:) )
-           IF( jn == jp_sal )  str_adv(:) = ptr_vj( zwy(:,:,:) )
+           IF( jn == jp_tem )   htr_adv(:) = ptr_vj( zwy(:,:,:) )
+           IF( jn == jp_sal )   str_adv(:) = ptr_vj( zwy(:,:,:) )
          ENDIF
          !
-      ENDDO
+      END DO
 
       ! ---------------------------  required in restart file to ensure restartability)
@@ -301,6 +293,6 @@
       ENDIF
       !
-      CALL wrk_dealloc( jpi, jpj, ztfreez, zpress )
-      CALL wrk_dealloc( jpi, jpj, jpk, zwz, zind )
+      CALL wrk_dealloc( jpi, jpj, zpres, zfzp )
+      CALL wrk_dealloc( jpi, jpj, jpk, zwx, zwy, zwz, zind )
       !
       IF( nn_timing == 1 )  CALL timing_stop('tra_adv_cen2')
@@ -323,5 +315,4 @@
       INTEGER  ::   ii0, ii1, ij0, ij1      ! temporary integers
       !!----------------------------------------------------------------------
-      
       !
       IF( nn_timing == 1 )  CALL timing_start('ups_orca_set')
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_muscl.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_muscl.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_muscl.F90	(revision 4946)
@@ -16,29 +16,28 @@
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and active tracers
+   USE trc_oce        ! share passive tracers/Ocean variables
    USE dom_oce        ! ocean space and time domain
-   USE trdmod_oce     ! tracers trends 
-   USE trdtra         ! tracers trends 
-   USE in_out_manager ! I/O manager
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! tracers trends manager
    USE dynspg_oce     ! choice/control of key cpp for surface pressure gradient
-   USE trabbl         ! tracers: bottom boundary layer
-   USE lib_mpp        ! distribued memory computing
-   USE lbclnk         ! ocean lateral boundary condition (or mpp link) 
+   USE sbcrnf          ! river runoffs
    USE diaptr         ! poleward transport diagnostics
-   USE trc_oce        ! share passive tracers/Ocean variables
+   !
    USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE eosbn2          ! equation of state
-   USE sbcrnf          ! river runoffs
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! distribued memory computing
+   USE lbclnk         ! ocean lateral boundary condition (or mpp link) 
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   tra_adv_muscl  ! routine called by step.F90
-
-   LOGICAL  :: l_trd                        ! flag to compute trends
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) :: upsmsk !: mixed upstream/centered scheme near some straits
-   !                                                             !  and in closed seas (orca 2 and 4 configurations)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: xind         !: mixed upstream/centered index
+   PUBLIC   tra_adv_muscl   ! routine called by traadv.F90
+   
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   upsmsk   !: mixed upstream/centered scheme near some straits
+   !                                                           !  and in closed seas (orca 2 and 4 configurations)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   xind     !: mixed upstream/centered index
+   
    !! * Substitutions
 #  include "domzgr_substitute.h90"
@@ -51,6 +50,6 @@
 CONTAINS
 
-   SUBROUTINE tra_adv_muscl( kt, kit000, cdtype, p2dt, pun, pvn, pwn, &
-      &                                        ptb, pta, kjpt, ld_msc_ups )
+   SUBROUTINE tra_adv_muscl( kt, kit000, cdtype, p2dt, pun, pvn, pwn,   &
+      &                                                ptb, pta, kjpt, ld_msc_ups )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE tra_adv_muscl  ***
@@ -68,6 +67,4 @@
       !!              IPSL, Sept. 2000 (http://www.lodyc.jussieu.fr/opa)
       !!----------------------------------------------------------------------
-      USE oce     , ONLY:   zwx   => ua    , zwy   => va          ! (ua,va) used as workspace
-      !
       INTEGER                              , INTENT(in   ) ::   kt              ! ocean time-step index
       INTEGER                              , INTENT(in   ) ::   kit000          ! first time step index
@@ -79,19 +76,18 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb             ! before tracer field
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta             ! tracer trend 
-
-      !
-      INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
+      !
+      INTEGER  ::   ji, jj, jk, jn            ! dummy loop indices
+      INTEGER  ::   ierr                      ! local integer
       REAL(wp) ::   zu, z0u, zzwx, zw         ! local scalars
       REAL(wp) ::   zv, z0v, zzwy, z0w        !   -      -
       REAL(wp) ::   ztra, zbtr, zdt, zalpha   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zslpx, zslpy
-      INTEGER  ::   ierr
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zslpx, zslpy   ! 3D workspace
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zwx  , zwy     ! -      - 
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('tra_adv_muscl')
       !
-      CALL wrk_alloc( jpi, jpj, jpk, zslpx, zslpy )
-      !
-
+      CALL wrk_alloc( jpi, jpj, jpk, zslpx, zslpy, zwx, zwy )
+      !
       IF( kt == kit000 )  THEN
          IF(lwp) WRITE(numout,*)
@@ -117,25 +113,20 @@
 
          !
-         ! Upstream / centered scheme indicator
+         ! Upstream / MUSCL scheme indicator
          ! ------------------------------------
+!!gm  useless
          xind(:,:,:) = 1._wp                             ! set equal to 1 where up-stream is not needed
+!!gm
          !
          IF( ld_msc_ups )  THEN
-            DO jk = 1, jpk
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     xind(ji,jj,jk) = 1  - MAX (           &
-                        rnfmsk(ji,jj) * rnfmsk_z(jk),      &  ! near runoff mouths (& closed sea outflows)
-                        upsmsk(ji,jj) ) * tmask(ji,jj,jk)     ! some of some straits
-                  END DO
-               END DO
+            DO jk = 1, jpkm1
+               xind(:,:,jk) = 1._wp                              &                 ! =>1 where up-stream is not needed
+                  &         - MAX ( rnfmsk(:,:) * rnfmsk_z(jk),  &                 ! =>0 near runoff mouths (& closed sea outflows)
+                  &                 upsmsk(:,:)                ) * tmask(:,:,jk)   ! =>0 near some straits
             END DO
          ENDIF 
          !
       ENDIF 
-      !
-      l_trd = .FALSE.
-      IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) ) l_trd = .TRUE.
-      
+      !      
       !                                                     ! ===========
       DO jn = 1, kjpt                                       ! tracer loop
@@ -192,6 +183,6 @@
                   zalpha = 0.5 - z0u
                   zu  = z0u - 0.5 * pun(ji,jj,jk) * zdt / ( e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) )
-                  zzwx = ptb(ji+1,jj,jk,jn) + xind(ji,jj,jk) * (zu * zslpx(ji+1,jj,jk))
-                  zzwy = ptb(ji  ,jj,jk,jn) + xind(ji,jj,jk) * (zu * zslpx(ji  ,jj,jk))
+                  zzwx = ptb(ji+1,jj,jk,jn) + xind(ji,jj,jk) * zu * zslpx(ji+1,jj,jk)
+                  zzwy = ptb(ji  ,jj,jk,jn) + xind(ji,jj,jk) * zu * zslpx(ji  ,jj,jk)
                   zwx(ji,jj,jk) = pun(ji,jj,jk) * ( zalpha * zzwx + (1.-zalpha) * zzwy )
                   !
@@ -199,6 +190,6 @@
                   zalpha = 0.5 - z0v
                   zv  = z0v - 0.5 * pvn(ji,jj,jk) * zdt / ( e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) )
-                  zzwx = ptb(ji,jj+1,jk,jn) + xind(ji,jj,jk) * (zv * zslpy(ji,jj+1,jk))
-                  zzwy = ptb(ji,jj  ,jk,jn) + xind(ji,jj,jk) * (zv * zslpy(ji,jj  ,jk))
+                  zzwx = ptb(ji,jj+1,jk,jn) + xind(ji,jj,jk) * zv * zslpy(ji,jj+1,jk)
+                  zzwy = ptb(ji,jj  ,jk,jn) + xind(ji,jj,jk) * zv * zslpy(ji,jj  ,jk)
                   zwy(ji,jj,jk) = pvn(ji,jj,jk) * ( zalpha * zzwx + (1.-zalpha) * zzwy )
                END DO
@@ -222,7 +213,8 @@
          END DO        
          !                                 ! trend diagnostics (contribution of upstream fluxes)
-         IF( l_trd )  THEN
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_xad, zwx, pun, ptb(:,:,:,jn) )
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_yad, zwy, pvn, ptb(:,:,:,jn) )
+         IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR.   &
+            &( cdtype == 'TRC' .AND. l_trdtrc )      )  THEN
+            CALL trd_tra( kt, cdtype, jn, jptra_xad, zwx, pun, ptb(:,:,:,jn) )
+            CALL trd_tra( kt, cdtype, jn, jptra_yad, zwy, pvn, ptb(:,:,:,jn) )
          END IF
          !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
@@ -274,6 +266,6 @@
                   zalpha = 0.5 + z0w
                   zw  = z0w - 0.5 * pwn(ji,jj,jk+1) * zdt * zbtr 
-                  zzwx = ptb(ji,jj,jk+1,jn) + xind(ji,jj,jk) * (zw * zslpx(ji,jj,jk+1))
-                  zzwy = ptb(ji,jj,jk  ,jn) + xind(ji,jj,jk) * (zw * zslpx(ji,jj,jk  ))
+                  zzwx = ptb(ji,jj,jk+1,jn) + xind(ji,jj,jk) * zw * zslpx(ji,jj,jk+1)
+                  zzwy = ptb(ji,jj,jk  ,jn) + xind(ji,jj,jk) * zw * zslpx(ji,jj,jk  )
                   zwx(ji,jj,jk+1) = pwn(ji,jj,jk+1) * ( zalpha * zzwx + (1.-zalpha) * zzwy )
                END DO 
@@ -281,9 +273,8 @@
          END DO
 
-         ! Compute & add the vertical advective trend
-         DO jk = 1, jpkm1
+         DO jk = 1, jpkm1                    ! Compute & add the vertical advective trend
             DO jj = 2, jpjm1      
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  zbtr = 1. / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
                   ! vertical advective trends 
                   ztra = - zbtr * ( zwx(ji,jj,jk) - zwx(ji,jj,jk+1) )
@@ -294,9 +285,11 @@
          END DO
          !                                 ! Save the vertical advective trends for diagnostic
-         IF( l_trd ) CALL trd_tra( kt, cdtype, jn, jptra_trd_zad, zwx, pwn, ptb(:,:,:,jn) )
-         !
-      ENDDO
-      !
-      CALL wrk_dealloc( jpi, jpj, jpk, zslpx, zslpy )
+         IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR.     &
+            &( cdtype == 'TRC' .AND. l_trdtrc )      )   &
+            CALL trd_tra( kt, cdtype, jn, jptra_zad, zwx, pwn, ptb(:,:,:,jn) )
+         !
+      END DO
+      !
+      CALL wrk_dealloc( jpi, jpj, jpk, zslpx, zslpy, zwx, zwy )
       !
       IF( nn_timing == 1 )  CALL timing_stop('tra_adv_muscl')
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_muscl2.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_muscl2.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_muscl2.F90	(revision 4946)
@@ -13,14 +13,14 @@
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and active tracers
+   USE trc_oce         ! share passive tracers/Ocean variables
    USE dom_oce         ! ocean space and time domain
-   USE trdmod_oce      ! tracers trends 
-   USE trdtra          ! tracers trends 
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
    USE in_out_manager  ! I/O manager
    USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
-   USE trabbl          ! tracers: bottom boundary layer
+   USE diaptr          ! poleward transport diagnostics
+   !
    USE lib_mpp         ! distribued memory computing
    USE lbclnk          ! ocean lateral boundary condition (or mpp link) 
-   USE diaptr          ! poleward transport diagnostics
-   USE trc_oce         ! share passive tracers/Ocean variables
    USE wrk_nemo        ! Memory Allocation
    USE timing          ! Timing
@@ -31,6 +31,4 @@
 
    PUBLIC   tra_adv_muscl2        ! routine called by step.F90
-
-   LOGICAL  :: l_trd       ! flag to compute trends
 
    !! * Substitutions
@@ -61,6 +59,4 @@
       !!              IPSL, Sept. 2000 (http://www.lodyc.jussieu.fr/opa)
       !!----------------------------------------------------------------------
-      USE oce     , ONLY:   zwx   => ua    , zwy   => va         ! (ua,va) used as 3D workspace
-      !!
       INTEGER                              , INTENT(in   ) ::   kt              ! ocean time-step index
       INTEGER                              , INTENT(in   ) ::   kit000          ! first time step index
@@ -76,10 +72,10 @@
       REAL(wp) ::   zv, z0v, zzwy, z0w        !   -      -
       REAL(wp) ::   ztra, zbtr, zdt, zalpha   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zslpx, zslpy
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zslpx, zslpy , zwx, zwy
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('tra_adv_muscl2')
       !
-      CALL wrk_alloc( jpi, jpj, jpk, zslpx, zslpy )
+      CALL wrk_alloc( jpi, jpj, jpk, zslpx, zslpy, zwx, zwy )
       !
 
@@ -90,7 +86,4 @@
       ENDIF
       !
-      l_trd = .FALSE.
-      IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) )   l_trd = .TRUE.
-
       !                                                          ! ===========
       DO jn = 1, kjpt                                            ! tracer loop
@@ -200,7 +193,8 @@
          END DO
          !                                 ! trend diagnostics (contribution of upstream fluxes)
-         IF( l_trd ) THEN
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_xad, zwx, pun, ptb(:,:,:,jn) )
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_yad, zwy, pvn, ptb(:,:,:,jn) )
+         IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR.   &
+            &( cdtype == 'TRC' .AND. l_trdtrc )      ) THEN
+            CALL trd_tra( kt, cdtype, jn, jptra_xad, zwx, pun, ptb(:,:,:,jn) )
+            CALL trd_tra( kt, cdtype, jn, jptra_yad, zwy, pvn, ptb(:,:,:,jn) )
          END IF
 
@@ -284,9 +278,11 @@
          END DO
          !                       ! trend diagnostics (contribution of upstream fluxes)
-         IF( l_trd )  CALL trd_tra( kt, cdtype, jn, jptra_trd_zad, zwx, pwn, ptb(:,:,:,jn) )
+         IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR.     &
+            &( cdtype == 'TRC' .AND. l_trdtrc )      )   &
+            CALL trd_tra( kt, cdtype, jn, jptra_zad, zwx, pwn, ptb(:,:,:,jn) )
          !
       END DO
       !
-      CALL wrk_dealloc( jpi, jpj, jpk, zslpx, zslpy )
+      CALL wrk_dealloc( jpi, jpj, jpk, zslpx, zslpy, zwx, zwy )
       !
       IF( nn_timing == 1 )  CALL timing_stop('tra_adv_muscl2')
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_qck.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_qck.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_qck.F90	(revision 4946)
@@ -17,13 +17,13 @@
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
-   USE trdmod_oce      ! ocean space and time domain
-   USE trdtra          ! ocean tracers trends 
-   USE trabbl          ! advective term in the BBL
+   USE trc_oce         ! share passive tracers/Ocean variables
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
+   USE dynspg_oce      ! surface pressure gradient variables
+   USE diaptr          ! poleward transport diagnostics
+   !
    USE lib_mpp         ! distribued memory computing
    USE lbclnk          ! ocean lateral boundary condition (or mpp link)
-   USE dynspg_oce      ! surface pressure gradient variables
    USE in_out_manager  ! I/O manager
-   USE diaptr          ! poleward transport diagnostics
-   USE trc_oce         ! share passive tracers/Ocean variables
    USE wrk_nemo        ! Memory Allocation
    USE timing          ! Timing
@@ -93,5 +93,4 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta             ! tracer trend 
       !!----------------------------------------------------------------------
-
       !
       IF( nn_timing == 1 )  CALL timing_start('tra_adv_qck')
@@ -103,8 +102,7 @@
          IF(lwp) WRITE(numout,*)
       ENDIF
-      !
       l_trd = .FALSE.
-      IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) ) l_trd = .TRUE.
-
+      IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) )   l_trd = .TRUE.
+      !
       ! I. The horizontal fluxes are computed with the QUICKEST + ULTIMATE scheme
       CALL tra_adv_qck_i( kt, cdtype, p2dt, pun, ptb, ptn, pta, kjpt ) 
@@ -124,6 +122,4 @@
       !!
       !!----------------------------------------------------------------------
-      USE oce     , ONLY:   zwx => ua       ! ua used as workspace
-      !
       INTEGER                              , INTENT(in   ) ::   kt         ! ocean time-step index
       CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype     ! =TRA or TRC (tracer indicator)
@@ -136,8 +132,8 @@
       INTEGER  :: ji, jj, jk, jn   ! dummy loop indices
       REAL(wp) :: ztra, zbtr, zdir, zdx, zdt, zmsk   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zfu, zfc, zfd
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwx, zfu, zfc, zfd
       !----------------------------------------------------------------------
       !
-      CALL wrk_alloc( jpi, jpj, jpk, zfu, zfc, zfd )
+      CALL wrk_alloc( jpi, jpj, jpk, zwx, zfu, zfc, zfd )
       !                                                          ! ===========
       DO jn = 1, kjpt                                            ! tracer loop
@@ -233,9 +229,9 @@
          END DO
          !                                 ! trend diagnostics (contribution of upstream fluxes)
-         IF( l_trd )  CALL trd_tra( kt, cdtype, jn, jptra_trd_xad, zwx, pun, ptn(:,:,:,jn) )
+         IF( l_trd )   CALL trd_tra( kt, cdtype, jn, jptra_xad, zwx, pun, ptn(:,:,:,jn) )
          !
       END DO
       !
-      CALL wrk_dealloc( jpi, jpj, jpk, zfu, zfc, zfd )
+      CALL wrk_dealloc( jpi, jpj, jpk, zwx, zfu, zfc, zfd )
       !
    END SUBROUTINE tra_adv_qck_i
@@ -247,6 +243,4 @@
       !!
       !!----------------------------------------------------------------------
-      USE oce     , ONLY:   zwy => ua       ! ua used as workspace
-      !
       INTEGER                              , INTENT(in   ) ::   kt         ! ocean time-step index
       CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype     ! =TRA or TRC (tracer indicator)
@@ -259,8 +253,8 @@
       INTEGER  :: ji, jj, jk, jn   ! dummy loop indices
       REAL(wp) :: ztra, zbtr, zdir, zdx, zdt, zmsk   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zfu, zfc, zfd
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwy, zfu, zfc, zfd
       !----------------------------------------------------------------------
       !
-      CALL wrk_alloc( jpi, jpj, jpk, zfu, zfc, zfd )
+      CALL wrk_alloc( jpi, jpj, jpk, zwy, zfu, zfc, zfd )
       !
       !                                                          ! ===========
@@ -359,5 +353,5 @@
          END DO
          !                                 ! trend diagnostics (contribution of upstream fluxes)
-         IF( l_trd )  CALL trd_tra( kt, cdtype, jn, jptra_trd_yad, zwy, pvn, ptn(:,:,:,jn) )
+         IF( l_trd )   CALL trd_tra( kt, cdtype, jn, jptra_yad, zwy, pvn, ptn(:,:,:,jn) )
          !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
          IF( cdtype == 'TRA' .AND. ln_diaptr .AND. ( MOD( kt, nn_fptr ) == 0 ) ) THEN  
@@ -368,5 +362,5 @@
       END DO
       !
-      CALL wrk_dealloc( jpi, jpj, jpk, zfu, zfc, zfd )
+      CALL wrk_dealloc( jpi, jpj, jpk, zwy, zfu, zfc, zfd )
       !
    END SUBROUTINE tra_adv_qck_j
@@ -378,6 +372,4 @@
       !!
       !!----------------------------------------------------------------------
-      USE oce, ONLY:   zwz => ua   ! ua used as workspace
-      !
       INTEGER                              , INTENT(in   ) ::   kt       ! ocean time-step index
       CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype   ! =TRA or TRC (tracer indicator)
@@ -389,6 +381,8 @@
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
       REAL(wp) ::   zbtr , ztra      ! local scalars
-      !!----------------------------------------------------------------------
-
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwz
+      !!----------------------------------------------------------------------
+      !
+      CALL wrk_alloc( jpi, jpj, jpk, zwz )
       !                                                          ! ===========
       DO jn = 1, kjpt                                            ! tracer loop
@@ -422,7 +416,9 @@
          END DO
          !                                 ! Save the vertical advective trends for diagnostic
-         IF( l_trd )  CALL trd_tra( kt, cdtype, jn, jptra_trd_zad, zwz, pwn, ptn(:,:,:,jn) )
+         IF( l_trd )  CALL trd_tra( kt, cdtype, jn, jptra_zad, zwz, pwn, ptn(:,:,:,jn) )
          !
       END DO
+      !
+      CALL wrk_dealloc( jpi, jpj, jpk, zwz )
       !
    END SUBROUTINE tra_adv_cen2_k
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_tvd.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_tvd.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_tvd.F90	(revision 4946)
@@ -22,12 +22,13 @@
    USE oce            ! ocean dynamics and active tracers
    USE dom_oce        ! ocean space and time domain
-   USE trdmod_oce     ! tracers trends
+   USE trc_oce        ! share passive tracers/Ocean variables
+   USE trd_oce        ! trends: ocean variables
    USE trdtra         ! tracers trends
-   USE in_out_manager ! I/O manager
    USE dynspg_oce     ! choice/control of key cpp for surface pressure gradient
+   USE diaptr         ! poleward transport diagnostics
+   !
    USE lib_mpp        ! MPP library
    USE lbclnk         ! ocean lateral boundary condition (or mpp link) 
-   USE diaptr         ! poleward transport diagnostics
-   USE trc_oce        ! share passive tracers/Ocean variables
+   USE in_out_manager ! I/O manager
    USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
@@ -95,8 +96,8 @@
          IF(lwp) WRITE(numout,*) 'tra_adv_tvd : TVD advection scheme on ', cdtype
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+         !
+         l_trd = .FALSE.
+         IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) ) l_trd = .TRUE.
       ENDIF
-      !
-      l_trd = .FALSE.
-      IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) ) l_trd = .TRUE.
       !
       IF( l_trd )  THEN
@@ -244,7 +245,7 @@
             ztrdz(:,:,:) = ztrdz(:,:,:) + zwz(:,:,:)  ! <<< Add to previously computed
             
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_xad, ztrdx, pun, ptn(:,:,:,jn) )   
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_yad, ztrdy, pvn, ptn(:,:,:,jn) )  
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_zad, ztrdz, pwn, ptn(:,:,:,jn) ) 
+            CALL trd_tra( kt, cdtype, jn, jptra_xad, ztrdx, pun, ptn(:,:,:,jn) )   
+            CALL trd_tra( kt, cdtype, jn, jptra_yad, ztrdy, pvn, ptn(:,:,:,jn) )  
+            CALL trd_tra( kt, cdtype, jn, jptra_zad, ztrdz, pwn, ptn(:,:,:,jn) ) 
          END IF
          !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
@@ -518,7 +519,7 @@
             ztrdz(:,:,:) = ztrdz(:,:,:) + zwz(:,:,:)  ! <<< Add to previously computed
             
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_xad, ztrdx, pun, ptn(:,:,:,jn) )   
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_yad, ztrdy, pvn, ptn(:,:,:,jn) )  
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_zad, ztrdz, pwn, ptn(:,:,:,jn) ) 
+            CALL trd_tra( kt, cdtype, jn, jptra_xad, ztrdx, pun, ptn(:,:,:,jn) )   
+            CALL trd_tra( kt, cdtype, jn, jptra_yad, ztrdy, pvn, ptn(:,:,:,jn) )  
+            CALL trd_tra( kt, cdtype, jn, jptra_zad, ztrdz, pwn, ptn(:,:,:,jn) ) 
          END IF
          !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
@@ -552,12 +553,10 @@
       !!       in-space based differencing for fluid
       !!----------------------------------------------------------------------
-      !
-      !!----------------------------------------------------------------------
       REAL(wp), DIMENSION(jpk)         , INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
       REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pbef, paft      ! before & after field
       REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(inout) ::   paa, pbb, pcc   ! monotonic fluxes in the 3 directions
       !
-      INTEGER ::   ji, jj, jk   ! dummy loop indices
-      INTEGER ::   ikm1         ! local integer
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   ikm1         ! local integer
       REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zrtrn, z2dtt   ! local scalars
       REAL(wp) ::   zau, zbu, zcu, zav, zbv, zcv, zup, zdo            !   -      -
@@ -569,17 +568,15 @@
       CALL wrk_alloc( jpi, jpj, jpk, zbetup, zbetdo, zbup, zbdo )
       !
-
       zbig  = 1.e+40_wp
       zrtrn = 1.e-15_wp
       zbetup(:,:,:) = 0._wp   ;   zbetdo(:,:,:) = 0._wp
 
-
       ! Search local extrema
       ! --------------------
       ! max/min of pbef & paft with large negative/positive value (-/+zbig) inside land
-      zbup = MAX( pbef * tmask - zbig * ( 1.e0 - tmask ),   &
-         &        paft * tmask - zbig * ( 1.e0 - tmask )  )
-      zbdo = MIN( pbef * tmask + zbig * ( 1.e0 - tmask ),   &
-         &        paft * tmask + zbig * ( 1.e0 - tmask )  )
+      zbup = MAX( pbef * tmask - zbig * ( 1._wp - tmask ),   &
+         &        paft * tmask - zbig * ( 1._wp - tmask )  )
+      zbdo = MIN( pbef * tmask + zbig * ( 1._wp - tmask ),   &
+         &        paft * tmask + zbig * ( 1._wp - tmask )  )
 
       DO jj = 2, jpjm1
@@ -625,13 +622,13 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zau = MIN( 1.e0, zbetdo(ji,jj,jk), zbetup(ji+1,jj,jk) )
-               zbu = MIN( 1.e0, zbetup(ji,jj,jk), zbetdo(ji+1,jj,jk) )
+               zau = MIN( 1._wp, zbetdo(ji,jj,jk), zbetup(ji+1,jj,jk) )
+               zbu = MIN( 1._wp, zbetup(ji,jj,jk), zbetdo(ji+1,jj,jk) )
                zcu =       ( 0.5  + SIGN( 0.5 , paa(ji,jj,jk) ) )
-               paa(ji,jj,jk) = paa(ji,jj,jk) * ( zcu * zau + ( 1.e0 - zcu) * zbu )
-
-               zav = MIN( 1.e0, zbetdo(ji,jj,jk), zbetup(ji,jj+1,jk) )
-               zbv = MIN( 1.e0, zbetup(ji,jj,jk), zbetdo(ji,jj+1,jk) )
+               paa(ji,jj,jk) = paa(ji,jj,jk) * ( zcu * zau + ( 1._wp - zcu) * zbu )
+
+               zav = MIN( 1._wp, zbetdo(ji,jj,jk), zbetup(ji,jj+1,jk) )
+               zbv = MIN( 1._wp, zbetup(ji,jj,jk), zbetdo(ji,jj+1,jk) )
                zcv =       ( 0.5  + SIGN( 0.5 , pbb(ji,jj,jk) ) )
-               pbb(ji,jj,jk) = pbb(ji,jj,jk) * ( zcv * zav + ( 1.e0 - zcv) * zbv )
+               pbb(ji,jj,jk) = pbb(ji,jj,jk) * ( zcv * zav + ( 1._wp - zcv) * zbv )
 
       ! monotonic flux in the k direction, i.e. pcc
@@ -640,5 +637,5 @@
                zb = MIN( 1., zbetup(ji,jj,jk+1), zbetdo(ji,jj,jk) )
                zc =       ( 0.5  + SIGN( 0.5 , pcc(ji,jj,jk+1) ) )
-               pcc(ji,jj,jk+1) = pcc(ji,jj,jk+1) * ( zc * za + ( 1.e0 - zc) * zb )
+               pcc(ji,jj,jk+1) = pcc(ji,jj,jk+1) * ( zc * za + ( 1._wp - zc) * zb )
             END DO
          END DO
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_ubs.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_ubs.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_ubs.F90	(revision 4946)
@@ -14,12 +14,13 @@
    USE oce            ! ocean dynamics and active tracers
    USE dom_oce        ! ocean space and time domain
-   USE trdmod_oce     ! ocean space and time domain
-   USE trdtra
-   USE lib_mpp
+   USE trc_oce        ! share passive tracers/Ocean variables
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! trends manager: tracers 
+   USE dynspg_oce     ! choice/control of key cpp for surface pressure gradient
+   USE diaptr         ! poleward transport diagnostics
+   !
+   USE lib_mpp        ! I/O library
    USE lbclnk         ! ocean lateral boundary condition (or mpp link)
    USE in_out_manager ! I/O manager
-   USE diaptr         ! poleward transport diagnostics
-   USE dynspg_oce     ! choice/control of key cpp for surface pressure gradient
-   USE trc_oce        ! share passive tracers/Ocean variables
    USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
@@ -51,10 +52,10 @@
       !!      and add it to the general trend of passive tracer equations.
       !!
-      !! ** Method  :   The upstream biased 3rd order scheme (UBS) is based on an
+      !! ** Method  :   The upstream biased scheme (UBS) is based on a 3rd order
       !!      upstream-biased parabolic interpolation (Shchepetkin and McWilliams 2005)
       !!      It is only used in the horizontal direction.
       !!      For example the i-component of the advective fluxes are given by :
       !!                !  e2u e3u un ( mi(Tn) - zltu(i  ) )   if un(i) >= 0
-      !!          zwx = !  or 
+      !!          ztu = !  or 
       !!                !  e2u e3u un ( mi(Tn) - zltu(i+1) )   if un(i) < 0
       !!      where zltu is the second derivative of the before temperature field:
@@ -76,6 +77,4 @@
       !!             Farrow, D.E., Stevens, D.P., 1995, J. Phys. Ocean. 25, 1731Ð1741. 
       !!----------------------------------------------------------------------
-      USE oce     , ONLY:   zwx  => ua       , zwy  => va         ! (ua,va) used as workspace
-      !
       INTEGER                              , INTENT(in   ) ::   kt              ! ocean time-step index
       INTEGER                              , INTENT(in   ) ::   kit000          ! first time step index
@@ -98,5 +97,4 @@
       CALL wrk_alloc( jpi, jpj, jpk, ztu, ztv, zltu, zltv, zti, ztw )
       !
-
       IF( kt == kit000 )  THEN
          IF(lwp) WRITE(numout,*)
@@ -151,6 +149,6 @@
                   zcenvt = pvn(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji  ,jj+1,jk,jn) )
                   ! UBS advective fluxes
-                  zwx(ji,jj,jk) = 0.5 * ( zcenut - zfp_ui * zltu(ji,jj,jk) - zfm_ui * zltu(ji+1,jj,jk) )
-                  zwy(ji,jj,jk) = 0.5 * ( zcenvt - zfp_vj * zltv(ji,jj,jk) - zfm_vj * zltv(ji,jj+1,jk) )
+                  ztu(ji,jj,jk) = 0.5 * ( zcenut - zfp_ui * zltu(ji,jj,jk) - zfm_ui * zltu(ji+1,jj,jk) )
+                  ztv(ji,jj,jk) = 0.5 * ( zcenvt - zfp_vj * zltv(ji,jj,jk) - zfm_vj * zltv(ji,jj+1,jk) )
                END DO
             END DO
@@ -159,15 +157,10 @@
          zltu(:,:,:) = pta(:,:,:,jn)      ! store pta trends
 
-         ! Horizontal advective trends
-         DO jk = 1, jpkm1
-            !  Tracer flux divergence at t-point added to the general trend
+         DO jk = 1, jpkm1                 ! Horizontal advective trends
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
-                  ! horizontal advective
-                  ztra = - zbtr * (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk)   &
-                     &             + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk)  )
-                  ! add it to the general tracer trends
-                  pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + ztra
+                  pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn)                        &
+                     &             - (  ztu(ji,jj,jk) - ztu(ji-1,jj  ,jk)    &
+                     &                + ztv(ji,jj,jk) - ztv(ji  ,jj-1,jk)  ) / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
                END DO
             END DO
@@ -178,15 +171,13 @@
          zltu(:,:,:) = pta(:,:,:,jn) - zltu(:,:,:)
 
-         ! 3. Save the horizontal advective trends for diagnostic
-         ! ------------------------------------------------------
-         !                                 ! trend diagnostics (contribution of upstream fluxes)
-         IF( l_trd ) THEN
-             CALL trd_tra( kt, cdtype, jn, jptra_trd_xad, zwx, pun, ptn(:,:,:,jn) )
-             CALL trd_tra( kt, cdtype, jn, jptra_trd_yad, zwy, pvn, ptn(:,:,:,jn) )
+         !                
+         IF( l_trd ) THEN                  ! trend diagnostics
+             CALL trd_tra( kt, cdtype, jn, jptra_xad, ztu, pun, ptn(:,:,:,jn) )
+             CALL trd_tra( kt, cdtype, jn, jptra_yad, ztv, pvn, ptn(:,:,:,jn) )
          END IF
          !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
          IF( cdtype == 'TRA' .AND. ln_diaptr .AND. ( MOD( kt, nn_fptr ) == 0 ) ) THEN  
-            IF( jn == jp_tem )  htr_adv(:) = ptr_vj( zwy(:,:,:) )
-            IF( jn == jp_sal )  str_adv(:) = ptr_vj( zwy(:,:,:) )
+            IF( jn == jp_tem )  htr_adv(:) = ptr_vj( ztv(:,:,:) )
+            IF( jn == jp_sal )  str_adv(:) = ptr_vj( ztv(:,:,:) )
          ENDIF
          
@@ -265,8 +256,8 @@
                END DO
             END DO
-            CALL trd_tra( kt, cdtype, jn, jptra_trd_zad, zltv )
+            CALL trd_tra( kt, cdtype, jn, jptra_zad, zltv )
          ENDIF
          !
-      ENDDO
+      END DO
       !
       CALL wrk_dealloc( jpi, jpj, jpk, ztu, ztv, zltu, zltv, zti, ztw )
@@ -290,5 +281,4 @@
       !!       in-space based differencing for fluid
       !!----------------------------------------------------------------------
-      !
       REAL(wp), INTENT(in   ), DIMENSION(jpk)          ::   p2dt   ! vertical profile of tracer time-step
       REAL(wp),                DIMENSION (jpi,jpj,jpk) ::   pbef   ! before field
@@ -306,5 +296,4 @@
       CALL wrk_alloc( jpi, jpj, jpk, zbetup, zbetdo )
       !
-
       zbig  = 1.e+40_wp
       zrtrn = 1.e-15_wp
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 4946)
@@ -18,6 +18,6 @@
    USE dom_oce         ! domain: ocean
    USE phycst          ! physical constants
-   USE trdmod_oce      ! trends: ocean variables 
-   USE trdtra          ! trends: active tracers 
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
@@ -84,11 +84,6 @@
       !
       !                             !  Add the geothermal heat flux trend on temperature
-#if defined key_vectopt_loop
-      DO jj = 1, 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)
             zqgh_trd = qgh_trd0(ji,jj) / fse3t(ji,jj,ik)
@@ -99,5 +94,5 @@
       IF( l_trdtra ) THEN        ! Save the geothermal heat flux trend for diagnostics
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_bbc, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_bbc, ztrdt )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt )
       ENDIF
@@ -130,5 +125,5 @@
       INTEGER  ::   inum                ! temporary logical unit
       INTEGER  ::   ios                 ! Local integer output status for namelist read
-      !!
+      !
       NAMELIST/nambbc/ln_trabbc, nn_geoflx, rn_geoflx_cst 
       !!----------------------------------------------------------------------
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 4946)
@@ -12,4 +12,5 @@
    !!             -   ! 2010-06  (C. Ethe, G. Madec)  merge TRA-TRC
    !!             -   ! 2010-11  (G. Madec) add mbk. arrays associated to the deepest ocean level
+   !!             -   ! 2013-04  (F. Roquet, G. Madec)  use of eosbn2 instead of local hard coded alpha and beta
    !!----------------------------------------------------------------------
 #if   defined key_trabbl   ||   defined key_esopa
@@ -28,7 +29,8 @@
    USE phycst         ! physical constant
    USE eosbn2         ! equation of state
-   USE trdmod_oce     ! trends: ocean variables
+   USE trd_oce     ! trends: ocean variables
    USE trdtra         ! trends: active tracers
-   USE iom            ! IOM server
+   !
+   USE iom            ! IOM library               
    USE in_out_manager ! I/O manager
    USE lbclnk         ! ocean lateral boundary conditions
@@ -36,5 +38,5 @@
    USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
-
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
 
    IMPLICIT NONE
@@ -57,5 +59,5 @@
    REAL(wp), PUBLIC ::   rn_gambbl   !: lateral coeff. for bottom boundary layer scheme [s]
 
-   LOGICAL , PUBLIC ::   l_bbl                  !: flag to compute bbl diffu. flux coef and transport
+   LOGICAL , PUBLIC ::   l_bbl       !: flag to compute bbl diffu. flux coef and transport
 
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:), PUBLIC ::   utr_bbl  , vtr_bbl   ! u- (v-) transport in the bottom boundary layer
@@ -84,5 +86,5 @@
          &      vtr_bbl  (jpi,jpj) , ahv_bbl  (jpi,jpj) , mbkv_d  (jpi,jpj) , mgrhv(jpi,jpj) ,     &
          &      ahu_bbl_0(jpi,jpj) , ahv_bbl_0(jpi,jpj) ,                                          &
-         &      e3u_bbl_0(jpi,jpj) , e3v_bbl_0(jpi,jpj) , STAT= tra_bbl_alloc                )
+         &      e3u_bbl_0(jpi,jpj) , e3v_bbl_0(jpi,jpj) ,                                      STAT=tra_bbl_alloc )
          !
       IF( lk_mpp            )   CALL mpp_sum ( tra_bbl_alloc )
@@ -104,5 +106,5 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step
-      !!
+      !
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdt, ztrds
       !!----------------------------------------------------------------------
@@ -110,5 +112,5 @@
       IF( nn_timing == 1 )  CALL timing_start( 'tra_bbl')
       !
-      IF( l_trdtra )   THEN                        !* Save ta and sa trends
+      IF( l_trdtra )   THEN                         !* Save ta and sa trends
          CALL wrk_alloc( jpi, jpj, jpk, ztrdt, ztrds )
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
@@ -116,12 +118,12 @@
       ENDIF
 
-      IF( l_bbl )  CALL bbl( kt, nit000, 'TRA' )   !* bbl coef. and transport (only if not already done in trcbbl)
-
-      IF( nn_bbl_ldf == 1 ) THEN                   !* Diffusive bbl
+      IF( l_bbl )   CALL bbl( kt, nit000, 'TRA' )   !* bbl coef. and transport (only if not already done in trcbbl)
+
+      IF( nn_bbl_ldf == 1 ) THEN                    !* Diffusive bbl
          !
          CALL tra_bbl_dif( tsb, tsa, jpts )
          IF( ln_ctl )  &
          CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' bbl_ldf  - Ta: ', mask1=tmask, &
-         &             tab3d_2=tsa(:,:,:,jp_sal), clinfo2=           ' Sa: ', mask2=tmask, clinfo3='tra' )
+            &          tab3d_2=tsa(:,:,:,jp_sal), clinfo2=           ' Sa: ', mask2=tmask, clinfo3='tra' )
          ! lateral boundary conditions ; just need for outputs
          CALL lbc_lnk( ahu_bbl, 'U', 1. )     ;     CALL lbc_lnk( ahv_bbl, 'V', 1. )
@@ -131,10 +133,10 @@
       END IF
 
-      IF( nn_bbl_adv /= 0 ) THEN                !* Advective bbl
+      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' )
+            &          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. )
@@ -147,6 +149,6 @@
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
          ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_bbl, ztrdt )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_bbl, ztrds )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_bbl, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_bbl, ztrds )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
       ENDIF
@@ -164,6 +166,5 @@
       !!                advection terms.
       !!
-      !! ** Method  :
-      !!        * diffusive bbl (nn_bbl_ldf=1) :
+      !! ** Method  : * diffusive bbl only (nn_bbl_ldf=1) :
       !!        When the product grad( rho) * grad(h) < 0 (where grad is an
       !!      along bottom slope gradient) an additional lateral 2nd order
@@ -179,5 +180,4 @@
       !!              Campin, J.-M., and H. Goosse, 1999, Tellus, 412-430.
       !!----------------------------------------------------------------------
-      !
       INTEGER                              , INTENT(in   ) ::   kjpt   ! number of tracers
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb    ! before and now tracer fields
@@ -196,24 +196,14 @@
       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
-               zptb(ji,jj) = ptb(ji,jj,ik,jn)              ! bottom before T and S
+               ik = mbkt(ji,jj)                              ! bottom T-level index
+               zptb(ji,jj) = ptb(ji,jj,ik,jn)       ! bottom before T and S
             END DO
          END DO
-         !                                                ! Compute the trend
-#  if defined key_vectopt_loop
-         DO jj = 1, 1   ! vector opt. (forced unrolling)
-            DO ji = jpi+1, jpij-jpi-1
-#  else
-         DO jj = 2, jpjm1
+         !               
+         DO jj = 2, jpjm1                                    ! Compute the trend
             DO ji = 2, jpim1
-#  endif
-               ik = mbkt(ji,jj)                            ! bottom T-level index
+               ik = mbkt(ji,jj)                              ! bottom T-level index
                zbtr = r1_e12t(ji,jj)  / fse3t(ji,jj,ik)
                pta(ji,jj,ik,jn) = pta(ji,jj,ik,jn)                                                         &
@@ -264,11 +254,6 @@
       DO jn = 1, kjpt                                            ! tracer loop
          !                                                       ! ===========
-# if defined key_vectopt_loop
-         DO jj = 1, 1
-            DO ji = 1, jpij-jpi-1   ! vector opt. (forced unrolling)
-# else
          DO jj = 1, jpjm1
             DO ji = 1, jpim1            ! CAUTION start from i=1 to update i=2 when cyclic east-west
-# endif
                IF( utr_bbl(ji,jj) /= 0.e0 ) THEN            ! non-zero i-direction bbl advection
                   ! down-slope i/k-indices (deep)      &   up-slope i/k indices (shelf)
@@ -333,6 +318,5 @@
       !!                advection terms.
       !!
-      !! ** Method  :
-      !!        * diffusive bbl (nn_bbl_ldf=1) :
+      !! ** Method  : * diffusive bbl (nn_bbl_ldf=1) :
       !!        When the product grad( rho) * grad(h) < 0 (where grad is an
       !!      along bottom slope gradient) an additional lateral 2nd order
@@ -342,5 +326,5 @@
       !!      a downslope velocity of 20 cm/s if the condition for slope
       !!      convection is satified)
-      !!        * advective bbl (nn_bbl_adv=1 or 2) :
+      !!              * 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
@@ -353,56 +337,20 @@
       !!              Campin, J.-M., and H. Goosse, 1999, Tellus, 412-430.
       !!----------------------------------------------------------------------
-      !
       INTEGER         , INTENT(in   ) ::   kt       ! ocean time-step index
-      INTEGER         , INTENT(in   ) ::   kit000          ! first time step index
+      INTEGER         , INTENT(in   ) ::   kit000   ! first time step index
       CHARACTER(len=3), INTENT(in   ) ::   cdtype   ! =TRA or TRC (tracer indicator)
       !!
       INTEGER  ::   ji, jj                    ! dummy loop indices
       INTEGER  ::   ik                        ! local integers
-      INTEGER  ::   iis , iid , ijs , ijd     !   -       -
-      INTEGER  ::   ikus, ikud, ikvs, ikvd    !   -       -
-      REAL(wp) ::   zsign, zsigna, zgbbl      ! local scalars
-      REAL(wp) ::   zgdrho, zt, zs, zh        !   -      -
-      !!
-      REAL(wp) ::   fsalbt, fsbeta, pft, pfs, pfh   ! statement function
-      REAL(wp), POINTER, DIMENSION(:,:) :: zub, zvb, ztb, zsb, zdep
-      !!----------------------- zv_bbl-----------------------------------------------
-      ! ratio alpha/beta = fsalbt : ratio of thermal over saline expension coefficients
-      ! ================            pft :  potential temperature in degrees celcius
-      !                             pfs :  salinity anomaly (s-35) in psu
-      !                             pfh :  depth in meters
-      ! nn_eos = 0  (Jackett and McDougall 1994 formulation)
-      fsalbt( pft, pfs, pfh ) =                                              &   ! alpha/beta
-         ( ( ( -0.255019e-07 * pft + 0.298357e-05 ) * pft                    &
-                                   - 0.203814e-03 ) * pft                    &
-                                   + 0.170907e-01 ) * pft                    &
-                                   + 0.665157e-01                            &
-         +(-0.678662e-05 * pfs - 0.846960e-04 * pft + 0.378110e-02 ) * pfs   &
-         +  ( ( - 0.302285e-13 * pfh                                         &
-                - 0.251520e-11 * pfs                                         &
-                + 0.512857e-12 * pft * pft          ) * pfh                  &
-                                     - 0.164759e-06   * pfs                  &
-             +(   0.791325e-08 * pft - 0.933746e-06 ) * pft                  &
-                                     + 0.380374e-04 ) * pfh
-      fsbeta( pft, pfs, pfh ) =                                              &   ! beta
-         ( ( -0.415613e-09 * pft + 0.555579e-07 ) * pft                      &
-                                 - 0.301985e-05 ) * pft                      &
-                                 + 0.785567e-03                              &
-         + (     0.515032e-08 * pfs                                          &
-               + 0.788212e-08 * pft - 0.356603e-06 ) * pfs                   &
-               +(  (   0.121551e-17 * pfh                                    &
-                     - 0.602281e-15 * pfs                                    &
-                     - 0.175379e-14 * pft + 0.176621e-12 ) * pfh             &
-                                          + 0.408195e-10   * pfs             &
-                 + ( - 0.213127e-11 * pft + 0.192867e-09 ) * pft             &
-                                          - 0.121555e-07 ) * pfh
-      !!----------------------------------------------------------------------
-
+      INTEGER  ::   iis, iid, ikus, ikud      !   -       -
+      INTEGER  ::   ijs, ijd, ikvs, ikvd      !   -       -
+      REAL(wp) ::   za, zb, zgdrho            ! local scalars
+      REAL(wp) ::   zsign, zsigna, zgbbl      !   -      -
+      REAL(wp), DIMENSION(jpi,jpj,jpts)   :: zts, zab         ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj)        :: zub, zvb, zdep   ! 2D workspace
+      !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start( 'bbl')
       !
-      CALL wrk_alloc( jpi, jpj, zub, zvb, ztb, zsb, zdep )
-      !
-
       IF( kt == kit000 )  THEN
          IF(lwp)  WRITE(numout,*)
@@ -410,50 +358,43 @@
          IF(lwp)  WRITE(numout,*) '~~~~~~~~~~'
       ENDIF
-
-      !                                        !* bottom temperature, salinity, velocity and depth
-#if defined key_vectopt_loop
-      DO jj = 1, 1   ! vector opt. (forced unrolling)
-         DO ji = 1, jpij
-#else
+      !                                        !* bottom variables (T, S, alpha, beta, depth, velocity)
       DO jj = 1, jpj
          DO ji = 1, jpi
-#endif
-            ik = mbkt(ji,jj)                        ! bottom T-level index
-            ztb (ji,jj) = tsb(ji,jj,ik,jp_tem) * ssmask(ji,jj)      ! bottom before T and S
-            zsb (ji,jj) = tsb(ji,jj,ik,jp_sal) * ssmask(ji,jj)
-            zdep(ji,jj) = gdept_0(ji,jj,ik)         ! bottom T-level reference depth
+            ik = mbkt(ji,jj)                             ! bottom T-level index
+            zts (ji,jj,jp_tem) = tsb(ji,jj,ik,jp_tem)    ! bottom before T and S
+            zts (ji,jj,jp_sal) = tsb(ji,jj,ik,jp_sal)
             !
-            zub(ji,jj) = un(ji,jj,mbku(ji,jj))      ! bottom velocity
-            zvb(ji,jj) = vn(ji,jj,mbkv(ji,jj))
+            zdep(ji,jj) = fsdept(ji,jj,ik)               ! bottom T-level reference depth
+            zub (ji,jj) = un(ji,jj,mbku(ji,jj))          ! bottom velocity
+            zvb (ji,jj) = vn(ji,jj,mbkv(ji,jj))
          END DO
       END DO
-
+      !
+      CALL eos_rab( zts, zdep, zab )
+      !
       !                                   !-------------------!
       IF( nn_bbl_ldf == 1 ) THEN          !   diffusive bbl   !
          !                                !-------------------!
          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
-               zs = 0.5 * ( zsb (ji,jj) + zsb (ji+1,jj) ) - 35.0
-               zh = 0.5 * ( zdep(ji,jj) + zdep(ji+1,jj) )
-               !                                                         ! masked bbl i-gradient of density
-               zgdrho = (  fsalbt( zt, zs, zh ) * ( ztb(ji+1,jj) - ztb(ji,jj) )    &
-                  &                             - ( zsb(ji+1,jj) - zsb(ji,jj) )  ) * umask(ji,jj,1)
+            DO ji = 1, fs_jpim1   ! vector opt.
+               !                                                   ! i-direction
+               za = zab(ji+1,jj,jp_tem) + zab(ji,jj,jp_tem)              ! 2*(alpha,beta) at u-point
+               zb = zab(ji+1,jj,jp_sal) + zab(ji,jj,jp_sal)
+               !                                                         ! 2*masked bottom density gradient
+               zgdrho = (  za * ( zts(ji+1,jj,jp_tem) - zts(ji,jj,jp_tem) )    &
+                  &      - zb * ( zts(ji+1,jj,jp_sal) - zts(ji,jj,jp_sal) )  ) * umask(ji,jj,1)
                !
-               zsign          = SIGN(  0.5, - zgdrho * REAL( mgrhu(ji,jj) )  )    ! sign of ( i-gradient * i-slope )
-               ahu_bbl(ji,jj) = ( 0.5 - zsign ) * ahu_bbl_0(ji,jj)                  ! masked diffusive flux coeff.
+               zsign  = SIGN(  0.5, -zgdrho * REAL( mgrhu(ji,jj) )  )    ! sign of ( i-gradient * i-slope )
+               ahu_bbl(ji,jj) = ( 0.5 - zsign ) * ahu_bbl_0(ji,jj)       ! masked diffusive flux coeff.
                !
-               !                                                ! j-direction
-               zt = 0.5 * ( ztb (ji,jj+1) + ztb (ji,jj) )                ! T, S anomalie, and depth
-               zs = 0.5 * ( zsb (ji,jj+1) + zsb (ji,jj) ) - 35.0
-               zh = 0.5 * ( zdep(ji,jj+1) + zdep(ji,jj) )
-               !                                                         ! masked bbl j-gradient of density
-               zgdrho = (  fsalbt( zt, zs, zh ) * ( ztb(ji,jj+1) - ztb(ji,jj) )    &
-                  &                             - ( zsb(ji,jj+1) - zsb(ji,jj) )  ) * vmask(ji,jj,1)
+               !                                                   ! j-direction
+               za = zab(ji,jj+1,jp_tem) + zab(ji,jj,jp_tem)              ! 2*(alpha,beta) at v-point
+               zb = zab(ji,jj+1,jp_sal) + zab(ji,jj,jp_sal)
+               !                                                         ! 2*masked bottom density gradient
+               zgdrho = (  za * ( zts(ji,jj+1,jp_tem) - zts(ji,jj,jp_tem) )    &
+                  &      - zb * ( zts(ji,jj+1,jp_sal) - zts(ji,jj,jp_sal) )  ) * vmask(ji,jj,1)
                !
-               zsign          = SIGN(  0.5, -zgdrho * REAL( mgrhv(ji,jj) )  )     ! sign of ( j-gradient * j-slope )
+               zsign = SIGN(  0.5, -zgdrho * REAL( mgrhv(ji,jj) )  )     ! sign of ( j-gradient * j-slope )
                ahv_bbl(ji,jj) = ( 0.5 - zsign ) * ahv_bbl_0(ji,jj)
-               !
             END DO
          END DO
@@ -469,29 +410,27 @@
             DO jj = 1, jpjm1                                 ! criteria: grad(rho).grad(h)<0  and grad(rho).grad(h)<0
                DO ji = 1, fs_jpim1   ! vector opt.
-                  !                                               ! i-direction
-                  zt = 0.5 * ( ztb (ji,jj) + ztb (ji+1,jj) )                  ! T, S anomalie, and depth
-                  zs = 0.5 * ( zsb (ji,jj) + zsb (ji+1,jj) ) - 35.0
-                  zh = 0.5 * ( zdep(ji,jj) + zdep(ji+1,jj) )
-                  !                                                           ! masked bbl i-gradient of density
-                  zgdrho = (  fsalbt( zt, zs, zh ) * ( ztb(ji+1,jj) - ztb(ji,jj) )    &
-                     &                             - ( zsb(ji+1,jj) - zsb(ji,jj) )  ) * umask(ji,jj,1)
-                  !
-                  zsign = SIGN(  0.5, - zgdrho   * REAL( mgrhu(ji,jj) )  )    ! sign of i-gradient * i-slope
-                  zsigna= SIGN(  0.5, zub(ji,jj) * REAL( mgrhu(ji,jj) )  )    ! sign of u * i-slope
-                  !
-                  !                                                           ! bbl velocity
+                  !                                                  ! i-direction
+                  za = zab(ji+1,jj,jp_tem) + zab(ji,jj,jp_tem)               ! 2*(alpha,beta) at u-point
+                  zb = zab(ji+1,jj,jp_sal) + zab(ji,jj,jp_sal)
+                  !                                                          ! 2*masked bottom density gradient 
+                  zgdrho = (  za * ( zts(ji+1,jj,jp_tem) - zts(ji,jj,jp_tem) )    &
+                            - zb * ( zts(ji+1,jj,jp_sal) - zts(ji,jj,jp_sal) )  ) * umask(ji,jj,1)
+                  !
+                  zsign = SIGN(  0.5, - zgdrho   * REAL( mgrhu(ji,jj) )  )   ! sign of i-gradient * i-slope
+                  zsigna= SIGN(  0.5, zub(ji,jj) * REAL( mgrhu(ji,jj) )  )   ! sign of u * i-slope
+                  !
+                  !                                                          ! bbl velocity
                   utr_bbl(ji,jj) = ( 0.5 + zsigna ) * ( 0.5 - zsign ) * e2u(ji,jj) * e3u_bbl_0(ji,jj) * zub(ji,jj)
                   !
-                  !                                               ! j-direction
-                  zt = 0.5 * ( ztb (ji,jj+1) + ztb (ji,jj) )                  ! T, S anomalie, and depth
-                  zs = 0.5 * ( zsb (ji,jj+1) + zsb (ji,jj) ) - 35.0
-                  zh = 0.5 * ( zdep(ji,jj+1) + zdep(ji,jj) )
-                  !                                                           ! masked bbl j-gradient of density
-                  zgdrho = (  fsalbt( zt, zs, zh ) * ( ztb(ji,jj+1) - ztb(ji,jj) )    &
-                     &                             - ( zsb(ji,jj+1) - zsb(ji,jj) )  ) * vmask(ji,jj,1)
-                  zsign = SIGN(  0.5, - zgdrho   * REAL( mgrhv(ji,jj) )  )    ! sign of j-gradient * j-slope
-                  zsigna= SIGN(  0.5, zvb(ji,jj) * REAL( mgrhv(ji,jj) )  )    ! sign of u * i-slope
-                  !
-                  !                                                           ! bbl velocity
+                  !                                                  ! j-direction
+                  za = zab(ji,jj+1,jp_tem) + zab(ji,jj,jp_tem)               ! 2*(alpha,beta) at v-point
+                  zb = zab(ji,jj+1,jp_sal) + zab(ji,jj,jp_sal)
+                  !                                                          ! 2*masked bottom density gradient
+                  zgdrho = (  za * ( zts(ji,jj+1,jp_tem) - zts(ji,jj,jp_tem) )    &
+                     &      - zb * ( zts(ji,jj+1,jp_sal) - zts(ji,jj,jp_sal) )  ) * vmask(ji,jj,1)
+                  zsign = SIGN(  0.5, - zgdrho   * REAL( mgrhv(ji,jj) )  )   ! sign of j-gradient * j-slope
+                  zsigna= SIGN(  0.5, zvb(ji,jj) * REAL( mgrhv(ji,jj) )  )   ! sign of u * i-slope
+                  !
+                  !                                                          ! bbl transport
                   vtr_bbl(ji,jj) = ( 0.5 + zsigna ) * ( 0.5 - zsign ) * e1v(ji,jj) * e3v_bbl_0(ji,jj) * zvb(ji,jj)
                END DO
@@ -502,36 +441,38 @@
             DO jj = 1, jpjm1                            ! criteria: rho_up > rho_down
                DO ji = 1, fs_jpim1   ! vector opt.
-                  !                                         ! i-direction
+                  !                                                  ! i-direction
                   ! down-slope T-point i/k-index (deep)  &   up-slope T-point i/k-index (shelf)
-                  iid  = ji + MAX( 0, mgrhu(ji,jj) )     ;    iis  = ji + 1 - MAX( 0, mgrhu(ji,jj) )
-                  ikud = mbku_d(ji,jj)                   ;    ikus = mbku(ji,jj)
-                  !
-                  !                                             ! mid-depth density anomalie (up-slope minus down-slope)
-                  zt = 0.5 * ( ztb (ji,jj) + ztb (ji+1,jj) )           ! mid slope depth of T, S, and depth
-                  zs = 0.5 * ( zsb (ji,jj) + zsb (ji+1,jj) ) - 35.0
-                  zh = 0.5 * ( zdep(ji,jj) + zdep(ji+1,jj) )
-                  zgdrho =    fsbeta( zt, zs, zh )                                    &
-                     &   * (  fsalbt( zt, zs, zh ) * ( ztb(iid,jj) - ztb(iis,jj) )    &
-                     &                             - ( zsb(iid,jj) - zsb(iis,jj) )  ) * umask(ji,jj,1)
-                  zgdrho = MAX( 0.e0, zgdrho )                         ! only if shelf is denser than deep
-                  !
-                  !                                             ! bbl transport (down-slope direction)
+                  iid  = ji + MAX( 0, mgrhu(ji,jj) )
+                  iis  = ji + 1 - MAX( 0, mgrhu(ji,jj) )
+                  !
+                  ikud = mbku_d(ji,jj)
+                  ikus = mbku(ji,jj)
+                  !
+                  za = zab(ji+1,jj,jp_tem) + zab(ji,jj,jp_tem)               ! 2*(alpha,beta) at u-point
+                  zb = zab(ji+1,jj,jp_sal) + zab(ji,jj,jp_sal)
+                  !                                                          !   masked bottom density gradient
+                  zgdrho = 0.5 * (  za * ( zts(iid,jj,jp_tem) - zts(iis,jj,jp_tem) )    &
+                     &            - zb * ( zts(iid,jj,jp_sal) - zts(iis,jj,jp_sal) )  ) * umask(ji,jj,1)
+                  zgdrho = MAX( 0.e0, zgdrho )                               ! only if shelf is denser than deep
+                  !
+                  !                                                          ! bbl transport (down-slope direction)
                   utr_bbl(ji,jj) = e2u(ji,jj) * e3u_bbl_0(ji,jj) * zgbbl * zgdrho * REAL( mgrhu(ji,jj) )
                   !
-                  !                                         ! j-direction
+                  !                                                  ! j-direction
                   !  down-slope T-point j/k-index (deep)  &   of the up  -slope T-point j/k-index (shelf)
-                  ijd  = jj + MAX( 0, mgrhv(ji,jj) )      ;    ijs  = jj + 1 - MAX( 0, mgrhv(ji,jj) )
-                  ikvd = mbkv_d(ji,jj)                    ;    ikvs = mbkv(ji,jj)
-                  !
-                  !                                             ! mid-depth density anomalie (up-slope minus down-slope)
-                  zt = 0.5 * ( ztb (ji,jj) + ztb (ji,jj+1) )           ! mid slope depth of T, S, and depth
-                  zs = 0.5 * ( zsb (ji,jj) + zsb (ji,jj+1) ) - 35.0
-                  zh = 0.5 * ( zdep(ji,jj) + zdep(ji,jj+1) )
-                  zgdrho =    fsbeta( zt, zs, zh )                                    &
-                     &   * (  fsalbt( zt, zs, zh ) * ( ztb(ji,ijd) - ztb(ji,ijs) )    &
-                     &                             - ( zsb(ji,ijd) - zsb(ji,ijs) )  ) * vmask(ji,jj,1)
-                  zgdrho = MAX( 0.e0, zgdrho )                         ! only if shelf is denser than deep
-                  !
-                  !                                             ! bbl transport (down-slope direction)
+                  ijd  = jj + MAX( 0, mgrhv(ji,jj) )
+                  ijs  = jj + 1 - MAX( 0, mgrhv(ji,jj) )
+                  !
+                  ikvd = mbkv_d(ji,jj)
+                  ikvs = mbkv(ji,jj)
+                  !
+                  za = zab(ji,jj+1,jp_tem) + zab(ji,jj,jp_tem)               ! 2*(alpha,beta) at v-point
+                  zb = zab(ji,jj+1,jp_sal) + zab(ji,jj,jp_sal)
+                  !                                                          !   masked bottom density gradient
+                  zgdrho = 0.5 * (  za * ( zts(ji,ijd,jp_tem) - zts(ji,ijs,jp_tem) )    &
+                     &            - zb * ( zts(ji,ijd,jp_sal) - zts(ji,ijs,jp_sal) )  ) * vmask(ji,jj,1)
+                  zgdrho = MAX( 0.e0, zgdrho )                               ! only if shelf is denser than deep
+                  !
+                  !                                                          ! bbl transport (down-slope direction)
                   vtr_bbl(ji,jj) = e1v(ji,jj) * e3v_bbl_0(ji,jj) * zgbbl * zgdrho * REAL( mgrhv(ji,jj) )
                END DO
@@ -541,6 +482,4 @@
       ENDIF
       !
-      CALL wrk_dealloc( jpi, jpj, zub, zvb, ztb, zsb, zdep )
-      !
       IF( nn_timing == 1 )  CALL timing_stop( 'bbl')
       !
@@ -558,6 +497,6 @@
       !!----------------------------------------------------------------------
       INTEGER ::   ji, jj               ! dummy loop indices
-      INTEGER ::   ii0, ii1, ij0, ij1   ! temporary integer
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
+      INTEGER ::   ii0, ii1, ij0, ij1   ! local integer
+      INTEGER ::   ios                  !   -      -
       REAL(wp), POINTER, DIMENSION(:,:) :: zmbk
       !!
@@ -598,6 +537,4 @@
       IF( nn_bbl_adv == 2 )    WRITE(numout,*) '       * Advective BBL using velocity = F( delta rho)'
 
-      IF( nn_eos /= 0 )   CALL ctl_stop ( ' bbl parameterisation requires eos = 0. We stop.' )
-
       !                             !* vertical index of  "deep" bottom u- and v-points
       DO jj = 1, jpjm1                    ! (the "shelf" bottom k-indices are mbku and mbkv)
@@ -607,10 +544,10 @@
          END DO
       END DO
-      ! convert into REAL to use lbc_lnk ; impose a min value of 1 as a zero can be set in lbclnk
+      ! converte into REAL to use lbc_lnk ; impose a min value of 1 as a zero can be set in lbclnk
       zmbk(:,:) = REAL( mbku_d(:,:), wp )   ;   CALL lbc_lnk(zmbk,'U',1.)   ;   mbku_d(:,:) = MAX( INT( zmbk(:,:) ), 1 )
       zmbk(:,:) = REAL( mbkv_d(:,:), wp )   ;   CALL lbc_lnk(zmbk,'V',1.)   ;   mbkv_d(:,:) = MAX( INT( zmbk(:,:) ), 1 )
 
-                                     !* sign of grad(H) at u- and v-points
-      mgrhu(jpi,:) = 0.    ;    mgrhu(:,jpj) = 0.   ;    mgrhv(jpi,:) = 0.    ;    mgrhv(:,jpj) = 0.
+                                        !* sign of grad(H) at u- and v-points
+      mgrhu(jpi,:) = 0   ;   mgrhu(:,jpj) = 0   ;   mgrhv(jpi,:) = 0   ;   mgrhv(:,jpj) = 0
       DO jj = 1, jpjm1
          DO ji = 1, jpim1
@@ -621,5 +558,5 @@
 
       DO jj = 1, jpjm1              !* bbl thickness at u- (v-) point
-         DO ji = 1, jpim1           ! minimum of top & bottom e3u_0 (e3v_0)
+         DO ji = 1, jpim1                 ! minimum of top & bottom e3u_0 (e3v_0)
             e3u_bbl_0(ji,jj) = MIN( e3u_0(ji,jj,mbkt(ji+1,jj  )), e3u_0(ji,jj,mbkt(ji,jj)) )
             e3v_bbl_0(ji,jj) = MIN( e3v_0(ji,jj,mbkt(ji  ,jj+1)), e3v_0(ji,jj,mbkt(ji,jj)) )
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 4946)
@@ -28,6 +28,6 @@
    USE dom_oce        ! ocean: domain variables
    USE c1d            ! 1D vertical configuration
-   USE trdmod_oce     ! ocean: trend variables
-   USE trdtra         ! active tracers: trends
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! trends manager: tracers 
    USE zdf_oce        ! ocean: vertical physics
    USE phycst         ! physical constants
@@ -48,4 +48,6 @@
    PUBLIC   dtacof_zoom  ! routine called by tradmp.F90, trcdmp.F90 and dyndmp.F90
 
+!!gm  why all namelist variable public????   only ln_tradmp should be sufficient
+
    !                               !!* Namelist namtra_dmp : T & S newtonian damping *
    LOGICAL , PUBLIC ::   ln_tradmp   !: internal damping flag
@@ -112,4 +114,5 @@
       !
       CALL wrk_alloc( jpi, jpj, jpk, jpts,  zts_dta )
+      !
       !                           !==   input T-S data at kt   ==!
       CALL dta_tsd( kt, zts_dta )            ! read and interpolates T-S data at kt
@@ -172,6 +175,6 @@
       !
       IF( l_trdtra )   THEN       ! trend diagnostic
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_dmp, ttrdmp )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_dmp, strdmp )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_dmp, ttrdmp )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_dmp, strdmp )
       ENDIF
       !                           ! Control print
@@ -194,12 +197,13 @@
       !! ** Method  :   read the namtra_dmp namelist and check the parameters
       !!----------------------------------------------------------------------
+      INTEGER  ::   ios   ! Local integer output status for namelist read
+      !!
       NAMELIST/namtra_dmp/ ln_tradmp, nn_hdmp, nn_zdmp, rn_surf, rn_bot, rn_dep, nn_file
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
-      !!----------------------------------------------------------------------
-
+      !!----------------------------------------------------------------------
+      !
       REWIND( numnam_ref )              ! Namelist namtra_dmp in reference namelist : Temperature and salinity damping term
       READ  ( numnam_ref, namtra_dmp, IOSTAT = ios, ERR = 901)
 901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtra_dmp in reference namelist', lwp )
-
+      !
       REWIND( numnam_cfg )              ! Namelist namtra_dmp in configuration namelist : Temperature and salinity damping term
       READ  ( numnam_cfg, namtra_dmp, IOSTAT = ios, ERR = 902 )
@@ -228,4 +232,7 @@
          IF( tra_dmp_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'tra_dmp_init: unable to allocate arrays' )
          !
+!!gm  I don't understand the specificities of c1d case......   
+!!gm  to be check with the autor of these lines
+         
 #if ! defined key_c1d
          SELECT CASE ( nn_hdmp )
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traldf.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traldf.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traldf.F90	(revision 4946)
@@ -23,6 +23,7 @@
    USE traldf_iso_grif ! lateral mixing          (tra_ldf_iso_grif routine)
    USE traldf_lap      ! lateral mixing               (tra_ldf_lap routine)
-   USE trdmod_oce      ! ocean space and time domain
-   USE trdtra          ! ocean active tracers trends
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
+   !
    USE prtctl          ! Print control
    USE in_out_manager  ! I/O manager
@@ -35,6 +36,6 @@
    PRIVATE
 
-   PUBLIC   tra_ldf         ! called by step.F90 
-   PUBLIC   tra_ldf_init    ! called by opa.F90 
+   PUBLIC   tra_ldf        ! called by step.F90 
+   PUBLIC   tra_ldf_init   ! called by opa.F90 
    !
    INTEGER ::   nldf = 0   ! type of lateral diffusion used defined from ln_traldf_... namlist logicals)
@@ -118,6 +119,6 @@
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
          ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_ldf, ztrdt )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_ldf, ztrds )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_ldf, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_ldf, ztrds )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds ) 
       ENDIF
@@ -180,10 +181,10 @@
             IF ( ln_traldf_iso   )   nldf = 1      ! isoneutral (   rotation)
          ENDIF
-         IF ( ln_zps ) THEN             ! z-coordinate
+         IF ( ln_zps ) THEN             ! zps-coordinate
             IF ( ln_traldf_level )   ierr = 1      ! iso-level not allowed
             IF ( ln_traldf_hor   )   nldf = 0      ! horizontal (no rotation)
             IF ( ln_traldf_iso   )   nldf = 1      ! isoneutral (   rotation)
          ENDIF
-         IF ( ln_sco ) THEN             ! z-coordinate
+         IF ( ln_sco ) THEN             ! s-coordinate
             IF ( ln_traldf_level )   nldf = 0      ! iso-level  (no rotation)
             IF ( ln_traldf_hor   )   nldf = 1      ! horizontal (   rotation)
@@ -198,10 +199,10 @@
             IF ( ln_traldf_iso   )   ierr = 2      ! isoneutral (   rotation)
          ENDIF
-         IF ( ln_zps ) THEN             ! z-coordinate
+         IF ( ln_zps ) THEN             ! zps-coordinate
             IF ( ln_traldf_level )   ierr = 1      ! iso-level not allowed 
             IF ( ln_traldf_hor   )   nldf = 2      ! horizontal (no rotation)
             IF ( ln_traldf_iso   )   ierr = 2      ! isoneutral (   rotation)
          ENDIF
-         IF ( ln_sco ) THEN             ! z-coordinate
+         IF ( ln_sco ) THEN             ! s-coordinate
             IF ( ln_traldf_level )   nldf = 2      ! iso-level  (no rotation)
             IF ( ln_traldf_hor   )   nldf = 3      ! horizontal (   rotation)
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso_grif.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso_grif.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso_grif.F90	(revision 4946)
@@ -252,11 +252,6 @@
          END DO
          IF( ln_zps.and.l_grad_zps ) THEN              ! partial steps: correction at the last level
-# if defined key_vectopt_loop
-            DO jj = 1, 1
-               DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
-# else
             DO jj = 1, jpjm1
                DO ji = 1, jpim1
-# endif
                   zdit(ji,jj,mbku(ji,jj)) = pgu(ji,jj,jn)
                   zdjt(ji,jj,mbkv(ji,jj)) = pgv(ji,jj,jn)
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/tranpc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/tranpc.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/tranpc.F90	(revision 4946)
@@ -2,5 +2,5 @@
    !!==============================================================================
    !!                       ***  MODULE  tranpc  ***
-   !! Ocean active tracers:  non penetrative convection scheme
+   !! Ocean active tracers:  non penetrative convective adjustment scheme
    !!==============================================================================
    !! History :  1.0  ! 1990-09  (G. Madec)  Original code
@@ -9,4 +9,5 @@
    !!            3.0  ! 2008-06  (G. Madec)  applied on ta, sa and called before tranxt in step.F90
    !!            3.3  ! 2010-05  (C. Ethe, G. Madec)  merge TRC-TRA
+   !!            3.7  ! 2014-06  (L. Brodeau) new algorithm based on local Brunt-Vaisala freq.
    !!----------------------------------------------------------------------
 
@@ -14,10 +15,12 @@
    !!   tra_npc : apply the non penetrative convection scheme
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and active tracers 
+   USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
    USE zdf_oce         ! ocean vertical physics
-   USE trdmod_oce      ! ocean active tracer trends
+   USE trd_oce         ! ocean active tracer trends
    USE trdtra          ! ocean active tracer trends
-   USE eosbn2          ! equation of state (eos routine) 
+   USE eosbn2          ! equation of state (eos routine)
+   !
    USE lbclnk          ! lateral boundary conditions (or mpp link)
    USE in_out_manager  ! I/O manager
@@ -29,11 +32,12 @@
    PRIVATE
 
-   PUBLIC   tra_npc       ! routine called by step.F90
+   PUBLIC   tra_npc    ! routine called by step.F90
 
    !! * Substitutions
 #  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.6 , NEMO Consortium (2014)
+   !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -44,44 +48,48 @@
       !!                  ***  ROUTINE tranpc  ***
       !!
-      !! ** Purpose :   Non penetrative convective adjustment scheme. solve 
+      !! ** Purpose : Non-penetrative convective adjustment scheme. solve
       !!      the static instability of the water column on after fields
       !!      while conserving heat and salt contents.
       !!
-      !! ** Method  :   The algorithm used converges in a maximium of jpk 
-      !!      iterations. instabilities are treated when the vertical density
-      !!      gradient is less than 1.e-5.
-      !!      l_trdtra=T: the trend associated with this algorithm is saved.
+      !! ** Method  : updated algorithm able to deal with non-linear equation of state
+      !!              (i.e. static stability computed locally)
       !!
       !! ** Action  : - (ta,sa) after the application od the npc scheme
-      !!              - save the associated trends (ttrd,strd) ('key_trdtra')
+      !!              - send the associated trends for on-line diagnostics (l_trdtra=T)
       !!
-      !! References : Madec, et al., 1991, JPO, 21, 9, 1349-1371.
+      !! References :     Madec, et al., 1991, JPO, 21, 9, 1349-1371.
       !!----------------------------------------------------------------------
-      !
       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), POINTER, DIMENSION(:,:  ) :: zwx, zwy, zwz
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrdt, ztrds, zrhop
+      INTEGER  ::   jiter, ikbot, ik, ikup, ikdown, ilayer, ikm   ! local integers
+      LOGICAL  ::   l_bottom_reached, l_column_treated
+      REAL(wp) ::   zta, zalfa, zsum_temp, zsum_alfa, zaw, zdz, zsum_z
+      REAL(wp) ::   zsa, zbeta, zsum_sali, zsum_beta, zbw, zrw, z1_r2dt
+      REAL(wp), POINTER, DIMENSION(:)       ::   zvn2   ! vertical profile of N2 at 1 given point...
+      REAL(wp), POINTER, DIMENSION(:,:)     ::   zvts   ! vertical profile of T and S at 1 given point...
+      REAL(wp), POINTER, DIMENSION(:,:)     ::   zvab   ! vertical profile of alpha and beta
+      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zn2    ! N^2 
+      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   zab    ! alpha and beta
+      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   ztrdt, ztrds   ! 3D workspace
+      !
+      !!LB debug:
+      LOGICAL, PARAMETER :: l_LB_debug = .FALSE.
+      INTEGER :: ilc1, jlc1, klc1, nncpu
+      LOGICAL :: lp_monitor_point = .FALSE.
+      !!LB debug.
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('tra_npc')
       !
-      CALL wrk_alloc(jpi, jpj, jpk, zrhop )
-      CALL wrk_alloc(jpi, jpk, zwx, zwy, zwz )
-      !
       IF( MOD( kt, nn_npc ) == 0 ) THEN
-
-         inpcc = 0
-         inpci = 0
-
-         CALL eos( tsa, rhd, zrhop, fsdept_n(:,:,:) )         ! Potential density
-
-         IF( l_trdtra )   THEN                    !* Save ta and sa trends
+         !
+         CALL wrk_alloc( jpi, jpj, jpk, zn2 )    ! N2
+         CALL wrk_alloc( jpi, jpj, jpk, 2, zab ) ! Alpha and Beta
+         CALL wrk_alloc( jpk, 2, zvts, zvab )    ! 1D column vector at point ji,jj
+         CALL wrk_alloc( jpk, zvn2 )             ! 1D column vector at point ji,jj
+
+         IF( l_trdtra )   THEN                    !* Save initial after fields
             CALL wrk_alloc( jpi, jpj, jpk, ztrdt, ztrds )
             ztrdt(:,:,:) = tsa(:,:,:,jp_tem) 
@@ -89,135 +97,240 @@
          ENDIF
 
-         !                                                ! ===============
-         DO jj = 1, jpj                                   !  Vertical slab
-            !                                             ! ===============
-            !  Static instability pointer 
-            ! ----------------------------
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  zwx(ji,jk) = ( zrhop(ji,jj,jk) - zrhop(ji,jj,jk+1) ) * tmask(ji,jj,jk+1)
-               END DO
-            END DO
-
-            ! 1.1 do not consider the boundary points
-
-            ! even if east-west cyclic b. c. do not considere ji=1 or jpi
-            DO jk = 1, jpkm1
-               zwx( 1 ,jk) = 0.e0
-               zwx(jpi,jk) = 0.e0
-            END DO
-            ! even if south-symmetric b. c. used, do not considere jj=1
-            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.e0
-               END DO
-            END DO
-
-            zwy(:,1) = 0.e0
-            DO ji = 1, jpi
-               DO jk = 1, jpkm1
-                  zwy(ji,1) = zwy(ji,1) + zwx(ji,jk)
-               END DO
-            END DO
-
-            zwz(1,1) = 0.e0
-            DO ji = 1, jpi
-               zwz(1,1) = zwz(1,1) + zwy(ji,1)
-            END DO
-
-            inpcc = inpcc + NINT( zwz(1,1) )
-
-
-            ! 2. Vertical mixing for each instable portion of the density profil
-            ! ------------------------------------------------------------------
-
-            IF( zwz(1,1) /= 0.e0 ) THEN         ! -->> the density profil is statically instable :
-               DO ji = 1, jpi
-                  IF( zwy(ji,1) /= 0.e0 ) THEN
+         !LB debug:
+         IF( lwp .AND. l_LB_debug ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'LOLO: entering tra_npc, kt, narea =', kt, narea
+         ENDIF
+         !LBdebug: Monitoring of 1 column subject to convection...
+         IF( l_LB_debug ) THEN
+            ! Location of 1 known convection spot to follow what's happening in the water column
+            ilc1 = 54 ;  jlc1 = 15 ; ! Labrador ORCA1 4x4 cpus:
+            nncpu = 15  ; ! the CPU domain contains the convection spot
+            !ilc1 = 14 ;  jlc1 = 13 ; ! Labrador ORCA1 8x8 cpus:
+            !nncpu = 54  ; ! the CPU domain contains the convection spot
+            klc1 =  mbkt(ilc1,jlc1) ! bottom of the ocean for debug point...          
+         ENDIF
+         !LBdebug.
+
+         CALL eos_rab( tsa, zab )         ! after alpha and beta
+         CALL bn2    ( tsa, zab, zn2 )    ! after Brunt-Vaisala
+        
+         inpcc = 0
+
+         DO jj = 2, jpjm1                 ! interior column only
+            DO ji = fs_2, fs_jpim1
+               !
+               IF( tmask(ji,jj,2) == 1 ) THEN      ! At least 2 ocean points
+                  !                                     ! consider one ocean column 
+                  zvts(:,jp_tem) = tsa(ji,jj,:,jp_tem)      ! temperature
+                  zvts(:,jp_sal) = tsa(ji,jj,:,jp_sal)      ! salinity
+
+                  zvab(:,jp_tem)  = zab(ji,jj,:,jp_tem)     ! Alpha 
+                  zvab(:,jp_sal)  = zab(ji,jj,:,jp_sal)     ! Beta  
+                  zvn2(:)         = zn2(ji,jj,:)            ! N^2 
+                 
+                  IF( l_LB_debug ) THEN                  !LB debug:
+                     lp_monitor_point = .FALSE.
+                     IF( ( ji == ilc1 ).AND.( jj == jlc1 ) ) lp_monitor_point = .TRUE.
+                     ! writing only if on CPU domain where conv region is:
+                     lp_monitor_point = (narea == nncpu).AND.lp_monitor_point 
+                     
+                     IF(lp_monitor_point) THEN
+                        WRITE(numout,*) '' ;WRITE(numout,*) '' ;
+                       WRITE(numout,'("Time step = ",i6.6," !!!")')  kt
+                        WRITE(numout,'(" *** BEFORE anything, N^2 for point ",i3,",",i3,":" )') ji,jj
+                        DO jk = 1, klc1
+                           WRITE(numout,*) jk, zvn2(jk)
+                        END DO
+                        WRITE(numout,*) ' '
+                     ENDIF
+                  ENDIF                                  !LB debug  end
+
+                  ikbot = mbkt(ji,jj)   ! ikbot: ocean bottom T-level
+                  ik = 1                ! because N2 is irrelevant at the surface level (will start at ik=2)
+                  ilayer = 0
+                  jiter  = 0
+                  l_column_treated = .FALSE.
+                 
+                  DO WHILE ( .NOT. l_column_treated )
                      !
-                     ikbot = mbkt(ji,jj)        ! ikbot: ocean bottom T-level
+                     jiter = jiter + 1
+                    
+                     IF( jiter >= 400 ) EXIT
+                    
+                     l_bottom_reached = .FALSE.
+
+                     DO WHILE ( .NOT. l_bottom_reached )
+
+                        ik = ik + 1
+                       
+                        !! Checking level ik for instability
+                        !! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+                        IF( zvn2(ik) < 0. ) THEN ! Instability found!
+
+                           ikm  = ik              ! first level whith negative N2
+                           ilayer = ilayer + 1    ! yet another layer found....
+                           IF(jiter == 1) inpcc = inpcc + 1
+
+                           IF(l_LB_debug .AND. lp_monitor_point) &
+                              & WRITE(numout,*) 'Negative N2 at ik =', ikm, ' layer nb.', ilayer, &
+                              & ' inpcc =', inpcc
+
+                           !! Case we mix with upper regions where N2==0:
+                           !! All the points above ikup where N2 == 0 must also be mixed => we go
+                           !! upward to find a new ikup, where the layer doesn't have N2==0
+                           ikup = ikm
+                           DO jk = ikm, 2, -1
+                              ikup = ikup - 1
+                              IF( (zvn2(jk-1) > 0.).OR.(ikup == 1) ) EXIT
+                           END DO
+                          
+                           ! adjusting ikup if the upper part of the unstable column was neutral (N2=0)
+                           IF((zvn2(ikup+1) == 0.).AND.(ikup /= 1)) ikup = ikup+1 ;
+
+                          
+                           IF( lp_monitor_point )   WRITE(numout,*) ' => ikup is =', ikup, ' layer nb.', ilayer
+                          
+                           zsum_temp = 0._wp
+                           zsum_sali = 0._wp
+                           zsum_alfa = 0._wp
+                           zsum_beta = 0._wp
+                           zsum_z    = 0._wp
+                                                    
+                           DO jk = ikup, ikbot+1      ! Inside the instable (and overlying neutral) portion of the column
+                              !
+                              IF(l_LB_debug .AND. lp_monitor_point) WRITE(numout,*) '     -> summing for jk =', jk
+                              !
+                              zdz       = fse3t(ji,jj,jk)
+                              zsum_temp = zsum_temp + zvts(jk,jp_tem)*zdz
+                              zsum_sali = zsum_sali + zvts(jk,jp_sal)*zdz
+                              zsum_alfa = zsum_alfa + zvab(jk,jp_tem)*zdz
+                              zsum_beta = zsum_beta + zvab(jk,jp_sal)*zdz
+                              zsum_z    = zsum_z    + zdz
+                              !
+                              !! EXIT if we found the bottom of the unstable portion of the water column    
+                              IF( (zvn2(jk+1) > 0.).OR.(jk == ikbot ).OR.((jk==ikm).AND.(zvn2(jk+1) == 0.)) )   EXIT
+                           END DO
+                          
+                           !ik     = jk !LB remove?
+                           ikdown = jk ! for the current unstable layer, ikdown is the deepest point with a negative N2
+                          
+                           IF(l_LB_debug .AND. lp_monitor_point) &
+                              &    WRITE(numout,*) '  => ikdown =', ikdown, '  layer nb.', ilayer
+                          
+                           ! Mixing Temperature and salinity between ikup and ikdown:
+                           zta   = zsum_temp/zsum_z
+                           zsa   = zsum_sali/zsum_z
+                           zalfa = zsum_alfa/zsum_z
+                           zbeta = zsum_beta/zsum_z
+
+                           IF(l_LB_debug .AND. lp_monitor_point) THEN
+                              WRITE(numout,*) '  => Mean temp. in that portion =', zta
+                              WRITE(numout,*) '  => Mean sali. in that portion =', zsa
+                              WRITE(numout,*) '  => Mean Alpha in that portion =', zalfa
+                              WRITE(numout,*) '  => Mean Beta  in that portion =', zbeta
+                           ENDIF
+
+                           !! Homogenaizing the temperature, salinity, alpha and beta in this portion of the column
+                           DO jk = ikup, ikdown
+                              zvts(jk,jp_tem) = zta
+                              zvts(jk,jp_sal) = zsa
+                              zvab(jk,jp_tem) = zalfa
+                              zvab(jk,jp_sal) = zbeta
+                           END DO
+                           !
+                           !! Before updating N2, it is possible that another unstable
+                           !! layer exists underneath the one we just homogeneized!
+                           ik = ikdown
+                           ! 
+                        ENDIF  ! IF( zvn2(ik+1) < 0. ) THEN
+                        !
+                        IF( ik == ikbot ) l_bottom_reached = .TRUE.
+                        !
+                     END DO ! DO WHILE ( .NOT. l_bottom_reached )
+
+                     IF( ik /= ikbot )   STOP 'ERROR: tranpc.F90 => PROBLEM #1'
+                    
+                     ! ******* At this stage ik == ikbot ! *******
+                    
+                     IF( ilayer > 0 ) THEN
+                        !! least an unstable layer has been found
+                        !! Temperature, Salinity, Alpha and Beta have been homogenized in the unstable portion
+                        !! => Need to re-compute N2! will use Alpha and Beta!
+                        !
+                        DO jk = ikup+1, ikdown+1   ! we must go 1 point deeper than ikdown!     
+                           !! Doing exactly as in eosbn2.F90:
+                           !! * Except that we only are interested in the sign of N2 !!!
+                           !!   => just considering the vertical gradient of density
+                           zrw =   (fsdepw(ji,jj,jk  ) - fsdept(ji,jj,jk)) &
+                               & / (fsdept(ji,jj,jk-1) - fsdept(ji,jj,jk))
+                           zaw = zvab(jk,jp_tem) * (1._wp - zrw) + zvab(jk-1,jp_tem) * zrw
+                           zbw = zvab(jk,jp_sal) * (1._wp - zrw) + zvab(jk-1,jp_sal) * zrw
+                          
+                           !zvn2(jk) = grav*( zaw * ( zvts(jk-1,jp_tem) - zvts(jk,jp_tem) )     &
+                           !     &           - zbw * ( zvts(jk-1,jp_sal) - zvts(jk,jp_sal) )  )  &
+                           !     &       / fse3w(ji,jj,jk) * tmask(ji,jj,jk)
+                           zvn2(jk) = (  zaw * ( zvts(jk-1,jp_tem) - zvts(jk,jp_tem) )     &
+                                &      - zbw * ( zvts(jk-1,jp_sal) - zvts(jk,jp_sal) )  )  
+                        END DO
+
+                        IF(l_LB_debug .AND. lp_monitor_point) THEN
+                           WRITE(numout, '(" *** After iteration #",i3.3,", N^2 for point ",i3,",",i3,":" )') &
+                              & jiter, ji,jj
+                           DO jk = 1, klc1
+                              WRITE(numout,*) jk, zvn2(jk)
+                           END DO
+                           WRITE(numout,*) ' '
+                        ENDIF
+
+                        ik     = 1  ! starting again at the surface for the next iteration
+                        ilayer = 0
+                     ENDIF
                      !
-                     DO jiter = 1, jpk          ! vertical iteration
-                        !
-                        ! search of ikup : the first static instability from the sea surface
-                        !
-                        ik = 0
-220                     CONTINUE
-                        ik = ik + 1
-                        IF( ik >= ikbot ) GO TO 200
-                        zwx(ji,ik) = zrhop(ji,jj,ik) - zrhop(ji,jj,ik+1)
-                        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   = tsa  (ji,jj,ikup,jp_tem)
-                        zsa   = tsa  (ji,jj,ikup,jp_sal)
-                        zraua = zrhop(ji,jj,ikup)
-                        !
-                        DO jkdown = ikup+1, ikbot-1
-                           IF( zraua <= zrhop(ji,jj,jkdown) ) THEN
-                              ikdown = jkdown
-                              GO TO 240
-                           ENDIF
-                           ze3dwn =  fse3t(ji,jj,jkdown)
-                           ze3tot =  ze3tot + ze3dwn
-                           zta   = ( zta*(ze3tot-ze3dwn) + tsa(ji,jj,jkdown,jp_tem)*ze3dwn )/ze3tot
-                           zsa   = ( zsa*(ze3tot-ze3dwn) + tsa(ji,jj,jkdown,jp_sal)*ze3dwn )/ze3tot
-                           zraua = ( zraua*(ze3tot-ze3dwn) + zrhop(ji,jj,jkdown)*ze3dwn )/ze3tot
-                           inpci = inpci+1
-                        END DO
-                        ikdown = ikbot-1
-240                     CONTINUE
-                        !
-                        DO jkp = ikup, ikdown-1
-                           tsa  (ji,jj,jkp,jp_tem) = zta
-                           tsa  (ji,jj,jkp,jp_sal) = zsa
-                           zrhop(ji,jj,jkp       ) = zraua
-                        END DO
-                        IF (ikdown == ikbot-1 .AND. zraua >= zrhop(ji,jj,ikdown) ) THEN
-                           tsa  (ji,jj,jkp,jp_tem) = zta
-                           tsa  (ji,jj,jkp,jp_sal) = zsa
-                           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
-         !                                                ! ===============
-         ! 
-         IF( l_trdtra )   THEN         ! save the Non penetrative mixing trends for diagnostic
-            ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
-            ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
-            CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_npc, ztrdt )
-            CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_npc, ztrds )
+                     IF( ik >= ikbot ) THEN
+                        IF(l_LB_debug .AND. lp_monitor_point) WRITE(numout,*) '    --- exiting jiter loop ---'
+                        l_column_treated = .TRUE.
+                     ENDIF
+                     !
+                  END DO ! DO WHILE ( .NOT. l_column_treated )
+
+                  !! Updating tsa:
+                  tsa(ji,jj,:,jp_tem) = zvts(:,jp_tem)
+                  tsa(ji,jj,:,jp_sal) = zvts(:,jp_sal)
+
+                  !! lolo:  Should we update something else????
+                  !! => like alpha and beta?
+
+                  IF(l_LB_debug .AND. lp_monitor_point) WRITE(numout,*) ''
+
+               ENDIF ! IF( tmask(ji,jj,3) == 1 ) THEN
+
+            END DO ! ji
+         END DO ! jj
+         !
+         IF( l_trdtra ) THEN         ! send the Non penetrative mixing trends for diagnostic
+            z1_r2dt = 1._wp / (2._wp * rdt)
+            ztrdt(:,:,:) = ( tsa(:,:,:,jp_tem) - ztrdt(:,:,:) ) * z1_r2dt
+            ztrds(:,:,:) = ( tsa(:,:,:,jp_sal) - ztrds(:,:,:) ) * z1_r2dt
+            CALL trd_tra( kt, 'TRA', jp_tem, jptra_npc, ztrdt )
+            CALL trd_tra( kt, 'TRA', jp_sal, jptra_npc, ztrds )
             CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
          ENDIF
-      
-         ! Lateral boundary conditions on ( ta, sa )   ( Unchanged sign)
-         ! ------------------------------============
+         !
          CALL lbc_lnk( tsa(:,:,:,jp_tem), 'T', 1. )   ;   CALL lbc_lnk( tsa(:,:,:,jp_sal), 'T', 1. )
-      
-
-         !  2. non penetrative convective scheme statistics
-         !  -----------------------------------------------
-         IF( nn_npcp /= 0 .AND. MOD( kt, nn_npcp ) == 0 ) THEN
-            IF(lwp) WRITE(numout,*)' kt=',kt, ' number of statically instable',   &
-               &                   ' water column : ',inpcc, ' number of iteration : ',inpci
-         ENDIF
-         !
-      ENDIF
-      !
-      CALL wrk_dealloc(jpi, jpj, jpk, zrhop )
-      CALL wrk_dealloc(jpi, jpk, zwx, zwy, zwz )
+         !
+         IF(lwp) THEN
+            WRITE(numout,*) 'LOLO: exiting tra_npc, kt =', kt
+            WRITE(numout,*)' => number of statically instable water column : ',inpcc
+            WRITE(numout,*) '' ; WRITE(numout,*) ''
+         ENDIF
+         !
+         CALL wrk_dealloc(jpi, jpj, jpk, zn2 )
+         CALL wrk_dealloc(jpi, jpj, jpk, 2, zab )
+         CALL wrk_dealloc(jpk, zvn2 )
+         CALL wrk_dealloc(jpk, 2, zvts, zvab )
+         !
+      ENDIF   ! IF( MOD( kt, nn_npc ) == 0 ) THEN
       !
       IF( nn_timing == 1 )  CALL timing_stop('tra_npc')
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 4946)
@@ -27,23 +27,25 @@
    USE dom_oce         ! ocean space and time domain variables 
    USE sbc_oce         ! surface boundary condition: ocean
-   USE zdf_oce         ! ???
+   USE zdf_oce         ! ocean vertical mixing
    USE domvvl          ! variable volume
    USE dynspg_oce      ! surface     pressure gradient variables
    USE dynhpg          ! hydrostatic pressure gradient 
-   USE trdmod_oce      ! ocean space and time domain variables 
-   USE trdtra          ! ocean active tracers trends 
-   USE phycst
-   USE bdy_oce
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
+   USE traqsr          ! penetrative solar radiation (needed for nksr)
+   USE phycst          ! physical constant
+   USE ldftra_oce      ! lateral physics on tracers
+   USE bdy_oce         ! BDY open boundary condition variables
    USE bdytra          ! open boundary condition (bdy_tra routine)
+   !
    USE in_out_manager  ! I/O manager
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE prtctl          ! Print control
-   USE traqsr          ! penetrative solar radiation (needed for nksr)
+   USE wrk_nemo        ! Memory allocation
+   USE timing          ! Timing
 #if defined key_agrif
    USE agrif_opa_update
    USE agrif_opa_interp
 #endif
-   USE wrk_nemo        ! Memory allocation
-   USE timing          ! Timing
 
    IMPLICIT NONE
@@ -80,5 +82,5 @@
       !!             at the local domain   boundaries through lbc_lnk call, 
       !!             at the one-way open boundaries (lk_bdy=T), 
-      !!             at the AGRIF zoom     boundaries (lk_agrif=T)
+      !!             at the AGRIF zoom   boundaries (lk_agrif=T)
       !!
       !!              - Update lateral boundary conditions on AGRIF children
@@ -127,4 +129,8 @@
          ztrdt(:,:,:) = tsn(:,:,:,jp_tem) 
          ztrds(:,:,:) = tsn(:,:,:,jp_sal)
+         IF( ln_traldf_iso ) THEN              ! diagnose the "pure" Kz diffusive trend 
+            CALL trd_tra( kt, 'TRA', jp_tem, jptra_zdfp, ztrdt )
+            CALL trd_tra( kt, 'TRA', jp_sal, jptra_zdfp, ztrds )
+         ENDIF
       ENDIF
 
@@ -150,10 +156,10 @@
       IF( l_trdtra ) THEN      ! trend of the Asselin filter (tb filtered - tb)/dt     
          DO jk = 1, jpkm1
-            zfact = 1.e0_wp / r2dtra(jk)             
+            zfact = 1._wp / r2dtra(jk)             
             ztrdt(:,:,jk) = ( tsb(:,:,jk,jp_tem) - ztrdt(:,:,jk) ) * zfact
             ztrds(:,:,jk) = ( tsb(:,:,jk,jp_sal) - ztrds(:,:,jk) ) * zfact
          END DO
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_atf, ztrdt )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_atf, ztrds )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_atf, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_atf, ztrds )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
       END IF
@@ -163,6 +169,5 @@
          &                       tab3d_2=tsn(:,:,:,jp_sal), clinfo2=       ' Sn: ', mask2=tmask )
       !
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_nxt')
+      IF( nn_timing == 1 )   CALL timing_stop('tra_nxt')
       !
    END SUBROUTINE tra_nxt
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 4946)
@@ -21,6 +21,6 @@
    USE sbc_oce         ! surface boundary condition: ocean
    USE trc_oce         ! share SMS/Ocean variables
-   USE trdmod_oce      ! ocean variables trends
-   USE trdtra          ! ocean active tracers trends 
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! trends manager: tracers
    USE in_out_manager  ! I/O manager
    USE phycst          ! physical constants
@@ -169,6 +169,5 @@
                DO ji = 1, jpi
                   IF ( qsr(ji,jj) /= 0._wp ) THEN
-                     oatte(ji,jj) = ( qsr_hc(ji,jj,1) / ( r1_rau0_rcp * qsr(ji,jj) ) )
-                     iatte(ji,jj) = oatte(ji,jj)
+                     fraqsr_1lev(ji,jj) = ( qsr_hc(ji,jj,1) / ( r1_rau0_rcp * qsr(ji,jj) ) )
                   ENDIF
                END DO
@@ -241,6 +240,5 @@
                         zzc2 = zcoef  * EXP( - fse3t(ji,jj,1) * zekg(ji,jj) )
                         zzc3 = zcoef  * EXP( - fse3t(ji,jj,1) * zekr(ji,jj) )
-                        oatte(ji,jj) = 1.0 - ( zzc0 + zzc1 + zzc2  + zzc3  ) * tmask(ji,jj,2) 
-                        iatte(ji,jj) = 1.0 - ( zzc0 + zzc1 + zcoef + zcoef ) * tmask(ji,jj,2)
+                        fraqsr_1lev(ji,jj) = 1.0 - ( zzc0 + zzc1 + zzc2  + zzc3  ) * tmask(ji,jj,2) 
                      END DO
                   END DO
@@ -259,6 +257,5 @@
                ! clem: store attenuation coefficient of the first ocean level
                IF ( lk_lim3 .AND. ln_qsr_ice ) THEN
-                  oatte(:,:) = etot3(:,:,1) / r1_rau0_rcp
-                  iatte(:,:) = oatte(:,:)
+                  fraqsr_1lev(:,:) = etot3(:,:,1) / r1_rau0_rcp
                ENDIF
            ENDIF
@@ -287,6 +284,5 @@
                         zc0 = zz0 * EXP( -fsdepw(ji,jj,1)*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,1)*xsi1r )
                         zc1 = zz0 * EXP( -fsdepw(ji,jj,2)*xsi0r ) + zz1 * EXP( -fsdepw(ji,jj,2)*xsi1r )
-                        oatte(ji,jj) = ( zc0*tmask(ji,jj,1) - zc1*tmask(ji,jj,2) ) / r1_rau0_rcp
-                        iatte(ji,jj) = oatte(ji,jj)
+                        fraqsr_1lev(ji,jj) = ( zc0*tmask(ji,jj,1) - zc1*tmask(ji,jj,2) ) / r1_rau0_rcp
                      END DO
                   END DO
@@ -303,6 +299,5 @@
                ! clem: store attenuation coefficient of the first ocean level
                IF ( lk_lim3 .AND. ln_qsr_ice ) THEN
-                  oatte(:,:) = etot3(:,:,1) / r1_rau0_rcp
-                  iatte(:,:) = oatte(:,:)
+                  fraqsr_1lev(:,:) = etot3(:,:,1) / r1_rau0_rcp
                ENDIF
                !
@@ -335,5 +330,5 @@
       IF( l_trdtra ) THEN     ! qsr tracers trends saved for diagnostics
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_qsr, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_qsr, ztrdt )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt ) 
       ENDIF
@@ -385,8 +380,7 @@
       IF( nn_timing == 1 )  CALL timing_start('tra_qsr_init')
       !
-      ! clem init for oatte and iatte
+      ! Default value for fraqsr_1lev
       IF( .NOT. ln_rstart ) THEN
-         oatte(:,:) = 1._wp
-         iatte(:,:) = 1._wp
+         fraqsr_1lev(:,:) = 1._wp
       ENDIF
       !
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 4946)
@@ -18,7 +18,10 @@
    USE dom_oce         ! ocean space domain variables
    USE phycst          ! physical constant
+   USE sbcmod          ! ln_rnf  
+   USE sbcrnf          ! River runoff  
    USE traqsr          ! solar radiation penetration
-   USE trdmod_oce      ! ocean trends 
-   USE trdtra          ! ocean trends
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
+   !
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
@@ -41,5 +44,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -93,5 +96,5 @@
       !!         where emp, the surface freshwater budget (evaporation minus
       !!         precipitation minus runoff) given in kg/m2/s is divided
-      !!         by rau0 = 1020 kg/m3 (density of sea water) to obtain m/s.    
+      !!         by rau0 (density of sea water) to obtain m/s.    
       !!         Note: even though Fwe does not appear explicitly for 
       !!         temperature in this routine, the heat carried by the water
@@ -109,5 +112,5 @@
       !! ** Action  : - Update the 1st level of (ta,sa) with the trend associated
       !!                with the tracer surface boundary condition 
-      !!              - save the trend it in ttrd ('key_trdtra')
+      !!              - send trends to trdtra module (l_trdtra=T)
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
@@ -130,5 +133,5 @@
       ENDIF
 
-      IF( l_trdtra )   THEN                    !* Save ta and sa trends
+      IF( l_trdtra ) THEN                    !* Save ta and sa trends
          CALL wrk_alloc( jpi, jpj, jpk, ztrdt, ztrds ) 
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
@@ -143,5 +146,5 @@
 
       !----------------------------------------
-      !        EMP, EMPS and QNS effects
+      !        EMP, SFX and QNS effects
       !----------------------------------------
       !                                          Set before sbc tracer content fields
@@ -152,14 +155,14 @@
               & iom_varid( numror, 'sbc_hc_b', ldstop = .FALSE. ) > 0 ) THEN
             IF(lwp) WRITE(numout,*) '          nit000-1 surface tracer content forcing fields red in the restart file'
-            zfact = 0.5e0
+            zfact = 0.5_wp
             CALL iom_get( numror, jpdom_autoglo, 'sbc_hc_b', sbc_tsc_b(:,:,jp_tem) )   ! before heat content sbc trend
             CALL iom_get( numror, jpdom_autoglo, 'sbc_sc_b', sbc_tsc_b(:,:,jp_sal) )   ! before salt content sbc trend
          ELSE                                         ! No restart or restart not found: Euler forward time stepping
-            zfact = 1.e0
-            sbc_tsc_b(:,:,:) = 0.e0
+            zfact = 1._wp
+            sbc_tsc_b(:,:,:) = 0._wp
          ENDIF
       ELSE                                         ! Swap of forcing fields
          !                                         ! ----------------------
-         zfact = 0.5e0
+         zfact = 0.5_wp
          sbc_tsc_b(:,:,:) = sbc_tsc(:,:,:)
       ENDIF
@@ -217,5 +220,5 @@
       !----------------------------------------
       !
-      IF (nn_isf .GT. 0) THEN
+      IF( nn_isf > 0 ) THEN
          zfact = 0.5e0
          DO jj = 2, jpj
@@ -231,5 +234,5 @@
                ! compute tfreez for the temperature correction (we add water at freezing temperature)
 !                  zpress = grav*rau0*fsdept(ji,jj,jk)*1.e-04
-                  zt_frz = -1.9 !tfreez1D( tsn(ji,jj,jk,jp_sal), zpress )
+                  zt_frz = -1.9 !eos_fzp( tsn(ji,jj,jk,jp_sal), zpress )
                ! compute trend
                   tsa(ji,jj,jk,jp_tem) = tsa(ji,jj,jk,jp_tem)                                          &
@@ -244,5 +247,5 @@
                ! compute tfreez for the temperature correction (we add water at freezing temperature)
 !               zpress = grav*rau0*fsdept(ji,jj,ikb)*1.e-04
-               zt_frz = -1.9 !tfreez1D( tsn(ji,jj,ikb,jp_sal), zpress )
+               zt_frz = -1.9 !eos_fzp( tsn(ji,jj,ikb,jp_sal), zpress )
                ! compute trend
                tsa(ji,jj,ikb,jp_tem) = tsa(ji,jj,ikb,jp_tem)                                           &
@@ -286,9 +289,9 @@
       ENDIF
  
-      IF( l_trdtra )   THEN                      ! save the horizontal diffusive trends for further diagnostics
+      IF( l_trdtra )   THEN                      ! send trends for further diagnostics
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
          ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_nsr, ztrdt )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_nsr, ztrds )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_nsr, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_nsr, ztrds )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds ) 
       ENDIF
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90	(revision 4946)
@@ -19,11 +19,10 @@
    USE sbc_oce         ! surface boundary condition: ocean
    USE dynspg_oce
-
    USE trazdf_exp      ! vertical diffusion: explicit (tra_zdf_exp     routine)
    USE trazdf_imp      ! vertical diffusion: implicit (tra_zdf_imp     routine)
-
    USE ldftra_oce      ! ocean active tracers: lateral physics
-   USE trdmod_oce      ! ocean active tracers: lateral physics
-   USE trdtra      ! ocean tracers trends 
+   USE trd_oce         ! trends: ocean variables
+   USE trdtra          ! trends manager: tracers 
+   !
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
@@ -32,5 +31,4 @@
    USE wrk_nemo        ! Memory allocation
    USE timing          ! Timing
-
 
    IMPLICIT NONE
@@ -47,5 +45,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -96,6 +94,8 @@
             ztrds(:,:,jk) = ( ( tsa(:,:,jk,jp_sal) - tsb(:,:,jk,jp_sal) ) / r2dtra(jk) ) - ztrds(:,:,jk)
          END DO
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_zdf, ztrdt )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_zdf, ztrds )
+         CALL lbc_lnk( ztrdt, 'T', 1. )
+         CALL lbc_lnk( ztrds, 'T', 1. )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_zdf, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_zdf, ztrds )
          CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
       ENDIF
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/zpshde.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/zpshde.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRA/zpshde.F90	(revision 4946)
@@ -75,9 +75,9 @@
       !!          Idem for di(s) and dj(s)          
       !!
-      !!      For rho, we call eos_insitu_2d which will compute rd~(t~,s~) at 
-      !!      the good depth zh from interpolated T and S for the different
-      !!      formulation of the equation of state (eos).
+      !!      For rho, we call eos which will compute rd~(t~,s~) at the right
+      !!      depth zh from interpolated T and S for the different formulations
+      !!      of the equation of state (eos).
       !!      Gradient formulation for rho :
-      !!          di(rho) = rd~ - rd(i,j,k) or rd(i+1,j,k) - rd~
+      !!          di(rho) = rd~ - rd(i,j,k)   or   rd(i+1,j,k) - rd~
       !!
       !! ** Action  : compute for top and bottom interfaces
@@ -88,5 +88,4 @@
       !!              - pge3ru, pge3rv, sge3ru, sge3rv: horizontal gradient of rho weighted by local e3w at u- & v-points 
       !!----------------------------------------------------------------------
-      !
       INTEGER                              , INTENT(in   )           ::  kt          ! ocean time-step index
       INTEGER                              , INTENT(in   )           ::  kjpt        ! number of tracers
@@ -107,24 +106,16 @@
       INTEGER  ::   iku, ikv, ikum1, ikvm1,ikup1, ikvp1   ! partial step level (ocean bottom level) at u- and v-points
       REAL(wp) ::  ze3wu, ze3wv, zmaxu, zmaxv, zdzwu, zdzwv, zdzwuip1, zdzwvjp1  ! temporary scalars
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::  zri, zrj, zhi, zhj
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zti, ztj    ! interpolated value of tracer
+      REAL(wp), DIMENSION(jpi,jpj)      ::  zri, zrj, zhi, zhj   ! NB: 3rd dim=1 to use eos
+      REAL(wp), DIMENSION(jpi,jpj,kjpt) ::  zti, ztj             ! 
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start( 'zps_hde')
       !
-      CALL wrk_alloc( jpi, jpj,       zri, zrj, zhi, zhj ) 
-      CALL wrk_alloc( jpi, jpj, kjpt, zti, ztj           ) 
-      !
       pgtu(:,:,:)=0.0_wp ; pgtv(:,:,:)=0.0_wp ;
       !
       DO jn = 1, kjpt      !==   Interpolation of tracers at the last ocean level   ==!
          !
-# if defined key_vectopt_loop
-         jj = 1
-         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolled)
-# else
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-# endif
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
                iku = mbku(ji,jj)   ;   ikum1 = MAX( iku - 1 , 1 )    ! last and before last ocean level at u- & v-points
                ikv = mbkv(ji,jj)   ;   ikvm1 = MAX( ikv - 1 , 1 )    ! if level first is a p-step, ik.m1=1
@@ -138,38 +129,36 @@
                ! i- direction
                IF (iku .GT. 1) THEN
-               IF( ze3wu >= 0._wp ) THEN      ! case 1
-                  zmaxu =  ze3wu / fse3w(ji+1,jj,iku)
-                  ! interpolated values of tracers
-                  zti(ji,jj,jn) = pta(ji+1,jj,iku,jn) + zmaxu * ( pta(ji+1,jj,ikum1,jn) - pta(ji+1,jj,iku,jn) )
-                  ! gradient of  tracers
-                  pgtu(ji,jj,jn) = umask(ji,jj,iku) * ( zti(ji,jj,jn) - pta(ji,jj,iku,jn) )
-               ELSE                           ! case 2
-                  zmaxu = -ze3wu / fse3w(ji,jj,iku)
-                  ! interpolated values of tracers
-                  zti(ji,jj,jn) = pta(ji,jj,iku,jn) + zmaxu * ( pta(ji,jj,ikum1,jn) - pta(ji,jj,iku,jn) )
-                  ! gradient of tracers
-                  pgtu(ji,jj,jn) = umask(ji,jj,iku) * ( pta(ji+1,jj,iku,jn) - zti(ji,jj,jn) )
-               ENDIF
+                  IF( ze3wu >= 0._wp ) THEN      ! case 1
+                     zmaxu =  ze3wu / fse3w(ji+1,jj,iku)
+                     ! interpolated values of tracers
+                     zti (ji,jj,jn) = pta(ji+1,jj,iku,jn) + zmaxu * ( pta(ji+1,jj,ikum1,jn) - pta(ji+1,jj,iku,jn) )
+                     ! gradient of  tracers
+                     pgtu(ji,jj,jn) = umask(ji,jj,iku) * ( zti(ji,jj,jn) - pta(ji,jj,iku,jn) )
+                  ELSE                           ! case 2
+                     zmaxu = -ze3wu / fse3w(ji,jj,iku)
+                     ! interpolated values of tracers
+                     zti (ji,jj,jn) = pta(ji,jj,iku,jn) + zmaxu * ( pta(ji,jj,ikum1,jn) - pta(ji,jj,iku,jn) )
+                     ! gradient of tracers
+                     pgtu(ji,jj,jn) = umask(ji,jj,iku) * ( pta(ji+1,jj,iku,jn) - zti(ji,jj,jn) )
+                  ENDIF
                ENDIF
                !
                ! j- direction
                IF (ikv .GT. 1) THEN
-               IF( ze3wv >= 0._wp ) THEN      ! case 1
-                  zmaxv =  ze3wv / fse3w(ji,jj+1,ikv)
-                  ! interpolated values of tracers
-                  ztj(ji,jj,jn) = pta(ji,jj+1,ikv,jn) + zmaxv * ( pta(ji,jj+1,ikvm1,jn) - pta(ji,jj+1,ikv,jn) )
-                  ! gradient of tracers
-                  pgtv(ji,jj,jn) = vmask(ji,jj,ikv) * ( ztj(ji,jj,jn) - pta(ji,jj,ikv,jn) )
-               ELSE                           ! case 2
-                  zmaxv =  -ze3wv / fse3w(ji,jj,ikv)
-                  ! interpolated values of tracers
-                  ztj(ji,jj,jn) = pta(ji,jj,ikv,jn) + zmaxv * ( pta(ji,jj,ikvm1,jn) - pta(ji,jj,ikv,jn) )
-                  ! gradient of tracers
-                  pgtv(ji,jj,jn) = vmask(ji,jj,ikv) * ( pta(ji,jj+1,ikv,jn) - ztj(ji,jj,jn) )
-               ENDIF
-               ENDIF
-# if ! defined key_vectopt_loop
-            END DO
-# endif
+                  IF( ze3wv >= 0._wp ) THEN      ! case 1
+                     zmaxv =  ze3wv / fse3w(ji,jj+1,ikv)
+                     ! interpolated values of tracers
+                     ztj (ji,jj,jn) = pta(ji,jj+1,ikv,jn) + zmaxv * ( pta(ji,jj+1,ikvm1,jn) - pta(ji,jj+1,ikv,jn) )
+                     ! gradient of tracers
+                     pgtv(ji,jj,jn) = vmask(ji,jj,ikv) * ( ztj(ji,jj,jn) - pta(ji,jj,ikv,jn) )
+                  ELSE                           ! case 2
+                     zmaxv =  -ze3wv / fse3w(ji,jj,ikv)
+                     ! interpolated values of tracers
+                     ztj (ji,jj,jn) = pta(ji,jj,ikv,jn) + zmaxv * ( pta(ji,jj,ikvm1,jn) - pta(ji,jj,ikv,jn) )
+                     ! gradient of tracers
+                     pgtv(ji,jj,jn) = vmask(ji,jj,ikv) * ( pta(ji,jj+1,ikv,jn) - ztj(ji,jj,jn) )
+                  ENDIF
+              ENDIF
+            END DO
          END DO
          CALL lbc_lnk( pgtu(:,:,jn), 'U', -1. )   ;   CALL lbc_lnk( pgtv(:,:,jn), 'V', -1. )   ! Lateral boundary cond.
@@ -180,11 +169,6 @@
       IF( PRESENT( prd ) ) THEN         ! depth of the partial step level
          pgru(:,:)=0.0_wp ; pgrv(:,:)=0.0_wp 
-# if defined key_vectopt_loop
-         jj = 1
-         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolled)
-# else
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-# endif
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
                iku = mbku(ji,jj)
                ikv = mbkv(ji,jj)
@@ -198,7 +182,5 @@
                ELSE                        ;   zhj(ji,jj) = fsdept(ji,jj  ,ikv) + ze3wv    ! -     -      case 2
                ENDIF
-# if ! defined key_vectopt_loop
-            END DO
-# endif
+            END DO
          END DO
          
@@ -209,11 +191,6 @@
 
          ! Gradient of density at the last level 
-# if defined key_vectopt_loop
-         jj = 1
-         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolled)
-# else
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-# endif
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
                iku = mbku(ji,jj) ; ikum1 = MAX( iku - 1 , 1 )    ! last and before last ocean level at u- & v-points
                ikv = mbkv(ji,jj) ; ikvm1 = MAX( ikv - 1 , 1 )    ! last and before last ocean level at u- & v-points
@@ -250,7 +227,5 @@
                                    -(fse3w(ji,jj  ,ikv) + ze3wv) * ( zrj(ji,jj      ) + prd(ji,jj  ,ikvm1) + 2._wp) )  ! j: 2
                ENDIF
-# if ! defined key_vectopt_loop
-            END DO
-# endif
+            END DO
          END DO
          CALL lbc_lnk( pgru   , 'U', -1. )   ;   CALL lbc_lnk( pgrv   , 'V', -1. )   ! Lateral boundary conditions
@@ -262,11 +237,6 @@
          ! (ISH)  compute grui and gruvi
       DO jn = 1, kjpt      !==   Interpolation of tracers at the last ocean level   ==!            !
-# if defined key_vectopt_loop
-         jj = 1
-         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolled)
-# else
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-# endif
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
                iku = miku(ji,jj)   ;  ikup1 = miku(ji,jj) + 1
                ikv = mikv(ji,jj)   ;  ikvp1 = mikv(ji,jj) + 1
@@ -307,7 +277,5 @@
                   sgtv(ji,jj,jn) = vmask(ji,jj,ikv) * ( pta(ji,jj+1,ikv,jn) - ztj(ji,jj,jn) )
                ENDIF
-# if ! defined key_vectopt_loop
-            END DO
-# endif
+            END DO!!
          END DO!!
          CALL lbc_lnk( sgtu(:,:,jn), 'U', -1. )   ;   CALL lbc_lnk( sgtv(:,:,jn), 'V', -1. )   ! Lateral boundary cond.
@@ -317,11 +285,6 @@
       ! horizontal derivative of density anomalies (rd)
       IF( PRESENT( prd ) ) THEN         ! depth of the partial step level
-# if defined key_vectopt_loop
-         jj = 1
-         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolled)
-# else
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-# endif
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
                iku = miku(ji,jj)
                ikv = mikv(ji,jj)
@@ -335,7 +298,5 @@
                ELSE                        ;   zhj(ji,jj) = fsdept(ji,jj  ,ikv) - ze3wv    ! -     -      case 2
                ENDIF
-# if ! defined key_vectopt_loop
-            END DO
-# endif
+            END DO
          END DO
 
@@ -346,11 +307,6 @@
 
          ! Gradient of density at the last level 
-# if defined key_vectopt_loop
-         jj = 1
-         DO ji = 1, jpij-jpi   ! vector opt. (forced unrolled)
-# else
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-# endif
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
                iku = miku(ji,jj) ; ikup1 = miku(ji,jj) + 1
                ikv = mikv(ji,jj) ; ikvp1 = mikv(ji,jj) + 1
@@ -388,7 +344,5 @@
                                    -(fse3w(ji,jj  ,ikv+1) + ze3wv) * ( zrj(ji,jj      ) + prd(ji,jj  ,ikv+1) + 2._wp) )  ! j: 2
                ENDIF
-# if ! defined key_vectopt_loop
-            END DO
-# endif
+            END DO
          END DO
          CALL lbc_lnk( sgru   , 'U', -1. )   ;   CALL lbc_lnk( sgrv   , 'V', -1. )   ! Lateral boundary conditions
@@ -399,7 +353,4 @@
       END IF  
       !
-      CALL wrk_dealloc( jpi, jpj,       zri, zrj, zhi, zhj) 
-      CALL wrk_dealloc( jpi, jpj, kjpt, zti, ztj           ) 
-      !
       IF( nn_timing == 1 )  CALL timing_stop( 'zps_hde')
       !
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trd_oce.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trd_oce.F90	(revision 4946)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trd_oce.F90	(revision 4946)
@@ -0,0 +1,81 @@
+MODULE trd_oce
+   !!======================================================================
+   !!                   ***  MODULE trd_oce  ***
+   !! Ocean trends :   set tracer and momentum trend variables
+   !!======================================================================
+   !! History :  1.0  !  2004-08  (C. Talandier) Original code
+   !!----------------------------------------------------------------------
+   USE par_oce                 ! ocean parameters
+   USE trdmxl_oce              ! ocean active mixed layer tracers trends variables
+   USE trdvor_oce              ! ocean vorticity trends variables
+
+   IMPLICIT NONE
+   PUBLIC
+
+   !                                                   !!* Namelist namtrd:  diagnostics on dynamics/tracer trends *
+   LOGICAL , PUBLIC  ::   ln_dyn_trd   = .FALSE.        !: (T) 3D momentum             trends or (F) not
+   LOGICAL , PUBLIC  ::   ln_tra_trd   = .FALSE.        !: (T) 3D tracer               trends or (F) not
+   LOGICAL , PUBLIC  ::   ln_KE_trd    = .FALSE.        !: (T) 3D Kinetic   Energy     trends or (F) not
+   LOGICAL , PUBLIC  ::   ln_PE_trd    = .FALSE.        !: (T) 3D Potential Energy     trends or (F) not
+   LOGICAL , PUBLIC  ::   ln_vor_trd   = .FALSE.        !: (T) 3D barotropic vorticity trends or (F) not
+   LOGICAL , PUBLIC  ::   ln_glo_trd   = .FALSE.        !: (T) global domain averaged diag for T, T^2, KE, and PE
+   LOGICAL , PUBLIC  ::   ln_dyn_mxl   = .FALSE.        !: (T) 2D tracer   trends averaged over the mixed layer 
+   LOGICAL , PUBLIC  ::   ln_tra_mxl   = .FALSE.        !: (T) 2D momentum trends averaged over the mixed layer 
+   INTEGER , PUBLIC  ::   nn_trd       = 10             !: time step frequency for ln_glo_trd=T only
+
+   LOGICAL , PUBLIC ::   l_trdtra        !: tracers  trend flag (set from namelist in trdini)
+   LOGICAL , PUBLIC ::   l_trddyn        !: momentum trend flag (set from namelist in trdini)
+   
+# if ( defined key_trdtrc && defined key_iomput )  ||  defined key_trdmxl_trc
+   LOGICAL , PUBLIC ::   l_trdtrc = .TRUE.        !: tracers  trend flag
+# else
+   LOGICAL , PUBLIC ::   l_trdtrc = .FALSE.       !: tracers  trend flag
+# endif
+   !                                                  !!!* Active tracers trends indexes
+   INTEGER, PUBLIC, PARAMETER ::   jptot_tra  = 14     !: Total trend nb: change it when adding/removing one indice below
+   !                               ===============     !  
+   INTEGER, PUBLIC, PARAMETER ::   jptra_xad  =  1     !: x- horizontal advection
+   INTEGER, PUBLIC, PARAMETER ::   jptra_yad  =  2     !: y- horizontal advection
+   INTEGER, PUBLIC, PARAMETER ::   jptra_zad  =  3     !: z- vertical   advection
+   INTEGER, PUBLIC, PARAMETER ::   jptra_sad  =  4     !: z- vertical   advection
+   INTEGER, PUBLIC, PARAMETER ::   jptra_ldf  =  5     !: lateral       diffusion
+   INTEGER, PUBLIC, PARAMETER ::   jptra_zdf  =  6     !: vertical      diffusion
+   INTEGER, PUBLIC, PARAMETER ::   jptra_zdfp =  7     !: "PURE" vert.  diffusion (ln_traldf_iso=T)
+   INTEGER, PUBLIC, PARAMETER ::   jptra_bbc  =  8     !: Bottom Boundary Condition (geoth. heating) 
+   INTEGER, PUBLIC, PARAMETER ::   jptra_bbl  =  9     !: Bottom Boundary Layer (diffusive and/or advective)
+   INTEGER, PUBLIC, PARAMETER ::   jptra_npc  = 10     !: non-penetrative convection treatment
+   INTEGER, PUBLIC, PARAMETER ::   jptra_dmp  = 11     !: internal restoring (damping)
+   INTEGER, PUBLIC, PARAMETER ::   jptra_qsr  = 12     !: penetrative solar radiation
+   INTEGER, PUBLIC, PARAMETER ::   jptra_nsr  = 13     !: non solar radiation / C/D on salinity  (+runoff if ln_rnf=T)
+   INTEGER, PUBLIC, PARAMETER ::   jptra_atf  = 14     !: Asselin time filter
+   !
+   !                                                  !!!* Passive tracers trends indices (use if "key_top" defined)
+   INTEGER, PUBLIC, PARAMETER ::   jptra_sms  = 15     !: sources m. sinks
+   INTEGER, PUBLIC, PARAMETER ::   jptra_radn = 16     !: corr. trn<0 in trcrad
+   INTEGER, PUBLIC, PARAMETER ::   jptra_radb = 17     !: corr. trb<0 in trcrad (like atf)
+   !
+   !                                                  !!!* Momentum trends indices
+   INTEGER, PUBLIC, PARAMETER ::   jptot_dyn  = 15     !: Total trend nb: change it when adding/removing one indice below
+   !                               ===============     !  
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_hpg  =  1     !: hydrostatic pressure gradient 
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_spg  =  2     !: surface     pressure gradient
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_keg  =  3     !: kinetic energy gradient  or horizontal advection
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_rvo  =  4     !: relative  vorticity      or metric term
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_pvo  =  5     !: planetary vorticity
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_zad  =  6     !: vertical advection
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_ldf  =  7     !: horizontal diffusion   
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_zdf  =  8     !: vertical   diffusion
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_bfr  =  9     !: bottom  stress 
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_atf  = 10     !: Asselin time filter
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_tau  = 11     !: surface stress
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_bfri = 12     !: implicit bottom friction (ln_bfrimp=.TRUE.)
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_ken  = 13     !: use for calculation of KE
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_spgflt  = 14  !: filter contribution to surface pressure gradient (spg_flt)
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_spgexp  = 15  !: explicit contribution to surface pressure gradient (spg_flt)
+   !
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: trd_oce.F90 3318 2012-02-25 15:50:01Z gm $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!======================================================================
+END MODULE trd_oce
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trddyn.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trddyn.F90	(revision 4946)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trddyn.F90	(revision 4946)
@@ -0,0 +1,182 @@
+MODULE trddyn
+   !!======================================================================
+   !!                       ***  MODULE  trddyn  ***
+   !! Ocean diagnostics:  ocean dynamic trends
+   !!=====================================================================
+   !! History :  3.5  !  2012-02  (G. Madec) creation from trdmod: split DYN and TRA trends
+   !!                                        and manage  3D trends output for U, V, and KE
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   trd_dyn       : manage the type of momentum trend diagnostics (3D I/O, domain averaged, KE)
+   !!   trd_dyn_iom   : output 3D momentum and/or tracer trends using IOM
+   !!   trd_dyn_init  : initialization step
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables
+   USE zdf_oce        ! ocean vertical physics variables
+   USE trd_oce        ! trends: ocean variables
+   USE zdfbfr         ! bottom friction
+   USE sbc_oce        ! surface boundary condition: ocean
+   USE phycst         ! physical constants
+   USE trdken         ! trends: Kinetic ENergy 
+   USE trdglo         ! trends: global domain averaged
+   USE trdvor         ! trends: vertical averaged vorticity 
+   USE trdmxl         ! trends: mixed layer averaged 
+   USE in_out_manager ! I/O manager
+   USE lbclnk         ! lateral boundary condition 
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory allocation
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trd_dyn        ! called by all dynXX modules
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: trddyn.F90 3325 2012-03-12 14:44:43Z gm $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trd_dyn( putrd, pvtrd, ktrd, kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mod  ***
+      !! 
+      !! ** Purpose :   Dispatch momentum trend computation, e.g. 3D output, 
+      !!              integral constraints, barotropic vorticity, kinetic enrgy, 
+      !!              and/or mixed layer budget.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   putrd, pvtrd   ! U and V trends 
+      INTEGER                   , INTENT(in   ) ::   ktrd           ! trend index
+      INTEGER                   , INTENT(in   ) ::   kt             ! time step
+      !!----------------------------------------------------------------------
+      !
+      putrd(:,:,:) = putrd(:,:,:) * umask(:,:,:)                       ! mask the trends
+      pvtrd(:,:,:) = pvtrd(:,:,:) * vmask(:,:,:)
+      !
+
+!!gm NB : here a lbc_lnk should probably be added
+
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !   3D output of momentum and/or tracers trends using IOM interface
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF( ln_dyn_trd )   CALL trd_dyn_iom( putrd, pvtrd, ktrd, kt )
+         
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !  Integral Constraints Properties for momentum and/or tracers trends
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF( ln_glo_trd )   CALL trd_glo( putrd, pvtrd, ktrd, 'DYN', kt )
+
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !  Kinetic Energy trends
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      IF( ln_KE_trd  )   CALL trd_ken( putrd, pvtrd, ktrd, kt )
+
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !  Vorticity trends
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      IF( ln_vor_trd )   CALL trd_vor( putrd, pvtrd, ktrd, kt )
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      !  Mixed layer trends for active tracers
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+!!gm      IF( ln_dyn_mxl )   CALL trd_mxl_dyn   
+      !
+   END SUBROUTINE trd_dyn
+
+
+   SUBROUTINE trd_dyn_iom( putrd, pvtrd, ktrd, kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_dyn_iom  ***
+      !! 
+      !! ** Purpose :   output 3D trends using IOM
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   putrd, pvtrd   ! U and V trends
+      INTEGER                   , INTENT(in   ) ::   ktrd           ! trend index
+      INTEGER                   , INTENT(in   ) ::   kt             ! time step
+      !
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
+      INTEGER ::   ikbu, ikbv   ! local integers
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   z2dx, z2dy   ! 2D workspace 
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   z3dx, z3dy   ! 3D workspace 
+      !!----------------------------------------------------------------------
+      !
+      SELECT CASE( ktrd )
+      CASE( jpdyn_hpg )   ;   CALL iom_put( "utrd_hpg", putrd )    ! hydrostatic pressure gradient
+                              CALL iom_put( "vtrd_hpg", pvtrd )
+      CASE( jpdyn_spg )   ;   CALL iom_put( "utrd_spg", putrd )    ! surface pressure gradient
+                              CALL iom_put( "vtrd_spg", pvtrd )
+      CASE( jpdyn_spgexp );   CALL iom_put( "utrd_spgexp", putrd ) ! surface pressure gradient (explicit)
+                              CALL iom_put( "vtrd_spgexp", pvtrd )
+      CASE( jpdyn_spgflt );   CALL iom_put( "utrd_spgflt", putrd ) ! surface pressure gradient (filtered)
+                              CALL iom_put( "vtrd_spgflt", pvtrd )
+      CASE( jpdyn_pvo )   ;   CALL iom_put( "utrd_pvo", putrd )    ! planetary vorticity
+                              CALL iom_put( "vtrd_pvo", pvtrd )
+      CASE( jpdyn_rvo )   ;   CALL iom_put( "utrd_rvo", putrd )    ! relative  vorticity     (or metric term)
+                              CALL iom_put( "vtrd_rvo", pvtrd )
+      CASE( jpdyn_keg )   ;   CALL iom_put( "utrd_keg", putrd )    ! Kinetic Energy gradient (or had)
+                              CALL iom_put( "vtrd_keg", pvtrd )
+                              CALL wrk_alloc( jpi, jpj, jpk, z3dx, z3dy )
+                              z3dx(:,:,:) = 0._wp                  ! U.dxU & V.dyV (approximation)
+                              z3dy(:,:,:) = 0._wp
+                              DO jk = 1, jpkm1					   ! no mask as un,vn are masked
+                                 DO jj = 2, jpjm1
+                                    DO ji = 2, jpim1
+                                       z3dx(ji,jj,jk) = un(ji,jj,jk) * ( un(ji+1,jj,jk) - un(ji-1,jj,jk) ) / ( 2._wp * e1u(ji,jj) )
+                                       z3dy(ji,jj,jk) = vn(ji,jj,jk) * ( vn(ji,jj+1,jk) - vn(ji,jj-1,jk) ) / ( 2._wp * e2v(ji,jj) )
+                                    END DO
+                                 END DO
+                              END DO
+                              CALL lbc_lnk( z3dx, 'U', -1. )
+                              CALL lbc_lnk( z3dy, 'V', -1. )
+                              CALL iom_put( "utrd_udx", z3dx  )
+                              CALL iom_put( "vtrd_vdy", z3dy  )
+                              CALL wrk_dealloc( jpi, jpj, jpk, z3dx, z3dy )
+      CASE( jpdyn_zad )   ;   CALL iom_put( "utrd_zad", putrd )    ! vertical   advection
+                              CALL iom_put( "vtrd_zad", pvtrd )
+      CASE( jpdyn_ldf )   ;   CALL iom_put( "utrd_ldf", putrd )    ! lateral diffusion
+                              CALL iom_put( "vtrd_ldf", pvtrd )
+      CASE( jpdyn_zdf )   ;   CALL iom_put( "utrd_zdf", putrd )    ! vertical diffusion 
+                              CALL iom_put( "vtrd_zdf", pvtrd )
+                              !                                    ! wind stress trends
+                              CALL wrk_alloc( jpi, jpj, z2dx, z2dy )
+                              z2dx(:,:) = ( utau_b(:,:) + utau(:,:) ) / ( fse3u(:,:,1) * rau0 )
+                              z2dy(:,:) = ( vtau_b(:,:) + vtau(:,:) ) / ( fse3v(:,:,1) * rau0 )
+                              CALL iom_put( "utrd_tau", z2dx )
+                              CALL iom_put( "vtrd_tau", z2dy )
+                              CALL wrk_dealloc( jpi, jpj, z2dx, z2dy )
+      CASE( jpdyn_bfr )       ! called if ln_bfrimp=T
+                              CALL iom_put( "utrd_bfr", putrd )    ! bottom friction (explicit case)
+                              CALL iom_put( "vtrd_bfr", pvtrd )
+      CASE( jpdyn_atf )   ;   CALL iom_put( "utrd_atf", putrd )        ! asselin filter trends 
+                              CALL iom_put( "vtrd_atf", pvtrd )
+      CASE( jpdyn_bfri )  ;   IF( ln_bfrimp ) THEN                     ! bottom friction (implicit case)
+                              	CALL wrk_alloc( jpi, jpj, jpk, z3dx, z3dy )
+                              	z3dx(:,:,:) = 0._wp   ;   z3dy(:,:,:) = 0._wp  ! after velocity known (now filed at this stage)
+                              	DO jk = 1, jpkm1
+                                    DO jj = 2, jpjm1
+                                       DO ji = 2, jpim1
+                              	         ikbu = mbku(ji,jj)          ! deepest ocean u- & v-levels
+                                          ikbv = mbkv(ji,jj)
+                                          z3dx(ji,jj,jk) = bfrua(ji,jj) * un(ji,jj,ikbu) / fse3u(ji,jj,ikbu)
+                                          z3dy(ji,jj,jk) = bfrva(ji,jj) * vn(ji,jj,ikbv) / fse3v(ji,jj,ikbv)
+                              	      END DO
+                              	   END DO
+                              	END DO
+                              	CALL lbc_lnk( z3dx, 'U', -1. ) ; CALL lbc_lnk( z3dy, 'V', -1. )
+                              	CALL iom_put( "utrd_bfri", z3dx )
+                              	CALL iom_put( "vtrd_bfri", z3dy )
+                              	CALL wrk_dealloc( jpi, jpj, jpk, z3dx, z3dy )
+         					      ENDIF
+      END SELECT
+      !
+   END SUBROUTINE trd_dyn_iom
+
+   !!======================================================================
+END MODULE trddyn
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdglo.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdglo.F90	(revision 4946)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdglo.F90	(revision 4946)
@@ -0,0 +1,564 @@
+MODULE trdglo
+   !!======================================================================
+   !!                       ***  MODULE  trdglo  ***
+   !! Ocean diagnostics:  global domain averaged tracer and momentum trends
+   !!=====================================================================
+   !! History :  1.0  !  2004-08 (C. Talandier) New trends organization
+   !!            3.5  !  2012-02 (G. Madec)  add 3D tracer zdf trend output using iom
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   trd_glo      : domain averaged budget of trends (including kinetic energy and T^2 trends)
+   !!   glo_dyn_wri  : print dynamic trends in ocean.output file
+   !!   glo_tra_wri  : print global T & T^2 trends in ocean.output file
+   !!   trd_glo_init : initialization step
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE sbc_oce         ! surface boundary condition: ocean
+   USE trd_oce         ! trends: ocean variables
+   USE phycst          ! physical constants
+   USE ldftra_oce      ! ocean active tracers: lateral physics
+   USE ldfdyn_oce      ! ocean dynamics: lateral physics
+   USE zdf_oce         ! ocean vertical physics
+   USE zdfbfr          ! bottom friction
+   USE zdfddm          ! ocean vertical physics: double diffusion
+   USE eosbn2          ! equation of state
+   USE phycst          ! physical constants
+   USE lib_mpp         ! distibuted memory computing library
+   USE in_out_manager  ! I/O manager
+   USE iom             ! I/O manager library
+   USE wrk_nemo        ! Memory allocation
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trd_glo       ! called by trdtra and trddyn modules
+   PUBLIC   trd_glo_init  ! called by trdini module
+
+   !                     !!! Variables used for diagnostics
+   REAL(wp) ::   tvolt    ! volume of the whole ocean computed at t-points
+   REAL(wp) ::   tvolu    ! volume of the whole ocean computed at u-points
+   REAL(wp) ::   tvolv    ! volume of the whole ocean computed at v-points
+   REAL(wp) ::   rpktrd   ! potential to kinetic energy conversion
+   REAL(wp) ::   peke     ! conversion potential energy - kinetic energy trend
+
+   !                     !!! domain averaged trends
+   REAL(wp), DIMENSION(jptot_tra) ::   tmo, smo   ! temperature and salinity trends 
+   REAL(wp), DIMENSION(jptot_tra) ::   t2 , s2    ! T^2 and S^2 trends 
+   REAL(wp), DIMENSION(jptot_dyn) ::   umo, vmo   ! momentum trends 
+   REAL(wp), DIMENSION(jptot_dyn) ::   hke        ! kinetic energy trends (u^2+v^2) 
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+#  include "zdfddm_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: trdglo.F90 3325 2012-03-12 14:44:43Z gm $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trd_glo( ptrdx, ptrdy, ktrd, ctype, kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_glo  ***
+      !! 
+      !! ** Purpose :   compute and print global domain averaged trends for 
+      !!              T, T^2, momentum, KE, and KE<->PE
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend 
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
+      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
+      CHARACTER(len=3)          , INTENT(in   ) ::   ctype   ! momentum or tracers trends type (='DYN'/'TRA')
+      INTEGER                   , INTENT(in   ) ::   kt      ! time step
+      !!
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+      INTEGER ::   ikbu, ikbv      ! local integers
+      REAL(wp)::   zvm, zvt, zvs, z1_2rau0   ! local scalars
+      REAL(wp), POINTER, DIMENSION(:,:)  :: ztswu, ztswv, z2dx, z2dy   ! 2D workspace 
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, ztswu, ztswv, z2dx, z2dy )
+
+      IF( MOD(kt,nn_trd) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
+         !
+      	SELECT CASE( ctype )
+      	!
+      	CASE( 'TRA' )          !==  Tracers (T & S)  ==!
+      	   DO jk = 1, jpkm1       ! global sum of mask volume trend and trend*T (including interior mask)
+      	      DO jj = 1, jpj
+      	         DO ji = 1, jpi        
+      	            zvm = e1e2t(ji,jj) * fse3t(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+      	            zvt = ptrdx(ji,jj,jk) * zvm
+      	            zvs = ptrdy(ji,jj,jk) * zvm
+         	         tmo(ktrd) = tmo(ktrd) + zvt   
+         	         smo(ktrd) = smo(ktrd) + zvs
+         	         t2 (ktrd) = t2(ktrd)  + zvt * tsn(ji,jj,jk,jp_tem)
+         	         s2 (ktrd) = s2(ktrd)  + zvs * tsn(ji,jj,jk,jp_sal)
+                  END DO
+               END DO
+            END DO
+            !                       ! linear free surface: diagnose advective flux trough the fixed k=1 w-surface
+            IF( .NOT.lk_vvl .AND. ktrd == jptra_zad ) THEN  
+               tmo(jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_tem) * e1e2t(:,:) )
+               smo(jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_sal) * e1e2t(:,:)  )
+               t2 (jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_tem) * tsn(:,:,1,jp_tem) * e1e2t(:,:)  )
+               s2 (jptra_sad) = SUM( wn(:,:,1) * tsn(:,:,1,jp_sal) * tsn(:,:,1,jp_sal) * e1e2t(:,:)  )
+            ENDIF
+            !
+            IF( ktrd == jptra_atf ) THEN     ! last trend (asselin time filter)
+               ! 
+               CALL glo_tra_wri( kt )             ! print the results in ocean.output
+               !                
+	            tmo(:) = 0._wp                     ! prepare the next time step (domain averaged array reset to zero)
+   	         smo(:) = 0._wp
+               t2 (:) = 0._wp
+               s2 (:) = 0._wp
+               !
+            ENDIF
+            !
+         CASE( 'DYN' )          !==  Momentum and KE  ==!        
+            DO jk = 1, jpkm1
+               DO jj = 1, jpjm1
+                  DO ji = 1, jpim1
+                     zvt = ptrdx(ji,jj,jk) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)   &
+                        &                  * e1u    (ji  ,jj  ) * e2u    (ji,jj) * fse3u(ji,jj,jk)
+                     zvs = ptrdy(ji,jj,jk) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)   &
+                        &                  * e1v    (ji  ,jj  ) * e2v    (ji,jj) * fse3u(ji,jj,jk)
+                     umo(ktrd) = umo(ktrd) + zvt
+                     vmo(ktrd) = vmo(ktrd) + zvs
+                     hke(ktrd) = hke(ktrd) + un(ji,jj,jk) * zvt + vn(ji,jj,jk) * zvs
+                  END DO
+               END DO
+            END DO
+            !                 
+            IF( ktrd == jpdyn_zdf ) THEN      ! zdf trend: compute separately the surface forcing trend
+               z1_2rau0 = 0.5_wp / rau0
+               DO jj = 1, jpjm1
+                  DO ji = 1, jpim1
+                     zvt = ( utau_b(ji,jj) + utau(ji,jj) ) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)   &
+                        &                       * z1_2rau0 * e1u    (ji  ,jj  ) * e2u    (ji,jj)
+                     zvs = ( vtau_b(ji,jj) + vtau(ji,jj) ) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)   &
+                        &                       * z1_2rau0 * e1v    (ji  ,jj  ) * e2v    (ji,jj) * fse3u(ji,jj,jk)
+                     umo(jpdyn_tau) = umo(jpdyn_tau) + zvt
+                     vmo(jpdyn_tau) = vmo(jpdyn_tau) + zvs
+                     hke(jpdyn_tau) = hke(jpdyn_tau) + un(ji,jj,1) * zvt + vn(ji,jj,1) * zvs
+                  END DO
+               END DO
+            ENDIF
+            !                       
+            IF( ktrd == jpdyn_atf ) THEN     ! last trend (asselin time filter)
+               !
+               IF( ln_bfrimp ) THEN                   ! implicit bfr case: compute separately the bottom friction 
+                  z1_2rau0 = 0.5_wp / rau0
+                  DO jj = 1, jpjm1
+                     DO ji = 1, jpim1
+                        ikbu = mbku(ji,jj)                  ! deepest ocean u- & v-levels
+                        ikbv = mbkv(ji,jj)
+                        zvt = bfrua(ji,jj) * un(ji,jj,ikbu) * e1u(ji,jj) * e2v(ji,jj)
+                        zvs = bfrva(ji,jj) * vn(ji,jj,ikbv) * e1v(ji,jj) * e2v(ji,jj)
+                        umo(jpdyn_bfri) = umo(jpdyn_bfri) + zvt
+                        vmo(jpdyn_bfri) = vmo(jpdyn_bfri) + zvs
+                        hke(jpdyn_bfri) = hke(jpdyn_bfri) + un(ji,jj,ikbu) * zvt + vn(ji,jj,ikbv) * zvs
+                     END DO
+                  END DO
+               ENDIF
+               ! 
+               CALL glo_dyn_wri( kt )                 ! print the results in ocean.output
+               !                
+               umo(:) = 0._wp                         ! reset for the next time step
+               vmo(:) = 0._wp
+               hke(:) = 0._wp
+               !
+            ENDIF
+            !
+         END SELECT
+         !
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi, jpj, ztswu, ztswv, z2dx, z2dy )
+      !
+   END SUBROUTINE trd_glo
+
+
+   SUBROUTINE glo_dyn_wri( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE glo_dyn_wri  ***
+      !! 
+      !! ** Purpose :  write global averaged U, KE, PE<->KE trends in ocean.output 
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zcof         ! local scalar
+      REAL(wp), POINTER, DIMENSION(:,:,:)  ::  zkx, zky, zkz, zkepe  
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, jpk, zkx, zky, zkz, zkepe )
+
+      ! I. Momentum trends
+      ! -------------------
+
+      IF( MOD( kt, nn_trd ) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
+
+         ! I.1 Conversion potential energy - kinetic energy
+         ! --------------------------------------------------
+         ! c a u t i o n here, trends are computed at kt+1 (now , but after the swap)
+         zkx  (:,:,:) = 0._wp
+         zky  (:,:,:) = 0._wp
+         zkz  (:,:,:) = 0._wp
+         zkepe(:,:,:) = 0._wp
+   
+         CALL eos( tsn, rhd, rhop )       ! now potential density
+
+         zcof = 0.5_wp / rau0             ! Density flux at w-point
+         zkz(:,:,1) = 0._wp
+         DO jk = 2, jpk
+            zkz(:,:,jk) = zcof * e1e2t(:,:) * wn(:,:,jk) * ( rhop(:,:,jk) + rhop(:,:,jk-1) ) * tmask_i(:,:)
+         END DO
+         
+         zcof   = 0.5_wp / rau0           ! Density flux at u and v-points
+         DO jk = 1, jpkm1
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1
+                  zkx(ji,jj,jk) = zcof * e2u(ji,jj) * fse3u(ji,jj,jk) * un(ji,jj,jk) * ( rhop(ji,jj,jk) + rhop(ji+1,jj,jk) )
+                  zky(ji,jj,jk) = zcof * e1v(ji,jj) * fse3v(ji,jj,jk) * vn(ji,jj,jk) * ( rhop(ji,jj,jk) + rhop(ji,jj+1,jk) )
+               END DO
+            END DO
+         END DO
+         
+         DO jk = 1, jpkm1                 ! Density flux divergence at t-point
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  zkepe(ji,jj,jk) = - (  zkz(ji,jj,jk) - zkz(ji  ,jj  ,jk+1)               &
+                     &                 + zkx(ji,jj,jk) - zkx(ji-1,jj  ,jk  )               &
+                     &                 + zky(ji,jj,jk) - zky(ji  ,jj-1,jk  )   )           &
+                     &              / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) ) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+               END DO
+            END DO
+         END DO
+
+         ! I.2 Basin averaged kinetic energy trend
+         ! ----------------------------------------
+         peke = 0._wp
+         DO jk = 1, jpkm1
+            peke = peke + SUM( zkepe(:,:,jk) * fsdept(:,:,jk) * e1e2t(:,:) * fse3t(:,:,jk) )
+         END DO
+         peke = grav * peke
+
+         ! I.3 Sums over the global domain
+         ! ---------------------------------
+         IF( lk_mpp ) THEN
+            CALL mpp_sum( peke )
+            CALL mpp_sum( umo , jptot_dyn )
+            CALL mpp_sum( vmo , jptot_dyn )
+            CALL mpp_sum( hke , jptot_dyn )
+         ENDIF
+
+         ! I.2 Print dynamic trends in the ocean.output file
+         ! --------------------------------------------------
+
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9500) kt
+            WRITE (numout,9501) umo(jpdyn_hpg) / tvolu, vmo(jpdyn_hpg) / tvolv
+            WRITE (numout,9502) umo(jpdyn_keg) / tvolu, vmo(jpdyn_keg) / tvolv
+            WRITE (numout,9503) umo(jpdyn_rvo) / tvolu, vmo(jpdyn_rvo) / tvolv
+            WRITE (numout,9504) umo(jpdyn_pvo) / tvolu, vmo(jpdyn_pvo) / tvolv
+            WRITE (numout,9505) umo(jpdyn_zad) / tvolu, vmo(jpdyn_zad) / tvolv
+            WRITE (numout,9506) umo(jpdyn_ldf) / tvolu, vmo(jpdyn_ldf) / tvolv
+            WRITE (numout,9507) umo(jpdyn_zdf) / tvolu, vmo(jpdyn_zdf) / tvolv
+            WRITE (numout,9508) umo(jpdyn_spg) / tvolu, vmo(jpdyn_spg) / tvolv
+            WRITE (numout,9509) umo(jpdyn_bfr) / tvolu, vmo(jpdyn_bfr) / tvolv
+            WRITE (numout,9510) umo(jpdyn_atf) / tvolu, vmo(jpdyn_atf) / tvolv
+            WRITE (numout,9511)
+            WRITE (numout,9512)                                                 &
+            &     (  umo(jpdyn_hpg) + umo(jpdyn_keg) + umo(jpdyn_rvo) + umo(jpdyn_pvo)   &
+            &      + umo(jpdyn_zad) + umo(jpdyn_ldf) + umo(jpdyn_zdf) + umo(jpdyn_spg)   &
+            &      + umo(jpdyn_bfr) + umo(jpdyn_atf) ) / tvolu,   &
+            &     (  vmo(jpdyn_hpg) + vmo(jpdyn_keg) + vmo(jpdyn_rvo) + vmo(jpdyn_pvo)   &
+            &      + vmo(jpdyn_zad) + vmo(jpdyn_ldf) + vmo(jpdyn_zdf) + vmo(jpdyn_spg)   &
+            &      + vmo(jpdyn_bfr) + vmo(jpdyn_atf) ) / tvolv
+            WRITE (numout,9513) umo(jpdyn_tau) / tvolu, vmo(jpdyn_tau) / tvolv
+            IF( ln_bfrimp )   WRITE (numout,9514) umo(jpdyn_bfri) / tvolu, vmo(jpdyn_bfri) / tvolv
+         ENDIF
+
+ 9500    FORMAT(' momentum trend at it= ', i6, ' :', /' ==============================')
+ 9501    FORMAT(' hydro pressure gradient    u= ', e20.13, '    v= ', e20.13)
+ 9502    FORMAT(' ke gradient                u= ', e20.13, '    v= ', e20.13)
+ 9503    FORMAT(' relative vorticity term    u= ', e20.13, '    v= ', e20.13)
+ 9504    FORMAT(' planetary vorticity term   u= ', e20.13, '    v= ', e20.13)
+ 9505    FORMAT(' vertical advection         u= ', e20.13, '    v= ', e20.13)
+ 9506    FORMAT(' horizontal diffusion       u= ', e20.13, '    v= ', e20.13)
+ 9507    FORMAT(' vertical diffusion         u= ', e20.13, '    v= ', e20.13)
+ 9508    FORMAT(' surface pressure gradient  u= ', e20.13, '    v= ', e20.13)
+ 9509    FORMAT(' explicit bottom friction   u= ', e20.13, '    v= ', e20.13)
+ 9510    FORMAT(' Asselin time filter        u= ', e20.13, '    v= ', e20.13)
+ 9511    FORMAT(' -----------------------------------------------------------------------------')
+ 9512    FORMAT(' total trend                u= ', e20.13, '    v= ', e20.13)
+ 9513    FORMAT(' incl. surface wind stress  u= ', e20.13, '    v= ', e20.13)
+ 9514    FORMAT('       bottom stress        u= ', e20.13, '    v= ', e20.13)
+
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9520) kt
+            WRITE (numout,9521) hke(jpdyn_hpg) / tvolt
+            WRITE (numout,9522) hke(jpdyn_keg) / tvolt
+            WRITE (numout,9523) hke(jpdyn_rvo) / tvolt
+            WRITE (numout,9524) hke(jpdyn_pvo) / tvolt
+            WRITE (numout,9525) hke(jpdyn_zad) / tvolt
+            WRITE (numout,9526) hke(jpdyn_ldf) / tvolt
+            WRITE (numout,9527) hke(jpdyn_zdf) / tvolt
+            WRITE (numout,9528) hke(jpdyn_spg) / tvolt
+            WRITE (numout,9529) hke(jpdyn_bfr) / tvolt
+            WRITE (numout,9530) hke(jpdyn_atf) / tvolt
+            WRITE (numout,9531)
+            WRITE (numout,9532)   &
+            &     (  hke(jpdyn_hpg) + hke(jpdyn_keg) + hke(jpdyn_rvo) + hke(jpdyn_pvo)   &
+            &      + hke(jpdyn_zad) + hke(jpdyn_ldf) + hke(jpdyn_zdf) + hke(jpdyn_spg)   &
+            &      + hke(jpdyn_bfr) + hke(jpdyn_atf) ) / tvolt
+            WRITE (numout,9533) hke(jpdyn_tau) / tvolt
+            IF( ln_bfrimp )   WRITE (numout,9534) hke(jpdyn_bfri) / tvolt
+         ENDIF
+
+ 9520    FORMAT(' kinetic energy trend at it= ', i6, ' :', /' ====================================')
+ 9521    FORMAT(' hydro pressure gradient   u2= ', e20.13)
+ 9522    FORMAT(' ke gradient               u2= ', e20.13)
+ 9523    FORMAT(' relative vorticity term   u2= ', e20.13)
+ 9524    FORMAT(' planetary vorticity term  u2= ', e20.13)
+ 9525    FORMAT(' vertical advection        u2= ', e20.13)
+ 9526    FORMAT(' horizontal diffusion      u2= ', e20.13)
+ 9527    FORMAT(' vertical diffusion        u2= ', e20.13)
+ 9528    FORMAT(' surface pressure gradient u2= ', e20.13)
+ 9529    FORMAT(' explicit bottom friction  u2= ', e20.13)
+ 9530    FORMAT(' Asselin time filter       u2= ', e20.13)
+ 9531    FORMAT(' --------------------------------------------------')
+ 9532    FORMAT(' total trend               u2= ', e20.13)
+ 9533    FORMAT(' incl. surface wind stress u2= ', e20.13)
+ 9534    FORMAT('       bottom stress       u2= ', e20.13)
+
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9540) kt
+            WRITE (numout,9541) ( hke(jpdyn_keg) + hke(jpdyn_rvo) + hke(jpdyn_zad) ) / tvolt
+            WRITE (numout,9542) ( hke(jpdyn_keg) + hke(jpdyn_zad) ) / tvolt
+            WRITE (numout,9543) ( hke(jpdyn_pvo) ) / tvolt
+            WRITE (numout,9544) ( hke(jpdyn_rvo) ) / tvolt
+            WRITE (numout,9545) ( hke(jpdyn_spg) ) / tvolt
+            WRITE (numout,9546) ( hke(jpdyn_ldf) ) / tvolt
+            WRITE (numout,9547) ( hke(jpdyn_zdf) ) / tvolt
+            WRITE (numout,9548) ( hke(jpdyn_hpg) ) / tvolt, rpktrd / tvolt
+            WRITE (numout,*)
+            WRITE (numout,*)
+         ENDIF
+
+ 9540    FORMAT(' energetic consistency at it= ', i6, ' :', /' =========================================')
+ 9541    FORMAT(' 0 = non linear term (true if KE conserved)                : ', e20.13)
+ 9542    FORMAT(' 0 = ke gradient + vertical advection                      : ', e20.13)
+ 9543    FORMAT(' 0 = coriolis term  (true if KE conserving scheme)         : ', e20.13)
+ 9544    FORMAT(' 0 = vorticity term (true if KE conserving scheme)         : ', e20.13)
+ 9545    FORMAT(' 0 = surface pressure gradient  ???                        : ', e20.13)
+ 9546    FORMAT(' 0 < horizontal diffusion                                  : ', e20.13)
+ 9547    FORMAT(' 0 < vertical diffusion                                    : ', e20.13)
+ 9548    FORMAT(' pressure gradient u2 = - 1/rau0 u.dz(rhop)                : ', e20.13, '  u.dz(rhop) =', e20.13)
+         !
+         ! Save potential to kinetic energy conversion for next time step
+         rpktrd = peke
+         !
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi, jpj, jpk, zkx, zky, zkz, zkepe )
+      !
+   END SUBROUTINE glo_dyn_wri
+
+
+   SUBROUTINE glo_tra_wri( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE glo_tra_wri  ***
+      !! 
+      !! ** Purpose :  write global domain averaged of T and T^2 trends in ocean.output 
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      INTEGER  ::   jk   ! loop indices
+      !!----------------------------------------------------------------------
+
+      ! I. Tracers trends
+      ! -----------------
+
+      IF( MOD(kt,nn_trd) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
+
+         ! I.1 Sums over the global domain
+         ! -------------------------------
+         IF( lk_mpp ) THEN
+            CALL mpp_sum( tmo, jptot_tra )   
+            CALL mpp_sum( smo, jptot_tra )
+            CALL mpp_sum( t2 , jptot_tra )
+            CALL mpp_sum( s2 , jptot_tra )
+         ENDIF
+
+         ! I.2 Print tracers trends in the ocean.output file
+         ! --------------------------------------------------
+         
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9400) kt
+            WRITE (numout,9401)  tmo(jptra_xad) / tvolt, smo(jptra_xad) / tvolt
+            WRITE (numout,9411)  tmo(jptra_yad) / tvolt, smo(jptra_yad) / tvolt
+            WRITE (numout,9402)  tmo(jptra_zad) / tvolt, smo(jptra_zad) / tvolt
+            WRITE (numout,9403)  tmo(jptra_ldf) / tvolt, smo(jptra_ldf) / tvolt
+            WRITE (numout,9404)  tmo(jptra_zdf) / tvolt, smo(jptra_zdf) / tvolt
+            WRITE (numout,9405)  tmo(jptra_npc) / tvolt, smo(jptra_npc) / tvolt
+            WRITE (numout,9406)  tmo(jptra_dmp) / tvolt, smo(jptra_dmp) / tvolt
+            WRITE (numout,9407)  tmo(jptra_qsr) / tvolt
+            WRITE (numout,9408)  tmo(jptra_nsr) / tvolt, smo(jptra_nsr) / tvolt
+            WRITE (numout,9409) 
+            WRITE (numout,9410) (  tmo(jptra_xad) + tmo(jptra_yad) + tmo(jptra_zad) + tmo(jptra_ldf) + tmo(jptra_zdf)   &
+            &                    + tmo(jptra_npc) + tmo(jptra_dmp) + tmo(jptra_qsr) + tmo(jptra_nsr) ) / tvolt,   &
+            &                   (  smo(jptra_xad) + smo(jptra_yad) + smo(jptra_zad) + smo(jptra_ldf) + smo(jptra_zdf)   &
+            &                    + smo(jptra_npc) + smo(jptra_dmp)                   + smo(jptra_nsr) ) / tvolt
+         ENDIF
+
+9400     FORMAT(' tracer trend at it= ',i6,' :     temperature',   &
+              '              salinity',/' ============================')
+9401     FORMAT(' zonal      advection        ',e20.13,'     ',e20.13)
+9411     FORMAT(' meridional advection        ',e20.13,'     ',e20.13)
+9402     FORMAT(' vertical advection          ',e20.13,'     ',e20.13)
+9403     FORMAT(' horizontal diffusion        ',e20.13,'     ',e20.13)
+9404     FORMAT(' vertical diffusion          ',e20.13,'     ',e20.13)
+9405     FORMAT(' static instability mixing   ',e20.13,'     ',e20.13)
+9406     FORMAT(' damping term                ',e20.13,'     ',e20.13)
+9407     FORMAT(' penetrative qsr             ',e20.13)
+9408     FORMAT(' non solar radiation         ',e20.13,'     ',e20.13)
+9409     FORMAT(' -------------------------------------------------------------------------')
+9410     FORMAT(' total trend                 ',e20.13,'     ',e20.13)
+
+
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9420) kt
+            WRITE (numout,9421)   t2(jptra_xad) / tvolt, s2(jptra_xad) / tvolt
+            WRITE (numout,9431)   t2(jptra_yad) / tvolt, s2(jptra_yad) / tvolt
+            WRITE (numout,9422)   t2(jptra_zad) / tvolt, s2(jptra_zad) / tvolt
+            WRITE (numout,9423)   t2(jptra_ldf) / tvolt, s2(jptra_ldf) / tvolt
+            WRITE (numout,9424)   t2(jptra_zdf) / tvolt, s2(jptra_zdf) / tvolt
+            WRITE (numout,9425)   t2(jptra_npc) / tvolt, s2(jptra_npc) / tvolt
+            WRITE (numout,9426)   t2(jptra_dmp) / tvolt, s2(jptra_dmp) / tvolt
+            WRITE (numout,9427)   t2(jptra_qsr) / tvolt
+            WRITE (numout,9428)   t2(jptra_nsr) / tvolt, s2(jptra_nsr) / tvolt
+            WRITE (numout,9429)
+            WRITE (numout,9430) (  t2(jptra_xad) + t2(jptra_yad) + t2(jptra_zad) + t2(jptra_ldf) + t2(jptra_zdf)   &
+            &                    + t2(jptra_npc) + t2(jptra_dmp) + t2(jptra_qsr) + t2(jptra_nsr) ) / tvolt,   &
+            &                   (  s2(jptra_xad) + s2(jptra_yad) + s2(jptra_zad) + s2(jptra_ldf) + s2(jptra_zdf)   &
+            &                    + s2(jptra_npc) + s2(jptra_dmp)                  + s2(jptra_nsr) ) / tvolt
+         ENDIF
+
+9420     FORMAT(' tracer**2 trend at it= ', i6, ' :      temperature',   &
+            '               salinity', /, ' ===============================')
+9421     FORMAT(' zonal      advection      * t   ', e20.13, '     ', e20.13)
+9431     FORMAT(' meridional advection      * t   ', e20.13, '     ', e20.13)
+9422     FORMAT(' vertical advection        * t   ', e20.13, '     ', e20.13)
+9423     FORMAT(' horizontal diffusion      * t   ', e20.13, '     ', e20.13)
+9424     FORMAT(' vertical diffusion        * t   ', e20.13, '     ', e20.13)
+9425     FORMAT(' static instability mixing * t   ', e20.13, '     ', e20.13)
+9426     FORMAT(' damping term              * t   ', e20.13, '     ', e20.13)
+9427     FORMAT(' penetrative qsr           * t   ', e20.13)
+9428     FORMAT(' non solar radiation       * t   ', e20.13, '     ', e20.13)
+9429     FORMAT(' -----------------------------------------------------------------------------')
+9430     FORMAT(' total trend                *t = ', e20.13, '  *s = ', e20.13)
+
+
+         IF(lwp) THEN
+            WRITE (numout,*)
+            WRITE (numout,*)
+            WRITE (numout,9440) kt
+            WRITE (numout,9441) ( tmo(jptra_xad)+tmo(jptra_yad)+tmo(jptra_zad) )/tvolt,   &
+            &                   ( smo(jptra_xad)+smo(jptra_yad)+smo(jptra_zad) )/tvolt
+            WRITE (numout,9442)   tmo(jptra_sad)/tvolt,  smo(jptra_sad)/tvolt
+            WRITE (numout,9443)   tmo(jptra_ldf)/tvolt,  smo(jptra_ldf)/tvolt
+            WRITE (numout,9444)   tmo(jptra_zdf)/tvolt,  smo(jptra_zdf)/tvolt
+            WRITE (numout,9445)   tmo(jptra_npc)/tvolt,  smo(jptra_npc)/tvolt
+            WRITE (numout,9446) ( t2(jptra_xad)+t2(jptra_yad)+t2(jptra_zad) )/tvolt,    &
+            &                   ( s2(jptra_xad)+s2(jptra_yad)+s2(jptra_zad) )/tvolt
+            WRITE (numout,9447)   t2(jptra_ldf)/tvolt,   s2(jptra_ldf)/tvolt
+            WRITE (numout,9448)   t2(jptra_zdf)/tvolt,   s2(jptra_zdf)/tvolt
+            WRITE (numout,9449)   t2(jptra_npc)/tvolt,   s2(jptra_npc)/tvolt
+         ENDIF
+
+9440     FORMAT(' tracer consistency at it= ',i6,   &
+            ' :         temperature','                salinity',/,   &
+            ' ==================================')
+9441     FORMAT(' 0 = horizontal+vertical advection +    ',e20.13,'       ',e20.13)
+9442     FORMAT('     1st lev vertical advection         ',e20.13,'       ',e20.13)
+9443     FORMAT(' 0 = horizontal diffusion               ',e20.13,'       ',e20.13)
+9444     FORMAT(' 0 = vertical diffusion                 ',e20.13,'       ',e20.13)
+9445     FORMAT(' 0 = static instability mixing          ',e20.13,'       ',e20.13)
+9446     FORMAT(' 0 = horizontal+vertical advection * t  ',e20.13,'       ',e20.13)
+9447     FORMAT(' 0 > horizontal diffusion          * t  ',e20.13,'       ',e20.13)
+9448     FORMAT(' 0 > vertical diffusion            * t  ',e20.13,'       ',e20.13)
+9449     FORMAT(' 0 > static instability mixing     * t  ',e20.13,'       ',e20.13)
+         !
+      ENDIF
+      !
+   END SUBROUTINE glo_tra_wri
+
+
+   SUBROUTINE trd_glo_init
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_glo_init  ***
+      !! 
+      !! ** Purpose :   Read the namtrd namelist
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trd_glo_init : integral constraints properties trends'
+         WRITE(numout,*) '~~~~~~~~~~~~~'
+      ENDIF
+
+      ! Total volume at t-points:
+      tvolt = 0._wp
+      DO jk = 1, jpkm1
+         tvolt = tvolt + SUM( e1e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:) )
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( tvolt )   ! sum over the global domain
+
+      IF(lwp) WRITE(numout,*) '                total ocean volume at T-point   tvolt = ',tvolt
+
+      ! Initialization of potential to kinetic energy conversion
+      rpktrd = 0._wp
+
+      ! Total volume at u-, v- points:
+!!gm :  bug?  je suis quasi sur que le produit des tmask_i ne correspond pas exactement au umask_i et vmask_i !
+      tvolu = 0._wp
+      tvolv = 0._wp
+
+      DO jk = 1, jpk
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               tvolu = tvolu + e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)
+               tvolv = tvolv + e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( tvolu )   ! sums over the global domain
+      IF( lk_mpp )   CALL mpp_sum( tvolv )
+
+      IF(lwp) THEN
+         WRITE(numout,*) '                total ocean volume at U-point   tvolu = ',tvolu
+         WRITE(numout,*) '                total ocean volume at V-point   tvolv = ',tvolv
+      ENDIF
+      !
+   END SUBROUTINE trd_glo_init
+
+   !!======================================================================
+END MODULE trdglo
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdicp.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdicp.F90	(revision 4944)
+++ 	(revision )
@@ -1,607 +1,0 @@
-MODULE trdicp
-   !!======================================================================
-   !!                       ***  MODULE  trdicp  ***
-   !! Ocean diagnostics:  ocean tracers and dynamic trends
-   !!=====================================================================
-   !! History :  1.0  !  2004-08 (C. Talandier) New trends organization
-   !!----------------------------------------------------------------------
-#if  defined key_trdtra   ||   defined key_trddyn   ||   defined key_esopa
-   !!----------------------------------------------------------------------
-   !!   'key_trdtra'  or                  active tracers trends diagnostics
-   !!   'key_trddyn'                            momentum trends diagnostics
-   !!----------------------------------------------------------------------
-   !!   trd_icp          : compute the basin averaged properties for tra/dyn 
-   !!   trd_dwr          : print dynmaic trends in ocean.output file
-   !!   trd_twr          : print tracers trends in ocean.output file
-   !!   trd_icp_init     : initialization step
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables
-   USE trdmod_oce      ! ocean variables trends
-   USE ldftra_oce      ! ocean active tracers: lateral physics
-   USE ldfdyn_oce      ! ocean dynamics: lateral physics
-   USE zdf_oce         ! ocean vertical physics
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! distibuted memory computing library
-   USE eosbn2          ! equation of state
-   USE phycst          ! physical constants
-   USE wrk_nemo        ! Memory allocation
-
-
-   IMPLICIT NONE
-   PRIVATE
-
-   INTERFACE trd_icp
-      MODULE PROCEDURE trd_2d, trd_3d
-   END INTERFACE
-
-   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
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE trd_2d( ptrd2dx, ptrd2dy, ktrd , ctype )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_2d  ***
-      !! 
-      !! ** Purpose : verify the basin averaged properties of tracers and/or
-      !!              momentum equations at every time step frequency nn_trd.
-      !!----------------------------------------------------------------------
-      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
-      !!
-      INTEGER ::   ji, jj   ! loop indices
-      !!----------------------------------------------------------------------
-
-      SELECT CASE( ctype )    !==  Mask trends  ==!
-      !
-      CASE( 'DYN' )                    ! Momentum
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-               ptrd2dx(ji,jj) = ptrd2dx(ji,jj) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,1)
-               ptrd2dy(ji,jj) = ptrd2dy(ji,jj) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,1)
-            END DO
-         END DO
-         ptrd2dx(jpi, : ) = 0._wp      ;      ptrd2dy(jpi, : ) = 0._wp
-         ptrd2dx( : ,jpj) = 0._wp      ;      ptrd2dy( : ,jpj) = 0._wp
-         !
-      CASE( 'TRA' )                    ! Tracers
-         ptrd2dx(:,:) = ptrd2dx(:,:) * tmask_i(:,:)
-         ptrd2dy(:,:) = ptrd2dy(:,:) * tmask_i(:,:)
-         !
-      END SELECT
-      
-      SELECT CASE( ctype )    !==  Basin averaged tracer/momentum trends  ==!
-      !
-      CASE( 'DYN' )                    ! Momentum
-         umo(ktrd) = 0._wp
-         vmo(ktrd) = 0._wp
-         !
-         SELECT CASE( ktrd )
-         CASE( jpdyn_trd_swf )         ! surface forcing
-            umo(ktrd) = SUM( ptrd2dx(:,:) * e1u(:,:) * e2u(:,:) * fse3u(:,:,1) )
-            vmo(ktrd) = SUM( ptrd2dy(:,:) * e1v(:,:) * e2v(:,:) * fse3v(:,:,1) )
-         END SELECT
-         !
-      CASE( 'TRA' )              ! Tracers
-         tmo(ktrd) = SUM( ptrd2dx(:,:) * e1e2t(:,:) * fse3t(:,:,1) )
-         smo(ktrd) = SUM( ptrd2dy(:,:) * e1e2t(:,:) * fse3t(:,:,1) )
-      END SELECT
-      
-      SELECT CASE( ctype )    !==  Basin averaged tracer/momentum square trends  ==!   (now field)
-      !
-      CASE( 'DYN' )              ! Momentum
-         hke(ktrd) = SUM(   un(:,:,1) * ptrd2dx(:,:) * e1u(:,:) * e2u(:,:) * fse3u(:,:,1)   &
-            &             + vn(:,:,1) * ptrd2dy(:,:) * e1v(:,:) * e2v(:,:) * fse3v(:,:,1)   )
-         !
-      CASE( 'TRA' )              ! Tracers
-         t2(ktrd) = SUM( ptrd2dx(:,:) * e1e2t(:,:) * fse3t(:,:,1) * tsn(:,:,1,jp_tem) )
-         s2(ktrd) = SUM( ptrd2dy(:,:) * e1e2t(:,:) * fse3t(:,:,1) * tsn(:,:,1,jp_sal) )
-         !      
-      END SELECT
-      !
-   END SUBROUTINE trd_2d
-
-
-   SUBROUTINE trd_3d( ptrd3dx, ptrd3dy, ktrd, ctype )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_3d  ***
-      !! 
-      !! ** Purpose : verify the basin averaged properties of tracers and/or
-      !!              momentum equations at every time step frequency nn_trd.
-      !!----------------------------------------------------------------------
-      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
-      !!
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      !!----------------------------------------------------------------------
-
-      SELECT CASE( ctype )    !==  Mask the trends  ==!
-      !
-      CASE( 'DYN' )              ! Momentum        
-         DO jk = 1, jpkm1
-            DO jj = 1, jpjm1
-               DO ji = 1, jpim1
-                  ptrd3dx(ji,jj,jk) = ptrd3dx(ji,jj,jk) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)
-                  ptrd3dy(ji,jj,jk) = ptrd3dy(ji,jj,jk) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         ptrd3dx(jpi, : ,:) = 0._wp      ;      ptrd3dy(jpi, : ,:) = 0._wp
-         ptrd3dx( : ,jpj,:) = 0._wp      ;      ptrd3dy( : ,jpj,:) = 0._wp
-         !
-      CASE( 'TRA' )              ! Tracers
-         DO jk = 1, jpkm1
-            ptrd3dx(:,:,jk) = ptrd3dx(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:)
-            ptrd3dy(:,:,jk) = ptrd3dy(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:)
-         END DO
-         !
-      END SELECT   
-
-      SELECT CASE( ctype )    !==  Basin averaged tracer/momentum trends  ==!
-      !
-      CASE( 'DYN' )              ! Momentum
-         umo(ktrd) = 0._wp
-         vmo(ktrd) = 0._wp
-         DO jk = 1, jpkm1
-            umo(ktrd) = umo(ktrd) + SUM( ptrd3dx(:,:,jk) * e1u(:,:) * e2u(:,:) * fse3u(:,:,jk) )
-            vmo(ktrd) = vmo(ktrd) + SUM( ptrd3dy(:,:,jk) * e1v(:,:) * e2v(:,:) * fse3v(:,:,jk) )
-         END DO
-         !
-      CASE( 'TRA' )              ! Tracers
-         tmo(ktrd) = 0._wp
-         smo(ktrd) = 0._wp
-         DO jk = 1, jpkm1
-            tmo(ktrd) = tmo(ktrd) + SUM( ptrd3dx(:,:,jk) * e1e2t(:,:) * fse3t(:,:,jk) )
-            smo(ktrd) = smo(ktrd) + SUM( ptrd3dy(:,:,jk) * e1e2t(:,:) * fse3t(:,:,jk) )
-         END DO
-         !
-      END SELECT
-
-      SELECT CASE( ctype )    !==  Basin averaged tracer/momentum square trends  ==!   (now field)
-      !
-      CASE( 'DYN' )              ! Momentum
-         hke(ktrd) = 0._wp
-         DO jk = 1, jpkm1
-            hke(ktrd) = hke(ktrd) + SUM(   un(:,:,jk) * ptrd3dx(:,:,jk) * e1u(:,:) * e2u(:,:) * fse3u(:,:,jk)   &
-               &                         + vn(:,:,jk) * ptrd3dy(:,:,jk) * e1v(:,:) * e2v(:,:) * fse3v(:,:,jk)   )
-         END DO
-         !
-      CASE( 'TRA' )              ! Tracers
-         t2(ktrd) = 0._wp
-         s2(ktrd) = 0._wp
-         DO jk = 1, jpkm1
-            t2(ktrd) = t2(ktrd) + SUM( ptrd3dx(:,:,jk) * tsn(:,:,jk,jp_tem) * e1e2t(:,:) * fse3t(:,:,jk) )
-            s2(ktrd) = s2(ktrd) + SUM( ptrd3dy(:,:,jk) * tsn(:,:,jk,jp_sal) * e1e2t(:,:) * fse3t(:,:,jk) )
-         END DO
-         !
-      END SELECT
-      !
-   END SUBROUTINE trd_3d
-
-
-   SUBROUTINE trd_icp_init
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_icp_init  ***
-      !! 
-      !! ** Purpose :   Read the namtrd namelist
-      !!----------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      !!----------------------------------------------------------------------
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'trd_icp_init : integral constraints properties trends'
-         WRITE(numout,*) '~~~~~~~~~~~~~'
-      ENDIF
-
-      ! Total volume at t-points:
-      tvolt = 0._wp
-      DO jk = 1, jpkm1
-         tvolt = tvolt + SUM( e1e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:) )
-      END DO
-      IF( lk_mpp )   CALL mpp_sum( tvolt )   ! sum over the global domain
-
-      IF(lwp) WRITE(numout,*) '                total ocean volume at T-point   tvolt = ',tvolt
-
-#if  defined key_trddyn
-      ! Initialization of potential to kinetic energy conversion
-      rpktrd = 0._wp
-
-      ! Total volume at u-, v- points:
-      tvolu = 0._wp
-      tvolv = 0._wp
-      DO jk = 1, jpk
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               tvolu = tvolu + e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)
-               tvolv = tvolv + e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-      IF( lk_mpp )   CALL mpp_sum( tvolu )   ! sums over the global domain
-      IF( lk_mpp )   CALL mpp_sum( tvolv )
-
-      IF(lwp) THEN
-         WRITE(numout,*) '                total ocean volume at U-point   tvolu = ',tvolu
-         WRITE(numout,*) '                total ocean volume at V-point   tvolv = ',tvolv
-      ENDIF
-#endif
-      !
-   END SUBROUTINE trd_icp_init
-
-
-   SUBROUTINE trd_dwr( kt )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_dwr  ***
-      !! 
-      !! ** Purpose :  write dynamic trends in ocean.output 
-      !!----------------------------------------------------------------------
-      !
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zcof         ! local scalar
-      REAL(wp), POINTER, DIMENSION(:,:,:)  ::  zkx, zky, zkz, zkepe  
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, jpk, zkx, zky, zkz, zkepe )
-
-      ! I. Momentum trends
-      ! -------------------
-
-      IF( MOD(kt,nn_trd) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
-
-         ! I.1 Conversion potential energy - kinetic energy
-         ! --------------------------------------------------
-         ! c a u t i o n here, trends are computed at kt+1 (now , but after the swap)
-         zkx  (:,:,:) = 0._wp
-         zky  (:,:,:) = 0._wp
-         zkz  (:,:,:) = 0._wp
-         zkepe(:,:,:) = 0._wp
-   
-         CALL eos( tsn, rhd, rhop, fsdept_n(:,:,:) )       ! now potential and in situ densities
-
-         zcof = 0.5_wp / rau0             ! Density flux at w-point
-         zkz(:,:,1) = 0._wp
-         DO jk = 2, jpk
-            zkz(:,:,jk) = e1e2t(:,:) * wn(:,:,jk) * ( rhop(:,:,jk) + rhop(:,:,jk-1) ) * tmask_i(:,:)
-         END DO
-         
-         zcof   = 0.5_wp / rau0           ! Density flux at u and v-points
-         DO jk = 1, jpkm1
-            DO jj = 1, jpjm1
-               DO ji = 1, jpim1
-                  zkx(ji,jj,jk) = zcof * e2u(ji,jj) * fse3u(ji,jj,jk) * un(ji,jj,jk) * ( rhop(ji,jj,jk) + rhop(ji+1,jj,jk) )
-                  zky(ji,jj,jk) = zcof * e1v(ji,jj) * fse3v(ji,jj,jk) * vn(ji,jj,jk) * ( rhop(ji,jj,jk) + rhop(ji,jj+1,jk) )
-               END DO
-            END DO
-         END DO
-         
-         DO jk = 1, jpkm1                 ! Density flux divergence at t-point
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
-                  zkepe(ji,jj,jk) = - (  zkz(ji,jj,jk) - zkz(ji  ,jj  ,jk+1)               &
-                     &                 + zkx(ji,jj,jk) - zkx(ji-1,jj  ,jk  )               &
-                     &                 + zky(ji,jj,jk) - zky(ji  ,jj-1,jk  )   )           &
-                     &              / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) ) * tmask(ji,jj,jk) * tmask_i(ji,jj)
-               END DO
-            END DO
-         END DO
-
-         ! I.2 Basin averaged kinetic energy trend
-         ! ----------------------------------------
-         peke = 0._wp
-         DO jk = 1, jpkm1
-            peke = peke + SUM( zkepe(:,:,jk) * fsdept(:,:,jk) * e1e2t(:,:) * fse3t(:,:,jk) )
-         END DO
-         peke = grav * peke
-
-         ! I.3 Sums over the global domain
-         ! ---------------------------------
-         IF( lk_mpp ) THEN
-            CALL mpp_sum( peke )
-            CALL mpp_sum( umo , jptot_dyn )
-            CALL mpp_sum( vmo , jptot_dyn )
-            CALL mpp_sum( hke , jptot_dyn )
-         ENDIF
-
-         ! I.2 Print dynamic trends in the ocean.output file
-         ! --------------------------------------------------
-
-         IF(lwp) THEN
-            WRITE (numout,*)
-            WRITE (numout,*)
-            WRITE (numout,9500) kt
-            WRITE (numout,9501) umo(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_had) / tvolu, vmo(jpicpd_had) / tvolv
-            WRITE (numout,9507) umo(jpicpd_zad) / tvolu, vmo(jpicpd_zad) / tvolv
-            WRITE (numout,9508) umo(jpicpd_zdf) / tvolu, vmo(jpicpd_zdf) / tvolv
-            WRITE (numout,9509) umo(jpicpd_spg) / tvolu, vmo(jpicpd_spg) / tvolv
-            WRITE (numout,9510) umo(jpicpd_swf) / tvolu, vmo(jpicpd_swf) / tvolv
-            WRITE (numout,9511) umo(jpicpd_dat) / tvolu, vmo(jpicpd_dat) / tvolv
-            WRITE (numout,9512) umo(jpicpd_bfr) / tvolu, vmo(jpicpd_bfr) / tvolv
-            WRITE (numout,9513)
-            WRITE (numout,9514)                                                 &
-            &     (  umo(jpicpd_hpg) + umo(jpicpd_keg) + umo(jpicpd_rvo) + umo(jpicpd_pvo) + umo(jpicpd_ldf)   &
-            &      + umo(jpicpd_had) + 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_had) + vmo(jpicpd_zad) + vmo(jpicpd_zdf) + vmo(jpicpd_spg) + vmo(jpicpd_dat)   &
-            &      + vmo(jpicpd_swf) + vmo(jpicpd_bfr) ) / tvolv
-         ENDIF
-
- 9500    FORMAT(' momentum trend at it= ', i6, ' :', /' ==============================')
- 9501    FORMAT(' pressure gradient          u= ', e20.13, '    v= ', e20.13)
- 9502    FORMAT(' ke gradient                u= ', e20.13, '    v= ', e20.13)
- 9503    FORMAT(' relative vorticity term    u= ', e20.13, '    v= ', e20.13)
- 9504    FORMAT(' coriolis term              u= ', e20.13, '    v= ', e20.13)
- 9505    FORMAT(' horizontal diffusion       u= ', e20.13, '    v= ', e20.13)
- 9506    FORMAT(' horizontal advection       u= ', e20.13, '    v= ', e20.13)
- 9507    FORMAT(' vertical advection         u= ', e20.13, '    v= ', e20.13)
- 9508    FORMAT(' vertical diffusion         u= ', e20.13, '    v= ', e20.13)
- 9509    FORMAT(' surface pressure gradient  u= ', e20.13, '    v= ', e20.13)
- 9510    FORMAT(' surface wind forcing       u= ', e20.13, '    v= ', e20.13)
- 9511    FORMAT(' dampimg term               u= ', e20.13, '    v= ', e20.13)
- 9512    FORMAT(' bottom flux                u= ', e20.13, '    v= ', e20.13)
- 9513    FORMAT(' -----------------------------------------------------------------------------')
- 9514    FORMAT(' total trend                u= ', e20.13, '    v= ', e20.13)
-
-         IF(lwp) THEN
-            WRITE (numout,*)
-            WRITE (numout,*)
-            WRITE (numout,9520) kt
-            WRITE (numout,9521) hke(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_had) / tvolt
-            WRITE (numout,9527) hke(jpicpd_zad) / tvolt
-            WRITE (numout,9528) hke(jpicpd_zdf) / tvolt
-            WRITE (numout,9529) hke(jpicpd_spg) / tvolt
-            WRITE (numout,9530) hke(jpicpd_swf) / tvolt
-            WRITE (numout,9531) hke(jpicpd_dat) / tvolt
-            WRITE (numout,9532) hke(jpicpd_bfr) / tvolt
-            WRITE (numout,9533)
-            WRITE (numout,9534)   &
-            &     (  hke(jpicpd_hpg) + hke(jpicpd_keg) + hke(jpicpd_rvo) + hke(jpicpd_pvo) + hke(jpicpd_ldf)   &
-            &      + hke(jpicpd_had) + hke(jpicpd_zad) + hke(jpicpd_zdf) + hke(jpicpd_spg) + hke(jpicpd_dat)   &
-            &      + hke(jpicpd_swf) + hke(jpicpd_bfr) ) / tvolt
-         ENDIF
-
- 9520    FORMAT(' kinetic energy trend at it= ', i6, ' :', /' ====================================')
- 9521    FORMAT(' pressure gradient         u2= ', e20.13)
- 9522    FORMAT(' ke gradient               u2= ', e20.13)
- 9523    FORMAT(' relative vorticity term   u2= ', e20.13)
- 9524    FORMAT(' coriolis term             u2= ', e20.13)
- 9525    FORMAT(' horizontal diffusion      u2= ', e20.13)
- 9526    FORMAT(' horizontal advection      u2= ', e20.13)
- 9527    FORMAT(' vertical advection        u2= ', e20.13)
- 9528    FORMAT(' vertical diffusion        u2= ', e20.13)
- 9529    FORMAT(' surface pressure gradient u2= ', e20.13)
- 9530    FORMAT(' surface wind forcing      u2= ', e20.13)
- 9531    FORMAT(' dampimg term              u2= ', e20.13)
- 9532    FORMAT(' bottom flux               u2= ', e20.13)
- 9533    FORMAT(' --------------------------------------------------')
- 9534    FORMAT(' total trend               u2= ', e20.13)
-
-         IF(lwp) THEN
-            WRITE (numout,*)
-            WRITE (numout,*)
-            WRITE (numout,9540) kt
-            WRITE (numout,9541) ( hke(jpicpd_keg) + hke(jpicpd_rvo) + hke(jpicpd_had) + hke(jpicpd_zad) ) / tvolt
-            WRITE (numout,9542) ( hke(jpicpd_keg) + hke(jpicpd_had) + 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 + horizontal + 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)
-         !
-         ! Save potential to kinetic energy conversion for next time step
-         rpktrd = peke
-         !
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, jpk, zkx, zky, zkz, zkepe )
-      !
-   END SUBROUTINE trd_dwr
-
-
-   SUBROUTINE trd_twr( kt )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_twr  ***
-      !! 
-      !! ** Purpose :  write active tracers trends in ocean.output 
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
-      !!----------------------------------------------------------------------
-
-      ! I. Tracers trends
-      ! -----------------
-
-      IF( MOD(kt,nn_trd) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
-
-         ! I.1 Sums over the global domain
-         ! -------------------------------
-         IF( lk_mpp ) THEN
-            CALL mpp_sum( tmo, jptot_tra )   
-            CALL mpp_sum( smo, jptot_tra )
-            CALL mpp_sum( t2 , jptot_tra )
-            CALL mpp_sum( s2 , jptot_tra )
-         ENDIF
-
-         ! I.2 Print tracers trends in the ocean.output file
-         ! --------------------------------------------------
-         
-         IF(lwp) THEN
-            WRITE (numout,*)
-            WRITE (numout,*)
-            WRITE (numout,9400) kt
-            WRITE (numout,9401)  tmo(jpicpt_xad) / tvolt, smo(jpicpt_xad) / tvolt
-            WRITE (numout,9411)  tmo(jpicpt_yad) / tvolt, 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
-
-9400     FORMAT(' tracer trend at it= ',i6,' :     temperature',   &
-              '              salinity',/' ============================')
-9401     FORMAT(' zonal      advection        ',e20.13,'     ',e20.13)
-9411     FORMAT(' meridional advection        ',e20.13,'     ',e20.13)
-9402     FORMAT(' vertical advection          ',e20.13,'     ',e20.13)
-9403     FORMAT(' horizontal diffusion        ',e20.13,'     ',e20.13)
-9404     FORMAT(' vertical diffusion          ',e20.13,'     ',e20.13)
-9405     FORMAT(' static instability mixing   ',e20.13,'     ',e20.13)
-9406     FORMAT(' damping term                ',e20.13,'     ',e20.13)
-9407     FORMAT(' penetrative qsr             ',e20.13)
-9408     FORMAT(' non solar radiation         ',e20.13,'     ',e20.13)
-9409     FORMAT(' -------------------------------------------------------------------------')
-9410     FORMAT(' total trend                 ',e20.13,'     ',e20.13)
-
-
-         IF(lwp) THEN
-            WRITE (numout,*)
-            WRITE (numout,*)
-            WRITE (numout,9420) kt
-            WRITE (numout,9421)   t2(jpicpt_xad) / tvolt, s2(jpicpt_xad) / tvolt
-            WRITE (numout,9431)   t2(jpicpt_yad) / tvolt, 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(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
-
-9420     FORMAT(' tracer**2 trend at it= ', i6, ' :      temperature',   &
-            '               salinity', /, ' ===============================')
-9421     FORMAT(' zonal      advection      * t   ', e20.13, '     ', e20.13)
-9431     FORMAT(' meridional advection      * t   ', e20.13, '     ', e20.13)
-9422     FORMAT(' vertical advection        * t   ', e20.13, '     ', e20.13)
-9423     FORMAT(' horizontal diffusion      * t   ', e20.13, '     ', e20.13)
-9424     FORMAT(' vertical diffusion        * t   ', e20.13, '     ', e20.13)
-9425     FORMAT(' static instability mixing * t   ', e20.13, '     ', e20.13)
-9426     FORMAT(' damping term              * t   ', e20.13, '     ', e20.13)
-9427     FORMAT(' penetrative qsr           * t   ', e20.13)
-9428     FORMAT(' non solar radiation       * t   ', e20.13, '     ', e20.13)
-9429     FORMAT(' -----------------------------------------------------------------------------')
-9430     FORMAT(' total trend                *t = ', e20.13, '  *s = ', e20.13)
-
-
-         IF(lwp) THEN
-            WRITE (numout,*)
-            WRITE (numout,*)
-            WRITE (numout,9440) kt
-            WRITE (numout,9441) ( tmo(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
-
-9440     FORMAT(' tracer consistency at it= ',i6,   &
-            ' :         temperature','                salinity',/,   &
-            ' ==================================')
-9441     FORMAT(' 0 = horizontal+vertical advection +    ',e20.13,'       ',e20.13)
-9442     FORMAT('     1st lev vertical advection         ',e20.13,'       ',e20.13)
-9443     FORMAT(' 0 = horizontal diffusion               ',e20.13,'       ',e20.13)
-9444     FORMAT(' 0 = vertical diffusion                 ',e20.13,'       ',e20.13)
-9445     FORMAT(' 0 = static instability mixing          ',e20.13,'       ',e20.13)
-9446     FORMAT(' 0 = horizontal+vertical advection * t  ',e20.13,'       ',e20.13)
-9447     FORMAT(' 0 > horizontal diffusion          * t  ',e20.13,'       ',e20.13)
-9448     FORMAT(' 0 > vertical diffusion            * t  ',e20.13,'       ',e20.13)
-9449     FORMAT(' 0 > static instability mixing     * t  ',e20.13,'       ',e20.13)
-         !
-      ENDIF
-      !
-   END SUBROUTINE trd_twr
-
-#   else
-   !!----------------------------------------------------------------------
-   !!   Default case :                                         Empty module
-   !!----------------------------------------------------------------------
-   INTERFACE trd_icp
-      MODULE PROCEDURE trd_2d, trd_3d
-   END INTERFACE
-
-CONTAINS
-   SUBROUTINE trd_2d( ptrd2dx, ptrd2dy, ktrd , ctype )       ! Empty routine
-      REAL, DIMENSION(:,:) ::   ptrd2dx, ptrd2dy
-      INTEGER                     , INTENT(in   ) ::   ktrd         ! tracer trend index
-      CHARACTER(len=3)            , INTENT(in   ) ::   ctype        ! momentum ('DYN') or tracers ('TRA') trends
-      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(:,:,:) ::   ptrd3dx, ptrd3dy
-      INTEGER                     , INTENT(in   ) ::   ktrd         ! tracer trend index
-      CHARACTER(len=3)            , INTENT(in   ) ::   ctype        ! momentum ('DYN') or tracers ('TRA') trends
-      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
-      WRITE(*,*) 'trd_dwr: You should not have seen this print! error ?', kt
-   END SUBROUTINE trd_dwr
-   SUBROUTINE trd_twr( kt )          ! Empty routine
-      WRITE(*,*) 'trd_twr: You should not have seen this print! error ?', kt
-   END SUBROUTINE trd_twr
-#endif
-
-   !!======================================================================
-END MODULE trdicp
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdicp_oce.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdicp_oce.F90	(revision 4944)
+++ 	(revision )
@@ -1,90 +1,0 @@
-MODULE trdicp_oce
-   !!======================================================================
-   !!                   ***  MODULE trdicp_oce  ***
-   !! Ocean trends :   set tracer and momentum trend variables
-   !!======================================================================
-
-   !!----------------------------------------------------------------------
-   !!   'key_trdtra'   or                         tracer trends diagnostics
-   !!   'key_trddyn'                            momentum trends diagnostics
-   !!----------------------------------------------------------------------
-   USE par_oce                 ! ocean parameters
-
-   IMPLICIT NONE
-   PUBLIC
-
-#if  defined key_trdtra   &&   defined key_trddyn    ||   defined key_esopa
-   LOGICAL, PARAMETER ::   lk_trdtra = .TRUE.    !: tracers  trend flag
-   LOGICAL, PARAMETER ::   lk_trddyn = .TRUE.    !: momentum trend flag
-#elif  defined key_trdtra
-   LOGICAL, PARAMETER ::   lk_trdtra = .TRUE.    !: tracers  trend flag
-   LOGICAL, PARAMETER ::   lk_trddyn = .FALSE.   !: momentum trend flag
-#elif  defined key_trddyn
-   LOGICAL, PARAMETER ::   lk_trdtra = .FALSE.   !: tracers  trend flag
-   LOGICAL, PARAMETER ::   lk_trddyn = .TRUE.    !: momentum trend flag
-#else
-   LOGICAL, PARAMETER ::   lk_trdtra = .FALSE.   !: tracers  trend flag
-   LOGICAL, PARAMETER ::   lk_trddyn = .FALSE.   !: momentum trend flag
-#endif
-
-   !                                        !!! => tracer trends indexes <=
-   INTEGER, PARAMETER ::   jpicpt_xad =  1   !: x- horizontal advection
-   INTEGER, PARAMETER ::   jpicpt_yad =  2   !: y- horizontal advection
-   INTEGER, PARAMETER ::   jpicpt_zad =  3   !: z- vertical   advection
-   INTEGER, PARAMETER ::   jpicpt_ldf =  4   !: lateral       diffusion
-   INTEGER, PARAMETER ::   jpicpt_zdf =  5   !: vertical diffusion (Kz)
-   INTEGER, PARAMETER ::   jpicpt_bbc =  6   !: Bottom Boundary Condition (geoth. flux) 
-   INTEGER, PARAMETER ::   jpicpt_bbl =  7   !: Bottom Boundary Layer (diffusive/convective)
-   INTEGER, PARAMETER ::   jpicpt_npc =  8   !: static instability mixing
-   INTEGER, PARAMETER ::   jpicpt_dmp =  9   !: damping
-   INTEGER, PARAMETER ::   jpicpt_qsr = 10   !: penetrative solar radiation
-   INTEGER, PARAMETER ::   jpicpt_nsr = 11   !: non solar radiation
-   INTEGER, PARAMETER ::   jpicpt_zl1 = 12   !: first level vertical flux
-
-   !                                        !!! => Total tracer trends indexes <=
-   INTEGER, PARAMETER ::   jptot_tra  = 12   !: change it when adding/removing one indice above
-   
-   !                                        !!! => dynamic trends indexes <=
-   INTEGER, PARAMETER ::   jpicpd_hpg =  1   !: hydrostatic pressure gradient 
-   INTEGER, PARAMETER ::   jpicpd_keg =  2   !: kinetic energy gradient
-   INTEGER, PARAMETER ::   jpicpd_rvo =  3   !: relative vorticity
-   INTEGER, PARAMETER ::   jpicpd_pvo =  4   !: planetary vorticity
-   INTEGER, PARAMETER ::   jpicpd_ldf =  5   !: lateral diffusion
-   INTEGER, PARAMETER ::   jpicpd_had =  6   !: horizontal advection
-   INTEGER, PARAMETER ::   jpicpd_zad =  7   !: vertical advection
-   INTEGER, PARAMETER ::   jpicpd_zdf =  8   !: vertical diffusion
-   INTEGER, PARAMETER ::   jpicpd_spg =  9   !: surface pressure gradient
-   INTEGER, PARAMETER ::   jpicpd_dat = 10   !: damping term
-   INTEGER, PARAMETER ::   jpicpd_swf = 11   !: surface wind forcing
-   INTEGER, PARAMETER ::   jpicpd_bfr = 12   !: bottom friction 
-
-   !                                        !!! => Total dynamic trends indexes <=
-   INTEGER, PARAMETER ::   jptot_dyn  = 12   !: 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
-   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(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(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
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!======================================================================
-END MODULE trdicp_oce
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdini.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdini.F90	(revision 4946)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdini.F90	(revision 4946)
@@ -0,0 +1,108 @@
+MODULE trdini
+   !!======================================================================
+   !!                       ***  MODULE  trdini  ***
+   !! Ocean diagnostics:  ocean tracers and dynamic trends
+   !!=====================================================================
+   !! History :   3.5  !  2012-02  (G. Madec) add 3D trends output for T, S, U, V, PE and KE
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   trd_init      : initialization step
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean domain
+   USE trd_oce        ! trends: ocean variables
+   USE trdken         ! trends: 3D kinetic   energy
+   USE trdpen         ! trends: 3D potential energy
+   USE trdglo         ! trends: global domain averaged tracers and dynamics
+   USE trdmxl         ! trends: mixed layer averaged trends (tracer only)
+   USE trdvor         ! trends: vertical averaged vorticity 
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trd_init   ! called by nemogcm.F90 module
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: trdini.F90 3329 2012-03-16 12:22:15Z gm $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trd_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_init  ***
+      !! 
+      !! ** Purpose :   Initialization of trend diagnostics
+      !!----------------------------------------------------------------------
+      INTEGER ::   ios   ! local integer
+      !!
+      NAMELIST/namtrd/ ln_dyn_trd, ln_KE_trd, ln_vor_trd, ln_dyn_mxl,   &
+         &             ln_tra_trd, ln_PE_trd, ln_glo_trd, ln_tra_mxl, nn_trd 
+      !!----------------------------------------------------------------------
+      !
+      REWIND( numnam_ref )              ! Namelist namtrd in reference namelist : trends diagnostic
+      READ  ( numnam_ref, namtrd, IOSTAT = ios, ERR = 901 )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrd in reference namelist', lwp )
+      !
+      REWIND( numnam_cfg )              ! Namelist namtrd in configuration namelist : trends diagnostic
+      READ  ( numnam_cfg, namtrd, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrd in configuration namelist', lwp )
+      WRITE( numond, namtrd )
+      !
+      IF(lwp) THEN                  ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) ' trd_init : Momentum/Tracers trends'
+         WRITE(numout,*) ' ~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namtrd : set trends parameters'
+         WRITE(numout,*) '      global domain averaged dyn & tra trends   ln_glo_trd  = ', ln_glo_trd
+         WRITE(numout,*) '      U & V trends: 3D output                   ln_dyn_trd  = ', ln_dyn_trd
+         WRITE(numout,*) '      U & V trends: Mixed Layer averaged        ln_dyn_mxl  = ', ln_dyn_mxl
+         WRITE(numout,*) '      T & S trends: 3D output                   ln_tra_trd  = ', ln_tra_trd
+         WRITE(numout,*) '      T & S trends: Mixed Layer averaged        ln_tra_mxl  = ', ln_tra_mxl
+         WRITE(numout,*) '      Kinetic   Energy trends                   ln_KE_trd   = ', ln_KE_trd
+         WRITE(numout,*) '      Potential Energy trends                   ln_PE_trd   = ', ln_PE_trd
+         WRITE(numout,*) '      Barotropic vorticity trends               ln_vor_trd  = ', ln_vor_trd
+         !
+         WRITE(numout,*) '      frequency of trends diagnostics (glo)     nn_trd      = ', nn_trd
+      ENDIF
+      !
+      !                             ! trend extraction flags  
+      l_trdtra = .FALSE.                                                       ! tracers  
+      IF ( ln_tra_trd .OR. ln_PE_trd .OR. ln_tra_mxl .OR.   &
+         & ln_glo_trd                                       )   l_trdtra = .TRUE. 
+      !
+      l_trddyn = .FALSE.                                                       ! momentum
+      IF ( ln_dyn_trd .OR. ln_KE_trd .OR. ln_dyn_mxl .OR.   &
+         & ln_vor_trd .OR. ln_glo_trd                       )   l_trddyn = .TRUE.
+      !
+
+!!gm check the stop below      
+      IF( ln_dyn_mxl )   CALL ctl_stop( 'ML diag on momentum are not yet coded we stop' )
+      !
+
+!!gm end
+      IF( ln_tra_mxl .OR. ln_vor_trd )   CALL ctl_stop( 'ML tracer and Barotropic vorticity diags are still using old IOIPSL' )
+!!gm end
+      !
+      IF( lk_vvl .AND. ( l_trdtra .OR. l_trddyn ) )  CALL ctl_stop( 'trend diagnostics with variable volume not validated' )
+      
+!!gm  : Potential BUG : 3D output only for vector invariant form!  add a ctl_stop or code the flux form case
+!!gm  : bug/pb for vertical advection of tracer in vvl case: add T.dt[eta] in the output... 
+
+      !                             ! diagnostic initialization  
+      IF( ln_glo_trd )   CALL trd_glo_init      ! global domain averaged trends
+      IF( ln_tra_mxl )   CALL trd_mxl_init      ! mixed-layer          trends  
+      IF( ln_vor_trd )   CALL trd_vor_init      ! barotropic vorticity trends
+      IF( ln_KE_trd  )   CALL trd_ken_init      ! 3D Kinetic    energy trends
+      IF( ln_PE_trd  )   CALL trd_pen_init      ! 3D Potential  energy trends
+      !
+   END SUBROUTINE trd_init
+
+   !!======================================================================
+END MODULE trdini
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdken.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdken.F90	(revision 4946)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdken.F90	(revision 4946)
@@ -0,0 +1,281 @@
+MODULE trdken
+   !!======================================================================
+   !!                       ***  MODULE  trdken  ***
+   !! Ocean diagnostics:  compute and output 3D kinetic energy trends
+   !!=====================================================================
+   !! History :  3.5  !  2012-02  (G. Madec) original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   trd_ken       : compute and output 3D Kinetic energy trends using IOM
+   !!   trd_ken_init  : initialisation
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables
+   USE zdf_oce        ! ocean vertical physics variables
+   USE trd_oce        ! trends: ocean variables
+!!gm   USE dynhpg          ! hydrostatic pressure gradient   
+   USE zdfbfr         ! bottom friction
+   USE ldftra_oce     ! ocean active tracers lateral physics
+   USE sbc_oce        ! surface boundary condition: ocean
+   USE phycst         ! physical constants
+   USE trdvor         ! ocean vorticity trends 
+   USE trdglo         ! trends:global domain averaged
+   USE trdmxl         ! ocean active mixed layer tracers trends 
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory allocation
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trd_ken       ! called by trddyn module
+   PUBLIC   trd_ken_init  ! called by trdini module
+
+   INTEGER ::   nkstp       ! current time step 
+
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   bu, bv   ! volume of u- and v-boxes
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   r1_bt    ! inverse of t-box volume
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: trdken.F90 3329 2012-03-16 12:22:15Z gm $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION trd_ken_alloc()
+      !!---------------------------------------------------------------------
+      !!                  ***  FUNCTION trd_ken_alloc  ***
+      !!---------------------------------------------------------------------
+      ALLOCATE( bu(jpi,jpj,jpk) , bv(jpi,jpj,jpk) , r1_bt(jpi,jpj,jpk) , STAT= trd_ken_alloc )
+      !
+      IF( lk_mpp             )   CALL mpp_sum ( trd_ken_alloc )
+      IF( trd_ken_alloc /= 0 )   CALL ctl_warn('trd_ken_alloc: failed to allocate arrays')
+   END FUNCTION trd_ken_alloc
+
+
+   SUBROUTINE trd_ken( putrd, pvtrd, ktrd, kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_ken  ***
+      !! 
+      !! ** Purpose :   output 3D Kinetic Energy trends using IOM
+      !!
+      !! ** Method  : - apply lbc to the input masked velocity trends 
+      !!              - compute the associated KE trend:
+      !!          zke = 0.5 * (  mi-1[ un * putrd * bu ] + mj-1[ vn * pvtrd * bv]  ) / bt
+      !!      where bu, bv, bt are the volume of u-, v- and t-boxes. 
+      !!              - vertical diffusion case (jpdyn_zdf): 
+      !!          diagnose separately the KE trend associated with wind stress
+      !!              - bottom friction case (jpdyn_bfr):
+      !!          explicit case (ln_bfrimp=F): bottom trend put in the 1st level 
+      !!                                       of putrd, pvtrd
+      !
+      !
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   putrd, pvtrd   ! U and V masked trends
+      INTEGER                   , INTENT(in   ) ::   ktrd           ! trend index
+      INTEGER                   , INTENT(in   ) ::   kt             ! time step
+      !
+      INTEGER ::   ji, jj, jk       ! dummy loop indices
+      INTEGER ::   ikbu  , ikbv     ! local integers
+      INTEGER ::   ikbum1, ikbvm1   !   -       -
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   z2dx, z2dy, zke2d   ! 2D workspace 
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zke                 ! 3D workspace 
+      !!----------------------------------------------------------------------
+      !
+      CALL wrk_alloc( jpi, jpj, jpk, zke )
+      !
+      CALL lbc_lnk( putrd, 'U', -1. )   ;   CALL lbc_lnk( pvtrd, 'V', -1. )      ! lateral boundary conditions
+      !
+      IF ( lk_vvl .AND. kt /= nkstp ) THEN   ! Variable volume: set box volume at the 1st call of kt time step
+         nkstp = kt
+         DO jk = 1, jpkm1
+            bu   (:,:,jk) =  e1u(:,:) * e2u(:,:) * fse3u_n(:,:,jk)
+            bv   (:,:,jk) =  e1v(:,:) * e2v(:,:) * fse3v_n(:,:,jk)
+            r1_bt(:,:,jk) = 1._wp / ( e1e2t(:,:) * fse3t_n(:,:,jk) ) * tmask(:,:,jk)
+         END DO
+      ENDIF
+      !
+      zke(:,:,jpk) = 0._wp
+      zke(1,:, : ) = 0._wp
+      zke(:,1, : ) = 0._wp
+      DO jk = 1, jpkm1
+         DO jj = 2, jpj
+            DO ji = 2, jpi
+               zke(ji,jj,jk) = 0.5_wp * rau0 *( un(ji  ,jj,jk) * putrd(ji  ,jj,jk) * bu(ji  ,jj,jk)  &
+                  &                           + un(ji-1,jj,jk) * putrd(ji-1,jj,jk) * bu(ji-1,jj,jk)  &
+                  &                           + vn(ji,jj  ,jk) * pvtrd(ji,jj  ,jk) * bv(ji,jj  ,jk)  &
+                  &                           + vn(ji,jj-1,jk) * pvtrd(ji,jj-1,jk) * bv(ji,jj-1,jk)  ) * r1_bt(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+      SELECT CASE( ktrd )
+      	CASE( jpdyn_hpg )   ;   CALL iom_put( "ketrd_hpg", zke )    ! hydrostatic pressure gradient
+      	CASE( jpdyn_spg )   ;   CALL iom_put( "ketrd_spg", zke )    ! surface pressure gradient
+      	CASE( jpdyn_spgexp );   CALL iom_put( "ketrd_spgexp", zke ) ! surface pressure gradient (explicit)
+      	CASE( jpdyn_spgflt );   CALL iom_put( "ketrd_spgflt", zke ) ! surface pressure gradient (filter)
+      	CASE( jpdyn_pvo )   ;   CALL iom_put( "ketrd_pvo", zke )    ! planetary vorticity
+      	CASE( jpdyn_rvo )   ;   CALL iom_put( "ketrd_rvo", zke )    ! relative  vorticity     (or metric term)
+      	CASE( jpdyn_keg )   ;   CALL iom_put( "ketrd_keg", zke )    ! Kinetic Energy gradient (or had)
+      	CASE( jpdyn_zad )   ;   CALL iom_put( "ketrd_zad", zke )    ! vertical   advection
+      	CASE( jpdyn_ldf )   ;   CALL iom_put( "ketrd_ldf", zke )    ! lateral diffusion
+      	CASE( jpdyn_zdf )   ;   CALL iom_put( "ketrd_zdf", zke )    ! vertical diffusion 
+                                 !                                   ! wind stress trends
+                              	CALL wrk_alloc( jpi, jpj, z2dx, z2dy, zke2d )
+         						z2dx(:,:) = un(:,:,1) * ( utau_b(:,:) + utau(:,:) ) * e1u(:,:) * e2u(:,:) * umask(:,:,1)
+         						z2dy(:,:) = vn(:,:,1) * ( vtau_b(:,:) + vtau(:,:) ) * e1v(:,:) * e2v(:,:) * vmask(:,:,1)
+         						zke2d(1,:) = 0._wp   ;   zke2d(:,1) = 0._wp
+         						DO jj = 2, jpj
+            					   DO ji = 2, jpi
+               						zke2d(ji,jj) = 0.5_wp * (   z2dx(ji,jj) + z2dx(ji-1,jj)   &
+                  					&                         + z2dy(ji,jj) + z2dy(ji,jj-1)   ) * r1_bt(ji,jj,1)
+            					   END DO
+         						END DO
+                              	CALL iom_put( "ketrd_tau", zke2d )
+                              	CALL wrk_dealloc( jpi, jpj     , z2dx, z2dy, zke2d )
+      	CASE( jpdyn_bfr )   ;   CALL iom_put( "ketrd_bfr", zke )    ! bottom friction (explicit case) 
+!!gm TO BE DONE properly
+!!gm only valid if ln_bfrimp=F otherwise the bottom stress as to be recomputed at the end of the computation....
+!         IF(.NOT. ln_bfrimp) THEN
+!            DO jj = 1, jpj    !   
+!               DO ji = 1, jpi
+!                  ikbu = mbku(ji,jj)         ! deepest ocean u- & v-levels
+!                  ikbv = mbkv(ji,jj)   
+!                  z2dx(ji,jj) = un(ji,jj,ikbu) * bfrua(ji,jj) * un(ji,jj,ikbu)
+!                  z2dy(ji,jj) = vn(ji,jj,ikbu) * bfrva(ji,jj) * vn(ji,jj,ikbv)
+!               END DO
+!            END DO
+!            zke2d(1,:) = 0._wp   ;   zke2d(:,1) = 0._wp
+!            DO jj = 2, jpj
+!               DO ji = 2, jpi
+!                  zke2d(ji,jj) = 0.5_wp * (   z2dx(ji,jj) + z2dx(ji-1,jj)   &
+!                     &                      + z2dy(ji,jj) + z2dy(ji,jj-1)   ) * r1_bt(ji,jj,  BEURK!!!
+!               END DO
+!            END DO
+!                              CALL iom_put( "ketrd_bfr", zke2d )    ! bottom friction (explicit case)
+!         ENDIF
+!!gm end
+      	CASE( jpdyn_atf )   ;   CALL iom_put( "ketrd_atf", zke )    ! asselin filter trends 
+!! a faire !!!!  idee changer dynnxt pour avoir un appel a jpdyn_bfr avant le swap !!!
+!! reflechir a une possible sauvegarde du "vrai" un,vn pour le calcul de atf....
+!
+!         IF( ln_bfrimp ) THEN                                          ! bottom friction (implicit case)
+!            DO jj = 1, jpj                                                  ! after velocity known (now filed at this stage)
+!               DO ji = 1, jpi
+!                  ikbu = mbku(ji,jj)          ! deepest ocean u- & v-levels
+!                  ikbv = mbkv(ji,jj)
+!                  z2dx(ji,jj) = un(ji,jj,ikbu) * bfrua(ji,jj) * un(ji,jj,ikbu) / fse3u(ji,jj,ikbu)
+!                  z2dy(ji,jj) = un(ji,jj,ikbu) * bfrva(ji,jj) * vn(ji,jj,ikbv) / fse3v(ji,jj,ikbv)
+!               END DO
+!            END DO
+!            zke2d(1,:) = 0._wp   ;   zke2d(:,1) = 0._wp
+!            DO jj = 2, jpj
+!               DO ji = 2, jpi
+!                  zke2d(ji,jj) = 0.5_wp * (   z2dx(ji,jj) + z2dx(ji-1,jj)   &
+!                     &                      + z2dy(ji,jj) + z2dy(ji,jj-1)   )
+!               END DO
+!            END DO
+!                              CALL iom_put( "ketrd_bfri", zke2d )
+!         ENDIF
+      	CASE( jpdyn_ken )   ;   ! kinetic energy
+      							! called in dynnxt.F90 before asselin time filter
+      							! with putrd=ua and pvtrd=va
+      							zke(:,:,:) = 0.5_wp * zke(:,:,:)
+      							CALL iom_put( "KE", zke )
+      							!
+      							CALL ken_p2k( kt , zke )
+            					CALL iom_put( "ketrd_convP2K", zke )     ! conversion -rau*g*w
+         !
+      END SELECT
+      !
+      CALL wrk_dealloc( jpi, jpj, jpk, zke )
+      !
+   END SUBROUTINE trd_ken
+
+
+   SUBROUTINE ken_p2k( kt , pconv )
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE ken_p2k  ***
+      !!                    
+      !! ** Purpose :   compute rate of conversion from potential to kinetic energy
+      !!
+      !! ** Method  : - compute conv defined as -rau*g*w on T-grid points
+      !! 
+      !! ** Work only for full steps and partial steps (ln_hpg_zco or ln_hpg_zps)
+      !!---------------------------------------------------------------------- 
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      !!
+      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(  out) ::   pconv
+      !
+      INTEGER  ::   ji, jj, jk                       ! dummy loop indices
+      INTEGER  ::   iku, ikv                         ! temporary integers
+      REAL(wp) ::   zcoef                            ! temporary scalars
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zconv  ! temporary conv on W-grid
+      !!----------------------------------------------------------------------
+      !
+      CALL wrk_alloc( jpi,jpj,jpk, zconv )
+      !
+      ! Local constant initialization 
+      zcoef = - rau0 * grav * 0.5_wp      
+      
+      !  Surface value (also valid in partial step case)
+      zconv(:,:,1) = zcoef * ( 2._wp * rhd(:,:,1) ) * wn(:,:,1) * fse3w(:,:,1)
+
+      ! interior value (2=<jk=<jpkm1)
+      DO jk = 2, jpk
+         zconv(:,:,jk) = zcoef * ( rhd(:,:,jk) + rhd(:,:,jk-1) ) * wn(:,:,jk) * fse3w(:,:,jk)
+      END DO
+
+      ! conv value on T-point
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zcoef = 0.5_wp / fse3t(ji,jj,jk)
+               pconv(ji,jj,jk) = zcoef * ( zconv(ji,jj,jk) + zconv(ji,jj,jk+1) ) * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+      CALL wrk_dealloc( jpi,jpj,jpk, zconv )      
+      !
+   END SUBROUTINE ken_p2k
+
+
+   SUBROUTINE trd_ken_init
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_ken_init  ***
+      !! 
+      !! ** Purpose :   initialisation of 3D Kinetic Energy trend diagnostic
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trd_ken_init : 3D Kinetic Energy trends'
+         WRITE(numout,*) '~~~~~~~~~~~~~'
+      ENDIF
+      !                           ! allocate box volume arrays
+      IF ( trd_ken_alloc() /= 0 )   CALL ctl_stop('trd_ken_alloc: failed to allocate arrays')
+      !
+!!gm      IF( .NOT. (ln_hpg_zco.OR.ln_hpg_zps) )   &
+!!gm         &   CALL ctl_stop('trd_ken_init : only full and partial cells are coded for conversion rate')
+      !
+      IF ( .NOT.lk_vvl ) THEN     ! constant volume: bu, bv, 1/bt computed one for all
+         DO jk = 1, jpkm1
+            bu   (:,:,jk) =  e1u(:,:) * e2u(:,:) * fse3u_n(:,:,jk)
+            bv   (:,:,jk) =  e1v(:,:) * e2v(:,:) * fse3v_n(:,:,jk)
+            r1_bt(:,:,jk) = 1._wp / ( e1e2t(:,:) * fse3t_n(:,:,jk) )
+         END DO
+      ENDIF
+      !
+   END SUBROUTINE trd_ken_init
+
+   !!======================================================================
+END MODULE trdken
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld.F90	(revision 4944)
+++ 	(revision )
@@ -1,979 +1,0 @@
-MODULE trdmld
-   !!======================================================================
-   !!                       ***  MODULE  trdmld  ***
-   !! 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
-   !!   trd_mld_zint     : T and S trends vertical integration
-   !!   trd_mld_init     : initialization step
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables
-   USE trdmod_oce      ! ocean variables trends
-   USE trdmld_oce      ! ocean variables trends
-   USE ldftra_oce      ! ocean active tracers lateral physics
-   USE zdf_oce         ! ocean vertical physics
-   USE in_out_manager  ! I/O manager
-   USE phycst          ! Define parameters for the routines
-   USE dianam          ! build the name of file (routine)
-   USE ldfslp          ! iso-neutral slopes 
-   USE zdfmxl          ! mixed layer depth
-   USE zdfddm          ! ocean vertical physics: double diffusion
-   USE ioipsl          ! NetCDF library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE diadimg         ! dimg direct access file format output
-   USE trdmld_rst      ! restart for diagnosing the ML trends
-   USE prtctl          ! Print control
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory allocation
-
-   IMPLICIT NONE
-   PRIVATE
-
-   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
-   INTEGER, ALLOCATABLE, SAVE, DIMENSION(:) ::   ndextrd1
-   INTEGER ::   ndimtrd1                        
-   INTEGER ::   ionce, icount                   
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "ldftra_substitute.h90"
-#  include "zdfddm_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION trd_mld_alloc()
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mld_alloc  ***
-      !!----------------------------------------------------------------------
-      ALLOCATE( ndextrd1(jpi*jpj) , STAT=trd_mld_alloc )
-      !
-      IF( lk_mpp             )   CALL mpp_sum ( trd_mld_alloc )
-      IF( trd_mld_alloc /= 0 )   CALL ctl_warn('trd_mld_alloc: failed to allocate array ndextrd1')
-   END FUNCTION trd_mld_alloc
-
-
-   SUBROUTINE trd_mld_zint( pttrdmld, pstrdmld, ktrd, ctype )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mld_zint  ***
-      !! 
-      !! ** 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 :
-      !!      The control surface can be either a mixed layer depth (time varying)
-      !!      or a fixed surface (jk level or bowl). 
-      !!      Choose control surface with nn_ctls in namelist NAMTRD :
-      !!        nn_ctls = 0  : use mixed layer with density criterion 
-      !!        nn_ctls = 1  : read index from file 'ctlsurf_idx'
-      !!        nn_ctls > 1  : use fixed level surface jk = nn_ctls
-      !!      Note: in the remainder of the routine, the volume between the 
-      !!            surface and the control surface is called "mixed-layer"
-      !!----------------------------------------------------------------------
-      !
-      INTEGER                         , INTENT( in ) ::   ktrd       ! ocean trend index
-      CHARACTER(len=2)                , INTENT( in ) ::   ctype      ! 2D surface/bottom or 3D interior physics
-      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
-      REAL(wp), POINTER, DIMENSION(:,:)  :: zvlmsk 
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zvlmsk ) 
-
-      ! I. Definition of control surface and associated fields
-      ! ------------------------------------------------------
-      !            ==> only once per time step <== 
-
-      IF( icount == 1 ) THEN        
-         !
-         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( nn_ctls == 0 ) THEN       ! * control surface = mixed-layer with density criterion 
-            nmld(:,:) = nmln(:,:)    ! array nmln computed in zdfmxl.F90
-         ELSE IF( nn_ctls == 1 ) THEN  ! * control surface = read index from file 
-            nmld(:,:) = nbol(:,:)
-         ELSE IF( nn_ctls >= 2 ) THEN  ! * control surface = model level
-            nn_ctls = MIN( nn_ctls, jpktrd - 1 )
-            nmld(:,:) = nn_ctls + 1
-         ENDIF
-
-         ! ... 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 
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     IF( nmld(ji,jj) <= jpktrd ) THEN
-                        zvlmsk(ji,jj) = tmask(ji,jj,1)
-                     ELSE
-                        isum = isum + 1
-                        zvlmsk(ji,jj) = 0.
-                     ENDIF
-                  END DO
-               END DO
-            ENDIF
-
-            ! Index of ocean points (2D only)
-            IF( isum > 0 ) THEN
-               WRITE(numout,*)' Number of invalid points nmld > jpktrd', isum 
-               CALL wheneq( jpi*jpj, zvlmsk(:,:) , 1, 1., ndextrd1, ndimtrd1 )    ! surface
-            ELSE 
-               CALL wheneq( jpi*jpj, tmask(:,:,1), 1, 1., ndextrd1, ndimtrd1 )    ! surface
-            ENDIF                                
-
-            ionce = 0                ! no more pass here
-            !
-         END IF
-         
-         ! ... Weights for vertical averaging
-         wkx(:,:,:) = 0.e0
-         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.e0 )   wkx(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         
-         rmld(:,:) = 0.e0                ! compute mixed-layer depth : rmld
-         DO jk = 1, jpktrd
-            rmld(:,:) = rmld(:,:) + wkx(:,:,jk)
-         END DO
-         
-         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
-            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
-      !
-      CALL wrk_dealloc( jpi, jpj, zvlmsk ) 
-      !
-   END SUBROUTINE trd_mld_zint
-    
-
-   SUBROUTINE trd_mld( kt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mld  ***
-      !! 
-      !! ** 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 nn_trd 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).
-      !!
-      !! ** Consistency check : 
-      !!        If the control surface is fixed ( nn_ctls > 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. nn_trd=5, rn_ucf=1., nn_ctls=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)
-      !!----------------------------------------------------------------------
-      !
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
-      !
-      INTEGER :: ji, jj, jk, jl, ik, it, itmod
-      LOGICAL :: lldebug = .TRUE.
-      REAL(wp) :: zavt, zfn, zfn2
-      !                                              ! z(ts)mltot : dT/dt over the anlysis window (including Asselin)
-      !                                              ! z(ts)mlres : residual = dh/dt entrainment term
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::  ztmltot , zsmltot , ztmlres , zsmlres , ztmlatf , zsmlatf
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::  ztmltot2, zsmltot2, ztmlres2, zsmlres2, ztmlatf2, zsmlatf2, ztmltrdm2, zsmltrdm2  
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztmltrd2, zsmltrd2   ! only needed for mean diagnostics
-#if defined key_dimgout
-      INTEGER ::  iyear,imon,iday
-      CHARACTER(LEN=80) :: cltext, clmode
-#endif
-      !!----------------------------------------------------------------------
-  
-      CALL wrk_alloc( jpi, jpj,         ztmltot , zsmltot , ztmlres , zsmlres , ztmlatf , zsmlatf                        )
-      CALL wrk_alloc( jpi, jpj,         ztmltot2, zsmltot2, ztmlres2, zsmlres2, ztmlatf2, zsmlatf2, ztmltrdm2, zsmltrdm2 )  
-      CALL wrk_alloc( jpi, jpj, jpltrd, ztmltrd2, zsmltrd2                                                               )
-
-      ! ======================================================================
-      ! 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 ))
-      IF( ln_traldf_iso ) THEN
-         DO jj = 1,jpj
-            DO ji = 1,jpi
-               ik = nmld(ji,jj)
-               zavt = avt(ji,jj,ik)
-               tmltrd(ji,jj,jpmld_zdf) = - zavt / fse3w(ji,jj,ik) * tmask(ji,jj,ik)  &
-                  &                      * ( tsn(ji,jj,ik-1,jp_tem) - tsn(ji,jj,ik,jp_tem) )         &
-                  &                      / MAX( 1., rmld(ji,jj) ) * tmask(ji,jj,1)
-               zavt = fsavs(ji,jj,ik)
-               smltrd(ji,jj,jpmld_zdf) = - zavt / fse3w(ji,jj,ik) * tmask(ji,jj,ik)  &
-                  &                      * ( tsn(ji,jj,ik-1,jp_sal) - tsn(ji,jj,ik,jp_sal) )         &
-                  &                      / 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)
-         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
-         !   ... 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) * tsn(:,:,jk,jp_tem)
-         sml(:,:) = sml(:,:) + wkx(:,:,jk) * tsn(:,:,jk,jp_sal)
-      END DO
-
-      ! 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
-      !                          nn_trd                           2*nn_trd       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
-
-         ! ... 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(:,:,:) * rn_ucf   ! (actually needed for 1:jpltrd-1, but trdmld(:,:,jpltrd)
-      smltrd(:,:,:) = smltrd(:,:,:) * rn_ucf   !  is no longer used, and is reset to 0. at next time step)
-      
-      ! define time axis
-      it = kt
-      itmod = kt - nit000 + 1
-
-      MODULO_NTRD : IF( MOD( itmod, nn_trd ) == 0 ) THEN        ! nitend MUST be multiple of nn_trd
-         !
-         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(:,:)   * rn_ucf/zfn  ; zsmltot (:,:)   = zsmltot(:,:)   * rn_ucf/zfn
-         ztmlres (:,:)   = ztmlres(:,:)   * rn_ucf/zfn  ; zsmlres (:,:)   = zsmlres(:,:)   * rn_ucf/zfn
-         ztmlatf (:,:)   = ztmlatf(:,:)   * rn_ucf/zfn  ; zsmlatf (:,:)   = zsmlatf(:,:)   * rn_ucf/zfn
-
-         tml_sum (:,:)   = tml_sum (:,:)  /  (2*zfn) ; sml_sum (:,:)   = sml_sum (:,:)  /  (2*zfn)
-         ztmltot2(:,:)   = ztmltot2(:,:)  * rn_ucf/zfn2 ; zsmltot2(:,:)   = zsmltot2(:,:)  * rn_ucf/zfn2
-         ztmltrd2(:,:,:) = ztmltrd2(:,:,:)* rn_ucf/zfn2 ; zsmltrd2(:,:,:) = zsmltrd2(:,:,:)* rn_ucf/zfn2
-         ztmlatf2(:,:)   = ztmlatf2(:,:)  * rn_ucf/zfn2 ; zsmlatf2(:,:)   = zsmlatf2(:,:)  * rn_ucf/zfn2
-         ztmlres2(:,:)   = ztmlres2(:,:)  * rn_ucf/zfn2 ; zsmlres2(:,:)   = zsmlres2(:,:)  * rn_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
-
-      IF( MOD( itmod, nn_trd ) == 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
-         WRITE(clmode,'(f5.1,a)') nn_trd*rdt/86400.,' days average'
-         cltext = TRIM(cexper)//' mld diags'//TRIM(clmode)
-         CALL dia_wri_dimg (clname, cltext, smltrd, jpltrd, '2')
-      END IF
-
-9000  FORMAT(a,"_",a,"_y",i4.4,"m",i2.2,"d",i2.2,".dimgproc")
-
-#else
-      
-      ! IV.2 Code for IOIPSL/NetCDF output
-      ! ----------------------------------
-
-      IF( lwp .AND. MOD( itmod , nn_trd ) == 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
-         
-      !-- 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( MOD( itmod, nn_trd ) == 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
-
-      ! ======================================================================
-      ! V. Write restart file
-      ! ======================================================================
-
-      IF( lrst_oce )   CALL trd_mld_rst_write( kt ) 
-
-      CALL wrk_dealloc( jpi, jpj,         ztmltot , zsmltot , ztmlres , zsmlres , ztmlatf , zsmlatf                        )
-      CALL wrk_dealloc( jpi, jpj,         ztmltot2, zsmltot2, ztmlres2, zsmlres2, ztmlatf2, zsmlatf2, ztmltrdm2, zsmltrdm2 )  
-      CALL wrk_dealloc( jpi, jpj, jpltrd, ztmltrd2, zsmltrd2                                                               )
-      !
-   END SUBROUTINE trd_mld
-
-
-   SUBROUTINE trd_mld_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mld_init  ***
-      !! 
-      !! ** Purpose :   computation of vertically integrated T and S budgets
-      !!      from ocean surface down to control surface (NetCDF output)
-      !!----------------------------------------------------------------------
-      INTEGER :: jl
-      INTEGER :: inum   ! logical unit
-      REAL(wp) ::   zjulian, zsto, zout
-      CHARACTER (LEN=40) ::   clop
-      CHARACTER (LEN=12) ::   clmxl, cltu, clsu
-      !!----------------------------------------------------------------------
-
-      ! ======================================================================
-      ! I. initialization
-      ! ======================================================================
-
-      IF(lwp) THEN
-         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-nit000+1, nn_trd ) /= 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, nn_trd   = ', nn_trd
-         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. ( nn_cla == 1 ) ) THEN
-         WRITE(numout,cform_war)
-         WRITE(numout,*) '                You set n_cla = 1. Note that the Mixed-Layer diagnostics  '
-         WRITE(numout,*) '                are not exact along the corresponding straits.            '
-         nwarn = nwarn + 1
-      END IF
-
-      !                                   ! allocate trdmld arrays
-      IF( trd_mld_alloc()    /= 0 )   CALL ctl_stop( 'STOP', 'trd_mld_init : unable to allocate trdmld     arrays' )
-      IF( trdmld_oce_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'trd_mld_init : unable to allocate trdmld_oce arrays' )
-
-      ! I.2 Initialize arrays to zero or read a restart file
-      ! ----------------------------------------------------
-
-      nmoymltrd = 0
-
-      !     ... 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
-
-      icount = 1   ;   ionce  = 1                            ! open specifier
-
-      ! I.3 Read control surface from file ctlsurf_idx
-      ! ----------------------------------------------
- 
-      IF( nn_ctls == 1 ) THEN
-         CALL ctl_opn( inum, 'ctlsurf_idx', 'OLD', 'UNFORMATTED', 'SEQUENTIAL', -1, numout, lwp )
-         READ ( inum ) nbol
-         CLOSE( inum )
-      END IF
-
-      ! ======================================================================
-      ! II. netCDF output initialization
-      ! ======================================================================
-
-#if defined key_dimgout 
-      ???
-#else
-      ! clmxl = legend root for netCDF output
-      IF( nn_ctls == 0 ) THEN      ! control surface = mixed-layer with density criterion
-         clmxl = 'Mixed Layer '  !                   (array nmln computed in zdfmxl.F90)
-      ELSE IF( nn_ctls == 1 ) THEN ! control surface = read index from file 
-         clmxl = '      Bowl '
-      ELSE IF( nn_ctls >= 2 ) THEN ! control surface = model level
-         WRITE(clmxl,'(A10,I2,1X)') 'Levels 1 -', nn_ctls
-      END IF
-
-      ! II.1 Define frequency of output and means
-      ! -----------------------------------------
-      IF( ln_mskland )   THEN   ;   clop = "only(x)"   ! put 1.e+20 on land (very expensive!!)
-      ELSE                      ;   clop = "x"         ! no use of the mask value (require less cpu time)
-      ENDIF
-#  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 = nn_trd * rdt
-      clop = "inst("//TRIM(clop)//")"
-#  else
-      IF( ln_trdmld_instant ) THEN
-         zsto = rdt                 ! inst. diags : we use IOIPSL time averaging
-      ELSE
-         zsto = nn_trd * rdt          ! mean  diags : we DO NOT use any IOIPSL time averaging
-      END IF
-      clop = "ave("//TRIM(clop)//")"
-#  endif
-      zout = nn_trd * rdt
-
-      IF(lwp) WRITE (numout,*) '                netCDF initialization'
-
-      ! II.2 Compute julian date from starting date of the run
-      ! ------------------------------------------------------
-      CALL ymds2ju( nyear, nmonth, nday, rdt, zjulian )
-      zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
-      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)
-      ! ------------------------------------------
-      !-- 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, nn_trd, 'trends' )
-      IF(lwp) WRITE(numout,*) ' Name of NETCDF file ', clhstnam
-      CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,                                            &
-      &             1, jpi, 1, jpj, nit000-1, zjulian, rdt, nh_t, nidtrd, domain_id=nidom, snc4chunks=snc4set )
-
-      !-- 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     ( rn_ucf == 1.       ) THEN   ;   cltu = "degC/s"     ;   clsu = "p.s.u./s"
-      ELSEIF ( rn_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, snc4set )
-
-#endif        /* key_dimgout */
-   END SUBROUTINE trd_mld_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                       Empty module
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE trd_mld( kt )             ! Empty routine
-      INTEGER, INTENT( in) ::   kt
-      WRITE(*,*) 'trd_mld: You should not have seen this print! error?', kt
-   END SUBROUTINE trd_mld
-   SUBROUTINE trd_mld_zint( pttrdmld, pstrdmld, ktrd, ctype )
-      REAL, DIMENSION(:,:,:), INTENT( in ) ::   &
-         pttrdmld, pstrdmld                   ! Temperature and Salinity trends
-      INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
-      CHARACTER(len=2), INTENT( in ) ::   &  
-         ctype                                ! surface/bottom (2D arrays) or
-         !                                    ! interior (3D arrays) physics
-      WRITE(*,*) 'trd_mld_zint: You should not have seen this print! error?', pttrdmld(1,1,1)
-      WRITE(*,*) '  "      "  : You should not have seen this print! error?', pstrdmld(1,1,1)
-      WRITE(*,*) '  "      "  : You should not have seen this print! error?', ctype
-      WRITE(*,*) '  "      "  : You should not have seen this print! error?', ktrd
-   END SUBROUTINE trd_mld_zint
-   SUBROUTINE trd_mld_init              ! Empty routine
-      WRITE(*,*) 'trd_mld_init: You should not have seen this print! error?'
-   END SUBROUTINE trd_mld_init
-#endif
-
-   !!======================================================================
-END MODULE trdmld
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld_oce.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld_oce.F90	(revision 4944)
+++ 	(revision )
@@ -1,136 +1,0 @@
-MODULE trdmld_oce
-   !!======================================================================
-   !!                   ***  MODULE trdmld_oce  ***
-   !! Ocean trends :   set tracer and momentum trend variables
-   !!======================================================================
-   !! History :  1.0  ! 2004-08  (C. Talandier)  New trends organization
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   trdmld_oce_alloc    ! Called in trdmld.F90
-
-#if defined key_trdmld
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trdmld = .TRUE.    !: ML trend flag
-#else
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trdmld = .FALSE.   !: ML trend flag
-#endif
-   !!* mixed layer trends indices
-   INTEGER, PARAMETER, PUBLIC ::   jpltrd = 11      !: number of mixed-layer trends arrays
-   INTEGER, PUBLIC            ::   jpktrd           !: 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_xxx = xx   !:  add here any additional trend (add change jpltrd)
-   INTEGER, PUBLIC, PARAMETER ::   jpmld_atf = 11   !:  asselin trend (**MUST BE THE LAST ONE**)
-
-#if   defined  key_trdmld   ||   defined key_esopa
-   !!----------------------------------------------------------------------
-   !!   'key_trdmld'                         mixed layer trends diagnostics
-   !!----------------------------------------------------------------------
-
-   !! Arrays used for diagnosing mixed-layer trends 
-   !!---------------------------------------------------------------------
-   CHARACTER(LEN=80) , PUBLIC :: clname, ctrd(jpltrd+1,2)
-
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   nmld   !: mixed layer depth indexes 
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   nbol   !: mixed-layer depth indexes when read from file
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   wkx    !:
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::  &
-      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, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  &
-      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, ALLOCATABLE, DIMENSION(:,:,:) ::  &
-      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
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-  INTEGER FUNCTION trdmld_oce_alloc()
-     !!----------------------------------------------------------------------
-     !!                 ***  FUNCTION trdmld_oce_alloc   ***
-     !!----------------------------------------------------------------------
-     USE lib_mpp
-     INTEGER :: ierr(5)
-     !!----------------------------------------------------------------------
-
-     ! Initialise jpktrd here as can no longer do it in MODULE body since
-     ! jpk is now a variable.
-     jpktrd = jpk   !: max level for mixed-layer trends diag.
-
-     ierr(:) = 0
-
-#if   defined  key_trdmld   ||   defined key_esopa
-     ALLOCATE( nmld(jpi,jpj), nbol(jpi,jpj),       &
-        &      wkx(jpi,jpj,jpk), rmld(jpi,jpj),    & 
-        &      tml(jpi,jpj)    , sml(jpi,jpj),     & 
-        &      tmlb(jpi,jpj)   , smlb(jpi,jpj) ,   &
-        &      tmlbb(jpi,jpj)  , smlbb(jpi,jpj), STAT = ierr(1) )
-
-     ALLOCATE( tmlbn(jpi,jpj)  , smlbn(jpi,jpj),   &
-        &      tmltrdm(jpi,jpj), smltrdm(jpi,jpj), &
-        &      tml_sum(jpi,jpj), tml_sumb(jpi,jpj),&
-        &      tmltrd_atf_sumb(jpi,jpj)           , STAT=ierr(2) )
-
-     ALLOCATE( sml_sum(jpi,jpj), sml_sumb(jpi,jpj), &
-        &      smltrd_atf_sumb(jpi,jpj),            &
-        &      rmld_sum(jpi,jpj), rmldbn(jpi,jpj),  &
-        &      tmlatfb(jpi,jpj), tmlatfn(jpi,jpj), STAT = ierr(3) )
-
-     ALLOCATE( smlatfb(jpi,jpj), smlatfn(jpi,jpj), & 
-        &      tmlatfm(jpi,jpj), smlatfm(jpi,jpj), &
-        &      tmltrd(jpi,jpj,jpltrd),   smltrd(jpi,jpj,jpltrd), STAT=ierr(4))
-
-     ALLOCATE( tmltrd_sum(jpi,jpj,jpltrd),tmltrd_csum_ln(jpi,jpj,jpltrd),      &
-        &      tmltrd_csum_ub(jpi,jpj,jpltrd), smltrd_sum(jpi,jpj,jpltrd),     &
-        &      smltrd_csum_ln(jpi,jpj,jpltrd), smltrd_csum_ub(jpi,jpj,jpltrd), STAT=ierr(5) )
-#endif
-      !
-      trdmld_oce_alloc = MAXVAL( ierr )
-      IF( lk_mpp                )   CALL mpp_sum ( trdmld_oce_alloc )
-      IF( trdmld_oce_alloc /= 0 )   CALL ctl_warn('trdmld_oce_alloc: failed to allocate arrays')
-      !
-   END FUNCTION trdmld_oce_alloc
-
-   !!======================================================================
-END MODULE trdmld_oce
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld_rst.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld_rst.F90	(revision 4944)
+++ 	(revision )
@@ -1,207 +1,0 @@
-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 iom             ! I/O module
-
-   IMPLICIT NONE
-   PRIVATE
-  
-   PUBLIC   trd_mld_rst_read    ! routine called by trd_mld_init
-   PUBLIC   trd_mld_rst_write   ! routine called by step.F90
-  
-   INTEGER ::   nummldw         ! logical unit for mld restart
-
-   !!---------------------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!---------------------------------------------------------------------------------
-  
-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
-      !
-      CHARACTER (len=35) :: charout
-      INTEGER ::   jk                 ! loop indice
-      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
-      CHARACTER(LEN=50)   ::   clname   ! ice output restart file name
-      !!--------------------------------------------------------------------------------
-
-      ! to get better performances with NetCDF format:
-      ! we open and define the ocean restart_mld file one time step before writing the data (-> at nitrst - 1)
-      ! except if we write ocean restart_mld files every time step or if an ocean restart_mld file was writen at nitend - 1
-      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. MOD( nitend - 1, nstock ) == 0 ) ) THEN
-         ! beware of the format used to write kt (default is i8.8, that should be large enough...)
-         IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
-         ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
-         ENDIF
-         ! create the file
-         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_trdrst_out)
-         IF(lwp) THEN
-            WRITE(numout,*)
-            SELECT CASE ( jprstlib )
-            CASE ( jprstdimg )   ;   WRITE(numout,*) '             open ocean restart_mld binary file: '//clname
-            CASE DEFAULT         ;   WRITE(numout,*) '             open ocean restart_mld NetCDF file: '//clname
-            END SELECT
-            IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt,' date= ', ndastp
-            ELSE                          ;   WRITE(numout,*) '             kt = '             , kt,' date= ', ndastp
-            ENDIF
-         ENDIF
-
-         CALL iom_open( clname, nummldw, ldwrt = .TRUE., kiolib = jprstlib )
-      ENDIF
-
-      IF( kt == nitrst .AND. lwp ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'trdmld_rst: output for ML diags. restart, with trd_mld_rst_write routine kt =', kt
-         WRITE(numout,*) '~~~~~~~~~~'
-         WRITE(numout,*)
-      ENDIF
-
-      IF( ln_trdmld_instant ) THEN 
-         !-- Temperature
-         CALL iom_rstput( kt, nitrst, nummldw, 'tmlbb'           , tmlbb           )
-         CALL iom_rstput( kt, nitrst, nummldw, 'tmlbn'           , tmlbn           )
-         CALL iom_rstput( kt, nitrst, nummldw, 'tmlatfb'         , tmlatfb         )
-
-         !-- Salinity
-         CALL iom_rstput( kt, nitrst, nummldw, 'smlbb'           , smlbb           )
-         CALL iom_rstput( kt, nitrst, nummldw, 'smlbn'           , smlbn           )
-         CALL iom_rstput( kt, nitrst, nummldw, 'smlatfb'         , smlatfb         )
-      ELSE
-         CALL iom_rstput( kt, nitrst, nummldw, 'rmldbn'          , rmldbn          )
-
-         !-- Temperature
-         CALL iom_rstput( kt, nitrst, nummldw, 'tmlbn'           , tmlbn           )
-         CALL iom_rstput( kt, nitrst, nummldw, 'tml_sumb'        , tml_sumb        )
-         DO jk = 1, jpltrd
-            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I1)") jk
-            ELSE                 ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I2)") jk
-            ENDIF
-            CALL iom_rstput( kt, nitrst, nummldw, charout,  tmltrd_csum_ub(:,:,jk) )
-         ENDDO
-         CALL iom_rstput( kt, nitrst, nummldw, 'tmltrd_atf_sumb' , tmltrd_atf_sumb )
-
-         !-- Salinity
-         CALL iom_rstput( kt, nitrst, nummldw, 'smlbn'           , smlbn           )
-         CALL iom_rstput( kt, nitrst, nummldw, 'sml_sumb'        , sml_sumb        )
-         DO jk = 1, jpltrd
-            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('smltrd_csum_ub_', I1)") jk
-            ELSE                 ;   WRITE(charout,FMT="('smltrd_csum_ub_', I2)") jk
-            ENDIF
-            CALL iom_rstput( kt, nitrst, nummldw, charout , smltrd_csum_ub(:,:,jk) )
-         ENDDO
-         CALL iom_rstput( kt, nitrst, nummldw, 'smltrd_atf_sumb' , smltrd_atf_sumb )
-      ENDIF
-      !
-      IF( kt == nitrst ) THEN
-         CALL iom_close( nummldw )     ! close the restart file (only at last time step)
-         lrst_oce = .FALSE.
-      ENDIF
-      ! 
-      !    
-   END SUBROUTINE trd_mld_rst_write
-
-
-   SUBROUTINE trd_mld_rst_read
-    !!----------------------------------------------------------------------------
-    !!                   ***  SUBROUTINE trd_mld_rst_lec  ***
-    !!                   
-    !! ** Purpose :   Read file for mixed-layer diagnostics restart.
-    !!----------------------------------------------------------------------------
-    INTEGER  ::  inum       ! temporary logical unit
-    !
-    CHARACTER (len=35) :: charout
-    INTEGER ::   jk         ! loop indice
-    INTEGER ::   jlibalt = jprstlib
-    LOGICAL ::   llok
-    !!-----------------------------------------------------------------------------
-
-    IF(lwp)  THEN
-       WRITE(numout,*)
-       WRITE(numout,*) ' trd_mld_rst_read : read the NetCDF MLD restart file'
-       WRITE(numout,*) ' ~~~~~~~~~~~~~~~~'
-    ENDIF
-    IF ( jprstlib == jprstdimg ) THEN
-       ! eventually read netcdf file (monobloc)  for restarting on different number of processors
-       ! if {cn_trdrst_in}.nc exists, then set jlibalt to jpnf90
-       INQUIRE( FILE = TRIM(cn_trdrst_in)//'.nc', EXIST = llok )
-       IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
-    ENDIF
-
-    CALL iom_open( cn_trdrst_in, inum, kiolib = jlibalt ) 
-
-    IF( ln_trdmld_instant ) THEN 
-       !-- Temperature
-       CALL iom_get( inum, jpdom_autoglo, 'tmlbb'           , tmlbb          )
-       CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn          )
-       CALL iom_get( inum, jpdom_autoglo, 'tmlatfb'         , tmlatfb        )
-
-       !-- Salinity
-       CALL iom_get( inum, jpdom_autoglo, 'smlbb'           , smlbb          )
-       CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn          )
-       CALL iom_get( inum, jpdom_autoglo, 'smlatfb'         , smlatfb        )
-    ELSE
-       CALL iom_get( inum, jpdom_autoglo, 'rmldbn'          , rmldbn         ) ! needed for rmld_sum
-
-       !-- Temperature
-       CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn          ) ! needed for tml_sum
-       CALL iom_get( inum, jpdom_autoglo, 'tml_sumb'        , tml_sumb       )
-       DO jk = 1, jpltrd
-          IF( jk < 10 )   THEN
-             WRITE(charout,FMT="('tmltrd_csum_ub_', I1)") jk
-          ELSE
-             WRITE(charout,FMT="('tmltrd_csum_ub_', I2)") jk
-          ENDIF
-          CALL iom_get( inum, jpdom_autoglo, charout, tmltrd_csum_ub(:,:,jk) )
-       ENDDO
-       CALL iom_get( inum, jpdom_autoglo, 'tmltrd_atf_sumb' , tmltrd_atf_sumb)
-
-       !-- Salinity
-       CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn          ) ! needed for sml_sum
-       CALL iom_get( inum, jpdom_autoglo, 'sml_sumb'        , sml_sumb       )
-       DO jk = 1, jpltrd
-          IF( jk < 10 )   THEN
-             WRITE(charout,FMT="('smltrd_csum_ub_', I1)") jk
-          ELSE
-             WRITE(charout,FMT="('smltrd_csum_ub_', I2)") jk
-          ENDIF
-          CALL iom_get( inum, jpdom_autoglo, charout, smltrd_csum_ub(:,:,jk) )
-       ENDDO
-       CALL iom_get( inum, jpdom_autoglo, 'smltrd_atf_sumb' , smltrd_atf_sumb)
-
-       CALL iom_close( inum )
-    ENDIF
-
-  END SUBROUTINE trd_mld_rst_read
-  
-#else
-  !!=================================================================================
-  !!                       ***  MODULE  trdmld_rst  ***
-  !! Ocean dynamic :  Input/Output files for restart on mixed-layer diagnostics
-  !!=================================================================================
-CONTAINS
-  SUBROUTINE trd_mld_rst_write( kt )           !  No ML diags ==> empty routine
-    WRITE(*,*) 'trd_mld_rst_wri: You should not have seen this print! error?', kt
-  END SUBROUTINE trd_mld_rst_write
-  SUBROUTINE trd_mld_rst_read                  !  No ML Diags ==> empty routine
-  END SUBROUTINE trd_mld_rst_read
-#endif
-
-  !!=================================================================================
-END MODULE trdmld_rst
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod.F90	(revision 4944)
+++ 	(revision )
@@ -1,290 +1,0 @@
-MODULE trdmod
-   !!======================================================================
-   !!                       ***  MODULE  trdmod  ***
-   !! Ocean diagnostics:  ocean tracers and dynamic trends
-   !!=====================================================================
-   !! History :  1.0  !  2004-08  (C. Talandier) Original code
-   !!             -   !  2005-04  (C. Deltel)    Add Asselin trend in the ML budget
-   !!            3.3  ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
-   !!----------------------------------------------------------------------
-#if  defined key_trdtra || defined key_trddyn || defined key_trdmld || defined key_trdvor || defined key_esopa
-   !!----------------------------------------------------------------------
-   !!   trd_mod          : Call the trend to be computed
-   !!   trd_mod_init     : Initialization step
-   !!----------------------------------------------------------------------
-   USE oce                     ! ocean dynamics and tracers variables
-   USE dom_oce                 ! ocean space and time domain variables
-   USE zdf_oce                 ! ocean vertical physics variables
-   USE trdmod_oce              ! ocean variables trends
-   USE ldftra_oce              ! ocean active tracers lateral physics
-   USE sbc_oce                 ! surface boundary condition: ocean
-   USE phycst                  ! physical constants
-   USE trdvor                  ! ocean vorticity trends 
-   USE trdicp                  ! ocean bassin integral constraints properties
-   USE trdmld                  ! ocean active mixed layer tracers trends 
-   USE in_out_manager          ! I/O manager
-   USE lib_mpp                 ! MPP library
-   USE wrk_nemo                ! Memory allocation
-
-
-   IMPLICIT NONE
-   PRIVATE
-
-   REAL(wp) ::   r2dt          ! time-step, = 2 rdttra except at nit000 (=rdttra) if neuler=0
-
-   PUBLIC trd_mod              ! called by all dynXX or traXX modules
-   PUBLIC trd_mod_init         ! called by opa.F90 module
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE trd_mod( ptrdx, ptrdy, ktrd, ctype, kt )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mod  ***
-      !! 
-      !! ** Purpose : Dispatch all trends computation, e.g. vorticity, mld or 
-      !!              integral constraints
-      !!----------------------------------------------------------------------
-      !
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend 
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
-      CHARACTER(len=3)          , INTENT(in   ) ::   ctype   ! momentum or tracers trends type 'DYN'/'TRA'
-      INTEGER                   , INTENT(in   ) ::   kt      ! time step
-      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
-      !!
-      INTEGER ::   ji, jj   ! dummy loop indices
-      REAL(wp), POINTER, DIMENSION(:,:)  :: ztswu, ztswv, ztbfu, ztbfv, z2dx, z2dy 
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, ztswu, ztswv, ztbfu, ztbfv, z2dx, z2dy )
-
-      z2dx(:,:) = 0._wp   ;   z2dy(:,:) = 0._wp                            ! initialization of workspace arrays
-
-      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt   ! = rdtra (restart with Euler time stepping)
-      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt   ! = 2 rdttra (leapfrog)
-      ENDIF
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! I. Integral Constraints Properties for momentum and/or tracers trends
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-      IF( ( mod(kt,nn_trd) == 0 .OR. kt == nit000 .OR. kt == nitend) )   THEN
-         !
-         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 )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_zad, ctype )   ! z- vertical adv 
-                                         CALL trd_icp( ptrdx, ptrdy, jpicpt_zad, ctype )   
-                                         ! compute the surface flux condition wn(:,:,1)*tsn(:,:,1,jp_tem)
-                                         z2dx(:,:) = wn(:,:,1)*tsn(:,:,1,jp_tem)/fse3t(:,:,1)
-                                         z2dy(:,:) = wn(:,:,1)*tsn(:,:,1,jp_sal)/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_had )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_had, ctype )   ! horizontal advection 
-            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._wp   ;   ztswv(:,:) = 0._wp
-               ztbfu(:,:) = 0._wp   ;   ztbfv(:,:) = 0._wp 
-               DO jj = 2, jpjm1   
-                  DO ji = fs_2, fs_jpim1   ! vector opt.
-                     ! save the surface forcing momentum fluxes
-                     ztswu(ji,jj) = utau(ji,jj) / ( fse3u(ji,jj,1)*rau0 )
-                     ztswv(ji,jj) = vtau(ji,jj) / ( fse3v(ji,jj,1)*rau0 )
-                     ! bottom friction contribution now handled explicitly
-                     ptrdx(ji,jj,1) = ptrdx(ji,jj,1) - ztswu(ji,jj)
-                     ptrdy(ji,jj,1) = ptrdy(ji,jj,1) - ztswv(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
-               ! bottom friction contribution now handled explicitly
-            CASE ( jpdyn_trd_bfr )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_bfr, ctype )     ! bottom friction term
-            END SELECT
-            !
-         END IF
-         !
-      END IF
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! II. Vorticity trends
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-      IF( lk_trdvor .AND. ctype == 'DYN' )   THEN
-         !
-         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_had )   ;   CALL ctl_warn('Vorticity for horizontal advection trend never checked')   
-         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) = utau(ji,jj) / ( fse3u(ji,jj,1)*rau0 )
-                  ztswv(ji,jj) = vtau(ji,jj) / ( fse3v(ji,jj,1)*rau0 )
-                  !
-                  ptrdx(ji,jj,1     ) = ptrdx(ji,jj,1     ) - ztswu(ji,jj)
-                  ptrdy(ji,jj,1     ) = ptrdy(ji,jj,1     ) - ztswv(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
-         CASE ( jpdyn_trd_bfr )
-            CALL trd_vor_zint( ptrdx, ptrdy, jpvor_bfr )                               ! Bottom friction term
-         END SELECT
-         !
-      ENDIF
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! III. Mixed layer trends for active tracers
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-      IF( lk_trdmld .AND. ctype == 'TRA' )   THEN
-         
-         !-----------------------------------------------------------------------------------------------
-         ! W.A.R.N.I.N.G :
-         ! jptra_trd_ldf : called by traldf.F90
-         !                 at this stage we store:
-         !                  - the lateral geopotential diffusion (here, lateral = horizontal)
-         !                  - and the iso-neutral diffusion if activated 
-         ! jptra_trd_zdf : called by trazdf.F90
-         !                 * in case of iso-neutral diffusion we store the vertical diffusion component in the 
-         !                   lateral trend including the K_z contrib, which will be removed later (see trd_mld)
-         !-----------------------------------------------------------------------------------------------
-
-         SELECT CASE ( ktrd )
-         CASE ( jptra_trd_xad )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_xad, '3D' )   ! 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 )   THEN
-               CALL trd_mld_zint( ptrdx, ptrdy, jpmld_ldf, '3D' )   ! vertical diffusion (K_z)
-            ELSE
-               CALL trd_mld_zint( ptrdx, ptrdy, jpmld_zdf, '3D' )   ! vertical diffusion (K_z)
-            ENDIF
-         CASE ( jptra_trd_dmp )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_dmp, '3D' )   ! internal 3D restoring (tradmp)
-         CASE ( jptra_trd_qsr )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_for, '3D' )   ! air-sea : penetrative sol radiat
-         CASE ( jptra_trd_nsr )
-            ptrdx(:,:,2:jpk) = 0.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
-      !
-      CALL wrk_dealloc( jpi, jpj, ztswu, ztswv, ztbfu, ztbfv, z2dx, z2dy )
-      !
-   END SUBROUTINE trd_mod
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default case :                                         Empty module
-   !!----------------------------------------------------------------------
-   USE trdmod_oce      ! ocean variables trends
-   USE trdvor          ! ocean vorticity trends 
-   USE trdicp          ! ocean bassin integral constraints properties
-   USE trdmld          ! ocean active mixed layer tracers trends 
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE trd_mod(ptrd3dx, ptrd3dy, ktrd , ctype, kt )   ! Empty routine
-      REAL(wp) ::   ptrd3dx(:,:,:), ptrd3dy(:,:,:)
-      INTEGER  ::   ktrd, kt                            
-      CHARACTER(len=3) ::  ctype                  
-      WRITE(*,*) 'trd_3d: You should not have seen this print! error ?', ptrd3dx(1,1,1), ptrd3dy(1,1,1)
-      WRITE(*,*) ' "   ": You should not have seen this print! error ?', ktrd, ctype, kt
-   END SUBROUTINE trd_mod
-#endif
-
-   SUBROUTINE trd_mod_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mod_init  ***
-      !! 
-      !! ** Purpose :   Initialization of activated trends
-      !!----------------------------------------------------------------------
-      USE in_out_manager          ! I/O manager
-      USE lib_mpp                 ! MPP library
-      !!    
-      NAMELIST/namtrd/ nn_trd, nn_ctls, cn_trdrst_in, cn_trdrst_out, ln_trdmld_restart, rn_ucf, ln_trdmld_instant
-      INTEGER  ::   ios           ! Local integer output status for namelist read
-      !!----------------------------------------------------------------------
-
-      IF( l_trdtra .OR. l_trddyn )   THEN
- 
-         REWIND( numnam_ref )              ! Namelist namtrd in reference namelist : Diagnostics: trends
-         READ  ( numnam_ref, namtrd, IOSTAT = ios, ERR = 901)
-901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrd in reference namelist', lwp )
-
-         REWIND( numnam_cfg )              ! Namelist namtrd in configuration namelist : Diagnostics: trends
-         READ  ( numnam_cfg, namtrd, IOSTAT = ios, ERR = 902 )
-902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrd in configuration namelist', lwp )
-         IF(lwm) WRITE ( numond, namtrd )
-
-         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   nn_trd             = ', nn_trd
-            WRITE(numout,*) '      control surface type              nn_ctls            = ', nn_ctls
-            WRITE(numout,*) '      restart for ML diagnostics        ln_trdmld_restart  = ', ln_trdmld_restart
-            WRITE(numout,*) '      instantaneous or mean ML T/S      ln_trdmld_instant  = ', ln_trdmld_instant
-            WRITE(numout,*) '      unit conversion factor            rn_ucf             = ', rn_ucf
-        ENDIF
-      ENDIF
-      !
-      IF( lk_trddyn .OR. lk_trdtra )    CALL trd_icp_init       ! integral constraints trends
-      IF( lk_trdmld                )    CALL trd_mld_init       ! mixed-layer trends (active  tracers)  
-      IF( lk_trdvor                )    CALL trd_vor_init       ! vorticity trends        
-      !
-   END SUBROUTINE trd_mod_init
-
-   !!======================================================================
-END MODULE trdmod
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod_oce.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod_oce.F90	(revision 4944)
+++ 	(revision )
@@ -1,79 +1,0 @@
-MODULE trdmod_oce
-   !!======================================================================
-   !!                   ***  MODULE trdmod_oce  ***
-   !! Ocean trends :   set tracer and momentum trend variables
-   !!======================================================================
-   !! History :  1.0  !  2004-08  (C. Talandier) Original code
-   !!----------------------------------------------------------------------
-   USE 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
-
-   IMPLICIT NONE
-   PUBLIC
-
-   !                                        !!* Namelist namtrd:  diagnostics on dynamics/tracer trends *
-   INTEGER , PUBLIC  ::   nn_trd             !: time step frequency dynamics and tracers trends
-   INTEGER , PUBLIC  ::   nn_ctls            !: control surface type for trends vertical integration
-   REAL(wp), PUBLIC  ::   rn_ucf             !: unit conversion factor (for netCDF trends outputs)
-                                             !: =1. (=86400.) for degC/s (degC/day) and psu/s (psu/day)
-   CHARACTER(len=32) ::   cn_trdrst_in       !: suffix of ocean restart name (input)
-   CHARACTER(len=32) ::   cn_trdrst_out      !: suffix of ocean restart name (output)
-   LOGICAL , PUBLIC  ::   ln_trdmld_instant  !: flag to diagnose inst./mean ML T/S trends
-   LOGICAL , PUBLIC  ::   ln_trdmld_restart  !: flag to restart mixed-layer diagnostics
-
-# if defined key_trdtra   ||   defined key_trdmld
-   LOGICAL , PUBLIC ::   l_trdtra = .TRUE.                !: tracers  trend flag
-# else
-   LOGICAL , PUBLIC ::   l_trdtra = .FALSE.               !: tracers  trend flag
-# endif
-# if defined key_trddyn   ||   defined key_trdvor
-   LOGICAL , PUBLIC ::   l_trddyn = .TRUE.                !: momentum trend flag
-# else
-   LOGICAL , PUBLIC ::   l_trddyn = .FALSE.               !: momentum trend flag
-# endif
-# if ( defined key_trdtrc && defined key_iomput )  ||  defined key_trdmld_trc
-   LOGICAL , PUBLIC ::   l_trdtrc = .TRUE.                !: tracers  trend flag
-# else
-   LOGICAL , PUBLIC ::   l_trdtrc = .FALSE.               !: tracers  trend flag
-# endif
-   !                                                     !!!* Active tracers trends indexes
-   INTEGER, PUBLIC, PARAMETER ::   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
-#if defined key_top
-   !                                                     !!!* Passive tracers trends indexes
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_sms  = 13    !: sources m. sinks
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_radn = 14    !: corr. trn<0 in trcrad
-   INTEGER, PUBLIC, PARAMETER ::   jptra_trd_radb = 15    !: corr. trb<0 in trcrad (like atf)
-#endif
-   
-   !                                                     !!!* 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_had =  6     !: horizontal advection
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_zad =  7     !: vertical advection
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_zdf =  8     !: vertical diffusion
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_spg =  9     !: surface pressure gradient
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_dat = 10     !: damping term
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_swf = 11     !: surface wind forcing
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_trd_bfr = 12     !: bottom friction 
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!======================================================================
-END MODULE trdmod_oce
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod_trc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod_trc.F90	(revision 4944)
+++ 	(revision )
@@ -1,23 +1,0 @@
-MODULE trdmod_trc
-   !!======================================================================
-   !!                       ***  MODULE trdmod_trc  ***
-   !!  Dummy module
-   !!======================================================================
-   !!----------------------------------------------------------------------
-   !!   Dummy module                                             NO TOP use
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE trd_mod_trc( ptrtrd, kjn, ktrd, kt )
-      INTEGER ::   kt, kjn, ktrd   
-      REAL    ::   ptrtrd(:,:,:)  
-      WRITE(*,*) 'trd_mod_trc_trp : You should not have seen this print! error?', ptrtrd(1,1,1)
-      WRITE(*,*) '  "      "      : You should not have seen this print! error?', kjn, ktrd, kt
-   END SUBROUTINE trd_mod_trc
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!======================================================================
-END MODULE trdmod_trc
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl.F90	(revision 4946)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl.F90	(revision 4946)
@@ -0,0 +1,899 @@
+MODULE trdmxl
+   !!======================================================================
+   !!                       ***  MODULE  trdmxl  ***
+   !! Ocean diagnostics:  mixed layer T-S trends 
+   !!======================================================================
+   !! History :  OPA  !  1995-04  (J. Vialard)    Original code
+   !!                 !  1997-02  (E. Guilyardi)  Adaptation global + base cmo
+   !!                 !  1999-09  (E. Guilyardi)  Re-writing + netCDF output
+   !!   NEMO     1.0  !  2002-06  (G. Madec)      F90: Free form and module
+   !!             -   !  2004-08  (C. Talandier)  New trends organization
+   !!            2.0  !  2005-05  (C. Deltel)     Diagnose trends of time averaged ML T & S
+   !!            3.5  !  2012-03  (G. Madec)      complete reorganisation + change in the time averaging
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   trd_mxl          : T and S cumulated trends averaged over the mixed layer
+   !!   trd_mxl_zint     : T and S trends vertical integration
+   !!   trd_mxl_init     : initialization step
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE trd_oce         ! trends: ocean variables
+   USE trdmxl_oce      ! ocean variables trends
+   USE ldftra_oce      ! ocean active tracers lateral physics
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE phycst          ! Define parameters for the routines
+   USE dianam          ! build the name of file (routine)
+   USE ldfslp          ! iso-neutral slopes 
+   USE zdfmxl          ! mixed layer depth
+   USE zdfddm          ! ocean vertical physics: double diffusion
+   USE ioipsl          ! NetCDF library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE diadimg         ! dimg direct access file format output
+   USE trdmxl_rst      ! restart for diagnosing the ML trends
+   USE prtctl          ! Print control
+   USE restart         ! for lrst_oce
+   USE lib_mpp         ! MPP library
+   USE wrk_nemo        ! Memory allocation
+   USE iom
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trd_mxl        ! routine called by step.F90
+   PUBLIC   trd_mxl_init   ! routine called by opa.F90
+   PUBLIC   trd_mxl_zint   ! routine called by tracers routines
+
+   INTEGER ::   nkstp       ! current time step 
+
+
+
+!!gm  to be moved from trdmxl_oce
+!   REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   hml                ! ML depth (sum of e3t over nmln-1 levels) [m] 
+!   REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   tml    , sml       ! now ML averaged T & S 
+!   REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   tmlb_nf, smlb_nf   ! not filtered before ML averaged T & S
+!
+!
+!   REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   hmlb, hmln         ! before, now, and after Mixed Layer depths [m]
+!   
+!   REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   tb_mlb, tb_mln     ! before (not filtered) tracer averaged over before and now ML 
+!
+!   REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   tn_mln             ! now tracer averaged over now ML
+!!gm end   
+   
+   CHARACTER (LEN=40) ::  clhstnam         ! name of the trends NetCDF file
+   INTEGER ::   nh_t, nmoymltrd
+   INTEGER ::   nidtrd
+   INTEGER, ALLOCATABLE, SAVE, DIMENSION(:) ::   ndextrd1
+   INTEGER ::   ndimtrd1                        
+   INTEGER ::   ionce, icount                   
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "ldftra_substitute.h90"
+#  include "zdfddm_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: trdmxl.F90 3318 2012-02-25 15:50:01Z gm $ 
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION trd_mxl_alloc()
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mxl_alloc  ***
+      !!----------------------------------------------------------------------
+      ALLOCATE( ndextrd1(jpi*jpj) , STAT=trd_mxl_alloc )
+      !
+      IF( lk_mpp             )   CALL mpp_sum ( trd_mxl_alloc )
+      IF( trd_mxl_alloc /= 0 )   CALL ctl_warn('trd_mxl_alloc: failed to allocate array ndextrd1')
+   END FUNCTION trd_mxl_alloc
+
+
+   SUBROUTINE trd_tra_mxl( ptrdx, ptrdy, ktrd, kt, p2dt, kmxln )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_tra_mng  ***
+      !! 
+      !! ** Purpose :   Dispatch all trends computation, e.g. 3D output, integral
+      !!                constraints, barotropic vorticity, kinetic enrgy, 
+      !!                potential energy, and/or mixed layer budget.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend 
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
+      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
+      INTEGER                   , INTENT(in   ) ::   kt      ! time step index
+      REAL(wp)                  , INTENT(in   ) ::   p2dt    ! time step  [s]
+      REAL(wp), DIMENSION(:,:)  , INTENT(in   ) ::   kmxln   ! number of t-box for the vertical average 
+      !
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      !                         !==============================!
+      IF ( kt /= nkstp ) THEN   !=  1st call at kt time step  =!
+         !                      !==============================!
+         nkstp = kt
+         
+         
+         !                          !==  reset trend arrays to zero  ==!
+         tmltrd(:,:,:) = 0._wp    ;    smltrd(:,:,:) = 0._wp    
+         
+         
+         !
+         wkx(:,:,:) = 0._wp         !==  now ML weights for vertical averaging  ==!
+         DO jk = 1, jpktrd               ! initialize wkx with vertical scale factor in mixed-layer
+            DO jj = 1,jpj
+               DO ji = 1,jpi
+                  IF( jk - kmxln(ji,jj) < 0 )   wkx(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         hmxl(:,:) = 0._wp               ! NOW mixed-layer depth
+         DO jk = 1, jpktrd
+            hmxl(:,:) = hmxl(:,:) + wkx(:,:,jk)
+         END DO
+         DO jk = 1, jpktrd               ! integration weights
+            wkx(:,:,jk) = wkx(:,:,jk) / MAX( 1.e-20_wp, hmxl(:,:) ) * tmask(:,:,1)
+         END DO
+         
+         
+         !
+         !                          !==  Vertically averaged T and S  ==!
+         tml(:,:) = 0._wp   ;   sml(:,:) = 0._wp
+         DO jk = 1, jpktrd
+            tml(:,:) = tml(:,:) + wkx(:,:,jk) * tsn(:,:,jk,jp_tem)
+            sml(:,:) = sml(:,:) + wkx(:,:,jk) * tsn(:,:,jk,jp_sal)
+         END DO
+         !
+      ENDIF
+
+
+
+      ! mean now trends over the now ML 
+      tmltrd(:,:,ktrd) = tmltrd(:,:,ktrd) + ptrdx(:,:,jk) * wkx(:,:,jk)   ! temperature
+      smltrd(:,:,ktrd) = smltrd(:,:,ktrd) + ptrdy(:,:,jk) * wkx(:,:,jk)   ! salinity
+ 
+
+ 
+!!gm to be put juste before the output !
+!      ! Lateral boundary conditions
+!      CALL lbc_lnk( tmltrd(:,:,jl), 'T', 1. )
+!      CALL lbc_lnk( smltrd(:,:,jl), 'T', 1. )
+!!gm end
+
+
+
+		SELECT CASE( ktrd )
+		CASE( jptra_npc  )               ! non-penetrative convection: regrouped with zdf
+!!gm : to be completed ! 
+!		   IF( ....
+!!gm end
+		CASE( jptra_zdfp )               ! iso-neutral diffusion: "pure" vertical diffusion
+		   !                                   ! regroup iso-neutral diffusion in one term
+         tmltrd(:,:,jpmxl_ldf) = tmltrd(:,:,jpmxl_ldf) + ( tmltrd(:,:,jpmxl_zdf) - tmltrd(:,:,jpmxl_zdfp) )
+         smltrd(:,:,jpmxl_ldf) = smltrd(:,:,jpmxl_ldf) + ( smltrd(:,:,jpmxl_zdf) - smltrd(:,:,jpmxl_zdfp) )
+         !                                   ! put in zdf the dia-neutral diffusion
+         tmltrd(:,:,jpmxl_zdf) = tmltrd(:,:,jpmxl_zdfp)
+         smltrd(:,:,jpmxl_zdf) = smltrd(:,:,jpmxl_zdfp)
+         IF( ln_zdfnpc ) THEN
+            tmltrd(:,:,jpmxl_zdf) = tmltrd(:,:,jpmxl_zdf) + tmltrd(:,:,jpmxl_npc)
+            smltrd(:,:,jpmxl_zdf) = smltrd(:,:,jpmxl_zdf) + smltrd(:,:,jpmxl_npc)
+         ENDIF
+         !
+      CASE( jptra_atf  )               ! last trends of the current time step: perform the time averaging & output
+         !
+         ! after ML           :   zhmla                      NB will be swaped to provide hmln and hmlb
+         !
+         ! entrainement ent_1 :   tb_mln - tb_mlb        ==>> use previous timestep ztn_mla = tb_mln
+         !                                                    "     "         "     tn_mln = tb_mlb  (unfiltered tb!)
+         !                                                   NB: tn_mln itself comes from the 2 time step before (ta_mla)
+         !
+         ! atf trend          :   ztbf_mln - tb_mln      ==>> use previous timestep tn_mla = tb_mln
+         !                                                   need to compute tbf_mln, using the current tb
+         !                                                   which is the before fitered tracer
+         !
+         ! entrainement ent_2 :   zta_mla - zta_mln      ==>> need to compute zta_mla and zta_mln
+         !
+         ! time averaging     :   mean: CALL trd_mean( kt, ptrd, ptrdm )
+         !                              and out put the starting mean value and the total trends
+         !                              (i.e. difference between starting and ending values)
+         !                        hat : CALL trd_hat ( kt, ptrd, ptrdm )
+         !                              and output the starting hat value and the total hat trends
+         !
+         ! swaps              :   hmlb   <==   hmln   <== zhmla
+         !                        tb_mlb <==  tn_mln  <== zta_mla
+         !                        tb_mln <== ztn_mla     ==>> now T over after h, need to be computed here 
+         !                                                    to be used at next time step (unfiltered before)
+         !
+      END SELECT
+      !
+   END SUBROUTINE trd_tra_mxl
+
+
+   SUBROUTINE trd_mean( kt, ptrd, ptrdm )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mean  ***
+      !! 
+      !! ** Purpose :   
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   ptrd    ! trend at kt
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdm   ! cumulative trends at kt
+      INTEGER                   , INTENT(in   ) ::   kt      ! time step index
+      !!----------------------------------------------------------------------
+      !
+      IF ( kt == nn_it000 )   ptrdm(:,:,:) = 0._wp
+      !
+      ptrdm(:,:,:) = ptrdm(:,:,:) + ptrd(:,:,:)
+      !
+      IF ( MOD( kt - nn_it000 + 1, nn_trd ) == 0 ) THEN
+         !
+         ! call iom put????  avec en argument le tableau de nom des trends?
+         !
+      ENDIF
+      !
+   END SUBROUTINE trd_mean
+
+
+   SUBROUTINE trd_mxl_zint( pttrdmxl, pstrdmxl, ktrd, ctype )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mxl_zint  ***
+      !! 
+      !! ** 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 :
+      !!      The control surface can be either a mixed layer depth (time varying)
+      !!      or a fixed surface (jk level or bowl). 
+      !!      Choose control surface with nn_ctls in namelist NAMTRD :
+      !!        nn_ctls = 0  : use mixed layer with density criterion 
+      !!        nn_ctls = 1  : read index from file 'ctlsurf_idx'
+      !!        nn_ctls > 1  : use fixed level surface jk = nn_ctls
+      !!      Note: in the remainder of the routine, the volume between the 
+      !!            surface and the control surface is called "mixed-layer"
+      !!----------------------------------------------------------------------
+      INTEGER                         , INTENT( in ) ::   ktrd       ! ocean trend index
+      CHARACTER(len=2)                , INTENT( in ) ::   ctype      ! 2D surface/bottom or 3D interior physics
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   pttrdmxl   ! temperature trend 
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::   pstrdmxl   ! salinity trend 
+      !
+      INTEGER ::   ji, jj, jk, isum
+      REAL(wp), POINTER, DIMENSION(:,:)  :: zvlmsk 
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, zvlmsk ) 
+
+      ! I. Definition of control surface and associated fields
+      ! ------------------------------------------------------
+      !            ==> only once per time step <== 
+
+      IF( icount == 1 ) THEN        
+         !
+         
+!!gm BUG?
+!!gm CAUTION:  double check the definition of nmln  it is the nb of w-level, not t-level I guess
+
+         
+         ! ... Set nmxl(ji,jj) = index of first T point below control surf. or outside mixed-layer
+         IF( nn_ctls == 0 ) THEN       ! * control surface = mixed-layer with density criterion 
+            nmxl(:,:) = nmln(:,:)    ! array nmln computed in zdfmxl.F90
+         ELSEIF( nn_ctls == 1 ) THEN   ! * control surface = read index from file 
+            nmxl(:,:) = nbol(:,:)
+         ELSEIF( nn_ctls >= 2 ) THEN   ! * control surface = model level
+            nn_ctls = MIN( nn_ctls, jpktrd - 1 )
+            nmxl(:,:) = nn_ctls + 1
+         ENDIF
+
+      END IF
+      !
+      CALL wrk_dealloc( jpi, jpj, zvlmsk ) 
+      !
+   END SUBROUTINE trd_mxl_zint
+    
+
+   SUBROUTINE trd_mxl( kt, p2dt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mxl  ***
+      !! 
+      !! ** 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_trdmxl_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 nn_trd 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).
+      !!
+      !! ** Consistency check : 
+      !!        If the control surface is fixed ( nn_ctls > 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. nn_trd=5, rn_ucf=1., nn_ctls=8
+      !!             for checking residuals.
+      !!             On a NEC-SX5 computer, this typically leads to:
+      !!                   O(1.e-20) temp. residuals (tml_res) when ln_trdmxl_instant=.false.
+      !!                   O(1.e-21) temp. residuals (tml_res) when ln_trdmxl_instant=.true.
+      !!
+      !! ** Action :
+      !!       At each time step, mixed-layer averaged trends are stored in the 
+      !!       tmltrd(:,:,jpmxl_xxx) array (see trdmxl_oce.F90 for definitions of jpmxl_xxx).
+      !!       This array is known when trd_mxl 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 et al.,2001, JPO.
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   ) ::   kt     ! ocean time-step index
+      REAL(wp), INTENT(in   ) ::   p2dt   ! time step  [s]
+      !
+      INTEGER :: ji, jj, jk, jl, ik, it, itmod
+      LOGICAL :: lldebug = .TRUE.
+      REAL(wp) :: zavt, zfn, zfn2
+      !                                              ! z(ts)mltot : dT/dt over the anlysis window (including Asselin)
+      !                                              ! z(ts)mlres : residual = dh/dt entrainment term
+      REAL(wp), POINTER, DIMENSION(:,:  ) ::  ztmltot , zsmltot , ztmlres , zsmlres , ztmlatf , zsmlatf
+      REAL(wp), POINTER, DIMENSION(:,:  ) ::  ztmltot2, zsmltot2, ztmlres2, zsmlres2, ztmlatf2, zsmlatf2, ztmltrdm2, zsmltrdm2  
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztmltrd2, zsmltrd2   ! only needed for mean diagnostics
+#if defined key_dimgout
+      INTEGER ::  iyear,imon,iday
+      CHARACTER(LEN=80) :: cltext, clmode
+#endif
+      !!----------------------------------------------------------------------
+  
+      CALL wrk_alloc( jpi, jpj,         ztmltot , zsmltot , ztmlres , zsmlres , ztmlatf , zsmlatf                        )
+      CALL wrk_alloc( jpi, jpj,         ztmltot2, zsmltot2, ztmlres2, zsmlres2, ztmlatf2, zsmlatf2, ztmltrdm2, zsmltrdm2 )  
+      CALL wrk_alloc( jpi, jpj, jpltrd, ztmltrd2, zsmltrd2                                                               )
+
+      ! ======================================================================
+      ! 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
+         !   ... temperature ...                    ... salinity ...
+         tmlb   (:,:) = tml   (:,:)             ;   smlb   (:,:) = sml   (:,:)
+         tmlatfn(:,:) = tmltrd(:,:,jpmxl_atf)   ;   smlatfn(:,:) = smltrd(:,:,jpmxl_atf)
+      END IF
+
+
+      ! 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
+
+         hmxlbn(:,:) = hmxl(:,:)
+
+         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_trdmxl_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=hmxlbn         , clinfo1=' hmxlbn          -  : ', 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
+      !                          nn_trd                           2*nn_trd       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
+
+         ! ... 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       (:,:)
+         hmxl_sum      (:,:)   = hmxl_sum      (:,:)   + hmxl      (:,:)   ! rmxl
+         !
+      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(:,:,:) * rn_ucf   ! (actually needed for 1:jpltrd-1, but trdmxl(:,:,jpltrd)
+      smltrd(:,:,:) = smltrd(:,:,:) * rn_ucf   !  is no longer used, and is reset to 0. at next time step)
+      
+      ! define time axis
+      it = kt
+      itmod = kt - nit000 + 1
+
+      MODULO_NTRD : IF( MOD( itmod, nn_trd ) == 0 ) THEN        ! nitend MUST be multiple of nn_trd
+         !
+         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  = REAL( nmoymltrd, wp )   ;   zfn2 = zfn * zfn
+         
+         ! III.1 Prepare fields for output ("instantaneous" diagnostics) 
+         ! -------------------------------------------------------------
+         
+         !-- Compute total trends
+         ztmltot(:,:) = ( tml(:,:) - tmlbn(:,:) + tmlb(:,:) - tmlbb(:,:) ) / p2dt
+         zsmltot(:,:) = ( sml(:,:) - smlbn(:,:) + smlb(:,:) - smlbb(:,:) ) / p2dt
+         
+         !-- 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. )
+
+
+         ! III.2 Prepare fields for output ("mean" diagnostics) 
+         ! ----------------------------------------------------
+         
+         !-- Update the ML depth time sum (to build the Leap-Frog time mean)
+         hmxl_sum(:,:) = hmxlbn(:,:) + 2 * ( hmxl_sum(:,:) - hmxl(:,:) ) + hmxl(:,:)
+
+         !-- Compute temperature total trends
+         tml_sum (:,:) = tmlbn(:,:) + 2 * ( tml_sum(:,:) - tml(:,:) ) + tml(:,:)
+         ztmltot2(:,:) = ( tml_sum(:,:) - tml_sumb(:,:) ) / p2dt    ! now in degC/s
+         
+         !-- Compute salinity total trends
+         sml_sum (:,:) = smlbn(:,:) + 2 * ( sml_sum(:,:) - sml(:,:) ) + sml(:,:)
+         zsmltot2(:,:) = ( sml_sum(:,:) - sml_sumb(:,:) ) / p2dt    ! 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(:,:,jpmxl_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(:,:,jpmxl_atf) + smltrd_atf_sumb(:,:) )
+         
+         !-- Diagnose Asselin trend over the analysis window
+         ztmlatf2(:,:) = ztmltrd2(:,:,jpmxl_atf) - tmltrd_sum(:,:,jpmxl_atf) + tmltrd_atf_sumb(:,:)
+         zsmlatf2(:,:) = zsmltrd2(:,:,jpmxl_atf) - smltrd_sum(:,:,jpmxl_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(:,:,jpmxl_atf)
+         
+         ! For S mean diagnostics 
+         smltrd_csum_ub (:,:,:) = zfn * smltrd_sum(:,:,:) - smltrd_csum_ln(:,:,:)
+         sml_sumb       (:,:)   = sml_sum(:,:)
+         smltrd_atf_sumb(:,:)   = smltrd_sum(:,:,jpmxl_atf)
+         
+         ! ML depth
+         hmxlbn         (:,:)   = hmxl    (:,:)
+         
+         IF( ln_ctl ) THEN
+            IF( ln_trdmxl_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=hmxlbn         , clinfo1=' hmxlbn          -  : ', 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(:,:)   * rn_ucf/zfn  ; zsmltot (:,:)   = zsmltot(:,:)   * rn_ucf/zfn
+         ztmlres (:,:)   = ztmlres(:,:)   * rn_ucf/zfn  ; zsmlres (:,:)   = zsmlres(:,:)   * rn_ucf/zfn
+         ztmlatf (:,:)   = ztmlatf(:,:)   * rn_ucf/zfn  ; zsmlatf (:,:)   = zsmlatf(:,:)   * rn_ucf/zfn
+
+         tml_sum (:,:)   = tml_sum (:,:)  /  (2*zfn) ; sml_sum (:,:)   = sml_sum (:,:)  /  (2*zfn)
+         ztmltot2(:,:)   = ztmltot2(:,:)  * rn_ucf/zfn2 ; zsmltot2(:,:)   = zsmltot2(:,:)  * rn_ucf/zfn2
+         ztmltrd2(:,:,:) = ztmltrd2(:,:,:)* rn_ucf/zfn2 ; zsmltrd2(:,:,:) = zsmltrd2(:,:,:)* rn_ucf/zfn2
+         ztmlatf2(:,:)   = ztmlatf2(:,:)  * rn_ucf/zfn2 ; zsmlatf2(:,:)   = zsmlatf2(:,:)  * rn_ucf/zfn2
+         ztmlres2(:,:)   = ztmlres2(:,:)  * rn_ucf/zfn2 ; zsmlres2(:,:)   = zsmlres2(:,:)  * rn_ucf/zfn2
+
+         hmxl_sum(:,:)   = hmxl_sum(:,:)  /  (2*zfn)  ! similar to tml_sum and sml_sum
+
+         ! * Debugging information *
+         IF( lldebug ) THEN
+            !
+            WRITE(numout,*)
+            WRITE(numout,*) 'trd_mxl : 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 jpmxl_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 jpmxl_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
+      ! ======================================================================
+
+      !-- Write the trends for T/S instantaneous diagnostics 
+      
+      IF( ln_trdmxl_instant ) THEN           
+
+         CALL iom_put( "mxl_depth", hmxl(:,:) )
+         
+         !................................. ( ML temperature ) ...................................
+         
+         !-- Output the fields
+         CALL iom_put( "tml"     , tml    (:,:) ) 
+         CALL iom_put( "tml_tot" , ztmltot(:,:) ) 
+         CALL iom_put( "tml_res" , ztmlres(:,:) ) 
+         
+         DO jl = 1, jpltrd - 1
+            CALL iom_put( trim("tml"//ctrd(jl,2)), tmltrd (:,:,jl) )
+         END DO
+         
+         CALL iom_put( trim("tml"//ctrd(jpmxl_atf,2)), ztmlatf(:,:) )
+         
+         !.................................. ( ML salinity ) .....................................
+         
+         !-- Output the fields
+         CALL iom_put( "sml"    , sml    (:,:) )
+         CALL iom_put( "sml_tot", zsmltot(:,:) ) 
+         CALL iom_put( "sml_res", zsmlres(:,:) ) 
+         
+         DO jl = 1, jpltrd - 1
+            CALL iom_put( trim("sml"//ctrd(jl,2)), smltrd(:,:,jl) )
+         END DO
+         
+         CALL iom_put( trim("sml"//ctrd(jpmxl_atf,2)), zsmlatf(:,:) )
+
+
+         
+      ELSE      !-- Write the trends for T/S mean diagnostics 
+
+         CALL iom_put( "mxl_depth", hmxl_sum(:,:) )
+         
+         !................................. ( ML temperature ) ...................................
+         
+         !-- Output the fields
+         CALL iom_put( "tml"     , tml_sum (:,:) ) 
+         CALL iom_put( "tml_tot" , ztmltot2(:,:) ) 
+         CALL iom_put( "tml_res" , ztmlres2(:,:) ) 
+
+         DO jl = 1, jpltrd - 1
+            CALL iom_put( trim("tml"//ctrd(jl,2)), ztmltrd2(:,:,jl) )
+         END DO
+         
+         CALL iom_put( trim("tml"//ctrd(jpmxl_atf,2)), ztmlatf2(:,:) )
+         
+         !.................................. ( ML salinity ) .....................................
+                     
+         !-- Output the fields
+         CALL iom_put( "sml"    , sml_sum (:,:) )
+         CALL iom_put( "sml_tot", zsmltot2(:,:) ) 
+         CALL iom_put( "sml_res", zsmlres2(:,:) ) 
+
+         DO jl = 1, jpltrd - 1
+            CALL iom_put( trim("sml"//ctrd(jl,2)), zsmltrd2(:,:,jl) )
+         END DO
+         
+         CALL iom_put( trim("sml"//ctrd(jpmxl_atf,2)), zsmlatf2(:,:) )
+         !
+      END IF
+      !
+
+      IF( MOD( itmod, nn_trd ) == 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
+
+         hmxl_sum       (:,:)   = 0.e0
+         !
+      END IF
+
+      ! ======================================================================
+      ! V. Write restart file
+      ! ======================================================================
+
+      IF( lrst_oce )   CALL trd_mxl_rst_write( kt ) 
+
+      CALL wrk_dealloc( jpi, jpj,         ztmltot , zsmltot , ztmlres , zsmlres , ztmlatf , zsmlatf                        )
+      CALL wrk_dealloc( jpi, jpj,         ztmltot2, zsmltot2, ztmlres2, zsmlres2, ztmlatf2, zsmlatf2, ztmltrdm2, zsmltrdm2 )  
+      CALL wrk_dealloc( jpi, jpj, jpltrd, ztmltrd2, zsmltrd2                                                               )
+      !
+   END SUBROUTINE trd_mxl
+
+
+   SUBROUTINE trd_mxl_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mxl_init  ***
+      !! 
+      !! ** Purpose :   computation of vertically integrated T and S budgets
+      !!      from ocean surface down to control surface (NetCDF output)
+      !!----------------------------------------------------------------------
+      INTEGER  ::   jl     ! dummy loop indices
+      INTEGER  ::   inum   ! logical unit
+      INTEGER  ::   ios    ! local integer
+      REAL(wp) ::   zjulian, zsto, zout
+      CHARACTER (LEN=40) ::   clop
+      CHARACTER (LEN=12) ::   clmxl, cltu, clsu
+      !!
+      NAMELIST/namtrd_mxl/ nn_trd , cn_trdrst_in , ln_trdmxl_restart,       &
+         &                 nn_ctls, cn_trdrst_out, ln_trdmxl_instant, rn_ucf, rn_rho_c
+      !!----------------------------------------------------------------------
+      !
+      REWIND( numnam_ref )              ! Namelist namtrd_mxl in reference namelist : mixed layer trends diagnostic
+      READ  ( numnam_ref, namtrd_mxl, IOSTAT = ios, ERR = 901 )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrd_mxl in reference namelist', lwp )
+
+      REWIND( numnam_cfg )              ! Namelist namtrd_mxl in configuration namelist : mixed layer trends diagnostic
+      READ  ( numnam_cfg, namtrd_mxl, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrd_mxl in configuration namelist', lwp )
+      WRITE( numond, namtrd_mxl )
+      !
+      IF(lwp) THEN                      ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) ' trd_mxl_init : Mixed-layer trends'
+         WRITE(numout,*) ' ~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namtrd : set trends parameters'
+         WRITE(numout,*) '      frequency of trends diagnostics (glo)      nn_trd             = ', nn_trd
+         WRITE(numout,*) '      density criteria used to defined the MLD   rn_rho_c           = ', rn_rho_c
+         WRITE(numout,*) '      control surface type            (mld)      nn_ctls            = ', nn_ctls
+         WRITE(numout,*) '      restart for ML diagnostics                 ln_trdmxl_restart  = ', ln_trdmxl_restart
+         WRITE(numout,*) '      instantaneous or mean ML T/S               ln_trdmxl_instant  = ', ln_trdmxl_instant
+         WRITE(numout,*) '      unit conversion factor                     rn_ucf             = ', rn_ucf
+         WRITE(numout,*) '      criteria to compute the MLD                rn_rho_c           = ', rn_rho_c
+      ENDIF
+
+
+
+      ! I.1 Check consistency of user defined preferences
+      ! -------------------------------------------------
+      
+      IF ( rn_rho_c /= rho_c )   CALL ctl_warn( 'Unless you have good reason to do so, you should use the value ',    &
+         &                                      'defined in zdfmxl.F90 module to calculate the mixed layer depth' )
+
+      IF( MOD( nitend, nn_trd ) /= 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, nn_trd   = ', nn_trd
+         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 nn_fsbc parameter '
+         nstop = nstop + 1
+      END IF
+
+      IF( nn_cla == 1 )   CALL ctl_warn( '      You set n_cla = 1. Note that the Mixed-Layer diagnostics  ',   &
+         &                               '      are not exact along the corresponding straits.            ')
+
+      !                                   ! allocate trdmxl arrays
+      IF( trd_mxl_alloc()    /= 0 )   CALL ctl_stop( 'STOP', 'trd_mxl_init : unable to allocate trdmxl     arrays' )
+      IF( trdmxl_oce_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'trd_mxl_init : unable to allocate trdmxl_oce arrays' )
+
+
+
+
+   	nkstp     = nit000 - 1              ! current time step indicator initialization
+
+
+
+
+      ! I.2 Initialize arrays to zero or read a restart file
+      ! ----------------------------------------------------
+
+      nmoymltrd = 0
+
+      !     ... 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
+
+      hmxl           (:,:)   = 0.e0            
+      hmxl_sum       (:,:)   = 0.e0
+
+      IF( ln_rstart .AND. ln_trdmxl_restart ) THEN
+         CALL trd_mxl_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
+
+      icount = 1   ;   ionce  = 1                            ! open specifier
+
+      ! I.3 Read control surface from file ctlsurf_idx
+      ! ----------------------------------------------
+ 
+      IF( nn_ctls == 1 ) THEN
+         CALL ctl_opn( inum, 'ctlsurf_idx', 'OLD', 'UNFORMATTED', 'SEQUENTIAL', -1, numout, lwp )
+         READ ( inum ) nbol
+         CLOSE( inum )
+      END IF
+
+      ! ======================================================================
+      ! II. netCDF output initialization
+      ! ======================================================================
+
+      ! clmxl = legend root for netCDF output
+      IF( nn_ctls == 0 ) THEN      ! control surface = mixed-layer with density criterion
+         clmxl = 'Mixed Layer '  !                   (array nmln computed in zdfmxl.F90)
+      ELSE IF( nn_ctls == 1 ) THEN ! control surface = read index from file 
+         clmxl = '      Bowl '
+      ELSE IF( nn_ctls >= 2 ) THEN ! control surface = model level
+         WRITE(clmxl,'(A10,I2,1X)') 'Levels 1 -', nn_ctls
+      END IF
+
+
+
+      ! II.3 Define the T grid trend file (nidtrd)
+      ! ------------------------------------------
+      !-- Define long and short names for the NetCDF output variables
+      !       ==> choose them according to trdmxl_oce.F90 <==
+
+      ctrd(jpmxl_xad,1) = " Zonal advection"                  ;   ctrd(jpmxl_xad,2) = "_xad"
+      ctrd(jpmxl_yad,1) = " Meridional advection"             ;   ctrd(jpmxl_yad,2) = "_yad"
+      ctrd(jpmxl_zad,1) = " Vertical advection"               ;   ctrd(jpmxl_zad,2) = "_zad"
+      ctrd(jpmxl_ldf,1) = " Lateral diffusion"                ;   ctrd(jpmxl_ldf,2) = "_ldf"
+      ctrd(jpmxl_for,1) = " Forcing"                          ;   ctrd(jpmxl_for,2) = "_for"
+      ctrd(jpmxl_zdf,1) = " Vertical diff. (Kz)"              ;   ctrd(jpmxl_zdf,2) = "_zdf"
+      ctrd(jpmxl_bbc,1) = " Geothermal flux"                  ;   ctrd(jpmxl_bbc,2) = "_bbc"
+      ctrd(jpmxl_bbl,1) = " Adv/diff. Bottom boundary layer"  ;   ctrd(jpmxl_bbl,2) = "_bbl"
+      ctrd(jpmxl_dmp,1) = " Tracer damping"                   ;   ctrd(jpmxl_dmp,2) = "_dmp"
+      ctrd(jpmxl_npc,1) = " Non penetrative convec. adjust."  ;   ctrd(jpmxl_npc,2) = "_npc"
+      ctrd(jpmxl_atf,1) = " Asselin time filter"              ;   ctrd(jpmxl_atf,2) = "_atf"
+                                                                  
+
+      !-- Define physical units
+      IF     ( rn_ucf == 1.       ) THEN   ;   cltu = "degC/s"     ;   clsu = "p.s.u./s"
+      ELSEIF ( rn_ucf == 3600.*24.) THEN   ;   cltu = "degC/day"   ;   clsu = "p.s.u./day"
+      ELSE                                 ;   cltu = "unknown?"   ;   clsu = "unknown?"
+      END IF
+      !
+   END SUBROUTINE trd_mxl_init
+
+   !!======================================================================
+END MODULE trdmxl
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl_oce.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl_oce.F90	(revision 4946)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl_oce.F90	(revision 4946)
@@ -0,0 +1,135 @@
+MODULE trdmxl_oce
+   !!======================================================================
+   !!                   ***  MODULE trdmxl_oce  ***
+   !! Ocean trends :   set tracer and momentum trend variables
+   !!======================================================================
+   !! History :  1.0  ! 2004-08  (C. Talandier)  New trends organization
+   !!            3.5  ! 2012-02  (G. Madec) suppress the trend keys + new trdmxl formulation
+   !!----------------------------------------------------------------------
+   USE par_oce        ! ocean parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trdmxl_oce_alloc    ! Called in trdmxl.F90
+
+   !                                                !* mixed layer trend indices
+   INTEGER, PUBLIC, PARAMETER ::   jpltrd = 11      !: number of mixed-layer trends arrays
+   INTEGER, PUBLIC            ::   jpktrd           !: max level for mixed-layer trends diag.
+   !
+   INTEGER, PUBLIC, PARAMETER ::   jpmxl_xad =  1   !: i-componant of advection   
+   INTEGER, PUBLIC, PARAMETER ::   jpmxl_yad =  2   !: j-componant of advection
+   INTEGER, PUBLIC, PARAMETER ::   jpmxl_zad =  3   !: k-component of advection 
+   INTEGER, PUBLIC, PARAMETER ::   jpmxl_ldf =  4   !: lateral diffusion (geopot. or iso-neutral)
+   INTEGER, PUBLIC, PARAMETER ::   jpmxl_zdf =  5   !: vertical diffusion  
+   INTEGER, PUBLIC, PARAMETER ::   jpmxl_npc =  6   !: non penetrative convective adjustment
+   INTEGER, PUBLIC, PARAMETER ::   jpmxl_bbc =  7   !: geothermal flux
+   INTEGER, PUBLIC, PARAMETER ::   jpmxl_bbl =  8   !: bottom boundary layer (advective/diffusive)
+   INTEGER, PUBLIC, PARAMETER ::   jpmxl_for =  9   !: forcing 
+   INTEGER, PUBLIC, PARAMETER ::   jpmxl_dmp = 10   !: internal restoring trend
+   INTEGER, PUBLIC, PARAMETER ::   jpmxl_zdfp = 11   !: asselin trend (**MUST BE THE LAST ONE**)
+   INTEGER, PUBLIC, PARAMETER ::   jpmxl_atf  = 12   !: asselin trend (**MUST BE THE LAST ONE**)
+   !                                                            !!* Namelist namtrd_mxl:  trend diagnostics in the mixed layer *
+   INTEGER           , PUBLIC ::   nn_ctls  = 0                  !: control surface type for trends vertical integration
+   REAL(wp)          , PUBLIC ::   rn_rho_c = 0.01               !: density criteria for MLD definition
+   REAL(wp)          , PUBLIC ::   rn_ucf   = 1.                 !: unit conversion factor (for netCDF trends outputs)
+                                                                 !  =1. (=86400.) for degC/s (degC/day) and psu/s (psu/day)
+   CHARACTER(len=32), PUBLIC ::   cn_trdrst_in  = "restart_mxl"  !: suffix of ocean restart name (input)
+   CHARACTER(len=32), PUBLIC ::   cn_trdrst_out = "restart_mxl"  !: suffix of ocean restart name (output)
+   LOGICAL          , PUBLIC ::   ln_trdmxl_instant = .FALSE.    !: flag to diagnose inst./mean ML T/S trends
+   LOGICAL          , PUBLIC ::   ln_trdmxl_restart = .FALSE.    !: flag to restart mixed-layer diagnostics
+
+
+   !! Arrays used for diagnosing mixed-layer trends 
+   !!---------------------------------------------------------------------
+   CHARACTER(LEN=80) , PUBLIC :: clname, ctrd(jpltrd+1,2)
+
+   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   nmxl   !: mixed layer depth indexes 
+   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   nbol   !: mixed-layer depth indexes when read from file
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   wkx    !:
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::  &
+      hmxl   ,                      & !: mixed layer 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,              & !: 
+      hmxl_sum, hmxlbn                !: needed to compute the leap-frog time mean of the ML depth
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  &
+      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, ALLOCATABLE, DIMENSION(:,:,:) ::  &
+      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                  !: 
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! $Id: $ 
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+  INTEGER FUNCTION trdmxl_oce_alloc()
+     !!----------------------------------------------------------------------
+     !!                 ***  FUNCTION trdmxl_oce_alloc   ***
+     !!----------------------------------------------------------------------
+     USE lib_mpp
+     INTEGER :: ierr(5)
+     !!----------------------------------------------------------------------
+
+     ! Initialise jpktrd here as can no longer do it in MODULE body since
+     ! jpk is now a variable.
+     jpktrd = jpk   !: max level for mixed-layer trends diag.
+
+     ierr(:) = 0
+
+     ALLOCATE( nmxl (jpi,jpj)    , nbol (jpi,jpj),    &
+        &      wkx  (jpi,jpj,jpk), hmxl (jpi,jpj),    & 
+        &      tml  (jpi,jpj)    , sml  (jpi,jpj),    & 
+        &      tmlb (jpi,jpj)    , smlb (jpi,jpj),    &
+        &      tmlbb(jpi,jpj)    , smlbb(jpi,jpj), STAT = ierr(1) )
+
+     ALLOCATE( tmlbn(jpi,jpj)  , smlbn(jpi,jpj),   &
+        &      tmltrdm(jpi,jpj), smltrdm(jpi,jpj), &
+        &      tml_sum(jpi,jpj), tml_sumb(jpi,jpj),&
+        &      tmltrd_atf_sumb(jpi,jpj)           , STAT=ierr(2) )
+
+     ALLOCATE( sml_sum(jpi,jpj), sml_sumb(jpi,jpj), &
+        &      smltrd_atf_sumb(jpi,jpj),            &
+        &      hmxl_sum(jpi,jpj), hmxlbn(jpi,jpj),  &
+        &      tmlatfb(jpi,jpj), tmlatfn(jpi,jpj), STAT = ierr(3) )
+
+     ALLOCATE( smlatfb(jpi,jpj), smlatfn(jpi,jpj), & 
+        &      tmlatfm(jpi,jpj), smlatfm(jpi,jpj), &
+        &      tmltrd(jpi,jpj,jpltrd),   smltrd(jpi,jpj,jpltrd), STAT=ierr(4))
+
+     ALLOCATE( tmltrd_sum(jpi,jpj,jpltrd),tmltrd_csum_ln(jpi,jpj,jpltrd),      &
+        &      tmltrd_csum_ub(jpi,jpj,jpltrd), smltrd_sum(jpi,jpj,jpltrd),     &
+        &      smltrd_csum_ln(jpi,jpj,jpltrd), smltrd_csum_ub(jpi,jpj,jpltrd), STAT=ierr(5) )
+      !
+      trdmxl_oce_alloc = MAXVAL( ierr )
+      IF( lk_mpp                )   CALL mpp_sum ( trdmxl_oce_alloc )
+      IF( trdmxl_oce_alloc /= 0 )   CALL ctl_warn('trdmxl_oce_alloc: failed to allocate arrays')
+      !
+   END FUNCTION trdmxl_oce_alloc
+
+   !!======================================================================
+END MODULE trdmxl_oce
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl_rst.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl_rst.F90	(revision 4946)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl_rst.F90	(revision 4946)
@@ -0,0 +1,194 @@
+MODULE trdmxl_rst
+   !!=================================================================================
+   !!                       ***  MODULE  trdmxl_rst  ***
+   !! Ocean dynamic :  Input/Output files for restart on mixed-layer diagnostics
+   !!=================================================================================
+   !! History :  1.0  ! 2005-05 (C. Deltel)  Original code
+   !!---------------------------------------------------------------------------------
+
+   !!---------------------------------------------------------------------------------
+   !!  trd_mxl_rst_write : write mixed layer trend restart
+   !!  trd_mxl_rst_read  : read  mixed layer trend restart
+   !!---------------------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE trd_oce         ! trends: ocean variables
+   USE in_out_manager  ! I/O manager
+   USE iom             ! I/O module
+   USE restart         ! only for lrst_oce
+
+   IMPLICIT NONE
+   PRIVATE
+  
+   PUBLIC   trd_mxl_rst_read    ! routine called by trd_mxl_init
+   PUBLIC   trd_mxl_rst_write   ! routine called by step.F90
+  
+   INTEGER ::   nummxlw         ! logical unit for mxl restart
+
+   !!---------------------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: $ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!---------------------------------------------------------------------------------
+CONTAINS
+  
+   SUBROUTINE trd_mxl_rst_write( kt )
+      !!--------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE trd_mxl_rst_wri  ***
+      !!                
+      !! ** Purpose :   Write mixed-layer diagnostics restart fields.
+      !!--------------------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !
+      CHARACTER (len=35) :: charout
+      INTEGER ::   jk                 ! loop indice
+      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
+      CHARACTER(LEN=50)   ::   clname   ! ice output restart file name
+      !!--------------------------------------------------------------------------------
+
+      ! to get better performances with NetCDF format:
+      ! we open and define the ocean restart_mxl file one time step before writing the data (-> at nitrst - 1)
+      ! except if we write ocean restart_mxl files every time step or if an ocean restart_mxl file was writen at nitend - 1
+      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. MOD( nitend - 1, nstock ) == 0 ) ) THEN
+         ! beware of the format used to write kt (default is i8.8, that should be large enough...)
+         IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
+         ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
+         ENDIF
+         ! create the file
+         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_trdrst_out)
+         IF(lwp) THEN
+            WRITE(numout,*)
+            SELECT CASE ( jprstlib )
+            CASE ( jprstdimg )   ;   WRITE(numout,*) '             open ocean restart_mxl binary file: '//clname
+            CASE DEFAULT         ;   WRITE(numout,*) '             open ocean restart_mxl NetCDF file: '//clname
+            END SELECT
+            IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt,' date= ', ndastp
+            ELSE                          ;   WRITE(numout,*) '             kt = '             , kt,' date= ', ndastp
+            ENDIF
+         ENDIF
+
+         CALL iom_open( clname, nummxlw, ldwrt = .TRUE., kiolib = jprstlib )
+      ENDIF
+
+      IF( kt == nitrst .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trdmxl_rst: output for ML diags. restart, with trd_mxl_rst_write routine kt =', kt
+         WRITE(numout,*) '~~~~~~~~~~'
+         WRITE(numout,*)
+      ENDIF
+
+      IF( ln_trdmxl_instant ) THEN 
+         !-- Temperature
+         CALL iom_rstput( kt, nitrst, nummxlw, 'tmlbb'           , tmlbb           )
+         CALL iom_rstput( kt, nitrst, nummxlw, 'tmlbn'           , tmlbn           )
+         CALL iom_rstput( kt, nitrst, nummxlw, 'tmlatfb'         , tmlatfb         )
+
+         !-- Salinity
+         CALL iom_rstput( kt, nitrst, nummxlw, 'smlbb'           , smlbb           )
+         CALL iom_rstput( kt, nitrst, nummxlw, 'smlbn'           , smlbn           )
+         CALL iom_rstput( kt, nitrst, nummxlw, 'smlatfb'         , smlatfb         )
+      ELSE
+         CALL iom_rstput( kt, nitrst, nummxlw, 'hmxlbn'          , hmxlbn          )
+
+         !-- Temperature
+         CALL iom_rstput( kt, nitrst, nummxlw, 'tmlbn'           , tmlbn           )
+         CALL iom_rstput( kt, nitrst, nummxlw, 'tml_sumb'        , tml_sumb        )
+         DO jk = 1, jpltrd
+            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I1)")   jk
+            ELSE                 ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I2)")   jk
+            ENDIF
+            CALL iom_rstput( kt, nitrst, nummxlw, charout,  tmltrd_csum_ub(:,:,jk) )
+         ENDDO
+         CALL iom_rstput( kt, nitrst, nummxlw, 'tmltrd_atf_sumb' , tmltrd_atf_sumb )
+
+         !-- Salinity
+         CALL iom_rstput( kt, nitrst, nummxlw, 'smlbn'           , smlbn           )
+         CALL iom_rstput( kt, nitrst, nummxlw, 'sml_sumb'        , sml_sumb        )
+         DO jk = 1, jpltrd
+            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('smltrd_csum_ub_', I1)")   jk
+            ELSE                 ;   WRITE(charout,FMT="('smltrd_csum_ub_', I2)")   jk
+            ENDIF
+            CALL iom_rstput( kt, nitrst, nummxlw, charout , smltrd_csum_ub(:,:,jk) )
+         ENDDO
+         CALL iom_rstput( kt, nitrst, nummxlw, 'smltrd_atf_sumb' , smltrd_atf_sumb )
+      ENDIF
+      !
+      IF( kt == nitrst ) THEN
+         CALL iom_close( nummxlw )     ! close the restart file (only at last time step)
+         lrst_oce = .FALSE.
+      ENDIF
+      ! 
+   END SUBROUTINE trd_mxl_rst_write
+
+
+   SUBROUTINE trd_mxl_rst_read
+      !!----------------------------------------------------------------------------
+      !!                   ***  SUBROUTINE trd_mxl_rst_lec  ***
+      !!                   
+      !! ** Purpose :   Read file for mixed-layer diagnostics restart.
+      !!----------------------------------------------------------------------------
+      INTEGER  ::  inum       ! temporary logical unit
+      !
+      CHARACTER (len=35) :: charout
+      INTEGER ::   jk         ! loop indice
+      INTEGER ::   jlibalt = jprstlib
+      LOGICAL ::   llok
+      !!-----------------------------------------------------------------------------
+
+      IF(lwp)  THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' trd_mxl_rst_read : read the NetCDF mixed layer trend restart file'
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~'
+      ENDIF
+      IF ( jprstlib == jprstdimg ) THEN
+         ! eventually read netcdf file (monobloc)  for restarting on different number of processors
+         ! if {cn_trdrst_in}.nc exists, then set jlibalt to jpnf90
+         INQUIRE( FILE = TRIM(cn_trdrst_in)//'.nc', EXIST = llok )
+         IF ( llok ) THEN   ;   jlibalt = jpnf90   
+         ELSE               ;   jlibalt = jprstlib   
+         ENDIF
+      ENDIF
+
+      CALL iom_open( cn_trdrst_in, inum, kiolib = jlibalt ) 
+
+      IF( ln_trdmxl_instant ) THEN 
+         !-- Temperature
+         CALL iom_get( inum, jpdom_autoglo, 'tmlbb'           , tmlbb          )
+         CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn          )
+         CALL iom_get( inum, jpdom_autoglo, 'tmlatfb'         , tmlatfb        )
+         !
+         !-- Salinity
+         CALL iom_get( inum, jpdom_autoglo, 'smlbb'           , smlbb          )
+         CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn          )
+         CALL iom_get( inum, jpdom_autoglo, 'smlatfb'         , smlatfb        )
+      ELSE
+         CALL iom_get( inum, jpdom_autoglo, 'hmxlbn'          , hmxlbn         ) ! needed for hmxl_sum
+         !
+         !-- Temperature
+         CALL iom_get( inum, jpdom_autoglo, 'tmlbn'           , tmlbn          ) ! needed for tml_sum
+         CALL iom_get( inum, jpdom_autoglo, 'tml_sumb'        , tml_sumb       )
+         DO jk = 1, jpltrd
+            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I1)")   jk
+            ELSE                 ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I2)")   jk
+            ENDIF
+            CALL iom_get( inum, jpdom_autoglo, charout, tmltrd_csum_ub(:,:,jk) )
+         END DO
+         CALL iom_get( inum, jpdom_autoglo, 'tmltrd_atf_sumb' , tmltrd_atf_sumb)
+         !
+         !-- Salinity
+         CALL iom_get( inum, jpdom_autoglo, 'smlbn'           , smlbn          ) ! needed for sml_sum
+         CALL iom_get( inum, jpdom_autoglo, 'sml_sumb'        , sml_sumb       )
+         DO jk = 1, jpltrd
+            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('smltrd_csum_ub_', I1)")   jk
+            ELSE                 ;   WRITE(charout,FMT="('smltrd_csum_ub_', I2)")   jk
+            ENDIF
+            CALL iom_get( inum, jpdom_autoglo, charout, smltrd_csum_ub(:,:,jk) )
+         END DO
+         CALL iom_get( inum, jpdom_autoglo, 'smltrd_atf_sumb' , smltrd_atf_sumb)
+         !
+         CALL iom_close( inum )
+      ENDIF
+      !
+   END SUBROUTINE trd_mxl_rst_read
+  
+  !!=================================================================================
+END MODULE trdmxl_rst
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdpen.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdpen.F90	(revision 4946)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdpen.F90	(revision 4946)
@@ -0,0 +1,159 @@
+MODULE trdpen
+   !!======================================================================
+   !!                       ***  MODULE  trdpen  ***
+   !! Ocean diagnostics:  Potential Energy trends
+   !!=====================================================================
+   !! History :  3.5  !  2012-02  (G. Madec) original code 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   trd_pen       : compute and output Potential Energy trends from T & S trends
+   !!   trd_pen_init  : initialisation of PE trends
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean domain 
+   USE sbc_oce        ! surface boundary condition: ocean
+   USE zdf_oce        ! ocean vertical physics
+   USE trd_oce        ! trends: ocean variables
+   USE eosbn2         ! equation of state and related derivatives
+   USE ldftra_oce     ! ocean active tracers lateral physics
+   USE zdfddm         ! vertical physics: double diffusion
+   USE phycst         ! physical constants
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory allocation
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trd_pen        ! called by all trdtra module
+   PUBLIC   trd_pen_init   ! called by all nemogcm module
+
+   INTEGER ::   nkstp   ! current time step 
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   rab_pe   ! partial derivatives of PE anomaly with respect to T and S
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "zdfddm_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: trdtra.F90 3318 2012-02-25 15:50:01Z gm $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION trd_pen_alloc()
+      !!---------------------------------------------------------------------
+      !!                  ***  FUNCTION trd_tra_alloc  ***
+      !!---------------------------------------------------------------------
+      ALLOCATE( rab_pe(jpi,jpj,jpk,jpts) , STAT= trd_pen_alloc )
+      !
+      IF( lk_mpp             )   CALL mpp_sum ( trd_pen_alloc )
+      IF( trd_pen_alloc /= 0 )   CALL ctl_warn( 'trd_pen_alloc: failed to allocate arrays' )
+   END FUNCTION trd_pen_alloc
+
+
+   SUBROUTINE trd_pen( ptrdx, ptrdy, ktrd, kt, pdt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_tra_mng  ***
+      !! 
+      !! ** Purpose :   Dispatch all trends computation, e.g. 3D output, integral
+      !!                constraints, barotropic vorticity, kinetic enrgy, 
+      !!                potential energy, and/or mixed layer budget.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(in) ::   ptrdx, ptrdy   ! Temperature & Salinity trends
+      INTEGER                   , INTENT(in) ::   ktrd           ! tracer trend index
+      INTEGER                   , INTENT(in) ::   kt             ! time step index
+      REAL(wp)                  , INTENT(in) ::   pdt            ! time step [s]
+      !
+      INTEGER ::   jk                                            ! dummy loop indices
+      REAL(wp), POINTER, DIMENSION(:,:)      ::   z2d            ! 2D workspace 
+      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   zpe            ! 3D workspace 
+      !!----------------------------------------------------------------------
+      !
+      CALL wrk_alloc( jpi, jpj, jpk, zpe )
+      zpe(:,:,:) = 0._wp
+      !
+      IF ( kt /= nkstp ) THEN   ! full eos: set partial derivatives at the 1st call of kt time step
+         nkstp = kt
+         CALL eos_pen( tsn, rab_PE, zpe )
+         CALL iom_put( "alphaPE", rab_pe(:,:,:,jp_tem) )
+         CALL iom_put( "betaPE" , rab_pe(:,:,:,jp_sal) )
+         CALL iom_put( "PEanom" , zpe )
+      ENDIF
+      !
+      zpe(:,:,jpk) = 0._wp
+      DO jk = 1, jpkm1
+         zpe(:,:,jk) = ( - ( rab_n(:,:,jk,jp_tem) + rab_pe(:,:,jk,jp_tem) ) * ptrdx(:,:,jk)   &
+            &            + ( rab_n(:,:,jk,jp_sal) + rab_pe(:,:,jk,jp_sal) ) * ptrdy(:,:,jk)  )
+      END DO
+
+      SELECT CASE ( ktrd )
+      CASE ( jptra_xad  )   ;   CALL iom_put( "petrd_xad", zpe )   ! zonal    advection
+      CASE ( jptra_yad  )   ;   CALL iom_put( "petrd_yad", zpe )   ! merid.   advection
+      CASE ( jptra_zad  )   ;   CALL iom_put( "petrd_zad", zpe )   ! vertical advection
+                                IF( .NOT.lk_vvl ) THEN                   ! cst volume : adv flux through z=0 surface
+                                   CALL wrk_alloc( jpi, jpj, z2d )
+                                   z2d(:,:) = wn(:,:,1) * ( &
+                                   	  &   - ( rab_n(:,:,1,jp_tem) + rab_pe(:,:,1,jp_tem) ) * tsn(:,:,1,jp_tem)    &
+                                   	  &   + ( rab_n(:,:,1,jp_sal) + rab_pe(:,:,1,jp_sal) ) * tsn(:,:,1,jp_sal)    &
+                                      &   					) / fse3t(:,:,1)
+                                   CALL iom_put( "petrd_sad" , z2d )
+                                   CALL wrk_dealloc( jpi, jpj, z2d )
+                                ENDIF
+      CASE ( jptra_ldf  )   ;   CALL iom_put( "petrd_ldf" , zpe )   ! lateral  diffusion
+      CASE ( jptra_zdf  )   ;   CALL iom_put( "petrd_zdf" , zpe )   ! lateral  diffusion (K_z)
+      CASE ( jptra_zdfp )   ;   CALL iom_put( "petrd_zdfp", zpe )   ! vertical diffusion (K_z)
+      CASE ( jptra_dmp  )   ;   CALL iom_put( "petrd_dmp" , zpe )   ! internal 3D restoring (tradmp)
+      CASE ( jptra_bbl  )   ;   CALL iom_put( "petrd_bbl" , zpe )   ! bottom boundary layer
+      CASE ( jptra_npc  )   ;   CALL iom_put( "petrd_npc" , zpe )   ! non penetr convect adjustment
+      CASE ( jptra_nsr  )   ;   CALL iom_put( "petrd_nsr" , zpe )   ! surface forcing + runoff (ln_rnf=T)
+      CASE ( jptra_qsr  )   ;   CALL iom_put( "petrd_qsr" , zpe )   ! air-sea : penetrative sol radiat
+      CASE ( jptra_bbc  )   ;   CALL iom_put( "petrd_bbc" , zpe )   ! bottom bound cond (geoth flux)
+      CASE ( jptra_atf  )   ;   CALL iom_put( "petrd_atf" , zpe )   ! asselin time filter (last trend)
+                                !IF( .NOT.lk_vvl ) THEN                   ! cst volume : ssh term (otherwise include in e3t variation)
+                                !   CALL wrk_alloc( jpi, jpj, z2d )
+                                !   z2d(:,:) = ( ssha(:,:) - sshb(:,:) )                 &
+                                !      &     * (   dPE_dt(:,:,1) * tsn(:,:,1,jp_tem)    &
+                                !      &         + dPE_ds(:,:,1) * tsn(:,:,1,jp_sal)  ) / ( fse3t(:,:,1) * pdt )
+                                !   CALL iom_put( "petrd_sad" , z2d )
+                                !   CALL wrk_dealloc( jpi, jpj, z2d )
+                                !ENDIF
+         !
+      END SELECT
+      !
+      CALL wrk_dealloc( jpi, jpj, jpk, zpe )
+      !
+   END SUBROUTINE trd_pen
+
+
+   SUBROUTINE trd_pen_init
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_pen_init  ***
+      !! 
+      !! ** Purpose :   initialisation of 3D Kinetic Energy trend diagnostic
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'trd_pen_init : 3D Potential ENergy trends'
+         WRITE(numout,*) '~~~~~~~~~~~~~'
+      ENDIF
+      !                           ! allocate box volume arrays
+      IF ( trd_pen_alloc() /= 0 )   CALL ctl_stop('trd_pen_alloc: failed to allocate arrays')
+      !
+      rab_pe(:,:,:,:) = 0._wp
+      !
+      IF ( lk_vvl               )   CALL ctl_stop('trd_pen_init : PE trends not coded for variable volume')
+      !
+      nkstp     = nit000 - 1
+      !
+   END SUBROUTINE trd_pen_init
+
+   !!======================================================================
+END MODULE trdpen
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90	(revision 4946)
@@ -2,35 +2,48 @@
    !!======================================================================
    !!                       ***  MODULE  trdtra  ***
-   !! Ocean diagnostics:  ocean tracers trends
+   !! Ocean diagnostics:  ocean tracers trends pre-processing
    !!=====================================================================
-   !! History :  1.0  !  2004-08  (C. Talandier) Original code
-   !!            2.0  !  2005-04  (C. Deltel)    Add Asselin trend in the ML budget
-   !!            3.3  !  2010-06  (C. Ethe) merge TRA-TRC 
-   !!----------------------------------------------------------------------
-#if  defined key_trdtra || defined key_trdtrc || defined key_trdmld || defined key_trdmld_trc 
-   !!----------------------------------------------------------------------
-   !!   trd_tra      : Call the trend to be computed
-   !!----------------------------------------------------------------------
-   USE dom_oce          ! ocean domain 
-   USE trdmod_oce       ! ocean active mixed layer tracers trends 
-   USE trdmod           ! ocean active mixed layer tracers trends 
-   USE trdmod_trc       ! ocean passive mixed layer tracers trends 
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo        ! Memory allocation
-
+   !! History :  3.3  !  2010-06  (C. Ethe) creation for the TRA/TRC merge
+   !!            3.5  !  2012-02  (G. Madec) update the comments 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   trd_tra       : pre-process the tracer trends
+   !!   trd_tra_adv   : transform a div(U.T) trend into a U.grad(T) trend
+   !!   trd_tra_mng   : tracer trend manager: dispatch to the diagnostic modules
+   !!   trd_tra_iom   : output 3D tracer trends using IOM
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean domain 
+   USE sbc_oce        ! surface boundary condition: ocean
+   USE zdf_oce        ! ocean vertical physics
+   USE trd_oce        ! trends: ocean variables
+   USE trdtrc         ! ocean passive mixed layer tracers trends 
+   USE trdglo         ! trends: global domain averaged
+   USE trdpen         ! trends: Potential ENergy
+   USE trdmxl         ! ocean active mixed layer tracers trends 
+   USE ldftra_oce     ! ocean active tracers lateral physics
+   USE zdfddm         ! vertical physics: double diffusion
+   USE phycst         ! physical constants
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! Memory allocation
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   trd_tra          ! called by all  traXX modules
- 
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: trdtx, trdty, trdt  !:
+   PUBLIC   trd_tra   ! called by all tra_... modules
+
+   REAL(wp) ::   r2dt   ! time-step, = 2 rdttra except at nit000 (=rdttra) if neuler=0
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   trdtx, trdty, trdt   ! use to store the temperature trends
 
    !! * Substitutions
 #  include "domzgr_substitute.h90"
+#  include "zdfddm_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -39,7 +52,7 @@
 
    INTEGER FUNCTION trd_tra_alloc()
-      !!----------------------------------------------------------------------------
+      !!---------------------------------------------------------------------
       !!                  ***  FUNCTION trd_tra_alloc  ***
-      !!----------------------------------------------------------------------------
+      !!---------------------------------------------------------------------
       ALLOCATE( trdtx(jpi,jpj,jpk) , trdty(jpi,jpj,jpk) , trdt(jpi,jpj,jpk) , STAT= trd_tra_alloc )
       !
@@ -53,86 +66,97 @@
       !!                  ***  ROUTINE trd_tra  ***
       !! 
-      !! ** Purpose : Dispatch all trends computation, e.g. vorticity, mld or 
-      !!              integral constraints
+      !! ** Purpose : pre-process tracer trends
       !!
-      !! ** Method/usage : For the mixed-layer trend, the control surface can be either
-      !!       a mixed layer depth (time varying) or a fixed surface (jk level or bowl). 
-      !!      Choose control surface with nn_ctls in namelist NAMTRD :
-      !!        nn_ctls = 0  : use mixed layer with density criterion 
-      !!        nn_ctls = 1  : read index from file 'ctlsurf_idx'
-      !!        nn_ctls > 1  : use fixed level surface jk = nn_ctls
-      !!----------------------------------------------------------------------
-      !
-      INTEGER                         , INTENT(in)           ::  kt      ! time step
-      CHARACTER(len=3)                , INTENT(in)           ::  ctype   ! tracers trends type 'TRA'/'TRC'
-      INTEGER                         , INTENT(in)           ::  ktra    ! tracer index
-      INTEGER                         , INTENT(in)           ::  ktrd    ! tracer trend index
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in)           ::  ptrd    ! tracer trend  or flux
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::  pun     ! velocity 
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::  ptra    ! Tracer variablea
-      !
-      REAL(wp), POINTER, DIMENSION(:,:,:)  ::  ztrds
-      !!----------------------------------------------------------------------
-
+      !! ** Method  : - mask the trend
+      !!              - advection (ptra present) converte the incoming flux (U.T) 
+      !!              into trend (U.T => -U.grat(T)=div(U.T)-T.div(U)) through a 
+      !!              call to trd_tra_adv
+      !!              - 'TRA' case : regroup T & S trends
+      !!              - send the trends to trd_tra_mng (trdtrc) for further processing
+      !!----------------------------------------------------------------------
+      INTEGER                         , INTENT(in)           ::   kt      ! time step
+      CHARACTER(len=3)                , INTENT(in)           ::   ctype   ! tracers trends type 'TRA'/'TRC'
+      INTEGER                         , INTENT(in)           ::   ktra    ! tracer index
+      INTEGER                         , INTENT(in)           ::   ktrd    ! tracer trend index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in)           ::   ptrd    ! tracer trend  or flux
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::   pun     ! now velocity 
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::   ptra    ! now tracer variable
+      !
+      INTEGER  ::   jk   ! loop indices
+      REAL(wp), POINTER, DIMENSION(:,:,:)  ::   zwt, zws, ztrdt, ztrds   ! 3D workspace
+      !!----------------------------------------------------------------------
+      !
       CALL wrk_alloc( jpi, jpj, jpk, ztrds )
-
-      IF( .NOT. ALLOCATED( trdtx ) ) THEN       ! allocate trdtra arrays
+      !      
+      IF( .NOT. ALLOCATED( trdtx ) ) THEN      ! allocate trdtra arrays
          IF( trd_tra_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'trd_tra : unable to allocate arrays' )
       ENDIF
-      
-      ! Control of optional arguments
-      IF( ctype == 'TRA' .AND. ktra == jp_tem ) THEN 
-         IF( PRESENT( ptra ) ) THEN    
-            SELECT CASE( ktrd )            ! shift depending on the direction
-            CASE( jptra_trd_xad )  ;  CALL trd_tra_adv( ptrd, pun, ptra, 'X', trdtx ) 
-            CASE( jptra_trd_yad )  ;  CALL trd_tra_adv( ptrd, pun, ptra, 'Y', trdty ) 
-            CASE( jptra_trd_zad )  ;  CALL trd_tra_adv( ptrd, pun, ptra, 'Z', trdt  ) 
-            END SELECT
-         ELSE
-            trdt(:,:,:) = ptrd(:,:,:)
-            IF( ktrd == jptra_trd_bbc .OR. ktrd == jptra_trd_qsr ) THEN
-               ztrds(:,:,:) = 0.
-               CALL trd_mod( trdt, ztrds, ktrd, ctype, kt )
-            END IF
-         END IF
-      END IF
-
-      IF( ctype == 'TRA' .AND. ktra == jp_sal ) THEN 
-         IF( PRESENT( ptra ) ) THEN    
-            SELECT CASE( ktrd )            ! shift depending on the direction
-            CASE( jptra_trd_xad )  
-                                CALL trd_tra_adv( ptrd, pun, ptra, 'X', ztrds ) 
-                                CALL trd_mod( trdtx, ztrds, ktrd, ctype, kt   )
-            CASE( jptra_trd_yad )  
-                                CALL trd_tra_adv( ptrd, pun, ptra, 'Y', ztrds ) 
-                                CALL trd_mod( trdty, ztrds, ktrd, ctype, kt   )
-            CASE( jptra_trd_zad )    
-                                CALL trd_tra_adv( ptrd, pun, ptra, 'Z', ztrds ) 
-                                CALL trd_mod( trdt , ztrds, ktrd, ctype, kt   )
-            END SELECT
-         ELSE
-            ztrds(:,:,:) = ptrd(:,:,:)
-            CALL trd_mod( trdt, ztrds, ktrd, ctype, kt )  
-         END IF
-      END IF
-
-      IF( ctype == 'TRC' ) THEN
-         !
-         IF( PRESENT( ptra ) ) THEN  
-            SELECT CASE( ktrd )            ! shift depending on the direction
-            CASE( jptra_trd_xad )  
-                                CALL trd_tra_adv( ptrd, pun, ptra, 'X', ztrds ) 
-                                CALL trd_mod_trc( ztrds, ktra, ktrd, kt       )
-            CASE( jptra_trd_yad )  
-                                CALL trd_tra_adv( ptrd, pun, ptra, 'Y', ztrds ) 
-                                CALL trd_mod_trc( ztrds, ktra, ktrd, kt       )
-            CASE( jptra_trd_zad )    
-                                CALL trd_tra_adv( ptrd, pun, ptra, 'Z', ztrds ) 
-                                CALL trd_mod_trc( ztrds, ktra, ktrd, kt       )
-            END SELECT
-         ELSE
-            ztrds(:,:,:) = ptrd(:,:,:)
-            CALL trd_mod_trc( ztrds, ktra, ktrd, kt       )  
-         END IF
+
+      IF( ctype == 'TRA' .AND. ktra == jp_tem ) THEN   !==  Temperature trend  ==!
+         !
+         SELECT CASE( ktrd )
+         !                            ! advection: transform the advective flux into a trend
+         CASE( jptra_xad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'X', trdtx ) 
+         CASE( jptra_yad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'Y', trdty ) 
+         CASE( jptra_zad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'Z', trdt  ) 
+         CASE( jptra_bbc,    &        ! qsr, bbc: on temperature only, send to trd_tra_mng
+            &  jptra_qsr )   ;   trdt(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)
+                                 ztrds(:,:,:) = 0._wp
+                                 CALL trd_tra_mng( trdt, ztrds, ktrd, kt )
+         CASE DEFAULT                 ! other trends: masked trends
+            trdt(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)              ! mask & store
+         END SELECT
+         !
+      ENDIF
+
+      IF( ctype == 'TRA' .AND. ktra == jp_sal ) THEN      !==  Salinity trends  ==!
+         !
+         SELECT CASE( ktrd )
+         !                            ! advection: transform the advective flux into a trend
+         !                            !            and send T & S trends to trd_tra_mng
+         CASE( jptra_xad  )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'X'  , ztrds ) 
+                                  CALL trd_tra_mng( trdtx, ztrds, ktrd, kt   )
+         CASE( jptra_yad  )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'Y'  , ztrds ) 
+                                  CALL trd_tra_mng( trdty, ztrds, ktrd, kt   )
+         CASE( jptra_zad  )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'Z'  , ztrds ) 
+                                  CALL trd_tra_mng( trdt , ztrds, ktrd, kt   )
+         CASE( jptra_zdfp )           ! diagnose the "PURE" Kz trend (here: just before the swap)
+            !                         ! iso-neutral diffusion case otherwise jptra_zdf is "PURE"
+            CALL wrk_alloc( jpi, jpj, jpk, zwt, zws, ztrdt )
+            !
+            zwt(:,:, 1 ) = 0._wp   ;   zws(:,:, 1 ) = 0._wp            ! vertical diffusive fluxes
+            zwt(:,:,jpk) = 0._wp   ;   zws(:,:,jpk) = 0._wp
+            DO jk = 2, jpk
+               zwt(:,:,jk) =   avt(:,:,jk) * ( tsa(:,:,jk-1,jp_tem) - tsa(:,:,jk,jp_tem) ) / fse3w(:,:,jk) * tmask(:,:,jk)
+               zws(:,:,jk) = fsavs(:,:,jk) * ( tsa(:,:,jk-1,jp_sal) - tsa(:,:,jk,jp_sal) ) / fse3w(:,:,jk) * tmask(:,:,jk)
+            END DO
+            !
+            ztrdt(:,:,jpk) = 0._wp   ;   ztrds(:,:,jpk) = 0._wp
+            DO jk = 1, jpkm1
+               ztrdt(:,:,jk) = ( zwt(:,:,jk) - zwt(:,:,jk+1) ) / fse3t(:,:,jk)
+               ztrds(:,:,jk) = ( zws(:,:,jk) - zws(:,:,jk+1) ) / fse3t(:,:,jk) 
+            END DO
+            CALL trd_tra_mng( ztrdt, ztrds, jptra_zdfp, kt )  
+            !
+            CALL wrk_dealloc( jpi, jpj, jpk, zwt, zws, ztrdt )
+            !
+         CASE DEFAULT                 ! other trends: mask and send T & S trends to trd_tra_mng
+            ztrds(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)
+            CALL trd_tra_mng( trdt, ztrds, ktrd, kt )  
+         END SELECT
+      ENDIF
+
+      IF( ctype == 'TRC' ) THEN                           !==  passive tracer trend  ==!
+         !
+         SELECT CASE( ktrd )
+         !                            ! advection: transform the advective flux into a masked trend
+         CASE( jptra_xad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'X', ztrds ) 
+         CASE( jptra_yad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'Y', ztrds ) 
+         CASE( jptra_zad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'Z', ztrds ) 
+         CASE DEFAULT                 ! other trends: just masked 
+                                 ztrds(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)
+         END SELECT
+         !                            ! send trend to trd_trc
+         CALL trd_trc( ztrds, ktra, ktrd, kt ) 
          !
       ENDIF
@@ -147,39 +171,39 @@
       !!                  ***  ROUTINE trd_tra_adv  ***
       !! 
-      !! ** Purpose :   transformed the i-, j- or k-advective flux into thes
-      !!              i-, j- or k-advective trends, resp.
-      !! ** Method  :   i-advective trends = -un. di-1[T] = -( di-1[fi] - tn di-1[un] )
-      !!                k-advective trends = -un. di-1[T] = -( dj-1[fi] - tn dj-1[un] )
-      !!                k-advective trends = -un. di+1[T] = -( dk+1[fi] - tn dk+1[un] )
-      !!----------------------------------------------------------------------
-      REAL(wp)        , INTENT(in ), DIMENSION(jpi,jpj,jpk) ::   pf      ! advective flux in one direction
-      REAL(wp)        , INTENT(in ), DIMENSION(jpi,jpj,jpk) ::   pun     ! now velocity  in one direction
-      REAL(wp)        , INTENT(in ), DIMENSION(jpi,jpj,jpk) ::   ptn     ! now or before tracer 
-      CHARACTER(len=1), INTENT(in )                         ::   cdir    ! X/Y/Z direction
-      REAL(wp)        , INTENT(out), DIMENSION(jpi,jpj,jpk) ::   ptrd    ! advective trend in one direction
+      !! ** Purpose :   transformed a advective flux into a masked advective trends
+      !!
+      !! ** Method  :   use the following transformation: -div(U.T) = - U grad(T) + T.div(U)
+      !!       i-advective trends = -un. di-1[T] = -( di-1[fi] - tn di-1[un] )
+      !!       j-advective trends = -un. di-1[T] = -( dj-1[fi] - tn dj-1[un] )
+      !!       k-advective trends = -un. di+1[T] = -( dk+1[fi] - tn dk+1[un] )
+      !!                where fi is the incoming advective flux.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::   pf      ! advective flux in one direction
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::   pun     ! now velocity   in one direction
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::   ptn     ! now or before tracer 
+      CHARACTER(len=1)                , INTENT(in   ) ::   cdir    ! X/Y/Z direction
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(  out) ::   ptrd    ! advective trend in one direction
       !
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      INTEGER  ::   ii, ij, ik   ! index shift function of the direction
-      REAL(wp) ::   zbtr         ! local scalar
-      !!----------------------------------------------------------------------
-
-      SELECT CASE( cdir )            ! shift depending on the direction
-      CASE( 'X' )   ;   ii = 1   ; ij = 0   ;   ik = 0      ! i-advective trend
-      CASE( 'Y' )   ;   ii = 0   ; ij = 1   ;   ik = 0      ! j-advective trend
-      CASE( 'Z' )   ;   ii = 0   ; ij = 0   ;   ik =-1      ! k-advective trend
+      INTEGER  ::   ii, ij, ik   ! index shift as function of the direction
+      !!----------------------------------------------------------------------
+      !
+      SELECT CASE( cdir )      ! shift depending on the direction
+      CASE( 'X' )   ;   ii = 1   ;   ij = 0   ;   ik = 0      ! i-trend
+      CASE( 'Y' )   ;   ii = 0   ;   ij = 1   ;   ik = 0      ! j-trend
+      CASE( 'Z' )   ;   ii = 0   ;   ij = 0   ;   ik =-1      ! k-trend
       END SELECT
-
-      !                              ! set to zero uncomputed values
-      ptrd(jpi,:,:) = 0.e0   ;   ptrd(1,:,:) = 0.e0
-      ptrd(:,jpj,:) = 0.e0   ;   ptrd(:,1,:) = 0.e0
-      ptrd(:,:,jpk) = 0.e0
-      !
-      !
-      DO jk = 1, jpkm1
+      !
+      !                        ! set to zero uncomputed values
+      ptrd(jpi,:,:) = 0._wp   ;   ptrd(1,:,:) = 0._wp
+      ptrd(:,jpj,:) = 0._wp   ;   ptrd(:,1,:) = 0._wp
+      ptrd(:,:,jpk) = 0._wp
+      !
+      DO jk = 1, jpkm1         ! advective trend
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zbtr    = 1.e0/ ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
-               ptrd(ji,jj,jk) = - zbtr * (      pf (ji,jj,jk) - pf (ji-ii,jj-ij,jk-ik)                    &
-                 &                          - ( pun(ji,jj,jk) - pun(ji-ii,jj-ij,jk-ik) ) * ptn(ji,jj,jk)  )
+               ptrd(ji,jj,jk) = - (     pf (ji,jj,jk) - pf (ji-ii,jj-ij,jk-ik)                        &
+                 &                  - ( pun(ji,jj,jk) - pun(ji-ii,jj-ij,jk-ik) ) * ptn(ji,jj,jk)  )   &
+                 &              / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )  * tmask(ji,jj,jk)
             END DO
          END DO
@@ -188,23 +212,126 @@
    END SUBROUTINE trd_tra_adv
 
-#   else
-   !!----------------------------------------------------------------------
-   !!   Default case :          Dummy module           No trend diagnostics
-   !!----------------------------------------------------------------------
-   USE par_oce      ! ocean variables trends
-CONTAINS
-   SUBROUTINE trd_tra( kt, ctype, ktra, ktrd, ptrd, pu, ptra )
-      !!----------------------------------------------------------------------
-      INTEGER                         , INTENT(in)           ::  kt      ! time step
-      CHARACTER(len=3)                , INTENT(in)           ::  ctype   ! tracers trends type 'TRA'/'TRC'
-      INTEGER                         , INTENT(in)           ::  ktra    ! tracer index
-      INTEGER                         , INTENT(in)           ::  ktrd    ! tracer trend index
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in)           ::  ptrd    ! tracer trend 
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::  pu      ! velocity 
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::  ptra    ! Tracer variable 
-      WRITE(*,*) 'trd_3d: You should not have seen this print! error ?', ptrd(1,1,1), ptra(1,1,1), pu(1,1,1),   &
-         &                                                               ktrd, ktra, ctype, kt
-   END SUBROUTINE trd_tra
-#   endif
+
+   SUBROUTINE trd_tra_mng( ptrdx, ptrdy, ktrd, kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_tra_mng  ***
+      !! 
+      !! ** Purpose :   Dispatch all tracer trends computation, e.g. 3D output,
+      !!                integral constraints, potential energy, and/or 
+      !!                mixed layer budget.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend 
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
+      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
+      INTEGER                   , INTENT(in   ) ::   kt      ! time step
+      !!----------------------------------------------------------------------
+
+      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdtra (restart with Euler time stepping)
+      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdttra (leapfrog)
+      ENDIF
+
+      !                   ! 3D output of tracers trends using IOM interface
+      IF( ln_tra_trd )   CALL trd_tra_iom ( ptrdx, ptrdy, ktrd, kt )
+
+      !                   ! Integral Constraints Properties for tracers trends                                       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF( ln_glo_trd )   CALL trd_glo( ptrdx, ptrdy, ktrd, 'TRA', kt )
+
+      !                   ! Potential ENergy trends
+      IF( ln_PE_trd  )   CALL trd_pen( ptrdx, ptrdy, ktrd, kt, r2dt )
+
+      !                   ! Mixed layer trends for active tracers
+      IF( ln_tra_mxl )   THEN   
+         !-----------------------------------------------------------------------------------------------
+         ! W.A.R.N.I.N.G :
+         ! jptra_ldf : called by traldf.F90
+         !                 at this stage we store:
+         !                  - the lateral geopotential diffusion (here, lateral = horizontal)
+         !                  - and the iso-neutral diffusion if activated 
+         ! jptra_zdf : called by trazdf.F90
+         !                 * in case of iso-neutral diffusion we store the vertical diffusion component in the 
+         !                   lateral trend including the K_z contrib, which will be removed later (see trd_mxl)
+         !-----------------------------------------------------------------------------------------------
+
+         SELECT CASE ( ktrd )
+         CASE ( jptra_xad )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_xad, '3D' )   ! zonal    advection
+         CASE ( jptra_yad )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_yad, '3D' )   ! merid.   advection
+         CASE ( jptra_zad )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_zad, '3D' )   ! vertical advection
+         CASE ( jptra_ldf )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_ldf, '3D' )   ! lateral  diffusion
+         CASE ( jptra_bbl )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_bbl, '3D' )   ! bottom boundary layer
+         CASE ( jptra_zdf )
+            IF( ln_traldf_iso ) THEN ; CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_ldf, '3D' )   ! lateral  diffusion (K_z)
+            ELSE                   ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_zdf, '3D' )   ! vertical diffusion (K_z)
+            ENDIF
+         CASE ( jptra_dmp )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_dmp, '3D' )   ! internal 3D restoring (tradmp)
+         CASE ( jptra_qsr )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_for, '3D' )   ! air-sea : penetrative sol radiat
+         CASE ( jptra_nsr )        ;   ptrdx(:,:,2:jpk) = 0._wp   ;   ptrdy(:,:,2:jpk) = 0._wp
+                                       CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_for, '2D' )   ! air-sea : non penetr sol radiation
+         CASE ( jptra_bbc )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_bbc, '3D' )   ! bottom bound cond (geoth flux)
+         CASE ( jptra_npc )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_npc, '3D' )   ! non penetr convect adjustment
+         CASE ( jptra_atf )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_atf, '3D' )   ! asselin time filter (last trend)
+                                   !
+                                       CALL trd_mxl( kt, r2dt )                             ! trends: Mixed-layer (output)
+         END SELECT
+         !
+      ENDIF
+      !
+   END SUBROUTINE trd_tra_mng
+
+
+   SUBROUTINE trd_tra_iom( ptrdx, ptrdy, ktrd, kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_tra_iom  ***
+      !! 
+      !! ** Purpose :   output 3D tracer trends using IOM
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend 
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
+      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
+      INTEGER                   , INTENT(in   ) ::   kt      ! time step
+      !!
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
+      INTEGER ::   ikbu, ikbv   ! local integers
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   z2dx, z2dy   ! 2D workspace 
+      !!----------------------------------------------------------------------
+      !
+!!gm Rq: mask the trends already masked in trd_tra, but lbc_lnk should probably be added
+      !
+      SELECT CASE( ktrd )
+      CASE( jptra_xad  )   ;   CALL iom_put( "ttrd_xad" , ptrdx )        ! x- horizontal advection
+                               CALL iom_put( "strd_xad" , ptrdy )
+      CASE( jptra_yad  )   ;   CALL iom_put( "ttrd_yad" , ptrdx )        ! y- horizontal advection
+                               CALL iom_put( "strd_yad" , ptrdy )
+      CASE( jptra_zad  )   ;   CALL iom_put( "ttrd_zad" , ptrdx )        ! z- vertical   advection
+                               CALL iom_put( "strd_zad" , ptrdy )
+                               IF( .NOT. lk_vvl ) THEN                   ! cst volume : adv flux through z=0 surface
+                               	 CALL wrk_alloc( jpi, jpj, z2dx, z2dy )
+                                  z2dx(:,:) = wn(:,:,1) * tsn(:,:,1,jp_tem) / fse3t(:,:,1)
+                                  z2dy(:,:) = wn(:,:,1) * tsn(:,:,1,jp_sal) / fse3t(:,:,1)
+                                  CALL iom_put( "ttrd_sad", z2dx )
+                                  CALL iom_put( "strd_sad", z2dy )
+                                  CALL wrk_dealloc( jpi, jpj, z2dx, z2dy )
+                               ENDIF
+      CASE( jptra_ldf  )   ;   CALL iom_put( "ttrd_ldf" , ptrdx )        ! lateral diffusion
+                               CALL iom_put( "strd_ldf" , ptrdy )
+      CASE( jptra_zdf  )   ;   CALL iom_put( "ttrd_zdf" , ptrdx )        ! vertical diffusion (including Kz contribution)
+                               CALL iom_put( "strd_zdf" , ptrdy )
+      CASE( jptra_zdfp )   ;   CALL iom_put( "ttrd_zdfp", ptrdx )        ! PURE vertical diffusion (no isoneutral contribution)
+                               CALL iom_put( "strd_zdfp", ptrdy )
+      CASE( jptra_dmp  )   ;   CALL iom_put( "ttrd_dmp" , ptrdx )        ! internal restoring (damping)
+                               CALL iom_put( "strd_dmp" , ptrdy )
+      CASE( jptra_bbl  )   ;   CALL iom_put( "ttrd_bbl" , ptrdx )        ! bottom boundary layer
+                               CALL iom_put( "strd_bbl" , ptrdy )
+      CASE( jptra_npc  )   ;   CALL iom_put( "ttrd_npc" , ptrdx )        ! static instability mixing
+                               CALL iom_put( "strd_npc" , ptrdy )
+      CASE( jptra_nsr  )   ;   CALL iom_put( "ttrd_qns" , ptrdx )        ! surface forcing + runoff (ln_rnf=T)
+                               CALL iom_put( "strd_cdt" , ptrdy )
+      CASE( jptra_qsr  )   ;   CALL iom_put( "ttrd_qsr" , ptrdx )        ! penetrative solar radiat. (only on temperature)
+      CASE( jptra_bbc  )   ;   CALL iom_put( "ttrd_bbc" , ptrdx )        ! geothermal heating   (only on temperature)
+      CASE( jptra_atf  )   ;   CALL iom_put( "ttrd_atf" , ptrdx )        ! asselin time Filter
+                               CALL iom_put( "strd_atf" , ptrdy )
+      END SELECT
+      !
+   END SUBROUTINE trd_tra_iom
+
    !!======================================================================
 END MODULE trdtra
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdtrc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdtrc.F90	(revision 4946)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdtrc.F90	(revision 4946)
@@ -0,0 +1,23 @@
+MODULE trdtrc
+   !!======================================================================
+   !!                       ***  MODULE trdtrc  ***
+   !!  Dummy module
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                             NO TOP use
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trd_trc( ptrtrd, kjn, ktrd, kt )
+      INTEGER ::   kt, kjn, ktrd   
+      REAL    ::   ptrtrd(:,:,:)  
+      WRITE(*,*) 'trd_trc : You should not have seen this print! error?', ptrtrd(1,1,1)
+      WRITE(*,*) '  "      "      : You should not have seen this print! error?', kjn, ktrd, kt
+   END SUBROUTINE trd_trc
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: trdtrc.F90 2715 2011-03-30 15:58:35Z rblod $
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!======================================================================
+END MODULE trdtrc
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90	(revision 4946)
@@ -4,10 +4,9 @@
    !! Ocean diagnostics:  momentum trends
    !!=====================================================================
-   !! History :  1.0  !  04-2006  (L. Brunier, A-M. Treguier) Original code 
-   !!            2.0  !  04-2008  (C. Talandier) New trends organization
+   !! History :  1.0  !  2006-01  (L. Brunier, A-M. Treguier) Original code 
+   !!            2.0  !  2008-04  (C. Talandier) New trends organization
+   !!            3.5  !  2012-02  (G. Madec) regroup beta.V computation with pvo trend
    !!----------------------------------------------------------------------
-#if defined key_trdvor   ||   defined key_esopa
-   !!----------------------------------------------------------------------
-   !!   'key_trdvor'   : momentum trend diagnostics
+
    !!----------------------------------------------------------------------
    !!   trd_vor      : momentum trends averaged over the depth
@@ -17,16 +16,16 @@
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain variables
-   USE trdmod_oce      ! ocean variables trends
+   USE trd_oce         ! trends: ocean variables
    USE zdf_oce         ! ocean vertical physics
-   USE in_out_manager  ! I/O manager
+   USE sbc_oce         ! surface boundary condition: ocean
    USE phycst          ! Define parameters for the routines
    USE ldfdyn_oce      ! ocean active tracers: lateral physics
    USE dianam          ! build the name of file (routine)
    USE zdfmxl          ! mixed layer depth
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  ! I/O manager
    USE ioipsl          ! NetCDF library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp         ! MPP library
    USE wrk_nemo        ! Memory allocation
-
 
    IMPLICIT NONE
@@ -37,6 +36,5 @@
    END INTERFACE
 
-   PUBLIC   trd_vor        ! routine called by step.F90
-   PUBLIC   trd_vor_zint   ! routine called by dynamics routines
+   PUBLIC   trd_vor        ! routine called by trddyn.F90
    PUBLIC   trd_vor_init   ! routine called by opa.F90
    PUBLIC   trd_vor_alloc  ! routine called by nemogcm.F90
@@ -80,4 +78,52 @@
       IF( trd_vor_alloc /= 0 )   CALL ctl_warn('trd_vor_alloc: failed to allocate arrays')
    END FUNCTION trd_vor_alloc
+
+
+   SUBROUTINE trd_vor( putrd, pvtrd, ktrd, kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_vor  ***
+      !! 
+      !! ** Purpose :  computation of cumulated trends over analysis period
+      !!               and make outputs (NetCDF or DIMG format)
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   putrd, pvtrd   ! U and V trends 
+      INTEGER                   , INTENT(in   ) ::   ktrd           ! trend index
+      INTEGER                   , INTENT(in   ) ::   kt             ! time step
+      !
+      INTEGER ::   ji, jj   ! dummy loop indices
+      REAL(wp), POINTER, DIMENSION(:,:) ::   ztswu, ztswv    ! 2D workspace 
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, ztswu, ztswv )
+
+      SELECT CASE( ktrd ) 
+      CASE( jpdyn_hpg )   ;   CALL trd_vor_zint( putrd, pvtrd, jpvor_prg )   ! Hydrostatique Pressure Gradient 
+      CASE( jpdyn_keg )   ;   CALL trd_vor_zint( putrd, pvtrd, jpvor_keg )   ! KE Gradient 
+      CASE( jpdyn_rvo )   ;   CALL trd_vor_zint( putrd, pvtrd, jpvor_rvo )   ! Relative Vorticity 
+      CASE( jpdyn_pvo )   ;   CALL trd_vor_zint( putrd, pvtrd, jpvor_pvo )   ! Planetary Vorticity Term 
+      CASE( jpdyn_ldf )   ;   CALL trd_vor_zint( putrd, pvtrd, jpvor_ldf )   ! Horizontal Diffusion 
+      CASE( jpdyn_zad )   ;   CALL trd_vor_zint( putrd, pvtrd, jpvor_zad )   ! Vertical Advection 
+      CASE( jpdyn_spg )   ;   CALL trd_vor_zint( putrd, pvtrd, jpvor_spg )   ! Surface Pressure Grad. 
+      CASE( jpdyn_zdf )                                                      ! Vertical Diffusion 
+         ztswu(:,:) = 0.e0   ;   ztswv(:,:) = 0.e0
+         DO jj = 2, jpjm1                                                             ! wind stress trends
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ztswu(ji,jj) = 0.5 * ( utau_b(ji,jj) + utau(ji,jj) ) / ( fse3u(ji,jj,1) * rau0 )
+               ztswv(ji,jj) = 0.5 * ( vtau_b(ji,jj) + vtau(ji,jj) ) / ( fse3v(ji,jj,1) * rau0 )
+            END DO
+         END DO
+         !
+         CALL trd_vor_zint( putrd, pvtrd, jpvor_zdf )                             ! zdf trend including surf./bot. stresses 
+         CALL trd_vor_zint( ztswu, ztswv, jpvor_swf )                             ! surface wind stress 
+      CASE( jpdyn_bfr )
+         CALL trd_vor_zint( putrd, pvtrd, jpvor_bfr )                             ! Bottom stress
+         !
+      CASE( jpdyn_atf )       ! last trends: perform the output of 2D vorticity trends
+         CALL trd_vor_iom( kt )
+      END SELECT
+      !
+      CALL wrk_dealloc( jpi, jpj, ztswu, ztswv )
+      !
+   END SUBROUTINE trd_vor
 
 
@@ -109,5 +155,4 @@
       !!      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 
@@ -131,7 +176,7 @@
       !  =====================================
 
-      SELECT CASE (ktrd) 
-      !
-      CASE (jpvor_bfr)        ! bottom friction
+      SELECT CASE( ktrd ) 
+      !
+      CASE( jpvor_bfr )        ! bottom friction
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1 
@@ -143,5 +188,5 @@
          END DO
          !
-      CASE (jpvor_swf)        ! wind stress
+      CASE( jpvor_swf )        ! wind stress
          zudpvor(:,:) = putrdvor(:,:) * fse3u(:,:,1) * e1u(:,:) * umask(:,:,1)
          zvdpvor(:,:) = pvtrdvor(:,:) * fse3v(:,:,1) * e2v(:,:) * vmask(:,:,1)
@@ -154,6 +199,6 @@
    
       ! Curl
-      DO ji=1,jpim1
-         DO jj=1,jpjm1
+      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) )
@@ -229,15 +274,23 @@
       END DO
 
-      ! Save Beta.V term to avoid average before Curl
-      ! Beta.V : intergration, no average
-      IF( ktrd == jpvor_bev ) THEN 
+      ! Planetary vorticity: 2nd computation (Beta.V term) store the vertical sum
+      ! as Beta.V term need intergration, not average
+      IF( ktrd == jpvor_pvo ) THEN 
          zubet(:,:) = zudpvor(:,:)
          zvbet(:,:) = zvdpvor(:,:)
-      ENDIF
-
-      ! Average except for Beta.V
+         DO ji = 1, jpim1
+            DO jj = 1, jpjm1
+               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) )
+            END DO
+         END DO
+         ! Average of the Curl and Surface mask
+         vortrd(:,:,jpvor_bev) = vortrd(:,:,jpvor_bev) * hur(:,:) * fmask(:,:,1)
+      ENDIF
+      !
+      ! Average 
       zudpvor(:,:) = zudpvor(:,:) * hur(:,:)
       zvdpvor(:,:) = zvdpvor(:,:) * hvr(:,:)
-   
+      !
       ! Curl
       DO ji=1,jpim1
@@ -247,24 +300,6 @@
          END DO
       END DO
-
       ! Surface mask
       vortrd(:,:,ktrd) = vortrd(:,:,ktrd) * fmask(:,:,1)
-
-      ! Special treatement for the Beta.V term
-      ! Compute the Curl of the Beta.V term which is not averaged
-      IF( ktrd == jpvor_bev ) THEN
-         DO ji=1,jpim1
-            DO jj=1,jpjm1
-               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) )
-            END DO
-         END DO
-
-         ! Average on the Curl
-         vortrd(:,:,jpvor_bev) = vortrd(:,:,jpvor_bev) * hur(:,:)
-
-         ! Surface mask
-         vortrd(:,:,jpvor_bev) = vortrd(:,:,jpvor_bev) * fmask(:,:,1)
-      ENDIF
    
       IF( ndebug /= 0 ) THEN
@@ -278,5 +313,5 @@
 
 
-   SUBROUTINE trd_vor( kt )
+   SUBROUTINE trd_vor_iom( kt )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE trd_vor  ***
@@ -285,6 +320,5 @@
       !!               and make outputs (NetCDF or DIMG format)
       !!----------------------------------------------------------------------
-      !
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      INTEGER                   , INTENT(in   ) ::   kt             ! time step
       !
       INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
@@ -305,9 +339,4 @@
 
       IF( kt > nit000 )   vor_avrb(:,:) = vor_avr(:,:)
-
-      IF( ndebug /= 0 ) THEN
-          WRITE(numout,*) ' debuging trd_vor: I.1 done '
-          CALL FLUSH(numout)
-      ENDIF
 
       ! I.2 vertically integrated vorticity
@@ -330,6 +359,6 @@
 
       ! Curl
-      DO ji=1,jpim1
-         DO jj=1,jpjm1
+      DO ji = 1, jpim1
+         DO jj = 1, jpjm1
             vor_avr(ji,jj) = (  ( zvn(ji+1,jj) - zvn(ji,jj) )    &
                &              - ( zun(ji,jj+1) - zun(ji,jj) ) ) / ( e1f(ji,jj) * e2f(ji,jj) ) * fmask(ji,jj,1)
@@ -337,9 +366,4 @@
       END DO
       
-      IF( ndebug /= 0 ) THEN
-         WRITE(numout,*) ' debuging trd_vor: I.2 done'
-         CALL FLUSH(numout)
-      ENDIF
-
       !  =================================
       !   II. Cumulated trends
@@ -351,9 +375,4 @@
          vor_avrbb(:,:) = vor_avrb(:,:)
          vor_avrbn(:,:) = vor_avr (:,:)
-      ENDIF
-
-      IF( ndebug /= 0 ) THEN
-         WRITE(numout,*) ' debuging trd_vor: I1.1 done'
-         CALL FLUSH(numout)
       ENDIF
 
@@ -371,9 +390,4 @@
       ENDIF
 
-      IF( ndebug /= 0 ) THEN
-         WRITE(numout,*) ' debuging trd_vor: II.2 done'
-         CALL FLUSH(numout)
-      ENDIF
-
       !  =============================================
       !   III. Output in netCDF + residual computation
@@ -391,9 +405,4 @@
          vor_avrtot(:,:) = (  vor_avr(:,:) - vor_avrbn(:,:) + vor_avrb(:,:) - vor_avrbb(:,:) ) * zmean
 
-         IF( ndebug /= 0 ) THEN
-             WRITE(numout,*) ' zmean = ',zmean
-             WRITE(numout,*) ' debuging trd_vor: III.1 done'
-             CALL FLUSH(numout)
-         ENDIF
 
          ! III.2 compute residual
@@ -406,8 +415,4 @@
          CALL lbc_lnk( vor_avrres, 'F', 1. )
 
-         IF( ndebug /= 0 ) THEN
-            WRITE(numout,*) ' debuging trd_vor: III.2 done'
-            CALL FLUSH(numout)
-         ENDIF
 
          ! III.3 time evolution array swap
@@ -415,9 +420,4 @@
          vor_avrbb(:,:) = vor_avrb(:,:)
          vor_avrbn(:,:) = vor_avr (:,:)
-
-         IF( ndebug /= 0 ) THEN
-            WRITE(numout,*) ' debuging trd_vor: III.3 done'
-            CALL FLUSH(numout)
-         ENDIF
          !
          nmoydpvor = 0
@@ -463,5 +463,5 @@
       CALL wrk_dealloc( jpi, jpj, zun, zvn )                                   
       !
-   END SUBROUTINE trd_vor
+   END SUBROUTINE trd_vor_iom
 
 
@@ -587,29 +587,4 @@
    END SUBROUTINE trd_vor_init
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                       Empty module
-   !!----------------------------------------------------------------------
-   INTERFACE trd_vor_zint
-      MODULE PROCEDURE trd_vor_zint_2d, trd_vor_zint_3d
-   END INTERFACE
-CONTAINS
-   SUBROUTINE trd_vor( kt )        ! Empty routine
-      WRITE(*,*) 'trd_vor: You should not have seen this print! error?', kt
-   END SUBROUTINE trd_vor
-   SUBROUTINE trd_vor_zint_2d( putrdvor, pvtrdvor, ktrd )
-      REAL, DIMENSION(:,:), INTENT( inout ) ::   putrdvor, pvtrdvor
-      INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
-      WRITE(*,*) 'trd_vor_zint_2d: You should not have seen this print! error?', putrdvor(1,1), pvtrdvor(1,1), ktrd
-   END SUBROUTINE trd_vor_zint_2d
-   SUBROUTINE trd_vor_zint_3d( putrdvor, pvtrdvor, ktrd )
-      REAL, DIMENSION(:,:,:), INTENT( inout ) ::   putrdvor, pvtrdvor
-      INTEGER, INTENT( in ) ::   ktrd         ! ocean trend index
-      WRITE(*,*) 'trd_vor_zint_3d: You should not have seen this print! error?', putrdvor(1,1,1), pvtrdvor(1,1,1), ktrd
-   END SUBROUTINE trd_vor_zint_3d
-   SUBROUTINE trd_vor_init              ! Empty routine
-      WRITE(*,*) 'trd_vor_init: You should not have seen this print! error?'
-   END SUBROUTINE trd_vor_init
-#endif
    !!======================================================================
 END MODULE trdvor
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor_oce.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor_oce.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor_oce.F90	(revision 4946)
@@ -4,8 +4,7 @@
    !! Ocean trends :   set vorticity trend variables
    !!======================================================================
-   !! History :  9.0  !  04-2006  (L. Brunier, A-M. Treguier) Original code 
+   !! History :  1.0  !  04-2006  (L. Brunier, A-M. Treguier) Original code 
    !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
+   
    USE par_oce      ! ocean parameters
 
@@ -13,9 +12,4 @@
    PRIVATE
 
-#if defined key_trdvor
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trdvor = .TRUE.    !: momentum trend flag
-#else
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trdvor = .FALSE.   !: momentum trend flag
-#endif
    !                                               !!* vorticity trends index
    INTEGER, PUBLIC, PARAMETER ::   jpltot_vor = 11  !: Number of vorticity trend terms
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfbfr.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfbfr.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfbfr.F90	(revision 4946)
@@ -113,16 +113,8 @@
          IF ( ln_loglayer.AND.lk_vvl ) THEN ! "log layer" bottom friction coefficient
 
-#  if defined key_vectopt_loop
-            DO jj = 1, 1
-!CDIR NOVERRCHK
-               DO ji = 1, jpij   ! vector opt. (forced unrolling)
-#  else
-!CDIR NOVERRCHK
             DO jj = 1, jpj
-!CDIR NOVERRCHK
                DO ji = 1, jpi
-#  endif
                   ikbt = mbkt(ji,jj)
-! JC: possible WAD implementation should modify line below if layers vanish
+!! JC: possible WAD implementation should modify line below if layers vanish
                   ztmp = tmask(ji,jj,ikbt) * ( vkarmn / LOG( 0.5_wp * fse3t_n(ji,jj,ikbt) / rn_bfrz0 ))**2._wp
                   zbfrt(ji,jj) = MAX(bfrcoef2d(ji,jj), ztmp)
@@ -143,14 +135,6 @@
          ENDIF
 
-# if defined key_vectopt_loop
-         DO jj = 1, 1
-!CDIR NOVERRCHK
-            DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
-# else
-!CDIR NOVERRCHK
          DO jj = 2, jpjm1
-!CDIR NOVERRCHK
             DO ji = 2, jpim1
-# endif
                ikbu = mbku(ji,jj)         ! ocean bottom level at u- and v-points
                ikbv = mbkv(ji,jj)         ! (deepest ocean u- and v-points)
@@ -206,5 +190,4 @@
             END DO
          END DO
-
          !
          CALL lbc_lnk( bfrua, 'U', 1. )   ;   CALL lbc_lnk( bfrva, 'V', 1. )      ! Lateral boundary condition
@@ -342,14 +325,6 @@
          !
          IF ( ln_loglayer.AND.(.NOT.lk_vvl) ) THEN ! set "log layer" bottom friction once for all
-#  if defined key_vectopt_loop
-            DO jj = 1, 1
-!CDIR NOVERRCHK
-               DO ji = 1, jpij   ! vector opt. (forced unrolling)
-#  else
-!CDIR NOVERRCHK
             DO jj = 1, jpj
-!CDIR NOVERRCHK
                DO ji = 1, jpi
-#  endif
                   ikbt = mbkt(ji,jj)
                   ztmp = tmask(ji,jj,ikbt) * ( vkarmn / LOG( 0.5_wp * fse3t_n(ji,jj,ikbt) / rn_bfrz0 ))**2._wp
@@ -388,14 +363,6 @@
       zmaxtfr = -1.e10_wp    ! initialise tracker for maximum of bottom friction coefficient
       !
-#  if defined key_vectopt_loop
-      DO jj = 1, 1
-!CDIR NOVERRCHK
-         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
-#  else
-!CDIR NOVERRCHK
       DO jj = 2, jpjm1
-!CDIR NOVERRCHK
          DO ji = 2, jpim1
-#  endif
              ikbu = mbku(ji,jj)       ! deepest ocean level at u- and v-points
              ikbv = mbkv(ji,jj)
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfddm.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfddm.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfddm.F90	(revision 4946)
@@ -6,5 +6,6 @@
    !! History :  OPA  ! 2000-08  (G. Madec)  double diffusive mixing
    !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
-   !!            3.3  !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
+   !!            3.3  ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
+   !!            3.6  ! 2013-04  (G. Madec, F. Roquet) zrau compute locally using interpolation of alpha & beta
    !!----------------------------------------------------------------------
 #if defined key_zdfddm   ||   defined key_esopa
@@ -18,4 +19,6 @@
    USE dom_oce         ! ocean space and time domain variables 
    USE zdf_oce         ! ocean vertical physics variables
+   USE eosbn2         ! equation of state
+   !
    USE in_out_manager  ! I/O manager
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
@@ -34,15 +37,15 @@
    LOGICAL , PUBLIC, PARAMETER ::   lk_zdfddm = .TRUE.  !: double diffusive mixing flag
 
-   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   avs    !: salinity vertical diffusivity coeff. at w-point
-   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   rrau   !: heat/salt buoyancy flux ratio
-
-   !                      !!* Namelist namzdf_ddm : double diffusive mixing *
-   REAL(wp) ::   rn_avts   ! maximum value of avs for salt fingering
-   REAL(wp) ::   rn_hsbfr  ! heat/salt buoyancy flux ratio
+   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   avs   !: salinity vertical diffusivity coeff. at w-point
+
+   !                       !!* Namelist namzdf_ddm : double diffusive mixing *
+   REAL(wp) ::   rn_avts    ! maximum value of avs for salt fingering
+   REAL(wp) ::   rn_hsbfr   ! heat/salt buoyancy flux ratio
 
    !! * Substitutions
+#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -54,6 +57,5 @@
       !!                ***  ROUTINE zdf_ddm_alloc  ***
       !!----------------------------------------------------------------------
-      ALLOCATE( avs(jpi,jpj,jpk), rrau(jpi,jpj,jpk), STAT= zdf_ddm_alloc )
-      !
+      ALLOCATE( avs(jpi,jpj,jpk) , STAT= zdf_ddm_alloc )
       IF( lk_mpp             )   CALL mpp_sum ( zdf_ddm_alloc )
       IF( zdf_ddm_alloc /= 0 )   CALL ctl_warn('zdf_ddm_alloc: failed to allocate arrays')
@@ -71,16 +73,14 @@
       !!      diffusive mixing (i.e. salt fingering and diffusive layering)
       !!      following Merryfield et al. (1999). The rate of double diffusive 
-      !!      mixing depend on the buoyancy ratio: Rrau=alpha/beta dk[T]/dk[S]
-      !!      which is computed in rn2.F
+      !!      mixing depend on the buoyancy ratio (R=alpha/beta dk[T]/dk[S]):
       !!         * salt fingering (Schmitt 1981):
-      !!      for Rrau > 1 and rn2 > 0 : zavfs = rn_avts / ( 1 + (Rrau/rn_hsbfr)^6 )
-      !!      for Rrau > 1 and rn2 > 0 : zavfs = O
-      !!      otherwise                : zavft = 0.7 zavs / Rrau
+      !!      for R > 1 and rn2 > 0 : zavfs = rn_avts / ( 1 + (R/rn_hsbfr)^6 )
+      !!      for R > 1 and rn2 > 0 : zavfs = O
+      !!      otherwise                : zavft = 0.7 zavs / R
       !!         * diffusive layering (Federov 1988):
-      !!      for 0< Rrau < 1 and rn2 > 0 : zavdt = 1.3635e-6  
-      !!                                 * exp( 4.6 exp(-0.54 (1/Rrau-1) ) )
+      !!      for 0< R < 1 and N^2 > 0 : zavdt = 1.3635e-6 * exp( 4.6 exp(-0.54 (1/R-1) ) )
       !!      otherwise                   : zavdt = 0 
-      !!      for .5 < Rrau < 1 and rn2 > 0 : zavds = zavdt (1.885 Rrau -0.85)
-      !!      for  0 < Rrau <.5 and rn2 > 0 : zavds = zavdt 0.15 Rrau      
+      !!      for .5 < R < 1 and N^2 > 0 : zavds = zavdt (1.885 R -0.85)
+      !!      for  0 < R <.5 and N^2 > 0 : zavds = zavdt 0.15 R      
       !!      otherwise                     : zavds = 0 
       !!         * update the eddy diffusivity:
@@ -96,47 +96,65 @@
       !
       INTEGER  ::   ji, jj , jk     ! dummy loop indices
-      REAL(wp) ::   zinr, zrr       ! temporary scalars
-      REAL(wp) ::   zavft, zavfs    !    -         -
-      REAL(wp) ::   zavdt, zavds    !    -         -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zmsks, zmskf, zmskd1, zmskd2, zmskd3
+      REAL(wp) ::   zaw, zbw, zrw   ! local scalars
+      REAL(wp) ::   zdt, zds
+      REAL(wp) ::   zinr, zrr       !   -      -
+      REAL(wp) ::   zavft, zavfs    !   -      -
+      REAL(wp) ::   zavdt, zavds    !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zrau, zmsks, zmskf, zmskd1, zmskd2, zmskd3
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('zdf_ddm')
       !
-      CALL wrk_alloc( jpi,jpj, zmsks, zmskf, zmskd1, zmskd2, zmskd3 )
-
+      CALL wrk_alloc( jpi,jpj, zrau, zmsks, zmskf, zmskd1, zmskd2, zmskd3 )
+      !
       !                                                ! ===============
-      !                                                ! Horizontal slab
+      DO jk = 2, jpkm1                                 ! Horizontal slab
          !                                             ! ===============
-      DO jj = 1, jpj                                     ! indicators:
-         DO ji = 1, jpi
-            DO jk = mikt(ji,jj)+1, jpkm1                                 ! Horizontal slab
          ! Define the mask 
          ! ---------------
-               rrau(ji,jj,jk) = MAX( 1.e-20, rrau(ji,jj,jk) )         ! only retains positive value of rrau
-
+         DO jj = 1, jpj                                ! R=zrau = (alpha / beta) (dk[t] / dk[s])
+            DO ji = 1, jpi
+               zrw =   ( fsdepw(ji,jj,jk  ) - fsdept(ji,jj,jk) )   &
+                  &  / ( fsdept(ji,jj,jk-1) - fsdept(ji,jj,jk) ) 
+               !
+               zaw = (  rab_n(ji,jj,jk,jp_tem) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_tem) * zrw  )  &
+                   &    * tmask(ji,jj,jk) * tmask(ji,jj,jk-1)
+               zbw = (  rab_n(ji,jj,jk,jp_sal) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_sal) * zrw  )  &
+                   &    * tmask(ji,jj,jk) * tmask(ji,jj,jk-1)
+               !
+               zdt = zaw * ( tsn(ji,jj,jk-1,jp_tem) - tsn(ji,jj,jk,jp_tem) )
+               zds = zbw * ( tsn(ji,jj,jk-1,jp_sal) - tsn(ji,jj,jk,jp_sal) ) 
+               IF( ABS( zds) <= 1.e-20_wp )   zds = 1.e-20_wp
+               zrau(ji,jj) = MAX(  1.e-20, zdt / zds  )    ! only retains positive value of zrau
+            END DO
+         END DO
+
+         DO jj = 1, jpj                                     ! indicators:
+            DO ji = 1, jpi
                ! stability indicator: msks=1 if rn2>0; 0 elsewhere
                IF( rn2(ji,jj,jk) + 1.e-12  <= 0. ) THEN   ;   zmsks(ji,jj) = 0._wp
                ELSE                                       ;   zmsks(ji,jj) = 1._wp
                ENDIF
-               ! salt fingering indicator: msksf=1 if rrau>1; 0 elsewhere            
-               IF( rrau(ji,jj,jk) <= 1.          ) THEN   ;   zmskf(ji,jj) = 0._wp
+               ! salt fingering indicator: msksf=1 if R>1; 0 elsewhere            
+               IF( zrau(ji,jj) <= 1.             ) THEN   ;   zmskf(ji,jj) = 0._wp
                ELSE                                       ;   zmskf(ji,jj) = 1._wp
                ENDIF
                ! diffusive layering indicators: 
-               !     ! mskdl1=1 if 0<rrau<1; 0 elsewhere
-               IF( rrau(ji,jj,jk) >= 1.          ) THEN   ;   zmskd1(ji,jj) = 0._wp
+               !     ! mskdl1=1 if 0< R <1; 0 elsewhere
+               IF( zrau(ji,jj) >= 1.             ) THEN   ;   zmskd1(ji,jj) = 0._wp
                ELSE                                       ;   zmskd1(ji,jj) = 1._wp
                ENDIF
-               !     ! mskdl2=1 if 0<rrau<0.5; 0 elsewhere
-               IF( rrau(ji,jj,jk) >= 0.5         ) THEN   ;   zmskd2(ji,jj) = 0._wp
+               !     ! mskdl2=1 if 0< R <0.5; 0 elsewhere
+               IF( zrau(ji,jj) >= 0.5            ) THEN   ;   zmskd2(ji,jj) = 0._wp
                ELSE                                       ;   zmskd2(ji,jj) = 1._wp
                ENDIF
-               !   mskdl3=1 if 0.5<rrau<1; 0 elsewhere
-               IF( rrau(ji,jj,jk) <= 0.5 .OR. rrau(ji,jj,jk) >= 1. ) THEN   ;   zmskd3(ji,jj) = 0._wp
-               ELSE                                                         ;   zmskd3(ji,jj) = 1._wp
-               ENDIF
+               !   mskdl3=1 if 0.5< R <1; 0 elsewhere
+               IF( zrau(ji,jj) <= 0.5 .OR. zrau(ji,jj) >= 1. ) THEN   ;   zmskd3(ji,jj) = 0._wp
+               ELSE                                                   ;   zmskd3(ji,jj) = 1._wp
+               ENDIF
+            END DO
+         END DO
          ! mask zmsk in order to have avt and avs masked
-               zmsks(ji,jj) = zmsks(ji,jj) * tmask(ji,jj,jk)
+         zmsks(:,:) = zmsks(:,:) * tmask(:,:,jk)
 
 
@@ -144,7 +162,11 @@
          ! ------------------
          ! Constant eddy coefficient: reset to the background value
-               zinr = 1./rrau(ji,jj,jk)
+!CDIR NOVERRCHK
+         DO jj = 1, jpj
+!CDIR NOVERRCHK
+            DO ji = 1, jpi
+               zinr = 1._wp / zrau(ji,jj)
                ! salt fingering
-               zrr = rrau(ji,jj,jk)/rn_hsbfr
+               zrr = zrau(ji,jj) / rn_hsbfr
                zrr = zrr * zrr
                zavfs = rn_avts / ( 1 + zrr*zrr*zrr ) * zmsks(ji,jj) * zmskf(ji,jj)
@@ -152,6 +174,6 @@
                ! diffusive layering
                zavdt = 1.3635e-6 * EXP(  4.6 * EXP( -0.54*(zinr-1.) )  ) * zmsks(ji,jj) * zmskd1(ji,jj)
-               zavds = zavdt * zmsks(ji,jj) * (  (1.85 * rrau(ji,jj,jk) - 0.85 ) * zmskd3(ji,jj)   &
-                  &                            +  0.15 * rrau(ji,jj,jk)          * zmskd2(ji,jj)  )
+               zavds = zavdt * zmsks(ji,jj) * (  ( 1.85 * zrau(ji,jj) - 0.85 ) * zmskd3(ji,jj)   &
+                  &                             +  0.15 * zrau(ji,jj)          * zmskd2(ji,jj)  )
                ! add to the eddy viscosity coef. previously computed
                avs (ji,jj,jk) = avt(ji,jj,jk) + zavfs + zavds
@@ -160,16 +182,14 @@
             END DO
          END DO
-      END DO
+
+
          ! Increase avmu, avmv if necessary
          ! --------------------------------
 !!gm to be changed following the definition of avm.
-      DO jj = 1, jpjm1
-         DO ji = 1, fs_jpim1   ! vector opt.
-            DO jk = miku(ji,jj)+1, jpkm1                                 ! Horizontal slab
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
                avmu(ji,jj,jk) = MAX( avmu(ji,jj,jk),    &
                   &                  avt(ji,jj,jk), avt(ji+1,jj,jk),   &
                   &                  avs(ji,jj,jk), avs(ji+1,jj,jk) )  * umask(ji,jj,jk)
-            END DO
-            DO jk = mikv(ji,jj)+1, jpkm1
                avmv(ji,jj,jk) = MAX( avmv(ji,jj,jk),    &
                   &                  avt(ji,jj,jk), avt(ji,jj+1,jk),   &
@@ -209,6 +229,7 @@
       !!              called by zdf_ddm at the first timestep (nit000)
       !!----------------------------------------------------------------------
+      INTEGER ::   ios   ! local integer
+      !!
       NAMELIST/namzdf_ddm/ rn_avts, rn_hsbfr
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
       !!----------------------------------------------------------------------
       !
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfevd.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfevd.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfevd.F90	(revision 4946)
@@ -78,11 +78,6 @@
          !
          DO jk = 1, jpkm1 
-#if defined key_vectopt_loop
-            DO jj = 1, 1                     ! big loop forced
-               DO ji = jpi+2, jpij   
-#else
             DO jj = 2, jpj             ! no vector opt.
                DO ji = 2, jpi
-#endif
 #if defined key_zdfkpp
                   ! no evd mixing in the boundary layer with KPP
@@ -110,11 +105,6 @@
          DO jk = 1, jpkm1
 !!!         WHERE( rn2(:,:,jk) <= -1.e-12 ) avt(:,:,jk) = tmask(:,:,jk) * avevd   ! agissant sur T SEUL! 
-#if defined key_vectopt_loop
-            DO jj = 1, 1                     ! big loop forced
-               DO ji = 1, jpij   
-#else
             DO jj = 1, jpj             ! loop over the whole domain (no lbc_lnk call)
                DO ji = 1, jpi
-#endif
 #if defined key_zdfkpp
                   ! no evd mixing in the boundary layer with KPP
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfkpp.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfkpp.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfkpp.F90	(revision 4946)
@@ -26,14 +26,15 @@
    USE phycst         ! physical constants
    USE eosbn2         ! equation of state
-   USE zdfddm         ! double diffusion mixing
+   USE zdfddm         ! double diffusion mixing (avs array)
+   USE lib_mpp        ! MPP library
+   USE trd_oce        ! ocean trends definition
+   USE trdtra         ! tracers trends
+   !
    USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
    USE prtctl         ! Print control
-   USE trdmod_oce     ! ocean trends definition
-   USE trdtra         ! tracers trends
+   USE wrk_nemo       ! work arrays
    USE timing         ! Timing
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
 
    IMPLICIT NONE
@@ -246,8 +247,8 @@
       REAL(wp) ::   zdelta, zdelta2, zdzup, zdzdn, zdzh, zvath, zgat1, zdat1, zkm1m, zkm1t
 #if defined key_zdfddm
-      REAL(wp) ::   zrrau, zds, zavdds, zavddt,zinr   ! double diffusion mixing
-      REAL(wp), POINTER, DIMENSION(:,:)   ::     zdifs
+      REAL(wp) ::   zrw, zkm1s                    ! local scalars
+      REAL(wp) ::   zrrau, zdt, zds, zavdds, zavddt, zinr   ! double diffusion mixing
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   zdifs
       REAL(wp), POINTER, DIMENSION(:)     ::   za2s, za3s, zkmps
-      REAL(wp) ::                            zkm1s
       REAL(wp), POINTER, DIMENSION(:,:)   ::   zblcs
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   zdiffus
@@ -274,19 +275,17 @@
 #endif
 
-      zviscos(:,:,:) = 0.
-      zblcm  (:,:  ) = 0. 
-      zdiffut(:,:,:) = 0.
-      zblct  (:,:  ) = 0. 
+      zviscos(:,:,:) = 0._wp
+      zblcm  (:,:  ) = 0._wp
+      zdiffut(:,:,:) = 0._wp
+      zblct  (:,:  ) = 0._wp 
 #if defined key_zdfddm
-      zdiffus(:,:,:) = 0.
-      zblcs  (:,:  ) = 0. 
-#endif
-      ghats(:,:,:) = 0.
-     
-      zBo   (:,:) = 0.
-      zBosol(:,:) = 0.
-      zustar(:,:) = 0.
-
-
+      zdiffus(:,:,:) = 0._wp
+      zblcs  (:,:  ) = 0._wp 
+#endif
+      ghats  (:,:,:) = 0._wp
+      zBo    (:,:  ) = 0._wp
+      zBosol (:,:  ) = 0._wp
+      zustar (:,:  ) = 0._wp
+      !
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! I. Interior diffusivity and viscosity at w points ( T interfaces)
@@ -332,19 +331,28 @@
                   avt (ji,jj,jk) =  avt (ji,jj,jk) + rn_difri * zfri    
                ENDIF
+               !
 #if defined key_zdfddm 
-               avs (ji,jj,jk) =  avt (ji,jj,jk)              
+               !
                !  Double diffusion mixing ; NOT IN ROUTINE ZDFDDM.F90
-               ! ------------------------------------------------------------------
-               ! only retains positive value of rrau
-               zrrau = MAX( rrau(ji,jj,jk), epsln )
-               zds   = tsn(ji,jj,jk-1,jp_sal) - tsn(ji,jj,jk,jp_sal)
-               IF( zrrau > 1. .AND. zds > 0.) THEN
-                  !
-                  ! Salt fingering case.
-                  !---------------------
-                  ! Compute interior diffusivity for double diffusive mixing of
-                  ! salinity. Upper bound "zrrau" by "Rrho0"; (Rrho0=1.9, difcoefnuf=0.001).
-                  ! After that set interior diffusivity for double diffusive mixing
-                  ! of temperature
+               ! -------------------------
+               avs (ji,jj,jk) =  avt (ji,jj,jk)   
+
+               ! R=zrau = (alpha / beta) (dk[t] / dk[s])
+               zrw =   ( fsdepw(ji,jj,jk  ) - fsdept(ji,jj,jk) )   &
+                  &  / ( fsdept(ji,jj,jk-1) - fsdept(ji,jj,jk) ) 
+               !
+               zaw = (  rab_n(ji,jj,jk,jp_tem) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_tem) * zrw  ) * tmask(ji,jj,jk)
+               zbw = (  rab_n(ji,jj,jk,jp_sal) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_sal) * zrw  ) * tmask(ji,jj,jk)
+               !
+               zdt = zaw * ( tsn(ji,jj,jk-1,jp_tem) - tsn(ji,jj,jk,jp_tem) )
+               zds = zbw * ( tsn(ji,jj,jk-1,jp_sal) - tsn(ji,jj,jk,jp_sal) ) 
+               IF( ABS( zds) <= 1.e-20_wp )   zds = 1.e-20_wp
+               zrrau = MAX(  epsln , zdt / zds  )    ! only retains positive value of zrau
+               !
+               IF( zrrau > 1. .AND. zds > 0.) THEN                        ! Salt fingering case.
+                  !                                                       !---------------------
+                  ! Compute interior diffusivity for double diffusive mixing of salinity. 
+                  ! Upper bound "zrrau" by "Rrho0"; (Rrho0=1.9, difcoefnuf=0.001).
+                  ! After that set interior diffusivity for double diffusive mixing of temperature
                   zavdds = MIN( zrrau, Rrho0 )
                   zavdds = ( zavdds - 1.0 ) / ( Rrho0 - 1.0 )
@@ -353,18 +361,14 @@
                   zavdds = difssf * zavdds 
                   zavddt = 0.7 * zavdds
-               ELSEIF( zrrau < 1. .AND. zrrau > 0. .AND. zds < 0.) THEN
                   !
-                  ! Diffusive convection case.
-                  !---------------------------
-                  ! Compute interior diffusivity for double diffusive mixing of
-                  ! temperature (Marmorino and Caldwell, 1976); 
+               ELSEIF( zrrau < 1. .AND. zrrau > 0. .AND. zds < 0.) THEN   ! Diffusive convection case.
+                  !                                                       !---------------------------
+                  ! Compute interior diffusivity for double diffusive mixing of temperature (Marmorino and Caldwell, 1976); 
                   ! Compute interior diffusivity for double diffusive mixing of salinity 
                   zinr   = 1. / zrrau
                   zavddt = 0.909 * EXP( 4.6 * EXP( -0.54* ( zinr - 1. ) ) ) 
                   zavddt = difsdc * zavddt
-                  IF( zrrau < 0.5) THEN
-                     zavdds = zavddt * 0.15 * zrrau
-                  ELSE
-                     zavdds = zavddt * (1.85 * zrrau - 0.85 ) 
+                  IF( zrrau < 0.5) THEN   ;   zavdds = zavddt * 0.15 * zrrau
+                  ELSE                    ;   zavdds = zavddt * (1.85 * zrrau - 0.85 ) 
                   ENDIF
                ELSE
@@ -385,44 +389,10 @@
       !---------------------------------------------------------------------
       DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1     
-            IF( nn_eos < 1) THEN   
-               zt     = tsn(ji,jj,1,jp_tem)
-               zs     = tsn(ji,jj,1,jp_sal) - 35.0
-               zh     = fsdept(ji,jj,1)
-               !  potential volumic mass
-               zrhos  = rhop(ji,jj,1)
-               zalbet = ( ( ( - 0.255019e-07 * zt + 0.298357e-05 ) * zt   &   ! ratio alpha/beta
-                  &                               - 0.203814e-03 ) * zt   &
-                  &                               + 0.170907e-01 ) * zt   &
-                  &   + 0.665157e-01                                      &
-                  &   +     ( - 0.678662e-05 * zs                         &
-                  &           - 0.846960e-04 * zt + 0.378110e-02 ) * zs   &
-                  &   +   ( ( - 0.302285e-13 * zh                         &
-                  &           - 0.251520e-11 * zs                         &
-                  &           + 0.512857e-12 * zt * zt           ) * zh   &
-                  &           - 0.164759e-06 * zs                         &
-                  &        +(   0.791325e-08 * zt - 0.933746e-06 ) * zt   &
-                  &                               + 0.380374e-04 ) * zh
-
-               zbeta  = ( ( -0.415613e-09 * zt + 0.555579e-07 ) * zt      &   ! beta
-                  &                            - 0.301985e-05 ) * zt      &
-                  &   + 0.785567e-03                                      &
-                  &   + (     0.515032e-08 * zs                           &
-                  &         + 0.788212e-08 * zt - 0.356603e-06 ) * zs     &
-                  &   +(  (   0.121551e-17 * zh                           &
-                  &         - 0.602281e-15 * zs                           &
-                  &         - 0.175379e-14 * zt + 0.176621e-12 ) * zh     &
-                  &                             + 0.408195e-10   * zs     &
-                  &     + ( - 0.213127e-11 * zt + 0.192867e-09 ) * zt     &
-                  &                             - 0.121555e-07 ) * zh
-
-               zthermal = zbeta * zalbet / ( rcp * zrhos + epsln )
-               zhalin   = zbeta * tsn(ji,jj,1,jp_sal) * rcs
-            ELSE
-               zrhos    = rhop(ji,jj,1) + rau0 * ( 1. - tmask(ji,jj,1) )
-               zthermal = rn_alpha / ( rcp * zrhos + epsln )
-               zhalin   = rn_beta * tsn(ji,jj,1,jp_sal) * rcs
-               zbeta    = rn_beta
-            ENDIF
+         DO ji = fs_2, fs_jpim1           
+            zrhos    = rau0 * ( 1._wp + rhd(ji,jj,1) ) * tmask(ji,jj,1)
+            zthermal = rab_n(ji,jj,1,jp_tem) / ( rcp * zrhos + epsln )
+            zbeta    = rab_n(ji,jj,1,jp_sal)
+            zhalin   = zbeta * tsn(ji,jj,1,jp_sal) * rcs
+            !
             ! Radiative surface buoyancy force
             zBosol(ji,jj) = grav * zthermal * qsr(ji,jj)
@@ -435,6 +405,6 @@
             ws0(ji,jj) = - ( ( emp(ji,jj)-rnf(ji,jj) ) * tsn(ji,jj,1,jp_sal)                          &
                &             + sfx(ji,jj)                                     ) * rcs * tmask(ji,jj,1) 
-         ENDDO
-      ENDDO
+         END DO
+      END DO
 
       zflageos = 0.5 + SIGN( 0.5, nn_eos - 1. ) 
@@ -447,6 +417,6 @@
             ! Friction velocity (zustar), at T-point : LMD94 eq. 2
             zustar(ji,jj) = SQRT( taum(ji,jj) / ( zrhos +  epsln ) )
-         ENDDO
-      ENDDO
+         END DO
+      END DO
 
 !CDIR NOVERRCHK  
@@ -1270,6 +1240,6 @@
          ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
 !!bug gm jpttdzdf ==> jpttkpp
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_trd_zdf, ztrdt )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_trd_zdf, ztrds )
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_zdf, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_zdf, ztrds )
          DEALLOCATE( ztrdt )      ;     DEALLOCATE( ztrds )
       ENDIF
@@ -1340,5 +1310,5 @@
          IF( l_trdtrc ) THEN         ! save the non-local tracer flux trends for diagnostic
             ztrtrd(:,:,:) = tra(:,:,:,jn) - ztrtrd(:,:,:)
-            CALL trd_tra( kt, 'TRC', jn, jptra_trd_zdf, ztrtrd(:,:,:) )
+            CALL trd_tra( kt, 'TRC', jn, jptra_zdf, ztrtrd(:,:,:) )
          ENDIF
          !
@@ -1375,4 +1345,5 @@
       !!----------------------------------------------------------------------
       INTEGER  ::   ji, jj, jk     ! dummy loop indices
+      INTEGER  ::   ios            ! local integer
 #if ! defined key_kppcustom
       INTEGER  ::   jm             ! dummy loop indices     
@@ -1382,5 +1353,4 @@
       REAL(wp) ::   zustar, zucube, zustvk, zeta, zehat   ! tempory scalars
 #endif
-      INTEGER  ::   ios            ! Local integer output status for namelist read
       REAL(wp) ::   zhbf           ! tempory scalars
       LOGICAL  ::   ll_kppcustom   ! 1st ocean level taken as surface layer
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfmxl.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfmxl.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfmxl.F90	(revision 4946)
@@ -6,4 +6,6 @@
    !! History :  1.0  ! 2003-08  (G. Madec)  original code
    !!            3.2  ! 2009-07  (S. Masson, G. Madec)  IOM + merge of DO-loop
+   !!            3.7  ! 2012-03  (G. Madec)  make public the density criteria for trdmxl 
+   !!             -   ! 2014-02  (F. Roquet)  mixed layer depth calculated using N2 instead of rhop 
    !!----------------------------------------------------------------------
    !!   zdf_mxl      : Compute the turbocline and mixed layer depths.
@@ -14,4 +16,5 @@
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
+   USE phycst          ! physical constants
    USE iom             ! I/O library
    USE lib_mpp         ! MPP library
@@ -25,11 +28,11 @@
    PUBLIC   zdf_mxl       ! called by step.F90
 
-   REAL(wp), PUBLIC ::   rho_c = 0.01_wp    ! density criterion for mixed layer depth
-   REAL(wp), PUBLIC ::   avt_c = 5.e-4_wp   ! Kz criterion for the turbocline depth
-
    INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   nmln    !: number of level in the mixed layer (used by TOP)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmld    !: mixing layer depth (turbocline)      [m]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmlp    !: mixed layer depth  (rho=rho0+zdcrit) [m]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmlpt   !: mixed layer depth at t-points        [m]
+
+   REAL(wp), PUBLIC ::   rho_c = 0.01_wp    !: density criterion for mixed layer depth
+   REAL(wp)         ::   avt_c = 5.e-4_wp   ! Kz criterion for the turbocline depth
 
    !! * Substitutions
@@ -70,13 +73,14 @@
       !!      eddy diffusivity coefficient (resulting from the vertical physics
       !!      alone, not the isopycnal part, see trazdf.F) fall below a given
-      !!      value defined locally (avt_c here taken equal to 5 cm/s2)
+      !!      value defined locally (avt_c here taken equal to 5 cm/s2 by default)
       !!
       !! ** Action  :   nmln, hmld, hmlp, hmlpt
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
-      !!
-      INTEGER  ::   ji, jj, jk          ! dummy loop indices
-      INTEGER  ::   iikn, iiki          ! temporary integer within a do loop
-      INTEGER, POINTER, DIMENSION(:,:) ::   imld                ! temporary workspace
+      !
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   iikn, iiki, ikt, imkt   ! local integer
+      REAL(wp) ::   zN2_c        ! local scalar
+      INTEGER, POINTER, DIMENSION(:,:) ::   imld   ! 2D workspace
       !!----------------------------------------------------------------------
       !
@@ -94,11 +98,24 @@
 
       ! w-level of the mixing and mixed layers
-      nmln(:,:) = mbkt(:,:) + 1        ! Initialization to the number of w ocean point
-      imld(:,:) = mbkt(:,:) + 1
-      DO jk = jpkm1, nlb10, -1         ! from the bottom to nlb10
+      nmln(:,:)  = nlb10               ! Initialization to the number of w ocean point
+      hmlp(:,:)  = 0._wp               ! here hmlp used as a dummy variable, integrating vertically N^2
+      zN2_c = grav * rho_c * r1_rau0   ! convert density criteria into N^2 criteria
+      DO jk = nlb10, jpkm1
+         DO jj = 1, jpj                ! Mixed layer level: w-level 
+            DO ji = 1, jpi
+               ikt = mbkt(ji,jj)
+               hmlp(ji,jj) = hmlp(ji,jj) + MAX( rn2b(ji,jj,jk) , 0._wp ) * fse3w(ji,jj,jk)
+               IF( hmlp(ji,jj) < zN2_c )   nmln(ji,jj) = MIN( jk , ikt ) + 1   ! Mixed layer level
+            END DO
+         END DO
+      END DO
+      !
+      ! w-level of the turbocline
+      imld(:,:) = mbkt(:,:) + 1        ! Initialization to the number of w ocean point
+      DO jk = jpkm1, nlb10, -1         ! from the bottom to nlb10 
          DO jj = 1, jpj
             DO ji = 1, jpi
-               IF( rhop(ji,jj,jk) > rhop(ji,jj,MAX(mikt(ji,jj),nla10)) + rho_c )   nmln(ji,jj) = MAX(jk,mikt(ji,jj))      ! Mixed layer
-               IF( avt (ji,jj,jk) < avt_c                     )   imld(ji,jj) = MAX(mikt(ji,jj),jk)      ! Turbocline 
+               imkt = mikt(ji,jj)
+               IF( avt (ji,jj,jk) < avt_c )   imld(ji,jj) = MAX( imkt, jk )      ! Turbocline 
             END DO
          END DO
@@ -109,7 +126,8 @@
             iiki = imld(ji,jj)
             iikn = nmln(ji,jj)
-            hmld (ji,jj) = ( fsdepw(ji,jj,iiki  ) - fsdepw(ji,jj,mikt(ji,jj) )            ) * ssmask(ji,jj)    ! Turbocline depth 
-            hmlp (ji,jj) = ( fsdepw(ji,jj,iikn  ) - fsdepw(ji,jj,MAX(mikt(ji,jj),nla10) ) ) * ssmask(ji,jj)    ! Mixed layer depth
-            hmlpt(ji,jj) = ( fsdept(ji,jj,iikn-1) - fsdepw(ji,jj,mikt(ji,jj) )            ) * ssmask(ji,jj)    ! depth of the last T-point inside the mixed layer
+            imkt = mikt(ji,jj)
+            hmld (ji,jj) = ( fsdepw(ji,jj,iiki  ) - fsdepw(ji,jj,imkt )            )   * ssmask(ji,jj)    ! Turbocline depth 
+            hmlp (ji,jj) = ( fsdepw(ji,jj,iikn  ) - fsdepw(ji,jj,MAX( imkt,nla10 ) ) ) * ssmask(ji,jj)    ! Mixed layer depth
+            hmlpt(ji,jj) = ( fsdept(ji,jj,iikn-1) - fsdepw(ji,jj,imkt )            )   * ssmask(ji,jj)    ! depth of the last T-point inside the mixed layer
          END DO
       END DO
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 4946)
@@ -295,20 +295,12 @@
          END DO
          !                               ! finite LC depth
-# if defined key_vectopt_loop
-         DO jj = 1, 1
-            DO ji = 1, jpij   ! vector opt. (forced unrolling)
-# else
          DO jj = 1, jpj 
             DO ji = 1, jpi
-# endif
                zhlc(ji,jj) = fsdepw(ji,jj,imlc(ji,jj))
             END DO
          END DO
          zcof = 0.016 / SQRT( zrhoa * zcdrag )
-!CDIR NOVERRCHK
          DO jk = 2, jpkm1         !* TKE Langmuir circulation source term added to en
-!CDIR NOVERRCHK
             DO jj = 2, jpjm1
-!CDIR NOVERRCHK
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   zus  = zcof * SQRT( taum(ji,jj) )           ! Stokes drift
@@ -399,5 +391,5 @@
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   en(ji,jj,jk) = en(ji,jj,jk) + rn_efr * en(ji,jj,1) * EXP( -fsdepw(ji,jj,jk) / htau(ji,jj) )   &
-                     &                                               * ( 1._wp - fr_i(ji,jj) )  * tmask(ji,jj,jk) * tmask(ji,jj,1)
+                     &                                 * ( 1._wp - fr_i(ji,jj) )  * tmask(ji,jj,jk) * tmask(ji,jj,1)
                END DO
             END DO
@@ -408,5 +400,5 @@
                jk = nmln(ji,jj)
                en(ji,jj,jk) = en(ji,jj,jk) + rn_efr * en(ji,jj,1) * EXP( -fsdepw(ji,jj,jk) / htau(ji,jj) )   &
-                  &                                               * ( 1._wp - fr_i(ji,jj) )  * tmask(ji,jj,jk) * tmask(ji,jj,1)
+                  &                                 * ( 1._wp - fr_i(ji,jj) )  * tmask(ji,jj,jk) * tmask(ji,jj,1)
             END DO
          END DO
@@ -424,5 +416,5 @@
                   zdif = rhftau_scl * MAX( 0._wp, zdif + rhftau_add )  ! apply some modifications...
                   en(ji,jj,jk) = en(ji,jj,jk) + zbbrau * zdif * EXP( -fsdepw(ji,jj,jk) / htau(ji,jj) )   &
-                     &                                        * ( 1._wp - fr_i(ji,jj) ) * tmask(ji,jj,jk) * tmask(ji,jj,jk-1) * tmask(ji,jj,1)
+                     &                        * ( 1._wp - fr_i(ji,jj) ) * tmask(ji,jj,jk) * tmask(ji,jj,jk-1) * tmask(ji,jj,1)
                END DO
             END DO
@@ -734,10 +726,8 @@
       !
       !                               !* Check of some namelist values
-      IF( nn_mxl  < 0  .OR.  nn_mxl  > 3 )   CALL ctl_stop( 'bad flag: nn_mxl is  0, 1 or 2 ' )
-      IF( nn_pdl  < 0  .OR.  nn_pdl  > 1 )   CALL ctl_stop( 'bad flag: nn_pdl is  0 or 1    ' )
-      IF( nn_htau < 0  .OR.  nn_htau > 1 )   CALL ctl_stop( 'bad flag: nn_htau is 0, 1 or 2 ' )
-#if ! key_coupled
-      IF( nn_etau == 3 )   CALL ctl_stop( 'nn_etau == 3 : HF taum only known in coupled mode' )
-#endif
+      IF( nn_mxl  < 0   .OR.  nn_mxl  > 3 )   CALL ctl_stop( 'bad flag: nn_mxl is  0, 1 or 2 ' )
+      IF( nn_pdl  < 0   .OR.  nn_pdl  > 1 )   CALL ctl_stop( 'bad flag: nn_pdl is  0 or 1    ' )
+      IF( nn_htau < 0   .OR.  nn_htau > 1 )   CALL ctl_stop( 'bad flag: nn_htau is 0, 1 or 2 ' )
+      IF( nn_etau == 3 .AND. .NOT. lk_cpl )   CALL ctl_stop( 'nn_etau == 3 : HF taum only known in coupled mode' )
 
       IF( ln_mxl0 ) THEN
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 4946)
@@ -42,5 +42,4 @@
    !!----------------------------------------------------------------------
    USE step_oce        ! module used in the ocean time stepping module
-   USE sbc_oce         ! surface boundary condition: ocean
    USE cla             ! cross land advection               (tra_cla routine)
    USE domcfg          ! domain configuration               (dom_cfg routine)
@@ -51,7 +50,7 @@
 #endif
    USE tideini         ! tidal components initialization   (tide_ini routine)
-   USE bdyini          ! open boundary cond. initialization (bdy_init routine)
-   USE bdydta          ! open boundary cond. initialization (bdy_dta_init routine)
-   USE bdytides        ! open boundary cond. initialization (bdytide_init routine)
+   USE bdyini          ! open boundary cond. setting       (bdy_init routine)
+   USE bdydta          ! open boundary cond. setting   (bdy_dta_init routine)
+   USE bdytides        ! open boundary cond. setting   (bdytide_init routine)
    USE istate          ! initial state setting          (istate_init routine)
    USE ldfdyn          ! lateral viscosity setting      (ldfdyn_init routine)
@@ -59,5 +58,5 @@
    USE zdfini          ! vertical physics setting          (zdf_init routine)
    USE phycst          ! physical constant                  (par_cst routine)
-   USE trdmod          ! momentum/tracers trends       (trd_mod_init routine)
+   USE trdini          ! dyn/tra trends initialization     (trd_init routine)
    USE asminc          ! assimilation increments     
    USE asmbkg          ! writing out state trajectory
@@ -69,9 +68,5 @@
    USE icbini          ! handle bergs, initialisation
    USE icbstp          ! handle bergs, calving, themodynamics and transport
-#if defined key_oasis3
    USE cpl_oasis3      ! OASIS3 coupling
-#elif defined key_oasis4
-   USE cpl_oasis4      ! OASIS4 coupling (not working)
-#endif
    USE c1d             ! 1D configuration
    USE step_c1d        ! Time stepping loop for the 1D configuration
@@ -121,5 +116,4 @@
       !!----------------------------------------------------------------------
       !
-
 #if defined key_agrif
       CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
@@ -139,5 +133,4 @@
 # endif
 #endif
-
       ! check that all process are still there... If some process have an error,
       ! they will never enter in step and other processes will wait until the end of the cpu time!
@@ -166,5 +159,4 @@
 
          DO WHILE ( istp <= nitend .AND. nstop == 0 )
-
 #if defined key_agrif
             CALL Agrif_Step( stp )           ! AGRIF: time stepping
@@ -172,5 +164,4 @@
             CALL stp( istp )                 ! standard time stepping
 #endif
-
             istp = istp + 1
             IF( lk_mpp )   CALL mpp_max( nstop )
@@ -201,15 +192,14 @@
       !
       CALL nemo_closefile
+      !
 #if defined key_iomput
       CALL xios_finalize                ! end mpp communications with xios
-# if defined key_oasis3 || defined key_oasis4
-      CALL cpl_prism_finalize           ! end coupling and mpp communications with OASIS
-# endif
+      IF( lk_cpl ) CALL cpl_finalize    ! end coupling and mpp communications with OASIS
 #else
-# if defined key_oasis3 || defined key_oasis4
-      CALL cpl_prism_finalize           ! end coupling and mpp communications with OASIS
-# else
-      IF( lk_mpp )   CALL mppstop       ! end mpp communications
-# endif
+      IF( lk_cpl ) THEN 
+         CALL cpl_finalize              ! end coupling and mpp communications with OASIS
+      ELSE
+         IF( lk_mpp )   CALL mppstop    ! end mpp communications
+      ENDIF
 #endif
       !
@@ -227,6 +217,6 @@
       INTEGER ::   ios
       CHARACTER(len=80), DIMENSION(16) ::   cltxt
-      !!
-      NAMELIST/namctl/ ln_ctl, nn_print, nn_ictls, nn_ictle,   &
+      !
+      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
          &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
          &             nn_bench, nn_timing
@@ -281,22 +271,22 @@
 #if defined key_iomput
       IF( Agrif_Root() ) THEN
-# if defined key_oasis3 || defined key_oasis4
-         CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
-         CALL xios_initialize( "oceanx",local_comm=ilocal_comm )
-# else
-         CALL  xios_initialize( "nemo",return_comm=ilocal_comm )
-# endif
+         IF( lk_cpl ) THEN
+            CALL cpl_init( ilocal_comm )                               ! nemo local communicator given by oasis
+            CALL xios_initialize( "oceanx",local_comm=ilocal_comm )    ! send nemo communicator to xios
+         ELSE
+            CALL  xios_initialize( "nemo",return_comm=ilocal_comm )    ! nemo local communicator given by xios
+         ENDIF
       ENDIF
       narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection
 #else
-# if defined key_oasis3 || defined key_oasis4
-      IF( Agrif_Root() ) THEN
-         CALL cpl_prism_init( ilocal_comm )                 ! nemo local communicator given by oasis
-      ENDIF
-      narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection (control print return in cltxt)
-# else
-      ilocal_comm = 0
-      narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop )                 ! Nodes selection (control print return in cltxt)
-# endif
+      IF( lk_cpl ) THEN
+         IF( Agrif_Root() ) THEN
+            CALL cpl_init( ilocal_comm )                       ! nemo local communicator given by oasis
+         ENDIF
+         narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection (control print return in cltxt)
+      ELSE
+         ilocal_comm = 0
+         narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop )                ! Nodes selection (control print return in cltxt)
+      ENDIF
 #endif
       narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
@@ -393,8 +383,8 @@
       IF( lk_tide       )   CALL    tide_init( nit000 )    ! Initialisation of the tidal harmonics
 
-      IF( lk_bdy        )   CALL      bdy_init  ! Open boundaries initialisation
-      IF( lk_bdy        )   CALL  bdy_dta_init  ! Open boundaries initialisation of external data arrays
+      IF( lk_bdy        )   CALL     bdy_init   ! Open boundaries initialisation
+      IF( lk_bdy        )   CALL bdy_dta_init   ! Open boundaries initialisation of external data arrays
       IF( lk_bdy .AND. lk_tide )   &
-         &                  CALL  bdytide_init  ! Open boundaries initialisation of tidal harmonic forcing
+         &                  CALL bdytide_init   ! Open boundaries initialisation of tidal harmonic forcing
 
                             CALL dyn_nept_init  ! simplified form of Neptune effect
@@ -406,9 +396,6 @@
                             CALL     sbc_init   ! Forcings : surface module
       !                                         ! Vertical physics
-
                             CALL     zdf_init      ! namelist read
-
                             CALL zdf_bfr_init      ! bottom friction
-
       IF( lk_zdfric     )   CALL zdf_ric_init      ! Richardson number dependent Kz
       IF( lk_zdftke     )   CALL zdf_tke_init      ! TKE closure scheme
@@ -449,7 +436,5 @@
                             CALL     trc_init
 #endif
-      !
- 
-                                            ! Diagnostics
+      !                                     ! Diagnostics
       IF( lk_floats     )   CALL     flo_init   ! drifting Floats
       IF( lk_diaar5     )   CALL dia_ar5_init   ! ar5 diag
@@ -457,9 +442,10 @@
       IF( lk_diadct     )   CALL dia_dct_init   ! Sections tranports
                             CALL dia_hsb_init   ! heat content, salt content and volume budgets
-                            CALL trd_mod_init   ! Mixed-layer/Vorticity/Integral constraints trends
+                            CALL     trd_init   ! Mixed-layer/Vorticity/Integral constraints trends
       IF( lk_diaobs     ) THEN                  ! Observation & model comparison
                             CALL dia_obs_init            ! Initialize observational data
                             CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
       ENDIF
+
       !                                     ! Assimilation increments
       IF( lk_asminc     )   CALL asm_inc_init   ! Initialize assimilation increments
@@ -659,5 +645,5 @@
       !! ** Method  :
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
+      INTEGER, INTENT(in) ::   num_pes   ! The number of MPI processes we have
       !
       INTEGER, PARAMETER :: nfactmax = 20
@@ -668,9 +654,9 @@
       INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
       !!----------------------------------------------------------------------
-
+      !
       ierr = 0
-
+      !
       CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
-
+      !
       IF( nfact <= 1 ) THEN
          WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
@@ -714,5 +700,5 @@
       INTEGER, PARAMETER :: ntest = 14
       INTEGER :: ilfax(ntest)
-
+      !
       ! lfax contains the set of allowed factors.
       data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
@@ -765,4 +751,5 @@
 
 #if defined key_mpp_mpi
+
    SUBROUTINE nemo_northcomms
       !!======================================================================
@@ -839,4 +826,5 @@
    END SUBROUTINE nemo_northcomms
 #endif
+
    !!======================================================================
 END MODULE nemogcm
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/oce.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/oce.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/oce.F90	(revision 4946)
@@ -20,14 +20,13 @@
    !! dynamics and tracer fields                            ! before ! now    ! after  ! the after trends becomes the fields
    !! --------------------------                            ! fields ! fields ! trends ! only after tra_zdf and dyn_spg
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   ub   ,  un    , ua     !: i-horizontal velocity        [m/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   vb   ,  vn    , va     !: j-horizontal velocity        [m/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   ua_sv,  va_sv          !: Saved trends (time spliting) [m/s2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::           wn             !: vertical velocity            [m/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   rotb ,  rotn           !: relative vorticity           [s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   hdivb,  hdivn          !: horizontal divergence        [s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   tsb  ,  tsn            !: 4D T-S fields        [Celcius,psu] 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   rn2b ,  rn2            !: brunt-vaisala frequency**2   [s-2]
-   !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  tsa             !: 4D T-S trends fields & work array 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   ub   ,  un    , ua     !: i-horizontal velocity          [m/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   vb   ,  vn    , va     !: j-horizontal velocity          [m/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   ua_sv,  va_sv          !: Saved trends (time spliting)   [m/s2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::           wn             !: vertical velocity              [m/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   rotb ,  rotn           !: relative vorticity             [s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   hdivb,  hdivn          !: horizontal divergence          [s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   tsb  ,  tsn   , tsa    !: 4D T-S fields                  [Celcius,psu] 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   rab_b,  rab_n          !: thermal/haline expansion coef. [Celcius-1,psu-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   rn2b ,  rn2            !: brunt-vaisala frequency**2     [s-2]
    !
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   rhd    !: in situ density anomalie rhd=(rho-rau0)/rau0  [no units]
@@ -70,6 +69,6 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   snwice_fmass       !: time evolution of mass of snow+ice               [Kg/m2/s]
 
-   !! arrays related to penetration of solar fluxes to calculate the heat budget for sea ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   oatte, iatte       !: attenuation coef of the input solar flux [unitless]
+   !! Energy budget of the leads (open water embedded in sea ice)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   fraqsr_1lev        !: fraction of solar net radiation absorbed in the first ocean level [-]
 
    !!----------------------------------------------------------------------
@@ -94,4 +93,5 @@
          &      hdivb(jpi,jpj,jpk)      , hdivn(jpi,jpj,jpk)      ,                             &
          &      tsb  (jpi,jpj,jpk,jpts) , tsn  (jpi,jpj,jpk,jpts) , tsa(jpi,jpj,jpk,jpts) ,     &
+         &      rab_b(jpi,jpj,jpk,jpts) , rab_n(jpi,jpj,jpk,jpts) ,                             &
          &      rn2b (jpi,jpj,jpk)      , rn2  (jpi,jpj,jpk)                              , STAT=ierr(1) )
          !
@@ -117,5 +117,5 @@
       ALLOCATE( snwice_mass(jpi,jpj) , snwice_mass_b(jpi,jpj), snwice_fmass(jpi,jpj) , STAT=ierr(3) )
          !
-      ALLOCATE( iatte(jpi,jpj) , oatte(jpi,jpj) , STAT=ierr(4) )
+      ALLOCATE( fraqsr_1lev(jpi,jpj) , STAT=ierr(4) )
          !
       oce_alloc = MAXVAL( ierr )
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/par_oce.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/par_oce.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/par_oce.F90	(revision 4946)
@@ -94,10 +94,4 @@
 #endif
 
-#if defined key_vectopt_loop
-   LOGICAL, PUBLIC, PARAMETER ::   lk_vopt_loop = .TRUE.   !: vector optimization flag
-#else
-   LOGICAL, PUBLIC, PARAMETER ::   lk_vopt_loop = .FALSE.  !: vector optimization flag
-#endif
-
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/step.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 4946)
@@ -24,5 +24,6 @@
    !!             -   !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase + merge TRC-TRA
    !!            3.4  !  2011-04  (G. Madec, C. Ethe) Merge of dtatem and dtasal
-   !!                 !  2012-07  (J. Simeon, G. Madec. C. Ethe) Online coarsening of outputs
+   !!                 !  2012-07  (J. Simeon, G. Madec, C. Ethe) Online coarsening of outputs
+   !!            3.7  !  2014-04  (F. Roquet, G. Madec) New equations of state
    !!----------------------------------------------------------------------
 
@@ -40,7 +41,7 @@
    !! * Substitutions
 #  include "domzgr_substitute.h90"
-#  include "zdfddm_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+!!gm   #  include "zdfddm_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -107,6 +108,9 @@
       ! Ocean physics update                (ua, va, tsa used as workspace)
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL bn2( tsb, rn2b )        ! before Brunt-Vaisala frequency
-                         CALL bn2( tsn, rn2  )        ! now    Brunt-Vaisala frequency
+      !  THERMODYNAMICS
+                         CALL eos_rab( tsb, rab_b )       ! before local thermal/haline expension ratio at T-points
+                         CALL eos_rab( tsn, rab_n )       ! now    local thermal/haline expension ratio at T-points
+                         CALL bn2    ( tsb, rab_b, rn2b ) ! before Brunt-Vaisala frequency
+                         CALL bn2    ( tsn, rab_n, rn2  ) ! now    Brunt-Vaisala frequency
       !
       !  VERTICAL PHYSICS
@@ -206,5 +210,5 @@
       IF( lk_floats  )   CALL flo_stp( kstp )         ! drifting Floats
       IF( lk_diahth  )   CALL dia_hth( kstp )         ! Thermocline depth (20 degres isotherm depth)
-      IF( lk_diafwb  )   CALL dia_fwb( kstp )         ! Fresh water budget diagnostics
+      IF( .NOT. lk_cpl ) CALL dia_fwb( kstp )         ! Fresh water budget diagnostics
       IF( ln_diaptr  )   CALL dia_ptr( kstp )         ! Poleward TRansports diagnostics
       IF( lk_diadct  )   CALL dia_dct( kstp )         ! Transports
@@ -222,4 +226,5 @@
                          CALL trc_stp( kstp )         ! time-stepping
 #endif
+
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -322,14 +327,4 @@
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Trends                              (ua, va, tsa used as workspace)
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( nstop == 0 ) THEN
-         IF( lk_trddyn     )   CALL trd_dwr( kstp )         ! trends: dynamics
-         IF( lk_trdtra     )   CALL trd_twr( kstp )         ! trends: active tracers
-         IF( lk_trdmld     )   CALL trd_mld( kstp )         ! trends: Mixed-layer
-         IF( lk_trdvor     )   CALL trd_vor( kstp )         ! trends: vorticity budget
-      ENDIF
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! Coupled mode
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/step_oce.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 4946)
@@ -25,5 +25,5 @@
    USE sbcrnf           ! surface boundary condition: runoff variables
    USE sbccpl           ! surface boundary condition: coupled formulation (call send at end of step)
-   USE cpl_oasis3, ONLY : lk_cpl
+   USE sbc_oce          ! surface boundary condition: ocean
    USE sbctide          ! Tide initialisation
 
@@ -84,10 +84,4 @@
 
    USE diawri           ! Standard run outputs             (dia_wri routine)
-   USE trdicp           ! Ocean momentum/tracers trends    (trd_wri routine)
-   USE trdmld           ! mixed-layer trends               (trd_mld routine)
-   USE trdmld_rst       ! restart for mixed-layer trends
-   USE trdmod_oce       ! ocean momentum/tracers trends
-   USE trdmod           ! momentum/tracers trends
-   USE trdvor           ! vorticity budget                 (trd_vor routine)
    USE diaptr           ! poleward transports              (dia_ptr routine)
    USE diadct           ! sections transports              (dia_dct routine)
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/vectopt_loop_substitute.h90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/vectopt_loop_substitute.h90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/OPA_SRC/vectopt_loop_substitute.h90	(revision 4946)
@@ -2,17 +2,17 @@
    !!                   ***  vectopt_loop_substitute  ***
    !!----------------------------------------------------------------------
-   !! ** purpose :   substitute the inner loop starting and inding indices 
-   !!      to allow unrolling of do-loop using CPP macro.
+   !! ** purpose :   substitute the inner loop start/end indices with CPP macro
+   !!                allow unrolling of do-loop (useful with vector processors)
    !!----------------------------------------------------------------------
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
    !! $Id$ 
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 #if defined key_vectopt_loop
-#  define fs_2     1
-#  define fs_jpim1 jpi
+#  define   fs_2       1
+#  define   fs_jpim1   jpi
 #else
-#  define fs_2     2
-#  define fs_jpim1 jpim1
+#  define   fs_2       2
+#  define   fs_jpim1   jpim1
 #endif
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90	(revision 4946)
@@ -166,8 +166,4 @@
       !! note that we need sbc_ssm called first in sbc
       !
-      IF( ln_cpl ) THEN
-         IF( lwp ) WRITE(numout,*) 'Coupled mode not sensible with StandAlone Surface scheme'
-         ln_cpl = .FALSE.
-      ENDIF
       IF( ln_apr_dyn ) THEN
          IF( lwp ) WRITE(numout,*) 'No atmospheric gradient needed with StandAlone Surface scheme'
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/C14b/trcsms_c14b.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/C14b/trcsms_c14b.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/C14b/trcsms_c14b.F90	(revision 4946)
@@ -18,6 +18,6 @@
    USE par_trc       ! TOP parameters
    USE trc           ! TOP variables
-   USE trdmod_oce
-   USE trdmod_trc
+   USE trd_oce
+   USE trdtrc
    USE iom           ! I/O library
 
@@ -302,5 +302,5 @@
       ENDIF
 
-      IF( l_trdtrc )  CALL trd_mod_trc( tra(:,:,:,jpc14), jpc14, jptra_trd_sms, kt )   ! save trends
+      IF( l_trdtrc )  CALL trd_trc( tra(:,:,:,jpc14), jpc14, jptra_sms, kt )   ! save trends
 
       CALL wrk_dealloc( jpi, jpj,      zatmbc14 )
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90	(revision 4946)
@@ -18,6 +18,6 @@
    USE par_trc       ! TOP parameters
    USE trc           ! TOP variables
-   USE trdmod_oce
-   USE trdmod_trc
+   USE trd_oce
+   USE trdtrc
    USE iom           ! I/O library
 
@@ -201,5 +201,5 @@
       IF( l_trdtrc ) THEN
           DO jn = jp_cfc0, jp_cfc1
-            CALL trd_mod_trc( tra(:,:,:,jn), jn, jptra_trd_sms, kt )   ! save trends
+            CALL trd_trc( tra(:,:,:,jn), jn, jptra_sms, kt )   ! save trends
           END DO
       END IF
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcsms_my_trc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcsms_my_trc.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcsms_my_trc.F90	(revision 4946)
@@ -16,6 +16,6 @@
    USE oce_trc         ! Ocean variables
    USE trc             ! TOP variables
-   USE trdmod_oce
-   USE trdmod_trc
+   USE trd_oce
+   USE trdtrc
 
    IMPLICIT NONE
@@ -65,5 +65,5 @@
           DO jn = jp_myt0, jp_myt1
             ztrmyt(:,:,:) = tra(:,:,:,jn)
-            CALL trd_mod_trc( ztrmyt, jn, jptra_trd_sms, kt )   ! save trends
+            CALL trd_trc( ztrmyt, jn, jptra_sms, kt )   ! save trends
           END DO
           CALL wrk_dealloc( jpi, jpj, jpk, ztrmyt )
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zbio.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zbio.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zbio.F90	(revision 4946)
@@ -21,6 +21,6 @@
    USE lbclnk          ! 
    USE prtctl_trc      ! Print control for debbuging
-   USE trdmod_oce
-   USE trdmod_trc
+   USE trd_oce
+   USE trdtrc
    USE iom
    
@@ -457,5 +457,5 @@
       IF( l_trdtrc ) THEN
          DO jl = jp_pcs0_trd, jp_pcs1_trd
-            CALL trd_mod_trc( trbio(:,:,:,jl), jl, kt )   ! handle the trend
+            CALL trd_trc( trbio(:,:,:,jl), jl, kt )   ! handle the trend
          END DO
       ENDIF
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zexp.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zexp.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zexp.F90	(revision 4946)
@@ -22,6 +22,6 @@
    USE lbclnk
    USE prtctl_trc      ! Print control for debbuging
-   USE trdmod_oce
-   USE trdmod_trc
+   USE trd_oce
+   USE trdtrc
    USE iom
 
@@ -164,5 +164,5 @@
          ztrbio(:,:,:) = tra(:,:,:,jpno3) - ztrbio(:,:,:)
          jl = jp_pcs0_trd + 16
-         CALL trd_mod_trc( ztrbio, jl, kt )   ! handle the trend
+         CALL trd_trc( ztrbio, jl, kt )   ! handle the trend
          CALL wrk_dealloc( jpi, jpj, jpk, ztrbio )   ! temporary save of trends
       ENDIF
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zopt.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zopt.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zopt.F90	(revision 4946)
@@ -128,5 +128,5 @@
               IF( etot(ji,jj,jk) >= zpar100(ji,jj) )   neln(ji,jj) = jk + 1 
               !                                       ! nb. this is to ensure compatibility with
-              !                                       ! nmld_trc definition in trd_mld_trc_zint
+              !                                       ! nmld_trc definition in trd_mxl_trc_zint
            END DO
          END DO
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zsed.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zsed.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zsed.F90	(revision 4946)
@@ -18,6 +18,6 @@
    USE sms_pisces
    USE lbclnk
-   USE trdmod_oce
-   USE trdmod_trc
+   USE trd_oce
+   USE trdtrc
    USE iom
    USE prtctl_trc      ! Print control for debbuging
@@ -128,5 +128,5 @@
          ztrbio(:,:,:) = tra(:,:,:,jpdet) - ztrbio(:,:,:)
          jl = jp_pcs0_trd + 7
-         CALL trd_mod_trc( ztrbio, jl, kt )   ! handle the trend
+         CALL trd_trc( ztrbio, jl, kt )   ! handle the trend
          CALL wrk_dealloc( jpi, jpj, jpk, ztrbio )
       ENDIF
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zsms.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zsms.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zsms.F90	(revision 4946)
@@ -20,8 +20,8 @@
    USE p2zsed
    USE p2zexp
-   USE trdmod_oce
-   USE trdmod_trc_oce
-   USE trdmod_trc
-   USE trdmld_trc
+   USE trd_oce
+   USE trdtrc_oce
+   USE trdtrc
+   USE trdmxl_trc
 
    IMPLICIT NONE
@@ -61,9 +61,9 @@
       IF( l_trdtrc ) THEN
          DO jn = jp_pcs0, jp_pcs1
-           CALL trd_mod_trc( tra(:,:,:,jn), jn, jptra_trd_sms, kt )   ! save trends
+           CALL trd_trc( tra(:,:,:,jn), jn, jptra_sms, kt )   ! save trends
          END DO
       END IF
 
-      IF( lk_trdmld_trc )  CALL trd_mld_bio( kt )   ! trends: Mixed-layer
+      IF( lk_trdmxl_trc )  CALL trd_mxl_bio( kt )   ! trends: Mixed-layer
       !
       IF ( lwm .AND. kt == nittrc000 ) CALL FLUSH    ( numonp )     ! flush output namelist PISCES
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zopt.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zopt.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zopt.F90	(revision 4946)
@@ -205,5 +205,5 @@
               IF( etot(ji,jj,jk) * tmask(ji,jj,jk) >= 0.0043 * qsr(ji,jj) )  THEN
                  neln(ji,jj) = jk+1                    ! Euphotic level : 1rst T-level strictly below Euphotic layer
-                 !                                     ! nb: ensure the compatibility with nmld_trc definition in trd_mld_trc_zint
+                 !                                     ! nb: ensure the compatibility with nmld_trc definition in trd_mxl_trc_zint
                  heup(ji,jj) = fsdepw(ji,jj,jk+1)      ! Euphotic layer depth
               ENDIF
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsms.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsms.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsms.F90	(revision 4946)
@@ -11,5 +11,5 @@
    !!   'key_pisces'                                       PISCES bio-model
    !!----------------------------------------------------------------------
-   !!   p4zsms        :  Time loop of passive tracers sms
+   !!   p4zsms         :  Time loop of passive tracers sms
    !!----------------------------------------------------------------------
    USE oce_trc         !  shared variables between ocean and passive tracers
@@ -25,6 +25,6 @@
    USE p4zint          !  time interpolation
    USE iom             !  I/O manager
-   USE trdmod_oce      !  Ocean trends variables
-   USE trdmod_trc      !  TOP trends variables
+   USE trd_oce         !  Ocean trends variables
+   USE trdtrc          !  TOP trends variables
    USE sedmodel        !  Sediment model
    USE prtctl_trc      !  print control for debugging
@@ -33,6 +33,6 @@
    PRIVATE
 
-   PUBLIC   p4z_sms_init    ! called in p4zsms.F90
-   PUBLIC   p4z_sms    ! called in p4zsms.F90
+   PUBLIC   p4z_sms_init   ! called in p4zsms.F90
+   PUBLIC   p4z_sms        ! called in p4zsms.F90
 
    REAL(wp) :: alkbudget, no3budget, silbudget, ferbudget
@@ -146,5 +146,5 @@
             jl = jn + jp_pcs0 - 1
              ztrdpis(:,:,:,jn) = ztrdpis(:,:,:,jn) + tra(:,:,:,jl)
-             CALL trd_mod_trc( ztrdpis(:,:,:,jn), jn, jptra_trd_sms, kt )   ! save trends
+             CALL trd_trc( ztrdpis(:,:,:,jn), jn, jptra_sms, kt )   ! save trends
           END DO
           CALL wrk_dealloc( jpi, jpj, jpk, jp_pisces, ztrdpis ) 
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/trcnam_pisces.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/trcnam_pisces.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/PISCES/trcnam_pisces.F90	(revision 4946)
@@ -19,5 +19,5 @@
    USE trc             ! TOP variables
    USE sms_pisces      ! sms trends
-   USE trdmod_trc_oce
+   USE trdtrc_oce
    USE iom             ! I/O manager
 
@@ -123,5 +123,5 @@
 #if defined key_pisces_reduced
 
-      IF( ( .NOT.lk_iomput .AND. ln_diabio ) .OR. lk_trdmld_trc ) THEN
+      IF( ( .NOT.lk_iomput .AND. ln_diabio ) .OR. lk_trdmxl_trc ) THEN
          !
          ! Namelist nampisdbi
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcbbl.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcbbl.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcbbl.F90	(revision 4946)
@@ -25,5 +25,5 @@
    USE trabbl              ! 
    USE prtctl_trc          ! Print control for debbuging
-   USE trdmod_oce
+   USE trd_oce
    USE trdtra
 
@@ -93,5 +93,5 @@
         DO jn = 1, jptra
            ztrtrd(:,:,:,jn) = tra(:,:,:,jn) - ztrtrd(:,:,:,jn)
-           CALL trd_tra( kt, 'TRC', jn, jptra_trd_bbl, ztrtrd(:,:,:,jn) )
+           CALL trd_tra( kt, 'TRC', jn, jptra_bbl, ztrtrd(:,:,:,jn) )
         END DO
         CALL wrk_dealloc( jpi, jpj, jpk, jptra, ztrtrd ) ! temporary save of trends
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcdmp.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcdmp.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcdmp.F90	(revision 4946)
@@ -23,5 +23,5 @@
    USE prtctl_trc      ! Print control for debbuging
    USE trdtra
-   USE trdmod_oce
+   USE trd_oce
 
    IMPLICIT NONE
@@ -75,5 +75,5 @@
       !! ** Action  : - update the tracer trends tra with the newtonian 
       !!                damping trends.
-      !!              - save the trends ('key_trdmld_trc')
+      !!              - save the trends ('key_trdmxl_trc')
       !!----------------------------------------------------------------------
       !!
@@ -151,5 +151,5 @@
             IF( l_trdtrc ) THEN
                ztrtrd(:,:,:) = tra(:,:,:,jn) -  ztrtrd(:,:,:)
-               CALL trd_tra( kt, 'TRC', jn, jptra_trd_dmp, ztrtrd )
+               CALL trd_tra( kt, 'TRC', jn, jptra_dmp, ztrtrd )
             END IF
             !                                                       ! ===========
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcldf.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcldf.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcldf.F90	(revision 4946)
@@ -25,5 +25,5 @@
    USE traldf_iso_grif ! lateral mixing          (tra_ldf_iso_grif routine)
    USE traldf_lap      ! lateral mixing            (tra_ldf_lap routine)
-   USE trdmod_oce
+   USE trd_oce
    USE trdtra
    USE prtctl_trc      ! Print control
@@ -105,5 +105,5 @@
         DO jn = 1, jptra
            ztrtrd(:,:,:,jn) = tra(:,:,:,jn) - ztrtrd(:,:,:,jn)
-           CALL trd_tra( kt, 'TRC', jn, jptra_trd_ldf, ztrtrd(:,:,:,jn) )
+           CALL trd_tra( kt, 'TRC', jn, jptra_ldf, ztrtrd(:,:,:,jn) )
         END DO
         CALL wrk_dealloc( jpi, jpj, jpk, jptra, ztrtrd )
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 4946)
@@ -30,5 +30,5 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE prtctl_trc      ! Print control for debbuging
-   USE trdmod_oce
+   USE trd_oce
    USE trdtra
    USE tranxt
@@ -148,5 +148,5 @@
                zfact = 1.e0 / r2dt(jk)  
                ztrdt(:,:,jk,jn) = ( trb(:,:,jk,jn) - ztrdt(:,:,jk,jn) ) * zfact 
-               CALL trd_tra( kt, 'TRC', jn, jptra_trd_atf, ztrdt )
+               CALL trd_tra( kt, 'TRC', jn, jptra_atf, ztrdt )
             END DO
          END DO
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcrad.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcrad.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcrad.F90	(revision 4946)
@@ -15,5 +15,5 @@
    USE oce_trc             ! ocean dynamics and tracers variables
    USE trc                 ! ocean passive tracers variables
-   USE trdmod_oce
+   USE trd_oce
    USE trdtra
    USE prtctl_trc          ! Print control for debbuging
@@ -156,6 +156,6 @@
                ztrtrdb(:,:,:) = ( ptrb(:,:,:,jn) - ztrtrdb(:,:,:) ) * zs2rdt
                ztrtrdn(:,:,:) = ( ptrn(:,:,:,jn) - ztrtrdn(:,:,:) ) * zs2rdt 
-               CALL trd_tra( kt, 'TRC', jn, jptra_trd_radb, ztrtrdb )       ! Asselin-like trend handling
-               CALL trd_tra( kt, 'TRC', jn, jptra_trd_radn, ztrtrdn )       ! standard     trend handling
+               CALL trd_tra( kt, 'TRC', jn, jptra_radb, ztrtrdb )       ! Asselin-like trend handling
+               CALL trd_tra( kt, 'TRC', jn, jptra_radn, ztrtrdn )       ! standard     trend handling
               !
             ENDIF
@@ -187,6 +187,6 @@
                ztrtrdb(:,:,:) = ( ptrb(:,:,:,jn) - ztrtrdb(:,:,:) ) * zs2rdt
                ztrtrdn(:,:,:) = ( ptrn(:,:,:,jn) - ztrtrdn(:,:,:) ) * zs2rdt 
-               CALL trd_tra( kt, 'TRC', jn, jptra_trd_radb, ztrtrdb )       ! Asselin-like trend handling
-               CALL trd_tra( kt, 'TRC', jn, jptra_trd_radn, ztrtrdn )       ! standard     trend handling
+               CALL trd_tra( kt, 'TRC', jn, jptra_radb, ztrtrdb )       ! Asselin-like trend handling
+               CALL trd_tra( kt, 'TRC', jn, jptra_radn, ztrtrdn )       ! standard     trend handling
               !
             ENDIF
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 4946)
@@ -19,5 +19,5 @@
    USE trc             ! ocean  passive tracers variables
    USE prtctl_trc      ! Print control for debbuging
-   USE trdmod_oce
+   USE trd_oce
    USE trdtra
 
@@ -104,5 +104,5 @@
          IF( l_trdtrc ) THEN
             ztrtrd(:,:,:) = tra(:,:,:,jn) - ztrtrd(:,:,:)
-            CALL trd_tra( kt, 'TRC', jn, jptra_trd_nsr, ztrtrd )
+            CALL trd_tra( kt, 'TRC', jn, jptra_nsr, ztrtrd )
          END IF
          !                                                       ! ===========
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90	(revision 4946)
@@ -19,5 +19,5 @@
    USE trazdf_exp      ! vertical diffusion: explicit (tra_zdf_exp     routine)
    USE trazdf_imp      ! vertical diffusion: implicit (tra_zdf_imp     routine)
-   USE trdmod_oce
+   USE trd_oce
    USE trdtra
    USE prtctl_trc      ! Print control
@@ -106,5 +106,5 @@
                ztrtrd(:,:,jk,jn) = ( ( tra(:,:,jk,jn) - trb(:,:,jk,jn) ) / r2dt(jk) ) - ztrtrd(:,:,jk,jn)
             END DO
-            CALL trd_tra( kt, 'TRC', jn, jptra_trd_zdf, ztrtrd(:,:,:,jn) )
+            CALL trd_tra( kt, 'TRC', jn, jptra_zdf, ztrtrd(:,:,:,jn) )
          END DO
          CALL wrk_dealloc( jpi, jpj, jpk, jptra, ztrtrd )
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdmld_trc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdmld_trc.F90	(revision 4944)
+++ 	(revision )
@@ -1,1437 +1,0 @@
-MODULE trdmld_trc
-   !!======================================================================
-   !!                       ***  MODULE  trdmld_trc  ***
-   !! Ocean diagnostics:  mixed layer passive tracer trends 
-   !!======================================================================
-   !! History :  9.0  !  06-08  (C. Deltel)  Original code (from trdmld.F90)
-   !!                 !  07-04  (C. Deltel)  Bug fix : add trcrad trends
-   !!                 !  07-06  (C. Deltel)  key_gyre : do not call lbc_lnk
-   !!----------------------------------------------------------------------
-#if   defined key_top && ( defined key_trdmld_trc   ||   defined key_esopa )
-   !!----------------------------------------------------------------------
-   !!   'key_trdmld_trc'                      mixed layer trend diagnostics
-   !!----------------------------------------------------------------------
-   !!   trd_mld_trc      : passive tracer cumulated trends averaged over ML
-   !!   trd_mld_trc_zint : passive tracer trends vertical integration
-   !!   trd_mld_trc_init : initialization step
-   !!----------------------------------------------------------------------
-   USE trc               ! tracer definitions (trn, trb, tra, etc.)
-   USE trc_oce, ONLY :   nn_dttrc  ! frequency of step on passive tracers
-   USE dom_oce           ! domain definition
-   USE zdfmxl  , ONLY : nmln ! number of level in the mixed layer
-   USE zdf_oce , ONLY : avt  ! vert. diffusivity coef. at w-point for temp  
-# if defined key_zdfddm   
-   USE zdfddm  , ONLY : avs  ! salinity vertical diffusivity coeff. at w-point
-# endif
-   USE trcnam_trp        ! passive tracers transport namelist variables
-   USE trdmod_trc_oce    ! definition of main arrays used for trends computations
-   USE in_out_manager    ! I/O manager
-   USE dianam            ! build the name of file (routine)
-   USE ldfslp            ! iso-neutral slopes 
-   USE ioipsl            ! NetCDF library
-   USE lbclnk            ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp           ! MPP library
-   USE trdmld_trc_rst    ! restart for diagnosing the ML trends
-   USE prtctl            ! print control
-   USE sms_pisces        ! PISCES bio-model
-   USE wrk_nemo          ! Memory allocation
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC trd_mld_trc
-   PUBLIC trd_mld_trc_alloc
-   PUBLIC trd_mld_bio
-   PUBLIC trd_mld_trc_init
-   PUBLIC trd_mld_trc_zint
-   PUBLIC trd_mld_bio_zint
-
-   CHARACTER (LEN=40) ::  clhstnam                                ! name of the trends NetCDF file
-   INTEGER ::   nmoymltrd
-   INTEGER, ALLOCATABLE, SAVE, DIMENSION(:) ::   ndextrd1
-   INTEGER, DIMENSION(jptra) ::   nidtrd, nh_t
-   INTEGER ::   ndimtrd1                        
-   INTEGER, SAVE ::  ionce, icount
-#if defined key_pisces_reduced
-   INTEGER ::   nidtrdbio, nh_tb
-   INTEGER, SAVE ::  ioncebio, icountbio
-   INTEGER, SAVE ::   nmoymltrdbio
-#endif
-   LOGICAL :: llwarn  = .TRUE.                                    ! this should always be .TRUE.
-   LOGICAL :: lldebug = .TRUE.
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  ztmltrd2   !
-#if defined key_pisces_reduced
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  ztmltrdbio2  ! only needed for mean diagnostics in trd_mld_bio()
-#endif
-
-   !! * Substitutions
-#  include "top_substitute.h90"
-#  include "zdfddm_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
-   !! $Header:  $ 
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION trd_mld_trc_alloc()
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mld_trc_alloc  ***
-      !!----------------------------------------------------------------------
-      ALLOCATE( ztmltrd2(jpi,jpj,jpltrd_trc,jptra) ,      &
-#if defined key_pisces_reduced
-         &      ztmltrdbio2(jpi,jpj,jpdiabio)      ,      &
-#endif
-         &      ndextrd1(jpi*jpj)                  ,  STAT=trd_mld_trc_alloc)
-         !
-      IF( lk_mpp                )   CALL mpp_sum ( trd_mld_trc_alloc )
-      IF( trd_mld_trc_alloc /=0 )   CALL ctl_warn('trd_mld_trc_alloc: failed to allocate arrays')
-      !
-   END FUNCTION trd_mld_trc_alloc
-
-
-   SUBROUTINE trd_mld_trc_zint( ptrc_trdmld, ktrd, ctype, kjn )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mld_trc_zint  ***
-      !! 
-      !! ** 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 :
-      !!      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_trc in namelist NAMTRD :
-      !!        nctls_trc = -2  : use isopycnal surface
-      !!        nctls_trc = -1  : use euphotic layer with light criterion 
-      !!        nctls_trc =  0  : use mixed layer with density criterion 
-      !!        nctls_trc =  1  : read index from file 'ctlsurf_idx'
-      !!        nctls_trc >  1  : use fixed level surface jk = nctls_trc
-      !!      Note: in the remainder of the routine, the volume between the 
-      !!            surface and the control surface is called "mixed-layer"
-      !!----------------------------------------------------------------------
-      !!
-      INTEGER, INTENT( in ) ::   ktrd, kjn                        ! ocean trend index and passive tracer rank
-      CHARACTER(len=2), INTENT( in ) ::  ctype                    ! surface/bottom (2D) or interior (3D) physics
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::  ptrc_trdmld ! passive tracer trend
-      !
-      INTEGER ::   ji, jj, jk, isum
-      REAL(wp), POINTER, DIMENSION(:,:) :: zvlmsk
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zvlmsk )
-
-      ! I. Definition of control surface and integration weights
-      ! --------------------------------------------------------
-
-      ONCE_PER_TIME_STEP : IF( icount == 1 ) THEN
-         !
-         tmltrd_trc(:,:,:,:) = 0.e0                               ! <<< reset trend arrays to zero
-          
-         ! ... Set nmld(ji,jj) = index of first T point below control surf. or outside mixed-layer
-         SELECT CASE ( nn_ctls_trc )                                ! choice of the control surface
-            CASE ( -2  )   ;   STOP 'trdmld_trc : not ready '     !     -> isopycnal surface (see ???)
-#if defined key_pisces || defined key_pisces_reduced
-            CASE ( -1  )   ;   nmld_trc(:,:) = neln(:,:)          !     -> euphotic layer with light criterion
-#endif
-            CASE (  0  )   ;   nmld_trc(:,:) = nmln(:,:)          !     -> ML with density criterion (see zdfmxl)
-            CASE (  1  )   ;   nmld_trc(:,:) = nbol_trc(:,:)          !     -> read index from file
-            CASE (  2: )   ;   nn_ctls_trc = MIN( nn_ctls_trc, jpktrd_trc - 1 )
-                               nmld_trc(:,:) = nn_ctls_trc + 1      !     -> model level
-         END SELECT
-
-         ! ... Compute ndextrd1 and ndimtrd1  ??? role de jpktrd_trc
-         IF( ionce == 1 ) THEN
-            !
-            isum  = 0   ;   zvlmsk(:,:) = 0.e0
-
-            IF( jpktrd_trc < jpk ) THEN                           ! description ???
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     IF( nmld_trc(ji,jj) <= jpktrd_trc ) THEN
-                        zvlmsk(ji,jj) = tmask(ji,jj,1)
-                     ELSE
-                        isum = isum + 1
-                        zvlmsk(ji,jj) = 0.e0
-                     ENDIF
-                  END DO
-               END DO
-            ENDIF
-
-            IF( isum > 0 ) THEN                                   ! index of ocean points (2D only)
-               WRITE(numout,*)' tmltrd_trc : Number of invalid points nmld_trc > jpktrd', isum 
-               CALL wheneq( jpi*jpj, zvlmsk(:,:) , 1, 1., ndextrd1, ndimtrd1 )
-            ELSE 
-               CALL wheneq( jpi*jpj, tmask(:,:,1), 1, 1., ndextrd1, ndimtrd1 )
-            ENDIF                                
-
-            ionce = 0                                             ! no more pass here
-            !
-         ENDIF   ! ionce == 1
-         
-         ! ... Weights for vertical averaging
-         wkx_trc(:,:,:) = 0.e0
-         DO jk = 1, jpktrd_trc                                    ! initialize wkx_trc with vertical scale factor in mixed-layer
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  IF( jk - nmld_trc(ji,jj) < 0 )   wkx_trc(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         
-         rmld_trc(:,:) = 0.e0
-         DO jk = 1, jpktrd_trc                                    ! compute mixed-layer depth : rmld_trc
-            rmld_trc(:,:) = rmld_trc(:,:) + wkx_trc(:,:,jk)
-         END DO
-         
-         DO jk = 1, jpktrd_trc                                    ! compute integration weights
-            wkx_trc(:,:,jk) = wkx_trc(:,:,jk) / MAX( 1., rmld_trc(:,:) )
-         END DO
-
-         icount = 0                                               ! <<< flag = off : control surface & integr. weights
-         !                                                        !     computed only once per time step
-      ENDIF ONCE_PER_TIME_STEP
-
-      ! II. Vertical integration of trends in the mixed-layer
-      ! -----------------------------------------------------
-
-      SELECT CASE ( ctype )
-         CASE ( '3D' )                                            ! mean passive tracer trends in the mixed-layer
-            DO jk = 1, jpktrd_trc
-               tmltrd_trc(:,:,ktrd,kjn) = tmltrd_trc(:,:,ktrd,kjn) + ptrc_trdmld(:,:,jk) * wkx_trc(:,:,jk)   
-            END DO
-         CASE ( '2D' )                                            ! forcing at upper boundary of the mixed-layer 
-            tmltrd_trc(:,:,ktrd,kjn) = tmltrd_trc(:,:,ktrd,kjn) + ptrc_trdmld(:,:,1) * wkx_trc(:,:,1)  ! non penetrative
-      END SELECT
-      !
-      CALL wrk_dealloc( jpi, jpj, zvlmsk )
-      !
-   END SUBROUTINE trd_mld_trc_zint
-
-
-   SUBROUTINE trd_mld_bio_zint( ptrc_trdmld, ktrd )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mld_bio_zint  ***
-      !!
-      !! ** 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 :
-      !!      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 NAMTRD :
-      !!        nctls_trc = 0  : use mixed layer with density criterion
-      !!        nctls_trc = 1  : read index from file 'ctlsurf_idx'
-      !!        nctls_trc > 1  : use fixed level surface jk = nctls_trc
-      !!      Note: in the remainder of the routine, the volume between the
-      !!            surface and the control surface is called "mixed-layer"
-      !!----------------------------------------------------------------------
-      !!
-      INTEGER                         , INTENT(in) ::   ktrd          ! bio trend index
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in) ::   ptrc_trdmld   ! passive trc trend
-#if defined key_pisces_reduced
-      !
-      INTEGER ::   ji, jj, jk, isum
-      REAL(wp), POINTER, DIMENSION(:,:) :: zvlmsk
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zvlmsk )
-
-      ! I. Definition of control surface and integration weights
-      ! --------------------------------------------------------
-      !            ==> only once per time step <==
-
-      IF( icountbio == 1 ) THEN
-         !
-         tmltrd_bio(:,:,:) = 0.e0    ! <<< reset trend arrays to zero
-         ! ... Set nmld(ji,jj) = index of first T point below control surf. or outside mixed-layer
-         SELECT CASE ( nn_ctls_trc )                                    ! choice of the control surface
-            CASE ( -2  )   ;   STOP 'trdmld_trc : not ready '     !     -> isopycnal surface (see ???)
-            CASE ( -1  )   ;   nmld_trc(:,:) = neln(:,:)          !     -> euphotic layer with light criterion
-            CASE (  0  )   ;   nmld_trc(:,:) = nmln(:,:)          !     -> ML with density criterion (see zdfmxl)
-            CASE (  1  )   ;   nmld_trc(:,:) = nbol_trc(:,:)          !     -> read index from file
-            CASE (  2: )   ;   nn_ctls_trc = MIN( nn_ctls_trc, jpktrd_trc - 1 )
-                               nmld_trc(:,:) = nn_ctls_trc + 1          !     -> model level
-         END SELECT
-
-         ! ... Compute ndextrd1 and ndimtrd1 only once
-         IF( ioncebio == 1 ) THEN
-            !
-            ! Check of validity : nmld_trc(ji,jj) <= jpktrd_trc
-            isum        = 0
-            zvlmsk(:,:) = 0.e0
-
-            IF( jpktrd_trc < jpk ) THEN
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     IF( nmld_trc(ji,jj) <= jpktrd_trc ) THEN
-                        zvlmsk(ji,jj) = tmask(ji,jj,1)
-                     ELSE
-                        isum = isum + 1
-                        zvlmsk(ji,jj) = 0.
-                     END IF
-                  END DO
-               END DO
-            END IF
-
-            ! Index of ocean points (2D only)
-            IF( isum > 0 ) THEN
-               WRITE(numout,*)' tmltrd_trc : Number of invalid points nmld_trc > jpktrd', isum
-               CALL wheneq( jpi*jpj, zvlmsk(:,:) , 1, 1., ndextrd1, ndimtrd1 )
-            ELSE
-               CALL wheneq( jpi*jpj, tmask(:,:,1), 1, 1., ndextrd1, ndimtrd1 )
-            END IF
-
-            ioncebio = 0                  ! no more pass here
-            !
-         END IF !  ( ioncebio == 1 )
-
-         ! ... Weights for vertical averaging
-         wkx_trc(:,:,:) = 0.e0
-         DO jk = 1, jpktrd_trc         ! initialize wkx_trc with vertical scale factor in mixed-layer
-            DO jj = 1,jpj
-              DO ji = 1,jpi
-                  IF( jk - nmld_trc(ji,jj) < 0. )   wkx_trc(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-
-         rmld_trc(:,:) = 0.
-         DO jk = 1, jpktrd_trc         ! compute mixed-layer depth : rmld_trc
-            rmld_trc(:,:) = rmld_trc(:,:) + wkx_trc(:,:,jk)
-         END DO
-
-         DO jk = 1, jpktrd_trc         ! compute integration weights
-            wkx_trc(:,:,jk) = wkx_trc(:,:,jk) / MAX( 1., rmld_trc(:,:) )
-         END DO
-
-         icountbio = 0                    ! <<< flag = off : control surface & integr. weights
-         !                             !     computed only once per time step
-      END IF ! ( icountbio == 1 )
-
-      ! II. Vertical integration of trends in the mixed-layer
-      ! -----------------------------------------------------
-
-
-      DO jk = 1, jpktrd_trc
-         tmltrd_bio(:,:,ktrd) = tmltrd_bio(:,:,ktrd) + ptrc_trdmld(:,:,jk) * wkx_trc(:,:,jk)
-      END DO
-
-      CALL wrk_dealloc( jpi, jpj, zvlmsk )
-#endif
-      !
-   END SUBROUTINE trd_mld_bio_zint
-
-
-   SUBROUTINE trd_mld_trc( kt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mld_trc  ***
-      !! 
-      !! ** 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_trc_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 ntrc_trc 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).
-      !!
-      !! ** Consistency check : 
-      !!        If the control surface is fixed ( nctls_trc > 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. ntrc_trc=5, rn_ucf_trc=1., nctls_trc=8
-      !!             for checking residuals.
-      !!             On a NEC-SX5 computer, this typically leads to:
-      !!                   O(1.e-20) temp. residuals (tml_res) when ln_trdmld_trc_instant=.false.
-      !!                   O(1.e-21) temp. residuals (tml_res) when ln_trdmld_trc_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)
-      !!----------------------------------------------------------------------
-      !
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
-      !
-      INTEGER ::   ji, jj, jk, jl, ik, it, itmod, jn
-      REAL(wp) ::   zavt, zfn, zfn2
-      !
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltot             ! d(trc)/dt over the anlysis window (incl. Asselin)
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlres             ! residual = dh/dt entrainment term
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlatf             ! for storage only
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlrad             ! for storage only (for trb<0 corr in trcrad)
-      !
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltot2            ! -+
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlres2            !  | working arrays to diagnose the trends
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltrdm2           !  | associated with the time meaned ML
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlatf2            !  | passive tracers
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlrad2            !  | (-> for trb<0 corr in trcrad)
-      !
-      CHARACTER (LEN=10) ::   clvar
-#if defined key_dimgout
-      INTEGER ::   iyear,imon,iday
-      CHARACTER(LEN=80) ::   cltext, clmode
-#endif
-      !!----------------------------------------------------------------------
-
-      ! Set-up pointers into sub-arrays of workspaces
-      CALL wrk_alloc( jpi, jpj, jptra, ztmltot , ztmlres , ztmlatf , ztmlrad             )
-      CALL wrk_alloc( jpi, jpj, jptra, ztmltot2, ztmlres2, ztmlatf2, ztmlrad2, ztmltrdm2 )
-
-      IF( nn_dttrc  /= 1  )   CALL ctl_stop( " Be careful, trends diags never validated " )
-
-      ! ======================================================================
-      ! 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( tracer ))
-
-      IF( ln_trcldf_iso ) THEN
-         !
-         DO jj = 1,jpj
-            DO ji = 1,jpi
-               ik = nmld_trc(ji,jj)
-               zavt = fsavs(ji,jj,ik)
-               DO jn = 1, jptra
-                  IF( ln_trdtrc(jn) )    &
-                  tmltrd_trc(ji,jj,jpmld_trc_zdf,jn) = - zavt / fse3w(ji,jj,ik) * tmask(ji,jj,ik)  &
-                       &                    * ( trn(ji,jj,ik-1,jn) - trn(ji,jj,ik,jn) )            &
-                       &                    / MAX( 1., rmld_trc(ji,jj) ) * tmask(ji,jj,1)
-               END DO
-            END DO
-         END DO
-
-         DO jn = 1, jptra
-            ! ... Remove this K_z trend from the iso-neutral diffusion term (if any)
-            IF( ln_trdtrc(jn) ) &
-                 tmltrd_trc(:,:,jpmld_trc_ldf,jn) = tmltrd_trc(:,:,jpmld_trc_ldf,jn) - tmltrd_trc(:,:,jpmld_trc_zdf,jn)
-   
-         END DO
-         !      
-      ENDIF
-
-      IF ( cp_cfg .NE. 'gyre' ) THEN            ! other than GYRE configuration
-      ! GYRE : for diagnostic fields, are needed if cyclic B.C. are present, but not for purely MPI comm. 
-      ! therefore we do not call lbc_lnk in GYRE config. (closed basin, no cyclic B.C.)
-         DO jn = 1, jptra
-            IF( ln_trdtrc(jn) ) THEN
-               DO jl = 1, jpltrd_trc
-                  CALL lbc_lnk( tmltrd_trc(:,:,jl,jn), 'T', 1. )        ! lateral boundary conditions
-               END DO
-            ENDIF
-         END DO
-      ENDIF
-      ! ======================================================================
-      ! II. Cumulate the trends over the analysis window
-      ! ======================================================================
-
-      ztmltrd2(:,:,:,:) = 0.e0   ;   ztmltot2(:,:,:)   = 0.e0     ! <<< reset arrays to zero
-      ztmlres2(:,:,:)   = 0.e0   ;   ztmlatf2(:,:,:)   = 0.e0
-      ztmlrad2(:,:,:)   = 0.e0
-
-      ! II.1 Set before values of vertically averages passive tracers
-      ! -------------------------------------------------------------
-      IF( kt > nittrc000 ) THEN
-         DO jn = 1, jptra
-            IF( ln_trdtrc(jn) ) THEN
-               tmlb_trc   (:,:,jn) = tml_trc   (:,:,jn)
-               tmlatfn_trc(:,:,jn) = tmltrd_trc(:,:,jpmld_trc_atf,jn)
-               tmlradn_trc(:,:,jn) = tmltrd_trc(:,:,jpmld_trc_radb,jn)
-            ENDIF
-         END DO
-      ENDIF
-
-      ! II.2 Vertically averaged passive tracers
-      ! ----------------------------------------
-      tml_trc(:,:,:) = 0.e0
-      DO jk = 1, jpktrd_trc ! - 1 ???
-         DO jn = 1, jptra
-            IF( ln_trdtrc(jn) ) &
-               tml_trc(:,:,jn) = tml_trc(:,:,jn) + wkx_trc(:,:,jk) * trn(:,:,jk,jn)
-         END DO
-      END DO
-
-      ! II.3 Initialize mixed-layer "before" arrays for the 1rst analysis window    
-      ! ------------------------------------------------------------------------
-      IF( kt == nittrc000 + nn_dttrc ) THEN  !  i.e. ( .NOT. ln_rstart ).AND.( kt == nit000 + 1)    ???
-         !
-         DO jn = 1, jptra
-            IF( ln_trdtrc(jn) ) THEN
-               tmlbb_trc  (:,:,jn) = tmlb_trc   (:,:,jn)   ;   tmlbn_trc  (:,:,jn) = tml_trc    (:,:,jn)
-               tmlatfb_trc(:,:,jn) = tmlatfn_trc(:,:,jn)   ;   tmlradb_trc(:,:,jn) = tmlradn_trc(:,:,jn)
-               
-               tmltrd_csum_ub_trc (:,:,:,jn) = 0.e0   ;   tmltrd_atf_sumb_trc  (:,:,jn) = 0.e0
-               tmltrd_rad_sumb_trc  (:,:,jn) = 0.e0
-            ENDIF
-         END DO
-         
-         rmldbn_trc(:,:) = rmld_trc(:,:)
-         !
-      ENDIF
-
-      ! 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_rsttr ) ) THEN                        ! ???
-         !
-         nmoymltrd = nmoymltrd + 1
-
-
-         ! ... Cumulate over BOTH physical contributions AND over time steps
-         DO jn = 1, jptra
-            IF( ln_trdtrc(jn) ) THEN
-               DO jl = 1, jpltrd_trc
-                  tmltrdm_trc(:,:,jn) = tmltrdm_trc(:,:,jn) + tmltrd_trc(:,:,jl,jn)
-               END DO
-            ENDIF
-         END DO
-
-         DO jn = 1, jptra
-            IF( ln_trdtrc(jn) ) THEN
-               ! ... Special handling of the Asselin trend 
-               tmlatfm_trc(:,:,jn) = tmlatfm_trc(:,:,jn) + tmlatfn_trc(:,:,jn)
-               tmlradm_trc(:,:,jn) = tmlradm_trc(:,:,jn) + tmlradn_trc(:,:,jn)
-
-               ! ... Trends associated with the time mean of the ML passive tracers
-               tmltrd_sum_trc    (:,:,:,jn) = tmltrd_sum_trc    (:,:,:,jn) + tmltrd_trc    (:,:,:,jn)
-               tmltrd_csum_ln_trc(:,:,:,jn) = tmltrd_csum_ln_trc(:,:,:,jn) + tmltrd_sum_trc(:,:,:,jn)
-               tml_sum_trc       (:,:,jn)   = tml_sum_trc       (:,:,jn)   + tml_trc       (:,:,jn)
-            ENDIF
-         ENDDO
-
-         rmld_sum_trc      (:,:)     = rmld_sum_trc      (:,:)     + rmld_trc      (:,:)
-         !
-      ENDIF
-
-      ! ======================================================================
-      ! III. Prepare fields for output (get here ONCE PER ANALYSIS PERIOD)
-      ! ======================================================================
-
-      ! Convert to appropriate physical units
-      tmltrd_trc(:,:,:,:) = tmltrd_trc(:,:,:,:) * rn_ucf_trc
-
-      itmod = kt - nittrc000 + 1
-      it    = kt
-
-      MODULO_NTRD : IF( MOD( itmod, nn_trd_trc ) == 0 ) THEN           ! nitend MUST be multiple of nn_trd_trc
-         !
-         ztmltot (:,:,:) = 0.e0                                   ! reset arrays to zero
-         ztmlres (:,:,:) = 0.e0
-         ztmltot2(:,:,:) = 0.e0
-         ztmlres2(:,:,:) = 0.e0
-      
-         zfn  = FLOAT( nmoymltrd )    ;    zfn2 = zfn * zfn
-         
-         ! III.1 Prepare fields for output ("instantaneous" diagnostics) 
-         ! -------------------------------------------------------------
-
-         DO jn = 1, jptra
-            IF( ln_trdtrc(jn) ) THEN
-               !-- Compute total trends    (use rdttrc instead of rdt ???)
-               IF ( ln_trcadv_muscl .OR. ln_trcadv_muscl2 ) THEN  ! EULER-FORWARD schemes
-                  ztmltot(:,:,jn) =  ( tml_trc(:,:,jn) - tmlbn_trc(:,:,jn) )/rdt
-               ELSE                                                                     ! LEAP-FROG schemes
-                  ztmltot(:,:,jn) =  ( tml_trc(:,:,jn) - tmlbn_trc(:,:,jn) + tmlb_trc(:,:,jn) - tmlbb_trc(:,:,jn))/(2.*rdt)
-               ENDIF
-               
-               !-- Compute residuals
-               ztmlres(:,:,jn) = ztmltot(:,:,jn) - ( tmltrdm_trc(:,:,jn) - tmlatfn_trc(:,:,jn) + tmlatfb_trc(:,:,jn) &
-                  &                                                 - tmlradn_trc(:,:,jn) + tmlradb_trc(:,:,jn)  )
-               
-               !-- Diagnose Asselin trend over the analysis window 
-               ztmlatf(:,:,jn) = tmlatfm_trc(:,:,jn) - tmlatfn_trc(:,:,jn) + tmlatfb_trc(:,:,jn)
-               ztmlrad(:,:,jn) = tmlradm_trc(:,:,jn) - tmlradn_trc(:,:,jn) + tmlradb_trc(:,:,jn)
-               
-         !-- Lateral boundary conditions
-               IF ( cp_cfg .NE. 'gyre' ) THEN
-                  CALL lbc_lnk( ztmltot(:,:,jn) , 'T', 1. )   ;   CALL lbc_lnk( ztmlres(:,:,jn) , 'T', 1. )
-                  CALL lbc_lnk( ztmlatf(:,:,jn) , 'T', 1. )   ;   CALL lbc_lnk( ztmlrad(:,:,jn) , 'T', 1. )
-               ENDIF
-
-
-#if defined key_diainstant
-               STOP 'tmltrd_trc : key_diainstant was never checked within trdmld. Comment this to proceed.'
-#endif
-            ENDIF
-         END DO
-
-         ! III.2 Prepare fields for output ("mean" diagnostics) 
-         ! ----------------------------------------------------
-         
-         !-- Update the ML depth time sum (to build the Leap-Frog time mean)
-         rmld_sum_trc(:,:) = rmldbn_trc(:,:) + 2 * ( rmld_sum_trc(:,:) - rmld_trc(:,:) ) + rmld_trc(:,:)
-
-               !-- Compute passive tracer total trends
-         DO jn = 1, jptra
-            IF( ln_trdtrc(jn) ) THEN
-               tml_sum_trc(:,:,jn) = tmlbn_trc(:,:,jn) + 2 * ( tml_sum_trc(:,:,jn) - tml_trc(:,:,jn) ) + tml_trc(:,:,jn)
-               ztmltot2   (:,:,jn) = ( tml_sum_trc(:,:,jn) - tml_sumb_trc(:,:,jn) ) /  ( 2.*rdt )    ! now tracer unit is /sec
-            ENDIF
-         END DO
-
-         !-- Compute passive tracer residuals
-         DO jn = 1, jptra
-            IF( ln_trdtrc(jn) ) THEN
-               !
-               DO jl = 1, jpltrd_trc
-                  ztmltrd2(:,:,jl,jn) = tmltrd_csum_ub_trc(:,:,jl,jn) + tmltrd_csum_ln_trc(:,:,jl,jn)
-               END DO
-               
-               ztmltrdm2(:,:,jn) = 0.e0
-               DO jl = 1, jpltrd_trc
-                  ztmltrdm2(:,:,jn) = ztmltrdm2(:,:,jn) + ztmltrd2(:,:,jl,jn)
-               END DO
-               
-               ztmlres2(:,:,jn) =  ztmltot2(:,:,jn)  -       &
-                  & ( ztmltrdm2(:,:,jn) - tmltrd_sum_trc(:,:,jpmld_trc_atf ,jn) + tmltrd_atf_sumb_trc(:,:,jn) &
-                  &                     - tmltrd_sum_trc(:,:,jpmld_trc_radb,jn) + tmltrd_rad_sumb_trc(:,:,jn) )
-               !
-
-               !-- Diagnose Asselin trend over the analysis window
-               ztmlatf2(:,:,jn) = ztmltrd2(:,:,jpmld_trc_atf ,jn) - tmltrd_sum_trc(:,:,jpmld_trc_atf ,jn) &
-                  &                                               + tmltrd_atf_sumb_trc(:,:,jn)
-               ztmlrad2(:,:,jn) = ztmltrd2(:,:,jpmld_trc_radb,jn) - tmltrd_sum_trc(:,:,jpmld_trc_radb,jn) &
-                  &                                               + tmltrd_rad_sumb_trc(:,:,jn)
-
-         !-- Lateral boundary conditions 
-               IF ( cp_cfg .NE. 'gyre' ) THEN            ! other than GYRE configuration    
-                  CALL lbc_lnk( ztmltot2(:,:,jn), 'T', 1. )
-                  CALL lbc_lnk( ztmlres2(:,:,jn), 'T', 1. )
-                  DO jl = 1, jpltrd_trc
-                     CALL lbc_lnk( ztmltrd2(:,:,jl,jn), 'T', 1. )       ! will be output in the NetCDF trends file
-                  END DO
-               ENDIF
-
-            ENDIF
-         END DO
-
-         ! * Debugging information *
-         IF( lldebug ) THEN
-            !
-            WRITE(numout,*) 'trd_mld_trc : write trends in the Mixed Layer for debugging process:'
-            WRITE(numout,*) '~~~~~~~~~~~  '
-            WRITE(numout,*)
-            WRITE(numout,*) 'TRC kt = ', kt, '    nmoymltrd = ', nmoymltrd
-
-            DO jn = 1, jptra
-
-               IF( ln_trdtrc(jn) ) THEN
-                  WRITE(numout, *)
-                  WRITE(numout, *) '>>>>>>>>>>>>>>>>>>  TRC TRACER jn =', jn, ' <<<<<<<<<<<<<<<<<<'
-                  
-                  WRITE(numout, *)
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM ztmlres     : ', SUM2D(ztmlres(:,:,jn))
-                  !CD??? PREVOIR: z2d = ztmlres(:,:,jn)   ;   CALL prt_ctl(tab2d_1=z2d, clinfo1=' ztmlres   -   : ')
-                  
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM ABS(ztmlres): ', SUM2D(ABS(ztmlres(:,:,jn)))
-                  WRITE(numout, '(3x,a)') ' -->>>------------------- ztmlres is computed from ------------- '
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +ztmltot    : ', SUM2D(+ztmltot    (:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmltrdm_trc: ', SUM2D(+tmltrdm_trc(:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmlatfn_trc: ', SUM2D(-tmlatfn_trc(:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmlatfb_trc: ', SUM2D(+tmlatfb_trc(:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmlradn_trc: ', SUM2D(-tmlradn_trc(:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmlradb_trc: ', SUM2D(+tmlradb_trc(:,:,jn))
-                  WRITE(numout, '(3x,a)') ' --<<<----------------------------------------------------------- '
-                  
-                  WRITE(numout, *)
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM ztmlres2    : ', SUM2D(ztmlres2(:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM ABS(ztmlres2):', SUM2D(ABS(ztmlres2(:,:,jn)))
-                  WRITE(numout, '(3x,a)') ' -->>>------------------- ztmlres2 is computed from ------------ '
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +ztmltot2            : ', SUM2D(+ztmltot2(:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +ztmltrdm2           : ', SUM2D(+ztmltrdm2(:,:,jn)) 
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmltrd_sum_trc      : ', SUM2D(-tmltrd_sum_trc(:,:,jpmld_trc_atf,jn)) 
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmltrd_atf_sumb_trc : ', SUM2D(+tmltrd_atf_sumb_trc(:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmltrd_sum_trc      : ', SUM2D(-tmltrd_sum_trc(:,:,jpmld_trc_radb,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmltrd_rad_sumb_trc : ', SUM2D(+tmltrd_rad_sumb_trc(:,:,jn) )
-                  WRITE(numout, '(3x,a)') ' --<<<----------------------------------------------------------- '
-                  
-                  WRITE(numout, *)
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM ztmltot     : ', SUM2D(ztmltot    (:,:,jn))
-                  WRITE(numout, '(3x,a)') ' -->>>------------------- ztmltot is computed from ------------- '
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +tml_trc    : ', SUM2D(tml_trc    (:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmlbn_trc  : ', SUM2D(tmlbn_trc  (:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmlb_trc   : ', SUM2D(tmlb_trc   (:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmlbb_trc  : ', SUM2D(tmlbb_trc  (:,:,jn))
-                  WRITE(numout, '(3x,a)') ' --<<<----------------------------------------------------------- '
-                  
-                  WRITE(numout, *)
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM tmltrdm_trc : ', SUM2D(tmltrdm_trc(:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM tmlatfb_trc : ', SUM2D(tmlatfb_trc(:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM tmlatfn_trc : ', SUM2D(tmlatfn_trc(:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM tmlradb_trc : ', SUM2D(tmlradb_trc(:,:,jn))
-                  WRITE(numout,98) 'TRC jn =', jn, ' SUM tmlradn_trc : ', SUM2D(tmlradn_trc(:,:,jn))
-                  
-                  WRITE(numout, *)
-                  DO jl = 1, jpltrd_trc
-                     WRITE(numout,97) 'TRC jn =', jn, ' TREND INDEX jpmld_trc_xxx = ', jl, &
-                        & ' SUM tmltrd_trc : ', SUM2D(tmltrd_trc(:,:,jl,jn))
-                  END DO
-               
-                  WRITE(numout,*) 
-                  WRITE(numout,*) ' *********************** ZTMLRES, ZTMLRES2 *********************** '
-                  WRITE(numout,*)
-                  WRITE(numout,*) 'TRC ztmlres (jpi/2,jpj/2,:) : ', ztmlres (jpi/2,jpj/2,jn)
-                  WRITE(numout,*)
-                  WRITE(numout,*) 'TRC ztmlres2(jpi/2,jpj/2,:) : ', ztmlres2(jpi/2,jpj/2,jn)
-                  
-                  WRITE(numout,*) 
-                  WRITE(numout,*) ' *********************** ZTMLRES *********************** '
-                  WRITE(numout,*)
-                  
-                  WRITE(numout,*) '...................................................'
-                  WRITE(numout,*) 'TRC jn =', jn, ' ztmlres (1:10,1:5,jn) : '
-                  DO jj = 5, 1, -1
-                     WRITE(numout,99) jj, ( ztmlres (ji,jj,jn), ji=1,10 )
-                  END DO
-                  
-                  WRITE(numout,*) 
-                  WRITE(numout,*) ' *********************** ZTMLRES2 *********************** '
-                  WRITE(numout,*)
-                  
-                  WRITE(numout,*) '...................................................'
-                  WRITE(numout,*) 'TRC jn =', jn, ' ztmlres2 (1:10,1:5,jn) : '
-                  DO jj = 5, 1, -1
-                     WRITE(numout,99) jj, ( ztmlres2 (ji,jj,jn), ji=1,10 )
-                  END DO
-                  !
-               ENDIF
-               !
-            END DO
-
-
-97            FORMAT(a10, i3, 2x, a30, i3, a20, 2x, g20.10)
-98            FORMAT(a10, i3, 2x, a30, 2x, g20.10)
-99            FORMAT('TRC jj =', i3,' : ', 10(g10.3,2x))
-              WRITE(numout,*)
-            !
-         ENDIF
-
-         ! III.3 Time evolution array swap
-         ! -------------------------------
-         ! ML depth
-         rmldbn_trc(:,:)   = rmld_trc(:,:)
-         rmld_sum_trc(:,:)     = rmld_sum_trc(:,:)     /      (2*zfn)  ! similar to tml_sum and sml_sum
-         DO jn = 1, jptra
-            IF( ln_trdtrc(jn) ) THEN        
-               ! For passive tracer instantaneous diagnostics
-               tmlbb_trc  (:,:,jn) = tmlb_trc   (:,:,jn)   ;   tmlbn_trc  (:,:,jn) = tml_trc    (:,:,jn)
-               tmlatfb_trc(:,:,jn) = tmlatfn_trc(:,:,jn)   ;   tmlradb_trc(:,:,jn) = tmlradn_trc(:,:,jn)
-               
-               ! For passive tracer mean diagnostics
-               tmltrd_csum_ub_trc (:,:,:,jn) = zfn * tmltrd_sum_trc(:,:,:,jn) - tmltrd_csum_ln_trc(:,:,:,jn)
-               tml_sumb_trc       (:,:,jn)   = tml_sum_trc(:,:,jn)
-               tmltrd_atf_sumb_trc(:,:,jn)   = tmltrd_sum_trc(:,:,jpmld_trc_atf ,jn)
-               tmltrd_rad_sumb_trc(:,:,jn)   = tmltrd_sum_trc(:,:,jpmld_trc_radb,jn)
-               
-               
-               ! III.4 Convert to appropriate physical units
-               ! -------------------------------------------
-               ztmltot     (:,:,jn)   = ztmltot     (:,:,jn)   * rn_ucf_trc/zfn   ! instant diags
-               ztmlres     (:,:,jn)   = ztmlres     (:,:,jn)   * rn_ucf_trc/zfn
-               ztmlatf     (:,:,jn)   = ztmlatf     (:,:,jn)   * rn_ucf_trc/zfn
-               ztmlrad     (:,:,jn)   = ztmlrad     (:,:,jn)   * rn_ucf_trc/zfn
-               tml_sum_trc (:,:,jn)   = tml_sum_trc (:,:,jn)   /      (2*zfn)  ! mean diags
-               ztmltot2    (:,:,jn)   = ztmltot2    (:,:,jn)   * rn_ucf_trc/zfn2
-               ztmltrd2    (:,:,:,jn) = ztmltrd2    (:,:,:,jn) * rn_ucf_trc/zfn2
-               ztmlatf2    (:,:,jn)   = ztmlatf2    (:,:,jn)   * rn_ucf_trc/zfn2
-               ztmlrad2    (:,:,jn)   = ztmlrad2    (:,:,jn)   * rn_ucf_trc/zfn2
-               ztmlres2    (:,:,jn)   = ztmlres2    (:,:,jn)   * rn_ucf_trc/zfn2
-            ENDIF
-         END DO
-         !
-      ENDIF MODULO_NTRD
-
-      ! ======================================================================
-      ! IV. Write trends in the NetCDF file
-      ! ======================================================================
-
-      ! IV.1 Code for dimg mpp output
-      ! -----------------------------
-
-# if defined key_dimgout
-      STOP 'Not implemented'
-# else
-      
-      ! IV.2 Code for IOIPSL/NetCDF output
-      ! ----------------------------------
-
-      IF( lwp .AND. MOD( itmod , nn_trd_trc ) == 0 ) THEN
-         WRITE(numout,*) ' '
-         WRITE(numout,*) 'trd_mld_trc : write passive tracer trends in the NetCDF file :'
-         WRITE(numout,*) '~~~~~~~~~~~ '
-         WRITE(numout,*) '          ', trim(clhstnam), ' at kt = ', kt
-         WRITE(numout,*) '          N.B. nmoymltrd = ', nmoymltrd
-         WRITE(numout,*) ' '
-      ENDIF
-         
-      NETCDF_OUTPUT : IF( ln_trdmld_trc_instant ) THEN            ! <<< write the trends for passive tracer instant. diags
-         !
-
-         DO jn = 1, jptra
-            !
-            IF( ln_trdtrc(jn) ) THEN
-               CALL histwrite( nidtrd(jn), "mxl_depth", it, rmld_trc(:,:), ndimtrd1, ndextrd1 )
-               !-- Output the fields
-               clvar = trim(ctrcnm(jn))//"ml"                        ! e.g. detml, zooml, nh4ml, etc.
-               CALL histwrite( nidtrd(jn), trim(clvar)         , it, tml_trc(:,:,jn), ndimtrd1, ndextrd1 ) 
-               CALL histwrite( nidtrd(jn), trim(clvar)//"_tot" , it, ztmltot(:,:,jn), ndimtrd1, ndextrd1 ) 
-               CALL histwrite( nidtrd(jn), trim(clvar)//"_res" , it, ztmlres(:,:,jn), ndimtrd1, ndextrd1 ) 
-           
-               DO jl = 1, jpltrd_trc - 2
-                  CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jl,2)),             &
-                    &          it, tmltrd_trc(:,:,jl,jn), ndimtrd1, ndextrd1 )
-               END DO
-
-               CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmld_trc_radb,2)),    &  ! now trcrad    : jpltrd_trc - 1
-                    &          it, ztmlrad(:,:,jn), ndimtrd1, ndextrd1 )
-
-               CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmld_trc_atf,2)),     &  ! now Asselin   : jpltrd_trc
-                    &          it, ztmlatf(:,:,jn), ndimtrd1, ndextrd1 )
-                     
-            ENDIF
-         END DO
-
-         IF( kt == nitend ) THEN 
-            DO jn = 1, jptra
-               IF( ln_trdtrc(jn) )  CALL histclo( nidtrd(jn) )
-            END DO
-         ENDIF
-
-      ELSE                                                        ! <<< write the trends for passive tracer mean diagnostics
-         
-         DO jn = 1, jptra
-            !
-            IF( ln_trdtrc(jn) ) THEN
-               CALL histwrite( nidtrd(jn), "mxl_depth", it, rmld_sum_trc(:,:), ndimtrd1, ndextrd1 ) 
-               !-- Output the fields
-               clvar = trim(ctrcnm(jn))//"ml"                        ! e.g. detml, zooml, nh4ml, etc.
-
-               CALL histwrite( nidtrd(jn), trim(clvar)         , it, tml_sum_trc(:,:,jn), ndimtrd1, ndextrd1 )
-               CALL histwrite( nidtrd(jn), trim(clvar)//"_tot" , it,    ztmltot2(:,:,jn), ndimtrd1, ndextrd1 ) 
-               CALL histwrite( nidtrd(jn), trim(clvar)//"_res" , it,    ztmlres2(:,:,jn), ndimtrd1, ndextrd1 ) 
-
-               DO jl = 1, jpltrd_trc - 2
-                  CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jl,2)),           &
-                    &          it, ztmltrd2(:,:,jl,jn), ndimtrd1, ndextrd1 )
-               END DO
-            
-               CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmld_trc_radb,2)),   &  ! now trcrad    : jpltrd_trc - 1
-                 &          it, ztmlrad2(:,:,jn), ndimtrd1, ndextrd1 )
-
-               CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmld_trc_atf,2)),    &  ! now Asselin   : jpltrd_trc
-                 &          it, ztmlatf2(:,:,jn), ndimtrd1, ndextrd1 )
-
-            ENDIF 
-            !
-         END DO
-         IF( kt == nitend ) THEN 
-            DO jn = 1, jptra
-               IF( ln_trdtrc(jn) )  CALL histclo( nidtrd(jn) )
-            END DO
-         ENDIF
-
-         !
-      ENDIF NETCDF_OUTPUT
-         
-      ! Compute the control surface (for next time step) : flag = on
-      icount = 1
-
-# endif /* key_dimgout */
-
-      IF( MOD( itmod, nn_trd_trc ) == 0 ) THEN
-         !
-         ! Reset cumulative arrays to zero
-         ! -------------------------------         
-         nmoymltrd = 0
-         tmltrdm_trc        (:,:,:)   = 0.e0   ;   tmlatfm_trc        (:,:,:)   = 0.e0
-         tmlradm_trc        (:,:,:)   = 0.e0   ;   tml_sum_trc        (:,:,:)   = 0.e0
-         tmltrd_csum_ln_trc (:,:,:,:) = 0.e0   ;   tmltrd_sum_trc     (:,:,:,:) = 0.e0
-         rmld_sum_trc       (:,:)     = 0.e0
-         !
-      ENDIF
-
-      ! ======================================================================
-      ! V. Write restart file
-      ! ======================================================================
-
-      IF( lrst_trc )   CALL trd_mld_trc_rst_write( kt )  ! this must be after the array swap above (III.3)
-
-      CALL wrk_dealloc( jpi, jpj, jptra, ztmltot , ztmlres , ztmlatf , ztmlrad             )
-      CALL wrk_dealloc( jpi, jpj, jptra, ztmltot2, ztmlres2, ztmlatf2, ztmlrad2, ztmltrdm2 )
-      !
-   END SUBROUTINE trd_mld_trc
-
-
-   SUBROUTINE trd_mld_bio( kt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mld  ***
-      !!
-      !! ** Purpose :  Compute and cumulate the mixed layer biological 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_trc_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).
-      !!
-      !! ** 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_trc_instant=.false.
-      !!                   O(1.e-21) temp. residuals (tml_res) when ln_trdmld_trc_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)
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt                       ! ocean time-step index
-#if defined key_pisces_reduced
-      INTEGER  ::  jl, it, itmod
-      LOGICAL  :: llwarn  = .TRUE., lldebug = .TRUE.
-      REAL(wp) :: zfn, zfn2
-#if defined key_dimgout
-      INTEGER ::  iyear,imon,iday
-      CHARACTER(LEN=80) :: cltext, clmode
-#endif
-      !!----------------------------------------------------------------------
-      ! ... Warnings
-      IF( nn_dttrc  /= 1  ) CALL ctl_stop( " Be careful, trends diags never validated " )
-
-      ! ======================================================================
-      ! II. Cumulate the trends over the analysis window
-      ! ======================================================================
-
-      ztmltrdbio2(:,:,:) = 0.e0  ! <<< reset arrays to zero
-
-      ! II.3 Initialize mixed-layer "before" arrays for the 1rst analysis window
-      ! ------------------------------------------------------------------------
-      IF( kt == nittrc000 + nn_dttrc ) THEN  !  i.e. ( .NOT. ln_rstart ).AND.( kt == nit000 + 1)
-         !
-         tmltrd_csum_ub_bio (:,:,:) = 0.e0
-         !
-      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_rsttr ) ) THEN
-         !
-         nmoymltrdbio = nmoymltrdbio + 1
-
-         ! ... Trends associated with the time mean of the ML passive tracers
-         tmltrd_sum_bio    (:,:,:) = tmltrd_sum_bio    (:,:,:) + tmltrd_bio    (:,:,:)
-         tmltrd_csum_ln_bio(:,:,:) = tmltrd_csum_ln_bio(:,:,:) + tmltrd_sum_bio(:,:,:)
-         !
-      END IF
-
-      ! ======================================================================
-      ! III. Prepare fields for output (get here ONCE PER ANALYSIS PERIOD)
-      ! ======================================================================
-
-      ! Convert to appropriate physical units
-      tmltrd_bio(:,:,:) = tmltrd_bio(:,:,:) * rn_ucf_trc
-
-      MODULO_NTRD : IF( MOD( kt, nn_trd_trc ) == 0 ) THEN      ! nitend MUST be multiple of ntrd
-         !
-         zfn  = float(nmoymltrdbio)    ;    zfn2 = zfn * zfn
-
-         ! III.1 Prepare fields for output ("instantaneous" diagnostics)
-         ! -------------------------------------------------------------
-
-#if defined key_diainstant
-         STOP 'tmltrd_bio : key_diainstant was never checked within trdmld. Comment this to proceed.'
-#endif
-         ! III.2 Prepare fields for output ("mean" diagnostics)
-         ! ----------------------------------------------------
-
-         ztmltrdbio2(:,:,:) = tmltrd_csum_ub_bio(:,:,:) + tmltrd_csum_ln_bio(:,:,:)
-
-         !-- Lateral boundary conditions
-         IF ( cp_cfg .NE. 'gyre' ) THEN            ! other than GYRE configuration 
-            ! ES_B27_CD_WARN : lbc inutile GYRE, cf. + haut
-            DO jn = 1, jpdiabio
-              CALL lbc_lnk( ztmltrdbio2(:,:,jn), 'T', 1. )
-            ENDDO
-         ENDIF
-
-         IF( lldebug ) THEN
-            !
-            WRITE(numout,*) 'trd_mld_bio : write trends in the Mixed Layer for debugging process:'
-            WRITE(numout,*) '~~~~~~~~~~~  '
-            WRITE(numout,*) 'TRC kt = ', kt, 'nmoymltrdbio = ', nmoymltrdbio
-            WRITE(numout,*)
-
-            DO jl = 1, jpdiabio
-              IF( ln_trdmld_trc_instant ) THEN
-                  WRITE(numout,97) 'TRC jl =', jl, ' bio TREND INDEX  = ', jl, &
-                     & ' SUM tmltrd_bio : ', SUM2D(tmltrd_bio(:,:,jl))
-              ELSE
-                  WRITE(numout,97) 'TRC jl =', jl, ' bio TREND INDEX  = ', jl, &
-                     & ' SUM ztmltrdbio2 : ', SUM2D(ztmltrdbio2(:,:,jl))
-              endif
-            END DO
-
-97          FORMAT(a10, i3, 2x, a30, i3, a20, 2x, g20.10)
-98          FORMAT(a10, i3, 2x, a30, 2x, g20.10)
-99          FORMAT('TRC jj =', i3,' : ', 10(g10.3,2x))
-            WRITE(numout,*)
-            !
-         ENDIF
-
-         ! III.3 Time evolution array swap
-         ! -------------------------------
-
-         ! For passive tracer mean diagnostics
-         tmltrd_csum_ub_bio (:,:,:) = zfn * tmltrd_sum_bio(:,:,:) - tmltrd_csum_ln_bio(:,:,:)
-
-         ! III.4 Convert to appropriate physical units
-         ! -------------------------------------------
-         ztmltrdbio2    (:,:,:) = ztmltrdbio2    (:,:,:) * rn_ucf_trc/zfn2
-
-      END IF MODULO_NTRD
-
-      ! ======================================================================
-      ! IV. Write trends in the NetCDF file
-      ! ======================================================================
-
-      ! IV.1 Code for dimg mpp output
-      ! -----------------------------
-
-# if defined key_dimgout
-      STOP 'Not implemented'
-# else
-
-      ! IV.2 Code for IOIPSL/NetCDF output
-      ! ----------------------------------
-
-      ! define time axis
-      itmod = kt - nittrc000 + 1
-      it    = kt
-
-      IF( lwp .AND. MOD( itmod , nn_trd_trc ) == 0 ) THEN
-         WRITE(numout,*) ' '
-         WRITE(numout,*) 'trd_mld_bio : write ML bio trends in the NetCDF file :'
-         WRITE(numout,*) '~~~~~~~~~~~ '
-         WRITE(numout,*) '          ', TRIM(clhstnam), ' at kt = ', kt
-         WRITE(numout,*) '          N.B. nmoymltrdbio = ', nmoymltrdbio
-         WRITE(numout,*) ' '
-      END IF
-
-
-      ! 2. Start writing data
-      ! ---------------------
-
-      NETCDF_OUTPUT : IF( ln_trdmld_trc_instant ) THEN    ! <<< write the trends for passive tracer instant. diags
-         !
-            DO jl = 1, jpdiabio
-               CALL histwrite( nidtrdbio,TRIM("ML_"//ctrd_bio(jl,2)) ,            &
-                    &          it, tmltrd_bio(:,:,jl), ndimtrd1, ndextrd1 )
-            END DO
-
-
-         IF( kt == nitend )   CALL histclo( nidtrdbio )
-
-      ELSE    ! <<< write the trends for passive tracer mean diagnostics
-
-            DO jl = 1, jpdiabio
-               CALL histwrite( nidtrdbio, TRIM("ML_"//ctrd_bio(jl,2)) ,            &
-                    &          it, ztmltrdbio2(:,:,jl), ndimtrd1, ndextrd1 )
-            END DO
-
-            IF( kt == nitend )   CALL histclo( nidtrdbio )
-            !
-      END IF NETCDF_OUTPUT
-
-      ! Compute the control surface (for next time step) : flag = on
-      icountbio = 1
-
-
-# endif /* key_dimgout */
-
-      IF( MOD( itmod, nn_trd_trc ) == 0 ) THEN
-         !
-         ! III.5 Reset cumulative arrays to zero
-         ! -------------------------------------
-         nmoymltrdbio = 0
-         tmltrd_csum_ln_bio (:,:,:) = 0.e0
-         tmltrd_sum_bio     (:,:,:) = 0.e0
-      END IF
-
-      ! ======================================================================
-      ! Write restart file
-      ! ======================================================================
-
-! restart write is done in trd_mld_trc_write which is called by trd_mld_bio (Marina)
-!
-#endif
-   END SUBROUTINE trd_mld_bio
-
-
-   REAL FUNCTION sum2d( ztab )
-      !!----------------------------------------------------------------------
-      !! CD ??? prevoir d'utiliser plutot prtctl
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT( in ) ::  ztab      
-      !!----------------------------------------------------------------------
-      sum2d = SUM( ztab(2:jpi-1,2:jpj-1) )
-   END FUNCTION sum2d
-
-
-   SUBROUTINE trd_mld_trc_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mld_init  ***
-      !! 
-      !! ** Purpose :   computation of vertically integrated T and S budgets
-      !!      from ocean surface down to control surface (NetCDF output)
-      !!
-      !! ** Method/usage :
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER :: inum   ! logical unit
-      INTEGER :: ilseq, jl, jn, iiter
-      REAL(wp) ::   zjulian, zsto, zout
-      CHARACTER (LEN=40) ::   clop
-      CHARACTER (LEN=15) ::   csuff
-      CHARACTER (LEN=12) ::   clmxl
-      CHARACTER (LEN=16) ::   cltrcu
-      CHARACTER (LEN=10) ::   clvar
-
-      !!----------------------------------------------------------------------
-
-      ! ======================================================================
-      ! I. initialization
-      ! ======================================================================
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) ' trd_mld_trc_init : Mixed-layer trends for passive tracers                '
-         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~'
-         WRITE(numout,*)
-      ENDIF
-
-      
-      ! I.1 Check consistency of user defined preferences
-      ! -------------------------------------------------
-
-      IF( ( lk_trdmld_trc ) .AND. ( MOD( nitend-nittrc000+1, nn_trd_trc ) /= 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, nn_trd_trc   = ', nn_trd_trc
-         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
-      ENDIF
-
-      ! * Debugging information *
-      IF( lldebug ) THEN
-         WRITE(numout,*) '               ln_trcadv_muscl = '      , ln_trcadv_muscl
-         WRITE(numout,*) '               ln_trdmld_trc_instant = ', ln_trdmld_trc_instant
-      ENDIF
-
-      IF( ( ln_trcadv_muscl .OR. ln_trcadv_muscl2 ) .AND. .NOT. ln_trdmld_trc_instant ) THEN
-         WRITE(numout,cform_err)
-         WRITE(numout,*) '                Currently, you can NOT use simultaneously tracer MUSCL    '
-         WRITE(numout,*) '                advection and window averaged diagnostics of ML trends.   '
-         WRITE(numout,*) '                WHY? Everything in trdmld_trc is coded for leap-frog, and '
-         WRITE(numout,*) '                MUSCL scheme is Euler forward for passive tracers (note   '
-         WRITE(numout,*) '                that MUSCL is leap-frog for active tracers T/S).          '
-         WRITE(numout,*) '                In particuliar, entrainment trend would be FALSE. However '
-         WRITE(numout,*) '                this residual is correct for instantaneous ML diagnostics.'
-         WRITE(numout,*) 
-         nstop = nstop + 1
-      ENDIF
-
-      ! I.2 Initialize arrays to zero or read a restart file
-      ! ----------------------------------------------------
-      nmoymltrd   = 0
-
-      rmld_trc           (:,:)     = 0.e0   ;   tml_trc            (:,:,:)   = 0.e0       ! inst.
-      tmltrdm_trc        (:,:,:)   = 0.e0   ;   tmlatfm_trc        (:,:,:)   = 0.e0
-      tmlradm_trc        (:,:,:)   = 0.e0
-
-      tml_sum_trc        (:,:,:)   = 0.e0   ;   tmltrd_sum_trc     (:,:,:,:) = 0.e0       ! mean
-      tmltrd_csum_ln_trc (:,:,:,:) = 0.e0   ;   rmld_sum_trc       (:,:)     = 0.e0
-
-#if defined key_pisces_reduced
-      nmoymltrdbio   = 0
-      tmltrd_sum_bio     (:,:,:) = 0.e0     ;   tmltrd_csum_ln_bio (:,:,:) = 0.e0
-      DO jl = 1, jp_pisces_trd
-          ctrd_bio(jl,1) = ctrbil(jl)   ! long name
-          ctrd_bio(jl,2) = ctrbio(jl)   ! short name
-       ENDDO
-#endif
-
-      IF( ln_rsttr .AND. ln_trdmld_trc_restart ) THEN
-         CALL trd_mld_trc_rst_read
-      ELSE
-         tmlb_trc           (:,:,:)   = 0.e0   ;   tmlbb_trc          (:,:,:)   = 0.e0     ! inst.
-         tmlbn_trc          (:,:,:)   = 0.e0
-
-         tml_sumb_trc       (:,:,:)   = 0.e0   ;   tmltrd_csum_ub_trc (:,:,:,:) = 0.e0     ! mean
-         tmltrd_atf_sumb_trc(:,:,:)   = 0.e0   ;   tmltrd_rad_sumb_trc(:,:,:)   = 0.e0 
-#if defined key_pisces_reduced
-         tmltrd_csum_ub_bio (:,:,:) = 0.e0
-#endif
-
-       ENDIF
-
-      icount = 1   ;   ionce  = 1  ! open specifier   
-
-#if defined key_pisces_reduced
-      icountbio = 1   ;   ioncebio  = 1  ! open specifier
-#endif
-
-      ! I.3 Read control surface from file ctlsurf_idx
-      ! ----------------------------------------------
-      IF( nn_ctls_trc == 1 ) THEN
-         CALL ctl_opn( inum, 'ctlsurf_idx', 'OLD', 'UNFORMATTED', 'SEQUENTIAL', -1, numout, lwp )
-         READ ( inum ) nbol_trc
-         CLOSE( inum )
-      ENDIF
-
-      ! ======================================================================
-      ! II. netCDF output initialization
-      ! ======================================================================
-
-#if defined key_dimgout 
-      ???
-#else
-      ! clmxl = legend root for netCDF output
-      IF( nn_ctls_trc == 0 ) THEN                                   ! control surface = mixed-layer with density criterion
-         clmxl = 'Mixed Layer '
-      ELSE IF( nn_ctls_trc == 1 ) THEN                              ! control surface = read index from file 
-         clmxl = '      Bowl '
-      ELSE IF( nn_ctls_trc >= 2 ) THEN                              ! control surface = model level
-         WRITE(clmxl,'(A10,I2,1X)') 'Levels 1 -', nn_ctls_trc
-      ENDIF
-
-      ! II.1 Define frequency of output and means
-      ! -----------------------------------------
-      IF( ln_mskland )   THEN   ;   clop = "only(x)"   ! put 1.e+20 on land (very expensive!!)
-      ELSE                      ;   clop = "x"         ! no use of the mask value (require less cp time)
-      ENDIF
-#  if defined key_diainstant
-      IF( .NOT. ln_trdmld_trc_instant ) THEN
-         STOP 'trd_mld_trc : this was never checked. Comment this line to proceed...'
-      ENDIF
-      zsto = nn_trd_trc * rdt
-      clop = "inst("//TRIM(clop)//")"
-#  else
-      IF( ln_trdmld_trc_instant ) THEN
-         zsto = rdt                                               ! inst. diags : we use IOIPSL time averaging
-      ELSE
-         zsto = nn_trd_trc * rdt                                    ! mean  diags : we DO NOT use any IOIPSL time averaging
-      ENDIF
-      clop = "ave("//TRIM(clop)//")"
-#  endif
-      zout = nn_trd_trc * rdt
-      iiter = ( nittrc000 - 1 ) / nn_dttrc
-
-      IF(lwp) WRITE (numout,*) '                netCDF initialization'
-
-      ! II.2 Compute julian date from starting date of the run
-      ! ------------------------------------------------------
-      CALL ymds2ju( nyear, nmonth, nday, rdt, zjulian )
-      zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
-      IF(lwp) WRITE(numout,*)' '  
-      IF(lwp) WRITE(numout,*)' Date 0 used :', nittrc000               &
-           &   ,' YEAR ', nyear, ' MONTH ', nmonth,' DAY ', nday       &
-           &   ,'Julian day : ', zjulian
-
-      ! II.3 Define the T grid trend file (nidtrd)
-      ! ------------------------------------------
-
-      !-- Define long and short names for the NetCDF output variables
-      !       ==> choose them according to trdmld_trc_oce.F90 <==
-
-      ctrd_trc(jpmld_trc_xad    ,1) = " Zonal advection"                 ;   ctrd_trc(jpmld_trc_xad    ,2) = "_xad"
-      ctrd_trc(jpmld_trc_yad    ,1) = " Meridional advection"            ;   ctrd_trc(jpmld_trc_yad    ,2) = "_yad"
-      ctrd_trc(jpmld_trc_zad    ,1) = " Vertical advection"              ;   ctrd_trc(jpmld_trc_zad    ,2) = "_zad"
-      ctrd_trc(jpmld_trc_ldf    ,1) = " Lateral diffusion"               ;   ctrd_trc(jpmld_trc_ldf    ,2) = "_ldf"
-      ctrd_trc(jpmld_trc_zdf    ,1) = " Vertical diff. (Kz)"             ;   ctrd_trc(jpmld_trc_zdf    ,2) = "_zdf"
-      ctrd_trc(jpmld_trc_bbl    ,1) = " Adv/diff. Bottom boundary layer" ;   ctrd_trc(jpmld_trc_bbl    ,2) = "_bbl"
-      ctrd_trc(jpmld_trc_dmp    ,1) = " Tracer damping"                  ;   ctrd_trc(jpmld_trc_dmp    ,2) = "_dmp"
-      ctrd_trc(jpmld_trc_sbc    ,1) = " Surface boundary cond."          ;   ctrd_trc(jpmld_trc_sbc    ,2) = "_sbc"
-      ctrd_trc(jpmld_trc_sms,    1) = " Sources minus sinks"             ;   ctrd_trc(jpmld_trc_sms    ,2) = "_sms"
-      ctrd_trc(jpmld_trc_radb   ,1) = " Correct negative concentrations" ;   ctrd_trc(jpmld_trc_radb   ,2) = "_radb"
-      ctrd_trc(jpmld_trc_radn   ,1) = " Correct negative concentrations" ;   ctrd_trc(jpmld_trc_radn   ,2) = "_radn"
-      ctrd_trc(jpmld_trc_atf    ,1) = " Asselin time filter"             ;   ctrd_trc(jpmld_trc_atf    ,2) = "_atf"
-
-      DO jn = 1, jptra      
-      !-- Create a NetCDF file and enter the define mode 
-         IF( ln_trdtrc(jn) ) THEN
-            csuff="ML_"//ctrcnm(jn)
-            CALL dia_nam( clhstnam, nn_trd_trc, csuff )
-            CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,                                            &
-               &        1, jpi, 1, jpj, iiter, zjulian, rdt, nh_t(jn), nidtrd(jn), domain_id=nidom, snc4chunks=snc4set )
-      
-            !-- Define the ML depth variable
-            CALL histdef(nidtrd(jn), "mxl_depth", clmxl//" Mixed Layer Depth", "m",                        &
-               &        jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-
-         ENDIF
-      END DO
-
-#if defined key_pisces_reduced
-          !-- Create a NetCDF file and enter the define mode
-          CALL dia_nam( clhstnam, nn_trd_trc, 'trdbio' )
-          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,                                            &
-             &             1, jpi, 1, jpj, iiter, zjulian, rdt, nh_tb, nidtrdbio, domain_id=nidom, snc4chunks=snc4set )
-#endif
-
-      !-- Define physical units
-      IF( rn_ucf_trc == 1. ) THEN
-         cltrcu = "(mmole-N/m3)/sec"                              ! all passive tracers have the same unit 
-      ELSEIF ( rn_ucf_trc == 3600.*24.) THEN                         ! ??? trop long : seulement (mmole-N/m3)
-         cltrcu = "(mmole-N/m3)/day"                              ! ??? apparait dans les sorties netcdf 
-      ELSE
-         cltrcu = "unknown?"
-      ENDIF
-
-      !-- Define miscellaneous passive tracer mixed-layer variables 
-      IF( jpltrd_trc /= jpmld_trc_atf .OR.  jpltrd_trc - 1 /= jpmld_trc_radb ) THEN
-         STOP 'Error : jpltrd_trc /= jpmld_trc_atf .OR.  jpltrd_trc - 1 /= jpmld_trc_radb'  ! see below
-      ENDIF
-
-      DO jn = 1, jptra
-         !
-         IF( ln_trdtrc(jn) ) THEN
-            clvar = trim(ctrcnm(jn))//"ml"                           ! e.g. detml, zooml, no3ml, etc.
-            CALL histdef(nidtrd(jn), trim(clvar),           clmxl//" "//trim(ctrcnm(jn))//" Mixed Layer ",                         &
-              & "mmole-N/m3", jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zsto, zout )           
-            CALL histdef(nidtrd(jn), trim(clvar)//"_tot"  , clmxl//" "//trim(ctrcnm(jn))//" Total trend ",                         & 
-              &       cltrcu, jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zout, zout ) 
-            CALL histdef(nidtrd(jn), trim(clvar)//"_res"  , clmxl//" "//trim(ctrcnm(jn))//" dh/dt Entrainment (Resid.)",           & 
-              &       cltrcu, jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zout, zout )                   
-         
-            DO jl = 1, jpltrd_trc - 2                                ! <== only true if jpltrd_trc == jpmld_trc_atf
-               CALL histdef(nidtrd(jn), trim(clvar)//trim(ctrd_trc(jl,2)), clmxl//" "//clvar//ctrd_trc(jl,1),                      & 
-                 &    cltrcu, jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zsto, zout ) ! IOIPSL: time mean
-            END DO                                                                         ! if zsto=rdt above
-         
-            CALL histdef(nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmld_trc_radb,2)), clmxl//" "//clvar//ctrd_trc(jpmld_trc_radb,1), & 
-              &       cltrcu, jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zout, zout ) ! IOIPSL: NO time mean
-         
-            CALL histdef(nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmld_trc_atf,2)), clmxl//" "//clvar//ctrd_trc(jpmld_trc_atf,1),   & 
-              &       cltrcu, jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zout, zout ) ! IOIPSL: NO time mean
-         !
-         ENDIF
-      END DO
-
-#if defined key_pisces_reduced
-      DO jl = 1, jp_pisces_trd
-         CALL histdef(nidtrdbio, TRIM("ML_"//ctrd_bio(jl,2)), TRIM(clmxl//" ML_"//ctrd_bio(jl,1))   ,            &
-             &    cltrcu, jpi, jpj, nh_tb, 1  , 1, 1  , -99 , 32, clop, zsto, zout ) ! IOIPSL: time mean
-      END DO                                                                         ! if zsto=rdt above
-#endif
-
-      !-- Leave IOIPSL/NetCDF define mode
-      DO jn = 1, jptra
-         IF( ln_trdtrc(jn) )  CALL histend( nidtrd(jn), snc4set )
-      END DO
-
-#if defined key_pisces_reduced
-      !-- Leave IOIPSL/NetCDF define mode
-      CALL histend( nidtrdbio, snc4set )
-
-      IF(lwp) WRITE(numout,*)
-       IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization for ML bio trends'
-#endif
-
-#endif        /* key_dimgout */
-   END SUBROUTINE trd_mld_trc_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                       Empty module
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE trd_mld_trc( kt )                                   ! Empty routine
-      INTEGER, INTENT( in) ::   kt
-      WRITE(*,*) 'trd_mld_trc: You should not have seen this print! error?', kt
-   END SUBROUTINE trd_mld_trc
-   SUBROUTINE trd_mld_bio( kt )
-      INTEGER, INTENT( in) ::   kt
-      WRITE(*,*) 'trd_mld_bio: You should not have seen this print! error?', kt
-   END SUBROUTINE trd_mld_bio
-   SUBROUTINE trd_mld_trc_zint( ptrc_trdmld, ktrd, ctype, kjn )
-      INTEGER               , INTENT( in ) ::  ktrd, kjn              ! ocean trend index and passive tracer rank
-      CHARACTER(len=2)      , INTENT( in ) ::  ctype                  ! surface/bottom (2D) or interior (3D) physics
-      REAL, DIMENSION(:,:,:), INTENT( in ) ::  ptrc_trdmld            ! passive trc trend
-      WRITE(*,*) 'trd_mld_trc_zint: You should not have seen this print! error?', ptrc_trdmld(1,1,1)
-      WRITE(*,*) '  "      "      : You should not have seen this print! error?', ctype
-      WRITE(*,*) '  "      "      : You should not have seen this print! error?', ktrd
-      WRITE(*,*) '  "      "      : You should not have seen this print! error?', kjn
-   END SUBROUTINE trd_mld_trc_zint
-   SUBROUTINE trd_mld_trc_init                                    ! Empty routine
-      WRITE(*,*) 'trd_mld_trc_init: You should not have seen this print! error?'
-   END SUBROUTINE trd_mld_trc_init
-#endif
-
-   !!======================================================================
-END MODULE trdmld_trc
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdmld_trc_rst.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdmld_trc_rst.F90	(revision 4944)
+++ 	(revision )
@@ -1,220 +1,0 @@
-MODULE trdmld_trc_rst
-   !!======================================================================
-   !!                       ***  MODULE  trdmld_rst  ***
-   !! Ocean dynamic :  Input/Output files for restart on mixed-layer diagnostics
-   !!======================================================================
-   !! History :  9.0  ! 07-03 (C. Deltel) Original code
-   !!----------------------------------------------------------------------
-  
-#if defined key_top && defined key_trdmld_trc
-   !!----------------------------------------------------------------------
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O module
-   USE trc             ! for nn_dttrc ctrcnm
-   USE trdmod_trc_oce  ! for lk_trdmld_trc
-
-   IMPLICIT NONE
-   PRIVATE
-  
-   PUBLIC   trd_mld_trc_rst_read    ! routine called by trd_mld_init
-   PUBLIC   trd_mld_trc_rst_write   ! routine called by step.F90
-  
-   INTEGER ::   nummldw_trc               ! logical unit for mld restart
-   !!---------------------------------------------------------------------------------
-   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
-   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/TRD/trdmld_rst.F90,v 1.6 2006/11/14 09:46:13 opalod Exp $ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!---------------------------------------------------------------------------------
-  
-CONTAINS
-  
-
-    SUBROUTINE trd_mld_trc_rst_write( kt )
-      !!--------------------------------------------------------------------------------
-      !!                  ***  SUBROUTINE trd_mld_rst_wri  ***
-      !!                
-      !! ** Purpose :   Write mixed-layer diagnostics restart fields.
-      !!--------------------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
-      !
-      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
-      CHARACTER(LEN=50)   ::   clname   ! ice output restart file name
-      CHARACTER (len=35) :: charout
-      INTEGER :: jl,  jk, jn               ! loop indice
-      !!--------------------------------------------------------------------------------
-
-      IF( kt == nitrst - nn_dttrc .OR. nitend - nit000 + 1 < 2 * nn_dttrc ) THEN ! idem trcrst.F90
-         IF( nitrst > 1.0e9 ) THEN
-            WRITE(clkt,*) nitrst
-         ELSE
-           WRITE(clkt,'(i8.8)') nitrst
-         ENDIF
-         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_trdrst_trc_out)
-         IF(lwp) WRITE(numout,*) '             open ocean restart_mld_trc NetCDF  '//clname
-         CALL iom_open( clname, nummldw_trc, ldwrt = .TRUE., kiolib = jprstlib )
-      ENDIF
-
-      IF( kt == nitend .AND. lk_trdmld_trc ) THEN
-
-         IF( kt == nitend .AND. lwp ) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) 'trdmld_trc_rst: output for ML diags. restart, with trd_mld_trc_rst_write routine'
-            WRITE(numout,*) '~~~~~~~~~~~~~~'
-            WRITE(numout,*)
-         ENDIF
-
-         IF( ln_trdmld_trc_instant ) THEN 
-            !
-            DO jn = 1, jptra
-               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlbb_trc_'  //ctrcnm(jn), tmlbb_trc  (:,:,jn) )
-               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlbn_trc_'  //ctrcnm(jn), tmlbn_trc  (:,:,jn) )
-               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlatfb_trc_'//ctrcnm(jn), tmlatfb_trc(:,:,jn) )
-               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlradb_trc_'//ctrcnm(jn), tmlradb_trc(:,:,jn) )
-            END DO
-            !
-         ELSE
-            !
-            CALL iom_rstput( kt, nitrst, nummldw_trc, 'rmldbn_trc', rmldbn_trc )  ! 2D x 1
-            
-            !                                                          ! ===========
-            DO jn = 1, jptra                                           ! tracer loop
-               !                                                       ! ===========
-
-               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlatfb_trc_' //ctrcnm(jn), tmlatfb_trc (:,:,jn) ) ! 2D x jptra
-               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlbb_trc_'   //ctrcnm(jn), tmlbb_trc   (:,:,jn) ) ! 2D x jptra
-               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlradb_trc_' //ctrcnm(jn), tmlradb_trc (:,:,jn) ) ! 2D x jptra
-
-               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlbn_trc_'   //ctrcnm(jn), tmlbn_trc   (:,:,jn) ) ! 2D x jptra
-               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tml_sumb_trc_'//ctrcnm(jn), tml_sumb_trc(:,:,jn) ) ! 2D x jptra
-               
-               DO jk = 1, jpltrd_trc
-                  IF( jk < 10 )   THEN
-                     WRITE(charout,FMT="('tmltrd_csum_ub_trc_', A3, '_', I1)") ctrcnm(jn), jk
-                  ELSE
-                     WRITE(charout,FMT="('tmltrd_csum_ub_trc_', A3, '_', I2)") ctrcnm(jn), jk
-                  ENDIF
-                  CALL iom_rstput( kt, nitrst, nummldw_trc, charout, tmltrd_csum_ub_trc(:,:,jk,jn) )
-               END DO
-               
-               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmltrd_atf_sumb_trc_'//ctrcnm(jn) , &
-                    &           tmltrd_atf_sumb_trc(:,:,jn) ) ! 2D x jptra
-
-               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmltrd_rad_sumb_trc_'//ctrcnm(jn) , &
-                    &           tmltrd_rad_sumb_trc(:,:,jn) ) ! 2D x jptra
-               !                                                       ! ===========
-            END DO                                                     ! tracer loop
-            !                                                          ! ===========
-#if defined key_pisces_reduced
-            DO jl = 1, jp_pisces_trd
-               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmltrd_csum_ub_bio'//ctrd_bio(jl,2), tmltrd_csum_ub_bio(:,:,jl) )
-            ENDDO
-#endif
-
-         ENDIF
-         
-         CALL iom_close( nummldw_trc )
-         lrst_trc = .TRUE.
-
-      ENDIF
-
-    END SUBROUTINE trd_mld_trc_rst_write
-
-
-    SUBROUTINE trd_mld_trc_rst_read
-      !!----------------------------------------------------------------------------
-      !!                   ***  SUBROUTINE trd_mld_rst_lec  ***
-      !!                   
-      !! ** Purpose :   Read file for mixed-layer diagnostics restart.
-      !!----------------------------------------------------------------------------
-      INTEGER  ::  inum       ! temporary logical unit
-      !
-      CHARACTER (len=35) :: charout
-      INTEGER ::  jk, jn, jl     ! loop indice
-      INTEGER ::  jlibalt = jprstlib
-      LOGICAL ::  llok
-      !!-----------------------------------------------------------------------------
-      
-      IF(lwp)  THEN
-         WRITE(numout,*)
-         WRITE(numout,*) ' trd_mld_trc_rst_read : read the NetCDF MLD restart file'
-         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~'
-      ENDIF
-      
-      IF ( jprstlib == jprstdimg ) THEN
-        ! eventually read netcdf file (monobloc)  for restarting on different number of processors
-        ! if {cn_trdrst_trc_in}.nc exists, then set jlibalt to jpnf90
-        INQUIRE( FILE = TRIM(cn_trdrst_trc_in)//'.nc', EXIST = llok )
-        IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
-      ENDIF
-
-      CALL iom_open( cn_trdrst_trc_in, inum, kiolib = jlibalt ) 
-      
-      IF( ln_trdmld_trc_instant ) THEN 
-         
-         DO jn = 1, jptra
-            CALL iom_get( inum, jpdom_autoglo, 'tmlbb_trc_'  //ctrcnm(jn), tmlbb_trc  (:,:,jn) )
-            CALL iom_get( inum, jpdom_autoglo, 'tmlbn_trc_'  //ctrcnm(jn), tmlbn_trc  (:,:,jn) )
-            CALL iom_get( inum, jpdom_autoglo, 'tmlatfb_trc_'//ctrcnm(jn), tmlatfb_trc(:,:,jn) )
-            CALL iom_get( inum, jpdom_autoglo, 'tmlradb_trc_'//ctrcnm(jn), tmlradb_trc(:,:,jn) )
-         END DO
-         
-      ELSE
-         CALL iom_get( inum, jpdom_autoglo, 'rmldbn_trc', rmldbn_trc ) ! needed for rmld_sum
-         
-         !                                                          ! ===========
-         DO jn = 1, jptra                                           ! tracer loop
-            !                                                       ! ===========
-            CALL iom_get( inum, jpdom_autoglo, 'tmlatfb_trc_' //ctrcnm(jn), tmlatfb_trc(:,:,jn) )
-            CALL iom_get( inum, jpdom_autoglo, 'tmlbb_trc_'   //ctrcnm(jn), tmlbb_trc  (:,:,jn) )
-            CALL iom_get( inum, jpdom_autoglo, 'tmlradb_trc_' //ctrcnm(jn), tmlradb_trc(:,:,jn) )
-
-            CALL iom_get( inum, jpdom_autoglo, 'tmlbn_trc_'   //ctrcnm(jn), tmlbn_trc   (:,:,jn) ) ! needed for tml_sum
-            CALL iom_get( inum, jpdom_autoglo, 'tml_sumb_trc_'//ctrcnm(jn), tml_sumb_trc(:,:,jn) )
-            
-            DO jk = 1, jpltrd_trc
-               IF( jk < 10 )   THEN
-                  WRITE(charout,FMT="('tmltrd_csum_ub_trc_', A3, '_', I1)") ctrcnm(jn), jk
-               ELSE
-                  WRITE(charout,FMT="('tmltrd_csum_ub_trc_', A3, '_', I2)") ctrcnm(jn), jk
-               ENDIF
-               CALL iom_get( inum, jpdom_autoglo, charout, tmltrd_csum_ub_trc(:,:,jk,jn) )
-            END DO
-            
-            CALL iom_get( inum, jpdom_autoglo, 'tmltrd_atf_sumb_trc_'//ctrcnm(jn) , &
-                 &        tmltrd_atf_sumb_trc(:,:,jn) )
-
-            CALL iom_get( inum, jpdom_autoglo, 'tmltrd_rad_sumb_trc_'//ctrcnm(jn) , &
-                 &        tmltrd_rad_sumb_trc(:,:,jn) )
-            !                                                       ! ===========
-         END DO                                                     ! tracer loop
-         !                                                          ! ===========
-
-#if defined key_pisces_reduced
-         DO jl = 1, jp_pisces_trd
-            CALL iom_get( inum, jpdom_autoglo, 'tmltrd_csum_ub_bio'//ctrd_bio(jl,2), tmltrd_csum_ub_bio(:,:,jl) )
-         ENDDO
-#endif
-         
-         CALL iom_close( inum )
-      ENDIF
-      
-    END SUBROUTINE trd_mld_trc_rst_read
-  
-#else
-  !!=================================================================================
-  !!                       ***  MODULE  trdmld_rst  ***
-  !! Ocean dynamic :  Input/Output files for restart on mixed-layer diagnostics
-  !!=================================================================================
-CONTAINS
-  SUBROUTINE trd_mld_trc_rst_opn( kt )
-    WRITE(*,*) 'trd_mld_trc_rst_opn: You should not have seen this print! error?', kt
-  END SUBROUTINE trd_mld_trc_rst_opn
-  SUBROUTINE trd_mld_trc_rst_write( kt )           !  No ML diags ==> empty routine
-    WRITE(*,*) 'trd_mld_trc_rst_wri: You should not have seen this print! error?', kt
-  END SUBROUTINE trd_mld_trc_rst_write
-  SUBROUTINE trd_mld_trc_rst_read                  !  No ML Diags ==> empty routine
-  END SUBROUTINE trd_mld_trc_rst_read
-#endif
-
-  !!=================================================================================
-END MODULE trdmld_trc_rst
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdmod_trc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdmod_trc.F90	(revision 4944)
+++ 	(revision )
@@ -1,158 +1,0 @@
-MODULE trdmod_trc
-   !!======================================================================
-   !!                       ***  MODULE  trdmod_trc  ***
-   !! Ocean diagnostics:  mixed layer passive tracer trends 
-   !!======================================================================
-   !! History :  3.0  !  2010-07  (C. Ethe)  Original code (from trdmod.F90)
-   !!----------------------------------------------------------------------
-#if   defined key_top && ( defined key_trdmld_trc   ||   defined key_trdtrc )
-   !!----------------------------------------------------------------------
-   !!   'key_trdmld_trc'                  mixed layer trend diagnostics
-   !!   'key_trdtrc'                      3D trend diagnostics
-   !!----------------------------------------------------------------------
-   !!   trd_mod_trc      : passive tracer trends 
-   !!----------------------------------------------------------------------
-   USE trc               ! tracer definitions (trn, trb, tra, etc.)
-   USE trcnam_trp
-   USE trdmod_oce
-   USE trdmod_trc_oce    ! definition of main arrays used for trends computations
-   USE trdmld_trc        ! Mixed layer trends diag.
-   USE iom               ! I/O library
-
-   IMPLICIT NONE
-   PRIVATE
-
-   INTERFACE trd_mod_trc
-      MODULE PROCEDURE trd_mod_trc_trp, trd_mod_trc_bio
-   END INTERFACE
-
-   PUBLIC trd_mod_trc
-
-   !! * Substitutions
-#  include "top_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
-   !! $Header:  $ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE trd_mod_trc_trp( ptrtrd, kjn, ktrd, kt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mod_trc  ***
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in )  ::   kt                                  ! time step
-      INTEGER, INTENT( in )  ::   kjn                                 ! tracer index
-      INTEGER, INTENT( in )  ::   ktrd                                ! tracer trend index
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout )  ::   ptrtrd  ! Temperature or U trend
-      CHARACTER (len=20) :: cltra
-      !!----------------------------------------------------------------------
-
-      IF( kt == nittrc000 ) THEN
-!         IF(lwp)WRITE(numout,*)
-!         IF(lwp)WRITE(numout,*) 'trd_mod_trc:'
-!         IF(lwp)WRITE(numout,*) '~~~~~~~~~~~~'
-      ENDIF
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Mixed layer trends for passive tracers
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-#if defined key_trdmld_trc  
-      IF( lk_trdmld_trc .AND. ln_trdtrc( kjn ) ) THEN
-         !
-         SELECT CASE ( ktrd )
-         CASE ( jptra_trd_xad     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_xad, '3D', kjn )
-         CASE ( jptra_trd_yad     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_yad, '3D', kjn )
-         CASE ( jptra_trd_zad     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_zad, '3D', kjn )
-         CASE ( jptra_trd_ldf     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_ldf, '3D', kjn )
-         CASE ( jptra_trd_bbl     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_bbl, '3D', kjn )
-         CASE ( jptra_trd_zdf     )
-            IF( ln_trcldf_iso ) THEN
-               CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_ldf, '3D', kjn )
-            ELSE
-               CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_zdf, '3D', kjn )
-            ENDIF
-         CASE ( jptra_trd_dmp     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_dmp , '3D', kjn )
-         CASE ( jptra_trd_nsr     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_sbc , '2D', kjn )
-         CASE ( jptra_trd_sms     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_sms , '3D', kjn )
-         CASE ( jptra_trd_radb    )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_radb, '3D', kjn )
-         CASE ( jptra_trd_radn    )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_radn, '3D', kjn )
-         CASE ( jptra_trd_atf     )   ;   CALL trd_mld_trc_zint( ptrtrd, jpmld_trc_atf , '3D', kjn )
-         END SELECT
-         !
-      END IF
-#endif
-
-      IF( lk_trdtrc .AND. ln_trdtrc( kjn ) ) THEN
-         !
-         SELECT CASE( ktrd )
-         CASE( jptra_trd_xad  )       ;    WRITE (cltra,'("XAD_",4a)')
-         CASE( jptra_trd_yad  )       ;    WRITE (cltra,'("YAD_",4a)')
-         CASE( jptra_trd_zad  )       ;    WRITE (cltra,'("ZAD_",4a)')
-         CASE( jptra_trd_ldf  )       ;    WRITE (cltra,'("LDF_",4a)')
-         CASE( jptra_trd_bbl  )       ;    WRITE (cltra,'("BBL_",4a)')
-         CASE( jptra_trd_nsr  )       ;    WRITE (cltra,'("FOR_",4a)')
-         CASE( jptra_trd_zdf  )       ;    WRITE (cltra,'("ZDF_",4a)')
-         CASE( jptra_trd_dmp  )       ;    WRITE (cltra,'("DMP_",4a)')
-         CASE( jptra_trd_sms  )       ;    WRITE (cltra,'("SMS_",4a)')
-         CASE( jptra_trd_atf  )       ;    WRITE (cltra,'("ATF_",4a)')
-         CASE( jptra_trd_radb )       ;    WRITE (cltra,'("RDB_",4a)')
-         CASE( jptra_trd_radn )       ;    WRITE (cltra,'("RDN_",4a)')
-         END SELECT
-                                          cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
-                                          CALL iom_put( cltra,  ptrtrd(:,:,:) )
-         !
-      END IF
-
-   END SUBROUTINE trd_mod_trc_trp
-
-   SUBROUTINE trd_mod_trc_bio( ptrbio, ktrd, kt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE trd_mod_bio  ***
-      !!----------------------------------------------------------------------
-
-      INTEGER, INTENT( in )  ::   kt                                  ! time step
-      INTEGER, INTENT( in )  ::   ktrd                                ! bio trend index
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout )  ::   ptrbio  ! Bio trend
-      !!----------------------------------------------------------------------
-
-#if defined key_trdmld_trc  
-      CALL trd_mld_bio_zint( ptrbio, ktrd ) ! Verticaly integrated biological trends
-#endif
-
-   END SUBROUTINE trd_mod_trc_bio
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                       Empty module
-   !!----------------------------------------------------------------------
-
-   INTERFACE trd_mod_trc
-      MODULE PROCEDURE trd_mod_trc_trp, trd_mod_trc_bio
-   END INTERFACE
-
-CONTAINS
-
-   SUBROUTINE trd_mod_trc_trp( ptrtrd, kjn, ktrd, kt )
-      INTEGER               , INTENT( in )     ::   kt      ! time step
-      INTEGER               , INTENT( in )     ::   kjn     ! tracer index
-      INTEGER               , INTENT( in )     ::   ktrd    ! tracer trend index
-      REAL, DIMENSION(:,:,:), INTENT( inout )  ::   ptrtrd  ! Temperature or U trend
-      WRITE(*,*) 'trd_mod_trc_trp : You should not have seen this print! error?', ptrtrd(1,1,1)
-      WRITE(*,*) '  "      "      : You should not have seen this print! error?', kjn
-      WRITE(*,*) '  "      "      : You should not have seen this print! error?', ktrd
-      WRITE(*,*) '  "      "      : You should not have seen this print! error?', kt
-   END SUBROUTINE trd_mod_trc_trp
-
-   SUBROUTINE trd_mod_trc_bio( ptrbio, ktrd, kt )
-      INTEGER               , INTENT( in )     ::   kt      ! time step
-      INTEGER               , INTENT( in )     ::   ktrd    ! tracer trend index
-      REAL, DIMENSION(:,:,:), INTENT( inout )  ::   ptrbio  ! Temperature or U trend
-      WRITE(*,*) 'trd_mod_trc_trp : You should not have seen this print! error?', ptrbio(1,1,1)
-      WRITE(*,*) '  "      "      : You should not have seen this print! error?', ktrd
-      WRITE(*,*) '  "      "      : You should not have seen this print! error?', kt
-   END SUBROUTINE trd_mod_trc_bio
-
-#endif
-   !!======================================================================
-END MODULE trdmod_trc
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdmod_trc_oce.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdmod_trc_oce.F90	(revision 4944)
+++ 	(revision )
@@ -1,180 +1,0 @@
-MODULE trdmod_trc_oce
-   !!======================================================================
-   !!                   ***  MODULE trdmod_trc_oce  ***
-   !! Ocean trends :   set tracer and momentum trend variables
-   !!======================================================================
-#if defined key_top   ||   defined key_esopa
-   !!----------------------------------------------------------------------
-   !!   'key_top'                                                TOP models
-   !!----------------------------------------------------------------------
-   USE par_oce       ! ocean parameters
-   USE par_trc       ! passive tracers parameters
-
-   IMPLICIT NONE
-   PUBLIC
-
-   !                                         !!* Namelist namtoptrd:  diagnostics on passive tracers trends
-   INTEGER  ::    nn_trd_trc                  !: time step frequency dynamics and tracers trends
-   INTEGER  ::    nn_ctls_trc                 !: control surface type for trends vertical integration
-   REAL(wp) ::    rn_ucf_trc                  !: unit conversion factor (for netCDF trends outputs)
-   LOGICAL  ::    ln_trdmld_trc_instant       !: flag to diagnose inst./mean ML trc trends
-   LOGICAL  ::    ln_trdmld_trc_restart       !: flag to restart mixed-layer trc diagnostics
-   CHARACTER(len=50) ::  cn_trdrst_trc_in     !: suffix of pass. tracer restart name (input)
-   CHARACTER(len=50) ::  cn_trdrst_trc_out    !: suffix of pass. tracer restart name (output)
-   LOGICAL, DIMENSION(jptra) ::   ln_trdtrc   !: large trends diagnostic to write or not (namelist)
-
-# if defined key_trdtrc && defined key_iomput
-   LOGICAL, PARAMETER ::   lk_trdtrc = .TRUE. 
-# else
-   LOGICAL, PARAMETER ::   lk_trdtrc = .FALSE.   !: ML trend flag
-# endif
-
-# if defined key_trdmld_trc   ||   defined key_esopa
-   !!----------------------------------------------------------------------
-   !!   'key_trdmld_trc'                     mixed layer trends diagnostics
-   !!----------------------------------------------------------------------
-
-   LOGICAL, PARAMETER ::   lk_trdmld_trc = .TRUE.    !: ML trend flag
-
-   INTEGER, PARAMETER ::            & !: mixed layer trends indices
-        jpmld_trc_xad     =  1,     & !:     zonal       advection     
-        jpmld_trc_yad     =  2,     & !:     meridonal   =========
-        jpmld_trc_zad     =  3,     & !:     vertical    =========
-        jpmld_trc_ldf     =  4,     & !:     lateral diffusion (geopot. or iso-neutral)
-        jpmld_trc_zdf     =  5,     & !:     vertical diffusion (TKE)
-        jpmld_trc_bbl     =  6,     & !:     bottom boundary layer (advective/diffusive)
-        jpmld_trc_dmp     =  7,     & !:     internal restoring trend
-        jpmld_trc_sbc     =  8,     & !:     forcing 
-        jpmld_trc_sms     =  9,     & !:     sources minus sinks trend
-  !     jpmld_trc_xxx     = xx,     & !:     add here any additional trend    (** AND UPDATE JPLTRD_TRC BELOW **)
-        jpmld_trc_radn    = 10,     & !:     corr. trn<0 in trcrad
-        jpmld_trc_radb    = 11,     & !:     corr. trb<0 in trcrad (like atf) (** MUST BE BEFORE THE LAST ONE **)
-        jpmld_trc_atf     = 12        !:     asselin trend                    (** MUST BE    THE      LAST ONE**)
-
-   !! Trends diagnostics parameters
-   !!---------------------------------------------------------------------
-   INTEGER, PARAMETER :: jpltrd_trc = 12    !: number of mixed-layer trends arrays
-      
-   INTEGER            :: jpktrd_trc         !: max level for mixed-layer trends diag.
-
-   !! Arrays used for diagnosing mixed-layer trends 
-   !!---------------------------------------------------------------------
-   CHARACTER(LEN=80) :: clname_trc, ctrd_trc(jpltrd_trc+1,2)
-
-   INTEGER, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   &
-      nmld_trc       , &                            !: mixed layer depth indexes 
-      nbol_trc                                   !: mixed-layer depth indexes when read from file
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  wkx_trc  !:
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  rmld_trc     !: ML depth (m) corresponding to nmld_trc
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  rmld_sum_trc !: needed to compute the leap-frog time mean of ML depth
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  rmldbn_trc   !: idem
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  &
-      tml_trc    ,                        &      !: \ "now" mixed layer temperature/salinity
-      tmlb_trc   ,                        &      !: /  and associated "before" fields
-      tmlbb_trc  ,                        &      !: \  idem, but valid at the 1rst time step of the
-      tmlbn_trc  ,                        &      !: /  current analysis window
-      tml_sum_trc,                        &      !: mixed layer T, summed over the current analysis period
-      tml_sumb_trc,                       &      !: idem, but from the previous analysis period
-      tmltrd_atf_sumb_trc,                &      !: Asselin trends, summed over the previous analysis period
-      tmltrd_rad_sumb_trc                        !: trends due to trb correction in trcrad.F90, summed over the
-                                                 !:     previous analysis period
-                                                 
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  &      
-      tmlatfb_trc, tmlatfn_trc ,          &      !: "before" Asselin contrib. at beginning of the averaging
-                                                 !:     period (i.e. last contrib. from previous such period)
-                                                 !:     and "now" Asselin contrib. to the ML trc. trends
-      tmlatfm_trc,                        &      !: accumulator for Asselin trends (needed for storage only)
-      tmlradb_trc, tmlradn_trc ,          &      !: similar to Asselin above, but for the trend due to trb
-                                                 !:     correction in trcrad.F90
-      tmlradm_trc                                !: accumulator for the previous trcrad trend
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  &
-      tmltrd_trc,                         &      !: \ physical contributions to the total trend (for T/S),
-                                                 !: / cumulated over the current analysis window
-      tmltrd_sum_trc,                     &      !: sum of these trends over the analysis period
-      tmltrd_csum_ln_trc,                 &      !: now cumulated sum of trends over the "lower triangle"
-      tmltrd_csum_ub_trc                         !: before (prev. analysis period) cumulated sum over the
-                                                 !: upper triangle
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  &
-      tmltrdm_trc                                !: total cumulative trends over the analysis window
-
-# else
-   LOGICAL, PARAMETER ::   lk_trdmld_trc = .FALSE.   !: ML trend flag
-# endif
-
-# if defined key_pisces_reduced
-   CHARACTER(LEN=80) :: clname_bio, ctrd_bio(jpdiabio,2)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  &
-      tmltrd_bio,                         &      !: \ biological contributions to the total trend ,
-                                                 !: / cumulated over the current analysis window
-      tmltrd_sum_bio,                     &      !: sum of these trends over the analysis period
-      tmltrd_csum_ln_bio,                 &      !: now cumulated sum of trends over the "lower triangle"
-      tmltrd_csum_ub_bio                         !: before (prev. analysis period) cumulated sum over the
-                                                 !: upper triangle
-#endif
-   !!----------------------------------------------------------------------
-   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
-   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/TRD/trdmld_oce.F90,v 1.2 2005/03/27 18:35:23 opalod Exp $ 
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION trd_mod_trc_oce_alloc()
-      !!----------------------------------------------------------------------
-      !!         *** ROUTINE trd_mod_trc_oce_alloc ***
-      !!----------------------------------------------------------------------
-      USE lib_mpp, ONLY: ctl_warn
-      INTEGER :: ierr(2)
-      !!----------------------------------------------------------------------
-      ierr(:) = 0
-      !
-# if defined key_trdmld_trc
-      ALLOCATE(nmld_trc(jpi,jpj),          nbol_trc(jpi,jpj),           &
-               wkx_trc(jpi,jpj,jpk),       rmld_trc(jpi,jpj),           &
-               rmld_sum_trc(jpi,jpj),      rmldbn_trc(jpi,jpj),         &
-               tml_trc(jpi,jpj,jptra),     tmlb_trc(jpi,jpj,jptra),     &
-               tmlbb_trc(jpi,jpj,jptra),   tmlbn_trc(jpi,jpj,jptra),    &
-               tml_sum_trc(jpi,jpj,jptra), tml_sumb_trc(jpi,jpj,jptra), &
-               tmltrd_atf_sumb_trc(jpi,jpj,jptra),                      &
-               tmltrd_rad_sumb_trc(jpi,jpj,jptra),                      &
-               !
-               tmlatfb_trc(jpi,jpj,jptra), tmlatfn_trc(jpi,jpj,jptra),  &
-               tmlatfm_trc(jpi,jpj,jptra), tmlradb_trc(jpi,jpj,jptra),  &
-               tmlradn_trc(jpi,jpj,jptra), tmlradm_trc(jpi,jpj,jptra),  &
-               !
-               tmltrd_trc(jpi,jpj,jpltrd_trc,jptra)         , &
-               tmltrd_sum_trc(jpi,jpj,jpltrd_trc,jptra)     , &
-               tmltrd_csum_ln_trc(jpi,jpj,jpltrd_trc,jptra) , &
-               tmltrd_csum_ub_trc(jpi,jpj,jpltrd_trc,jptra) , &
-               !
-               tmltrdm_trc(jpi,jpj,jptra)                   , STAT=ierr(1) )
-#endif
-      !
-# if defined key_pisces_reduced
-      ALLOCATE( tmltrd_bio        (jpi,jpj,jpdiabio) ,     &
-         &      tmltrd_sum_bio    (jpi,jpj,jpdiabio) ,     &
-         &      tmltrd_csum_ln_bio(jpi,jpj,jpdiabio) ,     &
-         &      tmltrd_csum_ub_bio(jpi,jpj,jpdiabio) , STAT=ierr(2) )
-# endif
-      !
-      trd_mod_trc_oce_alloc = MAXVAL(ierr)
-      !
-      IF( trd_mod_trc_oce_alloc /= 0 )   CALL ctl_warn('trd_mod_trc_oce_alloc: failed to allocate arrays')
-      !
-# if defined key_trdmld_trc
-      jpktrd_trc = jpk      ! Initialise what used to be a parameter - max level for mixed-layer trends diag.
-# endif
-      !
-   END FUNCTION trd_mod_trc_oce_alloc
-
-#else
-   !!----------------------------------------------------------------------
-   !!  Empty module :                                     No passive tracer
-   !!----------------------------------------------------------------------
-#endif
-
-   !!======================================================================
-END MODULE trdmod_trc_oce
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc.F90	(revision 4946)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc.F90	(revision 4946)
@@ -0,0 +1,1437 @@
+MODULE trdmxl_trc
+   !!======================================================================
+   !!                       ***  MODULE  trdmxl_trc  ***
+   !! Ocean diagnostics:  mixed layer passive tracer trends 
+   !!======================================================================
+   !! History :  9.0  !  06-08  (C. Deltel)  Original code (from trdmxl.F90)
+   !!                 !  07-04  (C. Deltel)  Bug fix : add trcrad trends
+   !!                 !  07-06  (C. Deltel)  key_gyre : do not call lbc_lnk
+   !!----------------------------------------------------------------------
+#if   defined key_top && ( defined key_trdmxl_trc   ||   defined key_esopa )
+   !!----------------------------------------------------------------------
+   !!   'key_trdmxl_trc'                      mixed layer trend diagnostics
+   !!----------------------------------------------------------------------
+   !!   trd_mxl_trc      : passive tracer cumulated trends averaged over ML
+   !!   trd_mxl_trc_zint : passive tracer trends vertical integration
+   !!   trd_mxl_trc_init : initialization step
+   !!----------------------------------------------------------------------
+   USE trc               ! tracer definitions (trn, trb, tra, etc.)
+   USE trc_oce, ONLY :   nn_dttrc  ! frequency of step on passive tracers
+   USE dom_oce           ! domain definition
+   USE zdfmxl  , ONLY : nmln ! number of level in the mixed layer
+   USE zdf_oce , ONLY : avt  ! vert. diffusivity coef. at w-point for temp  
+# if defined key_zdfddm   
+   USE zdfddm  , ONLY : avs  ! salinity vertical diffusivity coeff. at w-point
+# endif
+   USE trcnam_trp        ! passive tracers transport namelist variables
+   USE trdtrc_oce    ! definition of main arrays used for trends computations
+   USE in_out_manager    ! I/O manager
+   USE dianam            ! build the name of file (routine)
+   USE ldfslp            ! iso-neutral slopes 
+   USE ioipsl            ! NetCDF library
+   USE lbclnk            ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp           ! MPP library
+   USE trdmxl_trc_rst    ! restart for diagnosing the ML trends
+   USE prtctl            ! print control
+   USE sms_pisces        ! PISCES bio-model
+   USE wrk_nemo          ! Memory allocation
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trd_mxl_trc
+   PUBLIC trd_mxl_trc_alloc
+   PUBLIC trd_mxl_bio
+   PUBLIC trd_mxl_trc_init
+   PUBLIC trd_mxl_trc_zint
+   PUBLIC trd_mxl_bio_zint
+
+   CHARACTER (LEN=40) ::  clhstnam                                ! name of the trends NetCDF file
+   INTEGER ::   nmoymltrd
+   INTEGER, ALLOCATABLE, SAVE, DIMENSION(:) ::   ndextrd1
+   INTEGER, DIMENSION(jptra) ::   nidtrd, nh_t
+   INTEGER ::   ndimtrd1                        
+   INTEGER, SAVE ::  ionce, icount
+#if defined key_pisces_reduced
+   INTEGER ::   nidtrdbio, nh_tb
+   INTEGER, SAVE ::  ioncebio, icountbio
+   INTEGER, SAVE ::   nmoymltrdbio
+#endif
+   LOGICAL :: llwarn  = .TRUE.                                    ! this should always be .TRUE.
+   LOGICAL :: lldebug = .TRUE.
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  ztmltrd2   !
+#if defined key_pisces_reduced
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  ztmltrdbio2  ! only needed for mean diagnostics in trd_mxl_bio()
+#endif
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+#  include "zdfddm_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Header:  $ 
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION trd_mxl_trc_alloc()
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mxl_trc_alloc  ***
+      !!----------------------------------------------------------------------
+      ALLOCATE( ztmltrd2(jpi,jpj,jpltrd_trc,jptra) ,      &
+#if defined key_pisces_reduced
+         &      ztmltrdbio2(jpi,jpj,jpdiabio)      ,      &
+#endif
+         &      ndextrd1(jpi*jpj)                  ,  STAT=trd_mxl_trc_alloc)
+         !
+      IF( lk_mpp                )   CALL mpp_sum ( trd_mxl_trc_alloc )
+      IF( trd_mxl_trc_alloc /=0 )   CALL ctl_warn('trd_mxl_trc_alloc: failed to allocate arrays')
+      !
+   END FUNCTION trd_mxl_trc_alloc
+
+
+   SUBROUTINE trd_mxl_trc_zint( ptrc_trdmxl, ktrd, ctype, kjn )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mxl_trc_zint  ***
+      !! 
+      !! ** 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 :
+      !!      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_trc in namelist NAMTRD :
+      !!        nctls_trc = -2  : use isopycnal surface
+      !!        nctls_trc = -1  : use euphotic layer with light criterion 
+      !!        nctls_trc =  0  : use mixed layer with density criterion 
+      !!        nctls_trc =  1  : read index from file 'ctlsurf_idx'
+      !!        nctls_trc >  1  : use fixed level surface jk = nctls_trc
+      !!      Note: in the remainder of the routine, the volume between the 
+      !!            surface and the control surface is called "mixed-layer"
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT( in ) ::   ktrd, kjn                        ! ocean trend index and passive tracer rank
+      CHARACTER(len=2), INTENT( in ) ::  ctype                    ! surface/bottom (2D) or interior (3D) physics
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) ::  ptrc_trdmxl ! passive tracer trend
+      !
+      INTEGER ::   ji, jj, jk, isum
+      REAL(wp), POINTER, DIMENSION(:,:) :: zvlmsk
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, zvlmsk )
+
+      ! I. Definition of control surface and integration weights
+      ! --------------------------------------------------------
+
+      ONCE_PER_TIME_STEP : IF( icount == 1 ) THEN
+         !
+         tmltrd_trc(:,:,:,:) = 0.e0                               ! <<< reset trend arrays to zero
+          
+         ! ... Set nmld(ji,jj) = index of first T point below control surf. or outside mixed-layer
+         SELECT CASE ( nn_ctls_trc )                                ! choice of the control surface
+            CASE ( -2  )   ;   STOP 'trdmxl_trc : not ready '     !     -> isopycnal surface (see ???)
+#if defined key_pisces || defined key_pisces_reduced
+            CASE ( -1  )   ;   nmld_trc(:,:) = neln(:,:)          !     -> euphotic layer with light criterion
+#endif
+            CASE (  0  )   ;   nmld_trc(:,:) = nmln(:,:)          !     -> ML with density criterion (see zdfmxl)
+            CASE (  1  )   ;   nmld_trc(:,:) = nbol_trc(:,:)          !     -> read index from file
+            CASE (  2: )   ;   nn_ctls_trc = MIN( nn_ctls_trc, jpktrd_trc - 1 )
+                               nmld_trc(:,:) = nn_ctls_trc + 1      !     -> model level
+         END SELECT
+
+         ! ... Compute ndextrd1 and ndimtrd1  ??? role de jpktrd_trc
+         IF( ionce == 1 ) THEN
+            !
+            isum  = 0   ;   zvlmsk(:,:) = 0.e0
+
+            IF( jpktrd_trc < jpk ) THEN                           ! description ???
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     IF( nmld_trc(ji,jj) <= jpktrd_trc ) THEN
+                        zvlmsk(ji,jj) = tmask(ji,jj,1)
+                     ELSE
+                        isum = isum + 1
+                        zvlmsk(ji,jj) = 0.e0
+                     ENDIF
+                  END DO
+               END DO
+            ENDIF
+
+            IF( isum > 0 ) THEN                                   ! index of ocean points (2D only)
+               WRITE(numout,*)' tmltrd_trc : Number of invalid points nmld_trc > jpktrd', isum 
+               CALL wheneq( jpi*jpj, zvlmsk(:,:) , 1, 1., ndextrd1, ndimtrd1 )
+            ELSE 
+               CALL wheneq( jpi*jpj, tmask(:,:,1), 1, 1., ndextrd1, ndimtrd1 )
+            ENDIF                                
+
+            ionce = 0                                             ! no more pass here
+            !
+         ENDIF   ! ionce == 1
+         
+         ! ... Weights for vertical averaging
+         wkx_trc(:,:,:) = 0.e0
+         DO jk = 1, jpktrd_trc                                    ! initialize wkx_trc with vertical scale factor in mixed-layer
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF( jk - nmld_trc(ji,jj) < 0 )   wkx_trc(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         
+         rmld_trc(:,:) = 0.e0
+         DO jk = 1, jpktrd_trc                                    ! compute mixed-layer depth : rmld_trc
+            rmld_trc(:,:) = rmld_trc(:,:) + wkx_trc(:,:,jk)
+         END DO
+         
+         DO jk = 1, jpktrd_trc                                    ! compute integration weights
+            wkx_trc(:,:,jk) = wkx_trc(:,:,jk) / MAX( 1., rmld_trc(:,:) )
+         END DO
+
+         icount = 0                                               ! <<< flag = off : control surface & integr. weights
+         !                                                        !     computed only once per time step
+      ENDIF ONCE_PER_TIME_STEP
+
+      ! II. Vertical integration of trends in the mixed-layer
+      ! -----------------------------------------------------
+
+      SELECT CASE ( ctype )
+         CASE ( '3D' )                                            ! mean passive tracer trends in the mixed-layer
+            DO jk = 1, jpktrd_trc
+               tmltrd_trc(:,:,ktrd,kjn) = tmltrd_trc(:,:,ktrd,kjn) + ptrc_trdmxl(:,:,jk) * wkx_trc(:,:,jk)   
+            END DO
+         CASE ( '2D' )                                            ! forcing at upper boundary of the mixed-layer 
+            tmltrd_trc(:,:,ktrd,kjn) = tmltrd_trc(:,:,ktrd,kjn) + ptrc_trdmxl(:,:,1) * wkx_trc(:,:,1)  ! non penetrative
+      END SELECT
+      !
+      CALL wrk_dealloc( jpi, jpj, zvlmsk )
+      !
+   END SUBROUTINE trd_mxl_trc_zint
+
+
+   SUBROUTINE trd_mxl_bio_zint( ptrc_trdmxl, ktrd )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mxl_bio_zint  ***
+      !!
+      !! ** 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 :
+      !!      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 NAMTRD :
+      !!        nctls_trc = 0  : use mixed layer with density criterion
+      !!        nctls_trc = 1  : read index from file 'ctlsurf_idx'
+      !!        nctls_trc > 1  : use fixed level surface jk = nctls_trc
+      !!      Note: in the remainder of the routine, the volume between the
+      !!            surface and the control surface is called "mixed-layer"
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER                         , INTENT(in) ::   ktrd          ! bio trend index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in) ::   ptrc_trdmxl   ! passive trc trend
+#if defined key_pisces_reduced
+      !
+      INTEGER ::   ji, jj, jk, isum
+      REAL(wp), POINTER, DIMENSION(:,:) :: zvlmsk
+      !!----------------------------------------------------------------------
+
+      CALL wrk_alloc( jpi, jpj, zvlmsk )
+
+      ! I. Definition of control surface and integration weights
+      ! --------------------------------------------------------
+      !            ==> only once per time step <==
+
+      IF( icountbio == 1 ) THEN
+         !
+         tmltrd_bio(:,:,:) = 0.e0    ! <<< reset trend arrays to zero
+         ! ... Set nmld(ji,jj) = index of first T point below control surf. or outside mixed-layer
+         SELECT CASE ( nn_ctls_trc )                                    ! choice of the control surface
+            CASE ( -2  )   ;   STOP 'trdmxl_trc : not ready '     !     -> isopycnal surface (see ???)
+            CASE ( -1  )   ;   nmld_trc(:,:) = neln(:,:)          !     -> euphotic layer with light criterion
+            CASE (  0  )   ;   nmld_trc(:,:) = nmln(:,:)          !     -> ML with density criterion (see zdfmxl)
+            CASE (  1  )   ;   nmld_trc(:,:) = nbol_trc(:,:)          !     -> read index from file
+            CASE (  2: )   ;   nn_ctls_trc = MIN( nn_ctls_trc, jpktrd_trc - 1 )
+                               nmld_trc(:,:) = nn_ctls_trc + 1          !     -> model level
+         END SELECT
+
+         ! ... Compute ndextrd1 and ndimtrd1 only once
+         IF( ioncebio == 1 ) THEN
+            !
+            ! Check of validity : nmld_trc(ji,jj) <= jpktrd_trc
+            isum        = 0
+            zvlmsk(:,:) = 0.e0
+
+            IF( jpktrd_trc < jpk ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     IF( nmld_trc(ji,jj) <= jpktrd_trc ) THEN
+                        zvlmsk(ji,jj) = tmask(ji,jj,1)
+                     ELSE
+                        isum = isum + 1
+                        zvlmsk(ji,jj) = 0.
+                     END IF
+                  END DO
+               END DO
+            END IF
+
+            ! Index of ocean points (2D only)
+            IF( isum > 0 ) THEN
+               WRITE(numout,*)' tmltrd_trc : Number of invalid points nmld_trc > jpktrd', isum
+               CALL wheneq( jpi*jpj, zvlmsk(:,:) , 1, 1., ndextrd1, ndimtrd1 )
+            ELSE
+               CALL wheneq( jpi*jpj, tmask(:,:,1), 1, 1., ndextrd1, ndimtrd1 )
+            END IF
+
+            ioncebio = 0                  ! no more pass here
+            !
+         END IF !  ( ioncebio == 1 )
+
+         ! ... Weights for vertical averaging
+         wkx_trc(:,:,:) = 0.e0
+         DO jk = 1, jpktrd_trc         ! initialize wkx_trc with vertical scale factor in mixed-layer
+            DO jj = 1,jpj
+              DO ji = 1,jpi
+                  IF( jk - nmld_trc(ji,jj) < 0. )   wkx_trc(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         rmld_trc(:,:) = 0.
+         DO jk = 1, jpktrd_trc         ! compute mixed-layer depth : rmld_trc
+            rmld_trc(:,:) = rmld_trc(:,:) + wkx_trc(:,:,jk)
+         END DO
+
+         DO jk = 1, jpktrd_trc         ! compute integration weights
+            wkx_trc(:,:,jk) = wkx_trc(:,:,jk) / MAX( 1., rmld_trc(:,:) )
+         END DO
+
+         icountbio = 0                    ! <<< flag = off : control surface & integr. weights
+         !                             !     computed only once per time step
+      END IF ! ( icountbio == 1 )
+
+      ! II. Vertical integration of trends in the mixed-layer
+      ! -----------------------------------------------------
+
+
+      DO jk = 1, jpktrd_trc
+         tmltrd_bio(:,:,ktrd) = tmltrd_bio(:,:,ktrd) + ptrc_trdmxl(:,:,jk) * wkx_trc(:,:,jk)
+      END DO
+
+      CALL wrk_dealloc( jpi, jpj, zvlmsk )
+#endif
+      !
+   END SUBROUTINE trd_mxl_bio_zint
+
+
+   SUBROUTINE trd_mxl_trc( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mxl_trc  ***
+      !! 
+      !! ** 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_trdmxl_trc_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 ntrc_trc 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).
+      !!
+      !! ** Consistency check : 
+      !!        If the control surface is fixed ( nctls_trc > 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. ntrc_trc=5, rn_ucf_trc=1., nctls_trc=8
+      !!             for checking residuals.
+      !!             On a NEC-SX5 computer, this typically leads to:
+      !!                   O(1.e-20) temp. residuals (tml_res) when ln_trdmxl_trc_instant=.false.
+      !!                   O(1.e-21) temp. residuals (tml_res) when ln_trdmxl_trc_instant=.true.
+      !!
+      !! ** Action :
+      !!       At each time step, mixed-layer averaged trends are stored in the 
+      !!       tmltrd(:,:,jpmxl_xxx) array (see trdmxl_oce.F90 for definitions of jpmxl_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)
+      !!----------------------------------------------------------------------
+      !
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      INTEGER ::   ji, jj, jk, jl, ik, it, itmod, jn
+      REAL(wp) ::   zavt, zfn, zfn2
+      !
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltot             ! d(trc)/dt over the anlysis window (incl. Asselin)
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlres             ! residual = dh/dt entrainment term
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlatf             ! for storage only
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlrad             ! for storage only (for trb<0 corr in trcrad)
+      !
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltot2            ! -+
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlres2            !  | working arrays to diagnose the trends
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmltrdm2           !  | associated with the time meaned ML
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlatf2            !  | passive tracers
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmlrad2            !  | (-> for trb<0 corr in trcrad)
+      !
+      CHARACTER (LEN=10) ::   clvar
+#if defined key_dimgout
+      INTEGER ::   iyear,imon,iday
+      CHARACTER(LEN=80) ::   cltext, clmode
+#endif
+      !!----------------------------------------------------------------------
+
+      ! Set-up pointers into sub-arrays of workspaces
+      CALL wrk_alloc( jpi, jpj, jptra, ztmltot , ztmlres , ztmlatf , ztmlrad             )
+      CALL wrk_alloc( jpi, jpj, jptra, ztmltot2, ztmlres2, ztmlatf2, ztmlrad2, ztmltrdm2 )
+
+      IF( nn_dttrc  /= 1  )   CALL ctl_stop( " Be careful, trends diags never validated " )
+
+      ! ======================================================================
+      ! 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( tracer ))
+
+      IF( ln_trcldf_iso ) THEN
+         !
+         DO jj = 1,jpj
+            DO ji = 1,jpi
+               ik = nmld_trc(ji,jj)
+               zavt = fsavs(ji,jj,ik)
+               DO jn = 1, jptra
+                  IF( ln_trdtrc(jn) )    &
+                  tmltrd_trc(ji,jj,jpmxl_trc_zdf,jn) = - zavt / fse3w(ji,jj,ik) * tmask(ji,jj,ik)  &
+                       &                    * ( trn(ji,jj,ik-1,jn) - trn(ji,jj,ik,jn) )            &
+                       &                    / MAX( 1., rmld_trc(ji,jj) ) * tmask(ji,jj,1)
+               END DO
+            END DO
+         END DO
+
+         DO jn = 1, jptra
+            ! ... Remove this K_z trend from the iso-neutral diffusion term (if any)
+            IF( ln_trdtrc(jn) ) &
+                 tmltrd_trc(:,:,jpmxl_trc_ldf,jn) = tmltrd_trc(:,:,jpmxl_trc_ldf,jn) - tmltrd_trc(:,:,jpmxl_trc_zdf,jn)
+   
+         END DO
+         !      
+      ENDIF
+
+      IF ( cp_cfg .NE. 'gyre' ) THEN            ! other than GYRE configuration
+      ! GYRE : for diagnostic fields, are needed if cyclic B.C. are present, but not for purely MPI comm. 
+      ! therefore we do not call lbc_lnk in GYRE config. (closed basin, no cyclic B.C.)
+         DO jn = 1, jptra
+            IF( ln_trdtrc(jn) ) THEN
+               DO jl = 1, jpltrd_trc
+                  CALL lbc_lnk( tmltrd_trc(:,:,jl,jn), 'T', 1. )        ! lateral boundary conditions
+               END DO
+            ENDIF
+         END DO
+      ENDIF
+      ! ======================================================================
+      ! II. Cumulate the trends over the analysis window
+      ! ======================================================================
+
+      ztmltrd2(:,:,:,:) = 0.e0   ;   ztmltot2(:,:,:)   = 0.e0     ! <<< reset arrays to zero
+      ztmlres2(:,:,:)   = 0.e0   ;   ztmlatf2(:,:,:)   = 0.e0
+      ztmlrad2(:,:,:)   = 0.e0
+
+      ! II.1 Set before values of vertically averages passive tracers
+      ! -------------------------------------------------------------
+      IF( kt > nittrc000 ) THEN
+         DO jn = 1, jptra
+            IF( ln_trdtrc(jn) ) THEN
+               tmlb_trc   (:,:,jn) = tml_trc   (:,:,jn)
+               tmlatfn_trc(:,:,jn) = tmltrd_trc(:,:,jpmxl_trc_atf,jn)
+               tmlradn_trc(:,:,jn) = tmltrd_trc(:,:,jpmxl_trc_radb,jn)
+            ENDIF
+         END DO
+      ENDIF
+
+      ! II.2 Vertically averaged passive tracers
+      ! ----------------------------------------
+      tml_trc(:,:,:) = 0.e0
+      DO jk = 1, jpktrd_trc ! - 1 ???
+         DO jn = 1, jptra
+            IF( ln_trdtrc(jn) ) &
+               tml_trc(:,:,jn) = tml_trc(:,:,jn) + wkx_trc(:,:,jk) * trn(:,:,jk,jn)
+         END DO
+      END DO
+
+      ! II.3 Initialize mixed-layer "before" arrays for the 1rst analysis window    
+      ! ------------------------------------------------------------------------
+      IF( kt == nittrc000 + nn_dttrc ) THEN  !  i.e. ( .NOT. ln_rstart ).AND.( kt == nit000 + 1)    ???
+         !
+         DO jn = 1, jptra
+            IF( ln_trdtrc(jn) ) THEN
+               tmlbb_trc  (:,:,jn) = tmlb_trc   (:,:,jn)   ;   tmlbn_trc  (:,:,jn) = tml_trc    (:,:,jn)
+               tmlatfb_trc(:,:,jn) = tmlatfn_trc(:,:,jn)   ;   tmlradb_trc(:,:,jn) = tmlradn_trc(:,:,jn)
+               
+               tmltrd_csum_ub_trc (:,:,:,jn) = 0.e0   ;   tmltrd_atf_sumb_trc  (:,:,jn) = 0.e0
+               tmltrd_rad_sumb_trc  (:,:,jn) = 0.e0
+            ENDIF
+         END DO
+         
+         rmldbn_trc(:,:) = rmld_trc(:,:)
+         !
+      ENDIF
+
+      ! 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_rsttr ) ) THEN                        ! ???
+         !
+         nmoymltrd = nmoymltrd + 1
+
+
+         ! ... Cumulate over BOTH physical contributions AND over time steps
+         DO jn = 1, jptra
+            IF( ln_trdtrc(jn) ) THEN
+               DO jl = 1, jpltrd_trc
+                  tmltrdm_trc(:,:,jn) = tmltrdm_trc(:,:,jn) + tmltrd_trc(:,:,jl,jn)
+               END DO
+            ENDIF
+         END DO
+
+         DO jn = 1, jptra
+            IF( ln_trdtrc(jn) ) THEN
+               ! ... Special handling of the Asselin trend 
+               tmlatfm_trc(:,:,jn) = tmlatfm_trc(:,:,jn) + tmlatfn_trc(:,:,jn)
+               tmlradm_trc(:,:,jn) = tmlradm_trc(:,:,jn) + tmlradn_trc(:,:,jn)
+
+               ! ... Trends associated with the time mean of the ML passive tracers
+               tmltrd_sum_trc    (:,:,:,jn) = tmltrd_sum_trc    (:,:,:,jn) + tmltrd_trc    (:,:,:,jn)
+               tmltrd_csum_ln_trc(:,:,:,jn) = tmltrd_csum_ln_trc(:,:,:,jn) + tmltrd_sum_trc(:,:,:,jn)
+               tml_sum_trc       (:,:,jn)   = tml_sum_trc       (:,:,jn)   + tml_trc       (:,:,jn)
+            ENDIF
+         ENDDO
+
+         rmld_sum_trc      (:,:)     = rmld_sum_trc      (:,:)     + rmld_trc      (:,:)
+         !
+      ENDIF
+
+      ! ======================================================================
+      ! III. Prepare fields for output (get here ONCE PER ANALYSIS PERIOD)
+      ! ======================================================================
+
+      ! Convert to appropriate physical units
+      tmltrd_trc(:,:,:,:) = tmltrd_trc(:,:,:,:) * rn_ucf_trc
+
+      itmod = kt - nittrc000 + 1
+      it    = kt
+
+      MODULO_NTRD : IF( MOD( itmod, nn_trd_trc ) == 0 ) THEN           ! nitend MUST be multiple of nn_trd_trc
+         !
+         ztmltot (:,:,:) = 0.e0                                   ! reset arrays to zero
+         ztmlres (:,:,:) = 0.e0
+         ztmltot2(:,:,:) = 0.e0
+         ztmlres2(:,:,:) = 0.e0
+      
+         zfn  = FLOAT( nmoymltrd )    ;    zfn2 = zfn * zfn
+         
+         ! III.1 Prepare fields for output ("instantaneous" diagnostics) 
+         ! -------------------------------------------------------------
+
+         DO jn = 1, jptra
+            IF( ln_trdtrc(jn) ) THEN
+               !-- Compute total trends    (use rdttrc instead of rdt ???)
+               IF ( ln_trcadv_muscl .OR. ln_trcadv_muscl2 ) THEN  ! EULER-FORWARD schemes
+                  ztmltot(:,:,jn) =  ( tml_trc(:,:,jn) - tmlbn_trc(:,:,jn) )/rdt
+               ELSE                                                                     ! LEAP-FROG schemes
+                  ztmltot(:,:,jn) =  ( tml_trc(:,:,jn) - tmlbn_trc(:,:,jn) + tmlb_trc(:,:,jn) - tmlbb_trc(:,:,jn))/(2.*rdt)
+               ENDIF
+               
+               !-- Compute residuals
+               ztmlres(:,:,jn) = ztmltot(:,:,jn) - ( tmltrdm_trc(:,:,jn) - tmlatfn_trc(:,:,jn) + tmlatfb_trc(:,:,jn) &
+                  &                                                 - tmlradn_trc(:,:,jn) + tmlradb_trc(:,:,jn)  )
+               
+               !-- Diagnose Asselin trend over the analysis window 
+               ztmlatf(:,:,jn) = tmlatfm_trc(:,:,jn) - tmlatfn_trc(:,:,jn) + tmlatfb_trc(:,:,jn)
+               ztmlrad(:,:,jn) = tmlradm_trc(:,:,jn) - tmlradn_trc(:,:,jn) + tmlradb_trc(:,:,jn)
+               
+         !-- Lateral boundary conditions
+               IF ( cp_cfg .NE. 'gyre' ) THEN
+                  CALL lbc_lnk( ztmltot(:,:,jn) , 'T', 1. )   ;   CALL lbc_lnk( ztmlres(:,:,jn) , 'T', 1. )
+                  CALL lbc_lnk( ztmlatf(:,:,jn) , 'T', 1. )   ;   CALL lbc_lnk( ztmlrad(:,:,jn) , 'T', 1. )
+               ENDIF
+
+
+#if defined key_diainstant
+               STOP 'tmltrd_trc : key_diainstant was never checked within trdmxl. Comment this to proceed.'
+#endif
+            ENDIF
+         END DO
+
+         ! III.2 Prepare fields for output ("mean" diagnostics) 
+         ! ----------------------------------------------------
+         
+         !-- Update the ML depth time sum (to build the Leap-Frog time mean)
+         rmld_sum_trc(:,:) = rmldbn_trc(:,:) + 2 * ( rmld_sum_trc(:,:) - rmld_trc(:,:) ) + rmld_trc(:,:)
+
+               !-- Compute passive tracer total trends
+         DO jn = 1, jptra
+            IF( ln_trdtrc(jn) ) THEN
+               tml_sum_trc(:,:,jn) = tmlbn_trc(:,:,jn) + 2 * ( tml_sum_trc(:,:,jn) - tml_trc(:,:,jn) ) + tml_trc(:,:,jn)
+               ztmltot2   (:,:,jn) = ( tml_sum_trc(:,:,jn) - tml_sumb_trc(:,:,jn) ) /  ( 2.*rdt )    ! now tracer unit is /sec
+            ENDIF
+         END DO
+
+         !-- Compute passive tracer residuals
+         DO jn = 1, jptra
+            IF( ln_trdtrc(jn) ) THEN
+               !
+               DO jl = 1, jpltrd_trc
+                  ztmltrd2(:,:,jl,jn) = tmltrd_csum_ub_trc(:,:,jl,jn) + tmltrd_csum_ln_trc(:,:,jl,jn)
+               END DO
+               
+               ztmltrdm2(:,:,jn) = 0.e0
+               DO jl = 1, jpltrd_trc
+                  ztmltrdm2(:,:,jn) = ztmltrdm2(:,:,jn) + ztmltrd2(:,:,jl,jn)
+               END DO
+               
+               ztmlres2(:,:,jn) =  ztmltot2(:,:,jn)  -       &
+                  & ( ztmltrdm2(:,:,jn) - tmltrd_sum_trc(:,:,jpmxl_trc_atf ,jn) + tmltrd_atf_sumb_trc(:,:,jn) &
+                  &                     - tmltrd_sum_trc(:,:,jpmxl_trc_radb,jn) + tmltrd_rad_sumb_trc(:,:,jn) )
+               !
+
+               !-- Diagnose Asselin trend over the analysis window
+               ztmlatf2(:,:,jn) = ztmltrd2(:,:,jpmxl_trc_atf ,jn) - tmltrd_sum_trc(:,:,jpmxl_trc_atf ,jn) &
+                  &                                               + tmltrd_atf_sumb_trc(:,:,jn)
+               ztmlrad2(:,:,jn) = ztmltrd2(:,:,jpmxl_trc_radb,jn) - tmltrd_sum_trc(:,:,jpmxl_trc_radb,jn) &
+                  &                                               + tmltrd_rad_sumb_trc(:,:,jn)
+
+         !-- Lateral boundary conditions 
+               IF ( cp_cfg .NE. 'gyre' ) THEN            ! other than GYRE configuration    
+                  CALL lbc_lnk( ztmltot2(:,:,jn), 'T', 1. )
+                  CALL lbc_lnk( ztmlres2(:,:,jn), 'T', 1. )
+                  DO jl = 1, jpltrd_trc
+                     CALL lbc_lnk( ztmltrd2(:,:,jl,jn), 'T', 1. )       ! will be output in the NetCDF trends file
+                  END DO
+               ENDIF
+
+            ENDIF
+         END DO
+
+         ! * Debugging information *
+         IF( lldebug ) THEN
+            !
+            WRITE(numout,*) 'trd_mxl_trc : write trends in the Mixed Layer for debugging process:'
+            WRITE(numout,*) '~~~~~~~~~~~  '
+            WRITE(numout,*)
+            WRITE(numout,*) 'TRC kt = ', kt, '    nmoymltrd = ', nmoymltrd
+
+            DO jn = 1, jptra
+
+               IF( ln_trdtrc(jn) ) THEN
+                  WRITE(numout, *)
+                  WRITE(numout, *) '>>>>>>>>>>>>>>>>>>  TRC TRACER jn =', jn, ' <<<<<<<<<<<<<<<<<<'
+                  
+                  WRITE(numout, *)
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM ztmlres     : ', SUM2D(ztmlres(:,:,jn))
+                  !CD??? PREVOIR: z2d = ztmlres(:,:,jn)   ;   CALL prt_ctl(tab2d_1=z2d, clinfo1=' ztmlres   -   : ')
+                  
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM ABS(ztmlres): ', SUM2D(ABS(ztmlres(:,:,jn)))
+                  WRITE(numout, '(3x,a)') ' -->>>------------------- ztmlres is computed from ------------- '
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +ztmltot    : ', SUM2D(+ztmltot    (:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmltrdm_trc: ', SUM2D(+tmltrdm_trc(:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmlatfn_trc: ', SUM2D(-tmlatfn_trc(:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmlatfb_trc: ', SUM2D(+tmlatfb_trc(:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmlradn_trc: ', SUM2D(-tmlradn_trc(:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmlradb_trc: ', SUM2D(+tmlradb_trc(:,:,jn))
+                  WRITE(numout, '(3x,a)') ' --<<<----------------------------------------------------------- '
+                  
+                  WRITE(numout, *)
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM ztmlres2    : ', SUM2D(ztmlres2(:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM ABS(ztmlres2):', SUM2D(ABS(ztmlres2(:,:,jn)))
+                  WRITE(numout, '(3x,a)') ' -->>>------------------- ztmlres2 is computed from ------------ '
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +ztmltot2            : ', SUM2D(+ztmltot2(:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +ztmltrdm2           : ', SUM2D(+ztmltrdm2(:,:,jn)) 
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmltrd_sum_trc      : ', SUM2D(-tmltrd_sum_trc(:,:,jpmxl_trc_atf,jn)) 
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmltrd_atf_sumb_trc : ', SUM2D(+tmltrd_atf_sumb_trc(:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmltrd_sum_trc      : ', SUM2D(-tmltrd_sum_trc(:,:,jpmxl_trc_radb,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmltrd_rad_sumb_trc : ', SUM2D(+tmltrd_rad_sumb_trc(:,:,jn) )
+                  WRITE(numout, '(3x,a)') ' --<<<----------------------------------------------------------- '
+                  
+                  WRITE(numout, *)
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM ztmltot     : ', SUM2D(ztmltot    (:,:,jn))
+                  WRITE(numout, '(3x,a)') ' -->>>------------------- ztmltot is computed from ------------- '
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +tml_trc    : ', SUM2D(tml_trc    (:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmlbn_trc  : ', SUM2D(tmlbn_trc  (:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmlb_trc   : ', SUM2D(tmlb_trc   (:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmlbb_trc  : ', SUM2D(tmlbb_trc  (:,:,jn))
+                  WRITE(numout, '(3x,a)') ' --<<<----------------------------------------------------------- '
+                  
+                  WRITE(numout, *)
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM tmltrdm_trc : ', SUM2D(tmltrdm_trc(:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM tmlatfb_trc : ', SUM2D(tmlatfb_trc(:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM tmlatfn_trc : ', SUM2D(tmlatfn_trc(:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM tmlradb_trc : ', SUM2D(tmlradb_trc(:,:,jn))
+                  WRITE(numout,98) 'TRC jn =', jn, ' SUM tmlradn_trc : ', SUM2D(tmlradn_trc(:,:,jn))
+                  
+                  WRITE(numout, *)
+                  DO jl = 1, jpltrd_trc
+                     WRITE(numout,97) 'TRC jn =', jn, ' TREND INDEX jpmxl_trc_xxx = ', jl, &
+                        & ' SUM tmltrd_trc : ', SUM2D(tmltrd_trc(:,:,jl,jn))
+                  END DO
+               
+                  WRITE(numout,*) 
+                  WRITE(numout,*) ' *********************** ZTMLRES, ZTMLRES2 *********************** '
+                  WRITE(numout,*)
+                  WRITE(numout,*) 'TRC ztmlres (jpi/2,jpj/2,:) : ', ztmlres (jpi/2,jpj/2,jn)
+                  WRITE(numout,*)
+                  WRITE(numout,*) 'TRC ztmlres2(jpi/2,jpj/2,:) : ', ztmlres2(jpi/2,jpj/2,jn)
+                  
+                  WRITE(numout,*) 
+                  WRITE(numout,*) ' *********************** ZTMLRES *********************** '
+                  WRITE(numout,*)
+                  
+                  WRITE(numout,*) '...................................................'
+                  WRITE(numout,*) 'TRC jn =', jn, ' ztmlres (1:10,1:5,jn) : '
+                  DO jj = 5, 1, -1
+                     WRITE(numout,99) jj, ( ztmlres (ji,jj,jn), ji=1,10 )
+                  END DO
+                  
+                  WRITE(numout,*) 
+                  WRITE(numout,*) ' *********************** ZTMLRES2 *********************** '
+                  WRITE(numout,*)
+                  
+                  WRITE(numout,*) '...................................................'
+                  WRITE(numout,*) 'TRC jn =', jn, ' ztmlres2 (1:10,1:5,jn) : '
+                  DO jj = 5, 1, -1
+                     WRITE(numout,99) jj, ( ztmlres2 (ji,jj,jn), ji=1,10 )
+                  END DO
+                  !
+               ENDIF
+               !
+            END DO
+
+
+97            FORMAT(a10, i3, 2x, a30, i3, a20, 2x, g20.10)
+98            FORMAT(a10, i3, 2x, a30, 2x, g20.10)
+99            FORMAT('TRC jj =', i3,' : ', 10(g10.3,2x))
+              WRITE(numout,*)
+            !
+         ENDIF
+
+         ! III.3 Time evolution array swap
+         ! -------------------------------
+         ! ML depth
+         rmldbn_trc(:,:)   = rmld_trc(:,:)
+         rmld_sum_trc(:,:)     = rmld_sum_trc(:,:)     /      (2*zfn)  ! similar to tml_sum and sml_sum
+         DO jn = 1, jptra
+            IF( ln_trdtrc(jn) ) THEN        
+               ! For passive tracer instantaneous diagnostics
+               tmlbb_trc  (:,:,jn) = tmlb_trc   (:,:,jn)   ;   tmlbn_trc  (:,:,jn) = tml_trc    (:,:,jn)
+               tmlatfb_trc(:,:,jn) = tmlatfn_trc(:,:,jn)   ;   tmlradb_trc(:,:,jn) = tmlradn_trc(:,:,jn)
+               
+               ! For passive tracer mean diagnostics
+               tmltrd_csum_ub_trc (:,:,:,jn) = zfn * tmltrd_sum_trc(:,:,:,jn) - tmltrd_csum_ln_trc(:,:,:,jn)
+               tml_sumb_trc       (:,:,jn)   = tml_sum_trc(:,:,jn)
+               tmltrd_atf_sumb_trc(:,:,jn)   = tmltrd_sum_trc(:,:,jpmxl_trc_atf ,jn)
+               tmltrd_rad_sumb_trc(:,:,jn)   = tmltrd_sum_trc(:,:,jpmxl_trc_radb,jn)
+               
+               
+               ! III.4 Convert to appropriate physical units
+               ! -------------------------------------------
+               ztmltot     (:,:,jn)   = ztmltot     (:,:,jn)   * rn_ucf_trc/zfn   ! instant diags
+               ztmlres     (:,:,jn)   = ztmlres     (:,:,jn)   * rn_ucf_trc/zfn
+               ztmlatf     (:,:,jn)   = ztmlatf     (:,:,jn)   * rn_ucf_trc/zfn
+               ztmlrad     (:,:,jn)   = ztmlrad     (:,:,jn)   * rn_ucf_trc/zfn
+               tml_sum_trc (:,:,jn)   = tml_sum_trc (:,:,jn)   /      (2*zfn)  ! mean diags
+               ztmltot2    (:,:,jn)   = ztmltot2    (:,:,jn)   * rn_ucf_trc/zfn2
+               ztmltrd2    (:,:,:,jn) = ztmltrd2    (:,:,:,jn) * rn_ucf_trc/zfn2
+               ztmlatf2    (:,:,jn)   = ztmlatf2    (:,:,jn)   * rn_ucf_trc/zfn2
+               ztmlrad2    (:,:,jn)   = ztmlrad2    (:,:,jn)   * rn_ucf_trc/zfn2
+               ztmlres2    (:,:,jn)   = ztmlres2    (:,:,jn)   * rn_ucf_trc/zfn2
+            ENDIF
+         END DO
+         !
+      ENDIF MODULO_NTRD
+
+      ! ======================================================================
+      ! IV. Write trends in the NetCDF file
+      ! ======================================================================
+
+      ! IV.1 Code for dimg mpp output
+      ! -----------------------------
+
+# if defined key_dimgout
+      STOP 'Not implemented'
+# else
+      
+      ! IV.2 Code for IOIPSL/NetCDF output
+      ! ----------------------------------
+
+      IF( lwp .AND. MOD( itmod , nn_trd_trc ) == 0 ) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) 'trd_mxl_trc : write passive tracer trends in the NetCDF file :'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '          ', trim(clhstnam), ' at kt = ', kt
+         WRITE(numout,*) '          N.B. nmoymltrd = ', nmoymltrd
+         WRITE(numout,*) ' '
+      ENDIF
+         
+      NETCDF_OUTPUT : IF( ln_trdmxl_trc_instant ) THEN            ! <<< write the trends for passive tracer instant. diags
+         !
+
+         DO jn = 1, jptra
+            !
+            IF( ln_trdtrc(jn) ) THEN
+               CALL histwrite( nidtrd(jn), "mxl_depth", it, rmld_trc(:,:), ndimtrd1, ndextrd1 )
+               !-- Output the fields
+               clvar = trim(ctrcnm(jn))//"ml"                        ! e.g. detml, zooml, nh4ml, etc.
+               CALL histwrite( nidtrd(jn), trim(clvar)         , it, tml_trc(:,:,jn), ndimtrd1, ndextrd1 ) 
+               CALL histwrite( nidtrd(jn), trim(clvar)//"_tot" , it, ztmltot(:,:,jn), ndimtrd1, ndextrd1 ) 
+               CALL histwrite( nidtrd(jn), trim(clvar)//"_res" , it, ztmlres(:,:,jn), ndimtrd1, ndextrd1 ) 
+           
+               DO jl = 1, jpltrd_trc - 2
+                  CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jl,2)),             &
+                    &          it, tmltrd_trc(:,:,jl,jn), ndimtrd1, ndextrd1 )
+               END DO
+
+               CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmxl_trc_radb,2)),    &  ! now trcrad    : jpltrd_trc - 1
+                    &          it, ztmlrad(:,:,jn), ndimtrd1, ndextrd1 )
+
+               CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmxl_trc_atf,2)),     &  ! now Asselin   : jpltrd_trc
+                    &          it, ztmlatf(:,:,jn), ndimtrd1, ndextrd1 )
+                     
+            ENDIF
+         END DO
+
+         IF( kt == nitend ) THEN 
+            DO jn = 1, jptra
+               IF( ln_trdtrc(jn) )  CALL histclo( nidtrd(jn) )
+            END DO
+         ENDIF
+
+      ELSE                                                        ! <<< write the trends for passive tracer mean diagnostics
+         
+         DO jn = 1, jptra
+            !
+            IF( ln_trdtrc(jn) ) THEN
+               CALL histwrite( nidtrd(jn), "mxl_depth", it, rmld_sum_trc(:,:), ndimtrd1, ndextrd1 ) 
+               !-- Output the fields
+               clvar = trim(ctrcnm(jn))//"ml"                        ! e.g. detml, zooml, nh4ml, etc.
+
+               CALL histwrite( nidtrd(jn), trim(clvar)         , it, tml_sum_trc(:,:,jn), ndimtrd1, ndextrd1 )
+               CALL histwrite( nidtrd(jn), trim(clvar)//"_tot" , it,    ztmltot2(:,:,jn), ndimtrd1, ndextrd1 ) 
+               CALL histwrite( nidtrd(jn), trim(clvar)//"_res" , it,    ztmlres2(:,:,jn), ndimtrd1, ndextrd1 ) 
+
+               DO jl = 1, jpltrd_trc - 2
+                  CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jl,2)),           &
+                    &          it, ztmltrd2(:,:,jl,jn), ndimtrd1, ndextrd1 )
+               END DO
+            
+               CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmxl_trc_radb,2)),   &  ! now trcrad    : jpltrd_trc - 1
+                 &          it, ztmlrad2(:,:,jn), ndimtrd1, ndextrd1 )
+
+               CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmxl_trc_atf,2)),    &  ! now Asselin   : jpltrd_trc
+                 &          it, ztmlatf2(:,:,jn), ndimtrd1, ndextrd1 )
+
+            ENDIF 
+            !
+         END DO
+         IF( kt == nitend ) THEN 
+            DO jn = 1, jptra
+               IF( ln_trdtrc(jn) )  CALL histclo( nidtrd(jn) )
+            END DO
+         ENDIF
+
+         !
+      ENDIF NETCDF_OUTPUT
+         
+      ! Compute the control surface (for next time step) : flag = on
+      icount = 1
+
+# endif /* key_dimgout */
+
+      IF( MOD( itmod, nn_trd_trc ) == 0 ) THEN
+         !
+         ! Reset cumulative arrays to zero
+         ! -------------------------------         
+         nmoymltrd = 0
+         tmltrdm_trc        (:,:,:)   = 0.e0   ;   tmlatfm_trc        (:,:,:)   = 0.e0
+         tmlradm_trc        (:,:,:)   = 0.e0   ;   tml_sum_trc        (:,:,:)   = 0.e0
+         tmltrd_csum_ln_trc (:,:,:,:) = 0.e0   ;   tmltrd_sum_trc     (:,:,:,:) = 0.e0
+         rmld_sum_trc       (:,:)     = 0.e0
+         !
+      ENDIF
+
+      ! ======================================================================
+      ! V. Write restart file
+      ! ======================================================================
+
+      IF( lrst_trc )   CALL trd_mxl_trc_rst_write( kt )  ! this must be after the array swap above (III.3)
+
+      CALL wrk_dealloc( jpi, jpj, jptra, ztmltot , ztmlres , ztmlatf , ztmlrad             )
+      CALL wrk_dealloc( jpi, jpj, jptra, ztmltot2, ztmlres2, ztmlatf2, ztmlrad2, ztmltrdm2 )
+      !
+   END SUBROUTINE trd_mxl_trc
+
+
+   SUBROUTINE trd_mxl_bio( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mld  ***
+      !!
+      !! ** Purpose :  Compute and cumulate the mixed layer biological trends over an analysis
+      !!               period, and write NetCDF (or dimg) outputs.
+      !!
+      !! ** Method/usage :
+      !!          The stored trends can be chosen twofold (according to the ln_trdmxl_trc_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).
+      !!
+      !! ** 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_trdmxl_trc_instant=.false.
+      !!                   O(1.e-21) temp. residuals (tml_res) when ln_trdmxl_trc_instant=.true.
+      !!
+      !! ** Action :
+      !!       At each time step, mixed-layer averaged trends are stored in the
+      !!       tmltrd(:,:,jpmxl_xxx) array (see trdmxl_oce.F90 for definitions of jpmxl_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)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt                       ! ocean time-step index
+#if defined key_pisces_reduced
+      INTEGER  ::  jl, it, itmod
+      LOGICAL  :: llwarn  = .TRUE., lldebug = .TRUE.
+      REAL(wp) :: zfn, zfn2
+#if defined key_dimgout
+      INTEGER ::  iyear,imon,iday
+      CHARACTER(LEN=80) :: cltext, clmode
+#endif
+      !!----------------------------------------------------------------------
+      ! ... Warnings
+      IF( nn_dttrc  /= 1  ) CALL ctl_stop( " Be careful, trends diags never validated " )
+
+      ! ======================================================================
+      ! II. Cumulate the trends over the analysis window
+      ! ======================================================================
+
+      ztmltrdbio2(:,:,:) = 0.e0  ! <<< reset arrays to zero
+
+      ! II.3 Initialize mixed-layer "before" arrays for the 1rst analysis window
+      ! ------------------------------------------------------------------------
+      IF( kt == nittrc000 + nn_dttrc ) THEN  !  i.e. ( .NOT. ln_rstart ).AND.( kt == nit000 + 1)
+         !
+         tmltrd_csum_ub_bio (:,:,:) = 0.e0
+         !
+      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_rsttr ) ) THEN
+         !
+         nmoymltrdbio = nmoymltrdbio + 1
+
+         ! ... Trends associated with the time mean of the ML passive tracers
+         tmltrd_sum_bio    (:,:,:) = tmltrd_sum_bio    (:,:,:) + tmltrd_bio    (:,:,:)
+         tmltrd_csum_ln_bio(:,:,:) = tmltrd_csum_ln_bio(:,:,:) + tmltrd_sum_bio(:,:,:)
+         !
+      END IF
+
+      ! ======================================================================
+      ! III. Prepare fields for output (get here ONCE PER ANALYSIS PERIOD)
+      ! ======================================================================
+
+      ! Convert to appropriate physical units
+      tmltrd_bio(:,:,:) = tmltrd_bio(:,:,:) * rn_ucf_trc
+
+      MODULO_NTRD : IF( MOD( kt, nn_trd_trc ) == 0 ) THEN      ! nitend MUST be multiple of ntrd
+         !
+         zfn  = float(nmoymltrdbio)    ;    zfn2 = zfn * zfn
+
+         ! III.1 Prepare fields for output ("instantaneous" diagnostics)
+         ! -------------------------------------------------------------
+
+#if defined key_diainstant
+         STOP 'tmltrd_bio : key_diainstant was never checked within trdmxl. Comment this to proceed.'
+#endif
+         ! III.2 Prepare fields for output ("mean" diagnostics)
+         ! ----------------------------------------------------
+
+         ztmltrdbio2(:,:,:) = tmltrd_csum_ub_bio(:,:,:) + tmltrd_csum_ln_bio(:,:,:)
+
+         !-- Lateral boundary conditions
+         IF ( cp_cfg .NE. 'gyre' ) THEN            ! other than GYRE configuration 
+            ! ES_B27_CD_WARN : lbc inutile GYRE, cf. + haut
+            DO jn = 1, jpdiabio
+              CALL lbc_lnk( ztmltrdbio2(:,:,jn), 'T', 1. )
+            ENDDO
+         ENDIF
+
+         IF( lldebug ) THEN
+            !
+            WRITE(numout,*) 'trd_mxl_bio : write trends in the Mixed Layer for debugging process:'
+            WRITE(numout,*) '~~~~~~~~~~~  '
+            WRITE(numout,*) 'TRC kt = ', kt, 'nmoymltrdbio = ', nmoymltrdbio
+            WRITE(numout,*)
+
+            DO jl = 1, jpdiabio
+              IF( ln_trdmxl_trc_instant ) THEN
+                  WRITE(numout,97) 'TRC jl =', jl, ' bio TREND INDEX  = ', jl, &
+                     & ' SUM tmltrd_bio : ', SUM2D(tmltrd_bio(:,:,jl))
+              ELSE
+                  WRITE(numout,97) 'TRC jl =', jl, ' bio TREND INDEX  = ', jl, &
+                     & ' SUM ztmltrdbio2 : ', SUM2D(ztmltrdbio2(:,:,jl))
+              endif
+            END DO
+
+97          FORMAT(a10, i3, 2x, a30, i3, a20, 2x, g20.10)
+98          FORMAT(a10, i3, 2x, a30, 2x, g20.10)
+99          FORMAT('TRC jj =', i3,' : ', 10(g10.3,2x))
+            WRITE(numout,*)
+            !
+         ENDIF
+
+         ! III.3 Time evolution array swap
+         ! -------------------------------
+
+         ! For passive tracer mean diagnostics
+         tmltrd_csum_ub_bio (:,:,:) = zfn * tmltrd_sum_bio(:,:,:) - tmltrd_csum_ln_bio(:,:,:)
+
+         ! III.4 Convert to appropriate physical units
+         ! -------------------------------------------
+         ztmltrdbio2    (:,:,:) = ztmltrdbio2    (:,:,:) * rn_ucf_trc/zfn2
+
+      END IF MODULO_NTRD
+
+      ! ======================================================================
+      ! IV. Write trends in the NetCDF file
+      ! ======================================================================
+
+      ! IV.1 Code for dimg mpp output
+      ! -----------------------------
+
+# if defined key_dimgout
+      STOP 'Not implemented'
+# else
+
+      ! IV.2 Code for IOIPSL/NetCDF output
+      ! ----------------------------------
+
+      ! define time axis
+      itmod = kt - nittrc000 + 1
+      it    = kt
+
+      IF( lwp .AND. MOD( itmod , nn_trd_trc ) == 0 ) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) 'trd_mxl_bio : write ML bio trends in the NetCDF file :'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '          ', TRIM(clhstnam), ' at kt = ', kt
+         WRITE(numout,*) '          N.B. nmoymltrdbio = ', nmoymltrdbio
+         WRITE(numout,*) ' '
+      END IF
+
+
+      ! 2. Start writing data
+      ! ---------------------
+
+      NETCDF_OUTPUT : IF( ln_trdmxl_trc_instant ) THEN    ! <<< write the trends for passive tracer instant. diags
+         !
+            DO jl = 1, jpdiabio
+               CALL histwrite( nidtrdbio,TRIM("ML_"//ctrd_bio(jl,2)) ,            &
+                    &          it, tmltrd_bio(:,:,jl), ndimtrd1, ndextrd1 )
+            END DO
+
+
+         IF( kt == nitend )   CALL histclo( nidtrdbio )
+
+      ELSE    ! <<< write the trends for passive tracer mean diagnostics
+
+            DO jl = 1, jpdiabio
+               CALL histwrite( nidtrdbio, TRIM("ML_"//ctrd_bio(jl,2)) ,            &
+                    &          it, ztmltrdbio2(:,:,jl), ndimtrd1, ndextrd1 )
+            END DO
+
+            IF( kt == nitend )   CALL histclo( nidtrdbio )
+            !
+      END IF NETCDF_OUTPUT
+
+      ! Compute the control surface (for next time step) : flag = on
+      icountbio = 1
+
+
+# endif /* key_dimgout */
+
+      IF( MOD( itmod, nn_trd_trc ) == 0 ) THEN
+         !
+         ! III.5 Reset cumulative arrays to zero
+         ! -------------------------------------
+         nmoymltrdbio = 0
+         tmltrd_csum_ln_bio (:,:,:) = 0.e0
+         tmltrd_sum_bio     (:,:,:) = 0.e0
+      END IF
+
+      ! ======================================================================
+      ! Write restart file
+      ! ======================================================================
+
+! restart write is done in trd_mxl_trc_write which is called by trd_mxl_bio (Marina)
+!
+#endif
+   END SUBROUTINE trd_mxl_bio
+
+
+   REAL FUNCTION sum2d( ztab )
+      !!----------------------------------------------------------------------
+      !! CD ??? prevoir d'utiliser plutot prtctl
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT( in ) ::  ztab      
+      !!----------------------------------------------------------------------
+      sum2d = SUM( ztab(2:jpi-1,2:jpj-1) )
+   END FUNCTION sum2d
+
+
+   SUBROUTINE trd_mxl_trc_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_mxl_init  ***
+      !! 
+      !! ** Purpose :   computation of vertically integrated T and S budgets
+      !!      from ocean surface down to control surface (NetCDF output)
+      !!
+      !! ** Method/usage :
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER :: inum   ! logical unit
+      INTEGER :: ilseq, jl, jn, iiter
+      REAL(wp) ::   zjulian, zsto, zout
+      CHARACTER (LEN=40) ::   clop
+      CHARACTER (LEN=15) ::   csuff
+      CHARACTER (LEN=12) ::   clmxl
+      CHARACTER (LEN=16) ::   cltrcu
+      CHARACTER (LEN=10) ::   clvar
+
+      !!----------------------------------------------------------------------
+
+      ! ======================================================================
+      ! I. initialization
+      ! ======================================================================
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' trd_mxl_trc_init : Mixed-layer trends for passive tracers                '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~'
+         WRITE(numout,*)
+      ENDIF
+
+      
+      ! I.1 Check consistency of user defined preferences
+      ! -------------------------------------------------
+
+      IF( ( lk_trdmxl_trc ) .AND. ( MOD( nitend-nittrc000+1, nn_trd_trc ) /= 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, nn_trd_trc   = ', nn_trd_trc
+         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
+      ENDIF
+
+      ! * Debugging information *
+      IF( lldebug ) THEN
+         WRITE(numout,*) '               ln_trcadv_muscl = '      , ln_trcadv_muscl
+         WRITE(numout,*) '               ln_trdmxl_trc_instant = ', ln_trdmxl_trc_instant
+      ENDIF
+
+      IF( ( ln_trcadv_muscl .OR. ln_trcadv_muscl2 ) .AND. .NOT. ln_trdmxl_trc_instant ) THEN
+         WRITE(numout,cform_err)
+         WRITE(numout,*) '                Currently, you can NOT use simultaneously tracer MUSCL    '
+         WRITE(numout,*) '                advection and window averaged diagnostics of ML trends.   '
+         WRITE(numout,*) '                WHY? Everything in trdmxl_trc is coded for leap-frog, and '
+         WRITE(numout,*) '                MUSCL scheme is Euler forward for passive tracers (note   '
+         WRITE(numout,*) '                that MUSCL is leap-frog for active tracers T/S).          '
+         WRITE(numout,*) '                In particuliar, entrainment trend would be FALSE. However '
+         WRITE(numout,*) '                this residual is correct for instantaneous ML diagnostics.'
+         WRITE(numout,*) 
+         nstop = nstop + 1
+      ENDIF
+
+      ! I.2 Initialize arrays to zero or read a restart file
+      ! ----------------------------------------------------
+      nmoymltrd   = 0
+
+      rmld_trc           (:,:)     = 0.e0   ;   tml_trc            (:,:,:)   = 0.e0       ! inst.
+      tmltrdm_trc        (:,:,:)   = 0.e0   ;   tmlatfm_trc        (:,:,:)   = 0.e0
+      tmlradm_trc        (:,:,:)   = 0.e0
+
+      tml_sum_trc        (:,:,:)   = 0.e0   ;   tmltrd_sum_trc     (:,:,:,:) = 0.e0       ! mean
+      tmltrd_csum_ln_trc (:,:,:,:) = 0.e0   ;   rmld_sum_trc       (:,:)     = 0.e0
+
+#if defined key_pisces_reduced
+      nmoymltrdbio   = 0
+      tmltrd_sum_bio     (:,:,:) = 0.e0     ;   tmltrd_csum_ln_bio (:,:,:) = 0.e0
+      DO jl = 1, jp_pisces_trd
+          ctrd_bio(jl,1) = ctrbil(jl)   ! long name
+          ctrd_bio(jl,2) = ctrbio(jl)   ! short name
+       ENDDO
+#endif
+
+      IF( ln_rsttr .AND. ln_trdmxl_trc_restart ) THEN
+         CALL trd_mxl_trc_rst_read
+      ELSE
+         tmlb_trc           (:,:,:)   = 0.e0   ;   tmlbb_trc          (:,:,:)   = 0.e0     ! inst.
+         tmlbn_trc          (:,:,:)   = 0.e0
+
+         tml_sumb_trc       (:,:,:)   = 0.e0   ;   tmltrd_csum_ub_trc (:,:,:,:) = 0.e0     ! mean
+         tmltrd_atf_sumb_trc(:,:,:)   = 0.e0   ;   tmltrd_rad_sumb_trc(:,:,:)   = 0.e0 
+#if defined key_pisces_reduced
+         tmltrd_csum_ub_bio (:,:,:) = 0.e0
+#endif
+
+       ENDIF
+
+      icount = 1   ;   ionce  = 1  ! open specifier   
+
+#if defined key_pisces_reduced
+      icountbio = 1   ;   ioncebio  = 1  ! open specifier
+#endif
+
+      ! I.3 Read control surface from file ctlsurf_idx
+      ! ----------------------------------------------
+      IF( nn_ctls_trc == 1 ) THEN
+         CALL ctl_opn( inum, 'ctlsurf_idx', 'OLD', 'UNFORMATTED', 'SEQUENTIAL', -1, numout, lwp )
+         READ ( inum ) nbol_trc
+         CLOSE( inum )
+      ENDIF
+
+      ! ======================================================================
+      ! II. netCDF output initialization
+      ! ======================================================================
+
+#if defined key_dimgout 
+      ???
+#else
+      ! clmxl = legend root for netCDF output
+      IF( nn_ctls_trc == 0 ) THEN                                   ! control surface = mixed-layer with density criterion
+         clmxl = 'Mixed Layer '
+      ELSE IF( nn_ctls_trc == 1 ) THEN                              ! control surface = read index from file 
+         clmxl = '      Bowl '
+      ELSE IF( nn_ctls_trc >= 2 ) THEN                              ! control surface = model level
+         WRITE(clmxl,'(A10,I2,1X)') 'Levels 1 -', nn_ctls_trc
+      ENDIF
+
+      ! II.1 Define frequency of output and means
+      ! -----------------------------------------
+      IF( ln_mskland )   THEN   ;   clop = "only(x)"   ! put 1.e+20 on land (very expensive!!)
+      ELSE                      ;   clop = "x"         ! no use of the mask value (require less cp time)
+      ENDIF
+#  if defined key_diainstant
+      IF( .NOT. ln_trdmxl_trc_instant ) THEN
+         STOP 'trd_mxl_trc : this was never checked. Comment this line to proceed...'
+      ENDIF
+      zsto = nn_trd_trc * rdt
+      clop = "inst("//TRIM(clop)//")"
+#  else
+      IF( ln_trdmxl_trc_instant ) THEN
+         zsto = rdt                                               ! inst. diags : we use IOIPSL time averaging
+      ELSE
+         zsto = nn_trd_trc * rdt                                    ! mean  diags : we DO NOT use any IOIPSL time averaging
+      ENDIF
+      clop = "ave("//TRIM(clop)//")"
+#  endif
+      zout = nn_trd_trc * rdt
+      iiter = ( nittrc000 - 1 ) / nn_dttrc
+
+      IF(lwp) WRITE (numout,*) '                netCDF initialization'
+
+      ! II.2 Compute julian date from starting date of the run
+      ! ------------------------------------------------------
+      CALL ymds2ju( nyear, nmonth, nday, rdt, zjulian )
+      zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
+      IF(lwp) WRITE(numout,*)' '  
+      IF(lwp) WRITE(numout,*)' Date 0 used :', nittrc000               &
+           &   ,' YEAR ', nyear, ' MONTH ', nmonth,' DAY ', nday       &
+           &   ,'Julian day : ', zjulian
+
+      ! II.3 Define the T grid trend file (nidtrd)
+      ! ------------------------------------------
+
+      !-- Define long and short names for the NetCDF output variables
+      !       ==> choose them according to trdmxl_trc_oce.F90 <==
+
+      ctrd_trc(jpmxl_trc_xad    ,1) = " Zonal advection"                 ;   ctrd_trc(jpmxl_trc_xad    ,2) = "_xad"
+      ctrd_trc(jpmxl_trc_yad    ,1) = " Meridional advection"            ;   ctrd_trc(jpmxl_trc_yad    ,2) = "_yad"
+      ctrd_trc(jpmxl_trc_zad    ,1) = " Vertical advection"              ;   ctrd_trc(jpmxl_trc_zad    ,2) = "_zad"
+      ctrd_trc(jpmxl_trc_ldf    ,1) = " Lateral diffusion"               ;   ctrd_trc(jpmxl_trc_ldf    ,2) = "_ldf"
+      ctrd_trc(jpmxl_trc_zdf    ,1) = " Vertical diff. (Kz)"             ;   ctrd_trc(jpmxl_trc_zdf    ,2) = "_zdf"
+      ctrd_trc(jpmxl_trc_bbl    ,1) = " Adv/diff. Bottom boundary layer" ;   ctrd_trc(jpmxl_trc_bbl    ,2) = "_bbl"
+      ctrd_trc(jpmxl_trc_dmp    ,1) = " Tracer damping"                  ;   ctrd_trc(jpmxl_trc_dmp    ,2) = "_dmp"
+      ctrd_trc(jpmxl_trc_sbc    ,1) = " Surface boundary cond."          ;   ctrd_trc(jpmxl_trc_sbc    ,2) = "_sbc"
+      ctrd_trc(jpmxl_trc_sms,    1) = " Sources minus sinks"             ;   ctrd_trc(jpmxl_trc_sms    ,2) = "_sms"
+      ctrd_trc(jpmxl_trc_radb   ,1) = " Correct negative concentrations" ;   ctrd_trc(jpmxl_trc_radb   ,2) = "_radb"
+      ctrd_trc(jpmxl_trc_radn   ,1) = " Correct negative concentrations" ;   ctrd_trc(jpmxl_trc_radn   ,2) = "_radn"
+      ctrd_trc(jpmxl_trc_atf    ,1) = " Asselin time filter"             ;   ctrd_trc(jpmxl_trc_atf    ,2) = "_atf"
+
+      DO jn = 1, jptra      
+      !-- Create a NetCDF file and enter the define mode 
+         IF( ln_trdtrc(jn) ) THEN
+            csuff="ML_"//ctrcnm(jn)
+            CALL dia_nam( clhstnam, nn_trd_trc, csuff )
+            CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,                                            &
+               &        1, jpi, 1, jpj, iiter, zjulian, rdt, nh_t(jn), nidtrd(jn), domain_id=nidom, snc4chunks=snc4set )
+      
+            !-- Define the ML depth variable
+            CALL histdef(nidtrd(jn), "mxl_depth", clmxl//" Mixed Layer Depth", "m",                        &
+               &        jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+
+         ENDIF
+      END DO
+
+#if defined key_pisces_reduced
+          !-- Create a NetCDF file and enter the define mode
+          CALL dia_nam( clhstnam, nn_trd_trc, 'trdbio' )
+          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,                                            &
+             &             1, jpi, 1, jpj, iiter, zjulian, rdt, nh_tb, nidtrdbio, domain_id=nidom, snc4chunks=snc4set )
+#endif
+
+      !-- Define physical units
+      IF( rn_ucf_trc == 1. ) THEN
+         cltrcu = "(mmole-N/m3)/sec"                              ! all passive tracers have the same unit 
+      ELSEIF ( rn_ucf_trc == 3600.*24.) THEN                         ! ??? trop long : seulement (mmole-N/m3)
+         cltrcu = "(mmole-N/m3)/day"                              ! ??? apparait dans les sorties netcdf 
+      ELSE
+         cltrcu = "unknown?"
+      ENDIF
+
+      !-- Define miscellaneous passive tracer mixed-layer variables 
+      IF( jpltrd_trc /= jpmxl_trc_atf .OR.  jpltrd_trc - 1 /= jpmxl_trc_radb ) THEN
+         STOP 'Error : jpltrd_trc /= jpmxl_trc_atf .OR.  jpltrd_trc - 1 /= jpmxl_trc_radb'  ! see below
+      ENDIF
+
+      DO jn = 1, jptra
+         !
+         IF( ln_trdtrc(jn) ) THEN
+            clvar = trim(ctrcnm(jn))//"ml"                           ! e.g. detml, zooml, no3ml, etc.
+            CALL histdef(nidtrd(jn), trim(clvar),           clmxl//" "//trim(ctrcnm(jn))//" Mixed Layer ",                         &
+              & "mmole-N/m3", jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zsto, zout )           
+            CALL histdef(nidtrd(jn), trim(clvar)//"_tot"  , clmxl//" "//trim(ctrcnm(jn))//" Total trend ",                         & 
+              &       cltrcu, jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zout, zout ) 
+            CALL histdef(nidtrd(jn), trim(clvar)//"_res"  , clmxl//" "//trim(ctrcnm(jn))//" dh/dt Entrainment (Resid.)",           & 
+              &       cltrcu, jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zout, zout )                   
+         
+            DO jl = 1, jpltrd_trc - 2                                ! <== only true if jpltrd_trc == jpmxl_trc_atf
+               CALL histdef(nidtrd(jn), trim(clvar)//trim(ctrd_trc(jl,2)), clmxl//" "//clvar//ctrd_trc(jl,1),                      & 
+                 &    cltrcu, jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zsto, zout ) ! IOIPSL: time mean
+            END DO                                                                         ! if zsto=rdt above
+         
+            CALL histdef(nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmxl_trc_radb,2)), clmxl//" "//clvar//ctrd_trc(jpmxl_trc_radb,1), & 
+              &       cltrcu, jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zout, zout ) ! IOIPSL: NO time mean
+         
+            CALL histdef(nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmxl_trc_atf,2)), clmxl//" "//clvar//ctrd_trc(jpmxl_trc_atf,1),   & 
+              &       cltrcu, jpi, jpj, nh_t(jn), 1  , 1, 1  , -99 , 32, clop, zout, zout ) ! IOIPSL: NO time mean
+         !
+         ENDIF
+      END DO
+
+#if defined key_pisces_reduced
+      DO jl = 1, jp_pisces_trd
+         CALL histdef(nidtrdbio, TRIM("ML_"//ctrd_bio(jl,2)), TRIM(clmxl//" ML_"//ctrd_bio(jl,1))   ,            &
+             &    cltrcu, jpi, jpj, nh_tb, 1  , 1, 1  , -99 , 32, clop, zsto, zout ) ! IOIPSL: time mean
+      END DO                                                                         ! if zsto=rdt above
+#endif
+
+      !-- Leave IOIPSL/NetCDF define mode
+      DO jn = 1, jptra
+         IF( ln_trdtrc(jn) )  CALL histend( nidtrd(jn), snc4set )
+      END DO
+
+#if defined key_pisces_reduced
+      !-- Leave IOIPSL/NetCDF define mode
+      CALL histend( nidtrdbio, snc4set )
+
+      IF(lwp) WRITE(numout,*)
+       IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization for ML bio trends'
+#endif
+
+#endif        /* key_dimgout */
+   END SUBROUTINE trd_mxl_trc_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                       Empty module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trd_mxl_trc( kt )                                   ! Empty routine
+      INTEGER, INTENT( in) ::   kt
+      WRITE(*,*) 'trd_mxl_trc: You should not have seen this print! error?', kt
+   END SUBROUTINE trd_mxl_trc
+   SUBROUTINE trd_mxl_bio( kt )
+      INTEGER, INTENT( in) ::   kt
+      WRITE(*,*) 'trd_mxl_bio: You should not have seen this print! error?', kt
+   END SUBROUTINE trd_mxl_bio
+   SUBROUTINE trd_mxl_trc_zint( ptrc_trdmxl, ktrd, ctype, kjn )
+      INTEGER               , INTENT( in ) ::  ktrd, kjn              ! ocean trend index and passive tracer rank
+      CHARACTER(len=2)      , INTENT( in ) ::  ctype                  ! surface/bottom (2D) or interior (3D) physics
+      REAL, DIMENSION(:,:,:), INTENT( in ) ::  ptrc_trdmxl            ! passive trc trend
+      WRITE(*,*) 'trd_mxl_trc_zint: You should not have seen this print! error?', ptrc_trdmxl(1,1,1)
+      WRITE(*,*) '  "      "      : You should not have seen this print! error?', ctype
+      WRITE(*,*) '  "      "      : You should not have seen this print! error?', ktrd
+      WRITE(*,*) '  "      "      : You should not have seen this print! error?', kjn
+   END SUBROUTINE trd_mxl_trc_zint
+   SUBROUTINE trd_mxl_trc_init                                    ! Empty routine
+      WRITE(*,*) 'trd_mxl_trc_init: You should not have seen this print! error?'
+   END SUBROUTINE trd_mxl_trc_init
+#endif
+
+   !!======================================================================
+END MODULE trdmxl_trc
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc_rst.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc_rst.F90	(revision 4946)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc_rst.F90	(revision 4946)
@@ -0,0 +1,220 @@
+MODULE trdmxl_trc_rst
+   !!======================================================================
+   !!                       ***  MODULE  trdmxl_rst  ***
+   !! Ocean dynamic :  Input/Output files for restart on mixed-layer diagnostics
+   !!======================================================================
+   !! History :  9.0  ! 07-03 (C. Deltel) Original code
+   !!----------------------------------------------------------------------
+  
+#if defined key_top && defined key_trdmxl_trc
+   !!----------------------------------------------------------------------
+   USE in_out_manager  ! I/O manager
+   USE iom             ! I/O module
+   USE trc             ! for nn_dttrc ctrcnm
+   USE trdmxl_trc_oce  ! for lk_trdmxl_trc
+
+   IMPLICIT NONE
+   PRIVATE
+  
+   PUBLIC   trd_mxl_trc_rst_read    ! routine called by trd_mxl_init
+   PUBLIC   trd_mxl_trc_rst_write   ! routine called by step.F90
+  
+   INTEGER ::   nummldw_trc               ! logical unit for mld restart
+   !!---------------------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/TRD/trdmxl_rst.F90,v 1.6 2006/11/14 09:46:13 opalod Exp $ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!---------------------------------------------------------------------------------
+  
+CONTAINS
+  
+
+    SUBROUTINE trd_mxl_trc_rst_write( kt )
+      !!--------------------------------------------------------------------------------
+      !!                  ***  SUBROUTINE trd_mxl_rst_wri  ***
+      !!                
+      !! ** Purpose :   Write mixed-layer diagnostics restart fields.
+      !!--------------------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
+      !
+      CHARACTER(LEN=20)   ::   clkt     ! ocean time-step deine as a character
+      CHARACTER(LEN=50)   ::   clname   ! ice output restart file name
+      CHARACTER (len=35) :: charout
+      INTEGER :: jl,  jk, jn               ! loop indice
+      !!--------------------------------------------------------------------------------
+
+      IF( kt == nitrst - nn_dttrc .OR. nitend - nit000 + 1 < 2 * nn_dttrc ) THEN ! idem trcrst.F90
+         IF( nitrst > 1.0e9 ) THEN
+            WRITE(clkt,*) nitrst
+         ELSE
+           WRITE(clkt,'(i8.8)') nitrst
+         ENDIF
+         clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_trdrst_trc_out)
+         IF(lwp) WRITE(numout,*) '             open ocean restart_mld_trc NetCDF  '//clname
+         CALL iom_open( clname, nummldw_trc, ldwrt = .TRUE., kiolib = jprstlib )
+      ENDIF
+
+      IF( kt == nitend .AND. lk_trdmxl_trc ) THEN
+
+         IF( kt == nitend .AND. lwp ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'trdmxl_trc_rst: output for ML diags. restart, with trd_mxl_trc_rst_write routine'
+            WRITE(numout,*) '~~~~~~~~~~~~~~'
+            WRITE(numout,*)
+         ENDIF
+
+         IF( ln_trdmxl_trc_instant ) THEN 
+            !
+            DO jn = 1, jptra
+               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlbb_trc_'  //ctrcnm(jn), tmlbb_trc  (:,:,jn) )
+               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlbn_trc_'  //ctrcnm(jn), tmlbn_trc  (:,:,jn) )
+               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlatfb_trc_'//ctrcnm(jn), tmlatfb_trc(:,:,jn) )
+               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlradb_trc_'//ctrcnm(jn), tmlradb_trc(:,:,jn) )
+            END DO
+            !
+         ELSE
+            !
+            CALL iom_rstput( kt, nitrst, nummldw_trc, 'rmldbn_trc', rmldbn_trc )  ! 2D x 1
+            
+            !                                                          ! ===========
+            DO jn = 1, jptra                                           ! tracer loop
+               !                                                       ! ===========
+
+               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlatfb_trc_' //ctrcnm(jn), tmlatfb_trc (:,:,jn) ) ! 2D x jptra
+               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlbb_trc_'   //ctrcnm(jn), tmlbb_trc   (:,:,jn) ) ! 2D x jptra
+               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlradb_trc_' //ctrcnm(jn), tmlradb_trc (:,:,jn) ) ! 2D x jptra
+
+               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmlbn_trc_'   //ctrcnm(jn), tmlbn_trc   (:,:,jn) ) ! 2D x jptra
+               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tml_sumb_trc_'//ctrcnm(jn), tml_sumb_trc(:,:,jn) ) ! 2D x jptra
+               
+               DO jk = 1, jpltrd_trc
+                  IF( jk < 10 )   THEN
+                     WRITE(charout,FMT="('tmltrd_csum_ub_trc_', A3, '_', I1)") ctrcnm(jn), jk
+                  ELSE
+                     WRITE(charout,FMT="('tmltrd_csum_ub_trc_', A3, '_', I2)") ctrcnm(jn), jk
+                  ENDIF
+                  CALL iom_rstput( kt, nitrst, nummldw_trc, charout, tmltrd_csum_ub_trc(:,:,jk,jn) )
+               END DO
+               
+               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmltrd_atf_sumb_trc_'//ctrcnm(jn) , &
+                    &           tmltrd_atf_sumb_trc(:,:,jn) ) ! 2D x jptra
+
+               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmltrd_rad_sumb_trc_'//ctrcnm(jn) , &
+                    &           tmltrd_rad_sumb_trc(:,:,jn) ) ! 2D x jptra
+               !                                                       ! ===========
+            END DO                                                     ! tracer loop
+            !                                                          ! ===========
+#if defined key_pisces_reduced
+            DO jl = 1, jp_pisces_trd
+               CALL iom_rstput( kt, nitrst, nummldw_trc, 'tmltrd_csum_ub_bio'//ctrd_bio(jl,2), tmltrd_csum_ub_bio(:,:,jl) )
+            ENDDO
+#endif
+
+         ENDIF
+         
+         CALL iom_close( nummldw_trc )
+         lrst_trc = .TRUE.
+
+      ENDIF
+
+    END SUBROUTINE trd_mxl_trc_rst_write
+
+
+    SUBROUTINE trd_mxl_trc_rst_read
+      !!----------------------------------------------------------------------------
+      !!                   ***  SUBROUTINE trd_mxl_rst_lec  ***
+      !!                   
+      !! ** Purpose :   Read file for mixed-layer diagnostics restart.
+      !!----------------------------------------------------------------------------
+      INTEGER  ::  inum       ! temporary logical unit
+      !
+      CHARACTER (len=35) :: charout
+      INTEGER ::  jk, jn, jl     ! loop indice
+      INTEGER ::  jlibalt = jprstlib
+      LOGICAL ::  llok
+      !!-----------------------------------------------------------------------------
+      
+      IF(lwp)  THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' trd_mxl_trc_rst_read : read the NetCDF MLD restart file'
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~'
+      ENDIF
+      
+      IF ( jprstlib == jprstdimg ) THEN
+        ! eventually read netcdf file (monobloc)  for restarting on different number of processors
+        ! if {cn_trdrst_trc_in}.nc exists, then set jlibalt to jpnf90
+        INQUIRE( FILE = TRIM(cn_trdrst_trc_in)//'.nc', EXIST = llok )
+        IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
+      ENDIF
+
+      CALL iom_open( cn_trdrst_trc_in, inum, kiolib = jlibalt ) 
+      
+      IF( ln_trdmxl_trc_instant ) THEN 
+         
+         DO jn = 1, jptra
+            CALL iom_get( inum, jpdom_autoglo, 'tmlbb_trc_'  //ctrcnm(jn), tmlbb_trc  (:,:,jn) )
+            CALL iom_get( inum, jpdom_autoglo, 'tmlbn_trc_'  //ctrcnm(jn), tmlbn_trc  (:,:,jn) )
+            CALL iom_get( inum, jpdom_autoglo, 'tmlatfb_trc_'//ctrcnm(jn), tmlatfb_trc(:,:,jn) )
+            CALL iom_get( inum, jpdom_autoglo, 'tmlradb_trc_'//ctrcnm(jn), tmlradb_trc(:,:,jn) )
+         END DO
+         
+      ELSE
+         CALL iom_get( inum, jpdom_autoglo, 'rmldbn_trc', rmldbn_trc ) ! needed for rmld_sum
+         
+         !                                                          ! ===========
+         DO jn = 1, jptra                                           ! tracer loop
+            !                                                       ! ===========
+            CALL iom_get( inum, jpdom_autoglo, 'tmlatfb_trc_' //ctrcnm(jn), tmlatfb_trc(:,:,jn) )
+            CALL iom_get( inum, jpdom_autoglo, 'tmlbb_trc_'   //ctrcnm(jn), tmlbb_trc  (:,:,jn) )
+            CALL iom_get( inum, jpdom_autoglo, 'tmlradb_trc_' //ctrcnm(jn), tmlradb_trc(:,:,jn) )
+
+            CALL iom_get( inum, jpdom_autoglo, 'tmlbn_trc_'   //ctrcnm(jn), tmlbn_trc   (:,:,jn) ) ! needed for tml_sum
+            CALL iom_get( inum, jpdom_autoglo, 'tml_sumb_trc_'//ctrcnm(jn), tml_sumb_trc(:,:,jn) )
+            
+            DO jk = 1, jpltrd_trc
+               IF( jk < 10 )   THEN
+                  WRITE(charout,FMT="('tmltrd_csum_ub_trc_', A3, '_', I1)") ctrcnm(jn), jk
+               ELSE
+                  WRITE(charout,FMT="('tmltrd_csum_ub_trc_', A3, '_', I2)") ctrcnm(jn), jk
+               ENDIF
+               CALL iom_get( inum, jpdom_autoglo, charout, tmltrd_csum_ub_trc(:,:,jk,jn) )
+            END DO
+            
+            CALL iom_get( inum, jpdom_autoglo, 'tmltrd_atf_sumb_trc_'//ctrcnm(jn) , &
+                 &        tmltrd_atf_sumb_trc(:,:,jn) )
+
+            CALL iom_get( inum, jpdom_autoglo, 'tmltrd_rad_sumb_trc_'//ctrcnm(jn) , &
+                 &        tmltrd_rad_sumb_trc(:,:,jn) )
+            !                                                       ! ===========
+         END DO                                                     ! tracer loop
+         !                                                          ! ===========
+
+#if defined key_pisces_reduced
+         DO jl = 1, jp_pisces_trd
+            CALL iom_get( inum, jpdom_autoglo, 'tmltrd_csum_ub_bio'//ctrd_bio(jl,2), tmltrd_csum_ub_bio(:,:,jl) )
+         ENDDO
+#endif
+         
+         CALL iom_close( inum )
+      ENDIF
+      
+    END SUBROUTINE trd_mxl_trc_rst_read
+  
+#else
+  !!=================================================================================
+  !!                       ***  MODULE  trdmxl_rst  ***
+  !! Ocean dynamic :  Input/Output files for restart on mixed-layer diagnostics
+  !!=================================================================================
+CONTAINS
+  SUBROUTINE trd_mxl_trc_rst_opn( kt )
+    WRITE(*,*) 'trd_mxl_trc_rst_opn: You should not have seen this print! error?', kt
+  END SUBROUTINE trd_mxl_trc_rst_opn
+  SUBROUTINE trd_mxl_trc_rst_write( kt )           !  No ML diags ==> empty routine
+    WRITE(*,*) 'trd_mxl_trc_rst_wri: You should not have seen this print! error?', kt
+  END SUBROUTINE trd_mxl_trc_rst_write
+  SUBROUTINE trd_mxl_trc_rst_read                  !  No ML Diags ==> empty routine
+  END SUBROUTINE trd_mxl_trc_rst_read
+#endif
+
+  !!=================================================================================
+END MODULE trdmxl_trc_rst
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc.F90	(revision 4946)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc.F90	(revision 4946)
@@ -0,0 +1,158 @@
+MODULE trdtrc
+   !!======================================================================
+   !!                       ***  MODULE  trdtrc  ***
+   !! Ocean diagnostics:  mixed layer passive tracer trends 
+   !!======================================================================
+   !! History :  3.0  !  2010-07  (C. Ethe)  Original code (from trdtrc.F90)
+   !!----------------------------------------------------------------------
+#if   defined key_top && ( defined key_trdmxl_trc   ||   defined key_trdtrc )
+   !!----------------------------------------------------------------------
+   !!   'key_trdmxl_trc'                  mixed layer trend diagnostics
+   !!   'key_trdtrc'                      3D trend diagnostics
+   !!----------------------------------------------------------------------
+   !!   trdtrc      : passive tracer trends 
+   !!----------------------------------------------------------------------
+   USE trc               ! tracer definitions (trn, trb, tra, etc.)
+   USE trcnam_trp
+   USE trd_oce
+   USE trdtrc_oce       ! definition of main arrays used for trends computations
+   USE trdmxl_trc        ! Mixed layer trends diag.
+   USE iom               ! I/O library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   INTERFACE trd_trc
+      MODULE PROCEDURE trd_trc_trp, trd_trc_bio
+   END INTERFACE
+
+   PUBLIC trd_trc
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Header:  $ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trd_trc_trp( ptrtrd, kjn, ktrd, kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_trc  ***
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in )  ::   kt                                  ! time step
+      INTEGER, INTENT( in )  ::   kjn                                 ! tracer index
+      INTEGER, INTENT( in )  ::   ktrd                                ! tracer trend index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout )  ::   ptrtrd  ! Temperature or U trend
+      CHARACTER (len=20) :: cltra
+      !!----------------------------------------------------------------------
+
+      IF( kt == nittrc000 ) THEN
+!         IF(lwp)WRITE(numout,*)
+!         IF(lwp)WRITE(numout,*) 'trd_trc:'
+!         IF(lwp)WRITE(numout,*) '~~~~~~~~~~~~'
+      ENDIF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Mixed layer trends for passive tracers
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+#if defined key_trdmxl_trc  
+      IF( lk_trdmxl_trc .AND. ln_trdtrc( kjn ) ) THEN
+         !
+         SELECT CASE ( ktrd )
+         CASE ( jptra_xad     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_xad, '3D', kjn )
+         CASE ( jptra_yad     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_yad, '3D', kjn )
+         CASE ( jptra_zad     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_zad, '3D', kjn )
+         CASE ( jptra_ldf     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_ldf, '3D', kjn )
+         CASE ( jptra_bbl     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_bbl, '3D', kjn )
+         CASE ( jptra_zdf     )
+            IF( ln_trcldf_iso ) THEN
+               CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_ldf, '3D', kjn )
+            ELSE
+               CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_zdf, '3D', kjn )
+            ENDIF
+         CASE ( jptra_dmp     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_dmp , '3D', kjn )
+         CASE ( jptra_nsr     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_sbc , '2D', kjn )
+         CASE ( jptra_sms     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_sms , '3D', kjn )
+         CASE ( jptra_radb    )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_radb, '3D', kjn )
+         CASE ( jptra_radn    )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_radn, '3D', kjn )
+         CASE ( jptra_atf     )   ;   CALL trd_mxl_trc_zint( ptrtrd, jpmxl_trc_atf , '3D', kjn )
+         END SELECT
+         !
+      END IF
+#endif
+
+      IF( lk_trdtrc .AND. ln_trdtrc( kjn ) ) THEN
+         !
+         SELECT CASE( ktrd )
+         CASE( jptra_xad  )       ;    WRITE (cltra,'("XAD_",4a)')
+         CASE( jptra_yad  )       ;    WRITE (cltra,'("YAD_",4a)')
+         CASE( jptra_zad  )       ;    WRITE (cltra,'("ZAD_",4a)')
+         CASE( jptra_ldf  )       ;    WRITE (cltra,'("LDF_",4a)')
+         CASE( jptra_bbl  )       ;    WRITE (cltra,'("BBL_",4a)')
+         CASE( jptra_nsr  )       ;    WRITE (cltra,'("FOR_",4a)')
+         CASE( jptra_zdf  )       ;    WRITE (cltra,'("ZDF_",4a)')
+         CASE( jptra_dmp  )       ;    WRITE (cltra,'("DMP_",4a)')
+         CASE( jptra_sms  )       ;    WRITE (cltra,'("SMS_",4a)')
+         CASE( jptra_atf  )       ;    WRITE (cltra,'("ATF_",4a)')
+         CASE( jptra_radb )       ;    WRITE (cltra,'("RDB_",4a)')
+         CASE( jptra_radn )       ;    WRITE (cltra,'("RDN_",4a)')
+         END SELECT
+                                          cltra = TRIM(cltra)//TRIM(ctrcnm(kjn))
+                                          CALL iom_put( cltra,  ptrtrd(:,:,:) )
+         !
+      END IF
+
+   END SUBROUTINE trd_trc_trp
+
+   SUBROUTINE trd_trc_bio( ptrbio, ktrd, kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trd_bio  ***
+      !!----------------------------------------------------------------------
+
+      INTEGER, INTENT( in )  ::   kt                                  ! time step
+      INTEGER, INTENT( in )  ::   ktrd                                ! bio trend index
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout )  ::   ptrbio  ! Bio trend
+      !!----------------------------------------------------------------------
+
+#if defined key_trdmxl_trc  
+      CALL trd_mxl_bio_zint( ptrbio, ktrd ) ! Verticaly integrated biological trends
+#endif
+
+   END SUBROUTINE trd_trc_bio
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                       Empty module
+   !!----------------------------------------------------------------------
+
+   INTERFACE trd_trc
+      MODULE PROCEDURE trd_trc_trp, trd_trc_bio
+   END INTERFACE
+
+CONTAINS
+
+   SUBROUTINE trd_trc_trp( ptrtrd, kjn, ktrd, kt )
+      INTEGER               , INTENT( in )     ::   kt      ! time step
+      INTEGER               , INTENT( in )     ::   kjn     ! tracer index
+      INTEGER               , INTENT( in )     ::   ktrd    ! tracer trend index
+      REAL, DIMENSION(:,:,:), INTENT( inout )  ::   ptrtrd  ! Temperature or U trend
+      WRITE(*,*) 'trd_trc_trp : You should not have seen this print! error?', ptrtrd(1,1,1)
+      WRITE(*,*) '  "      "      : You should not have seen this print! error?', kjn
+      WRITE(*,*) '  "      "      : You should not have seen this print! error?', ktrd
+      WRITE(*,*) '  "      "      : You should not have seen this print! error?', kt
+   END SUBROUTINE trd_trc_trp
+
+   SUBROUTINE trd_trc_bio( ptrbio, ktrd, kt )
+      INTEGER               , INTENT( in )     ::   kt      ! time step
+      INTEGER               , INTENT( in )     ::   ktrd    ! tracer trend index
+      REAL, DIMENSION(:,:,:), INTENT( inout )  ::   ptrbio  ! Temperature or U trend
+      WRITE(*,*) 'trd_trc_trp : You should not have seen this print! error?', ptrbio(1,1,1)
+      WRITE(*,*) '  "      "      : You should not have seen this print! error?', ktrd
+      WRITE(*,*) '  "      "      : You should not have seen this print! error?', kt
+   END SUBROUTINE trd_trc_bio
+
+#endif
+   !!======================================================================
+END MODULE trdtrc
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc_oce.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc_oce.F90	(revision 4946)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/TRP/trdtrc_oce.F90	(revision 4946)
@@ -0,0 +1,180 @@
+MODULE trdtrc_oce
+   !!======================================================================
+   !!                   ***  MODULE trdtrc_oce  ***
+   !! Ocean trends :   set tracer and momentum trend variables
+   !!======================================================================
+#if defined key_top   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_top'                                                TOP models
+   !!----------------------------------------------------------------------
+   USE par_oce       ! ocean parameters
+   USE par_trc       ! passive tracers parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+   !                                         !!* Namelist namtoptrd:  diagnostics on passive tracers trends
+   INTEGER  ::    nn_trd_trc                  !: time step frequency dynamics and tracers trends
+   INTEGER  ::    nn_ctls_trc                 !: control surface type for trends vertical integration
+   REAL(wp) ::    rn_ucf_trc                  !: unit conversion factor (for netCDF trends outputs)
+   LOGICAL  ::    ln_trdmxl_trc_instant       !: flag to diagnose inst./mean ML trc trends
+   LOGICAL  ::    ln_trdmxl_trc_restart       !: flag to restart mixed-layer trc diagnostics
+   CHARACTER(len=50) ::  cn_trdrst_trc_in     !: suffix of pass. tracer restart name (input)
+   CHARACTER(len=50) ::  cn_trdrst_trc_out    !: suffix of pass. tracer restart name (output)
+   LOGICAL, DIMENSION(jptra) ::   ln_trdtrc   !: large trends diagnostic to write or not (namelist)
+
+# if defined key_trdtrc && defined key_iomput
+   LOGICAL, PARAMETER ::   lk_trdtrc = .TRUE. 
+# else
+   LOGICAL, PARAMETER ::   lk_trdtrc = .FALSE.   !: ML trend flag
+# endif
+
+# if defined key_trdmxl_trc   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_trdmxl_trc'                     mixed layer trends diagnostics
+   !!----------------------------------------------------------------------
+
+   LOGICAL, PARAMETER ::   lk_trdmxl_trc = .TRUE.    !: ML trend flag
+
+   INTEGER, PARAMETER ::            & !: mixed layer trends indices
+        jpmxl_trc_xad     =  1,     & !:     zonal       advection     
+        jpmxl_trc_yad     =  2,     & !:     meridonal   =========
+        jpmxl_trc_zad     =  3,     & !:     vertical    =========
+        jpmxl_trc_ldf     =  4,     & !:     lateral diffusion (geopot. or iso-neutral)
+        jpmxl_trc_zdf     =  5,     & !:     vertical diffusion (TKE)
+        jpmxl_trc_bbl     =  6,     & !:     bottom boundary layer (advective/diffusive)
+        jpmxl_trc_dmp     =  7,     & !:     internal restoring trend
+        jpmxl_trc_sbc     =  8,     & !:     forcing 
+        jpmxl_trc_sms     =  9,     & !:     sources minus sinks trend
+  !     jpmxl_trc_xxx     = xx,     & !:     add here any additional trend    (** AND UPDATE JPLTRD_TRC BELOW **)
+        jpmxl_trc_radn    = 10,     & !:     corr. trn<0 in trcrad
+        jpmxl_trc_radb    = 11,     & !:     corr. trb<0 in trcrad (like atf) (** MUST BE BEFORE THE LAST ONE **)
+        jpmxl_trc_atf     = 12        !:     asselin trend                    (** MUST BE    THE      LAST ONE**)
+
+   !! Trends diagnostics parameters
+   !!---------------------------------------------------------------------
+   INTEGER, PARAMETER :: jpltrd_trc = 12    !: number of mixed-layer trends arrays
+      
+   INTEGER            :: jpktrd_trc         !: max level for mixed-layer trends diag.
+
+   !! Arrays used for diagnosing mixed-layer trends 
+   !!---------------------------------------------------------------------
+   CHARACTER(LEN=80) :: clname_trc, ctrd_trc(jpltrd_trc+1,2)
+
+   INTEGER, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   &
+      nmld_trc       , &                            !: mixed layer depth indexes 
+      nbol_trc                                   !: mixed-layer depth indexes when read from file
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  wkx_trc  !:
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  rmld_trc     !: ML depth (m) corresponding to nmld_trc
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  rmld_sum_trc !: needed to compute the leap-frog time mean of ML depth
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  rmldbn_trc   !: idem
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  &
+      tml_trc    ,                        &      !: \ "now" mixed layer temperature/salinity
+      tmlb_trc   ,                        &      !: /  and associated "before" fields
+      tmlbb_trc  ,                        &      !: \  idem, but valid at the 1rst time step of the
+      tmlbn_trc  ,                        &      !: /  current analysis window
+      tml_sum_trc,                        &      !: mixed layer T, summed over the current analysis period
+      tml_sumb_trc,                       &      !: idem, but from the previous analysis period
+      tmltrd_atf_sumb_trc,                &      !: Asselin trends, summed over the previous analysis period
+      tmltrd_rad_sumb_trc                        !: trends due to trb correction in trcrad.F90, summed over the
+                                                 !:     previous analysis period
+                                                 
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  &      
+      tmlatfb_trc, tmlatfn_trc ,          &      !: "before" Asselin contrib. at beginning of the averaging
+                                                 !:     period (i.e. last contrib. from previous such period)
+                                                 !:     and "now" Asselin contrib. to the ML trc. trends
+      tmlatfm_trc,                        &      !: accumulator for Asselin trends (needed for storage only)
+      tmlradb_trc, tmlradn_trc ,          &      !: similar to Asselin above, but for the trend due to trb
+                                                 !:     correction in trcrad.F90
+      tmlradm_trc                                !: accumulator for the previous trcrad trend
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  &
+      tmltrd_trc,                         &      !: \ physical contributions to the total trend (for T/S),
+                                                 !: / cumulated over the current analysis window
+      tmltrd_sum_trc,                     &      !: sum of these trends over the analysis period
+      tmltrd_csum_ln_trc,                 &      !: now cumulated sum of trends over the "lower triangle"
+      tmltrd_csum_ub_trc                         !: before (prev. analysis period) cumulated sum over the
+                                                 !: upper triangle
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  &
+      tmltrdm_trc                                !: total cumulative trends over the analysis window
+
+# else
+   LOGICAL, PARAMETER ::   lk_trdmxl_trc = .FALSE.   !: ML trend flag
+# endif
+
+# if defined key_pisces_reduced
+   CHARACTER(LEN=80) :: clname_bio, ctrd_bio(jpdiabio,2)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  &
+      tmltrd_bio,                         &      !: \ biological contributions to the total trend ,
+                                                 !: / cumulated over the current analysis window
+      tmltrd_sum_bio,                     &      !: sum of these trends over the analysis period
+      tmltrd_csum_ln_bio,                 &      !: now cumulated sum of trends over the "lower triangle"
+      tmltrd_csum_ub_bio                         !: before (prev. analysis period) cumulated sum over the
+                                                 !: upper triangle
+#endif
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/TRD/trdmxl_oce.F90,v 1.2 2005/03/27 18:35:23 opalod Exp $ 
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION trd_trc_oce_alloc()
+      !!----------------------------------------------------------------------
+      !!         *** ROUTINE trd_trc_oce_alloc ***
+      !!----------------------------------------------------------------------
+      USE lib_mpp, ONLY: ctl_warn
+      INTEGER :: ierr(2)
+      !!----------------------------------------------------------------------
+      ierr(:) = 0
+      !
+# if defined key_trdmxl_trc
+      ALLOCATE(nmld_trc(jpi,jpj),          nbol_trc(jpi,jpj),           &
+               wkx_trc(jpi,jpj,jpk),       rmld_trc(jpi,jpj),           &
+               rmld_sum_trc(jpi,jpj),      rmldbn_trc(jpi,jpj),         &
+               tml_trc(jpi,jpj,jptra),     tmlb_trc(jpi,jpj,jptra),     &
+               tmlbb_trc(jpi,jpj,jptra),   tmlbn_trc(jpi,jpj,jptra),    &
+               tml_sum_trc(jpi,jpj,jptra), tml_sumb_trc(jpi,jpj,jptra), &
+               tmltrd_atf_sumb_trc(jpi,jpj,jptra),                      &
+               tmltrd_rad_sumb_trc(jpi,jpj,jptra),                      &
+               !
+               tmlatfb_trc(jpi,jpj,jptra), tmlatfn_trc(jpi,jpj,jptra),  &
+               tmlatfm_trc(jpi,jpj,jptra), tmlradb_trc(jpi,jpj,jptra),  &
+               tmlradn_trc(jpi,jpj,jptra), tmlradm_trc(jpi,jpj,jptra),  &
+               !
+               tmltrd_trc(jpi,jpj,jpltrd_trc,jptra)         , &
+               tmltrd_sum_trc(jpi,jpj,jpltrd_trc,jptra)     , &
+               tmltrd_csum_ln_trc(jpi,jpj,jpltrd_trc,jptra) , &
+               tmltrd_csum_ub_trc(jpi,jpj,jpltrd_trc,jptra) , &
+               !
+               tmltrdm_trc(jpi,jpj,jptra)                   , STAT=ierr(1) )
+#endif
+      !
+# if defined key_pisces_reduced
+      ALLOCATE( tmltrd_bio        (jpi,jpj,jpdiabio) ,     &
+         &      tmltrd_sum_bio    (jpi,jpj,jpdiabio) ,     &
+         &      tmltrd_csum_ln_bio(jpi,jpj,jpdiabio) ,     &
+         &      tmltrd_csum_ub_bio(jpi,jpj,jpdiabio) , STAT=ierr(2) )
+# endif
+      !
+      trd_trc_oce_alloc = MAXVAL(ierr)
+      !
+      IF( trd_trc_oce_alloc /= 0 )   CALL ctl_warn('trd_trc_oce_alloc: failed to allocate arrays')
+      !
+# if defined key_trdmxl_trc
+      jpktrd_trc = jpk      ! Initialise what used to be a parameter - max level for mixed-layer trends diag.
+# endif
+      !
+   END FUNCTION trd_trc_oce_alloc
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Empty module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE trdtrc_oce
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90	(revision 4946)
@@ -66,4 +66,7 @@
    USE oce , ONLY :   rhop    =>    rhop    !: potential volumic mass (kg m-3) 
    USE oce , ONLY :   rhd     =>    rhd     !: in situ density anomalie rhd=(rho-rau0)/rau0 (no units)
+#if defined key_offline
+   USE oce , ONLY :   rab_n   =>    rab_n   !: local thermal/haline expension ratio at T-points
+#endif
    USE oce , ONLY :   hdivn   =>    hdivn   !: horizontal divergence (1/s)
    USE oce , ONLY :   rotn    =>    rotn    !: relative vorticity    [s-1]
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/trcini.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 4946)
@@ -191,7 +191,7 @@
       USE trcnxt        , ONLY:   trc_nxt_alloc
       USE trczdf        , ONLY:   trc_zdf_alloc
-      USE trdmod_trc_oce, ONLY:   trd_mod_trc_oce_alloc
-#if defined key_trdmld_trc 
-      USE trdmld_trc    , ONLY:   trd_mld_trc_alloc
+      USE trdtrc_oce    , ONLY:   trd_trc_oce_alloc
+#if defined key_trdmxl_trc 
+      USE trdmxl_trc    , ONLY:   trd_mxl_trc_alloc
 #endif
       !
@@ -203,7 +203,7 @@
       ierr = ierr + trc_nxt_alloc()
       ierr = ierr + trc_zdf_alloc()
-      ierr = ierr + trd_mod_trc_oce_alloc()
-#if defined key_trdmld_trc 
-      ierr = ierr + trd_mld_trc_alloc()
+      ierr = ierr + trd_trc_oce_alloc()
+#if defined key_trdmxl_trc 
+      ierr = ierr + trd_mxl_trc_alloc()
 #endif
       !
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/trcnam.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/trcnam.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/trcnam.F90	(revision 4946)
@@ -25,6 +25,6 @@
    USE trcnam_c14b       ! C14 SMS namelist
    USE trcnam_my_trc     ! MY_TRC SMS namelist
-   USE trdmod_oce       
-   USE trdmod_trc_oce
+   USE trd_oce       
+   USE trdtrc_oce
    USE iom               ! I/O manager
 
@@ -119,5 +119,5 @@
 
 
-#if defined key_trdmld_trc || defined key_trdtrc
+#if defined key_trdmxl_trc || defined key_trdtrc
 
          REWIND( numnat_ref )              ! Namelist namtrc_trd in reference namelist : Passive tracer trends
@@ -132,11 +132,11 @@
          IF(lwp) THEN
             WRITE(numout,*)
-            WRITE(numout,*) ' trd_mld_trc_init : read namelist namtrc_trd                    '
+            WRITE(numout,*) ' trd_mxl_trc_init : read namelist namtrc_trd                    '
             WRITE(numout,*) ' ~~~~~~~~~~~~~~~~                                               '
             WRITE(numout,*) '   * frequency of trends diagnostics   nn_trd_trc             = ', nn_trd_trc
             WRITE(numout,*) '   * control surface type              nn_ctls_trc            = ', nn_ctls_trc
-            WRITE(numout,*) '   * restart for ML diagnostics        ln_trdmld_trc_restart  = ', ln_trdmld_trc_restart
+            WRITE(numout,*) '   * restart for ML diagnostics        ln_trdmxl_trc_restart  = ', ln_trdmxl_trc_restart
             WRITE(numout,*) '   * flag to diagnose trends of                                 '
-            WRITE(numout,*) '     instantantaneous or mean ML T/S   ln_trdmld_trc_instant  = ', ln_trdmld_trc_instant
+            WRITE(numout,*) '     instantantaneous or mean ML T/S   ln_trdmxl_trc_instant  = ', ln_trdmxl_trc_instant
             WRITE(numout,*) '   * unit conversion factor            rn_ucf_trc             = ', rn_ucf_trc
             DO jn = 1, jptra
@@ -266,7 +266,7 @@
       !!---------------------------------------------------------------------
       INTEGER ::  ierr
-#if defined key_trdmld_trc  || defined key_trdtrc
+#if defined key_trdmxl_trc  || defined key_trdtrc
       NAMELIST/namtrc_trd/ nn_trd_trc, nn_ctls_trc, rn_ucf_trc, &
-         &                ln_trdmld_trc_restart, ln_trdmld_trc_instant, &
+         &                ln_trdmxl_trc_restart, ln_trdmxl_trc_instant, &
          &                cn_trdrst_trc_in, cn_trdrst_trc_out, ln_trdtrc
 #endif
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/trcrst.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 4946)
@@ -137,5 +137,5 @@
           CALL trc_rst_stat            ! statistics
           CALL iom_close( numrtw )     ! close the restart file (only at last time step)
-#if ! defined key_trdmld_trc
+#if ! defined key_trdmxl_trc
           lrst_trc = .FALSE.
 #endif
Index: branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/trcstp.F90
===================================================================
--- branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/trcstp.F90	(revision 4944)
+++ branches/2014/dev_MERGE_2014/NEMOGCM/NEMO/TOP_SRC/trcstp.F90	(revision 4946)
@@ -19,6 +19,6 @@
    USE trcwri
    USE trcrst
-   USE trdmod_trc_oce
-   USE trdmld_trc
+   USE trdtrc_oce
+   USE trdmxl_trc
    USE iom
    USE in_out_manager
@@ -59,5 +59,5 @@
       IF( nn_timing == 1 )   CALL timing_start('trc_stp')
       !
-      IF( kt == nittrc000 .AND. lk_trdmld_trc )  CALL trd_mld_trc_init    ! trends: Mixed-layer
+      IF( kt == nittrc000 .AND. lk_trdmxl_trc )  CALL trd_mxl_trc_init    ! trends: Mixed-layer
       !
       IF( lk_vvl ) THEN                                                   ! update ocean volume due to ssh temporal evolution
@@ -100,5 +100,5 @@
          ENDIF
          IF( lrst_trc )            CALL trc_rst_wri  ( kt )       ! write tracer restart file
-         IF( lk_trdmld_trc  )      CALL trd_mld_trc  ( kt )       ! trends: Mixed-layer
+         IF( lk_trdmxl_trc  )      CALL trd_mxl_trc  ( kt )       ! trends: Mixed-layer
          !
          IF( nn_dttrc /= 1   )     CALL trc_sub_reset( kt )       ! resetting physical variables when sub-stepping
