merge_events Subroutine

private 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

Arguments

Type IntentOptional 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

Called by

proc~~merge_events~~CalledByGraph proc~merge_events merge_events proc~signal_init signal_t%signal_init proc~signal_init->proc~merge_events proc~boundary_init_part1 boundary_init_part1 proc~boundary_init_part1->proc~signal_init proc~channel_init_part1 channel_init_part1 proc~channel_init_part1->proc~signal_init proc~mesh2d_init_part1 mesh2D_init_part1 proc~mesh2d_init_part1->proc~signal_init proc~sim_init simulation_t%sim_init proc~sim_init->proc~signal_init proc~solid_init_part1 solid_init_part1 proc~solid_init_part1->proc~signal_init proc~strand_init_part1 strand_init_part1 proc~strand_init_part1->proc~signal_init program~reims_p reims_p program~reims_p->proc~boundary_init_part1 program~reims_p->proc~channel_init_part1 program~reims_p->proc~mesh2d_init_part1 program~reims_p->proc~sim_init program~reims_p->proc~solid_init_part1 program~reims_p->proc~strand_init_part1

Source Code

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