Index: trunk/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90
===================================================================
--- trunk/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90	(revision 6140)
+++ trunk/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90	(revision 7646)
@@ -4,63 +4,38 @@
    !! Ocean system   : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
    !!======================================================================
-   !! History :  OPA  ! 1990-10  (C. Levy, G. Madec)  Original code
-   !!            7.0  ! 1991-11  (M. Imbard, C. Levy, G. Madec)
-   !!            7.1  ! 1993-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
-   !!                             P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes) release 7.1
-   !!             -   ! 1992-06  (L.Terray)  coupling implementation
-   !!             -   ! 1993-11  (M.A. Filiberti) IGLOO sea-ice
-   !!            8.0  ! 1996-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
-   !!                             P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy) release 8.0
-   !!            8.1  ! 1997-06  (M. Imbard, G. Madec)
-   !!            8.2  ! 1999-11  (M. Imbard, H. Goosse)  LIM sea-ice model
-   !!                 ! 1999-12  (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols)  OPEN-MP
-   !!                 ! 2000-07  (J-M Molines, M. Imbard)  Open Boundary Conditions  (CLIPPER)
-   !!   NEMO     1.0  ! 2002-08  (G. Madec)  F90: Free form and modules
-   !!             -   ! 2004-06  (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
-   !!             -   ! 2004-08  (C. Talandier) New trends organization
-   !!             -   ! 2005-06  (C. Ethe) Add the 1D configuration possibility
-   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
-   !!             -   ! 2006-03  (L. Debreu, C. Mazauric)  Agrif implementation
-   !!             -   ! 2006-04  (G. Madec, R. Benshila)  Step reorganization
-   !!             -   ! 2007-07  (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
-   !!            3.2  ! 2009-08  (S. Masson)  open/write in the listing file in mpp
-   !!            3.3  ! 2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
-   !!             -   ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
-   !!            3.3.1! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
-   !!            3.4  ! 2011-11  (C. Harris) decomposition changes for running with CICE
-   !!                 ! 2012-05  (C. Calone, J. Simeon, G. Madec, C. Ethe) Add grid coarsening 
+   !! History :  3.6  ! 2015-12  (A. Ryan) Original code   (from OPA_SRC/) 
+   !!            4.0  ! 2016-11  (G. Madec, S. Flavoni)  domain configuration / user defined interface
    !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
-   !!   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_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
    !!----------------------------------------------------------------------
-   USE step_oce        ! module used in the ocean time stepping module
-   USE domcfg          ! domain configuration               (dom_cfg routine)
-   USE mppini          ! shared/distributed memory setting (mpp_init routine)
-   USE domain          ! domain initialization             (dom_init routine)
+   USE step_oce       ! module used in the ocean time stepping module (step.F90)
+   USE domain         ! domain initialization   (dom_init & dom_cfg routines)
+   USE istate         ! initial state setting          (istate_init routine)
+   USE phycst         ! physical constant                  (par_cst routine)
+   USE step           ! NEMO time-stepping                 (stp     routine)
+   USE cpl_oasis3     ! OASIS3 coupling
+   USE diaobs         ! Observation diagnostics       (dia_obs_init routine)
 #if defined key_nemocice_decomp
    USE ice_domain_size, only: nx_global, ny_global
 #endif
-   USE istate          ! initial state setting          (istate_init routine)
-   USE phycst          ! physical constant                  (par_cst routine)
-   USE diaobs          ! Observation diagnostics       (dia_obs_init routine)
-   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
-   USE step            ! NEMO time-stepping                 (stp     routine)
-   USE cpl_oasis3      ! OASIS3 coupling
-   USE lib_mpp         ! distributed memory computing
-#if defined key_iomput
-   USE xios
-#endif
-   USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges 
-
-   ! Stand Alone Observation operator modules
+   !           ! Stand Alone Observation operator modules
    USE sao_data
    USE sao_intp
+   !
+   USE lib_mpp        ! distributed memory computing
+   USE mppini         ! shared/distributed memory setting (mpp_init routine)
+   USE lbcnfd  , ONLY : isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges 
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
+#if defined key_iomput
+   USE xios           ! xIOserver
+#endif
 
    IMPLICIT NONE
@@ -74,5 +49,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2016)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -91,20 +66,20 @@
          !!             3. Cycle through match ups
          !!             4. Write results to file
-         !!
          !!----------------------------------------------------------------------
-         !! Initialise NEMO
-         CALL nemo_init
-         !! Initialise Stand Alone Observation operator data
-         CALL sao_data_init
-         !! Initialise obs_oper
-         CALL dia_obs_init
-         !! Interpolate to observation space
-         CALL sao_interp
-         !! Pipe to output files
-         CALL dia_obs_wri
-         !! Reset the obs_oper between
-         CALL dia_obs_dealloc
-         !! Safely stop MPI
-         IF(lk_mpp) CALL mppstop  ! end mpp communications
+         !
+         CALL nemo_init       ! Initialise NEMO
+         !
+         CALL sao_data_init   ! Initialise Stand Alone Observation operator data
+         !
+         CALL dia_obs_init    ! Initialise obs_operator
+         !
+         CALL sao_interp      ! Interpolate to observation space
+         !
+         CALL dia_obs_wri     ! Pipe to output files
+         !
+         CALL dia_obs_dealloc ! Reset the obs_oper between
+         !
+         IF(lk_mpp)   CALL mppstop  ! Safely stop MPI (end mpp communications)
+         !
    END SUBROUTINE nemo_gcm
 
@@ -116,17 +91,17 @@
       !! ** Purpose :   initialization of the NEMO GCM
       !!----------------------------------------------------------------------
-      INTEGER ::   ji            ! dummy loop indices
-      INTEGER ::   ilocal_comm   ! local integer
-      INTEGER ::   ios
-      CHARACTER(len=80), DIMENSION(16) ::   cltxt
-      !
-      NAMELIST/namctl/ ln_ctl, nn_print, nn_ictls, nn_ictle,   &
-         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
-         &             nn_bench, nn_timing
-      NAMELIST/namcfg/ cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
-         &             jpizoom, jpjzoom, jperio, ln_use_jattr
-      !!----------------------------------------------------------------------
-      !
-      cltxt = ''
+      INTEGER ::   ji                 ! dummy loop indices
+      INTEGER ::   ios, ilocal_comm   ! local integer
+      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,   &
+         &             nn_timing, nn_diacfl
+      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_write_cfg, cn_domcfg_out, ln_use_jattr
+      !!----------------------------------------------------------------------
+      !
+      cltxt  = ''
+      cltxt2 = ''
+      clnam  = ''  
       cxios_context = 'nemo'
       !
@@ -135,14 +110,13 @@
       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 : Control prints
       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 : Control prints
       READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
 903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
@@ -152,19 +126,26 @@
 904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
 
-! Force values for AGRIF zoom (cf. agrif_user.F90)
+      !                             !--------------------------!
+      !                             !  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 )
+         !
+      ELSE                                ! user-defined namelist
+         CALL usr_def_nam( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
+      ENDIF
+      !
+      jpk = jpkglo
+      !
 #if defined key_agrif
-   IF( .NOT. Agrif_Root() ) THEN
-      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
-      jpidta  = jpiglo
-      jpjdta  = jpjglo
-      jpizoom = 1
-      jpjzoom = 1
-      nperio  = 0
-      jperio  = 0
-      ln_use_jattr = .false.
-   ENDIF
+      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
       !
@@ -198,4 +179,5 @@
       ENDIF
 #endif
+
       narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
 
@@ -209,11 +191,16 @@
          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
+            END DO
+         ENDIF
       ENDIF
 
       ! 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
-         IF( Agrif_Root() ) CALL nemo_partition(mppsize)
+         IF( Agrif_Root() )   CALL nemo_partition( mppsize )
 #else
          jpni  = 1
@@ -221,23 +208,23 @@
          jpnij = jpni*jpnj
 #endif
-      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
-      IF( Agrif_Root() ) THEN
+      ENDIF
+
+      IF( Agrif_Root() ) THEN       ! AGRIF mother: specific setting from jpni and 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*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
+         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim. 
 #else
-         jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
-         jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
+         jpi = ( jpiglo     -2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
+         jpj = ( jpjglo     -2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim.
 #endif
       ENDIF
-         jpk = jpkdta                                             ! third dim
-         jpim1 = jpi-1                                            ! inner domain indices
-         jpjm1 = jpj-1                                            !   "           "
-         jpkm1 = jpk-1                                            !   "           "
-         jpij  = jpi*jpj                                          !  jpi x j
+
+!!gm ???    why here  it has already been done in line 301 !
+      jpk = jpkglo                                             ! third dim
+!!gm end
+      jpim1 = jpi-1                                            ! inner domain indices
+      jpjm1 = jpj-1                                            !   "           "
+      jpkm1 = jpk-1                                            !   "           "
+      jpij  = jpi*jpj                                          !  jpi x j
 
       IF(lwp) THEN                            ! open listing units
@@ -249,16 +236,21 @@
          WRITE(numout,*) '                       NEMO team'
          WRITE(numout,*) '            Stand Alone Observation operator'
-         WRITE(numout,*) '                  version 1.0  (2015) '
+         WRITE(numout,*) '                NEMO version 3.7  (2015) '
          WRITE(numout,*)
          WRITE(numout,*)
          DO ji = 1, SIZE(cltxt)
-            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
+            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()
 
@@ -279,5 +271,4 @@
                             CALL     phy_cst    ! Physical constants
                             CALL     eos_init   ! Equation of state
-                            CALL     dom_cfg    ! Domain configuration
                             CALL     dom_init   ! Domain
 
@@ -301,5 +292,5 @@
       IF(lwp) THEN                  ! control print
          WRITE(numout,*)
-         WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
+         WRITE(numout,*) 'nemo_ctl: Control prints'
          WRITE(numout,*) '~~~~~~~ '
          WRITE(numout,*) '   Namelist namctl'
@@ -312,5 +303,4 @@
          WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
          WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
-         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
          WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
       ENDIF
@@ -323,5 +313,4 @@
       isplt     = nn_isplt
       jsplt     = nn_jsplt
-      nbench    = nn_bench
 
       IF(lwp) THEN                  ! control print
@@ -330,16 +319,9 @@
          WRITE(numout,*) '~~~~~~~ '
          WRITE(numout,*) '   Namelist namcfg'
-         WRITE(numout,*) '      configuration name              cp_cfg      = ', TRIM(cp_cfg)
-         WRITE(numout,*) '      configuration zoom name         cp_cfz      = ', TRIM(cp_cfz)
-         WRITE(numout,*) '      configuration resolution        jp_cfg      = ', jp_cfg
-         WRITE(numout,*) '      1st lateral dimension ( >= jpi ) jpidta     = ', jpidta
-         WRITE(numout,*) '      2nd    "         "    ( >= jpj ) jpjdta     = ', jpjdta
-         WRITE(numout,*) '      3nd    "         "               jpkdta     = ', jpkdta
-         WRITE(numout,*) '      1st dimension of global domain in i jpiglo  = ', jpiglo
-         WRITE(numout,*) '      2nd    -                  -    in j jpjglo  = ', jpjglo
-         WRITE(numout,*) '      left bottom i index of the zoom (in data domain) jpizoom = ', jpizoom
-         WRITE(numout,*) '      left bottom j index of the zoom (in data domain) jpizoom = ', jpjzoom
-         WRITE(numout,*) '      lateral cond. type (between 0 and 6) jperio = ', jperio   
-         WRITE(numout,*) '      use file attribute if exists as i/p j-start ln_use_jattr = ', ln_use_jattr
+         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 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
       !                             ! Parameter control
@@ -382,12 +364,4 @@
       ENDIF
       !
-      IF( nbench == 1 ) THEN              ! Benchmark
-         SELECT CASE ( cp_cfg )
-         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
-         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
-            &                                 ' cp_cfg = "gyre" in namelist &namcfg or set nbench = 0' )
-         END SELECT
-      ENDIF
-      !
       IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
          &                                               'f2003 standard. '                              ,  &
@@ -421,5 +395,4 @@
       IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
       IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
-
       !
       numout = 6                                     ! redefine numout in case it is used after this point...
@@ -460,5 +433,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
@@ -514,16 +487,15 @@
       INTEGER :: ifac, jl, inu
       INTEGER, PARAMETER :: ntest = 14
-      INTEGER :: ilfax(ntest)
+      INTEGER, DIMENSION(ntest) ::   ilfax
+      !!----------------------------------------------------------------------
       !
       ! lfax contains the set of allowed factors.
-      data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
-         &                            128,   64,   32,   16,    8,   4,   2  /
-      !!----------------------------------------------------------------------
-
+      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 == 1 )   GOTO 20
@@ -533,8 +505,8 @@
       ! l points to the allowed factor list.
       ! ifac holds the current factor.
-
+      !
       inu   = kn
       knfax = 0
-
+      !
       DO jl = ntest, 1, -1
          !
@@ -560,5 +532,5 @@
          !
       END DO
-
+      !
    20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
       !
@@ -568,26 +540,24 @@
 
    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.
+      !! ** 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) 
       !!----------------------------------------------------------------------
-
       INTEGER  ::   sxM, dxM, sxT, dxT, jn
       INTEGER  ::   njmppmax
-
+      !!----------------------------------------------------------------------
+      !
       njmppmax = MAXVAL( njmppt )
-    
+      !
       !initializes the north-fold communication variables
       isendto(:) = 0
-      nsndto = 0
-
+      nsndto     = 0
+      !
       !if I am a process in the north
       IF ( njmpp == njmppmax ) THEN
@@ -611,12 +581,12 @@
                 IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
                    nsndto = nsndto + 1
-                     isendto(nsndto) = jn
+                   isendto(nsndto) = jn
                 ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
                    nsndto = nsndto + 1
-                     isendto(nsndto) = jn
+                   isendto(nsndto) = jn
                 ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
                    nsndto = nsndto + 1
-                     isendto(nsndto) = jn
-                END IF
+                   isendto(nsndto) = jn
+                ENDIF
           END DO
           nfsloop = 1
@@ -636,4 +606,5 @@
       l_north_nogather = .TRUE.
    END SUBROUTINE nemo_northcomms
+
 #else
    SUBROUTINE nemo_northcomms      ! Dummy routine
@@ -645,3 +616,2 @@
 END MODULE nemogcm
 
-
Index: trunk/NEMOGCM/NEMO/SAO_SRC/sao_data.F90
===================================================================
--- trunk/NEMOGCM/NEMO/SAO_SRC/sao_data.F90	(revision 6140)
+++ trunk/NEMOGCM/NEMO/SAO_SRC/sao_data.F90	(revision 7646)
@@ -1,23 +1,29 @@
 MODULE sao_data
-   !! =================================================================
-   !!                    *** MODULE sao_data ***
-   !! =================================================================
+   !!======================================================================
+   !!                       ***  MODULE sao_data  ***
+   !!======================================================================
+   !! History :  3.6  ! 2015-12  (A. Ryan)  Original code
+   !!----------------------------------------------------------------------
    USE par_kind, ONLY: lc
    USE lib_mpp         ! distributed memory computing
+   USE in_out_manager
 
    IMPLICIT NONE
-
-   !! Public data
 
    INTEGER, PARAMETER :: MaxNumFiles = 1000
 
    !! Stand Alone Observation operator settings
-   CHARACTER(len=lc) :: &
-      & sao_files(MaxNumFiles)         !: model files
-   INTEGER            :: &
-      & n_files, &                     !: number of files
-      & nn_sao_idx(MaxNumFiles), &     !: time_counter indices
-      & nn_sao_freq                    !: read frequency in time steps
+   CHARACTER(len=lc) ::   sao_files(MaxNumFiles)   !: model files
+   INTEGER           ::   n_files                  !: number of files
+   INTEGER           :: nn_sao_idx(MaxNumFiles)    !: time_counter indices
+   INTEGER           :: nn_sao_freq                !: read frequency in time steps
+   
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
+   !! $Id: trazdf_imp.F90 6140 2015-12-21 11:35:23Z timgraham $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
+
    SUBROUTINE sao_data_init()
       !!----------------------------------------------------------------------
@@ -27,18 +33,16 @@
       !!
       !!----------------------------------------------------------------------
-      USE in_out_manager
-      INTEGER            :: &
-         & jf                           !: file dummy loop index
-      LOGICAL :: lmask(MaxNumFiles)     !: Logical mask used for counting
-      INTEGER :: ios
-
-      ! Standard offline obs_oper information
+      INTEGER ::   jf                   ! file dummy loop index
+      LOGICAL ::   lmask(MaxNumFiles)   ! Logical mask used for counting
+      INTEGER ::   ios
+      !!
       NAMELIST/namsao/sao_files, nn_sao_idx, nn_sao_freq
+      !!----------------------------------------------------------------------
 
       ! Standard offline obs_oper initialisation
-      n_files = 0                   !: number of files to cycle through
-      sao_files(:) = ''             !: list of files to read in
-      nn_sao_idx(:) = 0             !: list of indices inside each file
-      nn_sao_freq = -1              !: input frequency in time steps
+      n_files = 0                   ! number of files to cycle through
+      sao_files(:) = ''             ! list of files to read in
+      nn_sao_idx(:) = 0             ! list of indices inside each file
+      nn_sao_freq = -1              ! input frequency in time steps
 
       ! Standard offline obs_oper settings
@@ -46,23 +50,18 @@
       READ  ( numnam_ref, namsao, IOSTAT = ios, ERR = 901 )
 901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsao in reference namelist', .TRUE. )
-
+      !
       REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints & Benchmark
       READ  ( numnam_cfg, namsao, IOSTAT = ios, ERR = 902 )
 902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsao in configuration namelist', .TRUE. )
-
-
-      ! count input files
-      lmask(:) = .FALSE.
+     
+      lmask(:) = .FALSE.               ! count input files
       WHERE (sao_files(:) /= '') lmask(:) = .TRUE.
       n_files = COUNT(lmask)
-
-      !! Initialise sub obs window frequency
-      IF (nn_sao_freq == -1) THEN
-         !! Run length
-         nn_sao_freq = nitend - nit000 + 1
+      !
+      IF(nn_sao_freq == -1) THEN      ! Initialise sub obs window frequency
+         nn_sao_freq = nitend - nit000 + 1      ! Run length
       ENDIF
-
-      !! Print summary of settings
-      IF(lwp) THEN
+      !
+      IF(lwp) THEN                     ! Print summary of settings
          WRITE(numout,*)
          WRITE(numout,*) 'offline obs_oper : Initialization'
@@ -70,13 +69,12 @@
          WRITE(numout,*) '   Namelist namsao : set stand alone obs_oper parameters'
          DO jf = 1, n_files
-            WRITE(numout,'(1X,2A)') '   Input forecast file name          forecastfile = ', &
-               TRIM(sao_files(jf))
-            WRITE(numout,*) '   Input forecast file index        forecastindex = ', &
-               nn_sao_idx(jf)
+            WRITE(numout,'(1X,2A)') '   Input forecast file name          forecastfile = ', TRIM(sao_files(jf))
+            WRITE(numout,*) '   Input forecast file index        forecastindex = ', nn_sao_idx(jf)
          END DO
       END IF
-
+      !
    END SUBROUTINE sao_data_init
 
+   !!======================================================================
 END MODULE sao_data
 
Index: trunk/NEMOGCM/NEMO/SAO_SRC/sao_intp.F90
===================================================================
--- trunk/NEMOGCM/NEMO/SAO_SRC/sao_intp.F90	(revision 6140)
+++ trunk/NEMOGCM/NEMO/SAO_SRC/sao_intp.F90	(revision 7646)
@@ -4,8 +4,10 @@
    !! ** Purpose : Run NEMO observation operator in offline mode
    !!======================================================================
-   !! NEMO modules
+   !! History :  3.6  ! 2015-12  (A. Ryan)  Original code
+   !!----------------------------------------------------------------------
+   !        ! NEMO modules
    USE in_out_manager
    USE diaobs
-   !! Stand Alone Observation operator modules
+   !        ! Stand Alone Observation operator modules
    USE sao_read
    USE sao_data
@@ -16,33 +18,41 @@
    PUBLIC sao_interp
 
-   CONTAINS
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
+   !! $Id: trazdf_imp.F90 6140 2015-12-21 11:35:23Z timgraham $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
 
-      SUBROUTINE sao_interp
-         !!----------------------------------------------------------------------
-         !!                    ***  SUBROUTINE sao_interp ***
-         !!
-         !! ** Purpose : To interpolate the model as if it were running online.
-         !!
-         !! ** Method : 1. Populate model counterparts
-         !!             2. Call dia_obs at appropriate time steps
-         !!----------------------------------------------------------------------
-         INTEGER :: &
-            & istp, & ! time step index
-            & ifile   ! file index
-         istp = nit000 - 1
-         nstop = 0
-         ifile = 1
-         CALL sao_rea_dri(ifile)
-         DO WHILE ( istp <= nitend .AND. nstop == 0 )
-            IF (ifile <= n_files + 1) THEN
-               IF ( MOD(istp, nn_sao_freq) == nit000 ) THEN
-                  CALL sao_rea_dri(ifile)
-                  ifile = ifile + 1
-               ENDIF
-               CALL dia_obs(istp)
+   SUBROUTINE sao_interp
+      !!----------------------------------------------------------------------
+      !!                    ***  SUBROUTINE sao_interp ***
+      !!
+      !! ** Purpose : To interpolate the model as if it were running online.
+      !!
+      !! ** Method : 1. Populate model counterparts
+      !!             2. Call dia_obs at appropriate time steps
+      !!----------------------------------------------------------------------
+      INTEGER ::   istp    ! time step index
+      INTEGER ::   ifile   ! file index
+      !!----------------------------------------------------------------------
+      istp = nit000 - 1
+      nstop = 0
+      ifile = 1
+      CALL sao_rea_dri(ifile)
+      !
+      DO WHILE ( istp <= nitend .AND. nstop == 0 )
+         IF (ifile <= n_files + 1) THEN
+            IF ( MOD(istp, nn_sao_freq) == nit000 ) THEN
+               CALL sao_rea_dri(ifile)
+               ifile = ifile + 1
             ENDIF
-            istp = istp + 1
-         END DO
-      END SUBROUTINE sao_interp
+            CALL dia_obs(istp)
+         ENDIF
+         istp = istp + 1
+      END DO
+      !
+   END SUBROUTINE sao_interp
 
+   !!======================================================================
 END MODULE sao_intp
Index: trunk/NEMOGCM/NEMO/SAO_SRC/sao_read.F90
===================================================================
--- trunk/NEMOGCM/NEMO/SAO_SRC/sao_read.F90	(revision 6140)
+++ trunk/NEMOGCM/NEMO/SAO_SRC/sao_read.F90	(revision 7646)
@@ -1,7 +1,7 @@
 MODULE sao_read
-   !!==================================================================
-   !!                    *** MODULE sao_read ***
+   !!======================================================================
+   !!                      ***  MODULE sao_read  ***
    !! Read routines : I/O for Stand Alone Observation operator
-   !!==================================================================
+   !!======================================================================
    USE mppini
    USE lib_mpp
@@ -12,4 +12,5 @@
    USE dom_oce, ONLY: nlci, nlcj, nimpp, njmpp, tmask
    USE par_oce, ONLY: jpi, jpj, jpk
+   !
    USE obs_fbm, ONLY: fbimdi, fbrmdi, fbsp, fbdp
    USE sao_data
@@ -20,6 +21,12 @@
    PUBLIC sao_rea_dri
 
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
+   !! $Id: trazdf_imp.F90 6140 2015-12-21 11:35:23Z timgraham $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
 CONTAINS
-   SUBROUTINE sao_rea_dri(kfile)
+
+   SUBROUTINE sao_rea_dri( kfile )
       !!------------------------------------------------------------------------
       !!             *** sao_rea_dri ***
@@ -31,20 +38,20 @@
       !!
       !!------------------------------------------------------------------------
-      INTEGER, INTENT(IN) :: &
-              & kfile         !: File number
-      CHARACTER(len=lc) :: &
-              & cdfilename    !: File name
-      INTEGER :: &
-              & kindex        !: File index to read
-
-      cdfilename = TRIM(sao_files(kfile))
+      INTEGER, INTENT(in) ::   kfile         ! File number
+      !
+      CHARACTER(len=lc)   ::   cdfilename    ! File name
+      INTEGER ::   kindex        ! File index to read
+      !!------------------------------------------------------------------------
+      !
+      cdfilename = TRIM( sao_files(kfile) )
       kindex = nn_sao_idx(kfile)
-      CALL sao_read_file(TRIM(cdfilename), kindex)
-
+      CALL sao_read_file( TRIM( cdfilename ), kindex )
+      !
    END SUBROUTINE sao_rea_dri
 
-   SUBROUTINE sao_read_file(filename, ifcst)
+
+   SUBROUTINE sao_read_file( filename, ifcst )
       !!------------------------------------------------------------------------
-      !!             *** sao_read_file ***
+      !!                         ***  sao_read_file  ***
       !!
       !! Purpose : To fill tn and sn with dailymean field from netcdf files
@@ -54,31 +61,22 @@
       !! Author  : A. Ryan Oct 2010
       !!------------------------------------------------------------------------
-
-      INTEGER,          INTENT(IN) :: ifcst
-      CHARACTER(len=*), INTENT(IN) :: filename
-      INTEGER                      :: ncid, &
-                                    & varid,&
-                                    & istat,&
-                                    & ntimes,&
-                                    & tdim, &
-                                    & xdim, &
-                                    & ydim, &
-                                    & zdim
-      INTEGER                      :: ii, ij, ik
-      INTEGER, DIMENSION(4)        :: start_n, &
-                                    & count_n
-      INTEGER, DIMENSION(3)        :: start_s, &
-                                    & count_s
-      REAL(fbdp), DIMENSION(:,:,:),ALLOCATABLE :: temp_tn, &
-                                              & temp_sn
-      REAL(fbdp), DIMENSION(:,:),  ALLOCATABLE :: temp_sshn
-      REAL(fbdp)                     :: fill_val
+      INTEGER,          INTENT(in) ::   ifcst
+      CHARACTER(len=*), INTENT(in) ::   filename
+      INTEGER                      ::   ncid, varid, istat, ntimes
+      INTEGER                      ::   tdim, xdim, ydim, zdim
+      INTEGER                      ::   ii, ij, ik
+      INTEGER, DIMENSION(4)        ::   start_n, count_n
+      INTEGER, DIMENSION(3)        ::   start_s, count_s
+      REAL(fbdp)                   ::   fill_val
+      REAL(fbdp), DIMENSION(:,:,:), ALLOCATABLE ::   temp_tn, temp_sn
+      REAL(fbdp), DIMENSION(:,:)  , ALLOCATABLE ::   temp_sshn
 
       ! DEBUG
-      INTEGER :: istage
+      INTEGER ::   istage
+      !!------------------------------------------------------------------------
 
       IF (TRIM(filename) == 'nofile') THEN
-         tsn(:,:,:,:) = fbrmdi
-         sshn(:,:) = fbrmdi
+         tsn (:,:,:,:) = fbrmdi
+         sshn(:,:)     = fbrmdi
       ELSE
          WRITE(numout,*) "Opening :", TRIM(filename)
@@ -169,4 +167,7 @@
          istat = nf90_close(ncid)
       END IF
+      !
    END SUBROUTINE sao_read_file
+   
+   !!------------------------------------------------------------------------
 END MODULE sao_read
