def check_convergence(p_in, p_out, tols, abs_flags):
    """
    All four input arguments are lists or tuples of the same length.
    Compares values in 'p_in' against those in 'p_out', and returns
    False if the difference is greater than the corresponding value in
    'tols'.  If the value in 'abs_flags' is True, the values are
    compared in absolutely rather than fractionally.
    """
    for i, (pi, po, t, a) in enumerate(zip(list(p_in), list(p_out), tols, abs_flags)):
        if a:
            if abs(pi - po) > t:
                #print 'busted %i (%f -> %f       t= %f'%(i, pi, po, t)
                return False
        else:
            d = abs(pi+po)/2
            if d < 1e-7:
                d = 1e-7
            if abs(pi - po) / d > t:
                #print 'busted %i (%f -> %f d= %f t= %f'%(i, pi, po, d, t)
                return False
    return True