This function takes as input two sequences of ranges and returns a sequence which contains all overlaps between the input ranges.
Points to note:
andedRanges => andRangesPair(andedRanges, rangesB)
The memory that the pointer andedRanges pointed to before the call now has no pointer to it, since at the moment the call is executed andedRanges is reassigned to the same memory that the function points to, which was newly assigned during the call. The initial memory pointed to by andedRanges therefore cannot now be deallocated. Better would be:
tempAndedRanges => andRangesPair(andedRanges, rangesB) deallocate(andedRanges) andedRanges => tempAndedRanges
Then later, when appropriate, deallocate(andedRanges) for the final time.
% function andRangesPair(rangesA, rangesB, doChecks) result(andedRanges) function andRangesPair(rangesA, rangesB) result(andedRanges) type(RangeT), intent(in) :: rangesA(:), rangesB(:) type(RangeT), pointer :: andedRanges(:) % logical(bool), intent(in), optional :: doChecks end function andRangesPair