function md=loadresultsfromdisk(md,filename)
%LOADRESULTSFROMDISK - load results of solution sequence from disk file "filename"            
%
%   Usage:
%      md=loadresultsfromdisk(md,filename);

%check number of inputs/outputs
if ((nargin~=2) | (nargout~=1)),
	help loadresultsfromdisk;
	error('loadresultsfromdisk: error message.');
end

if ~md.qmu.isdakota,

	%Check that file exists
	if ~exist(filename,'file'),
		error(['binary file ' filename ' not found.']);
	end

	%initialize md.results if not a structure yet
	if ~isstruct(md.results),
		md.results=struct();
	end

	%load results onto model
	structure=parseresultsfromdisk(filename,~md.settings.io_gather);
	if isempty(fieldnames(structure)),
		error(['No result found in binary file ' filename '. Check for solution crash.']);
	end
	md.results.(structure(1).SolutionType)=structure;

	%recover solution_type from results
	md.private.solution=structure(1).SolutionType;

	%read log files onto  fields
	if exist([md.miscellaneous.name '.errlog'],'file'),
		md.results.(structure(1).SolutionType)(1).errlog=char(textread([md.miscellaneous.name '.errlog'],'%s','delimiter','\n'));
	else
		md.results.(structure(1).SolutionType)(1).errlog='';
	end

	if exist([md.miscellaneous.name '.outlog'],'file'),
		md.results.(structure(1).SolutionType)(1).outlog=char(textread([md.miscellaneous.name '.outlog'],'%s','delimiter','\n'));
	else
		md.results.(structure(1).SolutionType)(1).outlog='';
	end

	if ~isempty(md.results.(structure(1).SolutionType)(1).errlog),
		disp(['loadresultsfromcluster info message: error during solution. Check your errlog and outlog model fields']);
	end


%post processes qmu results if necessary
else

	if isscalar(md.private.solution),
		md.private.solution=EnumToString(md.private.solution);
	end
	md=postqmu(md);
	cd ..
end
