!===============================================================================
!
! h_mult_r8.F90
!
!-------------------------------------------------------------------------------
!
! 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/>.
!
!-------------------------------------------------------------------------------
! Author: Taylor Haar
!-------------------------------------------------------------------------------
# include "defs.h"

!-------------------------------------------------------------------------------
subroutine g5wmul_r8(out, in, id)  ! out = g5 W in
  use module_vol
  implicit none

  COMPLEX, dimension (NDIRAC, *) :: out, in
  integer :: id

  integer :: i
  COMPLEX :: x1, x2, x3, x4

  call wmul_r8(out, in, id)

  do i = 1, NCOL * volh
     x1 = out(1, i)
     x2 = out(2, i)
     x3 = out(3, i)
     x4 = out(4, i)
     
     out(1, i) = x3
     out(2, i) = x4
     out(3, i) = x1
     out(4, i) = x2
  enddo

end subroutine g5wmul_r8
!-------------------------------------------------------------------------------

subroutine wdagg5_r8(out, in, id)  ! out = Wdag g5 in
  use module_vol
  use module_p_interface
  implicit none

  SPINCOL_FIELD, intent(out) :: out
  SPINCOL_FIELD, intent(in)  :: in
  P_SPINCOL_FIELD, save :: tmp

  integer :: id

  integer :: i, c
  COMPLEX :: x1, x2, x3, x4

  ALLOCATE_SC_FIELD(tmp)

  do c = 1, NCOL
     do i = 1, volh
        tmp(1, c, i) = in(3, c, i)
        tmp(2, c, i) = in(4, c, i)
        tmp(3, c, i) = in(1, c, i)
        tmp(4, c, i) = in(2, c, i)        
     enddo
  enddo

  call wdag_r8(out, tmp(1,1,1), id)

end subroutine wdagg5_r8

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