Index: /NEMO/trunk/src/OCE/DIA/diacfl.F90
===================================================================
--- /NEMO/trunk/src/OCE/DIA/diacfl.F90	(revision 13457)
+++ /NEMO/trunk/src/OCE/DIA/diacfl.F90	(revision 13458)
@@ -56,46 +56,43 @@
       INTEGER , DIMENSION(3)           ::   iloc_u , iloc_v , iloc_w , iloc  ! workspace
       REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zCu_cfl, zCv_cfl, zCw_cfl        ! workspace
+      LOGICAL , DIMENSION(jpi,jpj,jpk) ::   llmsk
       !!----------------------------------------------------------------------
       !
       IF( ln_timing )   CALL timing_start('dia_cfl')
       !
-      DO_3D( 1, 1, 1, 1, 1, jpk )
+      llmsk(   1:Nis1,:,:) = .FALSE.                                              ! exclude halos from the checked region
+      llmsk(Nie1: jpi,:,:) = .FALSE.
+      llmsk(:,   1:Njs1,:) = .FALSE.
+      llmsk(:,Nje1: jpj,:) = .FALSE.
+      !
+      DO_3D( 0, 0, 0, 0, 1, jpk )
          zCu_cfl(ji,jj,jk) = ABS( uu(ji,jj,jk,Kmm) ) * rDt / e1u  (ji,jj)      ! for i-direction
          zCv_cfl(ji,jj,jk) = ABS( vv(ji,jj,jk,Kmm) ) * rDt / e2v  (ji,jj)      ! for j-direction
-         zCw_cfl(ji,jj,jk) = ABS( ww(ji,jj,jk) ) * rDt / e3w(ji,jj,jk,Kmm)   ! for k-direction
+         zCw_cfl(ji,jj,jk) = ABS( ww(ji,jj,jk) ) * rDt / e3w(ji,jj,jk,Kmm)     ! for k-direction
       END_3D
       !
       ! write outputs
-      IF( iom_use('cfl_cu') )   CALL iom_put( 'cfl_cu', MAXVAL( zCu_cfl, dim=3 ) )
-      IF( iom_use('cfl_cv') )   CALL iom_put( 'cfl_cv', MAXVAL( zCv_cfl, dim=3 ) )
-      IF( iom_use('cfl_cw') )   CALL iom_put( 'cfl_cw', MAXVAL( zCw_cfl, dim=3 ) )
+      IF( iom_use('cfl_cu') ) THEN
+         llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+         CALL iom_put( 'cfl_cu', MAXVAL( zCu_cfl, mask = llmsk, dim=3 ) )
+      ENDIF
+      IF( iom_use('cfl_cv') ) THEN
+         llmsk(Nis0:Nie0,Njs0:Nje0,:) = vmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+         CALL iom_put( 'cfl_cv', MAXVAL( zCv_cfl, mask = llmsk, dim=3 ) )
+      ENDIF
+      IF( iom_use('cfl_cw') ) THEN
+         llmsk(Nis0:Nie0,Njs0:Nje0,:) = wmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+         CALL iom_put( 'cfl_cw', MAXVAL( zCw_cfl, mask = llmsk, dim=3 ) )
+      ENDIF
 
       !                    ! calculate maximum values and locations
-      IF( lk_mpp ) THEN
-         CALL mpp_maxloc( 'diacfl', zCu_cfl, umask, zCu_max, iloc_u )
-         CALL mpp_maxloc( 'diacfl', zCv_cfl, vmask, zCv_max, iloc_v )
-         CALL mpp_maxloc( 'diacfl', zCw_cfl, wmask, zCw_max, iloc_w )
-      ELSE
-         iloc = MAXLOC( ABS( zcu_cfl(:,:,:) ) )
-         iloc_u(1) = iloc(1) + nimpp - 1
-         iloc_u(2) = iloc(2) + njmpp - 1
-         iloc_u(3) = iloc(3)
-         zCu_max = zCu_cfl(iloc(1),iloc(2),iloc(3))
-         !
-         iloc = MAXLOC( ABS( zcv_cfl(:,:,:) ) )
-         iloc_v(1) = iloc(1) + nimpp - 1
-         iloc_v(2) = iloc(2) + njmpp - 1
-         iloc_v(3) = iloc(3)
-         zCv_max = zCv_cfl(iloc(1),iloc(2),iloc(3))
-         !
-         iloc = MAXLOC( ABS( zcw_cfl(:,:,:) ) )
-         iloc_w(1) = iloc(1) + nimpp - 1
-         iloc_w(2) = iloc(2) + njmpp - 1
-         iloc_w(3) = iloc(3)
-         zCw_max = zCw_cfl(iloc(1),iloc(2),iloc(3))
-      ENDIF
+      llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+      CALL mpp_maxloc( 'diacfl', zCu_cfl, llmsk, zCu_max, iloc_u )
+      llmsk(Nis0:Nie0,Njs0:Nje0,:) = vmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+      CALL mpp_maxloc( 'diacfl', zCv_cfl, llmsk, zCv_max, iloc_v )
+      llmsk(Nis0:Nie0,Njs0:Nje0,:) = wmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+      CALL mpp_maxloc( 'diacfl', zCw_cfl, llmsk, zCw_max, iloc_w )
       !
-      !                    ! write out to file
-      IF( lwp ) THEN
+      IF( lwp ) THEN       ! write out to file
          WRITE(numcfl,FMT='(2x,i6,3x,a6,4x,f7.4,1x,i4,1x,i4,1x,i4)') kt, 'Max Cu', zCu_max, iloc_u(1), iloc_u(2), iloc_u(3)
          WRITE(numcfl,FMT='(11x,     a6,4x,f7.4,1x,i4,1x,i4,1x,i4)')     'Max Cv', zCv_max, iloc_v(1), iloc_v(2), iloc_v(3)
Index: /NEMO/trunk/src/OCE/DOM/domain.F90
===================================================================
--- /NEMO/trunk/src/OCE/DOM/domain.F90	(revision 13457)
+++ /NEMO/trunk/src/OCE/DOM/domain.F90	(revision 13458)
@@ -177,5 +177,5 @@
       !
       IF( ln_linssh ) THEN       != Fix in time : set to the reference one for all
-      !
+         !
          DO jt = 1, jpt                         ! depth of t- and w-grid-points
             gdept(:,:,:,jt) = gdept_0(:,:,:)
@@ -204,5 +204,5 @@
       ELSE                       != time varying : initialize before/now/after variables
          !
-         IF( .NOT.l_offline )  CALL dom_vvl_init( Kbb, Kmm, Kaa )
+         IF( .NOT.l_offline )   CALL dom_vvl_init( Kbb, Kmm, Kaa )
          !
       ENDIF
@@ -248,5 +248,5 @@
       !!----------------------------------------------------------------------
       !
-      DO ji = 1, jpi                 ! local domain indices ==> global domain, including halos, indices
+      DO ji = 1, jpi                 ! local domain indices ==> global domain indices, including halos
         mig(ji) = ji + nimpp - 1
       END DO
@@ -254,5 +254,5 @@
         mjg(jj) = jj + njmpp - 1
       END DO
-      !                              ! local domain indices ==> global domain, excluding halos, indices
+      !                              ! local domain indices ==> global domain indices, excluding halos
       !
       mig0(:) = mig(:) - nn_hls
@@ -493,33 +493,14 @@
       !!----------------------------------------------------------------------
       !
-      IF(lk_mpp) THEN
-         CALL mpp_minloc( 'domain', glamt(:,:), tmask_i(:,:), zglmin, imil )
-         CALL mpp_minloc( 'domain', gphit(:,:), tmask_i(:,:), zgpmin, imip )
-         CALL mpp_minloc( 'domain',   e1t(:,:), tmask_i(:,:), ze1min, imi1 )
-         CALL mpp_minloc( 'domain',   e2t(:,:), tmask_i(:,:), ze2min, imi2 )
-         CALL mpp_maxloc( 'domain', glamt(:,:), tmask_i(:,:), zglmax, imal )
-         CALL mpp_maxloc( 'domain', gphit(:,:), tmask_i(:,:), zgpmax, imap )
-         CALL mpp_maxloc( 'domain',   e1t(:,:), tmask_i(:,:), ze1max, ima1 )
-         CALL mpp_maxloc( 'domain',   e2t(:,:), tmask_i(:,:), ze2max, ima2 )
-      ELSE
-         llmsk = tmask_i(:,:) == 1._wp
-         zglmin = MINVAL( glamt(:,:), mask = llmsk )    
-         zgpmin = MINVAL( gphit(:,:), mask = llmsk )    
-         ze1min = MINVAL(   e1t(:,:), mask = llmsk )    
-         ze2min = MINVAL(   e2t(:,:), mask = llmsk )    
-         zglmin = MAXVAL( glamt(:,:), mask = llmsk )    
-         zgpmin = MAXVAL( gphit(:,:), mask = llmsk )    
-         ze1max = MAXVAL(   e1t(:,:), mask = llmsk )    
-         ze2max = MAXVAL(   e2t(:,:), mask = llmsk )    
-         !
-         imil   = MINLOC( glamt(:,:), mask = llmsk ) + (/ nimpp - 1, njmpp - 1 /)
-         imip   = MINLOC( gphit(:,:), mask = llmsk ) + (/ nimpp - 1, njmpp - 1 /)
-         imi1   = MINLOC(   e1t(:,:), mask = llmsk ) + (/ nimpp - 1, njmpp - 1 /)
-         imi2   = MINLOC(   e2t(:,:), mask = llmsk ) + (/ nimpp - 1, njmpp - 1 /)
-         imal   = MAXLOC( glamt(:,:), mask = llmsk ) + (/ nimpp - 1, njmpp - 1 /)
-         imap   = MAXLOC( gphit(:,:), mask = llmsk ) + (/ nimpp - 1, njmpp - 1 /)
-         ima1   = MAXLOC(   e1t(:,:), mask = llmsk ) + (/ nimpp - 1, njmpp - 1 /)
-         ima2   = MAXLOC(   e2t(:,:), mask = llmsk ) + (/ nimpp - 1, njmpp - 1 /)
-      ENDIF
+      llmsk = tmask_h(:,:) == 1._wp
+      !
+      CALL mpp_minloc( 'domain', glamt(:,:), llmsk, zglmin, imil )
+      CALL mpp_minloc( 'domain', gphit(:,:), llmsk, zgpmin, imip )
+      CALL mpp_minloc( 'domain',   e1t(:,:), llmsk, ze1min, imi1 )
+      CALL mpp_minloc( 'domain',   e2t(:,:), llmsk, ze2min, imi2 )
+      CALL mpp_maxloc( 'domain', glamt(:,:), llmsk, zglmax, imal )
+      CALL mpp_maxloc( 'domain', gphit(:,:), llmsk, zgpmax, imap )
+      CALL mpp_maxloc( 'domain',   e1t(:,:), llmsk, ze1max, ima1 )
+      CALL mpp_maxloc( 'domain',   e2t(:,:), llmsk, ze2max, ima2 )
       !
       IF(lwp) THEN
Index: /NEMO/trunk/src/OCE/DOM/domutl.F90
===================================================================
--- /NEMO/trunk/src/OCE/DOM/domutl.F90	(revision 13457)
+++ /NEMO/trunk/src/OCE/DOM/domutl.F90	(revision 13458)
@@ -48,5 +48,6 @@
       INTEGER , DIMENSION(2) ::   iloc
       REAL(wp)               ::   zlon, zmini
-      REAL(wp), DIMENSION(jpi,jpj) ::   zglam, zgphi, zmask, zdist
+      REAL(wp), DIMENSION(jpi,jpj) ::   zglam, zgphi, zdist
+      LOGICAL , DIMENSION(jpi,jpj) ::   llmsk
       !!--------------------------------------------------------------------
       !
@@ -54,11 +55,9 @@
       IF ( PRESENT(kkk) ) ik=kkk
       !
-      CALL dom_uniq(zmask,cdgrid)
-      !
       SELECT CASE( cdgrid )
-      CASE( 'U' )    ;   zglam(:,:) = glamu(:,:)   ;   zgphi(:,:) = gphiu(:,:)   ;   zmask(:,:) = zmask(:,:) * umask(:,:,ik)
-      CASE( 'V' )    ;   zglam(:,:) = glamv(:,:)   ;   zgphi(:,:) = gphiv(:,:)   ;   zmask(:,:) = zmask(:,:) * vmask(:,:,ik)
-      CASE( 'F' )    ;   zglam(:,:) = glamf(:,:)   ;   zgphi(:,:) = gphif(:,:)   ;   zmask(:,:) = zmask(:,:) * fmask(:,:,ik)
-      CASE DEFAULT   ;   zglam(:,:) = glamt(:,:)   ;   zgphi(:,:) = gphit(:,:)   ;   zmask(:,:) = zmask(:,:) * tmask(:,:,ik)
+      CASE( 'U' ) ;   zglam(:,:) = glamu(:,:)   ;   zgphi(:,:) = gphiu(:,:)   ;   llmsk(:,:) = tmask_h(:,:) * umask(:,:,ik) == 1._wp
+      CASE( 'V' ) ;   zglam(:,:) = glamv(:,:)   ;   zgphi(:,:) = gphiv(:,:)   ;   llmsk(:,:) = tmask_h(:,:) * vmask(:,:,ik) == 1._wp
+      CASE( 'F' ) ;   zglam(:,:) = glamf(:,:)   ;   zgphi(:,:) = gphif(:,:)   ;   llmsk(:,:) = tmask_h(:,:) * fmask(:,:,ik) == 1._wp
+      CASE DEFAULT;   zglam(:,:) = glamt(:,:)   ;   zgphi(:,:) = gphit(:,:)   ;   llmsk(:,:) = tmask_h(:,:) * tmask(:,:,ik) == 1._wp
       END SELECT
       !
@@ -68,16 +67,11 @@
       IF( zlon <  90. )   WHERE( zglam(:,:) > 180. ) zglam(:,:) = zglam(:,:) - 360.   ! glam between -180 and 180
       zglam(:,:) = zglam(:,:) - zlon
-
+      !
       zgphi(:,:) = zgphi(:,:) - plat
       zdist(:,:) = zglam(:,:) * zglam(:,:) + zgphi(:,:) * zgphi(:,:)
-      
-      IF( lk_mpp ) THEN  
-         CALL mpp_minloc( 'domngb', zdist(:,:), zmask, zmini, iloc)
-         kii = iloc(1) ; kjj = iloc(2)
-      ELSE
-         iloc(:) = MINLOC( zdist(:,:), mask = zmask(:,:) == 1.e0 )
-         kii = iloc(1) + nimpp - 1
-         kjj = iloc(2) + njmpp - 1
-      ENDIF
+      !
+      CALL mpp_minloc( 'domngb', zdist(:,:), llmsk, zmini, iloc, ldhalo = .TRUE. )
+      kii = iloc(1)
+      kjj = iloc(2)
       !
    END SUBROUTINE dom_ngb
Index: /NEMO/trunk/src/OCE/DOM/domvvl.F90
===================================================================
--- /NEMO/trunk/src/OCE/DOM/domvvl.F90	(revision 13457)
+++ /NEMO/trunk/src/OCE/DOM/domvvl.F90	(revision 13458)
@@ -334,5 +334,6 @@
       LOGICAL                ::   ll_do_bclinic         ! local logical
       REAL(wp), DIMENSION(jpi,jpj)     ::   zht, z_scale, zwu, zwv, zhdiv
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze3t
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ze3t
+      LOGICAL , DIMENSION(:,:,:), ALLOCATABLE ::   llmsk
       !!----------------------------------------------------------------------
       !
@@ -447,25 +448,21 @@
          ! Maximum deformation control
          ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-         ze3t(:,:,jpk) = 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(:,:,:) )
-         CALL mpp_max( 'domvvl', z_tmax )                 ! max over the global domain
-         z_tmin = MINVAL( ze3t(:,:,:) )
-         CALL mpp_min( 'domvvl', z_tmin )                 ! min over the global domain
+         ALLOCATE( ze3t(jpi,jpj,jpk), llmsk(jpi,jpj,jpk) )
+         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+            ze3t(ji,jj,jk) = tilde_e3t_a(ji,jj,jk) / e3t_0(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+         END_3D
+         !
+         llmsk(   1:Nis1,:,:) = .FALSE.   ! exclude halos from the checked region
+         llmsk(Nie1: jpi,:,:) = .FALSE.
+         llmsk(:,   1:Njs1,:) = .FALSE.
+         llmsk(:,Nje1: jpj,:) = .FALSE.
+         !
+         llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp                  ! define only the inner domain
+         z_tmax = MAXVAL( ze3t(:,:,:), mask = llmsk )   ;   CALL mpp_max( 'domvvl', z_tmax )   ! max over the global domain
+         z_tmin = MINVAL( ze3t(:,:,:), mask = llmsk )   ;   CALL mpp_min( 'domvvl', z_tmin )   ! min over the global domain
          ! - ML - test: for the moment, stop simulation for too large e3_t variations
          IF( ( z_tmax >  rn_zdef_max ) .OR. ( z_tmin < - rn_zdef_max ) ) THEN
-            IF( lk_mpp ) THEN
-               CALL mpp_maxloc( 'domvvl', ze3t, tmask, z_tmax, ijk_max )
-               CALL mpp_minloc( 'domvvl', ze3t, tmask, z_tmin, ijk_min )
-            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
+            CALL mpp_maxloc( 'domvvl', ze3t, llmsk, z_tmax, ijk_max )
+            CALL mpp_minloc( 'domvvl', ze3t, llmsk, z_tmin, ijk_min )
             IF (lwp) THEN
                WRITE(numout, *) 'MAX( tilde_e3t_a(:,:,:) / e3t_0(:,:,:) ) =', z_tmax
@@ -476,4 +473,5 @@
             ENDIF
          ENDIF
+         DEALLOCATE( ze3t, llmsk )
          ! - ML - end test
          ! - ML - Imposing these limits will cause a baroclinicity error which is corrected for below
Index: /NEMO/trunk/src/OCE/LBC/mpp_loc_generic.h90
===================================================================
--- /NEMO/trunk/src/OCE/LBC/mpp_loc_generic.h90	(revision 13457)
+++ /NEMO/trunk/src/OCE/LBC/mpp_loc_generic.h90	(revision 13458)
@@ -2,9 +2,13 @@
 #   if defined SINGLE_PRECISION
 #      define ARRAY_TYPE(i,j,k)    REAL(sp)        , INTENT(in   ) ::   ARRAY_IN(i,j,k)
-#      define MASK_TYPE(i,j,k)     REAL(sp)        , INTENT(in   ) ::   MASK_IN(i,j,k)
+#if defined key_mpp_mpi
+#      define MPI_TYPE MPI_2REAL
+#endif
 #      define PRECISION sp
 #   else
 #      define ARRAY_TYPE(i,j,k)    REAL(dp)        , INTENT(in   ) ::   ARRAY_IN(i,j,k)
-#      define MASK_TYPE(i,j,k)     REAL(dp)        , INTENT(in   ) ::   MASK_IN(i,j,k)
+#if defined key_mpp_mpi
+#      define MPI_TYPE MPI_2DOUBLE_PRECISION
+#endif
 #      define PRECISION dp
 #   endif
@@ -12,5 +16,5 @@
 #   if defined DIM_2d
 #      define ARRAY_IN(i,j,k)   ptab(i,j)
-#      define MASK_IN(i,j,k)    pmask(i,j)
+#      define MASK_IN(i,j,k)    ldmsk(i,j)
 #      define INDEX_TYPE(k)        INTEGER         , INTENT(  out) ::   kindex(2)
 #      define K_SIZE(ptab)      1
@@ -18,46 +22,49 @@
 #   if defined DIM_3d
 #      define ARRAY_IN(i,j,k)   ptab(i,j,k)
-#      define MASK_IN(i,j,k)    pmask(i,j,k)
+#      define MASK_IN(i,j,k)    ldmsk(i,j,k)
 #      define INDEX_TYPE(k)        INTEGER         , INTENT(  out) ::   kindex(3)
 #      define K_SIZE(ptab)      SIZE(ptab,3)
 #   endif
 #   if defined OPERATION_MAXLOC
-#      define MPI_OPERATION mpi_maxloc
+#      define MPI_OPERATION MPI_MAXLOC
 #      define LOC_OPERATION MAXLOC
 #      define ERRVAL -HUGE
 #   endif
 #   if defined OPERATION_MINLOC
-#      define MPI_OPERATION mpi_minloc
+#      define MPI_OPERATION MPI_MINLOC
 #      define LOC_OPERATION MINLOC
 #      define ERRVAL HUGE
 #   endif
 
-   SUBROUTINE ROUTINE_LOC( cdname, ptab, pmask, pmin, kindex )
+   SUBROUTINE ROUTINE_LOC( cdname, ptab, ldmsk, pmin, kindex, ldhalo )
       !!----------------------------------------------------------------------
-      CHARACTER(len=*), INTENT(in   ) ::   cdname  ! name of the calling subroutine
+      CHARACTER(len=*), INTENT(in    ) ::   cdname  ! name of the calling subroutine
       ARRAY_TYPE(:,:,:)                            ! array on which loctrans operation is applied
-      MASK_TYPE(:,:,:)                             ! local mask
-      REAL(PRECISION)        , INTENT(  out) ::   pmin    ! Global minimum of ptab
+      LOGICAL          , INTENT(in   ) ::   MASK_IN(:,:,:)                     ! local mask
+      REAL(PRECISION)  , INTENT(  out) ::   pmin    ! Global minimum of ptab
       INDEX_TYPE(:)                                ! index of minimum in global frame
+      LOGICAL, OPTIONAL, INTENT(in   ) ::   ldhalo  ! If .false. (default) excludes halos in kindex 
       !
       INTEGER  ::   ierror, ii, idim
       INTEGER  ::   index0
+      INTEGER , DIMENSION(:), ALLOCATABLE  ::   ilocs
       REAL(PRECISION) ::   zmin     ! local minimum
-      INTEGER , DIMENSION(:), ALLOCATABLE  ::   ilocs
-      REAL(dp), DIMENSION(2,1) ::   zain, zaout
+      REAL(PRECISION), DIMENSION(2,1) ::   zain, zaout
+      LOGICAL  ::   llhalo
       !!-----------------------------------------------------------------------
       !
       IF( narea == 1 .AND. numcom == -1 ) CALL mpp_report( cdname, ld_glb = .TRUE. )
       !
+      IF( PRESENT(ldhalo) ) THEN   ;   llhalo = ldhalo
+      ELSE                         ;   llhalo = .FALSE.
+      ENDIF
+      !
       idim = SIZE(kindex)
       !
-      IF ( ALL(MASK_IN(:,:,:) /= 1._wp) ) THEN
-         ! special case for land processors
-         zmin = ERRVAL(zmin)
-         index0 = 0
-      ELSE
+      IF ( ANY( MASK_IN(:,:,:) ) ) THEN   ! there is at least 1 valid point...
+         !
          ALLOCATE ( ilocs(idim) )
          !
-         ilocs = LOC_OPERATION( ARRAY_IN(:,:,:) , mask= MASK_IN(:,:,:) == 1._wp )
+         ilocs = LOC_OPERATION( ARRAY_IN(:,:,:) , mask= MASK_IN(:,:,:) )
          zmin  = ARRAY_IN(ilocs(1),ilocs(2),ilocs(3))
          !
@@ -79,15 +86,20 @@
          index0 = index0 + jpiglo * jpjglo * (kindex(3)-1)
 #endif
+      ELSE
+         ! special case for land processors
+         zmin = ERRVAL(zmin)
+         index0 = 0
       END IF
+      !
       zain(1,:) = zmin
-      zain(2,:) = REAL(index0, wp)
+      zain(2,:) = REAL(index0, PRECISION)
       !
+#if defined key_mpp_mpi
       IF( ln_timing ) CALL tic_tac(.TRUE., ld_global = .TRUE.)
-#if defined key_mpp_mpi
-      CALL MPI_ALLREDUCE( zain, zaout, 1, MPI_2DOUBLE_PRECISION, MPI_OPERATION ,MPI_COMM_OCE, ierror)
+      CALL MPI_ALLREDUCE( zain, zaout, 1, MPI_TYPE, MPI_OPERATION ,MPI_COMM_OCE, ierror)
+      IF( ln_timing ) CALL tic_tac(.FALSE., ld_global = .TRUE.)
 #else
       zaout(:,:) = zain(:,:)
 #endif
-      IF( ln_timing ) CALL tic_tac(.FALSE., ld_global = .TRUE.)
       !
       pmin      = zaout(1,1)
@@ -104,4 +116,11 @@
       kindex(:) = kindex(:) + 1   ! start indices at 1
 
+      IF( .NOT. llhalo ) THEN
+         kindex(1)  = kindex(1) - nn_hls
+#if defined DIM_2d || defined DIM_3d   /* avoid warning when kindex has 1 element */
+         kindex(2)  = kindex(2) - nn_hls
+#endif
+      ENDIF
+      
    END SUBROUTINE ROUTINE_LOC
 
@@ -109,8 +128,10 @@
 #undef PRECISION
 #undef ARRAY_TYPE
-#undef MASK_TYPE
 #undef ARRAY_IN
 #undef MASK_IN
 #undef K_SIZE
+#if defined key_mpp_mpi
+#   undef MPI_TYPE
+#endif
 #undef MPI_OPERATION
 #undef LOC_OPERATION
Index: /NEMO/trunk/src/OCE/stpctl.F90
===================================================================
--- /NEMO/trunk/src/OCE/stpctl.F90	(revision 13457)
+++ /NEMO/trunk/src/OCE/stpctl.F90	(revision 13458)
@@ -49,5 +49,4 @@
       !!
       !! ** Method  : - Save the time step in numstp
-      !!              - Print it each 50 time steps
       !!              - Stop the run IF problem encountered by setting nstop > 0
       !!                Problems checked: |ssh| maximum larger than 10 m
@@ -119,5 +118,11 @@
       !                                   !==            test of local extrema           ==!
       !                                   !==  done by all processes at every time step  ==!
-      llmsk(:,:,1) = ssmask(:,:) == 1._wp
+      !
+      llmsk(   1:Nis1,:,:) = .FALSE.                                              ! exclude halos from the checked region
+      llmsk(Nie1: jpi,:,:) = .FALSE.
+      llmsk(:,   1:Njs1,:) = .FALSE.
+      llmsk(:,Nje1: jpj,:) = .FALSE.
+      !
+      llmsk(Nis0:Nie0,Njs0:Nje0,1) = ssmask(Nis0:Nie0,Njs0:Nje0) == 1._wp         ! define only the inner domain
       IF( ll_wd ) THEN
          zmax(1) = MAXVAL( ABS( ssh(:,:,Kmm) + ssh_ref ), mask = llmsk(:,:,1) )   ! ssh max
@@ -125,7 +130,7 @@
          zmax(1) = MAXVAL( ABS( ssh(:,:,Kmm)           ), mask = llmsk(:,:,1) )   ! ssh max
       ENDIF
-      llmsk(:,:,:) = umask(:,:,:) == 1._wp
+      llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
       zmax(2) = MAXVAL(  ABS( uu(:,:,:,Kmm) ), mask = llmsk )                     ! velocity max (zonal only)
-      llmsk(:,:,:) = tmask(:,:,:) == 1._wp
+      llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
       zmax(3) = MAXVAL( -ts(:,:,:,jp_sal,Kmm), mask = llmsk )                     ! minus salinity max
       zmax(4) = MAXVAL(  ts(:,:,:,jp_sal,Kmm), mask = llmsk )                     !       salinity max
@@ -143,5 +148,5 @@
          zmax(5:8) = 0._wp
       ENDIF
-      zmax(9) = REAL( nstop, wp )                                              ! stop indicator
+      zmax(9) = REAL( nstop, wp )                                                 ! stop indicator
       !                                   !==               get global extrema             ==!
       !                                   !==  done by all processes if writting run.stat  ==!
@@ -183,8 +188,11 @@
             IF( lwm .AND. kt /= nitend )   istatus = NF90_CLOSE(nrunid)
             ! get global loc on the min/max
-            CALL mpp_maxloc( 'stpctl', ABS(ssh(:,:,         Kmm)), ssmask(:,:  ), zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
-            CALL mpp_maxloc( 'stpctl', ABS( uu(:,:,:,       Kmm)),  umask(:,:,:), zzz, iloc(1:3,2) )
-            CALL mpp_minloc( 'stpctl',      ts(:,:,:,jp_sal,Kmm) ,  tmask(:,:,:), zzz, iloc(1:3,3) )
-            CALL mpp_maxloc( 'stpctl',      ts(:,:,:,jp_sal,Kmm) ,  tmask(:,:,:), zzz, iloc(1:3,4) )
+            llmsk(Nis0:Nie0,Njs0:Nje0,1) = ssmask(Nis0:Nie0,Njs0:Nje0 ) == 1._wp         ! define only the inner domain
+            CALL mpp_maxloc( 'stpctl', ABS(ssh(:,:,         Kmm)), llmsk(:,:,1), zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
+            llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+            CALL mpp_maxloc( 'stpctl', ABS( uu(:,:,:,       Kmm)), llmsk(:,:,:), zzz, iloc(1:3,2) )
+            llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+            CALL mpp_minloc( 'stpctl',      ts(:,:,:,jp_sal,Kmm) , llmsk(:,:,:), zzz, iloc(1:3,3) )
+            CALL mpp_maxloc( 'stpctl',      ts(:,:,:,jp_sal,Kmm) , llmsk(:,:,:), zzz, iloc(1:3,4) )
             ! find which subdomain has the max.
             iareamin(:) = jpnij+1   ;   iareamax(:) = 0   ;   iareasum(:) = 0
@@ -199,8 +207,14 @@
          ELSE                    ! find local min and max locations:
             ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc
-            iloc(1:2,1) = MAXLOC( ABS( ssh(:,:,         Kmm)), mask = ssmask(:,:  ) == 1._wp ) + (/ nimpp - 1, njmpp - 1    /)
-            iloc(1:3,2) = MAXLOC( ABS(  uu(:,:,:,       Kmm)), mask =  umask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
-            iloc(1:3,3) = MINLOC(       ts(:,:,:,jp_sal,Kmm) , mask =  tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
-            iloc(1:3,4) = MAXLOC(       ts(:,:,:,jp_sal,Kmm) , mask =  tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
+            llmsk(Nis0:Nie0,Njs0:Nje0,1) = ssmask(Nis0:Nie0,Njs0:Nje0 ) == 1._wp        ! define only the inner domain
+            iloc(1:2,1) = MAXLOC( ABS( ssh(:,:,         Kmm)), mask = llmsk(:,:,1) )
+            llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+            iloc(1:3,2) = MAXLOC( ABS(  uu(:,:,:,       Kmm)), mask = llmsk(:,:,:) )
+            llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+            iloc(1:3,3) = MINLOC(       ts(:,:,:,jp_sal,Kmm) , mask = llmsk(:,:,:) )
+            iloc(1:3,4) = MAXLOC(       ts(:,:,:,jp_sal,Kmm) , mask = llmsk(:,:,:) )
+            DO ji = 1, 4   ! local domain indices ==> global domain indices, excluding halos
+               iloc(1:2,ji) = (/ mig0(iloc(1,ji)), mjg0(iloc(2,ji)) /)
+            END DO
             iareamin(:) = narea   ;   iareamax(:) = narea   ;   iareasum(:) = 1         ! this is local information
          ENDIF
Index: /NEMO/trunk/src/SAS/stpctl.F90
===================================================================
--- /NEMO/trunk/src/SAS/stpctl.F90	(revision 13457)
+++ /NEMO/trunk/src/SAS/stpctl.F90	(revision 13458)
@@ -20,4 +20,5 @@
    USE dom_oce         ! ocean space and time domain variables 
    USE ice      , ONLY : vt_i, u_ice, tm_i
+   USE phycst   , ONLY : rt0
    !
    USE diawri          ! Standard run outputs       (dia_wri_state routine)
@@ -48,5 +49,4 @@
       !!
       !! ** Method  : - Save the time step in numstp
-      !!              - Print it each 50 time steps
       !!              - Stop the run IF problem encountered by setting nstop > 0
       !!                Problems checked: ice thickness maximum > 100 m
@@ -111,9 +111,15 @@
       !                                   !==            test of local extrema           ==!
       !                                   !==  done by all processes at every time step  ==!
-      llmsk(:,:) = tmask(:,:,1) == 1._wp
+      !
+      llmsk(   1:Nis1,:) = .FALSE.                                              ! exclude halos from the checked region
+      llmsk(Nie1: jpi,:) = .FALSE.
+      llmsk(:,   1:Njs1) = .FALSE.
+      llmsk(:,Nje1: jpj) = .FALSE.
+      !
+      llmsk(Nis0:Nie0,Njs0:Nje0) = tmask(Nis0:Nie0,Njs0:Nje0,1) == 1._wp   ! test only the inner domain
       IF( COUNT( llmsk(:,:) ) > 0 ) THEN   ! avoid huge values sent back for land processors...
-         zmax(1) = MAXVAL(      vt_i (:,:)            , mask = llmsk )   ! max ice thickness
-         zmax(2) = MAXVAL( ABS( u_ice(:,:) )          , mask = llmsk )   ! max ice velocity (zonal only)
-         zmax(3) = MAXVAL(     -tm_i (:,:) + 273.15_wp, mask = llmsk )   ! min ice temperature
+         zmax(1) = MAXVAL(      vt_i (:,:)      , mask = llmsk )   ! max ice thickness
+         zmax(2) = MAXVAL( ABS( u_ice(:,:) )    , mask = llmsk )   ! max ice velocity (zonal only)
+         zmax(3) = MAXVAL(     -tm_i (:,:) + rt0, mask = llmsk )   ! min ice temperature (in degC)
       ELSE
          IF( ll_colruns ) THEN    ! default value: must not be kept when calling mpp_max -> must be as small as possible
@@ -154,7 +160,7 @@
             IF( lwm .AND. kt /= nitend )   istatus = NF90_CLOSE(nrunid)
             ! get global loc on the min/max
-            CALL mpp_maxloc( 'stpctl',      vt_i(:,:)            , tmask(:,:,1), zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
-            CALL mpp_maxloc( 'stpctl',ABS( u_ice(:,:) )          , tmask(:,:,1), zzz, iloc(1:2,2) )
-            CALL mpp_minloc( 'stpctl',      tm_i(:,:) - 273.15_wp, tmask(:,:,1), zzz, iloc(1:2,3) )
+            CALL mpp_maxloc( 'stpctl',      vt_i(:,:)      , llmsk, zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
+            CALL mpp_maxloc( 'stpctl',ABS( u_ice(:,:) )    , llmsk, zzz, iloc(1:2,2) )
+            CALL mpp_minloc( 'stpctl',      tm_i(:,:) - rt0, llmsk, zzz, iloc(1:2,3) )
             ! find which subdomain has the max.
             iareamin(:) = jpnij+1   ;   iareamax(:) = 0   ;   iareasum(:) = 0
@@ -169,7 +175,10 @@
          ELSE                    ! find local min and max locations:
             ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc
-            iloc(1:2,1) = MAXLOC(       vt_i(:,:)            , mask = llmsk ) + (/ nimpp - 1, njmpp - 1/)
-            iloc(1:2,2) = MAXLOC( ABS( u_ice(:,:) )          , mask = llmsk ) + (/ nimpp - 1, njmpp - 1/)
-            iloc(1:2,3) = MINLOC(       tm_i(:,:) - 273.15_wp, mask = llmsk ) + (/ nimpp - 1, njmpp - 1/)
+            iloc(1:2,1) = MAXLOC(       vt_i(:,:)      , mask = llmsk )
+            iloc(1:2,2) = MAXLOC( ABS( u_ice(:,:) )    , mask = llmsk )
+            iloc(1:2,3) = MINLOC(       tm_i(:,:) - rt0, mask = llmsk )
+            DO ji = 1, 3   ! local domain indices ==> global domain indices, excluding halos
+               iloc(1:2,ji) = (/ mig0(iloc(1,ji)), mjg0(iloc(2,ji)) /)
+            END DO
             iareamin(:) = narea   ;   iareamax(:) = narea   ;   iareasum(:) = 1         ! this is local information
          ENDIF
Index: /NEMO/trunk/src/SWE/domain.F90
===================================================================
--- /NEMO/trunk/src/SWE/domain.F90	(revision 13457)
+++ /NEMO/trunk/src/SWE/domain.F90	(revision 13458)
@@ -245,6 +245,9 @@
       IF( lk_c1d         )   CALL cor_c1d       ! 1D configuration: Coriolis set at T-point
       !
+
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) CALL Agrif_Init_Domain( Kbb, Kmm, Kaa )
+#endif
       IF( ln_meshmask    )   CALL dom_wri       ! Create a domain file
-
       IF( .NOT.ln_rstart )   CALL dom_ctl       ! Domain control
       !
@@ -269,12 +272,13 @@
       !! ** Method  :   
       !!
-      !! ** Action  : - mig , mjg : local  domain indices ==> global domain indices
+      !! ** Action  : - mig , mjg : local  domain indices ==> global domain, including halos, indices
+      !!              - mig0, mjg0: local  domain indices ==> global domain, excluding halos, indices
       !!              - mi0 , mi1 : global domain indices ==> local  domain indices
-      !!              - mj0,, mj1   (global point not in the local domain ==> mi0>mi1 and/or mj0>mj1)
+      !!              - mj0 , mj1   (if global point not in the local domain ==> mi0>mi1 and/or mj0>mj1)
       !!----------------------------------------------------------------------
       INTEGER ::   ji, jj   ! dummy loop argument
       !!----------------------------------------------------------------------
       !
-      DO ji = 1, jpi                 ! local domain indices ==> global domain indices
+      DO ji = 1, jpi                 ! local domain indices ==> global domain indices, including halos
         mig(ji) = ji + nimpp - 1
       END DO
@@ -282,5 +286,15 @@
         mjg(jj) = jj + njmpp - 1
       END DO
-      !                              ! global domain indices ==> local domain indices
+      !                              ! local domain indices ==> global domain indices, excluding halos
+      !
+      mig0(:) = mig(:) - nn_hls
+      mjg0(:) = mjg(:) - nn_hls  
+      ! WARNING: to keep compatibility with the trunk that was including periodocity into the input data, 
+      ! we must define mig0 and mjg0 as bellow.
+      ! Once we decide to forget trunk compatibility, we must simply define mig0 and mjg0 as:
+      mig0_oldcmp(:) = mig0(:) + COUNT( (/ jperio == 1 .OR. jperio == 4 .OR. jperio == 6 .OR. jperio == 7 /) )
+      mjg0_oldcmp(:) = mjg0(:) + COUNT( (/ jperio == 2 .OR. jperio == 7 /) )
+      !
+      !                              ! global domain, including halos, indices ==> local domain indices
       !                                   ! (return (m.0,m.1)=(1,0) if data domain gridpoint is to the west/south of the 
       !                                   ! local domain, or (m.0,m.1)=(jp.+1,jp.) to the east/north of local domain. 
@@ -300,27 +314,5 @@
          WRITE(numout,*) '   local  domain:   jpi    = ', jpi   , ' jpj    = ', jpj   , ' jpk    = ', jpk
          WRITE(numout,*)
-         WRITE(numout,*) '   conversion from local to global domain indices (and vise versa) done'
-         IF( nn_print >= 1 ) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) '          conversion local  ==> global i-index domain (mig)'
-            WRITE(numout,25)              (mig(ji),ji = 1,jpi)
-            WRITE(numout,*)
-            WRITE(numout,*) '          conversion global ==> local  i-index domain'
-            WRITE(numout,*) '             starting index (mi0)'
-            WRITE(numout,25)              (mi0(ji),ji = 1,jpiglo)
-            WRITE(numout,*) '             ending index (mi1)'
-            WRITE(numout,25)              (mi1(ji),ji = 1,jpiglo)
-            WRITE(numout,*)
-            WRITE(numout,*) '          conversion local  ==> global j-index domain (mjg)'
-            WRITE(numout,25)              (mjg(jj),jj = 1,jpj)
-            WRITE(numout,*)
-            WRITE(numout,*) '          conversion global ==> local  j-index domain'
-            WRITE(numout,*) '             starting index (mj0)'
-            WRITE(numout,25)              (mj0(jj),jj = 1,jpjglo)
-            WRITE(numout,*) '             ending index (mj1)'
-            WRITE(numout,25)              (mj1(jj),jj = 1,jpjglo)
-         ENDIF
-      ENDIF
- 25   FORMAT( 100(10x,19i4,/) )
+      ENDIF
       !
    END SUBROUTINE dom_glo
@@ -364,4 +356,11 @@
 902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namrun in configuration namelist' )
       IF(lwm) WRITE ( numond, namrun )
+
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) THEN
+            nn_it000 = (Agrif_Parent(nn_it000)-1)*Agrif_IRhot() + 1
+            nn_itend =  Agrif_Parent(nn_itend)   *Agrif_IRhot()
+      ENDIF
+#endif
       !
       IF(lwp) THEN                  ! control print
@@ -435,22 +434,18 @@
 #endif
 
-#if defined key_agrif
       IF( Agrif_Root() ) THEN
-#endif
-      IF(lwp) WRITE(numout,*)
-      SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
-      CASE (  1 ) 
-         CALL ioconf_calendar('gregorian')
-         IF(lwp) WRITE(numout,*) '   ==>>>   The IOIPSL calendar is "gregorian", i.e. leap year'
-      CASE (  0 )
-         CALL ioconf_calendar('noleap')
-         IF(lwp) WRITE(numout,*) '   ==>>>   The IOIPSL calendar is "noleap", i.e. no leap year'
-      CASE ( 30 )
-         CALL ioconf_calendar('360d')
-         IF(lwp) WRITE(numout,*) '   ==>>>   The IOIPSL calendar is "360d", i.e. 360 days in a year'
-      END SELECT
-#if defined key_agrif
-      ENDIF
-#endif
+         IF(lwp) WRITE(numout,*)
+         SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
+         CASE (  1 ) 
+            CALL ioconf_calendar('gregorian')
+            IF(lwp) WRITE(numout,*) '   ==>>>   The IOIPSL calendar is "gregorian", i.e. leap year'
+         CASE (  0 )
+            CALL ioconf_calendar('noleap')
+            IF(lwp) WRITE(numout,*) '   ==>>>   The IOIPSL calendar is "noleap", i.e. no leap year'
+         CASE ( 30 )
+            CALL ioconf_calendar('360d')
+            IF(lwp) WRITE(numout,*) '   ==>>>   The IOIPSL calendar is "360d", i.e. 360 days in a year'
+         END SELECT
+      ENDIF
 
       READ  ( numnam_ref, namdom, IOSTAT = ios, ERR = 903)
@@ -459,4 +454,10 @@
 904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdom in configuration namelist' )
       IF(lwm) WRITE( numond, namdom )
+      !
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) THEN
+            rn_Dt = Agrif_Parent(rn_Dt) / Agrif_Rhot()
+      ENDIF
+#endif
       !
       IF(lwp) THEN
@@ -519,41 +520,32 @@
       !! ** Method  :   compute and print extrema of masked scale factors
       !!----------------------------------------------------------------------
-      INTEGER, DIMENSION(2) ::   imi1, imi2, ima1, ima2
-      INTEGER, DIMENSION(2) ::   iloc   ! 
-      REAL(wp) ::   ze1min, ze1max, ze2min, ze2max
-      !!----------------------------------------------------------------------
-      !
-      IF(lk_mpp) THEN
-         CALL mpp_minloc( 'domain', e1t(:,:), tmask_i(:,:), ze1min, imi1 )
-         CALL mpp_minloc( 'domain', e2t(:,:), tmask_i(:,:), ze2min, imi2 )
-         CALL mpp_maxloc( 'domain', e1t(:,:), tmask_i(:,:), ze1max, ima1 )
-         CALL mpp_maxloc( 'domain', e2t(:,:), tmask_i(:,:), ze2max, ima2 )
-      ELSE
-         ze1min = MINVAL( e1t(:,:), mask = tmask_i(:,:) == 1._wp )    
-         ze2min = MINVAL( e2t(:,:), mask = tmask_i(:,:) == 1._wp )    
-         ze1max = MAXVAL( e1t(:,:), mask = tmask_i(:,:) == 1._wp )    
-         ze2max = MAXVAL( e2t(:,:), mask = tmask_i(:,:) == 1._wp )    
-         !
-         iloc  = MINLOC( e1t(:,:), mask = tmask_i(:,:) == 1._wp )
-         imi1(1) = iloc(1) + nimpp - 1
-         imi1(2) = iloc(2) + njmpp - 1
-         iloc  = MINLOC( e2t(:,:), mask = tmask_i(:,:) == 1._wp )
-         imi2(1) = iloc(1) + nimpp - 1
-         imi2(2) = iloc(2) + njmpp - 1
-         iloc  = MAXLOC( e1t(:,:), mask = tmask_i(:,:) == 1._wp )
-         ima1(1) = iloc(1) + nimpp - 1
-         ima1(2) = iloc(2) + njmpp - 1
-         iloc  = MAXLOC( e2t(:,:), mask = tmask_i(:,:) == 1._wp )
-         ima2(1) = iloc(1) + nimpp - 1
-         ima2(2) = iloc(2) + njmpp - 1
-      ENDIF
+      LOGICAL, DIMENSION(jpi,jpj) ::   llmsk
+      INTEGER, DIMENSION(2)       ::   imil, imip, imi1, imi2, imal, imap, ima1, ima2
+      REAL(wp)                    ::   zglmin, zglmax, zgpmin, zgpmax, ze1min, ze1max, ze2min, ze2max
+      !!----------------------------------------------------------------------
+      !
+      llmsk = tmask_h(:,:) == 1._wp
+      !
+      CALL mpp_minloc( 'domain', glamt(:,:), llmsk, zglmin, imil )
+      CALL mpp_minloc( 'domain', gphit(:,:), llmsk, zgpmin, imip )
+      CALL mpp_minloc( 'domain',   e1t(:,:), llmsk, ze1min, imi1 )
+      CALL mpp_minloc( 'domain',   e2t(:,:), llmsk, ze2min, imi2 )
+      CALL mpp_maxloc( 'domain', glamt(:,:), llmsk, zglmax, imal )
+      CALL mpp_maxloc( 'domain', gphit(:,:), llmsk, zgpmax, imap )
+      CALL mpp_maxloc( 'domain',   e1t(:,:), llmsk, ze1max, ima1 )
+      CALL mpp_maxloc( 'domain',   e2t(:,:), llmsk, ze2max, ima2 )
+      !
       IF(lwp) THEN
          WRITE(numout,*)
          WRITE(numout,*) 'dom_ctl : extrema of the masked scale factors'
          WRITE(numout,*) '~~~~~~~'
-         WRITE(numout,"(14x,'e1t maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") ze1max, ima1(1), ima1(2)
-         WRITE(numout,"(14x,'e1t mini: ',1f10.2,' at i = ',i5,' j= ',i5)") ze1min, imi1(1), imi1(2)
-         WRITE(numout,"(14x,'e2t maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") ze2max, ima2(1), ima2(2)
-         WRITE(numout,"(14x,'e2t mini: ',1f10.2,' at i = ',i5,' j= ',i5)") ze2min, imi2(1), imi2(2)
+         WRITE(numout,"(14x,'glamt mini: ',1f10.2,' at i = ',i5,' j= ',i5)") zglmin, imil(1), imil(2)
+         WRITE(numout,"(14x,'glamt maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") zglmax, imal(1), imal(2)
+         WRITE(numout,"(14x,'gphit mini: ',1f10.2,' at i = ',i5,' j= ',i5)") zgpmin, imip(1), imip(2)
+         WRITE(numout,"(14x,'gphit maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") zgpmax, imap(1), imap(2)
+         WRITE(numout,"(14x,'  e1t mini: ',1f10.2,' at i = ',i5,' j= ',i5)") ze1min, imi1(1), imi1(2)
+         WRITE(numout,"(14x,'  e1t maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") ze1max, ima1(1), ima1(2)
+         WRITE(numout,"(14x,'  e2t mini: ',1f10.2,' at i = ',i5,' j= ',i5)") ze2min, imi2(1), imi2(2)
+         WRITE(numout,"(14x,'  e2t maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") ze2max, ima2(1), ima2(2)
       ENDIF
       !
@@ -622,6 +614,6 @@
       IF(lwp) THEN
          WRITE(numout,*) '      cn_cfg = ', TRIM(cd_cfg), '   nn_cfg = ', kk_cfg
-         WRITE(numout,*) '      jpiglo = ', kpi
-         WRITE(numout,*) '      jpjglo = ', kpj
+         WRITE(numout,*) '      Ni0glo = ', kpi
+         WRITE(numout,*) '      Nj0glo = ', kpj
          WRITE(numout,*) '      jpkglo = ', kpk
          WRITE(numout,*) '      type of global domain lateral boundary   jperio = ', kperio
@@ -662,6 +654,5 @@
       !         
       clnam = cn_domcfg_out  ! filename (configuration information)
-      CALL iom_open( TRIM(clnam), inum, ldwrt = .TRUE. )
-      
+      CALL iom_open( TRIM(clnam), inum, ldwrt = .TRUE. )     
       !
       !                             !==  ORCA family specificities  ==!
@@ -671,10 +662,4 @@
       ENDIF
       !
-      !                             !==  global domain size  ==!
-      !
-      CALL iom_rstput( 0, 0, inum, 'jpiglo', REAL( jpiglo, wp), ktype = jp_i4 )
-      CALL iom_rstput( 0, 0, inum, 'jpjglo', REAL( jpjglo, wp), ktype = jp_i4 )
-      CALL iom_rstput( 0, 0, inum, 'jpkglo', REAL( jpk   , wp), ktype = jp_i4 )
-      !
       !                             !==  domain characteristics  ==!
       !
@@ -683,14 +668,10 @@
       !
       !                                   ! type of vertical coordinate
-      IF( ln_zco    ) THEN   ;   izco = 1   ;   ELSE   ;   izco = 0   ;   ENDIF
-      IF( ln_zps    ) THEN   ;   izps = 1   ;   ELSE   ;   izps = 0   ;   ENDIF
-      IF( ln_sco    ) THEN   ;   isco = 1   ;   ELSE   ;   isco = 0   ;   ENDIF
-      CALL iom_rstput( 0, 0, inum, 'ln_zco'   , REAL( izco, wp), ktype = jp_i4 )
-      CALL iom_rstput( 0, 0, inum, 'ln_zps'   , REAL( izps, wp), ktype = jp_i4 )
-      CALL iom_rstput( 0, 0, inum, 'ln_sco'   , REAL( isco, wp), ktype = jp_i4 )
+      CALL iom_rstput( 0, 0, inum, 'ln_zco', REAL(COUNT((/ln_zco/)), wp), ktype = jp_i4 )
+      CALL iom_rstput( 0, 0, inum, 'ln_zps', REAL(COUNT((/ln_zps/)), wp), ktype = jp_i4 )
+      CALL iom_rstput( 0, 0, inum, 'ln_sco', REAL(COUNT((/ln_sco/)), wp), ktype = jp_i4 )
       !
       !                                   ! ocean cavities under iceshelves
-      IF( ln_isfcav ) THEN   ;   icav = 1   ;   ELSE   ;   icav = 0   ;   ENDIF
-      CALL iom_rstput( 0, 0, inum, 'ln_isfcav', REAL( icav, wp), ktype = jp_i4 )
+      CALL iom_rstput( 0, 0, inum, 'ln_isfcav', REAL(COUNT((/ln_isfcav/)), wp), ktype = jp_i4 )
       !
       !                             !==  horizontal mesh  !
Index: /NEMO/trunk/src/SWE/domvvl.F90
===================================================================
--- /NEMO/trunk/src/SWE/domvvl.F90	(revision 13457)
+++ /NEMO/trunk/src/SWE/domvvl.F90	(revision 13458)
@@ -276,6 +276,6 @@
             IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA" ) THEN
                IF( nn_cfg == 3 ) THEN   ! ORCA2: Suppress ztilde in the Foxe Basin for ORCA2
-                  ii0 = 103   ;   ii1 = 111       
-                  ij0 = 128   ;   ij1 = 135   ;   
+                  ii0 = 103 + nn_hls - 1   ;   ii1 = 111 + nn_hls - 1      
+                  ij0 = 128 + nn_hls       ;   ij1 = 135 + nn_hls
                   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 / rn_Dt
@@ -415,5 +415,6 @@
       LOGICAL                ::   ll_do_bclinic         ! local logical
       REAL(wp), DIMENSION(jpi,jpj)     ::   zht, z_scale, zwu, zwv, zhdiv
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze3t
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ze3t
+      LOGICAL , DIMENSION(:,:,:), ALLOCATABLE ::   llmsk
       !!----------------------------------------------------------------------
       !
@@ -528,25 +529,22 @@
          ! Maximum deformation control
          ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+         ALLOCATE( ze3t(jpi,jpj,jpk), llmsk(jpi,jpj,jpk) )
          ze3t(:,:,jpk) = 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(:,:,:) )
-         CALL mpp_max( 'domvvl', z_tmax )                 ! max over the global domain
-         z_tmin = MINVAL( ze3t(:,:,:) )
-         CALL mpp_min( 'domvvl', z_tmin )                 ! min over the global domain
+         !
+         llmsk(   1:Nis1,:,:) = .FALSE.   ! exclude halos from the checked region
+         llmsk(Nie1: jpi,:,:) = .FALSE.
+         llmsk(:,   1:Njs1,:) = .FALSE.
+         llmsk(:,Nje1: jpj,:) = .FALSE.
+         !
+         llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp                  ! define only the inner domain
+         z_tmax = MAXVAL( ze3t(:,:,:), mask = llmsk )   ;   CALL mpp_max( 'domvvl', z_tmax )   ! max over the global domain
+         z_tmin = MINVAL( ze3t(:,:,:), mask = llmsk )   ;   CALL mpp_min( 'domvvl', z_tmin )   ! min over the global domain
          ! - ML - test: for the moment, stop simulation for too large e3_t variations
          IF( ( z_tmax >  rn_zdef_max ) .OR. ( z_tmin < - rn_zdef_max ) ) THEN
-            IF( lk_mpp ) THEN
-               CALL mpp_maxloc( 'domvvl', ze3t, tmask, z_tmax, ijk_max )
-               CALL mpp_minloc( 'domvvl', ze3t, tmask, z_tmin, ijk_min )
-            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
+            CALL mpp_maxloc( 'domvvl', ze3t, llmsk, z_tmax, ijk_max )
+            CALL mpp_minloc( 'domvvl', ze3t, llmsk, z_tmin, ijk_min )
             IF (lwp) THEN
                WRITE(numout, *) 'MAX( tilde_e3t_a(:,:,:) / e3t_0(:,:,:) ) =', z_tmax
@@ -557,4 +555,5 @@
             ENDIF
          ENDIF
+         DEALLOCATE( ze3t, llmsk )
          ! - ML - end test
          ! - ML - Imposing these limits will cause a baroclinicity error which is corrected for below
@@ -697,5 +696,4 @@
       LOGICAL                ::   ll_do_bclinic         ! local logical
       REAL(wp), DIMENSION(jpi,jpj)     ::   zht, z_scale, zwu, zwv, zhdiv
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze3t
       !!----------------------------------------------------------------------
       !
Index: /NEMO/trunk/src/SWE/step.F90
===================================================================
--- /NEMO/trunk/src/SWE/step.F90	(revision 13457)
+++ /NEMO/trunk/src/SWE/step.F90	(revision 13458)
@@ -291,5 +291,5 @@
       ! Control
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL stp_ctl      ( kstp, Nbb, Nnn, indic )
+                         CALL stp_ctl      ( kstp, Nnn )
                
                          
Index: /NEMO/trunk/src/SWE/stpctl.F90
===================================================================
--- /NEMO/trunk/src/SWE/stpctl.F90	(revision 13457)
+++ /NEMO/trunk/src/SWE/stpctl.F90	(revision 13458)
@@ -19,12 +19,12 @@
    USE dom_oce         ! ocean space and time domain variables 
    USE c1d             ! 1D vertical configuration
+   USE zdf_oce ,  ONLY : ln_zad_Aimp       ! ocean vertical physics variables
+   USE wet_dry,   ONLY : ll_wd, ssh_ref    ! reference depth for negative bathy
+   !  
    USE diawri          ! Standard run outputs       (dia_wri_state routine)
-   !
    USE in_out_manager  ! I/O manager
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp         ! distributed memory computing
-   USE zdf_oce ,  ONLY : ln_zad_Aimp       ! ocean vertical physics variables
-   USE wet_dry,   ONLY : ll_wd, ssh_ref    ! reference depth for negative bathy
-
+   !
    USE netcdf          ! NetCDF library
    IMPLICIT NONE
@@ -33,16 +33,14 @@
    PUBLIC stp_ctl           ! routine called by step.F90
 
-   INTEGER  ::   idrun, idtime, idssh, idu, ids1, ids2, idt1, idt2, idc1, idw1, istatus
-   LOGICAL  ::   lsomeoce
-!!stoops
-#  include "domzgr_substitute.h90"
+   INTEGER                ::   nrunid   ! netcdf file id
+   INTEGER, DIMENSION(2)  ::   nvarid   ! netcdf variable id
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: stpctl.F90 12614 2020-03-26 14:59:52Z gm $
+   !! $Id: stpctl.F90 13216 2020-07-02 09:25:49Z rblod $
    !! Software governed by the CeCILL license (see ./LICENSE)
    !!----------------------------------------------------------------------
 CONTAINS
 
-   SUBROUTINE stp_ctl( kt, Kbb, Kmm, kindic )
+   SUBROUTINE stp_ctl( kt, Kmm )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE stp_ctl  ***
@@ -51,115 +49,215 @@
       !!
       !! ** Method  : - Save the time step in numstp
-      !!              - Print it each 50 time steps
-      !!              - Stop the run IF problem encountered by setting indic=-3
-      !!                Problems checked: |ssh| maximum larger than 10 m
+      !!              - Stop the run IF problem encountered by setting nstop > 0
+      !!                Problems checked: negative sea surface height 
       !!                                  |U|   maximum larger than 10 m/s 
-      !!                                  negative sea surface salinity
       !!
       !! ** Actions :   "time.step" file = last ocean time-step
       !!                "run.stat"  file = run statistics
-      !!                nstop indicator sheared among all local domain (lk_mpp=T)
+      !!                 nstop indicator sheared among all local domain
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
-      INTEGER, INTENT(in   ) ::   Kbb, Kmm      ! ocean time level index
-      INTEGER, INTENT(inout) ::   kindic   ! error indicator
-      !!
-      INTEGER                ::   ji, jj, jk          ! dummy loop indices
-      INTEGER, DIMENSION(2)  ::   ih                  ! min/max loc indices
-      INTEGER, DIMENSION(3)  ::   iu, is1, is2        ! min/max loc indices
-      REAL(wp)               ::   zzz                 ! local real 
-      REAL(wp), DIMENSION(3) ::   zmax
-      LOGICAL                ::   ll_wrtstp, ll_colruns, ll_wrtruns
-      CHARACTER(len=20) :: clname
-      !!----------------------------------------------------------------------
-      !
-      ll_wrtstp  = ( MOD( kt, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend )
-      ll_colruns = ll_wrtstp .AND. ( sn_cfctl%l_runstat )
-      ll_wrtruns = ll_colruns .AND. lwm
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'stp_ctl : time-stepping control'
-         WRITE(numout,*) '~~~~~~~'
-         !                                ! open time.step file
-         IF( lwm ) CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
-         !                                ! open run.stat file(s) at start whatever
-         !                                ! the value of sn_cfctl%ptimincr
-         IF( lwm .AND. ( sn_cfctl%l_runstat ) ) THEN
+      INTEGER, INTENT(in   ) ::   Kmm      ! ocean time level index
+      !!
+      INTEGER                         ::   ji                                    ! dummy loop indices
+      INTEGER                         ::   idtime, istatus
+      INTEGER , DIMENSION(3)          ::   iareasum, iareamin, iareamax
+      INTEGER , DIMENSION(3,2)        ::   iloc                                  ! min/max loc indices
+      REAL(wp)                        ::   zzz                                   ! local real 
+      REAL(wp), DIMENSION(3)          ::   zmax, zmaxlocal
+      LOGICAL                         ::   ll_wrtstp, ll_colruns, ll_wrtruns
+      LOGICAL, DIMENSION(jpi,jpj,jpk) ::   llmsk
+      CHARACTER(len=20)               ::   clname
+      !!----------------------------------------------------------------------
+      IF( nstop > 0 .AND. ngrdstop > -1 )   RETURN   !   stpctl was already called by a child grid
+      !
+      ll_wrtstp  = ( MOD( kt-nit000, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend )
+      ll_colruns = ll_wrtstp .AND. sn_cfctl%l_runstat .AND. jpnij > 1 
+      ll_wrtruns = ( ll_colruns .OR. jpnij == 1 ) .AND. lwm
+      !
+      IF( kt == nit000 ) THEN
+         !
+         IF( lwp ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'stp_ctl : time-stepping control'
+            WRITE(numout,*) '~~~~~~~'
+         ENDIF
+         !                                ! open time.step    ascii file, done only by 1st subdomain
+         IF( lwm )   CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
+         !
+         IF( ll_wrtruns ) THEN
+            !                             ! open run.stat     ascii file, done only by 1st subdomain
             CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
+            !                             ! open run.stat.nc netcdf file, done only by 1st subdomain
             clname = 'run.stat.nc'
             IF( .NOT. Agrif_Root() )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
-            istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, idrun )
-            istatus = NF90_DEF_DIM( idrun, 'time', NF90_UNLIMITED, idtime )
-            istatus = NF90_DEF_VAR( idrun, 'abs_ssh_max', NF90_DOUBLE, (/ idtime /), idssh )
-            istatus = NF90_DEF_VAR( idrun,   'abs_u_max', NF90_DOUBLE, (/ idtime /), idu   )
-            istatus = NF90_ENDDEF(idrun)
-         ENDIF
-      ENDIF
-      IF( kt == nit000 )   lsomeoce = COUNT( ssmask(:,:) == 1._wp ) > 0
-      !
-      IF(lwm .AND. ll_wrtstp) THEN        !==  current time step  ==!   ("time.step" file)
+            istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, nrunid )
+            istatus = NF90_DEF_DIM( nrunid, 'time', NF90_UNLIMITED, idtime )
+            istatus = NF90_DEF_VAR( nrunid, 'abs_ssh_max', NF90_DOUBLE, (/ idtime /), nvarid(1) )
+            istatus = NF90_DEF_VAR( nrunid,   'abs_u_max', NF90_DOUBLE, (/ idtime /), nvarid(2) )
+            istatus = NF90_ENDDEF(nrunid)
+         ENDIF
+         !    
+      ENDIF
+      !
+      !                                   !==              write current time step              ==!
+      !                                   !==  done only by 1st subdomain at writting timestep  ==!
+      IF( lwm .AND. ll_wrtstp ) THEN
          WRITE ( numstp, '(1x, i8)' )   kt
          REWIND( numstp )
       ENDIF
-      !
-      !                                   !==  test of extrema  ==!
-      IF( ll_wd ) THEN
-         zmax(1) = MAXVAL(  ABS( ssh(:,:,Kmm) + ssh_ref*tmask(:,:,1) )  )        ! ssh max 
-      ELSE
-         zmax(1) = MINVAL( e3t(:,:,1,Kmm)  )                                         ! ssh min
-      ENDIF
-      zmax(2) = MAXVAL(  ABS( uu(:,:,:,Kmm) )  )                                  ! velocity max (zonal only)
-      zmax(3) = REAL( nstop , wp )                                            ! stop indicator
-      !
+      !                                   !==            test of local extrema           ==!
+      !                                   !==  done by all processes at every time step  ==!
+      !
+      llmsk(   1:Nis1,:,:) = .FALSE.                                              ! exclude halos from the checked region
+      llmsk(Nie1: jpi,:,:) = .FALSE.
+      llmsk(:,   1:Njs1,:) = .FALSE.
+      llmsk(:,Nje1: jpj,:) = .FALSE.
+      !
+      llmsk(Nis0:Nie0,Njs0:Nje0,1) = tmask(Nis0:Nie0,Njs0:Nje0,1) == 1._wp         ! define only the inner domain
+      zmax(1) = MAXVAL(     -e3t(:,:,1,Kmm) ), mask = llmsk(:,:,1) )      ! ssh max
+      llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+      zmax(2) = MAXVAL(  ABS( uu(:,:,:,Kmm) ), mask = llmsk(:,:,:) )                     ! velocity max (zonal only)
+      zmax(3) = REAL( nstop, wp )                                                 ! stop indicator
+      !                                   !==               get global extrema             ==!
+      !                                   !==  done by all processes if writting run.stat  ==!
       IF( ll_colruns ) THEN
+         zmaxlocal(:) = zmax(:)
          CALL mpp_max( "stpctl", zmax )          ! max over the global domain
-         nstop = NINT( zmax(3) )                 ! nstop indicator sheared among all local domains
-      ENDIF
-      !                                   !==  run statistics  ==!   ("run.stat" files)
+         nstop = NINT( zmax(3) )                 ! update nstop indicator (now sheared among all local domains)
+      ENDIF
+      !                                   !==              write "run.stat" files              ==!
+      !                                   !==  done only by 1st subdomain at writting timestep  ==!
       IF( ll_wrtruns ) THEN
          WRITE(numrun,9500) kt, zmax(1), zmax(2)
-         istatus = NF90_PUT_VAR( idrun, idssh, (/ zmax(1)/), (/kt/), (/1/) )
-         istatus = NF90_PUT_VAR( idrun,   idu, (/ zmax(2)/), (/kt/), (/1/) )
-         IF( MOD( kt , 100 ) == 0 ) istatus = NF90_SYNC(idrun)
-         IF( kt == nitend         ) istatus = NF90_CLOSE(idrun)
+         istatus = NF90_PUT_VAR( nrunid, nvarid(1), (/ -zmax(1)/), (/kt/), (/1/) )
+         istatus = NF90_PUT_VAR( nrunid, nvarid(2), (/  zmax(2)/), (/kt/), (/1/) )
+         IF( kt == nitend )   istatus = NF90_CLOSE(nrunid)
       END IF
-      !                                   !==  error handling  ==!
-      IF( ( sn_cfctl%l_glochk .OR. lsomeoce ) .AND. (   &  ! domain contains some ocean points, check for sensible ranges
-         &  zmax(1) <    0._wp .OR.   &                    ! negative sea surface height 
-         &  zmax(2) >   10._wp .OR.   &                    ! too large velocity ( > 10 m/s)
-         &  ISNAN( zmax(1) + zmax(2) ) ) ) THEN            ! NaN encounter in the tests
-         IF( lk_mpp .AND. sn_cfctl%l_glochk ) THEN
-            ! have use mpp_max (because sn_cfctl%l_glochk=.T. and distributed)
-            CALL mpp_maxloc( 'stpctl', ABS(ssh(:,:,Kmm))        , ssmask(:,:)  , zzz, ih  )
-            CALL mpp_maxloc( 'stpctl', ABS(uu(:,:,:,Kmm))          , umask (:,:,:), zzz, iu  )
+      !                                   !==               error handling               ==!
+      !                                   !==  done by all processes at every time step  ==!
+      !
+      IF(   zmax(1) >  0._wp           .OR.   &               ! negative sea surface height 
+         &  zmax(2) > 10._wp           .OR.   &               ! too large velocity ( > 10 m/s)
+         &  ISNAN( zmax(1) + zmax(2) ) .OR.   &               ! NaN encounter in the tests
+         &  ABS(   zmax(1) + zmax(2) ) > HUGE(1._wp) ) THEN   ! Infinity encounter in the tests
+         !
+         iloc(:,:) = 0
+         IF( ll_colruns ) THEN   ! zmax is global, so it is the same on all subdomains -> no dead lock with mpp_maxloc
+            ! first: close the netcdf file, so we can read it
+            IF( lwm .AND. kt /= nitend )   istatus = NF90_CLOSE(nrunid)
+            ! get global loc on the min/max
+            llmsk(Nis0:Nie0,Njs0:Nje0,1) = tmask(Nis0:Nie0,Njs0:Nje0,1) == 1._wp         ! define only the inner domain
+            CALL mpp_maxloc( 'stpctl',   -e3t(:,:,1,Kmm) , llmsk(:,:,1), zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
+            llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+            CALL mpp_maxloc( 'stpctl', ABS(uu(:,:,:,Kmm)), llmsk(:,:,:), zzz, iloc(1:3,2) )
+            ! find which subdomain has the max.
+            iareamin(:) = jpnij+1   ;   iareamax(:) = 0   ;   iareasum(:) = 0
+            DO ji = 1, 3
+               IF( zmaxlocal(ji) == zmax(ji) ) THEN
+                  iareamin(ji) = narea   ;   iareamax(ji) = narea   ;   iareasum(ji) = 1
+               ENDIF
+            END DO
+            CALL mpp_min( "stpctl", iareamin )         ! min over the global domain
+            CALL mpp_max( "stpctl", iareamax )         ! max over the global domain
+            CALL mpp_sum( "stpctl", iareasum )         ! sum over the global domain
+         ELSE                    ! find local min and max locations:
+            ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc
+            llmsk(Nis0:Nie0,Njs0:Nje0,1) = tmask(Nis0:Nie0,Njs0:Nje0,1) == 1._wp         ! define only the inner domain
+            iloc(1:2,1) = MAXLOC(   -e3t(:,:,1,Kmm) , mask = llmsk(:,:,1) )
+            llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+            iloc(1:3,2) = MAXLOC( ABS(uu(:,:,:,Kmm)), mask = llmsk(:,:,:) )
+            DO ji = 1, 2   ! local domain indices ==> global domain indices, excluding halos
+               iloc(1:2,ji) = (/ mig0(iloc(1,ji)), mjg0(iloc(2,ji)) /)
+            END DO
+            iareamin(:) = narea   ;   iareamax(:) = narea   ;   iareasum(:) = 1         ! this is local information
+         ENDIF
+         !
+         WRITE(ctmp1,*) ' stp_ctl: |ssh| > 20 m  or  |U| > 10 m/s  or  S <= 0  or  S >= 100  or  NaN encounter in the tests'
+         CALL wrt_line( ctmp2, kt, '|e3t| min', -zmax(1), iloc(:,1), iareasum(1), iareamin(1), iareamax(1) )
+         CALL wrt_line( ctmp3, kt, '|U|   max',  zmax(2), iloc(:,2), iareasum(2), iareamin(2), iareamax(2) )
+         IF( Agrif_Root() ) THEN
+            WRITE(ctmp6,*) '      ===> output of last computed fields in output.abort* files'
          ELSE
-            ! find local min and max locations
-            ih(:)  = MAXLOC( ABS( ssh(:,:,Kmm)   )                              ) + (/ nimpp - 1, njmpp - 1    /)
-            iu(:)  = MAXLOC( ABS( uu  (:,:,:,Kmm) )                              ) + (/ nimpp - 1, njmpp - 1, 0 /)
-         ENDIF
-         
-         WRITE(ctmp1,*) ' stp_ctl: (e3t0) ssh < 0 m  or  |U| > 10 m/s  or  NaN encounter in the tests'
-         WRITE(ctmp2,9100) kt,   zmax(1), ih(1) , ih(2)
-         WRITE(ctmp3,9200) kt,   zmax(2), iu(1) , iu(2) , iu(3)
-         WRITE(ctmp4,*) '      ===> output of last computed fields in output.abort.nc file'
-         
+            WRITE(ctmp6,*) '      ===> output of last computed fields in '//TRIM(Agrif_CFixed())//'_output.abort* files'
+         ENDIF
+         !
          CALL dia_wri_state( Kmm, 'output.abort' )     ! create an output.abort file
-         
-         IF( .NOT. sn_cfctl%l_glochk ) THEN
-            WRITE(ctmp8,*) 'E R R O R message from sub-domain: ', narea
-            CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp8, ' ', ctmp2, ctmp3, ctmp4 )
-         ELSE
-            CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ctmp4 )
-         ENDIF
-
-         kindic = -3
-         !
-      ENDIF
-      !
-9100  FORMAT (' kt=',i8,'   |ssh| min: ',1pg11.4,', at  i j  : ',2i5)
-9200  FORMAT (' kt=',i8,'   |U|   max: ',1pg11.4,', at  i j k: ',3i5)
-9500  FORMAT(' it :', i8, '    |ssh|_max: ', D23.16, ' |U|_max: ', D23.16)
+         !
+         IF( ll_colruns .or. jpnij == 1 ) THEN   ! all processes synchronized -> use lwp to print in opened ocean.output files
+            IF(lwp) THEN   ;   CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ' ', ctmp6 )
+            ELSE           ;   nstop = MAX(1, nstop)   ! make sure nstop > 0 (automatically done when calling ctl_stop)
+            ENDIF
+         ELSE                                    ! only mpi subdomains with errors are here -> STOP now
+            CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp2, ctmp3, ' ', ctmp6 )
+         ENDIF
+         !
+      ENDIF
+      !
+      IF( nstop > 0 ) THEN                                                  ! an error was detected and we did not abort yet...
+         ngrdstop = Agrif_Fixed()                                           ! store which grid got this error
+         IF( .NOT. ll_colruns .AND. jpnij > 1 )   CALL ctl_stop( 'STOP' )   ! we must abort here to avoid MPI deadlock
+      ENDIF
+      !
+9500  FORMAT(' it :', i8, '    |ssh|_max: ', D23.16, ' |U|_max: ', D23.16,' S_min: ', D23.16,' S_max: ', D23.16)
       !
    END SUBROUTINE stp_ctl
+
+
+   SUBROUTINE wrt_line( cdline, kt, cdprefix, pval, kloc, ksum, kmin, kmax )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE wrt_line  ***
+      !!
+      !! ** Purpose :   write information line
+      !!
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*),      INTENT(  out) ::   cdline
+      CHARACTER(len=*),      INTENT(in   ) ::   cdprefix
+      REAL(wp),              INTENT(in   ) ::   pval
+      INTEGER, DIMENSION(3), INTENT(in   ) ::   kloc
+      INTEGER,               INTENT(in   ) ::   kt, ksum, kmin, kmax
+      !
+      CHARACTER(len=80) ::   clsuff
+      CHARACTER(len=9 ) ::   clkt, clsum, clmin, clmax
+      CHARACTER(len=9 ) ::   cli, clj, clk
+      CHARACTER(len=1 ) ::   clfmt
+      CHARACTER(len=4 ) ::   cl4   ! needed to be able to compile with Agrif, I don't know why
+      INTEGER           ::   ifmtk
+      !!----------------------------------------------------------------------
+      WRITE(clkt , '(i9)') kt
+      
+      WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpnij  ,wp))) + 1     ! how many digits to we need to write ? (we decide max = 9)
+      !!! WRITE(clsum, '(i'//clfmt//')') ksum                   ! this is creating a compilation error with AGRIF
+      cl4 = '(i'//clfmt//')'   ;   WRITE(clsum, cl4) ksum
+      WRITE(clfmt, '(i1)') INT(LOG10(REAL(MAX(1,jpnij-1),wp))) + 1    ! how many digits to we need to write ? (we decide max = 9)
+      cl4 = '(i'//clfmt//')'   ;   WRITE(clmin, cl4) kmin-1
+                                   WRITE(clmax, cl4) kmax-1
+      !
+      WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpiglo,wp))) + 1      ! how many digits to we need to write jpiglo? (we decide max = 9)
+      cl4 = '(i'//clfmt//')'   ;   WRITE(cli, cl4) kloc(1)      ! this is ok with AGRIF
+      WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpjglo,wp))) + 1      ! how many digits to we need to write jpjglo? (we decide max = 9)
+      cl4 = '(i'//clfmt//')'   ;   WRITE(clj, cl4) kloc(2)      ! this is ok with AGRIF
+      !
+      IF( ksum == 1 ) THEN   ;   WRITE(clsuff,9100) TRIM(clmin)
+      ELSE                   ;   WRITE(clsuff,9200) TRIM(clsum), TRIM(clmin), TRIM(clmax)
+      ENDIF
+      IF(kloc(3) == 0) THEN
+         ifmtk = INT(LOG10(REAL(jpk,wp))) + 1                   ! how many digits to we need to write jpk? (we decide max = 9)
+         clk = REPEAT(' ', ifmtk)                               ! create the equivalent in blank string
+         WRITE(cdline,9300) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj), clk(1:ifmtk), TRIM(clsuff)
+      ELSE
+         WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpk,wp))) + 1      ! how many digits to we need to write jpk? (we decide max = 9)
+         !!! WRITE(clk, '(i'//clfmt//')') kloc(3)               ! this is creating a compilation error with AGRIF
+         cl4 = '(i'//clfmt//')'   ;   WRITE(clk, cl4) kloc(3)   ! this is ok with AGRIF
+         WRITE(cdline,9400) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj),    TRIM(clk), TRIM(clsuff)
+      ENDIF
+      !
+9100  FORMAT('MPI rank ', a)
+9200  FORMAT('found in ', a, ' MPI tasks, spread out among ranks ', a, ' to ', a)
+9300  FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j   ', a, ' ', a, ' ', a, ' ', a)
+9400  FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j k ', a, ' ', a, ' ', a, ' ', a)
+      !
+   END SUBROUTINE wrt_line
+
 
    !!======================================================================
Index: /NEMO/trunk/tests/CANAL/MY_SRC/domvvl.F90
===================================================================
--- /NEMO/trunk/tests/CANAL/MY_SRC/domvvl.F90	(revision 13457)
+++ /NEMO/trunk/tests/CANAL/MY_SRC/domvvl.F90	(revision 13458)
@@ -9,14 +9,7 @@
    !!            3.6  !  2014-11  (P. Mathiot) add ice shelf capability
    !!            4.1  !  2019-08  (A. Coward, D. Storkey) rename dom_vvl_sf_swp -> dom_vvl_sf_update for new timestepping
+   !!            4.x  ! 2020-02  (G. Madec, S. Techene) introduce ssh to h0 ratio
    !!----------------------------------------------------------------------
 
-   !!----------------------------------------------------------------------
-   !!   dom_vvl_init     : define initial vertical scale factors, depths and column thickness
-   !!   dom_vvl_sf_nxt   : Compute next vertical scale factors
-   !!   dom_vvl_sf_update   : 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
-   !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers
    USE phycst          ! physical constant
@@ -36,10 +29,4 @@
    PRIVATE
 
-   PUBLIC  dom_vvl_init       ! called by domain.F90
-   PUBLIC  dom_vvl_zgr        ! called by isfcpl.F90
-   PUBLIC  dom_vvl_sf_nxt     ! called by step.F90
-   PUBLIC  dom_vvl_sf_update  ! called by step.F90
-   PUBLIC  dom_vvl_interpol   ! called by dynnxt.F90
-
    !                                                      !!* Namelist nam_vvl
    LOGICAL , PUBLIC :: ln_vvl_zstar           = .FALSE.    ! zstar  vertical coordinate
@@ -63,4 +50,28 @@
    REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: frq_rst_hdv                 ! retoring period for low freq. divergence
 
+#if defined key_qco
+   !!----------------------------------------------------------------------
+   !!   'key_qco'      EMPTY MODULE      Quasi-Eulerian vertical coordonate
+   !!----------------------------------------------------------------------
+#else
+   !!----------------------------------------------------------------------
+   !!   Default key      Old management of time varying vertical coordinate
+   !!----------------------------------------------------------------------
+   
+   !!----------------------------------------------------------------------
+   !!   dom_vvl_init     : define initial vertical scale factors, depths and column thickness
+   !!   dom_vvl_sf_nxt   : Compute next vertical scale factors
+   !!   dom_vvl_sf_update   : 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
+   !!----------------------------------------------------------------------
+
+   PUBLIC  dom_vvl_init       ! called by domain.F90
+   PUBLIC  dom_vvl_zgr        ! called by isfcpl.F90
+   PUBLIC  dom_vvl_sf_nxt     ! called by step.F90
+   PUBLIC  dom_vvl_sf_update  ! called by step.F90
+   PUBLIC  dom_vvl_interpol   ! called by dynnxt.F90
+   
    !! * Substitutions
 #  include "do_loop_substitute.h90"
@@ -135,5 +146,6 @@
       !
    END SUBROUTINE dom_vvl_init
-   !
+
+
    SUBROUTINE dom_vvl_zgr(Kbb, Kmm, Kaa)
       !!----------------------------------------------------------------------
@@ -261,6 +273,6 @@
             IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA" ) THEN
                IF( nn_cfg == 3 ) THEN   ! ORCA2: Suppress ztilde in the Foxe Basin for ORCA2
-                  ii0 = 103   ;   ii1 = 111       
-                  ij0 = 128   ;   ij1 = 135   ;   
+                  ii0 = 103 + nn_hls - 1   ;   ii1 = 111 + nn_hls - 1      
+                  ij0 = 128 + nn_hls       ;   ij1 = 135 + nn_hls
                   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 / rn_Dt
@@ -322,5 +334,6 @@
       LOGICAL                ::   ll_do_bclinic         ! local logical
       REAL(wp), DIMENSION(jpi,jpj)     ::   zht, z_scale, zwu, zwv, zhdiv
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze3t
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ze3t
+      LOGICAL , DIMENSION(:,:,:), ALLOCATABLE ::   llmsk
       !!----------------------------------------------------------------------
       !
@@ -435,25 +448,21 @@
          ! Maximum deformation control
          ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-         ze3t(:,:,jpk) = 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(:,:,:) )
-         CALL mpp_max( 'domvvl', z_tmax )                 ! max over the global domain
-         z_tmin = MINVAL( ze3t(:,:,:) )
-         CALL mpp_min( 'domvvl', z_tmin )                 ! min over the global domain
+         ALLOCATE( ze3t(jpi,jpj,jpk), llmsk(jpi,jpj,jpk) )
+         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+            ze3t(ji,jj,jk) = tilde_e3t_a(ji,jj,jk) / e3t_0(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+         END_3D
+         !
+         llmsk(   1:Nis1,:,:) = .FALSE.   ! exclude halos from the checked region
+         llmsk(Nie1: jpi,:,:) = .FALSE.
+         llmsk(:,   1:Njs1,:) = .FALSE.
+         llmsk(:,Nje1: jpj,:) = .FALSE.
+         !
+         llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp                  ! define only the inner domain
+         z_tmax = MAXVAL( ze3t(:,:,:), mask = llmsk )   ;   CALL mpp_max( 'domvvl', z_tmax )   ! max over the global domain
+         z_tmin = MINVAL( ze3t(:,:,:), mask = llmsk )   ;   CALL mpp_min( 'domvvl', z_tmin )   ! min over the global domain
          ! - ML - test: for the moment, stop simulation for too large e3_t variations
          IF( ( z_tmax >  rn_zdef_max ) .OR. ( z_tmin < - rn_zdef_max ) ) THEN
-            IF( lk_mpp ) THEN
-               CALL mpp_maxloc( 'domvvl', ze3t, tmask, z_tmax, ijk_max )
-               CALL mpp_minloc( 'domvvl', ze3t, tmask, z_tmin, ijk_min )
-            ELSE
-               ijk_max = MAXLOC( ze3t(:,:,:) )
-               ijk_max(1) = mig0_oldcmp(ijk_max(1))
-               ijk_max(2) = mjg0_oldcmp(ijk_max(2))
-               ijk_min = MINLOC( ze3t(:,:,:) )
-               ijk_min(1) = mig0_oldcmp(ijk_min(1))
-               ijk_min(2) = mjg0_oldcmp(ijk_min(2))
-            ENDIF
+            CALL mpp_maxloc( 'domvvl', ze3t, llmsk, z_tmax, ijk_max )
+            CALL mpp_minloc( 'domvvl', ze3t, llmsk, z_tmin, ijk_min )
             IF (lwp) THEN
                WRITE(numout, *) 'MAX( tilde_e3t_a(:,:,:) / e3t_0(:,:,:) ) =', z_tmax
@@ -464,4 +473,5 @@
             ENDIF
          ENDIF
+         DEALLOCATE( ze3t, llmsk )
          ! - ML - end test
          ! - ML - Imposing these limits will cause a baroclinicity error which is corrected for below
@@ -1030,4 +1040,6 @@
    END SUBROUTINE dom_vvl_ctl
 
+#endif
+
    !!======================================================================
 END MODULE domvvl
Index: /NEMO/trunk/tests/CANAL/MY_SRC/stpctl.F90
===================================================================
--- /NEMO/trunk/tests/CANAL/MY_SRC/stpctl.F90	(revision 13457)
+++ /NEMO/trunk/tests/CANAL/MY_SRC/stpctl.F90	(revision 13458)
@@ -49,5 +49,4 @@
       !!
       !! ** Method  : - Save the time step in numstp
-      !!              - Print it each 50 time steps
       !!              - Stop the run IF problem encountered by setting nstop > 0
       !!                Problems checked: |ssh| maximum larger than 10 m
@@ -119,5 +118,11 @@
       !                                   !==            test of local extrema           ==!
       !                                   !==  done by all processes at every time step  ==!
-      llmsk(:,:,1) = ssmask(:,:) == 1._wp
+      !
+      llmsk(   1:Nis1,:,:) = .FALSE.                                              ! exclude halos from the checked region
+      llmsk(Nie1: jpi,:,:) = .FALSE.
+      llmsk(:,   1:Njs1,:) = .FALSE.
+      llmsk(:,Nje1: jpj,:) = .FALSE.
+      !
+      llmsk(Nis0:Nie0,Njs0:Nje0,1) = ssmask(Nis0:Nie0,Njs0:Nje0) == 1._wp         ! define only the inner domain
       IF( ll_wd ) THEN
          zmax(1) = MAXVAL( ABS( ssh(:,:,Kmm) + ssh_ref ), mask = llmsk(:,:,1) )   ! ssh max
@@ -125,7 +130,7 @@
          zmax(1) = MAXVAL( ABS( ssh(:,:,Kmm)           ), mask = llmsk(:,:,1) )   ! ssh max
       ENDIF
-      llmsk(:,:,:) = umask(:,:,:) == 1._wp
+      llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
       zmax(2) = MAXVAL(  ABS( uu(:,:,:,Kmm) ), mask = llmsk )                     ! velocity max (zonal only)
-      llmsk(:,:,:) = tmask(:,:,:) == 1._wp
+      llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
       zmax(3) = MAXVAL( -ts(:,:,:,jp_sal,Kmm), mask = llmsk )                     ! minus salinity max
       zmax(4) = MAXVAL(  ts(:,:,:,jp_sal,Kmm), mask = llmsk )                     !       salinity max
@@ -143,5 +148,5 @@
          zmax(5:8) = 0._wp
       ENDIF
-      zmax(9) = REAL( nstop, wp )                                              ! stop indicator
+      zmax(9) = REAL( nstop, wp )                                                 ! stop indicator
       !                                   !==               get global extrema             ==!
       !                                   !==  done by all processes if writting run.stat  ==!
@@ -183,8 +188,11 @@
             IF( lwm .AND. kt /= nitend )   istatus = NF90_CLOSE(nrunid)
             ! get global loc on the min/max
-            CALL mpp_maxloc( 'stpctl', ABS(ssh(:,:,         Kmm)), ssmask(:,:  ), zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
-            CALL mpp_maxloc( 'stpctl', ABS( uu(:,:,:,       Kmm)),  umask(:,:,:), zzz, iloc(1:3,2) )
-            CALL mpp_minloc( 'stpctl',      ts(:,:,:,jp_sal,Kmm) ,  tmask(:,:,:), zzz, iloc(1:3,3) )
-            CALL mpp_maxloc( 'stpctl',      ts(:,:,:,jp_sal,Kmm) ,  tmask(:,:,:), zzz, iloc(1:3,4) )
+            llmsk(Nis0:Nie0,Njs0:Nje0,1) = ssmask(Nis0:Nie0,Njs0:Nje0 ) == 1._wp         ! define only the inner domain
+            CALL mpp_maxloc( 'stpctl', ABS(ssh(:,:,         Kmm)), llmsk(:,:,1), zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
+            llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+            CALL mpp_maxloc( 'stpctl', ABS( uu(:,:,:,       Kmm)), llmsk(:,:,:), zzz, iloc(1:3,2) )
+            llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+            CALL mpp_minloc( 'stpctl',      ts(:,:,:,jp_sal,Kmm) , llmsk(:,:,:), zzz, iloc(1:3,3) )
+            CALL mpp_maxloc( 'stpctl',      ts(:,:,:,jp_sal,Kmm) , llmsk(:,:,:), zzz, iloc(1:3,4) )
             ! find which subdomain has the max.
             iareamin(:) = jpnij+1   ;   iareamax(:) = 0   ;   iareasum(:) = 0
@@ -199,8 +207,14 @@
          ELSE                    ! find local min and max locations:
             ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc
-            iloc(1:2,1) = MAXLOC( ABS( ssh(:,:,         Kmm)), mask = ssmask(:,:  ) == 1._wp ) + (/ nimpp - 1, njmpp - 1    /)
-            iloc(1:3,2) = MAXLOC( ABS(  uu(:,:,:,       Kmm)), mask =  umask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
-            iloc(1:3,3) = MINLOC(       ts(:,:,:,jp_sal,Kmm) , mask =  tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
-            iloc(1:3,4) = MAXLOC(       ts(:,:,:,jp_sal,Kmm) , mask =  tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
+            llmsk(Nis0:Nie0,Njs0:Nje0,1) = ssmask(Nis0:Nie0,Njs0:Nje0 ) == 1._wp         ! define only the inner domain
+            iloc(1:2,1) = MAXLOC( ABS( ssh(:,:,         Kmm)), mask = llmsk(:,:,1) )
+            llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+            iloc(1:3,2) = MAXLOC( ABS(  uu(:,:,:,       Kmm)), mask = llmsk(:,:,:) )
+            llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
+            iloc(1:3,3) = MINLOC(       ts(:,:,:,jp_sal,Kmm) , mask = llmsk(:,:,:) )
+            iloc(1:3,4) = MAXLOC(       ts(:,:,:,jp_sal,Kmm) , mask = llmsk(:,:,:) )
+            DO ji = 1, 4   ! local domain indices ==> global domain indices, excluding halos
+               iloc(1:2,ji) = (/ mig0(iloc(1,ji)), mjg0(iloc(2,ji)) /)
+            END DO
             iareamin(:) = narea   ;   iareamax(:) = narea   ;   iareasum(:) = 1         ! this is local information
          ENDIF
Index: /NEMO/trunk/tests/STATION_ASF/MY_SRC/stpctl.F90
===================================================================
--- /NEMO/trunk/tests/STATION_ASF/MY_SRC/stpctl.F90	(revision 13457)
+++ /NEMO/trunk/tests/STATION_ASF/MY_SRC/stpctl.F90	(revision 13458)
@@ -47,5 +47,4 @@
       !!
       !! ** Method  : - Save the time step in numstp
-      !!              - Print it each 50 time steps
       !!              - Stop the run IF problem encountered by setting nstop > 0
       !!                Problems checked: wind stress module  max larger than 5 N/m^2
@@ -110,5 +109,11 @@
       !                                   !==            test of local extrema           ==!
       !                                   !==  done by all processes at every time step  ==!
-      llmsk(:,:) = tmask(:,:,1) == 1._wp
+      !
+      llmsk(   1:Nis1,:) = .FALSE.                                              ! exclude halos from the checked region
+      llmsk(Nie1: jpi,:) = .FALSE.
+      llmsk(:,   1:Njs1) = .FALSE.
+      llmsk(:,Nje1: jpj) = .FALSE.
+      !
+      llmsk(Nis0:Nie0,Njs0:Nje0) = tmask(Nis0:Nie0,Njs0:Nje0,1) == 1._wp   ! test only the inner domain
       IF( COUNT( llmsk(:,:) ) > 0 ) THEN   ! avoid huge values sent back for land processors...
          zmax(1) = MAXVAL(     taum(:,:)   , mask = llmsk )   ! max wind stress module
@@ -153,7 +158,7 @@
             IF( lwm .AND. kt /= nitend )   istatus = NF90_CLOSE(nrunid)
             ! get global loc on the min/max
-            CALL mpp_maxloc( 'stpctl',    taum(:,:)  , tmask(:,:,1), zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
-            CALL mpp_maxloc( 'stpctl',ABS( qns(:,:) ), tmask(:,:,1), zzz, iloc(1:2,2) )
-            CALL mpp_minloc( 'stpctl',ABS( emp(:,:) ), tmask(:,:,1), zzz, iloc(1:2,3) )
+            CALL mpp_maxloc( 'stpctl',    taum(:,:)  , llmsk, zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
+            CALL mpp_maxloc( 'stpctl',ABS( qns(:,:) ), llmsk, zzz, iloc(1:2,2) )
+            CALL mpp_minloc( 'stpctl',ABS( emp(:,:) ), llmsk, zzz, iloc(1:2,3) )
             ! find which subdomain has the max.
             iareamin(:) = jpnij+1   ;   iareamax(:) = 0   ;   iareasum(:) = 0
@@ -168,7 +173,10 @@
          ELSE                    ! find local min and max locations:
             ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc
-            iloc(1:2,1) = MAXLOC(     taum(:,:)  , mask = llmsk ) + (/ nimpp - 1, njmpp - 1/)
-            iloc(1:2,2) = MAXLOC( ABS( qns(:,:) ), mask = llmsk ) + (/ nimpp - 1, njmpp - 1/)
-            iloc(1:2,3) = MINLOC( ABS( emp(:,:) ), mask = llmsk ) + (/ nimpp - 1, njmpp - 1/)
+            iloc(1:2,1) = MAXLOC(     taum(:,:)  , mask = llmsk )
+            iloc(1:2,2) = MAXLOC( ABS( qns(:,:) ), mask = llmsk )
+            iloc(1:2,3) = MINLOC( ABS( emp(:,:) ), mask = llmsk )
+            DO ji = 1, 3   ! local domain indices ==> global domain indices, excluding halos
+               iloc(1:2,ji) = (/ mig0(iloc(1,ji)), mjg0(iloc(2,ji)) /)
+            END DO
             iareamin(:) = narea   ;   iareamax(:) = narea   ;   iareasum(:) = 1         ! this is local information
          ENDIF
Index: /NEMO/trunk/tests/VORTEX/MY_SRC/domvvl.F90
===================================================================
--- /NEMO/trunk/tests/VORTEX/MY_SRC/domvvl.F90	(revision 13457)
+++ /NEMO/trunk/tests/VORTEX/MY_SRC/domvvl.F90	(revision 13458)
@@ -9,14 +9,7 @@
    !!            3.6  !  2014-11  (P. Mathiot) add ice shelf capability
    !!            4.1  !  2019-08  (A. Coward, D. Storkey) rename dom_vvl_sf_swp -> dom_vvl_sf_update for new timestepping
+   !!            4.x  ! 2020-02  (G. Madec, S. Techene) introduce ssh to h0 ratio
    !!----------------------------------------------------------------------
 
-   !!----------------------------------------------------------------------
-   !!   dom_vvl_init     : define initial vertical scale factors, depths and column thickness
-   !!   dom_vvl_sf_nxt   : Compute next vertical scale factors
-   !!   dom_vvl_sf_update   : 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
-   !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers
    USE phycst          ! physical constant
@@ -36,10 +29,4 @@
    PRIVATE
 
-   PUBLIC  dom_vvl_init       ! called by domain.F90
-   PUBLIC  dom_vvl_zgr        ! called by isfcpl.F90
-   PUBLIC  dom_vvl_sf_nxt     ! called by step.F90
-   PUBLIC  dom_vvl_sf_update  ! called by step.F90
-   PUBLIC  dom_vvl_interpol   ! called by dynnxt.F90
-
    !                                                      !!* Namelist nam_vvl
    LOGICAL , PUBLIC :: ln_vvl_zstar           = .FALSE.    ! zstar  vertical coordinate
@@ -63,4 +50,28 @@
    REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: frq_rst_hdv                 ! retoring period for low freq. divergence
 
+#if defined key_qco
+   !!----------------------------------------------------------------------
+   !!   'key_qco'      EMPTY MODULE      Quasi-Eulerian vertical coordonate
+   !!----------------------------------------------------------------------
+#else
+   !!----------------------------------------------------------------------
+   !!   Default key      Old management of time varying vertical coordinate
+   !!----------------------------------------------------------------------
+   
+   !!----------------------------------------------------------------------
+   !!   dom_vvl_init     : define initial vertical scale factors, depths and column thickness
+   !!   dom_vvl_sf_nxt   : Compute next vertical scale factors
+   !!   dom_vvl_sf_update   : 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
+   !!----------------------------------------------------------------------
+
+   PUBLIC  dom_vvl_init       ! called by domain.F90
+   PUBLIC  dom_vvl_zgr        ! called by isfcpl.F90
+   PUBLIC  dom_vvl_sf_nxt     ! called by step.F90
+   PUBLIC  dom_vvl_sf_update  ! called by step.F90
+   PUBLIC  dom_vvl_interpol   ! called by dynnxt.F90
+   
    !! * Substitutions
 #  include "do_loop_substitute.h90"
@@ -135,5 +146,6 @@
       !
    END SUBROUTINE dom_vvl_init
-   !
+
+
    SUBROUTINE dom_vvl_zgr(Kbb, Kmm, Kaa)
       !!----------------------------------------------------------------------
@@ -261,6 +273,6 @@
             IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA" ) THEN
                IF( nn_cfg == 3 ) THEN   ! ORCA2: Suppress ztilde in the Foxe Basin for ORCA2
-                  ii0 = 103   ;   ii1 = 111       
-                  ij0 = 128   ;   ij1 = 135   ;   
+                  ii0 = 103 + nn_hls - 1   ;   ii1 = 111 + nn_hls - 1      
+                  ij0 = 128 + nn_hls       ;   ij1 = 135 + nn_hls
                   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 / rn_Dt
@@ -322,5 +334,6 @@
       LOGICAL                ::   ll_do_bclinic         ! local logical
       REAL(wp), DIMENSION(jpi,jpj)     ::   zht, z_scale, zwu, zwv, zhdiv
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze3t
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ze3t
+      LOGICAL , DIMENSION(:,:,:), ALLOCATABLE ::   llmsk
       !!----------------------------------------------------------------------
       !
@@ -435,25 +448,21 @@
          ! Maximum deformation control
          ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-         ze3t(:,:,jpk) = 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(:,:,:) )
-         CALL mpp_max( 'domvvl', z_tmax )                 ! max over the global domain
-         z_tmin = MINVAL( ze3t(:,:,:) )
-         CALL mpp_min( 'domvvl', z_tmin )                 ! min over the global domain
+         ALLOCATE( ze3t(jpi,jpj,jpk), llmsk(jpi,jpj,jpk) )
+         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+            ze3t(ji,jj,jk) = tilde_e3t_a(ji,jj,jk) / e3t_0(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+         END_3D
+         !
+         llmsk(   1:Nis1,:,:) = .FALSE.   ! exclude halos from the checked region
+         llmsk(Nie1: jpi,:,:) = .FALSE.
+         llmsk(:,   1:Njs1,:) = .FALSE.
+         llmsk(:,Nje1: jpj,:) = .FALSE.
+         !
+         llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp                  ! define only the inner domain
+         z_tmax = MAXVAL( ze3t(:,:,:), mask = llmsk )   ;   CALL mpp_max( 'domvvl', z_tmax )   ! max over the global domain
+         z_tmin = MINVAL( ze3t(:,:,:), mask = llmsk )   ;   CALL mpp_min( 'domvvl', z_tmin )   ! min over the global domain
          ! - ML - test: for the moment, stop simulation for too large e3_t variations
          IF( ( z_tmax >  rn_zdef_max ) .OR. ( z_tmin < - rn_zdef_max ) ) THEN
-            IF( lk_mpp ) THEN
-               CALL mpp_maxloc( 'domvvl', ze3t, tmask, z_tmax, ijk_max )
-               CALL mpp_minloc( 'domvvl', ze3t, tmask, z_tmin, ijk_min )
-            ELSE
-               ijk_max = MAXLOC( ze3t(:,:,:) )
-               ijk_max(1) = mig0_oldcmp(ijk_max(1))
-               ijk_max(2) = mjg0_oldcmp(ijk_max(2))
-               ijk_min = MINLOC( ze3t(:,:,:) )
-               ijk_min(1) = mig0_oldcmp(ijk_min(1))
-               ijk_min(2) = mjg0_oldcmp(ijk_min(2))
-            ENDIF
+            CALL mpp_maxloc( 'domvvl', ze3t, llmsk, z_tmax, ijk_max )
+            CALL mpp_minloc( 'domvvl', ze3t, llmsk, z_tmin, ijk_min )
             IF (lwp) THEN
                WRITE(numout, *) 'MAX( tilde_e3t_a(:,:,:) / e3t_0(:,:,:) ) =', z_tmax
@@ -464,4 +473,5 @@
             ENDIF
          ENDIF
+         DEALLOCATE( ze3t, llmsk )
          ! - ML - end test
          ! - ML - Imposing these limits will cause a baroclinicity error which is corrected for below
@@ -1030,4 +1040,6 @@
    END SUBROUTINE dom_vvl_ctl
 
+#endif
+
    !!======================================================================
 END MODULE domvvl
