Index: branches/2014/dev_r4650_UKMO10_Tidally_Meaned_Diagnostics/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- branches/2014/dev_r4650_UKMO10_Tidally_Meaned_Diagnostics/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 4756)
+++ branches/2014/dev_r4650_UKMO10_Tidally_Meaned_Diagnostics/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 5260)
@@ -42,5 +42,4 @@
    !!----------------------------------------------------------------------
    USE step_oce        ! module used in the ocean time stepping module
-   USE sbc_oce         ! surface boundary condition: ocean
    USE cla             ! cross land advection               (tra_cla routine)
    USE domcfg          ! domain configuration               (dom_cfg routine)
@@ -51,7 +50,7 @@
 #endif
    USE tideini         ! tidal components initialization   (tide_ini routine)
-   USE bdyini          ! open boundary cond. initialization (bdy_init routine)
-   USE bdydta          ! open boundary cond. initialization (bdy_dta_init routine)
-   USE bdytides        ! open boundary cond. initialization (bdytide_init routine)
+   USE bdyini          ! open boundary cond. setting       (bdy_init routine)
+   USE bdydta          ! open boundary cond. setting   (bdy_dta_init routine)
+   USE bdytides        ! open boundary cond. setting   (bdytide_init routine)
    USE istate          ! initial state setting          (istate_init routine)
    USE ldfdyn          ! lateral viscosity setting      (ldfdyn_init routine)
@@ -59,5 +58,5 @@
    USE zdfini          ! vertical physics setting          (zdf_init routine)
    USE phycst          ! physical constant                  (par_cst routine)
-   USE trdmod          ! momentum/tracers trends       (trd_mod_init routine)
+   USE trdini          ! dyn/tra trends initialization     (trd_init routine)
    USE asminc          ! assimilation increments     
    USE asmbkg          ! writing out state trajectory
@@ -69,9 +68,5 @@
    USE icbini          ! handle bergs, initialisation
    USE icbstp          ! handle bergs, calving, themodynamics and transport
-#if defined key_oasis3
    USE cpl_oasis3      ! OASIS3 coupling
-#elif defined key_oasis4
-   USE cpl_oasis4      ! OASIS4 coupling (not working)
-#endif
    USE c1d             ! 1D configuration
    USE step_c1d        ! Time stepping loop for the 1D configuration
@@ -86,5 +81,5 @@
    USE sbctide, ONLY: lk_tide
    USE crsini          ! initialise grid coarsening utility
-   USE lbcnfd, ONLY: isendto, nsndto ! Setup of north fold exchanges 
+   USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges 
    USE diatmb          ! Top,middle,bottom output
    USE dia25h          ! 25h mean output
@@ -123,5 +118,4 @@
       !!----------------------------------------------------------------------
       !
-
 #if defined key_agrif
       CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
@@ -141,5 +135,4 @@
 # endif
 #endif
-
       ! check that all process are still there... If some process have an error,
       ! they will never enter in step and other processes will wait until the end of the cpu time!
@@ -168,5 +161,4 @@
 
          DO WHILE ( istp <= nitend .AND. nstop == 0 )
-
 #if defined key_agrif
             CALL Agrif_Step( stp )           ! AGRIF: time stepping
@@ -174,5 +166,4 @@
             CALL stp( istp )                 ! standard time stepping
 #endif
-
             istp = istp + 1
             IF( lk_mpp )   CALL mpp_max( nstop )
@@ -203,15 +194,14 @@
       !
       CALL nemo_closefile
+      !
 #if defined key_iomput
       CALL xios_finalize                ! end mpp communications with xios
-# if defined key_oasis3 || defined key_oasis4
-      CALL cpl_prism_finalize           ! end coupling and mpp communications with OASIS
-# endif
+      IF( lk_cpl ) CALL cpl_finalize    ! end coupling and mpp communications with OASIS
 #else
-# if defined key_oasis3 || defined key_oasis4
-      CALL cpl_prism_finalize           ! end coupling and mpp communications with OASIS
-# else
-      IF( lk_mpp )   CALL mppstop       ! end mpp communications
-# endif
+      IF( lk_cpl ) THEN 
+         CALL cpl_finalize              ! end coupling and mpp communications with OASIS
+      ELSE
+         IF( lk_mpp )   CALL mppstop    ! end mpp communications
+      ENDIF
 #endif
       !
@@ -229,10 +219,10 @@
       INTEGER ::   ios
       CHARACTER(len=80), DIMENSION(16) ::   cltxt
-      !!
-      NAMELIST/namctl/ ln_ctl, nn_print, nn_ictls, nn_ictle,   &
+      !
+      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
       !!----------------------------------------------------------------------
       !
@@ -273,4 +263,5 @@
       nperio  = 0
       jperio  = 0
+      ln_use_jattr = .false.
    ENDIF
 #endif
@@ -283,22 +274,22 @@
 #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
+         IF( lk_cpl ) THEN
+            CALL cpl_init( ilocal_comm )                               ! nemo local communicator given by oasis
+            CALL xios_initialize( "oceanx",local_comm=ilocal_comm )    ! send nemo communicator to xios
+         ELSE
+            CALL  xios_initialize( "nemo",return_comm=ilocal_comm )    ! nemo local communicator given by xios
+         ENDIF
       ENDIF
       narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection
 #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_cpl ) THEN
+         IF( Agrif_Root() ) THEN
+            CALL cpl_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
 #endif
       narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
@@ -353,5 +344,5 @@
          WRITE(numout,*) '                       NEMO team'
          WRITE(numout,*) '            Ocean General Circulation Model'
-         WRITE(numout,*) '                  version 3.4  (2011) '
+         WRITE(numout,*) '                  version 3.6  (2015) '
          WRITE(numout,*)
          WRITE(numout,*)
@@ -395,22 +386,19 @@
       IF( lk_tide       )   CALL    tide_init( nit000 )    ! Initialisation of the tidal harmonics
 
-      IF( lk_bdy        )   CALL      bdy_init  ! Open boundaries initialisation
-      IF( lk_bdy        )   CALL  bdy_dta_init  ! Open boundaries initialisation of external data arrays
+                            CALL     sbc_init   ! Forcings : surface module (clem: moved here for bdy purpose)
+
+      IF( lk_bdy        )   CALL     bdy_init   ! Open boundaries initialisation
+      IF( lk_bdy        )   CALL bdy_dta_init   ! Open boundaries initialisation of external data arrays
       IF( lk_bdy .AND. lk_tide )   &
-         &                  CALL  bdytide_init  ! Open boundaries initialisation of tidal harmonic forcing
+         &                  CALL bdytide_init   ! Open boundaries initialisation of tidal harmonic forcing
 
                             CALL dyn_nept_init  ! simplified form of Neptune effect
-
       !     
       IF( ln_crs        )   CALL     crs_init   ! Domain initialization of coarsened grid
       !
                                 ! Ocean physics
-                            CALL     sbc_init   ! Forcings : surface module
       !                                         ! Vertical physics
-
                             CALL     zdf_init      ! namelist read
-
                             CALL zdf_bfr_init      ! bottom friction
-
       IF( lk_zdfric     )   CALL zdf_ric_init      ! Richardson number dependent Kz
       IF( lk_zdftke     )   CALL zdf_tke_init      ! TKE closure scheme
@@ -451,7 +439,5 @@
                             CALL     trc_init
 #endif
-      !
- 
-                                            ! Diagnostics
+      !                                     ! Diagnostics
       IF( lk_floats     )   CALL     flo_init   ! drifting Floats
       IF( lk_diaar5     )   CALL dia_ar5_init   ! ar5 diag
@@ -459,9 +445,10 @@
       IF( lk_diadct     )   CALL dia_dct_init   ! Sections tranports
                             CALL dia_hsb_init   ! heat content, salt content and volume budgets
-                            CALL trd_mod_init   ! Mixed-layer/Vorticity/Integral constraints trends
+                            CALL     trd_init   ! Mixed-layer/Vorticity/Integral constraints trends
       IF( lk_diaobs     ) THEN                  ! Observation & model comparison
                             CALL dia_obs_init            ! Initialize observational data
                             CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
       ENDIF
+
       !                                     ! Assimilation increments
       IF( lk_asminc     )   CALL asm_inc_init   ! Initialize assimilation increments
@@ -525,4 +512,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
@@ -573,8 +561,4 @@
       ENDIF
       !
-      IF( lk_c1d .AND. .NOT.lk_iomput )   CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ',   &
-         &                                               'with the IOM Input/Output manager. '         ,   &
-         &                                               'Compile with key_iomput enabled' )
-      !
       IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
          &                                               'f2003 standard. '                              ,  &
@@ -628,5 +612,5 @@
       USE ldftra_oce, ONLY: ldftra_oce_alloc
       USE trc_oce   , ONLY: trc_oce_alloc
-      USE insitu_tem, ONLY: insitu_tem_alloc
+      USE diainsitutem, ONLY: insitu_tem_alloc
 #if defined key_diadct 
       USE diadct    , ONLY: diadct_alloc 
@@ -670,5 +654,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
@@ -679,9 +663,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'
@@ -725,5 +709,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,  &
@@ -776,4 +760,5 @@
 
 #if defined key_mpp_mpi
+
    SUBROUTINE nemo_northcomms
       !!======================================================================
@@ -810,24 +795,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.
@@ -838,4 +835,5 @@
    END SUBROUTINE nemo_northcomms
 #endif
+
    !!======================================================================
 END MODULE nemogcm
