From ddd95361ba66055ec1b72bcf1ab22073e69ec2c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?=
 <stephane.adjemian@univ-lemans.fr>
Date: Mon, 4 Nov 2013 10:54:45 +0100
Subject: [PATCH] Cosmetic changes. Added isoctave function to replace
 exist('OCTAVE_VERSION').
---
 matlab/MakeAllFigures.m                       |  4 +--
 matlab/McMCDiagnostics_core.m                 |  4 +--
 matlab/PosteriorIRF.m                         |  2 +-
 matlab/PosteriorIRF_core1.m                   |  4 +--
 matlab/UnivariateSpectralDensity.m            |  4 +--
 matlab/draw_prior_density.m                   |  6 ++--
 matlab/dyn_saveas.m                           |  6 ++--
 matlab/dyn_waitbar.m                          |  4 +--
 matlab/dyn_waitbar_close.m                    |  2 +-
 matlab/dynare.m                               |  4 +--
 matlab/dynare_config.m                        | 16 +++++-----
 matlab/dynare_estimation_1.m                  | 12 +++----
 matlab/dynare_identification.m                |  8 ++---
 matlab/dynare_sensitivity.m                   |  2 +-
 matlab/dynare_solve.m                         |  4 +--
 matlab/gensylv/sylvester3.m                   |  2 +-
 matlab/get_dynare_random_generator_state.m    |  2 +-
 matlab/global_initialization.m                |  2 +-
 matlab/gsa/filt_mc_.m                         |  2 +-
 matlab/independent_metropolis_hastings_core.m |  8 ++---
 matlab/load_csv_file_data.m                   |  2 +-
 matlab/lyapunov_symm.m                        |  2 +-
 matlab/mode_check.m                           |  2 +-
 matlab/ms-sbvar/dyn_save_graph.m              |  4 +--
 .../ms-sbvar/plot_ms_variance_decomposition.m |  2 +-
 .../AnalyseComputationalEnvironment.m         |  2 +-
 .../InitializeComputationalEnvironment.m      |  6 ++--
 matlab/parallel/dynareParallelDir.m           |  6 ++--
 matlab/parallel/dynareParallelGetFiles.m      |  2 +-
 matlab/parallel/dynareParallelRmDir.m         |  2 +-
 matlab/parallel/dynareParallelSendFiles.m     |  4 +--
 matlab/parallel/masterParallel.m              | 31 +++++++++----------
 matlab/partial_information/PI_gensys.m        |  2 +-
 matlab/plot_icforecast.m                      |  2 +-
 matlab/pm3.m                                  |  2 +-
 matlab/prior_bounds.m                         |  6 ++--
 matlab/qz/mjdgges.m                           |  2 +-
 matlab/random_walk_metropolis_hastings_core.m | 10 +++---
 matlab/reports/@graph/createGraph.m           |  2 +-
 matlab/reports/@report/compile.m              |  4 +--
 matlab/reports/@report/write.m                |  2 +-
 matlab/rplot.m                                |  2 +-
 matlab/set_dynare_random_generator_state.m    |  2 +-
 matlab/set_dynare_seed.m                      |  4 +--
 matlab/simul.m                                |  2 +-
 matlab/solve_one_boundary.m                   |  6 ++--
 matlab/steady_.m                              |  2 +-
 matlab/th_autocovariances.m                   |  4 +--
 matlab/utilities/general/isoctave.m           | 20 ++++++++++++
 matlab/varlist_indices.m                      |  2 +-
 matlab/warning_config.m                       |  2 +-
 matlab/writedata.m                            |  2 +-
 52 files changed, 131 insertions(+), 112 deletions(-)
 create mode 100644 matlab/utilities/general/isoctave.m
diff --git a/matlab/MakeAllFigures.m b/matlab/MakeAllFigures.m
index a89021921..89f35dac6 100644
--- a/matlab/MakeAllFigures.m
+++ b/matlab/MakeAllFigures.m
@@ -153,14 +153,14 @@ if Info.SaveFormat.Eps
         eval(['print -depsc2 ' M_.fname Info.SaveFormat.GenericName Info.SaveFormat.Name '.eps']);  
     end
 end
-if Info.SaveFormat.Pdf && ~exist('OCTAVE_VERSION')
+if Info.SaveFormat.Pdf && ~isoctave
     if isempty(Info.SaveFormat.Name)
         eval(['print -dpdf ' M_.fname Info.SaveFormat.GenericName int2str(Info.SaveFormat.Number)]);
     else
         eval(['print -dpdf ' M_.fname Info.SaveFormat.GenericName Info.SaveFormat.Name]);  
     end
 end
-if Info.SaveFormat.Fig && ~exist('OCTAVE_VERSION')
+if Info.SaveFormat.Fig && ~isoctave
     if isempty(Info.SaveFormat.Name)
         saveas(FigHandle,[M_.fname Info.SaveFormat.GenericName int2str(Info.SaveFormat.Number) '.fig']);
     else
diff --git a/matlab/McMCDiagnostics_core.m b/matlab/McMCDiagnostics_core.m
index 540c322e6..bf014e752 100644
--- a/matlab/McMCDiagnostics_core.m
+++ b/matlab/McMCDiagnostics_core.m
@@ -73,7 +73,7 @@ if whoiam
     fMessageStatus(0,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
 end
 for j=fpar:npar,
-    if exist('OCTAVE_VERSION'),
+    if isoctave
         if (whoiam==0),
             printf('    Parameter %d...  ',j);
         end
@@ -122,7 +122,7 @@ for j=fpar:npar,
             UDIAG(ligne,6,j-fpar+1) = UDIAG(ligne,6,j-fpar+1) + sum(abs(pmet(:,1)-moyenne).^3)/(n-1);
         end
     end
-    if exist('OCTAVE_VERSION'),
+    if isoctave
         if (whoiam==0),
             printf('Done! \n');
         end
diff --git a/matlab/PosteriorIRF.m b/matlab/PosteriorIRF.m
index 42e11640a..d7ce72c29 100644
--- a/matlab/PosteriorIRF.m
+++ b/matlab/PosteriorIRF.m
@@ -444,7 +444,7 @@ end
 
 
 % Comment for testing!
-if ~exist('OCTAVE_VERSION')
+if ~isoctave
     if isnumeric(options_.parallel)  || (M_.exo_nbr*ceil(size(varlist,1)/MaxNumberOfPlotPerFigure))<8,
         [fout] = PosteriorIRF_core2(localVars,1,M_.exo_nbr,0);
     else
diff --git a/matlab/PosteriorIRF_core1.m b/matlab/PosteriorIRF_core1.m
index 20294afa2..00b338478 100644
--- a/matlab/PosteriorIRF_core1.m
+++ b/matlab/PosteriorIRF_core1.m
@@ -278,7 +278,7 @@ while fpar<B
         ifil2 = ifil2 + 1;
         irun2 = 0;
     end
-%     if exist('OCTAVE_VERSION'),
+%     if isoctave
 %         if (whoiam==0),
 %             printf(['Posterior IRF  %3.f%% done\r'],(fpar/B*100));
 %         end
@@ -286,7 +286,7 @@ while fpar<B
 %         waitbar(fpar/B,h);
 %     end
 %     if whoiam,
-%         if ~exist('OCTAVE_VERSION')
+%         if ~isoctave
 %             fprintf('Done! \n');
 %         end
 %         waitbarString = [ 'Subdraw ' int2str(fpar) '/' int2str(B) ' done.'];
diff --git a/matlab/UnivariateSpectralDensity.m b/matlab/UnivariateSpectralDensity.m
index f9760ef79..0303cd306 100644
--- a/matlab/UnivariateSpectralDensity.m
+++ b/matlab/UnivariateSpectralDensity.m
@@ -39,7 +39,7 @@ sdl      = options_.SpectralDensity.sdl;
 omega    = (0:sdl:pi)';
 GridSize = length(omega);
 exo_names_orig_ord  = M_.exo_names_orig_ord;
-if exist('OCTAVE_VERSION')
+if isoctave
     warning('off', 'Octave:divide-by-zero')
 else
     warning off MATLAB:dividebyzero
@@ -160,7 +160,7 @@ for i=1:nvar
     f(i,:) = Gamma(i,1)/(2*pi) + Gamma(i,H+1)*cos(H'*omega')/pi;
 end  
 
-if exist('OCTAVE_VERSION')
+if isoctave
     warning('on', 'Octave:divide-by-zero')
 else
     warning on MATLAB:dividebyzero
diff --git a/matlab/draw_prior_density.m b/matlab/draw_prior_density.m
index ec0fa3c76..1d364eecf 100644
--- a/matlab/draw_prior_density.m
+++ b/matlab/draw_prior_density.m
@@ -54,7 +54,7 @@ switch pshape(indx)
         supbound = gaminv(1-truncprior,p6(indx),p7(indx))+p3(indx);
     catch
         % Workaround for ticket #161
-        if exist('OCTAVE_VERSION')
+        if isoctave
             error(['Due to a bug in Octave, you must choose other values for mean and/or variance of your prior on ' bayestopt_.name{indx} ', or use another shape'])
         else
             rethrow(lasterror)
@@ -73,7 +73,7 @@ switch pshape(indx)
         supbound = 1/sqrt(gaminv(10*truncprior, p7(indx)/2, 2/p6(indx)))+p3(indx);
     catch
         % Workaround for ticket #161
-        if exist('OCTAVE_VERSION')
+        if isoctave
             error(['Due to a bug in Octave, you must choose other values for mean and/or variance of your prior on ' bayestopt_.name{indx} ', or use another shape'])
         else
             rethrow(lasterror)
@@ -92,7 +92,7 @@ switch pshape(indx)
         supbound = 1/(gaminv(10*truncprior, p7(indx)/2, 2/p6(indx)))+p3(indx);
     catch
         % Workaround for ticket #161
-        if exist('OCTAVE_VERSION')
+        if isoctave
             error(['Due to a bug in Octave, you must choose other values for mean and/or variance of your prior on ' bayestopt_.name{indx} ', or use another shape'])
         else
             rethrow(lasterror)
diff --git a/matlab/dyn_saveas.m b/matlab/dyn_saveas.m
index 533f8a755..2bd513cc8 100644
--- a/matlab/dyn_saveas.m
+++ b/matlab/dyn_saveas.m
@@ -31,7 +31,7 @@ function dyn_saveas(h,fname,DynareOptions)
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 if any(strcmp('eps',cellstr(DynareOptions.graph_format)))
-    if exist('OCTAVE_VERSION')
+    if isoctave
         fname = strrep(fname,'/',filesep);
         fname = strrep(fname,'\',filesep);
         if DynareOptions.nodisplay && ispc,
@@ -41,14 +41,14 @@ if any(strcmp('eps',cellstr(DynareOptions.graph_format)))
     print(h,'-depsc2',[fname,'.eps']) 
 end
 if any(strcmp('pdf',cellstr(DynareOptions.graph_format)))
-    if exist('OCTAVE_VERSION')
+    if isoctave
         error('Octave cannot create pdf files!')
     else
         print(h,'-dpdf',[fname,'.pdf']) 
     end
 end
 if any(strcmp('fig',cellstr(DynareOptions.graph_format)))
-    if exist('OCTAVE_VERSION')
+    if isoctave
         error('Octave cannot create fig files!')
     else
         if DynareOptions.nodisplay
diff --git a/matlab/dyn_waitbar.m b/matlab/dyn_waitbar.m
index 73577c798..f9665c950 100644
--- a/matlab/dyn_waitbar.m
+++ b/matlab/dyn_waitbar.m
@@ -44,7 +44,7 @@ end
 
 if ~whoiam
     
-    if exist('OCTAVE_VERSION') || options_.console_mode,
+    if isoctave || options_.console_mode
                 
         if init,
             diary off;
@@ -55,7 +55,7 @@ if ~whoiam
             running_text =  varargin{2};
         end
         
-        if exist('OCTAVE_VERSION'),
+        if isoctave
             printf([running_text,' %3.f%% done\r'], prctdone*100);
         else
             s0=repmat('\b',1,length(newString));
diff --git a/matlab/dyn_waitbar_close.m b/matlab/dyn_waitbar_close.m
index 4dbb628e5..894e4c6fa 100644
--- a/matlab/dyn_waitbar_close.m
+++ b/matlab/dyn_waitbar_close.m
@@ -22,7 +22,7 @@ function dyn_waitbar_close(h)
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 global options_
 
-if exist('OCTAVE_VERSION') || options_.console_mode,
+if isoctave || options_.console_mode,
     clear dyn_waitbar;
     diary on,
     fprintf('\n');
diff --git a/matlab/dynare.m b/matlab/dynare.m
index 793a33886..0d533accc 100644
--- a/matlab/dynare.m
+++ b/matlab/dynare.m
@@ -46,7 +46,7 @@ end
 
 warning_config()
 
-if exist('OCTAVE_VERSION')
+if isoctave 
     if octave_ver_less_than('3.6.0')
         warning('This version of Dynare has only been tested on Octave 3.6.0 and above. Since your Octave version is older than that, Dynare may fail to run, or give unexpected results. Consider upgrading your Octave installation.');
     end
@@ -60,7 +60,7 @@ end
 more off
 
 % sets default format for save() command
-if exist('OCTAVE_VERSION')
+if isoctave
     default_save_options('-mat')
 end
 
diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m
index 3180a81a6..d52edad9f 100644
--- a/matlab/dynare_config.m
+++ b/matlab/dynare_config.m
@@ -67,7 +67,7 @@ addpath([dynareroot '/reports/'])
 % For functions that exist only under some Octave versions
 % or some MATLAB versions, and for which we provide some replacement functions
 
-if ~exist('OCTAVE_VERSION')
+if ~isoctave
     % Replacements for rows(), columns() and issquare() (inexistent under MATLAB)
     addpath([dynareroot '/missing/rows_columns'])
     addpath([dynareroot '/missing/issquare'])
@@ -80,34 +80,34 @@ if ~exist('OCTAVE_VERSION')
 end
 
 % ordeig() doesn't exist in Octave
-if exist('OCTAVE_VERSION')
+if isoctave
     addpath([dynareroot '/missing/ordeig'])
 end
 
 % bsxfun is missing in old versions of MATLAB (and exists in Octave)
-if ~exist('OCTAVE_VERSION') && matlab_ver_less_than('7.4')
+if ~isoctave && matlab_ver_less_than('7.4')
     addpath([dynareroot '/missing/bsxfun'])
 end
 
 % ilu is missing in old versions of MATLAB and in Octave
-if exist('OCTAVE_VERSION') || matlab_ver_less_than('7.4')
+if isoctave || matlab_ver_less_than('7.4')
     addpath([dynareroot '/missing/ilu'])
 end
 
 % strjoin is missing in older versions of MATLAB and in Octave
-if exist('OCTAVE_VERSION') || matlab_ver_less_than('8.1')
+if isoctave || matlab_ver_less_than('8.1')
     addpath([dynareroot '/missing/strjoin'])
 end
 
 % nanmean is in Octave Forge Statistics package and in MATLAB Statistics
 % toolbox
-if (exist('OCTAVE_VERSION') && ~user_has_octave_forge_package('statistics')) ...
-    || (~exist('OCTAVE_VERSION') && ~user_has_matlab_license('statistics_toolbox'))
+if (isoctave && ~user_has_octave_forge_package('statistics')) ...
+    || (~isoctave && ~user_has_matlab_license('statistics_toolbox'))
     addpath([dynareroot '/missing/nanmean'])
 end
 
 % Add path to MEX files
-if exist('OCTAVE_VERSION')
+if isoctave
     addpath([dynareroot '../mex/octave/']);
 else
     % Add win32 specific paths for Dynare Windows package
diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m
index 2c8783bfd..aa92fdc1b 100644
--- a/matlab/dynare_estimation_1.m
+++ b/matlab/dynare_estimation_1.m
@@ -218,7 +218,7 @@ end
 if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
     switch options_.mode_compute
       case 1
-        if exist('OCTAVE_VERSION')
+        if isoctave
             error('Option mode_compute=1 is not available under Octave')
         elseif ~user_has_matlab_license('optimization_toolbox')
             error('Option mode_compute=1 requires the Optimization Toolbox')
@@ -236,9 +236,9 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
       case 2
         error('ESTIMATION: mode_compute=2 option (Lester Ingber''s Adaptive Simulated Annealing) is no longer available')
       case 3
-        if exist('OCTAVE_VERSION') && ~user_has_octave_forge_package('optim')
+        if isoctave && ~user_has_octave_forge_package('optim')
             error('Option mode_compute=3 requires the optim package')
-        elseif ~exist('OCTAVE_VERSION') && ~user_has_matlab_license('optimization_toolbox')
+        elseif ~isoctave && ~user_has_matlab_license('optimization_toolbox')
             error('Option mode_compute=3 requires the Optimization Toolbox')
         end
         % Set default optimization options for fminunc.
@@ -249,7 +249,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
         if options_.analytic_derivation,
             optim_options = optimset(optim_options,'GradObj','on');
         end
-        if ~exist('OCTAVE_VERSION')
+        if ~isoctave
             [xparam1,fval,exitflag] = fminunc(objective_function,xparam1,optim_options,dataset_,options_,M_,estim_params_,bayestopt_,oo_);
         else
             % Under Octave, use a wrapper, since fminunc() does not have a 4th arg
@@ -456,9 +456,9 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
         save([M_.fname '_mode.mat'],'xparam1','hh','parameter_names');
       case 7
         % Matlab's simplex (Optimization toolbox needed).
-        if exist('OCTAVE_VERSION') && ~user_has_octave_forge_package('optim')
+        if isoctave && ~user_has_octave_forge_package('optim')
             error('Option mode_compute=7 requires the optim package')
-        elseif ~exist('OCTAVE_VERSION') && ~user_has_matlab_license('optimization_toolbox')
+        elseif ~isoctave && ~user_has_matlab_license('optimization_toolbox')
             error('Option mode_compute=7 requires the Optimization Toolbox')
         end
         optim_options = optimset('display','iter','MaxFunEvals',1000000,'MaxIter',6000,'TolFun',1e-8,'TolX',1e-6);
diff --git a/matlab/dynare_identification.m b/matlab/dynare_identification.m
index c9c100721..1e96f8b72 100644
--- a/matlab/dynare_identification.m
+++ b/matlab/dynare_identification.m
@@ -38,7 +38,7 @@ function [pdraws, TAU, GAM, LRE, gp, H, JJ] = dynare_identification(options_iden
 
 global M_ options_ oo_ bayestopt_ estim_params_
 
-if exist('OCTAVE_VERSION')
+if isoctave
     warning('off'),
 else
     warning off,
@@ -442,7 +442,7 @@ if iload <=0,
             end
             
             if SampleSize > 1,
-%                 if exist('OCTAVE_VERSION') || options_.console_mode,
+%                 if isoctave || options_.console_mode,
 %                     console_waitbar(0,iteration/SampleSize);
 %                 else
                     dyn_waitbar(iteration/SampleSize,h,['MC identification checks ',int2str(iteration),'/',int2str(SampleSize)])
@@ -454,7 +454,7 @@ if iload <=0,
     
     
     if SampleSize > 1,
-        if exist('OCTAVE_VERSION') || options_.console_mode,
+        if isoctave || options_.console_mode,
             fprintf('\n');
             diary on;
         else
@@ -581,7 +581,7 @@ if SampleSize > 1,
     end
 end
 
-if exist('OCTAVE_VERSION')
+if isoctave
     warning('on'),
 else
     warning on,
diff --git a/matlab/dynare_sensitivity.m b/matlab/dynare_sensitivity.m
index 07ffc50d0..79820d7af 100644
--- a/matlab/dynare_sensitivity.m
+++ b/matlab/dynare_sensitivity.m
@@ -300,7 +300,7 @@ if options_gsa.rmse,
         else
             a=whos('-file',[OutputDirectoryName,'/',fname_,'_mc'],'logpo2');
         end
-        if exist('OCTAVE_VERSION'),
+        if isoctave
             aflag=0;
             for ja=1:length(a),
                 aflag=aflag+strcmp('logpo2',a(ja).name);
diff --git a/matlab/dynare_solve.m b/matlab/dynare_solve.m
index f8eb4af9e..61fda7244 100644
--- a/matlab/dynare_solve.m
+++ b/matlab/dynare_solve.m
@@ -84,7 +84,7 @@ if max(abs(fvec)) < tolf
 end
 
 if options_.solve_algo == 0
-    if ~exist('OCTAVE_VERSION')
+    if ~isoctave
         if ~user_has_matlab_license('optimization_toolbox')
             error('You can''t use solve_algo=0 since you don''t have MATLAB''s Optimization Toolbox')
         end
@@ -99,7 +99,7 @@ if options_.solve_algo == 0
     else
         options.Jacobian = 'off';
     end
-    if ~exist('OCTAVE_VERSION')
+    if ~isoctave
         [x,fval,exitval,output] = fsolve(func,x,options,varargin{:});
     else
         % Under Octave, use a wrapper, since fsolve() does not have a 4th arg
diff --git a/matlab/gensylv/sylvester3.m b/matlab/gensylv/sylvester3.m
index 38465d6c4..aabdc6650 100644
--- a/matlab/gensylv/sylvester3.m
+++ b/matlab/gensylv/sylvester3.m
@@ -35,7 +35,7 @@ if m == 1
     return;
 end
 [u,t]=schur(c);
-if exist('OCTAVE_VERSION')
+if isoctave
     [aa,bb,qq,zz]=qz(full(a),full(b));
     for j=1:p,
         if octave_ver_less_than('3.4.0')
diff --git a/matlab/get_dynare_random_generator_state.m b/matlab/get_dynare_random_generator_state.m
index 42cf80a38..513919c22 100644
--- a/matlab/get_dynare_random_generator_state.m
+++ b/matlab/get_dynare_random_generator_state.m
@@ -23,7 +23,7 @@ function [state_u,state_n] = get_dynare_random_generator_state()
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-    matlab_random_streams = ~(exist('OCTAVE_VERSION') || matlab_ver_less_than('7.7'));
+    matlab_random_streams = ~(isoctave || matlab_ver_less_than('7.7'));
 
     if matlab_random_streams% Use new matlab interface.
         if matlab_ver_less_than('7.12')
diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m
index 0c57eef4d..abd1b3a13 100644
--- a/matlab/global_initialization.m
+++ b/matlab/global_initialization.m
@@ -124,7 +124,7 @@ options_.nograph = 0;
 options_.XTick = [];
 options_.XTickLabel = [];
 options_.console_mode = 0;
-if exist('OCTAVE_VERSION')
+if isoctave
     if sum(get(0,'screensize'))==4
         options_.console_mode = 1;
         options_.nodisplay = 1;
diff --git a/matlab/gsa/filt_mc_.m b/matlab/gsa/filt_mc_.m
index 5e09b0b72..b4bc83af5 100644
--- a/matlab/gsa/filt_mc_.m
+++ b/matlab/gsa/filt_mc_.m
@@ -565,7 +565,7 @@ else
             title([pnam{nsnam(j)}],'interpreter','none')
         end
         %subplot(3,2,6)
-        if exist('OCTAVE_VERSION'),
+        if isoctave
             legend(char('base',vvarvecm),'location','eastoutside');
         else
             h0=legend(char('base',vvarvecm),0);
diff --git a/matlab/independent_metropolis_hastings_core.m b/matlab/independent_metropolis_hastings_core.m
index 3162bd402..f30a70084 100644
--- a/matlab/independent_metropolis_hastings_core.m
+++ b/matlab/independent_metropolis_hastings_core.m
@@ -128,7 +128,7 @@ for b = fblck:nblck,
         x2 = zeros(InitSizeArray(b),npar);
         logpo2 = zeros(InitSizeArray(b),1);
     end
-    if exist('OCTAVE_VERSION') || options_.console_mode
+    if isoctave || options_.console_mode
         diary off
         skipline()
     elseif whoiam
@@ -176,9 +176,9 @@ for b = fblck:nblck,
             logpo2(irun) = ilogpo2(b);
         end
         prtfrc = j/nruns(b);
-        if exist('OCTAVE_VERSION') || options_.console_mode
+        if isoctave || options_.console_mode
             if mod(j, 10) == 0
-                if exist('OCTAVE_VERSION')
+                if isoctave
                     if (whoiam==0),
                         printf('MH: Computing Metropolis-Hastings (chain %d/%d): %3.f%% done, acception rate: %3.f%%\r', b, nblck, 100 * prtfrc, 100 * isux / j);
                     end
@@ -245,7 +245,7 @@ for b = fblck:nblck,
         irun = irun + 1;
     end% End of the simulations for one mh-block.
     record.AcceptationRates(b) = isux/j;
-    if exist('OCTAVE_VERSION') || options_.console_mode
+    if isoctave || options_.console_mode
         printf('\n');
         diary on
     elseif ~whoiam
diff --git a/matlab/load_csv_file_data.m b/matlab/load_csv_file_data.m
index ed370cf78..3af3e3494 100644
--- a/matlab/load_csv_file_data.m
+++ b/matlab/load_csv_file_data.m
@@ -62,7 +62,7 @@ end
 freq = 1;                  % Default frequency is annual.
 init = dates(1,1);         % Default initial date is year one.
 varlist = [];
-if ~exist('OCTAVE_VERSION')
+if ~isoctave
     % Under Matlab, save time by using importdata
     assert(exist(file, 'file') == 2, ['load_csv_file_data: I can''t find file ' file '!']);
     A = importdata(file, ',', withnames);
diff --git a/matlab/lyapunov_symm.m b/matlab/lyapunov_symm.m
index e23323f77..3d3d0c768 100644
--- a/matlab/lyapunov_symm.m
+++ b/matlab/lyapunov_symm.m
@@ -85,7 +85,7 @@ if method == 3
     end;
 elseif method == 4
     % works only with Matlab System Control toolbox or octave the control package,
-    if exist('OCTAVE_VERSION')
+    if isoctave
         if ~user_has_octave_forge_package('control')
             error('lyapunov=square_root_solver not available; you must install the control package from Octave Forge')
         end
diff --git a/matlab/mode_check.m b/matlab/mode_check.m
index a8e06a32d..786acb7da 100644
--- a/matlab/mode_check.m
+++ b/matlab/mode_check.m
@@ -168,7 +168,7 @@ for plt = 1:nbplt,
         drawnow
     end
     if DynareOptions.mode_check.nolik==0,
-        if exist('OCTAVE_VERSION'),
+        if isoctave
             axes('outerposition',[0.3 0.93 0.42 0.07],'box','on'),
         else
             axes('position',[0.3 0.01 0.42 0.05],'box','on'),
diff --git a/matlab/ms-sbvar/dyn_save_graph.m b/matlab/ms-sbvar/dyn_save_graph.m
index 355b7f13e..612be4960 100644
--- a/matlab/ms-sbvar/dyn_save_graph.m
+++ b/matlab/ms-sbvar/dyn_save_graph.m
@@ -44,10 +44,10 @@ function dyn_save_graph(dirname,graph_name,graph_formats,TeX,names,texnames,capt
     if graph_formats.eps || TeX
         print([ graph_name '.eps' ],'-depsc2');
     end
-    if graph_formats.pdf && ~exist(OCTAVE_VERSION)
+    if graph_formats.pdf && ~isoctave
         print(graph_name,'-dpdf');
     end
-    if graph_formats.fig && ~exist(OCTAVE_VERSION)
+    if graph_formats.fig && ~isoctave
         print(graph_name,'-dfig');
     end
     
diff --git a/matlab/ms-sbvar/plot_ms_variance_decomposition.m b/matlab/ms-sbvar/plot_ms_variance_decomposition.m
index 0188af2cc..7cd30dca8 100644
--- a/matlab/ms-sbvar/plot_ms_variance_decomposition.m
+++ b/matlab/ms-sbvar/plot_ms_variance_decomposition.m
@@ -150,7 +150,7 @@ end
             plot(x(2:end)',steady(:,k), '--k','LineWidth',2.25);
         end
         if k==K
-            if exist('OCTAVE_VERSION')
+            if isoctave
                 legend(shock_names,'Location','SouthOutside');
             else
                 legend(shock_names,'Location','BestOutside','Orientation','horizontal');
diff --git a/matlab/parallel/AnalyseComputationalEnvironment.m b/matlab/parallel/AnalyseComputationalEnvironment.m
index f6dd9e970..8ca504288 100644
--- a/matlab/parallel/AnalyseComputationalEnvironment.m
+++ b/matlab/parallel/AnalyseComputationalEnvironment.m
@@ -366,7 +366,7 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for'
         StrCommand=([s1,s2,s3,s4,s41,s42,s5,s51,s52,send]);
         
         % Mettere controllo su NbW ...
-        % if exist('OCTAVE_VERSION')
+        % if isoctave
         %     NbW = fprintf(fid,StrCommand, '%s');
         % else
         NbW = fprintf(fid,StrCommand, '%s');
diff --git a/matlab/parallel/InitializeComputationalEnvironment.m b/matlab/parallel/InitializeComputationalEnvironment.m
index 22cc49c83..02df7aad4 100644
--- a/matlab/parallel/InitializeComputationalEnvironment.m
+++ b/matlab/parallel/InitializeComputationalEnvironment.m
@@ -37,7 +37,7 @@ function InitializeComputationalEnvironment()
 % Comment the line 'warning('off');' in order to view the warning message
 % in Octave!
 
-if exist('OCTAVE_VERSION'), 
+if isoctave 
     warning('off');
 end
 
@@ -48,7 +48,7 @@ global options_
 isHybridMatlabOctave = false;
 for j=1:length(options_.parallel),
     if isempty(options_.parallel(j).MatlabOctavePath),
-        if exist('OCTAVE_VERSION')
+        if isoctave
             options_.parallel(j).MatlabOctavePath = 'octave';
         else
             options_.parallel(j).MatlabOctavePath = 'matlab';
@@ -60,7 +60,7 @@ for j=1:length(options_.parallel),
     end
     isHybridMatlabOctave = isHybridMatlabOctave || any(regexpi([options_.parallel(j).MatlabOctavePath], 'octave'));
 end
-isHybridMatlabOctave = isHybridMatlabOctave && ~exist('OCTAVE_VERSION');
+isHybridMatlabOctave = isHybridMatlabOctave && ~isoctave;
 options_.parallel_info.isHybridMatlabOctave = isHybridMatlabOctave;
 if isHybridMatlabOctave,
     % Reset dynare random generator and seed.
diff --git a/matlab/parallel/dynareParallelDir.m b/matlab/parallel/dynareParallelDir.m
index ba31dafe0..d257e8090 100644
--- a/matlab/parallel/dynareParallelDir.m
+++ b/matlab/parallel/dynareParallelDir.m
@@ -36,7 +36,7 @@ for indPC=1:length(Parallel),
             else
                 ssh_token = '';
             end
-            if exist('OCTAVE_VERSION') % Patch for peculiar behaviour of ssh-ls under Linux.
+            if isoctave % Patch for peculiar behaviour of ssh-ls under Linux.
                 % It is necessary to capture the ls warning message.
                 % To do it under the ssh protocol it is necessary to redirect the ls message in a text file.
                 % The file is 'OctaveStandardOutputMessage.txt' and it is
@@ -56,7 +56,7 @@ for indPC=1:length(Parallel),
             end
         else
 
-            if exist('OCTAVE_VERSION') % Patch for peculiar behaviour of ls under Linux.
+            if isoctave % Patch for peculiar behaviour of ls under Linux.
                 
                 % It is necessary to capture the ls warning message and properly manage the jolly char '*'!
                 [check ax]=system(['ls ' ,filename, ' 2> OctaveStandardOutputMessage.txt']);
@@ -74,7 +74,7 @@ for indPC=1:length(Parallel),
 
         end
     else
-        if exist('OCTAVE_VERSION'),     % Patch for peculiar behaviour of ls under Windows.
+        if isoctave     % Patch for peculiar behaviour of ls under Windows.
             if Parallel(indPC).Local==0,
                 ax0=dir(['\\',Parallel(indPC).ComputerName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\',filename]);
             else
diff --git a/matlab/parallel/dynareParallelGetFiles.m b/matlab/parallel/dynareParallelGetFiles.m
index bfffaf972..dbd13d683 100644
--- a/matlab/parallel/dynareParallelGetFiles.m
+++ b/matlab/parallel/dynareParallelGetFiles.m
@@ -54,7 +54,7 @@ for indPC=1:length(Parallel),
             end
             for jfil=1:size(NamFileInput,1),
 
-                if exist('OCTAVE_VERSION') % Patch for peculiar behaviour of ls under Linux.
+                if isoctave % Patch for peculiar behaviour of ls under Linux.
                     % It is necessary to manage the jolly char '*'!
 
                     FindAst=strfind(NamFileInput{jfil,2},'comp_status_random_walk_metropolis_hastings_core*');
diff --git a/matlab/parallel/dynareParallelRmDir.m b/matlab/parallel/dynareParallelRmDir.m
index 6322f9b8a..de08a5599 100644
--- a/matlab/parallel/dynareParallelRmDir.m
+++ b/matlab/parallel/dynareParallelRmDir.m
@@ -64,7 +64,7 @@ for indPC=1:length(Parallel),
             [stat NonServe] = system(['ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' rm -fr ',Parallel(indPC).RemoteDirectory,'/',PRCDir,]);
             break;
         else
-            if exist('OCTAVE_VERSION'), % Patch for peculiar behaviour of rmdir under Windows.
+            if isoctave % Patch for peculiar behaviour of rmdir under Windows.
                                         % It is necessary because the command rmdir always ask at the user to confirm your decision before
                                         % deleting a directory: this stops the computation! The Octave native function 'confirm_recursive_rmdir'
                                         % disable this mechanism.
diff --git a/matlab/parallel/dynareParallelSendFiles.m b/matlab/parallel/dynareParallelSendFiles.m
index b1dc9cc28..d76f8a7bd 100644
--- a/matlab/parallel/dynareParallelSendFiles.m
+++ b/matlab/parallel/dynareParallelSendFiles.m
@@ -63,7 +63,7 @@ for indPC=1:length(Parallel),
                 if ~isempty(NamFileInput{jfil,1})
                     if isempty(dynareParallelDir(NamFileInput{jfil,1},PRCDir,Parallel(indPC)))
                         
-                        if exist('OCTAVE_VERSION') % Patch for peculiar behaviour of mkdir under Windows.
+                        if isoctave % Patch for peculiar behaviour of mkdir under Windows.
                             
                             % It is Necessary because Octave is not able to
                             % create two nested directory at the same time.
@@ -89,7 +89,7 @@ for indPC=1:length(Parallel),
                     end
                 end
                 
-                if exist('OCTAVE_VERSION') % Patch for peculiar behaviour copyfile ls under Windows.
+                if isoctave % Patch for peculiar behaviour copyfile ls under Windows.
                     
                     % It is Necessary because Octave is not able to
                     % use the jolly char '*' with copyfile.
diff --git a/matlab/parallel/masterParallel.m b/matlab/parallel/masterParallel.m
index 1b64b5ba1..a0657176f 100644
--- a/matlab/parallel/masterParallel.m
+++ b/matlab/parallel/masterParallel.m
@@ -110,13 +110,13 @@ end
 % Comment the line 'warning('off');' in order to view the warning messages
 % in Octave!
 
-if exist('OCTAVE_VERSION'),
+if isoctave
     warning('off');
 end
 
 % check if there are function_handles in the input or global vars when
 % octave is used
-if isHybridMatlabOctave || exist('OCTAVE_VERSION'),
+if isHybridMatlabOctave || isoctave
     fInputNames = fieldnames(fInputVar);
     for j=1:length(fInputNames),
         TargetVar = fInputVar.(fInputNames{j});
@@ -504,7 +504,7 @@ if Strategy==0 || newInstance, % See above.
         pause(1)
     else
         
-        if exist('OCTAVE_VERSION')
+        if isoctave
             % Redirect the standard output to the file 'OctaveStandardOutputMessage.txt'!
             % This file is saved in the Model directory.
             system('ConcurrentCommand1.bat > OctaveStandardOutputMessage.txt');
@@ -523,9 +523,9 @@ global options_
 
 % Create a parallel (local/remote) specialized computational status bars!
 
-if exist('OCTAVE_VERSION') || (options_.console_mode == 1),
+if isoctave || options_.console_mode
     diary off;
-    if exist('OCTAVE_VERSION')
+    if isoctave
         printf('\n');
     else
         fprintf('\n');
@@ -575,9 +575,9 @@ idCPU = NaN(1,totCPU);
 
 % Caption for console mode computing ...
 
-if (options_.console_mode == 1) ||  exist('OCTAVE_VERSION')
+if options_.console_mode ||  isoctave
     
-    if ~exist('OCTAVE_VERSION')
+    if ~isoctave
         if strcmpi([Parallel(indPC).MatlabOctavePath], 'octave')
             RjInformation='Hybrid Computing Is Active: Remote jobs are computed by Octave!';
             fprintf([RjInformation,'\n\n']);
@@ -607,7 +607,7 @@ if (options_.console_mode == 1) ||  exist('OCTAVE_VERSION')
     fnameTemp(L)='';
     
     Information=['Parallel ' fnameTemp ' Computing ...'];
-    if exist('OCTAVE_VERSION')
+    if isoctave
         if (~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem)) && (Strategy==0)
             printf('\n');
             pause(2);
@@ -660,7 +660,7 @@ while (ForEver)
             end
             pcerdone(j) = prtfrc;
             idCPU(j) = njob;
-            if exist('OCTAVE_VERSION') || (options_.console_mode == 1),
+            if isoctave || options_.console_mode
                 if (~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem))
                     statusString = [statusString, int2str(j), ' %3.f%% done! '];
                 else
@@ -672,7 +672,7 @@ while (ForEver)
             end
         catch % ME
             % To define!
-            if exist('OCTAVE_VERSION') || (options_.console_mode == 1),
+            if isoctave || options_.console_mode
                 if (~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem))
                     statusString = [statusString, int2str(j), ' %3.f%% done! '];
                 else
@@ -681,15 +681,14 @@ while (ForEver)
             end
         end
     end
-    if exist('OCTAVE_VERSION') || (options_.console_mode == 1),
-        if exist('OCTAVE_VERSION')
+    if isoctave || options_.console_mode
+        if isoctave
             printf([statusString,'\r'], 100 .* pcerdone);
         else
             if ~isempty(statusString)
                 fprintf([statusString0,statusString], 100 .* pcerdone);
             end
         end
-        
     else
         for j=1:totCPU,
             try
@@ -705,7 +704,7 @@ while (ForEver)
     % 1. The files .log and .txt are not copied.
     % 2. The comp_status_*.mat files are managed separately.
     
-    if exist('OCTAVE_VERSION'), % to avoid synchronism problems
+    if isoctave % to avoid synchronism problems
         try
             PRCDirSnapshot=dynareParallelGetNewFiles(PRCDir,Parallel(1:totSlaves),PRCDirSnapshot);
         catch
@@ -729,8 +728,8 @@ while (ForEver)
         
         if HoTuttiGliOutput==totCPU,
             mydelete(['comp_status_',fname,'*.mat']);
-            if exist('OCTAVE_VERSION')|| (options_.console_mode == 1),
-                if exist('OCTAVE_VERSION')
+            if isoctave || options_.console_mode
+                if isoctave
                     printf('\n');
                     printf(['End Parallel Session ....','\n\n']);
                 else
diff --git a/matlab/partial_information/PI_gensys.m b/matlab/partial_information/PI_gensys.m
index de63ba9a0..c46d45d07 100644
--- a/matlab/partial_information/PI_gensys.m
+++ b/matlab/partial_information/PI_gensys.m
@@ -180,7 +180,7 @@ try
     % In Octave: [aa bb q z v w] = qz(a,b) s.t. q'az = aa, q'bz=bb %
     % and qzcomplex() extension based on lapack zgges produces same 
     % qz output for Octave as Matlab qz() does for Matlab thus:
-    if exist('OCTAVE_VERSION')
+    if isoctave
         [a b q z]=qzcomplex(G0pi,G1pi);
         q=q';
     else
diff --git a/matlab/plot_icforecast.m b/matlab/plot_icforecast.m
index 6284769fa..84db7297b 100644
--- a/matlab/plot_icforecast.m
+++ b/matlab/plot_icforecast.m
@@ -27,7 +27,7 @@ function plot_icforecast(Variables,periods,options_)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-if exist('OCTAVE_VERSION') && octave_ver_less_than('3.4.0')
+if isoctave && octave_ver_less_than('3.4.0')
     % The set() command on the handle returned by area() crashes in Octave 3.2
     error('plot_conditional_forecast: you need Octave >= 3.4 (because of a bug in older versions)')
 end
diff --git a/matlab/pm3.m b/matlab/pm3.m
index 09488aa5e..5974fca27 100644
--- a/matlab/pm3.m
+++ b/matlab/pm3.m
@@ -118,7 +118,7 @@ localVars.Mean=Mean;
 % Like sequential execution!
 nvar0=nvar;
 
-if ~exist('OCTAVE_VERSION')
+if ~isoctave
     % Commenting for testing!
     if isnumeric(options_.parallel) || ceil(size(varlist,1)/MaxNumberOfPlotsPerFigure)<4,
         fout = pm3_core(localVars,1,nvar,0);
diff --git a/matlab/prior_bounds.m b/matlab/prior_bounds.m
index 2d187c9a5..4eb290e57 100644
--- a/matlab/prior_bounds.m
+++ b/matlab/prior_bounds.m
@@ -95,7 +95,7 @@ for i=1:length(p6)
                 bounds(i,2) = gaminv(1-prior_trunc,p6(i),p7(i))+p3(i);
             catch
                 % Workaround for ticket #161
-                if exist('OCTAVE_VERSION')
+                if isoctave
                     error(['Due to a bug in Octave, you must choose other values for mean and/or variance of your prior on ' bayestopt.name{i} ', or use another shape'])
                 else
                     rethrow(lasterror)
@@ -121,7 +121,7 @@ for i=1:length(p6)
                                             2/p6(i)))+p3(i);
             catch
                 % Workaround for ticket #161
-                if exist('OCTAVE_VERSION')
+                if isoctave
                     error(['Due to a bug in Octave, you must choose other values for mean and/or variance of your prior on ' bayestopt.name{i} ', or use another shape'])
                 else
                     rethrow(lasterror)
@@ -146,7 +146,7 @@ for i=1:length(p6)
                 bounds(i,2) = 1/gaminv(prior_trunc, p7(i)/2, 2/p6(i))+ p3(i);
             catch
                 % Workaround for ticket #161
-                if exist('OCTAVE_VERSION')
+                if isoctave
                     error(['Due to a bug in Octave, you must choose other values for mean and/or variance of your prior on ' bayestopt.name{i} ', or use another shape'])
                 else
                     rethrow(lasterror)
diff --git a/matlab/qz/mjdgges.m b/matlab/qz/mjdgges.m
index fea90931f..2225e257b 100644
--- a/matlab/qz/mjdgges.m
+++ b/matlab/qz/mjdgges.m
@@ -63,7 +63,7 @@ info = 0;
 %   as an option
 % - under Octave, only real decomposition available, but grouping of
 %   eigenvalues <= 1 is implemented as an option (criterium can't be changed)
-if exist('OCTAVE_VERSION')
+if isoctave
     [ss,tt,w,eigval] = qz(e,d,'S');
     sdim = sum(abs(eigval) <= 1.0);
     if any(abs(eigval) > 1.0 & abs(eigval) <= qz_criterium)
diff --git a/matlab/random_walk_metropolis_hastings_core.m b/matlab/random_walk_metropolis_hastings_core.m
index fa1b771d2..6cdb46b91 100644
--- a/matlab/random_walk_metropolis_hastings_core.m
+++ b/matlab/random_walk_metropolis_hastings_core.m
@@ -152,7 +152,7 @@ for b = fblck:nblck,
         logpo2 = zeros(InitSizeArray(b),1);
     end
     if whoiam
-        prc0=(b-fblck)/(nblck-fblck+1)*(exist('OCTAVE_VERSION') || options_.console_mode);
+        prc0=(b-fblck)/(nblck-fblck+1)*(isoctave || options_.console_mode);
         hh = dyn_waitbar({prc0,whoiam,options_.parallel(ThisMatlab)},['MH (' int2str(b) '/' int2str(options_.mh_nblck) ')...']);
     else
         hh = dyn_waitbar(0,['Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...']);
@@ -185,9 +185,9 @@ for b = fblck:nblck,
             logpo2(irun) = ilogpo2(b);
         end
         prtfrc = j/nruns(b);
-%         if exist('OCTAVE_VERSION') || options_.console_mode
+%         if isoctave || options_.console_mode
 %             if mod(j, 10) == 0
-%                 if exist('OCTAVE_VERSION')
+%                 if isoctave
 %                     if (whoiam==0)
 %                         printf('MH: Computing Metropolis-Hastings (chain %d/%d): %3.f%% done, acception rate: %3.f%%\r', b, nblck, 100 * prtfrc, 100 * isux / j);
 %                     end
@@ -263,8 +263,8 @@ for b = fblck:nblck,
         irun = irun + 1;
     end% End of the simulations for one mh-block.
     record.AcceptationRates(b) = isux/j;
-%     if exist('OCTAVE_VERSION') || options_.console_mode || whoiam
-%         if exist('OCTAVE_VERSION')
+%     if isoctave || options_.console_mode || whoiam
+%         if isoctave
 %             printf('\n');
 %         else
 %             fprintf('\n');
diff --git a/matlab/reports/@graph/createGraph.m b/matlab/reports/@graph/createGraph.m
index 48f1c3771..22eaafae3 100755
--- a/matlab/reports/@graph/createGraph.m
+++ b/matlab/reports/@graph/createGraph.m
@@ -142,7 +142,7 @@ if isempty(o.figname)
     o.figname = [tn '.tex'];
 end
 disp('  converting to tex....');
-if exist('OCTAVE_VERSION') && isempty(regexpi(computer, '.*apple.*', 'once'))
+if isoctave && isempty(regexpi(computer, '.*apple.*', 'once'))
     print(o.figname, '-dtikz');
 else
     matlab2tikz('filename', o.figname, ...
diff --git a/matlab/reports/@report/compile.m b/matlab/reports/@report/compile.m
index 06b48db8f..6388ba7dd 100755
--- a/matlab/reports/@report/compile.m
+++ b/matlab/reports/@report/compile.m
@@ -47,7 +47,7 @@ if ~exist(o.filename, 'file')
 end
 
 middle = ' ./';
-if exist('OCTAVE_VERSION')
+if isoctave
     echo = 1;
 else
     echo = '-echo';
@@ -82,7 +82,7 @@ fprintf(1, '\n\nDone.\n')
 disp('Your compiled report is located here:');
 disp(['     ' pwd filesep rfn '.pdf']);
 
-if ~exist('OCTAVE_VERSION')
+if ~isoctave
     open([pwd filesep rfn '.pdf']);
 end
 end
\ No newline at end of file
diff --git a/matlab/reports/@report/write.m b/matlab/reports/@report/write.m
index 0b34bdadb..91ca0c523 100644
--- a/matlab/reports/@report/write.m
+++ b/matlab/reports/@report/write.m
@@ -46,7 +46,7 @@ fprintf(fid, ['\\makeatletter\n' ...
               '\\def\\blfootnote{\\gdef\\@thefnmark{}\\@footnotetext}\n' ...
               '\\makeatother\n']);
 
-if exist('OCTAVE_VERSION') && isempty(regexpi(computer, '.*apple.*', 'once'))
+if isoctave && isempty(regexpi(computer, '.*apple.*', 'once'))
     fprintf(fid, '\\usepackage[T1]{fontenc}\n');
     fprintf(fid, '\\usepackage[utf8x]{inputenc}\n');
     fprintf(fid, '\\usepackage{gnuplot-lua-tikz}\n');
diff --git a/matlab/rplot.m b/matlab/rplot.m
index 50cda1bca..df7712535 100644
--- a/matlab/rplot.m
+++ b/matlab/rplot.m
@@ -63,7 +63,7 @@ if rplottype == 0
     title (t,'Interpreter','none') ;
     xlabel('Periods') ;
     if size(s1,1) > 1
-        if exist('OCTAVE_VERSION')
+        if isoctave
             legend(s1, 0);
         else
             h = legend(s1,0);
diff --git a/matlab/set_dynare_random_generator_state.m b/matlab/set_dynare_random_generator_state.m
index dccc6d16f..f16ce13ae 100644
--- a/matlab/set_dynare_random_generator_state.m
+++ b/matlab/set_dynare_random_generator_state.m
@@ -23,7 +23,7 @@ function [state_u,state_n] = set_dynare_random_generator_state(state_u,state_n)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-    matlab_random_streams = ~(exist('OCTAVE_VERSION') || matlab_ver_less_than('7.7'));
+    matlab_random_streams = ~(isoctave || matlab_ver_less_than('7.7'));
 
     if matlab_random_streams% Use new matlab interface.
         if matlab_ver_less_than('7.12')
diff --git a/matlab/set_dynare_seed.m b/matlab/set_dynare_seed.m
index 991b8ed57..fbde1abc3 100644
--- a/matlab/set_dynare_seed.m
+++ b/matlab/set_dynare_seed.m
@@ -24,7 +24,7 @@ if ~nargin
     error('set_dynare_seed:: I need at least one input argument!')
 end
 
-matlab_random_streams = ~(exist('OCTAVE_VERSION') || matlab_ver_less_than('7.7') || options_.parallel_info.isHybridMatlabOctave);
+matlab_random_streams = ~(isoctave || matlab_ver_less_than('7.7') || options_.parallel_info.isHybridMatlabOctave);
 
 if matlab_random_streams% Use new matlab interface.
     if nargin==1
@@ -93,7 +93,7 @@ if matlab_random_streams% Use new matlab interface.
 else% Use old matlab interface.
     if nargin==1
         if ischar(a) && strcmpi(a,'default')
-            if exist('OCTAVE_VERSION') || matlab_ver_less_than('7.4')
+            if isoctave || matlab_ver_less_than('7.4')
                 options_.DynareRandomStreams.algo = 'state';
             else
                 % Twister was introduced in MATLAB 7.4
diff --git a/matlab/simul.m b/matlab/simul.m
index c9fb8f896..953bb67d7 100644
--- a/matlab/simul.m
+++ b/matlab/simul.m
@@ -50,7 +50,7 @@ if (options_.block || options_.bytecode) && options_.stack_solve_algo == 6
     error('SIMUL: you can''t use stack_solve_algo = 6 with block or bytecode option')
 end
 
-if exist('OCTAVE_VERSION') && options_.stack_solve_algo == 2
+if isoctave && options_.stack_solve_algo == 2
     error('SIMUL: you can''t use stack_solve_algo = 2 under Octave')
 end
 
diff --git a/matlab/solve_one_boundary.m b/matlab/solve_one_boundary.m
index 21227076a..304b81892 100644
--- a/matlab/solve_one_boundary.m
+++ b/matlab/solve_one_boundary.m
@@ -224,7 +224,7 @@ for it_=start:incr:finish
                 if (verbose == 1)
                     disp('steady: fsolve');
                 end
-                if ~exist('OCTAVE_VERSION')
+                if ~isoctave
                     if ~user_has_matlab_license('optimization_toolbox')
                         error('SOLVE_ONE_BOUNDARY: you can''t use solve_algo=0 since you don''t have MATLAB''s Optimization Toolbox')
                     end
@@ -235,7 +235,7 @@ for it_=start:incr:finish
                 options.TolFun=1e-8;
                 options.Display = 'iter';
                 options.Jacobian = 'on';
-                if ~exist('OCTAVE_VERSION')
+                if ~isoctave
                     [yn,fval,exitval,output] = fsolve(@local_fname, y(y_index_eq), ...
                                                       options, x, params, steady_state, y, y_index_eq, fname, 0);
                 else
@@ -309,7 +309,7 @@ for it_=start:incr:finish
                 end;
             elseif((stack_solve_algo==2 && is_dynamic) || (options.solve_algo==7 && ~is_dynamic)),
                 flag1=1;
-                if exist('OCTAVE_VERSION')
+                if isoctave
                     error('SOLVE_ONE_BOUNDARY: you can''t use solve_algo=7 since GMRES is not implemented in Octave')
                 end
                 if (verbose == 1 && ~is_dynamic)
diff --git a/matlab/steady_.m b/matlab/steady_.m
index 822d4fbf4..df1772a72 100644
--- a/matlab/steady_.m
+++ b/matlab/steady_.m
@@ -47,7 +47,7 @@ if ~options_.bytecode && options_.block && options_.solve_algo == 5
     error('STEADY: you can''t use solve_algo = 5 without bytecode option')
 end
 
-if exist('OCTAVE_VERSION') && options_.solve_algo == 7
+if isoctave && options_.solve_algo == 7
     error('SIMUL: you can''t use solve_algo = 7 under Octave')
 end
 
diff --git a/matlab/th_autocovariances.m b/matlab/th_autocovariances.m
index eff41b89d..889f7d9f4 100644
--- a/matlab/th_autocovariances.m
+++ b/matlab/th_autocovariances.m
@@ -51,7 +51,7 @@ end
 
 endo_nbr = M_.endo_nbr;
 exo_names_orig_ord  = M_.exo_names_orig_ord;
-if exist('OCTAVE_VERSION')
+if isoctave
     warning('off', 'Octave:divide-by-zero')
 else
     warning off MATLAB:dividebyzero
@@ -260,7 +260,7 @@ else% ==> Theoretical HP filter.
         end
     end
 end
-if exist('OCTAVE_VERSION')
+if isoctave
     warning('on', 'Octave:divide-by-zero')
 else
     warning on MATLAB:dividebyzero
diff --git a/matlab/utilities/general/isoctave.m b/matlab/utilities/general/isoctave.m
new file mode 100644
index 000000000..15c6fb38d
--- /dev/null
+++ b/matlab/utilities/general/isoctave.m
@@ -0,0 +1,20 @@
+function A = isoctave()
+
+% Copyright (C) 2013 Dynare Team
+%
+% This file is part of Dynare.
+%
+% Dynare is free software: you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation, either version 3 of the License, or
+% (at your option) any later version.
+%
+% Dynare is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
+
+A = exist('OCTAVE_VERSION');
\ No newline at end of file
diff --git a/matlab/varlist_indices.m b/matlab/varlist_indices.m
index 20ece2830..d267adca1 100644
--- a/matlab/varlist_indices.m
+++ b/matlab/varlist_indices.m
@@ -31,7 +31,7 @@ function [i_var,nvar] = varlist_indices(sublist,list)
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 % In Octave, ismember() doesn't operate on character arrays
-if ~exist('OCTAVE_VERSION')
+if ~isoctave
     if isempty(sublist)
         check = [];
         i_var = [];
diff --git a/matlab/warning_config.m b/matlab/warning_config.m
index 3e3771409..6b6f53306 100644
--- a/matlab/warning_config.m
+++ b/matlab/warning_config.m
@@ -32,7 +32,7 @@ warning on;
 % Display a calling stack trace when a warning is issued
 warning('on', 'backtrace');
 
-if exist('OCTAVE_VERSION')
+if isoctave
     warning('off', 'Octave:separator-insert');
     warning('off', 'Octave:matlab-incompatible');
     warning('off', 'Octave:single-quote-string');
diff --git a/matlab/writedata.m b/matlab/writedata.m
index 93bd99c56..815563008 100644
--- a/matlab/writedata.m
+++ b/matlab/writedata.m
@@ -30,7 +30,7 @@ function writedata(fname)
 global M_ oo_
 
 % xlswrite doesn't exist on Octave, and appeared in MATLAB 7.0
-if exist('OCTAVE_VERSION') || matlab_ver_less_than('7.0')
+if isoctave || matlab_ver_less_than('7.0')
     error('Function not supported on your version of MATLAB or Octave')
 end
 
-- 
GitLab