Index: NEMO/branches/2019/ENHANCE-03_closea/cfgs/SHARED/field_def_nemo-oce.xml
===================================================================
--- NEMO/branches/2019/ENHANCE-03_closea/cfgs/SHARED/field_def_nemo-oce.xml	(revision 11629)
+++ NEMO/branches/2019/ENHANCE-03_closea/cfgs/SHARED/field_def_nemo-oce.xml	(revision 11656)
@@ -250,4 +250,5 @@
           <field id="runoffs"      long_name="River Runoffs"                        standard_name="water_flux_into_sea_water_from_rivers"                                unit="kg/m2/s"   />
           <field id="precip"       long_name="Total precipitation"                  standard_name="precipitation_flux"                                                   unit="kg/m2/s"   />
+          <field id="wclosea"      long_name="closed sea empmr correction"          standard_name="closea_empmr"                                                         unit="kg/m2/s"   />
 	  
           <field id="qt"           long_name="Net Downward Heat Flux"                standard_name="surface_downward_heat_flux_in_sea_water"                              unit="W/m2"                           />
@@ -256,4 +257,5 @@
           <field id="qsr3d"        long_name="Shortwave Radiation 3D distribution"   standard_name="downwelling_shortwave_flux_in_sea_water"                              unit="W/m2"      grid_ref="grid_T_3D" />
           <field id="qrp"          long_name="Surface Heat Flux: Damping"            standard_name="heat_flux_into_sea_water_due_to_newtonian_relaxation"                 unit="W/m2"                           />
+          <field id="qclosea"      long_name="closed sea heat content flux"          standard_name="closea_heat_content_downward_flux"                                    unit="W/m2"     />
           <field id="erp"          long_name="Surface Water Flux: Damping"           standard_name="water_flux_out_of_sea_water_due_to_newtonian_relaxation"              unit="kg/m2/s"                        />
           <field id="taum"         long_name="wind stress module"                    standard_name="magnitude_of_surface_downward_stress"                                 unit="N/m2"                           />
Index: NEMO/branches/2019/ENHANCE-03_closea/cfgs/SHARED/namelist_ref
===================================================================
--- NEMO/branches/2019/ENHANCE-03_closea/cfgs/SHARED/namelist_ref	(revision 11629)
+++ NEMO/branches/2019/ENHANCE-03_closea/cfgs/SHARED/namelist_ref	(revision 11656)
@@ -96,12 +96,13 @@
 &namclo        !   parameters of the closed sea (cs) behavior                (default: OFF)
 !-----------------------------------------------------------------------
-   ln_maskcs = .false.           ! (=T) cs are masked ; 
-      !                          ! (=F) cs masks are read and net evap/precip over closed sea spread out depending on domain_cfg.nc masks
-      !                          ! see ln_mask_csundef and ln_clo_rnf for specific option related to this case
+   ln_maskcs = .false.        ! (=T) cs are masked ; So, in this case ln_mask_csundef and ln_clo_rnf have no effect.
+      !                       ! (=F => set ln_mask_csundef and ln_clo_rnf) 
+      !                       ! cs masks are read and net evap/precip over closed sea spread out depending on domain_cfg.nc masks.
+      !                       ! See ln_mask_csundef and ln_clo_rnf for specific option related to this case
       !
-      ln_mask_csundef = .false.  ! (=T) undefined closed seas are masked ; 
+      ln_mask_csundef = .true.   ! (=T) undefined closed seas are masked ; 
       !                          ! (=F) undefined closed seas are kept and no specific treatment is done for these closed seas
       !
-      ln_clo_rnf = .false.       ! (=T) river mouth specified in domain_cfg.nc masks (rnf and emp case) are added to the runoff mask.
+      ln_clo_rnf = .true.        ! (=T) river mouth specified in domain_cfg.nc masks (rnf and emp case) are added to the runoff mask.
       !                          !      allow the treatment of closed sea outflow grid-points to be the same as river mouth grid-points
 /
Index: NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/closea.F90
===================================================================
--- NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/closea.F90	(revision 11629)
+++ NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/closea.F90	(revision 11656)
@@ -19,19 +19,14 @@
    !!   clo_msk    : set to zero a field over closed sea (see domzgr)
    !!----------------------------------------------------------------------
-   USE oce             ! dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE sbc_oce         ! ocean surface boundary conditions
-   USE iom             ! I/O routines
+   USE in_out_manager  ! I/O manager
    !
-   USE in_out_manager  ! I/O manager
-   USE lib_fortran,    ONLY: glob_sum
-   USE lbclnk          ! lateral boundary condition - MPP exchanges
-   USE lib_mpp         ! MPP library
-   USE timing          ! Timing
+   USE diurnal_bulk, ONLY: ln_diurnal_only            ! used for sanity check
+   USE iom         , ONLY: iom_open, iom_get, iom_close, jpdom_data ! I/O routines
+   USE lib_fortran , ONLY: glob_sum                   ! fortran library
+   USE lib_mpp     , ONLY: mpp_max, ctl_nam, ctl_stop ! MPP library
 
    IMPLICIT NONE
-   PRIVATE read_csmask
-   PRIVATE alloc_csmask
+
+   PRIVATE
 
    PUBLIC dom_clo      ! called by domain module
@@ -50,9 +45,9 @@
    INTEGER, PUBLIC :: ncse      !: number of closed seas empmr  mappings (inferred from closea_mask_emp field)
 
-   INTEGER, PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:) :: mask_opnsea, mask_csundef !: mask defining the open sea and the undefined closed sea
+   INTEGER, PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:) :: mask_opnsea, mask_csundef  !: mask defining the open sea and the undefined closed sea
  
-   INTEGER, PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:) :: mask_csglo, mask_csgrpglo !: mask of integers defining closed seas
-   INTEGER, PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:) :: mask_csrnf, mask_csgrprnf !: mask of integers defining closed seas rnf mappings
-   INTEGER, PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:) :: mask_csemp, mask_csgrpemp !: mask of integers defining closed seas empmr mappings
+   INTEGER, PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:) :: mask_csglo , mask_csgrpglo !: mask of integers defining closed seas
+   INTEGER, PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:) :: mask_csrnf , mask_csgrprnf !: mask of integers defining closed seas rnf mappings
+   INTEGER, PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:) :: mask_csemp , mask_csgrpemp !: mask of integers defining closed seas empmr mappings
 
    !! * Substitutions
@@ -97,4 +92,5 @@
       IF(lwp) WRITE(numout,*)'dom_clo : read in masks to define closed seas '
       IF(lwp) WRITE(numout,*)'~~~~~~~'
+      IF(lwp) WRITE(numout,*)
       !!
       !! check option compatibility
@@ -116,4 +112,6 @@
       IF ( ln_maskcs ) THEN
          ! closed sea are masked
+         IF(lwp) WRITE(numout,*)'          ln_maskcs = T : all closed seas are masked'
+         IF(lwp) WRITE(numout,*)
          ! no special treatment of closed sea
          ! no redistribution of emp unbalance over closed sea into river mouth/open ocean
@@ -121,4 +119,6 @@
       ELSE
          ! redistribution of emp unbalance over closed sea into river mouth/open ocean
+         IF(lwp) WRITE(numout,*)'          ln_maskcs = F : net emp is corrected over defined closed seas'
+         !
          l_sbc_clo = .true.
          !
@@ -126,12 +126,15 @@
          IF ( ln_clo_rnf) l_clo_rnf = .true.
          !
-         ! closed sea not defined (ie not in the domcfg namelist used to build the domcfg.nc file) are masked 
          IF ( ln_mask_csundef) THEN
+            ! closed sea not defined (ie not in the domcfg namelist used to build the domcfg.nc file) are masked 
+            IF(lwp) WRITE(numout,*)'          ln_mask_csundef = T : all undefined closed seas are masked'
+            !
             CALL alloc_csmask( mask_csundef )
             CALL read_csmask( cn_domcfg, 'mask_csundef', mask_csundef )
             ! revert the mask for masking of undefined closed seas in domzgr 
             ! (0 over the undefined closed sea and 1 elsewhere)
-            mask_csundef = 1 - mask_csundef
+            mask_csundef(:,:) = 1 - mask_csundef(:,:)
          END IF
+         IF(lwp) WRITE(numout,*)
          !
          ! allocate source mask for each cases
Index: NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/domain.F90
===================================================================
--- NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/domain.F90	(revision 11629)
+++ NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/domain.F90	(revision 11656)
@@ -30,5 +30,4 @@
    USE trc_oce        ! shared ocean & passive tracers variab
    USE phycst         ! physical constants
-   USE closea         ! closed seas
    USE domhgr         ! domain: set the horizontal mesh
    USE domzgr         ! domain: set the vertical mesh
@@ -38,5 +37,6 @@
    USE c1d            ! 1D configuration
    USE dyncor_c1d     ! 1D configuration: Coriolis term    (cor_c1d routine)
-   USE wet_dry,  ONLY : ll_wd
+   USE wet_dry, ONLY : ll_wd
+   USE closea , ONLY : dom_clo ! closed seas
    !
    USE in_out_manager ! I/O manager
Index: NEMO/branches/2019/ENHANCE-03_closea/src/OCE/SBC/sbcclo.F90
===================================================================
--- NEMO/branches/2019/ENHANCE-03_closea/src/OCE/SBC/sbcclo.F90	(revision 11629)
+++ NEMO/branches/2019/ENHANCE-03_closea/src/OCE/SBC/sbcclo.F90	(revision 11656)
@@ -22,14 +22,13 @@
    !!----------------------------------------------------------------------
    !
-   USE oce             ! dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE closea          ! closed sea 
-   USE phycst          ! physical constants
-   USE sbc_oce         ! ocean surface boundary conditions
-   USE iom             ! I/O routines
-   !
-   USE in_out_manager  ! I/O manager
-   USE lib_fortran,    ONLY: glob_sum
-   USE lib_mpp         ! MPP library
+   USE closea                                  ! closed sea 
+   USE in_out_manager                          ! I/O manager
+   !
+   USE dom_oce,     ONLY: e1e2t                ! ocean space and time domain
+   USE phycst ,     ONLY: rcp                  ! physical constants
+   USE sbc_oce,     ONLY: emp, qns, rnf, sst_m ! ocean surface boundary conditions
+   USE iom    ,     ONLY: iom_put              ! I/O routines
+   USE lib_fortran, ONLY: glob_sum             ! fortran library
+   USE lib_mpp    , ONLY: mpp_min, ctl_stop    ! MPP library
    !
    IMPLICIT NONE
@@ -270,22 +269,29 @@
       INTEGER, DIMENSION(jpi,jpj) :: imsk_src, imsk_trg  ! tmp array source and target closed sea masks
       
-      REAL(wp) :: zcoef, zcoef1, ztmp ! tmp
-      REAL(wp) :: zcsfwf              ! tmp net fwf over one closed sea
-      REAL(wp) :: zsurftrg            ! tmp target surface area
+      REAL(wp) :: zcsfw, zcsh        ! total fresh water and associated heat over one closed sea
+      REAL(wp) :: zcsfwf             ! mean fresh water flux over one closed sea
+      REAL(wp) :: zsurftrg, zsurfsrc ! total target surface area
       !!----------------------------------------------------------------------
       !
       DO jcs = 1, kncs  ! loop over closed seas
          !
-         !! 0. get mask of the closed sea
-         imsk_src(:,:) = 0
-         WHERE ( kmsk_src(:,:) == jcs ) imsk_src(:,:) = 1
-         !
-         !! 1. Work out net freshwater fluxes over the closed sea from EMP - RNF.
+         !! 0. get mask and surface of the closed sea
+         ! mask src
+         WHERE ( kmsk_src(:,:) == jcs ) 
+            imsk_src(:,:) = 1
+         ELSEWHERE
+            imsk_src(:,:) = 0
+         END WHERE
+         ! area src
+         zsurfsrc = psurfsrc(jcs)
+         !
+         !! 1. Work out net freshwater over the closed sea from EMP - RNF.
+         !!    Work out net heat associated with the correction (needed for conservation)
          !!    (PM: should we consider used delayed glob sum ?)
-         zcsfwf = glob_sum( 'closea', e1e2t(:,:) * ( emp(:,:)-rnf(:,:) ) * imsk_src(:,:) )
+         zcsfw  = glob_sum( 'closea', e1e2t(:,:) * ( emp(:,:)-rnf(:,:) ) * imsk_src(:,:) )
          !
          !! 2. Deal with runoff special case (net evaporation spread globally)
          !!    and compute trg mask
-         IF (cdcstype == 'rnf' .AND. zcsfwf > 0) THEN
+         IF (cdcstype == 'rnf' .AND. zcsfw  > 0._wp) THEN
             zsurftrg = psurf_opnsea(1)           ! change the target area surface
             imsk_trg = kcsgrp(jcs) * kmsk_opnsea ! trg mask is now the open sea mask
@@ -295,22 +301,17 @@
          END IF
          !
-         !! 3. Add residuals to target points
-         zcoef  = zcsfwf / zsurftrg
-         zcoef1 = rcp * zcoef
+         !! 3. Subtract residuals from source points
+         zcsfwf = zcsfw / zsurfsrc
+         pwcs(:,:) = pwcs(:,:) -       zcsfwf              * imsk_src(:,:)
+         pqcs(:,:) = pqcs(:,:) + rcp * zcsfwf * sst_m(:,:) * imsk_src(:,:)
+         !
+         !! 4. Add residuals to target points 
+         !!    Do not use pqcs(:,:) = pqcs(:,:) - rcp * zcsfw  * sst_m(:,:) / zsurftrg 
+         !!    as there is no reason for heat conservation with this formulation
+         zcsh   = glob_sum( 'closea', e1e2t(:,:) * rcp * zcsfwf * sst_m(:,:) * imsk_src(:,:) )
          WHERE( imsk_trg(:,:) == kcsgrp(jcs) )
-            pwcs(:,:) = pwcs(:,:) + zcoef
-            pqcs(:,:) = pqcs(:,:) - zcoef1 * sst_m(:,:)
+            pwcs(:,:) = pwcs(:,:) + zcsfw / zsurftrg
+            pqcs(:,:) = pqcs(:,:) - zcsh  / zsurftrg
          ENDWHERE
-         !
-         !! 4. Subtract residuals from source points
-         zcoef    = zcsfwf / psurfsrc(jcs)
-         zcoef1   = rcp * zcoef
-         WHERE( kmsk_src(:,:) == jcs )
-            pwcs(:,:) = pwcs(:,:) - zcoef
-            pqcs(:,:) = pqcs(:,:) + zcoef1 * sst_m(:,:)
-         ENDWHERE
-         ! WARNING (PM): the correction is done as it was done in the previous version
-         !               this do no conserve heat as there is no reason that 
-         !               sum(zcoef1*sst_m) over the source (closed sea) (4) = sum(zcoef1*sst_m) over the target (river mouth) (3)
          !
       END DO ! jcs
Index: NEMO/branches/2019/ENHANCE-03_closea/src/OCE/SBC/sbcrnf.F90
===================================================================
--- NEMO/branches/2019/ENHANCE-03_closea/src/OCE/SBC/sbcrnf.F90	(revision 11629)
+++ NEMO/branches/2019/ENHANCE-03_closea/src/OCE/SBC/sbcrnf.F90	(revision 11656)
@@ -21,5 +21,5 @@
    USE sbcisf         ! PM we could remove it I think
    USE eosbn2         ! Equation Of State
-   USE closea         ! closed seas
+   USE closea, ONLY: l_clo_rnf, clo_rnf ! closed seas
    !
    USE in_out_manager ! I/O manager
