diff --git a/matlab/aggregate.m b/matlab/aggregate.m index 6c4a65dd5..4af51d5bd 100644 --- a/matlab/aggregate.m +++ b/matlab/aggregate.m @@ -166,7 +166,7 @@ xlist = xlist(1:xnum,:); xlist = xlist(idx,:); % Get parameter values. -calibration = ''; +pArray = cell(0, 3); for i=1:length(varargin) fid = fopen(sprintf('%s/parameter-values.inc', varargin{i})); if fid<0 @@ -176,12 +176,51 @@ for i=1:length(varargin) end cline = fgetl(fid); while ischar(cline) - calibration = sprintf('%s\n%s', calibration, cline); + tmp = textscan(cline, '%s = %f', 'Delimiter', {';','=',' '}); + pArray(end+1,1) = tmp{1}; + pArray{end,2} = tmp{2}; + pArray{end,3} = varargin{i}; cline = fgetl(fid); end fclose(fid); end +if rows(pArray)>1 + irow = 2; + while irow<=rows(pArray) + ispreviouslydefined = strcmpi(pArray{irow,1}, pArray(1:irow-1,1)); + if any(ispreviouslydefined) + if isnan(pArray{ispreviouslydefined,2}) + if ~isnan(pArray{irow,2}) + % Remove first assignment (with NaN) + pArray(ispreviouslydefined,:) = []; + else + % Remove second assignment (both assigments are NaNs) + pArray(irow,:) = []; + end + elseif isnan(pArray{irow,2}) + % New assigment is NaN but not the previous one. + pArray(irow,:) = []; + else + % Check that the values are identical in both assignments. + if abs(pArray{ispreviouslydefined,2}-pArray{irow,2})>1e-10 + error('More than one assigment for parameter %s with different values (see cherrypicked files in %s and %s).', pArray{irow,1}, pArray{irow,3}, pArray{ispreviouslydefined,3}); + else + % Remove last assignement (duplicate). + pArray(irow,:) = []; + end + end + else + irow = irow+1; + end + end +end + +calibration = ''; +for i=1:rows(pArray) + calibration = sprintf('%s%s = %f;\n', calibration, pArray{i,1}, pArray{i,2}); +end + % Move the endogenous variables which are not LHS of an equation % into the set of exogenous variables. [~, i1] = intersect(elist(:,1), eqlist(:,1)); diff --git a/tests/ecb/aggregate/3/parameter-values.inc b/tests/ecb/aggregate/3/parameter-values.inc index 5650b370d..086291556 100644 --- a/tests/ecb/aggregate/3/parameter-values.inc +++ b/tests/ecb/aggregate/3/parameter-values.inc @@ -4,4 +4,5 @@ c3 = -.3; d3 = -.4; e3 = -.5; f3 = -.6; -g3 = -.7; \ No newline at end of file +g3 = -.7; +g1 = .7; diff --git a/tests/ecb/aggregate/3/parameters.inc b/tests/ecb/aggregate/3/parameters.inc index f64aed1e0..10d830ddd 100644 --- a/tests/ecb/aggregate/3/parameters.inc +++ b/tests/ecb/aggregate/3/parameters.inc @@ -1 +1 @@ -parameters a3 b3 c3 d3 e3 f3 g3; \ No newline at end of file +parameters a3 b3 c3 d3 e3 f3 g3 g1;