From 446623f576b0ba52959f534c93ce0fc6dafcbde0 Mon Sep 17 00:00:00 2001 From: sebastien Date: Mon, 16 Jul 2007 16:47:09 +0000 Subject: [PATCH] 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 --- parser.src/ComputingTasks.cc | 6 +- parser.src/ModFile.cc | 99 +++++++++++++++++++-------------- parser.src/ModelTree.cc | 11 ---- parser.src/include/ModelTree.hh | 2 - parser.src/include/Statement.hh | 4 +- 5 files changed, 65 insertions(+), 57 deletions(-) diff --git a/parser.src/ComputingTasks.cc b/parser.src/ComputingTasks.cc index b2dfd76a1..33fd5afcf 100644 --- a/parser.src/ComputingTasks.cc +++ b/parser.src/ComputingTasks.cc @@ -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 diff --git a/parser.src/ModFile.cc b/parser.src/ModFile.cc index b973b6341..8cc11f890 100644 --- a/parser.src/ModFile.cc +++ b/parser.src/ModFile.cc @@ -26,16 +26,24 @@ ModFile::addStatement(Statement *st) void ModFile::checkPass() { - model_tree.checkPass(); - for(vector::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::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) + + if (model_tree.equation_number() > 0) { - 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); + 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::const_iterator it = statements.begin(); diff --git a/parser.src/ModelTree.cc b/parser.src/ModelTree.cc index b74920fd8..8cd1d6573 100644 --- a/parser.src/ModelTree.cc +++ b/parser.src/ModelTree.cc @@ -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) { diff --git a/parser.src/include/ModelTree.hh b/parser.src/include/ModelTree.hh index f5eeadf39..c2d8c63a3 100644 --- a/parser.src/include/ModelTree.hh +++ b/parser.src/include/ModelTree.hh @@ -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 diff --git a/parser.src/include/Statement.hh b/parser.src/include/Statement.hh index e1f98fa75..3f5303749 100644 --- a/parser.src/include/Statement.hh +++ b/parser.src/include/Statement.hh @@ -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; };