1!
2! Copyright (C) 2004 PWSCF group
3! This file is distributed under the terms of the
4! GNU General Public License. See the file `License'
5! in the root directory of the present distribution,
6! or http://www.gnu.org/copyleft/gpl.txt .
7!
8subroutine vpack (ndim, ndimx, nspin, vin, vout, iflag)
9  use kinds, ONLY: DP
10  implicit none
11  integer :: ndim, ndimx, nspin, iflag, n
12
13  real(DP) :: vin (ndimx * nspin), vout (ndimx * nspin)
14  if (nspin.eq.1.or.ndim.eq.ndimx) return
15  if (iflag.eq.1) then
16     do n = 1, ndim
17        vin (n + ndim) = vin (n + ndimx)
18        vout (n + ndim) = vout (n + ndimx)
19     enddo
20  elseif (iflag.eq. - 1) then
21     do n = ndim, 1, - 1
22        vin (n + ndimx) = vin (n + ndim)
23        vout (n + ndimx) = vout (n + ndim)
24     enddo
25     do n = ndim + 1, ndimx
26        vin (n) = 0.0_DP
27        vout (n) = 0.0_DP
28     enddo
29  else
30     call errore ('vpack', ' wrong flag ', 1)
31
32  endif
33  return
34end subroutine vpack
35