def _add_time_variable(root, time, **kwds):
    """Add a time value to a NetCDF file.

    Append a new time value to the time variable of a NetCDF file. If there
    is not time variable, create one. The time variable is named, ``t``.

    Parameters
    ----------
    root : netcdf_file
        A NetCDF file.
    time : float
        The time.
    units : str, optional
        Time units.
    reference : str, optional
        Reference time.
    """
    units = kwds.get('units', 'days')
    reference = kwds.get('reference', '00:00:00 UTC')
    netcdf_vars = root.variables
    try:
        time_var = netcdf_vars['t']
    except KeyError:
        time_var = root.createVariable('t', 'f8', ('nt',))
        time_var.units = ' '.join([units, 'since', reference])
        time_var.long_name = 'time'
    try:
        n_times = len(time_var)
    except TypeError:
        n_times = len(time_var[:])
    if time is not None:
        time_var[n_times] = time
    else:
        time_var[n_times] = n_times
