From bf93558234cee81f0667ad1454d3b663b74c8724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Argos=29?= <stepan@adjemian.eu> Date: Tue, 5 Nov 2024 15:50:44 +0100 Subject: [PATCH] Use isfile() and isfolder() when possible Instead of exist(). --- doc/internals/build_internal_documentation.m | 8 +-- matlab/+gsa/monte_carlo_filtering.m | 2 +- matlab/+gsa/run.m | 10 ++-- .../get_perturbation_params_derivs.m | 8 +-- matlab/+mom/check_irf_matching_file.m | 6 +-- matlab/+mom/default_option_mom_values.m | 6 +-- matlab/+mom/run.m | 4 +- matlab/+occbin/graph.m | 2 +- matlab/aggregate.m | 4 +- matlab/backward/checkdatabase.m | 2 +- .../backward/shock_decomposition_backward.m | 4 +- matlab/check_matlab_path.m | 2 +- matlab/cherrypick.m | 4 +- matlab/cli/search.m | 2 +- .../mcmc_diagnostics_core.m | 4 +- matlab/default_option_values.m | 4 +- matlab/dynare.m | 12 ++--- .../check_posterior_sampler_options.m | 4 +- matlab/estimation/check_prior_analysis_data.m | 2 +- matlab/estimation/delete_mh_history_files.m | 4 +- matlab/estimation/dynare_estimation_1.m | 4 +- matlab/estimation/dynare_estimation_init.m | 4 +- .../execute_prior_posterior_function.m | 4 +- matlab/estimation/load_last_mh_history_file.m | 4 +- .../estimation/mh_autocorrelation_function.m | 8 +-- matlab/estimation/posterior_sampler_core.m | 2 +- matlab/estimation/set_prior.m | 37 +++++++------- matlab/estimation/trace_plot.m | 8 +-- matlab/forecast_graphs.m | 8 +-- matlab/get_build_dir.m | 4 +- matlab/get_path_to_mex_files.m | 8 +-- matlab/histvalf_initvalf.m | 12 ++--- .../kalman/plot_classical_smoother_results.m | 2 +- .../save_display_classical_smoother_results.m | 2 +- matlab/latex/write_latex_definitions.m | 4 +- matlab/latex/write_latex_parameter_table.m | 4 +- matlab/latex/write_latex_prior_table.m | 6 +-- matlab/load_m_file_data_legacy.m | 2 +- matlab/model_diagnostics.m | 2 +- matlab/moments/UnivariateSpectralDensity.m | 6 +-- matlab/ols/get_ast.m | 4 +- matlab/ols/write_param_init_inc_file.m | 2 +- matlab/parallel/dynareParallelDelete.m | 2 +- .../PCL_Part_info_moments.m | 4 +- ..._foresight_with_expectation_errors_setup.m | 2 +- matlab/plot_contributions.m | 2 +- matlab/print_expectations.m | 6 +-- matlab/read_variables.m | 18 +++---- matlab/reporting/@page/write.m | 2 +- matlab/reporting/@report/compile.m | 2 +- matlab/reporting/@report/write.m | 4 +- .../reporting/@report_graph/writeGraphFile.m | 2 +- .../reporting/@report_table/writeTableFile.m | 2 +- matlab/rplot.m | 10 ++-- matlab/stochastic_solver/simult.m | 4 +- matlab/stochastic_solver/stoch_simul.m | 4 +- .../utilities/general/clean_current_folder.m | 10 ++-- tests/decision_rules/example1_use_dll.mod | 48 +++++++++--------- tests/decision_rules/k_order/fs2000k2_m.mod | 47 +++++++++--------- .../k_order/fs2000k2_use_dll.mod | 49 ++++++++++--------- tests/decision_rules/k_order/fs2000k3_m.mod | 37 +++++++------- .../k_order/fs2000k3_use_dll.mod | 38 +++++++------- tests/decision_rules/k_order/fs2000k_1_m.mod | 49 ++++++++++--------- .../k_order/fs2000k_1_use_dll.mod | 49 ++++++++++--------- tests/dynare-command-options/ramst.mod | 2 +- tests/estimation/fs2000.mod | 4 +- tests/optimal_policy/neo_growth_ramsey.mod | 43 +++++++++------- .../neo_growth_ramsey_foresight.mod | 27 +++++----- .../neo_growth_ramsey_k_order.mod | 25 ++++++---- tests/run_block_bytecode_tests.m | 2 +- tests/stochastic_simulations/example2long.mod | 10 ++-- .../example2long_use_dll.mod | 10 ++-- 72 files changed, 396 insertions(+), 349 deletions(-) diff --git a/doc/internals/build_internal_documentation.m b/doc/internals/build_internal_documentation.m index cbb83e6b9a..9dfe97a134 100644 --- a/doc/internals/build_internal_documentation.m +++ b/doc/internals/build_internal_documentation.m @@ -15,7 +15,7 @@ simulationfiles = []; miscfiles = []; % Data. -if exist('data.texi') +if isfile('data.texi') delete('data.texi') end fid = fopen('data.texi','w'); @@ -32,7 +32,7 @@ end fclose(fid); % Estimation. -if exist('estimation.texi') +if isfile('estimation.texi') delete('estimation.texi') end fid = fopen('estimation.texi','w'); @@ -49,7 +49,7 @@ end fclose(fid); % Simulation. -if exist('simulation.texi') +if isfile('simulation.texi') delete('simulation.texi') end fid = fopen('simulation.texi','w'); @@ -66,7 +66,7 @@ end fclose(fid); % Miscellaneous. -if exist('misc.texi') +if isfile('misc.texi') delete('misc.texi') end fid = fopen('misc.texi','w'); diff --git a/matlab/+gsa/monte_carlo_filtering.m b/matlab/+gsa/monte_carlo_filtering.m index 69b100b4d3..bc653f22fc 100644 --- a/matlab/+gsa/monte_carlo_filtering.m +++ b/matlab/+gsa/monte_carlo_filtering.m @@ -115,7 +115,7 @@ if options_.opt_gsa.ppost xparam1_mean=c.xparam1; xparam1=c.xparam1; clear c -elseif ~isempty(options_.mode_file) && exist([M_.dname filesep 'Output' filesep fname_,'_mean.mat'],'file')==2 +elseif ~isempty(options_.mode_file) && isfile([M_.dname filesep 'Output' filesep fname_,'_mean.mat']) c=load([M_.dname filesep 'Output' filesep fname_,'_mean.mat'],'xparam1'); xparam1_mean=c.xparam1; xparam1=c.xparam1; diff --git a/matlab/+gsa/run.m b/matlab/+gsa/run.m index 8ff035e895..f1726ba7ab 100644 --- a/matlab/+gsa/run.m +++ b/matlab/+gsa/run.m @@ -284,8 +284,8 @@ else end if (options_gsa.load_stab || options_gsa.load_rmse || options_gsa.load_redform) && options_gsa.pprior - filetoload=[OutputDirectoryName '/' fname_ '_prior.mat']; - if ~exist(filetoload,'file') + filetoload=[OutputDirectoryName filesep fname_ '_prior.mat']; + if ~isfile(filetoload) disp([filetoload,' not found!']) disp('You asked to load a non existent analysis') return @@ -356,11 +356,11 @@ if options_gsa.redform && ~isempty(options_gsa.namendo) if options_gsa.morris==1 gsa.reduced_form_screening(OutputDirectoryName,options_gsa, estim_params_, M_, oo_.dr, options_, bayestopt_); else - % check existence of the SS_ANOVA toolbox + % check existence of the SS_ANOVA toolbox % TODO: Check if this is documented somewhere. if isempty(options_gsa.threshold_redform) && ~(exist('gsa_sdp','file')==6 || exist('gsa_sdp','file')==2) fprintf('\nThe "SS-ANOVA-R: MATLAB Toolbox for the estimation of Smoothing Spline ANOVA models with Recursive algorithms" is missing.\n') fprintf('To obtain it, go to:\n\n') - fprintf('https://ec.europa.eu/jrc/en/macro-econometric-statistical-software/ss-anova-r-downloads \n\n') + fprintf('https://ec.europa.eu/jrc/en/macro-econometric-statistical-software/ss-anova-r-downloads \n\n') % TODO: Check the link (the ss-anova toolbox doesn't seem to be available) fprintf('and follow the instructions there.\n') fprintf('After obtaining the files, you need to unpack them and set a Matlab Path to those files.\n') error('SS-ANOVA-R Toolbox missing!') @@ -400,7 +400,7 @@ if options_gsa.rmse else TmpDirectoryName = ([M_.dname filesep 'gsa' filesep 'mc']); end - if exist(TmpDirectoryName,'dir') + if isfolder(TmpDirectoryName) mydelete([M_.fname '_filter_step_ahead*.mat'],[TmpDirectoryName filesep]); mydelete([M_.fname '_inno*.mat'],[TmpDirectoryName filesep]); mydelete([M_.fname '_smooth*.mat'],[TmpDirectoryName filesep]); diff --git a/matlab/+identification/get_perturbation_params_derivs.m b/matlab/+identification/get_perturbation_params_derivs.m index 354d25026b..6800086a90 100644 --- a/matlab/+identification/get_perturbation_params_derivs.m +++ b/matlab/+identification/get_perturbation_params_derivs.m @@ -448,11 +448,11 @@ if analytic_derivation_mode == -2 clear dYss_g elseif (analytic_derivation_mode == 0 || analytic_derivation_mode == 1) - if ~exist(['+' fname filesep 'static_params_derivs.m'],'file') - error('For analytical parameter derivatives ''static_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order) + if ~isfile(['+' fname filesep 'static_params_derivs.m']) + error('For analytical parameter derivatives ''static_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.', order) end - if ~exist(['+' fname filesep 'dynamic_params_derivs.m'],'file') - error('For analytical parameter derivatives ''dynamic_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order) + if ~isfile(['+' fname filesep 'dynamic_params_derivs.m']) + error('For analytical parameter derivatives ''dynamic_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.', order) end %% Analytical computation of Jacobian and Hessian (wrt selected model parameters) of steady state, i.e. dYss and d2Yss [g1_static, T_order_static, T_static] = feval([fname,'.sparse.static_g1'], ys, exo_steady_state', params, M_.static_g1_sparse_rowval, M_.static_g1_sparse_colval, M_.static_g1_sparse_colptr); %g1_static is [endo_nbr by endo_nbr] first-derivative (wrt all endogenous variables) of static model equations f, i.e. df/dys, in declaration order diff --git a/matlab/+mom/check_irf_matching_file.m b/matlab/+mom/check_irf_matching_file.m index 3aa5db2726..dca955b716 100644 --- a/matlab/+mom/check_irf_matching_file.m +++ b/matlab/+mom/check_irf_matching_file.m @@ -51,7 +51,7 @@ else if isempty(irf_matching_file_path) irf_matching_file_path = '.'; end - if exist([irf_matching_file_path filesep irf_matching_file_name irf_matching_file_ext],'file') ~= 2 - error('method_of_moments: Could not find a ''irf_matching_file'' called ''%s''!',[irf_matching_file_path filesep irf_matching_file_name irf_matching_file_ext]); + if ~isfile(fullfile(irf_matching_file_path, strcat(irf_matching_file_name, irf_matching_file_ext))) + error('method_of_moments: Could not find a ''irf_matching_file'' called ''%s''!', fullfile(irf_matching_file_path, strcat(irf_matching_file_name, irf_matching_file_ext))) end -end \ No newline at end of file +end diff --git a/matlab/+mom/default_option_mom_values.m b/matlab/+mom/default_option_mom_values.m index e5f056a04c..661d9f2858 100644 --- a/matlab/+mom/default_option_mom_values.m +++ b/matlab/+mom/default_option_mom_values.m @@ -460,7 +460,7 @@ if strcmp(mom_method,'IRF_MATCHING') && do_bayesian_estimation warning('method_of_moments: You specified mh_tune_jscale, but the maximum number of iterations is smaller than the step size. No update will take place.') end if options_mom_.load_results_after_load_mh - if ~exist([options_mom_.dirname filesep 'method_of_moments' filesep fname '_mom_results.mat'],'file') + if ~isfile(sprintf('%s%smethod_of_moments%s%s_mom_results.mat', options_mom.dirname, filesep, filesep, fname)) fprintf('\nYou specified the ''load_results_after_load_mh'' option, but no ''%s_mom_results.mat'' file\n',fname); fprintf('was found in the folder %s%smethod_of_moments.\n',options_mom_.dirname,filesep); fprintf('Results will be recomputed and option ''load_results_after_load_mh'' is reset to false.\n'); @@ -477,6 +477,6 @@ if options_mom_.mom.analytic_jacobian && ~strcmp(mom_method,'GMM') end if strcmp(options_mom_.mom.mom_method,'IRF_MATCHING') if any(cellfun(@(x) isnumeric(x) && any(x == 13), options_mom_.optimizer_vec)) - error('method_of_moments: lsqnonlin (mode_compute=13) is not yet supported for IRF matching!'); + error('method_of_moments: lsqnonlin (mode_compute=13) is not yet supported for IRF matching!') end -end \ No newline at end of file +end diff --git a/matlab/+mom/run.m b/matlab/+mom/run.m index 93f5e2335f..e06d9c7fea 100644 --- a/matlab/+mom/run.m +++ b/matlab/+mom/run.m @@ -281,7 +281,7 @@ if options_mom_.mom.mom_nbr < length(xparam0) end skipline(2); % check if a _prior_restrictions.m file exists -if exist([M_.fname '_prior_restrictions.m'],'file') +if isfile(sprintf('%s_prior_restrictions.m', M_.fname)) options_mom_.prior_restrictions.status = 1; options_mom_.prior_restrictions.routine = str2func([M_.fname '_prior_restrictions']); end @@ -828,4 +828,4 @@ if strcmp(options_mom_.mom.mom_method,'SMM') || strcmp(options_mom_.mom.mom_meth end if strcmp(options_mom_.mom.mom_method,'IRF_MATCHING') && ~isempty(options_mom_.mom.irf_matching_file.path) && ~strcmp(options_mom_.mom.irf_matching_file.path,'.') rmpath(options_mom_.irf_matching_file.path); % remove path to irf_matching_file -end \ No newline at end of file +end diff --git a/matlab/+occbin/graph.m b/matlab/+occbin/graph.m index 187a1e5f34..b2ff74b2c1 100644 --- a/matlab/+occbin/graph.m +++ b/matlab/+occbin/graph.m @@ -27,7 +27,7 @@ function graph(M_, options_, options_occbin_, oo_, var_list) options_ = occbin.set_option(options_,options_occbin_,'graph.steady_state'); -if ~exist([M_.dname '/graphs'],'dir') +if ~isfolder(sprintf('%s/graphs', M_.dname)) mkdir(M_.dname,'graphs'); end diff --git a/matlab/aggregate.m b/matlab/aggregate.m index b8ae195b04..4555ed27b4 100644 --- a/matlab/aggregate.m +++ b/matlab/aggregate.m @@ -254,13 +254,13 @@ xlist = [xlist1, xlist2]; % Print all cherry-picked models in one mod-file. [filepath, filename, fileext] = fileparts(ofile); -if ~isempty(filepath) && ~exist(filepath, 'dir') +if ~isempty(filepath) && ~isfolder(filepath) mkdir(filepath); end if isempty(filepath) fid = fopen(sprintf('%s%s', filename, fileext), 'w'); else - fid = fopen(sprintf('%s%s%s%s', filepath, filesep(), filename, fileext), 'w'); + fid = fopen(fullfile(filepath, strcat(filename, fileext)), 'w'); end if ~isempty(firstline) fprintf(fid, '%s\n\n', firstline); diff --git a/matlab/backward/checkdatabase.m b/matlab/backward/checkdatabase.m index daeb14aecc..5a36f38dc6 100644 --- a/matlab/backward/checkdatabase.m +++ b/matlab/backward/checkdatabase.m @@ -31,7 +31,7 @@ if nargin<3 inversionflag = false; end -if exist(sprintf('+%s/dynamic_set_auxiliary_series.m', M_.fname), 'file') +if isfile(sprintf('+%s/dynamic_set_auxiliary_series.m', M_.fname)) dbase = feval(sprintf('%s.dynamic_set_auxiliary_series', M_.fname), dbase, M_.params); end diff --git a/matlab/backward/shock_decomposition_backward.m b/matlab/backward/shock_decomposition_backward.m index 9296200606..ec23f586b0 100644 --- a/matlab/backward/shock_decomposition_backward.m +++ b/matlab/backward/shock_decomposition_backward.m @@ -59,7 +59,7 @@ nperiods = simulations.nobs - initialconditions.nobs; decomposition = NaN(M_.endo_nbr, length(shocklist), nperiods); % Add auxiliary variables to simulation paths -if exist(sprintf('+%s/dynamic_set_auxiliary_series.m', M_.fname), 'file') +if isfile(sprintf('+%s/dynamic_set_auxiliary_series.m', M_.fname)) simulations = feval(sprintf('%s.dynamic_set_auxiliary_series', M_.fname), simulations, M_.params); end @@ -89,7 +89,7 @@ for i = length(shocklist):-1:1 % Compute simulation with the current shock or shock group removed simulations_new = simul_backward_model(initialconditions, nperiods, innovations); - if exist(sprintf('+%s/dynamic_set_auxiliary_series.m', M_.fname), 'file') + if isfile(sprintf('+%s/dynamic_set_auxiliary_series.m', M_.fname)) simulations_new = feval(sprintf('%s.dynamic_set_auxiliary_series', M_.fname), simulations_new, M_.params); end diff --git a/matlab/check_matlab_path.m b/matlab/check_matlab_path.m index 79bf393d9a..d3a492896a 100644 --- a/matlab/check_matlab_path.m +++ b/matlab/check_matlab_path.m @@ -95,7 +95,7 @@ else mexpath = get_path_to_mex_files([DYNARE_PATH filesep]); MATLAB_PATH = path2cell(MATLAB_PATH); for i=1:length(mexpath) - if exist([mexpath{i} filesep 'mjdgges.' mexext],'file') && ismember([DYNARE_PATH filesep 'qz'],MATLAB_PATH) + if isfile([mexpath{i} filesep 'mjdgges.' mexext]) && ismember([DYNARE_PATH filesep 'qz'],MATLAB_PATH) msg = sprintf(['You put all the subfolders of the Dynare matlab folder in the Matlab/Octave path! Only ' ... 'the dynare ' filesep 'matlab folder (without subfolders)\nshould be in the ' ... 'path. Dynare automatically adds any required subfolders to the ' ... diff --git a/matlab/cherrypick.m b/matlab/cherrypick.m index 1aac16614c..1f8d5b1005 100644 --- a/matlab/cherrypick.m +++ b/matlab/cherrypick.m @@ -52,10 +52,10 @@ end mkdir(outfold); % Check that infile.mod and the related JSON output exist. -if ~exist(sprintf('%s.mod', infile), 'file') +if ~isfile(sprintf('%s.mod', infile)) error('Cannot find %s.mod.', infile) end -if ~exist(sprintf('%s/model/json', infile), 'dir') +if ~isfolder(sprintf('%s/model/json', infile)) error('Cannot find %s/model/json folder. Did you run %s.mod with the json option?', infile, infile); end diff --git a/matlab/cli/search.m b/matlab/cli/search.m index ff391c2a61..c577490471 100644 --- a/matlab/cli/search.m +++ b/matlab/cli/search.m @@ -37,7 +37,7 @@ end jname = sprintf('%s%smodel%sjson%smodfile-original.json', M_.fname, filesep, filesep, filesep); % Check if corresponding JSON file exists. -if exist(jname, 'file') ~= 2 +if ~isfile(jname, 'file') error('Please use the json option (See the Dynare invocation section in the reference manual).'); end diff --git a/matlab/convergence_diagnostics/mcmc_diagnostics_core.m b/matlab/convergence_diagnostics/mcmc_diagnostics_core.m index 65ebd74f05..dbee0d9136 100644 --- a/matlab/convergence_diagnostics/mcmc_diagnostics_core.m +++ b/matlab/convergence_diagnostics/mcmc_diagnostics_core.m @@ -70,7 +70,7 @@ M_=myinputs.M_; if whoiam Parallel=myinputs.Parallel; end -if ~exist(MetropolisFolder,'dir') +if ~isfolder(MetropolisFolder) MetropolisFolder = CheckPath('metropolis',M_.dname); end @@ -142,4 +142,4 @@ for j=fpar:npar end end -myoutput.UDIAG = UDIAG; \ No newline at end of file +myoutput.UDIAG = UDIAG; diff --git a/matlab/default_option_values.m b/matlab/default_option_values.m index d3773fc937..92123f72ba 100644 --- a/matlab/default_option_values.m +++ b/matlab/default_option_values.m @@ -81,9 +81,9 @@ options_.threads.k_order_perturbation = max(1, num_procs/2); options_.jacobian_flag = true; % steady state file -if exist(['+' M_.fname '/steadystate.m'],'file') +if isfile(sprintf('+%s%ssteadystate.m', M_.fname, filesep)) options_.steadystate_flag = 2; -elseif exist([M_.fname '_steadystate.m'],'file') +elseif isfile(sprintf('%s_steadystate.m', M_.fname)) options_.steadystate_flag = 1; else options_.steadystate_flag = 0; diff --git a/matlab/dynare.m b/matlab/dynare.m index 5d19152794..ce973cd45e 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -141,7 +141,7 @@ end if contains(fname,filesep) fprintf('\nIt seems you are trying to call a .mod file not located in the "Current Folder". This is not possible (the %s symbol is not allowed in the name of the .mod file).\n', filesep) [pathtomodfile,basename] = fileparts(fname); - if exist(pathtomodfile,'dir') + if isfolder(pathtomodfile) filesindirectory = dir(pathtomodfile); filesindirectory = struct2cell(filesindirectory); filesindirectory = filesindirectory(1,:); @@ -155,7 +155,7 @@ if contains(fname,filesep) error(['Dynare: can''t open ' fname, '.']) end -if ~exist(fname,'file') || isequal(fname,'dir') +if ~isfile(fname) || isequal(fname,'dir') fprintf('\nThe file %s could not be located in the "Current Folder". Check whether you typed in the correct filename\n',fname) fprintf('and whether the file is really located in the "Current Folder".\n') try @@ -173,7 +173,7 @@ if ~isvarname(fname(1:end-4)) end % pre-dynare-preprocessor-hook -if exist(fname(1:end-4),'dir') && exist([fname(1:end-4) filesep 'hooks'],'dir') && exist([fname(1:end-4) filesep 'hooks/priorprocessing.m'],'file') +if isfolder(fname(1:end-4)) && isfolder([fname(1:end-4) filesep 'hooks']) && isfile([fname(1:end-4) filesep 'hooks/priorprocessing.m']) run([fname(1:end-4) filesep 'hooks/priorprocessing']) end @@ -190,7 +190,7 @@ fast = ismember('fast', varargin) || ismember('fast', file_opts); diary off if ~nolog logfile = [ fname(1:end-4) '.log' ]; - if exist(logfile, 'file') + if isfile(logfile) delete(logfile) end diary(logfile) @@ -239,7 +239,7 @@ end % For an instance of this bug, see: % https://forum.dynare.org/t/issue-with-dynare-preprocessor-4-6-1/15448/1 if ~fast - if ispc && ~isoctave && exist(['+',fname(1:end-4)],'dir') + if ispc && ~isoctave && isfolder(['+',fname(1:end-4)]) [~,~]=rmdir(['+', fname(1:end-4)],'s'); % output required to suppress triggering error end end @@ -287,7 +287,7 @@ if onlyjson end % post-dynare-prerocessor-hook -if exist(fname(1:end-4),'dir') && exist([fname(1:end-4) filesep 'hooks'],'dir') && exist([fname(1:end-4) filesep 'hooks/postprocessing.m'],'file') +if isfolder(fname(1:end-4)) && isfolder([fname(1:end-4) filesep 'hooks']) && isfile([fname(1:end-4) filesep 'hooks/postprocessing.m']) run([fname(1:end-4) filesep 'hooks/postprocessing']) end diff --git a/matlab/estimation/check_posterior_sampler_options.m b/matlab/estimation/check_posterior_sampler_options.m index e93510075b..acb06e0707 100644 --- a/matlab/estimation/check_posterior_sampler_options.m +++ b/matlab/estimation/check_posterior_sampler_options.m @@ -92,7 +92,7 @@ if init case 'scale_file' % load optimal_mh_scale parameter if previous run was with mode_compute=6 % will overwrite jscale from set_prior.m - if exist(options_list{i,2},'file') || exist([options_list{i,2},'.mat'],'file') + if isfile(options_list{i,2}) || isfile([options_list{i,2},'.mat']) tmp = load(options_list{i,2},'Scale'); bayestopt_.mh_jscale = tmp.Scale; options_.mh_jscale = tmp.Scale; @@ -157,7 +157,7 @@ if init case 'scale_file' % load optimal_mh_scale parameter if previous run was with mode_compute=6 % will overwrite jscale from set_prior.m - if exist(options_list{i,2},'file') || exist([options_list{i,2},'.mat'],'file') + if isfile(options_list{i,2}) || isfile([options_list{i,2},'.mat']) tmp = load(options_list{i,2},'Scale'); bayestopt_.mh_jscale = tmp.Scale; options_.mh_jscale = tmp.Scale; diff --git a/matlab/estimation/check_prior_analysis_data.m b/matlab/estimation/check_prior_analysis_data.m index ee40050987..a60556caf0 100644 --- a/matlab/estimation/check_prior_analysis_data.m +++ b/matlab/estimation/check_prior_analysis_data.m @@ -41,7 +41,7 @@ if nargout>1 end %% Get informations about prior draws files. -if ~exist([ M_.dname '/prior/draws'],'dir') +if ~isfolder(sprintf('%s%sprior%sdraws', M_.dname, filesep, filesep)) disp('check_prior_analysis_data:: Can''t find any prior draws file!') return end diff --git a/matlab/estimation/delete_mh_history_files.m b/matlab/estimation/delete_mh_history_files.m index c626b577bd..fef6e55f0c 100644 --- a/matlab/estimation/delete_mh_history_files.m +++ b/matlab/estimation/delete_mh_history_files.m @@ -24,9 +24,9 @@ mh_history_files = dir([BaseName '_mh_history_*.mat']); % Delete the mh-history files (old or new format) if any. if isequal(length(mh_history_files),0) - if exist([BaseName '_mh_history.mat']) + if isfile([BaseName '_mh_history.mat']) delete([BaseName '_mh_history.mat']) end else delete([BaseName '_mh_history_*.mat']) -end \ No newline at end of file +end diff --git a/matlab/estimation/dynare_estimation_1.m b/matlab/estimation/dynare_estimation_1.m index 6e2bd2bee0..17699fa1d7 100644 --- a/matlab/estimation/dynare_estimation_1.m +++ b/matlab/estimation/dynare_estimation_1.m @@ -45,8 +45,8 @@ if isdime(options_) && options_.prior_trunc fprintf('%s: DIME requires no prior truncation. Resetting options_.prior_trunc=0.\n', dispString); end -if ~exist([M_.dname filesep 'Output'],'dir') - mkdir(M_.dname,'Output'); +if ~isfolder(sprintf('%s%sOutput', M_.dname, filesep)) + mkdir(M_.dname, 'Output'); end if isempty(estim_params_) diff --git a/matlab/estimation/dynare_estimation_init.m b/matlab/estimation/dynare_estimation_init.m index 1303f81073..fdfb92f95d 100644 --- a/matlab/estimation/dynare_estimation_init.m +++ b/matlab/estimation/dynare_estimation_init.m @@ -147,7 +147,7 @@ if ~isempty(bayestopt_) && any(bayestopt_.pshape==0) && any(bayestopt_.pshape~=0 error('Estimation must be either fully ML or fully Bayesian. Maybe you forgot to specify a prior distribution.') end % Check if a _prior_restrictions.m file exists -if exist([M_.fname '_prior_restrictions.m'],'file') +if isfile(sprintf('%s_prior_restrictions.m', M_.fname)) options_.prior_restrictions.status = 1; options_.prior_restrictions.routine = str2func([M_.fname '_prior_restrictions']); end @@ -476,7 +476,7 @@ end estim_params_= get_matrix_entries_for_psd_check(M_,estim_params_); if options_.load_results_after_load_mh - if ~exist([M_.dname filesep 'Output' filesep M_.fname '_results.mat'],'file') + if ~isfile(sprintf('%s%sOutput%s%s_results.mat', M_.dname, filesep, filesep, M°.fname)) fprintf('\ndynare_estimation_init:: You specified the load_results_after_load_mh, but no _results.mat-file\n') fprintf('dynare_estimation_init:: was found. Results will be recomputed.\n') options_.load_results_after_load_mh=0; diff --git a/matlab/estimation/execute_prior_posterior_function.m b/matlab/estimation/execute_prior_posterior_function.m index 898cf63005..5bd2e98ed5 100644 --- a/matlab/estimation/execute_prior_posterior_function.m +++ b/matlab/estimation/execute_prior_posterior_function.m @@ -41,7 +41,7 @@ end fullname = [basename extension]; if ~strcmp(extension,'.m') %if not m-file error('The Posterior Function is not an m-file.') -elseif ~exist(fullname,'file') %if m-file, but does not exist +elseif ~isfile(fullname) %if m-file, but does not exist error(['The Posterior Function ', fullname ,' was not found. Check the spelling.']); end %Create function handle @@ -68,7 +68,7 @@ elseif strcmpi(type,'prior') error('The prior distributions are not properly set up.') end end - if exist([M_.fname '_prior_restrictions.m'],"file") + if isfile([M_.fname '_prior_restrictions.m']) warning('prior_function currently does not support endogenous prior restrictions. They will be ignored. Consider using a posterior_function with nobs=1.') end Prior = dprior(bayestopt_, options_.prior_trunc); diff --git a/matlab/estimation/load_last_mh_history_file.m b/matlab/estimation/load_last_mh_history_file.m index 27d25274c1..479ec3c758 100644 --- a/matlab/estimation/load_last_mh_history_file.m +++ b/matlab/estimation/load_last_mh_history_file.m @@ -34,7 +34,7 @@ mh_history_files = dir([BaseName '_mh_history_*.mat']); % Consistency with older versions of Dynare. if isequal(length(mh_history_files),0) - if exist([BaseName '_mh_history.mat'],'file') + if isfile([BaseName '_mh_history.mat']) format_mh_history_file = 1; % old Dynare format else error(['Estimation::load_mh_file: I cannot find any mh-history file in ' MetropolisFolder '!']) @@ -66,4 +66,4 @@ else if ~isfield(record,'MAX_nruns') record.MAX_nruns=NaN(size(record.MhDraws,1),1); % This information is forever lost... end -end \ No newline at end of file +end diff --git a/matlab/estimation/mh_autocorrelation_function.m b/matlab/estimation/mh_autocorrelation_function.m index 04ef6fb2c0..8f24711885 100644 --- a/matlab/estimation/mh_autocorrelation_function.m +++ b/matlab/estimation/mh_autocorrelation_function.m @@ -84,11 +84,11 @@ hh_fig=dyn_figure(options_.nodisplay,'Name',FigureName); bar(0:options_.mh_autocorrelation_function_size,autocor,'k'); axis tight % create subdirectory <dname>/graphs if it doesn't exist -if ~exist(M_.dname, 'dir') - mkdir('.',M_.dname); +if ~isfolder(M_.dname) + mkdir('.', M_.dname); end -if ~exist([M_.dname filesep 'graphs'],'dir') - mkdir(M_.dname,'graphs'); +if ~isfolder(sprintf('%s%sgraphs', M_.dname, filesep)) + mkdir(M_.dname, 'graphs'); end plot_name=get_the_name(column,0,M_,estim_params_,options_.varobs); diff --git a/matlab/estimation/posterior_sampler_core.m b/matlab/estimation/posterior_sampler_core.m index 61492fd4fe..8ac57b46a0 100644 --- a/matlab/estimation/posterior_sampler_core.m +++ b/matlab/estimation/posterior_sampler_core.m @@ -135,7 +135,7 @@ for curr_block = fblck:nblck options_=set_dynare_seed_local_options(options_,options_.DynareRandomStreams.seed+curr_block); end mh_recover_flag=0; - if options_.mh_recover && exist([BaseName '_mh_tmp_blck' int2str(curr_block) '.mat'],'file')==2 && OpenOldFile(curr_block) + if options_.mh_recover && isfile([BaseName '_mh_tmp_blck' int2str(curr_block) '.mat']) && OpenOldFile(curr_block) % this should be done whatever value of load_mh_file load([BaseName '_mh_tmp_blck' int2str(curr_block) '.mat']); draw_iter = size(neval_this_chain,2)+1; diff --git a/matlab/estimation/set_prior.m b/matlab/estimation/set_prior.m index 3069a8a095..238aca5cd3 100644 --- a/matlab/estimation/set_prior.m +++ b/matlab/estimation/set_prior.m @@ -285,24 +285,25 @@ end CheckPath('prior',M_.dname); % I save the prior definition if the prior has changed. -if exist([ M_.dname '/prior/definition.mat'],'file') - old = load([M_.dname '/prior/definition.mat'],'bayestopt_'); - prior_has_changed = 0; - if length(bayestopt_.p1)==length(old.bayestopt_.p1) - if any(bayestopt_.p1-old.bayestopt_.p1) - prior_has_changed = 1; - elseif any(bayestopt_.p2-old.bayestopt_.p2) - prior_has_changed = 1; - elseif any(bayestopt_.p3-old.bayestopt_.p3) - prior_has_changed = 1; - elseif any(bayestopt_.p4-old.bayestopt_.p4) - prior_has_changed = 1; - elseif any(bayestopt_.p5-old.bayestopt_.p5(:)) - prior_has_changed = 1; - elseif any(bayestopt_.p6-old.bayestopt_.p6) - prior_has_changed = 1; - elseif any(bayestopt_.p7-old.bayestopt_.p7) - prior_has_changed = 1; +priorfile = sprintf('%s/prior/definition.mat', M_.dname); +if isfile(priorfile) + old = load(priorfile, 'prior'); + prior_has_changed = false; + if length(prior.p1)==length(old.prior.p1) + if any(prior.p1-old.prior.p1) + prior_has_changed = true; + elseif any(prior.p2-old.prior.p2) + prior_has_changed = true; + elseif any(prior.p3-old.prior.p3) + prior_has_changed = true; + elseif any(prior.p4-old.prior.p4) + prior_has_changed = true; + elseif any(prior.p5-old.prior.p5(:)) + prior_has_changed = true; + elseif any(prior.p6-old.prior.p6) + prior_has_changed = true; + elseif any(prior.p7-old.prior.p7) + prior_has_changed = true; end else prior_has_changed = 1; diff --git a/matlab/estimation/trace_plot.m b/matlab/estimation/trace_plot.m index 2d0dd7c2d6..861f9d8f99 100644 --- a/matlab/estimation/trace_plot.m +++ b/matlab/estimation/trace_plot.m @@ -142,11 +142,11 @@ else legend(pp,strcat(repmat({'Chain '},n_nblocks_to_plot,1),num2str(blck(:)))); end % create subdirectory <dname>/graphs if it doesn't exist -if ~exist(M_.dname, 'dir') - mkdir('.',M_.dname); +if ~isfolder(M_.dname) + mkdir('.', M_.dname); end -if ~exist([M_.dname filesep 'graphs'],'dir') - mkdir(M_.dname,'graphs'); +if ~isfolder(sprintf('%s%sgraphs', M_.dname, filesep)) + mkdir(M_.dname, 'graphs'); end %get name for plot diff --git a/matlab/forecast_graphs.m b/matlab/forecast_graphs.m index 3b26838ec3..4c7395f23a 100644 --- a/matlab/forecast_graphs.m +++ b/matlab/forecast_graphs.m @@ -48,11 +48,11 @@ end nvar = length(i_var); % create subdirectory <dname>/graphs if id doesn't exist -if ~exist(dname, 'dir') - mkdir('.',dname); +if ~isfolder(dname) + mkdir('.', dname); end -if ~exist([dname '/graphs'],'dir') - mkdir(dname,'graphs'); +if ~isfolder(sprintf('%s%sgraphs', dname, filesep)) + mkdir(dname, 'graphs'); end if options_.TeX && any(strcmp('eps', cellstr(options_.graph_format))) diff --git a/matlab/get_build_dir.m b/matlab/get_build_dir.m index aa0e39ae3d..fb8b283d2f 100644 --- a/matlab/get_build_dir.m +++ b/matlab/get_build_dir.m @@ -25,9 +25,9 @@ default_octave = [ dynareroot '..' filesep 'build-octave' ]; if ~isempty(envvar) p = envvar; -elseif ~isoctave && exist(default_matlab, 'dir') +elseif ~isoctave && isfolder(default_matlab) p = default_matlab; -elseif isoctave && exist(default_octave, 'dir') +elseif isoctave && isfolder(default_octave) p = default_octave; else p = []; diff --git a/matlab/get_path_to_mex_files.m b/matlab/get_path_to_mex_files.m index 4823b37a11..b2cbf22af4 100644 --- a/matlab/get_path_to_mex_files.m +++ b/matlab/get_path_to_mex_files.m @@ -30,7 +30,7 @@ elseif isoctave warning('MEX files not available for 32-bit Octave') else tmp = [dynareroot '../mex/octave/win64/']; - if exist(tmp, 'dir') + if isfolder(tmp) mexpath = tmp; end end @@ -48,20 +48,20 @@ else % Add win64 specific paths for Dynare Windows package if strcmp(computer, 'PCWIN64') tmp = [dynareroot '../mex/matlab/win64-9.5-24.2/']; - if exist(tmp, 'dir') + if isfolder(tmp) mexpath = tmp; end end % Add macOS paths for Dynare Mac package if strcmp(computer, 'MACI64') tmp = [dynareroot '../mex/matlab/maci64-9.5-24.2/']; - if exist(tmp, 'dir') + if isfolder(tmp) mexpath = tmp; end end if strcmp(computer, 'MACA64') tmp = [dynareroot '../mex/matlab/maca64-23.2-24.2/']; - if exist(tmp, 'dir') + if isfolder(tmp) mexpath = tmp; end end diff --git a/matlab/histvalf_initvalf.m b/matlab/histvalf_initvalf.m index 36aaf62005..80ce2d74ca 100644 --- a/matlab/histvalf_initvalf.m +++ b/matlab/histvalf_initvalf.m @@ -61,19 +61,19 @@ if datafile [~,basename,extension] = fileparts(datafile); % Auto-detect extension if not provided if isempty(extension) - if exist([basename '.m'],'file') + if isfile(sprintf('%s.m', basename)) extension = '.m'; - elseif exist([basename '.mat'],'file') + elseif isfile(sprintf('%s.mat', basename)) extension = '.mat'; - elseif exist([basename '.xls'],'file') + elseif isfile(sprintf('%s.xls', basename)) extension = '.xls'; - elseif exist([basename '.xlsx'],'file') + elseif isfile(sprintf('%s.xlsx', basename)) extension = '.xlsx'; else error('%s_FILE: Can''t find datafile: %s.{m,mat,xls,xlsx}', caller, basename); end end - fullname = [basename extension]; + fullname = strcat(basename, extension); series = dseries(fullname); end @@ -104,7 +104,7 @@ if error_flag error('%s_FILE: some variables are missing', caller) end -if exist(sprintf('+%s/dynamic_set_auxiliary_series.m', M_.fname), 'file') +if isfile(sprintf('+%s/dynamic_set_auxiliary_series.m', M_.fname)) series = feval(sprintf('%s.dynamic_set_auxiliary_series', M_.fname), series, M_.params); end diff --git a/matlab/kalman/plot_classical_smoother_results.m b/matlab/kalman/plot_classical_smoother_results.m index 578d3166a1..0388b240ac 100644 --- a/matlab/kalman/plot_classical_smoother_results.m +++ b/matlab/kalman/plot_classical_smoother_results.m @@ -33,7 +33,7 @@ n_varobs = length(options_.varobs); if ~options_.nograph [nbplt,nr,nc,~,~,nstar] = pltorg(M_.exo_nbr); - if ~exist([M_.dname '/graphs'],'dir') + if ~isfolder(sprintf('%s%sgraphs', M_.dname, filesep)) mkdir(M_.dname,'graphs'); end if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format))) diff --git a/matlab/kalman/save_display_classical_smoother_results.m b/matlab/kalman/save_display_classical_smoother_results.m index 46d42c9969..94a0f3eaa5 100644 --- a/matlab/kalman/save_display_classical_smoother_results.m +++ b/matlab/kalman/save_display_classical_smoother_results.m @@ -63,4 +63,4 @@ else end if ~smoother_error plot_classical_smoother_results(M_,oo_,options_,dataset_info,dataset_,estim_params_,yf); -end \ No newline at end of file +end diff --git a/matlab/latex/write_latex_definitions.m b/matlab/latex/write_latex_definitions.m index a2e836a0bc..8009b7dd4c 100644 --- a/matlab/latex/write_latex_definitions.m +++ b/matlab/latex/write_latex_definitions.m @@ -39,8 +39,8 @@ else M_var_root = {'M_.endo', 'M_.exo', 'M_.exo_det', 'M_.param'}; end -if ~exist([M_.dname '/latex'],'dir') - mkdir(M_.dname,'latex'); +if ~isfolder(sprintf('%s%s/latex', M_.dname , filesep)) + mkdir(M_.dname, 'latex'); end fid = fopen([M_.dname, '/latex/' M_.fname '_latex_definitions.tex'], 'w'); for i=1:length(tables) diff --git a/matlab/latex/write_latex_parameter_table.m b/matlab/latex/write_latex_parameter_table.m index e92cfad84f..1ba22677f1 100644 --- a/matlab/latex/write_latex_parameter_table.m +++ b/matlab/latex/write_latex_parameter_table.m @@ -37,8 +37,8 @@ if ~isequal(M_.param_names, M_.param_names_long) Long_names_present = true; end -if ~exist([M_.dname '/latex'],'dir') - mkdir(M_.dname,'latex'); +if ~isfolder(sprintf('%s%slatex', M_.dname, filesep)) + mkdir(M_.dname, 'latex'); end fid = fopen([M_.dname, '/latex/' M_.fname '_latex_parameters.tex'], 'w'); diff --git a/matlab/latex/write_latex_prior_table.m b/matlab/latex/write_latex_prior_table.m index 7d5c21067a..dcf8f51f82 100644 --- a/matlab/latex/write_latex_prior_table.m +++ b/matlab/latex/write_latex_prior_table.m @@ -54,8 +54,8 @@ ub=bounds.ub; PriorNames = { 'Beta' , 'Gamma' , 'Gaussian' , 'Inv. Gamma' , 'Uniform' , 'Inv. Gamma -- 2', '', 'Weibull' }; -if ~exist([M_.dname '/latex'],'dir') - mkdir(M_.dname,'latex'); +if ~isfolder(sprintf('%s%slatex', M_.danme, filesep)) + mkdir(M_.dname, 'latex'); end fidTeX = fopen([M_.dname, '/latex/' M_.fname '_priors_table.tex'],'w+'); fprintf(fidTeX,'%% TeX-table generated by Dynare write_latex_prior_table.m.\n'); @@ -196,4 +196,4 @@ if ~isnumeric(UpperBound) else format_string = [ format_string , ' %6.4f &']; end -format_string = [ format_string , ' %6.4f & %6.4f \\\\ \n']; \ No newline at end of file +format_string = [ format_string , ' %6.4f & %6.4f \\\\ \n']; diff --git a/matlab/load_m_file_data_legacy.m b/matlab/load_m_file_data_legacy.m index d48bd4ade2..00c57f46a3 100644 --- a/matlab/load_m_file_data_legacy.m +++ b/matlab/load_m_file_data_legacy.m @@ -97,7 +97,7 @@ fclose(fid); % Define a set of variables to be loaded. listofvariablestobeloaded = {'b'; 'a'}; % Test if we can load the data. -exist('example1.m', 'file'); % To force the detection of the new file under old MATLAB +exist('example1.m', 'file'); % To force the detection of the new file under old MATLAB. TODO: Test if this trick is still necessary. try data = load_m_file_data_legacy('example1.m', listofvariablestobeloaded); t(1) = 1; diff --git a/matlab/model_diagnostics.m b/matlab/model_diagnostics.m index b16cdce7af..079bb8c4eb 100644 --- a/matlab/model_diagnostics.m +++ b/matlab/model_diagnostics.m @@ -299,7 +299,7 @@ elseif options_.order >= 2 [g1, T_order, T] = feval([M_.fname '.sparse.dynamic_g1'], dyn_endo_ss, exo, M_.params, ... dr.ys, M_.dynamic_g1_sparse_rowval, M_.dynamic_g1_sparse_colval, ... M_.dynamic_g1_sparse_colptr); - if exist(['+' M_.fname '/+sparse/dynamic_g2.m'],"file") || exist(['+' M_.fname '/+sparse/dynamic_g2.' mexext],"file") + if isfile(['+' M_.fname '/+sparse/dynamic_g2.m']) || isfile(['+' M_.fname '/+sparse/dynamic_g2.' mexext]) g2_v = feval([M_.fname '.sparse.dynamic_g2'], dyn_endo_ss, exo, M_.params, dr.ys, T_order, T); end end diff --git a/matlab/moments/UnivariateSpectralDensity.m b/matlab/moments/UnivariateSpectralDensity.m index d1963e62ac..18f91de5a7 100644 --- a/matlab/moments/UnivariateSpectralDensity.m +++ b/matlab/moments/UnivariateSpectralDensity.m @@ -129,12 +129,12 @@ if isoctave end if ~options_.nograph - if ~exist(M_.dname, 'dir') + if ~isfolder(M_.dname) mkdir('.',M_.dname); end - if ~exist([M_.dname '/graphs'],'dir') + if ~isfolder(sprintf('%s/graphs', M_.dname)) mkdir(M_.dname,'graphs'); - end + end for i= 1:nvar hh_fig = dyn_figure(options_.nodisplay,'Name',['Spectral Density of ' M_.endo_names{ivar(i)} '.']); diff --git a/matlab/ols/get_ast.m b/matlab/ols/get_ast.m index 000c71a148..8fc095c32c 100644 --- a/matlab/ols/get_ast.m +++ b/matlab/ols/get_ast.m @@ -39,7 +39,7 @@ end jsonfile = sprintf('%s%smodel%sjson%smodfile-original.json', M_.fname, filesep(), filesep(), filesep()); -if ~exist(jsonfile, 'file') +if ~isfile(jsonfile) error('Could not find %s! Please use the json=compute option (see the Dynare invocation section in the reference manual).', jsonfile) end @@ -55,4 +55,4 @@ if ~isempty(eqtags) if nargout>1 jsonmodel = getEquationsByTags(jsonmodel, 'name', eqtags); end -end \ No newline at end of file +end diff --git a/matlab/ols/write_param_init_inc_file.m b/matlab/ols/write_param_init_inc_file.m index deaa167fca..2345461254 100644 --- a/matlab/ols/write_param_init_inc_file.m +++ b/matlab/ols/write_param_init_inc_file.m @@ -55,7 +55,7 @@ end %% Write file % Open filepath = [M_.fname filesep 'model' filesep subfolder]; -if ~exist(filepath, 'dir') +if ~isfolder(filepath) mkdir(filepath) end diff --git a/matlab/parallel/dynareParallelDelete.m b/matlab/parallel/dynareParallelDelete.m index 2d4703c3ed..2d00b3f355 100644 --- a/matlab/parallel/dynareParallelDelete.m +++ b/matlab/parallel/dynareParallelDelete.m @@ -55,7 +55,7 @@ for indPC=1:length(Parallel) system(['ssh ',ssh_token,username,Parallel(indPC).ComputerName,' ''/bin/bash --norc -c "rm -f ',directory,pname,fname,'"''']); else fname_temp=['\\',Parallel(indPC).ComputerName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteDirectory,'\',pname,fname]; - if exist(fname_temp,'file') + if isfile(fname_temp) delete(fname_temp); end end diff --git a/matlab/partial_information/PCL_Part_info_moments.m b/matlab/partial_information/PCL_Part_info_moments.m index f4932d3f5e..e1db39b948 100644 --- a/matlab/partial_information/PCL_Part_info_moments.m +++ b/matlab/partial_information/PCL_Part_info_moments.m @@ -28,8 +28,8 @@ function oo_=PCL_Part_info_moments(M_, oo_, options_, varobs, dr, ivar) % and the jump variables x(t). % The jump variables have dimension NETA -if ~exist([M_.dname '/Output'],'dir') - mkdir(M_.dname,'Output'); +if ~isfolder(sprintf('%s%sOutput', M_.dname, filesep)) + mkdir(M_.dname, 'Output'); end warning_old_state = warning; diff --git a/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_setup.m b/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_setup.m index 8074e7beba..2b001224e8 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_setup.m +++ b/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_setup.m @@ -37,7 +37,7 @@ periods = options_.periods; oo_.pfwee.terminal_info = NaN(M_.exo_nbr, periods); % 2nd dimension is informational time oo_.pfwee.shocks_info = NaN(M_.exo_nbr, periods, periods); % 2nd dimension is real time, 3rd dimension is informational time -if exist(options_.datafile, 'file') +if isfile(options_.datafile) if ~isempty(M_.det_shocks) || ~isempty(M_.learnt_shocks) || ~isempty(oo_.initial_steady_state) || ~isempty(M_.learnt_endval) warning('perfect_foresight_with_expectation_errors_setup: since you passed the datafile option, the contents of shocks and endval blocks will be ignored') end diff --git a/matlab/plot_contributions.m b/matlab/plot_contributions.m index 74aadda5f3..492af14888 100644 --- a/matlab/plot_contributions.m +++ b/matlab/plot_contributions.m @@ -42,7 +42,7 @@ function plot_contributions(equationname, ds1, ds0) global M_ jsonfile = [M_.fname filesep() 'model' filesep() 'json' filesep() 'modfile-original.json']; -if exist(jsonfile, 'file') ~= 2 +if ~isfile(jsonfile) error('Could not find %s! Please use the json option (See the Dynare invocation section in the reference manual).', jsonfile); end diff --git a/matlab/print_expectations.m b/matlab/print_expectations.m index 069dde5076..2871cb52b1 100644 --- a/matlab/print_expectations.m +++ b/matlab/print_expectations.m @@ -105,7 +105,7 @@ auxmodel = M_.(expectationmodel.auxiliary_model_type).(expectationmodel.auxiliar % % First print the list of parameters appearing in the VAR_EXPECTATION/PAC_EXPECTATION term. % -if ~exist(sprintf('%s/model/%s', M_.fname, [expectationmodelkind '-expectations']), 'dir') +if ~isfolder(sprintf('%s/model/%s', M_.fname, [expectationmodelkind '-expectations'])) mkdir(sprintf('%s/model/%s', M_.fname, [expectationmodelkind '-expectations'])) end @@ -218,7 +218,7 @@ end % kind = [expectationmodelkind '_expectations']; ndir = sprintf('+%s/+%s/+%s', M_.fname, kind, expectationmodelname); -if ~exist(ndir, 'dir') +if ~isfolder(ndir) mkdir(sprintf('+%s/+%s/+%s', M_.fname, kind, expectationmodelname)); end filename = sprintf('+%s/+%s/+%s/evaluate.m', M_.fname, kind, expectationmodelname); @@ -253,7 +253,7 @@ end clear('expression'); % Get coefficient values in the target (if any) -if exist(sprintf('+%s/pac_target_coefficients.m', M_.fname), 'file') +if isfile(sprintf('+%s/pac_target_coefficients.m', M_.fname)) targetcoefficients = feval(sprintf('%s.pac_target_coefficients', M_.fname), expectationmodelname, M_.params); end diff --git a/matlab/read_variables.m b/matlab/read_variables.m index 9cc92f8631..f79174db39 100644 --- a/matlab/read_variables.m +++ b/matlab/read_variables.m @@ -46,25 +46,25 @@ var_size_01 = length(var_names_01); % Auto-detect extension if not provided if isempty(extension) - if exist([basename '.m'],'file') + if isfile(sprintf('.m', basename)) extension = '.m'; - elseif exist([basename '.mat'],'file') + elseif isfile(sprintf('.mat', basename)) extension = '.mat'; - elseif exist([basename '.xls'],'file') + elseif isfile(sprintf('.xls', basename)) extension = '.xls'; - elseif exist([basename '.xlsx'],'file') + elseif isfile(sprintf('.xlsx', basename)) extension = '.xlsx'; - elseif exist([basename '.csv'],'file') + elseif isfile(sprintf('.csv', basename)) extension = '.csv'; else - error(['Can''t find datafile: ' basename '.{m,mat,xls,xlsx,csv}']); + error('Can''t find datafile: %s.{m,mat,xls,xlsx,csv}', basename); end end -fullname = [basename extension]; +fullname = strcat(basename, extension); -if ~exist(fullname) - error(['Can''t find datafile: ' fullname ]); +if ~isfile(fullname) + error('Can''t find datafile: %s', fullname) end switch (extension) diff --git a/matlab/reporting/@page/write.m b/matlab/reporting/@page/write.m index e51d07d355..14889b5699 100644 --- a/matlab/reporting/@page/write.m +++ b/matlab/reporting/@page/write.m @@ -49,7 +49,7 @@ fprintf(fid, '\n'); if ~isempty(o.latex) dir = [rep_dir '/' o.pageDirName]; - if exist(dir, 'dir') ~= 7 + if ~isfolder(dir, 'dir') mkdir(dir); end pagename = [dir '/page_' num2str(pg) '.tex']; diff --git a/matlab/reporting/@report/compile.m b/matlab/reporting/@report/compile.m index cab277f52b..c984cc0663 100644 --- a/matlab/reporting/@report/compile.m +++ b/matlab/reporting/@report/compile.m @@ -57,7 +57,7 @@ assert(ischar(opts.compiler), '@report.compile: compiler file must be a string') assert(islogical(opts.showReport), '@report.compile: showReport must be either true or false'); assert(islogical(opts.showOutput), '@report.compile: showOutput must be either true or false'); -if exist([o.directory '/' o.fileName], 'file') ~= 2 +if ~isfile([o.directory filesep() o.fileName]) o.write(); end diff --git a/matlab/reporting/@report/write.m b/matlab/reporting/@report/write.m index 39095e9b78..ce2ba21ca9 100644 --- a/matlab/reporting/@report/write.m +++ b/matlab/reporting/@report/write.m @@ -28,10 +28,10 @@ function o = write(o) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <https://www.gnu.org/licenses/>. -if exist(o.directory, 'dir') ~= 7 +if ~isfolder(o.directory) mkdir(o.directory); end -if exist([o.directory '/' o.reportDirName], 'dir') ~= 7 +if ~isfolder([o.directory '/' o.reportDirName]) mkdir([o.directory '/' o.reportDirName]); end idx = strfind(o.fileName, '.tex'); diff --git a/matlab/reporting/@report_graph/writeGraphFile.m b/matlab/reporting/@report_graph/writeGraphFile.m index f405f184c9..8f747654b1 100644 --- a/matlab/reporting/@report_graph/writeGraphFile.m +++ b/matlab/reporting/@report_graph/writeGraphFile.m @@ -39,7 +39,7 @@ if ne < 1 return end -if exist([rep_dir '/' o.graphDirName], 'dir') ~= 7 +if ~isfolder([rep_dir '/' o.graphDirName]) mkdir([rep_dir '/' o.graphDirName]); end if isempty(o.graphName) diff --git a/matlab/reporting/@report_table/writeTableFile.m b/matlab/reporting/@report_table/writeTableFile.m index dae86e88d3..b97146049f 100644 --- a/matlab/reporting/@report_table/writeTableFile.m +++ b/matlab/reporting/@report_table/writeTableFile.m @@ -42,7 +42,7 @@ end if is_data_table ne = size(o.table_data{1}.data,2); end -if exist([rep_dir '/' o.tableDirName], 'dir') ~= 7 +if ~isfolder([rep_dir '/' o.tableDirName]) mkdir([rep_dir '/' o.tableDirName]); end if isempty(o.tableName) diff --git a/matlab/rplot.m b/matlab/rplot.m index 53abb116de..b02ed04819 100644 --- a/matlab/rplot.m +++ b/matlab/rplot.m @@ -38,11 +38,11 @@ if isempty(oo_.endo_simul) end % create subdirectory <dname>/graphs if it doesn't exist -if ~exist(M_.dname, 'dir') - mkdir('.',M_.dname); +if ~isfolder(M_.dname) + mkdir('.', M_.dname); end -if ~exist([M_.dname filesep 'graphs'],'dir') - mkdir(M_.dname,'graphs'); +if ~isfolder(sprintf('%s%sgraphs', M_.dname, filesep)) + mkdir(M_.dname, 'graphs'); end ix = (1 - M_.maximum_lag:size(oo_.endo_simul,2)-M_.maximum_lag)'; @@ -51,7 +51,7 @@ y = []; for k = 1:length(s1) if ~any(strcmp(s1{k}, M_.endo_names)) if ~any(strcmp(s1{k}, M_.exo_names)) - error ('rplot: One of the variables specified does not exist') ; + error ('rplot: One of the variables specified does not exist') else y = [y; oo_.exo_simul(:, strcmp(s1{k}, M_.exo_names))'] ; s1_TeX(k,1)=M_.exo_names_tex(strcmp(s1{k}, M_.exo_names)); diff --git a/matlab/stochastic_solver/simult.m b/matlab/stochastic_solver/simult.m index 4787d0e619..c3155bc27a 100644 --- a/matlab/stochastic_solver/simult.m +++ b/matlab/stochastic_solver/simult.m @@ -64,7 +64,7 @@ order = options_.order; replic = options_.simul_replic; if replic > 1 - if ~exist([M_.dname '/Output'],'dir') + if ~isfolder(sprintf('%s%sOutput', M_.dname, filesep)) mkdir(M_.dname,'Output'); end fname = [M_.dname filesep 'Output' filesep M_.fname,'_simul']; @@ -96,4 +96,4 @@ end if replic > 1 fclose(fh); -end \ No newline at end of file +end diff --git a/matlab/stochastic_solver/stoch_simul.m b/matlab/stochastic_solver/stoch_simul.m index 376de52368..b19b85e90e 100644 --- a/matlab/stochastic_solver/stoch_simul.m +++ b/matlab/stochastic_solver/stoch_simul.m @@ -218,8 +218,8 @@ end if options_.irf var_listTeX = M_.endo_names_tex(i_var); if ~options_.nograph || (TeX && any(strcmp('eps',cellstr(options_.graph_format)))) - if ~exist([M_.dname '/graphs'],'dir') - mkdir(M_.dname,'graphs'); + if ~isfolder(sprintf('%s%sgraphs', M_.dname, filesep)) + mkdir(M_.dname, 'graphs'); end end if TeX && any(strcmp('eps',cellstr(options_.graph_format))) diff --git a/matlab/utilities/general/clean_current_folder.m b/matlab/utilities/general/clean_current_folder.m index f458d6a641..4b51afd059 100644 --- a/matlab/utilities/general/clean_current_folder.m +++ b/matlab/utilities/general/clean_current_folder.m @@ -22,20 +22,20 @@ a = dir('*.mod'); for i = 1:length(a) [~,basename] = fileparts(a(i).name); - if exist([basename '.m']) + if isfile([basename '.m']) delete([basename '.m']); end - if exist([basename '.log']) + if isfile([basename '.log']) delete([basename '.log']); end - if exist(basename,'dir') + if isfolder(basename) rmdir(basename,'s'); end - if exist([basename '_steadystate.m']) + if isfolder([basename '_steadystate.m']) movefile([basename '_steadystate.m'],['protect_' basename '_steadystate.m']); end delete([basename '_*']) - if exist(['protect_' basename '_steadystate.m']) + if isfile(['protect_' basename '_steadystate.m']) movefile(['protect_' basename '_steadystate.m'],[basename '_steadystate.m']); end end diff --git a/tests/decision_rules/example1_use_dll.mod b/tests/decision_rules/example1_use_dll.mod index 8c5b200d6d..124ac6dbc4 100644 --- a/tests/decision_rules/example1_use_dll.mod +++ b/tests/decision_rules/example1_use_dll.mod @@ -44,30 +44,34 @@ end; stoch_simul(nograph); -if ~exist(['example1' filesep 'Output' filesep 'example1_results.mat'],'file'); - error('example1 must be run first'); -end; +matfilename = sprintf('example1%sOutput%sexample1_results.mat', filesep, filesep); + +if ~isfile(matfilename) + error('example1 must be run first') +end + +[p, f, e] = fileparts(matfilename); -oo1 = load(['example1' filesep 'Output' filesep 'example1_results'],'oo_'); +oo1 = load(fullfile(p, f),'oo_'); dr0 = oo1.oo_.dr; dr = oo_.dr; -if max(max(abs(dr0.ghx - dr.ghx))) > 1e-12; - error('error in ghx'); -end; -if max(max(abs(dr0.ghu - dr.ghu))) > 1e-12; - error('error in ghu'); -end; -if max(max(abs(dr0.ghxx - dr.ghxx))) > 1e-12; - error('error in ghxx'); -end; -if max(max(abs(dr0.ghuu - dr.ghuu))) > 1e-12; - error('error in ghuu'); -end; -if max(max(abs(dr0.ghxu - dr.ghxu))) > 1e-12; - error('error in ghxu'); -end; -if max(max(abs(dr0.ghs2 - dr.ghs2))) > 1e-12; - error('error in ghs2'); -end; +if max(max(abs(dr0.ghx - dr.ghx))) > 1e-12 + error('error in ghx') +end +if max(max(abs(dr0.ghu - dr.ghu))) > 1e-12 + error('error in ghu') +end +if max(max(abs(dr0.ghxx - dr.ghxx))) > 1e-12 + error('error in ghxx') +end +if max(max(abs(dr0.ghuu - dr.ghuu))) > 1e-12 + error('error in ghuu') +end +if max(max(abs(dr0.ghxu - dr.ghxu))) > 1e-12 + error('error in ghxu') +end +if max(max(abs(dr0.ghs2 - dr.ghs2))) > 1e-12 + error('error in ghs2') +end diff --git a/tests/decision_rules/k_order/fs2000k2_m.mod b/tests/decision_rules/k_order/fs2000k2_m.mod index 02ca454508..f5383d7b66 100644 --- a/tests/decision_rules/k_order/fs2000k2_m.mod +++ b/tests/decision_rules/k_order/fs2000k2_m.mod @@ -66,31 +66,34 @@ steady; stoch_simul(order=2,k_order_solver,periods=1000); -if ~exist(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results.mat'],'file'); - error('fs2000k2a must be run first'); +matfilename = sprintf('fs2000k2a%sOutput%sfs2000k2a_results.mat', filesep, filesep); + +if ~isfile(matfilename) + error('fs2000k2a must be run first') end; -oo1 = load(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results'],'oo_'); +[p, f, e] = fileparts(matfilename); + +oo1 = load(fullfile(p, f), 'oo_'); dr0 = oo1.oo_.dr; dr = oo_.dr; -if max(max(abs(dr0.ghx - dr.ghx))) > 1e-12; - error('error in ghx'); -end; -if max(max(abs(dr0.ghu - dr.ghu))) > 1e-12; - error('error in ghu'); -end; -if max(max(abs(dr0.ghxx - dr.ghxx))) > 1e-12; - error('error in ghxx'); -end; -if max(max(abs(dr0.ghuu - dr.ghuu))) > 1e-12; - error('error in ghuu'); -end; -if max(max(abs(dr0.ghxu - dr.ghxu))) > 1e-12; - error('error in ghxu'); -end; -if max(max(abs(dr0.ghs2 - dr.ghs2))) > 1e-12; - error('error in ghs2'); -end; - +if max(max(abs(dr0.ghx - dr.ghx))) > 1e-12 + error('error in ghx') +end +if max(max(abs(dr0.ghu - dr.ghu))) > 1e-12 + error('error in ghu') +end +if max(max(abs(dr0.ghxx - dr.ghxx))) > 1e-12 + error('error in ghxx') +end +if max(max(abs(dr0.ghuu - dr.ghuu))) > 1e-12 + error('error in ghuu') +end +if max(max(abs(dr0.ghxu - dr.ghxu))) > 1e-12 + error('error in ghxu') +end +if max(max(abs(dr0.ghs2 - dr.ghs2))) > 1e-12 + error('error in ghs2') +end diff --git a/tests/decision_rules/k_order/fs2000k2_use_dll.mod b/tests/decision_rules/k_order/fs2000k2_use_dll.mod index 9b5ea9dd95..2a56cb73bf 100644 --- a/tests/decision_rules/k_order/fs2000k2_use_dll.mod +++ b/tests/decision_rules/k_order/fs2000k2_use_dll.mod @@ -66,31 +66,34 @@ steady; stoch_simul(order=2,k_order_solver,periods=1000); -if ~exist(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results.mat'],'file'); - error('fs2000k2a must be run first'); -end; +matfilename = sprintf('fs2000k2a%sOutput%sfs2000k2a_results.mat', filesep, filesep); + +if ~isfile(matfilename) + error('fs2000k2a must be run first') +end + +[p, f, e] = fileparts(matfilename); -oo1 = load(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results'],'oo_'); +oo1 = load(fullfile(p, f), 'oo_'); dr0 = oo1.oo_.dr; dr = oo_.dr; -if max(max(abs(dr0.ghx - dr.ghx))) > 1e-12; - error('error in ghx'); -end; -if max(max(abs(dr0.ghu - dr.ghu))) > 1e-12; - error('error in ghu'); -end; -if max(max(abs(dr0.ghxx - dr.ghxx))) > 1e-12; - error('error in ghxx'); -end; -if max(max(abs(dr0.ghuu - dr.ghuu))) > 1e-12; - error('error in ghuu'); -end; -if max(max(abs(dr0.ghxu - dr.ghxu))) > 1e-12; - error('error in ghxu'); -end; -if max(max(abs(dr0.ghs2 - dr.ghs2))) > 1e-12; - error('error in ghs2'); -end; - +if max(max(abs(dr0.ghx - dr.ghx))) > 1e-12 + error('error in ghx') +end +if max(max(abs(dr0.ghu - dr.ghu))) > 1e-12 + error('error in ghu') +end +if max(max(abs(dr0.ghxx - dr.ghxx))) > 1e-12 + error('error in ghxx') +end +if max(max(abs(dr0.ghuu - dr.ghuu))) > 1e-12 + error('error in ghuu') +end +if max(max(abs(dr0.ghxu - dr.ghxu))) > 1e-12 + error('error in ghxu') +end +if max(max(abs(dr0.ghs2 - dr.ghs2))) > 1e-12 + error('error in ghs2') +end diff --git a/tests/decision_rules/k_order/fs2000k3_m.mod b/tests/decision_rules/k_order/fs2000k3_m.mod index fa91efec8d..ee4f68a943 100644 --- a/tests/decision_rules/k_order/fs2000k3_m.mod +++ b/tests/decision_rules/k_order/fs2000k3_m.mod @@ -66,25 +66,28 @@ steady; stoch_simul(order=3,periods=1000); -if ~exist(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results.mat'],'file'); - error('fs2000k2a must be run first'); -end; +matfilename = sprintf('fs2000k2a%sOutput%sfs2000k2a_results.mat', filesep, filesep); + +if ~isfile(matfilename) + error('fs2000k2a must be run first') +end -oo1 = load(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results'],'oo_'); +[p, f, e] = fileparts(matfilename); + +oo1 = load(fullfile(p, f), 'oo_'); dr0 = oo1.oo_.dr; dr = oo_.dr; -if max(max(abs(dr0.ghxx - dr.ghxx))) > 1e-12; - error('error in ghxx'); -end; -if max(max(abs(dr0.ghuu - dr.ghuu))) > 1e-12; - error('error in ghuu'); -end; -if max(max(abs(dr0.ghxu - dr.ghxu))) > 1e-12; - error('error in ghxu'); -end; -if max(max(abs(dr0.ghs2 - dr.ghs2))) > 1e-12; - error('error in ghs2'); -end; - +if max(max(abs(dr0.ghxx - dr.ghxx))) > 1e-12 + error('error in ghxx') +end +if max(max(abs(dr0.ghuu - dr.ghuu))) > 1e-12 + error('error in ghuu') +end +if max(max(abs(dr0.ghxu - dr.ghxu))) > 1e-12 + error('error in ghxu') +end +if max(max(abs(dr0.ghs2 - dr.ghs2))) > 1e-12 + error('error in ghs2') +end diff --git a/tests/decision_rules/k_order/fs2000k3_use_dll.mod b/tests/decision_rules/k_order/fs2000k3_use_dll.mod index 2028443b60..b113de436f 100644 --- a/tests/decision_rules/k_order/fs2000k3_use_dll.mod +++ b/tests/decision_rules/k_order/fs2000k3_use_dll.mod @@ -66,25 +66,29 @@ steady; stoch_simul(order=3,periods=1000); -if ~exist(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results.mat'],'file'); - error('fs2000k2a must be run first'); -end; -oo1 = load(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results'],'oo_'); +matfilename = sprintf('fs2000k2a%sOutput%sfs2000k2a_results.mat', filesep, filesep); + +if ~isfile(matfilename) + error('fs2000k2a must be run first') +end + +[p, f, e] = fileparts(matfilename); + +oo1 = load(fullfile(p, f), 'oo_'); dr0 = oo1.oo_.dr; dr = oo_.dr; -if max(max(abs(dr0.ghxx - dr.ghxx))) > 1e-12; - error('error in ghxx'); -end; -if max(max(abs(dr0.ghuu - dr.ghuu))) > 1e-12; - error('error in ghuu'); -end; -if max(max(abs(dr0.ghxu - dr.ghxu))) > 1e-12; - error('error in ghxu'); -end; -if max(max(abs(dr0.ghs2 - dr.ghs2))) > 1e-12; - error('error in ghs2'); -end; - +if max(max(abs(dr0.ghxx - dr.ghxx))) > 1e-12 + error('error in ghxx') +end +if max(max(abs(dr0.ghuu - dr.ghuu))) > 1e-12 + error('error in ghuu') +end +if max(max(abs(dr0.ghxu - dr.ghxu))) > 1e-12 + error('error in ghxu') +end +if max(max(abs(dr0.ghs2 - dr.ghs2))) > 1e-12 + error('error in ghs2') +end diff --git a/tests/decision_rules/k_order/fs2000k_1_m.mod b/tests/decision_rules/k_order/fs2000k_1_m.mod index f4bad22ce1..7f267257b7 100644 --- a/tests/decision_rules/k_order/fs2000k_1_m.mod +++ b/tests/decision_rules/k_order/fs2000k_1_m.mod @@ -74,11 +74,15 @@ steady; stoch_simul(order=2,k_order_solver,irf=0); -if ~exist(['fs2000k2_m' filesep 'Output' filesep 'fs2000k2_m_results.mat'],'file'); - error('fs2000k2_m must be run first'); -end; +matfilename = sprintf('fs2000k2_m%sOutput%sfs2000k2_m_results.mat', filesep, filesep); + +if ~isfile(matfilename) + error('fs2000k2_m must be run first') +end + +[p, f, e] = fileparts(matfilename); -oo1 = load(['fs2000k2_m' filesep 'Output' filesep 'fs2000k2_m_results'],'oo_'); +oo1 = load(fullfile(p, f), 'oo_'); dr0 = oo1.oo_.dr; dr = oo_.dr; @@ -88,22 +92,21 @@ ikc = [1 3 4 2]; ikc2 = [1 3 4 2 9 11 12 10 13 15 16 14 5 7 8 6]; ikc2u = [1 2 5 6 7 8 3 4]; -if max(max(abs(dr0.ghx - dr.ghx(ikr,ikc)))) > 1e-12; - error('error in ghx'); -end; -if max(max(abs(dr0.ghu - dr.ghu(ikr,:)))) > 1e-12; - error('error in ghu'); -end; -if max(max(abs(dr0.ghxx - dr.ghxx(ikr,ikc2)))) > 1e-12; - error('error in ghxx'); -end; -if max(max(abs(dr0.ghuu - dr.ghuu(ikr,:)))) > 1e-12; - error('error in ghuu'); -end; -if max(max(abs(dr0.ghxu - dr.ghxu(ikr,ikc2u)))) > 1e-12; - error('error in ghxu'); -end; -if max(max(abs(dr0.ghs2 - dr.ghs2(ikr,:)))) > 1e-12; - error('error in ghs2'); -end; - +if max(max(abs(dr0.ghx - dr.ghx(ikr,ikc)))) > 1e-12 + error('error in ghx') +end +if max(max(abs(dr0.ghu - dr.ghu(ikr,:)))) > 1e-12 + error('error in ghu') +end +if max(max(abs(dr0.ghxx - dr.ghxx(ikr,ikc2)))) > 1e-12 + error('error in ghxx') +end +if max(max(abs(dr0.ghuu - dr.ghuu(ikr,:)))) > 1e-12 + error('error in ghuu') +end +if max(max(abs(dr0.ghxu - dr.ghxu(ikr,ikc2u)))) > 1e-12 + error('error in ghxu') +end +if max(max(abs(dr0.ghs2 - dr.ghs2(ikr,:)))) > 1e-12 + error('error in ghs2') +end diff --git a/tests/decision_rules/k_order/fs2000k_1_use_dll.mod b/tests/decision_rules/k_order/fs2000k_1_use_dll.mod index f4eb030081..e6ad4371f4 100644 --- a/tests/decision_rules/k_order/fs2000k_1_use_dll.mod +++ b/tests/decision_rules/k_order/fs2000k_1_use_dll.mod @@ -73,11 +73,15 @@ steady; stoch_simul(order=2,k_order_solver,irf=0); -if ~exist(['fs2000k2_use_dll' filesep 'Output' filesep 'fs2000k2_use_dll_results.mat'],'file'); - error('fs2000k2_use_dll must be run first'); -end; +matfilename = sprintf('fs2000k2_use_dll%sOutput%sfs2000k2_use_dll_results.mat', filesep, filesep); + +if ~isfile(matfilename) + error('fs2000k2_use_dll must be run first') +end + +[p, f, e] = fileparts(matfilename); -oo1 = load(['fs2000k2_use_dll' filesep 'Output' filesep 'fs2000k2_use_dll_results'],'oo_'); +oo1 = load(fullfile(p, f), 'oo_'); dr0 = oo1.oo_.dr; dr = oo_.dr; @@ -87,22 +91,21 @@ ikc = [1 3 4 2]; ikc2 = [1 3 4 2 9 11 12 10 13 15 16 14 5 7 8 6]; ikc2u = [1 2 5 6 7 8 3 4]; -if max(max(abs(dr0.ghx - dr.ghx(ikr,ikc)))) > 1e-12; - error('error in ghx'); -end; -if max(max(abs(dr0.ghu - dr.ghu(ikr,:)))) > 1e-12; - error('error in ghu'); -end; -if max(max(abs(dr0.ghxx - dr.ghxx(ikr,ikc2)))) > 1e-12; - error('error in ghxx'); -end; -if max(max(abs(dr0.ghuu - dr.ghuu(ikr,:)))) > 1e-12; - error('error in ghuu'); -end; -if max(max(abs(dr0.ghxu - dr.ghxu(ikr,ikc2u)))) > 1e-12; - error('error in ghxu'); -end; -if max(max(abs(dr0.ghs2 - dr.ghs2(ikr,:)))) > 1e-12; - error('error in ghs2'); -end; - +if max(max(abs(dr0.ghx - dr.ghx(ikr,ikc)))) > 1e-12 + error('error in ghx') +end +if max(max(abs(dr0.ghu - dr.ghu(ikr,:)))) > 1e-12 + error('error in ghu') +end +if max(max(abs(dr0.ghxx - dr.ghxx(ikr,ikc2)))) > 1e-12 + error('error in ghxx') +end +if max(max(abs(dr0.ghuu - dr.ghuu(ikr,:)))) > 1e-12 + error('error in ghuu') +end +if max(max(abs(dr0.ghxu - dr.ghxu(ikr,ikc2u)))) > 1e-12 + error('error in ghxu') +end +if max(max(abs(dr0.ghs2 - dr.ghs2(ikr,:)))) > 1e-12 + error('error in ghs2') +end diff --git a/tests/dynare-command-options/ramst.mod b/tests/dynare-command-options/ramst.mod index 1f3da08e86..bde08b641e 100644 --- a/tests/dynare-command-options/ramst.mod +++ b/tests/dynare-command-options/ramst.mod @@ -38,6 +38,6 @@ perfect_foresight_solver; rplot c; rplot k; -if ~exist('./ramst/model/json/modfile.json', 'file') || exist('./ramst.log', 'file') +if ~isfile('./ramst/model/json/modfile.json') || isfile('./ramst.log') error('The dynare command did not honor the options provided in the mod file!') end diff --git a/tests/estimation/fs2000.mod b/tests/estimation/fs2000.mod index 071d047b65..e2e3466841 100644 --- a/tests/estimation/fs2000.mod +++ b/tests/estimation/fs2000.mod @@ -119,8 +119,8 @@ if ~isoctave error('Adding draws did not result in the same chain') end end - -if ~exist([M_.dname filesep 'Output'],'dir') + +if ~isfolder(sprintf('%s%sOutput', M_.dname, filesep)) mkdir(M_.dname,'Output'); end save([M_.dname filesep 'Output' filesep 'fs2000_results.mat'], 'oo_'); diff --git a/tests/optimal_policy/neo_growth_ramsey.mod b/tests/optimal_policy/neo_growth_ramsey.mod index b766c31536..14c50b116c 100644 --- a/tests/optimal_policy/neo_growth_ramsey.mod +++ b/tests/optimal_policy/neo_growth_ramsey.mod @@ -33,34 +33,39 @@ stoch_simul(order=2, irf=0); planner_objective_value = evaluate_planner_objective(M_, options_, oo_); -if ~exist(['neo_growth' filesep 'Output' filesep 'neo_growth_results.mat'],'file'); - error('neo_growth must be run first'); -end; +matfilename = sprintf('neo_growth%sOutput%sneo_growth_results.mat', filesep, filesep); + +if ~isfile(matfilename) + error('neo_growth must be run first') +end -oo1 = load(['neo_growth' filesep 'Output' filesep 'neo_growth_results'],'oo_'); -M1 = load(['neo_growth' filesep 'Output' filesep 'neo_growth_results'],'M_'); -options1 = load(['neo_growth' filesep 'Output' filesep 'neo_growth_results'],'options_'); -unc_W_hand = oo1.oo_.mean(strmatch('W',M1.M_.endo_names,'exact')); +[p, f, e] = fileparts(matfilename); +matfilebasename = fullfile(p, f); + +oo1 = load(matfilebasename,'oo_'); +M1 = load(matfilebasename,'M_'); +options1 = load(matfilebasename,'options_'); +unc_W_hand = oo1.oo_.mean(strmatch('W', M1.M_.endo_names,'exact')); initial_condition_states = repmat(oo1.oo_.dr.ys,1,M1.M_.maximum_lag); shock_matrix = zeros(1,M1.M_.exo_nbr); y_sim = simult_(M1.M_,options1.options_,initial_condition_states,oo1.oo_.dr,shock_matrix,options1.options_.order); cond_W_hand_L_SS=y_sim(strmatch('W',M1.M_.endo_names,'exact'),2); -if abs((unc_W_hand - planner_objective_value.unconditional)/unc_W_hand) > 1e-6; - error('Inaccurate unconditional welfare assessment'); -end; -if abs(cond_W_hand_L_SS - planner_objective_value.conditional.steady_initial_multiplier) > 1e-6; - error('Inaccurate conditional welfare with Lagrange multiplier set to its steady-state value'); -end; +if abs((unc_W_hand - planner_objective_value.unconditional)/unc_W_hand) > 1e-6 + error('Inaccurate unconditional welfare assessment') +end +if abs(cond_W_hand_L_SS - planner_objective_value.conditional.steady_initial_multiplier) > 1e-6 + error('Inaccurate conditional welfare with Lagrange multiplier set to its steady-state value') +end if abs(oo_.mean(strmatch('U',M_.endo_names,'exact'))-oo1.oo_.mean(strmatch('U',M1.M_.endo_names,'exact')))>1e-6 - error('Utility inconsistent'); + error('Utility inconsistent') end -if abs(planner_objective_value.unconditional-oo_.mean(strmatch('U',M_.endo_names,'exact'))/(1-beta)) > 1e-6; - error('Unconditional welfare assessment does not match utility'); -end; +if abs(planner_objective_value.unconditional-oo_.mean(strmatch('U',M_.endo_names,'exact'))/(1-beta)) > 1e-6 + error('Unconditional welfare assessment does not match utility') +end initial_condition_states = zeros(M1.M_.endo_nbr,M1.M_.maximum_lag); @@ -68,6 +73,6 @@ initial_condition_states(1:M1.M_.orig_endo_nbr,:) = repmat(oo1.oo_.dr.ys(1:M1.M_ shock_matrix = zeros(1,M1.M_.exo_nbr); y_sim = simult_(M1.M_,options1.options_,initial_condition_states,oo1.oo_.dr,shock_matrix,options1.options_.order); cond_W_hand_L_0=y_sim(strmatch('W',M1.M_.endo_names,'exact'),2); -if abs(cond_W_hand_L_0 - planner_objective_value.conditional.zero_initial_multiplier) > 1e-6; - error('Inaccurate conditional welfare with zero Lagrange multiplier'); +if abs(cond_W_hand_L_0 - planner_objective_value.conditional.zero_initial_multiplier) > 1e-6 + error('Inaccurate conditional welfare with zero Lagrange multiplier') end; diff --git a/tests/optimal_policy/neo_growth_ramsey_foresight.mod b/tests/optimal_policy/neo_growth_ramsey_foresight.mod index 1b87f9844d..b2833612f1 100644 --- a/tests/optimal_policy/neo_growth_ramsey_foresight.mod +++ b/tests/optimal_policy/neo_growth_ramsey_foresight.mod @@ -35,19 +35,24 @@ perfect_foresight_solver; planner_objective_value = evaluate_planner_objective(M_, options_, oo_); -if ~exist('neo_growth_foresight_results.mat','file'); - error('neo_growth_foresight must be run first'); +matfilename = sprintf('neo_growth_foresight%sOutput%sneo_growth_foresight_results.mat', filesep, filesep); + +if ~isfile(matfilename) + error('neo_growth_foresight must be run first') end; -oo1 = load(['neo_growth_foresight' filesep 'Output' filesep 'neo_growth_foresight_results'],'oo_'); -M1 = load(['neo_growth_foresight' filesep 'Output' filesep 'neo_growth_foresight_results'],'M_'); -options1 = load(['neo_growth_foresight' filesep 'Output' filesep 'neo_growth_foresight_results'],'options_'); +[p, f, e] = fileparts(matfilename); +matfilebasename = fullfile(p, f); + +oo1 = load(matfilebasename, 'oo_'); +M1 = load(matfilebasename, 'M_'); +options1 = load(matfilebasename, 'options_'); cond_W_hand = oo1.oo_.endo_simul(strmatch('W',M1.M_.endo_names,'exact'),2); unc_W_hand = oo1.oo_.endo_simul(strmatch('W',M1.M_.endo_names,'exact'),end); -if abs((unc_W_hand - planner_objective_value.unconditional)/unc_W_hand) > 1e-6; - error('Inaccurate unconditional welfare assessment'); -end; -if abs((cond_W_hand - planner_objective_value.conditional)/cond_W_hand) > 1e-6; - error('Inaccurate conditional welfare assessment'); -end; +if abs((unc_W_hand - planner_objective_value.unconditional)/unc_W_hand) > 1e-6 + error('Inaccurate unconditional welfare assessment') +end +if abs((cond_W_hand - planner_objective_value.conditional)/cond_W_hand) > 1e-6 + error('Inaccurate conditional welfare assessment') +end diff --git a/tests/optimal_policy/neo_growth_ramsey_k_order.mod b/tests/optimal_policy/neo_growth_ramsey_k_order.mod index e0aa648f9d..06a33d9f1c 100644 --- a/tests/optimal_policy/neo_growth_ramsey_k_order.mod +++ b/tests/optimal_policy/neo_growth_ramsey_k_order.mod @@ -35,15 +35,20 @@ evaluate_planner_objective(periods=10000,drop=1000); [W_dynpp] = k_order_welfare(oo_.dr, M_, options_); -if ~exist(['neo_growth_k_order' filesep 'Output' filesep 'neo_growth_k_order_results.mat'],'file'); - error('neo_growth_k_order must be run first'); -end; +matfilename = sprintf('neo_growth_k_order%sOutput%sneo_growth_k_order_results.mat', filesep, filesep); + +if ~isfile(matfilename) + error('neo_growth_k_order must be run first') +end -oo = load(['neo_growth_k_order' filesep 'Output' filesep 'neo_growth_k_order_results'],'oo_'); -M = load(['neo_growth_k_order' filesep 'Output' filesep 'neo_growth_k_order_results'],'M_'); -options = load(['neo_growth_k_order' filesep 'Output' filesep 'neo_growth_k_order_results'],'options_'); +[p, f, e] = fileparts(matfilename); +matfilebasename = fullfile(p, f); -ind_W = strmatch('W', M.M_.endo_names,'exact'); +oo = load(matfilebasename, 'oo_'); +M = load(matfilebasename, 'M_'); +options = load(matfilebasename, 'options_'); + +ind_W = strmatch('W', M.M_.endo_names, 'exact'); err = -1e6; for i = 1:options_.order @@ -53,6 +58,6 @@ for i = 1:options_.order err = max(err, tmp_err); end -if err > 1e-10; - error('Inaccurate assessment of the derivatives of the welfare function'); -end; +if err > 1e-10 + error('Inaccurate assessment of the derivatives of the welfare function') +end diff --git a/tests/run_block_bytecode_tests.m b/tests/run_block_bytecode_tests.m index 0c95b794ab..21f7058cae 100644 --- a/tests/run_block_bytecode_tests.m +++ b/tests/run_block_bytecode_tests.m @@ -56,7 +56,7 @@ for blockFlag = 0:1 % Workaround for strange race condition related to the static/dynamic % files (especially when we switch to/from use_dll) - if isoctave && exist('+ls2003_tmp') + if isoctave && isfolder('+ls2003_tmp') rmdir('+ls2003_tmp', 's'); pause(1) end diff --git a/tests/stochastic_simulations/example2long.mod b/tests/stochastic_simulations/example2long.mod index f68bd608a5..0c273a96a8 100644 --- a/tests/stochastic_simulations/example2long.mod +++ b/tests/stochastic_simulations/example2long.mod @@ -51,11 +51,15 @@ end; stoch_simul; -if ~exist(['example1long' filesep 'Output' filesep 'example1long_results.mat'],'file'); +matfilename = sprintf('example1long%sOutput%sexample1long_results.mat', filesep, filesep); + +if ~isfile(matfilename); error('example1long must be run first'); end; -oo1 = load(['example1long' filesep 'Output' filesep 'example1long_results'],'oo_'); +[p, f, e] = fileparts(matfilename); + +oo1 = load(fullfile(p, f), 'oo_'); dr0 = oo1.oo_.dr; dr = oo_.dr; @@ -100,4 +104,4 @@ end if d_ghs2>epsilon error('error in ghs2') -end \ No newline at end of file +end diff --git a/tests/stochastic_simulations/example2long_use_dll.mod b/tests/stochastic_simulations/example2long_use_dll.mod index 0dab99e81d..eda50bd03f 100644 --- a/tests/stochastic_simulations/example2long_use_dll.mod +++ b/tests/stochastic_simulations/example2long_use_dll.mod @@ -51,11 +51,15 @@ end; stoch_simul; -if ~exist(['example1long' filesep 'Output' filesep 'example1long_results.mat'],'file'); +matfilename = sprintf('example1long%sOutput%sexample1long_results.mat', filesep, filesep); + +if ~isfile(matfilename); error('example1long must be run first'); end; -oo1 = load(['example1long' filesep 'Output' filesep 'example1long_results'],'oo_'); +[p, f, e] = fileparts(matfilename); + +oo1 = load(fullname(p, f), 'oo_'); dr0 = oo1.oo_.dr; @@ -101,4 +105,4 @@ end if d_ghs2>epsilon error('error in ghs2') -end \ No newline at end of file +end -- GitLab