def boxcar(xL, n):
    """
    You can smooth the data data1 using k points by calling the 
    function boxcar(xL, n) where n is HALF the size of boxcar  
    
    # xL is list to be smoothed, n is HALF the size of boxcar 
    # (preserve position, so use points from -n to +n
    """
    x_smooth = []
    L = len(xL)
    for i in range(L):
        if i < n:
            imin = 0
            imax = i * 2 + 1
        elif i < L - n:
            imin = i - n
            imax = i + n
        else:
            imax = L
            imin = i - (L - i) - 1
        span = imax - imin
        val = sum(xL[imin:imax]) / span
        x_smooth.append(val)
    return x_smooth
