Skip to content

Commit fa10e9c

Browse files
committed
review 1 changes
1 parent cb99ff5 commit fa10e9c

File tree

4 files changed

+56
-52
lines changed

4 files changed

+56
-52
lines changed

doc/specs/fftpack.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ Pure function.
11431143

11441144
### Syntax
11451145

1146-
`result = [[fftpack(module):dct(interface)]](x [, n, t])`
1146+
`result = [[fftpack(module):dct(interface)]](x [, n, type])`
11471147

11481148
### Argument
11491149

@@ -1155,7 +1155,7 @@ The data to transform.
11551155
This argument is `intent(in)` and `optional`.
11561156
Defines the length of the DCT. If `n` is not specified (the default) then `n = size(x)`. If `n <= size(x)`, `x` is truncated, if `n > size(x)`, `x` is zero-padded.
11571157

1158-
`t`: Shall be an `integer` scalar, equal to `1`, `2` or `3`.
1158+
`type`: Shall be an `integer` scalar, equal to `1`, `2` or `3`.
11591159
This argument is `intent(in)` and `optional`.
11601160
Defines the type of DCT to be performed. The default type is `2`.
11611161

@@ -1166,9 +1166,9 @@ Returns a `real` and rank-1 array, the DCT type-`t` of the input data `x`.
11661166
#### Notes
11671167

11681168
Within numerical accuracy,
1169-
- `x == idct(dct(x, t=1), t=1) / (2*(size(x) - 1))`
1170-
- `x == idct(dct(x, t=2), t=2) / (4*size(x))`
1171-
- `x == idct(dct(x, t=3), t=3) / (4*size(x))`
1169+
- `x == idct(dct(x, type=1), type=1) / (2*(size(x) - 1))`
1170+
- `x == idct(dct(x, type=2), type=2) / (4*size(x))`
1171+
- `x == idct(dct(x, type=3), type=3) / (4*size(x))`
11721172

11731173
### Example
11741174

@@ -1177,9 +1177,9 @@ program demo_dct
11771177
use fftpack, only: dct
11781178
real(kind=8) :: x(4) = [1, 2, 3, 4]
11791179
print *, dct(x,3,1) !! [8.0, -2.0, 0.0].
1180-
print *, dct(x,t=1) !! [15.0, -4.0, 0.0, -1.0].
1180+
print *, dct(x,type=1) !! [15.0, -4.0, 0.0, -1.0].
11811181
print *, dct(x,5,2) !! [14.36, -6.11, -5.0, 4.40, -2.65].
1182-
print *, dct(dct(x,t=1),t=1)/(2*(4 - 1)) !! (normalized): [1.0, 2.0, 3.0, 4.0]
1182+
print *, dct(dct(x,type=1),type=1)/(2*(4 - 1)) !! (normalized): [1.0, 2.0, 3.0, 4.0]
11831183
end program demo_dct
11841184
```
11851185

@@ -1201,7 +1201,7 @@ Pure function.
12011201

12021202
### Syntax
12031203

1204-
`result = [[fftpack(module):idct(interface)]](x [, n, t])`
1204+
`result = [[fftpack(module):idct(interface)]](x [, n, type])`
12051205

12061206
### Argument
12071207

@@ -1213,7 +1213,7 @@ Transformed data to invert.
12131213
This argument is `intent(in)` and `optional`.
12141214
Defines the length of the Fourier transform. If `n` is not specified (the default) then `n = size(x)`. If `n <= size(x)`, `x` is truncated, if `n > size(x)`, `x` is zero-padded.
12151215

1216-
`t`: Shall be an `integer` scalar, equal to `1` or `2`.
1216+
`type`: Shall be an `integer` scalar, equal to `1` or `2`.
12171217
This argument is `intent(in)` and `optional`.
12181218
Defines the type of the IDCT to be performed. The default type is `2`.
12191219

@@ -1224,19 +1224,19 @@ Returns a `real` and rank-1 array, the IDCT type-`t` of the input data `x`.
12241224
#### Notes
12251225

12261226
Within numerical accuracy,
1227-
- `x == idct(dct(x, t=1), t=1) / (2*(size(x) - 1))`
1228-
- `x == idct(dct(x, t=2), t=2) / (4*size(x))`
1229-
- `x == idct(dct(x, t=3), t=3) / (4*size(x))`
1227+
- `x == idct(dct(x, type=1), type=1) / (2*(size(x) - 1))`
1228+
- `x == idct(dct(x, type=2), type=2) / (4*size(x))`
1229+
- `x == idct(dct(x, type=3), type=3) / (4*size(x))`
12301230

12311231
### Example
12321232

12331233
```fortran
12341234
program demo_idct
12351235
use fftpack, only: dct, idct
12361236
real(kind=8) :: x(4) = [1, 2, 3, 4]
1237-
print *, idct(dct(x,t=1),t=1)/(2*(4-1)) !! (normalized): [1.0, 2.0, 3.0, 4.0]
1238-
print *, idct(dct(x,t=2),t=2)/(4*4) !! (normalized): [1.0, 2.0, 3.0, 4.0]
1239-
print *, idct(dct(x), n=3) !! (unnormalized): [22.06, 32.5, 65.65]
1237+
print *, idct(dct(x,type=1),type=1)/(2*(4-1)) !! (normalized): [1.0, 2.0, 3.0, 4.0]
1238+
print *, idct(dct(x,type=2),type=2)/(4*4) !! (normalized): [1.0, 2.0, 3.0, 4.0]
1239+
print *, idct(dct(x), n=3) !! (unnormalized): [22.06, 32.5, 65.65]
12401240
end program demo_idct
12411241
```
12421242

src/fftpack.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@ end function irfft_rk
247247
!> Dsicrete cosine transforms.
248248
!> ([Specification](../page/specs/fftpack.html#dct))
249249
interface dct
250-
pure module function dct_rk(x, n, t) result(result)
250+
pure module function dct_rk(x, n, type) result(result)
251251
real(kind=rk), intent(in) :: x(:)
252252
integer, intent(in), optional :: n
253-
integer, intent(in), optional :: t
253+
integer, intent(in), optional :: type
254254
real(kind=rk), allocatable :: result(:)
255255
end function dct_rk
256256
end interface dct
@@ -260,10 +260,10 @@ end function dct_rk
260260
!> Inverse discrete cosine transforms.
261261
!> ([Specification](../page/specs/fftpack.html#idct))
262262
interface idct
263-
pure module function idct_rk(x, n, t) result(result)
263+
pure module function idct_rk(x, n, type) result(result)
264264
real(kind=rk), intent(in) :: x(:)
265265
integer, intent(in), optional :: n
266-
integer, intent(in), optional :: t
266+
integer, intent(in), optional :: type
267267
real(kind=rk), allocatable :: result(:)
268268
end function idct_rk
269269
end interface idct

src/fftpack_dct.f90

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
contains
44

55
!> Discrete cosine transforms of types 1, 2, 3.
6-
pure module function dct_rk(x, n, t) result(result)
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 :: t
9+
integer, intent(in), optional :: type
1010
real(kind=rk), allocatable :: result(:)
1111

1212
integer :: lenseq, lensav, i
@@ -25,25 +25,25 @@ pure module function dct_rk(x, n, t) result(result)
2525
end if
2626

2727
! Default to DCT-2
28-
if (.not.present(t)) then
28+
if (.not.present(type)) then
2929
lensav = 3*lenseq + 15
3030
allocate (wsave(lensav))
3131
call dcosqi(lenseq, wsave)
3232
call dcosqb(lenseq, result, wsave)
3333
return
3434
end if
3535

36-
if (t == 1) then ! DCT-1
36+
if (type == 1) then ! DCT-1
3737
lensav = 3*lenseq + 15
3838
allocate (wsave(lensav))
3939
call dcosti(lenseq, wsave)
4040
call dcost(lenseq, result, wsave)
41-
else if (t == 2) then ! DCT-2
41+
else if (type == 2) then ! DCT-2
4242
lensav = 3*lenseq + 15
4343
allocate (wsave(lensav))
4444
call dcosqi(lenseq, wsave)
4545
call dcosqb(lenseq, result, wsave)
46-
else if (t == 3) then ! DCT-3
46+
else if (type == 3) then ! DCT-3
4747
lensav = 3*lenseq + 15
4848
allocate (wsave(lensav))
4949
call dcosqi(lenseq, wsave)
@@ -52,10 +52,10 @@ pure module function dct_rk(x, n, t) result(result)
5252
end function dct_rk
5353

5454
!> Inverse discrete cosine transforms of types 1, 2, 3.
55-
pure module function idct_rk(x, n, t) result(result)
55+
pure module function idct_rk(x, n, type) result(result)
5656
real(kind=rk), intent(in) :: x(:)
5757
integer, intent(in), optional :: n
58-
integer, intent(in), optional :: t
58+
integer, intent(in), optional :: type
5959
real(kind=rk), allocatable :: result(:)
6060

6161
integer :: lenseq, lensav, i
@@ -74,25 +74,25 @@ pure module function idct_rk(x, n, t) result(result)
7474
end if
7575

7676
! Default to t=2; inverse DCT-2 is DCT-3
77-
if (.not.present(t)) then
77+
if (.not.present(type)) then
7878
lensav = 3*lenseq + 15
7979
allocate (wsave(lensav))
8080
call dcosqi(lenseq, wsave)
8181
call dcosqf(lenseq, result, wsave)
8282
return
8383
end if
8484

85-
if (t == 1) then ! inverse DCT-1 is DCT-1
85+
if (type == 1) then ! inverse DCT-1 is DCT-1
8686
lensav = 3*lenseq + 15
8787
allocate (wsave(lensav))
8888
call dcosti(lenseq, wsave)
8989
call dcost(lenseq, result, wsave)
90-
else if (t == 2) then ! inverse DCT-2 is DCT-3
90+
else if (type == 2) then ! inverse DCT-2 is DCT-3
9191
lensav = 3*lenseq + 15
9292
allocate (wsave(lensav))
9393
call dcosqi(lenseq, wsave)
9494
call dcosqf(lenseq, result, wsave)
95-
else if (t == 3) then ! inverse DCT-3 is DCT-2
95+
else if (type == 3) then ! inverse DCT-3 is DCT-2
9696
lensav = 3*lenseq + 15
9797
allocate (wsave(lensav))
9898
call dcosqi(lenseq, wsave)

test/test_fftpack_dct.f90

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ subroutine test_modernized_dct(error)
5656
! DCT-1
5757
call check(error, sum(abs(dct(x,2,1) - [0.0_rk, 18.0_rk])) < eps, "`dct(x,2,1)` failed.")
5858
if (allocated(error)) return
59-
call check(error, sum(abs(dct(x,3,1) - dct(x,t=1))) < eps, "`dct(x,3,1)` failed.")
59+
call check(error, sum(abs(dct(x,3,1) - dct(x,type=1))) < eps, "`dct(x,3,1)` failed.")
6060
if (allocated(error)) return
6161
call check(error, sum(abs(dct(x,4,1) - [real(kind=rk) :: -3, -3.0000000000000036_rk, 15, 33])) < eps,&
6262
"`dct(x,4,1)` failed.")
@@ -74,12 +74,12 @@ subroutine test_modernized_dct(error)
7474
call check(error, sum(abs(dct(x,2,3) - [-3.7279220613578570_rk, 21.727922061357859_rk])) < eps, &
7575
"`dct(x,2,3)` failed.")
7676
if (allocated(error)) return
77-
call check(error, sum(abs(dct(x,3,3) - dct(x,t=3))) < eps, &
77+
call check(error, sum(abs(dct(x,3,3) - dct(x,type=3))) < eps, &
7878
"`dct(x,3,3)` failed.")
7979
if (allocated(error)) return
8080
call check(error, sum(abs(dct(x,4,3) - [-3.3871908980838743_rk, -2.1309424696909023_rk, &
8181
11.645661095452331_rk, 29.872472272322447_rk])) < eps, &
82-
"`dct(x,n=4,t=3)` failed.")
82+
"`dct(x,4,3)` failed.")
8383

8484
end subroutine test_modernized_dct
8585

@@ -89,36 +89,40 @@ subroutine test_modernized_idct(error)
8989
real(kind=rk) :: x(4) = [1, 2, 3, 4]
9090

9191
! inverse DCT-1
92-
call check(error, sum(abs(idct(dct(x,t=1),t=1)/(2*3) - x)) < eps, "`idct(dct(x,t=1),t=1)/(2*3)` failed.")
92+
call check(error, sum(abs(idct(dct(x,type=1),type=1)/(2*3) - x)) < eps, &
93+
"`idct(dct(x,type=1),type=1)/(2*3)` failed.")
9394
if (allocated(error)) return
94-
call check(error, sum(abs(idct(dct(x,t=1), 2, 1)/(2*1) - [5.5_rk, 9.5_rk])) < eps,&
95-
"`idct(dct(x,t=1), 2, 1)/(2*1)` failed.")
95+
call check(error, sum(abs(idct(dct(x,type=1), 2, 1)/(2*1) - [5.5_rk, 9.5_rk])) < eps, &
96+
"`idct(dct(x,type=1), 2, 1)/(2*1)` failed.")
9697
if (allocated(error)) return
97-
call check(error, sum(abs(idct(dct(x,2,1), 4, 1)/(2*3) - [0.16666666666666666_rk, 0.33333333333333331_rk,&
98-
0.66666666666666663_rk, 0.83333333333333315_rk])) < eps,&
98+
call check(error, sum(abs(idct(dct(x,2,1), 4, 1)/(2*3) - [0.16666666666666666_rk, 0.33333333333333331_rk, &
99+
0.66666666666666663_rk, 0.83333333333333315_rk])) < eps, &
99100
"`idct(dct(x,2,1), 4, 1)/(2*3)` failed.")
100-
101+
101102
! inverse DCT-2
102103
x = [1, 2, 3, 4]
103-
call check(error, sum(abs(idct(dct(x,t=2))/(4*4) - x)) < eps, &
104-
"`idct(dct(x, t=2))/(4*4)` failed.")
104+
call check(error, sum(abs(idct(dct(x,type=2))/(4*4) - x)) < eps, &
105+
"`idct(dct(x, type=2))/(4*4)` failed.")
105106
if (allocated(error)) return
106-
call check(error, sum(abs(idct(dct(x,t=2),n=2) - [22.156460020898692_rk, 57.843539979101308_rk])) < eps,&
107-
"`idct(dct(x,t=2),n=2)` failed.")
107+
call check(error, sum(abs(idct(dct(x,type=2),n=2) - [22.156460020898692_rk, 57.843539979101308_rk])) < eps, &
108+
"`idct(dct(x, type=2),n=2)` failed.")
108109
if (allocated(error)) return
109-
call check(error, sum(abs(idct(dct(x,n=2,t=2),n=4) - [6.7737481404944937_rk, 9.8352155994152106_rk,&
110-
14.164784400584789_rk, 17.226251859505506_rk])) < eps, "`idct(dct(x,n=2,t=2),n=4)` failed.")
110+
call check(error, sum(abs(idct(dct(x,n=2,type=2),n=4) - [6.7737481404944937_rk, 9.8352155994152106_rk, &
111+
14.164784400584789_rk, 17.226251859505506_rk])) < eps, &
112+
"`idct(dct(x, n=2, type=2), n=4)` failed.")
111113

112114
! inverse DCT-3
113115
x = [1, 2, 3, 4]
114-
call check(error, sum(abs(idct(dct(x,t=3),t=3)/(4*4) - x)) < eps, &
115-
"`idct(dct(x, t=3), t=3)/(4*4)` failed.")
116+
call check(error, sum(abs(idct(dct(x,type=3),type=3)/(4*4) - x)) < eps, &
117+
"`idct(dct(x, type=3), type=3)/(4*4)` failed.")
116118
if (allocated(error)) return
117-
call check(error, sum(abs(idct(dct(x,t=3),n=2,t=3)/(4*2) - [1.4483415291679655_rk, 7.4608849947753271_rk])) < eps, &
118-
"`idct(dct(x,t=3),n=2,t=3)/(4*2)` failed.")
119+
call check(error, sum(abs(idct(dct(x,type=3),n=2,type=3)/(4*2) - &
120+
[1.4483415291679655_rk, 7.4608849947753271_rk])) < eps, &
121+
"`idct(dct(x, type=3), n=2, type=3)/(4*2)` failed.")
119122
if (allocated(error)) return
120-
call check(error, sum(abs(idct(dct(x,n=2,t=3),n=4,t=3)/(4*4) - [0.5_rk, 0.70932417358418376_rk, 1.0_rk, &
121-
0.78858050747473762_rk])) < eps, "`idct(dct(x,n=2,t=3),n=4, t=3)/(4*4)` failed.")
123+
call check(error, sum(abs(idct(dct(x,n=2,type=3),n=4,type=3)/(4*4) - &
124+
[0.5_rk, 0.70932417358418376_rk, 1.0_rk, 0.78858050747473762_rk])) < eps, &
125+
"`idct(dct(x, n=2, type=3), n=4, type=3)/(4*4)` failed.")
122126

123127
end subroutine test_modernized_idct
124128

0 commit comments

Comments
 (0)