Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better expose the fftpack interface #47

Merged
merged 3 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/bench02_zfft.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
program main
program bench2
use fftpack, only: zffti, zfftf, zfftb, fft, ifft
use fftpack_kind, only: rk

Expand Down
2 changes: 1 addition & 1 deletion example/bench03_dfft.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
program main
program bench3
use fftpack, only: dffti, dfftf, dfftb, rfft, irfft
use fftpack_kind, only: rk

Expand Down
41 changes: 41 additions & 0 deletions example/real-forward-transform.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
program forward_transform_of_real_function
!! This program computes the forward transform of a real function and constructs
!! the complex result (re)organized to match the array subscripting to the common
!! analytical form [1]. Which form one uses in practice requires balancing the
!! need for speed versus clarity.
!!
!! [1] https://docs.scipy.org/doc/scipy/reference/generated/scipy.fftpack.rfft.html#scipy.fftpack.rfft
use fftpack, only: rfft, irfft
implicit none
integer j, k
integer, parameter :: N = 8
double precision, parameter :: two_pi = 2.D0*acos(-1.D0), tolerance = 1.0D-06, f_avg = 3.D0, zero=0.D0
double precision, parameter :: f(0:N-1) = f_avg + [(cos(two_pi*dble(j)/dble(N)), j=0,N-1)]
double precision, dimension(0:N-1) :: f_round_trip, rfft_f
integer, parameter :: rk = kind(two_pi)
complex(rk) f_hat(0:N/2)

call assert(mod(N,2)==0, "the algorithm below requires even N")

rfft_f(:) = rfft(f)/dble(N)
f_hat(:) = [ cmplx(rfft_f(0),zero), [( cmplx(k,k+1), k=lbound(rfft_f,1)+1,ubound(rfft_f,1)-1,2)], cmplx(zero,rfft_f(N-1)) ]
f_round_trip(:) = dble(irfft(rfft_f))
!call assert(any(abs(f_round_trip - f) < tolerance), "inverse of forward FFT must yield the original function")

print *, "f = ", f
print *, "f_hat = ", f_hat
print *, "f_round_trip = ", f_round_trip

!print '(3(10x,a,10x))',"f", "f_round_trip", "rfft_f"
!do m = 1, size(f)
! print *, f(m), f_round_trip(m), rfft_f(m)
!end do
!print *

contains
pure subroutine assert(assertion, description)
logical, intent(in) :: assertion
character(len=*), intent(in) :: description
if (.not. assertion) error stop description
end subroutine
end program
5 changes: 0 additions & 5 deletions fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ implicit-typing=true
implicit-external=true
source-form="default"

[build]
auto-executables = false
auto-tests = false
auto-examples = false

[dev-dependencies]
test-drive = { git = "https://github.com/fortran-lang/test-drive", tag = "v0.4.0" }

Expand Down
119 changes: 60 additions & 59 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,66 +1,67 @@
# Locate the source directory
# Locate the source directories
set(dir ${CMAKE_CURRENT_SOURCE_DIR})
set(subdir "${dir}/fftpack")

# The source files
set(FFTPACK_SOURCES
${dir}/cfftb1.f90
${dir}/cfftf1.f90
${dir}/cffti1.f90
${dir}/cosqb1.f90
${dir}/cosqf1.f90
${dir}/dcosqb.f90
${dir}/dcosqf.f90
${dir}/dcosqi.f90
${dir}/dcost.f90
${dir}/dcosti.f90
${dir}/dfftb.f90
${dir}/dfftf.f90
${dir}/dffti.f90
${dir}/dsinqb.f90
${dir}/dsinqf.f90
${dir}/dsinqi.f90
${dir}/dsint.f90
${dir}/dsinti.f90
${dir}/dzfftb.f90
${dir}/dzfftf.f90
${dir}/dzffti.f90
${dir}/ezfft1.f90
${subdir}/cfftb1.f90
${subdir}/cfftf1.f90
${subdir}/cffti1.f90
${subdir}/cosqb1.f90
${subdir}/cosqf1.f90
${subdir}/dcosqb.f90
${subdir}/dcosqf.f90
${subdir}/dcosqi.f90
${subdir}/dcost.f90
${subdir}/dcosti.f90
${subdir}/dfftb.f90
${subdir}/dfftf.f90
${subdir}/dffti.f90
${subdir}/dsinqb.f90
${subdir}/dsinqf.f90
${subdir}/dsinqi.f90
${subdir}/dsint.f90
${subdir}/dsinti.f90
${subdir}/dzfftb.f90
${subdir}/dzfftf.f90
${subdir}/dzffti.f90
${subdir}/ezfft1.f90
${dir}/fftpack.f90
${dir}/fftpack_dct.f90
${dir}/fftpack_fft.f90
${dir}/fftpack_fftshift.f90
${dir}/fftpack_ifft.f90
${dir}/fftpack_ifftshift.f90
${dir}/fftpack_irfft.f90
${dir}/fftpack_rfft.f90
${dir}/fftpack_utils.f90
${dir}/passb.f90
${dir}/passb2.f90
${dir}/passb3.f90
${dir}/passb4.f90
${dir}/passb5.f90
${dir}/passf.f90
${dir}/passf2.f90
${dir}/passf3.f90
${dir}/passf4.f90
${dir}/passf5.f90
${dir}/radb2.f90
${dir}/radb3.f90
${dir}/radb4.f90
${dir}/radb5.f90
${dir}/radbg.f90
${dir}/radf2.f90
${dir}/radf3.f90
${dir}/radf4.f90
${dir}/radf5.f90
${dir}/radfg.f90
${dir}/rfftb1.f90
${dir}/rfftf1.f90
${dir}/rffti1.f90
${dir}/rk.f90
${dir}/sint1.f90
${dir}/zfftb.f90
${dir}/zfftf.f90
${dir}/zffti.f90
${subdir}/fftpack_dct.f90
${subdir}/fftpack_fft.f90
${subdir}/fftpack_fftshift.f90
${subdir}/fftpack_ifft.f90
${subdir}/fftpack_ifftshift.f90
${subdir}/fftpack_irfft.f90
${subdir}/fftpack_rfft.f90
${subdir}/fftpack_utils.f90
${subdir}/passb.f90
${subdir}/passb2.f90
${subdir}/passb3.f90
${subdir}/passb4.f90
${subdir}/passb5.f90
${subdir}/passf.f90
${subdir}/passf2.f90
${subdir}/passf3.f90
${subdir}/passf4.f90
${subdir}/passf5.f90
${subdir}/radb2.f90
${subdir}/radb3.f90
${subdir}/radb4.f90
${subdir}/radb5.f90
${subdir}/radbg.f90
${subdir}/radf2.f90
${subdir}/radf3.f90
${subdir}/radf4.f90
${subdir}/radf5.f90
${subdir}/radfg.f90
${subdir}/rfftb1.f90
${subdir}/rfftf1.f90
${subdir}/rffti1.f90
${subdir}/rk.f90
${subdir}/sint1.f90
${subdir}/zfftb.f90
${subdir}/zfftf.f90
${subdir}/zffti.f90
)
set(FFTPACK_SOURCES ${FFTPACK_SOURCES} PARENT_SCOPE)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading