From 440a0e460bd26a1b773ed3876d430dffb60fe620 Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Thu, 22 Jul 2021 17:46:08 +0200
Subject: [PATCH] Storage of results: use subfolder

Ref. #1758
---
 doc/manual/source/running-dynare.rst          |  3 +-
 doc/manual/source/the-model-file.rst          |  9 +++--
 matlab/compute_mh_covariance_matrix.m         |  2 +-
 matlab/dynare_estimation.m                    |  2 +-
 matlab/dynare_estimation_1.m                  | 16 +++++----
 matlab/gsa/filt_mc_.m                         |  6 ++--
 matlab/marginal_density.m                     |  2 +-
 matlab/model_comparison.m                     |  4 +--
 matlab/partial_information/dr1_PI.m           |  2 +-
 matlab/simult.m                               |  2 +-
 matlab/stochastic_solvers.m                   |  8 ++---
 preprocessor                                  |  2 +-
 tests/AIM/fs2000_b1L1L_AIM.mod                |  2 +-
 tests/AIM/fs2000x10L9_L_AIM.mod               |  2 +-
 tests/AIM/fs2000x10_L9_L_AIM.mod              |  2 +-
 tests/AIM/ls2003_2L0L_AIM.mod                 |  2 +-
 tests/AIM/ls2003_2L2L_AIM.mod                 |  2 +-
 tests/Makefile.am                             |  7 ----
 .../fs2000_analytic_derivation.mod            | 36 +++++++++----------
 .../lola_solve_one_boundary_mfs1.mod          |  2 +-
 .../lola_solve_one_boundary_mfs2.mod          |  2 +-
 .../lola_solve_one_boundary_mfs3.mod          |  2 +-
 .../block_bytecode/lola_stochastic_block.mod  |  2 +-
 .../ramst_augmented_histval.mod               |  2 +-
 .../multiple_lead_lags/sim_endo_lead_lag.mod  |  4 +--
 .../sim_endo_lead_lag_aux_vars.mod            |  2 +-
 .../multiple_lead_lags/sim_exo_lead_lag.mod   |  4 +--
 .../sim_exo_lead_lag_aux_vars.mod             |  2 +-
 .../multiple_lead_lags/sim_lead_lag.mod       |  4 +--
 .../sim_lead_lag_aux_vars.mod                 |  2 +-
 .../rbc_det_exo_lag_2b.mod                    |  2 +-
 .../rbc_det_exo_lag_2c.mod                    |  2 +-
 .../rbc_det_stack_solve_algo_7.mod            |  4 +--
 .../rbc_det_stack_solve_algo_7_exo_lag.mod    |  4 +--
 .../rbc_det_stack_solve_algo_7_exo_lead.mod   |  4 +--
 .../Gali_2015_chapter_3_nonlinear.mod         |  2 +-
 .../estimation/MH_recover/fs2000_recover.mod  |  2 +-
 .../MH_recover/fs2000_recover_2.mod           |  4 +--
 .../MH_recover/fs2000_recover_3.mod           |  4 +--
 .../MH_recover/fs2000_recover_tarb.mod        |  2 +-
 tests/estimation/fs2000.mod                   |  8 ++---
 .../fs2000_MCMC_jumping_covariance.mod        |  4 +--
 .../heteroskedastic_shocks/fs2000_het.mod     |  2 +-
 .../fs2000_het_corr.mod                       |  2 +-
 tests/example1_use_dll.mod                    |  4 +--
 tests/example2long.mod                        |  4 +--
 tests/example2long_use_dll.mod                |  5 +--
 tests/external_function/extfun_in_mlv.mod     |  2 +-
 .../first_and_2nd_deriv_given.mod             |  2 +-
 .../first_and_2nd_deriv_given_dll.mod         |  2 +-
 ...irst_and_2nd_deriv_given_dll_namespace.mod |  2 +-
 .../first_and_2nd_deriv_given_namespace.mod   |  2 +-
 tests/external_function/first_deriv_given.mod |  2 +-
 .../first_deriv_given_dll.mod                 |  2 +-
 tests/external_function/no_deriv_given.mod    |  2 +-
 .../external_function/no_deriv_given_dll.mod  |  2 +-
 tests/gsa/ls2003.mod                          | 12 +++----
 .../sim_exo_lead_lag_initvalf.mod             | 10 +++---
 tests/k_order_perturbation/fs2000k2_m.mod     |  4 +--
 .../k_order_perturbation/fs2000k2_use_dll.mod |  4 +--
 tests/k_order_perturbation/fs2000k3_m.mod     |  4 +--
 .../k_order_perturbation/fs2000k3_use_dll.mod |  4 +--
 tests/k_order_perturbation/fs2000k_1_m.mod    |  4 +--
 .../fs2000k_1_use_dll.mod                     |  4 +--
 .../likelihood_from_dynare/fs2000_corr_ME.mod |  2 +-
 .../fs2000_corr_ME_missing.mod                |  2 +-
 .../fs2000_uncorr_ME.mod                      |  2 +-
 .../fs2000_uncorr_ME_missing.mod              |  2 +-
 .../fs2000ns_corr_ME.mod                      |  2 +-
 .../fs2000ns_corr_ME_missing.mod              |  2 +-
 .../fs2000ns_uncorr_ME.mod                    |  2 +-
 .../fs2000ns_uncorr_ME_missing.mod            |  2 +-
 tests/kalman_filter_smoother/algo2.mod        |  4 +--
 tests/kalman_filter_smoother/algo4.mod        |  4 +--
 tests/kalman_filter_smoother/algo4a.mod       |  2 +-
 tests/kalman_filter_smoother/algo4b.mod       |  2 +-
 tests/kalman_filter_smoother/algoH2.mod       |  4 +--
 tests/lmmcp/sw_newton.mod                     |  2 +-
 .../example4_loglinear_lagged_exogenous_a.mod |  2 +-
 .../model_borrcon/borrcon_0_std_shocks.mod    |  2 +-
 .../dynrbc_0_std_shocks.mod                   |  2 +-
 tests/optimal_policy/neo_growth_ramsey.mod    |  8 ++---
 .../neo_growth_ramsey_foresight.mod           |  6 ++--
 .../neo_growth_ramsey_k_order.mod             |  8 ++---
 .../nk_ramsey_expectation_a.mod               |  2 +-
 tests/optimizers/fs2000_102.mod               |  2 +-
 tests/optimizers/fs2000_6.mod                 |  4 +--
 tests/parallel/ls2003.mod                     |  4 +--
 .../AS_pruned_state_space_red_shock.mod       |  2 +-
 tests/second_order/ds2.mod                    |  2 +-
 tests/smoother2histval/fs2000_simul.mod       |  4 +--
 91 files changed, 173 insertions(+), 171 deletions(-)

diff --git a/doc/manual/source/running-dynare.rst b/doc/manual/source/running-dynare.rst
index 60469e61d6..824d9f8268 100644
--- a/doc/manual/source/running-dynare.rst
+++ b/doc/manual/source/running-dynare.rst
@@ -548,7 +548,8 @@ by the ``dynare`` command.
     results in the workspace available for further processing. More
     details are given under the relevant computing tasks. The
     ``M_``,``oo_``, and ``options_`` structures are saved in a file
-    called ``FILENAME_results.mat``. If they exist, ``estim_params_``,
+    called ``FILENAME_results.mat`` located in the ``MODFILENAME/Output`` folder.
+    If they exist, ``estim_params_``,
     ``bayestopt_``, ``dataset_``, ``oo_recursive_`` and
     ``estimation_info`` are saved in the same file. Note that Matlab 
     by default only allows ``.mat``-files up to 2GB. You can lift this 
diff --git a/doc/manual/source/the-model-file.rst b/doc/manual/source/the-model-file.rst
index fa0e2c0661..fcc42707b2 100644
--- a/doc/manual/source/the-model-file.rst
+++ b/doc/manual/source/the-model-file.rst
@@ -3890,7 +3890,8 @@ Computing the stochastic solution
        requested (i.e. ``periods`` :math:`>` 0). Note that if this
        option is greater than 1, the additional series will not be
        used for computing the empirical moments but will simply be
-       saved in binary form to the file ``FILENAME_simul``. Default:
+       saved in binary form to the file ``FILENAME_simul`` in the 
+       ``FILENAME/Output``-folder. Default:
        ``1``.
 
     .. option:: solve_algo = INTEGER
@@ -5297,7 +5298,8 @@ block decomposition of the model (see :opt:`block`).
        achieve an acceptance rate of
        :ref:`AcceptanceRateTarget<art>`. The resulting scale parameter
        will be saved into a file named
-       ``MODEL_FILENAME_mh_scale.mat.`` This file can be loaded in
+       ``MODEL_FILENAME_mh_scale.mat`` in the ``FILENAME/Output``-folder.
+       This file can be loaded in
        subsequent runs via the ``posterior_sampler_options`` option
        :ref:`scale_file <scale-file>`. Both ``mode_compute=6`` and
        ``scale_file`` will overwrite any value specified in
@@ -5378,7 +5380,8 @@ block decomposition of the model (see :opt:`block`).
        Name of the file containing previous value for the mode. When
        computing the mode, Dynare stores the mode (``xparam1``) and
        the hessian (``hh``, only if ``cova_compute=1``) in a file
-       called ``MODEL_FILENAME_mode.mat``. After a successful run of
+       called ``MODEL_FILENAME_mode.mat`` in the ``FILENAME/Output``-folder. 
+       After a successful run of
        the estimation command, the ``mode_file`` will be disabled to
        prevent other function calls from implicitly using an updated
        ``mode-file``. Thus, if the mod-file contains subsequent
diff --git a/matlab/compute_mh_covariance_matrix.m b/matlab/compute_mh_covariance_matrix.m
index ffd0b218e3..662d7b25a9 100644
--- a/matlab/compute_mh_covariance_matrix.m
+++ b/matlab/compute_mh_covariance_matrix.m
@@ -78,4 +78,4 @@ hh = inv(posterior_covariance);
 fval = posterior_kernel_at_the_mode;
 parameter_names = bayestopt_.name;
 
-save([M_.fname '_mh_mode.mat'],'xparam1','hh','fval','parameter_names');
\ No newline at end of file
+save([M_.dname filesep 'Output' filesep M_.fname '_mh_mode.mat'],'xparam1','hh','fval','parameter_names');
\ No newline at end of file
diff --git a/matlab/dynare_estimation.m b/matlab/dynare_estimation.m
index 073929ee17..a790d8a87c 100644
--- a/matlab/dynare_estimation.m
+++ b/matlab/dynare_estimation.m
@@ -101,7 +101,7 @@ if nnobs>1 || nfirstobs > 1
         end
         dynare_estimation_1(var_list,M_.dname);
         if isequal(i,1) && options_.mode_compute ~= 0
-            options_.mode_file = [M_.fname '_mode'];
+            options_.mode_file = [M_.dname filesep 'Output' filesep M_.fname '_mode'];
         end
         if options_.recursive_estimation_restart
             for j=1:options_.recursive_estimation_restart
diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m
index ee51830f9f..311f283bee 100644
--- a/matlab/dynare_estimation_1.m
+++ b/matlab/dynare_estimation_1.m
@@ -31,6 +31,10 @@ function dynare_estimation_1(var_list_,dname)
 
 global M_ options_ oo_ estim_params_ bayestopt_ dataset_ dataset_info
 
+if ~exist([M_.dname filesep 'Output'],'dir')
+    mkdir(M_.dname,'Output');
+end
+
 if isempty(estim_params_)
     mode_compute_o = options_.mode_compute;
     mh_replic_o = options_.mh_replic;
@@ -206,7 +210,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
         newratflag = new_rat_hess_info.newratflag;
         new_rat_hess_info = new_rat_hess_info.new_rat_hess_info;
     elseif isnumeric(options_.mode_compute) && options_.mode_compute==6 %save scaling factor
-        save([M_.fname '_optimal_mh_scale_parameter.mat'],'Scale');
+        save([M_.dname filesep 'Output' filesep M_.fname '_optimal_mh_scale_parameter.mat'],'Scale');
         options_.mh_jscale = Scale;
         bayestopt_.jscale(:) = options_.mh_jscale;
     end
@@ -260,9 +264,9 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
     end
     parameter_names = bayestopt_.name;
     if options_.cova_compute || options_.mode_compute==5 || options_.mode_compute==6
-        save([M_.fname '_mode.mat'],'xparam1','hh','parameter_names','fval');
+        save([M_.dname filesep 'Output' filesep M_.fname '_mode.mat'],'xparam1','hh','parameter_names','fval');
     else
-        save([M_.fname '_mode.mat'],'xparam1','parameter_names','fval');
+        save([M_.dname filesep 'Output' filesep M_.fname '_mode.mat'],'xparam1','parameter_names','fval');
     end
 end
 
@@ -375,7 +379,7 @@ end
 
 if np > 0
     pindx = estim_params_.param_vals(:,1);
-    save([M_.fname '_params.mat'],'pindx');
+    save([M_.dname filesep 'Output' filesep M_.fname '_params.mat'],'pindx');
 end
 
 switch options_.MCMC_jumping_covariance
@@ -472,7 +476,7 @@ if (any(bayestopt_.pshape  >0 ) && options_.mh_replic) || ...
     else
         %get stored results if required
         if options_.load_mh_file && options_.load_results_after_load_mh
-            oo_load_mh=load([M_.fname '_results'],'oo_');
+            oo_load_mh=load([M_.dname filesep 'Output' filesep M_.fname '_results'],'oo_');
         end
         if ~options_.nodiagnostic
             if (options_.mh_replic>0 || (options_.load_mh_file && ~options_.load_results_after_load_mh))
@@ -778,7 +782,7 @@ end
 
 if np > 0
     pindx = estim_params_.param_vals(:,1);
-    save([M_.fname '_pindx.mat'] ,'pindx');
+    save([M_.dname filesep 'Output' filesep M_.fname '_pindx.mat'] ,'pindx');
 end
 
 %reset qz_criterium
diff --git a/matlab/gsa/filt_mc_.m b/matlab/gsa/filt_mc_.m
index d15c6789d1..74b7c0fe10 100644
--- a/matlab/gsa/filt_mc_.m
+++ b/matlab/gsa/filt_mc_.m
@@ -92,11 +92,11 @@ if ~isempty(options_.mode_file)
     load(options_.mode_file,'xparam1')
 end
 if options_.opt_gsa.ppost
-    c=load([fname_,'_mean.mat'],'xparam1');
+    c=load([M_.dname filesep 'Output' filesep fname_,'_mean.mat'],'xparam1');
     xparam1_mean=c.xparam1;
     clear c
-elseif ~isempty(options_.mode_file) && exist([fname_,'_mean.mat'])==2
-    c=load([fname_,'_mean.mat'],'xparam1');
+elseif ~isempty(options_.mode_file) && exist([M_.dname filesep 'Output' filesep fname_,'_mean.mat'])==2
+    c=load([M_.dname filesep 'Output' filesep fname_,'_mean.mat'],'xparam1');
     xparam1_mean=c.xparam1;
     clear c
 end
diff --git a/matlab/marginal_density.m b/matlab/marginal_density.m
index 995df30a8e..bd10e86ea0 100644
--- a/matlab/marginal_density.m
+++ b/matlab/marginal_density.m
@@ -66,7 +66,7 @@ end
 % (usefull if the user wants to perform some computations using
 % the posterior mean instead of the posterior mode ==> ).
 parameter_names = bayestopt_.name;
-save([M_.fname '_mean.mat'],'xparam1','hh','parameter_names','SIGMA');
+save([M_.dname filesep 'Output' filesep M_.fname '_mean.mat'],'xparam1','hh','parameter_names','SIGMA');
 
 fprintf('Estimation::marginal density: I''m computing the posterior log marginal density (modified harmonic mean)... ');
 logdetSIGMA = log(det(SIGMA));
diff --git a/matlab/model_comparison.m b/matlab/model_comparison.m
index f49320adf2..302bda814c 100644
--- a/matlab/model_comparison.m
+++ b/matlab/model_comparison.m
@@ -81,9 +81,9 @@ for i=1:NumberOfModels
         mstruct.oo_ = oo;
     else
         if strcmpi(ModelNames{i}(end-3:end),'.mod') || strcmpi(ModelNames{i}(end-3:end),'.dyn')
-            mstruct = load([ModelNames{i}(1:end-4) '_results.mat' ],'oo_');
+            mstruct = load([ModelNames{i}(1:end-4) filesep 'Output' ModelNames{i}(1:end-4) '_results.mat' ],'oo_');
         else
-            mstruct = load([ModelNames{i} '_results.mat' ],'oo_');
+            mstruct = load([ModelNames{i} filesep 'Output' filesep ModelNames{i} '_results.mat' ],'oo_');
         end
     end
     try
diff --git a/matlab/partial_information/dr1_PI.m b/matlab/partial_information/dr1_PI.m
index a8cbc93d98..dfafa44a07 100644
--- a/matlab/partial_information/dr1_PI.m
+++ b/matlab/partial_information/dr1_PI.m
@@ -154,7 +154,7 @@ else
 end
 
 if options_.debug
-    save([M_.fname '_debug.mat'],'jacobia_')
+    save([M_.dname filesep 'Output' filesep M_.fname '_debug.mat'],'jacobia_')
 end
 
 dr=set_state_space(dr,M_,options_);
diff --git a/matlab/simult.m b/matlab/simult.m
index c03fb78db4..caeae45c4f 100644
--- a/matlab/simult.m
+++ b/matlab/simult.m
@@ -66,7 +66,7 @@ order = DynareOptions.order;
 replic = DynareOptions.simul_replic;
 
 if replic > 1
-    fname = [DynareModel.fname,'_simul'];
+    fname = [DynareModel.dname filesep 'Output' DynareModel.fname,'_simul'];
     fh = fopen(fname,'w+');
 end
 
diff --git a/matlab/stochastic_solvers.m b/matlab/stochastic_solvers.m
index 3b8d770fc2..4e04485685 100644
--- a/matlab/stochastic_solvers.m
+++ b/matlab/stochastic_solvers.m
@@ -128,7 +128,7 @@ elseif local_order == 2
         if ~isempty(infrow)
             fprintf('\nSTOCHASTIC_SOLVER: The Hessian of the dynamic model contains Inf.\n')
             fprintf('STOCHASTIC_SOLVER: Try running model_diagnostics to find the source of the problem.\n')
-            save([M_.fname '_debug.mat'],'hessian1')
+            save([M_.dname filesep 'Output' filesep M_.fname '_debug.mat'],'hessian1')
         end
     end
     if ~isempty(infrow)
@@ -140,7 +140,7 @@ elseif local_order == 2
         if ~isempty(nanrow)
             fprintf('\nSTOCHASTIC_SOLVER: The Hessian of the dynamic model contains NaN.\n')
             fprintf('STOCHASTIC_SOLVER: Try running model_diagnostics to find the source of the problem.\n')
-            save([M_.fname '_debug.mat'],'hessian1')
+            save([M_.dname filesep 'Output' filesep M_.fname '_debug.mat'],'hessian1')
         end
     end
     if ~isempty(nanrow)
@@ -155,7 +155,7 @@ if options_.debug
     if ~isempty(infrow)
         fprintf('\nSTOCHASTIC_SOLVER: The Jacobian of the dynamic model contains Inf. The problem is associated with:\n\n')
         display_problematic_vars_Jacobian(infrow,infcol,M_,dr.ys,'dynamic','STOCHASTIC_SOLVER: ')
-        save([M_.fname '_debug.mat'],'jacobia_')
+        save([M_.dname filesep 'Output' filesep M_.fname '_debug.mat'],'jacobia_')
     end
 end
 
@@ -184,7 +184,7 @@ if options_.debug
     if ~isempty(nanrow)
         fprintf('\nSTOCHASTIC_SOLVER: The Jacobian of the dynamic model contains NaN. The problem is associated with:\n\n')
         display_problematic_vars_Jacobian(nanrow,nancol,M_,dr.ys,'dynamic','STOCHASTIC_SOLVER: ')
-        save([M_.fname '_debug.mat'],'jacobia_')
+        save([M_.dname filesep 'Output' filesep M_.fname '_debug.mat'],'jacobia_')
     end
 end
 
diff --git a/preprocessor b/preprocessor
index 5cfe6303e2..bb19d98712 160000
--- a/preprocessor
+++ b/preprocessor
@@ -1 +1 @@
-Subproject commit 5cfe6303e26fcaeff204e6d2ca3988b169621f46
+Subproject commit bb19d98712f2599380dfc704f98b33531d7414de
diff --git a/tests/AIM/fs2000_b1L1L_AIM.mod b/tests/AIM/fs2000_b1L1L_AIM.mod
index 71a0ec1ade..ffd5d5bb07 100644
--- a/tests/AIM/fs2000_b1L1L_AIM.mod
+++ b/tests/AIM/fs2000_b1L1L_AIM.mod
@@ -92,7 +92,7 @@ steady(nocheck);
  
 stoch_simul(aim_solver, order=1, irf=0);
  
-benchmark = load('fs2000_b1L1L_results');
+benchmark = load(['fs2000_b1L1L' filesep 'Output' filesep 'fs2000_b1L1L_results']);
 threshold = 1e-8;
  
 if max(max(abs(benchmark.oo_.dr.ghx-oo_.dr.ghx) > threshold));
diff --git a/tests/AIM/fs2000x10L9_L_AIM.mod b/tests/AIM/fs2000x10L9_L_AIM.mod
index e651ff93d8..e52b2db37d 100644
--- a/tests/AIM/fs2000x10L9_L_AIM.mod
+++ b/tests/AIM/fs2000x10L9_L_AIM.mod
@@ -76,7 +76,7 @@ check;
 
 stoch_simul(aim_solver, order=1,irf=0);
  
-benchmark = load('fs2000x10L9_L_results');
+benchmark = load(['fs2000x10L9_L' filesep 'Output' filesep 'fs2000x10L9_L_results']);
 threshold = 1e-8;
  
 if max(max(abs(benchmark.oo_.dr.ghx-oo_.dr.ghx) > threshold));
diff --git a/tests/AIM/fs2000x10_L9_L_AIM.mod b/tests/AIM/fs2000x10_L9_L_AIM.mod
index fa80630c06..92c5c2179b 100644
--- a/tests/AIM/fs2000x10_L9_L_AIM.mod
+++ b/tests/AIM/fs2000x10_L9_L_AIM.mod
@@ -57,7 +57,7 @@ steady;
 
 stoch_simul(aim_solver, order=1,irf=0);
 
-benchmark = load('fs2000x10_L9_L_results');
+benchmark = load(['fs2000x10_L9_L' filesep 'Output' filesep 'fs2000x10_L9_L_results']);
 threshold = 1e-8;
  
 if max(max(abs(benchmark.oo_.dr.ghx-oo_.dr.ghx) > threshold));
diff --git a/tests/AIM/ls2003_2L0L_AIM.mod b/tests/AIM/ls2003_2L0L_AIM.mod
index 8ff90c3e5a..175b852426 100644
--- a/tests/AIM/ls2003_2L0L_AIM.mod
+++ b/tests/AIM/ls2003_2L0L_AIM.mod
@@ -45,7 +45,7 @@ end;
 
 stoch_simul(aim_solver, order=1,irf=0);
  
-benchmark = load('ls2003_2L0L_results');
+benchmark = load(['ls2003_2L0L' filesep 'Output' filesep 'ls2003_2L0L_results']);
 threshold = 1e-8;
  
 if max(max(abs(benchmark.oo_.dr.ghx-oo_.dr.ghx) > threshold));
diff --git a/tests/AIM/ls2003_2L2L_AIM.mod b/tests/AIM/ls2003_2L2L_AIM.mod
index 11f60720dc..0fcef43fff 100644
--- a/tests/AIM/ls2003_2L2L_AIM.mod
+++ b/tests/AIM/ls2003_2L2L_AIM.mod
@@ -43,7 +43,7 @@ end;
 
 stoch_simul(aim_solver, order=1,irf=0);
  
-benchmark = load('ls2003_2L2L_results');
+benchmark = load(['ls2003_2L2L' filesep 'Output' filesep 'ls2003_2L2L_results']);
 threshold = 1e-8;
  
 if max(max(abs(benchmark.oo_.dr.ghx-oo_.dr.ghx) > threshold));
diff --git a/tests/Makefile.am b/tests/Makefile.am
index aa84d1cf01..5f981419e2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1412,13 +1412,6 @@ clean-local:
 	rm -f $(patsubst %.trs, %.json, $(O_TRS_FILES))
 	rm -f $(patsubst %.trs, %.json, $(O_XFAIL_TRS_FILES))
 
-	rm -f $(patsubst %.mod, %_results.mat, $(MODFILES))
-	rm -f $(patsubst %.mod, %_mode.mat, $(MODFILES))
-	rm -f $(patsubst %.mod, %_mh_mode.mat, $(MODFILES))
-	rm -f $(patsubst %.mod, %_mean.mat, $(MODFILES))
-	rm -f $(patsubst %.mod, %_pindx.mat, $(MODFILES))
-	rm -f $(patsubst %.mod, %_params.mat, $(MODFILES))
-	rm -f $(patsubst %.mod, %_simul, $(MODFILES))
 	rm -f $(patsubst %.mod, %.log, $(MODFILES))
 
 	rm -rf $(patsubst %.mod, %, $(MODFILES))
diff --git a/tests/analytic_derivatives/fs2000_analytic_derivation.mod b/tests/analytic_derivatives/fs2000_analytic_derivation.mod
index 677b0f2e12..c74af9d655 100644
--- a/tests/analytic_derivatives/fs2000_analytic_derivation.mod
+++ b/tests/analytic_derivatives/fs2000_analytic_derivation.mod
@@ -78,22 +78,22 @@ options_.solve_tolf = 1e-12;
 
 estimation(order=1,mode_compute=9,analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0,prior_trunc=0);
 if (isoctave && user_has_octave_forge_package('optim', '1.6')) || (~isoctave && user_has_matlab_license('optimization_toolbox'))
-    estimation(order=1,mode_compute=1,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0
+    estimation(order=1,mode_compute=1,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0
     %,optim = ('DerivativeCheck', 'on','FiniteDifferenceType','central')
     );
-    estimation(order=1,mode_compute=3,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
-    estimation(order=1,mode_compute=101,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);    
+    estimation(order=1,mode_compute=3,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
+    estimation(order=1,mode_compute=101,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);    
 end
-estimation(order=1,mode_compute=5,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=2,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
-estimation(order=1,mode_compute=4,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
-estimation(order=1,mode_compute=4,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=2,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
+estimation(order=1,mode_compute=5,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=2,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
+estimation(order=1,mode_compute=4,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
+estimation(order=1,mode_compute=4,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=2,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
 options_.debug=1;
-estimation(order=1,mode_compute=0,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,plot_priors=0);
+estimation(order=1,mode_compute=0,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,plot_priors=0);
 fval_ML_1=oo_.likelihood_at_initial_parameters;
-estimation(order=1,mode_compute=0,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=2,datafile=my_data,nobs=192,mh_replic=0,plot_priors=0);
+estimation(order=1,mode_compute=0,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=2,datafile=my_data,nobs=192,mh_replic=0,plot_priors=0);
 fval_ML_2=oo_.likelihood_at_initial_parameters;
 options_.analytic_derivation=0;
-estimation(order=1,mode_compute=0,mode_file=fs2000_analytic_derivation_mode,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,plot_priors=0);
+estimation(order=1,mode_compute=0,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,plot_priors=0);
 fval_ML_3=oo_.likelihood_at_initial_parameters;
 
 if abs(fval_ML_1-fval_ML_2)>1e-5 || abs(fval_ML_1-fval_ML_3)>1e-5
@@ -111,22 +111,22 @@ end;
 
 estimation(order=1,mode_compute=9,analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0,prior_trunc=0);
 if (isoctave && user_has_octave_forge_package('optim', '1.6')) || (~isoctave && user_has_matlab_license('optimization_toolbox'))
-    estimation(order=1,mode_compute=1,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0
+    estimation(order=1,mode_compute=1,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0
     %,optim = ('DerivativeCheck', 'on','FiniteDifferenceType','central')
     );
-    estimation(order=1,mode_compute=3,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
-    estimation(order=1,mode_compute=101,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);    
+    estimation(order=1,mode_compute=3,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
+    estimation(order=1,mode_compute=101,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);    
 end
-estimation(order=1,mode_compute=5,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=2,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
-estimation(order=1,mode_compute=4,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
-estimation(order=1,mode_compute=4,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=2,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
+estimation(order=1,mode_compute=5,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=2,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
+estimation(order=1,mode_compute=4,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
+estimation(order=1,mode_compute=4,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=2,datafile=my_data,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8,plot_priors=0);
 options_.debug=1;
-estimation(order=1,mode_compute=0,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,plot_priors=0);
+estimation(order=1,mode_compute=0,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,plot_priors=0);
 fval_Bayes_1=oo_.likelihood_at_initial_parameters;
-estimation(order=1,mode_compute=0,mode_file=fs2000_analytic_derivation_mode,analytic_derivation,kalman_algo=2,datafile=my_data,nobs=192,mh_replic=0,plot_priors=0);
+estimation(order=1,mode_compute=0,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',analytic_derivation,kalman_algo=2,datafile=my_data,nobs=192,mh_replic=0,plot_priors=0);
 fval_Bayes_2=oo_.likelihood_at_initial_parameters;
 options_.analytic_derivation=0;
-estimation(order=1,mode_compute=0,mode_file=fs2000_analytic_derivation_mode,kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,plot_priors=0);
+estimation(order=1,mode_compute=0,mode_file='fs2000_analytic_derivation/Output/fs2000_analytic_derivation_mode',kalman_algo=1,datafile=my_data,nobs=192,mh_replic=0,plot_priors=0);
 fval_Bayes_3=oo_.likelihood_at_initial_parameters;
 
 if abs(fval_Bayes_1-fval_Bayes_2)>1e-5 || abs(fval_Bayes_1-fval_Bayes_3)>1e-5
diff --git a/tests/block_bytecode/lola_solve_one_boundary_mfs1.mod b/tests/block_bytecode/lola_solve_one_boundary_mfs1.mod
index 553171257d..64ff378bf7 100644
--- a/tests/block_bytecode/lola_solve_one_boundary_mfs1.mod
+++ b/tests/block_bytecode/lola_solve_one_boundary_mfs1.mod
@@ -5,7 +5,7 @@
 @#define mfs = 1
 @#include "lola_common.inc"
 
-mfs0=load('lola_solve_one_boundary_results');
+mfs0=load(['lola_solve_one_boundary' filesep 'Output' filesep 'lola_solve_one_boundary_results']);
 
 if max(max(oo_.endo_simul-mfs0.oo_.endo_simul)) > options_.dynatol.x
    error('Inconsistency with mfs=0')
diff --git a/tests/block_bytecode/lola_solve_one_boundary_mfs2.mod b/tests/block_bytecode/lola_solve_one_boundary_mfs2.mod
index f582ecc844..db5d379d59 100644
--- a/tests/block_bytecode/lola_solve_one_boundary_mfs2.mod
+++ b/tests/block_bytecode/lola_solve_one_boundary_mfs2.mod
@@ -5,7 +5,7 @@
 @#define mfs = 2
 @#include "lola_common.inc"
 
-mfs0=load('lola_solve_one_boundary_results');
+mfs0=load(['lola_solve_one_boundary' filesep 'Output' filesep 'lola_solve_one_boundary_results']);
 
 if max(max(oo_.endo_simul-mfs0.oo_.endo_simul)) > options_.dynatol.x
    error('Inconsistency with mfs=0')
diff --git a/tests/block_bytecode/lola_solve_one_boundary_mfs3.mod b/tests/block_bytecode/lola_solve_one_boundary_mfs3.mod
index 3eb2dc9f01..16b227463e 100644
--- a/tests/block_bytecode/lola_solve_one_boundary_mfs3.mod
+++ b/tests/block_bytecode/lola_solve_one_boundary_mfs3.mod
@@ -5,7 +5,7 @@
 @#define mfs = 3
 @#include "lola_common.inc"
 
-mfs0=load('lola_solve_one_boundary_results');
+mfs0=load(['lola_solve_one_boundary' filesep 'Output' filesep 'lola_solve_one_boundary_results']);
 
 if max(max(oo_.endo_simul-mfs0.oo_.endo_simul)) > options_.dynatol.x
    error('Inconsistency with mfs=0')
diff --git a/tests/block_bytecode/lola_stochastic_block.mod b/tests/block_bytecode/lola_stochastic_block.mod
index 5f6fff6b85..954ecd4625 100644
--- a/tests/block_bytecode/lola_stochastic_block.mod
+++ b/tests/block_bytecode/lola_stochastic_block.mod
@@ -8,7 +8,7 @@
 
 [~, state_reorder] = sort(oo_.dr.state_var);
 
-ref = load('lola_stochastic_results.mat');
+ref = load(['lola_stochastic' filesep 'Output' filesep 'lola_stochastic_results.mat']);
 
 [~, ref_state_reorder] = sort(ref.oo_.dr.state_var);
 
diff --git a/tests/deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.mod b/tests/deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.mod
index 52aa9de85c..fb362e0dca 100644
--- a/tests/deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.mod
+++ b/tests/deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.mod
@@ -70,7 +70,7 @@ if max(abs(junk(M_.maximum_lag+1:end)-oo_.endo_simul(strmatch('y_backward',M_.en
     error('Solution of purely backwards model not correct')
 end
         
-ramst_results=load('../../ramst_results.mat');
+ramst_results=load('../../ramst/Output/ramst_results.mat');
 if max(abs(ramst_results.oo_.endo_simul(strmatch('k',ramst_results.M_.endo_names,'exact'),1:end-M_.maximum_lead)-oo_.endo_simul(strmatch('k',M_.endo_names,'exact'),1:end-M_.maximum_lead)))>1e-10
     error('Solution of forward part of the model not correct')
 end
diff --git a/tests/deterministic_simulations/multiple_lead_lags/sim_endo_lead_lag.mod b/tests/deterministic_simulations/multiple_lead_lags/sim_endo_lead_lag.mod
index bf21b61498..eedbad7021 100644
--- a/tests/deterministic_simulations/multiple_lead_lags/sim_endo_lead_lag.mod
+++ b/tests/deterministic_simulations/multiple_lead_lags/sim_endo_lead_lag.mod
@@ -44,7 +44,7 @@ if ~oo_.deterministic_simulation.status
    error('Perfect foresight simulation failed')
 end
 
-base_results=load('sim_base_results.mat');
+base_results=load(['sim_base' filesep 'Output' filesep 'sim_base_results.mat']);
 if max(abs(base_results.oo_.endo_simul(strmatch('c',base_results.M_.endo_names,'exact'),1+base_results.M_.maximum_endo_lag:end-base_results.M_.maximum_endo_lead) -...
     oo_.endo_simul(strmatch('c',M_.endo_names,'exact'),1+M_.maximum_endo_lag:end-M_.maximum_endo_lead)))>1e-8 || ...
     max(abs(base_results.oo_.endo_simul(strmatch('k',base_results.M_.endo_names,'exact'),1+base_results.M_.maximum_endo_lag:end-base_results.M_.maximum_endo_lead) -...
@@ -58,7 +58,7 @@ if max(abs(base_results.oo_.exo_simul(1:end-base_results.M_.maximum_lead-base_re
 end
 
 clear base_results;
-base_results_aux_vars=load('sim_endo_lead_lag_aux_vars_results.mat');
+base_results_aux_vars=load(['sim_exo_lead_lag_aux_vars' filesep 'Output' filesep 'sim_exo_lead_lag_aux_vars_results.mat']);
 if max(abs(base_results_aux_vars.oo_.endo_simul(strmatch('z_backward_lag_2',base_results_aux_vars.M_.endo_names,'exact'),1:end-base_results_aux_vars.M_.maximum_lead) -...
     oo_.endo_simul(strmatch('AUX_ENDO_LAG_2_2',M_.endo_names,'exact'),1:end-M_.maximum_lag)))>1e-8 
     error('Translation of endogenous variables is wrong')
diff --git a/tests/deterministic_simulations/multiple_lead_lags/sim_endo_lead_lag_aux_vars.mod b/tests/deterministic_simulations/multiple_lead_lags/sim_endo_lead_lag_aux_vars.mod
index 9c5a26f4da..d291d91815 100644
--- a/tests/deterministic_simulations/multiple_lead_lags/sim_endo_lead_lag_aux_vars.mod
+++ b/tests/deterministic_simulations/multiple_lead_lags/sim_endo_lead_lag_aux_vars.mod
@@ -47,7 +47,7 @@ if ~oo_.deterministic_simulation.status
    error('Perfect foresight simulation failed')
 end
 
-base_results=load('sim_base_results.mat');
+base_results=load(['sim_base' filesep 'Output' filesep 'sim_base_results.mat']);
 if max(abs(base_results.oo_.endo_simul(strmatch('c',base_results.M_.endo_names,'exact'),1+base_results.M_.maximum_endo_lag:end-base_results.M_.maximum_endo_lead) -...
     oo_.endo_simul(strmatch('c',M_.endo_names,'exact'),1+M_.maximum_endo_lag:end-M_.maximum_endo_lead)))>1e-8 || ...
     max(abs(base_results.oo_.endo_simul(strmatch('k',base_results.M_.endo_names,'exact'),1+base_results.M_.maximum_endo_lag:end-base_results.M_.maximum_endo_lead) -...
diff --git a/tests/deterministic_simulations/multiple_lead_lags/sim_exo_lead_lag.mod b/tests/deterministic_simulations/multiple_lead_lags/sim_exo_lead_lag.mod
index fa0c3d384e..d84479a45e 100644
--- a/tests/deterministic_simulations/multiple_lead_lags/sim_exo_lead_lag.mod
+++ b/tests/deterministic_simulations/multiple_lead_lags/sim_exo_lead_lag.mod
@@ -42,7 +42,7 @@ if ~oo_.deterministic_simulation.status
    error('Perfect foresight simulation failed')
 end
 
-base_results=load('sim_base_results.mat');
+base_results=load(['sim_base' filesep 'Output' filesep 'sim_base_results.mat']);
 if max(abs(base_results.oo_.endo_simul(strmatch('c',base_results.M_.endo_names,'exact'),1+base_results.M_.maximum_endo_lag:end-base_results.M_.maximum_endo_lead) -...
     oo_.endo_simul(strmatch('c',M_.endo_names,'exact'),1+M_.maximum_lag:end-M_.maximum_lead)))>1e-8 || ...
     max(abs(base_results.oo_.endo_simul(strmatch('k',base_results.M_.endo_names,'exact'),1+base_results.M_.maximum_endo_lag:end-base_results.M_.maximum_endo_lead) -...
@@ -51,7 +51,7 @@ if max(abs(base_results.oo_.endo_simul(strmatch('c',base_results.M_.endo_names,'
 end
 
 clear base_results
-base_results_aux_vars=load('sim_exo_lead_lag_aux_vars_results.mat');
+base_results_aux_vars=load(['sim_exo_lead_lag_aux_vars' filesep 'Output' filesep 'sim_exo_lead_lag_aux_vars_results.mat']);
 
 if max(abs(base_results_aux_vars.oo_.endo_simul(strmatch('x_lag_3',base_results_aux_vars.M_.endo_names,'exact'),base_results_aux_vars.M_.maximum_lag+3:end-base_results_aux_vars.M_.maximum_lead)' -...
     oo_.exo_simul(M_.maximum_lag:end-M_.maximum_lead-3,strmatch('x', M_.exo_names, 'exact'))))>1e-8
diff --git a/tests/deterministic_simulations/multiple_lead_lags/sim_exo_lead_lag_aux_vars.mod b/tests/deterministic_simulations/multiple_lead_lags/sim_exo_lead_lag_aux_vars.mod
index 0cf9342aeb..113812b5d9 100644
--- a/tests/deterministic_simulations/multiple_lead_lags/sim_exo_lead_lag_aux_vars.mod
+++ b/tests/deterministic_simulations/multiple_lead_lags/sim_exo_lead_lag_aux_vars.mod
@@ -47,7 +47,7 @@ if ~oo_.deterministic_simulation.status
    error('Perfect foresight simulation failed')
 end
 
-base_results=load('sim_base_results.mat');
+base_results=load(['sim_base' filesep 'Output' filesep 'sim_base_results.mat']);
 if max(abs(base_results.oo_.endo_simul(strmatch('c',base_results.M_.endo_names,'exact'),1+base_results.M_.maximum_endo_lag:end-base_results.M_.maximum_endo_lead) -...
     oo_.endo_simul(strmatch('c',M_.endo_names,'exact'),1+M_.maximum_endo_lag:end-M_.maximum_endo_lead)))>1e-8 || ...
     max(abs(base_results.oo_.endo_simul(strmatch('k',base_results.M_.endo_names,'exact'),1+base_results.M_.maximum_endo_lag:end-base_results.M_.maximum_endo_lead) -...
diff --git a/tests/deterministic_simulations/multiple_lead_lags/sim_lead_lag.mod b/tests/deterministic_simulations/multiple_lead_lags/sim_lead_lag.mod
index d39ce7c7b8..8187405455 100644
--- a/tests/deterministic_simulations/multiple_lead_lags/sim_lead_lag.mod
+++ b/tests/deterministic_simulations/multiple_lead_lags/sim_lead_lag.mod
@@ -46,7 +46,7 @@ if ~oo_.deterministic_simulation.status
    error('Perfect foresight simulation failed')
 end
 
-base_results=load('sim_base_results.mat');
+base_results=load(['sim_base' filesep 'Output' filesep 'sim_base_results.mat']);
 if max(abs(base_results.oo_.endo_simul(strmatch('c',base_results.M_.endo_names,'exact'),1+base_results.M_.maximum_endo_lag:end-base_results.M_.maximum_endo_lead) -...
     oo_.endo_simul(strmatch('c',M_.endo_names,'exact'),1+M_.maximum_lag:end-M_.maximum_lead)))>1e-8 || ...
     max(abs(base_results.oo_.endo_simul(strmatch('k',base_results.M_.endo_names,'exact'),1+base_results.M_.maximum_endo_lag:end-base_results.M_.maximum_endo_lead) -...
@@ -55,7 +55,7 @@ if max(abs(base_results.oo_.endo_simul(strmatch('c',base_results.M_.endo_names,'
 end
 
 clear base_results
-base_results_aux_vars=load('sim_lead_lag_aux_vars_results.mat');
+base_results_aux_vars=load(['sim_exo_lead_lag_aux_vars' filesep 'Output' filesep 'sim_exo_lead_lag_aux_vars_results.mat']);
 
 if max(abs(base_results_aux_vars.oo_.endo_simul(strmatch('x_lag_3',base_results_aux_vars.M_.endo_names,'exact'),base_results_aux_vars.M_.maximum_lag+3:end-base_results_aux_vars.M_.maximum_lead)' -...
     oo_.exo_simul(M_.maximum_lag:end-M_.maximum_lead-3,strmatch('x', M_.exo_names, 'exact'))))>1e-8
diff --git a/tests/deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.mod b/tests/deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.mod
index a09c0d0e64..b35cacd458 100644
--- a/tests/deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.mod
+++ b/tests/deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.mod
@@ -57,7 +57,7 @@ if ~oo_.deterministic_simulation.status
    error('Perfect foresight simulation failed')
 end
 
-base_results=load('sim_base_results.mat');
+base_results=load(['sim_base' filesep 'Output' filesep 'sim_base_results.mat']);
 if max(abs(base_results.oo_.endo_simul(strmatch('c',base_results.M_.endo_names,'exact'),1+base_results.M_.maximum_endo_lag:end-base_results.M_.maximum_endo_lead) -...
     oo_.endo_simul(strmatch('c',M_.endo_names,'exact'),1+M_.maximum_endo_lag:end-M_.maximum_endo_lead)))>1e-8 || ...
     max(abs(base_results.oo_.endo_simul(strmatch('k',base_results.M_.endo_names,'exact'),1+base_results.M_.maximum_endo_lag:end-base_results.M_.maximum_endo_lead) -...
diff --git a/tests/deterministic_simulations/rbc_det_exo_lag_2b.mod b/tests/deterministic_simulations/rbc_det_exo_lag_2b.mod
index 8965fc18f1..60e7e7cc5d 100644
--- a/tests/deterministic_simulations/rbc_det_exo_lag_2b.mod
+++ b/tests/deterministic_simulations/rbc_det_exo_lag_2b.mod
@@ -79,6 +79,6 @@ end
 rplot Consumption;
 rplot Capital;
 
-O=load('rbc_det_exo_lag_2a_results');
+O=load(['rbc_det_exo_lag_2a' filesep 'Output' filesep 'rbc_det_exo_lag_2a_results']);
 
 fataltest(oo_.endo_simul(1:M_.orig_endo_nbr,:),O.oo_.endo_simul(1:O.M_.orig_endo_nbr,:),1);
diff --git a/tests/deterministic_simulations/rbc_det_exo_lag_2c.mod b/tests/deterministic_simulations/rbc_det_exo_lag_2c.mod
index a1b5c2ae0d..75e44854c8 100644
--- a/tests/deterministic_simulations/rbc_det_exo_lag_2c.mod
+++ b/tests/deterministic_simulations/rbc_det_exo_lag_2c.mod
@@ -79,6 +79,6 @@ end
 rplot Consumption;
 rplot Capital;
 
-O=load('rbc_det_exo_lag_2a_results');
+O=load(['rbc_det_exo_lag_2a' filesep 'Output' filesep 'rbc_det_exo_lag_2a_results']);
 
 fataltest(oo_.endo_simul(1:M_.orig_endo_nbr,:),O.oo_.endo_simul(1:O.M_.orig_endo_nbr,:),1);
diff --git a/tests/deterministic_simulations/rbc_det_stack_solve_algo_7.mod b/tests/deterministic_simulations/rbc_det_stack_solve_algo_7.mod
index a4c829ffb3..aec2adb46c 100644
--- a/tests/deterministic_simulations/rbc_det_stack_solve_algo_7.mod
+++ b/tests/deterministic_simulations/rbc_det_stack_solve_algo_7.mod
@@ -81,7 +81,7 @@ end
 rplot Consumption;
 rplot Capital;
 
-D = load('rbc_det_results');
+D = load(['rbc_det' filesep 'Output' filesep 'rbc_det_results']);
 
 if norm(D.oo_.endo_simul - oo_.endo_simul) > 1e-30;
    disp(norm(D.oo_.endo_simul - oo_.endo_simul));
@@ -102,7 +102,7 @@ end
 rplot Consumption;
 rplot Capital;
 
-D = load('rbc_det_results');
+D = load(['rbc_det' filesep 'Output' filesep 'rbc_det_results']);
 if isoctave && options_.solve_algo==0
     %%acount for somehow weaker convergence criterion in Octave's fsolve
     tol_crit=1e-4;
diff --git a/tests/deterministic_simulations/rbc_det_stack_solve_algo_7_exo_lag.mod b/tests/deterministic_simulations/rbc_det_stack_solve_algo_7_exo_lag.mod
index e449069044..3c35acebd4 100644
--- a/tests/deterministic_simulations/rbc_det_stack_solve_algo_7_exo_lag.mod
+++ b/tests/deterministic_simulations/rbc_det_stack_solve_algo_7_exo_lag.mod
@@ -81,7 +81,7 @@ end
 rplot Consumption;
 rplot Capital;
 
-D = load('rbc_det_results');
+D = load(['rbc_det' filesep 'Output' filesep 'rbc_det_results']);
 
 if norm(D.oo_.endo_simul(1:D.M_.orig_endo_nbr,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(1:M_.orig_endo_nbr,M_.maximum_lag+1:end-M_.maximum_lead)) > 1e-30;
    disp(D.oo_.endo_simul(1:D.M_.orig_endo_nbr,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(1:M_.orig_endo_nbr,M_.maximum_lag+1:end-M_.maximum_lead));
@@ -102,7 +102,7 @@ end
 rplot Consumption;
 rplot Capital;
 
-D = load('rbc_det_results');
+D = load(['rbc_det' filesep 'Output' filesep 'rbc_det_results']);
 if isoctave && options_.solve_algo==0
     %%acount for somehow weaker convergence criterion in Octave's fsolve
     tol_crit=1e-4;
diff --git a/tests/deterministic_simulations/rbc_det_stack_solve_algo_7_exo_lead.mod b/tests/deterministic_simulations/rbc_det_stack_solve_algo_7_exo_lead.mod
index 9d649d9023..60b969a688 100644
--- a/tests/deterministic_simulations/rbc_det_stack_solve_algo_7_exo_lead.mod
+++ b/tests/deterministic_simulations/rbc_det_stack_solve_algo_7_exo_lead.mod
@@ -81,7 +81,7 @@ end
 rplot Consumption;
 rplot Capital;
 
-D = load('rbc_det_results');
+D = load(['rbc_det' filesep 'Output' filesep 'rbc_det_results']);
 
 if norm(D.oo_.endo_simul(1:D.M_.orig_endo_nbr,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(1:M_.orig_endo_nbr,M_.maximum_lag+1:end-M_.maximum_lead)) > 1e-30;
    disp(D.oo_.endo_simul(1:D.M_.orig_endo_nbr,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(1:M_.orig_endo_nbr,M_.maximum_lag+1:end-M_.maximum_lead));
@@ -102,7 +102,7 @@ end
 rplot Consumption;
 rplot Capital;
 
-D = load('rbc_det_results');
+D = load(['rbc_det' filesep 'Output' filesep 'rbc_det_results']);
 if isoctave && options_.solve_algo==0
     %%acount for somehow weaker convergence criterion in Octave's fsolve
     tol_crit=1e-4;
diff --git a/tests/discretionary_policy/Gali_2015_chapter_3_nonlinear.mod b/tests/discretionary_policy/Gali_2015_chapter_3_nonlinear.mod
index 26ecf95d73..ca76e30335 100644
--- a/tests/discretionary_policy/Gali_2015_chapter_3_nonlinear.mod
+++ b/tests/discretionary_policy/Gali_2015_chapter_3_nonlinear.mod
@@ -219,7 +219,7 @@ end;
 planner_objective 0.5*((siggma+(varphi+alppha)/(1-alppha))*y_hat^2+epsilon/0.0215*pi^2)/100;
 discretionary_policy(order=1,instruments=(R),irf=20,planner_discount=betta, periods=0) y_hat pi_ann log_y log_N log_W_real log_P;
 
-temp=load('Gali_2015_chapter_3_results.mat');
+temp=load(['Gali_2015_chapter_3' filesep 'Output' filesep 'Gali_2015_chapter_3_results.mat']);
 if abs(oo_.planner_objective_value-temp.oo_.planner_objective_value)>1e-6
     warning('Planner objective does not match linear model')
 end
diff --git a/tests/estimation/MH_recover/fs2000_recover.mod b/tests/estimation/MH_recover/fs2000_recover.mod
index 7a55782f60..5b551e8d2e 100644
--- a/tests/estimation/MH_recover/fs2000_recover.mod
+++ b/tests/estimation/MH_recover/fs2000_recover.mod
@@ -8,7 +8,7 @@ copyfile([M_.dname filesep 'metropolis' filesep M_.dname '_mh1_blck1.mat'],[M_.d
 copyfile([M_.dname filesep 'metropolis' filesep M_.dname '_mh2_blck2.mat'],[M_.dname '_mh2_blck2.mat'])
 delete([M_.dname filesep 'metropolis' filesep M_.dname '_mh2_blck2.mat'])
 
-estimation(order=1, datafile='../fsdat_simul',mode_compute=0,mode_file=fs2000_recover_mode, nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8,mh_recover);
+estimation(order=1, datafile='../fsdat_simul',mode_compute=0,mode_file='fs2000_recover/Output/fs2000_recover_mode', nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8,mh_recover);
 
 %check first unaffected chain
 temp1=load([M_.dname '_mh1_blck1.mat']);
diff --git a/tests/estimation/MH_recover/fs2000_recover_2.mod b/tests/estimation/MH_recover/fs2000_recover_2.mod
index 11800bcb9c..cb70cd1c9d 100644
--- a/tests/estimation/MH_recover/fs2000_recover_2.mod
+++ b/tests/estimation/MH_recover/fs2000_recover_2.mod
@@ -5,7 +5,7 @@
 
 options_.MaxNumberOfBytes=2000*11*8/4;
 estimation(order=1, datafile='../fsdat_simul',nobs=192, loglinear, mh_replic=999, mh_nblocks=2, mh_jscale=0.8);
-estimation(order=1,mode_compute=0,mode_file=fs2000_recover_2_mode, datafile='../fsdat_simul',nobs=192, loglinear, load_mh_file,mh_replic=1002, mh_nblocks=2, mh_jscale=0.8);
+estimation(order=1,mode_compute=0,mode_file='fs2000_recover_2/Output/fs2000_recover_2_mode', datafile='../fsdat_simul',nobs=192, loglinear, load_mh_file,mh_replic=1002, mh_nblocks=2, mh_jscale=0.8);
 copyfile([M_.dname filesep 'metropolis' filesep M_.dname '_mh1_blck1.mat'],[M_.dname '_mh1_blck1.mat'])
 copyfile([M_.dname filesep 'metropolis' filesep M_.dname '_mh3_blck2.mat'],[M_.dname '_mh3_blck2.mat'])
 copyfile([M_.dname filesep 'metropolis' filesep M_.dname '_mh4_blck2.mat'],[M_.dname '_mh4_blck2.mat'])
@@ -14,7 +14,7 @@ delete([M_.dname filesep 'metropolis' filesep M_.dname '_mh3_blck2.mat'])
 delete([M_.dname filesep 'metropolis' filesep M_.dname '_mh4_blck2.mat'])
 delete([M_.dname filesep 'metropolis' filesep M_.dname '_mh5_blck2.mat'])
 
-estimation(order=1, datafile='../fsdat_simul',mode_compute=0,mode_file=fs2000_recover_2_mode, nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8,mh_recover);
+estimation(order=1, datafile='../fsdat_simul',mode_compute=0,mode_file='fs2000_recover_2/Output/fs2000_recover_2_mode', nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8,mh_recover);
 
 %check first unaffected chain
 temp1=load([M_.dname '_mh1_blck1.mat']);
diff --git a/tests/estimation/MH_recover/fs2000_recover_3.mod b/tests/estimation/MH_recover/fs2000_recover_3.mod
index ac01b4bb2b..ecf0592d47 100644
--- a/tests/estimation/MH_recover/fs2000_recover_3.mod
+++ b/tests/estimation/MH_recover/fs2000_recover_3.mod
@@ -5,14 +5,14 @@
 
 options_.MaxNumberOfBytes=2000*11*8/4;
 estimation(order=1, datafile='../fsdat_simul',nobs=192, loglinear, mh_replic=1000, mh_nblocks=2, mh_jscale=0.8);
-estimation(order=1,mode_compute=0,mode_file=fs2000_recover_3_mode, datafile='../fsdat_simul',nobs=192, loglinear, load_mh_file,mh_replic=1000, mh_nblocks=2, mh_jscale=0.8);
+estimation(order=1,mode_compute=0,mode_file='fs2000_recover_3/Output/fs2000_recover_3_mode', datafile='../fsdat_simul',nobs=192, loglinear, load_mh_file,mh_replic=1000, mh_nblocks=2, mh_jscale=0.8);
 copyfile([M_.dname filesep 'metropolis' filesep M_.dname '_mh1_blck1.mat'],[M_.dname '_mh1_blck1.mat'])
 copyfile([M_.dname filesep 'metropolis' filesep M_.dname '_mh3_blck2.mat'],[M_.dname '_mh3_blck2.mat'])
 copyfile([M_.dname filesep 'metropolis' filesep M_.dname '_mh4_blck2.mat'],[M_.dname '_mh4_blck2.mat'])
 delete([M_.dname filesep 'metropolis' filesep M_.dname '_mh3_blck2.mat'])
 delete([M_.dname filesep 'metropolis' filesep M_.dname '_mh4_blck2.mat'])
 
-estimation(order=1, datafile='../fsdat_simul',mode_compute=0,mode_file=fs2000_recover_3_mode, nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8,mh_recover);
+estimation(order=1, datafile='../fsdat_simul',mode_compute=0,mode_file='fs2000_recover_3/Output/fs2000_recover_3_mode', nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8,mh_recover);
 
 %check first unaffected chain
 temp1=load([M_.dname '_mh1_blck1.mat']);
diff --git a/tests/estimation/MH_recover/fs2000_recover_tarb.mod b/tests/estimation/MH_recover/fs2000_recover_tarb.mod
index 4d3d9ee733..ea4cb45200 100644
--- a/tests/estimation/MH_recover/fs2000_recover_tarb.mod
+++ b/tests/estimation/MH_recover/fs2000_recover_tarb.mod
@@ -8,7 +8,7 @@ copyfile([M_.dname filesep 'metropolis' filesep M_.dname '_mh1_blck1.mat'],[M_.d
 copyfile([M_.dname filesep 'metropolis' filesep M_.dname '_mh2_blck2.mat'],[M_.dname '_mh2_blck2.mat'])
 delete([M_.dname filesep 'metropolis' filesep M_.dname '_mh2_blck2.mat'])
 
-estimation(posterior_sampling_method='tailored_random_block_metropolis_hastings',order=1, datafile='../fsdat_simul',mode_compute=0,mode_file=fs2000_recover_mode, nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8,mh_recover);
+estimation(posterior_sampling_method='tailored_random_block_metropolis_hastings',order=1, datafile='../fsdat_simul',mode_compute=0,mode_file='fs2000_recover/Output/fs2000_recover_mode', nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8,mh_recover);
 
 %check first unaffected chain
 temp1=load([M_.dname '_mh1_blck1.mat']);
diff --git a/tests/estimation/fs2000.mod b/tests/estimation/fs2000.mod
index 4ab6d4ad68..f12c8d9b03 100644
--- a/tests/estimation/fs2000.mod
+++ b/tests/estimation/fs2000.mod
@@ -104,11 +104,11 @@ options_.smoother=0;
 options_.moments_varendo=0;
 options_.forecast=0;   
 copyfile([M_.dname filesep 'metropolis' filesep M_.dname '_mh1_blck1.mat'],[M_.dname '_mh1_blck1.mat'])
-estimation(mode_compute=0,mode_file=fs2000_mode,order=1, datafile=fsdat_simul, nobs=192, loglinear, mh_replic=1500, mh_nblocks=1, mh_jscale=0.8);
+estimation(mode_compute=0,mode_file='fs2000/Output/fs2000_mode',order=1, datafile=fsdat_simul, nobs=192, loglinear, mh_replic=1500, mh_nblocks=1, mh_jscale=0.8);
 hh=eye(size(bayestopt_.name,1));
-save('fs2000_mode.mat','hh','-append')
+save('fs2000/Output/fs2000_mode.mat','hh','-append')
 Laplace = oo_.MarginalDensity.LaplaceApproximation; %save Laplace approximation which will be overwritten with set hh otherwise
-estimation(mode_compute=0,mode_file=fs2000_mode,order=1, datafile=fsdat_simul, nobs=192, loglinear, mh_replic=1500, mh_nblocks=1, mh_jscale=10,load_mh_file);
+estimation(mode_compute=0,mode_file='fs2000/Output/fs2000_mode',order=1, datafile=fsdat_simul, nobs=192, loglinear, mh_replic=1500, mh_nblocks=1, mh_jscale=10,load_mh_file);
 
 temp1=load([M_.dname '_mh1_blck1.mat']);
 temp2=load([M_.dname filesep 'metropolis' filesep M_.dname '_mh1_blck1.mat']);
@@ -121,7 +121,7 @@ end
         
 save('fs2000_result.mat','oo_')        
 options_.load_results_after_load_mh=1;
-estimation(mode_compute=0,mode_file=fs2000_mode,order=1, datafile=fsdat_simul, nobs=192, loglinear, mh_replic=0, mh_nblocks=1, mh_jscale=10,load_mh_file,smoother) gy_obs gp_obs;
+estimation(mode_compute=0,mode_file='fs2000/Output/fs2000_mode',order=1, datafile=fsdat_simul, nobs=192, loglinear, mh_replic=0, mh_nblocks=1, mh_jscale=10,load_mh_file,smoother) gy_obs gp_obs;
 oo_.MarginalDensity.LaplaceApproximation = Laplace; %reset correct Laplace
 
 
diff --git a/tests/estimation/fs2000_MCMC_jumping_covariance.mod b/tests/estimation/fs2000_MCMC_jumping_covariance.mod
index 91a6f20d86..423ac91f97 100644
--- a/tests/estimation/fs2000_MCMC_jumping_covariance.mod
+++ b/tests/estimation/fs2000_MCMC_jumping_covariance.mod
@@ -84,9 +84,9 @@ options_.mode_compute=4;
 options_.plot_priors=0;
 estimation(order=1,datafile=fsdat_simul,nobs=192,loglinear,mh_replic=1000,mh_nblocks=1,mh_jscale=0.8,mcmc_jumping_covariance=hessian);
 
-load fs2000_MCMC_jumping_covariance_mode hh;
+load('fs2000_MCMC_jumping_covariance/Output/fs2000_MCMC_jumping_covariance_mode','hh');
 jumping_covariance=diag(diag(hh));
-save test_matrix.mat jumping_covariance;
+save('test_matrix.mat','jumping_covariance');
 
 estimation(order=1,datafile=fsdat_simul,nobs=192,loglinear,mh_replic=1000,mh_nblocks=1,mh_jscale=0.01,mcmc_jumping_covariance=prior_variance);
 estimation(order=1,datafile=fsdat_simul,nobs=192,loglinear,mh_replic=1000,mh_nblocks=1,mh_jscale=0.0001,mcmc_jumping_covariance=identity_matrix);
diff --git a/tests/estimation/heteroskedastic_shocks/fs2000_het.mod b/tests/estimation/heteroskedastic_shocks/fs2000_het.mod
index 2aa16d5055..a0974c92c8 100644
--- a/tests/estimation/heteroskedastic_shocks/fs2000_het.mod
+++ b/tests/estimation/heteroskedastic_shocks/fs2000_het.mod
@@ -29,5 +29,5 @@ end;
 
 estimation(order=1,datafile='../fsdat_simul',nobs=192,mode_compute=5,loglinear,mh_replic=0,smoother,filtered_vars,forecast=8,filter_step_ahead=[1:8],consider_all_endogenous,heteroskedastic_filter);
 
-@#define mode_file_name="fs2000_het_mode"
+@#define mode_file_name="'fs2000_het/Output/fs2000_het_mode'"
 @#include "fs2000_het_check.inc"
diff --git a/tests/estimation/heteroskedastic_shocks/fs2000_het_corr.mod b/tests/estimation/heteroskedastic_shocks/fs2000_het_corr.mod
index f0887ea708..dae222e46a 100644
--- a/tests/estimation/heteroskedastic_shocks/fs2000_het_corr.mod
+++ b/tests/estimation/heteroskedastic_shocks/fs2000_het_corr.mod
@@ -33,5 +33,5 @@ end;
 
 estimation(order=1,datafile='../fsdat_simul',nobs=192,mode_compute=5,loglinear,mh_replic=0,smoother,filtered_vars,forecast=8,filter_step_ahead=[1:8],consider_all_endogenous,heteroskedastic_filter);
 
-@#define mode_file_name="fs2000_het_corr_mode"
+@#define mode_file_name="'fs2000_het_corr/Output/fs2000_het_corr_mode'"
 @#include "fs2000_het_check.inc" 
diff --git a/tests/example1_use_dll.mod b/tests/example1_use_dll.mod
index 66bbe7c5c8..8c5b200d6d 100644
--- a/tests/example1_use_dll.mod
+++ b/tests/example1_use_dll.mod
@@ -44,11 +44,11 @@ end;
 
 stoch_simul(nograph);
 
-if ~exist('example1_results.mat','file');
+if ~exist(['example1' filesep 'Output' filesep 'example1_results.mat'],'file');
    error('example1 must be run first');
 end;
 
-oo1 = load('example1_results','oo_');
+oo1 = load(['example1' filesep 'Output' filesep 'example1_results'],'oo_');
 
 dr0 = oo1.oo_.dr;
 dr = oo_.dr;
diff --git a/tests/example2long.mod b/tests/example2long.mod
index bdaec0050b..f68bd608a5 100644
--- a/tests/example2long.mod
+++ b/tests/example2long.mod
@@ -51,11 +51,11 @@ end;
 
 stoch_simul;
 
-if ~exist('example1long_results.mat','file');
+if ~exist(['example1long' filesep 'Output' filesep 'example1long_results.mat'],'file');
    error('example1long must be run first');
 end;
 
-oo1 = load('example1long_results','oo_');
+oo1 = load(['example1long' filesep 'Output' filesep 'example1long_results'],'oo_');
 
 dr0 = oo1.oo_.dr;
 dr = oo_.dr;
diff --git a/tests/example2long_use_dll.mod b/tests/example2long_use_dll.mod
index b0a28fa011..0dab99e81d 100644
--- a/tests/example2long_use_dll.mod
+++ b/tests/example2long_use_dll.mod
@@ -51,11 +51,12 @@ end;
 
 stoch_simul;
 
-if ~exist('example1long_results.mat','file');
+if ~exist(['example1long' filesep 'Output' filesep 'example1long_results.mat'],'file');
    error('example1long must be run first');
 end;
 
-oo1 = load('example1long_results','oo_');
+oo1 = load(['example1long' filesep 'Output' filesep 'example1long_results'],'oo_');
+
 
 dr0 = oo1.oo_.dr;
 dr = oo_.dr;
diff --git a/tests/external_function/extfun_in_mlv.mod b/tests/external_function/extfun_in_mlv.mod
index 1b2947cff5..bed024d0f6 100644
--- a/tests/external_function/extfun_in_mlv.mod
+++ b/tests/external_function/extfun_in_mlv.mod
@@ -46,7 +46,7 @@ end;
 
 stoch_simul;
 
-L = load('benchmark_results.mat');
+L = load(['benchmark' filesep 'Output' filesep 'benchmark_results.mat']);
 if max(max(abs(L.oo_.dr.ghu - oo_.dr.ghu))) > 1e-12
   error('Failure in external function')
 end
diff --git a/tests/external_function/first_and_2nd_deriv_given.mod b/tests/external_function/first_and_2nd_deriv_given.mod
index f621104428..d4395ae538 100644
--- a/tests/external_function/first_and_2nd_deriv_given.mod
+++ b/tests/external_function/first_and_2nd_deriv_given.mod
@@ -45,7 +45,7 @@ end;
 
 stoch_simul;
 
-L = load('benchmark_results.mat');
+L = load(['benchmark' filesep 'Output' filesep 'benchmark_results.mat']);
 if max(max(abs(L.oo_.dr.ghu - oo_.dr.ghu))) > 1e-12
   error('Failure in external function')
 end
diff --git a/tests/external_function/first_and_2nd_deriv_given_dll.mod b/tests/external_function/first_and_2nd_deriv_given_dll.mod
index ac42623c6f..328b2e6928 100644
--- a/tests/external_function/first_and_2nd_deriv_given_dll.mod
+++ b/tests/external_function/first_and_2nd_deriv_given_dll.mod
@@ -45,7 +45,7 @@ end;
 
 stoch_simul;
 
-L = load('benchmark_results.mat');
+L = load(['benchmark' filesep 'Output' filesep 'benchmark_results.mat']);
 if max(max(abs(L.oo_.dr.ghu - oo_.dr.ghu))) > 1e-12
   error('Failure in external function')
 end
diff --git a/tests/external_function/first_and_2nd_deriv_given_dll_namespace.mod b/tests/external_function/first_and_2nd_deriv_given_dll_namespace.mod
index ca55aea5a9..5af21e14da 100644
--- a/tests/external_function/first_and_2nd_deriv_given_dll_namespace.mod
+++ b/tests/external_function/first_and_2nd_deriv_given_dll_namespace.mod
@@ -47,7 +47,7 @@ end;
 
 stoch_simul;
 
-L = load('benchmark_results.mat');
+L = load(['benchmark' filesep 'Output' filesep 'benchmark_results.mat']);
 if max(max(abs(L.oo_.dr.ghu - oo_.dr.ghu))) > 1e-12
   error('Failure in external function')
 end
diff --git a/tests/external_function/first_and_2nd_deriv_given_namespace.mod b/tests/external_function/first_and_2nd_deriv_given_namespace.mod
index 3729a17d66..cc42dc296f 100644
--- a/tests/external_function/first_and_2nd_deriv_given_namespace.mod
+++ b/tests/external_function/first_and_2nd_deriv_given_namespace.mod
@@ -47,7 +47,7 @@ end;
 
 stoch_simul;
 
-L = load('benchmark_results.mat');
+L = load(['benchmark' filesep 'Output' filesep 'benchmark_results.mat']);
 if max(max(abs(L.oo_.dr.ghu - oo_.dr.ghu))) > 1e-12
   error('Failure in external function')
 end
diff --git a/tests/external_function/first_deriv_given.mod b/tests/external_function/first_deriv_given.mod
index ef7ba0ab4f..4262a29a1a 100644
--- a/tests/external_function/first_deriv_given.mod
+++ b/tests/external_function/first_deriv_given.mod
@@ -45,7 +45,7 @@ end;
 
 stoch_simul;
 
-L = load('benchmark_results.mat');
+L = load(['benchmark' filesep 'Output' filesep 'benchmark_results.mat']);
 if max(max(abs(L.oo_.dr.ghu - oo_.dr.ghu))) > 1e-12
   error('Failure in external function')
 end
diff --git a/tests/external_function/first_deriv_given_dll.mod b/tests/external_function/first_deriv_given_dll.mod
index cfaf4ae519..6f4934369c 100644
--- a/tests/external_function/first_deriv_given_dll.mod
+++ b/tests/external_function/first_deriv_given_dll.mod
@@ -45,7 +45,7 @@ end;
 
 stoch_simul;
 
-L = load('benchmark_results.mat');
+L = load(['benchmark' filesep 'Output' filesep 'benchmark_results.mat']);
 if max(max(abs(L.oo_.dr.ghu - oo_.dr.ghu))) > 1e-12
   error('Failure in external function')
 end
diff --git a/tests/external_function/no_deriv_given.mod b/tests/external_function/no_deriv_given.mod
index c75cd10c15..44652a504c 100644
--- a/tests/external_function/no_deriv_given.mod
+++ b/tests/external_function/no_deriv_given.mod
@@ -45,7 +45,7 @@ end;
 
 stoch_simul;
 
-L = load('benchmark_results.mat');
+L = load(['benchmark' filesep 'Output' filesep 'benchmark_results.mat']);
 if max(max(abs(L.oo_.dr.ghu - oo_.dr.ghu))) > 1e-9
   error('Failure in external function')
 end
diff --git a/tests/external_function/no_deriv_given_dll.mod b/tests/external_function/no_deriv_given_dll.mod
index 2074168472..5ad3bcc2ea 100644
--- a/tests/external_function/no_deriv_given_dll.mod
+++ b/tests/external_function/no_deriv_given_dll.mod
@@ -45,7 +45,7 @@ end;
 
 stoch_simul;
 
-L = load('benchmark_results.mat');
+L = load(['benchmark' filesep 'Output' filesep 'benchmark_results.mat']);
 if max(max(abs(L.oo_.dr.ghu - oo_.dr.ghu))) > 1e-9
   error('Failure in external function')
 end
diff --git a/tests/gsa/ls2003.mod b/tests/gsa/ls2003.mod
index 3c1b3c9100..d4a56b4d5e 100644
--- a/tests/gsa/ls2003.mod
+++ b/tests/gsa/ls2003.mod
@@ -152,7 +152,7 @@ estimation(datafile='data_ca1.m',first_obs=8,nobs=79,mh_nblocks=1,
 
 // run this to produce posterior samples of filtered, smoothed and irf variables, if not yet done
 //estimation(datafile='data_ca1.m',first_obs=8,nobs=79,mh_nblocks=2,prefilter=1,mh_jscale=0.3,
-//          mh_replic=0, mode_file=ls2003_mode, mode_compute=0, load_mh_file, bayesian_irf,
+//          mh_replic=0, mode_file='ls2003/Output/ls2003_mode', mode_compute=0, load_mh_file, bayesian_irf,
 //		  filtered_vars, smoother, mh_drop=0.6);
 
 disp(' ');
@@ -163,7 +163,7 @@ disp(' ');
 disp('Press ENTER to continue'); pause(5);
 
 dynare_sensitivity(nodisplay, pprior=0,Nsam=512,neighborhood_width=0.2,
-mode_file=ls2003_mode,  // specifies the mode file where the mode and Hessian are stored
+mode_file='ls2003/Output/ls2003_mode',  // specifies the mode file where the mode and Hessian are stored
 datafile='data_ca1.m',first_obs=8,nobs=79,prefilter=1,
 rmse=1);
 
@@ -174,7 +174,7 @@ disp(' ');
 disp('Press ENTER to continue'); pause(5);
 
 dynare_sensitivity(nodisplay, pprior=0,Nsam=512,
-mode_file=ls2003_mode  // specifies the mode file where the mode and Hessian are stored
+mode_file='ls2003/Output/ls2003_mode'  // specifies the mode file where the mode and Hessian are stored
 );
 
 
@@ -182,7 +182,7 @@ disp(' ');
 disp('RMSE ANALYSIS FOR MULTIVARIATE SAMPLE AT THE POSTERIOR MODE');
 disp(' ');
 disp('Press ENTER to continue'); pause(5);
-dynare_sensitivity(nodisplay, mode_file=ls2003_mode,
+dynare_sensitivity(nodisplay, mode_file='ls2003/Output/ls2003_mode',
 datafile='data_ca1.m',first_obs=8,nobs=79,prefilter=1,
 pprior=0,
 stab=0,
@@ -200,7 +200,7 @@ disp('datafile=data_ca1.m,first_obs=8,nobs=79,prefilter=1,')
 disp('rmse=1, alpha2_rmse=0, alpha_rmse=0);')
 disp(' ');
 disp('Press ENTER to continue'); pause(5);
-//dynare_sensitivity(pprior=0,Nsam=2048,alpha2_stab=0.4,mode_file=ls2003_mode,
+//dynare_sensitivity(pprior=0,Nsam=2048,alpha2_stab=0.4,mode_file='ls2003/Output/ls2003_mode',
 //datafile='data_ca1.m',first_obs=8,nobs=79,prefilter=1,
 //rmse=1,
 //alpha2_rmse=0, // no correlation analysis
@@ -211,7 +211,7 @@ disp(' ');
 disp('RMSE ANALYSIS FOR POSTERIOR MCMC sample (ppost=1)');
 disp('Needs a call to dynare_estimation to load all MH environment');
 disp('Press ENTER to continue'); pause(5);
-//estimation(datafile='data_ca1.m',first_obs=8,nobs=79,mh_nblocks=2, mode_file=ls2003_mode, load_mh_file,
+//estimation(datafile='data_ca1.m',first_obs=8,nobs=79,mh_nblocks=2, mode_file='ls2003/Output/ls2003_mode', load_mh_file,
 //  prefilter=1,mh_jscale=0.5,mh_replic=0, mode_compute=0, mh_drop=0.6);
 
 dynare_sensitivity(nodisplay, stab=0, // no need for stability analysis since the posterior sample is surely OK
diff --git a/tests/histval_initval_file/sim_exo_lead_lag_initvalf.mod b/tests/histval_initval_file/sim_exo_lead_lag_initvalf.mod
index 43e129e3e4..ec6f47bb26 100644
--- a/tests/histval_initval_file/sim_exo_lead_lag_initvalf.mod
+++ b/tests/histval_initval_file/sim_exo_lead_lag_initvalf.mod
@@ -38,7 +38,7 @@ if ~oo_.deterministic_simulation.status
    error('Perfect foresight simulation failed');
 end
 
-base_results=load('sim_exo_lead_lag_results.mat');
+base_results=load(['sim_exo_lead_lag' filesep 'Output' filesep 'sim_exo_lead_lag_results.mat']);
 if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8
     error('Simulation with leads and lags doesn''t match the one with auxiliary variables')
 end
@@ -63,7 +63,7 @@ if ~oo_.deterministic_simulation.status
    error('Perfect foresight simulation failed');
 end
 
-base_results=load('sim_exo_lead_lag_results.mat');
+base_results=load(['sim_exo_lead_lag' filesep 'Output' filesep 'sim_exo_lead_lag_results.mat']);
 if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8
     error('Simulation with leads and lags doesn''t match the one with auxiliary variables')
 end
@@ -84,7 +84,7 @@ if ~oo_.deterministic_simulation.status
    error('Perfect foresight simulation failed');
 end
 
-base_results=load('sim_exo_lead_lag_results.mat');
+base_results=load(['sim_exo_lead_lag' filesep 'Output' filesep 'sim_exo_lead_lag_results.mat']);
 if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8
     error('Simulation with leads and lags doesn''t match the one with auxiliary variables')
 end
@@ -105,7 +105,7 @@ if ~oo_.deterministic_simulation.status
    error('Perfect foresight simulation failed');
 end
 
-base_results=load('sim_exo_lead_lag_results.mat');
+base_results=load(['sim_exo_lead_lag' filesep 'Output' filesep 'sim_exo_lead_lag_results.mat']);
 if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8
     error('Simulation with leads and lags doesn''t match the one with auxiliary variables')
 end
@@ -126,7 +126,7 @@ if ~oo_.deterministic_simulation.status
    error('Perfect foresight simulation failed');
 end
 
-base_results=load('sim_exo_lead_lag_results.mat');
+base_results=load(['sim_exo_lead_lag' filesep 'Output' filesep 'sim_exo_lead_lag_results.mat']);
 if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8
     error('Simulation with leads and lags doesn''t match the one with auxiliary variables')
 end
diff --git a/tests/k_order_perturbation/fs2000k2_m.mod b/tests/k_order_perturbation/fs2000k2_m.mod
index b1dd6f80e2..02ca454508 100644
--- a/tests/k_order_perturbation/fs2000k2_m.mod
+++ b/tests/k_order_perturbation/fs2000k2_m.mod
@@ -66,11 +66,11 @@ steady;
 
 stoch_simul(order=2,k_order_solver,periods=1000);
 
-if ~exist('fs2000k2a_results.mat','file');
+if ~exist(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results.mat'],'file');
    error('fs2000k2a must be run first');
 end;
 
-oo1 = load('fs2000k2a_results','oo_');
+oo1 = load(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results'],'oo_');
 
 dr0 = oo1.oo_.dr;
 dr = oo_.dr;
diff --git a/tests/k_order_perturbation/fs2000k2_use_dll.mod b/tests/k_order_perturbation/fs2000k2_use_dll.mod
index 20284beca8..9b5ea9dd95 100644
--- a/tests/k_order_perturbation/fs2000k2_use_dll.mod
+++ b/tests/k_order_perturbation/fs2000k2_use_dll.mod
@@ -66,11 +66,11 @@ steady;
 
 stoch_simul(order=2,k_order_solver,periods=1000);
 
-if ~exist('fs2000k2a_results.mat','file');
+if ~exist(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results.mat'],'file');
    error('fs2000k2a must be run first');
 end;
 
-oo1 = load('fs2000k2a_results','oo_');
+oo1 = load(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results'],'oo_');
 
 dr0 = oo1.oo_.dr;
 dr = oo_.dr;
diff --git a/tests/k_order_perturbation/fs2000k3_m.mod b/tests/k_order_perturbation/fs2000k3_m.mod
index 0e2529763f..fa91efec8d 100644
--- a/tests/k_order_perturbation/fs2000k3_m.mod
+++ b/tests/k_order_perturbation/fs2000k3_m.mod
@@ -66,11 +66,11 @@ steady;
 
 stoch_simul(order=3,periods=1000);
 
-if ~exist('fs2000k2a_results.mat','file');
+if ~exist(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results.mat'],'file');
    error('fs2000k2a must be run first');
 end;
 
-oo1 = load('fs2000k2a_results','oo_');
+oo1 = load(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results'],'oo_');
 
 dr0 = oo1.oo_.dr;
 dr = oo_.dr;
diff --git a/tests/k_order_perturbation/fs2000k3_use_dll.mod b/tests/k_order_perturbation/fs2000k3_use_dll.mod
index 88821218a4..2028443b60 100644
--- a/tests/k_order_perturbation/fs2000k3_use_dll.mod
+++ b/tests/k_order_perturbation/fs2000k3_use_dll.mod
@@ -66,11 +66,11 @@ steady;
 
 stoch_simul(order=3,periods=1000);
 
-if ~exist('fs2000k2a_results.mat','file');
+if ~exist(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results.mat'],'file');
    error('fs2000k2a must be run first');
 end;
 
-oo1 = load('fs2000k2a_results','oo_');
+oo1 = load(['fs2000k2a' filesep 'Output' filesep 'fs2000k2a_results'],'oo_');
 
 dr0 = oo1.oo_.dr;
 dr = oo_.dr;
diff --git a/tests/k_order_perturbation/fs2000k_1_m.mod b/tests/k_order_perturbation/fs2000k_1_m.mod
index 5cd18f42c8..f4bad22ce1 100644
--- a/tests/k_order_perturbation/fs2000k_1_m.mod
+++ b/tests/k_order_perturbation/fs2000k_1_m.mod
@@ -74,11 +74,11 @@ steady;
 
 stoch_simul(order=2,k_order_solver,irf=0);
 
-if ~exist('fs2000k2_m_results.mat','file');
+if ~exist(['fs2000k2_m' filesep 'Output' filesep 'fs2000k2_m_results.mat'],'file');
    error('fs2000k2_m must be run first');
 end;
 
-oo1 = load('fs2000k2_m_results','oo_');
+oo1 = load(['fs2000k2_m' filesep 'Output' filesep 'fs2000k2_m_results'],'oo_');
 
 dr0 = oo1.oo_.dr;
 dr = oo_.dr;
diff --git a/tests/k_order_perturbation/fs2000k_1_use_dll.mod b/tests/k_order_perturbation/fs2000k_1_use_dll.mod
index 4de96ae254..f4eb030081 100644
--- a/tests/k_order_perturbation/fs2000k_1_use_dll.mod
+++ b/tests/k_order_perturbation/fs2000k_1_use_dll.mod
@@ -73,11 +73,11 @@ steady;
 
 stoch_simul(order=2,k_order_solver,irf=0);
 
-if ~exist('fs2000k2_use_dll_results.mat','file');
+if ~exist(['fs2000k2_use_dll' filesep 'Output' filesep 'fs2000k2_use_dll_results.mat'],'file');
    error('fs2000k2_use_dll must be run first');
 end;
 
-oo1 = load('fs2000k2_use_dll_results','oo_');
+oo1 = load(['fs2000k2_use_dll' filesep 'Output' filesep 'fs2000k2_use_dll_results'],'oo_');
 
 dr0 = oo1.oo_.dr;
 dr = oo_.dr;
diff --git a/tests/kalman/likelihood_from_dynare/fs2000_corr_ME.mod b/tests/kalman/likelihood_from_dynare/fs2000_corr_ME.mod
index 17756e640f..25443b5c29 100644
--- a/tests/kalman/likelihood_from_dynare/fs2000_corr_ME.mod
+++ b/tests/kalman/likelihood_from_dynare/fs2000_corr_ME.mod
@@ -12,7 +12,7 @@ stderr gy_obs, 1;
 corr gp_obs, gy_obs,0;
 end;
 
-@#define mode_file_name="fs2000_corr_ME_mode"
+@#define mode_file_name="'fs2000_corr_ME/Output/fs2000_corr_ME_mode'"
 @#define data_file_name="fsdat_simul_corr_ME"
 
 @#include "fs2000_estimation_check.inc" 
\ No newline at end of file
diff --git a/tests/kalman/likelihood_from_dynare/fs2000_corr_ME_missing.mod b/tests/kalman/likelihood_from_dynare/fs2000_corr_ME_missing.mod
index 860d6242b0..7810b432fb 100644
--- a/tests/kalman/likelihood_from_dynare/fs2000_corr_ME_missing.mod
+++ b/tests/kalman/likelihood_from_dynare/fs2000_corr_ME_missing.mod
@@ -12,7 +12,7 @@ stderr gy_obs, 1;
 corr gp_obs, gy_obs,0;
 end;
 
-@#define mode_file_name="fs2000_corr_ME_missing_mode"
+@#define mode_file_name="'fs2000_corr_ME_missing/Output/fs2000_corr_ME_missing_mode'"
 @#define data_file_name="fsdat_simul_corr_ME_missing"
 
 @#include "fs2000_estimation_check.inc" 
\ No newline at end of file
diff --git a/tests/kalman/likelihood_from_dynare/fs2000_uncorr_ME.mod b/tests/kalman/likelihood_from_dynare/fs2000_uncorr_ME.mod
index 7376f42bb3..95cd231ea4 100644
--- a/tests/kalman/likelihood_from_dynare/fs2000_uncorr_ME.mod
+++ b/tests/kalman/likelihood_from_dynare/fs2000_uncorr_ME.mod
@@ -29,7 +29,7 @@ stderr gy_obs, 1;
 //corr gp_obs, gy_obs,0;
 end;
 
-@#define mode_file_name="fs2000_uncorr_ME_mode"
+@#define mode_file_name="'fs2000_uncorr_ME/Output/fs2000_uncorr_ME_mode'"
 @#define data_file_name="fsdat_simul_uncorr_ME"
 
 @#include "fs2000_estimation_check.inc" 
\ No newline at end of file
diff --git a/tests/kalman/likelihood_from_dynare/fs2000_uncorr_ME_missing.mod b/tests/kalman/likelihood_from_dynare/fs2000_uncorr_ME_missing.mod
index 77cac92692..3dd1c54976 100644
--- a/tests/kalman/likelihood_from_dynare/fs2000_uncorr_ME_missing.mod
+++ b/tests/kalman/likelihood_from_dynare/fs2000_uncorr_ME_missing.mod
@@ -12,7 +12,7 @@ stderr gy_obs, 1;
 //corr gp_obs, gy_obs,0;
 end;
 
-@#define mode_file_name="fs2000_uncorr_ME_missing_mode"
+@#define mode_file_name="'fs2000_uncorr_ME_missing/Output/fs2000_uncorr_ME_missing_mode'"
 @#define data_file_name="fsdat_simul_uncorr_ME_missing"
 
 @#include "fs2000_estimation_check.inc" 
diff --git a/tests/kalman/likelihood_from_dynare/fs2000ns_corr_ME.mod b/tests/kalman/likelihood_from_dynare/fs2000ns_corr_ME.mod
index edeaa1743f..2f9de9afd8 100644
--- a/tests/kalman/likelihood_from_dynare/fs2000ns_corr_ME.mod
+++ b/tests/kalman/likelihood_from_dynare/fs2000ns_corr_ME.mod
@@ -12,7 +12,7 @@ stderr Y_obs, 0.05;
 corr Y_obs, P_obs,0.5;
 end;
 
-@#define mode_file_name="fs2000ns_corr_ME_mode"
+@#define mode_file_name="'fs2000ns_corr_ME/Output/fs2000ns_corr_ME_mode'"
 @#define data_file_name="fs_ns_dat_simul_corr_ME"
 
 @#include "fs2000ns_estimation_check.inc" 
diff --git a/tests/kalman/likelihood_from_dynare/fs2000ns_corr_ME_missing.mod b/tests/kalman/likelihood_from_dynare/fs2000ns_corr_ME_missing.mod
index 41741474cd..da8317d5ce 100644
--- a/tests/kalman/likelihood_from_dynare/fs2000ns_corr_ME_missing.mod
+++ b/tests/kalman/likelihood_from_dynare/fs2000ns_corr_ME_missing.mod
@@ -12,7 +12,7 @@ stderr Y_obs, 0.05;
 corr Y_obs, P_obs,0.5;
 end;
 
-@#define mode_file_name="fs2000ns_corr_ME_missing_mode"
+@#define mode_file_name="'fs2000ns_corr_ME_missing/Output/fs2000ns_corr_ME_missing_mode'"
 @#define data_file_name="fs_ns_dat_simul_corr_ME_missing"
 
 @#include "fs2000ns_estimation_check.inc" 
diff --git a/tests/kalman/likelihood_from_dynare/fs2000ns_uncorr_ME.mod b/tests/kalman/likelihood_from_dynare/fs2000ns_uncorr_ME.mod
index 61072d20f5..0e6ba9443a 100644
--- a/tests/kalman/likelihood_from_dynare/fs2000ns_uncorr_ME.mod
+++ b/tests/kalman/likelihood_from_dynare/fs2000ns_uncorr_ME.mod
@@ -36,7 +36,7 @@ stderr Y_obs, 0.05;
 //corr gp_obs, gy_obs,0;
 end;
 
-@#define mode_file_name="fs2000ns_uncorr_ME_mode"
+@#define mode_file_name="'fs2000ns_uncorr_ME/Output/fs2000ns_uncorr_ME_mode'"
 @#define data_file_name="fs_ns_dat_simul_uncorr_ME"
 
 @#include "fs2000ns_estimation_check.inc" 
diff --git a/tests/kalman/likelihood_from_dynare/fs2000ns_uncorr_ME_missing.mod b/tests/kalman/likelihood_from_dynare/fs2000ns_uncorr_ME_missing.mod
index 2d0550e501..fcf83f8aa1 100644
--- a/tests/kalman/likelihood_from_dynare/fs2000ns_uncorr_ME_missing.mod
+++ b/tests/kalman/likelihood_from_dynare/fs2000ns_uncorr_ME_missing.mod
@@ -12,7 +12,7 @@ stderr Y_obs, 0.05;
 //corr gp_obs, gy_obs,0;
 end;
 
-@#define mode_file_name="fs2000ns_uncorr_ME_missing_mode"
+@#define mode_file_name="'fs2000ns_uncorr_ME_missing/Output/fs2000ns_uncorr_ME_missing_mode'"
 @#define data_file_name="fs_ns_dat_simul_uncorr_ME_missing"
 
 @#include "fs2000ns_estimation_check.inc" 
diff --git a/tests/kalman_filter_smoother/algo2.mod b/tests/kalman_filter_smoother/algo2.mod
index 89bca77504..b18eeb42a1 100644
--- a/tests/kalman_filter_smoother/algo2.mod
+++ b/tests/kalman_filter_smoother/algo2.mod
@@ -32,7 +32,7 @@ end;
 
 varobs dw dx dy z;
 
-estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file=algo1_mode,kalman_algo=2,filtered_vars,smoothed_state_uncertainty);
+estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file='algo1/Output/algo1_mode',kalman_algo=2,filtered_vars,smoothed_state_uncertainty);
 
 //checking smoother consistency
 X = oo_.SmoothedVariables;
@@ -55,7 +55,7 @@ if max(max(abs(dat(1000:1199,:)-S(:,[2:4 1])))) > 1e-10;
    error('Test fails');
 end;
 
-o1 = load('algo1_results');
+o1 = load(['algo1' filesep 'Output' filesep 'algo1_results.mat']);
 obj_endo={'SmoothedVariables'; 'FilteredVariables'; 'UpdatedVariables'};
 obj_exo = {'SmoothedShocks';}; 
 nobj_endo = size(obj_endo,1);
diff --git a/tests/kalman_filter_smoother/algo4.mod b/tests/kalman_filter_smoother/algo4.mod
index 1d07bc93c8..7d26340ce7 100644
--- a/tests/kalman_filter_smoother/algo4.mod
+++ b/tests/kalman_filter_smoother/algo4.mod
@@ -35,7 +35,7 @@ end;
 
 varobs w x y;
 
-estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file=algo3_mode,diffuse_filter,kalman_algo=4,filtered_vars,smoothed_state_uncertainty);
+estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file='algo3/Output/algo3_mode',diffuse_filter,kalman_algo=4,filtered_vars,smoothed_state_uncertainty);
 
 //checking smoother consistency
 X = oo_.SmoothedVariables;
@@ -58,7 +58,7 @@ if max(max(abs(dat(1000:1199,:)-S(:,[7:9])))) > 1e-10;
    error('Test fails');
 end;
 
-o1 = load('algo3_results');
+o1 = load(['algo3' filesep 'Output' filesep 'algo3_results.mat']);
 obj_endo={'SmoothedVariables'; 'FilteredVariables'; 'UpdatedVariables'};
 obj_exo = {'SmoothedShocks';}; 
 nobj_endo = size(obj_endo,1);
diff --git a/tests/kalman_filter_smoother/algo4a.mod b/tests/kalman_filter_smoother/algo4a.mod
index 9ca4675018..28c8b65114 100644
--- a/tests/kalman_filter_smoother/algo4a.mod
+++ b/tests/kalman_filter_smoother/algo4a.mod
@@ -34,7 +34,7 @@ end;
 varobs dw dx y z;
        
 estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,diffuse_filter);
-//estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file=algo3_mode,diffuse_filter);
+//estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file='algo3/Output/algo3_mode',diffuse_filter);
 
 //checking smoother consistency
 X = oo_.SmoothedVariables;
diff --git a/tests/kalman_filter_smoother/algo4b.mod b/tests/kalman_filter_smoother/algo4b.mod
index 37d743bbb7..0e6c6da925 100644
--- a/tests/kalman_filter_smoother/algo4b.mod
+++ b/tests/kalman_filter_smoother/algo4b.mod
@@ -34,7 +34,7 @@ end;
 varobs dw dx y z;
        
 estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,diffuse_filter,smoothed_state_uncertainty);
-//estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file=algo3_mode,diffuse_filter);
+//estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file='algo3/Output/algo3_mode',diffuse_filter);
 
 //checking smoother consistency
 X = oo_.SmoothedVariables;
diff --git a/tests/kalman_filter_smoother/algoH2.mod b/tests/kalman_filter_smoother/algoH2.mod
index b6d5f2b4b9..39f750995b 100644
--- a/tests/kalman_filter_smoother/algoH2.mod
+++ b/tests/kalman_filter_smoother/algoH2.mod
@@ -35,7 +35,7 @@ end;
 varobs dw dx dy z;
        
 //estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,kalman_algo=2);
-estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file=algoH1_mode,kalman_algo=2,filtered_vars,smoothed_state_uncertainty);
+estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file='algoH1/Output/algoH1_mode',kalman_algo=2,filtered_vars,smoothed_state_uncertainty);
 
 //checking smoother consistency
 X = oo_.SmoothedVariables;
@@ -60,7 +60,7 @@ if max(max(abs(dat(1000:1199,:)-S(:,[2:4 1])-ME))) > 1e-10;
    error('Test fails');
 end;    
 
-o1 = load('algoH1_results');
+o1 = load(['algoH1' filesep 'Output' filesep 'algoH1_results.mat']);
 obj_endo={'SmoothedVariables'; 'FilteredVariables'; 'UpdatedVariables'};
 obj_exo = {'SmoothedShocks';}; 
 nobj_endo = size(obj_endo,1);
diff --git a/tests/lmmcp/sw_newton.mod b/tests/lmmcp/sw_newton.mod
index f40297e0f7..bab473d026 100644
--- a/tests/lmmcp/sw_newton.mod
+++ b/tests/lmmcp/sw_newton.mod
@@ -71,7 +71,7 @@ simul(periods=1000);
 
 newton_solution_is_wrong = abs(evaluate_max_dynamic_residual(str2func('sw_newton.dynamic'), oo_.endo_simul, oo_.exo_simul, M_.params, oo_.steady_state, 1000, size(oo_.endo_simul, 1), 1, M_.lead_lag_incidence))>options_.dynatol.f;
 
-lmmcp = load('sw_lmmcp_results');
+lmmcp = load(['sw_lmmcp' filesep 'Output' filesep 'sw_lmmcp_results']);
 
 lmmcp_solution_is_wrong = abs(evaluate_max_dynamic_residual(str2func('sw_newton.dynamic'), lmmcp.oo_.endo_simul, lmmcp.oo_.exo_simul, M_.params, oo_.steady_state, 1000, size(oo_.endo_simul, 1), 1, M_.lead_lag_incidence))>options_.dynatol.f;
 
diff --git a/tests/loglinear/example4_loglinear_lagged_exogenous_a.mod b/tests/loglinear/example4_loglinear_lagged_exogenous_a.mod
index cf93edac98..5d843aabbe 100644
--- a/tests/loglinear/example4_loglinear_lagged_exogenous_a.mod
+++ b/tests/loglinear/example4_loglinear_lagged_exogenous_a.mod
@@ -69,7 +69,7 @@ end;
 
 stoch_simul(loglinear,order=1);
 
-D = load('example4_loglinear_lagged_exogenous_results');
+D = load(['example4_loglinear_lagged_exogenous' filesep 'Output' filesep 'example4_loglinear_lagged_exogenous_results']);
 
 test1 = D.oo_.dr.ghx - oo_.dr.ghx;
 if norm(test1) > 1e-16;
diff --git a/tests/occbin/model_borrcon/borrcon_0_std_shocks.mod b/tests/occbin/model_borrcon/borrcon_0_std_shocks.mod
index 2943458db0..c43a0a2169 100644
--- a/tests/occbin/model_borrcon/borrcon_0_std_shocks.mod
+++ b/tests/occbin/model_borrcon/borrcon_0_std_shocks.mod
@@ -53,7 +53,7 @@ end;
 
 @#include "borrcon_common.inc"
 
-orig_results=load('borrcon_results.mat');
+orig_results=load(['borrcon' filesep 'Output' filesep 'borrcon_results.mat']);
 if max(max(abs(oo_.occbin.piecewise-orig_results.oo_.occbin.piecewise)))>1e-10
     error('Results do not match')
 end
diff --git a/tests/occbin/model_irrcap_twoconstraints/dynrbc_0_std_shocks.mod b/tests/occbin/model_irrcap_twoconstraints/dynrbc_0_std_shocks.mod
index 1c0579d5ad..f7c09446db 100644
--- a/tests/occbin/model_irrcap_twoconstraints/dynrbc_0_std_shocks.mod
+++ b/tests/occbin/model_irrcap_twoconstraints/dynrbc_0_std_shocks.mod
@@ -59,7 +59,7 @@ end;
 
 @#include "dynrbc_common.inc"
 
-orig_results=load('dynrbc_results.mat');
+orig_results=load(['dynrbc' filesep 'Output' filesep 'dynrbc_results.mat']);
 if max(max(abs(oo_.occbin.piecewise-orig_results.oo_.occbin.piecewise)))>1e-10
     error('Results do not match')
 end
diff --git a/tests/optimal_policy/neo_growth_ramsey.mod b/tests/optimal_policy/neo_growth_ramsey.mod
index 2c8ea07dc9..8185ca2f44 100644
--- a/tests/optimal_policy/neo_growth_ramsey.mod
+++ b/tests/optimal_policy/neo_growth_ramsey.mod
@@ -33,13 +33,13 @@ stoch_simul(order=2, irf=0);
 
 planner_objective_value = evaluate_planner_objective(M_, options_, oo_);
 
-if ~exist('neo_growth_results.mat','file');
+if ~exist(['neo_growth' filesep 'Output' filesep 'neo_growth_results.mat'],'file');
    error('neo_growth must be run first');
 end;
 
-oo1 = load('neo_growth_results','oo_');
-M1 = load('neo_growth_results','M_');
-options1 = load('neo_growth_results','options_');
+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'));
 
 initial_condition_states = repmat(oo1.oo_.dr.ys,1,M1.M_.maximum_lag);
diff --git a/tests/optimal_policy/neo_growth_ramsey_foresight.mod b/tests/optimal_policy/neo_growth_ramsey_foresight.mod
index 57c34056b3..b4175f58f4 100644
--- a/tests/optimal_policy/neo_growth_ramsey_foresight.mod
+++ b/tests/optimal_policy/neo_growth_ramsey_foresight.mod
@@ -39,9 +39,9 @@ if ~exist('neo_growth_foresight_results.mat','file');
    error('neo_growth_foresight must be run first');
 end;
 
-oo1 = load('neo_growth_foresight_results','oo_');
-M1 = load('neo_growth_foresight_results','M_');
-options1 = load('neo_growth_foresight_results','options_');
+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_');
 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);
 
diff --git a/tests/optimal_policy/neo_growth_ramsey_k_order.mod b/tests/optimal_policy/neo_growth_ramsey_k_order.mod
index 658ed71517..02a82d48b7 100644
--- a/tests/optimal_policy/neo_growth_ramsey_k_order.mod
+++ b/tests/optimal_policy/neo_growth_ramsey_k_order.mod
@@ -38,13 +38,13 @@ evaluate_planner_objective;
 if condWelfare~=oo_.planner_objective_value(1)
     error('Values do not match');
 end
-if ~exist('neo_growth_k_order_results.mat','file');
+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;
 
-oo = load('neo_growth_k_order_results','oo_');
-M = load('neo_growth_k_order_results','M_');
-options = load('neo_growth_k_order_results','options_');
+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_');
 
 ind_U = strmatch('U', M.M_.endo_names,'exact');
 ind_W = strmatch('W', M.M_.endo_names,'exact');
diff --git a/tests/optimal_policy/nk_ramsey_expectation_a.mod b/tests/optimal_policy/nk_ramsey_expectation_a.mod
index fc79789371..4a0f85aaf2 100644
--- a/tests/optimal_policy/nk_ramsey_expectation_a.mod
+++ b/tests/optimal_policy/nk_ramsey_expectation_a.mod
@@ -93,7 +93,7 @@ ramsey_model(planner_discount=0.99);
 stoch_simul(order=1,irf=0);
 evaluate_planner_objective;
 
-o1=load('nk_ramsey_expectation_results');
+o1=load(['nk_ramsey_expectation' filesep 'Output' filesep 'nk_ramsey_expectation_results']);
 if (norm(o1.oo_.dr.ghx-oo_.dr.ghx,inf) > 1e-12)
    error('ghx doesn''t match')
 end
diff --git a/tests/optimizers/fs2000_102.mod b/tests/optimizers/fs2000_102.mod
index 40646a9c01..f23ae2d774 100644
--- a/tests/optimizers/fs2000_102.mod
+++ b/tests/optimizers/fs2000_102.mod
@@ -1,5 +1,5 @@
 @#include "fs2000.common.inc"
 
 if ~isoctave() && exist('simulannealbnd','file')
-   estimation(mode_compute=102,mode_file='../estimation/fs2000_mode',order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8);
+   estimation(mode_compute=102,mode_file='../estimation/fs2000/Output/fs2000_mode',order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8);
 end
diff --git a/tests/optimizers/fs2000_6.mod b/tests/optimizers/fs2000_6.mod
index 21738c8693..000fa1932c 100644
--- a/tests/optimizers/fs2000_6.mod
+++ b/tests/optimizers/fs2000_6.mod
@@ -3,5 +3,5 @@
 estimation(mode_compute=6,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, optim=('nclimb-mh', 10, 'ncov-mh', 1000, 'nscale-mh', 5000));
 
 // test the mode file generated with mode_compute=6
-estimation(order=1,datafile='../fs2000/fsdat_simul',nobs=192,loglinear,mode_compute=0,mode_file=fs2000_6_mode,mh_replic=10,
-        posterior_sampler_options=('scale_file','fs2000_6_optimal_mh_scale_parameter'));
+estimation(order=1,datafile='../fs2000/fsdat_simul',nobs=192,loglinear,mode_compute=0,mode_file='fs2000_6/Output/fs2000_6_mode',mh_replic=10,
+        posterior_sampler_options=('scale_file','fs2000_6/Output/fs2000_6_optimal_mh_scale_parameter'));
diff --git a/tests/parallel/ls2003.mod b/tests/parallel/ls2003.mod
index 64db3899c6..cf3d8d0769 100644
--- a/tests/parallel/ls2003.mod
+++ b/tests/parallel/ls2003.mod
@@ -66,7 +66,7 @@ end;
 
 
 estimation(datafile=data_ca1,first_obs=8,nobs=79,mh_replic=0,nodisplay);
-estimation(datafile=data_ca1,first_obs=8,nobs=79,mode_compute=0,nodisplay, mode_file=ls2003_mode, mh_nblocks=4, prefilter=1, mh_jscale=0.5, mh_replic=2000);
-estimation(datafile=data_ca1,first_obs=8,nobs=79,mode_compute=0,nodisplay, mode_file=ls2003_mode, mh_nblocks=4,prefilter=1,mh_jscale=0.5,mh_replic=2000,bayesian_irf,load_mh_file,smoother,forecast=12, filtered_vars, filter_step_ahead=[1 2 3 4]) y y_s R pie dq pie_s de A y_obs pie_obs R_obs;
+estimation(datafile=data_ca1,first_obs=8,nobs=79,mode_compute=0,nodisplay, mode_file='ls2003/Output/ls2003_mode', mh_nblocks=4, prefilter=1, mh_jscale=0.5, mh_replic=2000);
+estimation(datafile=data_ca1,first_obs=8,nobs=79,mode_compute=0,nodisplay, mode_file='ls2003/Output/ls2003_mode', mh_nblocks=4,prefilter=1,mh_jscale=0.5,mh_replic=2000,bayesian_irf,load_mh_file,smoother,forecast=12, filtered_vars, filter_step_ahead=[1 2 3 4]) y y_s R pie dq pie_s de A y_obs pie_obs R_obs;
 
 
diff --git a/tests/pruning/AS_pruned_state_space_red_shock.mod b/tests/pruning/AS_pruned_state_space_red_shock.mod
index dfbc3571c8..177688e052 100644
--- a/tests/pruning/AS_pruned_state_space_red_shock.mod
+++ b/tests/pruning/AS_pruned_state_space_red_shock.mod
@@ -144,7 +144,7 @@ for iorder = 1:3
         error('Something wrong with pruned_state_space.m compared to Andreasen et al 2018 Toolbox v2 at order %d.',iorder);
     end
     if iorder==3
-        pruned_without_shock = load('AnSchorfheide_pruned_state_space_results.mat');
+        pruned_without_shock = load(['AnSchorfheide_pruned_state_space' filesep 'Output' filesep 'AnSchorfheide_pruned_state_space_results.mat']);
         pruned_without_shock = pruned_without_shock.oo_.pruned;
         norm_E_yx   = norm(pruned.E_y   - pruned_without_shock.E_y , Inf);
         fprintf('max(sum(abs(E[y;x]''))): %d\n',norm_E_yx);
diff --git a/tests/second_order/ds2.mod b/tests/second_order/ds2.mod
index 66fa7fdb4a..45a92208e6 100644
--- a/tests/second_order/ds2.mod
+++ b/tests/second_order/ds2.mod
@@ -68,7 +68,7 @@ model_diagnostics;
 check;
 stoch_simul(order=2,irf=0);
 
-o1 = load('ds1_results','oo_');
+o1 = load(['ds1' filesep 'Output' filesep 'ds1_results'],'oo_');
 oo1 = o1.oo_.dr;
 oo2 = oo_.dr;
 if any(abs(oo1.ghxx-oo2.ghxx) > 1e-14);error('ds1 with missing variable doesn''t reproduce ds2');end;
diff --git a/tests/smoother2histval/fs2000_simul.mod b/tests/smoother2histval/fs2000_simul.mod
index a682c76c04..9b1b81f1c1 100644
--- a/tests/smoother2histval/fs2000_simul.mod
+++ b/tests/smoother2histval/fs2000_simul.mod
@@ -62,11 +62,11 @@ var e_a; stderr 0.014;
 var e_m; stderr 0.005;
 end;
 
-results_estimation=load('fs2000_smooth_results');
+results_estimation=load(['fs2000_smooth' filesep 'Output' filesep 'fs2000_smooth_results']);
 M_.params=results_estimation.M_.params;
 steady;
 
-OO = load('fs2000_smooth_results.mat');
+OO = load(['fs2000_smooth' filesep 'Output' filesep 'fs2000_smooth_results']);;
 M_.params = OO.M_.params;
 
 histval_file(filename = 'fs2000_histval.mat');
-- 
GitLab