










      subroutine step()      


      use Agrif_Util
      interface
        subroutine Sub_Loop_step(nbstep3d,nfast,iif,Mmmpi,padd_X,Lm,Lmmp
     &i,padd_E,Mm)
          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 :: 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.
      real, parameter :: qp2 = 0.0000172D0
      integer(4) :: nbstep3d
      integer(4) :: nfast
      integer(4) :: iif
      integer(4) :: Mmmpi
      integer(4) :: padd_X
      integer(4) :: Lm
      integer(4) :: Lmmpi
      integer(4) :: padd_E
      integer(4) :: Mm
        end subroutine Sub_Loop_step

      end interface
      

        call Sub_Loop_step( Agrif_tabvars_i(156)%iarray0, Agrif_tabvars_
     &i(161)%iarray0, Agrif_tabvars_i(152)%iarray0, Agrif_tabvars_i(8)%i
     &array0, Agrif_tabvars_i(13)%iarray0, Agrif_tabvars_i(2)%iarray0, A
     &grif_tabvars_i(7)%iarray0, Agrif_tabvars_i(14)%iarray0, Agrif_tabv
     &ars_i(4)%iarray0)

      end


      subroutine Sub_Loop_step(nbstep3d,nfast,iif,Mmmpi,padd_X,Lm,Lmmpi,
     &padd_E,Mm)

      use Agrif_Util

      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 :: 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.
      real, parameter :: qp2 = 0.0000172D0
      integer(4) :: nbstep3d
      integer(4) :: nfast
      integer(4) :: iif
      integer(4) :: Mmmpi
      integer(4) :: padd_X
      integer(4) :: Lm
      integer(4) :: Lmmpi
      integer(4) :: padd_E
      integer(4) :: Mm

                   

                                            
                             
                                            

                                                             
                     
                        

                                                            
                                           
                                                               
                                    
                                      
                                                          

                       

                                    

                        
                              

                       
                          

                                                
                                             
                          

                        

                                 

                                                
                        

                                                              
                      
                              

                                       
                                                                     
                                          
                         

                             

                             

                            

                            

                                             

                            

                                     

                                                               

                         

                                                      
                                                      
                                                                  
                               

                               

                              

                              

                               

                              

                              

                                

                             

                                                                  
                                                                       
                                                                 
                                 
                                
                                                                       
                                                                 
                                                                 
                                                                 
                                                        
                                                                       
                                                                 
                                                                 
            
                                              
                                                   
                     
                              
                               
                                 
                                                  
                                                                       
                                                                 
                                                                 
                        
                      
                           
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                    
                           
                                      
                             
                                                 
                                                                       
                                                                 
                     
                                                      
                                                                       
                                                                 
              
                                          
                                                                       
                                                                 
       
                                                           
      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
                                            
                                               
                                            
                                               
                                                                 
                                                 
                                 
                                               
                                               
                                               
                                               
                                               
                                               
                                             
                                             
                                             
                                             
                                             
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                              
                                                  
                                                  
                                                  
                                                  
                                                 
                                                 
                                               
                                               
                                                      
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                           
                                                           
                                                           
                                    
                                                
                                                
                                                
                                                
                                                 
                           
                           
                           
                           
                             
                                              
                          
                                               
                                               
                                                       
                                                
                                                
                                                      
                                                      
                               
                               
                                       
                                       
                                                  
                                                    
                                                    
                                                  
                                                  
                                    
                                   
                                   
                                   
                                   
                                                
                                                
                                                   
                                              
                                               
                                                   
                                                
                                                  
                                                 
                                                 
                                                              
                             
                                                 
                                                  
                                                 
                                                
                                             
                                                
                            
               
                                 

                                                 
                                                 
                                                 
                              
                              
                              
!$AGRIF_DO_NOT_TREAT
      INTEGER*4 :: ocean_grid_comm
      common /cpl_comm/ ocean_grid_comm
!$AGRIF_END_DO_NOT_TREAT
      IF (agrif_fixed().NE.sortedint(nbtimes)) return
      nbtimes = nbtimes + 1
       iif = iif+1
      IF (iif .EQ. 0) then
C$OMP PARALLEL
        call prestep3D_thread()
C$OMP END PARALLEL
      endif
      IF ((iif.GT.0).AND.(iif.LT.(nfast+1))) THEN
C$OMP PARALLEL
        call step2d_thread()
C$OMP END PARALLEL
      ENDIF
      IF (iif .EQ. (nfast+1)) then
C$OMP PARALLEL
        call step3D_uv_thread()
C$OMP END PARALLEL
      endif
      IF (iif .EQ. (nfast + 2)) then
C$OMP PARALLEL
        call step3D_t_thread()
C$OMP END PARALLEL
        iif = -1
        nbstep3d = nbstep3d + 1
      endif
      return
       
      

      end subroutine Sub_Loop_step

      subroutine prestep3D_thread()      

      use Agrif_Util
      interface
        subroutine Sub_Loop_prestep3D_thread(may_day_flag,synchro_flag,n
     &new,nrhs,nstp,tdays,ntstart,iic,dt,time_start,time,padd_E,Mm,padd_
     &X,Lm)
          use Agrif_Util
          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 :: 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), parameter :: filetype_his = 1
      integer(4), parameter :: filetype_avg = 2
      integer(4), parameter :: filetype_dia = 3
      integer(4), parameter :: filetype_dia_avg = 4
      integer(4), parameter :: filetype_diaM = 5
      integer(4), parameter :: filetype_diaM_avg = 6
      integer(4), parameter :: filetype_diags_vrt = 7
      integer(4), parameter :: filetype_diags_vrt_avg = 8
      integer(4), parameter :: filetype_diags_ek = 9
      integer(4), parameter :: filetype_diags_ek_avg = 10
      integer(4), parameter :: filetype_diags_pv = 11
      integer(4), parameter :: filetype_diags_pv_avg = 12
      integer(4), parameter :: filetype_diags_eddy_avg = 17
      integer(4), parameter :: filetype_surf = 13
      integer(4), parameter :: filetype_surf_avg = 14
      integer(4), parameter :: filetype_diabio = 15
      integer(4), parameter :: filetype_diabio_avg = 16
      integer(4), parameter :: filetype_abl = 18
      integer(4), parameter :: filetype_abl_avg = 19
      integer(4), parameter :: indxTime = 1
      integer(4), parameter :: indxZ = 2
      integer(4), parameter :: indxUb = 3
      integer(4), parameter :: indxVb = 4
      integer(4), parameter :: indxU = 6
      integer(4), parameter :: indxV = 7
      integer(4), parameter :: indxT = indxV+1
      integer(4), parameter :: indxS = indxV+ntrc_temp+1
      integer(4), parameter :: indxBSD = indxV+ntrc_temp+ntrc_salt+ntrc_
     &pas+ntrc_bio+1
      integer(4), parameter :: indxBSS = 101
      integer(4), parameter :: indxO = indxV+ntrc_temp+ntrc_salt+ntrc_pa
     &s+ntrc_bio+ntrc_sed+ntrc_substot+ntrc_diats+ntrc_diauv+ntrc_diavrt
     &+ntrc_diaek+ntrc_diapv+ntrc_diaeddy+ntrc_surf+ntrc_diabio+1
      integer(4), parameter :: indxW = indxO+1
      integer(4), parameter :: indxR = indxO+2
      integer(4), parameter :: indxVisc = indxO+3
      integer(4), parameter :: indxDiff = indxO+4
      integer(4), parameter :: indxAkv = indxO+5
      integer(4), parameter :: indxAkt = indxO+6
      integer(4), parameter :: indxAks = indxAkv+ntrc_temp+4
      integer(4), parameter :: indxHbl = indxAkv+ntrc_temp+5
      integer(4), parameter :: indxHbbl = indxAkv+ntrc_temp+6
      integer(4), parameter :: indxSSH = indxAkv+ntrc_temp+12
      integer(4), parameter :: indxbvf = indxSSH+1
      integer(4), parameter :: indxSUSTR = indxSSH+2
      integer(4), parameter :: indxSVSTR = indxSSH+3
      integer(4), parameter :: indxTime2 = indxSSH+4
      integer(4), parameter :: indxShflx = indxSUSTR+5
      integer(4), parameter :: indxSwflx = indxShflx+1
      integer(4), parameter :: indxShflx_rsw = indxShflx+2
      integer(4), parameter :: indxSST = indxShflx_rsw+1
      integer(4), parameter :: indxdQdSST = indxShflx_rsw+2
      integer(4), parameter :: indxSSS = indxSST+2
      integer(4), parameter :: indxWstr = indxSUSTR+23
      integer(4), parameter :: indxUWstr = indxSUSTR+24
      integer(4), parameter :: indxVWstr = indxSUSTR+25
      integer(4), parameter :: indxBostr = indxSUSTR+26
      integer(4), parameter :: indxBustr = indxSUSTR+27
      integer(4), parameter :: indxBvstr = indxBustr+1
      integer(4), parameter :: indxWWA = indxSUSTR+42
      integer(4), parameter :: indxWWD = indxWWA+1
      integer(4), parameter :: indxWWP = indxWWA+2
      integer(4), parameter :: r2dvar = 0
      integer(4), parameter :: u2dvar = 1
      integer(4), parameter :: v2dvar = 2
      integer(4), parameter :: p2dvar = 3
      integer(4), parameter :: r3dvar = 4
      integer(4), parameter :: u3dvar = 5
      integer(4), parameter :: v3dvar = 6
      integer(4), parameter :: p3dvar = 7
      integer(4), parameter :: w3dvar = 8
      integer(4), parameter :: pw3dvar = 11
      integer(4), parameter :: b3dvar = 12
      real, parameter :: qp2 = 0.0000172D0
      integer(4) :: may_day_flag
      logical :: synchro_flag
      integer(4) :: nnew
      integer(4) :: nrhs
      integer(4) :: nstp
      real :: tdays
      integer(4) :: ntstart
      integer(4) :: iic
      real :: dt
      real :: time_start
      real :: time
      integer(4) :: padd_E
      integer(4) :: Mm
      integer(4) :: padd_X
      integer(4) :: Lm
        end subroutine Sub_Loop_prestep3D_thread

      end interface
      

        call Sub_Loop_prestep3D_thread( Agrif_tabvars_i(167)%iarray0, Ag
     &rif_tabvars_l(6)%larray0, Agrif_tabvars_i(155)%iarray0, Agrif_tabv
     &ars_i(154)%iarray0, Agrif_tabvars_i(153)%iarray0, Agrif_tabvars_r(
     &8)%array0, Agrif_tabvars_i(158)%iarray0, Agrif_tabvars_i(147)%iarr
     &ay0, Agrif_tabvars_r(3)%array0, Agrif_tabvars_r(7)%array0, Agrif_t
     &abvars_r(5)%array0, Agrif_tabvars_i(14)%iarray0, Agrif_tabvars_i(4
     &)%iarray0, Agrif_tabvars_i(13)%iarray0, Agrif_tabvars_i(2)%iarray0
     &)

      end


      subroutine Sub_Loop_prestep3D_thread(may_day_flag,synchro_flag,nne
     &w,nrhs,nstp,tdays,ntstart,iic,dt,time_start,time,padd_E,Mm,padd_X,
     &Lm)

      use Agrif_Types, only : Agrif_tabvars

      use Agrif_Util
      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 :: 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), parameter :: filetype_his = 1
      integer(4), parameter :: filetype_avg = 2
      integer(4), parameter :: filetype_dia = 3
      integer(4), parameter :: filetype_dia_avg = 4
      integer(4), parameter :: filetype_diaM = 5
      integer(4), parameter :: filetype_diaM_avg = 6
      integer(4), parameter :: filetype_diags_vrt = 7
      integer(4), parameter :: filetype_diags_vrt_avg = 8
      integer(4), parameter :: filetype_diags_ek = 9
      integer(4), parameter :: filetype_diags_ek_avg = 10
      integer(4), parameter :: filetype_diags_pv = 11
      integer(4), parameter :: filetype_diags_pv_avg = 12
      integer(4), parameter :: filetype_diags_eddy_avg = 17
      integer(4), parameter :: filetype_surf = 13
      integer(4), parameter :: filetype_surf_avg = 14
      integer(4), parameter :: filetype_diabio = 15
      integer(4), parameter :: filetype_diabio_avg = 16
      integer(4), parameter :: filetype_abl = 18
      integer(4), parameter :: filetype_abl_avg = 19
      integer(4), parameter :: indxTime = 1
      integer(4), parameter :: indxZ = 2
      integer(4), parameter :: indxUb = 3
      integer(4), parameter :: indxVb = 4
      integer(4), parameter :: indxU = 6
      integer(4), parameter :: indxV = 7
      integer(4), parameter :: indxT = indxV+1
      integer(4), parameter :: indxS = indxV+ntrc_temp+1
      integer(4), parameter :: indxBSD = indxV+ntrc_temp+ntrc_salt+ntrc_
     &pas+ntrc_bio+1
      integer(4), parameter :: indxBSS = 101
      integer(4), parameter :: indxO = indxV+ntrc_temp+ntrc_salt+ntrc_pa
     &s+ntrc_bio+ntrc_sed+ntrc_substot+ntrc_diats+ntrc_diauv+ntrc_diavrt
     &+ntrc_diaek+ntrc_diapv+ntrc_diaeddy+ntrc_surf+ntrc_diabio+1
      integer(4), parameter :: indxW = indxO+1
      integer(4), parameter :: indxR = indxO+2
      integer(4), parameter :: indxVisc = indxO+3
      integer(4), parameter :: indxDiff = indxO+4
      integer(4), parameter :: indxAkv = indxO+5
      integer(4), parameter :: indxAkt = indxO+6
      integer(4), parameter :: indxAks = indxAkv+ntrc_temp+4
      integer(4), parameter :: indxHbl = indxAkv+ntrc_temp+5
      integer(4), parameter :: indxHbbl = indxAkv+ntrc_temp+6
      integer(4), parameter :: indxSSH = indxAkv+ntrc_temp+12
      integer(4), parameter :: indxbvf = indxSSH+1
      integer(4), parameter :: indxSUSTR = indxSSH+2
      integer(4), parameter :: indxSVSTR = indxSSH+3
      integer(4), parameter :: indxTime2 = indxSSH+4
      integer(4), parameter :: indxShflx = indxSUSTR+5
      integer(4), parameter :: indxSwflx = indxShflx+1
      integer(4), parameter :: indxShflx_rsw = indxShflx+2
      integer(4), parameter :: indxSST = indxShflx_rsw+1
      integer(4), parameter :: indxdQdSST = indxShflx_rsw+2
      integer(4), parameter :: indxSSS = indxSST+2
      integer(4), parameter :: indxWstr = indxSUSTR+23
      integer(4), parameter :: indxUWstr = indxSUSTR+24
      integer(4), parameter :: indxVWstr = indxSUSTR+25
      integer(4), parameter :: indxBostr = indxSUSTR+26
      integer(4), parameter :: indxBustr = indxSUSTR+27
      integer(4), parameter :: indxBvstr = indxBustr+1
      integer(4), parameter :: indxWWA = indxSUSTR+42
      integer(4), parameter :: indxWWD = indxWWA+1
      integer(4), parameter :: indxWWP = indxWWA+2
      integer(4), parameter :: r2dvar = 0
      integer(4), parameter :: u2dvar = 1
      integer(4), parameter :: v2dvar = 2
      integer(4), parameter :: p2dvar = 3
      integer(4), parameter :: r3dvar = 4
      integer(4), parameter :: u3dvar = 5
      integer(4), parameter :: v3dvar = 6
      integer(4), parameter :: p3dvar = 7
      integer(4), parameter :: w3dvar = 8
      integer(4), parameter :: pw3dvar = 11
      integer(4), parameter :: b3dvar = 12
      real, parameter :: qp2 = 0.0000172D0
      integer(4) :: may_day_flag
      logical :: synchro_flag
      integer(4) :: nnew
      integer(4) :: nrhs
      integer(4) :: nstp
      real :: tdays
      integer(4) :: ntstart
      integer(4) :: iic
      real :: dt
      real :: time_start
      real :: time
      integer(4) :: padd_E
      integer(4) :: Mm
      integer(4) :: padd_X
      integer(4) :: Lm

                     
                   

                                            
                             
                                            

                                                             
                     
                        

                                                            
                                           
                                                               
                                    
                                      
                                                          

                       

                                    

                        
                              

                       
                          

                                                
                                             
                          

                        

                                 

                                                
                        

                                                              
                      
                              

                                       
                                                                     
                                          
                         

                             

                             

                            

                            

                                             

                            

                                     

                                                               

                         

                                                      
                                                      
                                                                  
                               

                               

                              

                              

                               

                              

                              

                                

                             

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

                                                                       
                                                                 
                  
                                                                       
                                                                 
                                                                 
                                                                 
                  

                          

              
                             

                  
                               

                 
                                

                       
                                   

                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                      
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                         

                                 
      integer(4) :: iloop
      integer(4) :: indextemp
                                                
                                                         

                             
                                  

                      
                               

                      
                                         

                                 
                                                                       
                                                                 
                              

                                                                       
                                                                 
                                                                 
    
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                 

                        
                                             

                        
                                             

                         
                                              

                        
                                              

                        
                                   

                                     
                                                          

                          
                                     

                                         
                                       

                          
                                                                  

                                    
                                                                     

                        
                                   

                         
                                       

                          
                                        

                          
                                        

                          
                                        

                                     
                                                                

                                                                
      integer(4) :: indxWEB
      integer(4) :: indxWED
      integer(4) :: indxWER
                                                                       
                                                                 
                                                          

                                                                       
                                                                 
                                                                 
            
                                                                       
                                                                 
                                                                 
       

                                           
                                                       
                                                                       
                                                                 
                                                                 
                              
                                                                       
                                                                 
    
                                                                       
                                                                 
                                                                 
                    
                         
                       
                        
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                   
                         
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                      
                         
                                                            
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                       
                                   
                                                                 
                                                                       
                                                                 
                                                                 
                                                                 
                               
                                                                  
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
     
                                    
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
               
                                                 
                                                 
                                                 
                              
                              
                              
                                                
                                                
                                                   
                                              
                                               
                                                   
                                                
                                                  
                                                 
                                                 
                                                              
                             
                                                 
                                                  
                                                 
                                                
                                             
                                                
                            
               
                                 

                      
      integer(4) :: range
                                                                       
                                                                 
 
      integer(4) :: ntrds
      integer(4) :: trd
      integer(4) :: my_first
      integer(4) :: my_last
      integer(4) :: tile
      integer(4) :: my_iif
                     
      integer(4) :: itrc
                                                        
      integer(4) :: omp_get_num_threads
      integer(4) :: omp_get_thread_num
      ntrds=omp_get_num_threads()
      trd=omp_get_thread_num()
C$OMP BARRIER
      range=(NSUB_X*NSUB_E+ntrds-1)/ntrds
      my_first=trd*range
      my_last=min(my_first + range-1, NSUB_X*NSUB_E-1)
C$OMP MASTER
      time=time_start+dt*float(iic-ntstart)
      tdays=time*sec2day
      nstp=1+mod(iic-ntstart,2)
      nrhs=nstp
      nnew=3
      if (synchro_flag) then
        IF (Agrif_Root()) THEN
            call get_bry
        ENDIF
        call get_vbc
        synchro_flag=.false.
      endif
C$OMP END MASTER
C$OMP BARRIER
      if (may_day_flag.ne.0) return
      do tile=my_first,my_last,+1
        IF (Agrif_Root()) THEN
          call set_bry (tile)
        ENDIF
        call rho_eos (tile)
        call set_HUV (tile)
        call diag(tile)
      enddo
C$OMP BARRIER
      do tile=my_last,my_first,-1
        call set_vbc (tile)
        IF (Agrif_Root()) call clm_tides (tile)
      enddo
C$OMP BARRIER
C$OMP BARRIER
      if (may_day_flag.ne.0) return
      do tile=my_first,my_last,+1
        call lmd_vmix (tile)
        call omega (tile)
      enddo
C$OMP BARRIER
      do tile=my_last,my_first,-1
        call prsgrd (tile)
        call rhs3d (tile)
        call pre_step3d (tile)
      if (.Not.Agrif_Root()) then
        call uv3dpremix (tile)
      endif
      enddo
C$OMP BARRIER
      do tile=my_first,my_last,+1
        call uv3dmix_spg (tile)
        call set_avg (tile)
      enddo
C$OMP BARRIER
C$OMP MASTER
      nrhs=3
      nnew=3-nstp
      call output
C$OMP END MASTER
C$OMP BARRIER
      if (may_day_flag.ne.0) return
      return
       
      

      end subroutine Sub_Loop_prestep3D_thread

      subroutine step2D_thread()      

      use Agrif_Util
      interface
        subroutine Sub_Loop_step2D_thread(knew,kstp,padd_E,Mm,padd_X,Lm)
          use Agrif_Util
          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 :: 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), parameter :: filetype_his = 1
      integer(4), parameter :: filetype_avg = 2
      integer(4), parameter :: filetype_dia = 3
      integer(4), parameter :: filetype_dia_avg = 4
      integer(4), parameter :: filetype_diaM = 5
      integer(4), parameter :: filetype_diaM_avg = 6
      integer(4), parameter :: filetype_diags_vrt = 7
      integer(4), parameter :: filetype_diags_vrt_avg = 8
      integer(4), parameter :: filetype_diags_ek = 9
      integer(4), parameter :: filetype_diags_ek_avg = 10
      integer(4), parameter :: filetype_diags_pv = 11
      integer(4), parameter :: filetype_diags_pv_avg = 12
      integer(4), parameter :: filetype_diags_eddy_avg = 17
      integer(4), parameter :: filetype_surf = 13
      integer(4), parameter :: filetype_surf_avg = 14
      integer(4), parameter :: filetype_diabio = 15
      integer(4), parameter :: filetype_diabio_avg = 16
      integer(4), parameter :: filetype_abl = 18
      integer(4), parameter :: filetype_abl_avg = 19
      integer(4), parameter :: indxTime = 1
      integer(4), parameter :: indxZ = 2
      integer(4), parameter :: indxUb = 3
      integer(4), parameter :: indxVb = 4
      integer(4), parameter :: indxU = 6
      integer(4), parameter :: indxV = 7
      integer(4), parameter :: indxT = indxV+1
      integer(4), parameter :: indxS = indxV+ntrc_temp+1
      integer(4), parameter :: indxBSD = indxV+ntrc_temp+ntrc_salt+ntrc_
     &pas+ntrc_bio+1
      integer(4), parameter :: indxBSS = 101
      integer(4), parameter :: indxO = indxV+ntrc_temp+ntrc_salt+ntrc_pa
     &s+ntrc_bio+ntrc_sed+ntrc_substot+ntrc_diats+ntrc_diauv+ntrc_diavrt
     &+ntrc_diaek+ntrc_diapv+ntrc_diaeddy+ntrc_surf+ntrc_diabio+1
      integer(4), parameter :: indxW = indxO+1
      integer(4), parameter :: indxR = indxO+2
      integer(4), parameter :: indxVisc = indxO+3
      integer(4), parameter :: indxDiff = indxO+4
      integer(4), parameter :: indxAkv = indxO+5
      integer(4), parameter :: indxAkt = indxO+6
      integer(4), parameter :: indxAks = indxAkv+ntrc_temp+4
      integer(4), parameter :: indxHbl = indxAkv+ntrc_temp+5
      integer(4), parameter :: indxHbbl = indxAkv+ntrc_temp+6
      integer(4), parameter :: indxSSH = indxAkv+ntrc_temp+12
      integer(4), parameter :: indxbvf = indxSSH+1
      integer(4), parameter :: indxSUSTR = indxSSH+2
      integer(4), parameter :: indxSVSTR = indxSSH+3
      integer(4), parameter :: indxTime2 = indxSSH+4
      integer(4), parameter :: indxShflx = indxSUSTR+5
      integer(4), parameter :: indxSwflx = indxShflx+1
      integer(4), parameter :: indxShflx_rsw = indxShflx+2
      integer(4), parameter :: indxSST = indxShflx_rsw+1
      integer(4), parameter :: indxdQdSST = indxShflx_rsw+2
      integer(4), parameter :: indxSSS = indxSST+2
      integer(4), parameter :: indxWstr = indxSUSTR+23
      integer(4), parameter :: indxUWstr = indxSUSTR+24
      integer(4), parameter :: indxVWstr = indxSUSTR+25
      integer(4), parameter :: indxBostr = indxSUSTR+26
      integer(4), parameter :: indxBustr = indxSUSTR+27
      integer(4), parameter :: indxBvstr = indxBustr+1
      integer(4), parameter :: indxWWA = indxSUSTR+42
      integer(4), parameter :: indxWWD = indxWWA+1
      integer(4), parameter :: indxWWP = indxWWA+2
      integer(4), parameter :: r2dvar = 0
      integer(4), parameter :: u2dvar = 1
      integer(4), parameter :: v2dvar = 2
      integer(4), parameter :: p2dvar = 3
      integer(4), parameter :: r3dvar = 4
      integer(4), parameter :: u3dvar = 5
      integer(4), parameter :: v3dvar = 6
      integer(4), parameter :: p3dvar = 7
      integer(4), parameter :: w3dvar = 8
      integer(4), parameter :: pw3dvar = 11
      integer(4), parameter :: b3dvar = 12
      integer(4) :: knew
      integer(4) :: kstp
      integer(4) :: padd_E
      integer(4) :: Mm
      integer(4) :: padd_X
      integer(4) :: Lm
        end subroutine Sub_Loop_step2D_thread

      end interface
      

        call Sub_Loop_step2D_thread( Agrif_tabvars_i(150)%iarray0, Agrif
     &_tabvars_i(148)%iarray0, Agrif_tabvars_i(14)%iarray0, Agrif_tabvar
     &s_i(4)%iarray0, Agrif_tabvars_i(13)%iarray0, Agrif_tabvars_i(2)%ia
     &rray0)

      end


      subroutine Sub_Loop_step2D_thread(knew,kstp,padd_E,Mm,padd_X,Lm)

      use Agrif_Types, only : Agrif_tabvars

      use Agrif_Util
      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 :: 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), parameter :: filetype_his = 1
      integer(4), parameter :: filetype_avg = 2
      integer(4), parameter :: filetype_dia = 3
      integer(4), parameter :: filetype_dia_avg = 4
      integer(4), parameter :: filetype_diaM = 5
      integer(4), parameter :: filetype_diaM_avg = 6
      integer(4), parameter :: filetype_diags_vrt = 7
      integer(4), parameter :: filetype_diags_vrt_avg = 8
      integer(4), parameter :: filetype_diags_ek = 9
      integer(4), parameter :: filetype_diags_ek_avg = 10
      integer(4), parameter :: filetype_diags_pv = 11
      integer(4), parameter :: filetype_diags_pv_avg = 12
      integer(4), parameter :: filetype_diags_eddy_avg = 17
      integer(4), parameter :: filetype_surf = 13
      integer(4), parameter :: filetype_surf_avg = 14
      integer(4), parameter :: filetype_diabio = 15
      integer(4), parameter :: filetype_diabio_avg = 16
      integer(4), parameter :: filetype_abl = 18
      integer(4), parameter :: filetype_abl_avg = 19
      integer(4), parameter :: indxTime = 1
      integer(4), parameter :: indxZ = 2
      integer(4), parameter :: indxUb = 3
      integer(4), parameter :: indxVb = 4
      integer(4), parameter :: indxU = 6
      integer(4), parameter :: indxV = 7
      integer(4), parameter :: indxT = indxV+1
      integer(4), parameter :: indxS = indxV+ntrc_temp+1
      integer(4), parameter :: indxBSD = indxV+ntrc_temp+ntrc_salt+ntrc_
     &pas+ntrc_bio+1
      integer(4), parameter :: indxBSS = 101
      integer(4), parameter :: indxO = indxV+ntrc_temp+ntrc_salt+ntrc_pa
     &s+ntrc_bio+ntrc_sed+ntrc_substot+ntrc_diats+ntrc_diauv+ntrc_diavrt
     &+ntrc_diaek+ntrc_diapv+ntrc_diaeddy+ntrc_surf+ntrc_diabio+1
      integer(4), parameter :: indxW = indxO+1
      integer(4), parameter :: indxR = indxO+2
      integer(4), parameter :: indxVisc = indxO+3
      integer(4), parameter :: indxDiff = indxO+4
      integer(4), parameter :: indxAkv = indxO+5
      integer(4), parameter :: indxAkt = indxO+6
      integer(4), parameter :: indxAks = indxAkv+ntrc_temp+4
      integer(4), parameter :: indxHbl = indxAkv+ntrc_temp+5
      integer(4), parameter :: indxHbbl = indxAkv+ntrc_temp+6
      integer(4), parameter :: indxSSH = indxAkv+ntrc_temp+12
      integer(4), parameter :: indxbvf = indxSSH+1
      integer(4), parameter :: indxSUSTR = indxSSH+2
      integer(4), parameter :: indxSVSTR = indxSSH+3
      integer(4), parameter :: indxTime2 = indxSSH+4
      integer(4), parameter :: indxShflx = indxSUSTR+5
      integer(4), parameter :: indxSwflx = indxShflx+1
      integer(4), parameter :: indxShflx_rsw = indxShflx+2
      integer(4), parameter :: indxSST = indxShflx_rsw+1
      integer(4), parameter :: indxdQdSST = indxShflx_rsw+2
      integer(4), parameter :: indxSSS = indxSST+2
      integer(4), parameter :: indxWstr = indxSUSTR+23
      integer(4), parameter :: indxUWstr = indxSUSTR+24
      integer(4), parameter :: indxVWstr = indxSUSTR+25
      integer(4), parameter :: indxBostr = indxSUSTR+26
      integer(4), parameter :: indxBustr = indxSUSTR+27
      integer(4), parameter :: indxBvstr = indxBustr+1
      integer(4), parameter :: indxWWA = indxSUSTR+42
      integer(4), parameter :: indxWWD = indxWWA+1
      integer(4), parameter :: indxWWP = indxWWA+2
      integer(4), parameter :: r2dvar = 0
      integer(4), parameter :: u2dvar = 1
      integer(4), parameter :: v2dvar = 2
      integer(4), parameter :: p2dvar = 3
      integer(4), parameter :: r3dvar = 4
      integer(4), parameter :: u3dvar = 5
      integer(4), parameter :: v3dvar = 6
      integer(4), parameter :: p3dvar = 7
      integer(4), parameter :: w3dvar = 8
      integer(4), parameter :: pw3dvar = 11
      integer(4), parameter :: b3dvar = 12
      integer(4) :: knew
      integer(4) :: kstp
      integer(4) :: padd_E
      integer(4) :: Mm
      integer(4) :: padd_X
      integer(4) :: Lm

                     
                   

                                            
                             
                                            

                                                             
                     
                        

                                                            
                                           
                                                               
                                    
                                      
                                                          

                       

                                    

                        
                              

                       
                          

                                                
                                             
                          

                        

                                 

                                                
                        

                                                              
                      
                              

                                       
                                                                     
                                          
                         

                             

                             

                            

                            

                                             

                            

                                     

                                                               

                         

                                                      
                                                      
                                                                  
                               

                               

                              

                              

                               

                              

                              

                                

                             

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

                                                                       
                                                                 
                  
                                                                       
                                                                 
                                                                 
                                                                 
                  

                          

              
                             

                  
                               

                 
                                

                       
                                   

                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                      
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                         

                                 
      integer(4) :: iloop
      integer(4) :: indextemp
                                                
                                                         

                             
                                  

                      
                               

                      
                                         

                                 
                                                                       
                                                                 
                              

                                                                       
                                                                 
                                                                 
    
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                 

                        
                                             

                        
                                             

                         
                                              

                        
                                              

                        
                                   

                                     
                                                          

                          
                                     

                                         
                                       

                          
                                                                  

                                    
                                                                     

                        
                                   

                         
                                       

                          
                                        

                          
                                        

                          
                                        

                                     
                                                                

                                                                
      integer(4) :: indxWEB
      integer(4) :: indxWED
      integer(4) :: indxWER
                                                                       
                                                                 
                                                          

                                                                       
                                                                 
                                                                 
            
                                                                       
                                                                 
                                                                 
       

                                           
                                                       
                                                                       
                                                                 
                                                                 
                              
                                                                       
                                                                 
    
                                                                       
                                                                 
                                                                 
                    
                         
                       
                        
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                   
                         
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                      
                         
                                                            
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                       
                                   
                                                                 
                                                                       
                                                                 
                                                                 
                                                                 
                               
                                                                  
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
     
                                    
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
               
                                                 
                                                 
                                                 
                              
                              
                              
                      
      integer(4) :: range
                                                                       
                                                                 
 
      integer(4) :: ntrds
      integer(4) :: trd
      integer(4) :: my_first
      integer(4) :: my_last
      integer(4) :: tile
      integer(4) :: my_iif
                                                        
      integer(4) :: omp_get_num_threads
      integer(4) :: omp_get_thread_num
      ntrds=omp_get_num_threads()
      trd=omp_get_thread_num()
C$OMP BARRIER
      range=(NSUB_X*NSUB_E+ntrds-1)/ntrds
      my_first=trd*range
      my_last=min(my_first + range-1, NSUB_X*NSUB_E-1)
C$OMP MASTER
        kstp=knew
        knew=kstp+1
        if (knew.gt.4) knew=1
C$OMP END MASTER
C$OMP BARRIER
        if (mod(knew,2).eq.0) then
          do tile=my_last,my_first,-1
            call     step2d (tile)
          enddo
        else
          do tile=my_first,my_last,+1
            call     step2d (tile)
          enddo
        endif
        if (.not.agrif_root()) then
            call update2d()
        endif
      return
       
      

      end subroutine Sub_Loop_step2D_thread

      subroutine step3D_uv_thread()      

      use Agrif_Util
      use debug
      interface
        subroutine Sub_Loop_step3D_uv_thread(Mmmpi,padd_X,Lm,Lmmpi,padd_
     &E,Mm)
          use debug
          use Agrif_Util
          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 :: 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), parameter :: filetype_his = 1
      integer(4), parameter :: filetype_avg = 2
      integer(4), parameter :: filetype_dia = 3
      integer(4), parameter :: filetype_dia_avg = 4
      integer(4), parameter :: filetype_diaM = 5
      integer(4), parameter :: filetype_diaM_avg = 6
      integer(4), parameter :: filetype_diags_vrt = 7
      integer(4), parameter :: filetype_diags_vrt_avg = 8
      integer(4), parameter :: filetype_diags_ek = 9
      integer(4), parameter :: filetype_diags_ek_avg = 10
      integer(4), parameter :: filetype_diags_pv = 11
      integer(4), parameter :: filetype_diags_pv_avg = 12
      integer(4), parameter :: filetype_diags_eddy_avg = 17
      integer(4), parameter :: filetype_surf = 13
      integer(4), parameter :: filetype_surf_avg = 14
      integer(4), parameter :: filetype_diabio = 15
      integer(4), parameter :: filetype_diabio_avg = 16
      integer(4), parameter :: filetype_abl = 18
      integer(4), parameter :: filetype_abl_avg = 19
      integer(4), parameter :: indxTime = 1
      integer(4), parameter :: indxZ = 2
      integer(4), parameter :: indxUb = 3
      integer(4), parameter :: indxVb = 4
      integer(4), parameter :: indxU = 6
      integer(4), parameter :: indxV = 7
      integer(4), parameter :: indxT = indxV+1
      integer(4), parameter :: indxS = indxV+ntrc_temp+1
      integer(4), parameter :: indxBSD = indxV+ntrc_temp+ntrc_salt+ntrc_
     &pas+ntrc_bio+1
      integer(4), parameter :: indxBSS = 101
      integer(4), parameter :: indxO = indxV+ntrc_temp+ntrc_salt+ntrc_pa
     &s+ntrc_bio+ntrc_sed+ntrc_substot+ntrc_diats+ntrc_diauv+ntrc_diavrt
     &+ntrc_diaek+ntrc_diapv+ntrc_diaeddy+ntrc_surf+ntrc_diabio+1
      integer(4), parameter :: indxW = indxO+1
      integer(4), parameter :: indxR = indxO+2
      integer(4), parameter :: indxVisc = indxO+3
      integer(4), parameter :: indxDiff = indxO+4
      integer(4), parameter :: indxAkv = indxO+5
      integer(4), parameter :: indxAkt = indxO+6
      integer(4), parameter :: indxAks = indxAkv+ntrc_temp+4
      integer(4), parameter :: indxHbl = indxAkv+ntrc_temp+5
      integer(4), parameter :: indxHbbl = indxAkv+ntrc_temp+6
      integer(4), parameter :: indxSSH = indxAkv+ntrc_temp+12
      integer(4), parameter :: indxbvf = indxSSH+1
      integer(4), parameter :: indxSUSTR = indxSSH+2
      integer(4), parameter :: indxSVSTR = indxSSH+3
      integer(4), parameter :: indxTime2 = indxSSH+4
      integer(4), parameter :: indxShflx = indxSUSTR+5
      integer(4), parameter :: indxSwflx = indxShflx+1
      integer(4), parameter :: indxShflx_rsw = indxShflx+2
      integer(4), parameter :: indxSST = indxShflx_rsw+1
      integer(4), parameter :: indxdQdSST = indxShflx_rsw+2
      integer(4), parameter :: indxSSS = indxSST+2
      integer(4), parameter :: indxWstr = indxSUSTR+23
      integer(4), parameter :: indxUWstr = indxSUSTR+24
      integer(4), parameter :: indxVWstr = indxSUSTR+25
      integer(4), parameter :: indxBostr = indxSUSTR+26
      integer(4), parameter :: indxBustr = indxSUSTR+27
      integer(4), parameter :: indxBvstr = indxBustr+1
      integer(4), parameter :: indxWWA = indxSUSTR+42
      integer(4), parameter :: indxWWD = indxWWA+1
      integer(4), parameter :: indxWWP = indxWWA+2
      integer(4), parameter :: r2dvar = 0
      integer(4), parameter :: u2dvar = 1
      integer(4), parameter :: v2dvar = 2
      integer(4), parameter :: p2dvar = 3
      integer(4), parameter :: r3dvar = 4
      integer(4), parameter :: u3dvar = 5
      integer(4), parameter :: v3dvar = 6
      integer(4), parameter :: p3dvar = 7
      integer(4), parameter :: w3dvar = 8
      integer(4), parameter :: pw3dvar = 11
      integer(4), parameter :: b3dvar = 12
      real, parameter :: qp2 = 0.0000172D0
      real, parameter :: Gslope_max = 1.D0
      real, parameter :: Rslope_max = 0.05D0
      integer(4) :: Mmmpi
      integer(4) :: padd_X
      integer(4) :: Lm
      integer(4) :: Lmmpi
      integer(4) :: padd_E
      integer(4) :: Mm
        end subroutine Sub_Loop_step3D_uv_thread

      end interface
      

        call Sub_Loop_step3D_uv_thread( Agrif_tabvars_i(8)%iarray0, Agri
     &f_tabvars_i(13)%iarray0, Agrif_tabvars_i(2)%iarray0, Agrif_tabvars
     &_i(7)%iarray0, Agrif_tabvars_i(14)%iarray0, Agrif_tabvars_i(4)%iar
     &ray0)

      end


      subroutine Sub_Loop_step3D_uv_thread(Mmmpi,padd_X,Lm,Lmmpi,padd_E,
     &Mm)

      use Agrif_Types, only : Agrif_tabvars

      use debug
      use Agrif_Util
      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 :: 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), parameter :: filetype_his = 1
      integer(4), parameter :: filetype_avg = 2
      integer(4), parameter :: filetype_dia = 3
      integer(4), parameter :: filetype_dia_avg = 4
      integer(4), parameter :: filetype_diaM = 5
      integer(4), parameter :: filetype_diaM_avg = 6
      integer(4), parameter :: filetype_diags_vrt = 7
      integer(4), parameter :: filetype_diags_vrt_avg = 8
      integer(4), parameter :: filetype_diags_ek = 9
      integer(4), parameter :: filetype_diags_ek_avg = 10
      integer(4), parameter :: filetype_diags_pv = 11
      integer(4), parameter :: filetype_diags_pv_avg = 12
      integer(4), parameter :: filetype_diags_eddy_avg = 17
      integer(4), parameter :: filetype_surf = 13
      integer(4), parameter :: filetype_surf_avg = 14
      integer(4), parameter :: filetype_diabio = 15
      integer(4), parameter :: filetype_diabio_avg = 16
      integer(4), parameter :: filetype_abl = 18
      integer(4), parameter :: filetype_abl_avg = 19
      integer(4), parameter :: indxTime = 1
      integer(4), parameter :: indxZ = 2
      integer(4), parameter :: indxUb = 3
      integer(4), parameter :: indxVb = 4
      integer(4), parameter :: indxU = 6
      integer(4), parameter :: indxV = 7
      integer(4), parameter :: indxT = indxV+1
      integer(4), parameter :: indxS = indxV+ntrc_temp+1
      integer(4), parameter :: indxBSD = indxV+ntrc_temp+ntrc_salt+ntrc_
     &pas+ntrc_bio+1
      integer(4), parameter :: indxBSS = 101
      integer(4), parameter :: indxO = indxV+ntrc_temp+ntrc_salt+ntrc_pa
     &s+ntrc_bio+ntrc_sed+ntrc_substot+ntrc_diats+ntrc_diauv+ntrc_diavrt
     &+ntrc_diaek+ntrc_diapv+ntrc_diaeddy+ntrc_surf+ntrc_diabio+1
      integer(4), parameter :: indxW = indxO+1
      integer(4), parameter :: indxR = indxO+2
      integer(4), parameter :: indxVisc = indxO+3
      integer(4), parameter :: indxDiff = indxO+4
      integer(4), parameter :: indxAkv = indxO+5
      integer(4), parameter :: indxAkt = indxO+6
      integer(4), parameter :: indxAks = indxAkv+ntrc_temp+4
      integer(4), parameter :: indxHbl = indxAkv+ntrc_temp+5
      integer(4), parameter :: indxHbbl = indxAkv+ntrc_temp+6
      integer(4), parameter :: indxSSH = indxAkv+ntrc_temp+12
      integer(4), parameter :: indxbvf = indxSSH+1
      integer(4), parameter :: indxSUSTR = indxSSH+2
      integer(4), parameter :: indxSVSTR = indxSSH+3
      integer(4), parameter :: indxTime2 = indxSSH+4
      integer(4), parameter :: indxShflx = indxSUSTR+5
      integer(4), parameter :: indxSwflx = indxShflx+1
      integer(4), parameter :: indxShflx_rsw = indxShflx+2
      integer(4), parameter :: indxSST = indxShflx_rsw+1
      integer(4), parameter :: indxdQdSST = indxShflx_rsw+2
      integer(4), parameter :: indxSSS = indxSST+2
      integer(4), parameter :: indxWstr = indxSUSTR+23
      integer(4), parameter :: indxUWstr = indxSUSTR+24
      integer(4), parameter :: indxVWstr = indxSUSTR+25
      integer(4), parameter :: indxBostr = indxSUSTR+26
      integer(4), parameter :: indxBustr = indxSUSTR+27
      integer(4), parameter :: indxBvstr = indxBustr+1
      integer(4), parameter :: indxWWA = indxSUSTR+42
      integer(4), parameter :: indxWWD = indxWWA+1
      integer(4), parameter :: indxWWP = indxWWA+2
      integer(4), parameter :: r2dvar = 0
      integer(4), parameter :: u2dvar = 1
      integer(4), parameter :: v2dvar = 2
      integer(4), parameter :: p2dvar = 3
      integer(4), parameter :: r3dvar = 4
      integer(4), parameter :: u3dvar = 5
      integer(4), parameter :: v3dvar = 6
      integer(4), parameter :: p3dvar = 7
      integer(4), parameter :: w3dvar = 8
      integer(4), parameter :: pw3dvar = 11
      integer(4), parameter :: b3dvar = 12
      real, parameter :: qp2 = 0.0000172D0
      real, parameter :: Gslope_max = 1.D0
      real, parameter :: Rslope_max = 0.05D0
      integer(4) :: Mmmpi
      integer(4) :: padd_X
      integer(4) :: Lm
      integer(4) :: Lmmpi
      integer(4) :: padd_E
      integer(4) :: Mm

                     
                
                   

                                            
                             
                                            

                                                             
                     
                        

                                                            
                                           
                                                               
                                    
                                      
                                                          

                       

                                    

                        
                              

                       
                          

                                                
                                             
                          

                        

                                 

                                                
                        

                                                              
                      
                              

                                       
                                                                     
                                          
                         

                             

                             

                            

                            

                                             

                            

                                     

                                                               

                         

                                                      
                                                      
                                                                  
                               

                               

                              

                              

                               

                              

                              

                                

                             

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

                                                                       
                                                                 
                  
                                                                       
                                                                 
                                                                 
                                                                 
                  

                          

              
                             

                  
                               

                 
                                

                       
                                   

                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                      
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                         

                                 
      integer(4) :: iloop
      integer(4) :: indextemp
                                                
                                                         

                             
                                  

                      
                               

                      
                                         

                                 
                                                                       
                                                                 
                              

                                                                       
                                                                 
                                                                 
    
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                 

                        
                                             

                        
                                             

                         
                                              

                        
                                              

                        
                                   

                                     
                                                          

                          
                                     

                                         
                                       

                          
                                                                  

                                    
                                                                     

                        
                                   

                         
                                       

                          
                                        

                          
                                        

                          
                                        

                                     
                                                                

                                                                
      integer(4) :: indxWEB
      integer(4) :: indxWED
      integer(4) :: indxWER
                                                                       
                                                                 
                                                          

                                                                       
                                                                 
                                                                 
            
                                                                       
                                                                 
                                                                 
       

                                           
                                                       
                                                                       
                                                                 
                                                                 
                              
                                                                       
                                                                 
    
                                                                       
                                                                 
                                                                 
                    
                         
                       
                        
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                   
                         
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                      
                         
                                                            
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                       
                                   
                                                                 
                                                                       
                                                                 
                                                                 
                                                                 
                               
                                                                  
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
     
                                    
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
               
                                             
                              
                                          
                              
                                          
                              
                                                       
                              
                                                      
                              
                                                      
                              
                                              
                               
                                           
                               
                                           
                               
                                                        
                               
                                                       
                               
                                                       
                               
                                              
                                                        
                                            
                                                   
                                            
                                                   
                           
                                  
                           
                                  
                           
                                  
                                        
                               
                                                           
                                        
                          
                                                       
                                             
                         
                                   
                                                    
                                                    
                                
                                                    
                                 
                                                    
                                                   
                                                   
                                                  
                                                               
                                           
                                                     
                                                     
                                                       
                                                        
                                                           
                                                       
                                                       
                                           
                                                            
                                  
                                                            
                               
                                                            
                               
                                                     
                                            
                                                  
                                            
                                                  
                                            
                                                  
                                            
                                                                
                                            
                                                             
                                            
                                                             
                                            
                                                             
                                            
                                                      
                                             
                                                   
                                             
                                                   
                                             
                                                   
                                             
                                                                 
                                             
                                                              
                                             
                                                              
                                             
                                                              
                                             
                                          
                                                           
                                            
                                             
                                     
                                                    
                                                      
                                                                       
                                                                 
                                           
                                                    
                                                      
                                               
                                                            
                                           
                                
                                
                             
                                                                       
                                                                 
             
                                                      
                        
                                                          
                                                                       
                                                                 
                                              
                                                         
                                               
                                                
                                           
                                           
                                                                       
                                                                 
                                                                 
                                                                 
                         
!$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) :: range
                                                                       
                                                                 
 
      integer(4) :: ntrds
      integer(4) :: trd
      integer(4) :: my_first
      integer(4) :: my_last
      integer(4) :: tile
      integer(4) :: my_iif
                      
      integer(4) :: i
      integer(4) :: j
      integer(4) :: k
                                                        
      integer(4) :: omp_get_num_threads
      integer(4) :: omp_get_thread_num
                     
      integer(4) :: itrc
                    
      real :: t1
      real :: t2
      real :: t3
      ntrds=omp_get_num_threads()
      trd=omp_get_thread_num()
C$OMP BARRIER
      range=(NSUB_X*NSUB_E+ntrds-1)/ntrds
      my_first=trd*range
      my_last=min(my_first + range-1, NSUB_X*NSUB_E-1)
C$OMP BARRIER
      do tile=my_last,my_first,-1
        call set_depth (tile)
      enddo
C$OMP BARRIER
      do tile=my_first,my_last,+1
        call set_HUV2 (tile)
      enddo
C$OMP BARRIER
      do tile=my_last,my_first,-1
        call omega (tile)
        call rho_eos (tile)
      enddo
C$OMP BARRIER
      do tile=my_first,my_last,+1
        call prsgrd (tile)
        call rhs3d (tile)
        call step3d_uv1 (tile)
      enddo
C$OMP BARRIER
      do tile=my_last,my_first,-1
        call step3d_uv2 (tile)
        call hdiff_coef (tile)
      enddo
C$OMP BARRIER
C$OMP BARRIER
C$OMP MASTER
      if (.Not.Agrif_Root()) then
        call Agrif_update_uv_np1
      endif
C$OMP END MASTER
      return
       
      

      end subroutine Sub_Loop_step3D_uv_thread

      subroutine step3D_t_thread()      

      use Agrif_Util
      interface
        subroutine Sub_Loop_step3D_t_thread(iic,nbcoarse,Mmmpi,padd_X,Lm
     &,Lmmpi,padd_E,Mm)
          use Agrif_Util
          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 :: 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), parameter :: filetype_his = 1
      integer(4), parameter :: filetype_avg = 2
      integer(4), parameter :: filetype_dia = 3
      integer(4), parameter :: filetype_dia_avg = 4
      integer(4), parameter :: filetype_diaM = 5
      integer(4), parameter :: filetype_diaM_avg = 6
      integer(4), parameter :: filetype_diags_vrt = 7
      integer(4), parameter :: filetype_diags_vrt_avg = 8
      integer(4), parameter :: filetype_diags_ek = 9
      integer(4), parameter :: filetype_diags_ek_avg = 10
      integer(4), parameter :: filetype_diags_pv = 11
      integer(4), parameter :: filetype_diags_pv_avg = 12
      integer(4), parameter :: filetype_diags_eddy_avg = 17
      integer(4), parameter :: filetype_surf = 13
      integer(4), parameter :: filetype_surf_avg = 14
      integer(4), parameter :: filetype_diabio = 15
      integer(4), parameter :: filetype_diabio_avg = 16
      integer(4), parameter :: filetype_abl = 18
      integer(4), parameter :: filetype_abl_avg = 19
      integer(4), parameter :: indxTime = 1
      integer(4), parameter :: indxZ = 2
      integer(4), parameter :: indxUb = 3
      integer(4), parameter :: indxVb = 4
      integer(4), parameter :: indxU = 6
      integer(4), parameter :: indxV = 7
      integer(4), parameter :: indxT = indxV+1
      integer(4), parameter :: indxS = indxV+ntrc_temp+1
      integer(4), parameter :: indxBSD = indxV+ntrc_temp+ntrc_salt+ntrc_
     &pas+ntrc_bio+1
      integer(4), parameter :: indxBSS = 101
      integer(4), parameter :: indxO = indxV+ntrc_temp+ntrc_salt+ntrc_pa
     &s+ntrc_bio+ntrc_sed+ntrc_substot+ntrc_diats+ntrc_diauv+ntrc_diavrt
     &+ntrc_diaek+ntrc_diapv+ntrc_diaeddy+ntrc_surf+ntrc_diabio+1
      integer(4), parameter :: indxW = indxO+1
      integer(4), parameter :: indxR = indxO+2
      integer(4), parameter :: indxVisc = indxO+3
      integer(4), parameter :: indxDiff = indxO+4
      integer(4), parameter :: indxAkv = indxO+5
      integer(4), parameter :: indxAkt = indxO+6
      integer(4), parameter :: indxAks = indxAkv+ntrc_temp+4
      integer(4), parameter :: indxHbl = indxAkv+ntrc_temp+5
      integer(4), parameter :: indxHbbl = indxAkv+ntrc_temp+6
      integer(4), parameter :: indxSSH = indxAkv+ntrc_temp+12
      integer(4), parameter :: indxbvf = indxSSH+1
      integer(4), parameter :: indxSUSTR = indxSSH+2
      integer(4), parameter :: indxSVSTR = indxSSH+3
      integer(4), parameter :: indxTime2 = indxSSH+4
      integer(4), parameter :: indxShflx = indxSUSTR+5
      integer(4), parameter :: indxSwflx = indxShflx+1
      integer(4), parameter :: indxShflx_rsw = indxShflx+2
      integer(4), parameter :: indxSST = indxShflx_rsw+1
      integer(4), parameter :: indxdQdSST = indxShflx_rsw+2
      integer(4), parameter :: indxSSS = indxSST+2
      integer(4), parameter :: indxWstr = indxSUSTR+23
      integer(4), parameter :: indxUWstr = indxSUSTR+24
      integer(4), parameter :: indxVWstr = indxSUSTR+25
      integer(4), parameter :: indxBostr = indxSUSTR+26
      integer(4), parameter :: indxBustr = indxSUSTR+27
      integer(4), parameter :: indxBvstr = indxBustr+1
      integer(4), parameter :: indxWWA = indxSUSTR+42
      integer(4), parameter :: indxWWD = indxWWA+1
      integer(4), parameter :: indxWWP = indxWWA+2
      integer(4), parameter :: r2dvar = 0
      integer(4), parameter :: u2dvar = 1
      integer(4), parameter :: v2dvar = 2
      integer(4), parameter :: p2dvar = 3
      integer(4), parameter :: r3dvar = 4
      integer(4), parameter :: u3dvar = 5
      integer(4), parameter :: v3dvar = 6
      integer(4), parameter :: p3dvar = 7
      integer(4), parameter :: w3dvar = 8
      integer(4), parameter :: pw3dvar = 11
      integer(4), parameter :: b3dvar = 12
      real, parameter :: qp2 = 0.0000172D0
      integer(4) :: iic
      integer(4) :: nbcoarse
      integer(4) :: Mmmpi
      integer(4) :: padd_X
      integer(4) :: Lm
      integer(4) :: Lmmpi
      integer(4) :: padd_E
      integer(4) :: Mm
        end subroutine Sub_Loop_step3D_t_thread

      end interface
      

        call Sub_Loop_step3D_t_thread( Agrif_tabvars_i(147)%iarray0, Agr
     &if_tabvars_i(236)%iarray0, Agrif_tabvars_i(8)%iarray0, Agrif_tabva
     &rs_i(13)%iarray0, Agrif_tabvars_i(2)%iarray0, Agrif_tabvars_i(7)%i
     &array0, Agrif_tabvars_i(14)%iarray0, Agrif_tabvars_i(4)%iarray0)

      end


      subroutine Sub_Loop_step3D_t_thread(iic,nbcoarse,Mmmpi,padd_X,Lm,L
     &mmpi,padd_E,Mm)

      use Agrif_Types, only : Agrif_tabvars

      use Agrif_Util
      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 :: 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), parameter :: filetype_his = 1
      integer(4), parameter :: filetype_avg = 2
      integer(4), parameter :: filetype_dia = 3
      integer(4), parameter :: filetype_dia_avg = 4
      integer(4), parameter :: filetype_diaM = 5
      integer(4), parameter :: filetype_diaM_avg = 6
      integer(4), parameter :: filetype_diags_vrt = 7
      integer(4), parameter :: filetype_diags_vrt_avg = 8
      integer(4), parameter :: filetype_diags_ek = 9
      integer(4), parameter :: filetype_diags_ek_avg = 10
      integer(4), parameter :: filetype_diags_pv = 11
      integer(4), parameter :: filetype_diags_pv_avg = 12
      integer(4), parameter :: filetype_diags_eddy_avg = 17
      integer(4), parameter :: filetype_surf = 13
      integer(4), parameter :: filetype_surf_avg = 14
      integer(4), parameter :: filetype_diabio = 15
      integer(4), parameter :: filetype_diabio_avg = 16
      integer(4), parameter :: filetype_abl = 18
      integer(4), parameter :: filetype_abl_avg = 19
      integer(4), parameter :: indxTime = 1
      integer(4), parameter :: indxZ = 2
      integer(4), parameter :: indxUb = 3
      integer(4), parameter :: indxVb = 4
      integer(4), parameter :: indxU = 6
      integer(4), parameter :: indxV = 7
      integer(4), parameter :: indxT = indxV+1
      integer(4), parameter :: indxS = indxV+ntrc_temp+1
      integer(4), parameter :: indxBSD = indxV+ntrc_temp+ntrc_salt+ntrc_
     &pas+ntrc_bio+1
      integer(4), parameter :: indxBSS = 101
      integer(4), parameter :: indxO = indxV+ntrc_temp+ntrc_salt+ntrc_pa
     &s+ntrc_bio+ntrc_sed+ntrc_substot+ntrc_diats+ntrc_diauv+ntrc_diavrt
     &+ntrc_diaek+ntrc_diapv+ntrc_diaeddy+ntrc_surf+ntrc_diabio+1
      integer(4), parameter :: indxW = indxO+1
      integer(4), parameter :: indxR = indxO+2
      integer(4), parameter :: indxVisc = indxO+3
      integer(4), parameter :: indxDiff = indxO+4
      integer(4), parameter :: indxAkv = indxO+5
      integer(4), parameter :: indxAkt = indxO+6
      integer(4), parameter :: indxAks = indxAkv+ntrc_temp+4
      integer(4), parameter :: indxHbl = indxAkv+ntrc_temp+5
      integer(4), parameter :: indxHbbl = indxAkv+ntrc_temp+6
      integer(4), parameter :: indxSSH = indxAkv+ntrc_temp+12
      integer(4), parameter :: indxbvf = indxSSH+1
      integer(4), parameter :: indxSUSTR = indxSSH+2
      integer(4), parameter :: indxSVSTR = indxSSH+3
      integer(4), parameter :: indxTime2 = indxSSH+4
      integer(4), parameter :: indxShflx = indxSUSTR+5
      integer(4), parameter :: indxSwflx = indxShflx+1
      integer(4), parameter :: indxShflx_rsw = indxShflx+2
      integer(4), parameter :: indxSST = indxShflx_rsw+1
      integer(4), parameter :: indxdQdSST = indxShflx_rsw+2
      integer(4), parameter :: indxSSS = indxSST+2
      integer(4), parameter :: indxWstr = indxSUSTR+23
      integer(4), parameter :: indxUWstr = indxSUSTR+24
      integer(4), parameter :: indxVWstr = indxSUSTR+25
      integer(4), parameter :: indxBostr = indxSUSTR+26
      integer(4), parameter :: indxBustr = indxSUSTR+27
      integer(4), parameter :: indxBvstr = indxBustr+1
      integer(4), parameter :: indxWWA = indxSUSTR+42
      integer(4), parameter :: indxWWD = indxWWA+1
      integer(4), parameter :: indxWWP = indxWWA+2
      integer(4), parameter :: r2dvar = 0
      integer(4), parameter :: u2dvar = 1
      integer(4), parameter :: v2dvar = 2
      integer(4), parameter :: p2dvar = 3
      integer(4), parameter :: r3dvar = 4
      integer(4), parameter :: u3dvar = 5
      integer(4), parameter :: v3dvar = 6
      integer(4), parameter :: p3dvar = 7
      integer(4), parameter :: w3dvar = 8
      integer(4), parameter :: pw3dvar = 11
      integer(4), parameter :: b3dvar = 12
      real, parameter :: qp2 = 0.0000172D0
      integer(4) :: iic
      integer(4) :: nbcoarse
      integer(4) :: Mmmpi
      integer(4) :: padd_X
      integer(4) :: Lm
      integer(4) :: Lmmpi
      integer(4) :: padd_E
      integer(4) :: Mm

                     
                   

                                            
                             
                                            

                                                             
                     
                        

                                                            
                                           
                                                               
                                    
                                      
                                                          

                       

                                    

                        
                              

                       
                          

                                                
                                             
                          

                        

                                 

                                                
                        

                                                              
                      
                              

                                       
                                                                     
                                          
                         

                             

                             

                            

                            

                                             

                            

                                     

                                                               

                         

                                                      
                                                      
                                                                  
                               

                               

                              

                              

                               

                              

                              

                                

                             

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

                                                                       
                                                                 
                  
                                                                       
                                                                 
                                                                 
                                                                 
                  

                          

              
                             

                  
                               

                 
                                

                       
                                   

                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                      
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                         

                                 
      integer(4) :: iloop
      integer(4) :: indextemp
                                                
                                                         

                             
                                  

                      
                               

                      
                                         

                                 
                                                                       
                                                                 
                              

                                                                       
                                                                 
                                                                 
    
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                 

                        
                                             

                        
                                             

                         
                                              

                        
                                              

                        
                                   

                                     
                                                          

                          
                                     

                                         
                                       

                          
                                                                  

                                    
                                                                     

                        
                                   

                         
                                       

                          
                                        

                          
                                        

                          
                                        

                                     
                                                                

                                                                
      integer(4) :: indxWEB
      integer(4) :: indxWED
      integer(4) :: indxWER
                                                                       
                                                                 
                                                          

                                                                       
                                                                 
                                                                 
            
                                                                       
                                                                 
                                                                 
       

                                           
                                                       
                                                                       
                                                                 
                                                                 
                              
                                                                       
                                                                 
    
                                                                       
                                                                 
                                                                 
                    
                         
                       
                        
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                   
                         
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                      
                         
                                                            
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                       
                                   
                                                                 
                                                                       
                                                                 
                                                                 
                                                                 
                               
                                                                  
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
     
                                    
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
               
                                             
                              
                                          
                              
                                          
                              
                                                       
                              
                                                      
                              
                                                      
                              
                                              
                               
                                           
                               
                                           
                               
                                                        
                               
                                                       
                               
                                                       
                               
                                              
                                                        
                                            
                                                   
                                            
                                                   
                           
                                  
                           
                                  
                           
                                  
                                        
                               
                                                           
                                        
                          
                                                       
                                             
                         
                                   
                                                    
                                                    
                                
                                                    
                                 
                                                    
                                                   
                                                   
                                                  
                                                               
                                           
                                                     
                                                     
                                                       
                                                        
                                                           
                                                       
                                                       
                                           
                                                            
                                  
                                                            
                               
                                                            
                               
                                                     
                                            
                                                  
                                            
                                                  
                                            
                                                  
                                            
                                                                
                                            
                                                             
                                            
                                                             
                                            
                                                             
                                            
                                                      
                                             
                                                   
                                             
                                                   
                                             
                                                   
                                             
                                                                 
                                             
                                                              
                                             
                                                              
                                             
                                                              
                                             
                                          
                                                           
                                            
                                             
                                     
                                                    
                                                      
                                                                       
                                                                 
                                           
                                                    
                                                      
                                               
                                                            
                                           
                                
                                
                             
                                                                       
                                                                 
             
                                                      
                        
                                                          
                                                                       
                                                                 
                                              
                                                         
                                               
                                                
                                           
                                           
                                                                       
                                                                 
                                                                 
                                                                 
                         
!$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) :: range
                                                                       
                                                                 
 
      integer(4) :: ntrds
      integer(4) :: trd
      integer(4) :: my_first
      integer(4) :: my_last
      integer(4) :: tile
      integer(4) :: my_iif
                      
      integer(4) :: i
      integer(4) :: j
      integer(4) :: k
                                                        
      integer(4) :: omp_get_num_threads
      integer(4) :: omp_get_thread_num
                           
      integer(4) :: itrc
      integer(4) :: ilay
                    
      real :: t1
      real :: t2
      real :: t3
      ntrds=omp_get_num_threads()
      trd=omp_get_thread_num()
C$OMP BARRIER
      range=(NSUB_X*NSUB_E+ntrds-1)/ntrds
      my_first=trd*range
      my_last=min(my_first + range-1, NSUB_X*NSUB_E-1)
C$OMP BARRIER
      do tile=my_first,my_last,+1
        call omega (tile)
        call step3d_t (tile)
        if (.Not.Agrif_Root()) then
          call t3dpremix (tile)
        endif
      enddo
C$OMP BARRIER
      do tile=my_last,my_first,-1
        call t3dmix (tile)
        call t3dmix_spg (tile)
      enddo
C$OMP BARRIER
C$OMP BARRIER
C$OMP MASTER
      if ((.Not.Agrif_Root()).and.
     &    (nbcoarse == Agrif_Irhot())) then
        call Agrif_update_np1
      endif
C$OMP END MASTER
C$OMP MASTER
      iic=iic + 1
      nbcoarse = 1 + mod(nbcoarse, Agrif_IRhot())
C$OMP END MASTER
C$OMP BARRIER
      return
       
      

      end subroutine Sub_Loop_step3D_t_thread

      module lmd_kpp_ghats


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_lmd_kpp_ghats
      contains
      subroutine Alloc_agrif_lmd_kpp_ghats(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : ghats
          if (.not. allocated(Agrif_Gr % tabvars(132)% array3)) then
          allocate(Agrif_Gr % tabvars(132)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,0 : N))
          Agrif_Gr % tabvars(132)% array3 = 0
      endif
      end subroutine Alloc_agrif_lmd_kpp_ghats
      end module lmd_kpp_ghats
      module lmd_kpp_hbl


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_lmd_kpp_hbl
      contains
      subroutine Alloc_agrif_lmd_kpp_hbl(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : hbls
          if (.not. allocated(Agrif_Gr % tabvars(133)% array3)) then
          allocate(Agrif_Gr % tabvars(133)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : 2))
          Agrif_Gr % tabvars(133)% array3 = 0
      endif
      end subroutine Alloc_agrif_lmd_kpp_hbl
      end module lmd_kpp_hbl
      module lmd_kpp_kbbl


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_lmd_kpp_kbbl
      contains
      subroutine Alloc_agrif_lmd_kpp_kbbl(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : kbbl
          if (.not. allocated(Agrif_Gr % tabvars_i(248)% iarray2)) then
          allocate(Agrif_Gr % tabvars_i(248)% iarray2(-1 :  Agrif_tabvar
     &s_i(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_
     &i(4)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars_i(248)% iarray2 = 0
      endif
      end subroutine Alloc_agrif_lmd_kpp_kbbl
      end module lmd_kpp_kbbl
      module lmd_kpp_hbbl


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_lmd_kpp_hbbl
      contains
      subroutine Alloc_agrif_lmd_kpp_hbbl(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : hbbl
          if (.not. allocated(Agrif_Gr % tabvars(134)% array2)) then
          allocate(Agrif_Gr % tabvars(134)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(134)% array2 = 0
      endif
      end subroutine Alloc_agrif_lmd_kpp_hbbl
      end module lmd_kpp_hbbl
      module lmd_kpp_kbl


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_lmd_kpp_kbl
      contains
      subroutine Alloc_agrif_lmd_kpp_kbl(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : kbl
          if (.not. allocated(Agrif_Gr % tabvars_i(249)% iarray2)) then
          allocate(Agrif_Gr % tabvars_i(249)% iarray2(-1 :  Agrif_tabvar
     &s_i(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_
     &i(4)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars_i(249)% iarray2 = 0
      endif
      end subroutine Alloc_agrif_lmd_kpp_kbl
      end module lmd_kpp_kbl
      module lmd_kpp_ustar


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_lmd_kpp_ustar
      contains
      subroutine Alloc_agrif_lmd_kpp_ustar(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : ustar
          if (.not. allocated(Agrif_Gr % tabvars(135)% array2)) then
          allocate(Agrif_Gr % tabvars(135)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(135)% array2 = 0
      endif
      end subroutine Alloc_agrif_lmd_kpp_ustar
      end module lmd_kpp_ustar
      module mixing_bvf


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_bvf
      contains
      subroutine Alloc_agrif_mixing_bvf(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : bvf
          if (.not. allocated(Agrif_Gr % tabvars(136)% array3)) then
          allocate(Agrif_Gr % tabvars(136)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,0 : N))
          Agrif_Gr % tabvars(136)% array3 = 0
      endif
      end subroutine Alloc_agrif_mixing_bvf
      end module mixing_bvf
      module mixing_Akt


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_Akt
      contains
      subroutine Alloc_agrif_mixing_Akt(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : Akt
          if (.not. allocated(Agrif_Gr % tabvars(137)% array4)) then
          allocate(Agrif_Gr % tabvars(137)% array4(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,0 : N,1 : 2))
          Agrif_Gr % tabvars(137)% array4 = 0
      endif
      end subroutine Alloc_agrif_mixing_Akt
      end module mixing_Akt
      module mixing_Akv


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_Akv
      contains
      subroutine Alloc_agrif_mixing_Akv(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : Akv
          if (.not. allocated(Agrif_Gr % tabvars(138)% array3)) then
          allocate(Agrif_Gr % tabvars(138)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,0 : N))
          Agrif_Gr % tabvars(138)% array3 = 0
      endif
      end subroutine Alloc_agrif_mixing_Akv
      end module mixing_Akv
      module mixing_idRz


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_idRz
      contains
      subroutine Alloc_agrif_mixing_idRz(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : idRz
          if (.not. allocated(Agrif_Gr % tabvars(139)% array3)) then
          allocate(Agrif_Gr % tabvars(139)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,0 : N))
          Agrif_Gr % tabvars(139)% array3 = 0
      endif
      end subroutine Alloc_agrif_mixing_idRz
      end module mixing_idRz
      module mixing_dRde


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_dRde
      contains
      subroutine Alloc_agrif_mixing_dRde(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : dRde
          if (.not. allocated(Agrif_Gr % tabvars(140)% array3)) then
          allocate(Agrif_Gr % tabvars(140)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N))
          Agrif_Gr % tabvars(140)% array3 = 0
      endif
      end subroutine Alloc_agrif_mixing_dRde
      end module mixing_dRde
      module mixing_dRdx


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_dRdx
      contains
      subroutine Alloc_agrif_mixing_dRdx(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : dRdx
          if (.not. allocated(Agrif_Gr % tabvars(141)% array3)) then
          allocate(Agrif_Gr % tabvars(141)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N))
          Agrif_Gr % tabvars(141)% array3 = 0
      endif
      end subroutine Alloc_agrif_mixing_dRdx
      end module mixing_dRdx
      module mixing_diff3d_v


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_diff3d_v
      contains
      subroutine Alloc_agrif_mixing_diff3d_v(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : diff3d_v
          if (.not. allocated(Agrif_Gr % tabvars(142)% array3)) then
          allocate(Agrif_Gr % tabvars(142)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N))
          Agrif_Gr % tabvars(142)% array3 = 0
      endif
      end subroutine Alloc_agrif_mixing_diff3d_v
      end module mixing_diff3d_v
      module mixing_diff3d_u


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_diff3d_u
      contains
      subroutine Alloc_agrif_mixing_diff3d_u(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : diff3d_u
          if (.not. allocated(Agrif_Gr % tabvars(143)% array3)) then
          allocate(Agrif_Gr % tabvars(143)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N))
          Agrif_Gr % tabvars(143)% array3 = 0
      endif
      end subroutine Alloc_agrif_mixing_diff3d_u
      end module mixing_diff3d_u
      module mixing_diff4


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_diff4
      contains
      subroutine Alloc_agrif_mixing_diff4(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: ntrc_sed = 0
      integer(4), parameter :: ntrc_bio = 0
      integer(4), parameter :: ntrc_pas = 0
      integer(4), parameter :: ntrc_salt = 1
      integer(4), parameter :: itemp = 1
      integer(4), parameter :: NT = itemp+ntrc_salt+ntrc_pas+ntrc_bio+nt
     &rc_sed
      !! ALLOCATION OF VARIABLE : diff4
          if (.not. allocated(Agrif_Gr % tabvars(144)% array3)) then
          allocate(Agrif_Gr % tabvars(144)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : NT))
          Agrif_Gr % tabvars(144)% array3 = 0
      endif
      end subroutine Alloc_agrif_mixing_diff4
      end module mixing_diff4
      module mixing_diff4_sponge


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_diff4_sponge
      contains
      subroutine Alloc_agrif_mixing_diff4_sponge(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : diff4_sponge
          if (.not. allocated(Agrif_Gr % tabvars(145)% array2)) then
          allocate(Agrif_Gr % tabvars(145)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(145)% array2 = 0
      endif
      end subroutine Alloc_agrif_mixing_diff4_sponge
      end module mixing_diff4_sponge
      module mixing_diff2


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_diff2
      contains
      subroutine Alloc_agrif_mixing_diff2(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: ntrc_sed = 0
      integer(4), parameter :: ntrc_bio = 0
      integer(4), parameter :: ntrc_pas = 0
      integer(4), parameter :: ntrc_salt = 1
      integer(4), parameter :: itemp = 1
      integer(4), parameter :: NT = itemp+ntrc_salt+ntrc_pas+ntrc_bio+nt
     &rc_sed
      !! ALLOCATION OF VARIABLE : diff2
          if (.not. allocated(Agrif_Gr % tabvars(146)% array3)) then
          allocate(Agrif_Gr % tabvars(146)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : NT))
          Agrif_Gr % tabvars(146)% array3 = 0
      endif
      end subroutine Alloc_agrif_mixing_diff2
      end module mixing_diff2
      module mixing_diff2_sponge


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_diff2_sponge
      contains
      subroutine Alloc_agrif_mixing_diff2_sponge(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : diff2_sponge
          if (.not. allocated(Agrif_Gr % tabvars(147)% array2)) then
          allocate(Agrif_Gr % tabvars(147)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(147)% array2 = 0
      endif
      end subroutine Alloc_agrif_mixing_diff2_sponge
      end module mixing_diff2_sponge
      module mixing_visc2_sponge_p


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_visc2_sponge_p
      contains
      subroutine Alloc_agrif_mixing_visc2_sponge_p(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : visc2_sponge_p
          if (.not. allocated(Agrif_Gr % tabvars(148)% array2)) then
          allocate(Agrif_Gr % tabvars(148)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(148)% array2 = 0
      endif
      end subroutine Alloc_agrif_mixing_visc2_sponge_p
      end module mixing_visc2_sponge_p
      module mixing_visc2_sponge_r


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_visc2_sponge_r
      contains
      subroutine Alloc_agrif_mixing_visc2_sponge_r(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : visc2_sponge_r
          if (.not. allocated(Agrif_Gr % tabvars(149)% array2)) then
          allocate(Agrif_Gr % tabvars(149)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(149)% array2 = 0
      endif
      end subroutine Alloc_agrif_mixing_visc2_sponge_r
      end module mixing_visc2_sponge_r
      module mixing_visc2_p


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_visc2_p
      contains
      subroutine Alloc_agrif_mixing_visc2_p(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : visc2_p
          if (.not. allocated(Agrif_Gr % tabvars(150)% array2)) then
          allocate(Agrif_Gr % tabvars(150)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(150)% array2 = 0
      endif
      end subroutine Alloc_agrif_mixing_visc2_p
      end module mixing_visc2_p
      module mixing_visc2_r


      use debug
      use Agrif_Util
        implicit none
        public :: Alloc_agrif_mixing_visc2_r
      contains
      subroutine Alloc_agrif_mixing_visc2_r(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : visc2_r
          if (.not. allocated(Agrif_Gr % tabvars(151)% array2)) then
          allocate(Agrif_Gr % tabvars(151)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(151)% array2 = 0
      endif
      end subroutine Alloc_agrif_mixing_visc2_r
      end module mixing_visc2_r
      module ocean_qp1


        implicit none
        public :: Alloc_agrif_ocean_qp1
      contains
      subroutine Alloc_agrif_ocean_qp1(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : qp1
          if (.not. allocated(Agrif_Gr % tabvars(152)% array3)) then
          allocate(Agrif_Gr % tabvars(152)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N))
          Agrif_Gr % tabvars(152)% array3 = 0
      endif
      end subroutine Alloc_agrif_ocean_qp1
      end module ocean_qp1
      module ocean_rho


        implicit none
        public :: Alloc_agrif_ocean_rho
      contains
      subroutine Alloc_agrif_ocean_rho(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : rho
          if (.not. allocated(Agrif_Gr % tabvars(153)% array3)) then
          allocate(Agrif_Gr % tabvars(153)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N))
          Agrif_Gr % tabvars(153)% array3 = 0
      endif
      end subroutine Alloc_agrif_ocean_rho
      end module ocean_rho
      module ocean_rho1


        implicit none
        public :: Alloc_agrif_ocean_rho1
      contains
      subroutine Alloc_agrif_ocean_rho1(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : rho1
          if (.not. allocated(Agrif_Gr % tabvars(154)% array3)) then
          allocate(Agrif_Gr % tabvars(154)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N))
          Agrif_Gr % tabvars(154)% array3 = 0
      endif
      end subroutine Alloc_agrif_ocean_rho1
      end module ocean_rho1
      module grid_We


        implicit none
        public :: Alloc_agrif_grid_We
      contains
      subroutine Alloc_agrif_grid_We(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : We
          if (.not. allocated(Agrif_Gr % tabvars(155)% array3)) then
          allocate(Agrif_Gr % tabvars(155)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,0 : N))
          Agrif_Gr % tabvars(155)% array3 = 0
      endif
      end subroutine Alloc_agrif_grid_We
      end module grid_We
      module grid_zr


        implicit none
        public :: Alloc_agrif_grid_zr
      contains
      subroutine Alloc_agrif_grid_zr(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : z_r
          if (.not. allocated(Agrif_Gr % tabvars(156)% array3)) then
          allocate(Agrif_Gr % tabvars(156)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N))
          Agrif_Gr % tabvars(156)% array3 = 0
      endif
      end subroutine Alloc_agrif_grid_zr
      end module grid_zr
      module grid_Hz


        implicit none
        public :: Alloc_agrif_grid_Hz
      contains
      subroutine Alloc_agrif_grid_Hz(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : Hz
          if (.not. allocated(Agrif_Gr % tabvars(157)% array3)) then
          allocate(Agrif_Gr % tabvars(157)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N))
          Agrif_Gr % tabvars(157)% array3 = 0
      endif
      end subroutine Alloc_agrif_grid_Hz
      end module grid_Hz
      module grid_Hvom


        implicit none
        public :: Alloc_agrif_grid_Hvom
      contains
      subroutine Alloc_agrif_grid_Hvom(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : Hvom
          if (.not. allocated(Agrif_Gr % tabvars(158)% array3)) then
          allocate(Agrif_Gr % tabvars(158)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N))
          Agrif_Gr % tabvars(158)% array3 = 0
      endif
      end subroutine Alloc_agrif_grid_Hvom
      end module grid_Hvom
      module grid_Huon


        implicit none
        public :: Alloc_agrif_grid_Huon
      contains
      subroutine Alloc_agrif_grid_Huon(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : Huon
          if (.not. allocated(Agrif_Gr % tabvars(159)% array3)) then
          allocate(Agrif_Gr % tabvars(159)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N))
          Agrif_Gr % tabvars(159)% array3 = 0
      endif
      end subroutine Alloc_agrif_grid_Huon
      end module grid_Huon
      module grid_zw


        implicit none
        public :: Alloc_agrif_grid_zw
      contains
      subroutine Alloc_agrif_grid_zw(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : z_w
          if (.not. allocated(Agrif_Gr % tabvars(160)% array3)) then
          allocate(Agrif_Gr % tabvars(160)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,0 : N))
          Agrif_Gr % tabvars(160)% array3 = 0
      endif
      end subroutine Alloc_agrif_grid_zw
      end module grid_zw
      module grid_Hz_bak


        implicit none
        public :: Alloc_agrif_grid_Hz_bak
      contains
      subroutine Alloc_agrif_grid_Hz_bak(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : Hz_bak
          if (.not. allocated(Agrif_Gr % tabvars(161)% array3)) then
          allocate(Agrif_Gr % tabvars(161)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N))
          Agrif_Gr % tabvars(161)% array3 = 0
      endif
      end subroutine Alloc_agrif_grid_Hz_bak
      end module grid_Hz_bak
      module ocean_t


        implicit none
        public :: Alloc_agrif_ocean_t
      contains
      subroutine Alloc_agrif_ocean_t(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: ntrc_sed = 0
      integer(4), parameter :: ntrc_bio = 0
      integer(4), parameter :: ntrc_pas = 0
      integer(4), parameter :: ntrc_salt = 1
      integer(4), parameter :: itemp = 1
      integer(4), parameter :: NT = itemp+ntrc_salt+ntrc_pas+ntrc_bio+nt
     &rc_sed
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : t
          if (.not. allocated(Agrif_Gr % tabvars(162)% array5)) then
          allocate(Agrif_Gr % tabvars(162)% array5(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N,1 : 3,1 : NT))
          Agrif_Gr % tabvars(162)% array5 = 0
      endif
      end subroutine Alloc_agrif_ocean_t
      end module ocean_t
      module ocean_v


        implicit none
        public :: Alloc_agrif_ocean_v
      contains
      subroutine Alloc_agrif_ocean_v(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : v
          if (.not. allocated(Agrif_Gr % tabvars(163)% array4)) then
          allocate(Agrif_Gr % tabvars(163)% array4(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N,1 : 3))
          Agrif_Gr % tabvars(163)% array4 = 0
      endif
      end subroutine Alloc_agrif_ocean_v
      end module ocean_v
      module ocean_u


        implicit none
        public :: Alloc_agrif_ocean_u
      contains
      subroutine Alloc_agrif_ocean_u(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      integer(4), parameter :: N = 32
      !! ALLOCATION OF VARIABLE : u
          if (.not. allocated(Agrif_Gr % tabvars(164)% array4)) then
          allocate(Agrif_Gr % tabvars(164)% array4(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : N,1 : 3))
          Agrif_Gr % tabvars(164)% array4 = 0
      endif
      end subroutine Alloc_agrif_ocean_u
      end module ocean_u
      module coup_DV_avg2


        implicit none
        public :: Alloc_agrif_coup_DV_avg2
      contains
      subroutine Alloc_agrif_coup_DV_avg2(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : DV_avg2
          if (.not. allocated(Agrif_Gr % tabvars(165)% array2)) then
          allocate(Agrif_Gr % tabvars(165)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(165)% array2 = 0
      endif
      end subroutine Alloc_agrif_coup_DV_avg2
      end module coup_DV_avg2
      module coup_DU_avg2


        implicit none
        public :: Alloc_agrif_coup_DU_avg2
      contains
      subroutine Alloc_agrif_coup_DU_avg2(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : DU_avg2
          if (.not. allocated(Agrif_Gr % tabvars(166)% array2)) then
          allocate(Agrif_Gr % tabvars(166)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(166)% array2 = 0
      endif
      end subroutine Alloc_agrif_coup_DU_avg2
      end module coup_DU_avg2
      module coup_DV_avg1


        implicit none
        public :: Alloc_agrif_coup_DV_avg1
      contains
      subroutine Alloc_agrif_coup_DV_avg1(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : DV_avg1
          if (.not. allocated(Agrif_Gr % tabvars(167)% array3)) then
          allocate(Agrif_Gr % tabvars(167)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : 5))
          Agrif_Gr % tabvars(167)% array3 = 0
      endif
      end subroutine Alloc_agrif_coup_DV_avg1
      end module coup_DV_avg1
      module coup_DU_avg1


        implicit none
        public :: Alloc_agrif_coup_DU_avg1
      contains
      subroutine Alloc_agrif_coup_DU_avg1(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : DU_avg1
          if (.not. allocated(Agrif_Gr % tabvars(168)% array3)) then
          allocate(Agrif_Gr % tabvars(168)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : 5))
          Agrif_Gr % tabvars(168)% array3 = 0
      endif
      end subroutine Alloc_agrif_coup_DU_avg1
      end module coup_DU_avg1
      module ocean_Zt_avg1


        implicit none
        public :: Alloc_agrif_ocean_Zt_avg1
      contains
      subroutine Alloc_agrif_ocean_Zt_avg1(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : Zt_avg1
          if (.not. allocated(Agrif_Gr % tabvars(169)% array2)) then
          allocate(Agrif_Gr % tabvars(169)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(169)% array2 = 0
      endif
      end subroutine Alloc_agrif_ocean_Zt_avg1
      end module ocean_Zt_avg1
      module coup_rvfrc_bak


        implicit none
        public :: Alloc_agrif_coup_rvfrc_bak
      contains
      subroutine Alloc_agrif_coup_rvfrc_bak(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : rvfrc_bak
          if (.not. allocated(Agrif_Gr % tabvars(170)% array3)) then
          allocate(Agrif_Gr % tabvars(170)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : 2))
          Agrif_Gr % tabvars(170)% array3 = 0
      endif
      end subroutine Alloc_agrif_coup_rvfrc_bak
      end module coup_rvfrc_bak
      module coup_rufrc_bak


        implicit none
        public :: Alloc_agrif_coup_rufrc_bak
      contains
      subroutine Alloc_agrif_coup_rufrc_bak(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : rufrc_bak
          if (.not. allocated(Agrif_Gr % tabvars(171)% array3)) then
          allocate(Agrif_Gr % tabvars(171)% array3(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0,1 : 2))
          Agrif_Gr % tabvars(171)% array3 = 0
      endif
      end subroutine Alloc_agrif_coup_rufrc_bak
      end module coup_rufrc_bak
      module coup_rvfrc


        implicit none
        public :: Alloc_agrif_coup_rvfrc
      contains
      subroutine Alloc_agrif_coup_rvfrc(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : rvfrc
          if (.not. allocated(Agrif_Gr % tabvars(172)% array2)) then
          allocate(Agrif_Gr % tabvars(172)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(172)% array2 = 0
      endif
      end subroutine Alloc_agrif_coup_rvfrc
      end module coup_rvfrc
      module coup_rufrc


        implicit none
        public :: Alloc_agrif_coup_rufrc
      contains
      subroutine Alloc_agrif_coup_rufrc(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : rufrc
          if (.not. allocated(Agrif_Gr % tabvars(173)% array2)) then
          allocate(Agrif_Gr % tabvars(173)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(173)% array2 = 0
      endif
      end subroutine Alloc_agrif_coup_rufrc
      end module coup_rufrc
      module coup_rhoS


        implicit none
        public :: Alloc_agrif_coup_rhoS
      contains
      subroutine Alloc_agrif_coup_rhoS(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : rhoS
          if (.not. allocated(Agrif_Gr % tabvars(174)% array2)) then
          allocate(Agrif_Gr % tabvars(174)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(174)% array2 = 0
      endif
      end subroutine Alloc_agrif_coup_rhoS
      end module coup_rhoS
      module coup_rhoA


        implicit none
        public :: Alloc_agrif_coup_rhoA
      contains
      subroutine Alloc_agrif_coup_rhoA(Agrif_Gr)
        use Agrif_Util
        type(Agrif_grid), pointer :: Agrif_Gr
        integer :: i
      !! ALLOCATION OF VARIABLE : rhoA
          if (.not. allocated(Agrif_Gr % tabvars(175)% array2)) then
          allocate(Agrif_Gr % tabvars(175)% array2(-1 :  Agrif_tabvars_i
     &(2)%iarray0+2+ Agrif_tabvars_i(13)%iarray0,-1 :  Agrif_tabvars_i(4
     &)%iarray0+2+ Agrif_tabvars_i(14)%iarray0))
          Agrif_Gr % tabvars(175)% array2 = 0
      endif
      end subroutine Alloc_agrif_coup_rhoA
      end module coup_rhoA
