1 | ! Transformee de Fourier complexe-reelle simple |
---|
2 | |
---|
3 | program tjmcsfft |
---|
4 | |
---|
5 | implicit none |
---|
6 | |
---|
7 | integer, parameter :: n = 8 |
---|
8 | complex, dimension(0:n/2) :: x, xx |
---|
9 | real, dimension(0:n/2,2) :: rx |
---|
10 | equivalence ( x, rx ) |
---|
11 | real, dimension(0:n-1) :: y |
---|
12 | |
---|
13 | ! Pour stocker les cosinus et les sinus |
---|
14 | ! En fait 100+2*n suffisent pour les routines jm |
---|
15 | integer, parameter :: ntable = 100+4*n |
---|
16 | real, dimension(0:ntable-1) :: table |
---|
17 | |
---|
18 | ! En fait, 2*n suffisent pour les routines jm |
---|
19 | integer, parameter :: nwork = 4+4*n |
---|
20 | real, dimension(0:nwork-1) :: work |
---|
21 | |
---|
22 | integer :: isign |
---|
23 | real :: scale |
---|
24 | integer :: isys |
---|
25 | integer :: i, k |
---|
26 | real :: twopi |
---|
27 | complex :: s |
---|
28 | |
---|
29 | ! On prepare le tableau d'entree sans forcer a 0 les termes necessaires |
---|
30 | call random_number( rx ) |
---|
31 | xx = x |
---|
32 | |
---|
33 | scale = 1. |
---|
34 | isys = 0 |
---|
35 | |
---|
36 | isign = 0 |
---|
37 | call csfft(isign,n,scale,x,y,table,work,isys) |
---|
38 | isign = 1 |
---|
39 | print *,'jmcsfft ',n,isign,scale |
---|
40 | call csfft(isign,n,scale,x,y,table,work,isys) |
---|
41 | |
---|
42 | ! On imprime le tableau de sortie |
---|
43 | open(10,file='temp1',status='unknown',form='formatted') |
---|
44 | write(10,'(e25.12)') y |
---|
45 | close(10) |
---|
46 | |
---|
47 | ! Ce qu'il faut trouver |
---|
48 | open(11,file='temp2',status='unknown',form='formatted') |
---|
49 | twopi = 2 * acos(real(-1)) |
---|
50 | ! On reprepare le tableau d'entree en forcant a 0 les termes necessaires |
---|
51 | x = xx |
---|
52 | x(0) = cmplx( real( x(0) ), 0 ) |
---|
53 | if ( mod( n, 2 ) == 0 ) x(n/2) = cmplx( real( x(n/2) ), 0 ) |
---|
54 | xx = x |
---|
55 | ! Et on calcule |
---|
56 | do i = 0,n-1 |
---|
57 | s = 0 |
---|
58 | do k = 0,n/2 |
---|
59 | s = s+cmplx(cos(twopi*i*k/real(n)),isign*sin(twopi*i*k/real(n)))*x(k) |
---|
60 | end do |
---|
61 | do k = n/2+1,n-1 |
---|
62 | s = s+cmplx(cos(twopi*i*k/real(n)),isign*sin(twopi*i*k/real(n)))* & |
---|
63 | & conjg(x(n-k)) |
---|
64 | end do |
---|
65 | write(11,'(2e25.12)') real(s*scale) |
---|
66 | end do |
---|
67 | close(11) |
---|
68 | |
---|
69 | end program tjmcsfft |
---|