forked from anowacki/mineos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fftsubs.f
1265 lines (1265 loc) · 30.4 KB
/
fftsubs.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
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
c
c MINEOS version 1.0 by Guy Masters, John Woodhouse, and Freeman Gilbert
c
c This program is free software; you can redistribute it and/or modify
c it under the terms of the GNU General Public License as published by
c the Free Software Foundation; either version 2 of the License, or
c (at your option) any later version.
c
c This program is distributed in the hope that it will be useful,
c but WITHOUT ANY WARRANTY; without even the implied warranty of
c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c GNU General Public License for more details.
c
c You should have received a copy of the GNU General Public License
c along with this program; if not, write to the Free Software
c Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
c
c*************************************************************************
c
c FFT routines
c
c*************************************************************************
SUBROUTINE FACTOR(N)
C FACTOR DETERMINES THE SMALLEST EVEN NUMBER .GE. N THAT CAN BE FACTORED INTO
C PRODUCTS OF PRIMES IN THE ARRAY NP. THE RESULT IS RETURNED AS N.
C ONLY THE FIRST FOUR PRIMES ARE USED. THIS ROUTINE IS CALLED BEFORE USING FFTL.
DIMENSION NP(4)
DATA NP/2,3,5,7/
NCHK=N/2
IF(N.NE.(NCHK*2)) N=N+1
5 NF=N
DO 15 I=1,4
M=NP(I)
10 L=MOD(NF,M)
IF(L.NE.0) GO TO 15
NF=NF/M
GO TO 10
15 CONTINUE
IF(NF.EQ.1) RETURN
N=N+2
GO TO 5
END
SUBROUTINE FACDWN(N)
C FACDWN DETERMINES THE LARGEST EVEN NUMBER .LE. N THAT CAN BE FACTORED INTO
C PRODUCTS OF PRIMES IN THE ARRAY NP. THE RESULT IS RETURNED AS N.
C ONLY THE FIRST FOUR PRIMES ARE USED. THIS ROUTINE IS CALLED BEFORE USING FFTL.
DIMENSION NP(4)
DATA NP/2,3,5,7/
NCHK=N/2
IF(N.NE.(NCHK*2)) N=N-1
5 NF=N
DO 15 I=1,4
M=NP(I)
10 L=MOD(NF,M)
IF(L.NE.0) GO TO 15
NF=NF/M
GO TO 10
15 CONTINUE
IF(NF.EQ.1) RETURN
N=N-2
GO TO 5
END
SUBROUTINE FFTL(X,N,NDIR,IERR)
C IF IABS(NDIR)=1 FFTL FOURIER TRANSFORMS THE N POINTS REAL TIME SERIES IN ARRAY
C X. THE RESULT OVERWRITES X STORED AS (N+2)/2 COMPLEX NUMBERS (NON-NEGATIVE
C FREQUENCIES ONLY).
C IF IABS(NDIR)=2 FFTL FOURIER TRANSFORMS THE (N+2)/2 COMPLEX FOURIER COEFFICIENTS
C (NON-NEGATIVE FREQUENCIES ONLY) IN ARRAY X (ASSUMING THE SERIES IS HERMITIAN).
C THE RESULTING N POINT REAL TIME SERIES OVERWRITES X.
C NDIR>0 THE FORWARD TRANSFORM USES THE SIGN CONVENTION EXP(I*W*T).
C NDIR<0 THE FORWARD TRANSFORM USES THE SIGN CONVENTION EXP(-I*W*T).
C THE FORWARD TRANSFORM IS NORMALIZED SUCH THAT A SINE WAVE OF UNIT AMPLITUDE
C IS TRANSFORMED INTO DELTA FUNCTIONS OF UNIT AMPLITUDE. THE BACKWARD TRANSFORM
C IS NORMALIZED SUCH THAT TRANSFORMING FORWARD AND THEN BACK RECOVERS THE
C ORIGINAL SERIES. IERR IS NORMALLY ZERO. IF IERR.EQ.1 THEN FFT HAS NOT BEEN
C ABLE TO FACTOR THE SERIES. HOWEVER, X HAS BEEN SCRAMBLED BY REALTR. NOTE
C THAT IF N IS ODD THE LAST POINT WILL NOT BE USED IN THE TRANSFORM.
C -RPB
DIMENSION X(*)
N2=N/2
IDIR=IABS(NDIR)
GO TO (1,2),IDIR
C DO FORWARD TRANSFORM (IE. TIME TO FREQUENCY).
1 CALL FFT(X,X(2),N2,N2,N2,2,IERR)
CALL REALTR(X,X(2),N2,2)
N1=2*N2+2
SCALE=1./N
IF(NDIR.GT.0) GO TO 3
DO 5 I=4,N,2
5 X(I)=-X(I)
GO TO 3
C DO BACKWARD TRANSFORM (IE. FREQUENCY TO TIME).
2 IF(NDIR.GT.0) GO TO 6
DO 7 I=4,N,2
7 X(I)=-X(I)
6 X(2)=0.
X(2*N2+2)=0.
CALL REALTR(X,X(2),N2,-2)
CALL FFT(X,X(2),N2,N2,N2,-2,IERR)
N1=2*N2
SCALE=.5
C NORMALIZE THE TRANSFORM.
3 DO 4 I=1,N1
4 X(I)=SCALE*X(I)
RETURN
END
SUBROUTINE REALTR(A,B,N,ISN)
C IF ISN=1, THIS SUBROUTINE COMPLETES THE FOURIER TRANSFORM OF 2*N REAL
C DATA VALUES, WHERE THE ORIGINAL DATA VALUES ARE STORED ALTERNATELY IN
C ARRAYS A AND B, AND ARE FIRST TRANSFORMED BY A COMPLEX FOURIER TRANSFORM
c OF DIMENSION N. THE COSINE COEFFICIENTS ARE IN A(1),A(2),...A(N+1) AND
C THE SINE COEFFICIENTS ARE IN B(1),B(2),...B(N+1). A TYPICAL CALLING
C SEQUENCE IS
C CALL FFT (A,B,N,1)
C CALL REALTR (A,B,N,1)
C THE RESULTS SHOULD BE MULTIPLIED BY 0.5/N TO GIVE THE USUAL SCALING
C IF ISN=1, THE INVERSE TRANSFORMATION IS DONE, THE FIRST STEP IN EVALUATING
C A REAL FOURIER SERIES. A TYPICAL CALLING SEQUENCE IS
C CALL REALTR (A,B,N,-1)
C CALL FFT (A,B,N,-1)
C THE RESULTS SHOULD BE MULTIPLIED BY 0.5 TO GIVE THE USUAL SCALING, AND
C THE TIME DOMAIN RESULTS ALTERNATE IN ARRAYS A AND B, I.E. A(1),B(1), A(2),B(2),
C ...A(N),B(N). THE DATA MAY ALTERNATIVELY BE STORED IN A SINGLE COMPLEX
C ARRAY A, THEN THE MAGNITUDE OF ISN CHANGED TO TWO TO GIVE THE CORRECT
C INDEXING INCREMENT AND A(2) USED TO PASS THE INITIAL ADDRESS FOR THE
C SEQUENCE OF IMAGINARY VALUES,E.G.
C CALL FFT(A,A(2),N,2)
C CALL REALTR(A,A(2),N,2)
C IN THIS CASE, THE COSINE AND SINE COEFFICIENTS ALTERNATE IN A.
DIMENSION A(*),B(*)
IF(N .LE. 1) RETURN
INC=ISN
IF(INC.LT.0) INC=-INC
NK = N * INC + 2
NH = NK / 2
SD = 3.1415926535898E0/(2.E0*N)
CD = 2.E0 * SIN(SD)**2
SD = SIN(SD+SD)
SN = 0.E0
IF(ISN .GT. 0) GO TO 10
CN = -1.E0
SD = -SD
GO TO 20
10 CN = 1.E0
A(NK-1) = A(1)
B(NK-1) = B(1)
20 DO 30 J=1,NH,INC
K = NK - J
AA = A(J) + A(K)
AB = A(J) - A(K)
BA = B(J) + B(K)
BB = B(J) - B(K)
XX = CN * BA + SN * AB
YY = SN * BA - CN * AB
B(K) = YY - BB
B(J) = YY + BB
A(K) = AA - XX
A(J) = AA + XX
AA = CN - (CD * CN + SD * SN)
SN = (SD * CN - CD * SN) + SN
30 CN = AA
RETURN
END
SUBROUTINE FFT(A,B,NTOT,N,NSPAN,ISN,IERR)
C FFT IS A SINGLE PRECISION VERSION OF SINGLETON'S FFT PROCEDURE.
C MULTIVARIATE COMPLEX FOURIER TRANSFORM, COMPUTED IN PLACE USING
C MIXED-RADIX FAST FOURIER TRANSFORM ALGORITHM. BY R. C. SINGLETON,
C STANFORD RESEARCH INSTITUTE, SEPT. 1968
C ARRAYS A AND B ORIGINALLY HOLD THE REAL AND IMAGINARY COMPONENTS OF THE
C DATA, AND RETURN THE REAL AND IMAGINARY COMPONENTS OF THE RESULTING FOURIER
C COEFFICIENTS. MULTIVARIATE DATA IS INDEXED ACCORDING TO THE FORTRAN ARRAY
C ELEMENT SUCCESSOR FUNCTION, WITHOUT LIMIT ON THE NUMBER OF IMPLIED MULTIPLE
C SUBSCRIPTS. THE SUBROUTINE IS CALLED ONCE FOR EACH VARIATE. THE CALLS FOR A
C MULTIVARIATE TRANSFORM MAY BE IN ANY ORDER.
C NTOT IS THE TOTAL NUMBER OF COMPLEX DATA VALUES.
C N IS THE DIMENSION OF THE CURRENT VARIABLE.
C NSPAN/N IS THE SPACING OF CONSECUTIVE DATA VALUES FOR THE CURRENT VARIABLE.
C IERR IS AN ERROR RETURN INDICATOR. IT IS NORMALLY ZERO, BUT IS SET TO 1 IF
C THE NUMBER OF TERMS CANNOT BE FACTORED IN THE SPACE AVAILABLE.
C THE SIGN OF ISN DETERMINES THE SIGN OF THE COMPLEX EXPONENTIAL, AND THE
C MAGNITUDE OF ISN IS NORMALLY ONE.
C A TRI-VARIATE TRANSFORM WITH A(N1,N2,N3), B(N1,N2,N3) IS COMPUTED BY
C CALL FFT(A,B,N1*N2*N3,N1,N1,1)
C CALL FFT(A,B,N1*N2*N3,N2,N1*N2,1)
C CALL FFT(A,B,N1*N2*N3,N3,N1*N2*N3,1)
C FOR A SINGLE-VARIATE TRANSFORM,
C NTOT = N = NSPAN = (NUMBER OF COMPLEX DATA VALUES), E.G.
C CALL FFT(A,B,N,N,N,1)
C WITH MOST FORTRAN COMPILERS THE DATA CAN ALTERNATIVELY BE STORED IN A SINGLE
C COMPLEX ARRAY A, THEN THE MAGNITUDE OF ISN CHANGED TO TWO TO GIVE THE CORRECT
C INDEXING INCREMENT AND A(2) USED TO PASS THE INITIAL ADDRESS FOR THE SEQUENCE
C OF IMAGINARY VALUES, E.G.
C CALL FFT(A,A(2),NTOT,N,NSPAN,2)
C ARRAYS AT(MAXF), CK(MAXF), BT(MAXF), SK(MAXF), AND NP(MAXP) ARE USED FOR
C TEMPORARY STORAGE. IF THE AVAILABLE STORAGE IS INSUFFICIENT, THE PROGRAM IS
C TERMINATED BY THE ERROR RETURN OPTION
C MAXF MUST BE .GE. THE MAXIMUM PRIME FACTOR OF N.
C MAXP MUST BE .GT. THE NUMBER OF PRIME FACTORS OF N.
C IN ADDITION, IF THE SQUARE-FREE PORTION K OF N HAS TWO OR MORE PRIME FACTORS,
C THEN MAXP MUST BE .GE. K-1. ARRAY STORAGE IN NFAC FOR A MAXIMUM OF 11 PRIME
C FACTORS OF N. IF N HAS MORE THAN ONE SQUARE-FREE FACTOR, THE PRODUCT OF THE
C SQUARE-FREE FACTORS MUST BE .LE. 210. (2**5*7=210)
DIMENSION A(*),B(*)
DIMENSION NFAC(11),NP(209)
C ARRAY STORAGE FOR MAXIMUM PRIME FACTOR OF 23
DIMENSION AT(23),CK(23),BT(23),SK(23)
EQUIVALENCE (I,II)
C THE FOLLOWING TWO CONSTANTS SHOULD AGREE WITH THE ARRAY DIMENSIONS.
MAXF=23
MAXP=209
IERR=0
IF(N .LT. 2) RETURN
INC=ISN
C72=0.30901699437494E0
S72=0.95105651629515E0
S120=0.86602540378443E0
RAD=6.2831853071796E0
IF(ISN .GE. 0) GO TO 10
S72=-S72
S120=-S120
RAD=-RAD
INC=-INC
10 NT=INC*NTOT
KS=INC*NSPAN
KSPAN=KS
NN=NT-INC
JC=KS/N
RADF=RAD*(JC*0.5E0)
I=0
JF=0
C DETERMINE THE FACTORS OF N
M=0
K=N
GO TO 20
15 M=M+1
NFAC(M)=4
K=K/16
20 IF(K-(K/16)*16 .EQ. 0) GO TO 15
J=3
JJ=9
GO TO 30
25 M=M+1
NFAC(M)=J
K=K/JJ
30 IF(MOD(K,JJ) .EQ. 0) GO TO 25
J=J+2
JJ=J**2
IF(JJ .LE. K) GO TO 30
IF(K .GT. 4) GO TO 40
KT=M
NFAC(M+1)=K
IF(K .NE. 1) M=M+1
GO TO 80
40 IF(K-(K/4)*4 .NE. 0) GO TO 50
M=M+1
NFAC(M)=2
K=K/4
50 KT=M
J=2
60 IF(MOD(K,J) .NE. 0) GO TO 70
M=M+1
NFAC(M)=J
K=K/J
70 J=((J+1)/2)*2+1
IF(J .LE. K) GO TO 60
80 IF(KT .EQ. 0) GO TO 100
J=KT
90 M=M+1
NFAC(M)=NFAC(J)
J=J-1
IF(J .NE. 0) GO TO 90
C COMPUTE FOURIER TRANSFORM
100 SD=RADF/(KSPAN)
CD=2.E0*SIN(SD)**2
SD=SIN(SD+SD)
KK=1
I=I+1
IF(NFAC(I) .NE. 2) GO TO 400
C TRANSFORM FOR FACTOR OF 2 (INCLUDING ROTATION FACTOR)
KSPAN=KSPAN/2
K1=KSPAN+2
210 K2=KK+KSPAN
AK=A(K2)
B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SK(JJ)+BJ
JJ=JJ+J
IF(JJ .GT. JF) JJ=JJ-JF
IF(K .LT. JF) GO TO 670
K=JF-J
A(K1)=AK-BJ
B(K1)=BK+AJ
A(K2)=AK+BJ
B(K2)=BK-AJ
J=J+1
IF(J .LT. K) GO TO 660
KK=KK+KSPNN
IF(KK .LE. NN) GO TO 640
KK=KK-NN
IF(KK .LE. KSPAN) GO TO 640
C MULTIPLY BY ROTATION FACTOR (EXCEPT FOR FACTORS OF 2 AND 4)
700 IF(I .EQ. M) GO TO 800
KK=JC+1
710 C2=1.E0-CD
S1=SD
720 C1=C2
S2=S1
KK=KK+KSPAN
730 AK=A(KK)
A(KK)=C2*AK-S2*B(KK)
B(KK)=S2*AK+C2*B(KK)
KK=KK+KSPNN
IF(KK .LE. NT) GO TO 730
AK=S1*S2
S2=S1*C2+C1*S2
C2=C1*C2-AK
KK=KK-NT+KSPAN
IF(KK .LE. KSPNN) GO TO 730
C2=C1-(CD*C1+SD*S1)
S1=S1+(SD*C1-CD*S1)
KK=KK-KSPNN+JC
IF(KK .LE. KSPAN) GO TO 720
KK=KK-KSPAN+JC+INC
IF(KK .LE. JC+JC) GO TO 710
GO TO 100
C PERMUTE THE RESULTS TO NORMAL ORDER---DONE IN TWO STAGES
C PERMUTATION FOR SQUARE FACTORS OF N
800 NP(1)=KS
IF(KT .EQ. 0) GO TO 890
K=KT+KT+1
IF(M .LT. K) K=K-1
J=1
NP(K+1)=JC
810 NP(J+1)=NP(J)/NFAC(J)
NP(K)=NP(K+1)*NFAC(J)
J=J+1
K=K-1
IF(J .LT. K) GO TO 810
K3=NP(K+1)
KSPAN=NP(2)
KK=JC+1
K2=KSPAN+1
J=1
IF(N .NE. NTOT) GO TO 850
C PERMUTATION FOR SINGLE-VARIATE TRANSFORM (OPTIONAL CODE)
820 AK=A(KK)
A(KK)=A(K2)
A(K2)=AK
BK=B(KK)
B(KK)=B(K2)
B(K2)=BK
KK=KK+INC
K2=KSPAN+K2
IF(K2 .LT. KS) GO TO 820
830 K2=K2-NP(J)
J=J+1
K2=NP(J+1)+K2
IF(K2 .GT. NP(J)) GO TO 830
J=1
840 IF(KK .LT. K2) GO TO 820
KK=KK+INC
K2=KSPAN+K2
IF(K2 .LT. KS) GO TO 840
IF(KK .LT. KS) GO TO 830
JC=K3
GO TO 890
C PERMUTATION FOR MULTIVARIATE TRANSFORM
850 K=KK+JC
860 AK=A(KK)
A(KK)=A(K2)
A(K2)=AK
BK=B(KK)
B(KK)=B(K2)
B(K2)=BK
KK=KK+INC
K2=K2+INC
IF(KK .LT. K) GO TO 860
KK=KK+KS-JC
K2=K2+KS-JC
IF(KK .LT. NT) GO TO 850
K2=K2-NT+KSPAN
KK=KK-NT+JC
IF(K2 .LT. KS) GO TO 850
870 K2=K2-NP(J)
J=J+1
K2=NP(J+1)+K2
IF(K2 .GT. NP(J)) GO TO 870
J=1
880 IF(KK .LT. K2) GO TO 850
KK=KK+JC
K2=KSPAN+K2
IF(K2 .LT. KS) GO TO 880
IF(KK .LT. KS) GO TO 870
JC=K3
890 IF(2*KT+1 .GE. M) RETURN
KSPNN=NP(KT+1)
C PERMUTATION FOR SQUARE-FREE FACTORS OF N
J=M-KT
NFAC(J+1)=1
900 NFAC(J)=NFAC(J)*NFAC(J+1)
J=J-1
IF(J .NE. KT) GO TO 900
KT=KT+1
NN=NFAC(KT)-1
IF(NN .GT. MAXP) GO TO 998
JJ=0
J=0
GO TO 906
902 JJ=JJ-K2
K2=KK
K=K+1
KK=NFAC(K)
904 JJ=KK+JJ
IF(JJ .GE. K2) GO TO 902
NP(J)=JJ
906 K2=NFAC(KT)
K=KT+1
KK=NFAC(K)
J=J+1
IF(J .LE. NN) GO TO 904
C DETERMINE THE PERMUTATION CYCLES OF LENGTH GREATER THAN 1
J=0
GO TO 914
910 K=KK
KK=NP(K)
NP(K)=-KK
IF(KK .NE. J) GO TO 910
K3=KK
914 J=J+1
KK=NP(J)
IF(KK .LT. 0) GO TO 914
IF(KK .NE. J) GO TO 910
NP(J)=-J
IF(J .NE. NN) GO TO 914
MAXF=INC*MAXF
C REORDER A AND B, FOLLOWING THE PERMUTATION CYCLES
GO TO 950
924 J=J-1
IF(NP(J) .LT. 0) GO TO 924
JJ=JC
926 KSPAN=JJ
IF(JJ .GT. MAXF) KSPAN=MAXF
JJ=JJ-KSPAN
K=NP(J)
KK=JC*K+II+JJ
K1=KK+KSPAN
K2=0
928 K2=K2+1
AT(K2)=A(K1)
BT(K2)=B(K1)
K1=K1-INC
IF(K1 .NE. KK) GO TO 928
932 K1=KK+KSPAN
K2=K1-JC*(K+NP(K))
K=-NP(K)
936 A(K1)=A(K2)
B(K1)=B(K2)
K1=K1-INC
K2=K2-INC
IF(K1 .NE. KK) GO TO 936
KK=K2
IF(K .NE. J) GO TO 932
K1=KK+KSPAN
K2=0
940 K2=K2+1
A(K1)=AT(K2)
B(K1)=BT(K2)
K1=K1-INC
IF(K1 .NE. KK) GO TO 940
IF(JJ .NE. 0) GO TO 926
IF(J .NE. 1) GO TO 924
950 J=K3+1
NT=NT-KSPNN
II=NT-INC+1
IF(NT .GE. 0) GO TO 924
RETURN
C ERROR FINISH, INSUFFICIENT ARRAY STORAGE
998 IERR=1
RETURN
END
SUBROUTINE FFTLDP(X,N,NDIR,DT,IERR)
C FFTLDP IS A DOUBLE PRECISION VERSION OF FFTL. SEE NOTES TO FFTL FOR USAGE
C THE SCALING IN FFTLDP DIFFERS FROM THAT IN FFTL :
C THE FORWARD TRANSFORM IS SPECTRUM(W)=DT*SUM(0,N-1)X(J)*EXP(-I*W*J*DT)
C THE SPACING IN W IS 2*PI/(N*DT)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION X(*)
N2=N/2
IDIR=NDIR
IF(IDIR.LT.0) IDIR=-IDIR
GO TO (1,2),IDIR
C DO FORWARD TRANSFORM (IE. TIME TO FREQUENCY).
1 CALL FFTDP(X,X(2),N2,N2,N2,2,IERR)
CALL RLTRDP(X,X(2),N2,2)
N1=2*N2+2
SCALE=0.5D0*DT
IF(NDIR.GT.0) GO TO 3
DO 5 I=4,N,2
5 X(I)=-X(I)
GO TO 3
C DO BACKWARD TRANSFORM (IE. FREQUENCY TO TIME).
2 IF(NDIR.GT.0) GO TO 6
DO 7 I=4,N,2
7 X(I)=-X(I)
6 X(2)=0.D0
N1=2*N2
X(N1+2)=0.D0
CALL RLTRDP(X,X(2),N2,-2)
CALL FFTDP(X,X(2),N2,N2,N2,-2,IERR)
SCALE=1.D0/(N*DT)
C NORMALIZE THE TRANSFORM.
3 DO 4 I=1,N1
4 X(I)=SCALE*X(I)
RETURN
END
SUBROUTINE RLTRDP(A,B,N,ISN)
C RLTRDP IS A DOUBLE PRECISION VERSION OF REALTR. SEE REALTR FOR NOTES
C ON USAGE.
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION A(*),B(*)
IF(N .LE. 1) RETURN
INC=ISN
IF(INC.LT.0) INC=-INC
NK = N * INC + 2
NH = NK / 2
SD = 3.1415926535898D0/(2.D0*N)
CD = 2.D0 * DSIN(SD)**2
SD = DSIN(SD+SD)
SN = 0.D0
IF(ISN .GT. 0) GO TO 10
CN = -1.D0
SD = -SD
GO TO 20
10 CN = 1.D0
A(NK-1) = A(1)
B(NK-1) = B(1)
20 DO 30 J=1,NH,INC
K = NK - J
AA = A(J) + A(K)
AB = A(J) - A(K)
BA = B(J) + B(K)
BB = B(J) - B(K)
XX = CN * BA + SN * AB
YY = SN * BA - CN * AB
B(K) = YY - BB
B(J) = YY + BB
A(K) = AA - XX
A(J) = AA + XX
AA = CN - (CD * CN + SD * SN)
SN = (SD * CN - CD * SN) + SN
30 CN = AA
RETURN
END
SUBROUTINE FFTDP(A,B,NTOT,N,NSPAN,ISN,IERR)
C FFTDP IS A DOUBLE PRECISION VERSION OF SINGLETON'S FFT PROCEDURE. SEE NOTES
C TO FFT FOR USAGE
IMPLICIT REAL*8(A-H),REAL*8(O-Z)
DIMENSION A(*),B(*)
DIMENSION NFAC(11),NP(209)
C ARRAY STORAGE FOR MAXIMUM PRIME FACTOR OF 23
DIMENSION AT(23),CK(23),BT(23),SK(23)
EQUIVALENCE (I,II)
C THE FOLLOWING TWO CONSTANTS SHOULD AGREE WITH THE ARRAY DIMENSIONS.
MAXF=23
MAXP=209
IERR=0
IF(N .LT. 2) RETURN
INC=ISN
C72=0.30901699437494D0
S72=0.95105651629515D0
S120=0.86602540378443D0
RAD=6.2831853071796D0
IF(ISN .GE. 0) GO TO 10
S72=-S72
S120=-S120
RAD=-RAD
INC=-INC
10 NT=INC*NTOT
KS=INC*NSPAN
KSPAN=KS
NN=NT-INC
JC=KS/N
RADF=RAD*(JC*0.5D0)
I=0
JF=0
C DETERMINE THE FACTORS OF N
M=0
K=N
GO TO 20
15 M=M+1
NFAC(M)=4
K=K/16
20 IF(K-(K/16)*16 .EQ. 0) GO TO 15
J=3
JJ=9
GO TO 30
25 M=M+1
NFAC(M)=J
K=K/JJ
30 IF(MOD(K,JJ) .EQ. 0) GO TO 25
J=J+2
JJ=J**2
IF(JJ .LE. K) GO TO 30
IF(K .GT. 4) GO TO 40
KT=M
NFAC(M+1)=K
IF(K .NE. 1) M=M+1
GO TO 80
40 IF(K-(K/4)*4 .NE. 0) GO TO 50
M=M+1
NFAC(M)=2
K=K/4
50 KT=M
J=2
60 IF(MOD(K,J) .NE. 0) GO TO 70
M=M+1
NFAC(M)=J
K=K/J
70 J=((J+1)/2)*2+1
IF(J .LE. K) GO TO 60
80 IF(KT .EQ. 0) GO TO 100
J=KT
90 M=M+1
NFAC(M)=NFAC(J)
J=J-1
IF(J .NE. 0) GO TO 90
C COMPUTE FOURIER TRANSFORM
100 SD=RADF/(KSPAN)
CD=2.D0*DSIN(SD)**2
SD=DSIN(SD+SD)
KK=1
I=I+1
IF(NFAC(I) .NE. 2) GO TO 400
C TRANSFORM FOR FACTOR OF 2 (INCLUDING ROTATION FACTOR)
KSPAN=KSPAN/2
K1=KSPAN+2
210 K2=KK+KSPAN
AK=A(K2)
BK=B(K2)
A(K2)=A(KK)-AK
B(K2)=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