def _check_n(fields, name, dim=0):
    """
    Check the field consistency
    Args:
        fields (list): a list of fields
        name (str): name to use when raising error
        dim (int): dimension for comparing

    Returns: int or None
    """
    n_candidates = []
    for i in fields:
        if i is not None:
            n_candidates.append(i.shape[dim])
    if len(n_candidates) > 0:
        if len(list(set(n_candidates))) > 1:
            raise ValueError(f"{name} inconsistent")
        return n_candidates[0]
    return None