-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfft.f
324 lines (225 loc) · 11.7 KB
/
fft.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
********************************************************************************
** FICHE F.37. ROUTINES TO CALCULATE FOURIER TRANSFORMS. **
** This FORTRAN code is intended to illustrate points made in the text. **
** To our knowledge it works correctly. However it is the responsibility of **
** the user to test it, if it is to be used in a research application. **
********************************************************************************
C *******************************************************************
C ** THREE SEPARATE ROUTINES FOR DIFFERENT APPLICATIONS. **
C *******************************************************************
SUBROUTINE FILONC ( DT, DOM, NMAX, C, CHAT )
C *******************************************************************
C ** CALCULATES THE FOURIER COSINE TRANSFORM BY FILON'S METHOD **
C ** **
C ** A CORRELATION FUNCTION, C(T), IN THE TIME DOMAIN, IS **
C ** TRANSFORMED TO A SPECTRUM CHAT(OMEGA) IN THE FREQUENCY DOMAIN.**
C ** **
C ** REFERENCE: **
C ** **
C ** FILON, PROC ROY SOC EDIN, 49 38, 1928. **
C ** **
C ** PRINCIPAL VARIABLES: **
C ** **
C ** REAL C(NMAX) THE CORRELATION FUNCTION. **
C ** REAL CHAT(NMAX) THE 1-D COSINE TRANSFORM. **
C ** REAL DT TIME INTERVAL BETWEEN POINTS IN C. **
C ** REAL DOM FREQUENCY INTERVAL FOR CHAT. **
C ** INTEGER NMAX NO. OF INTERVALS ON THE TIME AXIS **
C ** REAL OMEGA THE FREQUENCY **
C ** REAL TMAX MAXIMUM TIME IN CORRL. FUNCTION **
C ** REAL ALPHA, BETA, GAMMA FILON PARAMETERS **
C ** INTEGER TAU TIME INDEX **
C ** INTEGER NU FREQUENCY INDEX **
C ** **
C ** USAGE: **
C ** **
C ** THE ROUTINE REQUIRES THAT THE NUMBER OF INTERVALS, NMAX, IS **
C ** EVEN AND CHECKS FOR THIS CONDITION. THE FIRST VALUE OF C(T) **
C ** IS AT T=0. THE MAXIMUM TIME FOR THE CORRELATION FUNCTION IS **
C ** TMAX=DT*NMAX. FOR AN ACCURATE TRANSFORM C(TMAX)=0. **
C *******************************************************************
INTEGER NMAX
REAL DT, DOM, C(0:NMAX), CHAT(0:NMAX)
REAL TMAX, OMEGA, THETA, SINTH, COSTH, CE, CO
REAL SINSQ, COSSQ, THSQ, THCUB, ALPHA, BETA, GAMMA
INTEGER TAU, NU
C *******************************************************************
C ** CHECKS NMAX IS EVEN **
IF ( MOD ( NMAX, 2 ) .NE. 0 ) THEN
STOP ' NMAX SHOULD BE EVEN '
ENDIF
TMAX = REAL ( NMAX ) * DT
C ** LOOP OVER OMEGA **
DO 30 NU = 0, NMAX
OMEGA = REAL ( NU ) * DOM
THETA = OMEGA * DT
C ** CALCULATE THE FILON PARAMETERS **
SINTH = SIN ( THETA )
COSTH = COS ( THETA )
SINSQ = SINTH * SINTH
COSSQ = COSTH * COSTH
THSQ = THETA * THETA
THCUB = THSQ * THETA
IF ( THETA. EQ. 0.0 ) THEN
ALPHA = 0.0
BETA = 2.0 / 3.0
GAMMA = 4.0 / 3.0
ELSE
ALPHA = ( 1.0 / THCUB )
: * ( THSQ + THETA * SINTH * COSTH - 2.0 * SINSQ )
BETA = ( 2.0 / THCUB )
: * ( THETA * ( 1.0 + COSSQ ) -2.0 * SINTH * COSTH )
GAMMA = ( 4.0 / THCUB ) * ( SINTH - THETA * COSTH )
ENDIF
C ** DO THE SUM OVER THE EVEN ORDINATES **
CE = 0.0
DO 10 TAU = 0, NMAX, 2
CE = CE + C(TAU) * COS ( THETA * REAL ( TAU ) )
10 CONTINUE
C ** SUBTRACT HALF THE FIRST AND LAST TERMS **
CE = CE - 0.5 * ( C(0) + C(NMAX) * COS ( OMEGA * TMAX ) )
C ** DO THE SUM OVER THE ODD ORDINATES **
CO = 0.0
DO 20 TAU = 1, NMAX - 1, 2
CO = CO + C(TAU) * COS ( THETA * REAL ( TAU ) )
20 CONTINUE
C ** FACTOR OF TWO FOR THE REAL COSINE TRANSFORM **
CHAT(NU) = 2.0 * ( ALPHA * C(NMAX) * SIN ( OMEGA * TMAX )
: + BETA * CE + GAMMA * CO ) * DT
30 CONTINUE
RETURN
END
SUBROUTINE LADO ( DT, NMAX, C, CHAT )
C *******************************************************************
C ** CALCULATES THE FOURIER COSINE TRANSFORM BY LADO'S METHOD **
C ** **
C ** A CORRELATION FUNCTION, C(T), IN THE TIME DOMAIN, IS **
C ** TRANSFORMED TO A SPECTRUM CHAT(OMEGA) IN THE FREQUENCY DOMAIN.**
C ** **
C ** REFERENCE: **
C ** **
C ** LADO, J COMPUT PHYS, 8 417, 1971. **
C ** **
C ** PRINCIPAL VARIABLES: **
C ** **
C ** REAL C(NMAX) THE CORRELATION FUNCTION. **
C ** REAL CHAT(NMAX) THE 1-D COSINE TRANSFORM. **
C ** REAL DT TIME INTERVAL BETWEEN POINTS IN C. **
C ** REAL DOM FREQUENCY INTERVAL BETWEEN POINTS IN CHAT.**
C ** INTEGER NMAX NO. OF INTERVALS ON THE TIME AXIS **
C ** **
C ** USAGE: **
C ** **
C ** THE CORRELATION FUNCTION IS REQUIRED AT HALF INTEGER **
C ** INTERVALS, I.E. C(T), T=(TAU-0.5)*DT FOR TAU=1 .. NMAX. **
C ** THE COSINE TRANSFORM IS RETURNED AT HALF INTERVALS, I.E. **
C ** CHAT(OMEGA), OMEGA=(NU-0.5)*DOM FOR NU = 1 .. NMAX. **
C *******************************************************************
INTEGER NMAX
REAL DT, C(NMAX), CHAT(NMAX)
INTEGER TAU, NU
REAL TAUH, NUH, NMAXH, PI, SUM
PARAMETER ( PI = 3.1415927 )
C *******************************************************************
NMAXH = REAL ( NMAX ) - 0.5
C ** LOOP OVER OMEGA **
DO 20 NU = 1, NMAX
NUH = REAL ( NU ) - 0.5
SUM = 0.0
C ** LOOP OVER T **
DO 10 TAU = 1, NMAX
TAUH = REAL ( TAU ) - 0.5
SUM = SUM + C(TAU) * COS ( TAUH * NUH * PI / NMAXH )
10 CONTINUE
C ** FACTOR OF TWO FOR THE REAL COSINE TRANSFORM **
CHAT(NU) = 2.0 * DT * SUM
20 CONTINUE
RETURN
END
SUBROUTINE FILONS ( DR, DK, NMAX, H, HHAT )
C *******************************************************************
C ** FOURIER SINE TRANSFORM BY FILON'S METHOD **
C ** **
C ** A SPATIAL CORRELATION FUNCTION, H(R), IS TRANSFORMED TO **
C ** HHAT(K) IN RECIPROCAL SPACE. **
C ** **
C ** REFERENCE: **
C ** **
C ** FILON, PROC ROY SOC EDIN, 49 38, 1928. **
C ** **
C ** PRINCIPAL VARIABLES: **
C ** **
C ** REAL KVEC THE WAVENUMBER **
C ** REAL RMAX MAXIMUM DIST IN CORREL. FUNCTION **
C ** REAL ALPHA, BETA, GAMMA FILON PARAMETERS **
C ** REAL H(NMAX) THE CORRELATION FUNCTION **
C ** REAL HHAT(NMAX) THE 3-D TRANSFORM **
C ** REAL DR INTERVAL BETWEEN POINTS IN H **
C ** REAL DK INTERVAL BETWEEN POINTS IN HHAT **
C ** INTEGER NMAX NO. OF INTERVALS **
C ** **
C ** USAGE: **
C ** **
C ** THE ROUTINE REQUIRES THAT THE NUMBER OF INTERVALS, NMAX, IS **
C ** EVEN AND CHECKS FOR THIS CONDITION. THE FIRST VALUE OF H(R) **
C ** IS AT R=0. THE MAXIMUM R FOR THE CORRELATION FUNCTION IS **
C ** RMAX=DR*NMAX. FOR AN ACCURATE TRANSFORM H(RMAX)=0. **
C *******************************************************************
INTEGER NMAX
REAL DR, DK, H(0:NMAX), HHAT(0:NMAX)
REAL RMAX, K, THETA, SINTH, COSTH
REAL SINSQ, COSSQ, THSQ, THCUB, ALPHA, BETA, GAMMA
REAL SE, SO, FOURPI, R
INTEGER IR, IK
C *******************************************************************
C ** CHECKS NMAX IS EVEN **
IF ( MOD ( NMAX, 2 ) .NE. 0 ) THEN
STOP ' NMAX SHOULD BE EVEN '
ENDIF
FOURPI = 16.0 * ATAN ( 1.0 )
RMAX = REAL ( NMAX ) * DR
C ** LOOP OVER K **
DO 30 IK = 0, NMAX
K = REAL ( IK ) * DK
THETA = K * DR
C ** CALCULATE THE FILON PARAMETERS **
SINTH = SIN ( THETA )
COSTH = COS ( THETA )
SINSQ = SINTH * SINTH
COSSQ = COSTH * COSTH
THSQ = THETA * THETA
THCUB = THSQ * THETA
IF ( THETA. EQ. 0.0 ) THEN
ALPHA = 0.0
BETA = 2.0 / 3.0
GAMMA = 4.0 / 3.0
ELSE
ALPHA = ( 1.0 / THCUB )
: * ( THSQ + THETA * SINTH * COSTH - 2.0 * SINSQ )
BETA = ( 2.0 / THCUB )
: * ( THETA * ( 1.0 + COSSQ ) -2.0 * SINTH * COSTH )
GAMMA = ( 4.0 / THCUB ) * ( SINTH - THETA * COSTH )
ENDIF
C ** THE INTEGRAND IS H(R) * R FOR THE 3-D TRANSFORM **
C ** DO THE SUM OVER THE EVEN ORDINATES **
SE = 0.0
DO 10 IR = 0, NMAX, 2
R = REAL ( IR ) * DR
SE = SE + H(IR) * R * SIN ( K * R )
10 CONTINUE
C ** SUBTRACT HALF THE FIRST AND LAST TERMS **
C ** HERE THE FIRST TERM IS ZERO **
SE = SE - 0.5 * ( H(NMAX) * RMAX * SIN ( K * RMAX ) )
C ** DO THE SUM OVER THE ODD ORDINATES **
SO = 0.0
DO 20 IR = 1, NMAX - 1, 2
R = REAL ( IR ) * DR
SO = SO + H(IR) * R * SIN ( K * R )
20 CONTINUE
HHAT(IK) = ( - ALPHA * H(NMAX) * RMAX * COS ( K * RMAX)
: + BETA * SE + GAMMA * SO ) * DR
C ** INCLUDE NORMALISING FACTOR **
HHAT(IK) = FOURPI * HHAT(IK) / K
30 CONTINUE
RETURN
END