% This file can be run to update the velocity archives  of the test1.
% 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 Ice code. 

% The archive files will be saved in this directory but will not commited to ice1. 
% Just commit the result if you want to.

%packages and solutions to be tested
packages={'macayeal','ice','cielo_serial','cielo_parallel'};
solutions={'diagnostic','prognostic'};
solutions={'prognostic'};

%go through the solutions requested
testname='IceSheetNoIceFrontM2d_16';
for i=1:length(packages),
	package=packages{i};

	for j=1:length(solutions),
		solution=solutions{j};

		%check package
		if ~(strcmpi(package,'macayeal') | strcmpi(package,'ice') | strcmpi(package,'cielo_serial') | strcmpi(package,'cielo_parallel'));
			error(['package: ' package  ' in test: ' testname  ' not supported yet']);
			%check solution
		elseif ~(strcmpi(solution,'diagnostic') | strcmpi(solution,'prognostic'));
			error(['solution: ' solution  ' in test: ' testname  ' not supported yet']);
		end
		%check solution requested
		if (~strcmpi(package,'ice') & strcmpi(solution,'prognostic')),
			disp(sprintf(['\nsolution: ' solution  ', with package: ' package  ', in test: ' testname  ', not supported yet.\n']));
			continue
		end

		%initialize model
		md=model;
		md=mesh(md,'DomainOutline.exp',50000);
		md=geography(md,'','');
		md=parameterize(md,'Square.par');
		md=setelementstype(md,'macayeal','all');
		if strcmpi(package,'cielo_parallel'), md.cluster='wilkes'; end
		if md.numberofgrids==388
			load Velocities; md.vx=0.5*vx; md.vy=0.5*vy;
		end

		%compute solution
		if strcmpi(package,'cielo_parallel') & strcmpi(solution,'diagnostic'),
			md=solve(md,'diagnostic_horiz','cielo');
		elseif strcmpi(package,'cielo_serial'),
			eval(['md=solve(md,''' solution ''',''cielo'');']);
		else
			eval(['md=solve(md,''' solution ''',''' package ''');']);
		end

		%save new archive
		if strcmpi(solution,'diagnostic'),
			fieldtest=md.vel;
		elseif strcmpi(solution,'prognostic'),
			fieldtest=md.new_thickness';
		end
		eval(['Archive' package solution '=fieldtest;']);
		eval(['save Archive' package solution ' Archive' package solution]);
	end
end
