From 839ae22b1fbbb0c0b3cb8dc30fbf110efd4923c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Fri, 29 Nov 2013 16:03:15 +0100 Subject: [PATCH] Add a warning when some exogenous are not used in the model --- preprocessor/DynamicModel.cc | 13 +++++++++++++ preprocessor/DynamicModel.hh | 2 ++ preprocessor/ModFile.cc | 15 +++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index aa682d19e..ecd0881b6 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -3585,6 +3585,19 @@ DynamicModel::findUnusedEndogenous() return unusedEndo; } +set +DynamicModel::findUnusedExogenous() +{ + set usedExo, unusedExo; + for (int i = 0; i < (int) equations.size(); i++) + equations[i]->collectVariables(eExogenous, usedExo); + set allExo = symbol_table.getExogenous(); + set_difference(allExo.begin(), allExo.end(), + usedExo.begin(), usedExo.end(), + inserter(unusedExo, unusedExo.begin())); + return unusedExo; +} + void DynamicModel::computeDerivIDs() { diff --git a/preprocessor/DynamicModel.hh b/preprocessor/DynamicModel.hh index c02d11303..5f32ed11f 100644 --- a/preprocessor/DynamicModel.hh +++ b/preprocessor/DynamicModel.hh @@ -224,6 +224,8 @@ public: //! Find endogenous variables not used in model set findUnusedEndogenous(); + //! Find exogenous variables not used in model + set findUnusedExogenous(); //! Copies a dynamic model (only the equations) /*! It assumes that the dynamic model given in argument has just been allocated */ diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index 56c5fb30d..6d6af32bb 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -286,6 +286,21 @@ ModFile::checkPass() cerr << ") also appear in the expressions defining the variance/covariance matrix of shocks; this is not allowed." << endl; exit(EXIT_FAILURE); } + + // Check if some exogenous is not used in the model block + set unusedExo = dynamic_model.findUnusedExogenous(); + if (unusedExo.size() > 1) + { + warnings << "WARNING: some exogenous ("; + for (set::const_iterator it = unusedExo.begin(); + it != unusedExo.end(); ) + { + warnings << symbol_table.getName(*it); + if (++it != unusedExo.end()) + warnings << ", "; + } + warnings << ") are declared but not used in the model. This may lead to crashes or unexpected behaviour." << endl; + } } void