function [old, preloaded] = scd_push_context(model, new)
% Save model parameters before setting up new ones

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

%% Make sure the model is loaded
if isempty(find_system('SearchDepth',0,'CaseSensitive','off','Name',model))
    preloaded = 0;
    load_system(model);
else
    preloaded = 1;
end

%% Save this before calling set_param() ..
old = struct('Dirty', get_param(model,'Dirty'));

f = fieldnames(new);
for k = 1:length(f)
    prop = f{k};
    have_val = get_param(model, prop);
    want_val = getfield(new, prop);
    if ~isequal(have_val, want_val)
        set_param(model, prop, want_val);
        old = setfield(old, prop, have_val);
    end
end