Reorder files generated by “moments_varendo” option of “estimation”

If there were more than 10 files of Metropolis parameter draws, the ordering
the files containing the posterior moments could be different from that of the
parameter draws. This is because the “dir()” command was used to order the
files containing the parameter draws, and because the command uses alphabetic
ordering, file #10 would come before #2.

This commit enforces the numerical ordering of files.
parent 8c6b24db
......@@ -19,7 +19,7 @@ function [nvar,vartan,NumberOfConditionalDecompFiles] = ...
% vartan [char] array of characters (with nvar rows).
% NumberOfConditionalDecompFiles [integer] scalar, number of prior or posterior data files (for covariance).
% Copyright (C) 2009-2015 Dynare Team
% Copyright (C) 2009-2020 Dynare Team
%
% This file is part of Dynare.
%
......@@ -39,10 +39,10 @@ function [nvar,vartan,NumberOfConditionalDecompFiles] = ...
% Get informations about the _posterior_draws files.
if strcmpi(type,'posterior')
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
NumberOfDrawsFiles = length(dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]));
posterior = 1;
elseif strcmpi(type,'prior')
DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
NumberOfDrawsFiles = length(dir([M_.dname '/prior/draws/' type '_draws*' ]));
CheckPath('prior/moments',M_.dname);
posterior = 0;
else
......@@ -78,7 +78,6 @@ nvar = length(ivar);
nar = options_.ar;
options_.ar = 0;
NumberOfDrawsFiles = rows(DrawsFiles);
NumberOfSavedElementsPerSimulation = nvar*M_.exo_nbr*length(Steps);
MaXNumberOfConditionalDecompLines = ceil(options_.MaxNumberOfBytes/NumberOfSavedElementsPerSimulation/8);
......@@ -132,9 +131,9 @@ linea = 0;
linea_ME = 0;
for file = 1:NumberOfDrawsFiles
if posterior
load([M_.dname '/metropolis/' DrawsFiles(file).name ]);
load([M_.dname '/metropolis/' M_.fname '_' type '_draws' num2str(file) ]);
else
load([M_.dname '/prior/draws/' DrawsFiles(file).name ]);
load([M_.dname '/prior/draws/' type '_draws' num2str(file) ]);
end
isdrsaved = columns(pdraws)-1;
NumberOfDraws = rows(pdraws);
......
......@@ -17,7 +17,7 @@ function [nvar,vartan,CorrFileNumber] = dsge_simulated_theoretical_correlation(S
% vartan [char] array of characters (with nvar rows).
% CorrFileNumber [integer] scalar, number of prior or posterior data files (for correlation).
% Copyright (C) 2007-2017 Dynare Team
% Copyright (C) 2007-2020 Dynare Team
%
% This file is part of Dynare.
%
......@@ -38,17 +38,16 @@ nodecomposition = 1;
% Get informations about the _posterior_draws files.
if strcmpi(type,'posterior')
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
NumberOfDrawsFiles = length(dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]));
posterior = 1;
elseif strcmpi(type,'prior')
DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
NumberOfDrawsFiles = length(dir([M_.dname '/prior/draws/' type '_draws*' ]));
CheckPath('prior/moments',M_.dname);
posterior = 0;
else
disp('dsge_simulated_theoretical_correlation:: Unknown type!');
error()
end
NumberOfDrawsFiles = length(DrawsFiles);
%delete old stale files before creating new ones
if posterior
......@@ -95,9 +94,9 @@ CorrFileNumber = 1;
linea = 0;
for file = 1:NumberOfDrawsFiles
if posterior
load([M_.dname '/metropolis/' DrawsFiles(file).name ]);
load([M_.dname '/metropolis/' M_.fname '_' type '_draws' num2str(file) ]);
else
load([M_.dname '/prior/draws/' DrawsFiles(file).name]);
load([M_.dname '/prior/draws/' type '_draws' num2str(file) ]);
end
NumberOfDraws = rows(pdraws);
isdrsaved = columns(pdraws)-1;
......@@ -136,4 +135,4 @@ for file = 1:NumberOfDrawsFiles
end
end
options_.ar = oldnar;
\ No newline at end of file
options_.ar = oldnar;
......@@ -16,7 +16,7 @@ function [nvar,vartan,CovarFileNumber] = dsge_simulated_theoretical_covariance(S
% vartan [char] array of characters (with nvar rows).
% CovarFileNumber [integer] scalar, number of prior or posterior data files (for covariance).
% Copyright (C) 2007-2017 Dynare Team
% Copyright (C) 2007-2020 Dynare Team
%
% This file is part of Dynare.
%
......@@ -37,17 +37,16 @@ nodecomposition = 1;
% Get informations about the _posterior_draws files.
if strcmpi(type,'posterior')
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
NumberOfDrawsFiles = length(dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]));
posterior = 1;
elseif strcmpi(type,'prior')
DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
NumberOfDrawsFiles = length(dir([M_.dname '/prior/draws/' type '_draws*' ]));
CheckPath('prior/moments',M_.dname);
posterior = 0;
else
disp('dsge_simulated_theoretical_covariance:: Unknown type!')
error();
end
NumberOfDrawsFiles = length(DrawsFiles);
%delete old stale files before creating new ones
if posterior
......@@ -94,9 +93,9 @@ CovarFileNumber = 1;
linea = 0;
for file = 1:NumberOfDrawsFiles
if posterior
load([M_.dname '/metropolis/' DrawsFiles(file).name ],'pdraws');
load([M_.dname '/metropolis/' M_.fname '_' type '_draws' num2str(file) ]);
else
load([M_.dname '/prior/draws/' DrawsFiles(file).name ],'pdraws');
load([M_.dname '/prior/draws/' type '_draws' num2str(file) ]);
end
NumberOfDraws = rows(pdraws);
isdrsaved = columns(pdraws)-1;
......@@ -136,4 +135,4 @@ for file = 1:NumberOfDrawsFiles
end
end
options_.ar = nar;
\ No newline at end of file
options_.ar = nar;
......@@ -18,7 +18,7 @@ function [nvar,vartan,NumberOfDecompFiles] = ...
% vartan [char] array of characters (with nvar rows).
% CovarFileNumber [integer] scalar, number of prior or posterior data files (for covariance).
% Copyright (C) 2007-2017 Dynare Team
% Copyright (C) 2007-2020 Dynare Team
%
% This file is part of Dynare.
%
......@@ -39,10 +39,10 @@ nodecomposition = 0;
% Get informations about the _posterior_draws files.
if strcmpi(type,'posterior')
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
NumberOfDrawsFiles = length(dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]));
posterior = 1;
elseif strcmpi(type,'prior')
DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
NumberOfDrawsFiles = length(dir([M_.dname '/prior/draws/' type '_draws*' ]));
CheckPath('prior/moments',M_.dname);
posterior = 0;
else
......@@ -81,7 +81,6 @@ options_.ar = 0;
nexo = M_.exo_nbr;
NumberOfDrawsFiles = rows(DrawsFiles);
NumberOfSavedElementsPerSimulation = nvar*(nexo+1);
MaXNumberOfDecompLines = ceil(options_.MaxNumberOfBytes/NumberOfSavedElementsPerSimulation/8);
......@@ -131,9 +130,9 @@ linea_ME = 0;
only_non_stationary_vars=0;
for file = 1:NumberOfDrawsFiles
if posterior
load([M_.dname '/metropolis/' DrawsFiles(file).name ]);
load([M_.dname '/metropolis/' M_.fname '_' type '_draws' num2str(file) ]);
else
load([M_.dname '/prior/draws/' DrawsFiles(file).name ]);
load([M_.dname '/prior/draws/' type '_draws' num2str(file) ]);
end
isdrsaved = columns(pdraws)-1;
NumberOfDraws = rows(pdraws);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment