my_minloc Function

public pure function my_minloc(vec, target_state)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: vec(:)
integer, intent(in), optional :: target_state

Return Value integer


Contents

Source Code


Source Code

    pure integer function my_minloc(vec, target_state)
        real(dp), intent(in) :: vec(:)
        integer, intent(in), optional :: target_state

        logical :: flag(size(vec))
        integer :: i


        if (present(target_state)) then
            flag = .true.
            do i = 1, target_state
                my_minloc = minloc(vec, dim = 1, mask = flag)
                flag(my_minloc) = .false.
            end do
        else
            my_minloc = minloc(vec, 1)
        end if

    end function my_minloc