Index: NEMO/branches/2019/ENHANCE-03_closea/cfgs/SHARED/namelist_ref
===================================================================
--- NEMO/trunk/cfgs/SHARED/namelist_ref	(revision 11190)
+++ NEMO/branches/2019/ENHANCE-03_closea/cfgs/SHARED/namelist_ref	(revision 11207)
@@ -80,19 +80,29 @@
 &namcfg        !   parameters of the configuration                      (default: use namusr_def in namelist_cfg)
 !-----------------------------------------------------------------------
-   ln_read_cfg = .false.   !  (=T) read the domain configuration file
-      !                    !  (=F) user defined configuration           (F => create/check namusr_def)
+   ln_read_cfg = .false.     !  (=T) read the domain configuration file
+      !                      !  (=F) user defined configuration           (F => create/check namusr_def)
       cn_domcfg = "domain_cfg"  ! domain configuration filename
       !
-      ln_closea    = .false.    !  T => keep closed seas (defined by closea_mask field) in the  
-      !                         !       domain and apply special treatment of freshwater fluxes.
-      !                         !  F => suppress closed seas (defined by closea_mask field) 
-      !                         !       from the bathymetry at runtime.
-      !                         !  If closea_mask field doesn't exist in the domain_cfg file
-      !                         !       then this logical does nothing.
-   ln_write_cfg = .false.   !  (=T) create the domain configuration file
+      ln_closea    = .false. !  (=T => fill namclo) 
+      !                      !  (=F) no control of net precip/evap over closed sea
+      !
+   ln_write_cfg = .false.    !  (=T) create the domain configuration file
       cn_domcfg_out = "domain_cfg_out" ! newly created domain configuration filename
       !
-   ln_use_jattr = .false.  !  use (T) the file attribute: open_ocean_jstart, if present
-   !                       !  in netcdf input files, as the start j-row for reading
+   ln_use_jattr = .false.    !  use (T) the file attribute: open_ocean_jstart, if present
+   !                         !  in netcdf input files, as the start j-row for reading
+/
+!-----------------------------------------------------------------------
+&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_mask_csundef = .false.  ! (=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.
+      !                          !      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/trunk/src/OCE/DOM/closea.F90	(revision 11190)
+++ NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/closea.F90	(revision 11207)
@@ -11,4 +11,5 @@
    !!             4.0  !  2016-06  (G. Madec)  move to usrdef_closea, remove clo_ups
    !!             4.0  !  2017-12  (D. Storkey) new formulation based on masks read from file
+   !!             4.1  !  2019-07  (P. Mathiot) update to the new domcfg.nc input file
    !!----------------------------------------------------------------------
 
@@ -35,29 +36,31 @@
 
    PUBLIC dom_clo      ! called by domain module
+   PUBLIC sbc_clo_init ! called by sbcmod module
    PUBLIC sbc_clo      ! called by sbcmod module
    PUBLIC clo_rnf      ! called by sbcrnf module
    PUBLIC clo_bat      ! called in domzgr module
 
-   LOGICAL, PUBLIC :: ln_closea  !:  T => keep closed seas (defined by closea_mask field) in the domain and apply
-                                 !:       special treatment of freshwater fluxes.
-                                 !:  F => suppress closed seas (defined by closea_mask field) from the bathymetry
-                                 !:       at runtime.
-                                 !:  If there is no closea_mask field in the domain_cfg file or we do not use
-                                 !:  a domain_cfg file then this logical does nothing.
-                                 !:
-   LOGICAL, PUBLIC :: l_sbc_clo  !: T => Closed seas defined, apply special treatment of freshwater fluxes.
-                                 !: F => No closed seas defined (closea_mask field not found).
-   LOGICAL, PUBLIC :: l_clo_rnf  !: T => Some closed seas output freshwater (RNF or EMPMR) to specified runoff points.
-   INTEGER, PUBLIC :: jncs       !: number of closed seas (inferred from closea_mask field)
-   INTEGER, PUBLIC :: jncsr      !: number of closed seas rnf mappings (inferred from closea_mask_rnf field)
-   INTEGER, PUBLIC :: jncse      !: number of closed seas empmr mappings (inferred from closea_mask_empmr field)
-   
-   INTEGER, PUBLIC, ALLOCATABLE, DIMENSION(:,:) ::  closea_mask       !: mask of integers defining closed seas
-   INTEGER, PUBLIC, ALLOCATABLE, DIMENSION(:,:) ::  closea_mask_rnf   !: mask of integers defining closed seas rnf mappings
-   INTEGER, PUBLIC, ALLOCATABLE, DIMENSION(:,:) ::  closea_mask_empmr !: mask of integers defining closed seas empmr mappings
-   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:)  ::   surf         !: closed sea surface areas 
-                                                                  !: (and residual global surface area) 
-   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:)  ::   surfr        !: closed sea target rnf surface areas 
-   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:)  ::   surfe        !: closed sea target empmr surface areas 
+   LOGICAL, PUBLIC :: ln_maskcs  !: mask all closed sea
+   LOGICAL, PUBLIC :: ln_mask_csundef  !: mask all closed sea
+   LOGICAL, PUBLIC :: ln_clo_rnf !: closed sea treated as runoff (update rnf mask)
+
+   LOGICAL, PUBLIC :: l_sbc_clo  !: T => net evap/precip over closed seas spread outover the globe/river mouth
+   LOGICAL, PUBLIC :: l_clo_rnf  !: T => Some closed seas output freshwater (RNF) to specified runoff points.
+
+   INTEGER, PUBLIC :: jncsg      !: number of closed seas global mappings (inferred from closea_mask_glo field)
+   INTEGER, PUBLIC :: jncsr      !: number of closed seas rnf    mappings (inferred from closea_mask_rnf field)
+   INTEGER, PUBLIC :: jncse      !: number of closed seas empmr  mappings (inferred from closea_mask_emp field)
+
+   INTEGER, PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:)   :: jcsgrpg, jcsgrpr, jcsgrpe
+  
+   INTEGER, PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:) :: mask_opnsea, mask_csundef 
+ 
+   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
+
+   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:) :: rsurfsrcg, rsurftrgg !: closed sea target glo surface areas 
+   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:) :: rsurfsrcr, rsurftrgr !: closed sea target rnf surface areas 
+   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:) :: rsurfsrce, rsurftrge !: closed sea target emp surface areas 
 
    !! * Substitutions
@@ -79,116 +82,224 @@
       !!                just the thermodynamic processes are applied.
       !!
-      !! ** Action  :   Read closea_mask* fields (if they exist) from domain_cfg file and infer
-      !!                number of closed seas from closea_mask field.
-      !!                closea_mask       : integer values defining closed seas (or groups of closed seas)
-      !!                closea_mask_rnf   : integer values defining mappings from closed seas or groups of
-      !!                                    closed seas to a runoff area for downwards flux only.
-      !!                closea_mask_empmr : integer values defining mappings from closed seas or groups of
-      !!                                    closed seas to a runoff area for net fluxes.
-      !!
-      !!                Python code to generate the closea_masks* fields from the old-style indices
-      !!                definitions is available at TOOLS/DOMAINcfg/make_closea_masks.py
-      !!----------------------------------------------------------------------
-      INTEGER ::   inum    ! input file identifier
-      INTEGER ::   ierr    ! error code
-      INTEGER ::   id      ! netcdf variable ID
-
-      REAL(wp), DIMENSION(jpi,jpj) :: zdata_in ! temporary real array for input
-      !!----------------------------------------------------------------------
-      !
+      !! ** Action  :   Read mask_cs* fields (if needed) from domain_cfg file and infer
+      !!                number of closed seas for each case (glo, rnf, emp) from mask_cs* field.
+      !!                mask_csglo and mask_csgrpglo  : integer values defining mappings from closed seas and associated groups to the open ocean for net fluxes.
+      !!                mask_csrnf and mask_csgrprnf  : integer values defining mappings from closed seas and associated groups to a runoff area for downwards flux only.
+      !!                mask_csemp and mask_csgrpemp  : integer values defining mappings from closed seas and associated groups to a runoff area for net fluxes.
+      !!----------------------------------------------------------------------
+      INTEGER ::   ios     ! io status
+      !!
+      NAMELIST/namclo/ ln_maskcs, ln_mask_csundef, ln_clo_rnf
+      !!---------------------------------------------------------------------
+      !!
+      REWIND( numnam_ref )              ! Namelist namclo in reference namelist : Lateral momentum boundary condition
+      READ  ( numnam_ref, namclo, IOSTAT = ios, ERR = 901 )
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namclo in reference namelist', lwp )
+      REWIND( numnam_cfg )              ! Namelist namclo in configuration namelist : Lateral momentum boundary condition
+      READ  ( numnam_cfg, namclo, IOSTAT = ios, ERR = 902 )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namclo in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, namclo )
+      !!
       IF(lwp) WRITE(numout,*)
       IF(lwp) WRITE(numout,*)'dom_clo : read in masks to define closed seas '
       IF(lwp) WRITE(numout,*)'~~~~~~~'
+      !!
+      !! check option compatibility
+      IF( .NOT. ln_read_cfg ) THEN
+         CALL ctl_stop('Suppression of closed seas does not work with ln_read_cfg = .true. . Set ln_closea = .false. .')
+      ENDIF
+      !!
+      IF( (.NOT. ln_maskcs) .AND. ln_diurnal_only ) THEN
+         CALL ctl_stop('Special handling of freshwater fluxes over closed seas not compatible with ln_diurnal_only.')
+      END IF
+      !
+      l_sbc_clo = .false. ; l_clo_rnf = .false.
+      IF (.NOT. ln_maskcs)                  l_sbc_clo = .true.
+      IF (.NOT. ln_maskcs .AND. ln_clo_rnf) l_clo_rnf = .true.
       !
       ! read the closed seas masks (if they exist) from domain_cfg file (if it exists)
       ! ------------------------------------------------------------------------------
       !
-      IF( ln_read_cfg) THEN
-         !
-         CALL iom_open( cn_domcfg, inum )
-         !
-         id = iom_varid(inum, 'closea_mask', ldstop = .false.)
-         IF( id > 0 ) THEN 
-            l_sbc_clo = .true.
-            ALLOCATE( closea_mask(jpi,jpj) , STAT=ierr )
-            IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'dom_clo: failed to allocate closea_mask array')
-            zdata_in(:,:) = 0.0
-            CALL iom_get ( inum, jpdom_data, 'closea_mask', zdata_in )
-            closea_mask(:,:) = NINT(zdata_in(:,:)) * tmask(:,:,1)
-            ! number of closed seas = global maximum value in closea_mask field
-            jncs = maxval(closea_mask(:,:))
-            CALL mpp_max('closea', jncs)
-            IF( jncs > 0 ) THEN
-               IF( lwp ) WRITE(numout,*) 'Number of closed seas : ',jncs
-            ELSE
-               CALL ctl_stop( 'Problem with closea_mask field in domain_cfg file. Has no values > 0 so no closed seas defined.')
-            ENDIF
-         ELSE 
-            IF( lwp ) WRITE(numout,*)
-            IF( lwp ) WRITE(numout,*) '   ==>>>   closea_mask field not found in domain_cfg file.'
-            IF( lwp ) WRITE(numout,*) '           No closed seas defined.'
-            IF( lwp ) WRITE(numout,*)
-            l_sbc_clo = .false.
-            jncs = 0 
-         ENDIF
-
-         l_clo_rnf = .false.
-
-         IF( l_sbc_clo ) THEN ! No point reading in closea_mask_rnf or closea_mask_empmr fields if no closed seas defined.
-
-            id = iom_varid(inum, 'closea_mask_rnf', ldstop = .false.)
-            IF( id > 0 ) THEN 
-               l_clo_rnf = .true.            
-               ALLOCATE( closea_mask_rnf(jpi,jpj) , STAT=ierr )
-               IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'dom_clo: failed to allocate closea_mask_rnf array')
-               CALL iom_get ( inum, jpdom_data, 'closea_mask_rnf', zdata_in )
-               closea_mask_rnf(:,:) = NINT(zdata_in(:,:)) * tmask(:,:,1)
-               ! number of closed seas rnf mappings = global maximum in closea_mask_rnf field
-               jncsr = maxval(closea_mask_rnf(:,:))
-               CALL mpp_max('closea', jncsr)
-               IF( jncsr > 0 ) THEN
-                  IF( lwp ) WRITE(numout,*) 'Number of closed seas rnf mappings : ',jncsr
-               ELSE
-                  CALL ctl_stop( 'Problem with closea_mask_rnf field in domain_cfg file. Has no values > 0 so no closed seas rnf mappings defined.')
-               ENDIF
-            ELSE 
-               IF( lwp ) WRITE(numout,*) 'closea_mask_rnf field not found in domain_cfg file. No closed seas rnf mappings defined.'
-               jncsr = 0
-            ENDIF
- 
-            id = iom_varid(inum, 'closea_mask_empmr', ldstop = .false.)
-            IF( id > 0 ) THEN 
-               l_clo_rnf = .true.            
-               ALLOCATE( closea_mask_empmr(jpi,jpj) , STAT=ierr )
-               IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'dom_clo: failed to allocate closea_mask_empmr array')
-               CALL iom_get ( inum, jpdom_data, 'closea_mask_empmr', zdata_in )
-               closea_mask_empmr(:,:) = NINT(zdata_in(:,:)) * tmask(:,:,1)
-               ! number of closed seas empmr mappings = global maximum value in closea_mask_empmr field
-               jncse = maxval(closea_mask_empmr(:,:))
-               CALL mpp_max('closea', jncse)
-               IF( jncse > 0 ) THEN 
-                  IF( lwp ) WRITE(numout,*) 'Number of closed seas empmr mappings : ',jncse
-               ELSE
-                  CALL ctl_stop( 'Problem with closea_mask_empmr field in domain_cfg file. Has no values > 0 so no closed seas empmr mappings defined.')
-               ENDIF
-            ELSE 
-               IF( lwp ) WRITE(numout,*) 'closea_mask_empmr field not found in domain_cfg file. No closed seas empmr mappings defined.'
-               jncse = 0
-            ENDIF
-
-         ENDIF ! l_sbc_clo
-         !
-         CALL iom_close( inum )
-         !
-      ELSE ! ln_read_cfg = .false. so no domain_cfg file
-         IF( lwp ) WRITE(numout,*) 'No domain_cfg file so no closed seas defined.'
-         l_sbc_clo = .false.
-         l_clo_rnf = .false.
-      ENDIF
-      !
+      ! load mask of open sea and undefined closed seas
+      CALL alloc_csmask( mask_opnsea )
+      CALL read_csmask( cn_domcfg, 'mask_opensea' , mask_opnsea  )
+      !
+      IF ( ln_maskcs ) THEN
+         ! not special treatment of closed sea
+         l_sbc_clo = .false. ; l_clo_rnf = .false.
+      ELSE
+         ! special treatment of closed seas
+         l_sbc_clo = .true.
+         !
+         ! river mouth from lakes added to rnf mask for special treatment
+         IF ( ln_clo_rnf) l_clo_rnf = .true.
+         !
+         IF ( ln_mask_csundef) THEN
+            ! load undef cs mask (1 in undef closed sea)
+            CALL alloc_csmask( mask_csundef )
+            CALL read_csmask( cn_domcfg, 'mask_csundef', mask_csundef )
+            ! revert the mask for masking in domzgr
+            mask_csundef = 1 - mask_csundef
+         END IF
+         !
+         ! allocate source mask
+         CALL alloc_csmask( mask_csglo )
+         CALL alloc_csmask( mask_csrnf )
+         CALL alloc_csmask( mask_csemp )
+         !
+         ! load source mask of cs for each cases
+         CALL read_csmask( cn_domcfg, 'mask_csglo', mask_csglo )
+         CALL read_csmask( cn_domcfg, 'mask_csrnf', mask_csrnf )
+         CALL read_csmask( cn_domcfg, 'mask_csemp', mask_csemp )
+         !
+         ! compute number of cs for each cases
+         jncsg = MAXVAL( mask_csglo(:,:) ) ; CALL mpp_max( 'closea', jncsg )
+         jncsr = MAXVAL( mask_csrnf(:,:) ) ; CALL mpp_max( 'closea', jncsr )
+         jncse = MAXVAL( mask_csemp(:,:) ) ; CALL mpp_max( 'closea', jncse )
+         !
+         ! allocate closed sea group masks
+         CALL alloc_csmask( mask_csgrpglo )
+         CALL alloc_csmask( mask_csgrprnf )
+         CALL alloc_csmask( mask_csgrpemp )
+
+         ! load mask of cs group for each cases
+         CALL read_csmask( cn_domcfg, 'mask_csgrpglo', mask_csgrpglo )
+         CALL read_csmask( cn_domcfg, 'mask_csgrprnf', mask_csgrprnf )
+         CALL read_csmask( cn_domcfg, 'mask_csgrpemp', mask_csgrpemp )
+         !
+         ! Allocate cs variables (surf)
+         CALL alloc_cssurf( jncsg, rsurfsrcg, rsurftrgg ) 
+         CALL alloc_cssurf( jncsr, rsurfsrcr, rsurftrgr )
+         CALL alloc_cssurf( jncse, rsurfsrce, rsurftrge )
+         !
+         ! Allocate cs group variables (jcsgrp)
+         CALL alloc_csgrp( jncsg, jcsgrpg )
+         CALL alloc_csgrp( jncsr, jcsgrpr )
+         CALL alloc_csgrp( jncse, jcsgrpe )
+         !
+      END IF
    END SUBROUTINE dom_clo
 
-
-   SUBROUTINE sbc_clo( kt )
+   SUBROUTINE sbc_clo_init
+
+      ! compute source surface area
+      CALL get_cssrcsurf( jncsg, mask_csglo, rsurfsrcg )
+      CALL get_cssrcsurf( jncsr, mask_csrnf, rsurfsrcr )
+      CALL get_cssrcsurf( jncse, mask_csemp, rsurfsrce )
+      !
+      ! compute target surface area and group number (jcsgrp) for all cs and cases 
+      ! glo could be simpler but for lisibility, all treated the same way
+      ! It is only done once, so not a big deal
+      CALL get_cstrgsurf( jncsg, mask_csglo, mask_csgrpglo, rsurftrgg, jcsgrpg )
+      CALL get_cstrgsurf( jncsr, mask_csrnf, mask_csgrprnf, rsurftrgr, jcsgrpr )
+      CALL get_cstrgsurf( jncse, mask_csemp, mask_csgrpemp, rsurftrge, jcsgrpe )
+      ! 
+      ! print out in ocean.ouput
+      CALL prt_csctl( jncsg, rsurfsrcg, rsurftrgg, jcsgrpg, 'glo' )
+      CALL prt_csctl( jncsr, rsurfsrcr, rsurftrgr, jcsgrpr, 'rnf' )
+      CALL prt_csctl( jncse, rsurfsrce, rsurftrge, jcsgrpe, 'emp' )
+
+   END SUBROUTINE sbc_clo_init
+
+   SUBROUTINE get_cssrcsurf(kncs, pmaskcs, psurfsrc)
+
+      ! subroutine parameters
+      INTEGER,                 INTENT(in   ) :: kncs
+      INTEGER, DIMENSION(:,:), INTENT(in   ) :: pmaskcs
+
+      REAL(wp), DIMENSION(:)  , INTENT(inout) :: psurfsrc
+
+      ! local variables
+      INTEGER, DIMENSION(jpi,jpj) :: zmsksrc
+      INTEGER :: jcs
+
+      DO jcs = 1,kncs
+         !
+         ! build river mouth mask for this lake
+         WHERE ( pmaskcs == jcs )
+            zmsksrc = 1
+         ELSE WHERE
+            zmsksrc = 0
+         END WHERE
+         !
+         ! compute target area
+         psurfsrc(jcs) = glob_sum('closea', e1e2t(:,:) * zmsksrc(:,:) )
+         !
+      END DO
+
+   END SUBROUTINE
+
+   SUBROUTINE get_cstrgsurf(kncs, pmaskcs, pmaskcsgrp, psurftrg, kcsgrp )
+
+      ! subroutine parameters
+      INTEGER,               INTENT(in   ) :: kncs
+      INTEGER, DIMENSION(:), INTENT(inout) :: kcsgrp
+      INTEGER, DIMENSION(:,:), INTENT(in   ) :: pmaskcs, pmaskcsgrp
+
+      REAL(wp), DIMENSION(:)  , INTENT(inout) :: psurftrg
+
+      ! local variables
+      INTEGER, DIMENSION(jpi,jpj) :: zmskgrp, zmsksrc, zmsktrg
+      INTEGER :: jcs, jtmp
+
+      DO jcs = 1,kncs
+         !
+         ! find group number
+         zmskgrp = pmaskcsgrp
+         zmsksrc = pmaskcs
+         !
+         ! set value where cs is
+         zmsktrg = HUGE(1)
+         WHERE ( zmsksrc == jcs ) zmsktrg = jcs
+         !
+         ! zmsk = HUGE outside the cs number jcs
+         ! ktmp = jcs - group number
+         ! jgrp = group corresponding to the cs jcs
+         zmsktrg = zmsktrg - zmskgrp
+         jtmp = MINVAL(zmsktrg) ; CALL mpp_min('closea',jtmp)
+         kcsgrp(jcs) = jcs - jtmp
+         !
+         ! build river mouth mask for this lake
+         WHERE ( zmskgrp * mask_opnsea == kcsgrp(jcs) )
+            zmsktrg = 1
+         ELSE WHERE
+            zmsktrg = 0
+         END WHERE
+         !
+         ! compute target area
+         psurftrg(jcs) = glob_sum('closea', e1e2t(:,:) * zmsktrg(:,:) )
+         !
+      END DO
+
+   END SUBROUTINE
+
+   SUBROUTINE prt_csctl(kncs, psurfsrc, psurftrg, kcsgrp, pcstype)
+      ! subroutine parameters
+      INTEGER, INTENT(in   ) :: kncs
+      INTEGER, DIMENSION(:), INTENT(in   ) :: kcsgrp
+      !
+      REAL(wp), DIMENSION(:), INTENT(in   ) :: psurfsrc, psurftrg
+      !
+      CHARACTER(256), INTENT(in   ) :: pcstype
+      !
+      ! local variable
+      INTEGER :: jcs
+      
+      IF ( lwp .AND. kncs > 0 ) THEN
+         WRITE(numout,*)''
+         !
+         WRITE(numout,*)'Closed sea target ',TRIM(pcstype),' : '
+         !
+         DO jcs = 1,kncs
+            WRITE(numout,FMT='(3a,i3,a,i3)') ' ',TRIM(pcstype),' closed sea id is ',jcs,' and trg id is : ', kcsgrp(jcs)
+            WRITE(numout,FMT='(a,f12.2)'   ) ' src surface areas (km2) : ', psurfsrc(jcs) * 1.0e-6
+            WRITE(numout,FMT='(a,f12.2)'   ) ' trg surface areas (km2) : ', psurftrg(jcs) * 1.0e-6
+         END DO
+         !
+         WRITE(numout,*)''
+      END IF
+   END SUBROUTINE
+
+   SUBROUTINE sbc_clo( kt ) ! to be move in SBC in a file sbcclo ???
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE sbc_clo  ***
@@ -203,204 +314,85 @@
       !!----------------------------------------------------------------------
       INTEGER         , INTENT(in   ) ::   kt       ! ocean model time step
-      !
-      INTEGER             ::   ierr
-      INTEGER             ::   jc, jcr, jce   ! dummy loop indices
-      REAL(wp), PARAMETER ::   rsmall = 1.e-20_wp    ! Closed sea correction epsilon
-      REAL(wp)            ::   zfwf_total, zcoef, zcoef1         ! 
-      REAL(wp), DIMENSION(jncs)    ::   zfwf      !:
-      REAL(wp), DIMENSION(jncsr+1) ::   zfwfr     !: freshwater fluxes over closed seas
-      REAL(wp), DIMENSION(jncse+1) ::   zfwfe     !: 
-      REAL(wp), DIMENSION(jpi,jpj) ::   ztmp2d   ! 2D workspace
       !!----------------------------------------------------------------------
       !
       IF( ln_timing )  CALL timing_start('sbc_clo')
       !
-      !                                                   !------------------! 
-      IF( kt == nit000 ) THEN                             !  Initialisation  !
-         !                                                !------------------!
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*)'sbc_clo : closed seas '
-         IF(lwp) WRITE(numout,*)'~~~~~~~'
-
-         ALLOCATE( surf(jncs+1) , STAT=ierr )
-         IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'sbc_clo: failed to allocate surf array')
-         surf(:) = 0.e0_wp
-         !
-         ! jncsr can be zero so add 1 to avoid allocating zero-length array
-         ALLOCATE( surfr(jncsr+1) , STAT=ierr )
-         IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'sbc_clo: failed to allocate surfr array')
-         surfr(:) = 0.e0_wp
-         !
-         ! jncse can be zero so add 1 to avoid allocating zero-length array
-         ALLOCATE( surfe(jncse+1) , STAT=ierr )
-         IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'sbc_clo: failed to allocate surfe array')
-         surfe(:) = 0.e0_wp
-         !
-         surf(jncs+1) = glob_sum( 'closea', e1e2t(:,:) )   ! surface of the global ocean
-         !
-         !                                        ! surface areas of closed seas 
-         DO jc = 1, jncs
-            ztmp2d(:,:) = 0.e0_wp
-            WHERE( closea_mask(:,:) == jc ) ztmp2d(:,:) = e1e2t(:,:) * tmask_i(:,:)
-            surf(jc) = glob_sum( 'closea', ztmp2d(:,:) )
-         END DO
-         !
-         ! jncs+1 : surface area of global ocean, closed seas excluded
-         surf(jncs+1) = surf(jncs+1) - SUM(surf(1:jncs))
-         !
-         !                                        ! surface areas of rnf target areas
-         IF( jncsr > 0 ) THEN
-            DO jcr = 1, jncsr
-               ztmp2d(:,:) = 0.e0_wp
-               WHERE( closea_mask_rnf(:,:) == jcr .and. closea_mask(:,:) == 0 ) ztmp2d(:,:) = e1e2t(:,:) * tmask_i(:,:)
-               surfr(jcr) = glob_sum( 'closea', ztmp2d(:,:) )
-            END DO
-         ENDIF
-         !
-         !                                        ! surface areas of empmr target areas
-         IF( jncse > 0 ) THEN
-            DO jce = 1, jncse
-               ztmp2d(:,:) = 0.e0_wp
-               WHERE( closea_mask_empmr(:,:) == jce .and. closea_mask(:,:) == 0 ) ztmp2d(:,:) = e1e2t(:,:) * tmask_i(:,:)
-               surfe(jce) = glob_sum( 'closea', ztmp2d(:,:) )
-            END DO
-         ENDIF
-         !
-         IF(lwp) WRITE(numout,*)'     Closed sea surface areas (km2)'
-         DO jc = 1, jncs
-            IF(lwp) WRITE(numout,FMT='(1I3,5X,ES12.2)') jc, surf(jc) * 1.0e-6
-         END DO
-         IF(lwp) WRITE(numout,FMT='(A,ES12.2)') 'Global surface area excluding closed seas (km2): ', surf(jncs+1) * 1.0e-6
-         !
-         IF(jncsr > 0) THEN
-            IF(lwp) WRITE(numout,*)'     Closed sea target rnf surface areas (km2)'
-            DO jcr = 1, jncsr
-               IF(lwp) WRITE(numout,FMT='(1I3,5X,ES12.2)') jcr, surfr(jcr) * 1.0e-6
-            END DO
-         ENDIF
-         !
-         IF(jncse > 0) THEN
-            IF(lwp) WRITE(numout,*)'     Closed sea target empmr surface areas (km2)'
-            DO jce = 1, jncse
-               IF(lwp) WRITE(numout,FMT='(1I3,5X,ES12.2)') jce, surfe(jce) * 1.0e-6
-            END DO
-         ENDIF
-      ENDIF
-      !
-      !                                                      !--------------------!
-      !                                                      !  update emp        !
-      !                                                      !--------------------!
-
-      zfwf_total = 0._wp
-
-      !
-      ! 1. Work out total freshwater fluxes over closed seas from EMP - RNF.
-      !
-      zfwf(:) = 0.e0_wp           
-      DO jc = 1, jncs
-         ztmp2d(:,:) = 0.e0_wp
-         WHERE( closea_mask(:,:) == jc ) ztmp2d(:,:) = e1e2t(:,:) * ( emp(:,:)-rnf(:,:) ) * tmask_i(:,:)
-         zfwf(jc) = glob_sum( 'closea', ztmp2d(:,:) )
-      END DO
-      zfwf_total = SUM(zfwf)
-
-      zfwfr(:) = 0.e0_wp           
-      IF( jncsr > 0 ) THEN
-         !
-         ! 2. Work out total FW fluxes over rnf source areas and add to rnf target areas. 
-         !    Where zfwf is negative add flux at specified runoff points and subtract from fluxes for global redistribution.
-         !    Where positive leave in global redistribution total.
-         !
-         DO jcr = 1, jncsr
-            !
-            ztmp2d(:,:) = 0.e0_wp
-            WHERE( closea_mask_rnf(:,:) == jcr .and. closea_mask(:,:) > 0 ) ztmp2d(:,:) = e1e2t(:,:) * ( emp(:,:)-rnf(:,:) ) * tmask_i(:,:)
-            zfwfr(jcr) = glob_sum( 'closea', ztmp2d(:,:) )
-            !
-            ! The following if avoids the redistribution of the round off
-            IF ( ABS(zfwfr(jcr) / surf(jncs+1) ) > rsmall) THEN
-               !
-               ! Add residuals to target runoff points if negative and subtract from total to be added globally
-               IF( zfwfr(jcr) < 0.0 ) THEN 
-                  zfwf_total = zfwf_total - zfwfr(jcr)
-                  zcoef    = zfwfr(jcr) / surfr(jcr)
-                  zcoef1   = rcp * zcoef
-                  WHERE( closea_mask_rnf(:,:) == jcr .and. closea_mask(:,:) == 0.0)
-                     emp(:,:) = emp(:,:) + zcoef
-                     qns(:,:) = qns(:,:) - zcoef1 * sst_m(:,:)
-                  ENDWHERE
-               ENDIF
-               !
-            ENDIF
-         END DO
-      ENDIF  ! jncsr > 0    
-      !
-      zfwfe(:) = 0.e0_wp           
-      IF( jncse > 0 ) THEN
-         !
-         ! 3. Work out total fluxes over empmr source areas and add to empmr target areas. 
-         !
-         DO jce = 1, jncse
-            !
-            ztmp2d(:,:) = 0.e0_wp
-            WHERE( closea_mask_empmr(:,:) == jce .and. closea_mask(:,:) > 0 ) ztmp2d(:,:) = e1e2t(:,:) * ( emp(:,:)-rnf(:,:) ) * tmask_i(:,:)
-            zfwfe(jce) = glob_sum( 'closea', ztmp2d(:,:) )
-            !
-            ! The following if avoids the redistribution of the round off
-            IF ( ABS( zfwfe(jce) / surf(jncs+1) ) > rsmall ) THEN
-               !
-               ! Add residuals to runoff points and subtract from total to be added globally
-               zfwf_total = zfwf_total - zfwfe(jce)
-               zcoef    = zfwfe(jce) / surfe(jce)
-               zcoef1   = rcp * zcoef
-               WHERE( closea_mask_empmr(:,:) == jce .and. closea_mask(:,:) == 0.0)
-                  emp(:,:) = emp(:,:) + zcoef
-                  qns(:,:) = qns(:,:) - zcoef1 * sst_m(:,:)
-               ENDWHERE
-               !
-            ENDIF
-         END DO
-      ENDIF ! jncse > 0    
-
-      !
-      ! 4. Spread residual flux over global ocean. 
-      !
-      ! The following if avoids the redistribution of the round off
-      IF ( ABS(zfwf_total / surf(jncs+1) ) > rsmall) THEN
-         zcoef    = zfwf_total / surf(jncs+1)
+      ! update emp and qns
+      CALL sbc_csupdate( jncsg, jcsgrpg, mask_csglo, mask_csgrpglo, rsurfsrcg, rsurftrgg, 'glo', mask_opnsea, rsurftrgg )
+      CALL sbc_csupdate( jncsr, jcsgrpr, mask_csrnf, mask_csgrprnf, rsurfsrcr, rsurftrgr, 'rnf', mask_opnsea, rsurftrgg )
+      CALL sbc_csupdate( jncse, jcsgrpe, mask_csemp, mask_csgrpemp, rsurfsrce, rsurftrge, 'emp', mask_opnsea, rsurftrgg )
+      !
+      ! is this really useful ??????
+      emp(:,:) = emp(:,:) * tmask(:,:,1)
+      qns(:,:) = qns(:,:) * tmask(:,:,1)
+      !
+      ! is this really useful ??????
+      CALL lbc_lnk( 'closea', emp , 'T', 1._wp )
+      CALL lbc_lnk( 'closea', qns , 'T', 1._wp )
+      !
+   END SUBROUTINE sbc_clo
+   
+   SUBROUTINE sbc_csupdate(kncs, kcsgrp, pmsk_src, pmsk_trg, psurfsrc, psurftrg, pcstype, pmsk_opnsea, psurf_opnsea)
+
+      ! subroutine parameters
+      INTEGER, INTENT(in   ) :: kncs
+      INTEGER, DIMENSION(:  ), INTENT(in   ) :: kcsgrp
+      INTEGER, DIMENSION(:,:), INTENT(in   ) :: pmsk_src, pmsk_trg, pmsk_opnsea
+      
+      REAL(wp), DIMENSION(:), INTENT(inout) :: psurfsrc, psurftrg, psurf_opnsea
+
+      CHARACTER(256), INTENT(in   ) :: pcstype
+
+      ! local variables
+      INTEGER :: jcs
+      INTEGER, DIMENSION(jpi,jpj) :: zmsk_src, zmsk_trg
+      
+      REAL(wp) :: zcoef, zcoef1, ztmp
+      REAL(wp) :: zcsfwf
+      REAL(wp) :: zsurftrg
+     
+      DO jcs = 1, kncs
+         !!
+         !! 0. get mask of each closed sea
+         zmsk_src(:,:) = 0
+         WHERE ( pmsk_src(:,:) == jcs ) zmsk_src = 1
+         !!
+         !! 1. Work out net freshwater fluxes over each closed seas from EMP - RNF.
+         zcsfwf = glob_sum( 'closea', e1e2t(:,:) * ( emp(:,:)-rnf(:,:) ) * zmsk_src )
+         !!
+         !! 2. Deal with runoff special case (net evaporation spread globally)
+         IF (pcstype == 'rnf' .AND. zcsfwf > 0) THEN
+            zsurftrg = psurf_opnsea(1)
+            zmsk_trg = pmsk_opnsea
+         ELSE
+            zsurftrg = psurftrg(jcs)
+            zmsk_trg = pmsk_trg
+         END IF
+         zmsk_trg = zmsk_trg * pmsk_opnsea
+         !!
+         !! 3. Add residuals to target points
+         zcoef    = zcsfwf / zsurftrg
          zcoef1   = rcp * zcoef
-         WHERE( closea_mask(:,:) == 0 )
+         WHERE( zmsk_trg(:,:) == kcsgrp(jcs) )
             emp(:,:) = emp(:,:) + zcoef
             qns(:,:) = qns(:,:) - zcoef1 * sst_m(:,:)
          ENDWHERE
-      ENDIF
-
-      !
-      ! 5. Subtract area means from emp (and qns) over closed seas to give zero mean FW flux over each sea.
-      !
-      DO jc = 1, jncs
-         ! The following if avoids the redistribution of the round off
-         IF ( ABS(zfwf(jc) / surf(jncs+1) ) > rsmall) THEN
-            !
-            ! Subtract residuals from fluxes over closed sea
-            zcoef    = zfwf(jc) / surf(jc)
-            zcoef1   = rcp * zcoef
-            WHERE( closea_mask(:,:) == jc )
-               emp(:,:) = emp(:,:) - zcoef
-               qns(:,:) = qns(:,:) + zcoef1 * sst_m(:,:)
-            ENDWHERE
-            !
-         ENDIF
-      END DO
-      !
-      emp (:,:) = emp (:,:) * tmask(:,:,1)
-      !
-      CALL lbc_lnk( 'closea', emp , 'T', 1._wp )
-      !
-   END SUBROUTINE sbc_clo
+         !!
+         !! 4. Subtract residuals from source points
+         zcoef    = zcsfwf / psurfsrc(jcs)
+         zcoef1   = rcp * zcoef
+         WHERE( pmsk_src(:,:) == jcs )
+            emp(:,:) = emp(:,:) - zcoef
+            qns(:,:) = qns(:,:) + zcoef1 * sst_m(:,:)
+         ENDWHERE
+         !!
+      END DO ! jcs
+
+   END SUBROUTINE
+
 
    SUBROUTINE clo_rnf( p_rnfmsk )
       !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE sbc_rnf  ***
+      !!                  ***  ROUTINE clo_rnf  ***
       !!                    
       !! ** Purpose :   allow the treatment of closed sea outflow grid-points
@@ -412,23 +404,21 @@
       !! ** Action  :   update (p_)mskrnf (set 1 at closed sea outflow)
       !!----------------------------------------------------------------------
+      !!
+      !! subroutine parameter
       REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   p_rnfmsk   ! river runoff mask (rnfmsk array)
-      !!----------------------------------------------------------------------
-      !
-      IF( jncsr > 0 ) THEN
-         WHERE( closea_mask_rnf(:,:) > 0 .and. closea_mask(:,:) == 0 )
-            p_rnfmsk(:,:) = MAX( p_rnfmsk(:,:), 1.0_wp )
-         ENDWHERE
-      ENDIF
-      !
-      IF( jncse > 0 ) THEN
-         WHERE( closea_mask_empmr(:,:) > 0 .and. closea_mask(:,:) == 0 )
-            p_rnfmsk(:,:) = MAX( p_rnfmsk(:,:), 1.0_wp )
-         ENDWHERE
-      ENDIF
+      !!
+      !! local variables
+      REAL(wp), DIMENSION(jpi,jpj) :: zmsk
+      !!----------------------------------------------------------------------
+      !
+      ! zmsk > 0 where cs river mouth defined (case rnf and emp)
+      zmsk(:,:) = ( mask_csgrprnf (:,:) + mask_csgrpemp(:,:) ) * mask_opnsea(:,:)
+      WHERE( zmsk(:,:) > 0 )
+         p_rnfmsk(:,:) = 1.0_wp
+      END WHERE
       !
    END SUBROUTINE clo_rnf
-   
       
-   SUBROUTINE clo_bat( k_top, k_bot )
+   SUBROUTINE clo_bat( k_top, k_bot, p_mask, p_prt )
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE clo_bat  ***
@@ -443,44 +433,88 @@
       !! ** Action  :   set k_top=0 and k_bot=0 over closed seas
       !!----------------------------------------------------------------------
+      !!
+      !! subroutine parameter
       INTEGER, DIMENSION(:,:), INTENT(inout) ::   k_top, k_bot   ! ocean first and last level indices
-      INTEGER                           :: inum, id
-      INTEGER,  DIMENSION(jpi,jpj) :: closea_mask ! closea_mask field
-      REAL(wp), DIMENSION(jpi,jpj) :: zdata_in ! temporary real array for input
-      !!----------------------------------------------------------------------
-      !
-      IF(lwp) THEN                     ! Control print
+      INTEGER, DIMENSION(:,:), INTENT(in   ) ::   p_mask         ! mask used to mask ktop and k_bot
+      CHARACTER(256),          INTENT(in   ) ::   p_prt          ! text for control print
+      !!
+      !! local variables
+      !!----------------------------------------------------------------------
+      !!
+      IF ( lwp ) THEN
          WRITE(numout,*)
-         WRITE(numout,*) 'clo_bat : suppression of closed seas'
+         WRITE(numout,*) 'clo_bat : Suppression closed seas based on ',TRIM(p_prt),' field.'
          WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*)
       ENDIF
-      !
-      IF( ln_read_cfg ) THEN
-         !
-         CALL iom_open( cn_domcfg, inum )
-         !
-         id = iom_varid(inum, 'closea_mask', ldstop = .false.)      
-         IF( id > 0 ) THEN
-            IF( lwp ) WRITE(numout,*) 'Suppressing closed seas in bathymetry based on closea_mask field,'
-            CALL iom_get ( inum, jpdom_data, 'closea_mask', zdata_in )
-            closea_mask(:,:) = NINT(zdata_in(:,:))
-            WHERE( closea_mask(:,:) > 0 )
-               k_top(:,:) = 0   
-               k_bot(:,:) = 0   
-            ENDWHERE
-         ELSE
-            IF( lwp ) WRITE(numout,*) 'No closea_mask field found in domain_cfg file. No suppression of closed seas.'
-         ENDIF
-         !
-         CALL iom_close(inum)
-         !
-      ELSE
-         IF( lwp ) WRITE(numout,*) 'No domain_cfg file => no suppression of closed seas.'
-      ENDIF
-      !
-      ! Initialise l_sbc_clo and l_clo_rnf for this case (ln_closea=.false.)
-      l_sbc_clo = .false.
-      l_clo_rnf = .false.
-      !
+      !!
+      k_top(:,:) = k_top(:,:) * p_mask(:,:)
+      k_bot(:,:) = k_bot(:,:) * p_mask(:,:)
+      !!
    END SUBROUTINE clo_bat
+
+   SUBROUTINE read_csmask(p_file, p_var, p_mskout)
+      !
+      ! subroutine parameter
+      CHARACTER(256), INTENT(in   ) :: p_file, p_var
+      INTEGER, DIMENSION(:,:), INTENT(inout) :: p_mskout
+      !
+      ! local variables
+      INTEGER :: ics
+      REAL(wp), DIMENSION(jpi,jpj) :: zdta
+      !
+      CALL iom_open ( p_file, ics )
+      CALL iom_get  ( ics, jpdom_data, TRIM(p_var), zdta )
+      CALL iom_close( ics )
+      p_mskout(:,:) = NINT(zdta(:,:))
+      !
+   END SUBROUTINE read_csmask
+
+   SUBROUTINE alloc_csmask( pmask )
+      !
+      ! subroutine parameter
+      INTEGER, ALLOCATABLE, DIMENSION(:,:), INTENT(inout) :: pmask
+      !
+      ! local variables
+      INTEGER :: ierr
+      !
+      ALLOCATE( pmask(jpi,jpj) , STAT=ierr )
+      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'alloc_csmask: failed to allocate surf array')
+      !
+   END SUBROUTINE
+
+
+   SUBROUTINE alloc_cssurf( klen, pvarsrc, pvartrg )
+      !
+      ! subroutine parameter
+      INTEGER, INTENT(in) :: klen
+      REAL(wp), ALLOCATABLE, DIMENSION(:), INTENT(inout) :: pvarsrc, pvartrg 
+      !
+      ! local variables
+      INTEGER :: ierr
+      !
+      ! klen (number of lake) can be zero so use MAX(klen,1) to avoid 0 length array
+      ALLOCATE( pvarsrc(MAX(klen,1)) , pvartrg(MAX(klen,1)) , STAT=ierr )
+      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'sbc_clo: failed to allocate surf array')
+      ! initialise to 0
+      pvarsrc(:) = 0.e0_wp
+      pvartrg(:) = 0.e0_wp
+   END SUBROUTINE
+
+   SUBROUTINE alloc_csgrp( klen, kvar )
+      !
+      ! subroutine parameter
+      INTEGER, INTENT(in) :: klen
+      INTEGER, ALLOCATABLE, DIMENSION(:), INTENT(inout) :: kvar 
+      !
+      ! local variables
+      INTEGER :: ierr
+      !
+      ! klen (number of lake) can be zero so use MAX(klen,1) to avoid 0 length array
+      ALLOCATE( kvar(MAX(klen,1)) , STAT=ierr )
+      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'sbc_clo: failed to allocate group array')
+      ! initialise to 0
+      kvar(:) = 0
+   END SUBROUTINE
 
    !!======================================================================
Index: NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/domain.F90
===================================================================
--- NEMO/trunk/src/OCE/DOM/domain.F90	(revision 11190)
+++ NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/domain.F90	(revision 11207)
@@ -134,11 +134,13 @@
       ENDIF
       !
-      CALL dom_hgr                     ! Horizontal mesh
-      CALL dom_zgr( ik_top, ik_bot )   ! Vertical mesh and bathymetry
-      CALL dom_msk( ik_top, ik_bot )   ! Masks
-      IF( ln_closea )   CALL dom_clo   ! ln_closea=T : closed seas included in the simulation
-                                       ! Read in masks to define closed seas and lakes 
-      !
-      DO jj = 1, jpj                   ! depth of the iceshelves
+      CALL dom_hgr                      ! Horizontal mesh
+
+      IF( ln_closea ) CALL dom_clo      ! Read in masks to define closed seas and lakes
+
+      CALL dom_zgr( ik_top, ik_bot )    ! Vertical mesh and bathymetry
+
+      CALL dom_msk( ik_top, ik_bot )    ! Masks
+      !
+      DO jj = 1, jpj                    ! depth of the iceshelves
          DO ji = 1, jpi
             ik = mikt(ji,jj)
Index: NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/domzgr.F90
===================================================================
--- NEMO/trunk/src/OCE/DOM/domzgr.F90	(revision 11190)
+++ NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/domzgr.F90	(revision 11207)
@@ -118,5 +118,14 @@
       ! Any closed seas (defined by closea_mask > 0 in domain_cfg file) to be filled 
       ! in at runtime if ln_closea=.false.
-      IF( .NOT.ln_closea )   CALL clo_bat( k_top, k_bot )
+      IF( ln_closea ) THEN
+         IF ( ln_maskcs ) THEN
+            ! mask all the closed sea
+            CALL clo_bat( k_top, k_bot, mask_opnsea, 'mask_opensea' )
+         ELSE IF ( ln_mask_csundef ) THEN
+            ! defined closed sea are kept
+            ! mask all the undefined closed sea
+            CALL clo_bat( k_top, k_bot, mask_csundef, 'mask_csundef' )
+         END IF
+      END IF
       !
       IF(lwp) THEN                     ! Control print
Index: NEMO/branches/2019/ENHANCE-03_closea/src/OCE/SBC/sbcmod.F90
===================================================================
--- NEMO/trunk/src/OCE/SBC/sbcmod.F90	(revision 11190)
+++ NEMO/branches/2019/ENHANCE-03_closea/src/OCE/SBC/sbcmod.F90	(revision 11207)
@@ -24,4 +24,5 @@
    USE oce            ! ocean dynamics and tracers
    USE dom_oce        ! ocean space and time domain
+   USE closea         ! closed seas
    USE phycst         ! physical constants
    USE sbc_oce        ! Surface boundary condition: ocean fields
@@ -323,4 +324,6 @@
       !                       !**  associated modules : initialization
       !
+      IF( l_sbc_clo   )   CALL sbc_clo_init            ! closed sea surface initialisation
+      !
                           CALL sbc_ssm_init            ! Sea-surface mean fields initialization
       !
@@ -461,5 +464,5 @@
       ! Special treatment of freshwater fluxes over closed seas in the model domain
       ! Should not be run if ln_diurnal_only
-      IF( l_sbc_clo .AND. (.NOT. ln_diurnal_only) )   CALL sbc_clo( kt )   
+      IF( l_sbc_clo      )   CALL sbc_clo( kt )   
 
 !!$!RBbug do not understand why see ticket 667
Index: NEMO/branches/2019/ENHANCE-03_closea/src/OCE/par_oce.F90
===================================================================
--- NEMO/trunk/src/OCE/par_oce.F90	(revision 11190)
+++ NEMO/branches/2019/ENHANCE-03_closea/src/OCE/par_oce.F90	(revision 11207)
@@ -27,4 +27,5 @@
    !                                   !  with the extended grids used in the under ice shelf configurations to 
    !                                   !  be used without redundant rows when the ice shelves are not in use.
+   LOGICAL       ::   ln_closea        !: (=T) special treatment of closed sea
    ! 
 
