Index: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/GYRE/EXP00/namelist_cfg
===================================================================
--- branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/GYRE/EXP00/namelist_cfg	(revision 7177)
+++ branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/GYRE/EXP00/namelist_cfg	(revision 7188)
@@ -25,5 +25,5 @@
 &namcfg     !   parameters of the configuration   
 !-----------------------------------------------------------------------
-   ln_read_cfg = .true.    !  (=T) read the domain configuration in 'domain_cfg.nc" file
+   ln_read_cfg = .false.   !  (=T) read the domain configuration in 'domain_cfg.nc" file
    !                       !  (=F) user defined configuration  ==>>>  see usrdef(_...) modules
    ln_write_cfg= .false.   !  (=T) create the domain configuration file
Index: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg
===================================================================
--- branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg	(revision 7177)
+++ branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg	(revision 7188)
@@ -24,5 +24,5 @@
    ln_read_cfg = .false.   !  (=T) read the domain configuration in 'domain_cfg.nc" file
    !                       !  (=F) user defined configuration  ==>>>  see usrdef(_...) modules
-   ln_write_cfg= .true.    !  (=T) create the domain configuration file
+   ln_write_cfg= .false.   !  (=T) create the domain configuration file
    !
    cp_cfg      = "default" !  name of the configuration
Index: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_cfg
===================================================================
--- branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_cfg	(revision 7177)
+++ branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_cfg	(revision 7188)
@@ -17,5 +17,5 @@
    ln_read_cfg = .false.   !  (=T) read the domain configuration in 'domain_cfg.nc" file
    !                       !  (=F) user defined configuration  ==>>>  see usrdef(_...) modules
-   ln_write_cfg= .true.    !  (=T) create the domain configuration file
+   ln_write_cfg= .false.   !  (=T) create the domain configuration file
    !
    cp_cfg      = "default" !  name of the configuration
Index: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/GYRE_XIOS/EXP00/namelist_cfg
===================================================================
--- branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/GYRE_XIOS/EXP00/namelist_cfg	(revision 7177)
+++ branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/GYRE_XIOS/EXP00/namelist_cfg	(revision 7188)
@@ -17,5 +17,5 @@
    ln_read_cfg = .false.   !  (=T) read the domain configuration in 'domain_cfg.nc" file
    !                       !  (=F) user defined configuration  ==>>>  see usrdef(_...) modules
-   ln_write_cfg= .true.    !  (=T) create the domain configuration file
+   ln_write_cfg= .false.   !  (=T) create the domain configuration file
    !
    cp_cfg      = "default" !  name of the configuration
@@ -41,7 +41,7 @@
 &namtsd    !   data : Temperature  & Salinity
 !-----------------------------------------------------------------------
-   cn_dir        = './'      !  root directory for the location of the runoff files
-   ln_tsd_init   = .false.   !  Initialisation of ocean T & S with T &S input data (T) or not (F)
-   ln_tsd_tradmp = .false.   !  damping of ocean T & S toward T &S input data (T) or not (F)
+   cn_dir        = './'    !  root directory for the location of the runoff files
+   ln_tsd_init   = .false. !  Initialisation of ocean T & S with T &S input data (T) or not (F)
+   ln_tsd_tradmp = .false. !  damping of ocean T & S toward T &S input data (T) or not (F)
 /
 !-----------------------------------------------------------------------
Index: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/LOCK_EXCHANGE/MY_SRC/usrdef_zgr.F90
===================================================================
--- branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/LOCK_EXCHANGE/MY_SRC/usrdef_zgr.F90	(revision 7177)
+++ branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/LOCK_EXCHANGE/MY_SRC/usrdef_zgr.F90	(revision 7188)
@@ -122,12 +122,11 @@
       !!      vertical scale factors.
       !!
-      !! ** Method  :   z-coordinate system (use in all type of coordinate)
-      !!      The depth of model levels is defined from an analytical
-      !!      function the derivative of which gives the scale factors.
-      !!      both depth and scale factors only depend on k (1d arrays).
-      !!              w-level: pdepw_1d  = pdep(k)
-      !!                       pe3w_1d(k) = dk(pdep)(k)     = e3(k)
-      !!              t-level: pdept_1d  = pdep(k+0.5)
-      !!                       pe3t_1d(k) = dk(pdep)(k+0.5) = e3(k+0.5)
+      !! ** Method  :   1D z-coordinate system (use in all type of coordinate)
+      !!       The depth of model levels is set from dep(k), an analytical function:
+      !!                   w-level: depw_1d  = dep(k)
+      !!                   t-level: dept_1d  = dep(k+0.5)
+      !!       The scale factors are the discrete derivative of the depth:
+      !!                   e3w_1d(jk) = dk[ dept_1d ] 
+      !!                   e3t_1d(jk) = dk[ depw_1d ]
       !!
       !!            ===    Here constant vertical resolution   ===
Index: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/OVERFLOW/MY_SRC/usrdef_zgr.F90
===================================================================
--- branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/OVERFLOW/MY_SRC/usrdef_zgr.F90	(revision 7177)
+++ branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/CONFIG/OVERFLOW/MY_SRC/usrdef_zgr.F90	(revision 7188)
@@ -218,12 +218,11 @@
       !!      vertical scale factors.
       !!
-      !! ** Method  :   z-coordinate system (use in all type of coordinate)
-      !!      The depth of model levels is defined from an analytical
-      !!      function the derivative of which gives the scale factors.
-      !!      both depth and scale factors only depend on k (1d arrays).
-      !!              w-level: pdepw_1d  = pdep(k)
-      !!                       pe3w_1d(k) = dk(pdep)(k)     = e3(k)
-      !!              t-level: pdept_1d  = pdep(k+0.5)
-      !!                       pe3t_1d(k) = dk(pdep)(k+0.5) = e3(k+0.5)
+      !! ** Method  :   1D z-coordinate system (use in all type of coordinate)
+      !!       The depth of model levels is set from dep(k), an analytical function:
+      !!                   w-level: depw_1d  = dep(k)
+      !!                   t-level: dept_1d  = dep(k+0.5)
+      !!       The scale factors are the discrete derivative of the depth:
+      !!                   e3w_1d(jk) = dk[ dept_1d ] 
+      !!                   e3t_1d(jk) = dk[ depw_1d ]
       !!
       !!            ===    Here constant vertical resolution   ===
Index: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 7177)
+++ branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 7188)
@@ -167,4 +167,8 @@
    !! masks, top and bottom ocean point position
    !! ---------------------------------------------------------------------
+!!gm Proposition of new name for top/bottom vertical indices
+!   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mtk_t, mtk_u, mtk_v   !: top first wet T-, U-, V-, F-level (ISF)
+!   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbk_t, mbk_u, mbk_v   !: bottom last wet T-, U- and V-level
+!!gm
    INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbkt, mbku, mbkv   !: bottom last wet T-, U- and V-level
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmask_i            !: interior domain T-point mask
Index: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90
===================================================================
--- branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 7177)
+++ branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 7188)
@@ -572,15 +572,10 @@
       CALL iom_rstput( 0, 0, inum, 'ff_t' , ff_t , ktype = jp_r8 )
       !
-      !                             !==  vertical mesh - 3D mask  ==!
+      !                             !==  vertical mesh  ==!
       !                                                     
-      CALL iom_rstput( 0, 0, inum, 'gdept_1d', gdept_1d, ktype = jp_r8 )   ! reference 1D-coordinate
-      CALL iom_rstput( 0, 0, inum, 'gdepw_1d', gdepw_1d, ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e3t_1d'  , e3t_1d  , ktype = jp_r8 )
+      CALL iom_rstput( 0, 0, inum, 'e3t_1d'  , e3t_1d  , ktype = jp_r8 )   ! reference 1D-coordinate
       CALL iom_rstput( 0, 0, inum, 'e3w_1d'  , e3w_1d  , ktype = jp_r8 )
-      !                                                     
-      CALL iom_rstput( 0, 0, inum, 'gdept_0' , gdept_0 , ktype = jp_r8 )   ! depth (t- & w-points)
-      CALL iom_rstput( 0, 0, inum, 'gdepw_0' , gdepw_0 , ktype = jp_r8 )
-      !
-      CALL iom_rstput( 0, 0, inum, 'e3t_0'   , e3t_0   , ktype = jp_r8 )   ! vertical scale factors (e
+      !
+      CALL iom_rstput( 0, 0, inum, 'e3t_0'   , e3t_0   , ktype = jp_r8 )   ! vertical scale factors
       CALL iom_rstput( 0, 0, inum, 'e3u_0'   , e3u_0   , ktype = jp_r8 )
       CALL iom_rstput( 0, 0, inum, 'e3v_0'   , e3v_0   , ktype = jp_r8 )
@@ -590,8 +585,8 @@
       CALL iom_rstput( 0, 0, inum, 'e3vw_0'  , e3vw_0  , ktype = jp_r8 )
       !                                         
-      !                             !==  ocean top and bottom level  ==!   (caution: multiplied by ssmask)
-      !
+      !                             !==  wet top and bottom level  ==!   (caution: multiplied by ssmask)
+      !
+      CALL iom_rstput( 0, 0, inum, 'top_level'    , REAL( mikt, wp )*ssmask , ktype = jp_i4 )   ! nb of ocean T-points (ISF)
       CALL iom_rstput( 0, 0, inum, 'bottom_level' , REAL( mbkt, wp )*ssmask , ktype = jp_i4 )   ! nb of ocean T-points
-      CALL iom_rstput( 0, 0, inum, 'top_level'    , REAL( mikt, wp )*ssmask , ktype = jp_i4 )   ! nb of ocean T-points (ISF)
       !
       IF( ln_sco ) THEN             ! s-coordinate: store grid stiffness ratio  (Not required anyway)
Index: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 7177)
+++ branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 7188)
@@ -29,4 +29,5 @@
    USE dom_oce        ! ocean domain
    USE usrdef_zgr     ! user defined vertical coordinate system
+   USE depth_e3       ! depth <=> e3
    !
    USE in_out_manager ! I/O manager
@@ -110,5 +111,5 @@
       ENDIF
       !
-!!gm to be remove when changing the definition of e3 scale factors so that gde3w disappears
+!!gm to be remove when removing the OLD definition of e3 scale factors so that gde3w disappears
       ! Compute gde3w_0 (vertical sum of e3w)
       gde3w_0(:,:,1) = 0.5_wp * e3w_0(:,:,1)
@@ -189,4 +190,5 @@
       INTEGER , DIMENSION(:,:)  , INTENT(out) ::   k_top , k_bot               ! first & last ocean level
       !
+      INTEGER  ::   jk     ! dummy loop index
       INTEGER  ::   inum   ! local logical unit
       REAL(WP) ::   z_zco, z_zps, z_sco, z_cav
@@ -215,27 +217,47 @@
       !
       !                                   ! reference 1D-coordinate
-      CALL iom_get( inum, jpdom_unknown, 'gdept_1d', pdept_1d )   
-      CALL iom_get( inum, jpdom_unknown, 'gdepw_1d', pdepw_1d )
       CALL iom_get( inum, jpdom_unknown, 'e3t_1d'  , pe3t_1d  )
       CALL iom_get( inum, jpdom_unknown, 'e3w_1d'  , pe3w_1d  )
       !
-      !                                   ! depth
-      CALL iom_get( inum, jpdom_data, 'gdept_0', pdept  )
-      CALL iom_get( inum, jpdom_data, 'gdepw_0', pdepw  )
-!      CALL iom_get( inum, jpdom_data, 'gde3w_0', pde3w )
-      !
-      !                                   ! vertical scale factors
-      CALL iom_get( inum, jpdom_data, 'e3t_0'  , pe3t  )
-      CALL iom_get( inum, jpdom_data, 'e3u_0'  , pe3u  )
-      CALL iom_get( inum, jpdom_data, 'e3v_0'  , pe3v  )
-      CALL iom_get( inum, jpdom_data, 'e3f_0'  , pe3f  )
-      CALL iom_get( inum, jpdom_data, 'e3w_0'  , pe3w  )
-      CALL iom_get( inum, jpdom_data, 'e3uw_0' , pe3uw )
-      CALL iom_get( inum, jpdom_data, 'e3vw_0' , pe3vw )
-
+      IF(  iom_varid( inum, 'gdept_1d', ldstop = .FALSE. ) > 0  .AND.  &
+         & iom_varid( inum, 'gdepw_1d', ldstop = .FALSE. ) > 0    ) THEN
+         CALL ctl_warn( 'zgr_read : old definition of 1d depths and scale factors used ', & 
+            &                      'depths at t- and w-points read in domain_cfg file')
+         CALL iom_get( inum, jpdom_unknown, 'gdept_1d', pdept_1d )   
+         CALL iom_get( inum, jpdom_unknown, 'gdepw_1d', pdepw_1d )
+      ELSE 
+         CALL e3_to_depth( pe3t_1d, pe3w_1d, pdept_1d, pdepw_1d )
+         IF(lwp) THEN                        ! control print
+            WRITE(numout,*)
+            WRITE(numout,*) '              Reference 1D z-coordinate depth and scale factors:'
+            WRITE(numout, "(9x,' level  gdept_1d  gdepw_1d  e3t_1d   e3w_1d  ')" )
+            WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, pdept_1d(jk), pdepw_1d(jk), pe3t_1d(jk), pe3w_1d(jk), jk = 1, jpk )
+         ENDIF
+      ENDIF
+      !
+      !                                   ! 3D vertical scale factors
+      CALL iom_get( inum, jpdom_data, 'e3t_0'  , pe3t  , lrowattr=ln_use_jattr )
+      CALL iom_get( inum, jpdom_data, 'e3u_0'  , pe3u  , lrowattr=ln_use_jattr )
+      CALL iom_get( inum, jpdom_data, 'e3v_0'  , pe3v  , lrowattr=ln_use_jattr )
+      CALL iom_get( inum, jpdom_data, 'e3f_0'  , pe3f  , lrowattr=ln_use_jattr )
+      CALL iom_get( inum, jpdom_data, 'e3w_0'  , pe3w  , lrowattr=ln_use_jattr )
+      CALL iom_get( inum, jpdom_data, 'e3uw_0' , pe3uw , lrowattr=ln_use_jattr )
+      CALL iom_get( inum, jpdom_data, 'e3vw_0' , pe3vw , lrowattr=ln_use_jattr )
+      !
+      !                                   ! 3D depths
+      IF(  iom_varid( inum, 'gdept_0', ldstop = .FALSE. ) > 0  .AND.  &
+         & iom_varid( inum, 'gdepw_0', ldstop = .FALSE. ) > 0    ) THEN
+         CALL ctl_warn( 'zgr_read : old definition of depths and scale factors used ', & 
+            &                      'depths at t- and w-points read in domain_cfg file')
+         CALL iom_get( inum, jpdom_data, 'gdept_0' , pdept , lrowattr=ln_use_jattr )
+         CALL iom_get( inum, jpdom_data, 'gdepw_0' , pdepw , lrowattr=ln_use_jattr )
+      ELSE
+         CALL e3_to_depth( pe3t, pe3w, pdept, pdepw )
+      ENDIF
+      !
       !                                   ! ocean top and bottom level
-      CALL iom_get( inum, jpdom_data, 'bottom_level' , z2d    )  ! nb of ocean T-points
+      CALL iom_get( inum, jpdom_data, 'bottom_level' , z2d  , lrowattr=ln_use_jattr )  ! nb of ocean T-points
       k_bot(:,:) = INT( z2d(:,:) )
-      CALL iom_get( inum, jpdom_data, 'top_level'    , z2d     )   ! nb of ocean T-points (ISF)
+      CALL iom_get( inum, jpdom_data, 'top_level'    , z2d  , lrowattr=ln_use_jattr )   ! nb of ocean T-points (ISF)
       k_top(:,:) = INT( z2d(:,:) )
       !
Index: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/USR/usrdef_zgr.F90
===================================================================
--- branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/USR/usrdef_zgr.F90	(revision 7177)
+++ branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/USR/usrdef_zgr.F90	(revision 7188)
@@ -11,17 +11,18 @@
 
    !!----------------------------------------------------------------------
-   !!   usr_def_zgr      : user defined vertical coordinate system
-   !!       zgr_z        : reference 1D z-coordinate 
-   !!       zgr_top_bot  : ocean top and bottom level indices
-   !!       zgr_zco      : 3D verticl coordinate in pure z-coordinate case
+   !!   usr_def_zgr   : user defined vertical coordinate system
+   !!      zgr_z      : reference 1D z-coordinate 
+   !!      zgr_top_bot: ocean top and bottom level indices
+   !!      zgr_zco    : 3D verticl coordinate in pure z-coordinate case
    !!---------------------------------------------------------------------
-   USE oce               ! ocean variables
-   USE dom_oce           ! ocean domain
+   USE oce            ! ocean variables
+   USE dom_oce        ! ocean domain
+   USE depth_e3       ! depth <=> e3
    !
-   USE in_out_manager    ! I/O manager
-   USE lbclnk            ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp           ! distributed memory computing library
-   USE wrk_nemo          ! Memory allocation
-   USE timing            ! Timing
+   USE in_out_manager ! I/O manager
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp        ! distributed memory computing library
+   USE wrk_nemo       ! Memory allocation
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -72,5 +73,5 @@
       ! type of vertical coordinate
       ! ---------------------------
-      ld_zco    = .TRUE.         ! GYRE case:  z-coordinate & no ocean cavities
+      ld_zco    = .TRUE.         ! GYRE case:  z-coordinate without ocean cavities
       ld_zps    = .FALSE.
       ld_sco    = .FALSE.
@@ -80,9 +81,9 @@
       ! Build the vertical coordinate system
       ! ------------------------------------
-      CALL zgr_z  ( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d )  ! Reference z-coordinate system
-      !
-      CALL zgr_msk_top_bot( k_top , k_bot )                  ! masked top and bottom ocean t-level indices
-      !
-      !                                                      ! z-coordinate (3D arrays) from the 1D z-coord.
+      CALL zgr_z( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d )   ! Reference z-coordinate system
+      !
+      CALL zgr_msk_top_bot( k_top , k_bot )                 ! masked top and bottom ocean t-level indices
+      !
+      !                                                     ! z-coordinate (3D arrays) from the 1D z-coord.
       CALL zgr_zco( pdept_1d, pdepw_1d, pe3t_1d, pe3w_1d,   &   ! in  : 1D reference vertical coordinate
          &          pdept   , pdepw   ,                     &   ! out : 3D t & w-points depth
@@ -100,14 +101,20 @@
       !!              vertical scale factors.
       !!
-      !! ** Method  :   z-coordinate system (use in all type of coordinate)
-      !!              The depth of model levels is defined from an analytical
-      !!              function the derivative of which gives the scale factors.
-      !!              both depth and scale factors only depend on k (1d arrays).
-      !!                 w-level: pdepw_1d  = pdep(k)
-      !!                          pe3w_1d(k) = dk(pdep)(k)     = e3(k)
-      !!                 t-level: pdept_1d  = pdep(k+0.5)
-      !!                          pe3t_1d(k) = dk(pdep)(k+0.5) = e3(k+0.5)
-      !!
-      !!      Here the Madec & Imbard (1996) function is used
+      !! ** Method  :   1D z-coordinate system (use in all type of coordinate)
+      !!       The depth of model levels is set from dep(k), an analytical function:
+      !!                   w-level: depw_1d  = dep(k)
+      !!                   t-level: dept_1d  = dep(k+0.5)
+      !!       The scale factors are the discrete derivative of the depth:
+      !!                   e3w_1d(jk) = dk[ dept_1d ] 
+      !!                   e3t_1d(jk) = dk[ depw_1d ]
+      !!           with at top and bottom :
+      !!                   e3w_1d( 1 ) = 2 * ( dept_1d( 1 ) - depw_1d( 1 ) )
+      !!                   e3t_1d(jpk) = 2 * ( dept_1d(jpk) - depw_1d(jpk) )
+      !!       The depth are then re-computed from the sum of e3. This ensures 
+      !!    that depths are identical when reading domain_cfg.nc file. Indeed,
+      !!    Only e3. are saved in this file, depth are compute by a call to 
+      !!    the e3_to_depth subroutine.
+      !!
+      !!       Here the Madec & Imbard (1996) function is used.
       !!
       !! ** Action  : - pdept_1d, pdepw_1d : depth of T- and W-point (m)
@@ -156,26 +163,12 @@
          pdepw_1d(jk) = ( zsur + za0 * zw + za1 * zacr *  LOG( COSH( (zw-zkth) / zacr ) )  )
          pdept_1d(jk) = ( zsur + za0 * zt + za1 * zacr *  LOG( COSH( (zt-zkth) / zacr ) )  )
-         pe3w_1d (jk) =          za0      + za1        * TANH(       (zw-zkth) / zacr   )
-         pe3t_1d (jk) =          za0      + za1        * TANH(       (zt-zkth) / zacr   )
       END DO
-      pdepw_1d(1) = 0._wp                    ! force first w-level to be exactly at zero
-
-
-!!gm   This should become the reference !
-!      IF ( ln_isfcav ) THEN
-! need to be like this to compute the pressure gradient with ISF. If not, level beneath the ISF are not aligned (sum(e3t) /= depth)
-! define pe3t_0 and pe3w_0 as the differences between pdept and pdepw respectively
-!         DO jk = 1, jpkm1
-!            pe3t_1d(jk) = pdepw_1d(jk+1)-pdepw_1d(jk) 
-!         END DO
-!         pe3t_1d(jpk) = pe3t_1d(jpk-1)   ! we don't care because this level is masked in NEMO
-!
-!         DO jk = 2, jpk
-!            pe3w_1d(jk) = pdept_1d(jk) - pdept_1d(jk-1) 
-!         END DO
-!         pe3w_1d(1  ) = 2._wp * (pdept_1d(1) - pdepw_1d(1)) 
-!      END IF
-!!gm end
-
+      !
+      !                       ! e3t and e3w from depth
+      CALL depth_to_e3( pdept_1d, pdepw_1d, pe3t_1d, pe3w_1d ) 
+      !
+      !                       ! recompute depths from SUM(e3)  <== needed
+      CALL e3_to_depth( pe3t_1d, pe3w_1d, pdept_1d, pdepw_1d ) 
+      !
       IF(lwp) THEN                        ! control print
          WRITE(numout,*)
@@ -184,8 +177,4 @@
          WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, pdept_1d(jk), pdepw_1d(jk), pe3t_1d(jk), pe3w_1d(jk), jk = 1, jpk )
       ENDIF
-      DO jk = 1, jpk                      ! control positivity
-         IF( pe3w_1d (jk) <= 0._wp .OR. pe3t_1d (jk) <= 0._wp )   CALL ctl_stop( 'dom:zgr_z: e3w_1d or e3t_1d =< 0 '    )
-         IF( pdepw_1d(jk) <  0._wp .OR. pdept_1d(jk) <  0._wp )   CALL ctl_stop( 'dom:zgr_z: gdepw_1d or gdept_1d < 0 ' )
-      END DO
       !
       IF( nn_timing == 1 )  CALL timing_stop('zgr_z')
Index: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 7177)
+++ branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 7188)
@@ -239,8 +239,8 @@
       INTEGER  ::   ios, inum     !   -      -
       REAL(wp) ::   ziglo, zjglo, zkglo, zperio   ! local scalars
-      CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam, clbug
-      !
-      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
-         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
+      CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
+      !
+      NAMELIST/namctl/ ln_ctl   , nn_print, nn_ictls, nn_ictle,   &
+         &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,   &
          &             nn_timing, nn_diacfl
       NAMELIST/namcfg/ ln_read_cfg, ln_write_cfg, cp_cfg, jp_cfg, ln_use_jattr
@@ -250,5 +250,4 @@
       cltxt2 = ''
       clnam  = ''  
-      clbug  = ''
       cxios_context = 'nemo'
       !
@@ -257,33 +256,24 @@
       CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
       !
-
-!!gm      WRITE(clbug(1),*) ' before namelist / namctl read    nstop', nstop      
-
       REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints
       READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
 901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
-
+      !
       REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints
       READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
 902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
-
-
-!!gm      WRITE(clbug(2),*) ' before namelist namcfg read    nstop', nstop      
-
       !
       REWIND( numnam_ref )              ! Namelist namcfg in reference namelist
       READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
 903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
-
+      !
       REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist
       READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
 904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
 
-!!gm      WRITE(clbug(3),*) ' after namelist namcfg read    nstop', nstop
-
       !                             !--------------------------!
       !                             !  Set global domain size  !   (control print return in cltxt2)
       !                             !--------------------------!
-      IF( ln_read_cfg ) THEN              ! Read sizes in configuration "mesh_mask" file
+      IF( ln_read_cfg ) THEN              ! Read sizes in configuration "domain_cfg" file
          CALL iom_open( 'domain_cfg', inum )
          CALL iom_get( inum, 'jpiglo', ziglo  )   ;   jpiglo = INT( ziglo )
@@ -292,8 +282,9 @@
          CALL iom_get( inum, 'jperio', zperio )   ;   jperio = INT( zperio )
          CALL iom_close( inum )
-         WRITE(cltxt2(1),*) '~~~~~~~~~~   '      
-         WRITE(cltxt2(2),*) 'domain_cfg : domain size read in "domain_cfg" file : jp(i,j,k)glo = '
-         WRITE(cltxt2(3),*) '            ', jpiglo, jpjglo, jpkglo        
-         WRITE(cltxt2(1),*) '~~~~~~~~~~   lateral boudary type of the global domain jperio= ', jperio
+         WRITE(cltxt2(1),*) ' '      
+         WRITE(cltxt2(2),*) 'domain_cfg : domain size read in "domain_cfg" file '         
+         WRITE(cltxt2(3),*) '~~~~~~~~~~    '
+         WRITE(cltxt2(4),*) '   jpiglo = ', jpiglo, ' jpjglo = ', jpjglo,  ' jpkglo = ', jpkglo
+         WRITE(cltxt2(5),*) '   global domain type of lateral boundary   jperio = ', jperio
          !        
       ELSE                                ! user-defined namelist
@@ -404,11 +395,4 @@
          !
 
-         DO ji = 1, SIZE(clbug)
-            IF( TRIM(clbug (ji)) /= '' )   WRITE(numout,*) clbug(ji)      ! bug print 
-         END DO
-         WRITE(numout,*)
-
-
-
 
          WRITE(numout,*)
@@ -425,5 +409,4 @@
          WRITE(numout,*)
          DO ji = 1, SIZE(cltxt2)
-!            IF( TRIM(cltxt2(ji)) /= '' )   WRITE(numout,*) cltxt2(ji)     ! control print of domain size
             IF( cltxt2(ji) /= '' )   WRITE(numout,*) cltxt2(ji)     ! control print of domain size
          END DO
