!===============================================================================
!
! cg_proj.F90
!
!-------------------------------------------------------------------------------
!
! Copyright (C) 2016 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/>.
!
!-------------------------------------------------------------------------------
# define LANGUAGE_FORTRAN
# include "defs.h"
# include "cg_defs.h"

!-------------------------------------------------------------------------------
subroutine T(cg_proj)(proj, in, mu0, dag)

  use module_nnpe
  use module_lattice
  use typedef_simd
  use T(module_vol)
  implicit none
  sc2_FIELD, intent(out) :: proj
  spincol_FIELD, intent(in) :: in
  integer, intent(in) :: mu0
  integer, intent(in) :: dag
  integer :: mu, mu1, mu2

  if (mu0 == 0) then
     mu1 = 2
     mu2 = DIM
  else
     mu1 = mu0
     mu2 = mu0
  endif

  if (dag == 0) then

     do mu = mu1, mu2
        if (npe(mu) == 1) cycle
        select case (mu)
        case (2)
           call T(cg_proj_yf)(proj, in)
           call T(cg_proj_yb)(proj, in)
        case (3)
           call T(cg_proj_zf)(proj, in)
           call T(cg_proj_zb)(proj, in)
        end select
     enddo

  else

     do mu = mu1, mu2
        if (npe(mu) == 1) cycle
        select case (mu)
        case (2)
           call T(cg_proj_dag_yf)(proj, in)
           call T(cg_proj_dag_yb)(proj, in)
        case (3)
           call T(cg_proj_dag_zf)(proj, in)
           call T(cg_proj_dag_zb)(proj, in)
        end select
     enddo

  endif

end

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