r'''Returns the nearest hit to a given name from from dictionaries of
    building, insulating, or refractory material from tables in [1]_, [2]_,
    and [3]_. Function will pick the closest match based on a fuzzy search.
    if `complete` is True, will only return hits with all three of density,
    heat capacity, and thermal conductivity available.

    Parameters
    ----------
    name : str
        Search keywords to be used by difflib function
    complete : bool, optional
        If True, returns only hits with all parameters available

    Returns
    -------
    ID : str
        A key to one of the dictionaries mentioned above

    Examples
    --------
    >>> nearest_material('stainless steel')
    'Metals, stainless steel'

    References
    ----------
    .. [1] ASHRAE Handbook: Fundamentals. American Society of Heating,
       Refrigerating and Air-Conditioning Engineers, Incorporated, 2013.
    .. [2] DIN EN 12524 (2000-07) Building Materials and Products
       Hygrothermal Properties - Tabulated Design Values; English Version of
       DIN EN 12524.
    .. [3] Gesellschaft, V. D. I., ed. VDI Heat Atlas. 2nd edition.
       Berlin; New York:: Springer, 2010.

def nearest_material(name, complete=False):
    r'''Returns the nearest hit to a given name from from dictionaries of
    building, insulating, or refractory material from tables in [1]_, [2]_,
    and [3]_. Function will pick the closest match based on a fuzzy search.
    if `complete` is True, will only return hits with all three of density,
    heat capacity, and thermal conductivity available.

    Parameters
    ----------
    name : str
        Search keywords to be used by difflib function
    complete : bool, optional
        If True, returns only hits with all parameters available

    Returns
    -------
    ID : str
        A key to one of the dictionaries mentioned above

    Examples
    --------
    >>> nearest_material('stainless steel')
    'Metals, stainless steel'

    References
    ----------
    .. [1] ASHRAE Handbook: Fundamentals. American Society of Heating,
       Refrigerating and Air-Conditioning Engineers, Incorporated, 2013.
    .. [2] DIN EN 12524 (2000-07) Building Materials and Products
       Hygrothermal Properties - Tabulated Design Values; English Version of
       DIN EN 12524.
    .. [3] Gesellschaft, V. D. I., ed. VDI Heat Atlas. 2nd edition.
       Berlin; New York:: Springer, 2010.
    '''
    if complete:
        hits = difflib.get_close_matches(name, materials_dict.keys(), n=1000, cutoff=0)
        for hit in hits:
            if materials_dict[hit] == 1 or materials_dict[hit]==3 or (ASHRAE[hit][0] and ASHRAE[hit][1]):
                return hit
    else:
        ID = difflib.get_close_matches(name, materials_dict.keys(), n=1, cutoff=0.6)
        if not ID:
            ID = difflib.get_close_matches(name, materials_dict.keys(), n=1, cutoff=0.3)
        if not ID:
            ID = difflib.get_close_matches(name, materials_dict.keys(), n=1, cutoff=0)
        return ID[0]