function M = card(F,N)
% CARD Cardinality of the factor domain
%
% M = CARD(F) returns the overall table dimensions
%
% M = CARD(F,N) returns the cardinality of variable N

% Jerod Weinman
% jerod@acm.org
    
% $Id: card.m 1 2009-06-17 20:04:43Z weinman $
 
% Jerod Weinman
% jerod@acm.org
% Copyright 2006, 2008, 2009, 2011
 
%    This file is part of VIDI.
%
%    VIDI is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    VIDI is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with VIDI.  If not, see <http://www.gnu.org/licenses/>.
  
  if length(F)>1
	error('Cardinality undefined for multiple factors');
  end;
  
  if nargin==2
	D = find(arguments(F)==N);
	
	if isempty(D)
	  error('Node %d is not a factor argument',N);
	end;

	if D~=F.wordnode
	  M = F.numLabels;
	else
	  M = 2;
	end;
	
  else
	
	M = [F.numLabels(1,ones(1,wordlen(F))) 2];
	
  end;
  
  
