From 767dce0a3be78a26d1ac5f75770d1c06995a7b01 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 18 May 2013 19:00:11 +0200 Subject: [PATCH] Check in McMCDiagnostics.m whether all consecutive MH files are present Closes #390 --- matlab/McMCDiagnostics.m | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/matlab/McMCDiagnostics.m b/matlab/McMCDiagnostics.m index 8e4303155..ffc6f2fc3 100644 --- a/matlab/McMCDiagnostics.m +++ b/matlab/McMCDiagnostics.m @@ -16,7 +16,7 @@ function McMCDiagnostics(options_, estim_params_, M_) % PARALLEL CONTEXT % See the comment in random_walk_metropolis_hastings.m funtion. -% Copyright (C) 2005-2012 Dynare Team +% Copyright (C) 2005-2013 Dynare Team % % This file is part of Dynare. % @@ -52,6 +52,10 @@ MAX_nruns = ceil(options_.MaxNumberOfBytes/(npar+2)/8); load([MhDirectoryName '/' M_.fname '_mh_history.mat']) NumberOfMcFilesPerBlock = size(dir([MhDirectoryName ,filesep, M_.fname '_mh*_blck1.mat']),1); + +% check if all previous files are there for block 1 +check_presence_consecutive_MC_files(MhDirectoryName,M_.fname,1) + for blck = 2:nblck tmp = size(dir([MhDirectoryName ,filesep, M_.fname '_mh*_blck' int2str(blck) '.mat']),1); if tmp~=NumberOfMcFilesPerBlock @@ -59,6 +63,8 @@ for blck = 2:nblck disp([' the number of mh files in chain 1 is ' int2str(mcfiles) '!']) error('The number of mh files has to be constant across chains!') end + % check if all previous files are there for block blck + check_presence_consecutive_MC_files(MhDirectoryName,M_.fname,blck) end PastDraws = sum(record.MhDraws,1); @@ -358,4 +364,16 @@ if TeX fprintf(fidTeX,'\n'); fprintf(fidTeX,'% End Of TeX file.'); fclose(fidTeX); -end \ No newline at end of file +end + +function check_presence_consecutive_MC_files(MhDirectoryName,fname,blck) +% check if all previous files are there +files=ls([MhDirectoryName ,filesep, fname '_mh*_blck' int2str(blck) '.mat']); %list files +right_string=files(:,length([fname '_mh'])+1:end); %cut off left part of filename +k = cell2mat(strfind(cellstr(right_string),['_blck' int2str(blck) '.mat'])); %find index of position after number +file_numbers=str2num(right_string(:,1:k-1)); %get file number +if sum(sort(file_numbers)-(min(file_numbers):max(file_numbers))')~=0 + error(['There are MH draw files missing within chain ', int2str(blck)]) +end + +