Index: vendors/AGRIF/current/AGRIF_FILES/modbcfunction.F
===================================================================
--- vendors/AGRIF/current/AGRIF_FILES/modbcfunction.F	(revision 1901)
+++ vendors/AGRIF/current/AGRIF_FILES/modbcfunction.F	(revision 2671)
@@ -1,4 +1,4 @@
 !
-! $Id: modbcfunction.F 1200 2008-09-24 13:05:20Z rblod $
+! $Id: modbcfunction.F 779 2007-12-22 17:04:17Z rblod $
 !
 C     AGRIF (Adaptive Grid Refinement In Fortran)
@@ -35,4 +35,5 @@
       Use Agrif_Update
       Use Agrif_fluxmod
+      Use Agrif_Save
 C             
       IMPLICIT NONE
@@ -65,5 +66,6 @@
      &                     Agrif_Init_variable1d,
      &                     Agrif_Init_variable2d,
-     &                     Agrif_Init_variable3d
+     &                     Agrif_Init_variable3d,
+     &                     Agrif_Init_variable4d
       end interface       
 C
@@ -75,5 +77,12 @@
      &                     Agrif_update_var4d,
      &                     Agrif_update_var5d
-      end interface       
+      end interface      
+      
+      interface Agrif_Save_Forrestore
+         module procedure Agrif_Save_Forrestore0d,    
+     &                    Agrif_Save_Forrestore2d,    
+     &                    Agrif_Save_Forrestore3d,    
+     &                    Agrif_Save_Forrestore4d
+      end interface
 C
       Contains 
@@ -255,5 +264,5 @@
       LOGICAL, OPTIONAL :: Interpolationshouldbemade
 C
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
       TYPE(Agrif_PVariable),Pointer ::tabvars
       
@@ -265,8 +274,15 @@
 C     
 
-      if (tabvarsindic <=0) then
-      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-tabvarsindic)
-      else
-      tabvars=>Agrif_Curgrid % tabvars(tabvarsindic)
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
       endif  
       
@@ -307,24 +323,44 @@
       INTEGER, OPTIONAL      :: interp,interp1,interp2,interp3
 C
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
+      TYPE(Agrif_PVariable),Pointer ::tabvars
+      
+    
+C
 C
 C     Begin 
 C
-      Agrif_Mygrid % tabvars(tabvarsindic)% var % Typeinterp = 
+C     
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      else
+      tabvars=>Agrif_Mygrid % tabvars(indic)
+      endif      
+C
+C     Begin 
+C
+      tabvars % var % Typeinterp = 
      &    Agrif_Constant
       IF (present(interp)) THEN
-      Agrif_Mygrid % tabvars(tabvarsindic)% var % Typeinterp = 
+      tabvars % var % Typeinterp = 
      &           interp
       ENDIF
       IF (present(interp1)) THEN
-      Agrif_Mygrid % tabvars(tabvarsindic)% var % Typeinterp(1) = 
+      tabvars % var % Typeinterp(1) = 
      &           interp1
       ENDIF
       IF (present(interp2)) THEN
-      Agrif_Mygrid % tabvars(tabvarsindic)% var % Typeinterp(2) = 
+      tabvars % var % Typeinterp(2) = 
      &           interp2
       ENDIF
       IF (present(interp3)) THEN
-      Agrif_Mygrid % tabvars(tabvarsindic)% var % Typeinterp(3) = 
+      tabvars % var % Typeinterp(3) = 
      &           interp3
       ENDIF
@@ -353,5 +389,5 @@
       INTEGER, OPTIONAL      :: interp11,interp12,interp21,interp22
 C
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
       TYPE(Agrif_PVariable),Pointer ::tabvars
       
@@ -363,8 +399,15 @@
 C     
 
-      if (tabvarsindic <=0) then
-      tabvars => Agrif_Search_Variable(Agrif_Mygrid,-tabvarsindic)
-      else
-      tabvars=>Agrif_Mygrid % tabvars(tabvarsindic)
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      else
+      tabvars=>Agrif_Mygrid % tabvars(indic)
       endif 
 C
@@ -460,34 +503,50 @@
      &       update2, update3,update4,update5
 C
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic,indic ! indice of the variable in tabvars
+      TYPE(Agrif_PVariable),Pointer :: roottabvars      
 C
 C
 C     Begin 
-C
-      Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate = 
+
+      indic = tabvarsindic
+
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
+      if (indic <=0) then
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)      
+      else
+      roottabvars => Agrif_Mygrid % tabvars(indic)
+      endif
+      
+C
+      roottabvars% var % typeupdate = 
      &                   Agrif_Update_Copy
       
       IF (present(update)) THEN
-        Agrif_Mygrid % tabvars(tabvarsindic)% var % typeupdate = 
+        roottabvars% var % typeupdate = 
      &           update
       ENDIF
       IF (present(update1)) THEN
-        Agrif_Mygrid % tabvars(tabvarsindic)% var % typeupdate(1) = 
+        roottabvars% var % typeupdate(1) = 
      &           update1
       ENDIF  
       IF (present(update2)) THEN
-        Agrif_Mygrid % tabvars(tabvarsindic)% var % typeupdate(2) = 
+        roottabvars% var % typeupdate(2) = 
      &           update2
       ENDIF  
       IF (present(update3)) THEN
-        Agrif_Mygrid % tabvars(tabvarsindic)% var % typeupdate(3) = 
+        roottabvars% var % typeupdate(3) = 
      &           update3
       ENDIF 
       IF (present(update4)) THEN
-        Agrif_Mygrid % tabvars(tabvarsindic)% var % typeupdate(4) = 
+        roottabvars% var % typeupdate(4) = 
      &           update4
       ENDIF       
       IF (present(update5)) THEN
-        Agrif_Mygrid % tabvars(tabvarsindic)% var % typeupdate(5) = 
+        roottabvars% var % typeupdate(5) = 
      &           update5
       ENDIF                  
@@ -513,10 +572,16 @@
 C     Arguments      
 C
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic,indic ! indice of the variable in tabvars
 C
 C     Begin 
 C
-C
-      Agrif_Mygrid%tabvars(tabvarsindic)%var % restaure = .TRUE.
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif  
+C
+      Agrif_Mygrid%tabvars(indic)%var % restaure = .TRUE.
 C
       End Subroutine Agrif_Set_restore
@@ -530,5 +595,5 @@
 
       INTEGER :: tabvarsindic0 ! indice of the variable in tabvars
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic,indic ! indice of the variable in tabvars
       External :: procname
       Optional ::  procname
@@ -536,10 +601,17 @@
       if (Agrif_Root()) Return
 C      
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
       if (present(procname)) then
-      CALL Agrif_Interp_variable(tabvarsindic0,tabvarsindic,procname)
-      CALL Agrif_Bc_variable(tabvarsindic0,tabvarsindic,1.,procname)
-      else
-      CALL Agrif_Interp_variable(tabvarsindic0,tabvarsindic)
-      CALL Agrif_Bc_variable(tabvarsindic0,tabvarsindic,1.)
+      CALL Agrif_Interp_variable(tabvarsindic0,indic,procname)
+      CALL Agrif_Bc_variable(tabvarsindic0,indic,1.,procname)
+      else
+      CALL Agrif_Interp_variable(tabvarsindic0,indic)
+      CALL Agrif_Bc_variable(tabvarsindic0,indic,1.)
       endif
 
@@ -553,5 +625,5 @@
 
       REAL, DIMENSION(:) :: q
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
       External :: procname
       Optional ::  procname
@@ -559,11 +631,18 @@
 C
       if (Agrif_Root()) Return
+C      
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif      
 C
       if (present(procname)) then
-      CALL Agrif_Interp_variable(q,tabvarsindic,procname)
-      CALL Agrif_Bc_variable(q,tabvarsindic,1.,procname)
-      else
-      CALL Agrif_Interp_variable(q,tabvarsindic)
-      CALL Agrif_Bc_variable(q,tabvarsindic,1.)
+      CALL Agrif_Interp_variable(q,indic,procname)
+      CALL Agrif_Bc_variable(q,indic,1.,procname)
+      else
+      CALL Agrif_Interp_variable(q,indic)
+      CALL Agrif_Bc_variable(q,indic,1.)
       endif
 
@@ -579,14 +658,22 @@
       External :: procname
       Optional ::  procname
+      integer :: indic
 
 C
       if (Agrif_Root()) Return
 C
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
       if (present(procname)) then
-      CALL Agrif_Interp_variable(q,tabvarsindic,procname)
-      CALL Agrif_Bc_variable(q,tabvarsindic,1.,procname)
-      else
-      CALL Agrif_Interp_variable(q,tabvarsindic)
-      CALL Agrif_Bc_variable(q,tabvarsindic,1.)
+      CALL Agrif_Interp_variable(q,indic,procname)
+      CALL Agrif_Bc_variable(q,indic,1.,procname)
+      else
+      CALL Agrif_Interp_variable(q,indic)
+      CALL Agrif_Bc_variable(q,indic,1.)
       endif
 
@@ -601,16 +688,23 @@
 
       REAL,  DIMENSION(:,:,:) :: q
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic,indic ! indice of the variable in tabvars
       External :: procname
       Optional ::  procname
 C
       if (Agrif_Root()) Return
+C      
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif      
 C
       if (present(procname)) then
-      CALL Agrif_Interp_variable(q,tabvarsindic,procname)
-      CALL Agrif_Bc_variable(q,tabvarsindic,1.,procname)
-      else
-      CALL Agrif_Interp_variable(q,tabvarsindic)
-      CALL Agrif_Bc_variable(q,tabvarsindic,1.)
+      CALL Agrif_Interp_variable(q,indic,procname)
+      CALL Agrif_Bc_variable(q,indic,1.,procname)
+      else
+      CALL Agrif_Interp_variable(q,indic)
+      CALL Agrif_Bc_variable(q,indic,1.)
       endif
 
@@ -625,16 +719,23 @@
 
       REAL,  DIMENSION(:,:,:,:) :: q
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
       External :: procname
       Optional ::  procname
 C
       if (Agrif_Root()) Return
+C      
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif       
 C
       if (present(procname)) then
-      CALL Agrif_Interp_variable(q,tabvarsindic,procname)
-      CALL Agrif_Bc_variable(q,tabvarsindic,1.,procname)
-      else
-      CALL Agrif_Interp_variable(q,tabvarsindic)
-      CALL Agrif_Bc_variable(q,tabvarsindic,1.)
+      CALL Agrif_Interp_variable(q,indic,procname)
+      CALL Agrif_Bc_variable(q,indic,1.,procname)
+      else
+      CALL Agrif_Interp_variable(q,indic)
+      CALL Agrif_Bc_variable(q,indic,1.)
       endif
 
@@ -798,5 +899,5 @@
       External :: procname
       Optional ::  procname
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
 C        
       REAL, OPTIONAL :: calledweight
@@ -808,4 +909,11 @@
 C      
       If (Agrif_Root()) Return
+C      
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif         
       
       if ( PRESENT(calledweight) ) then
@@ -817,12 +925,12 @@
       endif
       
-      if (tabvarsindic <=0) then
-      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-tabvarsindic)
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
       parenttabvars => tabvars%parent_var
-      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-tabvarsindic)
-      else
-      tabvars=>Agrif_Curgrid % tabvars(tabvarsindic)
-      parenttabvars => Agrif_Curgrid % parent % tabvars(tabvarsindic)
-      roottabvars => Agrif_Mygrid % tabvars(tabvarsindic)
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
       endif
             
@@ -856,5 +964,5 @@
       External :: procname
       Optional ::  procname
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
 C        
       REAL, OPTIONAL :: calledweight
@@ -866,4 +974,11 @@
 C      
       If (Agrif_Root()) Return
+C      
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif       
       
       if ( PRESENT(calledweight) ) then
@@ -875,12 +990,12 @@
       endif
       
-      if (tabvarsindic <=0) then
-      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-tabvarsindic)
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
       parenttabvars => tabvars%parent_var
-      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-tabvarsindic)
-      else
-      tabvars=>Agrif_Curgrid % tabvars(tabvarsindic)
-      parenttabvars => Agrif_Curgrid % parent % tabvars(tabvarsindic)
-      roottabvars => Agrif_Mygrid % tabvars(tabvarsindic)
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
       endif
             
@@ -914,5 +1029,5 @@
       External :: procname
       Optional ::  procname
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
 C        
       REAL, OPTIONAL :: calledweight
@@ -924,4 +1039,11 @@
 C      
       If (Agrif_Root()) Return
+C      
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif       
       
       if ( PRESENT(calledweight) ) then
@@ -933,12 +1055,12 @@
       endif
       
-      if (tabvarsindic <=0) then
-      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-tabvarsindic)
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
       parenttabvars => tabvars%parent_var
-      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-tabvarsindic)
-      else
-      tabvars=>Agrif_Curgrid % tabvars(tabvarsindic)
-      parenttabvars => Agrif_Curgrid % parent % tabvars(tabvarsindic)
-      roottabvars => Agrif_Mygrid % tabvars(tabvarsindic)
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
       endif
             
@@ -972,5 +1094,5 @@
       External :: procname
       Optional ::  procname
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
 C        
       REAL, OPTIONAL :: calledweight
@@ -983,4 +1105,12 @@
       If (Agrif_Root()) Return
       
+C      
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif      
+      
       if ( PRESENT(calledweight) ) then
         weight=calledweight      
@@ -991,12 +1121,12 @@
       endif
       
-      if (tabvarsindic <=0) then
-      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-tabvarsindic)
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
       parenttabvars => tabvars%parent_var
-      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-tabvarsindic)
-      else
-      tabvars=>Agrif_Curgrid % tabvars(tabvarsindic)
-      parenttabvars => Agrif_Curgrid % parent % tabvars(tabvarsindic)
-      roottabvars => Agrif_Mygrid % tabvars(tabvarsindic)
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
       endif
             
@@ -1030,5 +1160,5 @@
       External :: procname
       Optional ::  procname
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
 C        
       REAL, OPTIONAL :: calledweight
@@ -1040,4 +1170,11 @@
 C      
       If (Agrif_Root()) Return
+C      
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif      
       
       if ( PRESENT(calledweight) ) then
@@ -1049,12 +1186,12 @@
       endif
       
-      if (tabvarsindic <=0) then
-      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-tabvarsindic)
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
       parenttabvars => tabvars%parent_var
-      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-tabvarsindic)
-      else
-      tabvars=>Agrif_Curgrid % tabvars(tabvarsindic)
-      parenttabvars => Agrif_Curgrid % parent % tabvars(tabvarsindic)
-      roottabvars => Agrif_Mygrid % tabvars(tabvarsindic)
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
       endif
             
@@ -1086,5 +1223,5 @@
 
       INTEGER :: tabvarsindic0 ! indice of the variable in tabvars
-      INTEGER :: tabvarsindic  ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic  ! indice of the variable in tabvars
       INTEGER :: dimensio  ! indice of the variable in tabvars
       External :: procname
@@ -1092,24 +1229,31 @@
 C      
       if (Agrif_Root()) Return
+C      
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif       
 C     
-      dimensio = Agrif_Mygrid % tabvars(tabvarsindic) % var % nbdim 
+      dimensio = Agrif_Mygrid % tabvars(indic) % var % nbdim 
 C
       if ( dimensio .EQ. 1 ) then
        if (present(procname)) then
        Call Agrif_Interp_1D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Mygrid % tabvars(indic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(indic),
+     & Agrif_Curgrid % tabvars(indic),
      & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array1 ,     
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim,procname)
+     & Agrif_Mygrid % tabvars(indic) % var % restaure,
+     & Agrif_Mygrid % tabvars(indic) %var % nbdim,procname)
        else
        Call Agrif_Interp_1D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Mygrid % tabvars(indic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(indic),
+     & Agrif_Curgrid % tabvars(indic),
      & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array1 ,     
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+     & Agrif_Mygrid % tabvars(indic) % var % restaure,
+     & Agrif_Mygrid % tabvars(indic) %var % nbdim)
        endif
        endif
@@ -1118,18 +1262,18 @@
       if (present(procname)) then
        Call Agrif_Interp_2D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Mygrid % tabvars(indic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(indic),
+     & Agrif_Curgrid % tabvars(indic),
      & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array2 ,     
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim,procname)
+     & Agrif_Mygrid % tabvars(indic) % var % restaure,
+     & Agrif_Mygrid % tabvars(indic) %var % nbdim,procname)
       else
        Call Agrif_Interp_2D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Mygrid % tabvars(indic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(indic),
+     & Agrif_Curgrid % tabvars(indic),
      & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array2 ,     
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+     & Agrif_Mygrid % tabvars(indic) % var % restaure,
+     & Agrif_Mygrid % tabvars(indic) %var % nbdim)
       endif
       endif
@@ -1138,18 +1282,18 @@
       if (present(procname)) then
        Call Agrif_Interp_3D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Mygrid % tabvars(indic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(indic),
+     & Agrif_Curgrid % tabvars(indic),
      & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array3 ,     
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim,procname)
+     & Agrif_Mygrid % tabvars(indic) % var % restaure,
+     & Agrif_Mygrid % tabvars(indic) %var % nbdim,procname)
       else
        Call Agrif_Interp_3D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Mygrid % tabvars(indic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(indic),
+     & Agrif_Curgrid % tabvars(indic),
      & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array3 ,     
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+     & Agrif_Mygrid % tabvars(indic) % var % restaure,
+     & Agrif_Mygrid % tabvars(indic) %var % nbdim)
       endif
       endif
@@ -1158,18 +1302,18 @@
       if (present(procname)) then
        Call Agrif_Interp_4D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Mygrid % tabvars(indic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(indic),
+     & Agrif_Curgrid % tabvars(indic),
      & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array4 ,     
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim,procname)
+     & Agrif_Mygrid % tabvars(indic) % var % restaure,
+     & Agrif_Mygrid % tabvars(indic) %var % nbdim,procname)
       else
        Call Agrif_Interp_4D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Mygrid % tabvars(indic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(indic),
+     & Agrif_Curgrid % tabvars(indic),
      & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array4 ,     
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+     & Agrif_Mygrid % tabvars(indic) % var % restaure,
+     & Agrif_Mygrid % tabvars(indic) %var % nbdim)
       endif
       endif
@@ -1178,18 +1322,18 @@
       if (present(procname)) then
        Call Agrif_Interp_5D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Mygrid % tabvars(indic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(indic),
+     & Agrif_Curgrid % tabvars(indic),
      & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array5 ,     
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim,procname)
+     & Agrif_Mygrid % tabvars(indic) % var % restaure,
+     & Agrif_Mygrid % tabvars(indic) %var % nbdim,procname)
       else
        Call Agrif_Interp_5D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Mygrid % tabvars(indic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(indic),
+     & Agrif_Curgrid % tabvars(indic),
      & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array5 ,     
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+     & Agrif_Mygrid % tabvars(indic) % var % restaure,
+     & Agrif_Mygrid % tabvars(indic) %var % nbdim)
        endif
        endif
@@ -1198,18 +1342,18 @@
       if (present(procname)) then
        Call Agrif_Interp_6D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Mygrid % tabvars(indic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(indic),
+     & Agrif_Curgrid % tabvars(indic),
      & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array6 ,     
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim,procname)
+     & Agrif_Mygrid % tabvars(indic) % var % restaure,
+     & Agrif_Mygrid % tabvars(indic) %var % nbdim,procname)
       else
        Call Agrif_Interp_6D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),
+     & Agrif_Mygrid % tabvars(indic) % var %  TypeInterp,
+     & Agrif_Curgrid % parent % tabvars(indic),
+     & Agrif_Curgrid % tabvars(indic),
      & Agrif_Curgrid % tabvars(tabvarsindic0) % var % array6 ,     
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+     & Agrif_Mygrid % tabvars(indic) % var % restaure,
+     & Agrif_Mygrid % tabvars(indic) %var % nbdim)
       endif
       endif
@@ -1225,24 +1369,44 @@
 
       REAL, DIMENSION(:) :: q
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
       External :: procname
       Optional ::  procname
+      TYPE(Agrif_PVariable),Pointer ::tabvars,parenttabvars,roottabvars      
 C
       if (Agrif_Root()) Return
 C      
+C      
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
+      parenttabvars => tabvars%parent_var
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
+      endif
+      
       if (present(procname)) then
       Call Agrif_Interp_1D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim,procname)
+     & roottabvars % var %  TypeInterp,
+     & parenttabvars,
+     & tabvars,q,
+     & roottabvars % var % restaure,
+     & roottabvars %var % nbdim,procname)
       else
       Call Agrif_Interp_1D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+     & roottabvars % var %  TypeInterp,
+     & parenttabvars,
+     & tabvars,q,
+     & roottabvars % var % restaure,
+     & roottabvars %var % nbdim)
+     
       endif
       Return
@@ -1256,26 +1420,51 @@
 
       REAL,  DIMENSION(:,:) :: q
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
       External :: procname
       Optional ::  procname
-
-C
-       if (Agrif_Root()) Return
-C
-       if (present(procname)) then
-       Call Agrif_Interp_2D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim,procname)
-       else
-       Call Agrif_Interp_2D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
-       endif
+      TYPE(Agrif_PVariable),Pointer ::tabvars,parenttabvars,roottabvars      
+C
+      if (Agrif_Root()) Return
+C      
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
+      parenttabvars => tabvars%parent_var
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      if (tabvars%var%restaure) then
+        if (agrif_curgrid%ngridstep == 0) then
+          call AGRIF_CopyFromold_AllOneVar
+     &            (Agrif_Curgrid,Agrif_OldMygrid,indic)
+        endif
+      endif
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
+      endif
+
+            
+      if (present(procname)) then
+      Call Agrif_Interp_2D(
+     & roottabvars % var %  TypeInterp,
+     & parenttabvars,
+     & tabvars,q,
+     & roottabvars % var % restaure,
+     & roottabvars %var % nbdim,procname)
+      else
+      Call Agrif_Interp_2D(
+     & roottabvars % var %  TypeInterp,
+     & parenttabvars,
+     & tabvars,q,
+     & roottabvars % var % restaure,
+     & roottabvars %var % nbdim)
+     
+      endif 
       Return
       End Subroutine Agrif_Interp_var2d
@@ -1288,26 +1477,51 @@
 
       REAL,  DIMENSION(:,:,:) :: q
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
       External :: procname
       Optional ::  procname
-
+      TYPE(Agrif_PVariable),Pointer ::tabvars,parenttabvars,roottabvars      
 C
       if (Agrif_Root()) Return
-C
+C      
+
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
+      parenttabvars => tabvars%parent_var
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      if (tabvars%var%restaure) then
+        if (agrif_curgrid%ngridstep == 0) then
+          call AGRIF_CopyFromold_AllOneVar
+     &            (Agrif_Curgrid,Agrif_OldMygrid,indic)
+        endif
+      endif      
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
+      endif
+
       if (present(procname)) then
       Call Agrif_Interp_3D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim,procname)
+     & roottabvars % var %  TypeInterp,
+     & parenttabvars,
+     & tabvars,q,
+     & roottabvars % var % restaure,
+     & roottabvars %var % nbdim,procname)
       else
       Call Agrif_Interp_3D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
-      endif
+     & roottabvars % var %  TypeInterp,
+     & parenttabvars,
+     & tabvars,q,
+     & roottabvars % var % restaure,
+     & roottabvars %var % nbdim)
+     
+      endif   
       Return
       End Subroutine Agrif_Interp_var3d
@@ -1320,26 +1534,51 @@
 
       REAL,  DIMENSION(:,:,:,:) :: q
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
       External :: procname
       Optional ::  procname
-
+      TYPE(Agrif_PVariable),Pointer ::tabvars,parenttabvars,roottabvars  
 C
       if (Agrif_Root()) Return
-C
+C      
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
+      parenttabvars => tabvars%parent_var
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      if (tabvars%var%restaure) then
+        if (agrif_curgrid%ngridstep == 0) then
+          call AGRIF_CopyFromold_AllOneVar
+     &            (Agrif_Curgrid,Agrif_OldMygrid,indic)
+        endif
+      endif      
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
+      endif
+            
       if (present(procname)) then
       Call Agrif_Interp_4D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim,procname)
+     & roottabvars % var %  TypeInterp,
+     & parenttabvars,
+     & tabvars,q,
+     & roottabvars % var % restaure,
+     & roottabvars %var % nbdim,procname)
       else
       Call Agrif_Interp_4D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
-      endif
+     & roottabvars % var %  TypeInterp,
+     & parenttabvars,
+     & tabvars,q,
+     & roottabvars % var % restaure,
+     & roottabvars %var % nbdim)
+     
+      endif      
+
       Return
       End Subroutine Agrif_Interp_var4d     
@@ -1352,25 +1591,44 @@
 
       REAL,  DIMENSION(:,:,:,:,:) :: q
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic, indic ! indice of the variable in tabvars
       External :: procname
       Optional ::  procname
-
+      TYPE(Agrif_PVariable),Pointer ::tabvars,parenttabvars,roottabvars      
 C
       if (Agrif_Root()) Return
-C
+C      
+
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
+      parenttabvars => tabvars%parent_var
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
+      endif
+      
       if (present(procname)) then
       Call Agrif_Interp_5D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim,procname)
+     & roottabvars % var %  TypeInterp,
+     & parenttabvars,
+     & tabvars,q,
+     & roottabvars % var % restaure,
+     & roottabvars %var % nbdim,procname)
       else
       Call Agrif_Interp_5D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var %  TypeInterp,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % restaure,
-     & Agrif_Mygrid % tabvars(tabvarsindic) %var % nbdim)
+     & roottabvars % var %  TypeInterp,
+     & parenttabvars,
+     & tabvars,q,
+     & roottabvars % var % restaure,
+     & roottabvars %var % nbdim)
+     
       endif
       Return
@@ -1538,5 +1796,5 @@
 
       REAL,  DIMENSION(:) :: q
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic,indic ! indice of the variable in tabvars
       External :: procname
       Optional ::  procname      
@@ -1544,30 +1802,49 @@
       INTEGER, DIMENSION(2), OPTIONAL :: locupdate1
       INTEGER, DIMENSION(2), OPTIONAL :: locupdate2        
+      TYPE(Agrif_PVariable),Pointer ::tabvars,parenttabvars,roottabvars   
 C      
       if (Agrif_Root()) Return
 C     
+
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
+      parenttabvars => tabvars%parent_var
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)      
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
+      endif
+      
       IF (present(locupdate)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1:1) 
+      tabvars%var % updateinf(1:1) 
      &      = locupdate(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1:1) 
+      tabvars%var % updatesup(1:1) 
      &      = locupdate(2)
       ELSE
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1:1) 
+      tabvars%var % updateinf(1:1) 
      &      = -99
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1:1) 
+      tabvars%var % updatesup(1:1) 
      &      = -99
       ENDIF
       
       IF (present(locupdate1)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1) 
+      tabvars%var % updateinf(1) 
      &      = locupdate1(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1) 
+      tabvars%var % updatesup(1) 
      &      = locupdate1(2)
       ENDIF  
       
       IF (present(locupdate2)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(2) 
+      tabvars%var % updateinf(2) 
      &      = locupdate2(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(2) 
+      tabvars%var % updatesup(2) 
      &      = locupdate2(2)
       ENDIF       
@@ -1575,17 +1852,17 @@
       IF (present(procname)) THEN
       Call Agrif_Update_1D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & roottabvars % var % typeupdate,
+     & parenttabvars,
+     & tabvars,q,
+     & tabvars % var % updateinf,
+     & tabvars % var % updatesup,
      & procname)
-      ELSE
+      ELSE 
       Call Agrif_Update_1D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+     & roottabvars % var % typeupdate,
+     & parenttabvars,
+     & tabvars,q,
+     & tabvars % var % updateinf,
+     & tabvars % var % updatesup)       
       ENDIF
 
@@ -1607,32 +1884,50 @@
       INTEGER, DIMENSION(2), OPTIONAL :: locupdate1
       INTEGER, DIMENSION(2), OPTIONAL :: locupdate2        
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic,indic ! indice of the variable in tabvars
+      TYPE(Agrif_PVariable),Pointer ::tabvars,parenttabvars,roottabvars       
 C      
       IF (Agrif_Root()) RETURN
       
 C 
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
+      parenttabvars => tabvars%parent_var
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)      
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
+      endif
+      
       IF (present(locupdate)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1:2) 
+      tabvars%var % updateinf(1:2) 
      &      = locupdate(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1:2) 
+      tabvars%var % updatesup(1:2) 
      &      = locupdate(2)
       ELSE
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1:2) 
+      tabvars%var % updateinf(1:2) 
      &      = -99
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1:2) 
+      tabvars%var % updatesup(1:2) 
      &      = -99
       ENDIF
       
       IF (present(locupdate1)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1) 
+      tabvars%var % updateinf(1) 
      &      = locupdate1(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1) 
+      tabvars%var % updatesup(1) 
      &      = locupdate1(2)
       ENDIF  
       
       IF (present(locupdate2)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(2) 
+      tabvars%var % updateinf(2) 
      &      = locupdate2(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(2) 
+      tabvars%var % updatesup(2) 
      &      = locupdate2(2)
       ENDIF
@@ -1640,17 +1935,17 @@
       IF (present(procname)) THEN
       Call Agrif_Update_2D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & roottabvars % var % typeupdate,
+     & parenttabvars,
+     & tabvars,q,
+     & tabvars % var % updateinf,
+     & tabvars % var % updatesup,
      & procname)
-      ELSE
+      ELSE 
       Call Agrif_Update_2D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+     & roottabvars % var % typeupdate,
+     & parenttabvars,
+     & tabvars,q,
+     & tabvars % var % updateinf,
+     & tabvars % var % updatesup)       
       ENDIF
 
@@ -1672,32 +1967,49 @@
       INTEGER, DIMENSION(2), OPTIONAL :: locupdate1
       INTEGER, DIMENSION(2), OPTIONAL :: locupdate2        
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic,indic ! indice of the variable in tabvars
+      TYPE(Agrif_PVariable),Pointer ::tabvars,parenttabvars,roottabvars       
 C      
       IF (Agrif_Root()) RETURN 
 C      
-
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
+      parenttabvars => tabvars%parent_var
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)      
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
+      endif
+      
       IF (present(locupdate)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1:3) 
+      tabvars%var % updateinf(1:3) 
      &      = locupdate(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1:3) 
+      tabvars%var % updatesup(1:3) 
      &      = locupdate(2)
       ELSE
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1:3) 
+      tabvars%var % updateinf(1:3) 
      &      = -99
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1:3) 
+      tabvars%var % updatesup(1:3) 
      &      = -99
       ENDIF      
       
       IF (present(locupdate1)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1) 
+      tabvars%var % updateinf(1) 
      &      = locupdate1(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1) 
+      tabvars%var % updatesup(1) 
      &      = locupdate1(2)
       ENDIF  
       
       IF (present(locupdate2)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(2) 
+      tabvars%var % updateinf(2) 
      &      = locupdate2(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(2) 
+      tabvars%var % updatesup(2) 
      &      = locupdate2(2)
       ENDIF
@@ -1705,17 +2017,17 @@
       IF (present(procname)) THEN
       Call Agrif_Update_3D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & roottabvars % var % typeupdate,
+     & parenttabvars,
+     & tabvars,q,
+     & tabvars % var % updateinf,
+     & tabvars % var % updatesup,
      & procname)
-      ELSE
+      ELSE 
       Call Agrif_Update_3D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+     & roottabvars % var % typeupdate,
+     & parenttabvars,
+     & tabvars,q,
+     & tabvars % var % updateinf,
+     & tabvars % var % updatesup)       
       ENDIF
 
@@ -1737,31 +2049,48 @@
       INTEGER, DIMENSION(2), OPTIONAL :: locupdate1
       INTEGER, DIMENSION(2), OPTIONAL :: locupdate2        
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic,indic ! indice of the variable in tabvars
+      TYPE(Agrif_PVariable),Pointer ::tabvars,parenttabvars,roottabvars       
 C      
       IF (Agrif_Root()) RETURN
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
+      parenttabvars => tabvars%parent_var
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)     
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
+      endif      
 C      
       IF (present(locupdate)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1:4) 
+      tabvars%var % updateinf(1:4) 
      &      = locupdate(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1:4) 
+      tabvars%var % updatesup(1:4) 
      &      = locupdate(2)
       ELSE
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1:4) 
+      tabvars%var % updateinf(1:4) 
      &      = -99
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1:4) 
+      tabvars%var % updatesup(1:4) 
      &      = -99
       ENDIF
       
       IF (present(locupdate1)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1) 
+      tabvars%var % updateinf(1) 
      &      = locupdate1(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1) 
+      tabvars%var % updatesup(1) 
      &      = locupdate1(2)
       ENDIF  
       
       IF (present(locupdate2)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(2) 
+      tabvars%var % updateinf(2) 
      &      = locupdate2(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(2) 
+      tabvars%var % updatesup(2) 
      &      = locupdate2(2)
       ENDIF
@@ -1769,17 +2098,17 @@
       IF (present(procname)) THEN
       Call Agrif_Update_4D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & roottabvars % var % typeupdate,
+     & parenttabvars,
+     & tabvars,q,
+     & tabvars % var % updateinf,
+     & tabvars % var % updatesup,
      & procname)
-      ELSE
+      ELSE 
       Call Agrif_Update_4D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+     & roottabvars % var % typeupdate,
+     & parenttabvars,
+     & tabvars,q,
+     & tabvars % var % updateinf,
+     & tabvars % var % updatesup)       
       ENDIF
 
@@ -1801,31 +2130,49 @@
       INTEGER, DIMENSION(2), OPTIONAL :: locupdate1
       INTEGER, DIMENSION(2), OPTIONAL :: locupdate2        
-      INTEGER :: tabvarsindic ! indice of the variable in tabvars
+      INTEGER :: tabvarsindic,indic ! indice of the variable in tabvars
+      TYPE(Agrif_PVariable),Pointer ::tabvars,parenttabvars,roottabvars       
 C
       IF (Agrif_Root()) RETURN
-C      
+C     
+      indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif 
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
+      parenttabvars => tabvars%parent_var
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)      
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      parenttabvars => Agrif_Curgrid % parent % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
+      endif
+       
       IF (present(locupdate)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1:5) 
+      tabvars%var % updateinf(1:5) 
      &      = locupdate(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1:5) 
+      tabvars%var % updatesup(1:5) 
      &      = locupdate(2)
       ELSE
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1:5) 
+      tabvars%var % updateinf(1:5) 
      &      = -99
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1:5) 
+      tabvars%var % updatesup(1:5) 
      &      = -99
       ENDIF
       
       IF (present(locupdate1)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(1) 
+      tabvars%var % updateinf(1) 
      &      = locupdate1(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(1) 
+      tabvars%var % updatesup(1) 
      &      = locupdate1(2)
       ENDIF  
       
       IF (present(locupdate2)) THEN
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updateinf(2) 
+      tabvars%var % updateinf(2) 
      &      = locupdate2(1)
-      Agrif_Curgrid%tabvars(tabvarsindic)%var % updatesup(2) 
+      tabvars%var % updatesup(2) 
      &      = locupdate2(2)
       ENDIF
@@ -1833,17 +2180,17 @@
       IF (present(procname)) THEN
       Call Agrif_Update_5D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup,
+     & roottabvars % var % typeupdate,
+     & parenttabvars,
+     & tabvars,q,
+     & tabvars % var % updateinf,
+     & tabvars % var % updatesup,
      & procname)
-      ELSE
+      ELSE 
       Call Agrif_Update_5D(
-     & Agrif_Mygrid % tabvars(tabvarsindic) % var % typeupdate,
-     & Agrif_Curgrid % parent % tabvars(tabvarsindic),
-     & Agrif_Curgrid % tabvars(tabvarsindic),q,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updateinf,
-     & Agrif_Curgrid % tabvars(tabvarsindic) % var % updatesup)      
+     & roottabvars % var % typeupdate,
+     & parenttabvars,
+     & tabvars,q,
+     & tabvars % var % updateinf,
+     & tabvars % var % updatesup)       
       ENDIF
 
@@ -1952,96 +2299,5 @@
       End Subroutine Agrif_Flux_Correction
 
-      Subroutine Agrif_Declare_Variable(posvar,firstpoint,
-     &    raf,lb,ub,varid)
-      character*(80) :: variablename
-      Type(Agrif_List_Variables), Pointer :: newvariable,newvariablep
-      INTEGER, DIMENSION(:) :: posvar
-      INTEGER, DIMENSION(:) :: lb,ub
-      INTEGER, DIMENSION(:) :: firstpoint
-      CHARACTER(*) ,DIMENSION(:) :: raf        
-      TYPE(Agrif_Pvariable), Pointer :: parent_var,root_var
-      INTEGER :: dimensio
-      INTEGER :: varid
-            
-      if (agrif_root()) return
-
-      dimensio = SIZE(posvar)
-C
-C    
-      Allocate(newvariable)
-      Allocate(newvariable%pvar)
-      Allocate(newvariable%pvar%var)
-      Allocate(newvariable%pvar%var%posvar(dimensio))
-      Allocate(newvariable%pvar%var%interptab(dimensio))
-      newvariable%pvar%var%variablename = variablename
-      newvariable%pvar%var%interptab = raf
-      newvariable%pvar%var%nbdim = dimensio
-      newvariable%pvar%var%posvar = posvar
-      newvariable%pvar%var%point(1:dimensio) = firstpoint
-      newvariable%pvar%var%lb(1:dimensio) = lb(1:dimensio)
-      newvariable%pvar%var%ub(1:dimensio) = ub(1:dimensio)
-      
-      newvariable % nextvariable => Agrif_Curgrid%variables
-      
-      Agrif_Curgrid%variables => newvariable
-      Agrif_Curgrid%Nbvariables = Agrif_Curgrid%Nbvariables + 1
-      
-      varid = -Agrif_Curgrid%Nbvariables
-      
-       if (agrif_curgrid%parent%nbvariables < agrif_curgrid%nbvariables)
-     &       then
-      Allocate(newvariablep)
-      Allocate(newvariablep%pvar)
-      Allocate(newvariablep%pvar%var)      
-      Allocate(newvariablep%pvar%var%posvar(dimensio))
-      Allocate(newvariablep%pvar%var%interptab(dimensio))
-      newvariablep%pvar%var%variablename = variablename
-      newvariablep%pvar%var%interptab = raf
-      newvariablep%pvar%var%nbdim = dimensio
-      newvariablep%pvar%var%posvar = posvar
-      newvariablep%pvar%var%point(1:dimensio) = firstpoint
-      
-      newvariablep % nextvariable => Agrif_Curgrid%parent%variables
-      
-      Agrif_Curgrid%parent%variables => newvariablep       
-      
-      Agrif_Curgrid%parent%Nbvariables = 
-     &    Agrif_Curgrid%parent%Nbvariables + 1
-      parent_var=>newvariablep%pvar
-      else
-      parent_var=>Agrif_Search_Variable
-     &              (Agrif_Curgrid%parent,Agrif_Curgrid%nbvariables)
-       endif
-       
-       newvariable%pvar%parent_var=>parent_var
-      
-      root_var=>Agrif_Search_Variable
-     &              (Agrif_Mygrid,Agrif_Curgrid%nbvariables)
-     
-      newvariable%pvar%var%root_var=>root_var%var
-      
-           
-      End Subroutine Agrif_Declare_Variable
-
-      FUNCTION Agrif_Search_Variable(grid,varid)
-      integer :: varid
-      Type(Agrif_Pvariable), Pointer :: Agrif_Search_variable
-      Type(Agrif_grid), Pointer :: grid
-      
-      Type(Agrif_List_Variables), pointer :: parcours
-      Logical :: foundvariable
-      integer nb
-      
-      foundvariable = .FALSE.
-      parcours => grid%variables
-      
-      do nb=1,varid-1
-         parcours => parcours%nextvariable
-      End Do
-      
-      Agrif_Search_variable => parcours%pvar
-      
-      
-      End Function Agrif_Search_variable
+
                               
       Subroutine Agrif_Declare_Profile_flux(profilename,posvar,
@@ -2071,5 +2327,122 @@
       
       End Subroutine Agrif_Declare_Profile_flux
-              
+
+      Subroutine Agrif_Save_ForRestore0D(tabvarsindic0,tabvarsindic)
+      integer :: tabvarsindic0, tabvarsindic
+      integer :: dimensio
+      
+      dimensio =  Agrif_Mygrid % tabvars(tabvarsindic0) % var % nbdim
+      
+      select case(dimensio)
+      case(2)
+          call Agrif_Save_ForRestore2D(
+     &      Agrif_Curgrid % tabvars(tabvarsindic0) % var % array2,
+     &      tabvarsindic)
+      case(3)
+          call Agrif_Save_ForRestore3D(
+     &      Agrif_Curgrid % tabvars(tabvarsindic0) % var % array3,
+     &      tabvarsindic)
+      case(4)
+          call Agrif_Save_ForRestore4D(
+     &      Agrif_Curgrid % tabvars(tabvarsindic0) % var % array4,
+     &      tabvarsindic)     
+      end select
+
+      Return
+      End Subroutine Agrif_Save_ForRestore0D 
+      
+    
+      
+      Subroutine Agrif_Save_ForRestore2D(q,tabvarsindic)
+      real,dimension(:,:) :: q
+      integer :: tabvarsindic, indic
+      TYPE(Agrif_PVariable),Pointer ::tabvars, roottabvars    
+ 
+       indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
+      endif      
+      if (.not.allocated(tabvars%var%array2)) then      
+      allocate(tabvars%var%array2(tabvars%var%lb(1):tabvars%var%ub(1),
+     &                            tabvars%var%lb(2):tabvars%var%ub(2)))
+      endif
+      tabvars%var%array2 = q
+      roottabvars%var%restaure = .true.
+      
+      Return
+      End Subroutine Agrif_Save_ForRestore2D  
+      
+      Subroutine Agrif_Save_ForRestore3D(q,tabvarsindic)
+      real,dimension(:,:,:) :: q
+      integer :: tabvarsindic, indic
+      TYPE(Agrif_PVariable),Pointer ::tabvars, roottabvars    
+ 
+       indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
+      endif      
+
+      if (.not.allocated(tabvars%var%array3)) then
+      allocate(tabvars%var%array3(tabvars%var%lb(1):tabvars%var%ub(1),
+     &                            tabvars%var%lb(2):tabvars%var%ub(2),
+     &                            tabvars%var%lb(3):tabvars%var%ub(3)))
+      endif
+      tabvars%var%array3 = q
+      roottabvars%var%restaure = .true.
+      
+      Return
+      End Subroutine Agrif_Save_ForRestore3D
+      
+      Subroutine Agrif_Save_ForRestore4D(q,tabvarsindic)
+      real,dimension(:,:,:,:) :: q
+      integer :: tabvarsindic, indic
+      TYPE(Agrif_PVariable),Pointer ::tabvars, roottabvars    
+ 
+       indic = tabvarsindic
+      if (tabvarsindic >=0) then
+        if (agrif_curgrid%tabvars(tabvarsindic)%var%nbdim == 0) then
+          indic = agrif_curgrid%tabvars(tabvarsindic)%var%iarray0
+        endif
+      endif
+      
+      if (indic <=0) then
+      tabvars => Agrif_Search_Variable(Agrif_Curgrid,-indic)
+      roottabvars => Agrif_Search_Variable(Agrif_Mygrid,-indic)
+      else
+      tabvars=>Agrif_Curgrid % tabvars(indic)
+      roottabvars => Agrif_Mygrid % tabvars(indic)
+      endif
+
+      if (.not.allocated(tabvars%var%array4)) then         
+      allocate(tabvars%var%array4(tabvars%var%lb(1):tabvars%var%ub(1),
+     &                            tabvars%var%lb(2):tabvars%var%ub(2),
+     &                            tabvars%var%lb(3):tabvars%var%ub(3),
+     &                            tabvars%var%lb(4):tabvars%var%ub(4)))
+      endif
+      tabvars%var%array4 = q
+      roottabvars%var%restaure = .true.
+      
+      Return
+      End Subroutine Agrif_Save_ForRestore4D                   
 C
       End module Agrif_bcfunction
