8 SUBROUTINE readin(input_file, ier_flag)
19 INTEGER,
INTENT(inout) :: ier_flag
20 CHARACTER(LEN=*) :: input_file
22 INTEGER :: n, iunit, ier_flag_init, i, ni, m, nsmin, mj, isgn, ioff, joff
23 REAL(rprec),
DIMENSION(:,:),
POINTER :: rbcc, rbss, rbcs, rbsc, zbcs, zbsc, zbcc, zbss
24 REAL(rprec) :: rtest, ztest, tzc, trc, delta
25 REAL(rprec),
ALLOCATABLE :: temp(:)
26 CHARACTER(LEN=100) :: line, line2
28 ier_flag_init = ier_flag
42 CALL read_mgrid (mgrid_file, extcur, nzeta, nfp, .true., ier_flag)
5320
FORMAT(//,
' VACUUM FIELD PARAMETERS:',/,1x,24(
'-'),/, &
54 ' nr-grid nz-grid np-grid rmin rmax zmin', &
55 ' zmax input-file',/,3i9,4f10.3,5x,a)
65 IF (nsmin .le. nsd)
THEN
71 print *,
' NS_ARRAY ELEMENTS CANNOT EXCEED ',nsd
78 IF (all(ns_array.eq.0))
THEN
79 stop
'NS ARRAY MUST NOT BE ALL ZEROES'
99 nfp,gamma,spres_ped,phiedge,curtor
100100
FORMAT(/,
' COMPUTATION PARAMETERS: (u = theta, v = zeta)'/, &
102 ' ns nu nv mu mv',/,5i7//, &
103 ' CONFIGURATION PARAMETERS:',/,1x,39(
'-'),/, &
104 ' nfp gamma spres_ped phiedge(wb) curtor(A)',/, &
105 i7,1p,e11.3,2e15.3,e14.3/)
107 IF (nvacskip.le.0)
then
113 WRITE (nthreed,110) ncurr,niter_array(
multi_ns_grid),ns_array(1), &
115 mfilter_fbdy,nfilter_fbdy
116110
FORMAT(
' RUN CONTROL PARAMETERS:',/,1x,23(
'-'),/, &
117 ' ncurr niter nsin nstep nvacskip ftol tcon0',&
119 4i7,i10,1p,2e10.2,2l9,/, &
120 ' mfilter_fbdy nfilter_fbdy',/, &
124 WRITE(nthreed,
"(' EXTERNAL CURRENTS',/,1x,17('-'))")
128 WRITE (line,
'(a,i2.2,a)')
"(5a",ni,
")"
129 WRITE (line2,
'(a,i2.2,a)')
"(5(",ni-12,
"x,1p,e12.4))"
133 WRITE (nthreed, line, iostat=mj) (trim(
curlabel(n)),n=i,ni)
135 WRITE (nthreed, line2,iostat=mj) (extcur(n), n=i,ni)
140 IF (bloat .ne. one)
THEN
141 WRITE (nthreed,
'(" Profile Bloat Factor: ",1pe11.4)') bloat
142 phiedge = phiedge*bloat
145 IF (pres_scale .ne. one)
THEN
146 WRITE (nthreed,
'(" Pressure profile factor: ",1pe11.4,'// &
147 '" (multiplier for pressure)")') pres_scale
152 WRITE(nthreed,131) trim(pmass_type)
154130
FORMAT(
' MASS PROFILE COEFFICIENTS am - newton/m**2 (EXPANSION IN NORMALIZED RADIUS):')
155131
FORMAT(
' PMASS parameterization type is ''', a,
'''')
156132
FORMAT(1x,35(
'-'))
157 WRITE(nthreed,135)(am(i-1),i=1,
SIZE(am))
159 SELECT CASE(trim(pmass_type))
160 CASE (
'Akima_spline',
'cubic_spline')
161 WRITE(nthreed,
"(' am_aux_s is' )")
162 WRITE(nthreed,135)(am_aux_s(i),i=1,
SIZE(am_aux_s))
163 WRITE(nthreed,
"(' am_aux_f is' )")
164 WRITE(nthreed,135)(am_aux_f(i),i=1,
SIZE(am_aux_f))
169 WRITE(nthreed,143) trim(piota_type)
172 WRITE(nthreed,135)(ai(i-1),i=1,
SIZE(ai))
173 SELECT CASE(trim(piota_type))
174 CASE (
'Akima_spline',
'cubic_spline')
175 WRITE(nthreed,
"(' ai_aux_s is' )")
176 WRITE(nthreed,135)(ai_aux_s(i),i=1,
SIZE(ai_aux_s))
177 WRITE(nthreed,
"(' ai_aux_f is' )")
178 WRITE(nthreed,135)(ai_aux_f(i),i=1,
SIZE(ai_aux_f))
183 WRITE(nthreed,146) trim(pcurr_type)
185 WRITE(nthreed,135)(ac(i-1),i=1,
SIZE(ac))
186 SELECT CASE(trim(pcurr_type))
187 CASE (
'Akima_spline_Ip',
'Akima_spline_I', &
188 'cubic_spline_Ip',
'cubic_spline_I')
189 WRITE(nthreed,
"(' ac_aux_s is' )")
190 WRITE(nthreed,135)(ac_aux_s(i),i=1,
SIZE(ac_aux_s))
191 WRITE(nthreed,
"(' ac_aux_f is' )")
192 WRITE(nthreed,135)(ac_aux_f(i),i=1,
SIZE(ac_aux_f))
196140
FORMAT(/
' IOTA PROFILE COEFFICIENTS ai (EXPANSION IN NORMALIZED RADIUS):')
197143
FORMAT(
' PIOTA parameterization type is ''', a,
'''')
198145
FORMAT(/
' TOROIDAL CURRENT DENSITY (*V'') COEFFICIENTS ac (EXPANSION IN NORMALIZED RADIUS):')
199146
FORMAT(
' PCURR parameterization type is ''', a,
'''')
200147
FORMAT(1x,38(
'-'))
203 WRITE(nthreed,135)(aphi(i),i=1,
SIZE(aphi))
204150
FORMAT(/
' NORMALIZED TOROIDAL FLUX COEFFICIENTS aphi (EXPANSION IN S):',/,1x,35(
'-'))
208180
FORMAT(/,
' R-Z FOURIER BOUNDARY COEFFICIENTS AND', &
209 ' MAGNETIC AXIS INITIAL GUESS',/, &
210 ' R = RBC*COS(m*u - n*v) + RBS*SIN(m*u - n*v),', &
211 ' Z = ZBC*COS(m*u - n*v) + ZBS*SIN(m*u-n*v)'/1x,86(
'-'), &
212 /,
' nb mb rbc rbs zbc zbs ',&
213 ' raxis(c) raxis(s) zaxis(c) zaxis(s)')
218 delta = atan2(rbs(0,1) - zbc(0,1), rbc(0,1) + zbs(0,1))
219 IF (delta .ne. zero)
THEN
223 trc = rbc(n,m)*cos(m*delta) + rbs(n,m)*sin(m*delta)
224 rbs(n,m) = rbs(n,m)*cos(m*delta) - rbc(n,m)*sin(m*delta)
227 tzc = zbc(n,m)*cos(m*delta) + zbs(n,m)*sin(m*delta)
228 zbs(n,m) = zbs(n,m)*cos(m*delta) - zbc(n,m)*sin(m*delta)
268 ioff = lbound(rbcc,1)
269 joff = lbound(rbcc,2)
278 IF (lfreeb .and. (mfilter_fbdy.gt.1 .and. m.gt.mfilter_fbdy)) cycle
283 IF (lfreeb .and. (nfilter_fbdy.gt.0 .and. abs(n).gt.nfilter_fbdy)) cycle
294 ELSE IF (n .gt. 0)
THEN
300 rbcc(ni,mj) = rbcc(ni,mj) + rbc(n,m)
301 IF (m .gt. 0) zbsc(ni,mj) = zbsc(ni,mj) + zbs(n,m)
305 rbss(ni,mj) = rbss(ni,mj) + isgn*rbc(n,m)
307 zbcs(ni,mj) = zbcs(ni,mj) - isgn*zbs(n,m)
311 IF (m .gt. 0) rbsc(ni,mj) = rbsc(ni,mj) + rbs(n,m)
312 zbcc(ni,mj) = zbcc(ni,mj) + zbc(n,m)
315 rbcs(ni,mj) = rbcs(ni,mj) - isgn*rbs(n,m)
316 IF (m .gt. 0) zbss(ni,mj) = zbss(ni,mj) + isgn*zbc(n,m)
329 print *,
"skip printing of initial guess for geometry, since ier_flag_init = ",ier_flag_init
335 trc = abs(rbc(n,m)) + abs(rbs(n,m)) + abs(zbc(n,m)) + abs(zbs(n,m))
344 IF (trc.eq.zero .and. abs(raxis_cc(n)).eq.zero .and. abs(zaxis_cs(n)).eq.zero)
then
349 WRITE (nthreed,195) n, m, rbc(n,m), rbs(n,m), zbc(n,m), zbs(n,m), &
350 raxis_cc(n), raxis_cs(n), zaxis_cc(n), zaxis_cs(n)
354 IF (trc .eq. zero)
then
358 WRITE (nthreed,195) n, m, rbc(n,m), rbs(n,m), zbc(n,m), zbs(n,m)
363195
FORMAT(i5,i4,1p,8e12.4)
368 rtest = sum(rbcc(1:ntor1,mj))
369 ztest = sum(zbsc(1:ntor1,mj))
370 lflip=(rtest*ztest .lt. zero)
377 rtest = sum(rbcc(1:ntor1,mj))
378 ztest = sum(zbsc(1:ntor1,mj))
379 if (rtest*ztest .lt. zero)
then
380 stop
"flip_theta did not fix it!"
392 ALLOCATE (temp(
SIZE(rbcc,1)))
396 rbss(:,mj) = cp5*(temp(:) + zbcs(:,mj))
397 zbcs(:,mj) = cp5*(temp(:) - zbcs(:,mj))
402 rbsc(:,mj) = cp5*(temp(:) + zbcc(:,mj))
403 zbcc(:,mj) = cp5*(temp(:) - zbcc(:,mj))
410 if (.not. lasym)
then
412 call add_real_2d(
"rbcc", ntor1, mpol, rbcc)
413 call add_real_2d(
"zbsc", ntor1, mpol, zbsc)
414 call add_null(
"rbss")
415 call add_null(
"zbcs")
416 call add_null(
"rbsc")
417 call add_null(
"zbcc")
418 call add_null(
"rbcs")
419 call add_null(
"zbss")
421 call add_real_2d(
"rbcc", ntor1, mpol, rbcc)
422 call add_real_2d(
"zbsc", ntor1, mpol, zbsc)
423 call add_real_2d(
"rbss", ntor1, mpol, rbss)
424 call add_real_2d(
"zbcs", ntor1, mpol, zbcs)
425 call add_null(
"rbsc")
426 call add_null(
"zbcc")
427 call add_null(
"rbcs")
428 call add_null(
"zbss")
432 call add_real_2d(
"rbcc", ntor1, mpol, rbcc)
433 call add_real_2d(
"zbsc", ntor1, mpol, zbsc)
434 call add_null(
"rbss")
435 call add_null(
"zbcs")
436 call add_real_2d(
"rbsc", ntor1, mpol, rbsc)
437 call add_real_2d(
"zbcc", ntor1, mpol, zbcc)
438 call add_null(
"rbcs")
439 call add_null(
"zbss")
441 call add_real_2d(
"rbcc", ntor1, mpol, rbcc)
442 call add_real_2d(
"zbsc", ntor1, mpol, zbsc)
443 call add_real_2d(
"rbss", ntor1, mpol, rbss)
444 call add_real_2d(
"zbcs", ntor1, mpol, zbcs)
445 call add_real_2d(
"rbsc", ntor1, mpol, rbsc)
446 call add_real_2d(
"zbcc", ntor1, mpol, zbcc)
447 call add_real_2d(
"rbcs", ntor1, mpol, rbcs)
448 call add_real_2d(
"zbss", ntor1, mpol, zbss)