def setmask(arr, x1=None, x2=None):
    """setmask(arr, x1, x2)
    arr = 1D arr
    x1 = lower value
    x2 = upper value
    by default it returns a mask that
    is the full range of arr
    returns
    =======
    mask, x1, x2
    if input x1 and x2 are out of bounds
    then it sets x1 and x2 to the boundry of arr"""
    if (x1 == None) | (x1 <= arr[0]):
        x1 = arr[0]
    if (x2 == None) | (x2 >= arr[-1]):
        x2 = arr[-1]
    mask = (arr >= x1) & (arr <= x2)
    return mask, x1, x2
