Commit 446623f5 authored by sebastien's avatar sebastien
Browse files

v4 parser: allow for empty model in some cases (actually for standalone BVAR estimation)


git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1370 ac1d8469-bf42-47a9-8791-bf33cf982152
parent daef6d60
......@@ -759,7 +759,11 @@ PlannerObjectiveStatement::~PlannerObjectiveStatement()
void
PlannerObjectiveStatement::checkPass(ModFileStructure &mod_file_struct)
{
model_tree->checkPass();
if (model_tree->equation_number() != 1)
{
cerr << "Error: planer_objective: should have only one equation!" << endl;
exit(-1);
}
}
void
......
......@@ -26,16 +26,24 @@ ModFile::addStatement(Statement *st)
void
ModFile::checkPass()
{
model_tree.checkPass();
for(vector<Statement *>::iterator it = statements.begin();
it != statements.end(); it++)
(*it)->checkPass(mod_file_struct);
// Allow empty model only when doing a standalone BVAR estimation
if (model_tree.equation_number() == 0
&& (mod_file_struct.check_present
|| mod_file_struct.simul_present
|| mod_file_struct.stoch_simul_or_similar_present))
{
cerr << "Error: you must declare at least one model equation!" << endl;
exit(-1);
}
if (mod_file_struct.simul_present
&& mod_file_struct.stoch_simul_or_similar_present)
{
cerr << "Error: a mod file cannot contain both a simul command and one of {stoch_simul, estimation, olr, osr}" << endl;
cerr << "Error: a mod file cannot contain both a simul command and one of {stoch_simul, estimation, osr, ramsey_policy}" << endl;
exit(-1);
}
}
......@@ -43,24 +51,28 @@ ModFile::checkPass()
void
ModFile::computingPass()
{
// Set things to compute
if (mod_file_struct.simul_present)
model_tree.computeJacobian = true;
else
// Mod file may have no equation (for example in a standalone BVAR estimation)
if (model_tree.equation_number() > 0)
{
if (mod_file_struct.order_option < 1 || mod_file_struct.order_option > 3)
// Set things to compute
if (mod_file_struct.simul_present)
model_tree.computeJacobian = true;
else
{
cerr << "Incorrect order option..." << endl;
exit(-1);
if (mod_file_struct.order_option < 1 || mod_file_struct.order_option > 3)
{
cerr << "Incorrect order option..." << endl;
exit(-1);
}
model_tree.computeJacobianExo = true;
if (mod_file_struct.order_option >= 2)
model_tree.computeHessian = true;
if (mod_file_struct.order_option == 3)
model_tree.computeThirdDerivatives = true;
}
model_tree.computeJacobianExo = true;
if (mod_file_struct.order_option >= 2)
model_tree.computeHessian = true;
if (mod_file_struct.order_option == 3)
model_tree.computeThirdDerivatives = true;
}
model_tree.computingPass(global_eval_context);
model_tree.computingPass(global_eval_context);
}
for(vector<Statement *>::iterator it = statements.begin();
it != statements.end(); it++)
......@@ -114,38 +126,43 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
mOutputFile << "logname_ = '" << basename << ".log';" << endl;
mOutputFile << "diary '" << basename << ".log';" << endl;
if (model_tree.mode == eDLLMode)
{
mOutputFile << "if ";
mOutputFile << interfaces::file_exist(basename + "_static.c") << endl;
mOutputFile << " clear " << basename << "_static" << endl;
mOutputFile << " " << interfaces::compile(basename +"_static.c") << endl;
mOutputFile << "end" << endl;
mOutputFile << "if ";
mOutputFile << interfaces::file_exist(basename + "_dynamic.c") << endl;
mOutputFile << " clear " << basename << "_dynamic" << endl;
mOutputFile << " " + interfaces::compile(basename+"_dynamic.c") << endl;
mOutputFile << "end" << endl;
}
else
if (model_tree.equation_number() > 0)
{
mOutputFile << "erase_compiled_function('" + basename +"_static');" << endl;
mOutputFile << "erase_compiled_function('" + basename +"_dynamic');" << endl;
mOutputFile << interfaces::load_model_function_files(basename);
if (model_tree.mode == eDLLMode)
{
mOutputFile << "if ";
mOutputFile << interfaces::file_exist(basename + "_static.c") << endl;
mOutputFile << " clear " << basename << "_static" << endl;
mOutputFile << " " << interfaces::compile(basename +"_static.c") << endl;
mOutputFile << "end" << endl;
mOutputFile << "if ";
mOutputFile << interfaces::file_exist(basename + "_dynamic.c") << endl;
mOutputFile << " clear " << basename << "_dynamic" << endl;
mOutputFile << " " + interfaces::compile(basename+"_dynamic.c") << endl;
mOutputFile << "end" << endl;
}
else
{
mOutputFile << "erase_compiled_function('" + basename +"_static');" << endl;
mOutputFile << "erase_compiled_function('" + basename +"_dynamic');" << endl;
mOutputFile << interfaces::load_model_function_files(basename);
}
}
cout << "Processing outputs ..." << endl;
symbol_table.writeOutput(mOutputFile);
if (linear == 1)
mOutputFile << "options_.linear = 1;" << endl;
model_tree.writeOutput(mOutputFile);
cout << "Processing outputs ..." << endl;
model_tree.writeStaticFile(basename);
model_tree.writeDynamicFile(basename);
if (model_tree.equation_number() > 0)
{
model_tree.writeOutput(mOutputFile);
model_tree.writeStaticFile(basename);
model_tree.writeDynamicFile(basename);
}
// Print statements
for(vector<Statement *>::const_iterator it = statements.begin();
......
......@@ -1979,17 +1979,6 @@ ModelTree::addEquation(NodeID eq)
equations.push_back(beq);
}
void
ModelTree::checkPass() const
{
// Exit if there is no equation in model file
if (equations.size() == 0)
{
cerr << "No equation found in model file" << endl;
exit(-1);
}
}
void
ModelTree::evaluateJacobian(const eval_context_type &eval_context, jacob_map *j_m)
{
......
......@@ -115,8 +115,6 @@ public:
bool new_SGE;
//! Declare a node as an equation of the model
void addEquation(NodeID eq);
//! Do some checking
void checkPass() const;
//! Whether dynamic Jacobian (w.r. to endogenous) should be written
bool computeJacobian;
//! Whether dynamic Jacobian (w.r. to endogenous and exogenous) should be written
......
......@@ -15,9 +15,9 @@ public:
bool check_present;
//! Whether a simul statement is present
bool simul_present;
//! Whether a stoch_simul, estimation, olr, osr, ramsey_policy statement is present
//! Whether a stoch_simul, estimation, osr, ramsey_policy statement is present
bool stoch_simul_or_similar_present;
//! The value of the "order" option of stoch_simul, estimation, olr, osr, ramsey_policy
//! The value of the "order" option of stoch_simul, estimation, osr, ramsey_policy
/*! Defaults to 2 */
int order_option;
};
......
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