!===============================================================================
!
! nonactice.F90
!
!-------------------------------------------------------------------------------
!
! Copyright (C) 2009-2010 Yoshifumi Nakamura
!
! This file is part of BQCD -- Berlin Quantum ChromoDynamics program
!
! BQCD is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! BQCD is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with BQCD.  If not, see <http://www.gnu.org/licenses/>.
!
!-------------------------------------------------------------------------------
# include "defs.h"

!-------------------------------------------------------------------------------
subroutine nonactive(p)
  use module_dd
  use module_vol
  implicit none
  GENERATOR_FIELD, intent(inout) :: p
  integer :: i, j, eo, mu, ip

  if(.not. ddable) return
  if(ddallactive) return

  do mu = 1, DIM
  do ip = 0, ld%lat%num_ip-1
     do eo = EVEN, ODD
        do j = 1, ldnn(ip)%count_eo(eo,mu,FWD)
           i = ldnn(ip)%volh_eo(j,eo,mu,FWD)
           p(:,ddi2(i,eo,ip),ddeo2(i,eo,ip),mu)=ZERO
        enddo
     enddo
  enddo
  enddo

end

!-------------------------------------------------------------------------------
subroutine paratransu(u)
  use module_dd
  use module_vol
  use module_counter
  use module_function_decl
  implicit none
  GAUGE_FIELD, intent(inout) :: u
  integer :: i, j, eo, mu
  integer :: n , v(4)
  REAL :: tmp
  REAL,external ::sg

  if(.not. ddable) return
  if(ddallactive) return

  TIMING_START(timing_bin_hmc_xbound_g)
  call xbound_g_field(u)
  TIMING_STOP(timing_bin_hmc_xbound_g)

  !! for check
  !!
  tmp=sg(u)
  if (my_pe()==0) write(0,*)"before trans, 1st conp. of u, 1-p",u(1,1,1,0,1), tmp

  n =10
  do i=1,4
     n=min(n,ld%lat%n(i))
  enddo
  n = n/2
  
  !!
  !! counter accepted traj may be better 
  !!
  if (mod(counter%traj,n)==0) then
     do i= 1,4
        v(i)=int(ran_number() * dble(ld%lat%n(i)))
     enddo
  else
     v=nint(dble(ld%lat%n)/dble(n))
  endif

  do i=1,4
     do j=1,v(i) !!                     dir
        call gauge_field_translation(u, i)
     enddo
  enddo

  tmp=sg(u)
  if (my_pe()==0) write(0,*)"after  trans, 1st conp. of u, 1-p",u(1,1,1,0,1), tmp

end

!-------------------------------------------------------------------------------
subroutine gauge_field_translation(u, dir)
  use module_nn
  use module_vol
  implicit none
  GAUGE_FIELD, intent(inout) :: u
  GAUGE_FIELD :: utt
  integer :: i, j, eo, mu, dir

  do mu = 1, DIM
     do eo = EVEN, ODD
        do i = 1, volh
           j = nn(i, eo, dir, BWD)
           utt(:,:,i,eo,mu)=u(:,:,j,1-eo,mu)
        enddo
     enddo
  enddo

  TIMING_START(timing_bin_hmc_xbound_g)
  call xbound_g_field(utt)
  TIMING_STOP(timing_bin_hmc_xbound_g)
  u=utt

end

!===============================================================================
