Index: NEMO/branches/2020/dev_r13296_HPC-07_mocavero_mpi3/src/SAS/nemogcm.F90
===================================================================
--- NEMO/branches/2020/dev_r13296_HPC-07_mocavero_mpi3/src/SAS/nemogcm.F90	(revision 13302)
+++ NEMO/branches/2020/dev_r13296_HPC-07_mocavero_mpi3/src/SAS/nemogcm.F90	(revision 13571)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE nemogcm   ***
-   !! StandAlone Surface module : surface fluxes + sea-ice + iceberg floats
+   !! StandAlone Surface module : surface fluxes + sea-ice + iceberg floats + ABL
    !!======================================================================
    !! History :  3.6  ! 2011-11  (S. Alderson, G. Madec) original code
@@ -58,4 +58,5 @@
 
 #if defined key_mpp_mpi
+   ! need MPI_Wtime
    INCLUDE 'mpif.h'
 #endif
@@ -83,4 +84,5 @@
       !!----------------------------------------------------------------------
       INTEGER ::   istp   ! time step index
+      REAL(wp)::   zstptiming   ! elapsed time for 1 time step
       !!----------------------------------------------------------------------
       !
@@ -93,5 +95,5 @@
 #if defined key_agrif
       Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
-      CALL Agrif_Declare_Var       !  "      "   "   "      "  DYN/TRA 
+      CALL Agrif_Declare_Var       !  "      "   "   "      "  DYN/TRA
 # if defined key_top
       CALL Agrif_Declare_Var_top   !  "      "   "   "      "  TOP
@@ -107,4 +109,7 @@
       !                            !==   time stepping   ==!
       !                            !-----------------------!
+      !
+      !                                               !== set the model time-step  ==!
+      !
       istp = nit000
       !
@@ -124,16 +129,22 @@
       END DO
       !
-#else
+# else
       !
       IF( .NOT.ln_diurnal_only ) THEN                 !==  Standard time-stepping  ==!
          !
          DO WHILE( istp <= nitend .AND. nstop == 0 )
-#if defined key_mpp_mpi
+
             ncom_stp = istp
-            IF ( istp == ( nit000 + 1 ) ) elapsed_time = MPI_Wtime()
-            IF ( istp ==         nitend ) elapsed_time = MPI_Wtime() - elapsed_time
-#endif
+            IF( ln_timing ) THEN
+               zstptiming = MPI_Wtime()
+               IF ( istp == ( nit000 + 1 ) ) elapsed_time = zstptiming
+               IF ( istp ==         nitend ) elapsed_time = zstptiming - elapsed_time
+            ENDIF
+            
             CALL stp        ( istp ) 
             istp = istp + 1
+
+            IF( lwp .AND. ln_timing )   WRITE(numtime,*) 'timing step ', istp-1, ' : ', MPI_Wtime() - zstptiming
+
          END DO
          !
@@ -305,5 +316,5 @@
          WRITE(numout,*) "       )  )       \) |`\ \)  '.   \      (   (   "
          WRITE(numout,*) "      (  (           \_/       '-._\      )   )  "
-         WRITE(numout,*) "       )  ) jgs                    `     (   (   "
+         WRITE(numout,*) "       )  ) jgs                     `    (   (   "
          WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
          WRITE(numout,*)
@@ -355,5 +366,5 @@
       !
       !                                      ! General initialization
-      IF( ln_timing    )   CALL timing_init     ! timing
+      IF( ln_timing    )   CALL timing_init ( 'timing_sas.output' )
       IF( ln_timing    )   CALL timing_start( 'nemo_init')
 
@@ -367,7 +378,10 @@
          &                 CALL prt_ctl_init        ! Print control
       
+      IF( ln_rstart )      CALL rst_read_open
                            CALL day_init        ! model calendar (using both namelist and restart infos)
-      IF( ln_rstart )      CALL rst_read_open
-
+
+#if defined key_agrif
+      uu(:,:,:,:) = 0.0_wp   ;   vv(:,:,:,:) = 0.0_wp   ;   ts(:,:,:,:,:) = 0.0_wp   ! needed for interp done at initialization phase
+#endif 
       !                                      ! external forcing 
                            CALL sbc_init( Nbb, Nnn, Naa )  ! Forcings : surface module 
@@ -480,5 +494,5 @@
       ierr =        dia_wri_alloc()
       ierr = ierr + dom_oce_alloc()          ! ocean domain
-      ierr = ierr + oce_alloc    ()          ! (tsn...) needed for agrif and/or SI3 and bdy
+      ierr = ierr + oce_alloc    ()          ! (ts...) needed for agrif and/or SI3 and bdy
       ierr = ierr + bdy_oce_alloc()          ! bdy masks (incl. initialization)
       !
Index: NEMO/branches/2020/dev_r13296_HPC-07_mocavero_mpi3/src/SAS/stpctl.F90
===================================================================
--- NEMO/branches/2020/dev_r13296_HPC-07_mocavero_mpi3/src/SAS/stpctl.F90	(revision 13302)
+++ NEMO/branches/2020/dev_r13296_HPC-07_mocavero_mpi3/src/SAS/stpctl.F90	(revision 13571)
@@ -20,4 +20,6 @@
    USE dom_oce         ! ocean space and time domain variables 
    USE ice      , ONLY : vt_i, u_ice, tm_i
+   USE phycst   , ONLY : rt0
+   USE sbc_oce  , ONLY : lk_oasis
    !
    USE diawri          ! Standard run outputs       (dia_wri_state routine)
@@ -48,5 +50,4 @@
       !!
       !! ** Method  : - Save the time step in numstp
-      !!              - Print it each 50 time steps
       !!              - Stop the run IF problem encountered by setting nstop > 0
       !!                Problems checked: ice thickness maximum > 100 m
@@ -85,11 +86,17 @@
          ENDIF
          !                                ! open time.step    ascii file, done only by 1st subdomain
-         IF( lwm )   CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
+         IF( lk_oasis ) THEN   ;   clname = 'time_sas.step'
+         ELSE                  ;   clname = 'time.step'
+         ENDIF
+         IF( lwm )   CALL ctl_opn( numstp, clname, 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
          !
          IF( ll_wrtruns ) THEN
+            IF( lk_oasis ) THEN   ;   clname = 'run_sas.stat'
+            ELSE                  ;   clname = 'run.stat'
+            ENDIF
             !                             ! open run.stat     ascii file, done only by 1st subdomain
-            CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
+            CALL ctl_opn( numrun, clname, 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
             !                             ! open run.stat.nc netcdf file, done only by 1st subdomain
-            clname = 'run.stat.nc'
+            clname = TRIM(clname)//'.nc'
             IF( .NOT. Agrif_Root() )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
             istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, nrunid )
@@ -111,9 +118,15 @@
       !                                   !==            test of local extrema           ==!
       !                                   !==  done by all processes at every time step  ==!
-      llmsk(:,:) = tmask(:,:,1) == 1._wp
+      !
+      llmsk(   1:Nis1,:) = .FALSE.                                              ! exclude halos from the checked region
+      llmsk(Nie1: jpi,:) = .FALSE.
+      llmsk(:,   1:Njs1) = .FALSE.
+      llmsk(:,Nje1: jpj) = .FALSE.
+      !
+      llmsk(Nis0:Nie0,Njs0:Nje0) = tmask(Nis0:Nie0,Njs0:Nje0,1) == 1._wp   ! test only the inner domain
       IF( COUNT( llmsk(:,:) ) > 0 ) THEN   ! avoid huge values sent back for land processors...
-         zmax(1) = MAXVAL(      vt_i (:,:)            , mask = llmsk )   ! max ice thickness
-         zmax(2) = MAXVAL( ABS( u_ice(:,:) )          , mask = llmsk )   ! max ice velocity (zonal only)
-         zmax(3) = MAXVAL(     -tm_i (:,:) + 273.15_wp, mask = llmsk )   ! min ice temperature
+         zmax(1) = MAXVAL(      vt_i (:,:)      , mask = llmsk )   ! max ice thickness
+         zmax(2) = MAXVAL( ABS( u_ice(:,:) )    , mask = llmsk )   ! max ice velocity (zonal only)
+         zmax(3) = MAXVAL(     -tm_i (:,:) + rt0, mask = llmsk )   ! min ice temperature (in degC)
       ELSE
          IF( ll_colruns ) THEN    ! default value: must not be kept when calling mpp_max -> must be as small as possible
@@ -154,7 +167,7 @@
             IF( lwm .AND. kt /= nitend )   istatus = NF90_CLOSE(nrunid)
             ! get global loc on the min/max
-            CALL mpp_maxloc( 'stpctl',      vt_i(:,:)            , tmask(:,:,1), zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
-            CALL mpp_maxloc( 'stpctl',ABS( u_ice(:,:) )          , tmask(:,:,1), zzz, iloc(1:2,2) )
-            CALL mpp_minloc( 'stpctl',      tm_i(:,:) - 273.15_wp, tmask(:,:,1), zzz, iloc(1:2,3) )
+            CALL mpp_maxloc( 'stpctl',      vt_i(:,:)      , llmsk, zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
+            CALL mpp_maxloc( 'stpctl',ABS( u_ice(:,:) )    , llmsk, zzz, iloc(1:2,2) )
+            CALL mpp_minloc( 'stpctl',      tm_i(:,:) - rt0, llmsk, zzz, iloc(1:2,3) )
             ! find which subdomain has the max.
             iareamin(:) = jpnij+1   ;   iareamax(:) = 0   ;   iareasum(:) = 0
@@ -169,7 +182,10 @@
          ELSE                    ! find local min and max locations:
             ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc
-            iloc(1:2,1) = MAXLOC(       vt_i(:,:)            , mask = llmsk ) + (/ nimpp - 1, njmpp - 1/)
-            iloc(1:2,2) = MAXLOC( ABS( u_ice(:,:) )          , mask = llmsk ) + (/ nimpp - 1, njmpp - 1/)
-            iloc(1:2,3) = MINLOC(       tm_i(:,:) - 273.15_wp, mask = llmsk ) + (/ nimpp - 1, njmpp - 1/)
+            iloc(1:2,1) = MAXLOC(       vt_i(:,:)      , mask = llmsk )
+            iloc(1:2,2) = MAXLOC( ABS( u_ice(:,:) )    , mask = llmsk )
+            iloc(1:2,3) = MINLOC(       tm_i(:,:) - rt0, mask = llmsk )
+            DO ji = 1, 3   ! local domain indices ==> global domain indices, excluding halos
+               iloc(1:2,ji) = (/ mig0(iloc(1,ji)), mjg0(iloc(2,ji)) /)
+            END DO
             iareamin(:) = narea   ;   iareamax(:) = narea   ;   iareasum(:) = 1         ! this is local information
          ENDIF
