added dname as argument to CheckPath function and changed all calls to

this function. Suppressed use of globals in CheckPath.
time-shift
Michel Juillard 2011-12-15 11:56:23 +01:00
parent d0e458eb79
commit 7408714ea1
38 changed files with 73 additions and 74 deletions

View File

@ -1,8 +1,9 @@
function DirectoryName = CheckPath(type)
function DirectoryName = CheckPath(type,dname)
% Creates the subfolder "./M_.dname/type" if it does not exist yet.
%
% INPUTS
% type [string] Name of the subfolder.
% type [string] Name of the subfolder.
% dname [string] Name of the directory
%
% OUTPUTS
% none.
@ -27,14 +28,12 @@ function DirectoryName = CheckPath(type)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
global M_
DirectoryName = [ dname '/' type ];
DirectoryName = [ M_.dname '/' type ];
if ~isdir(M_.dname)
if ~isdir(dname)
% Make sure there isn't a file with the same name, see trac ticket #47
delete(M_.dname)
mkdir('.', M_.dname);
delete(dname)
mkdir('.', dname);
end
if ~isdir(DirectoryName)

View File

@ -33,7 +33,7 @@ function CutSample(M_, options_, estim_params_)
npar = estim_params_.np+estim_params_.nvn+estim_params_.ncx+estim_params_.ncn+estim_params_.nvx;
DirectoryName = CheckPath('metropolis');
DirectoryName = CheckPath('metropolis',M_.dname);
file = dir([ DirectoryName ,filesep, M_.fname '_mh_history.mat']);
files = dir([ DirectoryName ,filesep, M_.fname '_mh*.mat' ]);
if ~length(files)

View File

@ -39,7 +39,7 @@ nblck = options_.mh_nblck;
iline = FirstLine;
linee = 1;
DirectoryName = CheckPath('metropolis');
DirectoryName = CheckPath('metropolis',M_.dname);
if nblck>1 && nargin<6
Draws = zeros(NumberOfDraws*nblck,1);

View File

@ -45,8 +45,8 @@ ncn = estim_params_.ncn;
np = estim_params_.np ;
nx = nvx+nvn+ncx+ncn+np;
DirectoryName = CheckPath('metropolis');
OutputDirectoryName = CheckPath('Output');
DirectoryName = CheckPath('metropolis',M_.dname);
OutputDirectoryName = CheckPath('Output',M_.dname);
load([ DirectoryName '/' M_.fname '_mh_history'])
FirstMhFile = record.KeepedDraws.FirstMhFile;

View File

@ -33,8 +33,8 @@ function McMCDiagnostics(options_, estim_params_, M_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
DirectoryName = CheckPath('Output');
MhDirectoryName = CheckPath('metropolis');
DirectoryName = CheckPath('Output',M_.dname);
MhDirectoryName = CheckPath('metropolis',M_.dname);
TeX = options_.TeX;
nblck = options_.mh_nblck;

View File

@ -56,7 +56,7 @@ if whoiam
Parallel=myinputs.Parallel;
end
if ~exist('MhDirectoryName'),
MhDirectoryName = CheckPath('metropolis');
MhDirectoryName = CheckPath('metropolis',M_.dname);
end
ALPHA = 0.2; % increase too much with the number of simulations.

View File

@ -33,7 +33,7 @@ function oo_ = PlotPosteriorDistributions(estim_params_, M_, options_, bayestopt
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
OutputDirectoryName = CheckPath('Output');
OutputDirectoryName = CheckPath('Output',M_.dname);
TeX = options_.TeX;
nblck = options_.mh_nblck;

View File

@ -55,8 +55,8 @@ i_last_obs = gend+(1-M_.maximum_endo_lag:0);
horizon = options_.forecast;
maxlag = M_.maximum_endo_lag;
%%
CheckPath('Plots/');
DirectoryName = CheckPath('metropolis');
CheckPath('Plots/',M_.dname);
DirectoryName = CheckPath('metropolis',M_.dname);
load([ DirectoryName '/' M_.fname '_mh_history.mat'])
FirstMhFile = record.KeepedDraws.FirstMhFile;
FirstLine = record.KeepedDraws.FirstLine;

View File

@ -76,17 +76,17 @@ else
MAX_nirfs_dsgevar = 0;
end
DirectoryName = CheckPath('Output');
DirectoryName = CheckPath('Output',M_.dname);
if strcmpi(type,'posterior')
MhDirectoryName = CheckPath('metropolis');
MhDirectoryName = CheckPath('metropolis',M_.dname);
elseif strcmpi(type,'gsa')
if options_.opt_gsa.pprior
MhDirectoryName = CheckPath(['GSA' filesep 'prior']);
MhDirectoryName = CheckPath(['GSA' filesep 'prior'],M_.dname);
else
MhDirectoryName = CheckPath(['GSA' filesep 'mc']);
MhDirectoryName = CheckPath(['GSA' filesep 'mc'],M_.dname);
end
else
MhDirectoryName = CheckPath('prior');
MhDirectoryName = CheckPath('prior',M_.dname);
end
delete([MhDirectoryName filesep M_.fname '_IRF_DSGEs*.mat']);
delete([MhDirectoryName filesep M_.fname '_IRF_BVARDSGEs*.mat']);
@ -95,7 +95,7 @@ if strcmpi(type,'posterior')
TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws);
elseif strcmpi(type,'gsa')
RootDirectoryName = CheckPath('gsa');
RootDirectoryName = CheckPath('gsa',M_.dname);
if options_.opt_gsa.pprior
load([ RootDirectoryName filesep M_.fname '_prior.mat'],'lpmat0','lpmat','istable')
else

View File

@ -84,15 +84,15 @@ end
% MhDirectoryName = myinputs.MhDirectoryName;
if strcmpi(type,'posterior')
MhDirectoryName = CheckPath('metropolis');
MhDirectoryName = CheckPath('metropolis',M_.dname);
elseif strcmpi(type,'gsa')
if options_.opt_gsa.pprior
MhDirectoryName = CheckPath(['gsa' filesep 'prior']);
MhDirectoryName = CheckPath(['gsa' filesep 'prior'],M_.dname);
else
MhDirectoryName = CheckPath(['gsa' filesep 'mc']);
MhDirectoryName = CheckPath(['gsa' filesep 'mc'],M_.dname);
end
else
MhDirectoryName = CheckPath('prior');
MhDirectoryName = CheckPath('prior',M_.dname);
end
RemoteFlag = 0;

View File

@ -69,7 +69,7 @@ end
% To save the figures where the function is computed!
DirectoryName = CheckPath('Output');
DirectoryName = CheckPath('Output',M_.dname);
RemoteFlag = 0;
if whoiam,

View File

@ -45,22 +45,22 @@ function ReshapeMatFiles(type, type2)
global M_ options_
if nargin==1,
MhDirectoryName = [ CheckPath('metropolis') filesep ];
MhDirectoryName = [ CheckPath('metropolis',M_.dname) filesep ];
else
if strcmpi(type2,'posterior')
MhDirectoryName = [CheckPath('metropolis') filesep ];
MhDirectoryName = [CheckPath('metropolis',M_.dname) filesep ];
elseif strcmpi(type2,'gsa')
if options_.opt_gsa.morris==1,
MhDirectoryName = [CheckPath('gsa/screen') filesep ];
MhDirectoryName = [CheckPath('gsa/screen',M_.dname) filesep ];
elseif options_.opt_gsa.morris==2,
MhDirectoryName = [CheckPath('gsa/identif') filesep ];
MhDirectoryName = [CheckPath('gsa/identif',M_.dname) filesep ];
elseif options_.opt_gsa.pprior
MhDirectoryName = [CheckPath(['gsa' filesep 'prior']) filesep ];
MhDirectoryName = [CheckPath(['gsa' filesep 'prior'],M_.dname) filesep ];
else
MhDirectoryName = [CheckPath(['gsa' filesep 'mc']) filesep ];
MhDirectoryName = [CheckPath(['gsa' filesep 'mc'],M_.dname) filesep ];
end
else
MhDirectoryName = [CheckPath('prior') filesep ];
MhDirectoryName = [CheckPath('prior',M_.dname) filesep ];
end
end
switch type

View File

@ -68,7 +68,7 @@ switch type
otherwise
disp(['This feature is not yet implemented!'])
end
CheckPath('prior/moments');
CheckPath('prior/moments',M_.dname);
pdfinfo = dir([ M_.dname '/prior/' generic_prior_data_file_name '*']);
if isempty(pdfinfo)
info = 4;

View File

@ -42,7 +42,7 @@ n = estim_params_.np + ...
estim_params_.nvx;
nblck = options_.mh_nblck;
MhDirectoryName = CheckPath('metropolis');
MhDirectoryName = CheckPath('metropolis',M_.dname);
load([ MhDirectoryName '/' M_.fname '_mh_history.mat'])
FirstMhFile = record.KeepedDraws.FirstMhFile;

View File

@ -40,7 +40,7 @@ if strcmpi(type,'posterior')
posterior = 1;
elseif strcmpi(type,'prior')
DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
CheckPath('prior/moments');
CheckPath('prior/moments',M_.dname);
posterior = 0;
else
disp('dsge_simulated_theoretical_conditional_variance_decomposition:: Unknown type!')

View File

@ -40,7 +40,7 @@ if strcmpi(type,'posterior')
posterior = 1;
elseif strcmpi(type,'prior')
DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
CheckPath('prior/moments');
CheckPath('prior/moments',M_.dname);
posterior = 0;
else
disp('dsge_simulated_theoretical_correlation:: Unknown type!');

View File

@ -40,7 +40,7 @@ if strcmpi(type,'posterior')
posterior = 1;
elseif strcmpi(type,'prior')
DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
CheckPath('prior/moments');
CheckPath('prior/moments',M_.dname);
posterior = 0;
else
disp('dsge_simulated_theoretical_covariance:: Unknown type!')

View File

@ -41,7 +41,7 @@ if strcmpi(type,'posterior')
posterior = 1;
elseif strcmpi(type,'prior')
DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
CheckPath('prior/moments');
CheckPath('prior/moments',M_.dname);
posterior = 0;
else
disp('dsge_simulated_theoretical_variance_decomposition:: Unknown type!')

View File

@ -567,7 +567,7 @@ elseif ~any(bayestopt_.pshape > 0) && options_.mh_posterior_mode_estimation
end
OutputDirectoryName = CheckPath('Output');
OutputDirectoryName = CheckPath('Output',M_.dname);
if any(bayestopt_.pshape > 0) && options_.TeX %% Bayesian estimation (posterior mode) Latex output
if np

View File

@ -158,7 +158,7 @@ if ~(exist('sylvester3mr','file')==2),
addpath([dynareroot 'gensylv'])
end
IdentifDirectoryName = CheckPath('identification');
IdentifDirectoryName = CheckPath('identification',M_.dname);
if prior_exist,
indx = [];

View File

@ -136,12 +136,12 @@ if options_gsa.morris==1 || options_gsa.morris==3,
options_gsa.ksstat=1;
if options_gsa.morris==3,
options_gsa = set_default_option(options_gsa,'Nsam',256);
OutputDirectoryName = CheckPath('gsa/identif');
OutputDirectoryName = CheckPath('gsa/identif',M_.dname);
else
OutputDirectoryName = CheckPath('gsa/screen');
OutputDirectoryName = CheckPath('gsa/screen',M_.dname);
end
else
OutputDirectoryName = CheckPath('gsa');
OutputDirectoryName = CheckPath('gsa',M_.dname);
end
options_.opt_gsa = options_gsa;
@ -281,7 +281,7 @@ if options_gsa.glue,
dr_ = oo_.dr;
if options_gsa.ppost
load([OutputDirectoryName,'/',fname_,'_post']);
DirectoryName = CheckPath('metropolis');
DirectoryName = CheckPath('metropolis',M_.dname);
else
if options_gsa.pprior
load([OutputDirectoryName,'/',fname_,'_prior']);

View File

@ -31,7 +31,7 @@ function [mhname,info] = get_name_of_the_last_mh_file(M_)
mhname = [];
info = 1;
MhDirectoryName = CheckPath('metropolis');
MhDirectoryName = CheckPath('metropolis',M_.dname);
load([ MhDirectoryName '/' M_.fname '_mh_history.mat']) ;
mh_number = record.LastFileNumber ;

View File

@ -93,14 +93,14 @@ end
if options_.opt_gsa.ppost,
fnamtmp=[fname_,'_post'];
DirectoryName = CheckPath('metropolis');
DirectoryName = CheckPath('metropolis',M_.dname);
else
if options_.opt_gsa.pprior
fnamtmp=[fname_,'_prior'];
DirectoryName = CheckPath(['gsa' filesep 'prior']);
DirectoryName = CheckPath(['gsa' filesep 'prior'],M_.dname);
else
fnamtmp=[fname_,'_mc'];
DirectoryName = CheckPath(['gsa' filesep 'mc']);
DirectoryName = CheckPath(['gsa' filesep 'mc'],M_.dname);
end
end
if ~loadSA,

View File

@ -21,7 +21,7 @@ function gsa_plotmatrix(type,varargin)
global bayestopt_ options_ M_
RootDirectoryName = CheckPath('gsa');
RootDirectoryName = CheckPath('gsa',M_.dname);
if options_.opt_gsa.pprior
load([ RootDirectoryName filesep M_.fname '_prior.mat'],'lpmat0','lpmat','istable','iunstable','iindeterm','iwrong')

View File

@ -27,7 +27,7 @@ function [pars, cosnJ] = ident_bruteforce(J,n,TeX, pnames_TeX)
% along with Dynare. If not, see <http://www.gnu.org/licen
global M_ options_
OutputDirectoryName = CheckPath('Identification');
OutputDirectoryName = CheckPath('Identification',M_.dname);
k = size(J,2); % number of parameters

View File

@ -71,7 +71,7 @@ end
% (re)Set the penalty.
bayestopt_.penalty = Inf;
MhDirectoryName = CheckPath('metropolis');
MhDirectoryName = CheckPath('metropolis',M_.dname);
OpenOldFile = ones(nblck,1);
if strcmpi(ProposalFun,'rand_multivariate_normal')

View File

@ -36,7 +36,7 @@ function [marginal,oo_] = marginal_density(M_, options_, estim_params_, oo_)
npar = estim_params_.np+estim_params_.nvn+estim_params_.ncx+estim_params_.ncn+estim_params_.nvx;
nblck = options_.mh_nblck;
MhDirectoryName = CheckPath('metropolis');
MhDirectoryName = CheckPath('metropolis',M_.dname);
load([ MhDirectoryName '/' M_.fname '_mh_history.mat'])
FirstMhFile = record.KeepedDraws.FirstMhFile;

View File

@ -39,7 +39,7 @@ if init
ncn = estim_params_.ncn;
np = estim_params_.np ;
npar = nvx+nvn+ncx+ncn+np;
MhDirectoryName = CheckPath('metropolis');
MhDirectoryName = CheckPath('metropolis',M_.dname);
fname = [ MhDirectoryName '/' M_.fname];
load([ fname '_mh_history']);
FirstMhFile = record.KeepedDraws.FirstMhFile;

View File

@ -56,7 +56,7 @@ end
bayestopt_.penalty = 1e8;
MhDirectoryName = CheckPath('metropolis');
MhDirectoryName = CheckPath('metropolis',M_.dname);
nblck = options_.mh_nblck;
nruns = ones(nblck,1)*options_.mh_replic;

View File

@ -47,7 +47,7 @@ if isempty(column)
end
% Get informations about the posterior draws:
DirectoryName = CheckPath('metropolis');
DirectoryName = CheckPath('metropolis',M_.dname);
try
load([DirectoryName '/' M_.fname '_mh_history.mat']);
catch

View File

@ -96,7 +96,7 @@ for i=fpar:nvar
if whoiam,
if Parallel(ThisMatlab).Local==0
DirectoryName = CheckPath('Output');
DirectoryName = CheckPath('Output',M_.dname);
end
end

View File

@ -69,7 +69,7 @@ end
maxlag = M_.maximum_endo_lag;
%%
if strcmpi(type,'posterior')
DirectoryName = CheckPath('metropolis');
DirectoryName = CheckPath('metropolis',M_.dname);
load([ DirectoryName '/' M_.fname '_mh_history'])
FirstMhFile = record.KeepedDraws.FirstMhFile;
FirstLine = record.KeepedDraws.FirstLine;
@ -86,12 +86,12 @@ if strcmpi(type,'posterior')
B = min(1200, round(0.25*NumberOfDraws));
end
elseif strcmpi(type,'gsa')
RootDirectoryName = CheckPath('gsa');
RootDirectoryName = CheckPath('gsa',M_.dname);
if options_.opt_gsa.pprior
DirectoryName = CheckPath(['gsa',filesep,'prior']);
DirectoryName = CheckPath(['gsa',filesep,'prior'],M_.dname);
load([ RootDirectoryName filesep M_.fname '_prior.mat'],'lpmat0','lpmat','istable')
else
DirectoryName = CheckPath(['gsa',filesep,'mc']);
DirectoryName = CheckPath(['gsa',filesep,'mc'],M_.dname);
load([ RootDirectoryName filesep M_.fname '_mc.mat'],'lpmat0','lpmat','istable')
end
x=[lpmat0(istable,:) lpmat(istable,:)];
@ -99,7 +99,7 @@ elseif strcmpi(type,'gsa')
NumberOfDraws=size(x,1);
B=NumberOfDraws;
elseif strcmpi(type,'prior')
DirectoryName = CheckPath('prior');
DirectoryName = CheckPath('prior',M_.dname);
if ~isempty(options_.subdraws)
B = options_.subdraws;
else

View File

@ -97,15 +97,15 @@ end
% DirectoryName = myinputs.DirectoryName;
if strcmpi(type,'posterior')
DirectoryName = CheckPath('metropolis');
DirectoryName = CheckPath('metropolis',M_.dname);
elseif strcmpi(type,'gsa')
if options_.opt_gsa.pprior
DirectoryName = CheckPath(['gsa',filesep,'prior']);
DirectoryName = CheckPath(['gsa',filesep,'prior'],M_.dname);
else
DirectoryName = CheckPath(['gsa',filesep,'mc']);
DirectoryName = CheckPath(['gsa',filesep,'mc'],M_.dname);
end
elseif strcmpi(type,'prior')
DirectoryName = CheckPath('prior');
DirectoryName = CheckPath('prior',M_.dname);
end
RemoteFlag = 0;

View File

@ -32,7 +32,7 @@ function results = prior_sampler(drsave,M_,bayestopt_,options_,oo_)
% Initialization.
prior_draw(1);
PriorDirectoryName = CheckPath('prior/draws');
PriorDirectoryName = CheckPath('prior/draws',M_.dname);
work = ~drsave;
iteration = 0;
loop_indx = 0;

View File

@ -103,7 +103,7 @@ end
% (re)Set the penalty
bayestopt_.penalty = Inf;
MhDirectoryName = CheckPath('metropolis');
MhDirectoryName = CheckPath('metropolis',M_.dname);
options_.lik_algo = 1;
OpenOldFile = ones(nblck,1);

View File

@ -63,7 +63,7 @@ switch nargin
end
% Get informations about the mcmc:
MhDirectoryName = CheckPath('metropolis');
MhDirectoryName = CheckPath('metropolis',M_.dname);
fname = [ MhDirectoryName '/' M_.fname];
load([ fname '_mh_history.mat']);
FirstMhFile = record.KeepedDraws.FirstMhFile;

View File

@ -263,7 +263,7 @@ if options_.initialize_estimated_parameters_with_the_prior_mode
end
% I create subfolder M_.dname/prior if needed.
CheckPath('prior');
CheckPath('prior',M_.dname);
% I save the prior definition if the prior has changed.
if exist([ M_.dname '/prior/definition.mat'])

View File

@ -46,7 +46,7 @@ if isempty(column)
end
% Get informations about the posterior draws:
DirectoryName = CheckPath('metropolis');
DirectoryName = CheckPath('metropolis',M_.dname);
try
load([DirectoryName '/' M_.fname '_mh_history.mat']);
catch