More robust version of get_name_of_the_last_mh_file.m.

git-svn-id: https://www.dynare.org/svn/dynare/trunk@2558 ac1d8469-bf42-47a9-8791-bf33cf982152
time-shift
stepan 2009-04-06 14:58:44 +00:00
parent 2b0f2d5fd1
commit 2083b59072
2 changed files with 39 additions and 17 deletions

View File

@ -1,7 +1,7 @@
function [d1,d2] = get_date_of_a_file(filename)
%function [d1,d2] = get_date_of_a_file(filename)
% Copyright (C) 2008 Dynare Team
% Copyright (C) 2008-2009 Dynare Team
%
% This file is part of Dynare.
%
@ -19,7 +19,10 @@ function [d1,d2] = get_date_of_a_file(filename)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
info = dir(filename);
if isempty(info)
error(['get_date_of_a_file:: I''m not able to find ' filename '!'])
end
d1 = info.datenum;
if nargout>1
d2 = info.date;
end
end

View File

@ -1,7 +1,17 @@
function mhname = get_name_of_the_last_mh_file(M_)
%function mhname = get_name_of_the_last_mh_file(M_)
% Copyright (C) 2008 Dynare Team
function [mhname,info] = get_name_of_the_last_mh_file(M_)
% This function returns the name of the last mh file and test if the metropolis was completed.
%
% INPUTS
% M_ [structure] Dynare structure specifying the model.
%
% OUTPUTS
% mhname [string] Name of the last mh file (with complete path).
% info [integer] Scalar. If info is equal to 1 then the predicted name of the last
% metropolis hastings matches the name of the name of the last mh
% file. Otherwise info is equal to zero (a likely reason for this is
% that the mcmc simulations were not completed).
% Copyright (C) 2008-2009 Dynare Team
%
% This file is part of Dynare.
%
@ -18,17 +28,26 @@ function mhname = get_name_of_the_last_mh_file(M_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
model_name = M_.fname ;
mcmc_directory = M_.dname ;
load([ mcmc_directory '/metropolis/' model_name '_mh_history.mat']) ;
mhname = [];
info = 1;
MhDirectoryName = CheckPath('metropolis');
load([ MhDirectoryName '/' M_.fname '_mh_history.mat']) ;
mh_number = record.LastFileNumber ;
bk_number = record.Nblck ;
clear('record') ;
mhname = [ mcmc_directory ...
'/metropolis/' ...
model_name ...
'_mh' ...
int2str(mh_number) ...
'_blck' ...
int2str(bk_number) ...
'.mat'] ;
predicted_mhname = [ MhDirectoryName '/' M_.fname '_mh' int2str(mh_number) '_blck' int2str(bk_number) '.mat' ] ;
AllMhFiles = dir([MhDirectoryName '/' M_.fname '_mh*_blck*' ]);
idx = 1;
for i=2:size(AllMhFiles)
if AllMhFiles(i).datenum>AllMhFiles(i-1).datenum
idx = i;
end
end
mhname = [ MhDirectoryName '/' AllMhFiles(idx).name];
if ~strcmpi(mhname,predicted_mhname)
info = 0;
end