Index: /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/EXTERNAL/XMLIO_SERVER/src/IOSERVER/mod_event_parameters.f90
===================================================================
--- /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/EXTERNAL/XMLIO_SERVER/src/IOSERVER/mod_event_parameters.f90	(revision 2461)
+++ /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/EXTERNAL/XMLIO_SERVER/src/IOSERVER/mod_event_parameters.f90	(revision 2462)
@@ -19,3 +19,4 @@
   INTEGER, PARAMETER :: event_id_set_calendar          = 117
   INTEGER, PARAMETER :: event_id_stop_ioserver         = 999
+  INTEGER, ALLOCATABLE, SAVE :: nregproc_in(:)
 END MODULE mod_event_parameters
Index: /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/EXTERNAL/XMLIO_SERVER/src/IOSERVER/mod_ioclient_para.F90
===================================================================
--- /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/EXTERNAL/XMLIO_SERVER/src/IOSERVER/mod_ioclient_para.F90	(revision 2461)
+++ /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/EXTERNAL/XMLIO_SERVER/src/IOSERVER/mod_ioclient_para.F90	(revision 2462)
@@ -17,4 +17,5 @@
 #endif
   USE mpi_mod
+  USE mod_event_parameters
   IMPLICIT NONE
     INTEGER :: NEW_COMM
@@ -26,9 +27,10 @@
     INTEGER :: nb_server_io  
     INTEGER,ALLOCATABLE :: proc_color(:) 
-    INTEGER :: i
+    INTEGER :: i, ix, jpni_reg, jpnj_reg
     INTEGER :: div,remain
     INTEGER :: group_color
     INTEGER :: Comm_client_server
     CHARACTER(LEN=6) :: oasis_server_id
+    LOGICAL :: ln_around, ln_use_allproc
     
     IF (using_oasis) THEN
@@ -51,11 +53,49 @@
 
     nb_server_io=global_size-mpi_size
-    div=mpi_size/nb_server_io
-    remain=MOD(mpi_size,nb_server_io)
-    
-    IF (mpi_rank<remain*(div+1)) THEN
-      group_color=mpi_rank/(div+1)
+!   
+! Need to be cleverer at setting group_colour when jpni*jpnj /= jpnij
+! nregproc_in holds the list of equivalent ranks in a jpni by jpnj decomposition
+! which has retained the land-only areas. If jpni*jpnj= jpnij then nregproc_in(mpi_size)
+! should equal mpi_size-1 and nregproc_in(mpi_rank+1) = mpi_rank for all mpi_rank.
+!
+    ln_use_allproc = .true.
+    ALLOCATE(nregproc_in(mpi_size))
+    INQUIRE (file='layout.dat', exist=ln_around)
+    IF (ln_around) THEN
+! use it
+     OPEN(UNIT=123,FILE='layout.dat')
+     READ(123,'(48X,2i8,/)',ERR=606,END=606) jpni_reg, jpnj_reg
+     do ix = 1,mpi_size
+      READ(123,'(45X,I5)',ERR=606,END=606) nregproc_in(ix)
+     end do
+     ln_use_allproc = .false.
+ 606 CLOSE(123)
+    ENDIF
+    IF ( ln_use_allproc ) THEN
+!
+! Either layout.dat does not exist or the reading of nregproc_in has failed.
+! Default to regular decomposition with no omitted land-only regions.
+!
+     do ix = 1,mpi_size
+      nregproc_in(ix) = ix - 1
+     end do
+!
+! jpni_reg and jpnj_reg are not known; just have to make sure jpni_reg*jpnj_reg=mpi_size
+!
+     jpni_reg=mpi_size
+     jpnj_reg=1
+    ENDIF
+
+    div=(jpni_reg*jpnj_reg)/nb_server_io
+    remain=MOD(jpni_reg*jpnj_reg,nb_server_io)
+ 
+!
+! Note need to add 1 to mpi_rank when indexing nregproc_in since nregproc_in is 
+! indexed 1 to mpi_size but mpi_rank ranges from 0 to mpi_size-1
+!
+    IF (nregproc_in(mpi_rank+1)<remain*(div+1)) THEN
+      group_color=nregproc_in(mpi_rank+1)/(div+1)
     ELSE
-      group_color=(nb_server_io-1)-(mpi_size-1-mpi_rank)/div
+      group_color=(nb_server_io-1)-(jpni_reg*jpnj_reg - 1 -nregproc_in(mpi_rank+1))/div
     ENDIF
 
Index: /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 2461)
+++ /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 2462)
@@ -89,4 +89,5 @@
    !                                                  ! (mi0=1 and mi1=0 if the global index is not in the local domain)
    INTEGER, PUBLIC, DIMENSION(jpnij)  ::   nimppt, njmppt   !: i-, j-indexes for each processor
+   INTEGER, PUBLIC, DIMENSION(jpnij)  ::   nregproc_out     !: equivalent rank position when jpni*jpnj=jpnij
    INTEGER, PUBLIC, DIMENSION(jpnij)  ::   ibonit, ibonjt   !: i-, j- processor neighbour existence
    INTEGER, PUBLIC, DIMENSION(jpnij)  ::   nlcit , nlcjt    !: dimensions of every subdomain
Index: /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90
===================================================================
--- /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90	(revision 2461)
+++ /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90	(revision 2462)
@@ -16,4 +16,7 @@
    USE lib_mpp         ! distribued memory computing library
    USE ioipsl
+#if defined key_iomput
+   USE mod_event_client
+# endif
 
    IMPLICIT NONE
@@ -278,4 +281,5 @@
          nldjt(jn) = nldj
          nlejt(jn) = nlej
+         nregproc_out(jn) = jn - 1
       END DO
       
@@ -336,14 +340,32 @@
         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'
+        WRITE(inum,'(8i8)') jpnij,jpi,jpj,jpk,jpiglo,jpjglo,jpni,jpnj
+        WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimpp njmpp nregproc_out'
 
         DO  jn = 1, jpnij
-         WRITE(inum,'(9i5)') jn, nlcit(jn), nlcjt(jn), &
+         WRITE(inum,'(10i5)') jn, nlcit(jn), nlcjt(jn), &
                                       nldit(jn), nldjt(jn), &
                                       nleit(jn), nlejt(jn), &
-                                      nimppt(jn), njmppt(jn)
+                                      nimppt(jn), njmppt(jn), nregproc_out(jn)
         END DO
         CLOSE(inum)   
+#ifdef key_iomput
+     ! Check nregproc_in matches nregproc_out and abort if it does not.
+     ! This should only occur on the first run of a new domain decomposition
+     ! when jpni*jpnj /= jpnij. If ioservers are not being used, Init_parallel 
+     ! will not have been called and nregproc_in will not have been allocated.
+     ! In such a case the check is unnecessary so only check for a match if 
+     ! nregproc_in has been allocated.
+      IF (ALLOCATED(nregproc_in)) THEN
+        DO  jn = 1, jpnij
+         IF ( nregproc_in(jn) /= nregproc_out(jn) ) THEN
+          WRITE(numout,*) ' nregproc_in and nregproc_out do not match.'
+          WRITE(numout,*) ' This is expected when starting a new domain docomposition.'
+          WRITE(numout,*) ' The layout.dat file has been updated and the model may be rerun.'
+          CALL ctl_stop( ' mpp_init: IO server domain colour assignment mismatch ')
+         END IF
+        END DO
+      ENDIF
+#endif
       END IF
 
Index: /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/NEMO/OPA_SRC/LBC/mppini_2.h90
===================================================================
--- /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/NEMO/OPA_SRC/LBC/mppini_2.h90	(revision 2461)
+++ /branches/DEV_r2460_v3_3beta_NOL/NEMOGCM/NEMO/OPA_SRC/LBC/mppini_2.h90	(revision 2462)
@@ -41,4 +41,7 @@
       USE in_out_manager  ! I/O Manager
       USE iom
+#if defined key_iomput
+      USE mod_event_client
+# endif
       !! 
       INTEGER :: ji, jj, jn, jproc, jarea     ! dummy loop indices
@@ -288,4 +291,5 @@
             iin(icont+1) = ii
             ijn(icont+1) = ij
+            nregproc_out(icont+1) = jarea - 1
          ENDIF
       END DO
@@ -461,14 +465,32 @@
       IF (lwp) THEN
          CALL ctl_opn( inum, 'layout.dat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE., narea )
-         WRITE(inum,'(6i8)') jpnij,jpi,jpj,jpk,jpiglo,jpjglo
-         WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimpp njmpp'
+         WRITE(inum,'(8i8)') jpnij,jpi,jpj,jpk,jpiglo,jpjglo,jpni,jpnj
+         WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimpp njmpp nregproc_out'
 
         DO  jproc = 1, jpnij
-         WRITE(inum,'(9i5)') jproc, nlcit(jproc), nlcjt(jproc), &
+         WRITE(inum,'(10i5)') jproc, nlcit(jproc), nlcjt(jproc), &
                                       nldit(jproc), nldjt(jproc), &
                                       nleit(jproc), nlejt(jproc), &
-                                      nimppt(jproc), njmppt(jproc)
+                                      nimppt(jproc), njmppt(jproc), nregproc_out(jproc)
         END DO
         CLOSE(inum)   
+#ifdef key_iomput
+     ! Check nregproc_in matches nregproc_out and abort if it does not.
+     ! This should only occur on the first run of a new domain decomposition
+     ! when jpni*jpnj /= jpnij. If ioservers are not being used, Init_parallel
+     ! will not have been called and nregproc_in will not have been allocated.
+     ! In such a case the check is unnecessary so only check for a match if
+     ! nregproc_in has been allocated.
+       IF (ALLOCATED(nregproc_in)) THEN
+        DO  jn = 1, jpnij
+         IF ( nregproc_in(jn) /= nregproc_out(jn) ) THEN
+          WRITE(numout,*) ' nregproc_in and nregproc_out do not match.'
+          WRITE(numout,*) ' This is expected when starting a new domain docomposition.'
+          WRITE(numout,*) ' The layout.dat file has been updated and the model may be rerun.'
+          CALL ctl_stop( ' mpp_init: IO server domain colour assignment mismatch ')
+         END IF
+        END DO
+       END IF
+#endif
       END IF
 
