Index: NEMO/trunk/src/OCE/DYN/sshwzv.F90
===================================================================
--- NEMO/trunk/src/OCE/DYN/sshwzv.F90	(revision 13497)
+++ NEMO/trunk/src/OCE/DYN/sshwzv.F90	(revision 14053)
@@ -6,9 +6,10 @@
    !! History :  3.1  !  2009-02  (G. Madec, M. Leclair)  Original code
    !!            3.3  !  2010-04  (M. Leclair, G. Madec)  modified LF-RA 
-   !!             -   !  2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
-   !!             -   !  2010-09  (D.Storkey and E.O'Dea) bug fixes for BDY module
-   !!            3.3  !  2011-10  (M. Leclair) split former ssh_wzv routine and remove all vvl related work
-   !!            4.0  !  2018-12  (A. Coward) add mixed implicit/explicit advection
-   !!            4.1  !  2019-08  (A. Coward, D. Storkey) Rename ssh_nxt -> ssh_atf. Now only does time filtering.
+   !!             -   !  2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea)  Assimilation interface
+   !!             -   !  2010-09  (D.Storkey and E.O'Dea)  bug fixes for BDY module
+   !!            3.3  !  2011-10  (M. Leclair)  split former ssh_wzv routine and remove all vvl related work
+   !!            4.0  !  2018-12  (A. Coward)  add mixed implicit/explicit advection
+   !!            4.1  !  2019-08  (A. Coward, D. Storkey)  Rename ssh_nxt -> ssh_atf. Now only does time filtering.
+   !!             -   !  2020-08  (S. Techene, G. Madec)  add here ssh initiatlisation
    !!----------------------------------------------------------------------
 
@@ -17,4 +18,5 @@
    !!   ssh_atf       : time filter the ssh arrays
    !!   wzv           : compute now vertical velocity
+   !!   ssh_init_rst  : ssh set from restart or domcfg.nc file or usr_def_istat_ssh
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and tracers variables
@@ -40,17 +42,18 @@
    USE timing         ! Timing
    USE wet_dry        ! Wetting/Drying flux limiting
-
+   USE usrdef_istate, ONLY : usr_def_istate_ssh   ! user defined ssh initial state 
+   
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   ssh_nxt    ! called by step.F90
-   PUBLIC   wzv        ! called by step.F90
-   PUBLIC   wAimp      ! called by step.F90
-   PUBLIC   ssh_atf    ! called by step.F90
+   PUBLIC   ssh_nxt        ! called by step.F90
+   PUBLIC   wzv            ! called by step.F90
+   PUBLIC   wAimp          ! called by step.F90
+   PUBLIC   ssh_atf        ! called by step.F90
+   PUBLIC   ssh_init_rst   ! called by domain.F90
 
    !! * Substitutions
 #  include "do_loop_substitute.h90"
 #  include "domzgr_substitute.h90"
-
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
@@ -299,4 +302,5 @@
          !                                                  ! filtered "now" field
          pssh(:,:,Kmm) = pssh(:,:,Kmm) + rn_atfp * ( pssh(:,:,Kbb) - 2 * pssh(:,:,Kmm) + pssh(:,:,Kaa) )
+         !
          IF( .NOT.ln_linssh ) THEN                          ! "now" <-- with forcing removed
             zcoef = rn_atfp * rn_Dt * r1_rho0
@@ -307,10 +311,11 @@
 
             ! ice sheet coupling
-            IF ( ln_isf .AND. ln_isfcpl .AND. kt == nit000+1) pssh(:,:,Kbb) = pssh(:,:,Kbb) - rn_atfp * rn_Dt * ( risfcpl_ssh(:,:) - 0.0 ) * ssmask(:,:)
+            IF( ln_isf .AND. ln_isfcpl .AND. kt == nit000+1 )   &
+               &   pssh(:,:,Kbb) = pssh(:,:,Kbb) - rn_atfp * rn_Dt * ( risfcpl_ssh(:,:) - 0.0 ) * ssmask(:,:)
 
          ENDIF
       ENDIF
       !
-      IF(sn_cfctl%l_prtctl)   CALL prt_ctl( tab2d_1=pssh(:,:,Kmm), clinfo1=' pssh(:,:,Kmm)  - : ', mask1=tmask )
+      IF(sn_cfctl%l_prtctl)   CALL prt_ctl( tab2d_1=pssh(:,:,Kmm), clinfo1=' atf  - pssh(:,:,Kmm): ', mask1=tmask )
       !
       IF( ln_timing )   CALL timing_stop('ssh_atf')
@@ -431,4 +436,87 @@
       !
    END SUBROUTINE wAimp
+
+
+   SUBROUTINE ssh_init_rst( Kbb, Kmm, Kaa )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE ssh_init_rst  ***
+      !!
+      !! ** Purpose :   ssh initialization of the sea surface height (ssh)
+      !!
+      !! ** Method  :   set ssh from restart or read configuration, or user_def
+      !!              * ln_rstart = T
+      !!                   USE of IOM library to read ssh in the restart file
+      !!                   Leap-Frog: Kbb and Kmm are read except for l_1st_euler=T
+      !!
+      !!              * otherwise 
+      !!                   call user defined ssh or
+      !!                   set to -ssh_ref in wet and drying case with domcfg.nc
+      !!
+      !!              NB: ssh_b/n are written by restart.F90
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Kaa   ! ocean time level indices
+      !
+      INTEGER ::   ji, jj, jk
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ssh_init_rst : ssh initialization'
+         WRITE(numout,*) '~~~~~~~~~~~~ '
+      ENDIF
+      !
+      !                            !=============================!
+      IF( ln_rstart ) THEN         !==  Read the restart file  ==!
+         !                         !=============================!
+         !
+         !                                     !*  Read ssh at Kmm
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*)    '      Kmm sea surface height read in the restart file'
+         CALL iom_get( numror, jpdom_auto, 'sshn'   , ssh(:,:,Kmm) )
+         !
+         IF( l_1st_euler ) THEN                !* Euler at first time-step
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '      Euler first time step : ssh(Kbb) = ssh(Kmm)'
+            ssh(:,:,Kbb) = ssh(:,:,Kmm)
+            !
+         ELSE                                  !* read ssh at Kbb
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '      Kbb sea surface height read in the restart file'
+            CALL iom_get( numror, jpdom_auto, 'sshb', ssh(:,:,Kbb) )
+         ENDIF
+         !                         !============================!
+      ELSE                         !==  Initialize at "rest"  ==!
+         !                         !============================!
+         !
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*)    '      initialization at rest'
+         !
+         IF( ll_wd ) THEN                      !* wet and dry 
+            !
+            IF( ln_read_cfg  ) THEN                 ! read configuration : ssh_ref is read in domain_cfg file
+!!st  why ssh is not masked : i.e. ssh(:,:,Kmm) = -ssh_ref*ssmask(:,:),
+!!st  since at the 1st time step lbclnk will be applied on ssh at Kaa but not initially at Kbb and Kmm
+               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)
+                  ENDIF
+               END_2D
+            ELSE                                    ! user define configuration case  
+               CALL usr_def_istate_ssh( tmask, ssh(:,:,Kbb) )
+            ENDIF
+            !
+         ELSE                                  !* user defined configuration
+            CALL usr_def_istate_ssh( tmask, ssh(:,:,Kbb) )
+            !
+         ENDIF
+         !
+         ssh(:,:,Kmm) = ssh(:,:,Kbb)           !* set now values from to before ones
+         ssh(:,:,Kaa) = 0._wp 
+      ENDIF
+      !
+   END SUBROUTINE ssh_init_rst
+      
    !!======================================================================
 END MODULE sshwzv
