From db847c468d112f85241c180e4a9dcd3794e868a2 Mon Sep 17 00:00:00 2001
From: Marco Ratto <marco.ratto@jrc.ec.europa.eu>
Date: Mon, 2 Jul 2012 10:55:02 +0200
Subject: [PATCH] - Added trap to avoid infinite loops when type is not
 'prior'; - Recover value of nosaddle from _core routine (bug fix when type is
 'prior'); (cherry picked from commit
 99c35e22f16b52650ec33efb1178aeafc2b0b367)

---
 matlab/PosteriorIRF.m       |  7 +++++--
 matlab/PosteriorIRF_core1.m | 12 +++++++++---
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/matlab/PosteriorIRF.m b/matlab/PosteriorIRF.m
index 13543e3c05..c78733e383 100644
--- a/matlab/PosteriorIRF.m
+++ b/matlab/PosteriorIRF.m
@@ -162,7 +162,6 @@ end
 % function.
 
 b = 0;
-nosaddle = 0;
 
 localVars=[];
 
@@ -171,7 +170,6 @@ localVars=[];
 localVars.IRUN = IRUN;
 localVars.irun = irun;
 localVars.irun2=irun2;
-localVars.nosaddle=nosaddle;
 localVars.npar = npar;
 
 localVars.type=type;
@@ -208,6 +206,7 @@ localVars.MhDirectoryName=MhDirectoryName;
 % Like sequential execution!
 if isnumeric(options_.parallel),
     [fout] = PosteriorIRF_core1(localVars,1,B,0);
+    nosaddle = fout.nosaddle;
 else
     % Parallel execution!
     [nCPU, totCPU, nBlockPerCPU] = distributeJobs(options_.parallel, 1, B);
@@ -241,6 +240,10 @@ else
         NamFileInput(length(NamFileInput)+1,:)={'',[M_.fname '_steadystate.m']};
     end
     [fout] = masterParallel(options_.parallel, 1, B,NamFileInput,'PosteriorIRF_core1', localVars, globalVars, options_.parallel_info);
+    nosaddle=0;
+    for j=1:length(fout),
+        nosaddle = nosaddle + fout(j).nosaddle;
+    end
     
 end
 
diff --git a/matlab/PosteriorIRF_core1.m b/matlab/PosteriorIRF_core1.m
index fa89722f35..115327fa8a 100644
--- a/matlab/PosteriorIRF_core1.m
+++ b/matlab/PosteriorIRF_core1.m
@@ -52,7 +52,6 @@ end
 IRUN = myinputs.IRUN;
 irun =myinputs.irun;
 irun2=myinputs.irun2;
-nosaddle=myinputs.nosaddle;
 npar=myinputs.npar;
 type=myinputs.type;
 if ~strcmpi(type,'prior'),
@@ -124,6 +123,7 @@ OutputFileName_param = {};
 
 fpar = fpar-1;
 fpar0=fpar;
+nosaddle=0;
 
 if whoiam
     ifil2=ifil2(whoiam);
@@ -163,8 +163,12 @@ while fpar<B
         elseif info(1) == 5
             errordef = 'Rank condition  is not satisfied';
         end
-        disp(['PosteriorIRF :: Dynare is unable to solve the model (' errordef ')'])
-        continue
+        if strcmpi(type,'prior'),
+            disp(['PosteriorIRF :: Dynare is unable to solve the model (' errordef ')'])
+            continue
+        else
+            error(['PosteriorIRF :: Dynare is unable to solve the model (' errordef ') with sample ' type])
+        end
     end
     SS(M_.exo_names_orig_ord,M_.exo_names_orig_ord) = M_.Sigma_e+1e-14*eye(M_.exo_nbr);
     SS = transpose(chol(SS));
@@ -305,6 +309,8 @@ end
 myoutput.OutputFileName = [OutputFileName_dsge;
                     OutputFileName_param;
                     OutputFileName_bvardsge];
+                
+myoutput.nosaddle = nosaddle;
 
 
 
-- 
GitLab