Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/tests/VORTEX/MY_SRC/domqco.F90
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/tests/VORTEX/MY_SRC/domqco.F90	(revision 13679)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/tests/VORTEX/MY_SRC/domqco.F90	(revision 13679)
@@ -0,0 +1,504 @@
+MODULE domqco
+   !!======================================================================
+   !!                       ***  MODULE domqco   ***
+   !! 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) add time level indices for prognostic variables
+   !!            4.x  !  2020-02  (S. Techene, G. Madec) quasi-eulerian coordinate (z* or s*) from domvvl
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dom_qco_init   : define initial vertical scale factors, depths and column thickness
+   !!   dom_qco_zgr    : Set ssh/h_0 ratio at t
+   !!   dom_qco_r3c    : Compute ssh/h_0 ratio at t-, u-, v-, and optionally f-points
+   !!       qco_rst_read : read/write restart file
+   !!       qco_ctl    : Check the vvl options
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE phycst         ! physical constant
+   USE dom_oce        ! ocean space and time domain
+   USE dynadv  , ONLY : ln_dynadv_vec
+   USE isf_oce        ! iceshelf cavities
+   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
+
+   PUBLIC  dom_qco_init       ! called by domain.F90
+   PUBLIC  dom_qco_zgr        ! called by isfcpl.F90
+   PUBLIC  dom_qco_r3c        ! called by steplf.F90
+
+   !                                                      !!* 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
+
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id: domvvl.F90 12377 2020-02-12 14:39:06Z acc $
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE dom_qco_init( Kbb, Kmm, Kaa )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE dom_qco_init  ***
+      !!
+      !! ** Purpose :  Initialization of all ssh. to h._0 ratio
+      !!
+      !! ** Method  :  - use restart file and/or initialize
+      !!               - compute ssh. to h._0 ratio
+      !!
+      !! ** Action  : - r3(t/u/v)_b
+      !!              - r3(t/u/v/f)_n
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Kaa   ! time level indices
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'dom_qco_init : Variable volume activated'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
+      !
+      CALL qco_ctl                            ! choose vertical coordinate (z_star, z_tilde or layer)
+      !              ! CAUTION COM A METTRE !!!
+!!st      CALL qco_rst_read2( nit000, Kbb, Kmm )  ! Read or initialize ssh_(Kbb/Kmm) and r3
+!!st CAUTION if read2 removed change restart.F90 ! 
+      !
+      CALL qco_rst_read( nit000, Kbb, Kmm )   ! Read or initialize ssh_(Kbb/Kmm)
+      !
+      CALL dom_qco_zgr( Kbb, Kmm, Kaa )       ! interpolation scale factor, depth and water column
+      !
+      IF(lwxios) THEN   ! define variables in restart file when writing with XIOS
+         CALL iom_set_rstw_var_active('sshb')
+         CALL iom_set_rstw_var_active('sshn')
+      ENDIF
+      !
+   END SUBROUTINE dom_qco_init
+
+
+   SUBROUTINE dom_qco_zgr( Kbb, Kmm, Kaa )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE dom_qco_init  ***
+      !!
+      !! ** Purpose :  Initialization of all ssh./h._0 ratio
+      !!
+      !! ** Method  :  - call domqco using Kbb and Kmm
+      !!
+      !! ** Action  : - r3(t/u/v)_b
+      !!              - r3(t/u/v/f)_n
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Kaa   ! time level indices
+      !!----------------------------------------------------------------------
+      !
+      !                    !== Set of all other vertical scale factors  ==!  (now and before)
+      !                                ! Horizontal interpolation of e3t
+      CALL dom_qco_r3c( ssh(:,:,Kbb), r3t(:,:,Kbb), r3u(:,:,Kbb), r3v(:,:,Kbb) )
+      CALL dom_qco_r3c( ssh(:,:,Kmm), r3t(:,:,Kmm), r3u(:,:,Kmm), r3v(:,:,Kmm), r3f(:,:) )
+      !
+#if defined key_agrif
+      ! We need to define r3[tuv](Kaa) for AGRIF initialisation (should not be a problem for the restartability...)
+      r3t(:,:,Kaa) = r3t(:,:,Kmm)
+      r3u(:,:,Kaa) = r3u(:,:,Kmm)
+      r3v(:,:,Kaa) = r3v(:,:,Kmm)
+#endif
+      !
+   END SUBROUTINE dom_qco_zgr
+
+
+   SUBROUTINE dom_qco_r3c( pssh, pr3t, pr3u, pr3v, pr3f )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE r3c  ***
+      !!
+      !! ** Purpose :   compute the filtered ratio ssh/h_0 at t-,u-,v-,f-points
+      !!
+      !! ** Method  : - compute the ssh at u- and v-points (f-point optional)
+      !!                   Vector Form : surface weighted averaging
+      !!                   Flux   Form : simple           averaging
+      !!              - compute the ratio ssh/h_0 at t-,u-,v-pts, (f-pt optional)
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:)          , INTENT(in   )  ::   pssh               ! sea surface height   [m]
+      REAL(wp), DIMENSION(:,:)          , INTENT(  out)  ::   pr3t, pr3u, pr3v   ! ssh/h0 ratio at t-, u-, v-,points  [-]
+      REAL(wp), DIMENSION(:,:), OPTIONAL, INTENT(  out)  ::   pr3f               ! ssh/h0 ratio at f-point   [-]
+      !
+      INTEGER ::   ji, jj   ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      !
+      pr3t(:,:) = pssh(:,:) * r1_ht_0(:,:)   !==  ratio at t-point  ==!
+      !
+      !
+      !                                      !==  ratio at u-,v-point  ==!
+      !
+!!st      IF( ln_dynadv_vec ) THEN                     !- Vector Form   (thickness weighted averaging)
+#if ! defined key_qcoTest_FluxForm
+      !                                ! no 'key_qcoTest_FluxForm' : surface weighted ssh average
+         DO_2D( 0, 0, 0, 0 )
+            pr3u(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)
+            pr3v(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
+!!st      ELSE                                         !- Flux Form   (simple averaging)
+#else
+         DO_2D( 0, 0, 0, 0 )
+            pr3u(ji,jj) = 0.5_wp * (  pssh(ji,jj) + pssh(ji+1,jj  )  ) * r1_hu_0(ji,jj)
+            pr3v(ji,jj) = 0.5_wp * (  pssh(ji,jj) + pssh(ji  ,jj+1)  ) * r1_hv_0(ji,jj)
+         END_2D
+!!st      ENDIF
+#endif         
+      !
+      IF( .NOT.PRESENT( pr3f ) ) THEN              !- lbc on ratio at u-, v-points only
+         CALL lbc_lnk_multi( 'dom_qco_r3c', pr3u, 'U', 1._wp, pr3v, 'V', 1._wp )
+         !
+         !
+      ELSE                                   !==  ratio at f-point  ==!
+         !
+!!st         IF( ln_dynadv_vec )   THEN                !- Vector Form   (thickness weighted averaging)
+#if ! defined key_qcoTest_FluxForm
+         !                                ! no 'key_qcoTest_FluxForm' : surface weighted ssh average
+
+            DO_2D( 0, 0, 0, 0 )                               ! start from 1 since lbc_lnk('F') doesn't update the 1st row/line
+               pr3f(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
+!!st         ELSE                                      !- Flux Form   (simple averaging)
+#else
+            DO_2D( 0, 0, 0, 0 )                               ! start from 1 since lbc_lnk('F') doesn't update the 1st row/line
+               pr3f(ji,jj) = 0.25_wp * (  pssh(ji,jj  ) + pssh(ji+1,jj  )  &
+                  &                     + pssh(ji,jj+1) + pssh(ji+1,jj+1)  ) * r1_hf_0(ji,jj)
+            END_2D
+!!st         ENDIF
+#endif
+         !                                                 ! lbc on ratio at u-,v-,f-points
+         CALL lbc_lnk_multi( 'dom_qco_r3c', pr3u, 'U', 1._wp, pr3v, 'V', 1._wp, pr3f, 'F', 1._wp )
+         !
+      ENDIF
+      !
+   END SUBROUTINE dom_qco_r3c
+
+
+   SUBROUTINE qco_rst_read( kt, Kbb, Kmm )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE qco_rst_read  ***
+      !!
+      !! ** Purpose :   Read ssh in restart file
+      !!
+      !! ** Method  :   use of IOM library
+      !!                if the restart does not contain ssh,
+      !!                it is set to the _0 values.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt         ! ocean time-step
+      INTEGER, INTENT(in) ::   Kbb, Kmm   ! ocean time level indices
+      !
+      INTEGER ::   ji, jj, jk
+      INTEGER ::   id1, id2     ! local integers
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_rstart ) THEN                   !* Read the restart file
+         CALL rst_read_open                  !  open the restart file if necessary
+         !
+         id1 = iom_varid( numror, 'sshb', ldstop = .FALSE. )
+         id2 = iom_varid( numror, 'sshn', ldstop = .FALSE. )
+         !
+         !                             ! --------- !
+         !                             ! all cases !
+         !                             ! --------- !
+         !
+         IF( MIN( id1, id2 ) > 0 ) THEN       ! all required arrays exist
+            CALL iom_get( numror, jpdom_auto, 'sshb'   , ssh(:,:,Kbb), ldxios = lrxios    )
+            CALL iom_get( numror, jpdom_auto, 'sshn'   , ssh(:,:,Kmm), ldxios = lrxios    )
+            ! needed to restart if land processor not computed
+            IF(lwp) write(numout,*) 'qco_rst_read : ssh(:,:,Kbb) and ssh(:,:,Kmm) found in restart files'
+            !!WHERE ( ssmask(:,:) == 0.0_wp )   !!gm/st ==> sm should not be necessary on ssh while it was required on e3
+            !!   ssh(:,:,Kmm) = 0._wp
+            !!   ssh(:,:,Kbb) = 0._wp
+            !!END WHERE
+            IF( l_1st_euler ) THEN
+               ssh(:,:,Kbb) = ssh(:,:,Kmm)
+            ENDIF
+         ELSE IF( id1 > 0 ) THEN
+            IF(lwp) write(numout,*) 'qco_rst_read WARNING : ssh(:,:,Kmm) not found in restart files'
+            IF(lwp) write(numout,*) 'sshn set equal to sshb.'
+            IF(lwp) write(numout,*) 'neuler is forced to 0'
+            CALL iom_get( numror, jpdom_auto, 'sshb', ssh(:,:,Kbb), ldxios = lrxios )
+            ssh(:,:,Kmm) = ssh(:,:,Kbb)
+            l_1st_euler = .TRUE.
+         ELSE IF( id2 > 0 ) THEN
+            IF(lwp) write(numout,*) 'qco_rst_read WARNING : ssh(:,:,Kbb) not found in restart files'
+            IF(lwp) write(numout,*) 'sshb set equal to sshn.'
+            IF(lwp) write(numout,*) 'neuler is forced to 0'
+            CALL iom_get( numror, jpdom_auto, 'sshn', ssh(:,:,Kmm), ldxios = lrxios )
+            ssh(:,:,Kbb) = ssh(:,:,Kmm)
+            l_1st_euler = .TRUE.
+         ELSE
+            IF(lwp) write(numout,*) 'qco_rst_read WARNING : ssh(:,:,Kmm) not found in restart file'
+            IF(lwp) write(numout,*) 'ssh_b and ssh_n set to zero'
+            IF(lwp) write(numout,*) 'neuler is forced to 0'
+            ssh(:,:,:) = 0._wp
+            l_1st_euler = .TRUE.
+         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)  )
+               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
+            !
+            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( 'qco_rst_read: 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)  )
+!           !
+            ssh(:,:,:) = 0._wp
+            !
+         ENDIF           ! end of ll_wd edits
+         !
+      ENDIF
+      !
+   END SUBROUTINE qco_rst_read
+
+   
+   SUBROUTINE qco_rst_read2( kt, Kbb, Kmm )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE qco_rst_read  ***
+      !!
+      !! ** Purpose :   Read ssh in restart file
+      !!
+      !! ** Method  :   use of IOM library
+      !!                if the restart does not contain ssh,
+      !!                it is set to the _0 values.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt         ! ocean time-step
+      INTEGER, INTENT(in) ::   Kbb, Kmm   ! ocean time level indices
+      !
+      INTEGER ::   ji, jj, jk
+      INTEGER ::   id1, id2     ! local integers
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_rstart ) THEN                   !* Read the restart file
+         CALL rst_read_open                  !  open the restart file if necessary
+         !
+         id1 = iom_varid( numror, 'sshb', ldstop = .FALSE. )
+         id2 = iom_varid( numror, 'sshn', ldstop = .FALSE. )
+         !
+         !                             ! --------- !
+         !                             ! all cases !
+         !                             ! --------- !
+         !
+         IF( MIN( id1, id2 ) > 0 ) THEN       ! all required arrays exist
+            CALL iom_get( numror, jpdom_auto, 'sshb'   , ssh(:,:,Kbb), ldxios = lrxios    )
+            CALL iom_get( numror, jpdom_auto, 'sshn'   , ssh(:,:,Kmm), ldxios = lrxios    )
+            CALL iom_get( numror, jpdom_auto, 'r3tb'   , r3t(:,:,Kbb), ldxios = lrxios    )
+            CALL iom_get( numror, jpdom_auto, 'r3tn'   , r3t(:,:,Kmm), ldxios = lrxios    )
+            CALL iom_get( numror, jpdom_auto, 'r3ub'   , r3u(:,:,Kbb), ldxios = lrxios, cd_type = 'U'    )
+            CALL iom_get( numror, jpdom_auto, 'r3un'   , r3u(:,:,Kmm), ldxios = lrxios, cd_type = 'U'    )
+            CALL iom_get( numror, jpdom_auto, 'r3vb'   , r3v(:,:,Kbb), ldxios = lrxios, cd_type = 'V'    )
+            CALL iom_get( numror, jpdom_auto, 'r3vn'   , r3v(:,:,Kmm), ldxios = lrxios, cd_type = 'V'    )
+            CALL iom_get( numror, jpdom_auto, 'r3f'    , r3f(:,:)    , ldxios = lrxios, cd_type = 'F'    )
+            
+            ! needed to restart if land processor not computed
+            IF(lwp) write(numout,*) 'qco_rst_read : ssh(:,:,Kbb) and ssh(:,:,Kmm) found in restart files'
+            !!WHERE ( ssmask(:,:) == 0.0_wp )   !!gm/st ==> sm should not be necessary on ssh while it was required on e3
+            !!   ssh(:,:,Kmm) = 0._wp
+            !!   ssh(:,:,Kbb) = 0._wp
+            !!END WHERE
+            IF( l_1st_euler ) THEN
+               ssh(:,:,Kbb) = ssh(:,:,Kmm)
+            ENDIF
+         ELSE IF( id1 > 0 ) THEN
+            IF(lwp) write(numout,*) 'qco_rst_read WARNING : ssh(:,:,Kmm) not found in restart files'
+            IF(lwp) write(numout,*) 'sshn set equal to sshb.'
+            IF(lwp) write(numout,*) 'neuler is forced to 0'
+            CALL iom_get( numror, jpdom_auto, 'sshb', ssh(:,:,Kbb), ldxios = lrxios )
+            ssh(:,:,Kmm) = ssh(:,:,Kbb)
+            l_1st_euler = .TRUE.
+         ELSE IF( id2 > 0 ) THEN
+            IF(lwp) write(numout,*) 'qco_rst_read WARNING : ssh(:,:,Kbb) not found in restart files'
+            IF(lwp) write(numout,*) 'sshb set equal to sshn.'
+            IF(lwp) write(numout,*) 'neuler is forced to 0'
+            CALL iom_get( numror, jpdom_auto, 'sshn', ssh(:,:,Kmm), ldxios = lrxios )
+            ssh(:,:,Kbb) = ssh(:,:,Kmm)
+            l_1st_euler = .TRUE.
+         ELSE
+            IF(lwp) write(numout,*) 'qco_rst_read WARNING : ssh(:,:,Kmm) not found in restart file'
+            IF(lwp) write(numout,*) 'ssh_b and ssh_n set to zero'
+            IF(lwp) write(numout,*) 'neuler is forced to 0'
+            ssh(:,:,:) = 0._wp
+            l_1st_euler = .TRUE.
+         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)  )
+               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
+            !
+            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( 'qco_rst_read: 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)  )
+            !
+            ssh(:,:    ,Kmm) = ssh(:,:    ,Kbb) 
+!            ssh(:,:,:) = 0._wp
+!            r3t(:,:,:) = 0._wp
+!            r3u(:,:,:) = 0._wp
+!            r3v(:,:,:) = 0._wp
+!            r3f(:,:  ) = 0._wp
+            !
+         ENDIF           ! end of ll_wd edits
+         !
+      ENDIF
+      !
+   END SUBROUTINE qco_rst_read2
+
+
+   SUBROUTINE qco_ctl
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE qco_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,*) 'qco_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 qco_ctl
+
+   !!======================================================================
+END MODULE domqco
Index: /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/tests/VORTEX/cpp_VORTEX.fcm
===================================================================
--- /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/tests/VORTEX/cpp_VORTEX.fcm	(revision 13678)
+++ /NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/tests/VORTEX/cpp_VORTEX.fcm	(revision 13679)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys key_iomput key_mpp_mpi key_agrif
+ bld::tool::fppkeys key_iomput key_mpp_mpi key_agrif key_qco
