tracer_step Subroutine

public subroutine tracer_step(tr, bs, i, ivlo, ivhi, m)

Feed model i's intervals (ivlo/ivhi, m of them, ascending in y).

Matches each interval to an open band from model i - 1 by overlap; unmatched intervals open new bands; bands w/o continuation stored to bs.

Arguments

Type IntentOptional Attributes Name
type(tracer_t), intent(inout) :: tr

Tracer.

type(bandset_t), intent(inout) :: bs

Receives bands closed at this model.

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

Model index; number of intervals.

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

Lower and upper y of each interval, 1:m used.

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

Lower and upper y of each interval, 1:m used.

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

Model index; number of intervals.


Source Code

   subroutine tracer_step(tr, bs, i, ivlo, ivhi, m)
      !! Feed model `i`'s intervals (`ivlo`/`ivhi`, `m` of them, ascending in y).
      !!
      !! Matches each interval to an open band from model `i - 1` by overlap; unmatched intervals
      !! open new bands; bands w/o continuation stored to `bs`.
      ! Arguments
      type(tracer_t), intent(inout) :: tr
         !! Tracer.
      type(bandset_t), intent(inout) :: bs
         !! Receives bands closed at this model.
      integer(int32), intent(in)    :: i, m
         !! Model index; number of intervals.
      real(real64), intent(in)    :: ivlo(:), ivhi(:)
         !! Lower and upper y of each interval, `1:m` used.
      integer(int32) :: k, b, newb
      logical :: matched
      tr%ext = .false.
      do k = 1, m
         matched = .false.
         do b = 1, tr%maxbands
            if (.not. tr%opn(b) .or. tr%ext(b) .or. tr%i1(b) /= i - 1) cycle
            if (ivlo(k) < tr%yhi(b, i - 1) .and. tr%ylo(b, i - 1) < ivhi(k)) then
               tr%ylo(b, i) = ivlo(k); tr%yhi(b, i) = ivhi(k)
               tr%i1(b) = i; tr%ext(b) = .true.
               matched = .true.
               exit
            end if
         end do
         if (matched) cycle
         newb = 0
         do b = 1, tr%maxbands
            if (.not. tr%opn(b)) then; newb = b; exit; end if
         end do
         if (newb > 0) then
            tr%opn(newb) = .true.; tr%ext(newb) = .true.
            tr%i0(newb) = i; tr%i1(newb) = i
            tr%ylo(newb, i) = ivlo(k); tr%yhi(newb, i) = ivhi(k)
         else
            ! overflow fallback: store as a single-model band
            call bandset_append(bs, i, i, ivlo(k:k), ivhi(k:k))
         end if
      end do
      ! store order: overflow bands as their interval comes, then bands closed here in slot order
      do b = 1, tr%maxbands
         if (tr%opn(b) .and. .not. tr%ext(b)) then
            call tracer_close(tr, bs, b)
         end if
      end do
   end subroutine tracer_step