def _ascii_generate_header(tab, comments='#', delimiter=' ',
    commentedHeader=True):
    """ Generate the corresponding ascii Header that contains all necessary info

    Parameters
    ----------

    tab: SimpleTable instance
        table

    comments: str
        string to prepend header lines

    delimiter: str, optional
        The string used to separate values.  By default, this is any
        whitespace.

    commentedHeader: bool, optional
        if set, the last line of the header is expected to be the column titles

    Returns
    -------
    hdr: str
        string that will be be written at the beginning of the file
    """
    hdr = []
    if comments is None:
        comments = ''
    length = max(list(map(len, list(tab.header.keys()))))
    fmt = '{{0:s}} {{1:{0:d}s}}\t{{2:s}}'.format(length)
    for k, v in list(tab.header.items()):
        for vk in str(v).split('\n'):
            if len(vk) > 0:
                hdr.append(fmt.format(comments, k.upper(), vk.strip()))
    length = max(list(map(len, list(tab.keys()))))
    fmt = '{{0:s}}{{0:s}} {{1:{0:d}s}}\t{{2:s}}\t{{3:s}}'.format(length)
    for colname in list(tab.keys()):
        unit = tab._units.get(colname, 'None')
        desc = tab._desc.get(colname, 'None')
        hdr.append(fmt.format(comments, colname, unit, desc))
    if len(tab._aliases) > 0:
        for k, v in list(tab._aliases.items()):
            hdr.append('{0:s} alias\t{1:s}={2:s}'.format(comments, k, v))
    if commentedHeader:
        hdr.append('{0:s} {1:s}'.format(comments, delimiter.join(list(tab.
            keys()))))
    else:
        hdr.append('{0:s}'.format(delimiter.join(list(tab.keys()))))
    return '\n'.join(hdr)
