Index: NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/closea.F90
===================================================================
--- NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/closea.F90	(revision 11295)
+++ NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/closea.F90	(revision 11629)
@@ -16,7 +16,6 @@
    !!----------------------------------------------------------------------
    !!   dom_clo    : read in masks which define closed seas and runoff areas
-   !!   sbc_clo    : Special handling of freshwater fluxes over closed seas
    !!   clo_rnf    : set close sea outflows as river mouths (see sbcrnf)
-   !!   clo_bat    : set to zero a field over closed sea (see domzgr)
+   !!   clo_msk    : set to zero a field over closed sea (see domzgr)
    !!----------------------------------------------------------------------
    USE oce             ! dynamics and tracers
@@ -38,5 +37,5 @@
    PUBLIC dom_clo      ! called by domain module
    PUBLIC clo_rnf      ! called by sbcrnf module
-   PUBLIC clo_bat      ! called in domzgr module
+   PUBLIC clo_msk      ! called in domzgr module
 
    LOGICAL, PUBLIC :: ln_maskcs        !: logical to mask all closed sea
@@ -77,5 +76,6 @@
       !! ** 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.
+      !!
+      !! ** Output  :   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.
@@ -107,8 +107,4 @@
       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)
       ! ------------------------------------------------------------------------------
@@ -119,8 +115,10 @@
       !
       IF ( ln_maskcs ) THEN
-         ! not special treatment of closed sea
+         ! closed sea are masked
+         ! no special treatment of closed sea
+         ! no redistribution of emp unbalance over closed sea into river mouth/open ocean
          l_sbc_clo = .false. ; l_clo_rnf = .false.
       ELSE
-         ! special treatment of closed seas
+         ! redistribution of emp unbalance over closed sea into river mouth/open ocean
          l_sbc_clo = .true.
          !
@@ -128,13 +126,14 @@
          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
-            ! 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
+            ! 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
          END IF
          !
-         ! allocate source mask
+         ! allocate source mask for each cases
          CALL alloc_csmask( mask_csglo )
          CALL alloc_csmask( mask_csrnf )
@@ -151,5 +150,6 @@
          ncse = MAXVAL( mask_csemp(:,:) ) ; CALL mpp_max( 'closea', ncse )
          !
-         ! allocate closed sea group masks
+         ! allocate closed sea group masks 
+         !(used to defined the target area in case multiple lakes have the same river mouth (great lakes for example)
          CALL alloc_csmask( mask_csgrpglo )
          CALL alloc_csmask( mask_csgrprnf )
@@ -176,5 +176,4 @@
       !! ** 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)
@@ -192,12 +191,11 @@
    END SUBROUTINE clo_rnf
       
-   SUBROUTINE clo_bat( k_top, k_bot, k_mask, cd_prt )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE clo_bat  ***
+   SUBROUTINE clo_msk( k_top, k_bot, k_mask, cd_prt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE clo_msk  ***
       !!                    
       !! ** Purpose :   Suppress closed sea from the domain
       !!
-      !! ** Method  :   Read in closea_mask field (if it exists) from domain_cfg file.
-      !!                Where closea_mask > 0 set first and last ocean level to 0
+      !! ** Method  :   Where closea_mask > 0 set first and last ocean level to 0
       !!                (As currently coded you can't define a closea_mask field in 
       !!                usr_def_zgr).
@@ -205,5 +203,4 @@
       !! ** 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
@@ -216,5 +213,5 @@
       IF ( lwp ) THEN
          WRITE(numout,*)
-         WRITE(numout,*) 'clo_bat : Suppression closed seas based on ',TRIM(cd_prt),' field.'
+         WRITE(numout,*) 'clo_msk : Suppression closed seas based on ',TRIM(cd_prt),' field.'
          WRITE(numout,*) '~~~~~~~'
          WRITE(numout,*)
@@ -224,15 +221,20 @@
       k_bot(:,:) = k_bot(:,:) * k_mask(:,:)
       !!
-   END SUBROUTINE clo_bat
+   END SUBROUTINE clo_msk
 
    SUBROUTINE read_csmask(cd_file, cd_var, k_mskout)
-      !
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE read_csmask  ***
+      !!                    
+      !! ** Purpose : read mask in cd_filec file
+      !!----------------------------------------------------------------------
       ! subroutine parameter
-      CHARACTER(256), INTENT(in   ) :: cd_file, cd_var     ! netcdf file and variable name
-      INTEGER, DIMENSION(:,:), INTENT(inout) :: k_mskout ! output mask variable
+      CHARACTER(256),          INTENT(in   ) :: cd_file, cd_var     ! netcdf file and variable name
+      INTEGER, DIMENSION(:,:), INTENT(  out) :: k_mskout            ! output mask variable
       !
       ! local variables
       INTEGER :: ics                       ! netcdf id
       REAL(wp), DIMENSION(jpi,jpj) :: zdta ! netcdf data
+      !!----------------------------------------------------------------------
       !
       CALL iom_open ( cd_file, ics )
@@ -244,5 +246,9 @@
 
    SUBROUTINE alloc_csmask( kmask )
-      !
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE alloc_csmask  ***
+      !!                    
+      !! ** Purpose : allocated cs mask
+      !!----------------------------------------------------------------------
       ! subroutine parameter
       INTEGER, ALLOCATABLE, DIMENSION(:,:), INTENT(inout) :: kmask
@@ -250,4 +256,5 @@
       ! local variables
       INTEGER :: ierr
+      !!----------------------------------------------------------------------
       !
       ALLOCATE( kmask(jpi,jpj) , STAT=ierr )
Index: NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/domzgr.F90
===================================================================
--- NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/domzgr.F90	(revision 11295)
+++ NEMO/branches/2019/ENHANCE-03_closea/src/OCE/DOM/domzgr.F90	(revision 11629)
@@ -121,9 +121,9 @@
          IF ( ln_maskcs ) THEN
             ! mask all the closed sea
-            CALL clo_bat( k_top, k_bot, mask_opnsea, 'mask_opensea' )
+            CALL clo_msk( 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' )
+            CALL clo_msk( k_top, k_bot, mask_csundef, 'mask_csundef' )
          END IF
       END IF
Index: NEMO/branches/2019/ENHANCE-03_closea/src/OCE/SBC/sbcclo.F90
===================================================================
--- NEMO/branches/2019/ENHANCE-03_closea/src/OCE/SBC/sbcclo.F90	(revision 11295)
+++ NEMO/branches/2019/ENHANCE-03_closea/src/OCE/SBC/sbcclo.F90	(revision 11629)
@@ -2,16 +2,18 @@
    !!======================================================================
    !!                       ***  MODULE  sbcclo  ***
-   !! Ocean forcing:  closea sea correction
+   !! Ocean forcing: redistribution of emp unbalance over closed sea into river mouth or open ocean
    !!=====================================================================
-   !! History :  4.1  ! 2019-09  (P. Mathiot) original
-   !!   NEMO 
-   !!----------------------------------------------------------------------
-   !
-   !!----------------------------------------------------------------------
+   !! History :  4.0 and earlier ! see closea.F90 history   
+   !!   NEMO     4.1  ! 2019-09  (P. Mathiot) rewrite sbc_clo module to match new closed sea mask definition (original sbcclo.F90)
+   !! 
+   !!----------------------------------------------------------------------
+   !
+   !!----------------------------------------------------------------------
+   !!   Public subroutines:
    !!   sbc_clo       : update emp and qns over target area and source area
    !!   sbc_clo_init  : initialise all variable needed for closed sea correction
    !!
-   !!   alloc_cssurf  : allocate closed sea surface array
-   !!   alloc_csgrp   : allocate closed sea group array
+   !!   Private subroutines:
+   !!   alloc_csarr   : allocate closed sea array
    !!   get_cssrcsurf : compute source surface area
    !!   get_cstrgsurf : compute target surface area
@@ -33,19 +35,14 @@
    IMPLICIT NONE
    !
-   PRIVATE alloc_cssurf
-   PRIVATE alloc_csgrp
-   PRIVATE get_cssrcsurf
-   PRIVATE get_cstrgsurf
-   PRIVATE prt_csctl
-   PRIVATE sbc_csupdate
+   PRIVATE
    !
    PUBLIC sbc_clo
    PUBLIC sbc_clo_init
    !
-   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 
-   !
-   INTEGER, PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:) :: mcsgrpg, mcsgrpr, mcsgrpe !: closed sea group for glo, rnf and emp
+   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:) :: rsurfsrcg, rsurftrgg      !: closed sea source/target glo surface areas 
+   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:) :: rsurfsrcr, rsurftrgr      !: closed sea source/target rnf surface areas 
+   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:) :: rsurfsrce, rsurftrge      !: closed sea source/target emp surface areas 
+   !
+   INTEGER, PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:)  :: mcsgrpg, mcsgrpr, mcsgrpe !: closed sea group for glo, rnf and emp
    !
    CONTAINS
@@ -59,16 +56,16 @@
       !!                  ***  ROUTINE sbc_clo_init  ***
       !!                    
-      !! ** Purpose :  Initialisation of the net fw closed sea correction
+      !! ** Purpose :  Initialisation of the variable needed for the net fw closed sea correction
       !!
       !! ** Method  :  - compute source surface area for each closed sea
       !!               - defined the group of each closed sea 
-      !!                    (needed to manage multiple closed sea and one target area like great lakes / St Laurent outlet)
-      !!               - compute target surface area and corresponding group for each closed sea
+      !!                 (needed to manage multiple closed sea and one target area like great lakes / St Laurent outlet)
+      !!               - compute target surface area
       !!----------------------------------------------------------------------
       !
       ! 0. Allocate cs variables (surf)
-      CALL alloc_cssurf( ncsg, rsurfsrcg, rsurftrgg ) 
-      CALL alloc_cssurf( ncsr, rsurfsrcr, rsurftrgr )
-      CALL alloc_cssurf( ncse, rsurfsrce, rsurftrge )
+      CALL alloc_csarr( ncsg, rsurfsrcg, rsurftrgg, mcsgrpg ) 
+      CALL alloc_csarr( ncsr, rsurfsrcr, rsurftrgr, mcsgrpr )
+      CALL alloc_csarr( ncse, rsurfsrce, rsurftrge, mcsgrpe )
       !
       ! 1. compute source surface area
@@ -77,10 +74,5 @@
       CALL get_cssrcsurf( ncse, mask_csemp, rsurfsrce )
       !
-      ! 2. Allocate cs group variables (mcsgrp)
-      CALL alloc_csgrp( ncsg, mcsgrpg )
-      CALL alloc_csgrp( ncsr, mcsgrpr )
-      CALL alloc_csgrp( ncse, mcsgrpe )
-      !
-      ! 3. compute target surface area and group number (mcsgrp) for all cs and cases 
+      ! 2. compute target surface area and group number (mcsgrp) 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
@@ -89,5 +81,7 @@
       CALL get_cstrgsurf( ncse, mask_csemp, mask_csgrpemp, rsurftrge, mcsgrpe )
       ! 
-      ! 4. print out in ocean.ouput
+      ! 3. print out in ocean.ouput
+      IF ( lwp ) WRITE(numout,*) 'sbc_clo_init : compute surface area for source (closed sea) and target (river mouth)'
+      IF ( lwp ) WRITE(numout,*) '~~~~~~~~~~~~~~'
       CALL prt_csctl( ncsg, rsurfsrcg, rsurftrgg, mcsgrpg, 'glo' )
       CALL prt_csctl( ncsr, rsurfsrcr, rsurftrgr, mcsgrpr, 'rnf' )
@@ -96,5 +90,5 @@
    END SUBROUTINE sbc_clo_init
 
-   SUBROUTINE sbc_clo( kt ) ! to be move in SBC in a file sbcclo ???
+   SUBROUTINE sbc_clo( kt )
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE sbc_clo  ***
@@ -144,8 +138,7 @@
       !!----------------------------------------------------------------------
       ! subroutine parameters
-      INTEGER,                 INTENT(in   ) :: kncs           ! closed sea number
-      INTEGER, DIMENSION(:,:), INTENT(in   ) :: kmaskcs        ! closed sea mask
-
-      REAL(wp), DIMENSION(:)  , INTENT(inout) :: psurfsrc      ! source surface area
+      INTEGER ,                 INTENT(in   ) :: kncs          ! closed sea number
+      INTEGER , DIMENSION(:,:), INTENT(in   ) :: kmaskcs       ! closed sea mask
+      REAL(wp), DIMENSION(:)  , INTENT(  out) :: psurfsrc      ! source surface area
 
       ! local variables
@@ -177,13 +170,15 @@
       !!----------------------------------------------------------------------
       ! subroutine parameters
+      ! input
       INTEGER,                 INTENT(in   ) :: kncs                 ! closed sea number
-      INTEGER, DIMENSION(:)  , INTENT(inout) :: kcsgrp               ! closed sea group number
       INTEGER, DIMENSION(:,:), INTENT(in   ) :: kmaskcs, kmaskcsgrp  ! closed sea and group mask
 
-      REAL(wp), DIMENSION(:)  , INTENT(inout) :: psurftrg            ! target surface area
+      ! output
+      INTEGER , DIMENSION(:)  , INTENT(  out) :: kcsgrp              ! closed sea group number
+      REAL(wp), DIMENSION(:)  , INTENT(  out) :: psurftrg            ! target surface area
 
       ! local variables
       INTEGER :: jcs, jtmp                                           ! tmp
-      INTEGER, DIMENSION(jpi,jpj) :: imskgrp, imsksrc, imsktrg       ! tmp group, source and target mask
+      INTEGER, DIMENSION(jpi,jpj) :: imskgrp, imsksrc, imsktrg, imsk ! tmp group, source, target and tmp mask
       !!----------------------------------------------------------------------
       !
@@ -194,16 +189,17 @@
          imsksrc = kmaskcs
          !
-         ! set cs value where cs is
-         imsktrg = HUGE(1)
-         WHERE ( imsksrc == jcs ) imsktrg = jcs
-         !
-         ! zmsk = HUGE outside the cs number jcs
-         ! ktmp = jcs - group number
-         ! jgrp = group corresponding to the cs jcs
-         imsktrg = imsktrg - imskgrp
-         jtmp = MINVAL(imsktrg) ; CALL mpp_min('closea',jtmp)
+         ! set cs value where cs is defined
+         ! imsk = HUGE outside the cs id jcs
+         imsk = HUGE(1)
+         WHERE ( imsksrc == jcs ) imsk = jcs
+         !
+         ! jtmp = jcs - group id for this lake
+         imsk = imsk - imskgrp
+         jtmp = MINVAL(imsk) ; CALL mpp_min('closea',jtmp)
+         ! kcsgrp = group id corresponding to the cs id jcs
+         ! kcsgrp(jcs)=(jcs - (jcs - group id))=group id
          kcsgrp(jcs) = jcs - jtmp
          !
-         !! 1. build river mouth mask for this lake
+         !! 1. build the target river mouth mask for this lake
          WHERE ( imskgrp * mask_opnsea == kcsgrp(jcs) )
             imsktrg = 1
@@ -243,5 +239,5 @@
          !
          DO jcs = 1,kncs
-            WRITE(numout,FMT='(3a,i3,a,i3)') ' ',TRIM(cdcstype),' closed sea id is ',jcs,' and trg id is : ', kcsgrp(jcs)
+            WRITE(numout,FMT='(3a,i3,a,i3)') ' ',TRIM(cdcstype),' closed sea id is ',jcs,' and trg group 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
@@ -253,5 +249,5 @@
    END SUBROUTINE
 
-   SUBROUTINE sbc_csupdate(kncs, kcsgrp, kmsk_src, kmsk_trg, psurfsrc, psurftrg, cdcstype, kmsk_opnsea, psurf_opnsea, pwcs, pqcs)
+   SUBROUTINE sbc_csupdate(kncs, kcsgrp, kmsk_src, kmsk_grp, psurfsrc, psurftrg, cdcstype, kmsk_opnsea, psurf_opnsea, pwcs, pqcs)
       !!-----------------------------------------------------------------------
       !!                  ***  routine sbc_csupdate  ***
@@ -261,7 +257,7 @@
       !!----------------------------------------------------------------------
       ! subroutine parameters
-      INTEGER,                 INTENT(in) :: kncs                              ! closed sea number
-      INTEGER, DIMENSION(:  ), INTENT(in) :: kcsgrp                            ! closed sea group number
-      INTEGER, DIMENSION(:,:), INTENT(in) :: kmsk_src, kmsk_trg, kmsk_opnsea   ! source, target, open ocean mask
+      INTEGER,                 INTENT(in) :: kncs                                 ! closed sea id
+      INTEGER, DIMENSION(:  ), INTENT(in) :: kcsgrp                               ! closed sea group id
+      INTEGER, DIMENSION(:,:), INTENT(in) :: kmsk_src, kmsk_grp, kmsk_opnsea      ! source, target, open ocean mask
       
       REAL(wp), DIMENSION(:)  , INTENT(in   ) :: psurfsrc, psurftrg, psurf_opnsea ! source, target and open ocean surface area
@@ -271,5 +267,5 @@
 
       ! local variables
-      INTEGER :: jcs  ! loop index over closed sea 
+      INTEGER :: jcs                                     ! loop index over closed sea 
       INTEGER, DIMENSION(jpi,jpj) :: imsk_src, imsk_trg  ! tmp array source and target closed sea masks
       
@@ -281,24 +277,25 @@
       DO jcs = 1, kncs  ! loop over closed seas
          !
-         !! 0. get mask of each closed sea
+         !! 0. get mask of the closed sea
          imsk_src(:,:) = 0
          WHERE ( kmsk_src(:,:) == jcs ) imsk_src(:,:) = 1
          !
-         !! 1. Work out net freshwater fluxes over each closed seas from EMP - RNF.
+         !! 1. Work out net freshwater fluxes over the closed sea from EMP - RNF.
+         !!    (PM: should we consider used delayed glob sum ?)
          zcsfwf = 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
-            zsurftrg = psurf_opnsea(1)
-            imsk_trg = kmsk_opnsea * kcsgrp(jcs) ! set imsk_trg value to the corresponding group id
+            zsurftrg = psurf_opnsea(1)           ! change the target area surface
+            imsk_trg = kcsgrp(jcs) * kmsk_opnsea ! trg mask is now the open sea mask
          ELSE
             zsurftrg = psurftrg(jcs)
-            imsk_trg = kmsk_trg
+            imsk_trg = kmsk_grp * kmsk_opnsea
          END IF
-         imsk_trg = imsk_trg * kmsk_opnsea
          !
          !! 3. Add residuals to target points
-         zcoef    = zcsfwf / zsurftrg
-         zcoef1   = rcp * zcoef
+         zcoef  = zcsfwf / zsurftrg
+         zcoef1 = rcp * zcoef
          WHERE( imsk_trg(:,:) == kcsgrp(jcs) )
             pwcs(:,:) = pwcs(:,:) + zcoef
@@ -313,4 +310,7 @@
             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
@@ -318,13 +318,14 @@
    END SUBROUTINE
 
-   SUBROUTINE alloc_cssurf( klen, pvarsrc, pvartrg )
+   SUBROUTINE alloc_csarr( klen, pvarsrc, pvartrg, kvargrp )
       !!-----------------------------------------------------------------------
       !!                  ***  routine alloc_cssurf  ***
       !!
-      !! ** Purpose : allocate closed sea surface array (source)
-      !!----------------------------------------------------------------------
-      ! subroutine parameters
-      INTEGER, INTENT(in) :: klen
-      REAL(wp), ALLOCATABLE, DIMENSION(:), INTENT(inout) :: pvarsrc, pvartrg 
+      !! ** Purpose : allocate closed sea surface array
+      !!----------------------------------------------------------------------
+      ! subroutine parameters
+      INTEGER,  INTENT(in) :: klen
+      INTEGER,  ALLOCATABLE, DIMENSION(:), INTENT(  out) :: kvargrp
+      REAL(wp), ALLOCATABLE, DIMENSION(:), INTENT(  out) :: pvarsrc, pvartrg 
       !
       ! local variables
@@ -336,28 +337,11 @@
       IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'sbc_clo: failed to allocate surf array')
       !
+      ALLOCATE( kvargrp(MAX(klen,1)) , STAT=ierr )
+      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'sbc_clo: failed to allocate group array')
+      !
       ! initialise to 0
       pvarsrc(:) = 0.e0_wp
       pvartrg(:) = 0.e0_wp
-   END SUBROUTINE
-
-   SUBROUTINE alloc_csgrp( klen, kvar )
-      !!-----------------------------------------------------------------------
-      !!                  ***  routine alloc_csgrp  ***
-      !!
-      !! ** Purpose : allocate closed sea group surface array
-      !!----------------------------------------------------------------------
-      ! subroutine parameters
-      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
+      kvargrp(:) = 0
    END SUBROUTINE
 
