-
Notifications
You must be signed in to change notification settings - Fork 0
/
pfft2lib.f
11994 lines (11994 loc) · 378 KB
/
pfft2lib.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 2d parallel PIC library for fast fourier transforms
c pfft2lib.f contains procedures to perform ffts:
c PFFT2C performs complex to complex fft and its inverse,
c for distributed data.
c WPFFT2RINIT calculates tables needed by a two dimensional real to
c complex fast fourier transform and its inverse,
c for distributed data.
c WPFFT2R performs real to complex fft and its inverse for scalar array,
c for distributed data.
c WPFFT2RX performs real to complex fft and its inverse for scalar
c array, for distributed data, with bufferless algorithm.
c WPFFT2R2 performs real to complex fft and its inverse for 2 component
c vector array, for distributed data.
c WPFFT2R3 performs real to complex fft and its inverse for 3 component
c vector array, for distributed data.
c WPFFT2RX2 performs real to complex fft and its inverse for 2 component
c vector array, for distributed data, with bufferless
c algorithm.
c WPFFT2RX3 performs real to complex fft and its inverse for 3 component
c vector array, for distributed data, with bufferless
c algorithm.
c WPFFT2RN performs real to complex fft and its inverse for n component
c vector array, for distributed data.
c WPFFT2RXN performs real to complex fft and its inverse for n component
c vector array, for distributed data, with bufferless
c algorithm.
c WP2FFT2RN performs two real to complex ffts and their inverses for n
c component vector arrays, for distributed data.
c WPFST2RINIT calculates tables needed by a two dimensional fast real
c sine and cosine transforms and their inverses,
c for distributed data.
c WPFSST2R performs fast real sine/sine transform, for distributed data.
c WPFSCT2R performs fast real mixed sine/cosine transform,
c for distributed data.
c WPFCST2R performs fast real mixed cosine/sine transform,
c for distributed data.
c WPFCCT2R performs fast real cosine/cosine transform, for distributed
c data.
c WPFCST2R2 performs fast real cosine/sine transform for 2 component
c vector array for the electric field with dirichlet or
c magnetic field with neumann boundary conditions,
c for distributed data.
c WPFSCT2R2 performs fast real sine/cosine transform for 2 component
c vector array for the magnetic field with dirichlet or
c electric field with neumann boundary conditions,
c for distributed data.
c WPFCST2R3 performs fast real cosine/sine transform for 3 component
c vector array for the electric field with dirichlet or
c magnetic field with neumann boundary conditions,
c for distributed data.
c WPFSCT2R3 performs fast real sine/cosine transform for 3 component
c vector array for the magnetic field with dirichlet or
c electric field with neumann boundary conditions,
c for distributed data.
c WPFSFT2R performs fast real mixed sine/periodic transform,
c for distributed data.
c WPFCFT2R performs fast real mixed cosine/periodic transform,
c for distributed data.
c WPFCSFT2R2 performs fast real cosine/sine/periodic transform for
c 2 component vector array for the electric field with
c dirichlet or magnetic field with neumann boundary
c conditions, for distributed data.
c WPFSCFT2R2 performs fast real cosine/sine/periodic transform for
c 2 component vector array for the magnetic field with
c dirichlet or electric field with neumann boundary
c conditions, for distributed data.
c WPFCSFT2R3 performs fast real cosine/sine/periodic transform for
c 3 component vector array for the electric field with
c dirichlet or magnetic field with neumann boundary
c conditions, for distributed data.
c WPFSCFT2R3 performs fast real cosine/sine/periodic transform for
c 3 component vector array for the magnetic field with
c dirichlet or electric field with neumann boundary
c conditions, for distributed data.
c WPFDT2RINIT calculates tables needed by a two dimensional fast real
c sine DST-III/cosine DCT-III/periodic transforms and their
c inverses, for distributed data.
c WPFDSFT2RX performs fast real mixed sine DST-III/periodic transform,
c for distributed data.
c WPFDCFT2RX performs fast real mixed cosine DCT-III/periodic transform,
c for distributed data.
c WPFDCSFT2R2 performs real cosine DCT-III/sine DST-III/periodic
c transforms for the electric field with mixed
c dirichlet-neumann or magnetic field with mixed
c neumann-dirichlet boundary conditions, for distributed
c data.
c WPFDSCFT2R2 performs real sine DST-III/cosine DCT-III/periodic
c transforms for 2 component vector array for the magnetic
c field with mixed dirichlet-neumann or electric field with
c mixed neumann-dirichlet boundary conditions,
c for distributed data.
c WPFDCSFT2R3 performs real cosine DCT-III/sine DST-III/periodic
c transforms for 3 component vector array for the electric
c field with mixed dirichlet-neumann or magnetic field with
c mixed neumann-dirichlet boundary conditions,
c for distributed data.
c WPFDSCFT2R3 performs real sine DST-III/cosine DCT-III/periodic
c transforms for 3 component vector array for the magnetic
c field with mixed dirichlet-neumann or electric field with
c mixed neumann-dirichlet boundary conditions,
c for distributed data.
c written by viktor k. decyk, ucla
c copyright 1995, regents of the university of california
c update: december 10, 2009
c-----------------------------------------------------------------------
subroutine PFFT2R(f,g,bs,br,isign,ntpose,mixup,sct,indx,indy,kstrt
1,nxvh,nyv,kxp,kyp,kypd,jblok,kblok,nxhyd,nxyhd)
c this subroutine performs a two dimensional real to complex fast
c fourier transform and its inverse, using complex arithmetic,
c for data which is distributed in blocks
c for isign = 0, input: isign, indx, indy, kstrt, nxhyd, nxyhd
c output: mixup, sct
c for isign = (-1,1), input: all, output: f, g, bs, br
c for isign = -1, approximate flop count: N*(5*log2(N) + 10)/nvp
c for isign = 1, approximate flop count: N*(5*log2(N) + 8)/nvp
c where N = (nx/2)*ny, and nvp = number of procs
c indx/indy = exponent which determines length in x/y direction,
c where nx=2**indx, ny=2**indy
c ntpose = (0,1) = (no,yes) input, output data are transposed
c if isign = 0, the fft tables are prepared
c if isign = -1, an inverse fourier transform is performed
c if ntpose = 0, f is the input and output array, g is a scratch array
c f(n,m,l) = (1/nx*ny)*sum(f(j,k,i)*
c exp(-sqrt(-1)*2pi*n*j/nx)*exp(-sqrt(-1)*2pi*mm*kk/ny))
c where mm = m + kyp*(l - 1) and kk = k + kyp*(i - 1)
c if ntpose = 1, f is the input and g is the output
c g(m,n,l) = (1/nx*ny)*sum(f(j,k,i)*
c exp(-sqrt(-1)*2pi*nn*j/nx)*exp(-sqrt(-1)*2pi*m*kk/ny))
c where nn = n + kxp*(l - 1) and kk = k + kyp*(i - 1)
c if isign = 1, a forward fourier transform is performed
c if ntpose = 0, f is the input and output array, g is a scratch array
c f(j,k,i) = sum(f(n,m,l)*exp(sqrt(-1)*2pi*n*j/nx)*
c exp(sqrt(-1)*2pi*mm*kk/ny))
c where mm = m + kyp*(l - 1) and kk = k + kyp*(i - 1)
c if ntpose = 1, g is the input and f is the output
c f(j,k,i) = sum(g(m,n,l)*exp(sqrt(-1)*2pi*nn*j/nx)*
c exp(sqrt(-1)*2pi*m*kk/ny))
c where nn = n + kxp*(l - 1) and kk = k + kyp*(i - 1)
c bs, br = scratch arrays
c kstrt = starting data block number
c nxvh/nyv = first dimension of f/g
c kypd = second dimension of f
c kxp/kyp = number of data values per block in x/y
c jblok/kblok = number of data blocks in x/y
c mixup = array of bit reversed addresses
c sct = sine/cosine table
c nxhyd = maximum of (nx/2,ny)
c nxyhd = one half of maximum of (nx,ny)
c the real data is stored in a complex array of length nx/2, ny
c with the odd/even x points stored in the real/imaginary parts.
c in complex notation, fourier coefficients are stored as follows:
c if ntpose = 0,
c f(j,k,i) = mode j-1,kk-1, where kk = k + kyp*(i - 1)
c 1 <= j <= nx/2 and 1 <= kk <= ny, except for
c f(1,k,i) = mode nx/2,kk-1, where ny/2+2 <= kk <= ny, and
c imaginary part of f(1,1,1) = real part of mode nx/2,0 and
c imaginary part of f(1,1,(ny/2)/kyp+1) = real part of mode nx/2,ny/2
c if ntpose = 1,
c g(k,j,i) = mode jj-1,k-1, where jj = j + kxp*(i - 1)
c 1 <= jj <= nx/2 and 1 <= k <= ny, except for
c g(k,1,1) = mode nx/2,k-1, where ny/2+2 <= k <= ny, and
c imaginary part of g(1,1,1) = real part of mode nx/2,0 and
c imaginary part of g(ny/2+1,1,1) = real part of mode nx/2,ny/2
c written by viktor k. decyk, ucla
c parallel version
implicit none
integer isign, ntpose, indx, indy, kstrt, nxvh, nyv, kxp, kyp
integer kypd, jblok, kblok, nxhyd, nxyhd, mixup
complex f, g, bs, br, sct
dimension f(nxvh,kypd,kblok), g(nyv,kxp,jblok)
dimension bs(kxp,kyp,kblok), br(kxp,kyp,jblok)
dimension mixup(nxhyd), sct(nxyhd)
c local data
integer indx1, indx1y, nx, nxh, nxhh, nxh2, ny, nyh, ny2, nxy
integer nxhy, ks, j, k, lb, ll, jb, it, nxyh, nrx, nry, l, i, m
integer ns, ns2, km, kmr, k1, k2, j1, j2
real dnxy, arg, ani
complex s, t, t1
indx1 = indx - 1
indx1y = max0(indx1,indy)
nx = 2**indx
nxh = nx/2
nxhh = nx/4
nxh2 = nxh + 2
ny = 2**indy
nyh = ny/2
ny2 = ny + 2
nxy = max0(nx,ny)
nxhy = 2**indx1y
ks = kstrt - 2
if (isign) 50, 10, 300
c prepare fft tables
c bit-reverse index table: mixup(j) = 1 + reversed bits of (j - 1)
10 do 30 j = 1, nxhy
lb = j - 1
ll = 0
do 20 k = 1, indx1y
jb = lb/2
it = lb - 2*jb
lb = jb
ll = 2*ll + it
20 continue
mixup(j) = ll + 1
30 continue
c sine/cosine table for the angles 2*n*pi/nxy
nxyh = nxy/2
dnxy = 6.28318530717959/float(nxy)
do 40 j = 1, nxyh
arg = dnxy*float(j - 1)
sct(j) = cmplx(cos(arg),-sin(arg))
40 continue
return
c inverse fourier transform
50 if (kstrt.gt.ny) go to 180
nrx = nxhy/nxh
do 80 l = 1, kblok
c bit-reverse array elements in x
do 70 j = 1, nxh
j1 = (mixup(j) - 1)/nrx + 1
if (j.ge.j1) go to 70
do 60 k = 1, kyp
t = f(j1,k,l)
f(j1,k,l) = f(j,k,l)
f(j,k,l) = t
60 continue
70 continue
80 continue
c first transform in x
nrx = nxy/nxh
do 130 m = 1, indx1
ns = 2**(m - 1)
ns2 = ns + ns
km = nxhh/ns
kmr = km*nrx
do 120 l = 1, kblok
do 110 k = 1, km
k1 = ns2*(k - 1)
k2 = k1 + ns
do 100 j = 1, ns
j1 = j + k1
j2 = j + k2
s = sct(1+kmr*(j-1))
do 90 i = 1, kyp
t = s*f(j2,i,l)
f(j2,i,l) = f(j1,i,l) - t
f(j1,i,l) = f(j1,i,l) + t
90 continue
100 continue
110 continue
120 continue
130 continue
c unscramble coefficients and normalize
kmr = nxy/nx
ani = 0.5/(float(nx)*float(ny))
do 170 l = 1, kblok
do 150 j = 2, nxhh
t1 = cmplx(aimag(sct(1+kmr*(j-1))),-real(sct(1+kmr*(j-1))))
do 140 k = 1, kyp
t = conjg(f(nxh2-j,k,l))
s = f(j,k,l) + t
t = (f(j,k,l) - t)*t1
f(j,k,l) = ani*(s + t)
f(nxh2-j,k,l) = ani*conjg(s - t)
140 continue
150 continue
do 160 k = 1, kyp
f(nxhh+1,k,l) = 2.*ani*conjg(f(nxhh+1,k,l))
f(1,k,l) = 2.*ani*cmplx(real(f(1,k,l)) + aimag(f(1,k,l)),real(f(1,
1k,l)) - aimag(f(1,k,l)))
160 continue
170 continue
c transpose f array to g
180 call PTPOSE(f,g,bs,br,nxh,ny,kstrt,nxvh,nyv,kxp,kyp,kxp,kypd,jblok
1,kblok)
if (kstrt.gt.nxh) go to 290
nry = nxhy/ny
do 210 l = 1, jblok
c bit-reverse array elements in y
do 200 k = 1, ny
k1 = (mixup(k) - 1)/nry + 1
if (k.ge.k1) go to 200
do 190 j = 1, kxp
t = g(k1,j,l)
g(k1,j,l) = g(k,j,l)
g(k,j,l) = t
190 continue
200 continue
210 continue
c then transform in y
nry = nxy/ny
do 260 m = 1, indy
ns = 2**(m - 1)
ns2 = ns + ns
km = nyh/ns
kmr = km*nry
do 250 l = 1, jblok
do 240 k = 1, km
k1 = ns2*(k - 1)
k2 = k1 + ns
do 230 j = 1, ns
j1 = j + k1
j2 = j + k2
s = sct(1+kmr*(j-1))
do 220 i = 1, kxp
t = s*g(j2,i,l)
g(j2,i,l) = g(j1,i,l) - t
g(j1,i,l) = g(j1,i,l) + t
220 continue
230 continue
240 continue
250 continue
260 continue
c unscramble modes kx = 0, nx/2
do 280 l = 1, jblok
if ((l+ks).gt.0) go to 280
do 270 k = 2, nyh
s = g(ny2-k,1,l)
g(ny2-k,1,l) = .5*cmplx(aimag(g(k,1,l) + s),real(g(k,1,l) - s))
g(k,1,l) = .5*cmplx(real(g(k,1,l) + s),aimag(g(k,1,l) - s))
270 continue
280 continue
c transpose g array to f
290 if (ntpose.eq.0) call PTPOSE(g,f,br,bs,ny,nxh,kstrt,nyv,nxvh,kyp,k
1xp,kypd,kxp,kblok,jblok)
return
c forward fourier transform
c transpose f array to g
300 if (ntpose.eq.0) call PTPOSE(f,g,bs,br,nxh,ny,kstrt,nxvh,nyv,kxp,k
1yp,kxp,kypd,jblok,kblok)
if (kstrt.gt.nxh) go to 410
nry = nxhy/ny
do 350 l = 1, jblok
c scramble modes kx = 0, nx/2
if ((l+ks).gt.0) go to 320
do 310 k = 2, nyh
s = cmplx(aimag(g(ny2-k,1,l)),real(g(ny2-k,1,l)))
g(ny2-k,1,l) = conjg(g(k,1,l) - s)
g(k,1,l) = g(k,1,l) + s
310 continue
c bit-reverse array elements in y
320 do 340 k = 1, ny
k1 = (mixup(k) - 1)/nry + 1
if (k.ge.k1) go to 340
do 330 j = 1, kxp
t = g(k1,j,l)
g(k1,j,l) = g(k,j,l)
g(k,j,l) = t
330 continue
340 continue
350 continue
c first transform in y
nry = nxy/ny
do 400 m = 1, indy
ns = 2**(m - 1)
ns2 = ns + ns
km = nyh/ns
kmr = km*nry
do 390 l = 1, jblok
do 380 k = 1, km
k1 = ns2*(k - 1)
k2 = k1 + ns
do 370 j = 1, ns
j1 = j + k1
j2 = j + k2
s = conjg(sct(1+kmr*(j-1)))
do 360 i = 1, kxp
t = s*g(j2,i,l)
g(j2,i,l) = g(j1,i,l) - t
g(j1,i,l) = g(j1,i,l) + t
360 continue
370 continue
380 continue
390 continue
400 continue
c transpose g array to f
410 call PTPOSE(g,f,br,bs,ny,nxh,kstrt,nyv,nxvh,kyp,kxp,kypd,kxp,kblok
1,jblok)
if (kstrt.gt.ny) return
nrx = nxhy/nxh
kmr = nxy/nx
do 470 l = 1, kblok
c scramble coefficients
do 430 j = 2, nxhh
t1 = cmplx(aimag(sct(1+kmr*(j-1))),real(sct(1+kmr*(j-1))))
do 420 k = 1, kyp
t = conjg(f(nxh2-j,k,l))
s = f(j,k,l) + t
t = (f(j,k,l) - t)*t1
f(j,k,l) = s + t
f(nxh2-j,k,l) = conjg(s - t)
420 continue
430 continue
do 440 k = 1, kyp
f(nxhh+1,k,l) = 2.*conjg(f(nxhh+1,k,l))
f(1,k,l) = cmplx(real(f(1,k,l)) + aimag(f(1,k,l)),real(f(1,k,l)) -
1 aimag(f(1,k,l)))
440 continue
c bit-reverse array elements in x
do 460 j = 1, nxh
j1 = (mixup(j) - 1)/nrx + 1
if (j.ge.j1) go to 460
do 450 k = 1, kyp
t = f(j1,k,l)
f(j1,k,l) = f(j,k,l)
f(j,k,l) = t
450 continue
460 continue
470 continue
c then transform in x
nrx = nxy/nxh
do 520 m = 1, indx1
ns = 2**(m - 1)
ns2 = ns + ns
km = nxhh/ns
kmr = km*nrx
do 510 l = 1, kblok
do 500 k = 1, km
k1 = ns2*(k - 1)
k2 = k1 + ns
do 490 j = 1, ns
j1 = j + k1
j2 = j + k2
s = conjg(sct(1+kmr*(j-1)))
do 480 i = 1, kyp
t = s*f(j2,i,l)
f(j2,i,l) = f(j1,i,l) - t
f(j1,i,l) = f(j1,i,l) + t
480 continue
490 continue
500 continue
510 continue
520 continue
return
end
c-----------------------------------------------------------------------
subroutine PFFT2R2(f,g,bs,br,isign,ntpose,mixup,sct,indx,indy,kstr
1t,nxvh,nyv,kxp,kyp,kypd,jblok,kblok,nxhyd,nxyhd)
c this subroutine performs 2 two dimensional complex to real fast
c fourier transforms, using complex arithmetic,
c for data which is distributed in blocks
c for isign = 0, input: isign, indx, indy, kstrt, nxhyd, nxyhd
c output: mixup, sct
c for isign = (-1,1), input: all, output: f, g, bs, br
c for isign = -1, approximate flop count: N*(5*log2(N) + 10)/nvp
c for isign = 1, approximate flop count: N*(5*log2(N) + 8)/nvp
c where N = (nx/2)*ny, and nvp = number of procs
c indx/indy = exponent which determines length in x/y direction,
c where nx=2**indx, ny=2**indy
c ntpose = (0,1) = (no,yes) input, output data are transposed
c if isign = 0, the fft tables are prepared
c if isign = -1, two inverse fourier transforms are performed
c if ntpose = 0, f is the input and output array, g is a scratch array
c f(1:2,n,m,l) = (1/nx*ny)*sum(f(1:2,j,k,i)*
c exp(-sqrt(-1)*2pi*n*j/nx)*exp(-sqrt(-1)*2pi*mm*kk/ny))
c where mm = m + kyp*(l - 1) and kk = k + kyp*(i - 1)
c if ntpose = 1, f is the input and g is the output
c g(1:2,m,n,l) = (1/nx*ny)*sum(f(1:2,j,k,i)*
c exp(-sqrt(-1)*2pi*nn*j/nx)*exp(-sqrt(-1)*2pi*m*kk/ny))
c where nn = n + kxp*(l - 1) and kk = k + kyp*(i - 1)
c if isign = 1, two forward fourier transforms are performed
c if ntpose = 0, f is the input and output array, g is a scratch array
c f(1:2,j,k,i) = sum(f(1:2,n,m,l)*exp(sqrt(-1)*2pi*n*j/nx)*
c exp(sqrt(-1)*2pi*mm*kk/ny))
c where mm = m + kyp*(l - 1) and kk = k + kyp*(i - 1)
c if ntpose = 1, g is the input and f is the output
c f(1:2,j,k,i) = sum(g(1:2,m,n,l)*exp(sqrt(-1)*2pi*nn*j/nx)*
c exp(sqrt(-1)*2pi*m*kk/ny))
c where nn = n + kxp*(l - 1) and kk = k + kyp*(i - 1)
c bs, br = scratch arrays
c kstrt = starting data block number
c nxvh/nyv = second dimension of f/g
c kypd = third dimension of f
c kxp/kyp = number of data values per block in x/y
c jblok/kblok = number of data blocks in x/y
c mixup = array of bit reversed addresses
c sct = sine/cosine table
c nxhyd = maximum of (nx/2,ny)
c nxyhd = one half of maximum of (nx,ny)
c the real data is stored in a complex array of length nx/2, ny
c with the odd/even x points stored in the real/imaginary parts.
c in complex notation, fourier coefficients are stored as follows:
c if ntpose = 0,
c f(j,k,i) = mode j-1,kk-1, where kk = k + kyp*(i - 1)
c 1 <= j <= nx/2 and 1 <= kk <= ny, except for
c f(1,k,i) = mode nx/2,kk-1, where ny/2+2 <= kk <= ny, and
c imaginary part of f(1,1,1) = real part of mode nx/2,0 and
c imaginary part of f(1,1,(ny/2)/kyp+1) = real part of mode nx/2,ny/2
c if ntpose = 1,
c g(k,j,i) = mode jj-1,k-1, where jj = j + kxp*(i - 1)
c 1 <= jj <= nx/2 and 1 <= k <= ny, except for
c g(k,1,1) = mode nx/2,k-1, where ny/2+2 <= k <= ny, and
c imaginary part of g(1,1,1) = real part of mode nx/2,0 and
c imaginary part of g(ny/2+1,1,1) = real part of mode nx/2,ny/2
c written by viktor k. decyk, ucla
c parallel version
implicit none
integer isign, ntpose, indx, indy, kstrt, nxvh, nyv, kxp, kyp
integer kypd, jblok, kblok, nxhyd, nxyhd, mixup
complex f, g, bs, br, sct
dimension f(2,nxvh,kypd,kblok), g(2,nyv,kxp,jblok)
dimension bs(2,kxp,kyp,kblok), br(2,kxp,kyp,jblok)
dimension mixup(nxhyd), sct(nxyhd)
c local data
integer indx1, indx1y, nx, nxh, nxhh, nxh2, ny, nyh, ny2, nxy
integer nxhy, ks, j, k, lb, ll, jb, it, nxyh, nrx, nry, l, i, m
integer ns, ns2, km, kmr, k1, k2, j1, j2, jj
real dnxy, arg, ani, at1
complex s, t, t1, t2
indx1 = indx - 1
indx1y = max0(indx1,indy)
nx = 2**indx
nxh = nx/2
nxhh = nx/4
nxh2 = nxh + 2
ny = 2**indy
nyh = ny/2
ny2 = ny + 2
nxy = max0(nx,ny)
nxhy = 2**indx1y
ks = kstrt - 2
if (isign) 50, 10, 360
c prepare fft tables
c bit-reverse index table: mixup(j) = 1 + reversed bits of (j - 1)
10 do 30 j = 1, nxhy
lb = j - 1
ll = 0
do 20 k = 1, indx1y
jb = lb/2
it = lb - 2*jb
lb = jb
ll = 2*ll + it
20 continue
mixup(j) = ll + 1
30 continue
c sine/cosine table for the angles 2*n*pi/nxy
nxyh = nxy/2
dnxy = 6.28318530717959/float(nxy)
do 40 j = 1, nxyh
arg = dnxy*float(j - 1)
sct(j) = cmplx(cos(arg),-sin(arg))
40 continue
return
c inverse fourier transform
50 if (kstrt.gt.ny) go to 230
c swap complex components
do 80 l = 1, kblok
do 70 k = 1, kyp
do 60 j = 1, nxh
at1 = aimag(f(1,j,k,l))
f(1,j,k,l) = cmplx(real(f(1,j,k,l)),real(f(2,j,k,l)))
f(2,j,k,l) = cmplx(at1,aimag(f(2,j,k,l)))
60 continue
70 continue
80 continue
nrx = nxhy/nxh
do 110 l = 1, kblok
c bit-reverse array elements in x
do 100 j = 1, nxh
j1 = (mixup(j) - 1)/nrx + 1
if (j.ge.j1) go to 100
do 90 k = 1, kyp
t1 = f(1,j1,k,l)
t2 = f(2,j1,k,l)
f(1,j1,k,l) = f(1,j,k,l)
f(2,j1,k,l) = f(2,j,k,l)
f(1,j,k,l) = t1
f(2,j,k,l) = t2
90 continue
100 continue
110 continue
c first transform in x
nrx = nxy/nxh
do 160 m = 1, indx1
ns = 2**(m - 1)
ns2 = ns + ns
km = nxhh/ns
kmr = km*nrx
do 150 l = 1, kblok
do 140 k = 1, km
k1 = ns2*(k - 1)
k2 = k1 + ns
do 130 j = 1, ns
j1 = j + k1
j2 = j + k2
s = sct(1+kmr*(j-1))
do 120 i = 1, kyp
t1 = s*f(1,j2,i,l)
t2 = s*f(2,j2,i,l)
f(1,j2,i,l) = f(1,j1,i,l) - t1
f(2,j2,i,l) = f(2,j1,i,l) - t2
f(1,j1,i,l) = f(1,j1,i,l) + t1
f(2,j1,i,l) = f(2,j1,i,l) + t2
120 continue
130 continue
140 continue
150 continue
160 continue
c unscramble coefficients and normalize
kmr = nxy/nx
ani = 0.5/(float(nx)*float(ny))
do 220 l = 1, kblok
do 190 j = 2, nxhh
t1 = cmplx(aimag(sct(1+kmr*(j-1))),-real(sct(1+kmr*(j-1))))
do 180 k = 1, kyp
do 170 jj = 1, 2
t = conjg(f(jj,nxh2-j,k,l))
s = f(jj,j,k,l) + t
t = (f(jj,j,k,l) - t)*t1
f(jj,j,k,l) = ani*(s + t)
f(jj,nxh2-j,k,l) = ani*conjg(s - t)
170 continue
180 continue
190 continue
do 210 k = 1, kyp
do 200 jj = 1, 2
f(jj,nxhh+1,k,l) = 2.*ani*conjg(f(jj,nxhh+1,k,l))
f(jj,1,k,l) = 2.*ani*cmplx(real(f(jj,1,k,l)) + aimag(f(jj,1,k,l)),
1real(f(jj,1,k,l)) - aimag(f(jj,1,k,l)))
200 continue
210 continue
220 continue
c transpose f array to g
230 call P2TPOSE(f,g,bs,br,nxh,ny,kstrt,nxvh,nyv,kxp,kyp,kxp,kypd,jblo
1k,kblok)
if (kstrt.gt.nxh) go to 350
nry = nxhy/ny
do 260 l = 1, jblok
c bit-reverse array elements in y
do 250 k = 1, ny
k1 = (mixup(k) - 1)/nry + 1
if (k.ge.k1) go to 250
do 240 j = 1, kxp
t1 = g(1,k1,j,l)
t2 = g(2,k1,j,l)
g(1,k1,j,l) = g(1,k,j,l)
g(2,k1,j,l) = g(2,k,j,l)
g(1,k,j,l) = t1
g(2,k,j,l) = t2
240 continue
250 continue
260 continue
c then transform in y
nry = nxy/ny
do 310 m = 1, indy
ns = 2**(m - 1)
ns2 = ns + ns
km = nyh/ns
kmr = km*nry
do 300 l = 1, jblok
do 290 k = 1, km
k1 = ns2*(k - 1)
k2 = k1 + ns
do 280 j = 1, ns
j1 = j + k1
j2 = j + k2
s = sct(1+kmr*(j-1))
do 270 i = 1, kxp
t1 = s*g(1,j2,i,l)
t2 = s*g(2,j2,i,l)
g(1,j2,i,l) = g(1,j1,i,l) - t1
g(2,j2,i,l) = g(2,j1,i,l) - t2
g(1,j1,i,l) = g(1,j1,i,l) + t1
g(2,j1,i,l) = g(2,j1,i,l) + t2
270 continue
280 continue
290 continue
300 continue
310 continue
c unscramble modes kx = 0, nx/2
do 340 l = 1, jblok
if ((l+ks).gt.0) go to 340
do 330 k = 2, nyh
do 320 jj = 1, 2
s = g(jj,ny2-k,1,l)
g(jj,ny2-k,1,l) = .5*cmplx(aimag(g(jj,k,1,l) + s),real(g(jj,k,1,l)
1- s))
g(jj,k,1,l) = .5*cmplx(real(g(jj,k,1,l) + s),aimag(g(jj,k,1,l) - s
1))
320 continue
330 continue
340 continue
c transpose g array to f
350 if (ntpose.eq.0) call P2TPOSE(g,f,br,bs,ny,nxh,kstrt,nyv,nxvh,kyp,
1kxp,kypd,kxp,kblok,jblok)
return
c forward fourier transform
c transpose f array to g
360 if (ntpose.eq.0) call P2TPOSE(f,g,bs,br,nxh,ny,kstrt,nxvh,nyv,kxp,
1kyp,kxp,kypd,jblok,kblok)
if (kstrt.gt.nxh) go to 480
nry = nxhy/ny
do 420 l = 1, jblok
c scramble modes kx = 0, nx/2
if ((l+ks).gt.0) go to 390
do 380 k = 2, nyh
do 370 jj = 1, 2
s = cmplx(aimag(g(jj,ny2-k,1,l)),real(g(jj,ny2-k,1,l)))
g(jj,ny2-k,1,l) = conjg(g(jj,k,1,l) - s)
g(jj,k,1,l) = g(jj,k,1,l) + s
370 continue
380 continue
c bit-reverse array elements in y
390 do 410 k = 1, ny
k1 = (mixup(k) - 1)/nry + 1
if (k.ge.k1) go to 410
do 400 j = 1, kxp
t1 = g(1,k1,j,l)
t2 = g(2,k1,j,l)
g(1,k1,j,l) = g(1,k,j,l)
g(2,k1,j,l) = g(2,k,j,l)
g(1,k,j,l) = t1
g(2,k,j,l) = t2
400 continue
410 continue
420 continue
c first transform in y
nry = nxy/ny
do 470 m = 1, indy
ns = 2**(m - 1)
ns2 = ns + ns
km = nyh/ns
kmr = km*nry
do 460 l = 1, jblok
do 450 k = 1, km
k1 = ns2*(k - 1)
k2 = k1 + ns
do 440 j = 1, ns
j1 = j + k1
j2 = j + k2
s = conjg(sct(1+kmr*(j-1)))
do 430 i = 1, kxp
t1 = s*g(1,j2,i,l)
t2 = s*g(2,j2,i,l)
g(1,j2,i,l) = g(1,j1,i,l) - t1
g(2,j2,i,l) = g(2,j1,i,l) - t2
g(1,j1,i,l) = g(1,j1,i,l) + t1
g(2,j1,i,l) = g(2,j1,i,l) + t2
430 continue
440 continue
450 continue
460 continue
470 continue
c transpose g array to f
480 call P2TPOSE(g,f,br,bs,ny,nxh,kstrt,nyv,nxvh,kyp,kxp,kypd,kxp,kblo
1k,jblok)
if (kstrt.gt.ny) return
nrx = nxhy/nxh
kmr = nxy/nx
do 560 l = 1, kblok
c scramble coefficients
do 510 j = 2, nxhh
t1 = cmplx(aimag(sct(1+kmr*(j-1))),real(sct(1+kmr*(j-1))))
do 500 k = 1, kyp
do 490 jj = 1, 2
t = conjg(f(jj,nxh2-j,k,l))
s = f(jj,j,k,l) + t
t = (f(jj,j,k,l) - t)*t1
f(jj,j,k,l) = s + t
f(jj,nxh2-j,k,l) = conjg(s - t)
490 continue
500 continue
510 continue
do 530 k = 1, kyp
do 520 jj = 1, 2
f(jj,nxhh+1,k,l) = 2.*conjg(f(jj,nxhh+1,k,l))
f(jj,1,k,l) = cmplx(real(f(jj,1,k,l)) + aimag(f(jj,1,k,l)),real(f(
1jj,1,k,l)) - aimag(f(jj,1,k,l)))
520 continue
530 continue
c bit-reverse array elements in x
do 550 j = 1, nxh
j1 = (mixup(j) - 1)/nrx + 1
if (j.ge.j1) go to 550
do 540 k = 1, kyp
t1 = f(1,j1,k,l)
t2 = f(2,j1,k,l)
f(1,j1,k,l) = f(1,j,k,l)
f(2,j1,k,l) = f(2,j,k,l)
f(1,j,k,l) = t1
f(2,j,k,l) = t2
540 continue
550 continue
560 continue
c then transform in x
nrx = nxy/nxh
do 610 m = 1, indx1
ns = 2**(m - 1)
ns2 = ns + ns
km = nxhh/ns
kmr = km*nrx
do 600 l = 1, kblok
do 590 k = 1, km
k1 = ns2*(k - 1)
k2 = k1 + ns
do 580 j = 1, ns
j1 = j + k1
j2 = j + k2
s = conjg(sct(1+kmr*(j-1)))
do 570 i = 1, kyp
t1 = s*f(1,j2,i,l)
t2 = s*f(2,j2,i,l)
f(1,j2,i,l) = f(1,j1,i,l) - t1
f(2,j2,i,l) = f(2,j1,i,l) - t2
f(1,j1,i,l) = f(1,j1,i,l) + t1
f(2,j1,i,l) = f(2,j1,i,l) + t2
570 continue
580 continue
590 continue
600 continue
610 continue
c swap complex components
do 640 l = 1, kblok
do 630 k = 1, kyp
do 620 j = 1, nxh
at1 = aimag(f(1,j,k,l))
f(1,j,k,l) = cmplx(real(f(1,j,k,l)),real(f(2,j,k,l)))
f(2,j,k,l) = cmplx(at1,aimag(f(2,j,k,l)))
620 continue
630 continue
640 continue
return
end
c-----------------------------------------------------------------------
subroutine PFFT2R3(f,g,bs,br,isign,ntpose,mixup,sct,indx,indy,kstr
1t,nxvh,nyv,kxp,kyp,kypd,jblok,kblok,nxhyd,nxyhd)
c this subroutine performs 3 two dimensional complex to real fast
c fourier transforms, using complex arithmetic,
c for data which is distributed in blocks
c for isign = 0, input: isign, indx, indy, kstrt, nxhyd, nxyhd
c output: mixup, sct
c for isign = (-1,1), input: all, output: f, g, bs, br
c for isign = -1, approximate flop count: N*(5*log2(N) + 10)/nvp
c for isign = 1, approximate flop count: N*(5*log2(N) + 8)/nvp
c where N = (nx/2)*ny, and nvp = number of procs
c indx/indy = exponent which determines length in x/y direction,
c where nx=2**indx, ny=2**indy
c ntpose = (0,1) = (no,yes) input, output data are transposed
c if isign = 0, the fft tables are prepared
c if isign = -1, three inverse fourier transforms are performed
c if ntpose = 0, f is the input and output array, g is a scratch array
c f(1:3,n,m,l) = (1/nx*ny)*sum(f(1:3,j,k,i)*
c exp(-sqrt(-1)*2pi*n*j/nx)*exp(-sqrt(-1)*2pi*mm*kk/ny))
c where mm = m + kyp*(l - 1) and kk = k + kyp*(i - 1)
c if ntpose = 1, f is the input and g is the output
c g(1:3,m,n,l) = (1/nx*ny)*sum(f(1:3,j,k,i)*
c exp(-sqrt(-1)*2pi*nn*j/nx)*exp(-sqrt(-1)*2pi*m*kk/ny))
c where nn = n + kxp*(l - 1) and kk = k + kyp*(i - 1)
c if isign = 1, three forward fourier transforms are performed
c if ntpose = 0, f is the input and output array, g is a scratch array
c f(1:3,j,k,i) = sum(f(1:3,n,m,l)*exp(sqrt(-1)*2pi*n*j/nx)*
c exp(sqrt(-1)*2pi*mm*kk/ny))
c where mm = m + kyp*(l - 1) and kk = k + kyp*(i - 1)
c if ntpose = 1, g is the input and f is the output
c f(1:3,j,k,i) = sum(g(1:3,m,n,l)*exp(sqrt(-1)*2pi*nn*j/nx)*
c exp(sqrt(-1)*2pi*m*kk/ny))
c where nn = n + kxp*(l - 1) and kk = k + kyp*(i - 1)
c bs, br = scratch arrays
c kstrt = starting data block number
c nxvh/nyv = second dimension of f/g
c kypd = third dimension of f
c kxp/kyp = number of data values per block in x/y
c jblok/kblok = number of data blocks in x/y
c mixup = array of bit reversed addresses
c sct = sine/cosine table
c nxhyd = maximum of (nx/2,ny)
c nxyhd = one half of maximum of (nx,ny)
c the real data is stored in a complex array of length nx/2, ny
c with the odd/even x points stored in the real/imaginary parts.
c in complex notation, fourier coefficients are stored as follows:
c if ntpose = 0,
c f(j,k,i) = mode j-1,kk-1, where kk = k + kyp*(i - 1)
c 1 <= j <= nx/2 and 1 <= kk <= ny, except for
c f(1,k,i) = mode nx/2,kk-1, where ny/2+2 <= kk <= ny, and
c imaginary part of f(1,1,1) = real part of mode nx/2,0 and
c imaginary part of f(1,1,(ny/2)/kyp+1) = real part of mode nx/2,ny/2
c if ntpose = 1,
c g(k,j,i) = mode jj-1,k-1, where jj = j + kxp*(i - 1)
c 1 <= jj <= nx/2 and 1 <= k <= ny, except for
c g(k,1,1) = mode nx/2,k-1, where ny/2+2 <= k <= ny, and
c imaginary part of g(1,1,1) = real part of mode nx/2,0 and
c imaginary part of g(ny/2+1,1,1) = real part of mode nx/2,ny/2
c written by viktor k. decyk, ucla
c parallel version
implicit none
integer isign, ntpose, indx, indy, kstrt, nxvh, nyv, kxp, kyp
integer kypd, jblok, kblok, nxhyd, nxyhd, mixup
complex f, g, bs, br, sct
dimension f(3,nxvh,kypd,kblok), g(3,nyv,kxp,jblok)
dimension bs(3,kxp,kyp,kblok), br(3,kxp,kyp,jblok)
dimension mixup(nxhyd), sct(nxyhd)
c local data
integer indx1, indx1y, nx, nxh, nxhh, nxh2, ny, nyh, ny2, nxy
integer nxhy, ks, j, k, lb, ll, jb, it, nxyh, nrx, nry, l, i, m
integer ns, ns2, km, kmr, k1, k2, j1, j2, jj
real dnxy, arg, ani, at1, at2
complex s, t, t1, t2, t3
indx1 = indx - 1
indx1y = max0(indx1,indy)
nx = 2**indx
nxh = nx/2
nxhh = nx/4
nxh2 = nxh + 2
ny = 2**indy
nyh = ny/2
ny2 = ny + 2
nxy = max0(nx,ny)
nxhy = 2**indx1y
ks = kstrt - 2
if (isign) 50, 10, 360
c prepare fft tables
c bit-reverse index table: mixup(j) = 1 + reversed bits of (j - 1)
10 do 30 j = 1, nxhy
lb = j - 1
ll = 0
do 20 k = 1, indx1y
jb = lb/2
it = lb - 2*jb
lb = jb
ll = 2*ll + it
20 continue
mixup(j) = ll + 1
30 continue
c sine/cosine table for the angles 2*n*pi/nxy
nxyh = nxy/2
dnxy = 6.28318530717959/float(nxy)
do 40 j = 1, nxyh
arg = dnxy*float(j - 1)
sct(j) = cmplx(cos(arg),-sin(arg))
40 continue
return
c inverse fourier transform
50 if (kstrt.gt.ny) go to 230
c swap complex components
do 80 l = 1, kblok
do 70 i = 1, kyp
do 60 j = 1, nxh
at1 = real(f(3,j,i,l))
f(3,j,i,l) = cmplx(real(f(2,j,i,l)),aimag(f(3,j,i,l)))
at2 = aimag(f(2,j,i,l))
f(2,j,i,l) = cmplx(aimag(f(1,j,i,l)),at1)
f(1,j,i,l) = cmplx(real(f(1,j,i,l)),at2)
60 continue
70 continue
80 continue
nrx = nxhy/nxh
do 110 l = 1, kblok
c bit-reverse array elements in x
do 100 j = 1, nxh
j1 = (mixup(j) - 1)/nrx + 1
if (j.ge.j1) go to 100
do 90 k = 1, kyp
t1 = f(1,j1,k,l)
t2 = f(2,j1,k,l)
t3 = f(3,j1,k,l)
f(1,j1,k,l) = f(1,j,k,l)
f(2,j1,k,l) = f(2,j,k,l)
f(3,j1,k,l) = f(3,j,k,l)
f(1,j,k,l) = t1
f(2,j,k,l) = t2
f(3,j,k,l) = t3
90 continue
100 continue
110 continue
c first transform in x
nrx = nxy/nxh
do 160 m = 1, indx1
ns = 2**(m - 1)
ns2 = ns + ns
km = nxhh/ns
kmr = km*nrx
do 150 l = 1, kblok
do 140 k = 1, km
k1 = ns2*(k - 1)
k2 = k1 + ns
do 130 j = 1, ns
j1 = j + k1
j2 = j + k2
s = sct(1+kmr*(j-1))
do 120 i = 1, kyp
t1 = s*f(1,j2,i,l)
t2 = s*f(2,j2,i,l)
t3 = s*f(3,j2,i,l)
f(1,j2,i,l) = f(1,j1,i,l) - t1
f(2,j2,i,l) = f(2,j1,i,l) - t2
f(3,j2,i,l) = f(3,j1,i,l) - t3
f(1,j1,i,l) = f(1,j1,i,l) + t1
f(2,j1,i,l) = f(2,j1,i,l) + t2
f(3,j1,i,l) = f(3,j1,i,l) + t3
120 continue
130 continue
140 continue
150 continue
160 continue
c unscramble coefficients and normalize
kmr = nxy/nx
ani = 0.5/(float(nx)*float(ny))
do 220 l = 1, kblok
do 190 j = 2, nxhh
t1 = cmplx(aimag(sct(1+kmr*(j-1))),-real(sct(1+kmr*(j-1))))