program test complex, dimension(:), allocatable :: a, b, c real, dimension(:), allocatable :: x complex, parameter :: zi = (0., 1.) real, parameter :: pi = 3.1415926535897931 complex :: res integer :: k1, k2, nx, j namelist /input/k1, k2, nx open (unit=11, file='test.in', status='old') read (11, input) close (11) allocate (a(-nx/2:nx/2)) ; a = 0. allocate (b(-nx/2:nx/2)) ; b = 0. allocate (c(-nx/2:nx/2)) ; c = 0. allocate (x(-nx/2:nx/2)) ; x = 0. do j = -nx/2, nx/2 x(j) = 2*pi*j/nx end do a = (exp(zi*k1*x)+exp(-zi*k1*x)) b = (exp(zi*k2*x)+exp(-zi*k2*x)) ! ! This is the inner product ! res = sum(a(-nx/2+1:) * conjg(b(-nx/2+1:)))/(2*nx) res = 0. do j=-nx/2+1, nx/2 res = res + a(j)*conjg(b(j)) end do res = res/(2*nx) write(*,*) res open (unit=12, file='test.out') do j = -nx/2, nx/2 write(12,*) 2*j*pi/nx, real(a(j)), real(b(j)), & aimag(a(j)), aimag(b(j)) end do close (12) end program test