'From the data collected by `scan_cell()`, convert to the final data
structure.'

def structure_from_cells(self):

    rowseps = self.rowseps.keys()
    rowseps.sort()
    rowindex = {}
    for i in range(len(rowseps)):
        rowindex[rowseps[i]] = i
    colseps = self.colseps.keys()
    colseps.sort()
    colindex = {}
    for i in range(len(colseps)):
        colindex[colseps[i]] = i
    colspecs = [((colseps[i] - colseps[(i - 1)]) - 1) for i in range(1, len(colseps))]
    onerow = [None for i in range((len(colseps) - 1))]
    rows = [onerow[:] for i in range((len(rowseps) - 1))]
    remaining = ((len(rowseps) - 1) * (len(colseps) - 1))
    for (top, left, bottom, right, block) in self.cells:
        rownum = rowindex[top]
        colnum = colindex[left]
        assert (rows[rownum][colnum] is None), ('Cell    (row    %s,    column    %s)    already    used.' % ((rownum + 1), (colnum + 1)))
        morerows = ((rowindex[bottom] - rownum) - 1)
        morecols = ((colindex[right] - colnum) - 1)
        remaining -= ((morerows + 1) * (morecols + 1))
        rows[rownum][colnum] = (morerows, morecols, (top + 1), block)
    assert (remaining == 0), 'Unused    cells    remaining.'
    if self.head_body_sep:
        numheadrows = rowindex[self.head_body_sep]
        headrows = rows[:numheadrows]
        bodyrows = rows[numheadrows:]
    else:
        headrows = []
        bodyrows = rows
    return (colspecs, headrows, bodyrows)
