def METHOD_NAME(obj, default=None, warn=False, fail=False):
    """Return a string representation of an object's units.
    This function returns obj.attrs.get('units') with no processing, or it
    converts the units of a Quantity object to a string and returns that.  The
    output should be suitable for saving to an HDF5 file."""
    try:
        return obj.attrs.get('units') #this works for things with attrs
    except AttributeError:
        try:
            return str(obj.units) #this works for Quantities
        except:
            if warn:
                print("Warning: no unit string found on " + str(obj))
            if fail:
                raise ValueError("No unit information was found on " + str(obj))
            return default