Index: branches/UKMO/dev_isf_remapping_UKESM_GO6package_r9314/NEMOGCM/CONFIG/SHARED/namelist_ref
===================================================================
--- branches/UKMO/dev_isf_remapping_UKESM_GO6package_r9314/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 9315)
+++ branches/UKMO/dev_isf_remapping_UKESM_GO6package_r9314/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 9316)
@@ -116,4 +116,17 @@
                         !!!!!!!! Other stretching (not SH94 or SF12) [also uses rn_theta above]
    rn_thetb    =    1.0    !  bottom control parameter  (0<=thetb<= 1)
+/
+!-----------------------------------------------------------------------
+&namzgr_isf    !   isf cavity geometry definition
+!-----------------------------------------------------------------------
+   rn_isfdep_min    = 10.         ! minimum isf draft tickness (if lower, isf draft set to this value)
+   rn_isfhw_deep    = 1.e-3       ! minimum water column thickness to declare a column 'wet'
+   rn_isfshallow    = 0.0         ! bathy between surface and rn_isfshallow are declared shallow
+   rn_isfhw_shallow = 1.e-3       ! minimum water column thickness to declare a column 'wet' in case of shallow isf
+   ln_isfchannel    = .false.     ! remove channel (based on 2d mask build from isfdraft-bathy)
+   ln_isfconnect    = .false.     ! force connection under the ice shelf (based on 2d mask build from isfdraft-bathy)
+   nn_kisfmax       = 999         ! limiter in level on the previous condition. (if change larger than this number, get back to value before we enforce the connection)
+   rn_zisfmax       = 7000.       ! limiter in m     on the previous condition. (if change larger than this number, get back to value before we enforce the connection)
+   ln_isfcheminey   = .false.     ! close cheminey
 /
 !-----------------------------------------------------------------------
Index: branches/UKMO/dev_isf_remapping_UKESM_GO6package_r9314/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- branches/UKMO/dev_isf_remapping_UKESM_GO6package_r9314/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 9315)
+++ branches/UKMO/dev_isf_remapping_UKESM_GO6package_r9314/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 9316)
@@ -1263,497 +1263,329 @@
       !!                Bathymetry and isfdraft are modified (dig/close) to respect
       !!                this criterion.
-      !!                 
+      !!                digging and filling base on depth criterion only
+      !!                          1.0 = set iceshelf to the minimum depth allowed
+      !!                          1.1 = ground ice shelf if water column less than X m
+      !!                          1.2 = ensure a minimum thickness for iceshelf cavity in shallow water
+      !!                          1.3 = remove channels and single point 'bay'
+      !!                          1.4 = close single isolated point
+      !!                compute level
+      !!                          2.0 = compute level
+      !!                          2.1 = ensure misfdep is not below bathymetry after step 2.0
+      !!                digging and filling base on level criterion only                
+      !!                          3.0 = dig to fit the 2 water level criterion (closed pool possible after this step)
+      !!                          3.1 = dig enough to ensure connectivity of all the cell beneath an ice shelf 
+      !!                                (most of the close pool should be remove after this step)
+      !!                          3.2 = fill chimney
       !!   
       !! ** Action  : - test compatibility between isfdraft and bathy 
       !!              - bathy and isfdraft are modified
       !!----------------------------------------------------------------------
-      !!   
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      INTEGER  ::   ik, it           ! temporary integers
-      INTEGER  ::   id, jd, nprocd
-      INTEGER  ::   icompt, ibtest, ibtestim1, ibtestip1, ibtestjm1, ibtestjp1   ! (ISF)
-      LOGICAL  ::   ll_print         ! Allow  control print for debugging
-      REAL(wp) ::   ze3tp , ze3wp    ! Last ocean level thickness at T- and W-points
-      REAL(wp) ::   zdepwp, zdepth   ! Ajusted ocean depth to avoid too small e3t
-      REAL(wp) ::   zmax, zmin       ! Maximum and minimum depth
-      REAL(wp) ::   zdiff            ! temporary scalar
-      REAL(wp) ::   zrefdep          ! temporary scalar
-      REAL(wp) ::   zbathydiff, zrisfdepdiff  ! isf temporary scalar
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zrisfdep, zbathy, zmask   ! 2D workspace (ISH)
-      INTEGER , POINTER, DIMENSION(:,:)   ::   zmbathy, zmisfdep         ! 2D workspace (ISH)
+      !!  
+      INTEGER  ::   ji, jj, jk, jn
+      INTEGER  ::   ibtest, ibtestim1, ibtestip1, ibtestjm1, ibtestjp1   ! (ISF)
+      INTEGER  ::   zmbathyij, zmbathyip1, zmbathyim1, zmbathyjp1, zmbathyjm1
+      INTEGER , POINTER, DIMENSION(:,:)   ::   zmisfdep, zmbathy         ! 2D workspace (ISH)
+      !
+      REAL(wp) ::   zdepth, vmskjp1, vmskjm1, umskip1, umskim1, umskip1_r, umskim1_r, vmskjp1_r, vmskjm1_r
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   zdummy, zmask, zrisfdep   ! 2D workspace (ISH)
+      !
+      !!-----------------
+      ! NAMELIST
+      INTEGER  ::   ios
+      INTEGER  :: nn_kisfmax    = 999. !  
+      REAL(wp) :: rn_isfdep_min = 10.0_wp ! ice shelf minimal thickness 
+      REAL(wp) :: rn_isfhw_deep = 1.e-3 , rn_isfhw_shallow = 1.0e-3 ! threshold to define grounding line in deep/shallow water
+      REAL(wp) :: rn_isfshallow = 0.0_wp  ! threshold to define shallow ice shelf cavity
+      REAL(wp) :: rn_zisfmax    = 6000.0_wp ! maximun meter of ice we are allowed to dig to assure connectivity
+      LOGICAL  :: ln_isfcheminey= .FALSE. , ln_isfconnect= .FALSE. , ln_isfchannel= .FALSE. !  remove cheminey, assure connectivity
       !!---------------------------------------------------------------------
+      NAMELIST/namzgr_isf/nn_kisfmax, rn_zisfmax, &
+              &           rn_isfdep_min, rn_isfhw_deep, rn_isfhw_shallow, rn_isfshallow, &
+              &           ln_isfcheminey, ln_isfconnect, ln_isfchannel
       !
       IF( nn_timing == 1 )  CALL timing_start('zgr_isf')
       !
-      CALL wrk_alloc( jpi, jpj, zbathy, zmask, zrisfdep)
+      CALL wrk_alloc( jpi, jpj, zdummy, zmask, zrisfdep)
       CALL wrk_alloc( jpi, jpj, zmisfdep, zmbathy )
-
-
-      ! (ISF) compute misfdep
-      WHERE( risfdep(:,:) == 0._wp .AND. bathy(:,:) .NE. 0) ;   misfdep(:,:) = 1   ! open water : set misfdep to 1  
-      ELSEWHERE                      ;                          misfdep(:,:) = 2   ! iceshelf : initialize misfdep to second level 
-      END WHERE  
-
-      ! Compute misfdep for ocean points (i.e. first wet level) 
+      !
+      !
+      REWIND( numnam_ref )              ! Namelist namzgr_isf in reference namelist : ice shelf geometry definition
+      READ  ( numnam_ref, namzgr_isf, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzgr_isf in reference namelist', lwp )
+
+      REWIND( numnam_cfg )              ! Namelist namzgr_sco in configuration namelist : ice shelf geometry definition
+      READ  ( numnam_cfg, namzgr_isf, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzgr_isf in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, namzgr_isf )
+      !
+      IF (lwp) THEN
+         WRITE(numout,*) ' nn_kisfmax       = ',nn_kisfmax           !
+         WRITE(numout,*) ' rn_zisfmax       = ',rn_zisfmax           !
+         WRITE(numout,*) ' rn_isfdep_min    = ',rn_isfdep_min        !
+         WRITE(numout,*) ' rn_isfhw_deep    = ',rn_isfhw_deep        !
+         WRITE(numout,*) ' rn_isfhw_shallow = ',rn_isfhw_shallow     !
+         WRITE(numout,*) ' rn_isfshallow    = ',rn_isfshallow        !
+         WRITE(numout,*) ' ln_isfcheminey   = ',ln_isfcheminey       !
+         WRITE(numout,*) ' ln_isfconnect    = ',ln_isfconnect        !
+         WRITE(numout,*) ' ln_isfchannel    = ',ln_isfchannel        !
+      END IF
+      !
+      ! 1.0 set iceshelf to the minimum depth allowed
+      WHERE(risfdep(:,:) > 0.0_wp .AND. risfdep(:,:) < MAX(rn_isfdep_min,e3t_1d(1)))
+         risfdep(:,:)=rn_isfdep_min
+      END WHERE
+      !  
+      ! 1.1 ground ice shelf if water column less than X m
+      WHERE( bathy(:,:) - risfdep(:,:) < rn_isfhw_deep ) 
+         risfdep(:,:)=0.0 ; misfdep(:,:) = 1
+         bathy  (:,:)=0.0 ; mbathy (:,:) = 0
+      END WHERE
+      !
+      ! 1.2 ensure a minimum thickness for iceshelf cavity in shallow water
+      WHERE( (bathy(:,:) < rn_isfshallow) .AND. (bathy(:,:) - risfdep(:,:) < rn_isfhw_shallow) ) 
+         risfdep(:,:)=0.0 ; misfdep(:,:) = 1
+         bathy  (:,:)=0.0 ; mbathy (:,:) = 0
+      END WHERE
+      !
+      ! 1.3 Remove channels and single point 'bay'.
+      ! channel could be created if connectivity is enforced later.
+      IF (ln_isfchannel) THEN
+         zmask(:,:)=1._wp
+         WHERE (mbathy(:,:)==0.0)
+            zmask(:,:)=0._wp
+         END WHERE
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               IF(  (misfdep(ji,jj) > 1) .AND. (mbathy(ji,jj) > 0) ) THEN
+                  umskip1=zmask(ji,jj)*zmask(ji+1,jj  )  ! 1 = connexion
+                  vmskjp1=zmask(ji,jj)*zmask(ji  ,jj+1)  ! 1 = connexion
+                  umskim1=zmask(ji,jj)*zmask(ji-1,jj  )  ! 1 = connexion
+                  vmskjm1=zmask(ji,jj)*zmask(ji  ,jj-1)  ! 1 = connexion
+               ! zonal channel and single bay
+                  IF ((umskip1+umskim1>=1) .AND. (vmskjp1+vmskjm1==0)) THEN
+                     risfdep(ji,jj)=0.0 ; misfdep(ji,jj) = 1
+                     bathy  (ji,jj)=0.0 ; mbathy (ji,jj) = 0
+                  END IF
+               ! meridionnal channel and single bay
+                  IF ((vmskjp1+vmskjm1>=1) .AND. (umskip1+umskim1==0)) THEN
+                     risfdep(ji,jj)=0.0 ; misfdep(ji,jj) = 1
+                     bathy  (ji,jj)=0.0 ; mbathy (ji,jj) = 0
+                  END IF
+               END IF
+            END DO
+         END DO
+         ! ensure halo correct 
+         IF( lk_mpp ) THEN
+            zdummy(:,:) = FLOAT( misfdep(:,:) ); CALL lbc_lnk( zdummy, 'T', 1. ); misfdep(:,:) = INT( zdummy(:,:) )
+            zdummy(:,:) = FLOAT( mbathy(:,:)  ); CALL lbc_lnk( zdummy, 'T', 1. ); mbathy(:,:)  = INT( zdummy(:,:) )
+            CALL lbc_lnk( risfdep, 'T', 1. )
+            CALL lbc_lnk( bathy  , 'T', 1. )
+         ENDIF       
+      END IF
+      !
+      ! 1.4 Closed single isolated point
+      zmask(:,:)=1._wp
+      WHERE (mbathy(:,:)==0.0)
+         zmask(:,:)=0._wp
+      END WHERE
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            IF(  (misfdep(ji,jj) > 1) .AND. (mbathy(ji,jj) > 0) ) THEN
+               umskip1=zmask(ji,jj)*zmask(ji+1,jj  )  ! 1 = connexion
+               vmskjp1=zmask(ji,jj)*zmask(ji  ,jj+1)  ! 1 = connexion
+               umskim1=zmask(ji,jj)*zmask(ji-1,jj  )  ! 1 = connexion
+               vmskjm1=zmask(ji,jj)*zmask(ji  ,jj-1)  ! 1 = connexion
+               ! remove single point
+               IF (umskip1+umskim1+vmskjp1+vmskjm1==0.0_wp) THEN
+                  risfdep(ji,jj)=0.0 ; misfdep(ji,jj) = 1
+                  bathy  (ji,jj)=0.0 ; mbathy (ji,jj) = 0
+               END IF
+            END IF
+         END DO
+      END DO
+      ! ensure halo correct 
+      IF( lk_mpp ) THEN
+         zdummy(:,:) = FLOAT( misfdep(:,:) ); CALL lbc_lnk( zdummy, 'T', 1. ); misfdep(:,:) = INT( zdummy(:,:) )
+         zdummy(:,:) = FLOAT( mbathy(:,:)  ); CALL lbc_lnk( zdummy, 'T', 1. ); mbathy(:,:)  = INT( zdummy(:,:) )
+         CALL lbc_lnk( risfdep, 'T', 1. )
+         CALL lbc_lnk( bathy  , 'T', 1. )
+      ENDIF
+      !
+      ! 2 Compute misfdep for ocean points (i.e. first wet level) 
       ! find the first ocean level such that the first level thickness 
       ! is larger than the bot_level of e3zps_min and e3zps_rat * e3t_0 (where 
       ! e3t_0 is the reference level thickness 
+      !
+      ! 2.0 set misfdep to 1 on open water and initialisation beneath ice shelf
+      WHERE( risfdep(:,:) == 0.0 ) ;   misfdep(:,:) = 1   ! open water or grounded : set misfdep to 1  
+      ELSEWHERE                    ;   misfdep(:,:) = 2   ! iceshelf : initialize misfdep to second level 
+      END WHERE  
+      !
       DO jk = 2, jpkm1 
          zdepth = gdepw_1d(jk+1) - MIN( e3zps_min, e3t_1d(jk)*e3zps_rat ) 
-         WHERE( 0._wp < risfdep(:,:) .AND. risfdep(:,:) >= zdepth )   misfdep(:,:) = jk+1 
+         WHERE( risfdep(:,:) > 0.0 .AND. risfdep(:,:) >= zdepth )   misfdep(:,:) = jk+1 
       END DO 
-      WHERE (risfdep(:,:) <= e3t_1d(1) .AND. risfdep(:,:) .GT. 0._wp)
-         risfdep(:,:) = 0. ; misfdep(:,:) = 1
-      END WHERE
- 
-! basic check for the compatibility of bathy and risfdep. I think it should be offline because it is not perfect and cannot solved all the situation
-      icompt = 0 
-! run the bathy check 10 times to be sure all the modif in the bathy or iceshelf draft are compatible together
-      DO jl = 1, 10     
-         WHERE (bathy(:,:) .EQ. risfdep(:,:) )
-            misfdep(:,:) = 0 ; risfdep(:,:) = 0._wp
-            mbathy (:,:) = 0 ; bathy  (:,:) = 0._wp
+      !
+      ! 2.1 be sure misfdep not below mbathy 
+      ! warning because of condition 4 we could have 'wet cell with misfdep below mbathy
+      ! risfdep of these cells will be fix later on (see 5)
+      WHERE( misfdep > mbathy .AND. mbathy > 0 ) misfdep=mbathy
+      !
+      ! 3.0 Assure 2 wet cells in the column at T point and along the edge.
+      ! first do T, then loop 4 times on U-1, U, V-1, V and then at T point
+      ! If un-luky, digging cell U-1 can trigger case for U+1, then V-1, then V+1
+      !
+      ! find the deepest isfdep level that fit the 2 wet cell on the water column
+      ! on all the sides (still need 4 pass)
+      DO jn = 1, 4
+         zmisfdep = misfdep
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               ! ISF cell only
+               IF(  (misfdep(ji,jj) > 1) .AND. (mbathy(ji,jj) > 0) ) THEN
+                  zmbathyij  = mbathy(ji  ,jj)
+                  ! set ground edge value to jpk to skip it later on
+                  zmbathyip1 = mbathy(ji+1,jj) ; IF (zmbathyip1 < misfdep(ji,jj)) zmbathyip1 = jpk ! not wet cell in common on this edge
+                  zmbathyim1 = mbathy(ji-1,jj) ; IF (zmbathyim1 < misfdep(ji,jj)) zmbathyim1 = jpk ! not wet cell in common on this edge
+                  zmbathyjp1 = mbathy(ji,jj+1) ; IF (zmbathyjp1 < misfdep(ji,jj)) zmbathyjp1 = jpk ! not wet cell in common on this edge
+                  zmbathyjm1 = mbathy(ji,jj-1) ; IF (zmbathyjm1 < misfdep(ji,jj)) zmbathyjm1 = jpk ! not wet cell in common on this edge
+                  ! shallowest bathy level
+                  zmbathyij = MIN(zmbathyij,zmbathyip1,zmbathyim1,zmbathyjp1,zmbathyjm1)
+                  ! misfdep need to be <= zmbathyij-1 to fit 2 wet cell on the
+                  ! water column
+                  jk = MIN(misfdep(ji,jj),zmbathyij-1)
+                  ! update isf draft if needed
+                  IF ( jk < misfdep(ji,jj) ) THEN
+                     zmisfdep(ji,jj) = jk
+                     risfdep(ji,jj)  = gdepw_1d(jk+1) - MIN( e3zps_min, e3t_1d(jk)*e3zps_rat )
+                  ELSE
+                     ! isf depth not modify, nothing to do
+                  END IF
+               ENDIF
+            END DO
+         END DO
+         misfdep=zmisfdep
+         ! ensure halo correct before new pass 
+         IF( lk_mpp ) THEN
+            zdummy(:,:) = FLOAT( misfdep(:,:) ); CALL lbc_lnk( zdummy, 'T', 1. ); misfdep(:,:) = INT( zdummy(:,:) )
+            zdummy(:,:) = FLOAT( mbathy(:,:)  ); CALL lbc_lnk( zdummy, 'T', 1. ); mbathy(:,:)  = INT( zdummy(:,:) )
+            CALL lbc_lnk( risfdep, 'T', 1. )
+            CALL lbc_lnk( bathy  , 'T', 1. )
+         ENDIF
+      END DO ! jn
+      !
+      ! 3.1 condition block to assure connectivity every where beneath an ice shelf
+      IF (ln_isfconnect) THEN
+         zmask(:,:)=1.0
+         WHERE (mbathy==0)
+            zmask(:,:)=jpk
          END WHERE
-         WHERE (mbathy(:,:) <= 0) 
-            misfdep(:,:) = 0; risfdep(:,:) = 0._wp 
-            mbathy (:,:) = 0; bathy  (:,:) = 0._wp
-         ENDWHERE
-         IF( lk_mpp ) THEN
-            zbathy(:,:) = FLOAT( misfdep(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            misfdep(:,:) = INT( zbathy(:,:) )
-            CALL lbc_lnk( risfdep, 'T', 1. )
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF
-         IF( nperio == 1 .OR. nperio  ==  4 .OR. nperio  ==  6 ) THEN 
-            misfdep( 1 ,:) = misfdep(jpim1,:)           ! local domain is cyclic east-west 
-            misfdep(jpi,:) = misfdep(  2  ,:) 
-         ENDIF
-
-         IF( nperio == 1 .OR. nperio  ==  4 .OR. nperio  ==  6 ) THEN
-            mbathy( 1 ,:) = mbathy(jpim1,:)             ! local domain is cyclic east-west
-            mbathy(jpi,:) = mbathy(  2  ,:)
-         ENDIF
-
-         ! split last cell if possible (only where water column is 2 cell or less)
-         DO jk = jpkm1, 1, -1
-            zmax = gdepw_1d(jk) + MIN( e3zps_min, e3t_1d(jk)*e3zps_rat )
-            WHERE( gdepw_1d(jk) < bathy(:,:) .AND. bathy(:,:) <= zmax .AND. misfdep + 1 >= mbathy)
-               mbathy(:,:) = jk
-               bathy(:,:)  = zmax
-            END WHERE
-         END DO
- 
-         ! split top cell if possible (only where water column is 2 cell or less)
-         DO jk = 2, jpkm1
-            zmax = gdepw_1d(jk+1) - MIN( e3zps_min, e3t_1d(jk)*e3zps_rat )
-            WHERE( gdepw_1d(jk+1) > risfdep(:,:) .AND. risfdep(:,:) >= zmax .AND. misfdep + 1 >= mbathy)
-               misfdep(:,:) = jk
-               risfdep(:,:) = zmax
-            END WHERE
-         END DO
-
- 
- ! Case where bathy and risfdep compatible but not the level variable mbathy/misfdep because of partial cell condition
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! find the minimum change option:
-               ! test bathy
-               IF (risfdep(ji,jj) .GT. 1) THEN
-               zbathydiff =ABS(bathy(ji,jj)   - (gdepw_1d(mbathy (ji,jj)+1) &
-                 &   + MIN( e3zps_min, e3t_1d(mbathy (ji,jj)+1)*e3zps_rat )))
-               zrisfdepdiff=ABS(risfdep(ji,jj) - (gdepw_1d(misfdep(ji,jj)  ) &
-                 &   - MIN( e3zps_min, e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )))
- 
-                  IF (bathy(ji,jj) .GT. risfdep(ji,jj) .AND. mbathy(ji,jj) .LT. misfdep(ji,jj)) THEN
-                     IF (zbathydiff .LE. zrisfdepdiff) THEN
-                        bathy(ji,jj) = gdepw_1d(mbathy(ji,jj)) + MIN( e3zps_min, e3t_1d(mbathy(ji,jj)+1)*e3zps_rat )
-                        mbathy(ji,jj)= mbathy(ji,jj) + 1
-                     ELSE
-                        risfdep(ji,jj) = gdepw_1d(misfdep(ji,jj)) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )
-                        misfdep(ji,jj) = misfdep(ji,jj) - 1
-                     END IF
+
+         zmbathy  = mbathy
+         zmisfdep = misfdep
+         zrisfdep = risfdep
+         WHERE (mbathy == 0) zmbathy=jpk
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               IF(  (misfdep(ji,jj) > 1) .AND. (mbathy(ji,jj) > 0) ) THEN
+! what it should be
+                  umskip1=zmask(ji,jj)*zmask(ji+1,jj  )  ! 1 = should be connected
+                  umskim1=zmask(ji,jj)*zmask(ji-1,jj  )  ! 1 = should be connected
+                  vmskjp1=zmask(ji,jj)*zmask(ji  ,jj+1)  ! 1 = should be connected
+                  vmskjm1=zmask(ji,jj)*zmask(ji  ,jj-1)  ! 1 = should be connected
+! what it is
+                  umskip1_r=jpk ; umskim1_r=jpk; vmskjp1_r=jpk; vmskjm1_r=jpk
+                  IF (misfdep(ji,jj) > zmbathy(ji+1,jj  )) umskip1_r=1.0 ! 1 = no effective connection
+                  IF (misfdep(ji,jj) > zmbathy(ji-1,jj  )) umskim1_r=1.0
+                  IF (misfdep(ji,jj) > zmbathy(ji  ,jj+1)) vmskjp1_r=1.0
+                  IF (misfdep(ji,jj) > zmbathy(ji  ,jj-1)) vmskjm1_r=1.0
+                  ! defining level need for connectivity
+                  jk=NINT(MIN(zmbathy(ji+1,jj  ) * umskip1_r * umskip1, &
+                     &        zmbathy(ji-1,jj  ) * umskim1_r * umskim1, &
+                     &        zmbathy(ji  ,jj+1) * vmskjp1_r * vmskjp1, &
+                     &        zmbathy(ji  ,jj-1) * vmskjm1_r * vmskjm1, &
+                     &        jpk+1.0 )) ! add jpk in the MIN to avoid out of boundary later on
+! if connectivity is OK or no connection needed (grounding line) or grounded, zmisfdep=misfdep
+                  zmisfdep(ji,jj)=MIN(misfdep(ji,jj),jk-1)
+                  !
+                  ! update isf draft if needed (need to be done here because next test is in meter and level)
+                  IF ( zmisfdep(ji,jj) < misfdep(ji,jj) ) THEN
+                     jk = zmisfdep(ji,jj)
+                     zrisfdep(ji,jj)  = gdepw_1d(jk+1) - MIN( e3zps_min, e3t_1d(jk)*e3zps_rat )
+                  END IF
+   
+                  ! sanity check
+                  ! check if we dig more than nn_kisfmax level or reach the surface
+                  ! check if we dig more than rn_zisfmax meter
+                  ! => if this is the case, undo what has been done before
+                  IF (      (misfdep(ji,jj)-zmisfdep(ji,jj) > MIN(nn_kisfmax,misfdep(ji,jj)-2)) &
+                     & .OR. (risfdep(ji,jj)-zrisfdep(ji,jj) > MIN(rn_zisfmax,risfdep(ji,jj)  )) ) THEN
+                     zmisfdep(ji,jj)=misfdep(ji,jj) 
+                     zrisfdep(ji,jj)=risfdep(ji,jj)
                   END IF
                END IF
             END DO
          END DO
- 
-          ! At least 2 levels for water thickness at T, U, and V point.
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ! find the minimum change option:
-               ! test bathy
-               IF( misfdep(ji,jj) == mbathy(ji,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff  =ABS(bathy(ji,jj)  - (gdepw_1d(mbathy (ji,jj)+1)&
-                    & + MIN( e3zps_min,e3t_1d(mbathy (ji,jj)+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji,jj) - (gdepw_1d(misfdep(ji,jj)  )  &
-                    & - MIN( e3zps_min,e3t_1d(misfdep(ji,jj)-1)*e3zps_rat )))
-                  IF (zbathydiff .LE. zrisfdepdiff) THEN
-                     mbathy(ji,jj) = mbathy(ji,jj) + 1
-                     bathy(ji,jj)  = gdepw_1d(mbathy (ji,jj)) + MIN( e3zps_min, e3t_1d(mbathy(ji,jj) +1)*e3zps_rat )
-                  ELSE
-                     misfdep(ji,jj)= misfdep(ji,jj) - 1
-                     risfdep(ji,jj) = gdepw_1d(misfdep(ji,jj)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj))*e3zps_rat )
-                  END IF
-               ENDIF
-            END DO
-         END DO
- 
- ! point V mbathy(ji,jj) EQ misfdep(ji,jj+1) 
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-               IF( misfdep(ji,jj+1) == mbathy(ji,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff =ABS(bathy(ji,jj    ) - (gdepw_1d(mbathy (ji,jj)+1)   &
-                    &   + MIN( e3zps_min, e3t_1d(mbathy (ji,jj  )+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji,jj+1) - (gdepw_1d(misfdep(ji,jj+1))  &
-                    &  - MIN( e3zps_min, e3t_1d(misfdep(ji,jj+1)-1)*e3zps_rat )))
-                  IF (zbathydiff .LE. zrisfdepdiff) THEN
-                     mbathy(ji,jj) = mbathy(ji,jj) + 1
-                     bathy(ji,jj)  = gdepw_1d(mbathy (ji,jj  )) &
-                   &    + MIN( e3zps_min, e3t_1d(mbathy(ji,jj   )+1)*e3zps_rat )
-                  ELSE
-                     misfdep(ji,jj+1)  = misfdep(ji,jj+1) - 1
-                     risfdep (ji,jj+1) = gdepw_1d(misfdep(ji,jj+1)+1) &
-                   &   - MIN( e3zps_min, e3t_1d(misfdep(ji,jj+1))*e3zps_rat )
-                  END IF
-               ENDIF
-            END DO
-         END DO
- 
+         misfdep=zmisfdep
+         risfdep=zrisfdep
+         ! ensure halo correct 
          IF( lk_mpp ) THEN
-            zbathy(:,:) = FLOAT( misfdep(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            misfdep(:,:) = INT( zbathy(:,:) )
+            zdummy(:,:) = FLOAT( misfdep(:,:) ); CALL lbc_lnk( zdummy, 'T', 1. ); misfdep(:,:) = INT( zdummy(:,:) )
+            zdummy(:,:) = FLOAT( mbathy(:,:)  ); CALL lbc_lnk( zdummy, 'T', 1. ); mbathy(:,:)  = INT( zdummy(:,:) )
             CALL lbc_lnk( risfdep, 'T', 1. )
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
+            CALL lbc_lnk( bathy  , 'T', 1. )
          ENDIF
- ! point V misdep(ji,jj) EQ mbathy(ji,jj+1) 
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-               IF( misfdep(ji,jj) == mbathy(ji,jj+1) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff =ABS(  bathy(ji,jj+1) - (gdepw_1d(mbathy (ji,jj+1)+1) &
-                   &   + MIN( e3zps_min, e3t_1d(mbathy (ji,jj+1)+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji,jj  ) - (gdepw_1d(misfdep(ji,jj  )  )  &
-                   &   - MIN( e3zps_min, e3t_1d(misfdep(ji,jj  )-1)*e3zps_rat )))
-                  IF (zbathydiff .LE. zrisfdepdiff) THEN
-                     mbathy (ji,jj+1) = mbathy(ji,jj+1) + 1
-                     bathy  (ji,jj+1) = gdepw_1d(mbathy (ji,jj+1)  ) + MIN( e3zps_min, e3t_1d(mbathy (ji,jj+1)+1)*e3zps_rat )
-                  ELSE
-                     misfdep(ji,jj)   = misfdep(ji,jj) - 1
-                     risfdep(ji,jj)   = gdepw_1d(misfdep(ji,jj  )+1) - MIN( e3zps_min, e3t_1d(misfdep(ji,jj  )  )*e3zps_rat )
-                  END IF
-               ENDIF
-            END DO
-         END DO
- 
- 
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- 
- ! point U mbathy(ji,jj) EQ misfdep(ji,jj+1) 
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-               IF( misfdep(ji+1,jj) == mbathy(ji,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff =ABS(  bathy(ji  ,jj) - (gdepw_1d(mbathy (ji,jj)+1) &
-                    &   + MIN( e3zps_min, e3t_1d(mbathy (ji  ,jj)+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji+1,jj) - (gdepw_1d(misfdep(ji+1,jj)) &
-                    &  - MIN( e3zps_min, e3t_1d(misfdep(ji+1,jj)-1)*e3zps_rat )))
-                  IF (zbathydiff .LE. zrisfdepdiff) THEN
-                     mbathy(ji,jj) = mbathy(ji,jj) + 1
-                     bathy(ji,jj)  = gdepw_1d(mbathy (ji,jj)) + MIN( e3zps_min, e3t_1d(mbathy(ji,jj) +1)*e3zps_rat )
-                  ELSE
-                     misfdep(ji+1,jj)= misfdep(ji+1,jj) - 1
-                     risfdep(ji+1,jj) = gdepw_1d(misfdep(ji+1,jj)+1) - MIN( e3zps_min, e3t_1d(misfdep(ji+1,jj))*e3zps_rat )
-                  END IF
-               ENDIF
+      END IF
+      !
+      IF (ln_isfcheminey) THEN
+      ! 3.2 fill hole in ice shelf (ie cell with no velocity point)
+      !      => misfdep = MIN(misfdep at U, U-1, V, V-1)
+      !         risfdep = gdepw(misfdep) (ie full cell)
+         zmisfdep = misfdep
+         WHERE (mbathy == 0) zmisfdep=jpk   ! grounded
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               ibtest    = zmisfdep(ji  ,jj  )
+               ibtestim1 = zmisfdep(ji-1,jj  ) ; ibtestip1 = zmisfdep(ji+1,jj  )
+               ibtestjm1 = zmisfdep(ji  ,jj-1) ; ibtestjp1 = zmisfdep(ji  ,jj+1)
+               ! case unconected wet cell (T point) where isfdraft(ii,jj) deeper
+               ! than bathy U-1/U+1/V-1/V+1
+               IF( zmisfdep(ji,jj) > mbathy(ji-1,jj  ) ) ibtestim1 = jpk ! mask at U-1
+               IF( zmisfdep(ji,jj) > mbathy(ji+1,jj  ) ) ibtestip1 = jpk ! mask at U+1
+               IF( zmisfdep(ji,jj) > mbathy(ji  ,jj-1) ) ibtestjm1 = jpk ! mask at V-1
+               IF( zmisfdep(ji,jj) > mbathy(ji  ,jj+1) ) ibtestjp1 = jpk ! mask at V+1
+               ! case unconected wet cell (T point) where bathy(ii,jj) shallower
+               ! than isfdraft U-1/U+1/V-1/V+1
+               IF( mbathy(ji,jj) < zmisfdep(ji-1,jj  ) ) ibtestim1 = jpk ! mask at U-1
+               IF( mbathy(ji,jj) < zmisfdep(ji+1,jj  ) ) ibtestip1 = jpk ! mask at U+1
+               IF( mbathy(ji,jj) < zmisfdep(ji  ,jj-1) ) ibtestjm1 = jpk ! mask at V-1
+               IF( mbathy(ji,jj) < zmisfdep(ji  ,jj+1) ) ibtestjp1 = jpk ! mask at V+1
+               ! if surround in fully mask => mask cell  (1)
+               ! if hole in the ice shelf, set to the min of surrounding (the MIN is doing the job) 
+               ! if misfdep is not changed, nothing is done (the MAX is doing the
+               ! job)
+               ibtest = MAX(ibtest,MIN(ibtestim1, ibtestip1, ibtestjm1,ibtestjp1))
+               IF (misfdep(ji,jj) < ibtest) THEN
+                  misfdep(ji,jj) = ibtest
+                  risfdep(ji,jj) = gdepw_1d(ibtest)
+               END IF
             ENDDO
          ENDDO
- 
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- 
- ! point U misfdep(ji,jj) EQ bathy(ji,jj+1) 
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-               IF( misfdep(ji,jj) == mbathy(ji+1,jj) .AND. mbathy(ji,jj) .GT. 1) THEN
-                  zbathydiff =ABS(  bathy(ji+1,jj) - (gdepw_1d(mbathy (ji+1,jj)+1) &
-                      &   + MIN( e3zps_min, e3t_1d(mbathy (ji+1,jj)+1)*e3zps_rat )))
-                  zrisfdepdiff=ABS(risfdep(ji  ,jj) - (gdepw_1d(misfdep(ji  ,jj)  )  &
-                      &  - MIN( e3zps_min, e3t_1d(misfdep(ji  ,jj)-1)*e3zps_rat )))
-                  IF (zbathydiff .LE. zrisfdepdiff) THEN
-                     mbathy(ji+1,jj)  = mbathy (ji+1,jj) + 1
-                     bathy (ji+1,jj)  = gdepw_1d(mbathy (ji+1,jj)  )  &
-                      &   + MIN( e3zps_min, e3t_1d(mbathy (ji+1,jj) +1)*e3zps_rat )
-                  ELSE
-                     misfdep(ji,jj)   = misfdep(ji  ,jj) - 1
-                     risfdep(ji,jj)   = gdepw_1d(misfdep(ji  ,jj)+1) &
-                      &   - MIN( e3zps_min, e3t_1d(misfdep(ji  ,jj)   )*e3zps_rat )
-                  END IF
-               ENDIF
-            ENDDO
-         ENDDO
- 
+         WHERE( misfdep == jpk)   ! ground case (1)
+            mbathy = 0 ; bathy = 0.0_wp ; misfdep = 1 ; risfdep = 0.0_wp
+         END WHERE
+         !
+         ! ensure halo correct
          IF( lk_mpp ) THEN
-            zbathy(:,:) = FLOAT( misfdep(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            misfdep(:,:) = INT( zbathy(:,:) )
+            zdummy(:,:) = FLOAT( misfdep(:,:) ); CALL lbc_lnk( zdummy, 'T', 1. ); misfdep(:,:) = INT( zdummy(:,:) )
+            zdummy(:,:) = FLOAT( mbathy(:,:)  ); CALL lbc_lnk( zdummy, 'T', 1. ); mbathy(:,:)  = INT( zdummy(:,:) )
             CALL lbc_lnk( risfdep, 'T', 1. )
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF
-      END DO
-      ! end dig bathy/ice shelf to be compatible
-      ! now fill single point in "coastline" of ice shelf, bathy, hole, and test again one cell tickness
-      DO jl = 1,20
- 
- ! remove single point "bay" on isf coast line in the ice shelf draft'
-         DO jk = 2, jpk
-            WHERE (misfdep==0) misfdep=jpk
-            zmask=0
-            WHERE (misfdep .LE. jk) zmask=1
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
-                  IF (misfdep(ji,jj) .EQ. jk) THEN
-                     ibtest = zmask(ji-1,jj) + zmask(ji+1,jj) + zmask(ji,jj-1) + zmask(ji,jj+1)
-                     IF (ibtest .LE. 1) THEN
-                        risfdep(ji,jj)=gdepw_1d(jk+1) ; misfdep(ji,jj)=jk+1
-                        IF (misfdep(ji,jj) .GT. mbathy(ji,jj)) misfdep(ji,jj) = jpk
-                     END IF
-                  END IF
-               END DO
-            END DO
-         END DO
-         WHERE (misfdep==jpk)
-             misfdep=0 ; risfdep=0. ; mbathy=0 ; bathy=0.
-         END WHERE
-         IF( lk_mpp ) THEN
-            zbathy(:,:) = FLOAT( misfdep(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            misfdep(:,:) = INT( zbathy(:,:) )
-            CALL lbc_lnk( risfdep, 'T', 1. )
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF
- 
- ! remove single point "bay" on bathy coast line beneath an ice shelf'
-         DO jk = jpk,1,-1
-            zmask=0
-            WHERE (mbathy .GE. jk ) zmask=1
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
-                  IF (mbathy(ji,jj) .EQ. jk .AND. misfdep(ji,jj) .GE. 2) THEN
-                     ibtest = zmask(ji-1,jj) + zmask(ji+1,jj) + zmask(ji,jj-1) + zmask(ji,jj+1)
-                     IF (ibtest .LE. 1) THEN
-                        bathy(ji,jj)=gdepw_1d(jk) ; mbathy(ji,jj)=jk-1
-                        IF (misfdep(ji,jj) .GT. mbathy(ji,jj)) mbathy(ji,jj) = 0
-                     END IF
-                  END IF
-               END DO
-            END DO
-         END DO
-         WHERE (mbathy==0)
-             misfdep=0 ; risfdep=0. ; mbathy=0 ; bathy=0.
-         END WHERE
-         IF( lk_mpp ) THEN
-            zbathy(:,:) = FLOAT( misfdep(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            misfdep(:,:) = INT( zbathy(:,:) )
-            CALL lbc_lnk( risfdep, 'T', 1. )
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF
- 
- ! fill hole in ice shelf
-         zmisfdep = misfdep
-         zrisfdep = risfdep
-         WHERE (zmisfdep .LE. 1) zmisfdep=jpk
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-               ibtestim1 = zmisfdep(ji-1,jj  ) ; ibtestip1 = zmisfdep(ji+1,jj  )
-               ibtestjm1 = zmisfdep(ji  ,jj-1) ; ibtestjp1 = zmisfdep(ji  ,jj+1)
-               IF( zmisfdep(ji,jj) .GE. mbathy(ji-1,jj  ) ) ibtestim1 = jpk!MAX(0, mbathy(ji-1,jj  ) - 1)
-               IF( zmisfdep(ji,jj) .GE. mbathy(ji+1,jj  ) ) ibtestip1 = jpk!MAX(0, mbathy(ji+1,jj  ) - 1)
-               IF( zmisfdep(ji,jj) .GE. mbathy(ji  ,jj-1) ) ibtestjm1 = jpk!MAX(0, mbathy(ji  ,jj-1) - 1)
-               IF( zmisfdep(ji,jj) .GE. mbathy(ji  ,jj+1) ) ibtestjp1 = jpk!MAX(0, mbathy(ji  ,jj+1) - 1)
-               ibtest=MIN(ibtestim1, ibtestip1, ibtestjm1, ibtestjp1)
-               IF( ibtest == jpk .AND. misfdep(ji,jj) .GE. 2) THEN
-                  mbathy(ji,jj) = 0 ; bathy(ji,jj) = 0.0_wp ; misfdep(ji,jj) = 0 ; risfdep(ji,jj) = 0.0_wp
-               END IF
-               IF( zmisfdep(ji,jj) < ibtest .AND. misfdep(ji,jj) .GE. 2) THEN
-                  misfdep(ji,jj) = ibtest
-                  risfdep(ji,jj) = gdepw_1d(ibtest)
-               ENDIF
-            ENDDO
-         ENDDO
- 
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- !
- !! fill hole in bathymetry
-         zmbathy (:,:)=mbathy (:,:)
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-               ibtestim1 = zmbathy(ji-1,jj  ) ; ibtestip1 = zmbathy(ji+1,jj  )
-               ibtestjm1 = zmbathy(ji  ,jj-1) ; ibtestjp1 = zmbathy(ji  ,jj+1)
-               IF( zmbathy(ji,jj) .LT. misfdep(ji-1,jj  ) ) ibtestim1 = 0!MIN(jpk-1, misfdep(ji-1,jj  ) + 1)
-               IF( zmbathy(ji,jj) .LT. misfdep(ji+1,jj  ) ) ibtestip1 = 0
-               IF( zmbathy(ji,jj) .LT. misfdep(ji  ,jj-1) ) ibtestjm1 = 0
-               IF( zmbathy(ji,jj) .LT. misfdep(ji  ,jj+1) ) ibtestjp1 = 0
-               ibtest=MAX(ibtestim1, ibtestip1, ibtestjm1, ibtestjp1)
-               IF( ibtest == 0 .AND. misfdep(ji,jj) .GE. 2) THEN
-                  mbathy(ji,jj) = 0 ; bathy(ji,jj) = 0.0_wp ; misfdep(ji,jj) = 0 ; risfdep(ji,jj) = 0.0_wp ;
-               END IF
-               IF( ibtest < zmbathy(ji,jj) .AND. misfdep(ji,jj) .GE. 2) THEN
-                  mbathy(ji,jj) = ibtest
-                  bathy(ji,jj)  = gdepw_1d(ibtest+1) 
-               ENDIF
-            END DO
-         END DO
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- ! if not compatible after all check (ie U point water column less than 2 cells), mask U
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-               IF (mbathy(ji,jj) == misfdep(ji+1,jj) .AND. mbathy(ji,jj) .GE. 1 .AND. mbathy(ji+1,jj) .GE. 1) THEN
-                  mbathy(ji,jj)  = mbathy(ji,jj) - 1 ; bathy(ji,jj)   = gdepw_1d(mbathy(ji,jj)+1) ;
-               END IF
-            END DO
-         END DO
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- ! if not compatible after all check (ie U point water column less than 2 cells), mask U
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-               IF (misfdep(ji,jj) == mbathy(ji+1,jj) .AND. mbathy(ji,jj) .GE. 1 .AND. mbathy(ji+1,jj) .GE. 1) THEN
-                  mbathy(ji+1,jj)  = mbathy(ji+1,jj) - 1;   bathy(ji+1,jj)   = gdepw_1d(mbathy(ji+1,jj)+1) ;
-               END IF
-            END DO
-         END DO
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- ! if not compatible after all check (ie V point water column less than 2 cells), mask V
-         DO jj = 1, jpjm1
-            DO ji = 1, jpi
-               IF (mbathy(ji,jj) == misfdep(ji,jj+1) .AND. mbathy(ji,jj) .GE. 1 .AND. mbathy(ji,jj+1) .GE. 1) THEN
-                  mbathy(ji,jj)  = mbathy(ji,jj) - 1 ; bathy(ji,jj)   = gdepw_1d(mbathy(ji,jj)+1) ;
-               END IF
-            END DO
-         END DO
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- ! if not compatible after all check (ie V point water column less than 2 cells), mask V
-         DO jj = 1, jpjm1
-            DO ji = 1, jpi
-               IF (misfdep(ji,jj) == mbathy(ji,jj+1) .AND. mbathy(ji,jj) .GE. 1 .AND. mbathy(ji,jj+1) .GE. 1) THEN
-                  mbathy(ji,jj+1)  = mbathy(ji,jj+1) - 1 ; bathy(ji,jj+1)   = gdepw_1d(mbathy(ji,jj+1)+1) ;
-               END IF
-            END DO
-         END DO
-         IF( lk_mpp ) THEN 
-            zbathy(:,:) = FLOAT( misfdep(:,:) ) 
-            CALL lbc_lnk( zbathy, 'T', 1. ) 
-            misfdep(:,:) = INT( zbathy(:,:) ) 
-            CALL lbc_lnk( risfdep, 'T', 1. ) 
-            CALL lbc_lnk( bathy, 'T', 1. )
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
-            CALL lbc_lnk( zbathy, 'T', 1. )
-            mbathy(:,:) = INT( zbathy(:,:) )
-         ENDIF 
- ! if not compatible after all check, mask T
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF (mbathy(ji,jj) <= misfdep(ji,jj)) THEN
-                  misfdep(ji,jj) = 0 ; risfdep(ji,jj) = 0._wp ; mbathy(ji,jj)  = 0 ; bathy(ji,jj)   = 0._wp ;
-               END IF
-            END DO
-         END DO
- 
-         WHERE (mbathy(:,:) == 1)
-            mbathy = 0; bathy = 0.0_wp ; misfdep = 0 ; risfdep = 0.0_wp
-         END WHERE
-      END DO 
-! end check compatibility ice shelf/bathy
-      ! remove very shallow ice shelf (less than ~ 10m if 75L)
-      WHERE (misfdep(:,:) <= 5)
-         misfdep = 1; risfdep = 0.0_wp;
-      END WHERE
-
-      IF( icompt == 0 ) THEN 
-         IF(lwp) WRITE(numout,*)'     no points with ice shelf too close to bathymetry' 
-      ELSE 
-         IF(lwp) WRITE(numout,*)'    ',icompt,' ocean grid points with ice shelf thickness reduced to avoid bathymetry' 
-      ENDIF 
-
-      CALL wrk_dealloc( jpi, jpj, zmask, zbathy, zrisfdep )
-      CALL wrk_dealloc( jpi, jpj, zmisfdep, zmbathy )
-
+            CALL lbc_lnk( bathy  , 'T', 1. )
+         END IF
+      END IF
+      !
+      CALL wrk_dealloc( jpi, jpj, zmask, zdummy, zrisfdep)
+      CALL wrk_dealloc( jpi, jpj, zmisfdep, zmbathy)
+      !
       IF( nn_timing == 1 )  CALL timing_stop('zgr_isf')
       
