Index: /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg
===================================================================
--- /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg	(revision 12500)
+++ /NEMO/trunk/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg	(revision 12501)
@@ -28,5 +28,5 @@
 &namdom        !   time and space domain
 !-----------------------------------------------------------------------
-   rn_Dt      = 5400.     !  time step for the dynamics and tracer
+   rn_Dt       = 5400.     !  time step for the dynamics and tracer
 /
 !-----------------------------------------------------------------------
@@ -381,4 +381,14 @@
    ln_mevar    = .true.    !  variable (T) or constant (F) mixing efficiency
    ln_tsdiff   = .true.    !  account for differential T/S mixing (T) or not (F)
+
+   cn_dir      = './'      !  root directory for the iwm data location                                                                           
+   !___________!_________________________!___________________!___________!_____________!________!___________!__________________!__________!_______________!
+   !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
+   !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
+   sn_mpb      = 'mixing_power_bot'      , -12               , 'field'   , .false.  , .true. , 'yearly' , '' , ''  , ''
+   sn_mpp      = 'mixing_power_pyc'      , -12               , 'field'   , .false.  , .true. , 'yearly' , '' , ''  , ''
+   sn_mpc      = 'mixing_power_cri'      , -12               , 'field'   , .false.  , .true. , 'yearly' , '' , ''  , ''
+   sn_dsb      = 'decay_scale_bot'       , -12               , 'field'   , .false.  , .true. , 'yearly' , '' , ''  , ''
+   sn_dsc      = 'decay_scale_cri'       , -12               , 'field'   , .false.  , .true. , 'yearly' , '' , ''  , ''
 /
 !!======================================================================
Index: /NEMO/trunk/cfgs/SHARED/namelist_ref
===================================================================
--- /NEMO/trunk/cfgs/SHARED/namelist_ref	(revision 12500)
+++ /NEMO/trunk/cfgs/SHARED/namelist_ref	(revision 12501)
@@ -72,5 +72,5 @@
    ln_linssh   = .false.   !  =T  linear free surface  ==>>  model level are fixed in time
    !
-   rn_Dt      = 5400.     !  time step for the dynamics and tracer
+   rn_Dt       = 5400.     !  time step for the dynamics and tracer
    rn_atfp     =    0.1    !  asselin time filter parameter
    !
@@ -272,5 +272,5 @@
       rn_pfac    = 1.       !  multipl. factor for precipitation (total & snow)
       rn_efac    = 1.       !  multipl. factor for evaporation (0. or 1.)
-      rn_vfac    = 0.       !  multipl. factor for ocean & ice velocity 
+      rn_vfac    = 0.       !  multipl. factor for ocean & ice velocity
       !                     !  used to calculate the wind stress
       !                     ! (0. => absolute or 1. => relative winds)
@@ -292,6 +292,6 @@
    sn_tair     = 't_10.15JUNE2009_fill'       ,    6.        , 'T_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
    sn_humi     = 'q_10.15JUNE2009_fill'       ,    6.        , 'Q_10_MOD',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
-   sn_hpgi     = 'NONE'                       ,   24.        , 'uhpg'    ,   .false.   , .false., 'monthly' , 'weights_ERAI3D_F128_2_ORCA2_bicubic', 'UG'     , ''
-   sn_hpgj     = 'NONE'                       ,   24.        , 'vhpg'    ,   .false.   , .false., 'monthly' , 'weights_ERAI3D_F128_2_ORCA2_bicubic', 'VG'     , ''
+   sn_hpgi     = 'NOT USED'                   ,   24.        , 'uhpg'    ,   .false.   , .false., 'monthly' , 'weights_ERAI3D_F128_2_ORCA2_bicubic', 'UG'     , ''
+   sn_hpgj     = 'NOT USED'                   ,   24.        , 'vhpg'    ,   .false.   , .false., 'monthly' , 'weights_ERAI3D_F128_2_ORCA2_bicubic', 'VG'     , ''
    sn_prec     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'PRC_MOD1',   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
    sn_snow     = 'ncar_precip.15JUNE2009_fill',   -1.        , 'SNOW'    ,   .false.   , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc' , ''       , ''
@@ -999,5 +999,5 @@
       ln_bt_auto    = .true.     ! Number of sub-step defined from:
          rn_bt_cmax   =  0.8        ! =T : the Maximum Courant Number allowed
-         nn_e      = 30          ! =F : the number of sub-step in rn_Dt seconds
+         nn_e         = 30          ! =F : the number of sub-step in rn_Dt seconds
       rn_bt_alpha   = 0.         ! Temporal diffusion parameter (if ln_bt_av=F)
 /
@@ -1193,6 +1193,15 @@
    ln_mevar    = .true.    !  variable (T) or constant (F) mixing efficiency
    ln_tsdiff   = .true.    !  account for differential T/S mixing (T) or not (F)
-/
-
+
+   cn_dir      = './'      !  root directory for the iwm data location                                                                           
+   !___________!_________________________!___________________!___________!_____________!________!___________!__________________!__________!_______________!
+   !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
+   !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
+   sn_mpb      = 'NOT USED'              , -12               , 'mixing_power_bot' , .false.  , .true. , 'yearly' , '' , ''  , ''
+   sn_mpp      = 'NOT USED'              , -12               , 'mixing_power_pyc' , .false.  , .true. , 'yearly' , '' , ''  , ''
+   sn_mpc      = 'NOT USED'              , -12               , 'mixing_power_cri' , .false.  , .true. , 'yearly' , '' , ''  , ''
+   sn_dsb      = 'NOT USED'              , -12               , 'decay_scale_bot'  , .false.  , .true. , 'yearly' , '' , ''  , ''
+   sn_dsc      = 'NOT USED'              , -12               , 'decay_scale_cri'  , .false.  , .true. , 'yearly' , '' , ''  , ''
+/
 !!======================================================================
 !!                  ***  Diagnostics namelists  ***                   !!
Index: /NEMO/trunk/src/OCE/ZDF/zdfiwm.F90
===================================================================
--- /NEMO/trunk/src/OCE/ZDF/zdfiwm.F90	(revision 12500)
+++ /NEMO/trunk/src/OCE/ZDF/zdfiwm.F90	(revision 12501)
@@ -23,4 +23,5 @@
    USE phycst         ! physical constants
    !
+   USE fldread        ! field read
    USE prtctl         ! Print control
    USE in_out_manager ! I/O manager
@@ -383,9 +384,24 @@
       !!              de Lavergne et al. in prep., 2017
       !!----------------------------------------------------------------------
-      INTEGER  ::   inum         ! local integer
+      INTEGER  ::   ifpr               ! dummy loop indices
+      INTEGER  ::   inum               ! local integer
       INTEGER  ::   ios
       REAL(wp) ::   zbot, zpyc, zcri   ! local scalars
-      !!
-      NAMELIST/namzdf_iwm/ nn_zpyc, ln_mevar, ln_tsdiff
+      !
+      CHARACTER(len=256)            ::   cn_dir                 ! Root directory for location of ssr files
+      INTEGER, PARAMETER            ::   jpiwm  = 5             ! maximum number of files to read
+      INTEGER, PARAMETER            ::   jp_mpb = 1
+      INTEGER, PARAMETER            ::   jp_mpp = 2
+      INTEGER, PARAMETER            ::   jp_mpc = 3
+      INTEGER, PARAMETER            ::   jp_dsb = 4
+      INTEGER, PARAMETER            ::   jp_dsc = 5
+      !
+      TYPE(FLD_N), DIMENSION(jpiwm) ::   slf_iwm                ! array of namelist informations
+      TYPE(FLD_N)                   ::   sn_mpb, sn_mpp, sn_mpc ! informations about Mixing Power field to be read
+      TYPE(FLD_N)                   ::   sn_dsb, sn_dsc         ! informations about Decay Scale field to be read
+      TYPE(FLD  ), DIMENSION(jpiwm) ::   sf_iwm                 ! structure of input fields (file informations, fields read)
+      !
+      NAMELIST/namzdf_iwm/ nn_zpyc, ln_mevar, ln_tsdiff, &
+         &                 cn_dir, sn_mpb, sn_mpp, sn_mpc, sn_dsb, sn_dsc
       !!----------------------------------------------------------------------
       !
@@ -422,32 +438,36 @@
       IF( zdf_iwm_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_iwm_init : unable to allocate iwm arrays' )
       !
+      ! store namelist information in an array
+      slf_iwm(jp_mpb) = sn_mpb ; slf_iwm(jp_mpp) = sn_mpp ; slf_iwm(jp_mpc) = sn_mpc
+      slf_iwm(jp_dsb) = sn_dsb ; slf_iwm(jp_dsc) = sn_dsc
+      !
+      DO ifpr= 1, jpiwm
+         ALLOCATE( sf_iwm(ifpr)%fnow(jpi,jpj,1)   )
+         IF( slf_iwm(ifpr)%ln_tint )ALLOCATE( sf_iwm(ifpr)%fdta(jpi,jpj,1,2) )
+      END DO
+
+      ! fill sf_iwm with sf_iwm and control print
+      CALL fld_fill( sf_iwm, slf_iwm , cn_dir, 'zdfiwm_init', 'iwm input file', 'namiwm' )
+
+      !                             ! hard-coded default definition (to be defined in namelist ?)
+      sf_iwm(jp_mpb)%fnow(:,:,1) = 1.e-6
+      sf_iwm(jp_mpp)%fnow(:,:,1) = 1.e-6
+      sf_iwm(jp_mpc)%fnow(:,:,1) = 1.e-10
+      sf_iwm(jp_dsb)%fnow(:,:,1) = 100.
+      sf_iwm(jp_dsc)%fnow(:,:,1) = 100.
+
       !                             ! read necessary fields
-      CALL iom_open('mixing_power_bot',inum)       ! energy flux for high-mode wave breaking [W/m2]
-      CALL iom_get  (inum, jpdom_data, 'field', ebot_iwm, 1 ) 
-      CALL iom_close(inum)
-      !
-      CALL iom_open('mixing_power_pyc',inum)       ! energy flux for pynocline-intensified wave breaking [W/m2]
-      CALL iom_get  (inum, jpdom_data, 'field', epyc_iwm, 1 )
-      CALL iom_close(inum)
-      !
-      CALL iom_open('mixing_power_cri',inum)       ! energy flux for critical slope wave breaking [W/m2]
-      CALL iom_get  (inum, jpdom_data, 'field', ecri_iwm, 1 )
-      CALL iom_close(inum)
-      !
-      CALL iom_open('decay_scale_bot',inum)        ! spatially variable decay scale for high-mode wave breaking [m]
-      CALL iom_get  (inum, jpdom_data, 'field', hbot_iwm, 1 )
-      CALL iom_close(inum)
-      !
-      CALL iom_open('decay_scale_cri',inum)        ! spatially variable decay scale for critical slope wave breaking [m]
-      CALL iom_get  (inum, jpdom_data, 'field', hcri_iwm, 1 )
-      CALL iom_close(inum)
-
-      ebot_iwm(:,:) = ebot_iwm(:,:) * ssmask(:,:)
-      epyc_iwm(:,:) = epyc_iwm(:,:) * ssmask(:,:)
-      ecri_iwm(:,:) = ecri_iwm(:,:) * ssmask(:,:)
+      CALL fld_read( 1, 1, sf_iwm )
+
+      ebot_iwm(:,:) = sf_iwm(1)%fnow(:,:,1) * ssmask(:,:) ! energy flux for high-mode wave breaking [W/m2]
+      epyc_iwm(:,:) = sf_iwm(2)%fnow(:,:,1) * ssmask(:,:) ! energy flux for pynocline-intensified wave breaking [W/m2]
+      ecri_iwm(:,:) = sf_iwm(3)%fnow(:,:,1) * ssmask(:,:) ! energy flux for critical slope wave breaking [W/m2]
+      hbot_iwm(:,:) = sf_iwm(4)%fnow(:,:,1)               ! spatially variable decay scale for high-mode wave breaking [m]
+      hcri_iwm(:,:) = sf_iwm(5)%fnow(:,:,1)               ! spatially variable decay scale for critical slope wave breaking [m]
 
       zbot = glob_sum( 'zdfiwm', e1e2t(:,:) * ebot_iwm(:,:) )
       zpyc = glob_sum( 'zdfiwm', e1e2t(:,:) * epyc_iwm(:,:) )
       zcri = glob_sum( 'zdfiwm', e1e2t(:,:) * ecri_iwm(:,:) )
+
       IF(lwp) THEN
          WRITE(numout,*) '      High-mode wave-breaking energy:             ', zbot * 1.e-12_wp, 'TW'
Index: /NEMO/trunk/tests/BENCH/EXPREF/namelist_pisces_cfg
===================================================================
--- /NEMO/trunk/tests/BENCH/EXPREF/namelist_pisces_cfg	(revision 12500)
+++ /NEMO/trunk/tests/BENCH/EXPREF/namelist_pisces_cfg	(revision 12501)
@@ -81,10 +81,6 @@
 /
 !-----------------------------------------------------------------------
-&nampissbc     !   parameters for inputs deposition
+&nampisbc      !   parameters for inputs deposition
 !-----------------------------------------------------------------------
-   ln_dust     =  .false.   ! boolean for dust input from the atmosphere
-   ln_solub    =  .false.   ! boolean for variable solubility of atm. Iron
-   ln_river    =  .false.   ! boolean for river input of nutrients
-   ln_ndepo    =  .false.   ! boolean for atmospheric deposition of N
    ln_ironsed  =  .false.   ! boolean for Fe input from sediments
    ln_ironice  =  .false.   ! boolean for Fe input from sea ice
Index: MO/trunk/tests/BENCH/MY_SRC/zdfiwm.F90
===================================================================
--- /NEMO/trunk/tests/BENCH/MY_SRC/zdfiwm.F90	(revision 12500)
+++ 	(revision )
@@ -1,466 +1,0 @@
-MODULE zdfiwm
-   !!========================================================================
-   !!                       ***  MODULE  zdfiwm  ***
-   !! Ocean physics: Internal gravity wave-driven vertical mixing
-   !!========================================================================
-   !! History :  1.0  !  2004-04  (L. Bessieres, G. Madec)  Original code
-   !!             -   !  2006-08  (A. Koch-Larrouy)  Indonesian strait
-   !!            3.3  !  2010-10  (C. Ethe, G. Madec)  reorganisation of initialisation phase
-   !!            3.6  !  2016-03  (C. de Lavergne)  New param: internal wave-driven mixing 
-   !!            4.0  !  2017-04  (G. Madec)  renamed module, remove the old param. and the CPP keys
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   zdf_iwm       : global     momentum & tracer Kz with wave induced Kz
-   !!   zdf_iwm_init  : global     momentum & tracer Kz with wave induced Kz
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers variables
-   USE dom_oce        ! ocean space and time domain variables
-   USE zdf_oce        ! ocean vertical physics variables
-   USE zdfddm         ! ocean vertical physics: double diffusive mixing
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE eosbn2         ! ocean equation of state
-   USE phycst         ! physical constants
-   !
-   USE prtctl         ! Print control
-   USE in_out_manager ! I/O manager
-   USE iom            ! I/O Manager
-   USE lib_mpp        ! MPP library
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   zdf_iwm        ! called in step module 
-   PUBLIC   zdf_iwm_init   ! called in nemogcm module 
-
-   !                      !!* Namelist  namzdf_iwm : internal wave-driven mixing *
-   INTEGER ::  nn_zpyc     ! pycnocline-intensified mixing energy proportional to N (=1) or N^2 (=2)
-   LOGICAL ::  ln_mevar    ! variable (=T) or constant (=F) mixing efficiency
-   LOGICAL ::  ln_tsdiff   ! account for differential T/S wave-driven mixing (=T) or not (=F)
-
-   REAL(wp)::  r1_6 = 1._wp / 6._wp
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ebot_iwm   ! power available from high-mode wave breaking (W/m2)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   epyc_iwm   ! power available from low-mode, pycnocline-intensified wave breaking (W/m2)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ecri_iwm   ! power available from low-mode, critical slope wave breaking (W/m2)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hbot_iwm   ! WKB decay scale for high-mode energy dissipation (m)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hcri_iwm   ! decay scale for low-mode critical slope dissipation (m)
-
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: zdfiwm.F90 12377 2020-02-12 14:39:06Z acc $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION zdf_iwm_alloc()
-      !!----------------------------------------------------------------------
-      !!                ***  FUNCTION zdf_iwm_alloc  ***
-      !!----------------------------------------------------------------------
-      ALLOCATE( ebot_iwm(jpi,jpj),  epyc_iwm(jpi,jpj),  ecri_iwm(jpi,jpj) ,     &
-      &         hbot_iwm(jpi,jpj),  hcri_iwm(jpi,jpj)                     , STAT=zdf_iwm_alloc )
-      !
-      CALL mpp_sum ( 'zdfiwm', zdf_iwm_alloc )
-      IF( zdf_iwm_alloc /= 0 )   CALL ctl_stop( 'STOP', 'zdf_iwm_alloc: failed to allocate arrays' )
-   END FUNCTION zdf_iwm_alloc
-
-
-   SUBROUTINE zdf_iwm( kt, Kmm, p_avm, p_avt, p_avs )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE zdf_iwm  ***
-      !!                   
-      !! ** Purpose :   add to the vertical mixing coefficients the effect of
-      !!              breaking internal waves.
-      !!
-      !! ** Method  : - internal wave-driven vertical mixing is given by:
-      !!                  Kz_wave = min(  100 cm2/s, f(  Reb = zemx_iwm /( Nu * N^2 )  )
-      !!              where zemx_iwm is the 3D space distribution of the wave-breaking 
-      !!              energy and Nu the molecular kinematic viscosity.
-      !!              The function f(Reb) is linear (constant mixing efficiency)
-      !!              if the namelist parameter ln_mevar = F and nonlinear if ln_mevar = T.
-      !!
-      !!              - Compute zemx_iwm, the 3D power density that allows to compute
-      !!              Reb and therefrom the wave-induced vertical diffusivity.
-      !!              This is divided into three components:
-      !!                 1. Bottom-intensified low-mode dissipation at critical slopes
-      !!                     zemx_iwm(z) = ( ecri_iwm / rho0 ) * EXP( -(H-z)/hcri_iwm )
-      !!                                   / ( 1. - EXP( - H/hcri_iwm ) ) * hcri_iwm
-      !!              where hcri_iwm is the characteristic length scale of the bottom 
-      !!              intensification, ecri_iwm a map of available power, and H the ocean depth.
-      !!                 2. Pycnocline-intensified low-mode dissipation
-      !!                     zemx_iwm(z) = ( epyc_iwm / rho0 ) * ( sqrt(rn2(z))^nn_zpyc )
-      !!                                   / SUM( sqrt(rn2(z))^nn_zpyc * e3w(z) )
-      !!              where epyc_iwm is a map of available power, and nn_zpyc
-      !!              is the chosen stratification-dependence of the internal wave
-      !!              energy dissipation.
-      !!                 3. WKB-height dependent high mode dissipation
-      !!                     zemx_iwm(z) = ( ebot_iwm / rho0 ) * rn2(z) * EXP(-z_wkb(z)/hbot_iwm)
-      !!                                   / SUM( rn2(z) * EXP(-z_wkb(z)/hbot_iwm) * e3w(z) )
-      !!              where hbot_iwm is the characteristic length scale of the WKB bottom 
-      !!              intensification, ebot_iwm is a map of available power, and z_wkb is the
-      !!              WKB-stretched height above bottom defined as
-      !!                    z_wkb(z) = H * SUM( sqrt(rn2(z'>=z)) * e3w(z'>=z) )
-      !!                                 / SUM( sqrt(rn2(z'))    * e3w(z')    )
-      !!
-      !!              - update the model vertical eddy viscosity and diffusivity: 
-      !!                     avt  = avt  +    av_wave
-      !!                     avm  = avm  +    av_wave
-      !!
-      !!              - if namelist parameter ln_tsdiff = T, account for differential mixing:
-      !!                     avs  = avt  +    av_wave * diffusivity_ratio(Reb)
-      !!
-      !! ** Action  : - avt, avs, avm, increased by tide internal wave-driven mixing    
-      !!
-      !! References :  de Lavergne et al. 2015, JPO; 2016, in prep.
-      !!----------------------------------------------------------------------
-      INTEGER                    , INTENT(in   ) ::   kt             ! ocean time step
-      INTEGER                    , INTENT(in   ) ::   Kmm            ! time level index
-      REAL(wp), DIMENSION(:,:,:) , INTENT(inout) ::   p_avm          ! momentum Kz (w-points)
-      REAL(wp), DIMENSION(:,:,:) , INTENT(inout) ::   p_avt, p_avs   ! tracer   Kz (w-points)
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zztmp, ztmp1, ztmp2        ! scalar workspace
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zfact       ! Used for vertical structure
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zhdep       ! Ocean depth
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwkb        ! WKB-stretched height above bottom
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zweight     ! Weight for high mode vertical distribution
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   znu_t       ! Molecular kinematic viscosity (T grid)
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   znu_w       ! Molecular kinematic viscosity (W grid)
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zReb        ! Turbulence intensity parameter
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zemx_iwm    ! local energy density available for mixing (W/kg)
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zav_ratio   ! S/T diffusivity ratio (only for ln_tsdiff=T)
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zav_wave    ! Internal wave-induced diffusivity
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   z3d  ! 3D workspace used for iom_put 
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:)   ::   z2d  ! 2D     -      -    -     -
-      !!----------------------------------------------------------------------
-      !
-      !                       !* Set to zero the 1st and last vertical levels of appropriate variables
-      zemx_iwm (:,:,1) = 0._wp   ;   zemx_iwm (:,:,jpk) = 0._wp
-      zav_ratio(:,:,1) = 0._wp   ;   zav_ratio(:,:,jpk) = 0._wp
-      zav_wave (:,:,1) = 0._wp   ;   zav_wave (:,:,jpk) = 0._wp
-      !
-      !                       ! ----------------------------- !
-      !                       !  Internal wave-driven mixing  !  (compute zav_wave)
-      !                       ! ----------------------------- !
-      !                             
-      !                       !* Critical slope mixing: distribute energy over the time-varying ocean depth,
-      !                                                 using an exponential decay from the seafloor.
-      DO_2D_11_11
-         zhdep(ji,jj) = gdepw_0(ji,jj,mbkt(ji,jj)+1)       ! depth of the ocean
-         zfact(ji,jj) = rho0 * (  1._wp - EXP( -zhdep(ji,jj) / hcri_iwm(ji,jj) )  )
-         IF( zfact(ji,jj) /= 0._wp )   zfact(ji,jj) = ecri_iwm(ji,jj) / zfact(ji,jj)
-      END_2D
-!!gm gde3w ==>>>  check for ssh taken into account.... seem OK gde3w_n=gdept(:,:,:,Kmm) - ssh(:,:,Kmm)
-      DO_3D_11_11( 2, jpkm1 )
-         IF ( zfact(ji,jj) == 0._wp .OR. wmask(ji,jj,jk) == 0._wp ) THEN   ! optimization
-            zemx_iwm(ji,jj,jk) = 0._wp
-         ELSE
-            zemx_iwm(ji,jj,jk) = zfact(ji,jj) * (  EXP( ( gde3w(ji,jj,jk  ) - zhdep(ji,jj) ) / hcri_iwm(ji,jj) )     &
-                 &                               - EXP( ( gde3w(ji,jj,jk-1) - zhdep(ji,jj) ) / hcri_iwm(ji,jj) ) )   &
-                 &                            / ( gde3w(ji,jj,jk) - gde3w(ji,jj,jk-1) )
-         ENDIF
-      END_3D
-!!gm delta(gde3w) = e3t(:,:,:,Kmm)  !!  Please verify the grid-point position w versus t-point
-!!gm it seems to me that only 1/hcri_iwm  is used ==>  compute it one for all
-
-
-      !                        !* Pycnocline-intensified mixing: distribute energy over the time-varying 
-      !                        !* ocean depth as proportional to sqrt(rn2)^nn_zpyc
-      !                                          ! (NB: N2 is masked, so no use of wmask here)
-      SELECT CASE ( nn_zpyc )
-      !
-      CASE ( 1 )               ! Dissipation scales as N (recommended)
-         !
-         zfact(:,:) = 0._wp
-         DO jk = 2, jpkm1              ! part independent of the level
-            zfact(:,:) = zfact(:,:) + e3w(:,:,jk,Kmm) * SQRT(  MAX( 0._wp, rn2(:,:,jk) )  ) * wmask(:,:,jk)
-         END DO
-         !
-         DO_2D_11_11
-            IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = epyc_iwm(ji,jj) / ( rho0 * zfact(ji,jj) )
-         END_2D
-         !
-         DO jk = 2, jpkm1              ! complete with the level-dependent part
-            zemx_iwm(:,:,jk) = zemx_iwm(:,:,jk) + zfact(:,:) * SQRT(  MAX( 0._wp, rn2(:,:,jk) )  ) * wmask(:,:,jk)
-         END DO
-         !
-      CASE ( 2 )               ! Dissipation scales as N^2
-         !
-         zfact(:,:) = 0._wp
-         DO jk = 2, jpkm1              ! part independent of the level
-            zfact(:,:) = zfact(:,:) + e3w(:,:,jk,Kmm) * MAX( 0._wp, rn2(:,:,jk) ) * wmask(:,:,jk)
-         END DO
-         !
-         DO_2D_11_11
-            IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = epyc_iwm(ji,jj) / ( rho0 * zfact(ji,jj) )
-         END_2D
-         !
-         DO jk = 2, jpkm1              ! complete with the level-dependent part
-            zemx_iwm(:,:,jk) = zemx_iwm(:,:,jk) + zfact(:,:) * MAX( 0._wp, rn2(:,:,jk) ) * wmask(:,:,jk)
-         END DO
-         !
-      END SELECT
-
-      !                        !* WKB-height dependent mixing: distribute energy over the time-varying 
-      !                        !* ocean depth as proportional to rn2 * exp(-z_wkb/rn_hbot)
-      !
-      zwkb (:,:,:) = 0._wp
-      zfact(:,:)   = 0._wp
-      DO jk = 2, jpkm1
-         zfact(:,:) = zfact(:,:) + e3w(:,:,jk,Kmm) * SQRT(  MAX( 0._wp, rn2(:,:,jk) )  ) * wmask(:,:,jk)
-         zwkb(:,:,jk) = zfact(:,:)
-      END DO
-!!gm even better:
-!      DO jk = 2, jpkm1
-!         zwkb(:,:) = zwkb(:,:) + e3w(:,:,jk,Kmm) * SQRT(  MAX( 0._wp, rn2(:,:,jk) )  )
-!      END DO
-!      zfact(:,:) = zwkb(:,:,jpkm1)
-!!gm or just use zwkb(k=jpk-1) instead of zfact...
-!!gm
-      !
-      DO_3D_11_11( 2, jpkm1 )
-         IF( zfact(ji,jj) /= 0 )   zwkb(ji,jj,jk) = zhdep(ji,jj) * ( zfact(ji,jj) - zwkb(ji,jj,jk) )   &
-            &                                     * wmask(ji,jj,jk) / zfact(ji,jj)
-      END_3D
-      zwkb(:,:,1) = zhdep(:,:) * wmask(:,:,1)
-      !
-      DO_3D_11_11( 2, jpkm1 )
-         IF ( rn2(ji,jj,jk) <= 0._wp .OR. wmask(ji,jj,jk) == 0._wp ) THEN   ! optimization
-            zweight(ji,jj,jk) = 0._wp
-         ELSE
-            zweight(ji,jj,jk) = rn2(ji,jj,jk) * hbot_iwm(ji,jj)    &
-               &   * (  EXP( -zwkb(ji,jj,jk) / hbot_iwm(ji,jj) ) - EXP( -zwkb(ji,jj,jk-1) / hbot_iwm(ji,jj) )  )
-         ENDIF
-      END_3D
-      !
-      zfact(:,:) = 0._wp
-      DO jk = 2, jpkm1              ! part independent of the level
-         zfact(:,:) = zfact(:,:) + zweight(:,:,jk)
-      END DO
-      !
-      DO_2D_11_11
-         IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = ebot_iwm(ji,jj) / ( rho0 * zfact(ji,jj) )
-      END_2D
-      !
-      DO jk = 2, jpkm1              ! complete with the level-dependent part
-         zemx_iwm(:,:,jk) = zemx_iwm(:,:,jk) + zweight(:,:,jk) * zfact(:,:) * wmask(:,:,jk)   &
-            &                                / ( gde3w(:,:,jk) - gde3w(:,:,jk-1) )
-!!gm  use of e3t(:,:,:,Kmm) just above?
-      END DO
-      !
-!!gm  this is to be replaced by just a constant value znu=1.e-6 m2/s
-      ! Calculate molecular kinematic viscosity
-      znu_t(:,:,:) = 1.e-4_wp * (  17.91_wp - 0.53810_wp * ts(:,:,:,jp_tem,Kmm) + 0.00694_wp * ts(:,:,:,jp_tem,Kmm) * ts(:,:,:,jp_tem,Kmm)  &
-         &                                  + 0.02305_wp * ts(:,:,:,jp_sal,Kmm)  ) * tmask(:,:,:) * r1_rho0
-      DO jk = 2, jpkm1
-         znu_w(:,:,jk) = 0.5_wp * ( znu_t(:,:,jk-1) + znu_t(:,:,jk) ) * wmask(:,:,jk)
-      END DO
-!!gm end
-      !
-      ! Calculate turbulence intensity parameter Reb
-      DO jk = 2, jpkm1
-         zReb(:,:,jk) = zemx_iwm(:,:,jk) / MAX( 1.e-20_wp, znu_w(:,:,jk) * rn2(:,:,jk) )
-      END DO
-      !
-      ! Define internal wave-induced diffusivity
-      DO jk = 2, jpkm1
-         zav_wave(:,:,jk) = znu_w(:,:,jk) * zReb(:,:,jk) * r1_6   ! This corresponds to a constant mixing efficiency of 1/6
-      END DO
-      !
-      IF( ln_mevar ) THEN              ! Variable mixing efficiency case : modify zav_wave in the
-         DO_3D_11_11( 2, jpkm1 )
-            IF( zReb(ji,jj,jk) > 480.00_wp ) THEN
-               zav_wave(ji,jj,jk) = 3.6515_wp * znu_w(ji,jj,jk) * SQRT( zReb(ji,jj,jk) )
-            ELSEIF( zReb(ji,jj,jk) < 10.224_wp ) THEN
-               zav_wave(ji,jj,jk) = 0.052125_wp * znu_w(ji,jj,jk) * zReb(ji,jj,jk) * SQRT( zReb(ji,jj,jk) )
-            ENDIF
-         END_3D
-      ENDIF
-      !
-      DO jk = 2, jpkm1                 ! Bound diffusivity by molecular value and 100 cm2/s
-         zav_wave(:,:,jk) = MIN(  MAX( 1.4e-7_wp, zav_wave(:,:,jk) ), 1.e-2_wp  ) * wmask(:,:,jk)
-      END DO
-      !
-      IF( kt == nit000 ) THEN        !* Control print at first time-step: diagnose the energy consumed by zav_wave
-         zztmp = 0._wp
-!!gm used of glosum 3D....
-         DO_3D_11_11( 2, jpkm1 )
-            zztmp = zztmp + e3w(ji,jj,jk,Kmm) * e1e2t(ji,jj)   &
-               &          * MAX( 0._wp, rn2(ji,jj,jk) ) * zav_wave(ji,jj,jk) * wmask(ji,jj,jk) * tmask_i(ji,jj)
-         END_3D
-         CALL mpp_sum( 'zdfiwm', zztmp )
-         zztmp = rho0 * zztmp ! Global integral of rauo * Kz * N^2 = power contributing to mixing 
-         !
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) 'zdf_iwm : Internal wave-driven mixing (iwm)'
-            WRITE(numout,*) '~~~~~~~ '
-            WRITE(numout,*)
-            WRITE(numout,*) '      Total power consumption by av_wave =  ', zztmp * 1.e-12_wp, 'TW'
-         ENDIF
-      ENDIF
-
-      !                          ! ----------------------- !
-      !                          !   Update  mixing coefs  !                          
-      !                          ! ----------------------- !
-      !      
-      IF( ln_tsdiff ) THEN          !* Option for differential mixing of salinity and temperature
-         ztmp1 = 0.505_wp + 0.495_wp * TANH( 0.92_wp * ( LOG10( 1.e-20_wp ) - 0.60_wp ) )
-         DO_3D_11_11( 2, jpkm1 )
-            ztmp2 = zReb(ji,jj,jk) * 5._wp * r1_6
-            IF ( ztmp2 > 1.e-20_wp .AND. wmask(ji,jj,jk) == 1._wp ) THEN
-               zav_ratio(ji,jj,jk) = 0.505_wp + 0.495_wp * TANH( 0.92_wp * ( LOG10(ztmp2) - 0.60_wp ) )
-            ELSE
-               zav_ratio(ji,jj,jk) = ztmp1 * wmask(ji,jj,jk)
-            ENDIF
-         END_3D
-         CALL iom_put( "av_ratio", zav_ratio )
-         DO jk = 2, jpkm1           !* update momentum & tracer diffusivity with wave-driven mixing
-            p_avs(:,:,jk) = p_avs(:,:,jk) + zav_wave(:,:,jk) * zav_ratio(:,:,jk)
-            p_avt(:,:,jk) = p_avt(:,:,jk) + zav_wave(:,:,jk)
-            p_avm(:,:,jk) = p_avm(:,:,jk) + zav_wave(:,:,jk)
-         END DO
-         !
-      ELSE                          !* update momentum & tracer diffusivity with wave-driven mixing
-         DO jk = 2, jpkm1
-            p_avs(:,:,jk) = p_avs(:,:,jk) + zav_wave(:,:,jk)
-            p_avt(:,:,jk) = p_avt(:,:,jk) + zav_wave(:,:,jk)
-            p_avm(:,:,jk) = p_avm(:,:,jk) + zav_wave(:,:,jk)
-         END DO
-      ENDIF
-
-      !                             !* output internal wave-driven mixing coefficient
-      CALL iom_put( "av_wave", zav_wave )
-                                    !* output useful diagnostics: Kz*N^2 , 
-!!gm Kz*N2 should take into account the ratio avs/avt if it is used.... (see diaar5)
-                                    !  vertical integral of rho0 * Kz * N^2 , energy density (zemx_iwm)
-      IF( iom_use("bflx_iwm") .OR. iom_use("pcmap_iwm") ) THEN
-         ALLOCATE( z2d(jpi,jpj) , z3d(jpi,jpj,jpk) )
-         z3d(:,:,:) = MAX( 0._wp, rn2(:,:,:) ) * zav_wave(:,:,:)
-         z2d(:,:) = 0._wp
-         DO jk = 2, jpkm1
-            z2d(:,:) = z2d(:,:) + e3w(:,:,jk,Kmm) * z3d(:,:,jk) * wmask(:,:,jk)
-         END DO
-         z2d(:,:) = rho0 * z2d(:,:)
-         CALL iom_put( "bflx_iwm", z3d )
-         CALL iom_put( "pcmap_iwm", z2d )
-         DEALLOCATE( z2d , z3d )
-      ENDIF
-      CALL iom_put( "emix_iwm", zemx_iwm )
-      
-      IF(sn_cfctl%l_prtctl)   CALL prt_ctl(tab3d_1=zav_wave , clinfo1=' iwm - av_wave: ', tab3d_2=avt, clinfo2=' avt: ', kdim=jpk)
-      !
-   END SUBROUTINE zdf_iwm
-
-
-   SUBROUTINE zdf_iwm_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE zdf_iwm_init  ***
-      !!                     
-      !! ** Purpose :   Initialization of the wave-driven vertical mixing, reading
-      !!              of input power maps and decay length scales in netcdf files.
-      !!
-      !! ** Method  : - Read the namzdf_iwm namelist and check the parameters
-      !!
-      !!              - Read the input data in NetCDF files :
-      !!              power available from high-mode wave breaking (mixing_power_bot.nc)
-      !!              power available from pycnocline-intensified wave-breaking (mixing_power_pyc.nc)
-      !!              power available from critical slope wave-breaking (mixing_power_cri.nc)
-      !!              WKB decay scale for high-mode wave-breaking (decay_scale_bot.nc)
-      !!              decay scale for critical slope wave-breaking (decay_scale_cri.nc)
-      !!
-      !! ** input   : - Namlist namzdf_iwm
-      !!              - NetCDF files : mixing_power_bot.nc, mixing_power_pyc.nc, mixing_power_cri.nc,
-      !!              decay_scale_bot.nc decay_scale_cri.nc
-      !!
-      !! ** Action  : - Increase by 1 the nstop flag is setting problem encounter
-      !!              - Define ebot_iwm, epyc_iwm, ecri_iwm, hbot_iwm, hcri_iwm
-      !!
-      !! References : de Lavergne et al. JPO, 2015 ; de Lavergne PhD 2016
-      !!              de Lavergne et al. in prep., 2017
-      !!----------------------------------------------------------------------
-      INTEGER  ::   inum         ! local integer
-      INTEGER  ::   ios
-      REAL(wp) ::   zbot, zpyc, zcri   ! local scalars
-      !!
-      NAMELIST/namzdf_iwm/ nn_zpyc, ln_mevar, ln_tsdiff
-      !!----------------------------------------------------------------------
-      !
-      READ  ( numnam_ref, namzdf_iwm, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namzdf_iwm in reference namelist' )
-      !
-      READ  ( numnam_cfg, namzdf_iwm, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namzdf_iwm in configuration namelist' )
-      IF(lwm) WRITE ( numond, namzdf_iwm )
-      !
-      IF(lwp) THEN                  ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'zdf_iwm_init : internal wave-driven mixing'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist namzdf_iwm : set wave-driven mixing parameters'
-         WRITE(numout,*) '      Pycnocline-intensified diss. scales as N (=1) or N^2 (=2) = ', nn_zpyc
-         WRITE(numout,*) '      Variable (T) or constant (F) mixing efficiency            = ', ln_mevar
-         WRITE(numout,*) '      Differential internal wave-driven mixing (T) or not (F)   = ', ln_tsdiff
-      ENDIF
-      
-      ! The new wave-driven mixing parameterization elevates avt and avm in the interior, and
-      ! ensures that avt remains larger than its molecular value (=1.4e-7). Therefore, avtb should 
-      ! be set here to a very small value, and avmb to its (uniform) molecular value (=1.4e-6).
-      avmb(:) = 1.4e-6_wp        ! viscous molecular value
-      avtb(:) = 1.e-10_wp        ! very small diffusive minimum (background avt is specified in zdf_iwm)    
-      avtb_2d(:,:) = 1.e0_wp     ! uniform 
-      IF(lwp) THEN                  ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) '   Force the background value applied to avm & avt in TKE to be everywhere ',   &
-            &               'the viscous molecular value & a very small diffusive value, resp.'
-      ENDIF
-            
-      !                             ! allocate iwm arrays
-      IF( zdf_iwm_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_iwm_init : unable to allocate iwm arrays' )
-      !
-      !                             ! read necessary fields
-!!$      CALL iom_open('mixing_power_bot',inum)       ! energy flux for high-mode wave breaking [W/m2]
-!!$      CALL iom_get  (inum, jpdom_data, 'field', ebot_iwm, 1 ) 
-!!$      CALL iom_close(inum)
-      ebot_iwm(:,:) = 1.e-6
-      !
-!!$      CALL iom_open('mixing_power_pyc',inum)       ! energy flux for pynocline-intensified wave breaking [W/m2]
-!!$      CALL iom_get  (inum, jpdom_data, 'field', epyc_iwm, 1 )
-!!$      CALL iom_close(inum)
-      epyc_iwm(:,:) = 1.e-6
-      !
-!!$      CALL iom_open('mixing_power_cri',inum)       ! energy flux for critical slope wave breaking [W/m2]
-!!$      CALL iom_get  (inum, jpdom_data, 'field', ecri_iwm, 1 )
-!!$      CALL iom_close(inum)
-      ecri_iwm(:,:) = 1.e-10
-      !
-!!$      CALL iom_open('decay_scale_bot',inum)        ! spatially variable decay scale for high-mode wave breaking [m]
-!!$      CALL iom_get  (inum, jpdom_data, 'field', hbot_iwm, 1 )
-!!$      CALL iom_close(inum)
-      hbot_iwm(:,:) = 100.
-      !
-!!$      CALL iom_open('decay_scale_cri',inum)        ! spatially variable decay scale for critical slope wave breaking [m]
-!!$      CALL iom_get  (inum, jpdom_data, 'field', hcri_iwm, 1 )
-!!$      CALL iom_close(inum)
-      hcri_iwm(:,:) = 100.
-
-      ebot_iwm(:,:) = ebot_iwm(:,:) * ssmask(:,:)
-      epyc_iwm(:,:) = epyc_iwm(:,:) * ssmask(:,:)
-      ecri_iwm(:,:) = ecri_iwm(:,:) * ssmask(:,:)
-
-      zbot = glob_sum( 'zdfiwm', e1e2t(:,:) * ebot_iwm(:,:) )
-      zpyc = glob_sum( 'zdfiwm', e1e2t(:,:) * epyc_iwm(:,:) )
-      zcri = glob_sum( 'zdfiwm', e1e2t(:,:) * ecri_iwm(:,:) )
-      IF(lwp) THEN
-         WRITE(numout,*) '      High-mode wave-breaking energy:             ', zbot * 1.e-12_wp, 'TW'
-         WRITE(numout,*) '      Pycnocline-intensifed wave-breaking energy: ', zpyc * 1.e-12_wp, 'TW'
-         WRITE(numout,*) '      Critical slope wave-breaking energy:        ', zcri * 1.e-12_wp, 'TW'
-      ENDIF
-      !
-   END SUBROUTINE zdf_iwm_init
-
-   !!======================================================================
-END MODULE zdfiwm
