Merging sorted events of simulation
Both input arrays should be sorted and the last elements should alvays be huge() and they will be not sorted
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(inout), | allocatable | :: | time_inout(:) | ||
| logical, | intent(inout), | allocatable | :: | expl_inout(:) | ||
| real(kind=dp), | intent(in) | :: | time(:) |
sorted, without duplicates input arrays ending with huge |
||
| logical, | intent(in) | :: | explicit |
subroutine merge_events(time_inout, expl_inout, time, explicit) !! Merging sorted events of simulation !! !! Both input arrays should be sorted and the last elements !! should alvays be huge() and they will be not sorted real(dp), allocatable, intent(inout) :: time_inout(:) logical, allocatable, intent(inout) :: expl_inout(:) real(dp), intent(in) :: time(:) !! sorted, without duplicates input arrays ending with huge logical, intent(in) :: explicit real(dp), allocatable :: tmp(:) !! temporary time event array logical, allocatable :: msk(:) !! temporary explicit event array integer :: i1, i2, o !! input, output indexes allocate(tmp(size(time_inout) + size(time))) allocate(msk(size(tmp))) o = 0; i1 = 1; i2 = 1 do while (i1 <= size(time_inout) .and. i2 <= size(time)) o = o + 1 if (abs(time_inout(i1)-time(i2))<=sim_delta) then tmp(o) = time_inout(i1) msk(o) = expl_inout(i1) .or. explicit i1 = i1 + 1 i2 = i2 + 1 else if (time_inout(i1)<time(i2)) then tmp(o) = time_inout(i1) msk(o) = expl_inout(i1) i1 = i1 + 1 else tmp(o) = time(i2) msk(o) = explicit i2 = i2 + 1 endif enddo time_inout = tmp(1:o) expl_inout = msk(1:o) end subroutine merge_events