Skip to content
Snippets Groups Projects
Verified Commit 8b197bf7 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Remove duplicate assignments for parameters.

parent 4386116c
Branches
No related tags found
No related merge requests found
......@@ -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));
......
......@@ -4,4 +4,5 @@ c3 = -.3;
d3 = -.4;
e3 = -.5;
f3 = -.6;
g3 = -.7;
\ No newline at end of file
g3 = -.7;
g1 = .7;
parameters a3 b3 c3 d3 e3 f3 g3;
\ No newline at end of file
parameters a3 b3 c3 d3 e3 f3 g3 g1;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment