Index: /NEMO/branches/2020/tickets_icb_1900/src/OCE/ICB/icbdyn.F90
===================================================================
--- /NEMO/branches/2020/tickets_icb_1900/src/OCE/ICB/icbdyn.F90	(revision 13358)
+++ /NEMO/branches/2020/tickets_icb_1900/src/OCE/ICB/icbdyn.F90	(revision 13359)
@@ -332,12 +332,6 @@
          
          ! compute mean velocity 
-         zuo = 0.0 ; zvo = 0.0; zdep = 0.0
-         DO jk = 1, ikb-1
-            zuo = zuo + zuoce(jk) * ze3t(jk)
-            zvo = zvo + zvoce(jk) * ze3t(jk)
-            zdep = zdep + ze3t(jk)
-         END DO
-         zuo = (zuo + zuoce(ikb) * (zD - zdep)) / zD
-         zvo = (zvo + zvoce(ikb) * (zD - zdep)) / zD
+         CALL icb_utl_zavg(zuo, zuoce, ze3t, zD, ikb)
+         CALL icb_utl_zavg(zvo, zvoce, ze3t, zD, ikb)
       ELSE
          zuo = zssu
Index: /NEMO/branches/2020/tickets_icb_1900/src/OCE/ICB/icbstp.F90
===================================================================
--- /NEMO/branches/2020/tickets_icb_1900/src/OCE/ICB/icbstp.F90	(revision 13358)
+++ /NEMO/branches/2020/tickets_icb_1900/src/OCE/ICB/icbstp.F90	(revision 13359)
@@ -71,4 +71,7 @@
       !
       nktberg = kt
+      !
+      !CALL test_icb_utl_getkb
+      !CALL ctl_stop('end test icb')
       !
       IF( nn_test_icebergs < 0 .OR. ln_use_calving ) THEN !* read calving data
Index: /NEMO/branches/2020/tickets_icb_1900/src/OCE/ICB/icbthm.F90
===================================================================
--- /NEMO/branches/2020/tickets_icb_1900/src/OCE/ICB/icbthm.F90	(revision 13358)
+++ /NEMO/branches/2020/tickets_icb_1900/src/OCE/ICB/icbthm.F90	(revision 13359)
@@ -54,5 +54,5 @@
       REAL(wp) ::   zMbits, znMbits, zdMbitsE, zdMbitsM, zLbits, zAbits, zMbb
       REAL(wp) ::   zxi, zyj, zff, z1_rday, z1_e1e2, zdt, z1_dt, z1_dt_e1e2, zdepw
-      REAL(wp), DIMENSION(jpk) :: ztoce, zuoce, zvoce, ze3t, ztmp
+      REAL(wp), DIMENSION(jpk) :: ztoce, zuoce, zvoce, ze3t, zzMv
       TYPE(iceberg), POINTER ::   this, next
       TYPE(point)  , POINTER ::   pt
@@ -142,11 +142,6 @@
          IF ( ln_M2016 ) THEN
             ! Buoyant convection at sides (eqn M.A10) but averaging along all the iceberg draft
-            ztmp(:) = MAX( 7.62d-3*ztoce(:)+1.29d-3*(ztoce(:)**2), 0._wp ) * z1_rday
-            zMv = 0.0; zdepw = 0.0
-            DO jk = 1,ikb-1
-               zMv = zMv + ze3t(jk)*ztmp(jk)
-               zdepw = zdepw + ze3t(jk)
-            END DO
-            zMv = (zMv + (zD - zdepw)*ztmp(ikb)) / zD
+            zzMv(:) = MAX( 7.62d-3*ztoce(:)+1.29d-3*(ztoce(:)**2), 0._wp ) * z1_rday
+            CALL icb_utl_zavg(zMv, zzMv, ze3t, zD, ikb )
          ELSE
             zMv = MAX( 7.62d-3*zSST+1.29d-3*(zSST**2), 0._wp ) * z1_rday
@@ -262,4 +257,5 @@
 
 !!gm  add a test to avoid over melting ?
+!!pm  I agree, over melting could break conservation (more melt than calving)
 
          IF( zMnew <= 0._wp ) THEN       ! Delete the berg if completely melted
Index: /NEMO/branches/2020/tickets_icb_1900/src/OCE/ICB/icbutl.F90
===================================================================
--- /NEMO/branches/2020/tickets_icb_1900/src/OCE/ICB/icbutl.F90	(revision 13358)
+++ /NEMO/branches/2020/tickets_icb_1900/src/OCE/ICB/icbutl.F90	(revision 13359)
@@ -41,4 +41,6 @@
    PUBLIC   icb_utl_copy          ! routine called in icbstp module
    PUBLIC   icb_utl_getkb         ! routine called in icbdyn and icbthm modules
+   PUBLIC   test_icb_utl_getkb    ! routine called in icbdyn and icbthm modules
+   PUBLIC   icb_utl_zavg          ! routine called in icbdyn and icbthm modules
    PUBLIC   icb_utl_interp        ! routine called in icbdyn, icbthm modules
    PUBLIC   icb_utl_bilin_h       ! routine called in icbdyn module
@@ -482,5 +484,5 @@
       !!
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(out)               :: kb
+      INTEGER,                INTENT(out):: kb
       REAL(wp), DIMENSION(:), INTENT(in) :: pe3
       REAL(wp),               INTENT(in) :: pD
@@ -488,12 +490,37 @@
       INTEGER  :: jk
       REAL(wp) :: zdepw
-      !!
-      zdepw = 0.0
-      kb = 1
+      !!----------------------------------------------------------------------
+      !!
+      zdepw = pe3(1) ; kb = 2
       DO WHILE ( zdepw <  pD)
          zdepw = zdepw + pe3(kb)
          kb = kb + 1
       END DO
-      kb = kb - 1
+      kb = MIN(kb - 1,jpk)
+   END SUBROUTINE
+
+   SUBROUTINE icb_utl_zavg(pzavg, pdat, pe3, pD, kb )
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE icb_utl_getkb         ***
+      !!
+      !! ** Purpose :   compute the vertical average of ocean properties affected by icb
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER,                INTENT(in ) :: kb        ! deepest level affected by icb
+      REAL(wp), DIMENSION(:), INTENT(in ) :: pe3, pdat ! vertical profile
+      REAL(wp),               INTENT(in ) :: pD        ! draft
+      REAL(wp),               INTENT(out) :: pzavg     ! z average
+      !!----------------------------------------------------------------------
+      INTEGER  :: jk
+      REAL(wp) :: zdep
+      !!----------------------------------------------------------------------
+      pzavg = 0.0 ; zdep = 0.0
+      DO jk = 1,kb-1
+         pzavg = pzavg + pe3(jk)*pdat(jk)
+         zdep  = zdep  + pe3(jk)
+      END DO
+      ! if kb is limited by mbkt  => bottom value is used between bathy and icb tail
+      ! if kb not limited by mbkt => ocean value over mask is used (ie 0.0 for u, v)
+      pzavg = ( pzavg + (pD - zdep)*pdat(kb)) / pD
    END SUBROUTINE
 
@@ -855,4 +882,66 @@
    END FUNCTION icb_utl_heat
 
+   SUBROUTINE test_icb_utl_getkb
+      INTEGER :: ikb
+      REAL(wp) :: zD, zout
+      REAL(wp), DIMENSION(jpk) :: ze3, zin
+      WRITE(numout,*) 'Test icb_utl_getkb : '
+      zD = 0.0 ; ze3= 20.0
+      WRITE(numout,*) 'INPUT : zD = ',zD,' ze3 = ',ze3(1)
+      CALL icb_utl_getkb(ikb, ze3, zD)
+      WRITE(numout,*) 'OUTPUT : kb = ',ikb
+
+      zD = 8000000.0 ; ze3= 20.0
+      WRITE(numout,*) 'INPUT : zD = ',zD,' ze3 = ',ze3(1)
+      CALL icb_utl_getkb(ikb, ze3, zD)
+      WRITE(numout,*) 'OUTPUT : kb = ',ikb
+
+      zD = 80.0 ; ze3= 20.0
+      WRITE(numout,*) 'INPUT : zD = ',zD,' ze3 = ',ze3(1)
+      CALL icb_utl_getkb(ikb, ze3, zD)
+      WRITE(numout,*) 'OUTPUT : kb = ',ikb
+
+      zD = 85.0 ; ze3= 20.0
+      WRITE(numout,*) 'INPUT : zD = ',zD,' ze3 = ',ze3(1)
+      CALL icb_utl_getkb(ikb, ze3, zD)
+      WRITE(numout,*) 'OUTPUT : kb = ',ikb
+
+      zD = 75.0 ; ze3= 20.0
+      WRITE(numout,*) 'INPUT : zD = ',zD,' ze3 = ',ze3(1)
+      CALL icb_utl_getkb(ikb, ze3, zD)
+      WRITE(numout,*) 'OUTPUT : kb = ',ikb
+
+      WRITE(numout,*) '=================================='
+      WRITE(numout,*) 'Test icb_utl_zavg'
+      zD = 0.0 ; ze3= 20.0 ; zin=1.0
+      CALL icb_utl_getkb(ikb, ze3, zD)
+      CALL icb_utl_zavg(zout, zin, ze3, zD, ikb)
+      WRITE(numout,*) 'INPUT  : zD = ',zD,' ze3 = ',ze3(1),' zin = ', zin, ' ikb = ',ikb
+      WRITE(numout,*) 'OUTPUT : zout = ',zout
+
+      zD = 50.0 ; ze3= 20.0 ; zin=1.0; zin(3:jpk) = 0.0
+      CALL icb_utl_getkb(ikb, ze3, zD)
+      CALL icb_utl_zavg(zout, zin, ze3, zD, ikb)
+      WRITE(numout,*) 'INPUT  : zD = ',zD,' ze3 = ',ze3(1),' zin = ', zin, ' ikb = ',ikb
+      WRITE(numout,*) 'OUTPUT : zout = ',zout
+      CALL FLUSH(numout)
+
+      zD = 80.0 ; ze3= 20.0 ; zin=1.0; zin(3:jpk) = 0.0
+      CALL icb_utl_getkb(ikb, ze3, zD)
+      CALL icb_utl_zavg(zout, zin, ze3, zD, ikb)
+      WRITE(numout,*) 'INPUT  : zD = ',zD,' ze3 = ',ze3(1),' zin = ', zin, ' ikb = ',ikb
+      WRITE(numout,*) 'OUTPUT : zout = ',zout
+
+      zD = 80 ; ze3= 20.0 ; zin=1.0 ; zin(3:jpk) = 0.0
+      CALL icb_utl_getkb(ikb, ze3, zD)
+      ikb = 2
+      CALL icb_utl_zavg(zout, zin, ze3, zD, ikb)
+      WRITE(numout,*) 'INPUT  : zD = ',zD,' ze3 = ',ze3(1),' zin = ', zin, ' ikb = ',ikb
+      WRITE(numout,*) 'OUTPUT : zout = ',zout
+
+      CALL FLUSH(numout)
+
+   END SUBROUTINE test_icb_utl_getkb
+
    !!======================================================================
 END MODULE icbutl
