Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modarrays.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modarrays.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modarrays.F90	(revision 10087)
@@ -55,5 +55,6 @@
                                proc_id,         &
                                coords,          &
-                               lb_tab_true, ub_tab_true, memberin )
+                               lb_tab_true, ub_tab_true, memberin,  &
+                               indminglob3,indmaxglob3)
 !---------------------------------------------------------------------------------------------------
     integer,                   intent(in)  :: nbdim         !< Number of dimensions
@@ -61,4 +62,5 @@
     integer, dimension(nbdim), intent(in)  :: ub_var        !< Local upper boundary on the current processor
     integer, dimension(nbdim), intent(in)  :: lb_tab        !< Global lower boundary of the variable
+    integer, dimension(nbdim),OPTIONAL     :: indminglob3,indmaxglob3 !< True bounds for MPI USE
     integer, dimension(nbdim), intent(in)  :: ub_tab        !< Global upper boundary of the variable
     integer,                   intent(in)  :: proc_id       !< Current processor
@@ -78,10 +80,16 @@
         call Agrif_InvLoc( lb_var(i), proc_id, coord_i, lb_glob_index )
         call Agrif_InvLoc( ub_var(i), proc_id, coord_i, ub_glob_index )
+        if (present(indminglob3)) then
+          indminglob3(i)=lb_glob_index
+          indmaxglob3(i)=ub_glob_index
+        endif
 #else
         lb_glob_index = lb_var(i)
         ub_glob_index = ub_var(i)
 #endif
+
         lb_tab_true(i) = max(lb_tab(i), lb_glob_index)
         ub_tab_true(i) = min(ub_tab(i), ub_glob_index)
+
     enddo
 !
@@ -123,5 +131,6 @@
 !
     iminmaxg(1:nbdim,2) = - iminmaxg(1:nbdim,2)
-    call MPI_ALLREDUCE(iminmaxg, lubglob, 2*nbdim, MPI_INTEGER, MPI_MIN, Agrif_mpi_comm, code)
+    call MPI_ALLREDUCE(iminmaxg, lubglob, 2*nbdim, MPI_INTEGER, MPI_MIN, &
+                       Agrif_mpi_comm, code)
     lubglob(1:nbdim,2)  = - lubglob(1:nbdim,2)
 #endif
@@ -225,5 +234,6 @@
     case (1) ; call Agrif_set_array_tozero_1D(variable%array1)
     case (2) ; call Agrif_set_array_tozero_2D(variable%array2)
-    case (3) ; call Agrif_set_array_tozero_3D(variable%array3)
+    case (3) ; call Agrif_set_array_tozero_reshape(variable%array3,size(variable%array3))
+!case (3) ; call Agrif_set_array_tozero_3D(variable%array3)
     case (4) ; call Agrif_set_array_tozero_4D(variable%array4)
     case (5) ; call Agrif_set_array_tozero_5D(variable%array5)
@@ -266,4 +276,110 @@
 !===================================================================================================
 !
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine agrif_set_array_cond
+!
+!> Compute the masking of \b variablein, according to the required dimension.
+!---------------------------------------------------------------------------------------------------
+subroutine agrif_set_array_cond ( variablein, variableout, value, nbdim )
+!---------------------------------------------------------------------------------------------------
+    type(Agrif_Variable), intent(in)    :: variablein     !< Variablein
+    type(Agrif_Variable), intent(inout) :: variableout    !< Variableout
+    real,intent(in) :: value                            !< special value
+    integer, intent(in)                 :: nbdim        !< Dimension of the array
+
+!
+    select case (nbdim)
+    case (1) ; call agrif_set_array_cond_1D(variablein%array1,variableout%array1,value)
+    case (2) ; call agrif_set_array_cond_2D(variablein%array2,variableout%array2,value)
+    case (3) ; call agrif_set_array_cond_reshape(variablein%array3,variableout%array3,value,size(variablein%array3))
+!    case (3) ; call agrif_set_array_cond_3D(variablein%array3,variableout%array3,value)
+    case (4) ; call agrif_set_array_cond_4D(variablein%array4,variableout%array4,value)
+    case (5) ; call agrif_set_array_cond_5D(variablein%array5,variableout%array5,value)
+    case (6) ; call agrif_set_array_cond_6D(variablein%array6,variableout%array6,value)
+    end select
+!---------------------------------------------------------------------------------------------------
+contains
+!---------------------------------------------------------------------------------------------------
+subroutine agrif_set_array_cond_1D(arrayin,arrayout,value)
+real,dimension(:),intent(in) :: arrayin
+real,dimension(:),intent(out) :: arrayout
+real :: value
+
+where (arrayin == value)
+  arrayout = 0.
+elsewhere
+  arrayout = 1.
+end where
+
+end subroutine agrif_set_array_cond_1D
+!
+subroutine agrif_set_array_cond_2D(arrayin,arrayout,value)
+real,dimension(:,:),intent(in) :: arrayin
+real,dimension(:,:),intent(out) :: arrayout
+real :: value
+
+where (arrayin == value)
+  arrayout = 0.
+elsewhere
+  arrayout = 1.
+end where
+
+end subroutine agrif_set_array_cond_2D
+!
+subroutine agrif_set_array_cond_3D(arrayin,arrayout,value)
+real,dimension(:,:,:),intent(in) :: arrayin
+real,dimension(:,:,:),intent(out) :: arrayout
+real :: value
+
+where (arrayin == value)
+  arrayout = 0.
+elsewhere
+  arrayout = 1.
+end where
+
+end subroutine agrif_set_array_cond_3D
+!
+subroutine agrif_set_array_cond_4D(arrayin,arrayout,value)
+real,dimension(:,:,:,:),intent(in) :: arrayin
+real,dimension(:,:,:,:),intent(out) :: arrayout
+real :: value
+
+where (arrayin == value)
+  arrayout = 0.
+elsewhere
+  arrayout = 1.
+end where
+
+end subroutine agrif_set_array_cond_4D
+!
+subroutine agrif_set_array_cond_5D(arrayin,arrayout,value)
+real,dimension(:,:,:,:,:),intent(in) :: arrayin
+real,dimension(:,:,:,:,:),intent(out) :: arrayout
+real :: value
+
+where (arrayin == value)
+  arrayout = 0.
+elsewhere
+  arrayout = 1.
+end where
+
+end subroutine agrif_set_array_cond_5D
+!
+subroutine agrif_set_array_cond_6D(arrayin,arrayout,value)
+real,dimension(:,:,:,:,:,:),intent(in) :: arrayin
+real,dimension(:,:,:,:,:,:),intent(out) :: arrayout
+real :: value
+
+where (arrayin == value)
+  arrayout = 0.
+elsewhere
+  arrayout = 1.
+end where
+
+end subroutine agrif_set_array_cond_6D
+!---------------------------------------------------------------------------------------------------
+end subroutine agrif_set_array_cond
 !===================================================================================================
 !  subroutine Agrif_var_copy_array
@@ -330,9 +446,26 @@
         real, dimension(l(1):,l(2):,l(3):), intent(out) :: tabout
         real, dimension(m(1):,m(2):,m(3):), intent(in)  :: tabin
-        tabout(inf1(1):sup1(1), &
-               inf1(2):sup1(2), &
-               inf1(3):sup1(3)) = tabin(inf2(1):sup2(1), &
-                                        inf2(2):sup2(2), &
-                                        inf2(3):sup2(3))
+        integer :: i,j,k
+
+
+!$OMP PARALLEL DO DEFAULT(none) PRIVATE(i,j,k) &
+!$OMP SHARED(inf1,inf2,sup1,sup2,tabin,tabout) &
+!$OMP SCHEDULE(RUNTIME)
+        do k=inf1(3),sup1(3)
+        do j=inf1(2),sup1(2)
+        do i=inf1(1),sup1(1)
+!          tabout(i,j,k) = tabin(i+inf2(1)-inf1(1),j+inf2(2)-inf1(2),k+inf2(3)-inf1(3))
+          tabout(i,j,k) = tabin(i,j,k)
+        enddo
+        enddo
+        enddo
+!$OMP END PARALLEL DO
+
+
+!        tabout(inf1(1):sup1(1), &
+!               inf1(2):sup1(2), &
+!               inf1(3):sup1(3)) = tabin(inf2(1):sup2(1), &
+!                                        inf2(2):sup2(2), &
+!                                        inf2(3):sup2(3))
     end subroutine Agrif_copy_array_3d
 !
@@ -631,8 +764,8 @@
     integer, dimension(6), intent(out)          :: lb_child     !< Lower bound on the child grid
     integer, dimension(6), intent(out)          :: lb_parent    !< Lower bound on the parent grid
-    real, dimension(6),    intent(out)          :: s_child      !< Child  grid position (s_root = 0)
-    real, dimension(6),    intent(out)          :: s_parent     !< Parent grid position (s_root = 0)
-    real, dimension(6),    intent(out)          :: ds_child     !< Child  grid dx (ds_root = 1)
-    real, dimension(6),    intent(out)          :: ds_parent    !< Parent grid dx (ds_root = 1)
+    real(kind=8), dimension(6),    intent(out)  :: s_child      !< Child  grid position (s_root = 0)
+    real(kind=8), dimension(6),    intent(out)  :: s_parent     !< Parent grid position (s_root = 0)
+    real(kind=8), dimension(6),    intent(out)  :: ds_child     !< Child  grid dx (ds_root = 1)
+    real(kind=8), dimension(6),    intent(out)  :: ds_parent    !< Parent grid dx (ds_root = 1)
     integer,               intent(out)          :: nbdim        !< Number of dimensions
     logical,               intent(in)           :: interp       !< .true. if preprocess for interpolation, \n
@@ -671,6 +804,6 @@
             else
                 ub_child(n) = lb_child(n) + Agrif_Child_Gr % nb(1) - 1
-                s_child(n)  = s_child(n)  + 0.5*ds_child(n)
-                s_parent(n) = s_parent(n) + 0.5*ds_parent(n)
+                s_child(n)  = s_child(n)  + 0.5d0*ds_child(n)
+                s_parent(n) = s_parent(n) + 0.5d0*ds_parent(n)
             endif
 !
@@ -689,6 +822,6 @@
             else
                 ub_child(n) = lb_child(n) + Agrif_Child_Gr % nb(2) - 1
-                s_child(n)  = s_child(n)  + 0.5*ds_child(n)
-                s_parent(n) = s_parent(n) + 0.5*ds_parent(n)
+                s_child(n)  = s_child(n)  + 0.5d0*ds_child(n)
+                s_parent(n) = s_parent(n) + 0.5d0*ds_parent(n)
             endif
 !
@@ -727,8 +860,8 @@
 !           No interpolation but only a copy of the values of the grid variable
             lb_parent(n) = lb_child(n)
-            s_child(n)   = 0.
-            s_parent(n)  = 0.
-            ds_child(n)  = 1.
-            ds_parent(n) = 1.
+            s_child(n)   = 0.d0
+            s_parent(n)  = 0.d0
+            ds_child(n)  = 1.d0
+            ds_parent(n) = 1.d0
 !
         end select
@@ -803,4 +936,11 @@
     do i = 1,nbdim
 !
+     if (coords(i) == 0) then
+       nbloc(i) = 1
+       locbounds(i,1,1) = lb_glob(i)
+       locbounds(i,2,1) = ub_glob(i)
+       locbounds(i,1,2) = lb_glob(i)
+       locbounds(i,2,2) = ub_glob(i)
+     else
         call Agrif_InvLoc(lb_var(i), rank, coords(i), i1)
 !
@@ -816,4 +956,5 @@
             endif
         enddo
+     endif
     enddo
 
@@ -825,2 +966,35 @@
 !
 end module Agrif_Arrays
+
+
+subroutine agrif_set_array_cond_reshape(arrayin,arrayout,value,n)
+integer :: n
+real,dimension(n) :: arrayin,arrayout
+real :: value
+
+integer :: i
+
+do i=1,n
+  if (arrayin(i) == value) then
+    arrayout(i) = 0.
+  else
+    arrayout(i) = 1.
+  endif
+enddo
+
+end subroutine agrif_set_array_cond_reshape
+
+subroutine agrif_set_array_tozero_reshape(array,n)
+integer :: n
+real,dimension(n) :: array
+
+integer :: i
+
+!$OMP PARALLEL DO DEFAULT(none) PRIVATE(i) &
+!$OMP SHARED(array,n)
+do i=1,n
+    array(i) = 0.
+enddo
+!$OMP END PARALLEL DO
+
+end subroutine agrif_set_array_tozero_reshape
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modbc.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modbc.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modbc.F90	(revision 10087)
@@ -32,4 +32,5 @@
 !
     implicit none
+    REAL,DIMENSION(:),ALLOCATABLE :: parray_temp
 !
 contains
@@ -61,6 +62,6 @@
     integer, dimension(6)  :: loctab_child      ! Indicates if the child grid has a common border
                                                 !    with the root grid
-    real, dimension(6)     :: s_child, s_parent   ! Positions of the parent and child grids
-    real, dimension(6)     :: ds_child, ds_parent ! Space steps of the parent and child grids
+    real(kind=8), dimension(6)     :: s_child, s_parent   ! Positions of the parent and child grids
+    real(kind=8), dimension(6)     :: ds_child, ds_parent ! Space steps of the parent and child grids
 !
     call PreProcessToInterpOrUpdate( parent,   child,       &
@@ -145,6 +146,6 @@
     INTEGER, DIMENSION(nbdim)   :: posvartab_Child      !< Position of the grid variable (1 or 2)
     INTEGER, DIMENSION(nbdim)   :: loctab_Child         !< Indicates if the child grid has a common border with the root grid
-    REAL   , DIMENSION(nbdim)   :: s_Child,  s_Parent   !< Positions of the parent and child grids
-    REAL   , DIMENSION(nbdim)   :: ds_Child, ds_Parent  !< Space steps of the parent and child grids
+    REAL(kind=8)   , DIMENSION(nbdim)   :: s_Child,  s_Parent   !< Positions of the parent and child grids
+    REAL(kind=8)   , DIMENSION(nbdim)   :: ds_Child, ds_Parent  !< Space steps of the parent and child grids
     INTEGER                             :: nbdim        !< Number of dimensions of the grid variable
     procedure()                         :: procname     !< Data recovery procedure
@@ -159,9 +160,12 @@
     INTEGER,DIMENSION(nbdim,2,2,nbdim)  :: ptres,ptres2 ! calculated
     INTEGER,DIMENSION(nbdim)            :: coords
-    INTEGER                             :: i, nb, ndir
+    INTEGER                             :: i, nb, ndir,j,k,l
     INTEGER                             :: n, sizetab
     INTEGER                             :: ibeg, iend
     INTEGER                             :: i1,i2,j1,j2,k1,k2,l1,l2,m1,m2,n1,n2
     REAL                                :: c1t,c2t      ! Coefficients for the time interpolation (c2t=1-c1t)
+    INTEGER :: isize
+    INTEGER :: kindex_2d(2,nbdim)
+
 #if defined AGRIF_MPI
 !
@@ -188,5 +192,6 @@
     END WHERE
 !
-    call Agrif_get_var_global_bounds(child,lubglob,nbdim)
+!   call Agrif_get_var_global_bounds(child,lubglob,nbdim)
+    lubglob = child%lubglob(1:nbdim,:)
 !
     indtruetab(1:nbdim,1,1) = max(indtab(1:nbdim,1,1), lubglob(1:nbdim,1))
@@ -194,4 +199,5 @@
     indtruetab(1:nbdim,2,1) = min(indtab(1:nbdim,2,1), lubglob(1:nbdim,2))
     indtruetab(1:nbdim,2,2) = min(indtab(1:nbdim,2,2), lubglob(1:nbdim,2))
+	
 !
     do nb = 1,nbdim
@@ -267,4 +273,5 @@
                 if (loctab_child(nb) /= (-ndir) .AND. loctab_child(nb) /= -3) then
 !
+
                     call Agrif_InterpnD(type_interp, parent, child,             &
                                         ptres(1:nbdim,1,ndir,nb),               &
@@ -319,5 +326,6 @@
         do nb = 1,nbdim
             do ndir = 1,2
-                if (loctab_child(nb) /= (-ndir) .AND. loctab_child(nb) /= -3) then
+                kindex_2d(ndir,nb) = kindex
+                if ( (loctab_child(nb) /= (-ndir)) .AND. (loctab_child(nb) /= -3) .AND. child%memberin(nb,ndir) ) then
                     Call timeInterpolation(child,ptres2(:,:,ndir,nb),kindex,c1t,c2t,nbdim)
                 endif
@@ -325,9 +333,19 @@
         enddo
 !
-    endif
-!
     do nb = 1,nbdim
     do ndir = 1,2
         if ( (loctab_child(nb) /= (-ndir)) .AND. (loctab_child(nb) /= -3) .AND. child%memberin(nb,ndir) ) then
+
+         do i=1,nbdim
+         if (ptres2(i,1,ndir,nb) /= child%childarray(i,1,2,nb,ndir)) then
+            print *,'problem ptres2 childarray 1 ',ptres2(i,1,ndir,nb) /= child%childarray(i,1,2,nb,ndir)
+            stop
+         endif
+         if (ptres2(i,2,ndir,nb) /= child%childarray(i,2,2,nb,ndir)) then
+            print *,'problem ptres2 childarray 2 ',ptres2(i,2,ndir,nb) /= child%childarray(i,2,2,nb,ndir)
+          stop
+         endif
+         enddo
+
             select case(nbdim)
             case(1)
@@ -346,4 +364,5 @@
                               i1,i2,j1,j2, .FALSE.,coords(nb),ndir)
             case(3)
+
                 i1 = child % childarray(1,1,2,nb,ndir)
                 i2 = child % childarray(1,2,2,nb,ndir)
@@ -353,6 +372,6 @@
                 k2 = child % childarray(3,2,2,nb,ndir)
 
-                call procname(parray3(i1:i2,j1:j2,k1:k2),                   &
-                              i1,i2,j1,j2,k1,k2, .FALSE.,coords(nb),ndir)
+               call procname(parray_temp(kindex_2d(ndir,nb)),i1,i2,j1,j2,k1,k2, .FALSE.,coords(nb),ndir)
+
             case(4)
                 i1 = child % childarray(1,1,2,nb,ndir)
@@ -365,6 +384,6 @@
                 l2 = child % childarray(4,2,2,nb,ndir)
 
-                call procname(parray4(i1:i2,j1:j2,k1:k2,l1:l2),             &
-                              i1,i2,j1,j2,k1,k2,l1,l2, .FALSE.,coords(nb),ndir)
+                call procname(parray_temp(kindex_2d(ndir,nb)),i1,i2,j1,j2,k1,k2,l1,l2,.FALSE.,coords(nb),ndir)
+
             case(5)
                 i1 = child % childarray(1,1,2,nb,ndir)
@@ -401,4 +420,88 @@
     enddo
     enddo
+
+    else
+
+    do nb = 1,nbdim
+    do ndir = 1,2
+        if ( (loctab_child(nb) /= (-ndir)) .AND. (loctab_child(nb) /= -3) .AND. child%memberin(nb,ndir) ) then
+            select case(nbdim)
+            case(1)
+                i1 = child % childarray(1,1,2,nb,ndir)
+                i2 = child % childarray(1,2,2,nb,ndir)
+
+                call procname(parray1(i1:i2),                               &
+                              i1,i2, .FALSE.,coords(nb),ndir)
+            case(2)
+                i1 = child % childarray(1,1,2,nb,ndir)
+                i2 = child % childarray(1,2,2,nb,ndir)
+                j1 = child % childarray(2,1,2,nb,ndir)
+                j2 = child % childarray(2,2,2,nb,ndir)
+
+                call procname(parray2(i1:i2,j1:j2),                         &
+                              i1,i2,j1,j2, .FALSE.,coords(nb),ndir)
+            case(3)
+
+                i1 = child % childarray(1,1,2,nb,ndir)
+                i2 = child % childarray(1,2,2,nb,ndir)
+                j1 = child % childarray(2,1,2,nb,ndir)
+                j2 = child % childarray(2,2,2,nb,ndir)
+                k1 = child % childarray(3,1,2,nb,ndir)
+                k2 = child % childarray(3,2,2,nb,ndir)
+
+                call procname(parray3(i1:i2,j1:j2,k1:k2),                   &
+                              i1,i2,j1,j2,k1,k2, .FALSE.,coords(nb),ndir)
+
+            case(4)
+                i1 = child % childarray(1,1,2,nb,ndir)
+                i2 = child % childarray(1,2,2,nb,ndir)
+                j1 = child % childarray(2,1,2,nb,ndir)
+                j2 = child % childarray(2,2,2,nb,ndir)
+                k1 = child % childarray(3,1,2,nb,ndir)
+                k2 = child % childarray(3,2,2,nb,ndir)
+                l1 = child % childarray(4,1,2,nb,ndir)
+                l2 = child % childarray(4,2,2,nb,ndir)
+
+                call procname(parray4(i1:i2,j1:j2,k1:k2,l1:l2),             &
+                              i1,i2,j1,j2,k1,k2,l1,l2, .FALSE.,coords(nb),ndir)
+
+            case(5)
+                i1 = child % childarray(1,1,2,nb,ndir)
+                i2 = child % childarray(1,2,2,nb,ndir)
+                j1 = child % childarray(2,1,2,nb,ndir)
+                j2 = child % childarray(2,2,2,nb,ndir)
+                k1 = child % childarray(3,1,2,nb,ndir)
+                k2 = child % childarray(3,2,2,nb,ndir)
+                l1 = child % childarray(4,1,2,nb,ndir)
+                l2 = child % childarray(4,2,2,nb,ndir)
+                m1 = child % childarray(5,1,2,nb,ndir)
+                m2 = child % childarray(5,2,2,nb,ndir)
+
+                call procname(parray5(i1:i2,j1:j2,k1:k2,l1:l2,m1:m2),       &
+                              i1,i2,j1,j2,k1,k2,l1,l2,m1,m2, .FALSE.,coords(nb),ndir)
+            case(6)
+                i1 = child % childarray(1,1,2,nb,ndir)
+                i2 = child % childarray(1,2,2,nb,ndir)
+                j1 = child % childarray(2,1,2,nb,ndir)
+                j2 = child % childarray(2,2,2,nb,ndir)
+                k1 = child % childarray(3,1,2,nb,ndir)
+                k2 = child % childarray(3,2,2,nb,ndir)
+                l1 = child % childarray(4,1,2,nb,ndir)
+                l2 = child % childarray(4,2,2,nb,ndir)
+                m1 = child % childarray(5,1,2,nb,ndir)
+                m2 = child % childarray(5,2,2,nb,ndir)
+                n1 = child % childarray(6,1,2,nb,ndir)
+                n2 = child % childarray(6,2,2,nb,ndir)
+
+                call procname(parray6(i1:i2,j1:j2,k1:k2,l1:l2,m1:m2,n1:n2), &
+                              i1,i2,j1,j2,k1,k2,l1,l2,m1,m2,n1,n2, .FALSE.,coords(nb),ndir)
+            end select
+        endif
+    enddo
+    enddo
+
+    endif
+!
+
 !---------------------------------------------------------------------------------------------------
 end subroutine Agrif_Correctnd
@@ -525,4 +628,27 @@
 !
     INTEGER :: ir,jr,kr,lr,mr,nr
+    INTEGER :: kindexmax, isize,i
+    REAL,DIMENSION(:),ALLOCATABLE :: tabtemp
+
+    isize = 1
+    DO i=1,nbdim
+      isize = isize * (bounds(i,2)-bounds(i,1)+1)
+    ENDDO
+    IF (isize <= 0) RETURN
+
+    kindexmax = kindex + isize - 1
+    IF (.NOT.ALLOCATED(parray_temp)) THEN
+      ALLOCATE(parray_temp(kindexmax)) 
+    ELSE 
+      IF (size(parray_temp) < kindexmax) THEN
+         ALLOCATE(tabtemp(size(parray_temp)))
+         tabtemp = parray_temp
+         DEALLOCATE(parray_temp)
+         ALLOCATE(parray_temp(kindexmax))
+         parray_temp(1:size(tabtemp)) = tabtemp
+         DEALLOCATE(tabtemp)
+      ENDIF
+    ENDIF
+ 
 !
     SELECT CASE (nbdim)
@@ -546,28 +672,14 @@
 !
     CASE (3)
-        do kr = bounds(3,1),bounds(3,2)
-        do jr = bounds(2,1),bounds(2,2)
-!CDIR ALTCODE
-        do ir = bounds(1,1),bounds(1,2)
-            parray3(ir,jr,kr) = c2t*child_var % oldvalues2d(1,kindex) + &
-                                            c1t*child_var % oldvalues2d(2,kindex)
-            kindex = kindex + 1
-        enddo
-        enddo
-        enddo
+
+        parray_temp(kindex:kindexmax) = c2t*child_var % oldvalues2d(1,kindex:kindexmax) + &
+                                        c1t*child_var % oldvalues2d(2,kindex:kindexmax)
+
 !
     CASE (4)
-        do lr = bounds(4,1),bounds(4,2)
-        do kr = bounds(3,1),bounds(3,2)
-        do jr = bounds(2,1),bounds(2,2)
-!CDIR ALTCODE
-        do ir = bounds(1,1),bounds(1,2)
-            parray4(ir,jr,kr,lr) = c2t*child_var % oldvalues2d(1,kindex) + &
-                                               c1t*child_var % oldvalues2d(2,kindex)
-            kindex = kindex + 1
-        enddo
-        enddo
-        enddo
-        enddo
+
+        parray_temp(kindex:kindexmax) = c2t*child_var % oldvalues2d(1,kindex:kindexmax) + &
+                                        c1t*child_var % oldvalues2d(2,kindex:kindexmax)
+
 !
     CASE (5)
@@ -605,4 +717,7 @@
         enddo
     END SELECT
+
+    kindex = kindexmax + 1
+
 !---------------------------------------------------------------------------------------------------
 end subroutine timeInterpolation
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modbcfunction.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modbcfunction.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modbcfunction.F90	(revision 10087)
@@ -21,21 +21,16 @@
 !     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 !
+!---------------------------------------------------------------------------------------------------
 !> Module Agrif_BcFunction.
-!
+!!
+!---------------------------------------------------------------------------------------------------
 module Agrif_BcFunction
 !
 !     Modules used:
 !
-    use Agrif_Boundary
-    use Agrif_Update
-    use Agrif_Save
+  	use Agrif_User_Variables
+
 !
     implicit none
-!
-    interface Agrif_Set_Parent
-        module procedure Agrif_Set_Parent_int,      &
-                         Agrif_Set_Parent_real4,    &
-                         Agrif_Set_Parent_real8
-    end interface
 !
     interface Agrif_Save_Forrestore
@@ -47,202 +42,20 @@
 !
 contains
-!
-!===================================================================================================
-!  subroutine Agrif_Set_parent_int
-!
-!> To set the TYPE of the variable
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Set_parent_int(tabvarsindic,value)
-!---------------------------------------------------------------------------------------------------
-    integer, intent(in)     :: tabvarsindic !< indice of the variable in tabvars
-    integer, intent(in)     :: value        !< input value
-!
-    Agrif_Curgrid % parent % tabvars_i(tabvarsindic) % iarray0 = value
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Set_parent_int
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Set_parent_real4
-!---------------------------------------------------------------------------------------------------
-!> To set the TYPE of the variable
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Set_parent_real4 ( tabvarsindic, value )
-!---------------------------------------------------------------------------------------------------
-    integer, intent(in)     :: tabvarsindic !< indice of the variable in tabvars
-    real(kind=4),intent(in) :: value        !< input value
-!
-    Agrif_Curgrid % parent % tabvars_r(tabvarsindic) % array0 = value
-    Agrif_Curgrid % parent % tabvars_r(tabvarsindic) % sarray0 = value
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Set_parent_real4
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Set_parent_real8
-!---------------------------------------------------------------------------------------------------
-!> To set the TYPE of the variable
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Set_parent_real8 ( tabvarsindic, value )
-!---------------------------------------------------------------------------------------------------
-    integer, intent(in)     :: tabvarsindic !< indice of the variable in tabvars
-    real(kind=8),intent(in) :: value        !< input value
-!
-    Agrif_Curgrid % parent % tabvars_r(tabvarsindic) % darray0 = value
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Set_parent_real8
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Set_bc
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Set_bc ( tabvarsindic, bcinfsup, Interpolationshouldbemade )
-!---------------------------------------------------------------------------------------------------
-    integer,               intent(in)   :: tabvarsindic !< indice of the variable in tabvars
-    integer, dimension(2), intent(in)   :: bcinfsup     !< bcinfsup
-    logical, optional,     intent(in)   :: Interpolationshouldbemade !< interpolation should be made
-!
-    integer                         :: indic ! indice of the variable in tabvars
-    type(Agrif_Variable),  pointer  :: var
-!
-    indic = Agrif_Curgrid % tabvars_i(tabvarsindic) % iarray0
-!
-    if (indic <= 0) then
-        var => Agrif_Search_Variable(Agrif_Curgrid,-indic)
-    else
-        print*,"Agrif_Set_bc : warning indic >= 0 !!!"
-        var => Agrif_Curgrid % tabvars(indic)
-    endif
-
-    if (.not.associated(var)) return ! Grand mother grid case
-!
-    if ( Agrif_Curgrid % fixedrank /= 0 ) then
-        if ( .not.associated(var % oldvalues2D) ) then
-            allocate(var % oldvalues2D(2,1))
-            var % interpIndex = -1
-            var % oldvalues2D = 0.
-        endif
-        if ( present(Interpolationshouldbemade) ) then
-            var % Interpolationshouldbemade = Interpolationshouldbemade
-        endif
-    endif
-!
-    var % bcinf = bcinfsup(1)
-    var % bcsup = bcinfsup(2)
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Set_bc
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Set_interp
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Set_interp ( tabvarsindic, interp, interp1, interp2, interp3 , interp4)
-!---------------------------------------------------------------------------------------------------
-    integer,           intent(in)   :: tabvarsindic !< indice of the variable in tabvars
-    integer, optional, intent(in)   :: interp, interp1, interp2, interp3, interp4
-!
-    integer                         :: indic ! indice of the variable in tabvars
-    type(Agrif_Variable), pointer   :: var
-!
-    indic = Agrif_Curgrid % tabvars_i(tabvarsindic) % iarray0
-!
-    if (indic <= 0) then
-        var => Agrif_Search_Variable(Agrif_Mygrid,-indic)
-    else
-        print*,"Agrif_Set_interp : warning indic >= 0 !!!"
-        var => Agrif_Mygrid % tabvars(indic)
-    endif
-!
-    var % type_interp = Agrif_Constant
-!
-    if (present(interp))    var % type_interp    = interp
-    if (present(interp1))   var % type_interp(1) = interp1
-    if (present(interp2))   var % type_interp(2) = interp2
-    if (present(interp3))   var % type_interp(3) = interp3
-    if (present(interp4))   var % type_interp(4) = interp4
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Set_interp
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Set_bcinterp
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Set_bcinterp ( tabvarsindic, interp,   interp1,  interp2,  interp3, interp4, &
-                                              interp11, interp12, interp21, interp22 )
-!---------------------------------------------------------------------------------------------------
-    INTEGER,           intent(in)   :: tabvarsindic !< indice of the variable in tabvars
-    INTEGER, OPTIONAL, intent(in)   :: interp,   interp1,  interp2,  interp3, interp4
-    INTEGER, OPTIONAL, intent(in)   :: interp11, interp12, interp21, interp22
-!
-    INTEGER                         :: indic ! indice of the variable in tabvars
-    TYPE(Agrif_Variable), pointer   :: var
-!
+
+!===================================================================================================
+!  subroutine Agrif_Set_restore
+!> This subroutine is used to set the index of the current grid variable we want to restore.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_restore ( tabvarsindic )
+!---------------------------------------------------------------------------------------------------
+    INTEGER, intent(in) :: tabvarsindic     !< indice of the variable in tabvars
+!
+    INTEGER :: indic  !  indice of the variable in tabvars
+!
+print *,'CURRENTLY BROKEN'
+STOP
+
     indic = Agrif_Curgrid%tabvars_i(tabvarsindic)%iarray0
 !
-    if (indic <= 0) then
-        var => Agrif_Search_Variable(Agrif_Mygrid,-indic)
-    else
-        print*,"Agrif_Set_bcinterp : warning indic >= 0 !!!"
-        var => Agrif_Mygrid % tabvars(indic)
-    endif
-!
-    var % type_interp_bc = Agrif_Constant
-!
-    if (present(interp))    var % type_interp_bc      = interp
-    if (present(interp1))   var % type_interp_bc(:,1) = interp1
-    if (present(interp11))  var % type_interp_bc(1,1) = interp11
-    if (present(interp12))  var % type_interp_bc(1,2) = interp12
-    if (present(interp2))   var % type_interp_bc(:,2) = interp2
-    if (present(interp21))  var % type_interp_bc(2,1) = interp21
-    if (present(interp22))  var % type_interp_bc(2,2) = interp22
-    if (present(interp3))   var % type_interp_bc(:,3) = interp3
-    if (present(interp4))   var % type_interp_bc(:,4) = interp4
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Set_bcinterp
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Set_UpdateType
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Set_UpdateType ( tabvarsindic, update,  update1, update2, &
-                                                update3, update4, update5 )
-!---------------------------------------------------------------------------------------------------
-    INTEGER,           intent(in) :: tabvarsindic     !< indice of the variable in tabvars
-    INTEGER, OPTIONAL, intent(in) :: update, update1, update2, update3, update4, update5
-!
-    INTEGER                         :: indic ! indice of the variable in tabvars
-    type(Agrif_Variable),  pointer  :: root_var
-!
-    indic = Agrif_Curgrid%tabvars_i(tabvarsindic)%iarray0
-!
-    if (indic <= 0) then
-        root_var => Agrif_Search_Variable(Agrif_Mygrid,-indic)
-    else
-        print*,"Agrif_Set_UpdateType : warning indic >= 0 !!!"
-        root_var => Agrif_Mygrid % tabvars(indic)
-    endif
-!
-    root_var % type_update = Agrif_Update_Copy
-    if (present(update))    root_var % type_update    = update
-    if (present(update1))   root_var % type_update(1) = update1
-    if (present(update2))   root_var % type_update(2) = update2
-    if (present(update3))   root_var % type_update(3) = update3
-    if (present(update4))   root_var % type_update(4) = update4
-    if (present(update5))   root_var % type_update(5) = update5
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Set_UpdateType
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Set_restore
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Set_restore ( tabvarsindic )
-!---------------------------------------------------------------------------------------------------
-    INTEGER, intent(in) :: tabvarsindic     !< indice of the variable in tabvars
-!
-    INTEGER :: indic  !  indice of the variable in tabvars
-!
-    indic = Agrif_Curgrid%tabvars_i(tabvarsindic)%iarray0
-!
     Agrif_Mygrid%tabvars(indic) % restore = .TRUE.
 !---------------------------------------------------------------------------------------------------
@@ -251,304 +64,17 @@
 !
 !===================================================================================================
-!  subroutine Agrif_Init_variable
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Init_variable ( tabvarsindic, procname )
-!---------------------------------------------------------------------------------------------------
-    INTEGER, intent(in)  :: tabvarsindic     !< indice of the variable in tabvars
-    procedure()          :: procname         !< Data recovery procedure
-!
-    if ( Agrif_Curgrid%level <= 0 ) return
-!
-    call Agrif_Interp_variable(tabvarsindic, procname)
-    call Agrif_Bc_variable(tabvarsindic, procname, 1.)
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Init_variable
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Bc_variable
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Bc_variable ( tabvarsindic, procname, calledweight )
-!---------------------------------------------------------------------------------------------------
-    integer,        intent(in) :: tabvarsindic     !< indice of the variable in tabvars
-    procedure()                :: procname
-    real, optional, intent(in) :: calledweight
-!
-    real    :: weight
-    logical :: pweight
-    integer :: indic
-    integer :: nbdim
-    type(Agrif_Variable), pointer :: root_var
-    type(Agrif_Variable), pointer :: parent_var
-    type(Agrif_Variable), pointer :: child_var
-    type(Agrif_Variable), pointer :: child_tmp      ! Temporary variable on the child grid
-!
-    if ( Agrif_Curgrid%level <= 0 ) return
-!
-    indic = Agrif_Curgrid%tabvars_i(tabvarsindic)%iarray0
-!
-    if ( present(calledweight) ) then
-        weight  = calledweight
-        pweight = .true.
-    else
-        weight  = 0.
-        pweight = .false.
-    endif
-!
-    if (indic <= 0) then
-        child_var  => Agrif_Search_Variable(Agrif_Curgrid,-indic)
-        parent_var => child_var % parent_var
-        root_var   => child_var % root_var
-    else
-        print*,"Agrif_Bc_variable : warning indic >= 0 !!!"
-        child_var  => Agrif_Curgrid % tabvars(indic)
-        parent_var => Agrif_Curgrid % parent % tabvars(indic)
-        root_var   => Agrif_Mygrid % tabvars(indic)
-    endif
-!
-    nbdim = root_var % nbdim
-!
-    select case( nbdim )
-    case(1)
-        allocate(parray1(child_var%lb(1):child_var%ub(1)))
-    case(2)
-        allocate(parray2(child_var%lb(1):child_var%ub(1), &
-                         child_var%lb(2):child_var%ub(2) ))
-    case(3)
-        allocate(parray3(child_var%lb(1):child_var%ub(1), &
-                         child_var%lb(2):child_var%ub(2), &
-                         child_var%lb(3):child_var%ub(3) ))
-    case(4)
-        allocate(parray4(child_var%lb(1):child_var%ub(1), &
-                         child_var%lb(2):child_var%ub(2), &
-                         child_var%lb(3):child_var%ub(3), &
-                         child_var%lb(4):child_var%ub(4) ))
-    case(5)
-        allocate(parray5(child_var%lb(1):child_var%ub(1), &
-                         child_var%lb(2):child_var%ub(2), &
-                         child_var%lb(3):child_var%ub(3), &
-                         child_var%lb(4):child_var%ub(4), &
-                         child_var%lb(5):child_var%ub(5) ))
-    case(6)
-        allocate(parray6(child_var%lb(1):child_var%ub(1), &
-                         child_var%lb(2):child_var%ub(2), &
-                         child_var%lb(3):child_var%ub(3), &
-                         child_var%lb(4):child_var%ub(4), &
-                         child_var%lb(5):child_var%ub(5), &
-                         child_var%lb(6):child_var%ub(6) ))
-    end select
-!
-!   Create temporary child variable
-    allocate(child_tmp)
-!
-    child_tmp % root_var => root_var
-    child_tmp % oldvalues2D => child_var % oldvalues2D
-!
-!   Index indicating if a space interpolation is necessary
-    child_tmp % interpIndex =  child_var % interpIndex
-    child_tmp % list_interp => child_var % list_interp
-    child_tmp % Interpolationshouldbemade = child_var % Interpolationshouldbemade
-!
-    child_tmp % point = child_var % point
-    child_tmp % lb = child_var % lb
-    child_tmp % ub = child_var % ub
-!
-    child_tmp % bcinf = child_var % bcinf
-    child_tmp % bcsup = child_var % bcsup
-!
-    child_tmp % childarray = child_var % childarray
-    child_tmp % memberin   = child_var % memberin
-!
-    call Agrif_CorrectVariable(parent_var, child_tmp, pweight, weight, procname)
-!
-    child_var % childarray = child_tmp % childarray
-    child_var % memberin   = child_tmp % memberin
-!
-    child_var % oldvalues2D => child_tmp % oldvalues2D
-    child_var % list_interp => child_tmp % list_interp
-!
-    child_var % interpIndex = child_tmp % interpIndex
-!
-    deallocate(child_tmp)
-!
-    select case( nbdim )
-        case(1); deallocate(parray1)
-        case(2); deallocate(parray2)
-        case(3); deallocate(parray3)
-        case(4); deallocate(parray4)
-        case(5); deallocate(parray5)
-        case(6); deallocate(parray6)
-    end select
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Bc_variable
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Interp_variable
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Interp_variable ( tabvarsindic, procname )
-!---------------------------------------------------------------------------------------------------
-    integer,     intent(in)     :: tabvarsindic     !< indice of the variable in tabvars
-    procedure()                 :: procname         !< Data recovery procedure
-!
-    integer :: nbdim
-    integer :: indic  ! indice of the variable in tabvars
-    logical :: torestore
-    type(Agrif_Variable), pointer   :: root_var
-    type(Agrif_Variable), pointer   :: parent_var       ! Variable on the parent grid
-    type(Agrif_Variable), pointer   :: child_var        ! Variable on the parent grid
-    type(Agrif_Variable), pointer   :: child_tmp        ! Temporary variable on the child grid
-!
-    if ( Agrif_Curgrid%level <= 0 ) return
-!
-    indic = Agrif_Curgrid%tabvars_i(tabvarsindic)%iarray0
-!
-    if (indic <= 0) then
-        child_var  => Agrif_Search_Variable(Agrif_Curgrid,-indic)
-        parent_var => child_var % parent_var
-        root_var   => child_var % root_var
-    else
-        print*,"Agrif_Interp_variable : warning indic >= 0 !!!"
-        child_var  => Agrif_Curgrid % tabvars(indic)
-        parent_var => Agrif_Curgrid % parent % tabvars(indic)
-        root_var   => Agrif_Mygrid % tabvars(indic)
-    endif
-!
-    nbdim     = root_var % nbdim
-    torestore = root_var % restore
-!
-    allocate(child_tmp)
-!
-    child_tmp % root_var => root_var
-    child_tmp % nbdim = root_var % nbdim
-    child_tmp % point = child_var % point
-    child_tmp % lb = child_var % lb
-    child_tmp % ub = child_var % ub
-    child_tmp % interpIndex =  child_var % interpIndex
-    child_tmp % list_interp => child_var % list_interp
-    child_tmp % Interpolationshouldbemade = child_var % Interpolationshouldbemade
-!
-    if ( torestore ) then
-        select case( nbdim )
-        case(1)
-            parray1 = child_var % array1
-            child_tmp % restore1D => child_var % restore1D
-        case(2)
-            parray2 = child_var % array2
-            child_tmp % restore2D => child_var % restore2D
-        case(3)
-            parray3 = child_var % array3
-            child_tmp % restore3D => child_var % restore3D
-        case(4)
-            parray4 = child_var % array4
-            child_tmp % restore4D => child_var % restore4D
-        case(5)
-            parray5 = child_var % array5
-            child_tmp % restore5D => child_var % restore5D
-        case(6)
-            parray6 = child_var % array6
-            child_tmp % restore6D => child_var % restore6D
-        end select
-    endif
-!
-    call Agrif_InterpVariable(parent_var, child_tmp, torestore, procname)
-!
-    child_var % list_interp => child_tmp % list_interp
-!
-    deallocate(child_tmp)
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Interp_variable
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Update_Variable
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Update_Variable ( tabvarsindic, procname, &
-                                   locupdate, locupdate1, locupdate2, locupdate3, locupdate4 )
-!---------------------------------------------------------------------------------------------------
-    integer,               intent(in)           :: tabvarsindic     !< Indice of the variable in tabvars
-    procedure()                                 :: procname         !< Data recovery procedure
-    integer, dimension(2), intent(in), optional :: locupdate
-    integer, dimension(2), intent(in), optional :: locupdate1
-    integer, dimension(2), intent(in), optional :: locupdate2
-    integer, dimension(2), intent(in), optional :: locupdate3
-    integer, dimension(2), intent(in), optional :: locupdate4
-!---------------------------------------------------------------------------------------------------
-    integer :: indic
-    integer :: nbdim
-    integer, dimension(6)           :: updateinf    ! First positions where interpolations are calculated
-    integer, dimension(6)           :: updatesup    ! Last  positions where interpolations are calculated
-    type(Agrif_Variable), pointer   :: root_var
-    type(Agrif_Variable), pointer   :: parent_var
-    type(Agrif_Variable), pointer   :: child_var
-!
-    if ( Agrif_Root() .AND. (.not.agrif_coarse) ) return
-    if (agrif_curgrid%grand_mother_grid) return
-!
-    indic = Agrif_Curgrid%tabvars_i(tabvarsindic)%iarray0
-!
-    if (indic <= 0) then
-        child_var  => Agrif_Search_Variable(Agrif_Curgrid, -indic)
-        parent_var => child_var % parent_var
-
-        if (.not.associated(parent_var)) then
-          ! can occur during the first update of Agrif_Coarsegrid (if any)
-          parent_var => Agrif_Search_Variable(Agrif_Curgrid % parent, -indic)
-          child_var % parent_var => parent_var
-        endif
-
-        root_var   => child_var % root_var
-    else
-        print*,"Agrif_Update_Variable : warning indic >= 0 !!!"
-        root_var   => Agrif_Mygrid  % tabvars(indic)
-        child_var  => Agrif_Curgrid % tabvars(indic)
-        parent_var => Agrif_Curgrid % parent % tabvars(indic)
-    endif
-!
-    nbdim = root_var % nbdim
-!
-    updateinf = -99
-    updatesup = -99
-!
-    if ( present(locupdate) ) then
-        updateinf(1:nbdim) = locupdate(1)
-        updatesup(1:nbdim) = locupdate(2)
-    endif
-!
-    if ( present(locupdate1) ) then
-        updateinf(1) = locupdate1(1)
-        updatesup(1) = locupdate1(2)
-    endif
-!
-    if ( present(locupdate2) ) then
-        updateinf(2) = locupdate2(1)
-        updatesup(2) = locupdate2(2)
-    endif
-
-    if ( present(locupdate3) ) then
-        updateinf(3) = locupdate3(1)
-        updatesup(3) = locupdate3(2)
-    endif
-
-    if ( present(locupdate4) ) then
-        updateinf(4) = locupdate4(1)
-        updatesup(4) = locupdate4(2)
-    endif
-!
-    call Agrif_UpdateVariable( parent_var, child_var, updateinf, updatesup, procname )
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Update_Variable
-!===================================================================================================
-!
-!===================================================================================================
 !  subroutine Agrif_Save_ForRestore0D
 !---------------------------------------------------------------------------------------------------
 subroutine Agrif_Save_ForRestore0D ( tabvarsindic0, tabvarsindic )
 !---------------------------------------------------------------------------------------------------
-    integer, intent(in) :: tabvarsindic0, tabvarsindic
+    integer, intent(in) :: tabvarsindic0 !< index of the current grid variable 
+    integer, intent(in) :: tabvarsindic  !< index of the varible which should be restored
+    
 !
     type(Agrif_Variable), pointer   :: root_var, save_var
     integer :: nbdim
 !
+print *,'CURRENTLY BROKEN'
+STOP
     root_var => Agrif_Mygrid % tabvars(tabvarsindic0)
     save_var => Agrif_Curgrid % tabvars(tabvarsindic0)
@@ -566,13 +92,17 @@
 !===================================================================================================
 !  subroutine Agrif_Save_ForRestore2D
+!> This function is used to restore a current grid variable (with the index tabvarsindic) to the input 2D-variable.
 !---------------------------------------------------------------------------------------------------
 subroutine Agrif_Save_ForRestore2D ( q, tabvarsindic )
 !---------------------------------------------------------------------------------------------------
-    real, dimension(:,:), intent(in)        :: q
-    integer,              intent(in)        :: tabvarsindic
+!
+real, dimension(:,:), intent(in) :: q            !< input 2D-variable which should be saved
+integer, 			  intent(in) :: tabvarsindic !< index of the current grid variable we want to restore
 !
     type(Agrif_Variable),  pointer  :: root_var, save_var
     integer                         :: indic
 !
+print *,'CURRENTLY BROKEN'
+STOP
     indic = tabvarsindic
     if (tabvarsindic >= 0) then
@@ -603,13 +133,18 @@
 !===================================================================================================
 !  subroutine Agrif_Save_ForRestore3D
+!> This function is used to restore a current grid variable (with the index tabvarsindic) to the input 3D-variable.
 !---------------------------------------------------------------------------------------------------
 subroutine Agrif_Save_ForRestore3D ( q, tabvarsindic )
 !---------------------------------------------------------------------------------------------------
-    real, dimension(:,:,:), intent(in)      :: q
-    integer,                intent(in)      :: tabvarsindic
+!
+real, dimension(:,:,:), intent(in) :: q !< input 3D-variable which should be saved
+integer, intent(in) :: tabvarsindic 	!< index of the current grid variable we want to restore
 !
     type(Agrif_Variable),  pointer  :: root_var, save_var
     integer                         :: indic
 !
+print *,'CURRENTLY BROKEN'
+STOP
+
     indic = tabvarsindic
     if (tabvarsindic >= 0) then
@@ -641,13 +176,18 @@
 !===================================================================================================
 !  subroutine Agrif_Save_ForRestore4D
+!> This function is used to restore a current grid variable (with the index tabvarsindic) to the input 4D-variable.
 !---------------------------------------------------------------------------------------------------
 subroutine Agrif_Save_ForRestore4D ( q, tabvarsindic )
 !---------------------------------------------------------------------------------------------------
-    real, dimension(:,:,:,:), intent(in)    :: q
-    integer,                  intent(in)    :: tabvarsindic
+!
+real, dimension(:,:,:,:), intent(in) :: q !< input 4D-variable which should be saved
+integer, intent(in) :: tabvarsindic 	  !< index of the current grid variable we want to restore
+!
 !
     type(Agrif_Variable),  pointer  :: root_var, save_var
     integer                         :: indic
 !
+print *,'CURRENTLY BROKEN'
+STOP
     indic = tabvarsindic
     if (tabvarsindic >= 0) then
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modcluster.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modcluster.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modcluster.F90	(revision 10087)
@@ -29,7 +29,10 @@
 module Agrif_Clustering
 !
-    use Agrif_CurgridFunctions
+    !use Agrif_CurgridFunctions
+    !use Agrif_Init_Vars
+    !use Agrif_Save
     use Agrif_Init_Vars
     use Agrif_Save
+    use Agrif_Init
 !
     implicit none
@@ -54,5 +57,5 @@
     TYPE(Agrif_LRectangle), pointer  :: parcours
     TYPE(Agrif_Grid)      , pointer  :: newgrid
-    REAL                             :: g_eps
+    REAL(kind=8)                     :: g_eps
     INTEGER                          :: i
 !
@@ -131,8 +134,8 @@
     TYPE(Agrif_PGrid), pointer  :: parcours
 !
-    REAL                  :: g_eps, newgrid_eps, eps
-    REAL   , DIMENSION(3) :: newmin, newmax
-    REAL   , DIMENSION(3) :: gmin, gmax
-    REAL   , DIMENSION(3) :: xmin
+    REAL(kind=8)                  :: g_eps, newgrid_eps, eps
+    REAL(kind=8)   , DIMENSION(3) :: newmin, newmax
+    REAL(kind=8)   , DIMENSION(3) :: gmin, gmax
+    REAL(kind=8)   , DIMENSION(3) :: xmin
     INTEGER, DIMENSION(3) :: igmin, inewmin
     INTEGER, DIMENSION(3) :: inewmax
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modcurgridfunctions.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modcurgridfunctions.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modcurgridfunctions.F90	(revision 10087)
@@ -92,4 +92,5 @@
 !
     rhot = float(Agrif_IRhot())
+    
 !---------------------------------------------------------------------------------------------------
 end function Agrif_Rhot
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modflux.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modflux.F90	(revision 10087)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modflux.F90	(revision 10087)
@@ -0,0 +1,26 @@
+!     Agrif (Adaptive Grid Refinement In Fortran)
+!
+!     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+!                        Christophe Vouland (Christophe.Vouland@imag.fr)
+!
+!     This program is free software; you can redistribute it and/or modify
+!     it under the terms of the GNU General Public License as published by
+!     the Free Software Foundation; either version 2 of the License, or
+!     (at your option) any later version.
+!
+!     This program is distributed in the hope that it will be useful,
+!     but WITHOUT ANY WARRANTY; without even the implied warranty of
+!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+!     GNU General Public License for more details.
+!
+!     You should have received a copy of the GNU General Public License
+!     along with this program; if not, write to the Free Software
+!     Foundation, Inc., 59 Temple Place-Suite 330, Boston, MA 02111-1307, USA.
+!
+!
+module Agrif_FluxMod
+    Use Agrif_Types
+    Use Agrif_Arrays
+    Use Agrif_CurgridFunctions
+
+End Module Agrif_FluxMod
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modgrids.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modgrids.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modgrids.F90	(revision 10087)
@@ -44,7 +44,7 @@
     type(Agrif_Variable_i), dimension(:), allocatable :: tabvars_i  !< List of integer   grid variables
 !
-    real   , dimension(3)              :: Agrif_x   !< global x, y and z position
-    real   , dimension(3)              :: Agrif_dx  !< global space step in the x, y and z direction
-    real   , dimension(3)              :: Agrif_dt  !< global time  step in the x, y and z direction
+    real(kind=8), dimension(3)         :: Agrif_x   !< global x, y and z position
+    real(kind=8)   , dimension(3)      :: Agrif_dx  !< global space step in the x, y and z direction
+    real, dimension(3)                 :: Agrif_dt  !< global time  step in the x, y and z direction
     integer, dimension(3)              :: nb        !< number of cells in the x, y and z direction
     integer, dimension(3)              :: ix        !< minimal position in the x, y and z direction
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modinit.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modinit.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modinit.F90	(revision 10087)
@@ -31,7 +31,26 @@
 !
     implicit none
+
+    abstract interface
+        subroutine step_proc()
+        end subroutine step_proc
+    end interface
+    
 !
 contains
 !
+
+
+subroutine Agrif_call_procname ( procname )
+    procedure(step_proc)  :: procname
+    call procname()
+end subroutine  Agrif_call_procname
+!===================================================================================================
+
+subroutine Agrif_call_procname1 ( procname1 )
+    procedure(typedef_proc) :: procname1 
+    call procname1()
+end subroutine  Agrif_call_procname1
+
 !===================================================================================================
 !  subroutine Agrif_Allocation
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modinterp.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modinterp.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modinterp.F90	(revision 10087)
@@ -26,11 +26,14 @@
 module Agrif_Interpolation
 !
-    use Agrif_InterpBasic
-    use Agrif_Arrays
-    use Agrif_Mask
-    use Agrif_CurgridFunctions
+  use Agrif_Init
+  use Agrif_Arrays
+  use Agrif_InterpBasic
+  use Agrif_User_Functions
+
 #if defined AGRIF_MPI
     use Agrif_Mpp
 #endif
+  
+    use Agrif_Mask
 !
     implicit none
@@ -66,6 +69,6 @@
     integer, dimension(6) :: ub_child
     integer, dimension(6) :: lb_parent
-    real   , dimension(6) :: s_child,   s_parent
-    real   , dimension(6) :: ds_child, ds_parent
+    real(kind=8)   , dimension(6) :: s_child,   s_parent
+    real(kind=8)   , dimension(6) :: ds_child, ds_parent
     integer, dimension(child % root_var % nbdim,2,2) :: childarray
 !
@@ -115,6 +118,6 @@
     INTEGER, DIMENSION(nbdim), INTENT(in)   :: pttab_Parent !< Index of the first point inside the domain
                                                             !<    for the parent grid variable
-    REAL,    DIMENSION(nbdim), INTENT(in)   :: s_Child,s_Parent   !< Positions of the parent and child grids
-    REAL,    DIMENSION(nbdim), INTENT(in)   :: ds_Child,ds_Parent !< Space steps of the parent and child grids
+    REAL(kind=8),    DIMENSION(nbdim), INTENT(in)   :: s_Child,s_Parent   !< Positions of the parent and child grids
+    REAL(kind=8),    DIMENSION(nbdim), INTENT(in)   :: ds_Child,ds_Parent !< Space steps of the parent and child grids
     TYPE(Agrif_Variable),      pointer      :: restore            !< Indicates points where interpolation
     LOGICAL,                   INTENT(in)   :: torestore          !< Indicates if the array restore is used
@@ -128,11 +131,12 @@
     INTEGER                       :: i,j,k,l,m,n
     INTEGER, DIMENSION(nbdim)     :: pttruetab,cetruetab
-    INTEGER, DIMENSION(nbdim)     :: indmin,     indmax
+    INTEGER, DIMENSION(nbdim)     :: indmin,     indmax, indmin_required_p, indmax_required_p
     INTEGER, DIMENSION(nbdim)     :: indminglob, indmaxglob
 #if defined AGRIF_MPI
     INTEGER, DIMENSION(nbdim)     :: indminglob2,indmaxglob2
+    INTEGER, DIMENSION(nbdim)     :: indminglob3,indmaxglob3
 #endif
     LOGICAL, DIMENSION(nbdim)     :: noraftab
-    REAL   , DIMENSION(nbdim)     :: s_Child_temp,s_Parent_temp
+    REAL(kind=8)   , DIMENSION(nbdim)     :: s_Child_temp,s_Parent_temp,s_Parent_temp_p
     INTEGER, DIMENSION(nbdim)     :: lowerbound, upperbound, coords
     INTEGER, DIMENSION(nbdim,2,2), INTENT(OUT) :: childarray
@@ -148,4 +152,7 @@
     INTEGER, DIMENSION(nbdim,4,0:Agrif_Nbprocs-1)   :: tab4
     INTEGER, DIMENSION(nbdim,0:Agrif_Nbprocs-1,8)   :: tab4t
+    INTEGER,DIMENSION(nbdim,2) :: tab5
+    INTEGER,DIMENSION(nbdim,2,0:Agrif_Nbprocs-1) :: tab6
+    INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1,2) :: tab5t
     LOGICAL, DIMENSION(0:Agrif_Nbprocs-1)           :: memberinall
     LOGICAL, DIMENSION(0:Agrif_Nbprocs-1)           :: sendtoproc1, recvfromproc1
@@ -167,5 +174,6 @@
             child % list_interp,                                    &
             pttab, petab, pttab_Child, pttab_Parent, nbdim,         &
-            indmin, indmax, indminglob, indmaxglob,                 &
+            indmin, indmax, indmin_required_p, indmax_required_p,   &
+            indminglob, indmaxglob,                                 &
             pttruetab, cetruetab, memberin                          &
 #if defined AGRIF_MPI
@@ -174,12 +182,26 @@
 #endif
         )
+
 !
     if (.not.find_list_interp) then
 !
+! output : lowerbound and upperbound are the (local) lower and upper bounds of the child arrays
+
         call Agrif_get_var_bounds_array(child, lowerbound, upperbound, nbdim)
+
+! input : pttab, petab : global indexes where the interpolation is required
+! output : pttruetab, cetruetab : global indexes restricted to the bounds of the current processor 
+! output : memberin is false if the current processor is not involved in the interpolation
+
         call Agrif_Childbounds(nbdim, lowerbound, upperbound,               &
                                pttab, petab, Agrif_Procrank, coords,        &
                                pttruetab, cetruetab, memberin)
+			
+
+
+! output : indminglob, indmaxglob : global indexes required on the parent grid for the interpolation
+! output : s_Parent_temp, s_Child_temp : local s_Parent, s_Child relatively to indmin ou pttab
         call Agrif_Parentbounds(type_interp,nbdim,indminglob,indmaxglob,    &
+                                indmin_required_p, indmax_required_p,           &
                                 s_Parent_temp,s_Child_temp,                 &
                                 s_Child,ds_Child,                           &
@@ -190,5 +212,9 @@
 #if defined AGRIF_MPI
         if (memberin) then
+
+! output : indmin, indmax : global indexes required on the parent grid for the interpolation on the current processor (i.e. on pttruetab, cetruetab)
+! output : s_Parent_temp, s_Child_temp : local s_Parent, s_Child relatively to indmin ou pttruetab
             call Agrif_Parentbounds(type_interp,nbdim,indmin,indmax,        &
+                                    indmin_required_p, indmax_required_p,       &
                                     s_Parent_temp,s_Child_temp,             &
                                     s_Child,ds_Child,                       &
@@ -200,12 +226,26 @@
 
         local_proc = Agrif_Procrank
+
+! output : lowerbound and upperbound are the (local) lower and upper bounds of the parent arrays
         call Agrif_get_var_bounds_array(parent,lowerbound,upperbound,nbdim)
         call Agrif_ChildGrid_to_ParentGrid()
-!
+
+! input : indminglob,indmaxglob : global indexes where data are required for the interpolation
+! output : indminglob2,indmaxglob2 : global indexes restricted to the bounds of the current processor 
+! output : member is false if the current processor does not need to send data
+! output : indminglob3,indmaxglob3 : global bounds on the current processor for the parent array
+
         call Agrif_Childbounds(nbdim,lowerbound,upperbound,                 &
                                indminglob,indmaxglob, local_proc, coords,   &
-                               indminglob2,indmaxglob2,member)
+                               indminglob2,indmaxglob2,member,              &
+                               indminglob3,indmaxglob3)
 !
         if (member) then
+
+! output : parentarray
+! output : parentarray (:,:,2) : indminglob2, indmaxglob2 in term of local indexes on current processor
+! output : parentarray (:,:,1) : indminglob2, indmaxglob2 restricted to the current processor (different from indminglob2 ???)
+! output : member is .false. is the current processor has not data to send
+
             call Agrif_GlobalToLocalBounds(parentarray,                     &
                                            lowerbound,  upperbound,         &
@@ -216,12 +256,48 @@
         call Agrif_ParentGrid_to_ChildGrid()
 #else
+
+! In the sequentiel case, the following lines ensure that the bounds needed on the parent grid in the interpolation 
+! do not exceed lower and upper bounds of the parent array
+
+! output : lowerbound and upperbound are the (local) lower and upper bounds of the parent arrays
+        call Agrif_get_var_bounds_array(parent,lowerbound,upperbound,nbdim)
+        call Agrif_ChildGrid_to_ParentGrid()
+
+! input : indminglob,indmaxglob : global indexes where data are required for the interpolation
+! output : indminglob2,indmaxglob2 : global indexes restricted to the bounds of the current processor 
+! output : member is false if the current processor does not need to send data
+
+        call Agrif_Childbounds(nbdim,lowerbound,upperbound,                 &
+                               indminglob,indmaxglob, Agrif_Procrank, coords,   &
+                               indmin,indmax,member)
+
+        call Agrif_ParentGrid_to_ChildGrid()
+
+        indminglob = indmin
+        indmaxglob = indmax
+
         parentarray(:,1,1) = indminglob
         parentarray(:,2,1) = indmaxglob
         parentarray(:,1,2) = indminglob
         parentarray(:,2,2) = indmaxglob
-        indmin = indminglob
-        indmax = indmaxglob
+ 
+!       indmin = indminglob
+!        indmax = indmaxglob
+
         member = .TRUE.
+        s_Parent_temp = s_Parent + (indminglob - pttab_Parent) * ds_Parent
+
 #endif
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Correct for non refined directions
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        do i=1,nbdim
+          if (coords(i) == 0) then
+             indmin(i) = indminglob(i)
+             indmax(i) = indmaxglob(i)
+             pttruetab(i) = indminglob(i)
+             cetruetab(i) = indmaxglob(i)
+          endif
+        enddo
 
     else
@@ -231,10 +307,31 @@
         s_Child_temp  = s_Child + (pttruetab - pttab_Child) * ds_Child
 #else
+
+! In the sequentiel case, the following lines ensure that the bounds needed on the parent grid in the interpolation 
+! do not exceed lower and upper bounds of the parent array
+
+! output : lowerbound and upperbound are the (local) lower and upper bounds of the parent arrays
+        call Agrif_get_var_bounds_array(parent,lowerbound,upperbound,nbdim)
+        call Agrif_ChildGrid_to_ParentGrid()
+
+! input : indminglob,indmaxglob : global indexes where data are required for the interpolation
+! output : indminglob2,indmaxglob2 : global indexes restricted to the bounds of the current processor 
+! output : member is false if the current processor does not need to send data
+
+        call Agrif_Childbounds(nbdim,lowerbound,upperbound,                 &
+                               indminglob,indmaxglob, Agrif_Procrank, coords,   &
+                               indmin,indmax,member)
+
+        call Agrif_ParentGrid_to_ChildGrid()
+
+        indminglob = indmin
+        indmaxglob = indmax
+
         parentarray(:,1,1) = indminglob
         parentarray(:,2,1) = indmaxglob
         parentarray(:,1,2) = indminglob
         parentarray(:,2,2) = indmaxglob
-        indmin = indminglob
-        indmax = indmaxglob
+ !       indmin = indminglob
+ !       indmax = indmaxglob
         member = .TRUE.
         s_Parent_temp = s_Parent + (indminglob - pttab_Parent) * ds_Parent
@@ -246,4 +343,5 @@
         if (.not.associated(tempP)) allocate(tempP)
 !
+
         call Agrif_array_allocate(tempP,parentarray(:,1,1),parentarray(:,2,1),nbdim)
         call Agrif_var_set_array_tozero(tempP,nbdim)
@@ -286,4 +384,5 @@
                       parentarray(6,1,2),parentarray(6,2,2),.TRUE.,nb,ndir)
         end select
+
 !
         call Agrif_ParentGrid_to_ChildGrid()
@@ -298,7 +397,9 @@
         tab3(:,3) = indmin(:)
         tab3(:,4) = indmax(:)
+        tab5(:,1) = indminglob3(:)
+        tab5(:,2) = indmaxglob3(:)
 !
         call MPI_ALLGATHER(tab3,4*nbdim,MPI_INTEGER,tab4,4*nbdim,MPI_INTEGER,Agrif_mpi_comm,code)
-
+        call MPI_ALLGATHER(tab5,2*nbdim,MPI_INTEGER,tab6,2*nbdim,MPI_INTEGER,Agrif_mpi_comm,code)
         if (.not.associated(tempPextend))   allocate(tempPextend)
 
@@ -311,4 +412,12 @@
         enddo
 
+        do k=0,Agrif_Nbprocs-1
+          do j=1,2
+            do i=1,nbdim
+               tab5t(i,k,j) = tab6(i,j,k)
+            enddo
+          enddo
+        enddo
+      
         memberin1(1) = memberin
         call MPI_ALLGATHER(memberin1,1,MPI_LOGICAL,memberinall,1,MPI_LOGICAL,Agrif_mpi_comm,code)
@@ -319,5 +428,6 @@
                                      sendtoproc1,recvfromproc1,         &
                                      tab4t(:,:,5),tab4t(:,:,6),         &
-                                     tab4t(:,:,7),tab4t(:,:,8) )
+                                     tab4t(:,:,7),tab4t(:,:,8),         &
+                                     tab5t(:,:,1),tab5t(:,:,2))
     endif
 
@@ -333,4 +443,5 @@
                 child%list_interp,pttab,petab,                  &
                 pttab_Child,pttab_Parent,indmin,indmax,         &
+                indmin_required_p, indmax_required_p,           &
                 indminglob,indmaxglob,                          &
                 pttruetab,cetruetab,                            &
@@ -345,9 +456,12 @@
     endif
 !
+
     if (memberin) then
 !
         if (.not.associated(tempC)) allocate(tempC)
 !
+
         call Agrif_array_allocate(tempC,pttruetab,cetruetab,nbdim)
+
 !
 !       Special values on the parent grid
@@ -357,11 +471,13 @@
 !
             if (.not.associated(parentvalues))  allocate(parentvalues)
-!
+!t
+
             call Agrif_array_allocate(parentvalues,indmin,indmax,nbdim)
             call Agrif_var_full_copy_array(parentvalues,tempPextend,nbdim)
 !
-            call Agrif_CheckMasknD(tempPextend,parentvalues,    &
-                    indmin(1:nbdim),indmax(1:nbdim),            &
-                    indmin(1:nbdim),indmax(1:nbdim),            &
+            call Agrif_CheckMasknD(tempPextend,parentvalues,                &
+                    indmin(1:nbdim),indmax(1:nbdim),                        &
+                    indmin(1:nbdim),indmax(1:nbdim),                        &
+                    indmin_required_p(1:nbdim),indmax_required_p(1:nbdim),  &
                     noraftab(1:nbdim),nbdim)
 !
@@ -391,18 +507,28 @@
                                                 ds_Child(1:2),    ds_Parent(1:2) )
             case(3)
-                call Agrif_Interp_3D_recursive( type_interp(1:3),                       &
-                                                tempPextend % array3,                   &
-                                                tempC       % array3,                   &
-                                                indmin(1:3), indmax(1:3),               &
-                                                pttruetab(1:3),    cetruetab(1:3),      &
-                                                s_Child_temp(1:3), s_Parent_temp(1:3),  &
+                s_Parent_temp_p = s_Parent + (indmin_required_p - pttab_Parent) * ds_Parent
+                call Agrif_Interp_3D_recursive( type_interp(1:3),                                 &
+                                                tempPextend % array3(                             &
+                                                indmin_required_p(1):indmax_required_p(1),        &
+                                                indmin_required_p(2):indmax_required_p(2),        &
+                                                indmin_required_p(3):indmax_required_p(3)),       &
+                                                tempC       % array3,                             &
+                                                indmin_required_p(1:3), indmax_required_p(1:3),   &
+                                                pttruetab(1:3),    cetruetab(1:3),                &
+                                                s_Child_temp(1:3), s_Parent_temp_p(1:3),          &
                                                 ds_Child(1:3),    ds_Parent(1:3) )
+
             case(4)
-                call Agrif_Interp_4D_recursive( type_interp(1:4),                       &
-                                                tempPextend % array4,                   &
-                                                tempC       % array4,                   &
-                                                indmin(1:4), indmax(1:4),               &
-                                                pttruetab(1:4),    cetruetab(1:4),      &
-                                                s_Child_temp(1:4), s_Parent_temp(1:4),  &
+                s_Parent_temp_p = s_Parent + (indmin_required_p - pttab_Parent) * ds_Parent
+                call Agrif_Interp_4D_recursive( type_interp(1:4),                                 &
+                                                tempPextend % array4(                             &
+                                                indmin_required_p(1):indmax_required_p(1),        &
+                                                indmin_required_p(2):indmax_required_p(2),        &
+                                                indmin_required_p(3):indmax_required_p(3),        &
+                                                indmin_required_p(4):indmax_required_p(4)),       &
+                                                tempC       % array4,                             &
+                                                indmin_required_p(1:4), indmax_required_p(1:4),   &
+                                                pttruetab(1:4),    cetruetab(1:4),                &
+                                                s_Child_temp(1:4), s_Parent_temp_p(1:4),          &
                                                 ds_Child(1:4),    ds_Parent(1:4) )
             case(5)
@@ -595,4 +721,5 @@
         else    ! .not.to_restore
 !
+
             if (memberin) then
     !
@@ -715,4 +842,5 @@
         endif
 
+
         call Agrif_array_deallocate(tempPextend,nbdim)
         call Agrif_array_deallocate(tempC,nbdim)
@@ -736,4 +864,5 @@
 !---------------------------------------------------------------------------------------------------
 subroutine Agrif_Parentbounds ( type_interp, nbdim, indmin, indmax, &
+                                indmin_required,indmax_required,    &
                                 s_Parent_temp, s_Child_temp,        &
                                 s_Child, ds_Child,                  &
@@ -745,7 +874,8 @@
     INTEGER,                   intent(in)  :: nbdim
     INTEGER, DIMENSION(nbdim), intent(out) :: indmin, indmax
-    REAL,    DIMENSION(nbdim), intent(out) :: s_Parent_temp, s_child_temp
-    REAL,    DIMENSION(nbdim), intent(in)  :: s_Child, ds_child
-    REAL,    DIMENSION(nbdim), intent(in)  :: s_Parent,ds_Parent
+    INTEGER, DIMENSION(nbdim), intent(out) :: indmin_required, indmax_required
+    REAL(kind=8),    DIMENSION(nbdim), intent(out) :: s_Parent_temp, s_child_temp
+    REAL(kind=8),    DIMENSION(nbdim), intent(in)  :: s_Child, ds_child
+    REAL(kind=8),    DIMENSION(nbdim), intent(in)  :: s_Parent,ds_Parent
     INTEGER, DIMENSION(nbdim), intent(in)  :: pttruetab, cetruetab
     INTEGER, DIMENSION(nbdim), intent(in)  :: pttab_Child, pttab_Parent
@@ -753,6 +883,8 @@
     INTEGER, DIMENSION(nbdim), intent(in)  :: coords
 !
+    REAL(kind=8) :: xpmin, xpmax
+    INTEGER :: coeffraf
     INTEGER :: i
-    REAL,DIMENSION(nbdim) :: dim_newmin, dim_newmax
+    REAL(kind=8),DIMENSION(nbdim) :: dim_newmin, dim_newmax
 !
     dim_newmin = s_Child + (pttruetab - pttab_Child) * ds_Child
@@ -763,8 +895,18 @@
         indmin(i) = pttab_Parent(i) + agrif_int((dim_newmin(i)-s_Parent(i))/ds_Parent(i))
         indmax(i) = pttab_Parent(i) + agrif_ceiling((dim_newmax(i)-s_Parent(i))/ds_Parent(i))
+
+        coeffraf = nint(ds_Parent(i)/ds_Child(i))
+        
+        indmin_required(i) = indmin(i)
+        indmax_required(i) = indmax(i)
 !
 !       Necessary for the Quadratic interpolation
 !
+
         if ( (pttruetab(i) == cetruetab(i)) .and. (posvar(i) == 1) ) then
+            if (Agrif_UseSpecialValue) then
+               indmin(i) = indmin(i)-MaxSearch
+               indmax(i) = indmax(i)+MaxSearch
+            endif
         elseif ( coords(i) == 0 ) then  ! (interptab == 'N')
         elseif ( (type_interp(i) == Agrif_ppm)     .or.     &
@@ -772,16 +914,71 @@
                  (type_interp(i) == Agrif_ppm_lim) .or.     &
                  (type_interp(i) == Agrif_weno) ) then
-            indmin(i) = indmin(i) - 2
-            indmax(i) = indmax(i) + 2
-
+                 
+            if ((mod(coeffraf,2) == 0).AND.(posvar(i)==2)) then
+            
+              xpmax = s_Parent(i)+(indmax(i)-pttab_Parent(i))*ds_Parent(i)
+              if (xpmax > dim_newmax(i)+ds_Child(i)) then
+                indmax(i) = indmax(i) + 1
+              else
+                indmax(i) = indmax(i) + 2
+              endif
+              
+              xpmin = s_Parent(i)+(indmin(i)-pttab_Parent(i))*ds_Parent(i)
+              if (xpmin < dim_newmin(i)-ds_Child(i)) then
+                indmin(i) = indmin(i) - 1
+              else
+                indmin(i) = indmin(i) - 2
+              endif
+              
+            else
+              indmin(i) = indmin(i) - 2
+              indmax(i) = indmax(i) + 2
+            endif
+
+            indmin_required(i) = indmin(i)
+            indmax_required(i) = indmax(i)
+        
             if (Agrif_UseSpecialValue) then
                indmin(i) = indmin(i)-MaxSearch
                indmax(i) = indmax(i)+MaxSearch
             endif
-
+        elseif (type_interp(i) == Agrif_linearconservlim) then
+        
+            if ((mod(coeffraf,2) == 0).AND.(posvar(i)==2)) then
+            
+              xpmax = s_Parent(i)+(indmax(i)-pttab_Parent(i))*ds_Parent(i)
+              if (xpmax > dim_newmax(i)+ds_Child(i)) then
+                indmax(i) = indmax(i)
+              else
+                indmax(i) = indmax(i) + 1
+              endif
+              
+              xpmin = s_Parent(i)+(indmin(i)-pttab_Parent(i))*ds_Parent(i)
+              if (xpmin < dim_newmin(i)-ds_Child(i)) then
+                indmin(i) = indmin(i)
+              else
+                indmin(i) = indmin(i) - 1
+              endif
+              
+            else
+              indmin(i) = indmin(i) - 1
+              indmax(i) = indmax(i) + 1
+            endif
+
+            indmin_required(i) = indmin(i)
+            indmax_required(i) = indmax(i)
+        
+            if (Agrif_UseSpecialValue) then
+               indmin(i) = indmin(i)-MaxSearch
+               indmax(i) = indmax(i)+MaxSearch
+            endif
+            
         elseif ( (type_interp(i) /= Agrif_constant) .and.   &
                  (type_interp(i) /= Agrif_linear) ) then
             indmin(i) = indmin(i) - 1
             indmax(i) = indmax(i) + 1
+            
+            indmin_required(i) = indmin(i)
+            indmax_required(i) = indmax(i)
 
             if (Agrif_UseSpecialValue) then
@@ -789,13 +986,14 @@
                indmax(i) = indmax(i)+MaxSearch
             endif
-
         elseif ( (type_interp(i) == Agrif_constant) .or.   &
                  (type_interp(i) == Agrif_linear) ) then
+            indmin_required(i) = indmin(i)
+            indmax_required(i) = indmax(i)
             if (Agrif_UseSpecialValue) then
                indmin(i) = indmin(i)-MaxSearch
                indmax(i) = indmax(i)+MaxSearch
             endif
-
         endif
+
 !
     enddo
@@ -822,6 +1020,6 @@
     integer,            intent(in)  :: indmin, indmax
     integer,            intent(in)  :: pttab_child, petab_child
-    real,               intent(in)  :: s_child, s_parent
-    real,               intent(in)  :: ds_child, ds_parent
+    real(kind=8),               intent(in)  :: s_child, s_parent
+    real(kind=8),               intent(in)  :: ds_child, ds_parent
     real, dimension(            &
         indmin:indmax           &
@@ -857,6 +1055,6 @@
     integer, dimension(2),              intent(in)  :: indmin, indmax
     integer, dimension(2),              intent(in)  :: pttab_child, petab_child
-    real,    dimension(2),              intent(in)  :: s_child, s_parent
-    real,    dimension(2),              intent(in)  :: ds_child, ds_parent
+    real(kind=8),    dimension(2),              intent(in)  :: s_child, s_parent
+    real(kind=8),    dimension(2),              intent(in)  :: ds_child, ds_parent
     real,    dimension(                 &
         indmin(1):indmax(1),            &
@@ -875,5 +1073,5 @@
         indmin(2):indmax(2),            &
         pttab_child(1):petab_child(1))  :: tabtemp_trsp
-    integer                             :: i, j, coeffraf
+    integer                             :: i, j, coeffraf, locind_child_left, ideb
 !---------------------------------------------------------------------------------------------------
 !
@@ -900,5 +1098,16 @@
                     s_parent(1),s_child(1),ds_parent(1),ds_child(1),1)
 !---CDIR NEXPAND
-        call PPM1dAfterCompute(tabin,tabtemp,size(tabin),size(tabtemp),1)
+        call PPM1dAfterCompute(tabin,tabtemp,size(tabin),size(tabtemp),1,indchildppm(:,1),tabppm(:,:,1))
+    else if (coeffraf == 1) then
+        locind_child_left = indmin(1) + agrif_int((s_child(1)-s_parent(1))/ds_parent(1))
+        
+            do j = indmin(2), indmax(2)
+            ideb = locind_child_left
+            do i = pttab_child(1), petab_child(1)
+                tabtemp(i,j) = tabin(ideb,j)
+                ideb = ideb + 1
+            enddo
+            enddo
+
     else
         do j = indmin(2),indmax(2)
@@ -941,5 +1150,6 @@
 !---CDIR NEXPAND
         call PPM1dAfterCompute(tabtemp_trsp, tabout_trsp,    &
-                               size(tabtemp_trsp), size(tabout_trsp), 2)
+                               size(tabtemp_trsp), size(tabout_trsp), 2, &
+                              indchildppm(:,2),tabppm(:,:,2))
     else
         do i = pttab_child(1), petab_child(1)
@@ -976,6 +1186,6 @@
     integer, dimension(3),              intent(in)  :: indmin, indmax
     integer, dimension(3),              intent(in)  :: pttab_child, petab_child
-    real,    dimension(3),              intent(in)  :: s_child, s_parent
-    real,    dimension(3),              intent(in)  :: ds_child, ds_parent
+    real(kind=8),    dimension(3),              intent(in)  :: s_child, s_parent
+    real(kind=8),    dimension(3),              intent(in)  :: ds_child, ds_parent
     real,    dimension(                 &
         indmin(1):indmax(1),            &
@@ -991,6 +1201,11 @@
         pttab_child(2):petab_child(2),  &
         indmin(3):indmax(3))            :: tabtemp
-    integer                             :: i, j, k, coeffraf
+    integer                             :: i, j, k, coeffraf,kp,kp1,kp2,kp3,kp4,kref
     integer                             :: locind_child_left, kdeb
+    real(kind=8)    :: ypos,globind_parent_left
+    real(kind=8)    :: deltax, invdsparent
+    real    :: t2,t3,t4,t5,t6,t7,t8
+    integer :: locind_parent_left
+
 !
     coeffraf = nint ( ds_parent(1) / ds_child(1) )
@@ -1051,5 +1266,65 @@
             enddo
         enddo
+    else if (type_interp(3) == Agrif_LAGRANGE) then
+      invdsparent = 1./ds_parent(3)
+      ypos = s_child(3)
+      do k=pttab_child(3), petab_child(3)
+        locind_parent_left = indmin(3)+agrif_int((ypos - s_parent(3))/ds_parent(3))
+        globind_parent_left = s_parent(3) + (locind_parent_left - indmin(3))*ds_parent(3)
+        deltax = invdsparent*(ypos-globind_parent_left)
+        deltax = nint(coeffraf*deltax)/real(coeffraf)
+        ypos = ypos + ds_child(3)
+
+        if (abs(deltax) <= 0.0001) then
+          do j = pttab_child(2), petab_child(2)
+          do i = pttab_child(1), petab_child(1)
+             tabout(i,j,k) = tabtemp(i,j,locind_parent_left)
+          enddo
+          enddo
+        else
+         t2 = deltax - 2.
+        t3 = deltax - 1.
+        t4 = deltax + 1.
+
+        t5 = -(1./6.)*deltax*t2*t3
+        t6 = 0.5*t2*t3*t4
+        t7 = -0.5*deltax*t2*t4
+        t8 = (1./6.)*deltax*t3*t4      
+          do j = pttab_child(2), petab_child(2)
+          do i = pttab_child(1), petab_child(1)
+             tabout(i,j,k) = t5*tabtemp(i,j,locind_parent_left-1) + t6*tabtemp(i,j,locind_parent_left)    &
+              +t7*tabtemp(i,j,locind_parent_left+1) + t8*tabtemp(i,j,locind_parent_left+2)
+          enddo
+          enddo
+
+        endif
+
+      enddo
+    else if (type_interp(3) == Agrif_PPM) then
+     call PPM1dPrecompute2d(1, &
+                               indmax(3)-indmin(3)+1,           &
+                               petab_child(3)-pttab_child(3)+1, &
+                               s_parent(3),s_child(3),ds_parent(3),ds_child(3),1)
+
+     do k=pttab_child(3),petab_child(3)
+        kref = k-pttab_child(3)+1
+        kp=indmin(3)+indparentppm(kref,1)-1
+        kp1 = kp + 1
+        kp2 = kp1 + 1
+        kp3 = kp2 + 1
+        kp4 = kp3 + 1
+        do j = pttab_child(2), petab_child(2)
+        do i = pttab_child(1), petab_child(1)
+         tabout(i,j,k) = tabppm(1,indchildppm(kref,1),1)*tabtemp(i,j,kp)   + &
+                         tabppm(2,indchildppm(kref,1),1)*tabtemp(i,j,kp1)  + &
+                         tabppm(3,indchildppm(kref,1),1)*tabtemp(i,j,kp2)  + &
+                         tabppm(4,indchildppm(kref,1),1)*tabtemp(i,j,kp3)  + &
+                         tabppm(5,indchildppm(kref,1),1)*tabtemp(i,j,kp4)
+        enddo
+        enddo
+     enddo
+
     else
+
         do j = pttab_child(2), petab_child(2)
         do i = pttab_child(1), petab_child(1)
@@ -1063,4 +1338,5 @@
         enddo
         enddo
+
     endif
 !---------------------------------------------------------------------------------------------------
@@ -1083,6 +1359,6 @@
     integer, dimension(4),              intent(in)  :: indmin, indmax
     integer, dimension(4),              intent(in)  :: pttab_child, petab_child
-    real,    dimension(4),              intent(in)  :: s_child, s_parent
-    real,    dimension(4),              intent(in)  :: ds_child, ds_parent
+    real(kind=8),    dimension(4),              intent(in)  :: s_child, s_parent
+    real(kind=8),    dimension(4),              intent(in)  :: ds_child, ds_parent
     real,    dimension(                 &
         indmin(1):indmax(1),            &
@@ -1102,4 +1378,9 @@
         indmin(4):indmax(4))            :: tabtemp
     integer                             :: i, j, k, l
+
+    real(kind=8)    :: ypos,globind_parent_left
+    real(kind=8)    :: deltax, invdsparent
+    real    :: t2,t3,t4,t5,t6,t7,t8
+    integer :: locind_parent_left, coeffraf
 !
     do l = indmin(4), indmax(4)
@@ -1117,4 +1398,44 @@
     enddo
 !
+     if (type_interp(4) == Agrif_LAGRANGE) then
+      coeffraf = nint(ds_parent(4)/ds_child(4))
+      invdsparent = 1./ds_parent(4)
+      ypos = s_child(4)
+      do l=pttab_child(4), petab_child(4)
+        locind_parent_left = indmin(4)+agrif_int((ypos - s_parent(4))/ds_parent(4))
+        globind_parent_left = s_parent(4) + (locind_parent_left - indmin(4))*ds_parent(4)
+        deltax = invdsparent*(ypos-globind_parent_left)
+        deltax = nint(coeffraf*deltax)/real(coeffraf)
+        ypos = ypos + ds_child(4)
+
+        if (abs(deltax) <= 0.0001) then
+          do k = pttab_child(3), petab_child(3)
+          do j = pttab_child(2), petab_child(2)
+          do i = pttab_child(1), petab_child(1)
+             tabout(i,j,k,l) = tabtemp(i,j,k,locind_parent_left)
+          enddo
+          enddo
+          enddo
+        else
+         t2 = deltax - 2.
+        t3 = deltax - 1.
+        t4 = deltax + 1.
+
+        t5 = -(1./6.)*deltax*t2*t3
+        t6 = 0.5*t2*t3*t4
+        t7 = -0.5*deltax*t2*t4
+        t8 = (1./6.)*deltax*t3*t4      
+          do k = pttab_child(3), petab_child(3)
+          do j = pttab_child(2), petab_child(2)
+          do i = pttab_child(1), petab_child(1)
+             tabout(i,j,k,l) = t5*tabtemp(i,j,k,locind_parent_left-1) + t6*tabtemp(i,j,k,locind_parent_left)    &
+              +t7*tabtemp(i,j,k,locind_parent_left+1) + t8*tabtemp(i,j,k,locind_parent_left+2)
+          enddo
+          enddo
+          enddo
+        endif
+
+      enddo
+    else
     do k = pttab_child(3), petab_child(3)
     do j = pttab_child(2), petab_child(2)
@@ -1130,4 +1451,5 @@
     enddo
     enddo
+    endif
 !---------------------------------------------------------------------------------------------------
 end subroutine Agrif_Interp_4D_recursive
@@ -1149,6 +1471,6 @@
     integer, dimension(5),              intent(in)  :: indmin, indmax
     integer, dimension(5),              intent(in)  :: pttab_child, petab_child
-    real,    dimension(5),              intent(in)  :: s_child, s_parent
-    real,    dimension(5),              intent(in)  :: ds_child, ds_parent
+    real(kind=8),    dimension(5),              intent(in)  :: s_child, s_parent
+    real(kind=8),    dimension(5),              intent(in)  :: ds_child, ds_parent
     real,    dimension(                 &
         indmin(1):indmax(1),            &
@@ -1222,6 +1544,6 @@
     integer, dimension(6),                  intent(in)  :: indmin, indmax
     integer, dimension(6),                  intent(in)  :: pttab_child, petab_child
-    real,    dimension(6),                  intent(in)  :: s_child, s_parent
-    real,    dimension(6),                  intent(in)  :: ds_child, ds_parent
+    real(kind=8),    dimension(6),                  intent(in)  :: s_child, s_parent
+    real(kind=8),    dimension(6),                  intent(in)  :: ds_child, ds_parent
     real,    dimension(                 &
         indmin(1):indmax(1),            &
@@ -1301,6 +1623,6 @@
     REAL, DIMENSION(indmin:indmax),           INTENT(IN)    :: parenttab
     REAL, DIMENSION(pttab_child:petab_child), INTENT(OUT)   :: childtab
-    REAL                                                    :: s_parent, s_child
-    REAL                                                    :: ds_parent,ds_child
+    REAL(kind=8)                                            :: s_parent, s_child
+    REAL(kind=8)                                            :: ds_parent,ds_child
 !
     if ( (indmin == indmax) .and. (pttab_child == petab_child) ) then
@@ -1371,5 +1693,6 @@
 !---------------------------------------------------------------------------------------------------
 function Agrif_Find_list_interp ( list_interp, pttab, petab, pttab_Child, pttab_Parent,     &
-                                    nbdim, indmin, indmax, indminglob,  indmaxglob,         &
+                                    nbdim, indmin, indmax, indmin_required_p, indmax_required_p, &
+                                    indminglob,  indmaxglob,         &
                                     pttruetab, cetruetab, memberin                          &
 #if defined AGRIF_MPI
@@ -1382,5 +1705,5 @@
     integer,                       intent(in)  :: nbdim
     integer, dimension(nbdim),     intent(in)  :: pttab, petab, pttab_Child, pttab_Parent
-    integer, dimension(nbdim),     intent(out) :: indmin, indmax
+    integer, dimension(nbdim),     intent(out) :: indmin, indmax, indmin_required_p, indmax_required_p
     integer, dimension(nbdim),     intent(out) :: indminglob, indmaxglob
     integer, dimension(nbdim),     intent(out) :: pttruetab, cetruetab
@@ -1421,4 +1744,6 @@
         indmin = pil % indmin(1:nbdim)
         indmax = pil % indmax(1:nbdim)
+        indmin_required_p = pil % indmin_required_p(1:nbdim)
+        indmax_required_p = pil % indmax_required_p(1:nbdim)
 
         pttruetab = pil % pttruetab(1:nbdim)
@@ -1452,5 +1777,6 @@
 !---------------------------------------------------------------------------------------------------
 subroutine Agrif_AddTo_list_interp ( list_interp, pttab, petab, pttab_Child, pttab_Parent,  &
-                                     indmin, indmax, indminglob, indmaxglob,                &
+                                     indmin, indmax, indmin_required_p, indmax_required_p,  &
+                                     indminglob, indmaxglob,                &
                                      pttruetab, cetruetab,                                  &
                                      memberin, nbdim                                        &
@@ -1466,5 +1792,5 @@
     integer                                 :: nbdim
     integer, dimension(nbdim)               :: pttab, petab, pttab_Child, pttab_Parent
-    integer, dimension(nbdim)               :: indmin,indmax
+    integer, dimension(nbdim)               :: indmin,indmax, indmin_required_p, indmax_required_p
     integer, dimension(nbdim)               :: indminglob, indmaxglob
     integer, dimension(nbdim)               :: pttruetab, cetruetab
@@ -1495,4 +1821,7 @@
     pil % indmin(1:nbdim) = indmin(1:nbdim)
     pil % indmax(1:nbdim) = indmax(1:nbdim)
+
+    pil % indmin_required_p(1:nbdim) = indmin_required_p(1:nbdim)
+    pil % indmax_required_p(1:nbdim) = indmax_required_p(1:nbdim)
 
     pil % memberin = memberin
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modinterpbasic.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modinterpbasic.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modinterpbasic.F90	(revision 10087)
@@ -41,4 +41,5 @@
     integer, dimension(:), allocatable      :: indparentppm_1d, indchildppm_1d
 !
+
     private :: Agrif_limiter_vanleer
 !
@@ -56,12 +57,12 @@
     integer,             intent(in)     :: np           !< Length of input array
     integer,             intent(in)     :: nc           !< Length of output array
-    real,                intent(in)     :: s_parent     !< Parent grid position (s_root = 0)
-    real,                intent(in)     :: s_child      !< Child  grid position (s_root = 0)
-    real,                intent(in)     :: ds_parent    !< Parent grid dx (ds_root = 1)
-    real,                intent(in)     :: ds_child     !< Child  grid dx (ds_root = 1)
+    real(kind=8),                intent(in)     :: s_parent     !< Parent grid position (s_root = 0)
+    real(kind=8),                intent(in)     :: s_child      !< Child  grid position (s_root = 0)
+    real(kind=8),                intent(in)     :: ds_parent    !< Parent grid dx (ds_root = 1)
+    real(kind=8),                intent(in)     :: ds_child     !< Child  grid dx (ds_root = 1)
 !
     integer :: i, coeffraf, locind_parent_left
-    real    :: globind_parent_left, globind_parent_right
-    real    :: invds, invds2, ypos, ypos2, diff
+    real(kind=8)    :: globind_parent_left, globind_parent_right
+    real(kind=8)    :: invds, invds2, ypos, ypos2, diff
 !
     coeffraf = nint(ds_parent/ds_child)
@@ -92,5 +93,9 @@
 !
         diff = globind_parent_right - ypos2
+! quick fix for roundoff error
+        diff=nint(diff*coeffraf)/real(coeffraf)
+
         y(i) = (diff*x(locind_parent_left) + (1.-diff)*x(locind_parent_left+1))
+
         ypos2 = ypos2 + invds2
 !
@@ -104,7 +109,13 @@
     else
         globind_parent_left = s_parent + (locind_parent_left - 1)*ds_parent
-        y(nc) = ((globind_parent_left + ds_parent - ypos)*x(locind_parent_left)  &
-                           + (ypos - globind_parent_left)*x(locind_parent_left+1))*invds
-    endif
+        diff=(globind_parent_left + ds_parent - ypos)*invds
+
+! quick fix for roundoff error
+        diff=nint(diff*coeffraf)/real(coeffraf)
+!        y(nc) = ((globind_parent_left + ds_parent - ypos)*x(locind_parent_left)  &
+!                           + (ypos - globind_parent_left)*x(locind_parent_left+1))*invds
+        y(nc) = (diff*x(locind_parent_left) + (1.-diff)*x(locind_parent_left+1))
+    endif
+
 !---------------------------------------------------------------------------------------------------
 end subroutine Agrif_basicinterp_linear1D
@@ -120,6 +131,6 @@
 !---------------------------------------------------------------------------------------------------
     integer, intent(in) :: np,nc,np2
-    real,    intent(in) :: s_parent, s_child
-    real,    intent(in) :: ds_parent, ds_child
+    real(kind=8),    intent(in) :: s_parent, s_child
+    real(kind=8),    intent(in) :: ds_parent, ds_child
     integer, intent(in) :: dir
 !
@@ -127,7 +138,7 @@
     integer, dimension(:,:), allocatable :: indparent_tmp
     real, dimension(:,:), allocatable :: coeffparent_tmp
-    real    :: ypos,globind_parent_left,globind_parent_right
-    real    :: invds, invds2, invds3
-    real :: ypos2,diff
+    real(kind=8)    :: ypos,globind_parent_left,globind_parent_right
+    real(kind=8)    :: invds, invds2, invds3
+    real(kind=8) :: ypos2,diff
 !
     coeffraf = nint(ds_parent/ds_child)
@@ -164,5 +175,5 @@
         if (ypos2 > globind_parent_right) then
             locind_parent_left = locind_parent_left + 1
-            globind_parent_right = globind_parent_right + 1.
+            globind_parent_right = globind_parent_right + 1.d0
             ypos2 = ypos*invds+(i-1)*invds2
         endif
@@ -239,10 +250,10 @@
     real, dimension(np), intent(in)     :: x
     real, dimension(nc), intent(out)    :: y
-    real,                intent(in)     :: s_parent, s_child
-    real,                intent(in)     :: ds_parent, ds_child
+    real(kind=8),                intent(in)     :: s_parent, s_child
+    real(kind=8),                intent(in)     :: ds_parent, ds_child
 !
     integer :: i, coeffraf, locind_parent_left
-    real    :: ypos,globind_parent_left
-    real    :: deltax, invdsparent
+    real(kind=8)    :: ypos,globind_parent_left
+    real(kind=8)    :: deltax, invdsparent
     real    :: t2,t3,t4,t5,t6,t7,t8
 !
@@ -304,9 +315,9 @@
     real, dimension(np), intent(in)     :: x
     real, dimension(nc), intent(out)    :: y
-    real,                intent(in)     :: s_parent, s_child
-    real,                intent(in)     :: ds_parent, ds_child
+    real(kind=8),                intent(in)     :: s_parent, s_child
+    real(kind=8),                intent(in)     :: ds_parent, ds_child
 !
     integer :: i, coeffraf, locind_parent
-    real    :: ypos
+    real(kind=8)    :: ypos
 !
     coeffraf = nint(ds_parent/ds_child)
@@ -342,10 +353,10 @@
     real, dimension(np), intent(in)     :: x
     real, dimension(nc), intent(out)    :: y
-    real,                intent(in)     :: s_parent, s_child
-    real,                intent(in)     :: ds_parent, ds_child
+    real(kind=8),                intent(in)     :: s_parent, s_child
+    real(kind=8),                intent(in)     :: ds_parent, ds_child
 !
     real, dimension(:), allocatable :: ytemp
     integer :: i,coeffraf,locind_parent_left,locind_parent_last
-    real    :: ypos,xdiffmod,xpmin,xpmax,slope
+    real(kind=8)    :: ypos,xdiffmod,xpmin,xpmax,slope
     integer :: i1,i2,ii
     integer :: diffmod
@@ -429,10 +440,10 @@
     real, dimension(np), intent(in)     :: x
     real, dimension(nc), intent(out)    :: y
-    real,                intent(in)     :: s_parent, s_child
-    real,                intent(in)     :: ds_parent, ds_child
+    real(kind=8),                intent(in)     :: s_parent, s_child
+    real(kind=8),                intent(in)     :: ds_parent, ds_child
 !
     real, dimension(:), allocatable :: ytemp
     integer :: i,coeffraf,locind_parent_left,locind_parent_last
-    real    :: ypos,xdiffmod,xpmin,xpmax,slope
+    real(kind=8)    :: ypos,xdiffmod,xpmin,xpmax,slope
     integer :: i1,i2,ii
     integer :: diffmod
@@ -524,12 +535,13 @@
     real, dimension(np), intent(in)     :: x
     real, dimension(nc), intent(out)    :: y
-    real,                intent(in)     :: s_parent, s_child
-    real,                intent(in)     :: ds_parent, ds_child
+    real(kind=8),                intent(in)     :: s_parent, s_child
+    real(kind=8),                intent(in)     :: ds_parent, ds_child
 !
     integer :: i,coeffraf,locind_parent_left,locind_parent_last
     integer :: iparent,ipos,pos,nmin,nmax
-    real    :: ypos
+    real(kind=8)    :: ypos
     integer :: i1,jj
-    real :: xpmin,a
+    real(kind=8) :: xpmin
+    real :: a
 !
     real, dimension(np) :: xl,delta,a6,slope
@@ -646,6 +658,6 @@
 !---------------------------------------------------------------------------------------------------
     integer,             intent(in)     :: np2, np, nc
-    real,                intent(in)     :: s_parent, s_child
-    real,                intent(in)     :: ds_parent, ds_child
+    real(kind=8),                intent(in)     :: s_parent, s_child
+    real(kind=8),                intent(in)     :: ds_parent, ds_child
     integer,             intent(in)     :: dir
 !
@@ -655,6 +667,7 @@
     integer :: iparent,ipos,pos
     real    :: ypos
-    integer :: i1,jj
-    real :: xpmin,a
+    integer :: i1,jj,k,l,j
+    real(kind=8) :: xpmin
+    real :: a
 !
     integer :: diffmod
@@ -738,7 +751,14 @@
     enddo
 !
-    do i = 1,np2
-        indparentppm(1+(i-1)*nc:i*nc,dir) = indparentppm_1d(1:nc) + (i-1)*np
-        indchildppm (1+(i-1)*nc:i*nc,dir) = indchildppm_1d (1:nc)
+
+    k=1
+    l=0
+    do i=1,np2
+      do j=1,nc
+        indchildppm(k,dir) = indchildppm_1d(j)
+        indparentppm(k,dir) = indparentppm_1d(j) + l
+        k=k+1
+      enddo
+      l=l+np
     enddo
 !---------------------------------------------------------------------------------------------------
@@ -746,112 +766,5 @@
 !===================================================================================================
 !
-!===================================================================================================
-!subroutine PPM1dPrecompute(np,nc,&
-!                    s_parent,s_child,ds_parent,ds_child)
-!!
-!!CC   Description:
-!!CC   subroutine to compute coefficient and index for  a 1D interpolation
-!!CC   using piecewise parabolic method
-!!C    Method:
-!!
-!!     Declarations:
-!!
-!      Implicit none
-!!
-!!     Arguments
-!      Integer             :: np,nc
-!!      Real, Dimension(:),Allocatable :: ytemp
-!      Real                :: s_parent,s_child,ds_parent,ds_child
-!!
-!!     Local scalars
-!      Integer :: i,coeffraf,locind_parent_left,locind_parent_last
-!      Integer :: iparent,ipos,pos,nmin,nmax
-!      Real    :: ypos
-!      integer :: i1,jj
-!      Real :: xpmin,a
-!!
-!      Real :: xrmin,xrmax,am3,s2,s1
-!      Real, Dimension(np) :: xl,delta,a6,slope
-!!      Real, Dimension(:),Allocatable  :: diff,diff2,diff3
-!      INTEGER :: diffmod
-!      REAL :: invcoeffraf
-!!
-!      coeffraf = nint(ds_parent/ds_child)
-!!
-!      If (coeffraf == 1) Then
-!          return
-!      End If
-!      invcoeffraf = ds_child/ds_parent
-!!
-!
-!      if (.not.allocated(indparentppm)) then
-!      allocate(indparentppm(-2*coeffraf:nc+2*coeffraf,1),&
-!         indchildppm(-2*coeffraf:nc+2*coeffraf,1))
-!      else
-!      if (size(indparentppm,1)<nc+4*coeffraf+1) then
-!      deallocate(indparentppm,indchildppm)
-!      allocate(indparentppm(-2*coeffraf:nc+2*coeffraf,1),&
-!         indchildppm(-2*coeffraf:nc+2*coeffraf,1))
-!      endif
-!      endif
-!
-!      ypos = s_child
-!!
-!      locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent)
-!      locind_parent_last = 1 +&
-!      agrif_ceiling((ypos +(nc - 1)&
-!      *ds_child - s_parent)/ds_parent)
-!!
-!      xpmin = s_parent + (locind_parent_left-1)*ds_parent
-!      i1 = 1+agrif_int((xpmin-s_child)/ds_child)
-!!
-!!
-!
-!      Do i=1,coeffraf
-!        tabdiff2(i)=(real(i)-0.5)*invcoeffraf
-!      EndDo
-!
-!      a = invcoeffraf**2
-!      tabdiff3(1) = (1./3.)*a
-!      a=2.*a
-!!CDIR ALTCODE
-!!!!CDIR SHORTLOOP
-!      Do i=2,coeffraf
-!        tabdiff3(i) = tabdiff3(i-1)+(real(i)-1)*a
-!      EndDo
-!
-!!CDIR ALTCODE
-!!!!CDIR SHORTLOOP
-!      Do i=1,coeffraf
-!      tabppm(1,i,1) = 0.08333333333333*(-1.+4*tabdiff2(i)-3*tabdiff3(i))
-!      tabppm(2,i,1) = 0.08333333333333*&
-!              (7.-26.*tabdiff2(i)+18.*tabdiff3(i))
-!      tabppm(3,i,1) =0.08333333333333*(7.+30*tabdiff2(i)-30*tabdiff3(i))
-!      tabppm(4,i,1) = 0.08333333333333*&
-!              (-1.-10.*tabdiff2(i)+18.*tabdiff3(i))
-!      tabppm(5,i,1) = 0.08333333333333*(2*tabdiff2(i)-3*tabdiff3(i))
-!      End Do
-!!
-!!
-!        diffmod = 0
-!       IF (mod(coeffraf,2) == 0) diffmod = 1
-!!
-!        ipos = i1
-!!
-!        Do iparent = locind_parent_left,locind_parent_last
-!             pos=1
-!!CDIR ALTCODE
-!!CDIR SHORTLOOP
-!             Do jj = ipos - coeffraf/2+diffmod,ipos + coeffraf/2
-!         indparentppm(jj,1) = iparent-2
-!         indchildppm(jj,1) = pos
-!               pos = pos+1
-!             End do
-!             ipos = ipos + coeffraf
-!!
-!        End do
-!
-!      Return
-!      End subroutine ppm1dprecompute
+
 !===================================================================================================
 !
@@ -863,22 +776,32 @@
 ! Use precomputed coefficient and index.
 !---------------------------------------------------------------------------------------------------
-subroutine PPM1dAfterCompute ( x, y, np, nc, dir )
-!---------------------------------------------------------------------------------------------------
+subroutine PPM1dAfterCompute ( x, y, np, nc, dir, indchildppmloc, tabppmloc )
+!---------------------------------------------------------------------------------------------------
+    integer,             intent(in)     :: np, nc
     real, dimension(np), intent(in)     :: x
     real, dimension(nc), intent(out)    :: y
-    integer,             intent(in)     :: np, nc
     integer,             intent(in)     :: dir
-!
-    integer :: i
-!
+    integer, dimension(1:),intent(in) :: indchildppmloc
+    real, dimension(1:,1:),intent(in) :: tabppmloc
+!
+    integer :: i,j,jp1,jp2,jp3,jp4,k
+
+    
     do i = 1,nc
-        y(i) = tabppm(1,indchildppm(i,dir),dir) * x(indparentppm(i,dir)  ) + &
-               tabppm(2,indchildppm(i,dir),dir) * x(indparentppm(i,dir)+1) + &
-               tabppm(3,indchildppm(i,dir),dir) * x(indparentppm(i,dir)+2) + &
-               tabppm(4,indchildppm(i,dir),dir) * x(indparentppm(i,dir)+3) + &
-               tabppm(5,indchildppm(i,dir),dir) * x(indparentppm(i,dir)+4)
-    enddo
+        j = indparentppm(i,dir)
+        jp1=j+1
+        jp2=jp1+1
+        jp3=jp2+1
+        jp4=jp3+1
+        y(i) = tabppmloc(1,indchildppmloc(i)) * x(j) + &
+               tabppmloc(2,indchildppmloc(i)) * x(jp1) + &
+               tabppmloc(3,indchildppmloc(i)) * x(jp2) + &
+               tabppmloc(4,indchildppmloc(i)) * x(jp3) + &
+               tabppmloc(5,indchildppmloc(i)) * x(jp4)
+    enddo
+
 !---------------------------------------------------------------------------------------------------
 end subroutine PPM1dAfterCompute
+
 !===================================================================================================
 !
@@ -1069,13 +992,13 @@
     real, dimension(np), intent(in)     :: x
     real, dimension(nc), intent(out)    :: y
-    real,                intent(in)     :: s_parent, s_child
-    real,                intent(in)     :: ds_parent, ds_child
+    real(kind=8),                intent(in)     :: s_parent, s_child
+    real(kind=8),                intent(in)     :: ds_parent, ds_child
 !
     real, dimension(:), allocatable :: ytemp
     integer :: i,coeffraf,locind_parent_left,locind_parent_last
     integer :: iparent,ipos,pos,nmin,nmax
-    real    :: ypos
+    real(kind=8)    :: ypos
     integer :: i1,jj
-    real :: xpmin
+    real(kind=8) :: xpmin
 !
     real, dimension(np) :: slope
@@ -1166,12 +1089,12 @@
     real, dimension(np), intent(in)     :: x
     real, dimension(nc), intent(out)    :: y
-    real,                intent(in)     :: s_parent, s_child
-    real,                intent(in)     :: ds_parent, ds_child
+    real(kind=8),                intent(in)     :: s_parent, s_child
+    real(kind=8),                intent(in)     :: ds_parent, ds_child
 !
     integer :: i,coeffraf,locind_parent_left,locind_parent_last
     integer :: ipos, pos
-    real    :: ypos,xi
+    real(kind=8)    :: ypos,xi
     integer :: i1,jj
-    real :: xpmin
+    real(kind=8) :: xpmin
 !
     real, dimension(:),   allocatable  :: ytemp
@@ -1276,12 +1199,13 @@
       Real, Dimension(nc) :: y
       Real, Dimension(:),Allocatable :: ytemp
-      Real                :: s_parent,s_child,ds_parent,ds_child
+      Real(kind=8)        :: s_parent,s_child,ds_parent,ds_child
 !
 !     Local scalars
       Integer :: i,coeffraf,locind_parent_left,locind_parent_last
       Integer :: iparent,ipos,pos,nmin,nmax
-      Real    :: ypos
+      Real(kind=8)    :: ypos
       integer :: i1,jj
-      Real :: xpmin,cavg,a,b
+      Real(kind=8) :: xpmin
+      real :: cavg,a,b
 !      
       Real :: xrmin,xrmax,am3,s2,s1  
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modlinktomodel.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modlinktomodel.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modlinktomodel.F90	(revision 10087)
@@ -80,8 +80,4 @@
 !                    Agrif_Curgrid % spaceref(1)
 !===================================================================================================
-!  function Agrif_Parent_Irhox
-!        modify by conv. To use : var = Agrif_Parent_IRhox()
-!                    Agrif_Curgrid % parent % spaceref(1)
-!===================================================================================================
 !  function Agrif_Rhoy
 !        modify by conv. To use : var = Agrif_Rhoy()
@@ -96,7 +92,6 @@
 !                    Agrif_Curgrid % spaceref(2)
 !===================================================================================================
-!  function Agrif_Parent_Irhoy
-!        modify by conv. To use : var = Agrif_Parent_IRhoy()
-!                    Agrif_Curgrid % parent % spaceref(2)
+
+
 !===================================================================================================
 !  function Agrif_Rhoz
@@ -111,8 +106,5 @@
 !        modify by conv. To use : var = Agrif_Parent_IRhoz()
 !                    Agrif_Curgrid % spaceref(3)
-!===================================================================================================
-!  function Agrif_Parent_Irhoz
-!        modify by conv. To use : var = Agrif_Parent_IRhoz()
-!                    Agrif_Curgrid % parent % spaceref(3)
+
 !===================================================================================================
 !  function Agrif_NearCommonBorderX
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modmask.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modmask.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modmask.F90	(revision 10087)
@@ -40,5 +40,6 @@
 !! when this one is equal to Agrif_SpecialValue.
 !---------------------------------------------------------------------------------------------------
-subroutine Agrif_CheckMasknD ( tempP, parent, pbtab, petab, ppbtab, ppetab, noraftab, nbdim )
+subroutine Agrif_CheckMasknD ( tempP, parent, pbtab, petab, ppbtab, ppetab, &
+             pbtab_required, petab_required, noraftab, nbdim )
 !---------------------------------------------------------------------------------------------------
     type(Agrif_Variable), pointer   :: tempP  !< Part of the parent grid used for the interpolation of the child grid
@@ -46,9 +47,12 @@
     integer, dimension(nbdim)       :: pbtab  !< limits of the parent grid used
     integer, dimension(nbdim)       :: petab  !< interpolation of the child grid
-    integer, dimension(nbdim)       :: ppbtab, ppetab
+    integer, dimension(nbdim)       :: ppbtab, ppetab, pbtab_required, petab_required
     logical, dimension(nbdim)       :: noraftab
     integer                         :: nbdim
 !
-    integer :: i0,j0,k0,l0,m0,n0
+    integer :: i0,j0,k0,l0,m0,n0,ll,kk
+    integer,dimension(:,:),allocatable :: trytoreplace
+    integer :: ilook, Nbvals
+    real :: xold
 !
     select case (nbdim)
@@ -77,10 +81,4 @@
                     parent%array3(ppbtab(1),ppbtab(2),ppbtab(3)), &
                     ppbtab,ppetab,noraftab,MaxSearch,Agrif_SpecialValue)
-
-!            Call CalculNewValTempP((/i0,j0,k0/),
-!     &                             tempP,parent,
-!     &                             ppbtab,ppetab,
-!     &                             noraftab,nbdim)
-
             endif
         enddo
@@ -88,18 +86,68 @@
         enddo
     case (4)
-        do l0 = pbtab(4),petab(4)
-        do k0 = pbtab(3),petab(3)
-        do j0 = pbtab(2),petab(2)
-        do i0 = pbtab(1),petab(1)
+
+        if (noraftab(1).AND.noraftab(2)) then
+          allocate(trytoreplace(pbtab_required(3):petab_required(3),pbtab_required(4):petab_required(4)))
+          trytoreplace = -1
+          i0 = pbtab_required(1)
+          j0 = pbtab_required(2)
+          do l0 = pbtab_required(4),petab_required(4)
+          do k0 = pbtab_required(3),petab_required(3)
             if (tempP%array4(i0,j0,k0,l0) == Agrif_SpecialValue) then
                 call CalculNewValTempP4D((/i0,j0,k0,l0/), &
                     tempP%array4(ppbtab(1),ppbtab(2),ppbtab(3),ppbtab(4)),  &
                     parent%array4(ppbtab(1),ppbtab(2),ppbtab(3),ppbtab(4)), &
-                    ppbtab,ppetab,noraftab,MaxSearch,Agrif_SpecialValue)
-            endif
-        enddo
-        enddo
-        enddo
-        enddo
+                    ppbtab,ppetab,noraftab,MaxSearch,Agrif_SpecialValue, &
+                    trytoreplace(k0,l0))
+            endif
+          enddo
+          enddo
+
+          do l0 = pbtab_required(4),petab_required(4)
+          do k0 = pbtab_required(3),petab_required(3)
+          if (trytoreplace(k0,l0) /= -1) then
+          do j0 = pbtab_required(2),petab_required(2)
+          do i0 = pbtab_required(1),petab_required(1)
+
+          if (tempP%array4(i0,j0,k0,l0) == Agrif_SpecialValue) then
+          tempP%array4(i0,j0,k0,l0) = 0.
+          Nbvals = 0
+          do ll=max(l0-trytoreplace(k0,l0),ppbtab(4)),min(l0+trytoreplace(k0,l0),ppetab(4))
+          do kk=max(k0-trytoreplace(k0,l0),ppbtab(3)),min(k0+trytoreplace(k0,l0),ppetab(3))
+           if (parent%array4(i0,j0,kk,ll) /= Agrif_SpecialValue) then
+             tempP%array4(i0,j0,k0,l0) = tempP%array4(i0,j0,k0,l0) + parent%array4(i0,j0,kk,ll)
+             Nbvals = Nbvals + 1
+           endif
+          enddo
+          enddo
+
+          tempP%array4(i0,j0,k0,l0) = tempP%array4(i0,j0,k0,l0) /Nbvals
+          endif
+          enddo
+          enddo
+          endif
+          enddo
+          enddo
+          deallocate(trytoreplace)
+
+        else
+
+        do l0 = pbtab_required(4),petab_required(4)
+        do k0 = pbtab_required(3),petab_required(3)
+        do j0 = pbtab_required(2),petab_required(2)
+        do i0 = pbtab_required(1),petab_required(1)
+            if (tempP%array4(i0,j0,k0,l0) == Agrif_SpecialValue) then
+                ilook = -1
+                call CalculNewValTempP4D((/i0,j0,k0,l0/), &
+                    tempP%array4(ppbtab(1),ppbtab(2),ppbtab(3),ppbtab(4)),  &
+                    parent%array4(ppbtab(1),ppbtab(2),ppbtab(3),ppbtab(4)), &
+                    ppbtab,ppetab,noraftab,MaxSearch,Agrif_SpecialValue,ilook)
+            endif
+        enddo
+        enddo
+        enddo
+        enddo
+
+        endif
     case (5)
         do m0 = pbtab(5),petab(5)
@@ -488,5 +536,5 @@
 !---------------------------------------------------------------------------------------------------
 subroutine CalculNewValTempP4D ( indic, tempP, parent, ppbtab, ppetab, noraftab, &
-                                 MaxSearch, Agrif_SpecialValue )
+                                 MaxSearch, Agrif_SpecialValue, ilook )
 !---------------------------------------------------------------------------------------------------
     integer, parameter          :: nbdim = 4
@@ -511,4 +559,5 @@
 !
     logical                     :: firsttest
+    integer :: ilook
 !
     ValMax = 1
@@ -528,8 +577,14 @@
     firsttest = .TRUE.
     idecal = indic
+
+    if (ilook /= -1) then
+       i = ilook
+    else
+       i = 1
+    endif
 !
     do while (i <= ValMax)
 !
-        if ((i == 1).AND.(firsttest)) i = Valmax
+!        if ((i == 1).AND.(firsttest)) i = Valmax
 
         do iii = 1,nbdim
@@ -537,13 +592,13 @@
                 imin(iii) = max(indic(iii) - i,ppbtab(iii))
                 imax(iii) = min(indic(iii) + i,ppetab(iii))
-                if (firsttest) then
-                    if (indic(iii) > ppbtab(iii)) then
-                        idecal(iii) = idecal(iii)-1
-                        if (tempP(idecal(1),idecal(2),idecal(3),idecal(4)) == Agrif_SpecialValue) then
-                            imin(iii) = imax(iii)
-                        endif
-                        idecal(iii) = idecal(iii)+1
-                    endif
-                endif
+ !               if (firsttest) then
+ !                   if (indic(iii) > ppbtab(iii)) then
+ !                       idecal(iii) = idecal(iii)-1
+ !                       if (tempP(idecal(1),idecal(2),idecal(3),idecal(4)) == Agrif_SpecialValue) then
+ !                           imin(iii) = imax(iii)
+ !                       endif
+ !                       idecal(iii) = idecal(iii)+1
+ !                   endif
+ !               endif
             endif
         enddo
@@ -567,14 +622,15 @@
 !
         if (Nbvals > 0) then
-            if (firsttest) then
-                firsttest = .FALSE.
-                i=1
-                cycle
-            endif
+!            if (firsttest) then
+!                firsttest = .FALSE.
+!                i=1
+!                cycle
+!            endif
 
             tempP(indic(1),indic(2),indic(3),indic(4)) = Res/Nbvals
+            ilook = i
             exit
         else
-            if (firsttest) exit
+!            if (firsttest) exit
             i = i + 1
         endif
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modmpp.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modmpp.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modmpp.F90	(revision 10087)
@@ -166,5 +166,5 @@
 subroutine Get_External_Data_first ( pttruetab, cetruetab, pttruetabwhole, cetruetabwhole,  &
                                      nbdim, memberoutall, coords, sendtoproc, recvfromproc, &
-                                     imin, imax, imin_recv, imax_recv )
+                                     imin, imax, imin_recv, imax_recv, bornesmin, bornesmax )
 !---------------------------------------------------------------------------------------------------
     include 'mpif.h'
@@ -179,4 +179,5 @@
     integer, dimension(nbdim,0:Agrif_NbProcs-1), intent(out) :: imin,imax
     integer, dimension(nbdim,0:Agrif_NbProcs-1), intent(out) :: imin_recv,imax_recv
+    integer, dimension(nbdim,0:Agrif_NbProcs-1), intent(in) :: bornesmin, bornesmax
 !
     integer :: imintmp, imaxtmp, i, j, k, i1
@@ -211,5 +212,5 @@
             IF (cetruetab(i,Agrif_Procrank) > cetruetab(i,k)) THEN
                 DO j=imin1,imax1
-                    IF ((cetruetab(i,k)-j) > (j-pttruetab(i,Agrif_Procrank))) THEN
+                    IF ((bornesmax(i,k)-j) > (j-bornesmin(i,Agrif_Procrank))) THEN
                         imintmp = j+1
                         tochange = .TRUE.
@@ -228,5 +229,5 @@
             IF (pttruetab(i,Agrif_Procrank) < pttruetab(i,k)) THEN
                 DO j=imax1,imin1,-1
-                    IF ((j-pttruetab(i,k)) > (cetruetab(i,Agrif_Procrank)-j)) THEN
+                    IF ((j-bornesmin(i,k)) > (bornesmax(i,Agrif_Procrank)-j)) THEN
                         imaxtmp = j-1
                         tochange = .TRUE.
@@ -248,4 +249,7 @@
         sendtoproc(k) = .true.
 !
+        IF ( .not. memberoutall(k) ) THEN
+            sendtoproc(k) = .false.
+        ELSE
 !CDIR SHORTLOOP
         do i = 1,nbdim
@@ -257,6 +261,4 @@
             endif
         enddo
-        IF ( .not. memberoutall(k) ) THEN
-            sendtoproc(k) = .false.
         ENDIF
     enddo
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modsauv.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modsauv.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modsauv.F90	(revision 10087)
@@ -27,9 +27,9 @@
 !
 module Agrif_Save
-!
+!   
     use Agrif_Types
     use Agrif_Link
     use Agrif_Arrays
-    use Agrif_Variables
+    use Agrif_User_Variables
 !
     implicit none
@@ -250,5 +250,5 @@
 !
     type(Agrif_PGrid), pointer  :: parcours ! Pointer for the recursive procedure
-    real    :: g_eps, eps, oldgrid_eps
+    real(kind=8)    :: g_eps, eps, oldgrid_eps
     integer :: out
     integer :: iii
@@ -331,5 +331,5 @@
 !
     type(Agrif_PGrid), pointer  :: parcours ! Pointer for the recursive procedure
-    real    :: g_eps,eps,oldgrid_eps
+    real(kind=8)    :: g_eps,eps,oldgrid_eps
     integer :: out
     integer :: iii
@@ -415,7 +415,7 @@
     integer, dimension(6) :: nbtabold  ! Number of cells in each direction
     integer, dimension(6) :: nbtabnew  ! Number of cells in each direction
-    real,    dimension(6) :: snew,sold
-    real,    dimension(6) :: dsnew,dsold
-    real    :: eps
+    real(kind=8),    dimension(6) :: snew,sold
+    real(kind=8),    dimension(6) :: dsnew,dsold
+    real(kind=8)    :: eps
     integer :: n
 !
@@ -531,13 +531,13 @@
     integer, dimension(nbdim),     intent(in)    :: pttabold
     integer, dimension(nbdim),     intent(in)    :: petabold
-    real,    dimension(nbdim),     intent(in)    :: snew, sold
-    real,    dimension(nbdim),     intent(in)    :: dsnew,dsold
+    real(kind=8),    dimension(nbdim),     intent(in)    :: snew, sold
+    real(kind=8),    dimension(nbdim),     intent(in)    :: dsnew,dsold
     integer,                       intent(in)    :: nbdim
 !
     integer :: i,j,k,l,m,n,i0,j0,k0,l0,m0,n0
 !
-    real,    dimension(nbdim) :: dim_gmin,   dim_gmax
-    real,    dimension(nbdim) :: dim_newmin, dim_newmax
-    real,    dimension(nbdim) :: dim_min
+    real(kind=8),    dimension(nbdim) :: dim_gmin,   dim_gmax
+    real(kind=8),    dimension(nbdim) :: dim_newmin, dim_newmax
+    real(kind=8),    dimension(nbdim) :: dim_min
     integer, dimension(nbdim) :: ind_gmin,ind_newmin, ind_newmax
 !
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modseq.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modseq.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modseq.F90	(revision 10087)
@@ -3,5 +3,6 @@
     use Agrif_Init
     use Agrif_Procs
-    use Agrif_Arrays
+    use Agrif_Grids
+    !use Agrif_Arrays
 !
     implicit none
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modtypes.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modtypes.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modtypes.F90	(revision 10087)
@@ -109,4 +109,31 @@
     real(4), dimension(:,:,:,:,:,:), allocatable :: sarray6
 !> @}
+!> \name Arrays containing the values of the grid variables (real)
+!> @{
+    real,    dimension(:)          , pointer :: parray1
+    real,    dimension(:,:)        , pointer :: parray2
+    real,    dimension(:,:,:)      , pointer :: parray3
+    real,    dimension(:,:,:,:)    , pointer :: parray4
+    real,    dimension(:,:,:,:,:)  , pointer :: parray5
+    real,    dimension(:,:,:,:,:,:), pointer :: parray6
+!> @}
+!> \name Arrays containing the values of the grid variables (real*8)
+!> @{
+    real(8), dimension(:)          , pointer :: pdarray1
+    real(8), dimension(:,:)        , pointer :: pdarray2
+    real(8), dimension(:,:,:)      , pointer :: pdarray3
+    real(8), dimension(:,:,:,:)    , pointer :: pdarray4
+    real(8), dimension(:,:,:,:,:)  , pointer :: pdarray5
+    real(8), dimension(:,:,:,:,:,:), pointer :: pdarray6
+!> @}
+!> \name Arrays containing the values of the grid variables (real*4)
+!> @{
+    real(4), dimension(:)          , pointer :: psarray1
+    real(4), dimension(:,:)        , pointer :: psarray2
+    real(4), dimension(:,:,:)      , pointer :: psarray3
+    real(4), dimension(:,:,:,:)    , pointer :: psarray4
+    real(4), dimension(:,:,:,:,:)  , pointer :: psarray5
+    real(4), dimension(:,:,:,:,:,:), pointer :: psarray6
+!> @}
 !> \name Arrays used to restore the values
 !> @{
@@ -132,4 +159,6 @@
     integer, dimension(6)   :: ub
 
+    integer, dimension(6,2) :: lubglob
+
     logical,dimension(6,2) :: memberin
     integer,dimension(6,2,2,6,2) :: childarray
@@ -153,7 +182,7 @@
 !> \name Arrays containing the values of the grid variables (character)
 !> @{
-    character(2400)                             :: carray0
-    character(200), dimension(:)  , allocatable :: carray1
-    character(200), dimension(:,:), allocatable :: carray2
+    character(4000)                             :: carray0
+    character(400), dimension(:)  , allocatable :: carray1
+    character(400), dimension(:,:), allocatable :: carray2
 !> @}
 !---------------------------------------------------------------------------------------------------
@@ -218,5 +247,5 @@
 !> \name Arrays containing the values of the grid variables (logical)
 !> @{
-    logical                                      :: larray0
+    logical                                      :: larray0 = .FALSE.
     logical, dimension(:)          , allocatable :: larray1
     logical, dimension(:,:)        , allocatable :: larray2
@@ -242,5 +271,5 @@
 !> \name Arrays containing the values of the grid variables (integer)
 !> @{
-    integer                                      :: iarray0
+    integer                                      :: iarray0 = 0
     integer, dimension(:)          , allocatable :: iarray1
     integer, dimension(:,:)        , allocatable :: iarray2
@@ -259,4 +288,5 @@
     integer,dimension(6)              :: pttab, petab, pttab_Child, pttab_Parent = -99
     integer,dimension(6)              :: indmin, indmax
+    integer,dimension(6)              :: indmin_required_p, indmax_required_p
     integer,dimension(6)              :: pttruetab,cetruetab
     logical :: member, memberin
@@ -324,5 +354,5 @@
     real                  :: Agrif_Efficiency = 0.7
     integer               :: MaxSearch = 5
-    real, dimension(3)    :: Agrif_mind
+    real(kind=8), dimension(3)    :: Agrif_mind
 !> @}
 !> \name parameters for the interpolation of the child grids
@@ -388,5 +418,5 @@
 integer function Agrif_Ceiling ( x )
 !---------------------------------------------------------------------------------------------------
-    real,   intent(in) :: x
+    real(kind=8),intent(in) :: x
 !
     integer   :: i
@@ -408,5 +438,5 @@
     integer function Agrif_Int(x)
 !---------------------------------------------------------------------------------------------------
-    real,   intent(in) :: x
+    real(kind=8),intent(in) :: x
 !
     integer :: i
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modupdate.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modupdate.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modupdate.F90	(revision 10087)
@@ -27,8 +27,18 @@
 module Agrif_Update
 !
+!    use Agrif_UpdateBasic
+!    use Agrif_Arrays
+!    use Agrif_CurgridFunctions
+!    use Agrif_Mask
+#if defined AGRIF_MPI
+!    use Agrif_Mpp
+#endif
+!
     use Agrif_UpdateBasic
     use Agrif_Arrays
-    use Agrif_CurgridFunctions
+    use Agrif_User_Functions
+    use Agrif_Init
     use Agrif_Mask
+    
 #if defined AGRIF_MPI
     use Agrif_Mpp
@@ -58,8 +68,8 @@
     integer, dimension(6) :: ub_child
     integer, dimension(6) :: lb_parent
-    real   , dimension(6) ::  s_child           ! Child  grid position (s_root = 0)
-    real   , dimension(6) ::  s_parent          ! Parent grid position (s_root = 0)
-    real   , dimension(6) :: ds_child           ! Child  grid dx (ds_root = 1)
-    real   , dimension(6) :: ds_parent          ! Parent grid dx (ds_root = 1)
+    real(kind=8)   , dimension(6) ::  s_child           ! Child  grid position (s_root = 0)
+    real(kind=8)   , dimension(6) ::  s_parent          ! Parent grid position (s_root = 0)
+    real(kind=8)   , dimension(6) :: ds_child           ! Child  grid dx (ds_root = 1)
+    real(kind=8)   , dimension(6) :: ds_parent          ! Parent grid dx (ds_root = 1)
     logical, dimension(6) :: do_update          ! Indicates if we perform update for each dimension
     integer, dimension(6) :: posvar             ! Position of the variable on the cell (1 or 2)
@@ -160,8 +170,8 @@
     integer, dimension(nbdim), intent(in) :: posvar         !< Position of the variable on the cell (1 or 2)
     logical, dimension(nbdim), intent(in) :: do_update      !< Indicates if we update for each dimension
-    real,    dimension(nbdim), intent(in) :: s_child        !< Positions of the child grid
-    real,    dimension(nbdim), intent(in) :: s_parent       !< Positions of the parent grid
-    real,    dimension(nbdim), intent(in) :: ds_child       !< Space steps of the child grid
-    real,    dimension(nbdim), intent(in) :: ds_parent      !< Space steps of the parent grid
+    real(kind=8),    dimension(nbdim), intent(in) :: s_child        !< Positions of the child grid
+    real(kind=8),    dimension(nbdim), intent(in) :: s_parent       !< Positions of the parent grid
+    real(kind=8),    dimension(nbdim), intent(in) :: ds_child       !< Space steps of the child grid
+    real(kind=8),    dimension(nbdim), intent(in) :: ds_parent      !< Space steps of the parent grid
     procedure()                           :: procname       !< Data recovery procedure
 !
@@ -230,5 +240,6 @@
 ! lubglob(:,2) : global lbound for each dimension
 !
-    call Agrif_get_var_global_bounds(child, lubglob, nbdim)
+!     call Agrif_get_var_global_bounds(child, lubglob, nbdim)
+    lubglob = child % lubglob(1:nbdim,:)
 !
     indtruetab(1:nbdim,1,1) = max(indtab(1:nbdim,1,1), lubglob(1:nbdim,1))
@@ -274,8 +285,8 @@
     integer, dimension(nbdim), intent(in)   :: posvar       !< Position of the variable on the cell (1 or 2)
     logical, dimension(nbdim), intent(in)   :: do_update    !< Indicates if we update for each dimension
-    real,    dimension(nbdim), intent(in)   :: s_child      !< Positions of the child grid
-    real,    dimension(nbdim), intent(in)   :: s_parent     !< Positions of the parent grid
-    real,    dimension(nbdim), intent(in)   :: ds_child     !< Space steps of the child grid
-    real,    dimension(nbdim), intent(in)   :: ds_parent    !< Space steps of the parent grid
+    real(kind=8),    dimension(nbdim), intent(in)   :: s_child      !< Positions of the child grid
+    real(kind=8),    dimension(nbdim), intent(in)   :: s_parent     !< Positions of the parent grid
+    real(kind=8),    dimension(nbdim), intent(in)   :: ds_child     !< Space steps of the child grid
+    real(kind=8),    dimension(nbdim), intent(in)   :: ds_parent    !< Space steps of the parent grid
     procedure()                             :: procname     !< Data recovery procedure
 !
@@ -390,8 +401,8 @@
 #endif
 !
-    integer, dimension(6),     intent(in)   :: type_update  !< Type of update (copy or average)
     type(Agrif_Variable), pointer           :: parent       !< Variable of the parent grid
     type(Agrif_Variable), pointer           :: child        !< Variable of the child grid
     integer,                   intent(in)   :: nbdim
+    integer, dimension(nbdim), intent(in)   :: type_update  !< Type of update (copy or average)
     integer, dimension(nbdim), intent(in)   :: pttab        !< Index of the first point inside the domain
     integer, dimension(nbdim), intent(in)   :: petab        !< Index of the first point inside the domain
@@ -400,8 +411,8 @@
     integer, dimension(nbdim), intent(in)   :: lb_parent !< Index of the first point inside the domain for the parent
                                                             !!    grid variable
-    real,    dimension(nbdim), intent(in)   :: s_child      !< Positions of the child grid
-    real,    dimension(nbdim), intent(in)   :: s_parent     !< Positions of the parent grid
-    real,    dimension(nbdim), intent(in)   :: ds_child     !< Space steps of the child grid
-    real,    dimension(nbdim), intent(in)   :: ds_parent    !< Space steps of the parent grid
+    real(kind=8),    dimension(nbdim), intent(in)   :: s_child      !< Positions of the child grid
+    real(kind=8),    dimension(nbdim), intent(in)   :: s_parent     !< Positions of the parent grid
+    real(kind=8),    dimension(nbdim), intent(in)   :: ds_child     !< Space steps of the child grid
+    real(kind=8),    dimension(nbdim), intent(in)   :: ds_parent    !< Space steps of the parent grid
     procedure()                             :: procname     !< Data recovery procedure
     integer, optional,         intent(in)   :: nb, ndir
@@ -415,5 +426,5 @@
     integer, dimension(nbdim)       :: indmin, indmax
     integer, dimension(nbdim)       :: indminglob, indmaxglob
-    real   , dimension(nbdim)       :: s_Child_temp, s_Parent_temp
+    real(kind=8)   , dimension(nbdim)       :: s_Child_temp, s_Parent_temp
     integer, dimension(nbdim)       :: lowerbound,upperbound
     integer, dimension(nbdim)       :: pttruetabwhole, cetruetabwhole
@@ -450,4 +461,5 @@
     real :: coeff_multi
     integer :: nb_dimensions
+
 !
 !   Get local lower and upper bound of the child variable
@@ -506,5 +518,7 @@
 !
         call Agrif_array_allocate(tempC,pttruetab,cetruetab,nbdim)
+#if defined AGRIF_MPI
         call Agrif_var_set_array_tozero(tempC,nbdim)
+#endif
 
         SELECT CASE (nbdim)
@@ -582,5 +596,6 @@
                                      nbdim, memberinall, coords,                            &
                                      sendtoproc1,recvfromproc1,                             &
-                                     tab4t(:,:,5),tab4t(:,:,6),tab4t(:,:,7),tab4t(:,:,8))
+                                     tab4t(:,:,5),tab4t(:,:,6),tab4t(:,:,7),tab4t(:,:,8),   &
+                                     tab4t(:,:,1),tab4t(:,:,2))
     endif
 
@@ -600,5 +615,17 @@
 !
         call Agrif_array_allocate(tempP,indmin,indmax,nbdim)
-!
+
+        IF (Agrif_UseSpecialValueInUpdate) THEN
+            allocate(tempC_indic)
+            allocate(tempP_indic)
+            call Agrif_array_allocate(tempC_indic,pttruetabwhole,cetruetabwhole,nbdim)
+            call Agrif_array_allocate(tempP_indic,indmin,indmax,nbdim)
+            call agrif_set_array_cond(tempCextend,tempC_indic,agrif_SpecialValueFineGrid,nbdim)
+        ELSE
+            tempC_indic=>tempCextend ! Just to associate tempC_indic to something ...
+        ENDIF
+!
+
+
         if ( nbdim == 1 ) then
             tempP % array1 = 0.
@@ -606,4 +633,5 @@
                                             tempP%array1,   &
                                             tempCextend%array1, &
+                                            tempC_indic%array1, &
                                             indmin(1), indmax(1),   &
                                             pttruetabwhole(1), cetruetabwhole(1),   &
@@ -612,8 +640,4 @@
                                             
             IF (Agrif_UseSpecialValueInUpdate) THEN
-            allocate(tempC_indic)
-            allocate(tempP_indic)
-            call Agrif_array_allocate(tempC_indic,lbound(tempCextend%array1),ubound(tempCextend%array1),nbdim)
-            call Agrif_array_allocate(tempP_indic,lbound(tempP%array1),ubound(tempP%array1),nbdim)
 
             compute_average = .FALSE.
@@ -629,4 +653,5 @@
                                             tempP_average%array1,       &
                                             tempCextend%array1, &
+                                            tempC_indic%array1, &
                                             indmin(1), indmax(1),   &
                                             pttruetabwhole(1), cetruetabwhole(1),   &
@@ -639,10 +664,4 @@
             ENDIF
             
-            WHERE (tempCextend%array1 == Agrif_SpecialValueFineGrid)
-              tempC_indic%array1 = 0.
-            ELSEWHERE
-              tempC_indic%array1 = 1.
-            END WHERE
-            
             Agrif_UseSpecialValueInUpdate = .FALSE.
             Agrif_Update_Weights = .TRUE.
@@ -650,4 +669,5 @@
              call Agrif_Update_1D_Recursive( type_update_temp(1),   &
                                             tempP_indic%array1,       &
+                                            tempC_indic%array1, &
                                             tempC_indic%array1, &
                                             indmin(1), indmax(1),   &
@@ -691,4 +711,5 @@
                                             tempP%array2,       &
                                             tempCextend%array2, &
+                                            tempC_indic%array2, &
                                             indmin(1:2), indmax(1:2),   &
                                             pttruetabwhole(1:2), cetruetabwhole(1:2),   &
@@ -697,8 +718,4 @@
 
             IF (Agrif_UseSpecialValueInUpdate) THEN
-            allocate(tempC_indic)
-            allocate(tempP_indic)
-            call Agrif_array_allocate(tempC_indic,lbound(tempCextend%array2),ubound(tempCextend%array2),nbdim)
-            call Agrif_array_allocate(tempP_indic,lbound(tempP%array2),ubound(tempP%array2),nbdim)
  
             compute_average = .FALSE.
@@ -714,4 +731,5 @@
                                             tempP_average%array2,       &
                                             tempCextend%array2, &
+                                            tempC_indic%array2, &
                                             indmin(1:2), indmax(1:2),   &
                                             pttruetabwhole(1:2), cetruetabwhole(1:2),   &
@@ -724,10 +742,4 @@
             ENDIF
             
-            WHERE (tempCextend%array2 == Agrif_SpecialValueFineGrid)
-              tempC_indic%array2 = 0.
-            ELSEWHERE
-              tempC_indic%array2 = 1.
-            END WHERE
-            
             Agrif_UseSpecialValueInUpdate = .FALSE.
             Agrif_Update_Weights = .TRUE.
@@ -735,4 +747,5 @@
             call Agrif_Update_2D_Recursive( type_update_temp(1:2),   &
                                             tempP_indic%array2,       &
+                                            tempC_indic%array2, &
                                             tempC_indic%array2, &
                                             indmin(1:2), indmax(1:2),   &
@@ -773,17 +786,16 @@
         endif
         if ( nbdim == 3 ) then
+
             call Agrif_Update_3D_Recursive( type_update(1:3),   &
                                             tempP%array3,       &
                                             tempCextend%array3, &
+                                            tempC_indic%array3, &
                                             indmin(1:3), indmax(1:3),   &
                                             pttruetabwhole(1:3), cetruetabwhole(1:3),   &
                                             s_Child_temp(1:3), s_Parent_temp(1:3),      &
                                             ds_child(1:3), ds_parent(1:3) )
-                                            
+
+                      
             IF (Agrif_UseSpecialValueInUpdate) THEN
-            allocate(tempC_indic)
-            allocate(tempP_indic)
-            call Agrif_array_allocate(tempC_indic,lbound(tempCextend%array3),ubound(tempCextend%array3),nbdim)
-            call Agrif_array_allocate(tempP_indic,lbound(tempP%array3),ubound(tempP%array3),nbdim)
 
             compute_average = .FALSE.
@@ -796,7 +808,9 @@
                 type_update_temp(1:nbdim) = Agrif_Update_Average
               END WHERE
+
               call Agrif_Update_3D_Recursive( type_update_temp(1:3),   &
                                             tempP_average%array3,       &
                                             tempCextend%array3, &
+                                            tempC_indic%array3, &
                                             indmin(1:3), indmax(1:3),   &
                                             pttruetabwhole(1:3), cetruetabwhole(1:3),   &
@@ -808,17 +822,13 @@
               enddo
             ENDIF
-            
-            WHERE (tempCextend%array3 == Agrif_SpecialValueFineGrid)
-              tempC_indic%array3 = 0.
-            ELSEWHERE
-              tempC_indic%array3 = 1.
-            END WHERE
-            
+
             Agrif_UseSpecialValueInUpdate = .FALSE.
             Agrif_Update_Weights = .TRUE.
- 
+
+
              call Agrif_Update_3D_Recursive( type_update_temp(1:3),   &
                                             tempP_indic%array3,       &
                                             tempC_indic%array3, &
+                                            tempCextend%array3, &
                                             indmin(1:3), indmax(1:3),   &
                                             pttruetabwhole(1:3), cetruetabwhole(1:3),   &
@@ -826,8 +836,11 @@
                                             ds_child(1:3), ds_parent(1:3) )
 
+
            Agrif_UseSpecialValueInUpdate = .TRUE.
            Agrif_Update_Weights = .FALSE.
 
+
            IF (compute_average) THEN
+         
                WHERE (tempP_indic%array3 == 0.)
                   tempP%array3 = Agrif_SpecialValueFineGrid
@@ -837,5 +850,5 @@
                   tempP%array3 = tempP_average%array3 /tempP_indic%array3
                END WHERE
-
+            
            ELSE
                WHERE (tempP_indic%array3 == 0.)
@@ -845,5 +858,5 @@
                END WHERE
             ENDIF
-           
+
             deallocate(tempP_indic%array3)
             deallocate(tempC_indic%array3)
@@ -855,21 +868,19 @@
             ENDIF
             ENDIF
-            
+
+         
         endif
         if ( nbdim == 4 ) then
+          
             call Agrif_Update_4D_Recursive( type_update(1:4),   &
                                             tempP%array4,       &
                                             tempCextend%array4, &
+                                            tempC_indic%array4, &
                                             indmin(1:4), indmax(1:4),   &
                                             pttruetabwhole(1:4), cetruetabwhole(1:4),   &
                                             s_Child_temp(1:4), s_Parent_temp(1:4),      &
                                             ds_child(1:4), ds_parent(1:4) )
-                                            
+                
             IF (Agrif_UseSpecialValueInUpdate) THEN
-            
-            allocate(tempC_indic)
-            allocate(tempP_indic)
-            call Agrif_array_allocate(tempC_indic,lbound(tempCextend%array4),ubound(tempCextend%array4),nbdim)
-            call Agrif_array_allocate(tempP_indic,lbound(tempP%array4),ubound(tempP%array4),nbdim)
            
             compute_average = .FALSE.
@@ -885,4 +896,5 @@
                                             tempP_average%array4,       &
                                             tempCextend%array4, &
+                                            tempC_indic%array4, &
                                             indmin(1:4), indmax(1:4),   &
                                             pttruetabwhole(1:4), cetruetabwhole(1:4),   &
@@ -895,10 +907,4 @@
             ENDIF
             
-            WHERE (tempCextend%array4 == Agrif_SpecialValueFineGrid)
-              tempC_indic%array4 = 0.
-            ELSEWHERE
-              tempC_indic%array4 = 1.
-            END WHERE
-            
             Agrif_UseSpecialValueInUpdate = .FALSE.
             Agrif_Update_Weights = .TRUE.
@@ -906,4 +912,5 @@
              call Agrif_Update_4D_Recursive( type_update_temp(1:4),   &
                                             tempP_indic%array4,       &
+                                            tempC_indic%array4, &
                                             tempC_indic%array4, &
                                             indmin(1:4), indmax(1:4),   &
@@ -940,5 +947,5 @@
             ENDIF
             ENDIF
-            
+                 
         endif
         if ( nbdim == 5 ) then
@@ -946,4 +953,5 @@
                                             tempP%array5,       &
                                             tempCextend%array5, &
+                                            tempC_indic%array5, &
                                             indmin(1:5), indmax(1:5),   &
                                             pttruetabwhole(1:5), cetruetabwhole(1:5),   &
@@ -952,8 +960,4 @@
                                             
             IF (Agrif_UseSpecialValueInUpdate) THEN
-            allocate(tempC_indic)
-            allocate(tempP_indic)
-            call Agrif_array_allocate(tempC_indic,lbound(tempCextend%array5),ubound(tempCextend%array5),nbdim)
-            call Agrif_array_allocate(tempP_indic,lbound(tempP%array5),ubound(tempP%array5),nbdim)
 
             compute_average = .FALSE.
@@ -969,4 +973,5 @@
                                             tempP_average%array5,       &
                                             tempCextend%array5, &
+                                            tempC_indic%array5, &
                                             indmin(1:5), indmax(1:5),   &
                                             pttruetabwhole(1:5), cetruetabwhole(1:5),   &
@@ -979,10 +984,4 @@
             ENDIF
             
-            WHERE (tempCextend%array5 == Agrif_SpecialValueFineGrid)
-              tempC_indic%array5 = 0.
-            ELSEWHERE
-              tempC_indic%array5 = 1.
-            END WHERE
-            
             Agrif_UseSpecialValueInUpdate = .FALSE.
             Agrif_Update_Weights = .TRUE.
@@ -990,4 +989,5 @@
              call Agrif_Update_5D_Recursive( type_update_temp(1:5),   &
                                             tempP_indic%array5,       &
+                                            tempC_indic%array5, &
                                             tempC_indic%array5, &
                                             indmin(1:5), indmax(1:5),   &
@@ -1031,13 +1031,11 @@
                                             tempP%array6,       &
                                             tempCextend%array6, &
+                                            tempC_indic%array6, &
                                             indmin(1:6), indmax(1:6),   &
                                             pttruetabwhole(1:6), cetruetabwhole(1:6),   &
                                             s_Child_temp(1:6), s_Parent_temp(1:6),      &
                                             ds_child(1:6), ds_parent(1:6) )
+
             IF (Agrif_UseSpecialValueInUpdate) THEN
-            allocate(tempC_indic)
-            allocate(tempP_indic)
-            call Agrif_array_allocate(tempC_indic,lbound(tempCextend%array6),ubound(tempCextend%array6),nbdim)
-            call Agrif_array_allocate(tempP_indic,lbound(tempP%array6),ubound(tempP%array6),nbdim)
 
             compute_average = .FALSE.
@@ -1054,4 +1052,5 @@
                                             tempP_average%array6,       &
                                             tempCextend%array6, &
+                                            tempC_indic%array6, &
                                             indmin(1:6), indmax(1:6),   &
                                             pttruetabwhole(1:6), cetruetabwhole(1:6),   &
@@ -1064,4 +1063,20 @@
             ENDIF
 
+            
+            Agrif_UseSpecialValueInUpdate = .FALSE.
+            Agrif_Update_Weights = .TRUE.
+ 
+             call Agrif_Update_6D_Recursive( type_update_temp(1:6),   &
+                                            tempP_indic%array6,       &
+                                            tempC_indic%array6, &
+                                            tempC_indic%array6, &
+                                            indmin(1:6), indmax(1:6),   &
+                                            pttruetabwhole(1:6), cetruetabwhole(1:6),   &
+                                            s_Child_temp(1:6), s_Parent_temp(1:6),      &
+                                            ds_child(1:6), ds_parent(1:6) )
+
+           Agrif_UseSpecialValueInUpdate = .TRUE.
+           Agrif_Update_Weights = .FALSE.
+           
            IF (compute_average) THEN
                WHERE (tempP_indic%array6 == 0.)
@@ -1080,24 +1095,4 @@
                END WHERE
             ENDIF
-            
-            Agrif_UseSpecialValueInUpdate = .FALSE.
-            Agrif_Update_Weights = .TRUE.
- 
-             call Agrif_Update_6D_Recursive( type_update_temp(1:6),   &
-                                            tempP_indic%array6,       &
-                                            tempC_indic%array6, &
-                                            indmin(1:6), indmax(1:6),   &
-                                            pttruetabwhole(1:6), cetruetabwhole(1:6),   &
-                                            s_Child_temp(1:6), s_Parent_temp(1:6),      &
-                                            ds_child(1:6), ds_parent(1:6) )
-
-           Agrif_UseSpecialValueInUpdate = .TRUE.
-           Agrif_Update_Weights = .FALSE.
-           
-            WHERE (tempP_indic%array6 == 0.)
-              tempP%array6 = Agrif_SpecialValueFineGrid
-            ELSEWHERE
-              tempP%array6 = tempP%array6 /tempP_indic%array6
-            END WHERE
            
             deallocate(tempP_indic%array6)
@@ -1154,5 +1149,6 @@
                                      nbdim, memberinall2, coords,                           &
                                      sendtoproc2, recvfromproc2,                            &
-                                     tab5t(:,:,5),tab5t(:,:,6),tab5t(:,:,7),tab5t(:,:,8))
+                                     tab5t(:,:,5),tab5t(:,:,6),tab5t(:,:,7),tab5t(:,:,8),   &
+                                     tab5t(:,:,1),tab5t(:,:,2))
 
         call Agrif_Addto_list_update(child%list_update,pttab,petab,lb_child,lb_parent,      &
@@ -1323,7 +1319,7 @@
     integer,                   intent(in)   :: nbdim
     integer, dimension(nbdim), intent(out)  :: indmin, indmax
-    real,    dimension(nbdim), intent(out)  :: s_Parent_temp, s_Child_temp
-    real,    dimension(nbdim), intent(in)   :: s_child,  ds_child
-    real,    dimension(nbdim), intent(in)   :: s_parent, ds_parent
+    real(kind=8),    dimension(nbdim), intent(out)  :: s_Parent_temp, s_Child_temp
+    real(kind=8),    dimension(nbdim), intent(in)   :: s_child,  ds_child
+    real(kind=8),    dimension(nbdim), intent(in)   :: s_parent, ds_parent
     integer, dimension(nbdim), intent(in)   :: pttruetab, cetruetab
     integer, dimension(nbdim), intent(in)   :: lb_child, lb_parent
@@ -1335,8 +1331,8 @@
 #endif
 !
-    real,dimension(nbdim) :: dim_newmin,dim_newmax
+    real(kind=8),dimension(nbdim) :: dim_newmin,dim_newmax
     integer :: i
 #if defined AGRIF_MPI
-    real    :: positionmin, positionmax
+    real(kind=8)    :: positionmin, positionmax
     integer :: imin, imax
     integer :: coeffraf
@@ -1422,9 +1418,9 @@
 !> Updates a 1D grid variable on the parent grid
 !---------------------------------------------------------------------------------------------------
-subroutine Agrif_Update_1D_Recursive ( type_update,         &
-                                       tempP, tempC,        &
-                                       indmin, indmax,      &
-                                       lb_child, ub_child,  &
-                                       s_child,  s_parent,  &
+subroutine Agrif_Update_1D_Recursive ( type_update,                     &
+                                       tempP, tempC, tempC_indic,       &
+                                       indmin, indmax,                  &
+                                       lb_child, ub_child,              &
+                                       s_child,  s_parent,              &
                                        ds_child, ds_parent )
 !---------------------------------------------------------------------------------------------------
@@ -1432,8 +1428,8 @@
     integer,                            intent(in)  :: indmin, indmax
     integer,                            intent(in)  :: lb_child, ub_child
-    real,                               intent(in)  ::  s_child,  s_parent
-    real,                               intent(in)  :: ds_child, ds_parent
+    real(kind=8),                               intent(in)  ::  s_child,  s_parent
+    real(kind=8),                               intent(in)  :: ds_child, ds_parent
     real, dimension(indmin:indmax),     intent(out) :: tempP
-    real, dimension(lb_child:ub_child), intent(in)  :: tempC
+    real, dimension(lb_child:ub_child), intent(in)  :: tempC, tempC_indic
 !---------------------------------------------------------------------------------------------------
     call Agrif_UpdateBase(type_update,              &
@@ -1454,9 +1450,9 @@
 !! Calls #Agrif_Update_1D_Recursive and #Agrif_UpdateBase
 !---------------------------------------------------------------------------------------------------
-subroutine Agrif_Update_2D_Recursive ( type_update,         &
-                                       tempP, tempC,        &
-                                       indmin, indmax,      &
-                                       lb_child, ub_child,  &
-                                        s_child,  s_parent, &
+subroutine Agrif_Update_2D_Recursive ( type_update,                     &
+                                       tempP, tempC, tempC_indic,       &
+                                       indmin, indmax,                  &
+                                       lb_child, ub_child,              &
+                                       s_child,  s_parent,              &
                                        ds_child, ds_parent )
 !---------------------------------------------------------------------------------------------------
@@ -1464,10 +1460,10 @@
     integer, dimension(2),          intent(in)  :: indmin, indmax
     integer, dimension(2),          intent(in)  :: lb_child, ub_child
-    real,    dimension(2),          intent(in)  ::  s_child,  s_parent
-    real,    dimension(2),          intent(in)  :: ds_child, ds_parent
+    real(kind=8),    dimension(2),          intent(in)  ::  s_child,  s_parent
+    real(kind=8),    dimension(2),          intent(in)  :: ds_child, ds_parent
     real,    dimension(          &
         indmin(1):indmax(1),     &
         indmin(2):indmax(2)),       intent(out) :: tempP
-    real,    dimension(:,:),        intent(in)  :: tempC
+    real,    dimension(:,:),        intent(in)  :: tempC, tempC_indic
 !---------------------------------------------------------------------------------------------------
     real, dimension(indmin(1):indmax(1), lb_child(2):ub_child(2)) :: tabtemp
@@ -1475,7 +1471,15 @@
     real, dimension(lb_child(2):ub_child(2), indmin(1):indmax(1)) :: tabtemp_trsp
     integer :: i, j
-    integer :: coeffraf
-!
-    tabtemp = 0.
+    integer :: coeffraf, coeffraf_2
+	integer :: jmin,jmax
+    integer locind_child_left, locind_child_left_2,kuinf
+    logical :: to_transpose
+    real :: invcoeffraf
+    integer :: diffmod, jj,i1,j1
+
+
+    to_transpose = .TRUE.
+!
+    
     coeffraf = nint ( ds_parent(1) / ds_child(1) )
 !
@@ -1490,4 +1494,5 @@
         endif
 !---CDIR NEXPAND
+        tabtemp = 0.
         call Average1dAfterCompute( tabtemp, tempC, size(tabtemp), size(tempC), &
                     s_parent(1),s_child(1),ds_parent(1),ds_child(1),1)
@@ -1503,6 +1508,66 @@
         endif
 !---CDIR NEXPAND
+
         call Agrif_basicupdate_copy1d_after(tabtemp,tempC,size(tabtemp),size(tempC),1)
 !
+    ELSE IF ((coeffraf == 1).AND.(type_update(2) == Agrif_Update_Average)) THEN
+            locind_child_left = 1+agrif_int((s_parent(1)-s_child(1))/ds_child(1))
+            coeffraf_2 = nint ( ds_parent(2) / ds_child(2) )
+            invcoeffraf = 1./coeffraf_2
+            tempP = 0.
+            diffmod = 0
+            if (mod(coeffraf_2,2) == 0) diffmod = 1
+            locind_child_left_2 = 1+agrif_int((s_parent(2)-s_child(2))/ds_child(2))
+
+            if (Agrif_UseSpecialValueInUpdate) then
+              j1 = -coeffraf_2/2+locind_child_left_2+diffmod
+              do j=indmin(2),indmax(2)
+                do jj=j1,j1+coeffraf_2-1
+                  i1 = locind_child_left
+                  do i=indmin(1),indmax(1)
+                     tempP(i,j) = tempP(i,j) + tempC(i1,jj)*tempC_indic(i1,jj)
+                     i1 = i1 + 1
+                  enddo
+                enddo
+                j1 = j1 + coeffraf_2
+              enddo
+            else
+              j1 = -coeffraf_2/2+locind_child_left_2+diffmod
+              do j=indmin(2),indmax(2)
+                do jj=j1,j1+coeffraf_2-1
+                  do i=indmin(1),indmax(1)
+                       tempP(i,j) = tempP(i,j) + tempC(locind_child_left+i-indmin(1),jj)
+                  enddo
+                enddo
+                j1 = j1 + coeffraf_2
+              enddo
+              if (.not.Agrif_Update_Weights) tempP = tempP * invcoeffraf
+            endif
+            return
+!
+    ELSE IF ((coeffraf == 1).AND.(type_update(2) == Agrif_Update_Copy)) THEN
+
+            locind_child_left = 1 + agrif_int((s_parent(1)-s_child(1))/ds_child(1))
+!
+            locind_child_left_2 = 1+nint((s_parent(2)-s_child(2))/ds_child(2))
+            coeffraf_2 = nint ( ds_parent(2) / ds_child(2) )
+
+            do j=indmin(2),indmax(2)
+              do i=indmin(1),indmax(1)
+                tempP(i,j) = tempC(locind_child_left+i-indmin(1),locind_child_left_2)
+              enddo
+              locind_child_left_2 = locind_child_left_2 + coeffraf_2
+            enddo
+
+            return
+
+    ELSE IF (coeffraf == 1) THEN
+            locind_child_left = 1 + agrif_int((s_parent(1)-s_child(1))/ds_child(1))
+!
+            do j = lb_child(2),ub_child(2)
+!              tabtemp(indmin(1):indmax(1),j) = tempC(locind_child_left:locind_child_left+indmax(1)-indmin(1),j-lb_child(2)+1)
+              tabtemp_trsp(j,indmin(1):indmax(1)) = tempC(locind_child_left:locind_child_left+indmax(1)-indmin(1),j-lb_child(2)+1)
+            enddo
+            to_transpose = .FALSE.
     ELSE
         do j = lb_child(2),ub_child(2)
@@ -1512,4 +1577,5 @@
                                             tabtemp(:,j),               &
                                             tempC(:,j-lb_child(2)+1),   &
+                                            tempC_indic(:,j-lb_child(2)+1),   &
                                             indmin(1), indmax(1),       &
                                             lb_child(1),ub_child(1),    &
@@ -1519,5 +1585,7 @@
     ENDIF
 !
-    tabtemp_trsp = TRANSPOSE(tabtemp)
+
+    if (to_transpose) tabtemp_trsp = TRANSPOSE(tabtemp)
+
     coeffraf = nint(ds_parent(2)/ds_child(2))
 !
@@ -1564,53 +1632,9 @@
     ENDIF
 !
+
+	
     tempP = TRANSPOSE(tempP_trsp)
 !---------------------------------------------------------------------------------------------------
 end subroutine Agrif_Update_2D_Recursive
-!===================================================================================================
-!
-subroutine Agrif_Update_2D_Recursive_ok ( type_update, &
-                                        tempP, tempC, &
-                                        indmin, indmax,   &
-                                       lb_child, ub_child,                    &
-                                       s_child, s_parent, ds_child, ds_parent )
-!---------------------------------------------------------------------------------------------------
-    INTEGER, DIMENSION(2), intent(in)   :: type_update            !< Type of update (copy or average)
-    INTEGER, DIMENSION(2), intent(in)   :: indmin, indmax
-    INTEGER, DIMENSION(2), intent(in)   :: lb_child, ub_child
-    REAL,    DIMENSION(2), intent(in)   :: s_child,  s_parent
-    REAL,    DIMENSION(2), intent(in)   :: ds_child, ds_parent
-    REAL,    DIMENSION(                 &
-                indmin(1):indmax(1),    &
-                indmin(2):indmax(2)),           intent(out) :: tempP
-    REAL, DIMENSION(                            &
-                lb_child(1):ub_child(1),  &
-                lb_child(2):ub_child(2)), intent(in)  :: tempC
-!
-    REAL, DIMENSION(indmin(1):indmax(1), lb_child(2):ub_child(2)) :: tabtemp
-    INTEGER :: i
-!
-    do i = lb_child(2),ub_child(2)
-        call Agrif_Update_1D_Recursive(type_update(1),                              &
-                                       tabtemp(:, i),          &
-                                       tempC(:,i),  &
-                                       indmin(1),indmax(1),                 &
-                                       lb_child(1),ub_child(1),       &
-                                       s_child(1), s_parent(1),             &
-                                      ds_child(1),ds_parent(1))
-    enddo
-!
-    tempP = 0.
-!
-    do i = indmin(1),indmax(1)
-        call Agrif_UpdateBase(type_update(2),                                       &
-                              tempP(i,:),             &
-                              tabtemp(i,:), &
-                              indmin(2),indmax(2),                          &
-                              lb_child(2),ub_child(2),                &
-                              s_parent(2),s_child(2),                       &
-                             ds_parent(2),ds_child(2))
-    enddo
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Update_2D_Recursive_ok
 !===================================================================================================
 
@@ -1622,9 +1646,9 @@
 !! Calls #Agrif_Update_2D_Recursive and #Agrif_UpdateBase.
 !---------------------------------------------------------------------------------------------------
-subroutine Agrif_Update_3D_Recursive ( type_update,         &
-                                       tempP, tempC,        &
-                                       indmin, indmax,      &
-                                       lb_child, ub_child,  &
-                                        s_child,  s_parent, &
+subroutine Agrif_Update_3D_Recursive ( type_update,                     &
+                                       tempP, tempC, tempC_indic,       &
+                                       indmin, indmax,                  &
+                                       lb_child, ub_child,              &
+                                       s_child,  s_parent,              &
                                        ds_child, ds_parent )
 !---------------------------------------------------------------------------------------------------
@@ -1632,6 +1656,6 @@
     integer, dimension(3),          intent(in)  :: indmin, indmax
     integer, dimension(3),          intent(in)  :: lb_child, ub_child
-    real,    dimension(3),          intent(in)  ::  s_child,  s_parent
-    real,    dimension(3),          intent(in)  :: ds_child, ds_parent
+    real(kind=8),    dimension(3),          intent(in)  ::  s_child,  s_parent
+    real(kind=8),    dimension(3),          intent(in)  :: ds_child, ds_parent
     real,    dimension(          &
         indmin(1):indmax(1),     &
@@ -1641,5 +1665,5 @@
         lb_child(1):ub_child(1), &
         lb_child(2):ub_child(2), &
-        lb_child(3):ub_child(3)),   intent(in)  :: tempC
+        lb_child(3):ub_child(3)),   intent(in)  :: tempC, tempC_indic
 !---------------------------------------------------------------------------------------------------
     real, dimension(            &
@@ -1650,4 +1674,6 @@
     integer :: coeffraf,locind_child_left
     integer :: kuinf
+    REAL :: invcoeffraf
+    INTEGER :: diffmod, kk
 !
     coeffraf = nint ( ds_parent(1) / ds_child(1) )
@@ -1687,11 +1713,21 @@
     endif
 !
+ !   do k = lb_child(3),ub_child(3)
+ !       call Agrif_Update_2D_Recursive( type_update(1:2),tabtemp(:,:,k),tempC(:,:,k), &
+ !                                       indmin(1:2),indmax(1:2),                &
+ !                                       lb_child(1:2),ub_child(1:2),      &
+ !                                       s_child(1:2),s_parent(1:2),             &
+ !                                       ds_child(1:2),ds_parent(1:2) )
+ !   enddo
+
+
     do k = lb_child(3),ub_child(3)
-        call Agrif_Update_2D_Recursive( type_update(1:2),tabtemp(:,:,k),tempC(:,:,k), &
-                                        indmin(1:2),indmax(1:2),                &
-                                        lb_child(1:2),ub_child(1:2),      &
-                                        s_child(1:2),s_parent(1:2),             &
-                                        ds_child(1:2),ds_parent(1:2) )
+        call Agrif_Update_2D_Recursive( type_update,tabtemp(:,:,k),tempC(:,:,k),tempC_indic(:,:,k), &
+                                        indmin,indmax,                &
+                                        lb_child,ub_child,      &
+                                        s_child,s_parent,             &
+                                        ds_child,ds_parent)
     enddo
+
 !
     precomputedone(1) = .FALSE.
@@ -1711,6 +1747,50 @@
             enddo
         enddo
+    else if (type_update(3) == Agrif_Update_Copy) then
+    locind_child_left = lb_child(3) + nint((s_parent(3)-s_child(3))/ds_child(3))
+
+        do k=indmin(3),indmax(3)
+            do j = indmin(2),indmax(2)
+            do i = indmin(1),indmax(1)
+                tempP(i,j,k) = tabtemp(i,j,locind_child_left)
+            enddo
+            enddo
+            locind_child_left = locind_child_left + coeffraf
+        enddo
+    else if (type_update(3) == Agrif_Update_Average) then
+      invcoeffraf = 1./coeffraf
+      tempP = 0.
+      diffmod = 0
+      if (mod(coeffraf,2) == 0) diffmod=1 
+      locind_child_left = lb_child(3) + agrif_int((s_parent(3)-s_child(3))/ds_child(3))
+      if (Agrif_UseSpecialValueInUpdate) then
+        do k=indmin(3),indmax(3)
+          do kk=-coeffraf/2+locind_child_left+diffmod, &
+                   coeffraf/2+locind_child_left
+            do j=indmin(2),indmax(2)
+            do i=indmin(1),indmax(1)
+               if (tabtemp(i,j,kk) /= Agrif_SpecialValueFineGrid) then
+                  tempP(i,j,k) = tempP(i,j,k) + tabtemp(i,j,kk)
+               endif
+            enddo
+            enddo
+          enddo
+          locind_child_left = locind_child_left + coeffraf
+        enddo
+      else
+        do k=indmin(3),indmax(3)
+          do kk=-coeffraf/2+locind_child_left+diffmod, &
+                   coeffraf/2+locind_child_left
+            do j=indmin(2),indmax(2)
+            do i=indmin(1),indmax(1)
+                  tempP(i,j,k) = tempP(i,j,k) + tabtemp(i,j,kk)
+            enddo
+            enddo
+          enddo
+          locind_child_left = locind_child_left + coeffraf
+        enddo
+        if (.not.Agrif_Update_Weights) tempP = tempP * invcoeffraf
+      endif
     else
-        tempP = 0.
         do j = indmin(2),indmax(2)
         do i = indmin(1),indmax(1)
@@ -1720,7 +1800,9 @@
                                   s_parent(3),s_child(3),               &
                                   ds_parent(3),ds_child(3))
-!
+
         enddo
         enddo
+
+
     endif
 !---------------------------------------------------------------------------------------------------
@@ -1734,9 +1816,9 @@
 !! Calls #Agrif_Update_3D_Recursive and #Agrif_UpdateBase.
 !---------------------------------------------------------------------------------------------------
-subroutine Agrif_Update_4D_Recursive ( type_update,         &
-                                       tempP, tempC,        &
-                                       indmin, indmax,      &
-                                       lb_child, ub_child,  &
-                                        s_child,  s_parent, &
+subroutine Agrif_Update_4D_Recursive ( type_update,                     &
+                                       tempP, tempC, tempC_indic,       &
+                                       indmin, indmax,                  &
+                                       lb_child, ub_child,              &
+                                       s_child,  s_parent,              &
                                        ds_child, ds_parent )
 !---------------------------------------------------------------------------------------------------
@@ -1744,6 +1826,6 @@
     integer, dimension(4),          intent(in)  :: indmin, indmax
     integer, dimension(4),          intent(in)  :: lb_child, ub_child
-    real,    dimension(4),          intent(in)  ::  s_child,  s_parent
-    real,    dimension(4),          intent(in)  :: ds_child, ds_parent
+    real(kind=8),    dimension(4),          intent(in)  ::  s_child,  s_parent
+    real(kind=8),    dimension(4),          intent(in)  :: ds_child, ds_parent
     real,    dimension(          &
         indmin(1):indmax(1),     &
@@ -1755,5 +1837,5 @@
         lb_child(2):ub_child(2), &
         lb_child(3):ub_child(3), &
-        lb_child(4):ub_child(4)),   intent(in)  :: tempC
+        lb_child(4):ub_child(4)),   intent(in)  :: tempC, tempC_indic
 !---------------------------------------------------------------------------------------------------
     real, dimension(:,:,:,:), allocatable       :: tabtemp
@@ -1771,4 +1853,7 @@
                                                indmin(3):indmax(3), l),     &
                                        tempC(lb_child(1):ub_child(1),       &
+                                             lb_child(2):ub_child(2),       &
+                                             lb_child(3):ub_child(3), l),   &
+                                       tempC_indic(lb_child(1):ub_child(1),       &
                                              lb_child(2):ub_child(2),       &
                                              lb_child(3):ub_child(3), l),   &
@@ -1806,9 +1891,9 @@
 !! Calls #Agrif_Update_4D_Recursive and #Agrif_UpdateBase.
 !---------------------------------------------------------------------------------------------------
-subroutine Agrif_Update_5D_Recursive ( type_update,         &
-                                       tempP, tempC,        &
-                                       indmin, indmax,      &
-                                       lb_child, ub_child,  &
-                                        s_child,  s_parent, &
+subroutine Agrif_Update_5D_Recursive ( type_update,                     &
+                                       tempP, tempC, tempC_indic,       &
+                                       indmin, indmax,                  &
+                                       lb_child, ub_child,              &
+                                       s_child,  s_parent,              &
                                        ds_child, ds_parent )
 !---------------------------------------------------------------------------------------------------
@@ -1816,6 +1901,6 @@
     integer, dimension(5),          intent(in)  :: indmin, indmax
     integer, dimension(5),          intent(in)  :: lb_child, ub_child
-    real,    dimension(5),          intent(in)  ::  s_child,  s_parent
-    real,    dimension(5),          intent(in)  :: ds_child, ds_parent
+    real(kind=8),    dimension(5),          intent(in)  ::  s_child,  s_parent
+    real(kind=8),    dimension(5),          intent(in)  :: ds_child, ds_parent
     real,    dimension(          &
         indmin(1):indmax(1),     &
@@ -1829,5 +1914,5 @@
         lb_child(3):ub_child(3), &
         lb_child(4):ub_child(4), &
-        lb_child(5):ub_child(5)),   intent(in)  :: tempC
+        lb_child(5):ub_child(5)),   intent(in)  :: tempC, tempC_indic
 !---------------------------------------------------------------------------------------------------
     real, dimension(:,:,:,:,:), allocatable     :: tabtemp
@@ -1847,4 +1932,8 @@
                                                indmin(4):indmax(4), m),     &
                                        tempC(lb_child(1):ub_child(1),       &
+                                             lb_child(2):ub_child(2),       &
+                                             lb_child(3):ub_child(3),       &
+                                             lb_child(4):ub_child(4), m),   &
+                                       tempC_indic(lb_child(1):ub_child(1),       &
                                              lb_child(2):ub_child(2),       &
                                              lb_child(3):ub_child(3),       &
@@ -1885,9 +1974,9 @@
 !! Calls #Agrif_Update_5D_Recursive and #Agrif_UpdateBase.
 !---------------------------------------------------------------------------------------------------
-subroutine Agrif_Update_6D_Recursive ( type_update,         &
-                                       tempP, tempC,        &
-                                       indmin, indmax,      &
-                                       lb_child, ub_child,  &
-                                        s_child,  s_parent, &
+subroutine Agrif_Update_6D_Recursive ( type_update,                     &
+                                       tempP, tempC, tempC_indic,       &
+                                       indmin, indmax,                  &
+                                       lb_child, ub_child,              &
+                                       s_child,  s_parent,              &
                                        ds_child, ds_parent )
 !---------------------------------------------------------------------------------------------------
@@ -1895,6 +1984,6 @@
     integer, dimension(6),          intent(in)  :: indmin, indmax
     integer, dimension(6),          intent(in)  :: lb_child, ub_child
-    real,    dimension(6),          intent(in)  ::  s_child,  s_parent
-    real,    dimension(6),          intent(in)  :: ds_child, ds_parent
+    real(kind=8),    dimension(6),          intent(in)  ::  s_child,  s_parent
+    real(kind=8),    dimension(6),          intent(in)  :: ds_child, ds_parent
     real,    dimension(          &
         indmin(1):indmax(1),     &
@@ -1910,5 +1999,5 @@
         lb_child(4):ub_child(4), &
         lb_child(5):ub_child(5), &
-        lb_child(6):ub_child(6)),   intent(in)  :: tempC
+        lb_child(6):ub_child(6)),   intent(in)  :: tempC, tempC_indic
 !---------------------------------------------------------------------------------------------------
     real, dimension(:,:,:,:,:,:), allocatable   :: tabtemp
@@ -1930,4 +2019,9 @@
                                                indmin(5):indmax(5), n),     &
                                        tempC(lb_child(1):ub_child(1),       &
+                                             lb_child(2):ub_child(2),       &
+                                             lb_child(3):ub_child(3),       &
+                                             lb_child(4):ub_child(4),       &
+                                             lb_child(5):ub_child(5), n),   &
+                                       tempC_indic(lb_child(1):ub_child(1),       &
                                              lb_child(2):ub_child(2),       &
                                              lb_child(3):ub_child(3),       &
@@ -1982,6 +2076,6 @@
     real, dimension(indmin:indmax),     intent(out):: parent_tab
     real, dimension(lb_child:ub_child), intent(in) :: child_tab
-    real,                               intent(in) :: s_parent,  s_child
-    real,                               intent(in) :: ds_parent, ds_child
+    real(kind=8),                       intent(in) :: s_parent,  s_child
+    real(kind=8),                       intent(in) :: ds_parent, ds_child
 !---------------------------------------------------------------------------------------------------
     integer :: np       ! Length of parent array
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modupdatebasic.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modupdatebasic.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modupdatebasic.F90	(revision 10087)
@@ -49,8 +49,8 @@
     integer,             intent(in)     :: np           !< Length of parent array
     integer,             intent(in)     :: nc           !< Length of child  array
-    real,                intent(in)     :: s_parent     !< Parent grid position (s_root = 0)
-    real,                intent(in)     :: s_child      !< Child  grid position (s_root = 0)
-    real,                intent(in)     :: ds_parent    !< Parent grid dx (ds_root = 1)
-    real,                intent(in)     :: ds_child     !< Child  grid dx (ds_root = 1)
+    real(kind=8),        intent(in)     :: s_parent     !< Parent grid position (s_root = 0)
+    real(kind=8),        intent(in)     :: s_child      !< Child  grid position (s_root = 0)
+    real(kind=8),        intent(in)     :: ds_parent    !< Parent grid dx (ds_root = 1)
+    real(kind=8),        intent(in)     :: ds_child     !< Child  grid dx (ds_root = 1)
 !---------------------------------------------------------------------------------------------------
     integer :: i, locind_child_left, coeffraf
@@ -84,8 +84,8 @@
     integer,             intent(in)     :: np           !< Length of parent array
     integer,             intent(in)     :: nc           !< Length of child  array
-    real,                intent(in)     :: s_parent     !< Parent grid position (s_root = 0)
-    real,                intent(in)     :: s_child      !< Child  grid position (s_root = 0)
-    real,                intent(in)     :: ds_parent    !< Parent grid dx (ds_root = 1)
-    real,                intent(in)     :: ds_child     !< Child  grid dx (ds_root = 1)
+    real(kind=8),        intent(in)     :: s_parent     !< Parent grid position (s_root = 0)
+    real(kind=8),        intent(in)     :: s_child      !< Child  grid position (s_root = 0)
+    real(kind=8),        intent(in)     :: ds_parent    !< Parent grid dx (ds_root = 1)
+    real(kind=8),        intent(in)     :: ds_child     !< Child  grid dx (ds_root = 1)
     integer,             intent(in)     :: dir          !< Direction
 !---------------------------------------------------------------------------------------------------
@@ -157,9 +157,10 @@
     REAL, DIMENSION(nc), intent(in)     :: y
     INTEGER,             intent(in)     :: np,nc
-    REAL,                intent(in)     :: s_parent,  s_child
-    REAL,                intent(in)     :: ds_parent, ds_child
+    REAL(kind=8),        intent(in)     :: s_parent,  s_child
+    REAL(kind=8),        intent(in)     :: ds_parent, ds_child
 !
     INTEGER :: i, ii, locind_child_left, coeffraf
-    REAL    :: xpos, invcoeffraf
+    REAL(kind=8)    :: xpos
+    REAL ::  invcoeffraf
     INTEGER :: nbnonnuls
     INTEGER :: diffmod
@@ -229,11 +230,11 @@
 !---------------------------------------------------------------------------------------------------
     INTEGER, intent(in) :: nc2, np, nc
-    REAL,    intent(in) :: s_parent,  s_child
-    REAL,    intent(in) :: ds_parent, ds_child
+    REAL(kind=8),    intent(in) :: s_parent,  s_child
+    REAL(kind=8),    intent(in) :: ds_parent, ds_child
     INTEGER, intent(in) :: dir
 !
     INTEGER, DIMENSION(:,:), ALLOCATABLE :: indchildaverage_tmp
     INTEGER :: i, locind_child_left, coeffraf
-    REAL    :: xpos
+    REAL(kind=8)    :: xpos
     INTEGER :: diffmod
 !
@@ -281,6 +282,6 @@
     REAL, DIMENSION(nc), intent(in)     :: y
     INTEGER,             intent(in)     :: np, nc
-    REAL,                intent(in)     :: s_parent,  s_child
-    REAL,                intent(in)     :: ds_parent, ds_child
+    REAL(kind=8),                intent(in)     :: s_parent,  s_child
+    REAL(kind=8),                intent(in)     :: ds_parent, ds_child
     INTEGER,             intent(in)     :: dir
 !
@@ -311,10 +312,9 @@
     ELSE
 !
-!CDIR NOLOOPCHG
-        do  j = 1,coeffraf
-!CDIR VECTOR
-            do i= 1,np
+
+        do i = 1,np
+        do j = 1,coeffraf
                 x(i) = x(i) + y(indchildaverage(i,dir) + j-1 )
-            enddo
+        enddo
         enddo
         IF (.not.Agrif_Update_Weights) THEN
@@ -338,8 +338,8 @@
     real, dimension(nc), intent(in)     :: y
     integer,             intent(in)     :: np, nc
-    real,                intent(in)     :: s_parent,  s_child
-    real,                intent(in)     :: ds_parent, ds_child
-!---------------------------------------------------------------------------------------------------
-    REAL    :: xpos, xposfin
+    real(kind=8),                intent(in)     :: s_parent,  s_child
+    real(kind=8),                intent(in)     :: ds_parent, ds_child
+!---------------------------------------------------------------------------------------------------
+    REAL(kind=8)    :: xpos, xposfin
     INTEGER :: i, ii, diffmod
     INTEGER :: it1, it2
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduserfunctions.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduserfunctions.F90	(revision 10087)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduserfunctions.F90	(revision 10087)
@@ -0,0 +1,1333 @@
+!
+! $Id: modcurgridfunctions.F 774 2007-12-18 16:45:53Z rblod $
+!
+!     AGRIF (Adaptive Grid Refinement In Fortran)
+!
+!     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+!                        Christophe Vouland (Christophe.Vouland@imag.fr)
+!
+!     This program is free software; you can redistribute it and/or modify
+!     it under the terms of the GNU General Public License as published by
+!     the Free Software Foundation; either version 2 of the License, or
+!     (at your option) any later version.
+!
+!     This program is distributed in the hope that it will be useful,
+!     but WITHOUT ANY WARRANTY; without even the implied warranty of
+!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+!     GNU General Public License for more details.
+!
+!     You should have received a copy of the GNU General Public License
+!     along with this program; if not, write to the Free Software
+!     Foundation, Inc., 59 Temple Place-  Suite 330, Boston, MA 02111-1307, USA.
+!
+!-------------------------------------------------------------------------------
+!> Module Agrif_user_Functions
+!!
+!! This module defines procedures concerning current grids informations.
+!-------------------------------------------------------------------------------
+!
+module Agrif_User_Functions
+!
+! Module used:
+  use Agrif_Init
+  use Agrif_Grids
+!
+    implicit none
+!
+
+    interface Agrif_Parent
+        module procedure Agrif_Parent_Real_4,   &
+                         Agrif_Parent_Real_8,   &
+                         Agrif_Parent_Integer, &
+                         Agrif_Parent_Character, &
+                         Agrif_Parent_Logical
+    end interface
+
+    interface Agrif_Set_Parent
+        module procedure Agrif_Set_Parent_int,      &
+                         Agrif_Set_Parent_real4,    &
+                         Agrif_Set_Parent_real8
+    end interface
+    
+contains
+!
+!===================================================================================================
+!  subroutine Agrif_Set_parent_int
+!
+!> This subroutine is used to set the type of the variable of the parent grid of the 
+!! current grid as integer variable.
+!
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_parent_int(integer_variable,value)
+!---------------------------------------------------------------------------------------------------
+    integer, intent(in)     :: integer_variable !< indice of the variable in tabvars
+    integer, intent(in)     :: value        !< input value
+!
+    
+integer :: i
+logical :: i_found
+
+i_found = .FALSE.
+
+do i=1,Agrif_NbVariables(4)
+  if (LOC(integer_variable) == LOC(agrif_curgrid%tabvars_i(i)%iarray0)) then
+     agrif_curgrid%tabvars_i(i)%parent_var%iarray0 = value
+     i_found = .TRUE.
+     EXIT
+  endif
+enddo
+
+if (.NOT.i_found) STOP 'Agrif_Set_Integer : Variable not found'
+
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_parent_int
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_parent_real4
+!---------------------------------------------------------------------------------------------------
+!> This subroutine is used to set a real variable of the parent grid of the current 
+!! grid as Single-precision real floating-point value.
+!
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_parent_real4 ( real_variable, value )
+!---------------------------------------------------------------------------------------------------
+    real(kind=4), intent(in)     :: real_variable !< input variable
+    real(kind=4),intent(in) :: value        !< input value for the parent grid
+
+integer :: i
+logical :: i_found
+
+i_found = .FALSE.
+
+do i=1,Agrif_NbVariables(2)
+  if (LOC(real_variable) == LOC(agrif_curgrid%tabvars_r(i)%array0)) then
+     agrif_curgrid%tabvars_r(i)%parent_var%array0 = value
+     agrif_curgrid%tabvars_r(i)%parent_var%sarray0 = value
+     i_found = .TRUE.
+     EXIT
+  endif
+enddo
+
+IF (.NOT.i_found) THEN
+do i=1,Agrif_NbVariables(2)
+  if (LOC(real_variable) == LOC(agrif_curgrid%tabvars_r(i)%sarray0)) then
+     agrif_curgrid%tabvars_r(i)%parent_var%array0 = value
+     agrif_curgrid%tabvars_r(i)%parent_var%sarray0 = value
+     i_found = .TRUE.
+     EXIT
+  endif
+enddo
+ENDIF
+
+if (.NOT.i_found) STOP 'Agrif_Set_parent_real4 : Variable not found'
+
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_parent_real4
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_parent_real8
+!---------------------------------------------------------------------------------------------------
+!> This subroutine is used to set a real variable of the parent grid of the current 
+!! grid as Double-precision real floating-point value.
+!
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_parent_real8 ( real_variable, value )
+!---------------------------------------------------------------------------------------------------
+    real(kind=8), intent(in)     :: real_variable !< input variable
+    real(kind=8),intent(in) :: value        !< input value for the parent grid
+
+integer :: i
+logical :: i_found
+
+i_found = .FALSE.
+
+do i=1,Agrif_NbVariables(2)
+  if (LOC(real_variable) == LOC(agrif_curgrid%tabvars_r(i)%array0)) then
+     agrif_curgrid%tabvars_r(i)%parent_var%darray0 = value
+     agrif_curgrid%tabvars_r(i)%parent_var%array0 = value
+     i_found = .TRUE.
+     EXIT
+  endif
+enddo
+
+IF (.NOT.i_found) THEN
+do i=1,Agrif_NbVariables(2)
+  if (LOC(real_variable) == LOC(agrif_curgrid%tabvars_r(i)%darray0)) then
+     agrif_curgrid%tabvars_r(i)%parent_var%darray0 = value
+     agrif_curgrid%tabvars_r(i)%parent_var%array0 = value
+     i_found = .TRUE.
+     EXIT
+  endif
+enddo
+ENDIF
+
+if (.NOT.i_found) STOP 'Agrif_Set_parent_real8 : Variable not found'
+
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_parent_real8
+!===================================================================================================
+!
+!
+!===================================================================================================
+!  Function Agrif_rel_dt
+!
+!> Returns the time step of the current grid, relatively to the root grid (for which dt=1.).
+!!
+!! In fact, it is a real number which could be define as the ratio between the current grid time 
+!!step and the root grid time step.
+!---------------------------------------------------------------------------------------------------
+function Agrif_rel_dt ( ) result( rel_dt )
+!---------------------------------------------------------------------------------------------------
+    integer :: i
+    real    :: rel_dt !< time step
+!
+    rel_dt = 1.
+!
+    do i = 1,Agrif_Probdim
+        rel_dt = min(rel_dt, Agrif_Curgrid % Agrif_dt(i))
+    enddo
+!---------------------------------------------------------------------------------------------------
+end function Agrif_rel_dt
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_rel_idt
+!
+!> This function returns an integer which is the time refinement factor of the current grid, 
+!! relatively to the root grid (for which time step = 1).
+!!
+!! It is the inverse of Agrif_rel_dt set to integer. Here, it is the ratio between the time step 
+!! of the root grid and the time step of the current grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_rel_idt ( ) result( rel_idt )
+!---------------------------------------------------------------------------------------------------
+    integer :: rel_idt !< time step
+!
+    rel_idt = nint(1./Agrif_rel_dt())
+!---------------------------------------------------------------------------------------------------
+end function Agrif_rel_idt
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_IRhot
+!
+!> This function returns an integer number which is the time refinement factor of the current grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_IRhot ( ) result( irhot )
+!---------------------------------------------------------------------------------------------------
+    integer :: i
+    integer :: irhot !< time refinement factor of the current grid
+!
+    irhot = 1
+!
+    do i = 1,Agrif_Probdim
+        irhot = max(irhot, Agrif_Curgrid % timeref(i))
+    enddo
+!---------------------------------------------------------------------------------------------------
+end function Agrif_IRhot
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_Rhot
+!
+!> This function returns a real number which is the time refinement factor of the current grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Rhot ( ) result( rhot )
+!---------------------------------------------------------------------------------------------------
+    real    :: rhot !< time refinement factor of the current grid
+!
+    rhot = float(Agrif_IRhot())
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Rhot
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_Parent_IRhot
+!
+!> This function returns an integer number which represents the time refinement factor of the parent of the current grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Parent_IRhot ( ) result( irhot )
+!---------------------------------------------------------------------------------------------------
+    integer :: i
+    integer :: irhot !< time refinement factor of the parent grid
+!
+    irhot = 1
+!
+    do i = 1,Agrif_Probdim
+        irhot = max(irhot, Agrif_Curgrid % parent % timeref(i))
+    enddo
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Parent_IRhot
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_Parent_Rhot
+!
+!> Returns a real number which represents the time refinement factor of the parent of the current grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Parent_Rhot ( ) result( rhot )
+!---------------------------------------------------------------------------------------------------
+    real :: rhot !< time refinement factor of the parent grid
+!
+    rhot = float(Agrif_Parent_IRhot())
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Parent_Rhot
+!===================================================================================================
+!
+!===================================================================================================
+!  Function Agrif_Nbstepint
+!
+!> This function returns an integer which is the time step of the current grid inside one time 
+!! step of its parent grid. 
+!!
+!! It variates from zero to the time refinement factor of the current grid minus 1 (Agrif_Rhot - 1).
+!! It is useful for example for interpolation/update.
+!
+!---------------------------------------------------------------------------------------------------
+function Agrif_Nbstepint ( )
+!---------------------------------------------------------------------------------------------------
+    integer :: Agrif_nbstepint !< time step of the current grid
+!
+    Agrif_nbstepint = mod(Agrif_Curgrid % ngridstep, Agrif_iRhot())
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Nbstepint
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_Parent_Nbstepint
+!
+!> It returns an integer which represents time step of the parent grid inside one time step of its 
+!! parent grid.
+!!
+!! It variates from zero to the time refinement factor of the parent grid minus 1 (Agrif_Parent_Rhot - 1).
+!---------------------------------------------------------------------------------------------------
+function Agrif_Parent_Nbstepint ( )
+!---------------------------------------------------------------------------------------------------
+    integer :: Agrif_Parent_Nbstepint !< time step of the parent grid
+!
+    Agrif_Parent_Nbstepint = mod(Agrif_Curgrid % parent % ngridstep, int(Agrif_Parent_Rhot()))
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Parent_Nbstepint
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_InterpNearBorderX
+!
+!> Allows to interpolate (in the x direction) on a near (West) border of the current grid if this one
+!! has a common border with the root coarse grid.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_InterpNearBorderX ( )
+!---------------------------------------------------------------------------------------------------
+    Agrif_Curgrid % NearRootBorder(1) = .FALSE.
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_InterpNearBorderX
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_InterpDistantBorderX
+!
+!> Allows to interpolate (in the x direction) on a distant (East) border of the current grid if this one
+!! has a common border with the root coarse grid.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_InterpDistantBorderX ( )
+!---------------------------------------------------------------------------------------------------
+    Agrif_Curgrid % DistantRootBorder(1) = .FALSE.
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_InterpDistantBorderX
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_InterpNearBorderY
+!
+!> Allows to interpolate (in the y direction) on a near (South) border of the current grid if this one
+!! has a common border with the root coarse grid.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_InterpNearBorderY ( )
+!---------------------------------------------------------------------------------------------------
+    Agrif_Curgrid % NearRootBorder(2) = .FALSE.
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_InterpNearBorderY
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_InterpDistantBorderY
+!
+!> Allows to interpolate (in the y direction) on a distant (North) border of the current grid if this one
+!! has a common border with the root coarse grid.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_InterpDistantBorderY ( )
+!---------------------------------------------------------------------------------------------------
+    Agrif_Curgrid % DistantRootBorder(2) = .FALSE.
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_InterpDistantBorderY
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_InterpNearBorderZ
+!
+!> Allows to interpolate (in the z direction) on a near (Down) border of the current grid if this one
+!! has a common border with the root coarse grid.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_InterpNearBorderZ ( )
+!---------------------------------------------------------------------------------------------------
+    Agrif_Curgrid % NearRootBorder(3) = .FALSE.
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_InterpNearBorderZ
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_InterpDistantBorderZ
+!
+!> Allows to interpolate (in the z direction) on a distant (Up) border of the current grid if this one
+!! has a common border with the root coarse grid.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_InterpDistantBorderZ()
+!---------------------------------------------------------------------------------------------------
+    Agrif_Curgrid % DistantRootBorder(3) = .FALSE.
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_InterpDistantBorderZ
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_Parent_Nb_Step
+!
+!> This function returns an integer which is the number of time step of the parent of the current grid.
+!!
+!! In fact, it indicates the number of iterations done on the parent grid of the current grid 
+!! since the start of the time integration of the grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Parent_Nb_Step ( )
+!---------------------------------------------------------------------------------------------------
+    integer :: Agrif_Parent_Nb_Step !< time step of the parent of the current grid
+!
+    if (Agrif_Root()) then
+        Agrif_Parent_Nb_Step = -1
+    else
+        Agrif_Parent_Nb_Step = Agrif_Curgrid % parent % ngridstep
+    endif
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Parent_Nb_Step
+!===================================================================================================
+!
+!===================================================================================================
+!  Function Agrif_Root
+!
+!> This function returns a logical which indicates if the current grid is the root grid or not.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Root ( )
+!---------------------------------------------------------------------------------------------------
+    logical :: Agrif_Root !  Result
+!
+    Agrif_Root = (Agrif_Curgrid % fixedrank == 0)
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Root
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_GrandMother
+!
+!> This function returns a logical which indicates if the current grid is the grandmother grid or not.
+!---------------------------------------------------------------------------------------------------
+function Agrif_GrandMother ( )
+!---------------------------------------------------------------------------------------------------
+    logical :: Agrif_GrandMother ! Result
+!
+    Agrif_GrandMother = Agrif_Curgrid % grand_mother_grid
+!---------------------------------------------------------------------------------------------------
+end function Agrif_GrandMother
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_Parent_Root
+!
+!> This function indicates if the parent of the current grid is the root grid or not.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Parent_Root ( )
+!---------------------------------------------------------------------------------------------------
+    logical :: Agrif_Parent_Root ! Result
+!
+    Agrif_Parent_Root = (Agrif_Curgrid % parent % fixedrank == 0)
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Parent_Root
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_Fixed
+!
+!> This function returns the number of the current grid.
+!!
+!!Indeed, it returns 0 for the coarse grid, a positive number for a fixed grid and -1 for a non fixed grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Fixed ( )
+!---------------------------------------------------------------------------------------------------
+    integer :: Agrif_Fixed   !< Result
+!
+    if (Agrif_Curgrid % fixed) then
+        Agrif_Fixed = Agrif_Curgrid % fixedrank
+    else
+        Agrif_Fixed = -1
+    endif
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Fixed
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_Parent_Fixed
+!
+!> This function returns the number of the parent of the current grid.
+!!
+!!Indeed, it returns 0 for the coarse grid and non fixed parent grid and positive number for a fixed grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Parent_Fixed ( )
+!---------------------------------------------------------------------------------------------------
+    integer :: Agrif_Parent_Fixed   ! Result
+!
+    if (Agrif_Curgrid % parent % fixed) then
+        Agrif_Parent_Fixed = Agrif_Curgrid % parent % fixedrank
+    else
+        Agrif_Parent_Fixed = 0
+    endif
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Parent_Fixed
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_Is_Fixed
+!
+!> This function returns .TRUE. if the current grid is fixed even if we are on the root grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Is_Fixed ( )
+!---------------------------------------------------------------------------------------------------
+    logical :: Agrif_Is_Fixed   ! Result
+!
+    Agrif_Is_Fixed = Agrif_Curgrid % fixed
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Is_Fixed
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_Parent_Is_Fixed
+!
+!> This function returns .TRUE. if the parent grid of the current grid is fixed even if we are on the root grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Parent_Is_Fixed ( )
+!---------------------------------------------------------------------------------------------------
+    logical :: Agrif_Parent_Is_Fixed   ! Result
+!
+    Agrif_Parent_Is_Fixed = Agrif_Curgrid % parent % fixed
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Parent_Is_Fixed
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_CFixed
+!
+!> This function returns the number of the current grid as a string.
+!---------------------------------------------------------------------------------------------------
+function Agrif_CFixed ( )
+!---------------------------------------------------------------------------------------------------
+    character(3) :: Agrif_CFixed   ! Result
+!
+    character(3) :: cfixed
+    integer      :: fixed
+!
+    fixed = Agrif_Fixed()
+!
+    if (fixed /= -1) then
+!
+        if (fixed <= 9) then
+            write(cfixed,'(i1)') fixed
+        else
+            write(cfixed,'(i2)') fixed
+        endif
+!
+        Agrif_CFixed = cfixed
+        
+        if (associated(agrif_curgrid,agrif_coarsegrid)) then
+          Agrif_CFixed = 'gm'
+        endif
+!
+    else
+        print*,'Call to Agrif_CFixed() on a moving grid'
+        stop
+    endif
+!---------------------------------------------------------------------------------------------------
+end function Agrif_CFixed
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_Parent_CFixed
+!
+!> This function returns the number of the parent of the current grid as a string.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Parent_CFixed ( )
+!---------------------------------------------------------------------------------------------------
+    character(3) :: Agrif_Parent_CFixed   ! Result
+!
+    character(3) :: cfixed
+    integer      :: fixed
+!
+    fixed = Agrif_Parent_Fixed()
+!
+    if(fixed /= -1) then
+!
+        if (fixed <= 9) then
+            write(cfixed,'(i1)')fixed
+        else
+            write(cfixed,'(i2)')fixed
+        endif
+!
+        Agrif_Parent_CFixed=cfixed
+!
+    else
+        print*,'Illegal call to Agrif_Parent_CFixed()'
+        stop
+    endif
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Parent_CFixed
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_ChildGrid_to_ParentGrid
+!
+!> This subroutine makes #Agrif_Curgrid point on the parent grid of the current grid.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_ChildGrid_to_ParentGrid ( )
+!---------------------------------------------------------------------------------------------------
+    Agrif_Curgrid % parent % save_grid => Agrif_Curgrid
+    call Agrif_Instance(Agrif_Curgrid%parent)
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_ChildGrid_to_ParentGrid
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_ParentGrid_to_ChildGrid
+!
+!> This subroutine makes the pointer #Agrif_Curgrid point on the child grid after having called the subroutine
+!! :agrifdoc:`moduserfunctions.F90::agrif_childgrid_to_parentgrid<Agrif_ChildGrid_to_ParentGrid()>` .
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_ParentGrid_to_ChildGrid ( )
+!---------------------------------------------------------------------------------------------------
+    call Agrif_Instance(Agrif_Curgrid%save_grid)
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_ParentGrid_to_ChildGrid
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_Get_Unit
+!
+!> This function returns a unit not connected to any file.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Get_Unit ( )
+!---------------------------------------------------------------------------------------------------
+    integer :: Agrif_Get_Unit  ! Result
+!
+    integer :: n
+    logical :: op
+!
+    integer :: nunit
+    integer :: iii, out, iiimax
+    logical :: bexist
+    integer,dimension(1:1000) :: forbiddenunit
+!
+!   Load forbidden Unit if the file Agrif_forbidenUnit exist
+!
+    INQUIRE(file='Agrif_forbiddenUnit.txt', exist=bexist)
+!
+    if (.not. bexist) then
+!       File Agrif_forbiddenUnit.txt not found
+    else
+        nunit = 777
+        OPEN(nunit,file='Agrif_forbiddenUnit.txt', form='formatted', status="old")
+        iii = 1
+        do while ( .TRUE. )
+            READ(nunit,*, end=99) forbiddenunit(iii)
+            iii = iii + 1
+        enddo
+   99   continue
+        iiimax = iii
+        close(nunit)
+    endif
+!
+    do n = 7,1000
+!
+        INQUIRE(Unit=n,Opened=op)
+!
+        out = 0
+        if ( bexist .AND. (.NOT.op) ) then
+            do iii = 1,iiimax
+                if ( n == forbiddenunit(iii) ) out = 1
+            enddo
+        endif
+!
+        if ( (.NOT.op) .AND. (out == 0) ) exit
+!
+    enddo
+!
+    Agrif_Get_Unit = n
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Get_Unit
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_Extra_Boundary_Cells
+!> This subroutine is used to set the number of extra boundary cells which is take as input parameter.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_Extra_Boundary_Cells ( nb_extra_cells )
+!---------------------------------------------------------------------------------------------------
+    integer, intent(in) :: nb_extra_cells !< number of extra cells
+!
+    Agrif_Extra_Boundary_Cells = nb_extra_cells
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_Extra_Boundary_Cells
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_Efficiency
+!> This subroutine is used to set the efficiency which is taken as input parameter.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_Efficiency ( eff )
+!---------------------------------------------------------------------------------------------------
+    real, intent(in) :: eff !< efficiency
+!
+    if ( (eff < 0.) .OR. (eff > 1) ) then
+        write(*,*) 'Error Efficiency should be between 0 and 1'
+        stop
+    else
+        Agrif_Efficiency = eff
+    endif
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_Efficiency
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_Regridding
+!> This subroutine is used to set the regridding frequency which is taken as input parameter
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_Regridding ( regfreq )
+!---------------------------------------------------------------------------------------------------
+    integer, intent(in) :: regfreq !< Regridding frequency
+!
+    if (regfreq < 0) then
+        write(*,*) 'Regridding frequency should be positive'
+        stop
+    else
+        Agrif_Regridding = regfreq
+    endif
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_Regridding
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_coeffref_x
+!> This subroutine is used to set the space refinement coefficient in the x direction (first dimension).
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_coeffref_x ( coeffref )
+!---------------------------------------------------------------------------------------------------
+    integer, intent(in) :: coeffref !< Coefficient of spatial refinement
+
+      if (coeffref < 0) then
+         write(*,*) 'Coefficient of refinement should be positive'
+         stop
+      else
+         Agrif_coeffref(1) = coeffref
+      endif
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_coeffref_x
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_coeffref_y
+!> This subroutine is used to set the space refinement coefficient in the y direction (second dimension).
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_coeffref_y ( coeffref )
+!---------------------------------------------------------------------------------------------------
+    integer, intent(in) :: coeffref !< Coefficient of spatial refinement
+
+    if (coeffref < 0) then
+        write(*,*) 'Coefficient of refinement should be positive'
+        stop
+    else
+        Agrif_coeffref(2) = coeffref
+    endif
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_coeffref_y
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_coeffref_z
+!> This subroutine is used to set the space refinement coefficient in the z direction (third dimension).
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_coeffref_z ( coeffref )
+!---------------------------------------------------------------------------------------------------
+    integer, intent(in) :: coeffref !< Coefficient of spatial refinement
+!
+    if (coeffref < 0) then
+        write(*,*) 'Coefficient of refinement should be positive'
+        stop
+    else
+        Agrif_coeffref(3) = coeffref
+    endif
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_coeffref_z
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_coeffreft_x
+!> This subroutine is used to set the time refinement factor in x direction (first dimension).
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_coeffreft_x ( coeffref )
+!---------------------------------------------------------------------------------------------------
+    integer, intent(in) :: coeffref !< Coefficient of time refinement
+
+    if (coeffref < 0) then
+        write(*,*) 'Coefficient of time refinement should be positive'
+        stop
+    else
+        Agrif_coeffreft(1) = coeffref
+    endif
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_coeffreft_x
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_coeffreft_y
+!> This subroutine is used to set the time refinement factor in y direction (second dimension).
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_coeffreft_y ( coeffref )
+!---------------------------------------------------------------------------------------------------
+    integer, intent(in) :: coeffref !< Coefficient of time refinement
+!
+    if (coeffref < 0) then
+        write(*,*) 'Coefficient of time refinement should be positive'
+        stop
+    else
+        Agrif_coeffreft(2) = coeffref
+    endif
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_coeffreft_y
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_coeffreft_z
+!> This subroutine is used to set the time refinement coefficient in the z direction (third dimension).
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_coeffreft_z ( coeffref )
+!---------------------------------------------------------------------------------------------------
+    integer, intent(in) :: coeffref
+
+    if (coeffref < 0) then
+        write(*,*)'Coefficient of time refinement should be positive'
+        stop
+    else
+        Agrif_coeffreft(3) = coeffref
+    endif
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_coeffreft_z
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_Minwidth
+!> This subroutine is used to set the minimum width which is taken as input parameter.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_Minwidth ( coefminwidth )
+!---------------------------------------------------------------------------------------------------
+    integer, intent(in) :: coefminwidth !< Coefficient of minwidth
+!
+    if (coefminwidth < 0) then
+        write(*,*)'Coefficient of Minwidth should be positive'
+        stop
+    else
+        Agrif_Minwidth = coefminwidth
+    endif
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_Minwidth
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_Rafmax
+!> This subroutine is used to set the maximal level in x,y and z-direction which is taken as input parameter. 
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_Rafmax ( coefrafmax )
+!---------------------------------------------------------------------------------------------------
+    integer, intent(in) :: coefrafmax !< maximal space refinement coefficient
+!
+    integer :: i
+    real    :: res
+!
+    if (coefrafmax < 0) then
+        write(*,*)'Refinement coefficient should be positive'
+        stop
+    else
+        res = 1.
+        do i = 1,coefrafmax-1
+            res = res * FLOAT(Agrif_coeffref(1))
+        enddo
+        if ( res == 0 ) res = 1
+        Agrif_Mind(1) = 1.d0 / real(res,kind=8)
+!
+        res = 1.
+        do i = 1,coefrafmax-1
+            res = res * FLOAT(Agrif_coeffref(2))
+        enddo
+        if ( res == 0 ) res = 1
+        Agrif_Mind(2) = 1.d0 / real(res,kind=8)
+!
+        res = 1.
+        do i = 1,coefrafmax-1
+            res = res * FLOAT(Agrif_coeffref(3))
+        enddo
+        if ( res == 0 ) res = 1
+        Agrif_Mind(3) = 1.d0 / real(res,kind=8)
+!
+      endif
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_Rafmax
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_MaskMaxSearch
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_MaskMaxSearch ( mymaxsearch )
+!---------------------------------------------------------------------------------------------------
+    integer, intent(in) :: mymaxsearch !< input variables
+!
+    MaxSearch = mymaxsearch
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_MaskMaxSearch
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_Level
+!> This function returns the level of the current grid in the grids hierarchy.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Level ( )
+!---------------------------------------------------------------------------------------------------
+    integer :: Agrif_Level  !< level of the current grid
+!
+    Agrif_Level = Agrif_Curgrid % level
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Level
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_MaxLevel
+!> This function returns the maximum level of grid location in the hierarchy.
+!---------------------------------------------------------------------------------------------------
+function Agrif_MaxLevel ( )
+!---------------------------------------------------------------------------------------------------
+    integer :: Agrif_MaxLevel  ! Result
+!
+    Agrif_MaxLevel = Agrif_MaxLevelLoc
+!---------------------------------------------------------------------------------------------------
+end function Agrif_MaxLevel
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_GridAllocation_is_done
+!> This function is used to verify if the the allocation is done for the current grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_GridAllocation_is_done ( ) result(isdone)
+!---------------------------------------------------------------------------------------------------
+    logical :: isdone ! Result
+!
+    isdone = Agrif_Curgrid % allocation_is_done
+!---------------------------------------------------------------------------------------------------
+end function Agrif_GridAllocation_is_done
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_Parent_Real_4
+!> This function returns the list of real grid variables of the parent of the current grid as single-precision 
+!! real floating-point.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Parent_Real_4(real_variable) result(real_variable_parent)
+!---------------------------------------------------------------------------------------------------
+real(KIND=4) :: real_variable !< input real variable
+real(KIND=4) :: real_variable_parent  ! Result
+
+integer :: i
+logical :: i_found
+
+i_found = .FALSE.
+
+do i=1,Agrif_NbVariables(2)
+  if (LOC(real_variable) == LOC(agrif_curgrid%tabvars_r(i)%array0)) then
+     real_variable_parent = agrif_curgrid%tabvars_r(i)%parent_var%array0
+     i_found = .TRUE.
+     EXIT
+  endif
+enddo
+
+IF (.NOT.i_found) THEN
+do i=1,Agrif_NbVariables(2)
+  if (LOC(real_variable) == LOC(agrif_curgrid%tabvars_r(i)%sarray0)) then
+     real_variable_parent = agrif_curgrid%tabvars_r(i)%parent_var%sarray0
+     i_found = .TRUE.
+     EXIT
+  endif
+enddo
+ENDIF
+
+if (.NOT.i_found) STOP 'Agrif_Parent_Real_4 : Variable not found'
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Parent_Real_4
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_Parent_Real_8
+!> This function returns the list of real grid variables of the parent of the current grid as double-precision 
+!! real floating-point.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Parent_Real_8(real_variable) result(real_variable_parent)
+!---------------------------------------------------------------------------------------------------
+real(KIND=8) :: real_variable !< input real variable
+real(KIND=8) :: real_variable_parent ! Result
+
+integer :: i
+logical :: i_found
+
+i_found = .FALSE.
+
+do i=1,Agrif_NbVariables(2)
+  if (LOC(real_variable) == LOC(agrif_curgrid%tabvars_r(i)%array0)) then
+     real_variable_parent = agrif_curgrid%tabvars_r(i)%parent_var%array0
+     i_found = .TRUE.
+     EXIT
+  endif
+enddo
+
+IF (.NOT.i_found) THEN
+do i=1,Agrif_NbVariables(2)
+  if (LOC(real_variable) == LOC(agrif_curgrid%tabvars_r(i)%darray0)) then
+     real_variable_parent = agrif_curgrid%tabvars_r(i)%parent_var%darray0
+     i_found = .TRUE.
+     EXIT
+  endif
+enddo
+ENDIF
+
+if (.NOT.i_found) STOP 'Agrif_Parent_Real_8 : Variable not found'
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Parent_Real_8
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_Parent_Integer
+!> This function returns the list of integer grid variables of the parent of the current grid as integer.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Parent_Integer(integer_variable) result(integer_variable_parent)
+integer :: integer_variable
+integer :: integer_variable_parent ! Result
+
+integer :: i
+logical :: i_found
+
+i_found = .FALSE.
+
+do i=1,Agrif_NbVariables(4)
+  if (LOC(integer_variable) == LOC(agrif_curgrid%tabvars_i(i)%iarray0)) then
+     integer_variable_parent = agrif_curgrid%tabvars_i(i)%parent_var%iarray0
+     i_found = .TRUE.
+     EXIT
+  endif
+enddo
+
+if (.NOT.i_found) STOP 'Agrif_Parent : Variable not found'
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Parent_Integer
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_Parent_Character
+!> This function returns the list of character grid variables of the parent of the current grid as character.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Parent_Character(character_variable) result(character_variable_parent)
+!---------------------------------------------------------------------------------------------------
+character(*) :: character_variable
+character(len(character_variable)) :: character_variable_parent ! Result
+
+integer :: i
+logical :: i_found
+
+i_found = .FALSE.
+
+do i=1,Agrif_NbVariables(1)
+  if (LOC(character_variable) == LOC(agrif_curgrid%tabvars_c(i)%carray0)) then
+     character_variable_parent = agrif_curgrid%tabvars_c(i)%parent_var%carray0
+     i_found = .TRUE.
+     EXIT
+  endif
+enddo
+
+if (.NOT.i_found) STOP 'Agrif_Parent : Variable not found'
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Parent_Character
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_Parent_Logical
+!> This function returns the list of logical grid variables of the parent of the current grid as logical variables.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Parent_Logical(logical_variable) result(logical_variable_parent)
+!---------------------------------------------------------------------------------------------------
+logical :: logical_variable    !
+logical :: logical_variable_parent   ! Result
+
+integer :: i
+logical :: i_found
+
+i_found = .FALSE.
+
+do i=1,Agrif_NbVariables(3)
+  if (LOC(logical_variable) == LOC(agrif_curgrid%tabvars_l(i)%larray0)) then
+     logical_variable_parent = agrif_curgrid%tabvars_l(i)%parent_var%larray0
+     i_found = .TRUE.
+     EXIT
+  endif
+enddo
+
+if (.NOT.i_found) STOP 'Agrif_Parent : Variable not found'
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Parent_Logical
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_Irhox
+!> This function is used to get the space refinement factor of the current grid in x direction (first dimension) set as integer.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Irhox() result(i_val)
+!---------------------------------------------------------------------------------------------------
+integer :: i_val  ! Result
+i_val = agrif_curgrid%spaceref(1)
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Irhox
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_Irhoy
+!> This function is used to get the space refinement factor of the current grid in y direction (second dimension) set as integer. 
+!---------------------------------------------------------------------------------------------------
+function Agrif_Irhoy() result(i_val)
+!---------------------------------------------------------------------------------------------------
+integer :: i_val  ! Result
+i_val = agrif_curgrid%spaceref(2)
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Irhoy
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_Irhoz
+!> This function is used to get the space refinement factor of the current grid in z direction (third dimension) set as integer. 
+!---------------------------------------------------------------------------------------------------
+function Agrif_Irhoz() result(i_val)
+!---------------------------------------------------------------------------------------------------
+integer :: i_val  ! Result
+i_val = agrif_curgrid%spaceref(3)
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Irhoz
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_NearCommonBorderX
+!> This function returns a logical which indicates whether the current grid and root grid have a common 
+!! border on the western side of the first dimension of space (the x direction).  
+!---------------------------------------------------------------------------------------------------
+function Agrif_NearCommonBorderX() result(l_val)
+!---------------------------------------------------------------------------------------------------
+logical :: l_val  ! Result
+l_val = agrif_curgrid%nearRootBorder(1)
+!---------------------------------------------------------------------------------------------------
+end function Agrif_NearCommonBorderX
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_NearCommonBorderY
+!> This function returns a logical which indicates whether the current grid and root grid have a common 
+!! border on the southern side of the second dimension of space (the y direction). 
+!---------------------------------------------------------------------------------------------------
+function Agrif_NearCommonBorderY() result(l_val)
+!---------------------------------------------------------------------------------------------------
+logical :: l_val  ! Result
+l_val = agrif_curgrid%nearRootBorder(2)
+!---------------------------------------------------------------------------------------------------
+end function Agrif_NearCommonBorderY
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_NearCommonBorderZ
+!> This function returns a logical which indicates whether the current grid and root grid have a common 
+!! border on the down side of the third dimension of space (the z direction).
+!---------------------------------------------------------------------------------------------------
+function Agrif_NearCommonBorderZ() result(l_val)
+!---------------------------------------------------------------------------------------------------
+logical :: l_val  ! Result
+l_val = agrif_curgrid%nearRootBorder(3)
+!---------------------------------------------------------------------------------------------------
+end function Agrif_NearCommonBorderZ
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_DistantCommonBorderX
+!> This function returns a logical which indicates whether the current grid and root grid have a common 
+!! border on the eastern side of the first dimension of space (the x direction).  
+!---------------------------------------------------------------------------------------------------
+function Agrif_DistantCommonBorderX() result(l_val)
+!---------------------------------------------------------------------------------------------------
+logical :: l_val  ! Result
+l_val = agrif_curgrid%DistantRootBorder(1)
+!---------------------------------------------------------------------------------------------------
+end function Agrif_DistantCommonBorderX
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_DistantCommonBorderY
+!> This function returns a logical which indicates whether the current grid and root grid have a common 
+!! border on the northern side of the second dimension of space (the y direction). 
+!---------------------------------------------------------------------------------------------------
+function Agrif_DistantCommonBorderY() result(l_val)
+!---------------------------------------------------------------------------------------------------
+logical :: l_val  ! Result
+l_val = agrif_curgrid%DistantRootBorder(2)
+!---------------------------------------------------------------------------------------------------
+end function Agrif_DistantCommonBorderY
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_DistantCommonBorderZ
+!> This function returns a logical which indicates whether the current grid and root grid have a common 
+!! border on the up side of the third dimension of space (the z direction).
+!---------------------------------------------------------------------------------------------------
+function Agrif_DistantCommonBorderZ() result(l_val)
+!---------------------------------------------------------------------------------------------------
+logical :: l_val  ! Result 
+l_val = agrif_curgrid%DistantRootBorder(3)
+!---------------------------------------------------------------------------------------------------
+end function Agrif_DistantCommonBorderZ
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_Ix
+!> This function returns an integer which indicates the minimal position of the current grid in the x direction.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Ix() result(i_val)
+!---------------------------------------------------------------------------------------------------
+integer :: i_val  !< minimal position
+i_val = agrif_curgrid%ix(1)
+end function Agrif_Ix
+!===================================================================================================
+! 
+!===================================================================================================
+! function Agrif_Iy
+!> This function returns an integer which indicates the minimal position of the current grid in the y direction.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Iy() result(i_val)
+!---------------------------------------------------------------------------------------------------
+integer :: i_val  !< minimal position
+i_val = agrif_curgrid%ix(2)
+end function Agrif_Iy
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_Iz
+!> This function returns an integer which indicates the minimal position of the current grid in the z direction.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Iz() result(i_val)
+!---------------------------------------------------------------------------------------------------
+integer :: i_val !< minimal position
+i_val = agrif_curgrid%ix(3)
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Iz
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_Get_grid_id
+!> This function is used to get the grid id of the current grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Get_grid_id() result(i_val)
+!---------------------------------------------------------------------------------------------------
+integer :: i_val !< grid id of the current grid
+i_val = agrif_curgrid % grid_id
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Get_grid_id
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_Get_parent_id
+!> This function is used to get the grid id of the parent grid of the current grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Get_parent_id() result(i_val)
+!---------------------------------------------------------------------------------------------------
+integer :: i_val !< grid id of the parent grid
+i_val = agrif_curgrid % parent % grid_id
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Get_parent_id
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_rhox
+!> This function returns a real number which represents the space refinement factor of the current grid 
+!! for the first dimension x. 
+!---------------------------------------------------------------------------------------------------
+function Agrif_rhox() result(r_val)
+!---------------------------------------------------------------------------------------------------
+real :: r_val !< space refinement factor
+r_val = real(agrif_curgrid%spaceref(1))
+!---------------------------------------------------------------------------------------------------
+end function Agrif_rhox
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_rhoy
+!> This function returns a real number which represents the space refinement factor of the current grid 
+!! for the second dimension y.
+!---------------------------------------------------------------------------------------------------
+function Agrif_rhoy() result(r_val)
+!---------------------------------------------------------------------------------------------------
+real :: r_val !< space refinement factor
+r_val = real(agrif_curgrid%spaceref(2))
+!---------------------------------------------------------------------------------------------------
+end function Agrif_rhoy
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_rhoz
+!> This function returns a real number which represents the space refinement factor of the current grid 
+!! for the third dimension z.
+!---------------------------------------------------------------------------------------------------
+function Agrif_rhoz() result(r_val)
+!---------------------------------------------------------------------------------------------------
+real :: r_val !< space refinement factor
+r_val = real(agrif_curgrid%spaceref(3))
+!---------------------------------------------------------------------------------------------------
+end function Agrif_rhoz
+!===================================================================================================
+!
+!===================================================================================================
+! function Agrif_Nb_Step
+!> This function returns an integer which represents the number of time steps of the current grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Nb_Step() result(i_val)
+!---------------------------------------------------------------------------------------------------
+integer :: i_val !< number of time steps
+i_val = agrif_curgrid%ngridstep
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Nb_Step
+!====================================================================================================
+!
+!===================================================================================================
+! function Agrif_Nb_Fine_Grids
+!> This function returns the number of fixed grids.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Nb_Fine_Grids() result(i_val)
+!---------------------------------------------------------------------------------------------------  
+  integer :: i_val
+  
+  i_val = Agrif_nbfixedgrids
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Nb_Fine_Grids
+!===================================================================================================
+
+end module Agrif_User_Functions
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduserhierarchy.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduserhierarchy.F90	(revision 10087)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduserhierarchy.F90	(revision 10087)
@@ -0,0 +1,1159 @@
+!
+! $Id: modutil.F 662 2007-05-25 15:58:52Z opalod $
+!
+!     Agrif (Adaptive Grid Refinement In Fortran)
+!
+!     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+!                        Christophe Vouland (Christophe.Vouland@imag.fr)
+!
+!     This program is free software; you can redistribute it and/or modify
+!     it under the terms of the GNU General Public License as published by
+!     the Free Software Foundation; either version 2 of the License, or
+!     (at your option) any later version.
+!
+!     This program is distributed in the hope that it will be useful,
+!     but WITHOUT ANY WARRANTY; without even the implied warranty of
+!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+!     GNU General Public License for more details.
+!
+!     You should have received a copy of the GNU General Public License
+!     along with this program; if not, write to the Free Software
+!     Foundation, Inc., 59 Temple Place-  Suite 330, Boston, MA 02111-1307, USA.
+!
+!> Module Agrif_User_Hierarchy
+!!
+!! This module contains procedures we used to manage the grid hierarchy. For example the procedures below are
+!! called in the main program :
+!! - #Agrif_Init_Grids allows the initialization of the root coarse grid.
+!! - #Agrif_Step allows the creation of the grid hierarchy and the management of the time integration.
+!
+module Agrif_User_Hierarchy
+!
+   use Agrif_Clustering
+   use Agrif_Init
+   use Agrif_User_Functions
+   use Agrif_seq
+!
+!
+contains
+!
+!===================================================================================================
+!  subroutine Agrif_Step
+!
+!>This subroutine Creates the grid hierarchy and manages the time integration procedure.
+!! It should be called in the main program and calls the procname recursively for each grid.
+!! It also takes account the time refinement factor and Calls subroutines **Agrif_Regrid** 
+!! and **Agrif_Integrate**. 
+
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Step ( procname )
+!---------------------------------------------------------------------------------------------------
+    procedure(step_proc)    :: procname     !< subroutine to call on each grid
+    type(agrif_grid), pointer :: ref_grid
+!
+! Set the clustering variables
+    call Agrif_clustering_def()
+!
+! Creation and initialization of the grid hierarchy
+    if ( Agrif_USE_ONLY_FIXED_GRIDS == 1 ) then
+!
+        if ( (Agrif_Mygrid % ngridstep == 0) .AND. (.not. Agrif_regrid_has_been_done) ) then
+            call Agrif_Regrid()
+            Agrif_regrid_has_been_done = .TRUE.
+        endif
+!
+    else
+!
+        if (mod(Agrif_Mygrid % ngridstep,Agrif_Regridding) == 0) then
+            call Agrif_Regrid()
+        endif
+!
+    endif
+!
+! Time integration of the grid hierarchy
+    if (agrif_coarse) then
+      ref_grid => agrif_coarsegrid
+    else
+      ref_grid => agrif_mygrid
+    endif
+    if ( Agrif_Parallel_sisters ) then
+        call Agrif_Integrate_Parallel(ref_grid,procname)
+    else
+        call Agrif_Integrate(ref_grid,procname)
+    endif
+!
+    if ( ref_grid%child_list%nitems > 0 ) call Agrif_Instance(ref_grid)
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Step
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Step_Child
+!> This subroutine calls 'procname' recursively for each grid and do not take account the time refinement factor.
+!> It Applies 'procname' to each grid of the hierarchy.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Step_Child ( procname )
+!---------------------------------------------------------------------------------------------------
+    procedure(step_proc)    :: procname     !< subroutine to call on each grid
+!
+    if ( Agrif_Parallel_sisters ) then
+        call Agrif_Integrate_Child_Parallel(Agrif_Mygrid,procname)
+    else
+        call Agrif_Integrate_Child(Agrif_Mygrid,procname)
+    endif
+!
+    if ( Agrif_Mygrid%child_list%nitems > 0 ) call Agrif_Instance(Agrif_Mygrid)
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Step_Child
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Step_Childs
+!> The subroutine Agrif_Step_Childs calls 'procname' recursively on each child grid 
+!! of the current coarse grid and take account the time refinement.
+!> So, it Applies 'procname' to each child grids of the current grid
+!---------------------------------------------------------------------------------------------------
+Subroutine Agrif_Step_Childs(procname)
+!---------------------------------------------------------------------------------------------------
+
+    procedure(step_proc)    :: procname     !< subroutine to call on each grid
+!     Pointer argument
+      Type(Agrif_Grid),pointer   :: g        ! Pointer on the current grid
+!
+
+!
+!     Local pointer
+      Type(Agrif_pgrid),pointer  :: parcours ! Pointer for the recursive
+                                             ! procedure
+!
+      g => Agrif_Curgrid
+      
+      parcours => g % child_list % first
+!
+!     Recursive procedure for the time integration of the grid hierarchy      
+      Do while (associated(parcours))
+!
+!       Instanciation of the variables of the current grid
+        Call Agrif_Instance(parcours % gr)
+
+!     One step on the current grid
+
+         !Call procname ()
+        call Agrif_call_procname ( procname )
+         
+        parcours => parcours % next
+      enddo
+   
+      If (associated(g % child_list % first)) Call Agrif_Instance (g)
+      Return
+      End Subroutine Agrif_Step_Childs
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Regrid
+!
+!> This subroutine creates the grid hierarchy from fixed grids and adaptive mesh refinement.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Regrid ( procname )
+!---------------------------------------------------------------------------------------------------
+    procedure(init_proc), optional    :: procname     !< Initialisation subroutine (Default: Agrif_InitValues)
+!
+    type(Agrif_Rectangle), pointer     :: coarsegrid_fixed
+    type(Agrif_Rectangle), pointer     :: coarsegrid_moving
+    integer                            :: i, j
+    integer :: nunit
+    logical :: BEXIST
+    TYPE(Agrif_Rectangle)            :: newrect    ! Pointer on a new grid
+    integer :: is_coarse, rhox, rhoy, rhoz, rhot
+!
+    if ( Agrif_USE_ONLY_FIXED_GRIDS == 0 ) &
+        call Agrif_detect_all(Agrif_Mygrid)     ! Detection of areas to be refined
+!
+    allocate(coarsegrid_fixed)
+    allocate(coarsegrid_moving)
+!
+    if ( Agrif_USE_ONLY_FIXED_GRIDS == 0 ) &
+        call Agrif_Cluster_All(Agrif_Mygrid,coarsegrid_moving) ! Clustering
+!
+    if ( Agrif_USE_FIXED_GRIDS == 1 .OR. Agrif_USE_ONLY_FIXED_GRIDS == 1 ) then
+!
+        if (Agrif_Mygrid % ngridstep == 0) then
+!            
+            nunit = Agrif_Get_Unit()
+            open(nunit, file='AGRIF_FixedGrids.in', form='formatted', status="old", ERR=99)
+            if (agrif_coarse) then ! SKIP the coarse grid declaration
+                if (Agrif_Probdim == 3) then
+                    read(nunit,*) is_coarse, rhox, rhoy, rhoz, rhot
+                elseif (Agrif_Probdim == 2) then
+                    read(nunit,*) is_coarse, rhox, rhoy, rhot
+                elseif (Agrif_Probdim == 2) then
+                    read(nunit,*) is_coarse, rhox, rhot
+                endif
+            endif
+!           Creation of the grid hierarchy from the Agrif_FixedGrids.in file
+            do i = 1,Agrif_Probdim
+                coarsegrid_fixed % imin(i) = 1
+                coarsegrid_fixed % imax(i) = Agrif_Mygrid % nb(i) + 1
+            enddo
+            j = 1
+            call Agrif_Read_Fix_Grd(coarsegrid_fixed,j,nunit)
+            close(nunit)
+!
+            call Agrif_gl_clear(Agrif_oldmygrid)
+!
+!           Creation of the grid hierarchy from coarsegrid_fixed
+            call Agrif_Create_Grids(Agrif_Mygrid,coarsegrid_fixed)
+            
+        else
+            call Agrif_gl_copy(Agrif_oldmygrid, Agrif_Mygrid % child_list)
+        endif
+    else
+        call Agrif_gl_copy(Agrif_oldmygrid, Agrif_Mygrid % child_list)
+        call Agrif_gl_clear(Agrif_Mygrid % child_list)
+    endif
+!
+    if ( Agrif_USE_ONLY_FIXED_GRIDS == 0 ) then
+!
+        call Agrif_Save_All(Agrif_oldmygrid)
+        call Agrif_Free_before_All(Agrif_oldmygrid)
+!
+!       Creation of the grid hierarchy from coarsegrid_moving
+        call Agrif_Create_Grids(Agrif_Mygrid,coarsegrid_moving)
+!
+    endif
+!
+!   Initialization of the grid hierarchy by copy or interpolation
+!
+#if defined AGRIF_MPI
+    if ( Agrif_Parallel_sisters ) then
+        call Agrif_Init_Hierarchy_Parallel_1(Agrif_Mygrid)
+        call Agrif_Init_Hierarchy_Parallel_2(Agrif_Mygrid,procname)
+    else
+        call Agrif_Init_Hierarchy(Agrif_Mygrid,procname)
+    endif
+#else
+        call Agrif_Init_Hierarchy(Agrif_Mygrid,procname)
+#endif
+!
+    if ( Agrif_USE_ONLY_FIXED_GRIDS == 0 ) call Agrif_Free_after_All(Agrif_oldmygrid)
+!
+    Agrif_regrid_has_been_done = .TRUE.
+!
+    call Agrif_Instance( Agrif_Mygrid )
+!
+    deallocate(coarsegrid_fixed)
+    deallocate(coarsegrid_moving)
+!
+    return
+!
+!     Opening error
+!
+99  INQUIRE(FILE='AGRIF_FixedGrids.in',EXIST=BEXIST)
+    if (.not. BEXIST) then
+        print*,'ERROR : File AGRIF_FixedGrids.in not found.'
+        STOP
+    else
+        print*,'Error opening file AGRIF_FixedGrids.in'
+        STOP
+    endif
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Regrid
+!===================================================================================================
+!
+!
+!===================================================================================================
+!  subroutine Agrif_Integrate_ChildGrids
+!
+!> This subroutine manages the time integration of the grid hierarchy.
+!! It Calls the subroutine procname on each child grid of the current grid
+!---------------------------------------------------------------------------------------------------
+recursive subroutine Agrif_Integrate_ChildGrids ( procname )
+!---------------------------------------------------------------------------------------------------
+    procedure(step_proc)        :: procname !< Subroutine to call on each grid
+!
+    type(Agrif_PGrid), pointer  :: parcours ! Pointer for the recursive procedure
+    integer                     :: nbt      ! Number of time steps of the current grid
+    integer                     :: i, k, is
+    type(Agrif_Grid)                    , pointer :: save_grid
+    type(Agrif_PGrid), pointer  :: gridp    ! Pointer for the recursive procedure
+    
+    save_grid => Agrif_Curgrid
+
+! Number of time steps on the current grid
+    save_grid % ngridstep = save_grid % ngridstep + 1
+    
+#ifdef AGRIF_MPI
+    if ( .not. Agrif_Parallel_sisters ) then
+#endif
+    parcours => save_grid % child_list % first
+!
+!   Recursive procedure for the time integration of the grid hierarchy
+    do while (associated(parcours))
+!
+!       Instanciation of the variables of the current grid
+        call Agrif_Instance(parcours % gr)
+!
+!       Number of time steps
+        nbt = 1
+        do i = 1,Agrif_Probdim
+            nbt = max(nbt, parcours % gr % timeref(i))
+        enddo
+!
+        do k = 1,nbt
+            !call procname()
+           call Agrif_call_procname ( procname )
+            
+        enddo
+!
+        parcours => parcours % next
+!
+    enddo
+
+#ifdef AGRIF_MPI
+    else
+! Continue only if the grid has defined sequences of child integrations.
+    if ( .not. associated(save_grid % child_seq) ) return
+!
+    do is = 1, save_grid % child_seq % nb_seqs
+!
+!     For each sequence, a given processor does integrate only on grid.
+        gridp => Agrif_seq_select_child(save_grid,is)
+!
+!     Instanciation of the variables of the current grid
+        call Agrif_Instance(gridp % gr)
+!
+!     Number of time steps
+        nbt = 1
+        do i = 1,Agrif_Probdim
+            nbt = max(nbt, gridp % gr % timeref(i))
+        enddo
+!
+        do k = 1,nbt
+          !call procname()
+           call Agrif_call_procname ( procname )            
+        enddo
+!
+    enddo
+    endif
+#endif 
+
+    call Agrif_Instance(save_grid)
+    
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Integrate_ChildGrids
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Init_Grids
+!
+!> This subroutine initializes the root coarse grid pointed by #Agrif_Mygrid. It is called in the main program.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Init_Grids ( procname1, procname2 )
+!---------------------------------------------------------------------------------------------------
+    procedure(typedef_proc), optional   :: procname1 !< (Default: Agrif_probdim_modtype_def)
+    procedure(alloc_proc),   optional   :: procname2 !< (Default: Agrif_Allocationcalls)
+!
+    integer :: i, ierr_allocate, nunit
+    integer :: is_coarse, rhox,rhoy,rhoz,rhot
+    logical :: BEXIST
+!
+    if (present(procname1)) Then
+        !call procname1()
+        call Agrif_call_procname1 ( procname1 )        
+    else
+        call Agrif_probdim_modtype_def()
+    endif
+!
+
+! TEST FOR COARSE GRID (GRAND MOTHER GRID) in AGRIF_FixedGrids.in
+    nunit = Agrif_Get_Unit()
+    open(nunit, file='AGRIF_FixedGrids.in', form='formatted', status="old", ERR=98)
+    if (Agrif_Probdim == 3) then
+       read(nunit,*) is_coarse, rhox, rhoy, rhoz, rhot
+    elseif (Agrif_Probdim == 2) then
+       read(nunit,*) is_coarse, rhox, rhoy, rhot
+    elseif (Agrif_Probdim == 2) then
+       read(nunit,*) is_coarse, rhox, rhot
+    endif
+    if (is_coarse == -1) then
+       agrif_coarse = .TRUE.
+       if (Agrif_Probdim == 3) then
+          coarse_spaceref(1:3)=(/rhox,rhoy,rhoz/)
+       elseif (Agrif_Probdim == 2) then
+          coarse_spaceref(1:2)=(/rhox,rhoy/)
+       elseif (Agrif_Probdim == 2) then
+          coarse_spaceref(1:1)=(/rhox/)
+       endif
+       coarse_timeref(1:Agrif_Probdim) = rhot
+    endif
+    close(nunit)
+    
+    Agrif_UseSpecialValue = .FALSE.
+    Agrif_UseSpecialValueFineGrid = .FALSE.
+    Agrif_SpecialValue = 0.
+    Agrif_SpecialValueFineGrid = 0.
+!
+    allocate(Agrif_Mygrid)
+    allocate(Agrif_OldMygrid)
+!
+!   Space and time refinement factors are set to 1 on the root grid
+!
+    do i = 1,Agrif_Probdim
+        Agrif_Mygrid % spaceref(i) = coarse_spaceref(i)
+        Agrif_Mygrid % timeref(i)  = coarse_timeref(i)
+    enddo
+!
+!   Initialization of the number of time steps
+    Agrif_Mygrid % ngridstep = 0
+    Agrif_Mygrid % grid_id   = 0
+!
+!   No parent grid for the root coarse grid
+    nullify(Agrif_Mygrid % parent)
+!
+!   Initialization of the minimum positions, global abscissa and space steps
+    do i = 1, Agrif_Probdim
+        Agrif_Mygrid % ix(i) = 1
+        Agrif_Mygrid % Agrif_x(i)  = 0.
+        Agrif_Mygrid % Agrif_dx(i) = 1.d0/real(Agrif_Mygrid % spaceref(i),kind=8)
+        Agrif_Mygrid % Agrif_dt(i) = 1./Agrif_Mygrid % timeref(i)
+!       Borders of the root coarse grid
+        Agrif_Mygrid % NearRootBorder(i) = .true.
+        Agrif_Mygrid % DistantRootBorder(i) = .true.
+    enddo
+!
+!   The root coarse grid is a fixed grid
+    Agrif_Mygrid % fixed = .TRUE.
+!   Level of the root grid
+    Agrif_Mygrid % level = 0
+!   Maximum level in the hierarchy
+    Agrif_MaxLevelLoc = 0
+!
+!   Number of the grid pointed by Agrif_Mygrid (root coarse grid)
+    Agrif_Mygrid % rank = 1
+!
+!   Number of the root grid as a fixed grid
+    Agrif_Mygrid % fixedrank = 0
+!
+!   Initialization of some fields of the root grid variables
+    ierr_allocate = 0
+    if( Agrif_NbVariables(0) > 0 ) allocate(Agrif_Mygrid % tabvars(Agrif_NbVariables(0)),stat=ierr_allocate)
+    if( Agrif_NbVariables(1) > 0 ) allocate(Agrif_Mygrid % tabvars_c(Agrif_NbVariables(1)),stat=ierr_allocate)
+    if( Agrif_NbVariables(2) > 0 ) allocate(Agrif_Mygrid % tabvars_r(Agrif_NbVariables(2)),stat=ierr_allocate)
+    if( Agrif_NbVariables(3) > 0 ) allocate(Agrif_Mygrid % tabvars_l(Agrif_NbVariables(3)),stat=ierr_allocate)
+    if( Agrif_NbVariables(4) > 0 ) allocate(Agrif_Mygrid % tabvars_i(Agrif_NbVariables(4)),stat=ierr_allocate)
+    if (ierr_allocate /= 0) THEN
+      STOP "*** ERROR WHEN ALLOCATING TABVARS ***"
+    endif
+!
+!   Initialization of the other fields of the root grid variables (number of
+!   cells, positions, number and type of its dimensions, ...)
+    call Agrif_Instance(Agrif_Mygrid)
+    call Agrif_Set_numberofcells(Agrif_Mygrid)
+!
+!   Allocation of the array containing the values of the grid variables
+    call Agrif_Allocation(Agrif_Mygrid, procname2)
+    call Agrif_initialisations(Agrif_Mygrid)
+!
+!   Total number of fixed grids
+    Agrif_nbfixedgrids = 0
+    
+! If a grand mother grid is declared
+
+    if (agrif_coarse) then
+      allocate(Agrif_Coarsegrid)
+
+      Agrif_Coarsegrid % ngridstep = 0
+      Agrif_Coarsegrid % grid_id   = -9999
+      
+    do i = 1, Agrif_Probdim
+        Agrif_Coarsegrid%spaceref(i) = coarse_spaceref(i)
+        Agrif_Coarsegrid%timeref(i) = coarse_timeref(i)
+        Agrif_Coarsegrid % ix(i) = 1
+        Agrif_Coarsegrid % Agrif_x(i)  = 0.
+        Agrif_Coarsegrid % Agrif_dx(i) = 1.
+        Agrif_Coarsegrid % Agrif_dt(i) = 1.
+!       Borders of the root coarse grid
+        Agrif_Coarsegrid % NearRootBorder(i) = .true.
+        Agrif_Coarsegrid % DistantRootBorder(i) = .true.
+        Agrif_Coarsegrid % nb(i) =Agrif_mygrid%nb(i) / coarse_spaceref(i)
+    enddo      
+
+!   The root coarse grid is a fixed grid
+    Agrif_Coarsegrid % fixed = .TRUE.
+!   Level of the root grid
+    Agrif_Coarsegrid % level = -1
+    
+    Agrif_Coarsegrid % grand_mother_grid = .true.
+
+!   Number of the grid pointed by Agrif_Mygrid (root coarse grid)
+    Agrif_Coarsegrid % rank = -9999
+!
+!   Number of the root grid as a fixed grid
+    Agrif_Coarsegrid % fixedrank = -9999
+    
+      Agrif_Mygrid%parent => Agrif_Coarsegrid
+      
+! Not used but required to prevent seg fault
+      Agrif_Coarsegrid%parent => Agrif_Mygrid
+      
+      call Agrif_Create_Var(Agrif_Coarsegrid)
+
+! Reset to null
+      Nullify(Agrif_Coarsegrid%parent)
+      
+      Agrif_Coarsegrid%child_list%nitems = 1
+      allocate(Agrif_Coarsegrid%child_list%first)
+      allocate(Agrif_Coarsegrid%child_list%last)
+      Agrif_Coarsegrid%child_list%first%gr => Agrif_Mygrid
+      Agrif_Coarsegrid%child_list%last%gr => Agrif_Mygrid
+
+    endif
+    
+    return
+
+98  INQUIRE(FILE='AGRIF_FixedGrids.in',EXIST=BEXIST)
+    if (.not. BEXIST) then
+        print*,'ERROR : File AGRIF_FixedGrids.in not found.'
+        STOP
+    else
+        print*,'Error opening file AGRIF_FixedGrids.in'
+        STOP
+    endif
+    
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Init_Grids
+!===================================================================================================
+!
+!
+!===================================================================================================
+!  subroutine Agrif_Deallocation
+!
+!> This subroutine deallocates all data arrays.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Deallocation
+!---------------------------------------------------------------------------------------------------
+    integer                         :: nb
+    type(Agrif_Variable), pointer   :: var
+    type(Agrif_Variable_c), pointer   :: var_c
+    type(Agrif_Variable_l), pointer   :: var_l
+    type(Agrif_Variable_i), pointer   :: var_i
+!
+    do nb = 1,Agrif_NbVariables(0)
+!
+        var => Agrif_Mygrid % tabvars(nb)
+!
+        if ( allocated(var % array1) ) deallocate(var % array1)
+        if ( allocated(var % array2) ) deallocate(var % array2)
+        if ( allocated(var % array3) ) deallocate(var % array3)
+        if ( allocated(var % array4) ) deallocate(var % array4)
+        if ( allocated(var % array5) ) deallocate(var % array5)
+        if ( allocated(var % array6) ) deallocate(var % array6)
+!
+        if ( allocated(var % sarray1) ) deallocate(var % sarray1)
+        if ( allocated(var % sarray2) ) deallocate(var % sarray2)
+        if ( allocated(var % sarray3) ) deallocate(var % sarray3)
+        if ( allocated(var % sarray4) ) deallocate(var % sarray4)
+        if ( allocated(var % sarray5) ) deallocate(var % sarray5)
+        if ( allocated(var % sarray6) ) deallocate(var % sarray6)
+!
+        if ( allocated(var % darray1) ) deallocate(var % darray1)
+        if ( allocated(var % darray2) ) deallocate(var % darray2)
+        if ( allocated(var % darray3) ) deallocate(var % darray3)
+        if ( allocated(var % darray4) ) deallocate(var % darray4)
+        if ( allocated(var % darray5) ) deallocate(var % darray5)
+        if ( allocated(var % darray6) ) deallocate(var % darray6)
+!
+    enddo
+!
+    do nb = 1,Agrif_NbVariables(1)
+!
+        var_c => Agrif_Mygrid % tabvars_c(nb)
+!
+        if ( allocated(var_c % carray1) ) deallocate(var_c % carray1)
+        if ( allocated(var_c % carray2) ) deallocate(var_c % carray2)
+!
+    enddo
+
+    do nb = 1,Agrif_NbVariables(3)
+!
+        var_l => Agrif_Mygrid % tabvars_l(nb)
+!
+        if ( allocated(var_l % larray1) ) deallocate(var_l % larray1)
+        if ( allocated(var_l % larray2) ) deallocate(var_l % larray2)
+        if ( allocated(var_l % larray3) ) deallocate(var_l % larray3)
+        if ( allocated(var_l % larray4) ) deallocate(var_l % larray4)
+        if ( allocated(var_l % larray5) ) deallocate(var_l % larray5)
+        if ( allocated(var_l % larray6) ) deallocate(var_l % larray6)
+!
+    enddo
+!
+    do nb = 1,Agrif_NbVariables(4)
+!
+        var_i => Agrif_Mygrid % tabvars_i(nb)
+!
+        if ( allocated(var_i % iarray1) ) deallocate(var_i % iarray1)
+        if ( allocated(var_i % iarray2) ) deallocate(var_i % iarray2)
+        if ( allocated(var_i % iarray3) ) deallocate(var_i % iarray3)
+        if ( allocated(var_i % iarray4) ) deallocate(var_i % iarray4)
+        if ( allocated(var_i % iarray5) ) deallocate(var_i % iarray5)
+        if ( allocated(var_i % iarray6) ) deallocate(var_i % iarray6)
+!
+    enddo
+!
+    if ( allocated(Agrif_Mygrid % tabvars) )   deallocate(Agrif_Mygrid % tabvars)
+    if ( allocated(Agrif_Mygrid % tabvars_c) ) deallocate(Agrif_Mygrid % tabvars_c)
+    if ( allocated(Agrif_Mygrid % tabvars_r) ) deallocate(Agrif_Mygrid % tabvars_r)
+    if ( allocated(Agrif_Mygrid % tabvars_l) ) deallocate(Agrif_Mygrid % tabvars_l)
+    if ( allocated(Agrif_Mygrid % tabvars_i) ) deallocate(Agrif_Mygrid % tabvars_i)
+    deallocate(Agrif_Mygrid)
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Deallocation
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Step_adj
+!
+!> This subroutine creates the grid hierarchy and manages the backward time integration procedure.
+!> It is called in the main program and calls subroutines **Agrif_Regrid()** and **Agrif_Integrate_adj()**.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Step_adj ( procname )
+!---------------------------------------------------------------------------------------------------
+    procedure(step_proc)    :: procname     !< Subroutine to call on each grid
+!
+!   Creation and initialization of the grid hierarchy
+!
+!   Set the clustering variables
+    call Agrif_clustering_def()
+!
+    if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 1 ) then
+!
+        if (Agrif_Mygrid % ngridstep == 0) then
+            if (.not.Agrif_regrid_has_been_done ) then
+                call Agrif_Regrid()
+            endif
+            call Agrif_Instance(Agrif_Mygrid)
+        endif
+!
+    else
+!
+        if (mod(Agrif_Mygrid % ngridstep, Agrif_Regridding) == 0) then
+            call Agrif_Regrid()
+            call Agrif_Instance(Agrif_Mygrid)
+        endif
+!
+    endif
+!
+!   Time integration of the grid hierarchy
+!
+    call Agrif_Integrate_adj (Agrif_Mygrid,procname)
+!
+    if ( Agrif_Mygrid % child_list % nitems > 0 ) call Agrif_Instance(Agrif_Mygrid)
+!
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Step_adj
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Step_Child_adj
+!
+!> This subroutine applies 'procname' to each grid of the hierarchy from Child to Parent
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Step_Child_adj ( procname )
+!---------------------------------------------------------------------------------------------------
+    procedure(step_proc)        :: procname !< Subroutine to call on each grid
+!
+    call Agrif_Integrate_Child_adj(Agrif_Mygrid,procname)
+!
+    if ( Agrif_Mygrid % child_list % nitems > 0 ) call Agrif_Instance(Agrif_Mygrid)
+!
+end subroutine Agrif_Step_Child_adj
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_detect_All
+!
+!> \cond Detects areas to be refined.
+!---------------------------------------------------------------------------------------------------
+recursive subroutine Agrif_detect_all ( g )
+!---------------------------------------------------------------------------------------------------
+    TYPE(Agrif_Grid),  pointer  :: g        !< Pointer on the current grid
+!
+    Type(Agrif_PGrid), pointer  :: parcours ! Pointer for the recursive procedure
+    integer, DIMENSION(3)       :: size
+    integer                     :: i
+    real(kind=8)                :: g_eps
+!
+    parcours => g % child_list % first
+!
+!   To be positioned on the finer grids of the grid hierarchy
+!
+    do while (associated(parcours))
+        call Agrif_detect_all(parcours % gr)
+        parcours => parcours % next
+    enddo
+!
+    g_eps = huge(1.)
+    do i = 1,Agrif_Probdim
+        g_eps = min(g_eps, g % Agrif_dx(i))
+    enddo
+!
+    g_eps = g_eps / 100.d0
+!
+    if ( Agrif_Probdim == 1 ) g%tabpoint1D = 0
+    if ( Agrif_Probdim == 2 ) g%tabpoint2D = 0
+    if ( Agrif_Probdim == 3 ) g%tabpoint3D = 0
+!
+    do i = 1,Agrif_Probdim
+        if ( g%Agrif_dx(i)/Agrif_coeffref(i) < (Agrif_mind(i)-g_eps) ) return
+    enddo
+!
+    call Agrif_instance(g)
+!
+!   Detection (Agrif_detect is a users routine)
+!
+    do i = 1,Agrif_Probdim
+        size(i) = g % nb(i) + 1
+    enddo
+!
+    SELECT CASE (Agrif_Probdim)
+    CASE (1)
+        call Agrif_detect(g%tabpoint1D,size)
+    CASE (2)
+        call Agrif_detect(g%tabpoint2D,size)
+    CASE (3)
+        call Agrif_detect(g%tabpoint3D,size)
+    END SELECT
+!
+!   Addition of the areas detected on the child grids
+!
+    parcours => g % child_list % first
+!
+    do while (associated(parcours))
+        call Agrif_Add_detected_areas(g,parcours % gr)
+        parcours => parcours % next
+    enddo
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_detect_all
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Add_detected_areas
+!
+!> Adds on the parent grid the areas detected on its child grids
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Add_detected_areas ( parentgrid, childgrid )
+!---------------------------------------------------------------------------------------------------
+    Type(Agrif_Grid), pointer   :: parentgrid
+    Type(Agrif_Grid), pointer   :: childgrid
+!
+    integer :: i,j,k
+!
+    do i = 1,childgrid%nb(1)+1
+        if ( Agrif_Probdim == 1 ) then
+            if (childgrid%tabpoint1D(i)==1) then
+                parentgrid%tabpoint1D(childgrid%ix(1)+(i-1)/Agrif_Coeffref(1)) = 1
+            endif
+        else
+            do j=1,childgrid%nb(2)+1
+                if (Agrif_Probdim==2) then
+                    if (childgrid%tabpoint2D(i,j)==1) then
+                        parentgrid%tabpoint2D(                       &
+                            childgrid%ix(1)+(i-1)/Agrif_Coeffref(1), &
+                            childgrid%ix(2)+(j-1)/Agrif_Coeffref(2)) = 1
+                    endif
+                else
+                    do k=1,childgrid%nb(3)+1
+                        if (childgrid%tabpoint3D(i,j,k)==1) then
+                            parentgrid%tabpoint3D(                       &
+                                childgrid%ix(1)+(i-1)/Agrif_Coeffref(1), &
+                                childgrid%ix(2)+(j-1)/Agrif_Coeffref(2), &
+                                childgrid%ix(3)+(k-1)/Agrif_Coeffref(3)) = 1
+                        endif
+                    enddo
+                endif
+            enddo
+        endif
+    enddo
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Add_detected_areas
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Free_before_All
+!---------------------------------------------------------------------------------------------------
+recursive subroutine Agrif_Free_before_All ( gridlist )
+!---------------------------------------------------------------------------------------------------
+    Type(Agrif_Grid_List), intent(inout)    :: gridlist !< Grid list
+!
+    Type(Agrif_PGrid), pointer   :: parcours ! Pointer for the recursive procedure
+!
+    parcours => gridlist % first
+!
+    do while (associated(parcours))
+!
+        if (.not. parcours%gr%fixed) then
+            call Agrif_Free_data_before(parcours%gr)
+            parcours % gr % oldgrid = .TRUE.
+        endif
+!
+        call Agrif_Free_before_all (parcours % gr % child_list)
+!
+        parcours => parcours % next
+!
+    enddo
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Free_before_All
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Save_All
+!---------------------------------------------------------------------------------------------------
+recursive subroutine Agrif_Save_All ( gridlist )
+!---------------------------------------------------------------------------------------------------
+    type(Agrif_Grid_List), intent(inout)    :: gridlist !< Grid list
+!
+    type(Agrif_PGrid), pointer   :: parcours ! Pointer for the recursive procedure
+!
+    parcours => gridlist % first
+!
+    do while (associated(parcours))
+!
+        if (.not. parcours%gr%fixed) then
+            call Agrif_Instance(parcours%gr)
+            call Agrif_Before_Regridding()
+            parcours % gr % oldgrid = .TRUE.
+        endif
+!
+        call Agrif_Save_All(parcours % gr % child_list)
+!
+        parcours => parcours % next
+!
+      enddo
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Save_All
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Free_after_All
+!---------------------------------------------------------------------------------------------------
+recursive subroutine Agrif_Free_after_All ( gridlist )
+!---------------------------------------------------------------------------------------------------
+    Type(Agrif_Grid_List), intent(inout)    :: gridlist       !< Grid list to free
+!
+    Type(Agrif_PGrid), pointer  :: parcours ! Pointer for the recursive proced
+    Type(Agrif_PGrid), pointer  :: preparcours
+    Type(Agrif_PGrid), pointer  :: preparcoursini
+!
+    allocate(preparcours)
+!
+    preparcoursini => preparcours
+!
+    nullify(preparcours % gr)
+!
+    preparcours % next => gridlist % first
+    parcours => gridlist % first
+!
+    do while (associated(parcours))
+!
+        if ( (.NOT. parcours%gr % fixed) .AND. (parcours%gr % oldgrid) ) then
+            call Agrif_Free_data_after(parcours%gr)
+        endif
+!
+        call Agrif_Free_after_all( parcours%gr % child_list )
+!
+        if (parcours % gr % oldgrid) then
+            deallocate(parcours % gr)
+            preparcours % next => parcours % next
+            deallocate(parcours)
+            parcours => preparcours % next
+        else
+            preparcours => preparcours % next
+            parcours => parcours % next
+        endif
+!
+    enddo
+!
+    deallocate(preparcoursini)
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Free_after_All
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Integrate
+!
+!> Manages the time integration of the grid hierarchy.
+!! Recursive subroutine and call on subroutines Agrif_Init::Agrif_Instance and #Agrif_Step
+!---------------------------------------------------------------------------------------------------
+recursive subroutine Agrif_Integrate ( g, procname )
+!---------------------------------------------------------------------------------------------------
+    type(Agrif_Grid), pointer   :: g        !< Pointer on the current grid
+    procedure(step_proc)        :: procname !< Subroutine to call on each grid
+!
+    type(Agrif_PGrid), pointer  :: parcours ! Pointer for the recursive procedure
+    integer                     :: nbt      ! Number of time steps of the current grid
+    integer                     :: i, k
+!
+!   Instanciation of the variables of the current grid
+!    if ( g % fixedrank /= 0 ) then
+        call Agrif_Instance(g)
+!    endif
+!
+!   One step on the current grid
+!
+    !call procname ()
+    call Agrif_call_procname ( procname )
+    
+!
+!   Number of time steps on the current grid
+!
+    g%ngridstep = g % ngridstep + 1
+    parcours => g % child_list % first
+!
+!   Recursive procedure for the time integration of the grid hierarchy
+    do while (associated(parcours))
+!
+!       Instanciation of the variables of the current grid
+        call Agrif_Instance(parcours % gr)
+!
+!       Number of time steps
+        nbt = 1
+        do i = 1,Agrif_Probdim
+            nbt = max(nbt, parcours % gr % timeref(i))
+        enddo
+!
+        do k = 1,nbt
+            call Agrif_Integrate(parcours % gr, procname)
+        enddo
+!
+        parcours => parcours % next
+!
+    enddo
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Integrate
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Integrate_Parallel
+!
+!> Manages the time integration of the grid hierarchy in parallel
+!! Recursive subroutine and call on subroutines Agrif_Init::Agrif_Instance and #Agrif_Step
+!---------------------------------------------------------------------------------------------------
+recursive subroutine Agrif_Integrate_Parallel ( g, procname )
+!---------------------------------------------------------------------------------------------------
+    type(Agrif_Grid), pointer   :: g        !< Pointer on the current grid
+    procedure(step_proc)        :: procname !< Subroutine to call on each grid
+!
+#if defined AGRIF_MPI
+    type(Agrif_PGrid), pointer  :: gridp    ! Pointer for the recursive procedure
+    integer                     :: nbt      ! Number of time steps of the current grid
+    integer                     :: i, k, is
+!
+!   Instanciation of the variables of the current grid
+    if ( g % fixedrank /= 0 ) then
+        call Agrif_Instance(g)
+    endif
+!
+! One step on the current grid
+    !call procname ()
+     call Agrif_call_procname ( procname )
+    
+!
+! Number of time steps on the current grid
+    g % ngridstep = g % ngridstep + 1
+!
+! Continue only if the grid has defined sequences of child integrations.
+    if ( .not. associated(g % child_seq) ) return
+!
+    do is = 1, g % child_seq % nb_seqs
+!
+!     For each sequence, a given processor does integrate only on grid.
+        gridp => Agrif_seq_select_child(g,is)
+!
+!     Instanciation of the variables of the current grid
+        call Agrif_Instance(gridp % gr)
+!
+!     Number of time steps
+        nbt = 1
+        do i = 1,Agrif_Probdim
+            nbt = max(nbt, gridp % gr % timeref(i))
+        enddo
+!
+        do k = 1,nbt
+            call Agrif_Integrate_Parallel(gridp % gr, procname)
+        enddo
+!
+    enddo
+#else
+    call Agrif_Integrate( g, procname )
+#endif
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Integrate_Parallel
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Integrate_Child
+!
+!> Manages the time integration of the grid hierarchy.
+!! Recursive subroutine and call on subroutines Agrif_Instance & Agrif_Step.
+!---------------------------------------------------------------------------------------------------
+recursive subroutine Agrif_Integrate_Child ( g, procname )
+!---------------------------------------------------------------------------------------------------
+    type(Agrif_Grid), pointer   :: g        !< Pointer on the current grid
+    procedure(step_proc)        :: procname !< Subroutine to call on each grid
+!
+    type(Agrif_PGrid), pointer  :: parcours ! Pointer for the recursive procedure
+!
+!   One step on the current grid
+!
+    !call procname ()
+     call Agrif_call_procname ( procname )    
+!
+!   Number of time steps on the current grid
+!
+    parcours => g % child_list % first
+!
+!   Recursive procedure for the time integration of the grid hierarchy
+    do while (associated(parcours))
+!
+!       Instanciation of the variables of the current grid
+        call Agrif_Instance(parcours % gr)
+        call Agrif_Integrate_Child (parcours % gr, procname)
+        parcours => parcours % next
+!
+    enddo
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Integrate_Child
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Integrate_Child_Parallel
+!
+!> Manages the time integration of the grid hierarchy.
+!! Recursive subroutine and call on subroutines Agrif_Instance & Agrif_Step.
+!---------------------------------------------------------------------------------------------------
+recursive subroutine Agrif_Integrate_Child_Parallel ( g, procname )
+!---------------------------------------------------------------------------------------------------
+    type(Agrif_Grid), pointer   :: g        !< Pointer on the current grid
+    procedure(step_proc)        :: procname !< Subroutine to call on each grid
+!
+#if defined AGRIF_MPI
+    type(Agrif_PGrid), pointer  :: gridp    ! Pointer for the recursive procedure
+    integer                     :: is
+!
+! Instanciation of the variables of the current grid
+    call Agrif_Instance(g)
+!
+! One step on the current grid
+    !call procname ()
+    call Agrif_call_procname ( procname )
+
+!
+! Continue only if the grid has defined sequences of child integrations.
+    if ( .not. associated(g % child_seq) ) return
+!
+    do is = 1, g % child_seq % nb_seqs
+!
+!     For each sequence, a given processor does integrate only on grid.
+        gridp => Agrif_seq_select_child(g,is)
+        call Agrif_Integrate_Child_Parallel(gridp % gr, procname)
+!
+    enddo
+!
+    call Agrif_Instance(g)
+#else
+    call Agrif_Integrate_Child( g, procname )
+#endif
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Integrate_Child_Parallel
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Integrate_adj
+!
+!> Manages the backward time integration of the grid hierarchy.
+!! Recursive subroutine and call on subroutines Agrif_Init::Agrif_Instance and #Agrif_Step_adj
+!---------------------------------------------------------------------------------------------------
+recursive subroutine Agrif_Integrate_adj ( g, procname )
+!---------------------------------------------------------------------------------------------------
+    type(Agrif_Grid), pointer   :: g        !< Pointer on the current grid
+    procedure(step_proc)        :: procname !< Subroutine to call on each grid
+!
+    type(Agrif_pgrid), pointer :: parcours ! pointer for the recursive procedure
+    integer                    :: nbt      ! Number of time steps of the current grid
+    integer                    :: k
+!
+!   Instanciation of the variables of the current grid
+    if ( g%fixedrank /= 0 ) then
+        call Agrif_Instance(g)
+    endif
+!
+!   Number of time steps on the current grid
+!
+    g%ngridstep = g % ngridstep + 1
+    parcours => g % child_list % first
+!
+!   Recursive procedure for the time integration of the grid hierarchy
+    do while (associated(parcours))
+!
+!   Instanciation of the variables of the current grid
+        call Agrif_Instance(parcours % gr)
+!
+!       Number of time steps
+        nbt = 1
+        do k = 1,Agrif_Probdim
+            nbt = max(nbt, parcours % gr % timeref(k))
+        enddo
+!
+        do k = nbt,1,-1
+            call Agrif_Integrate_adj(parcours % gr, procname)
+        enddo
+!
+        parcours => parcours % next
+!
+    enddo
+!
+    if ( g % child_list % nitems > 0 )  call Agrif_Instance(g)
+!
+!   One step on the current grid
+    !call procname ()
+    call Agrif_call_procname ( procname )   
+!
+end subroutine Agrif_Integrate_adj
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Integrate_Child_adj
+!
+!> Manages the backward time integration of the grid hierarchy.
+!! Recursive subroutine and call on subroutines Agrif_Init::Agrif_Instance & Agrif_Step_adj.
+!---------------------------------------------------------------------------------------------------
+recursive subroutine Agrif_Integrate_Child_adj ( g, procname )
+!---------------------------------------------------------------------------------------------------
+    type(Agrif_Grid),pointer   :: g          !< Pointer on the current grid
+    procedure(step_proc)       :: procname   !< Subroutine to call on each grid
+!
+    type(Agrif_PGrid),pointer  :: parcours   !< Pointer for the recursive procedure
+!
+    parcours => g % child_list % first
+!
+!   Recursive procedure for the time integration of the grid hierarchy
+    do while (associated(parcours))
+!
+!       Instanciation of the variables of the current grid
+        call Agrif_Instance(parcours % gr)
+        call Agrif_Integrate_Child_adj(parcours % gr, procname)
+!
+       parcours => parcours % next
+!
+    enddo
+    if ( g % child_list % nitems > 0 )  call Agrif_Instance(g)
+!
+!   One step on the current grid
+    !call procname()
+     call Agrif_call_procname ( procname )    
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Integrate_Child_adj
+!===================================================================================================
+!
+!> \endcond
+end module Agrif_User_Hierarchy
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduserinterpolation.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduserinterpolation.F90	(revision 10087)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduserinterpolation.F90	(revision 10087)
@@ -0,0 +1,360 @@
+!
+! $Id: modupdate.F 779 2007-12-22 17:04:17Z rblod $
+!
+!     AGRIF (Adaptive Grid Refinement In Fortran)
+!
+!     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+!                        Christophe Vouland (Christophe.Vouland@imag.fr)
+!
+!     This program is free software; you can redistribute it and/or modify
+!     it under the terms of the GNU General Public License as published by
+!     the Free Software Foundation; either version 2 of the License, or
+!     (at your option) any later version.
+!
+!     This program is distributed in the hope that it will be useful,
+!     but WITHOUT ANY WARRANTY; without even the implied warranty of
+!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+!     GNU General Public License for more details.
+!
+!     You should have received a copy of the GNU General Public License
+!     along with this program; if not, write to the Free Software
+!     Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
+!
+!---------------------------------------------------------------------------------------------------
+!> Module Agrif_User_Interpolation
+!!
+!! This module contains procedures used by AGRIF users to do an interpolation 
+!! either within the domain or at boundary or on the whole domain.
+!---------------------------------------------------------------------------------------------------
+!
+module Agrif_User_Interpolation
+!
+  use Agrif_Boundary
+  use Agrif_user_variables
+!  
+  Implicit none
+
+contains
+!
+!===================================================================================================
+!  subroutine Agrif_Set_bc
+!> This subroutine is used to specify the variable we want to interpolate and the boundary location of 
+!! the current grid we want to interpolate (boundary interpolation).  
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_bc ( tabvarsindic, bcinfsup, Interpolationshouldbemade )
+!---------------------------------------------------------------------------------------------------
+    integer,               intent(in)   :: tabvarsindic !< index of the variable in tabvars
+    integer, dimension(2), intent(in)   :: bcinfsup     !< location
+    logical, optional,     intent(in)   :: Interpolationshouldbemade !< interpolation should be made
+!
+    integer                         :: indic ! indice of the variable in tabvars
+    type(Agrif_Variable),  pointer  :: var
+!
+    var => Agrif_Search_Variable(Agrif_Curgrid,tabvarsindic)
+    if (.not.associated(var)) return ! Grand mother grid case
+!
+    if ( Agrif_Curgrid % fixedrank /= 0 ) then
+        if ( .not.associated(var % oldvalues2D) ) then
+            allocate(var % oldvalues2D(2,1))
+            var % interpIndex = -1
+            var % oldvalues2D = 0.
+        endif
+        if ( present(Interpolationshouldbemade) ) then
+            var % Interpolationshouldbemade = Interpolationshouldbemade
+        endif
+    endif
+!
+    var % bcinf = bcinfsup(1)
+    var % bcsup = bcinfsup(2)
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_bc
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_interp
+!> This procedure specify the type of interpolation in case of interpolation within the domain.
+!! The index of the variable we want to interpolate is a profile defined with the subroutine Agrif_Declare_Variable.
+!
+! Interp1 indicates the type of interpolation in the first dimension
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_interp ( tabvarsindic, interp, interp1, interp2, interp3 , interp4)
+!---------------------------------------------------------------------------------------------------
+    integer,           intent(in)   :: tabvarsindic !< index of the variable in tabvars
+    integer, optional, intent(in)   :: interp, interp1, interp2, interp3, interp4 !< The type of interpolation
+!
+    integer                         :: indic ! index of the variable in tabvars
+    type(Agrif_Variable), pointer   :: var
+!
+    var => Agrif_Search_Variable(Agrif_Curgrid,tabvarsindic)
+    if (.not.associated(var)) return ! Grand mother grid case
+!
+    var % type_interp = Agrif_Constant
+!
+    if (present(interp))    var % type_interp    = interp
+    if (present(interp1))   var % type_interp(1) = interp1
+    if (present(interp2))   var % type_interp(2) = interp2
+    if (present(interp3))   var % type_interp(3) = interp3
+    if (present(interp4))   var % type_interp(4) = interp4
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_interp
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Set_bcinterp
+!> This subroutine is used to indicate the type of interpolation in case of boundary interpolation.
+!! The index of the variable we want to interpolate is a profile defined with the subroutine Agrif_Declare_Variable.
+!
+!> Interp1 indicates the type of interpolation in the first dimension
+!! Interp21 indicates the first variable of the second dimension
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_bcinterp ( tabvarsindic, interp,   interp1,  interp2,  interp3, interp4, &
+                                              interp11, interp12, interp21, interp22 )
+!---------------------------------------------------------------------------------------------------
+    INTEGER,           intent(in)   :: tabvarsindic !< index of the variable in tabvars
+    INTEGER, OPTIONAL, intent(in)   :: interp,   interp1,  interp2,  interp3, interp4 !< type of interpolation
+    INTEGER, OPTIONAL, intent(in)   :: interp11, interp12, interp21, interp22 !< dimension we want to interpolate
+!
+    INTEGER                         :: indic ! index of the variable in tabvars
+    TYPE(Agrif_Variable), pointer   :: var
+!
+    var => Agrif_Search_Variable(Agrif_Curgrid,tabvarsindic)
+!
+    var % type_interp_bc = Agrif_Constant
+!
+    if (present(interp))    var % type_interp_bc      = interp
+    if (present(interp1))   var % type_interp_bc(:,1) = interp1
+    if (present(interp11))  var % type_interp_bc(1,1) = interp11
+    if (present(interp12))  var % type_interp_bc(1,2) = interp12
+    if (present(interp2))   var % type_interp_bc(:,2) = interp2
+    if (present(interp21))  var % type_interp_bc(2,1) = interp21
+    if (present(interp22))  var % type_interp_bc(2,2) = interp22
+    if (present(interp3))   var % type_interp_bc(:,3) = interp3
+    if (present(interp4))   var % type_interp_bc(:,4) = interp4
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_bcinterp
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Init_variable
+!> This subroutine is used for interpolation over the whole domain (within the domain and boundaries). 
+!! It specifies the variable we want to interpolate and define through an input procedure (procname) 
+!! what we do either on parent or child grid. The index of the variable we want to interpolate is a profile
+!! defined with the subroutine Agrif_Declare_Variable.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Init_variable ( tabvarsindic, procname )
+!---------------------------------------------------------------------------------------------------
+    INTEGER, intent(in)  :: tabvarsindic     !< index of the variable in tabvars
+    procedure()          :: procname         !< Data recovery procedure written by users
+!
+    if ( Agrif_Curgrid%level <= 0 ) return
+!
+    call Agrif_Interp_variable(tabvarsindic, procname)
+    call Agrif_Bc_variable(tabvarsindic, procname, 1.)
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Init_variable
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Bc_variable
+!> This subroutine is used for boundary interpolation. It specifies the variable we want to interpolate
+!! and define through an input procedure (procname) what we do either on parent or child grid.
+!! The index of the variable we want to interpolate is a profile defined with the subroutine Agrif_Declare_Variable.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Bc_variable ( tabvarsindic, procname, calledweight )
+!---------------------------------------------------------------------------------------------------
+    integer,        intent(in) :: tabvarsindic  !< index of the variable in tabvars
+    procedure()                :: procname		!< Data recovery procedure written by users
+    real, optional, intent(in) :: calledweight	!< weight of interpolation
+!
+    real    :: weight
+    logical :: pweight
+    integer :: indic
+    integer :: nbdim
+    type(Agrif_Variable), pointer :: root_var
+    type(Agrif_Variable), pointer :: parent_var
+    type(Agrif_Variable), pointer :: child_var
+    type(Agrif_Variable), pointer :: child_tmp      ! Temporary variable on the child grid
+    integer :: i
+    integer,dimension(7) :: lb, ub
+!
+    if ( Agrif_Curgrid%level <= 0 ) return
+!
+!
+    if ( present(calledweight) ) then
+        weight  = calledweight
+        pweight = .true.
+    else
+        weight  = 0.
+        pweight = .false.
+    endif
+!
+        child_var  => Agrif_Search_Variable(Agrif_Curgrid,tabvarsindic)
+        parent_var => child_var % parent_var
+        root_var   => child_var % root_var
+!
+    nbdim = root_var % nbdim
+!
+    do i=1,nbdim
+      if (root_var%coords(i) == 0) then
+        lb(i) = parent_var%lb(i)
+        ub(i) = parent_var%ub(i)
+      else
+        lb(i) = child_var%lb(i)
+        ub(i) = child_var%ub(i)
+      endif
+    enddo
+
+    select case( nbdim )
+    case(1)
+        allocate(parray1(lb(1):ub(1)))
+    case(2)
+        allocate(parray2(lb(1):ub(1), &
+                         lb(2):ub(2) ))
+    case(3)
+        allocate(parray3(lb(1):ub(1), &
+                         lb(2):ub(2), &
+                         lb(3):ub(3) ))
+    case(4)
+        allocate(parray4(lb(1):ub(1), &
+                         lb(2):ub(2), &
+                         lb(3):ub(3), &
+                         lb(4):ub(4) ))
+    case(5)
+        allocate(parray5(lb(1):ub(1), &
+                         lb(2):ub(2), &
+                         lb(3):ub(3), &
+                         lb(4):ub(4), &
+                         lb(5):ub(5) ))
+    case(6)
+        allocate(parray6(lb(1):ub(1), &
+                         lb(2):ub(2), &
+                         lb(3):ub(3), &
+                         lb(4):ub(4), &
+                         lb(5):ub(5), &
+                         lb(6):ub(6) ))
+    end select
+!
+!   Create temporary child variable
+    allocate(child_tmp)
+!
+    child_tmp % root_var => root_var
+    child_tmp % oldvalues2D => child_var % oldvalues2D
+!
+!   Index indicating if a space interpolation is necessary
+    child_tmp % interpIndex =  child_var % interpIndex
+    child_tmp % list_interp => child_var % list_interp
+    child_tmp % Interpolationshouldbemade = child_var % Interpolationshouldbemade
+!
+    child_tmp % point = child_var % point
+    child_tmp % lb = child_var % lb
+    child_tmp % ub = child_var % ub
+
+    child_tmp % lubglob = child_var % lubglob
+
+!
+    child_tmp % bcinf = child_var % bcinf
+    child_tmp % bcsup = child_var % bcsup
+!
+    child_tmp % childarray = child_var % childarray
+    child_tmp % memberin   = child_var % memberin
+!
+    call Agrif_CorrectVariable(parent_var, child_tmp, pweight, weight, procname)
+!
+    child_var % childarray = child_tmp % childarray
+    child_var % memberin   = child_tmp % memberin
+!
+    child_var % oldvalues2D => child_tmp % oldvalues2D
+    child_var % list_interp => child_tmp % list_interp
+!
+    child_var % interpIndex = child_tmp % interpIndex
+!
+    deallocate(child_tmp)
+!
+    select case( nbdim )
+        case(1); deallocate(parray1)
+        case(2); deallocate(parray2)
+        case(3); deallocate(parray3)
+        case(4); deallocate(parray4)
+        case(5); deallocate(parray5)
+        case(6); deallocate(parray6)
+    end select
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Bc_variable
+!===================================================================================================
+!
+!===================================================================================================
+!  subroutine Agrif_Interp_variable
+!> This subroutine is used for interpolation within the domain. It specifies the variable we want to interpolate
+!! and define through an input procedure (procname) what we do either on parent or child grid.
+!! The index of the variable we want to interpolate is a profile defined with the subroutine Agrif_Declare_Variable.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Interp_variable ( tabvarsindic, procname )
+!---------------------------------------------------------------------------------------------------
+    integer,     intent(in)     :: tabvarsindic     !< index of the variable in tabvars
+    procedure()                 :: procname         !< Data recovery procedure written by users
+!
+    integer :: nbdim
+    integer :: indic  ! indice of the variable in tabvars
+    logical :: torestore
+    type(Agrif_Variable), pointer   :: root_var
+    type(Agrif_Variable), pointer   :: parent_var       ! Variable on the parent grid
+    type(Agrif_Variable), pointer   :: child_var        ! Variable on the parent grid
+    type(Agrif_Variable), pointer   :: child_tmp        ! Temporary variable on the child grid
+!
+    if ( Agrif_Curgrid%level <= 0 ) return
+!
+
+        child_var  => Agrif_Search_Variable(Agrif_Curgrid,tabvarsindic)
+        parent_var => child_var % parent_var
+        root_var   => child_var % root_var
+
+!
+    nbdim     = root_var % nbdim
+    torestore = root_var % restore
+!
+    allocate(child_tmp)
+!
+    child_tmp % root_var => root_var
+    child_tmp % nbdim = root_var % nbdim
+    child_tmp % point = child_var % point
+    child_tmp % lb = child_var % lb
+    child_tmp % ub = child_var % ub
+    child_tmp % lubglob = child_var % lubglob
+    child_tmp % interpIndex =  child_var % interpIndex
+    child_tmp % list_interp => child_var % list_interp
+    child_tmp % Interpolationshouldbemade = child_var % Interpolationshouldbemade
+!
+    if ( torestore ) then
+        select case( nbdim )
+        case(1)
+            parray1 = child_var % array1
+            child_tmp % restore1D => child_var % restore1D
+        case(2)
+            parray2 = child_var % array2
+            child_tmp % restore2D => child_var % restore2D
+        case(3)
+            parray3 = child_var % array3
+            child_tmp % restore3D => child_var % restore3D
+        case(4)
+            parray4 = child_var % array4
+            child_tmp % restore4D => child_var % restore4D
+        case(5)
+            parray5 = child_var % array5
+            child_tmp % restore5D => child_var % restore5D
+        case(6)
+            parray6 = child_var % array6
+            child_tmp % restore6D => child_var % restore6D
+        end select
+    endif
+!
+    call Agrif_InterpVariable(parent_var, child_tmp, torestore, procname)
+!
+    child_var % list_interp => child_tmp % list_interp
+!
+    deallocate(child_tmp)
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Interp_variable
+!===================================================================================================
+!
+
+end module Agrif_User_Interpolation
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduserupdate.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduserupdate.F90	(revision 10087)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduserupdate.F90	(revision 10087)
@@ -0,0 +1,147 @@
+!
+! $Id: modupdate.F 779 2007-12-22 17:04:17Z rblod $
+!
+!     AGRIF (Adaptive Grid Refinement In Fortran)
+!
+!     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+!                        Christophe Vouland (Christophe.Vouland@imag.fr)
+!
+!     This program is free software; you can redistribute it and/or modify
+!     it under the terms of the GNU General Public License as published by
+!     the Free Software Foundation; either version 2 of the License, or
+!     (at your option) any later version.
+!
+!     This program is distributed in the hope that it will be useful,
+!     but WITHOUT ANY WARRANTY; without even the implied warranty of
+!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+!     GNU General Public License for more details.
+!
+!     You should have received a copy of the GNU General Public License
+!     along with this program; if not, write to the Free Software
+!     Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
+!
+!---------------------------------------------------------------------------------------------------
+!> Module Agrif_User_Update
+!!
+!! This module contains the main procedures used to update a variable.
+!---------------------------------------------------------------------------------------------------
+!
+module Agrif_User_Update
+!
+    use Agrif_Update
+    use Agrif_Save
+!
+    implicit none
+!
+contains
+!
+!
+!===================================================================================================
+!  subroutine Agrif_Set_UpdateType
+!> This subroutine is used to specify the type of update we want to do. The index of the variable we want 
+!! to interpolate is a profile defined with the subroutine Agrif_Declare_Variable.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Set_UpdateType ( tabvarsindic, update,  update1, update2, &
+                                                update3, update4, update5 )
+!---------------------------------------------------------------------------------------------------
+    INTEGER,           intent(in) :: tabvarsindic     !< index of the variable in tabvars
+    INTEGER, OPTIONAL, intent(in) :: update, update1, update2, update3, update4, update5 !< type of update
+!
+    INTEGER                         :: indic ! indice of the variable in tabvars
+    type(Agrif_Variable),  pointer  :: root_var
+!
+
+        root_var => Agrif_Search_Variable(Agrif_Mygrid,tabvarsindic)
+
+!
+    root_var % type_update = Agrif_Update_Copy
+    if (present(update))    root_var % type_update    = update
+    if (present(update1))   root_var % type_update(1) = update1
+    if (present(update2))   root_var % type_update(2) = update2
+    if (present(update3))   root_var % type_update(3) = update3
+    if (present(update4))   root_var % type_update(4) = update4
+    if (present(update5))   root_var % type_update(5) = update5
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Set_UpdateType
+!===================================================================================================
+!
+!
+!===================================================================================================
+!  subroutine Agrif_Update_Variable
+!> This subroutine is used to update variables. When the location is not specify, the update is made 
+!! within the domain of the reference grid (not at boundary). The index of the variable we want to 
+!! interpolate is a profile defined with the subroutine Agrif_Declare_Variable.
+!>locupdate1 : specifies the location for the first dimension.
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Update_Variable ( tabvarsindic, procname, &
+                                   locupdate, locupdate1, locupdate2, locupdate3, locupdate4 )
+!---------------------------------------------------------------------------------------------------
+    integer,               intent(in)           :: tabvarsindic     !< Indice of the variable in tabvars
+    procedure()                                 :: procname         !< Data recovery procedure written by users
+    integer, dimension(2), intent(in), optional :: locupdate		!< location to update
+    integer, dimension(2), intent(in), optional :: locupdate1
+    integer, dimension(2), intent(in), optional :: locupdate2
+    integer, dimension(2), intent(in), optional :: locupdate3
+    integer, dimension(2), intent(in), optional :: locupdate4
+!---------------------------------------------------------------------------------------------------
+    integer :: indic
+    integer :: nbdim
+    integer, dimension(6)           :: updateinf    ! First positions where interpolations are calculated
+    integer, dimension(6)           :: updatesup    ! Last  positions where interpolations are calculated
+    type(Agrif_Variable), pointer   :: root_var
+    type(Agrif_Variable), pointer   :: parent_var
+    type(Agrif_Variable), pointer   :: child_var
+!
+    if ( Agrif_Root() .AND. (.not.agrif_coarse) ) return
+    if (agrif_curgrid%grand_mother_grid) return
+!
+
+        child_var  => Agrif_Search_Variable(Agrif_Curgrid, tabvarsindic)
+        parent_var => child_var % parent_var
+
+        if (.not.associated(parent_var)) then
+          ! can occur during the first update of Agrif_Coarsegrid (if any)
+          parent_var => Agrif_Search_Variable(Agrif_Curgrid % parent, tabvarsindic)
+          child_var % parent_var => parent_var
+        endif
+
+        root_var   => child_var % root_var
+
+!
+    nbdim = root_var % nbdim
+!
+    updateinf = -99
+    updatesup = -99
+!
+    if ( present(locupdate) ) then
+        updateinf(1:nbdim) = locupdate(1)
+        updatesup(1:nbdim) = locupdate(2)
+    endif
+!
+    if ( present(locupdate1) ) then
+        updateinf(1) = locupdate1(1)
+        updatesup(1) = locupdate1(2)
+    endif
+!
+    if ( present(locupdate2) ) then
+        updateinf(2) = locupdate2(1)
+        updatesup(2) = locupdate2(2)
+    endif
+
+    if ( present(locupdate3) ) then
+        updateinf(3) = locupdate3(1)
+        updatesup(3) = locupdate3(2)
+    endif
+
+    if ( present(locupdate4) ) then
+        updateinf(4) = locupdate4(1)
+        updatesup(4) = locupdate4(2)
+    endif
+!
+    call Agrif_UpdateVariable( parent_var, child_var, updateinf, updatesup, procname )
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Update_Variable
+!===================================================================================================
+!
+
+end module Agrif_User_Update
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduservariables.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduservariables.F90	(revision 10087)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/moduservariables.F90	(revision 10087)
@@ -0,0 +1,184 @@
+!
+! $Id: modupdate.F 779 2007-12-22 17:04:17Z rblod $
+!
+!     AGRIF (Adaptive Grid Refinement In Fortran)
+!
+!     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
+!                        Christophe Vouland (Christophe.Vouland@imag.fr)
+!
+!     This program is free software; you can redistribute it and/or modify
+!     it under the terms of the GNU General Public License as published by
+!     the Free Software Foundation; either version 2 of the License, or
+!     (at your option) any later version.
+!
+!     This program is distributed in the hope that it will be useful,
+!     but WITHOUT ANY WARRANTY; without even the implied warranty of
+!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+!     GNU General Public License for more details.
+!
+!     You should have received a copy of the GNU General Public License
+!     along with this program; if not, write to the Free Software
+!     Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
+!
+!----------------------------------------------------------------------------------------------------
+!> Module Agrif_User_Variables
+!!
+!! This module contains a procedure which will help to define a new variable which will 
+!! be used for interpolation/update.
+!----------------------------------------------------------------------------------------------------
+!
+module Agrif_User_Variables
+!
+  use Agrif_User_Functions
+!
+    implicit none
+!
+contains
+!
+!===================================================================================================
+!  subroutine Agrif_Declare_Variable
+!
+!> This subroutine is used to declare a profile (new variable)  which will be used for interpolation/update
+!---------------------------------------------------------------------------------------------------
+subroutine Agrif_Declare_Variable ( posvar, firstpoint, raf, lb, ub, varid, torestore )
+!---------------------------------------------------------------------------------------------------
+    integer,      dimension(:), intent(in)  :: posvar     !< position of the variable on the cell
+                                                          !! (1 for the border of the edge, 2 for the center)
+    integer,      dimension(:), intent(in)  :: firstpoint !< index of the first point in the real domain
+    character(1), dimension(:), intent(in)  :: raf        !< Array indicating the type of dimension (space or not)
+                                                          !!   for each of them
+    integer,      dimension(:), intent(in)  :: lb         !< Lower bounds of the array
+    integer,      dimension(:), intent(in)  :: ub         !< Upper bounds of the array
+    integer,                    intent(out) :: varid      !< Id number of the newly created variable
+    logical,      optional,     intent(in)  :: torestore  !< Indicates if the array restore is used
+!---------------------------------------------------------------------------------------------------
+    type(Agrif_Variables_List), pointer :: new_varlist
+    type(Agrif_Variable),       pointer :: var
+    integer                             :: nbdim, i
+    logical                             :: restore
+
+    restore = .FALSE.
+    if ( Agrif_Mygrid % ngridstep /= 0 ) then
+        if (present(torestore)) restore = torestore
+    endif
+!
+    nbdim = SIZE(posvar)
+!
+    allocate(new_varlist)
+    allocate(new_varlist % var)
+
+    var => new_varlist % var
+
+    allocate(var % posvar(nbdim))
+    allocate(var % interptab(nbdim))
+    allocate(var % coords(nbdim))
+!
+    var % nbdim          = nbdim
+    var % interptab      = raf(1:nbdim)
+    var % posvar         = posvar(1:nbdim)
+    var % point(1:nbdim) = firstpoint(1:nbdim)
+    var % restore = restore
+!
+    do i = 1,nbdim
+        select case( raf(i) )
+            case('x')    ; var % coords(i) = 1
+            case('y')    ; var % coords(i) = 2
+            case('z')    ; var % coords(i) = 3
+            case('N')    ; var % coords(i) = 0
+            case default ; var % coords(i) = 0
+        end select
+    enddo
+!
+    var % lb(1:nbdim) = lb(1:nbdim)
+    var % ub(1:nbdim) = ub(1:nbdim)
+
+
+    if ( restore ) then
+        select case(nbdim)
+        case(1)
+            allocate(var % Restore1D(lb(1):ub(1)))
+            var % Restore1D = 0
+        case(2)
+            allocate(var % Restore2D(lb(1):ub(1),   &
+                                     lb(2):ub(2)))
+            var % Restore2D = 0
+        case(3)
+            allocate(var % Restore3D(lb(1):ub(1),   &
+                                     lb(2):ub(2),   &
+                                     lb(3):ub(3)))
+            var % Restore3D = 0
+        case(4)
+            allocate(var % Restore4D(lb(1):ub(1),   &
+                                     lb(2):ub(2),   &
+                                     lb(3):ub(3),   &
+                                     lb(4):ub(4)))
+            var % Restore4D = 0
+        case(5)
+            allocate(var % Restore5D(lb(1):ub(1),   &
+                                     lb(2):ub(2),   &
+                                     lb(3):ub(3),   &
+                                     lb(4):ub(4),   &
+                                     lb(5):ub(5)))
+            var % Restore5D = 0
+        end select
+    endif
+
+    new_varlist % next => Agrif_Curgrid % variables
+
+    Agrif_Curgrid % variables => new_varlist
+    Agrif_Curgrid % Nbvariables = Agrif_Curgrid % Nbvariables + 1
+
+    varid = Agrif_Curgrid % Nbvariables
+
+    var % parent_var => Agrif_Search_Variable(Agrif_Curgrid % parent, Agrif_Curgrid % nbvariables)
+    var % root_var   => Agrif_Search_Variable(Agrif_Mygrid, Agrif_Curgrid % nbvariables)
+
+#if defined AGRIF_MPI
+    call Agrif_get_var_global_bounds(var,var%lubglob(1:nbdim,:),nbdim)
+#else
+    var%lubglob(1:nbdim,1) = var % lb(1:nbdim)
+	var%lubglob(1:nbdim,2) = var % ub(1:nbdim)
+#endif
+!---------------------------------------------------------------------------------------------------
+end subroutine Agrif_Declare_Variable
+!===================================================================================================
+!
+!===================================================================================================
+!  function Agrif_Search_Variable
+!
+!> \cond Returns a pointer to the variable varid for the grid grid.
+!---------------------------------------------------------------------------------------------------
+function Agrif_Search_Variable ( grid, varid ) result(outvar)
+!---------------------------------------------------------------------------------------------------
+    type(Agrif_Grid), pointer       :: grid     !< Pointer on the current grid.
+    integer,          intent(in)    :: varid    !< ID number of the variable we are looking for.
+!
+    type(Agrif_Variable),       pointer :: outvar
+    type(Agrif_Variables_List), pointer :: parcours
+    integer :: nb, varidinv
+!
+    if ( .not.associated(grid) ) then
+        outvar => NULL()
+        return
+    endif
+!
+    parcours => grid % variables
+
+    if (.not. associated(parcours)) then   ! can occur on the grand mother grid
+           outvar => NULL()                ! during the first call by agrif_mygrid
+           return
+    endif
+
+    varidinv = 1 + grid % nbvariables - varid
+
+    do nb = 1,varidinv-1
+        parcours => parcours % next
+    enddo
+
+    outvar => parcours % var
+!---------------------------------------------------------------------------------------------------
+end function Agrif_Search_variable
+!===================================================================================================
+!
+!!\endcond
+end module Agrif_User_Variables
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modutil.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modutil.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modutil.F90	(revision 10087)
@@ -2,5 +2,5 @@
 ! $Id$
 !
-!     Agrif (Adaptive Grid Refinement In Fortran)
+!     AGRIF (Adaptive Grid Refinement In Fortran)
 !
 !     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
@@ -19,1089 +19,25 @@
 !     You should have received a copy of the GNU General Public License
 !     along with this program; if not, write to the Free Software
-!     Foundation, Inc., 59 Temple Place-  Suite 330, Boston, MA 02111-1307, USA.
+!     Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
 !
 !> Module Agrif_Util
-!!
-!! This module contains the two procedures called in the main program :
-!! - #Agrif_Init_Grids allows the initialization of the root coarse grid
-!! - #Agrif_Step allows the creation of the grid hierarchy and the management of the time integration.
+!>
+!> 
+!
 !
 module Agrif_Util
 !
-    use Agrif_Clustering
-    use Agrif_BcFunction
-    use Agrif_seq
-    use Agrif_Link
+  use Agrif_User_Hierarchy
+  use Agrif_User_Variables
+  use Agrif_user_Functions
+  use Agrif_user_Interpolation
+  use Agrif_user_Update
+ 
 !
     implicit none
 !
-    abstract interface
-        subroutine step_proc()
-        end subroutine step_proc
-    end interface
-!
 contains
 !
-!===================================================================================================
-!  subroutine Agrif_Step
-!
-!> Creates the grid hierarchy and manages the time integration procedure.
-!> It is called in the main program.
-!> Calls subroutines #Agrif_Regrid and #Agrif_Integrate.
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Step ( procname )
-!---------------------------------------------------------------------------------------------------
-    procedure(step_proc)    :: procname     !< subroutine to call on each grid
-    type(agrif_grid), pointer :: ref_grid
-!
-! Set the clustering variables
-    call Agrif_clustering_def()
-!
-! Creation and initialization of the grid hierarchy
-    if ( Agrif_USE_ONLY_FIXED_GRIDS == 1 ) then
-!
-        if ( (Agrif_Mygrid % ngridstep == 0) .AND. (.not. Agrif_regrid_has_been_done) ) then
-            call Agrif_Regrid()
-            Agrif_regrid_has_been_done = .TRUE.
-        endif
-!
-    else
-!
-        if (mod(Agrif_Mygrid % ngridstep,Agrif_Regridding) == 0) then
-            call Agrif_Regrid()
-        endif
-!
-    endif
-!
-! Time integration of the grid hierarchy
-    if (agrif_coarse) then
-      ref_grid => agrif_coarsegrid
-    else
-      ref_grid => agrif_mygrid
-    endif
-    if ( Agrif_Parallel_sisters ) then
-        call Agrif_Integrate_Parallel(ref_grid,procname)
-    else
-        call Agrif_Integrate(ref_grid,procname)
-    endif
-!
-    if ( ref_grid%child_list%nitems > 0 ) call Agrif_Instance(ref_grid)
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Step
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Step_Child
-!
-!> Apply 'procname' to each grid of the hierarchy
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Step_Child ( procname )
-!---------------------------------------------------------------------------------------------------
-    procedure(step_proc)    :: procname     !< subroutine to call on each grid
-!
-    if ( Agrif_Parallel_sisters ) then
-        call Agrif_Integrate_Child_Parallel(Agrif_Mygrid,procname)
-    else
-        call Agrif_Integrate_Child(Agrif_Mygrid,procname)
-    endif
-!
-    if ( Agrif_Mygrid%child_list%nitems > 0 ) call Agrif_Instance(Agrif_Mygrid)
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Step_Child
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Regrid
-!
-!> Creates the grid hierarchy from fixed grids and adaptive mesh refinement.
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Regrid ( procname )
-!---------------------------------------------------------------------------------------------------
-    procedure(init_proc), optional    :: procname     !< Initialisation subroutine (Default: Agrif_InitValues)
-!
-    type(Agrif_Rectangle), pointer     :: coarsegrid_fixed
-    type(Agrif_Rectangle), pointer     :: coarsegrid_moving
-    integer                            :: i, j
-    integer :: nunit
-    logical :: BEXIST
-    TYPE(Agrif_Rectangle)            :: newrect    ! Pointer on a new grid
-    integer :: is_coarse, rhox, rhoy, rhoz, rhot
-!
-    if ( Agrif_USE_ONLY_FIXED_GRIDS == 0 ) &
-        call Agrif_detect_all(Agrif_Mygrid)     ! Detection of areas to be refined
-!
-    allocate(coarsegrid_fixed)
-    allocate(coarsegrid_moving)
-!
-    if ( Agrif_USE_ONLY_FIXED_GRIDS == 0 ) &
-        call Agrif_Cluster_All(Agrif_Mygrid,coarsegrid_moving) ! Clustering
-!
-    if ( Agrif_USE_FIXED_GRIDS == 1 .OR. Agrif_USE_ONLY_FIXED_GRIDS == 1 ) then
-!
-        if (Agrif_Mygrid % ngridstep == 0) then
-!            
-            nunit = Agrif_Get_Unit()
-            open(nunit, file='AGRIF_FixedGrids.in', form='formatted', status="old", ERR=99)
-            if (agrif_coarse) then ! SKIP the coarse grid declaration
-                if (Agrif_Probdim == 3) then
-                    read(nunit,*) is_coarse, rhox, rhoy, rhoz, rhot
-                elseif (Agrif_Probdim == 2) then
-                    read(nunit,*) is_coarse, rhox, rhoy, rhot
-                elseif (Agrif_Probdim == 2) then
-                    read(nunit,*) is_coarse, rhox, rhot
-                endif
-            endif
-!           Creation of the grid hierarchy from the Agrif_FixedGrids.in file
-            do i = 1,Agrif_Probdim
-                coarsegrid_fixed % imin(i) = 1
-                coarsegrid_fixed % imax(i) = Agrif_Mygrid % nb(i) + 1
-            enddo
-            j = 1
-            call Agrif_Read_Fix_Grd(coarsegrid_fixed,j,nunit)
-            close(nunit)
-!
-            call Agrif_gl_clear(Agrif_oldmygrid)
-!
-!           Creation of the grid hierarchy from coarsegrid_fixed
-            call Agrif_Create_Grids(Agrif_Mygrid,coarsegrid_fixed)
-            
-        else
-            call Agrif_gl_copy(Agrif_oldmygrid, Agrif_Mygrid % child_list)
-        endif
-    else
-        call Agrif_gl_copy(Agrif_oldmygrid, Agrif_Mygrid % child_list)
-        call Agrif_gl_clear(Agrif_Mygrid % child_list)
-    endif
-!
-    if ( Agrif_USE_ONLY_FIXED_GRIDS == 0 ) then
-!
-        call Agrif_Save_All(Agrif_oldmygrid)
-        call Agrif_Free_before_All(Agrif_oldmygrid)
-!
-!       Creation of the grid hierarchy from coarsegrid_moving
-        call Agrif_Create_Grids(Agrif_Mygrid,coarsegrid_moving)
-!
-    endif
-!
-!   Initialization of the grid hierarchy by copy or interpolation
-!
-#if defined AGRIF_MPI
-    if ( Agrif_Parallel_sisters ) then
-        call Agrif_Init_Hierarchy_Parallel_1(Agrif_Mygrid)
-        call Agrif_Init_Hierarchy_Parallel_2(Agrif_Mygrid,procname)
-    else
-        call Agrif_Init_Hierarchy(Agrif_Mygrid,procname)
-    endif
-#else
-        call Agrif_Init_Hierarchy(Agrif_Mygrid,procname)
-#endif
-!
-    if ( Agrif_USE_ONLY_FIXED_GRIDS == 0 ) call Agrif_Free_after_All(Agrif_oldmygrid)
-!
-    Agrif_regrid_has_been_done = .TRUE.
-!
-    call Agrif_Instance( Agrif_Mygrid )
-!
-    deallocate(coarsegrid_fixed)
-    deallocate(coarsegrid_moving)
-!
-    return
-!
-!     Opening error
-!
-99  INQUIRE(FILE='AGRIF_FixedGrids.in',EXIST=BEXIST)
-    if (.not. BEXIST) then
-        print*,'ERROR : File AGRIF_FixedGrids.in not found.'
-        STOP
-    else
-        print*,'Error opening file AGRIF_FixedGrids.in'
-        STOP
-    endif
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Regrid
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_detect_All
-!
-!> Detects areas to be refined.
-!---------------------------------------------------------------------------------------------------
-recursive subroutine Agrif_detect_all ( g )
-!---------------------------------------------------------------------------------------------------
-    TYPE(Agrif_Grid),  pointer  :: g        !< Pointer on the current grid
-!
-    Type(Agrif_PGrid), pointer  :: parcours ! Pointer for the recursive procedure
-    integer, DIMENSION(3)       :: size
-    integer                     :: i
-    real                        :: g_eps
-!
-    parcours => g % child_list % first
-!
-!   To be positioned on the finer grids of the grid hierarchy
-!
-    do while (associated(parcours))
-        call Agrif_detect_all(parcours % gr)
-        parcours => parcours % next
-    enddo
-!
-    g_eps = huge(1.)
-    do i = 1,Agrif_Probdim
-        g_eps = min(g_eps, g % Agrif_dx(i))
-    enddo
-!
-    g_eps = g_eps / 100.
-!
-    if ( Agrif_Probdim == 1 ) g%tabpoint1D = 0
-    if ( Agrif_Probdim == 2 ) g%tabpoint2D = 0
-    if ( Agrif_Probdim == 3 ) g%tabpoint3D = 0
-!
-    do i = 1,Agrif_Probdim
-        if ( g%Agrif_dx(i)/Agrif_coeffref(i) < (Agrif_mind(i)-g_eps) ) return
-    enddo
-!
-    call Agrif_instance(g)
-!
-!   Detection (Agrif_detect is a users routine)
-!
-    do i = 1,Agrif_Probdim
-        size(i) = g % nb(i) + 1
-    enddo
-!
-    SELECT CASE (Agrif_Probdim)
-    CASE (1)
-        call Agrif_detect(g%tabpoint1D,size)
-    CASE (2)
-        call Agrif_detect(g%tabpoint2D,size)
-    CASE (3)
-        call Agrif_detect(g%tabpoint3D,size)
-    END SELECT
-!
-!   Addition of the areas detected on the child grids
-!
-    parcours => g % child_list % first
-!
-    do while (associated(parcours))
-        call Agrif_Add_detected_areas(g,parcours % gr)
-        parcours => parcours % next
-    enddo
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_detect_all
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Add_detected_areas
-!
-!> Adds on the parent grid the areas detected on its child grids
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Add_detected_areas ( parentgrid, childgrid )
-!---------------------------------------------------------------------------------------------------
-    Type(Agrif_Grid), pointer   :: parentgrid
-    Type(Agrif_Grid), pointer   :: childgrid
-!
-    integer :: i,j,k
-!
-    do i = 1,childgrid%nb(1)+1
-        if ( Agrif_Probdim == 1 ) then
-            if (childgrid%tabpoint1D(i)==1) then
-                parentgrid%tabpoint1D(childgrid%ix(1)+(i-1)/Agrif_Coeffref(1)) = 1
-            endif
-        else
-            do j=1,childgrid%nb(2)+1
-                if (Agrif_Probdim==2) then
-                    if (childgrid%tabpoint2D(i,j)==1) then
-                        parentgrid%tabpoint2D(                       &
-                            childgrid%ix(1)+(i-1)/Agrif_Coeffref(1), &
-                            childgrid%ix(2)+(j-1)/Agrif_Coeffref(2)) = 1
-                    endif
-                else
-                    do k=1,childgrid%nb(3)+1
-                        if (childgrid%tabpoint3D(i,j,k)==1) then
-                            parentgrid%tabpoint3D(                       &
-                                childgrid%ix(1)+(i-1)/Agrif_Coeffref(1), &
-                                childgrid%ix(2)+(j-1)/Agrif_Coeffref(2), &
-                                childgrid%ix(3)+(k-1)/Agrif_Coeffref(3)) = 1
-                        endif
-                    enddo
-                endif
-            enddo
-        endif
-    enddo
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Add_detected_areas
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Free_before_All
-!---------------------------------------------------------------------------------------------------
-recursive subroutine Agrif_Free_before_All ( gridlist )
-!---------------------------------------------------------------------------------------------------
-    Type(Agrif_Grid_List), intent(inout)    :: gridlist !< Grid list
-!
-    Type(Agrif_PGrid), pointer   :: parcours ! Pointer for the recursive procedure
-!
-    parcours => gridlist % first
-!
-    do while (associated(parcours))
-!
-        if (.not. parcours%gr%fixed) then
-            call Agrif_Free_data_before(parcours%gr)
-            parcours % gr % oldgrid = .TRUE.
-        endif
-!
-        call Agrif_Free_before_all (parcours % gr % child_list)
-!
-        parcours => parcours % next
-!
-    enddo
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Free_before_All
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Save_All
-!---------------------------------------------------------------------------------------------------
-recursive subroutine Agrif_Save_All ( gridlist )
-!---------------------------------------------------------------------------------------------------
-    type(Agrif_Grid_List), intent(inout)    :: gridlist !< Grid list
-!
-    type(Agrif_PGrid), pointer   :: parcours ! Pointer for the recursive procedure
-!
-    parcours => gridlist % first
-!
-    do while (associated(parcours))
-!
-        if (.not. parcours%gr%fixed) then
-            call Agrif_Instance(parcours%gr)
-            call Agrif_Before_Regridding()
-            parcours % gr % oldgrid = .TRUE.
-        endif
-!
-        call Agrif_Save_All(parcours % gr % child_list)
-!
-        parcours => parcours % next
-!
-      enddo
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Save_All
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Free_after_All
-!---------------------------------------------------------------------------------------------------
-recursive subroutine Agrif_Free_after_All ( gridlist )
-!---------------------------------------------------------------------------------------------------
-    Type(Agrif_Grid_List), intent(inout)    :: gridlist       !< Grid list to free
-!
-    Type(Agrif_PGrid), pointer  :: parcours ! Pointer for the recursive proced
-    Type(Agrif_PGrid), pointer  :: preparcours
-    Type(Agrif_PGrid), pointer  :: preparcoursini
-!
-    allocate(preparcours)
-!
-    preparcoursini => preparcours
-!
-    nullify(preparcours % gr)
-!
-    preparcours % next => gridlist % first
-    parcours => gridlist % first
-!
-    do while (associated(parcours))
-!
-        if ( (.NOT. parcours%gr % fixed) .AND. (parcours%gr % oldgrid) ) then
-            call Agrif_Free_data_after(parcours%gr)
-        endif
-!
-        call Agrif_Free_after_all( parcours%gr % child_list )
-!
-        if (parcours % gr % oldgrid) then
-            deallocate(parcours % gr)
-            preparcours % next => parcours % next
-            deallocate(parcours)
-            parcours => preparcours % next
-        else
-            preparcours => preparcours % next
-            parcours => parcours % next
-        endif
-!
-    enddo
-!
-    deallocate(preparcoursini)
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Free_after_All
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Integrate
-!
-!> Manages the time integration of the grid hierarchy.
-!! Recursive subroutine and call on subroutines Agrif_Init::Agrif_Instance and #Agrif_Step
-!---------------------------------------------------------------------------------------------------
-recursive subroutine Agrif_Integrate ( g, procname )
-!---------------------------------------------------------------------------------------------------
-    type(Agrif_Grid), pointer   :: g        !< Pointer on the current grid
-    procedure(step_proc)        :: procname !< Subroutine to call on each grid
-!
-    type(Agrif_PGrid), pointer  :: parcours ! Pointer for the recursive procedure
-    integer                     :: nbt      ! Number of time steps of the current grid
-    integer                     :: i, k
-!
-!   Instanciation of the variables of the current grid
-!    if ( g % fixedrank /= 0 ) then
-        call Agrif_Instance(g)
-!    endif
-!
-!   One step on the current grid
-!
-    call procname ()
-!
-!   Number of time steps on the current grid
-!
-    g%ngridstep = g % ngridstep + 1
-    parcours => g % child_list % first
-!
-!   Recursive procedure for the time integration of the grid hierarchy
-    do while (associated(parcours))
-!
-!       Instanciation of the variables of the current grid
-        call Agrif_Instance(parcours % gr)
-!
-!       Number of time steps
-        nbt = 1
-        do i = 1,Agrif_Probdim
-            nbt = max(nbt, parcours % gr % timeref(i))
-        enddo
-!
-        do k = 1,nbt
-            call Agrif_Integrate(parcours % gr, procname)
-        enddo
-!
-        parcours => parcours % next
-!
-    enddo
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Integrate
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Integrate_Parallel
-!
-!> Manages the time integration of the grid hierarchy in parallel
-!! Recursive subroutine and call on subroutines Agrif_Init::Agrif_Instance and #Agrif_Step
-!---------------------------------------------------------------------------------------------------
-recursive subroutine Agrif_Integrate_Parallel ( g, procname )
-!---------------------------------------------------------------------------------------------------
-    type(Agrif_Grid), pointer   :: g        !< Pointer on the current grid
-    procedure(step_proc)        :: procname !< Subroutine to call on each grid
-!
-#if defined AGRIF_MPI
-    type(Agrif_PGrid), pointer  :: gridp    ! Pointer for the recursive procedure
-    integer                     :: nbt      ! Number of time steps of the current grid
-    integer                     :: i, k, is
-!
-!   Instanciation of the variables of the current grid
-    if ( g % fixedrank /= 0 ) then
-        call Agrif_Instance(g)
-    endif
-!
-! One step on the current grid
-    call procname ()
-!
-! Number of time steps on the current grid
-    g % ngridstep = g % ngridstep + 1
-!
-! Continue only if the grid has defined sequences of child integrations.
-    if ( .not. associated(g % child_seq) ) return
-!
-    do is = 1, g % child_seq % nb_seqs
-!
-!     For each sequence, a given processor does integrate only on grid.
-        gridp => Agrif_seq_select_child(g,is)
-!
-!     Instanciation of the variables of the current grid
-        call Agrif_Instance(gridp % gr)
-!
-!     Number of time steps
-        nbt = 1
-        do i = 1,Agrif_Probdim
-            nbt = max(nbt, gridp % gr % timeref(i))
-        enddo
-!
-        do k = 1,nbt
-            call Agrif_Integrate_Parallel(gridp % gr, procname)
-        enddo
-!
-    enddo
-#else
-    call Agrif_Integrate( g, procname )
-#endif
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Integrate_Parallel
-!===================================================================================================
-!
-!
-!===================================================================================================
-!  subroutine Agrif_Integrate_ChildGrids
-!
-!> Manages the time integration of the grid hierarchy.
-!! Call the subroutine procname on each child grid of the current grid
-!---------------------------------------------------------------------------------------------------
-recursive subroutine Agrif_Integrate_ChildGrids ( procname )
-!---------------------------------------------------------------------------------------------------
-    procedure(step_proc)        :: procname !< Subroutine to call on each grid
-!
-    type(Agrif_PGrid), pointer  :: parcours ! Pointer for the recursive procedure
-    integer                     :: nbt      ! Number of time steps of the current grid
-    integer                     :: i, k, is
-    type(Agrif_Grid)                    , pointer :: save_grid
-    type(Agrif_PGrid), pointer  :: gridp    ! Pointer for the recursive procedure
-    
-    save_grid => Agrif_Curgrid
 
-! Number of time steps on the current grid
-    save_grid % ngridstep = save_grid % ngridstep + 1
-    
-#ifdef AGRIF_MPI
-    if ( .not. Agrif_Parallel_sisters ) then
-#endif
-    parcours => save_grid % child_list % first
-!
-!   Recursive procedure for the time integration of the grid hierarchy
-    do while (associated(parcours))
-!
-!       Instanciation of the variables of the current grid
-        call Agrif_Instance(parcours % gr)
-!
-!       Number of time steps
-        nbt = 1
-        do i = 1,Agrif_Probdim
-            nbt = max(nbt, parcours % gr % timeref(i))
-        enddo
-!
-        do k = 1,nbt
-            call procname()
-        enddo
-!
-        parcours => parcours % next
-!
-    enddo
-
-#ifdef AGRIF_MPI
-    else
-! Continue only if the grid has defined sequences of child integrations.
-    if ( .not. associated(save_grid % child_seq) ) return
-!
-    do is = 1, save_grid % child_seq % nb_seqs
-!
-!     For each sequence, a given processor does integrate only on grid.
-        gridp => Agrif_seq_select_child(save_grid,is)
-!
-!     Instanciation of the variables of the current grid
-        call Agrif_Instance(gridp % gr)
-!
-!     Number of time steps
-        nbt = 1
-        do i = 1,Agrif_Probdim
-            nbt = max(nbt, gridp % gr % timeref(i))
-        enddo
-!
-        do k = 1,nbt
-            call procname()
-        enddo
-!
-    enddo
-    endif
-#endif 
-
-    call Agrif_Instance(save_grid)
-    
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Integrate_ChildGrids
-!===================================================================================================
-!===================================================================================================
-!  subroutine Agrif_Integrate_Child
-!
-!> Manages the time integration of the grid hierarchy.
-!! Recursive subroutine and call on subroutines Agrif_Instance & Agrif_Step.
-!---------------------------------------------------------------------------------------------------
-recursive subroutine Agrif_Integrate_Child ( g, procname )
-!---------------------------------------------------------------------------------------------------
-    type(Agrif_Grid), pointer   :: g        !< Pointer on the current grid
-    procedure(step_proc)        :: procname !< Subroutine to call on each grid
-!
-    type(Agrif_PGrid), pointer  :: parcours ! Pointer for the recursive procedure
-!
-!   One step on the current grid
-!
-    call procname ()
-!
-!   Number of time steps on the current grid
-!
-    parcours => g % child_list % first
-!
-!   Recursive procedure for the time integration of the grid hierarchy
-    do while (associated(parcours))
-!
-!       Instanciation of the variables of the current grid
-        call Agrif_Instance(parcours % gr)
-        call Agrif_Integrate_Child (parcours % gr, procname)
-        parcours => parcours % next
-!
-    enddo
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Integrate_Child
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Integrate_Child_Parallel
-!
-!> Manages the time integration of the grid hierarchy.
-!! Recursive subroutine and call on subroutines Agrif_Instance & Agrif_Step.
-!---------------------------------------------------------------------------------------------------
-recursive subroutine Agrif_Integrate_Child_Parallel ( g, procname )
-!---------------------------------------------------------------------------------------------------
-    type(Agrif_Grid), pointer   :: g        !< Pointer on the current grid
-    procedure(step_proc)        :: procname !< Subroutine to call on each grid
-!
-#if defined AGRIF_MPI
-    type(Agrif_PGrid), pointer  :: gridp    ! Pointer for the recursive procedure
-    integer                     :: is
-!
-! Instanciation of the variables of the current grid
-    call Agrif_Instance(g)
-!
-! One step on the current grid
-    call procname ()
-!
-! Continue only if the grid has defined sequences of child integrations.
-    if ( .not. associated(g % child_seq) ) return
-!
-    do is = 1, g % child_seq % nb_seqs
-!
-!     For each sequence, a given processor does integrate only on grid.
-        gridp => Agrif_seq_select_child(g,is)
-        call Agrif_Integrate_Child_Parallel(gridp % gr, procname)
-!
-    enddo
-!
-    call Agrif_Instance(g)
-#else
-    call Agrif_Integrate_Child( g, procname )
-#endif
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Integrate_Child_Parallel
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Init_Grids
-!
-!> Initializes the root coarse grid pointed by Agrif_Mygrid. It is called in the main program.
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Init_Grids ( procname1, procname2 )
-!---------------------------------------------------------------------------------------------------
-    procedure(typedef_proc), optional   :: procname1 !< (Default: Agrif_probdim_modtype_def)
-    procedure(alloc_proc),   optional   :: procname2 !< (Default: Agrif_Allocationcalls)
-!
-    integer :: i, ierr_allocate, nunit
-    integer :: is_coarse, rhox,rhoy,rhoz,rhot
-    logical :: BEXIST
-!
-    if (present(procname1)) Then
-        call procname1()
-    else
-        call Agrif_probdim_modtype_def()
-    endif
-!
-
-! TEST FOR COARSE GRID (GRAND MOTHER GRID) in AGRIF_FixedGrids.in
-    nunit = Agrif_Get_Unit()
-    open(nunit, file='AGRIF_FixedGrids.in', form='formatted', status="old", ERR=98)
-    if (Agrif_Probdim == 3) then
-       read(nunit,*) is_coarse, rhox, rhoy, rhoz, rhot
-    elseif (Agrif_Probdim == 2) then
-       read(nunit,*) is_coarse, rhox, rhoy, rhot
-    elseif (Agrif_Probdim == 2) then
-       read(nunit,*) is_coarse, rhox, rhot
-    endif
-    if (is_coarse == -1) then
-       agrif_coarse = .TRUE.
-       if (Agrif_Probdim == 3) then
-          coarse_spaceref(1:3)=(/rhox,rhoy,rhoz/)
-       elseif (Agrif_Probdim == 2) then
-          coarse_spaceref(1:2)=(/rhox,rhoy/)
-       elseif (Agrif_Probdim == 2) then
-          coarse_spaceref(1:1)=(/rhox/)
-       endif
-       coarse_timeref(1:Agrif_Probdim) = rhot
-    endif
-    close(nunit)
-    
-    Agrif_UseSpecialValue = .FALSE.
-    Agrif_UseSpecialValueFineGrid = .FALSE.
-    Agrif_SpecialValue = 0.
-    Agrif_SpecialValueFineGrid = 0.
-!
-    allocate(Agrif_Mygrid)
-    allocate(Agrif_OldMygrid)
-!
-!   Space and time refinement factors are set to 1 on the root grid
-!
-    do i = 1,Agrif_Probdim
-        Agrif_Mygrid % spaceref(i) = coarse_spaceref(i)
-        Agrif_Mygrid % timeref(i)  = coarse_timeref(i)
-    enddo
-!
-!   Initialization of the number of time steps
-    Agrif_Mygrid % ngridstep = 0
-    Agrif_Mygrid % grid_id   = 0
-!
-!   No parent grid for the root coarse grid
-    nullify(Agrif_Mygrid % parent)
-!
-!   Initialization of the minimum positions, global abscissa and space steps
-    do i = 1, Agrif_Probdim
-        Agrif_Mygrid % ix(i) = 1
-        Agrif_Mygrid % Agrif_x(i)  = 0.
-        Agrif_Mygrid % Agrif_dx(i) = 1./Agrif_Mygrid % spaceref(i)
-        Agrif_Mygrid % Agrif_dt(i) = 1./Agrif_Mygrid % timeref(i)
-!       Borders of the root coarse grid
-        Agrif_Mygrid % NearRootBorder(i) = .true.
-        Agrif_Mygrid % DistantRootBorder(i) = .true.
-    enddo
-!
-!   The root coarse grid is a fixed grid
-    Agrif_Mygrid % fixed = .TRUE.
-!   Level of the root grid
-    Agrif_Mygrid % level = 0
-!   Maximum level in the hierarchy
-    Agrif_MaxLevelLoc = 0
-!
-!   Number of the grid pointed by Agrif_Mygrid (root coarse grid)
-    Agrif_Mygrid % rank = 1
-!
-!   Number of the root grid as a fixed grid
-    Agrif_Mygrid % fixedrank = 0
-!
-!   Initialization of some fields of the root grid variables
-    ierr_allocate = 0
-    if( Agrif_NbVariables(0) > 0 ) allocate(Agrif_Mygrid % tabvars(Agrif_NbVariables(0)),stat=ierr_allocate)
-    if( Agrif_NbVariables(1) > 0 ) allocate(Agrif_Mygrid % tabvars_c(Agrif_NbVariables(1)),stat=ierr_allocate)
-    if( Agrif_NbVariables(2) > 0 ) allocate(Agrif_Mygrid % tabvars_r(Agrif_NbVariables(2)),stat=ierr_allocate)
-    if( Agrif_NbVariables(3) > 0 ) allocate(Agrif_Mygrid % tabvars_l(Agrif_NbVariables(3)),stat=ierr_allocate)
-    if( Agrif_NbVariables(4) > 0 ) allocate(Agrif_Mygrid % tabvars_i(Agrif_NbVariables(4)),stat=ierr_allocate)
-    if (ierr_allocate /= 0) THEN
-      STOP "*** ERROR WHEN ALLOCATING TABVARS ***"
-    endif
-!
-!   Initialization of the other fields of the root grid variables (number of
-!   cells, positions, number and type of its dimensions, ...)
-    call Agrif_Instance(Agrif_Mygrid)
-    call Agrif_Set_numberofcells(Agrif_Mygrid)
-!
-!   Allocation of the array containing the values of the grid variables
-    call Agrif_Allocation(Agrif_Mygrid, procname2)
-    call Agrif_initialisations(Agrif_Mygrid)
-!
-!   Total number of fixed grids
-    Agrif_nbfixedgrids = 0
-    
-! If a grand mother grid is declared
-
-    if (agrif_coarse) then
-      allocate(Agrif_Coarsegrid)
-
-      Agrif_Coarsegrid % ngridstep = 0
-      Agrif_Coarsegrid % grid_id   = -9999
-      
-    do i = 1, Agrif_Probdim
-        Agrif_Coarsegrid%spaceref(i) = coarse_spaceref(i)
-        Agrif_Coarsegrid%timeref(i) = coarse_timeref(i)
-        Agrif_Coarsegrid % ix(i) = 1
-        Agrif_Coarsegrid % Agrif_x(i)  = 0.
-        Agrif_Coarsegrid % Agrif_dx(i) = 1.
-        Agrif_Coarsegrid % Agrif_dt(i) = 1.
-!       Borders of the root coarse grid
-        Agrif_Coarsegrid % NearRootBorder(i) = .true.
-        Agrif_Coarsegrid % DistantRootBorder(i) = .true.
-        Agrif_Coarsegrid % nb(i) =Agrif_mygrid%nb(i) / coarse_spaceref(i)
-    enddo      
-
-!   The root coarse grid is a fixed grid
-    Agrif_Coarsegrid % fixed = .TRUE.
-!   Level of the root grid
-    Agrif_Coarsegrid % level = -1
-    
-    Agrif_Coarsegrid % grand_mother_grid = .true.
-
-!   Number of the grid pointed by Agrif_Mygrid (root coarse grid)
-    Agrif_Coarsegrid % rank = -9999
-!
-!   Number of the root grid as a fixed grid
-    Agrif_Coarsegrid % fixedrank = -9999
-    
-      Agrif_Mygrid%parent => Agrif_Coarsegrid
-      
-! Not used but required to prevent seg fault
-      Agrif_Coarsegrid%parent => Agrif_Mygrid
-      
-      call Agrif_Create_Var(Agrif_Coarsegrid)
-
-! Reset to null
-      Nullify(Agrif_Coarsegrid%parent)
-      
-      Agrif_Coarsegrid%child_list%nitems = 1
-      allocate(Agrif_Coarsegrid%child_list%first)
-      allocate(Agrif_Coarsegrid%child_list%last)
-      Agrif_Coarsegrid%child_list%first%gr => Agrif_Mygrid
-      Agrif_Coarsegrid%child_list%last%gr => Agrif_Mygrid
-
-    endif
-    
-    return
-
-98  INQUIRE(FILE='AGRIF_FixedGrids.in',EXIST=BEXIST)
-    if (.not. BEXIST) then
-        print*,'ERROR : File AGRIF_FixedGrids.in not found.'
-        STOP
-    else
-        print*,'Error opening file AGRIF_FixedGrids.in'
-        STOP
-    endif
-    
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Init_Grids
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Deallocation
-!
-!> Deallocates all data arrays.
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Deallocation
-!---------------------------------------------------------------------------------------------------
-    integer                         :: nb
-    type(Agrif_Variable), pointer   :: var
-    type(Agrif_Variable_c), pointer   :: var_c
-    type(Agrif_Variable_l), pointer   :: var_l
-    type(Agrif_Variable_i), pointer   :: var_i
-!
-    do nb = 1,Agrif_NbVariables(0)
-!
-        var => Agrif_Mygrid % tabvars(nb)
-!
-        if ( allocated(var % array1) ) deallocate(var % array1)
-        if ( allocated(var % array2) ) deallocate(var % array2)
-        if ( allocated(var % array3) ) deallocate(var % array3)
-        if ( allocated(var % array4) ) deallocate(var % array4)
-        if ( allocated(var % array5) ) deallocate(var % array5)
-        if ( allocated(var % array6) ) deallocate(var % array6)
-!
-        if ( allocated(var % sarray1) ) deallocate(var % sarray1)
-        if ( allocated(var % sarray2) ) deallocate(var % sarray2)
-        if ( allocated(var % sarray3) ) deallocate(var % sarray3)
-        if ( allocated(var % sarray4) ) deallocate(var % sarray4)
-        if ( allocated(var % sarray5) ) deallocate(var % sarray5)
-        if ( allocated(var % sarray6) ) deallocate(var % sarray6)
-!
-        if ( allocated(var % darray1) ) deallocate(var % darray1)
-        if ( allocated(var % darray2) ) deallocate(var % darray2)
-        if ( allocated(var % darray3) ) deallocate(var % darray3)
-        if ( allocated(var % darray4) ) deallocate(var % darray4)
-        if ( allocated(var % darray5) ) deallocate(var % darray5)
-        if ( allocated(var % darray6) ) deallocate(var % darray6)
-!
-    enddo
-!
-    do nb = 1,Agrif_NbVariables(1)
-!
-        var_c => Agrif_Mygrid % tabvars_c(nb)
-!
-        if ( allocated(var_c % carray1) ) deallocate(var_c % carray1)
-        if ( allocated(var_c % carray2) ) deallocate(var_c % carray2)
-!
-    enddo
-
-    do nb = 1,Agrif_NbVariables(3)
-!
-        var_l => Agrif_Mygrid % tabvars_l(nb)
-!
-        if ( allocated(var_l % larray1) ) deallocate(var_l % larray1)
-        if ( allocated(var_l % larray2) ) deallocate(var_l % larray2)
-        if ( allocated(var_l % larray3) ) deallocate(var_l % larray3)
-        if ( allocated(var_l % larray4) ) deallocate(var_l % larray4)
-        if ( allocated(var_l % larray5) ) deallocate(var_l % larray5)
-        if ( allocated(var_l % larray6) ) deallocate(var_l % larray6)
-!
-    enddo
-!
-    do nb = 1,Agrif_NbVariables(4)
-!
-        var_i => Agrif_Mygrid % tabvars_i(nb)
-!
-        if ( allocated(var_i % iarray1) ) deallocate(var_i % iarray1)
-        if ( allocated(var_i % iarray2) ) deallocate(var_i % iarray2)
-        if ( allocated(var_i % iarray3) ) deallocate(var_i % iarray3)
-        if ( allocated(var_i % iarray4) ) deallocate(var_i % iarray4)
-        if ( allocated(var_i % iarray5) ) deallocate(var_i % iarray5)
-        if ( allocated(var_i % iarray6) ) deallocate(var_i % iarray6)
-!
-    enddo
-!
-    if ( allocated(Agrif_Mygrid % tabvars) )   deallocate(Agrif_Mygrid % tabvars)
-    if ( allocated(Agrif_Mygrid % tabvars_c) ) deallocate(Agrif_Mygrid % tabvars_c)
-    if ( allocated(Agrif_Mygrid % tabvars_r) ) deallocate(Agrif_Mygrid % tabvars_r)
-    if ( allocated(Agrif_Mygrid % tabvars_l) ) deallocate(Agrif_Mygrid % tabvars_l)
-    if ( allocated(Agrif_Mygrid % tabvars_i) ) deallocate(Agrif_Mygrid % tabvars_i)
-    deallocate(Agrif_Mygrid)
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Deallocation
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Step_adj
-!
-!> creates the grid hierarchy and manages the backward time integration procedure.
-!> It is called in the main program.
-!> calls subroutines #Agrif_Regrid and #Agrif_Integrate_adj.
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Step_adj ( procname )
-!---------------------------------------------------------------------------------------------------
-    procedure(step_proc)    :: procname     !< Subroutine to call on each grid
-!
-!   Creation and initialization of the grid hierarchy
-!
-!   Set the clustering variables
-    call Agrif_clustering_def()
-!
-    if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 1 ) then
-!
-        if (Agrif_Mygrid % ngridstep == 0) then
-            if (.not.Agrif_regrid_has_been_done ) then
-                call Agrif_Regrid()
-            endif
-            call Agrif_Instance(Agrif_Mygrid)
-        endif
-!
-    else
-!
-        if (mod(Agrif_Mygrid % ngridstep, Agrif_Regridding) == 0) then
-            call Agrif_Regrid()
-            call Agrif_Instance(Agrif_Mygrid)
-        endif
-!
-    endif
-!
-!   Time integration of the grid hierarchy
-!
-    call Agrif_Integrate_adj (Agrif_Mygrid,procname)
-!
-    if ( Agrif_Mygrid % child_list % nitems > 0 ) call Agrif_Instance(Agrif_Mygrid)
-!
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Step_adj
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Integrate_adj
-!
-!> Manages the backward time integration of the grid hierarchy.
-!! Recursive subroutine and call on subroutines Agrif_Init::Agrif_Instance and #Agrif_Step_adj
-!---------------------------------------------------------------------------------------------------
-recursive subroutine Agrif_Integrate_adj ( g, procname )
-!---------------------------------------------------------------------------------------------------
-    type(Agrif_Grid), pointer   :: g        !< Pointer on the current grid
-    procedure(step_proc)        :: procname !< Subroutine to call on each grid
-!
-    type(Agrif_pgrid), pointer :: parcours ! pointer for the recursive procedure
-    integer                    :: nbt      ! Number of time steps of the current grid
-    integer                    :: k
-!
-!   Instanciation of the variables of the current grid
-    if ( g%fixedrank /= 0 ) then
-        call Agrif_Instance(g)
-    endif
-!
-!   Number of time steps on the current grid
-!
-    g%ngridstep = g % ngridstep + 1
-    parcours => g % child_list % first
-!
-!   Recursive procedure for the time integration of the grid hierarchy
-    do while (associated(parcours))
-!
-!   Instanciation of the variables of the current grid
-        call Agrif_Instance(parcours % gr)
-!
-!       Number of time steps
-        nbt = 1
-        do k = 1,Agrif_Probdim
-            nbt = max(nbt, parcours % gr % timeref(k))
-        enddo
-!
-        do k = nbt,1,-1
-            call Agrif_Integrate_adj(parcours % gr, procname)
-        enddo
-!
-        parcours => parcours % next
-!
-    enddo
-!
-    if ( g % child_list % nitems > 0 )  call Agrif_Instance(g)
-!
-!   One step on the current grid
-    call procname ()
-!
-end subroutine Agrif_Integrate_adj
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Step_Child_adj
-!
-!> Apply 'procname' to each grid of the hierarchy from Child to Parent
-!---------------------------------------------------------------------------------------------------
-subroutine Agrif_Step_Child_adj ( procname )
-!---------------------------------------------------------------------------------------------------
-    procedure(step_proc)        :: procname !< Subroutine to call on each grid
-!
-    call Agrif_Integrate_Child_adj(Agrif_Mygrid,procname)
-!
-    if ( Agrif_Mygrid % child_list % nitems > 0 ) call Agrif_Instance(Agrif_Mygrid)
-!
-end subroutine Agrif_Step_Child_adj
-!===================================================================================================
-!
-!===================================================================================================
-!  subroutine Agrif_Integrate_Child_adj
-!
-!> Manages the backward time integration of the grid hierarchy.
-!! Recursive subroutine and call on subroutines Agrif_Init::Agrif_Instance & Agrif_Step_adj.
-!---------------------------------------------------------------------------------------------------
-recursive subroutine Agrif_Integrate_Child_adj ( g, procname )
-!---------------------------------------------------------------------------------------------------
-    type(Agrif_Grid),pointer   :: g          !< Pointer on the current grid
-    procedure(step_proc)       :: procname   !< Subroutine to call on each grid
-!
-    type(Agrif_PGrid),pointer  :: parcours   !< Pointer for the recursive procedure
-!
-    parcours => g % child_list % first
-!
-!   Recursive procedure for the time integration of the grid hierarchy
-    do while (associated(parcours))
-!
-!       Instanciation of the variables of the current grid
-        call Agrif_Instance(parcours % gr)
-        call Agrif_Integrate_Child_adj(parcours % gr, procname)
-!
-       parcours => parcours % next
-!
-    enddo
-    if ( g % child_list % nitems > 0 )  call Agrif_Instance(g)
-!
-!   One step on the current grid
-    call procname()
-!---------------------------------------------------------------------------------------------------
-end subroutine Agrif_Integrate_Child_adj
-!===================================================================================================
-!
-!===================================================================================================
 
 end module Agrif_Util
Index: /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modvariables.F90
===================================================================
--- /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modvariables.F90	(revision 10086)
+++ /vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modvariables.F90	(revision 10087)
@@ -5,4 +5,16 @@
     implicit none
 !
+#if defined AGRIF_MPI
+    interface
+        subroutine Agrif_InvLoc ( indloc, proc_id, dir, indglob )
+            integer, intent(in)     :: indloc   !< local index
+            integer, intent(in)     :: proc_id  !< rank of the proc calling this function
+            integer, intent(in)     :: dir      !< direction of the index
+            integer, intent(out)    :: indglob  !< global index
+        end subroutine Agrif_InvLoc
+    end interface
+    private :: Agrif_InvLoc
+#endif
+
 contains
 !
@@ -14,18 +26,24 @@
 subroutine Agrif_Declare_Variable ( posvar, firstpoint, raf, lb, ub, varid, torestore )
 !---------------------------------------------------------------------------------------------------
-    integer,      dimension(:), intent(in)  :: posvar     !< position of the variable on the cell
-                                                          !! (1 for the border of the edge, 2 for the center)
-    integer,      dimension(:), intent(in)  :: firstpoint !< index of the first point in the real domain
-    character(1), dimension(:), intent(in)  :: raf        !< Array indicating the type of dimension (space or not)
-                                                          !!   for each of them
-    integer,      dimension(:), intent(in)  :: lb         !< Lower bounds of the array
-    integer,      dimension(:), intent(in)  :: ub         !< Upper bounds of the array
-    integer,                    intent(out) :: varid      !< Id number of the newly created variable
-    logical,      optional,     intent(in)  :: torestore  !< Indicates if the array restore is used
-!---------------------------------------------------------------------------------------------------
+    integer, dimension(:),      intent(in)      :: posvar     !< position of the variable on the cell
+                                                              !< (1 for the border of the edge, 2 for the center)
+    integer, dimension(:),      intent(in)      :: firstpoint !< index of the first point in the real domain
+    character(*), dimension(:), intent(in)      :: raf        !< Array indicating the type of dimension (space or not)
+                                                              !<   for each of them
+    integer, dimension(:),      intent(in)      :: lb         !< Lower bounds of the array
+    integer, dimension(:),      intent(in)      :: ub         !< Upper bounds of the array
+    integer,                    intent(out)     :: varid      !< Id number of the newly created variable
+    logical, optional,          intent(in)      :: torestore  !< Indicates if the array restore is used
+!
     type(Agrif_Variables_List), pointer :: new_varlist
     type(Agrif_Variable),       pointer :: var
-    integer                             :: nbdim, i
+    integer                             :: nbdim
     logical                             :: restore
+#if defined AGRIF_MPI
+    include 'mpif.h'
+    integer :: i
+    integer,dimension(6,2) :: iminmaxg, lubglob
+    integer :: code
+#endif
 
     restore = .FALSE.
@@ -43,24 +61,29 @@
     allocate(var % posvar(nbdim))
     allocate(var % interptab(nbdim))
-    allocate(var % coords(nbdim))
 !
-    var % nbdim          = nbdim
-    var % interptab      = raf(1:nbdim)
-    var % posvar         = posvar(1:nbdim)
-    var % point(1:nbdim) = firstpoint(1:nbdim)
+    var % interptab = raf
+    var % nbdim = nbdim
+    var % posvar = posvar
+    var % point(1:nbdim) = firstpoint
     var % restore = restore
-!
+
+    var % lb(1:nbdim) = lb(1:nbdim)
+    var % ub(1:nbdim) = ub(1:nbdim)
+
+#if defined AGRIF_MPI
     do i = 1,nbdim
-        select case( raf(i) )
-            case('x')    ; var % coords(i) = 1
-            case('y')    ; var % coords(i) = 2
-            case('z')    ; var % coords(i) = 3
-            case('N')    ; var % coords(i) = 0
-            case default ; var % coords(i) = 0
-        end select
+        call Agrif_Invloc(lb(i), Agrif_Procrank, i, iminmaxg(i,1))
+        call Agrif_Invloc(ub(i), Agrif_Procrank, i, iminmaxg(i,2))
     enddo
 !
-    var % lb(1:nbdim) = lb(1:nbdim)
-    var % ub(1:nbdim) = ub(1:nbdim)
+    iminmaxg(1:nbdim,2) = - iminmaxg(1:nbdim,2)
+    call MPI_ALLREDUCE(iminmaxg(1:nbdim,:), lubglob(1:nbdim,:), 2*nbdim, MPI_INTEGER,MPI_MIN,Agrif_mpi_comm, code)
+    lubglob(1:nbdim,2)  = - lubglob(1:nbdim,2)
+    var % lbglob(1:nbdim) = lubglob(1:nbdim,1)
+    var % ubglob(1:nbdim) = lubglob(1:nbdim,2)
+#else
+    var % lbglob(1:nbdim) = var % lb(1:nbdim)
+    var % ubglob(1:nbdim) = var % ub(1:nbdim)
+#endif
 
     if ( restore ) then
@@ -121,5 +144,5 @@
     integer :: nb, varidinv
 !
-    if ( .not.associated(grid) ) then
+    if ( .not.associated(grid)) then
         outvar => NULL()
         return
@@ -127,10 +150,11 @@
 !
     parcours => grid % variables
-
+    
     if (.not. associated(parcours)) then   ! can occur on the grand mother grid
            outvar => NULL()                ! during the first call by agrif_mygrid
            return
     endif
-
+                                           
+    
     varidinv = 1 + grid % nbvariables - varid
 
@@ -140,4 +164,5 @@
 
     outvar => parcours % var
+
 !---------------------------------------------------------------------------------------------------
 end function Agrif_Search_variable
