From 1424cf2ec9432f5b82ba76063454f0db9ee9edd1 Mon Sep 17 00:00:00 2001
From: Michel Juillard <michel.juillard@mjui.fr>
Date: Sun, 24 Jun 2012 11:23:12 +0200
Subject: [PATCH] k_order mex: added derivatives as members of KorderpDynare
 (cherry picked from commit 287b1348841b7ef3424dc259bcb9ef509815977a)

---
 mex/sources/k_order_perturbation/k_ord_dynare.cc | 11 +++++------
 mex/sources/k_order_perturbation/k_ord_dynare.hh |  4 ++++
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/mex/sources/k_order_perturbation/k_ord_dynare.cc b/mex/sources/k_order_perturbation/k_ord_dynare.cc
index d932743028..46aafbb958 100644
--- a/mex/sources/k_order_perturbation/k_ord_dynare.cc
+++ b/mex/sources/k_order_perturbation/k_ord_dynare.cc
@@ -89,10 +89,8 @@ KordpDynare::evaluateSystem(Vector &out, const Vector &yym, const Vector &yy,
 void
 KordpDynare::calcDerivativesAtSteady() throw (DynareException)
 {
-  TwoDMatrix g1(nY, nJcols);
-  g1.zeros();
-
-  TwoDMatrix *g2p = NULL, *g3p = NULL;
+  g1p = new TwoDMatrix(nY, nJcols);
+  g1p->zeros();
 
   if (nOrder > 1)
     {
@@ -115,9 +113,10 @@ KordpDynare::calcDerivativesAtSteady() throw (DynareException)
   Vector llxSteady(nJcols-nExog);
   LLxSteady(ySteady, llxSteady);
 
-  dynamicModelFile->eval(llxSteady, xx, params, ySteady, out, &g1, g2p, g3p);
+  dynamicModelFile->eval(llxSteady, xx, params, ySteady, out, g1p, g2p, g3p);
 
-  populateDerivativesContainer(g1, 1, JacobianIndices);
+  populateDerivativesContainer(*g1p, 1, JacobianIndices);
+  delete g1p;
 
   if (nOrder > 1)
     {
diff --git a/mex/sources/k_order_perturbation/k_ord_dynare.hh b/mex/sources/k_order_perturbation/k_ord_dynare.hh
index 3629c3d74a..262fecf211 100644
--- a/mex/sources/k_order_perturbation/k_ord_dynare.hh
+++ b/mex/sources/k_order_perturbation/k_ord_dynare.hh
@@ -113,6 +113,10 @@ class KordpDynare : public DynamicModel
   const TwoDMatrix &ll_Incidence;
   double qz_criterium;
   vector<int> JacobianIndices;
+
+  TwoDMatrix *g1p;
+  TwoDMatrix *g2p;
+  TwoDMatrix *g3p;
 public:
   KordpDynare(const vector<string> &endo, int num_endo,
               const vector<string> &exo, int num_exo, int num_par,
-- 
GitLab