def convert_units_apply(value, factor, fromto='from', mode='mul'):
    """
    Apply a conversion factor to a value.  For plain factors, if ('from' and
    'mul') or ('to' and 'div'), the value is multipled by the factor,
    otherwise the value is divided by the factor.

    Enter: value: a floating point value to adjust.
           factor: a factor to adjust it by.  This is either a number or a
                   two tuple of (factor, offset).
           fromto: 'from' or 'to'.  See above.
           mode: 'mul' or 'div'.  See above.
    Exit:  value: the converted value.
    """
    offset = 0
    if isinstance(factor, tuple):
        if callable(factor[0]):
            if (fromto, mode) in (('from', 'mul'), ('to', 'div')):
                return factor[0](value)
            else:
                return factor[1](value)
        (factor, offset) = factor
    if (fromto, mode) in (('from', 'mul'), ('to', 'div')):
        value = (value+offset)*factor
    else:
        value = value/factor-offset
    return value