function local_pop_context(model, old, varargin)
% Restore model parameters from previous context
%
% MODEL is the name of the model for the parameters to be set.
% OLD is the old structure that is stored
% VARAGIN is a flag for the case where the model should be closed.  

%  Author(s): John Glass
%  Revised:
% Copyright 1986-2003 The MathWorks, Inc.
% $Revision: 1.1.6.1 $ $Date: 2004/08/01 00:12:21 $

f = fieldnames(old);
for k = 1:length(f)
    prop = f{k};
    if ~isequal(prop,'Dirty')
        set_param(model, prop, getfield(old, prop));
    end
end

set_param(model, 'Dirty', old.Dirty);

if (nargin == 3) && (varargin{1} == 0)
    close_system(model,0);
end