level_intervals Subroutine

private subroutine level_intervals(i, vals, idxs, n, L, ivlo, ivhi, m)

Find intervals of model i where step function reaches level L.

Positive L reached by values at or above it, negative by values at or below; intervals in cgs for band tracer.

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: i

Model index.

integer(kind=int32), intent(in) :: vals(:)

Level of each step-function entry.

integer(kind=int32), intent(in) :: idxs(:)

Coordinate index where each entry starts.

integer(kind=int32), intent(in) :: n

Number of entries.

integer(kind=int32), intent(in) :: L

Contour level, nonzero.

real(kind=real64), intent(out) :: ivlo(:)

Lower mass (g) or radius (cm) of each interval, at least n long.

real(kind=real64), intent(out) :: ivhi(:)

Upper mass (g) or radius (cm) of each interval, at least n long.

integer(kind=int32), intent(out) :: m

Number of intervals.


Source Code

   subroutine level_intervals(i, vals, idxs, n, L, ivlo, ivhi, m)
      !! Find intervals of model `i` where step function reaches level `L`.
      !!
      !! Positive `L` reached by values at or above it, negative by values at or below; intervals in
      !! cgs for band tracer.
      ! Arguments
      integer(int32), intent(in)  :: i
         !! Model index.
      integer(int32), intent(in)  :: vals(:)
         !! Level of each step-function entry.
      integer(int32), intent(in)  :: idxs(:)
         !! Coordinate index where each entry starts.
      integer(int32), intent(in)  :: n
         !! Number of entries.
      integer(int32), intent(in)  :: L
         !! Contour level, nonzero.
      real(real64), intent(out) :: ivlo(:)
         !! Lower mass (g) or radius (cm) of each interval, at least `n` long.
      real(real64), intent(out) :: ivhi(:)
         !! Upper mass (g) or radius (cm) of each interval, at least `n` long.
      integer(int32), intent(out) :: m
         !! Number of intervals.
      integer(int32) :: pf, xprev, xcur
      logical :: rising, falling, inb
      real(real64) :: ylo
      m = 0; inb = .false.; ylo = 0.d0
      do pf = 1, n
         if (pf == 1) then
            xprev = 0
         else
            xprev = vals(pf - 1)
         end if
         xcur = vals(pf)
         if (L > 0) then
            rising = (xprev < L .and. xcur >= L)
            falling = (xprev >= L .and. xcur < L)
         else
            rising = (xprev > L .and. xcur <= L)
            falling = (xprev <= L .and. xcur > L)
         end if
         if (rising) then
            ylo = coord_at(i, idxs(pf)); inb = .true.
         else if (falling .and. inb) then
            m = m + 1; ivlo(m) = ylo; ivhi(m) = coord_at(i, idxs(pf))
            inb = .false.
         end if
      end do
      if (inb) then
         m = m + 1; ivlo(m) = ylo; ivhi(m) = coord_at(i, data(i)%ncoord)
      end if
   end subroutine level_intervals