Index: trunk/AGRIF/AGRIF_FILES/modupdate.F
===================================================================
--- trunk/AGRIF/AGRIF_FILES/modupdate.F	(revision 396)
+++ trunk/AGRIF/AGRIF_FILES/modupdate.F	(revision 662)
@@ -85,5 +85,8 @@
 C      
 C     Values on the current grid used for the update
-      childtemp % var % array1 => tab      
+      childtemp % var % array1 => tab     
+      
+C      childtemp % var % list_update => child%var%list_update
+             
 C
      
@@ -96,4 +99,6 @@
       ENDIF     
 C      
+C      child % var % list_update => childtemp%var%list_update
+      
       deallocate(childtemp % var)
 C
@@ -146,4 +151,6 @@
 C     Values on the current grid used for the update
       childtemp % var % array2 => tab      
+      
+C      childtemp % var % list_update => child%var%list_update      
 C
       IF (present(procname)) THEN
@@ -155,4 +162,6 @@
       ENDIF
 C      
+C      child % var % list_update => childtemp%var%list_update
+      
       deallocate(childtemp % var)
 C
@@ -204,4 +213,6 @@
 C     Values on the current grid used for the update
       childtemp % var % array3 => tab     
+      
+C      childtemp % var % list_update => child%var%list_update      
 C
       IF (present(procname)) THEN
@@ -213,4 +224,6 @@
       ENDIF
 C      
+C      child % var % list_update => childtemp%var%list_update
+      
       DEALLOCATE(childtemp % var)
 C
@@ -262,4 +275,7 @@
 C     Values on the current grid used for the update
       childtemp % var % array4 => tab     
+      
+C      childtemp % var % list_update => child%var%list_update
+            
 C
       IF (present(procname)) THEN
@@ -270,4 +286,6 @@
      &     (TypeUpdate,parent,child,deb,fin)
       ENDIF
+
+C      child % var % list_update => childtemp%var%list_update      
 C
       deallocate(childtemp % var)
@@ -322,4 +340,6 @@
 C     Values on the current grid used for the update
       childtemp % var % array5 => tab      
+      
+C      childtemp % var % list_update => child%var%list_update      
 C
       IF (present(procname)) THEN
@@ -330,4 +350,7 @@
      &     (TypeUpdate,parent,child,deb,fin)
       ENDIF
+      
+C      child % var % list_update => childtemp%var%list_update
+            
 C      
       deallocate(childtemp % var)
@@ -380,7 +403,11 @@
 C     Values on the current grid used for the update
       childtemp % var % array6 => tab      
+C      childtemp % var % list_update => child%var%list_update
 C
       Call Agrif_UpdateVariable
      &     (TypeUpdate,parent,child,deb,fin)
+     
+C      child % var % list_update => childtemp%var%list_update
+           
 C      
       deallocate(childtemp % var)
@@ -658,5 +685,8 @@
 
         IF (posvartab_child(i) == 1) THEN
-          IF (TypeUpdate(i) .NE. Agrif_Update_Copy) THEN
+          IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
+            indtab(i,1,1) = indtab(i,1,1) - (coeffraf - 1)
+            indtab(i,1,2) = indtab(i,1,2) + (coeffraf - 1)        
+          ELSE IF (TypeUpdate(i) .NE. Agrif_Update_Copy) THEN
             indtab(i,1,1) = indtab(i,1,1) - coeffraf / 2
             indtab(i,1,2) = indtab(i,1,2) + coeffraf / 2
@@ -665,4 +695,9 @@
           indtab(i,1,1) = indtab(i,1,1) - coeffraf
           indtab(i,1,2) = indtab(i,1,2) - 1
+          IF ((TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting)
+     &                            .AND.(mod(coeffraf,2) == 1)) THEN
+            indtab(i,1,1) = indtab(i,1,1) - 1
+            indtab(i,1,2) = indtab(i,1,2) + 1
+          ENDIF
         ENDIF
         IF (loctab_child(i) == -3) THEN
@@ -832,5 +867,8 @@
 
         IF (posvartab_child(i) == 1) THEN
-          IF (TypeUpdate(i) .NE. Agrif_Update_Copy) THEN
+          IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
+            indtab(i,:,1) = indtab(i,:,1) - (coeffraf - 1)
+            indtab(i,:,2) = indtab(i,:,2) + (coeffraf - 1)        
+          ELSE IF (TypeUpdate(i) .NE. Agrif_Update_Copy) THEN
             indtab(i,:,1) = indtab(i,:,1) - coeffraf / 2
             indtab(i,:,2) = indtab(i,:,2) + coeffraf / 2
@@ -840,4 +878,10 @@
           indtab(i,1,2) = indtab(i,1,2) - 1
           indtab(i,2,2) = indtab(i,2,2) + coeffraf - 1
+          IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
+            indtab(i,1,1) = indtab(i,1,1) - 1
+            indtab(i,1,2) = indtab(i,1,2) + 1
+            indtab(i,2,1) = indtab(i,2,1) - 1
+            indtab(i,2,2) = indtab(i,2,2) + 1
+          ENDIF          
         ENDIF
       ENDDO
@@ -952,5 +996,5 @@
      &              ds_Child(1:nbdim),ds_Parent(1:nbdim),
      &              posvartab_Child,loctab_Child,
-     &              nbdim,procname)
+     &              nbdim,procname,nb,ndir)
            ELSE
               Call Agrif_UpdatenD              
@@ -985,5 +1029,5 @@
      &                          ds_Child,ds_Parent,
      &                          posvartab_Child,loctab_Child,
-     &                          nbdim,procname)  
+     &                          nbdim,procname,nb,ndir)  
 C
 C     Description:
@@ -1030,8 +1074,11 @@
       External :: procname
       Optional ::  procname
+      Integer :: nb,ndir
+      Optional :: nb,ndir
+      
 C
 C     Local pointers
-      TYPE(AGRIF_PVARIABLE)      :: tempP      ! Temporary parent grid variable
-      TYPE(AGRIF_PVARIABLE)      :: tempC      ! Temporary child grid variable
+      TYPE(AGRIF_PVARIABLE), SAVE      :: tempP      ! Temporary parent grid variable
+      TYPE(AGRIF_PVARIABLE), SAVE      :: tempC      ! Temporary child grid variable
 C
 C     Local scalars
@@ -1047,6 +1094,6 @@
       INTEGER,DIMENSION(nbdim,2,2) :: childarray
       INTEGER,DIMENSION(nbdim,2,2) :: parentarray
-      TYPE(AGRIF_PVARIABLE)      :: tempCextend,tempPextend ! Temporary child
-                                                            !    grid
+      TYPE(AGRIF_PVARIABLE), SAVE      :: tempCextend,tempPextend ! Temporary child
+      INTEGER :: nbin, ndirin
 C
 #ifdef AGRIF_MPI
@@ -1057,6 +1104,8 @@
       INTEGER,DIMENSION(nbdim,4)           :: tab3
       INTEGER,DIMENSION(nbdim,4,0:Agrif_Nbprocs-1) :: tab4
-      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1,4) :: tab4t
-ccccccccccccccc      TYPE(AGRIF_PVARIABLE)                :: childvalues
+      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1,4) :: tab4t, tab5t
+      LOGICAL :: find_list_update
+      LOGICAL, DIMENSION(0:Agrif_Nbprocs-1) :: memberinall, memberinall2
+      LOGICAL, DIMENSION(1) :: memberin1      
 C
 #endif
@@ -1119,7 +1168,16 @@
 #endif
 
-
+       IF (present(procname)) THEN
+       IF (.Not.present(nb)) THEN
+       nbin=0
+       ndirin=0
+       ELSE
+       nbin = nb
+       ndirin = ndir
+       ENDIF
+       ENDIF
+       
       IF (memberin) THEN
-      allocate(tempC%var)
+      IF (.not.associated(tempC%var)) allocate(tempC%var)
 
 C
@@ -1136,10 +1194,10 @@
           CALL procname(tempC%var%array1,
      &                          childarray(1,1,2),childarray(1,2,2),
-     &                                   .TRUE.)
+     &                                   .TRUE.,nbin,ndirin)
         CASE(2)
           CALL procname(tempC%var%array2,
      &                          childarray(1,1,2),childarray(1,2,2),
      &                          childarray(2,1,2),childarray(2,2,2),
-     &                                   .TRUE.)
+     &                                   .TRUE.,nbin,ndirin)
         CASE(3)
           CALL procname(tempC%var%array3,
@@ -1147,5 +1205,5 @@
      &                          childarray(2,1,2),childarray(2,2,2),
      &                          childarray(3,1,2),childarray(3,2,2),
-     &                                   .TRUE.)
+     &                                   .TRUE.,nbin,ndirin)
         CASE(4)
           CALL procname(tempC%var%array4,
@@ -1154,5 +1212,5 @@
      &                          childarray(3,1,2),childarray(3,2,2),
      &                          childarray(4,1,2),childarray(4,2,2),
-     &                                   .TRUE.)
+     &                                   .TRUE.,nbin,ndirin)
         CASE(5)
           CALL procname(tempC%var%array5,
@@ -1162,5 +1220,5 @@
      &                          childarray(4,1,2),childarray(4,2,2),
      &                          childarray(5,1,2),childarray(5,2,2),
-     &                                   .TRUE.)
+     &                                   .TRUE.,nbin,ndirin)
         CASE(6)
           CALL procname(tempC%var%array6,
@@ -1171,5 +1229,5 @@
      &                          childarray(5,1,2),childarray(5,2,2),
      &                          childarray(6,1,2),childarray(6,2,2),
-     &                                   .TRUE.)
+     &                                   .TRUE.,nbin,ndirin)
         END SELECT
       ELSE
@@ -1189,4 +1247,13 @@
 C     tab2 contains the necessary limits of the parent grid for each processor
 
+      IF (Associated(child%var%list_update)) THEN
+      Call Agrif_Find_list_update(child%var%list_update,pttab,petab,
+     &                          pttab_Child,pttab_Parent,nbdim,
+     &       find_list_update,tab4t,tab5t,memberinall,memberinall2)
+      ELSE
+      find_list_update = .FALSE.
+      ENDIF
+      
+      if (.not.find_list_update) then      
       tab3(:,1) = pttruetab(:)
       tab3(:,2) = cetruetab(:)
@@ -1198,5 +1265,5 @@
      &                   MPI_INTEGER,MPI_COMM_WORLD,code)
 
-      Allocate(tempCextend%var)
+      IF (.not.associated(tempCextend%var)) Allocate(tempCextend%var)
       DO k=0,Agrif_Nbprocs-1
        do j=1,4
@@ -1206,7 +1273,15 @@
        enddo
       enddo
+      
+      memberin1(1) = memberin
+      CALL MPI_ALLGATHER(memberin1,1,MPI_LOGICAL,memberinall,
+     &                  1,MPI_LOGICAL,MPI_COMM_WORLD,code)
+           
+      endif
+      
       Call Get_External_Data(tempC,tempCextend,tab4t(:,:,1),
      &            tab4t(:,:,2),
-     &            tab4t(:,:,3),tab4t(:,:,4),nbdim,memberin,memberin)
+     &            tab4t(:,:,3),tab4t(:,:,4),nbdim,memberin,memberin,
+     &            memberinall)
 
 #else
@@ -1221,5 +1296,5 @@
       IF (memberin) THEN
 
-      allocate(tempP%var)
+      IF (.not.associated(tempP%var)) allocate(tempP%var)
       Call Agrif_nbdim_allocation(tempP%var,
      &                 indmin,indmax,nbdim)
@@ -1276,5 +1351,5 @@
 
       Call Agrif_nbdim_deallocation(tempCextend%var,nbdim)
-      Deallocate(tempCextend%var)
+C      Deallocate(tempCextend%var)
 
       ENDIF
@@ -1301,4 +1376,5 @@
       Call Agrif_ParentGrid_to_ChildGrid()
 
+      if (.not.find_list_update) then
       tab3(:,1) = indmin(:)
       tab3(:,2) = indmax(:)
@@ -1309,15 +1385,27 @@
      &                   MPI_INTEGER,MPI_COMM_WORLD,code)
 
-      Allocate(tempPextend%var)
+      IF (.not.associated(tempPextend%var)) Allocate(tempPextend%var)
       DO k=0,Agrif_Nbprocs-1
        do j=1,4
          do i=1,nbdim
-         tab4t(i,k,j) = tab4(i,j,k)
+         tab5t(i,k,j) = tab4(i,j,k)
          enddo
        enddo
       enddo
-      Call Get_External_Data(tempP,tempPextend,tab4t(:,:,1),
-     &            tab4t(:,:,2),
-     &            tab4t(:,:,3),tab4t(:,:,4),nbdim,memberin,member)
+ 
+      memberin1(1) = member
+      CALL MPI_ALLGATHER(memberin1,1,MPI_LOGICAL,memberinall2,
+     &                  1,MPI_LOGICAL,MPI_COMM_WORLD,code)
+     
+      Call Agrif_Addto_list_update(child%var%list_update,pttab,petab,
+     &                          pttab_Child,pttab_Parent,nbdim
+     &   ,tab4t,tab5t,memberinall,memberinall2) 
+          
+      endif
+      
+      Call Get_External_Data(tempP,tempPextend,tab5t(:,:,1),
+     &            tab5t(:,:,2),
+     &            tab5t(:,:,3),tab5t(:,:,4),nbdim,memberin,member,
+     &            memberinall2)
 
 #else
@@ -1407,5 +1495,5 @@
      &                      parentarray(1,1,1):parentarray(1,2,1)),
      &                      parentarray(1,1,2),parentarray(1,2,2),
-     &                                   .FALSE.
+     &                                   .FALSE.,nbin,ndirin
      &                      )
             CASE(2)
@@ -1416,5 +1504,5 @@
      &                      parentarray(1,1,2),parentarray(1,2,2),
      &                      parentarray(2,1,2),parentarray(2,2,2),
-     &                                   .FALSE.
+     &                                   .FALSE.,nbin,ndirin
      &                      )
             CASE(3)
@@ -1427,5 +1515,5 @@
      &                      parentarray(2,1,2),parentarray(2,2,2),
      &                      parentarray(3,1,2),parentarray(3,2,2),
-     &                                   .FALSE.
+     &                                   .FALSE.,nbin,ndirin
      &                      )
             CASE(4)
@@ -1440,5 +1528,5 @@
      &                      parentarray(3,1,2),parentarray(3,2,2),
      &                      parentarray(4,1,2),parentarray(4,2,2),
-     &                                   .FALSE.
+     &                                   .FALSE.,nbin,ndirin
      &                      )
             CASE(5)
@@ -1455,5 +1543,5 @@
      &                      parentarray(4,1,2),parentarray(4,2,2),
      &                      parentarray(5,1,2),parentarray(5,2,2),
-     &                                   .FALSE.
+     &                                   .FALSE.,nbin,ndirin
      &                      )
             CASE(6)
@@ -1472,5 +1560,5 @@
      &                      parentarray(5,1,2),parentarray(5,2,2),
      &                      parentarray(6,1,2),parentarray(6,2,2),
-     &                                   .FALSE.
+     &                                   .FALSE.,nbin,ndirin
      &                      )
             END SELECT
@@ -1545,11 +1633,11 @@
       Call Agrif_nbdim_deallocation(tempP%var,nbdim)
       Call Agrif_nbdim_deallocation(tempC%var,nbdim)
-      Deallocate(tempC % var)
+!      Deallocate(tempC % var)
 #endif
-      Deallocate(tempP % var)
+!      Deallocate(tempP % var)
       ENDIF
 #ifdef AGRIF_MPI
-      Deallocate(tempPextend%var)
-      IF (.Not.memberin) Deallocate(tempCextend%var)
+!      Deallocate(tempPextend%var)
+!      IF (.Not.memberin) Deallocate(tempCextend%var)
 #endif
 
@@ -1628,9 +1716,14 @@
         IF (loctab_Child(i) .NE. -3) THEN
         IF (posvartab_child(i) == 1) THEN
-          IF (TypeUpdate(i) .NE. Agrif_Update_Copy) THEN
-        positionmin = positionmin - ds_Parent(i)/2.
+          IF (TypeUpdate(i) .EQ. Agrif_Update_Average) THEN
+          positionmin = positionmin - ds_Parent(i)/2.
+          ELSE IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
+          positionmin = positionmin - (ds_Parent(i)-ds_Child(i))
           ENDIF
         ELSE
         positionmin = positionmin - ds_Parent(i)/2.
+        IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
+          positionmin = positionmin - ds_Child(i)
+        ENDIF
         ENDIF
         ENDIF
@@ -1647,9 +1740,14 @@
         IF (loctab_Child(i) .NE. -3) THEN
         IF (posvartab_child(i) == 1) THEN
-          IF (TypeUpdate(i) .NE. Agrif_Update_Copy) THEN
+          IF (TypeUpdate(i) .EQ. Agrif_Update_Average) THEN
         positionmax = positionmax  + ds_Parent(i)/2.
+          ELSE IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
+          positionmax = positionmax  + (ds_Parent(i)-ds_Child(i))
           ENDIF
         ELSE
         positionmax = positionmax  + ds_Parent(i)/2.
+        IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
+          positionmax = positionmax + ds_Child(i)
+        ENDIF        
         ENDIF
         ENDIF
@@ -1684,46 +1782,5 @@
 C
 C
-C     **************************************************************************
-CCC   Subroutine Agrif_Update_1D_Recursive
-C     **************************************************************************
-C
-      Subroutine Agrif_Update_1D_recursive(TypeUpdate,tempP,tempC,
-     &                                     indmin,indmax,
-     &                                     pttab_child,petab_child,
-     &                                     s_child,s_parent,
-     &                                     ds_child,ds_parent,nbdim)
-C
-CCC   Description:
-CCC   Subroutine to update a 1D grid variable on the parent grid.
-C
-CC    Method:
-C
-C     Declarations:
-C
-      
-C
-C     Arguments
-      INTEGER                   :: nbdim
-      INTEGER, DIMENSION(nbdim) :: TypeUpdate            ! TYPE of update (copy or average)
-      INTEGER, DIMENSION(nbdim) :: indmin,indmax
-      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
-      REAL, DIMENSION(nbdim)    :: s_child,s_parent
-      REAL, DIMENSION(nbdim)    :: ds_child,ds_parent
-      REAL, DIMENSION(indmin(nbdim):indmax(nbdim))           :: tempP
-      REAL, DIMENSION(pttab_child(nbdim):petab_child(nbdim)) :: tempC
-C
-C
-      Call Agrif_UpdateBase(TypeUpdate(1),
-     &                  tempP(indmin(nbdim):indmax(nbdim)),
-     &                  tempC(pttab_child(nbdim):petab_child(nbdim)),
-     &                  indmin(nbdim),indmax(nbdim),           
-     &                  pttab_child(nbdim),petab_child(nbdim),
-     &                  s_parent(nbdim),s_child(nbdim),
-     &                  ds_parent(nbdim),ds_child(nbdim))
-C
-      Return
-C
-C
-      End Subroutine Agrif_Update_1D_recursive
+
 C
 C
@@ -1734,5 +1791,5 @@
 C
       Subroutine Agrif_Update_2D_recursive(TypeUpdate,tempP,tempC,
-     &                                     indmin,indmax,   
+     &                                     indmin,indmax,
      &                                     pttab_child,petab_child,
      &                                     s_child,s_parent,
@@ -1757,20 +1814,20 @@
       REAL, DIMENSION(indmin(1):indmax(1),
      &                indmin(2):indmax(2))           :: tempP
-      REAL, DIMENSION(pttab_child(1):petab_child(1),
-     &                pttab_child(2):petab_child(2)) :: tempC
+C      REAL, DIMENSION(pttab_child(1):petab_child(1),
+C     &                pttab_child(2):petab_child(2)) :: tempC
+     
+      REAL, DIMENSION(:,:) :: tempC     
 C
 C     Local variables      
-      REAL, DIMENSION(:,:), Allocatable :: tabtemp
+      REAL, DIMENSION(indmin(1):indmax(1),
+     &                 pttab_child(2):petab_child(2)) :: tabtemp
       INTEGER :: i,j
-C
-C
-      Allocate(tabtemp(indmin(1):indmax(1),
-     &                 pttab_child(2):petab_child(2)))
+      INTEGER :: coeffraf,locind_child_left
 C
       do j = pttab_child(nbdim),petab_child(nbdim)
 C
-        Call Agrif_Update_1D_recursive(TypeUpdate,    
-     &         tabtemp(indmin(nbdim-1):indmax(nbdim-1),j),
-     &         tempC(pttab_child(nbdim-1):petab_child(nbdim-1),j),
+        Call Agrif_Update_1D_recursive(TypeUpdate(1:nbdim-1),    
+     &         tabtemp(:,j),
+     &         tempC(:,j-pttab_child(nbdim)+1),
      &         indmin(1:nbdim-1),indmax(1:nbdim-1),
      &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
@@ -1779,18 +1836,20 @@
 C
       enddo
+      
+      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
+     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
 C
       do i = indmin(1),indmax(1)
 C
         Call Agrif_UpdateBase(TypeUpdate(2),
-     &           tempP(i,indmin(nbdim):indmax(nbdim)),
-     &          tabtemp(i,pttab_child(nbdim):petab_child(nbdim)),
+     &           tempP(i,:),
+     &          tabtemp(i,:),
      &           indmin(nbdim),indmax(nbdim),
      &           pttab_child(nbdim),petab_child(nbdim),
      &           s_parent(nbdim),s_child(nbdim),
-     &           ds_parent(nbdim),ds_child(nbdim))
+     &           ds_parent(nbdim),ds_child(nbdim),
+     &                  coeffraf,locind_child_left)
 C        
       enddo
-C
-      Deallocate(tabtemp)
 C
       Return
@@ -1835,19 +1894,17 @@
 C
 C     Local variables      
-      REAL, DIMENSION(:,:,:), Allocatable :: tabtemp
+      REAL, DIMENSION(indmin(1):indmax(1),
+     &                 indmin(2):indmax(2), 
+     &                 pttab_child(3):petab_child(3)) :: tabtemp
       INTEGER :: i,j,k
-C
-C
-      Allocate(tabtemp(indmin(1):indmax(1),
-     &                 indmin(2):indmax(2), 
-     &                 pttab_child(3):petab_child(3)))
+      INTEGER :: coeffraf,locind_child_left
+      INTEGER :: kdeb
+C
 C
       do k = pttab_child(nbdim),petab_child(nbdim)
 C
-        Call Agrif_Update_2D_recursive(TypeUpdate,    
-     &         tabtemp(indmin(nbdim-2):indmax(nbdim-2),
-     &                 indmin(nbdim-1):indmax(nbdim-1),k),
-     &         tempC(pttab_child(nbdim-2):petab_child(nbdim-2),
-     &               pttab_child(nbdim-1):petab_child(nbdim-1),k),
+        Call Agrif_Update_2D_recursive(TypeUpdate(1:nbdim-1),    
+     &         tabtemp(:,:,k),
+     &         tempC(:,:,k),
      &         indmin(1:nbdim-1),indmax(1:nbdim-1),
      &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
@@ -1857,22 +1914,38 @@
       enddo
 C
-C
+      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
+     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
+      
+      IF (coeffraf == 1) THEN
+      
+      kdeb = pttab_child(3)+locind_child_left-2
+      do k=indmin(3),indmax(3)
+      kdeb = kdeb + 1
       do j = indmin(2),indmax(2)
-C
         do i = indmin(1),indmax(1)
+        tempP(i,j,k) = tabtemp(i,j,kdeb)
+      enddo
+      enddo
+      enddo
+              
+      ELSE
+C
+      do j = indmin(2),indmax(2)
+C
+        do i = indmin(1),indmax(1)
 C
           Call Agrif_UpdateBase(TypeUpdate(3),
-     &           tempP(i,j,indmin(nbdim):indmax(nbdim)),
-     &          tabtemp(i,j,pttab_child(nbdim):petab_child(nbdim)),
+     &           tempP(i,j,:),
+     &          tabtemp(i,j,:),
      &           indmin(nbdim),indmax(nbdim),
      &           pttab_child(nbdim),petab_child(nbdim),
      &           s_parent(nbdim),s_child(nbdim),
-     &           ds_parent(nbdim),ds_child(nbdim))
+     &           ds_parent(nbdim),ds_child(nbdim),
+     &                  coeffraf,locind_child_left)
 C
         enddo 
 C        
       enddo
-C
-      Deallocate(tabtemp)
+      ENDIF
 C
       Return
@@ -1921,4 +1994,5 @@
       REAL, DIMENSION(:,:,:,:), Allocatable :: tabtemp
       INTEGER :: i,j,k,l
+      INTEGER :: coeffraf,locind_child_left
 C
 C
@@ -1930,5 +2004,5 @@
       do l = pttab_child(nbdim),petab_child(nbdim)
 C
-        Call Agrif_Update_3D_recursive(TypeUpdate,    
+        Call Agrif_Update_3D_recursive(TypeUpdate(1:nbdim-1),    
      &         tabtemp(indmin(nbdim-3):indmax(nbdim-3),
      &                 indmin(nbdim-2):indmax(nbdim-2),
@@ -1943,4 +2017,7 @@
 C
       enddo
+      
+      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
+     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
 C
       do k = indmin(3),indmax(3)
@@ -1956,5 +2033,6 @@
      &           pttab_child(nbdim),petab_child(nbdim),
      &           s_parent(nbdim),s_child(nbdim),
-     &           ds_parent(nbdim),ds_child(nbdim))
+     &           ds_parent(nbdim),ds_child(nbdim),
+     &                  coeffraf,locind_child_left)
 C
           enddo 
@@ -2013,4 +2091,5 @@
       REAL, DIMENSION(:,:,:,:,:), Allocatable :: tabtemp
       INTEGER :: i,j,k,l,m
+      INTEGER :: coeffraf,locind_child_left
 C
 C
@@ -2023,5 +2102,5 @@
       do m = pttab_child(nbdim),petab_child(nbdim)
 C
-        Call Agrif_Update_4D_recursive(TypeUpdate,    
+        Call Agrif_Update_4D_recursive(TypeUpdate(1:nbdim-1),    
      &         tabtemp(indmin(nbdim-4):indmax(nbdim-4),
      &                 indmin(nbdim-3):indmax(nbdim-3),
@@ -2038,4 +2117,7 @@
 C
       enddo
+      
+      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
+     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
 C
       do l = indmin(4),indmax(4)
@@ -2054,5 +2136,6 @@
      &           pttab_child(nbdim),petab_child(nbdim),
      &           s_parent(nbdim),s_child(nbdim),
-     &           ds_parent(nbdim),ds_child(nbdim))
+     &           ds_parent(nbdim),ds_child(nbdim),
+     &                  coeffraf,locind_child_left)
 C
             enddo
@@ -2116,4 +2199,5 @@
       REAL, DIMENSION(:,:,:,:,:,:), Allocatable :: tabtemp
       INTEGER :: i,j,k,l,m,n
+      INTEGER :: coeffraf,locind_child_left
 C
 C
@@ -2127,5 +2211,5 @@
       do n = pttab_child(nbdim),petab_child(nbdim)
 C
-        Call Agrif_Update_5D_recursive(TypeUpdate,    
+        Call Agrif_Update_5D_recursive(TypeUpdate(1:nbdim-1),    
      &         tabtemp(indmin(nbdim-5):indmax(nbdim-5),
      &                 indmin(nbdim-4):indmax(nbdim-4),
@@ -2144,4 +2228,7 @@
 C
       enddo
+      
+      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
+     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
 C
       do m = indmin(5),indmax(5)
@@ -2161,5 +2248,6 @@
      &           pttab_child(nbdim),petab_child(nbdim),
      &           s_parent(nbdim),s_child(nbdim),
-     &           ds_parent(nbdim),ds_child(nbdim))
+     &           ds_parent(nbdim),ds_child(nbdim),
+     &                  coeffraf,locind_child_left)
 C
             enddo
@@ -2188,5 +2276,6 @@
      &                            parenttab,childtab,
      &                            indmin,indmax,pttab_child,petab_child,
-     &                            s_parent,s_child,ds_parent,ds_child)
+     &                            s_parent,s_child,ds_parent,ds_child,
+     &                            coeffraf,locind_child_left)
 C
 CCC   Description:
@@ -2206,10 +2295,11 @@
       REAL,DIMENSION(pttab_child:petab_child) :: childtab      
       REAL    :: s_parent,s_child
-      REAL    :: ds_parent,ds_child       
+      REAL    :: ds_parent,ds_child      
+      INTEGER :: coeffraf,locind_child_left
 C
 C
       if (TypeUpdate == AGRIF_Update_copy) then
 C             
-          Call copy1D
+          Call agrif_copy1D
      &       (parenttab,childtab,
      &          indmax-indmin+1,petab_child-pttab_child+1,
@@ -2228,5 +2318,6 @@
      &       (parenttab,childtab,
      &          indmax-indmin+1,petab_child-pttab_child+1,
-     &          s_parent,s_child,ds_parent,ds_child)
+     &          s_parent,s_child,ds_parent,ds_child,
+     &          coeffraf,locind_child_left)
 C
       endif 
@@ -2238,7 +2329,144 @@
 C
 C
+
+      Subroutine Agrif_Compute_nbdim_update(s_parent,s_child,
+     &  ds_parent,ds_child,coeffraf,locind_child_left)
+      real :: s_parent,s_child,ds_parent,ds_child
+      integer :: coeffraf,locind_child_left
+     
+      coeffraf = nint(ds_parent/ds_child)
+      locind_child_left = 1 + agrif_int((s_parent-s_child)/ds_child)
+      
+      End Subroutine Agrif_Compute_nbdim_update
+ 
+#if defined AGRIF_MPI      
+      Subroutine Agrif_Find_list_update(list_update,pttab,petab,
+     &                          pttab_Child,pttab_Parent,nbdim,
+     &     find_list_update,tab4t,tab5t,memberinall,memberinall2)     
+      TYPE(Agrif_List_Interp_Loc), Pointer :: list_update
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(nbdim)   :: pttab,petab,pttab_Child,pttab_Parent
+      LOGICAL :: find_list_update
+      Type(Agrif_List_Interp_loc), Pointer :: parcours
+      INTEGER :: i
+C
+      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1,4) :: tab4t, tab5t
+      LOGICAL, DIMENSION(0:Agrif_Nbprocs-1) :: memberinall,memberinall2
+                    
+      find_list_update = .FALSE.
+      
+      parcours => list_update
+      
+      Find_loop :   Do While (associated(parcours))
+        Do i=1,nbdim
+          IF ((pttab(i) /= parcours%interp_loc%pttab(i)).OR.
+     &        (petab(i) /= parcours%interp_loc%petab(i)).OR.
+     &        (pttab_child(i) /= parcours%interp_loc%pttab_child(i)).OR.
+     &        (pttab_parent(i) /= parcours%interp_loc%pttab_parent(i)))
+     &               THEN
+            parcours=>parcours%suiv
+            Cycle Find_loop
+          ENDIF
+        EndDo
+        
+        tab4t = parcours%interp_loc%tab4t(1:nbdim,0:Agrif_Nbprocs-1,1:4)
+        memberinall = parcours%interp_loc%memberinall(0:Agrif_Nbprocs-1)
+        
+        tab5t = parcours%interp_loc%tab5t(1:nbdim,0:Agrif_Nbprocs-1,1:4)
+        memberinall2 = 
+     &       parcours%interp_loc%memberinall2(0:Agrif_Nbprocs-1)
+        
+        find_list_update = .TRUE.   
+        Exit Find_loop
+      End Do Find_loop  
+                              
+      End Subroutine Agrif_Find_list_update  
+      
+      Subroutine Agrif_AddTo_list_update(list_update,pttab,petab,
+     &                          pttab_Child,pttab_Parent,nbdim
+     &      ,tab4t,tab5t,memberinall,memberinall2)
+          
+      TYPE(Agrif_List_Interp_Loc), Pointer :: list_update
+      INTEGER :: nbdim
+      INTEGER,DIMENSION(nbdim)   :: pttab,petab,pttab_Child,pttab_Parent
+      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1,4) :: tab4t, tab5t
+      LOGICAL,DIMENSION(0:Agrif_Nbprocs-1) :: memberinall, memberinall2
+
+      Type(Agrif_List_Interp_loc), Pointer :: parcours
+            
+       Allocate(parcours)
+      Allocate(parcours%interp_loc)
+      
+      parcours%interp_loc%pttab(1:nbdim) = pttab(1:nbdim)
+      parcours%interp_loc%petab(1:nbdim) = petab(1:nbdim)
+      parcours%interp_loc%pttab_child(1:nbdim) = pttab_child(1:nbdim)
+      parcours%interp_loc%pttab_parent(1:nbdim) = pttab_parent(1:nbdim)
+      Allocate(parcours%interp_loc%tab4t(nbdim,0:Agrif_Nbprocs-1,4))
+      Allocate(parcours%interp_loc%memberinall(0:Agrif_Nbprocs-1))
+      
+      Allocate(parcours%interp_loc%tab5t(nbdim,0:Agrif_Nbprocs-1,4))
+      Allocate(parcours%interp_loc%memberinall2(0:Agrif_Nbprocs-1))
+            
+      parcours%interp_loc%tab4t=tab4t   
+      parcours%interp_loc%memberinall=memberinall
+ 
+      parcours%interp_loc%tab5t=tab5t   
+      parcours%interp_loc%memberinall2=memberinall2
+            
+      parcours%suiv => list_update
+      
+      list_update => parcours
+      
+      End Subroutine Agrif_Addto_list_update
+#endif
+           
       End Module Agrif_Update
 
-
-
-      
+C     **************************************************************************
+CCC   Subroutine Agrif_Update_1D_Recursive
+C     **************************************************************************
+C
+      Subroutine Agrif_Update_1D_recursive(TypeUpdate,tempP,tempC,
+     &                                     indmin,indmax,
+     &                                     pttab_child,petab_child,
+     &                                     s_child,s_parent,
+     &                                     ds_child,ds_parent,nbdim)
+C
+CCC   Description:
+CCC   Subroutine to update a 1D grid variable on the parent grid.
+C
+CC    Method:
+C
+C     Declarations:
+C
+      
+C
+C     Arguments
+      USE Agrif_Update
+      INTEGER                   :: nbdim
+      INTEGER, DIMENSION(nbdim) :: TypeUpdate            ! TYPE of update (copy or average)
+      INTEGER, DIMENSION(nbdim) :: indmin,indmax
+      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
+      REAL, DIMENSION(nbdim)    :: s_child,s_parent
+      REAL, DIMENSION(nbdim)    :: ds_child,ds_parent
+      REAL, DIMENSION(indmin(nbdim):indmax(nbdim))           :: tempP
+      REAL, DIMENSION(pttab_child(nbdim):petab_child(nbdim)) :: tempC
+      INTEGER :: coeffraf,locind_child_left
+C
+C
+      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
+     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
+      
+      Call Agrif_UpdateBase(TypeUpdate(1),
+     &                  tempP(indmin(nbdim):indmax(nbdim)),
+     &                  tempC(pttab_child(nbdim):petab_child(nbdim)),
+     &                  indmin(nbdim),indmax(nbdim),           
+     &                  pttab_child(nbdim),petab_child(nbdim),
+     &                  s_parent(nbdim),s_child(nbdim),
+     &                  ds_parent(nbdim),ds_child(nbdim),
+     &                  coeffraf,locind_child_left)
+C
+      Return
+C
+C
+      End Subroutine Agrif_Update_1D_recursive      
