Index: /branches/2013/dev_MERGE_2013/NEMOGCM/CONFIG/SHARED/1_namelist_ref
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/CONFIG/SHARED/1_namelist_ref	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/CONFIG/SHARED/1_namelist_ref	(revision 4292)
@@ -507,4 +507,5 @@
 !-----------------------------------------------------------------------
    ln_tide_pot   = .true.   !  use tidal potential forcing
+   nb_harmo      =    11    !  number of constituents used
    clname(1)     =   'M2'   !  name of constituent
    clname(2)     =   'S2'
@@ -700,4 +701,17 @@
    ln_dynadv_cen2= .false. !  flux form - 2nd order centered scheme
    ln_dynadv_ubs = .false. !  flux form - 3rd order UBS      scheme
+/
+!-----------------------------------------------------------------------
+&nam_vvl    !   vertical coordinate options
+!-----------------------------------------------------------------------
+   ln_vvl_zstar  = .true.           !  zstar vertical coordinate                   
+   ln_vvl_ztilde = .false.          !  ztilde vertical coordinate: only high frequency variations
+   ln_vvl_layer  = .false.          !  full layer vertical coordinate
+   ln_vvl_ztilde_as_zstar = .false. !  ztilde vertical coordinate emulating zstar
+   rn_ahe3       = 0.0e0            !  thickness diffusion coefficient
+   rn_rst_e3t    = 30.e0            !  ztilde to zstar restoration timescale [days]
+   rn_lf_cutoff  = 5.0e0            !  cutoff frequency for low-pass filter  [days]
+   rn_zdef_max   = 0.9e0            !  maximum fractional e3t deformation
+   ln_vvl_dbg    = .true.           !  debug prints    (T/F)
 /
 !-----------------------------------------------------------------------
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/CONFIG/SHARED/namelist_ref
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 4292)
@@ -513,4 +513,5 @@
 !-----------------------------------------------------------------------
    ln_tide_pot   = .true.   !  use tidal potential forcing
+   nb_harmo      =    11    !  number of constituents used
    clname(1)     =   'M2'   !  name of constituent
    clname(2)     =   'S2'
@@ -712,4 +713,17 @@
    ln_dynadv_cen2= .false. !  flux form - 2nd order centered scheme
    ln_dynadv_ubs = .false. !  flux form - 3rd order UBS      scheme
+/
+!-----------------------------------------------------------------------
+&nam_vvl    !   vertical coordinate options
+!-----------------------------------------------------------------------
+   ln_vvl_zstar  = .true.           !  zstar vertical coordinate                   
+   ln_vvl_ztilde = .false.          !  ztilde vertical coordinate: only high frequency variations
+   ln_vvl_layer  = .false.          !  full layer vertical coordinate
+   ln_vvl_ztilde_as_zstar = .false. !  ztilde vertical coordinate emulating zstar
+   rn_ahe3       = 0.0e0            !  thickness diffusion coefficient
+   rn_rst_e3t    = 30.e0            !  ztilde to zstar restoration timescale [days]
+   rn_lf_cutoff  = 5.0e0            !  cutoff frequency for low-pass filter  [days]
+   rn_zdef_max   = 0.9e0            !  maximum fractional e3t deformation
+   ln_vvl_dbg    = .true.           !  debug prints    (T/F)
 /
 !-----------------------------------------------------------------------
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/LIM_SRC_2/limsbc_2.F90	(revision 4292)
@@ -24,4 +24,5 @@
    USE phycst           ! physical constants
    USE dom_oce          ! ocean domain
+   USE domvvl           ! ocean vertical scale factors
    USE dom_ice_2        ! LIM-2: ice domain
    USE ice_2            ! LIM-2: ice variables
@@ -59,4 +60,5 @@
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/LIM2 4.0 , UCL - NEMO Consortium (2011)
@@ -446,4 +448,6 @@
       !!-------------------------------------------------------------------
       !
+      INTEGER :: jk           ! local integer
+      !
       IF(lwp) WRITE(numout,*)
       IF(lwp) WRITE(numout,*) 'lim_sbc_init_2 : LIM-2 sea-ice - surface boundary condition'
@@ -472,4 +476,5 @@
          snwice_mass  (:,:) = 0.e0           ! no mass exchanges
          snwice_mass_b(:,:) = 0.e0           ! no mass exchanges
+         snwice_fmass (:,:) = 0.e0           ! no mass exchanges
       ENDIF
       IF( nn_ice_embd == 2 .AND.          &  ! full embedment (case 2) & no restart : 
@@ -477,4 +482,35 @@
          sshn(:,:) = sshn(:,:) - snwice_mass(:,:) * r1_rau0
          sshb(:,:) = sshb(:,:) - snwice_mass(:,:) * r1_rau0
+         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)) )
+         end do
+         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
       !
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/LIM_SRC_2/limthd_2.F90	(revision 4292)
@@ -237,5 +237,5 @@
             
             !  energy needed to bring ocean surface layer until its freezing
-            qcmif  (ji,jj) =  rau0 * rcp * fse3t_m(ji,jj,1) * ( tfu(ji,jj) - sst_m(ji,jj) - rt0 ) * ( 1 - zinda )
+            qcmif  (ji,jj) =  rau0 * rcp * fse3t_m(ji,jj) * ( tfu(ji,jj) - sst_m(ji,jj) - rt0 ) * ( 1 - zinda )
             
             !  calculate oceanic heat flux.
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90	(revision 4292)
@@ -40,4 +40,5 @@
    INTEGER :: e1u_id, e2v_id, sshn_id, gcb_id
    INTEGER :: trn_id, trb_id, tra_id
+   INTEGER :: unb_id, vnb_id
 
    !!----------------------------------------------------------------------
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 4292)
@@ -27,10 +27,19 @@
    USE agrif_opa_sponge
    USE lib_mpp
-   USE wrk_nemo  
+   USE wrk_nemo
+   USE dynspg_oce  
 
    IMPLICIT NONE
    PRIVATE
+
+   ! Barotropic arrays used to store open boundary data during
+   ! time-splitting loop:
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_w, vbdy_w, hbdy_w
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_e, vbdy_e, hbdy_e
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_n, vbdy_n, hbdy_n
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_s, vbdy_s, hbdy_s
     
-   PUBLIC   Agrif_tra, Agrif_dyn, Agrif_ssh, interpu, interpv
+   PUBLIC   Agrif_tra, Agrif_dyn, Agrif_ssh, Agrif_dyn_ts, Agrif_ssh_ts
+   PUBLIC   interpu, interpv, interpunb, interpvnb, interpsshn
 
 #  include "domzgr_substitute.h90"  
@@ -169,5 +178,5 @@
       REAL(wp) :: timeref
       REAL(wp) :: z2dt, znugdt
-      REAL(wp) :: zrhox, rhoy
+      REAL(wp) :: zrhox, zrhoy
       REAL(wp), POINTER, DIMENSION(:,:,:) :: zua, zva
       REAL(wp), POINTER, DIMENSION(:,:) :: spgv1, spgu1, zua2d, zva2d
@@ -180,5 +189,5 @@
 
       zrhox = Agrif_Rhox()
-      rhoy = Agrif_Rhoy()
+      zrhoy = Agrif_Rhoy()
 
       timeref = 1.
@@ -201,8 +210,10 @@
       zva2d = 0.
 
+#if defined key_dynspg_flt
       Agrif_SpecialValue=0.
       Agrif_UseSpecialValue = ln_spc_dyn
       CALL Agrif_Bc_variable(zua2d,e1u_id,calledweight=1.,procname=interpu2d)
       CALL Agrif_Bc_variable(zva2d,e2v_id,calledweight=1.,procname=interpv2d)
+#endif
       Agrif_UseSpecialValue = .FALSE.
 
@@ -210,15 +221,18 @@
       IF((nbondi == -1).OR.(nbondi == 2)) THEN
 
+#if defined key_dynspg_flt
          DO jj=1,jpj
-            laplacu(2,jj) = timeref * (zua2d(2,jj)/(rhoy*e2u(2,jj)))*umask(2,jj,1)
-         END DO
-
-         DO jk=1,jpkm1
-            DO jj=1,jpj
-               ua(1:2,jj,jk) = (zua(1:2,jj,jk)/(rhoy*e2u(1:2,jj)))
+            laplacu(2,jj) = timeref * (zua2d(2,jj)/(zrhoy*e2u(2,jj)))*umask(2,jj,1)
+         END DO
+#endif
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               ua(1:2,jj,jk) = (zua(1:2,jj,jk)/(zrhoy*e2u(1:2,jj)))
                ua(1:2,jj,jk) = ua(1:2,jj,jk) / fse3u(1:2,jj,jk)
             END DO
          END DO
 
+#if defined key_dynspg_flt
          DO jk=1,jpkm1
             DO jj=1,jpj
@@ -240,4 +254,7 @@
             ENDIF
          END DO
+#else
+         spgu(2,:) = ua_b(2,:)
+#endif
 
          DO jk=1,jpkm1
@@ -278,12 +295,13 @@
 
       IF((nbondi == 1).OR.(nbondi == 2)) THEN
-
+#if defined key_dynspg_flt
          DO jj=1,jpj
-            laplacu(nlci-2,jj) = timeref * (zua2d(nlci-2,jj)/(rhoy*e2u(nlci-2,jj)))
-         END DO
-
-         DO jk=1,jpkm1
-            DO jj=1,jpj
-               ua(nlci-2:nlci-1,jj,jk) = (zua(nlci-2:nlci-1,jj,jk)/(rhoy*e2u(nlci-2:nlci-1,jj)))
+            laplacu(nlci-2,jj) = timeref * (zua2d(nlci-2,jj)/(zrhoy*e2u(nlci-2,jj)))
+         END DO
+#endif
+
+         DO jk=1,jpkm1
+            DO jj=1,jpj
+               ua(nlci-2:nlci-1,jj,jk) = (zua(nlci-2:nlci-1,jj,jk)/(zrhoy*e2u(nlci-2:nlci-1,jj)))
 
                ua(nlci-2:nlci-1,jj,jk) = ua(nlci-2:nlci-1,jj,jk) / fse3u(nlci-2:nlci-1,jj,jk)
@@ -292,4 +310,5 @@
          END DO
 
+#if defined key_dynspg_flt
          DO jk=1,jpkm1
             DO jj=1,jpj
@@ -312,4 +331,7 @@
             ENDIF
          END DO
+#else
+         spgu(nlci-2,:) = ua_b(nlci-2,:)
+#endif
 
          DO jk=1,jpkm1
@@ -353,7 +375,9 @@
       IF((nbondj == -1).OR.(nbondj == 2)) THEN
 
+#if defined key_dynspg_flt
          DO ji=1,jpi
             laplacv(ji,2) = timeref * (zva2d(ji,2)/(zrhox*e1v(ji,2)))
          END DO
+#endif
 
          DO jk=1,jpkm1
@@ -364,4 +388,5 @@
          END DO
 
+#if defined key_dynspg_flt
          DO jk=1,jpkm1
             DO ji=1,jpi
@@ -383,4 +408,7 @@
             ENDIF
          END DO
+#else
+         spgv(:,2)=va_b(:,2)
+#endif
 
          DO jk=1,jpkm1
@@ -413,5 +441,5 @@
          DO jk=1,jpkm1
             DO ji=1,jpi
-               ua(ji,2,jk) = (zua(ji,2,jk)/(rhoy*e2u(ji,2)))*umask(ji,2,jk) 
+               ua(ji,2,jk) = (zua(ji,2,jk)/(zrhoy*e2u(ji,2)))*umask(ji,2,jk) 
                ua(ji,2,jk) = ua(ji,2,jk) / fse3u(ji,2,jk)
             END DO
@@ -422,7 +450,9 @@
       IF((nbondj == 1).OR.(nbondj == 2)) THEN
 
+#if defined key_dynspg_flt
          DO ji=1,jpi
             laplacv(ji,nlcj-2) = timeref * (zva2d(ji,nlcj-2)/(zrhox*e1v(ji,nlcj-2)))
          END DO
+#endif
 
          DO jk=1,jpkm1
@@ -433,4 +463,5 @@
          END DO
 
+#if defined key_dynspg_flt
          DO jk=1,jpkm1
             DO ji=1,jpi
@@ -438,5 +469,4 @@
             END DO
          END DO
-
 
          spgv(:,nlcj-2)=0.
@@ -453,4 +483,7 @@
             ENDIF
          END DO
+#else
+         spgv(:,nlcj-2)=va_b(:,nlcj-2)
+#endif
 
          DO jk=1,jpkm1
@@ -483,5 +516,5 @@
          DO jk=1,jpkm1
             DO ji=1,jpi
-               ua(ji,nlcj-1,jk) = (zua(ji,nlcj-1,jk)/(rhoy*e2u(ji,nlcj-1)))*umask(ji,nlcj-1,jk)
+               ua(ji,nlcj-1,jk) = (zua(ji,nlcj-1,jk)/(zrhoy*e2u(ji,nlcj-1)))*umask(ji,nlcj-1,jk)
                ua(ji,nlcj-1,jk) = ua(ji,nlcj-1,jk) / fse3u(ji,nlcj-1,jk)
             END DO
@@ -495,4 +528,128 @@
    END SUBROUTINE Agrif_dyn
 
+   SUBROUTINE Agrif_dyn_ts( kt, jn )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE Agrif_dyn_ts  ***
+      !!----------------------------------------------------------------------  
+      !! 
+      INTEGER, INTENT(in) ::   kt, jn
+      !!
+      INTEGER :: ji, jj
+      REAL(wp) :: zrhox, zrhoy
+      REAL(wp), POINTER, DIMENSION(:,:) :: spgv1, spgu1
+      REAL(wp), POINTER, DIMENSION(:,:) :: zunb, zvnb, zsshn
+      !!----------------------------------------------------------------------  
+
+      IF( Agrif_Root() )   RETURN
+
+      IF ((kt==nit000).AND.(jn==1)) THEN
+         ALLOCATE( ubdy_w(jpj), vbdy_w(jpj), hbdy_w(jpj))
+         ALLOCATE( ubdy_e(jpj), vbdy_e(jpj), hbdy_e(jpj))
+         ALLOCATE( ubdy_n(jpi), vbdy_n(jpi), hbdy_n(jpi))
+         ALLOCATE( ubdy_s(jpi), vbdy_s(jpi), hbdy_s(jpi))
+      ENDIF
+
+      IF (jn==1) THEN 
+         ! Fill boundary arrays at each baroclinic step 
+         ! with Parent grid barotropic fluxes and sea level
+         !
+         CALL wrk_alloc( jpi, jpj, zunb, zvnb, zsshn )
+
+         zrhox = Agrif_Rhox()
+         zrhoy = Agrif_Rhoy()
+
+!alt         Agrif_SpecialValue    = 0.e0
+!alt         Agrif_UseSpecialValue = .TRUE.
+!alt         CALL Agrif_Bc_variable(zsshn, sshn_id, procname=interpsshn )
+!alt         Agrif_UseSpecialValue = .FALSE.
+
+         Agrif_SpecialValue=0.
+         Agrif_UseSpecialValue = ln_spc_dyn
+         zunb(:,:) = 0._wp ; zvnb(:,:) = 0._wp
+         CALL Agrif_Bc_variable(zunb,unb_id,procname=interpunb)
+         CALL Agrif_Bc_variable(zvnb,vnb_id,procname=interpvnb)
+         Agrif_UseSpecialValue = .FALSE.
+
+         IF((nbondi == -1).OR.(nbondi == 2)) THEN
+            DO jj=1,jpj
+               ubdy_w(jj) = (zunb(2,jj)/(zrhoy*e2u(2,jj)))
+               vbdy_w(jj) = (zvnb(2,jj)/(zrhox*e1v(2,jj)))
+               hbdy_w(jj) = zsshn(2,jj)
+            END DO
+         ENDIF
+
+         IF((nbondi == 1).OR.(nbondi == 2)) THEN
+            DO jj=1,jpj
+               ubdy_e(jj) = zunb(nlci-2,jj)/(zrhoy*e2u(nlci-2,jj))
+               vbdy_e(jj) = zvnb(nlci-1,jj)/(zrhox*e1v(nlci-1,jj))
+               hbdy_e(jj) = zsshn(nlci-1,jj)
+            END DO
+         ENDIF
+
+         IF((nbondj == -1).OR.(nbondj == 2)) THEN
+            DO ji=1,jpi
+               ubdy_s(ji) = zunb(ji,2)/(zrhoy*e2u(ji,2))
+               vbdy_s(ji) = zvnb(ji,2)/(zrhox*e1v(ji,2))
+               hbdy_s(ji) = zsshn(ji,2)
+            END DO
+         ENDIF
+
+         IF((nbondj == 1).OR.(nbondj == 2)) THEN
+            DO ji=1,jpi
+               ubdy_n(ji) = zunb(ji,nlcj-1)/(zrhoy*e2u(ji,nlcj-1))
+               vbdy_n(ji) = zvnb(ji,nlcj-2)/(zrhox*e1v(ji,nlcj-2))
+               hbdy_n(ji) = zsshn(ji,nlcj-1)
+            END DO
+         ENDIF
+
+         CALL wrk_dealloc( jpi, jpj, zunb, zvnb, zsshn )
+      ENDIF ! jn==1
+
+      ! Then update velocities at each barotropic time step
+      IF((nbondi == -1).OR.(nbondi == 2)) THEN
+         DO jj=1,jpj
+            va_e(2,jj) = vbdy_w(jj) * hvr_e(2,jj)
+! Specified fluxes:
+            ua_e(2,jj) = ubdy_w(jj) * hur_e(2,jj)
+! Characteristics method:
+!alt            ua_e(2,jj) = 0.5_wp * ( ubdy_w(jj) * hur_e(2,jj) + ua_e(3,jj) &
+!alt                       &           - sqrt(grav * hur_e(2,jj)) * (sshn_e(3,jj) - hbdy_w(jj)) )
+         END DO
+      ENDIF
+
+      IF((nbondi == 1).OR.(nbondi == 2)) THEN
+         DO jj=1,jpj
+            va_e(nlci-1,jj) = vbdy_e(jj) * hvr_e(nlci-1,jj)
+! Specified fluxes:
+            ua_e(nlci-2,jj) = ubdy_e(jj) * hur_e(nlci-2,jj)
+! Characteristics method:
+!alt            ua_e(nlci-2,jj) = 0.5_wp * ( ubdy_e(jj) * hur_e(nlci-2,jj) + ua_e(nlci-3,jj) &
+!alt                            &           + sqrt(grav * hur_e(nlci-2,jj)) * (sshn_e(nlci-2,jj) - hbdy_e(jj)) )
+         END DO
+      ENDIF
+
+      IF((nbondj == -1).OR.(nbondj == 2)) THEN
+         DO ji=1,jpi
+            ua_e(ji,2) = ubdy_s(ji) * hur_e(ji,2)
+! Specified fluxes:
+            va_e(ji,2) = vbdy_s(ji) * hvr_e(ji,2)
+! Characteristics method:
+!alt            va_e(ji,2) = 0.5_wp * ( vbdy_s(ji) * hvr_e(ji,2) + va_e(ji,3) &
+!alt                       &           - sqrt(grav * hvr_e(ji,2)) * (sshn_e(ji,3) - hbdy_s(ji)) )
+         END DO
+      ENDIF
+
+      IF((nbondj == 1).OR.(nbondj == 2)) THEN
+         DO ji=1,jpi
+            ua_e(ji,nlcj-1) = ubdy_n(ji) * hur_e(ji,nlcj-1)
+! Specified fluxes:
+            va_e(ji,nlcj-2) = vbdy_n(ji) * hvr_e(ji,nlcj-2)
+! Characteristics method:
+!alt            va_e(ji,nlcj-2) = 0.5_wp * ( vbdy_n(ji) * hvr_e(ji,nlcj-2)  + va_e(ji,nlcj-3) &
+!alt                            &           + sqrt(grav * hvr_e(ji,nlcj-2)) * (sshn_e(ji,nlcj-2) - hbdy_n(ji)) )
+         END DO
+      ENDIF
+      !
+   END SUBROUTINE Agrif_dyn_ts
 
    SUBROUTINE Agrif_ssh( kt )
@@ -518,15 +675,54 @@
 
       IF((nbondj == -1).OR.(nbondj == 2)) THEN
-         ssha(:,2)=sshn(:,3)
-         sshn(:,2)=sshb(:,3)
+         ssha(:,2)=ssha(:,3)
+         sshn(:,2)=sshn(:,3)
       ENDIF
 
       IF((nbondj == 1).OR.(nbondj == 2)) THEN
          ssha(:,nlcj-1)=ssha(:,nlcj-2)
-         ssha(:,nlcj-1)=sshn(:,nlcj-2)                
+         sshn(:,nlcj-1)=sshn(:,nlcj-2)                
       ENDIF
 
    END SUBROUTINE Agrif_ssh
 
+   SUBROUTINE Agrif_ssh_ts( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE Agrif_ssh_ts  ***
+      !!----------------------------------------------------------------------  
+      INTEGER, INTENT(in) ::   kt
+      !!
+      !!----------------------------------------------------------------------  
+
+      IF((nbondi == -1).OR.(nbondi == 2)) THEN
+         ssha_e(2,:) = ssha_e(3,:)
+      ENDIF
+
+      IF((nbondi == 1).OR.(nbondi == 2)) THEN
+         ssha_e(nlci-1,:) = ssha_e(nlci-2,:)    
+      ENDIF
+
+      IF((nbondj == -1).OR.(nbondj == 2)) THEN
+         ssha_e(:,2) = ssha_e(:,3)
+      ENDIF
+
+      IF((nbondj == 1).OR.(nbondj == 2)) THEN
+         ssha_e(:,nlcj-1) = ssha_e(:,nlcj-2)            
+      ENDIF
+
+   END SUBROUTINE Agrif_ssh_ts
+
+   SUBROUTINE interpsshn(tabres,i1,i2,j1,j2)
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE interpsshn  ***
+      !!----------------------------------------------------------------------  
+      INTEGER, INTENT(in) :: i1,i2,j1,j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
+      !!
+      INTEGER :: ji,jj
+      !!----------------------------------------------------------------------  
+
+      tabres(i1:i2,j1:j2) = sshn(i1:i2,j1:j2)
+
+   END SUBROUTINE interpsshn
 
    SUBROUTINE interpu(tabres,i1,i2,j1,j2,k1,k2)
@@ -611,4 +807,48 @@
 
    END SUBROUTINE interpv2d
+
+   SUBROUTINE interpunb(tabres,i1,i2,j1,j2)
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE interpunb  ***
+      !!----------------------------------------------------------------------  
+      INTEGER, INTENT(in) :: i1,i2,j1,j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
+      !!
+      INTEGER :: ji,jj,jk
+      !!----------------------------------------------------------------------  
+
+      tabres(:,:) = 0.e0
+      DO jk=1,jpkm1
+         DO jj=j1,j2
+            DO ji=i1,i2
+               tabres(ji,jj) = tabres(ji,jj) + e2u(ji,jj) * un(ji,jj,jk) &
+                  * umask(ji,jj,jk) * fse3u(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE interpunb
+
+   SUBROUTINE interpvnb(tabres,i1,i2,j1,j2)
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE interpvnb  ***
+      !!----------------------------------------------------------------------  
+      INTEGER, INTENT(in) :: i1,i2,j1,j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
+      !!
+      INTEGER :: ji,jj,jk
+      !!----------------------------------------------------------------------  
+
+      tabres(:,:) = 0.e0
+      DO jk=1,jpkm1
+         DO jj=j1,j2
+            DO ji=i1,i2
+               tabres(ji,jj) = tabres(ji,jj) + e1v(ji,jj) * vn(ji,jj,jk) &
+                  * vmask(ji,jj,jk) * fse3v(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+   END SUBROUTINE interpvnb
 
 #else
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OFF_SRC/domain.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OFF_SRC/domain.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OFF_SRC/domain.F90	(revision 4292)
@@ -295,5 +295,5 @@
       !!      vertical scale factors.
       !!
-      !! ** Method  : - reference 1D vertical coordinate (gdep._0, e3._0)
+      !! ** Method  : - reference 1D vertical coordinate (gdep._1d, e3._1d)
       !!              - read/set ocean depth and ocean levels (bathy, mbathy)
       !!              - vertical coordinate (gdep., e3.) depending on the 
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OFF_SRC/domrea.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OFF_SRC/domrea.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OFF_SRC/domrea.F90	(revision 4292)
@@ -25,4 +25,6 @@
 
    PUBLIC   dom_rea    ! routine called by inidom.F90
+  !! * Substitutions
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OFF 3.3 , NEMO Consortium (2010)
@@ -173,25 +175,25 @@
             CALL iom_get( inum4, jpdom_unknown, 'esigw', esigw )
 
-            CALL iom_get( inum4, jpdom_data, 'e3t', e3t ) ! scale factors
-            CALL iom_get( inum4, jpdom_data, 'e3u', e3u )
-            CALL iom_get( inum4, jpdom_data, 'e3v', e3v )
-            CALL iom_get( inum4, jpdom_data, 'e3w', e3w )
-
-            CALL iom_get( inum4, jpdom_unknown, 'gdept_0', gdept_0 ) ! depth
-            CALL iom_get( inum4, jpdom_unknown, 'gdepw_0', gdepw_0 )
+            CALL iom_get( inum4, jpdom_data, 'e3t', fse3t_n(:,:,:) ) ! scale factors
+            CALL iom_get( inum4, jpdom_data, 'e3u', fse3u_n(:,:,:) )
+            CALL iom_get( inum4, jpdom_data, 'e3v', fse3v_n(:,:,:) )
+            CALL iom_get( inum4, jpdom_data, 'e3w', fse3w_n(:,:,:) )
+
+            CALL iom_get( inum4, jpdom_unknown, 'gdept_1d', gdept_1d ) ! depth
+            CALL iom_get( inum4, jpdom_unknown, 'gdepw_1d', gdepw_1d )
          ENDIF
 
  
          IF( ln_zps ) THEN                                           ! z-coordinate - partial steps
-            CALL iom_get( inum4, jpdom_unknown, 'gdept_0', gdept_0 )    ! reference depth
-            CALL iom_get( inum4, jpdom_unknown, 'gdepw_0', gdepw_0 )
-            CALL iom_get( inum4, jpdom_unknown, 'e3t_0'  , e3t_0   )    ! reference scale factors
-            CALL iom_get( inum4, jpdom_unknown, 'e3w_0'  , e3w_0   )
+            CALL iom_get( inum4, jpdom_unknown, 'gdept_1d', gdept_1d )  ! reference depth
+            CALL iom_get( inum4, jpdom_unknown, 'gdepw_1d', gdepw_1d )
+            CALL iom_get( inum4, jpdom_unknown, 'e3t_1d'  , e3t_1d   )    ! reference scale factors
+            CALL iom_get( inum4, jpdom_unknown, 'e3w_1d'  , e3w_1d   )
             !
             IF( nmsh <= 6 ) THEN                                        ! 3D vertical scale factors
-               CALL iom_get( inum4, jpdom_data, 'e3t', e3t )
-               CALL iom_get( inum4, jpdom_data, 'e3u', e3u )
-               CALL iom_get( inum4, jpdom_data, 'e3v', e3v )
-               CALL iom_get( inum4, jpdom_data, 'e3w', e3w )
+               CALL iom_get( inum4, jpdom_data, 'e3t', fse3t_n(:,:,:) )
+               CALL iom_get( inum4, jpdom_data, 'e3u', fse3u_n(:,:,:) )
+               CALL iom_get( inum4, jpdom_data, 'e3v', fse3v_n(:,:,:) )
+               CALL iom_get( inum4, jpdom_data, 'e3w', fse3w_n(:,:,:) )
             ELSE                                                        ! 2D bottom scale factors
                CALL iom_get( inum4, jpdom_data, 'e3t_ps', e3tp )
@@ -199,14 +201,14 @@
                !                                                        ! deduces the 3D scale factors
                DO jk = 1, jpk
-                  e3t(:,:,jk) = e3t_0(jk)                                     ! set to the ref. factors
-                  e3u(:,:,jk) = e3t_0(jk)
-                  e3v(:,:,jk) = e3t_0(jk)
-                  e3w(:,:,jk) = e3w_0(jk)
+                  fse3t_n(:,:,jk) = e3t_1d(jk)                                    ! set to the ref. factors
+                  fse3u_n(:,:,jk) = e3t_1d(jk)
+                  fse3v_n(:,:,jk) = e3t_1d(jk)
+                  fse3w_n(:,:,jk) = e3w_1d(jk)
                END DO
                DO jj = 1,jpj                                                  ! adjust the deepest values
                   DO ji = 1,jpi
                      ik = mbkt(ji,jj)
-                     e3t(ji,jj,ik) = e3tp(ji,jj) * tmask(ji,jj,1) + e3t_0(1) * ( 1._wp - tmask(ji,jj,1) )
-                     e3w(ji,jj,ik) = e3wp(ji,jj) * tmask(ji,jj,1) + e3w_0(1) * ( 1._wp - tmask(ji,jj,1) )
+                     fse3t_n(ji,jj,ik) = e3tp(ji,jj) * tmask(ji,jj,1) + e3t_1d(1) * ( 1._wp - tmask(ji,jj,1) )
+                     fse3w_n(ji,jj,ik) = e3wp(ji,jj) * tmask(ji,jj,1) + e3w_1d(1) * ( 1._wp - tmask(ji,jj,1) )
                   END DO
                END DO
@@ -214,21 +216,21 @@
                   DO jj = 1, jpjm1
                      DO ji = 1, jpim1
-                        e3u(ji,jj,jk) = MIN( e3t(ji,jj,jk), e3t(ji+1,jj,jk) )
-                        e3v(ji,jj,jk) = MIN( e3t(ji,jj,jk), e3t(ji,jj+1,jk) )
+                        fse3u_n(ji,jj,jk) = MIN( fse3t_n(ji,jj,jk), fse3t_n(ji+1,jj,jk) )
+                        fse3v_n(ji,jj,jk) = MIN( fse3t_n(ji,jj,jk), fse3t_n(ji,jj+1,jk) )
                      END DO
                   END DO
                END DO
-               CALL lbc_lnk( e3u , 'U', 1._wp )   ;   CALL lbc_lnk( e3uw, 'U', 1._wp )   ! lateral boundary conditions
-               CALL lbc_lnk( e3v , 'V', 1._wp )   ;   CALL lbc_lnk( e3vw, 'V', 1._wp )
+               CALL lbc_lnk( fse3u_n(:,:,:) , 'U', 1._wp )   ;   CALL lbc_lnk( fse3uw_n(:,:,:), 'U', 1._wp )   ! lateral boundary conditions
+               CALL lbc_lnk( fse3v_n(:,:,:) , 'V', 1._wp )   ;   CALL lbc_lnk( fse3vw_n(:,:,:), 'V', 1._wp )
                !
                DO jk = 1, jpk                        ! set to z-scale factor if zero (i.e. along closed boundaries)
-                  WHERE( e3u(:,:,jk) == 0._wp )   e3u(:,:,jk) = e3t_0(jk)
-                  WHERE( e3v(:,:,jk) == 0._wp )   e3v(:,:,jk) = e3t_0(jk)
+                  WHERE( fse3u_n(:,:,jk) == 0._wp )   fse3u_n(:,:,jk) = e3t_1d(jk)
+                  WHERE( fse3v_n(:,:,jk) == 0._wp )   fse3v_n(:,:,jk) = e3t_1d(jk)
                END DO
             END IF
 
             IF( iom_varid( inum4, 'gdept', ldstop = .FALSE. ) > 0 ) THEN   ! 3D depth of t- and w-level
-               CALL iom_get( inum4, jpdom_data, 'gdept', gdept )
-               CALL iom_get( inum4, jpdom_data, 'gdepw', gdepw )
+               CALL iom_get( inum4, jpdom_data, 'gdept', fsdept_n(:,:,:) )
+               CALL iom_get( inum4, jpdom_data, 'gdepw', fsdepw_n(:,:,:) )
             ELSE                                                           ! 2D bottom depth
                CALL iom_get( inum4, jpdom_data, 'hdept', zprt )
@@ -236,6 +238,6 @@
                !
                DO jk = 1, jpk                                              ! deduces the 3D depth
-                  gdept(:,:,jk) = gdept_0(jk)
-                  gdepw(:,:,jk) = gdepw_0(jk)
+                  fsdept_n(:,:,jk) = gdept_1d(jk)
+                  fsdepw_n(:,:,jk) = gdepw_1d(jk)
                END DO
                DO jj = 1, jpj
@@ -243,7 +245,7 @@
                      ik = mbkt(ji,jj)
                      IF( ik > 0 ) THEN
-                        gdepw(ji,jj,ik+1) = zprw(ji,jj)
-                        gdept(ji,jj,ik  ) = zprt(ji,jj)
-                        gdept(ji,jj,ik+1) = gdept(ji,jj,ik) + e3t(ji,jj,ik)
+                        fsdepw_n(ji,jj,ik+1) = zprw(ji,jj)
+                        fsdept_n(ji,jj,ik  ) = zprt(ji,jj)
+                        fsdept_n(ji,jj,ik+1) = fsdept_n(ji,jj,ik) + fse3t_n(ji,jj,ik)
                      ENDIF
                   END DO
@@ -254,15 +256,15 @@
 
          IF( ln_zco ) THEN           ! Vertical coordinates and scales factors
-            CALL iom_get( inum4, jpdom_unknown, 'gdept_0', gdept_0 ) ! depth
-            CALL iom_get( inum4, jpdom_unknown, 'gdepw_0', gdepw_0 )
-            CALL iom_get( inum4, jpdom_unknown, 'e3t_0'  , e3t_0   )
-            CALL iom_get( inum4, jpdom_unknown, 'e3w_0'  , e3w_0   )
+            CALL iom_get( inum4, jpdom_unknown, 'gdept_1d', gdept_1d ) ! depth
+            CALL iom_get( inum4, jpdom_unknown, 'gdepw_1d', gdepw_1d )
+            CALL iom_get( inum4, jpdom_unknown, 'e3t_1d'  , e3t_1d   )
+            CALL iom_get( inum4, jpdom_unknown, 'e3w_1d'  , e3w_1d   )
             DO jk = 1, jpk
-               e3t  (:,:,jk) = e3t_0(jk)                                     ! set to the ref. factors
-               e3u  (:,:,jk) = e3t_0(jk)
-               e3v  (:,:,jk) = e3t_0(jk)
-               e3w  (:,:,jk) = e3w_0(jk)
-               gdept(:,:,jk) = gdept_0(jk)
-               gdepw(:,:,jk) = gdepw_0(jk)
+               fse3t_n(:,:,jk) = e3t_1d(jk)                              ! set to the ref. factors
+               fse3u_n(:,:,jk) = e3t_1d(jk)
+               fse3v_n(:,:,jk) = e3t_1d(jk)
+               fse3w_n(:,:,jk) = e3w_1d(jk)
+               fsdept_n(:,:,jk) = gdept_1d(jk)
+               fsdepw_n(:,:,jk) = gdepw_1d(jk)
             END DO
          ENDIF
@@ -270,6 +272,6 @@
 !!gm BUG in s-coordinate this does not work!
       ! deepest/shallowest W level Above/Below ~10m
-      zrefdep = 10._wp - ( 0.1_wp * MINVAL(e3w_0) )                  ! ref. depth with tolerance (10% of minimum layer thickness)
-      nlb10 = MINLOC( gdepw_0, mask = gdepw_0 > zrefdep, dim = 1 )   ! shallowest W level Below ~10m
+      zrefdep = 10._wp - ( 0.1_wp * MINVAL(e3w_1d) )                 ! ref. depth with tolerance (10% of minimum layer thickness)
+      nlb10 = MINLOC( gdepw_1d, mask = gdepw_1d > zrefdep, dim = 1 ) ! shallowest W level Below ~10m
       nla10 = nlb10 - 1                                              ! deepest    W level Above ~10m
 !!gm end bug
@@ -312,10 +314,10 @@
          WRITE(numout,*) '              Reference z-coordinate depth and scale factors:'
          WRITE(numout, "(9x,' level   gdept    gdepw     e3t      e3w  ')" )
-         WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, gdept_0(jk), gdepw_0(jk), e3t_0(jk), e3w_0(jk), jk = 1, jpk )
+         WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, gdept_1d(jk), gdepw_1d(jk), e3t_1d(jk), e3w_1d(jk), jk = 1, jpk )
       ENDIF
 
       DO jk = 1, jpk
-         IF( e3w_0  (jk) <= 0._wp .OR. e3t_0  (jk) <= 0._wp )   CALL ctl_stop( ' e3w_0 or e3t_0 =< 0 ' )
-         IF( gdepw_0(jk) <  0._wp .OR. gdept_0(jk) <  0._wp )   CALL ctl_stop( ' gdepw_0 or gdept_0 < 0 ' )
+         IF( e3w_1d  (jk) <= 0._wp .OR. e3t_1d  (jk) <= 0._wp )   CALL ctl_stop( ' e3w_1d or e3t_1d =< 0 ' )
+         IF( gdepw_1d(jk) <  0._wp .OR. gdept_1d(jk) <  0._wp )   CALL ctl_stop( ' gdepw_1d or gdept_1d < 0 ' )
       END DO
       !                                     ! ============================
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 4292)
@@ -8,4 +8,5 @@
    !!            3.3  !  2010-09  (D. Storkey) add ice boundary conditions
    !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
+   !!            3.6  !  2012-01  (C. Rousset) add ice boundary conditions for lim3
    !!----------------------------------------------------------------------
 #if defined key_bdy 
@@ -27,22 +28,46 @@
       INTEGER, POINTER, DIMENSION(:,:)   ::  nbr
       INTEGER, POINTER, DIMENSION(:,:)   ::  nbmap
-      REAL   , POINTER, DIMENSION(:,:)   ::  nbw
-      REAL   , POINTER, DIMENSION(:,:)   ::  nbd
-      REAL   , POINTER, DIMENSION(:)     ::  flagu
-      REAL   , POINTER, DIMENSION(:)     ::  flagv
+      REAL(wp)   , POINTER, DIMENSION(:,:)   ::  nbw
+      REAL(wp)   , POINTER, DIMENSION(:,:)   ::  nbd
+      REAL(wp)   , POINTER, DIMENSION(:,:)   ::  nbdout
+      REAL(wp)   , POINTER, DIMENSION(:,:)   ::  flagu
+      REAL(wp)   , POINTER, DIMENSION(:,:)   ::  flagv
    END TYPE OBC_INDEX
 
+   !! Logicals in OBC_DATA structure are true if the chosen algorithm requires this
+   !! field as external data. If true the data can come from external files
+   !! or model initial conditions. If false then no "external" data array
+   !! is required for this field. 
+
    TYPE, PUBLIC ::   OBC_DATA     !: Storage for external data
-      REAL, POINTER, DIMENSION(:)     ::  ssh
-      REAL, POINTER, DIMENSION(:)     ::  u2d
-      REAL, POINTER, DIMENSION(:)     ::  v2d
-      REAL, POINTER, DIMENSION(:,:)   ::  u3d
-      REAL, POINTER, DIMENSION(:,:)   ::  v3d
-      REAL, POINTER, DIMENSION(:,:)   ::  tem
-      REAL, POINTER, DIMENSION(:,:)   ::  sal
+      INTEGER,       DIMENSION(2)     ::  nread
+      LOGICAL                         ::  ll_ssh
+      LOGICAL                         ::  ll_u2d
+      LOGICAL                         ::  ll_v2d
+      LOGICAL                         ::  ll_u3d
+      LOGICAL                         ::  ll_v3d
+      LOGICAL                         ::  ll_tem
+      LOGICAL                         ::  ll_sal
+      REAL(wp), POINTER, DIMENSION(:)     ::  ssh
+      REAL(wp), POINTER, DIMENSION(:)     ::  u2d
+      REAL(wp), POINTER, DIMENSION(:)     ::  v2d
+      REAL(wp), POINTER, DIMENSION(:,:)   ::  u3d
+      REAL(wp), POINTER, DIMENSION(:,:)   ::  v3d
+      REAL(wp), POINTER, DIMENSION(:,:)   ::  tem
+      REAL(wp), POINTER, DIMENSION(:,:)   ::  sal
 #if defined key_lim2
-      REAL, POINTER, DIMENSION(:)     ::  frld
-      REAL, POINTER, DIMENSION(:)     ::  hicif
-      REAL, POINTER, DIMENSION(:)     ::  hsnif
+      LOGICAL                         ::  ll_frld
+      LOGICAL                         ::  ll_hicif
+      LOGICAL                         ::  ll_hsnif
+      REAL(wp), POINTER, DIMENSION(:)     ::  frld
+      REAL(wp), POINTER, DIMENSION(:)     ::  hicif
+      REAL(wp), POINTER, DIMENSION(:)     ::  hsnif
+#elif defined key_lim3
+      LOGICAL                         ::  ll_a_i
+      LOGICAL                         ::  ll_ht_i
+      LOGICAL                         ::  ll_ht_s
+      REAL, POINTER, DIMENSION(:,:)   ::  a_i   !: now ice leads fraction climatology
+      REAL, POINTER, DIMENSION(:,:)   ::  ht_i  !: Now ice  thickness climatology
+      REAL, POINTER, DIMENSION(:,:)   ::  ht_s  !: now snow thickness
 #endif
    END TYPE OBC_DATA
@@ -63,23 +88,24 @@
    INTEGER                    ::   nn_volctl                !: = 0 the total volume will have the variability of the surface Flux E-P 
    !                                                        !  = 1 the volume will be constant during all the integration.
-   INTEGER, DIMENSION(jp_bdy) ::   nn_dyn2d                 ! Choice of boundary condition for barotropic variables (U,V,SSH)
-   INTEGER, DIMENSION(jp_bdy) ::   nn_dyn2d_dta      	    !: = 0 use the initial state as bdy dta ; 
+   CHARACTER(len=20), DIMENSION(jp_bdy) ::   cn_dyn2d       ! Choice of boundary condition for barotropic variables (U,V,SSH)
+   INTEGER, DIMENSION(jp_bdy)           ::   nn_dyn2d_dta   !: = 0 use the initial state as bdy dta ; 
                                                             !: = 1 read it in a NetCDF file
                                                             !: = 2 read tidal harmonic forcing from a NetCDF file
                                                             !: = 3 read external data AND tidal harmonic forcing from NetCDF files
-   INTEGER, DIMENSION(jp_bdy) ::   nn_dyn3d                 ! Choice of boundary condition for baroclinic velocities 
-   INTEGER, DIMENSION(jp_bdy) ::   nn_dyn3d_dta      	    !: = 0 use the initial state as bdy dta ; 
+   CHARACTER(len=20), DIMENSION(jp_bdy) ::   cn_dyn3d       ! Choice of boundary condition for baroclinic velocities 
+   INTEGER, DIMENSION(jp_bdy)           ::   nn_dyn3d_dta   !: = 0 use the initial state as bdy dta ; 
                                                             !: = 1 read it in a NetCDF file
-   INTEGER, DIMENSION(jp_bdy) ::   nn_tra                   ! Choice of boundary condition for active tracers (T and S)
-   INTEGER, DIMENSION(jp_bdy) ::   nn_tra_dta      	    !: = 0 use the initial state as bdy dta ; 
+   CHARACTER(len=20), DIMENSION(jp_bdy) ::   cn_tra         ! Choice of boundary condition for active tracers (T and S)
+   INTEGER, DIMENSION(jp_bdy)           ::   nn_tra_dta     !: = 0 use the initial state as bdy dta ; 
                                                             !: = 1 read it in a NetCDF file
    LOGICAL, DIMENSION(jp_bdy) ::   ln_tra_dmp               !: =T Tracer damping
    LOGICAL, DIMENSION(jp_bdy) ::   ln_dyn3d_dmp             !: =T Baroclinic velocity damping
-   REAL,    DIMENSION(jp_bdy) ::   rn_time_dmp              !: Damping time scale in days
+   REAL(wp),    DIMENSION(jp_bdy) ::   rn_time_dmp              !: Damping time scale in days
+   REAL(wp),    DIMENSION(jp_bdy) ::   rn_time_dmp_out          !: Damping time scale in days at radiation outflow points
 
 #if defined key_lim2
-   INTEGER, DIMENSION(jp_bdy) ::   nn_ice_lim2              ! Choice of boundary condition for sea ice variables 
-   INTEGER, DIMENSION(jp_bdy) ::   nn_ice_lim2_dta          !: = 0 use the initial state as bdy dta ; 
-                                                            !: = 1 read it in a NetCDF file
+   CHARACTER(len=20), DIMENSION(jp_bdy) ::   nn_ice_lim2      ! Choice of boundary condition for sea ice variables 
+   INTEGER, DIMENSION(jp_bdy)           ::   nn_ice_lim2_dta  !: = 0 use the initial state as bdy dta ; 
+                                                              !: = 1 read it in a NetCDF file
 #endif
    !
@@ -88,15 +114,15 @@
    !! Global variables
    !!----------------------------------------------------------------------
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bdytmask   !: Mask defining computational domain at T-points
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bdyumask   !: Mask defining computational domain at U-points
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bdyvmask   !: Mask defining computational domain at V-points
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:), TARGET ::   bdytmask   !: Mask defining computational domain at T-points
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:), TARGET ::   bdyumask   !: Mask defining computational domain at U-points
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:), TARGET ::   bdyvmask   !: Mask defining computational domain at V-points
 
    REAL(wp)                                    ::   bdysurftot !: Lateral surface of unstructured open boundary
 
-   REAL(wp), POINTER, DIMENSION(:,:)           ::   pssh       !: 
-   REAL(wp), POINTER, DIMENSION(:,:)           ::   phur       !: 
-   REAL(wp), POINTER, DIMENSION(:,:)           ::   phvr       !: Pointers for barotropic fields 
-   REAL(wp), POINTER, DIMENSION(:,:)           ::   pu2d       !: 
-   REAL(wp), POINTER, DIMENSION(:,:)           ::   pv2d       !: 
+   REAL(wp), POINTER, DIMENSION(:,:)           ::   pssh                  !: 
+   REAL(wp), POINTER, DIMENSION(:,:)           ::   phur                  !: 
+   REAL(wp), POINTER, DIMENSION(:,:)           ::   phvr                  !: Pointers for barotropic fields 
+   REAL(wp), POINTER, DIMENSION(:,:)           ::   pub2d, pun2d, pua2d   !: 
+   REAL(wp), POINTER, DIMENSION(:,:)           ::   pvb2d, pvn2d, pva2d   !: 
 
    !!----------------------------------------------------------------------
@@ -109,5 +135,5 @@
    REAL(wp), ALLOCATABLE, DIMENSION(:,:,:), TARGET ::   dta_global2       !: workspace for reading in global data arrays (struct. bdy)
    TYPE(OBC_INDEX), DIMENSION(jp_bdy), TARGET      ::   idx_bdy           !: bdy indices (local process)
-   TYPE(OBC_DATA) , DIMENSION(jp_bdy)              ::   dta_bdy           !: bdy external data (local process)
+   TYPE(OBC_DATA) , DIMENSION(jp_bdy), TARGET      ::   dta_bdy           !: bdy external data (local process)
 
    !!----------------------------------------------------------------------
@@ -125,5 +151,5 @@
       !!----------------------------------------------------------------------
       !
-      ALLOCATE( bdytmask(jpi,jpj) , bdyumask(jpi,jpj), bdyvmask(jpi,jpj),                    &  
+      ALLOCATE( bdytmask(jpi,jpj) , bdyumask(jpi,jpj), bdyvmask(jpi,jpj),     &  
          &      STAT=bdy_oce_alloc )
          !
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_par.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_par.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_par.F90	(revision 4292)
@@ -23,11 +23,6 @@
 # endif
    INTEGER, PUBLIC, PARAMETER ::   jp_bdy  = 10       !: Maximum number of bdy sets
-   INTEGER, PUBLIC, PARAMETER ::   jpbtime = 1000     !: Max number of time dumps per file
    INTEGER, PUBLIC, PARAMETER ::   jpbgrd  = 3	      !: Number of horizontal grid types used  (T, U, V)
 
-   !! Flags for choice of schemes
-   INTEGER, PUBLIC, PARAMETER ::   jp_none         = 0        !: Flag for no open boundary condition
-   INTEGER, PUBLIC, PARAMETER ::   jp_frs          = 1        !: Flag for Flow Relaxation Scheme
-   INTEGER, PUBLIC, PARAMETER ::   jp_flather      = 2        !: Flag for Flather
 #else
    !!----------------------------------------------------------------------
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 4292)
@@ -11,4 +11,5 @@
    !!            3.3  !  2010-09  (D.Storkey) add ice boundary conditions
    !!            3.4  !  2011     (D. Storkey) rewrite in preparation for OBC-BDY merge
+   !!            3.6  !  2012-01  (C. Rousset) add ice boundary conditions for lim3
    !!----------------------------------------------------------------------
 #if defined key_bdy
@@ -29,6 +30,11 @@
    USE iom             ! IOM library
    USE in_out_manager  ! I/O logical units
+   USE dynspg_oce, ONLY: lk_dynspg_ts ! Split-explicit free surface flag
 #if defined key_lim2
    USE ice_2
+#elif defined key_lim3
+   USE par_ice
+   USE ice
+   USE limcat_1D          ! redistribute ice input into categories
 #endif
    USE sbcapr
@@ -49,4 +55,9 @@
 
    TYPE(MAP_POINTER), ALLOCATABLE, DIMENSION(:) :: nbmap_ptr   ! array of pointers to nbmap
+
+#if defined key_lim3
+   LOGICAL :: ll_bdylim3                  ! determine whether ice input is lim2 (F) or lim3 (T) type
+   INTEGER :: jfld_hti, jfld_hts, jfld_ai ! indices of ice thickness, snow thickness and concentration in bf structure
+#endif
 
 #  include "domzgr_substitute.h90"
@@ -77,7 +88,8 @@
                                                         ! etc.
       !!
-      INTEGER     ::  ib_bdy, jfld, jstart, jend, ib, ii, ij, ik, igrd  ! local indices
+      INTEGER     ::  ib_bdy, jfld, jstart, jend, ib, ii, ij, ik, igrd, jl  ! local indices
       INTEGER,          DIMENSION(jpbgrd) ::   ilen1 
       INTEGER, POINTER, DIMENSION(:)      ::   nblen, nblenrim  ! short cuts
+      TYPE(OBC_DATA), POINTER             ::   dta              ! short cut
       !!
       !!---------------------------------------------------------------------------
@@ -91,15 +103,14 @@
          ! Calculate depth-mean currents
          !-----------------------------
-         CALL wrk_alloc(jpi,jpj,pu2d,pv2d) 
-
-         pu2d(:,:) = 0.e0
-         pv2d(:,:) = 0.e0
-
+         CALL wrk_alloc(jpi,jpj,pun2d,pvn2d) 
+
+         pun2d(:,:) = 0.e0
+         pvn2d(:,:) = 0.e0
          DO ik = 1, jpkm1   !! Vertically integrated momentum trends
-             pu2d(:,:) = pu2d(:,:) + fse3u(:,:,ik) * umask(:,:,ik) * un(:,:,ik)
-             pv2d(:,:) = pv2d(:,:) + fse3v(:,:,ik) * vmask(:,:,ik) * vn(:,:,ik)
+             pun2d(:,:) = pun2d(:,:) + fse3u(:,:,ik) * umask(:,:,ik) * un(:,:,ik)
+             pvn2d(:,:) = pvn2d(:,:) + fse3v(:,:,ik) * vmask(:,:,ik) * vn(:,:,ik)
          END DO
-         pu2d(:,:) = pu2d(:,:) * hur(:,:)
-         pv2d(:,:) = pv2d(:,:) * hvr(:,:)
+         pun2d(:,:) = pun2d(:,:) * hur(:,:)
+         pvn2d(:,:) = pvn2d(:,:) * hvr(:,:)
          
          DO ib_bdy = 1, nb_bdy
@@ -107,71 +118,143 @@
             nblen => idx_bdy(ib_bdy)%nblen
             nblenrim => idx_bdy(ib_bdy)%nblenrim
-
-            IF( nn_dyn2d(ib_bdy) .gt. 0 .and. nn_dyn2d_dta(ib_bdy) .eq. 0 ) THEN 
+            dta => dta_bdy(ib_bdy)
+
+            IF( nn_dyn2d_dta(ib_bdy) .eq. 0 ) THEN 
                ilen1(:) = nblen(:)
-               igrd = 1
-               DO ib = 1, ilen1(igrd)
-                  ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                  ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                  dta_bdy(ib_bdy)%ssh(ib) = sshn(ii,ij) * tmask(ii,ij,1)         
-               END DO 
-               igrd = 2
-               DO ib = 1, ilen1(igrd)
-                  ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                  ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                  dta_bdy(ib_bdy)%u2d(ib) = pu2d(ii,ij) * umask(ii,ij,1)         
-               END DO 
-               igrd = 3
-               DO ib = 1, ilen1(igrd)
-                  ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                  ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                  dta_bdy(ib_bdy)%v2d(ib) = pv2d(ii,ij) * vmask(ii,ij,1)         
-               END DO 
-            ENDIF
-
-            IF( nn_dyn3d(ib_bdy) .gt. 0 .and. nn_dyn3d_dta(ib_bdy) .eq. 0 ) THEN 
-               ilen1(:) = nblen(:)
-               igrd = 2 
-               DO ib = 1, ilen1(igrd)
-                  DO ik = 1, jpkm1
+               IF( dta%ll_ssh ) THEN 
+                  igrd = 1
+                  DO ib = 1, ilen1(igrd)
                      ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
                      ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                     dta_bdy(ib_bdy)%u3d(ib,ik) =  ( un(ii,ij,ik) - pu2d(ii,ij) ) * umask(ii,ij,ik)         
-                  END DO
-               END DO 
-               igrd = 3 
-               DO ib = 1, ilen1(igrd)
-                  DO ik = 1, jpkm1
+                     dta_bdy(ib_bdy)%ssh(ib) = sshn(ii,ij) * tmask(ii,ij,1)         
+                  END DO 
+               END IF
+               IF( dta%ll_u2d ) THEN 
+                  igrd = 2
+                  DO ib = 1, ilen1(igrd)
                      ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
                      ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                     dta_bdy(ib_bdy)%v3d(ib,ik) =  ( vn(ii,ij,ik) - pv2d(ii,ij) ) * vmask(ii,ij,ik)         
-                     END DO
-               END DO 
-            ENDIF
-
-            IF( nn_tra(ib_bdy) .gt. 0 .and. nn_tra_dta(ib_bdy) .eq. 0 ) THEN 
-               ilen1(:) = nblen(:)
-               igrd = 1                       ! Everything is at T-points here
-               DO ib = 1, ilen1(igrd)
-                  DO ik = 1, jpkm1
+                     dta_bdy(ib_bdy)%u2d(ib) = pun2d(ii,ij) * umask(ii,ij,1)         
+                  END DO 
+               END IF
+               IF( dta%ll_v2d ) THEN 
+                  igrd = 3
+                  DO ib = 1, ilen1(igrd)
                      ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
                      ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                     dta_bdy(ib_bdy)%tem(ib,ik) = tsn(ii,ij,ik,jp_tem) * tmask(ii,ij,ik)         
-                     dta_bdy(ib_bdy)%sal(ib,ik) = tsn(ii,ij,ik,jp_sal) * tmask(ii,ij,ik)         
+                     dta_bdy(ib_bdy)%v2d(ib) = pvn2d(ii,ij) * vmask(ii,ij,1)         
+                  END DO 
+               END IF
+            ENDIF
+
+            IF( nn_dyn3d_dta(ib_bdy) .eq. 0 ) THEN 
+               ilen1(:) = nblen(:)
+               IF( dta%ll_u3d ) THEN 
+                  igrd = 2 
+                  DO ib = 1, ilen1(igrd)
+                     DO ik = 1, jpkm1
+                        ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                        ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                        dta_bdy(ib_bdy)%u3d(ib,ik) =  ( un(ii,ij,ik) - pun2d(ii,ij) ) * umask(ii,ij,ik)         
+                     END DO
+                  END DO 
+               END IF
+               IF( dta%ll_v3d ) THEN 
+                  igrd = 3 
+                  DO ib = 1, ilen1(igrd)
+                     DO ik = 1, jpkm1
+                        ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                        ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                        dta_bdy(ib_bdy)%v3d(ib,ik) =  ( vn(ii,ij,ik) - pvn2d(ii,ij) ) * vmask(ii,ij,ik)         
+                        END DO
+                  END DO 
+               END IF
+            ENDIF
+
+            IF( nn_tra_dta(ib_bdy) .eq. 0 ) THEN 
+               ilen1(:) = nblen(:)
+               IF( dta%ll_tem ) THEN
+                  igrd = 1 
+                  DO ib = 1, ilen1(igrd)
+                     DO ik = 1, jpkm1
+                        ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                        ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                        dta_bdy(ib_bdy)%tem(ib,ik) = tsn(ii,ij,ik,jp_tem) * tmask(ii,ij,ik)         
+                     END DO
+                  END DO 
+               END IF
+               IF( dta%ll_sal ) THEN
+                  igrd = 1 
+                  DO ib = 1, ilen1(igrd)
+                     DO ik = 1, jpkm1
+                        ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                        ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                        dta_bdy(ib_bdy)%sal(ib,ik) = tsn(ii,ij,ik,jp_sal) * tmask(ii,ij,ik)         
+                     END DO
+                  END DO 
+               END IF
+            ENDIF
+
+#if defined key_lim2
+            IF( nn_ice_lim2_dta(ib_bdy) .eq. 0 ) THEN 
+               ilen1(:) = nblen(:)
+               IF( dta%ll_frld ) THEN
+                  igrd = 1 
+                  DO ib = 1, ilen1(igrd)
+                     ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                     ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                     dta_bdy(ib_bdy)%frld(ib) = frld(ii,ij) * tmask(ii,ij,1)         
+                  END DO 
+               END IF
+               IF( dta%ll_hicif ) THEN
+                  igrd = 1 
+                  DO ib = 1, ilen1(igrd)
+                     ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                     ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                     dta_bdy(ib_bdy)%hicif(ib) = hicif(ii,ij) * tmask(ii,ij,1)         
+                  END DO 
+               END IF
+               IF( dta%ll_hsnif ) THEN
+                  igrd = 1 
+                  DO ib = 1, ilen1(igrd)
+                     ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                     ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                     dta_bdy(ib_bdy)%hsnif(ib) = hsnif(ii,ij) * tmask(ii,ij,1)         
+                  END DO 
+               END IF
+            ENDIF
+#elif defined key_lim3
+            IF( nn_ice_lim_dta(ib_bdy) .eq. 0 ) THEN 
+               ilen1(:) = nblen(:)
+               IF( dta%ll_a_i ) THEN
+                  igrd = 1   
+                  DO jl = 1, jpl
+                     DO ib = 1, ilen1(igrd)
+                        ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                        ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                        dta_bdy(ib_bdy)%a_i (ib,jl) =  a_i(ii,ij,jl) * tmask(ii,ij,1) 
+                     END DO
                   END DO
-               END DO 
-            ENDIF
-
-#if defined key_lim2
-            IF( nn_ice_lim2(ib_bdy) .gt. 0 .and. nn_ice_lim2_dta(ib_bdy) .eq. 0 ) THEN 
-               ilen1(:) = nblen(:)
-               igrd = 1                       ! Everything is at T-points here
-               DO ib = 1, ilen1(igrd)
-                  ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                  ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                  dta_bdy(ib_bdy)%frld(ib) = frld(ii,ij) * tmask(ii,ij,1)         
-                  dta_bdy(ib_bdy)%hicif(ib) = hicif(ii,ij) * tmask(ii,ij,1)         
-                  dta_bdy(ib_bdy)%hsnif(ib) = hsnif(ii,ij) * tmask(ii,ij,1)         
-               END DO 
+               ENDIF
+               IF( dta%ll_ht_i ) THEN
+                  igrd = 1   
+                  DO jl = 1, jpl
+                     DO ib = 1, ilen1(igrd)
+                        ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                        ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                        dta_bdy(ib_bdy)%ht_i (ib,jl) =  ht_i(ii,ij,jl) * tmask(ii,ij,1) 
+                     END DO
+                  END DO
+               ENDIF
+               IF( dta%ll_ht_s ) THEN
+                  igrd = 1   
+                  DO jl = 1, jpl
+                     DO ib = 1, ilen1(igrd)
+                        ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                        ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                        dta_bdy(ib_bdy)%ht_s (ib,jl) =  ht_s(ii,ij,jl) * tmask(ii,ij,1) 
+                     END DO
+                  END DO
+               ENDIF
             ENDIF
 #endif
@@ -179,5 +262,5 @@
          ENDDO ! ib_bdy
 
-         CALL wrk_dealloc(jpi,jpj,pu2d,pv2d) 
+         CALL wrk_dealloc(jpi,jpj,pun2d,pvn2d) 
 
       ENDIF ! kt .eq. nit000
@@ -188,4 +271,5 @@
       jstart = 1
       DO ib_bdy = 1, nb_bdy   
+         dta => dta_bdy(ib_bdy)
          IF( nn_dta(ib_bdy) .eq. 1 ) THEN ! skip this bit if no external data required
       
@@ -193,22 +277,18 @@
                ! Update barotropic boundary conditions only
                ! jit is optional argument for fld_read and bdytide_update
-               IF( nn_dyn2d(ib_bdy) .gt. 0 ) THEN
+               IF( cn_dyn2d(ib_bdy) /= 'none' ) THEN
                   IF( nn_dyn2d_dta(ib_bdy) .eq. 2 ) THEN ! tidal harmonic forcing ONLY: initialise arrays
-                     dta_bdy(ib_bdy)%ssh(:) = 0.0
-                     dta_bdy(ib_bdy)%u2d(:) = 0.0
-                     dta_bdy(ib_bdy)%v2d(:) = 0.0
+                     IF( dta%ll_ssh ) dta%ssh(:) = 0.0
+                     IF( dta%ll_u2d ) dta%u2d(:) = 0.0
+                     IF( dta%ll_u3d ) dta%v2d(:) = 0.0
                   ENDIF
-                  IF (nn_tra(ib_bdy).ne.4) THEN
-                     IF( nn_dyn2d_dta(ib_bdy) .EQ. 1 .OR. nn_dyn2d_dta(ib_bdy) .EQ. 3 .OR.  &
-                       & (ln_full_vel_array(ib_bdy) .AND. nn_dyn3d_dta(ib_bdy).eq.1) )THEN
-
-                        ! For the runoff case, no need to update the forcing (already done in the baroclinic part)
-                        jend = nb_bdy_fld(ib_bdy)
-                        IF ( nn_tra(ib_bdy) .GT. 0 .AND. nn_tra_dta(ib_bdy) .GE. 1 ) jend = jend - 2
+                  IF (cn_tra(ib_bdy) /= 'runoff') THEN
+                     IF( nn_dyn2d_dta(ib_bdy) .EQ. 1 .OR. nn_dyn2d_dta(ib_bdy) .EQ. 3 ) THEN
+
+                        jend = jstart + dta%nread(2) - 1
                         CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend), map=nbmap_ptr(jstart:jend),  &
                                      & kit=jit, kt_offset=time_offset )
-                        IF ( nn_tra(ib_bdy) .GT. 0 .AND. nn_tra_dta(ib_bdy) .GE. 1 ) jend = jend + 2
-
-                        ! If full velocities in boundary data then split into barotropic and baroclinic data
+
+                        ! If full velocities in boundary data then extract barotropic velocities from 3D fields
                         IF( ln_full_vel_array(ib_bdy) .AND.                                             &
                           &    ( nn_dyn2d_dta(ib_bdy) .EQ. 1 .OR. nn_dyn2d_dta(ib_bdy) .EQ. 3 .OR.  &
@@ -216,35 +296,29 @@
 
                            igrd = 2                      ! zonal velocity
-                           dta_bdy(ib_bdy)%u2d(:) = 0.0
+                           dta%u2d(:) = 0.0
                            DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
                               ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
                               ij   = idx_bdy(ib_bdy)%nbj(ib,igrd)
                               DO ik = 1, jpkm1
-                                 dta_bdy(ib_bdy)%u2d(ib) = dta_bdy(ib_bdy)%u2d(ib) &
-                       &                          + fse3u(ii,ij,ik) * umask(ii,ij,ik) * dta_bdy(ib_bdy)%u3d(ib,ik)
+                                 dta%u2d(ib) = dta%u2d(ib) &
+                       &                          + fse3u(ii,ij,ik) * umask(ii,ij,ik) * dta%u3d(ib,ik)
                               END DO
-                              dta_bdy(ib_bdy)%u2d(ib) =  dta_bdy(ib_bdy)%u2d(ib) * hur(ii,ij)
-                              DO ik = 1, jpkm1
-                                 dta_bdy(ib_bdy)%u3d(ib,ik) = dta_bdy(ib_bdy)%u3d(ib,ik) - dta_bdy(ib_bdy)%u2d(ib)
-                              END DO
+                              dta%u2d(ib) =  dta%u2d(ib) * hur(ii,ij)
                            END DO
                            igrd = 3                      ! meridional velocity
-                           dta_bdy(ib_bdy)%v2d(:) = 0.0
+                           dta%v2d(:) = 0.0
                            DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
                               ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
                               ij   = idx_bdy(ib_bdy)%nbj(ib,igrd)
                               DO ik = 1, jpkm1
-                                 dta_bdy(ib_bdy)%v2d(ib) = dta_bdy(ib_bdy)%v2d(ib) &
-                       &                       + fse3v(ii,ij,ik) * vmask(ii,ij,ik) * dta_bdy(ib_bdy)%v3d(ib,ik)
+                                 dta%v2d(ib) = dta%v2d(ib) &
+                       &                       + fse3v(ii,ij,ik) * vmask(ii,ij,ik) * dta%v3d(ib,ik)
                               END DO
-                              dta_bdy(ib_bdy)%v2d(ib) =  dta_bdy(ib_bdy)%v2d(ib) * hvr(ii,ij)
-                              DO ik = 1, jpkm1
-                                 dta_bdy(ib_bdy)%v3d(ib,ik) = dta_bdy(ib_bdy)%v3d(ib,ik) - dta_bdy(ib_bdy)%v2d(ib)
-                              END DO
+                              dta%v2d(ib) =  dta%v2d(ib) * hvr(ii,ij)
                            END DO
                         ENDIF                    
                      ENDIF
                      IF( nn_dyn2d_dta(ib_bdy) .ge. 2 ) THEN ! update tidal harmonic forcing
-                        CALL bdytide_update( kt=kt, idx=idx_bdy(ib_bdy), dta=dta_bdy(ib_bdy), td=tides(ib_bdy),   & 
+                        CALL bdytide_update( kt=kt, idx=idx_bdy(ib_bdy), dta=dta, td=tides(ib_bdy),   & 
                           &                 jit=jit, time_offset=time_offset )
                      ENDIF
@@ -252,5 +326,5 @@
                ENDIF
             ELSE
-               IF (nn_tra(ib_bdy).eq.4) then      ! runoff condition
+               IF (cn_tra(ib_bdy) == 'runoff') then      ! runoff condition
                   jend = nb_bdy_fld(ib_bdy)
                   CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend),  &
@@ -261,5 +335,5 @@
                      ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
                      ij   = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                     dta_bdy(ib_bdy)%u2d(ib) = dta_bdy(ib_bdy)%u2d(ib) / ( e2u(ii,ij) * hu_0(ii,ij) )
+                     dta%u2d(ib) = dta%u2d(ib) / ( e2u(ii,ij) * hu_0(ii,ij) )
                   END DO
                   !
@@ -268,14 +342,14 @@
                      ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
                      ij   = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                     dta_bdy(ib_bdy)%v2d(ib) = dta_bdy(ib_bdy)%v2d(ib) / ( e1v(ii,ij) * hv_0(ii,ij) )
+                     dta%v2d(ib) = dta%v2d(ib) / ( e1v(ii,ij) * hv_0(ii,ij) )
                   END DO
                ELSE
-                  IF( nn_dyn2d(ib_bdy) .gt. 0 .and. nn_dyn2d_dta(ib_bdy) .eq. 2 ) THEN ! tidal harmonic forcing ONLY: initialise arrays
-                     dta_bdy(ib_bdy)%ssh(:) = 0.0
-                     dta_bdy(ib_bdy)%u2d(:) = 0.0
-                     dta_bdy(ib_bdy)%v2d(:) = 0.0
+                  IF( nn_dyn2d_dta(ib_bdy) .eq. 2 ) THEN ! tidal harmonic forcing ONLY: initialise arrays
+                     IF( dta%ll_ssh ) dta%ssh(:) = 0.0
+                     IF( dta%ll_u2d ) dta%u2d(:) = 0.0
+                     IF( dta%ll_v2d ) dta%v2d(:) = 0.0
                   ENDIF
-                  IF( nb_bdy_fld(ib_bdy) .gt. 0 ) THEN ! update external data
-                     jend = nb_bdy_fld(ib_bdy)
+                  IF( dta%nread(1) .gt. 0 ) THEN ! update external data
+                     jend = jstart + dta%nread(1) - 1
                      CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend), &
                                   & map=nbmap_ptr(jstart:jend), kt_offset=time_offset )
@@ -286,45 +360,55 @@
                     &   nn_dyn3d_dta(ib_bdy) .EQ. 1 ) ) THEN
                      igrd = 2                      ! zonal velocity
-                     dta_bdy(ib_bdy)%u2d(:) = 0.0
+                     dta%u2d(:) = 0.0
                      DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
                         ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
                         ij   = idx_bdy(ib_bdy)%nbj(ib,igrd)
                         DO ik = 1, jpkm1
-                           dta_bdy(ib_bdy)%u2d(ib) = dta_bdy(ib_bdy)%u2d(ib) &
-                 &                       + fse3u(ii,ij,ik) * umask(ii,ij,ik) * dta_bdy(ib_bdy)%u3d(ib,ik)
+                           dta%u2d(ib) = dta%u2d(ib) &
+                 &                       + fse3u(ii,ij,ik) * umask(ii,ij,ik) * dta%u3d(ib,ik)
                         END DO
-                        dta_bdy(ib_bdy)%u2d(ib) =  dta_bdy(ib_bdy)%u2d(ib) * hur(ii,ij)
+                        dta%u2d(ib) =  dta%u2d(ib) * hur(ii,ij)
                         DO ik = 1, jpkm1
-                           dta_bdy(ib_bdy)%u3d(ib,ik) = dta_bdy(ib_bdy)%u3d(ib,ik) - dta_bdy(ib_bdy)%u2d(ib)
+                           dta%u3d(ib,ik) = dta%u3d(ib,ik) - dta%u2d(ib)
                         END DO
                      END DO
                      igrd = 3                      ! meridional velocity
-                     dta_bdy(ib_bdy)%v2d(:) = 0.0
+                     dta%v2d(:) = 0.0
                      DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
                         ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
                         ij   = idx_bdy(ib_bdy)%nbj(ib,igrd)
                         DO ik = 1, jpkm1
-                           dta_bdy(ib_bdy)%v2d(ib) = dta_bdy(ib_bdy)%v2d(ib) &
-                 &                       + fse3v(ii,ij,ik) * vmask(ii,ij,ik) * dta_bdy(ib_bdy)%v3d(ib,ik)
+                           dta%v2d(ib) = dta%v2d(ib) &
+                 &                       + fse3v(ii,ij,ik) * vmask(ii,ij,ik) * dta%v3d(ib,ik)
                         END DO
-                        dta_bdy(ib_bdy)%v2d(ib) =  dta_bdy(ib_bdy)%v2d(ib) * hvr(ii,ij)
+                        dta%v2d(ib) =  dta%v2d(ib) * hvr(ii,ij)
                         DO ik = 1, jpkm1
-                           dta_bdy(ib_bdy)%v3d(ib,ik) = dta_bdy(ib_bdy)%v3d(ib,ik) - dta_bdy(ib_bdy)%v2d(ib)
+                           dta%v3d(ib,ik) = dta%v3d(ib,ik) - dta%v2d(ib)
                         END DO
                      END DO
                   ENDIF
-                  IF( nn_dyn2d(ib_bdy) .gt. 0 .and. nn_dyn2d_dta(ib_bdy) .ge. 2 ) THEN ! update tidal harmonic forcing
-                     CALL bdytide_update( kt=kt, idx=idx_bdy(ib_bdy), dta=dta_bdy(ib_bdy),  &
-                                        & td=tides(ib_bdy), time_offset=time_offset )
-                  ENDIF
-               ENDIF
-            ENDIF
-            jstart = jend+1
+
+               ENDIF
+#if defined key_lim3
+               IF( .NOT. ll_bdylim3 .AND. nn_ice_lim(ib_bdy) > 0 .AND. nn_ice_lim_dta(ib_bdy) == 1 ) THEN ! bdy ice input (case input is lim2 type)
+     	          CALL lim_cat_1D ( bf(jfld_hti)%fnow(:,1,1), bf(jfld_hts)%fnow(:,1,1), bf(jfld_ai)%fnow(:,1,1), &
+                                  & dta_bdy(ib_bdy)%ht_i,     dta_bdy(ib_bdy)%ht_s,     dta_bdy(ib_bdy)%a_i     )
+               ENDIF
+#endif
+            ENDIF
+            jstart = jstart + dta%nread(1)
          END IF ! nn_dta(ib_bdy) = 1
       END DO  ! ib_bdy
 
+      ! bg jchanut tschanges
+#if defined key_tide
+      ! Add tides if not split-explicit free surface else this is done in ts loop
+      IF (.NOT.lk_dynspg_ts) CALL bdy_dta_tides( kt=kt, time_offset=time_offset )
+#endif
+      ! end jchanut tschanges
+
       IF ( ln_apr_obc ) THEN
          DO ib_bdy = 1, nb_bdy
-            IF (nn_tra(ib_bdy).NE.4)THEN
+            IF (cn_tra(ib_bdy) /= 'runoff')THEN
                igrd = 1                      ! meridional velocity
                DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
@@ -349,5 +433,5 @@
       !!                for open boundary conditions
       !!
-      !! ** Method  :   Use fldread.F90
+      !! ** Method  :   
       !!                
       !!----------------------------------------------------------------------
@@ -362,9 +446,14 @@
                                                                 ! =F => baroclinic velocities in 3D boundary data
       INTEGER                                ::   ilen_global   ! Max length required for global bdy dta arrays
-      INTEGER,              DIMENSION(jpbgrd) ::  ilen0         ! size of local arrays
       INTEGER, ALLOCATABLE, DIMENSION(:)     ::   ilen1, ilen3  ! size of 1st and 3rd dimensions of local arrays
       INTEGER, ALLOCATABLE, DIMENSION(:)     ::   ibdy           ! bdy set for a particular jfld
       INTEGER, ALLOCATABLE, DIMENSION(:)     ::   igrid         ! index for grid type (1,2,3 = T,U,V)
       INTEGER, POINTER, DIMENSION(:)         ::   nblen, nblenrim  ! short cuts
+      TYPE(OBC_DATA), POINTER                ::   dta           ! short cut
+#if defined key_lim3
+      INTEGER, DIMENSION(3) ::   zdimsz   ! number of elements in each of the 4 dimensions (i.e. i,j,t,ice-cat) for an array
+      INTEGER               ::   zndims   ! number of dimensions in an array (i.e. 3 = wo ice cat; 4 = w ice cat)
+      INTEGER               ::   inum,id1 ! local integer
+#endif
       TYPE(FLD_N), ALLOCATABLE, DIMENSION(:) ::   blf_i         !  array of namelist information structures
       TYPE(FLD_N) ::   bn_tem, bn_sal, bn_u3d, bn_v3d   ! 
@@ -372,8 +461,12 @@
 #if defined key_lim2
       TYPE(FLD_N) ::   bn_frld, bn_hicif, bn_hsnif      !
+#elif defined key_lim3
+      TYPE(FLD_N) ::   bn_a_i, bn_ht_i, bn_ht_s      
 #endif
       NAMELIST/nambdy_dta/ cn_dir, bn_tem, bn_sal, bn_u3d, bn_v3d, bn_ssh, bn_u2d, bn_v2d 
 #if defined key_lim2
       NAMELIST/nambdy_dta/ bn_frld, bn_hicif, bn_hsnif
+#elif defined key_lim3
+      NAMELIST/nambdy_dta/ bn_a_i, bn_ht_i, bn_ht_s
 #endif
       NAMELIST/nambdy_dta/ ln_full_vel
@@ -392,6 +485,6 @@
                                ,nn_dyn3d_dta(ib_bdy)       &
                                ,nn_tra_dta(ib_bdy)         &
-#if defined key_lim2
-                               ,nn_ice_lim2_dta(ib_bdy)    &
+#if ( defined key_lim2 || defined key_lim3 )
+                              ,nn_ice_lim_dta(ib_bdy)    &
 #endif
                               )
@@ -404,15 +497,15 @@
       nb_bdy_fld(:) = 0
       DO ib_bdy = 1, nb_bdy         
-         IF( nn_dyn2d(ib_bdy) .gt. 0 .and. ( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) ) THEN
+         IF( cn_dyn2d(ib_bdy) /= 'none' .and. ( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) ) THEN
             nb_bdy_fld(ib_bdy) = nb_bdy_fld(ib_bdy) + 3
          ENDIF
-         IF( nn_dyn3d(ib_bdy) .gt. 0 .and. nn_dyn3d_dta(ib_bdy) .eq. 1 ) THEN
+         IF( cn_dyn3d(ib_bdy) /= 'none' .and. nn_dyn3d_dta(ib_bdy) .eq. 1 ) THEN
             nb_bdy_fld(ib_bdy) = nb_bdy_fld(ib_bdy) + 2
          ENDIF
-         IF( nn_tra(ib_bdy) .gt. 0 .and. nn_tra_dta(ib_bdy) .eq. 1  ) THEN
+         IF( cn_tra(ib_bdy) /= 'none' .and. nn_tra_dta(ib_bdy) .eq. 1  ) THEN
             nb_bdy_fld(ib_bdy) = nb_bdy_fld(ib_bdy) + 2
          ENDIF
-#if defined key_lim2
-         IF( nn_ice_lim2(ib_bdy) .gt. 0 .and. nn_ice_lim2_dta(ib_bdy) .eq. 1  ) THEN
+#if ( defined key_lim2 || defined key_lim3 )
+         IF( cn_ice_lim(ib_bdy) /= 'none' .and. nn_ice_lim_dta(ib_bdy) .eq. 1  ) THEN
             nb_bdy_fld(ib_bdy) = nb_bdy_fld(ib_bdy) + 3
          ENDIF
@@ -458,10 +551,13 @@
             nblen => idx_bdy(ib_bdy)%nblen
             nblenrim => idx_bdy(ib_bdy)%nblenrim
+            dta => dta_bdy(ib_bdy)
+            dta%nread(2) = 0
 
             ! Only read in necessary fields for this set.
             ! Important that barotropic variables come first.
-            IF( nn_dyn2d(ib_bdy) .gt. 0 .and. ( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) ) THEN 
-
-               IF( nn_dyn2d(ib_bdy) .ne. jp_frs .and. nn_tra(ib_bdy) .ne. 4 ) THEN ! runoff condition : no ssh reading
+            IF( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) THEN 
+
+               IF( dta%ll_ssh ) THEN 
+                  if(lwp) write(numout,*) '++++++ reading in ssh field'
                   jfld = jfld + 1
                   blf_i(jfld) = bn_ssh
@@ -470,7 +566,9 @@
                   ilen1(jfld) = nblen(igrid(jfld))
                   ilen3(jfld) = 1
-               ENDIF
-
-               IF( .not. ln_full_vel_array(ib_bdy) ) THEN
+                  dta%nread(2) = dta%nread(2) + 1
+               ENDIF
+
+               IF( dta%ll_u2d .and. .not. ln_full_vel_array(ib_bdy) ) THEN
+                  if(lwp) write(numout,*) '++++++ reading in u2d field'
                   jfld = jfld + 1
                   blf_i(jfld) = bn_u2d
@@ -479,5 +577,9 @@
                   ilen1(jfld) = nblen(igrid(jfld))
                   ilen3(jfld) = 1
-
+                  dta%nread(2) = dta%nread(2) + 1
+               ENDIF
+
+               IF( dta%ll_v2d .and. .not. ln_full_vel_array(ib_bdy) ) THEN
+                  if(lwp) write(numout,*) '++++++ reading in v2d field'
                   jfld = jfld + 1
                   blf_i(jfld) = bn_v2d
@@ -486,45 +588,60 @@
                   ilen1(jfld) = nblen(igrid(jfld))
                   ilen3(jfld) = 1
-               ENDIF
-
-            ENDIF
-
-            ! baroclinic velocities
-            IF( ( nn_dyn3d(ib_bdy) .gt. 0 .and. nn_dyn3d_dta(ib_bdy) .eq. 1 ) .or. &
-           &      ( ln_full_vel_array(ib_bdy) .and. nn_dyn2d(ib_bdy) .gt. 0 .and.  &
-           &        ( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) ) ) THEN
-
-               jfld = jfld + 1
-               blf_i(jfld) = bn_u3d
-               ibdy(jfld) = ib_bdy
-               igrid(jfld) = 2
-               ilen1(jfld) = nblen(igrid(jfld))
-               ilen3(jfld) = jpk
-
-               jfld = jfld + 1
-               blf_i(jfld) = bn_v3d
-               ibdy(jfld) = ib_bdy
-               igrid(jfld) = 3
-               ilen1(jfld) = nblen(igrid(jfld))
-               ilen3(jfld) = jpk
+                  dta%nread(2) = dta%nread(2) + 1
+               ENDIF
+
+            ENDIF
+
+            ! read 3D velocities if baroclinic velocities require OR if
+            ! barotropic velocities required and ln_full_vel set to .true.
+            IF( nn_dyn3d_dta(ib_bdy) .eq. 1 .or. &
+           &  ( ln_full_vel_array(ib_bdy) .and. ( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) ) ) THEN
+
+               IF( dta%ll_u3d .or. ( ln_full_vel_array(ib_bdy) .and. dta%ll_u2d ) ) THEN
+                  if(lwp) write(numout,*) '++++++ reading in u3d field'
+                  jfld = jfld + 1
+                  blf_i(jfld) = bn_u3d
+                  ibdy(jfld) = ib_bdy
+                  igrid(jfld) = 2
+                  ilen1(jfld) = nblen(igrid(jfld))
+                  ilen3(jfld) = jpk
+                  IF( ln_full_vel_array(ib_bdy) .and. dta%ll_u2d ) dta%nread(2) = dta%nread(2) + 1
+               ENDIF
+
+               IF( dta%ll_v3d .or. ( ln_full_vel_array(ib_bdy) .and. dta%ll_v2d ) ) THEN
+                  if(lwp) write(numout,*) '++++++ reading in v3d field'
+                  jfld = jfld + 1
+                  blf_i(jfld) = bn_v3d
+                  ibdy(jfld) = ib_bdy
+                  igrid(jfld) = 3
+                  ilen1(jfld) = nblen(igrid(jfld))
+                  ilen3(jfld) = jpk
+                  IF( ln_full_vel_array(ib_bdy) .and. dta%ll_v2d ) dta%nread(2) = dta%nread(2) + 1
+               ENDIF
 
             ENDIF
 
             ! temperature and salinity
-            IF( nn_tra(ib_bdy) .gt. 0 .and. nn_tra_dta(ib_bdy) .eq. 1 ) THEN
-
-               jfld = jfld + 1
-               blf_i(jfld) = bn_tem
-               ibdy(jfld) = ib_bdy
-               igrid(jfld) = 1
-               ilen1(jfld) = nblen(igrid(jfld))
-               ilen3(jfld) = jpk
-
-               jfld = jfld + 1
-               blf_i(jfld) = bn_sal
-               ibdy(jfld) = ib_bdy
-               igrid(jfld) = 1
-               ilen1(jfld) = nblen(igrid(jfld))
-               ilen3(jfld) = jpk
+            IF( nn_tra_dta(ib_bdy) .eq. 1 ) THEN
+
+               IF( dta%ll_tem ) THEN
+                  if(lwp) write(numout,*) '++++++ reading in tem field'
+                  jfld = jfld + 1
+                  blf_i(jfld) = bn_tem
+                  ibdy(jfld) = ib_bdy
+                  igrid(jfld) = 1
+                  ilen1(jfld) = nblen(igrid(jfld))
+                  ilen3(jfld) = jpk
+               ENDIF
+
+               IF( dta%ll_sal ) THEN
+                  if(lwp) write(numout,*) '++++++ reading in sal field'
+                  jfld = jfld + 1
+                  blf_i(jfld) = bn_sal
+                  ibdy(jfld) = ib_bdy
+                  igrid(jfld) = 1
+                  ilen1(jfld) = nblen(igrid(jfld))
+                  ilen3(jfld) = jpk
+               ENDIF
 
             ENDIF
@@ -532,28 +649,79 @@
 #if defined key_lim2
             ! sea ice
-            IF( nn_ice_lim2(ib_bdy) .gt. 0 .and. nn_ice_lim2_dta(ib_bdy) .eq. 1 ) THEN
-
-               jfld = jfld + 1
-               blf_i(jfld) = bn_frld
-               ibdy(jfld) = ib_bdy
-               igrid(jfld) = 1
-               ilen1(jfld) = nblen(igrid(jfld))
-               ilen3(jfld) = 1
-
-               jfld = jfld + 1
-               blf_i(jfld) = bn_hicif
-               ibdy(jfld) = ib_bdy
-               igrid(jfld) = 1
-               ilen1(jfld) = nblen(igrid(jfld))
-               ilen3(jfld) = 1
-
-               jfld = jfld + 1
-               blf_i(jfld) = bn_hsnif
-               ibdy(jfld) = ib_bdy
-               igrid(jfld) = 1
-               ilen1(jfld) = nblen(igrid(jfld))
-               ilen3(jfld) = 1
-
-            ENDIF
+            IF( nn_ice_lim2_dta(ib_bdy) .eq. 1 ) THEN
+
+               IF( dta%ll_frld ) THEN
+                  jfld = jfld + 1
+                  blf_i(jfld) = bn_frld
+                  ibdy(jfld) = ib_bdy
+                  igrid(jfld) = 1
+                  ilen1(jfld) = nblen(igrid(jfld))
+                  ilen3(jfld) = 1
+               ENDIF
+
+               IF( dta%ll_hicif ) THEN
+                  jfld = jfld + 1
+                  blf_i(jfld) = bn_hicif
+                  ibdy(jfld) = ib_bdy
+                  igrid(jfld) = 1
+                  ilen1(jfld) = nblen(igrid(jfld))
+                  ilen3(jfld) = 1
+               ENDIF
+
+               IF( dta%ll_hsnif ) THEN
+                  jfld = jfld + 1
+                  blf_i(jfld) = bn_hsnif
+                  ibdy(jfld) = ib_bdy
+                  igrid(jfld) = 1
+                  ilen1(jfld) = nblen(igrid(jfld))
+                  ilen3(jfld) = 1
+               ENDIF
+
+            ENDIF
+#elif defined key_lim3
+            ! sea ice
+            IF( nn_ice_lim_dta(ib_bdy) .eq. 1 ) THEN
+
+               ! Test for types of ice input (lim2 or lim3) 
+               CALL iom_open ( bn_a_i%clname, inum )
+               id1 = iom_varid ( inum, bn_a_i%clvar, kdimsz=zdimsz, kndims=zndims, ldstop = .FALSE. )
+               CALL iom_close ( inum )
+               !CALL fld_clopn ( bn_a_i, nyear, nmonth, nday, ldstop=.TRUE. )
+               !CALL iom_open ( bn_a_i %clname, inum )
+               !id1 = iom_varid ( bn_a_i%num, bn_a_i%clvar, kdimsz=zdimsz, kndims=zndims, ldstop = .FALSE. )
+      	       IF ( zndims == 4 ) THEN
+                 ll_bdylim3 = .TRUE.   ! lim3 input
+               ELSE
+                 ll_bdylim3 = .FALSE.  ! lim2 input      
+               ENDIF
+               ! End test
+
+               IF( dta%ll_a_i ) THEN
+                  jfld = jfld + 1
+                  blf_i(jfld) = bn_a_i
+                  ibdy(jfld) = ib_bdy
+                  igrid(jfld) = 1
+                  ilen1(jfld) = nblen(igrid(jfld))
+                  IF ( ll_bdylim3 ) THEN ; ilen3(jfld)=jpl ; ELSE ; ilen3(jfld)=1 ; ENDIF
+               ENDIF
+
+               IF( dta%ll_ht_i ) THEN
+                  jfld = jfld + 1
+                  blf_i(jfld) = bn_ht_i
+                  ibdy(jfld) = ib_bdy
+                  igrid(jfld) = 1
+                  ilen1(jfld) = nblen(igrid(jfld))
+                  IF ( ll_bdylim3 ) THEN ; ilen3(jfld)=jpl ; ELSE ; ilen3(jfld)=1 ; ENDIF
+               ENDIF
+
+               IF( dta%ll_ht_s ) THEN
+                  jfld = jfld + 1
+                   blf_i(jfld) = bn_ht_s
+                  ibdy(jfld) = ib_bdy
+                  igrid(jfld) = 1
+                  ilen1(jfld) = nblen(igrid(jfld))
+                  IF ( ll_bdylim3 ) THEN ; ilen3(jfld)=jpl ; ELSE ; ilen3(jfld)=1 ; ENDIF
+               ENDIF
+
 #endif
             ! Recalculate field counts
@@ -568,4 +736,6 @@
             ENDIF
 
+            dta%nread(1) = nb_bdy_fld(ib_bdy)
+
          ENDIF ! nn_dta .eq. 1
       ENDDO ! ib_bdy
@@ -596,51 +766,81 @@
 
          nblen => idx_bdy(ib_bdy)%nblen
-         nblenrim => idx_bdy(ib_bdy)%nblenrim
-
-         IF (nn_dyn2d(ib_bdy) .gt. 0) THEN
-            IF( nn_dyn2d_dta(ib_bdy) .eq. 0 .or. nn_dyn2d_dta(ib_bdy) .eq. 2 .or. ln_full_vel_array(ib_bdy) ) THEN
-               ilen0(1:3) = nblen(1:3)
-               ALLOCATE( dta_bdy(ib_bdy)%u2d(ilen0(2)) )
-               ALLOCATE( dta_bdy(ib_bdy)%v2d(ilen0(3)) )
-               IF ( nn_dyn2d(ib_bdy) .ne. jp_frs .and. (nn_dyn2d_dta(ib_bdy).eq.1.or.nn_dyn2d_dta(ib_bdy).eq.3) ) THEN
-                  jfld = jfld + 1
-                  dta_bdy(ib_bdy)%ssh => bf(jfld)%fnow(:,1,1)
+         dta => dta_bdy(ib_bdy)
+
+         if(lwp) then
+            write(numout,*) '++++++ dta%ll_ssh = ',dta%ll_ssh
+            write(numout,*) '++++++ dta%ll_u2d = ',dta%ll_u2d
+            write(numout,*) '++++++ dta%ll_v2d = ',dta%ll_v2d
+            write(numout,*) '++++++ dta%ll_u3d = ',dta%ll_u3d
+            write(numout,*) '++++++ dta%ll_v3d = ',dta%ll_v3d
+            write(numout,*) '++++++ dta%ll_tem = ',dta%ll_tem
+            write(numout,*) '++++++ dta%ll_sal = ',dta%ll_sal
+         endif
+
+         IF ( nn_dyn2d_dta(ib_bdy) .eq. 0 .or. nn_dyn2d_dta(ib_bdy) .eq. 2 ) THEN
+            if(lwp) write(numout,*) '++++++ dta%ssh/u2d/u3d allocated space'
+            IF( dta%ll_ssh ) ALLOCATE( dta%ssh(nblen(1)) )
+            IF( dta%ll_u2d ) ALLOCATE( dta%u2d(nblen(2)) )
+            IF( dta%ll_v2d ) ALLOCATE( dta%v2d(nblen(3)) )
+         ENDIF
+         IF ( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) THEN
+            IF( dta%ll_ssh ) THEN
+               if(lwp) write(numout,*) '++++++ dta%ssh pointing to fnow'
+               jfld = jfld + 1
+               dta%ssh => bf(jfld)%fnow(:,1,1)
+            ENDIF
+            IF ( dta%ll_u2d ) THEN
+               IF ( ln_full_vel_array(ib_bdy) ) THEN
+                  if(lwp) write(numout,*) '++++++ dta%u2d allocated space'
+                  ALLOCATE( dta%u2d(nblen(2)) )
                ELSE
-                  ALLOCATE( dta_bdy(ib_bdy)%ssh(nblen(1)) )
-               ENDIF
-            ELSE
-               IF( nn_dyn2d(ib_bdy) .ne. jp_frs ) THEN
-                  jfld = jfld + 1
-                  dta_bdy(ib_bdy)%ssh => bf(jfld)%fnow(:,1,1)
-               ENDIF
+                  if(lwp) write(numout,*) '++++++ dta%u2d pointing to fnow'
+                  jfld = jfld + 1
+                  dta%u2d => bf(jfld)%fnow(:,1,1)
+               ENDIF
+            ENDIF
+            IF ( dta%ll_v2d ) THEN
+               IF ( ln_full_vel_array(ib_bdy) ) THEN
+                  if(lwp) write(numout,*) '++++++ dta%v2d allocated space'
+                  ALLOCATE( dta%v2d(nblen(3)) )
+               ELSE
+                  if(lwp) write(numout,*) '++++++ dta%v2d pointing to fnow'
+                  jfld = jfld + 1
+                  dta%v2d => bf(jfld)%fnow(:,1,1)
+               ENDIF
+            ENDIF
+         ENDIF
+
+         IF ( nn_dyn3d_dta(ib_bdy) .eq. 0 ) THEN
+            if(lwp) write(numout,*) '++++++ dta%u3d/v3d allocated space'
+            IF( dta%ll_u3d ) ALLOCATE( dta_bdy(ib_bdy)%u3d(nblen(2),jpk) )
+            IF( dta%ll_v3d ) ALLOCATE( dta_bdy(ib_bdy)%v3d(nblen(3),jpk) )
+         ENDIF
+         IF ( nn_dyn3d_dta(ib_bdy) .eq. 1 .or. &
+           &  ( ln_full_vel_array(ib_bdy) .and. ( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) ) ) THEN
+            IF ( dta%ll_u3d .or. ( ln_full_vel_array(ib_bdy) .and. dta%ll_u2d ) ) THEN
+               if(lwp) write(numout,*) '++++++ dta%u3d pointing to fnow'
                jfld = jfld + 1
-               dta_bdy(ib_bdy)%u2d => bf(jfld)%fnow(:,1,1)
+               dta_bdy(ib_bdy)%u3d => bf(jfld)%fnow(:,1,:)
+            ENDIF
+            IF ( dta%ll_v3d .or. ( ln_full_vel_array(ib_bdy) .and. dta%ll_v2d ) ) THEN
+               if(lwp) write(numout,*) '++++++ dta%v3d pointing to fnow'
                jfld = jfld + 1
-               dta_bdy(ib_bdy)%v2d => bf(jfld)%fnow(:,1,1)
-            ENDIF
-         ENDIF
-
-         IF ( nn_dyn3d(ib_bdy) .gt. 0 .and. nn_dyn3d_dta(ib_bdy) .eq. 0 ) THEN
-            ilen0(1:3) = nblen(1:3)
-            ALLOCATE( dta_bdy(ib_bdy)%u3d(ilen0(2),jpk) )
-            ALLOCATE( dta_bdy(ib_bdy)%v3d(ilen0(3),jpk) )
-         ENDIF
-         IF ( ( nn_dyn3d(ib_bdy) .gt. 0 .and. nn_dyn3d_dta(ib_bdy) .eq. 1 ).or. &
-           &  ( ln_full_vel_array(ib_bdy) .and. nn_dyn2d(ib_bdy) .gt. 0 .and.   &
-           &    ( nn_dyn2d_dta(ib_bdy) .eq. 1 .or. nn_dyn2d_dta(ib_bdy) .eq. 3 ) ) ) THEN
-            jfld = jfld + 1
-            dta_bdy(ib_bdy)%u3d => bf(jfld)%fnow(:,1,:)
-            jfld = jfld + 1
-            dta_bdy(ib_bdy)%v3d => bf(jfld)%fnow(:,1,:)
-         ENDIF
-
-         IF (nn_tra(ib_bdy) .gt. 0) THEN
-            IF( nn_tra_dta(ib_bdy) .eq. 0 ) THEN
-               ilen0(1:3) = nblen(1:3)
-               ALLOCATE( dta_bdy(ib_bdy)%tem(ilen0(1),jpk) )
-               ALLOCATE( dta_bdy(ib_bdy)%sal(ilen0(1),jpk) )
-            ELSE
+               dta_bdy(ib_bdy)%v3d => bf(jfld)%fnow(:,1,:)
+            ENDIF
+         ENDIF
+
+         IF( nn_tra_dta(ib_bdy) .eq. 0 ) THEN
+            if(lwp) write(numout,*) '++++++ dta%tem/sal allocated space'
+            IF( dta%ll_tem ) ALLOCATE( dta_bdy(ib_bdy)%tem(nblen(1),jpk) )
+            IF( dta%ll_sal ) ALLOCATE( dta_bdy(ib_bdy)%sal(nblen(1),jpk) )
+         ELSE
+            IF( dta%ll_tem ) THEN
+               if(lwp) write(numout,*) '++++++ dta%tem pointing to fnow'
                jfld = jfld + 1
                dta_bdy(ib_bdy)%tem => bf(jfld)%fnow(:,1,:)
+            ENDIF
+            IF( dta%ll_sal ) THEN 
+               if(lwp) write(numout,*) '++++++ dta%sal pointing to fnow'
                jfld = jfld + 1
                dta_bdy(ib_bdy)%sal => bf(jfld)%fnow(:,1,:)
@@ -649,10 +849,9 @@
 
 #if defined key_lim2
-         IF (nn_ice_lim2(ib_bdy) .gt. 0) THEN
+         IF (nn_ice_lim(ib_bdy) .gt. 0) THEN
             IF( nn_ice_lim2_dta(ib_bdy) .eq. 0 ) THEN
-               ilen0(1:3) = nblen(1:3)
-               ALLOCATE( dta_bdy(ib_bdy)%frld(ilen0(1)) )
-               ALLOCATE( dta_bdy(ib_bdy)%hicif(ilen0(1)) )
-               ALLOCATE( dta_bdy(ib_bdy)%hsnif(ilen0(1)) )
+               ALLOCATE( dta_bdy(ib_bdy)%frld(nblen(1)) )
+               ALLOCATE( dta_bdy(ib_bdy)%hicif(nblen(1)) )
+               ALLOCATE( dta_bdy(ib_bdy)%hsnif(nblen(1)) )
             ELSE
                jfld = jfld + 1
@@ -662,4 +861,33 @@
                jfld = jfld + 1
                dta_bdy(ib_bdy)%hsnif => bf(jfld)%fnow(:,1,1)
+            ENDIF
+         ENDIF
+#elif defined key_lim3
+         IF (nn_ice_lim(ib_bdy) .gt. 0) THEN
+            IF( nn_ice_lim_dta(ib_bdy) .eq. 0 ) THEN
+               ALLOCATE( dta_bdy(ib_bdy)%a_i (nblen(1),jpl) )
+               ALLOCATE( dta_bdy(ib_bdy)%ht_i(nblen(1),jpl) )
+               ALLOCATE( dta_bdy(ib_bdy)%ht_s(nblen(1),jpl) )
+            ELSE
+               IF ( ll_bdylim3 ) THEN ! case input is lim3 type
+                  jfld = jfld + 1
+                  dta_bdy(ib_bdy)%a_i  => bf(jfld)%fnow(:,1,:)
+                  jfld = jfld + 1
+                  dta_bdy(ib_bdy)%ht_i => bf(jfld)%fnow(:,1,:)
+                  jfld = jfld + 1
+                  dta_bdy(ib_bdy)%ht_s => bf(jfld)%fnow(:,1,:)
+               ELSE ! case input is lim2 type
+                  jfld_ai  = jfld + 1
+                  jfld_hti = jfld + 2
+                  jfld_hts = jfld + 3
+                  jfld     = jfld + 3
+                  ALLOCATE( dta_bdy(ib_bdy)%a_i (nblen(1),jpl) )
+                  ALLOCATE( dta_bdy(ib_bdy)%ht_i(nblen(1),jpl) )
+                  ALLOCATE( dta_bdy(ib_bdy)%ht_s(nblen(1),jpl) )
+                  dta_bdy(ib_bdy)%a_i (:,:) = 0.0
+                  dta_bdy(ib_bdy)%ht_i(:,:) = 0.0
+                  dta_bdy(ib_bdy)%ht_s(:,:) = 0.0
+               ENDIF
+
             ENDIF
          ENDIF
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90	(revision 4292)
@@ -30,5 +30,5 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE in_out_manager  !
-   USE domvvl          ! variable volume
+   USE domvvl
 
    IMPLICIT NONE
@@ -57,7 +57,8 @@
       LOGICAL, INTENT( in ), OPTIONAL :: dyn3d_only       ! T => only update baroclinic velocities
       !!
-      INTEGER               :: jk,ii,ij,ib,igrd     ! Loop counter
-      LOGICAL               :: ll_dyn2d, ll_dyn3d  
-      !!
+      INTEGER               :: jk,ii,ij,ib_bdy,ib,igrd     ! Loop counter
+      LOGICAL               :: ll_dyn2d, ll_dyn3d, ll_orlanski
+      !!
+      REAL(wp), POINTER, DIMENSION(:,:) :: phur1, phvr1     ! inverse depth at u and v points
 
       IF( nn_timing == 1 ) CALL timing_start('bdy_dyn')
@@ -70,4 +71,10 @@
       ENDIF
 
+      ll_orlanski = .false.
+      DO ib_bdy = 1, nb_bdy
+         IF ( cn_dyn2d(ib_bdy) == 'orlanski' .or. cn_dyn2d(ib_bdy) == 'orlanski_npo' &
+     &   .or. cn_dyn3d(ib_bdy) == 'orlanski' .or. cn_dyn3d(ib_bdy) == 'orlanski_npo') ll_orlanski = .true.
+      ENDDO
+
       !-------------------------------------------------------
       ! Set pointers
@@ -77,5 +84,6 @@
       phur => hur
       phvr => hvr
-      CALL wrk_alloc(jpi,jpj,pu2d,pv2d) 
+      CALL wrk_alloc(jpi,jpj,pua2d,pva2d) 
+      IF ( ll_orlanski ) CALL wrk_alloc(jpi,jpj,pub2d,pvb2d,phur1,phvr1) 
 
       !-------------------------------------------------------
@@ -83,25 +91,69 @@
       !-------------------------------------------------------
 
-      pu2d(:,:) = 0.e0
-      pv2d(:,:) = 0.e0
+      ! "After" velocities: 
+
+      pua2d(:,:) = 0.e0
+      pva2d(:,:) = 0.e0
+      
       IF (lk_vvl) THEN
-         DO jk = 1, jpkm1   !! Vertically integrated momentum trends
-            pu2d(:,:) = pu2d(:,:) + fse3u_a(:,:,jk) * umask(:,:,jk) * ua(:,:,jk)
-            pv2d(:,:) = pv2d(:,:) + fse3v_a(:,:,jk) * vmask(:,:,jk) * va(:,:,jk)
-         END DO
-         pu2d(:,:) = pu2d(:,:) / ( hu_0(:,:) + sshu_a(:,:) + 1._wp - umask(:,:,1) )
-         pv2d(:,:) = pv2d(:,:) / ( hv_0(:,:) + sshv_a(:,:) + 1._wp - vmask(:,:,1) )
+         phur1(:,:) = 0.
+         phvr1(:,:) = 0.
+         DO jk = 1, jpkm1
+            phur1(:,:) = phur1(:,:) + fse3u_a(:,:,jk) * umask(:,:,jk)
+            phvr1(:,:) = phvr1(:,:) + fse3v_a(:,:,jk) * vmask(:,:,jk)
+            pua2d(:,:) = pua2d(:,:) + fse3u_a(:,:,jk) * umask(:,:,jk) * ua(:,:,jk)
+            pva2d(:,:) = pva2d(:,:) + fse3v_a(:,:,jk) * vmask(:,:,jk) * va(:,:,jk)
+         END DO
+         phur1(:,:) = umask(:,:,1) / ( phur1(:,:) + 1. - umask(:,:,1) )
+         phvr1(:,:) = vmask(:,:,1) / ( phvr1(:,:) + 1. - vmask(:,:,1) )
+         pua2d(:,:) = pua2d(:,:) * phur1(:,:)
+         pva2d(:,:) = pva2d(:,:) * phvr1(:,:)
       ELSE
-         DO jk = 1, jpkm1   !! Vertically integrated momentum trends
-            pu2d(:,:) = pu2d(:,:) + fse3u(:,:,jk) * umask(:,:,jk) * ua(:,:,jk)
-            pv2d(:,:) = pv2d(:,:) + fse3v(:,:,jk) * vmask(:,:,jk) * va(:,:,jk)
-         END DO
-         pu2d(:,:) = pu2d(:,:) * phur(:,:)
-         pv2d(:,:) = pv2d(:,:) * phvr(:,:)
+         DO jk = 1, jpkm1
+            pua2d(:,:) = pua2d(:,:) + fse3u(:,:,jk) * umask(:,:,jk) * ua(:,:,jk)
+            pva2d(:,:) = pva2d(:,:) + fse3v(:,:,jk) * vmask(:,:,jk) * va(:,:,jk)
+         END DO
+         pua2d(:,:) = pua2d(:,:) * phur(:,:)
+         pva2d(:,:) = pva2d(:,:) * phvr(:,:)
       ENDIF
+
       DO jk = 1 , jpkm1
-         ua(:,:,jk) = ua(:,:,jk) - pu2d(:,:) * umask(:,:,jk)
-         va(:,:,jk) = va(:,:,jk) - pv2d(:,:) * vmask(:,:,jk)
+         ua(:,:,jk) = ua(:,:,jk) - pua2d(:,:)
+         va(:,:,jk) = va(:,:,jk) - pva2d(:,:)
       END DO
+
+      ! "Before" velocities (required for Orlanski condition): 
+
+      IF ( ll_orlanski ) THEN          
+         pub2d(:,:) = 0.e0
+         pvb2d(:,:) = 0.e0
+
+         IF (lk_vvl) THEN
+            phur1(:,:) = 0.
+            phvr1(:,:) = 0.
+            DO jk = 1, jpkm1   !! Vertically integrated momentum trends
+               phur1(:,:) = phur1(:,:) + fse3u_b(:,:,jk) * umask(:,:,jk)
+               phvr1(:,:) = phvr1(:,:) + fse3v_b(:,:,jk) * vmask(:,:,jk)
+               pub2d(:,:) = pub2d(:,:) + fse3u_b(:,:,jk) * umask(:,:,jk) * ub(:,:,jk)
+               pvb2d(:,:) = pvb2d(:,:) + fse3v_b(:,:,jk) * vmask(:,:,jk) * vb(:,:,jk)
+            END DO
+            phur1(:,:) = umask(:,:,1) / ( phur1(:,:) + 1. - umask(:,:,1) )
+            phvr1(:,:) = vmask(:,:,1) / ( phvr1(:,:) + 1. - vmask(:,:,1) )
+            pub2d(:,:) = pub2d(:,:) * phur1(:,:)
+            pvb2d(:,:) = pvb2d(:,:) * phvr1(:,:)
+         ELSE
+            DO jk = 1, jpkm1   !! Vertically integrated momentum trends
+               pub2d(:,:) = pub2d(:,:) + fse3u(:,:,jk) * umask(:,:,jk) * ub(:,:,jk)
+               pvb2d(:,:) = pvb2d(:,:) + fse3v(:,:,jk) * vmask(:,:,jk) * vb(:,:,jk)
+            END DO
+            pub2d(:,:) = pub2d(:,:) * phur(:,:)
+            pvb2d(:,:) = pvb2d(:,:) * phvr(:,:)
+         ENDIF
+
+         DO jk = 1 , jpkm1
+            ub(:,:,jk) = ub(:,:,jk) - pub2d(:,:)
+            vb(:,:,jk) = vb(:,:,jk) - pvb2d(:,:)
+         END DO
+      END IF
 
       !-------------------------------------------------------
@@ -119,9 +171,17 @@
 
       DO jk = 1 , jpkm1
-         ua(:,:,jk) = ( ua(:,:,jk) + pu2d(:,:) ) * umask(:,:,jk)
-         va(:,:,jk) = ( va(:,:,jk) + pv2d(:,:) ) * vmask(:,:,jk)
+         ua(:,:,jk) = ( ua(:,:,jk) + pua2d(:,:) ) * umask(:,:,jk)
+         va(:,:,jk) = ( va(:,:,jk) + pva2d(:,:) ) * vmask(:,:,jk)
       END DO
 
-      CALL wrk_dealloc(jpi,jpj,pu2d,pv2d) 
+      IF ( ll_orlanski ) THEN
+         DO jk = 1 , jpkm1
+            ub(:,:,jk) = ( ub(:,:,jk) + pub2d(:,:) ) * umask(:,:,jk)
+            vb(:,:,jk) = ( vb(:,:,jk) + pvb2d(:,:) ) * vmask(:,:,jk)
+         END DO
+      END IF
+
+      CALL wrk_dealloc(jpi,jpj,pua2d,pva2d) 
+      IF ( ll_orlanski ) CALL wrk_dealloc(jpi,jpj,pub2d,pvb2d) 
 
       IF( nn_timing == 1 ) CALL timing_stop('bdy_dyn')
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn2d.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn2d.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn2d.F90	(revision 4292)
@@ -6,4 +6,5 @@
    !! History :  3.4  !  2011     (D. Storkey) new module as part of BDY rewrite
    !!            3.5  !  2012     (S. Mocavero, I. Epicoco) Optimization of BDY communications
+   !!            3.5  !  2013-07  (J. Chanut) Compliant with time splitting changes
    !!----------------------------------------------------------------------
 #if defined key_bdy 
@@ -11,6 +12,9 @@
    !!   'key_bdy' :                    Unstructured Open Boundary Condition
    !!----------------------------------------------------------------------
-   !!   bdy_dyn2d      : Apply open boundary conditions to barotropic variables.
-   !!   bdy_dyn2d_fla    : Apply Flather condition
+   !!   bdy_dyn2d          : Apply open boundary conditions to barotropic variables.
+   !!   bdy_dyn2d_frs      : Apply Flow Relaxation Scheme 
+   !!   bdy_dyn2d_fla      : Apply Flather condition
+   !!   bdy_dyn2d_orlanski : Orlanski Radiation
+   !!   bdy_ssh            : Duplicate sea level across open boundaries
    !!----------------------------------------------------------------------
    USE timing          ! Timing
@@ -18,4 +22,5 @@
    USE dom_oce         ! ocean space and time domain
    USE bdy_oce         ! ocean open boundary conditions
+   USE bdylib          ! BDY library routines
    USE dynspg_oce      ! for barotropic variables
    USE phycst          ! physical constants
@@ -26,5 +31,6 @@
    PRIVATE
 
-   PUBLIC   bdy_dyn2d     ! routine called in dynspg_ts and bdy_dyn
+   PUBLIC   bdy_dyn2d   ! routine called in dynspg_ts and bdy_dyn
+   PUBLIC   bdy_ssh       ! routine called in dynspg_ts or sshwzv
 
    !!----------------------------------------------------------------------
@@ -48,11 +54,15 @@
       DO ib_bdy=1, nb_bdy
 
-         SELECT CASE( nn_dyn2d(ib_bdy) )
-         CASE(jp_none)
+         SELECT CASE( cn_dyn2d(ib_bdy) )
+         CASE('none')
             CYCLE
-         CASE(jp_frs)
+         CASE('frs')
             CALL bdy_dyn2d_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy )
-         CASE(jp_flather)
+         CASE('flather')
             CALL bdy_dyn2d_fla( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy )
+         CASE('orlanski')
+            CALL bdy_dyn2d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, ll_npo=.false. )
+         CASE('orlanski_npo')
+            CALL bdy_dyn2d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, ll_npo=.true. )
          CASE DEFAULT
             CALL ctl_stop( 'bdy_dyn2d : unrecognised option for open boundaries for barotropic variables' )
@@ -89,5 +99,5 @@
          ij   = idx%nbj(jb,igrd)
          zwgt = idx%nbw(jb,igrd)
-         pu2d(ii,ij) = ( pu2d(ii,ij) + zwgt * ( dta%u2d(jb) - pu2d(ii,ij) ) ) * umask(ii,ij,1)
+         pua2d(ii,ij) = ( pua2d(ii,ij) + zwgt * ( dta%u2d(jb) - pua2d(ii,ij) ) ) * umask(ii,ij,1)
       END DO
       !
@@ -97,8 +107,8 @@
          ij   = idx%nbj(jb,igrd)
          zwgt = idx%nbw(jb,igrd)
-         pv2d(ii,ij) = ( pv2d(ii,ij) + zwgt * ( dta%v2d(jb) - pv2d(ii,ij) ) ) * vmask(ii,ij,1)
+         pva2d(ii,ij) = ( pva2d(ii,ij) + zwgt * ( dta%v2d(jb) - pva2d(ii,ij) ) ) * vmask(ii,ij,1)
       END DO 
-      CALL lbc_bdy_lnk( pu2d, 'U', -1., ib_bdy ) 
-      CALL lbc_bdy_lnk( pv2d, 'V', -1., ib_bdy)   ! Boundary points should be updated
+      CALL lbc_bdy_lnk( pua2d, 'U', -1., ib_bdy ) 
+      CALL lbc_bdy_lnk( pva2d, 'V', -1., ib_bdy)   ! Boundary points should be updated
       !
       IF( nn_timing == 1 ) CALL timing_stop('bdy_dyn2d_frs')
@@ -133,9 +143,13 @@
       INTEGER  ::   jb, igrd                         ! dummy loop indices
       INTEGER  ::   ii, ij, iim1, iip1, ijm1, ijp1   ! 2D addresses
+      REAL(wp), POINTER :: flagu, flagv              ! short cuts
       REAL(wp) ::   zcorr                            ! Flather correction
       REAL(wp) ::   zforc                            ! temporary scalar
+      REAL(wp) ::   zflag, z1_2                      !    "        "
       !!----------------------------------------------------------------------
 
       IF( nn_timing == 1 ) CALL timing_start('bdy_dyn2d_fla')
+
+      z1_2 = 0.5_wp
 
       ! ---------------------------------!
@@ -160,10 +174,15 @@
          ii  = idx%nbi(jb,igrd)
          ij  = idx%nbj(jb,igrd) 
-         iim1 = ii + MAX( 0, INT( idx%flagu(jb) ) )   ! T pts i-indice inside the boundary
-         iip1 = ii - MIN( 0, INT( idx%flagu(jb) ) )   ! T pts i-indice outside the boundary 
+         flagu => idx%flagu(jb,igrd)
+         iim1 = ii + MAX( 0, INT( flagu ) )   ! T pts i-indice inside the boundary
+         iip1 = ii - MIN( 0, INT( flagu ) )   ! T pts i-indice outside the boundary 
          !
-         zcorr = - idx%flagu(jb) * SQRT( grav * phur(ii, ij) ) * ( pssh(iim1, ij) - spgu(iip1,ij) )
-         zforc = dta%u2d(jb)
-         pu2d(ii,ij) = zforc + zcorr * umask(ii,ij,1) 
+         zcorr = - flagu * SQRT( grav * phur(ii, ij) ) * ( pssh(iim1, ij) - spgu(iip1,ij) )
+
+         ! jchanut tschanges: Set zflag to 0 below to revert to Flather scheme
+         ! Use characteristics method instead
+         zflag = ABS(flagu)
+         zforc = dta%u2d(jb) * (1._wp - z1_2*zflag) + z1_2 * zflag * pua2d(iim1,ij)
+         pua2d(ii,ij) = zforc + (1._wp - z1_2*zflag) * zcorr * umask(ii,ij,1) 
       END DO
       !
@@ -173,17 +192,110 @@
          ii  = idx%nbi(jb,igrd)
          ij  = idx%nbj(jb,igrd) 
-         ijm1 = ij + MAX( 0, INT( idx%flagv(jb) ) )   ! T pts j-indice inside the boundary
-         ijp1 = ij - MIN( 0, INT( idx%flagv(jb) ) )   ! T pts j-indice outside the boundary 
+         flagv => idx%flagv(jb,igrd)
+         ijm1 = ij + MAX( 0, INT( flagv ) )   ! T pts j-indice inside the boundary
+         ijp1 = ij - MIN( 0, INT( flagv ) )   ! T pts j-indice outside the boundary 
          !
-         zcorr = - idx%flagv(jb) * SQRT( grav * phvr(ii, ij) ) * ( pssh(ii, ijm1) - spgu(ii,ijp1) )
-         zforc = dta%v2d(jb)
-         pv2d(ii,ij) = zforc + zcorr * vmask(ii,ij,1)
-      END DO
-      CALL lbc_bdy_lnk( pu2d, 'U', -1., ib_bdy )   ! Boundary points should be updated
-      CALL lbc_bdy_lnk( pv2d, 'V', -1., ib_bdy )   !
+         zcorr = - flagv * SQRT( grav * phvr(ii, ij) ) * ( pssh(ii, ijm1) - spgu(ii,ijp1) )
+
+         ! jchanut tschanges: Set zflag to 0 below to revert to std Flather scheme
+         ! Use characteristics method instead
+         zflag = ABS(flagv)
+         zforc  = dta%v2d(jb) * (1._wp - z1_2*zflag) + z1_2 * zflag * pva2d(ii,ijm1)
+         pva2d(ii,ij) = zforc + (1._wp - z1_2*zflag) * zcorr * vmask(ii,ij,1)
+      END DO
+      CALL lbc_bdy_lnk( pua2d, 'U', -1., ib_bdy )   ! Boundary points should be updated
+      CALL lbc_bdy_lnk( pva2d, 'V', -1., ib_bdy )   !
       !
       IF( nn_timing == 1 ) CALL timing_stop('bdy_dyn2d_fla')
       !
    END SUBROUTINE bdy_dyn2d_fla
+
+
+   SUBROUTINE bdy_dyn2d_orlanski( idx, dta, ib_bdy, ll_npo )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_dyn2d_orlanski  ***
+      !!             
+      !!              - Apply Orlanski radiation condition adaptively:
+      !!                  - radiation plus weak nudging at outflow points
+      !!                  - no radiation and strong nudging at inflow points
+      !! 
+      !!
+      !! References:  Marchesiello, McWilliams and Shchepetkin, Ocean Modelling vol. 3 (2001)    
+      !!----------------------------------------------------------------------
+      TYPE(OBC_INDEX),              INTENT(in) ::   idx  ! OBC indices
+      TYPE(OBC_DATA),               INTENT(in) ::   dta  ! OBC external data
+      INTEGER,                      INTENT(in) ::   ib_bdy  ! number of current open boundary set
+      LOGICAL,                      INTENT(in) ::   ll_npo  ! flag for NPO version
+
+      INTEGER  ::   ib, igrd                               ! dummy loop indices
+      INTEGER  ::   ii, ij, iibm1, ijbm1                   ! indices
+      !!----------------------------------------------------------------------
+
+      IF( nn_timing == 1 ) CALL timing_start('bdy_dyn2d_orlanski')
+      !
+      igrd = 2      ! Orlanski bc on u-velocity; 
+      !            
+      CALL bdy_orlanski_2d( idx, igrd, pub2d, pua2d, dta%u2d, ll_npo )
+
+      igrd = 3      ! Orlanski bc on v-velocity
+      !  
+      CALL bdy_orlanski_2d( idx, igrd, pvb2d, pva2d, dta%v2d, ll_npo )
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_dyn2d_orlanski')
+      !
+      CALL lbc_bdy_lnk( pua2d, 'U', -1., ib_bdy )   ! Boundary points should be updated
+      CALL lbc_bdy_lnk( pva2d, 'V', -1., ib_bdy )   !
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_dyn2d_orlanski')
+      !
+   END SUBROUTINE bdy_dyn2d_orlanski
+
+   SUBROUTINE bdy_ssh( zssh )
+      !!----------------------------------------------------------------------
+      !!                  ***  SUBROUTINE bdy_ssh  ***
+      !!
+      !! ** Purpose : Duplicate sea level across open boundaries
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   zssh ! Sea level
+      !!
+      INTEGER  ::   ib_bdy, ib, igrd                        ! local integers
+      INTEGER  ::   ii, ij, zcoef, zcoef1, zcoef2, ip, jp   !   "       "
+
+      igrd = 1                       ! Everything is at T-points here
+
+      DO ib_bdy = 1, nb_bdy
+         DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
+            ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+            ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+            ! Set gradient direction:
+            zcoef1 = bdytmask(ii-1,ij  ) +  bdytmask(ii+1,ij  )
+            zcoef2 = bdytmask(ii  ,ij-1) +  bdytmask(ii  ,ij+1)
+            IF ( zcoef1+zcoef2 == 0 ) THEN
+               ! corner
+!               zcoef = tmask(ii-1,ij,1) + tmask(ii+1,ij,1) +  tmask(ii,ij-1,1) +  tmask(ii,ij+1,1)
+!               zssh(ii,ij) = zssh(ii-1,ij  ) * tmask(ii-1,ij  ,1) + &
+!                 &           zssh(ii+1,ij  ) * tmask(ii+1,ij  ,1) + &
+!                 &           zssh(ii  ,ij-1) * tmask(ii  ,ij-1,1) + &
+!                 &           zssh(ii  ,ij+1) * tmask(ii  ,ij+1,1)
+               zcoef = bdytmask(ii-1,ij) + bdytmask(ii+1,ij) +  bdytmask(ii,ij-1) +  bdytmask(ii,ij+1)
+               zssh(ii,ij) = zssh(ii-1,ij  ) * bdytmask(ii-1,ij  ) + &
+                 &           zssh(ii+1,ij  ) * bdytmask(ii+1,ij  ) + &
+                 &           zssh(ii  ,ij-1) * bdytmask(ii  ,ij-1) + &
+                 &           zssh(ii  ,ij+1) * bdytmask(ii  ,ij+1)
+               zssh(ii,ij) = ( zssh(ii,ij) / MAX( 1, zcoef) ) * tmask(ii,ij,1)
+            ELSE
+               ip = bdytmask(ii+1,ij  ) - bdytmask(ii-1,ij  )
+               jp = bdytmask(ii  ,ij+1) - bdytmask(ii  ,ij-1)
+               zssh(ii,ij) = zssh(ii+ip,ij+jp) * tmask(ii+ip,ij+jp,1)
+            ENDIF
+         END DO
+
+         ! Boundary points should be updated
+         CALL lbc_bdy_lnk( zssh(:,:), 'T', 1., ib_bdy )
+      END DO
+
+   END SUBROUTINE bdy_ssh
+
 #else
    !!----------------------------------------------------------------------
@@ -192,8 +304,11 @@
 CONTAINS
    SUBROUTINE bdy_dyn2d( kt )      ! Empty routine
-      WRITE(*,*) 'bdy_dyn_frs: You should not have seen this print! error?', kt
+      INTEGER, intent(in) :: kt
+      WRITE(*,*) 'bdy_dyn2d: You should not have seen this print! error?', kt
    END SUBROUTINE bdy_dyn2d
+
 #endif
 
    !!======================================================================
 END MODULE bdydyn2d
+
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn3d.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn3d.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn3d.F90	(revision 4292)
@@ -19,4 +19,5 @@
    USE dom_oce         ! ocean space and time domain
    USE bdy_oce         ! ocean open boundary conditions
+   USE bdylib          ! for orlanski library routines
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE in_out_manager  !
@@ -52,17 +53,17 @@
       DO ib_bdy=1, nb_bdy
 
-!!$         IF ( using Orlanski radiation conditions ) THEN 
-!!$            CALL bdy_rad( kt,  bdyidx(ib_bdy) )
-!!$         ENDIF
-
-         SELECT CASE( nn_dyn3d(ib_bdy) )
-         CASE(jp_none)
+         SELECT CASE( cn_dyn3d(ib_bdy) )
+         CASE('none')
             CYCLE
-         CASE(jp_frs)
+         CASE('frs')
             CALL bdy_dyn3d_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
-         CASE(2)
+         CASE('specified')
             CALL bdy_dyn3d_spe( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
-         CASE(3)
+         CASE('zero')
             CALL bdy_dyn3d_zro( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
+         CASE('orlanski')
+            CALL bdy_dyn3d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, ll_npo=.false. )
+         CASE('orlanski_npo')
+            CALL bdy_dyn3d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, ll_npo=.true. )
          CASE DEFAULT
             CALL ctl_stop( 'bdy_dyn3d : unrecognised option for open boundaries for baroclinic velocities' )
@@ -109,5 +110,6 @@
          END DO
       END DO
-      CALL lbc_bdy_lnk( ua, 'U', -1., ib_bdy )   ;   CALL lbc_bdy_lnk( va, 'V', -1.,ib_bdy )   ! Boundary points should be updated
+      CALL lbc_bdy_lnk( ua, 'U', -1., ib_bdy )   ! Boundary points should be updated  
+      CALL lbc_bdy_lnk( va, 'V', -1., ib_bdy )   
       !
       IF( kt .eq. nit000 ) CLOSE( unit = 102 )
@@ -204,5 +206,6 @@
          END DO
       END DO 
-      CALL lbc_bdy_lnk( ua, 'U', -1., ib_bdy )   ;   CALL lbc_bdy_lnk( va, 'V', -1.,ib_bdy )   ! Boundary points should be updated
+      CALL lbc_bdy_lnk( ua, 'U', -1., ib_bdy )    ! Boundary points should be updated
+      CALL lbc_bdy_lnk( va, 'V', -1., ib_bdy )   
       !
       IF( kt .eq. nit000 ) CLOSE( unit = 102 )
@@ -211,4 +214,42 @@
 
    END SUBROUTINE bdy_dyn3d_frs
+
+   SUBROUTINE bdy_dyn3d_orlanski( idx, dta, ib_bdy, ll_npo )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_dyn3d_orlanski  ***
+      !!             
+      !!              - Apply Orlanski radiation to baroclinic velocities. 
+      !!              - Wrapper routine for bdy_orlanski_3d
+      !! 
+      !!
+      !! References:  Marchesiello, McWilliams and Shchepetkin, Ocean Modelling vol. 3 (2001)    
+      !!----------------------------------------------------------------------
+      TYPE(OBC_INDEX),              INTENT(in) ::   idx  ! OBC indices
+      TYPE(OBC_DATA),               INTENT(in) ::   dta  ! OBC external data
+      INTEGER,                      INTENT(in) ::   ib_bdy  ! BDY set index
+      LOGICAL,                      INTENT(in) ::   ll_npo  ! switch for NPO version
+
+      INTEGER  ::   jb, igrd                               ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF( nn_timing == 1 ) CALL timing_start('bdy_dyn3d_orlanski')
+      !
+      !! Note that at this stage the ub and ua arrays contain the baroclinic velocities. 
+      !
+      igrd = 2      ! Orlanski bc on u-velocity; 
+      !            
+      CALL bdy_orlanski_3d( idx, igrd, ub, ua, dta%u3d, ll_npo )
+
+      igrd = 3      ! Orlanski bc on v-velocity
+      !  
+      CALL bdy_orlanski_3d( idx, igrd, vb, va, dta%v3d, ll_npo )
+      !
+      CALL lbc_bdy_lnk( ua, 'U', -1., ib_bdy )    ! Boundary points should be updated
+      CALL lbc_bdy_lnk( va, 'V', -1., ib_bdy )   
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_dyn3d_orlanski')
+      !
+   END SUBROUTINE bdy_dyn3d_orlanski
+
 
    SUBROUTINE bdy_dyn3d_dmp( kt )
@@ -225,4 +266,5 @@
       REAL(wp) ::   zwgt           ! boundary weight
       INTEGER  ::  ib_bdy          ! loop index
+      REAL(wp), POINTER, DIMENSION(:,:) :: phur1, phvr1     ! inverse depth at u and v points
       !!----------------------------------------------------------------------
       !
@@ -232,29 +274,35 @@
       ! Remove barotropic part from before velocity
       !-------------------------------------------------------
-      CALL wrk_alloc(jpi,jpj,pu2d,pv2d) 
-
-      pu2d(:,:) = 0.e0
-      pv2d(:,:) = 0.e0
-
+      CALL wrk_alloc(jpi,jpj,pub2d,pvb2d,phur1,phvr1) 
+
+      pub2d(:,:) = 0.e0
+      pvb2d(:,:) = 0.e0
+
+      phur1(:,:) = 0.
+      phvr1(:,:) = 0.
       DO jk = 1, jpkm1
 #if defined key_vvl
-         pu2d(:,:) = pu2d(:,:) + fse3u_b(:,:,jk)* ub(:,:,jk)   *umask(:,:,jk) 
-         pv2d(:,:) = pv2d(:,:) + fse3v_b(:,:,jk)* vb(:,:,jk)   *vmask(:,:,jk)
+         phur1(:,:) = phur1(:,:) + fse3u_a(:,:,jk) * umask(:,:,jk)
+         phvr1(:,:) = phvr1(:,:) + fse3v_a(:,:,jk) * vmask(:,:,jk)
+         pub2d(:,:) = pub2d(:,:) + fse3u_b(:,:,jk)* ub(:,:,jk)   *umask(:,:,jk) 
+         pvb2d(:,:) = pvb2d(:,:) + fse3v_b(:,:,jk)* vb(:,:,jk)   *vmask(:,:,jk)
 #else
-         pu2d(:,:) = pu2d(:,:) + fse3u_0(:,:,jk) * ub(:,:,jk)  * umask(:,:,jk)
-         pv2d(:,:) = pv2d(:,:) + fse3v_0(:,:,jk) * vb(:,:,jk)  * vmask(:,:,jk)
+         pub2d(:,:) = pub2d(:,:) + fse3u_0(:,:,jk) * ub(:,:,jk)  * umask(:,:,jk)
+         pvb2d(:,:) = pvb2d(:,:) + fse3v_0(:,:,jk) * vb(:,:,jk)  * vmask(:,:,jk)
 #endif
       END DO
 
       IF( lk_vvl ) THEN
-         pu2d(:,:) = pu2d(:,:) * umask(:,:,1) / ( hu_0(:,:) + sshu_b(:,:) + 1._wp - umask(:,:,1) )
-         pv2d(:,:) = pv2d(:,:) * vmask(:,:,1) / ( hv_0(:,:) + sshv_b(:,:) + 1._wp - vmask(:,:,1) )
+         phur1(:,:) = umask(:,:,1) / ( phur1(:,:) + 1. - umask(:,:,1) )
+         phvr1(:,:) = vmask(:,:,1) / ( phvr1(:,:) + 1. - vmask(:,:,1) )
+         pub2d(:,:) = pub2d(:,:) * umask(:,:,1) * phur1(:,:)
+         pvb2d(:,:) = pvb2d(:,:) * vmask(:,:,1) * phvr1(:,:)
       ELSE
-         pu2d(:,:) = pv2d(:,:) * hur(:,:)
-         pv2d(:,:) = pu2d(:,:) * hvr(:,:)
+         pub2d(:,:) = pvb2d(:,:) * hur(:,:)
+         pvb2d(:,:) = pub2d(:,:) * hvr(:,:)
       ENDIF
 
       DO ib_bdy=1, nb_bdy
-         IF ( ln_dyn3d_dmp(ib_bdy).and.nn_dyn3d(ib_bdy).gt.0 ) THEN
+         IF ( ln_dyn3d_dmp(ib_bdy) .and. cn_dyn3d(ib_bdy) /= 'none' ) THEN
             igrd = 2                      ! Relaxation of zonal velocity
             DO jb = 1, idx_bdy(ib_bdy)%nblen(igrd)
@@ -264,5 +312,5 @@
                DO jk = 1, jpkm1
                   ua(ii,ij,jk) = ( ua(ii,ij,jk) + zwgt * ( dta_bdy(ib_bdy)%u3d(jb,jk) - &
-                                   ub(ii,ij,jk) + pu2d(ii,ij)) ) * umask(ii,ij,jk)
+                                   ub(ii,ij,jk) + pub2d(ii,ij)) ) * umask(ii,ij,jk)
                END DO
             END DO
@@ -275,5 +323,5 @@
                DO jk = 1, jpkm1
                   va(ii,ij,jk) = ( va(ii,ij,jk) + zwgt * ( dta_bdy(ib_bdy)%v3d(jb,jk) -  &
-                                   vb(ii,ij,jk) + pv2d(ii,ij)) ) * vmask(ii,ij,jk)
+                                   vb(ii,ij,jk) + pvb2d(ii,ij)) ) * vmask(ii,ij,jk)
                END DO
             END DO
@@ -281,5 +329,5 @@
       ENDDO
       !
-      CALL wrk_dealloc(jpi,jpj,pu2d,pv2d) 
+      CALL wrk_dealloc(jpi,jpj,pub2d,pvb2d) 
       !
       CALL lbc_lnk( ua, 'U', -1. )   ;   CALL lbc_lnk( va, 'V', -1. )   ! Boundary points should be updated
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90	(revision 4292)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90	(revision 4292)
@@ -0,0 +1,416 @@
+MODULE bdyice_lim
+   !!======================================================================
+   !!                       ***  MODULE  bdyice_lim  ***
+   !! Unstructured Open Boundary Cond. :  Open boundary conditions for sea-ice (LIM2 and LIM3)
+   !!======================================================================
+   !!  History :  3.3  !  2010-09 (D. Storkey)  Original code
+   !!             3.4  !  2011    (D. Storkey)  rewrite in preparation for OBC-BDY merge
+   !!              -   !  2012-01 (C. Rousset)  add lim3 and remove useless jk loop 
+   !!----------------------------------------------------------------------
+#if defined   key_bdy   &&  ( defined key_lim2 || defined key_lim3 )
+   !!----------------------------------------------------------------------
+   !!   'key_bdy'            and                 Unstructured Open Boundary Conditions
+   !!   'key_lim2'                                                 LIM-2 sea ice model
+   !!   'key_lim3'                                                 LIM-3 sea ice model
+   !!----------------------------------------------------------------------
+   !!   bdy_ice_lim        : Application of open boundaries to ice
+   !!   bdy_ice_frs        : Application of Flow Relaxation Scheme
+   !!----------------------------------------------------------------------
+   USE timing          ! Timing
+   USE phycst          ! physical constant
+   USE eosbn2          ! equation of state
+   USE oce             ! ocean dynamics and tracers variables
+#if defined key_lim2
+   USE par_ice_2
+   USE ice_2           ! LIM_2 ice variables
+#elif defined key_lim3
+   USE par_ice
+   USE ice             ! LIM_3 ice variables
+#endif 
+   USE par_oce         ! ocean parameters
+   USE dom_oce         ! ocean space and time domain variables 
+   USE dom_ice          ! sea-ice domain
+   USE sbc_oce         ! Surface boundary condition: ocean fields
+   USE bdy_oce         ! ocean open boundary conditions
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  ! write to numout file
+   USE lib_mpp         ! distributed memory computing
+   USE lib_fortran     ! to use key_nosignedzero
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   bdy_ice_lim    ! routine called in sbcmod
+   PUBLIC   bdy_ice_lim_dyn ! routine called in limrhg
+
+   REAL(wp) ::   epsi20 = 1.e-20_wp  ! module constants
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: bdyice.F90 2715 2011-03-30 15:58:35Z rblod $
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE bdy_ice_lim( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  SUBROUTINE bdy_ice_lim  ***
+      !!
+      !! ** Purpose : - Apply open boundary conditions for ice (LIM2 and LIM3)
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) :: kt     ! Main time step counter
+      !!
+      INTEGER               :: ib_bdy ! Loop index
+      DO ib_bdy=1, nb_bdy
+
+         SELECT CASE( cn_ice_lim(ib_bdy) )
+         CASE('none')
+            CYCLE
+         CASE('frs')
+            CALL bdy_ice_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
+         CASE DEFAULT
+            CALL ctl_stop( 'bdy_ice_lim : unrecognised option for open boundaries for ice fields' )
+         END SELECT
+      ENDDO
+
+   END SUBROUTINE bdy_ice_lim
+
+   SUBROUTINE bdy_ice_frs( idx, dta, kt, ib_bdy )
+      !!------------------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_ice_frs  ***
+      !!                    
+      !! ** Purpose : Apply the Flow Relaxation Scheme for sea-ice fields in the case 
+      !!              of unstructured open boundaries.
+      !! 
+      !! Reference : Engedahl H., 1995: Use of the flow relaxation scheme in a three-
+      !!             dimensional baroclinic ocean model with realistic topography. Tellus, 365-382.
+      !!------------------------------------------------------------------------------
+      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
+      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
+      INTEGER,         INTENT(in) ::   kt   ! main time-step counter
+      INTEGER,         INTENT(in) ::   ib_bdy  ! BDY set index      !!
+
+      INTEGER  ::   jb, jk, jgrd, jl   ! dummy loop indices
+      INTEGER  ::   ji, jj             ! local scalar
+      REAL(wp) ::   zwgt, zwgt1        ! local scalar
+      REAL(wp) ::   zinda, ztmelts
+      !!------------------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('bdy_ice_frs')
+      !
+      !IF( kt /= nit000 ) THEN
+      jgrd = 1      ! Everything is at T-points here
+      !
+#if defined key_lim2
+      DO jb = 1, idx%nblen(jgrd)
+         ji    = idx%nbi(jb,jgrd)
+         jj    = idx%nbj(jb,jgrd)
+         zwgt  = idx%nbw(jb,jgrd)
+         zwgt1 = 1.e0 - idx%nbw(jb,jgrd)
+         frld (ji,jj) = ( frld (ji,jj) * zwgt1 + dta%frld (jb) * zwgt ) * tmask(ji,jj,1)     ! Leads fraction 
+         hicif(ji,jj) = ( hicif(ji,jj) * zwgt1 + dta%hicif(jb) * zwgt ) * tmask(ji,jj,1)     ! Ice depth 
+         hsnif(ji,jj) = ( hsnif(ji,jj) * zwgt1 + dta%hsnif(jb) * zwgt ) * tmask(ji,jj,1)     ! Snow depth
+
+!         zinda = 1.0 - MAX( 0.0_wp , SIGN ( 1.0_wp , - frld(ji,jj) ) ) ! 0 if no ice
+!         !------------------------------
+!         ! Sea ice surface temperature
+!         !------------------------------
+!         sist(ji,jj)   = zinda * 270.0 + ( 1.0 - zinda ) * tfu(ji,jj)
+!         !-----------------------------------------------
+!         ! Ice/snow temperatures and energy stored in brines 
+!         !-----------------------------------------------
+!         !!! TO BE CONTIUNED (as LIM3 below) !!!
+!            zindhe = MAX( 0.e0, SIGN( 1.e0, fcor(1,jj) ) )              ! = 0 for SH, =1 for NH
+! 
+!               ! Recover in situ values.
+!               zindb         = MAX( rzero, SIGN( rone, zs0a(ji,jj) - epsi06 ) )
+!               zacrith       = 1.0 - ( zindhe * acrit(1) + ( 1.0 - zindhe ) * acrit(2) )
+!               zs0a (ji,jj)  = zindb * MIN( zs0a(ji,jj), zacrith )
+!               hsnif(ji,jj)  = zindb * ( zs0sn(ji,jj) /MAX( zs0a(ji,jj), epsi16 ) )
+!               hicif(ji,jj)  = zindb * ( zs0ice(ji,jj)/MAX( zs0a(ji,jj), epsi16 ) )
+!               zindsn        = MAX( rzero, SIGN( rone, hsnif(ji,jj) - epsi06 ) )
+!               zindic        = MAX( rzero, SIGN( rone, hicif(ji,jj) - epsi03 ) )
+!               zindb         = MAX( zindsn, zindic )
+!               zs0a (ji,jj)  = zindb * zs0a(ji,jj)
+!               frld (ji,jj)  = 1.0 - zs0a(ji,jj)
+!               hsnif(ji,jj)  = zindsn * hsnif(ji,jj)
+!               hicif(ji,jj)  = zindic * hicif(ji,jj)
+!               zusvosn       = 1.0/MAX( hsnif(ji,jj) * zs0a(ji,jj), epsi16 )
+!               zusvoic       = 1.0/MAX( hicif(ji,jj) * zs0a(ji,jj), epsi16 )
+!               zignm         = MAX( rzero,  SIGN( rone, hsndif - hsnif(ji,jj) ) )
+!               zrtt          = 173.15 * rone 
+!               ztsn          =          zignm   * tbif(ji,jj,1)  &
+!                              + ( 1.0 - zignm ) * MIN( MAX( zrtt, rt0_snow * zusvosn * zs0c0(ji,jj)) , tfu(ji,jj) ) 
+!               ztic1          = MIN( MAX( zrtt, rt0_ice * zusvoic * zs0c1(ji,jj) ) , tfu(ji,jj) )
+!               ztic2          = MIN( MAX( zrtt, rt0_ice * zusvoic * zs0c2(ji,jj) ) , tfu(ji,jj) )
+! 
+!               tbif(ji,jj,1) = zindsn * ztsn  + ( 1.0 - zindsn ) * tfu(ji,jj)               
+!               tbif(ji,jj,2) = zindic * ztic1 + ( 1.0 - zindic ) * tfu(ji,jj)
+!               tbif(ji,jj,3) = zindic * ztic2 + ( 1.0 - zindic ) * tfu(ji,jj)
+!               qstoif(ji,jj) = zindb  * xlic * zs0st(ji,jj) /  MAX( zs0a(ji,jj), epsi16 )
+
+      END DO 
+
+      CALL lbc_bdy_lnk( frld,  'T', 1., ib_bdy )                                         ! lateral boundary conditions
+      CALL lbc_bdy_lnk( hicif, 'T', 1., ib_bdy )
+      CALL lbc_bdy_lnk( hsnif, 'T', 1., ib_bdy )
+
+      vt_i(:,:) = hicif(:,:) * frld(:,:)
+      vt_s(:,:) = hsnif(:,:) * frld(:,:)
+      !
+#elif defined key_lim3
+
+      DO jl = 1, jpl
+         DO jb = 1, idx%nblen(jgrd)
+            ji    = idx%nbi(jb,jgrd)
+            jj    = idx%nbj(jb,jgrd)
+            zwgt  = idx%nbw(jb,jgrd)
+            zwgt1 = 1.e0 - idx%nbw(jb,jgrd)
+            a_i (ji,jj,jl) = ( a_i (ji,jj,jl) * zwgt1 + dta%a_i (jb,jl) * zwgt ) * tmask(ji,jj,1)  ! Leads fraction 
+            ht_i(ji,jj,jl) = ( ht_i(ji,jj,jl) * zwgt1 + dta%ht_i(jb,jl) * zwgt ) * tmask(ji,jj,1)  ! Ice depth 
+            ht_s(ji,jj,jl) = ( ht_s(ji,jj,jl) * zwgt1 + dta%ht_s(jb,jl) * zwgt ) * tmask(ji,jj,1)  ! Snow depth
+         ENDDO
+         CALL lbc_bdy_lnk(  a_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk( ht_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk( ht_s(:,:,jl), 'T', 1., ib_bdy )
+
+         DO jb = 1, idx%nblen(jgrd)
+            ji    = idx%nbi(jb,jgrd)
+            jj    = idx%nbj(jb,jgrd)
+            ! clem : condition on ice thickness depends on the ice velocity
+            ! if velocity is outward (strictly), then ice thickness, volume... must be equal to adjacent values 
+            IF ( u_ice(ji+1,jj  ) < 0. .AND. umask(ji-1,jj  ,1) == 0. ) THEN
+               ht_i(ji,jj,jl) = ht_i(ji+1,jj  ,jl)
+               a_i (ji,jj,jl) = a_i (ji+1,jj  ,jl)
+               ht_s(ji,jj,jl) = ht_s(ji+1,jj  ,jl)
+            ENDIF
+            IF ( u_ice(ji-1,jj  ) > 0. .AND. umask(ji+1,jj  ,1) == 0. ) THEN
+               ht_i(ji,jj,jl) = ht_i(ji-1,jj  ,jl)
+               a_i (ji,jj,jl) = a_i (ji-1,jj  ,jl)
+               ht_s(ji,jj,jl) = ht_s(ji-1,jj  ,jl)
+            ENDIF
+            IF ( v_ice(ji  ,jj+1) < 0. .AND. vmask(ji  ,jj-1,1) == 0. ) THEN
+               ht_i(ji,jj,jl) = ht_i(ji  ,jj+1,jl)
+               a_i (ji,jj,jl) = a_i (ji  ,jj+1,jl)
+               ht_s(ji,jj,jl) = ht_s(ji  ,jj+1,jl)
+            ENDIF
+            IF ( v_ice(ji  ,jj-1) > 0. .AND. vmask(ji  ,jj+1,1) == 0. ) THEN
+               ht_i(ji,jj,jl) = ht_i(ji  ,jj-1,jl)
+               a_i (ji,jj,jl) = a_i (ji  ,jj-1,jl)
+               ht_s(ji,jj,jl) = ht_s(ji  ,jj-1,jl)
+            ENDIF
+
+            zinda = 1.0 - MAX( 0.0_wp , SIGN ( 1.0_wp , - a_i(ji,jj,jl) ) ) ! 0 if no ice
+            ! --------------------
+            ! Ice and snow volumes
+            ! --------------------
+            v_i(ji,jj,jl) = ht_i(ji,jj,jl) * a_i(ji,jj,jl)
+            v_s(ji,jj,jl) = ht_s(ji,jj,jl) * a_i(ji,jj,jl)
+
+            ! -------------
+            ! Ice salinity
+            !---------------
+            sm_i(ji,jj,jl)   = zinda * bulk_sal  + ( 1.0 - zinda ) * s_i_min
+            smv_i(ji,jj,jl)  = MIN( sm_i(ji,jj,jl) , sss_m(ji,jj) ) * v_i(ji,jj,jl)
+            
+            !----------
+            ! Ice age
+            !----------
+            o_i(ji,jj,jl)    = zinda * 1.0   + ( 1.0 - zinda )
+            oa_i(ji,jj,jl)   = o_i(ji,jj,jl) * a_i(ji,jj,jl)
+            
+            !------------------------------
+            ! Sea ice surface temperature
+            !------------------------------
+            t_su(ji,jj,jl)   = zinda * 270.0 + ( 1.0 - zinda ) * t_bo(ji,jj)
+            
+            !------------------------------------
+            ! Snow temperature and heat content
+            !------------------------------------
+            DO jk = 1, nlay_s
+               t_s(ji,jj,jk,jl) = zinda * 270.00 + ( 1.0 - zinda ) * rtt
+               ! Snow energy of melting
+               e_s(ji,jj,jk,jl) = zinda * rhosn * ( cpic * ( rtt - t_s(ji,jj,jk,jl) ) + lfus )
+               ! Change dimensions
+               e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) / unit_fac
+               ! Multiply by volume, so that heat content in 10^9 Joules
+               e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * area(ji,jj) * &
+                    v_s(ji,jj,jl)  / nlay_s
+            END DO !jk
+            
+            !-----------------------------------------------
+            ! Ice salinities, temperature and heat content 
+            !-----------------------------------------------
+            DO jk = 1, nlay_i
+               t_i(ji,jj,jk,jl) = zinda * 270.00 + ( 1.0 - zinda ) * rtt 
+               s_i(ji,jj,jk,jl) = zinda * bulk_sal + ( 1.0 - zinda ) * s_i_min
+               ztmelts          = - tmut * s_i(ji,jj,jk,jl) + rtt !Melting temperature in K
+               
+               ! heat content per unit volume
+               e_i(ji,jj,jk,jl) = zinda * rhoic * &
+                    (   cpic    * ( ztmelts - t_i(ji,jj,jk,jl) ) &
+                    +   lfus    * ( 1.0 - (ztmelts-rtt) / MIN((t_i(ji,jj,jk,jl)-rtt),-epsi20) ) &
+                    - rcp      * ( ztmelts - rtt ) )
+               
+               ! Correct dimensions to avoid big values
+               e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) / unit_fac 
+               
+               ! Mutliply by ice volume, and divide by number of layers to get heat content in 10^9 J
+               e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * & 
+                    area(ji,jj) * a_i(ji,jj,jl) * ht_i(ji,jj,jl) / nlay_i
+            END DO ! jk
+
+         END DO !jb
+ 
+
+         CALL lbc_bdy_lnk(  a_i(:,:,jl), 'T', 1., ib_bdy )                                         ! lateral boundary conditions
+         CALL lbc_bdy_lnk( ht_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk( ht_s(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk(  v_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk(  v_s(:,:,jl), 'T', 1., ib_bdy )
+ 
+         CALL lbc_bdy_lnk( smv_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk(  sm_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk(  oa_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk(   o_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk(  t_su(:,:,jl), 'T', 1., ib_bdy )
+         DO jk = 1, nlay_s
+            CALL lbc_bdy_lnk(t_s(:,:,jk,jl), 'T', 1., ib_bdy )
+            CALL lbc_bdy_lnk(e_s(:,:,jk,jl), 'T', 1., ib_bdy )
+         END DO
+         DO jk = 1, nlay_i
+            CALL lbc_bdy_lnk(t_i(:,:,jk,jl), 'T', 1., ib_bdy )
+            CALL lbc_bdy_lnk(e_i(:,:,jk,jl), 'T', 1., ib_bdy )
+         END DO
+
+      END DO !jl
+    
+#endif
+      !      
+      !ENDIF !nit000/=0
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_ice_frs')
+      !
+   END SUBROUTINE bdy_ice_frs
+
+
+   SUBROUTINE bdy_ice_lim_dyn( kn, pvar1, pvar2, pvar12 )
+      !!------------------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_ice_lim_dyn  ***
+      !!                    
+      !! ** Purpose : Apply dynamics boundary conditions for sea-ice in the cas of unstructured open boundaries.
+      !!      kn = 1: u_ice and v_ice are equal to the value of the adjacent grid point if this latter is not ice free
+      !!              if adjacent grid point is ice free, then u_ice and v_ice are equal to ocean velocities
+      !!      kn = 2: the stress tensor is set to 0 (i.e. pvar1, pvar2, pvar12)
+      !!
+      !! 2013-06 : C. Rousset
+      !!------------------------------------------------------------------------------
+      !!
+      INTEGER,  INTENT( in    )                           ::   kn     ! set up of ice vel (kn=1) or stress tensor (kn=2)
+      REAL(wp), INTENT( inout ), DIMENSION(:,:), OPTIONAL ::   pvar1, pvar2, pvar12  ! stress tensor components (zs1,zs2,zs12) 
+      INTEGER  ::   jb, jgrd   ! dummy loop indices
+      INTEGER  ::   ji, jj             ! local scalar
+      INTEGER  ::   ib_bdy ! Loop index
+      REAL(wp) ::   zmsk1, zmsk2, zflag, zinda 
+     !!------------------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 ) CALL timing_start('bdy_ice_lim_dyn')
+      !
+      DO ib_bdy=1, nb_bdy
+      !
+      SELECT CASE( nn_ice_lim(ib_bdy) )
+
+      CASE(jp_none)
+         CYCLE
+
+      CASE(jp_frs)
+
+         IF ( kn == 1 ) THEN ! set up of u_ice and v_ice
+           
+            jgrd = 2      ! u velocity
+            DO jb = 1, idx_bdy(ib_bdy)%nblen(jgrd)
+               ji    = idx_bdy(ib_bdy)%nbi(jb,jgrd)
+               jj    = idx_bdy(ib_bdy)%nbj(jb,jgrd)
+               zflag = idx_bdy(ib_bdy)%flagu(jb)
+
+               IF ( ABS( zflag ) == 1. ) THEN  ! eastern and western boundaries
+                  ! one of the two zmsk is always 0 (because of zflag)
+                  zmsk1 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji+1,jj) ) ) ! 0 if no ice
+                  zmsk2 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji-1,jj) ) ) ! 0 if no ice
+                  
+                  ! u_ice = u_ice of the adjacent grid point except if this grid point is ice-free (then u_ice = u_oce)
+                  u_ice (ji,jj) = u_ice(ji+1,jj) * 0.5 * ABS( zflag + 1._wp ) * zmsk1 + &
+                     &            u_ice(ji-1,jj) * 0.5 * ABS( zflag - 1._wp ) * zmsk2 + &
+                     &            u_oce(ji  ,jj) * ( 1._wp - MIN( 1._wp, zmsk1 + zmsk2 ) )
+               ELSE                             ! everywhere else
+                  u_ice(ji,jj) = u_oce(ji,jj)
+               ENDIF
+               ! mask ice velocities
+               zinda = 1.0 - MAX( 0.0_wp, SIGN( 1.0_wp , - at_i(ji,jj) ) ) ! 0 if no ice
+               u_ice(ji,jj) = zinda * u_ice(ji,jj)
+
+            ENDDO
+            
+            jgrd = 3      ! v velocity
+            DO jb = 1, idx_bdy(ib_bdy)%nblen(jgrd)
+               ji    = idx_bdy(ib_bdy)%nbi(jb,jgrd)
+               jj    = idx_bdy(ib_bdy)%nbj(jb,jgrd)
+               zflag = idx_bdy(ib_bdy)%flagv(jb)
+              
+               IF ( ABS( zflag ) == 1. ) THEN  ! northern and southern boundaries
+                  ! one of the two zmsk is always 0 (because of zflag)
+                  zmsk1 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji,jj+1) ) ) ! 0 if no ice
+                  zmsk2 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji,jj-1) ) ) ! 0 if no ice
+                  
+                  ! u_ice = u_ice of the adjacent grid point except if this grid point is ice-free (then u_ice = u_oce)
+                  v_ice (ji,jj) = v_ice(ji,jj+1) * 0.5 * ABS( zflag + 1._wp ) * zmsk1 + &
+                     &            v_ice(ji,jj-1) * 0.5 * ABS( zflag - 1._wp ) * zmsk2 + &
+                     &            v_oce(ji,jj  ) * ( 1._wp - MIN( 1._wp, zmsk1 + zmsk2 ) )
+               ELSE                             ! everywhere else
+                  v_ice(ji,jj) = v_oce(ji,jj)
+               ENDIF
+               ! mask ice velocities
+               zinda = 1.0 - MAX( 0.0_wp, SIGN( 1.0_wp , - at_i(ji,jj) ) ) ! 0 if no ice
+               v_ice(ji,jj) = zinda * v_ice(ji,jj)
+
+            ENDDO
+            
+         CALL lbc_bdy_lnk( u_ice(:,:), 'U', -1., ib_bdy )
+         CALL lbc_bdy_lnk( v_ice(:,:), 'V', -1., ib_bdy )
+ 
+         ELSEIF ( kn == 2 ) THEN ! set up of stress tensor (not sure it works)
+         
+            jgrd = 1      ! T grid
+            DO jb = 1, idx_bdy(ib_bdy)%nblen(jgrd)
+               ji    = idx_bdy(ib_bdy)%nbi(jb,jgrd)
+               jj    = idx_bdy(ib_bdy)%nbj(jb,jgrd)
+
+               pvar1 (ji,jj) = 0._wp
+               pvar2 (ji,jj) = 0._wp
+               pvar12(ji,jj) = 0._wp
+
+            ENDDO
+
+         ENDIF
+
+      CASE DEFAULT
+         CALL ctl_stop( 'bdy_ice_lim_dyn : unrecognised option for open boundaries for ice fields' )
+      END SELECT
+
+      ENDDO
+
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_ice_lim_dyn')
+ 
+    END SUBROUTINE bdy_ice_lim_dyn
+
+#else
+   !!---------------------------------------------------------------------------------
+   !!   Default option                                                    Empty module
+   !!---------------------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE bdy_ice_lim( kt )      ! Empty routine
+      WRITE(*,*) 'bdy_ice_lim: You should not have seen this print! error?', kt
+   END SUBROUTINE bdy_ice_lim
+#endif
+
+   !!=================================================================================
+END MODULE bdyice_lim
Index: anches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim2.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim2.F90	(revision 4291)
+++ 	(revision )
@@ -1,113 +1,0 @@
-MODULE bdyice_lim2
-   !!======================================================================
-   !!                       ***  MODULE  bdyice_lim2  ***
-   !! Unstructured Open Boundary Cond. :  Open boundary conditions for sea-ice (LIM2)
-   !!======================================================================
-   !!  History :  3.3  !  2010-09 (D. Storkey)  Original code
-   !!             3.4  !  2011    (D. Storkey) rewrite in preparation for OBC-BDY merge
-   !!             3.5  !  2012    (S. Mocavero, I. Epicoco) Optimization of BDY communications
-   !!----------------------------------------------------------------------
-#if defined   key_bdy   &&   defined key_lim2
-   !!----------------------------------------------------------------------
-   !!   'key_bdy'            and                 Unstructured Open Boundary Conditions
-   !!   'key_lim2'                                                 LIM-2 sea ice model
-   !!----------------------------------------------------------------------
-   !!   bdy_ice_lim_2      : Application of open boundaries to ice
-   !!   bdy_ice_frs        : Application of Flow Relaxation Scheme
-   !!----------------------------------------------------------------------
-   USE timing          ! Timing
-   USE oce             ! ocean dynamics and tracers variables
-   USE ice_2           ! LIM_2 ice variables
-   USE dom_oce         ! ocean space and time domain variables 
-   USE bdy_oce         ! ocean open boundary conditions
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE in_out_manager  ! write to numout file
-   USE lib_mpp         ! distributed memory computing
-   
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   bdy_ice_lim_2    ! routine called in sbcmod
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE bdy_ice_lim_2( kt )
-      !!----------------------------------------------------------------------
-      !!                  ***  SUBROUTINE bdy_ice_lim_2  ***
-      !!
-      !! ** Purpose : - Apply open boundary conditions for ice (LIM2)
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) :: kt     ! Main time step counter
-      !!
-      INTEGER               :: ib_bdy ! Loop index
-
-      DO ib_bdy=1, nb_bdy
-
-         SELECT CASE( nn_ice_lim2(ib_bdy) )
-         CASE(jp_none)
-            CYCLE
-         CASE(jp_frs)
-            CALL bdy_ice_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy )
-         CASE DEFAULT
-            CALL ctl_stop( 'bdy_ice_lim_2 : unrecognised option for open boundaries for ice fields' )
-         END SELECT
-      ENDDO
-
-   END SUBROUTINE bdy_ice_lim_2
-
-   SUBROUTINE bdy_ice_frs( idx, dta, ib_bdy )
-      !!------------------------------------------------------------------------------
-      !!                 ***  SUBROUTINE bdy_ice_frs  ***
-      !!                    
-      !! ** Purpose : Apply the Flow Relaxation Scheme for sea-ice fields in the case 
-      !!              of unstructured open boundaries. Currently only tested for LIM2.
-      !! 
-      !! Reference : Engedahl H., 1995: Use of the flow relaxation scheme in a three-
-      !!             dimensional baroclinic ocean model with realistic topography. Tellus, 365-382.
-      !!------------------------------------------------------------------------------
-      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
-      INTEGER,         INTENT(in) ::   ib_bdy  ! BDY set index
-      !!
-      INTEGER  ::   jb, jgrd   ! dummy loop indices
-      INTEGER  ::   ii, ij         ! local scalar
-      REAL(wp) ::   zwgt, zwgt1    ! local scalar
-      !!------------------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 ) CALL timing_start('bdy_ice_frs')
-      !
-      jgrd = 1      ! Everything is at T-points here
-      !
-      DO jb = 1, idx%nblen(jgrd)
-            ii    = idx%nbi(jb,jgrd)
-            ij    = idx%nbj(jb,jgrd)
-            zwgt  = idx%nbw(jb,jgrd)
-            zwgt1 = 1.e0 - idx%nbw(jb,jgrd)
-            frld (ii,ij) = ( frld (ii,ij) * zwgt1 + dta%frld (jb) * zwgt ) * tmask(ii,ij,1)     ! Leads fraction 
-            hicif(ii,ij) = ( hicif(ii,ij) * zwgt1 + dta%hicif(jb) * zwgt ) * tmask(ii,ij,1)     ! Ice depth 
-            hsnif(ii,ij) = ( hsnif(ii,ij) * zwgt1 + dta%hsnif(jb) * zwgt ) * tmask(ii,ij,1)     ! Snow depth
-      END DO 
-      CALL lbc_bdy_lnk( frld, 'T', 1., ib_bdy )                                         ! lateral boundary conditions
-      CALL lbc_bdy_lnk( hicif, 'T', 1., ib_bdy )   ;   CALL lbc_bdy_lnk( hsnif, 'T', 1., ib_bdy )
-      !      
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_ice_frs')
-      !
-   END SUBROUTINE bdy_ice_frs
-#else
-   !!---------------------------------------------------------------------------------
-   !!   Default option                                                    Empty module
-   !!---------------------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE bdy_ice_lim_2( kt )      ! Empty routine
-      WRITE(*,*) 'bdy_ice_frs_lim_2: You should not have seen this print! error?', kt
-   END SUBROUTINE bdy_ice_lim_2
-#endif
-
-   !!=================================================================================
-END MODULE bdyice_lim2
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 4292)
@@ -21,4 +21,5 @@
    !!   bdy_init       : Initialization of unstructured open boundaries
    !!----------------------------------------------------------------------
+   USE wrk_nemo        ! Memory Allocation
    USE timing          ! Timing
    USE oce             ! ocean dynamics and tracers variables
@@ -79,6 +80,8 @@
       INTEGER  ::   jpbdtau, jpbdtas                       !   -       -
       INTEGER  ::   ib_bdy1, ib_bdy2, ib1, ib2             !   -       -
+      INTEGER  ::   i_offset, j_offset                     !   -       -
       INTEGER, POINTER  ::  nbi, nbj, nbr                  ! short cuts
-      REAL   , POINTER  ::  flagu, flagv                   !    -   -
+      REAL(wp), POINTER  ::  flagu, flagv                  !    -   -
+      REAL(wp), POINTER, DIMENSION(:,:)       ::   pmask    ! pointer to 2D mask fields
       REAL(wp) ::   zefl, zwfl, znfl, zsfl                 ! local scalars
       INTEGER, DIMENSION (2)                  ::   kdimsz
@@ -90,12 +93,13 @@
       INTEGER :: com_east_b, com_west_b, com_south_b, com_north_b  ! Flags for boundaries receiving
       INTEGER :: iw_b(4), ie_b(4), is_b(4), in_b(4)                ! Arrays for neighbours coordinates
+      REAL(wp), POINTER, DIMENSION(:,:)       ::   zfmask  ! temporary fmask array excluding coastal boundary condition (shlat)
 
       !!
-      NAMELIST/nambdy/ nb_bdy, ln_coords_file, cn_coords_file,             &
-         &             ln_mask_file, cn_mask_file, nn_dyn2d, nn_dyn2d_dta, &
-         &             nn_dyn3d, nn_dyn3d_dta, nn_tra, nn_tra_dta,         &  
-         &             ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp,              &
-#if defined key_lim2
-         &             nn_ice_lim2, nn_ice_lim2_dta,                       &
+      NAMELIST/nambdy/ nb_bdy, ln_coords_file, cn_coords_file,                 &
+         &             ln_mask_file, cn_mask_file, cn_dyn2d, nn_dyn2d_dta,     &
+         &             cn_dyn3d, nn_dyn3d_dta, cn_tra, nn_tra_dta,             &  
+         &             ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp, rn_time_dmp_out, &
+#if ( defined key_lim2 || defined key_lim3 )
+         &             cn_ice_lim, nn_ice_lim_dta,                           &
 #endif
          &             ln_vol, nn_volctl, nn_rimwidth
@@ -156,11 +160,33 @@
 
         IF(lwp) WRITE(numout,*) 'Boundary conditions for barotropic solution:  '
-        SELECT CASE( nn_dyn2d(ib_bdy) )                  
-          CASE(jp_none)         ;   IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-          CASE(jp_frs)          ;   IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-          CASE(jp_flather)      ;   IF(lwp) WRITE(numout,*) '      Flather radiation condition'
-          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_dyn2d' )
+        SELECT CASE( cn_dyn2d(ib_bdy) )                  
+          CASE('none')         
+             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
+             dta_bdy(ib_bdy)%ll_ssh = .false.
+             dta_bdy(ib_bdy)%ll_u2d = .false.
+             dta_bdy(ib_bdy)%ll_v2d = .false.
+          CASE('frs')          
+             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
+             dta_bdy(ib_bdy)%ll_ssh = .false.
+             dta_bdy(ib_bdy)%ll_u2d = .true.
+             dta_bdy(ib_bdy)%ll_v2d = .true.
+          CASE('flather')      
+             IF(lwp) WRITE(numout,*) '      Flather radiation condition'
+             dta_bdy(ib_bdy)%ll_ssh = .true.
+             dta_bdy(ib_bdy)%ll_u2d = .true.
+             dta_bdy(ib_bdy)%ll_v2d = .true.
+          CASE('orlanski')     
+             IF(lwp) WRITE(numout,*) '      Orlanski (fully oblique) radiation condition with adaptive nudging'
+             dta_bdy(ib_bdy)%ll_ssh = .false.
+             dta_bdy(ib_bdy)%ll_u2d = .true.
+             dta_bdy(ib_bdy)%ll_v2d = .true.
+          CASE('orlanski_npo') 
+             IF(lwp) WRITE(numout,*) '      Orlanski (NPO) radiation condition with adaptive nudging'
+             dta_bdy(ib_bdy)%ll_ssh = .false.
+             dta_bdy(ib_bdy)%ll_u2d = .true.
+             dta_bdy(ib_bdy)%ll_v2d = .true.
+          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_dyn2d' )
         END SELECT
-        IF( nn_dyn2d(ib_bdy) .gt. 0 ) THEN
+        IF( cn_dyn2d(ib_bdy) /= 'none' ) THEN
            SELECT CASE( nn_dyn2d_dta(ib_bdy) )                   ! 
               CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
@@ -177,12 +203,32 @@
 
         IF(lwp) WRITE(numout,*) 'Boundary conditions for baroclinic velocities:  '
-        SELECT CASE( nn_dyn3d(ib_bdy) )                  
-          CASE(jp_none)  ;   IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-          CASE(jp_frs)   ;   IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-          CASE( 2 )      ;   IF(lwp) WRITE(numout,*) '      Specified value'
-          CASE( 3 )      ;   IF(lwp) WRITE(numout,*) '      Zero baroclinic velocities (runoff case)'
-          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_dyn3d' )
+        SELECT CASE( cn_dyn3d(ib_bdy) )                  
+          CASE('none')
+             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
+             dta_bdy(ib_bdy)%ll_u3d = .false.
+             dta_bdy(ib_bdy)%ll_v3d = .false.
+          CASE('frs')       
+             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
+             dta_bdy(ib_bdy)%ll_u3d = .true.
+             dta_bdy(ib_bdy)%ll_v3d = .true.
+          CASE('specified')
+             IF(lwp) WRITE(numout,*) '      Specified value'
+             dta_bdy(ib_bdy)%ll_u3d = .true.
+             dta_bdy(ib_bdy)%ll_v3d = .true.
+          CASE('zero')
+             IF(lwp) WRITE(numout,*) '      Zero baroclinic velocities (runoff case)'
+             dta_bdy(ib_bdy)%ll_u3d = .false.
+             dta_bdy(ib_bdy)%ll_v3d = .false.
+          CASE('orlanski')
+             IF(lwp) WRITE(numout,*) '      Orlanski (fully oblique) radiation condition with adaptive nudging'
+             dta_bdy(ib_bdy)%ll_u3d = .true.
+             dta_bdy(ib_bdy)%ll_v3d = .true.
+          CASE('orlanski_npo')
+             IF(lwp) WRITE(numout,*) '      Orlanski (NPO) radiation condition with adaptive nudging'
+             dta_bdy(ib_bdy)%ll_u3d = .true.
+             dta_bdy(ib_bdy)%ll_v3d = .true.
+          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_dyn3d' )
         END SELECT
-        IF( nn_dyn3d(ib_bdy) .gt. 0 ) THEN
+        IF( cn_dyn3d(ib_bdy) /= 'none' ) THEN
            SELECT CASE( nn_dyn3d_dta(ib_bdy) )                   ! 
               CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
@@ -193,8 +239,8 @@
 
         IF ( ln_dyn3d_dmp(ib_bdy) ) THEN
-           IF ( nn_dyn3d(ib_bdy).EQ.0 ) THEN
+           IF ( cn_dyn3d(ib_bdy) == 'none' ) THEN
               IF(lwp) WRITE(numout,*) 'No open boundary condition for baroclinic velocities: ln_dyn3d_dmp is set to .false.'
               ln_dyn3d_dmp(ib_bdy)=.false.
-           ELSEIF ( nn_dyn3d(ib_bdy).EQ.1 ) THEN
+           ELSEIF ( cn_dyn3d(ib_bdy) == 'frs' ) THEN
               CALL ctl_stop( 'Use FRS OR relaxation' )
            ELSE
@@ -202,4 +248,6 @@
               IF(lwp) WRITE(numout,*) '      Damping time scale: ',rn_time_dmp(ib_bdy),' days'
               IF((lwp).AND.rn_time_dmp(ib_bdy)<0) CALL ctl_stop( 'Time scale must be positive' )
+              dta_bdy(ib_bdy)%ll_u3d = .true.
+              dta_bdy(ib_bdy)%ll_v3d = .true.
            ENDIF
         ELSE
@@ -209,13 +257,36 @@
 
         IF(lwp) WRITE(numout,*) 'Boundary conditions for temperature and salinity:  '
-        SELECT CASE( nn_tra(ib_bdy) )                  
-          CASE(jp_none)  ;   IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-          CASE(jp_frs)   ;   IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-          CASE( 2 )      ;   IF(lwp) WRITE(numout,*) '      Specified value'
-          CASE( 3 )      ;   IF(lwp) WRITE(numout,*) '      Neumann conditions'
-          CASE( 4 )      ;   IF(lwp) WRITE(numout,*) '      Runoff conditions : Neumann for T and specified to 0.1 for salinity'
-          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_tra' )
+        SELECT CASE( cn_tra(ib_bdy) )                  
+          CASE('none')
+             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
+             dta_bdy(ib_bdy)%ll_tem = .false.
+             dta_bdy(ib_bdy)%ll_sal = .false.
+          CASE('frs')
+             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
+             dta_bdy(ib_bdy)%ll_tem = .true.
+             dta_bdy(ib_bdy)%ll_sal = .true.
+          CASE('specified')
+             IF(lwp) WRITE(numout,*) '      Specified value'
+             dta_bdy(ib_bdy)%ll_tem = .true.
+             dta_bdy(ib_bdy)%ll_sal = .true.
+          CASE('neumann')
+             IF(lwp) WRITE(numout,*) '      Neumann conditions'
+             dta_bdy(ib_bdy)%ll_tem = .false.
+             dta_bdy(ib_bdy)%ll_sal = .false.
+          CASE('runoff')
+             IF(lwp) WRITE(numout,*) '      Runoff conditions : Neumann for T and specified to 0.1 for salinity'
+             dta_bdy(ib_bdy)%ll_tem = .false.
+             dta_bdy(ib_bdy)%ll_sal = .false.
+          CASE('orlanski')
+             IF(lwp) WRITE(numout,*) '      Orlanski (fully oblique) radiation condition with adaptive nudging'
+             dta_bdy(ib_bdy)%ll_tem = .true.
+             dta_bdy(ib_bdy)%ll_sal = .true.
+          CASE('orlanski_npo')
+             IF(lwp) WRITE(numout,*) '      Orlanski (NPO) radiation condition with adaptive nudging'
+             dta_bdy(ib_bdy)%ll_tem = .true.
+             dta_bdy(ib_bdy)%ll_sal = .true.
+          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_tra' )
         END SELECT
-        IF( nn_tra(ib_bdy) .gt. 0 ) THEN
+        IF( cn_tra(ib_bdy) /= 'none' ) THEN
            SELECT CASE( nn_tra_dta(ib_bdy) )                   ! 
               CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
@@ -226,13 +297,16 @@
 
         IF ( ln_tra_dmp(ib_bdy) ) THEN
-           IF ( nn_tra(ib_bdy).EQ.0 ) THEN
+           IF ( cn_tra(ib_bdy) == 'none' ) THEN
               IF(lwp) WRITE(numout,*) 'No open boundary condition for tracers: ln_tra_dmp is set to .false.'
               ln_tra_dmp(ib_bdy)=.false.
-           ELSEIF ( nn_tra(ib_bdy).EQ.1 ) THEN
+           ELSEIF ( cn_tra(ib_bdy) == 'frs' ) THEN
               CALL ctl_stop( 'Use FRS OR relaxation' )
            ELSE
               IF(lwp) WRITE(numout,*) '      + T/S relaxation zone'
               IF(lwp) WRITE(numout,*) '      Damping time scale: ',rn_time_dmp(ib_bdy),' days'
+              IF(lwp) WRITE(numout,*) '      Outflow damping time scale: ',rn_time_dmp_out(ib_bdy),' days'
               IF((lwp).AND.rn_time_dmp(ib_bdy)<0) CALL ctl_stop( 'Time scale must be positive' )
+              dta_bdy(ib_bdy)%ll_tem = .true.
+              dta_bdy(ib_bdy)%ll_sal = .true.
            ENDIF
         ELSE
@@ -243,14 +317,45 @@
 #if defined key_lim2
         IF(lwp) WRITE(numout,*) 'Boundary conditions for sea ice:  '
-        SELECT CASE( nn_ice_lim2(ib_bdy) )                  
-          CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-          CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_tra' )
+        SELECT CASE( cn_ice_lim(ib_bdy) )                  
+          CASE('none')
+             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
+             dta_bdy(ib_bdy)%ll_frld  = .false.
+             dta_bdy(ib_bdy)%ll_hicif = .false.
+             dta_bdy(ib_bdy)%ll_hsnif = .false.
+          CASE('frs')
+             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
+             dta_bdy(ib_bdy)%ll_frld  = .true.
+             dta_bdy(ib_bdy)%ll_hicif = .true.
+             dta_bdy(ib_bdy)%ll_hsnif = .true.
+          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_ice_lim' )
         END SELECT
-        IF( nn_ice_lim2(ib_bdy) .gt. 0 ) THEN 
-           SELECT CASE( nn_ice_lim2_dta(ib_bdy) )                   ! 
+        IF( cn_ice_lim(ib_bdy) /= 'none' ) THEN 
+           SELECT CASE( nn_ice_lim_dta(ib_bdy) )                   ! 
               CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
               CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
-              CASE DEFAULT   ;   CALL ctl_stop( 'nn_ice_lim2_dta must be 0 or 1' )
+              CASE DEFAULT   ;   CALL ctl_stop( 'nn_ice_lim_dta must be 0 or 1' )
+           END SELECT
+        ENDIF
+        IF(lwp) WRITE(numout,*)
+#elif defined key_lim3
+        IF(lwp) WRITE(numout,*) 'Boundary conditions for sea ice:  '
+        SELECT CASE( cn_ice_lim(ib_bdy) )                  
+          CASE('none')
+             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
+             dta_bdy(ib_bdy)%ll_a_i  = .false.
+             dta_bdy(ib_bdy)%ll_ht_i = .false.
+             dta_bdy(ib_bdy)%ll_ht_s = .false.
+          CASE('frs')
+             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
+             dta_bdy(ib_bdy)%ll_a_i  = .true.
+             dta_bdy(ib_bdy)%ll_ht_i = .true.
+             dta_bdy(ib_bdy)%ll_ht_s = .true.
+          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_ice_lim' )
+        END SELECT
+        IF( cn_ice_lim(ib_bdy) /= 'none' ) THEN 
+           SELECT CASE( nn_ice_lim_dta(ib_bdy) )                   ! 
+              CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
+              CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
+              CASE DEFAULT   ;   CALL ctl_stop( 'nn_ice_lim_dta must be 0 or 1' )
            END SELECT
         ENDIF
@@ -740,8 +845,6 @@
                IF(lwp) THEN         ! Since all procs read global data only need to do this check on one proc...
                   IF( nbrdta(ib,igrd,ib_bdy) < nbrdta(ibm1,igrd,ib_bdy) ) THEN
-                     CALL ctl_stop('bdy_init : ERROR : boundary data in file  &
-                                    must be defined in order of distance from edge nbr.', &
-                                   'A utility for re-ordering boundary coordinates and data &
-                                    files exists in the TOOLS/OBC directory')
+                     CALL ctl_stop('bdy_init : ERROR : boundary data in file must be defined in order of distance from edge nbr.', &
+                                   'A utility for re-ordering boundary coordinates and data files exists in the TOOLS/OBC directory')
                   ENDIF    
                ENDIF
@@ -766,8 +869,9 @@
          ALLOCATE( idx_bdy(ib_bdy)%nbr(ilen1,jpbgrd) )
          ALLOCATE( idx_bdy(ib_bdy)%nbd(ilen1,jpbgrd) )
+         ALLOCATE( idx_bdy(ib_bdy)%nbdout(ilen1,jpbgrd) )
          ALLOCATE( idx_bdy(ib_bdy)%nbmap(ilen1,jpbgrd) )
          ALLOCATE( idx_bdy(ib_bdy)%nbw(ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%flagu(ilen1) )
-         ALLOCATE( idx_bdy(ib_bdy)%flagv(ilen1) )
+         ALLOCATE( idx_bdy(ib_bdy)%flagu(ilen1,jpbgrd) )
+         ALLOCATE( idx_bdy(ib_bdy)%flagv(ilen1,jpbgrd) )
 
          ! Dispatch mapping indices and discrete distances on each processor
@@ -937,4 +1041,5 @@
             ENDDO
          ENDDO 
+
          ! definition of the i- and j- direction local boundaries arrays
          ! used for sending the boudaries
@@ -990,4 +1095,6 @@
                nbr => idx_bdy(ib_bdy)%nbr(ib,igrd)
                idx_bdy(ib_bdy)%nbd(ib,igrd) = 1. / ( rn_time_dmp(ib_bdy) * rday ) & 
+               & *(FLOAT(nn_rimwidth(ib_bdy)+1-nbr)/FLOAT(nn_rimwidth(ib_bdy)))**2.   ! quadratic
+               idx_bdy(ib_bdy)%nbdout(ib,igrd) = 1. / ( rn_time_dmp_out(ib_bdy) * rday ) & 
                & *(FLOAT(nn_rimwidth(ib_bdy)+1-nbr)/FLOAT(nn_rimwidth(ib_bdy)))**2.   ! quadratic
             END DO
@@ -1092,5 +1199,16 @@
       ENDDO
 
+      ! For the flagu/flagv calculation below we require a version of fmask without
+      ! the land boundary condition (shlat) included:
+      CALL wrk_alloc(jpi,jpj,zfmask) 
+      DO ij = 2, jpjm1
+         DO ii = 2, jpim1
+            zfmask(ii,ij) = tmask(ii,ij  ,1) * tmask(ii+1,ij  ,1)   &
+           &              * tmask(ii,ij+1,1) * tmask(ii+1,ij+1,1)
+         END DO      
+      END DO
+
       ! Lateral boundary conditions
+      CALL lbc_lnk( zfmask       , 'F', 1. )
       CALL lbc_lnk( fmask        , 'F', 1. )   ;   CALL lbc_lnk( bdytmask(:,:), 'T', 1. )
       CALL lbc_lnk( bdyumask(:,:), 'U', 1. )   ;   CALL lbc_lnk( bdyvmask(:,:), 'V', 1. )
@@ -1098,52 +1216,91 @@
       DO ib_bdy = 1, nb_bdy       ! Indices and directions of rim velocity components
 
-         idx_bdy(ib_bdy)%flagu(:) = 0.e0
-         idx_bdy(ib_bdy)%flagv(:) = 0.e0
+         idx_bdy(ib_bdy)%flagu(:,:) = 0.e0
+         idx_bdy(ib_bdy)%flagv(:,:) = 0.e0
          icount = 0 
 
-         !flagu = -1 : u component is normal to the dynamical boundary but its direction is outward
-         !flagu =  0 : u is tangential
-         !flagu =  1 : u is normal to the boundary and is direction is inward
+         ! Calculate relationship of U direction to the local orientation of the boundary
+         ! flagu = -1 : u component is normal to the dynamical boundary and its direction is outward
+         ! flagu =  0 : u is tangential
+         ! flagu =  1 : u is normal to the boundary and is direction is inward
   
-         igrd = 2      ! u-component 
-         DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)  
-            nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
-            nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
-            zefl = bdytmask(nbi  ,nbj)
-            zwfl = bdytmask(nbi+1,nbj)
-            IF( zefl + zwfl == 2 ) THEN
-               icount = icount + 1
-            ELSE
-               idx_bdy(ib_bdy)%flagu(ib)=-zefl+zwfl
-            ENDIF
+         DO igrd = 1,jpbgrd 
+            SELECT CASE( igrd )
+               CASE( 1 )
+                  pmask => umask(:,:,1)
+                  i_offset = 0
+               CASE( 2 ) 
+                  pmask => bdytmask
+                  i_offset = 1
+               CASE( 3 ) 
+                  pmask => zfmask(:,:)
+                  i_offset = 0
+            END SELECT 
+            icount = 0
+            DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)  
+               nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
+               nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
+               zefl = pmask(nbi+i_offset-1,nbj)
+               zwfl = pmask(nbi+i_offset,nbj)
+               ! This error check only works if you are using the bdyXmask arrays
+               IF( i_offset == 1 .and. zefl + zwfl == 2 ) THEN
+                  icount = icount + 1
+                  IF(lwp) WRITE(numout,*) 'Problem with igrd = ',igrd,' at (global) nbi, nbj : ',mig(nbi),mjg(nbj)
+               ELSE
+                  idx_bdy(ib_bdy)%flagu(ib,igrd) = -zefl + zwfl
+               ENDIF
+            END DO
+            IF( icount /= 0 ) THEN
+               IF(lwp) WRITE(numout,*)
+               IF(lwp) WRITE(numout,*) ' E R R O R : Some ',cgrid(igrd),' grid points,',   &
+                  ' are not boundary points (flagu calculation). Check nbi, nbj, indices for boundary set ',ib_bdy
+               IF(lwp) WRITE(numout,*) ' ========== '
+               IF(lwp) WRITE(numout,*)
+               nstop = nstop + 1
+            ENDIF 
          END DO
 
-         !flagv = -1 : u component is normal to the dynamical boundary but its direction is outward
-         !flagv =  0 : u is tangential
-         !flagv =  1 : u is normal to the boundary and is direction is inward
-
-         igrd = 3      ! v-component
-         DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)  
-            nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
-            nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
-            znfl = bdytmask(nbi,nbj  )
-            zsfl = bdytmask(nbi,nbj+1)
-            IF( znfl + zsfl == 2 ) THEN
-               icount = icount + 1
-            ELSE
-               idx_bdy(ib_bdy)%flagv(ib) = -znfl + zsfl
-            END IF
+         ! Calculate relationship of V direction to the local orientation of the boundary
+         ! flagv = -1 : v component is normal to the dynamical boundary but its direction is outward
+         ! flagv =  0 : v is tangential
+         ! flagv =  1 : v is normal to the boundary and is direction is inward
+
+         DO igrd = 1,jpbgrd 
+            SELECT CASE( igrd )
+               CASE( 1 )
+                  pmask => vmask(:,:,1)
+                  j_offset = 0
+               CASE( 2 )
+                  pmask => zfmask(:,:)
+                  j_offset = 0
+               CASE( 3 )
+                  pmask => bdytmask
+                  j_offset = 1
+            END SELECT 
+            icount = 0
+            DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)  
+               nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
+               nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
+               znfl = pmask(nbi,nbj+j_offset-1  )
+               zsfl = pmask(nbi,nbj+j_offset)
+               ! This error check only works if you are using the bdyXmask arrays
+               IF( j_offset == 1 .and. znfl + zsfl == 2 ) THEN
+                  IF(lwp) WRITE(numout,*) 'Problem with igrd = ',igrd,' at (global) nbi, nbj : ',mig(nbi),mjg(nbj)
+                  icount = icount + 1
+               ELSE
+                  idx_bdy(ib_bdy)%flagv(ib,igrd) = -znfl + zsfl
+               END IF
+            END DO
+            IF( icount /= 0 ) THEN
+               IF(lwp) WRITE(numout,*)
+               IF(lwp) WRITE(numout,*) ' E R R O R : Some ',cgrid(igrd),' grid points,',   &
+                  ' are not boundary points (flagv calculation). Check nbi, nbj, indices for boundary set ',ib_bdy
+               IF(lwp) WRITE(numout,*) ' ========== '
+               IF(lwp) WRITE(numout,*)
+               nstop = nstop + 1
+            ENDIF 
          END DO
 
-         IF( icount /= 0 ) THEN
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) ' E R R O R : Some data velocity points,',   &
-               ' are not boundary points. Check nbi, nbj, indices for boundary set ',ib_bdy
-            IF(lwp) WRITE(numout,*) ' ========== '
-            IF(lwp) WRITE(numout,*)
-            nstop = nstop + 1
-         ENDIF 
-    
-      ENDDO
+      END DO
 
       ! Compute total lateral surface for volume correction:
@@ -1157,5 +1314,5 @@
                nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
                nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
-               flagu => idx_bdy(ib_bdy)%flagu(ib)
+               flagu => idx_bdy(ib_bdy)%flagu(ib,igrd)
                bdysurftot = bdysurftot + hu     (nbi  , nbj)                           &
                   &                    * e2u    (nbi  , nbj) * ABS( flagu ) &
@@ -1170,5 +1327,5 @@
                nbi => idx_bdy(ib_bdy)%nbi(ib,igrd)
                nbj => idx_bdy(ib_bdy)%nbj(ib,igrd)
-               flagv => idx_bdy(ib_bdy)%flagv(ib)
+               flagv => idx_bdy(ib_bdy)%flagv(ib,igrd)
                bdysurftot = bdysurftot + hv     (nbi, nbj  )                           &
                   &                    * e1v    (nbi, nbj  ) * ABS( flagv ) &
@@ -1186,4 +1343,6 @@
          DEALLOCATE(nbidta, nbjdta, nbrdta)
       ENDIF
+
+      CALL wrk_dealloc(jpi,jpj,zfmask) 
 
       IF( nn_timing == 1 ) CALL timing_stop('bdy_init')
@@ -1580,7 +1739,7 @@
       itest = 0
 
-      IF (nn_dyn2d(ib1)/=nn_dyn2d(ib2)) itest = itest + 1
-      IF (nn_dyn3d(ib1)/=nn_dyn3d(ib2)) itest = itest + 1
-      IF (nn_tra(ib1)/=nn_tra(ib2)) itest = itest + 1
+      IF (cn_dyn2d(ib1)/=cn_dyn2d(ib2)) itest = itest + 1
+      IF (cn_dyn3d(ib1)/=cn_dyn3d(ib2)) itest = itest + 1
+      IF (cn_tra(ib1)/=cn_tra(ib2)) itest = itest + 1
       !
       IF (nn_dyn2d_dta(ib1)/=nn_dyn2d_dta(ib2)) itest = itest + 1
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdylib.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdylib.F90	(revision 4292)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdylib.F90	(revision 4292)
@@ -0,0 +1,371 @@
+MODULE bdylib
+   !!======================================================================
+   !!                       ***  MODULE  bdylib  ***
+   !! Unstructured Open Boundary Cond. :  Library module of generic boundary algorithms.
+   !!======================================================================
+   !! History :  3.6  !  2013     (D. Storkey) new module
+   !!----------------------------------------------------------------------
+#if defined key_bdy 
+   !!----------------------------------------------------------------------
+   !!   'key_bdy' :                    Unstructured Open Boundary Condition
+   !!----------------------------------------------------------------------
+   !!   bdy_orlanski_2d
+   !!   bdy_orlanski_3d
+   !!----------------------------------------------------------------------
+   USE timing          ! Timing
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE bdy_oce         ! ocean open boundary conditions
+   USE phycst          ! physical constants
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  !
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   bdy_orlanski_2d     ! routine called where?
+   PUBLIC   bdy_orlanski_3d     ! routine called where?
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: bdydyn.F90 2528 2010-12-27 17:33:53Z rblod $ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE bdy_orlanski_2d( idx, igrd, phib, phia, phi_ext, ll_npo )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_orlanski_2d  ***
+      !!             
+      !!              - Apply Orlanski radiation condition adaptively to 2D fields:
+      !!                  - radiation plus weak nudging at outflow points
+      !!                  - no radiation and strong nudging at inflow points
+      !! 
+      !!
+      !! References:  Marchesiello, McWilliams and Shchepetkin, Ocean Modelling vol. 3 (2001)    
+      !!----------------------------------------------------------------------
+      TYPE(OBC_INDEX),            INTENT(in)     ::   idx      ! BDY indices
+      INTEGER,                    INTENT(in)     ::   igrd     ! grid index
+      REAL(wp), DIMENSION(:,:),   INTENT(in)     ::   phib     ! model before 2D field
+      REAL(wp), DIMENSION(:,:),   INTENT(inout)  ::   phia     ! model after 2D field (to be updated)
+      REAL(wp), DIMENSION(:),     INTENT(in)     ::   phi_ext  ! external forcing data
+      LOGICAL,                    INTENT(in)     ::   ll_npo   ! switch for NPO version
+
+      INTEGER  ::   jb                                     ! dummy loop indices
+      INTEGER  ::   ii, ij, iibm1, iibm2, ijbm1, ijbm2     ! 2D addresses
+      INTEGER  ::   iijm1, iijp1, ijjm1, ijjp1             ! 2D addresses
+      INTEGER  ::   iibm1jp1, iibm1jm1, ijbm1jp1, ijbm1jm1 ! 2D addresses
+      INTEGER  ::   ii_offset, ij_offset                   ! offsets for mask indices
+      INTEGER  ::   flagu, flagv                           ! short cuts
+      REAL(wp) ::   zmask_x, zmask_y1, zmask_y2
+      REAL(wp) ::   zex1, zex2, zey, zey1, zey2
+      REAL(wp) ::   zdt, zdx, zdy, znor2, zrx, zry         ! intermediate calculations
+      REAL(wp) ::   zout, zwgt, zdy_centred
+      REAL(wp) ::   zdy_1, zdy_2, zsign_ups
+      REAL(wp), PARAMETER :: zepsilon = 1.e-30                 ! local small value
+      REAL(wp), POINTER, DIMENSION(:,:)          :: pmask      ! land/sea mask for field
+      REAL(wp), POINTER, DIMENSION(:,:)          :: pmask_xdif ! land/sea mask for x-derivatives
+      REAL(wp), POINTER, DIMENSION(:,:)          :: pmask_ydif ! land/sea mask for y-derivatives
+      REAL(wp), POINTER, DIMENSION(:,:)          :: pe_xdif    ! scale factors for x-derivatives
+      REAL(wp), POINTER, DIMENSION(:,:)          :: pe_ydif    ! scale factors for y-derivatives
+      !!----------------------------------------------------------------------
+
+      IF( nn_timing == 1 ) CALL timing_start('bdy_orlanski_2d')
+
+      ! ----------------------------------!
+      ! Orlanski boundary conditions     :!
+      ! ----------------------------------! 
+     
+      SELECT CASE(igrd)
+         CASE(1)
+            pmask => tmask(:,:,1)
+            pmask_xdif => umask(:,:,1)
+            pmask_ydif => vmask(:,:,1)
+            pe_xdif => e1u(:,:)
+            pe_ydif => e2v(:,:)
+            ii_offset = 0
+            ij_offset = 0
+         CASE(2)
+            pmask => umask(:,:,1)
+            pmask_xdif => tmask(:,:,1)
+            pmask_ydif => fmask(:,:,1)
+            pe_xdif => e1t(:,:)
+            pe_ydif => e2f(:,:)
+            ii_offset = 1
+            ij_offset = 0
+         CASE(3)
+            pmask => vmask(:,:,1)
+            pmask_xdif => fmask(:,:,1)
+            pmask_ydif => tmask(:,:,1)
+            pe_xdif => e1f(:,:)
+            pe_ydif => e2t(:,:)
+            ii_offset = 0
+            ij_offset = 1
+         CASE DEFAULT ;   CALL ctl_stop( 'unrecognised value for igrd in bdy_orlanksi_2d' )
+      END SELECT
+      !
+      DO jb = 1, idx%nblenrim(igrd)
+         ii  = idx%nbi(jb,igrd)
+         ij  = idx%nbj(jb,igrd) 
+         flagu = int( idx%flagu(jb,igrd) )
+         flagv = int( idx%flagv(jb,igrd) )
+         !
+         ! Calculate positions of b-1 and b-2 points for this rim point
+         ! also (b-1,j-1) and (b-1,j+1) points
+         iibm1 = ii + flagu ; iibm2 = ii + 2*flagu 
+         ijbm1 = ij + flagv ; ijbm2 = ij + 2*flagv
+          !
+         iijm1 = ii - abs(flagv) ; iijp1 = ii + abs(flagv) 
+         ijjm1 = ij - abs(flagu) ; ijjp1 = ij + abs(flagu)
+         !
+         iibm1jm1 = ii + flagu - abs(flagv) ; iibm1jp1 = ii + flagu + abs(flagv) 
+         ijbm1jm1 = ij + flagv - abs(flagu) ; ijbm1jp1 = ij + flagv + abs(flagu) 
+         !
+         ! Calculate scale factors for calculation of spatial derivatives.        
+         zex1 = ( abs(iibm1-iibm2) * pe_xdif(iibm1+ii_offset,ijbm1          )         &
+        &       + abs(ijbm1-ijbm2) * pe_ydif(iibm1          ,ijbm1+ij_offset) ) 
+         zex2 = ( abs(iibm1-iibm2) * pe_xdif(iibm2+ii_offset,ijbm2          )         &
+        &       + abs(ijbm1-ijbm2) * pe_ydif(iibm2          ,ijbm2+ij_offset) ) 
+         zey1 = ( (iibm1-iibm1jm1) * pe_xdif(iibm1jm1+ii_offset,ijbm1jm1          )  & 
+        &      +  (ijbm1-ijbm1jm1) * pe_ydif(iibm1jm1          ,ijbm1jm1+ij_offset) ) 
+         zey2 = ( (iibm1jp1-iibm1) * pe_xdif(iibm1+ii_offset,ijbm1)                  &
+        &      +  (ijbm1jp1-ijbm1) * pe_ydif(iibm1          ,ijbm1+ij_offset) ) 
+         ! make sure scale factors are nonzero
+         if( zey1 .lt. rsmall ) zey1 = zey2
+         if( zey2 .lt. rsmall ) zey2 = zey1
+         zex1 = max(zex1,rsmall); zex2 = max(zex2,rsmall)
+         zey1 = max(zey1,rsmall); zey2 = max(zey2,rsmall); 
+         !
+         ! Calculate masks for calculation of spatial derivatives.        
+         zmask_x = ( abs(iibm1-iibm2) * pmask_xdif(iibm2+ii_offset,ijbm2          )         &
+        &          + abs(ijbm1-ijbm2) * pmask_ydif(iibm2          ,ijbm2+ij_offset) ) 
+         zmask_y1 = ( (iibm1-iibm1jm1) * pmask_xdif(iibm1jm1+ii_offset,ijbm1jm1          )  & 
+        &          +  (ijbm1-ijbm1jm1) * pmask_ydif(iibm1jm1          ,ijbm1jm1+ij_offset) ) 
+         zmask_y2 = ( (iibm1jp1-iibm1) * pmask_xdif(iibm1+ii_offset,ijbm1)                  &
+        &          +  (ijbm1jp1-ijbm1) * pmask_ydif(iibm1          ,ijbm1+ij_offset) ) 
+
+         ! Calculation of terms required for both versions of the scheme. 
+         ! Mask derivatives to ensure correct land boundary conditions for each variable.
+         ! Centred derivative is calculated as average of "left" and "right" derivatives for 
+         ! this reason. 
+         ! Note no rdt factor in expression for zdt because it cancels in the expressions for 
+         ! zrx and zry.
+         zdt = phia(iibm1,ijbm1) - phib(iibm1,ijbm1)
+         zdx = ( ( phia(iibm1,ijbm1) - phia(iibm2,ijbm2) ) / zex2 ) * zmask_x 
+         zdy_1 = ( ( phib(iibm1   ,ijbm1   ) - phib(iibm1jm1,ijbm1jm1) ) / zey1 ) * zmask_y1    
+         zdy_2 = ( ( phib(iibm1jp1,ijbm1jp1) - phib(iibm1   ,ijbm1)    ) / zey2 ) * zmask_y2 
+         zdy_centred = 0.5 * ( zdy_1 + zdy_2 )
+!!$         zdy_centred = phib(iibm1jp1,ijbm1jp1) - phib(iibm1jm1,ijbm1jm1)
+         ! upstream differencing for tangential derivatives
+         zsign_ups = sign( 1., zdt * zdy_centred )
+         zsign_ups = 0.5*( zsign_ups + abs(zsign_ups) )
+         zdy = zsign_ups * zdy_1 + (1. - zsign_ups) * zdy_2
+         znor2 = zdx * zdx + zdy * zdy
+         znor2 = max(znor2,zepsilon)
+         !
+         zrx = zdt * zdx / ( zex1 * znor2 ) 
+!!$         zrx = min(zrx,2.0_wp)
+         zout = sign( 1., zrx )
+         zout = 0.5*( zout + abs(zout) )
+         zwgt = 2.*rdt*( (1.-zout) * idx%nbd(jb,igrd) + zout * idx%nbdout(jb,igrd) )
+         ! only apply radiation on outflow points 
+         if( ll_npo ) then     !! NPO version !!
+            phia(ii,ij) = (1.-zout) * ( phib(ii,ij) + zwgt * ( phi_ext(jb) - phib(ii,ij) ) )        &
+           &            + zout      * ( phib(ii,ij) + zrx*phia(iibm1,ijbm1)                         &
+           &                            + zwgt * ( phi_ext(jb) - phib(ii,ij) ) ) / ( 1. + zrx ) 
+         else                  !! full oblique radiation !!
+            zsign_ups = sign( 1., zdt * zdy )
+            zsign_ups = 0.5*( zsign_ups + abs(zsign_ups) )
+            zey = zsign_ups * zey1 + (1.-zsign_ups) * zey2 
+            zry = zdt * zdy / ( zey * znor2 ) 
+            phia(ii,ij) = (1.-zout) * ( phib(ii,ij) + zwgt * ( phi_ext(jb) - phib(ii,ij) ) )        &
+           &            + zout      * ( phib(ii,ij) + zrx*phia(iibm1,ijbm1)                         &
+           &                    - zsign_ups      * zry * ( phib(ii   ,ij   ) - phib(iijm1,ijjm1 ) ) &
+           &                    - (1.-zsign_ups) * zry * ( phib(iijp1,ijjp1) - phib(ii   ,ij    ) ) &
+           &                    + zwgt * ( phi_ext(jb) - phib(ii,ij) ) ) / ( 1. + zrx ) 
+         end if
+         phia(ii,ij) = phia(ii,ij) * pmask(ii,ij)
+      END DO
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_orlanski_2d')
+
+   END SUBROUTINE bdy_orlanski_2d
+
+
+   SUBROUTINE bdy_orlanski_3d( idx, igrd, phib, phia, phi_ext, ll_npo )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_orlanski_3d  ***
+      !!             
+      !!              - Apply Orlanski radiation condition adaptively to 3D fields:
+      !!                  - radiation plus weak nudging at outflow points
+      !!                  - no radiation and strong nudging at inflow points
+      !! 
+      !!
+      !! References:  Marchesiello, McWilliams and Shchepetkin, Ocean Modelling vol. 3 (2001)    
+      !!----------------------------------------------------------------------
+      TYPE(OBC_INDEX),            INTENT(in)     ::   idx      ! BDY indices
+      INTEGER,                    INTENT(in)     ::   igrd     ! grid index
+      REAL(wp), DIMENSION(:,:,:), INTENT(in)     ::   phib     ! model before 3D field
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout)  ::   phia     ! model after 3D field (to be updated)
+      REAL(wp), DIMENSION(:,:),   INTENT(in)     ::   phi_ext  ! external forcing data
+      LOGICAL,                    INTENT(in)     ::   ll_npo   ! switch for NPO version
+
+      INTEGER  ::   jb, jk                                 ! dummy loop indices
+      INTEGER  ::   ii, ij, iibm1, iibm2, ijbm1, ijbm2     ! 2D addresses
+      INTEGER  ::   iijm1, iijp1, ijjm1, ijjp1             ! 2D addresses
+      INTEGER  ::   iibm1jp1, iibm1jm1, ijbm1jp1, ijbm1jm1 ! 2D addresses
+      INTEGER  ::   ii_offset, ij_offset                   ! offsets for mask indices
+      INTEGER  ::   flagu, flagv                           ! short cuts
+      REAL(wp) ::   zmask_x, zmask_y1, zmask_y2
+      REAL(wp) ::   zex1, zex2, zey, zey1, zey2
+      REAL(wp) ::   zdt, zdx, zdy, znor2, zrx, zry         ! intermediate calculations
+      REAL(wp) ::   zout, zwgt, zdy_centred
+      REAL(wp) ::   zdy_1, zdy_2,  zsign_ups
+      REAL(wp), PARAMETER :: zepsilon = 1.e-30                 ! local small value
+      REAL(wp), POINTER, DIMENSION(:,:,:)        :: pmask      ! land/sea mask for field
+      REAL(wp), POINTER, DIMENSION(:,:,:)        :: pmask_xdif ! land/sea mask for x-derivatives
+      REAL(wp), POINTER, DIMENSION(:,:,:)        :: pmask_ydif ! land/sea mask for y-derivatives
+      REAL(wp), POINTER, DIMENSION(:,:)          :: pe_xdif    ! scale factors for x-derivatives
+      REAL(wp), POINTER, DIMENSION(:,:)          :: pe_ydif    ! scale factors for y-derivatives
+      !!----------------------------------------------------------------------
+
+      IF( nn_timing == 1 ) CALL timing_start('bdy_orlanski_3d')
+
+      ! ----------------------------------!
+      ! Orlanski boundary conditions     :!
+      ! ----------------------------------! 
+     
+      SELECT CASE(igrd)
+         CASE(1)
+            pmask => tmask(:,:,:)
+            pmask_xdif => umask(:,:,:)
+            pmask_ydif => vmask(:,:,:)
+            pe_xdif => e1u(:,:)
+            pe_ydif => e2v(:,:)
+            ii_offset = 0
+            ij_offset = 0
+         CASE(2)
+            pmask => umask(:,:,:)
+            pmask_xdif => tmask(:,:,:)
+            pmask_ydif => fmask(:,:,:)
+            pe_xdif => e1t(:,:)
+            pe_ydif => e2f(:,:)
+            ii_offset = 1
+            ij_offset = 0
+         CASE(3)
+            pmask => vmask(:,:,:)
+            pmask_xdif => fmask(:,:,:)
+            pmask_ydif => tmask(:,:,:)
+            pe_xdif => e1f(:,:)
+            pe_ydif => e2t(:,:)
+            ii_offset = 0
+            ij_offset = 1
+         CASE DEFAULT ;   CALL ctl_stop( 'unrecognised value for igrd in bdy_orlanksi_2d' )
+      END SELECT
+
+      DO jk = 1, jpk
+         !            
+         DO jb = 1, idx%nblenrim(igrd)
+            ii  = idx%nbi(jb,igrd)
+            ij  = idx%nbj(jb,igrd) 
+            flagu = int( idx%flagu(jb,igrd) )
+            flagv = int( idx%flagv(jb,igrd) )
+            !
+            ! calculate positions of b-1 and b-2 points for this rim point
+            ! also (b-1,j-1) and (b-1,j+1) points
+            iibm1 = ii + flagu ; iibm2 = ii + 2*flagu 
+            ijbm1 = ij + flagv ; ijbm2 = ij + 2*flagv
+            !
+            iijm1 = ii - abs(flagv) ; iijp1 = ii + abs(flagv) 
+            ijjm1 = ij - abs(flagu) ; ijjp1 = ij + abs(flagu)
+            !
+            iibm1jm1 = ii + flagu - abs(flagv) ; iibm1jp1 = ii + flagu + abs(flagv) 
+            ijbm1jm1 = ij + flagv - abs(flagu) ; ijbm1jp1 = ij + flagv + abs(flagu) 
+            !
+            ! Calculate scale factors for calculation of spatial derivatives.        
+            zex1 = ( abs(iibm1-iibm2) * pe_xdif(iibm1+ii_offset,ijbm1          )         &
+           &       + abs(ijbm1-ijbm2) * pe_ydif(iibm1          ,ijbm1+ij_offset) ) 
+            zex2 = ( abs(iibm1-iibm2) * pe_xdif(iibm2+ii_offset,ijbm2          )         &
+           &       + abs(ijbm1-ijbm2) * pe_ydif(iibm2          ,ijbm2+ij_offset) ) 
+            zey1 = ( (iibm1-iibm1jm1) * pe_xdif(iibm1jm1+ii_offset,ijbm1jm1          )  & 
+           &      +  (ijbm1-ijbm1jm1) * pe_ydif(iibm1jm1          ,ijbm1jm1+ij_offset) ) 
+            zey2 = ( (iibm1jp1-iibm1) * pe_xdif(iibm1+ii_offset,ijbm1)                  &
+           &      +  (ijbm1jp1-ijbm1) * pe_ydif(iibm1          ,ijbm1+ij_offset) ) 
+            ! make sure scale factors are nonzero
+            if( zey1 .lt. rsmall ) zey1 = zey2
+            if( zey2 .lt. rsmall ) zey2 = zey1
+            zex1 = max(zex1,rsmall); zex2 = max(zex2,rsmall); 
+            zey1 = max(zey1,rsmall); zey2 = max(zey2,rsmall); 
+            !
+            ! Calculate masks for calculation of spatial derivatives.        
+            zmask_x = ( abs(iibm1-iibm2) * pmask_xdif(iibm2+ii_offset,ijbm2          ,jk)          &
+           &          + abs(ijbm1-ijbm2) * pmask_ydif(iibm2          ,ijbm2+ij_offset,jk) ) 
+            zmask_y1 = ( (iibm1-iibm1jm1) * pmask_xdif(iibm1jm1+ii_offset,ijbm1jm1          ,jk)   & 
+           &          +  (ijbm1-ijbm1jm1) * pmask_ydif(iibm1jm1          ,ijbm1jm1+ij_offset,jk) ) 
+            zmask_y2 = ( (iibm1jp1-iibm1) * pmask_xdif(iibm1+ii_offset,ijbm1          ,jk)         &
+           &          +  (ijbm1jp1-ijbm1) * pmask_ydif(iibm1          ,ijbm1+ij_offset,jk) ) 
+            !
+            ! Calculate normal (zrx) and tangential (zry) components of radiation velocities.
+            ! Mask derivatives to ensure correct land boundary conditions for each variable.
+            ! Centred derivative is calculated as average of "left" and "right" derivatives for 
+            ! this reason. 
+            zdt = phia(iibm1,ijbm1,jk) - phib(iibm1,ijbm1,jk)
+            zdx = ( ( phia(iibm1,ijbm1,jk) - phia(iibm2,ijbm2,jk) ) / zex2 ) * zmask_x                  
+            zdy_1 = ( ( phib(iibm1   ,ijbm1   ,jk) - phib(iibm1jm1,ijbm1jm1,jk) ) / zey1 ) * zmask_y1  
+            zdy_2 = ( ( phib(iibm1jp1,ijbm1jp1,jk) - phib(iibm1   ,ijbm1   ,jk) ) / zey2 ) * zmask_y2      
+            zdy_centred = 0.5 * ( zdy_1 + zdy_2 )
+!!$            zdy_centred = phib(iibm1jp1,ijbm1jp1,jk) - phib(iibm1jm1,ijbm1jm1,jk)
+            ! upstream differencing for tangential derivatives
+            zsign_ups = sign( 1., zdt * zdy_centred )
+            zsign_ups = 0.5*( zsign_ups + abs(zsign_ups) )
+            zdy = zsign_ups * zdy_1 + (1. - zsign_ups) * zdy_2
+            znor2 = zdx * zdx + zdy * zdy
+            znor2 = max(znor2,zepsilon)
+            !
+            ! update boundary value:
+            zrx = zdt * zdx / ( zex1 * znor2 )
+!!$            zrx = min(zrx,2.0_wp)
+            zout = sign( 1., zrx )
+            zout = 0.5*( zout + abs(zout) )
+            zwgt = 2.*rdt*( (1.-zout) * idx%nbd(jb,igrd) + zout * idx%nbdout(jb,igrd) )
+            ! only apply radiation on outflow points 
+            if( ll_npo ) then     !! NPO version !!
+               phia(ii,ij,jk) = (1.-zout) * ( phib(ii,ij,jk) + zwgt * ( phi_ext(jb,jk) - phib(ii,ij,jk) ) ) &
+              &               + zout      * ( phib(ii,ij,jk) + zrx*phia(iibm1,ijbm1,jk)                     &
+              &                            + zwgt * ( phi_ext(jb,jk) - phib(ii,ij,jk) ) ) / ( 1. + zrx ) 
+            else                  !! full oblique radiation !!
+               zsign_ups = sign( 1., zdt * zdy )
+               zsign_ups = 0.5*( zsign_ups + abs(zsign_ups) )
+               zey = zsign_ups * zey1 + (1.-zsign_ups) * zey2 
+               zry = zdt * zdy / ( zey * znor2 ) 
+               phia(ii,ij,jk) = (1.-zout) * ( phib(ii,ij,jk) + zwgt * ( phi_ext(jb,jk) - phib(ii,ij,jk) ) )    &
+              &               + zout      * ( phib(ii,ij,jk) + zrx*phia(iibm1,ijbm1,jk)                        &
+              &                       - zsign_ups      * zry * ( phib(ii   ,ij   ,jk) - phib(iijm1,ijjm1,jk) ) &
+              &                       - (1.-zsign_ups) * zry * ( phib(iijp1,ijjp1,jk) - phib(ii   ,ij   ,jk) ) &
+              &                       + zwgt * ( phi_ext(jb,jk) - phib(ii,ij,jk) ) ) / ( 1. + zrx ) 
+            end if
+            phia(ii,ij,jk) = phia(ii,ij,jk) * pmask(ii,ij,jk)
+         END DO
+         !
+      END DO
+
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_orlanski_3d')
+
+   END SUBROUTINE bdy_orlanski_3d
+
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                   NO Unstruct Open Boundary Conditions
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE bdy_orlanski_2d( idx, igrd, phib, phia, phi_ext  )      ! Empty routine
+      WRITE(*,*) 'bdy_orlanski_2d: You should not have seen this print! error?', kt
+   END SUBROUTINE bdy_orlanski_2d
+   SUBROUTINE bdy_orlanski_3d( idx, igrd, phib, phia, phi_ext  )      ! Empty routine
+      WRITE(*,*) 'bdy_orlanski_3d: You should not have seen this print! error?', kt
+   END SUBROUTINE bdy_orlanski_3d
+#endif
+
+   !!======================================================================
+END MODULE bdylib
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90	(revision 4292)
@@ -9,4 +9,5 @@
    !!            3.3  !  2010-09  (D.Storkey and E.O'Dea)  bug fixes
    !!            3.4  !  2012-09  (G. Reffray and J. Chanut) New inputs + mods
+   !!            3.5  !  2013-07  (J. Chanut) Compliant with time splitting changes
    !!----------------------------------------------------------------------
 #if defined key_bdy
@@ -32,4 +33,5 @@
 !   USE tide_mod       ! Useless ??
    USE fldread, ONLY: fld_map
+   USE dynspg_oce, ONLY: lk_dynspg_ts
 
    IMPLICIT NONE
@@ -38,4 +40,5 @@
    PUBLIC   bdytide_init     ! routine called in bdy_init
    PUBLIC   bdytide_update   ! routine called in bdy_dta
+   PUBLIC   bdy_dta_tides    ! routine called in dyn_spg_ts
 
    TYPE, PUBLIC ::   TIDES_DATA     !: Storage for external tidal harmonics data
@@ -49,4 +52,5 @@
 
    TYPE(TIDES_DATA), PUBLIC, DIMENSION(jp_bdy), TARGET :: tides  !: External tidal harmonics data
+   TYPE(OBC_DATA)  , PRIVATE, DIMENSION(jp_bdy) :: dta_bdy_s  !: bdy external data (slow component)
 
    !!----------------------------------------------------------------------
@@ -131,5 +135,5 @@
             ! JC: If FRS scheme is used, we assume that tidal is needed over the whole
             ! relaxation area      
-            IF( nn_dyn2d(ib_bdy) .eq. jp_frs ) THEN
+            IF( cn_dyn2d(ib_bdy) == 'frs' ) THEN
                ilen0(:)=nblen(:)
             ELSE
@@ -146,10 +150,10 @@
             ALLOCATE( td%v ( ilen0(3), nb_harmo, 2 ) )
 
-            td%ssh0(:,:,:) = 0.e0
-            td%ssh(:,:,:) = 0.e0
-            td%u0(:,:,:) = 0.e0
-            td%u(:,:,:) = 0.e0
-            td%v0(:,:,:) = 0.e0
-            td%v(:,:,:) = 0.e0
+            td%ssh0(:,:,:) = 0._wp
+            td%ssh (:,:,:) = 0._wp
+            td%u0  (:,:,:) = 0._wp
+            td%u   (:,:,:) = 0._wp
+            td%v0  (:,:,:) = 0._wp
+            td%v   (:,:,:) = 0._wp
 
             IF (ln_bdytide_2ddta) THEN
@@ -255,4 +259,14 @@
             ENDIF
             !
+            IF ( lk_dynspg_ts ) THEN ! Allocate arrays to save slowly varying boundary data during
+                                     ! time splitting integration
+               ALLOCATE( dta_bdy_s(ib_bdy)%ssh ( ilen0(1) ) )
+               ALLOCATE( dta_bdy_s(ib_bdy)%u2d ( ilen0(2) ) )
+               ALLOCATE( dta_bdy_s(ib_bdy)%v2d ( ilen0(3) ) )
+               dta_bdy_s(ib_bdy)%ssh(:) = 0.e0
+               dta_bdy_s(ib_bdy)%u2d(:) = 0.e0
+               dta_bdy_s(ib_bdy)%v2d(:) = 0.e0
+            ENDIF
+            !
          ENDIF ! nn_dyn2d_dta(ib_bdy) .ge. 2
          !
@@ -300,5 +314,5 @@
       ENDIF
 
-      IF ( nsec_day == NINT(0.5 * rdttra(1)) .AND. zflag==1 ) THEN
+      IF ( nsec_day == NINT(0.5_wp * rdttra(1)) .AND. zflag==1 ) THEN
         !
         kt_tide = kt
@@ -321,5 +335,5 @@
          
       IF( PRESENT(jit) ) THEN  
-         z_arg = ( ((kt-kt_tide)-1) * rdt + (jit+time_add) * rdt / REAL(nn_baro,wp) )
+         z_arg = ((kt-kt_tide) * rdt + (jit+0.5_wp*(time_add-1)) * rdt / REAL(nn_baro,wp) )
       ELSE                              
          z_arg = ((kt-kt_tide)+time_add) * rdt
@@ -327,6 +341,6 @@
 
       ! Linear ramp on tidal component at open boundaries 
-      zramp = 1.
-      IF (ln_tide_ramp) zramp = MIN(MAX( (z_arg + (kt_tide-nit000)*rdt)/(rdttideramp*rday),0.),1.)
+      zramp = 1._wp
+      IF (ln_tide_ramp) zramp = MIN(MAX( (z_arg + (kt_tide-nit000)*rdt)/(rdttideramp*rday),0._wp),1._wp)
 
       DO itide = 1, nb_harmo
@@ -354,4 +368,132 @@
       !
    END SUBROUTINE bdytide_update
+
+   SUBROUTINE bdy_dta_tides( kt, kit, time_offset )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_dta_tides  ***
+      !!                
+      !! ** Purpose : - Add tidal forcing to ssh, u2d and v2d OBC data arrays. 
+      !!                
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in )            ::   kt          ! Main timestep counter
+      INTEGER, INTENT( in ),OPTIONAL   ::   kit         ! Barotropic timestep counter (for timesplitting option)
+      INTEGER, INTENT( in ),OPTIONAL   ::   time_offset ! time offset in units of timesteps. NB. if kit
+                                                        ! is present then units = subcycle timesteps.
+                                                        ! time_offset = 0  => get data at "now"    time level
+                                                        ! time_offset = -1 => get data at "before" time level
+                                                        ! time_offset = +1 => get data at "after"  time level
+                                                        ! etc.
+      !!
+      LOGICAL  :: lk_first_btstp  ! =.TRUE. if time splitting and first barotropic step
+      INTEGER,          DIMENSION(jpbgrd) :: ilen0 
+      INTEGER, DIMENSION(1:jpbgrd) :: nblen, nblenrim  ! short cuts
+      INTEGER  :: itide, ib_bdy, ib, igrd                     ! loop indices
+      INTEGER  :: time_add                                    ! time offset in units of timesteps
+      REAL(wp) :: z_arg, z_sarg, zramp, zoff, z_cost, z_sist      
+      !!----------------------------------------------------------------------
+
+      IF( nn_timing == 1 ) CALL timing_start('bdy_dta_tides')
+
+      lk_first_btstp=.TRUE.
+      IF ( PRESENT(kit).AND.( kit /= 1 ) ) THEN ; lk_first_btstp=.FALSE. ; ENDIF
+
+      time_add = 0
+      IF( PRESENT(time_offset) ) THEN
+         time_add = time_offset
+      ENDIF
+      
+      ! Absolute time from model initialization:   
+      IF( PRESENT(kit) ) THEN  
+         z_arg = ( kt + (kit+0.5_wp*(time_add-1)) / REAL(nn_baro,wp) ) * rdt
+      ELSE                              
+         z_arg = ( kt + time_add ) * rdt
+      ENDIF
+
+      ! Linear ramp on tidal component at open boundaries 
+      zramp = 1.
+      IF (ln_tide_ramp) zramp = MIN(MAX( (z_arg - nit000*rdt)/(rdttideramp*rday),0.),1.)
+
+      DO ib_bdy = 1,nb_bdy
+
+         ! line below should be simplified (runoff case)
+!! CHANUT: TO BE SORTED OUT
+!!         IF (( nn_dyn2d_dta(ib_bdy) .ge. 2 ).AND.(nn_tra(ib_bdy).NE.4)) THEN
+         IF ( nn_dyn2d_dta(ib_bdy) .ge. 2 ) THEN
+
+            nblen(1:jpbgrd) = idx_bdy(ib_bdy)%nblen(1:jpbgrd)
+            nblenrim(1:jpbgrd) = idx_bdy(ib_bdy)%nblenrim(1:jpbgrd)
+
+            IF( cn_dyn2d(ib_bdy) == 'frs' ) THEN
+               ilen0(:)=nblen(:)
+            ELSE
+               ilen0(:)=nblenrim(:)
+            ENDIF     
+
+            ! We refresh nodal factors every day below
+            ! This should be done somewhere else
+            IF ( nsec_day == NINT(0.5_wp * rdttra(1)) .AND. lk_first_btstp ) THEN
+               !
+               kt_tide = kt               
+               !
+               IF(lwp) THEN
+               WRITE(numout,*)
+               WRITE(numout,*) 'bdy_tide_dta : Refresh nodal factors for tidal open bdy data at kt=',kt
+               WRITE(numout,*) '~~~~~~~~~~~~~~ '
+               ENDIF
+               !
+               CALL tide_init_elevation ( idx=idx_bdy(ib_bdy), td=tides(ib_bdy) )
+               CALL tide_init_velocities( idx=idx_bdy(ib_bdy), td=tides(ib_bdy) )
+               !
+            ENDIF
+            zoff = -kt_tide * rdt ! time offset relative to nodal factor computation time
+            !
+            ! If time splitting, save data at first barotropic iteration
+            IF ( PRESENT(kit) ) THEN
+               IF ( lk_first_btstp ) THEN ! Save slow varying open boundary data:
+                  dta_bdy_s(ib_bdy)%ssh(1:ilen0(1)) = dta_bdy(ib_bdy)%ssh(1:ilen0(1))
+                  dta_bdy_s(ib_bdy)%u2d(1:ilen0(2)) = dta_bdy(ib_bdy)%u2d(1:ilen0(2))
+                  dta_bdy_s(ib_bdy)%v2d(1:ilen0(3)) = dta_bdy(ib_bdy)%v2d(1:ilen0(3))
+
+               ELSE ! Initialize arrays from slow varying open boundary data:            
+                  dta_bdy(ib_bdy)%ssh(1:ilen0(1)) = dta_bdy_s(ib_bdy)%ssh(1:ilen0(1))
+                  dta_bdy(ib_bdy)%u2d(1:ilen0(2)) = dta_bdy_s(ib_bdy)%u2d(1:ilen0(2))
+                  dta_bdy(ib_bdy)%v2d(1:ilen0(3)) = dta_bdy_s(ib_bdy)%v2d(1:ilen0(3))
+               ENDIF
+            ENDIF
+            !
+            ! Update open boundary data arrays:
+            DO itide = 1, nb_harmo
+               !
+               z_sarg = (z_arg + zoff) * omega_tide(itide)
+               z_cost = zramp * COS( z_sarg )
+               z_sist = zramp * SIN( z_sarg )
+               !
+               igrd=1                              ! SSH on tracer grid
+               DO ib = 1, ilen0(igrd)
+                  dta_bdy(ib_bdy)%ssh(ib) = dta_bdy(ib_bdy)%ssh(ib) + &
+                     &                      ( tides(ib_bdy)%ssh(ib,itide,1)*z_cost + &
+                     &                        tides(ib_bdy)%ssh(ib,itide,2)*z_sist )
+               END DO
+               !
+               igrd=2                              ! U grid
+               DO ib = 1, ilen0(igrd)
+                  dta_bdy(ib_bdy)%u2d(ib) = dta_bdy(ib_bdy)%u2d(ib) + &
+                     &                      ( tides(ib_bdy)%u(ib,itide,1)*z_cost + &
+                     &                        tides(ib_bdy)%u(ib,itide,2)*z_sist )
+               END DO
+               !
+               igrd=3                              ! V grid
+               DO ib = 1, ilen0(igrd) 
+                  dta_bdy(ib_bdy)%v2d(ib) = dta_bdy(ib_bdy)%v2d(ib) + &
+                     &                      ( tides(ib_bdy)%v(ib,itide,1)*z_cost + &
+                     &                        tides(ib_bdy)%v(ib,itide,2)*z_sist )
+               END DO
+            END DO
+         END IF
+      END DO
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_dta_tides')
+      !
+   END SUBROUTINE bdy_dta_tides
 
    SUBROUTINE tide_init_elevation( idx, td )
@@ -460,6 +602,13 @@
       WRITE(*,*) 'bdytide_update: You should not have seen this print! error?', kt, jit
    END SUBROUTINE bdytide_update
+   SUBROUTINE bdy_dta_tides( kt, kit, time_offset )     ! Empty routine
+      INTEGER, INTENT( in )            ::   kt          ! Dummy argument empty routine      
+      INTEGER, INTENT( in ),OPTIONAL   ::   kit         ! Dummy argument empty routine
+      INTEGER, INTENT( in ),OPTIONAL   ::   time_offset ! Dummy argument empty routine
+      WRITE(*,*) 'bdy_dta_tides: You should not have seen this print! error?', kt, jit
+   END SUBROUTINE bdy_dta_tides
 #endif
 
    !!======================================================================
 END MODULE bdytides
+
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90	(revision 4292)
@@ -20,4 +20,5 @@
    USE dom_oce         ! ocean space and time domain variables 
    USE bdy_oce         ! ocean open boundary conditions
+   USE bdylib          ! for orlanski library routines
    USE bdydta, ONLY:   bf
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
@@ -51,14 +52,18 @@
       DO ib_bdy=1, nb_bdy
 
-         SELECT CASE( nn_tra(ib_bdy) )
-         CASE(jp_none)
+         SELECT CASE( cn_tra(ib_bdy) )
+         CASE('none')
             CYCLE
-         CASE(jp_frs)
+         CASE('frs')
             CALL bdy_tra_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
-         CASE(2)
+         CASE('specified')
             CALL bdy_tra_spe( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
-         CASE(3)
+         CASE('neumann')
             CALL bdy_tra_nmn( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
-         CASE(4)
+         CASE('orlanski')
+            CALL bdy_tra_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ll_npo=.false. )
+         CASE('orlanski_npo')
+            CALL bdy_tra_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ll_npo=.true. )
+         CASE('runoff')
             CALL bdy_tra_rnf( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt )
          CASE DEFAULT
@@ -196,4 +201,38 @@
       !
    END SUBROUTINE bdy_tra_nmn
+ 
+
+   SUBROUTINE bdy_tra_orlanski( idx, dta, ll_npo )
+      !!----------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_tra_orlanski  ***
+      !!             
+      !!              - Apply Orlanski radiation to temperature and salinity. 
+      !!              - Wrapper routine for bdy_orlanski_3d
+      !! 
+      !!
+      !! References:  Marchesiello, McWilliams and Shchepetkin, Ocean Modelling vol. 3 (2001)    
+      !!----------------------------------------------------------------------
+      TYPE(OBC_INDEX),              INTENT(in) ::   idx  ! OBC indices
+      TYPE(OBC_DATA),               INTENT(in) ::   dta  ! OBC external data
+      LOGICAL,                      INTENT(in) ::   ll_npo  ! switch for NPO version
+
+      INTEGER  ::   igrd                                    ! grid index
+      !!----------------------------------------------------------------------
+
+      IF( nn_timing == 1 ) CALL timing_start('bdy_tra_orlanski')
+      !
+      igrd = 1      ! Orlanski bc on temperature; 
+      !            
+      CALL bdy_orlanski_3d( idx, igrd, tsb(:,:,:,jp_tem), tsa(:,:,:,jp_tem), dta%tem, ll_npo )
+
+      igrd = 1      ! Orlanski bc on salinity;
+      !  
+      CALL bdy_orlanski_3d( idx, igrd, tsb(:,:,:,jp_sal), tsa(:,:,:,jp_sal), dta%sal, ll_npo )
+      !
+      IF( nn_timing == 1 ) CALL timing_stop('bdy_tra_orlanski')
+      !
+
+   END SUBROUTINE bdy_tra_orlanski
+
 
    SUBROUTINE bdy_tra_rnf( idx, dta, kt )
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90	(revision 4292)
@@ -104,5 +104,5 @@
                ii = idx%nbi(jb,jgrd)
                ij = idx%nbj(jb,jgrd)
-               zubtpecor = zubtpecor + idx%flagu(jb) * ua(ii,ij, jk) * e2u(ii,ij) * fse3u(ii,ij,jk)
+               zubtpecor = zubtpecor + idx%flagu(jb,jgrd) * ua(ii,ij, jk) * e2u(ii,ij) * fse3u(ii,ij,jk)
             END DO
          END DO
@@ -112,5 +112,5 @@
                ii = idx%nbi(jb,jgrd)
                ij = idx%nbj(jb,jgrd)
-               zubtpecor = zubtpecor + idx%flagv(jb) * va(ii,ij, jk) * e1v(ii,ij) * fse3v(ii,ij,jk) 
+               zubtpecor = zubtpecor + idx%flagv(jb,jgrd) * va(ii,ij, jk) * e1v(ii,ij) * fse3v(ii,ij,jk) 
             END DO
          END DO
@@ -136,6 +136,6 @@
                ii = idx%nbi(jb,jgrd)
                ij = idx%nbj(jb,jgrd)
-               ua(ii,ij,jk) = ua(ii,ij,jk) - idx%flagu(jb) * zubtpecor * umask(ii,ij,jk)
-               ztranst = ztranst + idx%flagu(jb) * ua(ii,ij,jk) * e2u(ii,ij) * fse3u(ii,ij,jk)
+               ua(ii,ij,jk) = ua(ii,ij,jk) - idx%flagu(jb,jgrd) * zubtpecor * umask(ii,ij,jk)
+               ztranst = ztranst + idx%flagu(jb,jgrd) * ua(ii,ij,jk) * e2u(ii,ij) * fse3u(ii,ij,jk)
             END DO
          END DO
@@ -145,6 +145,6 @@
                ii = idx%nbi(jb,jgrd)
                ij = idx%nbj(jb,jgrd)
-               va(ii,ij,jk) = va(ii,ij,jk) -idx%flagv(jb) * zubtpecor * vmask(ii,ij,jk)
-               ztranst = ztranst + idx%flagv(jb) * va(ii,ij,jk) * e1v(ii,ij) * fse3v(ii,ij,jk)
+               va(ii,ij,jk) = va(ii,ij,jk) -idx%flagv(jb,jgrd) * zubtpecor * vmask(ii,ij,jk)
+               ztranst = ztranst + idx%flagv(jb,jgrd) * va(ii,ij,jk) * e1v(ii,ij) * fse3v(ii,ij,jk)
             END DO
          END DO
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90	(revision 4292)
@@ -196,6 +196,6 @@
       thick0(:,:) = 0._wp
       DO jk = 1, jpkm1
-         vol0        = vol0        + SUM( area (:,:) * tmask(:,:,jk) * fse3t_0(:,:,jk) )
-         thick0(:,:) = thick0(:,:) +    tmask_i(:,:) * tmask(:,:,jk) * fse3t_0(:,:,jk)
+         vol0        = vol0        + SUM( area (:,:) * tmask(:,:,jk) * e3t_0(:,:,jk) )
+         thick0(:,:) = thick0(:,:) +    tmask_i(:,:) * tmask(:,:,jk) * e3t_0(:,:,jk)
       END DO
       IF( lk_mpp )   CALL mpp_sum( vol0 )
@@ -212,5 +212,5 @@
                ik = mbkt(ji,jj)
                IF( ik > 1 ) THEN
-                  zztmp = ( gdept_0(ik) - fsdept_0(ji,jj,ik) ) / ( gdept_0(ik) - gdept_0(ik-1) )
+                  zztmp = ( gdept_1d(ik) - gdept_0(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
                   sn0(ji,jj,ik) = ( 1._wp - zztmp ) * sn0(ji,jj,ik) + zztmp * sn0(ji,jj,ik-1)
                ENDIF
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diadimg.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diadimg.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diadimg.F90	(revision 4292)
@@ -112,8 +112,8 @@
 
     CASE ( 'T')
-       z4dep(:)=gdept_0(:)
+       z4dep(:)=gdept_1d(:)
 
     CASE ( 'W' )
-       z4dep(:)=gdepw_0(:)
+       z4dep(:)=gdepw_1d(:)
 
     CASE ( '2' )
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diaharm.F90	(revision 4292)
@@ -1,16 +1,16 @@
 MODULE diaharm 
-
-#if defined key_diaharm && defined key_tide
-   !!=================================================================================
+   !!======================================================================
    !!                       ***  MODULE  diaharm  ***
    !! Harmonic analysis of tidal constituents 
-   !!=================================================================================
-   !! * Modules used
+   !!======================================================================
+   !! History :  3.1  !  2007  (O. Le Galloudec, J. Chanut)  Original code
+   !!----------------------------------------------------------------------
+#if defined key_diaharm && defined key_tide
+   !!----------------------------------------------------------------------
+   !!   'key_diaharm'
+   !!   'key_tide'
+   !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain
-   USE in_out_manager  ! I/O units
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE ioipsl          ! NetCDF IPSL library
-   USE diadimg         ! To write dimg
    USE phycst
    USE dynspg_oce
@@ -18,5 +18,9 @@
    USE daymod
    USE tide_mod
-   USE iom 
+   USE in_out_manager  ! I/O units
+   USE iom             ! I/0 library
+   USE ioipsl          ! NetCDF IPSL library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE diadimg         ! To write dimg
    USE timing          ! preformance summary
    USE wrk_nemo        ! working arrays
@@ -30,36 +34,32 @@
    INTEGER, PARAMETER :: jpdimsparse  = jpincomax*300*24
 
-   INTEGER ::                            & !! namelist variables
-                         nit000_han    , & ! First time step used for harmonic analysis
-                         nitend_han    , & ! Last time step used for harmonic analysis
-                         nstep_han     , & ! Time step frequency for harmonic analysis
-                         nb_ana            ! Number of harmonics to analyse
-
-   INTEGER , ALLOCATABLE, DIMENSION(:)       :: name
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) :: ana_temp
-   REAL(wp), ALLOCATABLE, DIMENSION(:)       :: ana_freq, vt, ut, ft
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   :: out_eta, &
-                                                out_u  , &
-                                                out_v
-
-   INTEGER :: ninco, nsparse
-   INTEGER ,       DIMENSION(jpdimsparse)         :: njsparse, nisparse
-   INTEGER , SAVE, DIMENSION(jpincomax)           :: ipos1
-   REAL(wp),       DIMENSION(jpdimsparse)         :: valuesparse
-   REAL(wp),       DIMENSION(jpincomax)           :: ztmp4 , ztmp7
-   REAL(wp), SAVE, DIMENSION(jpincomax,jpincomax) :: ztmp3 , zpilier
-   REAL(wp), SAVE, DIMENSION(jpincomax)           :: zpivot
-
-   CHARACTER (LEN=4), DIMENSION(jpmax_harmo) ::   &
-       tname         ! Names of tidal constituents ('M2', 'K1',...)
-
-
-!! * Routine accessibility
-   PUBLIC  dia_harm    ! routine called by step.F90
-
-   !!---------------------------------------------------------------------------------
-   !!  
-   !!---------------------------------------------------------------------------------
-
+   !                            !!!namelist variables
+   INTEGER ::   nit000_han    ! First time step used for harmonic analysis
+   INTEGER ::   nitend_han    ! Last time step used for harmonic analysis
+   INTEGER ::   nstep_han     ! Time step frequency for harmonic analysis
+   INTEGER ::   nb_ana           ! Number of harmonics to analyse
+
+   INTEGER , ALLOCATABLE, DIMENSION(:)       ::   name
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::   ana_temp
+   REAL(wp), ALLOCATABLE, DIMENSION(:)       ::   ana_freq, ut   , vt   , ft
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   out_eta , out_u, out_v
+
+   INTEGER ::   ninco, nsparse
+   INTEGER ,       DIMENSION(jpdimsparse)         ::   njsparse, nisparse
+   INTEGER , SAVE, DIMENSION(jpincomax)           ::   ipos1
+   REAL(wp),       DIMENSION(jpdimsparse)         ::   valuesparse
+   REAL(wp),       DIMENSION(jpincomax)           ::   ztmp4 , ztmp7
+   REAL(wp), SAVE, DIMENSION(jpincomax,jpincomax) ::   ztmp3 , zpilier
+   REAL(wp), SAVE, DIMENSION(jpincomax)           ::   zpivot
+
+   CHARACTER (LEN=4), DIMENSION(jpmax_harmo) ::   tname   ! Names of tidal constituents ('M2', 'K1',...)
+
+   PUBLIC   dia_harm   ! routine called by step.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.5 , NEMO Consortium (2013)
+   !! $Id:$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
 
@@ -67,5 +67,4 @@
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE dia_harm_init  ***
-      !!----------------------------------------------------------------------
       !!         
       !! ** Purpose :   Initialization of tidal harmonic analysis
@@ -73,8 +72,5 @@
       !! ** Method  :   Initialize frequency array and  nodal factor for nit000_han
       !!
-      !! History :
-      !!   9.0  O. Le Galloudec and J. Chanut (Original)
-      !!--------------------------------------------------------------------
-      !! * Local declarations 
+      !!--------------------------------------------------------------------
       INTEGER :: jh, nhan, jk, ji
       INTEGER ::   ios                 ! Local integer output status for namelist read
@@ -108,21 +104,13 @@
       ! Basic checks on harmonic analysis time window:
       ! ----------------------------------------------
-      IF (nit000 > nit000_han) THEN
-        IF(lwp) WRITE(numout,*) ' E R R O R dia_harm_init : nit000_han must be greater than nit000, stop'
-        IF(lwp) WRITE(numout,*) ' restart capability not implemented'
-        nstop = nstop + 1
-      ENDIF
-      IF (nitend < nitend_han) THEN
-        IF(lwp) WRITE(numout,*) ' E R R O R dia_harm_init : nitend_han must be lower than nitend, stop'
-        IF(lwp) WRITE(numout,*) ' restart capability not implemented'
-        nstop = nstop + 1
-      ENDIF
-
-      IF (MOD(nitend_han-nit000_han+1,nstep_han).NE.0) THEN
-        IF(lwp) WRITE(numout,*) ' E R R O R dia_harm_init : analysis time span must be a multiple of nstep_han, stop'
-        nstop = nstop + 1
-      END IF
-
-      nb_ana=0
+      IF( nit000 > nit000_han )   CALL ctl_stop( 'dia_harm_init : nit000_han must be greater than nit000',   &
+         &                                       ' restart capability not implemented' )
+      IF( nitend < nitend_han )   CALL ctl_stop( 'dia_harm_init : nitend_han must be lower than nitend',   &
+         &                                       'restart capability not implemented' )
+
+      IF( MOD( nitend_han-nit000_han+1 , nstep_han ) /= 0 )   &
+         &                        CALL ctl_stop( 'dia_harm_init : analysis time span must be a multiple of nstep_han' )
+
+      nb_ana = 0
       DO jk=1,jpmax_harmo
          DO ji=1,jpmax_harmo
@@ -157,10 +145,7 @@
       ! Initialize frequency array:
       ! ---------------------------
-      ALLOCATE(ana_freq(nb_ana))
-      ALLOCATE(vt      (nb_ana))
-      ALLOCATE(ut      (nb_ana))
-      ALLOCATE(ft      (nb_ana))
-
-      CALL tide_harmo(ana_freq, vt, ut , ft, name ,nb_ana)
+      ALLOCATE( ana_freq(nb_ana), ut(nb_ana), vt(nb_ana), ft(nb_ana) )
+
+      CALL tide_harmo( ana_freq, vt, ut, ft, name, nb_ana )
 
       IF(lwp) WRITE(numout,*) 'Analysed frequency  : ',nb_ana ,'Frequency '
@@ -172,13 +157,13 @@
       ! Initialize temporary arrays:
       ! ----------------------------
-      ALLOCATE( ana_temp(jpi,jpj,nb_ana*2,3))
+      ALLOCATE( ana_temp(jpi,jpj,2*nb_ana,3) )
       ana_temp(:,:,:,:) = 0.e0
 
    END SUBROUTINE dia_harm_init
-   
+
+
    SUBROUTINE dia_harm ( kt )
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE dia_harm  ***
-      !!----------------------------------------------------------------------
       !!         
       !! ** Purpose :   Tidal harmonic analysis main routine
@@ -186,11 +171,7 @@
       !! ** Action  :   Sums ssh/u/v over time analysis [nit000_han,nitend_han]
       !!
-      !! History :
-      !!   9.0  O. Le Galloudec and J. Chanut (Original)
-      !!--------------------------------------------------------------------
-      !! * Argument:
+      !!--------------------------------------------------------------------
       INTEGER, INTENT( IN ) :: kt
-
-      !! * Local declarations
+      !
       INTEGER  :: ji, jj, jh, jc, nhc
       REAL(wp) :: ztime, ztemp
@@ -198,5 +179,5 @@
       IF( nn_timing == 1 )   CALL timing_start('dia_harm')
 
-      IF ( kt .EQ. nit000 ) CALL dia_harm_init
+      IF ( kt == nit000 ) CALL dia_harm_init
 
       IF ( ((kt.GE.nit000_han).AND.(kt.LE.nitend_han)).AND. &
@@ -215,13 +196,8 @@
               DO ji = 1,jpi
                 ! Elevation
-                ana_temp(ji,jj,nhc,1) = ana_temp(ji,jj,nhc,1)                &
-                                        + ztemp*sshn(ji,jj)*tmask(ji,jj,1)        
+                ana_temp(ji,jj,nhc,1) = ana_temp(ji,jj,nhc,1) + ztemp*sshn(ji,jj)           *tmask(ji,jj,1)        
 #if defined key_dynspg_ts
-                ! ubar
-                ana_temp(ji,jj,nhc,2) = ana_temp(ji,jj,nhc,2)                &
-                                        + ztemp*un_b(ji,jj)*hur(ji,jj)*umask(ji,jj,1)
-                ! vbar
-                ana_temp(ji,jj,nhc,3) = ana_temp(ji,jj,nhc,3)                &
-                                        + ztemp*vn_b(ji,jj)*hvr(ji,jj)*vmask(ji,jj,1)
+                ana_temp(ji,jj,nhc,2) = ana_temp(ji,jj,nhc,2) + ztemp*un_b(ji,jj)*hur(ji,jj)*umask(ji,jj,1)
+                ana_temp(ji,jj,nhc,3) = ana_temp(ji,jj,nhc,3) + ztemp*vn_b(ji,jj)*hvr(ji,jj)*vmask(ji,jj,1)
 #endif
               END DO
@@ -233,5 +209,5 @@
       END IF
 
-      IF ( kt .EQ. nitend_han ) CALL dia_harm_end
+      IF ( kt == nitend_han )   CALL dia_harm_end
 
       IF( nn_timing == 1 )   CALL timing_stop('dia_harm')
@@ -239,8 +215,8 @@
    END SUBROUTINE dia_harm
 
+
    SUBROUTINE dia_harm_end
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE diaharm_end  ***
-      !!----------------------------------------------------------------------
       !!         
       !! ** Purpose :  Compute the Real and Imaginary part of tidal constituents
@@ -248,9 +224,5 @@
       !! ** Action  :  Decompose the signal on the harmonic constituents 
       !!
-      !! History :
-      !!   9.0  O. Le Galloudec and J. Chanut (Original)
-      !!--------------------------------------------------------------------
-
-      !! * Local declarations
+      !!--------------------------------------------------------------------
       INTEGER :: ji, jj, jh, jc, jn, nhan, jl
       INTEGER :: ksp, kun, keq
@@ -283,12 +255,11 @@
                nisparse(ksp) = keq
                njsparse(ksp) = kun
-               valuesparse(ksp)= &
-                   +(   MOD(jc,2) * ft(jh) * COS(ana_freq(jh)*ztime + vt(jh) + ut(jh)) &
-                   +(1.-MOD(jc,2))* ft(jh) * SIN(ana_freq(jh)*ztime + vt(jh) + ut(jh)))
+               valuesparse(ksp) = (   MOD(jc,2) * ft(jh) * COS(ana_freq(jh)*ztime + vt(jh) + ut(jh))   &
+                  &             + (1.-MOD(jc,2))* ft(jh) * SIN(ana_freq(jh)*ztime + vt(jh) + ut(jh)) )
             END DO
          END DO
       END DO
 
-      nsparse=ksp
+      nsparse = ksp
 
       ! Elevation:
@@ -296,11 +267,11 @@
          DO ji = 1, jpi
             ! Fill input array
-            kun=0
-            DO jh = 1,nb_ana
-               DO jc = 1,2
+            kun = 0
+            DO jh = 1, nb_ana
+               DO jc = 1, 2
                   kun = kun + 1
                   ztmp4(kun)=ana_temp(ji,jj,kun,1)
-               ENDDO
-            ENDDO
+               END DO
+            END DO
 
             CALL SUR_DETERMINE(jj)
@@ -314,15 +285,15 @@
       END DO
 
-      ALLOCATE(out_eta(jpi,jpj,2*nb_ana))
-      ALLOCATE(out_u  (jpi,jpj,2*nb_ana))
-      ALLOCATE(out_v  (jpi,jpj,2*nb_ana))
+      ALLOCATE( out_eta(jpi,jpj,2*nb_ana),   & 
+         &      out_u  (jpi,jpj,2*nb_ana),   &
+         &      out_v  (jpi,jpj,2*nb_ana)  )
 
       DO jj = 1, jpj
          DO ji = 1, jpi
             DO jh = 1, nb_ana 
-               X1=ana_amp(ji,jj,jh,1)
-               X2=-ana_amp(ji,jj,jh,2)
-               out_eta(ji,jj,jh)=X1 * tmask(ji,jj,1)
-               out_eta(ji,jj,nb_ana+jh)=X2 * tmask(ji,jj,1)
+               X1 = ana_amp(ji,jj,jh,1)
+               X2 =-ana_amp(ji,jj,jh,2)
+               out_eta(ji,jj,jh       ) = X1 * tmask(ji,jj,1)
+               out_eta(ji,jj,jh+nb_ana) = X2 * tmask(ji,jj,1)
             ENDDO
          ENDDO
@@ -402,17 +373,11 @@
    END SUBROUTINE dia_harm_end
 
+
    SUBROUTINE dia_wri_harm
       !!--------------------------------------------------------------------
       !!                 ***  ROUTINE dia_wri_harm  ***
-      !!--------------------------------------------------------------------
       !!         
       !! ** Purpose : Write tidal harmonic analysis results in a netcdf file
-      !!
-      !!
-      !! History :
-      !!   9.0  O. Le Galloudec and J. Chanut (Original)
-      !!--------------------------------------------------------------------
-
-      !! * Local declarations
+      !!--------------------------------------------------------------------
       CHARACTER(LEN=lc) :: cltext
       CHARACTER(LEN=lc) ::   &
@@ -472,10 +437,11 @@
 #else
       DO jh = 1, nb_ana
-      CALL iom_put( TRIM(tname(jh))//'x_v', out_u(:,:,jh) )
-      CALL iom_put( TRIM(tname(jh))//'y_v', out_u(:,:,nb_ana+jh) )
+         CALL iom_put( TRIM(tname(jh))//'x_v', out_u(:,:,jh       ) )
+         CALL iom_put( TRIM(tname(jh))//'y_v', out_u(:,:,jh+nb_ana) )
       END DO
 #endif
 
    END SUBROUTINE dia_wri_harm
+
 
    SUBROUTINE SUR_DETERMINE(init)
@@ -486,6 +452,6 @@
    !!       
    !!---------------------------------------------------------------------------------
-   INTEGER, INTENT(in) :: init 
-               
+   INTEGER, INTENT(in) ::   init 
+   !
    INTEGER                         :: ji_sd, jj_sd, ji1_sd, ji2_sd, jk1_sd, jk2_sd
    REAL(wp)                        :: zval1, zval2, zx1
@@ -496,27 +462,20 @@
    CALL wrk_alloc( jpincomax , ipos2 , ipivot        )
             
-   IF( init==1 )THEN
-
-      IF( nsparse .GT. jpdimsparse ) &
-         CALL ctl_stop( 'STOP', 'SUR_DETERMINE : nsparse .GT. jpdimsparse')
-
-      IF( ninco .GT. jpincomax ) &
-         CALL ctl_stop( 'STOP', 'SUR_DETERMINE : ninco .GT. jpincomax')
-
-      ztmp3(:,:)=0.e0
-
+   IF( init == 1 ) THEN
+      IF( nsparse > jpdimsparse )   CALL ctl_stop( 'STOP', 'SUR_DETERMINE : nsparse .GT. jpdimsparse')
+      IF( ninco   > jpincomax   )   CALL ctl_stop( 'STOP', 'SUR_DETERMINE : ninco .GT. jpincomax')
+      !
+      ztmp3(:,:) = 0._wp
+      !
       DO jk1_sd = 1, nsparse
          DO jk2_sd = 1, nsparse
-
-            nisparse(jk2_sd)=nisparse(jk2_sd)
-            njsparse(jk2_sd)=njsparse(jk2_sd)
-
+            nisparse(jk2_sd) = nisparse(jk2_sd)
+            njsparse(jk2_sd) = njsparse(jk2_sd)
             IF( nisparse(jk2_sd) == nisparse(jk1_sd) ) THEN
                ztmp3(njsparse(jk1_sd),njsparse(jk2_sd)) = ztmp3(njsparse(jk1_sd),njsparse(jk2_sd))  &
                                                         + valuesparse(jk1_sd)*valuesparse(jk2_sd)
             ENDIF
-
-         ENDDO
-      ENDDO
+         END DO
+      END DO
 
       DO jj_sd = 1 ,ninco
@@ -588,5 +547,4 @@
    ENDDO
 
-
    CALL wrk_dealloc( jpincomax , ztmpx , zcol1 , zcol2 )
    CALL wrk_dealloc( jpincomax , ipos2 , ipivot        )
@@ -594,5 +552,4 @@
   END SUBROUTINE SUR_DETERMINE
 
-
 #else
    !!----------------------------------------------------------------------
@@ -601,12 +558,10 @@
    LOGICAL, PUBLIC, PARAMETER ::   lk_diaharm = .FALSE.
 CONTAINS
-
    SUBROUTINE dia_harm ( kt )     ! Empty routine
       INTEGER, INTENT( IN ) :: kt  
       WRITE(*,*) 'dia_harm: you should not have seen this print'
    END SUBROUTINE dia_harm
-
-
-#endif
+#endif
+
    !!======================================================================
 END MODULE diaharm
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90	(revision 4292)
@@ -304,9 +304,9 @@
       ! ----------------------------- !
 
-      ! find ilevel with (ilevel+1) the deepest W-level above 300m (we assume we can use e3t_0 to do this search...)
+      ! find ilevel with (ilevel+1) the deepest W-level above 300m (we assume we can use e3t_1d to do this search...)
       ilevel   = 0
       zthick_0 = 0._wp
       DO jk = 1, jpkm1                      
-         zthick_0 = zthick_0 + e3t_0(jk)
+         zthick_0 = zthick_0 + e3t_1d(jk)
          IF( zthick_0 < 300. )   ilevel = jk
       END DO
@@ -326,6 +326,4 @@
             htc3(ji,jj) = htc3(ji,jj) + tsn(ji,jj,ilevel+1,jp_tem) * MIN( fse3t(ji,jj,ilevel+1), zthick(ji,jj) )  &
                                                                    * tmask(ji,jj,ilevel+1)
-            htc3(ji,jj) = htc3(ji,jj) + tsn(ji,jj,ilevel+1,jp_tem) * MIN( fse3t(ji,jj,ilevel+1), zthick(ji,jj) )   &
-               &                                                   * tmask(ji,jj,ilevel+1)
          END DO
       END DO
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 4292)
@@ -259,4 +259,5 @@
       !
 #if defined key_mpp_mpi
+      ijpjjpk = jpj*jpk
       ish(1) = ijpjjpk  ;   ish2(1) = jpj   ;   ish2(2) = jpk
       zwork(1:ijpjjpk) = RESHAPE( p_fval, ish )
@@ -314,4 +315,5 @@
       END DO
 #if defined key_mpp_mpi
+      ijpjjpk = jpj*jpk
       ish(1) = jpj*jpk   ;   ish2(1) = jpj   ;   ish2(2) = jpk
       zwork(1:ijpjjpk)= RESHAPE( p_fval, ish )
@@ -670,9 +672,9 @@
             CALL histbeg(clhstnam, 1, zfoo, jpj, zphi,   &
                1, 1, 1, jpj, niter, zjulian, zdt*nn_fptr, nhoridz, numptr, domain_id=nidom_ptr)
-            ! Vertical grids : gdept_0, gdepw_0
+            ! Vertical grids : gdept_1d, gdepw_1d
             CALL histvert( numptr, "deptht", "Vertical T levels",   &
-               &                   "m", jpk, gdept_0, ndepidzt, "down" )
+               &                   "m", jpk, gdept_1d, ndepidzt, "down" )
             CALL histvert( numptr, "depthw", "Vertical W levels",   &
-               &                   "m", jpk, gdepw_0, ndepidzw, "down" )
+               &                   "m", jpk, gdepw_1d, ndepidzw, "down" )
             !
             CALL wheneq ( jpj*jpk, MIN(sjk(:,:,1), 1._wp), 1, 1., ndex  , ndim  )      ! Lat-Depth
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 4292)
@@ -25,4 +25,5 @@
    USE oce             ! ocean dynamics and tracers 
    USE dom_oce         ! ocean space and time domain
+   USE dynadv, ONLY: ln_dynadv_vec
    USE zdf_oce         ! ocean vertical physics
    USE ldftra_oce      ! ocean active tracers: lateral physics
@@ -44,4 +45,5 @@
    USE diadimg         ! dimg direct access file format output
    USE diaar5, ONLY :   lk_diaar5
+   USE dynadv, ONLY :   ln_dynadv_vec
    USE iom
    USE ioipsl
@@ -144,17 +146,32 @@
       ENDIF
 
-      CALL iom_put( "toce"   , tsn(:,:,:,jp_tem)                     )    ! temperature
-      CALL iom_put( "soce"   , tsn(:,:,:,jp_sal)                     )    ! salinity
-      CALL iom_put( "sst"    , tsn(:,:,1,jp_tem)                     )    ! sea surface temperature
-      CALL iom_put( "sst2"   , tsn(:,:,1,jp_tem) * tsn(:,:,1,jp_tem) )    ! square of sea surface temperature
-      CALL iom_put( "sss"    , tsn(:,:,1,jp_sal)                     )    ! sea surface salinity
-      CALL iom_put( "sss2"   , tsn(:,:,1,jp_sal) * tsn(:,:,1,jp_sal) )    ! square of sea surface salinity
-      CALL iom_put( "uoce"   , un                                    )    ! i-current      
-      CALL iom_put( "suoce"  , un(:,:,1)                             )    ! surface i-current      
-      CALL iom_put( "voce"   , vn                                    )    ! j-current
-      CALL iom_put( "svoce"  , vn(:,:,1)                             )    ! surface j-current
- 
-      CALL iom_put( "avt"    , avt                                   )    ! T vert. eddy diff. coef.
-      CALL iom_put( "avm"    , avmu                                  )    ! T vert. eddy visc. coef.
+      IF( lk_vvl ) THEN
+         z3d(:,:,:) = tsn(:,:,:,jp_tem) * fse3t_n(:,:,:)
+         CALL iom_put( "toce" , z3d                        )   ! heat content
+         CALL iom_put( "sst"  , z3d(:,:,1)                 )   ! sea surface heat content
+         z3d(:,:,1) = tsn(:,:,1,jp_tem) * z3d(:,:,1)
+         CALL iom_put( "sst2" , z3d(:,:,1)                 )   ! sea surface content of squared temperature
+         z3d(:,:,:) = tsn(:,:,:,jp_sal) * fse3t_n(:,:,:)            
+         CALL iom_put( "soce" , z3d                        )   ! salinity content
+         CALL iom_put( "sss"  , z3d(:,:,1)                 )   ! sea surface salinity content
+         z3d(:,:,1) = tsn(:,:,1,jp_sal) * z3d(:,:,1)
+         CALL iom_put( "sss2" , z3d(:,:,1)                 )   ! sea surface content of squared salinity
+      ELSE
+         CALL iom_put( "toce" , tsn(:,:,:,jp_tem)          )   ! temperature
+         CALL iom_put( "sst"  , tsn(:,:,1,jp_tem)          )   ! sea surface temperature
+         CALL iom_put( "sst2" , tsn(:,:,1,jp_tem) * tsn(:,:,1,jp_tem) ) ! square of sea surface temperature
+         CALL iom_put( "soce" , tsn(:,:,:,jp_sal)          )   ! salinity
+         CALL iom_put( "sss"  , tsn(:,:,1,jp_sal)          )   ! sea surface salinity
+         CALL iom_put( "sss2" , tsn(:,:,1,jp_sal) * tsn(:,:,1,jp_sal) ) ! square of sea surface salinity
+      END IF
+      IF( lk_vvl .AND. (.NOT. ln_dynadv_vec) ) THEN
+         CALL iom_put( "uoce" , un(:,:,:) * fse3u_n(:,:,:) )    ! i-transport
+         CALL iom_put( "voce" , vn(:,:,:) * fse3v_n(:,:,:) )    ! j-transport
+      ELSE
+         CALL iom_put( "uoce" , un                         )    ! i-current
+         CALL iom_put( "voce" , vn                         )    ! j-current
+      END IF
+      CALL iom_put(    "avt"  , avt                        )    ! T vert. eddy diff. coef.
+      CALL iom_put(    "avm"  , avmu                       )    ! T vert. eddy visc. coef.
       IF( lk_zdfddm ) THEN
          CALL iom_put( "avs" , fsavs(:,:,:)                          )    ! S vert. eddy diff. coef.
@@ -252,5 +269,5 @@
       !
       CALL wrk_alloc( jpi , jpj      , zw2d )
-      IF ( ln_traldf_gdia )  call wrk_alloc( jpi , jpj , jpk  , zw3d )
+      IF ( ln_traldf_gdia .OR. lk_vvl )  call wrk_alloc( jpi , jpj , jpk  , zw3d )
       !
       ! Output the initial state and forcings
@@ -325,5 +342,5 @@
             &          nit000-1, zjulian, zdt, nh_T, nid_T, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_T, "deptht", "Vertical T levels",      &  ! Vertical grid: gdept
-            &           "m", ipk, gdept_0, nz_T, "down" )
+            &           "m", ipk, gdept_1d, nz_T, "down" )
          !                                                            ! Index of ocean points
          CALL wheneq( jpi*jpj*ipk, tmask, 1, 1., ndex_T , ndim_T  )      ! volume
@@ -361,5 +378,5 @@
             &          nit000-1, zjulian, zdt, nh_U, nid_U, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_U, "depthu", "Vertical U levels",      &  ! Vertical grid: gdept
-            &           "m", ipk, gdept_0, nz_U, "down" )
+            &           "m", ipk, gdept_1d, nz_U, "down" )
          !                                                            ! Index of ocean points
          CALL wheneq( jpi*jpj*ipk, umask, 1, 1., ndex_U , ndim_U  )      ! volume
@@ -374,5 +391,5 @@
             &          nit000-1, zjulian, zdt, nh_V, nid_V, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_V, "depthv", "Vertical V levels",      &  ! Vertical grid : gdept
-            &          "m", ipk, gdept_0, nz_V, "down" )
+            &          "m", ipk, gdept_1d, nz_V, "down" )
          !                                                            ! Index of ocean points
          CALL wheneq( jpi*jpj*ipk, vmask, 1, 1., ndex_V , ndim_V  )      ! volume
@@ -387,5 +404,5 @@
             &          nit000-1, zjulian, zdt, nh_W, nid_W, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_W, "depthw", "Vertical W levels",      &  ! Vertical grid: gdepw
-            &          "m", ipk, gdepw_0, nz_W, "down" )
+            &          "m", ipk, gdepw_1d, nz_W, "down" )
 
 
@@ -397,4 +414,12 @@
          CALL histdef( nid_T, "vosaline", "Salinity"                           , "PSU"    ,   &  ! sn
             &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         IF(  lk_vvl  ) THEN
+            CALL histdef( nid_T, "vovvle3t", "Level thickness"                    , "m"      ,&  ! e3t_n
+            &             jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+            CALL histdef( nid_T, "vovvldep", "T point depth"                      , "m"      ,&  ! e3t_n
+            &             jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+            CALL histdef( nid_T, "vovvldef", "Squared level deformation"          , "%^2"    ,&  ! e3t_n
+            &             jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
+         ENDIF
          !                                                                                      !!! nid_T : 2D
          CALL histdef( nid_T, "sosstsst", "Sea Surface temperature"            , "C"      ,   &  ! sst
@@ -408,12 +433,12 @@
          CALL histdef( nid_T, "sosfldow", "downward salt flux"                 , "PSU/m2/s",  &  ! sfx
             &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-#if ! defined key_vvl
-         CALL histdef( nid_T, "sosst_cd", "Concentration/Dilution term on temperature"        &  ! emp * tsn(:,:,1,jp_tem)
+         IF(  .NOT. lk_vvl  ) THEN
+            CALL histdef( nid_T, "sosst_cd", "Concentration/Dilution term on temperature"     &  ! emp * tsn(:,:,1,jp_tem)
             &                                                                  , "KgC/m2/s",  &  ! sosst_cd
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sosss_cd", "Concentration/Dilution term on salinity"           &  ! emp * tsn(:,:,1,jp_sal)
+            &             jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+            CALL histdef( nid_T, "sosss_cd", "Concentration/Dilution term on salinity"        &  ! emp * tsn(:,:,1,jp_sal)
             &                                                                  , "KgPSU/m2/s",&  ! sosss_cd
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-#endif
+            &             jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         ENDIF
          CALL histdef( nid_T, "sohefldo", "Net Downward Heat Flux"             , "W/m2"   ,   &  ! qns + qsr
             &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
@@ -587,5 +612,5 @@
       ! ---------------------
 
-      ! ndex(1) est utilise ssi l'avant dernier argument est diffferent de 
+      ! ndex(1) est utilise ssi l'avant dernier argument est different de 
       ! la taille du tableau en sortie. Dans ce cas , l'avant dernier argument
       ! donne le nombre d'elements, et ndex la liste des indices a sortir
@@ -597,8 +622,22 @@
 
       ! Write fields on T grid
-      CALL histwrite( nid_T, "votemper", it, tsn(:,:,:,jp_tem), ndim_T , ndex_T  )   ! temperature
-      CALL histwrite( nid_T, "vosaline", it, tsn(:,:,:,jp_sal), ndim_T , ndex_T  )   ! salinity
-      CALL histwrite( nid_T, "sosstsst", it, tsn(:,:,1,jp_tem), ndim_hT, ndex_hT )   ! sea surface temperature
-      CALL histwrite( nid_T, "sosaline", it, tsn(:,:,1,jp_sal), ndim_hT, ndex_hT )   ! sea surface salinity
+      IF( lk_vvl ) THEN
+         CALL histwrite( nid_T, "votemper", it, tsn(:,:,:,jp_tem) * fse3t_n(:,:,:) , ndim_T , ndex_T  )   ! heat content
+         CALL histwrite( nid_T, "vosaline", it, tsn(:,:,:,jp_sal) * fse3t_n(:,:,:) , ndim_T , ndex_T  )   ! salt content
+         CALL histwrite( nid_T, "sosstsst", it, tsn(:,:,1,jp_tem) * fse3t_n(:,:,1) , ndim_hT, ndex_hT )   ! sea surface heat content
+         CALL histwrite( nid_T, "sosaline", it, tsn(:,:,1,jp_sal) * fse3t_n(:,:,1) , ndim_hT, ndex_hT )   ! sea surface salinity content
+      ELSE
+         CALL histwrite( nid_T, "votemper", it, tsn(:,:,:,jp_tem) , ndim_T , ndex_T  )   ! temperature
+         CALL histwrite( nid_T, "vosaline", it, tsn(:,:,:,jp_sal) , ndim_T , ndex_T  )   ! salinity
+         CALL histwrite( nid_T, "sosstsst", it, tsn(:,:,1,jp_tem) , ndim_hT, ndex_hT )   ! sea surface temperature
+         CALL histwrite( nid_T, "sosaline", it, tsn(:,:,1,jp_sal) , ndim_hT, ndex_hT )   ! sea surface salinity
+
+      ENDIF
+      IF( lk_vvl ) THEN
+         zw3d(:,:,:) = ( ( fse3t_n(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2
+         CALL histwrite( nid_T, "vovvle3t", it, fse3t_n (:,:,:) , ndim_T , ndex_T  )   ! level thickness
+         CALL histwrite( nid_T, "vovvldep", it, fsdept_n(:,:,:) , ndim_T , ndex_T  )   ! t-point depth
+         CALL histwrite( nid_T, "vovvldef", it, zw3d             , ndim_T , ndex_T  )   ! level thickness deformation
+      ENDIF
       CALL histwrite( nid_T, "sossheig", it, sshn          , ndim_hT, ndex_hT )   ! sea surface height
       CALL histwrite( nid_T, "sowaflup", it, ( emp-rnf )   , ndim_hT, ndex_hT )   ! upward water flux
@@ -606,10 +645,10 @@
                                                                                   ! (includes virtual salt flux beneath ice 
                                                                                   ! in linear free surface case)
-#if ! defined key_vvl
-      zw2d(:,:) = emp (:,:) * tsn(:,:,1,jp_tem)
-      CALL histwrite( nid_T, "sosst_cd", it, zw2d, ndim_hT, ndex_hT )             ! c/d term on sst
-      zw2d(:,:) = emp (:,:) * tsn(:,:,1,jp_sal)
-      CALL histwrite( nid_T, "sosss_cd", it, zw2d, ndim_hT, ndex_hT )             ! c/d term on sss
-#endif
+      IF( .NOT. lk_vvl ) THEN
+         zw2d(:,:) = emp (:,:) * tsn(:,:,1,jp_tem)
+         CALL histwrite( nid_T, "sosst_cd", it, zw2d, ndim_hT, ndex_hT )          ! c/d term on sst
+         zw2d(:,:) = emp (:,:) * tsn(:,:,1,jp_sal)
+         CALL histwrite( nid_T, "sosss_cd", it, zw2d, ndim_hT, ndex_hT )          ! c/d term on sss
+      ENDIF
       CALL histwrite( nid_T, "sohefldo", it, qns + qsr     , ndim_hT, ndex_hT )   ! total heat flux
       CALL histwrite( nid_T, "soshfldo", it, qsr           , ndim_hT, ndex_hT )   ! solar heat flux
@@ -752,5 +791,5 @@
       !
       CALL wrk_dealloc( jpi , jpj      , zw2d )
-      IF ( ln_traldf_gdia )  call wrk_dealloc( jpi , jpj , jpk  , zw3d )
+      IF ( ln_traldf_gdia .OR. lk_vvl )  call wrk_dealloc( jpi , jpj , jpk  , zw3d )
       !
       IF( nn_timing == 1 )   CALL timing_stop('dia_wri')
@@ -813,5 +852,5 @@
           1, jpi, 1, jpj, nit000-1, zjulian, zdt, nh_i, id_i, domain_id=nidom, snc4chunks=snc4set ) ! Horizontal grid : glamt and gphit
       CALL histvert( id_i, "deptht", "Vertical T levels",   &    ! Vertical grid : gdept
-          "m", jpk, gdept_0, nz_i, "down")
+          "m", jpk, gdept_1d, nz_i, "down")
 
       ! Declare all the output fields as NetCDF variables
@@ -841,4 +880,8 @@
       CALL histdef( id_i, "sometauy", "Meridional Wind Stress", "N/m2"   ,   &   ! j-wind stress
          &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+      IF( lk_vvl ) THEN
+         CALL histdef( id_i, "vovvldep", "T point depth"         , "m"      ,   &   ! t-point depth
+            &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
+      END IF
 
 #if defined key_lim2
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 4292)
@@ -152,8 +152,8 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  gphit, gphiu   !: latitude  of t-, u-, v- and f-points (degre)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  gphiv, gphif   !:
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  e1t, e2t       !: horizontal scale factors at t-point (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  e1u, e2u       !: horizontal scale factors at u-point (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  e1v, e2v       !: horizontal scale factors at v-point (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  e1f, e2f       !: horizontal scale factors at f-point (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, TARGET, DIMENSION(:,:) ::  e1t, e2t       !: horizontal scale factors at t-point (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, TARGET, DIMENSION(:,:) ::  e1u, e2u       !: horizontal scale factors at u-point (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, TARGET, DIMENSION(:,:) ::  e1v, e2v       !: horizontal scale factors at v-point (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, TARGET, DIMENSION(:,:) ::  e1f, e2f       !: horizontal scale factors at f-point (m)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  e1e2t          !: surface at t-point (m2)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ff             !: coriolis factor (2.*omega*sin(yphi) ) (s-1)
@@ -169,10 +169,10 @@
    !! All coordinates
    !! ---------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdep3w          !: depth of T-points (sum of e3w) (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdept , gdepw   !: analytical depth at T-W  points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3v   , e3f     !: analytical vertical scale factors at  V--F
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3t   , e3u     !:                                       T--U  points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3vw            !: analytical vertical scale factors at  VW--
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3w   , e3uw    !:                                        W--UW  points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdep3w_0           !: depth of t-points (sum of e3w) (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdept_0, gdepw_0   !: analytical (time invariant) depth at t-w  points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3v_0  , e3f_0     !: analytical (time invariant) vertical scale factors at  v-f
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3t_0  , e3u_0     !:                                      t-u  points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3vw_0             !: analytical (time invariant) vertical scale factors at  vw
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3w_0  , e3uw_0    !:                                      w-uw points (m)
 #if defined key_vvl
    LOGICAL, PUBLIC, PARAMETER ::   lk_vvl = .TRUE.    !: variable grid flag
@@ -180,18 +180,28 @@
    !! All coordinates
    !! ---------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdep3w_1           !: depth of T-points (sum of e3w) (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdept_1, gdepw_1   !: analytical depth at T-W  points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3v_1  , e3f_1     !: analytical vertical scale factors at  V--F
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3t_1  , e3u_1     !:                                       T--U  points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3vw_1             !: analytical vertical scale factors at  VW--
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3w_1  , e3uw_1    !:                                       W--UW  points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3t_b              !: before         -      -      -    -   T      points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3u_b  , e3v_b     !:   -            -      -      -    -   U--V   points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdep3w_n           !: now depth of T-points (sum of e3w) (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdept_n, gdepw_n   !: now depth at T-W  points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3t_n              !: now    vertical scale factors at  t       point  (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3u_n  , e3v_n     !:            -      -      -    -   u --v   points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3w_n  , e3f_n     !:            -      -      -    -   w --f   points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3uw_n , e3vw_n    !:            -      -      -    -   uw--vw  points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3t_b              !: before     -      -      -    -   t       points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3u_b  , e3v_b     !:   -        -      -      -    -   u --v   points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3uw_b , e3vw_b    !:   -        -      -      -    -   uw--vw  points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3t_a              !: after      -      -      -    -   t       point  (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e3u_a  , e3v_a     !:   -        -      -      -    -   u --v   points (m)
 #else
    LOGICAL, PUBLIC, PARAMETER ::   lk_vvl = .FALSE.   !: fixed grid flag
 #endif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:), TARGET ::   hur  , hvr    !: inverse of u and v-points ocean depth (1/m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   hu   , hv     !: depth at u- and v-points (meters)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   hu_0 , hv_0   !: refernce depth at u- and v-points (meters)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:), TARGET ::   hur  , hvr     !: inverse of u and v-points ocean depth (1/m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   hu   , hv      !: depth at u- and v-points (meters)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   ht_0           !: reference depth at t-       points (meters)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   hu_0 , hv_0    !: reference depth at u- and v-points (meters)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   re2u_e1u       !: scale factor coeffs at u points (e2u/e1u)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   re1v_e2v       !: scale factor coeffs at v points (e1v/e2v)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   e12t , r1_e12t !: horizontal cell surface and inverse at t points
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   e12u , r1_e12u !: horizontal cell surface and inverse at u points
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   e12v , r1_e12v !: horizontal cell surface and inverse at v points
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   e12f , r1_e12f !: horizontal cell surface and inverse at f points
 
    INTEGER, PUBLIC ::   nla10              !: deepest    W level Above  ~10m (nlb10 - 1)
@@ -200,39 +210,39 @@
    !! z-coordinate with full steps (also used in the other cases as reference z-coordinate)
    !! =-----------------====------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   :: gdept_0, gdepw_0 !: reference depth of t- and w-points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   :: e3t_0  , e3w_0   !: reference vertical scale factors at T- and W-pts (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: e3tp   , e3wp    !: ocean bottom level thickness at T and W points
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   gdept_1d, gdepw_1d !: reference depth of t- and w-points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   e3t_1d  , e3w_1d   !: reference vertical scale factors at T- and W-pts (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   e3tp    , e3wp     !: ocean bottom level thickness at T and W points
 
    !! s-coordinate and hybrid z-s-coordinate
    !! =----------------======---------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   gsigt, gsigw   !: model level depth coefficient at t-, w-levels (analytic)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   gsi3w          !: model level depth coefficient at w-level (sum of gsigw)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   esigt, esigw   !: vertical scale factor coef. at t-, w-levels
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hbatv , hbatf    !: ocean depth at the vertical of  V--F
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hbatt , hbatu    !:                                 T--U  points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   scosrf, scobot   !: ocean surface and bottom topographies 
-   !                                        !  (if deviating from coordinate surfaces in HYBRID)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hifv  , hiff     !: interface depth between stretching at  V--F
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hift  , hifu     !: and quasi-uniform spacing              T--U  points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rx1              !: Maximum grid stiffness ratio
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   gsigt, gsigw       !: model level depth coefficient at t-, w-levels (analytic)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   gsi3w              !: model level depth coefficient at w-level (sum of gsigw)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   esigt, esigw       !: vertical scale factor coef. at t-, w-levels
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hbatv , hbatf      !: ocean depth at the vertical of  v--f
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hbatt , hbatu      !:                                 t--u points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   scosrf, scobot     !: ocean surface and bottom topographies 
+   !                                                                           !  (if deviating from coordinate surfaces in HYBRID)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hifv  , hiff       !: interface depth between stretching at v--f
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hift  , hifu       !: and quasi-uniform spacing             t--u points (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   rx1                !: Maximum grid stiffness ratio
 
    !!----------------------------------------------------------------------
    !! masks, bathymetry
    !! ---------------------------------------------------------------------
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbathy       !: number of ocean level (=0, 1, ... , jpk-1)
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbkt         !: vertical index of the bottom last T- ocean level
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbku, mbkv   !: vertical index of the bottom last U- and W- ocean level
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bathy        !: ocean depth (meters)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmask_i      !: interior domain T-point mask
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bmask        !: land/ocean mask of barotropic stream function
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: tmask, umask, vmask, fmask   !: land/ocean mask at T-, U-, V- and F-pts
+   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbathy             !: number of ocean level (=0, 1, ... , jpk-1)
+   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbkt               !: vertical index of the bottom last T- ocean level
+   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbku, mbkv         !: vertical index of the bottom last U- and W- ocean level
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bathy              !: ocean depth (meters)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmask_i            !: interior domain T-point mask
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bmask              !: land/ocean mask of barotropic stream function
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:), TARGET :: tmask, umask, vmask, fmask   !: land/ocean mask at T-, U-, V- and F-pts
 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   tpol, fpol          !: north fold mask (jperio= 3 or 4)
 
 #if defined key_noslip_accurate
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:  ) :: npcoa        !: ???
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: nicoa, njcoa !: ???
+   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:  )  :: npcoa              !: ???
+   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  :: nicoa, njcoa       !: ???
 #endif
 
@@ -316,22 +326,29 @@
          &      glamf(jpi,jpj) , gphif(jpi,jpj) , e1f(jpi,jpj) , e2f(jpi,jpj) , ff   (jpi,jpj) , STAT=ierr(3) )     
          !
-      ALLOCATE( gdep3w(jpi,jpj,jpk) , e3v(jpi,jpj,jpk) , e3f (jpi,jpj,jpk) ,                         &
-         &      gdept (jpi,jpj,jpk) , e3t(jpi,jpj,jpk) , e3u (jpi,jpj,jpk) ,                         &
-         &      gdepw (jpi,jpj,jpk) , e3w(jpi,jpj,jpk) , e3vw(jpi,jpj,jpk) , e3uw(jpi,jpj,jpk) , STAT=ierr(4) )
+      ALLOCATE( gdep3w_0(jpi,jpj,jpk) , e3v_0(jpi,jpj,jpk) , e3f_0 (jpi,jpj,jpk) ,                         &
+         &      gdept_0 (jpi,jpj,jpk) , e3t_0(jpi,jpj,jpk) , e3u_0 (jpi,jpj,jpk) ,                         &
+         &      gdepw_0 (jpi,jpj,jpk) , e3w_0(jpi,jpj,jpk) , e3vw_0(jpi,jpj,jpk) , e3uw_0(jpi,jpj,jpk) , STAT=ierr(4) )
          !
 #if defined key_vvl
-      ALLOCATE( gdep3w_1(jpi,jpj,jpk) , e3v_1(jpi,jpj,jpk) , e3f_1 (jpi,jpj,jpk) ,                           &
-         &      gdept_1 (jpi,jpj,jpk) , e3t_1(jpi,jpj,jpk) , e3u_1 (jpi,jpj,jpk) ,                           &
-         &      gdepw_1 (jpi,jpj,jpk) , e3w_1(jpi,jpj,jpk) , e3vw_1(jpi,jpj,jpk) , e3uw_1(jpi,jpj,jpk) ,     &
-         &      e3t_b   (jpi,jpj,jpk) , e3u_b(jpi,jpj,jpk) , e3v_b (jpi,jpj,jpk)                       , STAT=ierr(5) )
-#endif
-         !
-      ALLOCATE( hu(jpi,jpj) , hur(jpi,jpj) , hu_0(jpi,jpj) ,     &
-         &      hv(jpi,jpj) , hvr(jpi,jpj) , hv_0(jpi,jpj) , STAT=ierr(6) )
-         !
-      ALLOCATE( gdept_0(jpk) , gdepw_0(jpk) ,                                     &
-         &      e3t_0  (jpk) , e3w_0  (jpk) , e3tp (jpi,jpj), e3wp(jpi,jpj) ,     &
-         &      gsigt  (jpk) , gsigw  (jpk) , gsi3w(jpk)    ,                     &
-         &      esigt  (jpk) , esigw  (jpk)                                 , STAT=ierr(7) )
+      ALLOCATE( gdep3w_n(jpi,jpj,jpk) , e3t_n (jpi,jpj,jpk) , e3u_n (jpi,jpj,jpk) ,                           &
+         &      gdept_n (jpi,jpj,jpk) , e3v_n (jpi,jpj,jpk) , e3w_n (jpi,jpj,jpk) ,                           &
+         &      gdepw_n (jpi,jpj,jpk) , e3f_n (jpi,jpj,jpk) , e3vw_n(jpi,jpj,jpk) , e3uw_n(jpi,jpj,jpk) ,     &
+         &      e3t_b   (jpi,jpj,jpk) , e3u_b (jpi,jpj,jpk) , e3v_b (jpi,jpj,jpk) ,                           &
+         &      e3uw_b  (jpi,jpj,jpk) , e3vw_b(jpi,jpj,jpk) ,                                                 &
+         &      e3t_a   (jpi,jpj,jpk) , e3u_a (jpi,jpj,jpk) , e3v_a (jpi,jpj,jpk)                       , STAT=ierr(5) )
+#endif
+         !
+      ALLOCATE( hu      (jpi,jpj) , hur     (jpi,jpj) , hu_0(jpi,jpj) , ht_0  (jpi,jpj) ,     &
+         &      hv      (jpi,jpj) , hvr     (jpi,jpj) , hv_0(jpi,jpj) ,                       &
+         &      re2u_e1u(jpi,jpj) , re1v_e2v(jpi,jpj) ,                                       &
+         &      e12t    (jpi,jpj) , r1_e12t (jpi,jpj) ,                                       &
+         &      e12u    (jpi,jpj) , r1_e12u (jpi,jpj) ,                                       &
+         &      e12v    (jpi,jpj) , r1_e12v (jpi,jpj) ,                                       &
+         &      e12f    (jpi,jpj) , r1_e12f (jpi,jpj) ,                                   STAT=ierr(6)  )
+         !
+      ALLOCATE( gdept_1d(jpk) , gdepw_1d(jpk) ,                                     &
+         &      e3t_1d  (jpk) , e3w_1d  (jpk) , e3tp (jpi,jpj), e3wp(jpi,jpj) ,     &
+         &      gsigt   (jpk) , gsigw   (jpk) , gsi3w(jpk)    ,                     &
+         &      esigt   (jpk) , esigw   (jpk)                                 , STAT=ierr(7) )
          !
       ALLOCATE( hbatv (jpi,jpj) , hbatf (jpi,jpj) ,     &
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 4292)
@@ -87,13 +87,26 @@
                              CALL dom_msk      ! Masks
       IF( ln_sco )           CALL dom_stiff    ! Maximum stiffness ratio/hydrostatic consistency
-      IF( lk_vvl         )   CALL dom_vvl      ! Vertical variable mesh
+      IF( lk_vvl )           CALL dom_vvl_init ! Vertical variable mesh
       !
       IF( lk_c1d         )   CALL cor_c1d      ! 1D configuration: Coriolis set at T-point
+      !
+      ! - ML - Used in dom_vvl_sf_nxt and lateral diffusion routines
+      !        but could be usefull in many other routines
+      e12t    (:,:) = e1t(:,:) * e2t(:,:)
+      e12u    (:,:) = e1u(:,:) * e2u(:,:)
+      e12v    (:,:) = e1v(:,:) * e2v(:,:)
+      e12f    (:,:) = e1f(:,:) * e2f(:,:)
+      r1_e12t (:,:) = 1._wp    / e12t(:,:)
+      r1_e12u (:,:) = 1._wp    / e12u(:,:)
+      r1_e12v (:,:) = 1._wp    / e12v(:,:)
+      r1_e12f (:,:) = 1._wp    / e12f(:,:)
+      re2u_e1u(:,:) = e2u(:,:) / e1u(:,:)
+      re1v_e2v(:,:) = e1v(:,:) / e2v(:,:)
       !
       hu(:,:) = 0._wp                          ! Ocean depth at U- and V-points
       hv(:,:) = 0._wp
       DO jk = 1, jpk
-         hu(:,:) = hu(:,:) + fse3u(:,:,jk) * umask(:,:,jk)
-         hv(:,:) = hv(:,:) + fse3v(:,:,jk) * vmask(:,:,jk)
+         hu(:,:) = hu(:,:) + fse3u_n(:,:,jk) * umask(:,:,jk)
+         hv(:,:) = hv(:,:) + fse3v_n(:,:,jk) * vmask(:,:,jk)
       END DO
       !                                        ! Inverse of the local depth
@@ -407,20 +420,20 @@
          DO jj = 2, jpjm1
             DO jk = 1, jpkm1
-               zr1(1) = umask(ji-1,jj  ,jk) *abs( (gdepw(ji  ,jj  ,jk  )-gdepw(ji-1,jj  ,jk  )  & 
-                    &                         +gdepw(ji  ,jj  ,jk+1)-gdepw(ji-1,jj  ,jk+1)) &
-                    &                        /(gdepw(ji  ,jj  ,jk  )+gdepw(ji-1,jj  ,jk  )  &
-                    &                         -gdepw(ji  ,jj  ,jk+1)-gdepw(ji-1,jj  ,jk+1) + rsmall) )
-               zr1(2) = umask(ji  ,jj  ,jk) *abs( (gdepw(ji+1,jj  ,jk  )-gdepw(ji  ,jj  ,jk  )  &
-                    &                         +gdepw(ji+1,jj  ,jk+1)-gdepw(ji  ,jj  ,jk+1)) &
-                    &                        /(gdepw(ji+1,jj  ,jk  )+gdepw(ji  ,jj  ,jk  )  &
-                    &                         -gdepw(ji+1,jj  ,jk+1)-gdepw(ji  ,jj  ,jk+1) + rsmall) )
-               zr1(3) = vmask(ji  ,jj  ,jk) *abs( (gdepw(ji  ,jj+1,jk  )-gdepw(ji  ,jj  ,jk  )  &
-                    &                         +gdepw(ji  ,jj+1,jk+1)-gdepw(ji  ,jj  ,jk+1)) &
-                    &                        /(gdepw(ji  ,jj+1,jk  )+gdepw(ji  ,jj  ,jk  )  &
-                    &                         -gdepw(ji  ,jj+1,jk+1)-gdepw(ji  ,jj  ,jk+1) + rsmall) )
-               zr1(4) = vmask(ji  ,jj-1,jk) *abs( (gdepw(ji  ,jj  ,jk  )-gdepw(ji  ,jj-1,jk  )  &
-                    &                         +gdepw(ji  ,jj  ,jk+1)-gdepw(ji  ,jj-1,jk+1)) &
-                    &                        /(gdepw(ji  ,jj  ,jk  )+gdepw(ji  ,jj-1,jk  )  &
-                    &                         -gdepw(ji,  jj  ,jk+1)-gdepw(ji  ,jj-1,jk+1) + rsmall) )
+               zr1(1) = umask(ji-1,jj  ,jk) *abs( (gdepw_0(ji  ,jj  ,jk  )-gdepw_0(ji-1,jj  ,jk  )  & 
+                    &                         +gdepw_0(ji  ,jj  ,jk+1)-gdepw_0(ji-1,jj  ,jk+1)) &
+                    &                        /(gdepw_0(ji  ,jj  ,jk  )+gdepw_0(ji-1,jj  ,jk  )  &
+                    &                         -gdepw_0(ji  ,jj  ,jk+1)-gdepw_0(ji-1,jj  ,jk+1) + rsmall) )
+               zr1(2) = umask(ji  ,jj  ,jk) *abs( (gdepw_0(ji+1,jj  ,jk  )-gdepw_0(ji  ,jj  ,jk  )  &
+                    &                         +gdepw_0(ji+1,jj  ,jk+1)-gdepw_0(ji  ,jj  ,jk+1)) &
+                    &                        /(gdepw_0(ji+1,jj  ,jk  )+gdepw_0(ji  ,jj  ,jk  )  &
+                    &                         -gdepw_0(ji+1,jj  ,jk+1)-gdepw_0(ji  ,jj  ,jk+1) + rsmall) )
+               zr1(3) = vmask(ji  ,jj  ,jk) *abs( (gdepw_0(ji  ,jj+1,jk  )-gdepw_0(ji  ,jj  ,jk  )  &
+                    &                         +gdepw_0(ji  ,jj+1,jk+1)-gdepw_0(ji  ,jj  ,jk+1)) &
+                    &                        /(gdepw_0(ji  ,jj+1,jk  )+gdepw_0(ji  ,jj  ,jk  )  &
+                    &                         -gdepw_0(ji  ,jj+1,jk+1)-gdepw_0(ji  ,jj  ,jk+1) + rsmall) )
+               zr1(4) = vmask(ji  ,jj-1,jk) *abs( (gdepw_0(ji  ,jj  ,jk  )-gdepw_0(ji  ,jj-1,jk  )  &
+                    &                         +gdepw_0(ji  ,jj  ,jk+1)-gdepw_0(ji  ,jj-1,jk+1)) &
+                    &                        /(gdepw_0(ji  ,jj  ,jk  )+gdepw_0(ji  ,jj-1,jk  )  &
+                    &                         -gdepw_0(ji,  jj  ,jk+1)-gdepw_0(ji  ,jj-1,jk+1) + rsmall) )
                zrxmax = MAXVAL(zr1(1:4))
                rx1(ji,jj) = MAX(rx1(ji,jj), zrxmax)
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domstp.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domstp.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domstp.F90	(revision 4292)
@@ -90,9 +90,9 @@
 
             DO jk = 1, jpk
-               IF( gdept_0(jk) <= rdth ) rdttra(jk) = rdtmin
-               IF( gdept_0(jk) >  rdth ) THEN
+               IF( gdept_1d(jk) <= rdth ) rdttra(jk) = rdtmin
+               IF( gdept_1d(jk) >  rdth ) THEN
                   rdttra(jk) = rdtmin + ( rdtmax - rdtmin )   &
-                                      * ( EXP( ( gdept_0(jk ) - rdth ) / rdth ) - 1. )   &
-                                      / ( EXP( ( gdept_0(jpk) - rdth ) / rdth ) - 1. )
+                                      * ( EXP( ( gdept_1d(jk ) - rdth ) / rdth ) - 1. )   &
+                                      / ( EXP( ( gdept_1d(jpk) - rdth ) / rdth ) - 1. )
                ENDIF
                IF(lwp) WRITE(numout,"(36x,f5.2,5x,i3)") rdttra(jk)/3600., jk
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90	(revision 4292)
@@ -6,16 +6,26 @@
    !! History :  2.0  !  2006-06  (B. Levier, L. Marie)  original code
    !!            3.1  !  2009-02  (G. Madec, M. Leclair, R. Benshila)  pure z* coordinate
-   !!----------------------------------------------------------------------
-#if defined key_vvl
+   !!            3.3  !  2011-10  (M. Leclair) totally rewrote domvvl:
+   !!                                          vvl option includes z_star and z_tilde coordinates
    !!----------------------------------------------------------------------
    !!   'key_vvl'                              variable volume
    !!----------------------------------------------------------------------
-   !!   dom_vvl     : defined coefficients to distribute ssh on each layers
    !!----------------------------------------------------------------------
+   !!   dom_vvl_init     : define initial vertical scale factors, depths and column thickness
+   !!   dom_vvl_sf_nxt   : Compute next vertical scale factors
+   !!   dom_vvl_sf_swp   : Swap vertical scale factors and update the vertical grid
+   !!   dom_vvl_interpol : Interpolate vertical scale factors from one grid point to another
+   !!   dom_vvl_rst      : read/write restart file
+   !!   dom_vvl_ctl      : Check the vvl options
+   !!   dom_vvl_orca_fix : Recompute some area-weighted interpolations of vertical scale factors 
+   !!                    : to account for manual changes to e[1,2][u,v] in some Straits 
+   !!----------------------------------------------------------------------
+   !! * Modules used
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
-   USE sbc_oce         ! surface boundary condition: ocean
-   USE phycst          ! physical constants
+   USE sbc_oce         ! ocean surface boundary condition
    USE in_out_manager  ! I/O manager
+   USE iom             ! I/O manager library
+   USE restart         ! ocean restart
    USE lib_mpp         ! distributed memory computing library
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
@@ -26,12 +36,32 @@
    PRIVATE
 
-   PUBLIC   dom_vvl         ! called by domain.F90
-   PUBLIC   dom_vvl_2       ! called by domain.F90
-   PUBLIC   dom_vvl_alloc   ! called by nemogcm.F90
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   mut , muu , muv , muf    !: 1/H_0 at t-,u-,v-,f-points 
-
-   REAL(wp),         ALLOCATABLE, SAVE, DIMENSION(:)     ::   r2dt   ! vertical profile time-step, = 2 rdttra 
-      !                                                              ! except at nit000 (=rdttra) if neuler=0
+   !! * Routine accessibility
+   PUBLIC  dom_vvl_init       ! called by domain.F90
+   PUBLIC  dom_vvl_sf_nxt     ! called by step.F90
+   PUBLIC  dom_vvl_sf_swp     ! called by step.F90
+   PUBLIC  dom_vvl_interpol   ! called by dynnxt.F90
+   PRIVATE dom_vvl_orca_fix   ! called by dom_vvl_interpol
+
+   !!* Namelist nam_vvl
+   LOGICAL , PUBLIC                                      :: ln_vvl_zstar           = .FALSE.   ! zstar  vertical coordinate
+   LOGICAL , PUBLIC                                      :: ln_vvl_ztilde          = .FALSE.   ! ztilde vertical coordinate
+   LOGICAL , PUBLIC                                      :: ln_vvl_layer           = .FALSE.   ! level  vertical coordinate
+   LOGICAL , PUBLIC                                      :: ln_vvl_ztilde_as_zstar = .FALSE.   ! ztilde vertical coordinate
+   LOGICAL , PUBLIC                                      :: ln_vvl_zstar_at_eqtor  = .FALSE.   ! ztilde vertical coordinate
+   LOGICAL , PUBLIC                                      :: ln_vvl_kepe            = .FALSE.   ! kinetic/potential energy transfer
+   !                                                                                           ! conservation: not used yet
+   REAL(wp)                                              :: rn_ahe3                =  0.0_wp   ! thickness diffusion coefficient
+   REAL(wp)                                              :: rn_rst_e3t             =  30._wp   ! ztilde to zstar restoration timescale [days]
+   REAL(wp)                                              :: rn_lf_cutoff           =  5.0_wp   ! cutoff frequency for low-pass filter  [days]
+   REAL(wp)                                              :: rn_zdef_max            =  0.9_wp   ! maximum fractional e3t deformation
+   LOGICAL , PUBLIC                                      :: ln_vvl_dbg             = .FALSE.   ! debug control prints
+
+   !! * Module variables
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: un_td, vn_td                       ! thickness diffusion transport
+   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: hdiv_lf                            ! low frequency part of hz divergence
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: tilde_e3t_b, tilde_e3t_n           ! baroclinic scale factors
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: tilde_e3t_a                        ! baroclinic scale factors
+   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: frq_rst_e3t                        ! retoring period for scale factors
+   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: frq_rst_hdv                        ! retoring period for low freq. divergence
 
    !! * Substitutions
@@ -39,197 +69,894 @@
 #  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)
    !!----------------------------------------------------------------------
-CONTAINS       
+
+CONTAINS
 
    INTEGER FUNCTION dom_vvl_alloc()
       !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_alloc  ***
-      !!----------------------------------------------------------------------
+      !!                ***  FUNCTION dom_vvl_alloc  ***
+      !!----------------------------------------------------------------------
+      IF( ln_vvl_zstar ) dom_vvl_alloc = 0
+      IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
+         ALLOCATE( tilde_e3t_b(jpi,jpj,jpk) , tilde_e3t_n(jpi,jpj,jpk) , tilde_e3t_a(jpi,jpj,jpk) ,   &
+            &      un_td  (jpi,jpj,jpk)     , vn_td  (jpi,jpj,jpk)     , STAT = dom_vvl_alloc        )
+         IF( lk_mpp             )   CALL mpp_sum ( dom_vvl_alloc )
+         IF( dom_vvl_alloc /= 0 )   CALL ctl_warn('dom_vvl_alloc: failed to allocate arrays')
+         un_td = 0.0_wp
+         vn_td = 0.0_wp
+      ENDIF
+      IF( ln_vvl_ztilde ) THEN
+         ALLOCATE( frq_rst_e3t(jpi,jpj) , frq_rst_hdv(jpi,jpj) , hdiv_lf(jpi,jpj,jpk) , STAT= dom_vvl_alloc )
+         IF( lk_mpp             )   CALL mpp_sum ( dom_vvl_alloc )
+         IF( dom_vvl_alloc /= 0 )   CALL ctl_warn('dom_vvl_alloc: failed to allocate arrays')
+      ENDIF
+
+   END FUNCTION dom_vvl_alloc
+
+
+   SUBROUTINE dom_vvl_init
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE dom_vvl_init  ***
+      !!                   
+      !! ** Purpose :  Initialization of all scale factors, depths
+      !!               and water column heights
+      !!
+      !! ** Method  :  - use restart file and/or initialize
+      !!               - interpolate scale factors
+      !!
+      !! ** Action  : - fse3t_(n/b) and tilde_e3t_(n/b)
+      !!              - Regrid: fse3(u/v)_n
+      !!                        fse3(u/v)_b       
+      !!                        fse3w_n           
+      !!                        fse3(u/v)w_b      
+      !!                        fse3(u/v)w_n      
+      !!                        fsdept_n, fsdepw_n and fsde3w_n
+      !!              - h(t/u/v)_0
+      !!              - frq_rst_e3t and frq_rst_hdv
+      !!
+      !! Reference  : Leclair, M., and G. Madec, 2011, Ocean Modelling.
+      !!----------------------------------------------------------------------
+      USE phycst,  ONLY : rpi, rsmall, rad
+      !! * Local declarations
+      INTEGER ::   ji,jj,jk
+      INTEGER ::   ii0, ii1, ij0, ij1
+      !!----------------------------------------------------------------------
+      IF( nn_timing == 1 )  CALL timing_start('dom_vvl_init')
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'dom_vvl_init : Variable volume activated'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
+
+      ! choose vertical coordinate (z_star, z_tilde or layer)
+      ! ==========================
+      CALL dom_vvl_ctl
+
+      ! Allocate module arrays
+      ! ======================
+      IF( dom_vvl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl_init : unable to allocate arrays' )
+
+      ! Read or initialize fse3t_(b/n), tilde_e3t_(b/n) and hdiv_lf (and e3t_a(jpk))
+      ! ============================================================================
+      CALL dom_vvl_rst( nit000, 'READ' )
+      fse3t_a(:,:,jpk) = e3t_0(:,:,jpk)
+
+      ! 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
+      ! Reference water column height at t-, u- and v- point
+      ! ----------------------------------------------------
+      ht_0(:,:) = 0.0_wp
+      hu_0(:,:) = 0.0_wp
+      hv_0(:,:) = 0.0_wp
+      DO jk = 1, jpk
+         ht_0(:,:) = ht_0(:,:) + e3t_0(:,:,jk) * tmask(:,:,jk)
+         hu_0(:,:) = hu_0(:,:) + e3u_0(:,:,jk) * umask(:,:,jk)
+         hv_0(:,:) = hv_0(:,:) + e3v_0(:,:,jk) * vmask(:,:,jk)
+      END DO
+
+      ! Restoring frequencies for z_tilde coordinate
+      ! ============================================
+      IF( ln_vvl_ztilde ) THEN
+         ! Values in days provided via the namelist; use rsmall to avoid possible division by zero errors with faulty settings
+         frq_rst_e3t(:,:) = 2.0_wp * rpi / ( MAX( rn_rst_e3t  , rsmall ) * 86400.0_wp )
+         frq_rst_hdv(:,:) = 2.0_wp * rpi / ( MAX( rn_lf_cutoff, rsmall ) * 86400.0_wp )
+         IF( ln_vvl_ztilde_as_zstar ) THEN
+            ! Ignore namelist settings and use these next two to emulate z-star using z-tilde
+            frq_rst_e3t(:,:) = 0.0_wp 
+            frq_rst_hdv(:,:) = 1.0_wp / rdt
+         ENDIF
+         IF ( ln_vvl_zstar_at_eqtor ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF( ABS(gphit(ji,jj)) >= 6.) THEN
+                     ! values outside the equatorial band and transition zone (ztilde)
+                     frq_rst_e3t(ji,jj) =  2.0_wp * rpi / ( MAX( rn_rst_e3t  , rsmall ) * 86400.e0_wp )
+                     frq_rst_hdv(ji,jj) =  2.0_wp * rpi / ( MAX( rn_lf_cutoff, rsmall ) * 86400.e0_wp )
+                  ELSEIF( ABS(gphit(ji,jj)) <= 2.5) THEN
+                     ! values inside the equatorial band (ztilde as zstar)
+                     frq_rst_e3t(ji,jj) =  0.0_wp
+                     frq_rst_hdv(ji,jj) =  1.0_wp / rdt
+                  ELSE
+                     ! values in the transition band (linearly vary from ztilde to ztilde as zstar values)
+                     frq_rst_e3t(ji,jj) = 0.0_wp + (frq_rst_e3t(ji,jj)-0.0_wp)*0.5_wp   &
+                        &            * (  1.0_wp - COS( rad*(ABS(gphit(ji,jj))-2.5_wp)  &
+                        &                                          * 180._wp / 3.5_wp ) )
+                     frq_rst_hdv(ji,jj) = (1.0_wp / rdt)                                &
+                        &            + (  frq_rst_hdv(ji,jj)-(1.e0_wp / rdt) )*0.5_wp   &
+                        &            * (  1._wp  - COS( rad*(ABS(gphit(ji,jj))-2.5_wp)  &
+                        &                                          * 180._wp / 3.5_wp ) )
+                  ENDIF
+               END DO
+            END DO
+            IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN
+               ii0 = 103   ;   ii1 = 111        ! Suppress ztilde in the Foxe Basin for ORCA2
+               ij0 = 128   ;   ij1 = 135   ;   
+               frq_rst_e3t( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  0.0_wp
+               frq_rst_hdv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  1.e0_wp / rdt
+            ENDIF
+         ENDIF
+      ENDIF
+
+      IF( nn_timing == 1 )  CALL timing_stop('dom_vvl_init')
+
+   END SUBROUTINE dom_vvl_init
+
+
+   SUBROUTINE dom_vvl_sf_nxt( kt ) 
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE dom_vvl_sf_nxt  ***
+      !!                   
+      !! ** Purpose :  - compute the after scale factors used in tra_zdf, dynnxt,
+      !!                 tranxt and dynspg routines
+      !!
+      !! ** Method  :  - z_star case:  Repartition of ssh INCREMENT proportionnaly to the level thickness.
+      !!               - z_tilde_case: after scale factor increment = 
+      !!                                    high frequency part of horizontal divergence
+      !!                                  + retsoring towards the background grid
+      !!                                  + thickness difusion
+      !!                               Then repartition of ssh INCREMENT proportionnaly
+      !!                               to the "baroclinic" level thickness.
+      !!
+      !! ** Action  :  - hdiv_lf    : restoring towards full baroclinic divergence in z_tilde case
+      !!               - tilde_e3t_a: after increment of vertical scale factor 
+      !!                              in z_tilde case
+      !!               - fse3(t/u/v)_a
+      !!
+      !! Reference  : Leclair, M., and Madec, G. 2011, Ocean Modelling.
+      !!----------------------------------------------------------------------
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: ze3t
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: zht, z_scale, zwu, zwv, zhdiv
+      !! * Arguments
+      INTEGER, INTENT( in )                  :: kt                    ! time step
+      !! * Local declarations
+      INTEGER                                :: ji, jj, jk            ! dummy loop indices
+      INTEGER , DIMENSION(3)                 :: ijk_max, ijk_min      ! temporary integers
+      REAL(wp)                               :: z2dt                  ! temporary scalars
+      REAL(wp)                               :: z_tmin, z_tmax        ! temporary scalars
+      !!----------------------------------------------------------------------
+      IF( nn_timing == 1 )  CALL timing_start('dom_vvl_sf_nxt')
+      CALL wrk_alloc( jpi, jpj, zht, z_scale, zwu, zwv, zhdiv )
+      CALL wrk_alloc( jpi, jpj, jpk, ze3t                     )
+
+      IF(kt == nit000)   THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dom_vvl_sf_nxt : compute after scale factors'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'
+      ENDIF
+
+      ! ******************************* !
+      ! After acale factors at t-points !
+      ! ******************************* !
+
+      !                                                ! ----------------- !
+      IF( ln_vvl_zstar ) THEN                          ! z_star coordinate !
+         !                                             ! ----------------- !
+
+         z_scale(:,:) = ( ssha(:,:) - sshb(:,:) ) * tmask(:,:,1) / ( ht_0(:,:) + sshn(:,:) + 1. - tmask(:,:,1) )
+         DO jk = 1, jpkm1
+            fse3t_a(:,:,jk) = fse3t_b(:,:,jk) + fse3t_n(:,:,jk) * z_scale(:,:) * tmask(:,:,jk)
+         END DO
+
+      !                                                ! --------------------------- !
+      ELSEIF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN   ! z_tilde or layer coordinate !
+         !                                             ! --------------------------- !
+
+         ! I - initialization
+         ! ==================
+
+         ! 1 - barotropic divergence
+         ! -------------------------
+         zhdiv(:,:) = 0.
+         zht(:,:)   = 0.
+         DO jk = 1, jpkm1
+            zhdiv(:,:) = zhdiv(:,:) + fse3t_n(:,:,jk) * hdivn(:,:,jk)
+            zht  (:,:) = zht  (:,:) + fse3t_n(:,:,jk) * tmask(:,:,jk)
+         END DO
+         zhdiv(:,:) = zhdiv(:,:) / ( zht(:,:) + 1. - tmask(:,:,1) )
+
+         ! 2 - Low frequency baroclinic horizontal divergence  (z-tilde case only)
+         ! --------------------------------------------------
+         IF( ln_vvl_ztilde ) THEN
+            IF( kt .GT. nit000 ) THEN
+               DO jk = 1, jpkm1
+                  hdiv_lf(:,:,jk) = hdiv_lf(:,:,jk) - rdt * frq_rst_hdv(:,:)   &
+                     &          * ( hdiv_lf(:,:,jk) - fse3t_n(:,:,jk) * ( hdivn(:,:,jk) - zhdiv(:,:) ) )
+               END DO
+            ENDIF
+         END IF
+
+         ! II - after z_tilde increments of vertical scale factors
+         ! =======================================================
+         tilde_e3t_a(:,:,:) = 0.0_wp  ! tilde_e3t_a used to store tendency terms
+
+         ! 1 - High frequency divergence term
+         ! ----------------------------------
+         IF( ln_vvl_ztilde ) THEN     ! z_tilde case
+            DO jk = 1, jpkm1
+               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - ( fse3t_n(:,:,jk) * ( hdivn(:,:,jk) - zhdiv(:,:) ) - hdiv_lf(:,:,jk) )
+            END DO
+         ELSE                         ! layer case
+            DO jk = 1, jpkm1
+               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) -   fse3t_n(:,:,jk) * ( hdivn(:,:,jk) - zhdiv(:,:) )
+            END DO
+         END IF
+
+         ! 2 - Restoring term (z-tilde case only)
+         ! ------------------
+         IF( ln_vvl_ztilde ) THEN
+            DO jk = 1, jpk
+               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - frq_rst_e3t(:,:) * tilde_e3t_b(:,:,jk)
+            END DO
+         END IF
+
+         ! 3 - Thickness diffusion term
+         ! ----------------------------
+         zwu(:,:) = 0.0_wp
+         zwv(:,:) = 0.0_wp
+         ! a - first derivative: diffusive fluxes
+         DO jk = 1, jpkm1
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  un_td(ji,jj,jk) = rn_ahe3 * umask(ji,jj,jk) * re2u_e1u(ji,jj) &
+                                  & * ( tilde_e3t_b(ji,jj,jk) - tilde_e3t_b(ji+1,jj  ,jk) )
+                  vn_td(ji,jj,jk) = rn_ahe3 * vmask(ji,jj,jk) * re1v_e2v(ji,jj) & 
+                                  & * ( tilde_e3t_b(ji,jj,jk) - tilde_e3t_b(ji  ,jj+1,jk) )
+                  zwu(ji,jj) = zwu(ji,jj) + un_td(ji,jj,jk)
+                  zwv(ji,jj) = zwv(ji,jj) + vn_td(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         ! b - correction for last oceanic u-v points
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               un_td(ji,jj,mbku(ji,jj)) = un_td(ji,jj,mbku(ji,jj)) - zwu(ji,jj)
+               vn_td(ji,jj,mbkv(ji,jj)) = vn_td(ji,jj,mbkv(ji,jj)) - zwv(ji,jj)
+            END DO
+         END DO
+         ! c - second derivative: divergence of diffusive fluxes
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  tilde_e3t_a(ji,jj,jk) = tilde_e3t_a(ji,jj,jk) + (   un_td(ji-1,jj  ,jk) - un_td(ji,jj,jk)    &
+                     &                                          +     vn_td(ji  ,jj-1,jk) - vn_td(ji,jj,jk)    &
+                     &                                            ) * r1_e12t(ji,jj)
+               END DO
+            END DO
+         END DO
+         ! d - thickness diffusion transport: boundary conditions
+         !     (stored for tracer advction and continuity equation)
+         CALL lbc_lnk( un_td , 'U' , -1.)
+         CALL lbc_lnk( vn_td , 'V' , -1.)
+
+         ! 4 - Time stepping of baroclinic scale factors
+         ! ---------------------------------------------
+         ! Leapfrog time stepping
+         ! ~~~~~~~~~~~~~~~~~~~~~~
+         IF( neuler == 0 .AND. kt == nit000 ) THEN
+            z2dt =  rdt
+         ELSE
+            z2dt = 2.0_wp * rdt
+         ENDIF
+         CALL lbc_lnk( tilde_e3t_a(:,:,:), 'T', 1. )
+         tilde_e3t_a(:,:,:) = tilde_e3t_b(:,:,:) + z2dt * tmask(:,:,:) * tilde_e3t_a(:,:,:)
+
+         ! Maximum deformation control
+         ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+         ze3t(:,:,jpk) = 0.0_wp
+         DO jk = 1, jpkm1
+            ze3t(:,:,jk) = tilde_e3t_a(:,:,jk) / e3t_0(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:)
+         END DO
+         z_tmax = MAXVAL( ze3t(:,:,:) )
+         IF( lk_mpp )   CALL mpp_max( z_tmax )                 ! max over the global domain
+         z_tmin = MINVAL( ze3t(:,:,:) )
+         IF( lk_mpp )   CALL mpp_min( z_tmin )                 ! min over the global domain
+         ! - ML - test: for the moment, stop simulation for too large e3_t variations
+         IF( ( z_tmax .GT. rn_zdef_max ) .OR. ( z_tmin .LT. - rn_zdef_max ) ) THEN
+            IF( lk_mpp ) THEN
+               CALL mpp_maxloc( ze3t, tmask, z_tmax, ijk_max(1), ijk_max(2), ijk_max(3) )
+               CALL mpp_minloc( ze3t, tmask, z_tmin, ijk_min(1), ijk_min(2), ijk_min(3) )
+            ELSE
+               ijk_max = MAXLOC( ze3t(:,:,:) )
+               ijk_max(1) = ijk_max(1) + nimpp - 1
+               ijk_max(2) = ijk_max(2) + njmpp - 1
+               ijk_min = MINLOC( ze3t(:,:,:) )
+               ijk_min(1) = ijk_min(1) + nimpp - 1
+               ijk_min(2) = ijk_min(2) + njmpp - 1
+            ENDIF
+            IF (lwp) THEN
+               WRITE(numout, *) 'MAX( tilde_e3t_a(:,:,:) / e3t_0(:,:,:) ) =', z_tmax
+               WRITE(numout, *) 'at i, j, k=', ijk_max
+               WRITE(numout, *) 'MIN( tilde_e3t_a(:,:,:) / e3t_0(:,:,:) ) =', z_tmin
+               WRITE(numout, *) 'at i, j, k=', ijk_min            
+               CALL ctl_warn('MAX( ABS( tilde_e3t_a(:,:,:) ) / e3t_0(:,:,:) ) too high')
+            ENDIF
+         ENDIF
+         ! - ML - end test
+         ! - ML - Imposing these limits will cause a baroclinicity error which is corrected for below
+         tilde_e3t_a(:,:,:) = MIN( tilde_e3t_a(:,:,:),   rn_zdef_max * e3t_0(:,:,:) )
+         tilde_e3t_a(:,:,:) = MAX( tilde_e3t_a(:,:,:), - rn_zdef_max * e3t_0(:,:,:) )
+
+         ! Add "tilda" part to the after scale factor
+         ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+         fse3t_a(:,:,:) = e3t_0(:,:,:) + tilde_e3t_a(:,:,:)
+
+         ! III - Barotropic repartition of the sea surface height over the baroclinic profile
+         ! ==================================================================================
+         ! add e3t(n-1) "star" Asselin-filtered
+         DO jk = 1, jpkm1
+            fse3t_a(:,:,jk) = fse3t_a(:,:,jk) + fse3t_b(:,:,jk) - e3t_0(:,:,jk) - tilde_e3t_b(:,:,jk)
+         END DO
+         ! add ( ssh increment + "baroclinicity error" ) proportionnaly to e3t(n)
+         ! - ML - baroclinicity error should be better treated in the future
+         !        i.e. locally and not spread over the water column.
+         !        (keep in mind that the idea is to reduce Eulerian velocity as much as possible)
+         zht(:,:) = 0.
+         DO jk = 1, jpkm1
+            zht(:,:)  = zht(:,:) + tilde_e3t_a(:,:,jk) * tmask(:,:,jk)
+         END DO
+         z_scale(:,:) = ( ssha(:,:) - sshb(:,:) - zht(:,:) ) / ( ht_0(:,:) + sshn(:,:) + 1. - tmask(:,:,1) )
+         DO jk = 1, jpkm1
+            fse3t_a(:,:,jk) = fse3t_a(:,:,jk) + fse3t_n(:,:,jk) * z_scale(:,:) * tmask(:,:,jk)
+         END DO
+
+      ENDIF
+
+      IF( ln_vvl_dbg ) THEN   ! - ML - test: control prints for debuging
+         !
+         IF( lwp ) WRITE(numout, *) 'kt =', kt
+         IF ( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
+            z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( zht(:,:) ) )
+            IF( lk_mpp ) CALL mpp_max( z_tmax )                             ! max over the global domain
+            IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(SUM(tilde_e3t_a))) =', z_tmax
+         END IF
+         !
+         zht(:,:) = 0.0_wp
+         DO jk = 1, jpkm1
+            zht(:,:) = zht(:,:) + fse3t_n(:,:,jk) * tmask(:,:,jk)
+         END DO
+         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + sshn(:,:) - zht(:,:) ) )
+         IF( lk_mpp ) CALL mpp_max( z_tmax )                                ! max over the global domain
+         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+sshn-SUM(fse3t_n))) =', z_tmax
+         !
+         zht(:,:) = 0.0_wp
+         DO jk = 1, jpkm1
+            zht(:,:) = zht(:,:) + fse3t_a(:,:,jk) * tmask(:,:,jk)
+         END DO
+         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + ssha(:,:) - zht(:,:) ) )
+         IF( lk_mpp ) CALL mpp_max( z_tmax )                                ! max over the global domain
+         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+ssha-SUM(fse3t_a))) =', z_tmax
+         !
+         zht(:,:) = 0.0_wp
+         DO jk = 1, jpkm1
+            zht(:,:) = zht(:,:) + fse3t_b(:,:,jk) * tmask(:,:,jk)
+         END DO
+         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + sshb(:,:) - zht(:,:) ) )
+         IF( lk_mpp ) CALL mpp_max( z_tmax )                                ! max over the global domain
+         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+sshb-SUM(fse3t_b))) =', z_tmax
+         !
+         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( sshb(:,:) ) )
+         IF( lk_mpp ) CALL mpp_max( z_tmax )                                ! max over the global domain
+         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(sshb))) =', z_tmax
+         !
+         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( sshn(:,:) ) )
+         IF( lk_mpp ) CALL mpp_max( z_tmax )                                ! max over the global domain
+         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(sshn))) =', z_tmax
+         !
+         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( ssha(:,:) ) )
+         IF( lk_mpp ) CALL mpp_max( z_tmax )                                ! max over the global domain
+         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ssha))) =', z_tmax
+      END IF
+
+      ! *********************************** !
+      ! After scale factors at u- v- points !
+      ! *********************************** !
+
+      CALL dom_vvl_interpol( fse3t_a(:,:,:), fse3u_a(:,:,:), 'U' )
+      CALL dom_vvl_interpol( fse3t_a(:,:,:), fse3v_a(:,:,:), 'V' )
+
+      CALL wrk_dealloc( jpi, jpj, zht, z_scale, zwu, zwv, zhdiv )
+      CALL wrk_dealloc( jpi, jpj, jpk, ze3t                     )
+
+      IF( nn_timing == 1 )  CALL timing_start('dom_vvl_sf_nxt')
+
+   END SUBROUTINE dom_vvl_sf_nxt
+
+
+   SUBROUTINE dom_vvl_sf_swp( kt )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE dom_vvl_sf_swp  ***
+      !!                   
+      !! ** Purpose :  compute time filter and swap of scale factors 
+      !!               compute all depths and related variables for next time step
+      !!               write outputs and restart file
+      !!
+      !! ** Method  :  - swap of e3t with trick for volume/tracer conservation
+      !!               - reconstruct scale factor at other grid points (interpolate)
+      !!               - recompute depths and water height fields
+      !!
+      !! ** Action  :  - fse3t_(b/n), tilde_e3t_(b/n) and fse3(u/v)_n ready for next time step
+      !!               - Recompute:
+      !!                    fse3(u/v)_b       
+      !!                    fse3w_n           
+      !!                    fse3(u/v)w_b      
+      !!                    fse3(u/v)w_n      
+      !!                    fsdept_n, fsdepw_n  and fsde3w_n
+      !!                    h(u/v) and h(u/v)r
+      !!
+      !! Reference  : Leclair, M., and G. Madec, 2009, Ocean Modelling.
+      !!              Leclair, M., and G. Madec, 2011, Ocean Modelling.
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER, INTENT( in )               :: kt       ! time step
+      !! * Local declarations
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: z_e3t_def
+      INTEGER                             :: jk       ! dummy loop indices
+      !!----------------------------------------------------------------------
+
+      IF( nn_timing == 1 )  CALL timing_start('dom_vvl_sf_swp')
       !
-      ALLOCATE( mut (jpi,jpj,jpk) , muu (jpi,jpj,jpk) , muv (jpi,jpj,jpk) , muf (jpi,jpj,jpk) ,     &
-         &      r2dt        (jpk)                                                             , STAT=dom_vvl_alloc )
-         !
-      IF( lk_mpp             )   CALL mpp_sum ( dom_vvl_alloc )
-      IF( dom_vvl_alloc /= 0 )   CALL ctl_warn('dom_vvl_alloc: failed to allocate arrays')
+      CALL wrk_alloc( jpi, jpj, jpk, z_e3t_def                )
       !
-   END FUNCTION dom_vvl_alloc
-
-
-   SUBROUTINE dom_vvl
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl  ***
-      !!                   
-      !! ** Purpose :   compute mu coefficients at t-, u-, v- and f-points to 
-      !!              spread ssh over the whole water column (scale factors)
-      !!                set the before and now ssh at u- and v-points 
-      !!              (also f-point in now case)
-      !!----------------------------------------------------------------------
+      IF( kt == nit000 )   THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dom_vvl_sf_swp : - time filter and swap of scale factors'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~   - interpolate scale factors and compute depths for next time step'
+      ENDIF
       !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zcoefu, zcoefv , zcoeff                ! local scalars
-      REAL(wp) ::   zvt   , zvt_ip1, zvt_jp1, zvt_ip1jp1   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:) ::  zee_t, zee_u, zee_v, zee_f   ! 2D workspace
-      !!----------------------------------------------------------------------
+      ! Time filter and swap of scale factors
+      ! =====================================
+      ! - ML - fse3(t/u/v)_b are allready computed in dynnxt.
+      IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
+         IF( neuler == 0 .AND. kt == nit000 ) THEN
+            tilde_e3t_b(:,:,:) = tilde_e3t_n(:,:,:)
+         ELSE
+            tilde_e3t_b(:,:,:) = tilde_e3t_n(:,:,:) & 
+            &         + atfp * ( tilde_e3t_b(:,:,:) - 2.0_wp * tilde_e3t_n(:,:,:) + tilde_e3t_a(:,:,:) )
+         ENDIF
+         tilde_e3t_n(:,:,:) = tilde_e3t_a(:,:,:)
+      ENDIF
+      fse3t_n(:,:,:) = fse3t_a(:,:,:)
+      fse3u_n(:,:,:) = fse3u_a(:,:,:)
+      fse3v_n(:,:,:) = fse3v_a(:,:,:)
+
+      ! Compute all missing vertical scale factor and depths
+      ! ====================================================
+      ! Horizontal scale factor interpolations
+      ! --------------------------------------
+      ! - ML - fse3u_b and fse3v_b are allready computed in dynnxt
+      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
+      ! Local depth and Inverse of the local depth of the water column at u- and v- points
+      ! ----------------------------------------------------------------------------------
+      hu(:,:) = 0.
+      hv(:,:) = 0.
+      DO jk = 1, jpk
+         hu(:,:) = hu(:,:) + fse3u_n(:,:,jk) * umask(:,:,jk)
+         hv(:,:) = hv(:,:) + fse3v_n(:,:,jk) * vmask(:,:,jk)
+      END DO
+      ! Inverse of the local depth
+      hur(:,:) = umask(:,:,1) / ( hu(:,:) + 1. - umask(:,:,1) )
+      hvr(:,:) = vmask(:,:,1) / ( hv(:,:) + 1. - vmask(:,:,1) )
+
+      ! Write outputs
+      ! =============
+      z_e3t_def(:,:,:) = ( ( fse3t_n(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2
+      CALL iom_put( "e3t_n"  , fse3t_n  (:,:,:) )
+      CALL iom_put( "dept_n" , fsde3w_n (:,:,:) )
+      CALL iom_put( "e3tdef" , z_e3t_def(:,:,:) )
+
+      ! write restart file
+      ! ==================
+      IF( lrst_oce ) CALL dom_vvl_rst( kt, 'WRITE' )
       !
-      IF( nn_timing == 1 )  CALL timing_start('dom_vvl')
+      CALL wrk_dealloc( jpi, jpj, jpk, z_e3t_def )
       !
-      CALL wrk_alloc( jpi, jpj, zee_t, zee_u, zee_v, zee_f )
+      IF( nn_timing == 1 )  CALL timing_stop('dom_vvl_sf_swp')
+
+   END SUBROUTINE dom_vvl_sf_swp
+
+
+   SUBROUTINE dom_vvl_interpol( pe3_in, pe3_out, pout )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dom_vvl__interpol  ***
+      !!
+      !! ** Purpose :   interpolate scale factors from one grid point to another
+      !!
+      !! ** Method  :   e3_out = e3_0 + interpolation(e3_in - e3_0)
+      !!                - horizontal interpolation: grid cell surface averaging
+      !!                - vertical interpolation: simple averaging
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in    ) ::  pe3_in     ! input e3 to be interpolated
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::  pe3_out    ! output interpolated e3
+      CHARACTER(LEN=*), INTENT( in )                    ::  pout       ! grid point of out scale factors
+      !                                                                !   =  'U', 'V', 'W, 'F', 'UW' or 'VW'
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk                                          ! dummy loop indices
+      LOGICAL ::   l_is_orca                                           ! local logical
+      !!----------------------------------------------------------------------
+      IF( nn_timing == 1 )  CALL timing_start('dom_vvl_interpol')
+         !
+      l_is_orca = .FALSE.
+      IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) l_is_orca = .TRUE.      ! ORCA R2 configuration - will need to correct some locations
+
+      SELECT CASE ( pout )
+         !               ! ------------------------------------- !
+      CASE( 'U' )        ! interpolation from T-point to U-point !
+         !               ! ------------------------------------- !
+         ! horizontal surface weighted interpolation
+         DO jk = 1, jpk
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk) * r1_e12u(ji,jj)                                   &
+                     &                       * (   e12t(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3t_0(ji  ,jj,jk) )     &
+                     &                           + e12t(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3t_0(ji+1,jj,jk) ) )
+               END DO
+            END DO
+         END DO
+         !
+         IF( l_is_orca ) CALL dom_vvl_orca_fix( pe3_in, pe3_out, pout )
+         ! boundary conditions
+         CALL lbc_lnk( pe3_out(:,:,:), 'U', 1. )
+         pe3_out(:,:,:) = pe3_out(:,:,:) + e3u_0(:,:,:)
+         !               ! ------------------------------------- !
+      CASE( 'V' )        ! interpolation from T-point to V-point !
+         !               ! ------------------------------------- !
+         ! horizontal surface weighted interpolation
+         DO jk = 1, jpk
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  pe3_out(ji,jj,jk) = 0.5_wp * vmask(ji,jj,jk) * r1_e12v(ji,jj)                                   &
+                     &                       * (   e12t(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3t_0(ji,jj  ,jk) )     &
+                     &                           + e12t(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3t_0(ji,jj+1,jk) ) )
+               END DO
+            END DO
+         END DO
+         !
+         IF( l_is_orca ) CALL dom_vvl_orca_fix( pe3_in, pe3_out, pout )
+         ! boundary conditions
+         CALL lbc_lnk( pe3_out(:,:,:), 'V', 1. )
+         pe3_out(:,:,:) = pe3_out(:,:,:) + e3v_0(:,:,:)
+         !               ! ------------------------------------- !
+      CASE( 'F' )        ! interpolation from U-point to F-point !
+         !               ! ------------------------------------- !
+         ! horizontal surface weighted interpolation
+         DO jk = 1, jpk
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk) * umask(ji,jj+1,jk) * r1_e12f(ji,jj)               &
+                     &                       * (   e12u(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3u_0(ji,jj  ,jk) )     &
+                     &                           + e12u(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3u_0(ji,jj+1,jk) ) )
+               END DO
+            END DO
+         END DO
+         !
+         IF( l_is_orca ) CALL dom_vvl_orca_fix( pe3_in, pe3_out, pout )
+         ! boundary conditions
+         CALL lbc_lnk( pe3_out(:,:,:), 'F', 1. )
+         pe3_out(:,:,:) = pe3_out(:,:,:) + e3f_0(:,:,:)
+         !               ! ------------------------------------- !
+      CASE( 'W' )        ! interpolation from T-point to W-point !
+         !               ! ------------------------------------- !
+         ! vertical simple interpolation
+         pe3_out(:,:,1) = e3w_0(:,:,1) + pe3_in(:,:,1) - e3t_0(:,:,1)
+         ! - ML - The use of mask in this formaula enables the special treatment of the last w- point without indirect adressing
+         DO jk = 2, jpk
+            pe3_out(:,:,jk) = e3w_0(:,:,jk) + ( 1.0_wp - 0.5_wp * tmask(:,:,jk) ) * ( pe3_in(:,:,jk-1) - e3t_0(:,:,jk-1) )   &
+               &                            +            0.5_wp * tmask(:,:,jk)   * ( pe3_in(:,:,jk  ) - e3t_0(:,:,jk  ) )
+         END DO
+         !               ! -------------------------------------- !
+      CASE( 'UW' )       ! interpolation from U-point to UW-point !
+         !               ! -------------------------------------- !
+         ! vertical simple interpolation
+         pe3_out(:,:,1) = e3uw_0(:,:,1) + pe3_in(:,:,1) - e3u_0(:,:,1)
+         ! - ML - The use of mask in this formaula enables the special treatment of the last w- point without indirect adressing
+         DO jk = 2, jpk
+            pe3_out(:,:,jk) = e3uw_0(:,:,jk) + ( 1.0_wp - 0.5_wp * umask(:,:,jk) ) * ( pe3_in(:,:,jk-1) - e3u_0(:,:,jk-1) )   &
+               &                             +            0.5_wp * umask(:,:,jk)   * ( pe3_in(:,:,jk  ) - e3u_0(:,:,jk  ) )
+         END DO
+         !               ! -------------------------------------- !
+      CASE( 'VW' )       ! interpolation from V-point to VW-point !
+         !               ! -------------------------------------- !
+         ! vertical simple interpolation
+         pe3_out(:,:,1) = e3vw_0(:,:,1) + pe3_in(:,:,1) - e3v_0(:,:,1)
+         ! - ML - The use of mask in this formaula enables the special treatment of the last w- point without indirect adressing
+         DO jk = 2, jpk
+            pe3_out(:,:,jk) = e3vw_0(:,:,jk) + ( 1.0_wp - 0.5_wp * vmask(:,:,jk) ) * ( pe3_in(:,:,jk-1) - e3v_0(:,:,jk-1) )   &
+               &                             +            0.5_wp * vmask(:,:,jk)   * ( pe3_in(:,:,jk  ) - e3v_0(:,:,jk  ) )
+         END DO
+      END SELECT
       !
-      IF(lwp) THEN
+
+      IF( nn_timing == 1 )  CALL timing_stop('dom_vvl_interpol')
+
+   END SUBROUTINE dom_vvl_interpol
+
+   SUBROUTINE dom_vvl_rst( kt, cdrw )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE dom_vvl_rst  ***
+      !!                     
+      !! ** Purpose :   Read or write VVL file in restart file
+      !!
+      !! ** Method  :   use of IOM library
+      !!                if the restart does not contain vertical scale factors,
+      !!                they are set to the _0 values
+      !!                if the restart does not contain vertical scale factors increments (z_tilde),
+      !!                they are set to 0.
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      INTEGER         , INTENT(in) ::   kt     ! ocean time-step
+      CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
+      !! * Local declarations
+      INTEGER ::   id1, id2, id3, id4, id5     ! local integers
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('dom_vvl_rst')
+      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
+         !                                   ! ===============
+         IF( ln_rstart ) THEN                   !* Read the restart file
+            CALL rst_read_open                  !  open the restart file if necessary
+            id1 = iom_varid( numror, 'fse3t_b', ldstop = .FALSE. )
+            id2 = iom_varid( numror, 'fse3t_n', ldstop = .FALSE. )
+            id3 = iom_varid( numror, 'tilde_e3t_b', ldstop = .FALSE. )
+            id4 = iom_varid( numror, 'tilde_e3t_n', ldstop = .FALSE. )
+            id5 = iom_varid( numror, 'hdif_lf', ldstop = .FALSE. )
+            !                             ! --------- !
+            !                             ! all cases !
+            !                             ! --------- !
+            IF( MIN( id1, id2 ) > 0 ) THEN       ! all required arrays exist
+               CALL iom_get( numror, jpdom_autoglo, 'fse3t_b', fse3t_b(:,:,:) )
+               CALL iom_get( numror, jpdom_autoglo, 'fse3t_n', fse3t_n(:,:,:) )
+               IF( neuler == 0 ) THEN
+                  fse3t_b(:,:,:) = fse3t_n(:,:,:)
+               ENDIF
+            ELSE IF( id1 > 0 ) THEN
+               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : fse3t_n not found in restart files'
+               IF(lwp) write(numout,*) 'fse3t_n set equal to fse3t_b.'
+               fse3t_b(:,:,:) = fse3t_n(:,:,:)
+            ELSE                                 ! one at least array is missing
+               CALL ctl_stop( 'dom_vvl_rst: vvl cannot restart from a non vvl run' )
+            ENDIF
+            !                             ! ----------- !
+            IF( ln_vvl_zstar ) THEN       ! z_star case !
+               !                          ! ----------- !
+               IF( MIN( id3, id4 ) > 0 ) THEN
+                  CALL ctl_stop( 'dom_vvl_rst: z_star cannot restart from a z_tilde or layer run' )
+               ENDIF
+               !                          ! ----------------------- !
+            ELSE                          ! z_tilde and layer cases !
+               !                          ! ----------------------- !
+               IF( MIN( id3, id4 ) > 0 ) THEN  ! all required arrays exist
+                  CALL iom_get( numror, jpdom_autoglo, 'tilde_e3t_b', tilde_e3t_b(:,:,:) )
+                  CALL iom_get( numror, jpdom_autoglo, 'tilde_e3t_n', tilde_e3t_n(:,:,:) )
+               ELSE                            ! one at least array is missing
+                  tilde_e3t_b(:,:,:) = 0.0_wp
+                  tilde_e3t_n(:,:,:) = 0.0_wp
+               ENDIF
+               !                          ! ------------ !
+               IF( ln_vvl_ztilde ) THEN   ! z_tilde case !
+                  !                       ! ------------ !
+                  IF( id5 > 0 ) THEN  ! required array exists
+                     CALL iom_get( numror, jpdom_autoglo, 'hdiv_lf', hdiv_lf(:,:,:) )
+                  ELSE                ! array is missing
+                     hdiv_lf(:,:,:) = 0.0_wp
+                  ENDIF
+               ENDIF
+            ENDIF
+            !
+         ELSE                                   !* Initialize at "rest"
+            fse3t_b(:,:,:) = e3t_0(:,:,:)
+            fse3t_n(:,:,:) = e3t_0(:,:,:)
+            IF( ln_vvl_ztilde .OR. ln_vvl_layer) THEN
+               tilde_e3t_b(:,:,:) = 0.0_wp
+               tilde_e3t_n(:,:,:) = 0.0_wp
+               IF( ln_vvl_ztilde ) hdiv_lf(:,:,:) = 0.0_wp
+            END IF
+         ENDIF
+
+      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
+         !                                   ! ===================
+         IF(lwp) WRITE(numout,*) '---- dom_vvl_rst ----'
+         !                                           ! --------- !
+         !                                           ! all cases !
+         !                                           ! --------- !
+         CALL iom_rstput( kt, nitrst, numrow, 'fse3t_b', fse3t_b(:,:,:) )
+         CALL iom_rstput( kt, nitrst, numrow, 'fse3t_n', fse3t_n(:,:,:) )
+         !                                           ! ----------------------- !
+         IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN  ! z_tilde and layer cases !
+            !                                        ! ----------------------- !
+            CALL iom_rstput( kt, nitrst, numrow, 'tilde_e3t_b', tilde_e3t_b(:,:,:) )
+            CALL iom_rstput( kt, nitrst, numrow, 'tilde_e3t_n', tilde_e3t_n(:,:,:) )
+         END IF
+         !                                           ! -------------!    
+         IF( ln_vvl_ztilde ) THEN                    ! z_tilde case !
+            !                                        ! ------------ !
+            CALL iom_rstput( kt, nitrst, numrow, 'hdiv_lf', hdiv_lf(:,:,:) )
+         ENDIF
+
+      ENDIF
+      IF( nn_timing == 1 )  CALL timing_stop('dom_vvl_rst')
+
+   END SUBROUTINE dom_vvl_rst
+
+
+   SUBROUTINE dom_vvl_ctl
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dom_vvl_ctl  ***
+      !!                
+      !! ** Purpose :   Control the consistency between namelist options
+      !!                for vertical coordinate
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio
+
+      NAMELIST/nam_vvl/ ln_vvl_zstar, ln_vvl_ztilde, ln_vvl_layer, ln_vvl_ztilde_as_zstar, &
+                      & ln_vvl_zstar_at_eqtor      , rn_ahe3     , rn_rst_e3t            , &
+                      & rn_lf_cutoff               , rn_zdef_max , ln_vvl_dbg                ! not yet implemented: ln_vvl_kepe
+      !!---------------------------------------------------------------------- 
+
+      REWIND ( numnam )               ! Read Namelist nam_vvl : vertical coordinate
+      READ   ( numnam, nam_vvl )
+
+      IF(lwp) THEN                    ! Namelist print
          WRITE(numout,*)
-         WRITE(numout,*) 'dom_vvl : Variable volume initialization'
-         WRITE(numout,*) '~~~~~~~~  compute coef. used to spread ssh over each layers'
+         WRITE(numout,*) 'dom_vvl_ctl : choice/control of the variable vertical coordinate'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '           Namelist nam_vvl : chose a vertical coordinate'
+         WRITE(numout,*) '              zstar                      ln_vvl_zstar   = ', ln_vvl_zstar
+         WRITE(numout,*) '              ztilde                     ln_vvl_ztilde  = ', ln_vvl_ztilde
+         WRITE(numout,*) '              layer                      ln_vvl_layer   = ', ln_vvl_layer
+         WRITE(numout,*) '              ztilde as zstar   ln_vvl_ztilde_as_zstar  = ', ln_vvl_ztilde_as_zstar
+         WRITE(numout,*) '      ztilde near the equator    ln_vvl_zstar_at_eqtor  = ', ln_vvl_zstar_at_eqtor
+         ! WRITE(numout,*) '           Namelist nam_vvl : chose kinetic-to-potential energy conservation'
+         ! WRITE(numout,*) '                                         ln_vvl_kepe    = ', ln_vvl_kepe
+         WRITE(numout,*) '           Namelist nam_vvl : thickness diffusion coefficient'
+         WRITE(numout,*) '                                         rn_ahe3        = ', rn_ahe3
+         WRITE(numout,*) '           Namelist nam_vvl : maximum e3t deformation fractional change'
+         WRITE(numout,*) '                                         rn_zdef_max    = ', rn_zdef_max
+         IF( ln_vvl_ztilde_as_zstar ) THEN
+            WRITE(numout,*) '           ztilde running in zstar emulation mode; '
+            WRITE(numout,*) '           ignoring namelist timescale parameters and using:'
+            WRITE(numout,*) '                 hard-wired : z-tilde to zstar restoration timescale (days)'
+            WRITE(numout,*) '                                         rn_rst_e3t     =    0.0'
+            WRITE(numout,*) '                 hard-wired : z-tilde cutoff frequency of low-pass filter (days)'
+            WRITE(numout,*) '                                         rn_lf_cutoff   =    1.0/rdt'
+         ELSE
+            WRITE(numout,*) '           Namelist nam_vvl : z-tilde to zstar restoration timescale (days)'
+            WRITE(numout,*) '                                         rn_rst_e3t     = ', rn_rst_e3t
+            WRITE(numout,*) '           Namelist nam_vvl : z-tilde cutoff frequency of low-pass filter (days)'
+            WRITE(numout,*) '                                         rn_lf_cutoff   = ', rn_lf_cutoff
+         ENDIF
+         WRITE(numout,*) '           Namelist nam_vvl : debug prints'
+         WRITE(numout,*) '                                         ln_vvl_dbg     = ', ln_vvl_dbg
       ENDIF
-      
-      IF( dom_vvl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl : unable to allocate arrays' )
-
-      fsdept(:,:,:) = gdept (:,:,:)
-      fsdepw(:,:,:) = gdepw (:,:,:)
-      fsde3w(:,:,:) = gdep3w(:,:,:)
-      fse3t (:,:,:) = e3t   (:,:,:)
-      fse3u (:,:,:) = e3u   (:,:,:)
-      fse3v (:,:,:) = e3v   (:,:,:)
-      fse3f (:,:,:) = e3f   (:,:,:)
-      fse3w (:,:,:) = e3w   (:,:,:)
-      fse3uw(:,:,:) = e3uw  (:,:,:)
-      fse3vw(:,:,:) = e3vw  (:,:,:)
-
-      !                                 !==  mu computation  ==!
-      zee_t(:,:) = fse3t_0(:,:,1)                ! Lower bound : thickness of the first model level
-      zee_u(:,:) = fse3u_0(:,:,1)
-      zee_v(:,:) = fse3v_0(:,:,1)
-      zee_f(:,:) = fse3f_0(:,:,1)
-      DO jk = 2, jpkm1                          ! Sum of the masked vertical scale factors
-         zee_t(:,:) = zee_t(:,:) + fse3t_0(:,:,jk) * tmask(:,:,jk)
-         zee_u(:,:) = zee_u(:,:) + fse3u_0(:,:,jk) * umask(:,:,jk)
-         zee_v(:,:) = zee_v(:,:) + fse3v_0(:,:,jk) * vmask(:,:,jk)
-         DO jj = 1, jpjm1                      ! f-point : fmask=shlat at coasts, use the product of umask
-            zee_f(:,jj) = zee_f(:,jj) + fse3f_0(:,jj,jk) *  umask(:,jj,jk) * umask(:,jj+1,jk)
-         END DO
-      END DO  
-      !                                         ! Compute and mask the inverse of the local depth at T, U, V and F points
-      zee_t(:,:) = 1._wp / zee_t(:,:) * tmask(:,:,1)
-      zee_u(:,:) = 1._wp / zee_u(:,:) * umask(:,:,1)
-      zee_v(:,:) = 1._wp / zee_v(:,:) * vmask(:,:,1)
-      DO jj = 1, jpjm1                               ! f-point case fmask cannot be used 
-         zee_f(:,jj) = 1._wp / zee_f(:,jj) * umask(:,jj,1) * umask(:,jj+1,1)
-      END DO
-      CALL lbc_lnk( zee_f, 'F', 1. )                 ! lateral boundary condition on ee_f
-      !
-      DO jk = 1, jpk                            ! mu coefficients
-         mut(:,:,jk) = zee_t(:,:) * tmask(:,:,jk)     ! T-point at T levels
-         muu(:,:,jk) = zee_u(:,:) * umask(:,:,jk)     ! U-point at T levels
-         muv(:,:,jk) = zee_v(:,:) * vmask(:,:,jk)     ! V-point at T levels
-      END DO
-      DO jk = 1, jpk                                 ! F-point : fmask=shlat at coasts, use the product of umask
-         DO jj = 1, jpjm1
-               muf(:,jj,jk) = zee_f(:,jj) * umask(:,jj,jk) * umask(:,jj+1,jk)   ! at T levels
-         END DO
-         muf(:,jpj,jk) = 0._wp
-      END DO
-      CALL lbc_lnk( muf, 'F', 1. )                   ! lateral boundary condition
-
-
-      hu_0(:,:) = 0.e0                          ! Reference ocean depth at U- and V-points
-      hv_0(:,:) = 0.e0
-      DO jk = 1, jpk
-         hu_0(:,:) = hu_0(:,:) + fse3u_0(:,:,jk) * umask(:,:,jk)
-         hv_0(:,:) = hv_0(:,:) + fse3v_0(:,:,jk) * vmask(:,:,jk)
-      END DO
-      
-      DO jj = 1, jpjm1                          ! initialise before and now Sea Surface Height at u-, v-, f-points
-         DO ji = 1, jpim1   ! NO vector opt.
-            zcoefu = 0.50_wp / ( e1u(ji,jj) * e2u(ji,jj) ) * umask(ji,jj,1)
-            zcoefv = 0.50_wp / ( e1v(ji,jj) * e2v(ji,jj) ) * vmask(ji,jj,1)
-            zcoeff = 0.25_wp / ( e1f(ji,jj) * e2f(ji,jj) ) * umask(ji,jj,1) * umask(ji,jj+1,1)
-            !
-            zvt           = e1e2t(ji  ,jj  ) * sshb(ji  ,jj  )    ! before fields
-            zvt_ip1       = e1e2t(ji+1,jj  ) * sshb(ji+1,jj  )
-            zvt_jp1       = e1e2t(ji  ,jj+1) * sshb(ji  ,jj+1)
-            sshu_b(ji,jj) = zcoefu * ( zvt + zvt_ip1 )
-            sshv_b(ji,jj) = zcoefv * ( zvt + zvt_jp1 )
-            !
-            zvt           = e1e2t(ji  ,jj  ) * sshn(ji  ,jj  )    ! now fields
-            zvt_ip1       = e1e2t(ji+1,jj  ) * sshn(ji+1,jj  )
-            zvt_jp1       = e1e2t(ji  ,jj+1) * sshn(ji  ,jj+1)
-            zvt_ip1jp1    = e1e2t(ji+1,jj+1) * sshn(ji+1,jj+1)
-            sshu_n(ji,jj) = zcoefu * ( zvt + zvt_ip1 )
-            sshv_n(ji,jj) = zcoefv * ( zvt + zvt_jp1 )
-            sshf_n(ji,jj) = zcoeff * ( zvt + zvt_ip1 + zvt_jp1 + zvt_ip1jp1 )
-         END DO
-      END DO
-      CALL lbc_lnk( sshu_n, 'U', 1. )   ;   CALL lbc_lnk( sshu_b, 'U', 1. )      ! lateral boundary conditions
-      CALL lbc_lnk( sshv_n, 'V', 1. )   ;   CALL lbc_lnk( sshv_b, 'V', 1. )
-      CALL lbc_lnk( sshf_n, 'F', 1. )
-      !
-      CALL wrk_dealloc( jpi, jpj, zee_t, zee_u, zee_v, zee_f )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dom_vvl')
-      !
-   END SUBROUTINE dom_vvl
-
-
-   SUBROUTINE dom_vvl_2( kt, pe3u_b, pe3v_b )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_2  ***
-      !!                   
-      !! ** Purpose :   compute the vertical scale factors at u- and v-points
-      !!              in variable volume case.
-      !!
-      !! ** Method  :   In variable volume case (non linear sea surface) the 
-      !!              the vertical scale factor at velocity points is computed
-      !!              as the average of the cell surface weighted e3t.
-      !!                It uses the sea surface heigth so it have to be initialized
-      !!              after ssh is read/set
-      !!----------------------------------------------------------------------
-      INTEGER                   , INTENT(in   ) ::   kt               ! ocean time-step index
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pe3u_b, pe3v_b   ! before vertical scale factor at u- & v-pts
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      INTEGER  ::   iku, ikv     ! local integers    
-      INTEGER  ::   ii0, ii1, ij0, ij1   ! temporary integers
-      REAL(wp) ::   zvt, zvtip1, zvtjp1  ! local scalars
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('dom_vvl_2')
-      !
-      IF( lwp .AND. kt == nit000 ) THEN
+
+      ioptio = 0                      ! Parameter control
+      IF( ln_vvl_ztilde_as_zstar ) ln_vvl_ztilde = .true.
+      IF( ln_vvl_zstar           )        ioptio = ioptio + 1
+      IF( ln_vvl_ztilde          )        ioptio = ioptio + 1
+      IF( ln_vvl_layer           )        ioptio = ioptio + 1
+
+      IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE vertical coordinate in namelist nam_vvl' )
+
+      IF(lwp) THEN                   ! Print the choice
          WRITE(numout,*)
-         WRITE(numout,*) 'dom_vvl_2 : Variable volume, fse3t_b initialization'
-         WRITE(numout,*) '~~~~~~~~~ '
-         pe3u_b(:,:,jpk) = fse3u_0(:,:,jpk)
-         pe3v_b(:,:,jpk) = fse3v_0(:,:,jpk)
+         IF( ln_vvl_zstar           ) WRITE(numout,*) '              zstar vertical coordinate is used'
+         IF( ln_vvl_ztilde          ) WRITE(numout,*) '              ztilde vertical coordinate is used'
+         IF( ln_vvl_layer           ) WRITE(numout,*) '              layer vertical coordinate is used'
+         IF( ln_vvl_ztilde_as_zstar ) WRITE(numout,*) '              to emulate a zstar coordinate'
+         ! - ML - Option not developed yet
+         ! IF(       ln_vvl_kepe ) WRITE(numout,*) '              kinetic to potential energy transfer : option used'
+         ! IF( .NOT. ln_vvl_kepe ) WRITE(numout,*) '              kinetic to potential energy transfer : option not used'
       ENDIF
-      
-      DO jk = 1, jpkm1           ! set the before scale factors at u- & v-points
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-               zvt    = ( fse3t_b(ji  ,jj  ,jk) - fse3t_0(ji  ,jj  ,jk) ) * e1e2t(ji  ,jj  )
-               zvtip1 = ( fse3t_b(ji+1,jj  ,jk) - fse3t_0(ji+1,jj  ,jk) ) * e1e2t(ji+1,jj  )
-               zvtjp1 = ( fse3t_b(ji  ,jj+1,jk) - fse3t_0(ji  ,jj+1,jk) ) * e1e2t(ji  ,jj+1)
-               pe3u_b(ji,jj,jk) = fse3u_0(ji,jj,jk) + 0.5_wp * ( zvt + zvtip1 ) / ( e1u(ji,jj) * e2u(ji,jj) )
-               pe3v_b(ji,jj,jk) = fse3v_0(ji,jj,jk) + 0.5_wp * ( zvt + zvtjp1 ) / ( e1v(ji,jj) * e2v(ji,jj) )
-            END DO
-         END DO
-      END DO
-
-      ! Correct scale factors at locations that have been individually modified in domhgr
-      ! Such modifications break the relationship between e1e2t and e1u*e2u etc. Recompute
-      ! scale factors ignoring the modified metric.
+
+   END SUBROUTINE dom_vvl_ctl
+
+   SUBROUTINE dom_vvl_orca_fix( pe3_in, pe3_out, pout )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE dom_vvl_orca_fix  ***
+      !!                     
+      !! ** Purpose :   Correct surface weighted, horizontally interpolated, 
+      !!                scale factors at locations that have been individually
+      !!                modified in domhgr. Such modifications break the
+      !!                relationship between e12t and e1u*e2u etc.
+      !!                Recompute some scale factors ignoring the modified metric.
+      !!----------------------------------------------------------------------
+      !! * Arguments
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in    ) ::  pe3_in     ! input e3 to be interpolated
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( inout ) ::  pe3_out    ! output interpolated e3
+      CHARACTER(LEN=*), INTENT( in )                    ::  pout       ! grid point of out scale factors
+      !                                                                !   =  'U', 'V', 'W, 'F', 'UW' or 'VW'
+      !! * Local declarations
+      INTEGER ::   ji, jj, jk                                          ! dummy loop indices
+      INTEGER ::   ij0, ij1, ii0, ii1                                  ! dummy loop indices
+      !! acc
+      !! Hmm with the time splitting these "fixes" seem to do more harm than good. Temporarily disabled for
+      !! the ORCA2 tests (by changing jp_cfg test from 2 to 3) pending further investigations
+      !! 
       !                                                ! =====================
       IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN    ! ORCA R2 configuration
          !                                             ! =====================
+      !! acc
          IF( nn_cla == 0 ) THEN
             !
             ii0 = 139   ;   ii1 = 140        ! Gibraltar Strait (e2u was modified)
-            ij0 = 102   ;   ij1 = 102   
-            DO jk = 1, jpkm1                 ! set the before scale factors at u-points
+            ij0 = 102   ;   ij1 = 102
+            DO jk = 1, jpkm1
                DO jj = mj0(ij0), mj1(ij1)
                   DO ji = mi0(ii0), mi1(ii1)
-                     zvt = fse3t_b(ji,jj,jk) * e1t(ji,jj)
-                     pe3u_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji+1,jj,jk) * e1t(ji+1,jj) ) / ( e1u(ji,jj) )
+                     SELECT CASE ( pout )
+                     CASE( 'U' )
+                        pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk)                                        &
+                       &                    * (   e1t(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3t_0(ji  ,jj,jk) ) &
+                       &                    +     e1t(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3t_0(ji+1,jj,jk) ) &
+                       &                      ) / e1u(ji,jj)   +   e3u_0(ji,jj,jk)
+                     CASE( 'F' )
+                        pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk) * umask(ji,jj+1,jk)                    &
+                       &                    * (   e1u(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3u_0(ji  ,jj,jk) ) &
+                       &                    +     e1u(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3u_0(ji+1,jj,jk) ) &
+                       &                      ) / e1f(ji,jj)   +   e3f_0(ji,jj,jk)
+                     END SELECT
                   END DO
                END DO
@@ -237,150 +964,236 @@
             !
             ii0 = 160   ;   ii1 = 160        ! Bab el Mandeb (e2u and e1v were modified)
-            ij0 =  88   ;   ij1 =  88   
-            DO jk = 1, jpkm1                 ! set the before scale factors at u-points
+            ij0 =  88   ;   ij1 =  88
+            DO jk = 1, jpkm1
                DO jj = mj0(ij0), mj1(ij1)
                   DO ji = mi0(ii0), mi1(ii1)
-                     zvt = fse3t_b(ji,jj,jk) * e1t(ji,jj)
-                     pe3u_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji+1,jj,jk) * e1t(ji+1,jj) ) / ( e1u(ji,jj) )
+                     SELECT CASE ( pout )
+                     CASE( 'U' )
+                        pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk)                                        &
+                       &                    * (   e1t(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3t_0(ji  ,jj,jk) ) &
+                       &                    +     e1t(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3t_0(ji+1,jj,jk) ) &
+                       &                      ) / e1u(ji,jj)   +   e3u_0(ji,jj,jk)
+                     CASE( 'V' )
+                        pe3_out(ji,jj,jk) = 0.5_wp * vmask(ji,jj,jk)                                        &
+                       &                    * (   e2t(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3t_0(ji,jj  ,jk) ) &
+                       &                    +     e2t(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3t_0(ji,jj+1,jk) ) &
+                       &                      ) / e2v(ji,jj)   +   e3v_0(ji,jj,jk)
+                     CASE( 'F' )
+                        pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk) * umask(ji,jj+1,jk)                    &
+                       &                    * (   e1u(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3u_0(ji  ,jj,jk) ) &
+                       &                    +     e1u(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3u_0(ji+1,jj,jk) ) &
+                       &                      ) / e1f(ji,jj)   +   e3f_0(ji,jj,jk)
+                     END SELECT
                   END DO
                END DO
             END DO
-            DO jk = 1, jpkm1                 ! set the before scale factors at v-points
-               DO jj = mj0(ij0), mj1(ij1)
-                  DO ji = mi0(ii0), mi1(ii1)
-                     zvt = fse3t_b(ji,jj,jk) * e2t(ji,jj)
-                     pe3v_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji,jj+1,jk) * e2t(ji,jj+1) ) / ( e2v(ji,jj) )
-                  END DO
-               END DO
-            END DO
          ENDIF
 
          ii0 = 145   ;   ii1 = 146        ! Danish Straits (e2u was modified)
-         ij0 = 116   ;   ij1 = 116   
-         DO jk = 1, jpkm1                 ! set the before scale factors at u-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e1t(ji,jj)
-                  pe3u_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji+1,jj,jk) * e1t(ji+1,jj) ) / ( e1u(ji,jj) )
-               END DO
-            END DO
-         END DO
-         !
+         ij0 = 116   ;   ij1 = 116
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'U' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk)                                        &
+                    &                    * (   e1t(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3t_0(ji  ,jj,jk) ) &
+                    &                    +     e1t(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3t_0(ji+1,jj,jk) ) &
+                    &                      ) / e1u(ji,jj)   +   e3u_0(ji,jj,jk)
+                  CASE( 'F' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk) * umask(ji,jj+1,jk)                    &
+                    &                    * (   e1u(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3u_0(ji  ,jj,jk) ) &
+                    &                    +     e1u(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3u_0(ji+1,jj,jk) ) &
+                    &                      ) / e1f(ji,jj)   +   e3f_0(ji,jj,jk)
+                  END SELECT
+               END DO
+            END DO
+         END DO
       ENDIF
+      !
          !                                             ! =====================
       IF( cp_cfg == "orca" .AND. jp_cfg == 1 ) THEN    ! ORCA R1 configuration
          !                                             ! =====================
-
+         !
          ii0 = 281   ;   ii1 = 282        ! Gibraltar Strait (e2u was modified)
-         ij0 = 200   ;   ij1 = 200   
-         DO jk = 1, jpkm1                 ! set the before scale factors at u-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e1t(ji,jj)
-                  pe3u_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji+1,jj,jk) * e1t(ji+1,jj) ) / ( e1u(ji,jj) )
-               END DO
-            END DO
-         END DO
-
+         ij0 = 200   ;   ij1 = 200
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'U' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk)                                        &
+                    &                    * (   e1t(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3t_0(ji  ,jj,jk) ) &
+                    &                    +     e1t(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3t_0(ji+1,jj,jk) ) &
+                    &                      ) / e1u(ji,jj)   +   e3u_0(ji,jj,jk)
+                  CASE( 'F' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk) * umask(ji,jj+1,jk)                    &
+                    &                    * (   e1u(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3u_0(ji  ,jj,jk) ) &
+                    &                    +     e1u(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3u_0(ji+1,jj,jk) ) &
+                    &                      ) / e1f(ji,jj)   +   e3f_0(ji,jj,jk)
+                  END SELECT
+               END DO
+            END DO
+         END DO
+         !
          ii0 = 314   ;   ii1 = 315        ! Bhosporus Strait (e2u was modified)
-         ij0 = 208   ;   ij1 = 208   
-         DO jk = 1, jpkm1                 ! set the before scale factors at u-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e1t(ji,jj)
-                  pe3u_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji+1,jj,jk) * e1t(ji+1,jj) ) / ( e1u(ji,jj) )
-               END DO
-            END DO
-         END DO
-
+         ij0 = 208   ;   ij1 = 208
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'U' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk)                                        &  
+                    &                    * (   e1t(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3t_0(ji  ,jj,jk) ) &
+                    &                    +     e1t(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3t_0(ji+1,jj,jk) ) &
+                    &                      ) / e1u(ji,jj)   +   e3u_0(ji,jj,jk)
+                  CASE( 'F' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk) * umask(ji,jj+1,jk)                    &  
+                    &                    * (   e1u(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3u_0(ji  ,jj,jk) ) &
+                    &                    +     e1u(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3u_0(ji+1,jj,jk) ) &
+                    &                      ) / e1f(ji,jj)   +   e3f_0(ji,jj,jk)
+                  END SELECT
+               END DO
+            END DO
+         END DO
+         !
          ii0 =  44   ;   ii1 =  44        ! Lombok Strait (e1v was modified)
-         ij0 = 124   ;   ij1 = 125   
-         DO jk = 1, jpkm1                 ! set the before scale factors at v-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e2t(ji,jj)
-                  pe3v_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji,jj+1,jk) * e2t(ji,jj+1) ) / ( e2v(ji,jj) )
-               END DO
-            END DO
-         END DO
-
+         ij0 = 124   ;   ij1 = 125
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'V' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * vmask(ji,jj,jk)                                        &
+                    &                    * (   e2t(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3t_0(ji,jj  ,jk) ) &
+                    &                    +     e2t(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3t_0(ji,jj+1,jk) ) &
+                    &                      ) / e2v(ji,jj)   +   e3v_0(ji,jj,jk)
+                  END SELECT
+               END DO
+            END DO
+         END DO
+         !
          ii0 =  48   ;   ii1 =  48        ! Sumba Strait (e1v was modified) [closed from bathy_11 on]
-         ij0 = 124   ;   ij1 = 125   
-         DO jk = 1, jpkm1                 ! set the before scale factors at v-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e2t(ji,jj)
-                  pe3v_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji,jj+1,jk) * e2t(ji,jj+1) ) / ( e2v(ji,jj) )
-               END DO
-            END DO
-         END DO
-
+         ij0 = 124   ;   ij1 = 125
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'V' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * vmask(ji,jj,jk)                                        &
+                    &                    * (   e2t(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3t_0(ji,jj  ,jk) ) &
+                    &                    +     e2t(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3t_0(ji,jj+1,jk) ) &
+                    &                      ) / e2v(ji,jj)   +   e3v_0(ji,jj,jk)
+                  END SELECT
+               END DO
+            END DO
+         END DO
+         !
          ii0 =  53   ;   ii1 =  53        ! Ombai Strait (e1v was modified)
-         ij0 = 124   ;   ij1 = 125   
-         DO jk = 1, jpkm1                 ! set the before scale factors at v-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e2t(ji,jj)
-                  pe3v_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji,jj+1,jk) * e2t(ji,jj+1) ) / ( e2v(ji,jj) )
-               END DO
-            END DO
-         END DO
-
+         ij0 = 124   ;   ij1 = 125
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'V' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * vmask(ji,jj,jk)                                        &
+                    &                    * (   e2t(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3t_0(ji,jj  ,jk) ) &
+                    &                    +     e2t(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3t_0(ji,jj+1,jk) ) &
+                    &                      ) / e2v(ji,jj)   +   e3v_0(ji,jj,jk)
+                  END SELECT
+               END DO
+            END DO
+         END DO
+         !
          ii0 =  56   ;   ii1 =  56        ! Timor Passage (e1v was modified)
-         ij0 = 124   ;   ij1 = 125   
-         DO jk = 1, jpkm1                 ! set the before scale factors at v-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e2t(ji,jj)
-                  pe3v_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji,jj+1,jk) * e2t(ji,jj+1) ) / ( e2v(ji,jj) )
-               END DO
-            END DO
-         END DO
-
+         ij0 = 124   ;   ij1 = 125
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'V' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * vmask(ji,jj,jk)                                        &
+                    &                    * (   e2t(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3t_0(ji,jj  ,jk) ) &
+                    &                    +     e2t(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3t_0(ji,jj+1,jk) ) &
+                    &                      ) / e2v(ji,jj)   +   e3v_0(ji,jj,jk)
+                  END SELECT
+               END DO
+            END DO
+         END DO
+         !
          ii0 =  55   ;   ii1 =  55        ! West Halmahera Strait (e1v was modified)
-         ij0 = 141   ;   ij1 = 142   
-         DO jk = 1, jpkm1                 ! set the before scale factors at v-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e2t(ji,jj)
-                  pe3v_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji,jj+1,jk) * e2t(ji,jj+1) ) / ( e2v(ji,jj) )
-               END DO
-            END DO
-         END DO
-
+         ij0 = 141   ;   ij1 = 142
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'V' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * vmask(ji,jj,jk)                                        &
+                    &                    * (   e2t(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3t_0(ji,jj  ,jk) ) &
+                    &                    +     e2t(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3t_0(ji,jj+1,jk) ) &
+                    &                      ) / e2v(ji,jj)   +   e3v_0(ji,jj,jk)
+                  END SELECT
+               END DO
+            END DO
+         END DO
+         !
          ii0 =  58   ;   ii1 =  58        ! East Halmahera Strait (e1v was modified)
-         ij0 = 141   ;   ij1 = 142   
-         DO jk = 1, jpkm1                 ! set the before scale factors at v-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e2t(ji,jj)
-                  pe3v_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji,jj+1,jk) * e2t(ji,jj+1) ) / ( e2v(ji,jj) )
-               END DO
-            END DO
-         END DO
-
-         !
+         ij0 = 141   ;   ij1 = 142
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'V' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * vmask(ji,jj,jk)                                        &
+                    &                    * (   e2t(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3t_0(ji,jj  ,jk) ) &
+                    &                    +     e2t(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3t_0(ji,jj+1,jk) ) &
+                    &                      ) / e2v(ji,jj)   +   e3v_0(ji,jj,jk)
+                  END SELECT
+               END DO
+            END DO
+         END DO
       ENDIF
-      !                                                ! ======================
+         !                                             ! =====================
       IF( cp_cfg == "orca" .AND. jp_cfg == 05 ) THEN   ! ORCA R05 configuration
-         !                                             ! ======================
+         !                                             ! =====================
+         !
          ii0 = 563   ;   ii1 = 564        ! Gibraltar Strait (e2u was modified)
-         ij0 = 327   ;   ij1 = 327   
-         DO jk = 1, jpkm1                 ! set the before scale factors at u-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e1t(ji,jj)
-                  pe3u_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji+1,jj,jk) * e1t(ji+1,jj) ) / ( e1u(ji,jj) )
-               END DO
-            END DO
-         END DO
-         !
-         ii0 = 627   ;   ii1 = 628        ! Bosphore Strait (e2u was modified)
-         ij0 = 343   ;   ij1 = 343   
-         DO jk = 1, jpkm1                 ! set the before scale factors at u-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e1t(ji,jj)
-                  pe3u_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji+1,jj,jk) * e1t(ji+1,jj) ) / ( e1u(ji,jj) )
+         ij0 = 327   ;   ij1 = 327
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'U' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk)                                        &
+                    &                    * (   e1t(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3t_0(ji  ,jj,jk) ) &
+                    &                    +     e1t(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3t_0(ji+1,jj,jk) ) &
+                    &                      ) / e1u(ji,jj)   +   e3u_0(ji,jj,jk)
+                  CASE( 'F' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk) * umask(ji,jj+1,jk)                    &
+                    &                    * (   e1u(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3u_0(ji  ,jj,jk) ) &
+                    &                    +     e1u(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3u_0(ji+1,jj,jk) ) &
+                    &                      ) / e1f(ji,jj)   +   e3f_0(ji,jj,jk)
+                  END SELECT
+               END DO
+            END DO
+         END DO
+         !
+         ii0 = 627   ;   ii1 = 628        ! Bosphorus Strait (e2u was modified)
+         ij0 = 343   ;   ij1 = 343
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'U' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk)                                        &  
+                    &                    * (   e1t(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3t_0(ji  ,jj,jk) ) &
+                    &                    +     e1t(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3t_0(ji+1,jj,jk) ) &
+                    &                      ) / e1u(ji,jj)   +   e3u_0(ji,jj,jk)
+                  CASE( 'F' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk) * umask(ji,jj+1,jk)                    &  
+                    &                    * (   e1u(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3u_0(ji  ,jj,jk) ) &
+                    &                    +     e1u(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3u_0(ji+1,jj,jk) ) &
+                    &                      ) / e1f(ji,jj)   +   e3f_0(ji,jj,jk)
+                  END SELECT
                END DO
             END DO
@@ -388,10 +1201,20 @@
          !
          ii0 =  93   ;   ii1 =  94        ! Sumba Strait (e2u was modified)
-         ij0 = 232   ;   ij1 = 232   
-         DO jk = 1, jpkm1                 ! set the before scale factors at u-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e1t(ji,jj)
-                  pe3u_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji+1,jj,jk) * e1t(ji+1,jj) ) / ( e1u(ji,jj) )
+         ij0 = 232   ;   ij1 = 232
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'U' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk)                                        &
+                    &                    * (   e1t(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3t_0(ji  ,jj,jk) ) &
+                    &                    +     e1t(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3t_0(ji+1,jj,jk) ) &
+                    &                      ) / e1u(ji,jj)   +   e3u_0(ji,jj,jk)
+                  CASE( 'F' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk) * umask(ji,jj+1,jk)                    &
+                    &                    * (   e1u(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3u_0(ji  ,jj,jk) ) &
+                    &                    +     e1u(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3u_0(ji+1,jj,jk) ) &
+                    &                      ) / e1f(ji,jj)   +   e3f_0(ji,jj,jk)
+                  END SELECT
                END DO
             END DO
@@ -399,10 +1222,20 @@
          !
          ii0 = 103   ;   ii1 = 103        ! Ombai Strait (e2u was modified)
-         ij0 = 232   ;   ij1 = 232   
-         DO jk = 1, jpkm1                 ! set the before scale factors at u-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e1t(ji,jj)
-                  pe3u_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji+1,jj,jk) * e1t(ji+1,jj) ) / ( e1u(ji,jj) )
+         ij0 = 232   ;   ij1 = 232
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'U' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk)                                        &
+                    &                    * (   e1t(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3t_0(ji  ,jj,jk) ) &
+                    &                    +     e1t(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3t_0(ji+1,jj,jk) ) &
+                    &                      ) / e1u(ji,jj)   +   e3u_0(ji,jj,jk)
+                  CASE( 'F' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk) * umask(ji,jj+1,jk)                    &
+                    &                    * (   e1u(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3u_0(ji  ,jj,jk) ) &
+                    &                    +     e1u(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3u_0(ji+1,jj,jk) ) &
+                    &                      ) / e1f(ji,jj)   +   e3f_0(ji,jj,jk)
+                  END SELECT
                END DO
             END DO
@@ -410,10 +1243,20 @@
          !
          ii0 =  15   ;   ii1 =  15        ! Palk Strait (e2u was modified)
-         ij0 = 270   ;   ij1 = 270   
-         DO jk = 1, jpkm1                 ! set the before scale factors at u-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e1t(ji,jj)
-                  pe3u_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji+1,jj,jk) * e1t(ji+1,jj) ) / ( e1u(ji,jj) )
+         ij0 = 270   ;   ij1 = 270
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'U' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk)                                        &
+                    &                    * (   e1t(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3t_0(ji  ,jj,jk) ) &
+                    &                    +     e1t(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3t_0(ji+1,jj,jk) ) &
+                    &                      ) / e1u(ji,jj)   +   e3u_0(ji,jj,jk)
+                  CASE( 'F' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * umask(ji,jj,jk) * umask(ji,jj+1,jk)                    &
+                    &                    * (   e1u(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3u_0(ji  ,jj,jk) ) &
+                    &                    +     e1u(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3u_0(ji+1,jj,jk) ) &
+                    &                      ) / e1f(ji,jj)   +   e3f_0(ji,jj,jk)
+                  END SELECT
                END DO
             END DO
@@ -421,10 +1264,15 @@
          !
          ii0 =  87   ;   ii1 =  87        ! Lombok Strait (e1v was modified)
-         ij0 = 232   ;   ij1 = 233   
-         DO jk = 1, jpkm1                 ! set the before scale factors at v-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e2t(ji,jj)
-                  pe3v_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji,jj+1,jk) * e2t(ji,jj+1) ) / ( e2v(ji,jj) )
+         ij0 = 232   ;   ij1 = 233
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'V' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * vmask(ji,jj,jk)                                        &
+                    &                    * (   e2t(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3t_0(ji,jj  ,jk) ) &
+                    &                    +     e2t(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3t_0(ji,jj+1,jk) ) &
+                    &                      ) / e2v(ji,jj)   +   e3v_0(ji,jj,jk)
+                  END SELECT
                END DO
             END DO
@@ -432,52 +1280,20 @@
          !
          ii0 = 662   ;   ii1 = 662        ! Bab el Mandeb (e1v was modified)
-         ij0 = 276   ;   ij1 = 276   
-         DO jk = 1, jpkm1                 ! set the before scale factors at v-points
-            DO jj = mj0(ij0), mj1(ij1)
-               DO ji = mi0(ii0), mi1(ii1)
-                  zvt = fse3t_b(ji,jj,jk) * e2t(ji,jj)
-                  pe3v_b(ji,jj,jk) = 0.5_wp * ( zvt + fse3t_b(ji,jj+1,jk) * e2t(ji,jj+1) ) / ( e2v(ji,jj) )
-               END DO
-            END DO
-         END DO
-         !
+         ij0 = 276   ;   ij1 = 276
+         DO jk = 1, jpkm1
+            DO jj = mj0(ij0), mj1(ij1)
+               DO ji = mi0(ii0), mi1(ii1)
+                  SELECT CASE ( pout )
+                  CASE( 'V' )
+                     pe3_out(ji,jj,jk) = 0.5_wp * vmask(ji,jj,jk)                                        &
+                    &                    * (   e2t(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3t_0(ji,jj  ,jk) ) &
+                    &                    +     e2t(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3t_0(ji,jj+1,jk) ) &
+                    &                      ) / e2v(ji,jj)   +   e3v_0(ji,jj,jk)
+                  END SELECT
+               END DO
+            END DO
+         END DO
       ENDIF
-      ! End of individual corrections to scale factors
-
-      IF( ln_zps ) THEN          ! minimum of the e3t at partial cell level
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-               iku = mbku(ji,jj)
-               ikv = mbkv(ji,jj)
-               pe3u_b(ji,jj,iku) = MIN( fse3t_b(ji,jj,iku), fse3t_b(ji+1,jj  ,iku) ) 
-               pe3v_b(ji,jj,ikv) = MIN( fse3t_b(ji,jj,ikv), fse3t_b(ji  ,jj+1,ikv) ) 
-            END DO
-         END DO
-      ENDIF
-
-      pe3u_b(:,:,:) = pe3u_b(:,:,:) - fse3u_0(:,:,:)      ! anomaly to avoid zero along closed boundary/extra halos
-      pe3v_b(:,:,:) = pe3v_b(:,:,:) - fse3v_0(:,:,:)
-      CALL lbc_lnk( pe3u_b(:,:,:), 'U', 1. )               ! lateral boundary conditions
-      CALL lbc_lnk( pe3v_b(:,:,:), 'V', 1. )
-      pe3u_b(:,:,:) = pe3u_b(:,:,:) + fse3u_0(:,:,:)      ! recover the full scale factor
-      pe3v_b(:,:,:) = pe3v_b(:,:,:) + fse3v_0(:,:,:)
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dom_vvl_2')
-      !
-   END SUBROUTINE dom_vvl_2
-   
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                      Empty routine
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE dom_vvl
-   END SUBROUTINE dom_vvl
-   SUBROUTINE dom_vvl_2(kdum, pudum, pvdum )
-      USE par_kind
-      INTEGER                   , INTENT(in   ) ::   kdum       
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pudum, pvdum
-   END SUBROUTINE dom_vvl_2
-#endif
+   END SUBROUTINE dom_vvl_orca_fix
 
    !!======================================================================
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domwri.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domwri.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domwri.F90	(revision 4292)
@@ -183,12 +183,12 @@
          CALL iom_rstput( 0, 0, inum4, 'esigw', esigw )
          !
-         CALL iom_rstput( 0, 0, inum4, 'e3t', e3t )             !    ! scale factors
-         CALL iom_rstput( 0, 0, inum4, 'e3u', e3u )
-         CALL iom_rstput( 0, 0, inum4, 'e3v', e3v )
-         CALL iom_rstput( 0, 0, inum4, 'e3w', e3w )
+         CALL iom_rstput( 0, 0, inum4, 'e3t_0', e3t_0 )         !    ! scale factors
+         CALL iom_rstput( 0, 0, inum4, 'e3u_0', e3u_0 )
+         CALL iom_rstput( 0, 0, inum4, 'e3v_0', e3v_0 )
+         CALL iom_rstput( 0, 0, inum4, 'e3w_0', e3w_0 )
          CALL iom_rstput( 0, 0, inum4, 'rx1', rx1 )             !    ! Max. grid stiffness ratio
          !
-         CALL iom_rstput( 0, 0, inum4, 'gdept' , gdept )    !    ! stretched system
-         CALL iom_rstput( 0, 0, inum4, 'gdepw' , gdepw )
+         CALL iom_rstput( 0, 0, inum4, 'gdept_1d' , gdept_1d )  !    ! stretched system
+         CALL iom_rstput( 0, 0, inum4, 'gdepw_1d' , gdepw_1d )
       ENDIF
       
@@ -196,13 +196,13 @@
          !
          IF( nmsh <= 6 ) THEN                                   !    ! 3D vertical scale factors
-            CALL iom_rstput( 0, 0, inum4, 'e3t', e3t )         
-            CALL iom_rstput( 0, 0, inum4, 'e3u', e3u )
-            CALL iom_rstput( 0, 0, inum4, 'e3v', e3v )
-            CALL iom_rstput( 0, 0, inum4, 'e3w', e3w )
+            CALL iom_rstput( 0, 0, inum4, 'e3t_0', e3t_0 )         
+            CALL iom_rstput( 0, 0, inum4, 'e3u_0', e3u_0 )
+            CALL iom_rstput( 0, 0, inum4, 'e3v_0', e3v_0 )
+            CALL iom_rstput( 0, 0, inum4, 'e3w_0', e3w_0 )
          ELSE                                                   !    ! 2D masked bottom ocean scale factors
             DO jj = 1,jpj   
                DO ji = 1,jpi
-                  e3tp(ji,jj) = e3t(ji,jj,mbkt(ji,jj)) * tmask(ji,jj,1)
-                  e3wp(ji,jj) = e3w(ji,jj,mbkt(ji,jj)) * tmask(ji,jj,1)
+                  e3tp(ji,jj) = e3t_0(ji,jj,mbkt(ji,jj)) * tmask(ji,jj,1)
+                  e3wp(ji,jj) = e3w_0(ji,jj,mbkt(ji,jj)) * tmask(ji,jj,1)
                END DO
             END DO
@@ -212,10 +212,10 @@
          !
          IF( nmsh <= 3 ) THEN                                   !    ! 3D depth
-            CALL iom_rstput( 0, 0, inum4, 'gdept', gdept, ktype = jp_r4 )     
+            CALL iom_rstput( 0, 0, inum4, 'gdept_0', gdept_0, ktype = jp_r4 )     
             DO jk = 1,jpk   
                DO jj = 1, jpjm1   
                   DO ji = 1, fs_jpim1   ! vector opt.
-                     zdepu(ji,jj,jk) = MIN( gdept(ji,jj,jk) , gdept(ji+1,jj  ,jk) )
-                     zdepv(ji,jj,jk) = MIN( gdept(ji,jj,jk) , gdept(ji  ,jj+1,jk) )
+                     zdepu(ji,jj,jk) = MIN( gdept_0(ji,jj,jk) , gdept_0(ji+1,jj  ,jk) )
+                     zdepv(ji,jj,jk) = MIN( gdept_0(ji,jj,jk) , gdept_0(ji  ,jj+1,jk) )
                   END DO   
                END DO   
@@ -224,10 +224,10 @@
             CALL iom_rstput( 0, 0, inum4, 'gdepu', zdepu, ktype = jp_r4 )
             CALL iom_rstput( 0, 0, inum4, 'gdepv', zdepv, ktype = jp_r4 )
-            CALL iom_rstput( 0, 0, inum4, 'gdepw', gdepw, ktype = jp_r4 )
+            CALL iom_rstput( 0, 0, inum4, 'gdepw_0', gdepw_0, ktype = jp_r4 )
          ELSE                                                   !    ! 2D bottom depth
             DO jj = 1,jpj   
                DO ji = 1,jpi
-                  zprt(ji,jj) = gdept(ji,jj,mbkt(ji,jj)  ) * tmask(ji,jj,1)
-                  zprw(ji,jj) = gdepw(ji,jj,mbkt(ji,jj)+1) * tmask(ji,jj,1)
+                  zprt(ji,jj) = gdept_0(ji,jj,mbkt(ji,jj)  ) * tmask(ji,jj,1)
+                  zprw(ji,jj) = gdepw_0(ji,jj,mbkt(ji,jj)+1) * tmask(ji,jj,1)
                END DO
             END DO
@@ -236,16 +236,16 @@
          ENDIF
          !
-         CALL iom_rstput( 0, 0, inum4, 'gdept_0', gdept_0 )     !    ! reference z-coord.
-         CALL iom_rstput( 0, 0, inum4, 'gdepw_0', gdepw_0 )
-         CALL iom_rstput( 0, 0, inum4, 'e3t_0'  , e3t_0   )
-         CALL iom_rstput( 0, 0, inum4, 'e3w_0'  , e3w_0   )
+         CALL iom_rstput( 0, 0, inum4, 'gdept_1d', gdept_1d )   !    ! reference z-coord.
+         CALL iom_rstput( 0, 0, inum4, 'gdepw_1d', gdepw_1d )
+         CALL iom_rstput( 0, 0, inum4, 'e3t_1d'  , e3t_1d   )
+         CALL iom_rstput( 0, 0, inum4, 'e3w_1d'  , e3w_1d   )
       ENDIF
       
       IF( ln_zco ) THEN
          !                                                      ! z-coordinate - full steps
-         CALL iom_rstput( 0, 0, inum4, 'gdept_0', gdept_0 )     !    ! depth
-         CALL iom_rstput( 0, 0, inum4, 'gdepw_0', gdepw_0 )
-         CALL iom_rstput( 0, 0, inum4, 'e3t_0'  , e3t_0   )     !    ! scale factors
-         CALL iom_rstput( 0, 0, inum4, 'e3w_0'  , e3w_0   )
+         CALL iom_rstput( 0, 0, inum4, 'gdept_1d', gdept_1d )   !    ! depth
+         CALL iom_rstput( 0, 0, inum4, 'gdepw_1d', gdepw_1d )
+         CALL iom_rstput( 0, 0, inum4, 'e3t_1d'  , e3t_1d   )   !    ! scale factors
+         CALL iom_rstput( 0, 0, inum4, 'e3w_1d'  , e3w_1d   )
       ENDIF
       !                                     ! ============================
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 4292)
@@ -88,5 +88,5 @@
       !!              vertical scale factors.
       !!
-      !! ** Method  : - reference 1D vertical coordinate (gdep._0, e3._0)
+      !! ** Method  : - reference 1D vertical coordinate (gdep._1d, e3._1d)
       !!              - read/set ocean depth and ocean levels (bathy, mbathy)
       !!              - vertical coordinate (gdep., e3.) depending on the 
@@ -153,17 +153,17 @@
       IF( nprint == 1 .AND. lwp )   THEN
          WRITE(numout,*) ' MIN val mbathy ', MINVAL( mbathy(:,:) ), ' MAX ', MAXVAL( mbathy(:,:) )
-         WRITE(numout,*) ' MIN val depth t ', MINVAL( fsdept(:,:,:) ),   &
-            &                   ' w ',   MINVAL( fsdepw(:,:,:) ), '3w ', MINVAL( fsde3w(:,:,:) )
-         WRITE(numout,*) ' MIN val e3    t ', MINVAL( fse3t(:,:,:) ), ' f ', MINVAL( fse3f(:,:,:) ),  &
-            &                   ' u ',   MINVAL( fse3u(:,:,:) ), ' u ', MINVAL( fse3v(:,:,:) ),  &
-            &                   ' uw',   MINVAL( fse3uw(:,:,:)), ' vw', MINVAL( fse3vw(:,:,:)),   &
-            &                   ' w ',   MINVAL( fse3w(:,:,:) )
-
-         WRITE(numout,*) ' MAX val depth t ', MAXVAL( fsdept(:,:,:) ),   &
-            &                   ' w ',   MAXVAL( fsdepw(:,:,:) ), '3w ', MAXVAL( fsde3w(:,:,:) )
-         WRITE(numout,*) ' MAX val e3    t ', MAXVAL( fse3t(:,:,:) ), ' f ', MAXVAL( fse3f(:,:,:) ),  &
-            &                   ' u ',   MAXVAL( fse3u(:,:,:) ), ' u ', MAXVAL( fse3v(:,:,:) ),  &
-            &                   ' uw',   MAXVAL( fse3uw(:,:,:)), ' vw', MAXVAL( fse3vw(:,:,:)),   &
-            &                   ' w ',   MAXVAL( fse3w(:,:,:) )
+         WRITE(numout,*) ' MIN val depth t ', MINVAL( gdept_0(:,:,:) ),   &
+            &                   ' w ',   MINVAL( gdepw_0(:,:,:) ), '3w ', MINVAL( gdep3w_0(:,:,:) )
+         WRITE(numout,*) ' MIN val e3    t ', MINVAL( e3t_0(:,:,:) ), ' f ', MINVAL( e3f_0(:,:,:) ),  &
+            &                   ' u ',   MINVAL( e3u_0(:,:,:) ), ' u ', MINVAL( e3v_0(:,:,:) ),  &
+            &                   ' uw',   MINVAL( e3uw_0(:,:,:)), ' vw', MINVAL( e3vw_0(:,:,:)),   &
+            &                   ' w ',   MINVAL( e3w_0(:,:,:) )
+
+         WRITE(numout,*) ' MAX val depth t ', MAXVAL( gdept_0(:,:,:) ),   &
+            &                   ' w ',   MAXVAL( gdepw_0(:,:,:) ), '3w ', MAXVAL( gdep3w_0(:,:,:) )
+         WRITE(numout,*) ' MAX val e3    t ', MAXVAL( e3t_0(:,:,:) ), ' f ', MAXVAL( e3f_0(:,:,:) ),  &
+            &                   ' u ',   MAXVAL( e3u_0(:,:,:) ), ' u ', MAXVAL( e3v_0(:,:,:) ),  &
+            &                   ' uw',   MAXVAL( e3uw_0(:,:,:)), ' vw', MAXVAL( e3vw_0(:,:,:)),   &
+            &                   ' w ',   MAXVAL( e3w_0(:,:,:) )
       ENDIF
       !
@@ -176,5 +176,5 @@
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE zgr_z  ***
-      !!                    
+      !!                   
       !! ** Purpose :   set the depth of model levels and the resulting 
       !!      vertical scale factors.
@@ -184,11 +184,11 @@
       !!      function the derivative of which gives the scale factors.
       !!        both depth and scale factors only depend on k (1d arrays).
-      !!              w-level: gdepw_0  = fsdep(k)
-      !!                       e3w_0(k) = dk(fsdep)(k)     = fse3(k)
-      !!              t-level: gdept_0  = fsdep(k+0.5)
-      !!                       e3t_0(k) = dk(fsdep)(k+0.5) = fse3(k+0.5)
-      !!
-      !! ** Action  : - gdept_0, gdepw_0 : depth of T- and W-point (m)
-      !!              - e3t_0  , e3w_0   : scale factors at T- and W-levels (m)
+      !!              w-level: gdepw_1d  = gdep(k)
+      !!                       e3w_1d(k) = dk(gdep)(k)     = e3(k)
+      !!              t-level: gdept_1d  = gdep(k+0.5)
+      !!                       e3t_1d(k) = dk(gdep)(k+0.5) = e3(k+0.5)
+      !!
+      !! ** Action  : - gdept_1d, gdepw_1d : depth of T- and W-point (m)
+      !!              - e3t_1d  , e3w_1d   : scale factors at T- and W-levels (m)
       !!
       !! Reference : Marti, Madec & Delecluse, 1992, JGR, 97, No8, 12,763-12,766.
@@ -262,8 +262,8 @@
             zw = FLOAT( jk )
             zt = FLOAT( jk ) + 0.5_wp
-            gdepw_0(jk) = ( zw - 1 ) * za1
-            gdept_0(jk) = ( zt - 1 ) * za1
-            e3w_0  (jk) =  za1
-            e3t_0  (jk) =  za1
+            gdepw_1d(jk) = ( zw - 1 ) * za1
+            gdept_1d(jk) = ( zt - 1 ) * za1
+            e3w_1d  (jk) =  za1
+            e3t_1d  (jk) =  za1
          END DO
       ELSE                                ! Madec & Imbard 1996 function
@@ -272,8 +272,8 @@
                zw = REAL( jk , wp )
                zt = REAL( jk , wp ) + 0.5_wp
-               gdepw_0(jk) = ( zsur + za0 * zw + za1 * zacr * LOG ( COSH( (zw-zkth) / zacr ) )  )
-               gdept_0(jk) = ( zsur + za0 * zt + za1 * zacr * LOG ( COSH( (zt-zkth) / zacr ) )  )
-               e3w_0  (jk) =          za0      + za1        * TANH(       (zw-zkth) / zacr   )
-               e3t_0  (jk) =          za0      + za1        * TANH(       (zt-zkth) / zacr   )
+               gdepw_1d(jk) = ( zsur + za0 * zw + za1 * zacr * LOG ( COSH( (zw-zkth) / zacr ) )  )
+               gdept_1d(jk) = ( zsur + za0 * zt + za1 * zacr * LOG ( COSH( (zt-zkth) / zacr ) )  )
+               e3w_1d  (jk) =          za0      + za1        * TANH(       (zw-zkth) / zacr   )
+               e3t_1d  (jk) =          za0      + za1        * TANH(       (zt-zkth) / zacr   )
             END DO
          ELSE
@@ -282,21 +282,21 @@
                zt = FLOAT( jk ) + 0.5_wp
                ! Double tanh function
-               gdepw_0(jk) = ( zsur + za0 * zw + za1 * zacr * LOG ( COSH( (zw-zkth ) / zacr  ) )    &
-                  &                            + za2 * zacr2* LOG ( COSH( (zw-zkth2) / zacr2 ) )  )
-               gdept_0(jk) = ( zsur + za0 * zt + za1 * zacr * LOG ( COSH( (zt-zkth ) / zacr  ) )    &
-                  &                            + za2 * zacr2* LOG ( COSH( (zt-zkth2) / zacr2 ) )  )
-               e3w_0  (jk) =          za0      + za1        * TANH(       (zw-zkth ) / zacr  )    &
-                  &                            + za2        * TANH(       (zw-zkth2) / zacr2 )
-               e3t_0  (jk) =          za0      + za1        * TANH(       (zt-zkth ) / zacr  )    &
-                  &                            + za2        * TANH(       (zt-zkth2) / zacr2 )
+               gdepw_1d(jk) = ( zsur + za0 * zw + za1 * zacr * LOG ( COSH( (zw-zkth ) / zacr  ) )    &
+                  &                             + za2 * zacr2* LOG ( COSH( (zw-zkth2) / zacr2 ) )  )
+               gdept_1d(jk) = ( zsur + za0 * zt + za1 * zacr * LOG ( COSH( (zt-zkth ) / zacr  ) )    &
+                  &                             + za2 * zacr2* LOG ( COSH( (zt-zkth2) / zacr2 ) )  )
+               e3w_1d  (jk) =          za0      + za1        * TANH(       (zw-zkth ) / zacr  )      &
+                  &                             + za2        * TANH(       (zw-zkth2) / zacr2 )
+               e3t_1d  (jk) =          za0      + za1        * TANH(       (zt-zkth ) / zacr  )      &
+                  &                             + za2        * TANH(       (zt-zkth2) / zacr2 )
             END DO
          ENDIF
-         gdepw_0(1) = 0._wp                    ! force first w-level to be exactly at zero
+         gdepw_1d(1) = 0._wp                    ! force first w-level to be exactly at zero
       ENDIF
 
 !!gm BUG in s-coordinate this does not work!
       ! deepest/shallowest W level Above/Below ~10m
-      zrefdep = 10._wp - 0.1_wp * MINVAL( e3w_0 )                    ! ref. depth with tolerance (10% of minimum layer thickness)
-      nlb10 = MINLOC( gdepw_0, mask = gdepw_0 > zrefdep, dim = 1 )   ! shallowest W level Below ~10m
+      zrefdep = 10._wp - 0.1_wp * MINVAL( e3w_1d )                   ! ref. depth with tolerance (10% of minimum layer thickness)
+      nlb10 = MINLOC( gdepw_1d, mask = gdepw_1d > zrefdep, dim = 1 ) ! shallowest W level Below ~10m
       nla10 = nlb10 - 1                                              ! deepest    W level Above ~10m
 !!gm end bug
@@ -305,10 +305,10 @@
          WRITE(numout,*)
          WRITE(numout,*) '              Reference z-coordinate depth and scale factors:'
-         WRITE(numout, "(9x,' level   gdept    gdepw     e3t      e3w  ')" )
-         WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, gdept_0(jk), gdepw_0(jk), e3t_0(jk), e3w_0(jk), jk = 1, jpk )
+         WRITE(numout, "(9x,' level  gdept_1d  gdepw_1d  e3t_1d   e3w_1d  ')" )
+         WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, gdept_1d(jk), gdepw_1d(jk), e3t_1d(jk), e3w_1d(jk), jk = 1, jpk )
       ENDIF
       DO jk = 1, jpk                      ! control positivity
-         IF( e3w_0  (jk) <= 0._wp .OR. e3t_0  (jk) <= 0._wp )   CALL ctl_stop( 'dom:zgr_z: e3w or e3t =< 0 '    )
-         IF( gdepw_0(jk) <  0._wp .OR. gdept_0(jk) <  0._wp )   CALL ctl_stop( 'dom:zgr_z: gdepw or gdept < 0 ' )
+         IF( e3w_1d  (jk) <= 0._wp .OR. e3t_1d  (jk) <= 0._wp )   CALL ctl_stop( 'dom:zgr_z: e3w_1d or e3t_1d =< 0 '    )
+         IF( gdepw_1d(jk) <  0._wp .OR. gdept_1d(jk) <  0._wp )   CALL ctl_stop( 'dom:zgr_z: gdepw_1d or gdept_1d < 0 ' )
       END DO
       !
@@ -382,5 +382,5 @@
                   idta(:,:) = jpkm1
                   DO jk = 1, jpkm1
-                     WHERE( gdept_0(jk) < zdta(:,:) .AND. zdta(:,:) <= gdept_0(jk+1) )   idta(:,:) = jk
+                     WHERE( gdept_1d(jk) < zdta(:,:) .AND. zdta(:,:) <= gdept_1d(jk+1) )   idta(:,:) = jk
                   END DO
                ENDIF
@@ -388,6 +388,6 @@
                IF(lwp) WRITE(numout,*) '         Depth = depthw(jpkm1)'
                idta(:,:) = jpkm1                            ! before last level
-               zdta(:,:) = gdepw_0(jpk)                     ! last w-point depth
-               h_oce     = gdepw_0(jpk)
+               zdta(:,:) = gdepw_1d(jpk)                     ! last w-point depth
+               h_oce     = gdepw_1d(jpk)
             ENDIF
          ELSE                                         ! bump centered in the basin
@@ -398,5 +398,5 @@
             r_bump  = 50000._wp                            ! bump radius (meters)       
             h_bump  =  2700._wp                            ! bump height (meters)
-            h_oce   = gdepw_0(jpk)                         ! background ocean depth (meters)
+            h_oce   = gdepw_1d(jpk)                        ! background ocean depth (meters)
             IF(lwp) WRITE(numout,*) '            bump characteristics: '
             IF(lwp) WRITE(numout,*) '               bump center (i,j)   = ', ii_bump, ii_bump
@@ -418,5 +418,5 @@
                idta(:,:) = jpkm1
                DO jk = 1, jpkm1
-                  WHERE( gdept_0(jk) < zdta(:,:) .AND. zdta(:,:) <= gdept_0(jk+1) )   idta(:,:) = jk
+                  WHERE( gdept_1d(jk) < zdta(:,:) .AND. zdta(:,:) <= gdept_1d(jk+1) )   idta(:,:) = jk
                END DO
             ENDIF
@@ -460,7 +460,7 @@
             CALL iom_close( inum )
             mbathy(:,:) = INT( bathy(:,:) )
-            !
+            !                                                ! =====================
             IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN    ! ORCA R2 configuration
-               !
+               !                                             ! =====================
                IF( nn_cla == 0 ) THEN
                   ii0 = 140   ;   ii1 = 140                  ! Gibraltar Strait open 
@@ -531,7 +531,7 @@
       IF ( .not. ln_sco ) THEN                                !==  set a minimum depth  ==!
          IF( rn_hmin < 0._wp ) THEN    ;   ik = - INT( rn_hmin )                                      ! from a nb of level
-         ELSE                          ;   ik = MINLOC( gdepw_0, mask = gdepw_0 > rn_hmin, dim = 1 )  ! from a depth
+         ELSE                          ;   ik = MINLOC( gdepw_1d, mask = gdepw_1d > rn_hmin, dim = 1 )  ! from a depth
          ENDIF
-         zhmin = gdepw_0(ik+1)                                                         ! minimum depth = ik+1 w-levels 
+         zhmin = gdepw_1d(ik+1)                                                         ! minimum depth = ik+1 w-levels 
          WHERE( bathy(:,:) <= 0._wp )   ;   bathy(:,:) = 0._wp                         ! min=0     over the lands
          ELSE WHERE                     ;   bathy(:,:) = MAX(  zhmin , bathy(:,:)  )   ! min=zhmin over the oceans
@@ -798,14 +798,14 @@
       !
       DO jk = 1, jpk
-            gdept(:,:,jk) = gdept_0(jk)
-            gdepw(:,:,jk) = gdepw_0(jk)
-            gdep3w(:,:,jk) = gdepw_0(jk)
-            e3t (:,:,jk) = e3t_0(jk)
-            e3u (:,:,jk) = e3t_0(jk)
-            e3v (:,:,jk) = e3t_0(jk)
-            e3f (:,:,jk) = e3t_0(jk)
-            e3w (:,:,jk) = e3w_0(jk)
-            e3uw(:,:,jk) = e3w_0(jk)
-            e3vw(:,:,jk) = e3w_0(jk)
+         gdept_0 (:,:,jk) = gdept_1d(jk)
+         gdepw_0 (:,:,jk) = gdepw_1d(jk)
+         gdep3w_0(:,:,jk) = gdepw_1d(jk)
+         e3t_0   (:,:,jk) = e3t_1d  (jk)
+         e3u_0   (:,:,jk) = e3t_1d  (jk)
+         e3v_0   (:,:,jk) = e3t_1d  (jk)
+         e3f_0   (:,:,jk) = e3t_1d  (jk)
+         e3w_0   (:,:,jk) = e3w_1d  (jk)
+         e3uw_0  (:,:,jk) = e3w_1d  (jk)
+         e3vw_0  (:,:,jk) = e3w_1d  (jk)
       END DO
       !
@@ -832,8 +832,8 @@
       !!      with partial steps  on 3d arrays ( i, j, k ).
       !!
-      !!              w-level: gdepw(i,j,k)  = fsdep(k)
-      !!                       e3w(i,j,k) = dk(fsdep)(k)     = fse3(i,j,k)
-      !!              t-level: gdept(i,j,k)  = fsdep(k+0.5)
-      !!                       e3t(i,j,k) = dk(fsdep)(k+0.5) = fse3(i,j,k+0.5)
+      !!              w-level: gdepw_0(i,j,k)  = gdep(k)
+      !!                       e3w_0(i,j,k) = dk(gdep)(k)     = e3(i,j,k)
+      !!              t-level: gdept_0(i,j,k)  = gdep(k+0.5)
+      !!                       e3t_0(i,j,k) = dk(gdep)(k+0.5) = e3(i,j,k+0.5)
       !!
       !!        With the help of the bathymetric file ( bathymetry_depth_ORCA_R2.nc),
@@ -843,5 +843,5 @@
       !!              - bathy = 0 => mbathy = 0
       !!              - 1 < mbathy < jpkm1    
-      !!              - bathy > gdepw(jpk) => mbathy = jpkm1  
+      !!              - bathy > gdepw_0(jpk) => mbathy = jpkm1  
       !!
       !!        Then, for each case, we find the new depth at t- and w- levels
@@ -855,6 +855,6 @@
       !!      schemes.
       !!
-      !!         c a u t i o n : gdept_0, gdepw_0 and e3._0 are positives
-      !!         - - - - - - -   gdept, gdepw and e3. are positives
+      !!         c a u t i o n : gdept_1d, gdepw_1d and e3._1d are positives
+      !!         - - - - - - -   gdept_0, gdepw_0 and e3. are positives
       !!      
       !!  Reference :   Pacanowsky & Gnanadesikan 1997, Mon. Wea. Rev., 126, 3248-3270.
@@ -892,5 +892,5 @@
       ! bathymetry in level (from bathy_meter)
       ! ===================
-      zmax = gdepw_0(jpk) + e3t_0(jpk)          ! maximum depth (i.e. the last ocean level thickness <= 2*e3t_0(jpkm1) )
+      zmax = gdepw_1d(jpk) + e3t_1d(jpk)        ! maximum depth (i.e. the last ocean level thickness <= 2*e3t_1d(jpkm1) )
       bathy(:,:) = MIN( zmax ,  bathy(:,:) )    ! bounded value of bathy (min already set at the end of zgr_bat)
       WHERE( bathy(:,:) == 0._wp )   ;   mbathy(:,:) = 0       ! land  : set mbathy to 0
@@ -900,8 +900,8 @@
       ! Compute mbathy for ocean points (i.e. the number of ocean levels)
       ! find the number of ocean levels such that the last level thickness
-      ! is larger than the minimum of e3zps_min and e3zps_rat * e3t_0 (where
-      ! e3t_0 is the reference level thickness
+      ! is larger than the minimum of e3zps_min and e3zps_rat * e3t_1d (where
+      ! e3t_1d is the reference level thickness
       DO jk = jpkm1, 1, -1
-         zdepth = gdepw_0(jk) + MIN( e3zps_min, e3t_0(jk)*e3zps_rat )
+         zdepth = gdepw_1d(jk) + MIN( e3zps_min, e3t_1d(jk)*e3zps_rat )
          WHERE( 0._wp < bathy(:,:) .AND. bathy(:,:) <= zdepth )   mbathy(:,:) = jk-1
       END DO
@@ -909,8 +909,8 @@
       ! Scale factors and depth at T- and W-points
       DO jk = 1, jpk                        ! intitialization to the reference z-coordinate
-         gdept(:,:,jk) = gdept_0(jk)
-         gdepw(:,:,jk) = gdepw_0(jk)
-         e3t  (:,:,jk) = e3t_0  (jk)
-         e3w  (:,:,jk) = e3w_0  (jk)
+         gdept_0(:,:,jk) = gdept_1d(jk)
+         gdepw_0(:,:,jk) = gdepw_1d(jk)
+         e3t_0  (:,:,jk) = e3t_1d  (jk)
+         e3w_0  (:,:,jk) = e3w_1d  (jk)
       END DO
       ! 
@@ -922,31 +922,31 @@
                IF( ik == jpkm1 ) THEN
                   zdepwp = bathy(ji,jj)
-                  ze3tp  = bathy(ji,jj) - gdepw_0(ik)
-                  ze3wp = 0.5_wp * e3w_0(ik) * ( 1._wp + ( ze3tp/e3t_0(ik) ) )
-                  e3t(ji,jj,ik  ) = ze3tp
-                  e3t(ji,jj,ik+1) = ze3tp
-                  e3w(ji,jj,ik  ) = ze3wp
-                  e3w(ji,jj,ik+1) = ze3tp
-                  gdepw(ji,jj,ik+1) = zdepwp
-                  gdept(ji,jj,ik  ) = gdept_0(ik-1) + ze3wp
-                  gdept(ji,jj,ik+1) = gdept(ji,jj,ik) + ze3tp
+                  ze3tp  = bathy(ji,jj) - gdepw_1d(ik)
+                  ze3wp = 0.5_wp * e3w_1d(ik) * ( 1._wp + ( ze3tp/e3t_1d(ik) ) )
+                  e3t_0(ji,jj,ik  ) = ze3tp
+                  e3t_0(ji,jj,ik+1) = ze3tp
+                  e3w_0(ji,jj,ik  ) = ze3wp
+                  e3w_0(ji,jj,ik+1) = ze3tp
+                  gdepw_0(ji,jj,ik+1) = zdepwp
+                  gdept_0(ji,jj,ik  ) = gdept_1d(ik-1) + ze3wp
+                  gdept_0(ji,jj,ik+1) = gdept_0(ji,jj,ik) + ze3tp
                   !
                ELSE                         ! standard case
-                  IF( bathy(ji,jj) <= gdepw_0(ik+1) ) THEN   ;   gdepw(ji,jj,ik+1) = bathy(ji,jj)
-                  ELSE                                       ;   gdepw(ji,jj,ik+1) = gdepw_0(ik+1)
+                  IF( bathy(ji,jj) <= gdepw_1d(ik+1) ) THEN  ;   gdepw_0(ji,jj,ik+1) = bathy(ji,jj)
+                  ELSE                                       ;   gdepw_0(ji,jj,ik+1) = gdepw_1d(ik+1)
                   ENDIF
-!gm Bug?  check the gdepw_0
+!gm Bug?  check the gdepw_1d
                   !       ... on ik
-                  gdept(ji,jj,ik) = gdepw_0(ik) + ( gdepw  (ji,jj,ik+1) - gdepw_0(ik) )   &
-                     &                          * ((gdept_0(      ik  ) - gdepw_0(ik) )   &
-                     &                          / ( gdepw_0(      ik+1) - gdepw_0(ik) ))
-                  e3t  (ji,jj,ik) = e3t_0  (ik) * ( gdepw  (ji,jj,ik+1) - gdepw_0(ik) )   & 
-                     &                          / ( gdepw_0(      ik+1) - gdepw_0(ik) ) 
-                  e3w  (ji,jj,ik) = 0.5_wp * ( gdepw(ji,jj,ik+1) + gdepw_0(ik+1) - 2._wp * gdepw_0(ik) )   &
-                     &                     * ( e3w_0(ik) / ( gdepw_0(ik+1) - gdepw_0(ik) ) )
+                  gdept_0(ji,jj,ik) = gdepw_1d(ik) + ( gdepw_0   (ji,jj,ik+1) - gdepw_1d(ik) )   &
+                     &                           * ((gdept_1d(      ik  ) - gdepw_1d(ik) )   &
+                     &                           / ( gdepw_1d(      ik+1) - gdepw_1d(ik) ))
+                  e3t_0(ji,jj,ik) = e3t_1d (ik) * ( gdepw_0 (ji,jj,ik+1) - gdepw_1d(ik) )   & 
+                     &                          / ( gdepw_1d(      ik+1) - gdepw_1d(ik) ) 
+                  e3w_0(ji,jj,ik) = 0.5_wp * ( gdepw_0(ji,jj,ik+1) + gdepw_1d(ik+1) - 2._wp * gdepw_1d(ik) )   &
+                     &                     * ( e3w_1d(ik) / ( gdepw_1d(ik+1) - gdepw_1d(ik) ) )
                   !       ... on ik+1
-                  e3w  (ji,jj,ik+1) = e3t  (ji,jj,ik)
-                  e3t  (ji,jj,ik+1) = e3t  (ji,jj,ik)
-                  gdept(ji,jj,ik+1) = gdept(ji,jj,ik) + e3t(ji,jj,ik)
+                  e3w_0  (ji,jj,ik+1) = e3t_0  (ji,jj,ik)
+                  e3t_0  (ji,jj,ik+1) = e3t_0  (ji,jj,ik)
+                  gdept_0(ji,jj,ik+1) = gdept_0(ji,jj,ik) + e3t_0(ji,jj,ik)
                ENDIF
             ENDIF
@@ -959,14 +959,14 @@
             ik = mbathy(ji,jj)
             IF( ik > 0 ) THEN               ! ocean point only
-               e3tp (ji,jj) = e3t(ji,jj,ik  )
-               e3wp (ji,jj) = e3w(ji,jj,ik  )
+               e3tp (ji,jj) = e3t_0(ji,jj,ik)
+               e3wp (ji,jj) = e3w_0(ji,jj,ik)
                ! test
-               zdiff= gdepw(ji,jj,ik+1) - gdept(ji,jj,ik  )
+               zdiff= gdepw_0(ji,jj,ik+1) - gdept_0(ji,jj,ik  )
                IF( zdiff <= 0._wp .AND. lwp ) THEN 
                   it = it + 1
                   WRITE(numout,*) ' it      = ', it, ' ik      = ', ik, ' (i,j) = ', ji, jj
                   WRITE(numout,*) ' bathy = ', bathy(ji,jj)
-                  WRITE(numout,*) ' gdept = ', gdept(ji,jj,ik), ' gdepw = ', gdepw(ji,jj,ik+1), ' zdiff = ', zdiff
-                  WRITE(numout,*) ' e3tp  = ', e3t  (ji,jj,ik), ' e3wp  = ', e3w  (ji,jj,ik  )
+                  WRITE(numout,*) ' gdept_0 = ', gdept_0(ji,jj,ik), ' gdepw_0 = ', gdepw_0(ji,jj,ik+1), ' zdiff = ', zdiff
+                  WRITE(numout,*) ' e3tp    = ', e3t_0  (ji,jj,ik), ' e3wp    = ', e3w_0  (ji,jj,ik  )
                ENDIF
             ENDIF
@@ -976,63 +976,63 @@
       ! Scale factors and depth at U-, V-, UW and VW-points
       DO jk = 1, jpk                        ! initialisation to z-scale factors
-         e3u (:,:,jk) = e3t_0(jk)
-         e3v (:,:,jk) = e3t_0(jk)
-         e3uw(:,:,jk) = e3w_0(jk)
-         e3vw(:,:,jk) = e3w_0(jk)
+         e3u_0 (:,:,jk) = e3t_1d(jk)
+         e3v_0 (:,:,jk) = e3t_1d(jk)
+         e3uw_0(:,:,jk) = e3w_1d(jk)
+         e3vw_0(:,:,jk) = e3w_1d(jk)
       END DO
       DO jk = 1,jpk                         ! Computed as the minimum of neighbooring scale factors
          DO jj = 1, jpjm1
             DO ji = 1, fs_jpim1   ! vector opt.
-               e3u (ji,jj,jk) = MIN( e3t(ji,jj,jk), e3t(ji+1,jj,jk) )
-               e3v (ji,jj,jk) = MIN( e3t(ji,jj,jk), e3t(ji,jj+1,jk) )
-               e3uw(ji,jj,jk) = MIN( e3w(ji,jj,jk), e3w(ji+1,jj,jk) )
-               e3vw(ji,jj,jk) = MIN( e3w(ji,jj,jk), e3w(ji,jj+1,jk) )
-            END DO
-         END DO
-      END DO
-      CALL lbc_lnk( e3u , 'U', 1._wp )   ;   CALL lbc_lnk( e3uw, 'U', 1._wp )   ! lateral boundary conditions
-      CALL lbc_lnk( e3v , 'V', 1._wp )   ;   CALL lbc_lnk( e3vw, 'V', 1._wp )
+               e3u_0 (ji,jj,jk) = MIN( e3t_0(ji,jj,jk), e3t_0(ji+1,jj,jk) )
+               e3v_0 (ji,jj,jk) = MIN( e3t_0(ji,jj,jk), e3t_0(ji,jj+1,jk) )
+               e3uw_0(ji,jj,jk) = MIN( e3w_0(ji,jj,jk), e3w_0(ji+1,jj,jk) )
+               e3vw_0(ji,jj,jk) = MIN( e3w_0(ji,jj,jk), e3w_0(ji,jj+1,jk) )
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk( e3u_0 , 'U', 1._wp )   ;   CALL lbc_lnk( e3uw_0, 'U', 1._wp )   ! lateral boundary conditions
+      CALL lbc_lnk( e3v_0 , 'V', 1._wp )   ;   CALL lbc_lnk( e3vw_0, 'V', 1._wp )
       !
       DO jk = 1, jpk                        ! set to z-scale factor if zero (i.e. along closed boundaries)
-         WHERE( e3u (:,:,jk) == 0._wp )   e3u (:,:,jk) = e3t_0(jk)
-         WHERE( e3v (:,:,jk) == 0._wp )   e3v (:,:,jk) = e3t_0(jk)
-         WHERE( e3uw(:,:,jk) == 0._wp )   e3uw(:,:,jk) = e3w_0(jk)
-         WHERE( e3vw(:,:,jk) == 0._wp )   e3vw(:,:,jk) = e3w_0(jk)
+         WHERE( e3u_0 (:,:,jk) == 0._wp )   e3u_0 (:,:,jk) = e3t_1d(jk)
+         WHERE( e3v_0 (:,:,jk) == 0._wp )   e3v_0 (:,:,jk) = e3t_1d(jk)
+         WHERE( e3uw_0(:,:,jk) == 0._wp )   e3uw_0(:,:,jk) = e3w_1d(jk)
+         WHERE( e3vw_0(:,:,jk) == 0._wp )   e3vw_0(:,:,jk) = e3w_1d(jk)
       END DO
       
       ! Scale factor at F-point
       DO jk = 1, jpk                        ! initialisation to z-scale factors
-         e3f(:,:,jk) = e3t_0(jk)
+         e3f_0(:,:,jk) = e3t_1d(jk)
       END DO
       DO jk = 1, jpk                        ! Computed as the minimum of neighbooring V-scale factors
          DO jj = 1, jpjm1
             DO ji = 1, fs_jpim1   ! vector opt.
-               e3f(ji,jj,jk) = MIN( e3v(ji,jj,jk), e3v(ji+1,jj,jk) )
-            END DO
-         END DO
-      END DO
-      CALL lbc_lnk( e3f, 'F', 1._wp )       ! Lateral boundary conditions
+               e3f_0(ji,jj,jk) = MIN( e3v_0(ji,jj,jk), e3v_0(ji+1,jj,jk) )
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk( e3f_0, 'F', 1._wp )       ! Lateral boundary conditions
       !
       DO jk = 1, jpk                        ! set to z-scale factor if zero (i.e. along closed boundaries)
-         WHERE( e3f(:,:,jk) == 0._wp )   e3f(:,:,jk) = e3t_0(jk)
+         WHERE( e3f_0(:,:,jk) == 0._wp )   e3f_0(:,:,jk) = e3t_1d(jk)
       END DO
 !!gm  bug ? :  must be a do loop with mj0,mj1
       ! 
-      e3t(:,mj0(1),:) = e3t(:,mj0(2),:)     ! we duplicate factor scales for jj = 1 and jj = 2
-      e3w(:,mj0(1),:) = e3w(:,mj0(2),:) 
-      e3u(:,mj0(1),:) = e3u(:,mj0(2),:) 
-      e3v(:,mj0(1),:) = e3v(:,mj0(2),:) 
-      e3f(:,mj0(1),:) = e3f(:,mj0(2),:) 
+      e3t_0(:,mj0(1),:) = e3t_0(:,mj0(2),:)     ! we duplicate factor scales for jj = 1 and jj = 2
+      e3w_0(:,mj0(1),:) = e3w_0(:,mj0(2),:) 
+      e3u_0(:,mj0(1),:) = e3u_0(:,mj0(2),:) 
+      e3v_0(:,mj0(1),:) = e3v_0(:,mj0(2),:) 
+      e3f_0(:,mj0(1),:) = e3f_0(:,mj0(2),:) 
 
       ! Control of the sign
-      IF( MINVAL( e3t  (:,:,:) ) <= 0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   e3t   <= 0' )
-      IF( MINVAL( e3w  (:,:,:) ) <= 0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   e3w   <= 0' )
-      IF( MINVAL( gdept(:,:,:) ) <  0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   gdepw <  0' )
-      IF( MINVAL( gdepw(:,:,:) ) <  0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   gdepw <  0' )
+      IF( MINVAL( e3t_0  (:,:,:) ) <= 0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   e3t_0 <= 0' )
+      IF( MINVAL( e3w_0  (:,:,:) ) <= 0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   e3w_0 <= 0' )
+      IF( MINVAL( gdept_0(:,:,:) ) <  0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   gdept_0 <  0' )
+      IF( MINVAL( gdepw_0(:,:,:) ) <  0._wp )   CALL ctl_stop( '    zgr_zps :   e r r o r   gdepw_0 <  0' )
      
-      ! Compute gdep3w (vertical sum of e3w)
-      gdep3w(:,:,1) = 0.5_wp * e3w(:,:,1)
+      ! Compute gdep3w_0 (vertical sum of e3w)
+      gdep3w_0(:,:,1) = 0.5_wp * e3w_0(:,:,1)
       DO jk = 2, jpk
-         gdep3w(:,:,jk) = gdep3w(:,:,jk-1) + e3w(:,:,jk) 
+         gdep3w_0(:,:,jk) = gdep3w_0(:,:,jk-1) + e3w_0(:,:,jk) 
       END DO
         
@@ -1043,10 +1043,10 @@
             DO ji = 1, jpi
                ik = MAX( mbathy(ji,jj), 1 )
-               zprt(ji,jj,1) = e3t   (ji,jj,ik)
-               zprt(ji,jj,2) = e3w   (ji,jj,ik)
-               zprt(ji,jj,3) = e3u   (ji,jj,ik)
-               zprt(ji,jj,4) = e3v   (ji,jj,ik)
-               zprt(ji,jj,5) = e3f   (ji,jj,ik)
-               zprt(ji,jj,6) = gdep3w(ji,jj,ik)
+               zprt(ji,jj,1) = e3t_0   (ji,jj,ik)
+               zprt(ji,jj,2) = e3w_0   (ji,jj,ik)
+               zprt(ji,jj,3) = e3u_0   (ji,jj,ik)
+               zprt(ji,jj,4) = e3v_0   (ji,jj,ik)
+               zprt(ji,jj,5) = e3f_0   (ji,jj,ik)
+               zprt(ji,jj,6) = gdep3w_0(ji,jj,ik)
             END DO
          END DO
@@ -1387,22 +1387,22 @@
       ENDIF 
 
-      CALL lbc_lnk( e3t , 'T', 1._wp )
-      CALL lbc_lnk( e3u , 'U', 1._wp )
-      CALL lbc_lnk( e3v , 'V', 1._wp )
-      CALL lbc_lnk( e3f , 'F', 1._wp )
-      CALL lbc_lnk( e3w , 'W', 1._wp )
-      CALL lbc_lnk( e3uw, 'U', 1._wp )
-      CALL lbc_lnk( e3vw, 'V', 1._wp )
-
-      fsdepw(:,:,:) = gdepw (:,:,:)
-      fsde3w(:,:,:) = gdep3w(:,:,:)
-      !
-      where (e3t   (:,:,:).eq.0.0)  e3t(:,:,:) = 1._wp
-      where (e3u   (:,:,:).eq.0.0)  e3u(:,:,:) = 1._wp
-      where (e3v   (:,:,:).eq.0.0)  e3v(:,:,:) = 1._wp
-      where (e3f   (:,:,:).eq.0.0)  e3f(:,:,:) = 1._wp
-      where (e3w   (:,:,:).eq.0.0)  e3w(:,:,:) = 1._wp
-      where (e3uw  (:,:,:).eq.0.0)  e3uw(:,:,:) = 1._wp
-      where (e3vw  (:,:,:).eq.0.0)  e3vw(:,:,:) = 1._wp
+      CALL lbc_lnk( e3t_0 , 'T', 1._wp )
+      CALL lbc_lnk( e3u_0 , 'U', 1._wp )
+      CALL lbc_lnk( e3v_0 , 'V', 1._wp )
+      CALL lbc_lnk( e3f_0 , 'F', 1._wp )
+      CALL lbc_lnk( e3w_0 , 'W', 1._wp )
+      CALL lbc_lnk( e3uw_0, 'U', 1._wp )
+      CALL lbc_lnk( e3vw_0, 'V', 1._wp )
+
+      fsdepw(:,:,:) = gdepw_0 (:,:,:)
+      fsde3w(:,:,:) = gdep3w_0(:,:,:)
+      !
+      where (e3t_0   (:,:,:).eq.0.0)  e3t_0(:,:,:) = 1.0
+      where (e3u_0   (:,:,:).eq.0.0)  e3u_0(:,:,:) = 1.0
+      where (e3v_0   (:,:,:).eq.0.0)  e3v_0(:,:,:) = 1.0
+      where (e3f_0   (:,:,:).eq.0.0)  e3f_0(:,:,:) = 1.0
+      where (e3w_0   (:,:,:).eq.0.0)  e3w_0(:,:,:) = 1.0
+      where (e3uw_0  (:,:,:).eq.0.0)  e3uw_0(:,:,:) = 1.0
+      where (e3vw_0  (:,:,:).eq.0.0)  e3vw_0(:,:,:) = 1.0
 
 #if defined key_agrif
@@ -1411,17 +1411,17 @@
          !  
          IF((nbondi == -1).OR.(nbondi == 2)) THEN
-            e3u(1,:,:) = e3u(2,:,:)
+            e3u_0(1,:,:) = e3u_0(2,:,:)
          ENDIF
          !
          IF((nbondi ==  1).OR.(nbondi == 2)) THEN
-            e3u(nlci-1,:,:) = e3u(nlci-2,:,:)
+            e3u_0(nlci-1,:,:) = e3u_0(nlci-2,:,:)
          ENDIF
          !
          IF((nbondj == -1).OR.(nbondj == 2)) THEN
-            e3v(:,1,:) = e3v(:,2,:)
+            e3v_0(:,1,:) = e3v_0(:,2,:)
          ENDIF
          !
          IF((nbondj ==  1).OR.(nbondj == 2)) THEN
-            e3v(:,nlcj-1,:) = e3v(:,nlcj-2,:)
+            e3v_0(:,nlcj-1,:) = e3v_0(:,nlcj-2,:)
          ENDIF
          !
@@ -1429,14 +1429,14 @@
 #endif
 
-      fsdept(:,:,:) = gdept (:,:,:)
-      fsdepw(:,:,:) = gdepw (:,:,:)
-      fsde3w(:,:,:) = gdep3w(:,:,:)
-      fse3t (:,:,:) = e3t   (:,:,:)
-      fse3u (:,:,:) = e3u   (:,:,:)
-      fse3v (:,:,:) = e3v   (:,:,:)
-      fse3f (:,:,:) = e3f   (:,:,:)
-      fse3w (:,:,:) = e3w   (:,:,:)
-      fse3uw(:,:,:) = e3uw  (:,:,:)
-      fse3vw(:,:,:) = e3vw  (:,:,:)
+      fsdept(:,:,:) = gdept_0 (:,:,:)
+      fsdepw(:,:,:) = gdepw_0 (:,:,:)
+      fsde3w(:,:,:) = gdep3w_0(:,:,:)
+      fse3t (:,:,:) = e3t_0   (:,:,:)
+      fse3u (:,:,:) = e3u_0   (:,:,:)
+      fse3v (:,:,:) = e3v_0   (:,:,:)
+      fse3f (:,:,:) = e3f_0   (:,:,:)
+      fse3w (:,:,:) = e3w_0   (:,:,:)
+      fse3uw(:,:,:) = e3uw_0  (:,:,:)
+      fse3vw(:,:,:) = e3vw_0  (:,:,:)
 !!
       ! HYBRID : 
@@ -1453,18 +1453,18 @@
 
       IF( nprint == 1  .AND. lwp )   THEN         ! min max values over the local domain
-         WRITE(numout,*) ' MIN val mbathy  ', MINVAL( mbathy(:,:)   ), ' MAX ', MAXVAL( mbathy(:,:) )
-         WRITE(numout,*) ' MIN val depth t ', MINVAL( fsdept(:,:,:) ),   &
-            &                          ' w ', MINVAL( fsdepw(:,:,:) ), '3w '  , MINVAL( fsde3w(:,:,:) )
-         WRITE(numout,*) ' MIN val e3    t ', MINVAL( fse3t (:,:,:) ), ' f '  , MINVAL( fse3f (:,:,:) ),   &
-            &                          ' u ', MINVAL( fse3u (:,:,:) ), ' u '  , MINVAL( fse3v (:,:,:) ),   &
-            &                          ' uw', MINVAL( fse3uw(:,:,:) ), ' vw'  , MINVAL( fse3vw(:,:,:) ),   &
-            &                          ' w ', MINVAL( fse3w (:,:,:) )
-
-         WRITE(numout,*) ' MAX val depth t ', MAXVAL( fsdept(:,:,:) ),   &
-            &                          ' w ', MAXVAL( fsdepw(:,:,:) ), '3w '  , MAXVAL( fsde3w(:,:,:) )
-         WRITE(numout,*) ' MAX val e3    t ', MAXVAL( fse3t (:,:,:) ), ' f '  , MAXVAL( fse3f (:,:,:) ),   &
-            &                          ' u ', MAXVAL( fse3u (:,:,:) ), ' u '  , MAXVAL( fse3v (:,:,:) ),   &
-            &                          ' uw', MAXVAL( fse3uw(:,:,:) ), ' vw'  , MAXVAL( fse3vw(:,:,:) ),   &
-            &                          ' w ', MAXVAL( fse3w (:,:,:) )
+         WRITE(numout,*) ' MIN val mbathy  ', MINVAL( mbathy(:,:)    ), ' MAX ', MAXVAL( mbathy(:,:) )
+         WRITE(numout,*) ' MIN val depth t ', MINVAL( gdept_0(:,:,:) ),   &
+            &                          ' w ', MINVAL( gdepw_0(:,:,:) ), '3w '  , MINVAL( gdep3w_0(:,:,:) )
+         WRITE(numout,*) ' MIN val e3    t ', MINVAL( e3t_0  (:,:,:) ), ' f '  , MINVAL( e3f_0   (:,:,:) ),   &
+            &                          ' u ', MINVAL( e3u_0  (:,:,:) ), ' u '  , MINVAL( e3v_0   (:,:,:) ),   &
+            &                          ' uw', MINVAL( e3uw_0 (:,:,:) ), ' vw'  , MINVAL( e3vw_0  (:,:,:) ),   &
+            &                          ' w ', MINVAL( e3w_0  (:,:,:) )
+
+         WRITE(numout,*) ' MAX val depth t ', MAXVAL( gdept_0(:,:,:) ),   &
+            &                          ' w ', MAXVAL( gdepw_0(:,:,:) ), '3w '  , MAXVAL( gdep3w_0(:,:,:) )
+         WRITE(numout,*) ' MAX val e3    t ', MAXVAL( e3t_0  (:,:,:) ), ' f '  , MAXVAL( e3f_0   (:,:,:) ),   &
+            &                          ' u ', MAXVAL( e3u_0  (:,:,:) ), ' u '  , MAXVAL( e3v_0   (:,:,:) ),   &
+            &                          ' uw', MAXVAL( e3uw_0 (:,:,:) ), ' vw'  , MAXVAL( e3vw_0  (:,:,:) ),   &
+            &                          ' w ', MAXVAL( e3w_0  (:,:,:) )
       ENDIF
       !  END DO
@@ -1473,31 +1473,25 @@
          WRITE(numout,*) ' domzgr: vertical coordinates : point (1,1,k) bathy = ', bathy(1,1), hbatt(1,1)
          WRITE(numout,*) ' ~~~~~~  --------------------'
-         WRITE(numout,"(9x,' level   gdept    gdepw    gde3w     e3t      e3w  ')")
-         WRITE(numout,"(10x,i4,4f9.2)") ( jk, fsdept(1,1,jk), fsdepw(1,1,jk),     &
-            &                                 fse3t (1,1,jk), fse3w (1,1,jk), jk=1,jpk )
-         iip1 = MIN(20, jpiglo-1)  ! for config with i smaller than 20 points
-         ijp1 = MIN(20, jpjglo-1)  ! for config with j smaller than 20 points
-         DO jj = mj0(ijp1), mj1(ijp1)
-            DO ji = mi0(iip1), mi1(iip1)
+         WRITE(numout,"(9x,' level  gdept_0   gdepw_0   e3t_0    e3w_0')")
+         WRITE(numout,"(10x,i4,4f9.2)") ( jk, gdept_0(1,1,jk), gdepw_0(1,1,jk),     &
+            &                                 e3t_0 (1,1,jk) , e3w_0 (1,1,jk) , jk=1,jpk )
+         DO jj = mj0(20), mj1(20)
+            DO ji = mi0(20), mi1(20)
                WRITE(numout,*)
-               WRITE(numout,*) ' domzgr: vertical coordinates : point (',iip1,',',ijp1,',k)   bathy = ',  &
-                  &                                              bathy(ji,jj), hbatt(ji,jj)
+               WRITE(numout,*) ' domzgr: vertical coordinates : point (20,20,k)   bathy = ', bathy(ji,jj), hbatt(ji,jj)
                WRITE(numout,*) ' ~~~~~~  --------------------'
-               WRITE(numout,"(9x,' level   gdept    gdepw    gde3w     e3t      e3w  ')")
-               WRITE(numout,"(10x,i4,4f9.2)") ( jk, fsdept(ji,jj,jk), fsdepw(ji,jj,jk),     &
-                  &                                 fse3t (ji,jj,jk), fse3w (ji,jj,jk), jk=1,jpk )
-            END DO
-         END DO
-         iip1 = MIN(  74, jpiglo-1)
-         ijp1 = MIN( 100, jpjglo-1)
-         DO jj = mj0(ijp1), mj1(ijp1)
-            DO ji = mi0(iip1), mi1(iip1)
+               WRITE(numout,"(9x,' level  gdept_0   gdepw_0   e3t_0    e3w_0')")
+               WRITE(numout,"(10x,i4,4f9.2)") ( jk, gdept_0(ji,jj,jk), gdepw_0(ji,jj,jk),     &
+                  &                                 e3t_0 (ji,jj,jk) , e3w_0 (ji,jj,jk) , jk=1,jpk )
+            END DO
+         END DO
+         DO jj = mj0(74), mj1(74)
+            DO ji = mi0(100), mi1(100)
                WRITE(numout,*)
-               WRITE(numout,*) ' domzgr: vertical coordinates : point (',iip1,',',ijp1,',k)   bathy = ',  &
-                  &                                              bathy(ji,jj), hbatt(ji,jj)
+               WRITE(numout,*) ' domzgr: vertical coordinates : point (100,74,k)   bathy = ', bathy(ji,jj), hbatt(ji,jj)
                WRITE(numout,*) ' ~~~~~~  --------------------'
-               WRITE(numout,"(9x,' level   gdept    gdepw    gde3w     e3t      e3w  ')")
-               WRITE(numout,"(10x,i4,4f9.2)") ( jk, fsdept(ji,jj,jk), fsdepw(ji,jj,jk),     &
-                  &                                 fse3t (ji,jj,jk), fse3w (ji,jj,jk), jk=1,jpk )
+               WRITE(numout,"(9x,' level  gdept_0   gdepw_0   e3t_0    e3w_0')")
+               WRITE(numout,"(10x,i4,4f9.2)") ( jk, gdept_0(ji,jj,jk), gdepw_0(ji,jj,jk),     &
+                  &                                 e3t_0 (ji,jj,jk) , e3w_0 (ji,jj,jk) , jk=1,jpk )
             END DO
          END DO
@@ -1617,7 +1611,7 @@
                zcoeft = ( REAL(jk,wp) - 0.5_wp ) / REAL(jpkm1,wp)
                zcoefw = ( REAL(jk,wp) - 1.0_wp ) / REAL(jpkm1,wp)
-               gdept (ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsigt3(ji,jj,jk)+rn_hc*zcoeft )
-               gdepw (ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsigw3(ji,jj,jk)+rn_hc*zcoefw )
-               gdep3w(ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsi3w3(ji,jj,jk)+rn_hc*zcoeft )
+               gdept_0 (ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsigt3(ji,jj,jk)+rn_hc*zcoeft )
+               gdepw_0 (ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsigw3(ji,jj,jk)+rn_hc*zcoefw )
+               gdep3w_0(ji,jj,jk) = ( scosrf(ji,jj) + (hbatt(ji,jj)-rn_hc)*z_gsi3w3(ji,jj,jk)+rn_hc*zcoeft )
             END DO
            !
@@ -1640,12 +1634,12 @@
                   &              / ( hbatt(ji,jj)+hbatt(ji,jj+1) )
                !
-               e3t(ji,jj,jk) = ( (hbatt(ji,jj)-rn_hc)*z_esigt3 (ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
-               e3u(ji,jj,jk) = ( (hbatu(ji,jj)-rn_hc)*z_esigtu3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
-               e3v(ji,jj,jk) = ( (hbatv(ji,jj)-rn_hc)*z_esigtv3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
-               e3f(ji,jj,jk) = ( (hbatf(ji,jj)-rn_hc)*z_esigtf3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
+               e3t_0(ji,jj,jk) = ( (hbatt(ji,jj)-rn_hc)*z_esigt3 (ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
+               e3u_0(ji,jj,jk) = ( (hbatu(ji,jj)-rn_hc)*z_esigtu3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
+               e3v_0(ji,jj,jk) = ( (hbatv(ji,jj)-rn_hc)*z_esigtv3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
+               e3f_0(ji,jj,jk) = ( (hbatf(ji,jj)-rn_hc)*z_esigtf3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
                !
-               e3w (ji,jj,jk) = ( (hbatt(ji,jj)-rn_hc)*z_esigw3 (ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
-               e3uw(ji,jj,jk) = ( (hbatu(ji,jj)-rn_hc)*z_esigwu3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
-               e3vw(ji,jj,jk) = ( (hbatv(ji,jj)-rn_hc)*z_esigwv3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
+               e3w_0 (ji,jj,jk) = ( (hbatt(ji,jj)-rn_hc)*z_esigw3 (ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
+               e3uw_0(ji,jj,jk) = ( (hbatu(ji,jj)-rn_hc)*z_esigwu3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
+               e3vw_0(ji,jj,jk) = ( (hbatv(ji,jj)-rn_hc)*z_esigwv3(ji,jj,jk) + rn_hc/REAL(jpkm1,wp) )
             END DO
         END DO
@@ -1745,7 +1739,7 @@
 
           DO jk = 1, jpk
-             gdept (ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsigt3(ji,jj,jk)
-             gdepw (ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsigw3(ji,jj,jk)
-             gdep3w(ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsi3w3(ji,jj,jk)
+             gdept_0 (ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsigt3(ji,jj,jk)
+             gdepw_0 (ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsigw3(ji,jj,jk)
+             gdep3w_0(ji,jj,jk) = (scosrf(ji,jj)+hbatt(ji,jj))*z_gsi3w3(ji,jj,jk)
           END DO
 
@@ -1769,16 +1763,21 @@
                                     ( hbatt(ji,jj)+hbatt(ji,jj+1) )
 
-             e3t(ji,jj,jk)=(scosrf(ji,jj)+hbatt(ji,jj))*z_esigt3(ji,jj,jk)
-             e3u(ji,jj,jk)=(scosrf(ji,jj)+hbatu(ji,jj))*z_esigtu3(ji,jj,jk)
-             e3v(ji,jj,jk)=(scosrf(ji,jj)+hbatv(ji,jj))*z_esigtv3(ji,jj,jk)
-             e3f(ji,jj,jk)=(scosrf(ji,jj)+hbatf(ji,jj))*z_esigtf3(ji,jj,jk)
+             e3t_0(ji,jj,jk)=(scosrf(ji,jj)+hbatt(ji,jj))*z_esigt3(ji,jj,jk)
+             e3u_0(ji,jj,jk)=(scosrf(ji,jj)+hbatu(ji,jj))*z_esigtu3(ji,jj,jk)
+             e3v_0(ji,jj,jk)=(scosrf(ji,jj)+hbatv(ji,jj))*z_esigtv3(ji,jj,jk)
+             e3f_0(ji,jj,jk)=(scosrf(ji,jj)+hbatf(ji,jj))*z_esigtf3(ji,jj,jk)
              !
-             e3w(ji,jj,jk)=hbatt(ji,jj)*z_esigw3(ji,jj,jk)
-             e3uw(ji,jj,jk)=hbatu(ji,jj)*z_esigwu3(ji,jj,jk)
-             e3vw(ji,jj,jk)=hbatv(ji,jj)*z_esigwv3(ji,jj,jk)
+             e3w_0(ji,jj,jk)=hbatt(ji,jj)*z_esigw3(ji,jj,jk)
+             e3uw_0(ji,jj,jk)=hbatu(ji,jj)*z_esigwu3(ji,jj,jk)
+             e3vw_0(ji,jj,jk)=hbatv(ji,jj)*z_esigwv3(ji,jj,jk)
           END DO
 
         ENDDO
       ENDDO
+      !
+      CALL lbc_lnk(e3t_0 ,'T',1.) ; CALL lbc_lnk(e3u_0 ,'T',1.)
+      CALL lbc_lnk(e3v_0 ,'T',1.) ; CALL lbc_lnk(e3f_0 ,'T',1.)
+      CALL lbc_lnk(e3w_0 ,'T',1.)
+      CALL lbc_lnk(e3uw_0,'T',1.) ; CALL lbc_lnk(e3vw_0,'T',1.)
       !
       !                                               ! =============
@@ -1838,7 +1837,7 @@
          zcoeft = ( REAL(jk,wp) - 0.5_wp ) / REAL(jpkm1,wp)
          zcoefw = ( REAL(jk,wp) - 1.0_wp ) / REAL(jpkm1,wp)
-         gdept (:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsigt(jk) + hift(:,:)*zcoeft )
-         gdepw (:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsigw(jk) + hift(:,:)*zcoefw )
-         gdep3w(:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsi3w(jk) + hift(:,:)*zcoeft )
+         gdept_0 (:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsigt(jk) + hift(:,:)*zcoeft )
+         gdepw_0 (:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsigw(jk) + hift(:,:)*zcoefw )
+         gdep3w_0(:,:,jk) = ( scosrf(:,:) + (hbatt(:,:)-hift(:,:))*z_gsi3w(jk) + hift(:,:)*zcoeft )
       END DO
 !!gm: e3uw, e3vw can be suppressed  (modif in dynzdf, dynzdf_iso, zdfbfr) (save 2 3D arrays)
@@ -1846,12 +1845,12 @@
          DO ji = 1, jpi
             DO jk = 1, jpk
-              e3t(ji,jj,jk) = ( (hbatt(ji,jj)-hift(ji,jj))*z_esigt(jk) + hift(ji,jj)/REAL(jpkm1,wp) )
-              e3u(ji,jj,jk) = ( (hbatu(ji,jj)-hifu(ji,jj))*z_esigt(jk) + hifu(ji,jj)/REAL(jpkm1,wp) )
-              e3v(ji,jj,jk) = ( (hbatv(ji,jj)-hifv(ji,jj))*z_esigt(jk) + hifv(ji,jj)/REAL(jpkm1,wp) )
-              e3f(ji,jj,jk) = ( (hbatf(ji,jj)-hiff(ji,jj))*z_esigt(jk) + hiff(ji,jj)/REAL(jpkm1,wp) )
+              e3t_0(ji,jj,jk) = ( (hbatt(ji,jj)-hift(ji,jj))*z_esigt(jk) + hift(ji,jj)/REAL(jpkm1,wp) )
+              e3u_0(ji,jj,jk) = ( (hbatu(ji,jj)-hifu(ji,jj))*z_esigt(jk) + hifu(ji,jj)/REAL(jpkm1,wp) )
+              e3v_0(ji,jj,jk) = ( (hbatv(ji,jj)-hifv(ji,jj))*z_esigt(jk) + hifv(ji,jj)/REAL(jpkm1,wp) )
+              e3f_0(ji,jj,jk) = ( (hbatf(ji,jj)-hiff(ji,jj))*z_esigt(jk) + hiff(ji,jj)/REAL(jpkm1,wp) )
               !
-              e3w (ji,jj,jk) = ( (hbatt(ji,jj)-hift(ji,jj))*z_esigw(jk) + hift(ji,jj)/REAL(jpkm1,wp) )
-              e3uw(ji,jj,jk) = ( (hbatu(ji,jj)-hifu(ji,jj))*z_esigw(jk) + hifu(ji,jj)/REAL(jpkm1,wp) )
-              e3vw(ji,jj,jk) = ( (hbatv(ji,jj)-hifv(ji,jj))*z_esigw(jk) + hifv(ji,jj)/REAL(jpkm1,wp) )
+              e3w_0 (ji,jj,jk) = ( (hbatt(ji,jj)-hift(ji,jj))*z_esigw(jk) + hift(ji,jj)/REAL(jpkm1,wp) )
+              e3uw_0(ji,jj,jk) = ( (hbatu(ji,jj)-hifu(ji,jj))*z_esigw(jk) + hifu(ji,jj)/REAL(jpkm1,wp) )
+              e3vw_0(ji,jj,jk) = ( (hbatv(ji,jj)-hifv(ji,jj))*z_esigw(jk) + hifv(ji,jj)/REAL(jpkm1,wp) )
             END DO
          END DO
@@ -1878,5 +1877,5 @@
       !!----------------------------------------------------------------------
       !
-      pf =   (   TANH( rn_theta * ( -(pk-0.5_wp) / REAL(jpkm1,wp) + rn_thetb )  )   &
+      pf =   (   TANH( rn_theta * ( -(pk-0.5_wp) / REAL(jpkm1) + rn_thetb )  )   &
          &     - TANH( rn_thetb * rn_theta                                )  )   &
          & * (   COSH( rn_theta                           )                      &
@@ -1904,8 +1903,8 @@
       !
       IF ( rn_theta == 0 ) then      ! uniform sigma
-         pf1 = - ( pk1 - 0.5_wp ) / REAL( jpkm1,wp )
+         pf1 = - ( pk1 - 0.5_wp ) / REAL( jpkm1 )
       ELSE                        ! stretched sigma
-         pf1 =   ( 1._wp - pbb ) * ( SINH( rn_theta*(-(pk1-0.5_wp)/REAL(jpkm1,wp)) ) ) / SINH( rn_theta )              &
-            &  + pbb * (  (TANH( rn_theta*( (-(pk1-0.5_wp)/REAL(jpkm1,wp)) + 0.5_wp) ) - TANH( 0.5_wp * rn_theta )  )  &
+         pf1 =   ( 1._wp - pbb ) * ( SINH( rn_theta*(-(pk1-0.5_wp)/REAL(jpkm1)) ) ) / SINH( rn_theta )              &
+            &  + pbb * (  (TANH( rn_theta*( (-(pk1-0.5_wp)/REAL(jpkm1)) + 0.5_wp) ) - TANH( 0.5_wp * rn_theta )  )  &
             &        / ( 2._wp * TANH( 0.5_wp * rn_theta ) )  )
       ENDIF
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr_substitute.h90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr_substitute.h90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr_substitute.h90	(revision 4292)
@@ -8,86 +8,85 @@
    !!            3.1  !  2009-02  (G. Madec, M. Leclair)  pure z* coordinate
    !!----------------------------------------------------------------------
-! reference for s- or zps-coordinate (3D no time dependency)
-#   define  fsdept_0(i,j,k)  gdept(i,j,k)
-#   define  fsdepw_0(i,j,k)  gdepw(i,j,k)
-#   define  fsde3w_0(i,j,k)  gdep3w(i,j,k)
-#   define  fse3t_0(i,j,k)   e3t(i,j,k)
-#   define  fse3u_0(i,j,k)   e3u(i,j,k)
-#   define  fse3v_0(i,j,k)   e3v(i,j,k)
-#   define  fse3f_0(i,j,k)   e3f(i,j,k)
-#   define  fse3w_0(i,j,k)   e3w(i,j,k)
-#   define  fse3uw_0(i,j,k)  e3uw(i,j,k)
-#   define  fse3vw_0(i,j,k)  e3vw(i,j,k)
+
 #if defined key_vvl
-! s* or z*-coordinate (3D + time dependency) + use of additional now arrays (..._1)
-#   define  fsdept(i,j,k)  gdept_1(i,j,k)
-#   define  fsdepw(i,j,k)  gdepw_1(i,j,k)
-#   define  fsde3w(i,j,k)  gdep3w_1(i,j,k)
-#   define  fse3t(i,j,k)   e3t_1(i,j,k)
-#   define  fse3u(i,j,k)   e3u_1(i,j,k)
-#   define  fse3v(i,j,k)   e3v_1(i,j,k)
-#   define  fse3f(i,j,k)   e3f_1(i,j,k)
-#   define  fse3w(i,j,k)   e3w_1(i,j,k)
-#   define  fse3uw(i,j,k)  e3uw_1(i,j,k)
-#   define  fse3vw(i,j,k)  e3vw_1(i,j,k)
+! s* or z*-coordinate (3D + time dependency) + use of additional now arrays (..._n)
 
 #   define  fse3t_b(i,j,k)   e3t_b(i,j,k)
 #   define  fse3u_b(i,j,k)   e3u_b(i,j,k)
 #   define  fse3v_b(i,j,k)   e3v_b(i,j,k)
-#   define  fse3uw_b(i,j,k)  (fse3uw_0(i,j,k)*(1.+sshu_b(i,j)*muu(i,j,k)))
-#   define  fse3vw_b(i,j,k)  (fse3vw_0(i,j,k)*(1.+sshv_b(i,j)*muv(i,j,k)))
+#   define  fse3uw_b(i,j,k)  e3uw_b(i,j,k)
+#   define  fse3vw_b(i,j,k)  e3vw_b(i,j,k)
 
-#   define  fsdept_n(i,j,k)  (fsdept_0(i,j,k)*(1.+sshn(i,j)*mut(i,j,k)))
-#   define  fsdepw_n(i,j,k)  (fsdepw_0(i,j,k)*(1.+sshn(i,j)*mut(i,j,k)))
-#   define  fsde3w_n(i,j,k)  (fsde3w_0(i,j,k)*(1.+sshn(i,j)*mut(i,j,k))-sshn(i,j))
-#   define  fse3t_n(i,j,k)   (fse3t_0(i,j,k)*(1.+sshn(i,j)*mut(i,j,k)))
-#   define  fse3u_n(i,j,k)   (fse3u_0(i,j,k)*(1.+sshu_n(i,j)*muu(i,j,k)))
-#   define  fse3v_n(i,j,k)   (fse3v_0(i,j,k)*(1.+sshv_n(i,j)*muv(i,j,k)))
-#   define  fse3f_n(i,j,k)   (fse3f_0(i,j,k)*(1.+sshf_n(i,j)*muf(i,j,k)))
-#   define  fse3w_n(i,j,k)   (fse3w_0(i,j,k)*(1.+sshn(i,j)*mut(i,j,k)))
-#   define  fse3uw_n(i,j,k)  (fse3uw_0(i,j,k)*(1.+sshu_n(i,j)*muu(i,j,k)))
-#   define  fse3vw_n(i,j,k)  (fse3vw_0(i,j,k)*(1.+sshv_n(i,j)*muv(i,j,k)))
+#   define  fsdept_n(i,j,k)  gdept_n(i,j,k)
+#   define  fsdepw_n(i,j,k)  gdepw_n(i,j,k)
+#   define  fsde3w_n(i,j,k)  gdep3w_n(i,j,k)
+#   define  fse3t_n(i,j,k)   e3t_n(i,j,k)
+#   define  fse3u_n(i,j,k)   e3u_n(i,j,k)
+#   define  fse3v_n(i,j,k)   e3v_n(i,j,k)
+#   define  fse3f_n(i,j,k)   e3f_n(i,j,k)
+#   define  fse3w_n(i,j,k)   e3w_n(i,j,k)
+#   define  fse3uw_n(i,j,k)  e3uw_n(i,j,k)
+#   define  fse3vw_n(i,j,k)  e3vw_n(i,j,k)
 
-#   define  fse3t_m(i,j,k)   (fse3t_0(i,j,k)*(1.+ssh_m(i,j)*mut(i,j,k)))
+#   define  fse3t_a(i,j,k)   e3t_a(i,j,k)
+#   define  fse3u_a(i,j,k)   e3u_a(i,j,k)
+#   define  fse3v_a(i,j,k)   e3v_a(i,j,k)
 
-#   define  fse3t_a(i,j,k)   (fse3t_0(i,j,k)*(1.+ssha(i,j)*mut(i,j,k)))
-#   define  fse3u_a(i,j,k)   (fse3u_0(i,j,k)*(1.+sshu_a(i,j)*muu(i,j,k)))
-#   define  fse3v_a(i,j,k)   (fse3v_0(i,j,k)*(1.+sshv_a(i,j)*muv(i,j,k)))
+#   define  fse3t_m(i,j)     e3t_m(i,j)
+
+! This part should be removed one day ...
+! ... In that case all occurence of the above statement functions
+!     have to be replaced in the code by xxx_n
+#   define  fsdept(i,j,k)    gdept_n(i,j,k)
+#   define  fsdepw(i,j,k)    gdepw_n(i,j,k)
+#   define  fsde3w(i,j,k)    gdep3w_n(i,j,k)
+#   define  fse3t(i,j,k)     e3t_n(i,j,k) 
+#   define  fse3u(i,j,k)     e3u_n(i,j,k) 
+#   define  fse3v(i,j,k)     e3v_n(i,j,k) 
+#   define  fse3f(i,j,k)     e3f_n(i,j,k) 
+#   define  fse3w(i,j,k)     e3w_n(i,j,k) 
+#   define  fse3uw(i,j,k)    e3uw_n(i,j,k)
+#   define  fse3vw(i,j,k)    e3vw_n(i,j,k)
 
 #else
 ! z- or s-coordinate (1D or 3D + no time dependency) use reference in all cases
-#   define  fsdept(i,j,k)  fsdept_0(i,j,k)
-#   define  fsdepw(i,j,k)  fsdepw_0(i,j,k)
-#   define  fsde3w(i,j,k)  fsde3w_0(i,j,k)
-#   define  fse3t(i,j,k)   fse3t_0(i,j,k)
-#   define  fse3u(i,j,k)   fse3u_0(i,j,k)
-#   define  fse3v(i,j,k)   fse3v_0(i,j,k)
-#   define  fse3f(i,j,k)   fse3f_0(i,j,k)
-#   define  fse3w(i,j,k)   fse3w_0(i,j,k)
-#   define  fse3uw(i,j,k)  fse3uw_0(i,j,k)
-#   define  fse3vw(i,j,k)  fse3vw_0(i,j,k)
 
-#   define  fse3t_b(i,j,k)   fse3t_0(i,j,k)
-#   define  fse3u_b(i,j,k)   fse3u_0(i,j,k)
-#   define  fse3v_b(i,j,k)   fse3v_0(i,j,k)
-#   define  fse3uw_b(i,j,k)  fse3uw_0(i,j,k)
-#   define  fse3vw_b(i,j,k)  fse3vw_0(i,j,k)
+#   define  fse3t_b(i,j,k)   e3t_0(i,j,k)
+#   define  fse3u_b(i,j,k)   e3u_0(i,j,k)
+#   define  fse3v_b(i,j,k)   e3v_0(i,j,k)
+#   define  fse3uw_b(i,j,k)  e3uw_0(i,j,k)
+#   define  fse3vw_b(i,j,k)  e3vw_0(i,j,k)
 
-#   define  fsdept_n(i,j,k)  fsdept_0(i,j,k)
-#   define  fsdepw_n(i,j,k)  fsdepw_0(i,j,k)
-#   define  fsde3w_n(i,j,k)  fsde3w_0(i,j,k)
-#   define  fse3t_n(i,j,k)   fse3t_0(i,j,k)
-#   define  fse3u_n(i,j,k)   fse3u_0(i,j,k)
-#   define  fse3v_n(i,j,k)   fse3v_0(i,j,k)
-#   define  fse3f_n(i,j,k)   fse3f_0(i,j,k)
-#   define  fse3w_n(i,j,k)   fse3w_0(i,j,k)
-#   define  fse3uw_n(i,j,k)  fse3uw_0(i,j,k)
-#   define  fse3vw_n(i,j,k)  fse3vw_0(i,j,k)
+#   define  fsdept_n(i,j,k)  gdept_0(i,j,k)
+#   define  fsdepw_n(i,j,k)  gdepw_0(i,j,k)
+#   define  fsde3w_n(i,j,k)  gdep3w_0(i,j,k)
+#   define  fse3t_n(i,j,k)   e3t_0(i,j,k)
+#   define  fse3u_n(i,j,k)   e3u_0(i,j,k)
+#   define  fse3v_n(i,j,k)   e3v_0(i,j,k)
+#   define  fse3f_n(i,j,k)   e3f_0(i,j,k)
+#   define  fse3w_n(i,j,k)   e3w_0(i,j,k)
+#   define  fse3uw_n(i,j,k)  e3uw_0(i,j,k)
+#   define  fse3vw_n(i,j,k)  e3vw_0(i,j,k)
 
-#   define  fse3t_m(i,j,k)   fse3t_0(i,j,k)
+#   define  fse3t_a(i,j,k)   e3t_0(i,j,k)
+#   define  fse3u_a(i,j,k)   e3u_0(i,j,k)
+#   define  fse3v_a(i,j,k)   e3v_0(i,j,k)
 
-#   define  fse3t_a(i,j,k)   fse3t_0(i,j,k)
-#   define  fse3u_a(i,j,k)   fse3u_0(i,j,k)
-#   define  fse3v_a(i,j,k)   fse3v_0(i,j,k)
+#   define  fse3t_m(i,j)     e3t_0(i,j,1)
+
+! This part should be removed one day ...
+! ... In that case all occurence of the above statement functions
+!     have to be replaced in the code by xxx_n
+#   define  fsdept(i,j,k)    gdept_0(i,j,k)
+#   define  fsdepw(i,j,k)    gdepw_0(i,j,k)
+#   define  fsde3w(i,j,k)    gdep3w_0(i,j,k)
+#   define  fse3t(i,j,k)     e3t_0(i,j,k)
+#   define  fse3u(i,j,k)     e3u_0(i,j,k)
+#   define  fse3v(i,j,k)     e3v_0(i,j,k)
+#   define  fse3f(i,j,k)     e3f_0(i,j,k)
+#   define  fse3w(i,j,k)     e3w_0(i,j,k)
+#   define  fse3uw(i,j,k)    e3uw_0(i,j,k)
+#   define  fse3vw(i,j,k)    e3vw_0(i,j,k)
+
 #endif
    !!----------------------------------------------------------------------
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/dtatsd.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/dtatsd.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/dtatsd.F90	(revision 4292)
@@ -221,15 +221,15 @@
             DO ji = 1, jpi
                DO jk = 1, jpk                        ! determines the intepolated T-S profiles at each (i,j) points
-                  zl = fsdept_0(ji,jj,jk)
-                  IF(     zl < gdept_0(1  ) ) THEN          ! above the first level of data
+                  zl = gdept_0(ji,jj,jk)
+                  IF(     zl < gdept_1d(1  ) ) THEN          ! above the first level of data
                      ztp(jk) =  ptsd(ji,jj,1    ,jp_tem)
                      zsp(jk) =  ptsd(ji,jj,1    ,jp_sal)
-                  ELSEIF( zl > gdept_0(jpk) ) THEN          ! below the last level of data
+                  ELSEIF( zl > gdept_1d(jpk) ) THEN          ! below the last level of data
                      ztp(jk) =  ptsd(ji,jj,jpkm1,jp_tem)
                      zsp(jk) =  ptsd(ji,jj,jpkm1,jp_sal)
                   ELSE                                      ! inbetween : vertical interpolation between jkk & jkk+1
                      DO jkk = 1, jpkm1                                  ! when  gdept(jkk) < zl < gdept(jkk+1)
-                        IF( (zl-gdept_0(jkk)) * (zl-gdept_0(jkk+1)) <= 0._wp ) THEN
-                           zi = ( zl - gdept_0(jkk) ) / (gdept_0(jkk+1)-gdept_0(jkk))
+                        IF( (zl-gdept_1d(jkk)) * (zl-gdept_1d(jkk+1)) <= 0._wp ) THEN
+                           zi = ( zl - gdept_1d(jkk) ) / (gdept_1d(jkk+1)-gdept_1d(jkk))
                            ztp(jk) = ptsd(ji,jj,jkk,jp_tem) + ( ptsd(ji,jj,jkk+1,jp_tem) - ptsd(ji,jj,jkk,jp_tem) ) * zi 
                            zsp(jk) = ptsd(ji,jj,jkk,jp_sal) + ( ptsd(ji,jj,jkk+1,jp_sal) - ptsd(ji,jj,jkk,jp_sal) ) * zi
@@ -259,5 +259,5 @@
                   ik = mbkt(ji,jj) 
                   IF( ik > 1 ) THEN
-                     zl = ( gdept_0(ik) - fsdept_0(ji,jj,ik) ) / ( gdept_0(ik) - gdept_0(ik-1) )
+                     zl = ( gdept_1d(ik) - gdept_0(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
                      ptsd(ji,jj,ik,jp_tem) = (1.-zl) * ptsd(ji,jj,ik,jp_tem) + zl * ptsd(ji,jj,ik-1,jp_tem)
                      ptsd(ji,jj,ik,jp_sal) = (1.-zl) * ptsd(ji,jj,ik,jp_sal) + zl * ptsd(ji,jj,ik-1,jp_sal)
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90	(revision 4292)
@@ -94,6 +94,4 @@
          neuler = 1                              ! Set time-step indicator at nit000 (leap-frog)
          CALL rst_read                           ! Read the restart file
-         !                                       ! define e3u_b, e3v_b from e3t_b read in restart file
-         CALL dom_vvl_2( nit000, fse3u_b(:,:,:), fse3v_b(:,:,:) )
          CALL day_init                           ! model calendar (using both namelist and restart infos)
       ELSE
@@ -144,6 +142,4 @@
             ENDDO
          ENDIF
-         !                                       ! define e3u_b, e3v_b from e3t_b initialized in domzgr
-         CALL dom_vvl_2( nit000, fse3u_b(:,:,:), fse3v_b(:,:,:) )
          ! 
       ENDIF
@@ -230,6 +226,6 @@
             IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
             !
-            zh1 = gdept_0(  1  )
-            zh2 = gdept_0(jpkm1)
+            zh1 = gdept_1d(  1  )
+            zh2 = gdept_1d(jpkm1)
             !
             zslope = ( zt1 - zt2 ) / ( zh1 - zh2 )
@@ -411,6 +407,6 @@
          WRITE(numout,*)
          WRITE(numout,*) '              Initial temperature and salinity profiles:'
-         WRITE(numout, "(9x,' level   gdept_0   temperature   salinity   ')" )
-         WRITE(numout, "(10x, i4, 3f10.2)" ) ( jk, gdept_0(jk), tsn(2,2,jk,jp_tem), tsn(2,2,jk,jp_sal), jk = 1, jpk )
+         WRITE(numout, "(9x,' level   gdept_1d   temperature   salinity   ')" )
+         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
 
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 4292)
@@ -767,6 +767,6 @@
       DO jj = 2, jpjm1
         DO ji = 2, jpim1
-          zu(ji,jj,1) = - ( fse3u(ji,jj,1) - sshu_n(ji,jj) * znad)
-          zv(ji,jj,1) = - ( fse3v(ji,jj,1) - sshv_n(ji,jj) * znad)
+          zu(ji,jj,1) = - ( fse3u(ji,jj,1) - sshn(ji,jj) * znad)    ! probable bug: changed from sshu_n for ztilde compilation
+          zv(ji,jj,1) = - ( fse3v(ji,jj,1) - sshn(ji,jj) * znad)    ! probable bug: changed from sshv_n for ztilde compilation
         END DO
       END DO
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 4292)
@@ -17,4 +17,5 @@
    !!            3.3  !  2010-09  (D. Storkey, E.O'Dea) Bug fix for BDY module
    !!            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
    !!-------------------------------------------------------------------------
   
@@ -42,4 +43,6 @@
    USE wrk_nemo        ! Memory Allocation
    USE prtctl          ! Print control
+   USE dynspg_ts       ! Barotropic velocities
+
 #if defined key_agrif
    USE agrif_opa_interp
@@ -103,4 +106,5 @@
       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 
       !!----------------------------------------------------------------------
@@ -109,4 +113,5 @@
       !
       CALL wrk_alloc( jpi,jpj,jpk, ze3u_f, ze3v_f )
+      IF ( lk_dynspg_ts ) CALL wrk_alloc( jpi,jpj, zua, zva )
       !
       IF( kt == nit000 ) THEN
@@ -127,4 +132,6 @@
       !
 #else
+
+# if defined key_dynspg_exp
       ! Next velocity :   Leap-frog time stepping
       ! -------------
@@ -147,5 +154,41 @@
          END DO
       ENDIF
-
+# endif
+
+# if defined key_dynspg_ts
+      ! 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
+      IF (lk_vvl) THEN
+         DO jk = 1, jpkm1
+            zua(:,:) = zua(:,:) + fse3u_a(:,:,jk) * ua(:,:,jk) * umask(:,:,jk)
+            zva(:,:) = zva(:,:) + fse3v_a(:,:,jk) * va(:,:,jk) * vmask(:,:,jk)    
+         END DO
+         DO jk = 1, jpkm1
+            ua(:,:,jk) = ( ua(:,:,jk) - zua(:,:) * hur_e(:,:) + ua_b(:,:) ) * umask(:,:,jk)
+            va(:,:,jk) = ( va(:,:,jk) - zva(:,:) * hvr_e(:,:) + va_b(:,:) ) * vmask(:,:,jk)
+         END DO
+      ELSE
+         DO jk = 1, jpkm1
+            zua(:,:) = zua(:,:) + fse3u(:,:,jk) * ua(:,:,jk) * umask(:,:,jk)
+            zva(:,:) = zva(:,:) + fse3v(:,:,jk) * va(:,:,jk) * vmask(:,:,jk)    
+         END DO
+         DO jk = 1, jpkm1
+            ua(:,:,jk) = ( ua(:,:,jk) - zua(:,:) * hur(:,:) + ua_b(:,:) ) *umask(:,:,jk)
+            va(:,:,jk) = ( va(:,:,jk) - zva(:,:) * hvr(:,:) + va_b(:,:) ) *vmask(:,:,jk)
+         END DO
+      ENDIF
+
+      IF (lk_dynspg_ts.AND.(.NOT.ln_bt_fw)) THEN
+         ! Remove advective velocity from "now velocities" 
+         ! prior to asselin filtering     
+         ! In the forward case, this is done below after asselin filtering    
+         DO jk = 1, jpkm1
+            un(:,:,jk) = ( un(:,:,jk) - un_adv(:,:) + un_b(:,:) )*umask(:,:,jk)
+            vn(:,:,jk) = ( vn(:,:,jk) - vn_adv(:,:) + vn_b(:,:) )*vmask(:,:,jk)
+         END DO  
+      ENDIF
+# endif
 
       ! Update after velocity on domain lateral boundaries
@@ -194,4 +237,11 @@
             vn(:,:,jk) = va(:,:,jk)
          END DO
+         IF (lk_vvl) THEN
+            DO jk = 1, jpkm1
+               fse3t_b(:,:,jk) = fse3t_n(:,:,jk)
+               fse3u_b(:,:,jk) = fse3u_n(:,:,jk)
+               fse3v_b(:,:,jk) = fse3v_n(:,:,jk)
+            ENDDO
+         ENDIF
       ELSE                                             !* Leap-Frog : Asselin filter and swap
          !                                ! =============!
@@ -201,6 +251,6 @@
                DO jj = 1, jpj
                   DO ji = 1, jpi    
-                     zuf = un(ji,jj,jk) + atfp * ( ub(ji,jj,jk) - 2.e0 * un(ji,jj,jk) + ua(ji,jj,jk) )
-                     zvf = vn(ji,jj,jk) + atfp * ( vb(ji,jj,jk) - 2.e0 * vn(ji,jj,jk) + va(ji,jj,jk) )
+                     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) )
                      !
                      ub(ji,jj,jk) = zuf                      ! ub <-- filtered velocity
@@ -214,23 +264,30 @@
          ELSE                             ! Variable volume !
             !                             ! ================!
+            ! Before scale factor at t-points
+            ! (used as a now filtered scale factor until the swap)
+            ! ----------------------------------------------------
+            IF (lk_dynspg_ts.AND.ln_bt_fw) THEN
+               ! Remove asselin filtering on thicknesses if forward time splitting
+                  fse3t_b(:,:,:) = fse3t_n(:,:,:)
+            ELSE
+               fse3t_b(:,:,:) = fse3t_n(:,:,:) + atfp * ( fse3t_b(:,:,:) - 2._wp * fse3t_n(:,:,:) + fse3t_a(:,:,:) )
+               ! Add volume filter correction: compatibility with tracer advection scheme
+               ! => time filter + conservation correction (only at the first level)
+               fse3t_b(:,:,1) = fse3t_b(:,:,1) - atfp * rdt * r1_rau0 * ( emp_b(:,:) - emp(:,:) ) * tmask(:,:,1)
             !
-            DO jk = 1, jpkm1                 ! Before scale factor at t-points
-               fse3t_b(:,:,jk) = fse3t_n(:,:,jk)                                   &
-                  &              + atfp * (  fse3t_b(:,:,jk) + fse3t_a(:,:,jk)     &
-                  &                         - 2._wp * fse3t_n(:,:,jk)            )
-            END DO
-            zec = atfp * rdt / rau0          ! Add filter correction only at the 1st level of t-point scale factors
-            fse3t_b(:,:,1) = fse3t_b(:,:,1) - zec * ( emp_b(:,:) - emp(:,:) ) * tmask(:,:,1)
+            ENDIF
             !
-            IF( ln_dynadv_vec ) THEN         ! vector invariant form (no thickness weighted calulation)
-               !
-               !                                      ! before scale factors at u- & v-pts (computed from fse3t_b)
-               CALL dom_vvl_2( kt, fse3u_b(:,:,:), fse3v_b(:,:,:) )
-               !
-               DO jk = 1, jpkm1                       ! Leap-Frog - Asselin filter and swap: applied on velocity
-                  DO jj = 1, jpj                      !                                                 --------
+            IF( ln_dynadv_vec ) THEN
+               ! Before scale factor at (u/v)-points
+               ! -----------------------------------
+               CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3u_b(:,:,:), 'U' )
+               CALL dom_vvl_interpol( fse3t_b(:,:,:), fse3v_b(:,:,:), 'V' )
+               ! Leap-Frog - Asselin filter and swap: applied on velocity
+               ! -----------------------------------
+               DO jk = 1, jpkm1
+                  DO jj = 1, jpj
                      DO ji = 1, jpi
-                        zuf = un(ji,jj,jk) + atfp * ( ub(ji,jj,jk) - 2.e0 * un(ji,jj,jk) + ua(ji,jj,jk) )
-                        zvf = vn(ji,jj,jk) + atfp * ( vb(ji,jj,jk) - 2.e0 * 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
@@ -242,10 +299,13 @@
                END DO
                !
-            ELSE                             ! flux form (thickness weighted calulation)
-               !
-               CALL dom_vvl_2( kt, ze3u_f, ze3v_f )   ! before scale factors at u- & v-pts (computed from fse3t_b)
-               !
-               DO jk = 1, jpkm1                       ! Leap-Frog - Asselin filter and swap: 
-                  DO jj = 1, jpj                      !                   applied on thickness weighted velocity
+            ELSE
+               ! Temporary filtered scale factor at (u/v)-points (will become before scale factor)
+               !------------------------------------------------
+               CALL dom_vvl_interpol( fse3t_b(:,:,:), ze3u_f, 'U' )
+               CALL dom_vvl_interpol( fse3t_b(:,:,:), ze3v_f, 'V' )
+               ! Leap-Frog - Asselin filter and swap: applied on thickness weighted velocity
+               ! -----------------------------------             ===========================
+               DO jk = 1, jpkm1
+                  DO jj = 1, jpj
                      DO ji = 1, jpi                   !                              ---------------------------
                         zue3a = ua(ji,jj,jk) * fse3u_a(ji,jj,jk)
@@ -272,5 +332,27 @@
          ENDIF
          !
-      ENDIF
+         IF (lk_dynspg_ts.AND.ln_bt_fw) THEN
+         ! Remove asselin filtering of barotropic velocities if forward time splitting
+         ! note that we replace barotropic velocities by advective velocities       
+            zua(:,:) = 0._wp
+            zva(:,:) = 0._wp
+            IF (lk_vvl) THEN
+               DO jk = 1, jpkm1
+                  zua(:,:) = zua(:,:) + fse3u_b(:,:,jk) * ub(:,:,jk) * umask(:,:,jk)
+                  zva(:,:) = zva(:,:) + fse3v_b(:,:,jk) * vb(:,:,jk) * vmask(:,:,jk)    
+               END DO
+            ELSE
+               DO jk = 1, jpkm1
+                  zua(:,:) = zua(:,:) + fse3u(:,:,jk) * ub(:,:,jk) * umask(:,:,jk)
+                  zva(:,:) = zva(:,:) + fse3v(:,:,jk) * vb(:,:,jk) * vmask(:,:,jk)    
+               END DO
+            ENDIF
+            DO jk = 1, jpkm1
+               ub(:,:,jk) = ub(:,:,jk) - (zua(:,:) * hur(:,:) - un_b(:,:)) * umask(:,:,jk)
+               vb(:,:,jk) = vb(:,:,jk) - (zva(:,:) * hvr(:,:) - vn_b(:,:)) * vmask(:,:,jk)
+            END DO
+         ENDIF
+         !
+      ENDIF ! neuler =/0
 
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=un, clinfo1=' nxt  - Un: ', mask1=umask,   &
@@ -278,4 +360,5 @@
       ! 
       CALL wrk_dealloc( jpi,jpj,jpk, ze3u_f, ze3v_f )
+      IF ( lk_dynspg_ts ) CALL wrk_dealloc( jpi,jpj, zua, zva )
       !
       IF( nn_timing == 1 )  CALL timing_stop('dyn_nxt')
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 4292)
@@ -23,4 +23,7 @@
    USE dynspg_flt     ! surface pressure gradient     (dyn_spg_flt routine)
    USE dynadv         ! dynamics: vector invariant versus flux form
+   USE dynhpg, ONLY: ln_dynhpg_imp
+   USE sbctide
+   USE updtide
    USE trdmod         ! ocean dynamics trends
    USE trdmod_oce     ! ocean variables trends
@@ -101,15 +104,57 @@
       ENDIF
 
-      IF( ln_apr_dyn ) THEN                   !==  Atmospheric pressure gradient  ==!
-         zg_2 = grav * 0.5
-         DO jj = 2, jpjm1                          ! gradient of Patm using inverse barometer ssh
+      IF(      ln_apr_dyn                                                &   ! atmos. pressure
+         .OR.  ( .NOT.lk_dynspg_ts .AND. (ln_tide_pot .AND. lk_tide) )   &   ! tide potential (no time slitting)
+         .OR.  nn_ice_embd == 2  ) THEN                                      ! embedded sea-ice
+         !
+         DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               spgu(ji,jj) =  zg_2 * (  ssh_ib (ji+1,jj) - ssh_ib (ji,jj)    &
-                  &                   + ssh_ibb(ji+1,jj) - ssh_ibb(ji,jj)  ) /e1u(ji,jj)
-               spgv(ji,jj) =  zg_2 * (  ssh_ib (ji,jj+1) - ssh_ib (ji,jj)    &
-                  &                   + ssh_ibb(ji,jj+1) - ssh_ibb(ji,jj)  ) /e2v(ji,jj)
-            END DO
-         END DO
-         DO jk = 1, jpkm1                          ! Add the apg to the general trend
+               spgu(ji,jj) = 0._wp
+               spgv(ji,jj) = 0._wp
+            END DO
+         END DO         
+         !
+         IF( ln_apr_dyn .AND. (.NOT. lk_dynspg_ts) ) THEN                    !==  Atmospheric pressure gradient (added later in time-split case) ==!
+            zg_2 = grav * 0.5
+            DO jj = 2, jpjm1                          ! gradient of Patm using inverse barometer ssh
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  spgu(ji,jj) = spgu(ji,jj) + zg_2 * (  ssh_ib (ji+1,jj) - ssh_ib (ji,jj)    &
+                     &                      + ssh_ibb(ji+1,jj) - ssh_ibb(ji,jj)  ) /e1u(ji,jj)
+                  spgv(ji,jj) = spgv(ji,jj) + zg_2 * (  ssh_ib (ji,jj+1) - ssh_ib (ji,jj)    &
+                     &                      + ssh_ibb(ji,jj+1) - ssh_ibb(ji,jj)  ) /e2v(ji,jj)
+               END DO
+            END DO
+         ENDIF
+         !
+         !                                    !==  tide potential forcing term  ==!
+         IF( .NOT.lk_dynspg_ts .AND. ( ln_tide_pot .AND. lk_tide )  ) THEN   ! N.B. added directly at sub-time-step in ts-case
+            !
+            CALL upd_tide( kt )                      ! update tide potential
+            !
+            DO jj = 2, jpjm1                         ! add tide potential forcing
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  spgv(ji,jj) = spgu(ji,jj) + grav * ( pot_astro(ji+1,jj) - pot_astro(ji,jj) ) / e1u(ji,jj)
+                  spgv(ji,jj) = spgv(ji,jj) + grav * ( pot_astro(ji,jj+1) - pot_astro(ji,jj) ) / e2v(ji,jj)
+               END DO 
+            END DO
+         ENDIF
+         !
+         IF( nn_ice_embd == 2 ) THEN          !== embedded sea ice: Pressure gradient due to snow-ice mass ==!
+            CALL wrk_alloc( jpi, jpj, zpice )
+            !                                            
+            zintp = REAL( MOD( kt-1, nn_fsbc ) ) / REAL( nn_fsbc )
+            zgrau0r     = - grav * r1_rau0
+            zpice(:,:) = (  zintp * snwice_mass(:,:) + ( 1.- zintp ) * snwice_mass_b(:,:)  ) * zgrau0r
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  spgu(ji,jj) = spgu(ji,jj) + ( zpice(ji+1,jj) - zpice(ji,jj) ) / e1u(ji,jj)
+                  spgv(ji,jj) = spgv(ji,jj) + ( zpice(ji,jj+1) - zpice(ji,jj) ) / e2v(ji,jj)
+               END DO
+            END DO
+            !
+            CALL wrk_dealloc( jpi, jpj, zpice )         
+         ENDIF
+         !
+         DO jk = 1, jpkm1                     !== Add all terms to the general trend
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -118,31 +163,6 @@
                END DO
             END DO
-         END DO
-      ENDIF
-
-      IF( nn_ice_embd == 2 ) THEN             !== embedded sea ice: Pressure gradient due to snow-ice mass ==!
-         CALL wrk_alloc( jpi, jpj, zpice )
-         !                                            
-         zintp = REAL( MOD( kt-1, nn_fsbc ) ) / REAL( nn_fsbc )
-         zgrau0r     = - grav * r1_rau0
-         zpice(:,:) = (  zintp * snwice_mass(:,:) + ( 1.- zintp ) * snwice_mass_b(:,:)  ) * zgrau0r
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               spgu(ji,jj) = ( zpice(ji+1,jj) - zpice(ji,jj) ) / e1u(ji,jj)
-               spgv(ji,jj) = ( zpice(ji,jj+1) - zpice(ji,jj) ) / e2v(ji,jj)
-            END DO
-         END DO
-         DO jk = 1, jpkm1                             ! Add the surface pressure trend to the general trend
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  ua(ji,jj,jk) = ua(ji,jj,jk) + spgu(ji,jj)
-                  va(ji,jj,jk) = va(ji,jj,jk) + spgv(ji,jj)
-               END DO
-            END DO
-         END DO
-         !
-         CALL wrk_dealloc( jpi, jpj, zpice )
-      ENDIF
-
+         END DO         
+      ENDIF
 
       SELECT CASE ( nspg )                       ! compute surf. pressure gradient trend and add it to the general trend
@@ -209,4 +229,6 @@
       ENDIF
 
+      IF( lk_dynspg_ts ) CALL dyn_spg_ts_init( nit000 )
+      ! (do it now, to set nn_baro, used to allocate some arrays later on)
       !                        ! allocate dyn_spg arrays
       IF( lk_dynspg_ts ) THEN
@@ -248,7 +270,7 @@
       ENDIF
 
-      !                        ! Control of momentum formulation
-      IF( lk_dynspg_ts .AND. lk_vvl ) THEN
-         IF( .NOT.ln_dynadv_vec )   CALL ctl_stop( 'Flux form not implemented for this free surface formulation' )
+      !			       ! Control of hydrostatic pressure choice
+      IF( lk_dynspg_ts .AND. ln_dynhpg_imp ) THEN
+         CALL ctl_stop( 'Semi-implicit hpg not compatible with time splitting' )
       ENDIF
       !
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90	(revision 4292)
@@ -91,5 +91,6 @@
                spgv(ji,jj) = - grav * ( sshn(ji,jj+1) - sshn(ji,jj) ) / e2v(ji,jj)
             END DO 
-         END DO 
+         END DO
+         !
          DO jk = 1, jpkm1                    ! Add it to the general trend
             DO jj = 2, jpjm1
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_oce.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_oce.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_oce.F90	(revision 4292)
@@ -39,4 +39,9 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:), TARGET ::   hur_e , hvr_e    ! inverse of hu_e and hv_e
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:), TARGET ::   sshn_b           ! before field without time-filter
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ua_b, va_b     ! after  averaged velocities
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   un_b, vn_b     ! now    averaged velocities
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ub_b, vb_b     ! before averaged velocities
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   un_adv, vn_adv ! Advection vel. at "now" barocl. step
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ub2_b,  vb2_b  ! Advection vel. at "now-0.5" barocl. step
 
    !!----------------------------------------------------------------------
@@ -53,4 +58,8 @@
       ALLOCATE( sshn_e(jpi,jpj) , ua_e(jpi,jpj) , hu_e(jpi,jpj) , hur_e(jpi,jpj) ,      &
          &      ssha_e(jpi,jpj) , va_e(jpi,jpj) , hv_e(jpi,jpj) , hvr_e(jpi,jpj) ,      &
+         &      ub_b(jpi,jpj)   , vb_b(jpi,jpj) , un_b(jpi,jpj) , vn_b(jpi,jpj)  ,      &
+         &      ua_b(jpi,jpj)   , va_b(jpi,jpj)                                  ,      & 
+         &      ub2_b(jpi,jpj)  , vb2_b(jpi,jpj)                                 ,      &
+         &      un_adv(jpi,jpj) , vn_adv(jpi,jpj)                                ,      &
          &      sshn_b(jpi,jpj)                                                  , STAT = dynspg_oce_alloc )
          !
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 4292)
@@ -9,4 +9,6 @@
    !!             3.3  ! 2010-09  (D. Storkey, E. O'Dea) update for BDY for Shelf configurations
    !!             3.3  ! 2011-03  (R. Benshila, R. Hordoir, P. Oddo) update calculation of ub_b
+   !!             3.5  ! 2013-07  (J. Chanut) Switch to Forward-backward time stepping
+   !!             3.6  ! 2013-11  (A. Coward) Update for z-tilde compatibility
    !!---------------------------------------------------------------------
 #if defined key_dynspg_ts   ||   defined key_esopa
@@ -16,5 +18,4 @@
    !!   dyn_spg_ts  : compute surface pressure gradient trend using a time-
    !!                 splitting scheme and add to the general trend 
-   !!   ts_rst      : read/write the time-splitting restart fields in the ocean restart file
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers
@@ -24,16 +25,11 @@
    USE phycst          ! physical constants
    USE domvvl          ! variable volume
-   USE zdfbfr          ! bottom friction
    USE dynvor          ! vorticity term
-   USE obc_oce         ! Lateral open boundary condition
-   USE obc_par         ! open boundary condition parameters
-   USE obcdta          ! open boundary condition data     
-   USE obcfla          ! Flather open boundary condition  
    USE bdy_par         ! for lk_bdy
    USE bdy_oce         ! Lateral open boundary condition
-   USE bdydta          ! open boundary condition data     
+   USE bdytides        ! open boundary condition data     
    USE bdydyn2d        ! open boundary conditions on barotropic variables
-   USE sbctide
-   USE updtide
+   USE sbctide         ! tides
+   USE updtide         ! tide potential
    USE lib_mpp         ! distributed memory computing library
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
@@ -41,7 +37,13 @@
    USE in_out_manager  ! I/O manager
    USE iom             ! IOM library
+   USE restart         ! only for lrst_oce
    USE zdf_oce         ! Vertical diffusion
    USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   USE timing          ! Timing    
+   USE sbcapr          ! surface boundary condition: atmospheric pressure
+   USE dynadv, ONLY: ln_dynadv_vec
+#if defined key_agrif
+   USE agrif_opa_interp ! agrif
+#endif
 
 
@@ -49,14 +51,32 @@
    PRIVATE
 
-   PUBLIC dyn_spg_ts        ! routine called by step.F90
-   PUBLIC ts_rst            ! routine called by istate.F90
-   PUBLIC dyn_spg_ts_alloc  ! routine called by dynspg.F90
-
-
+   PUBLIC dyn_spg_ts        ! routine called in dynspg.F90 
+   PUBLIC dyn_spg_ts_alloc  !    "      "     "    "
+   PUBLIC dyn_spg_ts_init   !    "      "     "    "
+
+   ! Potential namelist parameters below to be read in dyn_spg_ts_init
+   LOGICAL,  PUBLIC,  PARAMETER :: ln_bt_fw=.TRUE.        !: Forward integration of barotropic sub-stepping
+   LOGICAL,  PRIVATE, PARAMETER :: ln_bt_av=.TRUE.        !: Time averaging of barotropic variables
+   LOGICAL,  PRIVATE, PARAMETER :: ln_bt_nn_auto=.FALSE.  !: Set number of iterations automatically
+   INTEGER,  PRIVATE, PARAMETER :: nn_bt_flt=1            !: Filter choice
+   REAL(wp), PRIVATE, PARAMETER :: rn_bt_cmax=0.8_wp      !: Max. courant number (used if ln_bt_nn_auto=T)
+   ! End namelist parameters
+
+   INTEGER, SAVE :: icycle  ! Number of barotropic sub-steps for each internal step nn_baro <= 2.5 nn_baro
+   REAL(wp),SAVE :: rdtbt   ! Barotropic time step
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) :: &
+                    wgtbtp1, &              ! Primary weights used for time filtering of barotropic variables
+                    wgtbtp2                 ! Secondary weights used for time filtering of barotropic variables
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  zwz          ! ff/h at F points
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ftnw, ftne   ! triad of coriolis parameter
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ftsw, ftse   ! (only used with een vorticity scheme)
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   un_b, vn_b   ! now    averaged velocity
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ub_b, vb_b   ! before averaged velocity
+   ! Arrays below are saved to allow testing of the "no time averaging" option
+   ! If this option is not retained, these could be replaced by temporary arrays
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  sshbb_e, sshb_e, & ! Instantaneous barotropic arrays
+                                                   ubb_e, ub_e,     &
+                                                   vbb_e, vb_e
 
    !! * Substitutions
@@ -64,6 +84,6 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
-   !! $Id$
+   !! NEMO/OPA 3.5 , NEMO Consortium (2013)
+   !! $Id: dynspg_ts.F90
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -74,7 +94,19 @@
       !!                  ***  routine dyn_spg_ts_alloc  ***
       !!----------------------------------------------------------------------
-      ALLOCATE( ftnw  (jpi,jpj) , ftne(jpi,jpj) , un_b(jpi,jpj) , vn_b(jpi,jpj) ,     &
-         &      ftsw  (jpi,jpj) , ftse(jpi,jpj) , ub_b(jpi,jpj) , vb_b(jpi,jpj) , STAT= dyn_spg_ts_alloc )
-         !
+      INTEGER :: ierr(3)
+      !!----------------------------------------------------------------------
+      ierr(:) = 0
+
+      ALLOCATE( sshb_e(jpi,jpj), sshbb_e(jpi,jpj), &
+         &      ub_e(jpi,jpj)  , vb_e(jpi,jpj)   , &
+         &      ubb_e(jpi,jpj) , vbb_e(jpi,jpj)  , STAT= ierr(1) )
+
+      ALLOCATE( wgtbtp1(3*nn_baro), wgtbtp2(3*nn_baro), zwz(jpi,jpj), STAT= ierr(2) )
+
+      IF( ln_dynvor_een ) ALLOCATE( ftnw(jpi,jpj) , ftne(jpi,jpj) , & 
+                             &      ftsw(jpi,jpj) , ftse(jpi,jpj) , STAT=ierr(3) )
+
+      dyn_spg_ts_alloc = MAXVAL(ierr(:))
+
       IF( lk_mpp                )   CALL mpp_sum( dyn_spg_ts_alloc )
       IF( dyn_spg_ts_alloc /= 0 )   CALL ctl_warn('dynspg_oce_alloc: failed to allocate arrays')
@@ -82,57 +114,87 @@
    END FUNCTION dyn_spg_ts_alloc
 
-
    SUBROUTINE dyn_spg_ts( kt )
       !!----------------------------------------------------------------------
-      !!                  ***  routine dyn_spg_ts  ***
       !!
-      !! ** Purpose :   Compute the now trend due to the surface pressure
-      !!      gradient in case of free surface formulation with time-splitting.
-      !!      Add it to the general trend of momentum equation.
+      !! ** Purpose :   
+      !!      -Compute the now trend due to the explicit time stepping
+      !!      of the quasi-linear barotropic system. Barotropic variables are
+      !!      advanced from internal time steps "n" to "n+1" (if ln_bt_cen=F)
+      !!      or from "n-1" to "n+1" time steps (if ln_bt_cen=T) with a
+      !!      generalized forward-backward (see ref. below) time stepping.
+      !!      -Update the free surface at step "n+1" (ssha, zsshu_a, zsshv_a).
+      !!      -Compute barotropic advective velocities at step "n" to be used 
+      !!      to advect tracers latter on. These are compliant with discrete
+      !!      continuity equation taken at the baroclinic time steps, thus 
+      !!      ensuring tracers conservation.
       !!
-      !! ** Method  :   Free surface formulation with time-splitting
-      !!      -1- Save the vertically integrated trend. This general trend is
-      !!          held constant over the barotropic integration.
-      !!          The Coriolis force is removed from the general trend as the
-      !!          surface gradient and the Coriolis force are updated within
-      !!          the barotropic integration.
-      !!      -2- Barotropic loop : updates of sea surface height (ssha_e) and 
-      !!          barotropic velocity (ua_e and va_e) through barotropic 
-      !!          momentum and continuity integration. Barotropic former 
-      !!          variables are time averaging over the full barotropic cycle
-      !!          (= 2 * baroclinic time step) and saved in uX_b 
-      !!          and vX_b (X specifying after, now or before).
-      !!      -3- The new general trend becomes :
-      !!          ua = ua - sum_k(ua)/H + ( un_b - ub_b )
+      !! ** Method  :  
       !!
-      !! ** Action : - Update (ua,va) with the surf. pressure gradient trend
+      !! ** Action : - Update barotropic velocities: ua_b, va_b
+      !!             - Update trend (ua,va) with barotropic component
+      !!             - Update ssha, zsshu_a, zsshv_a
+      !!             - Update barotropic advective velocity at kt=now
       !!
-      !! References : Griffies et al., (2003): A technical guide to MOM4. NOAA/GFDL
+      !! References : Shchepetkin, A.F. and J.C. McWilliams, 2005: 
+      !!              The regional oceanic modeling system (ROMS): 
+      !!              a split-explicit, free-surface,
+      !!              topography-following-coordinate oceanic model. 
+      !!              Ocean Modelling, 9, 347-404. 
       !!---------------------------------------------------------------------
       !
       INTEGER, INTENT(in)  ::   kt   ! ocean time-step index
       !
-      INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
-      INTEGER  ::   icycle           ! local scalar
-      INTEGER  ::   ikbu, ikbv       ! local scalar
-      REAL(wp) ::   zraur, zcoef, z2dt_e, z1_2dt_b, z2dt_bf   ! local scalars
-      REAL(wp) ::   z1_8, zx1, zy1                            !   -      -
-      REAL(wp) ::   z1_4, zx2, zy2                            !   -      -
-      REAL(wp) ::   zu_spg, zu_cor, zu_sld, zu_asp            !   -      -
-      REAL(wp) ::   zv_spg, zv_cor, zv_sld, zv_asp            !   -      -
-      REAL(wp) ::   ua_btm, va_btm                            !   -      -
-      !
-      REAL(wp), POINTER, DIMENSION(:,:) :: zsshun_e, zsshvn_e, zsshb_e, zssh_sum, zhdiv 
-      REAL(wp), POINTER, DIMENSION(:,:) :: zua, zva, zun, zvn, zun_e, zvn_e, zub_e, zvb_e 
-      REAL(wp), POINTER, DIMENSION(:,:) :: zcu, zcv, zwx, zwy, zbfru, zbfrv, zu_sum, zv_sum
+      LOGICAL  ::   ll_fw_start			! if true, forward integration 
+      LOGICAL  ::   ll_init			! if true, special startup of 2d equations
+      INTEGER  ::   ji, jj, jk, jn   		! dummy loop indices
+      INTEGER  ::   ikbu, ikbv, noffset    	! local integers
+      REAL(wp) ::   zraur, z1_2dt_b, z2dt_bf  	! local scalars
+      REAL(wp) ::   zx1, zy1, zx2, zy2         	!   -      -
+      REAL(wp) ::   z1_12, z1_8, z1_4, z1_2 	!   -      -
+      REAL(wp) ::   zu_spg, zv_spg		!   -      -
+      REAL(wp) ::   zhura, zhvra         	!   -      -
+      REAL(wp) ::   za0, za1, za2, za3		!   -      -
+      !
+      REAL(wp), POINTER, DIMENSION(:,:) :: zun_e, zvn_e, zsshp2_e
+      REAL(wp), POINTER, DIMENSION(:,:) :: zu_trd, zv_trd, zu_frc, zv_frc, zssh_frc
+      REAL(wp), POINTER, DIMENSION(:,:) :: zu_sum, zv_sum, zwx, zwy, zhdiv
+      REAL(wp), POINTER, DIMENSION(:,:) :: zhup2_e, zhvp2_e, zhust_e, zhvst_e
+      REAL(wp), POINTER, DIMENSION(:,:) :: zhur_b, zhvr_b
+      REAL(wp), POINTER, DIMENSION(:,:) :: zsshu_a, zsshv_a
+      REAL(wp), POINTER, DIMENSION(:,:) :: zht, zhf
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('dyn_spg_ts')
       !
-      CALL wrk_alloc( jpi, jpj, zsshun_e, zsshvn_e, zsshb_e, zssh_sum, zhdiv     )
-      CALL wrk_alloc( jpi, jpj, zua, zva, zun, zvn, zun_e, zvn_e, zub_e, zvb_e   )
-      CALL wrk_alloc( jpi, jpj, zcu, zcv, zwx, zwy, zbfru, zbfrv, zu_sum, zv_sum )
-      !
-      IF( kt == nit000 ) THEN             !* initialisation
+      !                                         !* Allocate temporay arrays
+      CALL wrk_alloc( jpi, jpj, zsshp2_e, zhdiv )
+      CALL wrk_alloc( jpi, jpj, zu_trd, zv_trd, zun_e, zvn_e  )
+      CALL wrk_alloc( jpi, jpj, zwx, zwy, zu_sum, zv_sum, zssh_frc, zu_frc, zv_frc)
+      CALL wrk_alloc( jpi, jpj, zhup2_e, zhvp2_e, zhust_e, zhvst_e)
+      CALL wrk_alloc( jpi, jpj, zhur_b, zhvr_b                                     )
+      CALL wrk_alloc( jpi, jpj, zsshu_a, zsshv_a                                   )
+      CALL wrk_alloc( jpi, jpj, zht, zhf )
+      !
+      !                                         !* Local constant initialization
+      z1_12 = 1._wp / 12._wp 
+      z1_8  = 0.125_wp                                   
+      z1_4  = 0.25_wp
+      z1_2  = 0.5_wp     
+      zraur = 1._wp / rau0
+      !
+      IF( kt == nit000 .AND. neuler == 0 ) THEN  	! reciprocal of baroclinic time step 
+        z2dt_bf = rdt
+      ELSE
+        z2dt_bf = 2.0_wp * rdt
+      ENDIF
+      z1_2dt_b = 1.0_wp / z2dt_bf 
+      !
+      ll_init = ln_bt_av                       		! if no time averaging, then no specific restart 
+      ll_fw_start = .FALSE.
+      !
+                                     	                ! time offset in steps for bdy data update
+      IF (.NOT.ln_bt_fw) THEN ; noffset=-2*nn_baro ; ELSE ;  noffset = 0 ; ENDIF
+      !
+      IF( kt == nit000 ) THEN             	!* initialisation
          !
          IF(lwp) WRITE(numout,*)
@@ -141,52 +203,125 @@
          IF(lwp) WRITE(numout,*) ' Number of sub cycle in 1 time-step (2 rdt) : icycle = ',  2*nn_baro
          !
-         CALL ts_rst( nit000, 'READ' )   ! read or initialize the following fields: un_b, vn_b  
-         !
-         ua_e  (:,:) = un_b (:,:)
-         va_e  (:,:) = vn_b (:,:)
-         hu_e  (:,:) = hu   (:,:)
-         hv_e  (:,:) = hv   (:,:)
-         hur_e (:,:) = hur  (:,:)
-         hvr_e (:,:) = hvr  (:,:)
-         IF( ln_dynvor_een ) THEN
-            ftne(1,:) = 0._wp   ;   ftnw(1,:) = 0._wp   ;   ftse(1,:) = 0._wp   ;   ftsw(1,:) = 0._wp
+         IF (neuler==0) ll_init=.TRUE.
+         !
+         IF (ln_bt_fw.OR.(neuler==0)) THEN
+           ll_fw_start=.TRUE.
+           noffset = 0
+         ELSE
+           ll_fw_start=.FALSE.
+         ENDIF
+         !
+         ! Set averaging weights and cycle length:
+         CALL ts_wgt(ln_bt_av, ll_fw_start, icycle, wgtbtp1, wgtbtp2)
+         !
+         IF ((neuler/=0).AND.(ln_bt_fw)) CALL ts_rst( nit000, 'READ' ) 
+         !
+      ENDIF
+      !
+      ! Set arrays to remove/compute coriolis trend.
+      ! Do it once at kt=nit000 if volume is fixed, else at each long time step.
+      ! Note that these arrays are also used during barotropic loop. These are however frozen
+      ! although they should be updated in variable volume case. Not a big approximation.
+      ! To remove this approximation, copy lines below inside barotropic loop
+      ! and update depths at T-F points (ht and hf resp.) at each barotropic time step
+      !
+      IF ( kt == nit000 .OR. lk_vvl ) THEN
+         IF ( ln_dynvor_een ) THEN
+            ! JC: Simplification needed below: define ht_0 even when volume is fixed
+            IF (lk_vvl) THEN
+               zht(:,:) = (ht_0(:,:) + sshn(:,:)) * tmask(:,:,1) 
+            ELSE
+               zht(:,:) = 0.
+               DO jk = 1, jpkm1
+                  zht(:,:) = zht(:,:) + fse3t_n(:,:,jk) * tmask(:,:,jk)
+               END DO
+            ENDIF
+
+            DO jj = 1, jpjm1
+               DO ji = 1, jpim1
+                  zwz(ji,jj) =   ( zht(ji  ,jj+1) + zht(ji+1,jj+1) +                     &
+                        &          zht(ji  ,jj  ) + zht(ji+1,jj  )   )                   &
+                        &      / ( MAX( 1.0_wp, tmask(ji  ,jj+1, 1) + tmask(ji+1,jj+1, 1) +    &
+                        &                       tmask(ji  ,jj  , 1) + tmask(ji+1,jj  , 1) ) )
+                  IF( zwz(ji,jj) /= 0._wp )   zwz(ji,jj) = 1._wp / zwz(ji,jj)
+               END DO
+            END DO
+            CALL lbc_lnk( zwz, 'F', 1._wp )
+            zwz(:,:) = ff(:,:) * zwz(:,:)
+
+            ftne(1,:) = 0._wp ; ftnw(1,:) = 0._wp ; ftse(1,:) = 0._wp ; ftsw(1,:) = 0._wp
             DO jj = 2, jpj
                DO ji = fs_2, jpi   ! vector opt.
-                  ftne(ji,jj) = ( ff(ji-1,jj  ) + ff(ji  ,jj  ) + ff(ji  ,jj-1) ) / 3._wp
-                  ftnw(ji,jj) = ( ff(ji-1,jj-1) + ff(ji-1,jj  ) + ff(ji  ,jj  ) ) / 3._wp
-                  ftse(ji,jj) = ( ff(ji  ,jj  ) + ff(ji  ,jj-1) + ff(ji-1,jj-1) ) / 3._wp
-                  ftsw(ji,jj) = ( ff(ji  ,jj-1) + ff(ji-1,jj-1) + ff(ji-1,jj  ) ) / 3._wp
-               END DO
-            END DO
-         ENDIF
-         !
-      ENDIF
-
-      !                                                     !* Local constant initialization
-      z1_2dt_b = 1._wp / ( 2.0_wp * rdt )                   ! reciprocal of baroclinic time step
-      IF( neuler == 0 .AND. kt == nit000 )   z1_2dt_b = 1.0_wp / rdt    ! reciprocal of baroclinic 
-                                                                        ! time step (euler timestep)
-      z1_8     = 0.125_wp                                   ! coefficient for vorticity estimates
-      z1_4     = 0.25_wp        
-      zraur    = 1._wp / rau0                               ! 1 / volumic mass
-      !
-      zhdiv(:,:) = 0._wp                                    ! barotropic divergence
-      zu_sld = 0._wp   ;   zu_asp = 0._wp                   ! tides trends (lk_tide=F)
-      zv_sld = 0._wp   ;   zv_asp = 0._wp
-
-      IF( kt == nit000 .AND. neuler == 0) THEN              ! for implicit bottom friction
-        z2dt_bf = rdt
-      ELSE
-        z2dt_bf = 2.0_wp * rdt
-      ENDIF
-
+                  ftne(ji,jj) = zwz(ji-1,jj  ) + zwz(ji  ,jj  ) + zwz(ji  ,jj-1)
+                  ftnw(ji,jj) = zwz(ji-1,jj-1) + zwz(ji-1,jj  ) + zwz(ji  ,jj  )
+                  ftse(ji,jj) = zwz(ji  ,jj  ) + zwz(ji  ,jj-1) + zwz(ji-1,jj-1)
+                  ftsw(ji,jj) = zwz(ji  ,jj-1) + zwz(ji-1,jj-1) + zwz(ji-1,jj  )
+               END DO
+            END DO
+         ELSE
+            zwz(:,:) = 0._wp
+            zht(:,:) = 0.
+            IF ( .not. ln_sco ) THEN
+!              IF( rn_hmin < 0._wp ) THEN    ;   jk = - INT( rn_hmin )                                      ! from a nb of level
+!              ELSE                          ;   jk = MINLOC( gdepw_0, mask = gdepw_0 > rn_hmin, dim = 1 )  ! from a depth
+!              ENDIF
+!              zht(:,:) = gdepw_0(:,:,jk+1)
+            ELSE
+               zht(:,:) = hbatf(:,:)
+            END IF
+
+            DO jj = 1, jpjm1
+               zht(:,jj) = zht(:,jj)*(1._wp- umask(:,jj,1) * umask(:,jj+1,1))
+            END DO
+
+            DO jk = 1, jpkm1
+               DO jj = 1, jpjm1
+                  zht(:,jj) = zht(:,jj) + fse3f_n(:,jj,jk) * umask(:,jj,jk) * umask(:,jj+1,jk)
+               END DO
+            END DO
+            CALL lbc_lnk( zht, 'F', 1._wp )
+            ! JC: TBC. hf should be greater than 0 
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF( zht(ji,jj) /= 0._wp )   zwz(ji,jj) = 1._wp / zht(ji,jj) ! zht is actually hf here but it saves an array
+               END DO
+            END DO
+            zwz(:,:) = ff(:,:) * zwz(:,:)
+         ENDIF
+      ENDIF
+      !
+      ! If forward start at previous time step, and centered integration, 
+      ! then update averaging weights:
+      IF ((.NOT.ln_bt_fw).AND.((neuler==0).AND.(kt==nit000+1))) THEN
+         ll_fw_start=.FALSE.
+         CALL ts_wgt(ln_bt_av, ll_fw_start, icycle, wgtbtp1, wgtbtp2)
+      ENDIF
+
+      ! before inverse water column height at u- and v- points
+      IF( lk_vvl ) THEN
+         zhur_b(:,:) = 0.
+         zhvr_b(:,:) = 0.
+         DO jk = 1, jpk
+            zhur_b(:,:) = zhur_b(:,:) + fse3u_b(:,:,jk) * umask(:,:,jk)
+            zhvr_b(:,:) = zhvr_b(:,:) + fse3v_b(:,:,jk) * vmask(:,:,jk)
+         END DO
+         zhur_b(:,:) = umask(:,:,1) / ( zhur_b(:,:) + 1. - umask(:,:,1) )
+         zhvr_b(:,:) = vmask(:,:,1) / ( zhvr_b(:,:) + 1. - vmask(:,:,1) )
+      ELSE
+         zhur_b(:,:) = hur(:,:)
+         zhvr_b(:,:) = hvr(:,:)
+      ENDIF
+                          
       ! -----------------------------------------------------------------------------
       !  Phase 1 : Coupling between general trend and barotropic estimates (1st step)
       ! -----------------------------------------------------------------------------
       !      
+      ! Some vertical sums (at now and before time steps) below could be suppressed 
+      ! if one swap barotropic arrays somewhere
+      !
       !                                   !* e3*d/dt(Ua), e3*Ub, e3*Vn (Vertically integrated)
-      !                                   ! --------------------------
-      zua(:,:) = 0._wp   ;   zun(:,:) = 0._wp   ;   ub_b(:,:) = 0._wp
-      zva(:,:) = 0._wp   ;   zvn(:,:) = 0._wp   ;   vb_b(:,:) = 0._wp
+      !                                   ! --------------------------------------------------
+      zu_frc(:,:) = 0._wp   ;   ub_b(:,:) = 0._wp  ;  un_b(:,:) = 0._wp
+      zv_frc(:,:) = 0._wp   ;   vb_b(:,:) = 0._wp  ;  vn_b(:,:) = 0._wp
       !
       DO jk = 1, jpkm1
@@ -198,36 +333,41 @@
             DO ji = 1, jpi
 #endif
-               !                                                                              ! now trend
-               zua(ji,jj) = zua(ji,jj) + fse3u  (ji,jj,jk) * ua(ji,jj,jk) * umask(ji,jj,jk)
-               zva(ji,jj) = zva(ji,jj) + fse3v  (ji,jj,jk) * va(ji,jj,jk) * vmask(ji,jj,jk)
-               !                                                                              ! now velocity 
-               zun(ji,jj) = zun(ji,jj) + fse3u  (ji,jj,jk) * un(ji,jj,jk)
-               zvn(ji,jj) = zvn(ji,jj) + fse3v  (ji,jj,jk) * vn(ji,jj,jk)               
-               !
-#if defined key_vvl
-               ub_b(ji,jj) = ub_b(ji,jj) + fse3u_b(ji,jj,jk)* ub(ji,jj,jk)   *umask(ji,jj,jk) 
-               vb_b(ji,jj) = vb_b(ji,jj) + fse3v_b(ji,jj,jk)* vb(ji,jj,jk)   *vmask(ji,jj,jk)
-#else
-               ub_b(ji,jj) = ub_b(ji,jj) + fse3u_0(ji,jj,jk) * ub(ji,jj,jk)  * umask(ji,jj,jk)
-               vb_b(ji,jj) = vb_b(ji,jj) + fse3v_0(ji,jj,jk) * vb(ji,jj,jk)  * vmask(ji,jj,jk)
-#endif
+               !        ! now trend:                                                                   
+               zu_frc(ji,jj) = zu_frc(ji,jj) + fse3u(ji,jj,jk) * ua(ji,jj,jk) * umask(ji,jj,jk)
+               zv_frc(ji,jj) = zv_frc(ji,jj) + fse3v(ji,jj,jk) * va(ji,jj,jk) * vmask(ji,jj,jk)         
+               !        ! now bt transp:                   
+               un_b(ji,jj) = un_b(ji,jj) + fse3u(ji,jj,jk) * un(ji,jj,jk) * umask(ji,jj,jk)        
+               vn_b(ji,jj) = vn_b(ji,jj) + fse3v(ji,jj,jk) * vn(ji,jj,jk) * vmask(ji,jj,jk)
+               !	! before bt transp:
+               ub_b(ji,jj) = ub_b(ji,jj) + fse3u_b(ji,jj,jk) * ub(ji,jj,jk)  * umask(ji,jj,jk)
+               vb_b(ji,jj) = vb_b(ji,jj) + fse3v_b(ji,jj,jk) * vb(ji,jj,jk)  * vmask(ji,jj,jk)
             END DO
          END DO
       END DO
-
+      !
+      zu_frc(:,:) = zu_frc(:,:) * hur(:,:)
+      zv_frc(:,:) = zv_frc(:,:) * hvr(:,:)
+      !
+      IF( lk_vvl ) THEN
+          ub_b(:,:) = ub_b(:,:) * zhur_b(:,:)
+          vb_b(:,:) = vb_b(:,:) * zhvr_b(:,:)
+      ELSE
+          ub_b(:,:) = ub_b(:,:) * hur(:,:)
+          vb_b(:,:) = vb_b(:,:) * hvr(:,:)
+      ENDIF
+      !
       !                                   !* baroclinic momentum trend (remove the vertical mean trend)
-      DO jk = 1, jpkm1                    ! --------------------------
+      DO jk = 1, jpkm1                    ! -----------------------------------------------------------
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               ua(ji,jj,jk) = ua(ji,jj,jk) - zua(ji,jj) * hur(ji,jj)
-               va(ji,jj,jk) = va(ji,jj,jk) - zva(ji,jj) * hvr(ji,jj)
+               ua(ji,jj,jk) = ua(ji,jj,jk) - zu_frc(ji,jj) * umask(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) - zv_frc(ji,jj) * vmask(ji,jj,jk)
             END DO
          END DO
       END DO
-
-      !                                   !* barotropic Coriolis trends * H (vorticity scheme dependent)
-      !                                   ! ---------------------------====
-      zwx(:,:) = zun(:,:) * e2u(:,:)                   ! now transport 
-      zwy(:,:) = zvn(:,:) * e1v(:,:)
+      !                                   !* barotropic Coriolis trends (vorticity scheme dependent)
+      !                                   ! --------------------------------------------------------
+      zwx(:,:) = un_b(:,:) * e2u(:,:)           ! now transport 
+      zwy(:,:) = vn_b(:,:) * e1v(:,:)
       !
       IF( ln_dynvor_ene .OR. ln_dynvor_mix ) THEN      ! energy conserving or mixed scheme
@@ -239,250 +379,319 @@
                zx2 = ( zwx(ji  ,jj) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
                ! energy conserving formulation for planetary vorticity term
-               zcu(ji,jj) = z1_4 * ( ff(ji  ,jj-1) * zy1 + ff(ji,jj) * zy2 )
-               zcv(ji,jj) =-z1_4 * ( ff(ji-1,jj  ) * zx1 + ff(ji,jj) * zx2 )
-            END DO
-         END DO
-         !
-      ELSEIF ( ln_dynvor_ens ) THEN                    ! enstrophy conserving scheme
+               zu_trd(ji,jj) = z1_4 * ( zwz(ji  ,jj-1) * zy1 + zwz(ji,jj) * zy2 )
+               zv_trd(ji,jj) =-z1_4 * ( zwz(ji-1,jj  ) * zx1 + zwz(ji,jj) * zx2 )
+            END DO
+         END DO
+         !
+      ELSEIF ( ln_dynvor_ens ) THEN             ! enstrophy conserving scheme
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zy1 =   z1_8 * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1) + zwy(ji,jj) + zwy(ji+1,jj  ) ) / e1u(ji,jj)
-               zx1 = - z1_8 * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) + zwx(ji,jj) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
-               zcu(ji,jj)  = zy1 * ( ff(ji  ,jj-1) + ff(ji,jj) )
-               zcv(ji,jj)  = zx1 * ( ff(ji-1,jj  ) + ff(ji,jj) )
-            END DO
-         END DO
-         !
-      ELSEIF ( ln_dynvor_een ) THEN                    ! enstrophy and energy conserving scheme
+               zy1 =   z1_8 * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1) &
+                 &            + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) ) / e1u(ji,jj)
+               zx1 = - z1_8 * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) &
+                 &            + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
+               zu_trd(ji,jj)  = zy1 * ( zwz(ji  ,jj-1) + zwz(ji,jj) )
+               zv_trd(ji,jj)  = zx1 * ( zwz(ji-1,jj  ) + zwz(ji,jj) )
+            END DO
+         END DO
+         !
+      ELSEIF ( ln_dynvor_een ) THEN             ! enstrophy and energy conserving scheme
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zcu(ji,jj) = + z1_4 / e1u(ji,jj) * (  ftne(ji,jj  ) * zwy(ji  ,jj  ) + ftnw(ji+1,jj) * zwy(ji+1,jj  )   &
-                  &                                + ftse(ji,jj  ) * zwy(ji  ,jj-1) + ftsw(ji+1,jj) * zwy(ji+1,jj-1) )
-               zcv(ji,jj) = - z1_4 / e2v(ji,jj) * (  ftsw(ji,jj+1) * zwx(ji-1,jj+1) + ftse(ji,jj+1) * zwx(ji  ,jj+1)   &
-                  &                                + ftnw(ji,jj  ) * zwx(ji-1,jj  ) + ftne(ji,jj  ) * zwx(ji  ,jj  ) )
-            END DO
-         END DO
-         !
-      ENDIF
-
+               zu_trd(ji,jj) = + z1_12 / e1u(ji,jj) * (  ftne(ji,jj  ) * zwy(ji  ,jj  ) &
+                &                                      + ftnw(ji+1,jj) * zwy(ji+1,jj  ) &
+                &                                      + ftse(ji,jj  ) * zwy(ji  ,jj-1) &
+                &                                      + ftsw(ji+1,jj) * zwy(ji+1,jj-1) )
+               zv_trd(ji,jj) = - z1_12 / e2v(ji,jj) * (  ftsw(ji,jj+1) * zwx(ji-1,jj+1) &
+                &                                      + ftse(ji,jj+1) * zwx(ji  ,jj+1) &
+                &                                      + ftnw(ji,jj  ) * zwx(ji-1,jj  ) &
+                &                                      + ftne(ji,jj  ) * zwx(ji  ,jj  ) )
+            END DO
+         END DO
+         !
+      ENDIF 
+      !
+      un_b (:,:) = un_b(:,:) * hur(:,:)         ! Revert now transport to barotropic velocities
+      vn_b (:,:) = vn_b(:,:) * hvr(:,:)  
       !                                   !* Right-Hand-Side of the barotropic momentum equation
       !                                   ! ----------------------------------------------------
-      IF( lk_vvl ) THEN                         ! Variable volume : remove both Coriolis and Surface pressure gradient
+      IF( lk_vvl ) THEN                         ! Variable volume : remove surface pressure gradient
          DO jj = 2, jpjm1 
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zcu(ji,jj) = zcu(ji,jj) - grav * (  ( rhd(ji+1,jj  ,1) + 1 ) * sshn(ji+1,jj  )    &
-                  &                              - ( rhd(ji  ,jj  ,1) + 1 ) * sshn(ji  ,jj  )  ) * hu(ji,jj) / e1u(ji,jj)
-               zcv(ji,jj) = zcv(ji,jj) - grav * (  ( rhd(ji  ,jj+1,1) + 1 ) * sshn(ji  ,jj+1)    &
-                  &                              - ( rhd(ji  ,jj  ,1) + 1 ) * sshn(ji  ,jj  )  ) * hv(ji,jj) / e2v(ji,jj)
-            END DO
-         END DO
-      ENDIF
-
-      DO jj = 2, jpjm1                             ! Remove coriolis term (and possibly spg) from barotropic trend
+               zu_trd(ji,jj) = zu_trd(ji,jj) - grav * (  sshn(ji+1,jj  ) - sshn(ji  ,jj  )  ) / e1u(ji,jj)
+               zv_trd(ji,jj) = zv_trd(ji,jj) - grav * (  sshn(ji  ,jj+1) - sshn(ji  ,jj  )  ) / e2v(ji,jj)
+            END DO
+         END DO
+      ENDIF
+
+      DO jj = 2, jpjm1                          ! Remove coriolis term (and possibly spg) from barotropic trend
          DO ji = fs_2, fs_jpim1
-             zua(ji,jj) = zua(ji,jj) - zcu(ji,jj)
-             zva(ji,jj) = zva(ji,jj) - zcv(ji,jj)
+             zu_frc(ji,jj) = zu_frc(ji,jj) - zu_trd(ji,jj) * umask(ji,jj,1)
+             zv_frc(ji,jj) = zv_frc(ji,jj) - zv_trd(ji,jj) * vmask(ji,jj,1)
           END DO
-      END DO
-
-                    
-      !                                             ! Remove barotropic contribution of bottom friction 
-      !                                             ! from the barotropic transport trend
-      zcoef = -1._wp * z1_2dt_b
-
-      IF(ln_bfrimp) THEN
-      !                                   ! Remove the bottom stress trend from 3-D sea surface level gradient
-      !                                   ! and Coriolis forcing in case of 3D semi-implicit bottom friction 
-        DO jj = 2, jpjm1         
-           DO ji = fs_2, fs_jpim1
-              ikbu = mbku(ji,jj)
-              ikbv = mbkv(ji,jj)
-              ua_btm = zcu(ji,jj) * z2dt_bf * hur(ji,jj) * umask (ji,jj,ikbu)
-              va_btm = zcv(ji,jj) * z2dt_bf * hvr(ji,jj) * vmask (ji,jj,ikbv)
-
-              zua(ji,jj) = zua(ji,jj) - bfrua(ji,jj) * ua_btm
-              zva(ji,jj) = zva(ji,jj) - bfrva(ji,jj) * va_btm
-           END DO
-        END DO
-
-      ELSE
-
-# if defined key_vectopt_loop
-        DO jj = 1, 1
-           DO ji = 1, jpij-jpi   ! vector opt. (forced unrolling)
-# else
-        DO jj = 2, jpjm1
-           DO ji = 2, jpim1
-# endif
-            ! Apply stability criteria for bottom friction
-            !RBbug for vvl and external mode we may need to use varying fse3
-            !!gm  Rq: the bottom e3 present the smallest variation, the use of e3u_0 is not a big approx.
-              zbfru(ji,jj) = MAX(  bfrua(ji,jj) , fse3u(ji,jj,mbku(ji,jj)) * zcoef  )
-              zbfrv(ji,jj) = MAX(  bfrva(ji,jj) , fse3v(ji,jj,mbkv(ji,jj)) * zcoef  )
-           END DO
-        END DO
-
-        IF( lk_vvl ) THEN
-           DO jj = 2, jpjm1
-              DO ji = fs_2, fs_jpim1   ! vector opt.
-                 zua(ji,jj) = zua(ji,jj) - zbfru(ji,jj) * ub_b(ji,jj)   &
-                    &       / ( hu_0(ji,jj) + sshu_b(ji,jj) + 1._wp - umask(ji,jj,1) )
-                 zva(ji,jj) = zva(ji,jj) - zbfrv(ji,jj) * vb_b(ji,jj)   &
-                    &       / ( hv_0(ji,jj) + sshv_b(ji,jj) + 1._wp - vmask(ji,jj,1) )
-              END DO
-           END DO
-        ELSE
-           DO jj = 2, jpjm1
-              DO ji = fs_2, fs_jpim1   ! vector opt.
-                 zua(ji,jj) = zua(ji,jj) - zbfru(ji,jj) * ub_b(ji,jj) * hur(ji,jj)
-                 zva(ji,jj) = zva(ji,jj) - zbfrv(ji,jj) * vb_b(ji,jj) * hvr(ji,jj)
-              END DO
-           END DO
-        ENDIF
-      END IF    ! end (ln_bfrimp)
-
-                    
-      !                                   !* d/dt(Ua), Ub, Vn (Vertical mean velocity)
-      !                                   ! -------------------------- 
-      zua(:,:) = zua(:,:) * hur(:,:)
-      zva(:,:) = zva(:,:) * hvr(:,:)
-      !
-      IF( lk_vvl ) THEN
-         ub_b(:,:) = ub_b(:,:) * umask(:,:,1) / ( hu_0(:,:) + sshu_b(:,:) + 1._wp - umask(:,:,1) )
-         vb_b(:,:) = vb_b(:,:) * vmask(:,:,1) / ( hv_0(:,:) + sshv_b(:,:) + 1._wp - vmask(:,:,1) )
-      ELSE
-         ub_b(:,:) = ub_b(:,:) * hur(:,:)
-         vb_b(:,:) = vb_b(:,:) * hvr(:,:)
-      ENDIF
-
+      END DO 
+      !
+      !						! Add bottom stress contribution from baroclinic velocities:      
+      IF (ln_bt_fw) THEN
+         DO jj = 2, jpjm1                          
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ikbu = mbku(ji,jj)       
+               ikbv = mbkv(ji,jj)    
+               zwx(ji,jj) = un(ji,jj,ikbu) - un_b(ji,jj) ! NOW bottom baroclinic velocities
+               zwy(ji,jj) = vn(ji,jj,ikbv) - vn_b(ji,jj)
+            END DO
+         END DO
+      ELSE
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ikbu = mbku(ji,jj)       
+               ikbv = mbkv(ji,jj)    
+               zwx(ji,jj) = ub(ji,jj,ikbu) - ub_b(ji,jj) ! BEFORE bottom baroclinic velocities
+               zwy(ji,jj) = vb(ji,jj,ikbv) - vb_b(ji,jj)
+            END DO
+         END DO
+      ENDIF
+      !
+      ! Note that the "unclipped" bottom friction parameter is used even with explicit drag
+      zu_frc(:,:) = zu_frc(:,:) + hur(:,:) * bfrua(:,:) * zwx(:,:)
+      zv_frc(:,:) = zv_frc(:,:) + hvr(:,:) * bfrva(:,:) * zwy(:,:)
+      !       
+      IF (ln_bt_fw) THEN                        ! Add wind forcing
+         zu_frc(:,:) =  zu_frc(:,:) + zraur * utau(:,:) * hur(:,:)
+         zv_frc(:,:) =  zv_frc(:,:) + zraur * vtau(:,:) * hvr(:,:)
+      ELSE
+         zu_frc(:,:) =  zu_frc(:,:) + zraur * z1_2 * ( utau_b(:,:) + utau(:,:) ) * hur(:,:)
+         zv_frc(:,:) =  zv_frc(:,:) + zraur * z1_2 * ( vtau_b(:,:) + vtau(:,:) ) * hvr(:,:)
+      ENDIF  
+      !
+      IF ( ln_apr_dyn ) THEN                    ! Add atm pressure forcing
+         IF (ln_bt_fw) THEN
+            DO jj = 2, jpjm1              
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zu_spg =  grav * (  ssh_ib (ji+1,jj  ) - ssh_ib (ji,jj) ) /e1u(ji,jj)
+                  zv_spg =  grav * (  ssh_ib (ji  ,jj+1) - ssh_ib (ji,jj) ) /e2v(ji,jj)
+                  zu_frc(ji,jj) = zu_frc(ji,jj) + zu_spg
+                  zv_frc(ji,jj) = zv_frc(ji,jj) + zv_spg
+               END DO
+            END DO
+         ELSE
+            DO jj = 2, jpjm1              
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zu_spg =  grav * z1_2 * (  ssh_ib (ji+1,jj  ) - ssh_ib (ji,jj)    &
+                      &                    + ssh_ibb(ji+1,jj  ) - ssh_ibb(ji,jj)  ) /e1u(ji,jj)
+                  zv_spg =  grav * z1_2 * (  ssh_ib (ji  ,jj+1) - ssh_ib (ji,jj)    &
+                      &                    + ssh_ibb(ji  ,jj+1) - ssh_ibb(ji,jj)  ) /e2v(ji,jj)
+                  zu_frc(ji,jj) = zu_frc(ji,jj) + zu_spg
+                  zv_frc(ji,jj) = zv_frc(ji,jj) + zv_spg
+               END DO
+            END DO
+         ENDIF 
+      ENDIF
+      !                                   !* Right-Hand-Side of the barotropic ssh equation
+      !                                   ! -----------------------------------------------
+      !                                         ! Surface net water flux and rivers
+      IF (ln_bt_fw) THEN
+         zssh_frc(:,:) = zraur * ( emp(:,:) - rnf(:,:) )
+      ELSE
+         zssh_frc(:,:) = zraur * z1_2 * (emp(:,:) + emp_b(:,:) - rnf(:,:) - rnf_b(:,:))
+      ENDIF
+#if defined key_asminc
+      !                                         ! Include the IAU weighted SSH increment
+      IF( lk_asminc .AND. ln_sshinc .AND. ln_asmiau ) THEN
+         zssh_frc(:,:) = zssh_frc(:,:) + ssh_iau(:,:)
+      ENDIF
+#endif
+      !
       ! -----------------------------------------------------------------------
-      !  Phase 2 : Integration of the barotropic equations with time splitting
+      !  Phase 2 : Integration of the barotropic equations 
       ! -----------------------------------------------------------------------
       !
       !                                             ! ==================== !
       !                                             !    Initialisations   !
+      !                                             ! ==================== !  
+      ! Initialize barotropic variables:    
+      IF (ln_bt_fw) THEN                  ! FORWARD integration:  start from NOW fields                             
+         sshn_e (:,:) = sshn (:,:)            
+         zun_e  (:,:) = un_b (:,:)            
+         zvn_e  (:,:) = vn_b (:,:)
+      ELSE                                ! CENTERED integration: start from BEFORE fields
+         sshn_e (:,:) = sshb (:,:)
+         zun_e  (:,:) = ub_b (:,:)         
+         zvn_e  (:,:) = vb_b (:,:)
+      ENDIF
+      !
+      ! Initialize depths:
+      IF ( lk_vvl.AND.(.NOT.ln_bt_fw) ) THEN
+         hu_e  (:,:) = umask(:,:,1) / ( zhur_b(:,:) + 1._wp - umask(:,:,1) )
+         hv_e  (:,:) = vmask(:,:,1) / ( zhvr_b(:,:) + 1._wp - vmask(:,:,1) )
+         hur_e (:,:) = zhur_b(:,:)
+         hvr_e (:,:) = zhvr_b(:,:)
+      ELSE
+         hu_e  (:,:) = hu   (:,:)       
+         hv_e  (:,:) = hv   (:,:) 
+         hur_e (:,:) = hur  (:,:)    
+         hvr_e (:,:) = hvr  (:,:)
+      ENDIF
+      !
+      IF (.NOT.lk_vvl) THEN ! Depths at jn+0.5:
+         zhup2_e (:,:) = hu(:,:)
+         zhvp2_e (:,:) = hv(:,:)
+      ENDIF
+      !
+      ! Initialize sums:
+      ua_b  (:,:) = 0._wp       ! After barotropic velocities (or transport if flux form)          
+      va_b  (:,:) = 0._wp
+      ssha  (:,:) = 0._wp       ! Sum for after averaged sea level
+      zu_sum(:,:) = 0._wp       ! Sum for now transport issued from ts loop
+      zv_sum(:,:) = 0._wp
       !                                             ! ==================== !
-      icycle = 2  * nn_baro            ! Number of barotropic sub time-step
-      
-      !                                ! Start from NOW field
-      hu_e   (:,:) = hu   (:,:)            ! ocean depth at u- and v-points
-      hv_e   (:,:) = hv   (:,:) 
-      hur_e  (:,:) = hur  (:,:)            ! ocean depth inverted at u- and v-points
-      hvr_e  (:,:) = hvr  (:,:)
-!RBbug     zsshb_e(:,:) = sshn (:,:)  
-      zsshb_e(:,:) = sshn_b(:,:)           ! sea surface height (before and now)
-      sshn_e (:,:) = sshn (:,:)
-      
-      zun_e  (:,:) = un_b (:,:)            ! barotropic velocity (external)
-      zvn_e  (:,:) = vn_b (:,:)
-      zub_e  (:,:) = un_b (:,:)
-      zvb_e  (:,:) = vn_b (:,:)
-
-      zu_sum  (:,:) = un_b (:,:)           ! summation
-      zv_sum  (:,:) = vn_b (:,:)
-      zssh_sum(:,:) = sshn (:,:)
-
-#if defined key_obc
-      ! set ssh corrections to 0
-      ! ssh corrections are applied to normal velocities (Flather's algorithm) and averaged over the barotropic loop
-      IF( lp_obc_east  )   sshfoe_b(:,:) = 0._wp
-      IF( lp_obc_west  )   sshfow_b(:,:) = 0._wp
-      IF( lp_obc_south )   sshfos_b(:,:) = 0._wp
-      IF( lp_obc_north )   sshfon_b(:,:) = 0._wp
-#endif
-
-      !                                             ! ==================== !
-      DO jn = 1, icycle                             !  sub-time-step loop  ! (from NOW to AFTER+1)
+      DO jn = 1, icycle                             !  sub-time-step loop  !
          !                                          ! ==================== !
-         z2dt_e = 2. * ( rdt / nn_baro )
-         IF( jn == 1 )   z2dt_e = rdt / nn_baro
-
          !                                                !* Update the forcing (BDY and tides)
          !                                                !  ------------------
-         IF( lk_obc )   CALL obc_dta_bt ( kt, jn   )
-         IF( lk_bdy )   CALL bdy_dta ( kt, jit=jn, time_offset=+1 )
-         IF ( ln_tide_pot .AND. lk_tide) CALL upd_tide( kt, jn )
-
-         !                                                !* after ssh_e
+         ! Update only tidal forcing at open boundaries
+#if defined key_tide
+         IF ( lk_bdy .AND. lk_tide )      CALL bdy_dta_tides( kt, kit=jn, time_offset=(noffset+1) )
+         IF ( ln_tide_pot .AND. lk_tide ) CALL upd_tide( kt, kit=jn, koffset=noffset )
+#endif
+         !
+         ! Set extrapolation coefficients for predictor step:
+         IF ((jn<3).AND.ll_init) THEN      ! Forward           
+           za1 = 1._wp                                          
+           za2 = 0._wp                        
+           za3 = 0._wp                        
+         ELSE                              ! AB3-AM4 Coefficients: bet=0.281105 
+           za1 =  1.781105_wp              ! za1 =   3/2 +   bet
+           za2 = -1.06221_wp               ! za2 = -(1/2 + 2*bet)
+           za3 =  0.281105_wp              ! za3 = bet
+         ENDIF
+
+         ! Extrapolate barotropic velocities at step jit+0.5:
+         ua_e(:,:) = za1 * zun_e(:,:) + za2 * ub_e(:,:) + za3 * ubb_e(:,:)
+         va_e(:,:) = za1 * zvn_e(:,:) + za2 * vb_e(:,:) + za3 * vbb_e(:,:)
+
+         IF( lk_vvl ) THEN                                !* Update ocean depth (variable volume case only)
+            !                                             !  ------------------
+            ! Extrapolate Sea Level at step jit+0.5:
+            zsshp2_e(:,:) = za1 * sshn_e(:,:)  + za2 * sshb_e(:,:) + za3 * sshbb_e(:,:)
+            !
+            DO jj = 2, jpjm1                                    ! Sea Surface Height at u- & v-points
+               DO ji = 2, fs_jpim1   ! Vector opt.
+                  zwx(ji,jj) = z1_2 * umask(ji,jj,1) / ( e1u(ji,jj) * e2u(ji,jj) )       &
+                     &              * ( e1t(ji  ,jj) * e2t(ji  ,jj) * zsshp2_e(ji  ,jj)  &
+                     &              +   e1t(ji+1,jj) * e2t(ji+1,jj) * zsshp2_e(ji+1,jj) )
+                  zwy(ji,jj) = z1_2 * vmask(ji,jj,1) / ( e1v(ji,jj) * e2v(ji,jj) )       &
+                     &              * ( e1t(ji,jj  ) * e2t(ji,jj  ) * zsshp2_e(ji,jj  )  &
+                     &              +   e1t(ji,jj+1) * e2t(ji,jj+1) * zsshp2_e(ji,jj+1) )
+               END DO
+            END DO
+            CALL lbc_lnk( zwx, 'U', 1._wp )    ;   CALL lbc_lnk( zwy, 'V', 1._wp )
+            !
+            zhup2_e (:,:) = hu_0(:,:) + zwx(:,:)               ! Ocean depth at U- and V-points
+            zhvp2_e (:,:) = hv_0(:,:) + zwy(:,:)
+         ENDIF
+         !                                                !* after ssh
          !                                                !  -----------
-         DO jj = 2, jpjm1                                 ! Horizontal divergence of barotropic transports
+         ! One should enforce volume conservation at open boundaries here
+         ! considering fluxes below:
+         !
+         zwx(:,:) = e2u(:,:) * ua_e(:,:) * zhup2_e(:,:)         ! fluxes at jn+0.5
+         zwy(:,:) = e1v(:,:) * va_e(:,:) * zhvp2_e(:,:)
+         DO jj = 2, jpjm1                                 
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zhdiv(ji,jj) = (   e2u(ji  ,jj) * zun_e(ji  ,jj) * hu_e(ji  ,jj)     &
-                  &             - e2u(ji-1,jj) * zun_e(ji-1,jj) * hu_e(ji-1,jj)     &
-                  &             + e1v(ji,jj  ) * zvn_e(ji,jj  ) * hv_e(ji,jj  )     &
-                  &             - e1v(ji,jj-1) * zvn_e(ji,jj-1) * hv_e(ji,jj-1)   ) / ( e1t(ji,jj) * e2t(ji,jj) )
-            END DO
-         END DO
-         !
-#if defined key_obc
-         !                                                     ! OBC : zhdiv must be zero behind the open boundary
-!!  mpp remark: The zeroing of hdiv can probably be extended to 1->jpi/jpj for the correct row/column
-         IF( lp_obc_east  )   zhdiv(nie0p1:nie1p1,nje0  :nje1  ) = 0._wp      ! east
-         IF( lp_obc_west  )   zhdiv(niw0  :niw1  ,njw0  :njw1  ) = 0._wp      ! west
-         IF( lp_obc_north )   zhdiv(nin0  :nin1  ,njn0p1:njn1p1) = 0._wp      ! north
-         IF( lp_obc_south )   zhdiv(nis0  :nis1  ,njs0  :njs1  ) = 0._wp      ! south
+               zhdiv(ji,jj) = (   zwx(ji,jj) - zwx(ji-1,jj)   &
+                  &             + zwy(ji,jj) - zwy(ji,jj-1)   &
+                  &           ) / ( e1t(ji,jj) * e2t(ji,jj) )
+            END DO
+         END DO
+         !
+         ! Sum over sub-time-steps to compute advective velocities
+         za2 = wgtbtp2(jn)
+         zu_sum  (:,:) = zu_sum  (:,:) + za2 * ua_e  (:,:) * zhup2_e  (:,:)
+         zv_sum  (:,:) = zv_sum  (:,:) + za2 * va_e  (:,:) * zhvp2_e  (:,:)
+         !
+         ! Set next sea level:
+         ssha_e(:,:) = (  sshn_e(:,:) - rdtbt * ( zssh_frc(:,:) + zhdiv(:,:) )  ) * tmask(:,:,1)
+         CALL lbc_lnk( ssha_e, 'T',  1._wp )
+
+#if defined key_bdy
+         ! Duplicate sea level across open boundaries (this is only cosmetic if lk_vvl=.false.)
+         IF (lk_bdy) CALL bdy_ssh( ssha_e )
 #endif
-#if defined key_bdy
-         zhdiv(:,:) = zhdiv(:,:) * bdytmask(:,:)               ! BDY mask
+#if defined key_agrif
+         IF( .NOT.Agrif_Root() ) CALL agrif_ssh_ts( jn )
 #endif
-         !
-         DO jj = 2, jpjm1                                      ! leap-frog on ssh_e
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ssha_e(ji,jj) = ( zsshb_e(ji,jj) - z2dt_e * ( zraur * ( emp(ji,jj)-rnf(ji,jj) ) + zhdiv(ji,jj) ) ) * tmask(ji,jj,1) 
-            END DO
-         END DO
-
-         !                                                !* after barotropic velocities (vorticity scheme dependent)
-         !                                                !  ---------------------------  
-         zwx(:,:) = e2u(:,:) * zun_e(:,:) * hu_e(:,:)     ! now_e transport
-         zwy(:,:) = e1v(:,:) * zvn_e(:,:) * hv_e(:,:)
+         !  
+         ! Sea Surface Height at u-,v-points (vvl case only)
+         IF ( lk_vvl ) THEN                                
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1      ! NO Vector Opt.
+                  zsshu_a(ji,jj) = z1_2  * umask(ji,jj,1) / ( e1u(ji  ,jj) * e2u(ji  ,jj) )                 &
+                     &                                   * ( e1t(ji  ,jj) * e2t(ji  ,jj) * ssha_e(ji  ,jj) &
+                     &                                     + e1t(ji+1,jj) * e2t(ji+1,jj) * ssha_e(ji+1,jj) )
+                  zsshv_a(ji,jj) = z1_2  * vmask(ji,jj,1) / ( e1v(ji,jj  ) * e2v(ji,jj  ) )                 &
+                     &                                   * ( e1t(ji,jj  ) * e2t(ji,jj  ) * ssha_e(ji,jj  ) &
+                     &                                     + e1t(ji,jj+1) * e2t(ji,jj+1) * ssha_e(ji,jj+1) )
+               END DO
+            END DO
+            CALL lbc_lnk( zsshu_a, 'U', 1._wp )   ;   CALL lbc_lnk( zsshv_a, 'V', 1._wp )
+         ENDIF   
+         !                                 
+         ! Half-step back interpolation of SSH for surface pressure computation:
+         !----------------------------------------------------------------------
+         IF ((jn==1).AND.ll_init) THEN
+           za0=1._wp                        ! Forward-backward
+           za1=0._wp                           
+           za2=0._wp
+           za3=0._wp
+         ELSEIF ((jn==2).AND.ll_init) THEN  ! AB2-AM3 Coefficients; bet=0 ; gam=-1/6 ; eps=1/12
+           za0= 1.0833333333333_wp          ! za0 = 1-gam-eps
+           za1=-0.1666666666666_wp          ! za1 = gam
+           za2= 0.0833333333333_wp          ! za2 = eps
+           za3= 0._wp              
+         ELSE                               ! AB3-AM4 Coefficients; bet=0.281105 ; eps=0.013 ; gam=0.0880 
+           za0=0.614_wp                     ! za0 = 1/2 +   gam + 2*eps    
+           za1=0.285_wp                     ! za1 = 1/2 - 2*gam - 3*eps 
+           za2=0.088_wp                     ! za2 = gam
+           za3=0.013_wp                     ! za3 = eps
+         ENDIF
+
+         zsshp2_e(:,:) = za0 *  ssha_e(:,:) + za1 *  sshn_e (:,:) &
+          &            + za2 *  sshb_e(:,:) + za3 *  sshbb_e(:,:)
+
+         !
+         ! Compute associated depths at U and V points:
+         IF ( lk_vvl.AND.(.NOT.ln_dynadv_vec) ) THEN      
+            !                                        
+            DO jj = 2, jpjm1                            
+               DO ji = 2, jpim1
+                  zx1 = z1_2 * umask(ji,jj,1) / ( e1u(ji,jj) * e2u(ji,jj) )       &
+                    &        * ( e1t(ji  ,jj) * e2t(ji  ,jj) * zsshp2_e(ji  ,jj)  &
+                    &        +   e1t(ji+1,jj) * e2t(ji+1,jj) * zsshp2_e(ji+1,jj) )                 
+                  zy1 = z1_2 * vmask(ji,jj,1) / ( e1v(ji,jj) * e2v(ji,jj) )       &
+                     &       * ( e1t(ji,jj  ) * e2t(ji,jj  ) * zsshp2_e(ji,jj  )  &
+                     &       +   e1t(ji,jj+1) * e2t(ji,jj+1) * zsshp2_e(ji,jj+1) )
+                  zhust_e(ji,jj) = hu_0(ji,jj) + zx1 
+                  zhvst_e(ji,jj) = hv_0(ji,jj) + zy1
+               END DO
+            END DO
+         ENDIF
+         !
+         ! Add Coriolis trend:
+         ! zwz array below or triads normally depend on sea level with key_vvl and should be updated
+         ! at each time step. We however keep them constant here for optimization.
+         ! Recall that zwx and zwy arrays hold fluxes at this stage:
+         ! zwx(:,:) = e2u(:,:) * ua_e(:,:) * zhup2_e(:,:)   ! fluxes at jn+0.5
+         ! zwy(:,:) = e1v(:,:) * va_e(:,:) * zhvp2_e(:,:)
          !
          IF( ln_dynvor_ene .OR. ln_dynvor_mix ) THEN      !==  energy conserving or mixed scheme  ==!
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  ! surface pressure gradient
-                  IF( lk_vvl) THEN
-                     zu_spg = -grav * (  ( rhd(ji+1,jj ,1) + 1 ) * sshn_e(ji+1,jj  )    &
-                        &              - ( rhd(ji  ,jj ,1) + 1 ) * sshn_e(ji  ,jj  )  ) / e1u(ji,jj)
-                     zv_spg = -grav * (  ( rhd(ji ,jj+1,1) + 1 ) * sshn_e(ji  ,jj+1)    &
-                        &              - ( rhd(ji ,jj  ,1) + 1 ) * sshn_e(ji  ,jj  )  ) / e2v(ji,jj)
-                  ELSE
-                     zu_spg = -grav * ( sshn_e(ji+1,jj) - sshn_e(ji,jj) ) / e1u(ji,jj)
-                     zv_spg = -grav * ( sshn_e(ji,jj+1) - sshn_e(ji,jj) ) / e2v(ji,jj)
-                  ENDIF
-                  ! add tidal astronomical forcing
-                  IF ( ln_tide_pot .AND. lk_tide ) THEN 
-                  zu_spg = zu_spg + grav * ( pot_astro(ji+1,jj) - pot_astro(ji,jj) ) / e1u(ji,jj)
-                  zv_spg = zv_spg + grav * ( pot_astro(ji,jj+1) - pot_astro(ji,jj) ) / e2v(ji,jj)
-                  ENDIF
-                  ! energy conserving formulation for planetary vorticity term
                   zy1 = ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1) ) / e1u(ji,jj)
                   zy2 = ( zwy(ji  ,jj  ) + zwy(ji+1,jj  ) ) / e1u(ji,jj)
                   zx1 = ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) ) / e2v(ji,jj)
                   zx2 = ( zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
-                  zu_cor = z1_4 * ( ff(ji  ,jj-1) * zy1 + ff(ji,jj) * zy2 ) * hur_e(ji,jj)
-                  zv_cor =-z1_4 * ( ff(ji-1,jj  ) * zx1 + ff(ji,jj) * zx2 ) * hvr_e(ji,jj)
-                  ! after velocities with implicit bottom friction
-
-                  IF( ln_bfrimp ) THEN      ! implicit bottom friction
-                     !   A new method to implement the implicit bottom friction. 
-                     !   H. Liu
-                     !   Sept 2011
-                     ua_e(ji,jj) = umask(ji,jj,1) * ( zub_e(ji,jj) +                                            &
-                      &                               z2dt_e * ( zu_cor + zu_spg + zu_sld + zu_asp )            &
-                      &                               / ( 1._wp      - z2dt_e * bfrua(ji,jj) * hur_e(ji,jj) ) )
-                     ua_e(ji,jj) = ( ua_e(ji,jj) + z2dt_e *   zua(ji,jj)  ) * umask(ji,jj,1)   
-                     !
-                     va_e(ji,jj) = vmask(ji,jj,1) * ( zvb_e(ji,jj) +                                            &
-                      &                               z2dt_e * ( zv_cor + zv_spg + zv_sld + zv_asp )            &
-                      &                               / ( 1._wp      - z2dt_e * bfrva(ji,jj) * hvr_e(ji,jj) ) )
-                     va_e(ji,jj) = ( va_e(ji,jj) + z2dt_e *   zva(ji,jj)  ) * vmask(ji,jj,1)   
-                     !
-                  ELSE
-                     ua_e(ji,jj) = ( zub_e(ji,jj) + z2dt_e * ( zu_cor + zu_spg + zu_sld + zu_asp + zua(ji,jj))) * umask(ji,jj,1)   &
-                      &           / ( 1._wp         - z2dt_e * bfrua(ji,jj) * hur_e(ji,jj) )
-                     va_e(ji,jj) = ( zvb_e(ji,jj) + z2dt_e * ( zv_cor + zv_spg + zv_sld + zv_asp + zva(ji,jj))) * vmask(ji,jj,1)   &
-                      &           / ( 1._wp         - z2dt_e * bfrva(ji,jj) * hvr_e(ji,jj) )
-                  ENDIF
+                  zu_trd(ji,jj) = z1_4 * ( zwz(ji  ,jj-1) * zy1 + zwz(ji,jj) * zy2 )
+                  zv_trd(ji,jj) =-z1_4 * ( zwz(ji-1,jj  ) * zx1 + zwz(ji,jj) * zx2 )
                END DO
             END DO
@@ -491,45 +700,10 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                   ! surface pressure gradient
-                  IF( lk_vvl) THEN
-                     zu_spg = -grav * (  ( rhd(ji+1,jj ,1) + 1 ) * sshn_e(ji+1,jj  )    &
-                        &              - ( rhd(ji  ,jj ,1) + 1 ) * sshn_e(ji  ,jj  )  ) / e1u(ji,jj)
-                     zv_spg = -grav * (  ( rhd(ji ,jj+1,1) + 1 ) * sshn_e(ji  ,jj+1)    &
-                        &              - ( rhd(ji ,jj  ,1) + 1 ) * sshn_e(ji  ,jj  )  ) / e2v(ji,jj)
-                  ELSE
-                     zu_spg = -grav * ( sshn_e(ji+1,jj) - sshn_e(ji,jj) ) / e1u(ji,jj)
-                     zv_spg = -grav * ( sshn_e(ji,jj+1) - sshn_e(ji,jj) ) / e2v(ji,jj)
-                  ENDIF
-                  ! add tidal astronomical forcing
-                  IF ( ln_tide_pot .AND. lk_tide ) THEN
-                  zu_spg = zu_spg + grav * ( pot_astro(ji+1,jj) - pot_astro(ji,jj) ) / e1u(ji,jj)
-                  zv_spg = zv_spg + grav * ( pot_astro(ji,jj+1) - pot_astro(ji,jj) ) / e2v(ji,jj)
-                  ENDIF
-                  ! enstrophy conserving formulation for planetary vorticity term
-                  zy1 =   z1_8 * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1) + zwy(ji,jj) + zwy(ji+1,jj  ) ) / e1u(ji,jj)
-                  zx1 = - z1_8 * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) + zwx(ji,jj) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
-                  zu_cor  = zy1 * ( ff(ji  ,jj-1) + ff(ji,jj) ) * hur_e(ji,jj)
-                  zv_cor  = zx1 * ( ff(ji-1,jj  ) + ff(ji,jj) ) * hvr_e(ji,jj)
-                  ! after velocities with implicit bottom friction
-                  IF( ln_bfrimp ) THEN
-                     !   A new method to implement the implicit bottom friction. 
-                     !   H. Liu
-                     !   Sept 2011
-                     ua_e(ji,jj) = umask(ji,jj,1) * ( zub_e(ji,jj) +                                            &
-                      &                               z2dt_e * ( zu_cor + zu_spg + zu_sld + zu_asp )            &
-                      &                               / ( 1._wp      - z2dt_e * bfrua(ji,jj) * hur_e(ji,jj) ) )
-                     ua_e(ji,jj) = ( ua_e(ji,jj) + z2dt_e *   zua(ji,jj)  ) * umask(ji,jj,1)   
-                     !
-                     va_e(ji,jj) = vmask(ji,jj,1) * ( zvb_e(ji,jj) +                                            &
-                      &                               z2dt_e * ( zv_cor + zv_spg + zv_sld + zv_asp )            &
-                      &                               / ( 1._wp      - z2dt_e * bfrva(ji,jj) * hvr_e(ji,jj) ) )
-                     va_e(ji,jj) = ( va_e(ji,jj) + z2dt_e *   zva(ji,jj)  ) * vmask(ji,jj,1)   
-                     !
-                  ELSE
-                     ua_e(ji,jj) = ( zub_e(ji,jj) + z2dt_e * ( zu_cor + zu_spg + zu_sld + zu_asp + zua(ji,jj))) * umask(ji,jj,1)   &
-                     &            / ( 1._wp        - z2dt_e * bfrua(ji,jj) * hur_e(ji,jj) )
-                     va_e(ji,jj) = ( zvb_e(ji,jj) + z2dt_e * ( zv_cor + zv_spg + zv_sld + zv_asp + zva(ji,jj))) * vmask(ji,jj,1)   &
-                     &            / ( 1._wp        - z2dt_e * bfrva(ji,jj) * hvr_e(ji,jj) )
-                  ENDIF
+                  zy1 =   z1_8 * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1) &
+                   &             + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) ) / e1u(ji,jj)
+                  zx1 = - z1_8 * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) &
+                   &             + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) / e2v(ji,jj)
+                  zu_trd(ji,jj)  = zy1 * ( zwz(ji  ,jj-1) + zwz(ji,jj) )
+                  zv_trd(ji,jj)  = zx1 * ( zwz(ji-1,jj  ) + zwz(ji,jj) )
                END DO
             END DO
@@ -538,149 +712,211 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  ! surface pressure gradient
-                  IF( lk_vvl) THEN
-                     zu_spg = -grav * (  ( rhd(ji+1,jj  ,1) + 1 ) * sshn_e(ji+1,jj  )    &
-                        &              - ( rhd(ji  ,jj  ,1) + 1 ) * sshn_e(ji  ,jj  )  ) / e1u(ji,jj)
-                     zv_spg = -grav * (  ( rhd(ji  ,jj+1,1) + 1 ) * sshn_e(ji  ,jj+1)    &
-                        &              - ( rhd(ji  ,jj  ,1) + 1 ) * sshn_e(ji  ,jj  )  ) / e2v(ji,jj)
-                  ELSE
-                     zu_spg = -grav * ( sshn_e(ji+1,jj) - sshn_e(ji,jj) ) / e1u(ji,jj)
-                     zv_spg = -grav * ( sshn_e(ji,jj+1) - sshn_e(ji,jj) ) / e2v(ji,jj)
-                  ENDIF
-                  ! add tidal astronomical forcing
-                  IF ( ln_tide_pot .AND. lk_tide ) THEN
-                  zu_spg = zu_spg + grav * ( pot_astro(ji+1,jj) - pot_astro(ji,jj) ) / e1u(ji,jj)
-                  zv_spg = zv_spg + grav * ( pot_astro(ji,jj+1) - pot_astro(ji,jj) ) / e2v(ji,jj)
-                  ENDIF
-                  ! energy/enstrophy conserving formulation for planetary vorticity term
-                  zu_cor = + z1_4 / e1u(ji,jj) * (  ftne(ji,jj  ) * zwy(ji  ,jj  ) + ftnw(ji+1,jj) * zwy(ji+1,jj  )   &
-                     &                           + ftse(ji,jj  ) * zwy(ji  ,jj-1) + ftsw(ji+1,jj) * zwy(ji+1,jj-1) ) * hur_e(ji,jj)
-                  zv_cor = - z1_4 / e2v(ji,jj) * (  ftsw(ji,jj+1) * zwx(ji-1,jj+1) + ftse(ji,jj+1) * zwx(ji  ,jj+1)   &
-                     &                           + ftnw(ji,jj  ) * zwx(ji-1,jj  ) + ftne(ji,jj  ) * zwx(ji  ,jj  ) ) * hvr_e(ji,jj)
-                  ! after velocities with implicit bottom friction
-                  IF( ln_bfrimp ) THEN
-                     !   A new method to implement the implicit bottom friction. 
-                     !   H. Liu
-                     !   Sept 2011
-                     ua_e(ji,jj) = umask(ji,jj,1) * ( zub_e(ji,jj) +                                            &
-                      &                               z2dt_e * ( zu_cor + zu_spg + zu_sld + zu_asp )            &
-                      &                               / ( 1._wp      - z2dt_e * bfrua(ji,jj) * hur_e(ji,jj) ) )
-                     ua_e(ji,jj) = ( ua_e(ji,jj) + z2dt_e *   zua(ji,jj)  ) * umask(ji,jj,1)   
-                     !
-                     va_e(ji,jj) = vmask(ji,jj,1) * ( zvb_e(ji,jj) +                                            &
-                      &                               z2dt_e * ( zv_cor + zv_spg + zv_sld + zv_asp )            &
-                      &                               / ( 1._wp      - z2dt_e * bfrva(ji,jj) * hvr_e(ji,jj) ) )
-                     va_e(ji,jj) = ( va_e(ji,jj) + z2dt_e *   zva(ji,jj)  ) * vmask(ji,jj,1)   
-                     !
-                  ELSE
-                     ua_e(ji,jj) = ( zub_e(ji,jj) + z2dt_e * ( zu_cor + zu_spg + zu_sld + zu_asp + zua(ji,jj))) * umask(ji,jj,1)   &
-                     &            / ( 1._wp        - z2dt_e * bfrua(ji,jj) * hur_e(ji,jj) )
-                     va_e(ji,jj) = ( zvb_e(ji,jj) + z2dt_e * ( zv_cor + zv_spg + zv_sld + zv_asp + zva(ji,jj))) * vmask(ji,jj,1)   &
-                     &            / ( 1._wp        - z2dt_e * bfrva(ji,jj) * hvr_e(ji,jj) )
-                  ENDIF
+                  zu_trd(ji,jj) = + z1_12 / e1u(ji,jj) * (  ftne(ji,jj  ) * zwy(ji  ,jj  ) &
+                     &                                    + ftnw(ji+1,jj) * zwy(ji+1,jj  ) &
+                     &                                    + ftse(ji,jj  ) * zwy(ji  ,jj-1) & 
+                     &                                    + ftsw(ji+1,jj) * zwy(ji+1,jj-1) )
+                  zv_trd(ji,jj) = - z1_12 / e2v(ji,jj) * (  ftsw(ji,jj+1) * zwx(ji-1,jj+1) & 
+                     &                                    + ftse(ji,jj+1) * zwx(ji  ,jj+1) &
+                     &                                    + ftnw(ji,jj  ) * zwx(ji-1,jj  ) & 
+                     &                                    + ftne(ji,jj  ) * zwx(ji  ,jj  ) )
                END DO
             END DO
             ! 
          ENDIF
-         !                                                     !* domain lateral boundary
-         !                                                     !  -----------------------
-
-                                                               ! OBC open boundaries
-         IF( lk_obc               )   CALL obc_fla_ts ( ua_e, va_e, sshn_e, ssha_e )
-
-                                                               ! BDY open boundaries
-#if defined key_bdy
-         pssh => sshn_e
-         phur => hur_e
-         phvr => hvr_e
-         pu2d => ua_e
-         pv2d => va_e
-
-         IF( lk_bdy )   CALL bdy_dyn2d( kt ) 
-#endif
-
-         !
-         CALL lbc_lnk( ua_e  , 'U', -1. )                      ! local domain boundaries 
-         CALL lbc_lnk( va_e  , 'V', -1. )
-         CALL lbc_lnk( ssha_e, 'T',  1. )
-
-         zu_sum  (:,:) = zu_sum  (:,:) + ua_e  (:,:)           ! Sum over sub-time-steps
-         zv_sum  (:,:) = zv_sum  (:,:) + va_e  (:,:) 
-         zssh_sum(:,:) = zssh_sum(:,:) + ssha_e(:,:) 
-
-         !                                                !* Time filter and swap
-         !                                                !  --------------------
-         IF( jn == 1 ) THEN                                     ! Swap only (1st Euler time step)
-            zsshb_e(:,:) = sshn_e(:,:)
-            zub_e  (:,:) = zun_e (:,:)
-            zvb_e  (:,:) = zvn_e (:,:)
-            sshn_e (:,:) = ssha_e(:,:)
-            zun_e  (:,:) = ua_e  (:,:)
-            zvn_e  (:,:) = va_e  (:,:)
-         ELSE                                                   ! Swap + Filter
-            zsshb_e(:,:) = atfp * ( zsshb_e(:,:) + ssha_e(:,:) ) + atfp1 * sshn_e(:,:)
-            zub_e  (:,:) = atfp * ( zub_e  (:,:) + ua_e  (:,:) ) + atfp1 * zun_e (:,:)
-            zvb_e  (:,:) = atfp * ( zvb_e  (:,:) + va_e  (:,:) ) + atfp1 * zvn_e (:,:)
-            sshn_e (:,:) = ssha_e(:,:)
-            zun_e  (:,:) = ua_e  (:,:)
-            zvn_e  (:,:) = va_e  (:,:)
-         ENDIF
-
-         IF( lk_vvl ) THEN                                !* Update ocean depth (variable volume case only)
-            !                                             !  ------------------
-            DO jj = 1, jpjm1                                    ! Sea Surface Height at u- & v-points
-               DO ji = 1, fs_jpim1   ! Vector opt.
-                  zsshun_e(ji,jj) = 0.5_wp * umask(ji,jj,1) / ( e1u(ji,jj) * e2u(ji,jj) )       &
-                     &                     * ( e1t(ji  ,jj) * e2t(ji  ,jj) * sshn_e(ji  ,jj)    &
-                     &                     +   e1t(ji+1,jj) * e2t(ji+1,jj) * sshn_e(ji+1,jj) )
-                  zsshvn_e(ji,jj) = 0.5_wp * vmask(ji,jj,1) / ( e1v(ji,jj) * e2v(ji,jj) )       &
-                     &                     * ( e1t(ji,jj  ) * e2t(ji,jj  ) * sshn_e(ji,jj  )    &
-                     &                     +   e1t(ji,jj+1) * e2t(ji,jj+1) * sshn_e(ji,jj+1) )
-               END DO
-            END DO
-            CALL lbc_lnk( zsshun_e, 'U', 1. )                   ! lateral boundaries conditions
-            CALL lbc_lnk( zsshvn_e, 'V', 1. ) 
-            !
-            hu_e (:,:) = hu_0(:,:) + zsshun_e(:,:)              ! Ocean depth at U- and V-points
-            hv_e (:,:) = hv_0(:,:) + zsshvn_e(:,:)
+         !
+         ! Add tidal astronomical forcing if defined
+         IF ( lk_tide.AND.ln_tide_pot ) THEN
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zu_spg = grav * ( pot_astro(ji+1,jj) - pot_astro(ji,jj) ) / e1u(ji,jj)
+                  zv_spg = grav * ( pot_astro(ji,jj+1) - pot_astro(ji,jj) ) / e2v(ji,jj)
+                  zu_trd(ji,jj) = zu_trd(ji,jj) + zu_spg
+                  zv_trd(ji,jj) = zv_trd(ji,jj) + zv_spg
+               END DO
+            END DO
+         ENDIF
+         !
+         ! Add bottom stresses:
+         zu_trd(:,:) = zu_trd(:,:) + bfrua(:,:) * zun_e(:,:) * hur_e(:,:)
+         zv_trd(:,:) = zv_trd(:,:) + bfrva(:,:) * zvn_e(:,:) * hvr_e(:,:)
+         !
+         ! Surface pressure trend:
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! Add surface pressure gradient
+               zu_spg = - grav * ( zsshp2_e(ji+1,jj) - zsshp2_e(ji,jj) ) / e1u(ji,jj)
+               zv_spg = - grav * ( zsshp2_e(ji,jj+1) - zsshp2_e(ji,jj) ) / e2v(ji,jj)
+               zwx(ji,jj) = zu_spg
+               zwy(ji,jj) = zv_spg
+            END DO
+         END DO
+         !
+         ! Set next velocities:
+         IF( ln_dynadv_vec .OR. (.NOT. lk_vvl) ) THEN 	! Vector form
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ua_e(ji,jj) = (                                zun_e(ji,jj)   & 
+                            &     + rdtbt * (                      zwx(ji,jj)   &
+                            &                                 + zu_trd(ji,jj)   &
+                            &                                 + zu_frc(ji,jj) ) & 
+                            &   ) * umask(ji,jj,1)
+
+                  va_e(ji,jj) = (                                zvn_e(ji,jj)   &
+                            &     + rdtbt * (                      zwy(ji,jj)   &
+                            &                                 + zv_trd(ji,jj)   &
+                            &                                 + zv_frc(ji,jj) ) &
+                            &   ) * vmask(ji,jj,1)
+               END DO
+            END DO
+
+         ELSE					 	! Flux form
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+
+                  zhura = umask(ji,jj,1)/(hu_0(ji,jj) + zsshu_a(ji,jj) + 1._wp - umask(ji,jj,1))
+                  zhvra = vmask(ji,jj,1)/(hv_0(ji,jj) + zsshv_a(ji,jj) + 1._wp - vmask(ji,jj,1))
+
+                  ua_e(ji,jj) = (                hu_e(ji,jj)  *  zun_e(ji,jj)   & 
+                            &     + rdtbt * ( zhust_e(ji,jj)  *    zwx(ji,jj)   & 
+                            &               + zhup2_e(ji,jj)  * zu_trd(ji,jj)   &
+                            &               +      hu(ji,jj)  * zu_frc(ji,jj) ) &
+                            &   ) * zhura
+
+                  va_e(ji,jj) = (                hv_e(ji,jj)  *  zvn_e(ji,jj)   &
+                            &     + rdtbt * ( zhvst_e(ji,jj)  *    zwy(ji,jj)   &
+                            &               + zhvp2_e(ji,jj)  * zv_trd(ji,jj)   &
+                            &               +      hv(ji,jj)  * zv_frc(ji,jj) ) &
+                            &   ) * zhvra
+               END DO
+            END DO
+         ENDIF
+         !
+         IF( lk_vvl ) THEN                             !* Update ocean depth (variable volume case only)
+            !                                          !  ----------------------------------------------        
+            hu_e (:,:) = hu_0(:,:) + zsshu_a(:,:)
+            hv_e (:,:) = hv_0(:,:) + zsshv_a(:,:)
             hur_e(:,:) = umask(:,:,1) / ( hu_e(:,:) + 1._wp - umask(:,:,1) )
             hvr_e(:,:) = vmask(:,:,1) / ( hv_e(:,:) + 1._wp - vmask(:,:,1) )
             !
          ENDIF
+         !                                                 !* domain lateral boundary
+         !                                                 !  -----------------------
+         !
+         CALL lbc_lnk( ua_e  , 'U', -1._wp )               ! local domain boundaries 
+         CALL lbc_lnk( va_e  , 'V', -1._wp )
+
+#if defined key_bdy  
+
+         pssh => ssha_e
+         phur => hur_e
+         phvr => hvr_e
+         pua2d => ua_e
+         pva2d => va_e
+         pub2d => zun_e
+         pvb2d => zvn_e
+                                      
+         IF( lk_bdy )   CALL bdy_dyn2d( kt )               ! open boundaries
+#endif
+#if defined key_agrif
+         IF( .NOT.Agrif_Root() ) CALL agrif_dyn_ts( kt, jn ) ! Agrif
+#endif
+         !                                             !* Swap
+         !                                             !  ----
+         ubb_e  (:,:) = ub_e  (:,:)
+         ub_e   (:,:) = zun_e (:,:)
+         zun_e  (:,:) = ua_e  (:,:)
+         !
+         vbb_e  (:,:) = vb_e  (:,:)
+         vb_e   (:,:) = zvn_e (:,:)
+         zvn_e  (:,:) = va_e  (:,:)
+         !
+         sshbb_e(:,:) = sshb_e(:,:)
+         sshb_e (:,:) = sshn_e(:,:)
+         sshn_e (:,:) = ssha_e(:,:)
+
+         !                                             !* Sum over whole bt loop
+         !                                             !  ----------------------
+         za1 = wgtbtp1(jn)                                    
+         IF (( ln_dynadv_vec ).OR. (.NOT. lk_vvl)) THEN    ! Sum velocities
+            ua_b  (:,:) = ua_b  (:,:) + za1 * ua_e  (:,:) 
+            va_b  (:,:) = va_b  (:,:) + za1 * va_e  (:,:) 
+         ELSE                     			   ! Sum transports
+            ua_b  (:,:) = ua_b  (:,:) + za1 * ua_e  (:,:) * hu_e (:,:)
+            va_b  (:,:) = va_b  (:,:) + za1 * va_e  (:,:) * hv_e (:,:)
+         ENDIF
+         !                       			   ! Sum sea level
+         ssha(:,:) = ssha(:,:) + za1 * ssha_e(:,:)
          !                                                 ! ==================== !
       END DO                                               !        end loop      !
       !                                                    ! ==================== !
-
-#if defined key_obc
-      IF( lp_obc_east  )   sshfoe_b(:,:) = zcoef * sshfoe_b(:,:)     !!gm totally useless ?????
-      IF( lp_obc_west  )   sshfow_b(:,:) = zcoef * sshfow_b(:,:)
-      IF( lp_obc_north )   sshfon_b(:,:) = zcoef * sshfon_b(:,:)
-      IF( lp_obc_south )   sshfos_b(:,:) = zcoef * sshfos_b(:,:)
-#endif
-
       ! -----------------------------------------------------------------------------
       ! Phase 3. update the general trend with the barotropic trend
       ! -----------------------------------------------------------------------------
       !
-      !                                   !* Time average ==> after barotropic u, v, ssh
-      zcoef =  1._wp / ( 2 * nn_baro  + 1 ) 
-      zu_sum(:,:) = zcoef * zu_sum  (:,:) 
-      zv_sum(:,:) = zcoef * zv_sum  (:,:) 
-      ! 
-      !                                   !* update the general momentum trend
-      DO jk=1,jpkm1
-         ua(:,:,jk) = ua(:,:,jk) + ( zu_sum(:,:) - ub_b(:,:) ) * z1_2dt_b
-         va(:,:,jk) = va(:,:,jk) + ( zv_sum(:,:) - vb_b(:,:) ) * z1_2dt_b
+      ! At this stage ssha holds a time averaged value
+      !                                                ! Sea Surface Height at u-,v- and f-points
+      IF( lk_vvl ) THEN                                ! (required only in key_vvl case)
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1      ! NO Vector Opt.
+               zsshu_a(ji,jj) = z1_2 * umask(ji,jj,1) / ( e1u(ji  ,jj) * e2u(ji  ,jj) )                   &
+                  &                                  * ( e1t(ji  ,jj) * e2t(ji  ,jj) * ssha(ji  ,jj)     &
+                  &                                    + e1t(ji+1,jj) * e2t(ji+1,jj) * ssha(ji+1,jj) )
+               zsshv_a(ji,jj) = z1_2 * vmask(ji,jj,1) / ( e1v(ji,jj  ) * e2v(ji,jj  ) )                   &
+                  &                                  * ( e1t(ji,jj  ) * e2t(ji,jj  ) * ssha(ji,jj  )     &
+                  &                                    + e1t(ji,jj+1) * e2t(ji,jj+1) * ssha(ji,jj+1) )
+            END DO
+         END DO
+         CALL lbc_lnk( zsshu_a, 'U', 1._wp )   ;   CALL lbc_lnk( zsshv_a, 'V', 1._wp ) ! Boundary conditions
+      ENDIF
+      !
+      ! Set advection velocity correction:
+      IF (((kt==nit000).AND.(neuler==0)).OR.(.NOT.ln_bt_fw)) THEN     
+         un_adv(:,:) = zu_sum(:,:)*hur(:,:)
+         vn_adv(:,:) = zv_sum(:,:)*hvr(:,:)
+      ELSE
+         un_adv(:,:) = z1_2 * ( ub2_b(:,:) + zu_sum(:,:)) * hur(:,:)
+         vn_adv(:,:) = z1_2 * ( vb2_b(:,:) + zv_sum(:,:)) * hvr(:,:)
+      END IF
+
+      IF (ln_bt_fw) THEN ! Save integrated transport for next computation
+         ub2_b(:,:) = zu_sum(:,:)
+         vb2_b(:,:) = zv_sum(:,:)
+      ENDIF
+      !
+      ! Update barotropic trend:
+      IF (( ln_dynadv_vec ).OR. (.NOT. lk_vvl)) THEN
+         DO jk=1,jpkm1
+            ua(:,:,jk) = ua(:,:,jk) + ( ua_b(:,:) - ub_b(:,:) ) * z1_2dt_b
+            va(:,:,jk) = va(:,:,jk) + ( va_b(:,:) - vb_b(:,:) ) * z1_2dt_b
+         END DO
+      ELSE
+         hu_e  (:,:) = umask(:,:,1) / ( zhur_b(:,:) + 1._wp - umask(:,:,1) )
+         hv_e  (:,:) = vmask(:,:,1) / ( zhvr_b(:,:) + 1._wp - vmask(:,:,1) )
+         DO jk=1,jpkm1
+            ua(:,:,jk) = ua(:,:,jk) + hur(:,:) * ( ua_b(:,:) - ub_b(:,:) * hu_e(:,:) ) * z1_2dt_b
+            va(:,:,jk) = va(:,:,jk) + hvr(:,:) * ( va_b(:,:) - vb_b(:,:) * hv_e(:,:) ) * z1_2dt_b
+         END DO
+         ! Save barotropic velocities not transport:
+         ua_b  (:,:) =  ua_b(:,:) / ( hu_0(:,:) + zsshu_a(:,:) + 1._wp - umask(:,:,1) )
+         va_b  (:,:) =  va_b(:,:) / ( hv_0(:,:) + zsshv_a(:,:) + 1._wp - vmask(:,:,1) )
+      ENDIF
+      !
+      DO jk = 1, jpkm1
+         ! Correct velocities:
+         un(:,:,jk) = ( un(:,:,jk) + un_adv(:,:) - un_b(:,:) )*umask(:,:,jk)
+         vn(:,:,jk) = ( vn(:,:,jk) + vn_adv(:,:) - vn_b(:,:) )*vmask(:,:,jk)
+         !
       END DO
-      un_b  (:,:) =  zu_sum(:,:) 
-      vn_b  (:,:) =  zv_sum(:,:) 
-      sshn_b(:,:) = zcoef * zssh_sum(:,:) 
       !
       !                                   !* write time-spliting arrays in the restart
-      IF( lrst_oce )   CALL ts_rst( kt, 'WRITE' )
-      !
-      CALL wrk_dealloc( jpi, jpj, zsshun_e, zsshvn_e, zsshb_e, zssh_sum, zhdiv     )
-      CALL wrk_dealloc( jpi, jpj, zua, zva, zun, zvn, zun_e, zvn_e, zub_e, zvb_e   )
-      CALL wrk_dealloc( jpi, jpj, zcu, zcv, zwx, zwy, zbfru, zbfrv, zu_sum, zv_sum )
+      IF(lrst_oce .AND.ln_bt_fw)   CALL ts_rst( kt, 'WRITE' )
+      !
+      CALL wrk_dealloc( jpi, jpj, zsshp2_e, zhdiv )
+      CALL wrk_dealloc( jpi, jpj, zu_trd, zv_trd, zun_e, zvn_e )
+      CALL wrk_dealloc( jpi, jpj, zwx, zwy, zu_sum, zv_sum, zssh_frc, zu_frc, zv_frc )
+      CALL wrk_dealloc( jpi, jpj, zhup2_e, zhvp2_e, zhust_e, zhvst_e )
+      CALL wrk_dealloc( jpi, jpj, zhur_b, zhvr_b                                     )
+      CALL wrk_dealloc( jpi, jpj, zsshu_a, zsshv_a                                   )
+      CALL wrk_dealloc( jpi, jpj, zht, zhf )
       !
       IF( nn_timing == 1 )  CALL timing_stop('dyn_spg_ts')
@@ -688,4 +924,80 @@
    END SUBROUTINE dyn_spg_ts
 
+   SUBROUTINE ts_wgt( ll_av, ll_fw, jpit, zwgt1, zwgt2)
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE ts_wgt  ***
+      !!
+      !! ** Purpose : Set time-splitting weights for temporal averaging (or not)
+      !!----------------------------------------------------------------------
+      LOGICAL, INTENT(in) ::   ll_av      ! temporal averaging=.true.
+      LOGICAL, INTENT(in) ::   ll_fw      ! forward time splitting =.true.
+      INTEGER, INTENT(inout) :: jpit      ! cycle length    
+      REAL(wp), DIMENSION(3*nn_baro), INTENT(inout) ::   zwgt1, & ! Primary weights
+                                                         zwgt2    ! Secondary weights
+      
+      INTEGER ::  jic, jn, ji                      ! temporary integers
+      REAL(wp) :: za1, za2
+      !!----------------------------------------------------------------------
+
+      zwgt1(:) = 0._wp
+      zwgt2(:) = 0._wp
+
+      ! Set time index when averaged value is requested
+      IF (ll_fw) THEN 
+         jic = nn_baro
+      ELSE
+         jic = 2 * nn_baro
+      ENDIF
+
+      ! Set primary weights:
+      IF (ll_av) THEN
+           ! Define simple boxcar window for primary weights 
+           ! (width = nn_baro, centered around jic)     
+         SELECT CASE ( nn_bt_flt )
+              CASE( 0 )  ! No averaging
+                 zwgt1(jic) = 1._wp
+                 jpit = jic
+
+              CASE( 1 )  ! Boxcar, width = nn_baro
+                 DO jn = 1, 3*nn_baro
+                    za1 = ABS(float(jn-jic))/float(nn_baro) 
+                    IF (za1 < 0.5_wp) THEN
+                      zwgt1(jn) = 1._wp
+                      jpit = jn
+                    ENDIF
+                 ENDDO
+
+              CASE( 2 )  ! Boxcar, width = 2 * nn_baro
+                 DO jn = 1, 3*nn_baro
+                    za1 = ABS(float(jn-jic))/float(nn_baro) 
+                    IF (za1 < 1._wp) THEN
+                      zwgt1(jn) = 1._wp
+                      jpit = jn
+                    ENDIF
+                 ENDDO
+              CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_bt_flt' )
+         END SELECT
+
+      ELSE ! No time averaging
+         zwgt1(jic) = 1._wp
+         jpit = jic
+      ENDIF
+    
+      ! Set secondary weights
+      DO jn = 1, jpit
+        DO ji = jn, jpit
+             zwgt2(jn) = zwgt2(jn) + zwgt1(ji)
+        END DO
+      END DO
+
+      ! Normalize weigths:
+      za1 = 1._wp / SUM(zwgt1(1:jpit))
+      za2 = 1._wp / SUM(zwgt2(1:jpit))
+      DO jn = 1, jpit
+        zwgt1(jn) = zwgt1(jn) * za1
+        zwgt2(jn) = zwgt2(jn) * za2
+      END DO
+      !
+   END SUBROUTINE ts_wgt
 
    SUBROUTINE ts_rst( kt, cdrw )
@@ -698,81 +1010,141 @@
       CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
       !
-      INTEGER ::  ji, jk        ! dummy loop indices
       !!----------------------------------------------------------------------
       !
       IF( TRIM(cdrw) == 'READ' ) THEN
-         IF( iom_varid( numror, 'un_b', ldstop = .FALSE. ) > 0 ) THEN
-            CALL iom_get( numror, jpdom_autoglo, 'un_b'  , un_b  (:,:) )   ! external velocity issued
-            CALL iom_get( numror, jpdom_autoglo, 'vn_b'  , vn_b  (:,:) )   ! from barotropic loop
+         CALL iom_get( numror, jpdom_autoglo, 'ub2_b'  , ub2_b  (:,:) )   
+         CALL iom_get( numror, jpdom_autoglo, 'vb2_b'  , vb2_b  (:,:) ) 
+         IF( .NOT.ln_bt_av .AND. iom_varid( numror, 'sshbb_e', ldstop = .FALSE. ) > 0) THEN
+            CALL iom_get( numror, jpdom_autoglo, 'sshbb_e'  , sshbb_e(:,:) )   
+            CALL iom_get( numror, jpdom_autoglo, 'ubb_e'    ,   ubb_e(:,:) )   
+            CALL iom_get( numror, jpdom_autoglo, 'vbb_e'    ,   vbb_e(:,:) )
+            CALL iom_get( numror, jpdom_autoglo, 'sshb_e'   ,  sshb_e(:,:) ) 
+            CALL iom_get( numror, jpdom_autoglo, 'ub_e'     ,    ub_e(:,:) )   
+            CALL iom_get( numror, jpdom_autoglo, 'vb_e'     ,    vb_e(:,:) )
          ELSE
-            un_b (:,:) = 0._wp
-            vn_b (:,:) = 0._wp
-            ! vertical sum
-            IF( lk_vopt_loop ) THEN          ! vector opt., forced unroll
-               DO jk = 1, jpkm1
-                  DO ji = 1, jpij
-                     un_b(ji,1) = un_b(ji,1) + fse3u(ji,1,jk) * un(ji,1,jk)
-                     vn_b(ji,1) = vn_b(ji,1) + fse3v(ji,1,jk) * vn(ji,1,jk)
-                  END DO
-               END DO
-            ELSE                             ! No  vector opt.
-               DO jk = 1, jpkm1
-                  un_b(:,:) = un_b(:,:) + fse3u(:,:,jk) * un(:,:,jk)
-                  vn_b(:,:) = vn_b(:,:) + fse3v(:,:,jk) * vn(:,:,jk)
-               END DO
-            ENDIF
-            un_b (:,:) = un_b(:,:) * hur(:,:)
-            vn_b (:,:) = vn_b(:,:) * hvr(:,:)
-         ENDIF
-
-         ! Vertically integrated velocity (before)
-         IF (neuler/=0) THEN
-            ub_b (:,:) = 0._wp
-            vb_b (:,:) = 0._wp
-
-            ! vertical sum
-            IF( lk_vopt_loop ) THEN          ! vector opt., forced unroll
-               DO jk = 1, jpkm1
-                  DO ji = 1, jpij
-                     ub_b(ji,1) = ub_b(ji,1) + fse3u_b(ji,1,jk) * ub(ji,1,jk)
-                     vb_b(ji,1) = vb_b(ji,1) + fse3v_b(ji,1,jk) * vb(ji,1,jk)
-                  END DO
-               END DO
-            ELSE                             ! No  vector opt.
-               DO jk = 1, jpkm1
-                  ub_b(:,:) = ub_b(:,:) + fse3u_b(:,:,jk) * ub(:,:,jk)
-                  vb_b(:,:) = vb_b(:,:) + fse3v_b(:,:,jk) * vb(:,:,jk)
-               END DO
-            ENDIF
-
-            IF( lk_vvl ) THEN
-               ub_b (:,:) = ub_b(:,:) * umask(:,:,1) / ( hu_0(:,:) + sshu_b(:,:) + 1._wp - umask(:,:,1) )
-               vb_b (:,:) = vb_b(:,:) * vmask(:,:,1) / ( hv_0(:,:) + sshv_b(:,:) + 1._wp - vmask(:,:,1) )
-            ELSE
-               ub_b(:,:) = ub_b(:,:) * hur(:,:)
-               vb_b(:,:) = vb_b(:,:) * hvr(:,:)
-            ENDIF
-         ELSE                                 ! neuler==0
-            ub_b (:,:) = un_b (:,:)
-            vb_b (:,:) = vn_b (:,:)
-         ENDIF
-
-         IF( iom_varid( numror, 'sshn_b', ldstop = .FALSE. ) > 0 ) THEN
-            CALL iom_get( numror, jpdom_autoglo, 'sshn_b' , sshn_b (:,:) )   ! filtered ssh
-         ELSE
-            sshn_b(:,:) = sshb(:,:)   ! if not in restart set previous time mean to current baroclinic before value   
-         ENDIF 
+            sshbb_e = sshn_b                                                ! ACC GUESS WORK
+            ubb_e   = ub_b
+            vbb_e   = vb_b
+            sshb_e  = sshn_b
+            ub_e    = ub_b
+            vb_e    = vb_b
+         ENDIF
+      !
       ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN
-         CALL iom_rstput( kt, nitrst, numrow, 'un_b'   , un_b  (:,:) )   ! external velocity and ssh
-         CALL iom_rstput( kt, nitrst, numrow, 'vn_b'   , vn_b  (:,:) )   ! issued from barotropic loop
-         CALL iom_rstput( kt, nitrst, numrow, 'sshn_b' , sshn_b(:,:) )   ! 
+         CALL iom_rstput( kt, nitrst, numrow, 'ub2_b'   , ub2_b  (:,:) )
+         CALL iom_rstput( kt, nitrst, numrow, 'vb2_b'   , vb2_b  (:,:) )
+         !
+         IF (.NOT.ln_bt_av) THEN
+            CALL iom_rstput( kt, nitrst, numrow, 'sshbb_e'  , sshbb_e(:,:) ) 
+            CALL iom_rstput( kt, nitrst, numrow, 'ubb_e'    ,   ubb_e(:,:) )
+            CALL iom_rstput( kt, nitrst, numrow, 'vbb_e'    ,   vbb_e(:,:) )
+            CALL iom_rstput( kt, nitrst, numrow, 'sshb_e'   ,  sshb_e(:,:) )
+            CALL iom_rstput( kt, nitrst, numrow, 'ub_e'     ,    ub_e(:,:) )
+            CALL iom_rstput( kt, nitrst, numrow, 'vb_e'     ,    vb_e(:,:) )
+         ENDIF
       ENDIF
       !
    END SUBROUTINE ts_rst
 
+   SUBROUTINE dyn_spg_ts_init( kt )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE dyn_spg_ts_init  ***
+      !!
+      !! ** Purpose : Set time splitting options
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
+      !
+      INTEGER  :: ji ,jj, jk
+      REAL(wp) :: zxr2, zyr2, zcmax
+      REAL(wp), POINTER, DIMENSION(:,:) :: zcu, zht
+      !!
+!      NAMELIST/namsplit/ ln_bt_fw, ln_bt_av, ln_bt_nn_auto, &
+!      &                  nn_baro, rn_bt_cmax, nn_bt_flt
+      !!----------------------------------------------------------------------
+!      REWIND( numnam )              !* Namelist namsplit: split-explicit free surface
+!      READ  ( numnam, namsplit )
+      !         ! Max courant number for ext. grav. waves
+      !
+      CALL wrk_alloc( jpi, jpj, zcu, zht )
+      !
+      ! JC: Simplification needed below: define ht_0 even when volume is fixed
+      IF (lk_vvl) THEN 
+         zht(:,:) = ht_0(:,:) * tmask(:,:,1)
+      ELSE
+         zht(:,:) = 0.
+         DO jk = 1, jpkm1
+            zht(:,:) = zht(:,:) + fse3t_n(:,:,jk) * tmask(:,:,jk)
+         END DO
+      ENDIF
+
+      DO jj = 1, jpj
+         DO ji =1, jpi
+            zxr2 = 1./(e1t(ji,jj)*e1t(ji,jj))
+            zyr2 = 1./(e2t(ji,jj)*e2t(ji,jj))
+            zcu(ji,jj) = sqrt(grav*zht(ji,jj)*(zxr2 + zyr2) )
+         END DO
+      END DO
+
+      zcmax = MAXVAL(zcu(:,:))
+      IF( lk_mpp )   CALL mpp_max( zcmax )
+
+      ! Estimate number of iterations to satisfy a max courant number=0.8 
+      IF (ln_bt_nn_auto) nn_baro = CEILING( rdt / rn_bt_cmax * zcmax)
+      
+      rdtbt = rdt / FLOAT(nn_baro)
+      zcmax = zcmax * rdtbt
+							! Print results
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'dyn_spg_ts : split-explicit free surface'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+      IF( ln_bt_nn_auto ) THEN
+         IF(lwp) WRITE(numout,*) ' ln_ts_nn_auto=.true. Automatically set nn_baro '
+         IF(lwp) WRITE(numout,*) ' Max. courant number allowed: ', rn_bt_cmax
+      ELSE
+         IF(lwp) WRITE(numout,*) ' ln_ts_nn_auto=.false.: Use nn_baro in namelist '
+      ENDIF
+      IF(lwp) WRITE(numout,*) ' nn_baro = ', nn_baro
+      IF(lwp) WRITE(numout,*) ' Barotropic time step [s] is :', rdtbt
+      IF(lwp) WRITE(numout,*) ' Maximum Courant number is   :', zcmax
+
+      IF(ln_bt_av) THEN
+         IF(lwp) WRITE(numout,*) ' ln_bt_av=.true.  => Time averaging over nn_baro time steps is on '
+      ELSE
+         IF(lwp) WRITE(numout,*) ' ln_bt_av=.false. => No time averaging of barotropic variables '
+      ENDIF
+      !
+      !
+      IF(ln_bt_fw) THEN
+         IF(lwp) WRITE(numout,*) ' ln_bt_fw=.true.  => Forward integration of barotropic variables '
+      ELSE
+         IF(lwp) WRITE(numout,*) ' ln_bt_fw =.false.=> Centered integration of barotropic variables '
+      ENDIF
+      !
+      IF(lwp) WRITE(numout,*) ' Time filter choice, nn_bt_flt: ', nn_bt_flt
+      SELECT CASE ( nn_bt_flt )
+           CASE( 0 )  ;   IF(lwp) WRITE(numout,*) '      Dirac'
+           CASE( 1 )  ;   IF(lwp) WRITE(numout,*) '      Boxcar: width = nn_baro'
+           CASE( 2 )  ;   IF(lwp) WRITE(numout,*) '      Boxcar: width = 2*nn_baro' 
+           CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_bt_flt: should 0,1,2' )
+      END SELECT
+      !
+      IF ((.NOT.ln_bt_av).AND.(.NOT.ln_bt_fw)) THEN
+         CALL ctl_stop( 'dynspg_ts ERROR: No time averaging => only forward integration is possible' )
+      ENDIF
+      IF ( zcmax>0.9_wp ) THEN
+         CALL ctl_stop( 'dynspg_ts ERROR: Maximum Courant number is greater than 0.9: Inc. nn_baro !' )          
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi, jpj, zcu, zht )
+      !
+   END SUBROUTINE dyn_spg_ts_init
+
 #else
-   !!----------------------------------------------------------------------
-   !!   Default case :   Empty module   No standart free surface cst volume
-   !!----------------------------------------------------------------------
+   !!---------------------------------------------------------------------------
+   !!   Default case :   Empty module   No standard free surface constant volume
+   !!---------------------------------------------------------------------------
+
+   USE par_kind
+   LOGICAL, PUBLIC, PARAMETER :: ln_bt_fw=.FALSE. ! Forward integration of barotropic sub-stepping
 CONTAINS
    INTEGER FUNCTION dyn_spg_ts_alloc()    ! Dummy function
@@ -787,5 +1159,9 @@
       CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
       WRITE(*,*) 'ts_rst    : You should not have seen this print! error?', kt, cdrw
-   END SUBROUTINE ts_rst    
+   END SUBROUTINE ts_rst  
+   SUBROUTINE dyn_spg_ts_init( kt )       ! Empty routine
+      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
+      WRITE(*,*) 'dyn_spg_ts_init   : You should not have seen this print! error?', kt
+   END SUBROUTINE dyn_spg_ts_init
 #endif
    
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 4292)
@@ -572,4 +572,5 @@
       INTEGER  ::   ierr                                          ! local integer
       REAL(wp) ::   zfac12, zua, zva                              ! local scalars
+      REAL(wp) ::   zmsk, ze3                                     ! local scalars
       !                                                           !  3D workspace 
       REAL(wp), POINTER    , DIMENSION(:,:  )         :: zwx, zwy, zwz
@@ -577,6 +578,5 @@
 #if defined key_vvl
       REAL(wp), POINTER    , DIMENSION(:,:,:)         :: ze3f     !  3D workspace (lk_vvl=T)
-#endif
-#if ! defined key_vvl
+#else
       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:), SAVE   :: ze3f     ! lk_vvl=F, ze3f=1/e3f saved one for all
 #endif
@@ -604,11 +604,13 @@
       ENDIF
 
-      IF( kt == nit000 .OR. lk_vvl ) THEN      ! reciprocal of e3 at F-point (masked averaging of e3t)
+      IF( kt == nit000 .OR. lk_vvl ) THEN      ! reciprocal of e3 at F-point (masked averaging of e3t over ocean points)
          DO jk = 1, jpk
             DO jj = 1, jpjm1
                DO ji = 1, jpim1
-                  ze3f(ji,jj,jk) = ( fse3t(ji,jj+1,jk)*tmask(ji,jj+1,jk) + fse3t(ji+1,jj+1,jk)*tmask(ji+1,jj+1,jk)   &
-                     &             + fse3t(ji,jj  ,jk)*tmask(ji,jj  ,jk) + fse3t(ji+1,jj  ,jk)*tmask(ji+1,jj  ,jk) ) * 0.25
-                  IF( ze3f(ji,jj,jk) /= 0._wp )   ze3f(ji,jj,jk) = 1._wp / ze3f(ji,jj,jk)
+                  ze3  = ( fse3t(ji,jj+1,jk)*tmask(ji,jj+1,jk) + fse3t(ji+1,jj+1,jk)*tmask(ji+1,jj+1,jk)   &
+                     &   + fse3t(ji,jj  ,jk)*tmask(ji,jj  ,jk) + fse3t(ji+1,jj  ,jk)*tmask(ji+1,jj  ,jk) )
+                  zmsk = (                   tmask(ji,jj+1,jk) +                     tmask(ji+1,jj+1,jk)   &
+                     &                     + tmask(ji,jj  ,jk) +                     tmask(ji+1,jj  ,jk) )
+                  IF( ze3 /= 0._wp )   ze3f(ji,jj,jk) = zmsk / ze3
                END DO
             END DO
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_imp.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_imp.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_imp.F90	(revision 4292)
@@ -16,4 +16,5 @@
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
+   USE domvvl          ! variable volume
    USE sbc_oce         ! surface boundary condition: ocean
    USE zdf_oce         ! ocean vertical physics
@@ -24,4 +25,7 @@
    USE wrk_nemo        ! Memory Allocation
    USE timing          ! Timing
+   USE dynadv          ! dynamics: vector invariant versus flux form
+   USE dynspg_oce, ONLY: lk_dynspg_ts, ua_b, va_b
+   USE dynspg_ts
 
    IMPLICIT NONE
@@ -29,4 +33,6 @@
 
    PUBLIC   dyn_zdf_imp   ! called by step.F90
+
+   REAL(wp) ::  r_vvl     ! variable volume indicator, =1 if lk_vvl=T, =0 otherwise 
 
    !! * Substitutions
@@ -64,8 +70,8 @@
       INTEGER  ::   ikbu, ikbv   ! local integers
       REAL(wp) ::   z1_p2dt, zcoef, zzwi, zzws, zrhs   ! local scalars
+      REAL(wp) ::   ze3ua, ze3va
       !!----------------------------------------------------------------------
 
       REAL(wp), POINTER, DIMENSION(:,:,:) ::  zwi, zwd, zws
-      REAL(wp), POINTER, DIMENSION(:,:)   ::  zavmu, zavmv
       !!----------------------------------------------------------------------
       !
@@ -73,5 +79,4 @@
       !
       CALL wrk_alloc( jpi,jpj,jpk, zwi, zwd, zws ) 
-      CALL wrk_alloc( jpi,jpj, zavmu, zavmv ) 
       !
       IF( kt == nit000 ) THEN
@@ -79,4 +84,8 @@
          IF(lwp) WRITE(numout,*) 'dyn_zdf_imp : vertical momentum diffusion implicit operator'
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+         !
+         IF( lk_vvl ) THEN   ;    r_vvl = 1._wp       ! Variable volume indicator
+         ELSE                ;    r_vvl = 0._wp       
+         ENDIF
       ENDIF
 
@@ -94,19 +103,54 @@
       IF( ln_bfrimp ) THEN
 # if defined key_vectopt_loop
-      DO jj = 1, 1
-         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
+         DO jj = 1, 1
+            DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
 # else
-      DO jj = 2, jpjm1
-         DO ji = 2, jpim1
+         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)
-            zavmu(ji,jj) = avmu(ji,jj,ikbu+1)
-            zavmv(ji,jj) = avmv(ji,jj,ikbv+1)
-            avmu(ji,jj,ikbu+1) = -bfrua(ji,jj) * fse3uw(ji,jj,ikbu+1) 
-            avmv(ji,jj,ikbv+1) = -bfrva(ji,jj) * fse3vw(ji,jj,ikbv+1)
-         END DO
-      END DO
-      ENDIF
+               ikbu = mbku(ji,jj)       ! ocean bottom level at u- and v-points 
+               ikbv = mbkv(ji,jj)       ! (deepest ocean u- and v-points)
+               avmu(ji,jj,ikbu+1) = -bfrua(ji,jj) * fse3uw(ji,jj,ikbu+1)
+               avmv(ji,jj,ikbv+1) = -bfrva(ji,jj) * fse3vw(ji,jj,ikbv+1)
+            END DO
+         END DO
+      ENDIF
+
+#if defined key_dynspg_ts
+      IF( ln_dynadv_vec .OR. .NOT. lk_vvl ) THEN      ! applied on velocity
+         DO jk = 1, jpkm1
+            ua(:,:,jk) = ( ub(:,:,jk) + p2dt * ua(:,:,jk) ) * umask(:,:,jk)
+            va(:,:,jk) = ( vb(:,:,jk) + p2dt * va(:,:,jk) ) * vmask(:,:,jk)
+         END DO
+      ELSE                                            ! applied on thickness weighted velocity
+         DO jk = 1, jpkm1
+            ua(:,:,jk) = (          ub(:,:,jk) * fse3u_b(:,:,jk)      &
+               &           + p2dt * ua(:,:,jk) * fse3u_n(:,:,jk)  )   &
+               &                               / fse3u_a(:,:,jk) * umask(:,:,jk)
+            va(:,:,jk) = (          vb(:,:,jk) * fse3v_b(:,:,jk)      &
+               &           + p2dt * va(:,:,jk) * fse3v_n(:,:,jk)  )   &
+               &                               / fse3v_a(:,:,jk) * vmask(:,:,jk)
+         END DO
+      ENDIF
+
+      IF ( ln_bfrimp .AND.lk_dynspg_ts ) THEN
+         ! remove barotropic velocities:
+         DO jk = 1, jpkm1
+            ua(:,:,jk) = (ua(:,:,jk) - ua_b(:,:)) * umask(:,:,jk)
+            va(:,:,jk) = (va(:,:,jk) - va_b(:,:)) * vmask(:,:,jk)
+         ENDDO
+         ! Add bottom stress due to barotropic component only:
+         DO jj = 2, jpjm1        
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ikbu = mbku(ji,jj)         ! ocean bottom level at u- and v-points 
+               ikbv = mbkv(ji,jj)         ! (deepest ocean u- and v-points)
+               ze3ua =  ( 1._wp - r_vvl ) * fse3u_n(ji,jj,ikbu) + r_vvl   * fse3u_a(ji,jj,ikbu)
+               ze3va =  ( 1._wp - r_vvl ) * fse3v_n(ji,jj,ikbv) + r_vvl   * fse3v_a(ji,jj,ikbv)
+               ua(ji,jj,ikbu) = ua(ji,jj,ikbu) + p2dt * bfrua(ji,jj) * ua_b(ji,jj) / ze3ua
+               va(ji,jj,ikbv) = va(ji,jj,ikbv) + p2dt * bfrva(ji,jj) * va_b(ji,jj) / ze3va
+            END DO
+         END DO
+      ENDIF
+#endif
 
       ! 2. Vertical diffusion on u
@@ -119,5 +163,6 @@
          DO jj = 2, jpjm1 
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zcoef = - p2dt / fse3u(ji,jj,jk)
+               ze3ua =  ( 1._wp - r_vvl ) * fse3u_n(ji,jj,jk) + r_vvl   * fse3u_a(ji,jj,jk)   ! after scale factor at T-point
+               zcoef = - p2dt / ze3ua      
                zzwi          = zcoef * avmu (ji,jj,jk  ) / fse3uw(ji,jj,jk  )
                zwi(ji,jj,jk) = zzwi  * umask(ji,jj,jk)
@@ -128,5 +173,5 @@
          END DO
       END DO
-      DO jj = 2, jpjm1        ! Surface boudary conditions
+      DO jj = 2, jpjm1        ! Surface boundary conditions
          DO ji = fs_2, fs_jpim1   ! vector opt.
             zwi(ji,jj,1) = 0._wp
@@ -160,6 +205,12 @@
       DO jj = 2, jpjm1        !==  second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1  ==
          DO ji = fs_2, fs_jpim1   ! vector opt.
-            ua(ji,jj,1) = ub(ji,jj,1) + p2dt * (  ua(ji,jj,1) + 0.5_wp * ( utau_b(ji,jj) + utau(ji,jj) )   &
-               &                                                       * r1_rau0 / fse3u(ji,jj,1)       )
+            ze3ua =  ( 1._wp - r_vvl ) * fse3u_n(ji,jj,1) + r_vvl   * fse3u_a(ji,jj,1) 
+#if defined key_dynspg_ts
+            ua(ji,jj,1) = ua(ji,jj,1) + p2dt * 0.5_wp * ( utau_b(ji,jj) + utau(ji,jj) )   &
+               &                                      / ( ze3ua * rau0 ) 
+#else
+            ua(ji,jj,1) = ub(ji,jj,1) + p2dt *(ua(ji,jj,1) +  0.5_wp * ( utau_b(ji,jj) + utau(ji,jj) )   &
+               &                                                     / ( fse3u(ji,jj,1) * rau0     ) ) 
+#endif
          END DO
       END DO
@@ -167,5 +218,9 @@
          DO jj = 2, jpjm1   
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zrhs = ub(ji,jj,jk) + p2dt * ua(ji,jj,jk)   ! zrhs=right hand side
+#if defined key_dynspg_ts
+               zrhs = ua(ji,jj,jk)   ! zrhs=right hand side
+#else
+               zrhs = ub(ji,jj,jk) + p2dt * ua(ji,jj,jk)
+#endif
                ua(ji,jj,jk) = zrhs - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * ua(ji,jj,jk-1)
             END DO
@@ -186,4 +241,5 @@
       END DO
 
+#if ! defined key_dynspg_ts
       ! Normalization to obtain the general momentum trend ua
       DO jk = 1, jpkm1
@@ -194,5 +250,5 @@
          END DO
       END DO
-
+#endif
 
       ! 3. Vertical diffusion on v
@@ -205,5 +261,6 @@
          DO jj = 2, jpjm1   
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zcoef = -p2dt / fse3v(ji,jj,jk)
+               ze3va =  ( 1._wp - r_vvl ) * fse3v_n(ji,jj,jk)  + r_vvl * fse3v_a(ji,jj,jk)   ! after scale factor at T-point
+               zcoef = - p2dt / ze3va
                zzwi          = zcoef * avmv (ji,jj,jk  ) / fse3vw(ji,jj,jk  )
                zwi(ji,jj,jk) =  zzwi * vmask(ji,jj,jk)
@@ -214,5 +271,5 @@
          END DO
       END DO
-      DO jj = 2, jpjm1        ! Surface boudary conditions
+      DO jj = 2, jpjm1        ! Surface boundary conditions
          DO ji = fs_2, fs_jpim1   ! vector opt.
             zwi(ji,jj,1) = 0._wp
@@ -246,6 +303,12 @@
       DO jj = 2, jpjm1        !==  second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1  ==
          DO ji = fs_2, fs_jpim1   ! vector opt.
-            va(ji,jj,1) = vb(ji,jj,1) + p2dt * (  va(ji,jj,1) + 0.5_wp * ( vtau_b(ji,jj) + vtau(ji,jj) )   &
-               &                                                       * r1_rau0 / fse3v(ji,jj,1)       )
+            ze3va =  ( 1._wp - r_vvl ) * fse3v_n(ji,jj,1) + r_vvl   * fse3v_a(ji,jj,1) 
+#if defined key_dynspg_ts            
+            va(ji,jj,1) = va(ji,jj,1) + p2dt * 0.5_wp * ( vtau_b(ji,jj) + vtau(ji,jj) )   &
+               &                                      / ( ze3va * rau0 ) 
+#else
+            va(ji,jj,1) = vb(ji,jj,1) + p2dt *(va(ji,jj,1) +  0.5_wp * ( vtau_b(ji,jj) + vtau(ji,jj) )   &
+               &                                                       / ( fse3v(ji,jj,1) * rau0     )  )
+#endif
          END DO
       END DO
@@ -253,5 +316,9 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zrhs = vb(ji,jj,jk) + p2dt * va(ji,jj,jk)   ! zrhs=right hand side
+#if defined key_dynspg_ts
+               zrhs = va(ji,jj,jk)   ! zrhs=right hand side
+#else
+               zrhs = vb(ji,jj,jk) + p2dt * va(ji,jj,jk)
+#endif
                va(ji,jj,jk) = zrhs - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * va(ji,jj,jk-1)
             END DO
@@ -259,5 +326,5 @@
       END DO
       !
-      DO jj = 2, jpjm1        !==  thrid recurrence : SOLk = ( Lk - Uk * SOLk+1 ) / Dk  ==
+      DO jj = 2, jpjm1        !==  third recurrence : SOLk = ( Lk - Uk * SOLk+1 ) / Dk  ==
          DO ji = fs_2, fs_jpim1   ! vector opt.
             va(ji,jj,jpkm1) = va(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
@@ -273,4 +340,5 @@
 
       ! Normalization to obtain the general momentum trend va
+#if ! defined key_dynspg_ts
       DO jk = 1, jpkm1
          DO jj = 2, jpjm1   
@@ -280,5 +348,7 @@
          END DO
       END DO
-
+#endif
+
+      ! J. Chanut: Lines below are useless ?
       !! restore bottom layer avmu(v) 
       IF( ln_bfrimp ) THEN
@@ -292,6 +362,6 @@
             ikbu = mbku(ji,jj)         ! ocean bottom level at u- and v-points 
             ikbv = mbkv(ji,jj)         ! (deepest ocean u- and v-points)
-            avmu(ji,jj,ikbu+1) = zavmu(ji,jj)
-            avmv(ji,jj,ikbv+1) = zavmv(ji,jj)
+            avmu(ji,jj,ikbu+1) = 0.e0
+            avmv(ji,jj,ikbv+1) = 0.e0
          END DO
       END DO
@@ -299,5 +369,4 @@
       !
       CALL wrk_dealloc( jpi,jpj,jpk, zwi, zwd, zws) 
-      CALL wrk_dealloc( jpi,jpj, zavmu, zavmv) 
       !
       IF( nn_timing == 1 )  CALL timing_stop('dyn_zdf_imp')
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90	(revision 4292)
@@ -8,9 +8,11 @@
    !!             -   !  2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
    !!             -   !  2010-09  (D.Storkey and E.O'Dea) bug fixes for BDY module
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   ssh_wzv        : after ssh & now vertical velocity
-   !!   ssh_nxt        : filter ans swap the ssh arrays
+   !!            3.3  !  2011-10  (M. Leclair) split former ssh_wzv routine and remove all vvl related work
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   ssh_nxt        : after ssh
+   !!   ssh_swp        : filter ans swap the ssh arrays
+   !!   wzv            : compute now vertical velocity
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers variables
@@ -20,4 +22,5 @@
    USE divcur          ! hor. divergence and curl      (div & cur routines)
    USE iom             ! I/O library
+   USE restart         ! only for lrst_oce
    USE in_out_manager  ! I/O manager
    USE prtctl          ! Print control
@@ -28,7 +31,11 @@
    USE obc_oce
    USE bdy_oce
+   USE bdy_par         
+   USE bdydyn2d        ! bdy_ssh routine
    USE diaar5, ONLY:   lk_diaar5
    USE iom
-   USE sbcrnf, ONLY: h_rnf, nk_rnf   ! River runoff 
+   USE sbcrnf, ONLY: h_rnf, nk_rnf, sbc_rnf_div   ! River runoff 
+   USE dynspg_ts,   ONLY: ln_bt_fw
+   USE dynspg_oce, ONLY: lk_dynspg_ts
 #if defined key_agrif
    USE agrif_opa_update
@@ -44,6 +51,7 @@
    PRIVATE
 
-   PUBLIC   ssh_wzv    ! called by step.F90
    PUBLIC   ssh_nxt    ! called by step.F90
+   PUBLIC   wzv        ! called by step.F90
+   PUBLIC   ssh_swp    ! called by step.F90
 
    !! * Substitutions
@@ -57,97 +65,36 @@
 CONTAINS
 
-   SUBROUTINE ssh_wzv( kt ) 
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE ssh_wzv  ***
+   SUBROUTINE ssh_nxt( kt )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE ssh_nxt  ***
       !!                   
-      !! ** Purpose :   compute the after ssh (ssha), the now vertical velocity
-      !!              and update the now vertical coordinate (lk_vvl=T).
-      !!
-      !! ** Method  : - Using the incompressibility hypothesis, the vertical 
-      !!      velocity is computed by integrating the horizontal divergence  
-      !!      from the bottom to the surface minus the scale factor evolution.
-      !!        The boundary conditions are w=0 at the bottom (no flux) and.
+      !! ** Purpose :   compute the after ssh (ssha)
+      !!
+      !! ** Method  : - Using the incompressibility hypothesis, the ssh increment
+      !!      is computed by integrating the horizontal divergence and multiply by
+      !!      by the time step.
       !!
       !! ** action  :   ssha    : after sea surface height
-      !!                wn      : now vertical velocity
-      !!                sshu_a, sshv_a, sshf_a  : after sea surface height (lk_vvl=T)
-      !!                hu, hv, hur, hvr        : ocean depth and its inverse at u-,v-points
       !!
       !! Reference  : Leclair, M., and G. Madec, 2009, Ocean Modelling.
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! time step
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zcoefu, zcoefv, zcoeff, z2dt, z1_2dt, z1_rau0   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::  z2d, zhdiv
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  z3d
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('ssh_wzv')
-      !
-      CALL wrk_alloc( jpi, jpj, z2d, zhdiv ) 
+      !
+      REAL(wp), POINTER, DIMENSION(:,:  ) ::  zhdiv
+      INTEGER, INTENT(in) ::   kt                      ! time step
+      ! 
+      INTEGER             ::   jk                      ! dummy loop indice
+      REAL(wp)            ::   z2dt, z1_rau0           ! local scalars
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('ssh_nxt')
+      !
+      CALL wrk_alloc( jpi, jpj, zhdiv ) 
       !
       IF( kt == nit000 ) THEN
          !
          IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'ssh_wzv : after sea surface height and now vertical velocity '
+         IF(lwp) WRITE(numout,*) 'ssh_nxt : after sea surface height'
          IF(lwp) WRITE(numout,*) '~~~~~~~ '
          !
-         wn(:,:,jpk) = 0._wp                  ! bottom boundary condition: w=0 (set once for all)
-         !
-         IF( lk_vvl ) THEN                    ! before and now Sea SSH at u-, v-, f-points (vvl case only)
-            DO jj = 1, jpjm1
-               DO ji = 1, jpim1                    ! caution: use of Vector Opt. not possible
-                  zcoefu = 0.5  * umask(ji,jj,1) / ( e1u(ji,jj) * e2u(ji,jj) )
-                  zcoefv = 0.5  * vmask(ji,jj,1) / ( e1v(ji,jj) * e2v(ji,jj) )
-                  zcoeff = 0.25 * umask(ji,jj,1) * umask(ji,jj+1,1)
-                  sshu_b(ji,jj) = zcoefu * ( e1t(ji  ,jj) * e2t(ji  ,jj) * sshb(ji  ,jj)     &
-                     &                     + e1t(ji+1,jj) * e2t(ji+1,jj) * sshb(ji+1,jj) )
-                  sshv_b(ji,jj) = zcoefv * ( e1t(ji,jj  ) * e2t(ji,jj  ) * sshb(ji,jj  )     &
-                     &                     + e1t(ji,jj+1) * e2t(ji,jj+1) * sshb(ji,jj+1) )
-                  sshu_n(ji,jj) = zcoefu * ( e1t(ji  ,jj) * e2t(ji  ,jj) * sshn(ji  ,jj)     &
-                     &                     + e1t(ji+1,jj) * e2t(ji+1,jj) * sshn(ji+1,jj) )
-                  sshv_n(ji,jj) = zcoefv * ( e1t(ji,jj  ) * e2t(ji,jj  ) * sshn(ji,jj  )     &
-                     &                     + e1t(ji,jj+1) * e2t(ji,jj+1) * sshn(ji,jj+1) )
-               END DO
-            END DO
-            CALL lbc_lnk( sshu_b, 'U', 1. )   ;   CALL lbc_lnk( sshu_n, 'U', 1. )
-            CALL lbc_lnk( sshv_b, 'V', 1. )   ;   CALL lbc_lnk( sshv_n, 'V', 1. )
-            DO jj = 1, jpjm1
-               DO ji = 1, jpim1      ! NO Vector Opt.
-                  sshf_n(ji,jj) = 0.5  * umask(ji,jj,1) * umask(ji,jj+1,1)                   &
-                       &               / ( e1f(ji,jj  ) * e2f(ji,jj  ) )                     &
-                       &               * ( e1u(ji,jj  ) * e2u(ji,jj  ) * sshu_n(ji,jj  )     &
-                       &                 + e1u(ji,jj+1) * e2u(ji,jj+1) * sshu_n(ji,jj+1) )
-               END DO
-            END DO
-            CALL lbc_lnk( sshf_n, 'F', 1. )
-         ENDIF
-         !
-      ENDIF
-
-      !                                           !------------------------------------------!
-      IF( lk_vvl ) THEN                           !  Regridding: Update Now Vertical coord.  !   (only in vvl case)
-         !                                        !------------------------------------------!
-         DO jk = 1, jpkm1
-            fsdept(:,:,jk) = fsdept_n(:,:,jk)         ! now local depths stored in fsdep. arrays
-            fsdepw(:,:,jk) = fsdepw_n(:,:,jk)
-            fsde3w(:,:,jk) = fsde3w_n(:,:,jk)
-            !
-            fse3t (:,:,jk) = fse3t_n (:,:,jk)         ! vertical scale factors stored in fse3. arrays
-            fse3u (:,:,jk) = fse3u_n (:,:,jk)
-            fse3v (:,:,jk) = fse3v_n (:,:,jk)
-            fse3f (:,:,jk) = fse3f_n (:,:,jk)
-            fse3w (:,:,jk) = fse3w_n (:,:,jk)
-            fse3uw(:,:,jk) = fse3uw_n(:,:,jk)
-            fse3vw(:,:,jk) = fse3vw_n(:,:,jk)
-         END DO
-         !
-         hu(:,:) = hu_0(:,:) + sshu_n(:,:)            ! now ocean depth (at u- and v-points)
-         hv(:,:) = hv_0(:,:) + sshv_n(:,:)
-         !                                            ! now masked inverse of the ocean depth (at u- and v-points)
-         hur(:,:) = umask(:,:,1) / ( hu(:,:) + 1._wp - umask(:,:,1) )
-         hvr(:,:) = vmask(:,:,1) / ( hv(:,:) + 1._wp - vmask(:,:,1) )
-         ! 
       ENDIF
       !
@@ -162,10 +109,10 @@
       zhdiv(:,:) = 0._wp
       DO jk = 1, jpkm1                                 ! Horizontal divergence of barotropic transports
-        zhdiv(:,:) = zhdiv(:,:) + fse3t(:,:,jk) * hdivn(:,:,jk)
+        zhdiv(:,:) = zhdiv(:,:) + fse3t_n(:,:,jk) * hdivn(:,:,jk)
       END DO
       !                                                ! Sea surface elevation time stepping
       ! In forward Euler time stepping case, the same formulation as in the leap-frog case can be used
       ! because emp_b field is initialized with the vlaues of emp field. Hence, 0.5 * ( emp + emp_b ) = emp
-      z1_rau0 = 0.5 / rau0
+      z1_rau0 = 0.5_wp * r1_rau0
       ssha(:,:) = (  sshb(:,:) - z2dt * ( z1_rau0 * ( emp_b(:,:) + emp(:,:) ) + zhdiv(:,:) )  ) * tmask(:,:,1)
 
@@ -180,7 +127,13 @@
 #endif
 #if defined key_bdy
-      ssha(:,:) = ssha(:,:) * bdytmask(:,:)
-      CALL lbc_lnk( ssha, 'T', 1. )                    ! absolutly compulsory !! (jmm)
-#endif
+      ! bg jchanut tschanges
+      ! These lines are not necessary with time splitting since
+      ! boundary condition on sea level is set during ts loop
+      IF (lk_bdy) THEN
+         CALL lbc_lnk( ssha, 'T', 1. ) ! Not sure that's necessary
+         CALL bdy_ssh( ssha ) ! Duplicate sea level across open boundaries
+      ENDIF
+#endif
+      ! end jchanut tschanges
 #if defined key_asminc
       !                                                ! Include the IAU weighted SSH increment
@@ -190,43 +143,104 @@
       ENDIF
 #endif
-      !                                                ! Sea Surface Height at u-,v- and f-points (vvl case only)
-      IF( lk_vvl ) THEN                                ! (required only in key_vvl case)
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1      ! NO Vector Opt.
-               sshu_a(ji,jj) = 0.5  * umask(ji,jj,1) / ( e1u(ji  ,jj) * e2u(ji  ,jj) )                   &
-                  &                                  * ( e1t(ji  ,jj) * e2t(ji  ,jj) * ssha(ji  ,jj)     &
-                  &                                    + e1t(ji+1,jj) * e2t(ji+1,jj) * ssha(ji+1,jj) )
-               sshv_a(ji,jj) = 0.5  * vmask(ji,jj,1) / ( e1v(ji,jj  ) * e2v(ji,jj  ) )                   &
-                  &                                  * ( e1t(ji,jj  ) * e2t(ji,jj  ) * ssha(ji,jj  )     &
-                  &                                    + e1t(ji,jj+1) * e2t(ji,jj+1) * ssha(ji,jj+1) )
+
+      !                                           !------------------------------!
+      !                                           !           outputs            !
+      !                                           !------------------------------!
+      CALL iom_put( "ssh" , sshn                  )   ! sea surface height
+      CALL iom_put( "ssh2", sshn(:,:) * sshn(:,:) )   ! square of sea surface height
+      !
+      IF(ln_ctl)   CALL prt_ctl( tab2d_1=ssha, clinfo1=' ssha  - : ', mask1=tmask, ovlap=1 )
+      !
+      CALL wrk_dealloc( jpi, jpj, zhdiv ) 
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('ssh_nxt')
+      !
+   END SUBROUTINE ssh_nxt
+
+   
+   SUBROUTINE wzv( kt )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE wzv  ***
+      !!                   
+      !! ** Purpose :   compute the now vertical velocity
+      !!
+      !! ** Method  : - Using the incompressibility hypothesis, the vertical 
+      !!      velocity is computed by integrating the horizontal divergence  
+      !!      from the bottom to the surface minus the scale factor evolution.
+      !!        The boundary conditions are w=0 at the bottom (no flux) and.
+      !!
+      !! ** action  :   wn      : now vertical velocity
+      !!
+      !! Reference  : Leclair, M., and G. Madec, 2009, Ocean Modelling.
+      !!----------------------------------------------------------------------
+      !
+      INTEGER, INTENT(in) ::   kt           ! time step
+      REAL(wp), POINTER, DIMENSION(:,:  ) ::  z2d
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::  z3d, zhdiv
+      !
+      INTEGER             ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp)            ::   z1_2dt       ! local scalars
+      !!----------------------------------------------------------------------
+      
+      IF( nn_timing == 1 )  CALL timing_start('wzv')
+      !
+      IF( kt == nit000 ) THEN
+         !
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'wzv : now vertical velocity '
+         IF(lwp) WRITE(numout,*) '~~~~~ '
+         !
+         wn(:,:,jpk) = 0._wp                  ! bottom boundary condition: w=0 (set once for all)
+         !
+      ENDIF
+      !                                           !------------------------------!
+      !                                           !     Now Vertical Velocity    !
+      !                                           !------------------------------!
+      z1_2dt = 1. / ( 2. * rdt )                         ! set time step size (Euler/Leapfrog)
+      IF( neuler == 0 .AND. kt == nit000 )   z1_2dt = 1. / rdt
+      !
+      IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN      ! z_tilde and layer cases
+         CALL wrk_alloc( jpi, jpj, jpk, zhdiv ) 
+         !
+         DO jk = 1, jpkm1
+            ! horizontal divergence of thickness diffusion transport ( velocity multiplied by e3t)
+            ! - ML - note: computation allready done in dom_vvl_sf_nxt. Could be optimized (not critical and clearer this way)
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zhdiv(ji,jj,jk) = r1_e12t(ji,jj) * ( un_td(ji,jj,jk) - un_td(ji-1,jj,jk) + vn_td(ji,jj,jk) - vn_td(ji,jj-1,jk) )
+               END DO
             END DO
          END DO
-         CALL lbc_lnk( sshu_a, 'U', 1. )   ;   CALL lbc_lnk( sshv_a, 'V', 1. )      ! Boundaries conditions
-      ENDIF
-
-      !                                           !------------------------------!
-      !                                           !     Now Vertical Velocity    !
-      !                                           !------------------------------!
-      z1_2dt = 1.e0 / z2dt
-      DO jk = jpkm1, 1, -1                             ! integrate from the bottom the hor. divergence
-         ! - ML - need 3 lines here because replacement of fse3t by its expression yields too long lines otherwise
-         wn(:,:,jk) = wn(:,:,jk+1) -   fse3t_n(:,:,jk) * hdivn(:,:,jk)        &
-            &                      - ( fse3t_a(:,:,jk) - fse3t_b(:,:,jk) )    &
-            &                         * tmask(:,:,jk) * z1_2dt
+         CALL lbc_lnk(zhdiv, 'T', 1.)  ! - ML - Perhaps not necessary: not used for horizontal "connexions"
+         !                             ! Is it problematic to have a wrong vertical velocity in boundary cells?
+         !                             ! Same question holds for hdivn. Perhaps just for security
+         DO jk = jpkm1, 1, -1                       ! integrate from the bottom the hor. divergence
+            ! computation of w
+            wn(:,:,jk) = wn(:,:,jk+1) - (   fse3t_n(:,:,jk) * hdivn(:,:,jk) + zhdiv(:,:,jk)                    &
+               &                          + z1_2dt * ( fse3t_a(:,:,jk) - fse3t_b(:,:,jk) ) ) * tmask(:,:,jk)
+         END DO
+         !          IF( ln_vvl_layer ) wn(:,:,:) = 0.e0
+         CALL wrk_dealloc( jpi, jpj, jpk, zhdiv ) 
+      ELSE   ! z_star and linear free surface cases
+         DO jk = jpkm1, 1, -1                       ! integrate from the bottom the hor. divergence
+            ! computation of w
+            wn(:,:,jk) = wn(:,:,jk+1) - (   fse3t_n(:,:,jk) * hdivn(:,:,jk)                                   &
+               &                          + z1_2dt * ( fse3t_a(:,:,jk) - fse3t_b(:,:,jk) ) ) * tmask(:,:,jk)
+         END DO
+      ENDIF
+
 #if defined key_bdy
          wn(:,:,jk) = wn(:,:,jk) * bdytmask(:,:)
 #endif
-      END DO
-
+      !
       !                                           !------------------------------!
       !                                           !           outputs            !
       !                                           !------------------------------!
-      CALL iom_put( "woce", wn                    )   ! vertical velocity
-      CALL iom_put( "ssh" , sshn                  )   ! sea surface height
-      CALL iom_put( "ssh2", sshn(:,:) * sshn(:,:) )   ! square of sea surface height
+      CALL iom_put( "woce", wn )   ! vertical velocity
       IF( lk_diaar5 ) THEN                            ! vertical mass transport & its square value
+         CALL wrk_alloc( jpi, jpj, z2d ) 
+         CALL wrk_alloc( jpi, jpj, jpk, z3d ) 
          ! Caution: in the VVL case, it only correponds to the baroclinic mass transport.
-         CALL wrk_alloc( jpi,jpj,jpk, z3d )
-         z2d(:,:) = rau0 * e1t(:,:) * e2t(:,:)
+         z2d(:,:) = rau0 * e12t(:,:)
          DO jk = 1, jpk
             z3d(:,:,jk) = wn(:,:,jk) * z2d(:,:)
@@ -234,17 +248,14 @@
          CALL iom_put( "w_masstr" , z3d                     )  
          CALL iom_put( "w_masstr2", z3d(:,:,:) * z3d(:,:,:) )
-         CALL wrk_dealloc( jpi,jpj,jpk, z3d )
-      ENDIF
-      !
-      IF(ln_ctl)   CALL prt_ctl( tab2d_1=ssha, clinfo1=' ssha  - : ', mask1=tmask, ovlap=1 )
-      !
-      CALL wrk_dealloc( jpi, jpj, z2d, zhdiv ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('ssh_wzv')
-      !
-   END SUBROUTINE ssh_wzv
-
-
-   SUBROUTINE ssh_nxt( kt )
+         CALL wrk_dealloc( jpi, jpj, z2d  ) 
+         CALL wrk_dealloc( jpi, jpj, jpk, z3d ) 
+      ENDIF
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('wzv')
+
+
+   END SUBROUTINE wzv
+
+   SUBROUTINE ssh_swp( kt )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE ssh_nxt  ***
@@ -252,5 +263,5 @@
       !! ** Purpose :   achieve the sea surface  height time stepping by 
       !!              applying Asselin time filter and swapping the arrays
-      !!              ssha  already computed in ssh_wzv  
+      !!              ssha  already computed in ssh_nxt  
       !!
       !! ** Method  : - apply Asselin time fiter to now ssh (excluding the forcing
@@ -266,86 +277,25 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
-      !!
-      INTEGER  ::   ji, jj   ! dummy loop indices
-      REAL(wp) ::   zec      ! temporary scalar
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('ssh_nxt')
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('ssh_swp')
       !
       IF( kt == nit000 ) THEN
          IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'ssh_nxt : next sea surface height (Asselin time filter + swap)'
+         IF(lwp) WRITE(numout,*) 'ssh_swp : Asselin time filter and swap of sea surface height'
          IF(lwp) WRITE(numout,*) '~~~~~~~ '
       ENDIF
 
-      !                       !--------------------------!
-      IF( lk_vvl ) THEN       !  Variable volume levels  !     (ssh at t-, u-, v, f-points)
-         !                    !--------------------------!
-         !
-         IF( neuler == 0 .AND. kt == nit000 ) THEN    !** Euler time-stepping at first time-step : no filter
-            sshn  (:,:) = ssha  (:,:)                       ! now <-- after  (before already = now)
-            sshu_n(:,:) = sshu_a(:,:)
-            sshv_n(:,:) = sshv_a(:,:)
-            DO jj = 1, jpjm1                                ! ssh now at f-point
-               DO ji = 1, jpim1      ! NO Vector Opt.
-                  sshf_n(ji,jj) = 0.5  * umask(ji,jj,1) * umask(ji,jj+1,1)                 &
-                     &               / ( e1f(ji,jj  ) * e2f(ji,jj  ) )                     &
-                     &               * ( e1u(ji,jj  ) * e2u(ji,jj  ) * sshu_n(ji,jj  )     &
-                     &                 + e1u(ji,jj+1) * e2u(ji,jj+1) * sshu_n(ji,jj+1) )
-               END DO
-            END DO
-            CALL lbc_lnk( sshf_n, 'F', 1. )                 ! Boundaries conditions
-            !
-         ELSE                                         !** Leap-Frog time-stepping: Asselin filter + swap
-            zec = atfp * rdt / rau0
-            DO jj = 1, jpj
-               DO ji = 1, jpi                               ! before <-- now filtered
-                  sshb  (ji,jj) = sshn  (ji,jj) + atfp * ( sshb(ji,jj) - 2 * sshn(ji,jj) + ssha(ji,jj) )   &
-                     &                          - zec  * ( emp_b(ji,jj) - emp(ji,jj) ) * tmask(ji,jj,1)
-                  sshn  (ji,jj) = ssha  (ji,jj)             ! now <-- after
-                  sshu_n(ji,jj) = sshu_a(ji,jj)
-                  sshv_n(ji,jj) = sshv_a(ji,jj)
-               END DO
-            END DO
-            DO jj = 1, jpjm1                                ! ssh now at f-point
-               DO ji = 1, jpim1      ! NO Vector Opt.
-                  sshf_n(ji,jj) = 0.5  * umask(ji,jj,1) * umask(ji,jj+1,1)                 &
-                     &               / ( e1f(ji,jj  ) * e2f(ji,jj  ) )                     &
-                     &               * ( e1u(ji,jj  ) * e2u(ji,jj  ) * sshu_n(ji,jj  )     &
-                     &                 + e1u(ji,jj+1) * e2u(ji,jj+1) * sshu_n(ji,jj+1) )
-               END DO
-            END DO
-            CALL lbc_lnk( sshf_n, 'F', 1. )                 ! Boundaries conditions
-            !
-            DO jj = 1, jpjm1                                ! ssh before at u- & v-points
-               DO ji = 1, jpim1      ! NO Vector Opt.
-                  sshu_b(ji,jj) = 0.5  * umask(ji,jj,1) / ( e1u(ji  ,jj) * e2u(ji  ,jj) )                   &
-                     &                                  * ( e1t(ji  ,jj) * e2t(ji  ,jj) * sshb(ji  ,jj)     &
-                     &                                    + e1t(ji+1,jj) * e2t(ji+1,jj) * sshb(ji+1,jj) )
-                  sshv_b(ji,jj) = 0.5  * vmask(ji,jj,1) / ( e1v(ji,jj  ) * e2v(ji,jj  ) )                   &
-                     &                                  * ( e1t(ji,jj  ) * e2t(ji,jj  ) * sshb(ji,jj  )     &
-                     &                                    + e1t(ji,jj+1) * e2t(ji,jj+1) * sshb(ji,jj+1) )
-               END DO
-            END DO
-            CALL lbc_lnk( sshu_b, 'U', 1. )
-            CALL lbc_lnk( sshv_b, 'V', 1. )            !  Boundaries conditions
-            !
-         ENDIF
-         !                    !--------------------------!
-      ELSE                    !        fixed levels      !     (ssh at t-point only)
-         !                    !--------------------------!
-         !
-         IF( neuler == 0 .AND. kt == nit000 ) THEN    !** Euler time-stepping at first time-step : no filter
-            sshn(:,:) = ssha(:,:)                           ! now <-- after  (before already = now)
-            !
-         ELSE                                               ! Leap-Frog time-stepping: Asselin filter + swap
-            DO jj = 1, jpj
-               DO ji = 1, jpi                               ! before <-- now filtered
-                  sshb(ji,jj) = sshn(ji,jj) + atfp * ( sshb(ji,jj) - 2 * sshn(ji,jj) + ssha(ji,jj) )
-                  sshn(ji,jj) = ssha(ji,jj)                 ! now <-- after
-               END DO
-            END DO
-         ENDIF
-         !
+# if defined key_dynspg_ts
+      IF( ( neuler == 0 .AND. kt == nit000 ) .OR. ln_bt_fw ) THEN    !** Euler time-stepping: no filter
+# else
+      IF ( neuler == 0 .AND. kt == nit000 ) THEN   !** Euler time-stepping at first time-step : no filter
+#endif
+         sshb(:,:) = sshn(:,:)                           ! before <-- now
+         sshn(:,:) = ssha(:,:)                           ! now    <-- after  (before already = now)
+      ELSE                                         !** Leap-Frog time-stepping: Asselin filter + swap
+         sshb(:,:) = sshn(:,:) + atfp * ( sshb(:,:) - 2 * sshn(:,:) + ssha(:,:) )     ! before <-- now filtered
+         IF( lk_vvl ) sshb(:,:) = sshb(:,:) - atfp * rdt / rau0 * ( emp_b(:,:) - emp(:,:) ) * tmask(:,:,1)
+         sshn(:,:) = ssha(:,:)                           ! now <-- after
       ENDIF
       !
@@ -357,7 +307,7 @@
       IF(ln_ctl)   CALL prt_ctl( tab2d_1=sshb, clinfo1=' sshb  - : ', mask1=tmask, ovlap=1 )
       !
-      IF( nn_timing == 1 )  CALL timing_stop('ssh_nxt')
-      !
-   END SUBROUTINE ssh_nxt
+      IF( nn_timing == 1 )  CALL timing_stop('ssh_swp')
+      !
+   END SUBROUTINE ssh_swp
 
    !!======================================================================
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 4292)
@@ -136,8 +136,8 @@
 
       ! vertical grid definition
-      CALL iom_set_axis_attr( "deptht", gdept_0 )
-      CALL iom_set_axis_attr( "depthu", gdept_0 )
-      CALL iom_set_axis_attr( "depthv", gdept_0 )
-      CALL iom_set_axis_attr( "depthw", gdepw_0 )
+      CALL iom_set_axis_attr( "deptht", gdept_1d )
+      CALL iom_set_axis_attr( "depthu", gdept_1d )
+      CALL iom_set_axis_attr( "depthv", gdept_1d )
+      CALL iom_set_axis_attr( "depthw", gdepw_1d )
 # if defined key_floats
       CALL iom_set_axis_attr( "nfloat", (/ (REAL(ji,wp), ji=1,nfloat) /) )
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom_ioipsl.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom_ioipsl.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom_ioipsl.F90	(revision 4292)
@@ -408,5 +408,5 @@
                CALL flioputv( ioipslid, 'nav_lon'     , glamt(ix1:ix2, iy1:iy2) )
                CALL flioputv( ioipslid, 'nav_lat'     , gphit(ix1:ix2, iy1:iy2) )
-               CALL flioputv( ioipslid, 'nav_lev'     , gdept_0 )
+               CALL flioputv( ioipslid, 'nav_lev'     , gdept_1d )
                ! +++ WRONG VALUE: to be improved but not really useful...
                CALL flioputv( ioipslid, 'time_counter', kt )
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 4292)
@@ -532,5 +532,5 @@
                CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, gphit(ix1:ix2, iy1:iy2) ), clinfo)
                CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'nav_lev'     , idmy ), clinfo)
-               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, gdept_0                 ), clinfo)
+               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, gdept_1d                ), clinfo)
                ! +++ WRONG VALUE: to be improved but not really useful...
                CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'time_counter', idmy ), clinfo)
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 4292)
@@ -23,5 +23,4 @@
    USE eosbn2          ! equation of state            (eos bn2 routine)
    USE trdmld_oce      ! ocean active mixed layer tracers trends variables
-   USE domvvl          ! variable volume
    USE divcur          ! hor. divergence and curl      (div & cur routines)
    USE sbc_ice, ONLY : lk_lim3
@@ -30,7 +29,8 @@
    PRIVATE
 
-   PUBLIC   rst_opn    ! routine called by step module
-   PUBLIC   rst_write  ! routine called by step module
-   PUBLIC   rst_read   ! routine called by opa  module
+   PUBLIC   rst_opn         ! routine called by step module
+   PUBLIC   rst_write       ! routine called by step module
+   PUBLIC   rst_read        ! routine called by istate module
+   PUBLIC   rst_read_open   ! routine called in rst_read and (possibly) in dom_vvl_init
 
    !! * Substitutions
@@ -120,5 +120,4 @@
                      CALL iom_rstput( kt, nitrst, numrow, 'hdivb'  , hdivb     )
                      CALL iom_rstput( kt, nitrst, numrow, 'sshb'   , sshb      )
-      IF( lk_vvl )   CALL iom_rstput( kt, nitrst, numrow, 'fse3t_b', fse3t_b(:,:,:) )
                      !
                      CALL iom_rstput( kt, nitrst, numrow, 'un'     , un        )     ! now fields
@@ -144,4 +143,37 @@
    END SUBROUTINE rst_write
 
+   SUBROUTINE rst_read_open
+      !!---------------------------------------------------------------------- 
+      !!                   ***  ROUTINE rst_read_open  ***
+      !! 
+      !! ** Purpose :   Open read files for restart (format fixed by jprstlib )
+      !! 
+      !! ** Method  :   Use a non-zero, positive value of numror to assess whether or not
+      !!                the file has already been opened
+      !!----------------------------------------------------------------------
+      INTEGER  ::   jlibalt = jprstlib
+      LOGICAL  ::   llok
+      !!----------------------------------------------------------------------
+
+      IF( numror .LE. 0 ) THEN
+         IF(lwp) THEN                                             ! Contol prints
+            WRITE(numout,*)
+            SELECT CASE ( jprstlib )
+            CASE ( jpnf90    )   ;   WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
+            CASE ( jprstdimg )   ;   WRITE(numout,*) 'rst_read : read oce binary restart file'
+            END SELECT
+            IF ( snc4set%luse )      WRITE(numout,*) 'rst_read : configured with NetCDF4 support'
+            WRITE(numout,*) '~~~~~~~~'
+         ENDIF
+
+         IF ( jprstlib == jprstdimg ) THEN
+           ! eventually read netcdf file (monobloc)  for restarting on different number of processors
+           ! if {cn_ocerst_in}.nc exists, then set jlibalt to jpnf90
+           INQUIRE( FILE = TRIM(cn_ocerst_in)//'.nc', EXIST = llok )
+           IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
+         ENDIF
+         CALL iom_open( cn_ocerst_in, numror, kiolib = jlibalt )
+      ENDIF
+   END SUBROUTINE rst_read_open
 
    SUBROUTINE rst_read
@@ -154,25 +186,9 @@
       !!----------------------------------------------------------------------
       REAL(wp) ::   zrdt, zrdttra1
-      INTEGER  ::   jk, jlibalt = jprstlib
+      INTEGER  ::   jk
       LOGICAL  ::   llok
       !!----------------------------------------------------------------------
 
-      IF(lwp) THEN                                             ! Contol prints
-         WRITE(numout,*)
-         SELECT CASE ( jprstlib )
-         CASE ( jpnf90    )   ;   WRITE(numout,*) 'rst_read : read oce NetCDF restart file ',TRIM(cn_ocerst_in)//'.nc'
-         CASE ( jprstdimg )   ;   WRITE(numout,*) 'rst_read : read oce binary restart file'
-         END SELECT
-         IF ( snc4set%luse )      WRITE(numout,*) 'rst_read : configured with NetCDF4 support'
-         WRITE(numout,*) '~~~~~~~~'
-      ENDIF
-
-      IF ( jprstlib == jprstdimg ) THEN
-        ! eventually read netcdf file (monobloc)  for restarting on different number of processors
-        ! if {cn_ocerst_in}.nc exists, then set jlibalt to jpnf90
-        INQUIRE( FILE = TRIM(cn_ocerst_in)//'.nc', EXIST = llok )
-        IF ( llok ) THEN ; jlibalt = jpnf90  ; ELSE ; jlibalt = jprstlib ; ENDIF
-      ENDIF
-      CALL iom_open( cn_ocerst_in, numror, kiolib = jlibalt )
+      CALL rst_read_open           ! open restart for reading (if not already opened)
 
       ! Check dynamics and tracer time-step consistency and force Euler restart if changed
@@ -194,5 +210,4 @@
          CALL iom_get( numror, jpdom_autoglo, 'hdivb'  , hdivb   )
          CALL iom_get( numror, jpdom_autoglo, 'sshb'   , sshb    )
-         IF( lk_vvl )   CALL iom_get( numror, jpdom_autoglo, 'fse3t_b', fse3t_b(:,:,:) )
       ELSE
          neuler = 0
@@ -230,9 +245,4 @@
          hdivb(:,:,:)   = hdivn(:,:,:)
          sshb (:,:)     = sshn (:,:)
-         IF( lk_vvl ) THEN
-            DO jk = 1, jpk
-               fse3t_b(:,:,jk) = fse3t_n(:,:,jk)
-            END DO
-         ENDIF
       ENDIF
       !
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn.F90	(revision 4292)
@@ -191,6 +191,6 @@
       !!----------------------------------------------------------------------
 
-      zm00 = TANH( ( pdam - gdept_0(1    ) ) / pwam )
-      zm01 = TANH( ( pdam - gdept_0(jpkm1) ) / pwam )
+      zm00 = TANH( ( pdam - gdept_1d(1    ) ) / pwam )
+      zm01 = TANH( ( pdam - gdept_1d(jpkm1) ) / pwam )
       zmhs = zm00 / zm01
       zmhb = ( 1.e0 - pbot ) / ( 1.e0 - zmhs ) / zm01
@@ -232,6 +232,6 @@
       !!----------------------------------------------------------------------
 
-      zm00 = TANH( ( pdam - gdept_0(1    ) ) / pwam )
-      zm01 = TANH( ( pdam - gdept_0(jpkm1) ) / pwam )
+      zm00 = TANH( ( pdam - gdept_1d(1    ) ) / pwam )
+      zm01 = TANH( ( pdam - gdept_1d(jpkm1) ) / pwam )
       zmhs = zm00 / zm01
       zmhb = ( 1.e0 - pbot ) / ( 1.e0 - zmhs ) / zm01
@@ -274,6 +274,6 @@
       !!----------------------------------------------------------------------
 
-      zm00 = TANH( ( pdam - gdept_0(1    ) ) / pwam )   
-      zm01 = TANH( ( pdam - gdept_0(jpkm1) ) / pwam )
+      zm00 = TANH( ( pdam - gdept_1d(1    ) ) / pwam )   
+      zm01 = TANH( ( pdam - gdept_1d(jpkm1) ) / pwam )
       zmhs = zm00 / zm01
       zmhb = ( 1.e0 - pbot ) / ( 1.e0 - zmhs ) / zm01
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn_c3d.h90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn_c3d.h90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn_c3d.h90	(revision 4292)
@@ -386,5 +386,5 @@
 
       DO jk=1, jpk
-         zcoef(jk) = 1.0_wp + NINT(9.0_wp*(gdept_0(jk)-800.0_wp)/(3000.0_wp-800.0_wp))
+         zcoef(jk) = 1.0_wp + NINT(9.0_wp*(gdept_1d(jk)-800.0_wp)/(3000.0_wp-800.0_wp))
          zcoef(jk) = MIN(10.0_wp, MAX(1.0_wp, zcoef(jk)))
          IF(lwp) WRITE(numout,'(4x,i3,6x,f7.3)') jk,zcoef(jk)
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 4292)
@@ -976,5 +976,5 @@
       USE dom_oce, ONLY : &             ! Ocean space and time domain variables
          & rdt,           &                       
-         & gdept_0,       &             
+         & gdept_1d,       &             
          & tmask, umask, vmask                            
       USE phycst, ONLY : &              ! Physical constants
@@ -1038,5 +1038,5 @@
                   &              kstp, jpi, jpj, jpk, nit000, idaystp,   &
                   &              tsn(:,:,:,jp_tem), tsn(:,:,:,jp_sal),   &
-                  &              gdept_0, tmask, n1dint, n2dint,         &
+                  &              gdept_1d, tmask, n1dint, n2dint,        &
                   &              kdailyavtypes = endailyavtypes )
             ELSE
@@ -1044,5 +1044,5 @@
                   &              kstp, jpi, jpj, jpk, nit000, idaystp,   &
                   &              tsn(:,:,:,jp_tem), tsn(:,:,:,jp_sal),   &
-                  &              gdept_0, tmask, n1dint, n2dint               )
+                  &              gdept_1d, tmask, n1dint, n2dint              )
             ENDIF
          END DO
@@ -1088,5 +1088,5 @@
            ! zonal component of velocity
            CALL obs_vel_opt( veldatqc(jveloset), kstp, jpi, jpj, jpk, &
-              &              nit000, idaystp, un, vn, gdept_0, umask, vmask, &
+              &              nit000, idaystp, un, vn, gdept_1d, umask, vmask, &
                              n1dint, n2dint, ld_velav(jveloset) )
          END DO
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90	(revision 4292)
@@ -75,5 +75,5 @@
          & glamt,   &
          & gphit,   &
-         & gdept_0, &
+         & gdept_1d,&
          & tmask,   &
          & nproc
@@ -193,5 +193,5 @@
          &                 profdata%var(1)%vdep,                        &
          &                 glamt,                 gphit,                &
-         &                 gdept_0,               tmask,                &
+         &                 gdept_1d,              tmask,                &
          &                 profdata%nqc,          profdata%var(1)%nvqc, &
          &                 iosdtobs,              ilantobs,             &
@@ -213,5 +213,5 @@
          &                 profdata%var(2)%vdep,                        &
          &                 glamt,                 gphit,                &
-         &                 gdept_0,               tmask,                &
+         &                 gdept_1d,              tmask,                &
          &                 profdata%nqc,          profdata%var(2)%nvqc, &
          &                 iosdsobs,              ilansobs,             &
@@ -916,5 +916,5 @@
          & glamt, glamu, glamv,    &
          & gphit, gphiu, gphiv,    &
-         & gdept_0, &
+         & gdept_1d,             &
          & tmask, umask, vmask,  &
          & nproc
@@ -1032,5 +1032,5 @@
          &                 profdata%var(1)%vdep,                        &
          &                 glamu,                 gphiu,                &
-         &                 gdept_0,               umask,                &
+         &                 gdept_1d,              umask,                &
          &                 profdata%nqc,          profdata%var(1)%nvqc, &
          &                 iosduobs,              ilanuobs,             &
@@ -1052,5 +1052,5 @@
          &                 profdata%var(2)%vdep,                        &
          &                 glamv,                 gphiv,                &
-         &                 gdept_0,               vmask,                &
+         &                 gdept_1d,              vmask,                &
          &                 profdata%nqc,          profdata%var(2)%nvqc, &
          &                 iosdvobs,              ilanvobs,             &
@@ -1709,5 +1709,5 @@
       !! * Modules used
       USE dom_oce, ONLY : &       ! Geographical information
-         & gdepw_0                        
+         & gdepw_1d                        
 
       !! * Arguments
@@ -1826,5 +1826,5 @@
                &  .OR. ( pobsphi(jobs) >   90.         )       &
                &  .OR. ( pobsdep(jobsp) < 0.0          )       &
-               &  .OR. ( pobsdep(jobsp) > gdepw_0(kpk) ) ) THEN
+               &  .OR. ( pobsdep(jobsp) > gdepw_1d(kpk)) ) THEN
                kobsqc(jobsp) = kobsqc(jobsp) + 11
                kosdobs = kosdobs + 1
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_prof.F90	(revision 4292)
@@ -793,10 +793,10 @@
       !-----------------------------------------------------------------------
       IF ( ldt3d ) THEN
-         CALL obs_level_search( jpk, gdept_0, &
+         CALL obs_level_search( jpk, gdept_1d, &
             & profdata%nvprot(1), profdata%var(1)%vdep, &
             & profdata%var(1)%mvk )
       ENDIF
       IF ( lds3d ) THEN
-         CALL obs_level_search( jpk, gdept_0, &
+         CALL obs_level_search( jpk, gdept_1d, &
             & profdata%nvprot(2), profdata%var(2)%vdep, &
             & profdata%var(2)%mvk )
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_vel.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_vel.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_vel.F90	(revision 4292)
@@ -614,8 +614,8 @@
       ! Model level search
       !-----------------------------------------------------------------------
-      CALL obs_level_search( jpk, gdept_0, &
+      CALL obs_level_search( jpk, gdept_1d,          &
          & profdata%nvprot(1), profdata%var(1)%vdep, &
          & profdata%var(1)%mvk )
-      CALL obs_level_search( jpk, gdept_0, &
+      CALL obs_level_search( jpk, gdept_1d,          &
          & profdata%nvprot(2), profdata%var(2)%vdep, &
          & profdata%var(2)%mvk )
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90	(revision 4292)
@@ -100,4 +100,5 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sss_m     !: mean (nn_fsbc time-step) surface sea salinity            [psu]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ssh_m     !: mean (nn_fsbc time-step) sea surface height                [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   e3t_m     !: mean (nn_fsbc time-step) sea surface height                [m]
 
    !! * Substitutions
@@ -114,5 +115,5 @@
       !!                  ***  FUNCTION sbc_oce_alloc  ***
       !!---------------------------------------------------------------------
-      INTEGER :: ierr(4)
+      INTEGER :: ierr(5)
       !!---------------------------------------------------------------------
       ierr(:) = 0
@@ -135,4 +136,8 @@
          &      ssu_m  (jpi,jpj) , sst_m(jpi,jpj) ,                       &
          &      ssv_m  (jpi,jpj) , sss_m  (jpi,jpj), ssh_m(jpi,jpj) , STAT=ierr(4) )
+         !
+#if defined key_vvl
+      ALLOCATE( e3t_m(jpi,jpj) , STAT=ierr(5) )
+#endif
          !
       sbc_oce_alloc = MAXVAL( ierr )
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90	(revision 4292)
@@ -412,5 +412,5 @@
 ! Freezing/melting potential
 ! Calculated over NEMO leapfrog timestep (hence 2*dt)
-      nfrzmlt(:,:)=rau0*rcp*fse3t_m(:,:,1)*(Tocnfrz-sst_m(:,:))/(2.0*dt)
+      nfrzmlt(:,:)=rau0*rcp*fse3t_m(:,:)*(Tocnfrz-sst_m(:,:))/(2.0*dt)
 
       ztmp(:,:) = nfrzmlt(:,:)
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90	(revision 4292)
@@ -388,5 +388,5 @@
          IF( rn_hrnf > 0._wp ) THEN
             nkrnf = 2
-            DO WHILE( nkrnf /= jpkm1 .AND. gdepw_0(nkrnf+1) < rn_hrnf )   ;   nkrnf = nkrnf + 1   ;   END DO
+            DO WHILE( nkrnf /= jpkm1 .AND. gdepw_1d(nkrnf+1) < rn_hrnf )   ;   nkrnf = nkrnf + 1   ;   END DO
             IF( ln_sco )   CALL ctl_warn( 'sbc_rnf: number of levels over which Kz is increased is computed for zco...' )
          ENDIF
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90	(revision 4292)
@@ -26,8 +26,8 @@
    PUBLIC   sbc_ssm         ! routine called by step.F90
    PUBLIC   sbc_ssm_init    ! routine called by sbcmod.F90
-   
+
    LOGICAL, SAVE  ::   l_ssm_mean = .FALSE.       ! keep track of whether means have been read
                                                   ! from restart file
-
+   
    !! * Substitutions
 #  include "domzgr_substitute.h90"
@@ -67,5 +67,6 @@
          ELSE                    ;   ssh_m(:,:) = sshn(:,:)
          ENDIF
-
+         !
+         IF( lk_vvl )   fse3t_m(:,:) = fse3t_n(:,:,1)
          !
       ELSE
@@ -84,4 +85,5 @@
             ELSE                    ;   ssh_m(:,:) = zcoef *   sshn(:,:)
             ENDIF
+            IF( lk_vvl )   fse3t_m(:,:) = zcoef * fse3t_n(:,:,1)
             !                                             ! ---------------------------------------- !
          ELSEIF( MOD( kt - 2 , nn_fsbc ) == 0 ) THEN      !   Initialisation: New mean computation   !
@@ -92,4 +94,5 @@
             sss_m(:,:) = 0.e0
             ssh_m(:,:) = 0.e0
+            IF( lk_vvl )   fse3t_m(:,:) = 0.e0
          ENDIF
          !                                                ! ---------------------------------------- !
@@ -104,4 +107,5 @@
          ELSE                    ;   ssh_m(:,:) = ssh_m(:,:) + sshn(:,:)
          ENDIF
+         IF( lk_vvl )   fse3t_m(:,:) = fse3t_m(:,:) + fse3t_n(:,:,1)
 
          !                                                ! ---------------------------------------- !
@@ -114,4 +118,5 @@
             ssv_m(:,:) = ssv_m(:,:) * zcoef           !
             ssh_m(:,:) = ssh_m(:,:) * zcoef           ! mean SSH             [m]
+            IF( lk_vvl )   fse3t_m(:,:) = fse3t_m(:,:) * zcoef   ! mean vertical scale factor [m]
             !
          ENDIF
@@ -130,4 +135,7 @@
             CALL iom_rstput( kt, nitrst, numrow, 'sss_m'  , sss_m  )
             CALL iom_rstput( kt, nitrst, numrow, 'ssh_m'  , ssh_m  )
+            IF( lk_vvl ) THEN
+               CALL iom_rstput( kt, nitrst, numrow, 'fse3t_m'  , fse3t_m(:,:)  )
+            END IF
             !
          ENDIF
@@ -168,4 +176,5 @@
             CALL iom_get( numror, jpdom_autoglo, 'sss_m'  , sss_m  )   !   "         "    salinity    (T-point)
             CALL iom_get( numror, jpdom_autoglo, 'ssh_m'  , ssh_m  )   !   "         "    height      (T-point)
+            IF( lk_vvl ) CALL iom_get( numror, jpdom_autoglo, 'fse3t_m', fse3t_m(:,:) )
             !
             IF( zf_sbc /= REAL( nn_fsbc, wp ) ) THEN      ! nn_fsbc has changed between 2 runs
@@ -178,4 +187,5 @@
                sss_m(:,:) = zcoef * sss_m(:,:)
                ssh_m(:,:) = zcoef * ssh_m(:,:)
+               IF( lk_vvl ) fse3t_m(:,:) = zcoef * fse3t_m(:,:)
             ELSE
                IF(lwp) WRITE(numout,*) '~~~~~~~   mean fields read in the ocean restart file'
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90	(revision 4292)
@@ -1,107 +1,116 @@
 MODULE sbctide
-  !!=================================================================================
-  !!                       ***  MODULE  sbctide  ***
-  !! Initialization of tidal forcing
-  !! History :  9.0  !  07  (O. Le Galloudec)  Original code
-  !!=================================================================================
-  !! * Modules used
-  USE oce             ! ocean dynamics and tracers variables
-  USE dom_oce         ! ocean space and time domain
-  USE in_out_manager  ! I/O units
-  USE ioipsl          ! NetCDF IPSL library
-  USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-  USE phycst
-  USE daymod
-  USE dynspg_oce
-  USE tideini
-  USE iom
+   !!======================================================================
+   !!                       ***  MODULE  sbctide  ***
+   !! Initialization of tidal forcing
+   !!======================================================================
+   !! History :  9.0  !  2007  (O. Le Galloudec)  Original code
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain
+   USE phycst
+   USE daymod
+   USE dynspg_oce
+   USE tideini
+   !
+   USE iom
+   USE in_out_manager  ! I/O units
+   USE ioipsl          ! NetCDF IPSL library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
 
-  IMPLICIT NONE
-  PUBLIC
+   IMPLICIT NONE
+   PUBLIC
 
-  REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:) :: pot_astro
+   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:) ::   pot_astro   !
 
 #if defined key_tide
+   !!----------------------------------------------------------------------
+   !!   'key_tide' :                                        tidal potential
+   !!----------------------------------------------------------------------
+   !!   sbc_tide            : 
+   !!   tide_init_potential :
+   !!----------------------------------------------------------------------
 
-  LOGICAL, PUBLIC, PARAMETER ::   lk_tide  = .TRUE.
-  REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: amp_pot,phi_pot
-  !!---------------------------------------------------------------------------------
-  !!   OPA 9.0 , LODYC-IPSL  (2003)
-  !!---------------------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_tide  = .TRUE.
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   amp_pot, phi_pot
 
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.5 , NEMO Consortium (2013)
+   !! $Id: $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
 
-  SUBROUTINE sbc_tide ( kt )
-    !!----------------------------------------------------------------------
-    !!                 ***  ROUTINE sbc_tide  ***
-    !!----------------------------------------------------------------------      
-    !! * Arguments
-    INTEGER, INTENT( in ) ::   kt     ! ocean time-step
-    !!----------------------------------------------------------------------
+   SUBROUTINE sbc_tide( kt )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE sbc_tide  ***
+      !!----------------------------------------------------------------------      
+      INTEGER, INTENT( in ) ::   kt     ! ocean time-step
+      INTEGER               ::   jk     ! dummy loop index
+      !!----------------------------------------------------------------------
 
-    IF ( kt == nit000 .AND. .NOT. lk_dynspg_ts )  CALL ctl_stop( 'STOP', 'sbc_tide : tidal potential use only with time splitting' )
-
-    IF ( nsec_day == NINT(0.5 * rdttra(1)) ) THEN
+      IF( nsec_day == NINT(0.5_wp * rdttra(1)) ) THEN      ! start a new day
+         !
+         IF( kt == nit000 ) THEN
+            ALLOCATE( amp_pot(jpi,jpj,nb_harmo),                      &
+               &      phi_pot(jpi,jpj,nb_harmo), pot_astro(jpi,jpj)   )
+         ENDIF
+         !
+         amp_pot(:,:,:) = 0._wp
+         phi_pot(:,:,:) = 0._wp
+         pot_astro(:,:) = 0._wp
+         !
+         CALL tide_harmo( omega_tide, v0tide, utide, ftide, ntide, nb_harmo )
+         !
+         kt_tide = kt
+         !
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'sbc_tide : Update of the components and (re)Init. the potential at kt=', kt
+            WRITE(numout,*) '~~~~~~~~ '
+            DO jk = 1, nb_harmo
+               WRITE(numout,*) Wave(ntide(jk))%cname_tide, utide(jk), ftide(jk), v0tide(jk), omega_tide(jk)
+            END DO
+         ENDIF
+         !
+         IF( ln_tide_pot )   CALL tide_init_potential
+         !
+      ENDIF
       !
-      kt_tide = kt
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'sbc_tide : (re)Initialization of the tidal potential at kt=',kt
-         WRITE(numout,*) '~~~~~~~ '
-      ENDIF
-
-      IF(lwp) THEN
-         IF ( kt == nit000 ) WRITE(numout,*) 'Apply astronomical potential : ln_tide_pot =', ln_tide_pot
-         CALL flush(numout)
-      ENDIF
-
-      IF ( kt == nit000 ) ALLOCATE(amp_pot(jpi,jpj,nb_harmo))
-      IF ( kt == nit000 ) ALLOCATE(phi_pot(jpi,jpj,nb_harmo))
-      IF ( kt == nit000 ) ALLOCATE(pot_astro(jpi,jpj))
-
-      amp_pot(:,:,:) = 0.e0
-      phi_pot(:,:,:) = 0.e0
-      pot_astro(:,:) = 0.e0
-
-      IF ( ln_tide_pot ) CALL tide_init_potential
-      !
-    ENDIF
-
-  END SUBROUTINE sbc_tide
-
-  SUBROUTINE tide_init_potential
-    !!----------------------------------------------------------------------
-    !!                 ***  ROUTINE tide_init_potential  ***
-    !!----------------------------------------------------------------------
-    !! * Local declarations
-    INTEGER  :: ji,jj,jk
-    REAL(wp) :: zcons,ztmp1,ztmp2,zlat,zlon
+   END SUBROUTINE sbc_tide
 
 
-    DO jk=1,nb_harmo
-       zcons=0.7*Wave(ntide(jk))%equitide*ftide(jk)
-       do ji=1,jpi
-          do jj=1,jpj
-             ztmp1 = amp_pot(ji,jj,jk)*COS(phi_pot(ji,jj,jk))
-             ztmp2 = -amp_pot(ji,jj,jk)*SIN(phi_pot(ji,jj,jk))
-             zlat = gphit(ji,jj)*rad !! latitude en radian
-             zlon = glamt(ji,jj)*rad !! longitude en radian
-             ! le potentiel est composé des effets des astres:
-             IF (Wave(ntide(jk))%nutide .EQ.1) THEN
-                ztmp1= ztmp1 + zcons*(SIN(2.*zlat))*COS(v0tide(jk)+utide(jk)+Wave(ntide(jk))%nutide*zlon)
-                ztmp2= ztmp2 - zcons*(SIN(2.*zlat))*SIN(v0tide(jk)+utide(jk)+Wave(ntide(jk))%nutide*zlon)
-             ENDIF
-             IF (Wave(ntide(jk))%nutide.EQ.2) THEN
-                ztmp1= ztmp1 + zcons*(COS(zlat)**2)*COS(v0tide(jk)+utide(jk)+Wave(ntide(jk))%nutide*zlon)
-                ztmp2= ztmp2 - zcons*(COS(zlat)**2)*SIN(v0tide(jk)+utide(jk)+Wave(ntide(jk))%nutide*zlon)
-             ENDIF
-             amp_pot(ji,jj,jk)=SQRT(ztmp1**2+ztmp2**2)
-             phi_pot(ji,jj,jk)=ATAN2(-ztmp2/MAX(1.E-10,SQRT(ztmp1**2+ztmp2**2)),ztmp1/MAX(1.E-10,SQRT(ztmp1**2+ztmp2**2)))
-          enddo
-       enddo
-    END DO
+   SUBROUTINE tide_init_potential
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE tide_init_potential  ***
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zcons, ztmp1, ztmp2, zlat, zlon, ztmp, zamp, zcs   ! local scalar
+      !!----------------------------------------------------------------------
 
-  END SUBROUTINE tide_init_potential
+      DO jk = 1, nb_harmo
+         zcons = 0.7_wp * Wave(ntide(jk))%equitide * ftide(jk)
+         DO ji = 1, jpi
+            DO jj = 1, jpj
+               ztmp1 =  amp_pot(ji,jj,jk) * COS( phi_pot(ji,jj,jk) )
+               ztmp2 = -amp_pot(ji,jj,jk) * SIN( phi_pot(ji,jj,jk) )
+               zlat = gphit(ji,jj)*rad !! latitude en radian
+               zlon = glamt(ji,jj)*rad !! longitude en radian
+               ztmp = v0tide(jk) + utide(jk) + Wave(ntide(jk))%nutide * zlon
+               ! le potentiel est composé des effets des astres:
+               IF    ( Wave(ntide(jk))%nutide == 1 )  THEN  ;  zcs = zcons * SIN( 2._wp*zlat )
+               ELSEIF( Wave(ntide(jk))%nutide == 2 )  THEN  ;  zcs = zcons * COS( zlat )**2
+               ELSE                                         ;  zcs = 0._wp
+               ENDIF
+               ztmp1 = ztmp1 + zcs * COS( ztmp )
+               ztmp2 = ztmp2 - zcs * SIN( ztmp )
+               zamp = SQRT( ztmp1*ztmp1 + ztmp2*ztmp2 )
+               amp_pot(ji,jj,jk) = zamp
+               phi_pot(ji,jj,jk) = ATAN2( -ztmp2 / MAX( 1.e-10_wp , zamp ) ,   &
+                  &                        ztmp1 / MAX( 1.e-10_wp,  zamp )   )
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE tide_init_potential
 
 #else
@@ -116,5 +125,5 @@
   END SUBROUTINE sbc_tide
 #endif
+
   !!======================================================================
-
 END MODULE sbctide
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90	(revision 4292)
@@ -151,10 +151,10 @@
              DO jj = 1, jpj-1
                 DO ji = 1, jpi-1
-                   usd3d(ji,jj,jk) = usd2d(ji,jj)*exp(2.0*uwavenum(ji,jj)*(-MIN( gdept(ji,jj,jk) , gdept(ji+1,jj  ,jk))))
-                   vsd3d(ji,jj,jk) = vsd2d(ji,jj)*exp(2.0*vwavenum(ji,jj)*(-MIN( gdept(ji,jj,jk) , gdept(ji  ,jj+1,jk))))
+                   usd3d(ji,jj,jk) = usd2d(ji,jj)*exp(2.0*uwavenum(ji,jj)*(-MIN( gdept_0(ji,jj,jk) , gdept_0(ji+1,jj  ,jk))))
+                   vsd3d(ji,jj,jk) = vsd2d(ji,jj)*exp(2.0*vwavenum(ji,jj)*(-MIN( gdept_0(ji,jj,jk) , gdept_0(ji  ,jj+1,jk))))
                 END DO
              END DO
-             usd3d(jpi,:,jk) = usd2d(jpi,:)*exp( 2.0*uwavenum(jpi,:)*(-gdept(jpi,:,jk)) )
-             vsd3d(:,jpj,jk) = vsd2d(:,jpj)*exp( 2.0*vwavenum(:,jpj)*(-gdept(:,jpj,jk)) )
+             usd3d(jpi,:,jk) = usd2d(jpi,:)*exp( 2.0*uwavenum(jpi,:)*(-gdept_0(jpi,:,jk)) )
+             vsd3d(:,jpj,jk) = vsd2d(:,jpj)*exp( 2.0*vwavenum(:,jpj)*(-gdept_0(:,jpj,jk)) )
           END DO
 
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/tide.h90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/tide.h90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/tide.h90	(revision 4292)
@@ -1,28 +1,29 @@
-!! History :  9.0  !  07  (O. Le Galloudec)  Original code
+   !!----------------------------------------------------------------------
+   !! History :  3.2  !  2007  (O. Le Galloudec)  Original code
+   !!----------------------------------------------------------------------
 
-! Wave(1)= tide(name_tide,equitide,nutide,nt,ns,nh,np,np1,shift,nksi,nnu0,nnu1,nnu2,R,formula)
- 
-  
-  Wave(1)= tide('M2'     ,0.242297,2     ,2 ,-2,2 ,0 ,0  ,0    ,2   ,-2   ,0  ,0   ,0,78)
-  Wave(2)= tide('N2'     ,0.046313,2     ,2 ,-3,2 ,1 ,0  ,0    ,2   ,-2   ,0  ,0   ,0,78)
-  Wave(3)= tide('2N2'    ,0.006184,2     ,2 ,-4,2 ,2 ,0  ,0    ,2   ,-2   ,0  ,0   ,0,78)
-  Wave(4)= tide('S2'     ,0.113572,2     ,2 , 0,0 ,0 ,0  ,0    ,0   , 0   ,0  ,0   ,0,0)
-  Wave(5)= tide('K2'     ,0.030875,2     ,2 , 0,2 ,0 ,0  ,0    ,0   , 0   ,0  ,-2  ,0,235)
-
-  Wave(6)= tide('K1'     ,0.142408,1     ,1 , 0,1 ,0 ,0  ,-90  ,0   , 0   ,-1 ,0   ,0,227)
-  Wave(7)= tide('O1'     ,0.101266,1     ,1 ,-2,1 ,0 ,0  ,+90  ,2   ,-1   , 0 ,0   ,0,75)
-  Wave(8)= tide('Q1'     ,0.019387,1     ,1 ,-3,1 ,1 ,0  ,+90  ,2   ,-1   , 0 ,0   ,0,75)
-  Wave(9)= tide('P1'     ,0.047129,1     ,1 , 0,-1,0 ,0  ,+90  ,0   , 0   , 0 ,0   ,0,0)  
-
-  Wave(10)= tide('M4'    ,0.000000,4     ,4 ,-4, 4,0 ,0  ,0    ,4   , -4  , 0 ,0   ,0,1)
-
-  Wave(11) = tide('Mf'   ,0.042017,0     ,0 , 2, 0,0 ,0  ,0    ,-2  , 0   , 0 ,0   ,0,74)
-  Wave(12) = tide('Mm'   ,0.022191,0     ,0 , 1,0 ,-1,0  ,0    ,0   , 0   , 0 ,0   ,0,73)
-  Wave(13) = tide('Msqm' ,0.000667,0     ,0 , 4,-2, 0,0  ,0    ,-2  , 0   , 0 ,0   ,0,74)
-  Wave(14) = tide('Mtm'  ,0.008049,0     ,0 , 3, 0,-1,0  ,0    ,-2  , 0   , 0 ,0   ,0,74)
-
-  Wave(15) = tide('S1'   ,0.000000,1     ,1,  0, 0, 0,0  ,0    , 0  , 0   , 0 ,0   ,0,0)   
-  Wave(16) = tide('MU2'  ,0.005841,2     ,2, -4, 4, 0,0  ,0    ,2   ,-2   , 0, 0   ,0,78)
-  Wave(17) = tide('NU2'  ,0.009094,2     ,2, -3, 4,-1,0  ,0    ,2   ,-2   , 0, 0   ,0,78) 
-  Wave(18) = tide('L2'   ,0.006694,2     ,2, -1, 2,-1,0  ,+180 ,2   ,-2   , 0, 0   ,0,215)
-  Wave(19) = tide('T2'   ,0.006614,2     ,2,  0,-1, 0,1  ,0    ,0   , 0   , 0, 0   ,0,0)
+   !             !! name_tide , equitide , nutide , nt , ns , nh , np , np1 , shift , nksi , nnu0 , nnu1 , nnu2 , R , formula !!
+   !             !!           !          !        !    !    !    !    !     !       !      !      !      !      !   !         !!
+   Wave( 1) = tide(  'M2'     , 0.242297 ,    2   ,  2 , -2 ,  2 ,  0 ,  0  ,    0  ,  2   , -2   ,  0   ,  0   , 0 ,    78   )
+   Wave( 2) = tide(  'N2'     , 0.046313 ,    2   ,  2 , -3 ,  2 ,  1 ,  0  ,    0  ,  2   , -2   ,  0   ,  0   , 0 ,    78   )
+   Wave( 3) = tide( '2N2'     , 0.006184 ,    2   ,  2 , -4 ,  2 ,  2 ,  0  ,    0  ,  2   , -2   ,  0   ,  0   , 0 ,    78   )
+   Wave( 4) = tide(  'S2'     , 0.113572 ,    2   ,  2 ,  0 ,  0 ,  0 ,  0  ,    0  ,  0   ,  0   ,  0   ,  0   , 0 ,     0   )
+   Wave( 5) = tide(  'K2'     , 0.030875 ,    2   ,  2 ,  0 ,  2 ,  0 ,  0  ,    0  ,  0   ,  0   ,  0   , -2   , 0 ,   235   )
+   !              !           !          !        !    !    !    !    !     !       !      !      !      !      !   !         !
+   Wave( 6) = tide(  'K1'     , 0.142408 ,    1   ,  1 ,  0 ,  1 ,  0 ,  0  ,  -90  ,  0   ,  0   , -1   ,  0   , 0 ,   227   )
+   Wave( 7) = tide(  'O1'     , 0.101266 ,    1   ,  1 , -2 ,  1 ,  0 ,  0  ,  +90  ,  2   , -1   ,  0   ,  0   , 0 ,    75   )
+   Wave( 8) = tide(  'Q1'     , 0.019387 ,    1   ,  1 , -3 ,  1 ,  1 ,  0  ,  +90  ,  2   , -1   ,  0   ,  0   , 0 ,    75   )
+   Wave( 9) = tide(  'P1'     , 0.047129 ,    1   ,  1 ,  0 , -1 ,  0 ,  0  ,  +90  ,  0   ,  0   ,  0   ,  0   , 0 ,    0    )
+   !              !           !          !        !    !    !    !    !     !       !      !      !      !      !   !         !
+   Wave(10) = tide(  'M4'     , 0.000000 ,    4   ,  4 , -4 ,  4 ,  0 ,  0  ,    0  ,  4   , -4   ,  0   ,  0   , 0 ,    1    )
+   !              !           !          !        !    !    !    !    !     !       !      !      !      !      !   !         !
+   Wave(11) = tide(  'Mf'     , 0.042017 ,    0   ,  0 ,  2 ,  0 ,  0 ,  0  ,    0  , -2   ,  0   ,  0   ,  0   , 0 ,   74    )
+   Wave(12) = tide(  'Mm'     , 0.022191 ,    0   ,  0 ,  1 ,  0 , -1 ,  0  ,    0  ,  0   ,  0   ,  0   ,  0   , 0 ,   73    )
+   Wave(13) = tide(  'Msqm'   , 0.000667 ,    0   ,  0 ,  4 , -2 ,  0 ,  0  ,    0  , -2   ,  0   ,  0   ,  0   , 0 ,   74    )
+   Wave(14) = tide(  'Mtm'    , 0.008049 ,    0   ,  0 ,  3 ,  0 , -1 ,  0  ,    0  , -2   ,  0   ,  0   ,  0   , 0 ,   74    )
+   !              !           !          !        !    !    !    !    !     !       !      !      !      !      !   !         !
+   Wave(15) = tide(  'S1'     , 0.000000 ,    1   ,  1 ,  0 ,  0 ,  0 ,  0  ,    0  ,  0   ,  0   ,  0   ,  0   , 0 ,    0    )   
+   Wave(16) = tide(  'MU2'    , 0.005841 ,    2   ,  2 , -4 ,  4 ,  0 ,  0  ,    0  ,  2   , -2   ,  0   ,  0   , 0 ,   78    )
+   Wave(17) = tide(  'NU2'    , 0.009094 ,    2   ,  2 , -3 ,  4 , -1 ,  0  ,    0  ,  2   , -2   ,  0   ,  0   , 0 ,   78    ) 
+   Wave(18) = tide(  'L2'     , 0.006694 ,    2   ,  2 , -1 ,  2 , -1 ,  0  , +180  ,  2   , -2   ,  0   ,  0   , 0 ,  215    )
+   Wave(19) = tide(  'T2'     , 0.006614 ,    2   ,  2 ,  0 , -1 ,  0 ,  1  ,    0  ,  0   ,  0   ,  0   ,  0   , 0 ,    0    )
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/tide_mod.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/tide_mod.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/tide_mod.F90	(revision 4292)
@@ -1,493 +1,411 @@
 MODULE tide_mod
-  !!=================================================================================
-  !!                       ***  MODULE  tide_mod  ***
-  !! Compute nodal modulations corrections and pulsations
-  !!=================================================================================
-  !!---------------------------------------------------------------------------------
-  !!   OPA 9.0 , LODYC-IPSL  (2003)
-  !!---------------------------------------------------------------------------------
-  USE dom_oce         ! ocean space and time domain
-  USE phycst
-  USE daymod
-
-  IMPLICIT NONE
-  PRIVATE
-
-  REAL(wp) :: sh_T, sh_s, sh_h, sh_p, sh_p1, &
-       sh_xi, sh_nu, sh_nuprim, sh_nusec, sh_R, &
-       sh_I, sh_x1ra, sh_N
-
-  INTEGER,PUBLIC, PARAMETER ::   &
-       jpmax_harmo = 19             ! maximum number of harmonic
-
-  TYPE, PUBLIC ::    tide
-     CHARACTER(LEN=4)  :: cname_tide
-     REAL(wp) :: equitide
-     INTEGER  :: nutide
-     INTEGER  ::  nt,ns,nh,np,np1,shift
-     INTEGER  ::  nksi,nnu0,nnu1,nnu2,R
-     INTEGER  :: nformula
-  END TYPE tide
-
-  TYPE(tide), PUBLIC, DIMENSION(jpmax_harmo) :: Wave
-
-  !! * Accessibility
-  PUBLIC tide_harmo
-  PUBLIC nodal_factort
-  PUBLIC tide_init_Wave
-
+   !!======================================================================
+   !!                       ***  MODULE  tide_mod  ***
+   !! Compute nodal modulations corrections and pulsations
+   !!======================================================================
+   !! History :  1.0  !  2007  (O. Le Galloudec)  Original code
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constant
+   USE daymod         ! calendar
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tide_harmo       ! called by tideini and diaharm modules
+   PUBLIC   tide_init_Wave   ! called by tideini and diaharm modules
+
+   INTEGER, PUBLIC, PARAMETER ::   jpmax_harmo = 19   !: maximum number of harmonic
+
+   TYPE, PUBLIC ::    tide
+      CHARACTER(LEN=4) ::   cname_tide
+      REAL(wp)         ::   equitide
+      INTEGER          ::   nutide
+      INTEGER          ::   nt, ns, nh, np, np1, shift
+      INTEGER          ::   nksi, nnu0, nnu1, nnu2, R
+      INTEGER          ::   nformula
+   END TYPE tide
+
+   TYPE(tide), PUBLIC, DIMENSION(jpmax_harmo) ::   Wave   !:
+
+   REAL(wp) ::   sh_T, sh_s, sh_h, sh_p, sh_p1             ! astronomic angles
+   REAL(wp) ::   sh_xi, sh_nu, sh_nuprim, sh_nusec, sh_R   !
+   REAL(wp) ::   sh_I, sh_x1ra, sh_N                       !
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , LOCEAN-IPSL (2010) 
+   !! $Id:$ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
 
-  SUBROUTINE tide_init_Wave
-
-#  include "tide.h90"
-
-  END SUBROUTINE tide_init_Wave
-
-  SUBROUTINE tide_harmo( pomega, pvt, put , pcor, ktide ,kc)
-
-    INTEGER, DIMENSION(kc), INTENT( in ) ::   &
-         ktide      ! Indice of tidal constituents
-
-    INTEGER, INTENT( in ) :: &
-         kc         ! Total number of tidal constituents
-
-    REAL (wp), DIMENSION(kc), INTENT( out ) ::   &
-         pomega      ! pulsation in radians/s
-
-    REAL (wp), DIMENSION(kc), INTENT( out ) ::   &
-         pvt, &      !
-         put, &      !
-         pcor         !
-
-    CALL astronomic_angle
-    CALL tide_pulse(pomega, ktide ,kc)
-    CALL tide_vuf( pvt, put, pcor, ktide ,kc)
-
-  END SUBROUTINE tide_harmo
-
-  SUBROUTINE astronomic_angle
-
-    !!----------------------------------------------------------------------
-    !!
-    !!  tj is time elapsed since 1st January 1900, 0 hour, counted in julian
-    !!  century (e.g. time in days divide by 36525)
-    !!----------------------------------------------------------------------
-
-    REAL(wp) ::  cosI,p,q,t2,t4,sin2I,s2,tgI2,P1,sh_tgn2,at1,at2
-    REAL(wp) :: zqy,zsy,zday,zdj,zhfrac
-
-    zqy=AINT((nyear-1901.)/4.)
-    zsy=nyear-1900.
-
-    zdj=dayjul(nyear,nmonth,nday)
-    zday=zdj+zqy-1.
-
-    zhfrac=nsec_day/3600.
-
-    !----------------------------------------------------------------------
-    !  Sh_n Longitude of ascending lunar node
-    !----------------------------------------------------------------------
-
-    sh_N=(259.1560564-19.328185764*zsy-.0529539336*zday-.0022064139*zhfrac)*rad
-    !----------------------------------------------------------------------
-    ! T mean solar angle (Greenwhich time)
-    !----------------------------------------------------------------------
-    sh_T=(180.+zhfrac*(360./24.))*rad
-    !----------------------------------------------------------------------
-    ! h mean solar Longitude
-    !----------------------------------------------------------------------
-
-    sh_h=(280.1895014-.238724988*zsy+.9856473288*zday+.0410686387*zhfrac)*rad
-    !----------------------------------------------------------------------
-    ! s mean lunar Longitude
-    !----------------------------------------------------------------------
-
-    sh_s=(277.0256206+129.38482032*zsy+13.176396768*zday+.549016532*zhfrac)*rad
-    !----------------------------------------------------------------------
-    ! p1 Longitude of solar perigee
-    !----------------------------------------------------------------------
-
-    sh_p1=(281.2208569+.01717836*zsy+.000047064*zday+.000001961*zhfrac)*rad
-    !----------------------------------------------------------------------
-    ! p Longitude of lunar perigee
-    !----------------------------------------------------------------------
-
-    sh_p=(334.3837214+40.66246584*zsy+.111404016*zday+.004641834*zhfrac)*rad
-
-    sh_N =mod(sh_N ,2*rpi)
-    sh_s =mod(sh_s ,2*rpi)
-    sh_h =mod(sh_h, 2*rpi)
-    sh_p =mod(sh_p, 2*rpi)
-    sh_p1=mod(sh_p1,2*rpi)
-
-    cosI=0.913694997 -0.035692561 *cos(sh_N)
-
-    sh_I=acos(cosI)
-
-    sin2I=sin(sh_I)
-    sh_tgn2=tan(sh_N/2.0)
-
-    at1=atan(1.01883*sh_tgn2)
-    at2=atan(0.64412*sh_tgn2)
-
-    sh_xi=-at1-at2+sh_N
-
-    if (sh_N > rpi) sh_xi=sh_xi-2.0*rpi
-
-    sh_nu=at1-at2
-
-    !----------------------------------------------------------------------
-    ! For constituents l2 k1 k2
-    !----------------------------------------------------------------------
-
-    tgI2=tan(sh_I/2.0)
-    P1=sh_p-sh_xi
-
-    t2=tgI2*tgI2
-    t4=t2*t2
-    sh_x1ra=sqrt(1.0-12.0*t2*cos(2.0*P1)+36.0*t4)
-
-    p=sin(2.0*P1)
-    q=1.0/(6.0*t2)-cos(2.0*P1)
-    sh_R=atan(p/q)
-
-    p=sin(2.0*sh_I)*sin(sh_nu)
-    q=sin(2.0*sh_I)*cos(sh_nu)+0.3347
-    sh_nuprim=atan(p/q)
-
-    s2=sin(sh_I)*sin(sh_I)
-    p=s2*sin(2.0*sh_nu)
-    q=s2*cos(2.0*sh_nu)+0.0727
-    sh_nusec=0.5*atan(p/q)
-
-  END SUBROUTINE astronomic_angle
-
-  SUBROUTINE tide_pulse( pomega, ktide ,kc)
-    !!----------------------------------------------------------------------
-    !!                     ***  ROUTINE tide_pulse  ***
-    !!                      
-    !! ** Purpose : Compute tidal frequencies
-    !!
-    !!----------------------------------------------------------------------
-    !! * Arguments
-    INTEGER, DIMENSION(kc), INTENT( in ) ::   &
-         ktide      ! Indice of tidal constituents
-
-    INTEGER, INTENT( in ) :: &
-         kc         ! Total number of tidal constituents
-
-    REAL (wp), DIMENSION(kc), INTENT( out ) ::   &
-         pomega      ! pulsation in radians/s
-
-    !! * Local declarations
-    INTEGER :: jh
-    REAL(wp) :: zscale  =  36525*24.0
-    REAL(wp) :: zomega_T=  13149000.0
-    REAL(wp) :: zomega_s=    481267.892
-    REAL(wp) :: zomega_h=     36000.76892
-    REAL(wp) :: zomega_p=      4069.0322056
-    REAL(wp) :: zomega_n=      1934.1423972
-    REAL(wp) :: zomega_p1=        1.719175
-    !!----------------------------------------------------------------------
-
-    DO jh=1,kc
-       pomega(jh) = zomega_T * Wave(ktide(jh))%nT &
-            + zomega_s * Wave(ktide(jh))%ns &
-            + zomega_h * Wave(ktide(jh))%nh &
-            + zomega_p * Wave(ktide(jh))%np &
-            + zomega_p1* Wave(ktide(jh))%np1
-       pomega(jh) = (pomega(jh)/zscale)*rad/3600.
-    END DO
-
-  END SUBROUTINE tide_pulse
-
-  SUBROUTINE tide_vuf( pvt, put, pcor, ktide ,kc)
-    !!----------------------------------------------------------------------
-    !!                     ***  ROUTINE tide_vuf  ***
-    !!                      
-    !! ** Purpose : Compute nodal modulation corrections
-    !!
-    !! ** Outputs :
-    !!          vt: Pase of tidal potential relative to Greenwich (radians)
-    !!          ut: Phase correction u due to nodal motion (radians)
-    !!          ft: Nodal correction factor
-    !!
-    !! ** Inputs :
-    !!          tname: array of constituents names (dimension<=nc) 
-    !!             nc: number of constituents
-    !!   
-    !!----------------------------------------------------------------------
-    !! * Arguments
-    INTEGER, DIMENSION(kc), INTENT( in ) ::   &
-         ktide      ! Indice of tidal constituents
-    INTEGER, INTENT( in ) :: &
-         kc         ! Total number of tidal constituents
-    REAL (wp), DIMENSION(kc), INTENT( out ) ::   &
-         pvt, &      !
-         put, &      !
-         pcor         !
-    !! * Local declarations
-    INTEGER :: jh
-    !!----------------------------------------------------------------------
-
-    DO jh =1,kc
-       !  Phase of the tidal potential relative to the Greenwhich 
-       !  meridian (e.g. the position of the fictuous celestial body). Units are
-       !  radian:
-       pvt(jh) = sh_T *Wave(ktide(jh))%nT        &
-            +sh_s *Wave(ktide(jh))%ns        &
-            +sh_h *Wave(ktide(jh))%nh        &
-            +sh_p *Wave(ktide(jh))%np        &
-            +sh_p1*Wave(ktide(jh))%np1       &
-            +Wave(ktide(jh))%shift*rad
+   SUBROUTINE tide_init_Wave
+#     include "tide.h90"
+   END SUBROUTINE tide_init_Wave
+
+
+   SUBROUTINE tide_harmo( pomega, pvt, put , pcor, ktide ,kc)
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      INTEGER , DIMENSION(kc), INTENT(in ) ::   ktide            ! Indice of tidal constituents
+      INTEGER                , INTENT(in ) ::   kc               ! Total number of tidal constituents
+      REAL(wp), DIMENSION(kc), INTENT(out) ::   pomega           ! pulsation in radians/s
+      REAL(wp), DIMENSION(kc), INTENT(out) ::   pvt, put, pcor   !
+      !!----------------------------------------------------------------------
+      !
+      CALL astronomic_angle
+      CALL tide_pulse( pomega, ktide ,kc )
+      CALL tide_vuf  ( pvt, put, pcor, ktide ,kc )
+      !
+   END SUBROUTINE tide_harmo
+
+
+   SUBROUTINE astronomic_angle
+      !!----------------------------------------------------------------------
+      !!  tj is time elapsed since 1st January 1900, 0 hour, counted in julian
+      !!  century (e.g. time in days divide by 36525)
+      !!----------------------------------------------------------------------
+      REAL(wp) ::   cosI, p, q, t2, t4, sin2I, s2, tgI2, P1, sh_tgn2, at1, at2
+      REAL(wp) ::   zqy , zsy, zday, zdj, zhfrac
+      !!----------------------------------------------------------------------
+      !
+      zqy = AINT( (nyear-1901.)/4. )
+      zsy = nyear - 1900.
+      !
+      zdj  = dayjul( nyear, nmonth, nday )
+      zday = zdj + zqy - 1.
+      !
+      zhfrac = nsec_day / 3600.
+      !
+      !----------------------------------------------------------------------
+      !  Sh_n Longitude of ascending lunar node
+      !----------------------------------------------------------------------
+      sh_N=(259.1560564-19.328185764*zsy-.0529539336*zday-.0022064139*zhfrac)*rad
+      !----------------------------------------------------------------------
+      ! T mean solar angle (Greenwhich time)
+      !----------------------------------------------------------------------
+      sh_T=(180.+zhfrac*(360./24.))*rad
+      !----------------------------------------------------------------------
+      ! h mean solar Longitude
+      !----------------------------------------------------------------------
+      sh_h=(280.1895014-.238724988*zsy+.9856473288*zday+.0410686387*zhfrac)*rad
+      !----------------------------------------------------------------------
+      ! s mean lunar Longitude
+      !----------------------------------------------------------------------
+      sh_s=(277.0256206+129.38482032*zsy+13.176396768*zday+.549016532*zhfrac)*rad
+      !----------------------------------------------------------------------
+      ! p1 Longitude of solar perigee
+      !----------------------------------------------------------------------
+      sh_p1=(281.2208569+.01717836*zsy+.000047064*zday+.000001961*zhfrac)*rad
+      !----------------------------------------------------------------------
+      ! p Longitude of lunar perigee
+      !----------------------------------------------------------------------
+      sh_p=(334.3837214+40.66246584*zsy+.111404016*zday+.004641834*zhfrac)*rad
+
+      sh_N = MOD( sh_N ,2*rpi )
+      sh_s = MOD( sh_s ,2*rpi )
+      sh_h = MOD( sh_h, 2*rpi )
+      sh_p = MOD( sh_p, 2*rpi )
+      sh_p1= MOD( sh_p1,2*rpi )
+
+      cosI = 0.913694997 -0.035692561 *cos(sh_N)
+
+      sh_I = ACOS( cosI )
+
+      sin2I   = sin(sh_I)
+      sh_tgn2 = tan(sh_N/2.0)
+
+      at1=atan(1.01883*sh_tgn2)
+      at2=atan(0.64412*sh_tgn2)
+
+      sh_xi=-at1-at2+sh_N
+
+      IF( sh_N > rpi )   sh_xi=sh_xi-2.0*rpi
+
+      sh_nu = at1 - at2
+
+      !----------------------------------------------------------------------
+      ! For constituents l2 k1 k2
+      !----------------------------------------------------------------------
+
+      tgI2 = tan(sh_I/2.0)
+      P1   = sh_p-sh_xi
+
+      t2 = tgI2*tgI2
+      t4 = t2*t2
+      sh_x1ra = sqrt( 1.0-12.0*t2*cos(2.0*P1)+36.0*t4 )
+
+      p = sin(2.0*P1)
+      q = 1.0/(6.0*t2)-cos(2.0*P1)
+      sh_R = atan(p/q)
+
+      p = sin(2.0*sh_I)*sin(sh_nu)
+      q = sin(2.0*sh_I)*cos(sh_nu)+0.3347
+      sh_nuprim = atan(p/q)
+
+      s2 = sin(sh_I)*sin(sh_I)
+      p  = s2*sin(2.0*sh_nu)
+      q  = s2*cos(2.0*sh_nu)+0.0727
+      sh_nusec = 0.5*atan(p/q)
+      !
+   END SUBROUTINE astronomic_angle
+
+
+   SUBROUTINE tide_pulse( pomega, ktide ,kc )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE tide_pulse  ***
+      !!                      
+      !! ** Purpose : Compute tidal frequencies
+      !!----------------------------------------------------------------------
+      INTEGER                , INTENT(in ) ::   kc       ! Total number of tidal constituents
+      INTEGER , DIMENSION(kc), INTENT(in ) ::   ktide    ! Indice of tidal constituents
+      REAL(wp), DIMENSION(kc), INTENT(out) ::   pomega   ! pulsation in radians/s
+      !
+      INTEGER  ::   jh
+      REAL(wp) ::   zscale
+      REAL(wp) ::   zomega_T =  13149000.0_wp
+      REAL(wp) ::   zomega_s =    481267.892_wp
+      REAL(wp) ::   zomega_h =     36000.76892_wp
+      REAL(wp) ::   zomega_p =      4069.0322056_wp
+      REAL(wp) ::   zomega_n =      1934.1423972_wp
+      REAL(wp) ::   zomega_p1=         1.719175_wp
+      !!----------------------------------------------------------------------
+      !
+      zscale =  rad / ( 36525._wp * 86400._wp ) 
+      !
+      DO jh = 1, kc
+         pomega(jh) = (  zomega_T * Wave( ktide(jh) )%nT   &
+            &          + zomega_s * Wave( ktide(jh) )%ns   &
+            &          + zomega_h * Wave( ktide(jh) )%nh   &
+            &          + zomega_p * Wave( ktide(jh) )%np   &
+            &          + zomega_p1* Wave( ktide(jh) )%np1  ) * zscale
+      END DO
+      !
+   END SUBROUTINE tide_pulse
+
+
+   SUBROUTINE tide_vuf( pvt, put, pcor, ktide ,kc )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE tide_vuf  ***
+      !!                      
+      !! ** Purpose : Compute nodal modulation corrections
+      !!
+      !! ** Outputs : vt: Phase of tidal potential relative to Greenwich (radians)
+      !!              ut: Phase correction u due to nodal motion (radians)
+      !!              ft: Nodal correction factor
+      !!----------------------------------------------------------------------
+      INTEGER                , INTENT(in ) ::   kc               ! Total number of tidal constituents
+      INTEGER , DIMENSION(kc), INTENT(in ) ::   ktide            ! Indice of tidal constituents
+      REAL(wp), DIMENSION(kc), INTENT(out) ::   pvt, put, pcor   !
+      !
+      INTEGER ::   jh   ! dummy loop index
+      !!----------------------------------------------------------------------
+      !
+      DO jh = 1, kc
+         !  Phase of the tidal potential relative to the Greenwhich 
+         !  meridian (e.g. the position of the fictuous celestial body). Units are radian:
+         pvt(jh) = sh_T * Wave( ktide(jh) )%nT    &
+            &    + sh_s * Wave( ktide(jh) )%ns    &
+            &    + sh_h * Wave( ktide(jh) )%nh    &
+            &    + sh_p * Wave( ktide(jh) )%np    &
+            &    + sh_p1* Wave( ktide(jh) )%np1   &
+            &    +        Wave( ktide(jh) )%shift * rad
+         !
+         !  Phase correction u due to nodal motion. Units are radian:
+         put(jh) = sh_xi     * Wave( ktide(jh) )%nksi   &
+            &    + sh_nu     * Wave( ktide(jh) )%nnu0   &
+            &    + sh_nuprim * Wave( ktide(jh) )%nnu1   &
+            &    + sh_nusec  * Wave( ktide(jh) )%nnu2   &
+            &    + sh_R      * Wave( ktide(jh) )%R
+
+         !  Nodal correction factor:
+         pcor(jh) = nodal_factort( Wave( ktide(jh) )%nformula )
+      END DO
+      !
+   END SUBROUTINE tide_vuf
+
+
+   RECURSIVE FUNCTION nodal_factort( kformula ) RESULT( zf )
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) :: kformula
+      !
+      REAL(wp) :: zf
+      REAL(wp) :: zs, zf1, zf2
+      !!----------------------------------------------------------------------
+      !
+      SELECT CASE( kformula )
+      !
+      CASE( 0 )                  !==  formule 0, solar waves
+         zf = 1.0
+         !
+      CASE( 1 )                  !==  formule 1, compound waves (78 x 78)
+         zf=nodal_factort(78)
+         zf = zf * zf
+         !
+      CASE ( 2 )                 !==  formule 2, compound waves (78 x 0)  ===  (78) 
+       zf1= nodal_factort(78)
+       zf = nodal_factort( 0)
+       zf = zf1 * zf
        !
-       !  Phase correction u due to nodal motion. Units are radian:
-       put(jh) = sh_xi    *Wave(ktide(jh))%nksi  &
-            +sh_nu    *Wave(ktide(jh))%nnu0  &
-            +sh_nuprim*Wave(ktide(jh))%nnu1  &
-            +sh_nusec *Wave(ktide(jh))%nnu2  &
-            +sh_R     *Wave(ktide(jh))%R
-
-       !  Nodal correction factor:
-       pcor(jh) = nodal_factort(Wave(ktide(jh))%nformula)
-    END DO
-
-  END SUBROUTINE tide_vuf
-
-  recursive function nodal_factort(kformula) result (zf)
-    !!----------------------------------------------------------------------
-    INTEGER, INTENT(IN) :: kformula
-    REAL(wp) :: zf
-    REAL(wp) :: zs,zf1,zf2
-
-    SELECT CASE (kformula)
-
-       !!  formule 0, solar waves
-
-    case ( 0 )
-       zf=1.0
-
-       !! formule 1, compound waves (78 x 78)
-
-    case ( 1 )
-       zf=nodal_factort(78)
-       zf=zf*zf
-
-       !! formule 2, compound waves (78 x 0)  ===  (78) 
-
-    case ( 2 )
-       zf1=nodal_factort(78)
-       zf=nodal_factort(0)
-       zf=zf1*zf
-
-       !! formule 4,  compound waves (78 x 235) 
-
-    case ( 4 )
-       zf1=nodal_factort(78)
-       zf=nodal_factort(235)
-       zf=zf1*zf
-
-       !! formule 5,  compound waves (78 *78 x 235)
-
-    case ( 5 )
-       zf1=nodal_factort(78)
-       zf=nodal_factort(235)
-       zf=zf*zf1*zf1
-
-       !! formule 6,  compound waves (78 *78 x 0)
-
-    case ( 6 )
-       zf1=nodal_factort(78)
-       zf=nodal_factort(0)
-       zf=zf*zf1*zf1 
-
-       !! formule 7, compound waves (75 x 75)
-
-    case ( 7 )
-       zf=nodal_factort(75)
-       zf=zf*zf
-
-       !! formule 8,  compound waves (78 x 0 x 235)
-
-    case ( 8 )
-       zf=nodal_factort(78)
-       zf1=nodal_factort(0)
-       zf2=nodal_factort(235)
-       zf=zf*zf1*zf2
-
-       !! formule 9,  compound waves (78 x 0 x 227)
-
-    case ( 9 )
-       zf=nodal_factort(78)
-       zf1=nodal_factort(0)
-       zf2=nodal_factort(227)
-       zf=zf*zf1*zf2
-
-       !! formule 10,  compound waves (78 x 227)
-
-    case ( 10 )
-       zf=nodal_factort(78)
-       zf1=nodal_factort(227)
-       zf=zf*zf1
-
-       !! formule 11,  compound waves (75 x 0)
-
-    case ( 11 )
-       zf=nodal_factort(75)
-       zf=nodal_factort(0)
-       zf=zf*zf1
-
-       !! formule 12,  compound waves (78 x 78 x 78 x 0) 
-
-    case ( 12 )
-       zf1=nodal_factort(78)
-       zf=nodal_factort(0)
-       zf=zf*zf1*zf1*zf1
-
-       !! formule 13, compound waves (78 x 75)
-
-    case ( 13 )
-       zf1=nodal_factort(78)
-       zf=nodal_factort(75)
-       zf=zf*zf1
-
-       !! formule 14, compound waves (235 x 0)  ===  (235)
-
-    case ( 14 )
-       zf=nodal_factort(235)
-       zf1=nodal_factort(0)
-       zf=zf*zf1
-
-       !! formule 15, compound waves (235 x 75) 
-
-    case ( 15 )
-       zf=nodal_factort(235)
-       zf1=nodal_factort(75)
-       zf=zf*zf1
-
-       !! formule 16, compound waves (78 x 0 x 0)  ===  (78)
-
-    case ( 16 )
-       zf=nodal_factort(78)
-       zf1=nodal_factort(0)
-       zf=zf*zf1*zf1
-
-       !! formule 17,  compound waves (227 x 0) 
-
-    case ( 17 )
-       zf1=nodal_factort(227)
-       zf=nodal_factort(0)
-       zf=zf*zf1
-
-       !! formule 18,  compound waves (78 x 78 x 78 )
-
-    case ( 18 ) 
-       zf1=nodal_factort(78)
-       zf=zf1*zf1*zf1
-
-       !! formule 19, compound waves (78 x 0 x 0 x 0)  ===  (78)
-
-    case ( 19 )
-       zf=nodal_factort(78)
-       zf1=nodal_factort(0)
-       zf=zf*zf1*zf1
-
-       !! formule 73
-
-    case ( 73 )
-       zs=sin(sh_I)
-       zf=(2./3.-zs*zs)/0.5021
-
-       !! formule 74
-
-    case ( 74 )
-       zs=sin(sh_I)
-       zf=zs*zs/0.1578
-
-       !! formule 75
-
-    case ( 75 )
-       zs=cos (sh_I/2)
-       zf=sin (sh_I)*zs*zs/0.3800
-
-       !! formule 76
-
-    case ( 76 )
-       zf=sin (2*sh_I)/0.7214
-
-       !! formule 77
-
-    case ( 77 )
-       zs=sin (sh_I/2)
-       zf=sin (sh_I)*zs*zs/0.0164
-
-       !! formule 78
-
-    case ( 78 )
-       zs=cos (sh_I/2)
-       zf=zs*zs*zs*zs/0.9154
-
-       !! formule 79
-
-    case ( 79 )
-       zs=sin(sh_I)
-       zf=zs*zs/0.1565
-
-       !! formule 144
-
-    case ( 144 )
-       zs=sin (sh_I/2)
-       zf=(1-10*zs*zs+15*zs*zs*zs*zs)*cos(sh_I/2)/0.5873
-
-       !! formule 149
-
-    case ( 149 )
-       zs=cos (sh_I/2)
-       zf=zs*zs*zs*zs*zs*zs/0.8758
-
-       !! formule 215
-
-    case ( 215 )
-       zs=cos (sh_I/2)
-       zf=zs*zs*zs*zs/0.9154*sh_x1ra
-
-       !! formule 227 
-
-    case ( 227 )
-       zs=sin (2*sh_I)
-       zf=sqrt (0.8965*zs*zs+0.6001*zs*cos (sh_nu)+0.1006)
-
-       !! formule 235 
-
-    case ( 235 )
-       zs=sin (sh_I)
-       zf=sqrt (19.0444*zs*zs*zs*zs+2.7702*zs*zs*cos (2*sh_nu)+.0981)
-
-    END SELECT
-
-  end function nodal_factort
-
-  function dayjul(kyr,kmonth,kday)
-    !
-    !*** THIS ROUTINE COMPUTES THE JULIAN DAY (AS A REAL VARIABLE)
-    !
-    INTEGER,INTENT(IN) :: kyr,kmonth,kday
-    INTEGER,DIMENSION(12) ::  idayt,idays
-    INTEGER :: inc,ji
-    REAL(wp) :: dayjul,zyq
-
-    DATA idayt/0.,31.,59.,90.,120.,151.,181.,212.,243.,273.,304.,334./
-    idays(1)=0.
-    idays(2)=31.
-    inc=0.
-    zyq=MOD((kyr-1900.),4.)
-    IF(zyq .eq. 0.) inc=1.
-    DO ji=3,12
-       idays(ji)=idayt(ji)+inc
-    END DO
-    dayjul=idays(kmonth)+kday
-
-  END FUNCTION dayjul
-
+      CASE ( 4 )                 !==  formule 4,  compound waves (78 x 235) 
+         zf1 = nodal_factort( 78)
+         zf  = nodal_factort(235)
+         zf  = zf1 * zf
+         !
+      CASE ( 5 )                 !==  formule 5,  compound waves (78 *78 x 235)
+         zf1 = nodal_factort( 78)
+         zf  = nodal_factort(235)
+         zf  = zf * zf1 * zf1
+         !
+      CASE ( 6 )                 !==  formule 6,  compound waves (78 *78 x 0)
+         zf1 = nodal_factort(78)
+         zf  = nodal_factort( 0)
+         zf  = zf * zf1 * zf1 
+         !
+      CASE( 7 )                  !==  formule 7, compound waves (75 x 75)
+         zf = nodal_factort(75)
+         zf = zf * zf
+         !
+      CASE( 8 )                  !==  formule 8,  compound waves (78 x 0 x 235)
+         zf  = nodal_factort( 78)
+         zf1 = nodal_factort(  0)
+         zf2 = nodal_factort(235)
+         zf  = zf * zf1 * zf2
+         !
+      CASE( 9 )                  !==  formule 9,  compound waves (78 x 0 x 227)
+         zf  = nodal_factort( 78)
+         zf1 = nodal_factort(  0)
+         zf2 = nodal_factort(227)
+         zf  = zf * zf1 * zf2
+         !
+      CASE( 10 )                 !==  formule 10,  compound waves (78 x 227)
+         zf  = nodal_factort( 78)
+         zf1 = nodal_factort(227)
+         zf  = zf * zf1
+         !
+      CASE( 11 )                 !==  formule 11,  compound waves (75 x 0)
+!!gm bug???? zf 2 fois !
+         zf = nodal_factort(75)
+         zf = nodal_factort( 0)
+         zf = zf * zf1
+         !
+      CASE( 12 )                 !==  formule 12,  compound waves (78 x 78 x 78 x 0) 
+         zf1 = nodal_factort(78)
+         zf  = nodal_factort( 0)
+         zf  = zf * zf1 * zf1 * zf1
+         !
+      CASE( 13 )                 !==  formule 13, compound waves (78 x 75)
+         zf1 = nodal_factort(78)
+         zf  = nodal_factort(75)
+         zf  = zf * zf1
+         !
+      CASE( 14 )                 !==  formule 14, compound waves (235 x 0)  ===  (235)
+         zf  = nodal_factort(235)
+         zf1 = nodal_factort(  0)
+         zf  = zf * zf1
+         !
+      CASE( 15 )                 !==  formule 15, compound waves (235 x 75) 
+         zf  = nodal_factort(235)
+         zf1 = nodal_factort( 75)
+         zf  = zf * zf1
+         !
+      CASE( 16 )                 !==  formule 16, compound waves (78 x 0 x 0)  ===  (78)
+         zf  = nodal_factort(78)
+         zf1 = nodal_factort( 0)
+         zf  = zf * zf1 * zf1
+         !
+      CASE( 17 )                 !==  formule 17,  compound waves (227 x 0) 
+         zf1 = nodal_factort(227)
+         zf  = nodal_factort(  0)
+         zf  = zf * zf1
+         !
+      CASE( 18 )                 !==  formule 18,  compound waves (78 x 78 x 78 )
+         zf1 = nodal_factort(78)
+         zf  = zf1 * zf1 * zf1
+         !
+      CASE( 19 )                 !==  formule 19, compound waves (78 x 0 x 0 x 0)  ===  (78)
+!!gm bug2 ==>>>   here identical to formule 16,  a third multiplication by zf1 is missing
+         zf  = nodal_factort(78)
+         zf1 = nodal_factort( 0)
+         zf = zf * zf1 * zf1
+         !
+      CASE( 73 )                 !==  formule 73
+         zs = sin(sh_I)
+         zf = (2./3.-zs*zs)/0.5021
+         !
+      CASE( 74 )                 !==  formule 74
+         zs = sin(sh_I)
+         zf = zs * zs / 0.1578
+         !
+      CASE( 75 )                 !==  formule 75
+         zs = cos(sh_I/2)
+         zf = sin(sh_I) * zs * zs / 0.3800
+         !
+      CASE( 76 )                 !==  formule 76
+         zf = sin(2*sh_I) / 0.7214
+         !
+      CASE( 77 )                 !==  formule 77
+         zs = sin(sh_I/2)
+         zf = sin(sh_I) * zs * zs / 0.0164
+         !
+      CASE( 78 )                 !==  formule 78
+         zs = cos(sh_I/2)
+         zf = zs * zs * zs * zs / 0.9154
+         !
+      CASE( 79 )                 !==  formule 79
+         zs = sin(sh_I)
+         zf = zs * zs / 0.1565
+         !
+      CASE( 144 )                !==  formule 144
+         zs = sin(sh_I/2)
+         zf = ( 1-10*zs*zs+15*zs*zs*zs*zs ) * cos(sh_I/2) / 0.5873
+         !
+      CASE( 149 )                !==  formule 149
+         zs = cos(sh_I/2)
+         zf = zs*zs*zs*zs*zs*zs / 0.8758
+         !
+      CASE( 215 )                !==  formule 215
+         zs = cos(sh_I/2)
+         zf = zs*zs*zs*zs / 0.9154 * sh_x1ra
+         !
+      CASE( 227 )                !==  formule 227 
+         zs = sin(2*sh_I)
+         zf = sqrt( 0.8965*zs*zs+0.6001*zs*cos (sh_nu)+0.1006 )
+         !
+      CASE ( 235 )               !==  formule 235 
+         zs = sin(sh_I)
+         zf = sqrt( 19.0444*zs*zs*zs*zs + 2.7702*zs*zs*cos(2*sh_nu) + .0981 )
+         !
+      END SELECT
+      !
+   END FUNCTION nodal_factort
+
+
+   FUNCTION dayjul( kyr, kmonth, kday )
+      !!----------------------------------------------------------------------
+      !!  *** THIS ROUTINE COMPUTES THE JULIAN DAY (AS A REAL VARIABLE)
+      !!----------------------------------------------------------------------
+      INTEGER,INTENT(in) ::   kyr, kmonth, kday
+      !
+      INTEGER,DIMENSION(12) ::  idayt, idays
+      INTEGER  ::   inc, ji
+      REAL(wp) ::   dayjul, zyq
+      !
+      DATA idayt/0.,31.,59.,90.,120.,151.,181.,212.,243.,273.,304.,334./
+      !!----------------------------------------------------------------------
+      !
+      idays(1) = 0.
+      idays(2) = 31.
+      inc = 0.
+      zyq = MOD( kyr-1900. , 4. )
+      IF( zyq == 0.)   inc = 1.
+      DO ji = 3, 12
+         idays(ji)=idayt(ji)+inc
+      END DO
+      dayjul = idays(kmonth) + kday
+      !
+   END FUNCTION dayjul
+
+   !!======================================================================
 END MODULE tide_mod
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/tideini.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/tideini.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/tideini.F90	(revision 4292)
@@ -1,39 +1,42 @@
 MODULE tideini
-  !!=================================================================================
-  !!                       ***  MODULE  tideini  ***
-  !! Initialization of tidal forcing
-  !! History :  9.0  !  07  (O. Le Galloudec)  Original code
-  !!=================================================================================
-  !! * Modules used
-  USE oce             ! ocean dynamics and tracers variables
-  USE dom_oce         ! ocean space and time domain
-  USE in_out_manager  ! I/O units
-  USE ioipsl          ! NetCDF IPSL library
-  USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-  USE phycst
-  USE daymod
-  USE dynspg_oce
-  USE tide_mod
-  USE iom
+   !!======================================================================
+   !!                       ***  MODULE  tideini  ***
+   !! Initialization of tidal forcing
+   !!======================================================================
+   !! History :  1.0  !  2007  (O. Le Galloudec)  Original code
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain
+   USE phycst
+   USE daymod
+   USE dynspg_oce
+   USE tide_mod
+   !
+   USE iom
+   USE in_out_manager  ! I/O units
+   USE ioipsl          ! NetCDF IPSL library
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
 
-  IMPLICIT NONE
-  PUBLIC
+   IMPLICIT NONE
+   PUBLIC
 
-  REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:) ::  &
-       omega_tide,  &
-       v0tide,      &
-       utide,       &
-       ftide
+   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:) ::   omega_tide   !:
+   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:) ::   v0tide       !:
+   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:) ::   utide        !:
+   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:) ::   ftide        !:
 
-  LOGICAL, PUBLIC :: ln_tide_pot , ln_tide_ramp 
-  REAL(wp), PUBLIC :: rdttideramp 
-  INTEGER, PUBLIC :: nb_harmo
-  INTEGER, PUBLIC, ALLOCATABLE, DIMENSION(:) :: ntide
-  INTEGER, PUBLIC :: kt_tide
+   LOGICAL , PUBLIC ::   ln_tide_pot     !:
+   LOGICAL , PUBLIC ::   ln_tide_ramp    !:
+   INTEGER , PUBLIC ::   nb_harmo                 !:
+   INTEGER , PUBLIC ::   kt_tide                  !:
+   REAL(wp), PUBLIC ::   rdttideramp              !:
+   
+   INTEGER , PUBLIC, ALLOCATABLE, DIMENSION(:) ::   ntide   !:
 
-  !!---------------------------------------------------------------------------------
-  !!   OPA 9.0 , LODYC-IPSL  (2003)
-  !!---------------------------------------------------------------------------------
-
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.5 , NEMO Consortium (2013)
+   !! $Id: $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
    
@@ -72,28 +75,28 @@
        !
        nb_harmo=0
-       DO jk=1,jpmax_harmo
-          DO ji=1,jpmax_harmo
-             IF(TRIM(clname(jk)) .eq. Wave(ji)%cname_tide) THEN
-                nb_harmo=nb_harmo+1
-             ENDIF
+       DO jk = 1, jpmax_harmo
+          DO ji = 1,jpmax_harmo
+             IF( TRIM(clname(jk)) == Wave(ji)%cname_tide )   nb_harmo = nb_harmo + 1
           END DO
-       ENDDO
+       END DO
        !
        IF(lwp) THEN
-          WRITE(numout,*) '        Namelist nam_tide'
-          WRITE(numout,*) '        nb_harmo    = ', nb_harmo
-          WRITE(numout,*) '        ln_tide_ramp = ', ln_tide_ramp 
-          WRITE(numout,*) '        rdttideramp = ', rdttideramp
-          IF (ln_tide_ramp.AND.((nitend-nit000+1)*rdt/rday < rdttideramp)) &
-          & CALL ctl_stop('rdttideramp must be lower than run duration')
-          IF (ln_tide_ramp.AND.(rdttideramp<0.)) &
-          & CALL ctl_stop('rdttideramp must be positive')
-          CALL flush(numout)
+          WRITE(numout,*) '   Namelist nam_tide'
+          WRITE(numout,*) '      Apply astronomical potential : ln_tide_pot  =', ln_tide_pot
+          WRITE(numout,*) '                                     nb_harmo     = ', nb_harmo
+          WRITE(numout,*) '                                     ln_tide_ramp = ', ln_tide_ramp 
+          WRITE(numout,*) '                                     rdttideramp  = ', rdttideramp
        ENDIF
+       IF( ln_tide_ramp.AND.((nitend-nit000+1)*rdt/rday < rdttideramp) )   &
+          &   CALL ctl_stop('rdttideramp must be lower than run duration')
+       IF( ln_tide_ramp.AND.(rdttideramp<0.) ) &
+          &   CALL ctl_stop('rdttideramp must be positive')
        !
-       ALLOCATE(ntide(nb_harmo))
-       DO jk=1,nb_harmo
-          DO ji=1,jpmax_harmo
-             IF (TRIM(clname(jk)) .eq. Wave(ji)%cname_tide) THEN
+       IF( .NOT. lk_dynspg_ts )   CALL ctl_warn( 'sbc_tide : use of time splitting is recommended' )
+       !
+       ALLOCATE( ntide(nb_harmo) )
+       DO jk = 1, nb_harmo
+          DO ji = 1, jpmax_harmo
+             IF( TRIM(clname(jk)) .eq. Wave(ji)%cname_tide ) THEN
                 ntide(jk) = ji
                 EXIT
@@ -102,30 +105,12 @@
        END DO
        !
-       ALLOCATE(omega_tide(nb_harmo))
-       ALLOCATE(v0tide    (nb_harmo))
-       ALLOCATE(utide     (nb_harmo))
-       ALLOCATE(ftide     (nb_harmo))
+       ALLOCATE( omega_tide(nb_harmo), v0tide    (nb_harmo),   &
+          &      utide     (nb_harmo), ftide     (nb_harmo)  )
        kt_tide = kt
        !
-    ENDIF
-
-    IF ( nsec_day == NINT(0.5 * rdttra(1)) ) THEN
-       !
-       IF(lwp) THEN
-          WRITE(numout,*)
-          WRITE(numout,*) 'tide_ini : Update of the tidal components at kt=',kt
-          WRITE(numout,*) '~~~~~~~~ '
-       ENDIF
-       CALL tide_harmo(omega_tide, v0tide, utide, ftide, ntide, nb_harmo)
-       DO jk =1,nb_harmo
-         IF(lwp) WRITE(numout,*) Wave(ntide(jk))%cname_tide,utide(jk),ftide(jk),v0tide(jk),omega_tide(jk)
-         call flush(numout)
-       END DO
-       !
-       kt_tide = kt
-       !
-    ENDIF
-
-  END SUBROUTINE tide_init
-   
+      ENDIF
+      !
+   END SUBROUTINE tide_init
+     
+   !!======================================================================
 END MODULE tideini
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/updtide.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/updtide.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/SBC/updtide.F90	(revision 4292)
@@ -1,65 +1,83 @@
 MODULE updtide
-  !!=================================================================================
-  !!                       ***  MODULE  updtide  ***
-  !! Initialization of tidal forcing
-  !! History :  9.0  !  07  (O. Le Galloudec)  Original code
-  !!=================================================================================
+   !!======================================================================
+   !!                       ***  MODULE  updtide  ***
+   !! Initialization of tidal forcing
+   !!======================================================================
+   !! History :  9.0  !  07  (O. Le Galloudec)  Original code
+   !!----------------------------------------------------------------------
 #if defined key_tide
-  !! * Modules used
-  USE oce             ! ocean dynamics and tracers variables
-  USE dom_oce         ! ocean space and time domain
-  USE in_out_manager  ! I/O units
-  USE phycst
-  USE sbctide
-  USE dynspg_oce
-  USE tideini, ONLY: ln_tide_ramp, rdttideramp
+   !!----------------------------------------------------------------------
+   !!   'key_tide' :                                        tidal potential
+   !!----------------------------------------------------------------------
+   !!   upd_tide       : update tidal potential
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain
+   USE in_out_manager  ! I/O units
+   USE phycst          ! physical constant
+   USE sbctide         ! tide potential variable
+   USE tideini, ONLY: ln_tide_ramp, rdttideramp
 
-  IMPLICIT NONE
-  PUBLIC
+   IMPLICIT NONE
+   PUBLIC
 
-  !! * Routine accessibility
-  PUBLIC upd_tide
-  !!---------------------------------------------------------------------------------
-  !!   OPA 9.0 , LODYC-IPSL  (2003)
-  !!---------------------------------------------------------------------------------
-
+   PUBLIC   upd_tide   ! called in dynspg_... modules
+  
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: sbcfwb.F90 3625 2012-11-21 13:19:18Z acc $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
 
-  SUBROUTINE upd_tide (kt,kit)
-    !!----------------------------------------------------------------------
-    !!                 ***  ROUTINE upd_tide  ***
-    !!----------------------------------------------------------------------      
-    !! * Local declarations
+   SUBROUTINE upd_tide( kt, kit, kbaro, koffset )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE upd_tide  ***
+      !!
+      !! ** Purpose :   provide at each time step the astronomical potential
+      !!
+      !! ** Method  :   computed from pulsation and amplitude of all tide components
+      !!
+      !! ** Action  :   pot_astro   actronomical potential
+      !!----------------------------------------------------------------------      
+      INTEGER, INTENT(in)           ::   kt      ! ocean time-step index
+      INTEGER, INTENT(in), OPTIONAL ::   kit     ! external mode sub-time-step index (lk_dynspg_ts=T only)
+      INTEGER, INTENT(in), OPTIONAL ::   kbaro   ! number of sub-time-step           (lk_dynspg_ts=T only)
+      INTEGER, INTENT(in), OPTIONAL ::   koffset ! time offset in number 
+                                                 ! of sub-time-steps                 (lk_dynspg_ts=T only)
+      !
+      INTEGER  ::   joffset      ! local integer
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zt, zramp    ! local scalar
+      REAL(wp), DIMENSION(nb_harmo) ::   zwt 
+      !!----------------------------------------------------------------------      
+      !
+      !                               ! tide pulsation at model time step (or sub-time-step)
+      zt = ( kt - kt_tide ) * rdt
+      !
+      joffset = 0
+      IF( PRESENT( koffset ) )   joffset = koffset
+      !
+      IF( PRESENT( kit ) .AND. PRESENT( kbaro ) )   THEN
+         zt = zt + ( kit + 0.5_wp * ( joffset - 1 ) ) * rdt / REAL( kbaro, wp )
+      ELSE
+         zt = zt + joffset * rdt
+      ENDIF
+      !
+      zwt(:) = omega_tide(:) * zt
 
-    INTEGER, INTENT( in ) ::   kt,kit      ! ocean time-step index
-    INTEGER  :: ji,jj,jk
-    REAL (wp) :: zramp
-    REAL (wp), DIMENSION(nb_harmo) :: zwt 
-    !...............................................................................
-
-    pot_astro(:,:)=0.e0
-    zramp = 1.e0
-
-    IF (lk_dynspg_ts) THEN
-       zwt(:) = omega_tide(:)* ((kt-kt_tide)*rdt + kit*(rdt/REAL(nn_baro,wp)))
-       IF (ln_tide_ramp) THEN
-          zramp = MIN(MAX( ((kt-nit000)*rdt + kit*(rdt/REAL(nn_baro,wp)))/(rdttideramp*rday),0.),1.)
-       ENDIF
-    ELSE
-       zwt(:) = omega_tide(:)*(kt-kt_tide)*rdt
-       IF (ln_tide_ramp) THEN
-          zramp = MIN(MAX( ((kt-nit000)*rdt)/(rdttideramp*rday),0.),1.) 
-       ENDIF  
-    ENDIF
-
-    do jk=1,nb_harmo
-       do ji=1,jpi
-          do jj=1,jpj
-             pot_astro(ji,jj)=pot_astro(ji,jj) + zramp*(amp_pot(ji,jj,jk)*COS(zwt(jk)+phi_pot(ji,jj,jk)))      
-          enddo
-       enddo
-    enddo
-
-  END SUBROUTINE upd_tide
+      pot_astro(:,:) = 0._wp          ! update tidal potential (sum of all harmonics)
+      DO jk = 1, nb_harmo   
+         pot_astro(:,:) = pot_astro(:,:) + amp_pot(:,:,jk) * COS( zwt(jk) + phi_pot(:,:,jk) )      
+      END DO
+      !
+      IF( ln_tide_ramp ) THEN         ! linear increase if asked
+         zt = ( kt - nit000 ) * rdt
+         IF( PRESENT( kit ) .AND. PRESENT( kbaro ) )   zt = zt + kit * rdt / REAL( kbaro, wp )
+         zramp = MIN(  MAX( zt / (rdttideramp*rday) , 0._wp ) , 1._wp  )
+         pot_astro(:,:) = zramp * pot_astro(:,:)
+      ENDIF
+      !
+   END SUBROUTINE upd_tide
 
 #else
@@ -68,6 +86,9 @@
   !!----------------------------------------------------------------------
 CONTAINS
-  SUBROUTINE upd_tide( kt,kit )          ! Empty routine
-    INTEGER,INTENT (IN) :: kt, kit
+  SUBROUTINE upd_tide( kt, kit, kbaro, koffset )          ! Empty routine
+    INTEGER, INTENT(in)           ::   kt      !  integer  arg, dummy routine
+    INTEGER, INTENT(in), OPTIONAL ::   kit     !  optional arg, dummy routine
+    INTEGER, INTENT(in), OPTIONAL ::   kbaro   !  optional arg, dummy routine
+    INTEGER, INTENT(in), OPTIONAL ::   koffset !  optional arg, dummy routine
     WRITE(*,*) 'upd_tide: You should not have seen this print! error?', kt
   END SUBROUTINE upd_tide
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/eosbn2.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/eosbn2.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/eosbn2.F90	(revision 4292)
@@ -74,5 +74,5 @@
 CONTAINS
 
-   SUBROUTINE eos_insitu( pts, prd )
+   SUBROUTINE eos_insitu( pts, prd, pdep )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE eos_insitu  ***
@@ -114,4 +114,5 @@
       !                                                      ! 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
@@ -140,5 +141,5 @@
                   zt = pts   (ji,jj,jk,jp_tem)
                   zs = pts   (ji,jj,jk,jp_sal)
-                  zh = fsdept(ji,jj,jk)        ! depth
+                  zh = pdep(ji,jj,jk)        ! depth
                   zsr= zws   (ji,jj,jk)        ! square root salinity
                   !
@@ -198,5 +199,5 @@
 
 
-   SUBROUTINE eos_insitu_pot( pts, prd, prhop )
+   SUBROUTINE eos_insitu_pot( pts, prd, prhop, pdep )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE eos_insitu_pot  ***
@@ -249,4 +250,5 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(  out) ::   prd    ! in situ density            [-]
       REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(  out) ::   prhop  ! potential density (surface referenced)
+      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pdep   ! depth                      [m]
       !
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
@@ -271,5 +273,5 @@
                   zt = pts   (ji,jj,jk,jp_tem)
                   zs = pts   (ji,jj,jk,jp_sal)
-                  zh = fsdept(ji,jj,jk)        ! depth
+                  zh = pdep(ji,jj,jk)        ! depth
                   zsr= zws   (ji,jj,jk)        ! square root salinity
                   !
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traadv.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traadv.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traadv.F90	(revision 4292)
@@ -15,4 +15,5 @@
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
+   USE domvvl          ! variable vertical scale factors
    USE traadv_cen2     ! 2nd order centered scheme (tra_adv_cen2   routine)
    USE traadv_tvd      ! TVD      scheme           (tra_adv_tvd    routine)
@@ -94,4 +95,10 @@
          zwn(:,:,jk) = e1t(:,:) * e2t(:,:)      * wn(:,:,jk)
       END DO
+      !
+      IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
+         zun(:,:,:) = zun(:,:,:) + un_td(:,:,:)
+         zvn(:,:,:) = zvn(:,:,:) + vn_td(:,:,:)
+      ENDIF
+      !
       zun(:,:,jpk) = 0._wp                                                     ! no transport trough the bottom
       zvn(:,:,jpk) = 0._wp                                                     ! no transport trough the bottom
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 4292)
@@ -66,5 +66,4 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   ahu_bbl_0, ahv_bbl_0   ! diffusive bbl flux coefficients at u and v-points
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:), PUBLIC ::   e3u_bbl_0, e3v_bbl_0   ! thichness of the bbl (e3) at u and v-points (PUBLIC for TAM)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:), PUBLIC ::   r1_e1e2t               ! inverse of the cell surface at t-point      [1/m2] (PUBLIC for TAM)
 
    !! * Substitutions
@@ -85,5 +84,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) , r1_e1e2t(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 )
@@ -217,5 +216,5 @@
 #  endif
                ik = mbkt(ji,jj)                            ! bottom T-level index
-               zbtr = r1_e1e2t(ji,jj)  / fse3t(ji,jj,ik)
+               zbtr = r1_e12t(ji,jj)  / fse3t(ji,jj,ik)
                pta(ji,jj,ik,jn) = pta(ji,jj,ik,jn)                                                         &
                   &               + (   ahu_bbl(ji  ,jj  ) * ( zptb(ji+1,jj  ) - zptb(ji  ,jj  ) )   &
@@ -279,15 +278,15 @@
                   !
                   !                                               ! up  -slope T-point (shelf bottom point)
-                  zbtr = r1_e1e2t(iis,jj) / fse3t(iis,jj,ikus)
+                  zbtr = r1_e12t(iis,jj) / fse3t(iis,jj,ikus)
                   ztra = zu_bbl * ( ptb(iid,jj,ikus,jn) - ptb(iis,jj,ikus,jn) ) * zbtr
                   pta(iis,jj,ikus,jn) = pta(iis,jj,ikus,jn) + ztra
                   !
                   DO jk = ikus, ikud-1                            ! down-slope upper to down T-point (deep column)
-                     zbtr = r1_e1e2t(iid,jj) / fse3t(iid,jj,jk)
+                     zbtr = r1_e12t(iid,jj) / fse3t(iid,jj,jk)
                      ztra = zu_bbl * ( ptb(iid,jj,jk+1,jn) - ptb(iid,jj,jk,jn) ) * zbtr
                      pta(iid,jj,jk,jn) = pta(iid,jj,jk,jn) + ztra
                   END DO
                   !
-                  zbtr = r1_e1e2t(iid,jj) / fse3t(iid,jj,ikud)
+                  zbtr = r1_e12t(iid,jj) / fse3t(iid,jj,ikud)
                   ztra = zu_bbl * ( ptb(iis,jj,ikus,jn) - ptb(iid,jj,ikud,jn) ) * zbtr
                   pta(iid,jj,ikud,jn) = pta(iid,jj,ikud,jn) + ztra
@@ -301,15 +300,15 @@
                   !
                   ! up  -slope T-point (shelf bottom point)
-                  zbtr = r1_e1e2t(ji,ijs) / fse3t(ji,ijs,ikvs)
+                  zbtr = r1_e12t(ji,ijs) / fse3t(ji,ijs,ikvs)
                   ztra = zv_bbl * ( ptb(ji,ijd,ikvs,jn) - ptb(ji,ijs,ikvs,jn) ) * zbtr
                   pta(ji,ijs,ikvs,jn) = pta(ji,ijs,ikvs,jn) + ztra
                   !
                   DO jk = ikvs, ikvd-1                            ! down-slope upper to down T-point (deep column)
-                     zbtr = r1_e1e2t(ji,ijd) / fse3t(ji,ijd,jk)
+                     zbtr = r1_e12t(ji,ijd) / fse3t(ji,ijd,jk)
                      ztra = zv_bbl * ( ptb(ji,ijd,jk+1,jn) - ptb(ji,ijd,jk,jn) ) * zbtr
                      pta(ji,ijd,jk,jn) = pta(ji,ijd,jk,jn)  + ztra
                   END DO
                   !                                               ! down-slope T-point (deep bottom point)
-                  zbtr = r1_e1e2t(ji,ijd) / fse3t(ji,ijd,ikvd)
+                  zbtr = r1_e12t(ji,ijd) / fse3t(ji,ijd,ikvd)
                   ztra = zv_bbl * ( ptb(ji,ijs,ikvs,jn) - ptb(ji,ijd,ikvd,jn) ) * zbtr
                   pta(ji,ijd,ikvd,jn) = pta(ji,ijd,ikvd,jn) + ztra
@@ -423,5 +422,5 @@
             ztb (ji,jj) = tsb(ji,jj,ik,jp_tem) * tmask(ji,jj,1)      ! bottom before T and S
             zsb (ji,jj) = tsb(ji,jj,ik,jp_sal) * tmask(ji,jj,1)
-            zdep(ji,jj) = fsdept_0(ji,jj,ik)        ! bottom T-level reference depth
+            zdep(ji,jj) = gdept_0(ji,jj,ik)         ! bottom T-level reference depth
             !
             zub(ji,jj) = un(ji,jj,mbku(ji,jj))      ! bottom velocity
@@ -601,8 +600,4 @@
       IF( nn_eos /= 0 )   CALL ctl_stop ( ' bbl parameterisation requires eos = 0. We stop.' )
 
-
-      !                             !* inverse of surface of T-cells
-      r1_e1e2t(:,:) = 1._wp / ( e1t(:,:) * e2t(:,:) )
-
       !                             !* vertical index of  "deep" bottom u- and v-points
       DO jj = 1, jpjm1                    ! (the "shelf" bottom k-indices are mbku and mbkv)
@@ -612,21 +607,21 @@
          END DO
       END DO
-      ! converte into REAL to use lbc_lnk ; impose a min value of 1 as a zero can be set in lbclnk
+      ! convert 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
+                                     !* 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
-            mgrhu(ji,jj) = INT(  SIGN( 1.e0, fsdept_0(ji+1,jj,mbkt(ji+1,jj)) - fsdept_0(ji,jj,mbkt(ji,jj)) )  )
-            mgrhv(ji,jj) = INT(  SIGN( 1.e0, fsdept_0(ji,jj+1,mbkt(ji,jj+1)) - fsdept_0(ji,jj,mbkt(ji,jj)) )  )
+            mgrhu(ji,jj) = INT(  SIGN( 1.e0, gdept_0(ji+1,jj,mbkt(ji+1,jj)) - gdept_0(ji,jj,mbkt(ji,jj)) )  )
+            mgrhv(ji,jj) = INT(  SIGN( 1.e0, gdept_0(ji,jj+1,mbkt(ji,jj+1)) - gdept_0(ji,jj,mbkt(ji,jj)) )  )
          END DO
       END DO
 
       DO jj = 1, jpjm1              !* bbl thickness at u- (v-) point
-         DO ji = 1, jpim1                 ! minimum of top & bottom e3u_0 (e3v_0)
-            e3u_bbl_0(ji,jj) = MIN( fse3u_0(ji,jj,mbkt(ji+1,jj  )), fse3u_0(ji,jj,mbkt(ji,jj)) )
-            e3v_bbl_0(ji,jj) = MIN( fse3v_0(ji,jj,mbkt(ji  ,jj+1)), fse3v_0(ji,jj,mbkt(ji,jj)) )
+         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)) )
          END DO
       END DO
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 4292)
@@ -795,7 +795,7 @@
       clname = 'dist.coast'
       itime  = 0
-      CALL ymds2ju( 0     , 1      , 1     , 0._wp , zdate0 )
-      CALL restini( 'NONE', jpi    , jpj   , glamt, gphit ,   &
-         &          jpk   , gdept_0, clname, itime, zdate0,   &
+      CALL ymds2ju( 0     , 1       , 1     , 0._wp , zdate0 )
+      CALL restini( 'NONE', jpi     , jpj   , glamt, gphit ,   &
+         &          jpk   , gdept_1d, clname, itime, zdate0,   &
          &          rdt   , icot                         )
       CALL restput( icot, 'Tcoast', jpi, jpj, jpk, 0, pdct )
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_bilap.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_bilap.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_bilap.F90	(revision 4292)
@@ -110,6 +110,6 @@
             DO jj = 1, jpjm1
                DO ji = 1, fs_jpim1   ! vector opt.
-                  zeeu(ji,jj) = e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj) * umask(ji,jj,jk)
-                  zeev(ji,jj) = e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj) * vmask(ji,jj,jk)
+                  zeeu(ji,jj) = re2u_e1u(ji,jj) * fse3u_n(ji,jj,jk) * umask(ji,jj,jk)
+                  zeev(ji,jj) = re1v_e2v(ji,jj) * fse3v_n(ji,jj,jk) * vmask(ji,jj,jk)
                END DO
             END DO
@@ -133,5 +133,5 @@
             DO jj = 2, jpjm1                 ! Second derivative (divergence) time the eddy diffusivity coefficient
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zbtr = 1.0 / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  zbtr = 1.0 / ( e12t(ji,jj) * fse3t_n(ji,jj,jk) )
                   zlt(ji,jj) = fsahtt(ji,jj,jk) * zbtr * (   ztu(ji,jj,jk) - ztu(ji-1,jj,jk)   &
                      &                                     + ztv(ji,jj,jk) - ztv(ji,jj-1,jk)   )
@@ -151,5 +151,5 @@
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   ! horizontal diffusive trends
-                  zbtr = 1.0 / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  zbtr = 1.0 / ( e12t(ji,jj) * fse3t_n(ji,jj,jk) )
                   ztra = zbtr * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk) + ztv(ji,jj,jk) - ztv(ji,jj-1,jk)  )
                   ! add it to the general tracer trends
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_bilapg.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_bilapg.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_bilapg.F90	(revision 4292)
@@ -210,6 +210,6 @@
             DO jj = 1, jpjm1
                DO ji = 1, jpim1
-                  zabe1 = e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj)
-                  zabe2 = e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj)
+                  zabe1 = re2u_e1u(ji,jj) * fse3u_n(ji,jj,jk)
+                  zabe2 = re1v_e2v(ji,jj) * fse3v_n(ji,jj,jk)
                   
                   zmku = 1./MAX( tmask(ji+1,jj,jk  )+tmask(ji,jj,jk+1)   &
@@ -279,5 +279,5 @@
             DO jk = 2, jpkm1
                DO ji = 2, jpim1
-                  zcof0 = e1t(ji,jj) * e2t(ji,jj) / fse3w(ji,jj,jk)   &
+                  zcof0 = e12t(ji,jj) / fse3w_n(ji,jj,jk)   &
                      &     * (  wslpi(ji,jj,jk) * wslpi(ji,jj,jk)        &
                      &        + wslpj(ji,jj,jk) * wslpj(ji,jj,jk)  )
@@ -310,5 +310,5 @@
                   DO ji = 2, jpim1
                      ! eddy coef. divided by the volume element
-                     zbtr = 1.0 / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                     zbtr = 1.0 / ( e12t(ji,jj) * fse3t_n(ji,jj,jk) )
                      ! vertical divergence
                      ztav = fsahtt(ji,jj,jk) * ( zftw(ji,jk) - zftw(ji,jk+1) )
@@ -322,5 +322,5 @@
                   DO ji = 2, jpim1
                      ! inverse of the volume element
-                     zbtr = 1.0 / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                     zbtr = 1.0 / ( e12t(ji,jj) * fse3t_n(ji,jj,jk) )
                      ! vertical divergence
                      ztav = zftw(ji,jk) - zftw(ji,jk+1)
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso.F90	(revision 4292)
@@ -176,6 +176,6 @@
             DO jj = 1 , jpjm1
                DO ji = 1, fs_jpim1   ! vector opt.
-                  zabe1 = ( fsahtu(ji,jj,jk) + pahtb0 ) * e2u(ji,jj) * fse3u(ji,jj,jk) / e1u(ji,jj)
-                  zabe2 = ( fsahtv(ji,jj,jk) + pahtb0 ) * e1v(ji,jj) * fse3v(ji,jj,jk) / e2v(ji,jj)
+                  zabe1 = ( fsahtu(ji,jj,jk) + pahtb0 ) * re2u_e1u(ji,jj) * fse3u_n(ji,jj,jk)
+                  zabe2 = ( fsahtv(ji,jj,jk) + pahtb0 ) * re1v_e2v(ji,jj) * fse3v_n(ji,jj,jk)
                   !
                   zmsku = 1. / MAX(  tmask(ji+1,jj,jk  ) + tmask(ji,jj,jk+1)   &
@@ -201,5 +201,5 @@
             DO jj = 2 , jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zbtr = 1.0 / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  zbtr = 1.0 / ( e12t(ji,jj) * fse3t_n(ji,jj,jk) )
                   ztra = zbtr * ( zftu(ji,jj,jk) - zftu(ji-1,jj,jk) + zftv(ji,jj,jk) - zftv(ji,jj-1,jk)  )
                   pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + ztra
@@ -288,5 +288,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zbtr = 1.0 / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  zbtr = 1.0 / ( e12t(ji,jj) * fse3t_n(ji,jj,jk) )
                   ztra = (  ztfw(ji,jj,jk) - ztfw(ji,jj,jk+1)  ) * zbtr
                   pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + ztra
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_lap.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_lap.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_lap.F90	(revision 4292)
@@ -31,6 +31,4 @@
 
    PUBLIC   tra_ldf_lap   ! routine called by step.F90
-
-   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:) ::   e1ur, e2vr   ! scale factor coefficients
 
    !! * Substitutions
@@ -85,15 +83,4 @@
          IF(lwp) WRITE(numout,*) 'tra_ldf_lap : iso-level laplacian diffusion on ', cdtype
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
-         !
-         IF( .NOT. ALLOCATED( e1ur ) ) THEN
-            ! This routine may be called for both active and passive tracers. 
-            ! Allocate and set saved arrays on first call only.
-            ALLOCATE( e1ur(jpi,jpj), e2vr(jpi,jpj), STAT=ierr )
-            IF( lk_mpp    )   CALL mpp_sum( ierr )
-            IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'tra_ldf_lap : unable to allocate arrays' )
-            !
-            e1ur(:,:) = e2u(:,:) / e1u(:,:)
-            e2vr(:,:) = e1v(:,:) / e2v(:,:)
-         ENDIF
       ENDIF
 
@@ -107,6 +94,6 @@
             DO jj = 1, jpjm1
                DO ji = 1, fs_jpim1   ! vector opt.
-                  zabe1 = fsahtu(ji,jj,jk) * umask(ji,jj,jk) * e1ur(ji,jj) * fse3u(ji,jj,jk)
-                  zabe2 = fsahtv(ji,jj,jk) * vmask(ji,jj,jk) * e2vr(ji,jj) * fse3v(ji,jj,jk)
+                  zabe1 = fsahtu(ji,jj,jk) * umask(ji,jj,jk) * re2u_e1u(ji,jj) * fse3u_n(ji,jj,jk)
+                  zabe2 = fsahtv(ji,jj,jk) * vmask(ji,jj,jk) * re1v_e2v(ji,jj) * fse3v_n(ji,jj,jk)
                   ztu(ji,jj,jk) = zabe1 * ( ptb(ji+1,jj  ,jk,jn) - ptb(ji,jj,jk,jn) )
                   ztv(ji,jj,jk) = zabe2 * ( ptb(ji  ,jj+1,jk,jn) - ptb(ji,jj,jk,jn) )
@@ -120,9 +107,9 @@
                      ikv = mbkv(ji,jj)
                      IF( iku == jk ) THEN
-                        zabe1 = fsahtu(ji,jj,iku) * umask(ji,jj,iku) * e1ur(ji,jj) * fse3u(ji,jj,iku)
+                        zabe1 = fsahtu(ji,jj,iku) * umask(ji,jj,iku) * re2u_e1u(ji,jj) * fse3u_n(ji,jj,iku)
                         ztu(ji,jj,jk) = zabe1 * pgu(ji,jj,jn)
                      ENDIF
                      IF( ikv == jk ) THEN
-                        zabe2 = fsahtv(ji,jj,ikv) * vmask(ji,jj,ikv) * e2vr(ji,jj) * fse3v(ji,jj,ikv)
+                        zabe2 = fsahtv(ji,jj,ikv) * vmask(ji,jj,ikv) * re1v_e2v(ji,jj) * fse3v_n(ji,jj,ikv)
                         ztv(ji,jj,jk) = zabe2 * pgv(ji,jj,jn)
                      ENDIF
@@ -136,5 +123,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zbtr = 1._wp / ( e1t(ji,jj) *e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  zbtr = 1._wp / ( e12t(ji,jj) * fse3t_n(ji,jj,jk) )
                   ! horizontal diffusive trends added to the general tracer trends
                   pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + zbtr * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk)   &
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 4292)
@@ -466,5 +466,5 @@
             ENDIF
 
-            IF(lwp) WRITE(numout,*) '        level of light extinction = ', nksr, ' ref depth = ', gdepw_0(nksr+1), ' m'
+            IF(lwp) WRITE(numout,*) '        level of light extinction = ', nksr, ' ref depth = ', gdepw_1d(nksr+1), ' m'
             !
             IF( nn_chldta == 1 ) THEN           !* Chl data : set sf_chl structure
@@ -507,8 +507,8 @@
 !CDIR NOVERRCHK   
                         DO ji = 1, jpi
-                           zc0 = ze0(ji,jj,jk-1) * EXP( - fse3t_0(ji,jj,jk-1) * xsi0r     )
-                           zc1 = ze1(ji,jj,jk-1) * EXP( - fse3t_0(ji,jj,jk-1) * zekb(ji,jj) )
-                           zc2 = ze2(ji,jj,jk-1) * EXP( - fse3t_0(ji,jj,jk-1) * zekg(ji,jj) )
-                           zc3 = ze3(ji,jj,jk-1) * EXP( - fse3t_0(ji,jj,jk-1) * zekr(ji,jj) )
+                           zc0 = ze0(ji,jj,jk-1) * EXP( - e3t_0(ji,jj,jk-1) * xsi0r     )
+                           zc1 = ze1(ji,jj,jk-1) * EXP( - e3t_0(ji,jj,jk-1) * zekb(ji,jj) )
+                           zc2 = ze2(ji,jj,jk-1) * EXP( - e3t_0(ji,jj,jk-1) * zekg(ji,jj) )
+                           zc3 = ze3(ji,jj,jk-1) * EXP( - e3t_0(ji,jj,jk-1) * zekr(ji,jj) )
                            ze0(ji,jj,jk) = zc0
                            ze1(ji,jj,jk) = zc1
@@ -536,5 +536,5 @@
             IF(lwp) THEN
                WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) '        level of light extinction = ', nksr, ' ref depth = ', gdepw_0(nksr+1), ' m'
+            IF(lwp) WRITE(numout,*) '        level of light extinction = ', nksr, ' ref depth = ', gdepw_1d(nksr+1), ' m'
             ENDIF
             !
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfini.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfini.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfini.F90	(revision 4292)
@@ -154,5 +154,5 @@
       ELSE                                  ! Background profile of avt (fit a theoretical/observational profile (Krauss 1990)
          avmb(:) = rn_avm0
-         avtb(:) = rn_avt0 + ( 3.e-4_wp - 2._wp * rn_avt0 ) * 1.e-4_wp * gdepw_0(:)   ! m2/s
+         avtb(:) = rn_avt0 + ( 3.e-4_wp - 2._wp * rn_avt0 ) * 1.e-4_wp * gdepw_1d(:)   ! m2/s
          IF(ln_sco .AND. lwp)   CALL ctl_warn( 'avtb profile not valid in sco' )
       ENDIF
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 4292)
@@ -385,9 +385,10 @@
                             CALL  istate_init   ! ocean initial state (Dynamics and tracers)
 
-      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     bdytide_init   ! Open boundaries initialisation of tidal harmonic forcing
+      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 .AND. lk_tide )   &
+         &                  CALL  bdytide_init  ! Open boundaries initialisation of tidal harmonic forcing
 
                             CALL dyn_nept_init  ! simplified form of Neptune effect
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/oce.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/oce.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/oce.F90	(revision 4292)
@@ -22,4 +22,5 @@
    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]
@@ -36,7 +37,4 @@
    !! ------------                                      !  fields  ! fields ! trends !
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:), TARGET ::   sshb   , sshn   , ssha   !: sea surface height at t-point [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   sshu_b , sshu_n , sshu_a !: sea surface height at u-point [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::   sshv_b , sshv_n , sshv_a !: sea surface height at u-point [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)         ::            sshf_n          !: sea surface height at f-point [m]
    !
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   spgu, spgv               !: horizontal surface pressure gradient
@@ -76,4 +74,5 @@
       ALLOCATE( ub   (jpi,jpj,jpk)      , un   (jpi,jpj,jpk)      , ua(jpi,jpj,jpk)       ,     &
          &      vb   (jpi,jpj,jpk)      , vn   (jpi,jpj,jpk)      , va(jpi,jpj,jpk)       ,     &      
+         &      ua_sv(jpi,jpj,jpk)      , va_sv(jpi,jpj,jpk)      ,                             &      
          &      wn   (jpi,jpj,jpk)      ,                                                       &
          &      rotb (jpi,jpj,jpk)      , rotn (jpi,jpj,jpk)      ,                             &   
@@ -82,14 +81,10 @@
          &      rn2b (jpi,jpj,jpk)      , rn2  (jpi,jpj,jpk)                              , STAT=ierr(1) )
          !
-      ALLOCATE( rhd (jpi,jpj,jpk) ,                                         &
-         &      rhop(jpi,jpj,jpk) ,                                         &
-         &      rke (jpi,jpj,jpk) ,                                         &
-         &      sshb  (jpi,jpj)   , sshn  (jpi,jpj) , ssha  (jpi,jpj) ,     &
-         &      sshu_b(jpi,jpj)   , sshu_n(jpi,jpj) , sshu_a(jpi,jpj) ,     &
-         &      sshv_b(jpi,jpj)   , sshv_n(jpi,jpj) , sshv_a(jpi,jpj) ,     &
-         &                          sshf_n(jpi,jpj) ,                       &
-         &      spgu  (jpi,jpj)   , spgv(jpi,jpj)   ,                       &
-         &      gtsu(jpi,jpj,jpts), gtsv(jpi,jpj,jpts),                     &
-         &      gru(jpi,jpj)      , grv(jpi,jpj)                      , STAT=ierr(2) )
+      ALLOCATE(rhd (jpi,jpj,jpk) ,                                         &
+         &     rhop(jpi,jpj,jpk) ,                                         &
+         &     sshb  (jpi,jpj)   , sshn  (jpi,jpj) , ssha  (jpi,jpj) ,     &
+         &     spgu  (jpi,jpj)   , spgv(jpi,jpj)   ,                       &
+         &     gtsu(jpi,jpj,jpts), gtsv(jpi,jpj,jpts),                     &
+         &     gru(jpi,jpj)      , grv(jpi,jpj)                      , STAT=ierr(2) )
          !
       ALLOCATE( snwice_mass(jpi,jpj) , snwice_mass_b(jpi,jpj), snwice_fmass(jpi,jpj) , STAT=ierr(3) )
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/step.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 4292)
@@ -95,16 +95,50 @@
       ! Update data, open boundaries, surface boundary condition (including sea-ice)
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF( lk_tide    )   CALL sbc_tide( kstp )
+      IF( lk_obc     )   CALL obc_dta ( kstp )        ! update dynamic and tracer data at open boundaries
+      IF( lk_obc     )   CALL obc_rad ( kstp )        ! compute phase velocities at open boundaries
+      IF( lk_bdy     )   CALL bdy_dta ( kstp, time_offset=+1 )   ! update dynamic & tracer data at open boundaries
+
                          CALL sbc    ( kstp )         ! Sea Boundary Condition (including sea-ice)
-
-      IF( lk_tide.AND.(kstp /= nit000 ))   CALL tide_init ( kstp )
-      IF( lk_tide    )   CALL sbc_tide( kstp )
-      IF( lk_obc     )   CALL obc_dta( kstp )         ! update dynamic and tracer data at open boundaries
-      IF( lk_obc     )   CALL obc_rad( kstp )         ! compute phase velocities at open boundaries
-      IF( lk_bdy     )   CALL bdy_dta( kstp, time_offset=+1 ) ! update dynamic and tracer data at open boundaries
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      !  Ocean dynamics : ssh, wn, hdiv, rot                                 !
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL ssh_wzv( kstp )         ! after ssh & vertical velocity
+                                                      ! clem: moved here for bdy ice purpose
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      !  Ocean dynamics : hdiv, rot, ssh, e3, wn
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                         CALL zdf_bfr( kstp )         ! bottom friction (if quadratic)
+                         CALL ssh_nxt       ( kstp )  ! after ssh (includes call to div_cur)
+      IF( lk_dynspg_ts ) THEN
+                                  CALL wzv           ( kstp )  ! now cross-level velocity 
+          ! In case the time splitting case, update almost all momentum trends here:
+          ! Note that the computation of vertical velocity above, hence "after" sea level
+          ! is necessary to compute momentum advection for the rhs of barotropic loop:
+                                  CALL eos    ( tsn, rhd, rhop )                 ! now in situ density for hpg computation
+          IF( ln_zps      )       CALL zps_hde( kstp, jpts, tsn, gtsu, gtsv,  &  ! zps: now hor. derivative
+                &                                          rhd, gru , grv  )     ! of t, s, rd at the last ocean level
+
+                                  ua(:,:,:) = 0.e0             ! set dynamics trends to zero
+                                  va(:,:,:) = 0.e0
+          IF(  ln_asmiau .AND. &
+             & ln_dyninc       )  CALL dyn_asm_inc  ( kstp )   ! apply dynamics assimilation increment
+          IF( ln_neptsimp )       CALL dyn_nept_cor ( kstp )   ! subtract Neptune velocities (simplified)
+          IF( lk_bdy           )  CALL bdy_dyn3d_dmp( kstp )   ! bdy damping trends
+                                  CALL dyn_adv      ( kstp )   ! advection (vector or flux form)
+                                  CALL dyn_vor      ( kstp )   ! vorticity term including Coriolis
+                                  CALL dyn_ldf      ( kstp )   ! lateral mixing
+          IF( ln_neptsimp )       CALL dyn_nept_cor ( kstp )   ! add Neptune velocities (simplified)
+#if defined key_agrif
+          IF(.NOT. Agrif_Root())  CALL Agrif_Sponge_dyn        ! momentum sponge
+#endif
+                                  CALL dyn_hpg( kstp )         ! horizontal gradient of Hydrostatic pressure
+                                  CALL dyn_spg( kstp, indic )  ! surface pressure gradient
+
+                                  hdivb(:,:,:) = hdivn(:,:,:)  ! Store now divergence and rot temporarly, revert to these below 
+                                  rotb(:,:,:)  = rotn(:,:,:)     
+                                  ua_sv(:,:,:) = ua(:,:,:)     ! Save trends (barotropic trend has been fully updated)
+                                  va_sv(:,:,:) = va(:,:,:)
+
+                                  CALL div_cur( kstp )         ! Horizontal divergence & Relative vorticity (2nd call in time-split case)
+      ENDIF
+      IF( lk_vvl     )   CALL dom_vvl_sf_nxt( kstp )  ! after vertical scale factors
+                         CALL wzv           ( kstp )  ! now cross-level velocity (original)
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -115,6 +149,4 @@
       !
       !  VERTICAL PHYSICS
-                         CALL zdf_bfr( kstp )         ! bottom friction
-
       !                                               ! Vertical eddy viscosity and diffusivity coefficients
       IF( lk_zdfric  )   CALL zdf_ric( kstp )            ! Richardson number dependent Kz
@@ -122,5 +154,5 @@
       IF( lk_zdfgls  )   CALL zdf_gls( kstp )            ! GLS closure scheme for Kz
       IF( lk_zdfkpp  )   CALL zdf_kpp( kstp )            ! KPP closure scheme for Kz
-      IF( lk_zdfcst  )   THEN                            ! Constant Kz (reset avt, avm[uv] to the background value)
+      IF( lk_zdfcst  ) THEN                              ! Constant Kz (reset avt, avm[uv] to the background value)
          avt (:,:,:) = rn_avt0 * tmask(:,:,:)
          avmu(:,:,:) = rn_avm0 * umask(:,:,:)
@@ -146,5 +178,5 @@
       !
       IF( lk_ldfslp ) THEN                            ! slope of lateral mixing
-                         CALL eos( tsb, rhd )                ! before in situ density
+                         CALL eos( tsb, rhd, gdept_0(:,:,:) )             ! before in situ density
          IF( ln_zps )    CALL zps_hde( kstp, jpts, tsb, gtsu, gtsv,  &    ! Partial steps: before horizontal gradient
             &                                      rhd, gru , grv  )      ! of t, s, rd at the last ocean level
@@ -193,7 +225,4 @@
                              tsa(:,:,:,:) = 0.e0            ! set tracer trends to zero
 
-!write(numout,*) "MAV kt",kstp
-!write(numout,'(a5,3(1x,f21.18))') "INIn:",tsn(24,11,1,jp_tem),tsn(24,11,1,jp_sal),sshn(24,11)
-!write(numout,'(a5,3(1x,f21.18))') "INIa:",tsa(24,11,1,jp_tem),tsa(24,11,1,jp_sal),ssha(24,11)
       IF(  ln_asmiau .AND. &
          & ln_trainc     )   CALL tra_asm_inc( kstp )       ! apply tracer assimilation increment
@@ -205,36 +234,26 @@
       IF( lk_bdy         )   CALL bdy_tra_dmp( kstp )       ! bdy damping trends
                              CALL tra_adv    ( kstp )       ! horizontal & vertical advection
-!write(numout,'(a5,3(1x,f21.18))') "ADVn:",tsn(24,11,1,jp_tem),tsn(24,11,1,jp_sal),sshn(24,11)
-!write(numout,'(a5,3(1x,f21.18))') "ADVa:",tsa(24,11,1,jp_tem),tsa(24,11,1,jp_sal),ssha(24,11)
       IF( lk_zdfkpp      )   CALL tra_kpp    ( kstp )       ! KPP non-local tracer fluxes
                              CALL tra_ldf    ( kstp )       ! lateral mixing
-!write(numout,'(a5,3(1x,f21.18))') "LDFn:",tsn(24,11,1,jp_tem),tsn(24,11,1,jp_sal),sshn(24,11)
-!write(numout,'(a5,3(1x,f21.18))') "LDFa:",tsa(24,11,1,jp_tem),tsa(24,11,1,jp_sal),ssha(24,11)
 #if defined key_agrif
       IF(.NOT. Agrif_Root()) CALL Agrif_Sponge_tra          ! tracers sponge
 #endif
                              CALL tra_zdf    ( kstp )       ! vertical mixing and after tracer fields
-!do jk=1,jpk
-!write(numout,'(a5,3(1x,f21.18))') "ZDFn:",tsn(5,10,jk,jp_tem),tsn(5,10,jk,jp_sal),tmask(5,10,jk)
-!write(numout,'(a5,3(1x,f21.18))') "ZDFa:",tsa(5,10,jk,jp_tem),tsa(5,10,jk,jp_sal),ssha(5,10)
-!end do
 
       IF( ln_dynhpg_imp  ) THEN                             ! semi-implicit hpg (time stepping then eos)
          IF( ln_zdfnpc   )   CALL tra_npc( kstp )                ! update after fields by non-penetrative convection
                              CALL tra_nxt( kstp )                ! tracer fields at next time step
-                             CALL eos    ( tsa, rhd, rhop )      ! Time-filtered in situ density for hpg computation
+                             CALL eos    ( tsa, rhd, rhop, fsdept_n(:,:,:) )  ! Time-filtered in situ density for hpg computation
          IF( ln_zps      )   CALL zps_hde( kstp, jpts, tsa, gtsu, gtsv,  &    ! zps: time filtered hor. derivative
             &                                          rhd, gru , grv  )      ! of t, s, rd at the last ocean level
 
       ELSE                                                  ! centered hpg  (eos then time stepping)
-                             CALL eos    ( tsn, rhd, rhop )      ! now in situ density for hpg computation
-         IF( ln_zps      )   CALL zps_hde( kstp, jpts, tsn, gtsu, gtsv,  &    ! zps: now hor. derivative
+         IF ( .NOT. lk_dynspg_ts ) THEN                     ! eos already called in time-split case
+                                CALL eos    ( tsn, rhd, rhop, fsdept_n(:,:,:) )  ! now in situ density for hpg computation
+            IF( ln_zps      )   CALL zps_hde( kstp, jpts, tsn, gtsu, gtsv,  &    ! zps: now hor. derivative
             &                                          rhd, gru , grv  )      ! of t, s, rd at the last ocean level
-!write(numout,'(a5,3(1x,f21.18))') "ZPSn:",tsn(24,11,1,jp_tem),tsn(24,11,1,jp_sal),sshn(24,11)
-!write(numout,'(a5,3(1x,f21.18))') "ZPSa:",tsa(24,11,1,jp_tem),tsa(24,11,1,jp_sal),ssha(24,11)
+         ENDIF
          IF( ln_zdfnpc   )   CALL tra_npc( kstp )                ! update after fields by non-penetrative convection
                              CALL tra_nxt( kstp )                ! tracer fields at next time step
-!write(numout,'(a5,3(1x,f21.18))') "NXTn:",tsn(24,11,1,jp_tem),tsn(24,11,1,jp_sal),sshn(25,11)
-!write(numout,'(a5,3(1x,f21.18))') "NXTa:",tsa(24,11,1,jp_tem),tsa(24,11,1,jp_sal),ssha(24,11)
       ENDIF
 
@@ -242,18 +261,31 @@
       ! Dynamics                                    (tsa used as workspace)
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF( lk_dynspg_ts   )  THEN
+                                                             ! revert to previously computed momentum tendencies
+                                                             ! (not using ua, va as temporary arrays during tracers' update could avoid that)
+                               ua(:,:,:) = ua_sv(:,:,:)
+                               va(:,:,:) = va_sv(:,:,:)
+                                                             ! Revert now divergence and rotational to previously computed ones 
+                                                             !(needed because of the time swap in div_cur, at the beginning of each time step)
+                               hdivn(:,:,:) = hdivb(:,:,:)
+                               rotn(:,:,:)  = rotb(:,:,:) 
+
+                               CALL dyn_bfr( kstp )         ! bottom friction
+                               CALL dyn_zdf( kstp )         ! vertical diffusion
+      ELSE
                                ua(:,:,:) = 0.e0             ! set dynamics trends to zero
                                va(:,:,:) = 0.e0
 
-      IF(  ln_asmiau .AND. &
-         & ln_dyninc       )   CALL dyn_asm_inc( kstp )     ! apply dynamics assimilation increment
-      IF( ln_bkgwri )          CALL asm_bkg_wri( kstp )     ! output background fields
-      IF( ln_neptsimp )        CALL dyn_nept_cor( kstp )    ! subtract Neptune velocities (simplified)
-      IF( lk_bdy           )   CALL bdy_dyn3d_dmp(kstp )    ! bdy damping trends
+        IF(  ln_asmiau .AND. &
+           & ln_dyninc      )  CALL dyn_asm_inc( kstp )     ! apply dynamics assimilation increment
+        IF( ln_bkgwri )        CALL asm_bkg_wri( kstp )     ! output background fields
+        IF( ln_neptsimp )      CALL dyn_nept_cor( kstp )    ! subtract Neptune velocities (simplified)
+        IF( lk_bdy          )  CALL bdy_dyn3d_dmp(kstp )    ! bdy damping trends
                                CALL dyn_adv( kstp )         ! advection (vector or flux form)
                                CALL dyn_vor( kstp )         ! vorticity term including Coriolis
                                CALL dyn_ldf( kstp )         ! lateral mixing
-      IF( ln_neptsimp )        CALL dyn_nept_cor( kstp )    ! add Neptune velocities (simplified)
-#if defined key_agrif
-      IF(.NOT. Agrif_Root())   CALL Agrif_Sponge_dyn        ! momemtum sponge
+        IF( ln_neptsimp )      CALL dyn_nept_cor( kstp )    ! add Neptune velocities (simplified)
+#if defined key_agrif
+        IF(.NOT. Agrif_Root()) CALL Agrif_Sponge_dyn        ! momemtum sponge
 #endif
                                CALL dyn_hpg( kstp )         ! horizontal gradient of Hydrostatic pressure
@@ -261,7 +293,9 @@
                                CALL dyn_zdf( kstp )         ! vertical diffusion
                                CALL dyn_spg( kstp, indic )  ! surface pressure gradient
+      ENDIF
                                CALL dyn_nxt( kstp )         ! lateral velocity at next time step
 
-                               CALL ssh_nxt( kstp )         ! sea surface height at next time step
+                               CALL ssh_swp( kstp )         ! swap of sea surface height
+      IF( lk_vvl           )   CALL dom_vvl_sf_swp( kstp )  ! swap of vertical scale factors
 
       IF( ln_diahsb        )   CALL dia_hsb( kstp )         ! - ML - global conservation diagnostics
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/step_oce.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 4292)
@@ -11,4 +11,5 @@
    USE ldftra_oce       ! ocean tracer   - trends
    USE ldfdyn_oce       ! ocean dynamics - trends
+   USE divcur           ! hor. divergence and curl      (div & cur routines)
    USE in_out_manager   ! I/O manager
    USE iom              !
@@ -64,5 +65,9 @@
    USE bdydyn3d         ! bdy cond. for baroclinic vel.  (bdy_dyn3d routine)
 
-   USE sshwzv           ! vertical velocity and ssh        (ssh_wzv routine)
+   USE sshwzv           ! vertical velocity and ssh        (ssh_nxt routine)
+   !                                                       (ssh_swp routine)
+   !                                                       (wzv     routine)
+   USE domvvl           ! variable vertical scale factors  (dom_vvl_sf_nxt routine)
+   !                                                       (dom_vvl_sf_swp routine)
 
    USE ldfslp           ! iso-neutral slopes               (ldf_slp routine)
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/SAS_SRC/diawri.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/SAS_SRC/diawri.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/SAS_SRC/diawri.F90	(revision 4292)
@@ -220,5 +220,5 @@
             &          nit000-1, zjulian, zdt, nh_T, nid_T, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_T, "deptht", "Vertical T levels",      &  ! Vertical grid: gdept
-            &           "m", ipk, gdept_0, nz_T, "down" )
+            &           "m", ipk, gdept_1d, nz_T, "down" )
          !                                                            ! Index of ocean points
          CALL wheneq( jpi*jpj    , tmask, 1, 1., ndex_hT, ndim_hT )      ! surface
@@ -232,5 +232,5 @@
             &          nit000-1, zjulian, zdt, nh_U, nid_U, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_U, "depthu", "Vertical U levels",      &  ! Vertical grid: gdept
-            &           "m", ipk, gdept_0, nz_U, "down" )
+            &           "m", ipk, gdept_1d, nz_U, "down" )
          !                                                            ! Index of ocean points
          CALL wheneq( jpi*jpj    , umask, 1, 1., ndex_hU, ndim_hU )      ! surface
@@ -244,5 +244,5 @@
             &          nit000-1, zjulian, zdt, nh_V, nid_V, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_V, "depthv", "Vertical V levels",      &  ! Vertical grid : gdept
-            &          "m", ipk, gdept_0, nz_V, "down" )
+            &          "m", ipk, gdept_1d, nz_V, "down" )
          !                                                            ! Index of ocean points
          CALL wheneq( jpi*jpj    , vmask, 1, 1., ndex_hV, ndim_hV )      ! surface
@@ -394,5 +394,5 @@
           1, jpi, 1, jpj, nit000-1, zjulian, zdt, nh_i, id_i, domain_id=nidom, snc4chunks=snc4set ) ! Horizontal grid : glamt and gphit
       CALL histvert( id_i, "deptht", "Vertical T levels",   &    ! Vertical grid : gdept
-          "m", jpk, gdept_0, nz_i, "down")
+          "m", jpk, gdept_1d, nz_i, "down")
 
       ! Declare all the output fields as NetCDF variables
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/C14b/trcwri_c14b.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/C14b/trcwri_c14b.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/C14b/trcwri_c14b.F90	(revision 4292)
@@ -36,5 +36,9 @@
       DO jn = jp_c14b0, jp_c14b1
          cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
-         CALL iom_put( cltra, trn(:,:,:,jn) )
+         IF( lk_vvl ) THEN
+            CALL iom_put( cltra, trn(:,:,:,jn) * fse3t_n(:,:,:) )
+         ELSE
+            CALL iom_put( cltra, trn(:,:,:,jn) )
+         ENDIF
       END DO
       !
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/CFC/trcwri_cfc.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/CFC/trcwri_cfc.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/CFC/trcwri_cfc.F90	(revision 4292)
@@ -36,5 +36,9 @@
       DO jn = jp_cfc0, jp_cfc1
          cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
-         CALL iom_put( cltra, trn(:,:,:,jn) )
+         IF( lk_vvl ) THEN
+            CALL iom_put( cltra, trn(:,:,:,jn) * fse3t_n(:,:,:) )
+         ELSE
+            CALL iom_put( cltra, trn(:,:,:,jn) )
+         ENDIF
       END DO
       !
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcwri_my_trc.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcwri_my_trc.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/MY_TRC/trcwri_my_trc.F90	(revision 4292)
@@ -36,5 +36,9 @@
       DO jn = jp_myt0, jp_myt1
          cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
-         CALL iom_put( cltra, trn(:,:,:,jn) )
+         IF( lk_vvl ) THEN
+            CALL iom_put( cltra, trn(:,:,:,jn) * fse3t_n(:,:,:) )
+         ELSE
+            CALL iom_put( cltra, trn(:,:,:,jn) )
+         ENDIF
       END DO
       !
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zopt.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zopt.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zopt.F90	(revision 4292)
@@ -371,5 +371,5 @@
       nksrp = trc_oce_ext_lev( r_si2, 0.33e2 )     ! max level of light extinction (Blue Chl=0.01)
       !
-      IF(lwp) WRITE(numout,*) '        level of light extinction = ', nksrp, ' ref depth = ', gdepw_0(nksrp+1), ' m'
+      IF(lwp) WRITE(numout,*) '        level of light extinction = ', nksrp, ' ref depth = ', gdepw_1d(nksrp+1), ' m'
       !
                          etot (:,:,:) = 0._wp
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/PISCES/SED/sed.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/PISCES/SED/sed.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/PISCES/SED/sed.F90	(revision 4292)
@@ -19,5 +19,5 @@
    USE dom_oce , ONLY :   glamt     =>   glamt          !: longitude of t-point (degre)
    USE dom_oce , ONLY :   gphit     =>   gphit          !: latitude  of t-point (degre)
-   USE dom_oce , ONLY :   e3t_0     =>   e3t_0          !: reference depth of t-points (m)
+   USE dom_oce , ONLY :   e3t_1d    =>   e3t_1d         !: reference depth of t-points (m)
    USE dom_oce , ONLY :   mbkt      =>   mbkt           !: vertical index of the bottom last T- ocean level
    USE dom_oce , ONLY :   tmask     =>   tmask          !: land/ocean mask at t-points
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/PISCES/SED/sedini.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/PISCES/SED/sedini.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/PISCES/SED/sedini.F90	(revision 4292)
@@ -142,5 +142,5 @@
          DO ji = 1, jpi
             ikt = mbkt(ji,jj) 
-            IF( tmask(ji,jj,ikt) == 1 ) epkbot(ji,jj) = e3t_0(ikt)
+            IF( tmask(ji,jj,ikt) == 1 ) epkbot(ji,jj) = e3t_1d(ikt)
          ENDDO
       ENDDO
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/PISCES/trcwri_pisces.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/PISCES/trcwri_pisces.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/PISCES/trcwri_pisces.F90	(revision 4292)
@@ -21,4 +21,5 @@
    PUBLIC trc_wri_pisces 
 
+#  include "top_substitute.h90"
 CONTAINS
 
@@ -39,4 +40,9 @@
       DO jn = jp_pcs0, jp_pcs1
          cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
+         IF( lk_vvl ) THEN
+            CALL iom_put( cltra, trn(:,:,:,jn) * fse3t_n(:,:,:) )
+         ELSE
+            CALL iom_put( cltra, trn(:,:,:,jn) )
+         ENDIF
          CALL iom_put( cltra, trn(:,:,:,jn) * zrfact )
       END DO
@@ -47,5 +53,9 @@
          IF( jn == jppo4  )                 zrfact = po4r * 1.0e+6
          cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
-         CALL iom_put( cltra, trn(:,:,:,jn) * zrfact )
+         IF( lk_vvl ) THEN
+            CALL iom_put( cltra, trn(:,:,:,jn) * fse3t_n(:,:,:) * zrfact )
+         ELSE
+            CALL iom_put( cltra, trn(:,:,:,jn) * zrfact )
+         ENDIF
       END DO
 #endif
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90	(revision 4292)
@@ -70,11 +70,4 @@
    USE oce , ONLY :   sshb    =>    sshb    !: sea surface height at t-point [m]   
    USE oce , ONLY :   ssha    =>    ssha    !: sea surface height at t-point [m]   
-   USE oce , ONLY :   sshu_n  =>    sshu_n  !: sea surface height at u-point [m]   
-   USE oce , ONLY :   sshu_b  =>    sshu_b  !: sea surface height at u-point [m]   
-   USE oce , ONLY :   sshu_a  =>    sshu_a  !: sea surface height at u-point [m]   
-   USE oce , ONLY :   sshv_n  =>    sshv_n  !: sea surface height at v-point [m]   
-   USE oce , ONLY :   sshv_b  =>    sshv_b  !: sea surface height at v-point [m]   
-   USE oce , ONLY :   sshv_a  =>    sshv_a  !: sea surface height at v-point [m]   
-   USE oce , ONLY :   sshf_n  =>    sshf_n  !: sea surface height at v-point [m]   
    USE oce , ONLY :   l_traldf_rot => l_traldf_rot  !: rotated laplacian operator for lateral diffusion
 #if defined key_offline
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/trcdia.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/trcdia.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/trcdia.F90	(revision 4292)
@@ -187,5 +187,5 @@
 
          ! Vertical grid for tracer : gdept
-         CALL histvert( nit5, 'deptht', 'Vertical T levels', 'm', ipk, gdept_0, ndepit5)
+         CALL histvert( nit5, 'deptht', 'Vertical T levels', 'm', ipk, gdept_1d, ndepit5)
 
          ! Index of ocean points in 3D and 2D (surface)
@@ -308,5 +308,5 @@
          ! Vertical grid for 2d and 3d arrays
 
-         CALL histvert( nitd, 'deptht', 'Vertical T levels','m', ipk, gdept_0, ndepitd)
+         CALL histvert( nitd, 'deptht', 'Vertical T levels','m', ipk, gdept_1d, ndepitd)
 
          ! Declare all the output fields as NETCDF variables
@@ -439,5 +439,5 @@
             &    iiter, zjulian, zdt, nhoritb, nitb , domain_id=nidom, snc4chunks=snc4set )
          ! Vertical grid for biological trends
-         CALL histvert(nitb, 'deptht', 'Vertical T levels', 'm', ipk, gdept_0, ndepitb)
+         CALL histvert(nitb, 'deptht', 'Vertical T levels', 'm', ipk, gdept_1d, ndepitb)
 
          ! Declare all the output fields as NETCDF variables
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/trcdta.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/trcdta.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/trcdta.F90	(revision 4292)
@@ -188,13 +188,13 @@
                   DO ji = 1, jpi
                      DO jk = 1, jpk                        ! determines the intepolated T-S profiles at each (i,j) points
-                        zl = fsdept_0(ji,jj,jk)
-                        IF(     zl < gdept_0(1  ) ) THEN          ! above the first level of data
+                        zl = fsdept_n(ji,jj,jk)
+                        IF(     zl < gdept_1d(1  ) ) THEN         ! above the first level of data
                            ztp(jk) =  sf_dta(1)%fnow(ji,jj,1)
-                        ELSEIF( zl > gdept_0(jpk) ) THEN          ! below the last level of data
+                        ELSEIF( zl > gdept_1d(jpk) ) THEN         ! below the last level of data
                            ztp(jk) =  sf_dta(1)%fnow(ji,jj,jpkm1)
                         ELSE                                      ! inbetween : vertical interpolation between jkk & jkk+1
                            DO jkk = 1, jpkm1                                  ! when  gdept(jkk) < zl < gdept(jkk+1)
-                              IF( (zl-gdept_0(jkk)) * (zl-gdept_0(jkk+1)) <= 0._wp ) THEN
-                                 zi = ( zl - gdept_0(jkk) ) / (gdept_0(jkk+1)-gdept_0(jkk))
+                              IF( (zl-gdept_1d(jkk)) * (zl-gdept_1d(jkk+1)) <= 0._wp ) THEN
+                                 zi = ( zl - gdept_1d(jkk) ) / (gdept_1d(jkk+1)-gdept_1d(jkk))
                                  ztp(jk) = sf_dta(1)%fnow(ji,jj,jkk) + ( sf_dta(1)%fnow(ji,jj,jkk+1) - &
                                            sf_dta(1)%fnow(ji,jj,jkk) ) * zi 
@@ -219,5 +219,5 @@
                         ik = mbkt(ji,jj) 
                         IF( ik > 1 ) THEN
-                           zl = ( gdept_0(ik) - fsdept_0(ji,jj,ik) ) / ( gdept_0(ik) - gdept_0(ik-1) )
+                           zl = ( gdept_1d(ik) - fsdept_n(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
                            sf_dta(1)%fnow(ji,jj,ik) = (1.-zl) * sf_dta(1)%fnow(ji,jj,ik) + zl * sf_dta(1)%fnow(ji,jj,ik-1)
                         ENDIF
Index: /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/trcsub.F90
===================================================================
--- /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/trcsub.F90	(revision 4291)
+++ /branches/2013/dev_MERGE_2013/NEMOGCM/NEMO/TOP_SRC/trcsub.F90	(revision 4292)
@@ -79,6 +79,6 @@
            !
            sshb_hold  (:,:) = sshn  (:,:)
-           sshu_b_hold(:,:) = sshu_n(:,:)
-           sshv_b_hold(:,:) = sshv_n(:,:)
+!!Z~       sshu_b_hold(:,:) = sshu_n(:,:)
+!!Z~       sshv_b_hold(:,:) = sshv_n(:,:)
            emp_b_hold (:,:) = emp_b (:,:)
            !
@@ -117,6 +117,6 @@
           !
           sshn_tm  (:,:)         = sshn_tm  (:,:)         + sshn  (:,:) 
-          sshu_n_tm(:,:)         = sshu_n_tm(:,:)         + sshu_n(:,:) 
-          sshv_n_tm(:,:)         = sshv_n_tm(:,:)         + sshv_n(:,:) 
+!!Z~      sshu_n_tm(:,:)         = sshu_n_tm(:,:)         + sshu_n(:,:) 
+!!Z~      sshv_n_tm(:,:)         = sshv_n_tm(:,:)         + sshv_n(:,:) 
           rnf_tm   (:,:)         = rnf_tm   (:,:)         + rnf   (:,:) 
           h_rnf_tm (:,:)         = h_rnf_tm (:,:)         + h_rnf (:,:) 
@@ -197,13 +197,13 @@
 # endif
          sshn_temp  (:,:)        = sshn  (:,:)
-         sshu_n_temp(:,:)        = sshu_n(:,:)
-         sshv_n_temp(:,:)        = sshv_n(:,:)
-         sshf_n_temp(:,:)        = sshf_n(:,:)
+!!Z~     sshu_n_temp(:,:)        = sshu_n(:,:)
+!!Z~     sshv_n_temp(:,:)        = sshv_n(:,:)
+!!Z~     sshf_n_temp(:,:)        = sshf_n(:,:)
          sshb_temp  (:,:)        = sshb  (:,:)
-         sshu_b_temp(:,:)        = sshu_b(:,:)
-         sshv_b_temp(:,:)        = sshv_b(:,:)
+!!Z~     sshu_b_temp(:,:)        = sshu_b(:,:)
+!!Z~     sshv_b_temp(:,:)        = sshv_b(:,:)
          ssha_temp  (:,:)        = ssha  (:,:)
-         sshu_a_temp(:,:)        = sshu_a(:,:)
-         sshv_a_temp(:,:)        = sshv_a(:,:)
+!!Z~     sshu_a_temp(:,:)        = sshu_a(:,:)
+!!Z~     sshv_a_temp(:,:)        = sshv_a(:,:)
          rnf_temp   (:,:)        = rnf   (:,:)
          h_rnf_temp (:,:)        = h_rnf (:,:)
@@ -309,6 +309,6 @@
 # endif
          sshn_tm  (:,:)          = sshn_tm    (:,:)       + sshn  (:,:) 
-         sshu_n_tm(:,:)          = sshu_n_tm  (:,:)       + sshu_n(:,:) 
-         sshv_n_tm(:,:)          = sshv_n_tm  (:,:)       + sshv_n(:,:) 
+!!Z~     sshu_n_tm(:,:)          = sshu_n_tm  (:,:)       + sshu_n(:,:) 
+!!Z~     sshv_n_tm(:,:)          = sshv_n_tm  (:,:)       + sshv_n(:,:) 
          rnf_tm   (:,:)          = rnf_tm     (:,:)       + rnf   (:,:) 
          h_rnf_tm (:,:)          = h_rnf_tm   (:,:)       + h_rnf (:,:) 
@@ -321,9 +321,9 @@
          !
          sshn     (:,:)          = sshn_tm    (:,:) * r1_ndttrcp1 
-         sshu_n   (:,:)          = sshu_n_tm  (:,:) * r1_ndttrcp1  
-         sshv_n   (:,:)          = sshv_n_tm  (:,:) * r1_ndttrcp1  
+!!Z~     sshu_n   (:,:)          = sshu_n_tm  (:,:) * r1_ndttrcp1  
+!!Z~     sshv_n   (:,:)          = sshv_n_tm  (:,:) * r1_ndttrcp1  
          sshb     (:,:)          = sshb_hold  (:,:)
-         sshu_b   (:,:)          = sshu_b_hold(:,:)
-         sshv_b   (:,:)          = sshv_b_hold(:,:)
+!!Z~     sshu_b   (:,:)          = sshu_b_hold(:,:)
+!!Z~     sshv_b   (:,:)          = sshv_b_hold(:,:)
          rnf      (:,:)          = rnf_tm     (:,:) * r1_ndttrcp1 
          h_rnf    (:,:)          = h_rnf_tm   (:,:) * r1_ndttrcp1 
@@ -486,13 +486,13 @@
 #endif
          CALL lbc_lnk( sshn  (:,:)         , 'T', 1. ) 
-         CALL lbc_lnk( sshu_n(:,:)         , 'U', 1. ) 
-         CALL lbc_lnk( sshv_n(:,:)         , 'V', 1. ) 
-         CALL lbc_lnk( sshf_n(:,:)         , 'F', 1. ) 
+!!Z~     CALL lbc_lnk( sshu_n(:,:)         , 'U', 1. ) 
+!!Z~     CALL lbc_lnk( sshv_n(:,:)         , 'V', 1. ) 
+!!Z~     CALL lbc_lnk( sshf_n(:,:)         , 'F', 1. ) 
          CALL lbc_lnk( sshb  (:,:)         , 'T', 1. ) 
-         CALL lbc_lnk( sshu_b(:,:)         , 'U', 1. ) 
-         CALL lbc_lnk( sshv_b(:,:)         , 'V', 1. ) 
+!!Z~     CALL lbc_lnk( sshu_b(:,:)         , 'U', 1. ) 
+!!Z~     CALL lbc_lnk( sshv_b(:,:)         , 'V', 1. ) 
          CALL lbc_lnk( ssha  (:,:)         , 'T', 1. ) 
-         CALL lbc_lnk( sshu_a(:,:)         , 'U', 1. ) 
-         CALL lbc_lnk( sshv_a(:,:)         , 'V', 1. ) 
+!!Z~     CALL lbc_lnk( sshu_a(:,:)         , 'U', 1. ) 
+!!Z~     CALL lbc_lnk( sshv_a(:,:)         , 'V', 1. ) 
          CALL lbc_lnk( rnf   (:,:)         , 'T', 1. ) 
          CALL lbc_lnk( h_rnf (:,:)         , 'T', 1. ) 
@@ -592,6 +592,6 @@
 #endif
       sshn_tm  (:,:) = sshn  (:,:) 
-      sshu_n_tm(:,:) = sshu_n(:,:) 
-      sshv_n_tm(:,:) = sshv_n(:,:) 
+!!Z~  sshu_n_tm(:,:) = sshu_n(:,:) 
+!!Z~  sshv_n_tm(:,:) = sshv_n(:,:) 
       rnf_tm   (:,:) = rnf   (:,:) 
       h_rnf_tm (:,:) = h_rnf (:,:) 
@@ -695,11 +695,11 @@
       sshb  (:,:)     =  sshb_temp  (:,:)
       ssha  (:,:)     =  ssha_temp  (:,:)
-      sshu_n(:,:)     =  sshu_n_temp(:,:)
-      sshu_b(:,:)     =  sshu_b_temp(:,:)
-      sshu_a(:,:)     =  sshu_a_temp(:,:)
-      sshv_n(:,:)     =  sshv_n_temp(:,:)
-      sshv_b(:,:)     =  sshv_b_temp(:,:)
-      sshv_a(:,:)     =  sshv_a_temp(:,:)
-      sshf_n(:,:)     =  sshf_n_temp(:,:)
+!!Z~  sshu_n(:,:)     =  sshu_n_temp(:,:)
+!!Z~  sshu_b(:,:)     =  sshu_b_temp(:,:)
+!!Z~  sshu_a(:,:)     =  sshu_a_temp(:,:)
+!!Z~  sshv_n(:,:)     =  sshv_n_temp(:,:)
+!!Z~  sshv_b(:,:)     =  sshv_b_temp(:,:)
+!!Z~  sshv_a(:,:)     =  sshv_a_temp(:,:)
+!!Z~  sshf_n(:,:)     =  sshf_n_temp(:,:)
       rnf   (:,:)     =  rnf_temp   (:,:)
       h_rnf (:,:)     =  h_rnf_temp (:,:)
@@ -816,10 +816,10 @@
       !
       sshb_hold  (:,:) = sshn  (:,:)
-      sshu_b_hold(:,:) = sshu_n(:,:)
-      sshv_b_hold(:,:) = sshv_n(:,:)
+!!Z~  sshu_b_hold(:,:) = sshu_n(:,:)
+!!Z~  sshv_b_hold(:,:) = sshv_n(:,:)
       emp_b_hold (:,:) = emp   (:,:)
       sshn_tm    (:,:) = sshn  (:,:) 
-      sshu_n_tm  (:,:) = sshu_n(:,:) 
-      sshv_n_tm  (:,:) = sshv_n(:,:) 
+!!Z~  sshu_n_tm  (:,:) = sshu_n(:,:) 
+!!Z~  sshv_n_tm  (:,:) = sshv_n(:,:) 
       rnf_tm     (:,:) = rnf   (:,:) 
       h_rnf_tm   (:,:) = h_rnf (:,:) 
@@ -951,6 +951,6 @@
          END DO
          !
-         hu(:,:) = hu_0(:,:) + sshu_n(:,:)            ! now ocean depth (at u- and v-points)
-         hv(:,:) = hv_0(:,:) + sshv_n(:,:)
+!!Z~     hu(:,:) = hu_0(:,:) + sshu_n(:,:)            ! now ocean depth (at u- and v-points)
+!!Z~     hv(:,:) = hv_0(:,:) + sshv_n(:,:)
          !                                            ! now masked inverse of the ocean depth (at u- and v-points)
          hur(:,:) = umask(:,:,1) / ( hu(:,:) + 1._wp - umask(:,:,1) )
@@ -992,17 +992,17 @@
 
       !                                                ! Sea Surface Height at u-,v- and f-points (vvl case only)
-      IF( lk_vvl ) THEN                                ! (required only in key_vvl case)
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1      ! NO Vector Opt.
-               sshu_a(ji,jj) = 0.5  * umask(ji,jj,1) / ( e1u(ji  ,jj) * e2u(ji  ,jj) )                   &
-                  &                                  * ( e1t(ji  ,jj) * e2t(ji  ,jj) * ssha(ji  ,jj)     &
-                  &                                    + e1t(ji+1,jj) * e2t(ji+1,jj) * ssha(ji+1,jj) )
-               sshv_a(ji,jj) = 0.5  * vmask(ji,jj,1) / ( e1v(ji,jj  ) * e2v(ji,jj  ) )                   &
-                  &                                  * ( e1t(ji,jj  ) * e2t(ji,jj  ) * ssha(ji,jj  )     &
-                  &                                    + e1t(ji,jj+1) * e2t(ji,jj+1) * ssha(ji,jj+1) )
-            END DO
-         END DO
-         CALL lbc_lnk( sshu_a, 'U', 1. )   ;   CALL lbc_lnk( sshv_a, 'V', 1. )      ! Boundaries conditions
-      ENDIF
+!!Z~  IF( lk_vvl ) THEN                                ! (required only in key_vvl case)
+!!Z~     DO jj = 1, jpjm1
+!!Z~        DO ji = 1, jpim1      ! NO Vector Opt.
+!!Z~           sshu_a(ji,jj) = 0.5  * umask(ji,jj,1) / ( e1u(ji  ,jj) * e2u(ji  ,jj) )                   &
+!!Z~              &                                  * ( e1t(ji  ,jj) * e2t(ji  ,jj) * ssha(ji  ,jj)     &
+!!Z~              &                                    + e1t(ji+1,jj) * e2t(ji+1,jj) * ssha(ji+1,jj) )
+!!Z~           sshv_a(ji,jj) = 0.5  * vmask(ji,jj,1) / ( e1v(ji,jj  ) * e2v(ji,jj  ) )                   &
+!!Z~              &                                  * ( e1t(ji,jj  ) * e2t(ji,jj  ) * ssha(ji,jj  )     &
+!!Z~              &                                    + e1t(ji,jj+1) * e2t(ji,jj+1) * ssha(ji,jj+1) )
+!!Z~        END DO
+!!Z~     END DO
+!!Z~     CALL lbc_lnk( sshu_a, 'U', 1. )   ;   CALL lbc_lnk( sshv_a, 'V', 1. )      ! Boundaries conditions
+!!Z~  ENDIF
       
 
