From 2083b59072daf91368854b3e71254959900482fb Mon Sep 17 00:00:00 2001 From: stepan Date: Mon, 6 Apr 2009 14:58:44 +0000 Subject: [PATCH] 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 --- matlab/get_date_of_a_file.m | 7 ++-- matlab/get_name_of_the_last_mh_file.m | 49 +++++++++++++++++++-------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/matlab/get_date_of_a_file.m b/matlab/get_date_of_a_file.m index a3155e0f6..b980eea6a 100644 --- a/matlab/get_date_of_a_file.m +++ b/matlab/get_date_of_a_file.m @@ -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 . 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 \ No newline at end of file diff --git a/matlab/get_name_of_the_last_mh_file.m b/matlab/get_name_of_the_last_mh_file.m index 95cee5bc0..3a3366450 100644 --- a/matlab/get_name_of_the_last_mh_file.m +++ b/matlab/get_name_of_the_last_mh_file.m @@ -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 . - 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'] ; \ No newline at end of file + 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 \ No newline at end of file