The points of 1 .. n whose times are at most t (trace mode): i1 .. i2 (none: i2 < i1), the first points for increasing times, the last for decreasing ones (by bisection).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Trajectory), | intent(in) | :: | traj |
the trajectory |
||
| real(kind=wp), | intent(in) | :: | t |
the current time |
||
| integer, | intent(in) | :: | n |
the points considered (1 .. n) |
||
| integer, | intent(out) | :: | i1 |
the points passed (none: i2 < i1) |
||
| integer, | intent(out) | :: | i2 |
the points passed (none: i2 < i1) |
subroutine trace_range(traj, t, n, i1, i2) type(Trajectory), intent(in) :: traj !! the trajectory real(wp), intent(in) :: t !! the current time integer, intent(in) :: n !! the points considered (1 .. n) integer, intent(out) :: i1, i2 !! the points passed (none: i2 < i1) integer :: low, high, mid i1 = 1 i2 = 0 if (n < 1) return low = 0 high = n + 1 if (.not. decreasing_times(traj, n)) then ! points 1 .. low have times <= t do while (high - low > 1) mid = (low + high) / 2 if (traj%time(mid) <= t) then low = mid else high = mid end if end do i2 = low else ! points high .. n have times <= t do while (high - low > 1) mid = (low + high) / 2 if (traj%time(mid) <= t) then high = mid else low = mid end if end do i1 = high i2 = n end if end subroutine trace_range