Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/NST_SRC/agrif_user.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 9012)
@@ -28,6 +28,6 @@
       jpiglo  = nbcellsx + 2 + 2*nbghostcells
       jpjglo  = nbcellsy + 2 + 2*nbghostcells
-      jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
-      jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
+      jpi     = ( jpiglo-2*nn_hls + (jpni-1+0) ) / jpni + 2*nn_hls
+      jpj     = ( jpjglo-2*nn_hls + (jpnj-1+0) ) / jpnj + 2*nn_hls
 ! JC: change to allow for different vertical levels
 !     jpk is already set
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90	(revision 9012)
@@ -149,7 +149,9 @@
       !! ** Purpose :   initialization of the nemo model in off-line mode
       !!----------------------------------------------------------------------
-      INTEGER ::   ji            ! dummy loop indices
-      INTEGER ::   ilocal_comm   ! local integer
-      INTEGER ::   ios, inum
+      INTEGER  ::   ji                 ! dummy loop indices
+      INTEGER  ::   ilocal_comm        ! local integer
+      INTEGER  ::   ios, inum          ! local integers
+      INTEGER  ::   iiarea, ijarea     ! local integers
+      INTEGER  ::   iirest, ijrest     ! local integers
       REAL(wp) ::   ziglo, zjglo, zkglo, zperio   ! local scalars
       CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
@@ -197,5 +199,4 @@
          CALL usr_def_nam( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
       ENDIF
-      jpk    = jpkglo
       !
       !
@@ -245,12 +246,29 @@
       END IF
 
-      ! Calculate domain dimensions given calculated jpni and jpnj
-      ! This used to be done in par_oce.F90 when they were parameters rather
-      ! than variables
-      jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
-      jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
+      iiarea = 1 + MOD( narea - 1 , jpni )
+      ijarea = 1 + ( narea - 1 ) / jpni
+      iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni )
+      ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj )
+#if defined key_nemocice_decomp
+      jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+      jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim. 
+      jpimax  = jpi
+      jpjmax  = jpj
+      IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls)
+      IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls)
+#else
+      jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+      jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.
+      jpimax  = jpi
+      jpjmax  = jpj
+      IF( iiarea > iirest ) jpi = jpi - 1
+      IF( ijarea > ijrest ) jpj = jpj - 1
+#endif
+
+      jpk   = jpkglo                                           ! third dim
+
       jpim1 = jpi-1                                            ! inner domain indices
       jpjm1 = jpj-1                                            !   "           "
-      jpkm1 = jpk-1                                            !   "           "
+      jpkm1 = MAX( 1, jpk-1 )                                  !   "           "
       jpij  = jpi*jpj                                          !  jpi x j
 
@@ -285,7 +303,5 @@
 
       !                                      ! Domain decomposition
-      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
-      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
-      ENDIF
+      CALL mpp_init
       !
       IF( ln_timing    )   CALL timing_init
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsdom.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsdom.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsdom.F90	(revision 9012)
@@ -1895,6 +1895,6 @@
       jpjglo_crsm1 = jpjglo_crs - 1  
 
-      jpi_crs = ( jpiglo_crs   - 2 * jpreci + (jpni-1) ) / jpni + 2 * jpreci
-      jpj_crs = ( jpjglo_crsm1 - 2 * jprecj + (jpnj-1) ) / jpnj + 2 * jprecj   
+      jpi_crs = ( jpiglo_crs   - 2 * nn_hls + (jpni-1) ) / jpni + 2 * nn_hls
+      jpj_crs = ( jpjglo_crsm1 - 2 * nn_hls + (jpnj-1) ) / jpnj + 2 * nn_hls   
               
       IF( noso < 0 ) jpj_crs = jpj_crs + 1    ! add a local band on southern processors  
@@ -1940,5 +1940,5 @@
               CASE ( -1 )
                 IF( MOD( jpjglo - njmppt(jn), nn_facty) > 0 )  nlejt_crs(jn) = nlejt_crs(jn) + 1
-                nlcjt_crs(jn) = nlejt_crs(jn) + jprecj
+                nlcjt_crs(jn) = nlejt_crs(jn) + nn_hls
                 nldjt_crs(jn) = nldjt(jn)
               
@@ -1947,10 +1947,10 @@
                 nldjt_crs(jn) = nldjt(jn)
                 IF( nldjt(jn) == 1 )  nlejt_crs(jn) = nlejt_crs(jn) + 1
-                nlejt_crs(jn) = nlejt_crs(jn) + jprecj
-                nlcjt_crs(jn) = nlejt_crs(jn) + jprecj
+                nlejt_crs(jn) = nlejt_crs(jn) + nn_hls
+                nlcjt_crs(jn) = nlejt_crs(jn) + nn_hls
                 
               CASE ( 1, 2 )
               
-                nlejt_crs(jn) = nlejt_crs(jn) + jprecj
+                nlejt_crs(jn) = nlejt_crs(jn) + nn_hls
                 nlcjt_crs(jn) = nlejt_crs(jn)
                 nldjt_crs(jn) = nldjt(jn)
@@ -1990,16 +1990,16 @@
            SELECT CASE( ibonit(jn) )
               CASE ( -1 )
-                 nleit_crs(jn) = nleit_crs(jn) + jpreci           
-                 nlcit_crs(jn) = nleit_crs(jn) + jpreci
+                 nleit_crs(jn) = nleit_crs(jn) + nn_hls           
+                 nlcit_crs(jn) = nleit_crs(jn) + nn_hls
                  nldit_crs(jn) = nldit(jn) 
               
               CASE ( 0 )
-                 nleit_crs(jn) = nleit_crs(jn) + jpreci
-                 nlcit_crs(jn) = nleit_crs(jn) + jpreci
+                 nleit_crs(jn) = nleit_crs(jn) + nn_hls
+                 nlcit_crs(jn) = nleit_crs(jn) + nn_hls
                  nldit_crs(jn) = nldit(jn) 
                 
               CASE ( 1, 2 )
                  IF( MOD( jpiglo - nimppt(jn), nn_factx) > 0 )  nleit_crs(jn) = nleit_crs(jn) + 1
-                 nleit_crs(jn) = nleit_crs(jn) + jpreci
+                 nleit_crs(jn) = nleit_crs(jn) + nn_hls
                  nlcit_crs(jn) = nleit_crs(jn)
                  nldit_crs(jn) = nldit(jn) 
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsdomwri.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsdomwri.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsdomwri.F90	(revision 9012)
@@ -133,8 +133,8 @@
       
       tmask_i_crs(:,:) = tmask_crs(:,:,1)
-      iif = jpreci
-      iil = nlci_crs - jpreci + 1
-      ijf = jpreci
-      ijl = nlcj_crs - jprecj + 1
+      iif = nn_hls
+      iil = nlci_crs - nn_hls + 1
+      ijf = nn_hls
+      ijl = nlcj_crs - nn_hls + 1
      
       tmask_i_crs( 1:iif ,    :  ) = 0._wp
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 9012)
@@ -90,8 +90,4 @@
    INTEGER, PUBLIC ::   noea, nowe        !: index of the local neighboring processors in
    INTEGER, PUBLIC ::   noso, nono        !: east, west, south and north directions
-   INTEGER, PUBLIC ::   npne, npnw        !: index of north east and north west processor
-   INTEGER, PUBLIC ::   npse, npsw        !: index of south east and south west processor
-   INTEGER, PUBLIC ::   nbne, nbnw        !: logical of north east & north west processor
-   INTEGER, PUBLIC ::   nbse, nbsw        !: logical of south east & south west processor
    INTEGER, PUBLIC ::   nidom             !: ???
 
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 9012)
@@ -96,6 +96,6 @@
          WRITE(numout,cform) '       ' ,'   jpij    : ', jpij
          WRITE(numout,*)     '      mpp local domain info (mpp):'
-         WRITE(numout,*)     '              jpni    : ', jpni, '   jpreci  : ', jpreci
-         WRITE(numout,*)     '              jpnj    : ', jpnj, '   jprecj  : ', jprecj
+         WRITE(numout,*)     '              jpni    : ', jpni, '   nn_hls  : ', nn_hls
+         WRITE(numout,*)     '              jpnj    : ', jpnj, '   nn_hls  : ', nn_hls
          WRITE(numout,*)     '              jpnij   : ', jpnij
          WRITE(numout,*)     '      lateral boundary of the Global domain : jperio  = ', jperio
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 9012)
@@ -211,6 +211,6 @@
       ! --------------------
       !
-      iif = jpreci   ;   iil = nlci - jpreci + 1
-      ijf = jprecj   ;   ijl = nlcj - jprecj + 1
+      iif = nn_hls   ;   iil = nlci - nn_hls + 1
+      ijf = nn_hls   ;   ijl = nlcj - nn_hls + 1
       !
       !                          ! halo mask : 0 on the halo and 1 elsewhere
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/IOM/prtctl.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/IOM/prtctl.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/IOM/prtctl.F90	(revision 9012)
@@ -441,14 +441,14 @@
 
 #if defined key_nemocice_decomp
-      ijpi = ( nx_global+2-2*jpreci + (isplt-1) ) / isplt + 2*jpreci
-      ijpj = ( ny_global+2-2*jprecj + (jsplt-1) ) / jsplt + 2*jprecj 
+      ijpi = ( nx_global+2-2*nn_hls + (isplt-1) ) / isplt + 2*nn_hls
+      ijpj = ( ny_global+2-2*nn_hls + (jsplt-1) ) / jsplt + 2*nn_hls 
 #else
-      ijpi = ( jpiglo-2*jpreci + (isplt-1) ) / isplt + 2*jpreci
-      ijpj = ( jpjglo-2*jprecj + (jsplt-1) ) / jsplt + 2*jprecj
+      ijpi = ( jpiglo-2*nn_hls + (isplt-1) ) / isplt + 2*nn_hls
+      ijpj = ( jpjglo-2*nn_hls + (jsplt-1) ) / jsplt + 2*nn_hls
 #endif
 
 
-      nrecil  = 2 * jpreci
-      nrecjl  = 2 * jprecj
+      nrecil  = 2 * nn_hls
+      nrecjl  = 2 * nn_hls
       irestil = MOD( jpiglo - nrecil , isplt )
       irestjl = MOD( jpjglo - nrecjl , jsplt )
@@ -563,10 +563,10 @@
          ibonitl(jn) = nbondil
          
-         nldil =  1   + jpreci
-         nleil = nlcil - jpreci
+         nldil =  1   + nn_hls
+         nleil = nlcil - nn_hls
          IF( nbondil == -1 .OR. nbondil == 2 )   nldil = 1
          IF( nbondil ==  1 .OR. nbondil == 2 )   nleil = nlcil
-         nldjl =  1   + jprecj
-         nlejl = nlcjl - jprecj
+         nldjl =  1   + nn_hls
+         nlejl = nlcjl - nn_hls
          IF( nbondjl == -1 .OR. nbondjl == 2 )   nldjl = 1
          IF( nbondjl ==  1 .OR. nbondjl == 2 )   nlejl = nlcjl
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_lnk_generic.h90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_lnk_generic.h90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_lnk_generic.h90	(revision 9012)
@@ -3,4 +3,5 @@
 #   define SGN_IN(k)                psgn(k)
 #   define F_SIZE(ptab)             kfld
+#   define OPT_K(k)                 ,ipf
 #   if defined DIM_2d
 #      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_2D)                , INTENT(inout) ::   ptab(f)
@@ -26,4 +27,5 @@
 #   define SGN_IN(k)                psgn
 #   define F_SIZE(ptab)             1
+#   define OPT_K(k)                 
 #   if defined DIM_2d
 #      define ARRAY_IN(i,j,k,l,f)   ptab(i,j)
@@ -100,5 +102,5 @@
             ELSEIF( ll_nfd ) THEN                  !* north fold
                IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:, 1 ,:,:,jf) = zland    ! south except F-point
-               CALL lbc_nfd( ptab, NAT_IN(:), SGN_IN(:)  )                       ! north fold treatment         
+               CALL lbc_nfd( ptab, NAT_IN(:), SGN_IN(:) OPT_K(:) )                       ! north fold treatment         
             ELSE                                   !* closed
                IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:, 1 ,:,:,jf) = zland    ! south except F-point
@@ -119,2 +121,3 @@
 #undef L_SIZE
 #undef F_SIZE
+#undef OPT_K
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_ext_generic.h90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_ext_generic.h90	(revision 9012)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_ext_generic.h90	(revision 9012)
@@ -0,0 +1,154 @@
+!                          !==  IN: ptab is an array  ==!
+#define NAT_IN(k)                cd_nat
+#define SGN_IN(k)                psgn
+#define F_SIZE(ptab)             1
+#if defined DIM_2d
+#   define ARRAY_IN(i,j,k,l,f)   ptab(i,j)
+#   define K_SIZE(ptab)          1
+#   define L_SIZE(ptab)          1
+#endif
+#define ARRAY_TYPE(i,j,k,l,f)    REAL(wp),INTENT(inout)::ARRAY_IN(i,j,k,l,f)
+
+   SUBROUTINE ROUTINE_NFD( ptab, cd_nat, psgn, kextj )
+      ARRAY_TYPE(:,:,:,:,:)                             ! array or pointer of arrays on which the boundary condition is applied
+      CHARACTER(len=1) , INTENT(in   ) ::   NAT_IN(:)   ! nature of array grid-points
+      REAL(wp)         , INTENT(in   ) ::   SGN_IN(:)   ! sign used across the north fold boundary
+      INTEGER          , INTENT(in   ) ::   kextj       ! extra halo width at north fold
+      !
+      INTEGER  ::    ji,  jj,  jk,  jl, jh,  jf   ! dummy loop indices
+      INTEGER  ::   ipi, ipj, ipk, ipl,     ipf   ! dimension of the input array
+      INTEGER  ::   ijt, iju, ipjm1
+      !!----------------------------------------------------------------------
+      !
+      ipk = K_SIZE(ptab)   ! 3rd dimension
+      ipl = L_SIZE(ptab)   ! 4th    -
+      ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
+      !
+      !
+      SELECT CASE ( jpni )
+      CASE ( 1 )     ;   ipj = nlcj       ! 1 proc only  along the i-direction
+      CASE DEFAULT   ;   ipj = 4          ! several proc along the i-direction
+      END SELECT
+      !
+      ipjm1 = ipj-1
+
+      !
+      DO jf = 1, ipf                      ! Loop on the number of arrays to be treated
+         !
+         SELECT CASE ( npolj )
+         !
+         CASE ( 3 , 4 )                        ! *  North fold  T-point pivot
+            !
+            SELECT CASE ( NAT_IN(jf)  )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO jh = 0, kextj
+                  DO ji = 2, jpiglo
+                     ijt = jpiglo-ji+2
+                     ARRAY_IN(ji,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-2-jh,:,:,jf)
+                  END DO
+                  ARRAY_IN(1,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(3,ipj-2-jh,:,:,jf)
+               END DO
+               DO ji = jpiglo/2+1, jpiglo
+                  ijt = jpiglo-ji+2
+                  ARRAY_IN(ji,ipjm1,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipjm1,:,:,jf)
+               END DO
+            CASE ( 'U' )                               ! U-point
+               DO jh = 0, kextj
+                  DO ji = 1, jpiglo-1
+                     iju = jpiglo-ji+1
+                     ARRAY_IN(ji,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-2-jh,:,:,jf)
+                  END DO
+                 ARRAY_IN(   1  ,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(    2   ,ipj-2-jh,:,:,jf)
+                 ARRAY_IN(jpiglo,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(jpiglo-1,ipj-2-jh,:,:,jf) 
+               END DO
+               DO ji = jpiglo/2, jpiglo-1
+                  iju = jpiglo-ji+1
+                  ARRAY_IN(ji,ipjm1,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipjm1,:,:,jf)
+               END DO
+            CASE ( 'V' )                               ! V-point
+               DO jh = 0, kextj
+                  DO ji = 2, jpiglo
+                     ijt = jpiglo-ji+2
+                     ARRAY_IN(ji,ipj-1+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-2-jh,:,:,jf)
+                     ARRAY_IN(ji,ipj+jh  ,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-3-jh,:,:,jf)
+                  END DO
+                  ARRAY_IN(1,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(3,ipj-3-jh,:,:,jf) 
+               END DO
+            CASE ( 'F' )                               ! F-point
+               DO jh = 0, kextj
+                  DO ji = 1, jpiglo-1
+                     iju = jpiglo-ji+1
+                     ARRAY_IN(ji,ipj-1+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-2-jh,:,:,jf)
+                     ARRAY_IN(ji,ipj+jh  ,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-3-jh,:,:,jf)
+                  END DO
+                  ARRAY_IN(   1  ,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(    2   ,ipj-3-jh,:,:,jf)
+                  ARRAY_IN(jpiglo,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(jpiglo-1,ipj-3-jh,:,:,jf) 
+               END DO
+            END SELECT
+            !
+         CASE ( 5 , 6 )                        ! *  North fold  F-point pivot
+            !
+            SELECT CASE ( NAT_IN(jf)  )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO jh = 0, kextj
+                  DO ji = 1, jpiglo
+                     ijt = jpiglo-ji+1
+                     ARRAY_IN(ji,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-1-jh,:,:,jf)
+                  END DO
+               END DO
+            CASE ( 'U' )                               ! U-point
+               DO jh = 0, kextj
+                  DO ji = 1, jpiglo-1
+                     iju = jpiglo-ji
+                     ARRAY_IN(ji,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-1-jh,:,:,jf)
+                  END DO
+                  ARRAY_IN(jpiglo,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(1,ipj-1-jh,:,:,jf)
+               END DO
+            CASE ( 'V' )                               ! V-point
+               DO jh = 0, kextj
+                  DO ji = 1, jpiglo
+                     ijt = jpiglo-ji+1
+                     ARRAY_IN(ji,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-2-jh,:,:,jf)
+                  END DO
+               END DO
+               DO ji = jpiglo/2+1, jpiglo
+                  ijt = jpiglo-ji+1
+                  ARRAY_IN(ji,ipjm1,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipjm1,:,:,jf)
+               END DO
+            CASE ( 'F' )                               ! F-point
+               DO jh = 0, kextj
+                  DO ji = 1, jpiglo-1
+                     iju = jpiglo-ji
+                     ARRAY_IN(ji,ipj+jh  ,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-2-jh,:,:,jf)
+                  END DO
+                  ARRAY_IN(jpiglo,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(1,ipj-2-jh,:,:,jf)
+               END DO
+               DO ji = jpiglo/2+1, jpiglo-1
+                  iju = jpiglo-ji
+                  ARRAY_IN(ji,ipjm1,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipjm1,:,:,jf)
+               END DO
+            END SELECT
+            !
+         CASE DEFAULT                           ! *  closed : the code probably never go through
+            !
+            SELECT CASE ( NAT_IN(jf) )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               ARRAY_IN(:,  1:1-kextj  ,:,:,jf) = 0._wp
+               ARRAY_IN(:,ipj:ipj+kextj,:,:,jf) = 0._wp
+            CASE ( 'F' )                               ! F-point
+               ARRAY_IN(:,ipj:ipj+kextj,:,:,jf) = 0._wp
+            END SELECT
+            !
+         END SELECT     !  npolj
+         !
+      END DO
+      !
+   END SUBROUTINE ROUTINE_NFD
+
+#undef ARRAY_TYPE
+#undef ARRAY_IN
+#undef NAT_IN
+#undef SGN_IN
+#undef K_SIZE
+#undef L_SIZE
+#undef F_SIZE
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_generic.h90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_generic.h90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_generic.h90	(revision 9012)
@@ -44,9 +44,13 @@
 #endif
 
+#if defined MULTI
    SUBROUTINE ROUTINE_NFD( ptab, cd_nat, psgn, kfld )
+      INTEGER          , INTENT(in   ) ::   kfld        ! number of pt3d arrays
+#else
+   SUBROUTINE ROUTINE_NFD( ptab, cd_nat, psgn       )
+#endif
       ARRAY_TYPE(:,:,:,:,:)                             ! array or pointer of arrays on which the boundary condition is applied
       CHARACTER(len=1) , INTENT(in   ) ::   NAT_IN(:)   ! nature of array grid-points
       REAL(wp)         , INTENT(in   ) ::   SGN_IN(:)   ! sign used across the north fold boundary
-      INTEGER, OPTIONAL, INTENT(in   ) ::   kfld        ! number of pt3d arrays
       !
       INTEGER  ::    ji,  jj,  jk,  jl, jh,  jf   ! dummy loop indices
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90	(revision 9012)
@@ -21,5 +21,4 @@
    !!----------------------------------------------------------------------
    !!   lbc_lnk       : generic interface for mpp_lnk_3d and mpp_lnk_2d routines defined in lib_mpp
-   !!   lbc_lnk_e     : generic interface for mpp_lnk_2d_e routine defined in lib_mpp
    !!   lbc_bdy_lnk   : generic interface for mpp_lnk_bdy_2d and mpp_lnk_bdy_3d routines defined in lib_mpp
    !!----------------------------------------------------------------------
@@ -42,8 +41,4 @@
    END INTERFACE
    !
-   INTERFACE lbc_lnk_e
-      MODULE PROCEDURE mpp_lnk_2d_e
-   END INTERFACE
-   !
    INTERFACE lbc_lnk_icb
       MODULE PROCEDURE mpp_lnk_2d_icb
@@ -52,5 +47,4 @@
    PUBLIC   lbc_lnk       ! ocean/ice lateral boundary conditions
    PUBLIC   lbc_lnk_multi ! modified ocean/ice lateral boundary conditions
-   PUBLIC   lbc_lnk_e     ! extended ocean/ice lateral boundary conditions
    PUBLIC   lbc_bdy_lnk   ! ocean lateral BDY boundary conditions
    PUBLIC   lbc_lnk_icb   ! iceberg lateral boundary conditions
@@ -95,8 +89,4 @@
    END INTERFACE
    !
-   INTERFACE lbc_lnk_e
-      MODULE PROCEDURE lbc_lnk_2d_e
-   END INTERFACE
-   !
    INTERFACE lbc_bdy_lnk
       MODULE PROCEDURE lbc_bdy_lnk_2d, lbc_bdy_lnk_3d
@@ -104,9 +94,8 @@
    !
    INTERFACE lbc_lnk_icb
-      MODULE PROCEDURE lbc_lnk_2d_e
+      MODULE PROCEDURE lbc_lnk_2d_icb
    END INTERFACE
    
    PUBLIC   lbc_lnk       ! ocean/ice  lateral boundary conditions
-   PUBLIC   lbc_lnk_e     ! extended ocean/ice lateral boundary conditions
    PUBLIC   lbc_lnk_multi ! modified ocean/ice lateral boundary conditions
    PUBLIC   lbc_bdy_lnk   ! ocean lateral BDY boundary conditions
@@ -270,7 +259,7 @@
 
 
-!!gm  This routine should be remove with an optional halos size added in orgument of generic routines
-
-   SUBROUTINE lbc_lnk_2d_e( pt2d, cd_type, psgn, ki, kj )
+!!gm  This routine should be removed with an optional halos size added in argument of generic routines
+
+   SUBROUTINE lbc_lnk_2d_icb( pt2d, cd_type, psgn, ki, kj )
       !!----------------------------------------------------------------------
       REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2d      ! 2D array on which the lbc is applied
@@ -280,5 +269,5 @@
       !!----------------------------------------------------------------------
       CALL lbc_lnk_2d( pt2d, cd_type, psgn )
-   END SUBROUTINE lbc_lnk_2d_e
+   END SUBROUTINE lbc_lnk_2d_icb
 !!gm end
 
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbcnfd.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbcnfd.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbcnfd.F90	(revision 9012)
@@ -27,4 +27,5 @@
       MODULE PROCEDURE   lbc_nfd_2d    , lbc_nfd_3d    , lbc_nfd_4d
       MODULE PROCEDURE   lbc_nfd_2d_ptr, lbc_nfd_3d_ptr, lbc_nfd_4d_ptr
+      MODULE PROCEDURE   lbc_nfd_2d_ext
    END INTERFACE
    !
@@ -84,4 +85,12 @@
 #     undef ROUTINE_NFD
 #     undef MULTI
+#  undef DIM_2d
+   !
+   !                       !==  2D array with extra haloes  ==!
+   !
+#  define DIM_2d
+#     define ROUTINE_NFD           lbc_nfd_2d_ext
+#     include "lbc_nfd_ext_generic.h90"
+#     undef ROUTINE_NFD
 #  undef DIM_2d
    !
@@ -156,172 +165,4 @@
 
 
-!!gm   CAUTION HERE  optional pr2dj  not implemented in generic case
-!!gm                 furthermore, in the _org routine it is OK only for T-point pivot !!
-
-
-   SUBROUTINE lbc_nfd_2d_org( pt2d, cd_nat, psgn, pr2dj )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine lbc_nfd_2d  ***
-      !!
-      !! ** Purpose :   2D lateral boundary condition : North fold treatment
-      !!       without processor exchanges. 
-      !!
-      !! ** Method  :   
-      !!
-      !! ** Action  :   pt2d with updated values along the north fold
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2d      ! 2D array on which the boundary condition is applied
-      CHARACTER(len=1)        , INTENT(in   ) ::   cd_nat   ! nature of pt2d grid-point
-      REAL(wp)                , INTENT(in   ) ::   psgn      ! sign used across north fold
-      INTEGER , OPTIONAL      , INTENT(in   ) ::   pr2dj     ! number of additional halos
-      !
-      INTEGER  ::   ji, jl, ipr2dj
-      INTEGER  ::   ijt, iju, ijpj, ijpjm1
-      !!----------------------------------------------------------------------
-
-      SELECT CASE ( jpni )
-      CASE ( 1 )     ;   ijpj = nlcj      ! 1 proc only  along the i-direction
-      CASE DEFAULT   ;   ijpj = 4         ! several proc along the i-direction
-      END SELECT
-      !
-      IF( PRESENT(pr2dj) ) THEN           ! use of additional halos
-         ipr2dj = pr2dj
-         IF( jpni > 1 )   ijpj = ijpj + ipr2dj
-      ELSE
-         ipr2dj = 0 
-      ENDIF
-      !
-      ijpjm1 = ijpj-1
-
-
-      SELECT CASE ( npolj )
-      !
-      CASE ( 3, 4 )                       ! *  North fold  T-point pivot
-         !
-         SELECT CASE ( cd_nat )
-         !
-         CASE ( 'T' , 'W' )                               ! T- , W-points
-            DO jl = 0, ipr2dj
-               DO ji = 2, jpiglo
-                  ijt=jpiglo-ji+2
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(ijt,ijpj-2-jl)
-               END DO
-            END DO
-            pt2d(1,ijpj)   = psgn * pt2d(3,ijpj-2)
-            DO ji = jpiglo/2+1, jpiglo
-               ijt=jpiglo-ji+2
-               pt2d(ji,ijpj-1) = psgn * pt2d(ijt,ijpj-1)
-            END DO
-         CASE ( 'U' )                                     ! U-point
-            DO jl = 0, ipr2dj
-               DO ji = 1, jpiglo-1
-                  iju = jpiglo-ji+1
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(iju,ijpj-2-jl)
-               END DO
-            END DO
-            pt2d(   1  ,ijpj  ) = psgn * pt2d(    2   ,ijpj-2)
-            pt2d(jpiglo,ijpj  ) = psgn * pt2d(jpiglo-1,ijpj-2)
-            pt2d(1     ,ijpj-1) = psgn * pt2d(jpiglo  ,ijpj-1)   
-            DO ji = jpiglo/2, jpiglo-1
-               iju = jpiglo-ji+1
-               pt2d(ji,ijpjm1) = psgn * pt2d(iju,ijpjm1)
-            END DO
-         CASE ( 'V' )                                     ! V-point
-            DO jl = -1, ipr2dj
-               DO ji = 2, jpiglo
-                  ijt = jpiglo-ji+2
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(ijt,ijpj-3-jl)
-               END DO
-            END DO
-            pt2d( 1 ,ijpj)   = psgn * pt2d( 3 ,ijpj-3) 
-         CASE ( 'F' )                                     ! F-point
-            DO jl = -1, ipr2dj
-               DO ji = 1, jpiglo-1
-                  iju = jpiglo-ji+1
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(iju,ijpj-3-jl)
-               END DO
-            END DO
-            pt2d(   1  ,ijpj)   = psgn * pt2d(    2   ,ijpj-3)
-            pt2d(jpiglo,ijpj)   = psgn * pt2d(jpiglo-1,ijpj-3)
-            pt2d(jpiglo,ijpj-1) = psgn * pt2d(jpiglo-1,ijpj-2)      
-            pt2d(   1  ,ijpj-1) = psgn * pt2d(    2   ,ijpj-2)      
-         CASE ( 'I' )                                     ! ice U-V point (I-point)
-            DO jl = 0, ipr2dj
-               pt2d(2,ijpj+jl) = psgn * pt2d(3,ijpj-1+jl)
-               DO ji = 3, jpiglo
-                  iju = jpiglo - ji + 3
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(iju,ijpj-1-jl)
-               END DO
-            END DO
-         END SELECT
-         !
-      CASE ( 5, 6 )                        ! *  North fold  F-point pivot
-         !
-         SELECT CASE ( cd_nat )
-         CASE ( 'T' , 'W' )                               ! T-, W-point
-            DO jl = 0, ipr2dj
-               DO ji = 1, jpiglo
-                  ijt = jpiglo-ji+1
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(ijt,ijpj-1-jl)
-               END DO
-            END DO
-         CASE ( 'U' )                                     ! U-point
-            DO jl = 0, ipr2dj
-               DO ji = 1, jpiglo-1
-                  iju = jpiglo-ji
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(iju,ijpj-1-jl)
-               END DO
-            END DO
-            pt2d(jpiglo,ijpj) = psgn * pt2d(1,ijpj-1)
-         CASE ( 'V' )                                     ! V-point
-            DO jl = 0, ipr2dj
-               DO ji = 1, jpiglo
-                  ijt = jpiglo-ji+1
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(ijt,ijpj-2-jl)
-               END DO
-            END DO
-            DO ji = jpiglo/2+1, jpiglo
-               ijt = jpiglo-ji+1
-               pt2d(ji,ijpjm1) = psgn * pt2d(ijt,ijpjm1)
-            END DO
-         CASE ( 'F' )                               ! F-point
-            DO jl = 0, ipr2dj
-               DO ji = 1, jpiglo-1
-                  iju = jpiglo-ji
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(iju,ijpj-2-jl)
-               END DO
-            END DO
-            pt2d(jpiglo,ijpj) = psgn * pt2d(1,ijpj-2)
-            DO ji = jpiglo/2+1, jpiglo-1
-               iju = jpiglo-ji
-               pt2d(ji,ijpjm1) = psgn * pt2d(iju,ijpjm1)
-            END DO
-         CASE ( 'I' )                                  ! ice U-V point (I-point)
-            pt2d( 2 ,ijpj:ijpj+ipr2dj) = 0._wp
-            DO jl = 0, ipr2dj
-               DO ji = 2 , jpiglo-1
-                  ijt = jpiglo - ji + 2
-                  pt2d(ji,ijpj+jl)= 0.5 * ( pt2d(ji,ijpj-1-jl) + psgn * pt2d(ijt,ijpj-1-jl) )
-               END DO
-            END DO
-         END SELECT
-         !
-      CASE DEFAULT                           ! *  closed : the code probably never go through
-         !
-         SELECT CASE ( cd_nat)
-         CASE ( 'T' , 'U' , 'V' , 'W' )                 ! T-, U-, V-, W-points
-            pt2d(:, 1:1-ipr2dj     ) = 0._wp
-            pt2d(:,ijpj:ijpj+ipr2dj) = 0._wp
-         CASE ( 'F' )                                   ! F-point
-            pt2d(:,ijpj:ijpj+ipr2dj) = 0._wp
-         CASE ( 'I' )                                   ! ice U-V point
-            pt2d(:, 1:1-ipr2dj     ) = 0._wp
-            pt2d(:,ijpj:ijpj+ipr2dj) = 0._wp
-         END SELECT
-         !
-      END SELECT
-      !
-   END SUBROUTINE lbc_nfd_2d_org
-
    !!======================================================================
 END MODULE lbcnfd
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 9012)
@@ -41,5 +41,4 @@
    !!   mynode        : indentify the processor unit
    !!   mpp_lnk       : interface (defined in lbclnk) for message passing of 2d or 3d arrays (mpp_lnk_2d, mpp_lnk_3d)
-   !!   mpp_lnk_e     : interface (defined in lbclnk) for message passing of 2d array with extra halo (mpp_lnk_2d_e)
    !!   mpp_lnk_icb   : interface for message passing of 2d arrays with extra halo for icebergs (mpp_lnk_2d_icb)
    !!   mpprecv       :
@@ -55,7 +54,5 @@
    !!   mppstop       :
    !!   mpp_ini_north : initialisation of north fold
-!!gm   !!   mpp_lbc_north : north fold processors gathering
-   !!   mpp_lbc_north_e : variant of mpp_lbc_north for extra outer halo
-   !!   mpp_lbc_north_icb : variant of mpp_lbc_north for extra outer halo with icebergs
+   !!   mpp_lbc_north_icb : alternative to mpp_nfd for extra outer halo with icebergs
    !!----------------------------------------------------------------------
    USE dom_oce        ! ocean space and time domain
@@ -75,5 +72,4 @@
    PUBLIC   mpp_lnk_2d      , mpp_lnk_3d      , mpp_lnk_4d
    PUBLIC   mpp_lnk_2d_ptr, mpp_lnk_3d_ptr, mpp_lnk_4d_ptr
-   PUBLIC   mpp_lnk_2d_e
    !
 !!gm  this should be useless
@@ -84,11 +80,9 @@
    PUBLIC   ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam
    PUBLIC   mynode, mppstop, mppsync, mpp_comm_free
-   PUBLIC   mpp_ini_north, mpp_lbc_north_e
-!!gm   PUBLIC   mpp_ini_north, mpp_lbc_north, mpp_lbc_north_e
-   PUBLIC   mpp_lbc_north_icb, mpp_lnk_2d_icb
+   PUBLIC   mpp_ini_north
+   PUBLIC   mpp_lnk_2d_icb
+   PUBLIC   mpp_lbc_north_icb
    PUBLIC   mpp_min, mpp_max, mpp_sum, mpp_minloc, mpp_maxloc
    PUBLIC   mpp_max_multiple
-!!gm   PUBLIC   mpp_lnk_2d_9 
-!!gm   PUBLIC   mpp_lnk_sum_3d, mpp_lnk_sum_2d
    PUBLIC   mppscatter, mppgather
    PUBLIC   mpp_ini_ice, mpp_ini_znl
@@ -112,7 +106,4 @@
          &             mppsum_realdd, mppsum_a_realdd
    END INTERFACE
-!!gm   INTERFACE mpp_lbc_north
-!!gm      MODULE PROCEDURE mpp_lbc_north_3d, mpp_lbc_north_2d
-!!gm   END INTERFACE
    INTERFACE mpp_minloc
       MODULE PROCEDURE mpp_minloc2d ,mpp_minloc3d
@@ -145,5 +136,5 @@
 
    ! variables used in case of sea-ice
-   INTEGER, PUBLIC ::   ncomm_ice       !: communicator made by the processors with sea-ice (public so that it can be freed in icethd)
+   INTEGER, PUBLIC ::   ncomm_ice       !: communicator made by the processors with sea-ice (public so that it can be freed in limthd)
    INTEGER         ::   ngrp_iworld     !  group ID for the world processors (for rheology)
    INTEGER         ::   ngrp_ice        !  group ID for the ice processors (for rheology)
@@ -454,9 +445,4 @@
 #     include "mpp_bdy_generic.h90"
 #     undef ROUTINE_BDY
-#     define MULTI
-#     define ROUTINE_BDY           mpp_lnk_bdy_2d_ptr
-#     include "mpp_bdy_generic.h90"
-#     undef ROUTINE_BDY
-#     undef MULTI
 #  undef DIM_2d
    !
@@ -467,9 +453,4 @@
 #     include "mpp_bdy_generic.h90"
 #     undef ROUTINE_BDY
-#     define MULTI
-#     define ROUTINE_BDY           mpp_lnk_bdy_3d_ptr
-#     include "mpp_bdy_generic.h90"
-#     undef ROUTINE_BDY
-#     undef MULTI
 #  undef DIM_3d
    !
@@ -480,9 +461,4 @@
 !!#     include "mpp_bdy_generic.h90"
 !!#     undef ROUTINE_BDY
-!!#     define MULTI
-!!#     define ROUTINE_BDY           mpp_lnk_bdy_4d_ptr
-!!#     include "mpp_bdy_generic.h90"
-!!#     undef ROUTINE_BDY
-!!#     undef MULTI
 !!#  undef DIM_4d
 
@@ -492,7 +468,4 @@
    
    
-   !!    mpp_lnk_2d_e     utilisé dans ICB 
-
-
    !!    mpp_lnk_sum_2d et 3D   ====>>>>>>   à virer du code !!!!
    
@@ -500,187 +473,4 @@
    !!----------------------------------------------------------------------
 
-
-   SUBROUTINE mpp_lnk_2d_e( pt2d, cd_type, psgn, jpri, jprj )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_2d_e  ***
-      !!
-      !! ** Purpose :   Message passing manadgement for 2d array (with halo)
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    jpri   : number of rows for extra outer halo
-      !!                    jprj   : number of columns for extra outer halo
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER                                             , INTENT(in   ) ::   jpri
-      INTEGER                                             , INTENT(in   ) ::   jprj
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,1-jprj:jpj+jprj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
-      CHARACTER(len=1)                                    , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
-      !                                                                                 ! = T , U , V , F , W and I points
-      REAL(wp)                                            , INTENT(in   ) ::   psgn     ! =-1 the sign change across the
-      !!                                                                                ! north boundary, =  1. otherwise
-      INTEGER  ::   jl   ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ipreci, iprecj             ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !!
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dns
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dsn
-      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dwe
-      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dew
-      !!----------------------------------------------------------------------
-
-      ipreci = jpreci + jpri      ! take into account outer extra 2D overlap area
-      iprecj = jprecj + jprj
-
-
-      ! 1. standard boundary treatment   (CAUTION: the order matters Here !!!! )
-      ! ------------------------------
-      !                                !== North-South boundaries
-      !                                      !* cyclic
-      IF( nbondj == 2 .AND. jperio == 7 ) THEN
-         pt2d(:, 1-jprj:  1     ) = pt2d ( :, jpjm1-jprj:jpjm1 )
-         pt2d(:, jpj   :jpj+jprj) = pt2d ( :, 2         :2+jprj)
-      ELSE                                   !* closed
-         IF( .NOT. cd_type == 'F' )   pt2d(:,  1-jprj   :  jprecj  ) = 0._wp     ! south except at F-point
-                                      pt2d(:,nlcj-jprecj+1:jpj+jprj) = 0._wp     ! north
-      ENDIF
-      !                                !== East-West boundaries
-      !                                      !* Cyclic east-west
-      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-         pt2d(1-jpri:     1    ,:) = pt2d(jpim1-jpri:  jpim1 ,:)              ! east
-         pt2d(   jpi  :jpi+jpri,:) = pt2d(     2      :2+jpri,:)              ! west
-      ELSE                                   !* closed
-         IF( .NOT. cd_type == 'F' )   pt2d(  1-jpri   :jpreci    ,:) = 0._wp  ! south except at F-point
-                                      pt2d(nlci-jpreci+1:jpi+jpri,:) = 0._wp  ! north
-      ENDIF
-      !
-      ! north fold treatment
-      ! --------------------
-      IF( npolj /= 0 ) THEN
-         !
-         SELECT CASE ( jpni )
-!!gm ERROR        CASE ( 1 )     ;   CALL lbc_nfd        ( pt2d(1:jpi,1:jpj+jprj), cd_type, psgn, pr2dj=jprj )
-!!gm ERROR         CASE DEFAULT   ;   CALL mpp_lbc_north_e( pt2d                  , cd_type, psgn             )
-         END SELECT
-         !
-      ENDIF
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci-jpri
-         DO jl = 1, ipreci
-            r2dew(:,jl,1) = pt2d(jpreci+jl,:)
-            r2dwe(:,jl,1) = pt2d(iihom +jl,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = ipreci * ( jpj + 2*jprj)
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
-         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, ipreci
-            pt2d(iihom+jl,:) = r2dew(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, ipreci
-            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
-            pt2d( iihom+jl,:) = r2dew(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, ipreci
-            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
-         END DO
-      END SELECT
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj-jprj
-         DO jl = 1, iprecj
-            r2dsn(:,jl,1) = pt2d(:,ijhom +jl)
-            r2dns(:,jl,1) = pt2d(:,jprecj+jl)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = iprecj * ( jpi + 2*jpri )
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
-         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, iprecj
-            pt2d(:,ijhom+jl) = r2dns(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, iprecj
-            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
-            pt2d(:,ijhom+jl ) = r2dns(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, iprecj
-            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
-         END DO
-      END SELECT
-      !
-   END SUBROUTINE mpp_lnk_2d_e
 
 
@@ -1458,78 +1248,4 @@
 
 
-   SUBROUTINE mpp_lbc_north_e( pt2d, cd_type, psgn)
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_lbc_north_2d  ***
-      !!
-      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
-      !!              in mpp configuration in case of jpn1 > 1 and for 2d
-      !!              array with outer extra halo
-      !!
-      !! ** Method  :   North fold condition and mpp with more than one proc
-      !!              in i-direction require a specific treatment. We gather
-      !!              the 4+2*jpr2dj northern lines of the global domain on 1
-      !!              processor and apply lbc north-fold on this sub array.
-      !!              Then we scatter the north fold array back to the processors.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
-      CHARACTER(len=1)                                            , INTENT(in   ) ::   cd_type  ! nature of pt3d grid-points
-      REAL(wp)                                                    , INTENT(in   ) ::   psgn     ! sign used across the north fold
-      !
-      INTEGER ::   ji, jj, jr
-      INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ij, iproc
-      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE  ::  ztab_e, znorthloc_e
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE  ::  znorthgloio_e
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( ztab_e(jpiglo,4+2*jpr2dj), znorthloc_e(jpi,4+2*jpr2dj), znorthgloio_e(jpi,4+2*jpr2dj,jpni) )
-      !
-      ijpj=4
-      ztab_e(:,:) = 0._wp
-
-      ij = 0
-      ! put in znorthloc_e the last 4 jlines of pt2d
-      DO jj = nlcj - ijpj + 1 - jpr2dj, nlcj +jpr2dj
-         ij = ij + 1
-         DO ji = 1, jpi
-            znorthloc_e(ji,ij) = pt2d(ji,jj)
-         END DO
-      END DO
-      !
-      itaille = jpi * ( ijpj + 2 * jpr2dj )
-      CALL MPI_ALLGATHER( znorthloc_e(1,1)    , itaille, MPI_DOUBLE_PRECISION,    &
-         &                znorthgloio_e(1,1,1), itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
-      !
-      DO jr = 1, ndim_rank_north            ! recover the global north array
-         iproc = nrank_north(jr) + 1
-         ildi  = nldit (iproc)
-         ilei  = nleit (iproc)
-         iilb  = nimppt(iproc)
-         DO jj = 1, ijpj+2*jpr2dj
-            DO ji = ildi, ilei
-               ztab_e(ji+iilb-1,jj) = znorthgloio_e(ji,jj,jr)
-            END DO
-         END DO
-      END DO
-
-      ! 2. North-Fold boundary conditions
-      ! ----------------------------------
-!!gm ERROR      CALL lbc_nfd( ztab_e(:,:), cd_type, psgn, pr2dj = jpr2dj )
-
-      ij = jpr2dj
-      !! Scatter back to pt2d
-      DO jj = nlcj - ijpj + 1 , nlcj +jpr2dj
-      ij  = ij +1
-         DO ji= 1, nlci
-            pt2d(ji,jj) = ztab_e(ji+nimpp-1,ij)
-         END DO
-      END DO
-      !
-      DEALLOCATE( ztab_e, znorthloc_e, znorthgloio_e )
-      !
-   END SUBROUTINE mpp_lbc_north_e
-
-
    SUBROUTINE mpi_init_opa( ldtxt, ksft, code )
       !!---------------------------------------------------------------------
@@ -1623,5 +1339,5 @@
 
 
-   SUBROUTINE mpp_lbc_north_icb( pt2d, cd_type, psgn, pr2dj)
+   SUBROUTINE mpp_lbc_north_icb( pt2d, cd_type, psgn, kextj)
       !!---------------------------------------------------------------------
       !!                   ***  routine mpp_lbc_north_icb  ***
@@ -1633,8 +1349,9 @@
       !! ** Method  :   North fold condition and mpp with more than one proc
       !!              in i-direction require a specific treatment. We gather
-      !!              the 4+2*jpr2dj northern lines of the global domain on 1
+      !!              the 4+kextj northern lines of the global domain on 1
       !!              processor and apply lbc north-fold on this sub array.
       !!              Then we scatter the north fold array back to the processors.
-      !!              This version accounts for an extra halo with icebergs.
+      !!              This routine accounts for an extra halo with icebergs
+      !!              and assumes ghost rows and columns have been suppressed.
       !!
       !!----------------------------------------------------------------------
@@ -1644,9 +1361,9 @@
       REAL(wp)                , INTENT(in   ) ::   psgn     ! = -1. the sign change across the
       !!                                                    ! north fold, =  1. otherwise
-      INTEGER, OPTIONAL       , INTENT(in   ) ::   pr2dj
+      INTEGER                 , INTENT(in   ) ::   kextj    ! Extra halo width at north fold
       !
       INTEGER ::   ji, jj, jr
       INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ij, iproc, ipr2dj
+      INTEGER ::   ipj, ij, iproc
       !
       REAL(wp), DIMENSION(:,:)  , ALLOCATABLE  ::  ztab_e, znorthloc_e
@@ -1654,24 +1371,19 @@
       !!----------------------------------------------------------------------
       !
-      ijpj=4
-      IF( PRESENT(pr2dj) ) THEN           ! use of additional halos
-         ipr2dj = pr2dj
-      ELSE
-         ipr2dj = 0
-      ENDIF
-      ALLOCATE( ztab_e(jpiglo,4+2*ipr2dj), znorthloc_e(jpi,4+2*ipr2dj), znorthgloio_e(jpi,4+2*ipr2dj,jpni) )
-      !
-      ztab_e(:,:) = 0._wp
+      ipj=4
+      ALLOCATE( ztab_e(jpiglo,ipj+kextj), znorthloc_e(  jpimax,ipj+kextj), &
+     &                                    znorthgloio_e(jpimax,ipj+kextj,jpni) )
+      !
+      ztab_e(:,:)      = 0._wp
+      znorthloc_e(:,:) = 0._wp
       !
       ij = 0
-      ! put in znorthloc_e the last 4 jlines of pt2d
-      DO jj = nlcj - ijpj + 1 - ipr2dj, nlcj +ipr2dj
+      ! put the last ipj+kextj lines of pt2d into znorthloc_e 
+      DO jj = jpj - ipj + 1, jpj + kextj
          ij = ij + 1
-         DO ji = 1, jpi
-            znorthloc_e(ji,ij)=pt2d(ji,jj)
-         END DO
+         znorthloc_e(1:jpi,ij)=pt2d(1:jpi,jj)
       END DO
       !
-      itaille = jpi * ( ijpj + 2 * ipr2dj )
+      itaille = jpimax * ( ipj + kextj )
       CALL MPI_ALLGATHER( znorthloc_e(1,1)  , itaille, MPI_DOUBLE_PRECISION,    &
          &                znorthgloio_e(1,1,1), itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
@@ -1682,5 +1394,5 @@
          ilei = nleit (iproc)
          iilb = nimppt(iproc)
-         DO jj = 1, ijpj+2*ipr2dj
+         DO jj = 1, ipj+kextj
             DO ji = ildi, ilei
                ztab_e(ji+iilb-1,jj) = znorthgloio_e(ji,jj,jr)
@@ -1691,11 +1403,11 @@
       ! 2. North-Fold boundary conditions
       ! ----------------------------------
-!!gm ERROR      CALL lbc_nfd( ztab_e(:,:), cd_type, psgn, pr2dj = ipr2dj )
-
-      ij = ipr2dj
+      CALL lbc_nfd( ztab_e(:,:), cd_type, psgn, kextj )
+
+      ij = 0
       !! Scatter back to pt2d
-      DO jj = nlcj - ijpj + 1 , nlcj +ipr2dj
+      DO jj = jpj - ipj + 1 , jpj + kextj
       ij  = ij +1
-         DO ji= 1, nlci
+         DO ji= 1, jpi
             pt2d(ji,jj) = ztab_e(ji+nimpp-1,ij)
          END DO
@@ -1707,17 +1419,19 @@
 
 
-   SUBROUTINE mpp_lnk_2d_icb( pt2d, cd_type, psgn, jpri, jprj )
+   SUBROUTINE mpp_lnk_2d_icb( pt2d, cd_type, psgn, kexti, kextj )
       !!----------------------------------------------------------------------
       !!                  ***  routine mpp_lnk_2d_icb  ***
       !!
-      !! ** Purpose :   Message passing manadgement for 2d array (with extra halo and icebergs)
+      !! ** Purpose :   Message passing management for 2d array (with extra halo for icebergs)
+      !!                This routine receives a (1-kexti:jpi+kexti,1-kexti:jpj+kextj)
+      !!                array (usually (0:jpi+1, 0:jpj+1)) from lbc_lnk_icb calls.
       !!
       !! ** Method  :   Use mppsend and mpprecv function for passing mask
       !!      between processors following neighboring subdomains.
       !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    jpri   : number of rows for extra outer halo
-      !!                    jprj   : number of columns for extra outer halo
+      !!                    jpi    : first dimension of the local subdomain
+      !!                    jpj    : second dimension of the local subdomain
+      !!                    kexti  : number of columns for extra outer halo
+      !!                    kextj  : number of rows for extra outer halo
       !!                    nbondi : mark for "east-west local boundary"
       !!                    nbondj : mark for "north-south local boundary"
@@ -1727,9 +1441,9 @@
       !!                    nono   : number for local neighboring processors
       !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,1-jprj:jpj+jprj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
-      CHARACTER(len=1)                                    , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
-      REAL(wp)                                            , INTENT(in   ) ::   psgn     ! sign used across the north fold
-      INTEGER                                             , INTENT(in   ) ::   jpri
-      INTEGER                                             , INTENT(in   ) ::   jprj
+      REAL(wp), DIMENSION(1-kexti:jpi+kexti,1-kextj:jpj+kextj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
+      CHARACTER(len=1)                                        , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
+      REAL(wp)                                                , INTENT(in   ) ::   psgn     ! sign used across the north fold
+      INTEGER                                                 , INTENT(in   ) ::   kexti    ! extra i-halo width
+      INTEGER                                                 , INTENT(in   ) ::   kextj    ! extra j-halo width
       !
       INTEGER  ::   jl   ! dummy loop indices
@@ -1739,10 +1453,10 @@
       INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
       !!
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) ::   r2dns, r2dsn
-      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) ::   r2dwe, r2dew
-      !!----------------------------------------------------------------------
-
-      ipreci = jpreci + jpri      ! take into account outer extra 2D overlap area
-      iprecj = jprecj + jprj
+      REAL(wp), DIMENSION(1-kexti:jpi+kexti,nn_hls+kextj,2) ::   r2dns, r2dsn
+      REAL(wp), DIMENSION(1-kextj:jpj+kextj,nn_hls+kexti,2) ::   r2dwe, r2dew
+      !!----------------------------------------------------------------------
+
+      ipreci = nn_hls + kexti      ! take into account outer extra 2D overlap area
+      iprecj = nn_hls + kextj
 
 
@@ -1754,10 +1468,10 @@
       !                                           !* Cyclic east-west
       IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-         pt2d(1-jpri:     1    ,:) = pt2d(jpim1-jpri:  jpim1 ,:)       ! east
-         pt2d(   jpi  :jpi+jpri,:) = pt2d(     2      :2+jpri,:)       ! west
+         pt2d(1-kexti:     1    ,:) = pt2d(jpim1-kexti:  jpim1 ,:)       ! east
+         pt2d(   jpi  :jpi+kexti,:) = pt2d(     2      :2+kexti,:)       ! west
          !
       ELSE                                        !* closed
-         IF( .NOT. cd_type == 'F' )   pt2d(  1-jpri   :jpreci    ,:) = 0._wp    ! south except at F-point
-                                      pt2d(nlci-jpreci+1:jpi+jpri,:) = 0._wp    ! north
+         IF( .NOT. cd_type == 'F' )   pt2d(  1-kexti   :nn_hls    ,:) = 0._wp    ! south except at F-point
+                                      pt2d(jpi-nn_hls+1:jpi+kexti,:) = 0._wp    ! north
       ENDIF
       !
@@ -1768,6 +1482,6 @@
          !
          SELECT CASE ( jpni )
-!!gm ERROR         CASE ( 1 )     ;   CALL lbc_nfd        ( pt2d(1:jpi,1:jpj+jprj), cd_type, psgn, pr2dj=jprj )
-!!gm ERROR         CASE DEFAULT   ;   CALL mpp_lbc_north_icb( pt2d(1:jpi,1:jpj+jprj)  , cd_type, psgn , pr2dj=jprj  )
+                   CASE ( 1 )     ;   CALL lbc_nfd          ( pt2d(1:jpi,1:jpj+kextj), cd_type, psgn, kextj )
+                   CASE DEFAULT   ;   CALL mpp_lbc_north_icb( pt2d(1:jpi,1:jpj+kextj), cd_type, psgn, kextj )
          END SELECT
          !
@@ -1780,7 +1494,7 @@
       SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
       CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci-jpri
+         iihom = jpi-nreci-kexti
          DO jl = 1, ipreci
-            r2dew(:,jl,1) = pt2d(jpreci+jl,:)
+            r2dew(:,jl,1) = pt2d(nn_hls+jl,:)
             r2dwe(:,jl,1) = pt2d(iihom +jl,:)
          END DO
@@ -1788,26 +1502,26 @@
       !
       !                           ! Migrations
-      imigr = ipreci * ( jpj + 2*jprj)
+      imigr = ipreci * ( jpj + 2*kextj )
       !
       SELECT CASE ( nbondi )
       CASE ( -1 )
-         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
+         CALL mppsend( 2, r2dwe(1-kextj,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, r2dew(1-kextj,1,2), imigr, noea )
          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
       CASE ( 0 )
-         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
-         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
+         CALL mppsend( 1, r2dew(1-kextj,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, r2dwe(1-kextj,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, r2dew(1-kextj,1,2), imigr, noea )
+         CALL mpprecv( 2, r2dwe(1-kextj,1,2), imigr, nowe )
          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
          IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
       CASE ( 1 )
-         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
+         CALL mppsend( 1, r2dew(1-kextj,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, r2dwe(1-kextj,1,2), imigr, nowe )
          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
       END SELECT
       !
       !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
+      iihom = jpi - nn_hls
       !
       SELECT CASE ( nbondi )
@@ -1818,10 +1532,10 @@
       CASE ( 0 )
          DO jl = 1, ipreci
-            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
-            pt2d( iihom+jl,:) = r2dew(:,jl,2)
+            pt2d(jl-kexti,:) = r2dwe(:,jl,2)
+            pt2d(iihom+jl,:) = r2dew(:,jl,2)
          END DO
       CASE ( 1 )
          DO jl = 1, ipreci
-            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
+            pt2d(jl-kexti,:) = r2dwe(:,jl,2)
          END DO
       END SELECT
@@ -1833,34 +1547,34 @@
       !
       IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj-jprj
+         ijhom = jpj-nrecj-kextj
          DO jl = 1, iprecj
             r2dsn(:,jl,1) = pt2d(:,ijhom +jl)
-            r2dns(:,jl,1) = pt2d(:,jprecj+jl)
+            r2dns(:,jl,1) = pt2d(:,nn_hls+jl)
          END DO
       ENDIF
       !
       !                           ! Migrations
-      imigr = iprecj * ( jpi + 2*jpri )
+      imigr = iprecj * ( jpi + 2*kexti )
       !
       SELECT CASE ( nbondj )
       CASE ( -1 )
-         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
+         CALL mppsend( 4, r2dsn(1-kexti,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, r2dns(1-kexti,1,2), imigr, nono )
          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
       CASE ( 0 )
-         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
-         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
+         CALL mppsend( 3, r2dns(1-kexti,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, r2dsn(1-kexti,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, r2dns(1-kexti,1,2), imigr, nono )
+         CALL mpprecv( 4, r2dsn(1-kexti,1,2), imigr, noso )
          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
          IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
       CASE ( 1 )
-         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
+         CALL mppsend( 3, r2dns(1-kexti,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, r2dsn(1-kexti,1,2), imigr, noso )
          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
       END SELECT
       !
       !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj
+      ijhom = jpj - nn_hls
       !
       SELECT CASE ( nbondj )
@@ -1871,10 +1585,10 @@
       CASE ( 0 )
          DO jl = 1, iprecj
-            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
-            pt2d(:,ijhom+jl ) = r2dns(:,jl,2)
+            pt2d(:,jl-kextj) = r2dsn(:,jl,2)
+            pt2d(:,ijhom+jl) = r2dns(:,jl,2)
          END DO
       CASE ( 1 )
          DO jl = 1, iprecj
-            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
+            pt2d(:,jl-kextj) = r2dsn(:,jl,2)
          END DO
       END SELECT
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_bdy_generic.h90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_bdy_generic.h90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_bdy_generic.h90	(revision 9012)
@@ -1,26 +1,2 @@
-#if defined MULTI
-#   define NAT_IN(k)                cd_nat(k)   
-#   define SGN_IN(k)                psgn(k)
-#   define IBD_IN(k)                kb_bdy(k)
-#   define F_SIZE(ptab)             kfld
-#   if defined DIM_2d
-#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_2D)                , INTENT(inout) ::   ptab(f)
-#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt2d(i,j)
-#      define K_SIZE(ptab)             1
-#      define L_SIZE(ptab)             1
-#   endif
-#   if defined DIM_3d
-#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_3D)                , INTENT(inout) ::   ptab(f)
-#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt3d(i,j,k)
-#      define K_SIZE(ptab)             SIZE(ptab(1)%pt3d,3)
-#      define L_SIZE(ptab)             1
-#   endif
-#   if defined DIM_4d
-#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_4D)                , INTENT(inout) ::   ptab(f)
-#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt4d(i,j,k,l)
-#      define K_SIZE(ptab)             SIZE(ptab(1)%pt4d,3)
-#      define L_SIZE(ptab)             SIZE(ptab(1)%pt4d,4)
-#   endif
-#else
 #   define ARRAY_TYPE(i,j,k,l,f)    REAL(wp)                    , INTENT(inout) ::   ARRAY_IN(i,j,k,l,f)
 #   define NAT_IN(k)                cd_nat
@@ -28,4 +4,5 @@
 #   define IBD_IN(k)                kb_bdy
 #   define F_SIZE(ptab)             1
+#   define OPT_K(k)                 
 #   if defined DIM_2d
 #      define ARRAY_IN(i,j,k,l,f)   ptab(i,j)
@@ -43,12 +20,6 @@
 #      define L_SIZE(ptab)          SIZE(ptab,4)
 #   endif
-#endif
-
-#if defined MULTI
-   SUBROUTINE ROUTINE_BDY( ptab, cd_nat, psgn, kfld, kb_bdy )
-      INTEGER                     , INTENT(in   ) ::   kfld        ! number of pt3d arrays
-#else
+
    SUBROUTINE ROUTINE_BDY( ptab, cd_nat, psgn      , kb_bdy )
-#endif
       !!----------------------------------------------------------------------
       !!                  ***  routine mpp_lnk_bdy_3d  ***
@@ -91,6 +62,6 @@
       ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
       !      
-      ALLOCATE( zt3ns(jpi,jprecj,ipk,ipl,ipf,2), zt3sn(jpi,jprecj,ipk,ipl,ipf,2),   &
-         &      zt3ew(jpj,jpreci,ipk,ipl,ipf,2), zt3we(jpj,jpreci,ipk,ipl,ipf,2)  )
+      ALLOCATE( zt3ns(jpi,nn_hls,ipk,ipl,ipf,2), zt3sn(jpi,nn_hls,ipk,ipl,ipf,2),   &
+         &      zt3ew(jpj,nn_hls,ipk,ipl,ipf,2), zt3we(jpj,nn_hls,ipk,ipl,ipf,2)  )
 
       zland = 0._wp
@@ -109,19 +80,19 @@
                ARRAY_IN(jpi,:,:,:,jf) = ARRAY_IN(  2  ,:,:,:,jf)
             ELSE                                   !* Closed
-               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(     1       :jpreci,:,:,:,jf) = zland  ! east except F-point
-                                               ARRAY_IN(nlci-jpreci+1:jpi   ,:,:,:,jf) = zland  ! west
+               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(     1       :nn_hls,:,:,:,jf) = zland  ! east except F-point
+                                               ARRAY_IN(nlci-nn_hls+1:jpi   ,:,:,:,jf) = zland  ! west
             ENDIF
          ELSEIF(nbondi == -1) THEN              ! subdomain to the east only
-            IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(1:jpreci,:,:,:,jf) = zland     ! south except F-point
+            IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(1:nn_hls,:,:,:,jf) = zland     ! south except F-point
             !
          ELSEIF(nbondi == 1) THEN               ! subdomain to the west only
-            ARRAY_IN(nlci-jpreci+1:jpi,:,:,:,jf) = zland    ! north
+            ARRAY_IN(nlci-nn_hls+1:jpi,:,:,:,jf) = zland    ! north
          ENDIF
          !                                ! North-South boundaries
          !
          IF (nbondj == 2 .OR. nbondj == -1) THEN      !* closed
-           IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:,1:jprecj,:,:,jf) = zland            ! south except F-point
+           IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:,1:nn_hls,:,:,jf) = zland            ! south except F-point
          ELSEIF (nbondj == 2 .OR. nbondj == 1) THEN
-                                           ARRAY_IN(:,nlcj-jprecj+1:jpj,:,:,jf) = zland   ! north
+                                           ARRAY_IN(:,nlcj-nn_hls+1:jpj,:,:,jf) = zland   ! north
          ENDIF
       END DO
@@ -138,6 +109,6 @@
                DO jl = 1, ipl
                   DO jk = 1, ipk
-                     DO jh = 1, jpreci
-                        zt3ew(:,jh,jk,jl,jf,1) = ARRAY_IN(jpreci+jh,:,jk,jl,jf)
+                     DO jh = 1, nn_hls
+                        zt3ew(:,jh,jk,jl,jf,1) = ARRAY_IN(nn_hls+jh,:,jk,jl,jf)
                         zt3we(:,jh,jk,jl,jf,1) = ARRAY_IN(iihom +jh,:,jk,jl,jf)
                      END DO
@@ -147,6 +118,6 @@
          !
          !                           ! Migrations
-!!gm      imigr = jpreci * jpj * ipk * ipl * ipf
-         imigr = jpreci * jpj * ipk * ipl
+!!gm      imigr = nn_hls * jpj * ipk * ipl * ipf
+         imigr = nn_hls * jpj * ipk * ipl
          !
          SELECT CASE ( nbondi_bdy(IBD_IN(jf)) )
@@ -169,5 +140,5 @@
          !
          !                           ! Write Dirichlet lateral conditions
-         iihom = nlci-jpreci
+         iihom = nlci-nn_hls
          !
          !
@@ -176,5 +147,5 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jpreci
+                  DO jh = 1, nn_hls
                      ARRAY_IN(iihom+jh,:,jk,jl,jf) = zt3ew(:,jh,jk,jl,jf,2)
                   END DO
@@ -184,5 +155,5 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jpreci
+                  DO jh = 1, nn_hls
                      ARRAY_IN(jh      ,:,jk,jl,jf) = zt3we(:,jh,jk,jl,jf,2)
                      ARRAY_IN(iihom+jh,:,jk,jl,jf) = zt3ew(:,jh,jk,jl,jf,2)
@@ -193,5 +164,5 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jpreci
+                  DO jh = 1, nn_hls
                      ARRAY_IN(jh      ,:,jk,jl,jf) = zt3we(:,jh,jk,jl,jf,2)
                   END DO
@@ -211,7 +182,7 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jprecj
+                  DO jh = 1, nn_hls
                      zt3sn(:,jh,jk,jl,jf,1) = ARRAY_IN(:,ijhom +jh,jk,jl,jf)
-                     zt3ns(:,jh,jk,jl,jf,1) = ARRAY_IN(:,jprecj+jh,jk,jl,jf)
+                     zt3ns(:,jh,jk,jl,jf,1) = ARRAY_IN(:,nn_hls+jh,jk,jl,jf)
                   END DO
                END DO
@@ -220,6 +191,6 @@
          !
          !                           ! Migrations
-!!gm      imigr = jprecj * jpi * ipk * ipl * ipf
-         imigr = jprecj * jpi * ipk * ipl
+!!gm      imigr = nn_hls * jpi * ipk * ipl * ipf
+         imigr = nn_hls * jpi * ipk * ipl
          !
          SELECT CASE ( nbondj_bdy(IBD_IN(jf)) )
@@ -242,5 +213,5 @@
          !
          !                           ! Write Dirichlet lateral conditions
-         ijhom = nlcj-jprecj
+         ijhom = nlcj-nn_hls
          !
          SELECT CASE ( nbondj_bdy_b(IBD_IN(jf)) )
@@ -248,5 +219,5 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jprecj
+                  DO jh = 1, nn_hls
                      ARRAY_IN(:,ijhom+jh,jk,jl,jf) = zt3ns(:,jh,jk,jl,jf,2)
                   END DO
@@ -256,5 +227,5 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jprecj
+                  DO jh = 1, nn_hls
                      ARRAY_IN(:,      jh,jk,jl,jf) = zt3sn(:,jh,jk,jl,jf,2)
                      ARRAY_IN(:,ijhom+jh,jk,jl,jf) = zt3ns(:,jh,jk,jl,jf,2)
@@ -265,5 +236,5 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jprecj
+                  DO jh = 1, nn_hls
                      ARRAY_IN(:,jh,jk,jl,jf) = zt3sn(:,jh,jk,jl,jf,2)
                   END DO
@@ -279,6 +250,6 @@
          !
          SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd( ptab, NAT_IN(:), SGN_IN(:) )   ! only 1 northern proc, no mpp
-         CASE DEFAULT   ;   CALL mpp_nfd( ptab, NAT_IN(:), SGN_IN(:) )   ! for all northern procs.
+         CASE ( 1 )     ;   CALL lbc_nfd( ptab, NAT_IN(:), SGN_IN(:) OPT_K(:) )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_nfd( ptab, NAT_IN(:), SGN_IN(:) OPT_K(:) )   ! for all northern procs.
          END SELECT
          !
@@ -297,2 +268,3 @@
 #undef L_SIZE
 #undef F_SIZE
+#undef OPT_K
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_lnk_generic.h90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_lnk_generic.h90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_lnk_generic.h90	(revision 9012)
@@ -72,6 +72,6 @@
       ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
       !
-      ALLOCATE( zt3ns(jpi,jprecj,ipk,ipl,ipf,2), zt3sn(jpi,jprecj,ipk,ipl,ipf,2),   &
-         &      zt3ew(jpj,jpreci,ipk,ipl,ipf,2), zt3we(jpj,jpreci,ipk,ipl,ipf,2)  )
+      ALLOCATE( zt3ns(jpi,nn_hls,ipk,ipl,ipf,2), zt3sn(jpi,nn_hls,ipk,ipl,ipf,2),   &
+         &      zt3ew(jpj,nn_hls,ipk,ipl,ipf,2), zt3we(jpj,nn_hls,ipk,ipl,ipf,2)  )
       !
       ll_Iperio = nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6)
@@ -116,6 +116,6 @@
                ARRAY_IN(jpi,:,:,:,jf) = ARRAY_IN(  2  ,:,:,:,jf)
             ELSE                                   !* closed
-               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(     1       :jpreci,:,:,:,jf) = zland    ! east except F-point
-                                               ARRAY_IN(nlci-jpreci+1:jpi   ,:,:,:,jf) = zland    ! west
+               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(     1       :nn_hls,:,:,:,jf) = zland    ! east except F-point
+                                               ARRAY_IN(nlci-nn_hls+1:jpi   ,:,:,:,jf) = zland    ! west
             ENDIF
             !                                ! North-South boundaries
@@ -124,6 +124,6 @@
                ARRAY_IN(:,jpj,:,:,jf) = ARRAY_IN(:,   2  ,:,:,jf)
             ELSE                                   !* closed
-               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:,     1       :jprecj,:,:,jf) = zland    ! south except F-point
-                                               ARRAY_IN(:,nlcj-jprecj+1:jpj   ,:,:,jf) = zland    ! north
+               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:,     1       :nn_hls,:,:,jf) = zland    ! south except F-point
+                                               ARRAY_IN(:,nlcj-nn_hls+1:jpj   ,:,:,jf) = zland    ! north
             ENDIF
          END DO
@@ -142,6 +142,6 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jpreci
-                     zt3ew(:,jh,jk,jl,jf,1) = ARRAY_IN(jpreci+jh,:,jk,jl,jf)
+                  DO jh = 1, nn_hls
+                     zt3ew(:,jh,jk,jl,jf,1) = ARRAY_IN(nn_hls+jh,:,jk,jl,jf)
                      zt3we(:,jh,jk,jl,jf,1) = ARRAY_IN(iihom +jh,:,jk,jl,jf)
                   END DO
@@ -152,5 +152,5 @@
       !
       !                           ! Migrations
-      imigr = jpreci * jpj * ipk * ipl * ipf
+      imigr = nn_hls * jpj * ipk * ipl * ipf
       !
       SELECT CASE ( nbondi )
@@ -173,5 +173,5 @@
       !
       !                           ! Write Dirichlet lateral conditions
-      iihom = nlci-jpreci
+      iihom = nlci-nn_hls
       !
       SELECT CASE ( nbondi )
@@ -180,5 +180,5 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jpreci
+                  DO jh = 1, nn_hls
                      ARRAY_IN(iihom+jh,:,jk,jl,jf) = zt3ew(:,jh,jk,jl,jf,2)
                   END DO
@@ -190,5 +190,5 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jpreci
+                  DO jh = 1, nn_hls
                      ARRAY_IN(jh      ,:,jk,jl,jf) = zt3we(:,jh,jk,jl,jf,2)
                      ARRAY_IN(iihom+jh,:,jk,jl,jf) = zt3ew(:,jh,jk,jl,jf,2)
@@ -201,5 +201,5 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jpreci
+                  DO jh = 1, nn_hls
                      ARRAY_IN(jh      ,:,jk,jl,jf) = zt3we(:,jh,jk,jl,jf,2)
                   END DO
@@ -218,7 +218,7 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jprecj
+                  DO jh = 1, nn_hls
                      zt3sn(:,jh,jk,jl,jf,1) = ARRAY_IN(:,ijhom +jh,jk,jl,jf)
-                     zt3ns(:,jh,jk,jl,jf,1) = ARRAY_IN(:,jprecj+jh,jk,jl,jf)
+                     zt3ns(:,jh,jk,jl,jf,1) = ARRAY_IN(:,nn_hls+jh,jk,jl,jf)
                   END DO
                END DO
@@ -228,5 +228,5 @@
       !
       !                           ! Migrations
-      imigr = jprecj * jpi * ipk * ipl * ipf
+      imigr = nn_hls * jpi * ipk * ipl * ipf
       !
       SELECT CASE ( nbondj )
@@ -249,5 +249,5 @@
       !
       !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj-jprecj
+      ijhom = nlcj-nn_hls
       !
       SELECT CASE ( nbondj )
@@ -256,5 +256,5 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jprecj
+                  DO jh = 1, nn_hls
                      ARRAY_IN(:,ijhom+jh,jk,jl,jf) = zt3ns(:,jh,jk,jl,jf,2)
                   END DO
@@ -266,5 +266,5 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jprecj
+                  DO jh = 1, nn_hls
                      ARRAY_IN(:,      jh,jk,jl,jf) = zt3sn(:,jh,jk,jl,jf,2)
                      ARRAY_IN(:,ijhom+jh,jk,jl,jf) = zt3ns(:,jh,jk,jl,jf,2)
@@ -277,5 +277,5 @@
             DO jl = 1, ipl
                DO jk = 1, ipk
-                  DO jh = 1, jprecj
+                  DO jh = 1, nn_hls
                      ARRAY_IN(:,jh,jk,jl,jf) = zt3sn(:,jh,jk,jl,jf,2)
                   END DO
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_nfd_generic.h90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_nfd_generic.h90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_nfd_generic.h90	(revision 9012)
@@ -73,5 +73,5 @@
       ipj   = 4            ! 2nd dimension of message transfers (last j-lines)
       !
-      ALLOCATE( znorthloc(jpi,4,ipk,ipl,ipf) )
+      ALLOCATE( znorthloc(jpimax,4,ipk,ipl,ipf) )
       !
       znorthloc(:,:,:,:,:) = 0._wp
@@ -82,5 +82,5 @@
                DO jj = nlcj - ipj +1, nlcj
                   ij = jj - nlcj + ipj
-                  znorthloc(:,ij,jk,jl,jf) = ARRAY_IN(:,jj,jk,jl,jf)
+                  znorthloc(1:jpi,ij,jk,jl,jf) = ARRAY_IN(1:jpi,jj,jk,jl,jf)
                END DO
             END DO
@@ -89,5 +89,5 @@
       !
       !
-      itaille = jpi * ipj * ipk * ipl * ipf
+      itaille = jpimax * ipj * ipk * ipl * ipf
       !
       IF( l_north_nogather ) THEN      !==  ????  ==!
@@ -177,5 +177,5 @@
       ELSE                             !==  ????  ==!
          ALLOCATE( ztab       (jpiglo,4,ipk,ipl,ipf     ) )
-         ALLOCATE( znorthgloio(jpi   ,4,ipk,ipl,ipf,jpni) )
+         ALLOCATE( znorthgloio(jpimax,4,ipk,ipl,ipf,jpni) )
          !
          CALL MPI_ALLGATHER( znorthloc  , itaille, MPI_DOUBLE_PRECISION,                &
@@ -222,11 +222,4 @@
       ENDIF
       !
-      ! The ztab array has been either:
-      !  a. Fully populated by the mpi_allgather operation or
-      !  b. Had the active points for this domain and northern neighbours populated
-      !     by peer to peer exchanges
-      ! Either way the array may be folded by lbc_nfd and the result for the span of
-      ! this domain will be identical.
-      !
       DEALLOCATE( znorthloc )
       !
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90	(revision 9012)
@@ -1,18 +1,27 @@
 MODULE mppini
-   !!==============================================================================
+   !!======================================================================
    !!                       ***  MODULE mppini   ***
    !! Ocean initialization : distributed memory computing initialization
-   !!==============================================================================
-
-   !!----------------------------------------------------------------------
-   !!   mpp_init       : Lay out the global domain over processors
-   !!   mpp_init2      : Lay out the global domain over processors 
-   !!                    with land processor elimination
-   !!   mpp_init_ioispl: IOIPSL initialization in mpp
-   !!----------------------------------------------------------------------
-   USE dom_oce         ! ocean space and time domain 
-   USE in_out_manager  ! I/O Manager
-   USE lib_mpp         ! distribued memory computing library
-   USE ioipsl
+   !!======================================================================
+   !! History :  6.0  !  1994-11  (M. Guyon)  Original code
+   !!  OPA       7.0  !  1995-04  (J. Escobar, M. Imbard)
+   !!            8.0  !  1998-05  (M. Imbard, J. Escobar, L. Colombet )  SHMEM and MPI versions
+   !!  NEMO      1.0  !  2004-01  (G. Madec, J.M Molines)  F90 : free form , north fold jpni > 1
+   !!            4.0  !  2016-06  (G. Madec)  use domain configuration file instead of bathymetry file
+   !!            4.0  !  2017-06  (J.M. Molines, T. Lovato) merge of mppini and mppini_2
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!  mpp_init       : Lay out the global domain over processors with/without land processor elimination
+   !!  mpp_init_mask  : 
+   !!  mpp_init_ioipsl: IOIPSL initialization in mpp 
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean space and time domain
+   USE bdy_oce        ! open BounDarY  
+   !
+   USE lib_mpp        ! distribued memory computing library
+   USE iom            ! nemo I/O library 
+   USE ioipsl         ! I/O IPSL library
+   USE in_out_manager ! I/O Manager
 
    IMPLICIT NONE
@@ -20,8 +29,7 @@
 
    PUBLIC mpp_init       ! called by opa.F90
-   PUBLIC mpp_init2      ! called by opa.F90
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -41,12 +49,8 @@
       !!
       !! ** Method  :   Shared memory computing, set the local processor
-      !!      variables to the value of the global domain
-      !!
-      !! History :
-      !!   9.0  !  04-01  (G. Madec, J.M. Molines)  F90 : free form, north fold jpni >1
-      !!----------------------------------------------------------------------
-
-      ! No mpp computation
-      nimpp  = 1
+      !!              variables to the value of the global domain
+      !!----------------------------------------------------------------------
+      !
+      nimpp  = 1           ! 
       njmpp  = 1
       nlci   = jpi
@@ -61,31 +65,25 @@
       nidom  = FLIO_DOM_NONE
       npolj = jperio
-
+      !
       IF(lwp) THEN
          WRITE(numout,*)
-         WRITE(numout,*) 'mpp_init(2) : NO massively parallel processing'
-         WRITE(numout,*) '~~~~~~~~~~~ '
-         WRITE(numout,*) '         nperio = ', nperio
-         WRITE(numout,*) '         npolj  = ', npolj
-         WRITE(numout,*) '         nimpp  = ', nimpp
-         WRITE(numout,*) '         njmpp  = ', njmpp
-      ENDIF
-
-      IF(  jpni /= 1 .OR. jpnj /= 1 .OR. jpnij /= 1 ) &
-          CALL ctl_stop( 'equality  jpni = jpnj = jpnij = 1 is not satisfied',   &
-          &              'the domain is lay out for distributed memory computing! ' )
-
-      IF( jperio == 7 ) CALL ctl_stop( ' jperio = 7 needs distributed memory computing ',   &
-          &              ' with 1 process. Add key_mpp_mpi in the list of active cpp keys ' )
+         WRITE(numout,*) 'mpp_init : NO massively parallel processing'
+         WRITE(numout,*) '~~~~~~~~ '
+         WRITE(numout,*) '   nperio = ', nperio, '   nimpp  = ', nimpp
+         WRITE(numout,*) '   npolj  = ', npolj , '   njmpp  = ', njmpp
+      ENDIF
+      !
+      IF(  jpni /= 1 .OR. jpnj /= 1 .OR. jpnij /= 1 )                                     &
+         CALL ctl_stop( 'mpp_init: equality  jpni = jpnj = jpnij = 1 is not satisfied',   &
+            &           'the domain is lay out for distributed memory computing!' )
+         !
+      IF( jperio == 7 ) CALL ctl_stop( 'mpp_init: jperio = 7 needs distributed memory computing ',       &
+         &                             'with 1 process. Add key_mpp_mpi in the list of active cpp keys ' )
+         !
    END SUBROUTINE mpp_init
 
-
-   SUBROUTINE mpp_init2 
-      CALL mpp_init                             ! same routine as mpp_init
-   END SUBROUTINE mpp_init2
-
 #else
    !!----------------------------------------------------------------------
-   !!   'key_mpp_mpi'          OR         MPI massively parallel processing
+   !!   'key_mpp_mpi'                     MPI massively parallel processing
    !!----------------------------------------------------------------------
 
@@ -95,4 +93,8 @@
       !!                    
       !! ** Purpose :   Lay out the global domain over processors.
+      !!      If land processors are to be eliminated, this program requires the
+      !!      presence of the domain configuration file. Land processors elimination
+      !!      is performed if jpni x jpnj /= jpnij. In this case, using the MPP_PREP
+      !!      preprocessing tool, help for defining the best cutting out.
       !!
       !! ** Method  :   Global domain is distributed in smaller local domains.
@@ -103,5 +105,5 @@
       !!                     nperio local  periodic condition
       !!
-      !! ** Action  : - set domain parameters
+      !! ** Action : - set domain parameters
       !!                    nimpp     : longitudinal index 
       !!                    njmpp     : latitudinal  index
@@ -117,344 +119,453 @@
       !!                    noso      : number for local neighboring processor
       !!                    nono      : number for local neighboring processor
-      !!
-      !! History :
-      !!        !  94-11  (M. Guyon)  Original code
-      !!        !  95-04  (J. Escobar, M. Imbard)
-      !!        !  98-02  (M. Guyon)  FETI method
-      !!        !  98-05  (M. Imbard, J. Escobar, L. Colombet )  SHMEM and MPI versions
-      !!   8.5  !  02-08  (G. Madec)  F90 : free form
-      !!   3.4  !  11-11  (C. Harris) decomposition changes for running with CICE
-      !!----------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jn   ! dummy loop indices
-      INTEGER  ::   ii, ij, ifreq, il1, il2            ! local integers
-      INTEGER  ::   iresti, irestj, ijm1, imil, inum   !   -      -
-      REAL(wp) ::   zidom, zjdom                       ! local scalars
-      INTEGER, DIMENSION(jpni,jpnj) ::   iimppt, ijmppt, ilcit, ilcjt   ! local workspace
-      !!----------------------------------------------------------------------
-
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'mpp_init : Message Passing MPI'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~'
-
-
+      !!----------------------------------------------------------------------
+      INTEGER ::   ji, jj, jn, jproc, jarea   ! dummy loop indices
+      INTEGER ::   inum                       ! local logical unit
+      INTEGER ::   idir, ifreq, icont, isurf  ! local integers
+      INTEGER ::   ii, il1, ili, imil         !   -       -
+      INTEGER ::   ij, il2, ilj, ijm1         !   -       -
+      INTEGER ::   iino, ijno, iiso, ijso     !   -       -
+      INTEGER ::   iiea, ijea, iiwe, ijwe     !   -       -
+      INTEGER ::   iresti, irestj, iproc      !   -       -
+      INTEGER, DIMENSION(jpnij) ::   iin, ii_nono, ii_noea   ! 1D workspace
+      INTEGER, DIMENSION(jpnij) ::   ijn, ii_noso, ii_nowe   !  -     -
+      INTEGER, DIMENSION(jpni,jpnj) ::   iimppt, ilci, ibondi, ipproc   ! 2D workspace
+      INTEGER, DIMENSION(jpni,jpnj) ::   ijmppt, ilcj, ibondj, ipolj    !  -     -
+      INTEGER, DIMENSION(jpni,jpnj) ::   ilei, ildi, iono, ioea         !  -     -
+      INTEGER, DIMENSION(jpni,jpnj) ::   ilej, ildj, ioso, iowe         !  -     -
+      INTEGER, DIMENSION(jpiglo,jpjglo) ::   imask   ! 2D golbal domain workspace
+      REAL(wp) ::   zidom, zjdom   ! local scalars
+      !!----------------------------------------------------------------------
+      !
+      IF ( jpni * jpnj == jpnij ) THEN    ! regular domain lay out over processors
+         imask(:,:) = 1               
+      ELSEIF ( jpni*jpnj > jpnij ) THEN   ! remove land-only processor (i.e. where imask(:,:)=0)
+         CALL mpp_init_mask( imask )   
+      ELSE                                ! error
+         CALL ctl_stop( 'mpp_init: jpnij > jpni x jpnj. Check namelist setting!' )
+      ENDIF
+      !
       !  1. Dimension arrays for subdomains
       ! -----------------------------------
-      !  Computation of local domain sizes ilcit() ilcjt()
+      !  Computation of local domain sizes ilci() ilcj()
       !  These dimensions depend on global sizes jpni,jpnj and jpiglo,jpjglo
-      !  The subdomains are squares leeser than or equal to the global
-      !  dimensions divided by the number of processors minus the overlap
-      !  array (cf. par_oce.F90).
-      
-      nreci  = 2 * jpreci
-      nrecj  = 2 * jprecj
-      iresti = MOD( jpiglo - nreci , jpni )
-      irestj = MOD( jpjglo - nrecj , jpnj )
-
-      IF(  iresti == 0 )   iresti = jpni
-
+      !  The subdomains are squares lesser than or equal to the global
+      !  dimensions divided by the number of processors minus the overlap array.
+      !
+      nreci = 2 * nn_hls
+      nrecj = 2 * nn_hls
+      iresti = 1 + MOD( jpiglo - nreci -1 , jpni )
+      irestj = 1 + MOD( jpjglo - nrecj -1 , jpnj )
+      !
+      !  Need to use jpimax and jpjmax here since jpi and jpj have already been
+      !  shrunk to local sizes in nemogcm
 #if defined key_nemocice_decomp
-      ! In order to match CICE the size of domains in NEMO has to be changed
-      ! The last line of blocks (west) will have fewer points
-
-      DO jj = 1, jpnj
-         DO ji=1, jpni-1
-            ilcit(ji,jj) = jpi
-         END DO
-         ilcit(jpni,jj) = jpiglo - (jpni - 1) * (jpi - nreci)
-      END DO
-
+      ! Change padding to be consistent with CICE
+      ilci(1:jpni-1      ,:) = jpimax
+      ilci(jpni          ,:) = jpiglo - (jpni - 1) * (jpimax - nreci)
+      !
+      ilcj(:,      1:jpnj-1) = jpjmax
+      ilcj(:,          jpnj) = jpjglo - (jpnj - 1) * (jpjmax - nrecj)
 #else
-
-      DO jj = 1, jpnj
-         DO ji = 1, iresti
-            ilcit(ji,jj) = jpi
-         END DO
-         DO ji = iresti+1, jpni
-            ilcit(ji,jj) = jpi -1
-         END DO
-      END DO
-      
+      ilci(1:iresti      ,:) = jpimax
+      ilci(iresti+1:jpni ,:) = jpimax-1
+
+      ilcj(:,      1:irestj) = jpjmax
+      ilcj(:, irestj+1:jpnj) = jpjmax-1
 #endif
-      nfilcit(:,:) = ilcit(:,:)
-      IF( irestj == 0 )   irestj = jpnj
-
-#if defined key_nemocice_decomp
-      ! Same change to domains in North-South direction as in East-West. 
-      DO ji=1,jpni
-         DO jj=1,jpnj-1
-            ilcjt(ji,jj) = jpj
-         END DO
-         ilcjt(ji,jpnj) = jpjglo - (jpnj - 1) * (jpj - nrecj)
-      END DO
-
-#else
-
-      DO ji = 1, jpni
-         DO jj = 1, irestj
-            ilcjt(ji,jj) = jpj
-         END DO
-         DO jj = irestj+1, jpnj
-            ilcjt(ji,jj) = jpj -1
-         END DO
-      END DO
-      
-#endif
+      !
+      nfilcit(:,:) = ilci(:,:)
+      !
+      zidom = nreci + sum(ilci(:,1) - nreci )
+      zjdom = nrecj + sum(ilcj(1,:) - nrecj )
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'mpp_init : MPI Message Passing MPI - domain lay out over processors'
+         WRITE(numout,*) '~~~~~~~~ '
+         WRITE(numout,*) '   defines mpp subdomains'
+         WRITE(numout,*) '      iresti = ', iresti, ' jpni = ', jpni  
+         WRITE(numout,*) '      irestj = ', irestj, ' jpnj = ', jpnj
+         WRITE(numout,*)
+         WRITE(numout,*) '      sum ilci(i,1) = ', zidom, ' jpiglo = ', jpiglo
+         WRITE(numout,*) '      sum ilcj(1,j) = ', zjdom, ' jpjglo = ', jpjglo
+      ENDIF
 
       !  2. Index arrays for subdomains
       ! -------------------------------
-      
-      iimppt(:,:) = 1
-      ijmppt(:,:) = 1
-      
+      iimppt(:,:) =  1
+      ijmppt(:,:) =  1
+      ipproc(:,:) = -1
+      !
       IF( jpni > 1 ) THEN
          DO jj = 1, jpnj
             DO ji = 2, jpni
-               iimppt(ji,jj) = iimppt(ji-1,jj) + ilcit(ji-1,jj) - nreci
+               iimppt(ji,jj) = iimppt(ji-1,jj) + ilci(ji-1,jj) - nreci
             END DO
          END DO
       ENDIF
-      nfiimpp(:,:)=iimppt(:,:)
-
-      IF( jpnj > 1 ) THEN
+      nfiimpp(:,:) = iimppt(:,:)
+      !
+      IF( jpnj > 1 )THEN
          DO jj = 2, jpnj
             DO ji = 1, jpni
-               ijmppt(ji,jj) = ijmppt(ji,jj-1)+ilcjt(ji,jj-1)-nrecj
+               ijmppt(ji,jj) = ijmppt(ji,jj-1) + ilcj(ji,jj-1) - nrecj
             END DO
          END DO
       ENDIF
-      
-      ! 3. Subdomain description
-      ! ------------------------
-
-      DO jn = 1, jpnij
-         ii = 1 + MOD( jn-1, jpni )
-         ij = 1 + (jn-1) / jpni
-         nfipproc(ii,ij) = jn - 1
-         nimppt(jn) = iimppt(ii,ij)
-         njmppt(jn) = ijmppt(ii,ij)
-         nlcit (jn) = ilcit (ii,ij)     
-         nlci       = nlcit (jn)     
-         nlcjt (jn) = ilcjt (ii,ij)     
-         nlcj       = nlcjt (jn)
-         nbondj = -1                                   ! general case
-         IF( jn   >  jpni          )   nbondj = 0      ! first row of processor
-         IF( jn   >  (jpnj-1)*jpni )   nbondj = 1      ! last  row of processor
-         IF( jpnj == 1             )   nbondj = 2      ! one processor only in j-direction
-         ibonjt(jn) = nbondj
-         
-         nbondi = 0                                    ! 
-         IF( MOD( jn, jpni ) == 1 )   nbondi = -1      !
-         IF( MOD( jn, jpni ) == 0 )   nbondi =  1      !
-         IF( jpni            == 1 )   nbondi =  2      ! one processor only in i-direction
-         ibonit(jn) = nbondi
-         
-         nldi =  1   + jpreci
-         nlei = nlci - jpreci
-         IF( nbondi == -1 .OR. nbondi == 2 )   nldi = 1
-         IF( nbondi ==  1 .OR. nbondi == 2 )   nlei = nlci
-         nldj =  1   + jprecj
-         nlej = nlcj - jprecj
-         IF( nbondj == -1 .OR. nbondj == 2 )   nldj = 1
-         IF( nbondj ==  1 .OR. nbondj == 2 )   nlej = nlcj
-         nldit(jn) = nldi
-         nleit(jn) = nlei
-         nldjt(jn) = nldj
-         nlejt(jn) = nlej
+
+      ! 3. Subdomain description in the Regular Case
+      ! --------------------------------------------
+      nperio = 0
+      icont = -1
+      DO jarea = 1, jpni*jpnj
+         ii = 1 + MOD(jarea-1,jpni)
+         ij = 1 +    (jarea-1)/jpni
+         ili = ilci(ii,ij)
+         ilj = ilcj(ii,ij)
+         ibondj(ii,ij) = -1
+         IF( jarea >  jpni          )   ibondj(ii,ij) = 0
+         IF( jarea >  (jpnj-1)*jpni )   ibondj(ii,ij) = 1
+         IF( jpnj  == 1             )   ibondj(ii,ij) = 2
+         ibondi(ii,ij) = 0
+         IF( MOD(jarea,jpni) == 1 )   ibondi(ii,ij) = -1
+         IF( MOD(jarea,jpni) == 0 )   ibondi(ii,ij) =  1
+         IF( jpni            == 1 )   ibondi(ii,ij) =  2
+
+         ! Subdomain neighbors
+         iproc = jarea - 1
+         ioso(ii,ij) = iproc - jpni
+         iowe(ii,ij) = iproc - 1
+         ioea(ii,ij) = iproc + 1
+         iono(ii,ij) = iproc + jpni
+         ildi(ii,ij) =  1  + nn_hls
+         ilei(ii,ij) = ili - nn_hls
+
+         IF( ibondi(ii,ij) == -1 .OR. ibondi(ii,ij) == 2 ) ildi(ii,ij) =  1
+         IF( ibondi(ii,ij) ==  1 .OR. ibondi(ii,ij) == 2 ) ilei(ii,ij) = ili
+         ildj(ii,ij) =  1  + nn_hls
+         ilej(ii,ij) = ilj - nn_hls
+         IF( ibondj(ii,ij) == -1 .OR. ibondj(ii,ij) == 2 ) ildj(ii,ij) =  1
+         IF( ibondj(ii,ij) ==  1 .OR. ibondj(ii,ij) == 2 ) ilej(ii,ij) = ilj
+
+         ! warning ii*ij (zone) /= nproc (processors)!
+
+         IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) THEN
+            IF( jpni == 1 )THEN
+               ibondi(ii,ij) = 2
+               nperio = 1
+            ELSE
+               ibondi(ii,ij) = 0
+            ENDIF
+            IF( MOD(jarea,jpni) == 0 ) THEN
+               ioea(ii,ij) = iproc - (jpni-1)
+            ENDIF
+            IF( MOD(jarea,jpni) == 1 ) THEN
+               iowe(ii,ij) = iproc + jpni - 1
+            ENDIF
+         ENDIF
+         ipolj(ii,ij) = 0
+         IF( jperio == 3 .OR. jperio == 4 ) THEN
+            ijm1 = jpni*(jpnj-1)
+            imil = ijm1+(jpni+1)/2
+            IF( jarea > ijm1 ) ipolj(ii,ij) = 3
+            IF( MOD(jpni,2) == 1 .AND. jarea == imil ) ipolj(ii,ij) = 4
+            IF( ipolj(ii,ij) == 3 ) iono(ii,ij) = jpni*jpnj-jarea+ijm1   ! MPI rank of northern neighbour
+         ENDIF
+         IF( jperio == 5 .OR. jperio == 6 ) THEN
+            ijm1 = jpni*(jpnj-1)
+            imil = ijm1+(jpni+1)/2
+            IF( jarea > ijm1) ipolj(ii,ij) = 5
+            IF( MOD(jpni,2) == 1 .AND. jarea == imil ) ipolj(ii,ij) = 6
+            IF( ipolj(ii,ij) == 5) iono(ii,ij) = jpni*jpnj-jarea+ijm1    ! MPI rank of northern neighbour
+         ENDIF
+         !
+         ! Check wet points over the entire domain to preserve the MPI communication stencil
+         isurf = 0
+         DO jj = 1, ilj
+            DO  ji = 1, ili
+               IF( imask(ji+iimppt(ii,ij)-1, jj+ijmppt(ii,ij)-1) == 1)   isurf = isurf+1
+            END DO
+         END DO
+         !
+         IF( isurf /= 0 ) THEN
+            icont = icont + 1
+            ipproc(ii,ij) = icont
+            iin(icont+1) = ii
+            ijn(icont+1) = ij
+         ENDIF
       END DO
+      !
+      nfipproc(:,:) = ipproc(:,:)
+
+      ! Check potential error
+      IF( icont+1 /= jpnij ) THEN
+         WRITE(ctmp1,*) ' jpni =',jpni,' jpnj =',jpnj
+         WRITE(ctmp2,*) ' jpnij =',jpnij, '< jpni x jpnj' 
+         WRITE(ctmp3,*) ' ***********, mpp_init2 finds jpnij=',icont+1
+         CALL ctl_stop( 'mpp_init: Eliminate land processors algorithm', '', ctmp1, ctmp2, '', ctmp3 )
+      ENDIF
 
       ! 4. Subdomain print
       ! ------------------
-      
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '   defines mpp subdomains'
-      IF(lwp) WRITE(numout,*) '      jpni=', jpni, ' iresti=', iresti
-      IF(lwp) WRITE(numout,*) '      jpnj=', jpnj, ' irestj=', irestj
-      zidom = nreci
-      DO ji = 1, jpni
-         zidom = zidom + ilcit(ji,1) - nreci
-      END DO
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*)'      sum ilcit(i,1)=', zidom, ' jpiglo=', jpiglo
-
-      zjdom = nrecj
-      DO jj = 1, jpnj
-         zjdom = zjdom + ilcjt(1,jj) - nrecj
-      END DO
-      IF(lwp) WRITE(numout,*)'      sum ilcit(1,j)=', zjdom, ' jpjglo=', jpjglo
-
       IF(lwp) THEN
          ifreq = 4
-         il1   = 1
+         il1 = 1
          DO jn = 1, (jpni-1)/ifreq+1
-            il2 = MIN( jpni, il1+ifreq-1 )
+            il2 = MIN(jpni,il1+ifreq-1)
             WRITE(numout,*)
-            WRITE(numout,9200) ('***',ji = il1,il2-1)
+            WRITE(numout,9400) ('***',ji=il1,il2-1)
             DO jj = jpnj, 1, -1
-               WRITE(numout,9203) ('   ',ji = il1,il2-1)
-               WRITE(numout,9202) jj, ( ilcit(ji,jj),ilcjt(ji,jj),ji = il1,il2 )
-               WRITE(numout,9204) (nfipproc(ji,jj),ji=il1,il2)
-               WRITE(numout,9203) ('   ',ji = il1,il2-1)
-               WRITE(numout,9200) ('***',ji = il1,il2-1)
+               WRITE(numout,9403) ('   ',ji=il1,il2-1)
+               WRITE(numout,9402) jj, (ilci(ji,jj),ilcj(ji,jj),ji=il1,il2)
+               WRITE(numout,9404) (ipproc(ji,jj),ji=il1,il2)
+               WRITE(numout,9403) ('   ',ji=il1,il2-1)
+               WRITE(numout,9400) ('***',ji=il1,il2-1)
             END DO
-            WRITE(numout,9201) (ji,ji = il1,il2)
+            WRITE(numout,9401) (ji,ji=il1,il2)
             il1 = il1+ifreq
          END DO
- 9200     FORMAT('     ***',20('*************',a3))
- 9203     FORMAT('     *     ',20('         *   ',a3))
- 9201     FORMAT('        ',20('   ',i3,'          '))
- 9202     FORMAT(' ',i3,' *  ',20(i3,'  x',i3,'   *   '))
- 9204     FORMAT('     *  ',20('      ',i3,'   *   '))
-      ENDIF
-
-      ! 5. From global to local
-      ! -----------------------
-
-      nperio = 0
-      IF( jperio == 2 .AND. nbondj == -1 )   nperio = 2
-
-
-      ! 6. Subdomain neighbours
+ 9400    FORMAT('     ***',20('*************',a3))
+ 9403    FORMAT('     *     ',20('         *   ',a3))
+ 9401    FORMAT('        ',20('   ',i3,'          '))
+ 9402    FORMAT(' ',i3,' *  ',20(i3,'  x',i3,'   *   '))
+ 9404    FORMAT('     *  ',20('      ',i3,'   *   '))
+      ENDIF
+
+      ! 5. neighbour treatment
       ! ----------------------
-
-      nproc = narea - 1
-      noso  = nproc - jpni
-      nowe  = nproc - 1
-      noea  = nproc + 1
-      nono  = nproc + jpni
-      ! great neighbours
-      npnw = nono - 1
-      npne = nono + 1
-      npsw = noso - 1
-      npse = noso + 1
-      nbsw = 1
-      nbnw = 1
-      IF( MOD( nproc, jpni ) == 0 ) THEN
-         nbsw = 0
-         nbnw = 0
-      ENDIF
-      nbse = 1
-      nbne = 1
-      IF( MOD( nproc, jpni ) == jpni-1 ) THEN
-         nbse = 0
-         nbne = 0
-      ENDIF
-      IF(nproc < jpni) THEN
-         nbsw = 0
-         nbse = 0
-      ENDIF
-      IF( nproc >= (jpnj-1)*jpni ) THEN
-         nbnw = 0
-         nbne = 0
-      ENDIF
-      nlcj = nlcjt(narea)  
-      nlci = nlcit(narea)  
-      nldi = nldit(narea)
-      nlei = nleit(narea)
-      nldj = nldjt(narea)
-      nlej = nlejt(narea)
-      nbondi = ibonit(narea)
-      nbondj = ibonjt(narea)
-      nimpp  = nimppt(narea)  
-      njmpp  = njmppt(narea)  
-
-      ! Save processor layout in layout.dat file 
-      IF(lwp) THEN
+      DO jarea = 1, jpni*jpnj
+         iproc = jarea-1
+         ii = 1 + MOD( jarea-1  , jpni )
+         ij = 1 +     (jarea-1) / jpni
+         IF ( ipproc(ii,ij) == -1 .AND. 0 <= iono(ii,ij) .AND. iono(ii,ij) <= jpni*jpnj-1 ) THEN
+            iino = 1 + MOD( iono(ii,ij) , jpni )
+            ijno = 1 +      iono(ii,ij) / jpni
+            ! Need to reverse the logical direction of communication 
+            ! for northern neighbours of northern row processors (north-fold)
+            ! i.e. need to check that the northern neighbour only communicates
+            ! to the SOUTH (or not at all) if this area is land-only (#1057)
+            idir = 1
+            IF( ij == jpnj .AND. ijno == jpnj )   idir = -1    
+            IF( ibondj(iino,ijno) == idir     )   ibondj(iino,ijno) =   2
+            IF( ibondj(iino,ijno) == 0        )   ibondj(iino,ijno) = -idir
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. 0 <= ioso(ii,ij) .AND. ioso(ii,ij) <= jpni*jpnj-1 ) THEN
+            iiso = 1 + MOD( ioso(ii,ij) , jpni )
+            ijso = 1 +      ioso(ii,ij) / jpni
+            IF( ibondj(iiso,ijso) == -1 )   ibondj(iiso,ijso) = 2
+            IF( ibondj(iiso,ijso) ==  0 )   ibondj(iiso,ijso) = 1
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. 0 <= ioea(ii,ij) .AND. ioea(ii,ij) <= jpni*jpnj-1 ) THEN
+            iiea = 1 + MOD( ioea(ii,ij) , jpni )
+            ijea = 1 +      ioea(ii,ij) / jpni
+            IF( ibondi(iiea,ijea) == 1 )   ibondi(iiea,ijea) =  2
+            IF( ibondi(iiea,ijea) == 0 )   ibondi(iiea,ijea) = -1
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. 0 <= iowe(ii,ij) .AND. iowe(ii,ij) <= jpni*jpnj-1) THEN
+            iiwe = 1 + MOD( iowe(ii,ij) , jpni )
+            ijwe = 1 +      iowe(ii,ij) / jpni
+            IF( ibondi(iiwe,ijwe) == -1 )   ibondi(iiwe,ijwe) = 2
+            IF( ibondi(iiwe,ijwe) ==  0 )   ibondi(iiwe,ijwe) = 1
+         ENDIF
+      END DO
+
+      ! just to save nono etc for all proc
+      ii_noso(:) = -1
+      ii_nono(:) = -1
+      ii_noea(:) = -1
+      ii_nowe(:) = -1 
+      nproc = narea-1
+      DO jarea = 1, jpnij
+         ii = iin(jarea)
+         ij = ijn(jarea)
+         IF( 0 <= ioso(ii,ij) .AND. ioso(ii,ij) <= (jpni*jpnj-1) ) THEN
+            iiso = 1 + MOD( ioso(ii,ij) , jpni )
+            ijso = 1 +      ioso(ii,ij) / jpni
+            noso = ipproc(iiso,ijso)
+            ii_noso(jarea)= noso
+         ENDIF
+         IF( 0 <= iowe(ii,ij) .AND. iowe(ii,ij) <= (jpni*jpnj-1) ) THEN
+          iiwe = 1 + MOD( iowe(ii,ij) , jpni )
+          ijwe = 1 +      iowe(ii,ij) / jpni
+          nowe = ipproc(iiwe,ijwe)
+          ii_nowe(jarea)= nowe
+         ENDIF
+         IF( 0 <= ioea(ii,ij) .AND. ioea(ii,ij) <= (jpni*jpnj-1) ) THEN
+            iiea = 1 + MOD( ioea(ii,ij) , jpni )
+            ijea = 1 +      ioea(ii,ij) / jpni
+            noea = ipproc(iiea,ijea)
+            ii_noea(jarea)= noea
+         ENDIF
+         IF( 0 <= iono(ii,ij) .AND. iono(ii,ij) <= (jpni*jpnj-1) ) THEN
+            iino = 1 + MOD( iono(ii,ij) , jpni )
+            ijno = 1 +      iono(ii,ij) / jpni
+            nono = ipproc(iino,ijno)
+            ii_nono(jarea)= nono
+         ENDIF
+      END DO
+    
+      ! 6. Change processor name
+      ! ------------------------
+      nproc = narea-1
+      ii = iin(narea)
+      ij = ijn(narea)
+      !
+      ! set default neighbours
+      noso = ii_noso(narea)
+      nowe = ii_nowe(narea)
+      noea = ii_noea(narea)
+      nono = ii_nono(narea)
+      nlcj = ilcj(ii,ij)  
+      nlci = ilci(ii,ij)  
+      nldi = ildi(ii,ij)
+      nlei = ilei(ii,ij)
+      nldj = ildj(ii,ij)
+      nlej = ilej(ii,ij)
+      nbondi = ibondi(ii,ij)
+      nbondj = ibondj(ii,ij)
+      nimpp = iimppt(ii,ij)  
+      njmpp = ijmppt(ii,ij)  
+      DO jproc = 1, jpnij
+         ii = iin(jproc)
+         ij = ijn(jproc)
+         nimppt(jproc) = iimppt(ii,ij)  
+         njmppt(jproc) = ijmppt(ii,ij) 
+         nlcjt(jproc) = ilcj(ii,ij)
+         nlcit(jproc) = ilci(ii,ij)
+         nldit(jproc) = ildi(ii,ij)
+         nleit(jproc) = ilei(ii,ij)
+         nldjt(jproc) = ildj(ii,ij)
+         nlejt(jproc) = ilej(ii,ij)
+      END DO
+
+      ! Save processor layout in ascii file
+      IF (lwp) THEN
          CALL ctl_opn( inum, 'layout.dat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE., narea )
-         WRITE(inum,'(a)') '   jpnij     jpi     jpj     jpk  jpiglo  jpjglo'
-         WRITE(inum,'(6i8)') jpnij,jpi,jpj,jpk,jpiglo,jpjglo
-         WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimpp njmpp'
-         !
-         DO jn = 1, jpnij
-            WRITE(inum,'(9i5)') jn, nlcit(jn), nlcjt(jn), &
-               &                    nldit(jn), nldjt(jn), &
-               &                    nleit(jn), nlejt(jn), &
-               &                    nimppt(jn), njmppt(jn)
+         WRITE(inum,'(a)') '   jpnij   jpimax  jpjmax    jpk  jpiglo  jpjglo'//&
+   &           ' ( local:    narea     jpi     jpj)'
+         WRITE(inum,'(6i8,a,3i8,a)') jpnij,jpimax,jpjmax,jpk,jpiglo,jpjglo,&
+   &           ' ( local: ',narea,jpi,jpj,' )'
+         WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimp njmp nono noso nowe noea nbondi nbondj '
+
+         DO jproc = 1, jpnij
+            ii = iin(jproc)
+            ij = ijn(jproc)
+            WRITE(inum,'(15i5)') jproc-1, nlcit  (jproc), nlcjt  (jproc),   &
+               &                          nldit  (jproc), nldjt  (jproc),   &
+               &                          nleit  (jproc), nlejt  (jproc),   &
+               &                          nimppt (jproc), njmppt (jproc),   & 
+               &                          ii_nono(jproc), ii_noso(jproc),   &
+               &                          ii_nowe(jproc), ii_noea(jproc),   &
+               &                          ibondi (ii,ij), ibondj (ii,ij) 
          END DO
          CLOSE(inum)   
       END IF
 
-      ! w a r n i n g  narea (zone) /= nproc (processors)!
-
-      IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 .OR. jperio == 7 ) THEN
-         IF( jpni == 1 )THEN
-            nbondi = 2
-            nperio = 1
-         ELSE
-            nbondi = 0
-         ENDIF
-         IF( MOD( narea, jpni ) == 0 ) THEN
-            noea = nproc-(jpni-1)
-            npne = npne-jpni
-            npse = npse-jpni
-         ENDIF
-         IF( MOD( narea, jpni ) == 1 ) THEN
-            nowe = nproc+(jpni-1)
-            npnw = npnw+jpni
-            npsw = npsw+jpni
-         ENDIF
-         nbsw = 1
-         nbnw = 1
-         nbse = 1
-         nbne = 1
-         IF( nproc < jpni ) THEN
-            nbsw = 0
-            nbse = 0
-         ENDIF
-         IF( nproc >= (jpnj-1)*jpni ) THEN
-            nbnw = 0
-            nbne = 0
-         ENDIF
-      ENDIF
+      !                          ! north fold parameter
+      ! Defined npolj, either 0, 3 , 4 , 5 , 6
+      ! In this case the important thing is that npolj /= 0
+      ! Because if we go through these line it is because jpni >1 and thus
+      ! we must use lbcnorthmpp, which tests only npolj =0 or npolj /= 0
       npolj = 0
+      ij = ijn(narea)
       IF( jperio == 3 .OR. jperio == 4 ) THEN
-         ijm1 = jpni*(jpnj-1)
-         imil = ijm1+(jpni+1)/2
-         IF( narea > ijm1 ) npolj = 3
-         IF( MOD(jpni,2) == 1 .AND. narea == imil ) npolj = 4
-         IF( npolj == 3 ) nono = jpni*jpnj-narea+ijm1
+         IF( ij == jpnj )   npolj = 3
       ENDIF
       IF( jperio == 5 .OR. jperio == 6 ) THEN
-          ijm1 = jpni*(jpnj-1)
-          imil = ijm1+(jpni+1)/2
-          IF( narea > ijm1) npolj = 5
-          IF( MOD(jpni,2) == 1 .AND. narea == imil ) npolj = 6
-          IF( npolj == 5 ) nono = jpni*jpnj-narea+ijm1
-      ENDIF
-
-      ! Periodicity : no corner if nbondi = 2 and nperio != 1
-
+         IF( ij == jpnj )   npolj = 5
+      ENDIF
+      !
       IF(lwp) THEN
-         WRITE(numout,*) '      nproc  = ', nproc
-         WRITE(numout,*) '      nowe   = ', nowe  , '      noea   =  ', noea
-         WRITE(numout,*) '      nono   = ', nono  , '      noso   =  ', noso
-         WRITE(numout,*) '      nbondi = ', nbondi, '      nbondj = ', nbondj
-         WRITE(numout,*) '      npolj  = ', npolj
-         WRITE(numout,*) '      nperio = ', nperio
-         WRITE(numout,*) '      nlci   = ', nlci  , '      nlcj   = ', nlcj
-         WRITE(numout,*) '      nimpp  = ', nimpp , '      njmpp  = ', njmpp
-         WRITE(numout,*) '      nreci  = ', nreci , '      npse   = ', npse
-         WRITE(numout,*) '      nrecj  = ', nrecj , '      npsw   = ', npsw
-         WRITE(numout,*) '      jpreci = ', jpreci, '      npne   = ', npne
-         WRITE(numout,*) '      jprecj = ', jprecj, '      npnw   = ', npnw
          WRITE(numout,*)
-      ENDIF
-
-      IF( jperio == 7 .AND. ( jpni /= 1 .OR. jpnj /= 1 ) ) &
-         &                  CALL ctl_stop( ' mpp_init: error jperio = 7 works only with jpni = jpnj = 1' )
-      IF( nperio == 1 .AND. jpni /= 1 ) CALL ctl_stop( ' mpp_init: error on cyclicity' )
-
-      ! Prepare mpp north fold
-
+         WRITE(numout,*) ' nproc  = ', nproc
+         WRITE(numout,*) ' nowe   = ', nowe  , ' noea   =  ', noea
+         WRITE(numout,*) ' nono   = ', nono  , ' noso   =  ', noso
+         WRITE(numout,*) ' nbondi = ', nbondi
+         WRITE(numout,*) ' nbondj = ', nbondj
+         WRITE(numout,*) ' npolj  = ', npolj
+         WRITE(numout,*) ' nperio = ', nperio
+         WRITE(numout,*) ' nlci   = ', nlci
+         WRITE(numout,*) ' nlcj   = ', nlcj
+         WRITE(numout,*) ' nimpp  = ', nimpp
+         WRITE(numout,*) ' njmpp  = ', njmpp
+         WRITE(numout,*) ' nreci  = ', nreci  
+         WRITE(numout,*) ' nrecj  = ', nrecj  
+         WRITE(numout,*) ' nn_hls = ', nn_hls 
+      ENDIF
+
+      IF( nperio == 1 .AND. jpni /= 1 ) CALL ctl_stop( 'mpp_init: error on cyclicity' )
+
+      !                          ! Prepare mpp north fold
       IF( jperio >= 3 .AND. jperio <= 6 .AND. jpni > 1 ) THEN
          CALL mpp_ini_north
          IF(lwp) WRITE(numout,*) ' mpp_init : North fold boundary prepared for jpni >1'
       ENDIF
-
-      ! Prepare NetCDF output file (if necessary)
-      CALL mpp_init_ioipsl
-
-   END SUBROUTINE mpp_init
-
-#  include "mppini_2.h90"
+      !
+      CALL mpp_init_ioipsl       ! Prepare NetCDF output file (if necessary)
+      !
+    END SUBROUTINE mpp_init
+
+
+    SUBROUTINE mpp_init_mask( kmask )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE mpp_init_mask  ***
+      !!
+      !! ** Purpose : Read relevant bathymetric information in a global array
+      !!              in order to provide a land/sea mask used for the elimination
+      !!              of land domains, in an mpp computation.
+      !!
+      !! ** Method  : Read the namelist ln_zco and ln_isfcav in namelist namzgr
+      !!              in order to choose the correct bathymetric information
+      !!              (file and variables)  
+      !!----------------------------------------------------------------------
+      INTEGER, DIMENSION(jpiglo,jpjglo), INTENT(out) ::   kmask   ! global domain 
+  
+      INTEGER :: inum   !: logical unit for configuration file
+      INTEGER :: ios    !: iostat error flag
+      INTEGER ::  ijstartrow                   ! temporary integers
+      REAL(wp), DIMENSION(jpiglo,jpjglo) ::   zbot, zbdy          ! global workspace
+      REAL(wp) ::   zidom , zjdom          ! local scalars
+      NAMELIST/nambdy/ ln_bdy, 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, &
+           &             cn_ice_lim, nn_ice_lim_dta,                           &
+           &             rn_ice_tem, rn_ice_sal, rn_ice_age,                 &
+           &             ln_vol, nn_volctl, nn_rimwidth, nb_jpk_bdy
+      !!----------------------------------------------------------------------
+      ! 0. initialisation
+      ! -----------------
+      CALL iom_open( cn_domcfg, inum )
+      !
+      ! ocean bottom level
+      CALL iom_get( inum, jpdom_unknown, 'bottom_level' , zbot , lrowattr=ln_use_jattr )  ! nb of ocean T-points
+      !
+      CALL iom_close( inum )
+      !
+      ! 2D ocean mask (=1 if at least one level of the water column is ocean, =0 otherwise)
+      WHERE( zbot(:,:) > 0 )   ;   kmask(:,:) = 1
+      ELSEWHERE                ;   kmask(:,:) = 0
+      END WHERE
+  
+      ! Adjust kmask with bdy_msk if it exists
+  
+      REWIND( numnam_ref )              ! Namelist nambdy in reference namelist : BDY
+      READ  ( numnam_ref, nambdy, IOSTAT = ios, ERR = 903)
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy in reference namelist (mppini)', lwp )
+
+      REWIND( numnam_cfg )              ! Namelist nambdy in configuration namelist : BDY
+      READ  ( numnam_cfg, nambdy, IOSTAT = ios, ERR = 904 )
+904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy in configuration namelist (mppini)', lwp )
+
+      IF( ln_bdy .AND. ln_mask_file ) THEN
+         CALL iom_open( cn_mask_file, inum )
+         CALL iom_get ( inum, jpdom_unknown, 'bdy_msk', zbdy )
+         CALL iom_close( inum )
+         WHERE ( zbdy(:,:) <= 0. ) kmask = 0
+      ENDIF
+      !
+   END SUBROUTINE mpp_init_mask
+
 
    SUBROUTINE mpp_init_ioipsl
Index: anches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mppini_2.h90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mppini_2.h90	(revision 9011)
+++ 	(revision )
@@ -1,572 +1,0 @@
-   SUBROUTINE mpp_init2
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE mpp_init2  ***
-      !!
-      !! * Purpose :   Lay out the global domain over processors.
-      !!     FOR USING THIS VERSION, A PREPROCESSING TRAITMENT IS RECOMMENDED
-      !!     FOR DEFINING BETTER CUTTING OUT.
-      !!       This routine requires the presence of the domain configuration file.
-      !!       In this version, the land processors are avoided and the adress
-      !!     processor (nproc, narea,noea, ...) are calculated again.
-      !!     The jpnij parameter can be lesser than jpni x jpnj
-      !!     and this jpnij parameter must be calculated before with an
-      !!     algoritmic preprocessing program.
-      !!
-      !! ** Method  :   Global domain is distributed in smaller local domains.
-      !!      Periodic condition is a function of the local domain position
-      !!      (global boundary or neighbouring domain) and of the global
-      !!      periodic
-      !!      Type :         jperio global periodic condition
-      !!                     nperio local  periodic condition
-      !!
-      !! ** Action :        nimpp     : longitudinal index 
-      !!                    njmpp     : latitudinal  index
-      !!                    nperio    : lateral condition type 
-      !!                    narea     : number for local area
-      !!                    nlci      : first dimension
-      !!                    nlcj      : second dimension
-      !!                    nproc     : number for local processor
-      !!                    noea      : number for local neighboring processor
-      !!                    nowe      : number for local neighboring processor
-      !!                    noso      : number for local neighboring processor
-      !!                    nono      : number for local neighboring processor
-      !!
-      !! History :       !  1994-11  (M. Guyon)  Original code
-      !!  OPA            !  1995-04  (J. Escobar, M. Imbard)
-      !!                 !  1998-02  (M. Guyon)  FETI method
-      !!                 !  1998-05  (M. Imbard, J. Escobar, L. Colombet )  SHMEM and MPI versions
-      !!  NEMO      1.0  !  2004-01  (G. Madec, J.M Molines)  F90 : free form , north fold jpni > 1
-      !!            4.0  !  2016-06  (G. Madec)  use domain configuration file instead of bathymetry file
-      !!----------------------------------------------------------------------
-      USE in_out_manager  ! I/O Manager
-      USE iom
-      USE bdy_oce
-      !! 
-      INTEGER :: ji, jj, jn, jproc, jarea     ! dummy loop indices
-      INTEGER ::  inum                        ! temporary logical unit
-      INTEGER ::  idir                        ! temporary integers
-      INTEGER ::  jstartrow                   ! temporary integers
-      INTEGER ::   ios                        ! Local integer output status for namelist read
-      INTEGER ::   &
-         ii, ij, ifreq, il1, il2,          &  ! temporary integers
-         icont, ili, ilj,                  &  !    "          "
-         isurf, ijm1, imil,                &  !    "          "
-         iino, ijno, iiso, ijso,           &  !    "          " 
-         iiea, ijea, iiwe, ijwe,           &  !    "          "
-         iinw, ijnw, iine, ijne,           &  !    "          "
-         iisw, ijsw, iise, ijse,           &  !    "          "
-         iresti, irestj, iproc                !    "          "
-      INTEGER, DIMENSION(jpnij) ::   &
-         iin, ijn          
-      INTEGER, DIMENSION(jpni,jpnj) ::   &
-         iimppt, ijmppt, ilci  , ilcj  ,   &  ! temporary workspace
-         ipproc, ibondj, ibondi, ipolj ,   &  !    "           "
-         ilei  , ilej  , ildi  , ildj  ,   &  !    "           "
-         ioea  , iowe  , ioso  , iono  ,   &  !    "           "
-         ione  , ionw  , iose  , iosw  ,   &  !    "           "
-         ibne  , ibnw  , ibse  , ibsw         !    "           "
-      INTEGER,  DIMENSION(jpiglo,jpjglo) ::   imask               ! global workspace
-      REAL(wp), DIMENSION(jpiglo,jpjglo) ::   zbot, ztop, zbdy          ! global workspace
-      REAL(wp) ::   zidom , zjdom          ! local scalars
-      NAMELIST/nambdy/ ln_bdy, 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, &
-         &             cn_ice_lim, nn_ice_lim_dta,                           &
-         &             rn_ice_tem, rn_ice_sal, rn_ice_age,                 &
-         &             ln_vol, nn_volctl, nn_rimwidth, nb_jpk_bdy
-      !!----------------------------------------------------------------------
-      !! NEMO/OPA 4.0 , NEMO Consortium (2016)
-      !! $Id$
-      !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-      !!----------------------------------------------------------------------
-
-      IF(lwp)WRITE(numout,*)
-      IF(lwp)WRITE(numout,*) 'mpp_init_2 : Message Passing MPI'
-      IF(lwp)WRITE(numout,*) '~~~~~~~~~~'
-      IF(lwp)WRITE(numout,*) ' '
-
-      IF( jpni*jpnj < jpnij )   CALL ctl_stop( ' jpnij > jpni x jpnj impossible' )
-
-      ! 0. initialisation
-      ! -----------------
-      CALL iom_open( cn_domcfg, inum )
-      !
-      !                                   ! ocean top and bottom level
-      CALL iom_get( inum, jpdom_unknown, 'bottom_level' , zbot    )  ! nb of ocean T-points
-      CALL iom_get( inum, jpdom_unknown, 'top_level'    , ztop    )  ! nb of ocean T-points (ISF)
-      !
-      CALL iom_close( inum )
-      !
-      ! 2D ocean mask (=1 if at least one level of the water column is ocean, =0 otherwise)
-      WHERE( zbot(:,:) > 0 )                   ;   imask(:,:) = 1
-      ELSEWHERE                                ;   imask(:,:) = 0
-      END WHERE
-
-      ! Adjust imask with bdy_msk if exists
-
-      REWIND( numnam_ref )              ! Namelist nambdy in reference namelist : BDY
-      READ  ( numnam_ref, nambdy, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy in reference namelist (mppini_2)', lwp )
-
-      REWIND( numnam_cfg )              ! Namelist nambdy in configuration namelist : BDY
-      READ  ( numnam_cfg, nambdy, IOSTAT = ios, ERR = 904 )
-904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy in configuration namelist (mppini_2)', lwp )
-
-      IF( ln_bdy .AND. ln_mask_file ) THEN
-         CALL iom_open( cn_mask_file, inum )
-         CALL iom_get ( inum, jpdom_unknown, 'bdy_msk', zbdy)
-         CALL iom_close( inum )
-         WHERE ( zbdy(:,:) <= 0. ) imask = 0
-      ENDIF
-
-      !  1. Dimension arrays for subdomains
-      ! -----------------------------------
-
-      !  Computation of local domain sizes ilci() ilcj()
-      !  These dimensions depend on global sizes jpni,jpnj and jpiglo,jpjglo
-      !  The subdomains are squares leeser than or equal to the global
-      !  dimensions divided by the number of processors minus the overlap
-      !  array.
-
-      nreci=2*jpreci
-      nrecj=2*jprecj
-      iresti = 1 + MOD( jpiglo - nreci -1 , jpni )
-      irestj = 1 + MOD( jpjglo - nrecj -1 , jpnj )
-
-#if defined key_nemocice_decomp
-      ! Change padding to be consistent with CICE
-      ilci(1:jpni-1      ,:) = jpi
-      ilci(jpni          ,:) = jpiglo - (jpni - 1) * (jpi - nreci)
-
-      ilcj(:,      1:jpnj-1) = jpj
-      ilcj(:,          jpnj) = jpjglo - (jpnj - 1) * (jpj - nrecj)
-#else
-      ilci(1:iresti      ,:) = jpi
-      ilci(iresti+1:jpni ,:) = jpi-1
-
-      ilcj(:,      1:irestj) = jpj
-      ilcj(:, irestj+1:jpnj) = jpj-1
-#endif
-
-      nfilcit(:,:) = ilci(:,:)
-
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) ' mpp_init2: defines mpp subdomains'
-      IF(lwp) WRITE(numout,*) ' ~~~~~~  ----------------------'
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'iresti=',iresti,' irestj=',irestj
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'jpni=',jpni,' jpnj=',jpnj
-
-      zidom = nreci + sum(ilci(:,1) - nreci ) 
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*)' sum ilci(i,1)=',zidom,' jpiglo=',jpiglo
-
-      zjdom = nrecj + sum(ilcj(1,:) - nrecj ) 
-      IF(lwp) WRITE(numout,*) ' sum ilcj(1,j)=',zjdom,' jpjglo=',jpjglo
-      IF(lwp) WRITE(numout,*)
-
-
-      !  2. Index arrays for subdomains
-      ! -------------------------------
-
-      iimppt(:,:) = 1
-      ijmppt(:,:) = 1
-      ipproc(:,:) = -1
-
-      IF( jpni > 1 )THEN
-         DO jj = 1, jpnj
-            DO ji = 2, jpni
-               iimppt(ji,jj) = iimppt(ji-1,jj) + ilci(ji-1,jj) - nreci
-            END DO
-         END DO
-      ENDIF
-      nfiimpp(:,:) = iimppt(:,:)
-
-      IF( jpnj > 1 )THEN
-         DO jj = 2, jpnj
-            DO ji = 1, jpni
-               ijmppt(ji,jj) = ijmppt(ji,jj-1) + ilcj(ji,jj-1) - nrecj
-            END DO
-         END DO
-      ENDIF
-
-
-      ! 3. Subdomain description in the Regular Case
-      ! --------------------------------------------
-
-      nperio = 0
-      icont = -1
-      DO jarea = 1, jpni*jpnj
-         ii = 1 + MOD(jarea-1,jpni)
-         ij = 1 +    (jarea-1)/jpni
-         ili = ilci(ii,ij)
-         ilj = ilcj(ii,ij)
-         ibondj(ii,ij) = -1
-         IF( jarea >  jpni          )   ibondj(ii,ij) = 0
-         IF( jarea >  (jpnj-1)*jpni )   ibondj(ii,ij) = 1
-         IF( jpnj  == 1             )   ibondj(ii,ij) = 2
-         ibondi(ii,ij) = 0
-         IF( MOD(jarea,jpni) == 1 )   ibondi(ii,ij) = -1
-         IF( MOD(jarea,jpni) == 0 )   ibondi(ii,ij) =  1
-         IF( jpni            == 1 )   ibondi(ii,ij) =  2
-
-         ! 2.4 Subdomain neighbors
-
-         iproc = jarea - 1
-         ioso(ii,ij) = iproc - jpni
-         iowe(ii,ij) = iproc - 1
-         ioea(ii,ij) = iproc + 1
-         iono(ii,ij) = iproc + jpni
-         ildi(ii,ij) = 1 + jpreci
-         ilei(ii,ij) = ili -jpreci
-         ionw(ii,ij) = iono(ii,ij) - 1
-         ione(ii,ij) = iono(ii,ij) + 1
-         iosw(ii,ij) = ioso(ii,ij) - 1
-         iose(ii,ij) = ioso(ii,ij) + 1
-         ibsw(ii,ij) = 1
-         ibnw(ii,ij) = 1
-         IF( MOD(iproc,jpni) == 0 ) THEN
-            ibsw(ii,ij) = 0
-            ibnw(ii,ij) = 0
-         ENDIF
-         ibse(ii,ij) = 1
-         ibne(ii,ij) = 1
-         IF( MOD(iproc,jpni) == jpni-1 ) THEN
-            ibse(ii,ij) = 0
-            ibne(ii,ij) = 0
-         ENDIF
-         IF( iproc < jpni ) THEN
-            ibsw(ii,ij) = 0
-            ibse(ii,ij) = 0
-         ENDIF
-         IF( iproc >= (jpnj-1)*jpni ) THEN
-            ibnw(ii,ij) = 0
-            ibne(ii,ij) = 0
-         ENDIF
-         IF( ibondi(ii,ij) == -1 .OR. ibondi(ii,ij) == 2 ) ildi(ii,ij) = 1
-         IF( ibondi(ii,ij) ==  1 .OR. ibondi(ii,ij) == 2 ) ilei(ii,ij) = ili
-         ildj(ii,ij) =  1  + jprecj
-         ilej(ii,ij) = ilj - jprecj
-         IF( ibondj(ii,ij) == -1 .OR. ibondj(ii,ij) == 2 ) ildj(ii,ij) = 1
-         IF( ibondj(ii,ij) ==  1 .OR. ibondj(ii,ij) == 2 ) ilej(ii,ij) = ilj
-
-         ! warning ii*ij (zone) /= nproc (processors)!
-
-         IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) THEN
-            IF( jpni == 1 )THEN
-               ibondi(ii,ij) = 2
-               nperio = 1
-            ELSE
-               ibondi(ii,ij) = 0
-            ENDIF
-            IF( MOD(jarea,jpni) == 0 ) THEN
-               ioea(ii,ij) = iproc - (jpni-1)
-               ione(ii,ij) = ione(ii,ij) - jpni
-               iose(ii,ij) = iose(ii,ij) - jpni
-            ENDIF
-            IF( MOD(jarea,jpni) == 1 ) THEN
-               iowe(ii,ij) = iproc + jpni - 1
-               ionw(ii,ij) = ionw(ii,ij) + jpni
-               iosw(ii,ij) = iosw(ii,ij) + jpni 
-            ENDIF
-            ibsw(ii,ij) = 1
-            ibnw(ii,ij) = 1
-            ibse(ii,ij) = 1
-            ibne(ii,ij) = 1
-            IF( iproc < jpni ) THEN
-               ibsw(ii,ij) = 0
-               ibse(ii,ij) = 0
-            ENDIF
-            IF( iproc >= (jpnj-1)*jpni ) THEN
-               ibnw(ii,ij) = 0
-               ibne(ii,ij) = 0
-            ENDIF
-         ENDIF
-         ipolj(ii,ij) = 0
-         IF( jperio == 3 .OR. jperio == 4 ) THEN
-            ijm1 = jpni*(jpnj-1)
-            imil = ijm1+(jpni+1)/2
-            IF( jarea > ijm1 ) ipolj(ii,ij) = 3
-            IF( MOD(jpni,2) == 1 .AND. jarea == imil ) ipolj(ii,ij) = 4
-            IF( ipolj(ii,ij) == 3 ) iono(ii,ij) = jpni*jpnj-jarea+ijm1   ! MPI rank of northern neighbour
-         ENDIF
-         IF( jperio == 5 .OR. jperio == 6 ) THEN
-            ijm1 = jpni*(jpnj-1)
-            imil = ijm1+(jpni+1)/2
-            IF( jarea > ijm1) ipolj(ii,ij) = 5
-            IF( MOD(jpni,2) == 1 .AND. jarea == imil ) ipolj(ii,ij) = 6
-            IF( ipolj(ii,ij) == 5) iono(ii,ij) = jpni*jpnj-jarea+ijm1    ! MPI rank of northern neighbour
-         ENDIF
-
-         ! Check wet points over the entire domain to preserve the MPI communication stencil
-         isurf = 0
-         DO jj = 1, ilj
-            DO  ji = 1, ili
-               IF( imask(ji+iimppt(ii,ij)-1, jj+ijmppt(ii,ij)-1) == 1)   isurf = isurf+1
-            END DO
-         END DO
-
-         IF(isurf /= 0) THEN
-            icont = icont + 1
-            ipproc(ii,ij) = icont
-            iin(icont+1) = ii
-            ijn(icont+1) = ij
-         ENDIF
-      END DO
-
-      nfipproc(:,:) = ipproc(:,:)
-
-      ! Control
-      IF(icont+1 /= jpnij) THEN
-         WRITE(ctmp1,*) ' jpni =',jpni,' jpnj =',jpnj
-         WRITE(ctmp2,*) ' jpnij =',jpnij, '< jpni x jpnj' 
-         WRITE(ctmp3,*) ' ***********, mpp_init2 finds jpnij=',icont+1
-         CALL ctl_stop( ' Eliminate land processors algorithm', '', ctmp1, ctmp2, '', ctmp3 )
-      ENDIF
-
-      ! 4. Subdomain print
-      ! ------------------
-
-      IF(lwp) THEN
-         ifreq = 4
-         il1 = 1
-         DO jn = 1,(jpni-1)/ifreq+1
-            il2 = MIN(jpni,il1+ifreq-1)
-            WRITE(numout,*)
-            WRITE(numout,9400) ('***',ji=il1,il2-1)
-            DO jj = jpnj, 1, -1
-               WRITE(numout,9403) ('   ',ji=il1,il2-1)
-               WRITE(numout,9402) jj, (ilci(ji,jj),ilcj(ji,jj),ji=il1,il2)
-               WRITE(numout,9404) (ipproc(ji,jj),ji=il1,il2)
-               WRITE(numout,9403) ('   ',ji=il1,il2-1)
-               WRITE(numout,9400) ('***',ji=il1,il2-1)
-            END DO
-            WRITE(numout,9401) (ji,ji=il1,il2)
-            il1 = il1+ifreq
-         END DO
- 9400     FORMAT('     ***',20('*************',a3))
- 9403     FORMAT('     *     ',20('         *   ',a3))
- 9401     FORMAT('        ',20('   ',i3,'          '))
- 9402     FORMAT(' ',i3,' *  ',20(i3,'  x',i3,'   *   '))
- 9404     FORMAT('     *  ',20('      ',i3,'   *   '))
-      ENDIF
-
-
-      ! 5. neighbour treatment
-      ! ----------------------
-
-      DO jarea = 1, jpni*jpnj
-         iproc = jarea-1
-         ii = 1 + MOD(jarea-1,jpni)
-         ij = 1 +    (jarea-1)/jpni
-         IF( ipproc(ii,ij) == -1 .AND. iono(ii,ij) >= 0   &
-            .AND. iono(ii,ij) <= jpni*jpnj-1 ) THEN
-            iino = 1 + MOD(iono(ii,ij),jpni)
-            ijno = 1 +    (iono(ii,ij))/jpni
-              ! Need to reverse the logical direction of communication 
-              ! for northern neighbours of northern row processors (north-fold)
-              ! i.e. need to check that the northern neighbour only communicates
-              ! to the SOUTH (or not at all) if this area is land-only (#1057)
-            idir = 1
-            IF( ij .eq. jpnj .AND. ijno .eq. jpnj ) idir = -1    
-            IF( ibondj(iino,ijno) == idir ) ibondj(iino,ijno)=2
-            IF( ibondj(iino,ijno) == 0 ) ibondj(iino,ijno) = -idir
-         ENDIF
-         IF( ipproc(ii,ij) == -1 .AND. ioso(ii,ij) >= 0   &
-            .AND. ioso(ii,ij) <= jpni*jpnj-1 ) THEN
-            iiso = 1 + MOD(ioso(ii,ij),jpni)
-            ijso = 1 +    (ioso(ii,ij))/jpni
-            IF( ibondj(iiso,ijso) == -1 ) ibondj(iiso,ijso) = 2
-            IF( ibondj(iiso,ijso) ==  0 ) ibondj(iiso,ijso) = 1
-         ENDIF
-         IF( ipproc(ii,ij) == -1 .AND. ioea(ii,ij) >= 0   &
-            .AND. ioea(ii,ij) <= jpni*jpnj-1) THEN
-            iiea = 1 + MOD(ioea(ii,ij),jpni)
-            ijea = 1 +    (ioea(ii,ij))/jpni
-            IF( ibondi(iiea,ijea) == 1 ) ibondi(iiea,ijea) = 2
-            IF( ibondi(iiea,ijea) == 0 ) ibondi(iiea,ijea) = -1
-         ENDIF
-         IF( ipproc(ii,ij) == -1 .AND. iowe(ii,ij) >= 0   &
-            .AND. iowe(ii,ij) <= jpni*jpnj-1) THEN
-            iiwe = 1 + MOD(iowe(ii,ij),jpni)
-            ijwe = 1 +    (iowe(ii,ij))/jpni
-            IF( ibondi(iiwe,ijwe) == -1 ) ibondi(iiwe,ijwe) = 2
-            IF( ibondi(iiwe,ijwe) ==  0 ) ibondi(iiwe,ijwe) = 1
-         ENDIF
-         IF( ipproc(ii,ij) == -1 .AND. ibne(ii,ij) == 1 ) THEN
-            iine = 1 + MOD(ione(ii,ij),jpni)
-            ijne = 1 +    (ione(ii,ij))/jpni
-            IF( ibsw(iine,ijne) == 1 ) ibsw(iine,ijne) = 0
-         ENDIF
-         IF( ipproc(ii,ij) == -1 .AND. ibsw(ii,ij) == 1 ) THEN
-            iisw = 1 + MOD(iosw(ii,ij),jpni)
-            ijsw = 1 +    (iosw(ii,ij))/jpni
-            IF( ibne(iisw,ijsw) == 1 ) ibne(iisw,ijsw) = 0
-         ENDIF
-         IF( ipproc(ii,ij) == -1 .AND. ibnw(ii,ij) == 1 ) THEN
-            iinw = 1 + MOD(ionw(ii,ij),jpni)
-            ijnw = 1 +    (ionw(ii,ij))/jpni
-            IF( ibse(iinw,ijnw) == 1 ) ibse(iinw,ijnw)=0
-         ENDIF
-         IF( ipproc(ii,ij) == -1 .AND. ibse(ii,ij) == 1 ) THEN
-            iise = 1 + MOD(iose(ii,ij),jpni)
-            ijse = 1 +    (iose(ii,ij))/jpni
-            IF( ibnw(iise,ijse) == 1 ) ibnw(iise,ijse) = 0
-         ENDIF
-      END DO
-
-
-      ! 6. Change processor name
-      ! ------------------------
-
-      nproc = narea-1
-      ii = iin(narea)
-      ij = ijn(narea)
-
-      ! set default neighbours
-      noso = ioso(ii,ij)
-      nowe = iowe(ii,ij)
-      noea = ioea(ii,ij)
-      nono = iono(ii,ij) 
-      npse = iose(ii,ij)
-      npsw = iosw(ii,ij)
-      npne = ione(ii,ij)
-      npnw = ionw(ii,ij)
-
-      ! check neighbours location
-      IF( ioso(ii,ij) >= 0 .AND. ioso(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iiso = 1 + MOD(ioso(ii,ij),jpni)
-         ijso = 1 +    (ioso(ii,ij))/jpni
-         noso = ipproc(iiso,ijso)
-      ENDIF
-      IF( iowe(ii,ij) >= 0 .AND. iowe(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iiwe = 1 + MOD(iowe(ii,ij),jpni)
-         ijwe = 1 +    (iowe(ii,ij))/jpni
-         nowe = ipproc(iiwe,ijwe)
-      ENDIF
-      IF( ioea(ii,ij) >= 0 .AND. ioea(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iiea = 1 + MOD(ioea(ii,ij),jpni)
-         ijea = 1 +    (ioea(ii,ij))/jpni
-         noea = ipproc(iiea,ijea)
-      ENDIF
-      IF( iono(ii,ij) >= 0 .AND. iono(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iino = 1 + MOD(iono(ii,ij),jpni)
-         ijno = 1 +    (iono(ii,ij))/jpni
-         nono = ipproc(iino,ijno)
-      ENDIF
-      IF( iose(ii,ij) >= 0 .AND. iose(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iise = 1 + MOD(iose(ii,ij),jpni)
-         ijse = 1 +    (iose(ii,ij))/jpni
-         npse = ipproc(iise,ijse)
-      ENDIF
-      IF( iosw(ii,ij) >= 0 .AND. iosw(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iisw = 1 + MOD(iosw(ii,ij),jpni)
-         ijsw = 1 +    (iosw(ii,ij))/jpni
-         npsw = ipproc(iisw,ijsw)
-      ENDIF
-      IF( ione(ii,ij) >= 0 .AND. ione(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iine = 1 + MOD(ione(ii,ij),jpni)
-         ijne = 1 +    (ione(ii,ij))/jpni
-         npne = ipproc(iine,ijne)
-      ENDIF
-      IF( ionw(ii,ij) >= 0 .AND. ionw(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iinw = 1 + MOD(ionw(ii,ij),jpni)
-         ijnw = 1 +    (ionw(ii,ij))/jpni
-         npnw = ipproc(iinw,ijnw)
-      ENDIF
-      nbnw = ibnw(ii,ij)
-      nbne = ibne(ii,ij)
-      nbsw = ibsw(ii,ij)
-      nbse = ibse(ii,ij)
-      nlcj = ilcj(ii,ij)  
-      nlci = ilci(ii,ij)  
-      nldi = ildi(ii,ij)
-      nlei = ilei(ii,ij)
-      nldj = ildj(ii,ij)
-      nlej = ilej(ii,ij)
-      nbondi = ibondi(ii,ij)
-      nbondj = ibondj(ii,ij)
-      nimpp = iimppt(ii,ij)  
-      njmpp = ijmppt(ii,ij)  
-      DO jproc = 1, jpnij
-         ii = iin(jproc)
-         ij = ijn(jproc)
-         nimppt(jproc) = iimppt(ii,ij)  
-         njmppt(jproc) = ijmppt(ii,ij)  
-         nlcjt(jproc) = ilcj(ii,ij)
-         nlcit(jproc) = ilci(ii,ij)
-         nldit(jproc) = ildi(ii,ij)
-         nleit(jproc) = ilei(ii,ij)
-         nldjt(jproc) = ildj(ii,ij)
-         nlejt(jproc) = ilej(ii,ij)
-      END DO
-
-      ! Save processor layout in ascii file
-      IF (lwp) THEN
-         CALL ctl_opn( inum, 'layout.dat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE., narea )
-         WRITE(inum,'(a)') '   jpnij     jpi     jpj     jpk  jpiglo  jpjglo'
-         WRITE(inum,'(6i8)') jpnij,jpi,jpj,jpk,jpiglo,jpjglo
-         WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimpp njmpp'
-
-        DO  jproc = 1, jpnij
-         WRITE(inum,'(9i5)') jproc, nlcit(jproc), nlcjt(jproc), &
-                                      nldit(jproc), nldjt(jproc), &
-                                      nleit(jproc), nlejt(jproc), &
-                                      nimppt(jproc), njmppt(jproc)
-        END DO
-        CLOSE(inum)   
-      END IF
-
-      ! Defined npolj, either 0, 3 , 4 , 5 , 6
-      ! In this case the important thing is that npolj /= 0
-      ! Because if we go through these line it is because jpni >1 and thus
-      ! we must use lbcnorthmpp, which tests only npolj =0 or npolj /= 0
-
-      npolj = 0
-      ij = ijn(narea)
-
-      IF( jperio == 3 .OR. jperio == 4 ) THEN
-         IF( ij == jpnj ) npolj = 3
-      ENDIF
-
-      IF( jperio == 5 .OR. jperio == 6 ) THEN
-         IF( ij == jpnj ) npolj = 5
-      ENDIF
-
-      ! Periodicity : no corner if nbondi = 2 and nperio != 1
-
-      IF(lwp) THEN
-         WRITE(numout,*) ' nproc  = ', nproc
-         WRITE(numout,*) ' nowe   = ', nowe  , ' noea   =  ', noea
-         WRITE(numout,*) ' nono   = ', nono  , ' noso   =  ', noso
-         WRITE(numout,*) ' nbondi = ', nbondi
-         WRITE(numout,*) ' nbondj = ', nbondj
-         WRITE(numout,*) ' npolj  = ', npolj
-         WRITE(numout,*) ' nperio = ', nperio
-         WRITE(numout,*) ' nlci   = ', nlci
-         WRITE(numout,*) ' nlcj   = ', nlcj
-         WRITE(numout,*) ' nimpp  = ', nimpp
-         WRITE(numout,*) ' njmpp  = ', njmpp
-         WRITE(numout,*) ' nreci  = ', nreci  , ' npse   = ', npse
-         WRITE(numout,*) ' nrecj  = ', nrecj  , ' npsw   = ', npsw
-         WRITE(numout,*) ' jpreci = ', jpreci , ' npne   = ', npne
-         WRITE(numout,*) ' jprecj = ', jprecj , ' npnw   = ', npnw
-         WRITE(numout,*)
-      ENDIF
-
-      IF( nperio == 1 .AND. jpni /= 1 ) CALL ctl_stop( ' mpp_init2: error on cyclicity' )
-
-      ! Prepare mpp north fold
-
-      IF( jperio >= 3 .AND. jperio <= 6 .AND. jpni > 1 ) THEN
-         CALL mpp_ini_north
-         IF(lwp) WRITE(numout,*) ' mpp_init2 : North fold boundary prepared for jpni >1'
-      ENDIF
-
-      ! Prepare NetCDF output file (if necessary)
-      CALL mpp_init_ioipsl
-
-
-   END SUBROUTINE mpp_init2
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 9012)
@@ -235,4 +235,6 @@
       INTEGER  ::   ji                 ! dummy loop indices
       INTEGER  ::   ios, ilocal_comm   ! local integer
+      INTEGER  ::   iiarea, ijarea     ! local integers
+      INTEGER  ::   iirest, ijrest     ! local integers
       CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
       !
@@ -278,17 +280,4 @@
       ENDIF
       !
-      jpk = jpkglo
-      !
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
-         jpiglo  = nbcellsx + 2 + 2*nbghostcells
-         jpjglo  = nbcellsy + 2 + 2*nbghostcells
-         jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
-         jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
-         nperio  = 0
-         jperio  = 0
-         ln_use_jattr = .false.
-      ENDIF
-#endif
       !
       !                             !--------------------------------------------!
@@ -349,18 +338,42 @@
 #endif
       ENDIF
+      !
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
+         jpiglo  = nbcellsx + 2 + 2*nbghostcells
+         jpjglo  = nbcellsy + 2 + 2*nbghostcells
+         jpi     = ( jpiglo-2*nn_hls + (jpni-1+0) ) / jpni + 2*nn_hls
+         jpj     = ( jpjglo-2*nn_hls + (jpnj-1+0) ) / jpnj + 2*nn_hls
+         jpimax  = jpi
+         jpjmax  = jpj
+         nperio  = 0
+         jperio  = 0
+         ln_use_jattr = .false.
+      ENDIF
+#endif
 
       IF( Agrif_Root() ) THEN       ! AGRIF mother: specific setting from jpni and jpnj
+         iiarea = 1 + MOD( narea - 1 , jpni )
+         ijarea = 1 + ( narea - 1 ) / jpni
+         iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni )
+         ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj )
 #if defined key_nemocice_decomp
-         jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
-         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim. 
+         jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+         jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim. 
+         jpimax  = jpi
+         jpjmax  = jpj
+         IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls)
+         IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls)
 #else
-         jpi = ( jpiglo     -2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
-         jpj = ( jpjglo     -2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim.
-#endif
-      ENDIF
-
-!!gm ???    why here  it has already been done in line 301 !
+         jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+         jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.
+         jpimax  = jpi
+         jpjmax  = jpj
+         IF( iiarea > iirest ) jpi = jpi - 1
+         IF( ijarea > ijrest ) jpj = jpj - 1
+#endif
+      ENDIF
+
       jpk = jpkglo                                             ! third dim
-!!gm end
 
 #if defined key_agrif
@@ -409,7 +422,6 @@
 
       !                                      ! Domain decomposition
-      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
-      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
-      ENDIF
+      CALL mpp_init
+      IF( ln_nnogather )    CALL nemo_northcomms! northfold neighbour lists (must be done after the masks are defined)
       !
       IF( ln_timing    )   CALL timing_init
@@ -422,5 +434,5 @@
                            CALL     dom_init   ! Domain
       IF( ln_crs       )   CALL     crs_init   ! coarsened grid: domain initialization 
-      IF( ln_nnogather )   CALL nemo_northcomms! northfold neighbour lists (must be done after the masks are defined)
+      !IF( ln_nnogather )    CALL nemo_northcomms! northfold neighbour lists (must be done after the masks are defined)
       IF( ln_ctl       )   CALL prt_ctl_init   ! Print control
       
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/par_oce.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/par_oce.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/OPA_SRC/par_oce.F90	(revision 9012)
@@ -54,6 +54,6 @@
 
    ! local domain size                !!! * local computational domain *
-   INTEGER, PUBLIC ::   jpi   ! = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   !: first  dimension
-   INTEGER, PUBLIC ::   jpj   ! = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   !: second dimension
+   INTEGER, PUBLIC ::   jpi   ! = ( jpiglo-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls   !: first  dimension
+   INTEGER, PUBLIC ::   jpj   ! = ( jpjglo-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls   !: second dimension
    INTEGER, PUBLIC ::   jpk   ! = jpkglo
    INTEGER, PUBLIC ::   jpim1 ! = jpi-1                                            !: inner domain indices
@@ -61,4 +61,6 @@
    INTEGER, PUBLIC ::   jpkm1 ! = jpk-1                                            !:   -     -      -
    INTEGER, PUBLIC ::   jpij  ! = jpi*jpj                                          !:  jpi x jpj
+   INTEGER, PUBLIC ::   jpimax! = maximum jpi across all areas 
+   INTEGER, PUBLIC ::   jpjmax! = maximum jpj across all areas
 
    !!---------------------------------------------------------------------
@@ -78,6 +80,5 @@
    INTEGER, PUBLIC, PARAMETER ::   jpr2di = 0   !: number of columns for extra outer halo 
    INTEGER, PUBLIC, PARAMETER ::   jpr2dj = 0   !: number of rows    for extra outer halo 
-   INTEGER, PUBLIC, PARAMETER ::   jpreci = 1   !: number of columns for overlap 
-   INTEGER, PUBLIC, PARAMETER ::   jprecj = 1   !: number of rows    for overlap 
+   INTEGER, PUBLIC, PARAMETER ::   nn_hls = 1   !: halo width (applies to both rows and columns)
 
    !!----------------------------------------------------------------------
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90	(revision 9012)
@@ -93,4 +93,6 @@
       INTEGER ::   ji                 ! dummy loop indices
       INTEGER ::   ios, ilocal_comm   ! local integer
+      INTEGER  ::   iiarea, ijarea     ! local integers
+      INTEGER  ::   iirest, ijrest     ! local integers
       CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
       !
@@ -209,21 +211,52 @@
 #endif
       ENDIF
+      !
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
+         jpiglo  = nbcellsx + 2 + 2*nbghostcells
+         jpjglo  = nbcellsy + 2 + 2*nbghostcells
+         jpi     = ( jpiglo-2*nn_hls + (jpni-1+0) ) / jpni + 2*nn_hls
+         jpj     = ( jpjglo-2*nn_hls + (jpnj-1+0) ) / jpnj + 2*nn_hls
+         jpimax  = jpi
+         jpjmax  = jpj
+         nperio  = 0
+         jperio  = 0
+         ln_use_jattr = .false.
+      ENDIF
+#endif
 
       IF( Agrif_Root() ) THEN       ! AGRIF mother: specific setting from jpni and jpnj
+         iiarea = 1 + MOD( narea - 1 , jpni )
+         ijarea = 1 + ( narea - 1 ) / jpni
+         iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni )
+         ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj )
 #if defined key_nemocice_decomp
-         jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
-         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim. 
+         jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+         jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim. 
+         jpimax  = jpi
+         jpjmax  = jpj
+         IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls)
+         IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls)
 #else
-         jpi = ( jpiglo     -2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
-         jpj = ( jpjglo     -2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim.
-#endif
-      ENDIF
-
-!!gm ???    why here  it has already been done in line 301 !
+         jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+         jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.
+         jpimax  = jpi
+         jpjmax  = jpj
+         IF( iiarea > iirest ) jpi = jpi - 1
+         IF( ijarea > ijrest ) jpj = jpj - 1
+#endif
+      ENDIF
+
       jpk = jpkglo                                             ! third dim
-!!gm end
+
+#if defined key_agrif
+      ! simple trick to use same vertical grid as parent but different number of levels: 
+      ! Save maximum number of levels in jpkglo, then define all vertical grids with this number.
+      ! Suppress once vertical online interpolation is ok
+      IF(.NOT.Agrif_Root())   jpkglo = Agrif_Parent( jpkglo )
+#endif
       jpim1 = jpi-1                                            ! inner domain indices
       jpjm1 = jpj-1                                            !   "           "
-      jpkm1 = jpk-1                                            !   "           "
+      jpkm1 = MAX( 1, jpk-1 )                                  !   "           "
       jpij  = jpi*jpj                                          !  jpi x j
 
@@ -261,8 +294,6 @@
       CALL nemo_ctl                             ! Control prints & Benchmark
 
-      !                                         ! Domain decomposition
-      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
-      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
-      ENDIF
+      !                                      ! Domain decomposition
+      CALL mpp_init
       !
       IF( ln_timing    )   CALL timing_init     ! timing by routine
@@ -384,5 +415,5 @@
       !
       IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
-      IF( numsol          /= -1 )   CLOSE( numsol          )   ! solver file
+      IF( numrun          /= -1 )   CLOSE( numrun          )   ! run statistics file
       IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
       IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 9012)
@@ -163,4 +163,6 @@
       INTEGER  ::   ilocal_comm   ! local integer
       INTEGER  ::   ios, inum     !   -      -
+      INTEGER  ::   iiarea, ijarea     ! local integers
+      INTEGER  ::   iirest, ijrest     ! local integers
       CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
       CHARACTER(len=80)                 ::   clname
@@ -216,17 +218,4 @@
       ENDIF
       !
-      jpk = jpkglo
-      !
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
-         jpiglo  = nbcellsx + 2 + 2*nbghostcells
-         jpjglo  = nbcellsy + 2 + 2*nbghostcells
-         jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
-         jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
-         nperio  = 0
-         jperio  = 0
-         ln_use_jattr = .false.
-      ENDIF
-#endif
       !
       !                             !--------------------------------------------!
@@ -285,14 +274,42 @@
 #endif
       ENDIF
+      !
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
+         jpiglo  = nbcellsx + 2 + 2*nbghostcells
+         jpjglo  = nbcellsy + 2 + 2*nbghostcells
+         jpi     = ( jpiglo-2*nn_hls + (jpni-1+0) ) / jpni + 2*nn_hls
+         jpj     = ( jpjglo-2*nn_hls + (jpnj-1+0) ) / jpnj + 2*nn_hls
+         jpimax  = jpi
+         jpjmax  = jpj
+         nperio  = 0
+         jperio  = 0
+         ln_use_jattr = .false.
+      ENDIF
+#endif
 
       IF( Agrif_Root() ) THEN       ! AGRIF mother: specific setting from jpni and jpnj
+         iiarea = 1 + MOD( narea - 1 , jpni )
+         ijarea = 1 + ( narea - 1 ) / jpni
+         iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni )
+         ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj )
 #if defined key_nemocice_decomp
-         jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
-         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim. 
+         jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+         jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim. 
+         jpimax  = jpi
+         jpjmax  = jpj
+         IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls)
+         IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls)
 #else
-         jpi = ( jpiglo     -2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
-         jpj = ( jpjglo     -2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim.
-#endif
-      ENDIF
+         jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+         jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.
+         jpimax  = jpi
+         jpjmax  = jpj
+         IF( iiarea > iirest ) jpi = jpi - 1
+         IF( ijarea > ijrest ) jpj = jpj - 1
+#endif
+      ENDIF
+
+      jpk = jpkglo                                             ! third dim
 
 #if defined key_agrif
@@ -345,7 +362,5 @@
 
       !                                      ! Domain decomposition
-      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
-      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
-      ENDIF
+      CALL mpp_init
       !
       IF( ln_timing    )   CALL timing_init
Index: /branches/2017/dev_CNRS_2017/NEMOGCM/SETTE/sette_rpt.sh
===================================================================
--- /branches/2017/dev_CNRS_2017/NEMOGCM/SETTE/sette_rpt.sh	(revision 9011)
+++ /branches/2017/dev_CNRS_2017/NEMOGCM/SETTE/sette_rpt.sh	(revision 9012)
@@ -22,4 +22,5 @@
   nam=$2
   pass=$3
+
 #
   if [ -d $vdir/$nam ]; then
@@ -336,13 +337,5 @@
   mach=`grep "COMPILER=" ./sette.sh | sed -e 's/COMPILER=//'`
   NEMO_VALID=`grep "NEMO_VALIDATION_DIR=" ./param.cfg | sed -e 's/NEMO_VALIDATION_DIR=//'`
-# Directory to run the tests
- SETTE_DIR=$(cd $(dirname "$0"); pwd)
- MAIN_DIR=$(dirname $SETTE_DIR)
- CONFIG_DIR0=${MAIN_DIR}/CONFIG
- TOOLS_DIR=${MAIN_DIR}/TOOLS
- COMPIL_DIR=${TOOLS_DIR}/COMPILE
- NPROC=32
-
-  SAS_RESTART_DIR=${CONFIG_DIR0}/SAS_ST
+  NEMO_VALID=`eval "echo $NEMO_VALID"`
 #
   if [ ! -d $NEMO_VALID ]; then
@@ -350,4 +343,13 @@
     exit
   fi
+#
+# Directory to run the tests
+  SETTE_DIR=$(cd $(dirname "$0"); pwd)
+  MAIN_DIR=$(dirname $SETTE_DIR)
+  CONFIG_DIR0=${MAIN_DIR}/CONFIG
+  TOOLS_DIR=${MAIN_DIR}/TOOLS
+  COMPIL_DIR=${TOOLS_DIR}/COMPILE
+  NPROC=32
+  SAS_RESTART_DIR=${CONFIG_DIR0}/SAS_ST
 #
 # Show current revision tag and branch name
