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