def writedataset(h5group, name, data, overwrite=True):
    """
    Write a dataset to a hdf5 file.
    The `overwrite` parameter controls the behaviour when the dataset
    already exists.
    """
    if name in h5group:
        if overwrite:
            del h5group[name]
        else:
            return False
    h5group[name] = data
    return True