From f39f57b9b5ee60b8ba86aa023c1d31b03584f5ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemia=20=28Scylla=29?= <stepan@dynare.org>
Date: Tue, 2 Apr 2019 07:11:32 +0200
Subject: [PATCH] Added parameter values in cherrypick/agregate routines.

---
 matlab/agregate.m                         | 16 +++++++++++++++-
 matlab/cherrypick.m                       |  9 +++++++++
 tests/ecb/agregate/1/parameter-values.inc |  7 +++++++
 tests/ecb/agregate/2/parameter-values.inc |  7 +++++++
 4 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 tests/ecb/agregate/1/parameter-values.inc
 create mode 100644 tests/ecb/agregate/2/parameter-values.inc

diff --git a/matlab/agregate.m b/matlab/agregate.m
index e52c5e8ff9..0df7c27e25 100644
--- a/matlab/agregate.m
+++ b/matlab/agregate.m
@@ -19,7 +19,7 @@ function agregate(ofile, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-MAX_NUMBER_OF_ELEMENTS = 1000;
+MAX_NUMBER_OF_ELEMENTS = 10000;
 
 warning off MATLAB:subscripting:noSubscriptsSpecified
 
@@ -107,6 +107,18 @@ for i=1:length(varargin)
 end
 xlist = xlist(1:xnum,:);
 
+% Get parameter values.
+calibration = '';
+for i=1:length(varargin)
+    fid = fopen(sprintf('%s/parameter-values.inc', varargin{i}));
+    cline = fgetl(fid);
+    while ischar(cline)
+        calibration = sprintf('%s\n%s', calibration, cline);
+        cline = fgetl(fid);
+    end
+    fclose(fid);
+end
+
 % Move the endogenous variables which are not LHS of an equation
 % into the set of exogenous variables.
 [~, i1] = intersect(elist(:,1), eqlist(:,1));
@@ -132,6 +144,8 @@ for i=1:length(plist)
     fprintf(fid, '\t%s\n', plist{i});
 end
 fprintf(fid, ';\n\n');
+fprintf(fid, calibration);
+fprintf(fid, '\n\n');
 fprintf(fid, 'var\n');
 for i=1:rows(elist)
     if isempty(elist{i,2})
diff --git a/matlab/cherrypick.m b/matlab/cherrypick.m
index 467124c56a..992353a0a6 100644
--- a/matlab/cherrypick.m
+++ b/matlab/cherrypick.m
@@ -168,6 +168,15 @@ fid = fopen(sprintf('%s/exogenous.inc', outfold), 'w');
 printlistofvariables(fid, 'exo', xlist, M_);
 fclose(fid);
 
+% Export parameter values
+fid = fopen(sprintf('%s/parameter-values.inc', outfold), 'w');
+for i=1:length(plist)
+    id = strcmp(plist{i}, M_.param_names);
+    if any(id)
+        fprintf(fid, '%s = %s;\n', plist{i}, num2str(M_.params(id), 16));
+    end
+end
+fclose(fid);
 
 function printlistofvariables(fid, kind, list, DynareModel)
     if isfield(DynareModel, sprintf('%s_partitions', kind))
diff --git a/tests/ecb/agregate/1/parameter-values.inc b/tests/ecb/agregate/1/parameter-values.inc
new file mode 100644
index 0000000000..a9cd8ce5ac
--- /dev/null
+++ b/tests/ecb/agregate/1/parameter-values.inc
@@ -0,0 +1,7 @@
+a1 = .1;
+b1 = .2;
+c1 = .3;
+d1 = .4;
+e1 = .5;
+f1 = .6;
+g1 = .7;
\ No newline at end of file
diff --git a/tests/ecb/agregate/2/parameter-values.inc b/tests/ecb/agregate/2/parameter-values.inc
new file mode 100644
index 0000000000..7eab0b0d9e
--- /dev/null
+++ b/tests/ecb/agregate/2/parameter-values.inc
@@ -0,0 +1,7 @@
+a2 = -.1;
+b2 = -.2;
+c2 = -.3;
+d2 = -.4;
+e2 = -.5;
+f2 = -.6;
+g2 = -.7;
\ No newline at end of file
-- 
GitLab