Skip to content

Commit b745bb8

Browse files
authored
Merge pull request #35 from cval26/dct-interface
Combine dct and qct interfaces
2 parents 6a53d6f + 62396ea commit b745bb8

12 files changed

+512
-620
lines changed

doc/specs/fftpack.md

Lines changed: 351 additions & 404 deletions
Large diffs are not rendered by default.

src/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ set(FFTPACK_SOURCES
3131
${dir}/fftpack_fftshift.f90
3232
${dir}/fftpack_ifft.f90
3333
${dir}/fftpack_ifftshift.f90
34-
${dir}/fftpack_iqct.f90
3534
${dir}/fftpack_irfft.f90
36-
${dir}/fftpack_qct.f90
3735
${dir}/fftpack_rfft.f90
3836
${dir}/fftpack_utils.f90
3937
${dir}/passb.f90

src/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ SRCF90 = \
5757
fftpack_irfft.f90\
5858
fftpack_fftshift.f90\
5959
fftpack_ifftshift.f90\
60-
fftpack_qct.f90\
61-
fftpack_iqct.f90\
6260
fftpack_dct.f90\
6361
rk.f90\
6462
fftpack_utils.f90
@@ -82,8 +80,6 @@ fftpack_fft.o: fftpack.o rk.o
8280
fftpack_ifft.o: fftpack.o rk.o
8381
fftpack_rfft.o: fftpack.o rk.o
8482
fftpack_irfft.o: fftpack.o rk.o
85-
fftpack_qct.o: fftpack.o rk.o
86-
fftpack_iqct.o: fftpack.o rk.o
8783
fftpack_dct.o: fftpack.o rk.o
8884
fftpack_fftshift.o: fftpack.o rk.o
8985
fftpack_ifftshift.o: fftpack.o rk.o

src/fftpack.f90

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ module fftpack
1515
public :: dzffti, dzfftf, dzfftb
1616

1717
public :: dcosqi, dcosqf, dcosqb
18-
public :: qct, iqct
19-
2018
public :: dcosti, dcost
2119
public :: dct, idct
2220

@@ -246,46 +244,28 @@ end function irfft_rk
246244

247245
!> Version: experimental
248246
!>
249-
!> Forward transform of quarter wave data.
250-
!> ([Specifiction](../page/specs/fftpack.html#qct))
251-
interface qct
252-
pure module function qct_rk(x, n) result(result)
253-
real(kind=rk), intent(in) :: x(:)
254-
integer, intent(in), optional :: n
255-
real(kind=rk), allocatable :: result(:)
256-
end function qct_rk
257-
end interface qct
258-
259-
!> Version: experimental
260-
!>
261-
!> Backward transform of quarter wave data.
262-
!> ([Specifiction](../page/specs/fftpack.html#iqct))
263-
interface iqct
264-
pure module function iqct_rk(x, n) result(result)
265-
real(kind=rk), intent(in) :: x(:)
266-
integer, intent(in), optional :: n
267-
real(kind=rk), allocatable :: result(:)
268-
end function iqct_rk
269-
end interface iqct
270-
271-
!> Version: experimental
272-
!>
273-
!> Discrete fourier cosine (forward) transform of an even sequence.
247+
!> Dsicrete cosine transforms.
274248
!> ([Specification](../page/specs/fftpack.html#dct))
275249
interface dct
276-
pure module function dct_rk(x, n) result(result)
250+
pure module function dct_rk(x, n, type) result(result)
277251
real(kind=rk), intent(in) :: x(:)
278252
integer, intent(in), optional :: n
253+
integer, intent(in), optional :: type
279254
real(kind=rk), allocatable :: result(:)
280255
end function dct_rk
281256
end interface dct
282257

283258
!> Version: experimental
284259
!>
285-
!> Discrete fourier cosine (backward) transform of an even sequence.
260+
!> Inverse discrete cosine transforms.
286261
!> ([Specification](../page/specs/fftpack.html#idct))
287262
interface idct
288-
module procedure :: dct_rk
263+
pure module function idct_rk(x, n, type) result(result)
264+
real(kind=rk), intent(in) :: x(:)
265+
integer, intent(in), optional :: n
266+
integer, intent(in), optional :: type
267+
real(kind=rk), allocatable :: result(:)
268+
end function idct_rk
289269
end interface idct
290270

291271
!> Version: experimental

src/fftpack_dct.f90

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
contains
44

5-
!> Discrete fourier cosine transform of an even sequence.
6-
pure module function dct_rk(x, n) result(result)
5+
!> Discrete cosine transforms of types 1, 2, 3.
6+
pure module function dct_rk(x, n, type) result(result)
77
real(kind=rk), intent(in) :: x(:)
88
integer, intent(in), optional :: n
9+
integer, intent(in), optional :: type
910
real(kind=rk), allocatable :: result(:)
1011

1112
integer :: lenseq, lensav, i
@@ -23,14 +24,80 @@ pure module function dct_rk(x, n) result(result)
2324
result = x
2425
end if
2526

26-
!> Initialize FFT
27-
lensav = 3*lenseq + 15
28-
allocate (wsave(lensav))
29-
call dcosti(lenseq, wsave)
30-
31-
!> Discrete fourier cosine transformation
32-
call dcost(lenseq, result, wsave)
27+
! Default to DCT-2
28+
if (.not.present(type)) then
29+
lensav = 3*lenseq + 15
30+
allocate (wsave(lensav))
31+
call dcosqi(lenseq, wsave)
32+
call dcosqb(lenseq, result, wsave)
33+
return
34+
end if
3335

36+
if (type == 1) then ! DCT-1
37+
lensav = 3*lenseq + 15
38+
allocate (wsave(lensav))
39+
call dcosti(lenseq, wsave)
40+
call dcost(lenseq, result, wsave)
41+
else if (type == 2) then ! DCT-2
42+
lensav = 3*lenseq + 15
43+
allocate (wsave(lensav))
44+
call dcosqi(lenseq, wsave)
45+
call dcosqb(lenseq, result, wsave)
46+
else if (type == 3) then ! DCT-3
47+
lensav = 3*lenseq + 15
48+
allocate (wsave(lensav))
49+
call dcosqi(lenseq, wsave)
50+
call dcosqf(lenseq, result, wsave)
51+
end if
3452
end function dct_rk
3553

54+
!> Inverse discrete cosine transforms of types 1, 2, 3.
55+
pure module function idct_rk(x, n, type) result(result)
56+
real(kind=rk), intent(in) :: x(:)
57+
integer, intent(in), optional :: n
58+
integer, intent(in), optional :: type
59+
real(kind=rk), allocatable :: result(:)
60+
61+
integer :: lenseq, lensav, i
62+
real(kind=rk), allocatable :: wsave(:)
63+
64+
if (present(n)) then
65+
lenseq = n
66+
if (lenseq <= size(x)) then
67+
result = x(:lenseq)
68+
else if (lenseq > size(x)) then
69+
result = [x, (0.0_rk, i=1, lenseq - size(x))]
70+
end if
71+
else
72+
lenseq = size(x)
73+
result = x
74+
end if
75+
76+
! Default to t=2; inverse DCT-2 is DCT-3
77+
if (.not.present(type)) then
78+
lensav = 3*lenseq + 15
79+
allocate (wsave(lensav))
80+
call dcosqi(lenseq, wsave)
81+
call dcosqf(lenseq, result, wsave)
82+
return
83+
end if
84+
85+
if (type == 1) then ! inverse DCT-1 is DCT-1
86+
lensav = 3*lenseq + 15
87+
allocate (wsave(lensav))
88+
call dcosti(lenseq, wsave)
89+
call dcost(lenseq, result, wsave)
90+
else if (type == 2) then ! inverse DCT-2 is DCT-3
91+
lensav = 3*lenseq + 15
92+
allocate (wsave(lensav))
93+
call dcosqi(lenseq, wsave)
94+
call dcosqf(lenseq, result, wsave)
95+
else if (type == 3) then ! inverse DCT-3 is DCT-2
96+
lensav = 3*lenseq + 15
97+
allocate (wsave(lensav))
98+
call dcosqi(lenseq, wsave)
99+
call dcosqb(lenseq, result, wsave)
100+
end if
101+
end function idct_rk
102+
36103
end submodule fftpack_dct

src/fftpack_iqct.f90

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/fftpack_qct.f90

Lines changed: 0 additions & 36 deletions
This file was deleted.

test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ endmacro()
1414
set(FFTPACK_TEST_SOURCES
1515
test_fftpack_dct.f90
1616
test_fftpack_fft.f90
17-
test_fftpack_qct.f90
1817
test_fftpack_rfft.f90
1918
test_fftpack_utils.f90
2019
test_fftpack.f90

test/Makefile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ FETCH = curl -L
33
SRC = \
44
test_fftpack_fft.f90 \
55
test_fftpack_rfft.f90 \
6-
test_fftpack_qct.f90 \
76
test_fftpack_dct.f90 \
87
test_fftpack_utils.f90 \
98
test_fftpack.f90 \
109
testdrive.F90
11-
10+
1211
OBJ = $(SRC:.f90=.o)
1312
OBJ := $(OBJ:.F90=.o)
1413

@@ -24,10 +23,10 @@ tstfft: tstfft.f
2423
test_fftpack: $(OBJ)
2524
$(FC) $(FFLAGS) $(OBJ) -L../src -l$(LIB) -I../src -o $@.x
2625
./test_fftpack.x
27-
26+
2827
testdrive.F90:
2928
$(FETCH) https://github.com/fortran-lang/test-drive/raw/v0.4.0/src/testdrive.F90 > $@
30-
29+
3130
%.o: %.F90
3231
$(FC) $(FFLAGS) -c $<
3332

@@ -36,14 +35,12 @@ testdrive.F90:
3635

3736
test_fftpack.o: test_fftpack_fft.o \
3837
test_fftpack_rfft.o \
39-
test_fftpack_qct.o \
4038
test_fftpack_dct.o \
4139
test_fftpack_utils.o \
4240
testdrive.o
4341

4442
test_fftpack_fft.o: testdrive.o
4543
test_fftpack_rfft.o: testdrive.o
46-
test_fftpack_qct.o: testdrive.o
4744
test_fftpack_dct.o: testdrive.o
4845
test_fftpack_utils.o: testdrive.o
4946

test/test_fftpack.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ program test_fftpack
33
use testdrive, only: run_testsuite, new_testsuite, testsuite_type
44
use test_fftpack_fft, only: collect_fft
55
use test_fftpack_rfft, only: collect_rfft
6-
use test_fftpack_qct, only: collect_qct
76
use test_fftpack_dct, only: collect_dct
87
use test_fftpack_utils, only: collect_utils
98
implicit none
@@ -16,7 +15,6 @@ program test_fftpack
1615
testsuites = [ &
1716
new_testsuite("fft", collect_fft), &
1817
new_testsuite("rfft", collect_rfft), &
19-
new_testsuite("qct", collect_qct), &
2018
new_testsuite("dct", collect_dct), &
2119
new_testsuite("utils", collect_utils) &
2220
]

0 commit comments

Comments
 (0)