FIXME : Add documentation
subroutine get_initial_grids_3d
use file_utils, only: get_unused_unit
implicit none
integer :: unit
integer :: i, ntor
real :: dpdpsi, pres, bavg, cvavg
call get_unused_unit(unit)
open (unit=unit, file=trim(source), status="old", action="read")
read (unit=unit, fmt=*) ntgridin, nthetain, ntor
nthetain = nthetain * iperiod
do i = -ntgridin,ntgridin
read (unit=unit, fmt=*) thetagrid(i),bmag(i),gradpar(i),gds2(i),cvdrift(i),gbdrift(i),dpdpsi,pres
end do
close (unit=unit)
bavg = sum(bmag(-nthetain/2:nthetain/2))/(nthetain+1)
cvavg = sum(cvdrift)/size(cvdrift)
write(*,*) 'bavg = ',bavg
write(*,*) 'cvavg = ',cvavg,' and remember that cvdrift assumed beta_prime=0'
! bmag = bmag / bavg
gds2 = gds2 * ntor**2
gbdrift = gbdrift * ntor * 2. / bmag**2
! cvdrift = cvdrift * ntor * 2. / bmag**3 ! not correct for beta_prime term, so use:
cvdrift = gbdrift
! alp = -1./pres*dpdpsi
!
! these are theta and mod(b) grids that are periodic
!
thetain = thetagrid(-nthetain/2:nthetain/2)
bmagin = bmag(-nthetain/2:nthetain/2)
end subroutine get_initial_grids_3d