integer function smallestTrueIndex(maskVector) logical(bool), intent(in) :: maskVector(:) end function
Examples:
smallestTrueIndex(((/0, 1, 1/) > 0)) ! returns 2 smallestTrueIndex(((/1, 1, 1/) > 0)) ! returns 1 smallestTrueIndex(((/0, 0, 0/) > 0)) ! returns 4, ie 1 above vector limit.
size(maskVector)+1 is also returned if the vector is of zero size.