Index: branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfphy.F90
===================================================================
--- branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfini.F90	(revision 7931)
+++ branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfphy.F90	(revision 7953)
@@ -1,36 +1,39 @@
-MODULE zdfini
+MODULE zdfphy
    !!======================================================================
-   !!                      ***  MODULE  zdfini  ***
-   !! Ocean physics :   read vertical mixing namelist and check consistancy
+   !!                      ***  MODULE  zdfphy  ***
+   !! Ocean physics :   manager of vertical mixing parametrizations
    !!======================================================================
-   !! History :  8.0  ! 1997-06  (G. Madec)  Original code from inimix
-   !!            1.0  ! 2002-08  (G. Madec)  F90 : free form
-   !!             -   ! 2005-06  (C. Ethe) KPP scheme
-   !!             -   ! 2009-07  (G. Madec) add avmb, avtb in restart for cen2 advection
-   !!            3.7  ! 2014-12  (G. Madec) remove KPP scheme
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   zdf_init    : initialization, namelist read, and parameters control
-   !!----------------------------------------------------------------------
-   USE par_oce         ! mesh and scale factors
-   USE zdf_oce         ! TKE vertical mixing          
-   USE sbc_oce         ! surface module (only for nn_isf in the option compatibility test)
-   USE zdftke          ! TKE vertical mixing
-   USE zdfgls          ! GLS vertical mixing
-   USE zdfric          ! Richardson vertical mixing   
-   USE zdfddm          ! double diffusion mixing      
-   USE zdfevd          ! enhanced vertical diffusion  
-   USE tranpc          ! convection: non penetrative adjustment
-   USE ldfslp          ! iso-neutral slopes
+   !! History :  4.0  !  2017-04  (G. Madec)  original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   zdf_phy_init  : initialization of all vertical physics pakages
+   !!   zdf_phy       : upadate at each time-step the vertical mixing coeff. 
+   !!----------------------------------------------------------------------
+   USE par_oce        ! mesh and scale factors
+   USE zdf_oce        ! TKE vertical mixing          
+   USE sbc_oce        ! surface module (only for nn_isf in the option compatibility test)
+   USE zdfbfr         ! bottom friction
+   USE zdftke         ! TKE vertical mixing
+   USE zdfgls         ! GLS vertical mixing
+   USE zdfric         ! Richardson vertical mixing   
+   USE zdfddm         ! double diffusion mixing      
+   USE zdfevd         ! enhanced vertical diffusion
+   USE zdftmx         ! internal tide-induced mixing
+   USE zdfqiao          !Qiao module wave induced mixing   (zdf_qiao routine)
+   USE zdfmxl           ! Mixed-layer depth                (zdf_mxl routine)
+   USE tranpc         ! convection: non penetrative adjustment
+   USE sbcrnf         ! surface boundary condition: runoff variables
    !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! IOM library
-   USE lib_mpp         ! distribued memory computing
+   USE in_out_manager ! I/O manager
+   USE iom            ! IOM library
+   USE lib_mpp        ! distribued memory computing
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   zdf_init   ! routine called by opa.F90
+   PUBLIC   zdf_phy_init   ! routine called by nemogcm.F90
+   PUBLIC   zdf_phy        ! routine called by step.F90
+   
    
    !!----------------------------------------------------------------------
@@ -41,7 +44,7 @@
 CONTAINS
 
-   SUBROUTINE zdf_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE zdf_init  ***
+   SUBROUTINE zdf_phy_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_phy_init  ***
       !! 
       !! ** Purpose :   initializations of the vertical ocean physics
@@ -49,5 +52,5 @@
       !! ** Method  :   Read namelist namzdf, control logicals 
       !!----------------------------------------------------------------------
-      INTEGER ::   ioptio, ios       ! local integers
+      INTEGER ::   ioptio, ios   ! local integers
       !!
       NAMELIST/namzdf/ ln_zdfcst, ln_zdfric, ln_zdftke, ln_zdfgls,   &     ! type of closure scheme
@@ -77,5 +80,5 @@
       IF(lwp) THEN               !* Parameter print
          WRITE(numout,*)
-         WRITE(numout,*) 'zdf_init : vertical physics'
+         WRITE(numout,*) 'zdf_phy_init : vertical physics'
          WRITE(numout,*) '~~~~~~~~'
          WRITE(numout,*) '   Namelist namzdf : set vertical mixing mixing parameters'
@@ -106,9 +109,7 @@
       ENDIF
 
-      IF(ln_zdfddm) THEN                    ! double diffusive mixing'
-         ALLOCATE( avs(jpi,jpj,jpk) )
-         avs(:,:,:) = rn_avt0 * wmask(:,:,:) 
-      ENDIF
-
+!!gm      IF(ln_zdfddm) THEN                    ! double diffusive mixing'
+!         avs(:,:,:) = rn_avt0 * wmask(:,:,:) 
+!!gm      ENDIF
 
       !                          !* Parameter & logical controls
@@ -122,17 +123,17 @@
       IF(lwp) WRITE(numout,*) '   vertical mixing option :'
       ioptio = 0
-      IF( lk_zdfcst ) THEN
+      IF( ln_zdfcst ) THEN
          IF(lwp) WRITE(numout,*) '      constant eddy diffusion coefficients'
          ioptio = ioptio+1
       ENDIF
-      IF( lk_zdfric ) THEN
+      IF( ln_zdfric ) THEN
          IF(lwp) WRITE(numout,*) '      Richardson dependent eddy coefficients'
          ioptio = ioptio+1
       ENDIF
-      IF( lk_zdftke ) THEN
+      IF( ln_zdftke ) THEN
          IF(lwp) WRITE(numout,*) '      TKE dependent eddy coefficients'
          ioptio = ioptio+1
       ENDIF
-      IF( lk_zdfgls ) THEN
+      IF( ln_zdfgls ) THEN
          IF(lwp) WRITE(numout,*) '      GLS dependent eddy coefficients'
          ioptio = ioptio+1
@@ -140,5 +141,5 @@
       IF( ioptio == 0 .OR. ioptio > 1 )   &
          &   CALL ctl_stop( ' one and only one vertical diffusion option has to be defined ' )
-      IF( ( lk_zdfric .OR. lk_zdfgls ) .AND. ln_isfcav )   &
+      IF( ( ln_zdfric .OR. ln_zdfgls ) .AND. ln_isfcav )   &
          &   CALL ctl_stop( ' only zdfcst and zdftke were tested with ice shelves cavities ' )
       !
@@ -148,5 +149,5 @@
       !
 #if defined key_top
-      IF( ln_zdfnpc )   CALL ctl_stop( ' zdf_init: npc scheme is not working with key_top' )
+      IF( ln_zdfnpc )   CALL ctl_stop( ' zdf_phy_init: npc scheme is not working with key_top' )
 #endif
       !
@@ -160,12 +161,12 @@
          ioptio = ioptio+1
       ENDIF
-      IF( lk_zdftke ) THEN
+      IF( ln_zdftke ) THEN
          IF(lwp) WRITE(numout,*) '      use the 1.5 turbulent closure'
       ENDIF
-      IF( lk_zdfgls ) THEN
+      IF( ln_zdfgls ) THEN
          IF(lwp) WRITE(numout,*) '      use the GLS closure scheme'
       ENDIF
       IF ( ioptio > 1 )   CALL ctl_stop( ' chose between ln_zdfnpc and ln_zdfevd' )
-      IF( ioptio == 0 .AND. .NOT.( lk_zdftke .OR. lk_zdfgls ) )           &
+      IF( ioptio == 0 .AND. .NOT.( ln_zdftke .OR. ln_zdfgls ) )           &
          CALL ctl_stop( ' except for TKE or GLS physics, a convection scheme is',   &
          &              ' required: ln_zdfevd or ln_zdfnpc logicals' )
@@ -202,6 +203,80 @@
       ENDIF
       !
-   END SUBROUTINE zdf_init
+
+!!gm moved into zdf_phy_init
+!
+                            CALL zdf_bfr_init      ! bottom friction
+
+      ioptio = 0                 !==  type of vertical turbulent closure  ==!    (set nzdfphy)
+      !
+!      IF( ln_zdfcst ) THEN   ;   ioptio = ioptio + 1   ;    nzdf_phy = np_CST   ;   ENDIF
+!      IF( ln_zdfric ) THEN   ;   ioptio = ioptio + 1   ;    nzdf_phy = np_RIC   ;   CALL zdf_ric_init   ;   ENDIF
+!      IF( ln_zdftke ) THEN   ;   ioptio = ioptio + 1   ;    nzdf_phy = np_TKE   ;   CALL zdf_tke_init   ;   ENDIF
+!      IF( ln_zdfgls ) THEN   ;   ioptio = ioptio + 1   ;    nzdf_phy = np_GLS   ;   CALL zdf_gls_init   ;   ENDIF
+
+
+      !
+      IF( ln_zdfric     )   CALL zdf_ric_init      ! Richardson number dependent Kz
+      IF( ln_zdftke     )   CALL zdf_tke_init      ! TKE closure scheme
+      IF( ln_zdfgls     )   CALL zdf_gls_init      ! GLS closure scheme
+      IF( ln_zdftmx     )   CALL zdf_tmx_init      ! tidal vertical mixing
+!!gm
+      !
+   END SUBROUTINE zdf_phy_init
+
+
+   SUBROUTINE zdf_phy( kstp )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE zdf_phy  ***
+      !!
+      !! ** Purpose :  Update ocean physics at each time-step
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :   avm, avt vertical eddy viscosity and diffusivity at w-points
+      !!                nmld ??? mixed layer depth in level and meters   <<<<====verifier !
+      !!                bottom stress.....                               <<<<====verifier !
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kstp   ! ocean time-step index
+      !
+      INTEGER ::   ji, jj, jk    ! dummy loop indice
+      !!----------------------------------------------------------------------
+      !
+                         CALL zdf_bfr( kstp )         ! bottom friction (if quadratic)
+      !                                               ! Vertical eddy viscosity and diffusivity coefficients
+      IF( ln_zdfric  )   CALL zdf_ric ( kstp )             ! Richardson number dependent Kz
+      IF( ln_zdftke  )   CALL zdf_tke ( kstp )             ! TKE closure scheme for Kz
+      IF( ln_zdfgls  )   CALL zdf_gls ( kstp )             ! GLS closure scheme for Kz
+      IF( ln_zdfqiao )   CALL zdf_qiao( kstp )             ! Qiao vertical mixing 
+      !
+      IF( ln_zdfcst  ) THEN                                ! Constant Kz (reset avt, avm[uv] to the background value)
+         avt (:,:,:) = rn_avt0 * wmask (:,:,:)
+         avm (:,:,:) = rn_avm0 * wmask (:,:,:)
+         avmu(:,:,:) = rn_avm0 * wumask(:,:,:)
+         avmv(:,:,:) = rn_avm0 * wvmask(:,:,:)
+      ENDIF
+      !
+      IF( ln_rnf_mouth ) THEN                         ! increase diffusivity at rivers mouths
+         DO jk = 2, nkrnf   ;   avt(:,:,jk) = avt(:,:,jk) + 2._wp * rn_avt_rnf * rnfmsk(:,:) * tmask(:,:,jk)   ;   END DO
+      ENDIF
+      !
+      IF( ln_zdfevd  )   CALL zdf_evd( kstp )         ! enhanced vertical eddy diffusivity
+      !
+      IF( ln_zdfddm  ) THEN                           ! double diffusive mixing
+                         CALL zdf_ddm( kstp )
+      ELSE                                            ! avs=avt
+         DO jk = 2, jpkm1   ;   avs(:,:,jk) = avt(:,:,jk)   ;   END DO
+      ENDIF
+      !
+      IF( ln_zdftmx  )   CALL zdf_tmx( kstp )         ! tidal vertical mixing
+
+                         CALL zdf_mxl( kstp )         ! mixed layer depth
+
+                                                      ! write TKE or GLS information in the restart file
+      IF( lrst_oce .AND. ln_zdftke )   CALL tke_rst( kstp, 'WRITE' )
+      IF( lrst_oce .AND. ln_zdfgls )   CALL gls_rst( kstp, 'WRITE' )
+      !
+   END SUBROUTINE zdf_phy
 
    !!======================================================================
-END MODULE zdfini
+END MODULE zdfphy
