!===============================================================================
!
! cg_copy_spincol.F90
!
!-------------------------------------------------------------------------------
!
! Copyright (C) 2012-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"

!-------------------------------------------------------------------------------
# undef TRACE_NAME
# define TRACE_NAME T(cg_copyin)
!-------------------------------------------------------------------------------
subroutine T(cg_copyin)(out, in)

  use module_vol
  implicit none
  complex(8), intent(in)     :: in(NDIRAC2, NDIRAC2, NCOL, volh_tot)
  spincol_FIELD, intent(out) :: out
  integer :: i

  TRACE_ENTRY

  !$omp parallel do
  do i = 1, volh
  DO c = 1, 3
  DO s2 = 1, 2
  DO s1 = 1, 2
     Spincol(out, s1, s2, c, i) = in(s1, s2, c, i)  
  ENDDO
  ENDDO
  ENDDO
  enddo

  TRACE_RETURN
end

!-------------------------------------------------------------------------------
# undef TRACE_NAME
# define TRACE_NAME T(cg_copyout)
!-------------------------------------------------------------------------------
subroutine T(cg_copyout)(out, in)

  use module_vol
  implicit none
  spincol_FIELD, intent(in) :: in
  complex(8), intent(out)   :: out(NDIRAC2, NDIRAC2, NCOL, volh_tot)
  integer :: i

  TRACE_ENTRY

  !$omp parallel do
  do i = 1, volh
  DO c = 1, 3
  DO s2 = 1, 2
  DO s1 = 1, 2
     out(s1, s2, c, i) = Spincol(in, s1, s2, c, i)
  ENDDO
  ENDDO
  ENDDO
  enddo

  TRACE_RETURN
end

!-------------------------------------------------------------------------------
# undef TRACE_NAME
# define TRACE_NAME T(cg_copy_caxpy)
!-------------------------------------------------------------------------------
subroutine T(cg_copy_caxpy)(inout, in, a)  ! inout = inout + a * in

  use module_vol
  implicit none
  complex(8), intent(inout) :: inout(NDIRAC2, NDIRAC2, NCOL, volh_tot)
  spincol_FIELD, intent(in) :: in
  COMPLEX, intent(in)       :: a
  integer :: i

  TRACE_ENTRY

  !$omp parallel do
  do i = 1, volh
  DO c = 1, 3
  DO s2 = 1, 2
  DO s1 = 1, 2
     inout(s1, s2, c, i) = inout(s1, s2, c, i) + a * Spincol(in, s1, s2, c, i)
  ENDDO
  ENDDO
  ENDDO
  enddo

  TRACE_RETURN
end

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