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