From 6015b0e57bf3f809b62959909c9cf5dd9ab5dbc8 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Wed, 22 Aug 2018 09:15:00 +0200 Subject: [PATCH] fixes to trend component model --- src/ModFile.cc | 9 ++++++++- src/ParsingDriver.cc | 20 +++++++++----------- src/SubModel.cc | 17 ++++++++++++++++- src/SubModel.hh | 10 +++++++++- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/ModFile.cc b/src/ModFile.cc index 6f377258..644c7ae3 100644 --- a/src/ModFile.cc +++ b/src/ModFile.cc @@ -1315,9 +1315,16 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType output << ", "; dynamic_model.writeJsonOutput(output); - if (!statements.empty()) + if (!statements.empty() + || !trend_component_model_table.empty()) { output << ", \"statements\": ["; + if (!trend_component_model_table.empty()) + { + trend_component_model_table.writeJsonOutput(output); + output << ", "; + } + for (auto it = statements.begin(); it != statements.end(); it++) { diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc index 5265aa82..a86b37ff 100644 --- a/src/ParsingDriver.cc +++ b/src/ParsingDriver.cc @@ -1422,22 +1422,20 @@ ParsingDriver::stoch_simul() void ParsingDriver::trend_component_model() { - OptionsList::string_options_t::const_iterator it = - options_list.string_options.find("trend_component.name"); - if (it == options_list.string_options.end()) + const auto its = options_list.string_options.find("trend_component.name"); + if (its == options_list.string_options.end()) error("You must pass the model_name option to the trend_component_model statement."); - auto name = it->second; + auto name = its->second; - OptionsList::vec_str_options_t::const_iterator it1 = - options_list.vector_str_options.find("trend_component.eqtags"); - if (it1 == options_list.vector_str_options.end()) + const auto itvs = options_list.vector_str_options.find("trend_component.eqtags"); + if (itvs == options_list.vector_str_options.end()) error("You must pass the eqtags option to the trend_component_model statement."); - auto eqtags = it1->second; + auto eqtags = itvs->second; - it1 = options_list.vector_str_options.find("trend_component.trends"); - if (it1 == options_list.vector_str_options.end()) + const auto itvs1 = options_list.vector_str_options.find("trend_component.trends"); + if (itvs1 == options_list.vector_str_options.end()) error("You must pass the trends option to the trend_component_model statement."); - auto trends = it1->second; + auto trends = itvs1->second; mod_file->trend_component_model_table.addTrendComponentModel(name, eqtags, trends); options_list.clear(); diff --git a/src/SubModel.cc b/src/SubModel.cc index 17702a2d..0e399796 100644 --- a/src/SubModel.cc +++ b/src/SubModel.cc @@ -283,6 +283,21 @@ TrendComponentModelTable::writeJsonOutput(ostream &output) const if (name != *(names.begin())) output << ", "; output << "{\"statementName\": \"trend_component_model\"," - << "\"model_name\": \"" << name << "\"}"; + << "\"model_name\": \"" << name << "\"," + << "\"eqtags\": ["; + for (const auto &it : eqtags.at(name)) + { + output << "\"" << it << "\""; + if (&it != &eqtags.at(name).back()) + output << ", "; + } + output << "], \"trend_eqtags\": ["; + for (const auto &it : trend_eqtags.at(name)) + { + output << "\"" << it << "\""; + if (&it != &trend_eqtags.at(name).back()) + output << ", "; + } + output << "]}"; } } diff --git a/src/SubModel.hh b/src/SubModel.hh index e7fa2759..d03ad0fd 100644 --- a/src/SubModel.hh +++ b/src/SubModel.hh @@ -48,9 +48,11 @@ public: TrendComponentModelTable(SymbolTable &symbol_table_arg); //! Add a trend component model - void addTrendComponentModel(string name, vector<string> eqtags, vector<string> trend_eqtags); + void addTrendComponentModel(string name_arg, vector<string> eqtags_arg, + vector<string> trend_eqtags_arg); inline bool isExistingTrendComponentModelName(const string &name_arg) const; + inline bool empty() const; map<string, vector<string>> getEqTags() const; vector<string> getEqTags(const string &name_arg) const; @@ -93,4 +95,10 @@ TrendComponentModelTable::isExistingTrendComponentModelName(const string &name_a return names.find(name_arg) == names.end() ? false : true; } +inline bool +TrendComponentModelTable::empty() const +{ + return names.empty(); +} + #endif -- GitLab