Index: /issm/trunk/src/m/utils/Nightly/runme.m
===================================================================
--- /issm/trunk/src/m/utils/Nightly/runme.m	(revision 2132)
+++ /issm/trunk/src/m/utils/Nightly/runme.m	(revision 2133)
@@ -24,7 +24,4 @@
 % free to tweak the tolerance variable.
 
-%recover options
-options=recover_options(varargin{:});
-
 %check arguments
 if nargout>1
@@ -33,152 +30,6 @@
 end
 
-%warning if a runme already exists:
-if exist('./runme.m')
-	disp('this is the nighlty run runme, located in src/m/utils/Nightly/runme.m')
-	disp('Another local runme exist but is not executed')
-end
-
-%read configuration
-configuration;
-
-%packages and analysis_types to be tested
-if nargin==2,
-	solutions=varargin{2};
-end
-
-if nargin,
-	packages=varargin{1};
-end
-
-%go through the sequences requested.
-for i=1:size(sequences,1),
-	sequence=sequences{i};
-
-	%recover what is being requested.
-	analysis_type=sequence{1};
-	sub_analysis_type=sequence{2};
-	qmu=sequence{3};
-	control=sequence{4};
-	control_fit=sequence{5};
-	parallel=sequence{6};
-
-	%CHECK analysis_type
-	analysis_type_arg=find_option(options,'analysis_type');
-	if ~isempty(analysis_type_arg),
-		if ~ismember(analysis_type,analysis_type_arg)
-			continue
-		end
-	end
-
-	%CHECK sub_analysis_type
-	sub_analysis_type_arg=find_option(options,'sub_analysis_type');
-	if ~isempty(sub_analysis_type_arg),
-		if ~ismember(sub_analysis_type,sub_analysis_type_arg)
-			continue
-		end
-	end
-
-	%CHECK parallel
-	parallel_arg=find_option(options,'parallel');
-	if ~isempty(parallel_arg),
-		if parallel~=parallel_arg,
-			continue
-		end
-	end
-
-	%initialize model, using presolve if need be, or just the piece of generic code below.
-	md=model;
-	if ~rifts,
-		md=mesh(md,domainname,resolution);
-	else
-		md=mesh(md,domainname,riftoutline,resolution);
-		md=meshprocessrifts(md);
-	end
-	md=geography(md,iceshelfname,icesheetname);
-	md=parameterize(md,parametername);
-	md=extrude(md,numlayers,extrusionexponent);
-	eval(['md=setelementstype(md,' elementstype ');']);
-
-	if parallel, 
-		%this run will be done in parallel
-		md.cluster=oshostname;
-		%check and modify number of cpus if necessary
-		np=feature('numCores');
-		if np<md.np;
-			disp(['warning: changing number of cpus to ' num2str(np) ]);
-			md.np=np;
-		end
-		runtype='parallel';
-	else
-		runtype='serial';
-	end
-
-	%some solution checks;
-	if (  (strcmpi(analysis_type,'thermal') & strcmpi(sub_analysis_type,'steady')) | ...
-			(strcmpi(analysis_type,'steadystate'))...
-		)
-		md.dt=0;
-	end
-
-	if control,
-		md.control_analysis=1;
-		if strcmpi(control_fit,'absolute'),
-			md.fit(:)=0;
-		elseif strcmpi(control_fit,'relative'),
-			md.fit(:)=1;
-		elseif strcmpi(control_fit,'logarithmic'),
-			md.fit(:)=2;
-		else
-			error(['runme error message: for control solution, ' control_fit ' fit is not supported!']);
-		end
-	end
-	
-	%try to run the test
-	try,
-
-		%presolve
-		if exist('./testpresolve.m','file')==2,
-			testpresolve;
-		end
-
-		%solve
-		md=solve(md,'analysis_type',analysis_type,'sub_analysis_type',sub_analysis_type);
-
-		%postsolve
-		if exist('./testpostsolve.m','file')==2,
-			testpostsolve;
-		end
-
-		%compute fields to be checked
-		fields=testsgetfields2(md,sequence);
-
-		%load archive
-		eval(['load Archive_'  analysis_type '_' sub_analysis_type '_' runtype ]);
-
-		for k=1:length(fields),
-
-			%Get field and tolerance
-			field=fields{k};
-			tolerance=testsgettolerance2(md,sequence);
-
-			%compare to archive
-			eval(['Archive=Archive_'  analysis_type '_' sub_analysis_type '_' runtype '_field' num2str(k) ';']);
-			eval(['error_diff=full(max(abs(Archive-md.results.' field '))/(max(abs(Archive))+eps));']);
-
-			%disp test result
-			if (error_diff>tolerance);
-				disp(sprintf(['\nERROR   difference: %-7.2g > %7.2g test: %-25s solution: %-16s type: %-9s field: ' field  '.\n\n'],error_diff,tolerance,testname,[analysis_type '_' sub_analysis_type],runtype));
-			else
-				disp(sprintf(['\nSUCCESS difference: %-7.2g < %7.2g test: %-25s solution: %-16s type: %-9s field: ' field  '.\n\n'],error_diff,tolerance,testname,[analysis_type '_' sub_analysis_type],runtype));
-			end
-		end
-
-	catch me,
-
-		%something went wrong, print failure message:
-		message=getReport(me)
-		disp(sprintf(['\n\nFAILURE difference: %-16s test: %-25s solution: %-16s type: %-9s field: ' field  '.\n\n'],'N/A',testname,[analysis_type '_' sub_analysis_type],runtype));
-	end
-end
+%call runme_core
+md=runme_core('check',varargin{:});
 
 %output model md if requested
Index: /issm/trunk/src/m/utils/Nightly/runme_core.m
===================================================================
--- /issm/trunk/src/m/utils/Nightly/runme_core.m	(revision 2133)
+++ /issm/trunk/src/m/utils/Nightly/runme_core.m	(revision 2133)
@@ -0,0 +1,191 @@
+function md=runme_core(testtype,varargin)
+%RUNME_CORE - test deck for ISSM nightly runs
+%
+%   Usage:
+%      md=runme_core(varargin,testtype);
+%
+%   Examples:
+%      md=runme_core('parallel',1,'update');
+%
+%   See Also: UPDATEARCHIVE RUNME
+
+% This file can be run to check that the current version of issm is giving 
+% coherent results. This test deals with an icesheet without icefront for a 2d model. The geometry 
+% is square. Just run this file in Matlab, with a properly setup ISSM code. 
+% The results of this test will indicate if there is a difference between current computations 
+% and archived results.
+
+% Errors  between archived results and the current version will get flagged if they are not within 
+% a certain tolerance. The current tolerance is 10^-12. If you have good reasons to believe this 
+% tolerance should be lowered (for example, if you are running single precision compilers?), feel 
+% free to tweak the tolerance variable.
+
+%recover options
+options=recover_options(varargin{:});
+
+%check arguments
+if nargout~=1
+	help runme_core
+	error('runme_core error message: bad usage');
+end
+
+%warning if a runme_core already exists:
+if exist('./runme.m')
+	disp('this is the nighlty run runme_core, located in src/m/utils/Nightly/runme_core.m')
+	disp('Another local runme exist but is not executed')
+end
+
+%read configuration
+configuration;
+
+%go through the sequences requested.
+for i=1:size(sequences,1),
+	sequence=sequences{i};
+
+	%recover what is being requested.
+	analysis_type=sequence{1};
+	sub_analysis_type=sequence{2};
+	qmu=sequence{3};
+	control=sequence{4};
+	control_fit=sequence{5};
+	parallel=sequence{6};
+
+	%CHECK analysis_type
+	analysis_type_arg=find_option(options,'analysis_type');
+	if ~isempty(analysis_type_arg),
+		if ~ismember(analysis_type,analysis_type_arg)
+			continue
+		end
+	end
+
+	%CHECK sub_analysis_type
+	sub_analysis_type_arg=find_option(options,'sub_analysis_type');
+	if ~isempty(sub_analysis_type_arg),
+		if ~ismember(sub_analysis_type,sub_analysis_type_arg)
+			continue
+		end
+	end
+
+	%CHECK parallel
+	parallel_arg=find_option(options,'parallel');
+	if ~isempty(parallel_arg),
+		if parallel~=parallel_arg,
+			continue
+		end
+	end
+
+	%initialize model, using presolve if need be, or just the piece of generic code below.
+	md=model;
+	if ~rifts,
+		md=mesh(md,domainname,resolution);
+	else
+		md=mesh(md,domainname,riftoutline,resolution);
+		md=meshprocessrifts(md);
+	end
+	md=geography(md,iceshelfname,icesheetname);
+	md=parameterize(md,parametername);
+	md=extrude(md,numlayers,extrusionexponent);
+	eval(['md=setelementstype(md,' elementstype ');']);
+
+	if parallel, 
+		%this run will be done in parallel
+		md.cluster=oshostname;
+		%check and modify number of cpus if necessary
+		np=feature('numCores');
+		if np<md.np;
+			disp(['warning: changing number of cpus to ' num2str(np) ]);
+			md.np=np;
+		end
+		runtype='parallel';
+	else
+		runtype='serial';
+	end
+
+	%some solution checks;
+	if (  (strcmpi(analysis_type,'thermal') & strcmpi(sub_analysis_type,'steady')) | ...
+			(strcmpi(analysis_type,'steadystate'))...
+		)
+		md.dt=0;
+	end
+
+	if control,
+		md.control_analysis=1;
+		if strcmpi(control_fit,'absolute'),
+			md.fit(:)=0;
+		elseif strcmpi(control_fit,'relative'),
+			md.fit(:)=1;
+		elseif strcmpi(control_fit,'logarithmic'),
+			md.fit(:)=2;
+		else
+			error(['runme_core error message: for control solution, ' control_fit ' fit is not supported!']);
+		end
+	end
+
+	%try to run the test
+	try,
+
+		%presolve
+		if exist('./testpresolve.m','file')==2,
+			testpresolve;
+		end
+
+		%solve
+		md=solve(md,'analysis_type',analysis_type,'sub_analysis_type',sub_analysis_type);
+
+		%postsolve
+		if exist('./testpostsolve.m','file')==2,
+			testpostsolve;
+		end
+
+		%compute fields to be checked
+		fields=testsgetfields2(md,sequence);
+
+		%CHECK TEST?
+		if strcmpi(testtype,'check'),
+
+			%load archive
+			eval(['load Archive_'  analysis_type '_' sub_analysis_type '_' runtype ]);
+
+			for k=1:length(fields),
+
+				%Get field and tolerance
+				field=fields{k};
+				tolerance=testsgettolerance2(md,sequence,field);
+
+				%compare to archive
+				eval(['Archive=Archive_'  analysis_type '_' sub_analysis_type '_' runtype '_field' num2str(k) ';']);
+				eval(['error_diff=full(max(abs(Archive-md.results.' field '))/(max(abs(Archive))+eps));']);
+
+				%disp test result
+				if (error_diff>tolerance);
+					disp(sprintf(['\nERROR   difference: %-7.2g > %7.2g test: %-25s solution: %-16s type: %-9s field: ' field  '.\n\n'],error_diff,tolerance,testname,[analysis_type '_' sub_analysis_type],runtype));
+				else
+					disp(sprintf(['\nSUCCESS difference: %-7.2g < %7.2g test: %-25s solution: %-16s type: %-9s field: ' field  '.\n\n'],error_diff,tolerance,testname,[analysis_type '_' sub_analysis_type],runtype));
+				end
+			end
+
+
+
+		%UPDATE ARCHIVE?
+		elseif strcmpi(testtype,'update'),
+
+			for k=1:length(fields),
+				field=fields{k};
+				eval(['Archive_'  analysis_type '_' sub_analysis_type '_' runtype '_field' num2str(k) ' = md.results. ' field  ';']);
+			end
+			eval(['save Archive_'  analysis_type '_' sub_analysis_type '_' runtype ' Archive_'  analysis_type '_' sub_analysis_type '_' runtype '_field*']);
+			disp(sprintf(['File Archive_'  analysis_type '_' sub_analysis_type '_' runtype ' saved\n']));
+
+		else
+
+			error('runme_core error message: unknown runtype. should be ''check'' or ''update''');
+
+		end
+
+	catch me,
+
+		%something went wrong, print failure message:
+		message=getReport(me)
+		disp(sprintf(['\n\nFAILURE difference: %-16s test: %-25s solution: %-16s type: %-9s field: ' field  '.\n\n'],'N/A',testname,[analysis_type '_' sub_analysis_type],runtype));
+	end
+end
Index: /issm/trunk/src/m/utils/Nightly/testsgetfields2.m
===================================================================
--- /issm/trunk/src/m/utils/Nightly/testsgetfields2.m	(revision 2133)
+++ /issm/trunk/src/m/utils/Nightly/testsgetfields2.m	(revision 2133)
@@ -0,0 +1,58 @@
+function fields=testsgetfields2(md,sequence),
+%TESTSGETFIELDS - build the fields to be checked from a analysis
+%
+%   This routine is used by nightly runs (runme.m and updatearchive.m).
+%   for an input analysis 'prognostic', it will output 'cielo'
+%
+%   Usage:
+%      fields=testsgetfields(md,analysis)
+%
+%   Example:
+%      fields=testsgetfields(md,'diagnostic')
+%
+%   See also: TESTSGETANALYSIS, TESTGETPACKAGE
+
+%recover what is being requested.
+analysis_type=sequence{1};
+sub_analysis_type=sequence{2};
+qmu=sequence{3};
+control=sequence{4};
+control_fit=sequence{5};
+parallel=sequence{6};
+
+if strcmpi(analysis_type,'diagnostic'),
+	if control,
+		fields={'diagnostic.vel','diagnostic.J','diagnostic.parameter'};
+	elseif qmu,
+		fields={'dakota.importancefactors'};
+	else
+		if strcmpi(md.type,'3d')
+			fields={'diagnostic.vy','diagnostic.vz'};
+		else
+			fields={'diagnostic.vel'};
+		end
+	end
+
+elseif strcmpi(analysis_type,'thermal'),
+	fields={'thermal(end).temperature','thermal(end).melting'};
+
+elseif strcmpi(analysis_type,'prognostic'),
+	fields={'prognostic.thickness'};
+
+elseif strcmpi(analysis_type,'transient'), 
+	if strcmpi(md.type,'3d')
+		fields={'transient(end).vel','transient(end).pressure','transient(end).temperature','transient(end).melting','transient(end).thickness','transient(end).surface','transient(end).bed'};
+	else
+		fields={'transient(end).vel','transient(end).thickness','transient(end).surface','transient(end).bed'};
+	end
+
+elseif strcmpi(analysis_type,'steadystate'), 
+	if control,
+		fields={'steadystate.vel','steadystate.J','steadystate.parameter'};
+	else
+		fields={'steadystate.vel','steadystate.pressure','steadystate.temperature'};
+	end
+
+else
+	error(['testsgetfields error message: requested sequence not supported yet']);
+end
Index: /issm/trunk/src/m/utils/Nightly/testsgettolerance2.m
===================================================================
--- /issm/trunk/src/m/utils/Nightly/testsgettolerance2.m	(revision 2133)
+++ /issm/trunk/src/m/utils/Nightly/testsgettolerance2.m	(revision 2133)
@@ -0,0 +1,73 @@
+function tolerance=testsgettolerance2(md,sequence,field),
+%TESTSGETTOLERANCE - give the tolerance for the nightly run 
+%
+%   This routine is used by nightly runs (runme.m and updatearchive.m).
+%   It gives the accepted tolerance, given the package, the analysis_type and the field check.
+%
+%   Usage:
+%      tolerance=testsgettolerance2(md,package,analysis_type,field),
+%
+%   Example:
+%      tolerance=testsgettolerance2(md,'cielo','diagnostic','vel'),
+%
+%   See also: TESTSGETANALYSIS, TESTGETPACKAGE
+
+%recover what is being requested.
+analysis_type=sequence{1};
+sub_analysis_type=sequence{2};
+qmu=sequence{3};
+control=sequence{4};
+control_fit=sequence{5};
+parallel=sequence{6};
+
+if ~parallel,
+	tolerance=10^-12;
+
+else
+	if strcmpi(analysis_type,'prognostic'),
+		tolerance=10^-14;
+
+	elseif strcmpi(analysis_type,'transient'),
+		if strcmpi(md.type,'2d'),
+			tolerance=10^-11;
+		else
+			if md.isstokes,
+				tolerance=10^-4;
+			elseif any(md.gridonpattyn),
+				tolerance=10^-6;
+			else,
+				tolerance=10^-12;
+			end
+		end
+
+	elseif strcmpi(analysis_type,'diagnostic'),
+		if md.isstokes,
+			tolerance=10^-4;
+		elseif any(md.gridonpattyn),
+			tolerance=10^-6;
+		elseif ~isnans(md.rifts),
+			tolerance=10^-10;
+		else,
+			tolerance=10^-13;
+		end
+
+	elseif strcmpi(analysis_type,'thermal'),
+		if strncmpi(fliplr(field),fliplr('melting'),7),
+			tolerance=10^-6;
+		elseif strncmpi(fliplr(field),fliplr('temperature'),11),
+			tolerance=10^-11;
+		end
+
+	elseif (strcmpi(analysis_type,'steadystate')),
+			if md.isstokes,
+				tolerance=5*10^-5;
+			elseif any(md.gridonpattyn),
+				tolerance=2*10^-8;
+			else,
+				tolerance=10^-10;
+			end
+
+	else
+		error(['testsgettolerance2 error message: analysis_type '  analysis_type ' not supported yet with package cielo_parallel']);
+	end
+end
Index: /issm/trunk/src/m/utils/Nightly/updatearchive.m
===================================================================
--- /issm/trunk/src/m/utils/Nightly/updatearchive.m	(revision 2132)
+++ /issm/trunk/src/m/utils/Nightly/updatearchive.m	(revision 2133)
@@ -25,144 +25,11 @@
 
 %check arguments
-if (nargin>2 | nargout>1)
+if nargout>1
 	help updatearchive
 	error('updatearchive error message: bad usage');
 end
 
-%warning if a updatearchive already exists:
-if exist('./updatearchive.m')
-	disp('this is the nighlty run updatearchive, located in src/m/utils/Nightly/updatearchive.m')
-	disp('Another local updatearchive exist but is not executed')
-end
-
-%recover options
-options=recover_options(varargin{:});
-
-%read configuration
-configuration;
-
-%packages and analysis_types to be tested
-if nargin==2,
-	solutions=varargin{2};
-end
-
-if nargin,
-	packages=varargin{1};
-end
-
-%go through the sequences requested.
-for i=1:size(sequences,1),
-	sequence=sequences{i};
-
-	%recover what is being requested.
-	analysis_type=sequence{1};
-	sub_analysis_type=sequence{2};
-	qmu=sequence{3};
-	control=sequence{4};
-	control_fit=sequence{5};
-	parallel=sequence{6};
-
-	%CHECK analysis_type
-	analysis_type_arg=find_option(options,'analysis_type');
-	if ~isempty(analysis_type_arg),
-		if ~ismember(analysis_type,analysis_type_arg)
-			continue
-		end
-	end
-
-	%CHECK sub_analysis_type
-	sub_analysis_type_arg=find_option(options,'sub_analysis_type');
-	if ~isempty(sub_analysis_type_arg),
-		if ~ismember(sub_analysis_type,sub_analysis_type_arg)
-			continue
-		end
-	end
-
-	%CHECK parallel
-	parallel_arg=find_option(options,'parallel');
-	if ~isempty(parallel_arg),
-		if parallel~=parallel_arg,
-			continue
-		end
-	end
-
-	%initialize model, using presolve if need be, or just the piece of generic code below.
-	md=model;
-	if ~rifts,
-		md=mesh(md,domainname,resolution);
-	else
-		md=mesh(md,domainname,riftoutline,resolution);
-		md=meshprocessrifts(md);
-	end
-	md=geography(md,iceshelfname,icesheetname);
-	md=parameterize(md,parametername);
-	md=extrude(md,numlayers,extrusionexponent);
-	eval(['md=setelementstype(md,' elementstype ');']);
-
-	if parallel, 
-		%this run will be done in parallel
-		md.cluster=oshostname;
-		%check and modify number of cpus if necessary
-		np=feature('numCores');
-		if np<md.np;
-			disp(['warning: changing number of cpus to ' num2str(np) ]);
-			md.np=np;
-		end
-		runtype='parallel';
-	else
-		runtype='serial';
-	end
-
-	%some solution checks;
-	if (  (strcmpi(analysis_type,'thermal') & strcmpi(sub_analysis_type,'steady')) | ...
-			(strcmpi(analysis_type,'steadystate'))...
-		)
-		md.dt=0;
-	end
-
-	if control,
-		md.control_analysis=1;
-		if strcmpi(control_fit,'absolute'),
-			md.fit(:)=0;
-		elseif strcmpi(control_fit,'relative'),
-			md.fit(:)=1;
-		elseif strcmpi(control_fit,'logarithmic'),
-			md.fit(:)=2;
-		else
-			error(['updatearchive error message: for control solution, ' control_fit ' fit is not supported!']);
-		end
-	end
-	
-	%presolve
-	if exist('./testpresolve.m','file')==2,
-		testpresolve;
-	end
-
-	%solve
-	md=solve(md,'analysis_type',analysis_type,'sub_analysis_type',sub_analysis_type);
-
-	%postsolve
-	if exist('./testpostsolve.m','file')==2,
-		testpostsolve;
-	end
-	md=solve(md,'analysis_type',analysis_type,'sub_analysis_type',sub_analysis_type);
-
-	%compute fields to be checked
-	fields=testsgetfields2(md,sequence);
-
-	%save new archive
-	if parallel,
-		runtype='parallel';
-	else
-		runtype='serial';
-	end
-	for k=1:length(fields),
-		field=fields{k};
-		eval(['Archive_'  analysis_type '_' sub_analysis_type '_' runtype '_field' num2str(k) ' = md.results. ' field  ';']);
-	end
-	eval(['save Archive_'  analysis_type '_' sub_analysis_type '_' runtype ' Archive_'  analysis_type '_' sub_analysis_type '_' runtype '_field*']);
-	disp(sprintf(['File Archive_'  analysis_type '_' sub_analysis_type '_' runtype ' saved\n']));
-
-end
+%call updatearchive_core
+md=updatearchive_core(varargin{:},'update');
 
 %output model md if requested
