function C = set(C,F,V)
% SET Set fields of the object
    
% Jerod Weinman
% jerod@acm.org
    
% $Id: set.m 1 2009-05-07 13:41:00Z weinman $
 
% Jerod Weinman
% jerod@acm.org
% Copyright 2004, 2008, 2009
 
%    This file is part of Matlab GridCRF.
%
%    Matlab GridCRF 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.
%
%    Matlab GridCRF 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 Matlab GridCRF.  If not, see <http://www.gnu.org/licenses/>.

%  GCRF.SET
  
  switch F
   case 'numLabels'
	if floor(V)==ceil(V)
	  C.numLabels = V; % we probably shouldn't do this
	else
	  error('numStates must be an integer');
	end;
   case 'weights'
	if ~isa(V,'struct') | ~isfield(V,'node') | ...
		  ~isfield(V,'hEdge') | ...
		  ~isfield(V,'vEdge') | ...
		  (C.defEdge && ~isfield(V,'dhEdge')) | ...
		  (C.defEdge && ~isfield(V,'dvEdge')) | ...
		  any(size(V.node)~=size(C.weights.node)) | ...
		  any(size(V.hEdge)~=size(C.weights.hEdge)) | ...
		  any(size(V.vEdge)~=size(C.weights.vEdge)) | ...
		  (C.defEdge && any(size(V.dhEdge)~=size(C.weights.dhEdge))) | ...
		  (C.defEdge && any(size(V.dvEdge)~=size(C.weights.dvEdge))) 
	  
	  error(['weights must be a struct with fields appropriate' ...
			 ' fields of the proper sizes']);
	else
	  C.weights = V;
	end;
   case 'defEdge'
	if isscalar(V)
	  if V
		C.defEdge = 1;
	  else
		C.defEdge = 0;
	  end;
	else 
	  error('defEdge value must be scalar (boolean)');
	end;
   case 'isotropic'
	if isscalar(V)
	  if V
		C.isotropic = 1;
	  else
		C.isotropic = 0;
	  end;
	else 
	  error('isotropic value must be scalar (boolean)');
	end;
   case 'symmetric'
	if isscalar(V)
	  if V
		C.symmetric = 1;
	  else
		C.symmetric = 0;
	  end;
	else 
	  error('symmetric value must be scalar (boolean)');
	end;
	
   otherwise
	error(sprintf('Unknown field ''%s''',F));
  end;
  
