def loopover(vars, outview, inaxes=None, preserve=None, pbar=None):
    """ Loop over a variable 
    In: input variable, view of reduced variable, optionally a list of integer indices (preserve) 
    to axes that should be loaded in their entirety
    Out: slices into an accumulation array, chunks of the input variable that will go into that part of
    the accumulation array"""
    from pygeode.var import Var
    if isinstance(vars, Var):
        vars = [vars]
    outview = outview.clip()
    if inaxes is None:
        assert len(vars
            ) == 1, 'Implicit reduction axes (inaxes=None) can only be used when looping over one variable.'
        inaxes = vars[0].axes
    inview = outview.map_to(inaxes, strict=False)
    loop = list(inview.loop_mem(preserve=preserve))
    for i, inv in enumerate(loop):
        outv = inv.map_to(outview.axes)
        subpbar = pbar.part(i, len(loop))
        data = []
        for j, v in enumerate(vars):
            vpbar = subpbar.part(j, len(vars))
            try:
                data.append(inv.get(v, pbar=vpbar))
            except StopIteration:
                raise Exception(
                    'Stray StopIteration signal caught.  Unable to retrieve the data.'
                    )
        yield outv.slices, data
