V3FIT
init_bg_currents.f
1  SUBROUTINE init_bg_currents (nvariables, xvariables)
2 !-----------------------------------------------
3 ! M o d u l e s
4 !-----------------------------------------------
5  USE bcoils_mod
6  USE safe_open_mod
7  IMPLICIT NONE
8 !-----------------------------------------------
9 ! L o c a l V a r i a b l e s
10 !-----------------------------------------------
11  INTEGER :: i, m, iunit, istat
12  INTEGER, INTENT(out) :: nvariables
13  REAL(rprec) :: xvariables(*)
14 !-----------------------------------------------
15  mbcoils = 0
16  iunit = 77
17  CALL safe_open(iunit, istat, trim(bcoil_file), 'old',
18  1 'formatted')
19  IF (istat .eq. 0) THEN
20  READ (iunit, *) mbcoils
21  CLOSE (iunit)
22  ELSE
23  print *, 'Background file - ', trim(bcoil_file),
24  1 ' - could not be opened'
25  END IF
26 
27 ! Set variable background currents based on index mc_bg
28 
29  mc_max = 0
30  DO i = 1, mbcoils
31  m = mc_bg(i)
32  IF (m .gt. mc_max) THEN
33  cc_bg(m) = bcoil_cur(i)
34  mc_max = m
35  END IF
36  END DO
37 
38 !
39 ! lbcoil_cur == .false. is equivalent to mc_max = 0
40 !
41  IF (mc_max == 0) lbcoil_cur = .false.
42 
43  IF (lbcoil_cur) THEN
44  DO m = 1, mc_max
45  xvariables(m) = cc_bg(m)
46  END DO
47  END IF
48 
49  nvariables = mc_max
50 
51  END SUBROUTINE init_bg_currents