Index: NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/tests/VORTEX/MY_SRC/domvvl.F90
===================================================================
--- NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/tests/VORTEX/MY_SRC/domvvl.F90	(revision 13313)
+++ NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/tests/VORTEX/MY_SRC/domvvl.F90	(revision 13334)
@@ -9,14 +9,7 @@
    !!            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
+   !!            4.x  ! 2020-02  (G. Madec, S. Techene) introduce ssh to h0 ratio
    !!----------------------------------------------------------------------
 
-   !!----------------------------------------------------------------------
-   !!   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
-   !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers
    USE phycst          ! physical constant
@@ -33,12 +26,9 @@
    USE timing          ! Timing
 
+   USE agrif_oce ! initial state interpolation
+   USE agrif_oce_interp
+
    IMPLICIT NONE
    PRIVATE
-
-   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
 
    !                                                      !!* Namelist nam_vvl
@@ -63,4 +53,28 @@
    REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: frq_rst_hdv                 ! retoring period for low freq. divergence
 
+#if defined key_qco
+   !!----------------------------------------------------------------------
+   !!   'key_qco'      EMPTY MODULE      Quasi-Eulerian vertical coordonate
+   !!----------------------------------------------------------------------
+#else
+   !!----------------------------------------------------------------------
+   !!   Default key      Old management of time varying vertical coordinate
+   !!----------------------------------------------------------------------
+   
+   !!----------------------------------------------------------------------
+   !!   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
+   
    !! * Substitutions
 #  include "do_loop_substitute.h90"
@@ -135,5 +149,6 @@
       !
    END SUBROUTINE dom_vvl_init
-   !
+
+
    SUBROUTINE dom_vvl_zgr(Kbb, Kmm, Kaa)
       !!----------------------------------------------------------------------
@@ -261,6 +276,6 @@
             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   ;   
+                  ii0 = 103 + nn_hls - 1   ;   ii1 = 111 + nn_hls - 1      
+                  ij0 = 128 + nn_hls       ;   ij1 = 135 + nn_hls
                   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
@@ -450,9 +465,9 @@
             ELSE
                ijk_max = MAXLOC( ze3t(:,:,:) )
-               ijk_max(1) = mig0_oldcmp(ijk_max(1))
-               ijk_max(2) = mjg0_oldcmp(ijk_max(2))
+               ijk_max(1) = ijk_max(1) + nimpp - 1
+               ijk_max(2) = ijk_max(2) + njmpp - 1
                ijk_min = MINLOC( ze3t(:,:,:) )
-               ijk_min(1) = mig0_oldcmp(ijk_min(1))
-               ijk_min(2) = mjg0_oldcmp(ijk_min(2))
+               ijk_min(1) = ijk_min(1) + nimpp - 1
+               ijk_min(2) = ijk_min(2) + njmpp - 1
             ENDIF
             IF (lwp) THEN
@@ -792,13 +807,21 @@
          !                                   ! ===============
          IF( ln_rstart ) THEN                   !* Read the restart file
-            CALL rst_read_open                  !  open the restart file if necessary
-            CALL iom_get( numror, jpdom_auto, '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. )
-            !
+#if defined key_agrif
+            IF ( (.NOT.Agrif_root()).AND.(ln_init_chfrpar) ) THEN
+               ! skip reading restart if initialized from parent:
+               id1 = -1 ; id2 = -1 ; id3 = -1 ; id4 = -1 ; id5 = -1
+            ELSE
+#endif
+               CALL rst_read_open                  !  open the restart file if necessary
+               CALL iom_get( numror, jpdom_auto, '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. )
+#if defined key_agrif
+            ENDIF
+#endif
             !                             ! --------- !
             !                             ! all cases !
@@ -837,6 +860,6 @@
                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))
+                      &                            / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk)   &
+                      &            + e3t_0(:,:,jk)                               * (1._wp -tmask(:,:,jk))
                END DO
                e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
@@ -911,17 +934,17 @@
             ELSE
                !
-               ! usr_def_istate called here only to get ssh(Kbb) needed to initialize e3t(Kbb) and e3t(Kmm)
-               !
-               CALL usr_def_istate( gdept_0, tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )  
-               !
-               ! usr_def_istate will be called again in istate_init to initialize ts, ssh, u and v
+               ! 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)   &
-                    &            + e3t_0(:,:,jk) * ( 1._wp - tmask(:,:,jk) )   ! make sure e3t(:,:,:,Kbb) != 0 on land points
+                     &                             / ( ht_0(:,:) + 1._wp -ssmask(:,:) ) * tmask(:,:,jk) &
+                     &             + e3t_0(:,:,jk) * ( 1._wp - tmask(:,:,jk) )
                END DO
                e3t(:,:,:,Kmm) = e3t(:,:,:,Kbb)
-               ssh(:,:,Kmm) = ssh(:,:,Kbb)                                     ! needed later for gde3w
+!               ssh(:,:,Kmm)=0._wp
+!               e3t(:,:,:,Kmm)=e3t_0(:,:,:)
+!               e3t(:,:,:,Kbb)=e3t_0(:,:,:)
                !
             END IF           ! end of ll_wd edits
@@ -933,4 +956,18 @@
             END IF
          ENDIF
+
+#if defined key_agrif
+         IF ( .NOT.Agrif_root().AND.(ln_init_chfrpar) ) THEN
+            ! Interpolate initial ssh from parent:
+            CALL Agrif_istate_ssh( Kbb, Kmm )
+            !
+            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)
+         ENDIF
+#endif
          !
       ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
@@ -1030,4 +1067,6 @@
    END SUBROUTINE dom_vvl_ctl
 
+#endif
+
    !!======================================================================
 END MODULE domvvl
