From 6e9e2eac40decbe73e6d44c55f60e32307f013b0 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 10 Mar 2017 17:23:35 +0100 Subject: [PATCH] preprocessor: write JSON output for cross refs #1387 --- DynamicModel.cc | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ DynamicModel.hh | 3 ++ DynareMain2.cc | 2 +- 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index 1bd65d72..29858216 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -5446,6 +5446,89 @@ void DynamicModel::writeJsonOutput(ostream &output) const { writeJsonModelEquations(output, false); + output << ", "; + writeJsonXrefs(output); +} + +void +DynamicModel::writeJsonXrefs(ostream &output) const +{ + output << "\"xrefs\": {" + << "\"parameters\": ["; + for (map, set >::const_iterator it = xref_param.begin(); + it != xref_param.end(); it++) + { + if (it != xref_param.begin()) + output << ", "; + output << "{\"parameter\": \"" << symbol_table.getName(it->first.first) << "\"" + << ", \"equations\": ["; + for (set::const_iterator it1 = it->second.begin(); + it1 != it->second.end(); it1++) + { + if (it1 != it->second.begin()) + output << ", "; + output << *it1 + 1; + } + output << "]}"; + } + output << "]" + << ", \"endogenous\": ["; + for (map, set >::const_iterator it = xref_endo.begin(); + it != xref_endo.end(); it++) + { + if (it != xref_endo.begin()) + output << ", "; + output << "{\"endogenous\": \"" << symbol_table.getName(it->first.first) << "\"" + << ", \"shift\": " << it->first.second + << ", \"equations\": ["; + for (set::const_iterator it1 = it->second.begin(); + it1 != it->second.end(); it1++) + { + if (it1 != it->second.begin()) + output << ", "; + output << *it1 + 1; + } + output << "]}"; + } + output << "]" + << ", \"exogenous\": ["; + for (map, set >::const_iterator it = xref_exo.begin(); + it != xref_exo.end(); it++) + { + if (it != xref_exo.begin()) + output << ", "; + output << "{\"exogenous\": \"" << symbol_table.getName(it->first.first) << "\"" + << ", \"shift\": " << it->first.second + << ", \"equations\": ["; + for (set::const_iterator it1 = it->second.begin(); + it1 != it->second.end(); it1++) + { + if (it1 != it->second.begin()) + output << ", "; + output << *it1 + 1; + } + output << "]}"; + } + output << "]" + << ", \"exogenous_deterministic\": ["; + for (map, set >::const_iterator it = xref_exo_det.begin(); + it != xref_exo_det.end(); it++) + { + if (it != xref_exo_det.begin()) + output << ", "; + output << "{\"exogenous_det\": \"" << symbol_table.getName(it->first.first) << "\"" + << ", \"shift\": " << it->first.second + << ", \"equations\": ["; + for (set::const_iterator it1 = it->second.begin(); + it1 != it->second.end(); it1++) + { + if (it1 != it->second.begin()) + output << ", "; + output << *it1 + 1; + } + output << "]}"; + } + output << "]}" << endl; } void diff --git a/DynamicModel.hh b/DynamicModel.hh index 6001c017..c9c9da8a 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -245,6 +245,9 @@ public: //! Write JSON prams derivatives file void writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) const; + //! Write cross reference output if the xref maps have been filed + void writeJsonXrefs(ostream &output) const; + //! Return true if the hessian is equal to zero inline bool checkHessianZero() const; diff --git a/DynareMain2.cc b/DynareMain2.cc index 5a870a62..55f8304e 100644 --- a/DynareMain2.cc +++ b/DynareMain2.cc @@ -50,7 +50,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson); // Perform transformations on the model (creation of auxiliary vars and equations) - mod_file->transformPass(nostrict, compute_xrefs); + mod_file->transformPass(nostrict, compute_xrefs || json == transformpass); if (json == transformpass) mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);