-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfftpack.f90
executable file
·1413 lines (1399 loc) · 55.3 KB
/
fftpack.f90
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
! FROM UPDATE LIBRARY LMDBIB CY=2 02/08/85
!************************************************************************
!* *
!* C06-SUMMATION OF SERIES B6.1/3 *
!* *
!* FFT99 *
!* FFT991 *
!* *
!* *
!* SUBPROGRAM SUBROUTINE FFT99 *
!* FFT991 *
!* *
!* PURPOSE PERFORM MULTIPLE FAST FOURIER TRANSFORMS *
!* *
!* *
!* VERSION CYBER CRAY-1 *
!* *
!* JAN 1979 ORIGINAL JAN 1979 ORIGINAL *
!* *
!* USAGE *
!* CALL FFT99 (A,WORK,TRIGS,IFAX,INC,JUMP,N,M,ISIGN) *
!* CALL FFT991(A,WORK,TRIGS,IFAX,INC,JUMP,N,M,ISIGN) *
!* *
!* ARGUMENTS 1.DIMENSION *
!* A(IDIM),WORK((N+1)*M),TRIGS(3*N/2),IFAX(10) *
!* WORK IS A WORK ARRAY *
!* ! >>> TRIGS(DIMENSION 3*N/2 - ADD 1 IF N/2 IS ODD) *
!* *
!* 2.INPUT *
!* A - AN ARRAY CONTAINING THE INPUT DATA OR *
!* COEFFICIENT VECTORS. *
!* THIS ARRAY IS OVERWRITTEN BY THE RESULTS. *
!* TRIGS AND IFAX - ARRAYS SET UP BY FFTRIG AND FAX*
!* - SEE WRITEUP OF FFTRIG AND FAX *
!* INC - THE WORD INCREMENT BETWEEN SUCCESSIVE *
!* ELEMENTS OF EACH DATA OR COEFFICIENT VECTOR*
!* E.G. INC=1 FOR CONSECUTIVELY STORED DATA. *
!* JUMP - THE WORD INCREMENT BETWEEN THE FIRST *
!* ELEMENTS OF SUCCESSIVE DATA OR COEFFICIENT*
!* VECTORS. *
!* N - THE LENGTH OF EACH TRANSFORM. (SEE NOTE X) *
!* M - THE NUMBER OF TRANSFORMS TO BE DONE *
!* SIMULTANEOUSLY. *
!* ISIGN - +1 FOR A TRANSFORM FROM FOURIER *
!* COEFFICIENTS TO DATA VALUES. *
!* -1 FOR A TRANSFORM FROM DATA VALUES *
!* TO FOURIER COEFFICIENTS. *
!* *
!* 3.OUTPUT *
!* A - CONTAINS EITHER THE COEFFICIENTS OR THE *
!* DATA VALUES,DEPENDING ON ISIGN. *
!* IN EACH CASE N INDEPENDENT QUANTITIES *
!* OCCUPY N+2 WORDS. THE COEFFICIENTS ARE *
!* STORED AS SUCCESSIVE PAIRS OF REAL AND *
!* IMAGINARY PARTS - *
!* A(K),B(K) , K=0,1,...N/2 *
!* B(0) AND B(N/2) ARE STORED ALTHOUGH THEY *
!* MUST BE 0. *
!* FOR FFT99 THE DATA IS STORED WITH EXPLICIT *
!* PERIODICITY - *
!* X(N-1),X(0),X(1),....X(N-1),X(0) *
!* FOR FFT991 THE DATA APPEARS AS - *
!* X(0),X(1),X(2),......X(N-1),0,0 *
!* *
!* NOTES 1. ON CRAY-1, ARRANGE DATA SO THAT JUMP IS NOT A *
!* MULTIPLE OF 8 (TO AVOID MEMORY BANK CONFLICTS) *
!* *
!* WRITE UP COMPUTER BULLETIN B6.6/1 *
!* *
!* ENTRY POINTS FFT99,FFT991 *
!* *
!* COMMON BLOCKS NONE *
!* *
!* I/O NONE *
!* *
!* PRECISION SINGLE *
!* *
!* OTHER ROUTINES FFT99A,FFT99B,VPASSM (CY) *
!* REQUIRED CAL99,CPASS (CR) *
!* *
!* *
!* 7/80 FFT99-1 *
!* *
!************************************************************************
!* *
!* C06-SUMMATION OF SERIES B6.1/3 *
!* *
!* FFT99 *
!* FFT991 *
!* *
!* ACCESS (OBJECT) CYBER: *
!* ATTACH,ECLIB. *
!* LDSET(LIB=ECLIB) *
!* CRAY 1: *
!* LDR(LIB=ECLIB...) *
!* *
!* ACCESS (SOURCE) ATTACH,OLDPL,ECLIBPL *
!* *
!* CYBER : %DEFINE CYBER *
!* CRAY: %DEFINE CRAY *
!* %C FFT99,FFT991 *
!* *
!* LANGUAGE FORTRAN *
!* BUT CRAY IMPLEMENTATION OF PASS IS IN CAL *
!* *
!* SPECIALIST CLIVE TEMPERTON *
!* *
!* HISTORY WRITTEN BY C.TEMPERTON JAN 1979 *
!* *
!* ALGORITHM THE ALGORITHM IS THE SELF-SORTING (TEMPERTON) *
!* VERSION OF THE FAST FOURIER TRANSFORM *
!* *
!* REFERENCES ECMWF TECHNICAL REPORT NO.3 *
!* ECMWF INTERNAL REPORT NO.21 - C.TEMPERTON *
!* *
!* OBJECT SIZE FFT991 FFT99 (OCTAL WORDS) *
!* CYBER: 2665 2676 *
!* CRAY : 1250 1260 *
!* *
!* *
!* ACCURACY *
!* *
!* TIMING VECTORIZATION IS ON VECTORS OF LENGTH M. (CR) *
!* HENCE TIMING IS STRONGLY DEPENDENT ON M. *
!* TIME PER TRANSFORM ON CRAY-1 (MICROSECONDS) *
!* N M=4 M=16 M=64 *
!* 64 46 17 10 *
!* 128 81 33 21 *
!* 180 150 58 37 *
!* 192 149 58 36 *
!* 240 192 76 49 *
!* 256 191 76 49 *
!* 288 219 89 58 *
!* 300 253 102 68 *
!* 320 248 101 66 *
!* 360 286 118 79 *
!* 1024 898 359 238 *
!* *
!* PORTABILITY STANDARD FORTRAN *
!* STANDARD CAL (CR) *
!* *
!* SYSTEM ROUTINES NONE *
!* REQUIRED *
!* *
!* 7/80 FFT99-1 *
!* *
!************************************************************************
!
! SUBROUTINE 'FFT99' - MULTIPLE FAST REAL PERIODIC TRANSFORM
! CORRESPONDING TO OLD SCALAR ROUTINE FFT9
! PROCEDURE USED TO CONVERT TO HALF-LENGTH COMPLEX TRANSFORM
! IS GIVEN BY COOLEY, LEWIS ' WELCH (J. SOUND VIB., VOL. 12
! (1970), 315-337)
!
! A IS THE ARRAY CONTAINING INPUT ' OUTPUT DATA
! WORK IS AN AREA OF SIZE (N+1)*LOT
! TRIGS IS A PREVIOUSLY PREPARED LIST OF TRIG FUNCTION VALUES
! IFAX IS A PREVIOUSLY PREPARED LIST OF FACTORS OF N/2
! INC IS THE INCREMENT WITHIN EACH DATA "VECTOR"
! (E.G. INC=1 FOR CONSECUTIVELY STORED DATA)
! JUMP IS THE INCREMENT BETWEEN THE START OF EACH DATA VECTOR
! N IS THE LENGTH OF THE DATA VECTORS
! LOT IS THE NUMBER OF DATA VECTORS
! ISIGN = +1 FOR TRANSFORM FROM SPECTRAL TO GRIDPOINT
! = -1 FOR TRANSFORM FROM GRIDPOINT TO SPECTRAL
!
! ORDERING OF COEFFICIENTS:
! A(0),B(0),A(1),B(1),A(2),B(2),...,A(N/2),B(N/2)
! WHERE B(0)=B(N/2)=0; (N+2) LOCATIONS REQUIRED
!
! ORDERING OF DATA:
! X(N-1),X(0),X(1),X(2),...,X(N),X(0)
! I.E. EXPLICIT CYCLIC CONTINUITY; (N+2) LOCATIONS REQUIRED
!
! VECTORIZATION IS ACHIEVED ON CRAY BY DOING THE TRANSFORMS IN
! PARALLEL
!
! *** N.B. N IS ASSUMED TO BE AN EVEN NUMBER
!
! DEFINITION OF TRANSFORMS:
! -------------------------
!
! ISIGN=+1: X(J)=SUM(K=0,...,N-1)(C(K)*EXP(2*I*J*K*PI/N))
! WHERE C(K)=A(K)+I*B(K) AND C(N-K)=A(K)-I*B(K)
!
! ISIGN=-1: A(K)=(1/N)*SUM(J=0,...,N-1)(X(J)*COS(2*J*K*PI/N))
! B(K)=-(1/N)*SUM(J=0,...,N-1)(X(J)*SIN(2*J*K*PI/N))
!
SUBROUTINE FFT99 (A, WORK, TRIGS, IFAX, INC, JUMP, N, LOT, ISIGN)
USE SHARE_VARS
IMPLICIT NONE
INTEGER N
REAL (KIND=PR), DIMENSION (N) :: A, WORK, TRIGS
INTEGER, DIMENSION (1) :: IFAX
INTEGER :: INC, ISIGN, JUMP, LOT
INTEGER :: NFAX, MX, NH, INK, IGO, IBASE, JBASE, I, J, L, M
INTEGER :: K, IA, IB, LA
NFAX=IFAX(1)
MX=N+1
NH=N/2
INK=INC+INC
IF (ISIGN.EQ.+1) GO TO 30
!
! IF NECESSARY, TRANSFER DATA TO WORK AREA
IGO=50
IF (MOD(NFAX,2).EQ.1) GOTO 40
IBASE=INC+1
JBASE=1
DO 20 L=1,LOT
I=IBASE
J=JBASE
DO 10 M=1,N
WORK(J)=A(I)
I=I+INC
J=J+1
10 CONTINUE
IBASE=IBASE+JUMP
JBASE=JBASE+MX
20 CONTINUE
!
IGO=60
GO TO 40
!
! PREPROCESSING (ISIGN=+1)
! ------------------------
!
30 CONTINUE
CALL FFT99A(A,WORK,TRIGS,INC,JUMP,N,LOT)
IGO=60
!
! COMPLEX TRANSFORM
! -----------------
!
40 CONTINUE
IA=INC+1
LA=1
DO 80 K=1,NFAX
IF (IGO.EQ.60) GO TO 60
50 CONTINUE
CALL VPASSM(A(IA),A(IA+INC),WORK(1),WORK(2),TRIGS, &
INK,2,JUMP,MX,LOT,NH,IFAX(K+1),LA)
IGO=60
GO TO 70
60 CONTINUE
CALL VPASSM(WORK(1),WORK(2),A(IA),A(IA+INC),TRIGS, &
2,INK,MX,JUMP,LOT,NH,IFAX(K+1),LA)
IGO=50
70 CONTINUE
LA=LA*IFAX(K+1)
80 CONTINUE
!
IF (ISIGN.EQ.-1) GO TO 130
!
! IF NECESSARY, TRANSFER DATA FROM WORK AREA
IF (MOD(NFAX,2).EQ.1) GO TO 110
IBASE=1
JBASE=IA
DO 100 L=1,LOT
I=IBASE
J=JBASE
DO 90 M=1,N
A(J)=WORK(I)
I=I+1
J=J+INC
90 CONTINUE
IBASE=IBASE+MX
JBASE=JBASE+JUMP
100 CONTINUE
!
! FILL IN CYCLIC BOUNDARY POINTS
110 CONTINUE
IA=1
IB=N*INC+1
DO 120 L=1,LOT
A(IA)=A(IB)
A(IB+INC)=A(IA+INC)
IA=IA+JUMP
IB=IB+JUMP
120 CONTINUE
GO TO 140
!
! POSTPROCESSING (ISIGN=-1):
! --------------------------
!
130 CONTINUE
CALL FFT99B(WORK,A,TRIGS,INC,JUMP,N,LOT)
!
140 CONTINUE
END SUBROUTINE FFT99
SUBROUTINE FFT99A (A, WORK, TRIGS, INC, JUMP, N, LOT)
! subroutine fft99a - preprocessing step for fft99, isign=+1
! (spectral to gridpoint transform)
USE SHARE_VARS
IMPLICIT NONE
INTEGER N
REAL (KIND=PR), DIMENSION (N) :: A, WORK, TRIGS
REAL (KIND=PR) :: C, S
INTEGER :: INC, JUMP, LOT
INTEGER :: NH, MX, INK, IA, IB, JA, JB, K, L
INTEGER :: JBASE, IABASE, IBBASE, JABASE, JBBASE
NH=N/2
MX=N+1
INK=INC+INC
!
! A(0) ' A(N/2)
IA=1
IB=N*INC+1
JA=1
JB=2
DO 10 L=1,LOT
WORK(JA)=A(IA)+A(IB)
WORK(JB)=A(IA)-A(IB)
IA=IA+JUMP
IB=IB+JUMP
JA=JA+MX
JB=JB+MX
10 CONTINUE
!
! REMAINING WAVENUMBERS
IABASE=2*INC+1
IBBASE=(N-2)*INC+1
JABASE=3
JBBASE=N-1
!
DO 30 K=3,NH,2
IA=IABASE
IB=IBBASE
JA=JABASE
JB=JBBASE
C=TRIGS(N+K)
S=TRIGS(N+K+1)
DO 20 L=1,LOT
WORK(JA)=(A(IA)+A(IB))- &
(S*(A(IA)-A(IB))+C*(A(IA+INC)+A(IB+INC)))
WORK(JB)=(A(IA)+A(IB))+ &
(S*(A(IA)-A(IB))+C*(A(IA+INC)+A(IB+INC)))
WORK(JA+1)=(C*(A(IA)-A(IB))-S*(A(IA+INC)+A(IB+INC)))+ &
(A(IA+INC)-A(IB+INC))
WORK(JB+1)=(C*(A(IA)-A(IB))-S*(A(IA+INC)+A(IB+INC)))- &
(A(IA+INC)-A(IB+INC))
IA=IA+JUMP
IB=IB+JUMP
JA=JA+MX
JB=JB+MX
20 CONTINUE
IABASE=IABASE+INK
IBBASE=IBBASE-INK
JABASE=JABASE+2
JBBASE=JBBASE-2
30 CONTINUE
!
IF (IABASE.NE.IBBASE) GO TO 50
! WAVENUMBER N/4 (IF IT EXISTS)
IA=IABASE
JA=JABASE
DO 40 L=1,LOT
WORK(JA)=2.0*A(IA)
WORK(JA+1)=-2.0*A(IA+INC)
IA=IA+JUMP
JA=JA+MX
40 CONTINUE
!
50 CONTINUE
end subroutine fft99a
SUBROUTINE FFT99B (WORK, A, TRIGS, INC, JUMP, N, LOT)
! SUBROUTINE FFT99B - POSTPROCESSING STEP FOR FFT99, ISIGN = -1
! (GRIDPOINT TO SPECTRAL TRANSFORM)
USE SHARE_VARS
IMPLICIT NONE
INTEGER N
REAL (KIND=PR), DIMENSION (N) :: WORK, A, TRIGS
REAL (KIND=PR) :: C,S, SCALE
INTEGER :: INC, JUMP, LOT
INTEGER :: NH, MX, INK, IA, IB, JA, JB, IABASE, IBBASE, JABASE, JBBASE
INTEGER :: K, L
NH=N/2
MX=N+1
INK=INC+INC
!
! A(0) ' A(N/2)
SCALE=1.0/FLOAT(N)
IA=1
IB=2
JA=1
JB=N*INC+1
DO 10 L=1,LOT
A(JA)=SCALE*(WORK(IA)+WORK(IB))
A(JB)=SCALE*(WORK(IA)-WORK(IB))
A(JA+INC)=0.0
A(JB+INC)=0.0
IA=IA+MX
IB=IB+MX
JA=JA+JUMP
JB=JB+JUMP
10 CONTINUE
!
! REMAINING WAVENUMBERS
SCALE=0.5*SCALE
IABASE=3
IBBASE=N-1
JABASE=2*INC+1
JBBASE=(N-2)*INC+1
!
DO 30 K=3,NH,2
IA=IABASE
IB=IBBASE
JA=JABASE
JB=JBBASE
C=TRIGS(N+K)
S=TRIGS(N+K+1)
DO 20 L=1,LOT
A(JA)=SCALE*((WORK(IA)+WORK(IB)) &
+(C*(WORK(IA+1)+WORK(IB+1))+S*(WORK(IA)-WORK(IB))))
A(JB)=SCALE*((WORK(IA)+WORK(IB)) &
-(C*(WORK(IA+1)+WORK(IB+1))+S*(WORK(IA)-WORK(IB))))
A(JA+INC)=SCALE*((C*(WORK(IA)-WORK(IB))-S*(WORK(IA+1)+WORK(IB+1))) &
+(WORK(IB+1)-WORK(IA+1)))
A(JB+INC)=SCALE*((C*(WORK(IA)-WORK(IB))-S*(WORK(IA+1)+WORK(IB+1))) &
-(WORK(IB+1)-WORK(IA+1)))
IA=IA+MX
IB=IB+MX
JA=JA+JUMP
JB=JB+JUMP
20 CONTINUE
IABASE=IABASE+2
IBBASE=IBBASE-2
JABASE=JABASE+INK
JBBASE=JBBASE-INK
30 CONTINUE
!
IF (IABASE.NE.IBBASE) GO TO 50
! WAVENUMBER N/4 (IF IT EXISTS)
IA=IABASE
JA=JABASE
SCALE=2.0*SCALE
DO 40 L=1,LOT
A(JA)=SCALE*WORK(IA)
A(JA+INC)=-SCALE*WORK(IA+1)
IA=IA+MX
JA=JA+JUMP
40 CONTINUE
!
50 CONTINUE
END SUBROUTINE FFT99B
! SUBROUTINE 'FFT991' - MULTIPLE REAL/HALF-COMPLEX PERIODIC
! FAST FOURIER TRANSFORM
!
!************************************************************************
!* *
!*C06-SUMMATION OF SERIES B6.1/3 *
!* *
!* FFT99 *
!* FFT991 *
!* *
!* *
!*SUBPROGRAM SUBROUTINE FFT99 *
!* FFT991 *
!* *
!*PURPOSE PERFORM MULTIPLE FAST FOURIER TRANSFORMS *
!* *
!* *
!*VERSION CYBER CRAY-1 *
!* *
!* JAN 1979 ORIGINAL JAN 1979 ORIGINAL *
!* *
!*USAGE *
!* CALL FFT99 (A,WORK,TRIGS,IFAX,INC,JUMP,N,M,ISIGN) *
!* CALL FFT991(A,WORK,TRIGS,IFAX,INC,JUMP,N,M,ISIGN) *
!* *
!*ARGUMENTS 1.DIMENSION *
!* A(IDIM),WORK((N+1)*M),TRIGS(3*N/2),IFAX(10) *
!* WORK IS A WORK ARRAY *
!* *
!* 2.INPUT *
!* A - AN ARRAY CONTAINING THE INPUT DATA OR *
!* COEFFICIENT VECTORS. *
!* THIS ARRAY IS OVERWRITTEN BY THE RESULTS. *
!* TRIGS AND IFAX - ARRAYS SET UP BY FFTRIG AND FAX*
!* - SEE WRITEUP OF FFTRIG AND FAX *
!* INC - THE WORD INCREMENT BETWEEN SUCCESSIVE *
!* ELEMENTS OF EACH DATA OR COEFFICIENT VECTOR*
!* E.G. INC = 1 FOR CONSECUTIVELY STORED DATA. *
!* JUMP - THE WORD INCREMENT BETWEEN THE FIRST *
!* ELEMENTS OF SUCCESSIVE DATA OR COEFFICIENT*
!* VECTORS. *
!* N - THE LENGTH OF EACH TRANSFORM. (SEE NOTE X) *
!* M - THE NUMBER OF TRANSFORMS TO BE DONE *
!* SIMULTANEOUSLY. *
!* ISIGN - +1 FOR A TRANSFORM FROM FOURIER *
!* COEFFICIENTS TO DATA VALUES. *
!* -1 FOR A TRANSFORM FROM DATA VALUES *
!* TO FOURIER COEFFICIENTS. *
!* *
!* 3.OUTPUT *
!* A - CONTAINS EITHER THE COEFFICIENTS OR THE *
!* DATA VALUES,DEPENDING ON ISIGN. *
!* IN EACH CASE N INDEPENDENT QUANTITIES *
!* OCCUPY N+2 WORDS. THE COEFFICIENTS ARE *
!* STORED AS SUCCESSIVE PAIRS OF REAL AND *
!* IMAGINARY PARTS - *
!* A(K),B(K) , K = 0,1,...N/2 *
!* B(0) AND B(N/2) ARE STORED ALTHOUGH THEY *
!* MUST BE 0. *
!* FOR FFT99 THE DATA IS STORED WITH EXPLICIT *
!* PERIODICITY - *
!* X(N-1),X(0),X(1),....X(N-1),X(0) *
!* FOR FFT991 THE DATA APPEARS AS - *
!* X(0),X(1),X(2),......X(N-1),0,0 *
!* *
!*NOTES 1. ON CRAY-1, ARRANGE DATA SO THAT JUMP IS NOT A *
!* MULTIPLE OF 8 (TO AVOID MEMORY BANK CONFLICTS) *
!* *
!*WRITE UP COMPUTER BULLETIN B6.6/1 *
!* *
!*ENTRY POINTS FFT99,FFT991 *
!* *
!*COMMON BLOCKS NONE *
!* *
!*I/O NONE *
!* *
!*PRECISION SINGLE *
!* *
!*OTHER ROUTINES FFT99A,FFT99B,VPASSM (CY) *
!* REQUIRED CAL99,CPASS (CR) *
!* *
!* *
!*7/80 FFT99-1 *
!* *
!************************************************************************
!* *
!*C06-SUMMATION OF SERIES B6.1/3 *
!* *
!* FFT99 *
!* FFT991 *
!* *
!*ACCESS (OBJECT) CYBER: *
!* ATTACH,ECLIB. *
!* LDSET(LIB = ECLIB) *
!* CRAY 1: *
!* LDR(LIB = ECLIB...) *
!* *
!*ACCESS (SOURCE) ATTACH,OLDPL,ECLIBPL *
!* *
!* CYBER : %DEFINE CYBER *
!* CRAY: %DEFINE CRAY *
!* %C FFT99,FFT991 *
!* *
!*LANGUAGE FORTRAN *
!* BUT CRAY IMPLEMENTATION OF PASS IS IN CAL *
!* *
!*SPECIALIST CLIVE TEMPERTON *
!* *
!*HISTORY WRITTEN BY C.TEMPERTON JAN 1979 *
!* *
!*ALGORITHM THE ALGORITHM IS THE SELF-SORTING (TEMPERTON) *
!* VERSION OF THE FAST FOURIER TRANSFORM *
!* *
!*REFERENCES ECMWF TECHNICAL REPORT NO.3 *
!* ECMWF INTERNAL REPORT NO.21 - C.TEMPERTON *
!* *
!*OBJECT SIZE FFT991 FFT99 (OCTAL WORDS) *
!* CYBER: 2665 2676 *
!* CRAY : 1250 1260 *
!* *
!* *
!*ACCURACY *
!* *
!*TIMING VECTORIZATION IS ON VECTORS OF LENGTH M. (CR) *
!* HENCE TIMING IS STRONGLY DEPENDENT ON M. *
!* TIME PER TRANSFORM ON CRAY-1 (MICROSECONDS) *
!* N M=4 M=16 M=64 *
!* 64 46 17 10 *
!* 128 81 33 21 *
!* 180 150 58 37 *
!* 192 149 58 36 *
!* 240 192 76 49 *
!* 256 191 76 49 *
!* 288 219 89 58 *
!* 300 253 102 68 *
!* 320 248 101 66 *
!* 360 286 118 79 *
!* 1024 898 359 238 *
!* *
!*PORTABILITY STANDARD FORTRAN *
!* STANDARD CAL (CR) *
!* *
!*SYSTEM ROUTINES NONE *
!* REQUIRED *
!* *
!*7/80 FFT99-1 *
!* *
!************************************************************************
!
! SAME AS FFT99 EXCEPT THAT ORDERING OF DATA CORRESPONDS TO
! THAT IN MRFFT2
!
! PROCEDURE USED TO CONVERT TO HALF-LENGTH COMPLEX TRANSFORM
! IS GIVEN BY COOLEY, LEWIS ' WELCH (J. SOUND VIB., VOL. 12
! (1970), 315-337)
!
! A IS THE ARRAY CONTAINING INPUT ' OUTPUT DATA
! WORK IS AN AREA OF SIZE (N+1)*LOT
! TRIGS IS A PREVIOUSLY PREPARED LIST OF TRIG FUNCTION VALUES
! IFAX IS A PREVIOUSLY PREPARED LIST OF FACTORS OF N/2
! INC IS THE INCREMENT WITHIN EACH DATA "VECTOR"
! (E.G. INC=1 FOR CONSECUTIVELY STORED DATA)
! JUMP IS THE INCREMENT BETWEEN THE START OF EACH DATA VECTOR
! N IS THE LENGTH OF THE DATA VECTORS
! LOT IS THE NUMBER OF DATA VECTORS
! ISIGN = +1 FOR TRANSFORM FROM SPECTRAL TO GRIDPOINT
! = -1 FOR TRANSFORM FROM GRIDPOINT TO SPECTRAL
!
! ORDERING OF COEFFICIENTS:
! A(0),B(0),A(1),B(1),A(2),B(2),...,A(N/2),B(N/2)
! WHERE B(0)=B(N/2)=0; (N+2) LOCATIONS REQUIRED
!
! ORDERING OF DATA:
! X(0),X(1),X(2),...,X(N-1)
!
! VECTORIZATION IS ACHIEVED ON CRAY BY DOING THE TRANSFORMS IN
! PARALLEL
!
! **!*N.B. N IS ASSUMED TO BE AN EVEN NUMBER
!
! DEFINITION OF TRANSFORMS:
! -------------------------
!
! ISIGN=+1: X(J)=SUM(K=0,...,N-1)(C(K)*EXP(2*I*J*K*PI/N))
! WHERE C(K)=A(K)+I*B(K) AND C(N-K)=A(K)-I*B(K)
!
! ISIGN=-1: A(K)=(1/N)*SUM(J=0,...,N-1)(X(J)*COS(2*J*K*PI/N))
! B(K)=-(1/N)*SUM(J=0,...,N-1)(X(J)*SIN(2*J*K*PI/N))
!
SUBROUTINE FFT991 (A, WORK, TRIGS, IFAX, INC, JUMP, N, LOT, ISIGN)
USE SHARE_VARS
IMPLICIT NONE
INTEGER N
REAL (KIND=PR), DIMENSION (N) :: A, WORK, TRIGS
INTEGER, DIMENSION (1) :: IFAX
INTEGER :: INC, JUMP, LOT, ISIGN
INTEGER :: NFAX, MX, NH, INK, IGO, IBASE, JBASE, I, J, K, L, M, IA, IB, LA
NFAX=IFAX(1)
MX=N+1
NH=N/2
INK=INC+INC
IF (ISIGN.EQ.+1) GO TO 30
!
! IF NECESSARY, TRANSFER DATA TO WORK AREA
IGO=50
IF (MOD(NFAX,2).EQ.1) GOTO 40
IBASE=1
JBASE=1
DO 20 L=1,LOT
I=IBASE
J=JBASE
DO 10 M=1,N
WORK(J)=A(I)
I=I+INC
J=J+1
10 CONTINUE
IBASE=IBASE+JUMP
JBASE=JBASE+MX
20 CONTINUE
!
IGO=60
GO TO 40
!
! PREPROCESSING (ISIGN=+1)
! ------------------------
!
30 CONTINUE
CALL FFT99A(A,WORK,TRIGS,INC,JUMP,N,LOT)
IGO=60
!
! COMPLEX TRANSFORM
! -----------------
!
40 CONTINUE
IA=1
LA=1
DO 80 K=1,NFAX
IF (IGO.EQ.60) GO TO 60
50 CONTINUE
CALL VPASSM(A(IA),A(IA+INC),WORK(1),WORK(2),TRIGS, &
INK,2,JUMP,MX,LOT,NH,IFAX(K+1),LA)
IGO=60
GO TO 70
60 CONTINUE
CALL VPASSM(WORK(1),WORK(2),A(IA),A(IA+INC),TRIGS, &
2,INK,MX,JUMP,LOT,NH,IFAX(K+1),LA)
IGO=50
70 CONTINUE
LA=LA*IFAX(K+1)
80 CONTINUE
!
IF (ISIGN.EQ.-1) GO TO 130
!
! IF NECESSARY, TRANSFER DATA FROM WORK AREA
IF (MOD(NFAX,2).EQ.1) GO TO 110
IBASE=1
JBASE=1
DO 100 L=1,LOT
I=IBASE
J=JBASE
DO 90 M=1,N
A(J)=WORK(I)
I=I+1
J=J+INC
90 CONTINUE
IBASE=IBASE+MX
JBASE=JBASE+JUMP
100 CONTINUE
!
! FILL IN ZEROS AT END
110 CONTINUE
IB=N*INC+1
DO 120 L=1,LOT
A(IB)=0.0
A(IB+INC)=0.0
IB=IB+JUMP
120 CONTINUE
GO TO 140
!
! POSTPROCESSING (ISIGN=-1):
! --------------------------
!
130 CONTINUE
CALL FFT99B(WORK,A,TRIGS,INC,JUMP,N,LOT)
!
140 CONTINUE
END SUBROUTINE FFT991
! subroutine 'vpassm' - multiple version of 'vpassa'
! performs one pass through data
! as part of multiple complex fft routine
! a is first real input vector
! b is first imaginary input vector
! c is first real output vector
! d is first imaginary output vector
! trigs is precalculated table of sines ' cosines
! inc1 is addressing increment for a and b
! inc2 is addressing increment for c and d
! inc3 is addressing increment between a's & b's
! inc4 is addressing increment between c's & d's
! lot is the number of vectors
! n is length of vectors
! ifac is current factor of n
! la is product of previous factors
SUBROUTINE VPASSM (A, B, C, D, TRIGS, INC1, INC2, INC3, INC4, LOT, N, IFAC, LA)
USE SHARE_VARS
IMPLICIT NONE
INTEGER N
REAL (KIND=PR), DIMENSION (N) :: A, B, C, D, TRIGS
REAL (KIND=PR), PARAMETER :: SIN36 = 0.587785252292473, &
COS36 = 0.809016994374947, &
SIN72 = 0.951056516295154, COS72 = 0.309016994374947, &
SIN60 = 0.866025403784437
REAL (KIND=PR) :: C1, C2, C3, C4, S1, S2, S3, S4
INTEGER :: INC1, INC2, INC3, INC4, LOT, IFAC, LA
INTEGER :: M, IINK, JINK, JUMP, IGO, IA, IB, JA, JB, IBASE, JBASE, I, J, K, L, IJK
INTEGER :: IC, JC, ID, JD, IE, JE, KE, LA1, KB, KC, KD
M=N/IFAC
IINK=M*INC1
JINK=LA*INC2
JUMP=(IFAC-1)*JINK
IBASE=0
JBASE=0
IGO=IFAC-1
! CHECK FACTORS ARE CORRECT - ENSURE NON-NEGATIVE
GO TO (10,50,90,130),IGO
!
! CODING FOR FACTOR 2
!
10 IA=1
JA=1
IB=IA+IINK
JB=JA+JINK
DO 20 L=1,LA
I=IBASE
J=JBASE
DO 15 IJK=1,LOT
C(JA+J)=A(IA+I)+A(IB+I)
D(JA+J)=B(IA+I)+B(IB+I)
C(JB+J)=A(IA+I)-A(IB+I)
D(JB+J)=B(IA+I)-B(IB+I)
I=I+INC3
J=J+INC4
15 CONTINUE
IBASE=IBASE+INC1
JBASE=JBASE+INC2
20 CONTINUE
IF (LA.EQ.M) R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
105 CONTINUE
IBASE=IBASE+INC1
JBASE=JBASE+INC2
110 CONTINUE
JBASE=JBASE+JUMP
120 CONTINUE
RETURN
!
! CODING FOR FACTOR 5
!
130 IA=1
JA=1
IB=IA+IINK
JB=JA+JINK
IC=IB+IINK
JC=JB+JINK
ID=IC+IINK
JD=JC+JINK
IE=ID+IINK
JE=JD+JINK
DO 140 L=1,LA
I=IBASE
J=JBASE
DO 135 IJK=1,LOT
C(JA+J)=A(IA+I)+(A(IB+I)+A(IE+I))+(A(IC+I)+A(ID+I))
D(JA+J)=B(IA+I)+(B(IB+I)+B(IE+I))+(B(IC+I)+B(ID+I))
C(JB+J)=(A(IA+I)+COS72*(A(IB+I)+A(IE+I))-COS36*(A(IC+I)+A(ID+I))) &
-(SIN72*(B(IB+I)-B(IE+I))+SIN36*(B(IC+I)-B(ID+I)))
C(JE+J)=(A(IA+I)+COS72*(A(IB+I)+A(IE+I))-COS36*(A(IC+I)+A(ID+I))) &
+(SIN72*(B(IB+I)-B(IE+I))+SIN36*(B(IC+I)-B(ID+I)))
D(JB+J)=(B(IA+I)+COS72*(B(IB+I)+B(IE+I))-COS36*(B(IC+I)+B(ID+I))) &
+(SIN72*(A(IB+I)-A(IE+I))+SIN36*(A(IC+I)-A(ID+I)))
D(JE+J)=(B(IA+I)+COS72*(B(IB+I)+B(IE+I))-COS36*(B(IC+I)+B(ID+I))) &
-(SIN72*(A(IB+I)-A(IE+I))+SIN36*(A(IC+I)-A(ID+I)))
C(JC+J)=(A(IA+I)-COS36*(A(IB+I)+A(IE+I))+COS72*(A(IC+I)+A(ID+I))) &
-(SIN36*(B(IB+I)-B(IE+I))-SIN72*(B(IC+I)-B(ID+I)))
C(JD+J)=(A(IA+I)-COS36*(A(IB+I)+A(IE+I))+COS72*(A(IC+I)+A(ID+I))) &
+(SIN36*(B(IB+I)-B(IE+I))-SIN72*(B(IC+I)-B(ID+I)))
D(JC+J)=(B(IA+I)-COS36*(B(IB+I)+B(IE+I))+COS72*(B(IC+I)+B(ID+I))) &
+(SIN36*(A(IB+I)-A(IE+I))-SIN72*(A(IC+I)-A(ID+I)))
D(JD+J)=(B(IA+I)-COS36*(B(IB+I)+B(IE+I))+COS72*(B(IC+I)+B(ID+I))) &
-(SIN36*(A(IB+I)-A(IE+I))-SIN72*(A(IC+I)-A(ID+I)))
I=I+INC3
J=J+INC4
135 CONTINUE
IBASE=IBASE+INC1
JBASE=JBASE+INC2
140 CONTINUE
IF (LA.EQ.M) RETURN
LA1=LA+1