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-bf33cf982152time-shift
parent
daef6d60b6
commit
446623f576
|
@ -759,7 +759,11 @@ PlannerObjectiveStatement::~PlannerObjectiveStatement()
|
||||||
void
|
void
|
||||||
PlannerObjectiveStatement::checkPass(ModFileStructure &mod_file_struct)
|
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
|
void
|
||||||
|
|
|
@ -26,16 +26,24 @@ ModFile::addStatement(Statement *st)
|
||||||
void
|
void
|
||||||
ModFile::checkPass()
|
ModFile::checkPass()
|
||||||
{
|
{
|
||||||
model_tree.checkPass();
|
|
||||||
|
|
||||||
for(vector<Statement *>::iterator it = statements.begin();
|
for(vector<Statement *>::iterator it = statements.begin();
|
||||||
it != statements.end(); it++)
|
it != statements.end(); it++)
|
||||||
(*it)->checkPass(mod_file_struct);
|
(*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
|
if (mod_file_struct.simul_present
|
||||||
&& mod_file_struct.stoch_simul_or_similar_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);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,24 +51,28 @@ ModFile::checkPass()
|
||||||
void
|
void
|
||||||
ModFile::computingPass()
|
ModFile::computingPass()
|
||||||
{
|
{
|
||||||
// Set things to compute
|
// Mod file may have no equation (for example in a standalone BVAR estimation)
|
||||||
if (mod_file_struct.simul_present)
|
if (model_tree.equation_number() > 0)
|
||||||
model_tree.computeJacobian = true;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
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;
|
if (mod_file_struct.order_option < 1 || mod_file_struct.order_option > 3)
|
||||||
exit(-1);
|
{
|
||||||
|
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();
|
for(vector<Statement *>::iterator it = statements.begin();
|
||||||
it != statements.end(); it++)
|
it != statements.end(); it++)
|
||||||
|
@ -114,38 +126,43 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
|
||||||
mOutputFile << "logname_ = '" << basename << ".log';" << endl;
|
mOutputFile << "logname_ = '" << basename << ".log';" << endl;
|
||||||
mOutputFile << "diary '" << basename << ".log';" << endl;
|
mOutputFile << "diary '" << basename << ".log';" << endl;
|
||||||
|
|
||||||
if (model_tree.mode == eDLLMode)
|
|
||||||
|
if (model_tree.equation_number() > 0)
|
||||||
{
|
{
|
||||||
mOutputFile << "if ";
|
if (model_tree.mode == eDLLMode)
|
||||||
mOutputFile << interfaces::file_exist(basename + "_static.c") << endl;
|
{
|
||||||
mOutputFile << " clear " << basename << "_static" << endl;
|
mOutputFile << "if ";
|
||||||
mOutputFile << " " << interfaces::compile(basename +"_static.c") << endl;
|
mOutputFile << interfaces::file_exist(basename + "_static.c") << endl;
|
||||||
mOutputFile << "end" << endl;
|
mOutputFile << " clear " << basename << "_static" << endl;
|
||||||
mOutputFile << "if ";
|
mOutputFile << " " << interfaces::compile(basename +"_static.c") << endl;
|
||||||
mOutputFile << interfaces::file_exist(basename + "_dynamic.c") << endl;
|
mOutputFile << "end" << endl;
|
||||||
mOutputFile << " clear " << basename << "_dynamic" << endl;
|
mOutputFile << "if ";
|
||||||
mOutputFile << " " + interfaces::compile(basename+"_dynamic.c") << endl;
|
mOutputFile << interfaces::file_exist(basename + "_dynamic.c") << endl;
|
||||||
mOutputFile << "end" << endl;
|
mOutputFile << " clear " << basename << "_dynamic" << endl;
|
||||||
}
|
mOutputFile << " " + interfaces::compile(basename+"_dynamic.c") << endl;
|
||||||
else
|
mOutputFile << "end" << endl;
|
||||||
{
|
}
|
||||||
mOutputFile << "erase_compiled_function('" + basename +"_static');" << endl;
|
else
|
||||||
mOutputFile << "erase_compiled_function('" + basename +"_dynamic');" << endl;
|
{
|
||||||
mOutputFile << interfaces::load_model_function_files(basename);
|
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);
|
symbol_table.writeOutput(mOutputFile);
|
||||||
|
|
||||||
if (linear == 1)
|
if (linear == 1)
|
||||||
mOutputFile << "options_.linear = 1;" << endl;
|
mOutputFile << "options_.linear = 1;" << endl;
|
||||||
|
|
||||||
model_tree.writeOutput(mOutputFile);
|
if (model_tree.equation_number() > 0)
|
||||||
|
{
|
||||||
cout << "Processing outputs ..." << endl;
|
model_tree.writeOutput(mOutputFile);
|
||||||
|
model_tree.writeStaticFile(basename);
|
||||||
model_tree.writeStaticFile(basename);
|
model_tree.writeDynamicFile(basename);
|
||||||
|
}
|
||||||
model_tree.writeDynamicFile(basename);
|
|
||||||
|
|
||||||
// Print statements
|
// Print statements
|
||||||
for(vector<Statement *>::const_iterator it = statements.begin();
|
for(vector<Statement *>::const_iterator it = statements.begin();
|
||||||
|
|
|
@ -1979,17 +1979,6 @@ ModelTree::addEquation(NodeID eq)
|
||||||
equations.push_back(beq);
|
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
|
void
|
||||||
ModelTree::evaluateJacobian(const eval_context_type &eval_context, jacob_map *j_m)
|
ModelTree::evaluateJacobian(const eval_context_type &eval_context, jacob_map *j_m)
|
||||||
{
|
{
|
||||||
|
|
|
@ -115,8 +115,6 @@ public:
|
||||||
bool new_SGE;
|
bool new_SGE;
|
||||||
//! Declare a node as an equation of the model
|
//! Declare a node as an equation of the model
|
||||||
void addEquation(NodeID eq);
|
void addEquation(NodeID eq);
|
||||||
//! Do some checking
|
|
||||||
void checkPass() const;
|
|
||||||
//! Whether dynamic Jacobian (w.r. to endogenous) should be written
|
//! Whether dynamic Jacobian (w.r. to endogenous) should be written
|
||||||
bool computeJacobian;
|
bool computeJacobian;
|
||||||
//! Whether dynamic Jacobian (w.r. to endogenous and exogenous) should be written
|
//! Whether dynamic Jacobian (w.r. to endogenous and exogenous) should be written
|
||||||
|
|
|
@ -15,9 +15,9 @@ public:
|
||||||
bool check_present;
|
bool check_present;
|
||||||
//! Whether a simul statement is present
|
//! Whether a simul statement is present
|
||||||
bool simul_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;
|
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 */
|
/*! Defaults to 2 */
|
||||||
int order_option;
|
int order_option;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue