sub2ind Function

public function sub2ind(dims, subs) result(ind)

Calculates the linear index of an array with dimensions dims and subcripts subs

Arguments

Type IntentOptional AttributesName
integer, intent(in), dimension(:):: dims

Dimension of Array

integer, intent(in), dimension(:):: subs

Subscripts to convert

Return Value integer

Linear index


Called by

proc~~sub2ind~~CalledByGraph proc~sub2ind sub2ind proc~get_value get_value proc~get_value->proc~sub2ind

Contents

Source Code


Source Code

function sub2ind(dims, subs) result (ind)
    !+ Calculates the linear index of an array with dimensions `dims` and
    !+ subcripts `subs`
    integer, dimension(:), intent(in) :: dims
        !+ Dimension of Array
    integer, dimension(:), intent(in) :: subs
        !+ Subscripts to convert
    integer :: ind
        !+ Linear index

    integer :: k, l, p

    ind = subs(1)
    do k=2,size(dims)
        p = dims(1)
        do l=2, k-1
            p = p*dims(l)
        enddo
        ind = ind + p*(subs(k)-1)
    enddo

end function sub2ind