Index: branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 9209)
+++ branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 9210)
@@ -154,38 +154,61 @@
       !                            !-----------------------!
       istp = nit000
+      !
 #if defined key_c1d
-         DO WHILE ( istp <= nitend .AND. nstop == 0 )
-            CALL stp_c1d( istp )
+      DO WHILE ( istp <= nitend .AND. nstop == 0 )    !==  C1D time-stepping  ==!
+         CALL stp_c1d( istp )
+         istp = istp + 1
+      END DO
+#else
+
+!!gm     This data assimilation calls should be part of the initialisation (i.e. put in asm_inc_init)
+      !
+      IF( lk_asminc ) THEN                            !==  data assimilation  ==!   (done prior to time stepping)
+         IF( ln_bkgwri )   CALL asm_bkg_wri( nit000 - 1 )      ! Output background fields
+         IF( ln_asmdin ) THEN                                  ! Direct initialization
+            IF( ln_trainc )   CALL tra_asm_inc( nit000 - 1 )      ! Tracers
+            IF( ln_dyninc )   CALL dyn_asm_inc( nit000 - 1 )      ! Dynamics
+            IF( ln_sshinc )   CALL ssh_asm_inc( nit000 - 1 )      ! SSH
+         ENDIF
+      ENDIF
+!!gm end
+      !
+# if defined key_agrif
+      !                                               !==  AGRIF time-stepping  ==!
+      CALL Agrif_Regrid()
+      DO WHILE( istp <= nitend .AND. nstop == 0 )
+         CALL stp
+         istp = istp + 1
+      END DO
+      !
+      IF( .NOT. Agrif_Root() ) THEN
+         CALL Agrif_ParentGrid_To_ChildGrid()
+         IF( ln_diaobs )   CALL dia_obs_wri
+         IF( ln_timing )   CALL timing_finalize
+         CALL Agrif_ChildGrid_To_ParentGrid()
+      ENDIF
+      !
+# else
+      !
+      IF( .NOT.ln_diurnal_only ) THEN                 !==  Standard time-stepping  ==!
+         !
+         DO WHILE( istp <= nitend .AND. nstop == 0 )
+            CALL stp        ( istp ) 
             istp = istp + 1
          END DO
-#else
-          IF( lk_asminc ) THEN
-             IF( ln_bkgwri ) CALL asm_bkg_wri( nit000 - 1 )    ! Output background fields
-             IF( ln_asmdin ) THEN                        ! Direct initialization
-                IF( ln_trainc ) CALL tra_asm_inc( nit000 - 1 )    ! Tracers
-                IF( ln_dyninc ) CALL dyn_asm_inc( nit000 - 1 )    ! Dynamics
-                IF( ln_sshinc ) CALL ssh_asm_inc( nit000 - 1 )    ! SSH
-             ENDIF
-          ENDIF
-
-#if defined key_agrif
-          CALL Agrif_Regrid()
-#endif
-
-         DO WHILE ( istp <= nitend .AND. nstop == 0 )
-#if defined key_agrif
-            CALL stp                         ! AGRIF: time stepping
-#else
-            IF ( .NOT. ln_diurnal_only ) THEN 
-               CALL stp( istp )                 ! standard time stepping 
-            ELSE 
-               CALL stp_diurnal( istp )        ! time step only the diurnal SST 
-            ENDIF 
-#endif
+         !
+      ELSE                                            !==  diurnal SST time-steeping only  ==!
+         !
+         DO WHILE( istp <= nitend .AND. nstop == 0 )
+            CALL stp_diurnal( istp )   ! time step only the diurnal SST 
             istp = istp + 1
-            IF( lk_mpp )   CALL mpp_max( nstop )
          END DO
-#endif
-
+         !
+      ENDIF
+      !
+# endif
+      !
+#endif
+      !
       IF( ln_diaobs   )   CALL dia_obs_wri
       !
@@ -199,15 +222,8 @@
       IF( nstop /= 0 .AND. lwp ) THEN        ! error print
          WRITE(numout,cform_err)
-         WRITE(numout,*) nstop, ' error have been found'
-      ENDIF
-      !
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN
-         CALL Agrif_ParentGrid_To_ChildGrid()
-         IF( ln_diaobs )        CALL dia_obs_wri
-         IF( ln_timing )   CALL timing_finalize
-         CALL Agrif_ChildGrid_To_ParentGrid()
-      ENDIF
-#endif
+         WRITE(numout,*) 'nemo_gcm: a total of ', nstop, ' errors have been found'
+         WRITE(numout,*)
+      ENDIF
+      !
       IF( ln_timing )   CALL timing_finalize
       !
@@ -215,11 +231,9 @@
       !
 #if defined key_iomput
-      CALL xios_finalize                     ! end mpp communications with xios
-      IF( lk_oasis )   CALL cpl_finalize     ! end coupling and mpp communications with OASIS
+                                    CALL xios_finalize  ! end mpp communications with xios
+      IF( lk_oasis     )            CALL cpl_finalize   ! end coupling and mpp communications with OASIS
 #else
-      IF( lk_oasis ) THEN 
-         CALL cpl_finalize                   ! end coupling and mpp communications with OASIS
-      ELSE
-         IF( lk_mpp )   CALL mppstop         ! end mpp communications
+      IF    ( lk_oasis ) THEN   ;   CALL cpl_finalize   ! end coupling and mpp communications with OASIS
+      ELSEIF( lk_mpp   ) THEN   ;   CALL mppstop        ! end mpp communications
       ENDIF
 #endif
Index: branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/step.F90
===================================================================
--- branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 9209)
+++ branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 9210)
@@ -280,5 +280,5 @@
       IF(.NOT.ln_linssh) CALL dom_vvl_sf_swp( kstp )  ! swap of vertical scale factors
       !
-      IF( ln_diahsb        )   CALL dia_hsb( kstp )         ! - ML - global conservation diagnostics
+      IF( ln_diahsb  )   CALL dia_hsb       ( kstp )  ! - ML - global conservation diagnostics
 
 !!gm : This does not only concern the dynamics ==>>> add a new title
@@ -287,6 +287,6 @@
 !!jc: That would be better, but see comment above
 !!
-      IF( lrst_oce         )   CALL rst_write    ( kstp )   ! write output ocean restart file
-      IF( ln_sto_eos       )   CALL sto_rst_write( kstp )   ! write restart file for stochastic parameters
+      IF( lrst_oce   )   CALL rst_write    ( kstp )   ! write output ocean restart file
+      IF( ln_sto_eos )   CALL sto_rst_write( kstp )   ! write restart file for stochastic parameters
 
 #if defined key_agrif
@@ -298,28 +298,24 @@
       IF( Agrif_NbStepint() == 0 ) THEN               ! AGRIF Update 
 !!jc in fact update is useless at last time step, but do it for global diagnostics
-                             CALL Agrif_Update_ssh()      ! Update ssh
-         IF(.NOT.ln_linssh)  CALL Agrif_Update_vvl()      ! Update vertical scale factors  
-                             CALL Agrif_Update_Tra()      ! Update active tracers
-                             CALL Agrif_Update_Dyn()      ! Update momentum
-#if defined key_top
-                             CALL Agrif_Update_Trc()      ! Update passive tracers
-#endif
-      ENDIF
-#endif
-      IF( ln_diaobs  )   CALL dia_obs( kstp )         ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
+                              CALL Agrif_Update_ssh()    ! Update ssh
+         IF(.NOT.ln_linssh)   CALL Agrif_Update_vvl()    ! Update vertical scale factors  
+                              CALL Agrif_Update_Tra()    ! Update active tracers
+                              CALL Agrif_Update_Dyn()    ! Update momentum
+# if defined key_top
+                              CALL Agrif_Update_Trc()    ! Update passive tracers
+# endif
+      ENDIF
+#endif
+      IF( ln_diaobs  )   CALL dia_obs      ( kstp )      ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! Control
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL stp_ctl       ( kstp, indic )
-      IF( indic < 0  ) THEN
-                         CALL ctl_stop( 'step: indic < 0' )
-                         CALL dia_wri_state( 'output.abort', kstp )
-      ENDIF
-      IF( kstp == nit000 ) THEN
-                 CALL iom_close( numror )     ! close input  ocean restart file
-         IF(lwm) CALL FLUSH    ( numond )     ! flush output namelist oce
-         IF(lwm.AND.numoni /= -1 )   &
-            &    CALL FLUSH    ( numoni )     ! flush output namelist ice (if exist)
+                         CALL stp_ctl      ( kstp, indic )
+                         
+      IF( kstp == nit000 ) THEN                          ! 1st time step only
+                                        CALL iom_close( numror )   ! close input  ocean restart file
+         IF(lwm)                        CALL FLUSH    ( numond )   ! flush output namelist oce
+         IF(lwm .AND. numoni /= -1 )    CALL FLUSH    ( numoni )   ! flush output namelist ice (if exist)
       ENDIF
 
@@ -337,9 +333,5 @@
 #endif
       !
-      IF( ln_timing ) THEN
-         IF( ln_timing      )   CALL timing_start('stp')
-!!gm avoid the init phase during 1st time step ???  useless now no?
-         IF( kstp == nit000 )   CALL timing_reset           
-      ENDIF
+      IF( ln_timing )   CALL timing_stop('stp')
       !
    END SUBROUTINE stp
Index: branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/stpctl.F90
===================================================================
--- branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/stpctl.F90	(revision 9209)
+++ branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/stpctl.F90	(revision 9210)
@@ -19,9 +19,10 @@
    USE dom_oce         ! ocean space and time domain variables 
    USE c1d             ! 1D vertical configuration
+   USE diawri          ! Standard run outputs       (dia_wri_state routine)
    !
    USE in_out_manager  ! I/O manager
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp         ! distributed memory computing
-   USE wet_dry,    ONLY: ll_wd, ssh_ref    ! reference depth for negative bathy
+   USE wet_dry,   ONLY : ll_wd, ssh_ref    ! reference depth for negative bathy
 
    IMPLICIT NONE
@@ -51,4 +52,5 @@
       !! ** Actions :   "time.step" file = last ocean time-step
       !!                "run.stat"  file = run statistics
+      !!                nstop indicator sheared among all local domain (lk_mpp=T)
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
@@ -62,5 +64,5 @@
       INTEGER , DIMENSION(3) ::   ilocu, ilocs
       INTEGER , DIMENSION(2) ::   iloch
-      REAL(wp), DIMENSION(3) ::   zmax
+      REAL(wp), DIMENSION(4) ::   zmax
       !!----------------------------------------------------------------------
       !
@@ -82,12 +84,17 @@
       !                                   !==  test of extrema  ==!
       IF( ll_wd ) THEN
-         zmax(1) = MAXVAL(  ABS( sshn(:,:) + ssh_ref*tmask(:,:,1) )  )           ! ssh max 
+         zmax(1) = MAXVAL(  ABS( sshn(:,:) + ssh_ref*tmask(:,:,1) )  )        ! ssh max 
       ELSE
-         zmax(1) = MAXVAL(  ABS( sshn(:,:) )  )                                  ! ssh max
+         zmax(1) = MAXVAL(  ABS( sshn(:,:) )  )                               ! ssh max
       ENDIF
       zmax(2) = MAXVAL(  ABS( un(:,:,:) )  )                                  ! velocity max (zonal only)
       zmax(3) = MAXVAL( -tsn(:,:,:,jp_sal) , mask = tmask(:,:,:) == 1._wp )   ! minus salinity max
+      zmax(4) = REAL( nstop , wp )                                            ! stop indicator
       !
-      IF( lk_mpp )   CALL mpp_max_multiple( zmax(:), 3 ) ! max over the global domain
+      IF( lk_mpp ) THEN
+         CALL mpp_max_multiple( zmax(:), 4 )    ! max over the global domain
+         !
+         nstop = INT( zmax(4) )                 ! nstop indicator sheared among all local domains
+      ENDIF
       !
       IF( MOD( kt, nwrite ) == 1 .AND. lwp ) THEN
@@ -114,6 +121,6 @@
          IF(lwp) THEN
             WRITE(numout,cform_err)
-            WRITE(numout,*) ' stpctl: |ssh| > 10 m   or   |U| > 10 m/s   or   S < 0   or   NaN encounter in the tests'
-            WRITE(numout,*) ' ====== '
+            WRITE(numout,*) ' stp_ctl: |ssh| > 10 m   or   |U| > 10 m/s   or   S < 0   or   NaN encounter in the tests'
+            WRITE(numout,*) ' ======= '
             WRITE(numout,9100) kt,   zmax(1), iih, ijh
             WRITE(numout,9200) kt,   zmax(2), iiu, iju, iku
@@ -123,4 +130,8 @@
          ENDIF
          kindic = -3
+         !
+         nstop = nstop + 1                            ! increase nstop by 1 (on all local domains)
+         CALL dia_wri_state( 'output.abort', kt )     ! create an output.abort file
+         !
       ENDIF
 9100  FORMAT (' kt=',i8,'   |ssh| max: ',1pg11.4,', at  i j  : ',2i5)
