module swaps !--------------------------------------------- ! SWAP Subtoutines !--------------------------------------------- ! HISTORY ! 2020/10/29 [v1.0 ] author = Koji KOBAYASHI ! 2020/11/ 4 [v1.0.1] usage !--------------------------------------------- ! REQUIREMENTS ! None (stand alone) !--------------------------------------------- ! USAGE ! use swaps ! integer :: i,j ! integer :: ivec(3),jvec(3) ! integer :: iMat(2,2),jMat(2,2) ! real(kind(0d0)) :: a,b ! real(kind(0d0)) :: avec(3),bvec(3) ! real(kind(0d0)) :: aMat(2,2),bMat(2,2) ! complex(kind(0d0)) :: za,zb ! complex(kind(0d0)) :: zavec(3),zbvec(3) ! complex(kind(0d0)) :: zaMat(2,2),zbMat(2,2) ! call swap(i,j) ! call swap(ivec,jvec) ! call swap(iMat,jMat) ! call swap(a,b) ! call swap(avec,bvec) ! call swap(aMat,bMat) ! call swap(za,zb) ! call swap(zavec,zbvec) ! call swap(zaMat,zbMat) !--------------------------------------------- implicit none private INTERFACE swap module procedure swap_i,swap_d,swap_z end INTERFACE public :: swap CONTAINS !--------------------------------------------- ! integer !--------------------------------------------- pure elemental subroutine swap_i(a,b) integer, intent(inout) :: a, b integer :: temp temp = a ; a = b ; b = temp end subroutine !--------------------------------------------- !--------------------------------------------- ! double !--------------------------------------------- pure elemental subroutine swap_d(a,b) real(kind(0d0)), intent(inout) :: a, b real(kind(0d0)) :: temp temp = a ; a = b ; b = temp end subroutine !--------------------------------------------- !--------------------------------------------- ! double complex !--------------------------------------------- pure elemental subroutine swap_z(a,b) complex(kind(0d0)), intent(inout) :: a, b complex(kind(0d0)) :: temp temp = a ; a = b ; b = temp end subroutine !--------------------------------------------- end module swaps