import copy
import warnings


def get_list_values_smaller_than_ref(list_val, ref_val):
    """
    Returns list of values in list_val, which are smaller than ref_val

    Parameters
    ----------
    list_val : list (of floats)
        Value list
    ref_val : float
        Reference value, which defines upper bound for search

    Returns
    -------
    list_smaller : list (of floats)
        List holding all values of list_val, which are smaller than or equal to
        ref_value
    """

    list_smaller = copy.copy(list_val)

    for val in list_val:
        if val > ref_val:
            list_smaller.remove(val)

    if list_smaller == []:
        msg = 'list_smaller is empty list. Thus, going to use smallest ' \
              'values of original list list_val.'
        warnings.warn(msg)
        list_smaller.append(min(list_val))

    return list_smaller