def dictifyatts(varptr, tag):
    """
    read netcdf attributes and return them as a dict

    :param varptr: pointer to a netcdf variable object
    :param tag: string to add to the beginning of the keys in the dict
    :return: the attributes as a dict where the keys are the attribute names and the values are the attribute data
    """
    theDict = {}
    for key in varptr.ncattrs():
        if key.startswith('Instrument_'):
            n = key.find('_')
            newkey = tag + key[n + 1:]
        else:
            newkey = tag + key
        theDict[newkey] = varptr.getncattr(key)
    return theDict
