def writeDict2atts(cdfobj, d, tag):
    """
    write a dictionary to netCDF attributes

    :param cdfobj: netcdf file object
    :param dict d: dictionary of attribute names and values
    :param str tag: an identifier to prepend to the attribute name
    :return: the dictionary d with any strings that can be changed to numbers, as numbers
    """
    i = 0
    for key in iter(d):
        if type(d[key]) == str:
            try:
                d[key] = float(d[key])
            except ValueError:
                i += 1
    for key in iter(d):
        newkey = tag + key
        try:
            cdfobj.setncattr(newkey, d[key])
        except:
            print("can't set %s attribute" % key)
    return d
