diff --git a/DynamicModel.cc b/DynamicModel.cc index a4f81a0c..f072fd95 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -5544,6 +5544,76 @@ DynamicModel::writeJsonOriginalModelOutput(ostream &output) const writeJsonModelEquations(output, false); } +void +DynamicModel::writeJsonDynamicModelInfo(ostream &output) const +{ + output << "\"model_info\": {" + << "\"lead_lag_incidence\": ["; + // Loop on endogenous variables + int nstatic = 0, + nfwrd = 0, + npred = 0, + nboth = 0; + for (int endoID = 0; endoID < symbol_table.endo_nbr(); endoID++) + { + if (endoID != 0) + output << ","; + output << "["; + int sstatic = 1, + sfwrd = 0, + spred = 0, + sboth = 0; + // Loop on periods + for (int lag = -max_endo_lag; lag <= max_endo_lead; lag++) + { + // Print variableID if exists with current period, otherwise print 0 + try + { + if (lag != -max_endo_lag) + output << ","; + int varID = getDerivID(symbol_table.getID(eEndogenous, endoID), lag); + output << " " << getDynJacobianCol(varID) + 1; + if (lag == -1) + { + sstatic = 0; + spred = 1; + } + else if (lag == 1) + { + if (spred == 1) + { + sboth = 1; + spred = 0; + } + else + { + sstatic = 0; + sfwrd = 1; + } + } + } + catch (UnknownDerivIDException &e) + { + output << " 0"; + } + } + nstatic += sstatic; + nfwrd += sfwrd; + npred += spred; + nboth += sboth; + output << "]"; + } + output << "], " + << "\"nstatic\": " << nstatic << ", " + << "\"nfwrd\": " << nfwrd << ", " + << "\"npred\": " << npred << ", " + << "\"nboth\": " << nboth << ", " + << "\"nsfwrd\": " << nfwrd+nboth << ", " + << "\"nspred\": " << npred+nboth << ", " + << "\"ndynamic\": " << npred+nboth+nfwrd << endl; + output << "}"; +} + void DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) const { diff --git a/DynamicModel.hh b/DynamicModel.hh index b0ebd7fa..1fb14bc2 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -242,6 +242,9 @@ public: //! Write JSON Output representation of original dynamic model void writeJsonOriginalModelOutput(ostream &output) const; + //! Write JSON Output representation of model info (useful stuff from M_) + void writeJsonDynamicModelInfo(ostream &output) const; + //! Write JSON Output representation of dynamic model after computing pass void writeJsonComputingPassOutput(ostream &output, bool writeDetails) const; diff --git a/ModFile.cc b/ModFile.cc index 0ad63d2b..ba7a38c7 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -1270,7 +1270,7 @@ ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonF if (json == parsing || json == checkpass) symbol_table.freeze(); - writeJsonOutputParsingCheck(basename, json_output_mode, json == transformpass); + writeJsonOutputParsingCheck(basename, json_output_mode, json == transformpass, json == computingpass); if (json == parsing || json == checkpass) symbol_table.unfreeze(); @@ -1302,7 +1302,7 @@ ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonF } void -ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType json_output_mode, bool transformpass) const +ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType json_output_mode, bool transformpass, bool computingpass) const { ostringstream output; output << "{" << endl; @@ -1323,6 +1323,12 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType } output << "]" << endl; } + + if (computingpass) + { + output << ","; + dynamic_model.writeJsonDynamicModelInfo(output); + } output << "}" << endl; ostringstream original_model_output; @@ -1338,7 +1344,7 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType { cout << output.str(); if (!original_model_output.str().empty()) - cout << original_model_output.str(); + cout << "," << original_model_output.str(); } else { diff --git a/ModFile.hh b/ModFile.hh index 1b763f63..985a15a7 100644 --- a/ModFile.hh +++ b/ModFile.hh @@ -118,7 +118,7 @@ private: //! Warnings Encountered WarningConsolidation &warnings; //! Functions used in writing of JSON outut. See writeJsonOutput - void writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType json_output_mode, bool transformpass) const; + void writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType json_output_mode, bool transformpass, bool computingpass) const; void writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonprintderivdetail) const; void writeJsonFileHelper(string &fname, ostringstream &output) const; public: