Given an initial theta and gradpar (=dtheta/dl) compute a new theta grid, returned in arcl, which has gradpar = dg/dl = constant.
The input gradpar is modified on output.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | ntheta | |||
integer, | intent(in) | :: | nperiod | |||
real, | intent(in), | dimension(-ntgrid:) | :: | theta | ||
real, | intent(inout), | dimension(-ntgrid:) | :: | gpar | ||
real, | intent(out), | dimension(-ntgrid:) | :: | arcl |
pure subroutine arclength (ntheta, nperiod, theta, gpar, arcl)
use constants, only: twopi, pi
implicit none
integer, intent (in) :: ntheta, nperiod
real, dimension(-ntgrid:), intent (out) :: arcl
real, dimension(-ntgrid:), intent (in) :: theta
real, dimension(-ntgrid:), intent (in out) :: gpar
integer :: nth, j
real :: arcfac
nth = ntheta / 2
arcl(-nth) = 0.
do j = -nth, nth-1
arcl(j+1) = arcl(j) + 0.5 * (theta(j+1) - theta(j)) * (1. / gpar(j) + 1. / gpar(j+1))
end do
arcfac = 1. / arcl(nth)
do j = -nth, nth
arcl(j) = arcl(j) * twopi * arcfac - pi
end do
call periodic_copy(arcl, twopi, nperiod)
gpar = twopi * arcfac
end subroutine arclength