10 CHARACTER(LEN=*),
PARAMETER ::
16 CHARACTER(LEN=*),
PARAMETER ::
86 REAL(
rprec),
DIMENSION(:,:),
ALLOCATABLE,
TARGET ::
bvac
95 CHARACTER(LEN=30),
DIMENSION(:),
ALLOCATABLE ::
curlabel
96 CHARACTER(LEN=15),
DIMENSION(:),
ALLOCATABLE ::
100 REAL(
rprec),
DIMENSION(:,:),
ALLOCATABLE ::
105 PRIVATE :: read_mgrid_bin, read_mgrid_nc
125 INTEGER,
INTENT(out) :: ier_flag
126 INTEGER,
INTENT(in) :: nv, nfp
127 LOGICAL,
INTENT(in) :: lscreen
128 REAL(rprec),
INTENT(in) :: extcur(:)
129 CHARACTER(len=*),
INTENT(in) :: mgrid_file
136 CHARACTER(LEN=*),
PARAMETER :: mgrid_defarea=
'$HOME/vmec/MAKEGRID'
145 CHARACTER(LEN=200) :: home_dir
146 LOGICAL :: lgrid_exist, lfind
153 print *,
' mgrid file previously parsed!'
157 INQUIRE (file=
mgrid_path,exist=lgrid_exist,iostat=istat)
158 IF (istat.ne.0 .or. .not.lgrid_exist)
THEN
159 IF (lscreen) print *,
' MGRID FILE NOT FOUND IN SPECIFIED ',
160 1
'PATH: SEARCHING DEFAULT AREA'
182 IF (lgrid_exist)
THEN
183 IF (lscreen) print
'(2x,2a)',
184 1
'Opening vacuum field file: ', trim(mgrid_file)
192 CALL read_mgrid_nc (
mgrid_path, extcur, nv, nfp,
198 CALL read_mgrid_bin (
mgrid_path, extcur, nv, nfp,
202 IF (
np0b .ne. nv)
THEN
204 1
' NOT EQUAL TO NP0B=',
np0b,
' IN MGRID FILE'
206 ELSE IF (
nfper0.ne.nfp)
THEN
207 print *,
' NFP(READ in) = ',nfp,
' DOES NOT AGREE WITH ',
208 1
'NFPER (in vacuum field file) = ',
nfper0
214 IF (ier_flag .ne. 0)
RETURN
216 IF (.not.lgrid_exist .or. ier_flag.ne.0)
THEN
220 print *,
' Error opening/reading mgrid file in dir: ',
222 print *,
' User must supply vacuum bfield in mgrid to ',
223 1
'run vmec in free-boundary mode!'
224 print *,
' Proceeding to run vmec in',
225 1
' fixed boundary mode'
232 SUBROUTINE read_mgrid_bin (filename, extcur, nv, nfp, ier_flag,
242 INTEGER,
INTENT(in) :: nv, nfp
243 CHARACTER(LEN=*),
INTENT(in) :: filename
244 REAL(rprec),
INTENT(in) :: extcur(:)
248 REAL(rprec),
DIMENSION(:,:,:),
ALLOCATABLE ::
249 1 brtemp, bztemp, bptemp
250 INTEGER :: ier_flag, iunit = 50
251 integer :: istat, ig, i, j, n, n1, m, nsets_max, k
252 LOGICAL :: lscreen, lstyle_2000
255 CALL safe_open(iunit, istat, filename,
'old',
'unformatted')
256 IF (istat .ne. 0)
THEN
262 IF (istat .ne. 0) ier_flag = 9
269 IF (istat .ne. 0) ier_flag = 9
272 print *,
' NEXTCUR = 0 IN READING MGRID FILE'
279 IF (ier_flag .ne. 0)
RETURN
284 IF (istat .ne. 0)
THEN
285 print *,
' reading mgrid file failed (curlabel)'
294 IF (.NOT.
ALLOCATED(
bvac))
THEN
303 IF (istat .ne. 0)
THEN
304 print *,
' allocation for b-vector storage failed'
312 IF (lstyle_2000)
THEN
313 READ(iunit, iostat=istat) brtemp, bptemp, bztemp
315 READ(iunit, iostat=istat) (((brtemp(i,j,k), bztemp(i,j,k),
316 1 bptemp(i,j,k), i= 1,
nr0b),
328 DEALLOCATE (brtemp, bztemp, bptemp)
330 IF (istat .ne. 0)
THEN
335 IF (lstyle_2000)
THEN
337 IF (istat .eq. 0)
THEN
355 IF (lscreen) print *,
' No observation data in mgrid data'
532 1 extcur(ig)*
dbcoil(:n1,n,ig)
537 END SUBROUTINE read_mgrid_bin
540 SUBROUTINE read_mgrid_nc (filename, extcur, nv, nfp,
547 CHARACTER(LEN=*),
INTENT(in) :: filename
548 INTEGER,
INTENT(in) :: nv, nfp
549 REAL(rprec),
INTENT(in) :: extcur(:)
553 REAL(rprec),
DIMENSION(:,:,:),
ALLOCATABLE ::
554 1 brtemp, bztemp, bptemp
555 INTEGER :: ier_flag, ngrid
558 INTEGER,
DIMENSION(3) :: dimlens
559 CHARACTER(LEN=100) :: temp
560 CHARACTER(LEN=100),
ALLOCATABLE,
DIMENSION(:) ::
561 1 vn_br, vn_bp, vn_bz
563 call cdf_open(ngrid, filename,
'r', istat)
564 IF (istat .ne. 0)
THEN
582 print *,
' NEXTCUR = 0 IN READING MGRID FILE'
610 ELSE IF (istat .eq. 0)
THEN
614 IF (istat .ne. 0) stop
'Error allocating CURLABEL in mgrid_mod'
620 IF (istat .ne. 0) stop
'Error allocating vn_bX in mgrid_mod'
623 IF (.NOT.
ALLOCATED(
bvac))
THEN
628 IF (istat .ne. 0) stop
'Error allocating bvac in mgrid_mod'
633 WRITE (temp,
'(a,i3.3)')
"_",ig
634 vn_br(ig) =
vn_br0 // temp
635 vn_bp(ig) =
vn_bp0 // temp
636 vn_bz(ig) =
vn_bz0 // temp
637 CALL cdf_inquire(ngrid, vn_br(ig), dimlens)
638 IF (.NOT.
ALLOCATED(brtemp))
THEN
639 ALLOCATE (brtemp(dimlens(1),dimlens(2),dimlens(3)),
640 1 bptemp(dimlens(1),dimlens(2),dimlens(3)),
641 2 bztemp(dimlens(1),dimlens(2),dimlens(3)),
643 IF (istat .ne. 0)stop
'Error allocating bXtemp in mgrid_mod'
645 CALL cdf_read(ngrid, vn_br(ig), brtemp)
646 CALL cdf_read(ngrid, vn_bp(ig), bptemp)
647 CALL cdf_read(ngrid, vn_bz(ig), bztemp)
667 CALL cdf_inquire(ngrid,
vn_mgmode, dimlens, ier=istat)
668 IF (istat .eq. 0)
THEN
674 CALL cdf_inquire(ngrid,
vn_coilcur, dimlens, ier=istat)
675 IF (istat .eq. 0)
THEN
678 IF (istat .ne. 0) stop
'Error allocating RAW_COIL in mgrid_mod'
682 CALL cdf_close(ngrid)
684 IF (
ALLOCATED(brtemp))
685 1
DEALLOCATE (vn_br, vn_bz, vn_bp, brtemp, bptemp, bztemp)
687 END SUBROUTINE read_mgrid_nc
692 REAL(rprec),
INTENT(inout) :: bfield(n1)
693 REAL(rprec),
INTENT(in) :: bf_add(n1)
696 bfield = bfield + cur*bf_add
702 REAL(rprec),
TARGET,
INTENT(in) :: bptr(nr0b,nz0b,np0b,3)
704 brvac => bptr(:,:,:,1)
705 bpvac => bptr(:,:,:,2)
706 bzvac => bptr(:,:,:,3)
716 IF (
ALLOCATED(
bvac))
DEALLOCATE (
bvac,stat=istat)
integer, dimension(:), allocatable nbcoils
real(rprec), dimension(:,:), allocatable seplim
real(rprec), dimension(:), allocatable xobser
character(len= *), parameter vn_mgmode
real(rprec), dimension(:,:,:), pointer brvac
integer, dimension(:), allocatable nsetsn
real(rprec), dimension(:,:), allocatable unpsiext
real(rprec), dimension(:,:), allocatable abcoil
character(len= *), parameter vn_br0
character(len=30), dimension(:), allocatable curlabel
character(len=1) mgrid_mode
subroutine free_mgrid(istat)
real(rprec), dimension(:), allocatable dsiext
real(rprec), dimension(:), allocatable plflux
subroutine read_mgrid(mgrid_file, extcur, nv, nfp, lscreen, ier_flag)
real(rprec), dimension(:,:), allocatable rbcoilsqr
real(rprec), dimension(:), allocatable raw_coil_current
character(len= *), parameter vn_zmax
character(len= *), parameter vn_kp
real(rprec), dimension(:), allocatable b_chi
character(len= *), parameter vn_jz
character(len= *), parameter vn_bz0
character(len= *), parameter vn_nobd
integer, dimension(:), allocatable needflx
character(len= *), parameter vn_nfp
real(rprec), dimension(:), allocatable psiext
real(rprec), dimension(:,:), allocatable bcoil
integer, dimension(:,:), allocatable needbfld
character(len= *), parameter vn_zmin
real(rprec), dimension(:,:), allocatable rbcoil
real(rprec), dimension(:,:), allocatable rlim
character(len=15), dimension(:), allocatable bloopnames
character(len= *), parameter vn_flp
integer, parameter nlimset
real(rprec), dimension(:,:,:), pointer bpvac
character(len= *), parameter vn_rmin
real(rprec), dimension(:,:), allocatable, target bvac
character(len= *), parameter vn_coilcur
real(rprec), dimension(:,:), allocatable reslim
real(rprec), dimension(:,:,:), allocatable dbcoil
character(len= *), parameter vn_ir
character(len= *), parameter ln_flp
character(len= *), parameter ln_nobd
real(rprec), dimension(:,:), allocatable zbcoil
character(len= *), parameter ln_nbset
real(rprec), dimension(:,:,:), allocatable pfcspec
integer, dimension(:), allocatable limitr
subroutine sum_bfield(bfield, bf_add, cur, n1)
character(len= *), parameter vn_coilgrp
character(len= *), parameter vn_nbfld
integer, dimension(:,:), allocatable iconnect
real(rprec), dimension(:), allocatable xobsqr
character(len=300) mgrid_path
character(len= *), parameter ln_nbfld
subroutine assign_bptrs(bptr)
character(len= *), parameter ln_next
character(len=15), dimension(:), allocatable dsilabel
real(rprec), dimension(:,:), allocatable plbfld
real(rprec), dimension(:,:,:), pointer bzvac
real(rprec), dimension(:,:), allocatable zlim
character(len=300) mgrid_path_old
character(len= *), parameter vn_nextcur
character(len= *), parameter vn_nbset
character(len= *), parameter vn_bp0
real(rprec), dimension(:), allocatable zobser
character(len= *), parameter vn_rmax
fault-tolerant file opening routines
subroutine safe_open(iunit, istat, filename, filestat, fileform, record_in, access_in, delim_in)