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

    :param object cdfobj: netcdf file object
    :param dict d: metadata
    :param str tag: tag to add before each atrribute name
    :return: dict of metadata as written to file
    """
    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
