def check_h5_settings(f, n, dim, min_dist=None,
                      names=None, cats=None, write=False):
    if any(divs.shape != (n, n)
           for name, div_group in f.items() if name != '_meta'
           for divs in div_group.values()):
        raise ValueError("existing divs have wrong shape")

    if '_meta' in f:
        meta_group = f['_meta']
        def check(name, value):
            if np.any(meta_group[name][()] != value):
                raise ValueError("attribute '{}' differs in file".format(name))
    elif write:
        meta_group = f.require_group('_meta')
        def check(name, value):
            meta_group[name] = value
    else:
        meta_group = None
        def check(name, value):
            pass

    check('dim', dim)
    check('min_dist', default_min_dist(dim) if min_dist is None else min_dist)

    for x in ['names', 'cats']:
        if meta_group is not None and x in meta_group:
            if meta_group[x].shape != (n,):
                raise ValueError("'{}'' has wrong shape in file".format(x))
    if names is not None or cats is not None:
        reconcile_file_order(f, names=names, cats=cats, write=write)
Checks that the hdf5 div cache file has settings that agree with the
dataset/ETHPy150Open dougalsutherland/py-sdm/sdm/np_divs.py/check_h5_settings