Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 9553)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 9554)
@@ -145,11 +145,11 @@
       INTEGER, INTENT(in)  ::   kt   ! ocean time-step index
       !
-      INTEGER  ::   ji, jj, jk, jn   		! dummy loop indices
+      INTEGER  ::   ji, jj, jk, jn        ! dummy loop indices
       LOGICAL  ::   ll_fw_start           ! =T : forward integration 
-      LOGICAL  ::   ll_init			      ! =T : special startup of 2d equations
+      LOGICAL  ::   ll_init               ! =T : special startup of 2d equations
       LOGICAL  ::   ll_tmp1, ll_tmp2      ! local logical variables used in W/D
       INTEGER  ::   ikbu, iktu, noffset   ! local integers
       INTEGER  ::   ikbv, iktv            !   -      -
-      REAL(wp) ::   r1_2dt_b, z2dt_bf  	          ! local scalars
+      REAL(wp) ::   r1_2dt_b, z2dt_bf               ! local scalars
       REAL(wp) ::   zx1, zx2, zu_spg, zhura, z1_hu  !   -      -
       REAL(wp) ::   zy1, zy2, zv_spg, zhvra, z1_hv  !   -      -
@@ -254,15 +254,8 @@
                DO jj = 1, jpjm1
                   DO ji = 1, jpim1
-!!gm bug for ocean cavities
-!                     zwz(ji,jj) =   ( ht_n(ji  ,jj+1) + ht_n(ji+1,jj+1) +                     &
-!                        &             ht_n(ji  ,jj  ) + ht_n(ji+1,jj  )   )                   &
-!                        &       / ( MAX( 1._wp, tmask(ji  ,jj+1, 1) + tmask(ji+1,jj+1, 1) +    &
-!                        &                       tmask(ji  ,jj  , 1) + tmask(ji+1,jj  , 1) ) )
-!! replace by :
                      zwz(ji,jj) =             (  ht_n  (ji  ,jj+1) + ht_n  (ji+1,jj+1)      &
                         &                      + ht_n  (ji  ,jj  ) + ht_n  (ji+1,jj  )  )   &
                         &       / ( MAX( 1._wp,  ssmask(ji  ,jj+1) + ssmask(ji+1,jj+1)      &
                         &                      + ssmask(ji  ,jj  ) + ssmask(ji+1,jj  )  )   )
-!!gm end
                      IF( zwz(ji,jj) /= 0._wp )   zwz(ji,jj) = ff_f(ji,jj) / zwz(ji,jj)
                   END DO
@@ -320,19 +313,8 @@
                DO jj = 1, jpjm1
                   DO ji = 1, jpim1
-!!gm Bug here in case of ocean cavities, further more ht_0 is masked by definition ==>> remove mask multiplication 
-!                     zhf(ji,jj) = MAX( 0._wp,                                &
-!                                & ( ht_0(ji  ,jj  )*tmask(ji  ,jj  ,1) +     &
-!                                &   ht_0(ji+1,jj  )*tmask(ji+1,jj  ,1) +     &
-!                                &   ht_0(ji  ,jj+1)*tmask(ji  ,jj+1,1) +     &
-!                                &   ht_0(ji+1,jj+1)*tmask(ji+1,jj+1,1) ) /   &
-!                                & ( tmask(ji  ,jj  ,1) + tmask(ji+1,jj  ,1) +&
-!                                &   tmask(ji  ,jj+1,1) + tmask(ji+1,jj+1,1) +&
-!                                &   rsmall  ) )
-!!gm replaced by :
                      zhf(ji,jj) =    (   ht_0  (ji,jj  ) + ht_0  (ji+1,jj  )          &
                         &              + ht_0  (ji,jj+1) + ht_0  (ji+1,jj+1)   )      &
                         &       / MAX(   ssmask(ji,jj  ) + ssmask(ji+1,jj  )          &
                         &              + ssmask(ji,jj+1) + ssmask(ji+1,jj+1) , 1._wp  )
-!!gm end
                   END DO
                END DO
@@ -1249,9 +1231,9 @@
          DO jj = 1, jpjm1
             DO ji = 1, jpim1      ! NO Vector Opt.
-               zsshu_a(ji,jj) = r1_2 * umask(ji,jj,1)  * r1_e1e2u(ji,jj) &
-                  &              * ( e1e2t(ji  ,jj) * ssha(ji  ,jj)    &
+               zsshu_a(ji,jj) = r1_2 * ssumask(ji,jj)  * r1_e1e2u(ji,jj) &
+                  &              * ( e1e2t(ji  ,jj) * ssha(ji  ,jj)      &
                   &              +   e1e2t(ji+1,jj) * ssha(ji+1,jj) )
-               zsshv_a(ji,jj) = r1_2 * vmask(ji,jj,1)  * r1_e1e2v(ji,jj) &
-                  &              * ( e1e2t(ji,jj  ) * ssha(ji,jj  )    &
+               zsshv_a(ji,jj) = r1_2 * ssvmask(ji,jj)  * r1_e1e2v(ji,jj) &
+                  &              * ( e1e2t(ji,jj  ) * ssha(ji,jj  )      &
                   &              +   e1e2t(ji,jj+1) * ssha(ji,jj+1) )
             END DO
@@ -1310,6 +1292,6 @@
       !
       IF( ln_diatmb ) THEN
-         CALL iom_put( "baro_u" , un_b*umask(:,:,1)+zmdi*(1-umask(:,:,1 ) ) )  ! Barotropic  U Velocity
-         CALL iom_put( "baro_v" , vn_b*vmask(:,:,1)+zmdi*(1-vmask(:,:,1 ) ) )  ! Barotropic  V Velocity
+         CALL iom_put( "baro_u" , un_b*ssumask(:,:)+zmdi*(1.-ssumask(:,:) ) )  ! Barotropic  U Velocity
+         CALL iom_put( "baro_v" , vn_b*ssvmask(:,:)+zmdi*(1.-ssvmask(:,:) ) )  ! Barotropic  V Velocity
       ENDIF
       !
