This takes a vector of ranges and returns them in a well-formed sequence (see section 9.5.1). Note that the argument is a pointer because the operation may change the number of elements.
subroutine correctRanges(ranges) type(RangeT), pointer :: ranges(:) end subroutine correctRanges