def extract_basis_nwchem(data, name):
    """Extract atomic orbital, charge density fitting, or exchange
    correlation functional basis data from a text region passed in as
    data. The charge density fitting and exchange correlation functional
    basis set data are employed for density functional calculations.

    @param data: text region containing basis set data
    @type data : str
    @param name: name of basis type: "ao basis", "cd basis", or "xc basis"
    @type name : str
    @return: per-element basis set chunks
    @rtype : list
    """

    begin_marker = """BASIS "{0}" PRINT""".format(name)
    end_marker = "END"

    # search for the basis set data begin marker
    # calling "upper" on data because original data has inconsistent
    # capitalization
    begin = data.upper().find(begin_marker.upper())
    end = data.upper().find(end_marker, begin)

    # No basis data found
    if begin == -1:
        return []

    trimmed = data[begin + len(begin_marker): end - len(end_marker)].strip()

    chunks = []
    lines = []

    # group lines of data delimited by #BASIS SET... into per-element chunks
    for line in trimmed.split("\n"):
        if line.upper().startswith("#BASIS SET"):
            if lines:
                chunks.append(lines)
            lines = [line]
        else:
            lines.append(line)

    # handle trailing chunk that is not followed by another #BASIS SET...
    if lines and (not chunks or lines != chunks[-1]):
        chunks.append(lines)

    # join lines back into solid text blocks
    chunks = ["\n".join(c) for c in chunks]
    return chunks