program test
implicit none
integer, parameter :: rk=selected_real_kind(15,307)
real(rk), dimension(256) :: dat
real(rk), dimension(128) :: sig
integer :: i
do i=1,128,1
sig(i) = sin(6.28318530717959_rk*0.12345_rk*real(i,rk))
end do
dat = 0._rk
dat(1:256:2) = sig
! fft call with a = 0 and b = 2
call fft(128,dat,0._rk,2.0_rk)
do i=1,2*10,2
write(*,*) dat(i), dat(i+1)
end do
contains
subroutine fft(num,arr,fp1,fp2)
implicit none
integer, parameter :: rk=selected_real_kind(15,307)
integer, intent(in) :: num
real(rk), intent(in) :: fp1
real(rk), intent(in) :: fp2
real(rk), intent(inout) :: arr(2*num)
integer :: n,i,j,m,lim,ste
real(rk) :: pim, pre, ang, wr, wi, wpr, wpi, wx
n=2*num
j=1
do i=1,n,2
if(j.gt.i)then
pre=arr(j)
pim=arr(j+1)
arr(j)=arr(i)
arr(j+1)=arr(i+1)
arr(i)=pre
arr(i+1)=pim
endif
m=n/2
1 if ((m.ge.2).and.(j.gt.m)) then
j=j-m
m=m/2
goto 1
endif
j=j+m
enddo
lim=2
2 if (n.gt.lim) then
ste=2*lim
ang=6.28318530717959_rk/real(lim,rk)*fp2 ! -- just mult 2 pi
wpr=-2.0_rk*sin(0.5_rk*ang)**2 ! -- ? *sign(1._rk,ang)
wpi=sin(ang)
wr=1.0_rk
wi=0.0_rk
do m=1,lim,2
do i=m,n,ste
j=i+lim
pre=wr*arr(j)-wi*arr(j+1)
pim=wr*arr(j+1)+wi*arr(j)
arr(j)=arr(i)-pre
arr(j+1)=arr(i+1)-pim
arr(i)=arr(i)+pre
arr(i+1)=arr(i+1)+pim
enddo
wx=wr
wr=wr*wpr-wi*wpi+wr
wi=wi*wpr+wx*wpi+wi
enddo
lim=ste
goto 2
endif
arr = arr/real(num,rk)**((1.0_rk-fp1)/2.0_rk)
return
end subroutine fft
end program test