From 1a8382adfb25529fe4996dd57bbed3e78cf70005 Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Fri, 9 Dec 2016 14:29:02 +0100
Subject: [PATCH] OSR: add error indicator and suppress output if noprint
 options is specified

---
 matlab/osr.m  |  8 +++++---
 matlab/osr1.m | 30 +++++++++++++++++++-----------
 2 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/matlab/osr.m b/matlab/osr.m
index fcd5b507b..d579c63ec 100644
--- a/matlab/osr.m
+++ b/matlab/osr.m
@@ -55,9 +55,11 @@ for i=1:np
     i_params(i) = strmatch(str{:}, M_.param_names, 'exact');
 end
 
-skipline()
-disp('OPTIMAL SIMPLE RULE')
-skipline()
+if ~options_.noprint
+    skipline()
+    disp('OPTIMAL SIMPLE RULE')
+    skipline()
+end
 osr_res = osr1(i_params,i_var,W);
 
 stoch_simul(var_list);
\ No newline at end of file
diff --git a/matlab/osr1.m b/matlab/osr1.m
index 641e5fda9..cf13da166 100644
--- a/matlab/osr1.m
+++ b/matlab/osr1.m
@@ -41,6 +41,7 @@ iyv = iyv(:);
 iyr0 = find(iyv) ;
 it_ = M_.maximum_lag + 1 ;
 
+osr_res.error_indicator = 1; %initialize indicator
 
 if M_.exo_nbr == 0
     oo_.exo_steady_state = [] ;
@@ -101,10 +102,12 @@ i_var=unique(i_var);
 [loss,info,exit_flag,vx]=osr_obj(t0,i_params,inv_order_var(i_var),weights(i_var,i_var));
 if info~=0
    print_info(info, options_.noprint, options_);
-else
-   fprintf('\nOSR: Initial value of the objective function: %g \n\n',loss);
+   else 
+       if ~options_.noprint
+           fprintf('\nOSR: Initial value of the objective function: %g \n\n',loss);
+       end
 end
-if isinf(loss)
+if ~options_.noprint && isinf(loss) 
    fprintf('\nOSR: The initial value of the objective function is infinite.\n');
    fprintf('\nOSR: Check whether the unconditional variance of a target variable is infinite\n');
    fprintf('\nOSR: due to the presence of a unit root.\n');
@@ -136,12 +139,17 @@ for i=1:length(i_params)
     osr_res.optim_params.(deblank(M_.param_names(i_params(i),:))) = p(i);
 end
 
-skipline()
-disp('OPTIMAL VALUE OF THE PARAMETERS:')
-skipline()
-for i=1:np
-    disp(sprintf('%16s %16.6g\n',M_.param_names(i_params(i),:),p(i)))
+if ~options_.noprint
+    skipline()
+    disp('OPTIMAL VALUE OF THE PARAMETERS:')
+    skipline()
+    for i=1:np
+        disp(sprintf('%16s %16.6g\n',M_.param_names(i_params(i),:),p(i)))
+    end
+    disp(sprintf('Objective function : %16.6g\n',f));
+    skipline()
 end
-disp(sprintf('Objective function : %16.6g\n',f));
-skipline()
-[oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
\ No newline at end of file
+[oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
+if ~info
+    osr_res.error_indicator=0;
+end
\ No newline at end of file
-- 
GitLab