!===============================================================================
!
! dd_test.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 dd_test()
  use module_dd
  use module_lattice
  use module_function_decl
  implicit none
  integer :: x,y,z,t,global(4),local(4), home,i,eo,mu,fb
  integer,external :: xyzt2i_dd, e_o_dd

  do t = 0, n(4)-1
  do z = 0, n(3)-1
  do y = 0, n(2)-1
  do x = 0, n(1)-1
     global = (/x, y, z, t/)
     call global2local_dd(global, home, local,ld%lat)
     i=xyzt2i_dd(local,home,ld%lat)
     eo=e_o_dd(local, home,ld%lat)

     if (eo==0) write(0,106)"home",home,x,y,z,t,i,"E"
     if (eo==1) write(0,106)"home",home,x,y,z,t,i,"O"
  enddo
  enddo
  enddo
  enddo
106 format (a4, i6, 5x,5i5,x,a1)

end

!-------------------------------------------------------------------------------
subroutine dd_test2()
  use module_dd
  implicit none
  integer :: ip, i,eo,mu,fb

do ip=0,0!ld%lat%num_ip-1

  do mu= 1,4
  do fb=FWD,BWD
  do eo=0,1
  do i=1,ld%lat%volh_tot
  write(0,100)"home",ip, mu,fb,eo,i, ldnn(ip)%nn(i,eo,mu,fb)
  enddo
  enddo
  enddo
  enddo
enddo

100 format (a4, i10, 1x, 4i5, i15)

end

!-------------------------------------------------------------------------------
subroutine test_xbound_sc2_dd()
  use module_xbound_sc2_dd
  use module_dd
  implicit none
  integer :: mu, fb,i,ip

do ip=0,ld%lat%num_ip-1

  do mu = 1, DIM
  do fb = FWD, BWD
     i = xbsc2(ip)%i_bound(mu, fb)
     if (i /= 0) then
        write(0,100)ip,mu,fb, &
                  xbsc2(ip)%b(i)%i_source, &
                  xbsc2(ip)%b(i)%i_target, &
                  xbsc2(ip)%b(i)%dm_source, &
                  xbsc2(ip)%b(i)%dm_target, &
                  xbsc2(ip)%b(i)%size, &
                  xbsc2(ip)%b(i)%block_count, &
                  xbsc2(ip)%b(i)%block_size, &
                  xbsc2(ip)%b(i)%block_stride
     endif
  enddo
  enddo

enddo

100 format (12i6)
end

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