From ec561138d439fa8d3d439db789c6de823ebfdf2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 28 Jun 2017 15:06:54 +0200 Subject: [PATCH 1/7] Fix various typos (thanks lintian). --- DynamicModel.cc | 2 +- DynareMain.cc | 4 ++-- ModFile.cc | 2 +- StaticModel.cc | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index 8d3ca37d..e935e1cc 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -510,7 +510,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const } else { - cerr << "Type missmatch for equation " << equation_ID+1 << "\n"; + cerr << "Type mismatch for equation " << equation_ID+1 << "\n"; exit(EXIT_FAILURE); } output << ";\n"; diff --git a/DynareMain.cc b/DynareMain.cc index 14d594c4..0230d732 100644 --- a/DynareMain.cc +++ b/DynareMain.cc @@ -251,7 +251,7 @@ main(int argc, char **argv) { if (strlen(argv[arg]) <= 7 || argv[arg][6] != '=') { - cerr << "Incorrect syntax for ouput option" << endl; + cerr << "Incorrect syntax for output option" << endl; usage(); } if (strlen(argv[arg]) == 14 && !strncmp(argv[arg] + 7, "dynamic", 7)) @@ -264,7 +264,7 @@ main(int argc, char **argv) output_mode = third; else { - cerr << "Incorrect syntax for ouput option" << endl; + cerr << "Incorrect syntax for output option" << endl; usage(); } } diff --git a/ModFile.cc b/ModFile.cc index 397fee1b..0ad63d2b 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -232,7 +232,7 @@ ModFile::checkPass(bool nostrict) if (mod_file_struct.dsge_prior_weight_initialized && mod_file_struct.dsge_prior_weight_in_estimated_params) { - cerr << "ERROR: dsge_prior_weight cannot be both initalized and estimated." << endl; + cerr << "ERROR: dsge_prior_weight cannot be both initialized and estimated." << endl; exit(EXIT_FAILURE); } } diff --git a/StaticModel.cc b/StaticModel.cc index ecc50640..5c18d124 100644 --- a/StaticModel.cc +++ b/StaticModel.cc @@ -341,7 +341,7 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const } else { - cerr << "Type missmatch for equation " << equation_ID+1 << "\n"; + cerr << "Type mismatch for equation " << equation_ID+1 << "\n"; exit(EXIT_FAILURE); } output << ";\n"; From 507fad86a390736563022a06c4dc754abdbcee61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Wed, 28 Jun 2017 15:44:09 +0200 Subject: [PATCH 2/7] Cosmetic change. A "lag"" key with a negative value should be interpreted as a lead (and not a lag). Possible solutions are (1) Change the sign of the value, (2) Add a new key "lead" and consider only positive values, and (3) Change the key name for "shift" with negative values for lags and positive values for leads. The commit implements the third choice. --- DynamicModel.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index e935e1cc..a4f81a0c 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -5590,7 +5590,7 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c if (writeDetails) jacobian_output << "{\"eq\": " << eq + 1 << ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\"" - << ", \"lag\": " << getLagByDerivID(var); + << ", \"shift\": " << getLagByDerivID(var); else jacobian_output << "{\"row\": " << eq + 1; jacobian_output << ", \"col\": " << col + 1 @@ -5627,9 +5627,9 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c if (writeDetails) hessian_output << "{\"eq\": " << eq + 1 << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" - << ", \"lag1\": " << getLagByDerivID(var1) + << ", \"shift1\": " << getLagByDerivID(var1) << ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" - << ", \"lag2\": " << getLagByDerivID(var2); + << ", \"shift2\": " << getLagByDerivID(var2); else hessian_output << "{\"row\": " << eq + 1; @@ -5667,11 +5667,11 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c if (writeDetails) third_derivatives_output << "{\"eq\": " << eq + 1 << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" - << ", \"lag1\": " << getLagByDerivID(var1) + << ", \"shift1\": " << getLagByDerivID(var1) << ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" - << ", \"lag2\": " << getLagByDerivID(var2) + << ", \"shift2\": " << getLagByDerivID(var2) << ", \"var3\": \"" << symbol_table.getName(getSymbIDByDerivID(var3)) << "\"" - << ", \"lag3\": " << getLagByDerivID(var3); + << ", \"shift3\": " << getLagByDerivID(var3); else third_derivatives_output << "{\"row\": " << eq + 1; From 8b63e53d685d31ae0fe2e8e364bbbb2325a3b7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 28 Jun 2017 15:58:58 +0200 Subject: [PATCH 3/7] Add julia preprocessor to the clean rule. --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 892b2b17..5a8ac507 100644 --- a/Makefile.am +++ b/Makefile.am @@ -86,7 +86,7 @@ html-local: endif clean-local: - rm -rf ../matlab/preprocessor* + rm -rf ../matlab/preprocessor* ../julia/preprocessor* rm -rf doc/html/ EXTRA_DIST = $(BUILT_SOURCES) Doxyfile From c59b6ab0354ff5a4bab838440ae77518d100ff4d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 28 Jun 2017 17:11:24 +0200 Subject: [PATCH 4/7] preprocessor: write certain variables from M_ to JSON output --- DynamicModel.cc | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ DynamicModel.hh | 3 +++ ModFile.cc | 12 ++++++--- ModFile.hh | 2 +- 4 files changed, 83 insertions(+), 4 deletions(-) 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: From 955fb4f00338f20ba8883377136665bcc015348e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 29 Jun 2017 12:42:28 +0200 Subject: [PATCH 5/7] preprocessor: print JSON deriv detail by default; use option to print less-detailed versions of dynamic/static models --- DynamicModel.cc | 141 +++++++++++++++++++++++++++++------------------- DynareMain.cc | 12 ++--- DynareMain2.cc | 4 +- ModFile.cc | 82 ++++++++++++++-------------- ModFile.hh | 4 +- StaticModel.cc | 110 +++++++++++++++++++++++-------------- 6 files changed, 205 insertions(+), 148 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index f072fd95..e827d58c 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -5658,13 +5658,17 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c expr_t d1 = it->second; if (writeDetails) - jacobian_output << "{\"eq\": " << eq + 1 - << ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\"" - << ", \"shift\": " << getLagByDerivID(var); + jacobian_output << "{\"eq\": " << eq + 1; else jacobian_output << "{\"row\": " << eq + 1; - jacobian_output << ", \"col\": " << col + 1 - << ", \"val\": \""; + + jacobian_output << ", \"col\": " << col + 1; + + if (writeDetails) + jacobian_output << ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\"" + << ", \"shift\": " << getLagByDerivID(var); + + jacobian_output << ", \"val\": \""; d1->writeJsonOutput(jacobian_output, temp_term_union, tef_terms); jacobian_output << "\"}" << endl; } @@ -5695,19 +5699,22 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c int col_nb_sym = id2 * dynJacobianColsNbr + id1; if (writeDetails) - hessian_output << "{\"eq\": " << eq + 1 - << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" - << ", \"shift1\": " << getLagByDerivID(var1) - << ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" - << ", \"shift2\": " << getLagByDerivID(var2); + hessian_output << "{\"eq\": " << eq + 1; else hessian_output << "{\"row\": " << eq + 1; hessian_output << ", \"col\": [" << col_nb + 1; if (id1 != id2) hessian_output << ", " << col_nb_sym + 1; - hessian_output << "]" - << ", \"val\": \""; + hessian_output << "]"; + + if (writeDetails) + hessian_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" + << ", \"shift1\": " << getLagByDerivID(var1) + << ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" + << ", \"shift2\": " << getLagByDerivID(var2); + + hessian_output << ", \"val\": \""; d2->writeJsonOutput(hessian_output, temp_term_union, tef_terms); hessian_output << "\"}" << endl; } @@ -5735,13 +5742,7 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c expr_t d3 = it->second; if (writeDetails) - third_derivatives_output << "{\"eq\": " << eq + 1 - << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" - << ", \"shift1\": " << getLagByDerivID(var1) - << ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" - << ", \"shift2\": " << getLagByDerivID(var2) - << ", \"var3\": \"" << symbol_table.getName(getSymbIDByDerivID(var3)) << "\"" - << ", \"shift3\": " << getLagByDerivID(var3); + third_derivatives_output << "{\"eq\": " << eq + 1; else third_derivatives_output << "{\"row\": " << eq + 1; @@ -5763,17 +5764,26 @@ DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) c third_derivatives_output << ", "; third_derivatives_output << *it2 + 1; } - third_derivatives_output << "]" - << ", \"val\": \""; + third_derivatives_output << "]"; + + if (writeDetails) + third_derivatives_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" + << ", \"shift1\": " << getLagByDerivID(var1) + << ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" + << ", \"shift2\": " << getLagByDerivID(var2) + << ", \"var3\": \"" << symbol_table.getName(getSymbIDByDerivID(var3)) << "\"" + << ", \"shift3\": " << getLagByDerivID(var3); + + third_derivatives_output << ", \"val\": \""; d3->writeJsonOutput(third_derivatives_output, temp_term_union, tef_terms); third_derivatives_output << "\"}" << endl; } third_derivatives_output << "]}"; if (writeDetails) - output << "\"dynamic_model_derivative_details\": {"; + output << "\"dynamic_model\": {"; else - output << "\"dynamic_model_derivatives\": {"; + output << "\"dynamic_model_simple\": {"; output << model_local_vars_output.str() << ", " << model_output.str() << ", " << jacobian_output.str() @@ -5823,12 +5833,16 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; if (writeDetails) - jacobian_output << "{\"eq\": " << eq + 1 - << ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; + jacobian_output << "{\"eq\": " << eq + 1; else jacobian_output << "{\"row\": " << eq + 1; - jacobian_output << ", \"param_col\": " << param_col + 1 - << ", \"val\": \""; + + jacobian_output << ", \"param_col\": " << param_col + 1; + + if (writeDetails) + jacobian_output << ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; + + jacobian_output << ", \"val\": \""; d1->writeJsonOutput(jacobian_output, params_derivs_temporary_terms, tef_terms); jacobian_output << "\"}" << endl; } @@ -5853,15 +5867,19 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; if (writeDetails) - hessian_output << "{\"eq\": " << eq + 1 - << ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\"" - << ", \"lag\": " << getLagByDerivID(var) - << ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; + hessian_output << "{\"eq\": " << eq + 1; else hessian_output << "{\"row\": " << eq + 1; + hessian_output << ", \"var_col\": " << var_col + 1 - << ", \"param_col\": " << param_col + 1 - << ", \"val\": \""; + << ", \"param_col\": " << param_col + 1; + + if (writeDetails) + hessian_output << ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\"" + << ", \"lag\": " << getLagByDerivID(var) + << ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; + + hessian_output << ", \"val\": \""; d2->writeJsonOutput(hessian_output, params_derivs_temporary_terms, tef_terms); hessian_output << "\"}" << endl; } @@ -5887,14 +5905,17 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1; if (writeDetails) - hessian1_output << "{\"eq\": " << eq + 1 - << ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\"" - << ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\""; + hessian1_output << "{\"eq\": " << eq + 1; else hessian1_output << "{\"row\": " << eq + 1; hessian1_output << ", \"param1_col\": " << param1_col + 1 - << ", \"param2_col\": " << param2_col + 1 - << ", \"val\": \""; + << ", \"param2_col\": " << param2_col + 1; + + if (writeDetails) + hessian1_output << ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\"" + << ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\""; + + hessian1_output << ", \"val\": \""; d2->writeJsonOutput(hessian1_output, params_derivs_temporary_terms, tef_terms); hessian1_output << "\"}" << endl; } @@ -5922,17 +5943,21 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1; if (writeDetails) - third_derivs_output << "{\"eq\": " << eq + 1 - << ", \"var\": \"" << symbol_table.getName(var) << "\"" + third_derivs_output << "{\"eq\": " << eq + 1; + else + third_derivs_output << "{\"row\": " << eq + 1; + + third_derivs_output << ", \"var_col\": " << var_col + 1 + << ", \"param1_col\": " << param1_col + 1 + << ", \"param2_col\": " << param2_col + 1; + + if (writeDetails) + third_derivs_output << ", \"var\": \"" << symbol_table.getName(var) << "\"" << ", \"lag\": " << getLagByDerivID(var) << ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\"" << ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\""; - else - third_derivs_output << "{\"row\": " << eq + 1; - third_derivs_output << ", \"var_col\": " << var_col + 1 - << ", \"param1_col\": " << param1_col + 1 - << ", \"param2_col\": " << param2_col + 1 - << ", \"val\": \""; + + third_derivs_output << ", \"val\": \""; d2->writeJsonOutput(third_derivs_output, params_derivs_temporary_terms, tef_terms); third_derivs_output << "\"}" << endl; } @@ -5961,27 +5986,31 @@ DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; if (writeDetails) - third_derivs1_output << "{\"eq\": " << eq + 1 - << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" + third_derivs1_output << "{\"eq\": " << eq + 1; + else + third_derivs1_output << "{\"row\": " << eq + 1; + + third_derivs1_output << ", \"var1_col\": " << var1_col + 1 + << ", \"var2_col\": " << var2_col + 1 + << ", \"param_col\": " << param_col + 1; + + if (writeDetails) + third_derivs1_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" << ", \"lag1\": " << getLagByDerivID(var1) << ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" << ", \"lag2\": " << getLagByDerivID(var2) << ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; - else - third_derivs1_output << "{\"row\": " << eq + 1; - third_derivs1_output << ", \"var1_col\": " << var1_col + 1 - << ", \"var2_col\": " << var2_col + 1 - << ", \"param_col\": " << param_col + 1 - << ", \"val\": \""; + + third_derivs1_output << ", \"val\": \""; d2->writeJsonOutput(third_derivs1_output, params_derivs_temporary_terms, tef_terms); third_derivs1_output << "\"}" << endl; } third_derivs1_output << "]}" << endl; if (writeDetails) - output << "\"dynamic_model_params_derivative_details\": {"; + output << "\"dynamic_model_params_derivative\": {"; else - output << "\"dynamic_model_params_derivatives\": {"; + output << "\"dynamic_model_params_derivatives_simple\": {"; output << model_local_vars_output.str() << ", " << model_output.str() << ", " << jacobian_output.str() diff --git a/DynareMain.cc b/DynareMain.cc index 0230d732..49c26025 100644 --- a/DynareMain.cc +++ b/DynareMain.cc @@ -45,7 +45,7 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) , bool cygwin, bool msvc, bool mingw #endif - , JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonprintderivdetail + , JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple ); void main1(char *modfile, string &basename, bool debug, bool save_macro, string &save_macro_file, @@ -62,7 +62,7 @@ usage() #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) << " [cygwin] [msvc] [mingw]" #endif - << "[json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonprintderivdetail]" + << "[json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple]" << endl; exit(EXIT_FAILURE); } @@ -118,7 +118,7 @@ main(int argc, char **argv) JsonOutputPointType json = nojson; JsonFileOutputType json_output_mode = file; bool onlyjson = false; - bool jsonprintderivdetail = false; + bool jsonderivsimple = false; LanguageOutputType language = matlab; // Parse options @@ -301,8 +301,8 @@ main(int argc, char **argv) json_output_mode = standardout; else if (!strcmp(argv[arg], "onlyjson")) onlyjson = true; - else if (!strcmp(argv[arg], "jsonprintderivdetail")) - jsonprintderivdetail = true; + else if (!strcmp(argv[arg], "jsonderivsimple")) + jsonderivsimple = true; else if (strlen(argv[arg]) >= 4 && !strncmp(argv[arg], "json", 4)) { if (strlen(argv[arg]) <= 5 || argv[arg][4] != '=') @@ -370,7 +370,7 @@ main(int argc, char **argv) #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) , cygwin, msvc, mingw #endif - , json, json_output_mode, onlyjson, jsonprintderivdetail + , json, json_output_mode, onlyjson, jsonderivsimple ); return EXIT_SUCCESS; diff --git a/DynareMain2.cc b/DynareMain2.cc index 758b278f..e0a9e539 100644 --- a/DynareMain2.cc +++ b/DynareMain2.cc @@ -34,7 +34,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) , bool cygwin, bool msvc, bool mingw #endif - , JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonprintderivdetail + , JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple ) { ParsingDriver p(warnings, nostrict); @@ -60,7 +60,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear // Do computations mod_file->computingPass(no_tmp_terms, output_mode, params_derivs_order); if (json == computingpass) - mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, jsonprintderivdetail); + mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, jsonderivsimple); // Write outputs if (output_mode != none) diff --git a/ModFile.cc b/ModFile.cc index ba7a38c7..4098c8a2 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -1262,7 +1262,7 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output) } void -ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonprintderivdetail) +ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple) { if (json == nojson) return; @@ -1276,7 +1276,7 @@ ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonF symbol_table.unfreeze(); if (json == computingpass) - writeJsonComputingPassOutput(basename, json_output_mode, jsonprintderivdetail); + writeJsonComputingPassOutput(basename, json_output_mode, jsonderivsimple); switch (json) { @@ -1396,16 +1396,16 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType } void -ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonprintderivdetail) const +ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonderivsimple) const { - ostringstream static_output, static_detail_output; + ostringstream static_output, static_simple_output; static_output << "{"; - static_model.writeJsonComputingPassOutput(static_output, false); + static_model.writeJsonComputingPassOutput(static_output, true); static_output << "}" << endl; - ostringstream dynamic_output, dynamic_detail_output; + ostringstream dynamic_output, dynamic_simple_output; dynamic_output << "{"; - dynamic_model.writeJsonComputingPassOutput(dynamic_output, false); + dynamic_model.writeJsonComputingPassOutput(dynamic_output, true); dynamic_output << "}" << endl; ostringstream original_model_output; @@ -1413,42 +1413,42 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType original_model.writeJsonOriginalModelOutput(original_model_output); original_model_output << "}" << endl; - ostringstream tmp_out, static_paramsd_output, static_paramsd_detail_output; + ostringstream tmp_out, static_paramsd_output, static_paramsd_simple_output; tmp_out << ""; static_paramsd_output << ""; - static_paramsd_detail_output << ""; - static_model.writeJsonParamsDerivativesFile(tmp_out, false); + static_paramsd_simple_output << ""; + static_model.writeJsonParamsDerivativesFile(tmp_out, true); if (!tmp_out.str().empty()) static_paramsd_output << "{" << tmp_out.str() << "}" << endl; - ostringstream tmp1_out, dynamic_paramsd_output, dynamic_paramsd_detail_output; + ostringstream tmp1_out, dynamic_paramsd_output, dynamic_paramsd_simple_output; tmp1_out << ""; dynamic_paramsd_output << ""; - dynamic_paramsd_detail_output << ""; - dynamic_model.writeJsonParamsDerivativesFile(tmp1_out, false); + dynamic_paramsd_simple_output << ""; + dynamic_model.writeJsonParamsDerivativesFile(tmp1_out, true); if (!tmp1_out.str().empty()) dynamic_paramsd_output << "{" << tmp1_out.str() << "}" << endl; - if (jsonprintderivdetail) + if (jsonderivsimple) { - static_detail_output << "{"; - static_model.writeJsonComputingPassOutput(static_detail_output, true); - static_detail_output << "}"; + static_simple_output << "{"; + static_model.writeJsonComputingPassOutput(static_simple_output, false); + static_simple_output << "}"; - dynamic_detail_output << "{"; - dynamic_model.writeJsonComputingPassOutput(dynamic_detail_output, true); - dynamic_detail_output << "}"; + dynamic_simple_output << "{"; + dynamic_model.writeJsonComputingPassOutput(dynamic_simple_output, false); + dynamic_simple_output << "}"; ostringstream tmpd_out, tmpd1_out; tmpd_out << ""; tmpd1_out << ""; static_model.writeJsonParamsDerivativesFile(tmpd_out, true); if (!tmpd_out.str().empty()) - static_paramsd_detail_output << "{" << tmpd_out.str() << "}" << endl; + static_paramsd_simple_output << "{" << tmpd_out.str() << "}" << endl; dynamic_model.writeJsonParamsDerivativesFile(tmpd1_out, true); if (!tmpd1_out.str().empty()) - dynamic_paramsd_detail_output << "{" << tmpd1_out.str() << "}" << endl; + dynamic_paramsd_simple_output << "{" << tmpd1_out.str() << "}" << endl; } if (json_output_mode == standardout) @@ -1463,16 +1463,16 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType if (!dynamic_paramsd_output.str().empty()) cout << dynamic_paramsd_output.str() << endl; - if (jsonprintderivdetail) + if (jsonderivsimple) { - cout << static_detail_output.str() << endl - << dynamic_detail_output.str() << endl; + cout << static_simple_output.str() << endl + << dynamic_simple_output.str() << endl; - if (!static_paramsd_detail_output.str().empty()) - cout << static_paramsd_detail_output.str() << endl; + if (!static_paramsd_simple_output.str().empty()) + cout << static_paramsd_simple_output.str() << endl; - if (!dynamic_paramsd_detail_output.str().empty()) - cout << dynamic_paramsd_detail_output.str() << endl; + if (!dynamic_paramsd_simple_output.str().empty()) + cout << dynamic_paramsd_simple_output.str() << endl; } } else @@ -1492,32 +1492,32 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType writeJsonFileHelper(fname_static, static_output); writeJsonFileHelper(fname_dynamic, dynamic_output); - if (jsonprintderivdetail) + if (jsonderivsimple) { - string fname_static_details, fname_dynamic_details; - fname_static_details = basename + "_static_details.json"; - fname_dynamic_details = basename + "_dynamic_details.json"; + string fname_static_simple, fname_dynamic_simple; + fname_static_simple = basename + "_static_simple.json"; + fname_dynamic_simple = basename + "_dynamic_simple.json"; - writeJsonFileHelper(fname_static_details, static_detail_output); - writeJsonFileHelper(fname_dynamic_details, dynamic_detail_output); + writeJsonFileHelper(fname_static_simple, static_simple_output); + writeJsonFileHelper(fname_dynamic_simple, dynamic_simple_output); } if (!static_paramsd_output.str().empty()) { - string fname_static_params, fname_static_params_details; + string fname_static_params, fname_static_params_simple; fname_static_params = basename + "_static_params_derivs.json"; - fname_static_params_details = basename + "_static_params_derivs_details.json"; + fname_static_params_simple = basename + "_static_params_derivs_simple.json"; writeJsonFileHelper(fname_static_params, static_paramsd_output); - writeJsonFileHelper(fname_static_params_details, static_paramsd_detail_output); + writeJsonFileHelper(fname_static_params_simple, static_paramsd_simple_output); } if (!dynamic_paramsd_output.str().empty()) { - string fname_dynamic_params, fname_dynamic_params_details; + string fname_dynamic_params, fname_dynamic_params_simple; fname_dynamic_params = basename + "_params_derivs.json"; - fname_dynamic_params_details = basename + "_params_derivs_details.json"; + fname_dynamic_params_simple = basename + "_params_derivs_simple.json"; writeJsonFileHelper(fname_dynamic_params, dynamic_paramsd_output); - writeJsonFileHelper(fname_dynamic_params_details, dynamic_paramsd_detail_output); + writeJsonFileHelper(fname_dynamic_params_simple, dynamic_paramsd_simple_output); } } } diff --git a/ModFile.hh b/ModFile.hh index 985a15a7..7744d928 100644 --- a/ModFile.hh +++ b/ModFile.hh @@ -119,7 +119,7 @@ private: WarningConsolidation &warnings; //! Functions used in writing of JSON outut. See writeJsonOutput 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 writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonderivsimple) const; void writeJsonFileHelper(string &fname, ostringstream &output) const; public: //! Add a statement @@ -174,7 +174,7 @@ public: //! Initially created to enable Julia to work with .mod files //! Potentially outputs ModFile after the various parts of processing (parsing, checkPass, transformPass, computingPass) //! Allows user of other host language platforms (python, fortran, etc) to provide support for dynare .mod files - void writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonprintderivdetail = false); + void writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple = false); }; #endif // ! MOD_FILE_HH diff --git a/StaticModel.cc b/StaticModel.cc index 5c18d124..a398d1c4 100644 --- a/StaticModel.cc +++ b/StaticModel.cc @@ -2467,12 +2467,16 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co expr_t d1 = it->second; if (writeDetails) - jacobian_output << "{\"eq\": " << eq + 1 - << ", \"var\": \"" << symbol_table.getName(symb_id) << "\""; + jacobian_output << "{\"eq\": " << eq + 1; else jacobian_output << "{\"row\": " << eq + 1; - jacobian_output << ", \"col\": " << col + 1 - << ", \"val\": \""; + + jacobian_output << ", \"col\": " << col + 1; + + if (writeDetails) + jacobian_output << ", \"var\": \"" << symbol_table.getName(symb_id) << "\""; + + jacobian_output << ", \"val\": \""; d1->writeJsonOutput(jacobian_output, temp_term_union, tef_terms); jacobian_output << "\"}" << endl; } @@ -2506,13 +2510,16 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co int col_sym = tsid2*symbol_table.endo_nbr()+tsid1; if (writeDetails) - hessian_output << "{\"eq\": " << eq + 1 - << ", \"var1\": \"" << symbol_table.getName(symb_id1) << "\"" - << ", \"var2\": \"" << symbol_table.getName(symb_id2) << "\""; + hessian_output << "{\"eq\": " << eq + 1; else hessian_output << "{\"row\": " << eq + 1; hessian_output << ", \"col\": [" << col + 1; + + if (writeDetails) + hessian_output << ", \"var1\": \"" << symbol_table.getName(symb_id1) << "\"" + << ", \"var2\": \"" << symbol_table.getName(symb_id2) << "\""; + if (symb_id1 != symb_id2) hessian_output << ", " << col_sym + 1; hessian_output << "]" @@ -2544,10 +2551,7 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co expr_t d3 = it->second; if (writeDetails) - third_derivatives_output << "{\"eq\": " << eq + 1 - << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" - << ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" - << ", \"var3\": \"" << symbol_table.getName(getSymbIDByDerivID(var3)) << "\""; + third_derivatives_output << "{\"eq\": " << eq + 1; else third_derivatives_output << "{\"row\": " << eq + 1; @@ -2569,17 +2573,23 @@ StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) co third_derivatives_output << ", "; third_derivatives_output << *it2 + 1; } - third_derivatives_output << "]" - << ", \"val\": \""; + third_derivatives_output << "]"; + + if (writeDetails) + third_derivatives_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" + << ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" + << ", \"var3\": \"" << symbol_table.getName(getSymbIDByDerivID(var3)) << "\""; + + third_derivatives_output << ", \"val\": \""; d3->writeJsonOutput(third_derivatives_output, temp_term_union, tef_terms); third_derivatives_output << "\"}" << endl; } third_derivatives_output << "]}"; if (writeDetails) - output << "\"static_model_derivative_details\": {"; + output << "\"static_model\": {"; else - output << "\"static_model_derivatives\": {"; + output << "\"static_model_simple\": {"; output << model_local_vars_output.str() << ", " << model_output.str() << ", " << jacobian_output.str() @@ -2629,12 +2639,16 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; if (writeDetails) - jacobian_output << "{\"eq\": " << eq + 1 - << ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; + jacobian_output << "{\"eq\": " << eq + 1; else jacobian_output << "{\"row\": " << eq + 1; - jacobian_output << ", \"param_col\": " << param_col - << ", \"val\": \""; + + if (writeDetails) + jacobian_output << ", \"param_col\": " << param_col; + + jacobian_output << ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; + + jacobian_output << ", \"val\": \""; d1->writeJsonOutput(jacobian_output, params_derivs_temporary_terms, tef_terms); jacobian_output << "\"}" << endl; } @@ -2659,11 +2673,14 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; if (writeDetails) - hessian_output << "{\"eq\": " << eq + 1 - << ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\"" - << ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; + hessian_output << "{\"eq\": " << eq + 1; else hessian_output << "{\"row\": " << eq + 1; + + if (writeDetails) + hessian_output << ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\"" + << ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; + hessian_output << ", \"var_col\": " << var_col << ", \"param_col\": " << param_col << ", \"val\": \""; @@ -2692,14 +2709,18 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1; if (writeDetails) - hessian1_output << "{\"eq\": " << eq + 1 - << ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\"" - << ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\""; + hessian1_output << "{\"eq\": " << eq + 1; else hessian1_output << "{\"row\": " << eq + 1; + hessian1_output << ", \"param1_col\": " << param1_col - << ", \"param2_col\": " << param2_col - << ", \"val\": \""; + << ", \"param2_col\": " << param2_col; + + if (writeDetails) + hessian1_output << ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\"" + << ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\""; + + hessian1_output << ", \"val\": \""; d2->writeJsonOutput(hessian1_output, params_derivs_temporary_terms, tef_terms); hessian1_output << "\"}" << endl; } @@ -2727,16 +2748,19 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1; if (writeDetails) - third_derivs_output << "{\"eq\": " << eq + 1 - << ", \"var\": \"" << symbol_table.getName(var) << "\"" - << ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\"" - << ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\""; + third_derivs_output << "{\"eq\": " << eq + 1; else third_derivs_output << "{\"row\": " << eq + 1; third_derivs_output << ", \"var_col\": " << var_col << ", \"param1_col\": " << param1_col - << ", \"param2_col\": " << param2_col - << ", \"val\": \""; + << ", \"param2_col\": " << param2_col; + + if (writeDetails) + third_derivs_output << ", \"var\": \"" << symbol_table.getName(var) << "\"" + << ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\"" + << ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\""; + + third_derivs_output << ", \"val\": \""; d2->writeJsonOutput(third_derivs_output, params_derivs_temporary_terms, tef_terms); third_derivs_output << "\"}" << endl; } @@ -2765,25 +2789,29 @@ StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; if (writeDetails) - third_derivs1_output << "{\"eq\": " << eq + 1 - << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" - << ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" - << ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; + third_derivs1_output << "{\"eq\": " << eq + 1; else third_derivs1_output << "{\"row\": " << eq + 1; + third_derivs1_output << ", \"var1_col\": " << var1_col << ", \"var2_col\": " << var2_col - << ", \"param_col\": " << param_col - << ", \"val\": \""; + << ", \"param_col\": " << param_col; + + if (writeDetails) + third_derivs1_output << ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\"" + << ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\"" + << ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\""; + + third_derivs1_output << ", \"val\": \""; d2->writeJsonOutput(third_derivs1_output, params_derivs_temporary_terms, tef_terms); third_derivs1_output << "\"}" << endl; } third_derivs1_output << "]}" << endl; if (writeDetails) - output << "\"static_model_params_derivative_details\": {"; + output << "\"static_model_params_derivative\": {"; else - output << "\"static_model_params_derivatives\": {"; + output << "\"static_model_params_derivatives_simple\": {"; output << model_local_vars_output.str() << ", " << model_output.str() << ", " << jacobian_output.str() From 3597a41a4f68d54eadb37ca5f75d6bbd557dd96e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 29 Jun 2017 13:15:32 +0200 Subject: [PATCH 6/7] preprocessor: cleanup writing JSON to standardout --- ModFile.cc | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/ModFile.cc b/ModFile.cc index 4098c8a2..77805bc1 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -1270,6 +1270,9 @@ ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonF if (json == parsing || json == checkpass) symbol_table.freeze(); + if (json_output_mode == standardout) + cout << "{" << endl; + writeJsonOutputParsingCheck(basename, json_output_mode, json == transformpass, json == computingpass); if (json == parsing || json == checkpass) @@ -1278,6 +1281,9 @@ ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonF if (json == computingpass) writeJsonComputingPassOutput(basename, json_output_mode, jsonderivsimple); + if (json_output_mode == standardout) + cout << "}" << endl; + switch (json) { case parsing: @@ -1333,7 +1339,7 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType ostringstream original_model_output; original_model_output << ""; - if (transformpass) + if (transformpass || computingpass) { original_model_output << "{"; original_model.writeJsonOriginalModelOutput(original_model_output); @@ -1342,9 +1348,13 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType if (json_output_mode == standardout) { + if (transformpass || computingpass) + cout << "\"transformed_model\": "; + else + cout << "\"model\": "; cout << output.str(); if (!original_model_output.str().empty()) - cout << "," << original_model_output.str(); + cout << ", \"original_model\": " << original_model_output.str(); } else { @@ -1408,11 +1418,6 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType dynamic_model.writeJsonComputingPassOutput(dynamic_output, true); dynamic_output << "}" << endl; - ostringstream original_model_output; - original_model_output << "{"; - original_model.writeJsonOriginalModelOutput(original_model_output); - original_model_output << "}" << endl; - ostringstream tmp_out, static_paramsd_output, static_paramsd_simple_output; tmp_out << ""; static_paramsd_output << ""; @@ -1453,26 +1458,25 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType if (json_output_mode == standardout) { - cout << original_model_output.str() << endl - << static_output.str() << endl - << dynamic_output.str() << endl; + cout << ", \"static_model\": " << static_output.str() << endl + << ", \"dynamic_model\": " << dynamic_output.str() << endl; if (!static_paramsd_output.str().empty()) - cout << static_paramsd_output.str() << endl; + cout << ", \"static_params_deriv\": " << static_paramsd_output.str() << endl; if (!dynamic_paramsd_output.str().empty()) - cout << dynamic_paramsd_output.str() << endl; + cout << ", \"dynamic_params_deriv\":" << dynamic_paramsd_output.str() << endl; if (jsonderivsimple) { - cout << static_simple_output.str() << endl - << dynamic_simple_output.str() << endl; + cout << ", \"static_model_simple\": " << static_simple_output.str() << endl + << ", \"dynamic_model_simple\": " << dynamic_simple_output.str() << endl; if (!static_paramsd_simple_output.str().empty()) - cout << static_paramsd_simple_output.str() << endl; + cout << "," << static_paramsd_simple_output.str() << endl; if (!dynamic_paramsd_simple_output.str().empty()) - cout << dynamic_paramsd_simple_output.str() << endl; + cout << "," << dynamic_paramsd_simple_output.str() << endl; } } else @@ -1484,11 +1488,9 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType } string fname_original, fname_static, fname_dynamic; - fname_original = basename + "_original.json"; fname_static = basename + "_static.json"; fname_dynamic = basename + "_dynamic.json"; - writeJsonFileHelper(fname_original, original_model_output); writeJsonFileHelper(fname_static, static_output); writeJsonFileHelper(fname_dynamic, dynamic_output); From 478039db051907f3d947105ad7134c383fbebe8b Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 29 Jun 2017 13:18:59 +0200 Subject: [PATCH 7/7] preprocessor: couch JSON stdout output in constant text so users can easily find it --- ModFile.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ModFile.cc b/ModFile.cc index 77805bc1..130e6da3 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -1271,7 +1271,8 @@ ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonF symbol_table.freeze(); if (json_output_mode == standardout) - cout << "{" << endl; + cout << "//-- BEGIN JSON --// " << endl + << "{" << endl; writeJsonOutputParsingCheck(basename, json_output_mode, json == transformpass, json == computingpass); @@ -1282,7 +1283,8 @@ ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonF writeJsonComputingPassOutput(basename, json_output_mode, jsonderivsimple); if (json_output_mode == standardout) - cout << "}" << endl; + cout << "}" << endl + << "//-- END JSON --// " << endl; switch (json) {