Commit 718ff3d6 authored by Houtan Bastani's avatar Houtan Bastani
Browse files

preprocessor: only create *set_auxiliary_variables.m file if there will be...

preprocessor: only create *set_auxiliary_variables.m file if there will be something in it. Closes #1384
parent bd81ebc5
......@@ -235,7 +235,9 @@ else
% which files have to be copied to run remotely
NamFileInput(1,:) = {'',[M_.fname '_static.m']};
NamFileInput(2,:) = {'',[M_.fname '_dynamic.m']};
NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']};
if M_.set_auxiliary_variables
NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']};
end
if options_.steadystate_flag
if options_.steadystate_flag == 1
NamFileInput(length(NamFileInput)+1,:)={'',[M_.fname '_steadystate.m']};
......
......@@ -136,11 +136,15 @@ xx(1:M.orig_endo_nbr) = x(1:M.orig_endo_nbr); %set values of original endogenous
% setting steady state of auxiliary variables that depends on original endogenous variables
if any([M.aux_vars.type] ~= 6) %auxiliary variables other than multipliers
needs_set_auxiliary_variables = 1;
fh = str2func([M.fname '_set_auxiliary_variables']);
s_a_v_func = @(z) fh(z,...
[oo.exo_steady_state,...
oo.exo_det_steady_state],...
params);
if M.set_auxiliary_variables
fh = str2func([M.fname '_set_auxiliary_variables']);
s_a_v_func = @(z) fh(z,...
[oo.exo_steady_state,...
oo.exo_det_steady_state],...
params);
else
s_a_v_func = z;
end
xx = s_a_v_func(xx);
else
needs_set_auxiliary_variables = 0;
......
......@@ -48,7 +48,9 @@ exo_ss = [oo.exo_steady_state; oo.exo_det_steady_state];
if length(M.aux_vars) > 0 && ~steadystate_flag
h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']);
ys_init = h_set_auxiliary_variables(ys_init,exo_ss,M.params);
if M.set_auxiliary_variables
ys_init = h_set_auxiliary_variables(ys_init,exo_ss,M.params);
end
end
if options.ramsey_policy
......@@ -288,7 +290,9 @@ if check
info(1)= 20;
%make sure ys contains auxiliary variables in case of problem with dynare_solve
if length(M.aux_vars) > 0 && ~steadystate_flag
ys = h_set_auxiliary_variables(ys,exo_ss,M.params);
if M.set_auxiliary_variables
ys = h_set_auxiliary_variables(ys,exo_ss,M.params);
end
end
resid = evaluate_static_model(ys,exo_ss,params,M,options);
info(2) = resid'*resid ;
......
......@@ -74,14 +74,18 @@ h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']);
if isnan(updated_params_flag) || (updated_params_flag && any(isnan(params(~isnan(params))-params1(~isnan(params))))) %checks if new NaNs were added
info(1) = 24;
info(2) = NaN;
ys = h_set_auxiliary_variables(ys,exo_ss,params);
if M.set_auxiliary_variables
ys = h_set_auxiliary_variables(ys,exo_ss,params);
end
return
end
if updated_params_flag && ~isreal(params1)
info(1) = 23;
info(2) = sum(imag(params).^2);
ys = h_set_auxiliary_variables(ys,exo_ss,params);
if M.set_auxiliary_variables
ys = h_set_auxiliary_variables(ys,exo_ss,params);
end
return
end
......@@ -94,16 +98,22 @@ if length(M.aux_vars) > 0 && ~options.ramsey_policy
if debug
ys0 = ys;
end
ys = h_set_auxiliary_variables(ys,exo_ss,params);
if M.set_auxiliary_variables
ys = h_set_auxiliary_variables(ys,exo_ss,params);
end
if debug
ys1 = ys;
end
ys = h_set_auxiliary_variables(ys,exo_ss,params);
if M.set_auxiliary_variables
ys = h_set_auxiliary_variables(ys,exo_ss,params);
end
if debug
ys2 = ys;
end
if debug
ys = h_set_auxiliary_variables(ys,exo_ss,params);
if M.set_auxiliary_variables
ys = h_set_auxiliary_variables(ys,exo_ss,params);
end
ys3 = ys;
idx = find(abs(ys0-ys1)>0);
if ~isempty(idx)
......
......@@ -127,7 +127,9 @@ else
% which files have to be copied to run remotely
NamFileInput(1,:) = {'',[ModelName '_static.m']};
NamFileInput(2,:) = {'',[ModelName '_dynamic.m']};
NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']};
if M.set_auxiliary_variables
NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']};
end
if options_.steadystate_flag
if options_.steadystate_flag == 1
NamFileInput(length(NamFileInput)+1,:)={'',[M_.fname '_steadystate.m']};
......
......@@ -294,7 +294,9 @@ else
% which files have to be copied to run remotely
NamFileInput(1,:) = {'',[M_.fname '_static.m']};
NamFileInput(2,:) = {'',[M_.fname '_dynamic.m']};
NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']};
if M.set_auxiliary_variables
NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']};
end
if options_.steadystate_flag
if options_.steadystate_flag == 1
NamFileInput(length(NamFileInput)+1,:)={'',[M_.fname '_steadystate.m']};
......
......@@ -813,7 +813,8 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
mOutputFile << "M_.orig_eq_nbr = " << mod_file_struct.orig_eq_nbr << ";" << endl
<< "M_.eq_nbr = " << dynamic_model.equation_number() << ";" << endl
<< "M_.ramsey_eq_nbr = " << mod_file_struct.ramsey_eq_nbr << ";" << endl;
<< "M_.ramsey_eq_nbr = " << mod_file_struct.ramsey_eq_nbr << ";" << endl
<< "M_.set_auxiliary_variables = exist(['./' M_.fname '_set_auxiliary_variables.m'], 'file') == 2;" << endl;
if (dynamic_model.equation_number() > 0)
{
......
......@@ -2130,6 +2130,11 @@ StaticModel::writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type)
void
StaticModel::writeSetAuxiliaryVariables(const string &basename, const bool julia) const
{
ostringstream output_func_body;
writeAuxVarRecursiveDefinitions(output_func_body, oMatlabStaticModel);
if (output_func_body.str().empty())
return;
string func_name = basename + "_set_auxiliary_variables";
string filename = julia ? func_name + ".jl" : func_name + ".m";
......@@ -2148,10 +2153,8 @@ StaticModel::writeSetAuxiliaryVariables(const string &basename, const bool julia
<< comment << " Status : Computes static model for Dynare" << endl
<< comment << endl
<< comment << " Warning : this file is generated automatically by Dynare" << endl
<< comment << " from model file (.mod)" << endl
<< endl;
writeAuxVarRecursiveDefinitions(output, oMatlabStaticModel);
<< comment << " from model file (.mod)" << endl << endl
<< output_func_body.str();
}
void
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment