def add_filter_names(headerlist, filter_names, filter_labels, filters):
    """
    Add a set of filter header labels (i.e. niriss_f090w_magnitude for example)
    to a list, by matching filter names.

    Parameters
    ----------
    headerlist : list
        An existing (possibly empty) list to hold the header string for the
        output magnitudes

    filter_names : list
        The list of available filter names to match to

    filter_labels : list
        The corresponding list of filter labels

    filters : list
        The list of filter names to match, or an empty list or None to get
        all available filter labels

    Returns
    -------
    headerlist : list
        The revised list of labels with the filter labels requested appended
    """
    try:
        n1 = len(filters)
    except:
        n1 = 0
    if (filters is None) or (n1 == 0):
        for loop in range(len(filter_labels)):
            headerlist.append(filter_labels[loop])
    if n1 > 0:
        for loop in range(n1):
            for k in range(len(filter_names)):
                if filters[loop].lower() == filter_names[k].lower():
                    headerlist.append(filter_labels[k])
    return headerlist