Index: branches/2017/dev_merge_2017/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90
===================================================================
--- branches/2017/dev_merge_2017/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90	(revision 9169)
+++ branches/2017/dev_merge_2017/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90	(revision 9213)
@@ -10,50 +10,56 @@
 
    !!----------------------------------------------------------------------
-   !!   nemo_gcm        : off-line: solve ocean tracer only
-   !!   nemo_init       : initialization of the nemo model
-   !!   nemo_ctl        : initialisation of algorithm flag 
-   !!   nemo_closefile  : close remaining files
+   !!   nemo_gcm      : off-line: solve ocean tracer only
+   !!   nemo_gcm      : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
+   !!   nemo_init     : initialization of the NEMO system
+   !!   nemo_ctl      : initialisation of the contol print
+   !!   nemo_closefile: close remaining open files
+   !!   nemo_alloc    : dynamical allocation
+   !!   nemo_partition: calculate MPP domain decomposition
+   !!   factorise     : calculate the factors of the no. of MPI processes
+   !!   nemo_nfdcom   : Setup for north fold exchanges with explicit point-to-point messaging
+   !!   istate_init   : simple initialization to zero of ocean fields
+   !!   stp_ctl       : reduced step control (no dynamics in off-line)
    !!----------------------------------------------------------------------
-   USE dom_oce         ! ocean space domain variables
-   USE oce             ! dynamics and tracers variables
-   USE trc_oce         ! Shared ocean/passive tracers variables
-   USE c1d             ! 1D configuration
-   USE domain          ! domain initialization from coordinate & bathymetry (dom_init routine)
-   USE usrdef_nam      ! user defined configuration
-   USE eosbn2          ! equation of state            (eos bn2 routine)
+   USE dom_oce        ! ocean space domain variables
+   USE oce            ! dynamics and tracers variables
+   USE trc_oce        ! Shared ocean/passive tracers variables
+   USE c1d            ! 1D configuration
+   USE domain         ! domain initialization from coordinate & bathymetry (dom_init routine)
+   USE closea         ! treatment of closed seas (for ln_closea)
+   USE usrdef_nam     ! user defined configuration
+   USE eosbn2         ! equation of state            (eos bn2 routine)
    !              ! ocean physics
-   USE ldftra          ! lateral diffusivity setting    (ldf_tra_init routine)
-   USE ldfslp          ! slopes of neutral surfaces     (ldf_slp_init routine)
-   USE traqsr          ! solar radiation penetration    (tra_qsr_init routine)
-   USE trabbl          ! bottom boundary layer          (tra_bbl_init routine)
-   USE traldf          ! lateral physics                (tra_ldf_init routine)
-   USE sbcmod          ! surface boundary condition     (sbc_init     routine)
-   USE phycst          ! physical constant                   (par_cst routine)
-   USE dtadyn          ! Lecture and Interpolation of the dynamical fields
-   USE trcini          ! Initilization of the passive tracers
-   USE daymod          ! calendar                            (day     routine)
-   USE trcstp          ! passive tracer time-stepping        (trc_stp routine)
-   USE dtadyn          ! Lecture and interpolation of the dynamical fields
+   USE ldftra         ! lateral diffusivity setting    (ldf_tra_init routine)
+   USE ldfslp         ! slopes of neutral surfaces     (ldf_slp_init routine)
+   USE traqsr         ! solar radiation penetration    (tra_qsr_init routine)
+   USE trabbl         ! bottom boundary layer          (tra_bbl_init routine)
+   USE traldf         ! lateral physics                (tra_ldf_init routine)
+   USE sbcmod         ! surface boundary condition     (sbc_init     routine)
+   USE phycst         ! physical constant                   (par_cst routine)
+   USE dtadyn         ! Lecture and Interpolation of the dynamical fields
+   USE trcini         ! Initilization of the passive tracers
+   USE daymod         ! calendar                            (day     routine)
+   USE trcstp         ! passive tracer time-stepping        (trc_stp routine)
+   USE dtadyn         ! Lecture and interpolation of the dynamical fields
    !              ! Passive tracers needs
-   USE trc             ! passive tracer : variables
-   USE trcnam          ! passive tracer : namelist
-   USE trcrst          ! passive tracer restart
-   USE diaptr          ! Need to initialise this as some variables are used in if statements later
-   USE sbc_oce  , ONLY : ln_rnf
-   USE sbcrnf          ! surface boundary condition : runoffs
+   USE trc            ! passive tracer : variables
+   USE trcnam         ! passive tracer : namelist
+   USE trcrst         ! passive tracer restart
+   USE diaptr         ! Need to initialise this as some variables are used in if statements later
+   USE sbc_oce , ONLY : ln_rnf
+   USE sbcrnf         ! surface boundary condition : runoffs
    !              ! I/O & MPP
-   USE iom             ! I/O library
-   USE in_out_manager  ! I/O manager
-   USE mppini          ! shared/distributed memory setting (mpp_init routine)
-   USE lib_mpp         ! distributed memory computing
+   USE iom            ! I/O library
+   USE in_out_manager ! I/O manager
+   USE mppini         ! shared/distributed memory setting (mpp_init routine)
+   USE lib_mpp        ! distributed memory computing
 #if defined key_iomput
-   USE xios
+   USE xios           ! xIOserver
 #endif 
-   USE prtctl          ! Print control                    (prt_ctl_init routine)
-   USE timing          ! Timing
-   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
-   USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges
-
-
+   USE prtctl         ! Print control                    (prt_ctl_init routine)
+   USE timing         ! Timing
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
+   USE lbcnfd  , ONLY : isendto, nsndto, nfsloop, nfeloop   ! Setup of north fold exchanges
 
    IMPLICIT NONE
@@ -65,5 +71,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/OFF 3.3 , NEMO Consortium (2010)
+   !! NEMO/OFF 4.0 , NEMO Consortium (2018)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -75,6 +81,6 @@
       !!                     ***  ROUTINE nemo_gcm  ***
       !!
-      !! ** Purpose :   nemo solves the primitive equations on an orthogonal
-      !!      curvilinear mesh on the sphere.
+      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
+      !!              curvilinear mesh on the sphere.
       !!
       !! ** Method  : - model general initialization
@@ -99,10 +105,9 @@
       istp = nit000
       !
-      ! Initialize arrays of runoffs structures and read data from the namelist
-      IF ( ln_rnf ) CALL sbc_rnf(istp)
+      IF( ln_rnf )   CALL sbc_rnf(istp)   ! runoffs initialization 
       ! 
-      CALL iom_init( cxios_context )            ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
+      CALL iom_init( cxios_context )      ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
       ! 
-      DO WHILE ( istp <= nitend .AND. nstop == 0 )    ! time stepping
+      DO WHILE ( istp <= nitend .AND. nstop == 0 )    !==  OFF time-stepping  ==!
          !
          IF( istp /= nit000 )   CALL day        ( istp )         ! Calendar (day was already called at nit000 in day_init)
@@ -114,6 +119,6 @@
                                 CALL stp_ctl    ( istp, indic )  ! Time loop: control and print
          istp = istp + 1
-         IF( lk_mpp )   CALL mpp_max( nstop )
       END DO
+      !
 #if defined key_iomput
       CALL iom_context_finalize( cxios_context ) ! needed for XIOS+AGRIF
@@ -127,5 +132,6 @@
       IF( nstop /= 0 .AND. lwp ) THEN                 ! error print
          WRITE(numout,cform_err)
-         WRITE(numout,*) nstop, ' error have been found'
+         WRITE(numout,*) '   ==>>>   nemo_gcm: a total of ', nstop, ' errors have been found'
+         WRITE(numout,*)
       ENDIF
       !
@@ -134,9 +140,9 @@
       CALL nemo_closefile
       !
-# if defined key_iomput
-      CALL xios_finalize             ! end mpp communications
-# else
-      IF( lk_mpp )   CALL mppstop       ! end mpp communications
-# endif
+#if defined key_iomput
+                     CALL xios_finalize   ! end mpp communications with xios
+#else
+      IF( lk_mpp )   CALL mppstop         ! end mpp communications
+#endif
       !
    END SUBROUTINE nemo_gcm
@@ -145,22 +151,20 @@
    SUBROUTINE nemo_init
       !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE nemo_init ***
+      !!                     ***  ROUTINE nemo_init  ***
       !!
       !! ** Purpose :   initialization of the nemo model in off-line mode
       !!----------------------------------------------------------------------
       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
+      INTEGER  ::   ios, ilocal_comm   ! local integers
+      INTEGER  ::   iiarea, ijarea     !   -       -
+      INTEGER  ::   iirest, ijrest     !   -       -
       CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
       !!
-      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
-         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
+      NAMELIST/namctl/ ln_ctl   , nn_print, nn_ictls, nn_ictle,   &
+         &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,   &
          &             ln_timing, ln_diacfl
-
-      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_write_cfg, cn_domcfg_out, ln_use_jattr
-      !!----------------------------------------------------------------------
+      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_closea, ln_write_cfg, cn_domcfg_out, ln_use_jattr
+      !!----------------------------------------------------------------------
+      !
       cltxt  = ''
       cltxt2 = ''
@@ -172,23 +176,21 @@
       CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
       !
-      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints & Benchmark
+      REWIND( numnam_ref )              ! Namelist namctl in reference namelist
       READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
 901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
-      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints & Benchmark
+      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
       READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
 902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
-
-      !
-      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints & Benchmark
+      !
+      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist
       READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
 903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
-      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
+      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist
       READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
 904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
 
-
       !                             !--------------------------!
       !                             !  Set global domain size  !   (control print return in cltxt2)
-      !
+      !                             !--------------------------!
       IF( ln_read_cfg ) THEN              ! Read sizes in domain configuration file
          CALL domain_cfg ( cltxt2,        cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
@@ -198,6 +200,5 @@
       ENDIF
       !
-      !
-      l_offline = .true.            !  passive tracers are run offline
+      l_offline = .true.                  ! passive tracers are run offline
       !
       !                             !--------------------------------------------!
@@ -219,13 +220,12 @@
       lwp = (narea == 1) .OR. ln_ctl          ! control of all listing output print
 
-      IF(lwm) THEN
-         ! write merged namelists from earlier to output namelist now that the
-         ! file has been opened in call to mynode. nammpp has already been
-         ! written in mynode (if lk_mpp_mpi)
+      IF(lwm) THEN               ! write merged namelists from earlier to output namelist 
+         !                       ! now that the file has been opened in call to mynode. 
+         !                       ! NB: nammpp has already been written in mynode (if lk_mpp_mpi)
          WRITE( numond, namctl )
          WRITE( numond, namcfg )
          IF( .NOT.ln_read_cfg ) THEN
             DO ji = 1, SIZE(clnam)
-               IF( TRIM(clnam (ji)) /= '' )   WRITE(numond, * ) clnam(ji)    ! namusr_def print
+               IF( TRIM(clnam(ji)) /= '' )   WRITE(numond, * ) clnam(ji)     ! namusr_def print
             END DO
          ENDIF
@@ -234,13 +234,13 @@
       ! If dimensions of processor grid weren't specified in the namelist file 
       ! then we calculate them here now that we have our communicator size
-      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
+      IF( jpni < 1  .OR.  jpnj < 1 ) THEN
 #if   defined key_mpp_mpi
-         CALL nemo_partition(mppsize)
+         CALL nemo_partition( mppsize )
 #else
-         jpni = 1
-         jpnj = 1
+         jpni  = 1
+         jpnj  = 1
          jpnij = jpni*jpnj
 #endif
-      END IF
+      ENDIF
 
       iiarea = 1 + MOD( narea - 1 , jpni )
@@ -279,56 +279,57 @@
          WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
          WRITE(numout,*) '                       NEMO team'
-         WRITE(numout,*) '            Ocean General Circulation Model'
-         WRITE(numout,*) '                  version 3.6  (2015) '
-         WRITE(numout,*)
-         WRITE(numout,*)
-         DO ji = 1, SIZE(cltxt) 
-            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
+         WRITE(numout,*) '                   Off-line TOP Model'
+         WRITE(numout,*) '                NEMO version 4.0  (2017) '
+         WRITE(numout,*)
+         WRITE(numout,*)
+         DO ji = 1, SIZE(cltxt)
+            IF( TRIM(cltxt (ji)) /= '' )   WRITE(numout,*) cltxt(ji)    ! control print of mynode
          END DO
-         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
-         !
-      ENDIF
-
-      ! Now we know the dimensions of the grid and numout has been set we can 
-      ! allocate arrays
+         WRITE(numout,*)
+         WRITE(numout,*)
+         DO ji = 1, SIZE(cltxt2)
+            IF( TRIM(cltxt2(ji)) /= '' )   WRITE(numout,*) cltxt2(ji)   ! control print of domain size
+         END DO
+         !
+         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
+         !
+      ENDIF
+
+      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
       CALL nemo_alloc()
 
-      !                             !--------------------------------!
-      !                             !  Model general initialization  !
-      !                             !--------------------------------!
-
-      CALL nemo_ctl                           ! Control prints & Benchmark
+      !                             !-------------------------------!
+      !                             !  NEMO general initialization  !
+      !                             !-------------------------------!
+
+      CALL nemo_ctl                          ! Control prints
 
       !                                      ! Domain decomposition
-      CALL mpp_init
-      !
+      CALL mpp_init                             ! MPP
+      IF( ln_nnogather )   CALL nemo_nfdcom     ! northfold neighbour lists
+      !
+      !                                      ! General initialization
       IF( ln_timing    )   CALL timing_init
-      !
-
-      !                                      ! General initialization
       IF( ln_timing    )   CALL timing_start( 'nemo_init')
       !
-                           CALL     phy_cst    ! Physical constants
-                           CALL     eos_init   ! Equation of state
-      IF( lk_c1d       )   CALL     c1d_init   ! 1D column configuration
-
-                           CALL     dom_init   ! Domain
-
-                           CALL  istate_init   ! ocean initial state (Dynamics and tracers)
-
-      IF( ln_nnogather )   CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
-
-      IF( ln_ctl       )   CALL prt_ctl_init   ! Print control
-
-                           CALL     sbc_init   ! Forcings : surface module
-
-                           CALL ldf_tra_init   ! Lateral ocean tracer physics
-                           CALL ldf_eiv_init   ! Eddy induced velocity param
-                           CALL tra_ldf_init   ! lateral mixing
-      IF( l_ldfslp     )   CALL ldf_slp_init   ! slope of lateral mixing
-
-                           CALL tra_qsr_init   ! penetrative solar radiation qsr
-      IF( ln_trabbl    )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
-
+                           CALL     phy_cst     ! Physical constants
+                           CALL     eos_init    ! Equation of state
+      IF( lk_c1d       )   CALL     c1d_init    ! 1D column configuration
+                           CALL     dom_init    ! Domain
+      IF( ln_ctl       )   CALL prt_ctl_init    ! Print control
+
+                           CALL  istate_init    ! ocean initial state (Dynamics and tracers)
+
+                           CALL     sbc_init    ! Forcings : surface module
+
+      !                                      ! Tracer physics
+                           CALL ldf_tra_init    ! Lateral ocean tracer physics
+                           CALL ldf_eiv_init    ! Eddy induced velocity param
+                           CALL tra_ldf_init    ! lateral mixing
+      IF( l_ldfslp     )   CALL ldf_slp_init    ! slope of lateral mixing
+                           CALL tra_qsr_init    ! penetrative solar radiation qsr
+      IF( ln_trabbl    )   CALL tra_bbl_init    ! advective (and/or diffusive) bottom boundary layer scheme
+
+      !                                      ! Passive tracers
                            CALL trc_nam_run    ! Needed to get restart parameters for passive tracers
                            CALL trc_rst_cal( nit000, 'READ' )   ! calendar
@@ -336,6 +337,6 @@
 
                            CALL     trc_init   ! Passive tracers initialization
-                           CALL dia_ptr_init   ! Initialise diaptr as some variables are used 
-      !                                         ! in various advection and diffusion routines
+                           CALL dia_ptr_init   ! Poleward TRansports initialization
+                           
       IF(lwp) WRITE(numout,cform_aaa)           ! Flag AAAAAAA
       !
@@ -357,5 +358,5 @@
          WRITE(numout,*)
          WRITE(numout,*) 'nemo_ctl: Control prints'
-         WRITE(numout,*) '~~~~~~~ '
+         WRITE(numout,*) '~~~~~~~~'
          WRITE(numout,*) '   Namelist namctl'
          WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
@@ -381,14 +382,14 @@
       IF(lwp) THEN                  ! control print
          WRITE(numout,*)
-         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
-         WRITE(numout,*) '~~~~~~~ '
          WRITE(numout,*) '   Namelist namcfg'
-         WRITE(numout,*) '      read domain configuration files             ln_read_cfg      = ', ln_read_cfg
+         WRITE(numout,*) '      read domain configuration file              ln_read_cfg      = ', ln_read_cfg
          WRITE(numout,*) '         filename to be read                         cn_domcfg     = ', TRIM(cn_domcfg)
-         WRITE(numout,*) '      write  configuration definition files       ln_write_cfg     = ', ln_write_cfg
+         WRITE(numout,*) '         keep closed seas in the domain (if exist)   ln_closea     = ', TRIM(cn_domcfg)
+         WRITE(numout,*) '      create a configuration definition file      ln_write_cfg     = ', ln_write_cfg
          WRITE(numout,*) '         filename to be written                      cn_domcfg_out = ', TRIM(cn_domcfg_out)
          WRITE(numout,*) '      use file attribute if exists as i/p j-start ln_use_jattr     = ', ln_use_jattr
       ENDIF
-
+      IF( .NOT.ln_read_cfg )   ln_closea = .false.   ! dealing possible only with a domcfg file
+      !
       !                             ! Parameter control
       !
@@ -430,7 +431,6 @@
       ENDIF
       !
-      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
-         &                                               'f2003 standard. '                              ,  &
-         &                                               'Compile with key_nosignedzero enabled' )
+      IF( 1._wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows f2003 standard.',  &
+         &                                                'Compile with key_nosignedzero enabled' )
       !
    END SUBROUTINE nemo_ctl
@@ -444,5 +444,5 @@
       !!----------------------------------------------------------------------
       !
-      IF ( lk_mpp ) CALL mppsync
+      IF( lk_mpp )   CALL mppsync
       !
       CALL iom_close                                 ! close all input/output files managed by iom_*
@@ -453,5 +453,5 @@
       IF( numout     /=  6 )   CLOSE( numout     )   ! standard model output file
       IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
-
+      !
       numout = 6                                     ! redefine numout in case it is used after this point...
       !
@@ -467,18 +467,17 @@
       !! ** Method  :
       !!----------------------------------------------------------------------
-      USE diawri,       ONLY: dia_wri_alloc
-      USE dom_oce,      ONLY: dom_oce_alloc
-      USE zdf_oce,      ONLY: zdf_oce_alloc
-      USE trc_oce,      ONLY: trc_oce_alloc
+      USE diawri ,   ONLY : dia_wri_alloc
+      USE dom_oce,   ONLY : dom_oce_alloc
+      USE zdf_oce,   ONLY : zdf_oce_alloc
+      USE trc_oce,   ONLY : trc_oce_alloc
       !
       INTEGER :: ierr
       !!----------------------------------------------------------------------
       !
-      ierr =        oce_alloc       ()          ! ocean 
-      ierr = ierr + dia_wri_alloc   ()
-      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
-      ierr = ierr + zdf_oce_alloc   ()          ! ocean vertical physics
-      !
-      ierr = ierr + trc_oce_alloc   ()          ! shared TRC / TRA arrays
+      ierr =        oce_alloc    ()          ! ocean 
+      ierr = ierr + dia_wri_alloc()
+      ierr = ierr + dom_oce_alloc()          ! ocean domain
+      ierr = ierr + zdf_oce_alloc()          ! ocean vertical physics
+      ierr = ierr + trc_oce_alloc()          ! shared TRC / TRA arrays
       !
       IF( lk_mpp    )   CALL mpp_sum( ierr )
@@ -496,5 +495,5 @@
       !! ** Method  :
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
+      INTEGER, INTENT(in) ::   num_pes   ! The number of MPI processes we have
       !
       INTEGER, PARAMETER :: nfactmax = 20
@@ -505,9 +504,9 @@
       INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
       !!----------------------------------------------------------------------
-
+      !
       ierr = 0
-
+      !
       CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
-
+      !
       IF( nfact <= 1 ) THEN
          WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
@@ -540,5 +539,5 @@
       !!
       !! ** Purpose :   return the prime factors of n.
-      !!                knfax factors are returned in array kfax which is of 
+      !!                knfax factors are returned in array kfax which is of
       !!                maximum dimension kmaxfax.
       !! ** Method  :
@@ -550,32 +549,32 @@
       INTEGER :: ifac, jl, inu
       INTEGER, PARAMETER :: ntest = 14
-      INTEGER :: ilfax(ntest)
+      INTEGER, DIMENSION(ntest) ::   ilfax
+      !!----------------------------------------------------------------------
       !
       ! lfax contains the set of allowed factors.
       ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
-
+      !
       ! Clear the error flag and initialise output vars
-      kerr = 0
-      kfax = 1
+      kerr  = 0
+      kfax  = 1
       knfax = 0
-
-      ! Find the factors of n.
-      IF( kn .NE. 1 ) THEN
-
+      !
+      IF( kn /= 1 ) THEN      ! Find the factors of n
+         !
          ! nu holds the unfactorised part of the number.
          ! knfax holds the number of factors found.
          ! l points to the allowed factor list.
          ! ifac holds the current factor.
-   
+         !
          inu   = kn
          knfax = 0
-   
+         !
          DO jl = ntest, 1, -1
             !
             ifac = ilfax(jl)
             IF( ifac > inu )   CYCLE
-   
+            !
             ! Test whether the factor will divide.
-   
+            !
             IF( MOD(inu,ifac) == 0 ) THEN
                !
@@ -594,5 +593,5 @@
             !
          END DO
-   
+         !
       ENDIF
       !
@@ -600,78 +599,71 @@
 
 #if defined key_mpp_mpi
-   SUBROUTINE nemo_northcomms
-      !!======================================================================
-      !!                     ***  ROUTINE  nemo_northcomms  ***
-      !! nemo_northcomms    :  Setup for north fold exchanges with explicit 
-      !!                       point-to-point messaging
-      !!=====================================================================
-      !!----------------------------------------------------------------------
-      !!
-      !! ** Purpose :   Initialization of the northern neighbours lists.
+
+   SUBROUTINE nemo_nfdcom
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE  nemo_nfdcom  ***
+      !! ** Purpose :   Setup for north fold exchanges with explicit 
+      !!                point-to-point messaging
+      !!
+      !! ** Method :   Initialization of the northern neighbours lists.
       !!----------------------------------------------------------------------
       !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
-      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S.
-      !Mocavero, CMCC) 
-      !!----------------------------------------------------------------------
-
+      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC) 
+      !!----------------------------------------------------------------------
       INTEGER  ::   sxM, dxM, sxT, dxT, jn
       INTEGER  ::   njmppmax
-
+      !!----------------------------------------------------------------------
+      !
       njmppmax = MAXVAL( njmppt )
-
+      !
       !initializes the north-fold communication variables
       isendto(:) = 0
-      nsndto = 0
-
-      !if I am a process in the north
-      IF ( njmpp == njmppmax ) THEN
-          !sxM is the first point (in the global domain) needed to compute the
-          !north-fold for the current process
-          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
-          !dxM is the last point (in the global domain) needed to compute the
-          !north-fold for the current process
-          dxM = jpiglo - nimppt(narea) + 2
-
-          !loop over the other north-fold processes to find the processes
-          !managing the points belonging to the sxT-dxT range
-
-          DO jn = 1, jpni
-                !sxT is the first point (in the global domain) of the jn
-                !process
-                sxT = nfiimpp(jn, jpnj)
-                !dxT is the last point (in the global domain) of the jn
-                !process
-                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
-                IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
-                   nsndto = nsndto + 1
-                     isendto(nsndto) = jn
-                ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
-                   nsndto = nsndto + 1
-                     isendto(nsndto) = jn
-                ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
-                   nsndto = nsndto + 1
-                     isendto(nsndto) = jn
-                END IF
-          END DO
-          nfsloop = 1
-          nfeloop = nlci
-          DO jn = 2,jpni-1
-           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
-              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
-                 nfsloop = nldi
-              ENDIF
-              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
-                 nfeloop = nlei
-              ENDIF
-           ENDIF
-        END DO
-
+      nsndto     = 0
+      !
+      IF ( njmpp == njmppmax ) THEN      ! if I am a process in the north
+         !
+         !sxM is the first point (in the global domain) needed to compute the north-fold for the current process
+         sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
+         !dxM is the last point (in the global domain) needed to compute the north-fold for the current process
+         dxM = jpiglo - nimppt(narea) + 2
+         !
+         ! loop over the other north-fold processes to find the processes
+         ! managing the points belonging to the sxT-dxT range
+         !
+         DO jn = 1, jpni
+            !
+            sxT = nfiimpp(jn, jpnj)                            ! sxT = 1st  point (in the global domain) of the jn process
+            dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1    ! dxT = last point (in the global domain) of the jn process
+            !
+            IF    ( sxT < sxM  .AND.  sxM < dxT ) THEN
+               nsndto          = nsndto + 1
+               isendto(nsndto) = jn
+            ELSEIF( sxM <= sxT  .AND.  dxM >= dxT ) THEN
+               nsndto          = nsndto + 1
+               isendto(nsndto) = jn
+            ELSEIF( dxM <  dxT  .AND.  sxT <  dxM ) THEN
+               nsndto          = nsndto + 1
+               isendto(nsndto) = jn
+            ENDIF
+            !
+         END DO
+         nfsloop = 1
+         nfeloop = nlci
+         DO jn = 2,jpni-1
+            IF( nfipproc(jn,jpnj) == (narea - 1) ) THEN
+               IF( nfipproc(jn-1,jpnj) == -1 )   nfsloop = nldi
+               IF( nfipproc(jn+1,jpnj) == -1 )   nfeloop = nlei
+            ENDIF
+         END DO
+         !
       ENDIF
       l_north_nogather = .TRUE.
-   END SUBROUTINE nemo_northcomms
+      !
+   END SUBROUTINE nemo_nfdcom
+
 #else
-   SUBROUTINE nemo_northcomms      ! Dummy routine
-      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
-   END SUBROUTINE nemo_northcomms
+   SUBROUTINE nemo_nfdcom      ! Dummy routine
+      WRITE(*,*) 'nemo_nfdcom: You should not have seen this print! error?'
+   END SUBROUTINE nemo_nfdcom
 #endif
 
@@ -696,4 +688,5 @@
    END SUBROUTINE istate_init
 
+
    SUBROUTINE stp_ctl( kt, kindic )
       !!----------------------------------------------------------------------
@@ -722,4 +715,5 @@
       !
    END SUBROUTINE stp_ctl
+
    !!======================================================================
 END MODULE nemogcm
