1 | ! Transformee de Fourier complexe-reelle multiple |
---|
2 | |
---|
3 | program tjmcsfft2d |
---|
4 | |
---|
5 | implicit none |
---|
6 | |
---|
7 | integer, parameter :: m = 1 |
---|
8 | integer, parameter :: n = 8 |
---|
9 | complex, dimension(0:n/2,0:m-1) :: x, xx |
---|
10 | real, dimension(0:n/2,0:m-1,2) :: rx |
---|
11 | equivalence ( x, rx ) |
---|
12 | real, dimension(0:n-1+2,0:m-1) :: y |
---|
13 | |
---|
14 | ! Pour stocker les cosinus et les sinus |
---|
15 | integer, parameter :: ntable = 100+2*(n+m) |
---|
16 | real, dimension(0:ntable-1) :: table |
---|
17 | |
---|
18 | ! Les routines jm ont besoin de 2*2*(n/2+1)*m. D'ou tronconnage. |
---|
19 | integer, parameter :: nwork = 512*max(n,m) |
---|
20 | real, dimension(0:nwork-1) :: work |
---|
21 | |
---|
22 | integer :: isign |
---|
23 | real :: scale |
---|
24 | integer :: isys |
---|
25 | integer :: i, j, k, l |
---|
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 | ! On force la symetrie hermitienne pour i=0 et i=n/2 |
---|
32 | do j = m/2+1,m-1 |
---|
33 | x(0,j) = conjg(x(0,m-j)) |
---|
34 | end do |
---|
35 | !JMT- x(0,0) = cmplx(real(x(0,0)),0) |
---|
36 | !JMT- if (mod(m,2) == 0) x(0,m/2) = cmplx(real(x(0,m/2)),0) |
---|
37 | if (mod(n,2) == 0) then |
---|
38 | do j = m/2+1,m-1 |
---|
39 | x(n/2,j) = conjg(x(n/2,m-j)) |
---|
40 | end do |
---|
41 | !JMT- x(n/2,0) = cmplx(real(x(n/2,0)),0) |
---|
42 | !JMT- if (mod(m,2) == 0) x(n/2,m/2) = cmplx(real(x(n/2,m/2)),0) |
---|
43 | end if |
---|
44 | xx = x |
---|
45 | |
---|
46 | scale = 1. |
---|
47 | isys = 0 |
---|
48 | |
---|
49 | isign = 0 |
---|
50 | call csfft2d(isign,n,m,scale,x,n/2+1,y,n+2,table,work,isys) |
---|
51 | isign = 1 |
---|
52 | print *,'jmcsfft2d ',n,m,isign,scale |
---|
53 | call csfft2d(isign,n,m,scale,x,n/2+1,y,n+2,table,work,isys) |
---|
54 | |
---|
55 | ! On imprime le tableau de sortie |
---|
56 | open(10,file='temp1',status='unknown',form='formatted') |
---|
57 | write(10,'(e25.12)') y(0:n-1,0:m-1) |
---|
58 | close(10) |
---|
59 | |
---|
60 | ! Ce qu'il faut trouver |
---|
61 | open(11,file='temp2',status='unknown',form='formatted') |
---|
62 | twopi = 2 * acos(real(-1)) |
---|
63 | ! On reprepare le tableau d'entree, mais on force a 0 les termes necessaires |
---|
64 | x = xx |
---|
65 | x(0,0) = cmplx(real(x(0,0)),0) |
---|
66 | if (mod(m,2) == 0) x(0,m/2) = cmplx(real(x(0,m/2)),0) |
---|
67 | if (mod(n,2) == 0) then |
---|
68 | x(n/2,0) = cmplx(real(x(n/2,0)),0) |
---|
69 | if (mod(m,2) == 0) x(n/2,m/2) = cmplx(real(x(n/2,m/2)),0) |
---|
70 | end if |
---|
71 | ! Et on calcule |
---|
72 | do j = 0,m-1 |
---|
73 | do i = 0,n-1 |
---|
74 | s = 0 |
---|
75 | do l = 0,m-1 |
---|
76 | do k = 0,n/2 |
---|
77 | s = s+cmplx(cos(twopi*i*k/real(n)),isign*sin(twopi*i*k/real(n))) & |
---|
78 | & *cmplx(cos(twopi*j*l/real(m)),isign*sin(twopi*j*l/real(m))) & |
---|
79 | & *x(k,l) |
---|
80 | end do |
---|
81 | do k = n/2+1,n-1 |
---|
82 | s = s+cmplx(cos(twopi*i*k/real(n)),isign*sin(twopi*i*k/real(n))) & |
---|
83 | & *cmplx(cos(twopi*j*l/real(m)),isign*sin(twopi*j*l/real(m))) & |
---|
84 | & *conjg(x(n-k,mod(m-l,m))) |
---|
85 | end do |
---|
86 | end do |
---|
87 | write(11,'(2e25.12)') real(s*scale) |
---|
88 | end do |
---|
89 | end do |
---|
90 | close(11) |
---|
91 | |
---|
92 | end program tjmcsfft2d |
---|