Index: vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modbc.F90
===================================================================
--- vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modbc.F90	(revision 10083)
+++ 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
