def boxproj_(z,p,l,u):
    """ This subroutine projects the vector z onto the box [l,u]

    z,l,u are vectors of length p
    """

    z = z.flatten()
    for i in range(0,p):
        z[i] = min(max(l[i],z[i]),u[i])
    return z