def computeblocksize(expectedrows, compoundsize, lowercompoundsize):
    """Calculate the optimum number of superblocks made from compounds blocks.

    This is useful for computing the sizes of both blocks and
    superblocks (using the PyTables terminology for blocks in indexes).

    """
    nlowerblocks = expectedrows // lowercompoundsize + 1
    if nlowerblocks > 2 ** 20:
        nlowerblocks = 2 ** 20
    size = lowercompoundsize * nlowerblocks
    size = (size // compoundsize + 1) * compoundsize
    return size
