Trace all five convection types into conv_bands and conv_chains.
One pass over models per type, exact region outline built alongside: horizontal interface edges of every interval, plus at each strip edge the symmetric difference of adjacent models' interval sets. Tracer seams are covered on both sides, so never enter outline.
subroutine build_conv_cache() !! Trace all five convection types into `conv_bands` and `conv_chains`. !! !! One pass over models per type, exact region outline built alongside: horizontal interface !! edges of every interval, plus at each strip edge the symmetric difference of adjacent !! models' interval sets. Tracer seams are covered on both sides, so never enter outline. type(tracer_t) :: tr integer(int32) :: t, i, j, m, pm, maxnc, ns real(real64), allocatable :: ivlo(:), ivhi(:), plo(:), phi(:), bp(:) integer(int32), allocatable :: se0(:), se1(:) real(real64), allocatable :: sy0(:), sy1(:) maxnc = 1 do i = 1, nmodels maxnc = max(maxnc, int(data(i)%nconv, int32)) end do call tracer_alloc(tr, 64_int32, nmodels) allocate (ivlo(maxnc), ivhi(maxnc), plo(maxnc), phi(maxnc)) allocate (bp(4*maxnc + 4)) do t = 1, NCONVTYPES call bandset_clear(conv_bands(t)) call chainset_clear(conv_chains(t)) call tracer_reset(tr) ns = 0; pm = 0 do i = 1, nmodels ! intervals of this type in model i (centre -> surface order) m = 0 do j = 1, int(data(i)%nconv, int32) if (type_of(data(i)%yzip(j)) /= t) cycle m = m + 1 ivlo(m) = mbound(i, j - 1) ivhi(m) = mbound(i, j) end do call tracer_step(tr, conv_bands(t), i, ivlo, ivhi, m) ! outline: vertical boundary at strip edge i, horizontals of model i call symdiff_append(plo, phi, pm, ivlo, ivhi, m, i, bp, & se0, se1, sy0, sy1, ns) do j = 1, m if (ivhi(j) <= ivlo(j)) cycle call seg_append(se0, se1, sy0, sy1, ns, i, i + 1, ivlo(j), ivlo(j)) call seg_append(se0, se1, sy0, sy1, ns, i, i + 1, ivhi(j), ivhi(j)) end do pm = m; plo(1:m) = ivlo(1:m); phi(1:m) = ivhi(1:m) end do call tracer_flush(tr, conv_bands(t)) ! right boundary of the last model call symdiff_append(plo, phi, pm, ivlo, ivhi, 0_int32, nmodels + 1, bp, & se0, se1, sy0, sy1, ns) call build_chains(conv_chains(t), se0, se1, sy0, sy1, ns) end do deallocate (ivlo, ivhi, plo, phi, bp) call tracer_dealloc(tr) conv_valid = .true. end subroutine build_conv_cache