Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/asminc.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/asminc.F90	(revision 13603)
+++ 	(revision )
@@ -1,1030 +1,0 @@
-MODULE asminc
-   !!======================================================================
-   !!                       ***  MODULE asminc  ***
-   !! Assimilation increment : Apply an increment generated by data
-   !!                          assimilation
-   !!======================================================================
-   !! History :       ! 2007-03  (M. Martin)  Met Office version
-   !!                 ! 2007-04  (A. Weaver)  calc_date original code
-   !!                 ! 2007-04  (A. Weaver)  Merge with OPAVAR/NEMOVAR
-   !!   NEMO     3.3  ! 2010-05  (D. Lea)  Update to work with NEMO v3.2
-   !!             -   ! 2010-05  (D. Lea)  add calc_month_len routine based on day_init 
-   !!            3.4  ! 2012-10  (A. Weaver and K. Mogensen) Fix for direct initialization
-   !!                 ! 2014-09  (D. Lea)  Local calc_date removed use routine from OBS
-   !!                 ! 2015-11  (D. Lea)  Handle non-zero initial time of day
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   asm_inc_init   : Initialize the increment arrays and IAU weights
-   !!   tra_asm_inc    : Apply the tracer (T and S) increments
-   !!   dyn_asm_inc    : Apply the dynamic (u and v) increments
-   !!   ssh_asm_inc    : Apply the SSH increment
-   !!   ssh_asm_div    : Apply divergence associated with SSH increment
-   !!   seaice_asm_inc : Apply the seaice increment
-   !!----------------------------------------------------------------------
-   USE oce             ! Dynamics and active tracers defined in memory
-   USE par_oce         ! Ocean space and time domain variables
-   USE dom_oce         ! Ocean space and time domain
-   USE domvvl          ! domain: variable volume level
-   USE ldfdyn          ! lateral diffusion: eddy viscosity coefficients
-   USE eosbn2          ! Equation of state - in situ and potential density
-   USE zpshde          ! Partial step : Horizontal Derivative
-   USE asmpar          ! Parameters for the assmilation interface
-   USE asmbkg          ! 
-   USE c1d             ! 1D initialization
-   USE sbc_oce         ! Surface boundary condition variables.
-   USE diaobs   , ONLY : calc_date     ! Compute the calendar date on a given step
-#if defined key_si3
-   USE ice      , ONLY : hm_i, at_i, at_i_b
-#endif
-   !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! Library to read input files
-   USE lib_mpp         ! MPP library
-
-   IMPLICIT NONE
-   PRIVATE
-   
-   PUBLIC   asm_inc_init   !: Initialize the increment arrays and IAU weights
-   PUBLIC   tra_asm_inc    !: Apply the tracer (T and S) increments
-   PUBLIC   dyn_asm_inc    !: Apply the dynamic (u and v) increments
-   PUBLIC   ssh_asm_inc    !: Apply the SSH increment
-   PUBLIC   ssh_asm_div    !: Apply the SSH divergence
-   PUBLIC   seaice_asm_inc !: Apply the seaice increment
-
-#if defined key_asminc
-    LOGICAL, PUBLIC, PARAMETER :: lk_asminc = .TRUE.   !: Logical switch for assimilation increment interface
-#else
-    LOGICAL, PUBLIC, PARAMETER :: lk_asminc = .FALSE.  !: No assimilation increments
-#endif
-   LOGICAL, PUBLIC :: ln_bkgwri     !: No output of the background state fields
-   LOGICAL, PUBLIC :: ln_asmiau     !: No applying forcing with an assimilation increment
-   LOGICAL, PUBLIC :: ln_asmdin     !: No direct initialization
-   LOGICAL, PUBLIC :: ln_trainc     !: No tracer (T and S) assimilation increments
-   LOGICAL, PUBLIC :: ln_dyninc     !: No dynamics (u and v) assimilation increments
-   LOGICAL, PUBLIC :: ln_sshinc     !: No sea surface height assimilation increment
-   LOGICAL, PUBLIC :: ln_seaiceinc  !: No sea ice concentration increment
-   LOGICAL, PUBLIC :: ln_salfix     !: Apply minimum salinity check
-   LOGICAL, PUBLIC :: ln_temnofreeze = .FALSE. !: Don't allow the temperature to drop below freezing
-   INTEGER, PUBLIC :: nn_divdmp     !: Apply divergence damping filter nn_divdmp times
-
-   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::   t_bkg   , s_bkg      !: Background temperature and salinity
-   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::   u_bkg   , v_bkg      !: Background u- & v- velocity components
-   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::   t_bkginc, s_bkginc   !: Increment to the background T & S
-   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::   u_bkginc, v_bkginc   !: Increment to the u- & v-components 
-   REAL(wp), PUBLIC, DIMENSION(:)    , ALLOCATABLE ::   wgtiau               !: IAU weights for each time step
-#if defined key_asminc
-   REAL(wp), PUBLIC, DIMENSION(:,:)  , ALLOCATABLE ::   ssh_iau              !: IAU-weighted sea surface height increment
-#endif
-   !                                !!! time steps relative to the cycle interval [0,nitend-nit000-1]
-   INTEGER , PUBLIC ::   nitbkg      !: Time step of the background state used in the Jb term
-   INTEGER , PUBLIC ::   nitdin      !: Time step of the background state for direct initialization
-   INTEGER , PUBLIC ::   nitiaustr   !: Time step of the start of the IAU interval 
-   INTEGER , PUBLIC ::   nitiaufin   !: Time step of the end of the IAU interval
-   ! 
-   INTEGER , PUBLIC ::   niaufn      !: Type of IAU weighing function: = 0   Constant weighting
-   !                                 !: = 1   Linear hat-like, centred in middle of IAU interval 
-   REAL(wp), PUBLIC ::   salfixmin   !: Ensure that the salinity is larger than this  value if (ln_salfix)
-
-   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   ssh_bkg, ssh_bkginc   ! Background sea surface height and its increment
-   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   seaice_bkginc         ! Increment to the background sea ice conc
-#if defined key_cice && defined key_asminc
-   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   ndaice_da             ! ice increment tendency into CICE
-#endif
-
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-!!st10
-#  include "domzgr_substitute.h90"
-!!st10
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: asminc.F90 12614 2020-03-26 14:59:52Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE asm_inc_init( Kbb, Kmm, Krhs )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE asm_inc_init  ***
-      !!          
-      !! ** Purpose : Initialize the assimilation increment and IAU weights.
-      !!
-      !! ** Method  : Initialize the assimilation increment and IAU weights.
-      !!
-      !! ** Action  : 
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::  Kbb, Kmm, Krhs  ! time level indices
-      !
-      INTEGER :: ji, jj, jk, jt  ! dummy loop indices
-      INTEGER :: imid, inum      ! local integers
-      INTEGER :: ios             ! Local integer output status for namelist read
-      INTEGER :: iiauper         ! Number of time steps in the IAU period
-      INTEGER :: icycper         ! Number of time steps in the cycle
-      REAL(KIND=dp) :: ditend_date     ! Date YYYYMMDD.HHMMSS of final time step
-      REAL(KIND=dp) :: ditbkg_date     ! Date YYYYMMDD.HHMMSS of background time step for Jb term
-      REAL(KIND=dp) :: ditdin_date     ! Date YYYYMMDD.HHMMSS of background time step for DI
-      REAL(KIND=dp) :: ditiaustr_date  ! Date YYYYMMDD.HHMMSS of IAU interval start time step
-      REAL(KIND=dp) :: ditiaufin_date  ! Date YYYYMMDD.HHMMSS of IAU interval final time step
-
-      REAL(wp) :: znorm        ! Normalization factor for IAU weights
-      REAL(wp) :: ztotwgt      ! Value of time-integrated IAU weights (should be equal to one)
-      REAL(wp) :: z_inc_dateb  ! Start date of interval on which increment is valid
-      REAL(wp) :: z_inc_datef  ! End date of interval on which increment is valid
-      REAL(wp) :: zdate_bkg    ! Date in background state file for DI
-      REAL(wp) :: zdate_inc    ! Time axis in increments file
-      !
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zhdiv   ! 2D workspace
-      !!
-      NAMELIST/nam_asminc/ ln_bkgwri,                                      &
-         &                 ln_trainc, ln_dyninc, ln_sshinc,                &
-         &                 ln_asmdin, ln_asmiau,                           &
-         &                 nitbkg, nitdin, nitiaustr, nitiaufin, niaufn,   &
-         &                 ln_salfix, salfixmin, nn_divdmp
-      !!----------------------------------------------------------------------
-
-      !-----------------------------------------------------------------------
-      ! Read Namelist nam_asminc : assimilation increment interface
-      !-----------------------------------------------------------------------
-      ln_seaiceinc   = .FALSE.
-      ln_temnofreeze = .FALSE.
-
-      READ  ( numnam_ref, nam_asminc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_asminc in reference namelist' )
-      READ  ( numnam_cfg, nam_asminc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nam_asminc in configuration namelist' )
-      IF(lwm) WRITE ( numond, nam_asminc )
-
-      ! Control print
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'asm_inc_init : Assimilation increment initialization :'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist namasm : set assimilation increment parameters'
-         WRITE(numout,*) '      Logical switch for writing out background state          ln_bkgwri = ', ln_bkgwri
-         WRITE(numout,*) '      Logical switch for applying tracer increments            ln_trainc = ', ln_trainc
-         WRITE(numout,*) '      Logical switch for applying velocity increments          ln_dyninc = ', ln_dyninc
-         WRITE(numout,*) '      Logical switch for applying SSH increments               ln_sshinc = ', ln_sshinc
-         WRITE(numout,*) '      Logical switch for Direct Initialization (DI)            ln_asmdin = ', ln_asmdin
-         WRITE(numout,*) '      Logical switch for applying sea ice increments        ln_seaiceinc = ', ln_seaiceinc
-         WRITE(numout,*) '      Logical switch for Incremental Analysis Updating (IAU)   ln_asmiau = ', ln_asmiau
-         WRITE(numout,*) '      Timestep of background in [0,nitend-nit000-1]            nitbkg    = ', nitbkg
-         WRITE(numout,*) '      Timestep of background for DI in [0,nitend-nit000-1]     nitdin    = ', nitdin
-         WRITE(numout,*) '      Timestep of start of IAU interval in [0,nitend-nit000-1] nitiaustr = ', nitiaustr
-         WRITE(numout,*) '      Timestep of end of IAU interval in [0,nitend-nit000-1]   nitiaufin = ', nitiaufin
-         WRITE(numout,*) '      Type of IAU weighting function                           niaufn    = ', niaufn
-         WRITE(numout,*) '      Logical switch for ensuring that the sa > salfixmin      ln_salfix = ', ln_salfix
-         WRITE(numout,*) '      Minimum salinity after applying the increments           salfixmin = ', salfixmin
-      ENDIF
-
-      nitbkg_r    = nitbkg    + nit000 - 1            ! Background time referenced to nit000
-      nitdin_r    = nitdin    + nit000 - 1            ! Background time for DI referenced to nit000
-      nitiaustr_r = nitiaustr + nit000 - 1            ! Start of IAU interval referenced to nit000
-      nitiaufin_r = nitiaufin + nit000 - 1            ! End of IAU interval referenced to nit000
-
-      iiauper     = nitiaufin_r - nitiaustr_r + 1     ! IAU interval length
-      icycper     = nitend      - nit000      + 1     ! Cycle interval length
-
-      CALL calc_date( nitend     , ditend_date    )   ! Date of final time step
-      CALL calc_date( nitbkg_r   , ditbkg_date    )   ! Background time for Jb referenced to ndate0
-      CALL calc_date( nitdin_r   , ditdin_date    )   ! Background time for DI referenced to ndate0
-      CALL calc_date( nitiaustr_r, ditiaustr_date )   ! IAU start time referenced to ndate0
-      CALL calc_date( nitiaufin_r, ditiaufin_date )   ! IAU end time referenced to ndate0
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) '   Time steps referenced to current cycle:'
-         WRITE(numout,*) '       iitrst      = ', nit000 - 1
-         WRITE(numout,*) '       nit000      = ', nit000
-         WRITE(numout,*) '       nitend      = ', nitend
-         WRITE(numout,*) '       nitbkg_r    = ', nitbkg_r
-         WRITE(numout,*) '       nitdin_r    = ', nitdin_r
-         WRITE(numout,*) '       nitiaustr_r = ', nitiaustr_r
-         WRITE(numout,*) '       nitiaufin_r = ', nitiaufin_r
-         WRITE(numout,*)
-         WRITE(numout,*) '   Dates referenced to current cycle:'
-         WRITE(numout,*) '       ndastp         = ', ndastp
-         WRITE(numout,*) '       ndate0         = ', ndate0
-         WRITE(numout,*) '       nn_time0       = ', nn_time0
-         WRITE(numout,*) '       ditend_date    = ', ditend_date
-         WRITE(numout,*) '       ditbkg_date    = ', ditbkg_date
-         WRITE(numout,*) '       ditdin_date    = ', ditdin_date
-         WRITE(numout,*) '       ditiaustr_date = ', ditiaustr_date
-         WRITE(numout,*) '       ditiaufin_date = ', ditiaufin_date
-      ENDIF
-
-
-      IF ( ( ln_asmdin ).AND.( ln_asmiau ) )   &
-         & CALL ctl_stop( ' ln_asmdin and ln_asmiau :', &
-         &                ' Choose Direct Initialization OR Incremental Analysis Updating')
-
-      IF (      ( ( .NOT. ln_asmdin ).AND.( .NOT. ln_asmiau ) ) &
-           .AND.( ( ln_trainc ).OR.( ln_dyninc ).OR.( ln_sshinc ) .OR. ( ln_seaiceinc) )) &
-         & CALL ctl_stop( ' One or more of ln_trainc, ln_dyninc, ln_sshinc and ln_seaiceinc is set to .true.', &
-         &                ' but ln_asmdin and ln_asmiau are both set to .false. :', &
-         &                ' Inconsistent options')
-
-      IF ( ( niaufn /= 0 ).AND.( niaufn /= 1 ) ) &
-         & CALL ctl_stop( ' niaufn /= 0 or niaufn /=1 :',  &
-         &                ' Type IAU weighting function is invalid')
-
-      IF ( ( .NOT. ln_trainc ).AND.( .NOT. ln_dyninc ).AND.( .NOT. ln_sshinc ).AND.( .NOT. ln_seaiceinc ) &
-         &                     )  &
-         & CALL ctl_warn( ' ln_trainc, ln_dyninc, ln_sshinc and ln_seaiceinc are set to .false. :', &
-         &                ' The assimilation increments are not applied')
-
-      IF ( ( ln_asmiau ).AND.( nitiaustr == nitiaufin ) ) &
-         & CALL ctl_stop( ' nitiaustr = nitiaufin :',  &
-         &                ' IAU interval is of zero length')
-
-      IF ( ( ln_asmiau ).AND.( ( nitiaustr_r < nit000 ).OR.( nitiaufin_r > nitend ) ) ) &
-         & CALL ctl_stop( ' nitiaustr or nitiaufin :',  &
-         &                ' IAU starting or final time step is outside the cycle interval', &
-         &                 ' Valid range nit000 to nitend')
-
-      IF ( ( nitbkg_r < nit000 - 1 ).OR.( nitbkg_r > nitend ) ) &
-         & CALL ctl_stop( ' nitbkg :',  &
-         &                ' Background time step is outside the cycle interval')
-
-      IF ( ( nitdin_r < nit000 - 1 ).OR.( nitdin_r > nitend ) ) &
-         & CALL ctl_stop( ' nitdin :',  &
-         &                ' Background time step for Direct Initialization is outside', &
-         &                ' the cycle interval')
-
-      IF ( nstop > 0 ) RETURN       ! if there are any errors then go no further
-
-      !--------------------------------------------------------------------
-      ! Initialize the Incremental Analysis Updating weighting function
-      !--------------------------------------------------------------------
-
-      IF( ln_asmiau ) THEN
-         !
-         ALLOCATE( wgtiau( icycper ) )
-         !
-         wgtiau(:) = 0._wp
-         !
-         !                                !---------------------------------------------------------
-         IF( niaufn == 0 ) THEN           ! Constant IAU forcing 
-            !                             !---------------------------------------------------------
-            DO jt = 1, iiauper
-               wgtiau(jt+nitiaustr-1) = 1.0 / REAL( iiauper )
-            END DO
-            !                             !---------------------------------------------------------
-         ELSEIF ( niaufn == 1 ) THEN      ! Linear hat-like, centred in middle of IAU interval 
-            !                             !---------------------------------------------------------
-            ! Compute the normalization factor
-            znorm = 0._wp
-            IF( MOD( iiauper, 2 ) == 0 ) THEN   ! Even number of time steps in IAU interval
-               imid = iiauper / 2 
-               DO jt = 1, imid
-                  znorm = znorm + REAL( jt )
-               END DO
-               znorm = 2.0 * znorm
-            ELSE                                ! Odd number of time steps in IAU interval
-               imid = ( iiauper + 1 ) / 2        
-               DO jt = 1, imid - 1
-                  znorm = znorm + REAL( jt )
-               END DO
-               znorm = 2.0 * znorm + REAL( imid )
-            ENDIF
-            znorm = 1.0 / znorm
-            !
-            DO jt = 1, imid - 1
-               wgtiau(jt+nitiaustr-1) = REAL( jt ) * znorm
-            END DO
-            DO jt = imid, iiauper
-               wgtiau(jt+nitiaustr-1) = REAL( iiauper - jt + 1 ) * znorm
-            END DO
-            !
-         ENDIF
-
-         ! Test that the integral of the weights over the weighting interval equals 1
-          IF(lwp) THEN
-             WRITE(numout,*)
-             WRITE(numout,*) 'asm_inc_init : IAU weights'
-             WRITE(numout,*) '~~~~~~~~~~~~'
-             WRITE(numout,*) '             time step         IAU  weight'
-             WRITE(numout,*) '             =========     ====================='
-             ztotwgt = 0.0
-             DO jt = 1, icycper
-                ztotwgt = ztotwgt + wgtiau(jt)
-                WRITE(numout,*) '         ', jt, '       ', wgtiau(jt) 
-             END DO   
-             WRITE(numout,*) '         ==================================='
-             WRITE(numout,*) '         Time-integrated weight = ', ztotwgt
-             WRITE(numout,*) '         ==================================='
-          ENDIF
-         
-      ENDIF
-
-      !--------------------------------------------------------------------
-      ! Allocate and initialize the increment arrays
-      !--------------------------------------------------------------------
-
-      ALLOCATE( t_bkginc     (jpi,jpj,jpk) )   ;   t_bkginc     (:,:,:) = 0._wp
-      ALLOCATE( s_bkginc     (jpi,jpj,jpk) )   ;   s_bkginc     (:,:,:) = 0._wp
-      ALLOCATE( u_bkginc     (jpi,jpj,jpk) )   ;   u_bkginc     (:,:,:) = 0._wp
-      ALLOCATE( v_bkginc     (jpi,jpj,jpk) )   ;   v_bkginc     (:,:,:) = 0._wp
-      ALLOCATE( ssh_bkginc   (jpi,jpj)     )   ;   ssh_bkginc   (:,:)   = 0._wp
-      ALLOCATE( seaice_bkginc(jpi,jpj)     )   ;   seaice_bkginc(:,:)   = 0._wp
-#if defined key_asminc
-      ALLOCATE( ssh_iau      (jpi,jpj)     )   ;   ssh_iau      (:,:)   = 0._wp
-#endif
-#if defined key_cice && defined key_asminc
-      ALLOCATE( ndaice_da    (jpi,jpj)     )   ;   ndaice_da    (:,:)   = 0._wp
-#endif
-      !
-      IF ( ln_trainc .OR. ln_dyninc .OR.   &       !--------------------------------------
-         & ln_sshinc .OR. ln_seaiceinc   ) THEN    ! Read the increments from file
-         !                                         !--------------------------------------
-         CALL iom_open( c_asminc, inum )
-         !
-         CALL iom_get( inum, 'time'       , zdate_inc   ) 
-         CALL iom_get( inum, 'z_inc_dateb', z_inc_dateb )
-         CALL iom_get( inum, 'z_inc_datef', z_inc_datef )
-         z_inc_dateb = zdate_inc
-         z_inc_datef = zdate_inc
-         !
-         IF(lwp) THEN
-            WRITE(numout,*) 
-            WRITE(numout,*) 'asm_inc_init : Assimilation increments valid between dates ', z_inc_dateb,' and ', z_inc_datef
-            WRITE(numout,*) '~~~~~~~~~~~~'
-         ENDIF
-         !
-         IF ( ( z_inc_dateb < ndastp + nn_time0*0.0001_wp ) .OR.   &
-            & ( z_inc_datef > ditend_date ) ) &
-            &    CALL ctl_warn( ' Validity time of assimilation increments is ', &
-            &                   ' outside the assimilation interval' )
-
-         IF ( ( ln_asmdin ).AND.( zdate_inc /= ditdin_date ) ) &
-            & CALL ctl_warn( ' Validity time of assimilation increments does ', &
-            &                ' not agree with Direct Initialization time' )
-
-         IF ( ln_trainc ) THEN   
-            CALL iom_get( inum, jpdom_autoglo, 'bckint', t_bkginc, 1 )
-            CALL iom_get( inum, jpdom_autoglo, 'bckins', s_bkginc, 1 )
-            ! Apply the masks
-            t_bkginc(:,:,:) = t_bkginc(:,:,:) * tmask(:,:,:)
-            s_bkginc(:,:,:) = s_bkginc(:,:,:) * tmask(:,:,:)
-            ! Set missing increments to 0.0 rather than 1e+20
-            ! to allow for differences in masks
-            WHERE( ABS( t_bkginc(:,:,:) ) > 1.0e+10 ) t_bkginc(:,:,:) = 0.0
-            WHERE( ABS( s_bkginc(:,:,:) ) > 1.0e+10 ) s_bkginc(:,:,:) = 0.0
-         ENDIF
-
-         IF ( ln_dyninc ) THEN   
-            CALL iom_get( inum, jpdom_autoglo, 'bckinu', u_bkginc, 1 )              
-            CALL iom_get( inum, jpdom_autoglo, 'bckinv', v_bkginc, 1 )              
-            ! Apply the masks
-            u_bkginc(:,:,:) = u_bkginc(:,:,:) * umask(:,:,:)
-            v_bkginc(:,:,:) = v_bkginc(:,:,:) * vmask(:,:,:)
-            ! Set missing increments to 0.0 rather than 1e+20
-            ! to allow for differences in masks
-            WHERE( ABS( u_bkginc(:,:,:) ) > 1.0e+10 ) u_bkginc(:,:,:) = 0.0
-            WHERE( ABS( v_bkginc(:,:,:) ) > 1.0e+10 ) v_bkginc(:,:,:) = 0.0
-         ENDIF
-        
-         IF ( ln_sshinc ) THEN
-            CALL iom_get( inum, jpdom_autoglo, 'bckineta', ssh_bkginc, 1 )
-            ! Apply the masks
-            ssh_bkginc(:,:) = ssh_bkginc(:,:) * tmask(:,:,1)
-            ! Set missing increments to 0.0 rather than 1e+20
-            ! to allow for differences in masks
-            WHERE( ABS( ssh_bkginc(:,:) ) > 1.0e+10 ) ssh_bkginc(:,:) = 0.0
-         ENDIF
-
-         IF ( ln_seaiceinc ) THEN
-            CALL iom_get( inum, jpdom_autoglo, 'bckinseaice', seaice_bkginc, 1 )
-            ! Apply the masks
-            seaice_bkginc(:,:) = seaice_bkginc(:,:) * tmask(:,:,1)
-            ! Set missing increments to 0.0 rather than 1e+20
-            ! to allow for differences in masks
-            WHERE( ABS( seaice_bkginc(:,:) ) > 1.0e+10 ) seaice_bkginc(:,:) = 0.0
-         ENDIF
-         !
-         CALL iom_close( inum )
-         !
-      ENDIF
-      !
-      !                                            !--------------------------------------
-      IF ( ln_dyninc .AND. nn_divdmp > 0 ) THEN    ! Apply divergence damping filter
-         !                                         !--------------------------------------
-         ALLOCATE( zhdiv(jpi,jpj) ) 
-         !
-         DO jt = 1, nn_divdmp
-            !
-            DO jk = 1, jpkm1           ! zhdiv = e1e1 * div
-               zhdiv(:,:) = 0._wp
-               DO_2D( 0, 0, 0, 0 )
-                  zhdiv(ji,jj) = (  e2u(ji  ,jj) * e3u(ji  ,jj,jk,Kmm) * u_bkginc(ji  ,jj,jk)    &
-                     &            - e2u(ji-1,jj) * e3u(ji-1,jj,jk,Kmm) * u_bkginc(ji-1,jj,jk)    &
-                     &            + e1v(ji,jj  ) * e3v(ji,jj  ,jk,Kmm) * v_bkginc(ji,jj  ,jk)    &
-                     &            - e1v(ji,jj-1) * e3v(ji,jj-1,jk,Kmm) * v_bkginc(ji,jj-1,jk)  ) &
-                     &            / e3t(ji,jj,jk,Kmm)
-               END_2D
-               CALL lbc_lnk( 'asminc', zhdiv, 'T', 1. )   ! lateral boundary cond. (no sign change)
-               !
-               DO_2D( 0, 0, 0, 0 )
-                  u_bkginc(ji,jj,jk) = u_bkginc(ji,jj,jk)                         &
-                     &               + 0.2_wp * ( zhdiv(ji+1,jj) - zhdiv(ji  ,jj) ) * r1_e1u(ji,jj) * umask(ji,jj,jk)
-                  v_bkginc(ji,jj,jk) = v_bkginc(ji,jj,jk)                         &
-                     &               + 0.2_wp * ( zhdiv(ji,jj+1) - zhdiv(ji,jj  ) ) * r1_e2v(ji,jj) * vmask(ji,jj,jk) 
-               END_2D
-            END DO
-            !
-         END DO
-         !
-         DEALLOCATE( zhdiv ) 
-         !
-      ENDIF
-      !
-      !                             !-----------------------------------------------------
-      IF ( ln_asmdin ) THEN         ! Allocate and initialize the background state arrays
-         !                          !-----------------------------------------------------
-         !
-         ALLOCATE( t_bkg  (jpi,jpj,jpk) )   ;   t_bkg  (:,:,:) = 0._wp
-         ALLOCATE( s_bkg  (jpi,jpj,jpk) )   ;   s_bkg  (:,:,:) = 0._wp
-         ALLOCATE( u_bkg  (jpi,jpj,jpk) )   ;   u_bkg  (:,:,:) = 0._wp
-         ALLOCATE( v_bkg  (jpi,jpj,jpk) )   ;   v_bkg  (:,:,:) = 0._wp
-         ALLOCATE( ssh_bkg(jpi,jpj)     )   ;   ssh_bkg(:,:)   = 0._wp
-         !
-         !
-         !--------------------------------------------------------------------
-         ! Read from file the background state at analysis time
-         !--------------------------------------------------------------------
-         !
-         CALL iom_open( c_asmdin, inum )
-         !
-         CALL iom_get( inum, 'rdastp', zdate_bkg ) 
-         !
-         IF(lwp) THEN
-            WRITE(numout,*) 
-            WRITE(numout,*) '   ==>>>  Assimilation background state valid at : ', zdate_bkg
-            WRITE(numout,*)
-         ENDIF
-         !
-         IF ( zdate_bkg /= ditdin_date )   &
-            & CALL ctl_warn( ' Validity time of assimilation background state does', &
-            &                ' not agree with Direct Initialization time' )
-         !
-         IF ( ln_trainc ) THEN   
-            CALL iom_get( inum, jpdom_autoglo, 'tn', t_bkg )
-            CALL iom_get( inum, jpdom_autoglo, 'sn', s_bkg )
-            t_bkg(:,:,:) = t_bkg(:,:,:) * tmask(:,:,:)
-            s_bkg(:,:,:) = s_bkg(:,:,:) * tmask(:,:,:)
-         ENDIF
-         !
-         IF ( ln_dyninc ) THEN   
-            CALL iom_get( inum, jpdom_autoglo, 'un', u_bkg )
-            CALL iom_get( inum, jpdom_autoglo, 'vn', v_bkg )
-            u_bkg(:,:,:) = u_bkg(:,:,:) * umask(:,:,:)
-            v_bkg(:,:,:) = v_bkg(:,:,:) * vmask(:,:,:)
-         ENDIF
-         !
-         IF ( ln_sshinc ) THEN
-            CALL iom_get( inum, jpdom_autoglo, 'sshn', ssh_bkg )
-            ssh_bkg(:,:) = ssh_bkg(:,:) * tmask(:,:,1)
-         ENDIF
-         !
-         CALL iom_close( inum )
-         !
-      ENDIF
-      !
-      IF(lwp) WRITE(numout,*) '   ==>>>   Euler time step switch is ', l_1st_euler
-      !
-      IF( lk_asminc ) THEN                            !==  data assimilation  ==!
-         IF( ln_bkgwri )   CALL asm_bkg_wri( nit000 - 1, Kmm )      ! Output background fields
-         IF( ln_asmdin ) THEN                                  ! Direct initialization
-            IF( ln_trainc )   CALL tra_asm_inc( nit000 - 1, Kbb, Kmm, ts    , Krhs )      ! Tracers
-            IF( ln_dyninc )   CALL dyn_asm_inc( nit000 - 1, Kbb, Kmm, uu, vv, Krhs )      ! Dynamics
-            IF( ln_sshinc )   CALL ssh_asm_inc( nit000 - 1, Kbb, Kmm )                    ! SSH
-         ENDIF
-      ENDIF
-      !
-   END SUBROUTINE asm_inc_init
-   
-   
-   SUBROUTINE tra_asm_inc( kt, Kbb, Kmm, pts, Krhs )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE tra_asm_inc  ***
-      !!          
-      !! ** Purpose : Apply the tracer (T and S) assimilation increments
-      !!
-      !! ** Method  : Direct initialization or Incremental Analysis Updating
-      !!
-      !! ** Action  : 
-      !!----------------------------------------------------------------------
-      INTEGER                                  , INTENT(in   ) :: kt             ! Current time step
-      INTEGER                                  , INTENT(in   ) :: Kbb, Kmm, Krhs ! Time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts,jpt), INTENT(inout) :: pts            ! active tracers and RHS of tracer equation
-      !
-      INTEGER  :: ji, jj, jk
-      INTEGER  :: it
-      REAL(wp) :: zincwgt  ! IAU weight for current time step
-      REAL (wp), DIMENSION(jpi,jpj,jpk) :: fzptnz ! 3d freezing point values
-      !!----------------------------------------------------------------------
-      !
-      ! freezing point calculation taken from oc_fz_pt (but calculated for all depths) 
-      ! used to prevent the applied increments taking the temperature below the local freezing point 
-      DO jk = 1, jpkm1
-        CALL eos_fzp( pts(:,:,jk,jp_sal,Kmm), fzptnz(:,:,jk), gdept(:,:,jk,Kmm) )
-      END DO
-         !
-         !                             !--------------------------------------
-      IF ( ln_asmiau ) THEN            ! Incremental Analysis Updating
-         !                             !--------------------------------------
-         !
-         IF ( ( kt >= nitiaustr_r ).AND.( kt <= nitiaufin_r ) ) THEN
-            !
-            it = kt - nit000 + 1
-            zincwgt = wgtiau(it) / rn_Dt   ! IAU weight for the current time step
-            !
-            IF(lwp) THEN
-               WRITE(numout,*) 
-               WRITE(numout,*) 'tra_asm_inc : Tracer IAU at time step = ', kt,' with IAU weight = ', wgtiau(it)
-               WRITE(numout,*) '~~~~~~~~~~~~'
-            ENDIF
-            !
-            ! Update the tracer tendencies
-            DO jk = 1, jpkm1
-               IF (ln_temnofreeze) THEN
-                  ! Do not apply negative increments if the temperature will fall below freezing
-                  WHERE(t_bkginc(:,:,jk) > 0.0_wp .OR. &
-                     &   pts(:,:,jk,jp_tem,Kmm) + pts(:,:,jk,jp_tem,Krhs) + t_bkginc(:,:,jk) * wgtiau(it) > fzptnz(:,:,jk) ) 
-                     pts(:,:,jk,jp_tem,Krhs) = pts(:,:,jk,jp_tem,Krhs) + t_bkginc(:,:,jk) * zincwgt  
-                  END WHERE
-               ELSE
-                  pts(:,:,jk,jp_tem,Krhs) = pts(:,:,jk,jp_tem,Krhs) + t_bkginc(:,:,jk) * zincwgt  
-               ENDIF
-               IF (ln_salfix) THEN
-                  ! Do not apply negative increments if the salinity will fall below a specified
-                  ! minimum value salfixmin
-                  WHERE(s_bkginc(:,:,jk) > 0.0_wp .OR. &
-                     &   pts(:,:,jk,jp_sal,Kmm) + pts(:,:,jk,jp_sal,Krhs) + s_bkginc(:,:,jk) * wgtiau(it) > salfixmin ) 
-                     pts(:,:,jk,jp_sal,Krhs) = pts(:,:,jk,jp_sal,Krhs) + s_bkginc(:,:,jk) * zincwgt
-                  END WHERE
-               ELSE
-                  pts(:,:,jk,jp_sal,Krhs) = pts(:,:,jk,jp_sal,Krhs) + s_bkginc(:,:,jk) * zincwgt
-               ENDIF
-            END DO
-            !
-         ENDIF
-         !
-         IF ( kt == nitiaufin_r + 1  ) THEN   ! For bias crcn to work
-            DEALLOCATE( t_bkginc )
-            DEALLOCATE( s_bkginc )
-         ENDIF
-         !                             !--------------------------------------
-      ELSEIF ( ln_asmdin ) THEN        ! Direct Initialization
-         !                             !--------------------------------------
-         !            
-         IF ( kt == nitdin_r ) THEN
-            !
-            l_1st_euler = .TRUE.  ! Force Euler forward step
-            !
-            ! Initialize the now fields with the background + increment
-            IF (ln_temnofreeze) THEN
-               ! Do not apply negative increments if the temperature will fall below freezing
-               WHERE( t_bkginc(:,:,:) > 0.0_wp .OR. pts(:,:,:,jp_tem,Kmm) + t_bkginc(:,:,:) > fzptnz(:,:,:) ) 
-                  pts(:,:,:,jp_tem,Kmm) = t_bkg(:,:,:) + t_bkginc(:,:,:)   
-               END WHERE
-            ELSE
-               pts(:,:,:,jp_tem,Kmm) = t_bkg(:,:,:) + t_bkginc(:,:,:)   
-            ENDIF
-            IF (ln_salfix) THEN
-               ! Do not apply negative increments if the salinity will fall below a specified
-               ! minimum value salfixmin
-               WHERE( s_bkginc(:,:,:) > 0.0_wp .OR. pts(:,:,:,jp_sal,Kmm) + s_bkginc(:,:,:) > salfixmin ) 
-                  pts(:,:,:,jp_sal,Kmm) = s_bkg(:,:,:) + s_bkginc(:,:,:)   
-               END WHERE
-            ELSE
-               pts(:,:,:,jp_sal,Kmm) = s_bkg(:,:,:) + s_bkginc(:,:,:)   
-            ENDIF
-
-            pts(:,:,:,:,Kbb) = pts(:,:,:,:,Kmm)                 ! Update before fields
-
-            CALL eos( pts(:,:,:,:,Kbb), rhd, rhop, gdept_0(:,:,:) )  ! Before potential and in situ densities
-!!gm  fabien
-!            CALL eos( pts(:,:,:,:,Kbb), rhd, rhop )                ! Before potential and in situ densities
-!!gm
-
-            IF( ln_zps .AND. .NOT. lk_c1d .AND. .NOT. ln_isfcav)           &
-               &  CALL zps_hde    ( kt, Kmm, jpts, pts(:,:,:,:,Kbb), gtsu, gtsv,        &  ! Partial steps: before horizontal gradient
-               &                              rhd, gru , grv               )  ! of t, s, rd at the last ocean level
-            IF( ln_zps .AND. .NOT. lk_c1d .AND.       ln_isfcav)                       &
-               &  CALL zps_hde_isf( nit000, Kmm, jpts, pts(:,:,:,:,Kbb), gtsu, gtsv, gtui, gtvi,    &  ! Partial steps for top cell (ISF)
-               &                                  rhd, gru , grv , grui, grvi          )  ! of t, s, rd at the last ocean level
-
-            DEALLOCATE( t_bkginc )
-            DEALLOCATE( s_bkginc )
-            DEALLOCATE( t_bkg    )
-            DEALLOCATE( s_bkg    )
-         ENDIF
-         !  
-      ENDIF
-      ! Perhaps the following call should be in step
-      IF ( ln_seaiceinc  )   CALL seaice_asm_inc ( kt )   ! apply sea ice concentration increment
-      !
-   END SUBROUTINE tra_asm_inc
-
-
-   SUBROUTINE dyn_asm_inc( kt, Kbb, Kmm, puu, pvv, Krhs )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE dyn_asm_inc  ***
-      !!          
-      !! ** Purpose : Apply the dynamics (u and v) assimilation increments.
-      !!
-      !! ** Method  : Direct initialization or Incremental Analysis Updating.
-      !!
-      !! ** Action  : 
-      !!----------------------------------------------------------------------
-      INTEGER                             , INTENT( in )  ::  kt             ! ocean time-step index
-      INTEGER                             , INTENT( in )  ::  Kbb, Kmm, Krhs ! ocean time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) ::  puu, pvv       ! ocean velocities and RHS of momentum equation
-      !
-      INTEGER :: jk
-      INTEGER :: it
-      REAL(wp) :: zincwgt  ! IAU weight for current time step
-      !!----------------------------------------------------------------------
-      !
-      !                          !--------------------------------------------
-      IF ( ln_asmiau ) THEN      ! Incremental Analysis Updating
-         !                       !--------------------------------------------
-         !
-         IF ( ( kt >= nitiaustr_r ).AND.( kt <= nitiaufin_r ) ) THEN
-            !
-            it = kt - nit000 + 1
-            zincwgt = wgtiau(it) / rn_Dt   ! IAU weight for the current time step
-            !
-            IF(lwp) THEN
-               WRITE(numout,*) 
-               WRITE(numout,*) 'dyn_asm_inc : Dynamics IAU at time step = ', kt,' with IAU weight = ', wgtiau(it)
-               WRITE(numout,*) '~~~~~~~~~~~~'
-            ENDIF
-            !
-            ! Update the dynamic tendencies
-            DO jk = 1, jpkm1
-               puu(:,:,jk,Krhs) = puu(:,:,jk,Krhs) + u_bkginc(:,:,jk) * zincwgt
-               pvv(:,:,jk,Krhs) = pvv(:,:,jk,Krhs) + v_bkginc(:,:,jk) * zincwgt
-            END DO
-            !
-            IF ( kt == nitiaufin_r ) THEN
-               DEALLOCATE( u_bkginc )
-               DEALLOCATE( v_bkginc )
-            ENDIF
-            !
-         ENDIF
-         !                          !-----------------------------------------
-      ELSEIF ( ln_asmdin ) THEN     ! Direct Initialization
-         !                          !-----------------------------------------
-         !         
-         IF ( kt == nitdin_r ) THEN
-            !
-            l_1st_euler = .TRUE.                    ! Force Euler forward step
-            !
-            ! Initialize the now fields with the background + increment
-            puu(:,:,:,Kmm) = u_bkg(:,:,:) + u_bkginc(:,:,:)
-            pvv(:,:,:,Kmm) = v_bkg(:,:,:) + v_bkginc(:,:,:)  
-            !
-            puu(:,:,:,Kbb) = puu(:,:,:,Kmm)         ! Update before fields
-            pvv(:,:,:,Kbb) = pvv(:,:,:,Kmm)
-            !
-            DEALLOCATE( u_bkg    )
-            DEALLOCATE( v_bkg    )
-            DEALLOCATE( u_bkginc )
-            DEALLOCATE( v_bkginc )
-         ENDIF
-         !
-      ENDIF
-      !
-   END SUBROUTINE dyn_asm_inc
-
-
-   SUBROUTINE ssh_asm_inc( kt, Kbb, Kmm )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE ssh_asm_inc  ***
-      !!          
-      !! ** Purpose : Apply the sea surface height assimilation increment.
-      !!
-      !! ** Method  : Direct initialization or Incremental Analysis Updating.
-      !!
-      !! ** Action  : 
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(IN) :: kt         ! Current time step
-      INTEGER, INTENT(IN) :: Kbb, Kmm   ! Current time step
-      !
-      INTEGER :: it
-      INTEGER :: jk
-      REAL(wp) :: zincwgt  ! IAU weight for current time step
-      !!----------------------------------------------------------------------
-      !
-      !                             !-----------------------------------------
-      IF ( ln_asmiau ) THEN         ! Incremental Analysis Updating
-         !                          !-----------------------------------------
-         !
-         IF ( ( kt >= nitiaustr_r ).AND.( kt <= nitiaufin_r ) ) THEN
-            !
-            it = kt - nit000 + 1
-            zincwgt = wgtiau(it) / rn_Dt   ! IAU weight for the current time step
-            !
-            IF(lwp) THEN
-               WRITE(numout,*) 
-               WRITE(numout,*) 'ssh_asm_inc : SSH IAU at time step = ', &
-                  &  kt,' with IAU weight = ', wgtiau(it)
-               WRITE(numout,*) '~~~~~~~~~~~~'
-            ENDIF
-            !
-            ! Save the tendency associated with the IAU weighted SSH increment
-            ! (applied in dynspg.*)
-#if defined key_asminc
-            ssh_iau(:,:) = ssh_bkginc(:,:) * zincwgt
-#endif
-            !
-         ELSE IF( kt == nitiaufin_r+1 ) THEN
-            !
-            ! test on ssh_bkginc needed as ssh_asm_inc is called twice by time step
-            IF (ALLOCATED(ssh_bkginc)) DEALLOCATE( ssh_bkginc )
-            !
-#if defined key_asminc
-            ssh_iau(:,:) = 0._wp
-#endif
-            !
-         ENDIF
-         !                          !-----------------------------------------
-      ELSEIF ( ln_asmdin ) THEN     ! Direct Initialization
-         !                          !-----------------------------------------
-         !
-         IF ( kt == nitdin_r ) THEN
-            !
-            l_1st_euler = .TRUE.                            ! Force Euler forward step
-            !
-            ssh(:,:,Kmm) = ssh_bkg(:,:) + ssh_bkginc(:,:)   ! Initialize the now fields the background + increment
-            !
-            ssh(:,:,Kbb) = ssh(:,:,Kmm)                        ! Update before fields
-!!st11
-#if ! defined key_qco
-            e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-#endif
-!!st11
-!!gm why not e3u(:,:,:,Kbb), e3v(:,:,:,Kbb), gdept(:,:,jk,Kbb) ????
-            !
-            DEALLOCATE( ssh_bkg    )
-            DEALLOCATE( ssh_bkginc )
-            !
-         ENDIF
-         !
-      ENDIF
-      !
-   END SUBROUTINE ssh_asm_inc
-
-
-   SUBROUTINE ssh_asm_div( kt, Kbb, Kmm, phdivn )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE ssh_asm_div  ***
-      !!
-      !! ** Purpose :   ssh increment with z* is incorporated via a correction of the local divergence          
-      !!                across all the water column
-      !!
-      !! ** Method  :
-      !!                CAUTION : sshiau is positive (inflow) decreasing the
-      !!                          divergence and expressed in m/s
-      !!
-      !! ** Action  :   phdivn   decreased by the ssh increment
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(IN) :: kt                               ! ocean time-step index
-      INTEGER, INTENT(IN) :: Kbb, Kmm                         ! time level indices
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   phdivn   ! horizontal divergence
-      !!
-      INTEGER  ::   jk                                        ! dummy loop index
-      REAL(wp), DIMENSION(:,:)  , POINTER       ::   ztim     ! local array
-      !!----------------------------------------------------------------------
-      ! 
-#if defined key_asminc
-      CALL ssh_asm_inc( kt, Kbb, Kmm ) !==   (calculate increments)
-      !
-      IF( ln_linssh ) THEN 
-         phdivn(:,:,1) = phdivn(:,:,1) - ssh_iau(:,:) / e3t(:,:,1,Kmm) * tmask(:,:,1)
-      ELSE 
-         ALLOCATE( ztim(jpi,jpj) )
-         ztim(:,:) = ssh_iau(:,:) / ( ht(:,:) + 1.0 - ssmask(:,:) )
-         DO jk = 1, jpkm1                                 
-            phdivn(:,:,jk) = phdivn(:,:,jk) - ztim(:,:) * tmask(:,:,jk) 
-         END DO
-         !
-         DEALLOCATE(ztim)
-      ENDIF
-#endif
-      !
-   END SUBROUTINE ssh_asm_div
-
-
-   SUBROUTINE seaice_asm_inc( kt, kindic )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE seaice_asm_inc  ***
-      !!          
-      !! ** Purpose : Apply the sea ice assimilation increment.
-      !!
-      !! ** Method  : Direct initialization or Incremental Analysis Updating.
-      !!
-      !! ** Action  : 
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in)           ::   kt       ! Current time step
-      INTEGER, INTENT(in), OPTIONAL ::   kindic   ! flag for disabling the deallocation
-      !
-      INTEGER  ::   it
-      REAL(wp) ::   zincwgt   ! IAU weight for current time step
-#if defined key_si3
-      REAL(wp), DIMENSION(jpi,jpj) ::   zofrld, zohicif, zseaicendg, zhicifinc
-      REAL(wp) ::   zhicifmin = 0.5_wp      ! ice minimum depth in metres
-#endif
-      !!----------------------------------------------------------------------
-      !
-      !                             !-----------------------------------------
-      IF ( ln_asmiau ) THEN         ! Incremental Analysis Updating
-         !                          !-----------------------------------------
-         !
-         IF ( ( kt >= nitiaustr_r ).AND.( kt <= nitiaufin_r ) ) THEN
-            !
-            it = kt - nit000 + 1
-            zincwgt = wgtiau(it)      ! IAU weight for the current time step 
-            ! note this is not a tendency so should not be divided by rn_Dt (as with the tracer and other increments)
-            !
-            IF(lwp) THEN
-               WRITE(numout,*) 
-               WRITE(numout,*) 'seaice_asm_inc : sea ice conc IAU at time step = ', kt,' with IAU weight = ', wgtiau(it)
-               WRITE(numout,*) '~~~~~~~~~~~~'
-            ENDIF
-            !
-            ! Sea-ice : SI3 case
-            !
-#if defined key_si3
-            zofrld (:,:) = 1._wp - at_i(:,:)
-            zohicif(:,:) = hm_i(:,:)
-            !
-            at_i  (:,:) = 1. - MIN( MAX( 1.-at_i  (:,:) - seaice_bkginc(:,:) * zincwgt, 0.0_wp), 1.0_wp)
-            at_i_b(:,:) = 1. - MIN( MAX( 1.-at_i_b(:,:) - seaice_bkginc(:,:) * zincwgt, 0.0_wp), 1.0_wp)
-            fr_i(:,:) = at_i(:,:)        ! adjust ice fraction
-            !
-            zseaicendg(:,:) = zofrld(:,:) - (1. - at_i(:,:))   ! find out actual sea ice nudge applied
-            !
-            ! Nudge sea ice depth to bring it up to a required minimum depth
-            WHERE( zseaicendg(:,:) > 0.0_wp .AND. hm_i(:,:) < zhicifmin ) 
-               zhicifinc(:,:) = (zhicifmin - hm_i(:,:)) * zincwgt    
-            ELSEWHERE
-               zhicifinc(:,:) = 0.0_wp
-            END WHERE
-            !
-            ! nudge ice depth
-            hm_i (:,:) = hm_i (:,:) + zhicifinc(:,:)
-            !
-            ! seaice salinity balancing (to add)
-#endif
-            !
-#if defined key_cice && defined key_asminc
-            ! Sea-ice : CICE case. Pass ice increment tendency into CICE
-            ndaice_da(:,:) = seaice_bkginc(:,:) * zincwgt / rn_Dt
-#endif
-            !
-            IF ( kt == nitiaufin_r ) THEN
-               DEALLOCATE( seaice_bkginc )
-            ENDIF
-            !
-         ELSE
-            !
-#if defined key_cice && defined key_asminc
-            ndaice_da(:,:) = 0._wp        ! Sea-ice : CICE case. Zero ice increment tendency into CICE
-#endif
-            !
-         ENDIF
-         !                          !-----------------------------------------
-      ELSEIF ( ln_asmdin ) THEN     ! Direct Initialization
-         !                          !-----------------------------------------
-         !
-         IF ( kt == nitdin_r ) THEN
-            !
-            l_1st_euler = .TRUE.              ! Force Euler forward step
-            !
-            ! Sea-ice : SI3 case
-            !
-#if defined key_si3
-            zofrld (:,:) = 1._wp - at_i(:,:)
-            zohicif(:,:) = hm_i(:,:)
-            ! 
-            ! Initialize the now fields the background + increment
-            at_i(:,:) = 1. - MIN( MAX( 1.-at_i(:,:) - seaice_bkginc(:,:), 0.0_wp), 1.0_wp)
-            at_i_b(:,:) = at_i(:,:) 
-            fr_i(:,:) = at_i(:,:)        ! adjust ice fraction
-            !
-            zseaicendg(:,:) = zofrld(:,:) - (1. - at_i(:,:))   ! find out actual sea ice nudge applied
-            !
-            ! Nudge sea ice depth to bring it up to a required minimum depth
-            WHERE( zseaicendg(:,:) > 0.0_wp .AND. hm_i(:,:) < zhicifmin ) 
-               zhicifinc(:,:) = zhicifmin - hm_i(:,:)
-            ELSEWHERE
-               zhicifinc(:,:) = 0.0_wp
-            END WHERE
-            !
-            ! nudge ice depth
-            hm_i (:,:) = hm_i (:,:) + zhicifinc(:,:)
-            !
-            ! seaice salinity balancing (to add)
-#endif
-            !
-#if defined key_cice && defined key_asminc
-            ! Sea-ice : CICE case. Pass ice increment tendency into CICE
-           ndaice_da(:,:) = seaice_bkginc(:,:) / rn_Dt
-#endif
-            IF ( .NOT. PRESENT(kindic) ) THEN
-               DEALLOCATE( seaice_bkginc )
-            END IF
-            !
-         ELSE
-            !
-#if defined key_cice && defined key_asminc
-            ndaice_da(:,:) = 0._wp     ! Sea-ice : CICE case. Zero ice increment tendency into CICE
-#endif
-            !
-         ENDIF
-
-!#if defined defined key_si3 || defined key_cice
-!
-!            IF (ln_seaicebal ) THEN       
-!             !! balancing salinity increments
-!             !! simple case from limflx.F90 (doesn't include a mass flux)
-!             !! assumption is that as ice concentration is reduced or increased
-!             !! the snow and ice depths remain constant
-!             !! note that snow is being created where ice concentration is being increased
-!             !! - could be more sophisticated and
-!             !! not do this (but would need to alter h_snow)
-!
-!             usave(:,:,:)=sb(:,:,:)   ! use array as a temporary store
-!
-!             DO jj = 1, jpj
-!               DO ji = 1, jpi 
-!           ! calculate change in ice and snow mass per unit area
-!           ! positive values imply adding salt to the ocean (results from ice formation)
-!           ! fwf : ice formation and melting
-!
-!                 zfons = ( -nfresh_da(ji,jj)*soce + nfsalt_da(ji,jj) )*rn_Dt
-!
-!           ! change salinity down to mixed layer depth
-!                 mld=hmld_kara(ji,jj)
-!
-!           ! prevent small mld
-!           ! less than 10m can cause salinity instability 
-!                 IF (mld < 10) mld=10
-!
-!           ! set to bottom of a level 
-!                 DO jk = jpk-1, 2, -1
-!                   IF ((mld > gdepw(ji,jj,jk,Kmm)) .and. (mld < gdepw(ji,jj,jk+1,Kmm))) THEN 
-!                     mld=gdepw(ji,jj,jk+1,Kmm)
-!                     jkmax=jk
-!                   ENDIF
-!                 ENDDO
-!
-!            ! avoid applying salinity balancing in shallow water or on land
-!            ! 
-!
-!            ! dsal_ocn (psu kg m^-2) / (kg m^-3 * m)
-!
-!                 dsal_ocn=0.0_wp
-!                 sal_thresh=5.0_wp        ! minimum salinity threshold for salinity balancing
-!
-!                 if (tmask(ji,jj,1) > 0 .AND. tmask(ji,jj,jkmax) > 0 ) &
-!                              dsal_ocn = zfons / (rhop(ji,jj,1) * mld)
-!
-!           ! put increments in for levels in the mixed layer
-!           ! but prevent salinity below a threshold value 
-!
-!                   DO jk = 1, jkmax              
-!
-!                     IF (dsal_ocn > 0.0_wp .or. sb(ji,jj,jk)+dsal_ocn > sal_thresh) THEN 
-!                           sb(ji,jj,jk) = sb(ji,jj,jk) + dsal_ocn
-!                           sn(ji,jj,jk) = sn(ji,jj,jk) + dsal_ocn
-!                     ENDIF
-!
-!                   ENDDO
-!
-!      !            !  salt exchanges at the ice/ocean interface
-!      !            zpmess         = zfons / rDt_ice    ! rDt_ice is ice timestep
-!      !
-!      !! Adjust fsalt. A +ve fsalt means adding salt to ocean
-!      !!           fsalt(ji,jj) =  fsalt(ji,jj) + zpmess     ! adjust fsalt  
-!      !!               
-!      !!           emps(ji,jj) = emps(ji,jj) + zpmess        ! or adjust emps (see icestp1d) 
-!      !!                                                     ! E-P (kg m-2 s-2)
-!      !            emp(ji,jj) = emp(ji,jj) + zpmess          ! E-P (kg m-2 s-2)
-!               ENDDO !ji
-!             ENDDO !jj!
-!
-!            ENDIF !ln_seaicebal
-!
-!#endif
-         !
-      ENDIF
-      !
-   END SUBROUTINE seaice_asm_inc
-   
-   !!======================================================================
-END MODULE asminc
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/diawri.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/diawri.F90	(revision 13603)
+++ 	(revision )
@@ -1,985 +1,0 @@
-MODULE diawri
-   !!======================================================================
-   !!                     ***  MODULE  diawri  ***
-   !! Ocean diagnostics :  write ocean output files
-   !!=====================================================================
-   !! History :  OPA  ! 1991-03  (M.-A. Foujols)  Original code
-   !!            4.0  ! 1991-11  (G. Madec)
-   !!                 ! 1992-06  (M. Imbard)  correction restart file
-   !!                 ! 1992-07  (M. Imbard)  split into diawri and rstwri
-   !!                 ! 1993-03  (M. Imbard)  suppress writibm
-   !!                 ! 1998-01  (C. Levy)  NETCDF format using ioipsl INTERFACE
-   !!                 ! 1999-02  (E. Guilyardi)  name of netCDF files + variables
-   !!            8.2  ! 2000-06  (M. Imbard)  Original code (diabort.F)
-   !!   NEMO     1.0  ! 2002-06  (A.Bozec, E. Durand)  Original code (diainit.F)
-   !!             -   ! 2002-09  (G. Madec)  F90: Free form and module
-   !!             -   ! 2002-12  (G. Madec)  merge of diabort and diainit, F90
-   !!                 ! 2005-11  (V. Garnier) Surface pressure gradient organization
-   !!            3.2  ! 2008-11  (B. Lemaire) creation from old diawri
-   !!            3.7  ! 2014-01  (G. Madec) remove eddy induced velocity from no-IOM output
-   !!                 !                     change name of output variables in dia_wri_state
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dia_wri       : create the standart output files
-   !!   dia_wri_state : create an output NetCDF file for a single instantaeous ocean state and forcing fields
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers 
-   USE isf_oce
-   USE isfcpl
-   USE abl            ! abl variables in case ln_abl = .true.
-   USE dom_oce        ! ocean space and time domain
-   USE phycst         ! physical constants
-   USE dianam         ! build name of file (routine)
-   USE diahth         ! thermocline diagnostics
-   USE dynadv   , ONLY: ln_dynadv_vec
-   USE icb_oce        ! Icebergs
-   USE icbdia         ! Iceberg budgets
-   USE ldftra         ! lateral physics: eddy diffusivity coef.
-   USE ldfdyn         ! lateral physics: eddy viscosity   coef.
-   USE sbc_oce        ! Surface boundary condition: ocean fields
-   USE sbc_ice        ! Surface boundary condition: ice fields
-   USE sbcssr         ! restoring term toward SST/SSS climatology
-   USE sbcwave        ! wave parameters
-   USE wet_dry        ! wetting and drying
-   USE zdf_oce        ! ocean vertical physics
-   USE zdfdrg         ! ocean vertical physics: top/bottom friction
-   USE zdfmxl         ! mixed layer
-   !
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE in_out_manager ! I/O manager
-   USE dia25h         ! 25h Mean output
-   USE iom            ! 
-   USE ioipsl         ! 
-
-#if defined key_si3
-   USE ice 
-   USE icewri 
-#endif
-   USE lib_mpp         ! MPP library
-   USE timing          ! preformance summary
-   USE diu_bulk        ! diurnal warm layer
-   USE diu_coolskin    ! Cool skin
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dia_wri                 ! routines called by step.F90
-   PUBLIC   dia_wri_state
-   PUBLIC   dia_wri_alloc           ! Called by nemogcm module
-#if ! defined key_iomput   
-   PUBLIC   dia_wri_alloc_abl       ! Called by sbcabl  module (if ln_abl = .true.)
-#endif
-   INTEGER ::   nid_T, nz_T, nh_T, ndim_T, ndim_hT   ! grid_T file
-   INTEGER ::          nb_T              , ndim_bT   ! grid_T file
-   INTEGER ::   nid_U, nz_U, nh_U, ndim_U, ndim_hU   ! grid_U file
-   INTEGER ::   nid_V, nz_V, nh_V, ndim_V, ndim_hV   ! grid_V file
-   INTEGER ::   nid_W, nz_W, nh_W                    ! grid_W file
-   INTEGER ::   nid_A, nz_A, nh_A, ndim_A, ndim_hA   ! grid_ABL file   
-   INTEGER ::   ndex(1)                              ! ???
-   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_hT, ndex_hU, ndex_hV
-   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_hA, ndex_A ! ABL
-   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_T, ndex_U, ndex_V
-   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_bT
-
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-!!st12
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: diawri.F90 12667 2020-04-03 14:22:29Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-#if defined key_iomput
-   !!----------------------------------------------------------------------
-   !!   'key_iomput'                                        use IOM library
-   !!----------------------------------------------------------------------
-   INTEGER FUNCTION dia_wri_alloc()
-      !
-      dia_wri_alloc = 0
-      !
-   END FUNCTION dia_wri_alloc
-
-   
-   SUBROUTINE dia_wri( kt, Kmm )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dia_wri  ***
-      !!                   
-      !! ** Purpose :   Standard output of opa: dynamics and tracer fields 
-      !!      NETCDF format is used by default 
-      !!
-      !! ** Method  :  use iom_put
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-      INTEGER, INTENT( in ) ::   Kmm     ! ocean time level index
-      !!
-      INTEGER ::   ji, jj, jk       ! dummy loop indices
-      INTEGER ::   ikbot            ! local integer
-      REAL(wp)::   zztmp , zztmpx   ! local scalar
-      REAL(wp)::   zztmp2, zztmpy   !   -      -
-      REAL(wp)::   ze3              !   -      -
-      REAL(wp), DIMENSION(jpi,jpj)     ::   z2d   ! 2D workspace
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   z3d   ! 3D workspace
-      !!----------------------------------------------------------------------
-      ! 
-      IF( ln_timing )   CALL timing_start('dia_wri')
-      ! 
-      ! Output the initial state and forcings
-      IF( ninist == 1 ) THEN                       
-         CALL dia_wri_state( Kmm, 'output.init' )
-         ninist = 0
-      ENDIF
-
-      ! Output of initial vertical scale factor
-      CALL iom_put("e3t_0", e3t_0(:,:,:) )
-      CALL iom_put("e3u_0", e3u_0(:,:,:) )
-      CALL iom_put("e3v_0", e3v_0(:,:,:) )
-      !
-!!st13
-#if ! defined key_qco
-      IF ( iom_use("e3t") .OR. iom_use("e3tdef") ) THEN  ! time-varying e3t
-         DO jk = 1, jpk
-            z3d(:,:,jk) =  e3t(:,:,jk,Kmm)
-         END DO
-         CALL iom_put( "e3t"     ,     z3d(:,:,:) )
-         CALL iom_put( "e3tdef"  , ( ( z3d(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2 ) 
-      ENDIF 
-      IF ( iom_use("e3u") ) THEN                         ! time-varying e3u
-         DO jk = 1, jpk
-            z3d(:,:,jk) =  e3u(:,:,jk,Kmm)
-         END DO 
-         CALL iom_put( "e3u" , z3d(:,:,:) )
-      ENDIF
-      IF ( iom_use("e3v") ) THEN                         ! time-varying e3v
-         DO jk = 1, jpk
-            z3d(:,:,jk) =  e3v(:,:,jk,Kmm)
-         END DO 
-         CALL iom_put( "e3v" , z3d(:,:,:) )
-      ENDIF
-      IF ( iom_use("e3w") ) THEN                         ! time-varying e3w
-         DO jk = 1, jpk
-            z3d(:,:,jk) =  e3w(:,:,jk,Kmm)
-         END DO 
-         CALL iom_put( "e3w" , z3d(:,:,:) )
-      ENDIF
-#endif 
-!!st13
-      IF( ll_wd ) THEN
-         CALL iom_put( "ssh" , (ssh(:,:,Kmm)+ssh_ref)*tmask(:,:,1) )   ! sea surface height (brought back to the reference used for wetting and drying)
-      ELSE
-         CALL iom_put( "ssh" , ssh(:,:,Kmm) )                          ! sea surface height
-      ENDIF
-
-!!an 
-        IF( iom_use("ht") )   &                  ! water column at t-point
-         CALL iom_put( "ht" , ht_0(:,:) + ssh(:,:,Kmm) )
-      !
-      IF( iom_use("hu") )   THEN                   ! water column at u-point
-         z2d(:,:) = 0._wp
-         DO_2D( 1, 0, 1, 0 )  
-            z2d(ji,jj) = 0.5_wp * ( e3t(ji  ,jj,1,Kmm) * e1e2t(ji  ,jj)  &
-               &                  + e3t(ji+1,jj,1,Kmm) * e1e2t(ji+1,jj)  ) * r1_e1e2u(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'U', 1._wp )
-         CALL iom_put( "hu", z2d ) 
-      ENDIF
-     !                    
-      IF( iom_use("hv") )   THEN                  ! water column at v-point
-         z2d(:,:) = 0._wp
-         DO_2D( 1, 0, 1, 0 )  
-            z2d(ji,jj) = 0.5_wp * (  e3t(ji,jj+1,1,Kmm) * e1e2t(ji,jj+1)   &
-              &                    + e3t(ji,jj  ,1,Kmm) * e1e2t(ji,jj  )   ) * r1_e1e2v(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'V', 1._wp )
-         CALL iom_put( "hv", z2d )    
-      ENDIF             
-      !
-      IF( iom_use("hf") )  THEN                    ! water column at f-point
-         z2d(:,:) = 0._wp
-         DO_2D( 1, 0, 1, 0 )  
-            z2d(ji,jj) = 0.25_wp * (  e3t(ji,jj+1,1,Kmm) * e1e2t(ji,jj+1) + e3t(ji+1,jj+1,1,Kmm) * e1e2t(ji+1,jj+1)    &
-              &                     + e3t(ji,jj  ,1,Kmm) * e1e2t(ji,jj  ) + e3t(ji+1,jj  ,1,Kmm) * e1e2t(ji+1,jj  )  ) * r1_e1e2f(ji,jj)
-         END_2D
-         z2d(:,:) = z2d(:,:) * ssfmask(:,:)
-         CALL lbc_lnk( 'diawri', z2d, 'F', 1._wp )
-         CALL iom_put( "hf", z2d )   
-      ENDIF              
-!!an
-
-      IF( iom_use("wetdep") )   &                  ! wet depth
-         CALL iom_put( "wetdep" , ht_0(:,:) + ssh(:,:,Kmm) )
-
-      IF ( iom_use("taubot") ) THEN                ! bottom stress
-         zztmp = rho0 * 0.25
-         z2d(:,:) = 0._wp
-         DO_2D( 0, 0, 0, 0 )
-            zztmp2 = (  ( rCdU_bot(ji+1,jj)+rCdU_bot(ji  ,jj) ) * uu(ji  ,jj,mbku(ji  ,jj),Kmm)  )**2   &
-               &   + (  ( rCdU_bot(ji  ,jj)+rCdU_bot(ji-1,jj) ) * uu(ji-1,jj,mbku(ji-1,jj),Kmm)  )**2   &
-               &   + (  ( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj  ) ) * vv(ji,jj  ,mbkv(ji,jj  ),Kmm)  )**2   &
-               &   + (  ( rCdU_bot(ji,jj  )+rCdU_bot(ji,jj-1) ) * vv(ji,jj-1,mbkv(ji,jj-1),Kmm)  )**2
-            z2d(ji,jj) = zztmp * SQRT( zztmp2 ) * tmask(ji,jj,1) 
-            !
-         END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'T', 1. )
-         CALL iom_put( "taubot", z2d )           
-      ENDIF
-      !  
-      CALL iom_put(  "ssu" , uu(:,:,1,Kmm) )            ! surface i-current
-      CALL iom_put(  "ssv" , vv(:,:,1,Kmm) )            ! surface j-current
-      CALL iom_put(  "woce", ww )                       ! vertical velocity
-      !
-      
-      IF ( iom_use("sKE") ) THEN                        ! surface kinetic energy at T point
-         z2d(:,:) = 0._wp
-         DO_2D( 0, 0, 0, 0 )
-            z2d(ji,jj) =    0.25_wp * ( uu(ji  ,jj,1,Kmm) * uu(ji  ,jj,1,Kmm) * e1e2u(ji  ,jj) * e3u(ji  ,jj,1,Kmm)  &
-               &                      + uu(ji-1,jj,1,Kmm) * uu(ji-1,jj,1,Kmm) * e1e2u(ji-1,jj) * e3u(ji-1,jj,1,Kmm)  &
-               &                      + vv(ji,jj  ,1,Kmm) * vv(ji,jj  ,1,Kmm) * e1e2v(ji,jj  ) * e3v(ji,jj  ,1,Kmm)  & 
-               &                      + vv(ji,jj-1,1,Kmm) * vv(ji,jj-1,1,Kmm) * e1e2v(ji,jj-1) * e3v(ji,jj-1,1,Kmm)  )  &
-               &                    * r1_e1e2t(ji,jj) / e3t(ji,jj,1,Kmm) * tmask(ji,jj,1)
-         END_2D
-         !
-         CALL lbc_lnk( 'diawri', z2d, 'T', 1. )
-         IF ( iom_use("sKE" ) )  CALL iom_put( "sKE" , z2d )   
-                           
-      ENDIF
-           
-!!an sKEf
-      IF ( iom_use("sKEf") ) THEN                        ! surface kinetic energy at F point
-         z2d(:,:) = 0._wp                                ! CAUTION : only valid in SWE, not with bathymetry
-         DO_2D( 0, 0, 0, 0 )
-            z2d(ji,jj) =    0.25_wp * ( uu(ji,jj  ,1,Kmm) * uu(ji,jj  ,1,Kmm) * e1e2u(ji,jj  ) * e3u(ji,jj  ,1,Kmm)  &
-               &                      + uu(ji,jj+1,1,Kmm) * uu(ji,jj+1,1,Kmm) * e1e2u(ji,jj+1) * e3u(ji,jj+1,1,Kmm)  &
-               &                      + vv(ji  ,jj,1,Kmm) * vv(ji,jj  ,1,Kmm) * e1e2v(ji  ,jj) * e3v(ji  ,jj,1,Kmm)  & 
-               &                      + vv(ji+1,jj,1,Kmm) * vv(ji+1,jj,1,Kmm) * e1e2v(ji+1,jj) * e3v(ji+1,jj,1,Kmm)  )  &
-               &                    * r1_e1e2f(ji,jj) / e3f(ji,jj,1) * ssfmask(ji,jj)
-         END_2D
-         !
-         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
-         CALL iom_put( "sKEf", z2d )                     
-      ENDIF
-!!an
-      !
-      CALL iom_put( "hdiv", hdiv )                  ! Horizontal divergence
-      !
-      ! Output of vorticity terms
-      IF ( iom_use("relvor")    .OR. iom_use("plavor")    .OR.   &
-         & iom_use("relpotvor") .OR. iom_use("abspotvor") .OR.   &
-         & iom_use("Ens")                                        ) THEN
-         !
-         z2d(:,:) = 0._wp 
-         ze3 = 0._wp 
-         DO_2D( 1, 0, 1, 0 )
-            z2d(ji,jj) = (   e2v(ji+1,jj  ) * vv(ji+1,jj  ,1,Kmm) - e2v(ji,jj) * vv(ji,jj,1,Kmm)    &
-            &              - e1u(ji  ,jj+1) * uu(ji  ,jj+1,1,Kmm) + e1u(ji,jj) * uu(ji,jj,1,Kmm)  ) * r1_e1e2f(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
-         CALL iom_put( "relvor", z2d )                  ! relative vorticity ( zeta ) 
-         !
-         CALL iom_put( "plavor", ff_f )                 ! planetary vorticity ( f )
-         !
-         DO_2D( 1, 0, 1, 0 )  
-            ze3 = (  e3t(ji,jj+1,1,Kmm) * e1e2t(ji,jj+1) + e3t(ji+1,jj+1,1,Kmm) * e1e2t(ji+1,jj+1)    &
-              &    + e3t(ji,jj  ,1,Kmm) * e1e2t(ji,jj  ) + e3t(ji+1,jj  ,1,Kmm) * e1e2t(ji+1,jj  )  ) * r1_e1e2f(ji,jj)
-            IF( ze3 /= 0._wp ) THEN   ;   ze3 = 4._wp / ze3
-            ELSE                      ;   ze3 = 0._wp
-            ENDIF
-            z2d(ji,jj) = ze3 * z2d(ji,jj) 
-         END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
-         CALL iom_put( "relpotvor", z2d )                  ! relative potential vorticity (zeta/h)
-         !
-         DO_2D( 1, 0, 1, 0 )
-            ze3 = (  e3t(ji,jj+1,1,Kmm) * e1e2t(ji,jj+1) + e3t(ji+1,jj+1,1,Kmm) * e1e2t(ji+1,jj+1)    &
-              &    + e3t(ji,jj  ,1,Kmm) * e1e2t(ji,jj  ) + e3t(ji+1,jj  ,1,Kmm) * e1e2t(ji+1,jj  )  ) * r1_e1e2f(ji,jj)
-            IF( ze3 /= 0._wp ) THEN   ;   ze3 = 4._wp / ze3
-            ELSE                      ;   ze3 = 0._wp
-            ENDIF
-            z2d(ji,jj) = ze3 * ff_f(ji,jj) + z2d(ji,jj) 
-         END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
-         CALL iom_put( "abspotvor", z2d )                  ! absolute potential vorticity ( q )
-         !
-         DO_2D( 1, 0, 1, 0 )  
-            z2d(ji,jj) = 0.5_wp * z2d(ji,jj)  * z2d(ji,jj) 
-         END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
-         CALL iom_put( "Ens", z2d )                        ! potential enstrophy ( 1/2*q2 )
-         !
-      ENDIF
-      
-      !
-      IF( ln_timing )   CALL timing_stop('dia_wri')
-      !
-   END SUBROUTINE dia_wri
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                                  use IOIPSL  library
-   !!----------------------------------------------------------------------
-
-   INTEGER FUNCTION dia_wri_alloc()
-      !!----------------------------------------------------------------------
-      INTEGER, DIMENSION(2) :: ierr
-      !!----------------------------------------------------------------------
-      IF( nn_write == -1 ) THEN
-         dia_wri_alloc = 0
-      ELSE    
-         ierr = 0
-         ALLOCATE( ndex_hT(jpi*jpj) , ndex_T(jpi*jpj*jpk) ,     &
-            &      ndex_hU(jpi*jpj) , ndex_U(jpi*jpj*jpk) ,     &
-            &      ndex_hV(jpi*jpj) , ndex_V(jpi*jpj*jpk) , STAT=ierr(1) )
-         !
-         dia_wri_alloc = MAXVAL(ierr)
-         CALL mpp_sum( 'diawri', dia_wri_alloc )
-         !
-      ENDIF
-      !
-   END FUNCTION dia_wri_alloc
- 
-   INTEGER FUNCTION dia_wri_alloc_abl()
-      !!----------------------------------------------------------------------
-	  ALLOCATE(   ndex_hA(jpi*jpj), ndex_A (jpi*jpj*jpkam1), STAT=dia_wri_alloc_abl)
-      CALL mpp_sum( 'diawri', dia_wri_alloc_abl )
-      !
-   END FUNCTION dia_wri_alloc_abl
-
-   
-   SUBROUTINE dia_wri( kt, Kmm )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dia_wri  ***
-      !!                   
-      !! ** Purpose :   Standard output of opa: dynamics and tracer fields 
-      !!      NETCDF format is used by default 
-      !!
-      !! ** Method  :   At the beginning of the first time step (nit000), 
-      !!      define all the NETCDF files and fields
-      !!      At each time step call histdef to compute the mean if ncessary
-      !!      Each nn_write time step, output the instantaneous or mean fields
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
-      INTEGER, INTENT( in ) ::   Kmm  ! ocean time level index
-      !
-      LOGICAL ::   ll_print = .FALSE.                        ! =T print and flush numout
-      CHARACTER (len=40) ::   clhstnam, clop, clmx           ! local names
-      INTEGER  ::   inum = 11                                ! temporary logical unit
-      INTEGER  ::   ji, jj, jk                               ! dummy loop indices
-      INTEGER  ::   ierr                                     ! error code return from allocation
-      INTEGER  ::   iimi, iima, ipk, it, itmod, ijmi, ijma   ! local integers
-      INTEGER  ::   ipka                                     ! ABL
-      INTEGER  ::   jn, ierror                               ! local integers
-      REAL(wp) ::   zsto, zout, zmax, zjulian                ! local scalars
-      !
-      REAL(wp), DIMENSION(jpi,jpj)   :: zw2d       ! 2D workspace
-!!st14
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zw3d, ze3t, zgdept       ! 3D workspace
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zw3d_abl   ! ABL 3D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( ninist == 1 ) THEN     !==  Output the initial state and forcings  ==!
-         CALL dia_wri_state( Kmm, 'output.init' )
-         ninist = 0
-      ENDIF
-      !
-      IF( nn_write == -1 )   RETURN   ! we will never do any output
-      ! 
-      IF( ln_timing )   CALL timing_start('dia_wri')
-      !
-      ! 0. Initialisation
-      ! -----------------
-
-      ll_print = .FALSE.                  ! local variable for debugging
-      ll_print = ll_print .AND. lwp
-
-      ! Define frequency of output and means
-      clop = "x"         ! no use of the mask value (require less cpu time and otherwise the model crashes)
-#if defined key_diainstant
-      zsto = nn_write * rn_Dt
-      clop = "inst("//TRIM(clop)//")"
-#else
-      zsto=rn_Dt
-      clop = "ave("//TRIM(clop)//")"
-#endif
-      zout = nn_write * rn_Dt
-      zmax = ( nitend - nit000 + 1 ) * rn_Dt
-
-      ! Define indices of the horizontal output zoom and vertical limit storage
-      iimi = 1      ;      iima = jpi
-      ijmi = 1      ;      ijma = jpj
-      ipk = jpk
-      IF(ln_abl) ipka = jpkam1
-
-      ! define time axis
-      it = kt
-      itmod = kt - nit000 + 1
-!!st15
-      ! store e3t for subsitute
-      DO jk = 1, jpk
-         ze3t  (:,:,jk) =  e3t  (:,:,jk,Kmm)
-         zgdept(:,:,jk) =  gdept(:,:,jk,Kmm)
-      END DO
-!!st15
-
-      ! 1. Define NETCDF files and fields at beginning of first time step
-      ! -----------------------------------------------------------------
-
-      IF( kt == nit000 ) THEN
-
-         ! Define the NETCDF files (one per grid)
-
-         ! Compute julian date from starting date of the run
-         CALL ymds2ju( nyear, nmonth, nday, rn_Dt, zjulian )
-         zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
-         IF(lwp)WRITE(numout,*)
-         IF(lwp)WRITE(numout,*) 'Date 0 used :', nit000, ' YEAR ', nyear,   &
-            &                    ' MONTH ', nmonth, ' DAY ', nday, 'Julian day : ', zjulian
-         IF(lwp)WRITE(numout,*) ' indexes of zoom = ', iimi, iima, ijmi, ijma,   &
-                                 ' limit storage in depth = ', ipk
-
-         ! WRITE root name in date.file for use by postpro
-         IF(lwp) THEN
-            CALL dia_nam( clhstnam, nn_write,' ' )
-            CALL ctl_opn( inum, 'date.file', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
-            WRITE(inum,*) clhstnam
-            CLOSE(inum)
-         ENDIF
-
-         ! Define the T grid FILE ( nid_T )
-
-         CALL dia_nam( clhstnam, nn_write, 'grid_T' )
-         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
-         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
-            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, rn_Dt, nh_T, nid_T, domain_id=nidom, snc4chunks=snc4set )
-         CALL histvert( nid_T, "deptht", "Vertical T levels",      &  ! Vertical grid: gdept
-            &           "m", ipk, gdept_1d, nz_T, "down" )
-         !                                                            ! Index of ocean points
-         CALL wheneq( jpi*jpj*ipk, tmask, 1, 1., ndex_T , ndim_T  )      ! volume
-         CALL wheneq( jpi*jpj    , tmask, 1, 1., ndex_hT, ndim_hT )      ! surface
-         !
-         IF( ln_icebergs ) THEN
-            !
-            !! allocation cant go in dia_wri_alloc because ln_icebergs is only set after 
-            !! that routine is called from nemogcm, so do it here immediately before its needed
-            ALLOCATE( ndex_bT(jpi*jpj*nclasses), STAT=ierror )
-            CALL mpp_sum( 'diawri', ierror )
-            IF( ierror /= 0 ) THEN
-               CALL ctl_stop('dia_wri: failed to allocate iceberg diagnostic array')
-               RETURN
-            ENDIF
-            !
-            !! iceberg vertical coordinate is class number
-            CALL histvert( nid_T, "class", "Iceberg class",      &  ! Vertical grid: class
-               &           "number", nclasses, class_num, nb_T )
-            !
-            !! each class just needs the surface index pattern
-            ndim_bT = 3
-            DO jn = 1,nclasses
-               ndex_bT((jn-1)*jpi*jpj+1:jn*jpi*jpj) = ndex_hT(1:jpi*jpj)
-            ENDDO
-            !
-         ENDIF
-
-         ! Define the U grid FILE ( nid_U )
-
-         CALL dia_nam( clhstnam, nn_write, 'grid_U' )
-         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
-         CALL histbeg( clhstnam, jpi, glamu, jpj, gphiu,           &  ! Horizontal grid: glamu and gphiu
-            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, rn_Dt, nh_U, nid_U, domain_id=nidom, snc4chunks=snc4set )
-         CALL histvert( nid_U, "depthu", "Vertical U levels",      &  ! Vertical grid: gdept
-            &           "m", ipk, gdept_1d, nz_U, "down" )
-         !                                                            ! Index of ocean points
-         CALL wheneq( jpi*jpj*ipk, umask, 1, 1., ndex_U , ndim_U  )      ! volume
-         CALL wheneq( jpi*jpj    , umask, 1, 1., ndex_hU, ndim_hU )      ! surface
-
-         ! Define the V grid FILE ( nid_V )
-
-         CALL dia_nam( clhstnam, nn_write, 'grid_V' )                   ! filename
-         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
-         CALL histbeg( clhstnam, jpi, glamv, jpj, gphiv,           &  ! Horizontal grid: glamv and gphiv
-            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, rn_Dt, nh_V, nid_V, domain_id=nidom, snc4chunks=snc4set )
-         CALL histvert( nid_V, "depthv", "Vertical V levels",      &  ! Vertical grid : gdept
-            &          "m", ipk, gdept_1d, nz_V, "down" )
-         !                                                            ! Index of ocean points
-         CALL wheneq( jpi*jpj*ipk, vmask, 1, 1., ndex_V , ndim_V  )      ! volume
-         CALL wheneq( jpi*jpj    , vmask, 1, 1., ndex_hV, ndim_hV )      ! surface
-
-         ! Define the W grid FILE ( nid_W )
-
-         CALL dia_nam( clhstnam, nn_write, 'grid_W' )                   ! filename
-         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
-         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
-            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, rn_Dt, nh_W, nid_W, domain_id=nidom, snc4chunks=snc4set )
-         CALL histvert( nid_W, "depthw", "Vertical W levels",      &  ! Vertical grid: gdepw
-            &          "m", ipk, gdepw_1d, nz_W, "down" )
-
-         IF( ln_abl ) THEN 
-         ! Define the ABL grid FILE ( nid_A )
-            CALL dia_nam( clhstnam, nn_write, 'grid_ABL' )
-            IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
-            CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
-               &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-               &          nit000-1, zjulian, rn_Dt, nh_A, nid_A, domain_id=nidom, snc4chunks=snc4set )
-            CALL histvert( nid_A, "ght_abl", "Vertical T levels",      &  ! Vertical grid: gdept
-               &           "m", ipka, ght_abl(2:jpka), nz_A, "up" )
-            !                                                            ! Index of ocean points
-			ALLOCATE( zw3d_abl(jpi,jpj,ipka) ) 
-			zw3d_abl(:,:,:) = 1._wp 
-			CALL wheneq( jpi*jpj*ipka, zw3d_abl, 1, 1., ndex_A , ndim_A  )      ! volume
-            CALL wheneq( jpi*jpj     , zw3d_abl, 1, 1., ndex_hA, ndim_hA )      ! surface
-			DEALLOCATE(zw3d_abl)
-         ENDIF
-
-         ! Declare all the output fields as NETCDF variables
-
-         !                                                                                      !!! nid_T : 3D
-         CALL histdef( nid_T, "votemper", "Temperature"                        , "C"      ,   &  ! tn
-            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
-         CALL histdef( nid_T, "vosaline", "Salinity"                           , "PSU"    ,   &  ! sn
-            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
-         IF(  .NOT.ln_linssh  ) THEN
-            CALL histdef( nid_T, "vovvle3t", "Level thickness"                    , "m"      ,&  ! ze3t(:,:,:,Kmm)
-            &             jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
-            CALL histdef( nid_T, "vovvldep", "T point depth"                      , "m"      ,&  ! ze3t(:,:,:,Kmm)
-            &             jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
-            CALL histdef( nid_T, "vovvldef", "Squared level deformation"          , "%^2"    ,&  ! ze3t(:,:,:,Kmm)
-            &             jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
-         ENDIF
-         !                                                                                      !!! nid_T : 2D
-         CALL histdef( nid_T, "sosstsst", "Sea Surface temperature"            , "C"      ,   &  ! sst
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sosaline", "Sea Surface Salinity"               , "PSU"    ,   &  ! sss
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sossheig", "Sea Surface Height"                 , "m"      ,   &  ! ssh
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sowaflup", "Net Upward Water Flux"              , "Kg/m2/s",   &  ! (emp-rnf)
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sorunoff", "River runoffs"                      , "Kg/m2/s",   &  ! runoffs
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sosfldow", "downward salt flux"                 , "PSU/m2/s",  &  ! sfx
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         IF(  ln_linssh  ) THEN
-            CALL histdef( nid_T, "sosst_cd", "Concentration/Dilution term on temperature"     &  ! emp * ts(:,:,1,jp_tem,Kmm)
-            &                                                                  , "KgC/m2/s",  &  ! sosst_cd
-            &             jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "sosss_cd", "Concentration/Dilution term on salinity"        &  ! emp * ts(:,:,1,jp_sal,Kmm)
-            &                                                                  , "KgPSU/m2/s",&  ! sosss_cd
-            &             jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         ENDIF
-         CALL histdef( nid_T, "sohefldo", "Net Downward Heat Flux"             , "W/m2"   ,   &  ! qns + qsr
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "soshfldo", "Shortwave Radiation"                , "W/m2"   ,   &  ! qsr
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "somixhgt", "Turbocline Depth"                   , "m"      ,   &  ! hmld
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "somxl010", "Mixed Layer Depth 0.01"             , "m"      ,   &  ! hmlp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "soicecov", "Ice fraction"                       , "[0,1]"  ,   &  ! fr_i
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sowindsp", "wind speed at 10m"                  , "m/s"    ,   &  ! wndm
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         !
-         IF( ln_abl ) THEN
-            CALL histdef( nid_A, "t_abl", "Potential Temperature"     , "K"        ,       &  ! t_abl
-               &          jpi, jpj, nh_A, ipka, 1, ipka, nz_A, 32, clop, zsto, zout )
-            CALL histdef( nid_A, "q_abl", "Humidity"                  , "kg/kg"    ,       &  ! q_abl
-               &          jpi, jpj, nh_A, ipka, 1, ipka, nz_A, 32, clop, zsto, zout ) 
-            CALL histdef( nid_A, "u_abl", "Atmospheric U-wind   "     , "m/s"        ,     &  ! u_abl
-               &          jpi, jpj, nh_A, ipka, 1, ipka, nz_A, 32, clop, zsto, zout )
-            CALL histdef( nid_A, "v_abl", "Atmospheric V-wind   "     , "m/s"    ,         &  ! v_abl
-               &          jpi, jpj, nh_A, ipka, 1, ipka, nz_A, 32, clop, zsto, zout ) 
-            CALL histdef( nid_A, "tke_abl", "Atmospheric TKE   "     , "m2/s2"    ,        &  ! tke_abl
-               &          jpi, jpj, nh_A, ipka, 1, ipka, nz_A, 32, clop, zsto, zout ) 
-            CALL histdef( nid_A, "avm_abl", "Atmospheric turbulent viscosity", "m2/s"   ,  &  ! avm_abl
-               &          jpi, jpj, nh_A, ipka, 1, ipka, nz_A, 32, clop, zsto, zout ) 
-            CALL histdef( nid_A, "avt_abl", "Atmospheric turbulent diffusivity", "m2/s2",  &  ! avt_abl
-               &          jpi, jpj, nh_A, ipka, 1, ipka, nz_A, 32, clop, zsto, zout ) 
-            CALL histdef( nid_A, "pblh", "Atmospheric boundary layer height "  , "m",      &  ! pblh
-               &          jpi, jpj, nh_A,  1  , 1, 1   , -99 , 32, clop, zsto, zout )		 			   
-#if defined key_si3
-            CALL histdef( nid_A, "oce_frac", "Fraction of open ocean"  , " ",      &  ! ato_i
-               &          jpi, jpj, nh_A,  1  , 1, 1   , -99 , 32, clop, zsto, zout )
-#endif
-            CALL histend( nid_A, snc4chunks=snc4set )
-         ENDIF
-         !
-         IF( ln_icebergs ) THEN
-            CALL histdef( nid_T, "calving"             , "calving mass input"                       , "kg/s"   , &
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "calving_heat"        , "calving heat flux"                        , "XXXX"   , &
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "berg_floating_melt"  , "Melt rate of icebergs + bits"             , "kg/m2/s", &
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "berg_stored_ice"     , "Accumulated ice mass by class"            , "kg"     , &
-               &          jpi, jpj, nh_T, nclasses  , 1, nclasses  , nb_T , 32, clop, zsto, zout )
-            IF( ln_bergdia ) THEN
-               CALL histdef( nid_T, "berg_melt"           , "Melt rate of icebergs"                    , "kg/m2/s", &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "berg_buoy_melt"      , "Buoyancy component of iceberg melt rate"  , "kg/m2/s", &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "berg_eros_melt"      , "Erosion component of iceberg melt rate"   , "kg/m2/s", &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "berg_conv_melt"      , "Convective component of iceberg melt rate", "kg/m2/s", &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "berg_virtual_area"   , "Virtual coverage by icebergs"             , "m2"     , &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "bits_src"           , "Mass source of bergy bits"                , "kg/m2/s", &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "bits_melt"          , "Melt rate of bergy bits"                  , "kg/m2/s", &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "bits_mass"          , "Bergy bit density field"                  , "kg/m2"  , &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "berg_mass"           , "Iceberg density field"                    , "kg/m2"  , &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "berg_real_calving"   , "Calving into iceberg class"               , "kg/s"   , &
-                  &          jpi, jpj, nh_T, nclasses  , 1, nclasses  , nb_T , 32, clop, zsto, zout )
-            ENDIF
-         ENDIF
-
-         IF( ln_ssr ) THEN
-            CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "sosafldp", "Surface salt flux: damping"         , "Kg/m2/s",   &  ! erp * sn
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         ENDIF
-       
-         clmx ="l_max(only(x))"    ! max index on a period
-!         CALL histdef( nid_T, "sobowlin", "Bowl Index"                         , "W-point",   &  ! bowl INDEX 
-!            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clmx, zsto, zout )
-#if defined key_diahth
-         CALL histdef( nid_T, "sothedep", "Thermocline Depth"                  , "m"      ,   & ! hth
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "so20chgt", "Depth of 20C isotherm"              , "m"      ,   & ! hd20
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "so28chgt", "Depth of 28C isotherm"              , "m"      ,   & ! hd28
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sohtc300", "Heat content 300 m"                 , "J/m2"   ,   & ! htc3
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-#endif
-
-         CALL histend( nid_T, snc4chunks=snc4set )
-
-         !                                                                                      !!! nid_U : 3D
-         CALL histdef( nid_U, "vozocrtx", "Zonal Current"                      , "m/s"    ,   &  ! uu(:,:,:,Kmm)
-            &          jpi, jpj, nh_U, ipk, 1, ipk, nz_U, 32, clop, zsto, zout )
-         IF( ln_wave .AND. ln_sdw) THEN
-            CALL histdef( nid_U, "sdzocrtx", "Stokes Drift Zonal Current"         , "m/s"    ,   &  ! usd
-               &          jpi, jpj, nh_U, ipk, 1, ipk, nz_U, 32, clop, zsto, zout )
-         ENDIF
-         !                                                                                      !!! nid_U : 2D
-         CALL histdef( nid_U, "sozotaux", "Wind Stress along i-axis"           , "N/m2"   ,   &  ! utau
-            &          jpi, jpj, nh_U, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
-
-         CALL histend( nid_U, snc4chunks=snc4set )
-
-         !                                                                                      !!! nid_V : 3D
-         CALL histdef( nid_V, "vomecrty", "Meridional Current"                 , "m/s"    ,   &  ! vv(:,:,:,Kmm)
-            &          jpi, jpj, nh_V, ipk, 1, ipk, nz_V, 32, clop, zsto, zout )
-         IF( ln_wave .AND. ln_sdw) THEN
-            CALL histdef( nid_V, "sdmecrty", "Stokes Drift Meridional Current"    , "m/s"    ,   &  ! vsd
-               &          jpi, jpj, nh_V, ipk, 1, ipk, nz_V, 32, clop, zsto, zout )
-         ENDIF
-         !                                                                                      !!! nid_V : 2D
-         CALL histdef( nid_V, "sometauy", "Wind Stress along j-axis"           , "N/m2"   ,   &  ! vtau
-            &          jpi, jpj, nh_V, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
-
-         CALL histend( nid_V, snc4chunks=snc4set )
-
-         !                                                                                      !!! nid_W : 3D
-         CALL histdef( nid_W, "vovecrtz", "Vertical Velocity"                  , "m/s"    ,   &  ! ww
-            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-         CALL histdef( nid_W, "votkeavt", "Vertical Eddy Diffusivity"          , "m2/s"   ,   &  ! avt
-            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-         CALL histdef( nid_W, "votkeavm", "Vertical Eddy Viscosity"             , "m2/s"  ,   &  ! avm
-            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-
-         IF( ln_zdfddm ) THEN
-            CALL histdef( nid_W,"voddmavs","Salt Vertical Eddy Diffusivity"    , "m2/s"   ,   &  ! avs
-               &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-         ENDIF
-         
-         IF( ln_wave .AND. ln_sdw) THEN
-            CALL histdef( nid_W, "sdvecrtz", "Stokes Drift Vertical Current"   , "m/s"    ,   &  ! wsd
-               &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-         ENDIF
-         !                                                                                      !!! nid_W : 2D
-         CALL histend( nid_W, snc4chunks=snc4set )
-
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization'
-         IF(ll_print) CALL FLUSH(numout )
-
-      ENDIF
-
-      ! 2. Start writing data
-      ! ---------------------
-
-      ! ndex(1) est utilise ssi l'avant dernier argument est different de 
-      ! la taille du tableau en sortie. Dans ce cas , l'avant dernier argument
-      ! donne le nombre d'elements, et ndex la liste des indices a sortir
-
-      IF( lwp .AND. MOD( itmod, nn_write ) == 0 ) THEN 
-         WRITE(numout,*) 'dia_wri : write model outputs in NetCDF files at ', kt, 'time-step'
-         WRITE(numout,*) '~~~~~~ '
-      ENDIF
-!!st16
-      IF( .NOT.ln_linssh ) THEN
-         CALL histwrite( nid_T, "votemper", it, ts(:,:,:,jp_tem,Kmm) * ze3t(:,:,:) , ndim_T , ndex_T  )   ! heat content
-         CALL histwrite( nid_T, "vosaline", it, ts(:,:,:,jp_sal,Kmm) * ze3t(:,:,:) , ndim_T , ndex_T  )   ! salt content
-         CALL histwrite( nid_T, "sosstsst", it, ts(:,:,1,jp_tem,Kmm) * ze3t(:,:,1) , ndim_hT, ndex_hT )   ! sea surface heat content
-         CALL histwrite( nid_T, "sosaline", it, ts(:,:,1,jp_sal,Kmm) * ze3t(:,:,1) , ndim_hT, ndex_hT )   ! sea surface salinity content
-!!st16
-      ELSE
-         CALL histwrite( nid_T, "votemper", it, ts(:,:,:,jp_tem,Kmm) , ndim_T , ndex_T  )   ! temperature
-         CALL histwrite( nid_T, "vosaline", it, ts(:,:,:,jp_sal,Kmm) , ndim_T , ndex_T  )   ! salinity
-         CALL histwrite( nid_T, "sosstsst", it, ts(:,:,1,jp_tem,Kmm) , ndim_hT, ndex_hT )   ! sea surface temperature
-         CALL histwrite( nid_T, "sosaline", it, ts(:,:,1,jp_sal,Kmm) , ndim_hT, ndex_hT )   ! sea surface salinity
-      ENDIF
-      IF( .NOT.ln_linssh ) THEN
-!!st17 if ! defined key_qco 
-         zw3d(:,:,:) = ( ( ze3t(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2
-         CALL histwrite( nid_T, "vovvle3t", it, ze3t (:,:,:)     , ndim_T , ndex_T  )   ! level thickness
-         CALL histwrite( nid_T, "vovvldep", it, zgdept , ndim_T , ndex_T  )   ! t-point depth 
-!!st17
-         CALL histwrite( nid_T, "vovvldef", it, zw3d             , ndim_T , ndex_T  )   ! level thickness deformation
-      ENDIF
-      CALL histwrite( nid_T, "sossheig", it, ssh(:,:,Kmm)          , ndim_hT, ndex_hT )   ! sea surface height
-      CALL histwrite( nid_T, "sowaflup", it, ( emp-rnf )   , ndim_hT, ndex_hT )   ! upward water flux
-      CALL histwrite( nid_T, "sorunoff", it, rnf           , ndim_hT, ndex_hT )   ! river runoffs
-      CALL histwrite( nid_T, "sosfldow", it, sfx           , ndim_hT, ndex_hT )   ! downward salt flux 
-                                                                                  ! (includes virtual salt flux beneath ice 
-                                                                                  ! in linear free surface case)
-      IF( ln_linssh ) THEN
-         zw2d(:,:) = emp (:,:) * ts(:,:,1,jp_tem,Kmm)
-         CALL histwrite( nid_T, "sosst_cd", it, zw2d, ndim_hT, ndex_hT )          ! c/d term on sst
-         zw2d(:,:) = emp (:,:) * ts(:,:,1,jp_sal,Kmm)
-         CALL histwrite( nid_T, "sosss_cd", it, zw2d, ndim_hT, ndex_hT )          ! c/d term on sss
-      ENDIF
-      CALL histwrite( nid_T, "sohefldo", it, qns + qsr     , ndim_hT, ndex_hT )   ! total heat flux
-      CALL histwrite( nid_T, "soshfldo", it, qsr           , ndim_hT, ndex_hT )   ! solar heat flux
-      CALL histwrite( nid_T, "somixhgt", it, hmld          , ndim_hT, ndex_hT )   ! turbocline depth
-      CALL histwrite( nid_T, "somxl010", it, hmlp          , ndim_hT, ndex_hT )   ! mixed layer depth
-      CALL histwrite( nid_T, "soicecov", it, fr_i          , ndim_hT, ndex_hT )   ! ice fraction   
-      CALL histwrite( nid_T, "sowindsp", it, wndm          , ndim_hT, ndex_hT )   ! wind speed   
-      !
-      IF( ln_abl ) THEN 
-         ALLOCATE( zw3d_abl(jpi,jpj,jpka) )
-         IF( ln_mskland )   THEN 
-            DO jk=1,jpka
-               zw3d_abl(:,:,jk) = tmask(:,:,1)
-            END DO       
-         ELSE
-            zw3d_abl(:,:,:) = 1._wp		 
-         ENDIF			
-         CALL histwrite( nid_A,  "pblh"   , it, pblh(:,:)                  *zw3d_abl(:,:,1     ), ndim_hA, ndex_hA )   ! pblh 
-         CALL histwrite( nid_A,  "u_abl"  , it, u_abl   (:,:,2:jpka,nt_n  )*zw3d_abl(:,:,2:jpka), ndim_A , ndex_A  )   ! u_abl
-         CALL histwrite( nid_A,  "v_abl"  , it, v_abl   (:,:,2:jpka,nt_n  )*zw3d_abl(:,:,2:jpka), ndim_A , ndex_A  )   ! v_abl
-         CALL histwrite( nid_A,  "t_abl"  , it, tq_abl  (:,:,2:jpka,nt_n,1)*zw3d_abl(:,:,2:jpka), ndim_A , ndex_A  )   ! t_abl
-         CALL histwrite( nid_A,  "q_abl"  , it, tq_abl  (:,:,2:jpka,nt_n,2)*zw3d_abl(:,:,2:jpka), ndim_A , ndex_A  )   ! q_abl		 
-         CALL histwrite( nid_A,  "tke_abl", it, tke_abl (:,:,2:jpka,nt_n  )*zw3d_abl(:,:,2:jpka), ndim_A , ndex_A  )   ! tke_abl
-         CALL histwrite( nid_A,  "avm_abl", it, avm_abl (:,:,2:jpka       )*zw3d_abl(:,:,2:jpka), ndim_A , ndex_A  )   ! avm_abl
-         CALL histwrite( nid_A,  "avt_abl", it, avt_abl (:,:,2:jpka       )*zw3d_abl(:,:,2:jpka), ndim_A , ndex_A  )   ! avt_abl	
-#if defined key_si3
-         CALL histwrite( nid_A,  "oce_frac"   , it, ato_i(:,:)                                  , ndim_hA, ndex_hA )   ! ato_i
-#endif
-         DEALLOCATE(zw3d_abl)
-      ENDIF
-      !
-      IF( ln_icebergs ) THEN
-         !
-         CALL histwrite( nid_T, "calving"             , it, berg_grid%calving      , ndim_hT, ndex_hT )  
-         CALL histwrite( nid_T, "calving_heat"        , it, berg_grid%calving_hflx , ndim_hT, ndex_hT )         
-         CALL histwrite( nid_T, "berg_floating_melt"  , it, berg_grid%floating_melt, ndim_hT, ndex_hT )  
-         !
-         CALL histwrite( nid_T, "berg_stored_ice"     , it, berg_grid%stored_ice   , ndim_bT, ndex_bT )
-         !
-         IF( ln_bergdia ) THEN
-            CALL histwrite( nid_T, "berg_melt"           , it, berg_melt        , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "berg_buoy_melt"      , it, buoy_melt        , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "berg_eros_melt"      , it, eros_melt        , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "berg_conv_melt"      , it, conv_melt        , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "berg_virtual_area"   , it, virtual_area     , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "bits_src"            , it, bits_src         , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "bits_melt"           , it, bits_melt        , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "bits_mass"           , it, bits_mass        , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "berg_mass"           , it, berg_mass        , ndim_hT, ndex_hT   )  
-            !
-            CALL histwrite( nid_T, "berg_real_calving"   , it, real_calving     , ndim_bT, ndex_bT   )
-         ENDIF
-      ENDIF
-
-      IF( ln_ssr ) THEN
-         CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
-         CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
-         zw2d(:,:) = erp(:,:) * ts(:,:,1,jp_sal,Kmm) * tmask(:,:,1)
-         CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
-      ENDIF
-!      zw2d(:,:) = FLOAT( nmln(:,:) ) * tmask(:,:,1)
-!      CALL histwrite( nid_T, "sobowlin", it, zw2d          , ndim_hT, ndex_hT )   ! ???
-
-#if defined key_diahth
-      CALL histwrite( nid_T, "sothedep", it, hth           , ndim_hT, ndex_hT )   ! depth of the thermocline
-      CALL histwrite( nid_T, "so20chgt", it, hd20          , ndim_hT, ndex_hT )   ! depth of the 20 isotherm
-      CALL histwrite( nid_T, "so28chgt", it, hd28          , ndim_hT, ndex_hT )   ! depth of the 28 isotherm
-      CALL histwrite( nid_T, "sohtc300", it, htc3          , ndim_hT, ndex_hT )   ! first 300m heaat content
-#endif
-
-      CALL histwrite( nid_U, "vozocrtx", it, uu(:,:,:,Kmm)            , ndim_U , ndex_U )    ! i-current
-      CALL histwrite( nid_U, "sozotaux", it, utau          , ndim_hU, ndex_hU )   ! i-wind stress
-
-      CALL histwrite( nid_V, "vomecrty", it, vv(:,:,:,Kmm)            , ndim_V , ndex_V  )   ! j-current
-      CALL histwrite( nid_V, "sometauy", it, vtau          , ndim_hV, ndex_hV )   ! j-wind stress
-
-      IF( ln_zad_Aimp ) THEN
-         CALL histwrite( nid_W, "vovecrtz", it, ww + wi     , ndim_T, ndex_T )    ! vert. current
-      ELSE
-         CALL histwrite( nid_W, "vovecrtz", it, ww          , ndim_T, ndex_T )    ! vert. current
-      ENDIF
-      CALL histwrite( nid_W, "votkeavt", it, avt            , ndim_T, ndex_T )    ! T vert. eddy diff. coef.
-      CALL histwrite( nid_W, "votkeavm", it, avm            , ndim_T, ndex_T )    ! T vert. eddy visc. coef.
-      IF( ln_zdfddm ) THEN
-         CALL histwrite( nid_W, "voddmavs", it, avs         , ndim_T, ndex_T )    ! S vert. eddy diff. coef.
-      ENDIF
-
-      IF( ln_wave .AND. ln_sdw ) THEN
-         CALL histwrite( nid_U, "sdzocrtx", it, usd         , ndim_U , ndex_U )    ! i-StokesDrift-current
-         CALL histwrite( nid_V, "sdmecrty", it, vsd         , ndim_V , ndex_V )    ! j-StokesDrift-current
-         CALL histwrite( nid_W, "sdvecrtz", it, wsd         , ndim_T , ndex_T )    ! StokesDrift vert. current
-      ENDIF
-
-      ! 3. Close all files
-      ! ---------------------------------------
-      IF( kt == nitend ) THEN
-         CALL histclo( nid_T )
-         CALL histclo( nid_U )
-         CALL histclo( nid_V )
-         CALL histclo( nid_W )
-         IF(ln_abl) CALL histclo( nid_A )
-      ENDIF
-      !
-      IF( ln_timing )   CALL timing_stop('dia_wri')
-      !
-   END SUBROUTINE dia_wri
-#endif
-
-   SUBROUTINE dia_wri_state( Kmm, cdfile_name )
-      !!---------------------------------------------------------------------
-      !!                 ***  ROUTINE dia_wri_state  ***
-      !!        
-      !! ** Purpose :   create a NetCDF file named cdfile_name which contains 
-      !!      the instantaneous ocean state and forcing fields.
-      !!        Used to find errors in the initial state or save the last
-      !!      ocean state in case of abnormal end of a simulation
-      !!
-      !! ** Method  :   NetCDF files using ioipsl
-      !!      File 'output.init.nc'  is created if ninist = 1 (namelist)
-      !!      File 'output.abort.nc' is created in case of abnormal job end
-      !!----------------------------------------------------------------------
-      INTEGER           , INTENT( in ) ::   Kmm              ! time level index
-      CHARACTER (len=* ), INTENT( in ) ::   cdfile_name      ! name of the file created
-      !!
-      INTEGER :: inum, jk
-!!st18  TBR
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ze3t, zgdept      ! 3D workspace !!st patch to use substitution
-      !!----------------------------------------------------------------------
-      ! 
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'dia_wri_state : single instantaneous ocean state'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~   and forcing fields file created '
-      IF(lwp) WRITE(numout,*) '                and named :', cdfile_name, '...nc'
-!!st19 TBR
-      DO jk = 1, jpk
-         ze3t(:,:,jk) =  e3t(:,:,jk,Kmm)
-         zgdept(:,:,jk) =  gdept(:,:,jk,Kmm)
-      END DO
-!!st19
-#if defined key_si3
-     CALL iom_open( TRIM(cdfile_name), inum, ldwrt = .TRUE., kdlev = jpl )
-#else
-     CALL iom_open( TRIM(cdfile_name), inum, ldwrt = .TRUE. )
-#endif
-
-      CALL iom_rstput( 0, 0, inum, 'votemper', ts(:,:,:,jp_tem,Kmm) )    ! now temperature
-      CALL iom_rstput( 0, 0, inum, 'vosaline', ts(:,:,:,jp_sal,Kmm) )    ! now salinity
-      CALL iom_rstput( 0, 0, inum, 'sossheig', ssh(:,:,Kmm)              )    ! sea surface height
-      CALL iom_rstput( 0, 0, inum, 'vozocrtx', uu(:,:,:,Kmm)                )    ! now i-velocity
-      CALL iom_rstput( 0, 0, inum, 'vomecrty', vv(:,:,:,Kmm)                )    ! now j-velocity
-      IF( ln_zad_Aimp ) THEN
-         CALL iom_rstput( 0, 0, inum, 'vovecrtz', ww + wi        )    ! now k-velocity
-      ELSE
-         CALL iom_rstput( 0, 0, inum, 'vovecrtz', ww             )    ! now k-velocity
-      ENDIF
-      CALL iom_rstput( 0, 0, inum, 'risfdep', risfdep            )    ! now k-velocity
-      CALL iom_rstput( 0, 0, inum, 'ht'     , ht(:,:)            )    ! now water column height
-
-      IF ( ln_isf ) THEN
-         IF (ln_isfcav_mlt) THEN
-            CALL iom_rstput( 0, 0, inum, 'fwfisf_cav', fwfisf_cav          )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'rhisf_cav_tbl', rhisf_tbl_cav    )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'rfrac_cav_tbl', rfrac_tbl_cav    )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'misfkb_cav', REAL(misfkb_cav,wp) )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'misfkt_cav', REAL(misfkt_cav,wp) )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'mskisf_cav', REAL(mskisf_cav,wp), ktype = jp_i1 )
-         END IF
-         IF (ln_isfpar_mlt) THEN
-            CALL iom_rstput( 0, 0, inum, 'isfmsk_par', REAL(mskisf_par,wp) )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'fwfisf_par', fwfisf_par          )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'rhisf_par_tbl', rhisf_tbl_par    )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'rfrac_par_tbl', rfrac_tbl_par    )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'misfkb_par', REAL(misfkb_par,wp) )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'misfkt_par', REAL(misfkt_par,wp) )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'mskisf_par', REAL(mskisf_par,wp), ktype = jp_i1 )
-         END IF
-      END IF
-      !
-      IF( ALLOCATED(ahtu) ) THEN
-         CALL iom_rstput( 0, 0, inum,  'ahtu', ahtu              )    ! aht at u-point
-         CALL iom_rstput( 0, 0, inum,  'ahtv', ahtv              )    ! aht at v-point
-      ENDIF
-      IF( ALLOCATED(ahmt) ) THEN
-         CALL iom_rstput( 0, 0, inum,  'ahmt', ahmt              )    ! ahmt at u-point
-         CALL iom_rstput( 0, 0, inum,  'ahmf', ahmf              )    ! ahmf at v-point
-      ENDIF
-      CALL iom_rstput( 0, 0, inum, 'sowaflup', emp - rnf         )    ! freshwater budget
-      CALL iom_rstput( 0, 0, inum, 'sohefldo', qsr + qns         )    ! total heat flux
-      CALL iom_rstput( 0, 0, inum, 'soshfldo', qsr               )    ! solar heat flux
-      CALL iom_rstput( 0, 0, inum, 'soicecov', fr_i              )    ! ice fraction
-      CALL iom_rstput( 0, 0, inum, 'sozotaux', utau              )    ! i-wind stress
-      CALL iom_rstput( 0, 0, inum, 'sometauy', vtau              )    ! j-wind stress
-!!st20 TBR
-      IF(  .NOT.ln_linssh  ) THEN
-         CALL iom_rstput( 0, 0, inum, 'vovvldep', zgdept        )    !  T-cell depth 
-         CALL iom_rstput( 0, 0, inum, 'vovvle3t', ze3t          )    !  T-cell thickness  
-      END IF
-      IF( ln_wave .AND. ln_sdw ) THEN
-         CALL iom_rstput( 0, 0, inum, 'sdzocrtx', usd            )    ! now StokesDrift i-velocity
-         CALL iom_rstput( 0, 0, inum, 'sdmecrty', vsd            )    ! now StokesDrift j-velocity
-         CALL iom_rstput( 0, 0, inum, 'sdvecrtz', wsd            )    ! now StokesDrift k-velocity
-      ENDIF
-      IF ( ln_abl ) THEN
-         CALL iom_rstput ( 0, 0, inum, "uz1_abl",   u_abl(:,:,2,nt_a  ) )   ! now first level i-wind
-         CALL iom_rstput ( 0, 0, inum, "vz1_abl",   v_abl(:,:,2,nt_a  ) )   ! now first level j-wind
-         CALL iom_rstput ( 0, 0, inum, "tz1_abl",  tq_abl(:,:,2,nt_a,1) )   ! now first level temperature
-         CALL iom_rstput ( 0, 0, inum, "qz1_abl",  tq_abl(:,:,2,nt_a,2) )   ! now first level humidity
-      ENDIF
- 
-#if defined key_si3
-      IF( nn_ice == 2 ) THEN   ! condition needed in case agrif + ice-model but no-ice in child grid
-         CALL ice_wri_state( inum )
-      ENDIF
-#endif
-      !
-      CALL iom_close( inum )
-      ! 
-   END SUBROUTINE dia_wri_state
-
-   !!======================================================================
-END MODULE diawri
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dom_oce.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dom_oce.F90	(revision 13603)
+++ 	(revision )
@@ -1,335 +1,0 @@
-MODULE dom_oce
-   !!======================================================================
-   !!                       ***  MODULE dom_oce  ***
-   !!       
-   !! ** Purpose :   Define in memory all the ocean space domain variables
-   !!======================================================================
-   !! History :  1.0  ! 2005-10  (A. Beckmann, G. Madec)  reactivate s-coordinate 
-   !!            3.3  ! 2010-11  (G. Madec) add mbk. arrays associated to the deepest ocean level
-   !!            3.4  ! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
-   !!            3.5  ! 2012     (S. Mocavero, I. Epicoco) Add arrays associated
-   !!                             to the optimization of BDY communications
-   !!            3.7  ! 2015-11  (G. Madec) introduce surface and scale factor ratio
-   !!             -   ! 2015-11  (G. Madec, A. Coward)  time varying zgr by default
-   !!            4.1  ! 2019-08  (A. Coward, D. Storkey) rename prognostic variables in preparation for new time scheme.
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   Agrif_Root    : dummy function used when lk_agrif=F
-   !!   Agrif_CFixed  : dummy function used when lk_agrif=F
-   !!   dom_oce_alloc : dynamical allocation of dom_oce arrays
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-
-   IMPLICIT NONE
-   PUBLIC             ! allows the acces to par_oce when dom_oce is used (exception to coding rules)
-
-   PUBLIC dom_oce_alloc  ! Called from nemogcm.F90
-
-   !!----------------------------------------------------------------------
-   !! time & space domain namelist
-   !! ----------------------------
-   !                                   !!* Namelist namdom : time & space domain *
-   LOGICAL , PUBLIC ::   ln_linssh      !: =T  linear free surface ==>> model level are fixed in time
-   LOGICAL , PUBLIC ::   ln_meshmask    !: =T  create a mesh-mask file (mesh_mask.nc)
-   REAL(wp), PUBLIC ::   rn_Dt          !: time step for the dynamics and tracer
-   REAL(wp), PUBLIC ::   rn_atfp        !: asselin time filter parameter
-   LOGICAL , PUBLIC ::   ln_1st_euler   !: =T start with forward time step or not (=F)
-   LOGICAL , PUBLIC ::   ln_crs         !: Apply grid coarsening to dynamical model output or online passive tracers
-
-   !! Free surface parameters
-   !! =======================
-   LOGICAL , PUBLIC :: ln_dynspg_exp    !: Explicit free surface flag
-   LOGICAL , PUBLIC :: ln_dynspg_ts     !: Split-Explicit free surface flag
-
-   !! Time splitting parameters
-   !! =========================
-   LOGICAL,  PUBLIC :: ln_bt_fw         !: Forward integration of barotropic sub-stepping
-   LOGICAL,  PUBLIC :: ln_bt_av         !: Time averaging of barotropic variables
-   LOGICAL,  PUBLIC :: ln_bt_auto       !: Set number of barotropic iterations automatically
-   INTEGER,  PUBLIC :: nn_bt_flt        !: Filter choice
-   INTEGER,  PUBLIC :: nn_e          !: Number of barotropic iterations during one baroclinic step (rn_Dt)
-   REAL(wp), PUBLIC :: rn_bt_cmax       !: Maximum allowed courant number (used if ln_bt_auto=T)
-   REAL(wp), PUBLIC :: rn_bt_alpha      !: Time stepping diffusion parameter
-
-
-   !                                   !!! associated variables
-   LOGICAL , PUBLIC ::   l_1st_euler    !: Euler 1st time-step flag (=T if ln_restart=F or ln_1st_euler=T)
-   REAL(wp), PUBLIC ::   rDt, r1_Dt     !: Current model timestep and reciprocal
-                                        !: rDt = 2 * rn_Dt if leapfrog and l_1st_euler = F
-                                        !:     =     rn_Dt if leapfrog and l_1st_euler = T
-                                        !:     =     rn_Dt if RK3
-
-   !!----------------------------------------------------------------------
-   !! space domain parameters
-   !!----------------------------------------------------------------------
-   INTEGER, PUBLIC ::   jperio   !: Global domain lateral boundary type (between 0 and 7)
-   !                                !  = 0 closed                 ;   = 1 cyclic East-West
-   !                                !  = 2 cyclic North-South     ;   = 3 North fold T-point pivot
-   !                                !  = 4 cyclic East-West AND North fold T-point pivot
-   !                                !  = 5 North fold F-point pivot
-   !                                !  = 6 cyclic East-West AND North fold F-point pivot
-   !                                !  = 7 bi-cyclic East-West AND North-South
-   LOGICAL, PUBLIC ::   l_Iperio, l_Jperio   !   should we explicitely take care I/J periodicity
-
-   !                             !: domain MPP decomposition parameters
-   INTEGER             , PUBLIC ::   nimpp, njmpp     !: i- & j-indexes for mpp-subdomain left bottom
-   INTEGER             , PUBLIC ::   nreci, nrecj     !: overlap region in i and j
-   INTEGER             , PUBLIC ::   nproc            !: number for local processor
-   INTEGER             , PUBLIC ::   narea            !: number for local area
-   INTEGER             , PUBLIC ::   nbondi, nbondj   !: mark of i- and j-direction local boundaries
-   INTEGER, ALLOCATABLE, PUBLIC ::   nbondi_bdy(:)    !: mark i-direction local boundaries for BDY open boundaries
-   INTEGER, ALLOCATABLE, PUBLIC ::   nbondj_bdy(:)    !: mark j-direction local boundaries for BDY open boundaries
-   INTEGER, ALLOCATABLE, PUBLIC ::   nbondi_bdy_b(:)  !: mark i-direction of neighbours local boundaries for BDY open boundaries  
-   INTEGER, ALLOCATABLE, PUBLIC ::   nbondj_bdy_b(:)  !: mark j-direction of neighbours local boundaries for BDY open boundaries  
-
-   INTEGER, PUBLIC ::   npolj             !: north fold mark (0, 3 or 4)
-   INTEGER, PUBLIC ::   nlci, nldi, nlei  !: i-dimensions of the local subdomain and its first and last indoor indices
-   INTEGER, PUBLIC ::   nlcj, nldj, nlej  !: i-dimensions of the local subdomain and its first and last indoor indices
-   INTEGER, PUBLIC ::   noea, nowe        !: index of the local neighboring processors in
-   INTEGER, PUBLIC ::   noso, nono        !: east, west, south and north directions
-   INTEGER, PUBLIC ::   nidom             !: ???
-
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   mig        !: local  ==> global domain i-index
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   mjg        !: local  ==> global domain j-index
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   mi0, mi1   !: global ==> local  domain i-index (mi0=1 and mi1=0 if the global index
-   !                                                                !                                             is not in the local domain)
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   mj0, mj1   !: global ==> local  domain j-index (mj0=1 and mj1=0 if the global index
-   !                                                                !                                             is not in the local domain)
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   nimppt, njmppt   !: i-, j-indexes for each processor
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ibonit, ibonjt   !: i-, j- processor neighbour existence
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   nlcit , nlcjt    !: dimensions of every subdomain
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   nldit , nldjt    !: first, last indoor index for each i-domain
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   nleit , nlejt    !: first, last indoor index for each j-domain
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: nfiimpp, nfipproc, nfilcit
-
-   !!----------------------------------------------------------------------
-   !! horizontal curvilinear coordinate and scale factors
-   !! ---------------------------------------------------------------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   glamt , glamu, glamv , glamf    !: longitude at t, u, v, f-points [degree]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   gphit , gphiu, gphiv , gphif    !: latitude  at t, u, v, f-points [degree]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, TARGET, DIMENSION(:,:) ::   e1t   , e2t  , r1_e1t, r1_e2t   !: t-point horizontal scale factors    [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, TARGET, DIMENSION(:,:) ::   e1u   , e2u  , r1_e1u, r1_e2u   !: horizontal scale factors at u-point [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, TARGET, DIMENSION(:,:) ::   e1v   , e2v  , r1_e1v, r1_e2v   !: horizontal scale factors at v-point [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, TARGET, DIMENSION(:,:) ::   e1f   , e2f  , r1_e1f, r1_e2f   !: horizontal scale factors at f-point [m]
-   !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2t , r1_e1e2t                !: associated metrics at t-point
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2u , r1_e1e2u , e2_e1u       !: associated metrics at u-point
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2v , r1_e1e2v , e1_e2v       !: associated metrics at v-point
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2f , r1_e1e2f                !: associated metrics at f-point
-   !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ff_f  , ff_t                    !: Coriolis factor at f- & t-points  [1/s]
-   !!----------------------------------------------------------------------
-   !! vertical coordinate and scale factors
-   !! ---------------------------------------------------------------------
-   LOGICAL, PUBLIC ::   ln_zco       !: z-coordinate - full step
-   LOGICAL, PUBLIC ::   ln_zps       !: z-coordinate - partial step
-   LOGICAL, PUBLIC ::   ln_sco       !: s-coordinate or hybrid z-s coordinate
-   LOGICAL, PUBLIC ::   ln_isfcav    !: presence of ISF 
-   !                                                        !  reference scale factors
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3t_0   !: t- vert. scale factor [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3u_0   !: u- vert. scale factor [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3v_0   !: v- vert. scale factor [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3f_0   !: f- vert. scale factor [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3w_0   !: w- vert. scale factor [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::    e3uw_0   !: uw-vert. scale factor [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::    e3vw_0   !: vw-vert. scale factor [m]
-   !                                                        !  time-dependent scale factors
-!!st1
-#if ! defined key_qco
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e3t, e3u, e3v, e3w, e3uw, e3vw  !: vert. scale factor [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   e3f                             !: F-point vert. scale factor [m]
-#endif
-   !                                                        !  time-dependent ratio ssh / h_0
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   r3t, r3u, r3v                   !: time-dependent    ratio at t-, u- and v-point [-]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   r3f                             !: mid-time-level    ratio at f-point            [-]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   r3t_f, r3u_f, r3v_f             !: now time-filtered ratio at t-, u- and v-point [-]
-
-   !                                                        !  reference depths of cells
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   gdept_0  !: t- depth              [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   gdepw_0  !: w- depth              [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   gde3w_0  !: w- depth (sum of e3w) [m]
-   !                                                        !  time-dependent depths of cells
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   gdept, gdepw
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   gde3w
-!!st2
-   !                                                        !  reference heights of ocean water column and its inverse
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   ht_0, r1_ht_0   !: t-depth        [m] and [1/m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   hu_0, r1_hu_0   !: u-depth        [m] and [1/m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   hv_0, r1_hv_0   !: v-depth        [m] and [1/m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   hf_0, r1_hf_0   !: f-depth        [m] and [1/m]
-   !                                                        ! time-dependent heights of ocean water column
-#if ! defined key_qco
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   ht          !: t-points           [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   hu, r1_hu   !: u-depth            [m] and [1/m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   hv, r1_hv   !: v-depth            [m] and [1/m]
-#endif
-!!st2
-   
-   INTEGER, PUBLIC ::   nla10              !: deepest    W level Above  ~10m (nlb10 - 1)
-   INTEGER, PUBLIC ::   nlb10              !: shallowest W level Bellow ~10m (nla10 + 1) 
-
-   !! 1D reference  vertical coordinate
-   !! =-----------------====------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   gdept_1d, gdepw_1d !: reference depth of t- and w-points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   e3t_1d  , e3w_1d   !: reference vertical scale factors at T- and W-pts (m)
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   risfdep, bathy
-
-   !!----------------------------------------------------------------------
-   !! masks, top and bottom ocean point position
-   !! ---------------------------------------------------------------------
-!!gm Proposition of new name for top/bottom vertical indices
-!   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mtk_t, mtk_u, mtk_v   !: top    first wet T-, U-, and V-level (ISF)
-!   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbk_t, mbk_u, mbk_v   !: bottom last  wet T-, U-, and V-level
-!!gm
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbkt, mbku, mbkv   !: bottom last wet T-, U- and V-level
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmask_i            !: interior domain T-point mask
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmask_h            !: internal domain T-point mask (Figure 8.5 NEMO book)
-
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mikt, miku, mikv, mikf  !: top first wet T-, U-, V-, F-level           (ISF)
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ssmask, ssumask, ssvmask, ssfmask    !: surface mask at T-,U-, V- and F-pts
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:), TARGET :: tmask, umask, vmask, fmask   !: land/ocean mask at T-, U-, V- and F-pts
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:), TARGET :: wmask, wumask, wvmask        !: land/ocean mask at WT-, WU- and WV-pts
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   tpol, fpol          !: north fold mask (jperio= 3 or 4)
-
-   !!----------------------------------------------------------------------
-   !! calendar variables
-   !! ---------------------------------------------------------------------
-   INTEGER , PUBLIC ::   nyear         !: current year
-   INTEGER , PUBLIC ::   nmonth        !: current month
-   INTEGER , PUBLIC ::   nday          !: current day of the month
-   INTEGER , PUBLIC ::   nhour         !: current hour
-   INTEGER , PUBLIC ::   nminute       !: current minute
-   INTEGER , PUBLIC ::   ndastp        !: time step date in yyyymmdd format
-   INTEGER , PUBLIC ::   nday_year     !: current day counted from jan 1st of the current year
-   INTEGER , PUBLIC ::   nsec_year     !: seconds between 00h jan 1st of the current  year and half of the current time step
-   INTEGER , PUBLIC ::   nsec_month    !: seconds between 00h 1st day of the current month and half of the current time step
-   INTEGER , PUBLIC ::   nsec_monday   !: seconds between 00h         of the last Monday   and half of the current time step
-   INTEGER , PUBLIC ::   nsec_day      !: seconds between 00h         of the current   day and half of the current time step
-   REAL(wp), PUBLIC ::   fjulday       !: current julian day 
-   REAL(wp), PUBLIC ::   fjulstartyear !: first day of the current year in julian days
-   REAL(wp), PUBLIC ::   adatrj        !: number of elapsed days since the begining of the whole simulation
-   !                                   !: (cumulative duration of previous runs that may have used different time-step size)
-   INTEGER , PUBLIC, DIMENSION(  0: 2) ::   nyear_len     !: length in days of the previous/current/next year
-   INTEGER , PUBLIC, DIMENSION(-11:25) ::   nmonth_len    !: length in days of the months of the current year
-   INTEGER , PUBLIC, DIMENSION(-11:25) ::   nmonth_beg    !: second since Jan 1st 0h of the current year and the half of the months
-   INTEGER , PUBLIC                  ::   nsec1jan000     !: second since Jan 1st 0h of nit000 year and Jan 1st 0h the current year
-   INTEGER , PUBLIC                  ::   nsec000_1jan000   !: second since Jan 1st 0h of nit000 year and nit000
-   INTEGER , PUBLIC                  ::   nsecend_1jan000   !: second since Jan 1st 0h of nit000 year and nitend
-
-   !!----------------------------------------------------------------------
-   !! agrif domain
-   !!----------------------------------------------------------------------
-#if defined key_agrif
-   LOGICAL, PUBLIC, PARAMETER ::   lk_agrif = .TRUE.    !: agrif flag
-#else
-   LOGICAL, PUBLIC, PARAMETER ::   lk_agrif = .FALSE.   !: agrif flag
-#endif
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: dom_oce.F90 12614 2020-03-26 14:59:52Z gm $ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-#if ! defined key_agrif
-   !!----------------------------------------------------------------------
-   !! NOT 'key_agrif'      dummy function                     No AGRIF zoom
-   !!----------------------------------------------------------------------
-   LOGICAL FUNCTION Agrif_Root()
-      Agrif_Root = .TRUE.
-   END FUNCTION Agrif_Root
-
-   CHARACTER(len=3) FUNCTION Agrif_CFixed()
-      Agrif_CFixed = '0' 
-   END FUNCTION Agrif_CFixed
-#endif
-!!st3: dom_oce_alloc modified to ease the ifdef if necessary (gm stuff)
-   INTEGER FUNCTION dom_oce_alloc()
-      !!----------------------------------------------------------------------
-      INTEGER                ::   ii
-      INTEGER, DIMENSION(30) :: ierr
-      !!----------------------------------------------------------------------
-      ii = 0   ;   ierr(:) = 0
-      !
-      ii = ii+1
-      ALLOCATE( mig(jpi), mjg(jpj), STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE( mi0 (jpiglo) , mi1 (jpiglo),  mj0(jpjglo) , mj1 (jpjglo) ,     &
-         &      tpol(jpiglo) , fpol(jpiglo)                              , STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE( glamt(jpi,jpj) ,    glamu(jpi,jpj) ,  glamv(jpi,jpj) ,  glamf(jpi,jpj) ,     &
-         &      gphit(jpi,jpj) ,    gphiu(jpi,jpj) ,  gphiv(jpi,jpj) ,  gphif(jpi,jpj) ,     &
-         &       e1t (jpi,jpj) ,     e2t (jpi,jpj) , r1_e1t(jpi,jpj) , r1_e2t(jpi,jpj) ,     &
-         &       e1u (jpi,jpj) ,     e2u (jpi,jpj) , r1_e1u(jpi,jpj) , r1_e2u(jpi,jpj) ,     &
-         &       e1v (jpi,jpj) ,     e2v (jpi,jpj) , r1_e1v(jpi,jpj) , r1_e2v(jpi,jpj) ,     &
-         &       e1f (jpi,jpj) ,     e2f (jpi,jpj) , r1_e1f(jpi,jpj) , r1_e2f(jpi,jpj) ,     &
-         &      e1e2t(jpi,jpj) , r1_e1e2t(jpi,jpj)                                     ,     &
-         &      e1e2u(jpi,jpj) , r1_e1e2u(jpi,jpj) , e2_e1u(jpi,jpj)                   ,     &
-         &      e1e2v(jpi,jpj) , r1_e1e2v(jpi,jpj) , e1_e2v(jpi,jpj)                   ,     &
-         &      e1e2f(jpi,jpj) , r1_e1e2f(jpi,jpj)                                     ,     &
-         &      ff_f (jpi,jpj) ,    ff_t (jpi,jpj)                                     , STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE(  e3t_0(jpi,jpj,jpk) , e3u_0 (jpi,jpj,jpk) , e3v_0 (jpi,jpj,jpk) , e3f_0(jpi,jpj,jpk) ,      &
-         &       e3w_0(jpi,jpj,jpk) , e3uw_0(jpi,jpj,jpk) , e3vw_0(jpi,jpj,jpk)                      ,  STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE( gdept_0(jpi,jpj,jpk)     , gdepw_0(jpi,jpj,jpk)     , gde3w_0(jpi,jpj,jpk) ,      &
-         &      gdept  (jpi,jpj,jpk,jpt) , gdepw  (jpi,jpj,jpk,jpt) , gde3w  (jpi,jpj,jpk) , STAT=ierr(ii) )
-         !
-!!st4
-#if ! defined key_qco
-      ii = ii+1
-      ALLOCATE( e3t(jpi,jpj,jpk,jpt) , e3u (jpi,jpj,jpk,jpt) , e3v (jpi,jpj,jpk,jpt) , e3f(jpi,jpj,jpk) ,      &
-         &      e3w(jpi,jpj,jpk,jpt) , e3uw(jpi,jpj,jpk,jpt) , e3vw(jpi,jpj,jpk,jpt)                    ,  STAT=ierr(ii) )
-#endif
-!!st4
-         !
-      ii = ii+1
-      ALLOCATE( r3t  (jpi,jpj,jpt)   , r3u  (jpi,jpj,jpt)    , r3v  (jpi,jpj,jpt)    , r3f  (jpi,jpj) ,  &
-         &      r3t_f(jpi,jpj)       , r3u_f(jpi,jpj)        , r3v_f(jpi,jpj)                         ,  STAT=ierr(ii) )       
-         !
-      ii = ii+1
-      ALLOCATE( ht_0(jpi,jpj) ,    hu_0(jpi,jpj)    ,    hv_0(jpi,jpj)     , hf_0(jpi,jpj) ,       &
-         &   r1_ht_0(jpi,jpj) , r1_hu_0(jpi,jpj) ,    r1_hv_0(jpi,jpj),   r1_hf_0(jpi,jpj) ,   STAT=ierr(ii)  )
-         !
-#if ! defined key_qco
-      ii = ii+1
-      ALLOCATE( ht  (jpi,jpj) ,    hu  (jpi,jpj,jpt),    hv  (jpi,jpj,jpt)                 ,       &
-         &                      r1_hu  (jpi,jpj,jpt), r1_hv  (jpi,jpj,jpt)                 ,   STAT=ierr(ii)  )
-#endif
-         !
-      ii = ii+1
-      ALLOCATE( risfdep(jpi,jpj) , bathy(jpi,jpj) , STAT=ierr(ii)  ) 
-         !
-      ii = ii+1
-      ALLOCATE( gdept_1d(jpk) , gdepw_1d(jpk) , e3t_1d(jpk) , e3w_1d(jpk) , STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE( tmask_i(jpi,jpj) , tmask_h(jpi,jpj) ,                                           &
-         &      ssmask (jpi,jpj) , ssumask(jpi,jpj) , ssvmask(jpi,jpj) , ssfmask(jpi,jpj) ,     &
-         &      mbkt   (jpi,jpj) , mbku   (jpi,jpj) , mbkv   (jpi,jpj) ,                    STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE( mikt(jpi,jpj), miku(jpi,jpj), mikv(jpi,jpj), mikf(jpi,jpj), STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE( tmask(jpi,jpj,jpk) , umask(jpi,jpj,jpk) ,     &
-         &      vmask(jpi,jpj,jpk) , fmask(jpi,jpj,jpk) , STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE( wmask(jpi,jpj,jpk) , wumask(jpi,jpj,jpk), wvmask(jpi,jpj,jpk) , STAT=ierr(ii) )
-      !
-      dom_oce_alloc = MAXVAL(ierr)
-      !
-   END FUNCTION dom_oce_alloc
-
-   !!======================================================================
-END MODULE dom_oce
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/domain.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/domain.F90	(revision 13603)
+++ 	(revision )
@@ -1,760 +1,0 @@
-MODULE domain
-   !!==============================================================================
-   !!                       ***  MODULE domain   ***
-   !! Ocean initialization : domain initialization
-   !!==============================================================================
-   !! History :  OPA  !  1990-10  (C. Levy - G. Madec)  Original code
-   !!                 !  1992-01  (M. Imbard) insert time step initialization
-   !!                 !  1996-06  (G. Madec) generalized vertical coordinate 
-   !!                 !  1997-02  (G. Madec) creation of domwri.F
-   !!                 !  2001-05  (E.Durand - G. Madec) insert closed sea
-   !!   NEMO     1.0  !  2002-08  (G. Madec)  F90: Free form and module
-   !!            2.0  !  2005-11  (V. Garnier) Surface pressure gradient organization
-   !!            3.3  !  2010-11  (G. Madec)  initialisation in C1D configuration
-   !!            3.6  !  2013     ( J. Simeon, C. Calone, G. Madec, C. Ethe ) Online coarsening of outputs
-   !!            3.7  !  2015-11  (G. Madec, A. Coward)  time varying zgr by default
-   !!            4.0  !  2016-10  (G. Madec, S. Flavoni)  domain configuration / user defined interface
-   !!----------------------------------------------------------------------
-   
-   !!----------------------------------------------------------------------
-   !!   dom_init      : initialize the space and time domain
-   !!   dom_glo       : initialize global domain <--> local domain indices
-   !!   dom_nam       : read and contral domain namelists
-   !!   dom_ctl       : control print for the ocean domain
-   !!   domain_cfg    : read the global domain size in domain configuration file
-   !!   cfg_write     : create the domain configuration file
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean variables
-   USE dom_oce        ! domain: ocean
-   USE sbc_oce        ! surface boundary condition: ocean
-   USE trc_oce        ! shared ocean & passive tracers variab
-   USE phycst         ! physical constants
-   USE domhgr         ! domain: set the horizontal mesh
-   USE domzgr         ! domain: set the vertical mesh
-   USE dommsk         ! domain: set the mask system
-   USE domwri         ! domain: write the meshmask file
-!!st5
-#if ! defined key_qco
-   USE domvvl         ! variable volume
-#else
-   USE domqco          ! variable volume
-#endif
-!!st5
-   USE c1d            ! 1D configuration
-   USE dyncor_c1d     ! 1D configuration: Coriolis term    (cor_c1d routine)
-   USE wet_dry, ONLY : ll_wd
-   USE closea , ONLY : dom_clo ! closed seas
-   !
-   USE in_out_manager ! I/O manager
-   USE iom            ! I/O library
-   USE lbclnk         ! ocean lateral boundary condition (or mpp link)
-   USE lib_mpp        ! distributed memory computing library
-!!an45
-!   USE usrdef_nam, ONLY : ln_45machin
-   !
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dom_init     ! called by nemogcm.F90
-   PUBLIC   domain_cfg   ! called by nemogcm.F90
-#  include "do_loop_substitute.h90"
-   !!-------------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: domain.F90 12822 2020-04-28 09:10:38Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!-------------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dom_init( Kbb, Kmm, Kaa, cdstr )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE dom_init  ***
-      !!                    
-      !! ** Purpose :   Domain initialization. Call the routines that are 
-      !!              required to create the arrays which define the space 
-      !!              and time domain of the ocean model.
-      !!
-      !! ** Method  : - dom_msk: compute the masks from the bathymetry file
-      !!              - dom_hgr: compute or read the horizontal grid-point position
-      !!                         and scale factors, and the coriolis factor
-      !!              - dom_zgr: define the vertical coordinate and the bathymetry
-      !!              - dom_wri: create the meshmask file (ln_meshmask=T)
-      !!              - 1D configuration, move Coriolis, u and v at T-point
-      !!----------------------------------------------------------------------
-      INTEGER          , INTENT(in) :: Kbb, Kmm, Kaa          ! ocean time level indices
-      CHARACTER (len=*), INTENT(in) :: cdstr                  ! model: NEMO or SAS. Determines core restart variables
-      !
-!!st6
-      INTEGER ::   ji, jj, jk, jt   ! dummy loop indices
-!!st6
-      INTEGER ::   iconf = 0    ! local integers
-      CHARACTER (len=64) ::   cform = "(A12, 3(A13, I7))" 
-      INTEGER , DIMENSION(jpi,jpj) ::   ik_top , ik_bot       ! top and bottom ocean level
-      REAL(wp), DIMENSION(jpi,jpj) ::   z1_hu_0, z1_hv_0
-      REAL(wp)::   zcoeff                                     ! local real
-
-      !!----------------------------------------------------------------------
-      !
-      IF(lwp) THEN         ! Ocean domain Parameters (control print)
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_init : domain initialization'
-         WRITE(numout,*) '~~~~~~~~'
-         !
-         WRITE(numout,*)     '   Domain info'
-         WRITE(numout,*)     '      dimension of model:'
-         WRITE(numout,*)     '             Local domain      Global domain       Data domain '
-         WRITE(numout,cform) '        ','   jpi     : ', jpi, '   jpiglo  : ', jpiglo
-         WRITE(numout,cform) '        ','   jpj     : ', jpj, '   jpjglo  : ', jpjglo
-         WRITE(numout,cform) '        ','   jpk     : ', jpk, '   jpkglo  : ', jpkglo
-         WRITE(numout,cform) '       ' ,'   jpij    : ', jpij
-         WRITE(numout,*)     '      mpp local domain info (mpp):'
-         WRITE(numout,*)     '              jpni    : ', jpni, '   nn_hls  : ', nn_hls
-         WRITE(numout,*)     '              jpnj    : ', jpnj, '   nn_hls  : ', nn_hls
-         WRITE(numout,*)     '              jpnij   : ', jpnij
-         WRITE(numout,*)     '      lateral boundary of the Global domain : jperio  = ', jperio
-         SELECT CASE ( jperio )
-         CASE( 0 )   ;   WRITE(numout,*) '         (i.e. closed)'
-         CASE( 1 )   ;   WRITE(numout,*) '         (i.e. cyclic east-west)'
-         CASE( 2 )   ;   WRITE(numout,*) '         (i.e. cyclic north-south)'
-         CASE( 3 )   ;   WRITE(numout,*) '         (i.e. north fold with T-point pivot)'
-         CASE( 4 )   ;   WRITE(numout,*) '         (i.e. cyclic east-west and north fold with T-point pivot)'
-         CASE( 5 )   ;   WRITE(numout,*) '         (i.e. north fold with F-point pivot)'
-         CASE( 6 )   ;   WRITE(numout,*) '         (i.e. cyclic east-west and north fold with F-point pivot)'
-         CASE( 7 )   ;   WRITE(numout,*) '         (i.e. cyclic east-west and north-south)'
-         CASE DEFAULT
-            CALL ctl_stop( 'dom_init:   jperio is out of range' )
-         END SELECT
-         WRITE(numout,*)     '      Ocean model configuration used:'
-         WRITE(numout,*)     '         cn_cfg = ', TRIM( cn_cfg ), '   nn_cfg = ', nn_cfg
-      ENDIF
-      lwxios = .FALSE.
-      ln_xios_read = .FALSE.
-      !
-      !           !==  Reference coordinate system  ==!
-      !
-      CALL dom_glo                     ! global domain versus local domain
-      CALL dom_nam                     ! read namelist ( namrun, namdom )
-      !
-      IF( lwxios ) THEN
-!define names for restart write and set core output (restart.F90)
-         CALL iom_set_rst_vars(rst_wfields)
-         CALL iom_set_rstw_core(cdstr)
-      ENDIF
-!reset namelist for SAS
-      IF(cdstr == 'SAS') THEN
-         IF(lrxios) THEN
-               IF(lwp) write(numout,*) 'Disable reading restart file using XIOS for SAS'
-               lrxios = .FALSE.
-         ENDIF
-      ENDIF
-      !
-      CALL dom_hgr                      ! Horizontal mesh
-
-      IF( ln_closea ) CALL dom_clo      ! Read in masks to define closed seas and lakes
-
-      CALL dom_zgr( ik_top, ik_bot )    ! Vertical mesh and bathymetry (return top and bottom ocean t-level indices)
-
-      CALL dom_msk( ik_top, ik_bot )    ! Masks
-      !
-      ht_0(:,:) = 0._wp  ! Reference ocean thickness
-      hu_0(:,:) = 0._wp
-      hv_0(:,:) = 0._wp
-      hf_0(:,:) = 0._wp
-      DO jk = 1, jpkm1
-         ht_0(:,:) = ht_0(:,:) + e3t_0(:,:,jk) * tmask(:,:,jk)
-         hu_0(:,:) = hu_0(:,:) + e3u_0(:,:,jk) * umask(:,:,jk)
-         hv_0(:,:) = hv_0(:,:) + e3v_0(:,:,jk) * vmask(:,:,jk)
-         hf_0(:,:) = hf_0(:,:) + e3f_0(:,:,jk) * ssfmask(:,:)     ! CAUTION : only valid in SWE, not with bathymetry
-      END DO
-      !
-!!anhf hf_0 = mean(ht_0*tmask) so hf = mimj( ht0 + ssht)
-! ne pas combiner avec an45 tout de suite
-!      DO_2D( 1, 0, 1, 0 )
-!         hf_0(ji,jj) = 0.25_wp * (   ht_0(ji,jj+1) * tmask(ji,jj+1,1) + ht_0(ji+1,jj+1) * tmask(ji+1,jj+1,1)   &
-!            &                      + ht_0(ji,jj  ) * tmask(ji,jj  ,1) + ht_0(ji+1,jj  ) * tmask(ji+1,jj  ,1)   )
-!      END_2D
-!      CALL lbc_lnk( 'domain', hf_0, 'F', 1. )      ! Lateral boundary conditions
-!!anhf
-      !                                 ! Inverse of reference ocean thickness
-      r1_ht_0(:,:) =  ssmask(:,:) / ( ht_0(:,:) + 1._wp -  ssmask(:,:) )
-      r1_hu_0(:,:) = ssumask(:,:) / ( hu_0(:,:) + 1._wp - ssumask(:,:) )
-      r1_hv_0(:,:) = ssvmask(:,:) / ( hv_0(:,:) + 1._wp - ssvmask(:,:) )
-      r1_hf_0(:,:) = ssfmask(:,:) / ( hf_0(:,:) + 1._wp - ssfmask(:,:) )
-      !
-!!an45 Ligne de cote a 45deg : e1e2t *= ( mi(umask) + mj(vmask) ) /2
-!!                             idem pour e1e2f
-!      DO_2D( 1, 0, 1, 0 )
-!      zcoeff = 0.25_wp * (   umask(ji,jj+1,1) + umask(ji+1,jj+1,1)   &
-!         &                 + vmask(ji,jj  ,1) + vmask(ji+1,jj  ,1)   )
-!         IF ( zcoeff /= 0._wp )   THEN
-!               e1e2t(ji,jj) =    e1e2t(ji,jj) * zcoeff
-!            r1_e1e2t(ji,jj) = r1_e1e2t(ji,jj) / zcoeff
-!         ENDIF
-!      END_2D
-!      WRITE(numout,*) '   an45 half T cell e1e2t '
-!      zcoeff = 0.25_wp * (   umask(ji,jj+1,1) + umask(ji+1,jj+1,1)   &
-!         &                 + vmask(ji,jj  ,1) + vmask(ji+1,jj  ,1)   )
-!         IF ( zcoeff /= 0._wp )   THEN
-!               e1e2t(ji,jj) =    e1e2t(ji,jj) * zcoeff
-!            r1_e1e2t(ji,jj) = r1_e1e2t(ji,jj) / zcoeff
-!!an45
-!!st7 : make it easier to use key_qco condition (gm stuff)
-#if defined key_qco
-      !           !==  initialisation of time varying coordinate  ==!   Quasi-Euerian coordinate case
-      !
-      IF( .NOT.l_offline )   CALL dom_qco_init( Kbb, Kmm, Kaa )
-      !
-      IF( ln_linssh )        CALL ctl_stop('STOP','domain: key_qco and ln_linssh = T are incompatible')
-      !
-#else
-      !           !==  time varying part of coordinate system  ==!
-      !
-      IF( ln_linssh ) THEN       != Fix in time : set to the reference one for all
-         !
-         DO jt = 1, jpt                         ! depth of t- and w-grid-points
-            gdept(:,:,:,jt) = gdept_0(:,:,:)
-            gdepw(:,:,:,jt) = gdepw_0(:,:,:)
-         END DO
-            gde3w(:,:,:)    = gde3w_0(:,:,:)    ! = gdept as the sum of e3t
-         !
-         DO jt = 1, jpt                         ! vertical scale factors
-            e3t(:,:,:,jt) =  e3t_0(:,:,:)
-            e3u(:,:,:,jt) =  e3u_0(:,:,:)
-            e3v(:,:,:,jt) =  e3v_0(:,:,:)
-            e3w(:,:,:,jt) =  e3w_0(:,:,:)
-            e3uw(:,:,:,jt) = e3uw_0(:,:,:)
-            e3vw(:,:,:,jt) = e3vw_0(:,:,:)
-         END DO
-            e3f(:,:,:)    =  e3f_0(:,:,:)
-         !
-         DO jt = 1, jpt                         ! water column thickness and its inverse
-            hu(:,:,jt)    =    hu_0(:,:)
-            hv(:,:,jt)    =    hv_0(:,:)
-            r1_hu(:,:,jt) = r1_hu_0(:,:)
-            r1_hv(:,:,jt) = r1_hv_0(:,:)
-         END DO
-            ht(:,:) =    ht_0(:,:)
-         !
-      ELSE                       != time varying : initialize before/now/after variables
-         !
-         IF( .NOT.l_offline )   CALL dom_vvl_init( Kbb, Kmm, Kaa )
-         !
-      ENDIF
-#endif
-!!st7
-      !
-      IF( lk_c1d         )   CALL cor_c1d       ! 1D configuration: Coriolis set at T-point
-      !
-      IF( ln_meshmask    )   CALL dom_wri       ! Create a domain file
-
-      IF( .NOT.ln_rstart )   CALL dom_ctl       ! Domain control
-      !
-      IF( ln_write_cfg   )   CALL cfg_write     ! create the configuration file
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_init :   ==>>>   END of domain initialization'
-         WRITE(numout,*) '~~~~~~~~'
-         WRITE(numout,*) 
-      ENDIF
-      !
-   END SUBROUTINE dom_init
-
-
-   SUBROUTINE dom_glo
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE dom_glo  ***
-      !!
-      !! ** Purpose :   initialization of global domain <--> local domain indices
-      !!
-      !! ** Method  :   
-      !!
-      !! ** Action  : - mig , mjg : local  domain indices ==> global domain indices
-      !!              - mi0 , mi1 : global domain indices ==> local  domain indices
-      !!              - mj0,, mj1   (global point not in the local domain ==> mi0>mi1 and/or mj0>mj1)
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj   ! dummy loop argument
-      !!----------------------------------------------------------------------
-      !
-      DO ji = 1, jpi                 ! local domain indices ==> global domain indices
-        mig(ji) = ji + nimpp - 1
-      END DO
-      DO jj = 1, jpj
-        mjg(jj) = jj + njmpp - 1
-      END DO
-      !                              ! global domain indices ==> local domain indices
-      !                                   ! (return (m.0,m.1)=(1,0) if data domain gridpoint is to the west/south of the 
-      !                                   ! local domain, or (m.0,m.1)=(jp.+1,jp.) to the east/north of local domain. 
-      DO ji = 1, jpiglo
-        mi0(ji) = MAX( 1 , MIN( ji - nimpp + 1, jpi+1 ) )
-        mi1(ji) = MAX( 0 , MIN( ji - nimpp + 1, jpi   ) )
-      END DO
-      DO jj = 1, jpjglo
-        mj0(jj) = MAX( 1 , MIN( jj - njmpp + 1, jpj+1 ) )
-        mj1(jj) = MAX( 0 , MIN( jj - njmpp + 1, jpj   ) )
-      END DO
-      IF(lwp) THEN                   ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_glo : domain: global <<==>> local '
-         WRITE(numout,*) '~~~~~~~ '
-         WRITE(numout,*) '   global domain:   jpiglo = ', jpiglo, ' jpjglo = ', jpjglo, ' jpkglo = ', jpkglo
-         WRITE(numout,*) '   local  domain:   jpi    = ', jpi   , ' jpj    = ', jpj   , ' jpk    = ', jpk
-         WRITE(numout,*)
-         WRITE(numout,*) '   conversion from local to global domain indices (and vise versa) done'
-         IF( nn_print >= 1 ) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) '          conversion local  ==> global i-index domain (mig)'
-            WRITE(numout,25)              (mig(ji),ji = 1,jpi)
-            WRITE(numout,*)
-            WRITE(numout,*) '          conversion global ==> local  i-index domain'
-            WRITE(numout,*) '             starting index (mi0)'
-            WRITE(numout,25)              (mi0(ji),ji = 1,jpiglo)
-            WRITE(numout,*) '             ending index (mi1)'
-            WRITE(numout,25)              (mi1(ji),ji = 1,jpiglo)
-            WRITE(numout,*)
-            WRITE(numout,*) '          conversion local  ==> global j-index domain (mjg)'
-            WRITE(numout,25)              (mjg(jj),jj = 1,jpj)
-            WRITE(numout,*)
-            WRITE(numout,*) '          conversion global ==> local  j-index domain'
-            WRITE(numout,*) '             starting index (mj0)'
-            WRITE(numout,25)              (mj0(jj),jj = 1,jpjglo)
-            WRITE(numout,*) '             ending index (mj1)'
-            WRITE(numout,25)              (mj1(jj),jj = 1,jpjglo)
-         ENDIF
-      ENDIF
- 25   FORMAT( 100(10x,19i4,/) )
-      !
-   END SUBROUTINE dom_glo
-
-
-   SUBROUTINE dom_nam
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE dom_nam  ***
-      !!                    
-      !! ** Purpose :   read domaine namelists and print the variables.
-      !!
-      !! ** input   : - namrun namelist
-      !!              - namdom namelist
-      !!              - namnc4 namelist   ! "key_netcdf4" only
-      !!----------------------------------------------------------------------
-      USE ioipsl
-      !!
-      INTEGER  ::   ios   ! Local integer
-      !
-      NAMELIST/namrun/ cn_ocerst_indir, cn_ocerst_outdir, nn_stocklist, ln_rst_list,                 &
-         &             nn_no   , cn_exp   , cn_ocerst_in, cn_ocerst_out, ln_rstart , nn_rstctl ,     &
-         &             nn_it000, nn_itend , nn_date0    , nn_time0     , nn_leapy  , nn_istate ,     &
-         &             nn_stock, nn_write , ln_mskland  , ln_clobber   , nn_chunksz, ln_1st_euler  , &
-         &             ln_cfmeta, ln_xios_read, nn_wxios
-      NAMELIST/namdom/ ln_linssh, rn_Dt, rn_atfp, ln_crs, ln_meshmask
-#if defined key_netcdf4
-      NAMELIST/namnc4/ nn_nchunks_i, nn_nchunks_j, nn_nchunks_k, ln_nc4zip
-#endif
-      !!----------------------------------------------------------------------
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_nam : domain initialization through namelist read'
-         WRITE(numout,*) '~~~~~~~ '
-      ENDIF
-      !
-      !
-      READ  ( numnam_ref, namrun, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namrun in reference namelist' )
-      READ  ( numnam_cfg, namrun, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namrun in configuration namelist' )
-      IF(lwm) WRITE ( numond, namrun )
-      !
-      IF(lwp) THEN                  ! control print
-         WRITE(numout,*) '   Namelist : namrun   ---   run parameters'
-         WRITE(numout,*) '      Assimilation cycle              nn_no           = ', nn_no
-         WRITE(numout,*) '      experiment name for output      cn_exp          = ', TRIM( cn_exp           )
-         WRITE(numout,*) '      file prefix restart input       cn_ocerst_in    = ', TRIM( cn_ocerst_in     )
-         WRITE(numout,*) '      restart input directory         cn_ocerst_indir = ', TRIM( cn_ocerst_indir  )
-         WRITE(numout,*) '      file prefix restart output      cn_ocerst_out   = ', TRIM( cn_ocerst_out    )
-         WRITE(numout,*) '      restart output directory        cn_ocerst_outdir= ', TRIM( cn_ocerst_outdir )
-         WRITE(numout,*) '      restart logical                 ln_rstart       = ', ln_rstart
-         WRITE(numout,*) '      start with forward time step    ln_1st_euler    = ', ln_1st_euler
-         WRITE(numout,*) '      control of time step            nn_rstctl       = ', nn_rstctl
-         WRITE(numout,*) '      number of the first time step   nn_it000        = ', nn_it000
-         WRITE(numout,*) '      number of the last time step    nn_itend        = ', nn_itend
-         WRITE(numout,*) '      initial calendar date aammjj    nn_date0        = ', nn_date0
-         WRITE(numout,*) '      initial time of day in hhmm     nn_time0        = ', nn_time0
-         WRITE(numout,*) '      leap year calendar (0/1)        nn_leapy        = ', nn_leapy
-         WRITE(numout,*) '      initial state output            nn_istate       = ', nn_istate
-         IF( ln_rst_list ) THEN
-            WRITE(numout,*) '      list of restart dump times      nn_stocklist    =', nn_stocklist
-         ELSE
-            WRITE(numout,*) '      frequency of restart file       nn_stock        = ', nn_stock
-         ENDIF
-#if ! defined key_iomput
-         WRITE(numout,*) '      frequency of output file        nn_write        = ', nn_write
-#endif
-         WRITE(numout,*) '      mask land points                ln_mskland      = ', ln_mskland
-         WRITE(numout,*) '      additional CF standard metadata ln_cfmeta       = ', ln_cfmeta
-         WRITE(numout,*) '      overwrite an existing file      ln_clobber      = ', ln_clobber
-         WRITE(numout,*) '      NetCDF chunksize (bytes)        nn_chunksz      = ', nn_chunksz
-         IF( TRIM(Agrif_CFixed()) == '0' ) THEN
-            WRITE(numout,*) '      READ restart for a single file using XIOS ln_xios_read =', ln_xios_read
-            WRITE(numout,*) '      Write restart using XIOS        nn_wxios   = ', nn_wxios
-         ELSE
-            WRITE(numout,*) "      AGRIF: nn_wxios will be ingored. See setting for parent"
-            WRITE(numout,*) "      AGRIF: ln_xios_read will be ingored. See setting for parent"
-         ENDIF
-      ENDIF
-
-      cexper = cn_exp         ! conversion DOCTOR names into model names (this should disappear soon)
-      nrstdt = nn_rstctl
-      nit000 = nn_it000
-      nitend = nn_itend
-      ndate0 = nn_date0
-      nleapy = nn_leapy
-      ninist = nn_istate
-      l_1st_euler = ln_1st_euler
-      IF( .NOT. l_1st_euler .AND. .NOT. ln_rstart ) THEN
-         IF(lwp) WRITE(numout,*)  
-         IF(lwp) WRITE(numout,*)'   ==>>>   Start from rest (ln_rstart=F)'
-         IF(lwp) WRITE(numout,*)'           an Euler initial time step is used : l_1st_euler is forced to .true. '   
-         l_1st_euler = .true.
-      ENDIF
-      !                             ! control of output frequency
-      IF( .NOT. ln_rst_list ) THEN     ! we use nn_stock
-         IF( nn_stock == -1 )   CALL ctl_warn( 'nn_stock = -1 --> no restart will be done' )
-         IF( nn_stock == 0 .OR. nn_stock > nitend ) THEN
-            WRITE(ctmp1,*) 'nn_stock = ', nn_stock, ' it is forced to ', nitend
-            CALL ctl_warn( ctmp1 )
-            nn_stock = nitend
-         ENDIF
-      ENDIF
-#if ! defined key_iomput
-      IF( nn_write == -1 )   CALL ctl_warn( 'nn_write = -1 --> no output files will be done' )
-      IF ( nn_write == 0 ) THEN
-         WRITE(ctmp1,*) 'nn_write = ', nn_write, ' it is forced to ', nitend
-         CALL ctl_warn( ctmp1 )
-         nn_write = nitend
-      ENDIF
-#endif
-
-#if defined key_agrif
-      IF( Agrif_Root() ) THEN
-#endif
-      IF(lwp) WRITE(numout,*)
-      SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
-      CASE (  1 ) 
-         CALL ioconf_calendar('gregorian')
-         IF(lwp) WRITE(numout,*) '   ==>>>   The IOIPSL calendar is "gregorian", i.e. leap year'
-      CASE (  0 )
-         CALL ioconf_calendar('noleap')
-         IF(lwp) WRITE(numout,*) '   ==>>>   The IOIPSL calendar is "noleap", i.e. no leap year'
-      CASE ( 30 )
-         CALL ioconf_calendar('360d')
-         IF(lwp) WRITE(numout,*) '   ==>>>   The IOIPSL calendar is "360d", i.e. 360 days in a year'
-      END SELECT
-#if defined key_agrif
-      ENDIF
-#endif
-
-      READ  ( numnam_ref, namdom, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdom in reference namelist' )
-      READ  ( numnam_cfg, namdom, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdom in configuration namelist' )
-      IF(lwm) WRITE( numond, namdom )
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) '   Namelist : namdom   ---   space & time domain'
-         WRITE(numout,*) '      linear free surface (=T)                ln_linssh   = ', ln_linssh
-         WRITE(numout,*) '      create mesh/mask file                   ln_meshmask = ', ln_meshmask
-         WRITE(numout,*) '      ocean time step                         rn_Dt       = ', rn_Dt
-         WRITE(numout,*) '      asselin time filter parameter           rn_atfp     = ', rn_atfp
-         WRITE(numout,*) '      online coarsening of dynamical fields   ln_crs      = ', ln_crs
-      ENDIF
-      !
-      !! Initialise current model timestep rDt = 2*rn_Dt if MLF or rDt = rn_Dt if RK3
-      rDt  = 2._wp * rn_Dt
-      r1_Dt = 1._wp / rDt
-
-      IF( TRIM(Agrif_CFixed()) == '0' ) THEN
-         lrxios = ln_xios_read.AND.ln_rstart
-!set output file type for XIOS based on NEMO namelist 
-         IF (nn_wxios > 0) lwxios = .TRUE. 
-         nxioso = nn_wxios
-      ENDIF
-
-#if defined key_netcdf4
-      !                             ! NetCDF 4 case   ("key_netcdf4" defined)
-      READ  ( numnam_ref, namnc4, IOSTAT = ios, ERR = 907)
-907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namnc4 in reference namelist' )
-      READ  ( numnam_cfg, namnc4, IOSTAT = ios, ERR = 908 )
-908   IF( ios >  0 )   CALL ctl_nam ( ios , 'namnc4 in configuration namelist' )
-      IF(lwm) WRITE( numond, namnc4 )
-
-      IF(lwp) THEN                        ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) '   Namelist namnc4 - Netcdf4 chunking parameters'
-         WRITE(numout,*) '      number of chunks in i-dimension             nn_nchunks_i = ', nn_nchunks_i
-         WRITE(numout,*) '      number of chunks in j-dimension             nn_nchunks_j = ', nn_nchunks_j
-         WRITE(numout,*) '      number of chunks in k-dimension             nn_nchunks_k = ', nn_nchunks_k
-         WRITE(numout,*) '      apply netcdf4/hdf5 chunking & compression   ln_nc4zip    = ', ln_nc4zip
-      ENDIF
-
-      ! Put the netcdf4 settings into a simple structure (snc4set, defined in in_out_manager module)
-      ! Note the chunk size in the unlimited (time) dimension will be fixed at 1
-      snc4set%ni   = nn_nchunks_i
-      snc4set%nj   = nn_nchunks_j
-      snc4set%nk   = nn_nchunks_k
-      snc4set%luse = ln_nc4zip
-#else
-      snc4set%luse = .FALSE.        ! No NetCDF 4 case
-#endif
-      !
-   END SUBROUTINE dom_nam
-
-
-   SUBROUTINE dom_ctl
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE dom_ctl  ***
-      !!
-      !! ** Purpose :   Domain control.
-      !!
-      !! ** Method  :   compute and print extrema of masked scale factors
-      !!----------------------------------------------------------------------
-      INTEGER, DIMENSION(2) ::   imi1, imi2, ima1, ima2
-      INTEGER, DIMENSION(2) ::   iloc   ! 
-      REAL(wp) ::   ze1min, ze1max, ze2min, ze2max
-      !!----------------------------------------------------------------------
-      !
-      IF(lk_mpp) THEN
-         CALL mpp_minloc( 'domain', e1t(:,:), tmask_i(:,:), ze1min, imi1 )
-         CALL mpp_minloc( 'domain', e2t(:,:), tmask_i(:,:), ze2min, imi2 )
-         CALL mpp_maxloc( 'domain', e1t(:,:), tmask_i(:,:), ze1max, ima1 )
-         CALL mpp_maxloc( 'domain', e2t(:,:), tmask_i(:,:), ze2max, ima2 )
-      ELSE
-         ze1min = MINVAL( e1t(:,:), mask = tmask_i(:,:) == 1._wp )    
-         ze2min = MINVAL( e2t(:,:), mask = tmask_i(:,:) == 1._wp )    
-         ze1max = MAXVAL( e1t(:,:), mask = tmask_i(:,:) == 1._wp )    
-         ze2max = MAXVAL( e2t(:,:), mask = tmask_i(:,:) == 1._wp )    
-         !
-         iloc  = MINLOC( e1t(:,:), mask = tmask_i(:,:) == 1._wp )
-         imi1(1) = iloc(1) + nimpp - 1
-         imi1(2) = iloc(2) + njmpp - 1
-         iloc  = MINLOC( e2t(:,:), mask = tmask_i(:,:) == 1._wp )
-         imi2(1) = iloc(1) + nimpp - 1
-         imi2(2) = iloc(2) + njmpp - 1
-         iloc  = MAXLOC( e1t(:,:), mask = tmask_i(:,:) == 1._wp )
-         ima1(1) = iloc(1) + nimpp - 1
-         ima1(2) = iloc(2) + njmpp - 1
-         iloc  = MAXLOC( e2t(:,:), mask = tmask_i(:,:) == 1._wp )
-         ima2(1) = iloc(1) + nimpp - 1
-         ima2(2) = iloc(2) + njmpp - 1
-      ENDIF
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_ctl : extrema of the masked scale factors'
-         WRITE(numout,*) '~~~~~~~'
-         WRITE(numout,"(14x,'e1t maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") ze1max, ima1(1), ima1(2)
-         WRITE(numout,"(14x,'e1t mini: ',1f10.2,' at i = ',i5,' j= ',i5)") ze1min, imi1(1), imi1(2)
-         WRITE(numout,"(14x,'e2t maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") ze2max, ima2(1), ima2(2)
-         WRITE(numout,"(14x,'e2t mini: ',1f10.2,' at i = ',i5,' j= ',i5)") ze2min, imi2(1), imi2(2)
-      ENDIF
-      !
-   END SUBROUTINE dom_ctl
-
-
-   SUBROUTINE domain_cfg( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE dom_nam  ***
-      !!                    
-      !! ** Purpose :   read the domain size in domain configuration file
-      !!
-      !! ** Method  :   read the cn_domcfg NetCDF file
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
-      INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
-      INTEGER                       , INTENT(out) ::   kpi, kpj, kpk   ! global domain sizes 
-      INTEGER                       , INTENT(out) ::   kperio          ! lateral global domain b.c. 
-      !
-      INTEGER ::   inum   ! local integer
-      REAL(wp) ::   zorca_res                     ! local scalars
-      REAL(wp) ::   zperio                        !   -      -
-      INTEGER, DIMENSION(4) ::   idvar, idimsz    ! size   of dimensions
-      !!----------------------------------------------------------------------
-      !
-      IF(lwp) THEN
-         WRITE(numout,*) '           '
-         WRITE(numout,*) 'domain_cfg : domain size read in ', TRIM( cn_domcfg ), ' file'
-         WRITE(numout,*) '~~~~~~~~~~ '
-      ENDIF
-      !
-      CALL iom_open( cn_domcfg, inum )
-      !
-      !                                   !- ORCA family specificity
-      IF(  iom_varid( inum, 'ORCA'       , ldstop = .FALSE. ) > 0  .AND.  &
-         & iom_varid( inum, 'ORCA_index' , ldstop = .FALSE. ) > 0    ) THEN
-         !
-         cd_cfg = 'ORCA'
-         CALL iom_get( inum, 'ORCA_index', zorca_res )   ;   kk_cfg = NINT( zorca_res )
-         !
-         IF(lwp) THEN
-            WRITE(numout,*) '   .'
-            WRITE(numout,*) '   ==>>>   ORCA configuration '
-            WRITE(numout,*) '   .'
-         ENDIF
-         !
-      ELSE                                !- cd_cfg & k_cfg are not used
-         cd_cfg = 'UNKNOWN'
-         kk_cfg = -9999999
-                                          !- or they may be present as global attributes 
-                                          !- (netcdf only)  
-         CALL iom_getatt( inum, 'cn_cfg', cd_cfg )  ! returns   !  if not found
-         CALL iom_getatt( inum, 'nn_cfg', kk_cfg )  ! returns -999 if not found
-         IF( TRIM(cd_cfg) == '!') cd_cfg = 'UNKNOWN'
-         IF( kk_cfg == -999     ) kk_cfg = -9999999
-         !
-      ENDIF
-       !
-      idvar = iom_varid( inum, 'e3t_0', kdimsz = idimsz )   ! use e3t_0, that must exist, to get jp(ijk)glo
-      kpi = idimsz(1)
-      kpj = idimsz(2)
-      kpk = idimsz(3)
-      CALL iom_get( inum, 'jperio', zperio )   ;   kperio = NINT( zperio )
-      CALL iom_close( inum )
-      !
-      IF(lwp) THEN
-         WRITE(numout,*) '      cn_cfg = ', TRIM(cd_cfg), '   nn_cfg = ', kk_cfg
-         WRITE(numout,*) '      jpiglo = ', kpi
-         WRITE(numout,*) '      jpjglo = ', kpj
-         WRITE(numout,*) '      jpkglo = ', kpk
-         WRITE(numout,*) '      type of global domain lateral boundary   jperio = ', kperio
-      ENDIF
-      !        
-   END SUBROUTINE domain_cfg
-   
-   
-   SUBROUTINE cfg_write
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE cfg_write  ***
-      !!                   
-      !! ** Purpose :   Create the "cn_domcfg_out" file, a NetCDF file which 
-      !!              contains all the ocean domain informations required to 
-      !!              define an ocean configuration.
-      !!
-      !! ** Method  :   Write in a file all the arrays required to set up an
-      !!              ocean configuration.
-      !!
-      !! ** output file :   domcfg_out.nc : domain size, characteristics, horizontal 
-      !!                       mesh, Coriolis parameter, and vertical scale factors
-      !!                    NB: also contain ORCA family information
-      !!----------------------------------------------------------------------
-      INTEGER           ::   ji, jj, jk   ! dummy loop indices
-      INTEGER           ::   izco, izps, isco, icav
-      INTEGER           ::   inum     ! local units
-      CHARACTER(len=21) ::   clnam    ! filename (mesh and mask informations)
-      REAL(wp), DIMENSION(jpi,jpj) ::   z2d   ! workspace
-      !!----------------------------------------------------------------------
-      !
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'cfg_write : create the domain configuration file (', TRIM(cn_domcfg_out),'.nc)'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~'
-      !
-      !                       ! ============================= !
-      !                       !  create 'domcfg_out.nc' file  !
-      !                       ! ============================= !
-      !         
-      clnam = cn_domcfg_out  ! filename (configuration information)
-      CALL iom_open( TRIM(clnam), inum, ldwrt = .TRUE. )
-      
-      !
-      !                             !==  ORCA family specificities  ==!
-      IF( cn_cfg == "ORCA" ) THEN
-         CALL iom_rstput( 0, 0, inum, 'ORCA'      , 1._wp            , ktype = jp_i4 )
-         CALL iom_rstput( 0, 0, inum, 'ORCA_index', REAL( nn_cfg, wp), ktype = jp_i4 )         
-      ENDIF
-      !
-      !                             !==  global domain size  ==!
-      !
-      CALL iom_rstput( 0, 0, inum, 'jpiglo', REAL( jpiglo, wp), ktype = jp_i4 )
-      CALL iom_rstput( 0, 0, inum, 'jpjglo', REAL( jpjglo, wp), ktype = jp_i4 )
-      CALL iom_rstput( 0, 0, inum, 'jpkglo', REAL( jpk   , wp), ktype = jp_i4 )
-      !
-      !                             !==  domain characteristics  ==!
-      !
-      !                                   ! lateral boundary of the global domain
-      CALL iom_rstput( 0, 0, inum, 'jperio', REAL( jperio, wp), ktype = jp_i4 )
-      !
-      !                                   ! type of vertical coordinate
-      IF( ln_zco    ) THEN   ;   izco = 1   ;   ELSE   ;   izco = 0   ;   ENDIF
-      IF( ln_zps    ) THEN   ;   izps = 1   ;   ELSE   ;   izps = 0   ;   ENDIF
-      IF( ln_sco    ) THEN   ;   isco = 1   ;   ELSE   ;   isco = 0   ;   ENDIF
-      CALL iom_rstput( 0, 0, inum, 'ln_zco'   , REAL( izco, wp), ktype = jp_i4 )
-      CALL iom_rstput( 0, 0, inum, 'ln_zps'   , REAL( izps, wp), ktype = jp_i4 )
-      CALL iom_rstput( 0, 0, inum, 'ln_sco'   , REAL( isco, wp), ktype = jp_i4 )
-      !
-      !                                   ! ocean cavities under iceshelves
-      IF( ln_isfcav ) THEN   ;   icav = 1   ;   ELSE   ;   icav = 0   ;   ENDIF
-      CALL iom_rstput( 0, 0, inum, 'ln_isfcav', REAL( icav, wp), ktype = jp_i4 )
-      !
-      !                             !==  horizontal mesh  !
-      !
-      CALL iom_rstput( 0, 0, inum, 'glamt', glamt, ktype = jp_r8 )   ! latitude
-      CALL iom_rstput( 0, 0, inum, 'glamu', glamu, ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'glamv', glamv, ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'glamf', glamf, ktype = jp_r8 )
-      !                                
-      CALL iom_rstput( 0, 0, inum, 'gphit', gphit, ktype = jp_r8 )   ! longitude
-      CALL iom_rstput( 0, 0, inum, 'gphiu', gphiu, ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'gphiv', gphiv, ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'gphif', gphif, ktype = jp_r8 )
-      !                                
-      CALL iom_rstput( 0, 0, inum, 'e1t'  , e1t  , ktype = jp_r8 )   ! i-scale factors (e1.)
-      CALL iom_rstput( 0, 0, inum, 'e1u'  , e1u  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e1v'  , e1v  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e1f'  , e1f  , ktype = jp_r8 )
-      !
-      CALL iom_rstput( 0, 0, inum, 'e2t'  , e2t  , ktype = jp_r8 )   ! j-scale factors (e2.)
-      CALL iom_rstput( 0, 0, inum, 'e2u'  , e2u  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e2v'  , e2v  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e2f'  , e2f  , ktype = jp_r8 )
-      !
-      CALL iom_rstput( 0, 0, inum, 'ff_f' , ff_f , ktype = jp_r8 )   ! coriolis factor
-      CALL iom_rstput( 0, 0, inum, 'ff_t' , ff_t , ktype = jp_r8 )
-      !
-      !                             !==  vertical mesh  ==!
-      !                                                     
-      CALL iom_rstput( 0, 0, inum, 'e3t_1d'  , e3t_1d , ktype = jp_r8 )   ! reference 1D-coordinate
-      CALL iom_rstput( 0, 0, inum, 'e3w_1d'  , e3w_1d , ktype = jp_r8 )
-      !
-      CALL iom_rstput( 0, 0, inum, 'e3t_0'   , e3t_0  , ktype = jp_r8 )   ! vertical scale factors
-      CALL iom_rstput( 0, 0, inum, 'e3u_0'   , e3u_0  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e3v_0'   , e3v_0  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e3f_0'   , e3f_0  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e3w_0'   , e3w_0  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e3uw_0'  , e3uw_0 , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e3vw_0'  , e3vw_0 , ktype = jp_r8 )
-      !                                         
-      !                             !==  wet top and bottom level  ==!   (caution: multiplied by ssmask)
-      !
-      CALL iom_rstput( 0, 0, inum, 'top_level'    , REAL( mikt, wp )*ssmask , ktype = jp_i4 )   ! nb of ocean T-points (ISF)
-      CALL iom_rstput( 0, 0, inum, 'bottom_level' , REAL( mbkt, wp )*ssmask , ktype = jp_i4 )   ! nb of ocean T-points
-      !
-      IF( ln_sco ) THEN             ! s-coordinate: store grid stiffness ratio  (Not required anyway)
-         CALL dom_stiff( z2d )
-         CALL iom_rstput( 0, 0, inum, 'stiffness', z2d )        !    ! Max. grid stiffness ratio
-      ENDIF
-      !
-      IF( ll_wd ) THEN              ! wetting and drying domain
-         CALL iom_rstput( 0, 0, inum, 'ht_0'   , ht_0   , ktype = jp_r8 )
-      ENDIF
-      !
-      ! Add some global attributes ( netcdf only )
-      CALL iom_putatt( inum, 'nn_cfg', nn_cfg )
-      CALL iom_putatt( inum, 'cn_cfg', TRIM(cn_cfg) )
-      !
-      !                                ! ============================
-      !                                !        close the files 
-      !                                ! ============================
-      CALL iom_close( inum )
-      !
-   END SUBROUTINE cfg_write
-
-   !!======================================================================
-END MODULE domain
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dommsk.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dommsk.F90	(revision 13603)
+++ 	(revision )
@@ -1,295 +1,0 @@
-MODULE dommsk
-   !!======================================================================
-   !!                       ***  MODULE dommsk   ***
-   !! Ocean initialization : domain land/sea mask 
-   !!======================================================================
-   !! History :  OPA  ! 1987-07  (G. Madec)  Original code
-   !!            6.0  ! 1993-03  (M. Guyon)  symetrical conditions (M. Guyon)
-   !!            7.0  ! 1996-01  (G. Madec)  suppression of common work arrays
-   !!             -   ! 1996-05  (G. Madec)  mask computed from tmask
-   !!            8.0  ! 1997-02  (G. Madec)  mesh information put in domhgr.F
-   !!            8.1  ! 1997-07  (G. Madec)  modification of kbat and fmask
-   !!             -   ! 1998-05  (G. Roullet)  free surface
-   !!            8.2  ! 2000-03  (G. Madec)  no slip accurate
-   !!             -   ! 2001-09  (J.-M. Molines)  Open boundaries
-   !!   NEMO     1.0  ! 2002-08  (G. Madec)  F90: Free form and module
-   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
-   !!            3.2  ! 2009-07  (R. Benshila) Suppression of rigid-lid option
-   !!            3.6  ! 2015-05  (P. Mathiot) ISF: add wmask,wumask and wvmask
-   !!            4.0  ! 2016-06  (G. Madec, S. Flavoni)  domain configuration / user defined interface
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dom_msk       : compute land/ocean mask
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers
-   USE dom_oce        ! ocean space and time domain
-   USE usrdef_fmask   ! user defined fmask
-   USE bdy_oce        ! open boundary
-   !
-   USE in_out_manager ! I/O manager
-   USE iom            ! IOM library
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp        ! Massively Parallel Processing library
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dom_msk    ! routine called by inidom.F90
-
-   !                            !!* Namelist namlbc : lateral boundary condition *
-   REAL(wp)        :: rn_shlat   ! type of lateral boundary condition on velocity
-   LOGICAL, PUBLIC :: ln_vorlat  !  consistency of vorticity boundary condition 
-   !                                            with analytical eqs.
-
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: dommsk.F90 12614 2020-03-26 14:59:52Z gm $ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dom_msk( k_top, k_bot )
-      !!---------------------------------------------------------------------
-      !!                 ***  ROUTINE dom_msk  ***
-      !!
-      !! ** Purpose :   Compute land/ocean mask arrays at tracer points, hori-
-      !!      zontal velocity points (u & v), vorticity points (f) points.
-      !!
-      !! ** Method  :   The ocean/land mask  at t-point is deduced from ko_top 
-      !!      and ko_bot, the indices of the fist and last ocean t-levels which 
-      !!      are either defined in usrdef_zgr or read in zgr_read.
-      !!                The velocity masks (umask, vmask, wmask, wumask, wvmask) 
-      !!      are deduced from a product of the two neighboring tmask.
-      !!                The vorticity mask (fmask) is deduced from tmask taking
-      !!      into account the choice of lateral boundary condition (rn_shlat) :
-      !!         rn_shlat = 0, free slip  (no shear along the coast)
-      !!         rn_shlat = 2, no slip  (specified zero velocity at the coast)
-      !!         0 < rn_shlat < 2, partial slip   | non-linear velocity profile
-      !!         2 < rn_shlat, strong slip        | in the lateral boundary layer
-      !!
-      !!      tmask_i : interior ocean mask at t-point, i.e. excluding duplicated
-      !!                rows/lines due to cyclic or North Fold boundaries as well
-      !!                as MPP halos.
-      !!      tmask_h : halo mask at t-point, i.e. excluding duplicated rows/lines
-      !!                due to cyclic or North Fold boundaries as well as MPP halos.
-      !!
-      !! ** Action :   tmask, umask, vmask, wmask, wumask, wvmask : land/ocean mask 
-      !!                         at t-, u-, v- w, wu-, and wv-points (=0. or 1.)
-      !!               fmask   : land/ocean mask at f-point (=0., or =1., or 
-      !!                         =rn_shlat along lateral boundaries)
-      !!               tmask_i : interior ocean mask 
-      !!               tmask_h : halo mask
-      !!               ssmask , ssumask, ssvmask, ssfmask : 2D ocean mask
-      !!----------------------------------------------------------------------
-      INTEGER, DIMENSION(:,:), INTENT(in) ::   k_top, k_bot   ! first and last ocean level
-      !
-      INTEGER  ::   ji, jj, jk     ! dummy loop indices
-      INTEGER  ::   iif, iil       ! local integers
-      INTEGER  ::   ijf, ijl       !   -       -
-      INTEGER  ::   iktop, ikbot   !   -       -
-      INTEGER  ::   ios, inum
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zwf   ! 2D workspace
-      !!
-      NAMELIST/namlbc/ rn_shlat, ln_vorlat
-      NAMELIST/nambdy/ ln_bdy ,nb_bdy, ln_coords_file, cn_coords_file,         &
-         &             ln_mask_file, cn_mask_file, cn_dyn2d, nn_dyn2d_dta,     &
-         &             cn_dyn3d, nn_dyn3d_dta, cn_tra, nn_tra_dta,             &
-         &             ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp, rn_time_dmp_out, &
-         &             cn_ice, nn_ice_dta,                                     &
-         &             ln_vol, nn_volctl, nn_rimwidth
-      !!---------------------------------------------------------------------
-      !
-      READ  ( numnam_ref, namlbc, IOSTAT = ios, ERR = 901 )
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlbc in reference namelist' )
-      READ  ( numnam_cfg, namlbc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlbc in configuration namelist' )
-      IF(lwm) WRITE ( numond, namlbc )
-      
-      IF(lwp) THEN                  ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'dommsk : ocean mask '
-         WRITE(numout,*) '~~~~~~'
-         WRITE(numout,*) '   Namelist namlbc'
-         WRITE(numout,*) '      lateral momentum boundary cond.    rn_shlat  = ',rn_shlat
-         WRITE(numout,*) '      consistency with analytical form   ln_vorlat = ',ln_vorlat 
-      ENDIF
-      !
-      IF(lwp) WRITE(numout,*)
-      IF     (      rn_shlat == 0.               ) THEN   ;   IF(lwp) WRITE(numout,*) '   ==>>>   ocean lateral  free-slip'
-      ELSEIF (      rn_shlat == 2.               ) THEN   ;   IF(lwp) WRITE(numout,*) '   ==>>>   ocean lateral  no-slip'
-      ELSEIF ( 0. < rn_shlat .AND. rn_shlat < 2. ) THEN   ;   IF(lwp) WRITE(numout,*) '   ==>>>   ocean lateral  partial-slip'
-      ELSEIF ( 2. < rn_shlat                     ) THEN   ;   IF(lwp) WRITE(numout,*) '   ==>>>   ocean lateral  strong-slip'
-      ELSE
-         CALL ctl_stop( 'dom_msk: wrong value for rn_shlat (i.e. a negalive value). We stop.' )
-      ENDIF
-
-      !  Ocean/land mask at t-point  (computed from ko_top and ko_bot)
-      ! ----------------------------
-      !
-      tmask(:,:,:) = 0._wp
-      DO_2D( 1, 1, 1, 1 )
-         iktop = k_top(ji,jj)
-         ikbot = k_bot(ji,jj)
-         IF( iktop /= 0 ) THEN       ! water in the column
-            tmask(ji,jj,iktop:ikbot  ) = 1._wp
-         ENDIF
-      END_2D
-      !
-      ! the following call is mandatory
-      ! it masks boundaries (bathy=0) where needed depending on the configuration (closed, periodic...)  
-      CALL lbc_lnk( 'dommsk', tmask  , 'T', 1._wp )      ! Lateral boundary conditions
-
-     ! Mask corrections for bdy (read in mppini2)
-      READ  ( numnam_ref, nambdy, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy in reference namelist' )
-      READ  ( numnam_cfg, nambdy, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'nambdy in configuration namelist' )
-      ! ------------------------
-      IF ( ln_bdy .AND. ln_mask_file ) THEN
-         CALL iom_open( cn_mask_file, inum )
-         CALL iom_get ( inum, jpdom_data, 'bdy_msk', bdytmask(:,:) )
-         CALL iom_close( inum )
-         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
-            tmask(ji,jj,jk) = tmask(ji,jj,jk) * bdytmask(ji,jj)
-         END_3D
-      ENDIF
-         
-      !  Ocean/land mask at u-, v-, and f-points   (computed from tmask)
-      ! ----------------------------------------
-      ! NB: at this point, fmask is designed for free slip lateral boundary condition
-      DO jk = 1, jpk
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1   ! vector loop
-               umask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji+1,jj  ,jk)
-               vmask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji  ,jj+1,jk)
-            END DO
-            DO ji = 1, jpim1      ! NO vector opt.
-               fmask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji+1,jj  ,jk)   &
-                  &            * tmask(ji,jj+1,jk) * tmask(ji+1,jj+1,jk)
-            END DO
-         END DO
-      END DO
-      CALL lbc_lnk_multi( 'dommsk', umask, 'U', 1., vmask, 'V', 1., fmask, 'F', 1. )      ! Lateral boundary conditions
- 
-      ! Ocean/land mask at wu-, wv- and w points    (computed from tmask)
-      !-----------------------------------------
-      wmask (:,:,1) = tmask(:,:,1)     ! surface
-      wumask(:,:,1) = umask(:,:,1)
-      wvmask(:,:,1) = vmask(:,:,1)
-      DO jk = 2, jpk                   ! interior values
-         wmask (:,:,jk) = tmask(:,:,jk) * tmask(:,:,jk-1)
-         wumask(:,:,jk) = umask(:,:,jk) * umask(:,:,jk-1)   
-         wvmask(:,:,jk) = vmask(:,:,jk) * vmask(:,:,jk-1)
-      END DO
-
-
-      ! Ocean/land column mask at t-, u-, and v-points   (i.e. at least 1 wet cell in the vertical)
-      ! ----------------------------------------------
-      ssmask (:,:) = MAXVAL( tmask(:,:,:), DIM=3 )
-      ssumask(:,:) = MAXVAL( umask(:,:,:), DIM=3 )
-      ssvmask(:,:) = MAXVAL( vmask(:,:,:), DIM=3 )
-!!an 
-      ! ssfmask(:,:) = MAXVAL( fmask(:,:,:), DIM=3 )
-      DO_2D( 1, 0, 1, 0 )
-         ssfmask(ji,jj) = MAX(  tmask(ji,jj+1,1), tmask(ji+1,jj+1,1),  & 
-            &                   tmask(ji,jj  ,1), tmask(ji+1,jj  ,1)   )
-      END_2D
-      CALL lbc_lnk( 'dommsk', ssfmask, 'F', 1._wp )   
-
-!!an
-
-      ! Interior domain mask  (used for global sum)
-      ! --------------------
-      !
-      iif = nn_hls   ;   iil = nlci - nn_hls + 1
-      ijf = nn_hls   ;   ijl = nlcj - nn_hls + 1
-      !
-      !                          ! halo mask : 0 on the halo and 1 elsewhere
-      tmask_h(:,:) = 1._wp                  
-      tmask_h( 1 :iif,   :   ) = 0._wp      ! first columns
-      tmask_h(iil:jpi,   :   ) = 0._wp      ! last  columns (including mpp extra columns)
-      tmask_h(   :   , 1 :ijf) = 0._wp      ! first rows
-      tmask_h(   :   ,ijl:jpj) = 0._wp      ! last  rows (including mpp extra rows)
-      !
-      !                          ! north fold mask
-      tpol(1:jpiglo) = 1._wp 
-      fpol(1:jpiglo) = 1._wp
-      IF( jperio == 3 .OR. jperio == 4 ) THEN      ! T-point pivot
-         tpol(jpiglo/2+1:jpiglo) = 0._wp
-         fpol(     1    :jpiglo) = 0._wp
-         IF( mjg(nlej) == jpjglo ) THEN                  ! only half of the nlcj-1 row for tmask_h
-            DO ji = iif+1, iil-1
-               tmask_h(ji,nlej-1) = tmask_h(ji,nlej-1) * tpol(mig(ji))
-            END DO
-         ENDIF
-      ENDIF
-      !
-      IF( jperio == 5 .OR. jperio == 6 ) THEN      ! F-point pivot
-         tpol(     1    :jpiglo) = 0._wp
-         fpol(jpiglo/2+1:jpiglo) = 0._wp
-      ENDIF
-      !
-      !                          ! interior mask : 2D ocean mask x halo mask 
-      tmask_i(:,:) = ssmask(:,:) * tmask_h(:,:)
-
-
-      ! Lateral boundary conditions on velocity (modify fmask)
-      ! ---------------------------------------  
-      IF( rn_shlat /= 0 ) THEN      ! Not free-slip lateral boundary condition
-         !
-         ALLOCATE( zwf(jpi,jpj) )
-         !
-         DO jk = 1, jpk
-            zwf(:,:) = fmask(:,:,jk)         
-            DO_2D( 0, 0, 0, 0 )
-               IF( fmask(ji,jj,jk) == 0._wp ) THEN
-                  fmask(ji,jj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(ji+1,jj), zwf(ji,jj+1),   &
-                     &                                           zwf(ji-1,jj), zwf(ji,jj-1)  )  )
-               ENDIF
-            END_2D
-            DO jj = 2, jpjm1
-               IF( fmask(1,jj,jk) == 0._wp ) THEN
-                  fmask(1  ,jj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(2,jj), zwf(1,jj+1), zwf(1,jj-1) ) )
-               ENDIF
-               IF( fmask(jpi,jj,jk) == 0._wp ) THEN
-                  fmask(jpi,jj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(jpi,jj+1), zwf(jpim1,jj), zwf(jpi,jj-1) ) )
-               ENDIF
-            END DO         
-            DO ji = 2, jpim1
-               IF( fmask(ji,1,jk) == 0._wp ) THEN
-                  fmask(ji, 1 ,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(ji+1,1), zwf(ji,2), zwf(ji-1,1) ) )
-               ENDIF
-               IF( fmask(ji,jpj,jk) == 0._wp ) THEN
-                  fmask(ji,jpj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(ji+1,jpj), zwf(ji-1,jpj), zwf(ji,jpjm1) ) )
-               ENDIF
-            END DO
-#if defined key_agrif 
-            IF( .NOT. AGRIF_Root() ) THEN 
-               IF ((nbondi ==  1).OR.(nbondi == 2)) fmask(nlci-1 , :     ,jk) = 0.e0      ! east 
-               IF ((nbondi == -1).OR.(nbondi == 2)) fmask(1      , :     ,jk) = 0.e0      ! west 
-               IF ((nbondj ==  1).OR.(nbondj == 2)) fmask(:      ,nlcj-1 ,jk) = 0.e0      ! north 
-               IF ((nbondj == -1).OR.(nbondj == 2)) fmask(:      ,1      ,jk) = 0.e0      ! south 
-            ENDIF 
-#endif 
-         END DO
-         !
-         DEALLOCATE( zwf )
-         !
-         CALL lbc_lnk( 'dommsk', fmask, 'F', 1._wp )      ! Lateral boundary conditions on fmask
-         !
-         ! CAUTION : The fmask may be further modified in dyn_vor_init ( dynvor.F90 ) depending on ln_vorlat
-         !
-      ENDIF
-      
-      ! User defined alteration of fmask (use to reduce ocean transport in specified straits)
-      ! -------------------------------- 
-      !
-      CALL usr_def_fmask( cn_cfg, nn_cfg, fmask )
-      !
-   END SUBROUTINE dom_msk
-   
-   !!======================================================================
-END MODULE dommsk
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/domvvl.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/domvvl.F90	(revision 13603)
+++ 	(revision )
@@ -1,1352 +1,0 @@
-
-MODULE domvvl
-   !!======================================================================
-   !!                       ***  MODULE domvvl   ***
-   !! Ocean : 
-   !!======================================================================
-   !! History :  2.0  !  2006-06  (B. Levier, L. Marie)  original code
-   !!            3.1  !  2009-02  (G. Madec, M. Leclair, R. Benshila)  pure z* coordinate
-   !!            3.3  !  2011-10  (M. Leclair) totally rewrote domvvl: vvl option includes z_star and z_tilde coordinates
-   !!            3.6  !  2014-11  (P. Mathiot) add ice shelf capability
-   !!            4.1  !  2019-08  (A. Coward, D. Storkey) rename dom_vvl_sf_swp -> dom_vvl_sf_update for new timestepping
-   !!----------------------------------------------------------------------
-
-   USE oce             ! ocean dynamics and tracers
-   USE phycst          ! physical constant
-   USE dom_oce         ! ocean space and time domain
-   USE sbc_oce         ! ocean surface boundary condition
-   USE wet_dry         ! wetting and drying
-   USE usrdef_istate   ! user defined initial state (wad only)
-   USE restart         ! ocean restart
-   !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O manager library
-   USE lib_mpp         ! distributed memory computing library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE timing          ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   !                                                      !!* Namelist nam_vvl
-   LOGICAL , PUBLIC :: ln_vvl_zstar           = .FALSE.    ! zstar  vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_ztilde          = .FALSE.    ! ztilde vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_layer           = .FALSE.    ! level  vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_ztilde_as_zstar = .FALSE.    ! ztilde vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_zstar_at_eqtor  = .FALSE.    ! ztilde vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_kepe            = .FALSE.    ! kinetic/potential energy transfer
-   !                                                       ! conservation: not used yet
-   REAL(wp)         :: rn_ahe3                             ! thickness diffusion coefficient
-   REAL(wp)         :: rn_rst_e3t                          ! ztilde to zstar restoration timescale [days]
-   REAL(wp)         :: rn_lf_cutoff                        ! cutoff frequency for low-pass filter  [days]
-   REAL(wp)         :: rn_zdef_max                         ! maximum fractional e3t deformation
-   LOGICAL , PUBLIC :: ln_vvl_dbg = .FALSE.                ! debug control prints
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: un_td, vn_td                ! thickness diffusion transport
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: hdiv_lf                     ! low frequency part of hz divergence
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: tilde_e3t_b, tilde_e3t_n    ! baroclinic scale factors
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: tilde_e3t_a, dtilde_e3t_a   ! baroclinic scale factors
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: frq_rst_e3t                 ! retoring period for scale factors
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: frq_rst_hdv                 ! retoring period for low freq. divergence
-!!stoops
-#if defined key_qco
-   !!----------------------------------------------------------------------
-   !!   'key_qco'      EMPTY MODULE      Quasi-Eulerian vertical coordonate
-   !!----------------------------------------------------------------------
-#else
-   !!----------------------------------------------------------------------
-   !!   Default key      Old management of time varying vertical coordinate
-   !!----------------------------------------------------------------------
-!!st
-   !!----------------------------------------------------------------------
-   !!   dom_vvl_init     : define initial vertical scale factors, depths and column thickness
-   !!   dom_vvl_sf_nxt   : Compute next vertical scale factors
-   !!   dom_vvl_sf_update   : Swap vertical scale factors and update the vertical grid
-   !!   dom_vvl_interpol : Interpolate vertical scale factors from one grid point to another
-   !!   dom_vvl_rst      : read/write restart file
-   !!   dom_vvl_ctl      : Check the vvl options
-   !!----------------------------------------------------------------------
-  
-   PUBLIC  dom_vvl_init       ! called by domain.F90
-   PUBLIC  dom_vvl_zgr        ! called by isfcpl.F90
-   PUBLIC  dom_vvl_sf_nxt     ! called by step.F90
-   PUBLIC  dom_vvl_sf_update  ! called by step.F90
-   PUBLIC  dom_vvl_interpol   ! called by dynnxt.F90
-   PUBLIC  dom_vvl_interpol_st! called by dynnxt.F90
-   PUBLIC  dom_vvl_sf_nxt_st  ! called by step.F90
-   PUBLIC  dom_vvl_sf_update_st
-!!st
-   
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: domvvl.F90 12614 2020-03-26 14:59:52Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION dom_vvl_alloc()
-      !!----------------------------------------------------------------------
-      !!                ***  FUNCTION dom_vvl_alloc  ***
-      !!----------------------------------------------------------------------
-      IF( ln_vvl_zstar )   dom_vvl_alloc = 0
-      IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
-         ALLOCATE( tilde_e3t_b(jpi,jpj,jpk)  , tilde_e3t_n(jpi,jpj,jpk) , tilde_e3t_a(jpi,jpj,jpk) ,   &
-            &      dtilde_e3t_a(jpi,jpj,jpk) , un_td  (jpi,jpj,jpk)     , vn_td  (jpi,jpj,jpk)     ,   &
-            &      STAT = dom_vvl_alloc        )
-         CALL mpp_sum ( 'domvvl', dom_vvl_alloc )
-         IF( dom_vvl_alloc /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl_alloc: failed to allocate arrays' )
-         un_td = 0._wp
-         vn_td = 0._wp
-      ENDIF
-      IF( ln_vvl_ztilde ) THEN
-         ALLOCATE( frq_rst_e3t(jpi,jpj) , frq_rst_hdv(jpi,jpj) , hdiv_lf(jpi,jpj,jpk) , STAT= dom_vvl_alloc )
-         CALL mpp_sum ( 'domvvl', dom_vvl_alloc )
-         IF( dom_vvl_alloc /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl_alloc: failed to allocate arrays' )
-      ENDIF
-      !
-   END FUNCTION dom_vvl_alloc
-
-
-   SUBROUTINE dom_vvl_init( Kbb, Kmm, Kaa )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_init  ***
-      !!                   
-      !! ** Purpose :  Initialization of all scale factors, depths
-      !!               and water column heights
-      !!
-      !! ** Method  :  - use restart file and/or initialize
-      !!               - interpolate scale factors
-      !!
-      !! ** Action  : - e3t_(n/b) and tilde_e3t_(n/b)
-      !!              - Regrid: e3[u/v](:,:,:,Kmm)
-      !!                        e3[u/v](:,:,:,Kmm)       
-      !!                        e3w(:,:,:,Kmm)           
-      !!                        e3[u/v]w_b
-      !!                        e3[u/v]w_n      
-      !!                        gdept(:,:,:,Kmm), gdepw(:,:,:,Kmm) and gde3w
-      !!              - h(t/u/v)_0
-      !!              - frq_rst_e3t and frq_rst_hdv
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa
-      !
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'dom_vvl_init : Variable volume activated'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
-      !
-      CALL dom_vvl_ctl     ! choose vertical coordinate (z_star, z_tilde or layer)
-      !
-      !                    ! Allocate module arrays
-      IF( dom_vvl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl_init : unable to allocate arrays' )
-      !
-      !                    ! Read or initialize e3t_(b/n), tilde_e3t_(b/n) and hdiv_lf
-      CALL dom_vvl_rst( nit000, Kbb, Kmm, 'READ' )
-      e3t(:,:,jpk,Kaa) = e3t_0(:,:,jpk)  ! last level always inside the sea floor set one for all
-      !
-      CALL dom_vvl_zgr_st(Kbb, Kmm, Kaa) ! interpolation scale factor, depth and water column
-      !
-   END SUBROUTINE dom_vvl_init
-   !
-   SUBROUTINE dom_vvl_zgr(Kbb, Kmm, Kaa)
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_init  ***
-      !!                   
-      !! ** Purpose :  Interpolation of all scale factors, 
-      !!               depths and water column heights
-      !!
-      !! ** Method  :  - interpolate scale factors
-      !!
-      !! ** Action  : - e3t_(n/b) and tilde_e3t_(n/b)
-      !!              - Regrid: e3(u/v)_n
-      !!                        e3(u/v)_b       
-      !!                        e3w_n           
-      !!                        e3(u/v)w_b      
-      !!                        e3(u/v)w_n      
-      !!                        gdept_n, gdepw_n and gde3w_n
-      !!              - h(t/u/v)_0
-      !!              - frq_rst_e3t and frq_rst_hdv
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk
-      INTEGER ::   ii0, ii1, ij0, ij1
-      REAL(wp)::   zcoef
-      !!----------------------------------------------------------------------
-      !
-      !                    !== Set of all other vertical scale factors  ==!  (now and before)
-      !                                ! Horizontal interpolation of e3t
-      CALL dom_vvl_interpol( ssh(:,:,Kbb), e3u(:,:,:,Kbb), 'U' )    ! from T to U
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3u(:,:,:,Kmm), 'U' )
-      CALL dom_vvl_interpol( ssh(:,:,Kbb), e3v(:,:,:,Kbb), 'V' )    ! from T to V 
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3v(:,:,:,Kmm), 'V' )
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3f(:,:,:), 'F' )    ! from U to F
-      !                                ! Vertical interpolation of e3t,u,v 
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3w (:,:,:,Kmm), 'W'  )  ! from T to W
-      CALL dom_vvl_interpol( ssh(:,:,Kbb), e3w (:,:,:,Kbb), 'W'  )
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )  ! from U to UW
-      CALL dom_vvl_interpol( ssh(:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )  ! from V to UW
-      CALL dom_vvl_interpol( ssh(:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-
-      ! We need to define e3[tuv]_a for AGRIF initialisation (should not be a problem for the restartability...)
-      e3t(:,:,:,Kaa) = e3t(:,:,:,Kmm)
-      e3u(:,:,:,Kaa) = e3u(:,:,:,Kmm)
-      e3v(:,:,:,Kaa) = e3v(:,:,:,Kmm)
-      !
-      !                    !==  depth of t and w-point  ==!   (set the isf depth as it is in the initial timestep)
-      gdept(:,:,1,Kmm) = 0.5_wp * e3w(:,:,1,Kmm)       ! reference to the ocean surface (used for MLD and light penetration)
-      gdepw(:,:,1,Kmm) = 0.0_wp
-      gde3w(:,:,1) = gdept(:,:,1,Kmm) - ssh(:,:,Kmm)  ! reference to a common level z=0 for hpg
-      gdept(:,:,1,Kbb) = 0.5_wp * e3w(:,:,1,Kbb)
-      gdepw(:,:,1,Kbb) = 0.0_wp
-      DO_3D( 1, 1, 1, 1, 2, jpk )
-         !    zcoef = tmask - wmask    ! 0 everywhere tmask = wmask, ie everywhere expect at jk = mikt
-         !                             ! 1 everywhere from mbkt to mikt + 1 or 1 (if no isf)
-         !                             ! 0.5 where jk = mikt     
-!!gm ???????   BUG ?  gdept(:,:,:,Kmm) as well as gde3w  does not include the thickness of ISF ??
-         zcoef = ( tmask(ji,jj,jk) - wmask(ji,jj,jk) )
-         gdepw(ji,jj,jk,Kmm) = gdepw(ji,jj,jk-1,Kmm) + e3t(ji,jj,jk-1,Kmm)
-         gdept(ji,jj,jk,Kmm) =      zcoef  * ( gdepw(ji,jj,jk  ,Kmm) + 0.5 * e3w(ji,jj,jk,Kmm))  &
-            &                + (1-zcoef) * ( gdept(ji,jj,jk-1,Kmm) +       e3w(ji,jj,jk,Kmm)) 
-         gde3w(ji,jj,jk) = gdept(ji,jj,jk,Kmm) - ssh(ji,jj,Kmm)
-         gdepw(ji,jj,jk,Kbb) = gdepw(ji,jj,jk-1,Kbb) + e3t(ji,jj,jk-1,Kbb)
-         gdept(ji,jj,jk,Kbb) =      zcoef  * ( gdepw(ji,jj,jk  ,Kbb) + 0.5 * e3w(ji,jj,jk,Kbb))  &
-            &                + (1-zcoef) * ( gdept(ji,jj,jk-1,Kbb) +       e3w(ji,jj,jk,Kbb)) 
-      END_3D
-      !
-      !                    !==  thickness of the water column  !!   (ocean portion only)
-      ht(:,:) = e3t(:,:,1,Kmm) * tmask(:,:,1)   !!gm  BUG  :  this should be 1/2 * e3w(k=1) ....
-      hu(:,:,Kbb) = e3u(:,:,1,Kbb) * umask(:,:,1)
-      hu(:,:,Kmm) = e3u(:,:,1,Kmm) * umask(:,:,1)
-      hv(:,:,Kbb) = e3v(:,:,1,Kbb) * vmask(:,:,1)
-      hv(:,:,Kmm) = e3v(:,:,1,Kmm) * vmask(:,:,1)
-      DO jk = 2, jpkm1
-         ht(:,:) = ht(:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-         hu(:,:,Kbb) = hu(:,:,Kbb) + e3u(:,:,jk,Kbb) * umask(:,:,jk)
-         hu(:,:,Kmm) = hu(:,:,Kmm) + e3u(:,:,jk,Kmm) * umask(:,:,jk)
-         hv(:,:,Kbb) = hv(:,:,Kbb) + e3v(:,:,jk,Kbb) * vmask(:,:,jk)
-         hv(:,:,Kmm) = hv(:,:,Kmm) + e3v(:,:,jk,Kmm) * vmask(:,:,jk)
-      END DO
-      !
-      !                    !==  inverse of water column thickness   ==!   (u- and v- points)
-      r1_hu(:,:,Kbb) = ssumask(:,:) / ( hu(:,:,Kbb) + 1._wp - ssumask(:,:) )    ! _i mask due to ISF
-      r1_hu(:,:,Kmm) = ssumask(:,:) / ( hu(:,:,Kmm) + 1._wp - ssumask(:,:) )
-      r1_hv(:,:,Kbb) = ssvmask(:,:) / ( hv(:,:,Kbb) + 1._wp - ssvmask(:,:) )
-      r1_hv(:,:,Kmm) = ssvmask(:,:) / ( hv(:,:,Kmm) + 1._wp - ssvmask(:,:) )
-
-      !                    !==   z_tilde coordinate case  ==!   (Restoring frequencies)
-      IF( ln_vvl_ztilde ) THEN
-!!gm : idea: add here a READ in a file of custumized restoring frequency
-         !                                   ! Values in days provided via the namelist
-         !                                   ! use rsmall to avoid possible division by zero errors with faulty settings
-         frq_rst_e3t(:,:) = 2._wp * rpi / ( MAX( rn_rst_e3t  , rsmall ) * 86400.0_wp )
-         frq_rst_hdv(:,:) = 2._wp * rpi / ( MAX( rn_lf_cutoff, rsmall ) * 86400.0_wp )
-         !
-         IF( ln_vvl_ztilde_as_zstar ) THEN   ! z-star emulation using z-tile
-            frq_rst_e3t(:,:) = 0._wp               !Ignore namelist settings
-            frq_rst_hdv(:,:) = 1._wp / rn_Dt
-         ENDIF
-         IF ( ln_vvl_zstar_at_eqtor ) THEN   ! use z-star in vicinity of the Equator
-            DO_2D( 1, 1, 1, 1 )
-!!gm  case |gphi| >= 6 degrees is useless   initialized just above by default
-               IF( ABS(gphit(ji,jj)) >= 6.) THEN
-                  ! values outside the equatorial band and transition zone (ztilde)
-                  frq_rst_e3t(ji,jj) =  2.0_wp * rpi / ( MAX( rn_rst_e3t  , rsmall ) * 86400.e0_wp )
-                  frq_rst_hdv(ji,jj) =  2.0_wp * rpi / ( MAX( rn_lf_cutoff, rsmall ) * 86400.e0_wp )
-               ELSEIF( ABS(gphit(ji,jj)) <= 2.5) THEN    ! Equator strip ==> z-star
-                  ! values inside the equatorial band (ztilde as zstar)
-                  frq_rst_e3t(ji,jj) =  0.0_wp
-                  frq_rst_hdv(ji,jj) =  1.0_wp / rn_Dt
-               ELSE                                      ! transition band (2.5 to 6 degrees N/S)
-                  !                                      ! (linearly transition from z-tilde to z-star)
-                  frq_rst_e3t(ji,jj) = 0.0_wp + (frq_rst_e3t(ji,jj)-0.0_wp)*0.5_wp   &
-                     &            * (  1.0_wp - COS( rad*(ABS(gphit(ji,jj))-2.5_wp)  &
-                     &                                          * 180._wp / 3.5_wp ) )
-                  frq_rst_hdv(ji,jj) = (1.0_wp / rn_Dt)                                &
-                     &            + (  frq_rst_hdv(ji,jj)-(1.e0_wp / rn_Dt) )*0.5_wp   &
-                     &            * (  1._wp  - COS( rad*(ABS(gphit(ji,jj))-2.5_wp)  &
-                     &                                          * 180._wp / 3.5_wp ) )
-               ENDIF
-            END_2D
-            IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA" ) THEN
-               IF( nn_cfg == 3 ) THEN   ! ORCA2: Suppress ztilde in the Foxe Basin for ORCA2
-                  ii0 = 103   ;   ii1 = 111       
-                  ij0 = 128   ;   ij1 = 135   ;   
-                  frq_rst_e3t( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  0.0_wp
-                  frq_rst_hdv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  1.e0_wp / rn_Dt
-               ENDIF
-            ENDIF
-         ENDIF
-      ENDIF
-      !
-      IF(lwxios) THEN
-! define variables in restart file when writing with XIOS
-         CALL iom_set_rstw_var_active('e3t_b')
-         CALL iom_set_rstw_var_active('e3t_n')
-         !                                           ! ----------------------- !
-         IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN  ! z_tilde and layer cases !
-            !                                        ! ----------------------- !
-            CALL iom_set_rstw_var_active('tilde_e3t_b')
-            CALL iom_set_rstw_var_active('tilde_e3t_n')
-         END IF
-         !                                           ! -------------!    
-         IF( ln_vvl_ztilde ) THEN                    ! z_tilde case !
-            !                                        ! ------------ !
-            CALL iom_set_rstw_var_active('hdiv_lf')
-         ENDIF
-         !
-      ENDIF
-      !
-   END SUBROUTINE dom_vvl_zgr
-
-   
-   SUBROUTINE dom_vvl_zgr_st(Kbb, Kmm, Kaa)
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_init  ***
-      !!                   
-      !! ** Purpose :  Interpolation of all scale factors, 
-      !!               depths and water column heights
-      !!
-      !! ** Method  :  - interpolate scale factors
-      !!
-      !! ** Action  : - e3t_(n/b) and tilde_e3t_(n/b)
-      !!              - Regrid: e3(u/v)_n
-      !!                        e3(u/v)_b       
-      !!                        e3w_n           
-      !!                        e3(u/v)w_b      
-      !!                        e3(u/v)w_n      
-      !!                        gdept_n, gdepw_n and gde3w_n
-      !!              - h(t/u/v)_0
-      !!              - frq_rst_e3t and frq_rst_hdv
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk
-      INTEGER ::   ii0, ii1, ij0, ij1
-      REAL(wp)::   zcoef
-      !!----------------------------------------------------------------------
-      !
-      !                    !== Set of all other vertical scale factors  ==!  (now and before)
-      !                                ! Horizontal interpolation of e3t
-      CALL dom_vvl_interpol_st( r3u(:,:,Kbb), e3u(:,:,:,Kbb), 'U' )    ! from T to U
-      CALL dom_vvl_interpol_st( r3u(:,:,Kmm), e3u(:,:,:,Kmm), 'U' )
-      CALL dom_vvl_interpol_st( r3v(:,:,Kbb), e3v(:,:,:,Kbb), 'V' )    ! from T to V 
-      CALL dom_vvl_interpol_st( r3v(:,:,Kmm), e3v(:,:,:,Kmm), 'V' )
-      CALL dom_vvl_interpol_st( r3f(:,:), e3f(:,:,:), 'F' )    ! from U to F
-      !                                ! Vertical interpolation of e3t,u,v 
-      CALL dom_vvl_interpol_st( r3t(:,:,Kmm), e3w (:,:,:,Kmm), 'W'  )  ! from T to W
-      CALL dom_vvl_interpol_st( r3t(:,:,Kbb), e3w (:,:,:,Kbb), 'W'  )
-      CALL dom_vvl_interpol_st( r3u(:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )  ! from U to UW
-      CALL dom_vvl_interpol_st( r3u(:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-      CALL dom_vvl_interpol_st( r3v(:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )  ! from V to UW
-      CALL dom_vvl_interpol_st( r3v(:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-
-      ! We need to define e3[tuv]_a for AGRIF initialisation (should not be a problem for the restartability...)
-      e3t(:,:,:,Kaa) = e3t(:,:,:,Kmm)
-      e3u(:,:,:,Kaa) = e3u(:,:,:,Kmm)
-      e3v(:,:,:,Kaa) = e3v(:,:,:,Kmm)
-      !
-      DO_3D( 1, 1, 1, 1, 1, jpk )
-         gdepw(ji,jj,jk,Kmm) =  gdepw_0(ji,jj,jk) * (1._wp + r3t(ji,jj,Kmm))
-         gdept(ji,jj,jk,Kmm) =  gdept_0(ji,jj,jk) * (1._wp + r3t(ji,jj,Kmm)) 
-         gde3w(ji,jj,jk    ) =  gdept(ji,jj,jk,Kmm) - ssh(ji,jj,Kmm)
-         gdepw(ji,jj,jk,Kbb) =  gdepw_0(ji,jj,jk) * (1._wp + r3t(ji,jj,Kbb))
-         gdept(ji,jj,jk,Kbb) =  gdept_0(ji,jj,jk) * (1._wp + r3t(ji,jj,Kbb)) 
-      END_3D     
-      !
-      !                    !==  thickness of the water column  !!   (ocean portion only)
-      ht(:,:) = ht_0(:,:) + ssh(:,:,Kmm)
-      hu(:,:,Kbb) = (hu_0(:,:)*(1._wp+r3u(:,:,Kbb)))
-      hv(:,:,Kbb) = (hv_0(:,:)*(1._wp+r3v(:,:,Kbb)))
-      hu(:,:,Kbb) = (hu_0(:,:)*(1._wp+r3u(:,:,Kmm)))
-      hv(:,:,Kbb) = (hv_0(:,:)*(1._wp+r3v(:,:,Kmm)))
-      !                    !==  inverse of water column thickness   ==!   (u- and v- points)
-      r1_hu(:,:,Kbb) = ssumask(:,:) / ( hu(:,:,Kbb) + 1._wp - ssumask(:,:) )    ! _i mask due to ISF
-      r1_hu(:,:,Kmm) = ssumask(:,:) / ( hu(:,:,Kmm) + 1._wp - ssumask(:,:) )
-      r1_hv(:,:,Kbb) = ssvmask(:,:) / ( hv(:,:,Kbb) + 1._wp - ssvmask(:,:) )
-      r1_hv(:,:,Kmm) = ssvmask(:,:) / ( hv(:,:,Kmm) + 1._wp - ssvmask(:,:) ) 
-      !
-      IF(lwxios) THEN
-! define variables in restart file when writing with XIOS
-         CALL iom_set_rstw_var_active('e3t_b')
-         CALL iom_set_rstw_var_active('e3t_n')
-         !
-      ENDIF
-      !
-   END SUBROUTINE dom_vvl_zgr_st
-   
-
-   SUBROUTINE dom_vvl_sf_nxt( kt, Kbb, Kmm, Kaa, kcall ) 
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_sf_nxt  ***
-      !!                   
-      !! ** Purpose :  - compute the after scale factors used in tra_zdf, dynnxt,
-      !!                 tranxt and dynspg routines
-      !!
-      !! ** Method  :  - z_star case:  Repartition of ssh INCREMENT proportionnaly to the level thickness.
-      !!               - z_tilde_case: after scale factor increment = 
-      !!                                    high frequency part of horizontal divergence
-      !!                                  + retsoring towards the background grid
-      !!                                  + thickness difusion
-      !!                               Then repartition of ssh INCREMENT proportionnaly
-      !!                               to the "baroclinic" level thickness.
-      !!
-      !! ** Action  :  - hdiv_lf    : restoring towards full baroclinic divergence in z_tilde case
-      !!               - tilde_e3t_a: after increment of vertical scale factor 
-      !!                              in z_tilde case
-      !!               - e3(t/u/v)_a
-      !!
-      !! Reference  : Leclair, M., and Madec, G. 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in )           ::   kt             ! time step
-      INTEGER, INTENT( in )           ::   Kbb, Kmm, Kaa  ! time step
-      INTEGER, INTENT( in ), OPTIONAL ::   kcall          ! optional argument indicating call sequence
-      !
-      INTEGER                ::   ji, jj, jk            ! dummy loop indices
-      INTEGER , DIMENSION(3) ::   ijk_max, ijk_min      ! temporary integers
-      REAL(wp)               ::   z_tmin, z_tmax        ! local scalars
-      LOGICAL                ::   ll_do_bclinic         ! local logical
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zht, z_scale, zwu, zwv, zhdiv
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze3t
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_linssh )   RETURN      ! No calculation in linear free surface
-      !
-      IF( ln_timing )   CALL timing_start('dom_vvl_sf_nxt')
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dom_vvl_sf_nxt : compute after scale factors'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'
-      ENDIF
-
-      ll_do_bclinic = .TRUE.
-      IF( PRESENT(kcall) ) THEN
-         IF( kcall == 2 .AND. ln_vvl_ztilde )   ll_do_bclinic = .FALSE.
-      ENDIF
-
-      ! ******************************* !
-      ! After acale factors at t-points !
-      ! ******************************* !
-      !                                                ! --------------------------------------------- !
-      !                                                ! z_star coordinate and barotropic z-tilde part !
-      !                                                ! --------------------------------------------- !
-      !
-      z_scale(:,:) = ( ssh(:,:,Kaa) - ssh(:,:,Kbb) ) * ssmask(:,:) / ( ht_0(:,:) + ssh(:,:,Kmm) + 1. - ssmask(:,:) )
-      DO jk = 1, jpkm1
-         ! formally this is the same as e3t(:,:,:,Kaa) = e3t_0*(1+ssha/ht_0)
-         e3t(:,:,jk,Kaa) = e3t(:,:,jk,Kbb) + e3t(:,:,jk,Kmm) * z_scale(:,:) * tmask(:,:,jk)
-      END DO
-      !
-      IF( (ln_vvl_ztilde .OR. ln_vvl_layer) .AND. ll_do_bclinic ) THEN   ! z_tilde or layer coordinate !
-         !                                                               ! ------baroclinic part------ !
-         ! I - initialization
-         ! ==================
-
-         ! 1 - barotropic divergence
-         ! -------------------------
-         zhdiv(:,:) = 0._wp
-         zht(:,:)   = 0._wp
-         DO jk = 1, jpkm1
-            zhdiv(:,:) = zhdiv(:,:) + e3t(:,:,jk,Kmm) * hdiv(:,:,jk)
-            zht  (:,:) = zht  (:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-         END DO
-         zhdiv(:,:) = zhdiv(:,:) / ( zht(:,:) + 1. - tmask_i(:,:) )
-
-         ! 2 - Low frequency baroclinic horizontal divergence  (z-tilde case only)
-         ! --------------------------------------------------
-         IF( ln_vvl_ztilde ) THEN
-            IF( kt > nit000 ) THEN
-               DO jk = 1, jpkm1
-                  hdiv_lf(:,:,jk) = hdiv_lf(:,:,jk) - rn_Dt * frq_rst_hdv(:,:)   &
-                     &          * ( hdiv_lf(:,:,jk) - e3t(:,:,jk,Kmm) * ( hdiv(:,:,jk) - zhdiv(:,:) ) )
-               END DO
-            ENDIF
-         ENDIF
-
-         ! II - after z_tilde increments of vertical scale factors
-         ! =======================================================
-         tilde_e3t_a(:,:,:) = 0._wp  ! tilde_e3t_a used to store tendency terms
-
-         ! 1 - High frequency divergence term
-         ! ----------------------------------
-         IF( ln_vvl_ztilde ) THEN     ! z_tilde case
-            DO jk = 1, jpkm1
-               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - ( e3t(:,:,jk,Kmm) * ( hdiv(:,:,jk) - zhdiv(:,:) ) - hdiv_lf(:,:,jk) )
-            END DO
-         ELSE                         ! layer case
-            DO jk = 1, jpkm1
-               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) -   e3t(:,:,jk,Kmm) * ( hdiv(:,:,jk) - zhdiv(:,:) ) * tmask(:,:,jk)
-            END DO
-         ENDIF
-
-         ! 2 - Restoring term (z-tilde case only)
-         ! ------------------
-         IF( ln_vvl_ztilde ) THEN
-            DO jk = 1, jpk
-               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - frq_rst_e3t(:,:) * tilde_e3t_b(:,:,jk)
-            END DO
-         ENDIF
-
-         ! 3 - Thickness diffusion term
-         ! ----------------------------
-         zwu(:,:) = 0._wp
-         zwv(:,:) = 0._wp
-         DO_3D( 1, 0, 1, 0, 1, jpkm1 )
-            un_td(ji,jj,jk) = rn_ahe3 * umask(ji,jj,jk) * e2_e1u(ji,jj)           &
-               &            * ( tilde_e3t_b(ji,jj,jk) - tilde_e3t_b(ji+1,jj  ,jk) )
-            vn_td(ji,jj,jk) = rn_ahe3 * vmask(ji,jj,jk) * e1_e2v(ji,jj)           & 
-               &            * ( tilde_e3t_b(ji,jj,jk) - tilde_e3t_b(ji  ,jj+1,jk) )
-            zwu(ji,jj) = zwu(ji,jj) + un_td(ji,jj,jk)
-            zwv(ji,jj) = zwv(ji,jj) + vn_td(ji,jj,jk)
-         END_3D
-         DO_2D( 1, 1, 1, 1 )
-            un_td(ji,jj,mbku(ji,jj)) = un_td(ji,jj,mbku(ji,jj)) - zwu(ji,jj)
-            vn_td(ji,jj,mbkv(ji,jj)) = vn_td(ji,jj,mbkv(ji,jj)) - zwv(ji,jj)
-         END_2D
-         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-            tilde_e3t_a(ji,jj,jk) = tilde_e3t_a(ji,jj,jk) + (   un_td(ji-1,jj  ,jk) - un_td(ji,jj,jk)    &
-               &                                          +     vn_td(ji  ,jj-1,jk) - vn_td(ji,jj,jk)    &
-               &                                            ) * r1_e1e2t(ji,jj)
-         END_3D
-         !                       ! d - thickness diffusion transport: boundary conditions
-         !                             (stored for tracer advction and continuity equation)
-         CALL lbc_lnk_multi( 'domvvl', un_td , 'U' , -1._wp, vn_td , 'V' , -1._wp)
-
-         ! 4 - Time stepping of baroclinic scale factors
-         ! ---------------------------------------------
-         CALL lbc_lnk( 'domvvl', tilde_e3t_a(:,:,:), 'T', 1._wp )
-         tilde_e3t_a(:,:,:) = tilde_e3t_b(:,:,:) + rDt * tmask(:,:,:) * tilde_e3t_a(:,:,:)
-
-         ! Maximum deformation control
-         ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-         ze3t(:,:,jpk) = 0._wp
-         DO jk = 1, jpkm1
-            ze3t(:,:,jk) = tilde_e3t_a(:,:,jk) / e3t_0(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:)
-         END DO
-         z_tmax = MAXVAL( ze3t(:,:,:) )
-         CALL mpp_max( 'domvvl', z_tmax )                 ! max over the global domain
-         z_tmin = MINVAL( ze3t(:,:,:) )
-         CALL mpp_min( 'domvvl', z_tmin )                 ! min over the global domain
-         ! - ML - test: for the moment, stop simulation for too large e3_t variations
-         IF( ( z_tmax >  rn_zdef_max ) .OR. ( z_tmin < - rn_zdef_max ) ) THEN
-            IF( lk_mpp ) THEN
-               CALL mpp_maxloc( 'domvvl', ze3t, tmask, z_tmax, ijk_max )
-               CALL mpp_minloc( 'domvvl', ze3t, tmask, z_tmin, ijk_min )
-            ELSE
-               ijk_max = MAXLOC( ze3t(:,:,:) )
-               ijk_max(1) = ijk_max(1) + nimpp - 1
-               ijk_max(2) = ijk_max(2) + njmpp - 1
-               ijk_min = MINLOC( ze3t(:,:,:) )
-               ijk_min(1) = ijk_min(1) + nimpp - 1
-               ijk_min(2) = ijk_min(2) + njmpp - 1
-            ENDIF
-            IF (lwp) THEN
-               WRITE(numout, *) 'MAX( tilde_e3t_a(:,:,:) / e3t_0(:,:,:) ) =', z_tmax
-               WRITE(numout, *) 'at i, j, k=', ijk_max
-               WRITE(numout, *) 'MIN( tilde_e3t_a(:,:,:) / e3t_0(:,:,:) ) =', z_tmin
-               WRITE(numout, *) 'at i, j, k=', ijk_min            
-               CALL ctl_stop( 'STOP', 'MAX( ABS( tilde_e3t_a(:,:,: ) ) / e3t_0(:,:,:) ) too high')
-            ENDIF
-         ENDIF
-         ! - ML - end test
-         ! - ML - Imposing these limits will cause a baroclinicity error which is corrected for below
-         tilde_e3t_a(:,:,:) = MIN( tilde_e3t_a(:,:,:),   rn_zdef_max * e3t_0(:,:,:) )
-         tilde_e3t_a(:,:,:) = MAX( tilde_e3t_a(:,:,:), - rn_zdef_max * e3t_0(:,:,:) )
-
-         !
-         ! "tilda" change in the after scale factor
-         ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-         DO jk = 1, jpkm1
-            dtilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - tilde_e3t_b(:,:,jk)
-         END DO
-         ! III - Barotropic repartition of the sea surface height over the baroclinic profile
-         ! ==================================================================================
-         ! add ( ssh increment + "baroclinicity error" ) proportionly to e3t(n)
-         ! - ML - baroclinicity error should be better treated in the future
-         !        i.e. locally and not spread over the water column.
-         !        (keep in mind that the idea is to reduce Eulerian velocity as much as possible)
-         zht(:,:) = 0.
-         DO jk = 1, jpkm1
-            zht(:,:)  = zht(:,:) + tilde_e3t_a(:,:,jk) * tmask(:,:,jk)
-         END DO
-         z_scale(:,:) =  - zht(:,:) / ( ht_0(:,:) + ssh(:,:,Kmm) + 1. - ssmask(:,:) )
-         DO jk = 1, jpkm1
-            dtilde_e3t_a(:,:,jk) = dtilde_e3t_a(:,:,jk) + e3t(:,:,jk,Kmm) * z_scale(:,:) * tmask(:,:,jk)
-         END DO
-
-      ENDIF
-
-      IF( ln_vvl_ztilde .OR. ln_vvl_layer )  THEN   ! z_tilde or layer coordinate !
-      !                                           ! ---baroclinic part--------- !
-         DO jk = 1, jpkm1
-            e3t(:,:,jk,Kaa) = e3t(:,:,jk,Kaa) + dtilde_e3t_a(:,:,jk) * tmask(:,:,jk)
-         END DO
-      ENDIF
-
-      IF( ln_vvl_dbg .AND. .NOT. ll_do_bclinic ) THEN   ! - ML - test: control prints for debuging
-         !
-         IF( lwp ) WRITE(numout, *) 'kt =', kt
-         IF ( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
-            z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( zht(:,:) ) )
-            CALL mpp_max( 'domvvl', z_tmax )                             ! max over the global domain
-            IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(SUM(tilde_e3t_a))) =', z_tmax
-         END IF
-         !
-         zht(:,:) = 0.0_wp
-         DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-         END DO
-         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + ssh(:,:,Kmm) - zht(:,:) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+sshn-SUM(e3t(:,:,:,Kmm)))) =', z_tmax
-         !
-         zht(:,:) = 0.0_wp
-         DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + e3t(:,:,jk,Kaa) * tmask(:,:,jk)
-         END DO
-         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + ssh(:,:,Kaa) - zht(:,:) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+ssha-SUM(e3t(:,:,:,Kaa)))) =', z_tmax
-         !
-         zht(:,:) = 0.0_wp
-         DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + e3t(:,:,jk,Kbb) * tmask(:,:,jk)
-         END DO
-         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + ssh(:,:,Kbb) - zht(:,:) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+sshb-SUM(e3t(:,:,:,Kbb)))) =', z_tmax
-         !
-         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( ssh(:,:,Kbb) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ssh(:,:,Kbb)))) =', z_tmax
-         !
-         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( ssh(:,:,Kmm) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ssh(:,:,Kmm)))) =', z_tmax
-         !
-         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( ssh(:,:,Kaa) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ssh(:,:,Kaa)))) =', z_tmax
-      END IF
-
-      ! *********************************** !
-      ! After scale factors at u- v- points !
-      ! *********************************** !
-
-      CALL dom_vvl_interpol( ssh(:,:,Kaa), e3u(:,:,:,Kaa), 'U' )
-      CALL dom_vvl_interpol( ssh(:,:,Kaa), e3v(:,:,:,Kaa), 'V' )
-
-      ! *********************************** !
-      ! After depths at u- v points         !
-      ! *********************************** !
-
-      hu(:,:,Kaa) = e3u(:,:,1,Kaa) * umask(:,:,1)
-      hv(:,:,Kaa) = e3v(:,:,1,Kaa) * vmask(:,:,1)
-      DO jk = 2, jpkm1
-         hu(:,:,Kaa) = hu(:,:,Kaa) + e3u(:,:,jk,Kaa) * umask(:,:,jk)
-         hv(:,:,Kaa) = hv(:,:,Kaa) + e3v(:,:,jk,Kaa) * vmask(:,:,jk)
-      END DO
-      !                                        ! Inverse of the local depth
-!!gm BUG ?  don't understand the use of umask_i here .....
-      r1_hu(:,:,Kaa) = ssumask(:,:) / ( hu(:,:,Kaa) + 1._wp - ssumask(:,:) )
-      r1_hv(:,:,Kaa) = ssvmask(:,:) / ( hv(:,:,Kaa) + 1._wp - ssvmask(:,:) )
-      !
-      IF( ln_timing )   CALL timing_stop('dom_vvl_sf_nxt')
-      !
-   END SUBROUTINE dom_vvl_sf_nxt
-
-
-
-   SUBROUTINE dom_vvl_sf_nxt_st( kt, Kbb, Kmm, Kaa, kcall ) 
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_sf_nxt  ***
-      !!                   
-      !! ** Purpose :  - compute the after scale factors used in tra_zdf, dynnxt,
-      !!                 tranxt and dynspg routines
-      !!
-      !! ** Method  :  - z_star case:  Repartition of ssh INCREMENT proportionnaly to the level thickness.
-      !!               - z_tilde_case: after scale factor increment = 
-      !!                                    high frequency part of horizontal divergence
-      !!                                  + retsoring towards the background grid
-      !!                                  + thickness difusion
-      !!                               Then repartition of ssh INCREMENT proportionnaly
-      !!                               to the "baroclinic" level thickness.
-      !!
-      !! ** Action  :  - hdiv_lf    : restoring towards full baroclinic divergence in z_tilde case
-      !!               - tilde_e3t_a: after increment of vertical scale factor 
-      !!                              in z_tilde case
-      !!               - e3(t/u/v)_a
-      !!
-      !! Reference  : Leclair, M., and Madec, G. 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in )           ::   kt             ! time step
-      INTEGER, INTENT( in )           ::   Kbb, Kmm, Kaa  ! time step
-      INTEGER, INTENT( in ), OPTIONAL ::   kcall          ! optional argument indicating call sequence
-      !
-      INTEGER                ::   ji, jj, jk            ! dummy loop indices
-      INTEGER , DIMENSION(3) ::   ijk_max, ijk_min      ! temporary integers
-      REAL(wp)               ::   z_tmin, z_tmax        ! local scalars
-      LOGICAL                ::   ll_do_bclinic         ! local logical
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zht, z_scale, zwu, zwv, zhdiv
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze3t
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_linssh )   RETURN      ! No calculation in linear free surface
-      !
-      IF( ln_timing )   CALL timing_start('dom_vvl_sf_nxt')
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dom_vvl_sf_nxt : compute after scale factors'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'
-      ENDIF
-
-      ll_do_bclinic = .TRUE.
-      IF( PRESENT(kcall) ) THEN
-         IF( kcall == 2 .AND. ln_vvl_ztilde )   ll_do_bclinic = .FALSE.
-      ENDIF
-
-      ! ******************************* !
-      ! After acale factors at t-points !
-      ! ******************************* !
-      !
-      DO jk = 1, jpkm1
-         e3t(:,:,jk,Kaa) = e3t_0(:,:,jk) * ( 1._wp + r3t(:,:,Kaa) )
-         e3u(:,:,jk,Kaa) = e3u_0(:,:,jk) * ( 1._wp + r3u(:,:,Kaa) )
-         e3v(:,:,jk,Kaa) = e3v_0(:,:,jk) * ( 1._wp + r3v(:,:,Kaa) )
-      END DO
-      !
-      ! *********************************** !
-      ! After scale factors at u- v- points !
-      ! *********************************** !
-      
-      !!st CALL dom_vvl_interpol_st( r3u(:,:,Kaa), e3u(:,:,:,Kaa), 'U' )
-      !!st CALL dom_vvl_interpol_st( r3v(:,:,Kaa), e3v(:,:,:,Kaa), 'V' )
-
-      ! *********************************** !
-      ! After depths at u- v points         !
-      ! *********************************** !
-
-      !!st hu(:,:,Kaa) = e3u(:,:,1,Kaa) * umask(:,:,1)
-      !!st hv(:,:,Kaa) = e3v(:,:,1,Kaa) * vmask(:,:,1)
-      !!st DO jk = 2, jpkm1
-      !!st    hu(:,:,Kaa) = hu(:,:,Kaa) + e3u(:,:,jk,Kaa) * umask(:,:,jk)
-      !!st    hv(:,:,Kaa) = hv(:,:,Kaa) + e3v(:,:,jk,Kaa) * vmask(:,:,jk)
-      !!st    
-      !!st END DO
-      hu(:,:,Kaa) = (hu_0(:,:)*(1._wp+r3u(:,:,Kaa)))
-      hv(:,:,Kaa) = (hv_0(:,:)*(1._wp+r3v(:,:,Kaa)))
-      !                                        ! Inverse of the local depth
-!!gm BUG ?  don't understand the use of umask_i here .....
-      r1_hu(:,:,Kaa) = ssumask(:,:) / ( hu(:,:,Kaa) + 1._wp - ssumask(:,:) )
-      r1_hv(:,:,Kaa) = ssvmask(:,:) / ( hv(:,:,Kaa) + 1._wp - ssvmask(:,:) )
-      !
-      IF( ln_timing )   CALL timing_stop('dom_vvl_sf_nxt')
-      !
-   END SUBROUTINE dom_vvl_sf_nxt_st
-   
-
-
-   SUBROUTINE dom_vvl_sf_update( kt, Kbb, Kmm, Kaa )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_sf_update  ***
-      !!                   
-      !! ** Purpose :  for z tilde case: compute time filter and swap of scale factors 
-      !!               compute all depths and related variables for next time step
-      !!               write outputs and restart file
-      !!
-      !! ** Method  :  - swap of e3t with trick for volume/tracer conservation (ONLY FOR Z TILDE CASE)
-      !!               - reconstruct scale factor at other grid points (interpolate)
-      !!               - recompute depths and water height fields
-      !!
-      !! ** Action  :  - tilde_e3t_(b/n) ready for next time step
-      !!               - Recompute:
-      !!                    e3(u/v)_b       
-      !!                    e3w(:,:,:,Kmm)           
-      !!                    e3(u/v)w_b      
-      !!                    e3(u/v)w_n      
-      !!                    gdept(:,:,:,Kmm), gdepw(:,:,:,Kmm)  and gde3w
-      !!                    h(u/v) and h(u/v)r
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2009, Ocean Modelling.
-      !!              Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt              ! time step
-      INTEGER, INTENT( in ) ::   Kbb, Kmm, Kaa   ! time level indices
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zcoef        ! local scalar
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_linssh )   RETURN      ! No calculation in linear free surface
-      !
-      IF( ln_timing )   CALL timing_start('dom_vvl_sf_update')
-      !
-      IF( kt == nit000 )   THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dom_vvl_sf_update : - interpolate scale factors and compute depths for next time step'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
-      ENDIF
-      !
-      ! Time filter and swap of scale factors
-      ! =====================================
-      ! - ML - e3(t/u/v)_b are allready computed in dynnxt.
-      IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
-         IF( l_1st_euler ) THEN
-            tilde_e3t_b(:,:,:) = tilde_e3t_n(:,:,:)
-         ELSE
-            tilde_e3t_b(:,:,:) = tilde_e3t_n(:,:,:) & 
-            &         + rn_atfp * ( tilde_e3t_b(:,:,:) - 2.0_wp * tilde_e3t_n(:,:,:) + tilde_e3t_a(:,:,:) )
-         ENDIF
-         tilde_e3t_n(:,:,:) = tilde_e3t_a(:,:,:)
-      ENDIF
-
-      ! Compute all missing vertical scale factor and depths
-      ! ====================================================
-      ! Horizontal scale factor interpolations
-      ! --------------------------------------
-      ! - ML - e3u(:,:,:,Kbb) and e3v(:,:,:,Kbb) are already computed in dynnxt
-      ! - JC - hu(:,:,:,Kbb), hv(:,:,:,:,Kbb), hur_b, hvr_b also
-      
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3f(:,:,:), 'F'  )
-      
-      ! Vertical scale factor interpolations
-      CALL dom_vvl_interpol( ssh(:,:,Kmm),  e3w(:,:,:,Kmm), 'W'  )
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )
-      CALL dom_vvl_interpol( ssh(:,:,Kbb),  e3w(:,:,:,Kbb), 'W'  )
-      CALL dom_vvl_interpol( ssh(:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-      CALL dom_vvl_interpol( ssh(:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-
-      ! t- and w- points depth (set the isf depth as it is in the initial step)
-      gdept(:,:,1,Kmm) = 0.5_wp * e3w(:,:,1,Kmm)
-      gdepw(:,:,1,Kmm) = 0.0_wp
-      gde3w(:,:,1) = gdept(:,:,1,Kmm) - ssh(:,:,Kmm)
-      DO_3D( 1, 1, 1, 1, 2, jpk )
-        !    zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))   ! 0 everywhere tmask = wmask, ie everywhere expect at jk = mikt
-                                                           ! 1 for jk = mikt
-         zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))
-         gdepw(ji,jj,jk,Kmm) = gdepw(ji,jj,jk-1,Kmm) + e3t(ji,jj,jk-1,Kmm)
-         gdept(ji,jj,jk,Kmm) =    zcoef  * ( gdepw(ji,jj,jk  ,Kmm) + 0.5 * e3w(ji,jj,jk,Kmm) )  &
-             &             + (1-zcoef) * ( gdept(ji,jj,jk-1,Kmm) +       e3w(ji,jj,jk,Kmm) ) 
-         gde3w(ji,jj,jk) = gdept(ji,jj,jk,Kmm) - ssh(ji,jj,Kmm)
-      END_3D
-
-      ! Local depth and Inverse of the local depth of the water
-      ! -------------------------------------------------------
-      !
-      ht(:,:) = e3t(:,:,1,Kmm) * tmask(:,:,1)
-      DO jk = 2, jpkm1
-         ht(:,:) = ht(:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-      END DO
-
-      ! write restart file
-      ! ==================
-      IF( lrst_oce  )   CALL dom_vvl_rst( kt, Kbb, Kmm, 'WRITE' )
-      !
-      IF( ln_timing )   CALL timing_stop('dom_vvl_sf_update')
-      !
-   END SUBROUTINE dom_vvl_sf_update
-   
-
-   SUBROUTINE dom_vvl_sf_update_st( kt, Kbb, Kmm, Kaa )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_sf_update  ***
-      !!                   
-      !! ** Purpose :  for z tilde case: compute time filter and swap of scale factors 
-      !!               compute all depths and related variables for next time step
-      !!               write outputs and restart file
-      !!
-      !! ** Method  :  - swap of e3t with trick for volume/tracer conservation (ONLY FOR Z TILDE CASE)
-      !!               - reconstruct scale factor at other grid points (interpolate)
-      !!               - recompute depths and water height fields
-      !!
-      !! ** Action  :  - tilde_e3t_(b/n) ready for next time step
-      !!               - Recompute:
-      !!                    e3(u/v)_b       
-      !!                    e3w(:,:,:,Kmm)           
-      !!                    e3(u/v)w_b      
-      !!                    e3(u/v)w_n      
-      !!                    gdept(:,:,:,Kmm), gdepw(:,:,:,Kmm)  and gde3w
-      !!                    h(u/v) and h(u/v)r
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2009, Ocean Modelling.
-      !!              Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt              ! time step
-      INTEGER, INTENT( in ) ::   Kbb, Kmm, Kaa   ! time level indices
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zcoef        ! local scalar
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_linssh )   RETURN      ! No calculation in linear free surface
-      !
-      IF( ln_timing )   CALL timing_start('dom_vvl_sf_update')
-      !
-      IF( kt == nit000 )   THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dom_vvl_sf_update : - interpolate scale factors and compute depths for next time step'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
-      ENDIF
-      !
-
-      ! Compute all missing vertical scale factor and depths
-      ! ====================================================
-      ! Horizontal scale factor interpolations
-      ! --------------------------------------
-      ! - ML - e3u(:,:,:,Kbb) and e3v(:,:,:,Kbb) are already computed in dynnxt
-      ! - JC - hu(:,:,:,Kbb), hv(:,:,:,:,Kbb), hur_b, hvr_b also
-      
-      CALL dom_vvl_interpol_st( r3f(:,:), e3f(:,:,:), 'F'  )
-
-      ! Vertical scale factor interpolations
-      CALL dom_vvl_interpol_st( r3t(:,:,Kmm),  e3w(:,:,:,Kmm), 'W'  )
-      CALL dom_vvl_interpol_st( r3u(:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )
-      CALL dom_vvl_interpol_st( r3v(:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )
-      CALL dom_vvl_interpol_st( r3t(:,:,Kbb),  e3w(:,:,:,Kbb), 'W'  )
-      CALL dom_vvl_interpol_st( r3u(:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-      CALL dom_vvl_interpol_st( r3v(:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-
-      ! t- and w- points depth (set the isf depth as it is in the initial step)
-      DO_3D( 1, 1, 1, 1, 1, jpk )
-         gdepw(ji,jj,jk,Kmm) =  gdepw_0(ji,jj,jk) * (1._wp + r3t(ji,jj,Kmm))
-         gdept(ji,jj,jk,Kmm) =  gdept_0(ji,jj,jk) * (1._wp + r3t(ji,jj,Kmm)) 
-         gde3w(ji,jj,jk    ) =  gdept(ji,jj,jk,Kmm) - ssh(ji,jj,Kmm)
-      END_3D
-
-      ! Local depth and Inverse of the local depth of the water
-      ! -------------------------------------------------------
-      !
-      ht(:,:) = ht_0(:,:) + ssh(:,:,Kmm)
-
-      ! write restart file
-      ! ==================
-      IF( lrst_oce  )   CALL dom_vvl_rst( kt, Kbb, Kmm, 'WRITE' )
-      !
-      IF( ln_timing )   CALL timing_stop('dom_vvl_sf_update')
-      !
-   END SUBROUTINE dom_vvl_sf_update_st
-   
-
-    
-   SUBROUTINE dom_vvl_interpol_st( rc3, pe3, cdp )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dom_vvl__interpol  ***
-      !!
-      !! ** Purpose :   interpolate scale factors from one grid point to another
-      !!
-      !! ** Method  :   e3_out = e3_0 + interpolation(e3_in - e3_0)
-      !!                - horizontal interpolation: grid cell surface averaging
-      !!                - vertical interpolation: simple averaging
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:)  , INTENT(in   ) ::   rc3     ! input e3   NOT used here (ssh is used instead)
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pe3     ! scale factor e3 to be updated   [m]
-      CHARACTER(LEN=*)          , INTENT(in   ) ::   cdp     ! grid point of the scale factor ( 'U', 'V', 'W, 'F', 'UW' or 'VW' )
-      !
-      INTEGER ::   ji, jj, jk                 ! dummy loop indices
-      REAL(wp), DIMENSION(jpi,jpj) ::   zc3   ! 2D workspace
-      !!----------------------------------------------------------------------
-      !
-      SELECT CASE ( cdp )     !==  type of interpolation  ==!
-         !
-      CASE( 'U' )                   !* from T- to U-point : hor. surface weighted mean
-         DO jk = 1, jpkm1
-            pe3(:,:,jk) = e3u_0(:,:,jk) * ( 1.0_wp + rc3(:,:) )
-         END DO
-         !
-      CASE( 'V' )                   !* from T- to V-point : hor. surface weighted mean
-         DO jk = 1, jpkm1
-            pe3(:,:,jk) = e3v_0(:,:,jk) * ( 1.0_wp + rc3(:,:) )
-         END DO
-         !
-      CASE( 'F' )                   !* from U-point to F-point : hor. surface weighted mean
-         DO jk = 1, jpkm1                    ! Horizontal interpolation of e3f from ssh
-            e3f(:,:,jk) = e3f_0(:,:,jk) * ( 1._wp + rc3(:,:) )
-         END DO
-         !
-      CASE( 'W' )                   !* from T- to W-point : vertical simple mean
-         DO jk = 1, jpk
-            pe3(:,:,jk) = e3w_0(:,:,jk) * ( 1.0_wp + rc3(:,:) )
-         END DO
-         !
-      CASE( 'UW' )                  !* from U- to UW-point
-         DO jk = 1, jpk
-            pe3(:,:,jk) = e3uw_0(:,:,jk) * ( 1.0_wp + rc3(:,:) )
-         END DO
-      CASE( 'VW' )                  !* from U- to UW-point : vertical simple mean
-         DO jk = 1, jpk
-            pe3(:,:,jk) = e3vw_0(:,:,jk) * ( 1.0_wp + rc3(:,:) )
-         END DO
-         !
-      END SELECT
-      !
-   END SUBROUTINE dom_vvl_interpol_st
-   
-
-   SUBROUTINE dom_vvl_interpol( pssh, pe3, cdp )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dom_vvl__interpol  ***
-      !!
-      !! ** Purpose :   interpolate scale factors from one grid point to another
-      !!
-      !! ** Method  :   e3_out = e3_0 + interpolation(e3_in - e3_0)
-      !!                - horizontal interpolation: grid cell surface averaging
-      !!                - vertical interpolation: simple averaging
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:)  , INTENT(in   ) ::   pssh    ! input e3   NOT used here (ssh is used instead)
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pe3     ! scale factor e3 to be updated   [m]
-      CHARACTER(LEN=*)          , INTENT(in   ) ::   cdp     ! grid point of the scale factor ( 'U', 'V', 'W, 'F', 'UW' or 'VW' )
-      !
-      INTEGER ::   ji, jj, jk                 ! dummy loop indices
-      REAL(wp), DIMENSION(jpi,jpj) ::   zc3   ! 2D workspace
-      !!----------------------------------------------------------------------
-      !
-      SELECT CASE ( cdp )     !==  type of interpolation  ==!
-         !
-      CASE( 'U' )                   !* from T- to U-point : hor. surface weighted mean
-         DO_2D( 0, 0, 0, 0 )
-            zc3(ji,jj) = 0.5_wp * (  e1e2t(ji  ,jj) * pssh(ji  ,jj)  &
-               &                   + e1e2t(ji+1,jj) * pssh(ji+1,jj)  ) * r1_hu_0(ji,jj) * r1_e1e2u(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'domvvl', zc3(:,:), 'U', 1._wp )
-         !
-         DO jk = 1, jpkm1
-            pe3(:,:,jk) = e3u_0(:,:,jk) * ( 1.0_wp + zc3(:,:) )
-         END DO
-         !
-      CASE( 'V' )                   !* from T- to V-point : hor. surface weighted mean
-         DO_2D( 0, 0, 0, 0 )
-            zc3(ji,jj) = 0.5_wp * (  e1e2t(ji,jj  ) * pssh(ji,jj  )  &
-               &                   + e1e2t(ji,jj+1) * pssh(ji,jj+1)  ) * r1_hv_0(ji,jj) * r1_e1e2v(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'domvvl', zc3(:,:), 'V', 1._wp )
-         !
-         DO jk = 1, jpkm1
-            pe3(:,:,jk) = e3v_0(:,:,jk) * ( 1.0_wp + zc3(:,:) )
-         END DO
-         !
-      CASE( 'F' )                   !* from U-point to F-point : hor. surface weighted mean
-         DO_2D( 1, 0, 1, 0 )
-            zc3(ji,jj) = 0.25_wp * (  e1e2t(ji  ,jj  ) * pssh(ji  ,jj  )  &
-               &                    + e1e2t(ji+1,jj  ) * pssh(ji+1,jj  )  &
-               &                    + e1e2t(ji  ,jj+1) * pssh(ji  ,jj+1)  &
-               &                    + e1e2t(ji+1,jj+1) * pssh(ji+1,jj+1)  ) * r1_hf_0(ji,jj) * r1_e1e2f(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'domvvl', zc3(:,:), 'F', 1._wp )
-         !
-         DO jk = 1, jpkm1                    ! Horizontal interpolation of e3f from ssh
-            e3f(:,:,jk)     = e3f_0(:,:,jk) * ( 1._wp + zc3(:,:) )
-         END DO
-         !
-      CASE( 'W' )                   !* from T- to W-point : vertical simple mean
-         zc3(:,:) = pssh(:,:) * r1_ht_0(:,:)
-         !
-         DO jk = 1, jpk
-            pe3(:,:,jk) = e3w_0(:,:,jk) * ( 1.0_wp + zc3(:,:) )
-         END DO
-         !
-      CASE( 'UW' )                  !* from U- to UW-point
-         !
-         DO_2D( 0, 0, 0, 0 )
-            zc3(ji,jj) = 0.5_wp * (  e1e2t(ji  ,jj) * pssh(ji  ,jj)  &
-               &                   + e1e2t(ji+1,jj) * pssh(ji+1,jj)  ) * r1_hu_0(ji,jj) * r1_e1e2u(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'domvvl', zc3(:,:), 'U', 1._wp )
-         !
-         DO jk = 1, jpk
-            pe3(:,:,jk) = e3uw_0(:,:,jk) * ( 1.0_wp + zc3(:,:) )
-         END DO
-      CASE( 'VW' )                  !* from U- to UW-point : vertical simple mean
-         !
-         DO_2D( 0, 0, 0, 0 )
-            zc3(ji,jj) = 0.5_wp * (  e1e2t(ji,jj  ) * pssh(ji,jj  )  &
-               &                   + e1e2t(ji,jj+1) * pssh(ji,jj+1)  ) * r1_hv_0(ji,jj) * r1_e1e2v(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'domvvl', zc3(:,:), 'V', 1._wp )
-          !
-         DO jk = 1, jpk
-            pe3(:,:,jk) = e3vw_0(:,:,jk) * ( 1.0_wp + zc3(:,:) )
-         END DO
-         !
-      END SELECT
-      !
-   END SUBROUTINE dom_vvl_interpol
-   
-
-   SUBROUTINE dom_vvl_rst( kt, Kbb, Kmm, cdrw )
-      !!---------------------------------------------------------------------
-      !!                   ***  ROUTINE dom_vvl_rst  ***
-      !!                     
-      !! ** Purpose :   Read or write VVL file in restart file
-      !!
-      !! ** Method  :   use of IOM library
-      !!                if the restart does not contain vertical scale factors,
-      !!                they are set to the _0 values
-      !!                if the restart does not contain vertical scale factors increments (z_tilde),
-      !!                they are set to 0.
-      !!----------------------------------------------------------------------
-      INTEGER         , INTENT(in) ::   kt        ! ocean time-step
-      INTEGER         , INTENT(in) ::   Kbb, Kmm  ! ocean time level indices
-      CHARACTER(len=*), INTENT(in) ::   cdrw      ! "READ"/"WRITE" flag
-      !
-      INTEGER ::   ji, jj, jk
-      INTEGER ::   id1, id2, id3, id4, id5     ! local integers
-      !!----------------------------------------------------------------------
-      !
-      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
-         !                                   ! ===============
-         IF( ln_rstart ) THEN                   !* Read the restart file
-            CALL rst_read_open                  !  open the restart file if necessary
-            CALL iom_get( numror, jpdom_autoglo, 'sshn'   , ssh(:,:,Kmm), ldxios = lrxios    )
-            !
-            id1 = iom_varid( numror, 'e3t_b', ldstop = .FALSE. )
-            id2 = iom_varid( numror, 'e3t_n', ldstop = .FALSE. )
-            id3 = iom_varid( numror, 'tilde_e3t_b', ldstop = .FALSE. )
-            id4 = iom_varid( numror, 'tilde_e3t_n', ldstop = .FALSE. )
-            id5 = iom_varid( numror, 'hdiv_lf', ldstop = .FALSE. )
-            !
-            !                             ! --------- !
-            !                             ! all cases !
-            !                             ! --------- !
-            !
-            IF( MIN( id1, id2 ) > 0 ) THEN       ! all required arrays exist
-               CALL iom_get( numror, jpdom_autoglo, 'e3t_b', e3t(:,:,:,Kbb), ldxios = lrxios )
-               CALL iom_get( numror, jpdom_autoglo, 'e3t_n', e3t(:,:,:,Kmm), ldxios = lrxios )
-               ! needed to restart if land processor not computed 
-               IF(lwp) write(numout,*) 'dom_vvl_rst : e3t(:,:,:,Kbb) and e3t(:,:,:,Kmm) found in restart files'
-               WHERE ( tmask(:,:,:) == 0.0_wp ) 
-                  e3t(:,:,:,Kmm) = e3t_0(:,:,:)
-                  e3t(:,:,:,Kbb) = e3t_0(:,:,:)
-               END WHERE
-               IF( l_1st_euler ) THEN
-                  e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               ENDIF
-            ELSE IF( id1 > 0 ) THEN
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kmm) not found in restart files'
-               IF(lwp) write(numout,*) 'e3t_n set equal to e3t_b.'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               CALL iom_get( numror, jpdom_autoglo, 'e3t_b', e3t(:,:,:,Kbb), ldxios = lrxios )
-               e3t(:,:,:,Kmm) = e3t(:,:,:,Kbb)
-               l_1st_euler = .true.
-            ELSE IF( id2 > 0 ) THEN
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kbb) not found in restart files'
-               IF(lwp) write(numout,*) 'e3t_b set equal to e3t_n.'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               CALL iom_get( numror, jpdom_autoglo, 'e3t_n', e3t(:,:,:,Kmm), ldxios = lrxios )
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               l_1st_euler = .true.
-            ELSE
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kmm) not found in restart file'
-               IF(lwp) write(numout,*) 'Compute scale factor from sshn'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               DO jk = 1, jpk
-                  e3t(:,:,jk,Kmm) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kmm) ) &
-                      &                          / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk)   &
-                      &          + e3t_0(:,:,jk)                               * (1._wp -tmask(:,:,jk))
-               END DO
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               l_1st_euler = .true.
-            ENDIF
-            !                             ! ----------- !
-            IF( ln_vvl_zstar ) THEN       ! z_star case !
-               !                          ! ----------- !
-               IF( MIN( id3, id4 ) > 0 ) THEN
-                  CALL ctl_stop( 'dom_vvl_rst: z_star cannot restart from a z_tilde or layer run' )
-               ENDIF
-               !                          ! ----------------------- !
-            ELSE                          ! z_tilde and layer cases !
-               !                          ! ----------------------- !
-               IF( MIN( id3, id4 ) > 0 ) THEN  ! all required arrays exist
-                  CALL iom_get( numror, jpdom_autoglo, 'tilde_e3t_b', tilde_e3t_b(:,:,:), ldxios = lrxios )
-                  CALL iom_get( numror, jpdom_autoglo, 'tilde_e3t_n', tilde_e3t_n(:,:,:), ldxios = lrxios )
-               ELSE                            ! one at least array is missing
-                  tilde_e3t_b(:,:,:) = 0.0_wp
-                  tilde_e3t_n(:,:,:) = 0.0_wp
-               ENDIF
-               !                          ! ------------ !
-               IF( ln_vvl_ztilde ) THEN   ! z_tilde case !
-                  !                       ! ------------ !
-                  IF( id5 > 0 ) THEN  ! required array exists
-                     CALL iom_get( numror, jpdom_autoglo, 'hdiv_lf', hdiv_lf(:,:,:), ldxios = lrxios )
-                  ELSE                ! array is missing
-                     hdiv_lf(:,:,:) = 0.0_wp
-                  ENDIF
-               ENDIF
-            ENDIF
-            !
-         ELSE                                   !* Initialize at "rest"
-            !
-
-            IF( ll_wd ) THEN   ! MJB ll_wd edits start here - these are essential 
-               !
-               IF( cn_cfg == 'wad' ) THEN
-                  ! Wetting and drying test case
-                  CALL usr_def_istate( gdept(:,:,:,Kbb), tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )
-!!an                  ts  (:,:,:,:,Kmm) = ts (:,:,:,:,Kbb)       ! set now values from to before ones
-                  ssh (:,:,Kmm)     = ssh(:,:,Kbb)
-                  uu   (:,:,:,Kmm)   = uu  (:,:,:,Kbb)
-                  vv   (:,:,:,Kmm)   = vv  (:,:,:,Kbb)
-               ELSE
-                  ! if not test case
-                  ssh(:,:,Kmm) = -ssh_ref
-                  ssh(:,:,Kbb) = -ssh_ref
-
-                  DO_2D( 1, 1, 1, 1 )
-                     IF( ht_0(ji,jj)-ssh_ref <  rn_wdmin1 ) THEN ! if total depth is less than min depth
-                        ssh(ji,jj,Kbb) = rn_wdmin1 - (ht_0(ji,jj) )
-                        ssh(ji,jj,Kmm) = rn_wdmin1 - (ht_0(ji,jj) )
-                     ENDIF
-                  END_2D
-               ENDIF !If test case else
-
-               ! Adjust vertical metrics for all wad
-               DO jk = 1, jpk
-                  e3t(:,:,jk,Kmm) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kmm)  ) &
-                    &                            / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk)   &
-                    &            + e3t_0(:,:,jk) * ( 1._wp - tmask(:,:,jk) )
-               END DO
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-
-               DO ji = 1, jpi
-                  DO jj = 1, jpj
-                     IF ( ht_0(ji,jj) .LE. 0.0 .AND. NINT( ssmask(ji,jj) ) .EQ. 1) THEN
-                       CALL ctl_stop( 'dom_vvl_rst: ht_0 must be positive at potentially wet points' )
-                     ENDIF
-                  END DO 
-               END DO 
-               !
-            ELSE
-               !
-               ! Just to read set ssh in fact, called latter once vertical grid
-               ! is set up:
-!               CALL usr_def_istate( gdept_0, tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )
-!               !
-!               DO jk=1,jpk
-!                  e3t(:,:,jk,Kbb) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kbb) ) &
-!                     &            / ( ht_0(:,:) + 1._wp -ssmask(:,:) ) * tmask(:,:,jk)
-!               END DO
-!               e3t(:,:,:,Kmm) = e3t(:,:,:,Kbb)
-                ssh(:,:,Kmm)=0._wp
-                ssh(:,:,Kbb)=0._wp
-                e3t(:,:,:,Kmm)=e3t_0(:,:,:)
-                e3t(:,:,:,Kbb)=e3t_0(:,:,:)
-               !
-            END IF           ! end of ll_wd edits
-
-            IF( ln_vvl_ztilde .OR. ln_vvl_layer) THEN
-               tilde_e3t_b(:,:,:) = 0._wp
-               tilde_e3t_n(:,:,:) = 0._wp
-               IF( ln_vvl_ztilde ) hdiv_lf(:,:,:) = 0._wp
-            END IF
-         ENDIF
-         !
-      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
-         !                                   ! ===================
-         IF(lwp) WRITE(numout,*) '---- dom_vvl_rst ----'
-         IF( lwxios ) CALL iom_swap(      cwxios_context          )
-         !                                           ! --------- !
-         !                                           ! all cases !
-         !                                           ! --------- !
-         CALL iom_rstput( kt, nitrst, numrow, 'e3t_b', e3t(:,:,:,Kbb), ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'e3t_n', e3t(:,:,:,Kmm), ldxios = lwxios )
-         !                                           ! ----------------------- !
-         IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN  ! z_tilde and layer cases !
-            !                                        ! ----------------------- !
-            CALL iom_rstput( kt, nitrst, numrow, 'tilde_e3t_b', tilde_e3t_b(:,:,:), ldxios = lwxios)
-            CALL iom_rstput( kt, nitrst, numrow, 'tilde_e3t_n', tilde_e3t_n(:,:,:), ldxios = lwxios)
-         END IF
-         !                                           ! -------------!    
-         IF( ln_vvl_ztilde ) THEN                    ! z_tilde case !
-            !                                        ! ------------ !
-            CALL iom_rstput( kt, nitrst, numrow, 'hdiv_lf', hdiv_lf(:,:,:), ldxios = lwxios)
-         ENDIF
-         !
-         IF( lwxios ) CALL iom_swap(      cxios_context          )
-      ENDIF
-      !
-   END SUBROUTINE dom_vvl_rst
-
-
-   SUBROUTINE dom_vvl_ctl
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dom_vvl_ctl  ***
-      !!                
-      !! ** Purpose :   Control the consistency between namelist options
-      !!                for vertical coordinate
-      !!----------------------------------------------------------------------
-      INTEGER ::   ioptio, ios
-      !!
-      NAMELIST/nam_vvl/ ln_vvl_zstar, ln_vvl_ztilde, ln_vvl_layer, ln_vvl_ztilde_as_zstar, &
-         &              ln_vvl_zstar_at_eqtor      , rn_ahe3     , rn_rst_e3t            , &
-         &              rn_lf_cutoff               , rn_zdef_max , ln_vvl_dbg                ! not yet implemented: ln_vvl_kepe
-      !!---------------------------------------------------------------------- 
-      !
-      READ  ( numnam_ref, nam_vvl, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_vvl in reference namelist' )
-      READ  ( numnam_cfg, nam_vvl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nam_vvl in configuration namelist' )
-      IF(lwm) WRITE ( numond, nam_vvl )
-      !
-      IF(lwp) THEN                    ! Namelist print
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_vvl_ctl : choice/control of the variable vertical coordinate'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist nam_vvl : chose a vertical coordinate'
-         WRITE(numout,*) '      zstar                      ln_vvl_zstar   = ', ln_vvl_zstar
-         WRITE(numout,*) '      ztilde                     ln_vvl_ztilde  = ', ln_vvl_ztilde
-         WRITE(numout,*) '      layer                      ln_vvl_layer   = ', ln_vvl_layer
-         WRITE(numout,*) '      ztilde as zstar   ln_vvl_ztilde_as_zstar  = ', ln_vvl_ztilde_as_zstar
-         WRITE(numout,*) '      ztilde near the equator    ln_vvl_zstar_at_eqtor  = ', ln_vvl_zstar_at_eqtor
-         WRITE(numout,*) '      !'
-         WRITE(numout,*) '      thickness diffusion coefficient                      rn_ahe3      = ', rn_ahe3
-         WRITE(numout,*) '      maximum e3t deformation fractional change            rn_zdef_max  = ', rn_zdef_max
-         IF( ln_vvl_ztilde_as_zstar ) THEN
-            WRITE(numout,*) '      ztilde running in zstar emulation mode (ln_vvl_ztilde_as_zstar=T) '
-            WRITE(numout,*) '         ignoring namelist timescale parameters and using:'
-            WRITE(numout,*) '            hard-wired : z-tilde to zstar restoration timescale (days)'
-            WRITE(numout,*) '                         rn_rst_e3t     = 0.e0'
-            WRITE(numout,*) '            hard-wired : z-tilde cutoff frequency of low-pass filter (days)'
-            WRITE(numout,*) '                         rn_lf_cutoff   = 1.0/rn_Dt'
-         ELSE
-            WRITE(numout,*) '      z-tilde to zstar restoration timescale (days)        rn_rst_e3t   = ', rn_rst_e3t
-            WRITE(numout,*) '      z-tilde cutoff frequency of low-pass filter (days)   rn_lf_cutoff = ', rn_lf_cutoff
-         ENDIF
-         WRITE(numout,*) '         debug prints flag                                 ln_vvl_dbg   = ', ln_vvl_dbg
-      ENDIF
-      !
-      ioptio = 0                      ! Parameter control
-      IF( ln_vvl_ztilde_as_zstar )   ln_vvl_ztilde = .true.
-      IF( ln_vvl_zstar           )   ioptio = ioptio + 1
-      IF( ln_vvl_ztilde          )   ioptio = ioptio + 1
-      IF( ln_vvl_layer           )   ioptio = ioptio + 1
-      !
-      IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE vertical coordinate in namelist nam_vvl' )
-      !
-      IF(lwp) THEN                   ! Print the choice
-         WRITE(numout,*)
-         IF( ln_vvl_zstar           ) WRITE(numout,*) '      ==>>>   zstar vertical coordinate is used'
-         IF( ln_vvl_ztilde          ) WRITE(numout,*) '      ==>>>   ztilde vertical coordinate is used'
-         IF( ln_vvl_layer           ) WRITE(numout,*) '      ==>>>   layer vertical coordinate is used'
-         IF( ln_vvl_ztilde_as_zstar ) WRITE(numout,*) '      ==>>>   to emulate a zstar coordinate'
-      ENDIF
-      !
-#if defined key_agrif
-      IF( (.NOT.Agrif_Root()).AND.(.NOT.ln_vvl_zstar) )   CALL ctl_stop( 'AGRIF is implemented with zstar coordinate only' )
-#endif
-      !
-   END SUBROUTINE dom_vvl_ctl
-
-#endif
-!!stoops
-
-   !!======================================================================
-END MODULE domvvl
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dynadv.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dynadv.F90	(revision 13603)
+++ 	(revision )
@@ -1,153 +1,0 @@
-MODULE dynadv
-   !!==============================================================================
-   !!                       ***  MODULE  dynadv  ***
-   !! Ocean active tracers:  advection scheme control
-   !!==============================================================================
-   !! History :  1.0  !  2006-11  (G. Madec)  Original code
-   !!            3.3  !  2010-10  (C. Ethe, G. Madec)  reorganisation of initialisation phase
-   !!            3.6  !  2015-05  (N. Ducousso, G. Madec)  add Hollingsworth scheme as an option 
-   !!            4.0  !  2017-07  (G. Madec)  add a linear dynamics option
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dyn_adv      : compute the momentum advection trend 
-   !!   dyn_adv_init : control the different options of advection scheme
-   !!----------------------------------------------------------------------
-   USE dom_oce         ! ocean space and time domain
-   USE dynadv_cen2     ! centred flux form advection      (dyn_adv_cen2 routine)
-   USE dynadv_ubs      ! UBS flux form advection          (dyn_adv_ubs  routine)
-   USE dynkeg          ! kinetic energy gradient          (dyn_keg      routine)
-   USE dynzad          ! vertical advection               (dyn_zad      routine)
-   !
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! MPP library
-   USE timing          ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC dyn_adv       ! routine called by step module
-   PUBLIC dyn_adv_init  ! routine called by opa  module
- 
-   !                                   !!* namdyn_adv namelist *
-   LOGICAL, PUBLIC ::   ln_dynadv_OFF   !: linear dynamics (no momentum advection)
-   LOGICAL, PUBLIC ::   ln_dynadv_vec   !: vector form
-   INTEGER, PUBLIC ::      nn_dynkeg       !: scheme of grad(KE): =0 C2 ; =1 Hollingsworth
-   LOGICAL, PUBLIC ::   ln_dynadv_cen2  !: flux form - 2nd order centered scheme flag
-   LOGICAL, PUBLIC ::   ln_dynadv_ubs   !: flux form - 3rd order UBS scheme flag
-   
-   INTEGER, PUBLIC ::   n_dynadv   !: choice of the formulation and scheme for momentum advection
-   !                               !  associated indices:
-   INTEGER, PUBLIC, PARAMETER ::   np_LIN_dyn = 0   ! no advection: linear dynamics
-   INTEGER, PUBLIC, PARAMETER ::   np_VEC_c2  = 1   ! vector form : 2nd order centered scheme
-   INTEGER, PUBLIC, PARAMETER ::   np_FLX_c2  = 2   ! flux   form : 2nd order centered scheme
-   INTEGER, PUBLIC, PARAMETER ::   np_FLX_ubs = 3   ! flux   form : 3rd order Upstream Biased Scheme
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: dynadv.F90 12822 2020-04-28 09:10:38Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dyn_adv( kt, Kbb, Kmm, puu, pvv, Krhs )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dyn_adv  ***
-      !!                
-      !! ** Purpose :   compute the ocean momentum advection trend.
-      !!
-      !! ** Method  : - Update (puu(:,:,:,Krhs),pvv(:,:,:,Krhs)) with the advection term following n_dynadv
-      !!
-      !!      NB: in flux form advection (ln_dynadv_cen2 or ln_dynadv_ubs=T) 
-      !!      a metric term is add to the coriolis term while in vector form 
-      !!      it is the relative vorticity which is added to coriolis term
-      !!      (see dynvor module).
-      !!----------------------------------------------------------------------
-      INTEGER                             , INTENT( in )  ::  kt               ! ocean time-step index
-      INTEGER                             , INTENT( in )  ::  Kbb, Kmm, Krhs   ! ocean time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) ::  puu, pvv         ! ocean velocities and RHS of momentum equation
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_timing )   CALL timing_start( 'dyn_adv' )
-      !
-      SELECT CASE( n_dynadv )    !==  compute advection trend and add it to general trend  ==!
-      CASE( np_VEC_c2  )     
-         CALL dyn_keg     ( kt, nn_dynkeg,      Kmm, puu, pvv, Krhs )    ! vector form : horizontal gradient of kinetic energy
-         CALL dyn_zad     ( kt,                 Kmm, puu, pvv, Krhs )    ! vector form : vertical advection
-      CASE( np_FLX_c2  ) 
-         CALL dyn_adv_cen2( kt,                 Kmm, puu, pvv, Krhs )    ! 2nd order centered scheme
-      CASE( np_FLX_ubs )   
-         CALL dyn_adv_ubs ( kt,            Kbb, Kmm, puu, pvv, Krhs )    ! 3rd order UBS      scheme (UP3)
-      END SELECT
-      !
-      IF( ln_timing )   CALL timing_stop( 'dyn_adv' )
-      !
-   END SUBROUTINE dyn_adv
-
-   
-   SUBROUTINE dyn_adv_init
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dyn_adv_init  ***
-      !!                
-      !! ** Purpose :   Control the consistency between namelist options for 
-      !!              momentum advection formulation & scheme and set n_dynadv
-      !!----------------------------------------------------------------------
-      INTEGER ::   ioptio, ios   ! Local integer
-      !
-      NAMELIST/namdyn_adv/ ln_dynadv_OFF, ln_dynadv_vec, nn_dynkeg, ln_dynadv_cen2, ln_dynadv_ubs
-      !!----------------------------------------------------------------------
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'dyn_adv_init : choice/control of the momentum advection scheme'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-      ENDIF
-      !
-      READ  ( numnam_ref, namdyn_adv, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_adv in reference namelist' )
-      READ  ( numnam_cfg, namdyn_adv, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_adv in configuration namelist' )
-      IF(lwm) WRITE ( numond, namdyn_adv )
-
-      IF(lwp) THEN                    ! Namelist print
-         WRITE(numout,*) '   Namelist namdyn_adv : chose a advection formulation & scheme for momentum'
-         WRITE(numout,*) '      linear dynamics : no momentum advection          ln_dynadv_OFF  = ', ln_dynadv_OFF
-         WRITE(numout,*) '      Vector form: 2nd order centered scheme           ln_dynadv_vec  = ', ln_dynadv_vec
-!!an45
-         WRITE(numout,*) '         with Hollingsworth scheme (=1) or not (=0,2)      nn_dynkeg  = ', nn_dynkeg
-!!an45
-         WRITE(numout,*) '      flux form: 2nd order centred scheme              ln_dynadv_cen2 = ', ln_dynadv_cen2
-         WRITE(numout,*) '                 3rd order UBS scheme                  ln_dynadv_ubs  = ', ln_dynadv_ubs
-      ENDIF
-
-      ioptio = 0                      ! parameter control and set n_dynadv
-      IF( ln_dynadv_OFF  ) THEN   ;   ioptio = ioptio + 1   ;   n_dynadv = np_LIN_dyn   ;   ENDIF
-      IF( ln_dynadv_vec  ) THEN   ;   ioptio = ioptio + 1   ;   n_dynadv = np_VEC_c2    ;   ENDIF
-      IF( ln_dynadv_cen2 ) THEN   ;   ioptio = ioptio + 1   ;   n_dynadv = np_FLX_c2    ;   ENDIF
-      IF( ln_dynadv_ubs  ) THEN   ;   ioptio = ioptio + 1   ;   n_dynadv = np_FLX_ubs   ;   ENDIF
-
-      IF( ioptio /= 1 )   CALL ctl_stop( 'choose ONE and only ONE advection scheme' )
-!!an45
-      IF( nn_dynkeg /= nkeg_C2 .AND. nn_dynkeg /= nkeg_C2_wpo .AND. nn_dynkeg /= nkeg_HW )   & 
-         &   CALL ctl_stop( 'KEG scheme wrong value of nn_dynkeg' )
-!!an45
-
-      IF(lwp) THEN                    ! Print the choice
-         WRITE(numout,*)
-         SELECT CASE( n_dynadv )
-         CASE( np_LIN_dyn )   ;   WRITE(numout,*) '   ==>>>   linear dynamics : no momentum advection used'
-         CASE( np_VEC_c2  )   ;   WRITE(numout,*) '   ==>>>   vector form : keg + zad + vor is used' 
-            IF( nn_dynkeg == nkeg_C2     )   WRITE(numout,*) '              with Centered standard keg scheme'
-!!an45
-            IF( nn_dynkeg == nkeg_C2_wpo )   WRITE(numout,*) '              with Centered standard keg scheme (wet point only)'
-!!an45
-            IF( nn_dynkeg == nkeg_HW     )   WRITE(numout,*) '              with Hollingsworth keg scheme'
-         CASE( np_FLX_c2  )   ;   WRITE(numout,*) '   ==>>>   flux form   : 2nd order scheme is used'
-         CASE( np_FLX_ubs )   ;   WRITE(numout,*) '   ==>>>   flux form   : UBS       scheme is used'
-         END SELECT
-      ENDIF
-      !
-   END SUBROUTINE dyn_adv_init
-
-  !!======================================================================
-END MODULE dynadv
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dynatf.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dynatf.F90	(revision 13603)
+++ 	(revision )
@@ -1,334 +1,0 @@
-MODULE dynatf
-   !!=========================================================================
-   !!                       ***  MODULE  dynatf  ***
-   !! Ocean dynamics: time filtering
-   !!=========================================================================
-   !! History :  OPA  !  1987-02  (P. Andrich, D. L Hostis)  Original code
-   !!                 !  1990-10  (C. Levy, G. Madec)
-   !!            7.0  !  1993-03  (M. Guyon)  symetrical conditions
-   !!            8.0  !  1997-02  (G. Madec & M. Imbard)  opa, release 8.0
-   !!            8.2  !  1997-04  (A. Weaver)  Euler forward step
-   !!             -   !  1997-06  (G. Madec)  lateral boudary cond., lbc routine
-   !!    NEMO    1.0  !  2002-08  (G. Madec)  F90: Free form and module
-   !!             -   !  2002-10  (C. Talandier, A-M. Treguier) Open boundary cond.
-   !!            2.0  !  2005-11  (V. Garnier) Surface pressure gradient organization
-   !!            2.3  !  2007-07  (D. Storkey) Calls to BDY routines. 
-   !!            3.2  !  2009-06  (G. Madec, R.Benshila)  re-introduce the vvl option
-   !!            3.3  !  2010-09  (D. Storkey, E.O'Dea) Bug fix for BDY module
-   !!            3.3  !  2011-03  (P. Oddo) Bug fix for time-splitting+(BDY-OBC) and not VVL
-   !!            3.5  !  2013-07  (J. Chanut) Compliant with time splitting changes
-   !!            3.6  !  2014-04  (G. Madec) add the diagnostic of the time filter trends
-   !!            3.7  !  2015-11  (J. Chanut) Free surface simplification
-   !!            4.1  !  2019-08  (A. Coward, D. Storkey) Rename dynnxt.F90 -> dynatf.F90. Now just does time filtering.
-   !!-------------------------------------------------------------------------
-  
-   !!----------------------------------------------------------------------------------------------
-   !!   dyn_atf       : apply Asselin time filtering to "now" velocities and vertical scale factors
-   !!----------------------------------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers
-   USE dom_oce        ! ocean space and time domain
-   USE sbc_oce        ! Surface boundary condition: ocean fields
-   USE sbcrnf         ! river runoffs
-   USE phycst         ! physical constants
-   USE dynadv         ! dynamics: vector invariant versus flux form
-   USE dynspg_ts      ! surface pressure gradient: split-explicit scheme
-   USE domvvl         ! variable volume
-   USE bdy_oce   , ONLY: ln_bdy
-   USE bdydta         ! ocean open boundary conditions
-   USE bdydyn         ! ocean open boundary conditions
-   USE bdyvol         ! ocean open boundary condition (bdy_vol routines)
-   USE trd_oce        ! trends: ocean variables
-   USE trddyn         ! trend manager: dynamics
-   USE trdken         ! trend manager: kinetic energy
-   USE isf_oce   , ONLY: ln_isf     ! ice shelf
-   USE isfdynatf , ONLY: isf_dynatf ! ice shelf volume filter correction subroutine 
-   !
-   USE in_out_manager ! I/O manager
-   USE iom            ! I/O manager library
-   USE lbclnk         ! lateral boundary condition (or mpp link)
-   USE lib_mpp        ! MPP library
-   USE prtctl         ! Print control
-   USE timing         ! Timing
-#if defined key_agrif
-   USE agrif_oce_interp
-#endif
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC    dyn_atf   ! routine called by step.F90
-!!st22
-#if defined key_qco
-   !!----------------------------------------------------------------------
-   !!   'key_qco'      EMPTY ROUTINE     Quasi-Eulerian vertical coordonate
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dyn_atf ( kt, Kbb, Kmm, Kaa, puu, pvv, pe3t, pe3u, pe3v )
-      INTEGER                             , INTENT(in   ) :: kt               ! ocean time-step index
-      INTEGER                             , INTENT(in   ) :: Kbb, Kmm, Kaa    ! before and after time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) :: puu, pvv         ! velocities to be time filtered
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) :: pe3t, pe3u, pe3v ! scale factors to be time filtered
-
-      WRITE(*,*) 'dyn_atf: You should not have seen this print! error?', kt
-   END SUBROUTINE dyn_atf
-
-#else
-
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: dynatf.F90 12614 2020-03-26 14:59:52Z gm $ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dyn_atf ( kt, Kbb, Kmm, Kaa, puu, pvv, pe3t, pe3u, pe3v )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE dyn_atf  ***
-      !!                   
-      !! ** Purpose :   Finalize after horizontal velocity. Apply the boundary 
-      !!             condition on the after velocity and apply the Asselin time
-      !!             filter to the now fields.
-      !!
-      !! ** Method  : * Ensure after velocities transport matches time splitting
-      !!             estimate (ln_dynspg_ts=T)
-      !!
-      !!              * Apply lateral boundary conditions on after velocity 
-      !!             at the local domain boundaries through lbc_lnk call,
-      !!             at the one-way open boundaries (ln_bdy=T),
-      !!             at the AGRIF zoom   boundaries (lk_agrif=T)
-      !!
-      !!              * Apply the Asselin time filter to the now fields
-      !!             arrays to start the next time step:
-      !!                (puu(Kmm),pvv(Kmm)) = (puu(Kmm),pvv(Kmm)) 
-      !!                                    + rn_atfp [ (puu(Kbb),pvv(Kbb)) + (puu(Kaa),pvv(Kaa)) - 2 (puu(Kmm),pvv(Kmm)) ]
-      !!             Note that with flux form advection and non linear free surface,
-      !!             the time filter is applied on thickness weighted velocity.
-      !!             As a result, dyn_atf MUST be called after tra_atf.
-      !!
-      !! ** Action :   puu(Kmm),pvv(Kmm)   filtered now horizontal velocity 
-      !!----------------------------------------------------------------------
-      INTEGER                             , INTENT(in   ) :: kt               ! ocean time-step index
-      INTEGER                             , INTENT(in   ) :: Kbb, Kmm, Kaa    ! before and after time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) :: puu, pvv         ! velocities to be time filtered
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) :: pe3t, pe3u, pe3v ! scale factors to be time filtered
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zue3a, zue3n, zue3b, zcoef    ! local scalars
-      REAL(wp) ::   zve3a, zve3n, zve3b, z1_2dt   !   -      -
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:)   ::   zue, zve, zwfld
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ze3t_f, ze3u_f, ze3v_f, zua, zva 
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_timing    )   CALL timing_start('dyn_atf')
-      IF( ln_dynspg_ts )   ALLOCATE( zue(jpi,jpj)     , zve(jpi,jpj)     )
-      IF( l_trddyn     )   ALLOCATE( zua(jpi,jpj,jpk) , zva(jpi,jpj,jpk) )
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn_atf : Asselin time filtering'
-         IF(lwp) WRITE(numout,*) '~~~~~~~'
-      ENDIF
-
-      IF ( ln_dynspg_ts ) THEN
-         ! Ensure below that barotropic velocities match time splitting estimate
-         ! Compute actual transport and replace it with ts estimate at "after" time step
-         zue(:,:) = pe3u(:,:,1,Kaa) * puu(:,:,1,Kaa) * umask(:,:,1)
-         zve(:,:) = pe3v(:,:,1,Kaa) * pvv(:,:,1,Kaa) * vmask(:,:,1)
-         DO jk = 2, jpkm1
-            zue(:,:) = zue(:,:) + pe3u(:,:,jk,Kaa) * puu(:,:,jk,Kaa) * umask(:,:,jk)
-            zve(:,:) = zve(:,:) + pe3v(:,:,jk,Kaa) * pvv(:,:,jk,Kaa) * vmask(:,:,jk)
-         END DO
-         DO jk = 1, jpkm1
-            puu(:,:,jk,Kaa) = ( puu(:,:,jk,Kaa) - zue(:,:) * r1_hu(:,:,Kaa) + uu_b(:,:,Kaa) ) * umask(:,:,jk)
-            pvv(:,:,jk,Kaa) = ( pvv(:,:,jk,Kaa) - zve(:,:) * r1_hv(:,:,Kaa) + vv_b(:,:,Kaa) ) * vmask(:,:,jk)
-         END DO
-         !
-         IF( .NOT.ln_bt_fw ) THEN
-            ! Remove advective velocity from "now velocities" 
-            ! prior to asselin filtering     
-            ! In the forward case, this is done below after asselin filtering   
-            ! so that asselin contribution is removed at the same time 
-            DO jk = 1, jpkm1
-               puu(:,:,jk,Kmm) = ( puu(:,:,jk,Kmm) - un_adv(:,:)*r1_hu(:,:,Kmm) + uu_b(:,:,Kmm) )*umask(:,:,jk)
-               pvv(:,:,jk,Kmm) = ( pvv(:,:,jk,Kmm) - vn_adv(:,:)*r1_hv(:,:,Kmm) + vv_b(:,:,Kmm) )*vmask(:,:,jk)
-            END DO  
-         ENDIF
-      ENDIF
-
-      ! Update after velocity on domain lateral boundaries
-      ! --------------------------------------------------      
-# if defined key_agrif
-      CALL Agrif_dyn( kt )             !* AGRIF zoom boundaries
-# endif
-      !
-      CALL lbc_lnk_multi( 'dynatf', puu(:,:,:,Kaa), 'U', -1., pvv(:,:,:,Kaa), 'V', -1. )     !* local domain boundaries
-      !
-      !                                !* BDY open boundaries
-      IF( ln_bdy .AND. ln_dynspg_exp )   CALL bdy_dyn( kt, Kbb, puu, pvv, Kaa )
-      IF( ln_bdy .AND. ln_dynspg_ts  )   CALL bdy_dyn( kt, Kbb, puu, pvv, Kaa, dyn3d_only=.true. )
-
-!!$   Do we need a call to bdy_vol here??
-      !
-      IF( l_trddyn ) THEN             ! prepare the atf trend computation + some diagnostics
-         !
-         !                                  ! Kinetic energy and Conversion
-         IF( ln_KE_trd  )   CALL trd_dyn( puu(:,:,:,Kaa), pvv(:,:,:,Kaa), jpdyn_ken, kt, Kmm )
-         !
-         IF( ln_dyn_trd ) THEN              ! 3D output: total momentum trends
-            zua(:,:,:) = ( puu(:,:,:,Kaa) - puu(:,:,:,Kbb) ) * r1_Dt
-            zva(:,:,:) = ( pvv(:,:,:,Kaa) - pvv(:,:,:,Kbb) ) * r1_Dt
-            CALL iom_put( "utrd_tot", zua )        ! total momentum trends, except the asselin time filter
-            CALL iom_put( "vtrd_tot", zva )
-         ENDIF
-         !
-         zua(:,:,:) = puu(:,:,:,Kmm)             ! save the now velocity before the asselin filter
-         zva(:,:,:) = pvv(:,:,:,Kmm)             ! (caution: there will be a shift by 1 timestep in the
-         !                                  !  computation of the asselin filter trends)
-      ENDIF
-
-      ! Time filter and swap of dynamics arrays
-      ! ------------------------------------------
-         
-      IF( .NOT. l_1st_euler ) THEN    !* Leap-Frog : Asselin time filter 
-         !                                ! =============!
-         IF( ln_linssh ) THEN             ! Fixed volume !
-            !                             ! =============!
-            DO_3D( 1, 1, 1, 1, 1, jpkm1 )
-               puu(ji,jj,jk,Kmm) = puu(ji,jj,jk,Kmm) + rn_atfp * ( puu(ji,jj,jk,Kbb) - 2._wp * puu(ji,jj,jk,Kmm) + puu(ji,jj,jk,Kaa) )
-               pvv(ji,jj,jk,Kmm) = pvv(ji,jj,jk,Kmm) + rn_atfp * ( pvv(ji,jj,jk,Kbb) - 2._wp * pvv(ji,jj,jk,Kmm) + pvv(ji,jj,jk,Kaa) )
-            END_3D
-            !                             ! ================!
-         ELSE                             ! Variable volume !
-            !                             ! ================!
-            ! Time-filtered scale factor at t-points
-            ! ----------------------------------------------------
-            ALLOCATE( ze3t_f(jpi,jpj,jpk), zwfld(jpi,jpj) )
-            DO jk = 1, jpkm1
-               ze3t_f(:,:,jk) = pe3t(:,:,jk,Kmm) + rn_atfp * ( pe3t(:,:,jk,Kbb) - 2._wp * pe3t(:,:,jk,Kmm) + pe3t(:,:,jk,Kaa) )
-            END DO
-            ! Add volume filter correction: compatibility with tracer advection scheme
-            ! => time filter + conservation correction
-            zcoef = rn_atfp * rn_Dt * r1_rho0
-            zwfld(:,:) = emp_b(:,:) - emp(:,:)
-            IF ( ln_rnf ) zwfld(:,:) =  zwfld(:,:) - ( rnf_b(:,:) - rnf(:,:) )
-            DO jk = 1, jpkm1
-               ze3t_f(:,:,jk) = ze3t_f(:,:,jk) - zcoef * zwfld(:,:) * tmask(:,:,jk) &
-                              &                        * pe3t(:,:,jk,Kmm) / ( ht(:,:) + 1._wp - ssmask(:,:) ) 
-            END DO
-            !
-            ! ice shelf melting (deal separately as it can be in depth)
-            ! PM: we could probably define a generic subroutine to do the in depth correction
-            !     to manage rnf, isf and possibly in the futur icb, tide water glacier (...)
-            !     ...(kt, coef, ktop, kbot, hz, fwf_b, fwf)
-            IF ( ln_isf ) CALL isf_dynatf( kt, Kmm, ze3t_f, rn_atfp * rn_Dt )
-            !
-            pe3t(:,:,1:jpkm1,Kmm) = ze3t_f(:,:,1:jpkm1)        ! filtered scale factor at T-points
-            !
-            IF( ln_dynadv_vec ) THEN      ! Asselin filter applied on velocity
-               ! Before filtered scale factor at (u/v)-points
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), pe3u(:,:,:,Kmm), 'U' )
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), pe3v(:,:,:,Kmm), 'V' )
-               DO_3D( 1, 1, 1, 1, 1, jpkm1 )
-                  puu(ji,jj,jk,Kmm) = puu(ji,jj,jk,Kmm) + rn_atfp * ( puu(ji,jj,jk,Kbb) - 2._wp * puu(ji,jj,jk,Kmm) + puu(ji,jj,jk,Kaa) )
-                  pvv(ji,jj,jk,Kmm) = pvv(ji,jj,jk,Kmm) + rn_atfp * ( pvv(ji,jj,jk,Kbb) - 2._wp * pvv(ji,jj,jk,Kmm) + pvv(ji,jj,jk,Kaa) )
-               END_3D
-               !
-            ELSE                          ! Asselin filter applied on thickness weighted velocity
-               !
-               ALLOCATE( ze3u_f(jpi,jpj,jpk) , ze3v_f(jpi,jpj,jpk) )
-               ! Now filtered scale factor at (u/v)-points stored in ze3u_f, ze3v_f
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), ze3u_f, 'U' )
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), ze3v_f, 'V' )
-               DO_3D( 1, 1, 1, 1, 1, jpkm1 )
-                  zue3a = pe3u(ji,jj,jk,Kaa) * puu(ji,jj,jk,Kaa)
-                  zve3a = pe3v(ji,jj,jk,Kaa) * pvv(ji,jj,jk,Kaa)
-                  zue3n = pe3u(ji,jj,jk,Kmm) * puu(ji,jj,jk,Kmm)
-                  zve3n = pe3v(ji,jj,jk,Kmm) * pvv(ji,jj,jk,Kmm)
-                  zue3b = pe3u(ji,jj,jk,Kbb) * puu(ji,jj,jk,Kbb)
-                  zve3b = pe3v(ji,jj,jk,Kbb) * pvv(ji,jj,jk,Kbb)
-                  !
-                  puu(ji,jj,jk,Kmm) = ( zue3n + rn_atfp * ( zue3b - 2._wp * zue3n  + zue3a ) ) / ze3u_f(ji,jj,jk)
-                  pvv(ji,jj,jk,Kmm) = ( zve3n + rn_atfp * ( zve3b - 2._wp * zve3n  + zve3a ) ) / ze3v_f(ji,jj,jk)
-               END_3D
-               pe3u(:,:,1:jpkm1,Kmm) = ze3u_f(:,:,1:jpkm1)  
-               pe3v(:,:,1:jpkm1,Kmm) = ze3v_f(:,:,1:jpkm1)
-               !
-               DEALLOCATE( ze3u_f , ze3v_f )
-            ENDIF
-            !
-            DEALLOCATE( ze3t_f, zwfld )
-         ENDIF
-         !
-         IF( ln_dynspg_ts .AND. ln_bt_fw ) THEN
-            ! Revert filtered "now" velocities to time split estimate
-            ! Doing it here also means that asselin filter contribution is removed  
-            zue(:,:) = pe3u(:,:,1,Kmm) * puu(:,:,1,Kmm) * umask(:,:,1)
-            zve(:,:) = pe3v(:,:,1,Kmm) * pvv(:,:,1,Kmm) * vmask(:,:,1)    
-            DO jk = 2, jpkm1
-               zue(:,:) = zue(:,:) + pe3u(:,:,jk,Kmm) * puu(:,:,jk,Kmm) * umask(:,:,jk)
-               zve(:,:) = zve(:,:) + pe3v(:,:,jk,Kmm) * pvv(:,:,jk,Kmm) * vmask(:,:,jk)    
-            END DO
-            DO jk = 1, jpkm1
-               puu(:,:,jk,Kmm) = puu(:,:,jk,Kmm) - (zue(:,:) * r1_hu(:,:,Kmm) - uu_b(:,:,Kmm)) * umask(:,:,jk)
-               pvv(:,:,jk,Kmm) = pvv(:,:,jk,Kmm) - (zve(:,:) * r1_hv(:,:,Kmm) - vv_b(:,:,Kmm)) * vmask(:,:,jk)
-            END DO
-         ENDIF
-         !
-      ENDIF ! .NOT. l_1st_euler
-      !
-      ! Set "now" and "before" barotropic velocities for next time step:
-      ! JC: Would be more clever to swap variables than to make a full vertical
-      ! integration
-      !
-      IF(.NOT.ln_linssh ) THEN
-         hu(:,:,Kmm) = pe3u(:,:,1,Kmm ) * umask(:,:,1)
-         hv(:,:,Kmm) = pe3v(:,:,1,Kmm ) * vmask(:,:,1)
-         DO jk = 2, jpkm1
-            hu(:,:,Kmm) = hu(:,:,Kmm) + pe3u(:,:,jk,Kmm ) * umask(:,:,jk)
-            hv(:,:,Kmm) = hv(:,:,Kmm) + pe3v(:,:,jk,Kmm ) * vmask(:,:,jk)
-         END DO
-         r1_hu(:,:,Kmm) = ssumask(:,:) / ( hu(:,:,Kmm) + 1._wp - ssumask(:,:) )
-         r1_hv(:,:,Kmm) = ssvmask(:,:) / ( hv(:,:,Kmm) + 1._wp - ssvmask(:,:) )
-      ENDIF
-      !
-      uu_b(:,:,Kaa) = pe3u(:,:,1,Kaa) * puu(:,:,1,Kaa) * umask(:,:,1)
-      uu_b(:,:,Kmm) = pe3u(:,:,1,Kmm) * puu(:,:,1,Kmm) * umask(:,:,1)
-      vv_b(:,:,Kaa) = pe3v(:,:,1,Kaa) * pvv(:,:,1,Kaa) * vmask(:,:,1)
-      vv_b(:,:,Kmm) = pe3v(:,:,1,Kmm) * pvv(:,:,1,Kmm) * vmask(:,:,1)
-      DO jk = 2, jpkm1
-         uu_b(:,:,Kaa) = uu_b(:,:,Kaa) + pe3u(:,:,jk,Kaa) * puu(:,:,jk,Kaa) * umask(:,:,jk)
-         uu_b(:,:,Kmm) = uu_b(:,:,Kmm) + pe3u(:,:,jk,Kmm) * puu(:,:,jk,Kmm) * umask(:,:,jk)
-         vv_b(:,:,Kaa) = vv_b(:,:,Kaa) + pe3v(:,:,jk,Kaa) * pvv(:,:,jk,Kaa) * vmask(:,:,jk)
-         vv_b(:,:,Kmm) = vv_b(:,:,Kmm) + pe3v(:,:,jk,Kmm) * pvv(:,:,jk,Kmm) * vmask(:,:,jk)
-      END DO
-      uu_b(:,:,Kaa) = uu_b(:,:,Kaa) * r1_hu(:,:,Kaa)
-      vv_b(:,:,Kaa) = vv_b(:,:,Kaa) * r1_hv(:,:,Kaa)
-      uu_b(:,:,Kmm) = uu_b(:,:,Kmm) * r1_hu(:,:,Kmm)
-      vv_b(:,:,Kmm) = vv_b(:,:,Kmm) * r1_hv(:,:,Kmm)
-      !
-      IF( .NOT.ln_dynspg_ts ) THEN        ! output the barotropic currents
-         CALL iom_put(  "ubar", uu_b(:,:,Kmm) )
-         CALL iom_put(  "vbar", vv_b(:,:,Kmm) )
-      ENDIF
-      IF( l_trddyn ) THEN                ! 3D output: asselin filter trends on momentum
-         zua(:,:,:) = ( puu(:,:,:,Kmm) - zua(:,:,:) ) * z1_2dt
-         zva(:,:,:) = ( pvv(:,:,:,Kmm) - zva(:,:,:) ) * z1_2dt
-         CALL trd_dyn( zua, zva, jpdyn_atf, kt, Kmm )
-      ENDIF
-      !
-      IF(sn_cfctl%l_prtctl)   CALL prt_ctl( tab3d_1=puu(:,:,:,Kaa), clinfo1=' nxt  - puu(:,:,:,Kaa): ', mask1=umask,   &
-         &                                  tab3d_2=pvv(:,:,:,Kaa), clinfo2=' pvv(:,:,:,Kaa): '       , mask2=vmask )
-      ! 
-      IF( ln_dynspg_ts )   DEALLOCATE( zue, zve )
-      IF( l_trddyn     )   DEALLOCATE( zua, zva )
-      IF( ln_timing    )   CALL timing_stop('dyn_atf')
-      !
-   END SUBROUTINE dyn_atf
-
-#endif
-!!st22
-   !!=========================================================================
-END MODULE dynatf
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dynkeg.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dynkeg.F90	(revision 13603)
+++ 	(revision )
@@ -1,159 +1,0 @@
-MODULE dynkeg
-   !!======================================================================
-   !!                       ***  MODULE  dynkeg  ***
-   !! Ocean dynamics:  kinetic energy gradient trend
-   !!======================================================================
-   !! History :  1.0  !  1987-09  (P. Andrich, M.-A. Foujols)  Original code
-   !!            7.0  !  1997-05  (G. Madec)  Split dynber into dynkeg and dynhpg
-   !!  NEMO      1.0  !  2002-07  (G. Madec)  F90: Free form and module
-   !!            3.6  !  2015-05  (N. Ducousso, G. Madec)  add Hollingsworth scheme as an option 
-   !!----------------------------------------------------------------------
-   
-   !!----------------------------------------------------------------------
-   !!   dyn_keg      : update the momentum trend with the horizontal tke
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE trd_oce         ! trends: ocean variables
-   USE trddyn          ! trend manager: dynamics
-   !
-   USE in_out_manager  ! I/O manager
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp         ! MPP library
-   USE prtctl          ! Print control
-   USE timing          ! Timing
-   USE bdy_oce         ! ocean open boundary conditions
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dyn_keg    ! routine called by step module
-   
-   INTEGER, PARAMETER, PUBLIC  ::   nkeg_C2     = 0   !: 2nd order centered scheme (standard scheme)
-!!an45
-   INTEGER, PARAMETER, PUBLIC  ::   nkeg_C2_wpo = 2   !: 2nd order centered scheme (wet point only : coastline at 45 degrees)
-   INTEGER, PARAMETER, PUBLIC  ::   nkeg_HW     = 1   !: Hollingsworth et al., QJRMS, 1983
-   !
-   REAL(wp) ::   r1_48 = 1._wp / 48._wp   !: =1/(4*2*6)
-   
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: dynkeg.F90 12377 2020-02-12 14:39:06Z acc $ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dyn_keg( kt, kscheme, Kmm, puu, pvv, Krhs )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE dyn_keg  ***
-      !!
-      !! ** Purpose :   Compute the now momentum trend due to the horizontal
-      !!      gradient of the horizontal kinetic energy and add it to the 
-      !!      general momentum trend.
-      !!
-      !! ** Method  : * kscheme = nkeg_C2 : 2nd order centered scheme that 
-      !!      conserve kinetic energy. Compute the now horizontal kinetic energy 
-      !!         zhke = 1/2 [ mi-1( un^2 ) + mj-1( vn^2 ) ]
-      !!              * kscheme = nkeg_HW : Hollingsworth correction following
-      !!      Arakawa (2001). The now horizontal kinetic energy is given by:
-      !!         zhke = 1/6 [ mi-1(  2 * un^2 + ((u(j+1)+u(j-1))/2)^2  )
-      !!                    + mj-1(  2 * vn^2 + ((v(i+1)+v(i-1))/2)^2  ) ]
-      !!      
-      !!      Take its horizontal gradient and add it to the general momentum
-      !!      trend.
-      !!         u(rhs) = u(rhs) - 1/e1u di[ zhke ]
-      !!         v(rhs) = v(rhs) - 1/e2v dj[ zhke ]
-      !!
-      !! ** Action : - Update the (puu(:,:,:,Krhs), pvv(:,:,:,Krhs)) with the hor. ke gradient trend
-      !!             - send this trends to trd_dyn (l_trddyn=T) for post-processing
-      !!
-      !! ** References : Arakawa, A., International Geophysics 2001.
-      !!                 Hollingsworth et al., Quart. J. Roy. Meteor. Soc., 1983.
-      !!----------------------------------------------------------------------
-      INTEGER                             , INTENT( in )  ::  kt               ! ocean time-step index
-      INTEGER                             , INTENT( in )  ::  kscheme          ! =0/1/2   type of KEG scheme 
-      INTEGER                             , INTENT( in )  ::  Kmm, Krhs        ! ocean time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) ::  puu, pvv         ! ocean velocities and RHS of momentum equation
-      !
-      INTEGER  ::   ji, jj, jk             ! dummy loop indices
-      REAL(wp) ::   zu, zv                   ! local scalars
-      REAL(wp), DIMENSION(jpi,jpj,jpk)        ::   zhke
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrdu, ztrdv 
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_timing )   CALL timing_start('dyn_keg')
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn_keg : kinetic energy gradient trend, scheme number=', kscheme
-         IF(lwp) WRITE(numout,*) '~~~~~~~'
-      ENDIF
-
-      IF( l_trddyn ) THEN           ! Save the input trends
-         ALLOCATE( ztrdu(jpi,jpj,jpk) , ztrdv(jpi,jpj,jpk) )
-         ztrdu(:,:,:) = puu(:,:,:,Krhs) 
-         ztrdv(:,:,:) = pvv(:,:,:,Krhs) 
-      ENDIF
-      
-      zhke(:,:,jpk) = 0._wp
-
-      SELECT CASE ( kscheme )             !== Horizontal kinetic energy at T-point  ==!
-!!an45 to be ADDED : que cas C2 - "wet points only" il suffit de x2 le terme quadratic a la coast (nn_dynkeg_adv = 2)
-      CASE ( nkeg_C2_wpo )                          !--  Standard scheme  --!
-         DO_3D( 0, 1, 0, 1, 1, jpkm1 )
-            zu =  (   puu(ji-1,jj  ,jk,Kmm) * puu(ji-1,jj  ,jk,Kmm)   &
-               &    + puu(ji  ,jj  ,jk,Kmm) * puu(ji  ,jj  ,jk,Kmm)   ) * ( 2._wp - umask(ji-1,jj,jk) * umask(ji,jj,jk) )
-            zv =  (   pvv(ji  ,jj-1,jk,Kmm) * pvv(ji  ,jj-1,jk,Kmm)   &
-               &    + pvv(ji  ,jj  ,jk,Kmm) * pvv(ji  ,jj  ,jk,Kmm)   ) * ( 2._wp - vmask(ji,jj-1,jk) * vmask(ji,jj,jk) )
-            zhke(ji,jj,jk) = 0.25_wp * ( zv + zu )
-         END_3D
-!!an45         
-      !
-      CASE ( nkeg_C2 )                          !--  Standard scheme  --!
-         DO_3D( 0, 1, 0, 1, 1, jpkm1 )
-            zu =    puu(ji-1,jj  ,jk,Kmm) * puu(ji-1,jj  ,jk,Kmm)   &
-               &  + puu(ji  ,jj  ,jk,Kmm) * puu(ji  ,jj  ,jk,Kmm)
-            zv =    pvv(ji  ,jj-1,jk,Kmm) * pvv(ji  ,jj-1,jk,Kmm)   &
-               &  + pvv(ji  ,jj  ,jk,Kmm) * pvv(ji  ,jj  ,jk,Kmm)
-            zhke(ji,jj,jk) = 0.25_wp * ( zv + zu )
-         END_3D
-      CASE ( nkeg_HW )                          !--  Hollingsworth scheme  --!
-         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-            zu = 8._wp * ( puu(ji-1,jj  ,jk,Kmm) * puu(ji-1,jj  ,jk,Kmm)    &
-               &         + puu(ji  ,jj  ,jk,Kmm) * puu(ji  ,jj  ,jk,Kmm) )  &
-               &   +     ( puu(ji-1,jj-1,jk,Kmm) + puu(ji-1,jj+1,jk,Kmm) ) * ( puu(ji-1,jj-1,jk,Kmm) + puu(ji-1,jj+1,jk,Kmm) )   &
-               &   +     ( puu(ji  ,jj-1,jk,Kmm) + puu(ji  ,jj+1,jk,Kmm) ) * ( puu(ji  ,jj-1,jk,Kmm) + puu(ji  ,jj+1,jk,Kmm) )
-               !
-            zv = 8._wp * ( pvv(ji  ,jj-1,jk,Kmm) * pvv(ji  ,jj-1,jk,Kmm)    &
-               &         + pvv(ji  ,jj  ,jk,Kmm) * pvv(ji  ,jj  ,jk,Kmm) )  &
-               &  +      ( pvv(ji-1,jj-1,jk,Kmm) + pvv(ji+1,jj-1,jk,Kmm) ) * ( pvv(ji-1,jj-1,jk,Kmm) + pvv(ji+1,jj-1,jk,Kmm) )   &
-               &  +      ( pvv(ji-1,jj  ,jk,Kmm) + pvv(ji+1,jj  ,jk,Kmm) ) * ( pvv(ji-1,jj  ,jk,Kmm) + pvv(ji+1,jj  ,jk,Kmm) )
-            zhke(ji,jj,jk) = r1_48 * ( zv + zu )
-         END_3D
-         CALL lbc_lnk( 'dynkeg', zhke, 'T', 1. )
-         !
-      END SELECT 
-      !
-      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-         puu(ji,jj,jk,Krhs) = puu(ji,jj,jk,Krhs) - ( zhke(ji+1,jj  ,jk) - zhke(ji,jj,jk) ) / e1u(ji,jj)
-         pvv(ji,jj,jk,Krhs) = pvv(ji,jj,jk,Krhs) - ( zhke(ji  ,jj+1,jk) - zhke(ji,jj,jk) ) / e2v(ji,jj)
-      END_3D
-      !
-      IF( l_trddyn ) THEN                 ! save the Kinetic Energy trends for diagnostic
-         ztrdu(:,:,:) = puu(:,:,:,Krhs) - ztrdu(:,:,:)
-         ztrdv(:,:,:) = pvv(:,:,:,Krhs) - ztrdv(:,:,:)
-         CALL trd_dyn( ztrdu, ztrdv, jpdyn_keg, kt, Kmm )
-         DEALLOCATE( ztrdu , ztrdv )
-      ENDIF
-      !
-      IF(sn_cfctl%l_prtctl)   CALL prt_ctl( tab3d_1=puu(:,:,:,Krhs), clinfo1=' keg  - Ua: ', mask1=umask,   &
-         &                                  tab3d_2=pvv(:,:,:,Krhs), clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-      !
-      IF( ln_timing )   CALL timing_stop('dyn_keg')
-      !
-   END SUBROUTINE dyn_keg
-
-   !!======================================================================
-END MODULE dynkeg
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dynldf_lap_blp.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dynldf_lap_blp.F90	(revision 13603)
+++ 	(revision )
@@ -1,241 +1,0 @@
-MODULE dynldf_lap_blp
-   !!======================================================================
-   !!                   ***  MODULE  dynldf_lap_blp  ***
-   !! Ocean dynamics:  lateral viscosity trend (laplacian and bilaplacian)
-   !!======================================================================
-   !! History : 3.7  ! 2014-01  (G. Madec, S. Masson)  Original code, re-entrant laplacian
-   !!           4.0  ! 2020-04  (A. Nasser, G. Madec)  Add symmetric mixing tensor 
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dyn_ldf_lap   : update the momentum trend with the lateral viscosity using an iso-level   laplacian operator
-   !!   dyn_ldf_blp   : update the momentum trend with the lateral viscosity using an iso-level bilaplacian operator
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers
-   USE dom_oce        ! ocean space and time domain
-   USE ldfdyn         ! lateral diffusion: eddy viscosity coef.
-   USE ldfslp         ! iso-neutral slopes 
-   USE zdf_oce        ! ocean vertical physics
-   !
-   USE in_out_manager ! I/O manager
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC dyn_ldf_lap  ! called by dynldf.F90
-   PUBLIC dyn_ldf_blp  ! called by dynldf.F90
-!!anSYM  
-   INTEGER, PUBLIC, PARAMETER ::   np_dynldf_lap_rot  = 1         ! div-rot   laplacian 
-   INTEGER, PUBLIC, PARAMETER ::   np_dynldf_lap_sym  = 2         ! symmetric laplacian (Griffies&Hallberg 2000)
-   INTEGER, PUBLIC, PARAMETER ::   np_dynldf_lap_symN = 3         ! symmetric laplacian (cartesian)
-   
-   INTEGER, PUBLIC, PARAMETER ::   ln_dynldf_lap_typ = 1         ! choose type of laplacian (ideally from namelist)
-!!anSYM
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-!!st21
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: dynldf_lap_blp.F90 12822 2020-04-28 09:10:38Z gm $ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dyn_ldf_lap( kt, Kbb, Kmm, pu, pv, pu_rhs, pv_rhs, kpass )
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE dyn_ldf_lap  ***
-      !!                       
-      !! ** Purpose :   Compute the before horizontal momentum diffusive 
-      !!      trend and add it to the general trend of momentum equation.
-      !!
-      !! ** Method  :   The Laplacian operator apply on horizontal velocity is 
-      !!      writen as :   grad_h( ahmt div_h(U )) - curl_h( ahmf curl_z(U) ) 
-      !!      writen as :   grad_h( ahmt div_h(U )) - curl_h( ahmf curl_z(U) ) 
-      !!
-      !! ** Action : - pu_rhs, pv_rhs increased by the harmonic operator applied on pu, pv.
-      !!
-      !! Reference : S.Griffies, R.Hallberg 2000 Mon.Wea.Rev., DOI:/ 
-      !!----------------------------------------------------------------------
-      INTEGER                         , INTENT(in   ) ::   kt         ! ocean time-step index
-      INTEGER                         , INTENT(in   ) ::   Kbb, Kmm   ! ocean time level indices
-      INTEGER                         , INTENT(in   ) ::   kpass      ! =1/2 first or second passage
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::   pu, pv     ! before velocity  [m/s]
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu_rhs, pv_rhs   ! velocity trend   [m/s2]
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zsign        ! local scalars
-      REAL(wp) ::   zua, zva     ! local scalars
-      REAL(wp), DIMENSION(jpi,jpj) ::   zcur, zdiv
-      REAL(wp), DIMENSION(jpi,jpj) ::   zten, zshe   ! tension (diagonal) and shearing (anti-diagonal) terms
-      !!----------------------------------------------------------------------
-      !
-!!anSYM TO BE ADDED : reading of laplacian operator (ln_dynldf_lap_typ -> to be written nn_) shall be added in dyn_ldf_init 
-!!                 as the writing   
-!!                 and an integer as np_dynldf_lap for instance taken as argument by dyn_ldf_lap call in dyn_ldf
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'dyn_ldf : iso-level harmonic (laplacian) operator, pass=', kpass
-         WRITE(numout,*) '~~~~~~~ '
-         WRITE(numout,*) '                  ln_dynldf_lap_typ = ', ln_dynldf_lap_typ
-         SELECT CASE( ln_dynldf_lap_typ )             ! print the choice of operator
-         CASE( np_dynldf_lap_rot )   ;   WRITE(numout,*) '   ==>>>   div-rot   laplacian'
-         CASE( np_dynldf_lap_sym )   ;   WRITE(numout,*) '   ==>>>   symmetric laplacian (covariant form)'
-         CASE( np_dynldf_lap_symN)   ;   WRITE(numout,*) '   ==>>>   symmetric laplacian (simple form)'
-         END SELECT
-      ENDIF
-      !
-      IF( kpass == 1 ) THEN   ;   zsign =  1._wp      ! bilaplacian operator require a minus sign
-      ELSE                    ;   zsign = -1._wp      !  (eddy viscosity coef. >0)
-      ENDIF
-      !
-      SELECT CASE( ln_dynldf_lap_typ )  
-         !              
-         CASE ( np_dynldf_lap_rot )       !==  Vorticity-Divergence form  ==!
-            !   
-            DO jk = 1, jpkm1                                 ! Horizontal slab
-               !                                             
-               DO_2D( 0, 1, 0, 1 )
-               !                                      ! ahm * e3 * curl  (computed from 1 to jpim1/jpjm1)
-!!gm open question here : e3f  at before or now ?    probably now... 
-!!gm note that ahmf has already been multiplied by fmask
-            zcur(ji-1,jj-1) =  &
-               &      ahmf(ji-1,jj-1,jk) * e3f(ji-1,jj-1,jk) * r1_e1e2f(ji-1,jj-1)      &
-               &  * (  e2v(ji  ,jj-1) * pv(ji  ,jj-1,jk) - e2v(ji-1,jj-1) * pv(ji-1,jj-1,jk)  &
-               &     - e1u(ji-1,jj  ) * pu(ji-1,jj  ,jk) + e1u(ji-1,jj-1) * pu(ji-1,jj-1,jk)  )
-            !                                      ! ahm * div        (computed from 2 to jpi/jpj)
-!!gm note that ahmt has already been multiplied by tmask
-                  zdiv(ji,jj)     = ahmt(ji,jj,jk) * r1_e1e2t(ji,jj) / e3t(ji,jj,jk,Kbb)                                         &
-                     &     * (  e2u(ji,jj)*e3u(ji,jj,jk,Kbb) * pu(ji,jj,jk) - e2u(ji-1,jj)*e3u(ji-1,jj,jk,Kbb) * pu(ji-1,jj,jk)  &
-                     &        + e1v(ji,jj)*e3v(ji,jj,jk,Kbb) * pv(ji,jj,jk) - e1v(ji,jj-1)*e3v(ji,jj-1,jk,Kbb) * pv(ji,jj-1,jk)  )
-               END_2D
-               !
-               DO_2D( 0, 0, 0, 0 )
-                  pu_rhs(ji,jj,jk) = pu_rhs(ji,jj,jk) + zsign * (                                             &
-                     &              - ( zcur(ji  ,jj) - zcur(ji,jj-1) ) * r1_e2u(ji,jj) / e3u(ji,jj,jk,Kmm)   &
-                     &              + ( zdiv(ji+1,jj) - zdiv(ji,jj  ) ) * r1_e1u(ji,jj)                       )
-                     !
-                  pv_rhs(ji,jj,jk) = pv_rhs(ji,jj,jk) + zsign * (                                             &
-                     &                ( zcur(ji,jj  ) - zcur(ji-1,jj) ) * r1_e1v(ji,jj) / e3v(ji,jj,jk,Kmm)   &
-                     &              + ( zdiv(ji,jj+1) - zdiv(ji  ,jj) ) * r1_e2v(ji,jj)                       )
-               END_2D
-               !
-            END DO                                           !   End of slab
-            !
-         CASE ( np_dynldf_lap_sym )       !==  Symmetric form  ==!   (Griffies&Hallberg 2000)
-            !
-            DO jk = 1, jpkm1                                 ! Horizontal slab
-               !
-               DO_2D( 0, 1, 0, 1 )
-                  !                                      ! shearing stress component (F-point)   NB : ahmf has already been multiplied by fmask
-                  zshe(ji-1,jj-1) = ahmf(ji-1,jj-1,jk)                                                              &
-                     &     * (    e1f(ji-1,jj-1)    * r1_e2f(ji-1,jj-1)                                             &
-                     &         * ( pu(ji-1,jj  ,jk) * r1_e1u(ji-1,jj  )  - pu(ji-1,jj-1,jk) * r1_e1u(ji-1,jj-1) )   &
-                     &         +  e2f(ji-1,jj-1)    * r1_e1f(ji-1,jj-1)                                             &
-                     &         * ( pv(ji  ,jj-1,jk) * r1_e2v(ji  ,jj-1)  - pv(ji-1,jj-1,jk) * r1_e2v(ji-1,jj-1) )   ) 
-                  !                                      ! tension stress component (T-point)   NB : ahmt has already been multiplied by tmask
-                  zten(ji,jj)    = ahmt(ji,jj,jk)                                                       &
-                     &     * (    e2t(ji,jj)    * r1_e1t(ji,jj)                                         &
-                     &         * ( pu(ji,jj,jk) * r1_e2u(ji,jj)  - pu(ji-1,jj,jk) * r1_e2u(ji-1,jj) )   &
-                     &         -  e1t(ji,jj)    * r1_e2t(ji,jj)                                         &
-                     &         * ( pv(ji,jj,jk) * r1_e1v(ji,jj)  - pv(ji,jj-1,jk) * r1_e1v(ji,jj-1) )   )   
-               END_2D
-               !
-               DO_2D( 0, 0, 0, 0 )
-                  pu_rhs(ji,jj,jk) = pu_rhs(ji,jj,jk) + zsign * r1_e1e2u(ji,jj) / e3u(ji,jj,jk,Kmm)                               &
-                     &    * (   (   zten(ji+1,jj  ) * e2t(ji+1,jj  )*e2t(ji+1,jj  ) * e3t(ji+1,jj  ,jk,Kmm)                       &
-                     &            - zten(ji  ,jj  ) * e2t(ji  ,jj  )*e2t(ji  ,jj  ) * e3t(ji  ,jj  ,jk,Kmm) ) * r1_e2u(ji,jj)     &                                                    
-                     &        + (   zshe(ji  ,jj  ) * e1f(ji  ,jj  )*e1f(ji  ,jj  ) * e3f(ji  ,jj  ,jk)                           &
-                     &            - zshe(ji  ,jj-1) * e1f(ji  ,jj-1)*e1f(ji  ,jj-1) * e3f(ji  ,jj-1,jk)     ) * r1_e1u(ji,jj) )   
-                  !
-                  pv_rhs(ji,jj,jk) = pv_rhs(ji,jj,jk) + zsign * r1_e1e2v(ji,jj) / e3v(ji,jj,jk,Kmm)                               &
-                     &    * (   (   zshe(ji  ,jj  ) * e2f(ji  ,jj  )*e2f(ji  ,jj  ) * e3f(ji  ,jj  ,jk)                           &
-                     &            - zshe(ji-1,jj  ) * e2f(ji-1,jj  )*e2f(ji-1,jj  ) * e3f(ji-1,jj  ,jk)     ) * r1_e2v(ji,jj)     &
-                     &        - (   zten(ji  ,jj+1) * e1t(ji  ,jj+1)*e1t(ji  ,jj+1) * e3t(ji  ,jj+1,jk,Kmm)                       &
-                     &            - zten(ji  ,jj  ) * e1t(ji  ,jj  )*e1t(ji  ,jj  ) * e3t(ji  ,jj  ,jk,Kmm) ) * r1_e1v(ji,jj) )
-                   !
-               END_2D
-               !
-            END DO                                           !   End of slab
-            !
-         CASE ( np_dynldf_lap_symN )       !==  Symmetric form  ==!   (naive way)
-            !
-            DO jk = 1, jpkm1                                 ! Horizontal slab
-               !
-               DO_2D( 0, 1, 0, 1 )
-                  !                                      ! shearing stress component (F-point)   NB : ahmf has already been multiplied by fmask
-                  zshe(ji-1,jj-1) = ahmf(ji-1,jj-1,jk)                                           &
-                     &     * (   r1_e2f(ji-1,jj-1) * ( pu(ji-1,jj  ,jk) - pu(ji-1,jj-1,jk)  )   &
-                     &         + r1_e1f(ji-1,jj-1) * ( pv(ji  ,jj-1,jk) - pv(ji-1,jj-1,jk)  )   ) 
-                  !                                      ! tension stress component (T-point)   NB : ahmt has already been multiplied by tmask
-                  zten(ji,jj)    = ahmt(ji,jj,jk)                                       &
-                     &     * (   r1_e1t(ji,jj) * ( pu(ji,jj,jk) - pu(ji-1,jj  ,jk)  )   &
-                     &         - r1_e2t(ji,jj) * ( pv(ji,jj,jk) - pv(ji  ,jj-1,jk)  )   )   
-               END_2D
-               !
-               DO_2D( 0, 0, 0, 0 )
-                  pu_rhs(ji,jj,jk) = pu_rhs(ji,jj,jk) + zsign * r1_e1e2u(ji,jj) / e3u(ji,jj,jk,Kmm)   &
-                     &    * (   zten(ji+1,jj  ) * e2t(ji+1,jj  ) * e3t(ji+1,jj  ,jk,Kmm)              &
-                     &        - zten(ji  ,jj  ) * e2t(ji  ,jj  ) * e3t(ji  ,jj  ,jk,Kmm)              &
-                     &        + zshe(ji  ,jj  ) * e1f(ji  ,jj  ) * e3f(ji  ,jj  ,jk)                  &
-                     &        - zshe(ji  ,jj-1) * e1f(ji  ,jj-1) * e3f(ji  ,jj-1,jk)                  )    
-                  !
-                  pv_rhs(ji,jj,jk) = pv_rhs(ji,jj,jk) + zsign * r1_e1e2v(ji,jj) / e3v(ji,jj,jk,Kmm)   &
-                     &    * (   zshe(ji  ,jj  ) * e2f(ji  ,jj  ) * e3f(ji  ,jj  ,jk)                  &
-                     &        - zshe(ji-1,jj  ) * e2f(ji-1,jj  ) * e3f(ji-1,jj  ,jk)                  &
-                     &        - zten(ji  ,jj+1) * e1t(ji  ,jj+1) * e3t(ji  ,jj+1,jk,Kmm)              &
-                     &        + zten(ji  ,jj  ) * e1t(ji  ,jj  ) * e3t(ji  ,jj  ,jk,Kmm)              )
-                   !
-               END_2D
-               !
-            END DO                                           !   End of slab
-            !  
-         CASE DEFAULT                                     ! error
-            CALL ctl_stop('STOP','dyn_ldf_lap: wrong value for ln_dynldf_lap_typ'  )
-         END SELECT
-         !
-      !
-   END SUBROUTINE dyn_ldf_lap
-
-
-   SUBROUTINE dyn_ldf_blp( kt, Kbb, Kmm, pu, pv, pu_rhs, pv_rhs )
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE dyn_ldf_blp  ***
-      !!                    
-      !! ** Purpose :   Compute the before lateral momentum viscous trend 
-      !!              and add it to the general trend of momentum equation.
-      !!
-      !! ** Method  :   The lateral viscous trends is provided by a bilaplacian
-      !!      operator applied to before field (forward in time).
-      !!      It is computed by two successive calls to dyn_ldf_lap routine
-      !!
-      !! ** Action :   pt(:,:,:,:,Krhs)   updated with the before rotated bilaplacian diffusion
-      !!----------------------------------------------------------------------
-      INTEGER                         , INTENT(in   ) ::   kt         ! ocean time-step index
-      INTEGER                         , INTENT(in   ) ::   Kbb, Kmm   ! ocean time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::   pu, pv     ! before velocity fields
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu_rhs, pv_rhs   ! momentum trend
-      !
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zulap, zvlap   ! laplacian at u- and v-point
-      !!----------------------------------------------------------------------
-      !
-      IF( kt == nit000 )  THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn_ldf_blp : bilaplacian operator momentum '
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
-      ENDIF
-      !
-      zulap(:,:,:) = 0._wp
-      zvlap(:,:,:) = 0._wp
-      !
-      CALL dyn_ldf_lap( kt, Kbb, Kmm, pu, pv, zulap, zvlap, 1 )   ! rotated laplacian applied to pt (output in zlap,Kbb)
-      !
-      CALL lbc_lnk_multi( 'dynldf_lap_blp', zulap, 'U', -1., zvlap, 'V', -1. )             ! Lateral boundary conditions
-      !
-      CALL dyn_ldf_lap( kt, Kbb, Kmm, zulap, zvlap, pu_rhs, pv_rhs, 2 )   ! rotated laplacian applied to zlap (output in pt(:,:,:,:,Krhs))
-      !
-   END SUBROUTINE dyn_ldf_blp
-
-   !!======================================================================
-END MODULE dynldf_lap_blp
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dynvor.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dynvor.F90	(revision 13603)
+++ NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/dynvor.F90	(revision 13604)
@@ -447,5 +447,5 @@
             IF( ln_dynvor_msk ) THEN                     ! mask the relative vorticity
                DO_2D( 1, 0, 1, 0 )
-                  zwz(ji,jj) = ff_f(ji,jj) * fmask(ji,jj,jk)
+                  zwz(ji,jj) = zwz(ji,jj) * fmask(ji,jj,jk)
                END_2D
             ENDIF
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/ldfdyn.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/ldfdyn.F90	(revision 13603)
+++ 	(revision )
@@ -1,525 +1,0 @@
-MODULE ldfdyn
-   !!======================================================================
-   !!                       ***  MODULE  ldfdyn  ***
-   !! Ocean physics:  lateral viscosity coefficient 
-   !!=====================================================================
-   !! History :  OPA  ! 1997-07  (G. Madec)  multi dimensional coefficients
-   !!   NEMO     1.0  ! 2002-09  (G. Madec)  F90: Free form and module
-   !!            3.7  ! 2014-01  (F. Lemarie, G. Madec)  restructuration/simplification of ahm specification,
-   !!                 !                                  add velocity dependent coefficient and optional read in file
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   ldf_dyn_init  : initialization, namelist read, and parameters control
-   !!   ldf_dyn       : update lateral eddy viscosity coefficients at each time step 
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers   
-   USE dom_oce         ! ocean space and time domain 
-   USE phycst          ! physical constants
-   USE ldfslp          ! lateral diffusion: slopes of mixing orientation
-   USE ldfc1d_c2d      ! lateral diffusion: 1D and 2D cases
-   !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O module for ehanced bottom friction file
-   USE timing          ! Timing
-   USE lib_mpp         ! distribued memory computing library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   ldf_dyn_init   ! called by nemogcm.F90
-   PUBLIC   ldf_dyn        ! called by step.F90
-
-   !                                    !!* Namelist namdyn_ldf : lateral mixing on momentum *
-   LOGICAL , PUBLIC ::   ln_dynldf_OFF   !: No operator (i.e. no explicit diffusion)
-   LOGICAL , PUBLIC ::   ln_dynldf_lap   !: laplacian operator
-   LOGICAL , PUBLIC ::   ln_dynldf_blp   !: bilaplacian operator
-   LOGICAL , PUBLIC ::   ln_dynldf_lev   !: iso-level direction
-   LOGICAL , PUBLIC ::   ln_dynldf_hor   !: horizontal (geopotential) direction
-!  LOGICAL , PUBLIC ::   ln_dynldf_iso   !: iso-neutral direction                        (see ldfslp)
-   INTEGER , PUBLIC ::   nn_ahm_ijk_t    !: choice of time & space variations of the lateral eddy viscosity coef.
-   !                                        !  time invariant coefficients:  aht = 1/2  Ud*Ld   (lap case) 
-   !                                           !                             bht = 1/12 Ud*Ld^3 (blp case)
-   REAL(wp), PUBLIC ::   rn_Uv                 !: lateral viscous velocity  [m/s]
-   REAL(wp), PUBLIC ::   rn_Lv                 !: lateral viscous length    [m]
-   !                                        ! Smagorinsky viscosity  (nn_ahm_ijk_t = 32) 
-   REAL(wp), PUBLIC ::   rn_csmc               !: Smagorinsky constant of proportionality 
-   REAL(wp), PUBLIC ::   rn_minfac             !: Multiplicative factor of theorectical minimum Smagorinsky viscosity
-   REAL(wp), PUBLIC ::   rn_maxfac             !: Multiplicative factor of theorectical maximum Smagorinsky viscosity
-   !                                        ! iso-neutral laplacian (ln_dynldf_lap=ln_dynldf_iso=T)
-   REAL(wp), PUBLIC ::   rn_ahm_b              !: lateral laplacian background eddy viscosity  [m2/s]
-
-   !                                    !!* Parameter to control the type of lateral viscous operator
-   INTEGER, PARAMETER, PUBLIC ::   np_ERROR  =-10                       !: error in setting the operator
-   INTEGER, PARAMETER, PUBLIC ::   np_no_ldf = 00                       !: without operator (i.e. no lateral viscous trend)
-   !                          !!      laplacian     !    bilaplacian    !
-   INTEGER, PARAMETER, PUBLIC ::   np_lap    = 10   ,   np_blp    = 20  !: iso-level operator
-   INTEGER, PARAMETER, PUBLIC ::   np_lap_i  = 11                       !: iso-neutral or geopotential operator
-   !
-   INTEGER           , PUBLIC ::   nldf_dyn         !: type of lateral diffusion used defined from ln_dynldf_... (namlist logicals)
-   LOGICAL           , PUBLIC ::   l_ldfdyn_time    !: flag for time variation of the lateral eddy viscosity coef.
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ahmt, ahmf   !: eddy viscosity coef. at T- and F-points [m2/s or m4/s]
-   REAL(wp),         ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dtensq       !: horizontal tension squared         (Smagorinsky only)
-   REAL(wp),         ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dshesq       !: horizontal shearing strain squared (Smagorinsky only)
-   REAL(wp),         ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   esqt, esqf   !: Square of the local gridscale (e1e2/(e1+e2))**2           
-
-   REAL(wp) ::   r1_2    = 0.5_wp            ! =1/2
-   REAL(wp) ::   r1_4    = 0.25_wp           ! =1/4
-   REAL(wp) ::   r1_8    = 0.125_wp          ! =1/8
-   REAL(wp) ::   r1_12   = 1._wp / 12._wp    ! =1/12
-   REAL(wp) ::   r1_288  = 1._wp / 288._wp   ! =1/( 12^2 * 2 )
-
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: ldfdyn.F90 12822 2020-04-28 09:10:38Z gm $ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE ldf_dyn_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE ldf_dyn_init  ***
-      !!                   
-      !! ** Purpose :   set the horizontal ocean dynamics physics
-      !!
-      !! ** Method  :   the eddy viscosity coef. specification depends on:
-      !!              - the operator:
-      !!             ln_dynldf_lap = T     laplacian operator
-      !!             ln_dynldf_blp = T   bilaplacian operator
-      !!              - the parameter nn_ahm_ijk_t:
-      !!    nn_ahm_ijk_t  =  0 => = constant
-      !!                  = 10 => = F(z) :     = constant with a reduction of 1/4 with depth 
-      !!                  =-20 => = F(i,j)     = shape read in 'eddy_viscosity.nc' file
-      !!                  = 20    = F(i,j)     = F(e1,e2) or F(e1^3,e2^3) (lap or bilap case)
-      !!                  =-30 => = F(i,j,k)   = shape read in 'eddy_viscosity.nc'  file
-      !!                  = 30    = F(i,j,k)   = 2D (case 20) + decrease with depth (case 10)
-      !!                  = 31    = F(i,j,k,t) = F(local velocity) (  |u|e  /12   laplacian operator
-      !!                                                           or |u|e^3/12 bilaplacian operator )
-      !!                  = 32    = F(i,j,k,t) = F(local deformation rate and gridscale) (D and L) (Smagorinsky)  
-      !!                                                           (   L^2|D|      laplacian operator
-      !!                                                           or  L^4|D|/8  bilaplacian operator )
-      !!----------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk                     ! dummy loop indices
-      INTEGER  ::   ioptio, ierr, inum, ios, inn   ! local integer
-      REAL(wp) ::   zah0, zah_max, zUfac           ! local scalar
-      REAL(wp) ::   zsum                           ! local scalar
-      CHARACTER(len=5) ::   cl_Units               ! units (m2/s or m4/s)
-      !!
-      NAMELIST/namdyn_ldf/ ln_dynldf_OFF, ln_dynldf_lap, ln_dynldf_blp,   &   ! type of operator
-         &                 ln_dynldf_lev, ln_dynldf_hor, ln_dynldf_iso,   &   ! acting direction of the operator
-         &                 nn_ahm_ijk_t , rn_Uv    , rn_Lv,   rn_ahm_b,   &   ! lateral eddy coefficient
-         &                 rn_csmc      , rn_minfac    , rn_maxfac            ! Smagorinsky settings
-      !!----------------------------------------------------------------------
-      !
-      READ  ( numnam_ref, namdyn_ldf, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_ldf in reference namelist' )
-
-      READ  ( numnam_cfg, namdyn_ldf, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_ldf in configuration namelist' )
-      IF(lwm) WRITE ( numond, namdyn_ldf )
-
-      IF(lwp) THEN                      ! Parameter print
-         WRITE(numout,*)
-         WRITE(numout,*) 'ldf_dyn : lateral momentum physics'
-         WRITE(numout,*) '~~~~~~~'
-         WRITE(numout,*) '   Namelist namdyn_ldf : set lateral mixing parameters'
-         !
-         WRITE(numout,*) '      type :'
-         WRITE(numout,*) '         no explicit diffusion                ln_dynldf_OFF = ', ln_dynldf_OFF
-         WRITE(numout,*) '         laplacian operator                   ln_dynldf_lap = ', ln_dynldf_lap
-         WRITE(numout,*) '         bilaplacian operator                 ln_dynldf_blp = ', ln_dynldf_blp
-         !
-         WRITE(numout,*) '      direction of action :'
-         WRITE(numout,*) '         iso-level                            ln_dynldf_lev = ', ln_dynldf_lev
-         WRITE(numout,*) '         horizontal (geopotential)            ln_dynldf_hor = ', ln_dynldf_hor
-         WRITE(numout,*) '         iso-neutral                          ln_dynldf_iso = ', ln_dynldf_iso
-         !
-         WRITE(numout,*) '      coefficients :'
-         WRITE(numout,*) '         type of time-space variation         nn_ahm_ijk_t  = ', nn_ahm_ijk_t
-         WRITE(numout,*) '         lateral viscous velocity  (if cst)      rn_Uv      = ', rn_Uv, ' m/s'
-         WRITE(numout,*) '         lateral viscous length    (if cst)      rn_Lv      = ', rn_Lv, ' m'
-         WRITE(numout,*) '         background viscosity (iso-lap case)     rn_ahm_b   = ', rn_ahm_b, ' m2/s'
-         !
-         WRITE(numout,*) '      Smagorinsky settings (nn_ahm_ijk_t  = 32) :'
-         WRITE(numout,*) '         Smagorinsky coefficient              rn_csmc       = ', rn_csmc
-         WRITE(numout,*) '         factor multiplier for eddy visc.'
-         WRITE(numout,*) '            lower limit (default 1.0)         rn_minfac    = ', rn_minfac
-         WRITE(numout,*) '            upper limit (default 1.0)         rn_maxfac    = ', rn_maxfac
-      ENDIF
-
-      !
-      !           !==  type of lateral operator used  ==!   (set nldf_dyn)
-      !           !=====================================!
-      !
-      nldf_dyn = np_ERROR
-      ioptio = 0
-      IF( ln_dynldf_OFF ) THEN   ;   nldf_dyn = np_no_ldf   ;   ioptio = ioptio + 1   ;   ENDIF
-      IF( ln_dynldf_lap ) THEN   ;                              ioptio = ioptio + 1   ;   ENDIF
-      IF( ln_dynldf_blp ) THEN   ;                              ioptio = ioptio + 1   ;   ENDIF
-      IF( ioptio /= 1   )   CALL ctl_stop( 'dyn_ldf_init: use ONE of the 3 operator options (NONE/lap/blp)' )
-      !
-      IF(.NOT.ln_dynldf_OFF ) THEN     !==  direction ==>> type of operator  ==!
-         ioptio = 0
-         IF( ln_dynldf_lev )   ioptio = ioptio + 1
-         IF( ln_dynldf_hor )   ioptio = ioptio + 1
-         IF( ln_dynldf_iso )   ioptio = ioptio + 1
-         IF( ioptio /= 1   )   CALL ctl_stop( 'dyn_ldf_init: use ONE of the 3 direction options (level/hor/iso)' )
-         !
-         !                             ! Set nldf_dyn, the type of lateral diffusion, from ln_dynldf_... logicals
-         ierr = 0
-         IF( ln_dynldf_lap ) THEN         ! laplacian operator
-            IF( ln_zco ) THEN                   ! z-coordinate
-               IF ( ln_dynldf_lev )   nldf_dyn = np_lap     ! iso-level = horizontal (no rotation)
-               IF ( ln_dynldf_hor )   nldf_dyn = np_lap     ! iso-level = horizontal (no rotation)
-               IF ( ln_dynldf_iso )   nldf_dyn = np_lap_i   ! iso-neutral            (   rotation)
-            ENDIF
-            IF( ln_zps ) THEN                   ! z-coordinate with partial step
-               IF ( ln_dynldf_lev )   nldf_dyn = np_lap     ! iso-level              (no rotation)
-               IF ( ln_dynldf_hor )   nldf_dyn = np_lap     ! iso-level              (no rotation)
-               IF ( ln_dynldf_iso )   nldf_dyn = np_lap_i   ! iso-neutral            (   rotation)
-            ENDIF
-            IF( ln_sco ) THEN                   ! s-coordinate
-               IF ( ln_dynldf_lev )   nldf_dyn = np_lap     ! iso-level = horizontal (no rotation)
-               IF ( ln_dynldf_hor )   nldf_dyn = np_lap_i   ! horizontal             (   rotation)
-               IF ( ln_dynldf_iso )   nldf_dyn = np_lap_i   ! iso-neutral            (   rotation)
-            ENDIF
-         ENDIF
-         !
-         IF( ln_dynldf_blp ) THEN         ! bilaplacian operator
-            IF( ln_zco ) THEN                   ! z-coordinate
-               IF( ln_dynldf_lev )   nldf_dyn = np_blp   ! iso-level = horizontal (no rotation)
-               IF( ln_dynldf_hor )   nldf_dyn = np_blp   ! iso-level = horizontal (no rotation)
-               IF( ln_dynldf_iso )   ierr = 2            ! iso-neutral            (   rotation)
-            ENDIF
-            IF( ln_zps ) THEN                   ! z-coordinate with partial step
-               IF( ln_dynldf_lev )   nldf_dyn = np_blp   ! iso-level              (no rotation)
-               IF( ln_dynldf_hor )   nldf_dyn = np_blp   ! iso-level              (no rotation)
-               IF( ln_dynldf_iso )   ierr = 2            ! iso-neutral            (   rotation)
-            ENDIF
-            IF( ln_sco ) THEN                   ! s-coordinate
-               IF( ln_dynldf_lev )   nldf_dyn = np_blp   ! iso-level              (no rotation)
-               IF( ln_dynldf_hor )   ierr = 2            ! horizontal             (   rotation)
-               IF( ln_dynldf_iso )   ierr = 2            ! iso-neutral            (   rotation)
-            ENDIF
-         ENDIF
-         !
-         IF( ierr == 2 )   CALL ctl_stop( 'rotated bi-laplacian operator does not exist' )
-         !
-         IF( nldf_dyn == np_lap_i )   l_ldfslp = .TRUE.  ! rotation require the computation of the slopes
-         !
-      ENDIF
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         SELECT CASE( nldf_dyn )
-         CASE( np_no_ldf )   ;   WRITE(numout,*) '   ==>>>   NO lateral viscosity'
-         CASE( np_lap    )   ;   WRITE(numout,*) '   ==>>>   iso-level laplacian operator'
-         CASE( np_lap_i  )   ;   WRITE(numout,*) '   ==>>>   rotated laplacian operator with iso-level background'
-         CASE( np_blp    )   ;   WRITE(numout,*) '   ==>>>   iso-level bi-laplacian operator'
-         END SELECT
-         WRITE(numout,*)
-      ENDIF
-      
-      !
-      !           !==  Space/time variation of eddy coefficients  ==!
-      !           !=================================================!
-      !
-      l_ldfdyn_time = .FALSE.                ! no time variation except in case defined below
-      !
-      IF( ln_dynldf_OFF ) THEN
-         IF(lwp) WRITE(numout,*) '   ==>>>   No viscous operator selected. ahmt and ahmf are not allocated'
-         RETURN
-         !
-      ELSE                                   !==  a lateral diffusion operator is used  ==!
-         !
-         !                                         ! allocate the ahm arrays
-         ALLOCATE( ahmt(jpi,jpj,jpk) , ahmf(jpi,jpj,jpk) , STAT=ierr )
-         IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'ldf_dyn_init: failed to allocate arrays')
-         !
-         ahmt(:,:,:) = 0._wp                       ! init to 0 needed 
-         ahmf(:,:,:) = 0._wp
-         !
-         !                                         ! value of lap/blp eddy mixing coef.
-         IF(     ln_dynldf_lap ) THEN   ;   zUfac = r1_2 *rn_Uv   ;   inn = 1   ;   cl_Units = ' m2/s'   !   laplacian
-         ELSEIF( ln_dynldf_blp ) THEN   ;   zUfac = r1_12*rn_Uv   ;   inn = 3   ;   cl_Units = ' m4/s'   ! bilaplacian
-         ENDIF
-         zah0    = zUfac *    rn_Lv**inn              ! mixing coefficient
-         zah_max = zUfac * (ra*rad)**inn              ! maximum reachable coefficient (value at the Equator)
-         !
-         SELECT CASE(  nn_ahm_ijk_t  )             !* Specification of space-time variations of ahmt, ahmf
-         !
-         CASE(   0  )      !==  constant  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity. = constant = ', zah0, cl_Units
-            ahmt(:,:,1:jpkm1) = zah0
-            ahmf(:,:,1:jpkm1) = zah0
-            !
-         CASE(  10  )      !==  fixed profile  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity = F( depth )'
-            IF(lwp) WRITE(numout,*) '           surface viscous coef. = constant = ', zah0, cl_Units
-            ahmt(:,:,1) = zah0                        ! constant surface value
-            ahmf(:,:,1) = zah0
-            CALL ldf_c1d( 'DYN', ahmt(:,:,1), ahmf(:,:,1), ahmt, ahmf )
-            !
-         CASE ( -20 )      !== fixed horizontal shape read in file  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity = F(i,j) read in eddy_viscosity.nc file'
-            CALL iom_open( 'eddy_viscosity_2D.nc', inum )
-            CALL iom_get ( inum, jpdom_data, 'ahmt_2d', ahmt(:,:,1) )
-            CALL iom_get ( inum, jpdom_data, 'ahmf_2d', ahmf(:,:,1) )
-            CALL iom_close( inum )
-            DO jk = 2, jpkm1
-               ahmt(:,:,jk) = ahmt(:,:,1)
-               ahmf(:,:,jk) = ahmf(:,:,1)
-            END DO
-            !
-         CASE(  20  )      !== fixed horizontal shape  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity = F( e1, e2 ) or F( e1^3, e2^3 ) (lap. or blp. case)'
-            IF(lwp) WRITE(numout,*) '           using a fixed viscous velocity = ', rn_Uv  ,' m/s   and   Lv = Max(e1,e2)'
-            IF(lwp) WRITE(numout,*) '           maximum reachable coefficient (at the Equator) = ', zah_max, cl_Units, '  for e1=1°)'
-            CALL ldf_c2d( 'DYN', zUfac      , inn        , ahmt, ahmf )         ! surface value proportional to scale factor^inn
-            !
-         CASE( -30  )      !== fixed 3D shape read in file  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity = F(i,j,k) read in eddy_viscosity_3D.nc file'
-            CALL iom_open( 'eddy_viscosity_3D.nc', inum )
-            CALL iom_get ( inum, jpdom_data, 'ahmt_3d', ahmt )
-            CALL iom_get ( inum, jpdom_data, 'ahmf_3d', ahmf )
-            CALL iom_close( inum )
-            !
-         CASE(  30  )       !==  fixed 3D shape  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity = F( latitude, longitude, depth )'
-            IF(lwp) WRITE(numout,*) '           using a fixed viscous velocity = ', rn_Uv  ,' m/s   and   Ld = Max(e1,e2)'
-            IF(lwp) WRITE(numout,*) '           maximum reachable coefficient (at the Equator) = ', zah_max, cl_Units, '  for e1=1°)'
-            CALL ldf_c2d( 'DYN', zUfac      , inn        , ahmt, ahmf )         ! surface value proportional to scale factor^inn
-            CALL ldf_c1d( 'DYN', ahmt(:,:,1), ahmf(:,:,1), ahmt, ahmf )  ! reduction with depth
-            !
-         CASE(  31  )       !==  time varying 3D field  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity = F( latitude, longitude, depth , time )'
-            IF(lwp) WRITE(numout,*) '           proportional to the local velocity : 1/2 |u|e (lap) or 1/12 |u|e^3 (blp)'
-            !
-            l_ldfdyn_time = .TRUE.     ! will be calculated by call to ldf_dyn routine in step.F90
-            !
-         CASE(  32  )       !==  time varying 3D field  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity = F( latitude, longitude, depth , time )'
-            IF(lwp) WRITE(numout,*) '           proportional to the local deformation rate and gridscale (Smagorinsky)'
-            !
-            l_ldfdyn_time = .TRUE.     ! will be calculated by call to ldf_dyn routine in step.F90
-            !
-            !                          ! allocate arrays used in ldf_dyn. 
-            ALLOCATE( dtensq(jpi,jpj,jpk) , dshesq(jpi,jpj,jpk) , esqt(jpi,jpj) , esqf(jpi,jpj) , STAT=ierr )
-            IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'ldf_dyn_init: failed to allocate Smagorinsky arrays')
-            !
-            DO_2D( 1, 1, 1, 1 )
-               esqt(ji,jj) = ( 2._wp * e1e2t(ji,jj) / ( e1t(ji,jj) + e2t(ji,jj) ) )**2 
-               esqf(ji,jj) = ( 2._wp * e1e2f(ji,jj) / ( e1f(ji,jj) + e2f(ji,jj) ) )**2 
-            END_2D
-            !
-         CASE DEFAULT
-            CALL ctl_stop('ldf_dyn_init: wrong choice for nn_ahm_ijk_t, the type of space-time variation of ahm')
-         END SELECT
-         !
-         IF( .NOT.l_ldfdyn_time ) THEN             !* No time variation 
-            IF(     ln_dynldf_lap ) THEN                 !   laplacian operator (mask only)
-               ahmt(:,:,1:jpkm1) =       ahmt(:,:,1:jpkm1)   * tmask(:,:,1:jpkm1)
-               WRITE(numout,*) ' ahmt tmask '
-!! mask tension at the coast (equivalent of ghostpoints at T)
-!              DO jk = 1, jpk
-!                 DO jj = 1, jpjm1
-!                    DO ji = 1, jpim1      ! NO vector opt.
-!                       ! si sum(fmask)==3 = mouillé (on touche pas)
-!                       ! si sum = 2 alors on met a 0 zsum = fmask + fmask + fmask,.. et si zsum < 2 -> 0 sinon = 1
-!                       zsum =   fmask(ji,jj  ,jk) + fmask(ji+1,jj  ,jk)   &
-!                          &   + fmask(ji,jj+1,jk) + fmask(ji+1,jj+1,jk)
-!                       IF ( zsum < 2._wp )   ahmt(ji,jj,jk) = 0
-!                       !
-!                       !ahmt(ji,jj,jk) = ahmt(ji,jj,jk) * fmask(ji,jj  ,jk) * fmask(ji+1,jj  ,jk)   &
-!                       !   &                            * fmask(ji,jj+1,jk) * fmask(ji+1,jj+1,jk)
-!                    END DO
-!                 END DO
-!              END DO
-!              ahmt(jpi,:,1:jpkm1) =  0._wp
-!              ahmt(:,jpj,1:jpkm1) =  0._wp
-!              WRITE(numout,*) '   an45 ahmt x0'
-
-               ahmf(:,:,1:jpkm1) =       ahmf(:,:,1:jpkm1)   * fmask(:,:,1:jpkm1)
-               WRITE(numout,*) ' ahmf fmask '
-!!an apply no slip at the coast (ssfmask = 1 within the domain and at the coast contrary to fmask in free slip)
-!               DO jk = 1, jpkm1
-!                  ahmf(:,:,jk) =    ahmf(:,:,jk) * ( 2._wp * ssfmask(:,:) - fmask(:,:,jk) )
-!               END DO
-!               WRITE(numout,*) '   an45 ahmf x2'
-
-            ELSEIF( ln_dynldf_blp ) THEN                 ! bilaplacian operator (square root + mask)
-               ahmt(:,:,1:jpkm1) = SQRT( ahmt(:,:,1:jpkm1) ) * tmask(:,:,1:jpkm1)
-               ahmf(:,:,1:jpkm1) = SQRT( ahmf(:,:,1:jpkm1) ) * fmask(:,:,1:jpkm1)
-            ENDIF
-         ENDIF
-         !
-      ENDIF
-      !
-   END SUBROUTINE ldf_dyn_init
-
-
-   SUBROUTINE ldf_dyn( kt, Kbb )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE ldf_dyn  ***
-      !! 
-      !! ** Purpose :   update at kt the momentum lateral mixing coeff. (ahmt and ahmf)
-      !!
-      !! ** Method  :   time varying eddy viscosity coefficients:
-      !!
-      !!    nn_ahm_ijk_t = 31    ahmt, ahmf = F(i,j,k,t) = F(local velocity) 
-      !!                         ( |u|e /12  or  |u|e^3/12 for laplacian or bilaplacian operator )
-      !!
-      !!    nn_ahm_ijk_t = 32    ahmt, ahmf = F(i,j,k,t) = F(local deformation rate and gridscale) (D and L) (Smagorinsky)  
-      !!                         ( L^2|D|    or  L^4|D|/8  for laplacian or bilaplacian operator )
-      !!
-      !! ** note    :    in BLP cases the sqrt of the eddy coef is returned, since bilaplacian is en re-entrant laplacian
-      !! ** action  :    ahmt, ahmf   updated at each time step
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! time step index
-      INTEGER, INTENT(in) ::   Kbb  ! ocean time level indices
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zu2pv2_ij_p1, zu2pv2_ij, zu2pv2_ij_m1, zemax   ! local scalar (option 31)
-      REAL(wp) ::   zcmsmag, zstabf_lo, zstabf_up, zdelta, zdb     ! local scalar (option 32)
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_timing )   CALL timing_start('ldf_dyn')
-      !
-      SELECT CASE(  nn_ahm_ijk_t  )       !== Eddy vicosity coefficients ==!
-      !
-      CASE(  31  )       !==  time varying 3D field  ==!   = F( local velocity )
-         !
-         IF( ln_dynldf_lap   ) THEN        ! laplacian operator : |u| e /12 = |u/144| e
-            DO jk = 1, jpkm1
-               DO_2D( 0, 0, 0, 0 )
-                  zu2pv2_ij    = uu(ji  ,jj  ,jk,Kbb) * uu(ji  ,jj  ,jk,Kbb) + vv(ji  ,jj  ,jk,Kbb) * vv(ji  ,jj  ,jk,Kbb)
-                  zu2pv2_ij_m1 = uu(ji-1,jj  ,jk,Kbb) * uu(ji-1,jj  ,jk,Kbb) + vv(ji  ,jj-1,jk,Kbb) * vv(ji  ,jj-1,jk,Kbb)
-                  zemax = MAX( e1t(ji,jj) , e2t(ji,jj) )
-                  ahmt(ji,jj,jk) = SQRT( (zu2pv2_ij + zu2pv2_ij_m1) * r1_288 ) * zemax * tmask(ji,jj,jk)      ! 288= 12*12 * 2
-               END_2D
-               DO_2D( 1, 0, 1, 0 )
-                  zu2pv2_ij_p1 = uu(ji  ,jj+1,jk, Kbb) * uu(ji  ,jj+1,jk, Kbb) + vv(ji+1,jj  ,jk, Kbb) * vv(ji+1,jj  ,jk, Kbb)
-                  zu2pv2_ij    = uu(ji  ,jj  ,jk, Kbb) * uu(ji  ,jj  ,jk, Kbb) + vv(ji  ,jj  ,jk, Kbb) * vv(ji  ,jj  ,jk, Kbb)
-                  zemax = MAX( e1f(ji,jj) , e2f(ji,jj) )
-                  ahmf(ji,jj,jk) = SQRT( (zu2pv2_ij + zu2pv2_ij_p1) * r1_288 ) * zemax * fmask(ji,jj,jk)      ! 288= 12*12 * 2
-               END_2D
-            END DO
-         ELSEIF( ln_dynldf_blp ) THEN      ! bilaplacian operator : sqrt( |u| e^3 /12 ) = sqrt( |u/144| e ) * e
-            DO jk = 1, jpkm1
-               DO_2D( 0, 0, 0, 0 )
-                  zu2pv2_ij    = uu(ji  ,jj  ,jk,Kbb) * uu(ji  ,jj  ,jk,Kbb) + vv(ji  ,jj  ,jk,Kbb) * vv(ji  ,jj  ,jk,Kbb)
-                  zu2pv2_ij_m1 = uu(ji-1,jj  ,jk,Kbb) * uu(ji-1,jj  ,jk,Kbb) + vv(ji  ,jj-1,jk,Kbb) * vv(ji  ,jj-1,jk,Kbb)
-                  zemax = MAX( e1t(ji,jj) , e2t(ji,jj) )
-                  ahmt(ji,jj,jk) = SQRT(  SQRT( (zu2pv2_ij + zu2pv2_ij_m1) * r1_288 ) * zemax  ) * zemax * tmask(ji,jj,jk)
-               END_2D
-               DO_2D( 1, 0, 1, 0 )
-                  zu2pv2_ij_p1 = uu(ji  ,jj+1,jk, Kbb) * uu(ji  ,jj+1,jk, Kbb) + vv(ji+1,jj  ,jk, Kbb) * vv(ji+1,jj  ,jk, Kbb)
-                  zu2pv2_ij    = uu(ji  ,jj  ,jk, Kbb) * uu(ji  ,jj  ,jk, Kbb) + vv(ji  ,jj  ,jk, Kbb) * vv(ji  ,jj  ,jk, Kbb)
-                  zemax = MAX( e1f(ji,jj) , e2f(ji,jj) )
-                  ahmf(ji,jj,jk) = SQRT(  SQRT( (zu2pv2_ij + zu2pv2_ij_p1) * r1_288 ) * zemax  ) * zemax * fmask(ji,jj,jk)
-               END_2D
-            END DO
-         ENDIF
-         !
-         CALL lbc_lnk_multi( 'ldfdyn', ahmt, 'T', 1.,  ahmf, 'F', 1. )
-         !
-         !
-      CASE(  32  )       !==  time varying 3D field  ==!   = F( local deformation rate and gridscale ) (Smagorinsky)
-         !
-         IF( ln_dynldf_lap .OR. ln_dynldf_blp  ) THEN        ! laplacian operator : (C_smag/pi)^2 L^2 |D|
-            !
-            zcmsmag   = (rn_csmc/rpi)**2                                            ! (C_smag/pi)^2
-            zstabf_lo = rn_minfac * rn_minfac / ( 2._wp * 12._wp * 12._wp * zcmsmag ) ! lower limit stability factor scaling
-            zstabf_up = rn_maxfac / ( 4._wp * zcmsmag * 2._wp * rn_Dt )               ! upper limit stability factor scaling
-            IF( ln_dynldf_blp ) zstabf_lo = ( 16._wp / 9._wp ) * zstabf_lo          ! provide |U|L^3/12 lower limit instead 
-            !                                                                       ! of |U|L^3/16 in blp case
-            DO jk = 1, jpkm1
-               !
-               DO_2D( 0, 0, 0, 0 )
-                  zdb =    ( uu(ji,jj,jk,Kbb) * r1_e2u(ji,jj) -  uu(ji-1,jj,jk,Kbb) * r1_e2u(ji-1,jj) )  &
-                       &                      * r1_e1t(ji,jj) * e2t(ji,jj)                           &
-                       & - ( vv(ji,jj,jk,Kbb) * r1_e1v(ji,jj) -  vv(ji,jj-1,jk,Kbb) * r1_e1v(ji,jj-1) )  &
-                       &                      * r1_e2t(ji,jj) * e1t(ji,jj)
-                  dtensq(ji,jj,jk) = zdb * zdb * tmask(ji,jj,jk)
-               END_2D
-               !
-               DO_2D( 1, 0, 1, 0 )
-                  zdb =   (  uu(ji,jj+1,jk,Kbb) * r1_e1u(ji,jj+1) -  uu(ji,jj,jk,Kbb) * r1_e1u(ji,jj) )  &
-                       &                        * r1_e2f(ji,jj)   * e1f(ji,jj)                       &
-                       & + ( vv(ji+1,jj,jk,Kbb) * r1_e2v(ji+1,jj) -  vv(ji,jj,jk,Kbb) * r1_e2v(ji,jj) )  &
-                       &                        * r1_e1f(ji,jj)   * e2f(ji,jj)
-                  dshesq(ji,jj,jk) = zdb * zdb * fmask(ji,jj,jk)
-               END_2D
-               !
-            END DO
-            !
-            CALL lbc_lnk_multi( 'ldfdyn', dtensq, 'T', 1. )  ! lbc_lnk on dshesq not needed
-            !
-            DO jk = 1, jpkm1
-              !
-               DO_2D( 0, 0, 0, 0 )
-                  !
-                  zu2pv2_ij    = uu(ji  ,jj  ,jk,Kbb) * uu(ji  ,jj  ,jk,Kbb) + vv(ji  ,jj  ,jk,Kbb) * vv(ji  ,jj  ,jk,Kbb)
-                  zu2pv2_ij_m1 = uu(ji-1,jj  ,jk,Kbb) * uu(ji-1,jj  ,jk,Kbb) + vv(ji  ,jj-1,jk,Kbb) * vv(ji  ,jj-1,jk,Kbb)
-                  !
-                  zdelta         = zcmsmag * esqt(ji,jj)                                        ! L^2 * (C_smag/pi)^2
-                  ahmt(ji,jj,jk) = zdelta * SQRT(          dtensq(ji  ,jj,jk) +                         &
-                     &                            r1_4 * ( dshesq(ji  ,jj,jk) + dshesq(ji  ,jj-1,jk) +  &
-                     &                                     dshesq(ji-1,jj,jk) + dshesq(ji-1,jj-1,jk) ) )
-                  ahmt(ji,jj,jk) = MAX( ahmt(ji,jj,jk), SQRT( (zu2pv2_ij + zu2pv2_ij_m1) * zdelta * zstabf_lo ) ) ! Impose lower limit == minfac  * |U|L/2
-                  ahmt(ji,jj,jk) = MIN( ahmt(ji,jj,jk),                                    zdelta * zstabf_up )   ! Impose upper limit == maxfac  * L^2/(4*2dt)
-                  !
-               END_2D
-               !
-               DO_2D( 1, 0, 1, 0 )
-                  !
-                  zu2pv2_ij_p1 = uu(ji  ,jj+1,jk, kbb) * uu(ji  ,jj+1,jk, kbb) + vv(ji+1,jj  ,jk, kbb) * vv(ji+1,jj  ,jk, kbb)
-                  zu2pv2_ij    = uu(ji  ,jj  ,jk, kbb) * uu(ji  ,jj  ,jk, kbb) + vv(ji  ,jj  ,jk, kbb) * vv(ji  ,jj  ,jk, kbb)
-                  !
-                  zdelta         = zcmsmag * esqf(ji,jj)                                        ! L^2 * (C_smag/pi)^2
-                  ahmf(ji,jj,jk) = zdelta * SQRT(          dshesq(ji  ,jj,jk) +                         &
-                     &                            r1_4 * ( dtensq(ji  ,jj,jk) + dtensq(ji  ,jj+1,jk) +  &
-                     &                                     dtensq(ji+1,jj,jk) + dtensq(ji+1,jj+1,jk) ) )
-                  ahmf(ji,jj,jk) = MAX( ahmf(ji,jj,jk), SQRT( (zu2pv2_ij + zu2pv2_ij_p1) * zdelta * zstabf_lo ) ) ! Impose lower limit == minfac  * |U|L/2
-                  ahmf(ji,jj,jk) = MIN( ahmf(ji,jj,jk),                                    zdelta * zstabf_up )   ! Impose upper limit == maxfac  * L^2/(4*2dt)
-                  !
-               END_2D
-               !
-            END DO
-            !
-         ENDIF
-         !
-         IF( ln_dynldf_blp ) THEN      ! bilaplacian operator : sqrt( (C_smag/pi)^2 L^4 |D|/8)
-            !                          !                      = sqrt( A_lap_smag L^2/8 )
-            !                          ! stability limits already applied to laplacian values
-            !                          ! effective default limits are 1/12 |U|L^3 < B_hm < 1//(32*2dt) L^4
-            DO jk = 1, jpkm1
-               DO_2D( 0, 0, 0, 0 )
-                  ahmt(ji,jj,jk) = SQRT( r1_8 * esqt(ji,jj) * ahmt(ji,jj,jk) )
-               END_2D
-               DO_2D( 1, 0, 1, 0 )
-                  ahmf(ji,jj,jk) = SQRT( r1_8 * esqf(ji,jj) * ahmf(ji,jj,jk) )
-               END_2D
-            END DO
-            !
-         ENDIF
-         !
-         CALL lbc_lnk_multi( 'ldfdyn', ahmt, 'T', 1. , ahmf, 'F', 1. )
-         !
-      END SELECT
-      !
-      CALL iom_put( "ahmt_2d", ahmt(:,:,1) )   ! surface u-eddy diffusivity coeff.
-      CALL iom_put( "ahmf_2d", ahmf(:,:,1) )   ! surface v-eddy diffusivity coeff.
-      CALL iom_put( "ahmt_3d", ahmt(:,:,:) )   ! 3D      u-eddy diffusivity coeff.
-      CALL iom_put( "ahmf_3d", ahmf(:,:,:) )   ! 3D      v-eddy diffusivity coeff.
-      !
-      IF( ln_timing )   CALL timing_stop('ldf_dyn')
-      !
-   END SUBROUTINE ldf_dyn
-
-   !!======================================================================
-END MODULE ldfdyn
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/phycst.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/phycst.F90	(revision 13603)
+++ 	(revision )
@@ -1,148 +1,0 @@
-MODULE phycst
-   !!======================================================================
-   !!                    ***  MODULE  phycst  ***
-   !!     Definition of of both ocean and ice parameters used in the code
-   !!=====================================================================
-   !! History :   OPA  !  1990-10  (C. Levy - G. Madec)  Original code
-   !!             8.1  !  1991-11  (G. Madec, M. Imbard)  cosmetic changes
-   !!   NEMO      1.0  !  2002-08  (G. Madec, C. Ethe)  F90, add ice constants
-   !!              -   !  2006-08  (G. Madec)  style 
-   !!             3.2  !  2006-08  (S. Masson, G. Madec)  suppress useless variables + style 
-   !!             3.4  !  2011-11  (C. Harris)  minor changes for CICE constants 
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   phy_cst  : define and print physical constant and domain parameters
-   !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE in_out_manager   ! I/O manager 
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   phy_cst     ! routine called by inipar.F90
-
-   REAL(wp), PUBLIC ::   rpi      = 3.141592653589793_wp             !: pi
-   REAL(wp), PUBLIC ::   rad      = 3.141592653589793_wp / 180._wp   !: conversion from degre into radian
-   REAL(wp), PUBLIC ::   rsmall   = 0.5 * EPSILON( 1.e0 )            !: smallest real computer value
-   
-   REAL(wp), PUBLIC ::   rday     = 24.*60.*60.      !: day                                [s]
-   REAL(wp), PUBLIC ::   rsiyea                      !: sideral year                       [s]
-   REAL(wp), PUBLIC ::   rsiday                      !: sideral day                        [s]
-   REAL(wp), PUBLIC ::   raamo    =  12._wp          !: number of months in one year
-   REAL(wp), PUBLIC ::   rjjhh    =  24._wp          !: number of hours in one day
-   REAL(wp), PUBLIC ::   rhhmm    =  60._wp          !: number of minutes in one hour
-   REAL(wp), PUBLIC ::   rmmss    =  60._wp          !: number of seconds in one minute
-   REAL(wp), PUBLIC ::   omega                       !: earth rotation parameter           [s-1]
-   REAL(wp), PUBLIC ::   ra       = 6371229._wp      !: earth radius                       [m]
-   REAL(wp), PUBLIC ::   grav     = 9.80665_wp       !: gravity                            [m/s2]   
-   REAL(wp), PUBLIC ::   rt0      = 273.15_wp        !: freezing point of fresh water [Kelvin]
-
-   REAL(wp), PUBLIC ::   rho0                        !: volumic mass of reference     [kg/m3]
-   REAL(wp), PUBLIC ::   r1_rho0                     !: = 1. / rho0                   [m3/kg]
-   REAL(wp), PUBLIC ::   rcp                         !: ocean specific heat           [J/Kelvin]
-   REAL(wp), PUBLIC ::   r1_rcp                      !: = 1. / rcp                    [Kelvin/J]
-   REAL(wp), PUBLIC ::   rho0_rcp                    !: = rho0 * rcp 
-   REAL(wp), PUBLIC ::   r1_rho0_rcp                 !: = 1. / ( rho0 * rcp )
-
-   REAL(wp), PUBLIC ::   emic     =    0.97_wp       !: emissivity of snow or ice (not used?)
-
-   REAL(wp), PUBLIC ::   sice     =    6.0_wp        !: salinity of ice (for pisces)          [psu]
-   REAL(wp), PUBLIC ::   soce     =   34.7_wp        !: salinity of sea (for pisces and isf)  [psu]
-   REAL(wp), PUBLIC ::   rLevap   =    2.5e+6_wp     !: latent heat of evaporation (water)
-   REAL(wp), PUBLIC ::   vkarmn   =    0.4_wp        !: von Karman constant
-   REAL(wp), PUBLIC ::   stefan   =    5.67e-8_wp    !: Stefan-Boltzmann constant 
-
-   REAL(wp), PUBLIC ::   rhos     =  330._wp         !: volumic mass of snow                                  [kg/m3]
-   REAL(wp), PUBLIC ::   rhoi     =  917._wp         !: volumic mass of sea ice                               [kg/m3]
-   REAL(wp), PUBLIC ::   rhow     = 1000._wp         !: volumic mass of freshwater in melt ponds              [kg/m3]
-   REAL(wp), PUBLIC ::   rcnd_i   =    2.034396_wp   !: thermal conductivity of fresh ice                     [W/m/K]
-   REAL(wp), PUBLIC ::   rcpi     = 2067.0_wp        !: specific heat of fresh ice                            [J/kg/K]
-   REAL(wp), PUBLIC ::   rLsub    =    2.834e+6_wp   !: pure ice latent heat of sublimation                   [J/kg]
-   REAL(wp), PUBLIC ::   rLfus    =    0.334e+6_wp   !: latent heat of fusion of fresh ice                    [J/kg]
-   REAL(wp), PUBLIC ::   rTmlt    =    0.054_wp      !: decrease of seawater meltpoint with salinity
-
-   REAL(wp), PUBLIC ::   r1_rhoi                     !: 1 / rhoi
-   REAL(wp), PUBLIC ::   r1_rhos                     !: 1 / rhos
-   REAL(wp), PUBLIC ::   r1_rcpi                     !: 1 / rcpi
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: phycst.F90 12614 2020-03-26 14:59:52Z gm $ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-   
-CONTAINS
-   
-   SUBROUTINE phy_cst
-      !!----------------------------------------------------------------------
-      !!                       ***  ROUTINE phy_cst  ***
-      !!
-      !! ** Purpose :   set and print the constants
-      !!----------------------------------------------------------------------
-
-      rsiyea = 365.25_wp * rday * 2._wp * rpi / 6.283076_wp
-      rsiday = rday / ( 1._wp + rday / rsiyea )
-#if defined key_cice
-      omega  = 7.292116e-05
-#else
-      omega  = 2._wp * rpi / rsiday 
-#endif
-
-      r1_rhoi = 1._wp / rhoi
-      r1_rhos = 1._wp / rhos
-      r1_rcpi = 1._wp / rcpi
-      !
-      rho0        = 1026._wp                 !: volumic mass of reference     [kg/m3]
-      rcp         = 3991.86795711963_wp      !: heat capacity     [J/K]
-      !
-      rho0_rcp    = rho0 * rcp 
-      r1_rho0     = 1._wp / rho0
-      r1_rcp      = 1._wp / rcp
-      r1_rho0_rcp = 1._wp / rho0_rcp 
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'phy_cst : initialization of ocean parameters and constants'
-         WRITE(numout,*) '~~~~~~~'
-         WRITE(numout,*) '      mathematical constant                 rpi = ', rpi
-         WRITE(numout,*) '      day                                rday   = ', rday,   ' s'
-         WRITE(numout,*) '      sideral year                       rsiyea = ', rsiyea, ' s'
-         WRITE(numout,*) '      sideral day                        rsiday = ', rsiday, ' s'
-         WRITE(numout,*) '      omega                              omega  = ', omega,  ' s^-1'
-         WRITE(numout,*)
-         WRITE(numout,*) '      nb of months per year               raamo = ', raamo, ' months'
-         WRITE(numout,*) '      nb of hours per day                 rjjhh = ', rjjhh, ' hours'
-         WRITE(numout,*) '      nb of minutes per hour              rhhmm = ', rhhmm, ' mn'
-         WRITE(numout,*) '      nb of seconds per minute            rmmss = ', rmmss, ' s'
-         WRITE(numout,*)
-         WRITE(numout,*) '      earth radius                         ra   = ', ra   , ' m'
-         WRITE(numout,*) '      gravity                              grav = ', grav , ' m/s^2'
-         WRITE(numout,*)
-         WRITE(numout,*) '      freezing point of water              rt0  = ', rt0  , ' K'
-         WRITE(numout,*)
-         WRITE(numout,*) '   reference density and heat capacity now defined in eosbn2.f90'
-         WRITE(numout,*)
-         WRITE(numout,*) '      thermal conductivity of pure ice          = ', rcnd_i  , ' J/s/m/K'
-         WRITE(numout,*) '      thermal conductivity of snow is defined in a namelist '
-         WRITE(numout,*) '      fresh ice specific heat                   = ', rcpi    , ' J/kg/K'
-         WRITE(numout,*) '      latent heat of fusion of fresh ice / snow = ', rLfus   , ' J/kg'
-         WRITE(numout,*) '      latent heat of subl.  of fresh ice / snow = ', rLsub   , ' J/kg'
-         WRITE(numout,*) '      density of sea ice                        = ', rhoi    , ' kg/m^3'
-         WRITE(numout,*) '      density of snow                           = ', rhos    , ' kg/m^3'
-         WRITE(numout,*) '      density of freshwater (in melt ponds)     = ', rhow    , ' kg/m^3'
-         WRITE(numout,*) '      salinity of ice (for pisces)              = ', sice    , ' psu'
-         WRITE(numout,*) '      salinity of sea (for pisces and isf)      = ', soce    , ' psu'
-         WRITE(numout,*) '      latent heat of evaporation (water)        = ', rLevap  , ' J/m^3' 
-         WRITE(numout,*) '      von Karman constant                       = ', vkarmn 
-         WRITE(numout,*) '      Stefan-Boltzmann constant                 = ', stefan  , ' J/s/m^2/K^4'
-         WRITE(numout,*)
-         WRITE(numout,*) '      conversion: degre ==> radian          rad = ', rad
-         WRITE(numout,*)
-         WRITE(numout,*) '      smallest real computer value       rsmall = ', rsmall
-      ENDIF
-
-   END SUBROUTINE phy_cst
-
-   !!======================================================================
-END MODULE phycst
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/restart.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/restart.F90	(revision 13604)
+++ NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/restart.F90	(revision 13604)
@@ -0,0 +1,279 @@
+MODULE restart
+   !!======================================================================
+   !!                     ***  MODULE  restart  ***
+   !! Ocean restart :  write the ocean restart file
+   !!======================================================================
+   !! History :  OPA  !  1999-11  (M. Imbard)  Original code
+   !!   NEMO     1.0  !  2002-08  (G. Madec)  F90: Free form
+   !!            2.0  !  2006-07  (S. Masson)  use IOM for restart
+   !!            3.3  !  2010-04  (M. Leclair, G. Madec)  modified LF-RA
+   !!            - -  !  2010-10  (C. Ethe, G. Madec) TRC-TRA merge (T-S in 4D)
+   !!            3.7  !  2014-01  (G. Madec) suppression of curl and hdiv from the restart
+   !!             -   !  2014-12  (G. Madec) remove KPP scheme
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   rst_opn    : open the ocean restart file
+   !!   rst_write  : write the ocean restart file
+   !!   rst_read   : read the ocean restart file
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE sbc_ice         ! only lk_si3 
+   USE phycst          ! physical constants
+!!st   USE eosbn2          ! equation of state            (eos bn2 routine)
+!!st   USE trdmxl_oce      ! ocean active mixed layer tracers trends variables
+   !
+   USE in_out_manager  ! I/O manager
+   USE iom             ! I/O module
+   USE diu_bulk
+   USE lib_mpp         ! distribued memory computing library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   rst_opn         ! routine called by step module
+   PUBLIC   rst_write       ! routine called by step module
+   PUBLIC   rst_read        ! routine called by istate module
+   PUBLIC   rst_read_open   ! routine called in rst_read and (possibly) in dom_vvl_init
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id: restart.F90 13427 2020-08-21 16:26:57Z techene $
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE rst_opn( kt )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE rst_opn  ***
+      !!                     
+      !! ** Purpose : + initialization (should be read in the namelist) of nitrst 
+      !!              + open the restart when we are one time step before nitrst
+      !!                   - restart header is defined when kt = nitrst-1
+      !!                   - restart data  are written when kt = nitrst
+      !!              + define lrst_oce to .TRUE. when we need to define or write the restart
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! ocean time-step
+      !!
+      CHARACTER(LEN=20)   ::   clkt      ! ocean time-step deine as a character
+      CHARACTER(LEN=50)   ::   clname    ! ocean output restart file name
+      CHARACTER(lc)       ::   clpath    ! full path to ocean output restart file
+      CHARACTER(LEN=52)   ::   clpname   ! ocean output restart file name including prefix for AGRIF
+      CHARACTER(LEN=256)  ::   clinfo    ! info character
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 ) THEN   ! default definitions
+         lrst_oce = .FALSE.   
+         IF( ln_rst_list ) THEN
+            nrst_lst = 1
+            nitrst = nn_stocklist( nrst_lst )
+         ELSE
+            nitrst = nitend
+         ENDIF
+      ENDIF
+      
+      IF( .NOT. ln_rst_list .AND. nn_stock == -1 )   RETURN   ! we will never do any restart
+
+      ! frequency-based restart dumping (nn_stock)
+      IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nn_stock ) == 0 ) THEN   
+         ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
+         nitrst = kt + nn_stock - 1                  ! define the next value of nitrst for restart writing
+         IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
+      ENDIF
+      ! to get better performances with NetCDF format:
+      ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1)
+      ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1
+      IF( kt == nitrst - 1 .OR. nn_stock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN
+         IF( nitrst <= nitend .AND. nitrst > 0 ) THEN 
+            ! beware of the format used to write kt (default is i8.8, that should be large enough...)
+            IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
+            ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
+            ENDIF
+            ! create the file
+            clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_ocerst_out)
+            clpath = TRIM(cn_ocerst_outdir)
+            IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
+            IF(lwp) THEN
+               WRITE(numout,*)
+               IF(.NOT.lwxios) THEN
+                  WRITE(numout,*) '             open ocean restart NetCDF file: ',TRIM(clpath)//TRIM(clname)
+                  IF ( snc4set%luse )      WRITE(numout,*) '             opened for NetCDF4 chunking and compression'
+                  IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt
+                  ELSE                          ;   WRITE(numout,*) '             kt = '             , kt
+                  ENDIF
+               ENDIF
+            ENDIF
+            !
+            IF(.NOT.lwxios) THEN
+               CALL iom_open( TRIM(clpath)//TRIM(clname), numrow, ldwrt = .TRUE. )
+            ELSE
+#if defined key_iomput
+               cwxios_context = "rstw_"//TRIM(ADJUSTL(clkt))
+               IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+                  clpname = clname
+               ELSE
+                  clpname = TRIM(Agrif_CFixed())//"_"//clname   
+               ENDIF
+               CALL iom_init( cwxios_context, TRIM(clpath)//TRIM(clpname), .false. )
+               CALL xios_update_calendar(nitrst)
+               CALL iom_swap(      cxios_context          )
+#else
+               clinfo = 'Can not use XIOS in rst_opn'
+               CALL ctl_stop(TRIM(clinfo))
+#endif
+            ENDIF
+            lrst_oce = .TRUE.
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE rst_opn
+
+
+   SUBROUTINE rst_write( kt, Kbb, Kmm )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE rstwrite  ***
+      !!                     
+      !! ** Purpose :   Write restart fields in NetCDF format
+      !!
+      !! ** Method  :   Write in numrow when kt == nitrst in NetCDF
+      !!              file, save fields which are necessary for restart
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt         ! ocean time-step
+      INTEGER, INTENT(in) ::   Kbb, Kmm   ! ocean time level indices
+      !!----------------------------------------------------------------------
+      IF(lwxios) CALL iom_swap(      cwxios_context          )
+      CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rn_Dt       , ldxios = lwxios)   ! dynamics time step
+      CALL iom_delay_rst( 'WRITE', 'OCE', numrow )   ! save only ocean delayed global communication variables
+      
+      CALL iom_rstput( kt, nitrst, numrow, 'ub'  , uu(:,:,:,Kbb), ldxios = lwxios )     ! before fields
+      CALL iom_rstput( kt, nitrst, numrow, 'vb'  , vv(:,:,:,Kbb), ldxios = lwxios )
+      CALL iom_rstput( kt, nitrst, numrow, 'sshb',ssh(:,:  ,Kbb), ldxios = lwxios )
+      !
+      CALL iom_rstput( kt, nitrst, numrow, 'un'  , uu(:,:,:,Kmm), ldxios = lwxios )     ! now fields
+      CALL iom_rstput( kt, nitrst, numrow, 'vn'  , vv(:,:,:,Kmm), ldxios = lwxios )
+      CALL iom_rstput( kt, nitrst, numrow, 'sshn',ssh(:,:  ,Kmm), ldxios = lwxios )
+      
+      IF(lwxios) CALL iom_swap(      cxios_context          )
+      IF( kt == nitrst ) THEN
+         IF(.NOT.lwxios) THEN
+            CALL iom_close( numrow )     ! close the restart file (only at last time step)
+         ELSE
+            CALL iom_context_finalize(      cwxios_context          )
+         ENDIF
+         lrst_oce = .FALSE.
+         IF( ln_rst_list ) THEN
+            nrst_lst = MIN(nrst_lst + 1, SIZE(nn_stocklist,1))
+            nitrst = nn_stocklist( nrst_lst )
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE rst_write
+
+
+   SUBROUTINE rst_read_open
+      !!---------------------------------------------------------------------- 
+      !!                   ***  ROUTINE rst_read_open  ***
+      !! 
+      !! ** Purpose :   Open read files for NetCDF restart
+      !! 
+      !! ** Method  :   Use a non-zero, positive value of numror to assess whether or not
+      !!                the file has already been opened
+      !!----------------------------------------------------------------------
+      LOGICAL        ::   llok
+      CHARACTER(lc)  ::   clpath   ! full path to ocean output restart file
+      !!----------------------------------------------------------------------
+      !
+      IF( numror <= 0 ) THEN
+         IF(lwp) THEN                                             ! Contol prints
+            WRITE(numout,*)
+            WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
+            IF ( snc4set%luse )      WRITE(numout,*) 'rst_read : configured with NetCDF4 support'
+            WRITE(numout,*) '~~~~~~~~'
+         ENDIF
+         lxios_sini = .FALSE.
+         clpath = TRIM(cn_ocerst_indir)
+         IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
+         CALL iom_open( TRIM(clpath)//cn_ocerst_in, numror )
+! are we using XIOS to read the data? Part above will have to modified once XIOS
+! can handle checking if variable is in the restart file (there will be no need to open
+! restart)
+         IF(.NOT.lxios_set) lrxios = lrxios.AND.lxios_sini
+         IF( lrxios) THEN
+             crxios_context = 'nemo_rst'
+             IF( .NOT.lxios_set ) THEN
+                 IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS'
+                 CALL iom_init( crxios_context )
+                 lxios_set = .TRUE.
+             ENDIF
+         ENDIF
+         IF( TRIM(Agrif_CFixed()) /= '0' .AND. lrxios) THEN
+             CALL iom_init( crxios_context )
+             IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for AGRIF'
+             lxios_set = .TRUE.
+         ENDIF 
+      ENDIF
+
+   END SUBROUTINE rst_read_open
+
+
+   SUBROUTINE rst_read( Kbb, Kmm )
+      !!---------------------------------------------------------------------- 
+      !!                   ***  ROUTINE rst_read  ***
+      !! 
+      !! ** Purpose :   Read files for NetCDF restart
+      !! 
+      !! ** Method  :   Read in restart.nc file fields which are necessary for restart
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kbb, Kmm   ! ocean time level indices
+      REAL(wp) ::   zrdt
+      INTEGER  ::   jk
+      REAL(wp), DIMENSION(jpi, jpj, jpk) :: w3d
+      !!----------------------------------------------------------------------
+
+      CALL rst_read_open           ! open restart for reading (if not already opened)
+
+      ! Check dynamics and tracer time-step consistency and force Euler restart if changed
+      IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
+         CALL iom_get( numror, 'rdt', zrdt, ldxios = lrxios )
+         IF( zrdt /= rn_Dt ) THEN
+            IF(lwp) WRITE( numout,*)
+            IF(lwp) WRITE( numout,*) 'rst_read:  rdt not equal to the read one'
+            IF(lwp) WRITE( numout,*)
+            IF(lwp) WRITE( numout,*) '      ==>>>   forced euler first time-step'
+            l_1st_euler =  .TRUE.
+         ENDIF
+      ENDIF
+
+      CALL iom_delay_rst( 'READ', 'OCE', numror )   ! read only ocean delayed global communication variables
+      
+      IF( iom_varid( numror, 'ub', ldstop = .FALSE. ) > 0 ) THEN
+         ! before fields
+         CALL iom_get( numror, jpdom_auto, 'ub'     , uu(:,:,:       ,Kbb), ldxios = lrxios, cd_type = 'U', psgn = -1._wp )
+         CALL iom_get( numror, jpdom_auto, 'vb'     , vv(:,:,:       ,Kbb), ldxios = lrxios, cd_type = 'V', psgn = -1._wp )
+#if ! defined key_qco
+         CALL iom_get( numror, jpdom_auto, 'sshb'   ,ssh(:,:         ,Kbb), ldxios = lrxios )
+#endif
+      ELSE
+         l_1st_euler =  .TRUE.      ! before field not found, forced euler 1st time-step
+      ENDIF
+      !
+      ! now fields
+      CALL iom_get( numror, jpdom_auto, 'un'     , uu(:,:,:       ,Kmm), ldxios = lrxios, cd_type = 'U', psgn = -1._wp )
+      CALL iom_get( numror, jpdom_auto, 'vn'     , vv(:,:,:       ,Kmm), ldxios = lrxios, cd_type = 'V', psgn = -1._wp )
+#if ! defined key_qco
+      CALL iom_get( numror, jpdom_auto, 'sshn'   ,ssh(:,:         ,Kmm), ldxios = lrxios )
+#endif
+      !
+      IF( l_1st_euler ) THEN                                  ! Euler restart 
+         uu   (:,:,:  ,Kbb) = uu   (:,:,:  ,Kmm)              ! all before fields set to now values
+         vv   (:,:,:  ,Kbb) = vv   (:,:,:  ,Kmm)
+         ssh  (:,:    ,Kbb) = ssh  (:,:    ,Kmm)
+      ENDIF
+      !
+      ww (:,:,:) = 0._wp !!st  gm is right 3D only !! 
+      !
+   END SUBROUTINE rst_read
+
+   !!=====================================================================
+END MODULE restart
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/sbcice_cice.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/sbcice_cice.F90	(revision 13603)
+++ 	(revision )
@@ -1,1060 +1,0 @@
-MODULE sbcice_cice
-   !!======================================================================
-   !!                       ***  MODULE  sbcice_cice  ***
-   !! To couple with sea ice model CICE (LANL)
-   !!=====================================================================
-#if defined key_cice
-   !!----------------------------------------------------------------------
-   !!   'key_cice' :                                     CICE sea-ice model
-   !!----------------------------------------------------------------------
-   !!   sbc_ice_cice  : sea-ice model time-stepping and update ocean sbc over ice-covered area
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-!!st8
-# if ! defined key_qco
-   USE domvvl
-# else
-   USE domqco
-# endif
-!!st8
-   USE phycst, only : rcp, rho0, r1_rho0, rhos, rhoi
-   USE in_out_manager  ! I/O manager
-   USE iom, ONLY : iom_put,iom_use              ! I/O manager library !!Joakim edit
-   USE lib_mpp         ! distributed memory computing library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE daymod          ! calendar
-   USE fldread         ! read input fields
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice   fields
-   USE sbcblk          ! Surface boundary condition: bulk
-   USE sbccpl
-
-   USE ice_kinds_mod
-   USE ice_blocks
-   USE ice_domain
-   USE ice_domain_size
-   USE ice_boundary
-   USE ice_constants
-   USE ice_gather_scatter
-   USE ice_calendar, only: dt
-   USE ice_state, only: aice,aicen,uvel,vvel,vsno,vsnon,vice,vicen
-# if defined key_cice4
-   USE ice_flux, only: strax,stray,strocnx,strocny,frain,fsnow,  &
-                strocnxT,strocnyT,                               & 
-                sst,sss,uocn,vocn,ss_tltx,ss_tlty,fsalt_gbm,     &
-                fresh_gbm,fhocn_gbm,fswthru_gbm,frzmlt,          &
-                flatn_f,fsurfn_f,fcondtopn_f,                    &
-                uatm,vatm,wind,fsw,flw,Tair,potT,Qa,rhoa,zlvl,   &
-                swvdr,swvdf,swidr,swidf
-   USE ice_therm_vertical, only: calc_Tsfc
-#else
-   USE ice_flux, only: strax,stray,strocnx,strocny,frain,fsnow,  &
-                strocnxT,strocnyT,                               & 
-                sst,sss,uocn,vocn,ss_tltx,ss_tlty,fsalt_ai,     &
-                fresh_ai,fhocn_ai,fswthru_ai,frzmlt,          &
-                flatn_f,fsurfn_f,fcondtopn_f,                    &
-                uatm,vatm,wind,fsw,flw,Tair,potT,Qa,rhoa,zlvl,   &
-                swvdr,swvdf,swidr,swidf
-   USE ice_therm_shared, only: calc_Tsfc
-#endif
-   USE ice_forcing, only: frcvdr,frcvdf,frcidr,frcidf
-   USE ice_atmo, only: calc_strair
-
-   USE CICE_InitMod
-   USE CICE_RunMod
-   USE CICE_FinalMod
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC cice_sbc_init   ! routine called by sbc_init
-   PUBLIC cice_sbc_final  ! routine called by sbc_final
-   PUBLIC sbc_ice_cice    ! routine called by sbc
-
-   INTEGER             ::   ji_off
-   INTEGER             ::   jj_off
-
-   INTEGER , PARAMETER ::   jpfld   = 13   ! maximum number of files to read 
-   INTEGER , PARAMETER ::   jp_snow = 1    ! index of snow file
-   INTEGER , PARAMETER ::   jp_rain = 2    ! index of rain file
-   INTEGER , PARAMETER ::   jp_sblm = 3    ! index of sublimation file
-   INTEGER , PARAMETER ::   jp_top1 = 4    ! index of category 1 topmelt file
-   INTEGER , PARAMETER ::   jp_top2 = 5    ! index of category 2 topmelt file
-   INTEGER , PARAMETER ::   jp_top3 = 6    ! index of category 3 topmelt file
-   INTEGER , PARAMETER ::   jp_top4 = 7    ! index of category 4 topmelt file
-   INTEGER , PARAMETER ::   jp_top5 = 8    ! index of category 5 topmelt file
-   INTEGER , PARAMETER ::   jp_bot1 = 9    ! index of category 1 botmelt file
-   INTEGER , PARAMETER ::   jp_bot2 = 10   ! index of category 2 botmelt file
-   INTEGER , PARAMETER ::   jp_bot3 = 11   ! index of category 3 botmelt file
-   INTEGER , PARAMETER ::   jp_bot4 = 12   ! index of category 4 botmelt file
-   INTEGER , PARAMETER ::   jp_bot5 = 13   ! index of category 5 botmelt file
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf    ! structure of input fields (file informations, fields read)
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:), PRIVATE ::   png     ! local array used in sbc_cice_ice
-
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: sbcice_cice.F90 12614 2020-03-26 14:59:52Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION sbc_ice_cice_alloc()
-      !!----------------------------------------------------------------------
-      !!                ***  FUNCTION sbc_ice_cice_alloc  ***
-      !!----------------------------------------------------------------------
-      ALLOCATE( png(jpi,jpj,jpnij), STAT=sbc_ice_cice_alloc )
-      CALL mpp_sum ( 'sbcice_cice', sbc_ice_cice_alloc )
-      IF( sbc_ice_cice_alloc > 0 )   CALL ctl_warn('sbc_ice_cice_alloc: allocation of arrays failed.')
-   END FUNCTION sbc_ice_cice_alloc
-
-   SUBROUTINE sbc_ice_cice( kt, ksbc )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE sbc_ice_cice  ***
-      !!                   
-      !! ** Purpose :   update the ocean surface boundary condition via the 
-      !!                CICE Sea Ice Model time stepping 
-      !!
-      !! ** Method  : - Get any extra forcing fields for CICE  
-      !!              - Prepare forcing fields
-      !!              - CICE model time stepping
-      !!              - call the routine that computes mass and 
-      !!                heat fluxes at the ice/ocean interface
-      !!
-      !! ** Action  : - time evolution of the CICE sea-ice model
-      !!              - update all sbc variables below sea-ice:
-      !!                utau, vtau, qns , qsr, emp , sfx
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt      ! ocean time step
-      INTEGER, INTENT(in) ::   ksbc    ! surface forcing type
-      !!----------------------------------------------------------------------
-      !
-      !                                        !----------------------!
-      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN     !  Ice time-step only  !
-         !                                     !----------------------!
-
-         ! Make sure any fluxes required for CICE are set
-         IF      ( ksbc == jp_flx ) THEN
-            CALL cice_sbc_force(kt)
-         ELSE IF( ksbc == jp_purecpl ) THEN
-            CALL sbc_cpl_ice_flx( fr_i )
-         ENDIF
-
-         CALL cice_sbc_in  ( kt, ksbc )
-         CALL CICE_Run
-         CALL cice_sbc_out ( kt, ksbc )
-
-         IF( ksbc == jp_purecpl )  CALL cice_sbc_hadgam(kt+1)
-
-      ENDIF                                          ! End sea-ice time step only
-      !
-   END SUBROUTINE sbc_ice_cice
-
-
-   SUBROUTINE cice_sbc_init( ksbc, Kbb, Kmm )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE cice_sbc_init  ***
-      !! ** Purpose: Initialise ice related fields for NEMO and coupling
-      !!
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT( in  ) ::   ksbc                ! surface forcing type
-      INTEGER, INTENT( in  ) ::   Kbb, Kmm            ! time level indices
-      REAL(wp), DIMENSION(jpi,jpj) :: ztmp1, ztmp2
-      REAL(wp) ::   zcoefu, zcoefv, zcoeff            ! local scalar
-      INTEGER  ::   ji, jj, jl, jk                    ! dummy loop indices
-      !!---------------------------------------------------------------------
-      !
-      IF(lwp) WRITE(numout,*)'cice_sbc_init'
-
-      ji_off = INT ( (jpiglo - nx_global) / 2 )
-      jj_off = INT ( (jpjglo - ny_global) / 2 )
-
-#if defined key_nemocice_decomp
-      ! Pass initial SST from NEMO to CICE so ice is initialised correctly if
-      ! there is no restart file.
-      ! Values from a CICE restart file would overwrite this
-      IF( .NOT. ln_rstart ) THEN    
-         CALL nemo2cice( ts(:,:,1,jp_tem,Kmm) , sst , 'T' , 1.) 
-      ENDIF  
-#endif
-
-! Initialize CICE
-      CALL CICE_Initialize
-
-! Do some CICE consistency checks
-      IF( (ksbc == jp_flx) .OR. (ksbc == jp_purecpl) ) THEN
-         IF( calc_strair .OR. calc_Tsfc ) THEN
-            CALL ctl_stop( 'STOP', 'cice_sbc_init : Forcing option requires calc_strair=F and calc_Tsfc=F in ice_in' )
-         ENDIF
-      ELSEIF(ksbc == jp_blk) THEN
-         IF( .NOT. (calc_strair .AND. calc_Tsfc) ) THEN
-            CALL ctl_stop( 'STOP', 'cice_sbc_init : Forcing option requires calc_strair=T and calc_Tsfc=T in ice_in' )
-         ENDIF
-      ENDIF
-
-
-! allocate sbc_ice and sbc_cice arrays
-      IF( sbc_ice_alloc()      /= 0 )   CALL ctl_stop( 'STOP', 'sbc_ice_cice_alloc : unable to allocate arrays' )
-      IF( sbc_ice_cice_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'sbc_ice_cice_alloc : unable to allocate cice arrays' )
-
-! Ensure ocean temperatures are nowhere below freezing if not a NEMO restart
-      IF( .NOT. ln_rstart ) THEN
-         ts(:,:,:,jp_tem,Kmm) = MAX (ts(:,:,:,jp_tem,Kmm),Tocnfrz)
-         ts(:,:,:,jp_tem,Kbb) = ts(:,:,:,jp_tem,Kmm)
-      ENDIF
-
-      fr_iu(:,:)=0.0
-      fr_iv(:,:)=0.0
-
-      CALL cice2nemo(aice,fr_i, 'T', 1. )
-      IF( (ksbc == jp_flx) .OR. (ksbc == jp_purecpl) ) THEN
-         DO jl=1,ncat
-            CALL cice2nemo(aicen(:,:,jl,:),a_i(:,:,jl), 'T', 1. )
-         ENDDO
-      ENDIF
-
-! T point to U point
-! T point to V point
-      DO_2D( 1, 0, 1, 0 )
-         fr_iu(ji,jj)=0.5*(fr_i(ji,jj)+fr_i(ji+1,jj))*umask(ji,jj,1)
-         fr_iv(ji,jj)=0.5*(fr_i(ji,jj)+fr_i(ji,jj+1))*vmask(ji,jj,1)
-      END_2D
-
-      CALL lbc_lnk_multi( 'sbcice_cice', fr_iu , 'U', 1.,  fr_iv , 'V', 1. )
-
-      ! set the snow+ice mass
-      CALL cice2nemo(vsno(:,:,:),ztmp1,'T', 1. )
-      CALL cice2nemo(vice(:,:,:),ztmp2,'T', 1. )
-      snwice_mass  (:,:) = ( rhos * ztmp1(:,:) + rhoi * ztmp2(:,:)  )
-      snwice_mass_b(:,:) = snwice_mass(:,:)
-
-      IF( .NOT.ln_rstart ) THEN
-         IF( ln_ice_embd ) THEN            ! embedded sea-ice: deplete the initial ssh below sea-ice area
-            ssh(:,:,Kmm) = ssh(:,:,Kmm) - snwice_mass(:,:) * r1_rho0
-            ssh(:,:,Kbb) = ssh(:,:,Kbb) - snwice_mass(:,:) * r1_rho0
-
-!!gm This should be put elsewhere....   (same remark for limsbc)
-!!gm especially here it is assumed zstar coordinate, but it can be ztilde....
-!!st9
-#if defined key_qco
-            IF( .NOT.ln_linssh )   CALL dom_qco_zgr( Kbb, Kmm, Kaa )   ! interpolation scale factor, depth and water column
-#else
-            IF( .NOT.ln_linssh ) THEN
-               !
-               DO jk = 1,jpkm1                     ! adjust initial vertical scale factors
-                  e3t(:,:,jk,Kmm) = e3t_0(:,:,jk)*( 1._wp + ssh(:,:,Kmm)*r1_ht_0(:,:)*tmask(:,:,jk) )
-                  e3t(:,:,jk,Kbb) = e3t_0(:,:,jk)*( 1._wp + ssh(:,:,Kbb)*r1_ht_0(:,:)*tmask(:,:,jk) )
-               END DO
-               e3t(:,:,:,Krhs) = e3t(:,:,:,Kbb)
-               ! Reconstruction of all vertical scale factors at now and before time-steps
-               ! =============================================================================
-               ! Horizontal scale factor interpolations
-               ! --------------------------------------
-               CALL dom_vvl_interpol( ssh(:,:,Kbb), e3u(:,:,:,Kbb), 'U' )
-               CALL dom_vvl_interpol( ssh(:,:,Kbb), e3v(:,:,:,Kbb), 'V' )
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), e3u(:,:,:,Kmm), 'U' )
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), e3v(:,:,:,Kmm), 'V' )
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), e3f(:,:,:), 'F' )
-               ! Vertical scale factor interpolations
-               ! ------------------------------------
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), e3w (:,:,:,Kmm), 'W'  )
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )
-               CALL dom_vvl_interpol( ssh(:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-               CALL dom_vvl_interpol( ssh(:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-               ! t- and w- points depth
-               ! ----------------------
-               gdept(:,:,1,Kmm) = 0.5_wp * e3w(:,:,1,Kmm)
-               gdepw(:,:,1,Kmm) = 0.0_wp
-               gde3w(:,:,1)     = gdept(:,:,1,Kmm) - ssh(:,:,Kmm)
-               DO jk = 2, jpk
-                  gdept(:,:,jk,Kmm) = gdept(:,:,jk-1,Kmm) + e3w(:,:,jk,Kmm)
-                  gdepw(:,:,jk,Kmm) = gdepw(:,:,jk-1,Kmm) + e3t(:,:,jk-1,Kmm)
-                  gde3w(:,:,jk)     = gdept(:,:,jk  ,Kmm) - sshn   (:,:)
-               END DO
-            ENDIF
-#endif
-!!st9
-         ENDIF
-      ENDIF
-      !
-   END SUBROUTINE cice_sbc_init
-
-   
-   SUBROUTINE cice_sbc_in( kt, ksbc )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE cice_sbc_in  ***
-      !! ** Purpose: Set coupling fields and pass to CICE
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in   ) ::   kt   ! ocean time step
-      INTEGER, INTENT(in   ) ::   ksbc ! surface forcing type
-      !
-      INTEGER  ::   ji, jj, jl                   ! dummy loop indices      
-      REAL(wp), DIMENSION(jpi,jpj) :: ztmp, zpice
-      REAL(wp), DIMENSION(jpi,jpj,ncat) :: ztmpn
-      REAL(wp) ::   zintb, zintn  ! dummy argument
-      !!---------------------------------------------------------------------
-      !
-      IF( kt == nit000 )  THEN
-         IF(lwp) WRITE(numout,*)'cice_sbc_in'
-      ENDIF
-
-      ztmp(:,:)=0.0
-
-! Aggregate ice concentration already set in cice_sbc_out (or cice_sbc_init on 
-! the first time-step)
-
-! forced and coupled case 
-
-      IF( (ksbc == jp_flx).OR.(ksbc == jp_purecpl) ) THEN
-
-         ztmpn(:,:,:)=0.0
-
-! x comp of wind stress (CI_1)
-! U point to F point
-         DO_2D( 1, 0, 1, 1 )
-            ztmp(ji,jj) = 0.5 * (  fr_iu(ji,jj) * utau(ji,jj)      &
-                                 + fr_iu(ji,jj+1) * utau(ji,jj+1) ) * fmask(ji,jj,1)
-         END_2D
-         CALL nemo2cice(ztmp,strax,'F', -1. )
-
-! y comp of wind stress (CI_2)
-! V point to F point
-         DO_2D( 1, 1, 1, 0 )
-            ztmp(ji,jj) = 0.5 * (  fr_iv(ji,jj) * vtau(ji,jj)      &
-                                 + fr_iv(ji+1,jj) * vtau(ji+1,jj) ) * fmask(ji,jj,1)
-         END_2D
-         CALL nemo2cice(ztmp,stray,'F', -1. )
-
-! Surface downward latent heat flux (CI_5)
-         IF(ksbc == jp_flx) THEN
-            DO jl=1,ncat
-               ztmpn(:,:,jl)=qla_ice(:,:,1)*a_i(:,:,jl)
-            ENDDO
-         ELSE
-! emp_ice is set in sbc_cpl_ice_flx as sublimation-snow
-            qla_ice(:,:,1)= - ( emp_ice(:,:)+sprecip(:,:) ) * rLsub
-! End of temporary code
-            DO_2D( 1, 1, 1, 1 )
-               IF(fr_i(ji,jj).eq.0.0) THEN
-                  DO jl=1,ncat
-                     ztmpn(ji,jj,jl)=0.0
-                  ENDDO
-                  ! This will then be conserved in CICE
-                  ztmpn(ji,jj,1)=qla_ice(ji,jj,1)
-               ELSE
-                  DO jl=1,ncat
-                     ztmpn(ji,jj,jl)=qla_ice(ji,jj,1)*a_i(ji,jj,jl)/fr_i(ji,jj)
-                  ENDDO
-               ENDIF
-            END_2D
-         ENDIF
-         DO jl=1,ncat
-            CALL nemo2cice(ztmpn(:,:,jl),flatn_f(:,:,jl,:),'T', 1. )
-
-! GBM conductive flux through ice (CI_6)
-!  Convert to GBM
-            IF(ksbc == jp_flx) THEN
-               ztmp(:,:) = botmelt(:,:,jl)*a_i(:,:,jl)
-            ELSE
-               ztmp(:,:) = botmelt(:,:,jl)
-            ENDIF
-            CALL nemo2cice(ztmp,fcondtopn_f(:,:,jl,:),'T', 1. )
-
-! GBM surface heat flux (CI_7)
-!  Convert to GBM
-            IF(ksbc == jp_flx) THEN
-               ztmp(:,:) = (topmelt(:,:,jl)+botmelt(:,:,jl))*a_i(:,:,jl) 
-            ELSE
-               ztmp(:,:) = (topmelt(:,:,jl)+botmelt(:,:,jl))
-            ENDIF
-            CALL nemo2cice(ztmp,fsurfn_f(:,:,jl,:),'T', 1. )
-         ENDDO
-
-      ELSE IF(ksbc == jp_blk) THEN
-
-! Pass bulk forcing fields to CICE (which will calculate heat fluxes etc itself)
-! x comp and y comp of atmosphere surface wind (CICE expects on T points)
-         ztmp(:,:) = wndi_ice(:,:)
-         CALL nemo2cice(ztmp,uatm,'T', -1. )
-         ztmp(:,:) = wndj_ice(:,:)
-         CALL nemo2cice(ztmp,vatm,'T', -1. )
-         ztmp(:,:) = SQRT ( wndi_ice(:,:)**2 + wndj_ice(:,:)**2 )
-         CALL nemo2cice(ztmp,wind,'T', 1. )    ! Wind speed (m/s)
-         ztmp(:,:) = qsr_ice(:,:,1)
-         CALL nemo2cice(ztmp,fsw,'T', 1. )     ! Incoming short-wave (W/m^2)
-         ztmp(:,:) = qlw_ice(:,:,1)
-         CALL nemo2cice(ztmp,flw,'T', 1. )     ! Incoming long-wave (W/m^2)
-         ztmp(:,:) = tatm_ice(:,:)
-         CALL nemo2cice(ztmp,Tair,'T', 1. )    ! Air temperature (K)
-         CALL nemo2cice(ztmp,potT,'T', 1. )    ! Potential temp (K)
-! Following line uses MAX(....) to avoid problems if tatm_ice has unset halo rows  
-         ztmp(:,:) = 101000. / ( 287.04 * MAX(1.0,tatm_ice(:,:)) )    
-                                               ! Constant (101000.) atm pressure assumed
-         CALL nemo2cice(ztmp,rhoa,'T', 1. )    ! Air density (kg/m^3)
-         ztmp(:,:) = qatm_ice(:,:)
-         CALL nemo2cice(ztmp,Qa,'T', 1. )      ! Specific humidity (kg/kg)
-         ztmp(:,:)=10.0
-         CALL nemo2cice(ztmp,zlvl,'T', 1. )    ! Atmos level height (m)
-
-! May want to check all values are physically realistic (as in CICE routine 
-! prepare_forcing)?
-
-! Divide shortwave into spectral bands (as in prepare_forcing)
-         ztmp(:,:)=qsr_ice(:,:,1)*frcvdr       ! visible direct
-         CALL nemo2cice(ztmp,swvdr,'T', 1. )             
-         ztmp(:,:)=qsr_ice(:,:,1)*frcvdf       ! visible diffuse
-         CALL nemo2cice(ztmp,swvdf,'T', 1. )              
-         ztmp(:,:)=qsr_ice(:,:,1)*frcidr       ! near IR direct
-         CALL nemo2cice(ztmp,swidr,'T', 1. )
-         ztmp(:,:)=qsr_ice(:,:,1)*frcidf       ! near IR diffuse
-         CALL nemo2cice(ztmp,swidf,'T', 1. )
-
-      ENDIF
-
-! Snowfall
-! Ensure fsnow is positive (as in CICE routine prepare_forcing)
-      IF( iom_use('snowpre') )   CALL iom_put('snowpre',MAX( (1.0-fr_i(:,:))*sprecip(:,:) ,0.0)) !!Joakim edit  
-      ztmp(:,:)=MAX(fr_i(:,:)*sprecip(:,:),0.0)  
-      CALL nemo2cice(ztmp,fsnow,'T', 1. ) 
-
-! Rainfall
-      IF( iom_use('precip') )   CALL iom_put('precip', (1.0-fr_i(:,:))*(tprecip(:,:)-sprecip(:,:)) ) !!Joakim edit
-      ztmp(:,:)=fr_i(:,:)*(tprecip(:,:)-sprecip(:,:))
-      CALL nemo2cice(ztmp,frain,'T', 1. ) 
-
-! Freezing/melting potential
-! Calculated over NEMO leapfrog timestep (hence 2*dt)
-      nfrzmlt(:,:) = rho0 * rcp * e3t_m(:,:) * ( Tocnfrz-sst_m(:,:) ) / ( 2.0*dt )
-
-      ztmp(:,:) = nfrzmlt(:,:)
-      CALL nemo2cice(ztmp,frzmlt,'T', 1. )
-
-! SST  and SSS
-
-      CALL nemo2cice(sst_m,sst,'T', 1. )
-      CALL nemo2cice(sss_m,sss,'T', 1. )
-
-! x comp and y comp of surface ocean current
-! U point to F point
-      DO_2D( 1, 0, 1, 1 )
-         ztmp(ji,jj)=0.5*(ssu_m(ji,jj)+ssu_m(ji,jj+1))*fmask(ji,jj,1)
-      END_2D
-      CALL nemo2cice(ztmp,uocn,'F', -1. )
-
-! V point to F point
-      DO_2D( 1, 1, 1, 0 )
-         ztmp(ji,jj)=0.5*(ssv_m(ji,jj)+ssv_m(ji+1,jj))*fmask(ji,jj,1)
-      END_2D
-      CALL nemo2cice(ztmp,vocn,'F', -1. )
-
-      IF( ln_ice_embd ) THEN             !== embedded sea ice: compute representative ice top surface ==!
-          !
-          ! average interpolation coeff as used in dynspg = (1/nn_fsbc) * {SUM[n/nn_fsbc], n=0,nn_fsbc-1}
-          !                                               = (1/nn_fsbc)^2 * {SUM[n], n=0,nn_fsbc-1}
-         zintn = REAL( nn_fsbc - 1 ) / REAL( nn_fsbc ) * 0.5_wp
-          !
-          ! average interpolation coeff as used in dynspg = (1/nn_fsbc) * {SUM[1-n/nn_fsbc], n=0,nn_fsbc-1}
-          !                                               = (1/nn_fsbc)^2 * (nn_fsbc^2 - {SUM[n], n=0,nn_fsbc-1})
-         zintb = REAL( nn_fsbc + 1 ) / REAL( nn_fsbc ) * 0.5_wp
-          !
-         zpice(:,:) = ssh_m(:,:) + (  zintn * snwice_mass(:,:) +  zintb * snwice_mass_b(:,:)  ) * r1_rho0
-          !
-         !
-      ELSE                                    !== non-embedded sea ice: use ocean surface for slope calculation ==!
-         zpice(:,:) = ssh_m(:,:)
-      ENDIF
-
-! x comp and y comp of sea surface slope (on F points)
-! T point to F point
-      DO_2D( 1, 0, 1, 0 )
-         ztmp(ji,jj)=0.5 * (  (zpice(ji+1,jj  )-zpice(ji,jj  )) * r1_e1u(ji,jj  )    &
-            &               + (zpice(ji+1,jj+1)-zpice(ji,jj+1)) * r1_e1u(ji,jj+1)  ) * fmask(ji,jj,1)
-      END_2D
-      CALL nemo2cice( ztmp,ss_tltx,'F', -1. )
-
-! T point to F point
-      DO_2D( 1, 0, 1, 0 )
-         ztmp(ji,jj)=0.5 * (  (zpice(ji  ,jj+1)-zpice(ji  ,jj)) * r1_e2v(ji  ,jj)    &
-            &               + (zpice(ji+1,jj+1)-zpice(ji+1,jj)) * r1_e2v(ji+1,jj)  ) *  fmask(ji,jj,1)
-      END_2D
-      CALL nemo2cice(ztmp,ss_tlty,'F', -1. )
-      !
-   END SUBROUTINE cice_sbc_in
-
-
-   SUBROUTINE cice_sbc_out( kt, ksbc )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE cice_sbc_out  ***
-      !! ** Purpose: Get fields from CICE and set surface fields for NEMO
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
-      INTEGER, INTENT( in  ) ::   ksbc ! surface forcing type
-      
-      INTEGER  ::   ji, jj, jl                 ! dummy loop indices
-      REAL(wp), DIMENSION(jpi,jpj) :: ztmp1, ztmp2
-      !!---------------------------------------------------------------------
-      !
-      IF( kt == nit000 )  THEN
-         IF(lwp) WRITE(numout,*)'cice_sbc_out'
-      ENDIF
-      
-! x comp of ocean-ice stress 
-      CALL cice2nemo(strocnx,ztmp1,'F', -1. )
-      ss_iou(:,:)=0.0
-! F point to U point
-      DO_2D( 0, 0, 0, 0 )
-         ss_iou(ji,jj) = 0.5 * ( ztmp1(ji,jj-1) + ztmp1(ji,jj) ) * umask(ji,jj,1)
-      END_2D
-      CALL lbc_lnk( 'sbcice_cice', ss_iou , 'U', -1. )
-
-! y comp of ocean-ice stress 
-      CALL cice2nemo(strocny,ztmp1,'F', -1. )
-      ss_iov(:,:)=0.0
-! F point to V point
-
-      DO_2D( 1, 0, 0, 0 )
-         ss_iov(ji,jj) = 0.5 * ( ztmp1(ji-1,jj) + ztmp1(ji,jj) ) * vmask(ji,jj,1)
-      END_2D
-      CALL lbc_lnk( 'sbcice_cice', ss_iov , 'V', -1. )
-
-! x and y comps of surface stress
-! Combine wind stress and ocean-ice stress
-! [Note that fr_iu hasn't yet been updated, so still from start of CICE timestep]
-! strocnx and strocny already weighted by ice fraction in CICE so not done here 
-
-      utau(:,:)=(1.0-fr_iu(:,:))*utau(:,:)-ss_iou(:,:)
-      vtau(:,:)=(1.0-fr_iv(:,:))*vtau(:,:)-ss_iov(:,:)     
- 
-! Also need ice/ocean stress on T points so that taum can be updated 
-! This interpolation is already done in CICE so best to use those values 
-      CALL cice2nemo(strocnxT,ztmp1,'T',-1.) 
-      CALL cice2nemo(strocnyT,ztmp2,'T',-1.) 
- 
-! Update taum with modulus of ice-ocean stress 
-! strocnxT and strocnyT are not weighted by ice fraction in CICE so must be done here 
-taum(:,:)=(1.0-fr_i(:,:))*taum(:,:)+fr_i(:,:)*SQRT(ztmp1*ztmp1 + ztmp2*ztmp2) 
-
-! Freshwater fluxes 
-
-      IF(ksbc == jp_flx) THEN
-! Note that emp from the forcing files is evap*(1-aice)-(tprecip-aice*sprecip)
-! What we want here is evap*(1-aice)-tprecip*(1-aice) hence manipulation below
-! Not ideal since aice won't be the same as in the atmosphere.  
-! Better to use evap and tprecip? (but for now don't read in evap in this case)
-         emp(:,:)  = emp(:,:)+fr_i(:,:)*(tprecip(:,:)-sprecip(:,:))
-      ELSE IF(ksbc == jp_blk) THEN
-         emp(:,:)  = (1.0-fr_i(:,:))*emp(:,:)        
-      ELSE IF(ksbc == jp_purecpl) THEN
-! emp_tot is set in sbc_cpl_ice_flx (called from cice_sbc_in above) 
-! This is currently as required with the coupling fields from the UM atmosphere
-         emp(:,:) = emp_tot(:,:)+tprecip(:,:)*fr_i(:,:) 
-      ENDIF
-
-#if defined key_cice4
-      CALL cice2nemo(fresh_gbm,ztmp1,'T', 1. )
-      CALL cice2nemo(fsalt_gbm,ztmp2,'T', 1. )
-#else
-      CALL cice2nemo(fresh_ai,ztmp1,'T', 1. )
-      CALL cice2nemo(fsalt_ai,ztmp2,'T', 1. )
-#endif
-
-! Check to avoid unphysical expression when ice is forming (ztmp1 negative)
-! Otherwise we are effectively allowing ice of higher salinity than the ocean to form
-! which has to be compensated for by the ocean salinity potentially going negative
-! This check breaks conservation but seems reasonable until we have prognostic ice salinity
-! Note the 1000.0 below is to convert from kg salt to g salt (needed for PSU)
-      WHERE (ztmp1(:,:).lt.0.0) ztmp2(:,:)=MAX(ztmp2(:,:),ztmp1(:,:)*sss_m(:,:)/1000.0)
-      sfx(:,:)=ztmp2(:,:)*1000.0
-      emp(:,:)=emp(:,:)-ztmp1(:,:)
-      fmmflx(:,:) = ztmp1(:,:) !!Joakim edit
-      
-      CALL lbc_lnk_multi( 'sbcice_cice', emp , 'T', 1., sfx , 'T', 1. )
-
-! Solar penetrative radiation and non solar surface heat flux
-
-! Scale qsr and qns according to ice fraction (bulk formulae only)
-
-      IF(ksbc == jp_blk) THEN
-         qsr(:,:)=qsr(:,:)*(1.0-fr_i(:,:))
-         qns(:,:)=qns(:,:)*(1.0-fr_i(:,:))
-      ENDIF
-! Take into account snow melting except for fully coupled when already in qns_tot
-      IF(ksbc == jp_purecpl) THEN
-         qsr(:,:)= qsr_tot(:,:)
-         qns(:,:)= qns_tot(:,:)
-      ELSE
-         qns(:,:)= qns(:,:)-sprecip(:,:)*Lfresh*(1.0-fr_i(:,:))
-      ENDIF
-
-! Now add in ice / snow related terms
-! [fswthru will be zero unless running with calc_Tsfc=T in CICE]
-#if defined key_cice4
-      CALL cice2nemo(fswthru_gbm,ztmp1,'T', 1. )
-#else
-      CALL cice2nemo(fswthru_ai,ztmp1,'T', 1. )
-#endif
-      qsr(:,:)=qsr(:,:)+ztmp1(:,:)
-      CALL lbc_lnk( 'sbcice_cice', qsr , 'T', 1. )
-
-      DO_2D( 1, 1, 1, 1 )
-         nfrzmlt(ji,jj)=MAX(nfrzmlt(ji,jj),0.0)
-      END_2D
-
-#if defined key_cice4
-      CALL cice2nemo(fhocn_gbm,ztmp1,'T', 1. )
-#else
-      CALL cice2nemo(fhocn_ai,ztmp1,'T', 1. )
-#endif
-      qns(:,:)=qns(:,:)+nfrzmlt(:,:)+ztmp1(:,:)
-
-      CALL lbc_lnk( 'sbcice_cice', qns , 'T', 1. )
-
-! Prepare for the following CICE time-step
-
-      CALL cice2nemo(aice,fr_i,'T', 1. )
-      IF( (ksbc == jp_flx).OR.(ksbc == jp_purecpl) ) THEN
-         DO jl=1,ncat
-            CALL cice2nemo(aicen(:,:,jl,:),a_i(:,:,jl), 'T', 1. )
-         ENDDO
-      ENDIF
-
-! T point to U point
-! T point to V point
-      DO_2D( 1, 0, 1, 0 )
-         fr_iu(ji,jj)=0.5*(fr_i(ji,jj)+fr_i(ji+1,jj))*umask(ji,jj,1)
-         fr_iv(ji,jj)=0.5*(fr_i(ji,jj)+fr_i(ji,jj+1))*vmask(ji,jj,1)
-      END_2D
-
-      CALL lbc_lnk_multi( 'sbcice_cice', fr_iu , 'U', 1., fr_iv , 'V', 1. )
-
-      ! set the snow+ice mass
-      CALL cice2nemo(vsno(:,:,:),ztmp1,'T', 1. )
-      CALL cice2nemo(vice(:,:,:),ztmp2,'T', 1. )
-      snwice_mass  (:,:) = ( rhos * ztmp1(:,:) + rhoi * ztmp2(:,:)  )
-      snwice_mass_b(:,:) = snwice_mass(:,:)
-      snwice_fmass (:,:) = ( snwice_mass(:,:) - snwice_mass_b(:,:) ) / dt
-      !
-   END SUBROUTINE cice_sbc_out
-
-
-   SUBROUTINE cice_sbc_hadgam( kt )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE cice_sbc_hadgam  ***
-      !! ** Purpose: Prepare fields needed to pass to HadGAM3 atmosphere
-      !! 
-      !!
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
-      !!
-      INTEGER  ::   jl                        ! dummy loop index
-      INTEGER  ::   ierror
-      !!---------------------------------------------------------------------
-      !
-      IF( kt == nit000 )  THEN
-         IF(lwp) WRITE(numout,*)'cice_sbc_hadgam'
-         IF( sbc_cpl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'sbc_cpl_alloc : unable to allocate arrays' )
-      ENDIF
-
-      !                                         ! =========================== !
-      !                                         !   Prepare Coupling fields   !
-      !                                         ! =========================== !
-      !
-      ! x and y comp of ice velocity
-      !
-      CALL cice2nemo(uvel,u_ice,'F', -1. )
-      CALL cice2nemo(vvel,v_ice,'F', -1. )
-      !
-      ! Ice concentration (CO_1) = a_i calculated at end of cice_sbc_out  
-      !
-      ! Snow and ice thicknesses (CO_2 and CO_3)
-      !
-      DO jl = 1, ncat
-         CALL cice2nemo( vsnon(:,:,jl,:), h_s(:,:,jl),'T', 1. )
-         CALL cice2nemo( vicen(:,:,jl,:), h_i(:,:,jl),'T', 1. )
-      END DO
-      !
-   END SUBROUTINE cice_sbc_hadgam
-
-
-   SUBROUTINE cice_sbc_final
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE cice_sbc_final  ***
-      !! ** Purpose: Finalize CICE
-      !!---------------------------------------------------------------------
-      !
-      IF(lwp) WRITE(numout,*)'cice_sbc_final'
-      !
-      CALL CICE_Finalize
-      !
-   END SUBROUTINE cice_sbc_final
-
-
-   SUBROUTINE cice_sbc_force (kt)
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE cice_sbc_force  ***
-      !! ** Purpose : Provide CICE forcing from files
-      !!
-      !!---------------------------------------------------------------------
-      !! ** Method  :   READ monthly flux file in NetCDF files
-      !!      
-      !!  snowfall    
-      !!  rainfall    
-      !!  sublimation rate    
-      !!  topmelt (category)
-      !!  botmelt (category)
-      !!
-      !! History :
-      !!----------------------------------------------------------------------
-      USE iom
-      !!
-      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
-      !!
-      INTEGER  ::   ierror             ! return error code
-      INTEGER  ::   ifpr               ! dummy loop index
-      !!
-      CHARACTER(len=100) ::  cn_dir                            !   Root directory for location of CICE forcing files
-      TYPE(FLD_N), DIMENSION(jpfld) ::   slf_i                 ! array of namelist informations on the fields to read
-      TYPE(FLD_N) ::   sn_snow, sn_rain, sn_sblm               ! informations about the fields to be read
-      TYPE(FLD_N) ::   sn_top1, sn_top2, sn_top3, sn_top4, sn_top5
-      TYPE(FLD_N) ::   sn_bot1, sn_bot2, sn_bot3, sn_bot4, sn_bot5 
-      !!
-      NAMELIST/namsbc_cice/ cn_dir, sn_snow, sn_rain, sn_sblm,   &
-         &                          sn_top1, sn_top2, sn_top3, sn_top4, sn_top5,  &
-         &                          sn_bot1, sn_bot2, sn_bot3, sn_bot4, sn_bot5
-      INTEGER :: ios
-      !!---------------------------------------------------------------------
-
-      !                                         ! ====================== !
-      IF( kt == nit000 ) THEN                   !  First call kt=nit000  !
-         !                                      ! ====================== !
-         ! namsbc_cice is not yet in the reference namelist
-         ! set file information (default values)
-         cn_dir = './'       ! directory in which the model is executed
-
-         ! (NB: frequency positive => hours, negative => months)
-         !            !    file          ! frequency !  variable    ! time intep !  clim   ! 'yearly' or ! weights  ! rotation   ! landmask
-         !            !    name          !  (hours)  !   name       !   (T/F)    !  (T/F)  !  'monthly'  ! filename ! pairs      ! file
-         sn_snow = FLD_N( 'snowfall_1m'  ,    -1.    ,  'snowfall'  ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    ) 
-         sn_rain = FLD_N( 'rainfall_1m'  ,    -1.    ,  'rainfall'  ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    ) 
-         sn_sblm = FLD_N( 'sublim_1m'    ,    -1.    ,  'sublim'    ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_top1 = FLD_N( 'topmeltn1_1m' ,    -1.    ,  'topmeltn1' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_top2 = FLD_N( 'topmeltn2_1m' ,    -1.    ,  'topmeltn2' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_top3 = FLD_N( 'topmeltn3_1m' ,    -1.    ,  'topmeltn3' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_top4 = FLD_N( 'topmeltn4_1m' ,    -1.    ,  'topmeltn4' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_top5 = FLD_N( 'topmeltn5_1m' ,    -1.    ,  'topmeltn5' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_bot1 = FLD_N( 'botmeltn1_1m' ,    -1.    ,  'botmeltn1' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_bot2 = FLD_N( 'botmeltn2_1m' ,    -1.    ,  'botmeltn2' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_bot3 = FLD_N( 'botmeltn3_1m' ,    -1.    ,  'botmeltn3' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_bot4 = FLD_N( 'botmeltn4_1m' ,    -1.    ,  'botmeltn4' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_bot5 = FLD_N( 'botmeltn5_1m' ,    -1.    ,  'botmeltn5' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-
-         READ  ( numnam_ref, namsbc_cice, IOSTAT = ios, ERR = 901)
-901      IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_cice in reference namelist' )
-
-         READ  ( numnam_cfg, namsbc_cice, IOSTAT = ios, ERR = 902 )
-902      IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_cice in configuration namelist' )
-         IF(lwm) WRITE ( numond, namsbc_cice )
-
-         ! store namelist information in an array
-         slf_i(jp_snow) = sn_snow   ;   slf_i(jp_rain) = sn_rain   ;   slf_i(jp_sblm) = sn_sblm
-         slf_i(jp_top1) = sn_top1   ;   slf_i(jp_top2) = sn_top2   ;   slf_i(jp_top3) = sn_top3
-         slf_i(jp_top4) = sn_top4   ;   slf_i(jp_top5) = sn_top5   ;   slf_i(jp_bot1) = sn_bot1
-         slf_i(jp_bot2) = sn_bot2   ;   slf_i(jp_bot3) = sn_bot3   ;   slf_i(jp_bot4) = sn_bot4
-         slf_i(jp_bot5) = sn_bot5
-         
-         ! set sf structure
-         ALLOCATE( sf(jpfld), STAT=ierror )
-         IF( ierror > 0 ) THEN
-            CALL ctl_stop( 'cice_sbc_force: unable to allocate sf structure' )   ;   RETURN
-         ENDIF
-
-         DO ifpr= 1, jpfld
-            ALLOCATE( sf(ifpr)%fnow(jpi,jpj,1) )
-            ALLOCATE( sf(ifpr)%fdta(jpi,jpj,1,2) )
-         END DO
-
-         ! fill sf with slf_i and control print
-         CALL fld_fill( sf, slf_i, cn_dir, 'cice_sbc_force', 'flux formulation for CICE', 'namsbc_cice' )
-         !
-      ENDIF
-
-      CALL fld_read( kt, nn_fsbc, sf )           ! Read input fields and provides the
-      !                                          ! input fields at the current time-step
-
-      ! set the fluxes from read fields
-      sprecip(:,:) = sf(jp_snow)%fnow(:,:,1)
-      tprecip(:,:) = sf(jp_snow)%fnow(:,:,1)+sf(jp_rain)%fnow(:,:,1)
-! May be better to do this conversion somewhere else
-      qla_ice(:,:,1) = -rLsub*sf(jp_sblm)%fnow(:,:,1)
-      topmelt(:,:,1) = sf(jp_top1)%fnow(:,:,1)
-      topmelt(:,:,2) = sf(jp_top2)%fnow(:,:,1)
-      topmelt(:,:,3) = sf(jp_top3)%fnow(:,:,1)
-      topmelt(:,:,4) = sf(jp_top4)%fnow(:,:,1)
-      topmelt(:,:,5) = sf(jp_top5)%fnow(:,:,1)
-      botmelt(:,:,1) = sf(jp_bot1)%fnow(:,:,1)
-      botmelt(:,:,2) = sf(jp_bot2)%fnow(:,:,1)
-      botmelt(:,:,3) = sf(jp_bot3)%fnow(:,:,1)
-      botmelt(:,:,4) = sf(jp_bot4)%fnow(:,:,1)
-      botmelt(:,:,5) = sf(jp_bot5)%fnow(:,:,1)
-
-      ! control print (if less than 100 time-step asked)
-      IF( nitend-nit000 <= 100 .AND. lwp ) THEN
-         WRITE(numout,*) 
-         WRITE(numout,*) '        read forcing fluxes for CICE OK'
-         CALL FLUSH(numout)
-      ENDIF
-
-   END SUBROUTINE cice_sbc_force
-
-   SUBROUTINE nemo2cice( pn, pc, cd_type, psgn)
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE nemo2cice  ***
-      !! ** Purpose :   Transfer field in NEMO array to field in CICE array.  
-#if defined key_nemocice_decomp
-      !!             
-      !!                NEMO and CICE PE sub domains are identical, hence
-      !!                there is no need to gather or scatter data from 
-      !!                one PE configuration to another.
-#else
-      !!                Automatically gather/scatter between 
-      !!                different processors and blocks
-      !! ** Method :    A. Ensure all haloes are filled in NEMO field (pn)
-      !!                B. Gather pn into global array (png)
-      !!                C. Map png into CICE global array (pcg)
-      !!                D. Scatter pcg to CICE blocks (pc) + update haloes  
-#endif
-      !!---------------------------------------------------------------------
-      CHARACTER(len=1), INTENT( in ) ::   &
-          cd_type       ! nature of pn grid-point
-          !             !   = T or F gridpoints
-      REAL(wp), INTENT( in ) ::   &
-          psgn          ! control of the sign change
-          !             !   =-1 , the sign is modified following the type of b.c. used
-          !             !   = 1 , no sign change
-      REAL(wp), DIMENSION(jpi,jpj) :: pn
-#if !defined key_nemocice_decomp
-      REAL(wp), DIMENSION(jpiglo,jpjglo) :: png2
-      REAL (kind=dbl_kind), dimension(nx_global,ny_global) :: pcg
-#endif
-      REAL (kind=dbl_kind), dimension(nx_block,ny_block,max_blocks) :: pc
-      INTEGER (int_kind) :: &
-         field_type,        &! id for type of field (scalar, vector, angle)
-         grid_loc            ! id for location on horizontal grid
-                            !  (center, NEcorner, Nface, Eface)
-
-      INTEGER  ::   ji, jj, jn                      ! dummy loop indices
-      !!---------------------------------------------------------------------
-
-!     A. Ensure all haloes are filled in NEMO field (pn)
-
-      CALL lbc_lnk( 'sbcice_cice', pn , cd_type, psgn )
-
-#if defined key_nemocice_decomp
-
-      ! Copy local domain data from NEMO to CICE field
-      pc(:,:,1)=0.0
-      DO jj=2,ny_block-1
-         DO ji=2,nx_block-1
-            pc(ji,jj,1)=pn(ji-1+ji_off,jj-1+jj_off)
-         ENDDO
-      ENDDO
-
-#else
-
-!     B. Gather pn into global array (png)
-
-      IF( jpnij > 1) THEN
-         CALL mppsync
-         CALL mppgather (pn,0,png) 
-         CALL mppsync
-      ELSE
-         png(:,:,1)=pn(:,:)
-      ENDIF
-
-!     C. Map png into CICE global array (pcg)
-
-! Need to make sure this is robust to changes in NEMO halo rows....
-! (may be OK but not 100% sure)
-
-      IF(nproc==0) THEN     
-!        pcg(:,:)=0.0
-         DO jn=1,jpnij
-            DO jj=nldjt(jn),nlejt(jn)
-               DO ji=nldit(jn),nleit(jn)
-                  png2(ji+nimppt(jn)-1,jj+njmppt(jn)-1)=png(ji,jj,jn)
-               ENDDO
-            ENDDO
-         ENDDO
-         DO jj=1,ny_global
-            DO ji=1,nx_global
-               pcg(ji,jj)=png2(ji+ji_off,jj+jj_off)
-            ENDDO
-         ENDDO
-      ENDIF
-
-#endif
-
-      SELECT CASE ( cd_type )
-         CASE ( 'T' )
-            grid_loc=field_loc_center
-         CASE ( 'F' )                              
-            grid_loc=field_loc_NEcorner
-      END SELECT
-
-      SELECT CASE ( NINT(psgn) )
-         CASE ( -1 )
-            field_type=field_type_vector
-         CASE ( 1 )                              
-            field_type=field_type_scalar
-      END SELECT
-
-#if defined key_nemocice_decomp
-      ! Ensure CICE halos are up to date
-      CALL ice_HaloUpdate (pc, halo_info, grid_loc, field_type)
-#else
-!     D. Scatter pcg to CICE blocks (pc) + update halos
-      CALL scatter_global(pc, pcg, 0, distrb_info, grid_loc, field_type)
-#endif
-
-   END SUBROUTINE nemo2cice
-
-   SUBROUTINE cice2nemo ( pc, pn, cd_type, psgn )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE cice2nemo  ***
-      !! ** Purpose :   Transfer field in CICE array to field in NEMO array.
-#if defined key_nemocice_decomp
-      !!             
-      !!                NEMO and CICE PE sub domains are identical, hence
-      !!                there is no need to gather or scatter data from 
-      !!                one PE configuration to another.
-#else 
-      !!                Automatically deal with scatter/gather between
-      !!                different processors and blocks
-      !! ** Method :    A. Gather CICE blocks (pc) into global array (pcg)
-      !!                B. Map pcg into NEMO global array (png)
-      !!                C. Scatter png into NEMO field (pn) for each processor
-      !!                D. Ensure all haloes are filled in pn 
-#endif
-      !!---------------------------------------------------------------------
-
-      CHARACTER(len=1), INTENT( in ) ::   &
-          cd_type       ! nature of pn grid-point
-          !             !   = T or F gridpoints
-      REAL(wp), INTENT( in ) ::   &
-          psgn          ! control of the sign change
-          !             !   =-1 , the sign is modified following the type of b.c. used
-          !             !   = 1 , no sign change
-      REAL(wp), DIMENSION(jpi,jpj) :: pn
-
-#if defined key_nemocice_decomp
-      INTEGER (int_kind) :: &
-         field_type,        & ! id for type of field (scalar, vector, angle)
-         grid_loc             ! id for location on horizontal grid
-                              ! (center, NEcorner, Nface, Eface)
-#else
-      REAL (kind=dbl_kind), dimension(nx_global,ny_global) :: pcg
-#endif
-
-      REAL (kind=dbl_kind), dimension(nx_block,ny_block,max_blocks) :: pc
-
-      INTEGER  ::   ji, jj, jn                      ! dummy loop indices
-
-
-#if defined key_nemocice_decomp
-
-      SELECT CASE ( cd_type )
-         CASE ( 'T' )
-            grid_loc=field_loc_center
-         CASE ( 'F' )                              
-            grid_loc=field_loc_NEcorner
-      END SELECT
-
-      SELECT CASE ( NINT(psgn) )
-         CASE ( -1 )
-            field_type=field_type_vector
-         CASE ( 1 )                              
-            field_type=field_type_scalar
-      END SELECT
-
-      CALL ice_HaloUpdate (pc, halo_info, grid_loc, field_type)
-
-
-      pn(:,:)=0.0
-      DO_2D( 1, 0, 1, 0 )
-         pn(ji,jj)=pc(ji+1-ji_off,jj+1-jj_off,1)
-      END_2D
-
-#else
-
-!      A. Gather CICE blocks (pc) into global array (pcg) 
-
-      CALL gather_global(pcg, pc, 0, distrb_info)
-
-!     B. Map pcg into NEMO global array (png)
-
-! Need to make sure this is robust to changes in NEMO halo rows....
-! (may be OK but not spent much time thinking about it)
-! Note that non-existent pcg elements may be used below, but
-! the lbclnk call on pn will replace these with sensible values
-
-      IF(nproc==0) THEN
-         png(:,:,:)=0.0
-         DO jn=1,jpnij
-            DO jj=nldjt(jn),nlejt(jn)
-               DO ji=nldit(jn),nleit(jn)
-                  png(ji,jj,jn)=pcg(ji+nimppt(jn)-1-ji_off,jj+njmppt(jn)-1-jj_off)
-               ENDDO
-            ENDDO
-         ENDDO
-      ENDIF
-
-!     C. Scatter png into NEMO field (pn) for each processor
-
-      IF( jpnij > 1) THEN
-         CALL mppsync
-         CALL mppscatter (png,0,pn) 
-         CALL mppsync
-      ELSE
-         pn(:,:)=png(:,:,1)
-      ENDIF
-
-#endif
-
-!     D. Ensure all haloes are filled in pn
-
-      CALL lbc_lnk( 'sbcice_cice', pn , cd_type, psgn )
-
-   END SUBROUTINE cice2nemo
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option           Dummy module         NO CICE sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE sbc_ice_cice ( kt, ksbc )     ! Dummy routine
-      IMPLICIT NONE
-      INTEGER, INTENT( in ) :: kt, ksbc
-      WRITE(*,*) 'sbc_ice_cice: You should not have seen this print! error?', kt
-   END SUBROUTINE sbc_ice_cice
-
-   SUBROUTINE cice_sbc_init (ksbc, Kbb, Kmm)    ! Dummy routine
-      IMPLICIT NONE
-      INTEGER, INTENT( in ) :: ksbc
-      INTEGER, INTENT( in ) :: Kbb, Kmm
-      WRITE(*,*) 'cice_sbc_init: You should not have seen this print! error?', ksbc
-   END SUBROUTINE cice_sbc_init
-
-   SUBROUTINE cice_sbc_final     ! Dummy routine
-      IMPLICIT NONE
-      WRITE(*,*) 'cice_sbc_final: You should not have seen this print! error?'
-   END SUBROUTINE cice_sbc_final
-
-#endif
-
-   !!======================================================================
-END MODULE sbcice_cice
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/step.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/step.F90	(revision 13603)
+++ 	(revision )
@@ -1,322 +1,0 @@
-MODULE step
-   !!======================================================================
-   !!                       ***  MODULE step  ***
-   !! Time-stepping   : manager of the shallow water equation time stepping
-   !!======================================================================
-   !! History :  NEMO !  2020-03  (A. Nasser, G. Madec)  Original code from  4.0.2
-   !!----------------------------------------------------------------------
-#if defined key_qco
-   !!----------------------------------------------------------------------
-   !!   'key_qco'      EMPTY MODULE      Quasi-Eulerian vertical coordonate
-   !!----------------------------------------------------------------------
-#else
-   !!----------------------------------------------------------------------
-   !!   stp             : Shallow Water time-stepping
-   !!----------------------------------------------------------------------
-   USE step_oce         ! time stepping definition modules
-   USE phycst           ! physical constants
-   USE usrdef_nam
-   !
-   USE iom              ! xIOs server 
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   stp   ! called by nemogcm.F90
-   
-   !!----------------------------------------------------------------------
-   !! time level indices
-   !!----------------------------------------------------------------------
-   INTEGER, PUBLIC ::   Nbb, Nnn, Naa, Nrhs   !! used by nemo_init
-      
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: step.F90 12614 2020-03-26 14:59:52Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-#if defined key_agrif
-   RECURSIVE SUBROUTINE stp( )
-      INTEGER             ::   kstp   ! ocean time-step index
-#else
-   SUBROUTINE stp( kstp )
-      INTEGER, INTENT(in) ::   kstp   ! ocean time-step index
-#endif
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE stp  ***
-      !!
-      !! ** Purpose : - Time stepping of shallow water (SHW) (momentum and ssh eqs.)
-      !!
-      !! ** Method  : -1- Update forcings
-      !!              -2- Update the ssh at Naa
-      !!              -3- Compute the momentum trends (Nrhs)
-      !!              -4- Update the horizontal velocity
-      !!              -5- Apply Asselin time filter to uu,vv,ssh
-      !!              -6- Outputs and diagnostics
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk   ! dummy loop indice
-      INTEGER ::   indic        ! error indicator if < 0
-!!gm kcall can be removed, I guess
-      INTEGER ::   kcall        ! optional integer argument (dom_vvl_sf_nxt)
-      REAL(wp)::   z1_2rho0     ! local scalars
-      
-      REAL(wp) ::   zue3a, zue3n, zue3b    ! local scalars
-      REAL(wp) ::   zve3a, zve3n, zve3b    !   -      -
-      REAL(wp) ::   ze3t_tf, ze3u_tf, ze3v_tf, zua, zva
-      !! ---------------------------------------------------------------------
-#if defined key_agrif
-      kstp = nit000 + Agrif_Nb_Step()
-      Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
-      IF( lk_agrif_debug ) THEN
-         IF( Agrif_Root() .and. lwp)   WRITE(*,*) '---'
-         IF(lwp)   WRITE(*,*) 'Grid Number', Agrif_Fixed(),' time step ', kstp, 'int tstep', Agrif_NbStepint()
-      ENDIF
-      IF( kstp == nit000 + 1 )   lk_agrif_fstep = .FALSE.
-# if defined key_iomput
-      IF( Agrif_Nbstepint() == 0 )   CALL iom_swap( cxios_context )
-# endif
-#endif
-      !
-      IF( ln_timing )   CALL timing_start('stp')
-      !
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! model timestep
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      !
-      IF( l_1st_euler ) THEN     ! start or restart with Euler 1st time-step
-         rDt   =  rn_Dt   
-         r1_Dt = 1._wp / rDt
-      ENDIF
-
-      IF ( kstp == nit000 )   ww(:,:,:) = 0._wp   ! initialize vertical velocity one for all to zero
-
-      !
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! update I/O and calendar 
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                             indic = 0                ! reset to no error condition
-                             
-      IF( kstp == nit000 ) THEN                       ! initialize IOM context (must be done after nemo_init for AGRIF+XIOS+OASIS)
-                             CALL iom_init( cxios_context, ld_closedef=.FALSE. )   ! for model grid (including passible AGRIF zoom)
-         IF( lk_diamlr   )   CALL dia_mlr_iom_init    ! with additional setup for multiple-linear-regression analysis
-                             CALL iom_init_closedef
-         IF( ln_crs      )   CALL iom_init( TRIM(cxios_context)//"_crs" )  ! for coarse grid
-      ENDIF
-      IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
-                             CALL iom_setkt( kstp - nit000 + 1,      cxios_context          )   ! tell IOM we are at time step kstp
-      IF( ln_crs         )   CALL iom_setkt( kstp - nit000 + 1, TRIM(cxios_context)//"_crs" )   ! tell IOM we are at time step kstp
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Update external forcing (tides, open boundaries, ice shelf interaction and surface boundary condition (including sea-ice)
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_tide    )   CALL tide_update( kstp )                     ! update tide potential
-      IF( ln_apr_dyn )   CALL sbc_apr ( kstp )                        ! atmospheric pressure (NB: call before bdy_dta which needs ssh_ib) 
-      IF( ln_bdy     )   CALL bdy_dta ( kstp, Nnn )                   ! update dynamic & tracer data at open boundaries
-                         CALL sbc     ( kstp, Nbb, Nnn )              ! Sea Boundary Condition
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Ocean physics update
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      !  LATERAL  PHYSICS
-      !                                                                        ! eddy diffusivity coeff.
-      IF( l_ldfdyn_time )   CALL ldf_dyn( kstp, Nbb )                          ! eddy viscosity coeff. 
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      !  Ocean dynamics : hdiv, ssh, e3, u, v, w
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-                            CALL ssh_nxt       ( kstp, Nbb, Nnn, ssh, Naa )    ! after ssh (includes call to div_hor)
-                         uu(:,:,:,Nrhs) = 0._wp            ! set dynamics trends to zero
-                         vv(:,:,:,Nrhs) = 0._wp
-
-      IF( .NOT.ln_linssh )  CALL dom_vvl_sf_nxt( kstp, Nbb, Nnn,      Naa )    ! after vertical scale factors 
-
-      IF( ln_bdy     )      CALL bdy_dyn3d_dmp ( kstp, Nbb,      uu, vv, Nrhs )  ! bdy damping trends
-
-#if defined key_agrif
-      IF(.NOT. Agrif_Root())  & 
-               &            CALL Agrif_Sponge_dyn        ! momentum sponge
-#endif
-                            CALL dyn_adv( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS
- 
-                            CALL dyn_vor( kstp,      Nnn      , uu, vv, Nrhs )  ! vorticity           	==> RHS
- 
-                            CALL dyn_ldf( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! lateral mixing
-
-!!an - calcul du gradient de pression horizontal (explicit)
-      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) - grav * ( ssh(ji+1,jj,Nnn) - ssh(ji,jj,Nnn) ) * r1_e1u(ji,jj)
-         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) - grav * ( ssh(ji,jj+1,Nnn) - ssh(ji,jj,Nnn) ) * r1_e2v(ji,jj)
-      END_3D
-      !
-      ! add wind stress forcing and layer linear friction to the RHS 
-      z1_2rho0 = 0.5_wp * r1_rho0
-      DO_3D( 0, 0, 0, 0,1,jpkm1)
-         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) + z1_2rho0 * ( utau_b(ji,jj) + utau(ji,jj) ) / e3u(ji,jj,jk,Nnn)   &
-            &                                  - rn_rfr * uu(ji,jj,jk,Nbb)
-         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) + z1_2rho0 * ( vtau_b(ji,jj) + vtau(ji,jj) ) / e3v(ji,jj,jk,Nnn)   &
-            &                                  - rn_rfr * vv(ji,jj,jk,Nbb)
-      END_3D   
-!!an         
-  
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Leap-Frog time splitting + Robert-Asselin time filter on u,v,e3 
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-          
-!! what about  IF( .NOT.ln_linssh )  ?
-!!an futur module dyn_nxt (a la place de dyn_atf)
-      
-      IF( ln_dynadv_vec ) THEN      ! vector invariant form : applied on velocity
-         IF( l_1st_euler ) THEN           ! Euler time stepping (no Asselin filter)
-            DO_3D( 0, 0, 0, 0,1,jpkm1)
-               uu(ji,jj,jk,Naa) = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-               vv(ji,jj,jk,Naa) = vv(ji,jj,jk,Nbb) + rDt * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-             END_3D          
-         ELSE                             ! Leap Frog time stepping + Asselin filter         
-            DO_3D( 1, 1, 1, 1,1,jpkm1)
-               zua = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-               zva = vv(ji,jj,jk,Nbb) + rDt * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-               !                                                                  ! Asselin time filter on u,v (Nnn)
-               uu(ji,jj,jk,Nnn) = uu(ji,jj,jk,Nnn) + rn_atfp * (uu(ji,jj,jk,Nbb) - 2._wp * uu(ji,jj,jk,Nnn) + zua)
-               vv(ji,jj,jk,Nnn) = vv(ji,jj,jk,Nnn) + rn_atfp * (vv(ji,jj,jk,Nbb) - 2._wp * vv(ji,jj,jk,Nnn) + zva)
-               !
-               ze3u_tf = e3u(ji,jj,jk,Nnn) + rn_atfp * ( e3u(ji,jj,jk,Nbb) - 2._wp * e3u(ji,jj,jk,Nnn)  + e3u(ji,jj,jk,Naa) )
-               ze3v_tf = e3v(ji,jj,jk,Nnn) + rn_atfp * ( e3v(ji,jj,jk,Nbb) - 2._wp * e3v(ji,jj,jk,Nnn)  + e3v(ji,jj,jk,Naa) )
-               ze3t_tf = e3t(ji,jj,jk,Nnn) + rn_atfp * ( e3t(ji,jj,jk,Nbb) - 2._wp * e3t(ji,jj,jk,Nnn)  + e3t(ji,jj,jk,Naa) )
-               !
-               e3u(ji,jj,jk,Nnn) = ze3u_tf
-               e3v(ji,jj,jk,Nnn) = ze3v_tf
-               e3t(ji,jj,jk,Nnn) = ze3t_tf
-               !              
-               uu(ji,jj,jk,Naa) = zua
-               vv(ji,jj,jk,Naa) = zva
-            END_3D
-         ENDIF
-         !
-      ELSE                          ! flux form : applied on thickness weighted velocity
-         IF( l_1st_euler ) THEN           ! Euler time stepping (no Asselin filter)
-            DO_3D( 0, 0, 0, 0,1,jpkm1)
-               zue3b = e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nbb)
-               zve3b = e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nbb)
-               !                                                ! LF time stepping
-               zue3a = zue3b + rDt * e3u(ji,jj,jk,Nrhs) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-               zve3a = zve3b + rDt * e3v(ji,jj,jk,Nrhs) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-               !
-               uu(ji,jj,jk,Naa) = zue3a / e3u(ji,jj,jk,Naa)    
-               vv(ji,jj,jk,Naa) = zve3a / e3v(ji,jj,jk,Naa)
-            END_3D
-         ELSE                             ! Leap Frog time stepping + Asselin filter
-            DO_3D( 1, 1, 1, 1,1,jpkm1)
-               zue3n = e3u(ji,jj,jk,Nnn) * uu(ji,jj,jk,Nnn)
-               zve3n = e3v(ji,jj,jk,Nnn) * vv(ji,jj,jk,Nnn)
-               zue3b = e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nbb)
-               zve3b = e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nbb)
-               !                                                ! LF time stepping
-               zue3a = zue3b + rDt * e3u(ji,jj,jk,Nrhs) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-               zve3a = zve3b + rDt * e3v(ji,jj,jk,Nrhs) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-               !                                                ! Asselin time filter on e3u/v/t
-               ze3u_tf = e3u(ji,jj,jk,Nnn) + rn_atfp * ( e3u(ji,jj,jk,Nbb) - 2._wp * e3u(ji,jj,jk,Nnn)  + e3u(ji,jj,jk,Naa) ) 
-               ze3v_tf = e3v(ji,jj,jk,Nnn) + rn_atfp * ( e3v(ji,jj,jk,Nbb) - 2._wp * e3v(ji,jj,jk,Nnn)  + e3v(ji,jj,jk,Naa) )
-               ze3t_tf = e3t(ji,jj,jk,Nnn) + rn_atfp * ( e3t(ji,jj,jk,Nbb) - 2._wp * e3t(ji,jj,jk,Nnn)  + e3t(ji,jj,jk,Naa) ) 
-               !                                                ! Asselin time filter on u,v (Nnn)
-               uu(ji,jj,jk,Nnn) = ( zue3n + rn_atfp * ( zue3b - 2._wp * zue3n  + zue3a ) ) / ze3u_tf
-               vv(ji,jj,jk,Nnn) = ( zve3n + rn_atfp * ( zve3b - 2._wp * zve3n  + zve3a ) ) / ze3v_tf
-               !
-               e3u(ji,jj,jk,Nnn) = ze3u_tf
-               e3v(ji,jj,jk,Nnn) = ze3v_tf
-               e3t(ji,jj,jk,Nnn) = ze3t_tf
-               !
-               uu(ji,jj,jk,Naa) = zue3a / e3u(ji,jj,jk,Naa)    
-               vv(ji,jj,jk,Naa) = zve3a / e3v(ji,jj,jk,Naa)
-            END_3D       
-         ENDIF
-      ENDIF
-
-
-      CALL lbc_lnk_multi( 'stp', uu(:,:,:,Nnn), 'U', -1., vv(:,:,:,Nnn), 'V', -1.,   &   !* local domain boundaries
-         &                       uu(:,:,:,Naa), 'U', -1., vv(:,:,:,Naa), 'V', -1.    )     
-
-!!an         
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Set boundary conditions, time filter and swap time levels
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-!!an TO BE ADDED : dyn_nxt
-!!                         CALL dyn_atf       ( kstp, Nbb, Nnn, Naa, uu, vv, e3t, e3u, e3v  )  ! time filtering of "now" velocities and scale factors
-!!an TO BE ADDED : a simplifier
-!!                         CALL ssh_atf       ( kstp, Nbb, Nnn, Naa, ssh )                     ! time filtering of "now" sea surface height
-      IF ( .NOT.( l_1st_euler ) ) THEN   ! Only do time filtering for leapfrog timesteps
-         !                                                  ! filtering "now" field
-         ssh(:,:,Nnn) = ssh(:,:,Nnn) + rn_atfp * ( ssh(:,:,Nbb) - 2 * ssh(:,:,Nnn) + ssh(:,:,Naa) )
-      ENDIF
-!!an 
-
-
-      ! Swap time levels
-      Nrhs = Nbb
-      Nbb = Nnn
-      Nnn = Naa
-      Naa = Nrhs
-      !
-                         CALL dom_vvl_sf_update( kstp, Nbb, Nnn, Naa )  ! recompute vertical scale factors
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! diagnostics and outputs
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_floats  )   CALL flo_stp   ( kstp, Nbb, Nnn )      ! drifting Floats
-      IF( ln_diacfl  )   CALL dia_cfl   ( kstp,      Nnn )      ! Courant number diagnostics
-    
-                         CALL dia_wri   ( kstp,      Nnn )      ! ocean model: outputs
-      !
-      IF( lrst_oce   )   CALL rst_write    ( kstp, Nbb, Nnn )   ! write output ocean restart file
-          
-
-#if defined key_agrif
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! AGRIF
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<      
-                         Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs      ! agrif_oce module copies of time level indices
-                         CALL Agrif_Integrate_ChildGrids( stp )       ! allows to finish all the Child Grids before updating
-
-                         IF( Agrif_NbStepint() == 0 ) THEN
-                            CALL Agrif_update_all( )                  ! Update all components
-                         ENDIF
-#endif
-      IF( ln_diaobs  )   CALL dia_obs      ( kstp, Nnn )      ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Control
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL stp_ctl      ( kstp, Nbb, Nnn, 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
-
-      !
-#if defined key_iomput
-      IF( kstp == nitend .OR. indic < 0 ) THEN 
-                      CALL iom_context_finalize(      cxios_context          ) ! needed for XIOS+AGRIF
-                      IF(lrxios) CALL iom_context_finalize(      crxios_context          )
-      ENDIF
-#endif
-      !
-      IF( l_1st_euler ) THEN         ! recover Leap-frog timestep
-         rDt = 2._wp * rn_Dt   
-         r1_Dt = 1._wp / rDt
-         l_1st_euler = .FALSE.      
-      ENDIF
-      !
-      IF( ln_timing )   CALL timing_stop('stp')
-      !
-   END SUBROUTINE stp
-#endif
-   !
-   !!======================================================================
-END MODULE step
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/stpRK3.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/stpRK3.F90	(revision 13603)
+++ NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/stpRK3.F90	(revision 13604)
@@ -1,19 +1,20 @@
 MODULE stpRK3
    !!======================================================================
-   !!                       ***  MODULE step  ***
+   !!                       ***  MODULE stpRK3  ***
    !! Time-stepping   : manager of the shallow water equation time stepping
+   !!                   3rd order Runge-Kutta scheme
    !!======================================================================
    !! History :  NEMO !  2020-03  (A. Nasser, G. Madec)  Original code from  4.0.2
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   stpRK3             : Shallow Water time-stepping
-   !!----------------------------------------------------------------------
-   USE step_oce         ! time stepping definition modules
-   USE phycst           ! physical constants
-   USE usrdef_nam
+   !!             -   !  2020-10  (S. Techene, G. Madec)  cleanning
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   stp_RK3       : RK3 Shallow Water Eq. time-stepping
+   !!----------------------------------------------------------------------
+   USE stp_oce        ! modules used in nemo_init and stp_RK3
    !
-   USE iom              ! xIOs server 
-   USE domqco
+   USE domqco         ! quasi-eulerian coordinate
+   USE phycst         ! physical constants
+   USE usrdef_nam     ! user defined namelist parameters
 
    IMPLICIT NONE
@@ -21,9 +22,7 @@
 
    PUBLIC   stp_RK3   ! called by nemogcm.F90
-   
-   !!----------------------------------------------------------------------
-   !! time level indices
-   !!----------------------------------------------------------------------
-   INTEGER, PUBLIC ::   Nbb, Nnn, Naa, Nrhs   !! used by nemo_init
+
+   !                                          !**  time level indices  **!
+   INTEGER, PUBLIC ::   Nbb, Nnn, Naa, Nrhs   !: used by nemo_init
       
    !! * Substitutions
@@ -37,45 +36,40 @@
 CONTAINS
 
-#if defined key_agrif
-   RECURSIVE SUBROUTINE stp_RK3( )
-      INTEGER             ::   kstp   ! ocean time-step index
-#else
    SUBROUTINE stp_RK3( kstp )
-      INTEGER, INTENT(in) ::   kstp   ! ocean time-step index
-#endif
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE stp_RK3  ***
       !!
-      !! ** Purpose : - Time stepping of shallow water (SHW) (momentum and ssh eqs.)
+      !! ** Purpose : - RK3 Time stepping scheme for shallow water Eq.
       !!
-      !! ** Method  : -1- Update forcings
-      !!              -2- Update the ssh at Naa
-      !!              -3- Compute the momentum trends (Nrhs)
-      !!              -4- Update the horizontal velocity
-      !!              -5- Apply Asselin time filter to uu,vv,ssh
-      !!              -6- Outputs and diagnostics
+      !! ** Method  : 3rd order time stepping scheme which has 3 stages
+      !!       * Update calendar and forcings
+      !!       stage 1   : n ==> n+1/3 using variables at n
+      !!                 - Compute the rhs of momentum
+      !!                 - Time step ssh at Naa (n+1/3)
+      !!                 - Time step u,v at Naa (n+1/3)
+      !!                 - Swap time indices
+      !!       stage 2   : n ==> n+1/2 using variables at n and n+1/3
+      !!                 - Compute the rhs of momentum
+      !!                 - Time step ssh at Naa (n+1/2)
+      !!                 - Time step u,v at Naa (n+1/2)
+      !!                 - Swap time indices
+      !!       stage 3   : n ==> n+1 using variables at n and n+1/2
+      !!                 - Compute the rhs of momentum
+      !!                 - Time step ssh at Naa (n+1)
+      !!                 - Time step u,v at Naa (n+1)
+      !!                 - Swap time indices
+      !!       * Outputs and diagnostics
+      !!
+      !!       NB: in stages 1 and 2 lateral mixing and forcing are not taken
+      !!           into account in the momentum RHS execpt if key_RK3all is used
       !!----------------------------------------------------------------------
+      INTEGER, INTENT(in   ) ::   kstp   ! ocean time-step index
+      !
       INTEGER ::   ji, jj, jk   ! dummy loop indice
       INTEGER ::   indic        ! error indicator if < 0
-!!gm kcall can be removed, I guess
-      INTEGER ::   kcall        ! optional integer argument (dom_vvl_sf_nxt)
       REAL(wp)::   z1_2rho0,  z5_6,  z3_4  ! local scalars
-      
-      REAL(wp) ::   zue3a, zue3n, zue3b    ! local scalars
-      REAL(wp) ::   zve3a, zve3n, zve3b    !   -      -
-      REAL(wp) ::   ze3t_tf, ze3u_tf, ze3v_tf, zua, zva
+      REAL(wp)::   zue3a, zue3b, zua    ! local scalars
+      REAL(wp)::   zve3a, zve3b, zva    !   -      -
       !! ---------------------------------------------------------------------
-#if defined key_agrif
-      kstp = nit000 + Agrif_Nb_Step()
-      Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
-      IF( lk_agrif_debug ) THEN
-         IF( Agrif_Root() .and. lwp)   WRITE(*,*) '---'
-         IF(lwp)   WRITE(*,*) 'Grid Number', Agrif_Fixed(),' time step ', kstp, 'int tstep', Agrif_NbStepint()
-      ENDIF
-      IF( kstp == nit000 + 1 )   lk_agrif_fstep = .FALSE.
-# if defined key_iomput
-      IF( Agrif_Nbstepint() == 0 )   CALL iom_swap( cxios_context )
-# endif
-#endif
       !
       IF( ln_timing )   CALL timing_start('stp_RK3')
@@ -93,29 +87,22 @@
                              indic = 0                ! reset to no error condition
                              
-      IF( kstp == nit000 ) THEN                       ! initialize IOM context (must be done after nemo_init for AGRIF+XIOS+OASIS)
-                             CALL iom_init( cxios_context, ld_closedef=.FALSE. )   ! for model grid (including passible AGRIF zoom)
-         IF( lk_diamlr   )   CALL dia_mlr_iom_init    ! with additional setup for multiple-linear-regression analysis
+      IF( kstp == nit000 ) THEN                       ! initialize IOM context
+                             CALL iom_init( cxios_context, ld_closedef=.FALSE. )   ! for model grid (including possible AGRIF zoom)
                              CALL iom_init_closedef
-         IF( ln_crs      )   CALL iom_init( TRIM(cxios_context)//"_crs" )  ! for coarse grid
       ENDIF
       IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
                              CALL iom_setkt( kstp - nit000 + 1,      cxios_context          )   ! tell IOM we are at time step kstp
-      IF( ln_crs         )   CALL iom_setkt( kstp - nit000 + 1, TRIM(cxios_context)//"_crs" )   ! tell IOM we are at time step kstp
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Update external forcing (tides, open boundaries, ice shelf interaction and surface boundary condition (including sea-ice)
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_tide    )   CALL tide_update( kstp )                     ! update tide potential
-      IF( ln_apr_dyn )   CALL sbc_apr ( kstp )                        ! atmospheric pressure (NB: call before bdy_dta which needs ssh_ib) 
-      IF( ln_bdy     )   CALL bdy_dta ( kstp, Nnn )                   ! update dynamic & tracer data at open boundaries
-                         CALL sbc     ( kstp, Nbb, Nnn )              ! Sea Boundary Condition
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Ocean physics update
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      !  LATERAL  PHYSICS
-      !                                                                        ! eddy diffusivity coeff.
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Update external forcing   (SWE: surface boundary condition only)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+                             CALL sbc     ( kstp, Nbb, Nnn )                   ! Sea Boundary Condition
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Ocean physics update   (SWE: eddy viscosity only)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
       IF( l_ldfdyn_time )   CALL ldf_dyn( kstp, Nbb )                          ! eddy viscosity coeff. 
-
 
       !======================================================================
@@ -127,23 +114,22 @@
       
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      !  RK3 1st stage Ocean dynamics : hdiv, ssh, e3, u, v, w
+      !  RK3 1st stage Ocean dynamics : u, v, ssh
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       rDt   = rn_Dt / 3._wp  
       r1_Dt = 1._wp / rDt
-      
-                            CALL ssh_nxt       ( kstp, Nbb, Nbb, ssh, Naa )    ! after ssh (includes call to div_hor)
-
-                         uu(:,:,:,Nrhs) = 0._wp            ! set dynamics trends to zero
-                         vv(:,:,:,Nrhs) = 0._wp
-
-                            CALL dyn_adv( kstp, Nbb, Nbb      , uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS
- 
-                            CALL dyn_vor( kstp,      Nbb      , uu, vv, Nrhs )  ! vorticity           	==> RHS
+      !
+      !                                 !==  RHS of the momentum Eq.  ==!
+      !
+      uu(:,:,:,Nrhs) = 0._wp                        ! set dynamics trends to zero
+      vv(:,:,:,Nrhs) = 0._wp
+
+      CALL dyn_adv( kstp, Nbb, Nbb, uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS
+      CALL dyn_vor( kstp,      Nbb, uu, vv, Nrhs )  ! vorticity           	==> RHS
 #if defined key_RK3all 
-                            CALL dyn_ldf( kstp, Nbb, Nbb      , uu, vv, Nrhs )  ! lateral mixing
-#endif
-      !
-!!an - calcul du gradient de pression horizontal (explicit)
-      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+      CALL dyn_ldf( kstp, Nbb, Nbb, uu, vv, Nrhs )  ! lateral mixing
+#endif
+      !
+      DO_3D( 0,0, 0,0, 1,jpkm1 )
+         !                                          ! horizontal pressure gradient
          uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) - grav * ( ssh(ji+1,jj,Nbb) - ssh(ji,jj,Nbb) ) * r1_e1u(ji,jj)
          vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) - grav * ( ssh(ji,jj+1,Nbb) - ssh(ji,jj,Nbb) ) * r1_e2v(ji,jj)
@@ -151,5 +137,5 @@
       !
 #if defined key_RK3all 
-      ! add wind stress forcing and layer linear friction to the RHS 
+      !                                             ! wind stress and layer friction
       z5_6 = 5._wp/6._wp
       DO_3D( 0, 0, 0, 0,1,jpkm1)
@@ -160,7 +146,33 @@
       END_3D
 #endif
-!!an
-                            CALL dom_qco_r3c   ( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )   ! "after" ssh./h._0 ratio explicit
-      IF( ln_dynadv_vec ) THEN      ! vector invariant form : applied on velocity
+!!!!st why not ?
+!!      z5_6 = 5._wp/6._wp
+!!      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+!!         !                                                              ! horizontal pressure gradient
+!!         zrhs_u =        - grav * ( ssh(ji+1,jj,Nnn) - ssh(ji,jj,Nnn) ) * r1_e1u(ji,jj)
+!!         zrhs_v =        - grav * ( ssh(ji,jj+1,Nnn) - ssh(ji,jj,Nnn) ) * r1_e2v(ji,jj)
+!!         !                                                              ! wind stress and layer friction
+!!#if defined key_RK3all
+!!         zrhs_u = zrhs_u + r1_rho0 * ( z5_6*utau_b(ji,jj) + (1._wp - z5_6)*utau(ji,jj) ) / e3u(ji,jj,jk,Nbb)   &
+!!            &                                  - rn_rfr * uu(ji,jj,jk,Nbb)
+!!         zrhs_v = zrhs_v + r1_rho0 * ( z5_6*vtau_b(ji,jj) + (1._wp - z5_6)*vtau(ji,jj) ) / e3v(ji,jj,jk,Nbb)   &
+!!            &                                  - rn_rfr * vv(ji,jj,jk,Nbb)
+!!         !                                                              ! ==> RHS
+!!#endif
+
+!!         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) + zrhs_u
+!!         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) + zrhs_v
+!!      END_3D
+!!!!st end
+      !
+      !                                 !==  Time stepping of ssh Eq.  ==!   (and update r3_Naa)
+      !
+      CALL ssh_nxt( kstp, Nbb, Nbb, ssh, Naa )      ! after ssh
+      !                                                                 ! after ssh/h_0 ratio explicit
+      CALL dom_qco_r3c( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )
+      !
+      !                                 !==  Time stepping of momentum Eq.  ==!
+      !
+      IF( ln_dynadv_vec ) THEN                      ! vector invariant form : applied on velocity
          DO_3D( 0, 0, 0, 0,1,jpkm1)
             uu(ji,jj,jk,Naa) = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
@@ -168,19 +180,21 @@
          END_3D          
       ELSE
-         DO_3D( 0, 0, 0, 0,1,jpkm1)       ! flux form : applied on thickness weighted velocity
-            uu(ji,jj,jk,Naa) = (         uu(ji,jj,jk,Nbb )*e3u(ji,jj,jk,Nbb)                              &
-               &                 + rDt * uu(ji,jj,jk,Nrhs)*e3t(ji,jj,jk,Nbb) * umask(ji,jj,jk)        )   &
-               &               /                           e3t(ji,jj,jk,Naa)
-            vv(ji,jj,jk,Naa) = (         vv(ji,jj,jk,Nbb )*e3v(ji,jj,jk,Nbb)                              &
-               &                 + rDt * vv(ji,jj,jk,Nrhs)*e3t(ji,jj,jk,Nbb) * vmask(ji,jj,jk)        )   &
-               &               /                           e3t(ji,jj,jk,Naa)
+         DO_3D( 0, 0, 0, 0,1,jpkm1)                 ! flux form : applied on thickness weighted velocity
+            zue3b = e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nbb)
+            zve3b = e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nbb)
+            zue3a = zue3b + rDt * e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
+            zve3a = zve3b + rDt * e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
+            !
+            uu(ji,jj,jk,Naa) = zue3a / e3u(ji,jj,jk,Naa)    
+            vv(ji,jj,jk,Naa) = zve3a / e3v(ji,jj,jk,Naa)
          END_3D
       ENDIF
-      ! Swap time levels
+      !
+      !                                 !==  Swap time levels  ==!
+      !
       Nrhs= Nnn
       Nnn = Naa
       Naa = Nrhs
 
-      
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       !  RK3 2nd stage Ocean dynamics : hdiv, ssh, e3, u, v, w
@@ -188,26 +202,23 @@
       rDt   = rn_Dt / 2._wp  
       r1_Dt = 1._wp / rDt
-      
-                            CALL ssh_nxt       ( kstp, Nbb, Nnn, ssh, Naa )    ! after ssh (includes call to div_hor)
-
-                         uu(:,:,:,Nrhs) = 0._wp            ! set dynamics trends to zero
-                         vv(:,:,:,Nrhs) = 0._wp
-!!st TBC for dyn_adv
-                            CALL dyn_adv( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS 
- 
-                            CALL dyn_vor( kstp,      Nnn      , uu, vv, Nrhs )  ! vorticity           	==> RHS
+      !
+      !                                 !==  RHS of the momentum Eq.  ==!
+      !
+      uu(:,:,:,Nrhs) = 0._wp                        ! set dynamics trends to zero
+      vv(:,:,:,Nrhs) = 0._wp
+      CALL dyn_adv( kstp, Nbb, Nnn, uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS 
+      CALL dyn_vor( kstp,      Nnn, uu, vv, Nrhs )  ! vorticity           	==> RHS
 #if defined key_RK3all  
-                            CALL dyn_ldf( kstp, Nbb, Nbb      , uu, vv, Nrhs )  ! lateral mixing
-#endif
-                            
-      !
-!!an - calcul du gradient de pression horizontal (explicit)
+      CALL dyn_ldf( kstp, Nbb, Nbb, uu, vv, Nrhs )  ! lateral mixing
+#endif
+      !
       DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+         !                                          ! horizontal pressure gradient
          uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) - grav * ( ssh(ji+1,jj,Nnn) - ssh(ji,jj,Nnn) ) * r1_e1u(ji,jj)
          vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) - grav * ( ssh(ji,jj+1,Nnn) - ssh(ji,jj,Nnn) ) * r1_e2v(ji,jj)
       END_3D
       !
-      ! add wind stress forcing and layer linear friction to the RHS 
 #if defined key_RK3all
+      !                                             ! wind stress and layer friction
       z3_4 = 3._wp/4._wp
       DO_3D( 0, 0, 0, 0,1,jpkm1)
@@ -218,7 +229,14 @@
       END_3D
 #endif
-!!an
-                           CALL dom_qco_r3c   ( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )   ! "after" ssh./h._0 ratio explicit
-      IF( ln_dynadv_vec ) THEN      ! vector invariant form : applied on velocity
+      !
+      !                                 !==  Time stepping of ssh Eq.  ==!   (and update r3_Naa)
+      !
+      CALL ssh_nxt( kstp, Nbb, Nnn, ssh, Naa )      ! after ssh
+      !                                                                 ! after ssh/h_0 ratio explicit
+      CALL dom_qco_r3c( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )
+      !
+      !                                 !==  Time stepping of momentum Eq.  ==!
+      !
+      IF( ln_dynadv_vec ) THEN                      ! vector invariant form : applied on velocity
          DO_3D( 0, 0, 0, 0,1,jpkm1)
             uu(ji,jj,jk,Naa) = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
@@ -226,14 +244,17 @@
          END_3D          
       ELSE
-         DO_3D( 0, 0, 0, 0,1,jpkm1)       ! flux form : applied on thickness weighted velocity
-            uu(ji,jj,jk,Naa) = (         uu(ji,jj,jk,Nbb )*e3u(ji,jj,jk,Nbb)                              &
-               &                 + rDt * uu(ji,jj,jk,Nrhs)*e3t(ji,jj,jk,Nnn) * umask(ji,jj,jk)        )   &
-               &               /                           e3t(ji,jj,jk,Naa)
-            vv(ji,jj,jk,Naa) = (         vv(ji,jj,jk,Nbb )*e3v(ji,jj,jk,Nbb)                              &
-               &                 + rDt * vv(ji,jj,jk,Nrhs)*e3t(ji,jj,jk,Nnn) * vmask(ji,jj,jk)        )   &
-               &               /                           e3t(ji,jj,jk,Naa)
+         DO_3D( 0, 0, 0, 0,1,jpkm1)                 ! flux form : applied on thickness weighted velocity
+            zue3b = e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nbb)
+            zve3b = e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nbb)
+            zue3a = zue3b + rDt * e3u(ji,jj,jk,Nnn) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
+            zve3a = zve3b + rDt * e3v(ji,jj,jk,Nnn) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
+            !
+            uu(ji,jj,jk,Naa) = zue3a / e3u(ji,jj,jk,Naa)    
+            vv(ji,jj,jk,Naa) = zve3a / e3v(ji,jj,jk,Naa)
          END_3D
       ENDIF
-      ! Swap time levels
+      !
+      !                                 !==  Swap time levels  ==!
+      !
       Nrhs= Nnn
       Nnn = Naa
@@ -245,29 +266,20 @@
       rDt   = rn_Dt
       r1_Dt = 1._wp / rDt
-
-                            CALL ssh_nxt       ( kstp, Nbb, Nnn, ssh, Naa )    ! after ssh (includes call to div_hor)
-      
-                         uu(:,:,:,Nrhs) = 0._wp            ! set dynamics trends to zero
-                         vv(:,:,:,Nrhs) = 0._wp
-
-      IF( ln_bdy     )      CALL bdy_dyn3d_dmp ( kstp, Nbb,      uu, vv, Nrhs )  ! bdy damping trends
-
-#if defined key_agrif
-      IF(.NOT. Agrif_Root())  & 
-               &            CALL Agrif_Sponge_dyn        ! momentum sponge
-#endif
-                            CALL dyn_adv( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS
- 
-                            CALL dyn_vor( kstp,      Nnn      , uu, vv, Nrhs )  ! vorticity           	==> RHS
- 
-                            CALL dyn_ldf( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! lateral mixing
-
-!!an - calcul du gradient de pression horizontal (explicit)
+      !
+      !                                 !==  RHS of the momentum Eq.  ==!
+      !
+      uu(:,:,:,Nrhs) = 0._wp                        ! set dynamics trends to zero
+      vv(:,:,:,Nrhs) = 0._wp
+      !
+      CALL dyn_adv( kstp, Nbb, Nnn, uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS
+      CALL dyn_vor( kstp,      Nnn, uu, vv, Nrhs )  ! vorticity           	==> RHS
+      CALL dyn_ldf( kstp, Nbb, Nnn, uu, vv, Nrhs )  ! lateral mixing
+
       DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+         !                                          ! horizontal pressure gradient
          uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) - grav * ( ssh(ji+1,jj,Nnn) - ssh(ji,jj,Nnn) ) * r1_e1u(ji,jj)
          vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) - grav * ( ssh(ji,jj+1,Nnn) - ssh(ji,jj,Nnn) ) * r1_e2v(ji,jj)
       END_3D
-      !
-      ! add wind stress forcing and layer linear friction to the RHS 
+      !                                             ! wind stress and layer friction
       z1_2rho0 = 0.5_wp * r1_rho0
       DO_3D( 0, 0, 0, 0,1,jpkm1)
@@ -276,8 +288,15 @@
          vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) + z1_2rho0 * ( vtau_b(ji,jj) + vtau(ji,jj) ) / e3v(ji,jj,jk,Nnn)   &
             &                                  - rn_rfr * vv(ji,jj,jk,Nbb)
-      END_3D   
-!!an         
-                            CALL dom_qco_r3c   ( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )   ! "after" ssh./h._0 ratio explicit      
-      IF( ln_dynadv_vec ) THEN      ! vector invariant form : applied on velocity
+      END_3D
+      !
+      !                                 !==  Time stepping of ssh Eq.  ==!   (and update r3_Naa)
+      !
+      CALL ssh_nxt( kstp, Nbb, Nnn, ssh, Naa )      ! after ssh
+      !                                                                 ! after ssh/h_0 ratio explicit
+      CALL dom_qco_r3c( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )
+      !
+      !                                 !==  Time stepping of momentum Eq.  ==!
+      !
+      IF( ln_dynadv_vec ) THEN                      ! vector invariant form : applied on velocity
          DO_3D( 1, 1, 1, 1,1,jpkm1)
             zua = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
@@ -291,64 +310,39 @@
          END_3D
          !
-      ELSE                          ! flux form : applied on thickness weighted velocity
+      ELSE                                          ! flux form : applied on thickness weighted velocity
          DO_3D( 1, 1, 1, 1,1,jpkm1)
-            zue3n = e3u(ji,jj,jk,Nnn) * uu(ji,jj,jk,Nnn)
-            zve3n = e3v(ji,jj,jk,Nnn) * vv(ji,jj,jk,Nnn)
             zue3b = e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nbb)
             zve3b = e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nbb)
-            !                                                ! LF time stepping
-            zue3a = zue3b + rDt * e3t(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-            zve3a = zve3b + rDt * e3t(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
+            zue3a = zue3b + rDt * e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
+            zve3a = zve3b + rDt * e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
             !
-            uu(ji,jj,jk,Naa) = zue3a / e3t(ji,jj,jk,Naa)    
-            vv(ji,jj,jk,Naa) = zve3a / e3t(ji,jj,jk,Naa)
+            uu(ji,jj,jk,Naa) = zue3a / e3u(ji,jj,jk,Naa)    
+            vv(ji,jj,jk,Naa) = zve3a / e3v(ji,jj,jk,Naa)
          END_3D
-!!st je ne comprends pas l'histoire des e3t et du Nbb et pas du Nnn pour le rhs ?        
-      ENDIF
-
+      ENDIF
 
       CALL lbc_lnk_multi( 'stp_RK3', uu(:,:,:,Nnn), 'U', -1., vv(:,:,:,Nnn), 'V', -1.,   &   !* local domain boundaries
-         &                       uu(:,:,:,Naa), 'U', -1., vv(:,:,:,Naa), 'V', -1.    )     
-
-!!an         
-
-
-      ! Swap time levels
+         &                           uu(:,:,:,Naa), 'U', -1., vv(:,:,:,Naa), 'V', -1.    )     
+      !
+      !                                 !==  Swap time levels  ==!
+      !
       Nrhs = Nbb
       Nbb = Naa
       Naa = Nrhs
-      !
-!                         CALL dom_vvl_sf_update_st( kstp, Nbb, Nnn, Naa )  ! recompute vertical scale factors
+
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! diagnostics and outputs
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_floats  )   CALL flo_stp   ( kstp, Nbb, Nnn )      ! drifting Floats
+      
       IF( ln_diacfl  )   CALL dia_cfl   ( kstp,      Nnn )      ! Courant number diagnostics
-    
                          CALL dia_wri   ( kstp,      Nnn )      ! ocean model: outputs
-
       !
       IF( lrst_oce   )   CALL rst_write    ( kstp, Nbb, Nnn )   ! write output ocean restart file
-          
-
-#if defined key_agrif
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! AGRIF
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<      
-                         Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs      ! agrif_oce module copies of time level indices
-                         CALL Agrif_Integrate_ChildGrids( stp_RK3 )       ! allows to finish all the Child Grids before updating
-
-                         IF( Agrif_NbStepint() == 0 ) THEN
-                            CALL Agrif_update_all( )                  ! Update all components
-                         ENDIF
-#endif
-      IF( ln_diaobs  )   CALL dia_obs      ( kstp, Nnn )      ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! Control
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL stp_ctl      ( kstp, Nbb, Nnn, indic )
-               
-                         
+                         CALL stp_ctl      ( kstp, Nnn )
+
       IF( kstp == nit000 ) THEN                          ! 1st time step only
                                         CALL iom_close( numror )   ! close input  ocean restart file
@@ -360,19 +354,12 @@
 #if defined key_iomput
       IF( kstp == nitend .OR. indic < 0 ) THEN 
-                      CALL iom_context_finalize(      cxios_context          ) ! needed for XIOS+AGRIF
-                      IF(lrxios) CALL iom_context_finalize(      crxios_context          )
-      ENDIF
-#endif
-      !
-      IF( l_1st_euler ) THEN         ! recover Leap-frog timestep
-         rDt = 2._wp * rn_Dt   
-         r1_Dt = 1._wp / rDt
-         l_1st_euler = .FALSE.      
-      ENDIF
+         CALL iom_context_finalize( cxios_context )
+      ENDIF
+#endif
       !
       IF( ln_timing )   CALL timing_stop('stp_RK3')
       !
    END SUBROUTINE stp_RK3
-   !
+
    !!======================================================================
 END MODULE stpRK3
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/stp_oce.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/stp_oce.F90	(revision 13604)
+++ NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/stp_oce.F90	(revision 13604)
@@ -0,0 +1,119 @@
+MODULE stp_oce
+   !!======================================================================
+   !!                       ***  MODULE stp_oce  ***
+   !! Ocean time-stepping : module used in both initialisation phase and time stepping
+   !!                                     (i.e. nemo_init and stp or stp_MLF routines)
+   !!======================================================================
+   !! History :   3.3  !  2010-08  (C. Ethe)  Original code - reorganisation of the initial phase
+   !!             3.7  !  2014-01  (G. Madec) LDF simplication 
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+
+   USE daymod          ! calendar                         (day     routine)
+
+   USE sbc_oce         ! surface boundary condition: ocean
+   USE sbcmod          ! surface boundary condition       (sbc     routine)
+   USE sbcrnf          ! surface boundary condition: runoff variables
+   USE sbccpl          ! surface boundary condition: coupled formulation (call send at end of step)
+   USE sbcapr          ! surface boundary condition: atmospheric pressure
+   USE sbcwave         ! Wave intialisation
+   USE tide_mod        ! tides
+
+   USE bdy_oce  , ONLY : ln_bdy
+   USE bdydta          ! open boundary condition data     (bdy_dta routine)
+   USE bdytra          ! bdy cond. for tracers            (bdy_tra routine)
+   USE bdydyn3d        ! bdy cond. for baroclinic vel.  (bdy_dyn3d routine)
+
+   USE isf_oce         ! ice shelf boundary condition
+   USE isfstp          ! ice shelf boundary condition     (isf_stp routine)
+
+   USE sshwzv          ! vertical velocity and ssh        (ssh_nxt routine)
+   !                                                      (ssh_swp routine)
+   !                                                      (wzv     routine)
+   USE domvvl          ! variable vertical scale factors  (dom_vvl_sf_nxt routine)
+   !                                                      (dom_vvl_sf_swp routine)
+   
+   USE divhor          ! horizontal divergence            (div_hor routine)
+   USE dynadv          ! advection                        (dyn_adv routine)
+   USE dynvor          ! vorticity term                   (dyn_vor routine)
+   USE dynhpg          ! hydrostatic pressure grad.       (dyn_hpg routine)
+   USE dynldf          ! lateral momentum diffusion       (dyn_ldf routine)
+   USE dynzdf          ! vertical diffusion               (dyn_zdf routine)
+   USE dynspg          ! surface pressure gradient        (dyn_spg routine)
+   USE dynatf          ! time-filtering                   (dyn_atf routine)
+
+   USE traqsr          ! solar radiation penetration      (tra_qsr routine)
+   USE traisf          ! ice shelf                        (tra_isf routine)
+   USE trasbc          ! surface boundary condition       (tra_sbc routine)
+   USE trabbc          ! bottom boundary condition        (tra_bbc routine)
+   USE trabbl          ! bottom boundary layer            (tra_bbl routine)
+   USE tradmp          ! internal damping                 (tra_dmp routine)
+   USE traadv          ! advection scheme control     (tra_adv_ctl routine)
+   USE traldf          ! lateral mixing                   (tra_ldf routine)
+   USE trazdf          ! vertical mixing                  (tra_zdf routine)
+   USE traatf          ! time filtering                   (tra_atf routine)
+   USE tranpc          ! non-penetrative convection       (tra_npc routine)
+
+   USE eosbn2          ! equation of state                (eos_bn2 routine)
+
+   USE stopar          ! Stochastic parametrization       (sto_par routine)
+   USE stopts 
+
+   USE ldfslp          ! iso-neutral slopes               (ldf_slp routine)
+   USE ldfdyn          ! lateral eddy viscosity coef.     (ldf_dyn routine)
+   USE ldftra          ! lateral eddy diffusive coef.     (ldf_tra routine)
+
+   USE zdf_oce         ! ocean vertical physics variables
+   USE zdfphy          ! vertical physics manager      (zdf_phy_init routine)
+   USE zdfdrg   , ONLY : ln_drgimp   ! implicit top/bottom friction
+   USE zdfosm   , ONLY : osm_rst, dyn_osm, tra_osm      ! OSMOSIS routines used in step.F90
+
+   USE diu_layers      ! diurnal SST bulk and coolskin routines
+   USE sbc_oce         ! surface fluxes  
+   
+   USE zpshde          ! partial step: hor. derivative     (zps_hde routine)
+
+   USE diawri          ! Standard run outputs             (dia_wri routine)
+   USE diaptr          ! poleward transports              (dia_ptr routine)
+   USE diadct          ! sections transports              (dia_dct routine)
+   USE diaar5          ! AR5 diagnosics                   (dia_ar5 routine)
+   USE diahth          ! thermocline depth                (dia_hth routine)
+   USE diahsb          ! heat, salt and volume budgets    (dia_hsb routine)
+   USE diacfl          ! CFL diagnostics                  (dia_cfl routine)
+   USE diaobs          ! Observation operator             (dia_obs routine)
+   USE diadetide       ! Weights computation for daily detiding of model diagnostics
+   USE diamlr          ! IOM context management for multiple-linear-regression analysis
+   USE flo_oce         ! floats variables
+   USE floats          ! floats computation               (flo_stp routine)
+
+   USE crsfld          ! Standard output on coarse grid   (crs_fld routine)
+
+   USE asminc          ! assimilation increments      (tra_asm_inc routine)
+   !                                                   (dyn_asm_inc routine)
+   USE asmbkg          ! writing out state trajectory
+   USE stpctl          ! time stepping control            (stp_ctl routine)
+   USE restart         ! ocean restart                    (rst_wri routine)
+   USE prtctl          ! Print control                    (prt_ctl routine)
+
+   USE in_out_manager  ! I/O manager
+   USE iom             !
+   USE lbclnk
+   USE timing          ! Timing
+
+#if defined key_iomput
+   USE xios            ! I/O server
+#endif
+#if defined key_agrif
+   USE agrif_oce_sponge ! Momemtum and tracers sponges
+   USE agrif_all_update ! Main update driver
+#endif
+#if defined key_top
+   USE trcstp, ONLY : trc_stp    ! passive tracer time-stepping      (trc_stp routine)
+#endif
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id$
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!======================================================================
+END MODULE stp_oce
Index: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/stpctl.F90
===================================================================
--- NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/stpctl.F90	(revision 13603)
+++ NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/stpctl.F90	(revision 13604)
@@ -3,12 +3,8 @@
    !!                       ***  MODULE  stpctl  ***
    !! Ocean run control :  gross check of the ocean time stepping
+   !!              *** Shallow Water Equation (SWE) case ***
+   !!               ( No test on temperature and salinity )
    !!======================================================================
-   !! History :  OPA  ! 1991-03  (G. Madec) Original code
-   !!            6.0  ! 1992-06  (M. Imbard)
-   !!            8.0  ! 1997-06  (A.M. Treguier)
-   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
-   !!            2.0  ! 2009-07  (G. Madec)  Add statistic for time-spliting
-   !!            3.7  ! 2016-09  (G. Madec)  Remove solver
-   !!            4.0  ! 2017-04  (G. Madec)  regroup global communications
+   !! History :  SWE  ! 2020-09  (A. Nasser, S. Techene ) OCE/stpctl adaptated to SWE
    !!----------------------------------------------------------------------
 
@@ -19,13 +15,13 @@
    USE dom_oce         ! ocean space and time domain variables 
    USE c1d             ! 1D vertical configuration
+   USE zdf_oce ,  ONLY : ln_zad_Aimp       ! ocean vertical physics variables
+   USE wet_dry,   ONLY : ll_wd, ssh_ref    ! reference depth for negative bathy
+   !
    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 zdf_oce ,  ONLY : ln_zad_Aimp       ! ocean vertical physics variables
-   USE wet_dry,   ONLY : ll_wd, ssh_ref    ! reference depth for negative bathy
-
    USE netcdf          ! NetCDF library
+
    IMPLICIT NONE
    PRIVATE
@@ -33,7 +29,8 @@
    PUBLIC stp_ctl           ! routine called by step.F90
 
-   INTEGER  ::   idrun, idtime, idssh, idu, ids1, ids2, idt1, idt2, idc1, idw1, istatus
-   LOGICAL  ::   lsomeoce
-!!stoops
+   INTEGER                ::   nrunid   ! netcdf file id
+   INTEGER, DIMENSION(2)  ::   nvarid   ! netcdf variable id
+!!SWE   INTEGER, DIMENSION(8)  ::   nvarid   ! netcdf variable id
+
 #  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
@@ -44,5 +41,5 @@
 CONTAINS
 
-   SUBROUTINE stp_ctl( kt, Kbb, Kmm, kindic )
+   SUBROUTINE stp_ctl( kt, Kmm )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE stp_ctl  ***
@@ -52,114 +49,252 @@
       !! ** Method  : - Save the time step in numstp
       !!              - Print it each 50 time steps
-      !!              - Stop the run IF problem encountered by setting indic=-3
-      !!                Problems checked: |ssh| maximum larger than 10 m
+      !!              - Stop the run IF problem encountered by setting nstop > 0
+      !!                Problems checked: e3t0+ssh minimum smaller that 0
       !!                                  |U|   maximum larger than 10 m/s 
-      !!                                  negative sea surface salinity
+      !!                                  ( not for SWE : negative sea surface salinity )
       !!
       !! ** Actions :   "time.step" file = last ocean time-step
       !!                "run.stat"  file = run statistics
-      !!                nstop indicator sheared among all local domain (lk_mpp=T)
+      !!                 nstop indicator sheared among all local domain
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
-      INTEGER, INTENT(in   ) ::   Kbb, Kmm      ! ocean time level index
-      INTEGER, INTENT(inout) ::   kindic   ! error indicator
-      !!
-      INTEGER                ::   ji, jj, jk          ! dummy loop indices
-      INTEGER, DIMENSION(2)  ::   ih                  ! min/max loc indices
-      INTEGER, DIMENSION(3)  ::   iu, is1, is2        ! min/max loc indices
-      REAL(wp)               ::   zzz                 ! local real 
-      REAL(wp), DIMENSION(3) ::   zmax
-      LOGICAL                ::   ll_wrtstp, ll_colruns, ll_wrtruns
-      CHARACTER(len=20) :: clname
-      !!----------------------------------------------------------------------
-      !
-      ll_wrtstp  = ( MOD( kt, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend )
-      ll_colruns = ll_wrtstp .AND. ( sn_cfctl%l_runstat )
-      ll_wrtruns = ll_colruns .AND. lwm
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'stp_ctl : time-stepping control'
-         WRITE(numout,*) '~~~~~~~'
-         !                                ! open time.step file
-         IF( lwm ) CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
-         !                                ! open run.stat file(s) at start whatever
-         !                                ! the value of sn_cfctl%ptimincr
-         IF( lwm .AND. ( sn_cfctl%l_runstat ) ) THEN
+      INTEGER, INTENT(in   ) ::   Kmm      ! ocean time level index
+      !!
+      INTEGER                         ::   ji                                    ! dummy loop indices
+      INTEGER                         ::   idtime, istatus
+!!SWE      INTEGER , DIMENSION(9)          ::   iareasum, iareamin, iareamax
+      INTEGER , DIMENSION(3)          ::   iareasum, iareamin, iareamax
+      INTEGER , DIMENSION(3,4)        ::   iloc                                  ! min/max loc indices
+      REAL(wp)                        ::   zzz                                   ! local real 
+!!SWE      REAL(wp), DIMENSION(9)          ::   zmax, zmaxlocal
+      REAL(wp), DIMENSION(3)          ::   zmax, zmaxlocal
+      LOGICAL                         ::   ll_wrtstp, ll_colruns, ll_wrtruns
+      LOGICAL, DIMENSION(jpi,jpj,jpk) ::   llmsk
+      CHARACTER(len=20)               ::   clname
+      !!----------------------------------------------------------------------
+      !
+      IF( nstop > 0 .AND. ngrdstop > -1 )   RETURN   !   stpctl was already called by a child grid
+      !
+      ll_wrtstp  = ( MOD( kt-nit000, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend )
+      ll_colruns = ll_wrtstp .AND. sn_cfctl%l_runstat .AND. jpnij > 1 
+      ll_wrtruns = ( ll_colruns .OR. jpnij == 1 ) .AND. lwm
+      !
+      IF( kt == nit000 ) THEN
+         !
+         IF( lwp ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'stp_ctl : time-stepping control'
+            WRITE(numout,*) '~~~~~~~'
+         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( ll_wrtruns ) THEN
+            !                             ! open run.stat     ascii file, done only by 1st subdomain
             CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
+            !                             ! open run.stat.nc netcdf file, done only by 1st subdomain
             clname = 'run.stat.nc'
             IF( .NOT. Agrif_Root() )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
-            istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, idrun )
-            istatus = NF90_DEF_DIM( idrun, 'time', NF90_UNLIMITED, idtime )
-            istatus = NF90_DEF_VAR( idrun, 'abs_ssh_max', NF90_DOUBLE, (/ idtime /), idssh )
-            istatus = NF90_DEF_VAR( idrun,   'abs_u_max', NF90_DOUBLE, (/ idtime /), idu   )
-            istatus = NF90_ENDDEF(idrun)
-         ENDIF
-      ENDIF
-      IF( kt == nit000 )   lsomeoce = COUNT( ssmask(:,:) == 1._wp ) > 0
-      !
-      IF(lwm .AND. ll_wrtstp) THEN        !==  current time step  ==!   ("time.step" file)
+            istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, nrunid )
+            istatus = NF90_DEF_DIM( nrunid, 'time', NF90_UNLIMITED, idtime )
+            istatus = NF90_DEF_VAR( nrunid, 'abs_ssh_max', NF90_DOUBLE, (/ idtime /), nvarid(1) )
+            istatus = NF90_DEF_VAR( nrunid,   'abs_u_max', NF90_DOUBLE, (/ idtime /), nvarid(2) )
+!!SWE            istatus = NF90_DEF_VAR( nrunid,       's_min', NF90_DOUBLE, (/ idtime /), nvarid(3) )
+!!SWE            istatus = NF90_DEF_VAR( nrunid,       's_max', NF90_DOUBLE, (/ idtime /), nvarid(4) )
+!!SWE            istatus = NF90_DEF_VAR( nrunid,       't_min', NF90_DOUBLE, (/ idtime /), nvarid(5) )
+!!SWE            istatus = NF90_DEF_VAR( nrunid,       't_max', NF90_DOUBLE, (/ idtime /), nvarid(6) )
+!!SWE            IF( ln_zad_Aimp ) THEN
+!!SWE               istatus = NF90_DEF_VAR( nrunid,   'Cf_max', NF90_DOUBLE, (/ idtime /), nvarid(7) )
+!!SWE               istatus = NF90_DEF_VAR( nrunid,'abs_wi_max',NF90_DOUBLE, (/ idtime /), nvarid(8) )
+!!SWE            ENDIF
+            istatus = NF90_ENDDEF(nrunid)
+         ENDIF
+         !    
+      ENDIF
+      !
+      !                                   !==              write current time step              ==!
+      !                                   !==  done only by 1st subdomain at writting timestep  ==!
+      IF( lwm .AND. ll_wrtstp ) THEN
          WRITE ( numstp, '(1x, i8)' )   kt
          REWIND( numstp )
       ENDIF
-      !
-      !                                   !==  test of extrema  ==!
-      IF( ll_wd ) THEN
-         zmax(1) = MAXVAL(  ABS( ssh(:,:,Kmm) + ssh_ref*tmask(:,:,1) )  )        ! ssh max 
+      !                                   !==            test of local extrema           ==!
+      !                                   !==  done by all processes at every time step  ==!
+!!SWE      llmsk(:,:,1) = ssmask(:,:) == 1._wp
+!!SWE      IF( ll_wd ) THEN
+!!SWE         zmax(1) = MAXVAL( ABS( ssh(:,:,Kmm) + ssh_ref ), mask = llmsk(:,:,1) )   ! ssh max
+!!SWE      ELSE
+!!SWE         zmax(1) = MAXVAL( ABS( ssh(:,:,Kmm)           ), mask = llmsk(:,:,1) )   ! ssh max
+!!SWE      ENDIF
+      zmax(1) = MINVAL( e3t_0(:,:,1)+ssh(:,:,Kmm)  )                              ! e3t_Kmm min
+!!SWE
+      llmsk(:,:,:) = umask(:,:,:) == 1._wp
+      zmax(2) = MAXVAL(  ABS( uu(:,:,:,Kmm) ), mask = llmsk )                     ! velocity max (zonal only)
+!!SWE      llmsk(:,:,:) = tmask(:,:,:) == 1._wp
+!!SWE      zmax(3) = MAXVAL( -ts(:,:,:,jp_sal,Kmm), mask = llmsk )                     ! minus salinity max
+!!SWE      zmax(4) = MAXVAL(  ts(:,:,:,jp_sal,Kmm), mask = llmsk )                     !       salinity max
+!!SWE      IF( ll_colruns .OR. jpnij == 1 ) THEN     ! following variables are used only in the netcdf file
+!!SWE         zmax(5) = MAXVAL( -ts(:,:,:,jp_tem,Kmm), mask = llmsk )                  ! minus temperature max
+!!SWE         zmax(6) = MAXVAL(  ts(:,:,:,jp_tem,Kmm), mask = llmsk )                  !       temperature max
+!!SWE         IF( ln_zad_Aimp ) THEN
+!!SWE            zmax(7) = MAXVAL(   Cu_adv(:,:,:)   , mask = llmsk )                  ! partitioning coeff. max
+!!SWE            llmsk(:,:,:) = wmask(:,:,:) == 1._wp
+!!SWE            zmax(8) = MAXVAL(  ABS( wi(:,:,:) ) , mask = llmsk )                  ! implicit vertical vel. max
+!!SWE         ELSE
+!!SWE            zmax(7:8) = 0._wp
+!!SWE         ENDIF
+!!SWE      ELSE
+!!SWE         zmax(5:8) = 0._wp
+!!SWE      ENDIF
+!!SWE      zmax(9) = REAL( nstop, wp )                                              ! stop indicator
+!!SWE
+      zmax(3) = REAL( nstop , wp )                                            ! stop indicator
+!!SWE
+      !                                   !==               get global extrema             ==!
+      !                                   !==  done by all processes if writting run.stat  ==!
+      IF( ll_colruns ) THEN
+         zmaxlocal(:) = zmax(:)
+         CALL mpp_max( "stpctl", zmax )          ! max over the global domain
+!!SWE         nstop = NINT( zmax(9) )                 ! update nstop indicator (now sheared among all local domains)
+         nstop = NINT( zmax(3) )                 ! update nstop indicator (now sheared among all local domains)
+      ENDIF
+      !                                   !==              write "run.stat" files              ==!
+      !                                   !==  done only by 1st subdomain at writting timestep  ==!
+      IF( ll_wrtruns ) THEN
+!!SWE         WRITE(numrun,9500) kt, zmax(1), zmax(2), -zmax(3), zmax(4)
+         WRITE(numrun,9500) kt, zmax(1), zmax(2)
+         istatus = NF90_PUT_VAR( nrunid, nvarid(1), (/ zmax(1)/), (/kt/), (/1/) )
+         istatus = NF90_PUT_VAR( nrunid, nvarid(2), (/ zmax(2)/), (/kt/), (/1/) )
+!!SWE         istatus = NF90_PUT_VAR( nrunid, nvarid(3), (/-zmax(3)/), (/kt/), (/1/) )
+!!SWE         istatus = NF90_PUT_VAR( nrunid, nvarid(4), (/ zmax(4)/), (/kt/), (/1/) )
+!!SWE         istatus = NF90_PUT_VAR( nrunid, nvarid(5), (/-zmax(5)/), (/kt/), (/1/) )
+!!SWE         istatus = NF90_PUT_VAR( nrunid, nvarid(6), (/ zmax(6)/), (/kt/), (/1/) )
+!!SWE         IF( ln_zad_Aimp ) THEN
+!!SWE            istatus = NF90_PUT_VAR( nrunid, nvarid(7), (/ zmax(7)/), (/kt/), (/1/) )
+!!SWE            istatus = NF90_PUT_VAR( nrunid, nvarid(8), (/ zmax(8)/), (/kt/), (/1/) )
+!!SWE         ENDIF
+         IF( kt == nitend )   istatus = NF90_CLOSE(nrunid)
+      ENDIF
+      !                                   !==               error handling               ==!
+      !                                   !==  done by all processes at every time step  ==!
+      !
+!!SWE specific : start
+      IF(   zmax(1) <=   0._wp .OR.           &               ! negative e3t_Kmm
+         &  zmax(2) >   10._wp .OR.           &               ! too large velocity ( > 10 m/s)
+         &  ISNAN( zmax(1) + zmax(2) ) .OR.   &               ! NaN encounter in the tests
+         &  ABS(   zmax(1) + zmax(2) ) > HUGE(1._wp) ) THEN   ! Infinity encounter in the tests
+         !
+         iloc(:,:) = 0
+         IF( ll_colruns ) THEN   ! zmax is global, so it is the same on all subdomains -> no dead lock with mpp_maxloc
+            ! first: close the netcdf file, so we can read it
+            IF( lwm .AND. kt /= nitend )   istatus = NF90_CLOSE(nrunid)
+            ! get global loc on the min/max
+            CALL mpp_minloc( 'stpctl', e3t_0(:,:,1) + ssh(:,:,Kmm), ssmask(:,:  ), zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
+            CALL mpp_maxloc( 'stpctl', ABS( uu(:,:,:,Kmm))        ,  umask(:,:,:), zzz, iloc(1:3,2) )
+            ! find which subdomain has the max.
+            iareamin(:) = jpnij+1   ;   iareamax(:) = 0   ;   iareasum(:) = 0
+            DO ji = 1, 3
+               IF( zmaxlocal(ji) == zmax(ji) ) THEN
+                  iareamin(ji) = narea   ;   iareamax(ji) = narea   ;   iareasum(ji) = 1
+               ENDIF
+            END DO
+            CALL mpp_min( "stpctl", iareamin )         ! min over the global domain
+            CALL mpp_max( "stpctl", iareamax )         ! max over the global domain
+            CALL mpp_sum( "stpctl", iareasum )         ! sum over the global domain
+         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) = MINLOC( e3t_0(:,:,1) + ssh(:,:,Kmm), mask = ssmask(:,:  ) == 1._wp ) + (/ nimpp - 1, njmpp - 1    /)
+            iloc(1:3,2) = MAXLOC( ABS(  uu(:,:,:,       Kmm)), mask =  umask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
+            iareamin(:) = narea   ;   iareamax(:) = narea   ;   iareasum(:) = 1         ! this is local information
+         ENDIF
+         !
+         WRITE(ctmp1,*) ' stp_ctl:  e3t0+ssh < 0 m  or  |U| > 10 m/s  or  NaN encounter in the tests'
+         CALL wrt_line( ctmp2, kt, 'e3t0+ssh min',  zmax(1), iloc(:,1), iareasum(1), iareamin(1), iareamax(1) )
+         CALL wrt_line( ctmp3, kt, '|U|   max'   ,  zmax(2), iloc(:,2), iareasum(2), iareamin(2), iareamax(2) )
+         IF( Agrif_Root() ) THEN
+            WRITE(ctmp6,*) '      ===> output of last computed fields in output.abort* files'
+         ELSE
+            WRITE(ctmp6,*) '      ===> output of last computed fields in '//TRIM(Agrif_CFixed())//'_output.abort* files'
+         ENDIF
+         !
+         CALL dia_wri_state( Kmm, 'output.abort' )     ! create an output.abort file
+         !
+         IF( ll_colruns .or. jpnij == 1 ) THEN   ! all processes synchronized -> use lwp to print in opened ocean.output files
+            IF(lwp) THEN   ;   CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ' ', ctmp6 )
+            ELSE           ;   nstop = MAX(1, nstop)   ! make sure nstop > 0 (automatically done when calling ctl_stop)
+            ENDIF
+         ELSE                                    ! only mpi subdomains with errors are here -> STOP now
+            CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp2, ctmp3, ' ', ctmp6 )
+         ENDIF
+         !
+      ENDIF
+!!SWE specific : end
+      !
+      IF( nstop > 0 ) THEN                                                  ! an error was detected and we did not abort yet...
+         ngrdstop = Agrif_Fixed()                                           ! store which grid got this error
+         IF( .NOT. ll_colruns .AND. jpnij > 1 )   CALL ctl_stop( 'STOP' )   ! we must abort here to avoid MPI deadlock
+      ENDIF
+      !
+!!SWE 9500  FORMAT(' it :', i8, '    |ssh|_max: ', D23.16, ' |U|_max: ', D23.16,' S_min: ', D23.16,' S_max: ', D23.16)
+9500  FORMAT(' it :', i8, '      e3t_min: ', D23.16, ' |U|_max: ', D23.16)
+      !
+   END SUBROUTINE stp_ctl
+
+
+   SUBROUTINE wrt_line( cdline, kt, cdprefix, pval, kloc, ksum, kmin, kmax )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE wrt_line  ***
+      !!
+      !! ** Purpose :   write information line
+      !!
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*),      INTENT(  out) ::   cdline
+      CHARACTER(len=*),      INTENT(in   ) ::   cdprefix
+      REAL(wp),              INTENT(in   ) ::   pval
+      INTEGER, DIMENSION(3), INTENT(in   ) ::   kloc
+      INTEGER,               INTENT(in   ) ::   kt, ksum, kmin, kmax
+      !
+      CHARACTER(len=80) ::   clsuff
+      CHARACTER(len=9 ) ::   clkt, clsum, clmin, clmax
+      CHARACTER(len=9 ) ::   cli, clj, clk
+      CHARACTER(len=1 ) ::   clfmt
+      CHARACTER(len=4 ) ::   cl4   ! needed to be able to compile with Agrif, I don't know why
+      INTEGER           ::   ifmtk
+      !!----------------------------------------------------------------------
+      WRITE(clkt , '(i9)') kt
+      
+      WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpnij  ,wp))) + 1     ! how many digits to we need to write ? (we decide max = 9)
+      !!! WRITE(clsum, '(i'//clfmt//')') ksum                   ! this is creating a compilation error with AGRIF
+      cl4 = '(i'//clfmt//')'   ;   WRITE(clsum, cl4) ksum
+      WRITE(clfmt, '(i1)') INT(LOG10(REAL(MAX(1,jpnij-1),wp))) + 1    ! how many digits to we need to write ? (we decide max = 9)
+      cl4 = '(i'//clfmt//')'   ;   WRITE(clmin, cl4) kmin-1
+                                   WRITE(clmax, cl4) kmax-1
+      !
+      WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpiglo,wp))) + 1      ! how many digits to we need to write jpiglo? (we decide max = 9)
+      cl4 = '(i'//clfmt//')'   ;   WRITE(cli, cl4) kloc(1)      ! this is ok with AGRIF
+      WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpjglo,wp))) + 1      ! how many digits to we need to write jpjglo? (we decide max = 9)
+      cl4 = '(i'//clfmt//')'   ;   WRITE(clj, cl4) kloc(2)      ! this is ok with AGRIF
+      !
+      IF( ksum == 1 ) THEN   ;   WRITE(clsuff,9100) TRIM(clmin)
+      ELSE                   ;   WRITE(clsuff,9200) TRIM(clsum), TRIM(clmin), TRIM(clmax)
+      ENDIF
+      IF(kloc(3) == 0) THEN
+         ifmtk = INT(LOG10(REAL(jpk,wp))) + 1                   ! how many digits to we need to write jpk? (we decide max = 9)
+         clk = REPEAT(' ', ifmtk)                               ! create the equivalent in blank string
+         WRITE(cdline,9300) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj), clk(1:ifmtk), TRIM(clsuff)
       ELSE
-         zmax(1) = MINVAL( e3t(:,:,1,Kmm)  )                                         ! ssh min
-      ENDIF
-      zmax(2) = MAXVAL(  ABS( uu(:,:,:,Kmm) )  )                                  ! velocity max (zonal only)
-      zmax(3) = REAL( nstop , wp )                                            ! stop indicator
-      !
-      IF( ll_colruns ) THEN
-         CALL mpp_max( "stpctl", zmax )          ! max over the global domain
-         nstop = NINT( zmax(3) )                 ! nstop indicator sheared among all local domains
-      ENDIF
-      !                                   !==  run statistics  ==!   ("run.stat" files)
-      IF( ll_wrtruns ) THEN
-         WRITE(numrun,9500) kt, zmax(1), zmax(2)
-         istatus = NF90_PUT_VAR( idrun, idssh, (/ zmax(1)/), (/kt/), (/1/) )
-         istatus = NF90_PUT_VAR( idrun,   idu, (/ zmax(2)/), (/kt/), (/1/) )
-         IF( MOD( kt , 100 ) == 0 ) istatus = NF90_SYNC(idrun)
-         IF( kt == nitend         ) istatus = NF90_CLOSE(idrun)
-      END IF
-      !                                   !==  error handling  ==!
-      IF( ( sn_cfctl%l_glochk .OR. lsomeoce ) .AND. (   &  ! domain contains some ocean points, check for sensible ranges
-         &  zmax(1) <    0._wp .OR.   &                    ! negative sea surface height 
-         &  zmax(2) >   10._wp .OR.   &                    ! too large velocity ( > 10 m/s)
-         &  ISNAN( zmax(1) + zmax(2) ) ) ) THEN            ! NaN encounter in the tests
-         IF( lk_mpp .AND. sn_cfctl%l_glochk ) THEN
-            ! have use mpp_max (because sn_cfctl%l_glochk=.T. and distributed)
-            CALL mpp_maxloc( 'stpctl', ABS(ssh(:,:,Kmm))        , ssmask(:,:)  , zzz, ih  )
-            CALL mpp_maxloc( 'stpctl', ABS(uu(:,:,:,Kmm))          , umask (:,:,:), zzz, iu  )
-         ELSE
-            ! find local min and max locations
-            ih(:)  = MAXLOC( ABS( ssh(:,:,Kmm)   )                              ) + (/ nimpp - 1, njmpp - 1    /)
-            iu(:)  = MAXLOC( ABS( uu  (:,:,:,Kmm) )                              ) + (/ nimpp - 1, njmpp - 1, 0 /)
-         ENDIF
-         
-         WRITE(ctmp1,*) ' stp_ctl: (e3t0) ssh < 0 m  or  |U| > 10 m/s  or  NaN encounter in the tests'
-         WRITE(ctmp2,9100) kt,   zmax(1), ih(1) , ih(2)
-         WRITE(ctmp3,9200) kt,   zmax(2), iu(1) , iu(2) , iu(3)
-         WRITE(ctmp4,*) '      ===> output of last computed fields in output.abort.nc file'
-         
-         CALL dia_wri_state( Kmm, 'output.abort' )     ! create an output.abort file
-         
-         IF( .NOT. sn_cfctl%l_glochk ) THEN
-            WRITE(ctmp8,*) 'E R R O R message from sub-domain: ', narea
-            CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp8, ' ', ctmp2, ctmp3, ctmp4 )
-         ELSE
-            CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ctmp4 )
-         ENDIF
-
-         kindic = -3
-         !
-      ENDIF
-      !
-9100  FORMAT (' kt=',i8,'   |ssh| min: ',1pg11.4,', at  i j  : ',2i5)
-9200  FORMAT (' kt=',i8,'   |U|   max: ',1pg11.4,', at  i j k: ',3i5)
-9500  FORMAT(' it :', i8, '    |ssh|_max: ', D23.16, ' |U|_max: ', D23.16)
-      !
-   END SUBROUTINE stp_ctl
+         WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpk,wp))) + 1      ! how many digits to we need to write jpk? (we decide max = 9)
+         !!! WRITE(clk, '(i'//clfmt//')') kloc(3)               ! this is creating a compilation error with AGRIF
+         cl4 = '(i'//clfmt//')'   ;   WRITE(clk, cl4) kloc(3)   ! this is ok with AGRIF
+         WRITE(cdline,9400) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj),    TRIM(clk), TRIM(clsuff)
+      ENDIF
+      !
+9100  FORMAT('MPI rank ', a)
+9200  FORMAT('found in ', a, ' MPI tasks, spread out among ranks ', a, ' to ', a)
+9300  FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j   ', a, ' ', a, ' ', a, ' ', a)
+9400  FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j k ', a, ' ', a, ' ', a, ' ', a)
+      !
+   END SUBROUTINE wrt_line
+
 
    !!======================================================================
