Index: NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/SAS/stpctl.F90
===================================================================
--- NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/SAS/stpctl.F90	(revision 10314)
+++ NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/SAS/stpctl.F90	(revision 10358)
@@ -32,4 +32,5 @@
 
    INTEGER  ::   idrun, idtime, idssh, idu, ids, istatus
+   LOGICAL  ::   lsomeoce
    !!----------------------------------------------------------------------
    !! NEMO/SAS 4.0 , NEMO Consortium (2018)
@@ -57,4 +58,5 @@
       !!
       REAL(wp), DIMENSION(3) ::   zmax
+      CHARACTER(len=20) :: clname
       !!----------------------------------------------------------------------
 
@@ -64,9 +66,10 @@
          WRITE(numout,*) '~~~~~~~'
          !                                ! open time.step file
-         CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
+         IF( lwm ) CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
          !                                ! open run.stat file
-         CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
-
-         IF( lwm ) THEN
+         IF( ln_ctl .AND. lwm ) THEN
+            CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
+            clname = 'run.stat.nc'
+            IF( .NOT. Agrif_Root() )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
             istatus = NF90_CREATE( 'run.stat.nc', NF90_CLOBBER, idrun )
             istatus = NF90_DEF_DIM( idrun, 'time'     , NF90_UNLIMITED, idtime )
@@ -76,25 +79,21 @@
             istatus = NF90_ENDDEF(idrun)
          ENDIF
-         
       ENDIF
+      IF( kt == nit000 )   lsomeoce = COUNT( ssmask(:,:) == 1._wp ) > 0
       !
-      IF(lwp) THEN                        !==  current time step  ==!   ("time.step" file)
+      IF(lwm) THEN                        !==  current time step  ==!   ("time.step" file)
          WRITE ( numstp, '(1x, i8)' )   kt
          REWIND( numstp )
       ENDIF
       !                                   !==  test of extrema  ==!
-      zmax(1) = MAXVAL(      vt_i (:,:) )                                           ! max ice thickness
-      zmax(2) = MAXVAL( ABS( u_ice(:,:) ) )                                         ! max ice velocity (zonal only)
-      zmax(3) = MAXVAL(     -tm_i (:,:)+273.15_wp , mask = ssmask(:,:) == 1._wp )   ! min ice temperature
-      !
-      IF( lk_mpp ) CALL mpp_max( "stpctl", zmax )    ! max over the global domain
-      !
-      IF( MOD( kt, nwrite ) == 1 .AND. lwp ) THEN
-         WRITE(numout,*) ' ==>> time-step= ', kt, ' vt_i max: ',  zmax(1), ' |u_ice| max: ', zmax(2), ' tm_i min: ', -zmax(3)
-      ENDIF
-
+      IF( ln_ctl ) THEN   ! must be done by all processes because of the mpp_max
+         zmax(1) = MAXVAL(      vt_i (:,:) )                                           ! max ice thickness
+         zmax(2) = MAXVAL( ABS( u_ice(:,:) ) )                                         ! max ice velocity (zonal only)
+         zmax(3) = MAXVAL(     -tm_i (:,:)+273.15_wp , mask = ssmask(:,:) == 1._wp )   ! min ice temperature
+         IF( lk_mpp ) CALL mpp_max( "stpctl", zmax )                                   ! max over the global domain
+      END IF
       !                                            !==  run statistics  ==!   ("run.stat" file)
-      IF(lwp) WRITE(numrun,9400) kt, zmax(1), zmax(2), - zmax(3)
-      IF( lwm ) THEN
+      IF( ln_ctl .AND. lwm ) THEN
+         IF(lwp) WRITE(numrun,9500) kt, zmax(1), zmax(2), - zmax(3)
          istatus = NF90_PUT_VAR( idrun, idssh, (/ zmax(1)/), (/kt/), (/1/) )
          istatus = NF90_PUT_VAR( idrun,   idu, (/ zmax(2)/), (/kt/), (/1/) )
@@ -104,5 +103,5 @@
       END IF
       !
-9400  FORMAT(' it :', i8, '    vt_i_max: ', D23.16, ' |u|_max: ', D23.16,' tm_i_min: ', D23.16)
+9500  FORMAT(' it :', i8, '    vt_i_max: ', D23.16, ' |u|_max: ', D23.16,' tm_i_min: ', D23.16)
       !
    END SUBROUTINE stp_ctl
