!===============================================================================
!
! support_bagel.F90
!
!-------------------------------------------------------------------------------
!
! Copyright (C) 2008 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 allocate_bagel_d()
  use module_vol
  use module_field
  implicit none

  allocate(bagel_u(NCOL, NCOL, DIM, volh, 0:1))

end

!-------------------------------------------------------------------------------
subroutine copy_u_bagel_d()
  use module_field
  use module_vol
  implicit none
  integer :: i, mu, c1, c2, eo

  do i = 1, volh
     do mu = 1, DIM
        do eo = 0, 1
           do c2 = 1, NCOL
           do c1 = 1, NCOL
              bagel_u(c1, c2, mu, i, eo) = gauge(2)%u(c1, c2, i, eo, mu)
           enddo
           enddo
        enddo
     enddo
  enddo

end

!-------------------------------------------------------------------------------
subroutine scfield_reorder_43_to_34(inout)
  use module_vol
  implicit none
  COMPLEX, dimension (12, volh_tot) :: inout
  integer :: i

  do i = 1, volh
     call sc_reorder_43_to_34(inout(1,i))
  enddo

end

!-------------------------------------------------------------------------------
subroutine scfield_reorder_34_to_43(inout)
  use module_vol
  implicit none
  COMPLEX, dimension (12, volh_tot) :: inout
  integer :: i

  do i = 1, volh
     call sc_reorder_34_to_43(inout(1,i))
  enddo

end

!-------------------------------------------------------------------------------
subroutine sc_reorder_43_to_34(inout)
  implicit none
  COMPLEX, dimension (12) :: inout, tmp
  integer :: i

  tmp=inout

  inout(2 ) = tmp(5 )
  inout(3 ) = tmp(9 )
  inout(4 ) = tmp(2 )
  inout(5 ) = tmp(6 )
  inout(6 ) = tmp(10)
  inout(7 ) = tmp(3 )
  inout(8 ) = tmp(7 )
  inout(9 ) = tmp(11)
  inout(10) = tmp(4 )
  inout(11) = tmp(8 )

end

!-------------------------------------------------------------------------------
subroutine sc_reorder_34_to_43(inout)
  implicit none
  COMPLEX, dimension (12) :: inout, tmp

  tmp=inout

  inout(5 ) = tmp(2 )
  inout(9 ) = tmp(3 )
  inout(2 ) = tmp(4 )
  inout(6 ) = tmp(5 )
  inout(10) = tmp(6 )
  inout(3 ) = tmp(7 )
  inout(7 ) = tmp(8 )
  inout(11) = tmp(9 )
  inout(4 ) = tmp(10)
  inout(8 ) = tmp(11)

end

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