%MASSFLUXATGATE class definition
%
%   Usage:
%      massfluxatgate=massfluxatgate();
%      massfluxatgate=massfluxatgate('GateName','PathToExpFile');

classdef massfluxatgate
	properties (SetAccess=public)  
		%massfluxatgate 
		name                = '';
		profilename            = ''; 
	end
	properties (SetAccess=private)  
		segments            = NaN;
	end
	methods
		function obj = massfluxatgate(varargin) % {{{
			switch nargin
				case 0
					obj=setdefaultparameters(obj);
				case 1
					obj.name=varargin{1};
				case 2
					obj.name=varargin{1};
					obj.profilename=varargin{2};
				otherwise
					error('constructor not supported');
			end
		end % }}}
		function obj = setdefaultparameters(obj) % {{{
		end % }}}
		function md = checkconsistency(obj,md,solution,analyses) % {{{
			
			if ~ischar(obj.name),
				error('massfluxatgate error message: ''name'' field should be a string!');
			end
			if ~ischar(obj.profilename),
				error('massfluxatgate error message: ''profilename'' field should be a string!');
			end

			%check the profilename points to a file!: 
			if exist(obj.profilename,'file')~=2,
				error('massfluxatgate error message: file name for profile corresponding to gate does not point to a legitimate file on disk!');
			end
		end % }}}
		function disp(obj) % {{{
			disp(sprintf('   Massfluxatgate:\n'));

			fielddisplay(obj,'name','identifier for this massfluxatgate response');
			fielddisplay(obj,'profilename','name of file (shapefile or argus file) defining a profile (or gate)');
			
		end % }}}
		function marshall(obj,md,fid) % {{{

		%before marshalling, we need to create the segments out of the profilename: 
		obj.segments=MeshProfileIntersection(md.mesh.elements,md.mesh.x,md.mesh.y,obj.profilename);

		%ok, marshall name and segments: 
		WriteData(fid,'object',obj,'fieldname','name','format','String');
		WriteData(fid,'object',obj,'fieldname','segments','format','DoubleMat','mattype',1);

		end % }}}
	end
end
