def min_int(la,
            lb,
            ia,
            ib,
            tol=0.01):
    """
    Given two complete drillholes A, B (no gaps and up to the end of
    the drillhole), this function returns the smaller of two
    intervals la = FromA[ia] lb = FromB[ib] and updates the
    indices ia and ib. There are three possible outcomes

    - FromA[ia] == FromB[ib]+/- tol. Returns mean of FromA[ia], FromB[ib] and ia+1, ib+1
    - FromA[ia] <  FromB[ib]. Returns FromA[ia] and ia+1, ib
    - FromA[ia] >  FromB[ib]. Returns FromB[ia] and ia, ib+1
    """

    # equal ?  
    #if (lb-1)<=la<=(lb+1):
    if la==lb:
        #print("la", la)
        #print("lb", lb)
        #print("1:", (la+lb)/2)
        #print("ia", ia)
        #print("ib", ib)
        #return ia+1, ib+1, (la+lb)/2
        return ia+1, ib+1, la
    
    # la < lb ?
    if la<lb:
        #print("la", la)
        #print("lb", lb)
        #print("2:",  la)
        return ia+1, ib, la

    # lb < la ?
    if lb<la:
        #print("la", la)
        #print("lb", lb)
        #print("3:",  lb)
        return ia, ib+1, lb