From e247e3ef0bf6d81b34a040f3a4ef7e9c052344c1 Mon Sep 17 00:00:00 2001 From: george <george@ac1d8469-bf42-47a9-8791-bf33cf982152> Date: Wed, 28 Jan 2009 19:26:40 +0000 Subject: [PATCH] Update: k_ord_dynare.cpp that prints the order when running ReorderDynareJacobianIndice and k_order_perturbation with MAT file printout git-svn-id: https://www.dynare.org/svn/dynare/trunk@2380 ac1d8469-bf42-47a9-8791-bf33cf982152 --- mex/sources/korderpert/src/k_ord_dynare.cpp | 4 ++ .../korderpert/src/k_order_perturbation.cpp | 54 ++++++++++--------- .../korderpert/src/k_order_test_main.cpp | 3 +- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/mex/sources/korderpert/src/k_ord_dynare.cpp b/mex/sources/korderpert/src/k_ord_dynare.cpp index 7742fff852..0fd0803641 100644 --- a/mex/sources/korderpert/src/k_ord_dynare.cpp +++ b/mex/sources/korderpert/src/k_ord_dynare.cpp @@ -402,6 +402,10 @@ Vector * KordpDynare::LLxSteady( const Vector& yS){ mexPrintf(" Error in LLxSteady - wrong index?"); } +#ifdef DEBUG + for (int j=0;j<nJcols-nExog;j++) + mexPrintf("LLxSteady: [%d] =%f .\n", j, (*llxSteady)[j]); +#endif return llxSteady; } diff --git a/mex/sources/korderpert/src/k_order_perturbation.cpp b/mex/sources/korderpert/src/k_order_perturbation.cpp index 0b71101f75..f68dfc0801 100644 --- a/mex/sources/korderpert/src/k_order_perturbation.cpp +++ b/mex/sources/korderpert/src/k_order_perturbation.cpp @@ -269,39 +269,43 @@ extern "C" { else irf_list_ind = ((const DynareNameList&)dynare.getExogNames()).selectIndices(params.irf_list); ****************/ - try { // intiate tensor library #ifdef DEBUG - mexPrintf("k_order_perturbation: Call tls init\n"); + mexPrintf("k_order_perturbation: Call tls init\n"); #endif - tls.init(dynare.order(), - dynare.nstat()+2*dynare.npred()+3*dynare.nboth()+ - 2*dynare.nforw()+dynare.nexog()); - - // construct main K-order approximation class + tls.init(dynare.order(), + dynare.nstat()+2*dynare.npred()+3*dynare.nboth()+ + 2*dynare.nforw()+dynare.nexog()); + + // construct main K-order approximation class // FistOrderApproximation app(dynare, journal, nSteps); #ifdef DEBUG - mexPrintf("k_order_perturbation: Call Approximation constructor \n"); + mexPrintf("k_order_perturbation: Call Approximation constructor \n"); #endif - Approximation app(dynare, journal, nSteps); - // run stochastic steady + Approximation app(dynare, journal, nSteps); + // run stochastic steady #ifdef DEBUG - mexPrintf("k_order_perturbation: Calling walkStochSteady.\n"); + mexPrintf("k_order_perturbation: Calling walkStochSteady.\n"); #endif - app.walkStochSteady(); - - } catch (const KordException& e) { - // tell about the exception and continue - printf("Caught (not yet fatal) Kord exception: "); - e.print(); - JournalRecord rec(journal); - rec << "Solution routine not finished (" << e.get_message() - << "), see what happens" << endrec; - } catch (const TLException& e) { - mexErrMsgTxt("Caugth TL exception."); - } catch (SylvException& e) { - mexErrMsgTxt("Caught Sylv exception."); - } + app.walkStochSteady(); + + // open mat file + std::string matfile(fName);//(params.basename); + matfile += ".mat"; + FILE* matfd = NULL; + if (NULL == (matfd=fopen(matfile.c_str(), "wb"))) { + fprintf(stderr, "Couldn't open %s for writing.\n", matfile.c_str()); + exit(1); + } + + std::string ss_matrix_name(fName);//params.prefix); + ss_matrix_name += "_steady_states"; + ConstTwoDMatrix(app.getSS()).writeMat4(matfd, ss_matrix_name.c_str()); + + // write the folded decision rule to the Mat-4 file + app.getFoldDecisionRule().writeMat4(matfd, fName);//params.prefix); + + fclose(matfd); /*********************** std::string ss_matrix_name("K_ordp");//params.prefix); diff --git a/mex/sources/korderpert/src/k_order_test_main.cpp b/mex/sources/korderpert/src/k_order_test_main.cpp index 4b537ffb4d..f8c9487cff 100644 --- a/mex/sources/korderpert/src/k_order_test_main.cpp +++ b/mex/sources/korderpert/src/k_order_test_main.cpp @@ -215,8 +215,7 @@ int main(int argc, char* argv[]) mexPrintf("k_order_perturbation: Calling walkStochSteady.\n"); #endif app.walkStochSteady(); - - + // open mat file std::string matfile(fName);//(params.basename); matfile += ".mat"; -- GitLab