def spec2nwbfields(spec):
    """Reads spec and determines __nwbfields__ which tells pynwb which attributes
    to write to disk

    Parameters
    ----------
    spec: dict

    Returns
    -------
    tuple of variable names

    """
    vars = [attrib.name for attrib in spec.attributes if attrib.name]
    if hasattr(spec, 'datasets'):
        vars += [dataset.name for dataset in spec.datasets if dataset.name]

    if hasattr(spec, 'groups'):
        for attrib in spec.groups:
            if attrib.name:
                if 'neurodata_type_inc' in attrib or 'neurodata_type_def' in attrib:
                    vars.append({'name': attrib.name, 'child': True})
                else:
                    vars.append(attrib.name)

    return tuple(vars)