%GIA class definition
%
%   Usage:
%      gia=gia();

classdef gia
	properties (SetAccess=public) 
		mantle_viscosity              = NaN;
		lithosphere_thickness         = NaN;
		cross_section_shape           = 0;
	end
	methods
		function obj = gia(varargin) % {{{
			switch nargin
				case 0
					obj=setdefaultparameters(obj);
				otherwise
					error('constructor not supported');
			end
		end % }}}
		function obj = setdefaultparameters(obj) % {{{
		obj.cross_section_shape=1; %square as default (see iedge in GiaDeflectionCorex)
		end % }}}
		function md = checkconsistency(obj,md,solution,analyses) % {{{

			if ~ismember(GiaAnalysisEnum(),analyses), return; end
			md = checkfield(md,'gia.mantle_viscosity','NaN',1,'size',[md.mesh.numberofvertices 1],'>',0);
			md = checkfield(md,'gia.lithosphere_thickness','NaN',1,'size',[md.mesh.numberofvertices 1],'>',0);
			md = checkfield(md,'gia.cross_section_shape','numel',[1],'values',[1,2]);

			%be sure that if we are running a masstransport ice flow model coupled with gia, that thickness forcings 
			%are not provided into the future.
			if solution==TransientSolutionEnum() & md.transient.ismasstransport & md.transient.isgia,
				%figure out if thickness is a transient forcing: 
				if size(md.geometry.thickness,1)==md.mesh.numberofvertices+1,
					%recover the furthest time "in time": 
					if(thickness(end,end)~=md.timestepping.start_time),
						md = checkmessage(md,['if ismasstransport is on, transient thickness forcing'...
							' for the gia model should not be provided in the future.'...
							' Synchronize your start_time to correspond to the most recent transient'...
							' thickness forcing timestep']);
					end
				end
			end

		end % }}}
		function disp(obj) % {{{
			disp(sprintf('   gia parameters:'));

			fielddisplay(obj,'mantle_viscosity','mantle viscosity[Pa s]');
			fielddisplay(obj,'lithosphere_thickness','lithosphere thickness (km)');
			fielddisplay(obj,'cross_section_shape','1: square-edged (default). 2: elliptical.  See iedge in GiaDeflectionCore');

		end % }}}
		function marshall(obj,md,fid) % {{{
			WriteData(fid,'object',obj,'fieldname','mantle_viscosity','format','DoubleMat','mattype',1);
			WriteData(fid,'object',obj,'fieldname','lithosphere_thickness','format','DoubleMat','mattype',1,'scale',10^3); %from km to m
			WriteData(fid,'object',obj,'fieldname','cross_section_shape','format','Integer');
		end % }}}
	end
end
