!===============================================================================
!
! i2ddi.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 i2ddi()
  use module_dd
  use module_lattice
  use module_vol
  implicit none
  integer :: i, eo, x,y,z,t
  integer :: local(4),ddlocal(4), home
  integer, external :: e_o, xyzt2i, e_o_ld, xyzt2i_dd

  allocate(ddi( volh, EVEN:ODD))
  allocate(ddeo(volh, EVEN:ODD))
  allocate(ddip(volh, EVEN:ODD))

  allocate(ddi2( ld%lat%volh, EVEN:ODD, 0:ld%lat%num_ip-1))
  allocate(ddeo2(ld%lat%volh, EVEN:ODD, 0:ld%lat%num_ip-1))

  do t = 0, n(4)-1
  do z = 0, n(3)-1
  do y = 0, n(2)-1
  do x = 0, n(1)-1
     local = (/x, y, z, t/)
     i  = xyzt2i(local)
     eo = e_o(local)

     call global2local_dd(local, home, ddlocal,ld%lat)

     ddi( i,eo) = xyzt2i_dd(ddlocal,home,ld%lat)
!!     ddeo(i,eo) = e_o_dd(   ddlocal,home,ld%lat)
     ddeo(i,eo) = e_o_ld(   ddlocal,home)
     ddip(i,eo) = home

     ddi2( ddi(i,eo),ddeo(i,eo),ddip(i,eo))=i
     ddeo2(ddi(i,eo),ddeo(i,eo),ddip(i,eo))=eo
  enddo
  enddo
  enddo
  enddo

end

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