V3FIT
reorganz.f
1  SUBROUTINE reorganz(coefs, mbuse, nbuse, factor, a1,
2  1 ntheta, nzeta)
3 C-----------------------------------------------
4 C M o d u l e s
5 C-----------------------------------------------
6  USE vmec0
7  IMPLICIT NONE
8 C-----------------------------------------------
9 C D u m m y A r g u m e n t s
10 C-----------------------------------------------
11  INTEGER mbuse, nbuse, ntheta, nzeta
12  REAL(rprec) factor
13  REAL(rprec), DIMENSION(ntheta + 2,nzeta) :: a1
14  complex(rprec), DIMENSION(-mbuse:mbuse,0:nbuse) :: coefs
15 C-----------------------------------------------
16 C L o c a l V a r i a b l e s
17 C-----------------------------------------------
18  INTEGER :: j, m, i, n, ia
19 C-----------------------------------------------
20 c--
21 c Version reorganz creates a COMPLEX coefs array.
22 c Subroutine to reorganize and scale the output from fft991 and cft99 into complex
23 c coefficients with INDEX (m,n). The coefficients are scaled by the
24 c factor FACTOR. This factor should be 1/(number of points in the
25 c forward complex transform direction). The original coefficients appear
26 c in array a1. The scaled coefficients will be
27 c copied to array COEFS in the calling list. Here, m is the poloidal
28 c mode number and n is the toroidal mode number/periods. Because we USE two
29 c FORWARD transforms, we must flip the sign of m to get the desired nu
30 c argument (u=theta, v=zeta)
31 c--
32 c
33 c- Because of (anti)symmetry, ONLY nonnegative values of n are needed. We also
34 c only fill to m = mbuse and n = nbuse since this is all that will be
35 c used in the sums over m and n.
36 c therefore, only i = 1 to mbuse+1 (for m = 0 to mbuse) and i = nth+1-mbuse
37 c to nth (for m = -mbuse to -1) and ONLY j = 1 to nbuse+1 (for n = 0 to nbuse)
38 c are needed.
39 c
40  DO j = 1, nbuse + 1
41  n = j - 1
42  DO i = 1, mbuse + 1
43  m = i - 1
44  ia = 2*i - 1
45  coefs(-m,n) = factor*cmplx(a1(ia,j),a1(ia+1,j))
46  END DO
47  END DO
48 
49  DO j = nzeta + 1 - nbuse, nzeta
50  n = -(nzeta + 1) + j
51  DO i = 1, mbuse + 1
52  m = i - 1
53  ia = 2*i - 1
54  coefs(m,-n) = factor*cmplx(a1(ia,j),(-a1(ia+1,j)))
55  END DO
56  END DO
57 
58  coefs(1:mbuse,0) = coefs(-1:-mbuse:-1,0)
59 
60  END SUBROUTINE reorganz