!===============================================================================
!
! D_PROJxyzt.F90 - projections onto 2 spincol components
!
!-------------------------------------------------------------------------------
!
! Copyright (C) 2010 Hinnerk Stueben
!
! 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"

#ifdef PRECISION_R4
# include "defs_r4.h"
#endif

!-------------------------------------------------------------------------------
#ifdef FORWARD
# define FB FWD
# define minus MINUS
# define plus PLUS
#else
# define FB BWD
# define minus PLUS
# define plus MINUS
#endif

#ifdef DAGGER
# define PLUS -
# define MINUS +
# define D_T_ONE 3
# define D_T_TWO 4
# define D_T_THREE 1 
# define D_T_FOUR 2
#else
# define PLUS +
# define MINUS -
# define D_T_ONE 1
# define D_T_TWO 2
# define D_T_THREE 3 
# define D_T_FOUR 4
#endif

#ifdef DIR_X
# define MU 1
# define GAMMA_A1(C) a(1, C, j) minus i_times(a(4, C, j))
# define GAMMA_A2(C) a(2, C, j) minus i_times(a(3, C, j))
#endif

#ifdef DIR_Y
# define MU 2
# define GAMMA_A1(C) a(1, C, j) minus a(4, C, j)
# define GAMMA_A2(C) a(2, C, j) plus  a(3, C, j)
#endif

#ifdef DIR_Z
# define MU 3
# define GAMMA_A1(C) a(1, C, j) minus i_times(a(3, C, j))
# define GAMMA_A2(C) a(2, C, j) plus  i_times(a(4, C, j))
#endif

#ifdef DIR_T
# define MU 4
#ifdef FORWARD
# define GAMMA_A1(C) a(D_T_THREE, C, j)
# define GAMMA_A2(C) a(D_T_FOUR, C, j)
#else
# define GAMMA_A1(C) a(D_T_ONE, C, j)
# define GAMMA_A2(C) a(D_T_TWO, C, j)
#endif
#endif

!-------------------------------------------------------------------------------
#ifdef PRECISION_R4
subroutine STRCAT(NAME, _r4)(eo, proj, a)
#else
subroutine NAME(eo, proj, a)
#endif

  use module_surface
  use module_vol
  implicit none
  integer, intent(in)  :: eo
  COMPLEX, intent(out) :: proj(2, NCOL, *)
  SPINCOL_FIELD, intent(in) :: a
  integer :: i, j

# include "i_times.h"

  do i = 1, surface(eo, MU, FB)%nsites
     j = surface(eo, MU, FB)%site(i)
     proj(1, 1, i) = GAMMA_A1(1)
     proj(2, 1, i) = GAMMA_A2(1)
     proj(1, 2, i) = GAMMA_A1(2)
     proj(2, 2, i) = GAMMA_A2(2)
     proj(1, 3, i) = GAMMA_A1(3)
     proj(2, 3, i) = GAMMA_A2(3)
  enddo

end

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