Index: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90
===================================================================
--- branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90	(revision 5063)
+++ branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90	(revision 5600)
@@ -53,14 +53,10 @@
    USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
    USE step            ! NEMO time-stepping                 (stp     routine)
-#if defined key_oasis3
    USE cpl_oasis3      ! OASIS3 coupling
-#elif defined key_oasis4
-   USE cpl_oasis4      ! OASIS4 coupling (not working)
-#endif
    USE lib_mpp         ! distributed memory computing
 #if defined key_iomput
    USE xios
 #endif
-   USE lbcnfd, ONLY: isendto, nsndto ! Setup of north fold exchanges 
+   USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges 
 
    ! Stand Alone Observation operator modules
@@ -124,13 +120,14 @@
       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
+         &             jpizoom, jpjzoom, jperio, ln_use_jattr
       !!----------------------------------------------------------------------
       !
       cltxt = ''
+      cxios_context = 'nemo'
       !
       !                             ! Open reference namelist and configuration namelist files
@@ -168,4 +165,5 @@
       nperio  = 0
       jperio  = 0
+      ln_use_jattr = .false.
    ENDIF
 #endif
@@ -178,22 +176,25 @@
 #if defined key_iomput
       IF( Agrif_Root() ) THEN
-# if defined key_oasis3 || defined key_oasis4
-         CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
-         CALL xios_initialize( "oceanx",local_comm=ilocal_comm )
-# else
-         CALL  xios_initialize( "nemo",return_comm=ilocal_comm )
-# endif
-      ENDIF
-      narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection
+         IF( lk_oasis ) THEN
+            CALL cpl_init( "oceanx", ilocal_comm )                     ! nemo local communicator given by oasis
+            CALL xios_initialize( "not used",local_comm=ilocal_comm )    ! send nemo communicator to xios
+         ELSE
+            CALL  xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )    ! nemo local communicator given by xios
+         ENDIF
+      ENDIF
+      ! Nodes selection (control print return in cltxt)
+      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
 #else
-# if defined key_oasis3 || defined key_oasis4
-      IF( Agrif_Root() ) THEN
-         CALL cpl_prism_init( ilocal_comm )                 ! nemo local communicator given by oasis
-      ENDIF
-      narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection (control print return in cltxt)
-# else
-      ilocal_comm = 0
-      narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop )                 ! Nodes selection (control print return in cltxt)
-# endif
+      IF( lk_oasis ) THEN
+         IF( Agrif_Root() ) THEN
+            CALL cpl_init( "oceanx", ilocal_comm )                      ! nemo local communicator given by oasis
+         ENDIF
+         ! Nodes selection (control print return in cltxt)
+         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
+      ELSE
+         ilocal_comm = 0
+         ! Nodes selection (control print return in cltxt)
+         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )
+      ENDIF
 #endif
       narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
@@ -340,4 +341,5 @@
          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
       ENDIF
       !                             ! Parameter control
@@ -467,9 +469,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'
@@ -513,5 +515,5 @@
       INTEGER, PARAMETER :: ntest = 14
       INTEGER :: ilfax(ntest)
-
+      !
       ! lfax contains the set of allowed factors.
       data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
@@ -564,4 +566,5 @@
 
 #if defined key_mpp_mpi
+
    SUBROUTINE nemo_northcomms
       !!======================================================================
@@ -598,24 +601,36 @@
           !loop over the other north-fold processes to find the processes
           !managing the points belonging to the sxT-dxT range
-          DO jn = jpnij - jpni +1, jpnij
-             IF ( njmppt(jn) == njmppmax ) THEN
+  
+          DO jn = 1, jpni
                 !sxT is the first point (in the global domain) of the jn
                 !process
-                sxT = nimppt(jn)
+                sxT = nfiimpp(jn, jpnj)
                 !dxT is the last point (in the global domain) of the jn
                 !process
-                dxT = nimppt(jn) + nlcit(jn) - 1
+                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
                 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
+                     isendto(nsndto) = jn
                 END IF
-             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
+
       ENDIF
       l_north_nogather = .TRUE.
@@ -626,4 +641,5 @@
    END SUBROUTINE nemo_northcomms
 #endif
+
    !!======================================================================
 END MODULE nemogcm
