map Function

pure function map(ival, m, reverse) result(idest)

Arguments

Type IntentOptional Attributes Name
integer(kind=ip), intent(in) :: ival
type(mapping), intent(in) :: m
logical, intent(in) :: reverse

Return Value integer(kind=ip)


Called by

proc~~map~~CalledByGraph proc~map problem_5::map proc~traverse problem_5::traverse proc~traverse->proc~map program~problem_5 problem_5 program~problem_5->proc~traverse

Source Code

    pure function map(ival, m, reverse) result(idest)
        integer(ip),intent(in) :: ival
        type(mapping),intent(in) :: m
        logical,intent(in) :: reverse ! if reversed, go from: dest -> src
        integer(ip) :: idest
        integer :: i
        if (reverse) then
            do i = 1, size(m%src_start)
                ! locate ival (dest) in the dest start:end range
                if (ival>=m%dest_start(i) .and. ival<=m%dest_end(i)) then ! found it, map to dest
                    idest = m%src_start(i) + (ival-m%dest_start(i)) ! this is the resultant isource
                    return
                end if
            end do
        else
            do i = 1, size(m%src_start)
                ! locate ival (source) in the source start:end range
                if (ival>=m%src_start(i) .and. ival<=m%src_end(i)) then ! found it, map to dest
                    idest = m%dest_start(i) + (ival-m%src_start(i))
                    return
                end if
            end do
        end if
        idest = ival ! if not found in any of the sets
    end function map