get_indices_in_char_array Subroutine

private subroutine get_indices_in_char_array(array, val, iloc, jloc)

return the indices of all the val elements in 2d array.

Arguments

Type IntentOptional Attributes Name
character(len=1), intent(in), dimension(:,:) :: array
character(len=1), intent(in) :: val
integer, intent(out), dimension(:), allocatable :: iloc
integer, intent(out), dimension(:), allocatable :: jloc

Called by

proc~~get_indices_in_char_array~~CalledByGraph proc~get_indices_in_char_array get_indices_in_char_array interface~get_indices get_indices interface~get_indices->proc~get_indices_in_char_array

Source Code

    subroutine get_indices_in_char_array(array, val, iloc, jloc)
        !! return the indices of all the `val` elements in 2d `array`.
        character(len=1),dimension(:,:),intent(in) :: array
        character(len=1),intent(in) :: val
        integer,dimension(:),allocatable,intent(out) :: iloc, jloc
        integer :: k !! counter
        ! do this by creating index matrices, and using mask to get the ones we want
        iloc = pack(spread([(k, k = 1, size(array,1))], dim=2, ncopies=size(array,2)), mask=array==val)
        jloc = pack(spread([(k, k = 1, size(array,2))], dim=1, ncopies=size(array,1)), mask=array==val)
    end subroutine get_indices_in_char_array