










      subroutine v2dbc_tile(Istr,Iend,Jstr,Jend,grad)
      use Agrif_Types, only : Agrif_tabvars

      use AGRIF_Util

      integer(4) :: Istr
      integer(4) :: Iend
      integer(4) :: Jstr
      integer(4) :: Jend
      real, dimension(Istr-2:Iend+2,Jstr-2:Jend+2) :: grad

                     
                                    
                                             
      if (AGRIF_Root()) then
        call v2dbc_parent_tile(Istr,Iend,Jstr,Jend,grad)
      else
        call v2dbc_child_tile(Istr,Iend,Jstr,Jend,grad)
      endif
      return
      end
      subroutine v2dbc_parent_tile(Istr,Iend,Jstr,Jend,grad)      


      use Agrif_Util
      interface
        subroutine Sub_Loop_v2dbc_parent_tile(Istr,Iend,Jstr,Jend,grad,p
     &add_E,Mm,padd_X,Lm,pm,zetabry_north,vbarbry_north,vmask,zetabry_so
     &uth,vbarbry_south,vbar,knew,pn,kstp,zeta,h,tauM_out,tauM_in,dtfast
     &,NORTH_INTER,SOUTH_INTER,EAST_INTER,WEST_INTER,Mmmpi,Lmmpi,N3dHz,N
     &3d,N2d)
          implicit none
      integer(4), parameter :: LLm0 = 41
      integer(4), parameter :: MMm0 = 42
      integer(4), parameter :: N = 32
      integer(4), parameter :: N_sl = 0
      integer(4), parameter :: NP_XI = 1
      integer(4), parameter :: NP_ETA = 4
      integer(4), parameter :: NNODES = NP_XI*NP_ETA
      integer(4), parameter :: NPP = 1
      integer(4), parameter :: NSUB_X = 1
      integer(4), parameter :: NSUB_E = 1
      integer(4), parameter :: NWEIGHT = 1000
      integer(4), parameter :: Ntides = 8
      integer(4), parameter :: stdout = 6
      integer(4), parameter :: Np = N+1
      integer(4), parameter :: NpHz = (N+1+N_sl)
      integer(4), parameter :: NSA = 28
      real, parameter :: Vtransform = 2
      integer(4), parameter :: itemp = 1
      integer(4), parameter :: ntrc_temp = 1
      integer(4), parameter :: ntrc_salt = 1
      integer(4), parameter :: ntrc_pas = 0
      integer(4), parameter :: ntrc_bio = 0
      integer(4), parameter :: ntrc_subs = 0
      integer(4), parameter :: ntrc_substot = 0
      integer(4), parameter :: ntrc_sed = 0
      integer(4), parameter :: NTA = itemp+ntrc_salt
      integer(4), parameter :: NT = itemp+ntrc_salt+ntrc_pas+ntrc_bio+nt
     &rc_sed
      integer(4), parameter :: NTot = NT
      integer(4), parameter :: isalt = itemp+1
      integer(4), parameter :: ntrc_diabio = 0
      integer(4), parameter :: ntrc_diats = 0
      integer(4), parameter :: ntrc_diauv = 0
      integer(4), parameter :: ntrc_diavrt = 0
      integer(4), parameter :: ntrc_diaek = 0
      integer(4), parameter :: ntrc_diapv = 0
      integer(4), parameter :: ntrc_diaeddy = 0
      integer(4), parameter :: ntrc_surf = 0
      real, parameter :: eps = 1.D-20
      real, parameter :: pi = 3.14159265358979323846D0
      real, parameter :: deg2rad = pi/180.D0
      real, parameter :: rad2deg = 180.D0/pi
      real, parameter :: Eradius = 6371315.0D0
      real, parameter :: Erotation = 7.292115090D-5
      real, parameter :: day2sec = 86400.D0
      real, parameter :: sec2day = 1.D0/86400.D0
      real, parameter :: year2day = 365.25D0
      real, parameter :: day2year = 1.D0/365.25D0
      real, parameter :: jul_off = 2440000.D0
      real, parameter :: g = 9.81D0
      real, parameter :: Cp = 3985.0D0
      real, parameter :: vonKar = 0.41D0
      real, parameter :: spval = -999.0D0
      logical, parameter :: mask_val = .true.
      integer(4) :: padd_E
      integer(4) :: Mm
      integer(4) :: padd_X
      integer(4) :: Lm
      integer(4) :: knew
      integer(4) :: kstp
      real :: tauM_out
      real :: tauM_in
      real :: dtfast
      logical :: NORTH_INTER
      logical :: SOUTH_INTER
      logical :: EAST_INTER
      logical :: WEST_INTER
      integer(4) :: Mmmpi
      integer(4) :: Lmmpi
      integer(4) :: N3dHz
      integer(4) :: N3d
      integer(4) :: N2d
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E) :: pm
      real, dimension(-1:Lm+2+padd_X) :: zetabry_north
      real, dimension(-1:Lm+2+padd_X) :: vbarbry_north
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E) :: vmask
      real, dimension(-1:Lm+2+padd_X) :: zetabry_south
      real, dimension(-1:Lm+2+padd_X) :: vbarbry_south
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E,1:4) :: vbar
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E) :: pn
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E,1:4) :: zeta
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E) :: h
      integer(4) :: Istr
      integer(4) :: Iend
      integer(4) :: Jstr
      integer(4) :: Jend
      real, dimension(Istr-2:Iend+2,Jstr-2:Jend+2) :: grad
        end subroutine Sub_Loop_v2dbc_parent_tile

      end interface
      integer(4) :: Istr
      integer(4) :: Iend
      integer(4) :: Jstr
      integer(4) :: Jend
      real, dimension(Istr-2:Iend+2,Jstr-2:Jend+2) :: grad
      

        call Sub_Loop_v2dbc_parent_tile(Istr,Iend,Jstr,Jend,grad, Agrif_
     &tabvars_i(14)%iarray0, Agrif_tabvars_i(4)%iarray0, Agrif_tabvars_i
     &(13)%iarray0, Agrif_tabvars_i(2)%iarray0, Agrif_tabvars(117)%array
     &2, Agrif_tabvars(187)%array1, Agrif_tabvars(183)%array1, Agrif_tab
     &vars(91)%array2, Agrif_tabvars(199)%array1, Agrif_tabvars(195)%arr
     &ay1, Agrif_tabvars(86)%array3, Agrif_tabvars_i(150)%iarray0, Agrif
     &_tabvars(116)%array2, Agrif_tabvars_i(148)%iarray0, Agrif_tabvars(
     &88)%array3, Agrif_tabvars(128)%array2, Agrif_tabvars_r(34)%array0,
     & Agrif_tabvars_r(33)%array0, Agrif_tabvars_r(4)%array0, Agrif_tabv
     &ars_l(13)%larray0, Agrif_tabvars_l(14)%larray0, Agrif_tabvars_l(11
     &)%larray0, Agrif_tabvars_l(12)%larray0, Agrif_tabvars_i(8)%iarray0
     &, Agrif_tabvars_i(7)%iarray0, Agrif_tabvars_i(17)%iarray0, Agrif_t
     &abvars_i(16)%iarray0, Agrif_tabvars_i(15)%iarray0)

      end


      subroutine Sub_Loop_v2dbc_parent_tile(Istr,Iend,Jstr,Jend,grad,pad
     &d_E,Mm,padd_X,Lm,pm,zetabry_north,vbarbry_north,vmask,zetabry_sout
     &h,vbarbry_south,vbar,knew,pn,kstp,zeta,h,tauM_out,tauM_in,dtfast,N
     &ORTH_INTER,SOUTH_INTER,EAST_INTER,WEST_INTER,Mmmpi,Lmmpi,N3dHz,N3d
     &,N2d)

      use Agrif_Types, only : Agrif_tabvars

      implicit none

      integer(4), parameter :: LLm0 = 41
      integer(4), parameter :: MMm0 = 42
      integer(4), parameter :: N = 32
      integer(4), parameter :: N_sl = 0
      integer(4), parameter :: NP_XI = 1
      integer(4), parameter :: NP_ETA = 4
      integer(4), parameter :: NNODES = NP_XI*NP_ETA
      integer(4), parameter :: NPP = 1
      integer(4), parameter :: NSUB_X = 1
      integer(4), parameter :: NSUB_E = 1
      integer(4), parameter :: NWEIGHT = 1000
      integer(4), parameter :: Ntides = 8
      integer(4), parameter :: stdout = 6
      integer(4), parameter :: Np = N+1
      integer(4), parameter :: NpHz = (N+1+N_sl)
      integer(4), parameter :: NSA = 28
      real, parameter :: Vtransform = 2
      integer(4), parameter :: itemp = 1
      integer(4), parameter :: ntrc_temp = 1
      integer(4), parameter :: ntrc_salt = 1
      integer(4), parameter :: ntrc_pas = 0
      integer(4), parameter :: ntrc_bio = 0
      integer(4), parameter :: ntrc_subs = 0
      integer(4), parameter :: ntrc_substot = 0
      integer(4), parameter :: ntrc_sed = 0
      integer(4), parameter :: NTA = itemp+ntrc_salt
      integer(4), parameter :: NT = itemp+ntrc_salt+ntrc_pas+ntrc_bio+nt
     &rc_sed
      integer(4), parameter :: NTot = NT
      integer(4), parameter :: isalt = itemp+1
      integer(4), parameter :: ntrc_diabio = 0
      integer(4), parameter :: ntrc_diats = 0
      integer(4), parameter :: ntrc_diauv = 0
      integer(4), parameter :: ntrc_diavrt = 0
      integer(4), parameter :: ntrc_diaek = 0
      integer(4), parameter :: ntrc_diapv = 0
      integer(4), parameter :: ntrc_diaeddy = 0
      integer(4), parameter :: ntrc_surf = 0
      real, parameter :: eps = 1.D-20
      real, parameter :: pi = 3.14159265358979323846D0
      real, parameter :: deg2rad = pi/180.D0
      real, parameter :: rad2deg = 180.D0/pi
      real, parameter :: Eradius = 6371315.0D0
      real, parameter :: Erotation = 7.292115090D-5
      real, parameter :: day2sec = 86400.D0
      real, parameter :: sec2day = 1.D0/86400.D0
      real, parameter :: year2day = 365.25D0
      real, parameter :: day2year = 1.D0/365.25D0
      real, parameter :: jul_off = 2440000.D0
      real, parameter :: g = 9.81D0
      real, parameter :: Cp = 3985.0D0
      real, parameter :: vonKar = 0.41D0
      real, parameter :: spval = -999.0D0
      logical, parameter :: mask_val = .true.
      integer(4) :: padd_E
      integer(4) :: Mm
      integer(4) :: padd_X
      integer(4) :: Lm
      integer(4) :: knew
      integer(4) :: kstp
      real :: tauM_out
      real :: tauM_in
      real :: dtfast
      logical :: NORTH_INTER
      logical :: SOUTH_INTER
      logical :: EAST_INTER
      logical :: WEST_INTER
      integer(4) :: Mmmpi
      integer(4) :: Lmmpi
      integer(4) :: N3dHz
      integer(4) :: N3d
      integer(4) :: N2d
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E) :: pm
      real, dimension(-1:Lm+2+padd_X) :: zetabry_north
      real, dimension(-1:Lm+2+padd_X) :: vbarbry_north
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E) :: vmask
      real, dimension(-1:Lm+2+padd_X) :: zetabry_south
      real, dimension(-1:Lm+2+padd_X) :: vbarbry_south
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E,1:4) :: vbar
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E) :: pn
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E,1:4) :: zeta
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E) :: h
      integer(4) :: Istr
      integer(4) :: Iend
      integer(4) :: Jstr
      integer(4) :: Jend
      real, dimension(Istr-2:Iend+2,Jstr-2:Jend+2) :: grad

                   

                                            
                             
                                            

                                                             
                     
                        

                                                            
                                           
                                                               
                                    
                                      
                                                          

                       

                                    

                        
                              

                       
                          

                                                
                                             
                          

                        

                                 

                                                
                        

                                                              
                      
                              

                                       
                                                                     
                                          
                         

                             

                             

                            

                            

                                             

                            

                                     

                                                               

                         

                                                      
                                                      
                                                                  
                               

                               

                              

                              

                               

                              

                              

                                

                             

                                         
      integer(4) :: i
      integer(4) :: j
                                                
                                                                       
                                                                 
               
                                 
                                            
                                      
                    
      integer(4) :: trd
C$    integer*4 omp_get_thread_num
                                                                       
                                                                 
                 
      real :: cff
      real :: cx
      real :: cy
      real :: v_str
      real :: dft
      real :: dfx
      real :: dfy
      real :: tau
      real :: tau_in
      real :: tau_out
      real :: hx
      real :: zx
                            

                           
                                    
                       
                                             
                                                                       
                                                                 
         
                     
                                          
                                                                       
                                                                       
                                                                 
                                                      
                                
                                            
                                                 
                                                             
                                           
                                                    
                                 
                                      
                                
                                            
                                                 
                                                             
                                           
                                                    
                                 
                                      
                                 
                                              
                                                   
                                                                
                                             
                                                       
                                  
                                        
                                 
                                              
                                                   
                                                                
                                             
                                                       
                                  
                                        
                                                                       
                                                                 
              
                                                           
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                                
                                                                       
                                                                 
                                                                 
                              
                                                                       
                                                                 
                              
                                                                       
                                                                 
                   
                                                  
                                                                       
                                                                 
              
                                                           
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                                
                                                                       
                                                                 
                                                                 
                              
                                                                       
                                                                 
                              
                                                                       
                                                                 
                  
                                                  
                                                                       
                                                                 
                
                                                              
                                                                       
                                                                 
                                                                 
                                      
                                                                       
                                                                 
                                                      
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                    
                                                                       
                                                                 
                    
                                                     
                                                                       
                                                                 
                
                                                              
                                                                       
                                                                 
                                                                 
                                      
                                                                       
                                                                 
                                                      
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                    
                                                                       
                                                                 
                    
                                                     
                                              
                             
                                            
                                               
                                            
                                               
                                                                 
                                                 
                                 
                                               
                                               
                                               
                                               
                                               
                                               
                                             
                                             
                                             
                                             
                                             
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                              
                                                  
                                                  
                                                  
                                                  
                                                 
                                                 
                                               
                                               
                                                      
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                           
                                                           
                                                           
                                    
                                                
                                                
                                                
                                                
                                                 
                           
                           
                           
                           
                             
                                              
                          
                                                 
                                                 
                                                 
                              
                              
                              
                                                                  
                                                                       
                                                                 
                                 
                                
                                                                       
                                                                 
                                                                 
                                                                 
                                                        
                                                                       
                                                                 
                                                                 
            
                                              
                                                   
                     
                              
                               
                                 
                                                  
                                                                       
                                                                 
                                                                 
                        
                      
                           
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                    
                           
                                      
                             
                                                 
                                                                       
                                                                 
                     
                                                      
                                                                       
                                                                 
              
                                          
                                                                       
                                                                 
       
                                                           
      real(8) :: Cu_Nbq_X
      real(8) :: Cu_Nbq_Y
      real(8) :: Cu_Nbq_Z
                                             
                                                                       
                                                                 
              
                                                  
                                                                       
                                                                 
              
                                  
                                           
                                                  
                                                                   
                                                               
                                                      
                                                                       
                                                                 
                      
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                        
                                
                                                                       
                                                                 
                                                        

                                                                       
                                                                 
                  
                                                                       
                                                                 
                                                                 
                                                                 
                  

                          

              
                             

                  
                               

                 
                                

                       
                                   

                                                
                                                
                                                     
                                                   
                                                   
                                                         
                                                
                                   
                                                    
                                              
                                     
                                                
                                              
                                            
                                                           
                                                     
                           
                                  
                                                
                                                
                                                     
                                                   
                                                   
                                                         
                                                           
                                                         
                                                              
                                                           
                                                                
                                                                   
                                                                    
                                                                   
                                                   
                                 
                                                      
                                   
                                        
                                        
                                                       
                                                     
                                             
                                                               
                                              
                                                           
                                        
                                                   
                                 
                                               
                               
                                              
                             
                                                  
                                                 
                                                   
                                             
                                 
                                                              
                                                  
                                             
                                                                    
                                          
                                                                   
                                                   
                                              
                             
                                                 
                               
                                 
                     
                                                              
                                     
                                             
                                                                       
                                                                 
 
                                                                   
                                           
                                                
                                 
                                                  
                                                  
                                                  
                                                   
                                                   
                                   
                                 
                                
                                           
                                         
                                             
                                                              
                                              
                                                                       
                                             
                              
                                          
                              
                                          
                              
                                                       
                              
                                                      
                              
                                                      
                              
                                              
                               
                                           
                               
                                           
                               
                                                        
                               
                                                       
                               
                                                       
                               
                                              
                                                        
                                            
                                                   
                                            
                                                   
                           
                                  
                           
                                  
                           
                                  
                                        
                               
                                                           
                                        
                          
                                                       
                                             
                         
                                   
                                                    
                                                    
                                
                                                    
                                 
                                                    
                                                   
                                                   
                                                  
                                                               
                                           
                                                     
                                                     
                                                       
                                                        
                                                           
                                                       
                                                       
                                           
                                                            
                                  
                                                            
                               
                                                            
                               
                                                     
                                            
                                                  
                                            
                                                  
                                            
                                                  
                                            
                                                                
                                            
                                                             
                                            
                                                             
                                            
                                                             
                                            
                                                      
                                             
                                                   
                                             
                                                   
                                             
                                                   
                                             
                                                                 
                                             
                                                              
                                             
                                                              
                                             
                                                              
                                             
                                          
                                                           
                                            
                                             
                                     
                                                    
                                                      
                                                                       
                                                                 
                                           
                                                    
                                                      
                                               
                                                            
                                           
                                
                                
                             
                                                                       
                                                                 
             
                                                      
                        
                                                          
                                                                       
                                                                 
                                              
                                                         
                                               
                                                
                                           
                                           
                                                                       
                                                                 
                                                                 
                                                                 
                         
!$AGRIF_DO_NOT_TREAT
      integer*4 :: iind
      integer*4 :: sortedint(0:10000)
      integer*4 :: whichstep(0:10000)
      integer*4 :: grids_at_level(0:20,0:100)
      integer*4 :: parent_grid(0:20)
      integer*4 :: coeff_ref_time(0:20)
      integer*4 :: nbtimes, nbmaxtimes
      common/rootintegrate/nbtimes, nbmaxtimes,
     &    iind,sortedint,whichstep,
     &    grids_at_level,parent_grid,coeff_ref_time
!$AGRIF_END_DO_NOT_TREAT
                                        
      integer(4) :: IstrR
      integer(4) :: IendR
      integer(4) :: JstrR
      integer(4) :: JendR
                      
      integer(4) :: IstrU
                      
      integer(4) :: JstrV
      if ((istr.eq.1 .and. .not.WEST_INTER)) then
        IstrR=Istr-1
        IstrU=Istr+1
      else
        IstrR=Istr
        IstrU=Istr
      endif
      if ((iend.eq.Lmmpi .and. .not.EAST_INTER)) then
        IendR=Iend+1
      else
        IendR=Iend
      endif
      if ((jstr.eq.1.and. .not.SOUTH_INTER)) then
        JstrR=Jstr-1
        JstrV=Jstr+1
      else
        JstrR=Jstr
        JstrV=Jstr
      endif
      if ((jend.eq.Mmmpi .and. .not.NORTH_INTER)) then
        JendR=Jend+1
      else
        JendR=Jend
      endif
!$acc kernels if(compute_on_device) default(present) async(1)
      tau_in=dtfast*tauM_in
      tau_out=dtfast*tauM_out
      grad = 1.D0
      if ((istr.eq.1 .and. .not.WEST_INTER) .and. (jstr.eq.1.and. 
     &                                           .not.SOUTH_INTER)) then
        grad(Istr,Jstr) = 0.5D0
      endif
      if ((iend.eq.Lmmpi .and. .not.EAST_INTER) .and. (jstr.eq.1.and. 
     &                                           .not.SOUTH_INTER)) then
        grad(Iend,Jstr) = 0.5D0
      endif
      if ((istr.eq.1 .and. .not.WEST_INTER) .and. (jend.eq.Mmmpi .and. 
     &                                           .not.NORTH_INTER)) then
        grad(Istr,Jend+1) = 0.5D0
      endif
      if ((iend.eq.Lmmpi .and. .not.EAST_INTER) .and. (jend.eq.Mmmpi 
     &                                     .and. .not.NORTH_INTER)) then
        grad(Iend,Jend+1) = 0.5D0
      endif
      if ((jstr.eq.1.and. .not.SOUTH_INTER)) then
        do i=Istr,Iend
          cff=0.5D0*(h(i,Jstr-1)+zeta(i,Jstr-1,kstp)+
     &             h(i,Jstr  )+zeta(i,Jstr  ,kstp))
          hx=sqrt(g/cff)
          cx=dtfast*cff*hx*0.5D0*(pn(i,Jstr-1)+pn(i,Jstr))
          zx=(0.5D0+cx)*zeta(i,jstr,kstp)+(0.5D0-cx)*zeta(i,jstr-1,kstp)
          if (cx .gt. 0.292893218813452D0) then
            zx=zx + ( zeta(i,jstr,knew) +cx*zeta(i,jstr-1,kstp)
     &                               -(1.D0+cx)*zeta(i,jstr,kstp)
     &                           )*(1.D0-0.292893218813452D0/cx)**2
          endif
          vbar(i,Jstr,knew)= 0.5D0*( (1.D0-cx)*vbar(i,Jstr,  kstp)
     &                                 +cx*vbar(i,Jstr+1,kstp)
     &                                     +vbarbry_south(i)
     &                                     -hx*( zx
     &                                        -zetabry_south(i)
     &                           ))
          vbar(i,Jstr,knew)=vbar(i,Jstr,knew)*vmask(i,Jstr)
        enddo
      endif
      if ((jend.eq.Mmmpi .and. .not.NORTH_INTER)) then
        do i=Istr,Iend
          cff=0.5D0*(h(i,Jend  )+zeta(i,Jend  ,kstp)+
     &             h(i,Jend+1)+zeta(i,Jend+1,kstp))
          hx=sqrt(g/cff)
          cx=dtfast*cff*hx*0.5D0*(pn(i,Jend)+pn(i,Jend+1))
          zx=(0.5D0+cx)*zeta(i,jend,kstp)+(0.5D0-cx)*zeta(i,jend+1,kstp)
          if (cx .gt. 0.292893218813452D0) then
            zx=zx + ( zeta(i,jend,knew) +cx*zeta(i,jend+1,kstp)
     &                               -(1.D0+cx)*zeta(i,jend,kstp)
     &                           )*(1.D0-0.292893218813452D0/cx)**2
          endif
          vbar(i,Jend+1,knew)= 0.5D0*( (1.D0-cx)*vbar(i,Jend+1,kstp)
     &                                   +cx*vbar(i,Jend  ,kstp)
     &                                       +vbarbry_north(i)
     &                                       +hx*( zx
     &                                         -zetabry_north(i)
     &                            ))
          vbar(i,Jend+1,knew)=vbar(i,Jend+1,knew)*vmask(i,Jend+1)
        enddo
      endif
      if ((istr.eq.1 .and. .not.WEST_INTER)) then
        do j=JstrV,Jend
          cff=sqrt(0.5D0*g*(h(Istr-1,j-1)+zeta(Istr-1,j-1,kstp)+
     &                    h(Istr-1,j  )+zeta(Istr-1,j  ,kstp)))
          cx=dtfast*cff*0.5D0*(pm(Istr-1,j-1)+pm(Istr-1,j))
          vbar(Istr-1,j,knew)=( vbar(Istr-1,j,kstp)
     &                      +cx*vbar(Istr  ,j,knew) )/(1.D0+cx)
     &                        *vmask(Istr-1,j)
        enddo
      endif
      if ((iend.eq.Lmmpi .and. .not.EAST_INTER)) then
        do j=JstrV,Jend
          cff=sqrt(0.5D0*g*(h(Iend+1,j-1)+zeta(Iend+1,j-1,kstp)+
     &                    h(Iend+1,j  )+zeta(Iend+1,j  ,kstp)))
          cx=dtfast*cff*0.5D0*(pm(Iend+1,j-1)+pm(Iend+1,j))
          vbar(Iend+1,j,knew)=(vbar(Iend+1,j,kstp)
     &                     +cx*vbar(Iend  ,j,knew) )/(1.D0+cx)
     &                        *vmask(Iend+1,j)
        enddo
      endif
      if ((istr.eq.1 .and. .not.WEST_INTER) .and. (jstr.eq.1.and. 
     &                                           .not.SOUTH_INTER)) then
        vbar(Istr-1,Jstr,knew)=0.5D0*( vbar(Istr-1,Jstr+1,knew)
     &                              +vbar(Istr  ,Jstr  ,knew))
     &                         *vmask(Istr-1,Jstr)
      endif
      if ((iend.eq.Lmmpi .and. .not.EAST_INTER) .and. (jstr.eq.1.and. 
     &                                           .not.SOUTH_INTER)) then
        vbar(Iend+1,Jstr,knew)=0.5D0*( vbar(Iend+1,Jstr+1,knew)
     &                              +vbar(Iend  ,Jstr  ,knew))
     &                         *vmask(Iend+1,Jstr)
      endif
      if ((istr.eq.1 .and. .not.WEST_INTER) .and. (jend.eq.Mmmpi .and. 
     &                                           .not.NORTH_INTER)) then
        vbar(Istr-1,Jend+1,knew)=0.5D0*( vbar(Istr-1,Jend,knew)
     &                                +vbar(Istr,Jend+1,knew))
     &                         *vmask(Istr-1,Jend+1)
      endif
      if ((iend.eq.Lmmpi .and. .not.EAST_INTER) .and. (jend.eq.Mmmpi 
     &                                     .and. .not.NORTH_INTER)) then
        vbar(Iend+1,Jend+1,knew)=0.5D0*( vbar(Iend+1,Jend,knew)
     &                                +vbar(Iend,Jend+1,knew))
     &                         *vmask(Iend+1,Jend+1)
      endif
!$acc end kernels
      return
       
      

      end subroutine Sub_Loop_v2dbc_parent_tile

      subroutine v2dbc_child_tile (Istr,Iend,Jstr,Jend,grad)      


      use Agrif_Util
      interface
        subroutine Sub_Loop_v2dbc_child_tile(Istr,Iend,Jstr,Jend,grad,pa
     &dd_X,Lm,padd_E,Mm,vbarbry_east,vbarbry_west,vbarbry_north,vmask,vb
     &arbry_south,knew,vbar,tauM_out,tauM_in,dtfast,A1dXI,A1dETA,NORTH_I
     &NTER,SOUTH_INTER,EAST_INTER,WEST_INTER,Mmmpi,Lmmpi,N3dHz,N3d,N2d)
          implicit none
      integer(4), parameter :: LLm0 = 41
      integer(4), parameter :: MMm0 = 42
      integer(4), parameter :: N = 32
      integer(4), parameter :: N_sl = 0
      integer(4), parameter :: NP_XI = 1
      integer(4), parameter :: NP_ETA = 4
      integer(4), parameter :: NNODES = NP_XI*NP_ETA
      integer(4), parameter :: NPP = 1
      integer(4), parameter :: NSUB_X = 1
      integer(4), parameter :: NSUB_E = 1
      integer(4), parameter :: NWEIGHT = 1000
      integer(4), parameter :: Ntides = 8
      integer(4), parameter :: stdout = 6
      integer(4), parameter :: Np = N+1
      integer(4), parameter :: NpHz = (N+1+N_sl)
      integer(4), parameter :: NSA = 28
      real, parameter :: Vtransform = 2
      integer(4), parameter :: itemp = 1
      integer(4), parameter :: ntrc_temp = 1
      integer(4), parameter :: ntrc_salt = 1
      integer(4), parameter :: ntrc_pas = 0
      integer(4), parameter :: ntrc_bio = 0
      integer(4), parameter :: ntrc_subs = 0
      integer(4), parameter :: ntrc_substot = 0
      integer(4), parameter :: ntrc_sed = 0
      integer(4), parameter :: NTA = itemp+ntrc_salt
      integer(4), parameter :: NT = itemp+ntrc_salt+ntrc_pas+ntrc_bio+nt
     &rc_sed
      integer(4), parameter :: NTot = NT
      integer(4), parameter :: isalt = itemp+1
      integer(4), parameter :: ntrc_diabio = 0
      integer(4), parameter :: ntrc_diats = 0
      integer(4), parameter :: ntrc_diauv = 0
      integer(4), parameter :: ntrc_diavrt = 0
      integer(4), parameter :: ntrc_diaek = 0
      integer(4), parameter :: ntrc_diapv = 0
      integer(4), parameter :: ntrc_diaeddy = 0
      integer(4), parameter :: ntrc_surf = 0
      real, parameter :: eps = 1.D-20
      real, parameter :: pi = 3.14159265358979323846D0
      real, parameter :: deg2rad = pi/180.D0
      real, parameter :: rad2deg = 180.D0/pi
      real, parameter :: Eradius = 6371315.0D0
      real, parameter :: Erotation = 7.292115090D-5
      real, parameter :: day2sec = 86400.D0
      real, parameter :: sec2day = 1.D0/86400.D0
      real, parameter :: year2day = 365.25D0
      real, parameter :: day2year = 1.D0/365.25D0
      real, parameter :: jul_off = 2440000.D0
      real, parameter :: g = 9.81D0
      real, parameter :: Cp = 3985.0D0
      real, parameter :: vonKar = 0.41D0
      real, parameter :: spval = -999.0D0
      logical, parameter :: mask_val = .true.
      integer(4) :: padd_X
      integer(4) :: Lm
      integer(4) :: padd_E
      integer(4) :: Mm
      integer(4) :: knew
      real :: tauM_out
      real :: tauM_in
      real :: dtfast
      logical :: NORTH_INTER
      logical :: SOUTH_INTER
      logical :: EAST_INTER
      logical :: WEST_INTER
      integer(4) :: Mmmpi
      integer(4) :: Lmmpi
      integer(4) :: N3dHz
      integer(4) :: N3d
      integer(4) :: N2d
      real, dimension(-1:Mm+2+padd_E) :: vbarbry_east
      real, dimension(-1:Mm+2+padd_E) :: vbarbry_west
      real, dimension(-1:Lm+2+padd_X) :: vbarbry_north
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E) :: vmask
      real, dimension(-1:Lm+2+padd_X) :: vbarbry_south
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E,1:4) :: vbar
      real, dimension(-1:Lm+2+padd_X,1:10*NWEIGHT) :: A1dXI
      real, dimension(-1:Mm+2+padd_E,1:10*NWEIGHT) :: A1dETA
      integer(4) :: Istr
      integer(4) :: Iend
      integer(4) :: Jstr
      integer(4) :: Jend
      real, dimension(Istr-2:Iend+2,Jstr-2:Jend+2) :: grad
        end subroutine Sub_Loop_v2dbc_child_tile

      end interface
      integer(4) :: Istr
      integer(4) :: Iend
      integer(4) :: Jstr
      integer(4) :: Jend
      real, dimension(Istr-2:Iend+2,Jstr-2:Jend+2) :: grad
      

        call Sub_Loop_v2dbc_child_tile(Istr,Iend,Jstr,Jend,grad, Agrif_t
     &abvars_i(13)%iarray0, Agrif_tabvars_i(2)%iarray0, Agrif_tabvars_i(
     &14)%iarray0, Agrif_tabvars_i(4)%iarray0, Agrif_tabvars(207)%array1
     &, Agrif_tabvars(219)%array1, Agrif_tabvars(183)%array1, Agrif_tabv
     &ars(91)%array2, Agrif_tabvars(195)%array1, Agrif_tabvars_i(150)%ia
     &rray0, Agrif_tabvars(86)%array3, Agrif_tabvars_r(34)%array0, Agrif
     &_tabvars_r(33)%array0, Agrif_tabvars_r(4)%array0, Agrif_tabvars(39
     &)%array2, Agrif_tabvars(38)%array2, Agrif_tabvars_l(13)%larray0, A
     &grif_tabvars_l(14)%larray0, Agrif_tabvars_l(11)%larray0, Agrif_tab
     &vars_l(12)%larray0, Agrif_tabvars_i(8)%iarray0, Agrif_tabvars_i(7)
     &%iarray0, Agrif_tabvars_i(17)%iarray0, Agrif_tabvars_i(16)%iarray0
     &, Agrif_tabvars_i(15)%iarray0)

      end


      subroutine Sub_Loop_v2dbc_child_tile(Istr,Iend,Jstr,Jend,grad,padd
     &_X,Lm,padd_E,Mm,vbarbry_east,vbarbry_west,vbarbry_north,vmask,vbar
     &bry_south,knew,vbar,tauM_out,tauM_in,dtfast,A1dXI,A1dETA,NORTH_INT
     &ER,SOUTH_INTER,EAST_INTER,WEST_INTER,Mmmpi,Lmmpi,N3dHz,N3d,N2d)

      use Agrif_Types, only : Agrif_tabvars

      implicit none

      integer(4), parameter :: LLm0 = 41
      integer(4), parameter :: MMm0 = 42
      integer(4), parameter :: N = 32
      integer(4), parameter :: N_sl = 0
      integer(4), parameter :: NP_XI = 1
      integer(4), parameter :: NP_ETA = 4
      integer(4), parameter :: NNODES = NP_XI*NP_ETA
      integer(4), parameter :: NPP = 1
      integer(4), parameter :: NSUB_X = 1
      integer(4), parameter :: NSUB_E = 1
      integer(4), parameter :: NWEIGHT = 1000
      integer(4), parameter :: Ntides = 8
      integer(4), parameter :: stdout = 6
      integer(4), parameter :: Np = N+1
      integer(4), parameter :: NpHz = (N+1+N_sl)
      integer(4), parameter :: NSA = 28
      real, parameter :: Vtransform = 2
      integer(4), parameter :: itemp = 1
      integer(4), parameter :: ntrc_temp = 1
      integer(4), parameter :: ntrc_salt = 1
      integer(4), parameter :: ntrc_pas = 0
      integer(4), parameter :: ntrc_bio = 0
      integer(4), parameter :: ntrc_subs = 0
      integer(4), parameter :: ntrc_substot = 0
      integer(4), parameter :: ntrc_sed = 0
      integer(4), parameter :: NTA = itemp+ntrc_salt
      integer(4), parameter :: NT = itemp+ntrc_salt+ntrc_pas+ntrc_bio+nt
     &rc_sed
      integer(4), parameter :: NTot = NT
      integer(4), parameter :: isalt = itemp+1
      integer(4), parameter :: ntrc_diabio = 0
      integer(4), parameter :: ntrc_diats = 0
      integer(4), parameter :: ntrc_diauv = 0
      integer(4), parameter :: ntrc_diavrt = 0
      integer(4), parameter :: ntrc_diaek = 0
      integer(4), parameter :: ntrc_diapv = 0
      integer(4), parameter :: ntrc_diaeddy = 0
      integer(4), parameter :: ntrc_surf = 0
      real, parameter :: eps = 1.D-20
      real, parameter :: pi = 3.14159265358979323846D0
      real, parameter :: deg2rad = pi/180.D0
      real, parameter :: rad2deg = 180.D0/pi
      real, parameter :: Eradius = 6371315.0D0
      real, parameter :: Erotation = 7.292115090D-5
      real, parameter :: day2sec = 86400.D0
      real, parameter :: sec2day = 1.D0/86400.D0
      real, parameter :: year2day = 365.25D0
      real, parameter :: day2year = 1.D0/365.25D0
      real, parameter :: jul_off = 2440000.D0
      real, parameter :: g = 9.81D0
      real, parameter :: Cp = 3985.0D0
      real, parameter :: vonKar = 0.41D0
      real, parameter :: spval = -999.0D0
      logical, parameter :: mask_val = .true.
      integer(4) :: padd_X
      integer(4) :: Lm
      integer(4) :: padd_E
      integer(4) :: Mm
      integer(4) :: knew
      real :: tauM_out
      real :: tauM_in
      real :: dtfast
      logical :: NORTH_INTER
      logical :: SOUTH_INTER
      logical :: EAST_INTER
      logical :: WEST_INTER
      integer(4) :: Mmmpi
      integer(4) :: Lmmpi
      integer(4) :: N3dHz
      integer(4) :: N3d
      integer(4) :: N2d
      real, dimension(-1:Mm+2+padd_E) :: vbarbry_east
      real, dimension(-1:Mm+2+padd_E) :: vbarbry_west
      real, dimension(-1:Lm+2+padd_X) :: vbarbry_north
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E) :: vmask
      real, dimension(-1:Lm+2+padd_X) :: vbarbry_south
      real, dimension(-1:Lm+2+padd_X,-1:Mm+2+padd_E,1:4) :: vbar
      real, dimension(-1:Lm+2+padd_X,1:10*NWEIGHT) :: A1dXI
      real, dimension(-1:Mm+2+padd_E,1:10*NWEIGHT) :: A1dETA
      integer(4) :: Istr
      integer(4) :: Iend
      integer(4) :: Jstr
      integer(4) :: Jend
      real, dimension(Istr-2:Iend+2,Jstr-2:Jend+2) :: grad

                   

                                            
                             
                                            

                                                             
                     
                        

                                                            
                                           
                                                               
                                    
                                      
                                                          

                       

                                    

                        
                              

                       
                          

                                                
                                             
                          

                        

                                 

                                                
                        

                                                              
                      
                              

                                       
                                                                     
                                          
                         

                             

                             

                            

                            

                                             

                            

                                     

                                                               

                         

                                                      
                                                      
                                                                  
                               

                               

                              

                              

                               

                              

                              

                                

                             

                                         
      integer(4) :: i
      integer(4) :: j
                                                
                                                                       
                                                                 
               
                                 
                                            
                                      
                    
      integer(4) :: trd
C$    integer*4 omp_get_thread_num
                                                                       
                                                                 
                 
      real :: cff
      real :: cx
      real :: cy
      real :: v_str
      real :: dft
      real :: dfx
      real :: dfy
      real :: tau
      real :: tau_in
      real :: tau_out
      real :: hx
      real :: zx
                            

                           
                                    
                       
                                             
                                                                       
                                                                 
         
                     
                                          
                                                                       
                                                                       
                                                                 
                                                      
                                
                                            
                                                 
                                                             
                                           
                                                    
                                 
                                      
                                
                                            
                                                 
                                                             
                                           
                                                    
                                 
                                      
                                 
                                              
                                                   
                                                                
                                             
                                                       
                                  
                                        
                                 
                                              
                                                   
                                                                
                                             
                                                       
                                  
                                        
                                                                       
                                                                 
              
                                                           
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                                
                                                                       
                                                                 
                                                                 
                              
                                                                       
                                                                 
                              
                                                                       
                                                                 
                   
                                                  
                                                                       
                                                                 
              
                                                           
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                                
                                                                       
                                                                 
                                                                 
                              
                                                                       
                                                                 
                              
                                                                       
                                                                 
                  
                                                  
                                                                       
                                                                 
                
                                                              
                                                                       
                                                                 
                                                                 
                                      
                                                                       
                                                                 
                                                      
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                    
                                                                       
                                                                 
                    
                                                     
                                                                       
                                                                 
                
                                                              
                                                                       
                                                                 
                                                                 
                                      
                                                                       
                                                                 
                                                      
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                    
                                                                       
                                                                 
                    
                                                     
                                              
                             
                                            
                                               
                                            
                                               
                                                                 
                                                 
                                 
                                               
                                               
                                               
                                               
                                               
                                               
                                             
                                             
                                             
                                             
                                             
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                              
                                                  
                                                  
                                                  
                                                  
                                                 
                                                 
                                               
                                               
                                                      
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                           
                                                           
                                                           
                                    
                                                
                                                
                                                
                                                
                                                 
                           
                           
                           
                           
                             
                                              
                          
                                                 
                                                 
                                                 
                              
                              
                              
                                                                  
                                                                       
                                                                 
                                 
                                
                                                                       
                                                                 
                                                                 
                                                                 
                                                        
                                                                       
                                                                 
                                                                 
            
                                              
                                                   
                     
                              
                               
                                 
                                                  
                                                                       
                                                                 
                                                                 
                        
                      
                           
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                    
                           
                                      
                             
                                                 
                                                                       
                                                                 
                     
                                                      
                                                                       
                                                                 
              
                                          
                                                                       
                                                                 
       
                                                           
      real(8) :: Cu_Nbq_X
      real(8) :: Cu_Nbq_Y
      real(8) :: Cu_Nbq_Z
                                             
                                                                       
                                                                 
              
                                                  
                                                                       
                                                                 
              
                                  
                                           
                                                  
                                                                   
                                                               
                                                      
                                                                       
                                                                 
                      
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                        
                                
                                                                       
                                                                 
                                                        

                                                                       
                                                                 
                  
                                                                       
                                                                 
                                                                 
                                                                 
                  

                          

              
                             

                  
                               

                 
                                

                       
                                   

                                                
                                                
                                                     
                                                   
                                                   
                                                         
                                                
                                   
                                                    
                                              
                                     
                                                
                                              
                                            
                                                           
                                                     
                           
                                  
                                                
                                                
                                                     
                                                   
                                                   
                                                         
                                                           
                                                         
                                                              
                                                           
                                                                
                                                                   
                                                                    
                                                                   
                                                   
                                 
                                                      
                                   
                                        
                                        
                                                       
                                                     
                                             
                                                               
                                              
                                                           
                                        
                                                   
                                 
                                               
                               
                                              
                             
                                                  
                                                 
                                                   
                                             
                                 
                                                              
                                                  
                                             
                                                                    
                                          
                                                                   
                                                   
                                              
                             
                                                 
                               
                                 
                     
                                                              
                                     
                                             
                                                                       
                                                                 
 
                                                                   
                                           
                                                
                                 
                                                  
                                                  
                                                  
                                                   
                                                   
                                   
                                 
                                
                                           
                                         
                                             
                                                              
                                              
                                                                       
                                             
                              
                                          
                              
                                          
                              
                                                       
                              
                                                      
                              
                                                      
                              
                                              
                               
                                           
                               
                                           
                               
                                                        
                               
                                                       
                               
                                                       
                               
                                              
                                                        
                                            
                                                   
                                            
                                                   
                           
                                  
                           
                                  
                           
                                  
                                        
                               
                                                           
                                        
                          
                                                       
                                             
                         
                                   
                                                    
                                                    
                                
                                                    
                                 
                                                    
                                                   
                                                   
                                                  
                                                               
                                           
                                                     
                                                     
                                                       
                                                        
                                                           
                                                       
                                                       
                                           
                                                            
                                  
                                                            
                               
                                                            
                               
                                                     
                                            
                                                  
                                            
                                                  
                                            
                                                  
                                            
                                                                
                                            
                                                             
                                            
                                                             
                                            
                                                             
                                            
                                                      
                                             
                                                   
                                             
                                                   
                                             
                                                   
                                             
                                                                 
                                             
                                                              
                                             
                                                              
                                             
                                                              
                                             
                                          
                                                           
                                            
                                             
                                     
                                                    
                                                      
                                                                       
                                                                 
                                           
                                                    
                                                      
                                               
                                                            
                                           
                                
                                
                             
                                                                       
                                                                 
             
                                                      
                        
                                                          
                                                                       
                                                                 
                                              
                                                         
                                               
                                                
                                           
                                           
                                                                       
                                                                 
                                                                 
                                                                 
                         
!$AGRIF_DO_NOT_TREAT
      integer*4 :: iind
      integer*4 :: sortedint(0:10000)
      integer*4 :: whichstep(0:10000)
      integer*4 :: grids_at_level(0:20,0:100)
      integer*4 :: parent_grid(0:20)
      integer*4 :: coeff_ref_time(0:20)
      integer*4 :: nbtimes, nbmaxtimes
      common/rootintegrate/nbtimes, nbmaxtimes,
     &    iind,sortedint,whichstep,
     &    grids_at_level,parent_grid,coeff_ref_time
!$AGRIF_END_DO_NOT_TREAT
                                        
      integer(4) :: IstrR
      integer(4) :: IendR
      integer(4) :: JstrR
      integer(4) :: JendR
                      
      integer(4) :: IstrU
                      
      integer(4) :: JstrV
      if ((istr.eq.1 .and. .not.WEST_INTER)) then
        IstrR=Istr-1
        IstrU=Istr+1
      else
        IstrR=Istr
        IstrU=Istr
      endif
      if ((iend.eq.Lmmpi .and. .not.EAST_INTER)) then
        IendR=Iend+1
      else
        IendR=Iend
      endif
      if ((jstr.eq.1.and. .not.SOUTH_INTER)) then
        JstrR=Jstr-1
        JstrV=Jstr+1
      else
        JstrR=Jstr
        JstrV=Jstr
      endif
      if ((jend.eq.Mmmpi .and. .not.NORTH_INTER)) then
        JendR=Jend+1
      else
        JendR=Jend
      endif
      trd=0
C$    trd=omp_get_thread_num()
      call v2dbc_interp_tile(Istr,Iend,Jstr,Jend
     &                    ,A1dETA(1,1)
     &                    ,A1dETA(1,2+NWEIGHT)
     &                    ,A1dETA(1,3+2*NWEIGHT)
     &                    ,A1dETA(1,4+2*NWEIGHT)
     &                    ,A1dXI(1,1)
     &                    ,A1dXI(1,2+NWEIGHT)
     &                    ,A1dXI(1,3+2*NWEIGHT)
     &                    ,A1dXI(1,4+2*NWEIGHT))
!$acc kernels if(compute_on_device) default(present) async(1)
      tau_in=dtfast*tauM_in
      tau_out=dtfast*tauM_out
      if ((jstr.eq.1.and. .not.SOUTH_INTER)) then
        do i=Istr,Iend
          vbar(i,Jstr,knew)=vbarbry_south(i)
     &                      *vmask(i,Jstr)
        enddo
      endif
      if ((jend.eq.Mmmpi .and. .not.NORTH_INTER)) then
        do i=Istr,Iend
          vbar(i,Jend+1,knew)=vbarbry_north(i)
     &                        *vmask(i,Jend+1)
        enddo
      endif
      if ((istr.eq.1 .and. .not.WEST_INTER)) then
       do j=JstrV,Jend
          vbar(Istr-1,j,knew)=vbarbry_west(j)
     &                        *vmask(Istr-1,j)
        enddo
      endif
      if ((iend.eq.Lmmpi .and. .not.EAST_INTER)) then
        do j=JstrV,Jend
          vbar(Iend+1,j,knew)=vbarbry_east(j)
     &                        *vmask(Iend+1,j)
        enddo
      endif
      if ((istr.eq.1 .and. .not.WEST_INTER) .and. (jstr.eq.1.and. 
     &                                           .not.SOUTH_INTER)) then
        vbar(Istr-1,Jstr,knew)=0.5D0*( vbar(Istr-1,Jstr+1,knew)
     &                              +vbar(Istr  ,Jstr  ,knew))
     &                         *vmask(Istr-1,Jstr)
      endif
      if ((iend.eq.Lmmpi .and. .not.EAST_INTER) .and. (jstr.eq.1.and. 
     &                                           .not.SOUTH_INTER)) then
        vbar(Iend+1,Jstr,knew)=0.5D0*( vbar(Iend+1,Jstr+1,knew)
     &                              +vbar(Iend  ,Jstr  ,knew))
     &                         *vmask(Iend+1,Jstr)
      endif
      if ((istr.eq.1 .and. .not.WEST_INTER) .and. (jend.eq.Mmmpi .and. 
     &                                           .not.NORTH_INTER)) then
        vbar(Istr-1,Jend+1,knew)=0.5D0*( vbar(Istr-1,Jend,knew)
     &                                +vbar(Istr,Jend+1,knew))
     &                         *vmask(Istr-1,Jend+1)
      endif
      if ((iend.eq.Lmmpi .and. .not.EAST_INTER) .and. (jend.eq.Mmmpi 
     &                                     .and. .not.NORTH_INTER)) then
        vbar(Iend+1,Jend+1,knew)=0.5D0*( vbar(Iend+1,Jend,knew)
     &                                +vbar(Iend,Jend+1,knew))
     &                         *vmask(Iend+1,Jend+1)
      endif
!$acc end kernels
      return
       
      

      end subroutine Sub_Loop_v2dbc_child_tile

