Index: /issm/trunk/src/m/classes/constants.m
===================================================================
--- /issm/trunk/src/m/classes/constants.m	(revision 9729)
+++ /issm/trunk/src/m/classes/constants.m	(revision 9730)
@@ -45,4 +45,7 @@
 
 		end % }}}
+		function flag = checkconsistency(obj,md) % {{{
+
+		end % }}}
 	end
 end
Index: /issm/trunk/src/m/classes/mesh.m
===================================================================
--- /issm/trunk/src/m/classes/mesh.m	(revision 9729)
+++ /issm/trunk/src/m/classes/mesh.m	(revision 9730)
@@ -65,4 +65,10 @@
 			obj.average_vertex_connectivity=25;
 		end % }}}
+		function checkconsistency(obj,md) % {{{
+
+			fields={'dimension'};
+			checkgreaterstrict(md,'mesh',fields,0);
+
+		end % }}}
 		function disp(obj) % {{{
 			disp(sprintf('   Mesh:')); 
Index: /issm/trunk/src/m/model/ismodelselfconsistent.m
===================================================================
--- /issm/trunk/src/m/model/ismodelselfconsistent.m	(revision 9729)
+++ /issm/trunk/src/m/model/ismodelselfconsistent.m	(revision 9730)
@@ -5,3 +5,12 @@
 %      ismodelselfconsistent(md),
 
-%nothing for now
+%initialize consistency as true
+modelconsistency(true);
+
+%Always check mesh
+md.mesh.checkconsistency(md);
+
+%error message if mode is not consistent
+if modelconsistency==false,
+	error(' ');
+end
Index: /issm/trunk/src/m/utils/consistency/checkforcing.m
===================================================================
--- /issm/trunk/src/m/utils/consistency/checkforcing.m	(revision 9730)
+++ /issm/trunk/src/m/utils/consistency/checkforcing.m	(revision 9730)
@@ -0,0 +1,25 @@
+function checkforcing(md,obj,fields)
+%CHECKFORCING - checkforcing
+%
+%   Used to check model consistency
+%
+%   Usage:
+%      checkforcing(md,obj,fields);
+
+for i=1:length(fields),
+	eval(['field=md.' obj '.' fields{i} ';']);
+	if size(field,1)==md.mesh.numberofvertices,
+		if ~size(field,2)==1,
+			checkmessage(['model not consistent: field ''' obj '.' fields{i} ''' should have only one column as there are md.mesh.numberofvertices lines']);
+		end
+	elseif size(field,1)==md.mesh.numberofvertices+1
+		if any(field(end,:)~=sort(field(end,:))),
+			checkmessage(['model not consistent: field ''' obj '.' fields{i} ''' columns should be chronological']);
+		end
+		if any(field(end,1:end-1)==field(end,2:end)),
+			checkmessage(['model not consistent: field ''' obj '.' fields{i} ''' columns must not contain duplicate timesteps']);
+		end
+	else
+		checkmessage(['model not consistent: field ''' obj '.' fields{i} ''' should have md.mesh.numberofvertices or md.mesh.numberofvertices+1 lines']);
+	end
+end
Index: /issm/trunk/src/m/utils/consistency/checkgreater.m
===================================================================
--- /issm/trunk/src/m/utils/consistency/checkgreater.m	(revision 9730)
+++ /issm/trunk/src/m/utils/consistency/checkgreater.m	(revision 9730)
@@ -0,0 +1,14 @@
+function checkgreater(md,obj,fields,lowerbound)
+%CHECKGREATER - checkgreater
+%
+%   Used to check model consistency
+%
+%   Usage:
+%      checkgreater(md,obj,field);
+
+for i=1:length(fields),
+	eval(['field=md.' obj '.' fields{i} ';']);
+	if any(field<lowerbound),
+		checkmessage(['model not consistent: field ''' obj '.' fields{i} ''' should have values above ' num2str(lowerbound)]);
+	end
+end
Index: /issm/trunk/src/m/utils/consistency/checkgreaterstrict.m
===================================================================
--- /issm/trunk/src/m/utils/consistency/checkgreaterstrict.m	(revision 9730)
+++ /issm/trunk/src/m/utils/consistency/checkgreaterstrict.m	(revision 9730)
@@ -0,0 +1,14 @@
+function checkgreaterstrict(md,obj,fields,lowerbound)
+%CHECKGREATERSTRICT - checkgreaterstrict
+%
+%   Used to check model consistency
+%
+%   Usage:
+%      checkgreaterstrict(md,obj,field);
+
+for i=1:length(fields),
+	eval(['field=md.' obj '.' fields{i} ';']);
+	if any(field<=lowerbound),
+		checkmessage(['model not consistent: field ''' obj '.' fields{i} ''' should have values stricly above ' num2str(lowerbound)]);
+	end
+end
Index: /issm/trunk/src/m/utils/consistency/checklength.m
===================================================================
--- /issm/trunk/src/m/utils/consistency/checklength.m	(revision 9730)
+++ /issm/trunk/src/m/utils/consistency/checklength.m	(revision 9730)
@@ -0,0 +1,14 @@
+function checklength(md,obj,fields,fieldlength)
+%CHECKLENGTH - checklength
+%
+%   Used to check model consistency
+%
+%   Usage:
+%      checklength(md,obj,field);
+
+for i=1:length(fields),
+	eval(['field=md.' obj '.' fields{i} ';']);
+	if length(field)~=fieldlength,
+		checkmessage(['model not consistent: field ''' obj '.' fields{i} ''' length should be ' num2str(fieldlength)]);
+	end
+end
Index: /issm/trunk/src/m/utils/consistency/checkless.m
===================================================================
--- /issm/trunk/src/m/utils/consistency/checkless.m	(revision 9730)
+++ /issm/trunk/src/m/utils/consistency/checkless.m	(revision 9730)
@@ -0,0 +1,14 @@
+function checkless(md,obj,fields,upperbound)
+%CHECKLESS - checkless
+%
+%   Used to check model consistency
+%
+%   Usage:
+%      checkless(md,obj,field);
+
+for i=1:length(fields),
+	eval(['field=md.' obj '.' fields{i} ';']);
+	if any(field>upperbound),
+		checkmessage(['model not consistent: field ''' obj '.' fields{i} ''' should have values below ' num2str(upperbound)]);
+	end
+end
Index: /issm/trunk/src/m/utils/consistency/checklessstrict.m
===================================================================
--- /issm/trunk/src/m/utils/consistency/checklessstrict.m	(revision 9730)
+++ /issm/trunk/src/m/utils/consistency/checklessstrict.m	(revision 9730)
@@ -0,0 +1,14 @@
+function checklessstrict(md,obj,fields,upperbound)
+%CHECKLESSSTRICT - checklessstrict
+%
+%   Used to check model consistency
+%
+%   Usage:
+%      checklessstrict(md,obj,field);
+
+for i=1:length(fields),
+	eval(['field=md.' obj '.' fields{i} ';']);
+	if any(field>=upperbound),
+		checkmessage(['model not consistent: field ''' obj '.' fields{i} ''' should have values stricly below ' num2str(upperbound)]);
+	end
+end
Index: /issm/trunk/src/m/utils/consistency/checkmessage.m
===================================================================
--- /issm/trunk/src/m/utils/consistency/checkmessage.m	(revision 9730)
+++ /issm/trunk/src/m/utils/consistency/checkmessage.m	(revision 9730)
@@ -0,0 +1,10 @@
+function checkmessage(string)
+%CHECKMESSAGE - checkmessage
+%
+%   Used to check model consistency
+%
+%   Usage:
+%      checkmessage(string);
+
+disp(string);
+modelconsistency(false);
Index: /issm/trunk/src/m/utils/consistency/checknan.m
===================================================================
--- /issm/trunk/src/m/utils/consistency/checknan.m	(revision 9730)
+++ /issm/trunk/src/m/utils/consistency/checknan.m	(revision 9730)
@@ -0,0 +1,14 @@
+function checknan(md,obj,fields)
+%CHECKNAN - checknan
+%
+%   Used to check model consistency
+%
+%   Usage:
+%      checknan(md,obj,field);
+
+for i=1:length(fields),
+	eval(['field=md.' obj '.' fields{i} ';']);
+	if any(isnan(field)),
+		checkmessage(['model not consistent: NaN values found in field ''' obj '.' fields{i}'''']);
+	end
+end
Index: /issm/trunk/src/m/utils/consistency/checkreal.m
===================================================================
--- /issm/trunk/src/m/utils/consistency/checkreal.m	(revision 9730)
+++ /issm/trunk/src/m/utils/consistency/checkreal.m	(revision 9730)
@@ -0,0 +1,14 @@
+function checkreal(md,obj,fields)
+%CHECKREAL - checkreal
+%
+%   Used to check model consistency
+%
+%   Usage:
+%      checkreal(md,obj,field);
+
+for i=1:length(fields),
+	eval(['field=md.' obj '.' fields{i} ';']);
+	if any(~isreal(field))
+		checkmessage(['model not consistent: complex values found in field ''' obj '.' fields{i}'''']);
+	end
+end
Index: /issm/trunk/src/m/utils/consistency/checksize.m
===================================================================
--- /issm/trunk/src/m/utils/consistency/checksize.m	(revision 9730)
+++ /issm/trunk/src/m/utils/consistency/checksize.m	(revision 9730)
@@ -0,0 +1,24 @@
+function checksize(md,obj,fields,fieldsize)
+%CHECKSIZE - checksize
+%
+%   Used to check model consistency
+%
+%   Usage:
+%      checksize(md,obj,field);
+
+for i=1:length(fields),
+	eval(['field=md.' obj '.' fields{i} ';']);
+	if isnan(fieldsize(1)),
+		if (size(field,2)~=fieldsize(2)),
+			checkmessage(['model not consistent: field ''' obj '.' fields{i} ''' should have ' num2str(fieldsize(2)) ' columns']);
+		end
+	elseif isnan(fieldsize(2)),
+		if (size(field,1)~=fieldsize(1)),
+			checkmessage(['model not consistent: field ''' obj '.' fields{i} ''' should have ' num2str(fieldsize(1)) ' rows']);
+		end
+	else
+		if ((size(field)~=fieldsize(1)) |  (size(field,2)~=fieldsize(2)))
+			checkmessage(['model not consistent: field ''' obj '.' fields{i} ''' size should be ' num2str(fieldsize(1)) ' x ' num2str(fieldsize(2))]);
+		end
+	end
+end
Index: /issm/trunk/src/m/utils/consistency/checkvalues.m
===================================================================
--- /issm/trunk/src/m/utils/consistency/checkvalues.m	(revision 9730)
+++ /issm/trunk/src/m/utils/consistency/checkvalues.m	(revision 9730)
@@ -0,0 +1,14 @@
+function checkvalues(md,obj,fields,values)
+%CHECKVALUES - checkvalues
+%
+%   Used to check model consistency
+%
+%   Usage:
+%      checkvalues(md,obj,field);
+
+for i=1:length(fields),
+	eval(['field=md.' obj '.' fields{i} ';']);
+	if any(~ismember(field,values)),
+		checkmessage(['model not consistent: field ''' obj '.' fields{i} ''' should have values in ' num2str(values)]);
+	end
+end
Index: /issm/trunk/src/m/utils/consistency/modelconsistency.m
===================================================================
--- /issm/trunk/src/m/utils/consistency/modelconsistency.m	(revision 9730)
+++ /issm/trunk/src/m/utils/consistency/modelconsistency.m	(revision 9730)
@@ -0,0 +1,23 @@
+function flag=modelconsistency(flag_in)
+%MODELCONSISTENCY - return flag for model consistency
+%
+%   Used to check model consistency
+%
+%   Usage:
+%      flag=modelconsistency(flag_in)
+
+persistent consistency;
+
+if nargin==1 & nargout==0,
+	%OK model is inconsistent, set flag as false
+	consistency=flag_in;
+elseif nargin==0 & nargout==1,
+	if isempty(consistency),
+		%modelinconsistent has never been called, model is consistent
+		consistency=true;
+	end
+else
+	message('Bad usage');
+end
+
+flag=consistency;
Index: sm/trunk/src/m/utils/genpath_ice.m
===================================================================
--- /issm/trunk/src/m/utils/genpath_ice.m	(revision 9729)
+++ 	(revision )
@@ -1,38 +1,0 @@
-function p = genpath_ice(d)
-%GENPATH_ICE - generate paths in a directory
-%
-%   this routine is equivalent to Matlab's genpath except that it skips CVS and .svn directories
-%
-%   Usage:
-%      p = genpath_ice(d)
-
-%initialize path to be returned
-p = '';
-sep=pathsep;  %directory separator
-
-% Generate path based on given root directory
-files=dir(d);
-if isempty(files)
-	return
-end
-
-% Add d to the path even if it is empty.
-p = [p d sep];
-
-% set logical vector for subdirectory entries in d
-isdir = logical(cat(1,files.isdir));
-
-% Recursively goes through the subdirectories of d
-dirs=files(isdir); % select only directory entries from the current listing
-for i=1:length(dirs)
-	dirname=dirs(i).name;
-	if ~strcmp(dirname,'.')    & ...
-		~strcmp(dirname,'..')   & ...
-		~strcmp(dirname,'.svn') & ...
-		~strcmp(dirname,'CVS')  & ...
-		~strncmp(dirname,'@',1) & ... %Method directories not allowed in MATLAB path
-		~strcmp(dirname,'private')    %private directories not allowed in MATLAB path
-
-		p = [p genpath_ice(fullfile(d,dirname))];
-	end
-end
Index: /issm/trunk/src/m/utils/recursivepath.m
===================================================================
--- /issm/trunk/src/m/utils/recursivepath.m	(revision 9730)
+++ /issm/trunk/src/m/utils/recursivepath.m	(revision 9730)
@@ -0,0 +1,38 @@
+function p = recursivepath(d)
+%RECURSIVEPATH - generate paths in a directory
+%
+%   this routine is equivalent to Matlab's genpath except that it skips CVS and .svn directories
+%
+%   Usage:
+%      p = recursivepath(d)
+
+%initialize path to be returned
+p = '';
+sep=pathsep;  %directory separator
+
+% Generate path based on given root directory
+files=dir(d);
+if isempty(files)
+	return
+end
+
+% Add d to the path even if it is empty.
+p = [p d sep];
+
+% set logical vector for subdirectory entries in d
+isdir = logical(cat(1,files.isdir));
+
+% Recursively goes through the subdirectories of d
+dirs=files(isdir); % select only directory entries from the current listing
+for i=1:length(dirs)
+	dirname=dirs(i).name;
+	if ~strcmp(dirname,'.')    & ...
+		~strcmp(dirname,'..')   & ...
+		~strcmp(dirname,'.svn') & ...
+		~strcmp(dirname,'CVS')  & ...
+		~strncmp(dirname,'@',1) & ... %Method directories not allowed in MATLAB path
+		~strcmp(dirname,'private')    %private directories not allowed in MATLAB path
+
+		p = [p recursivepath(fullfile(d,dirname))];
+	end
+end
Index: /issm/trunk/startup.m
===================================================================
--- /issm/trunk/startup.m	(revision 9729)
+++ /issm/trunk/startup.m	(revision 9730)
@@ -24,13 +24,13 @@
 
 %ISSM path
-addpath([ISSM_TIER '/src/m/utils/']); %loads genpath_ice
+addpath([ISSM_TIER '/src/m/utils/']); %loads recursivepath
 addpath([ISSM_TIER '/doc']);
 addpath([ISSM_TIER '/bin']);
-addpath(genpath_ice([ISSM_TIER '/src/m']));
-addpath(genpath_ice([ISSM_TIER '/externalpackages/scotch']));
-addpath(genpath_ice([ISSM_TIER '/externalpackages/canos']));
-addpath(genpath_ice([ISSM_TIER '/externalpackages/kml']));
-addpath(genpath_ice([ISSM_TIER '/externalpackages/googleearthtoolbox/']));
-addpath(genpath_ice([ISSM_TIER '/externalpackages/export_fig']));
+addpath(recursivepath([ISSM_TIER '/src/m']));
+addpath(recursivepath([ISSM_TIER '/externalpackages/scotch']));
+addpath(recursivepath([ISSM_TIER '/externalpackages/canos']));
+addpath(recursivepath([ISSM_TIER '/externalpackages/kml']));
+addpath(recursivepath([ISSM_TIER '/externalpackages/googleearthtoolbox/']));
+addpath(recursivepath([ISSM_TIER '/externalpackages/export_fig']));
 
 %Check on any warning messages that might indicate that the paths were not correct. 
@@ -57,7 +57,7 @@
 
 %Now, load personal startup preferences, using the local user name: 
-rmpath(genpath_ice([ISSM_TIER '/src/m/usr']));
+rmpath(recursivepath([ISSM_TIER '/src/m/usr']));
 if exist([ISSM_TIER '/src/m/usr/' USERNAME],'dir'),
-	addpath(genpath_ice([ISSM_TIER '/src/m/usr/' USERNAME]));
+	addpath(recursivepath([ISSM_TIER '/src/m/usr/' USERNAME]));
 end
 
