@@ -20,6 +20,7 @@ subroutine collect_original(testsuite)
2020 testsuite = [testsuite, new_unittest(" sint" , test_sint)]
2121 testsuite = [testsuite, new_unittest(" cost" , test_cost)]
2222 testsuite = [testsuite, new_unittest(" cosqt" , test_cosqt)]
23+ testsuite = [testsuite, new_unittest(" dzfft" , test_dzfft)]
2324 end subroutine collect_original
2425
2526 subroutine test_dfft (error )
@@ -360,6 +361,106 @@ subroutine test_cosqt(error)
360361
361362 end do
362363 end subroutine test_cosqt
364+
365+ subroutine test_dzfft (error )
366+ type (error_type), allocatable , intent (out ) :: error
367+ real (rk) :: x(200 ), y(200 ), xh(200 ), w(2000 )
368+ real (rk) :: a(100 ), b(100 ), ah(100 ), bh(100 )
369+ real (rk) :: azero, azeroh
370+ integer :: i, j, k, n, np1, nm1, ns2, ns2m, nz, modn
371+ real (rk) :: fn, tfn, dt, sum1, sum2, arg, arg1, arg2
372+ real (rk) :: mismatch, cf
373+
374+ do nz = 1 , size (nd)
375+ ! > Create multisine signal.
376+ n = nd(nz)
377+ modn = mod (n, 2 )
378+ fn = real (n, kind= rk)
379+ tfn = 2 * fn
380+ np1 = n + 1 ; nm1 = n - 1
381+ do j = 1 , np1
382+ x(j) = sin (j* sqrt (2.0_rk ))
383+ y(j) = x(j)
384+ xh(j) = x(j)
385+ end do
386+
387+ ! > Discrete Fourier Transform.
388+ dt = 2 * pi/ fn
389+ ns2 = (n + 1 )/ 2
390+ ns2m = ns2 - 1
391+ cf = 2.0_rk / n
392+ if (ns2m > 0 ) then
393+ do k = 1 , ns2m
394+ sum1 = 0.0_rk ; sum2 = 0.0_rk
395+ arg = k* dt
396+ do i = 1 , n
397+ arg1 = (i - 1 )* arg
398+ sum1 = sum1 + x(i)* cos (arg1)
399+ sum2 = sum2 + x(i)* sin (arg1)
400+ end do
401+ a(k) = cf* sum1
402+ b(k) = cf* sum2
403+ end do
404+ end if
405+ nm1 = n - 1
406+ sum1 = 0.0_rk
407+ sum2 = 0.0_rk
408+ do i = 1 , nm1, 2
409+ sum1 = sum1 + x(i)
410+ sum2 = sum2 + x(i + 1 )
411+ end do
412+ if (modn == 1 ) sum1 = sum1 + x(n)
413+ azero = 0.5_rk * cf* (sum1 + sum2)
414+ if (modn == 0 ) a(ns2) = 0.5_rk * cf* (sum1 - sum2)
415+
416+ ! > Fast Fourier Transform.
417+ call dzffti(n, w)
418+ call dzfftf(n, x, azeroh, ah, bh, w)
419+
420+ ! > Check error.
421+ mismatch = abs (azeroh - azero)
422+ if (modn == 0 ) mismatch = max (mismatch, abs (a(ns2) - ah(ns2)))
423+ if (ns2m > 0 ) then
424+ do i = 1 , ns2m
425+ mismatch = max (mismatch, abs (ah(i) - a(i)), abs (bh(i) - b(i)))
426+ end do
427+ end if
428+ call check(error, mismatch < rtol)
429+ if (allocated (error)) return
430+
431+ ! > Inverse Discrete Fourier Transform
432+ ns2 = n/ 2
433+ if (modn == 0 ) b(ns2) = 0.0_rk
434+ do i = 1 , n
435+ sum1 = azero
436+ arg1 = (i - 1 )* dt
437+ do k = 1 , ns2
438+ arg2 = k* arg1
439+ sum1 = sum1 + a(k)* cos (arg2) + b(k)* sin (arg2)
440+ end do
441+ x(i) = sum1
442+ end do
443+
444+ ! > Fast Inverse Fourier Transform.
445+ call dzfftb(n, y, azero, a, b, w)
446+
447+ ! > Check error.
448+ mismatch = maxval (abs (x(:n) - y(:n)))
449+ call check(error, mismatch < rtol)
450+ if (allocated (error)) return
451+
452+ ! > Chain direct and inverse Fourier transforms.
453+ x(:n) = xh(:n)
454+ call dzfftf(n, x, azero, a, b, w)
455+ call dzfftb(n, x, azero, a, b, w)
456+
457+ ! > Check error.
458+ mismatch = maxval (abs (x(:n) - y(:n)))
459+ call check(error, mismatch < rtol)
460+ if (allocated (error)) return
461+
462+ end do
463+ end subroutine test_dzfft
363464end module test_fftpack_original
364465
365466program test_original
0 commit comments