Index: branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90
===================================================================
--- branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90	(revision 7510)
+++ branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90	(revision 7757)
@@ -54,10 +54,15 @@
       IF( Agrif_Root() )  RETURN
       !
-      IF( PRESENT( kiter ) ) THEN  ! interpolation at the child sub-time step (for ice rheology)
-         zbeta = ( REAL(lim_nbstep) - REAL(kitermax - kiter) / REAL(kitermax) ) /  &
-            &    ( Agrif_Rhot() * REAL(Agrif_Parent(nn_fsbc)) / REAL(nn_fsbc) )
-      ELSE                         ! interpolation at the child time step
-         zbeta = REAL(lim_nbstep) / ( Agrif_Rhot() * REAL(Agrif_Parent(nn_fsbc)) / REAL(nn_fsbc) )
-      ENDIF
+      SELECT CASE(cd_type)
+      CASE('U','V')
+         IF( PRESENT( kiter ) ) THEN  ! interpolation at the child sub-time step (only for ice rheology)
+            zbeta = ( REAL(lim_nbstep) - REAL(kitermax - kiter) / REAL(kitermax) ) /  &
+               &    ( Agrif_Rhot() * REAL(Agrif_Parent(nn_fsbc)) / REAL(nn_fsbc) )
+         ELSE                         ! interpolation at the child time step
+            zbeta = REAL(lim_nbstep) / ( Agrif_Rhot() * REAL(Agrif_Parent(nn_fsbc)) / REAL(nn_fsbc) )
+         ENDIF
+      CASE('T')
+            zbeta = REAL(lim_nbstep-1) / ( Agrif_Rhot() * REAL(Agrif_Parent(nn_fsbc)) / REAL(nn_fsbc) )
+      END SELECT
       !
       Agrif_SpecialValue=-9999.
@@ -151,6 +156,6 @@
 
       !!-----------------------------------------------------------------------
-      ! clem: pkoi on n'utilise pas les quantités intégrées ici => before: * e12t ; after: * r1_e12t / rhox / rhoy
-      ! a priori c'est ok comme ca (cf ce qui est fait dans l'ocean). Je ne sais pas pkoi ceci dit
+      ! tracers are not multiplied by grid cell here => before: * e12t ; after: * r1_e12t / rhox / rhoy
+      ! and it is ok since we conserve tracers (same as in the ocean).
       ALLOCATE( ztab(SIZE(a_i_b,1),SIZE(a_i_b,2),SIZE(ptab,3)) )
      
@@ -177,133 +182,142 @@
       ELSE               ! child grid
 !! ==> The easiest interpolation is the following commented lines
-!!         jm = 1
-!!         DO jl = 1, jpl
-!!            a_i  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-!!            v_i  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-!!            v_s  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-!!            smv_i(i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-!!            oa_i (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-!!            DO jk = 1, nlay_s
-!!               e_s(i1:i2,j1:j2,jk,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-!!            ENDDO
-!!            DO jk = 1, nlay_i
-!!               e_i(i1:i2,j1:j2,jk,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-!!            ENDDO
-!!         ENDDO
+         jm = 1
+         DO jl = 1, jpl
+            a_i  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            v_i  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            v_s  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            smv_i(i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            oa_i (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            DO jk = 1, nlay_s
+               e_s(i1:i2,j1:j2,jk,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            ENDDO
+            DO jk = 1, nlay_i
+               e_i(i1:i2,j1:j2,jk,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            ENDDO
+         ENDDO
 
 !! ==> this is a more complex interpolation since we mix solutions over a couple of grid points
 !!     it is advised to use it for fields modified by high order schemes (e.g. advection UM5...)
-         ! record ztab
-         jm = 1
-         DO jl = 1, jpl
-            ztab(:,:,jm) = a_i_b  (:,:,jl) ; jm = jm + 1
-            ztab(:,:,jm) = v_i_b  (:,:,jl) ; jm = jm + 1
-            ztab(:,:,jm) = v_s_b  (:,:,jl) ; jm = jm + 1
-            ztab(:,:,jm) = smv_i_b(:,:,jl) ; jm = jm + 1
-            ztab(:,:,jm) = oa_i_b (:,:,jl) ; jm = jm + 1
-            DO jk = 1, nlay_s
-               ztab(:,:,jm) = e_s_b(:,:,jk,jl) ; jm = jm + 1
-            ENDDO
-            DO jk = 1, nlay_i
-               ztab(:,:,jm) = e_i_b(:,:,jk,jl) ; jm = jm + 1
-            ENDDO
-         ENDDO
-         !
-         ! borders of the domain
-         western_side  = (nb == 1).AND.(ndir == 1)  ;  eastern_side  = (nb == 1).AND.(ndir == 2)
-         southern_side = (nb == 2).AND.(ndir == 1)  ;  northern_side = (nb == 2).AND.(ndir == 2)
-         !
-         ! spatial smoothing
-         zrhox = Agrif_Rhox()
-         z1 =      ( zrhox - 1. ) * 0.5 
-         z3 =      ( zrhox - 1. ) / ( zrhox + 1. )
-         z6 = 2. * ( zrhox - 1. ) / ( zrhox + 1. )
-         z7 =    - ( zrhox - 1. ) / ( zrhox + 3. )
-         z2 = 1. - z1
-         z4 = 1. - z3
-         z5 = 1. - z6 - z7
-         !
-         ! Remove corners
-         imin = i1  ;  imax = i2  ;  jmin = j1  ;  jmax = j2
-         IF( (nbondj == -1) .OR. (nbondj == 2) )   jmin = 3
-         IF( (nbondj == +1) .OR. (nbondj == 2) )   jmax = nlcj-2
-         IF( (nbondi == -1) .OR. (nbondi == 2) )   imin = 3
-         IF( (nbondi == +1) .OR. (nbondi == 2) )   imax = nlci-2
-
-         ! smoothed fields
-         IF( eastern_side ) THEN
-            ztab(nlci,j1:j2,:) = z1 * ptab(nlci,j1:j2,:) + z2 * ptab(nlci-1,j1:j2,:)
-            DO jj = jmin, jmax
-               rswitch = 0.
-               IF( u_ice(nlci-2,jj) > 0._wp ) rswitch = 1.
-               ztab(nlci-1,jj,:) = ( 1. - umask(nlci-2,jj,1) ) * ztab(nlci,jj,:)  &
-                  &                +      umask(nlci-2,jj,1)   *  &
-                  &                ( ( 1. - rswitch ) * ( z4 * ztab(nlci,jj,:)   + z3 * ztab(nlci-2,jj,:) )  &
-                  &                  +      rswitch   * ( z6 * ztab(nlci-2,jj,:) + z5 * ztab(nlci,jj,:) + z7 * ztab(nlci-3,jj,:) ) )
-               ztab(nlci-1,jj,:) = ztab(nlci-1,jj,:) * tmask(nlci-1,jj,1)
-            END DO
-         ENDIF
-         ! 
-         IF( northern_side ) THEN
-            ztab(i1:i2,nlcj,:) = z1 * ptab(i1:i2,nlcj,:) + z2 * ptab(i1:i2,nlcj-1,:)
-            DO ji = imin, imax
-               rswitch = 0.
-               IF( v_ice(ji,nlcj-2) > 0._wp ) rswitch = 1.
-               ztab(ji,nlcj-1,:) = ( 1. - vmask(ji,nlcj-2,1) ) * ztab(ji,nlcj,:)  &
-                  &                +      vmask(ji,nlcj-2,1)   *  &
-                  &                ( ( 1. - rswitch ) * ( z4 * ztab(ji,nlcj,:)   + z3 * ztab(ji,nlcj-2,:) ) &
-                  &                  +      rswitch   * ( z6 * ztab(ji,nlcj-2,:) + z5 * ztab(ji,nlcj,:) + z7 * ztab(ji,nlcj-3,:) ) )
-               ztab(ji,nlcj-1,:) = ztab(ji,nlcj-1,:) * tmask(ji,nlcj-1,1)
-            END DO
-         END IF
-         !
-         IF( western_side) THEN
-            ztab(1,j1:j2,:) = z1 * ptab(1,j1:j2,:) + z2 * ptab(2,j1:j2,:)
-            DO jj = jmin, jmax
-               rswitch = 0.
-               IF( u_ice(2,jj) > 0._wp ) rswitch = 1.
-               ztab(2,jj,:) = ( 1. - umask(2,jj,1) ) * ztab(1,jj,:)  &
-                  &           +      umask(2,jj,1)   *   &
-                  &           ( ( 1. - rswitch ) * ( z4 * ztab(1,jj,:) + z3 * ztab(3,jj,:) ) &
-                  &             +      rswitch   * ( z6 * ztab(3,jj,:) + z5 * ztab(1,jj,:) + z7 * ztab(4,jj,:) ) )
-               ztab(2,jj,:) = ztab(2,jj,:) * tmask(2,jj,1)
-            END DO
-         ENDIF
-         !
-         IF( southern_side ) THEN
-            ztab(i1:i2,1,:) = z1 * ptab(i1:i2,1,:) + z2 * ptab(i1:i2,2,:)
-            DO ji = imin, imax
-               rswitch = 0.
-               IF( v_ice(ji,2) > 0._wp ) rswitch = 1.
-               ztab(ji,2,:) = ( 1. - vmask(ji,2,1) ) * ztab(ji,1,:)  &
-                  &           +      vmask(ji,2,1)   *  &
-                  &           ( ( 1. - rswitch ) * ( z4 * ztab(ji,1,:) + z3 * ztab(ji,3,:) ) &
-                  &             +      rswitch   * ( z6 * ztab(ji,3,:) + z5 * ztab(ji,1,:) + z7 * ztab(ji,4,:) ) )
-               ztab(ji,2,:) = ztab(ji,2,:) * tmask(ji,2,1)
-            END DO
-         END IF
-         !
-         ! Treatment of corners
-         IF( (eastern_side) .AND. ((nbondj == -1).OR.(nbondj == 2)) )  ztab(nlci-1,2,:)      = ptab(nlci-1,2,:)      ! East south
-         IF( (eastern_side) .AND. ((nbondj ==  1).OR.(nbondj == 2)) )  ztab(nlci-1,nlcj-1,:) = ptab(nlci-1,nlcj-1,:) ! East north
-         IF( (western_side) .AND. ((nbondj == -1).OR.(nbondj == 2)) )  ztab(2,2,:)           = ptab(2,2,:)           ! West south
-         IF( (western_side) .AND. ((nbondj ==  1).OR.(nbondj == 2)) )  ztab(2,nlcj-1,:)      = ptab(2,nlcj-1,:)      ! West north
-
-         ! retrieve ice tracers
-         jm = 1
-         DO jl = 1, jpl
-            a_i  (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            v_i  (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            v_s  (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            smv_i(i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            oa_i (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            DO jk = 1, nlay_s
-               e_s(i1:i2,j1:j2,jk,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            ENDDO
-            DO jk = 1, nlay_i
-               e_i(i1:i2,j1:j2,jk,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            ENDDO
-         ENDDO
-         
+!!        clem: for some reason (I don't know why), the following lines do not work 
+!!              with mpp (or in realistic configurations?). It makes the model crash
+!         ! record ztab
+!         jm = 1
+!         DO jl = 1, jpl
+!            ztab(:,:,jm) = a_i  (:,:,jl) ; jm = jm + 1
+!            ztab(:,:,jm) = v_i  (:,:,jl) ; jm = jm + 1
+!            ztab(:,:,jm) = v_s  (:,:,jl) ; jm = jm + 1
+!            ztab(:,:,jm) = smv_i(:,:,jl) ; jm = jm + 1
+!            ztab(:,:,jm) = oa_i (:,:,jl) ; jm = jm + 1
+!            DO jk = 1, nlay_s
+!               ztab(:,:,jm) = e_s(:,:,jk,jl) ; jm = jm + 1
+!            ENDDO
+!            DO jk = 1, nlay_i
+!               ztab(:,:,jm) = e_i(:,:,jk,jl) ; jm = jm + 1
+!            ENDDO
+!         ENDDO
+!         !
+!         ! borders of the domain
+!         western_side  = (nb == 1).AND.(ndir == 1)  ;  eastern_side  = (nb == 1).AND.(ndir == 2)
+!         southern_side = (nb == 2).AND.(ndir == 1)  ;  northern_side = (nb == 2).AND.(ndir == 2)
+!         !
+!         ! spatial smoothing
+!         zrhox = Agrif_Rhox()
+!         z1 =      ( zrhox - 1. ) * 0.5 
+!         z3 =      ( zrhox - 1. ) / ( zrhox + 1. )
+!         z6 = 2. * ( zrhox - 1. ) / ( zrhox + 1. )
+!         z7 =    - ( zrhox - 1. ) / ( zrhox + 3. )
+!         z2 = 1. - z1
+!         z4 = 1. - z3
+!         z5 = 1. - z6 - z7
+!         !
+!         ! Remove corners
+!         imin = i1  ;  imax = i2  ;  jmin = j1  ;  jmax = j2
+!         IF( (nbondj == -1) .OR. (nbondj == 2) )   jmin = 3
+!         IF( (nbondj == +1) .OR. (nbondj == 2) )   jmax = nlcj-2
+!         IF( (nbondi == -1) .OR. (nbondi == 2) )   imin = 3
+!         IF( (nbondi == +1) .OR. (nbondi == 2) )   imax = nlci-2
+!
+!         ! smoothed fields
+!         IF( eastern_side ) THEN
+!            ztab(nlci,j1:j2,:) = z1 * ptab(nlci,j1:j2,:) + z2 * ptab(nlci-1,j1:j2,:)
+!            DO jj = jmin, jmax
+!               rswitch = 0.
+!               IF( u_ice(nlci-2,jj) > 0._wp ) rswitch = 1.
+!               ztab(nlci-1,jj,:) = ( 1. - umask(nlci-2,jj,1) ) * ztab(nlci,jj,:)  &
+!                  &                +      umask(nlci-2,jj,1)   *  &
+!                  &                ( ( 1. - rswitch ) * ( z4 * ztab(nlci,jj,:)   + z3 * ztab(nlci-2,jj,:) )  &
+!                  &                  +      rswitch   * ( z6 * ztab(nlci-2,jj,:) + z5 * ztab(nlci,jj,:) + z7 * ztab(nlci-3,jj,:) ) )
+!               ztab(nlci-1,jj,:) = ztab(nlci-1,jj,:) * tmask(nlci-1,jj,1)
+!            END DO
+!         ENDIF
+!         ! 
+!         IF( northern_side ) THEN
+!            ztab(i1:i2,nlcj,:) = z1 * ptab(i1:i2,nlcj,:) + z2 * ptab(i1:i2,nlcj-1,:)
+!            DO ji = imin, imax
+!               rswitch = 0.
+!               IF( v_ice(ji,nlcj-2) > 0._wp ) rswitch = 1.
+!               ztab(ji,nlcj-1,:) = ( 1. - vmask(ji,nlcj-2,1) ) * ztab(ji,nlcj,:)  &
+!                  &                +      vmask(ji,nlcj-2,1)   *  &
+!                  &                ( ( 1. - rswitch ) * ( z4 * ztab(ji,nlcj,:)   + z3 * ztab(ji,nlcj-2,:) ) &
+!                  &                  +      rswitch   * ( z6 * ztab(ji,nlcj-2,:) + z5 * ztab(ji,nlcj,:) + z7 * ztab(ji,nlcj-3,:) ) )
+!               ztab(ji,nlcj-1,:) = ztab(ji,nlcj-1,:) * tmask(ji,nlcj-1,1)
+!            END DO
+!         END IF
+!         !
+!         IF( western_side) THEN
+!            ztab(1,j1:j2,:) = z1 * ptab(1,j1:j2,:) + z2 * ptab(2,j1:j2,:)
+!            DO jj = jmin, jmax
+!               rswitch = 0.
+!               IF( u_ice(2,jj) < 0._wp ) rswitch = 1.
+!               ztab(2,jj,:) = ( 1. - umask(2,jj,1) ) * ztab(1,jj,:)  &
+!                  &           +      umask(2,jj,1)   *   &
+!                  &           ( ( 1. - rswitch ) * ( z4 * ztab(1,jj,:) + z3 * ztab(3,jj,:) ) &
+!                  &             +      rswitch   * ( z6 * ztab(3,jj,:) + z5 * ztab(1,jj,:) + z7 * ztab(4,jj,:) ) )
+!               ztab(2,jj,:) = ztab(2,jj,:) * tmask(2,jj,1)
+!            END DO
+!         ENDIF
+!         !
+!         IF( southern_side ) THEN
+!            ztab(i1:i2,1,:) = z1 * ptab(i1:i2,1,:) + z2 * ptab(i1:i2,2,:)
+!            DO ji = imin, imax
+!               rswitch = 0.
+!               IF( v_ice(ji,2) < 0._wp ) rswitch = 1.
+!               ztab(ji,2,:) = ( 1. - vmask(ji,2,1) ) * ztab(ji,1,:)  &
+!                  &           +      vmask(ji,2,1)   *  &
+!                  &           ( ( 1. - rswitch ) * ( z4 * ztab(ji,1,:) + z3 * ztab(ji,3,:) ) &
+!                  &             +      rswitch   * ( z6 * ztab(ji,3,:) + z5 * ztab(ji,1,:) + z7 * ztab(ji,4,:) ) )
+!               ztab(ji,2,:) = ztab(ji,2,:) * tmask(ji,2,1)
+!            END DO
+!         END IF
+!         !
+!         ! Treatment of corners
+!         IF( (eastern_side) .AND. ((nbondj == -1).OR.(nbondj == 2)) )  ztab(nlci-1,2,:)      = ptab(nlci-1,2,:)      ! East south
+!         IF( (eastern_side) .AND. ((nbondj ==  1).OR.(nbondj == 2)) )  ztab(nlci-1,nlcj-1,:) = ptab(nlci-1,nlcj-1,:) ! East north
+!         IF( (western_side) .AND. ((nbondj == -1).OR.(nbondj == 2)) )  ztab(2,2,:)           = ptab(2,2,:)           ! West south
+!         IF( (western_side) .AND. ((nbondj ==  1).OR.(nbondj == 2)) )  ztab(2,nlcj-1,:)      = ptab(2,nlcj-1,:)      ! West north
+!
+!         ! retrieve ice tracers
+!         jm = 1
+!         DO jl = 1, jpl
+!            a_i  (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) ; jm = jm + 1
+!            v_i  (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) ; jm = jm + 1
+!            v_s  (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) ; jm = jm + 1
+!            smv_i(i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) ; jm = jm + 1
+!            oa_i (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) ; jm = jm + 1
+!            DO jk = 1, nlay_s
+!               e_s(i1:i2,j1:j2,jk,jl) = ztab(i1:i2,j1:j2,jm) ; jm = jm + 1
+!            ENDDO
+!            DO jk = 1, nlay_i
+!               e_i(i1:i2,j1:j2,jk,jl) = ztab(i1:i2,j1:j2,jm) ; jm = jm + 1
+!            ENDDO
+!         ENDDO
+       
+         ! integrated values
+         vt_i (i1:i2,j1:j2) = SUM( v_i(i1:i2,j1:j2,:), dim=3 )
+         vt_s (i1:i2,j1:j2) = SUM( v_s(i1:i2,j1:j2,:), dim=3 )
+         at_i (i1:i2,j1:j2) = SUM( a_i(i1:i2,j1:j2,:), dim=3 )
+         et_s(i1:i2,j1:j2)  = SUM( SUM( e_s(i1:i2,j1:j2,:,:), dim=4 ), dim=3 )
+         et_i(i1:i2,j1:j2)  = SUM( SUM( e_i(i1:i2,j1:j2,:,:), dim=4 ), dim=3 )
+
       ENDIF
       
Index: branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_lim3_update.F90
===================================================================
--- branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_lim3_update.F90	(revision 7510)
+++ branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_lim3_update.F90	(revision 7757)
@@ -52,16 +52,8 @@
       !!----------------------------------------------------------------------
       !
-!      IF( ( MOD( kt-nit000, Agrif_irhot() * Agrif_Parent(nn_fsbc) ) /=0 ) .AND. (kt /= 0) ) THEN
-!         PRINT *, 'clem NOT udpate, kt=',kt,Agrif_NbStepint()
-!      ELSE
-!         PRINT *, 'clem     UPDATE, kt=',kt,Agrif_NbStepint()
-!      ENDIF
-
-      !! clem: I think the update should take place each time the ocean sees the surface forcings (but maybe I am wrong and we should update every rhot time steps) 
-      IF( ( MOD( kt-nit000, Agrif_irhot() * Agrif_Parent(nn_fsbc) ) /=0 ) .AND. (kt /= 0) ) RETURN ! do not update if nb of child time steps differ from time refinement
-                                                                                                   ! i.e. update only at the parent time step
-      !! clem: this condition is clearly wrong if nn_fsbc/=1 (==> Agrif_NbStepint /= (Agrif_irhot()-1) all the time)
-      !!IF( ( Agrif_NbStepint() .NE. (Agrif_irhot()-1) ) .AND. (kt /= 0) )  RETURN
-      
+      !! clem: I think the update should take place each time the ocean sees the surface forcings
+      !!       (but maybe I am wrong and we should update every rhot time steps) 
+      IF( ( MOD( (kt-nit000)/nn_fsbc + 1, Agrif_irhot() * Agrif_Parent(nn_fsbc) / nn_fsbc ) /=0 ) .AND. (kt /= 0) ) RETURN ! do not update if nb of child time steps differ from time refinement
+                                                                                                                           ! i.e. update only at the parent time step
       Agrif_UseSpecialValueInUpdate = .TRUE.
       Agrif_SpecialValueFineGrid = -9999.
@@ -98,5 +90,5 @@
       INTEGER  :: jk, jl, jm
       !!-----------------------------------------------------------------------
-      ! clem: it is ok not to multiply by e1 e2 since we conserve tracers here (cf ce qui est fait dans opa).
+      ! it is ok not to multiply by e1*e2 since we conserve tracers here (same as in the ocean).
       IF( before ) THEN
          jm = 1
@@ -135,4 +127,11 @@
          ENDDO
 
+         ! integrated values
+         vt_i (i1:i2,j1:j2) = SUM( v_i(i1:i2,j1:j2,:), dim=3 )
+         vt_s (i1:i2,j1:j2) = SUM( v_s(i1:i2,j1:j2,:), dim=3 )
+         at_i (i1:i2,j1:j2) = SUM( a_i(i1:i2,j1:j2,:), dim=3 )
+         et_s(i1:i2,j1:j2)  = SUM( SUM( e_s(i1:i2,j1:j2,:,:), dim=4 ), dim=3 )
+         et_i(i1:i2,j1:j2)  = SUM( SUM( e_i(i1:i2,j1:j2,:,:), dim=4 ), dim=3 )
+         
       ENDIF
       !
Index: branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_user.F90
===================================================================
--- branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 7510)
+++ branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 7757)
@@ -35,7 +35,11 @@
 !     hold parent grid vertical levels number (set earlier)
 !      jpk     = jpkdta 
+# if defined key_sas2D
+      jpkm1   = 1
+# else
+      jpkm1   = jpk-1
+# endif
       jpim1   = jpi-1 
       jpjm1   = jpj-1 
-      jpkm1   = jpk-1                                         
       jpij    = jpi*jpj 
       jpidta  = jpiglo
@@ -90,4 +94,7 @@
 # if defined key_top
    CALL Agrif_InitValues_cont_top
+# endif
+# if defined key_lim3
+   CALL Agrif_InitValues_cont_lim3
 # endif
    !
@@ -289,9 +296,9 @@
          ! check if vmask agree with parent along northern and southern boundaries:
          CALL Agrif_Bc_variable(vmsk_id,calledweight=1.,procname=interpvmsk)
-	 ! check if tmask and vertical scale factors agree with parent over first two coarse grid points:
+         ! check if tmask and vertical scale factors agree with parent over first two coarse grid points:
          CALL Agrif_Bc_variable(e3t_id,calledweight=1.,procname=interpe3t)
          !
          IF (lk_mpp) CALL mpp_sum( kindic_agr )
-         IF( kindic_agr /= 0 ) THEN             		
+         IF( kindic_agr /= 0 ) THEN
             CALL ctl_stop('Child Bathymetry is not correct near boundaries.')
          ELSE
@@ -579,5 +586,12 @@
    CALL agrif_declare_var_lim3
 
-   ! Controls (clem)
+   ! Controls
+
+   ! clem: For some reason, nn_fsbc(child)/=1 does not work properly (signal is largely degraded by the agrif zoom)
+   !          the run must satisfy CFL=Uice/(dx/dt) < 0.6/nn_fsbc(child)
+   !          therefore, if nn_fsbc(child)>1 one must reduce the time-step in proportion to nn_fsbc(child), which is not acceptable
+   !       If a solution is found, the following stop could be removed
+   IF( nn_fsbc > 1 )  CALL ctl_stop('nn_fsbc(child) must be set to 1 otherwise agrif and lim3 do not work properly')
+
    ! stop if rhot * nn_fsbc(parent) /= N * nn_fsbc(child) with N being integer
    IF( MOD( Agrif_irhot() * Agrif_Parent(nn_fsbc), nn_fsbc ) /= 0 )  THEN
@@ -591,9 +605,10 @@
    ! First Interpolations (using "after" ice subtime step => lim_nbstep=1)
    !----------------------------------------------------------------------
-   lim_nbstep = 1
+!!   lim_nbstep = 1.
+   lim_nbstep = ( Agrif_irhot() * Agrif_Parent(nn_fsbc) / nn_fsbc ) ! clem: to have calledweight=1 in interp (otherwise the western border of the zoom is wrong)
    CALL agrif_interp_lim3('U') ! interpolation of ice velocities
    CALL agrif_interp_lim3('V') ! interpolation of ice velocities
    CALL agrif_interp_lim3('T') ! interpolation of ice tracers
-   lim_nbstep = 0
+   lim_nbstep = 0.
    
    ! Update in case 2 ways
@@ -618,4 +633,8 @@
    ! 1. Declaration of the type of variable which have to be interpolated (parent=>child)
    !       agrif_declare_variable(position,1st point index,--,--,dimensions,name)
+   !           ex.:  position=> 1,1 = not-centered (in i and j)
+   !                            2,2 =     centered (    -     )
+   !                 index   => 1,1 = one ghost line
+   !                            2,2 = two ghost lines
    !-------------------------------------------------------------------------------------
    CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpl*(5+nlay_s+nlay_i)/),tra_ice_id )
@@ -637,5 +656,5 @@
    ! 4. Set update type in case 2 ways (child=>parent) (normal & tangent to the grid cell for velocities)
    !--------------------------------------------------
-   CALL Agrif_Set_Updatetype(tra_ice_id, update = AGRIF_Update_Average) ! clem je comprends pas average/copy
+   CALL Agrif_Set_Updatetype(tra_ice_id, update = AGRIF_Update_Average)
    CALL Agrif_Set_Updatetype(u_ice_id  ,update1 = Agrif_Update_Copy   , update2 = Agrif_Update_Average)
    CALL Agrif_Set_Updatetype(v_ice_id  ,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy   )
